Changeset View
Standalone View
sys/netgraph/ng_bridge.c
Show First 20 Lines • Show All 387 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
const priv_p priv = NG_NODE_PRIVATE(node); | const priv_p priv = NG_NODE_PRIVATE(node); | ||||
struct ng_mesg *resp = NULL; | struct ng_mesg *resp = NULL; | ||||
int error = 0; | int error = 0; | ||||
struct ng_mesg *msg; | struct ng_mesg *msg; | ||||
NGI_GET_MSG(item, msg); | NGI_GET_MSG(item, msg); | ||||
switch (msg->header.typecookie) { | switch (msg->header.typecookie) { | ||||
#ifdef NGM_BRIDGE_TABLE_ABI | |||||
case NGM_BRIDGE_COOKIE_TBL: | |||||
switch (msg->header.cmd) { | |||||
case NGM_BRIDGE_GET_CONFIG: | |||||
{ | |||||
struct ng_bridge_config_tbl *conf; | |||||
NG_MKRESPONSE(resp, msg, | |||||
sizeof(struct ng_bridge_config_tbl), | |||||
M_NOWAIT|M_ZERO); | |||||
if (resp == NULL) { | |||||
error = ENOMEM; | |||||
goto out; | |||||
} | |||||
conf = (struct ng_bridge_config_tbl *)resp->data; | |||||
conf->cfg = priv->conf; | |||||
break; | |||||
julian: replace with "goto skip" | |||||
} | |||||
case NGM_BRIDGE_SET_CONFIG: | |||||
{ | |||||
struct ng_bridge_config_tbl *conf; | |||||
if (msg->header.arglen | |||||
!= sizeof(struct ng_bridge_config_tbl)) { | |||||
error = EINVAL; | |||||
goto out; | |||||
} | |||||
conf = (struct ng_bridge_config_tbl *)msg->data; | |||||
priv->conf = conf->cfg; | |||||
break; | |||||
Done Inline Actionsreplace with "goto skip;" julian: replace with "goto skip;" | |||||
} | |||||
case NGM_BRIDGE_GET_TABLE: | |||||
{ | |||||
struct ng_bridge_host_tbl_ary *ary; | |||||
struct ng_bridge_hent *hent; | |||||
int i = 0, bucket; | |||||
NG_MKRESPONSE(resp, msg, sizeof(*ary) | |||||
+ (priv->numHosts * sizeof(*ary->hosts)), M_NOWAIT); | |||||
if (resp == NULL) { | |||||
error = ENOMEM; | |||||
goto out; | |||||
} | |||||
ary = (struct ng_bridge_host_tbl_ary *)resp->data; | |||||
ary->numHosts = priv->numHosts; | |||||
for (bucket = 0; bucket < priv->numBuckets; bucket++) { | |||||
SLIST_FOREACH(hent, &priv->tab[bucket], next) { | |||||
memcpy(ary->hosts[i].addr, | |||||
hent->host.addr, | |||||
sizeof(ary->hosts[i].addr)); | |||||
ary->hosts[i].age = hent->host.age; | |||||
ary->hosts[i].staleness = hent->host.staleness; | |||||
ary->hosts[i].linkNum = | |||||
strtol(NG_HOOK_NAME(hent->host.link->hook) + | |||||
strlen(NG_BRIDGE_HOOK_LINK_PREFIX), | |||||
NULL, 10); | |||||
i++; | |||||
} | |||||
} | |||||
break; | |||||
Done Inline Actionsreplace with "goto skip;" julian: replace with "goto skip;" | |||||
} | |||||
} | |||||
if(resp != NULL) /* already handled, otherwise use new ABI */ | |||||
Done Inline ActionsI was editing this down to wrap lines, remove white space, etc. and noticed that this dos not seem to be right unless I misread something? If we get a NGM_BRIDGE_GET_CONFIG / NGM_BRIDGE_SET_CONFIG / NGM_BRIDGE_GET_TABLE on the NGM_BRIDGE_COOKIE_TBL and fall through then the same cases will be run again and we'll leak memory and and overwrite the original COOKIE_TBL work in the BGM_BRIDGE_COOKIE branch given the next NG_MKRESPONSE() will just allocate new memory again and assign it to resp once more? It's probably only really bad for the two GET commands and the SET command would probably fail? bz: I was editing this down to wrap lines, remove white space, etc. and noticed that this dos not… | |||||
bzUnsubmitted Done Inline ActionsI think this should be: if (resp != NULL || error != 0) break; and the goto out and the label should all vanish again. NG_RESPOND_MSG() still does a NG_FREE_ITEM(item) if resp == NULL and we do want to run through that. It'd also contain the change to within the #ifdef block which I would consider a feature. bz: I think this should be:
if (resp != NULL || error != 0)
break;
and the goto out and… | |||||
break; | |||||
#endif /* NGM_BRIDGE_TABLE_ABI */ | |||||
case NGM_BRIDGE_COOKIE: | case NGM_BRIDGE_COOKIE: | ||||
switch (msg->header.cmd) { | switch (msg->header.cmd) { | ||||
case NGM_BRIDGE_GET_CONFIG: | case NGM_BRIDGE_GET_CONFIG: | ||||
{ | { | ||||
struct ng_bridge_config *conf; | struct ng_bridge_config *conf; | ||||
NG_MKRESPONSE(resp, msg, | NG_MKRESPONSE(resp, msg, | ||||
sizeof(struct ng_bridge_config), M_NOWAIT); | sizeof(struct ng_bridge_config), M_NOWAIT); | ||||
if (resp == NULL) { | if (resp == NULL) { | ||||
error = ENOMEM; | error = ENOMEM; | ||||
break; | goto out; | ||||
} | } | ||||
conf = (struct ng_bridge_config *)resp->data; | conf = (struct ng_bridge_config *)resp->data; | ||||
*conf = priv->conf; /* no sanity checking needed */ | *conf = priv->conf; /* no sanity checking needed */ | ||||
break; | break; | ||||
} | } | ||||
case NGM_BRIDGE_SET_CONFIG: | case NGM_BRIDGE_SET_CONFIG: | ||||
{ | { | ||||
struct ng_bridge_config *conf; | struct ng_bridge_config *conf; | ||||
if (msg->header.arglen | if (msg->header.arglen | ||||
!= sizeof(struct ng_bridge_config)) { | != sizeof(struct ng_bridge_config)) { | ||||
error = EINVAL; | error = EINVAL; | ||||
break; | goto out; | ||||
} | } | ||||
conf = (struct ng_bridge_config *)msg->data; | conf = (struct ng_bridge_config *)msg->data; | ||||
priv->conf = *conf; | priv->conf = *conf; | ||||
break; | break; | ||||
} | } | ||||
case NGM_BRIDGE_RESET: | case NGM_BRIDGE_RESET: | ||||
{ | { | ||||
hook_p rethook; | hook_p rethook; | ||||
Show All 12 Lines | case NGM_BRIDGE_GETCLR_STATS: | ||||
{ | { | ||||
hook_p hook; | hook_p hook; | ||||
link_p link; | link_p link; | ||||
char linkName[NG_HOOKSIZ]; | char linkName[NG_HOOKSIZ]; | ||||
/* Get link number */ | /* Get link number */ | ||||
if (msg->header.arglen != sizeof(u_int32_t)) { | if (msg->header.arglen != sizeof(u_int32_t)) { | ||||
error = EINVAL; | error = EINVAL; | ||||
break; | goto out; | ||||
} | } | ||||
snprintf(linkName, sizeof(linkName), | snprintf(linkName, sizeof(linkName), | ||||
"%s%u", NG_BRIDGE_HOOK_LINK_PREFIX, | "%s%u", NG_BRIDGE_HOOK_LINK_PREFIX, | ||||
*((u_int32_t *)msg->data)); | *((u_int32_t *)msg->data)); | ||||
if ((hook = ng_findhook(node, linkName)) == NULL) { | if ((hook = ng_findhook(node, linkName)) == NULL) { | ||||
error = ENOTCONN; | error = ENOTCONN; | ||||
break; | goto out; | ||||
} | } | ||||
link = NG_HOOK_PRIVATE(hook); | link = NG_HOOK_PRIVATE(hook); | ||||
/* Get/clear stats */ | /* Get/clear stats */ | ||||
if (msg->header.cmd != NGM_BRIDGE_CLR_STATS) { | if (msg->header.cmd != NGM_BRIDGE_CLR_STATS) { | ||||
NG_MKRESPONSE(resp, msg, | NG_MKRESPONSE(resp, msg, | ||||
sizeof(link->stats), M_NOWAIT); | sizeof(link->stats), M_NOWAIT); | ||||
if (resp == NULL) { | if (resp == NULL) { | ||||
error = ENOMEM; | error = ENOMEM; | ||||
break; | goto out; | ||||
} | } | ||||
bcopy(&link->stats, | bcopy(&link->stats, | ||||
resp->data, sizeof(link->stats)); | resp->data, sizeof(link->stats)); | ||||
} | } | ||||
if (msg->header.cmd != NGM_BRIDGE_GET_STATS) | if (msg->header.cmd != NGM_BRIDGE_GET_STATS) | ||||
bzero(&link->stats, sizeof(link->stats)); | bzero(&link->stats, sizeof(link->stats)); | ||||
break; | break; | ||||
} | } | ||||
case NGM_BRIDGE_GET_TABLE: | case NGM_BRIDGE_GET_TABLE: | ||||
{ | { | ||||
struct ng_bridge_host_ary *ary; | struct ng_bridge_host_ary *ary; | ||||
struct ng_bridge_hent *hent; | struct ng_bridge_hent *hent; | ||||
int i = 0, bucket; | int i = 0, bucket; | ||||
NG_MKRESPONSE(resp, msg, sizeof(*ary) | NG_MKRESPONSE(resp, msg, sizeof(*ary) | ||||
+ (priv->numHosts * sizeof(*ary->hosts)), M_NOWAIT); | + (priv->numHosts * sizeof(*ary->hosts)), M_NOWAIT); | ||||
if (resp == NULL) { | if (resp == NULL) { | ||||
error = ENOMEM; | error = ENOMEM; | ||||
break; | goto out; | ||||
} | } | ||||
ary = (struct ng_bridge_host_ary *)resp->data; | ary = (struct ng_bridge_host_ary *)resp->data; | ||||
ary->numHosts = priv->numHosts; | ary->numHosts = priv->numHosts; | ||||
for (bucket = 0; bucket < priv->numBuckets; bucket++) { | for (bucket = 0; bucket < priv->numBuckets; bucket++) { | ||||
SLIST_FOREACH(hent, &priv->tab[bucket], next) { | SLIST_FOREACH(hent, &priv->tab[bucket], next) { | ||||
memcpy(ary->hosts[i].addr, | memcpy(ary->hosts[i].addr, | ||||
hent->host.addr, | hent->host.addr, | ||||
sizeof(ary->hosts[i].addr)); | sizeof(ary->hosts[i].addr)); | ||||
Show All 9 Lines | case NGM_BRIDGE_GET_TABLE: | ||||
} | } | ||||
case NGM_BRIDGE_SET_PERSISTENT: | case NGM_BRIDGE_SET_PERSISTENT: | ||||
{ | { | ||||
priv->persistent = 1; | priv->persistent = 1; | ||||
break; | break; | ||||
} | } | ||||
default: | default: | ||||
error = EINVAL; | error = EINVAL; | ||||
break; | goto out; | ||||
} | } | ||||
break; | break; | ||||
default: | default: | ||||
error = EINVAL; | error = EINVAL; | ||||
break; | goto out; | ||||
} | } | ||||
/* Done */ | /* Done */ | ||||
NG_RESPOND_MSG(error, node, item, resp); | NG_RESPOND_MSG(error, node, item, resp); | ||||
out: | |||||
Done Inline Actionsadd label "skip:" julian: add label "skip:" | |||||
NG_FREE_MSG(msg); | NG_FREE_MSG(msg); | ||||
return (error); | return (error); | ||||
} | } | ||||
/* | /* | ||||
* Receive data on a hook | * Receive data on a hook | ||||
*/ | */ | ||||
struct ng_bridge_send_ctx { | struct ng_bridge_send_ctx { | ||||
▲ Show 20 Lines • Show All 514 Lines • Show Last 20 Lines |
replace with "goto skip"