From 18dee1f739c19d536fd64bb1a5578d880ed64866 Mon Sep 17 00:00:00 2001 From: brian Date: Tue, 9 Nov 1999 19:05:48 +0000 Subject: Be a bit smarter when identifying a netgraph node (don't dereference NULL). --- usr.sbin/ppp/ether.c | 64 ++++++++-------------------------------------------- 1 file changed, 9 insertions(+), 55 deletions(-) (limited to 'usr.sbin/ppp/ether.c') diff --git a/usr.sbin/ppp/ether.c b/usr.sbin/ppp/ether.c index 2ec75a8..175ba79 100644 --- a/usr.sbin/ppp/ether.c +++ b/usr.sbin/ppp/ether.c @@ -612,6 +612,11 @@ ether_Create(struct physical *p) dev->timeout = p->cfg.cd.delay; dev->connected = CARRIER_PENDING; + + /* Hook things up so that we monitor dev->cs */ + p->desc.UpdateSet = ether_UpdateSet; + p->desc.IsSet = ether_IsSet; + p->desc.Read = ether_DescriptorRead; } else { /* See if we're a netgraph socket */ struct sockaddr_ng ngsock; @@ -621,53 +626,11 @@ ether_Create(struct physical *p) sz = sizeof ngsock; if (getsockname(p->fd, sock, &sz) != -1 && sock->sa_family == AF_NETGRAPH) { /* - * It's a netgraph node... determine the hook name and set things up - */ - - if (NgSendMsg(dev->cs, ".", NGM_GENERIC_COOKIE, NGM_LISTHOOKS, - NULL, 0) < 0) { - log_Printf(LogWARN, "Cannot send a netgraph message to stdin: %s\n", - strerror(errno)); - close(p->fd); - p->fd = -1; - return NULL; - } - - /* Get our list back */ - resp = (struct ng_mesg *)rbuf; - if (NgRecvMsg(dev->cs, resp, sizeof rbuf, NULL) < 0) { - log_Printf(LogWARN, "Cannot get netgraph response: %s\n", - strerror(errno)); - close(p->fd); - p->fd = -1; - return NULL; - } - - hlist = (const struct hooklist *)resp->data; - ninfo = &hlist->nodeinfo; - - /* - * Make sure we've got the right type of node... - * Can it be anything else ? + * It's a netgraph node... We can't determine hook names etc, so we + * stay pretty impartial.... */ - if (strncmp(ninfo->type, NG_SOCKET_NODE_TYPE, - sizeof NG_SOCKET_NODE_TYPE - 1)) { - log_Printf(LogWARN, "Unexpected netgraph node type ``%s'' (wanted ``" - NG_SOCKET_NODE_TYPE "'')\n", ninfo->type); - close(p->fd); - p->fd = -1; - return NULL; - } - - if (ninfo->hooks != 1) { - log_Printf(LogWARN, "Can't handle netgraph node with %d hooks\n", - ninfo->hooks); - close(p->fd); - p->fd = -1; - return NULL; - } + log_Printf(LogPHASE, "%s: Link is a netgraph node\n", p->link.name); - /* Looks good.... lets allocate a device structure */ if ((dev = malloc(sizeof *dev)) == NULL) { log_Printf(LogWARN, "%s: Cannot allocate an ether device: %s\n", p->link.name, strerror(errno)); @@ -677,22 +640,13 @@ ether_Create(struct physical *p) dev->cs = -1; dev->timeout = 0; dev->connected = CARRIER_OK; - strncpy(dev->hook, hlist->link->ourhook, sizeof dev->hook - 1); - dev->hook[sizeof dev->hook - 1] = '\0'; - - log_Printf(LogDEBUG, "Using netgraph hook ``.:%s'' -> [%x]:%s\n", - dev->hook, hlist->link->nodeinfo.id, hlist->link->peerhook); + *dev->hook = '\0'; } } if (dev) { memcpy(&dev->dev, &baseetherdevice, sizeof dev->dev); - /* Hook things up so that we monitor dev->cs */ - p->desc.UpdateSet = ether_UpdateSet; - p->desc.IsSet = ether_IsSet; - p->desc.Read = ether_DescriptorRead; - physical_SetupStack(p, dev->dev.name, PHYSICAL_FORCE_SYNCNOACF); /* Moan about (and fix) invalid LCP configurations */ -- cgit v1.1