ng_lmi.c (69922) | ng_lmi.c (70159) |
---|---|
1 2/* 3 * ng_lmi.c 4 * 5 * Copyright (c) 1996-1999 Whistle Communications, Inc. 6 * All rights reserved. 7 * 8 * Subject to the following obligations and disclaimer of warranty, use and --- 22 unchanged lines hidden (view full) --- 31 * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY 32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 34 * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY 35 * OF SUCH DAMAGE. 36 * 37 * Author: Julian Elischer <julian@freebsd.org> 38 * | 1 2/* 3 * ng_lmi.c 4 * 5 * Copyright (c) 1996-1999 Whistle Communications, Inc. 6 * All rights reserved. 7 * 8 * Subject to the following obligations and disclaimer of warranty, use and --- 22 unchanged lines hidden (view full) --- 31 * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY 32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 34 * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY 35 * OF SUCH DAMAGE. 36 * 37 * Author: Julian Elischer <julian@freebsd.org> 38 * |
39 * $FreeBSD: head/sys/netgraph/ng_lmi.c 69922 2000-12-12 18:52:14Z julian $ | 39 * $FreeBSD: head/sys/netgraph/ng_lmi.c 70159 2000-12-18 20:03:32Z julian $ |
40 * $Whistle: ng_lmi.c,v 1.38 1999/11/01 09:24:52 julian Exp $ 41 */ 42 43/* 44 * This node performs the frame relay LMI protocol. It knows how 45 * to do ITU Annex A, ANSI Annex D, and "Group-of-Four" variants 46 * of the protocol. 47 * --- 45 unchanged lines hidden (view full) --- 93static ng_rcvmsg_t nglmi_rcvmsg; 94static ng_shutdown_t nglmi_rmnode; 95static ng_newhook_t nglmi_newhook; 96static ng_rcvdata_t nglmi_rcvdata; 97static ng_disconnect_t nglmi_disconnect; 98static int nglmi_checkdata(hook_p hook, struct mbuf *m, meta_p meta); 99 100static struct ng_type typestruct = { | 40 * $Whistle: ng_lmi.c,v 1.38 1999/11/01 09:24:52 julian Exp $ 41 */ 42 43/* 44 * This node performs the frame relay LMI protocol. It knows how 45 * to do ITU Annex A, ANSI Annex D, and "Group-of-Four" variants 46 * of the protocol. 47 * --- 45 unchanged lines hidden (view full) --- 93static ng_rcvmsg_t nglmi_rcvmsg; 94static ng_shutdown_t nglmi_rmnode; 95static ng_newhook_t nglmi_newhook; 96static ng_rcvdata_t nglmi_rcvdata; 97static ng_disconnect_t nglmi_disconnect; 98static int nglmi_checkdata(hook_p hook, struct mbuf *m, meta_p meta); 99 100static struct ng_type typestruct = { |
101 NG_VERSION, | 101 NG_ABI_VERSION, |
102 NG_LMI_NODE_TYPE, 103 NULL, 104 nglmi_constructor, 105 nglmi_rcvmsg, 106 nglmi_rmnode, 107 nglmi_newhook, 108 NULL, 109 NULL, --- 335 unchanged lines hidden (view full) --- 445 sc->poll_count--; 446} 447 448/* 449 * Receive a netgraph control message. 450 */ 451static int 452nglmi_rcvmsg(node_p node, struct ng_mesg *msg, const char *retaddr, | 102 NG_LMI_NODE_TYPE, 103 NULL, 104 nglmi_constructor, 105 nglmi_rcvmsg, 106 nglmi_rmnode, 107 nglmi_newhook, 108 NULL, 109 NULL, --- 335 unchanged lines hidden (view full) --- 445 sc->poll_count--; 446} 447 448/* 449 * Receive a netgraph control message. 450 */ 451static int 452nglmi_rcvmsg(node_p node, struct ng_mesg *msg, const char *retaddr, |
453 struct ng_mesg **resp, hook_p lasthook) | 453 struct ng_mesg **rptr, hook_p lasthook) |
454{ | 454{ |
455 int error = 0; | |
456 sc_p sc = node->private; | 455 sc_p sc = node->private; |
456 struct ng_mesg *resp = NULL; 457 int error = 0; |
|
457 458 switch (msg->header.typecookie) { 459 case NGM_GENERIC_COOKIE: 460 switch (msg->header.cmd) { 461 case NGM_TEXT_STATUS: 462 { 463 char *arg; 464 int pos, count; 465 | 458 459 switch (msg->header.typecookie) { 460 case NGM_GENERIC_COOKIE: 461 switch (msg->header.cmd) { 462 case NGM_TEXT_STATUS: 463 { 464 char *arg; 465 int pos, count; 466 |
466 NG_MKRESPONSE(*resp, msg, NG_TEXTRESPONSE, M_NOWAIT); 467 if (*resp == NULL) { | 467 NG_MKRESPONSE(resp, msg, NG_TEXTRESPONSE, M_NOWAIT); 468 if (resp == NULL) { |
468 error = ENOMEM; 469 break; 470 } | 469 error = ENOMEM; 470 break; 471 } |
471 arg = (*resp)->data; | 472 arg = resp->data; |
472 pos = sprintf(arg, "protocol %s ", sc->protoname); 473 if (sc->flags & SCF_FIXED) 474 pos += sprintf(arg + pos, "fixed\n"); 475 else if (sc->flags & SCF_AUTO) 476 pos += sprintf(arg + pos, "auto-detecting\n"); 477 else 478 pos += sprintf(arg + pos, "auto on dlci %d\n", 479 (sc->lmi_channel == sc->lmi_channel0) ? --- 9 unchanged lines hidden (view full) --- 489 count++) { 490 if (sc->dlci_state[count]) { 491 pos += sprintf(arg + pos, 492 "dlci %d %s\n", count, 493 (sc->dlci_state[count] 494 == DLCI_UP) ? "up" : "down"); 495 } 496 } | 473 pos = sprintf(arg, "protocol %s ", sc->protoname); 474 if (sc->flags & SCF_FIXED) 475 pos += sprintf(arg + pos, "fixed\n"); 476 else if (sc->flags & SCF_AUTO) 477 pos += sprintf(arg + pos, "auto-detecting\n"); 478 else 479 pos += sprintf(arg + pos, "auto on dlci %d\n", 480 (sc->lmi_channel == sc->lmi_channel0) ? --- 9 unchanged lines hidden (view full) --- 490 count++) { 491 if (sc->dlci_state[count]) { 492 pos += sprintf(arg + pos, 493 "dlci %d %s\n", count, 494 (sc->dlci_state[count] 495 == DLCI_UP) ? "up" : "down"); 496 } 497 } |
497 (*resp)->header.arglen = pos + 1; | 498 resp->header.arglen = pos + 1; |
498 break; 499 } 500 default: 501 error = EINVAL; 502 break; 503 } 504 break; 505 case NGM_LMI_COOKIE: 506 switch (msg->header.cmd) { 507 case NGM_LMI_GET_STATUS: 508 { 509 struct nglmistat *stat; 510 int k; 511 | 499 break; 500 } 501 default: 502 error = EINVAL; 503 break; 504 } 505 break; 506 case NGM_LMI_COOKIE: 507 switch (msg->header.cmd) { 508 case NGM_LMI_GET_STATUS: 509 { 510 struct nglmistat *stat; 511 int k; 512 |
512 NG_MKRESPONSE(*resp, msg, sizeof(*stat), M_NOWAIT); 513 if (!*resp) { | 513 NG_MKRESPONSE(resp, msg, sizeof(*stat), M_NOWAIT); 514 if (!resp) { |
514 error = ENOMEM; 515 break; 516 } | 515 error = ENOMEM; 516 break; 517 } |
517 stat = (struct nglmistat *) (*resp)->data; | 518 stat = (struct nglmistat *) resp->data; |
518 strncpy(stat->proto, 519 sc->protoname, sizeof(stat->proto) - 1); 520 strncpy(stat->hook, 521 sc->protoname, sizeof(stat->hook) - 1); 522 stat->autod = !!(sc->flags & SCF_AUTO); 523 stat->fixed = !!(sc->flags & SCF_FIXED); 524 for (k = 0; k <= MAXDLCI; k++) { 525 switch (sc->dlci_state[k]) { --- 11 unchanged lines hidden (view full) --- 537 error = EINVAL; 538 break; 539 } 540 break; 541 default: 542 error = EINVAL; 543 break; 544 } | 519 strncpy(stat->proto, 520 sc->protoname, sizeof(stat->proto) - 1); 521 strncpy(stat->hook, 522 sc->protoname, sizeof(stat->hook) - 1); 523 stat->autod = !!(sc->flags & SCF_AUTO); 524 stat->fixed = !!(sc->flags & SCF_FIXED); 525 for (k = 0; k <= MAXDLCI; k++) { 526 switch (sc->dlci_state[k]) { --- 11 unchanged lines hidden (view full) --- 538 error = EINVAL; 539 break; 540 } 541 break; 542 default: 543 error = EINVAL; 544 break; 545 } |
546 547 if (rptr) 548 *rptr = resp; 549 else if (resp != NULL) 550 FREE(resp, M_NETGRAPH); 551 |
|
545 FREE(msg, M_NETGRAPH); 546 return (error); 547} 548 549#define STEPBY(stepsize) \ 550 do { \ 551 packetlen -= (stepsize); \ 552 data += (stepsize); \ --- 539 unchanged lines hidden --- | 552 FREE(msg, M_NETGRAPH); 553 return (error); 554} 555 556#define STEPBY(stepsize) \ 557 do { \ 558 packetlen -= (stepsize); \ 559 data += (stepsize); \ --- 539 unchanged lines hidden --- |