]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.sbin/ppp/ether.c
Bmake bits for Gcc 3.1.
[FreeBSD/FreeBSD.git] / usr.sbin / ppp / ether.c
1 /*-
2  * Copyright (c) 1999 Brian Somers <brian@Awfulhak.org>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  * $FreeBSD$
27  */
28
29 #include <sys/param.h>
30 #include <sys/socket.h>
31 #include <sys/un.h>
32 #include <netinet/in.h>
33 #include <arpa/inet.h>
34 #include <netdb.h>
35 #include <netgraph.h>
36 #include <net/ethernet.h>
37 #include <net/if.h>
38 #include <net/route.h>
39 #include <netinet/in_systm.h>
40 #include <netinet/ip.h>
41 #include <netgraph/ng_ether.h>
42 #include <netgraph/ng_message.h>
43 #include <netgraph/ng_pppoe.h>
44 #include <netgraph/ng_socket.h>
45
46 #include <errno.h>
47 #include <stdio.h>
48 #include <stdlib.h>
49 #include <string.h>
50 #include <sysexits.h>
51 #include <sys/fcntl.h>
52 #include <sys/stat.h>
53 #include <sys/uio.h>
54 #include <termios.h>
55 #include <sys/time.h>
56 #include <unistd.h>
57
58 #include "layer.h"
59 #include "defs.h"
60 #include "mbuf.h"
61 #include "log.h"
62 #include "timer.h"
63 #include "lqr.h"
64 #include "hdlc.h"
65 #include "throughput.h"
66 #include "fsm.h"
67 #include "lcp.h"
68 #include "ccp.h"
69 #include "link.h"
70 #include "async.h"
71 #include "descriptor.h"
72 #include "physical.h"
73 #include "main.h"
74 #include "mp.h"
75 #include "chat.h"
76 #include "auth.h"
77 #include "chap.h"
78 #include "cbcp.h"
79 #include "datalink.h"
80 #include "slcompress.h"
81 #include "iplist.h"
82 #include "ncpaddr.h"
83 #include "ip.h"
84 #include "ipcp.h"
85 #include "filter.h"
86 #ifndef NORADIUS
87 #include "radius.h"
88 #endif
89 #include "ipv6cp.h"
90 #include "ncp.h"
91 #include "bundle.h"
92 #include "id.h"
93 #include "iface.h"
94 #include "ether.h"
95
96
97 #define PPPOE_NODE_TYPE_LEN (sizeof NG_PPPOE_NODE_TYPE - 1) /* "PPPoE" */
98
99 struct etherdevice {
100   struct device dev;                    /* What struct physical knows about */
101   int cs;                               /* Control socket */
102   int connected;                        /* Are we connected yet ? */
103   int timeout;                          /* Seconds attempting to connect */
104   char hook[sizeof TUN_NAME + 11];      /* Our socket node hook */
105 };
106
107 #define device2ether(d) \
108   ((d)->type == ETHER_DEVICE ? (struct etherdevice *)d : NULL)
109
110 int
111 ether_DeviceSize(void)
112 {
113   return sizeof(struct etherdevice);
114 }
115
116 static ssize_t
117 ether_Write(struct physical *p, const void *v, size_t n)
118 {
119   struct etherdevice *dev = device2ether(p->handler);
120
121   return NgSendData(p->fd, dev->hook, v, n) == -1 ? -1 : n;
122 }
123
124 static ssize_t
125 ether_Read(struct physical *p, void *v, size_t n)
126 {
127   char hook[sizeof TUN_NAME + 11];
128
129   return NgRecvData(p->fd, v, n, hook);
130 }
131
132 static int
133 ether_RemoveFromSet(struct physical *p, fd_set *r, fd_set *w, fd_set *e)
134 {
135   struct etherdevice *dev = device2ether(p->handler);
136   int result;
137
138   if (r && dev->cs >= 0 && FD_ISSET(dev->cs, r)) {
139     FD_CLR(dev->cs, r);
140     log_Printf(LogTIMER, "%s: fdunset(ctrl) %d\n", p->link.name, dev->cs);
141     result = 1;
142   } else
143     result = 0;
144
145   /* Careful... physical_RemoveFromSet() called us ! */
146
147   p->handler->removefromset = NULL;
148   result += physical_RemoveFromSet(p, r, w, e);
149   p->handler->removefromset = ether_RemoveFromSet;
150
151   return result;
152 }
153
154 static void
155 ether_Free(struct physical *p)
156 {
157   struct etherdevice *dev = device2ether(p->handler);
158
159   physical_SetDescriptor(p);
160   if (dev->cs != -1)
161     close(dev->cs);
162   free(dev);
163 }
164
165 static const char *
166 ether_OpenInfo(struct physical *p)
167 {
168   struct etherdevice *dev = device2ether(p->handler);
169
170   switch (dev->connected) {
171     case CARRIER_PENDING:
172       return "negotiating";
173     case CARRIER_OK:
174       return "established";
175   }
176
177   return "disconnected";
178 }
179
180 static void
181 ether_device2iov(struct device *d, struct iovec *iov, int *niov,
182                  int maxiov, int *auxfd, int *nauxfd)
183 {
184   struct etherdevice *dev = device2ether(d);
185   int sz = physical_MaxDeviceSize();
186
187   iov[*niov].iov_base = realloc(d, sz);
188   if (iov[*niov].iov_base == NULL) {
189     log_Printf(LogALERT, "Failed to allocate memory: %d\n", sz);
190     AbortProgram(EX_OSERR);
191   }
192   iov[*niov].iov_len = sz;
193   (*niov)++;
194
195   if (dev->cs >= 0) {
196     *auxfd = dev->cs;
197     (*nauxfd)++;
198   }
199 }
200
201 static void
202 ether_MessageIn(struct etherdevice *dev)
203 {
204   char msgbuf[sizeof(struct ng_mesg) + sizeof(struct ngpppoe_sts)];
205   struct ng_mesg *rep = (struct ng_mesg *)msgbuf;
206   struct ngpppoe_sts *sts = (struct ngpppoe_sts *)(msgbuf + sizeof *rep);
207   char unknown[14];
208   const char *msg;
209   struct timeval t;
210   fd_set *r;
211   int ret;
212
213   if (dev->cs < 0)
214     return;
215
216   if ((r = mkfdset()) == NULL) {
217     log_Printf(LogERROR, "DoLoop: Cannot create fd_set\n");
218     return;
219   }
220   zerofdset(r);
221   FD_SET(dev->cs, r);
222   t.tv_sec = t.tv_usec = 0;
223   ret = select(dev->cs + 1, r, NULL, NULL, &t);
224   free(r);
225
226   if (ret <= 0)
227     return;
228
229   if (NgRecvMsg(dev->cs, rep, sizeof msgbuf, NULL) <= 0)
230     return;
231
232   if (rep->header.version != NG_VERSION) {
233     log_Printf(LogWARN, "%ld: Unexpected netgraph version, expected %ld\n",
234                (long)rep->header.version, (long)NG_VERSION);
235     return;
236   }
237
238   if (rep->header.typecookie != NGM_PPPOE_COOKIE) {
239     log_Printf(LogWARN, "%ld: Unexpected netgraph cookie, expected %ld\n",
240                (long)rep->header.typecookie, (long)NGM_PPPOE_COOKIE);
241     return;
242   }
243
244   switch (rep->header.cmd) {
245     case NGM_PPPOE_SET_FLAG:    msg = "SET_FLAG";       break;
246     case NGM_PPPOE_CONNECT:     msg = "CONNECT";        break;
247     case NGM_PPPOE_LISTEN:      msg = "LISTEN";         break;
248     case NGM_PPPOE_OFFER:       msg = "OFFER";          break;
249     case NGM_PPPOE_SUCCESS:     msg = "SUCCESS";        break;
250     case NGM_PPPOE_FAIL:        msg = "FAIL";           break;
251     case NGM_PPPOE_CLOSE:       msg = "CLOSE";          break;
252     case NGM_PPPOE_GET_STATUS:  msg = "GET_STATUS";     break;
253     case NGM_PPPOE_ACNAME:
254       msg = "ACNAME";
255       if (setenv("ACNAME", sts->hook, 1) != 0)
256         log_Printf(LogWARN, "setenv: cannot set ACNAME=%s: %m", sts->hook);
257       break;
258     default:
259       snprintf(unknown, sizeof unknown, "<%d>", (int)rep->header.cmd);
260       msg = unknown;
261       break;
262   }
263
264   log_Printf(LogPHASE, "Received NGM_PPPOE_%s (hook \"%s\")\n", msg, sts->hook);
265
266   switch (rep->header.cmd) {
267     case NGM_PPPOE_SUCCESS:
268       dev->connected = CARRIER_OK;
269       break;
270     case NGM_PPPOE_FAIL:
271     case NGM_PPPOE_CLOSE:
272       dev->connected = CARRIER_LOST;
273       break;
274   }
275 }
276
277 static int
278 ether_AwaitCarrier(struct physical *p)
279 {
280   struct etherdevice *dev = device2ether(p->handler);
281
282   if (dev->connected != CARRIER_OK && !dev->timeout--)
283     dev->connected = CARRIER_LOST;
284   else if (dev->connected == CARRIER_PENDING)
285     ether_MessageIn(dev);
286
287   return dev->connected;
288 }
289
290 static const struct device baseetherdevice = {
291   ETHER_DEVICE,
292   "ether",
293   1492,
294   { CD_REQUIRED, DEF_ETHERCDDELAY },
295   ether_AwaitCarrier,
296   ether_RemoveFromSet,
297   NULL,
298   NULL,
299   NULL,
300   NULL,
301   NULL,
302   ether_Free,
303   ether_Read,
304   ether_Write,
305   ether_device2iov,
306   NULL,
307   ether_OpenInfo
308 };
309
310 struct device *
311 ether_iov2device(int type, struct physical *p, struct iovec *iov, int *niov,
312                  int maxiov, int *auxfd, int *nauxfd)
313 {
314   if (type == ETHER_DEVICE) {
315     struct etherdevice *dev = (struct etherdevice *)iov[(*niov)++].iov_base;
316
317     dev = realloc(dev, sizeof *dev);    /* Reduce to the correct size */
318     if (dev == NULL) {
319       log_Printf(LogALERT, "Failed to allocate memory: %d\n",
320                  (int)(sizeof *dev));
321       AbortProgram(EX_OSERR);
322     }
323
324     if (*nauxfd) {
325       dev->cs = *auxfd;
326       (*nauxfd)--;
327     } else
328       dev->cs = -1;
329
330     /* Refresh function pointers etc */
331     memcpy(&dev->dev, &baseetherdevice, sizeof dev->dev);
332
333     physical_SetupStack(p, dev->dev.name, PHYSICAL_FORCE_SYNCNOACF);
334     return &dev->dev;
335   }
336
337   return NULL;
338 }
339
340 static int
341 ether_UpdateSet(struct fdescriptor *d, fd_set *r, fd_set *w, fd_set *e, int *n)
342 {
343   struct physical *p = descriptor2physical(d);
344   struct etherdevice *dev = device2ether(p->handler);
345   int result;
346
347   if (r && dev->cs >= 0) {
348     FD_SET(dev->cs, r);
349     log_Printf(LogTIMER, "%s(ctrl): fdset(r) %d\n", p->link.name, dev->cs);
350     result = 1;
351   } else
352     result = 0;
353
354   result += physical_doUpdateSet(d, r, w, e, n, 0);
355
356   return result;
357 }
358
359 static int
360 ether_IsSet(struct fdescriptor *d, const fd_set *fdset)
361 {
362   struct physical *p = descriptor2physical(d);
363   struct etherdevice *dev = device2ether(p->handler);
364   int result;
365
366   result = dev->cs >= 0 && FD_ISSET(dev->cs, fdset);
367   result += physical_IsSet(d, fdset);
368
369   return result;
370 }
371
372 static void
373 ether_DescriptorRead(struct fdescriptor *d, struct bundle *bundle,
374                      const fd_set *fdset)
375 {
376   struct physical *p = descriptor2physical(d);
377   struct etherdevice *dev = device2ether(p->handler);
378
379   if (dev->cs >= 0 && FD_ISSET(dev->cs, fdset)) {
380     ether_MessageIn(dev);
381     if (dev->connected == CARRIER_LOST) {
382       log_Printf(LogPHASE, "%s: Device disconnected\n", p->link.name);
383       datalink_Down(p->dl, CLOSE_NORMAL);
384       return;
385     }
386   }
387
388   if (physical_IsSet(d, fdset))
389     physical_DescriptorRead(d, bundle, fdset);
390 }
391
392 static struct device *
393 ether_Abandon(struct etherdevice *dev, struct physical *p)
394 {
395   /* Abandon our node construction */
396   close(dev->cs);
397   close(p->fd);
398   p->fd = -2;   /* Nobody else need try.. */
399   free(dev);
400
401   return NULL;
402 }
403
404 struct device *
405 ether_Create(struct physical *p)
406 {
407   u_char rbuf[2048];
408   struct etherdevice *dev;
409   struct ng_mesg *resp;
410   const struct hooklist *hlist;
411   const struct nodeinfo *ninfo;
412   char *path;
413   int ifacelen, f;
414
415   dev = NULL;
416   path = NULL;
417   ifacelen = 0;
418   if (p->fd < 0 && !strncasecmp(p->name.full, NG_PPPOE_NODE_TYPE,
419                                 PPPOE_NODE_TYPE_LEN) &&
420       p->name.full[PPPOE_NODE_TYPE_LEN] == ':') {
421     const struct linkinfo *nlink;
422     struct ngpppoe_init_data *data;
423     struct ngm_mkpeer mkp;
424     struct ngm_connect ngc;
425     const char *iface, *provider;
426     char etherid[12];
427     int providerlen;
428     char connectpath[sizeof dev->hook + 2];     /* .:<hook> */
429
430     p->fd--;                            /* We own the device - change fd */
431
432     loadmodules(LOAD_VERBOSLY, "netgraph", "ng_ether", "ng_pppoe", "ng_socket",
433                 NULL);
434
435     if ((dev = malloc(sizeof *dev)) == NULL)
436       return NULL;
437
438     iface = p->name.full + PPPOE_NODE_TYPE_LEN + 1;
439
440     provider = strchr(iface, ':');
441     if (provider) {
442       ifacelen = provider - iface;
443       provider++;
444       providerlen = strlen(provider);
445     } else {
446       ifacelen = strlen(iface);
447       provider = "";
448       providerlen = 0;
449     }
450
451     /*
452      * We're going to do this (where tunN is our tunnel device):
453      *
454      * .---------.
455      * |  ether  |
456      * | <iface> |                         dev->cs
457      * `---------'                           |
458      *  (orphan)                     p->fd   |
459      *     |                           |     |
460      *     |                           |     |
461      * (ethernet)                      |     |
462      * .---------.                  .-----------.
463      * |  pppoe  |                  |  socket   |
464      * | <iface> |(tunN)<---->(tunN)| <unnamed> |
465      * `---------                   `-----------'
466      *   (tunX)
467      *     ^
468      *     |
469      *     `--->(tunX)
470      */
471
472     /* Create a socket node */
473     if (ID0NgMkSockNode(NULL, &dev->cs, &p->fd) == -1) {
474       log_Printf(LogWARN, "Cannot create netgraph socket node: %s\n",
475                  strerror(errno));
476       free(dev);
477       p->fd = -2;
478       return NULL;
479     }
480
481     /*
482      * Ask for a list of hooks attached to the "ether" node.  This node should
483      * magically exist as a way of hooking stuff onto an ethernet device
484      */
485     path = (char *)alloca(ifacelen + 2);
486     sprintf(path, "%.*s:", ifacelen, iface);
487     if (NgSendMsg(dev->cs, path, NGM_GENERIC_COOKIE, NGM_LISTHOOKS,
488                   NULL, 0) < 0) {
489       log_Printf(LogWARN, "%s Cannot send a netgraph message: %s\n",
490                  path, strerror(errno));
491       return ether_Abandon(dev, p);
492     }
493
494     /* Get our list back */
495     resp = (struct ng_mesg *)rbuf;
496     if (NgRecvMsg(dev->cs, resp, sizeof rbuf, NULL) <= 0) {
497       log_Printf(LogWARN, "Cannot get netgraph response: %s\n",
498                  strerror(errno));
499       return ether_Abandon(dev, p);
500     }
501
502     hlist = (const struct hooklist *)resp->data;
503     ninfo = &hlist->nodeinfo;
504
505     /* Make sure we've got the right type of node */
506     if (strncmp(ninfo->type, NG_ETHER_NODE_TYPE,
507                 sizeof NG_ETHER_NODE_TYPE - 1)) {
508       log_Printf(LogWARN, "%s Unexpected node type ``%s'' (wanted ``"
509                  NG_ETHER_NODE_TYPE "'')\n", path, ninfo->type);
510       return ether_Abandon(dev, p);
511     }
512
513     log_Printf(LogDEBUG, "List of netgraph node ``%s'' (id %x) hooks:\n",
514                path, ninfo->id);
515
516     /* look for a hook already attached.  */
517     for (f = 0; f < ninfo->hooks; f++) {
518       nlink = &hlist->link[f];
519
520       log_Printf(LogDEBUG, "  Found %s -> %s\n", nlink->ourhook,
521                  nlink->peerhook);
522
523       if (!strcmp(nlink->ourhook, NG_ETHER_HOOK_ORPHAN) ||
524           !strcmp(nlink->ourhook, NG_ETHER_HOOK_DIVERT)) {
525         /*
526          * Something is using the data coming out of this ``ether'' node.
527          * If it's a PPPoE node, we use that node, otherwise we complain that
528          * someone else is using the node.
529          */
530         if (!strcmp(nlink->nodeinfo.type, NG_PPPOE_NODE_TYPE))
531           /* Use this PPPoE node ! */
532           snprintf(ngc.path, sizeof ngc.path, "[%x]:", nlink->nodeinfo.id);
533         else {
534           log_Printf(LogWARN, "%s Node type ``%s'' is currently active\n",
535                      path, nlink->nodeinfo.type);
536           return ether_Abandon(dev, p);
537         }
538         break;
539       }
540     }
541
542     if (f == ninfo->hooks) {
543       /*
544        * Create a new ``PPPoE'' node connected to the ``ether'' node using
545        * the ``orphan'' and ``ethernet'' hooks
546        */
547       snprintf(mkp.type, sizeof mkp.type, "%s", NG_PPPOE_NODE_TYPE);
548       snprintf(mkp.ourhook, sizeof mkp.ourhook, "%s", NG_ETHER_HOOK_ORPHAN);
549       snprintf(mkp.peerhook, sizeof mkp.peerhook, "%s", NG_PPPOE_HOOK_ETHERNET);
550       snprintf(etherid, sizeof etherid, "[%x]:", ninfo->id);
551
552       log_Printf(LogDEBUG, "Creating PPPoE netgraph node %s%s -> %s\n",
553                  etherid, mkp.ourhook, mkp.peerhook);
554
555       if (NgSendMsg(dev->cs, etherid, NGM_GENERIC_COOKIE,
556                     NGM_MKPEER, &mkp, sizeof mkp) < 0) {
557         log_Printf(LogWARN, "%s Cannot create PPPoE netgraph node: %s\n",
558                    etherid, strerror(errno));
559         return ether_Abandon(dev, p);
560       }
561
562       snprintf(ngc.path, sizeof ngc.path, "%s%s", path, NG_ETHER_HOOK_ORPHAN);
563     }
564
565     snprintf(dev->hook, sizeof dev->hook, "%s%d",
566              TUN_NAME, p->dl->bundle->unit);
567
568     /*
569      * Connect the PPPoE node to our socket node.
570      * ngc.path has already been set up
571      */
572     snprintf(ngc.ourhook, sizeof ngc.ourhook, "%s", dev->hook);
573     memcpy(ngc.peerhook, ngc.ourhook, sizeof ngc.peerhook);
574
575     log_Printf(LogDEBUG, "Connecting netgraph socket .:%s -> %s:%s\n",
576                ngc.ourhook, ngc.path, ngc.peerhook);
577     if (NgSendMsg(dev->cs, ".:", NGM_GENERIC_COOKIE,
578                   NGM_CONNECT, &ngc, sizeof ngc) < 0) {
579       log_Printf(LogWARN, "Cannot connect PPPoE and socket netgraph "
580                  "nodes: %s\n", strerror(errno));
581       return ether_Abandon(dev, p);
582     }
583
584     /* Bring the Ethernet interface up */
585     path[ifacelen] = '\0';      /* Remove the trailing ':' */
586     if (!iface_SetFlags(path, IFF_UP))
587       log_Printf(LogWARN, "%s: Failed to set the IFF_UP flag on %s\n",
588                  p->link.name, path);
589
590     /* And finally, request a connection to the given provider */
591
592     data = (struct ngpppoe_init_data *)alloca(sizeof *data + providerlen);
593     snprintf(data->hook, sizeof data->hook, "%s", dev->hook);
594     memcpy(data->data, provider, providerlen);
595     data->data_len = providerlen;
596
597     snprintf(connectpath, sizeof connectpath, ".:%s", dev->hook);
598     log_Printf(LogDEBUG, "Sending PPPOE_CONNECT to %s\n", connectpath);
599     if (NgSendMsg(dev->cs, connectpath, NGM_PPPOE_COOKIE,
600                   NGM_PPPOE_CONNECT, data, sizeof *data + providerlen) == -1) {
601       log_Printf(LogWARN, "``%s'': Cannot start netgraph node: %s\n",
602                  connectpath, strerror(errno));
603       return ether_Abandon(dev, p);
604     }
605
606     /* Hook things up so that we monitor dev->cs */
607     p->desc.UpdateSet = ether_UpdateSet;
608     p->desc.IsSet = ether_IsSet;
609     p->desc.Read = ether_DescriptorRead;
610
611     memcpy(&dev->dev, &baseetherdevice, sizeof dev->dev);
612     switch (p->cfg.cd.necessity) {
613       case CD_VARIABLE:
614         dev->dev.cd.delay = p->cfg.cd.delay;
615         break;
616       case CD_REQUIRED:
617         dev->dev.cd = p->cfg.cd;
618         break;
619       case CD_NOTREQUIRED:
620         log_Printf(LogWARN, "%s: Carrier must be set, using ``set cd %d!''\n",
621                    p->link.name, dev->dev.cd.delay);
622       case CD_DEFAULT:
623         break;
624     }
625
626     dev->timeout = dev->dev.cd.delay;
627     dev->connected = CARRIER_PENDING;
628
629   } else {
630     /* See if we're a netgraph socket */
631     struct stat st;
632
633     if (fstat(p->fd, &st) != -1 && (st.st_mode & S_IFSOCK)) {
634       struct sockaddr_storage ssock;
635       struct sockaddr *sock = (struct sockaddr *)&ssock;
636       int sz;
637
638       sz = sizeof ssock;
639       if (getsockname(p->fd, sock, &sz) == -1) {
640         log_Printf(LogPHASE, "%s: Link is a closed socket !\n", p->link.name);
641         close(p->fd);
642         p->fd = -1;
643         return NULL;
644       }
645
646       if (sock->sa_family == AF_NETGRAPH) {
647         /*
648          * It's a netgraph node... We can't determine hook names etc, so we
649          * stay pretty impartial....
650          */
651         log_Printf(LogPHASE, "%s: Link is a netgraph node\n", p->link.name);
652
653         if ((dev = malloc(sizeof *dev)) == NULL) {
654           log_Printf(LogWARN, "%s: Cannot allocate an ether device: %s\n",
655                      p->link.name, strerror(errno));
656           return NULL;
657         }
658
659         memcpy(&dev->dev, &baseetherdevice, sizeof dev->dev);
660         dev->cs = -1;
661         dev->timeout = 0;
662         dev->connected = CARRIER_OK;
663         *dev->hook = '\0';
664       }
665     }
666   }
667
668   if (dev) {
669     physical_SetupStack(p, dev->dev.name, PHYSICAL_FORCE_SYNCNOACF);
670     return &dev->dev;
671   }
672
673   return NULL;
674 }