ether.c revision 78410
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 78410 2001-06-18 14:59:36Z 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 <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#if defined(__FreeBSD__) && !defined(NOKLDLOAD) 53#include <sys/linker.h> 54#include <sys/module.h> 55#endif 56#include <sys/stat.h> 57#include <sys/uio.h> 58#include <termios.h> 59#include <sys/time.h> 60#include <unistd.h> 61 62#include "layer.h" 63#include "defs.h" 64#include "mbuf.h" 65#include "log.h" 66#include "timer.h" 67#include "lqr.h" 68#include "hdlc.h" 69#include "throughput.h" 70#include "fsm.h" 71#include "lcp.h" 72#include "ccp.h" 73#include "link.h" 74#include "async.h" 75#include "descriptor.h" 76#include "physical.h" 77#include "main.h" 78#include "mp.h" 79#include "chat.h" 80#include "auth.h" 81#include "chap.h" 82#include "cbcp.h" 83#include "datalink.h" 84#include "slcompress.h" 85#include "iplist.h" 86#include "ipcp.h" 87#include "filter.h" 88#ifndef NORADIUS 89#include "radius.h" 90#endif 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 99struct 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 110int 111ether_DeviceSize(void) 112{ 113 return sizeof(struct etherdevice); 114} 115 116static ssize_t 117ether_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 124static ssize_t 125ether_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 132static int 133ether_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 154static void 155ether_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 165static const char * 166ether_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 180static void 181ether_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 201static void 202ether_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 default: 254 snprintf(unknown, sizeof unknown, "<%d>", (int)rep->header.cmd); 255 msg = unknown; 256 break; 257 } 258 259 log_Printf(LogPHASE, "Received NGM_PPPOE_%s (hook \"%s\")\n", msg, sts->hook); 260 261 switch (rep->header.cmd) { 262 case NGM_PPPOE_SUCCESS: 263 dev->connected = CARRIER_OK; 264 break; 265 case NGM_PPPOE_FAIL: 266 case NGM_PPPOE_CLOSE: 267 dev->connected = CARRIER_LOST; 268 break; 269 } 270} 271 272static int 273ether_AwaitCarrier(struct physical *p) 274{ 275 struct etherdevice *dev = device2ether(p->handler); 276 277 if (dev->connected != CARRIER_OK && !dev->timeout--) 278 dev->connected = CARRIER_LOST; 279 else if (dev->connected == CARRIER_PENDING) 280 ether_MessageIn(dev); 281 282 return dev->connected; 283} 284 285static const struct device baseetherdevice = { 286 ETHER_DEVICE, 287 "ether", 288 1492, 289 { CD_REQUIRED, DEF_ETHERCDDELAY }, 290 ether_AwaitCarrier, 291 ether_RemoveFromSet, 292 NULL, 293 NULL, 294 NULL, 295 NULL, 296 ether_Free, 297 ether_Read, 298 ether_Write, 299 ether_device2iov, 300 NULL, 301 ether_OpenInfo 302}; 303 304struct device * 305ether_iov2device(int type, struct physical *p, struct iovec *iov, int *niov, 306 int maxiov, int *auxfd, int *nauxfd) 307{ 308 if (type == ETHER_DEVICE) { 309 struct etherdevice *dev = (struct etherdevice *)iov[(*niov)++].iov_base; 310 311 dev = realloc(dev, sizeof *dev); /* Reduce to the correct size */ 312 if (dev == NULL) { 313 log_Printf(LogALERT, "Failed to allocate memory: %d\n", 314 (int)(sizeof *dev)); 315 AbortProgram(EX_OSERR); 316 } 317 318 if (*nauxfd) { 319 dev->cs = *auxfd; 320 (*nauxfd)--; 321 } else 322 dev->cs = -1; 323 324 /* Refresh function pointers etc */ 325 memcpy(&dev->dev, &baseetherdevice, sizeof dev->dev); 326 327 physical_SetupStack(p, dev->dev.name, PHYSICAL_FORCE_SYNCNOACF); 328 return &dev->dev; 329 } 330 331 return NULL; 332} 333 334static int 335ether_UpdateSet(struct fdescriptor *d, fd_set *r, fd_set *w, fd_set *e, int *n) 336{ 337 struct physical *p = descriptor2physical(d); 338 struct etherdevice *dev = device2ether(p->handler); 339 int result; 340 341 if (r && dev->cs >= 0) { 342 FD_SET(dev->cs, r); 343 log_Printf(LogTIMER, "%s(ctrl): fdset(r) %d\n", p->link.name, dev->cs); 344 result = 1; 345 } else 346 result = 0; 347 348 result += physical_doUpdateSet(d, r, w, e, n, 0); 349 350 return result; 351} 352 353static int 354ether_IsSet(struct fdescriptor *d, const fd_set *fdset) 355{ 356 struct physical *p = descriptor2physical(d); 357 struct etherdevice *dev = device2ether(p->handler); 358 int result; 359 360 result = dev->cs >= 0 && FD_ISSET(dev->cs, fdset); 361 result += physical_IsSet(d, fdset); 362 363 return result; 364} 365 366static void 367ether_DescriptorRead(struct fdescriptor *d, struct bundle *bundle, 368 const fd_set *fdset) 369{ 370 struct physical *p = descriptor2physical(d); 371 struct etherdevice *dev = device2ether(p->handler); 372 373 if (dev->cs >= 0 && FD_ISSET(dev->cs, fdset)) { 374 ether_MessageIn(dev); 375 if (dev->connected == CARRIER_LOST) { 376 log_Printf(LogPHASE, "%s: Device disconnected\n", p->link.name); 377 datalink_Down(p->dl, CLOSE_NORMAL); 378 return; 379 } 380 } 381 382 if (physical_IsSet(d, fdset)) 383 physical_DescriptorRead(d, bundle, fdset); 384} 385 386static struct device * 387ether_Abandon(struct etherdevice *dev, struct physical *p) 388{ 389 /* Abandon our node construction */ 390 close(dev->cs); 391 close(p->fd); 392 p->fd = -2; /* Nobody else need try.. */ 393 free(dev); 394 395 return NULL; 396} 397 398struct device * 399ether_Create(struct physical *p) 400{ 401 u_char rbuf[2048]; 402 struct etherdevice *dev; 403 struct ng_mesg *resp; 404 const struct hooklist *hlist; 405 const struct nodeinfo *ninfo; 406 char *path; 407 int ifacelen, f; 408 409 dev = NULL; 410 path = NULL; 411 ifacelen = 0; 412 if (p->fd < 0 && !strncasecmp(p->name.full, NG_PPPOE_NODE_TYPE, 413 PPPOE_NODE_TYPE_LEN) && 414 p->name.full[PPPOE_NODE_TYPE_LEN] == ':') { 415 const struct linkinfo *nlink; 416 struct ngpppoe_init_data *data; 417 struct ngm_mkpeer mkp; 418 struct ngm_connect ngc; 419 const char *iface, *provider; 420 char etherid[12]; 421 int providerlen; 422 char connectpath[sizeof dev->hook + 2]; /* .:<hook> */ 423 424 p->fd--; /* We own the device - change fd */ 425 426#if defined(__FreeBSD__) && !defined(NOKLDLOAD) 427 if (modfind("netgraph") == -1 && ID0kldload("netgraph") == -1) { 428 log_Printf(LogWARN, "kldload: netgraph: %s\n", strerror(errno)); 429 return NULL; 430 } 431 432 if (modfind("ng_ether") == -1 && ID0kldload("ng_ether") == -1) 433 /* 434 * Don't treat this as an error as older kernels have this stuff 435 * built in as part of the netgraph node itself. 436 */ 437 log_Printf(LogWARN, "kldload: ng_ether: %s\n", strerror(errno)); 438 439 if (modfind("ng_pppoe") == -1 && ID0kldload("ng_pppoe") == -1) { 440 log_Printf(LogWARN, "kldload: ng_pppoe: %s\n", strerror(errno)); 441 return NULL; 442 } 443 444 if (modfind("ng_socket") == -1 && ID0kldload("ng_socket") == -1) { 445 log_Printf(LogWARN, "kldload: ng_socket: %s\n", strerror(errno)); 446 return NULL; 447 } 448#endif 449 450 if ((dev = malloc(sizeof *dev)) == NULL) 451 return NULL; 452 453 iface = p->name.full + PPPOE_NODE_TYPE_LEN + 1; 454 455 provider = strchr(iface, ':'); 456 if (provider) { 457 ifacelen = provider - iface; 458 provider++; 459 providerlen = strlen(provider); 460 } else { 461 ifacelen = strlen(iface); 462 provider = ""; 463 providerlen = 0; 464 } 465 466 /* 467 * We're going to do this (where tunN is our tunnel device): 468 * 469 * .---------. 470 * | ether | 471 * | <iface> | dev->cs 472 * `---------' | 473 * (orphan) p->fd | 474 * | | | 475 * | | | 476 * (ethernet) | | 477 * .---------. .-----------. 478 * | pppoe | | socket | 479 * | <iface> |(tunN)<---->(tunN)| <unnamed> | 480 * `--------- `-----------' 481 * (tunX) 482 * ^ 483 * | 484 * `--->(tunX) 485 */ 486 487 /* Create a socket node */ 488 if (ID0NgMkSockNode(NULL, &dev->cs, &p->fd) == -1) { 489 log_Printf(LogWARN, "Cannot create netgraph socket node: %s\n", 490 strerror(errno)); 491 free(dev); 492 return NULL; 493 } 494 495 /* 496 * Ask for a list of hooks attached to the "ether" node. This node should 497 * magically exist as a way of hooking stuff onto an ethernet device 498 */ 499 path = (char *)alloca(ifacelen + 2); 500 sprintf(path, "%.*s:", ifacelen, iface); 501 if (NgSendMsg(dev->cs, path, NGM_GENERIC_COOKIE, NGM_LISTHOOKS, 502 NULL, 0) < 0) { 503 log_Printf(LogWARN, "%s Cannot send a netgraph message: %s\n", 504 path, strerror(errno)); 505 return ether_Abandon(dev, p); 506 } 507 508 /* Get our list back */ 509 resp = (struct ng_mesg *)rbuf; 510 if (NgRecvMsg(dev->cs, resp, sizeof rbuf, NULL) < 0) { 511 log_Printf(LogWARN, "Cannot get netgraph response: %s\n", 512 strerror(errno)); 513 return ether_Abandon(dev, p); 514 } 515 516 hlist = (const struct hooklist *)resp->data; 517 ninfo = &hlist->nodeinfo; 518 519 /* Make sure we've got the right type of node */ 520 if (strncmp(ninfo->type, NG_ETHER_NODE_TYPE, 521 sizeof NG_ETHER_NODE_TYPE - 1)) { 522 log_Printf(LogWARN, "%s Unexpected node type ``%s'' (wanted ``" 523 NG_ETHER_NODE_TYPE "'')\n", path, ninfo->type); 524 return ether_Abandon(dev, p); 525 } 526 527 log_Printf(LogDEBUG, "List of netgraph node ``%s'' (id %x) hooks:\n", 528 path, ninfo->id); 529 530 /* look for a hook already attached. */ 531 for (f = 0; f < ninfo->hooks; f++) { 532 nlink = &hlist->link[f]; 533 534 log_Printf(LogDEBUG, " Found %s -> %s\n", nlink->ourhook, 535 nlink->peerhook); 536 537 if (!strcmp(nlink->ourhook, NG_ETHER_HOOK_ORPHAN) || 538 !strcmp(nlink->ourhook, NG_ETHER_HOOK_DIVERT)) { 539 /* 540 * Something is using the data coming out of this ``ether'' node. 541 * If it's a PPPoE node, we use that node, otherwise we complain that 542 * someone else is using the node. 543 */ 544 if (!strcmp(nlink->nodeinfo.type, NG_PPPOE_NODE_TYPE)) 545 /* Use this PPPoE node ! */ 546 snprintf(ngc.path, sizeof ngc.path, "[%x]:", nlink->nodeinfo.id); 547 else { 548 log_Printf(LogWARN, "%s Node type ``%s'' is currently active\n", 549 path, nlink->nodeinfo.type); 550 return ether_Abandon(dev, p); 551 } 552 break; 553 } 554 } 555 556 if (f == ninfo->hooks) { 557 /* 558 * Create a new ``PPPoE'' node connected to the ``ether'' node using 559 * the magic ``orphan'' and ``ethernet'' hooks 560 */ 561 snprintf(mkp.type, sizeof mkp.type, "%s", NG_PPPOE_NODE_TYPE); 562 snprintf(mkp.ourhook, sizeof mkp.ourhook, "%s", NG_ETHER_HOOK_ORPHAN); 563 snprintf(mkp.peerhook, sizeof mkp.peerhook, "%s", NG_PPPOE_HOOK_ETHERNET); 564 snprintf(etherid, sizeof etherid, "[%x]:", ninfo->id); 565 566 log_Printf(LogDEBUG, "Creating PPPoE netgraph node %s%s -> %s\n", 567 etherid, mkp.ourhook, mkp.peerhook); 568 569 if (NgSendMsg(dev->cs, etherid, NGM_GENERIC_COOKIE, 570 NGM_MKPEER, &mkp, sizeof mkp) < 0) { 571 log_Printf(LogWARN, "%s Cannot create PPPoE netgraph node: %s\n", 572 etherid, strerror(errno)); 573 return ether_Abandon(dev, p); 574 } 575 576 snprintf(ngc.path, sizeof ngc.path, "%s%s", path, NG_ETHER_HOOK_ORPHAN); 577 } 578 579 snprintf(dev->hook, sizeof dev->hook, "%s%d", 580 TUN_NAME, p->dl->bundle->unit); 581 582 /* 583 * Connect the PPPoE node to our socket node. 584 * ngc.path has already been set up 585 */ 586 snprintf(ngc.ourhook, sizeof ngc.ourhook, "%s", dev->hook); 587 memcpy(ngc.peerhook, ngc.ourhook, sizeof ngc.peerhook); 588 589 log_Printf(LogDEBUG, "Connecting netgraph socket .:%s -> %s:%s\n", 590 ngc.ourhook, ngc.path, ngc.peerhook); 591 if (NgSendMsg(dev->cs, ".:", NGM_GENERIC_COOKIE, 592 NGM_CONNECT, &ngc, sizeof ngc) < 0) { 593 log_Printf(LogWARN, "Cannot connect PPPoE and socket netgraph " 594 "nodes: %s\n", strerror(errno)); 595 return ether_Abandon(dev, p); 596 } 597 598 /* And finally, request a connection to the given provider */ 599 600 data = (struct ngpppoe_init_data *)alloca(sizeof *data + providerlen); 601 snprintf(data->hook, sizeof data->hook, "%s", dev->hook); 602 memcpy(data->data, provider, providerlen); 603 data->data_len = providerlen; 604 605 snprintf(connectpath, sizeof connectpath, ".:%s", dev->hook); 606 log_Printf(LogDEBUG, "Sending PPPOE_CONNECT to %s\n", connectpath); 607 if (NgSendMsg(dev->cs, connectpath, NGM_PPPOE_COOKIE, 608 NGM_PPPOE_CONNECT, data, sizeof *data + providerlen) == -1) { 609 log_Printf(LogWARN, "``%s'': Cannot start netgraph node: %s\n", 610 connectpath, strerror(errno)); 611 return ether_Abandon(dev, p); 612 } 613 614 /* Hook things up so that we monitor dev->cs */ 615 p->desc.UpdateSet = ether_UpdateSet; 616 p->desc.IsSet = ether_IsSet; 617 p->desc.Read = ether_DescriptorRead; 618 619 memcpy(&dev->dev, &baseetherdevice, sizeof dev->dev); 620 switch (p->cfg.cd.necessity) { 621 case CD_VARIABLE: 622 dev->dev.cd.delay = p->cfg.cd.delay; 623 break; 624 case CD_REQUIRED: 625 dev->dev.cd = p->cfg.cd; 626 break; 627 case CD_NOTREQUIRED: 628 log_Printf(LogWARN, "%s: Carrier must be set, using ``set cd %d!''\n", 629 p->link.name, dev->dev.cd.delay); 630 case CD_DEFAULT: 631 break; 632 } 633 634 dev->timeout = dev->dev.cd.delay; 635 dev->connected = CARRIER_PENDING; 636 637 } else { 638 /* See if we're a netgraph socket */ 639 struct stat st; 640 641 if (fstat(p->fd, &st) != -1 && (st.st_mode & S_IFSOCK)) { 642 struct sockaddr_storage ssock; 643 struct sockaddr *sock = (struct sockaddr *)&ssock; 644 int sz; 645 646 sz = sizeof ssock; 647 if (getsockname(p->fd, sock, &sz) == -1) { 648 log_Printf(LogPHASE, "%s: Link is a closed socket !\n", p->link.name); 649 close(p->fd); 650 p->fd = -1; 651 return NULL; 652 } 653 654 if (sock->sa_family == AF_NETGRAPH) { 655 /* 656 * It's a netgraph node... We can't determine hook names etc, so we 657 * stay pretty impartial.... 658 */ 659 log_Printf(LogPHASE, "%s: Link is a netgraph node\n", p->link.name); 660 661 if ((dev = malloc(sizeof *dev)) == NULL) { 662 log_Printf(LogWARN, "%s: Cannot allocate an ether device: %s\n", 663 p->link.name, strerror(errno)); 664 return NULL; 665 } 666 667 memcpy(&dev->dev, &baseetherdevice, sizeof dev->dev); 668 dev->cs = -1; 669 dev->timeout = 0; 670 dev->connected = CARRIER_OK; 671 *dev->hook = '\0'; 672 } 673 } 674 } 675 676 if (dev) { 677 physical_SetupStack(p, dev->dev.name, PHYSICAL_FORCE_SYNCNOACF); 678 679 if (path != NULL) { 680 /* Mark the interface as UP if it's not already */ 681 682 path[ifacelen] = '\0'; /* Remove the trailing ':' */ 683 if (!iface_SetFlags(path, IFF_UP)) 684 log_Printf(LogWARN, "%s: Failed to set the IFF_UP flag on %s\n", 685 p->link.name, path); 686 } 687 688 return &dev->dev; 689 } 690 691 return NULL; 692} 693