From 589f6ed8ce4b9da11cbdce95d6dcf9ad45792175 Mon Sep 17 00:00:00 2001 From: Julian Elischer Date: Mon, 18 Dec 2000 20:03:32 +0000 Subject: 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) --- sys/dev/sr/if_sr.c | 63 ++++++++++++++++++++++++-------------------------- sys/dev/sr/if_sr_isa.c | 63 ++++++++++++++++++++++++-------------------------- 2 files changed, 60 insertions(+), 66 deletions(-) (limited to 'sys/dev/sr') diff --git a/sys/dev/sr/if_sr.c b/sys/dev/sr/if_sr.c index 78acfdd26b58..9ca41d47f22a 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 78acfdd26b58..9ca41d47f22a 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); } -- cgit v1.3