1 2 /* 3 * ng_iface.c 4 * 5 * Copyright (c) 1996-1999 Whistle Communications, Inc. 6 * All rights reserved. 7 * 8 * Subject to the following obligations and disclaimer of warranty, use and 9 * redistribution of this software, in source or object code forms, with or 10 * without modifications are expressly permitted by Whistle Communications; 11 * provided, however, that: 12 * 1. Any and all reproductions of the source or object code must include the 13 * copyright notice above and the following disclaimer of warranties; and 14 * 2. No rights are granted, in any manner or form, to use Whistle 15 * Communications, Inc. trademarks, including the mark "WHISTLE 16 * COMMUNICATIONS" on advertising, endorsements, or otherwise except as 17 * such appears in the above copyright notice or in the software. 18 * 19 * THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND 20 * TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO 21 * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE, 22 * INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF 23 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. 24 * WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY 25 * REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS 26 * SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE. 27 * IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES 28 * RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING 29 * WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 30 * PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR 31 * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY 32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 34 * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY 35 * OF SUCH DAMAGE. 36 * 37 * Author: Archie Cobbs <archie@whistle.com> 38 * 39 * $FreeBSD$ 40 * $Whistle: ng_iface.c,v 1.33 1999/11/01 09:24:51 julian Exp $ 41 */ 42 43 /* 44 * This node is also a system networking interface. It has 45 * a hook for each protocol (IP, AppleTalk, IPX, etc). Packets 46 * are simply relayed between the interface and the hooks. 47 * 48 * Interfaces are named ng0, ng1, .... FreeBSD does not support 49 * the removal of interfaces, so iface nodes are persistent. 50 * 51 * This node also includes Berkeley packet filter support. 52 */ 53 54 #include "opt_inet.h" 55 #include "opt_atalk.h" 56 #include "opt_ipx.h" 57 58 #include <sys/param.h> 59 #include <sys/systm.h> 60 #include <sys/errno.h> 61 #include <sys/kernel.h> 62 #include <sys/malloc.h> 63 #include <sys/mbuf.h> 64 #include <sys/errno.h> 65 #include <sys/sockio.h> 66 #include <sys/socket.h> 67 #include <sys/syslog.h> 68 69 #include <net/if.h> 70 #include <net/if_types.h> 71 #include <net/netisr.h> 72 73 #include <netinet/in.h> 74 75 #include <netgraph/ng_message.h> 76 #include <netgraph/netgraph.h> 77 #include <netgraph/ng_iface.h> 78 #include <netgraph/ng_cisco.h> 79 80 #ifdef INET 81 #include <netinet/in_systm.h> 82 #include <netinet/in_var.h> 83 #include <netinet/in_var.h> 84 #endif 85 86 #ifdef NETATALK 87 #include <netatalk/at.h> 88 #include <netatalk/at_var.h> 89 #endif 90 91 #ifdef IPX 92 #include <netipx/ipx.h> 93 #include <netipx/ipx_if.h> 94 #endif 95 96 #ifdef NS 97 #include <netns/ns.h> 98 #include <netns/ns_if.h> 99 #endif 100 101 #include <net/bpf.h> 102 103 /* This struct describes one address family */ 104 struct iffam { 105 char *hookname; /* Name for hook */ 106 u_char af; /* Family number */ 107 u_char netisr; /* or NETISR_NONE */ 108 union { 109 void *_dummy; /* avoid warning */ 110 struct ifqueue *inq; /* if netisr */ 111 void (*input)(struct mbuf *m); /* if direct input */ 112 } u; 113 }; 114 typedef const struct iffam *iffam_p; 115 116 #define NETISR_NONE 0xff 117 118 /* List of address families supported by our interface. Each address 119 family has a way to input packets to it, either by calling a function 120 directly (such as ip_input()) or by adding the packet to a queue and 121 setting a NETISR bit. */ 122 const static struct iffam gFamilies[] = { 123 #ifdef INET 124 { 125 NG_IFACE_HOOK_INET, 126 AF_INET, 127 NETISR_NONE, 128 { ip_input } 129 }, 130 #endif 131 #ifdef NETATALK 132 { 133 NG_IFACE_HOOK_ATALK, 134 AF_APPLETALK, 135 NETISR_ATALK, 136 { &atintrq2 } 137 }, 138 #endif 139 #ifdef IPX 140 { 141 NG_IFACE_HOOK_IPX, 142 AF_IPX, 143 NETISR_IPX, 144 { &ipxintrq } 145 }, 146 #endif 147 #ifdef NS 148 { 149 NG_IFACE_HOOK_NS, 150 AF_NS, 151 NETISR_NS, 152 { &nsintrq } 153 }, 154 #endif 155 }; 156 #define NUM_FAMILIES (sizeof(gFamilies) / sizeof(*gFamilies)) 157 158 /* Node private data */ 159 struct ng_iface_private { 160 struct ifnet *ifp; /* This interface */ 161 node_p node; /* Our netgraph node */ 162 hook_p hooks[NUM_FAMILIES]; /* Hook for each address family */ 163 struct private *next; /* When hung on the free list */ 164 }; 165 typedef struct ng_iface_private *priv_p; 166 167 /* Interface methods */ 168 static void ng_iface_start(struct ifnet *ifp); 169 static int ng_iface_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data); 170 static int ng_iface_output(struct ifnet *ifp, struct mbuf *m0, 171 struct sockaddr *dst, struct rtentry *rt0); 172 static void ng_iface_bpftap(struct ifnet *ifp, struct mbuf *m, u_int af); 173 #ifdef DEBUG 174 static void ng_iface_print_ioctl(struct ifnet *ifp, int cmd, caddr_t data); 175 #endif 176 177 /* Netgraph methods */ 178 static ng_constructor_t ng_iface_constructor; 179 static ng_rcvmsg_t ng_iface_rcvmsg; 180 static ng_shutdown_t ng_iface_rmnode; 181 static ng_newhook_t ng_iface_newhook; 182 static ng_rcvdata_t ng_iface_rcvdata; 183 static ng_disconnect_t ng_iface_disconnect; 184 185 /* Helper stuff */ 186 static iffam_p get_iffam_from_af(int af); 187 static iffam_p get_iffam_from_hook(priv_p priv, hook_p hook); 188 static iffam_p get_iffam_from_name(const char *name); 189 static hook_p *get_hook_from_iffam(priv_p priv, iffam_p iffam); 190 191 /* Node type descriptor */ 192 static struct ng_type typestruct = { 193 NG_VERSION, 194 NG_IFACE_NODE_TYPE, 195 NULL, 196 ng_iface_constructor, 197 ng_iface_rcvmsg, 198 ng_iface_rmnode, 199 ng_iface_newhook, 200 NULL, 201 NULL, 202 ng_iface_rcvdata, 203 ng_iface_rcvdata, 204 ng_iface_disconnect, 205 NULL 206 }; 207 NETGRAPH_INIT(iface, &typestruct); 208 209 static char ng_iface_ifname[] = NG_IFACE_IFACE_NAME; 210 static int ng_iface_next_unit; 211 212 /************************************************************************ 213 HELPER STUFF 214 ************************************************************************/ 215 216 /* 217 * Get the family descriptor from the family ID 218 */ 219 static __inline__ iffam_p 220 get_iffam_from_af(int af) 221 { 222 iffam_p iffam; 223 int k; 224 225 for (k = 0; k < NUM_FAMILIES; k++) { 226 iffam = &gFamilies[k]; 227 if (iffam->af == af) 228 return (iffam); 229 } 230 return (NULL); 231 } 232 233 /* 234 * Get the family descriptor from the hook 235 */ 236 static __inline__ iffam_p 237 get_iffam_from_hook(priv_p priv, hook_p hook) 238 { 239 int k; 240 241 for (k = 0; k < NUM_FAMILIES; k++) 242 if (priv->hooks[k] == hook) 243 return (&gFamilies[k]); 244 return (NULL); 245 } 246 247 /* 248 * Get the hook from the iffam descriptor 249 */ 250 251 static __inline__ hook_p * 252 get_hook_from_iffam(priv_p priv, iffam_p iffam) 253 { 254 return (&priv->hooks[iffam - gFamilies]); 255 } 256 257 /* 258 * Get the iffam descriptor from the name 259 */ 260 static __inline__ iffam_p 261 get_iffam_from_name(const char *name) 262 { 263 iffam_p iffam; 264 int k; 265 266 for (k = 0; k < NUM_FAMILIES; k++) { 267 iffam = &gFamilies[k]; 268 if (!strcmp(iffam->hookname, name)) 269 return (iffam); 270 } 271 return (NULL); 272 } 273 274 /************************************************************************ 275 INTERFACE STUFF 276 ************************************************************************/ 277 278 /* 279 * Process an ioctl for the virtual interface 280 */ 281 static int 282 ng_iface_ioctl(struct ifnet *ifp, u_long command, caddr_t data) 283 { 284 struct ifreq *const ifr = (struct ifreq *) data; 285 int s, error = 0; 286 287 #ifdef DEBUG 288 ng_iface_print_ioctl(ifp, command, data); 289 #endif 290 s = splimp(); 291 switch (command) { 292 293 /* These two are mostly handled at a higher layer */ 294 case SIOCSIFADDR: 295 ifp->if_flags |= (IFF_UP | IFF_RUNNING); 296 ifp->if_flags &= ~(IFF_OACTIVE); 297 break; 298 case SIOCGIFADDR: 299 break; 300 301 /* Set flags */ 302 case SIOCSIFFLAGS: 303 /* 304 * If the interface is marked up and stopped, then start it. 305 * If it is marked down and running, then stop it. 306 */ 307 if (ifr->ifr_flags & IFF_UP) { 308 if (!(ifp->if_flags & IFF_RUNNING)) { 309 ifp->if_flags &= ~(IFF_OACTIVE); 310 ifp->if_flags |= IFF_RUNNING; 311 } 312 } else { 313 if (ifp->if_flags & IFF_RUNNING) 314 ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE); 315 } 316 break; 317 318 /* Set the interface MTU */ 319 case SIOCSIFMTU: 320 if (ifr->ifr_mtu > NG_IFACE_MTU_MAX 321 || ifr->ifr_mtu < NG_IFACE_MTU_MIN) 322 error = EINVAL; 323 else 324 ifp->if_mtu = ifr->ifr_mtu; 325 break; 326 327 /* Stuff that's not supported */ 328 case SIOCADDMULTI: 329 case SIOCDELMULTI: 330 error = 0; 331 break; 332 case SIOCSIFPHYS: 333 error = EOPNOTSUPP; 334 break; 335 336 default: 337 error = EINVAL; 338 break; 339 } 340 (void) splx(s); 341 return (error); 342 } 343 344 /* 345 * This routine is called to deliver a packet out the interface. 346 * We simply look at the address family and relay the packet to 347 * the corresponding hook, if it exists and is connected. 348 */ 349 350 static int 351 ng_iface_output(struct ifnet *ifp, struct mbuf *m, 352 struct sockaddr *dst, struct rtentry *rt0) 353 { 354 const priv_p priv = (priv_p) ifp->if_softc; 355 const iffam_p iffam = get_iffam_from_af(dst->sa_family); 356 meta_p meta = NULL; 357 int len, error = 0; 358 359 /* Check interface flags */ 360 if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING)) { 361 m_freem(m); 362 return (ENETDOWN); 363 } 364 365 /* Berkeley packet filter */ 366 ng_iface_bpftap(ifp, m, dst->sa_family); 367 368 /* Check address family to determine hook (if known) */ 369 if (iffam == NULL) { 370 m_freem(m); 371 log(LOG_WARNING, "%s%d: can't handle af%d\n", 372 ifp->if_name, ifp->if_unit, dst->sa_family); 373 return (EAFNOSUPPORT); 374 } 375 376 /* Copy length before the mbuf gets invalidated */ 377 len = m->m_pkthdr.len; 378 379 /* Send packet; if hook is not connected, mbuf will get freed. */ 380 NG_SEND_DATA(error, *get_hook_from_iffam(priv, iffam), m, meta); 381 382 /* Update stats */ 383 if (error == 0) { 384 ifp->if_obytes += len; 385 ifp->if_opackets++; 386 } 387 return (error); 388 } 389 390 /* 391 * This routine should never be called 392 */ 393 394 static void 395 ng_iface_start(struct ifnet *ifp) 396 { 397 printf("%s%d: %s called?", ifp->if_name, ifp->if_unit, __FUNCTION__); 398 } 399 400 /* 401 * Flash a packet by the BPF (requires prepending 4 byte AF header) 402 * Note the phoney mbuf; this is OK because BPF treats it read-only. 403 */ 404 static void 405 ng_iface_bpftap(struct ifnet *ifp, struct mbuf *m, u_int af) 406 { 407 struct mbuf m2; 408 409 if (ifp->if_bpf) { 410 if (af == AF_UNSPEC) { 411 af = *(mtod(m, int *)); 412 m->m_len -= sizeof(int); 413 m->m_pkthdr.len -= sizeof(int); 414 m->m_data += sizeof(int); 415 } 416 if (!ifp->if_bpf) 417 return; 418 m2.m_next = m; 419 m2.m_len = 4; 420 m2.m_data = (char *) ⁡ 421 bpf_mtap(ifp, &m2); 422 } 423 } 424 425 #ifdef DEBUG 426 /* 427 * Display an ioctl to the virtual interface 428 */ 429 430 static void 431 ng_iface_print_ioctl(struct ifnet *ifp, int command, caddr_t data) 432 { 433 char *str; 434 435 switch (command & IOC_DIRMASK) { 436 case IOC_VOID: 437 str = "IO"; 438 break; 439 case IOC_OUT: 440 str = "IOR"; 441 break; 442 case IOC_IN: 443 str = "IOW"; 444 break; 445 case IOC_INOUT: 446 str = "IORW"; 447 break; 448 default: 449 str = "IO??"; 450 } 451 log(LOG_DEBUG, "%s%d: %s('%c', %d, char[%d])\n", 452 ifp->if_name, ifp->if_unit, 453 str, 454 IOCGROUP(command), 455 command & 0xff, 456 IOCPARM_LEN(command)); 457 } 458 #endif /* DEBUG */ 459 460 /************************************************************************ 461 NETGRAPH NODE STUFF 462 ************************************************************************/ 463 464 /* 465 * Constructor for a node 466 */ 467 static int 468 ng_iface_constructor(node_p *nodep) 469 { 470 char ifname[NG_IFACE_IFACE_NAME_MAX + 1]; 471 struct ifnet *ifp; 472 node_p node; 473 priv_p priv; 474 int error = 0; 475 476 /* Allocate node and interface private structures */ 477 MALLOC(priv, priv_p, sizeof(*priv), M_NETGRAPH, M_WAITOK); 478 if (priv == NULL) 479 return (ENOMEM); 480 bzero(priv, sizeof(*priv)); 481 MALLOC(ifp, struct ifnet *, sizeof(*ifp), M_NETGRAPH, M_WAITOK); 482 if (ifp == NULL) { 483 FREE(priv, M_NETGRAPH); 484 return (ENOMEM); 485 } 486 bzero(ifp, sizeof(*ifp)); 487 488 /* Link them together */ 489 ifp->if_softc = priv; 490 priv->ifp = ifp; 491 492 /* Call generic node constructor */ 493 if ((error = ng_make_node_common(&typestruct, nodep))) { 494 FREE(priv, M_NETGRAPH); 495 FREE(ifp, M_NETGRAPH); 496 return (error); 497 } 498 node = *nodep; 499 500 /* Link together node and private info */ 501 node->private = priv; 502 priv->node = node; 503 504 /* Initialize interface structure */ 505 ifp->if_name = ng_iface_ifname; 506 ifp->if_unit = ng_iface_next_unit++; 507 ifp->if_output = ng_iface_output; 508 ifp->if_start = ng_iface_start; 509 ifp->if_ioctl = ng_iface_ioctl; 510 ifp->if_watchdog = NULL; 511 ifp->if_snd.ifq_maxlen = IFQ_MAXLEN; 512 ifp->if_mtu = NG_IFACE_MTU_DEFAULT; 513 ifp->if_flags = (IFF_SIMPLEX | IFF_POINTOPOINT | IFF_NOARP | IFF_MULTICAST); 514 ifp->if_type = IFT_PROPVIRTUAL; /* XXX */ 515 ifp->if_addrlen = 0; /* XXX */ 516 ifp->if_hdrlen = 0; /* XXX */ 517 ifp->if_baudrate = 64000; /* XXX */ 518 TAILQ_INIT(&ifp->if_addrhead); 519 520 /* Give this node the same name as the interface (if possible) */ 521 bzero(ifname, sizeof(ifname)); 522 sprintf(ifname, "%s%d", ifp->if_name, ifp->if_unit); 523 (void) ng_name_node(node, ifname); 524 525 /* Attach the interface */ 526 if_attach(ifp); 527 bpfattach(ifp, DLT_NULL, sizeof(u_int)); 528 529 /* Done */ 530 return (0); 531 } 532 533 /* 534 * Give our ok for a hook to be added 535 */ 536 static int 537 ng_iface_newhook(node_p node, hook_p hook, const char *name) 538 { 539 const iffam_p iffam = get_iffam_from_name(name); 540 hook_p *hookptr; 541 542 if (iffam == NULL) 543 return (EPFNOSUPPORT); 544 hookptr = get_hook_from_iffam((priv_p) node->private, iffam); 545 if (*hookptr != NULL) 546 return (EISCONN); 547 *hookptr = hook; 548 return (0); 549 } 550 551 /* 552 * Receive a control message 553 */ 554 static int 555 ng_iface_rcvmsg(node_p node, struct ng_mesg *msg, 556 const char *retaddr, struct ng_mesg **rptr) 557 { 558 const priv_p priv = node->private; 559 struct ifnet *const ifp = priv->ifp; 560 struct ng_mesg *resp = NULL; 561 int error = 0; 562 563 switch (msg->header.typecookie) { 564 case NGM_IFACE_COOKIE: 565 switch (msg->header.cmd) { 566 case NGM_IFACE_GET_IFNAME: 567 { 568 struct ng_iface_ifname *arg; 569 570 NG_MKRESPONSE(resp, msg, sizeof(*arg), M_NOWAIT); 571 if (resp == NULL) { 572 error = ENOMEM; 573 break; 574 } 575 arg = (struct ng_iface_ifname *) resp->data; 576 sprintf(arg->ngif_name, 577 "%s%d", ifp->if_name, ifp->if_unit); 578 break; 579 } 580 581 case NGM_IFACE_GET_IFADDRS: 582 { 583 struct ifaddr *ifa; 584 caddr_t ptr; 585 int buflen; 586 587 #define SA_SIZE(s) ((s)->sa_len<sizeof(*(s))? sizeof(*(s)):(s)->sa_len) 588 589 /* Determine size of response and allocate it */ 590 buflen = 0; 591 TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) 592 buflen += SA_SIZE(ifa->ifa_addr); 593 NG_MKRESPONSE(resp, msg, buflen, M_NOWAIT); 594 if (resp == NULL) { 595 error = ENOMEM; 596 break; 597 } 598 599 /* Add addresses */ 600 ptr = resp->data; 601 TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) { 602 const int len = SA_SIZE(ifa->ifa_addr); 603 604 if (buflen < len) { 605 log(LOG_ERR, "%s%d: len changed?\n", 606 ifp->if_name, ifp->if_unit); 607 break; 608 } 609 bcopy(ifa->ifa_addr, ptr, len); 610 ptr += len; 611 buflen -= len; 612 } 613 break; 614 #undef SA_SIZE 615 } 616 617 default: 618 error = EINVAL; 619 break; 620 } 621 break; 622 case NGM_CISCO_COOKIE: 623 switch (msg->header.cmd) { 624 case NGM_CISCO_GET_IPADDR: /* we understand this too */ 625 { 626 struct ifaddr *ifa; 627 628 /* Return the first configured IP address */ 629 TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) { 630 struct in_addr *ips; 631 632 if (ifa->ifa_addr->sa_family != AF_INET) 633 continue; 634 NG_MKRESPONSE(resp, msg, 635 2 * sizeof(*ips), M_NOWAIT); 636 if (resp == NULL) { 637 error = ENOMEM; 638 break; 639 } 640 ips = (struct in_addr *) resp->data; 641 ips[0] = ((struct sockaddr_in *) 642 ifa->ifa_addr)->sin_addr; 643 ips[1] = ((struct sockaddr_in *) 644 ifa->ifa_netmask)->sin_addr; 645 break; 646 } 647 648 /* No IP addresses on this interface? */ 649 if (ifa == NULL) 650 error = EADDRNOTAVAIL; 651 break; 652 } 653 default: 654 error = EINVAL; 655 break; 656 } 657 break; 658 default: 659 error = EINVAL; 660 break; 661 } 662 if (rptr) 663 *rptr = resp; 664 else if (resp) 665 FREE(resp, M_NETGRAPH); 666 FREE(msg, M_NETGRAPH); 667 return (error); 668 } 669 670 /* 671 * Recive data from a hook. Pass the packet to the correct input routine. 672 */ 673 static int 674 ng_iface_rcvdata(hook_p hook, struct mbuf *m, meta_p meta) 675 { 676 const priv_p priv = hook->node->private; 677 const iffam_p iffam = get_iffam_from_hook(priv, hook); 678 struct ifnet *const ifp = priv->ifp; 679 int s, error = 0; 680 681 /* Sanity checks */ 682 KASSERT(iffam != NULL, ("%s: iffam", __FUNCTION__)); 683 KASSERT(m->m_flags & M_PKTHDR, ("%s: not pkthdr", __FUNCTION__)); 684 if (m == NULL) 685 return (EINVAL); 686 if ((ifp->if_flags & IFF_UP) == 0) { 687 NG_FREE_DATA(m, meta); 688 return (ENETDOWN); 689 } 690 691 /* Update interface stats */ 692 ifp->if_ipackets++; 693 ifp->if_ibytes += m->m_pkthdr.len; 694 695 /* Note receiving interface */ 696 m->m_pkthdr.rcvif = ifp; 697 698 /* Berkeley packet filter */ 699 ng_iface_bpftap(ifp, m, iffam->af); 700 701 /* Ignore any meta-data */ 702 NG_FREE_META(meta); 703 704 /* Send packet, either by NETISR or use a direct input function */ 705 switch (iffam->netisr) { 706 case NETISR_NONE: 707 (*iffam->u.input)(m); 708 break; 709 default: 710 s = splimp(); 711 schednetisr(iffam->netisr); 712 if (IF_QFULL(iffam->u.inq)) { 713 IF_DROP(iffam->u.inq); 714 m_freem(m); 715 error = ENOBUFS; 716 } else 717 IF_ENQUEUE(iffam->u.inq, m); 718 splx(s); 719 break; 720 } 721 722 /* Done */ 723 return (error); 724 } 725 726 /* 727 * Because the BSD networking code doesn't support the removal of 728 * networking interfaces, iface nodes (once created) are persistent. 729 * So this method breaks all connections and marks the interface 730 * down, but does not remove the node. 731 */ 732 static int 733 ng_iface_rmnode(node_p node) 734 { 735 const priv_p priv = node->private; 736 struct ifnet *const ifp = priv->ifp; 737 738 ng_cutlinks(node); 739 node->flags &= ~NG_INVALID; 740 ifp->if_flags &= ~(IFF_UP | IFF_RUNNING | IFF_OACTIVE); 741 return (0); 742 } 743 744 /* 745 * Hook disconnection 746 */ 747 static int 748 ng_iface_disconnect(hook_p hook) 749 { 750 const priv_p priv = hook->node->private; 751 const iffam_p iffam = get_iffam_from_hook(priv, hook); 752 753 if (iffam == NULL) 754 panic(__FUNCTION__); 755 *get_hook_from_iffam(priv, iffam) = NULL; 756 return (0); 757 } 758 759