summaryrefslogtreecommitdiffstats
path: root/sys/dev
diff options
context:
space:
mode:
authorjulian <julian@FreeBSD.org>2000-12-18 20:03:32 +0000
committerjulian <julian@FreeBSD.org>2000-12-18 20:03:32 +0000
commit0c949560a12dd18943b66fe09bd06d3c34e5cf7a (patch)
tree5466b04ac515e8d01f9b135b6c119744a1138d82 /sys/dev
parente6bd476191c5b338634a02b0a6de56aa7f23cf37 (diff)
downloadFreeBSD-src-0c949560a12dd18943b66fe09bd06d3c34e5cf7a.zip
FreeBSD-src-0c949560a12dd18943b66fe09bd06d3c34e5cf7a.tar.gz
Divorce the kernel binary ABI version number from the message
format version number. (userland programs should not need to be recompiled when the netgraph kernel internal ABI is changed. Also fix modules that don;t handle the fact that a caller may not supply a return message pointer. (benign at the moment because the calling code checks, but that will change)
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/ar/if_ar.c64
-rw-r--r--sys/dev/ar/if_ar_isa.c64
-rw-r--r--sys/dev/lmc/if_lmc.c16
-rw-r--r--sys/dev/musycc/musycc.c58
-rw-r--r--sys/dev/sr/if_sr.c63
-rw-r--r--sys/dev/sr/if_sr_isa.c63
-rw-r--r--sys/dev/usb/udbp.c2
7 files changed, 164 insertions, 166 deletions
diff --git a/sys/dev/ar/if_ar.c b/sys/dev/ar/if_ar.c
index ad5aac9..fe9abeb 100644
--- a/sys/dev/ar/if_ar.c
+++ b/sys/dev/ar/if_ar.c
@@ -275,7 +275,7 @@ static ng_rcvdata_t ngar_rcvdata;
static ng_disconnect_t ngar_disconnect;
static struct ng_type typestruct = {
- NG_VERSION,
+ NG_ABI_VERSION,
NG_AR_NODE_TYPE,
NULL,
ngar_constructor,
@@ -2216,66 +2216,64 @@ ngar_newhook(node_p node, hook_p hook, const char *name)
* Just respond to the generic TEXT_STATUS message
*/
static int
-ngar_rcvmsg(node_p node, struct ng_mesg *msg,
- const char *retaddr, struct ng_mesg **resp, hook_p lasthook)
+ngar_rcvmsg(node_p node, struct ng_mesg *msg, const char *retaddr,
+ struct ng_mesg **rptr, hook_p lasthook)
{
struct ar_softc * sc;
+ struct ng_mesg *resp = NULL;
int error = 0;
sc = node->private;
switch (msg->header.typecookie) {
- case NG_AR_COOKIE:
+ case NG_AR_COOKIE:
error = EINVAL;
break;
- case NGM_GENERIC_COOKIE:
+ case NGM_GENERIC_COOKIE:
switch(msg->header.cmd) {
- case NGM_TEXT_STATUS: {
- char *arg;
- int pos = 0;
- int resplen = sizeof(struct ng_mesg) + 512;
- MALLOC(*resp, struct ng_mesg *, resplen,
- M_NETGRAPH, M_NOWAIT | M_ZERO);
- if (*resp == NULL) {
+ case NGM_TEXT_STATUS: {
+ char *arg;
+ int pos = 0;
+
+ int resplen = sizeof(struct ng_mesg) + 512;
+ NG_MKRESPONSE(resp, msg, resplen, M_NOWAIT);
+ if (resp == NULL) {
error = ENOMEM;
break;
- }
- arg = (*resp)->data;
-
- /*
- * Put in the throughput information.
- */
- pos = sprintf(arg, "%ld bytes in, %ld bytes out\n"
+ }
+ arg = (resp)->data;
+ pos = sprintf(arg, "%ld bytes in, %ld bytes out\n"
"highest rate seen: %ld B/S in, %ld B/S out\n",
- sc->inbytes, sc->outbytes,
- sc->inrate, sc->outrate);
- pos += sprintf(arg + pos,
+ sc->inbytes, sc->outbytes,
+ sc->inrate, sc->outrate);
+ pos += sprintf(arg + pos,
"%ld output errors\n",
sc->oerrors);
- pos += sprintf(arg + pos,
+ pos += sprintf(arg + pos,
"ierrors = %ld, %ld, %ld, %ld\n",
sc->ierrors[0],
sc->ierrors[1],
sc->ierrors[2],
sc->ierrors[3]);
- (*resp)->header.version = NG_VERSION;
- (*resp)->header.arglen = strlen(arg) + 1;
- (*resp)->header.token = msg->header.token;
- (*resp)->header.typecookie = NG_AR_COOKIE;
- (*resp)->header.cmd = msg->header.cmd;
- strncpy((*resp)->header.cmdstr, "status",
- NG_CMDSTRLEN);
- }
+ resp->header.arglen = pos + 1;
break;
- default:
+ }
+ default:
error = EINVAL;
break;
}
break;
- default:
+ default:
error = EINVAL;
break;
}
+ /* Take care of synchronous response, if any */
+ if (rptr)
+ *rptr = resp;
+ else if (resp)
+ /* Should send the hard way */
+ FREE(resp, M_NETGRAPH);
+
free(msg, M_NETGRAPH);
return (error);
}
diff --git a/sys/dev/ar/if_ar_isa.c b/sys/dev/ar/if_ar_isa.c
index ad5aac9..fe9abeb 100644
--- a/sys/dev/ar/if_ar_isa.c
+++ b/sys/dev/ar/if_ar_isa.c
@@ -275,7 +275,7 @@ static ng_rcvdata_t ngar_rcvdata;
static ng_disconnect_t ngar_disconnect;
static struct ng_type typestruct = {
- NG_VERSION,
+ NG_ABI_VERSION,
NG_AR_NODE_TYPE,
NULL,
ngar_constructor,
@@ -2216,66 +2216,64 @@ ngar_newhook(node_p node, hook_p hook, const char *name)
* Just respond to the generic TEXT_STATUS message
*/
static int
-ngar_rcvmsg(node_p node, struct ng_mesg *msg,
- const char *retaddr, struct ng_mesg **resp, hook_p lasthook)
+ngar_rcvmsg(node_p node, struct ng_mesg *msg, const char *retaddr,
+ struct ng_mesg **rptr, hook_p lasthook)
{
struct ar_softc * sc;
+ struct ng_mesg *resp = NULL;
int error = 0;
sc = node->private;
switch (msg->header.typecookie) {
- case NG_AR_COOKIE:
+ case NG_AR_COOKIE:
error = EINVAL;
break;
- case NGM_GENERIC_COOKIE:
+ case NGM_GENERIC_COOKIE:
switch(msg->header.cmd) {
- case NGM_TEXT_STATUS: {
- char *arg;
- int pos = 0;
- int resplen = sizeof(struct ng_mesg) + 512;
- MALLOC(*resp, struct ng_mesg *, resplen,
- M_NETGRAPH, M_NOWAIT | M_ZERO);
- if (*resp == NULL) {
+ case NGM_TEXT_STATUS: {
+ char *arg;
+ int pos = 0;
+
+ int resplen = sizeof(struct ng_mesg) + 512;
+ NG_MKRESPONSE(resp, msg, resplen, M_NOWAIT);
+ if (resp == NULL) {
error = ENOMEM;
break;
- }
- arg = (*resp)->data;
-
- /*
- * Put in the throughput information.
- */
- pos = sprintf(arg, "%ld bytes in, %ld bytes out\n"
+ }
+ arg = (resp)->data;
+ pos = sprintf(arg, "%ld bytes in, %ld bytes out\n"
"highest rate seen: %ld B/S in, %ld B/S out\n",
- sc->inbytes, sc->outbytes,
- sc->inrate, sc->outrate);
- pos += sprintf(arg + pos,
+ sc->inbytes, sc->outbytes,
+ sc->inrate, sc->outrate);
+ pos += sprintf(arg + pos,
"%ld output errors\n",
sc->oerrors);
- pos += sprintf(arg + pos,
+ pos += sprintf(arg + pos,
"ierrors = %ld, %ld, %ld, %ld\n",
sc->ierrors[0],
sc->ierrors[1],
sc->ierrors[2],
sc->ierrors[3]);
- (*resp)->header.version = NG_VERSION;
- (*resp)->header.arglen = strlen(arg) + 1;
- (*resp)->header.token = msg->header.token;
- (*resp)->header.typecookie = NG_AR_COOKIE;
- (*resp)->header.cmd = msg->header.cmd;
- strncpy((*resp)->header.cmdstr, "status",
- NG_CMDSTRLEN);
- }
+ resp->header.arglen = pos + 1;
break;
- default:
+ }
+ default:
error = EINVAL;
break;
}
break;
- default:
+ default:
error = EINVAL;
break;
}
+ /* Take care of synchronous response, if any */
+ if (rptr)
+ *rptr = resp;
+ else if (resp)
+ /* Should send the hard way */
+ FREE(resp, M_NETGRAPH);
+
free(msg, M_NETGRAPH);
return (error);
}
diff --git a/sys/dev/lmc/if_lmc.c b/sys/dev/lmc/if_lmc.c
index 3bec1fa..0aa6ea6 100644
--- a/sys/dev/lmc/if_lmc.c
+++ b/sys/dev/lmc/if_lmc.c
@@ -174,7 +174,7 @@ static const struct ng_cmdlist ng_lmc_cmdlist[] = {
};
static struct ng_type typestruct = {
- NG_VERSION,
+ NG_ABI_VERSION,
NG_LMC_NODE_TYPE,
NULL,
ng_lmc_constructor,
@@ -1341,9 +1341,9 @@ ng_lmc_rcvmsg(node_p node, struct ng_mesg *msg,
case NGM_TEXT_STATUS: {
char *arg;
int pos = 0;
+
int resplen = sizeof(struct ng_mesg) + 512;
- MALLOC(resp, struct ng_mesg *, resplen, M_NETGRAPH,
- M_NOWAIT | M_ZERO);
+ NG_MKRESPONSE(resp, msg, resplen, M_NOWAIT);
if (resp == NULL) {
error = ENOMEM;
break;
@@ -1363,15 +1363,9 @@ ng_lmc_rcvmsg(node_p node, struct ng_mesg *msg,
pos += sprintf(arg + pos, "%ld input errors\n",
sc->lmc_ierrors);
- resp->header.version = NG_VERSION;
- resp->header.arglen = strlen(arg) + 1;
- resp->header.token = msg->header.token;
- resp->header.typecookie = NG_LMC_COOKIE;
- resp->header.cmd = msg->header.cmd;
- strncpy(resp->header.cmdstr, "status",
- NG_CMDSTRLEN);
- }
+ resp->header.arglen = pos + 1;
break;
+ }
default:
error = EINVAL;
break;
diff --git a/sys/dev/musycc/musycc.c b/sys/dev/musycc/musycc.c
index c8f35ff..85ec6e0 100644
--- a/sys/dev/musycc/musycc.c
+++ b/sys/dev/musycc/musycc.c
@@ -265,7 +265,7 @@ static ng_rcvdata_t musycc_rcvdata;
static ng_disconnect_t musycc_disconnect;
static struct ng_type ngtypestruct = {
- NG_VERSION,
+ NG_ABI_VERSION,
NG_NODETYPE,
NULL,
musycc_constructor,
@@ -926,56 +926,70 @@ barf:
return;
}
+/*
+ * Handle status and config enquiries.
+ * Respond with a synchronous response.
+ * [JRE] -this would be easier to read with the usual 'switch' structure-
+ */
static int
-musycc_rcvmsg(node_p node, struct ng_mesg *msg, const char *retaddr, struct ng_mesg **resp, hook_p lasthook)
+musycc_rcvmsg(node_p node, struct ng_mesg *msg, const char *retaddr,
+ struct ng_mesg **rptr, hook_p lasthook)
{
struct softc *sc;
+ struct ng_mesg *resp = NULL;
char *s, *r;
+ int error = 0;
sc = node->private;
+ if (rptr)
+ *rptr = NULL; /* default answer in case of errors */
if (msg->header.typecookie != NGM_GENERIC_COOKIE)
goto out;
if (msg->header.cmd == NGM_TEXT_STATUS) {
- NG_MKRESPONSE(*resp, msg,
+ NG_MKRESPONSE(resp, msg,
sizeof(struct ng_mesg) + NG_TEXTRESPONSE, M_NOWAIT);
- if (*resp == NULL) {
- FREE(msg, M_NETGRAPH);
- return (ENOMEM);
+ if (resp == NULL) {
+ error = ENOMEM;
+ goto out;
}
- s = (char *)(*resp)->data;
+ s = (char *)resp->data;
status_8370(sc, s);
- (*resp)->header.arglen = strlen(s) + 1;
+ resp->header.arglen = strlen(s) + 1;
FREE(msg, M_NETGRAPH);
- return (0);
- }
- if (msg->header.cmd == NGM_TEXT_CONFIG) {
+
+ } else if (msg->header.cmd == NGM_TEXT_CONFIG) {
if (msg->header.arglen) {
s = (char *)msg->data;
} else {
s = NULL;
}
- NG_MKRESPONSE(*resp, msg,
+ NG_MKRESPONSE(resp, msg,
sizeof(struct ng_mesg) + NG_TEXTRESPONSE, M_NOWAIT);
- if (*resp == NULL) {
- FREE(msg, M_NETGRAPH);
- return (ENOMEM);
+ if (resp == NULL) {
+ error = ENOMEM;
+ goto out;
}
- r = (char *)(*resp)->data;
+ r = (char *)resp->data;
*r = '\0';
musycc_config(node, s, r);
- (*resp)->header.arglen = strlen(r) + 1;
+ resp->header.arglen = strlen(r) + 1;
FREE(msg, M_NETGRAPH);
- return (0);
- }
+ } else {
+ error = EINVAL;
+ }
out:
- if (resp)
- *resp = NULL;
+ /* Take care of synchronous response, if any */
+ if (rptr)
+ *rptr = resp;
+ else if (resp)
+ FREE(resp, M_NETGRAPH); /* eventually 'send' the response */
+
FREE(msg, M_NETGRAPH);
- return (EINVAL);
+ return (error);
}
static int
diff --git a/sys/dev/sr/if_sr.c b/sys/dev/sr/if_sr.c
index 78acfdd..9ca41d4 100644
--- a/sys/dev/sr/if_sr.c
+++ b/sys/dev/sr/if_sr.c
@@ -375,7 +375,7 @@ static ng_rcvdata_t ngsr_rcvdata;
static ng_disconnect_t ngsr_disconnect;
static struct ng_type typestruct = {
- NG_VERSION,
+ NG_ABI_VERSION,
NG_SR_NODE_TYPE,
NULL,
ngsr_constructor,
@@ -3170,41 +3170,38 @@ ngsr_newhook(node_p node, hook_p hook, const char *name)
*/
static int
ngsr_rcvmsg(node_p node, struct ng_mesg *msg, const char *retaddr,
- struct ng_mesg **resp, hook_p lasthook)
+ struct ng_mesg **rptr, hook_p lasthook)
{
struct sr_softc * sc;
+ struct ng_mesg *resp = NULL;
int error = 0;
sc = node->private;
switch (msg->header.typecookie) {
- case NG_SR_COOKIE:
+ case NG_SR_COOKIE:
error = EINVAL;
break;
- case NGM_GENERIC_COOKIE:
+ case NGM_GENERIC_COOKIE:
switch(msg->header.cmd) {
- case NGM_TEXT_STATUS: {
- char *arg;
- int pos = 0;
- int resplen = sizeof(struct ng_mesg) + 512;
- MALLOC(*resp, struct ng_mesg *, resplen,
- M_NETGRAPH, M_NOWAIT | M_ZERO);
- if (*resp == NULL) {
+ case NGM_TEXT_STATUS: {
+ char *arg;
+ int pos = 0;
+
+ int resplen = sizeof(struct ng_mesg) + 512;
+ NG_MKRESPONSE(resp, msg, resplen, M_NOWAIT);
+ if (resp == NULL) {
error = ENOMEM;
break;
- }
- arg = (*resp)->data;
-
- /*
- * Put in the throughput information.
- */
- pos = sprintf(arg, "%ld bytes in, %ld bytes out\n"
+ }
+ arg = (resp)->data;
+ pos = sprintf(arg, "%ld bytes in, %ld bytes out\n"
"highest rate seen: %ld B/S in, %ld B/S out\n",
- sc->inbytes, sc->outbytes,
- sc->inrate, sc->outrate);
- pos += sprintf(arg + pos,
+ sc->inbytes, sc->outbytes,
+ sc->inrate, sc->outrate);
+ pos += sprintf(arg + pos,
"%ld output errors\n",
sc->oerrors);
- pos += sprintf(arg + pos,
+ pos += sprintf(arg + pos,
"ierrors = %ld, %ld, %ld, %ld, %ld, %ld\n",
sc->ierrors[0],
sc->ierrors[1],
@@ -3213,24 +3210,24 @@ ngsr_rcvmsg(node_p node, struct ng_mesg *msg, const char *retaddr,
sc->ierrors[4],
sc->ierrors[5]);
- (*resp)->header.version = NG_VERSION;
- (*resp)->header.arglen = strlen(arg) + 1;
- (*resp)->header.token = msg->header.token;
- (*resp)->header.typecookie = NG_SR_COOKIE;
- (*resp)->header.cmd = msg->header.cmd;
- strncpy((*resp)->header.cmdstr, "status",
- NG_CMDSTRLEN);
- }
+ resp->header.arglen = pos + 1;
break;
- default:
+ }
+ default:
error = EINVAL;
break;
- }
+ }
break;
- default:
+ default:
error = EINVAL;
break;
}
+ /* Take care of synchronous response, if any */
+ if (rptr)
+ *rptr = resp;
+ else if (resp)
+ FREE(resp, M_NETGRAPH);
+
free(msg, M_NETGRAPH);
return (error);
}
diff --git a/sys/dev/sr/if_sr_isa.c b/sys/dev/sr/if_sr_isa.c
index 78acfdd..9ca41d4 100644
--- a/sys/dev/sr/if_sr_isa.c
+++ b/sys/dev/sr/if_sr_isa.c
@@ -375,7 +375,7 @@ static ng_rcvdata_t ngsr_rcvdata;
static ng_disconnect_t ngsr_disconnect;
static struct ng_type typestruct = {
- NG_VERSION,
+ NG_ABI_VERSION,
NG_SR_NODE_TYPE,
NULL,
ngsr_constructor,
@@ -3170,41 +3170,38 @@ ngsr_newhook(node_p node, hook_p hook, const char *name)
*/
static int
ngsr_rcvmsg(node_p node, struct ng_mesg *msg, const char *retaddr,
- struct ng_mesg **resp, hook_p lasthook)
+ struct ng_mesg **rptr, hook_p lasthook)
{
struct sr_softc * sc;
+ struct ng_mesg *resp = NULL;
int error = 0;
sc = node->private;
switch (msg->header.typecookie) {
- case NG_SR_COOKIE:
+ case NG_SR_COOKIE:
error = EINVAL;
break;
- case NGM_GENERIC_COOKIE:
+ case NGM_GENERIC_COOKIE:
switch(msg->header.cmd) {
- case NGM_TEXT_STATUS: {
- char *arg;
- int pos = 0;
- int resplen = sizeof(struct ng_mesg) + 512;
- MALLOC(*resp, struct ng_mesg *, resplen,
- M_NETGRAPH, M_NOWAIT | M_ZERO);
- if (*resp == NULL) {
+ case NGM_TEXT_STATUS: {
+ char *arg;
+ int pos = 0;
+
+ int resplen = sizeof(struct ng_mesg) + 512;
+ NG_MKRESPONSE(resp, msg, resplen, M_NOWAIT);
+ if (resp == NULL) {
error = ENOMEM;
break;
- }
- arg = (*resp)->data;
-
- /*
- * Put in the throughput information.
- */
- pos = sprintf(arg, "%ld bytes in, %ld bytes out\n"
+ }
+ arg = (resp)->data;
+ pos = sprintf(arg, "%ld bytes in, %ld bytes out\n"
"highest rate seen: %ld B/S in, %ld B/S out\n",
- sc->inbytes, sc->outbytes,
- sc->inrate, sc->outrate);
- pos += sprintf(arg + pos,
+ sc->inbytes, sc->outbytes,
+ sc->inrate, sc->outrate);
+ pos += sprintf(arg + pos,
"%ld output errors\n",
sc->oerrors);
- pos += sprintf(arg + pos,
+ pos += sprintf(arg + pos,
"ierrors = %ld, %ld, %ld, %ld, %ld, %ld\n",
sc->ierrors[0],
sc->ierrors[1],
@@ -3213,24 +3210,24 @@ ngsr_rcvmsg(node_p node, struct ng_mesg *msg, const char *retaddr,
sc->ierrors[4],
sc->ierrors[5]);
- (*resp)->header.version = NG_VERSION;
- (*resp)->header.arglen = strlen(arg) + 1;
- (*resp)->header.token = msg->header.token;
- (*resp)->header.typecookie = NG_SR_COOKIE;
- (*resp)->header.cmd = msg->header.cmd;
- strncpy((*resp)->header.cmdstr, "status",
- NG_CMDSTRLEN);
- }
+ resp->header.arglen = pos + 1;
break;
- default:
+ }
+ default:
error = EINVAL;
break;
- }
+ }
break;
- default:
+ default:
error = EINVAL;
break;
}
+ /* Take care of synchronous response, if any */
+ if (rptr)
+ *rptr = resp;
+ else if (resp)
+ FREE(resp, M_NETGRAPH);
+
free(msg, M_NETGRAPH);
return (error);
}
diff --git a/sys/dev/usb/udbp.c b/sys/dev/usb/udbp.c
index 906f524..29e203e 100644
--- a/sys/dev/usb/udbp.c
+++ b/sys/dev/usb/udbp.c
@@ -185,7 +185,7 @@ Static const struct ng_cmdlist ng_udbp_cmdlist[] = {
/* Netgraph node type descriptor */
Static struct ng_type ng_udbp_typestruct = {
- NG_VERSION,
+ NG_ABI_VERSION,
NG_UDBP_NODE_TYPE,
NULL,
ng_udbp_constructor,
OpenPOWER on IntegriCloud