Changeset View
Changeset View
Standalone View
Standalone View
sys/netinet/netdump/netdump_client.c
Show First 20 Lines • Show All 490 Lines • ▼ Show 20 Lines | |||||
* | * | ||||
* Returns: | * Returns: | ||||
* 0 on success, and an errno value on failure. | * 0 on success, and an errno value on failure. | ||||
*/ | */ | ||||
static int | static int | ||||
netdump_ioctl(struct cdev *dev __unused, u_long cmd, caddr_t addr, | netdump_ioctl(struct cdev *dev __unused, u_long cmd, caddr_t addr, | ||||
int flags __unused, struct thread *td) | int flags __unused, struct thread *td) | ||||
{ | { | ||||
struct diocskerneldump_arg kda_copy, *conf; | struct diocskerneldump_arg *conf; | ||||
struct dumperinfo dumper; | struct dumperinfo dumper; | ||||
uint8_t *encryptedkey; | uint8_t *encryptedkey; | ||||
int error; | int error; | ||||
#ifdef COMPAT_FREEBSD12 | |||||
struct diocskerneldump_arg_freebsd12 *kda12; | |||||
struct netdump_conf_freebsd12 *conf12; | |||||
#endif | |||||
conf = NULL; | conf = NULL; | ||||
error = 0; | error = 0; | ||||
NETDUMP_WLOCK(); | NETDUMP_WLOCK(); | ||||
switch (cmd) { | switch (cmd) { | ||||
#ifdef COMPAT_FREEBSD12 | |||||
/* | |||||
* Used by dumpon(8) in 12.x for clearing previous | |||||
* configuration -- then NETDUMPSCONF_FREEBSD12 is used to | |||||
* actually configure netdump. | |||||
*/ | |||||
case DIOCSKERNELDUMP_FREEBSD12: | |||||
gone_in(14, "12.x ABI compatibility"); | |||||
kda12 = (void *)addr; | |||||
if (kda12->kda12_enable) { | |||||
error = ENXIO; | |||||
break; | |||||
} | |||||
if (netdump_enabled()) | |||||
netdump_unconfigure(); | |||||
break; | |||||
case NETDUMPGCONF_FREEBSD12: | |||||
gone_in(14, "FreeBSD 12.x ABI compat"); | |||||
conf12 = (void *)addr; | |||||
if (!netdump_enabled()) { | |||||
error = ENXIO; | |||||
break; | |||||
} | |||||
if (nd_conf.ndc_af != AF_INET) { | |||||
error = EOPNOTSUPP; | |||||
break; | |||||
} | |||||
if (nd_ifp != NULL) | |||||
strlcpy(conf12->ndc12_iface, nd_ifp->if_xname, | |||||
sizeof(conf12->ndc12_iface)); | |||||
memcpy(&conf12->ndc12_server, &nd_server, | |||||
sizeof(conf12->ndc12_server)); | |||||
memcpy(&conf12->ndc12_client, &nd_client, | |||||
sizeof(conf12->ndc12_client)); | |||||
memcpy(&conf12->ndc12_gateway, &nd_gateway, | |||||
sizeof(conf12->ndc12_gateway)); | |||||
break; | |||||
#endif | |||||
case DIOCGKERNELDUMP: | case DIOCGKERNELDUMP: | ||||
conf = (void *)addr; | conf = (void *)addr; | ||||
/* | /* | ||||
* For now, index is ignored; netdump doesn't support multiple | * For now, index is ignored; netdump doesn't support multiple | ||||
* configurations (yet). | * configurations (yet). | ||||
*/ | */ | ||||
if (!netdump_enabled()) { | if (!netdump_enabled()) { | ||||
error = ENXIO; | error = ENXIO; | ||||
conf = NULL; | conf = NULL; | ||||
break; | break; | ||||
} | } | ||||
if (nd_ifp != NULL) | if (nd_ifp != NULL) | ||||
strlcpy(conf->kda_iface, nd_ifp->if_xname, | strlcpy(conf->kda_iface, nd_ifp->if_xname, | ||||
sizeof(conf->kda_iface)); | sizeof(conf->kda_iface)); | ||||
memcpy(&conf->kda_server, &nd_server, sizeof(nd_server)); | memcpy(&conf->kda_server, &nd_server, sizeof(nd_server)); | ||||
memcpy(&conf->kda_client, &nd_client, sizeof(nd_client)); | memcpy(&conf->kda_client, &nd_client, sizeof(nd_client)); | ||||
memcpy(&conf->kda_gateway, &nd_gateway, sizeof(nd_gateway)); | memcpy(&conf->kda_gateway, &nd_gateway, sizeof(nd_gateway)); | ||||
conf->kda_af = nd_conf.ndc_af; | conf->kda_af = nd_conf.ndc_af; | ||||
conf = NULL; | conf = NULL; | ||||
break; | break; | ||||
#ifdef COMPAT_FREEBSD12 | |||||
case NETDUMPSCONF_FREEBSD12: | |||||
gone_in(14, "FreeBSD 12.x ABI compat"); | |||||
conf12 = (struct netdump_conf_freebsd12 *)addr; | |||||
_Static_assert(offsetof(struct diocskerneldump_arg, kda_server) | |||||
== offsetof(struct netdump_conf_freebsd12, ndc12_server), | |||||
"simplifying assumption"); | |||||
memset(&kda_copy, 0, sizeof(kda_copy)); | |||||
memcpy(&kda_copy, conf12, | |||||
offsetof(struct diocskerneldump_arg, kda_server)); | |||||
/* 12.x ABI could only configure IPv4 (INET) netdump. */ | |||||
kda_copy.kda_af = AF_INET; | |||||
memcpy(&kda_copy.kda_server.in4, &conf12->ndc12_server, | |||||
sizeof(struct in_addr)); | |||||
memcpy(&kda_copy.kda_client.in4, &conf12->ndc12_client, | |||||
sizeof(struct in_addr)); | |||||
memcpy(&kda_copy.kda_gateway.in4, &conf12->ndc12_gateway, | |||||
sizeof(struct in_addr)); | |||||
kda_copy.kda_index = | |||||
(conf12->ndc12_kda.kda12_enable ? 0 : KDA_REMOVE_ALL); | |||||
conf = &kda_copy; | |||||
explicit_bzero(conf12, sizeof(*conf12)); | |||||
/* FALLTHROUGH */ | |||||
#endif | |||||
case DIOCSKERNELDUMP: | case DIOCSKERNELDUMP: | ||||
encryptedkey = NULL; | encryptedkey = NULL; | ||||
if (cmd == DIOCSKERNELDUMP) { | |||||
conf = (void *)addr; | conf = (void *)addr; | ||||
memcpy(&kda_copy, conf, sizeof(kda_copy)); | |||||
} | |||||
/* Netdump only supports IP4 at this time. */ | /* Netdump only supports IP4 at this time. */ | ||||
if (conf->kda_af != AF_INET) { | if (conf->kda_af != AF_INET) { | ||||
error = EPROTONOSUPPORT; | error = EPROTONOSUPPORT; | ||||
break; | break; | ||||
} | } | ||||
conf->kda_iface[sizeof(conf->kda_iface) - 1] = '\0'; | conf->kda_iface[sizeof(conf->kda_iface) - 1] = '\0'; | ||||
if (conf->kda_index == KDA_REMOVE || | if (conf->kda_index == KDA_REMOVE || | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | case DIOCSKERNELDUMP: | ||||
zfree(encryptedkey, M_TEMP); | zfree(encryptedkey, M_TEMP); | ||||
if (error != 0) | if (error != 0) | ||||
netdump_unconfigure(); | netdump_unconfigure(); | ||||
break; | break; | ||||
default: | default: | ||||
error = ENOTTY; | error = ENOTTY; | ||||
break; | break; | ||||
} | } | ||||
explicit_bzero(&kda_copy, sizeof(kda_copy)); | |||||
if (conf != NULL) | if (conf != NULL) | ||||
explicit_bzero(conf, sizeof(*conf)); | explicit_bzero(conf, sizeof(*conf)); | ||||
NETDUMP_WUNLOCK(); | NETDUMP_WUNLOCK(); | ||||
return (error); | return (error); | ||||
} | } | ||||
/* | /* | ||||
* Called upon system init or kld load. Initializes the netdump parameters to | * Called upon system init or kld load. Initializes the netdump parameters to | ||||
▲ Show 20 Lines • Show All 154 Lines • Show Last 20 Lines |