xref: /freebsd/usr.sbin/ppp/ether.c (revision 817420dc8eac7df799c78f5309b75092b7f7cd40)
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   int ret;
208 
209   if (dev->cs < 0)
210     return;
211 
212   if ((r = mkfdset()) == NULL) {
213     log_Printf(LogERROR, "DoLoop: Cannot create fd_set\n");
214     return;
215   }
216   zerofdset(r);
217   FD_SET(dev->cs, r);
218   t.tv_sec = t.tv_usec = 0;
219   ret = select(dev->cs + 1, r, NULL, NULL, &t);
220   free(r);
221 
222   if (ret <= 0)
223     return;
224 
225   if (NgRecvMsg(dev->cs, rep, sizeof msgbuf, NULL) < 0)
226     return;
227 
228   if (rep->header.version != NG_VERSION) {
229     log_Printf(LogWARN, "%ld: Unexpected netgraph version, expected %ld\n",
230                (long)rep->header.version, (long)NG_VERSION);
231     return;
232   }
233 
234   if (rep->header.typecookie != NGM_PPPOE_COOKIE) {
235     log_Printf(LogWARN, "%ld: Unexpected netgraph cookie, expected %ld\n",
236                (long)rep->header.typecookie, (long)NGM_PPPOE_COOKIE);
237     return;
238   }
239 
240   switch (rep->header.cmd) {
241     case NGM_PPPOE_SET_FLAG:	msg = "SET_FLAG";	break;
242     case NGM_PPPOE_CONNECT:	msg = "CONNECT";	break;
243     case NGM_PPPOE_LISTEN:	msg = "LISTEN";		break;
244     case NGM_PPPOE_OFFER:	msg = "OFFER";		break;
245     case NGM_PPPOE_SUCCESS:	msg = "SUCCESS";	break;
246     case NGM_PPPOE_FAIL:	msg = "FAIL";		break;
247     case NGM_PPPOE_CLOSE:	msg = "CLOSE";		break;
248     case NGM_PPPOE_GET_STATUS:	msg = "GET_STATUS";	break;
249     default:
250       snprintf(unknown, sizeof unknown, "<%d>", (int)rep->header.cmd);
251       msg = unknown;
252       break;
253   }
254 
255   log_Printf(LogPHASE, "Received NGM_PPPOE_%s (hook \"%s\")\n", msg, sts->hook);
256 
257   switch (rep->header.cmd) {
258     case NGM_PPPOE_SUCCESS:
259       dev->connected = CARRIER_OK;
260       break;
261     case NGM_PPPOE_FAIL:
262     case NGM_PPPOE_CLOSE:
263       dev->connected = CARRIER_LOST;
264       break;
265   }
266 }
267 
268 static int
269 ether_AwaitCarrier(struct physical *p)
270 {
271   struct etherdevice *dev = device2ether(p->handler);
272 
273   if (dev->connected != CARRIER_OK && !dev->timeout--)
274     dev->connected = CARRIER_LOST;
275   else if (dev->connected == CARRIER_PENDING)
276     ether_MessageIn(dev);
277 
278   return dev->connected;
279 }
280 
281 static const struct device baseetherdevice = {
282   ETHER_DEVICE,
283   "ether",
284   { CD_REQUIRED, DEF_ETHERCDDELAY },
285   ether_AwaitCarrier,
286   ether_RemoveFromSet,
287   NULL,
288   NULL,
289   NULL,
290   NULL,
291   ether_Free,
292   ether_Read,
293   ether_Write,
294   ether_device2iov,
295   NULL,
296   ether_OpenInfo
297 };
298 
299 struct device *
300 ether_iov2device(int type, struct physical *p, struct iovec *iov, int *niov,
301                  int maxiov, int *auxfd, int *nauxfd)
302 {
303   if (type == ETHER_DEVICE) {
304     struct etherdevice *dev = (struct etherdevice *)iov[(*niov)++].iov_base;
305 
306     dev = realloc(dev, sizeof *dev);	/* Reduce to the correct size */
307     if (dev == NULL) {
308       log_Printf(LogALERT, "Failed to allocate memory: %d\n",
309                  (int)(sizeof *dev));
310       AbortProgram(EX_OSERR);
311     }
312 
313     if (*nauxfd) {
314       dev->cs = *auxfd;
315       (*nauxfd)--;
316     } else
317       dev->cs = -1;
318 
319     /* Refresh function pointers etc */
320     memcpy(&dev->dev, &baseetherdevice, sizeof dev->dev);
321 
322     physical_SetupStack(p, dev->dev.name, PHYSICAL_FORCE_SYNCNOACF);
323     return &dev->dev;
324   }
325 
326   return NULL;
327 }
328 
329 static int
330 ether_UpdateSet(struct fdescriptor *d, fd_set *r, fd_set *w, fd_set *e, int *n)
331 {
332   struct physical *p = descriptor2physical(d);
333   struct etherdevice *dev = device2ether(p->handler);
334   int result;
335 
336   if (r && dev->cs >= 0) {
337     FD_SET(dev->cs, r);
338     log_Printf(LogTIMER, "%s(ctrl): fdset(r) %d\n", p->link.name, dev->cs);
339     result = 1;
340   } else
341     result = 0;
342 
343   result += physical_doUpdateSet(d, r, w, e, n, 0);
344 
345   return result;
346 }
347 
348 static int
349 ether_IsSet(struct fdescriptor *d, const fd_set *fdset)
350 {
351   struct physical *p = descriptor2physical(d);
352   struct etherdevice *dev = device2ether(p->handler);
353   int result;
354 
355   result = dev->cs >= 0 && FD_ISSET(dev->cs, fdset);
356   result += physical_IsSet(d, fdset);
357 
358   return result;
359 }
360 
361 static void
362 ether_DescriptorRead(struct fdescriptor *d, struct bundle *bundle,
363                      const fd_set *fdset)
364 {
365   struct physical *p = descriptor2physical(d);
366   struct etherdevice *dev = device2ether(p->handler);
367 
368   if (dev->cs >= 0 && FD_ISSET(dev->cs, fdset)) {
369     ether_MessageIn(dev);
370     if (dev->connected == CARRIER_LOST) {
371       log_Printf(LogPHASE, "%s: Device disconnected\n", p->link.name);
372       datalink_Down(p->dl, CLOSE_NORMAL);
373       return;
374     }
375   }
376 
377   if (physical_IsSet(d, fdset))
378     physical_DescriptorRead(d, bundle, fdset);
379 }
380 
381 static struct device *
382 ether_Abandon(struct etherdevice *dev, struct physical *p)
383 {
384   /* Abandon our node construction */
385   close(dev->cs);
386   close(p->fd);
387   p->fd = -2;	/* Nobody else need try.. */
388   free(dev);
389 
390   return NULL;
391 }
392 
393 struct device *
394 ether_Create(struct physical *p)
395 {
396   u_char rbuf[2048];
397   struct etherdevice *dev;
398   struct ng_mesg *resp;
399   const struct hooklist *hlist;
400   const struct nodeinfo *ninfo;
401   int f;
402 
403   dev = NULL;
404   if (p->fd < 0 && !strncasecmp(p->name.full, NG_PPPOE_NODE_TYPE,
405                                 PPPOE_NODE_TYPE_LEN) &&
406       p->name.full[PPPOE_NODE_TYPE_LEN] == ':') {
407     const struct linkinfo *nlink;
408     struct ngpppoe_init_data *data;
409     struct ngm_mkpeer mkp;
410     struct ngm_connect ngc;
411     const char *iface, *provider;
412     char *path, etherid[12];
413     int ifacelen, providerlen;
414     char connectpath[sizeof dev->hook + 2];	/* .:<hook> */
415 
416     p->fd--;				/* We own the device - change fd */
417 
418 #if defined(__FreeBSD__) && !defined(NOKLDLOAD)
419     if (modfind("netgraph") == -1) {
420       log_Printf(LogWARN, "Netgraph is not built into the kernel\n");
421       return NULL;
422     }
423 
424     if (modfind("ng_ether") == -1 && ID0kldload("ng_ether") == -1)
425       /*
426        * Don't treat this as an error as older kernels have this stuff
427        * built in as part of the netgraph node itself.
428        */
429       log_Printf(LogWARN, "kldload: ng_ether: %s\n", strerror(errno));
430 
431     if (modfind("ng_socket") == -1 && ID0kldload("ng_socket") == -1) {
432       log_Printf(LogWARN, "kldload: ng_socket: %s\n", strerror(errno));
433       return NULL;
434     }
435 #endif
436 
437     if ((dev = malloc(sizeof *dev)) == NULL)
438       return NULL;
439 
440     iface = p->name.full + PPPOE_NODE_TYPE_LEN + 1;
441 
442     provider = strchr(iface, ':');
443     if (provider) {
444       ifacelen = provider - iface;
445       provider++;
446       providerlen = strlen(provider);
447     } else {
448       ifacelen = strlen(iface);
449       provider = "";
450       providerlen = 0;
451     }
452 
453     /*
454      * We're going to do this (where tunN is our tunnel device):
455      *
456      * .---------.
457      * |  ether  |
458      * | <iface> |                         dev->cs
459      * `---------'                           |
460      *  (orphan)                     p->fd   |
461      *     |                           |     |
462      *     |                           |     |
463      * (ethernet)                      |     |
464      * .---------.                  .-----------.
465      * |  pppoe  |                  |  socket   |
466      * | <iface> |(tunN)<---->(tunN)| <unnamed> |
467      * `---------                   `-----------'
468      *   (tunX)
469      *     ^
470      *     |
471      *     `--->(tunX)
472      */
473 
474     /* Create a socket node */
475     if (ID0NgMkSockNode(NULL, &dev->cs, &p->fd) == -1) {
476       log_Printf(LogWARN, "Cannot create netgraph socket node: %s\n",
477                  strerror(errno));
478       free(dev);
479       return NULL;
480     }
481 
482     /*
483      * Ask for a list of hooks attached to the "ether" node.  This node should
484      * magically exist as a way of hooking stuff onto an ethernet device
485      */
486     path = (char *)alloca(ifacelen + 2);
487     sprintf(path, "%.*s:", ifacelen, iface);
488     if (NgSendMsg(dev->cs, path, NGM_GENERIC_COOKIE, NGM_LISTHOOKS,
489                   NULL, 0) < 0) {
490       log_Printf(LogWARN, "%s Cannot send a netgraph message: %s\n",
491                  path, strerror(errno));
492       return ether_Abandon(dev, p);
493     }
494 
495     /* Get our list back */
496     resp = (struct ng_mesg *)rbuf;
497     if (NgRecvMsg(dev->cs, resp, sizeof rbuf, NULL) < 0) {
498       log_Printf(LogWARN, "Cannot get netgraph response: %s\n",
499                  strerror(errno));
500       return ether_Abandon(dev, p);
501     }
502 
503     hlist = (const struct hooklist *)resp->data;
504     ninfo = &hlist->nodeinfo;
505 
506     /* Make sure we've got the right type of node */
507     if (strncmp(ninfo->type, NG_ETHER_NODE_TYPE,
508                 sizeof NG_ETHER_NODE_TYPE - 1)) {
509       log_Printf(LogWARN, "%s Unexpected node type ``%s'' (wanted ``"
510                  NG_ETHER_NODE_TYPE "'')\n", path, ninfo->type);
511       return ether_Abandon(dev, p);
512     }
513 
514     log_Printf(LogDEBUG, "List of netgraph node ``%s'' (id %x) hooks:\n",
515                path, ninfo->id);
516 
517     /* look for a hook already attached.  */
518     for (f = 0; f < ninfo->hooks; f++) {
519       nlink = &hlist->link[f];
520 
521       log_Printf(LogDEBUG, "  Found %s -> %s\n", nlink->ourhook,
522                  nlink->peerhook);
523 
524       if (!strcmp(nlink->ourhook, NG_ETHER_HOOK_ORPHAN) ||
525           !strcmp(nlink->ourhook, NG_ETHER_HOOK_DIVERT)) {
526         /*
527          * Something is using the data coming out of this ``ether'' node.
528          * If it's a PPPoE node, we use that node, otherwise we complain that
529          * someone else is using the node.
530          */
531         if (!strcmp(nlink->nodeinfo.type, NG_PPPOE_NODE_TYPE))
532           /* Use this PPPoE node ! */
533           snprintf(ngc.path, sizeof ngc.path, "[%x]:", nlink->nodeinfo.id);
534         else {
535           log_Printf(LogWARN, "%s Node type ``%s'' is currently active\n",
536                      path, nlink->nodeinfo.type);
537           return ether_Abandon(dev, p);
538         }
539         break;
540       }
541     }
542 
543     if (f == ninfo->hooks) {
544       /*
545        * Create a new ``PPPoE'' node connected to the ``ether'' node using
546        * the magic ``orphan'' and ``ethernet'' hooks
547        */
548       snprintf(mkp.type, sizeof mkp.type, "%s", NG_PPPOE_NODE_TYPE);
549       snprintf(mkp.ourhook, sizeof mkp.ourhook, "%s", NG_ETHER_HOOK_ORPHAN);
550       snprintf(mkp.peerhook, sizeof mkp.peerhook, "%s", NG_PPPOE_HOOK_ETHERNET);
551       snprintf(etherid, sizeof etherid, "[%x]:", ninfo->id);
552 
553       log_Printf(LogDEBUG, "Creating PPPoE netgraph node %s%s -> %s\n",
554                  etherid, mkp.ourhook, mkp.peerhook);
555 
556       if (NgSendMsg(dev->cs, etherid, NGM_GENERIC_COOKIE,
557                     NGM_MKPEER, &mkp, sizeof mkp) < 0) {
558         log_Printf(LogWARN, "%s Cannot create PPPoE netgraph node: %s\n",
559                    etherid, strerror(errno));
560         return ether_Abandon(dev, p);
561       }
562 
563       snprintf(ngc.path, sizeof ngc.path, "%s%s", path, NG_ETHER_HOOK_ORPHAN);
564     }
565 
566     snprintf(dev->hook, sizeof dev->hook, "%s%d",
567              TUN_NAME, p->dl->bundle->unit);
568 
569     /*
570      * Connect the PPPoE node to our socket node.
571      * ngc.path has already been set up
572      */
573     snprintf(ngc.ourhook, sizeof ngc.ourhook, "%s", dev->hook);
574     memcpy(ngc.peerhook, ngc.ourhook, sizeof ngc.peerhook);
575 
576     log_Printf(LogDEBUG, "Connecting netgraph socket .:%s -> %s:%s\n",
577                ngc.ourhook, ngc.path, ngc.peerhook);
578     if (NgSendMsg(dev->cs, ".:", NGM_GENERIC_COOKIE,
579                   NGM_CONNECT, &ngc, sizeof ngc) < 0) {
580       log_Printf(LogWARN, "Cannot connect PPPoE and socket netgraph "
581                  "nodes: %s\n", strerror(errno));
582       return ether_Abandon(dev, p);
583     }
584 
585     /* And finally, request a connection to the given provider */
586 
587     data = (struct ngpppoe_init_data *)alloca(sizeof *data + providerlen);
588     snprintf(data->hook, sizeof data->hook, "%s", dev->hook);
589     memcpy(data->data, provider, providerlen);
590     data->data_len = providerlen;
591 
592     snprintf(connectpath, sizeof connectpath, ".:%s", dev->hook);
593     log_Printf(LogDEBUG, "Sending PPPOE_CONNECT to %s\n", connectpath);
594     if (NgSendMsg(dev->cs, connectpath, NGM_PPPOE_COOKIE,
595                   NGM_PPPOE_CONNECT, data, sizeof *data + providerlen) == -1) {
596       log_Printf(LogWARN, "``%s'': Cannot start netgraph node: %s\n",
597                  connectpath, strerror(errno));
598       return ether_Abandon(dev, p);
599     }
600 
601     /* Hook things up so that we monitor dev->cs */
602     p->desc.UpdateSet = ether_UpdateSet;
603     p->desc.IsSet = ether_IsSet;
604     p->desc.Read = ether_DescriptorRead;
605 
606     memcpy(&dev->dev, &baseetherdevice, sizeof dev->dev);
607     switch (p->cfg.cd.necessity) {
608       case CD_VARIABLE:
609         dev->dev.cd.delay = p->cfg.cd.delay;
610         break;
611       case CD_REQUIRED:
612         dev->dev.cd = p->cfg.cd;
613         break;
614       case CD_NOTREQUIRED:
615         log_Printf(LogWARN, "%s: Carrier must be set, using ``set cd %d!''\n",
616                    p->link.name, dev->dev.cd.delay);
617       case CD_DEFAULT:
618         break;
619     }
620 
621     dev->timeout = dev->dev.cd.delay;
622     dev->connected = CARRIER_PENDING;
623 
624   } else {
625     /* See if we're a netgraph socket */
626     struct sockaddr_ng ngsock;
627     struct sockaddr *sock = (struct sockaddr *)&ngsock;
628     int sz;
629 
630     sz = sizeof ngsock;
631     if (getsockname(p->fd, sock, &sz) != -1 && sock->sa_family == AF_NETGRAPH) {
632       /*
633        * It's a netgraph node... We can't determine hook names etc, so we
634        * stay pretty impartial....
635        */
636       log_Printf(LogPHASE, "%s: Link is a netgraph node\n", p->link.name);
637 
638       if ((dev = malloc(sizeof *dev)) == NULL) {
639         log_Printf(LogWARN, "%s: Cannot allocate an ether device: %s\n",
640                    p->link.name, strerror(errno));
641         return NULL;
642       }
643 
644       memcpy(&dev->dev, &baseetherdevice, sizeof dev->dev);
645       dev->cs = -1;
646       dev->timeout = 0;
647       dev->connected = CARRIER_OK;
648       *dev->hook = '\0';
649     }
650   }
651 
652   if (dev) {
653     physical_SetupStack(p, dev->dev.name, PHYSICAL_FORCE_SYNCNOACF);
654 
655     /* Moan about (and fix) invalid LCP configurations */
656     if (p->link.lcp.cfg.mru > 1492) {
657       log_Printf(LogWARN, "%s: Reducing MRU to 1492\n", p->link.name);
658       p->link.lcp.cfg.mru = 1492;
659     }
660     if (p->dl->bundle->cfg.mtu > 1492) {
661       log_Printf(LogWARN, "%s: Reducing MTU to 1492\n", p->link.name);
662       p->dl->bundle->cfg.mtu = 1492;
663     }
664 
665     return &dev->dev;
666   }
667 
668   return NULL;
669 }
670