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