Deleted Added
full compact
ether.c (62209) ether.c (66898)
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 *
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: head/usr.sbin/ppp/ether.c 62209 2000-06-28 09:30:30Z brian $
26 * $FreeBSD: head/usr.sbin/ppp/ether.c 66898 2000-10-09 21:18:23Z brian $
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
95struct 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
106int
107ether_DeviceSize(void)
108{
109 return sizeof(struct etherdevice);
110}
111
112static ssize_t
113ether_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
120static ssize_t
121ether_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
128static int
129ether_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
150static void
151ether_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
161static const char *
162ether_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
176static void
177ether_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
197static void
198ether_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;
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
95struct 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
106int
107ether_DeviceSize(void)
108{
109 return sizeof(struct etherdevice);
110}
111
112static ssize_t
113ether_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
120static ssize_t
121ether_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
128static int
129ether_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
150static void
151ether_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
161static const char *
162ether_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
176static void
177ether_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
197static void
198ether_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;
206 fd_set *r;
207 int ret;
207
208 if (dev->cs < 0)
209 return;
210
208
209 if (dev->cs < 0)
210 return;
211
211 FD_ZERO(&r);
212 FD_SET(dev->cs, &r);
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);
213 t.tv_sec = t.tv_usec = 0;
218 t.tv_sec = t.tv_usec = 0;
214 if (select(dev->cs + 1, &r, NULL, NULL, &t) <= 0)
219 ret = select(dev->cs + 1, r, NULL, NULL, &t);
220 free(r);
221
222 if (ret <= 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
260static int
261ether_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
273static 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
291struct device *
292ether_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
321static int
322ether_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
340static int
341ether_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
353static void
354ether_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
373static struct device *
374ether_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
385struct device *
386ether_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}
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
268static int
269ether_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
281static 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
299struct device *
300ether_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
329static int
330ether_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
348static int
349ether_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
361static void
362ether_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
381static struct device *
382ether_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
393struct device *
394ether_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 + 1);
588
589 snprintf(data->hook, sizeof data->hook, "%s", dev->hook);
590 strcpy(data->data, provider);
591 data->data_len = providerlen;
592
593 snprintf(connectpath, sizeof connectpath, ".:%s", dev->hook);
594 log_Printf(LogDEBUG, "Sending PPPOE_CONNECT to %s\n", connectpath);
595 if (NgSendMsg(dev->cs, connectpath, NGM_PPPOE_COOKIE,
596 NGM_PPPOE_CONNECT, data, sizeof *data + providerlen) == -1) {
597 log_Printf(LogWARN, "``%s'': Cannot start netgraph node: %s\n",
598 connectpath, strerror(errno));
599 return ether_Abandon(dev, p);
600 }
601
602 /* Hook things up so that we monitor dev->cs */
603 p->desc.UpdateSet = ether_UpdateSet;
604 p->desc.IsSet = ether_IsSet;
605 p->desc.Read = ether_DescriptorRead;
606
607 memcpy(&dev->dev, &baseetherdevice, sizeof dev->dev);
608 switch (p->cfg.cd.necessity) {
609 case CD_VARIABLE:
610 dev->dev.cd.delay = p->cfg.cd.delay;
611 break;
612 case CD_REQUIRED:
613 dev->dev.cd = p->cfg.cd;
614 break;
615 case CD_NOTREQUIRED:
616 log_Printf(LogWARN, "%s: Carrier must be set, using ``set cd %d!''\n",
617 p->link.name, dev->dev.cd.delay);
618 case CD_DEFAULT:
619 break;
620 }
621
622 dev->timeout = dev->dev.cd.delay;
623 dev->connected = CARRIER_PENDING;
624
625 } else {
626 /* See if we're a netgraph socket */
627 struct sockaddr_ng ngsock;
628 struct sockaddr *sock = (struct sockaddr *)&ngsock;
629 int sz;
630
631 sz = sizeof ngsock;
632 if (getsockname(p->fd, sock, &sz) != -1 && sock->sa_family == AF_NETGRAPH) {
633 /*
634 * It's a netgraph node... We can't determine hook names etc, so we
635 * stay pretty impartial....
636 */
637 log_Printf(LogPHASE, "%s: Link is a netgraph node\n", p->link.name);
638
639 if ((dev = malloc(sizeof *dev)) == NULL) {
640 log_Printf(LogWARN, "%s: Cannot allocate an ether device: %s\n",
641 p->link.name, strerror(errno));
642 return NULL;
643 }
644
645 memcpy(&dev->dev, &baseetherdevice, sizeof dev->dev);
646 dev->cs = -1;
647 dev->timeout = 0;
648 dev->connected = CARRIER_OK;
649 *dev->hook = '\0';
650 }
651 }
652
653 if (dev) {
654 physical_SetupStack(p, dev->dev.name, PHYSICAL_FORCE_SYNCNOACF);
655
656 /* Moan about (and fix) invalid LCP configurations */
657 if (p->link.lcp.cfg.mru > 1492) {
658 log_Printf(LogWARN, "%s: Reducing MRU to 1492\n", p->link.name);
659 p->link.lcp.cfg.mru = 1492;
660 }
661 if (p->dl->bundle->cfg.mtu > 1492) {
662 log_Printf(LogWARN, "%s: Reducing MTU to 1492\n", p->link.name);
663 p->dl->bundle->cfg.mtu = 1492;
664 }
665
666 return &dev->dev;
667 }
668
669 return NULL;
670}