2 * Copyright (c) 1980, 1986, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * @(#)if.c 8.5 (Berkeley) 1/9/95
37 #include "opt_compat.h"
38 #include "opt_inet6.h"
42 #include <sys/param.h>
45 #include <sys/malloc.h>
48 #include <sys/systm.h>
50 #include <sys/socket.h>
51 #include <sys/socketvar.h>
52 #include <sys/protosw.h>
53 #include <sys/kernel.h>
54 #include <sys/sockio.h>
55 #include <sys/syslog.h>
56 #include <sys/sysctl.h>
60 #include <net/if_arp.h>
61 #include <net/if_dl.h>
62 #include <net/if_types.h>
63 #include <net/if_var.h>
64 #include <net/radix.h>
65 #include <net/route.h>
67 #if defined(INET) || defined(INET6)
69 #include <netinet/in.h>
70 #include <netinet/in_var.h>
72 #include <netinet6/in6_var.h>
73 #include <netinet6/in6_ifattach.h>
77 #include <netinet/if_ether.h>
80 static int ifconf(u_long, caddr_t);
81 static void if_grow(void);
82 static void if_init(void *);
83 static void if_check(void *);
84 static int if_findindex(struct ifnet *);
85 static void if_qflush(struct ifqueue *);
86 static void if_slowtimo(void *);
87 static void link_rtrequest(int, struct rtentry *, struct rt_addrinfo *);
88 static int if_rtdel(struct radix_node *, void *);
89 static struct if_clone *if_clone_lookup(const char *, int *);
90 static int if_clone_list(struct if_clonereq *);
91 static int ifhwioctl(u_long, struct ifnet *, caddr_t, struct thread *);
94 * XXX: declare here to avoid to include many inet6 related files..
95 * should be more generalized?
97 extern void nd6_setmtu(struct ifnet *);
101 struct ifindex_entry *ifindex_table = NULL;
102 int ifqmaxlen = IFQ_MAXLEN;
103 struct ifnethead ifnet; /* depend on static init XXX */
104 int if_cloners_count;
105 LIST_HEAD(, if_clone) if_cloners = LIST_HEAD_INITIALIZER(if_cloners);
107 static int if_indexlim = 8;
108 static struct klist ifklist;
110 static void filt_netdetach(struct knote *kn);
111 static int filt_netdev(struct knote *kn, long hint);
113 static struct filterops netdev_filtops =
114 { 1, NULL, filt_netdetach, filt_netdev };
117 * System initialization
119 SYSINIT(interfaces, SI_SUB_INIT_IF, SI_ORDER_FIRST, if_init, NULL)
120 SYSINIT(interface_check, SI_SUB_PROTO_IF, SI_ORDER_FIRST, if_check, NULL)
122 MALLOC_DEFINE(M_IFADDR, "ifaddr", "interface address");
123 MALLOC_DEFINE(M_IFMADDR, "ether_multi", "link-level multicast address");
124 MALLOC_DEFINE(M_CLONE, "clone", "interface cloning framework");
126 #define CDEV_MAJOR 165
128 static d_open_t netopen;
129 static d_close_t netclose;
130 static d_ioctl_t netioctl;
131 static d_kqfilter_t netkqfilter;
133 static struct cdevsw net_cdevsw = {
135 /* close */ netclose,
138 /* ioctl */ netioctl,
141 /* strategy */ nostrategy,
143 /* maj */ CDEV_MAJOR,
146 /* flags */ D_KQFILTER,
147 /* kqfilter */ netkqfilter,
151 netopen(dev_t dev, int flag, int mode, struct thread *td)
157 netclose(dev_t dev, int flags, int fmt, struct thread *td)
163 netioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct thread *td)
168 /* only support interface specific ioctls */
169 if (IOCGROUP(cmd) != 'i')
174 * special network device, not interface.
176 if (cmd == SIOCGIFCONF)
177 return (ifconf(cmd, data)); /* XXX remove cmd */
181 ifp = ifnet_byindex(idx);
185 error = ifhwioctl(cmd, ifp, data, td);
186 if (error == ENOIOCTL)
192 netkqfilter(dev_t dev, struct knote *kn)
202 ifp = ifnet_byindex(idx);
205 klist = &ifp->if_klist;
208 switch (kn->kn_filter) {
210 kn->kn_fop = &netdev_filtops;
216 kn->kn_hook = (caddr_t)klist;
219 SLIST_INSERT_HEAD(klist, kn, kn_selnext);
225 filt_netdetach(struct knote *kn)
227 struct klist *klist = (struct klist *)kn->kn_hook;
229 if (kn->kn_status & KN_DETACHED)
231 SLIST_REMOVE(klist, kn, knote, kn_selnext);
235 filt_netdev(struct knote *kn, long hint)
239 * Currently NOTE_EXIT is abused to indicate device detach.
241 if (hint == NOTE_EXIT) {
242 kn->kn_data = NOTE_LINKINV;
243 kn->kn_status |= KN_DETACHED;
244 kn->kn_flags |= (EV_EOF | EV_ONESHOT);
247 kn->kn_data = hint; /* current status */
248 if (kn->kn_sfflags & hint)
249 kn->kn_fflags |= hint;
250 return (kn->kn_fflags != 0);
254 * Network interface utility routines.
256 * Routines with ifa_ifwith* names take sockaddr *'s as
266 SLIST_INIT(&ifklist);
267 if_grow(); /* create initial table */
268 ifdev_byindex(0) = make_dev(&net_cdevsw, 0,
269 UID_ROOT, GID_WHEEL, 0600, "network");
276 struct ifindex_entry *e;
279 n = if_indexlim * sizeof(*e);
280 e = malloc(n, M_IFADDR, M_WAITOK | M_ZERO);
281 if (ifindex_table != NULL) {
282 memcpy((caddr_t)e, (caddr_t)ifindex_table, n/2);
283 free((caddr_t)ifindex_table, M_IFADDR);
297 TAILQ_FOREACH(ifp, &ifnet, if_link) {
298 if (ifp->if_snd.ifq_maxlen == 0) {
299 printf("%s%d XXX: driver didn't set ifq_maxlen\n",
300 ifp->if_name, ifp->if_unit);
301 ifp->if_snd.ifq_maxlen = ifqmaxlen;
303 if (!mtx_initialized(&ifp->if_snd.ifq_mtx)) {
304 printf("%s%d XXX: driver didn't initialize queue mtx\n",
305 ifp->if_name, ifp->if_unit);
306 mtx_init(&ifp->if_snd.ifq_mtx, "unknown",
307 MTX_NETWORK_LOCK, MTX_DEF);
315 if_findindex(struct ifnet *ifp)
318 char eaddr[18], devname[32];
319 const char *name, *p;
321 switch (ifp->if_type) {
322 case IFT_ETHER: /* these types use struct arpcom */
327 snprintf(eaddr, 18, "%6D",
328 ((struct arpcom *)ifp->if_softc)->ac_enaddr, ":");
334 snprintf(devname, 32, "%s%d", ifp->if_name, ifp->if_unit);
335 name = net_cdevsw.d_name;
337 while ((resource_find_dev(&i, name, &unit, NULL, NULL)) == 0) {
338 if (resource_string_value(name, unit, "ether", &p) == 0)
339 if (strcmp(p, eaddr) == 0)
341 if (resource_string_value(name, unit, "dev", &p) == 0)
342 if (strcmp(p, devname) == 0)
348 if (ifaddr_byindex(unit) == NULL)
350 printf("%s%d in use, cannot hardwire it to %s.\n",
351 name, unit, devname);
353 for (unit = 1; ; unit++) {
354 if (unit <= if_index && ifaddr_byindex(unit) != NULL)
356 if (resource_string_value(name, unit, "ether", &p) == 0 ||
357 resource_string_value(name, unit, "dev", &p) == 0)
365 * Attach an interface to the
366 * list of "active" interfaces.
372 unsigned socksize, ifasize;
373 int namelen, masklen;
375 register struct sockaddr_dl *sdl;
376 register struct ifaddr *ifa;
378 TAILQ_INSERT_TAIL(&ifnet, ifp, if_link);
381 * The old code would work if the interface passed a pre-existing
382 * chain of ifaddrs to this code. We don't trust our callers to
383 * properly initialize the tailq, however, so we no longer allow
384 * this unlikely case.
386 TAILQ_INIT(&ifp->if_addrhead);
387 TAILQ_INIT(&ifp->if_prefixhead);
388 TAILQ_INIT(&ifp->if_multiaddrs);
389 SLIST_INIT(&ifp->if_klist);
390 getmicrotime(&ifp->if_lastchange);
394 mac_create_ifnet(ifp);
397 ifp->if_index = if_findindex(ifp);
398 if (ifp->if_index > if_index)
399 if_index = ifp->if_index;
400 if (if_index >= if_indexlim)
403 ifnet_byindex(ifp->if_index) = ifp;
404 ifdev_byindex(ifp->if_index) = make_dev(&net_cdevsw, ifp->if_index,
405 UID_ROOT, GID_WHEEL, 0600, "%s/%s%d",
406 net_cdevsw.d_name, ifp->if_name, ifp->if_unit);
407 make_dev_alias(ifdev_byindex(ifp->if_index), "%s%d",
408 net_cdevsw.d_name, ifp->if_index);
410 mtx_init(&ifp->if_snd.ifq_mtx, ifp->if_name, "if send queue", MTX_DEF);
413 * create a Link Level name for this device
415 namelen = snprintf(workbuf, sizeof(workbuf),
416 "%s%d", ifp->if_name, ifp->if_unit);
417 #define _offsetof(t, m) ((int)((caddr_t)&((t *)0)->m))
418 masklen = _offsetof(struct sockaddr_dl, sdl_data[0]) + namelen;
419 socksize = masklen + ifp->if_addrlen;
420 #define ROUNDUP(a) (1 + (((a) - 1) | (sizeof(long) - 1)))
421 if (socksize < sizeof(*sdl))
422 socksize = sizeof(*sdl);
423 socksize = ROUNDUP(socksize);
424 ifasize = sizeof(*ifa) + 2 * socksize;
425 ifa = (struct ifaddr *)malloc(ifasize, M_IFADDR, M_WAITOK | M_ZERO);
427 sdl = (struct sockaddr_dl *)(ifa + 1);
428 sdl->sdl_len = socksize;
429 sdl->sdl_family = AF_LINK;
430 bcopy(workbuf, sdl->sdl_data, namelen);
431 sdl->sdl_nlen = namelen;
432 sdl->sdl_index = ifp->if_index;
433 sdl->sdl_type = ifp->if_type;
434 ifaddr_byindex(ifp->if_index) = ifa;
436 ifa->ifa_rtrequest = link_rtrequest;
437 ifa->ifa_addr = (struct sockaddr *)sdl;
438 sdl = (struct sockaddr_dl *)(socksize + (caddr_t)sdl);
439 ifa->ifa_netmask = (struct sockaddr *)sdl;
440 sdl->sdl_len = masklen;
442 sdl->sdl_data[--namelen] = 0xff;
443 TAILQ_INSERT_HEAD(&ifp->if_addrhead, ifa, ifa_link);
445 ifp->if_broadcastaddr = 0; /* reliably crash if used uninitialized */
447 /* Announce the interface. */
448 rt_ifannouncemsg(ifp, IFAN_ARRIVAL);
452 * Detach an interface, removing it from the
453 * list of "active" interfaces.
460 struct radix_node_head *rnh;
465 * Remove routes and flush queues.
471 * Remove address from ifindex_table[] and maybe decrement if_index.
472 * Clean up all addresses.
474 ifaddr_byindex(ifp->if_index) = NULL;
475 revoke_and_destroy_dev(ifdev_byindex(ifp->if_index));
476 ifdev_byindex(ifp->if_index) = NULL;
478 while (if_index > 0 && ifaddr_byindex(if_index) == NULL)
481 for (ifa = TAILQ_FIRST(&ifp->if_addrhead); ifa;
482 ifa = TAILQ_FIRST(&ifp->if_addrhead)) {
484 /* XXX: Ugly!! ad hoc just for INET */
485 if (ifa->ifa_addr && ifa->ifa_addr->sa_family == AF_INET) {
486 struct ifaliasreq ifr;
488 bzero(&ifr, sizeof(ifr));
489 ifr.ifra_addr = *ifa->ifa_addr;
490 if (ifa->ifa_dstaddr)
491 ifr.ifra_broadaddr = *ifa->ifa_dstaddr;
492 if (in_control(NULL, SIOCDIFADDR, (caddr_t)&ifr, ifp,
498 if (ifa->ifa_addr && ifa->ifa_addr->sa_family == AF_INET6) {
500 /* ifp_addrhead is already updated */
504 TAILQ_REMOVE(&ifp->if_addrhead, ifa, ifa_link);
510 * Remove all IPv6 kernel structs related to ifp. This should be done
511 * before removing routing entries below, since IPv6 interface direct
512 * routes are expected to be removed by the IPv6-specific kernel API.
513 * Otherwise, the kernel will detect some inconsistency and bark it.
519 * Delete all remaining routes using this interface
520 * Unfortuneatly the only way to do this is to slog through
521 * the entire routing table looking for routes which point
522 * to this interface...oh well...
524 for (i = 1; i <= AF_MAX; i++) {
525 if ((rnh = rt_tables[i]) == NULL)
527 (void) rnh->rnh_walktree(rnh, if_rtdel, ifp);
530 /* Announce that the interface is gone. */
531 rt_ifannouncemsg(ifp, IFAN_DEPARTURE);
534 mac_destroy_ifnet(ifp);
536 KNOTE(&ifp->if_klist, NOTE_EXIT);
537 TAILQ_REMOVE(&ifnet, ifp, if_link);
538 mtx_destroy(&ifp->if_snd.ifq_mtx);
543 * Delete Routes for a Network Interface
545 * Called for each routing entry via the rnh->rnh_walktree() call above
546 * to delete all route entries referencing a detaching network interface.
549 * rn pointer to node in the routing table
550 * arg argument passed to rnh->rnh_walktree() - detaching interface
554 * errno failed - reason indicated
559 struct radix_node *rn;
562 struct rtentry *rt = (struct rtentry *)rn;
563 struct ifnet *ifp = arg;
566 if (rt->rt_ifp == ifp) {
569 * Protect (sorta) against walktree recursion problems
572 if ((rt->rt_flags & RTF_UP) == 0)
575 err = rtrequest(RTM_DELETE, rt_key(rt), rt->rt_gateway,
576 rt_mask(rt), rt->rt_flags,
577 (struct rtentry **) NULL);
579 log(LOG_WARNING, "if_rtdel: error %d\n", err);
587 * Create a clone network interface.
590 if_clone_create(name, len)
594 struct if_clone *ifc;
596 int wildcard, bytoff, bitoff;
600 ifc = if_clone_lookup(name, &unit);
604 if (ifunit(name) != NULL)
608 wildcard = (unit < 0);
610 * Find a free unit if none was given.
613 while ((bytoff < ifc->ifc_bmlen)
614 && (ifc->ifc_units[bytoff] == 0xff))
616 if (bytoff >= ifc->ifc_bmlen)
618 while ((ifc->ifc_units[bytoff] & (1 << bitoff)) != 0)
620 unit = (bytoff << 3) + bitoff;
623 if (unit > ifc->ifc_maxunit)
626 err = (*ifc->ifc_create)(ifc, unit);
632 bitoff = unit - (bytoff << 3);
636 * Allocate the unit in the bitmap.
638 KASSERT((ifc->ifc_units[bytoff] & (1 << bitoff)) == 0,
639 ("%s: bit is already set", __func__));
640 ifc->ifc_units[bytoff] |= (1 << bitoff);
642 /* In the wildcard case, we need to update the name. */
644 for (dp = name; *dp != '\0'; dp++);
645 if (snprintf(dp, len - (dp-name), "%d", unit) >
646 len - (dp-name) - 1) {
648 * This can only be a programmer error and
649 * there's no straightforward way to recover if
652 panic("if_clone_create(): interface name too long");
661 * Destroy a clone network interface.
664 if_clone_destroy(name)
667 struct if_clone *ifc;
672 ifc = if_clone_lookup(name, &unit);
676 if (unit < ifc->ifc_minifs)
683 if (ifc->ifc_destroy == NULL)
686 (*ifc->ifc_destroy)(ifp);
689 * Compute offset in the bitmap and deallocate the unit.
692 bitoff = unit - (bytoff << 3);
693 KASSERT((ifc->ifc_units[bytoff] & (1 << bitoff)) != 0,
694 ("%s: bit is already cleared", __func__));
695 ifc->ifc_units[bytoff] &= ~(1 << bitoff);
700 * Look up a network interface cloner.
702 static struct if_clone *
703 if_clone_lookup(name, unitp)
707 struct if_clone *ifc;
711 for (ifc = LIST_FIRST(&if_cloners); ifc != NULL;) {
712 for (cp = name, i = 0; i < ifc->ifc_namelen; i++, cp++) {
713 if (ifc->ifc_name[i] != *cp)
718 ifc = LIST_NEXT(ifc, ifc_list);
722 return ((struct if_clone *)NULL);
728 for (i = 0; *cp != '\0'; cp++) {
729 if (*cp < '0' || *cp > '9') {
730 /* Bogus unit number. */
733 i = (i * 10) + (*cp - '0');
743 * Register a network interface cloner.
747 struct if_clone *ifc;
754 KASSERT(ifc->ifc_minifs - 1 <= ifc->ifc_maxunit,
755 ("%s: %s requested more units then allowed (%d > %d)",
756 __func__, ifc->ifc_name, ifc->ifc_minifs,
757 ifc->ifc_maxunit + 1));
759 * Compute bitmap size and allocate it.
761 maxclone = ifc->ifc_maxunit + 1;
763 if ((len << 3) < maxclone)
765 ifc->ifc_units = malloc(len, M_CLONE, M_WAITOK | M_ZERO);
766 ifc->ifc_bmlen = len;
768 LIST_INSERT_HEAD(&if_cloners, ifc, ifc_list);
771 for (unit = 0; unit < ifc->ifc_minifs; unit++) {
772 err = (*ifc->ifc_create)(ifc, unit);
774 ("%s: failed to create required interface %s%d",
775 __func__, ifc->ifc_name, unit));
777 /* Allocate the unit in the bitmap. */
779 bitoff = unit - (bytoff << 3);
780 ifc->ifc_units[bytoff] |= (1 << bitoff);
785 * Unregister a network interface cloner.
789 struct if_clone *ifc;
792 LIST_REMOVE(ifc, ifc_list);
793 free(ifc->ifc_units, M_CLONE);
798 * Provide list of interface cloners to userspace.
802 struct if_clonereq *ifcr;
804 char outbuf[IFNAMSIZ], *dst;
805 struct if_clone *ifc;
806 int count, error = 0;
808 ifcr->ifcr_total = if_cloners_count;
809 if ((dst = ifcr->ifcr_buffer) == NULL) {
810 /* Just asking how many there are. */
814 if (ifcr->ifcr_count < 0)
817 count = (if_cloners_count < ifcr->ifcr_count) ?
818 if_cloners_count : ifcr->ifcr_count;
820 for (ifc = LIST_FIRST(&if_cloners); ifc != NULL && count != 0;
821 ifc = LIST_NEXT(ifc, ifc_list), count--, dst += IFNAMSIZ) {
822 strncpy(outbuf, ifc->ifc_name, IFNAMSIZ);
823 outbuf[IFNAMSIZ - 1] = '\0'; /* sanity */
824 error = copyout(outbuf, dst, IFNAMSIZ);
833 * Locate an interface based on a complete address.
838 struct sockaddr *addr;
843 #define equal(a1, a2) \
844 (bcmp((caddr_t)(a1), (caddr_t)(a2), ((struct sockaddr *)(a1))->sa_len) == 0)
845 TAILQ_FOREACH(ifp, &ifnet, if_link)
846 TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
847 if (ifa->ifa_addr->sa_family != addr->sa_family)
849 if (equal(addr, ifa->ifa_addr))
851 /* IP6 doesn't have broadcast */
852 if ((ifp->if_flags & IFF_BROADCAST) &&
853 ifa->ifa_broadaddr &&
854 ifa->ifa_broadaddr->sa_len != 0 &&
855 equal(ifa->ifa_broadaddr, addr))
864 * Locate the point to point interface with a given destination address.
868 ifa_ifwithdstaddr(addr)
869 struct sockaddr *addr;
874 TAILQ_FOREACH(ifp, &ifnet, if_link) {
875 if ((ifp->if_flags & IFF_POINTOPOINT) == 0)
877 TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
878 if (ifa->ifa_addr->sa_family != addr->sa_family)
880 if (ifa->ifa_dstaddr && equal(addr, ifa->ifa_dstaddr))
890 * Find an interface on a specific network. If many, choice
891 * is most specific found.
895 struct sockaddr *addr;
897 register struct ifnet *ifp;
898 register struct ifaddr *ifa;
899 struct ifaddr *ifa_maybe = (struct ifaddr *) 0;
900 u_int af = addr->sa_family;
901 char *addr_data = addr->sa_data, *cplim;
904 * AF_LINK addresses can be looked up directly by their index number,
905 * so do that if we can.
908 register struct sockaddr_dl *sdl = (struct sockaddr_dl *)addr;
909 if (sdl->sdl_index && sdl->sdl_index <= if_index)
910 return (ifaddr_byindex(sdl->sdl_index));
914 * Scan though each interface, looking for ones that have
915 * addresses in this address family.
917 TAILQ_FOREACH(ifp, &ifnet, if_link) {
918 TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
919 register char *cp, *cp2, *cp3;
921 if (ifa->ifa_addr->sa_family != af)
923 if (af == AF_INET && ifp->if_flags & IFF_POINTOPOINT) {
925 * This is a bit broken as it doesn't
926 * take into account that the remote end may
927 * be a single node in the network we are
929 * The trouble is that we don't know the
930 * netmask for the remote end.
932 if (ifa->ifa_dstaddr != 0
933 && equal(addr, ifa->ifa_dstaddr))
937 * if we have a special address handler,
938 * then use it instead of the generic one.
940 if (ifa->ifa_claim_addr) {
941 if ((*ifa->ifa_claim_addr)(ifa, addr))
947 * Scan all the bits in the ifa's address.
948 * If a bit dissagrees with what we are
949 * looking for, mask it with the netmask
950 * to see if it really matters.
953 if (ifa->ifa_netmask == 0)
956 cp2 = ifa->ifa_addr->sa_data;
957 cp3 = ifa->ifa_netmask->sa_data;
958 cplim = ifa->ifa_netmask->sa_len
959 + (char *)ifa->ifa_netmask;
961 if ((*cp++ ^ *cp2++) & *cp3++)
962 goto next; /* next address! */
964 * If the netmask of what we just found
965 * is more specific than what we had before
966 * (if we had one) then remember the new one
967 * before continuing to search
968 * for an even better one.
970 if (ifa_maybe == 0 ||
971 rn_refines((caddr_t)ifa->ifa_netmask,
972 (caddr_t)ifa_maybe->ifa_netmask))
983 * Find an interface address specific to an interface best matching
987 ifaof_ifpforaddr(addr, ifp)
988 struct sockaddr *addr;
989 register struct ifnet *ifp;
991 register struct ifaddr *ifa;
992 register char *cp, *cp2, *cp3;
993 register char *cplim;
994 struct ifaddr *ifa_maybe = 0;
995 u_int af = addr->sa_family;
999 TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
1000 if (ifa->ifa_addr->sa_family != af)
1004 if (ifa->ifa_netmask == 0) {
1005 if (equal(addr, ifa->ifa_addr) ||
1006 (ifa->ifa_dstaddr && equal(addr, ifa->ifa_dstaddr)))
1010 if (ifp->if_flags & IFF_POINTOPOINT) {
1011 if (equal(addr, ifa->ifa_dstaddr))
1015 cp2 = ifa->ifa_addr->sa_data;
1016 cp3 = ifa->ifa_netmask->sa_data;
1017 cplim = ifa->ifa_netmask->sa_len + (char *)ifa->ifa_netmask;
1018 for (; cp3 < cplim; cp3++)
1019 if ((*cp++ ^ *cp2++) & *cp3)
1030 #include <net/route.h>
1033 * Default action when installing a route with a Link Level gateway.
1034 * Lookup an appropriate real ifa to point to.
1035 * This should be moved to /sys/net/link.c eventually.
1038 link_rtrequest(cmd, rt, info)
1040 register struct rtentry *rt;
1041 struct rt_addrinfo *info;
1043 register struct ifaddr *ifa;
1044 struct sockaddr *dst;
1047 if (cmd != RTM_ADD || ((ifa = rt->rt_ifa) == 0) ||
1048 ((ifp = ifa->ifa_ifp) == 0) || ((dst = rt_key(rt)) == 0))
1050 ifa = ifaof_ifpforaddr(dst, ifp);
1052 IFAFREE(rt->rt_ifa);
1055 if (ifa->ifa_rtrequest && ifa->ifa_rtrequest != link_rtrequest)
1056 ifa->ifa_rtrequest(cmd, rt, info);
1061 * Mark an interface down and notify protocols of
1063 * NOTE: must be called at splnet or eqivalent.
1066 if_unroute(ifp, flag, fam)
1067 register struct ifnet *ifp;
1070 register struct ifaddr *ifa;
1072 ifp->if_flags &= ~flag;
1073 getmicrotime(&ifp->if_lastchange);
1074 TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link)
1075 if (fam == PF_UNSPEC || (fam == ifa->ifa_addr->sa_family))
1076 pfctlinput(PRC_IFDOWN, ifa->ifa_addr);
1077 if_qflush(&ifp->if_snd);
1082 * Mark an interface up and notify protocols of
1084 * NOTE: must be called at splnet or eqivalent.
1087 if_route(ifp, flag, fam)
1088 register struct ifnet *ifp;
1091 register struct ifaddr *ifa;
1093 ifp->if_flags |= flag;
1094 getmicrotime(&ifp->if_lastchange);
1095 TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link)
1096 if (fam == PF_UNSPEC || (fam == ifa->ifa_addr->sa_family))
1097 pfctlinput(PRC_IFUP, ifa->ifa_addr);
1105 * Mark an interface down and notify protocols of
1107 * NOTE: must be called at splnet or eqivalent.
1111 register struct ifnet *ifp;
1114 if_unroute(ifp, IFF_UP, AF_UNSPEC);
1118 * Mark an interface up and notify protocols of
1120 * NOTE: must be called at splnet or eqivalent.
1124 register struct ifnet *ifp;
1127 if_route(ifp, IFF_UP, AF_UNSPEC);
1131 * Flush an interface queue.
1135 register struct ifqueue *ifq;
1137 register struct mbuf *m, *n;
1140 while ((m = n) != 0) {
1150 * Handle interface watchdog timer routines. Called
1151 * from softclock, we decrement timers (if set) and
1152 * call the appropriate interface routine on expiration.
1158 register struct ifnet *ifp;
1161 TAILQ_FOREACH(ifp, &ifnet, if_link) {
1162 if (ifp->if_timer == 0 || --ifp->if_timer)
1164 if (ifp->if_watchdog)
1165 (*ifp->if_watchdog)(ifp);
1168 timeout(if_slowtimo, (void *)0, hz / IFNET_SLOWHZ);
1172 * Map interface name to
1173 * interface structure pointer.
1176 ifunit(const char *name)
1178 char namebuf[IFNAMSIZ + 1];
1183 * Now search all the interfaces for this name/number
1188 * Devices should really be known as /dev/fooN, not /dev/net/fooN.
1190 snprintf(namebuf, IFNAMSIZ, "%s/%s", net_cdevsw.d_name, name);
1191 TAILQ_FOREACH(ifp, &ifnet, if_link) {
1192 dev = ifdev_byindex(ifp->if_index);
1193 if (strcmp(devtoname(dev), namebuf) == 0)
1195 if (dev_named(dev, name))
1202 * Map interface name in a sockaddr_dl to
1203 * interface structure pointer.
1207 struct sockaddr *sa;
1209 char ifname[IFNAMSIZ+1];
1210 struct sockaddr_dl *sdl = (struct sockaddr_dl *)sa;
1212 if ( (sa->sa_family != AF_LINK) || (sdl->sdl_nlen == 0) ||
1213 (sdl->sdl_nlen > IFNAMSIZ) )
1217 * ifunit wants a NUL-terminated string. It may not be NUL-terminated
1218 * in the sockaddr, and we don't want to change the caller's sockaddr
1219 * (there might not be room to add the trailing NUL anyway), so we make
1220 * a local copy that we know we can NUL-terminate safely.
1223 bcopy(sdl->sdl_data, ifname, sdl->sdl_nlen);
1224 ifname[sdl->sdl_nlen] = '\0';
1225 return ifunit(ifname);
1229 * Hardware specific interface ioctls.
1232 ifhwioctl(u_long cmd, struct ifnet *ifp, caddr_t data, struct thread *td)
1239 ifr = (struct ifreq *)data;
1242 ifr->ifr_index = ifp->if_index;
1246 ifr->ifr_flags = ifp->if_flags & 0xffff;
1247 ifr->ifr_flagshigh = ifp->if_flags >> 16;
1251 ifr->ifr_reqcap = ifp->if_capabilities;
1252 ifr->ifr_curcap = ifp->if_capenable;
1257 error = mac_ioctl_ifnet_get(td->td_proc->p_ucred, ifr, ifp);
1262 ifr->ifr_metric = ifp->if_metric;
1266 ifr->ifr_mtu = ifp->if_mtu;
1270 ifr->ifr_phys = ifp->if_physical;
1277 new_flags = (ifr->ifr_flags & 0xffff) |
1278 (ifr->ifr_flagshigh << 16);
1279 if (ifp->if_flags & IFF_SMART) {
1280 /* Smart drivers twiddle their own routes */
1281 } else if (ifp->if_flags & IFF_UP &&
1282 (new_flags & IFF_UP) == 0) {
1286 } else if (new_flags & IFF_UP &&
1287 (ifp->if_flags & IFF_UP) == 0) {
1292 ifp->if_flags = (ifp->if_flags & IFF_CANTCHANGE) |
1293 (new_flags &~ IFF_CANTCHANGE);
1294 if (new_flags & IFF_PPROMISC) {
1295 /* Permanently promiscuous mode requested */
1296 ifp->if_flags |= IFF_PROMISC;
1297 } else if (ifp->if_pcount == 0) {
1298 ifp->if_flags &= ~IFF_PROMISC;
1301 (void) (*ifp->if_ioctl)(ifp, cmd, data);
1302 getmicrotime(&ifp->if_lastchange);
1309 if (ifr->ifr_reqcap & ~ifp->if_capabilities)
1311 (void) (*ifp->if_ioctl)(ifp, cmd, data);
1316 error = mac_ioctl_ifnet_set(td->td_proc->p_ucred, ifr, ifp);
1324 ifp->if_metric = ifr->ifr_metric;
1325 getmicrotime(&ifp->if_lastchange);
1334 error = (*ifp->if_ioctl)(ifp, cmd, data);
1336 getmicrotime(&ifp->if_lastchange);
1341 u_long oldmtu = ifp->if_mtu;
1346 if (ifr->ifr_mtu < IF_MINMTU || ifr->ifr_mtu > IF_MAXMTU)
1348 if (ifp->if_ioctl == NULL)
1349 return (EOPNOTSUPP);
1350 error = (*ifp->if_ioctl)(ifp, cmd, data);
1352 getmicrotime(&ifp->if_lastchange);
1356 * If the link MTU changed, do network layer specific procedure.
1358 if (ifp->if_mtu != oldmtu) {
1372 /* Don't allow group membership on non-multicast interfaces. */
1373 if ((ifp->if_flags & IFF_MULTICAST) == 0)
1374 return (EOPNOTSUPP);
1376 /* Don't let users screw up protocols' entries. */
1377 if (ifr->ifr_addr.sa_family != AF_LINK)
1380 if (cmd == SIOCADDMULTI) {
1381 struct ifmultiaddr *ifma;
1382 error = if_addmulti(ifp, &ifr->ifr_addr, &ifma);
1384 error = if_delmulti(ifp, &ifr->ifr_addr);
1387 getmicrotime(&ifp->if_lastchange);
1390 case SIOCSIFPHYADDR:
1391 case SIOCDIFPHYADDR:
1393 case SIOCSIFPHYADDR_IN6:
1395 case SIOCSLIFPHYADDR:
1397 case SIOCSIFGENERIC:
1401 if (ifp->if_ioctl == NULL)
1402 return (EOPNOTSUPP);
1403 error = (*ifp->if_ioctl)(ifp, cmd, data);
1405 getmicrotime(&ifp->if_lastchange);
1409 ifs = (struct ifstat *)data;
1410 ifs->ascii[0] = '\0';
1412 case SIOCGIFPSRCADDR:
1413 case SIOCGIFPDSTADDR:
1414 case SIOCGLIFPHYADDR:
1416 case SIOCGIFGENERIC:
1417 if (ifp->if_ioctl == 0)
1418 return (EOPNOTSUPP);
1419 error = (*ifp->if_ioctl)(ifp, cmd, data);
1426 error = if_setlladdr(ifp,
1427 ifr->ifr_addr.sa_data, ifr->ifr_addr.sa_len);
1441 ifioctl(so, cmd, data, td)
1455 return (ifconf(cmd, data));
1457 ifr = (struct ifreq *)data;
1462 if ((error = suser(td)) != 0)
1464 return ((cmd == SIOCIFCREATE) ?
1465 if_clone_create(ifr->ifr_name, sizeof(ifr->ifr_name)) :
1466 if_clone_destroy(ifr->ifr_name));
1468 case SIOCIFGCLONERS:
1469 return (if_clone_list((struct if_clonereq *)data));
1472 ifp = ifunit(ifr->ifr_name);
1476 error = ifhwioctl(cmd, ifp, data, td);
1477 if (error != ENOIOCTL)
1480 oif_flags = ifp->if_flags;
1481 if (so->so_proto == 0)
1482 return (EOPNOTSUPP);
1484 error = ((*so->so_proto->pr_usrreqs->pru_control)(so, cmd,
1493 case SIOCSIFDSTADDR:
1495 case SIOCSIFBRDADDR:
1496 case SIOCSIFNETMASK:
1497 #if BYTE_ORDER != BIG_ENDIAN
1498 if (ifr->ifr_addr.sa_family == 0 &&
1499 ifr->ifr_addr.sa_len < 16) {
1500 ifr->ifr_addr.sa_family = ifr->ifr_addr.sa_len;
1501 ifr->ifr_addr.sa_len = 16;
1504 if (ifr->ifr_addr.sa_len == 0)
1505 ifr->ifr_addr.sa_len = 16;
1513 case OSIOCGIFDSTADDR:
1514 cmd = SIOCGIFDSTADDR;
1517 case OSIOCGIFBRDADDR:
1518 cmd = SIOCGIFBRDADDR;
1521 case OSIOCGIFNETMASK:
1522 cmd = SIOCGIFNETMASK;
1524 error = ((*so->so_proto->pr_usrreqs->pru_control)(so,
1531 case OSIOCGIFDSTADDR:
1532 case OSIOCGIFBRDADDR:
1533 case OSIOCGIFNETMASK:
1534 *(u_short *)&ifr->ifr_addr = ifr->ifr_addr.sa_family;
1538 #endif /* COMPAT_43 */
1540 if ((oif_flags ^ ifp->if_flags) & IFF_UP) {
1542 DELAY(100);/* XXX: temporary workaround for fxp issue*/
1543 if (ifp->if_flags & IFF_UP) {
1554 * Set/clear promiscuous mode on interface ifp based on the truth value
1555 * of pswitch. The calls are reference counted so that only the first
1556 * "on" request actually has an effect, as does the final "off" request.
1557 * Results are undefined if the "off" and "on" requests are not matched.
1560 ifpromisc(ifp, pswitch)
1566 int oldflags, oldpcount;
1568 oldpcount = ifp->if_pcount;
1569 oldflags = ifp->if_flags;
1570 if (ifp->if_flags & IFF_PPROMISC) {
1571 /* Do nothing if device is in permanently promiscuous mode */
1572 ifp->if_pcount += pswitch ? 1 : -1;
1577 * If the device is not configured up, we cannot put it in
1580 if ((ifp->if_flags & IFF_UP) == 0)
1582 if (ifp->if_pcount++ != 0)
1584 ifp->if_flags |= IFF_PROMISC;
1586 if (--ifp->if_pcount > 0)
1588 ifp->if_flags &= ~IFF_PROMISC;
1590 ifr.ifr_flags = ifp->if_flags & 0xffff;
1591 ifr.ifr_flagshigh = ifp->if_flags >> 16;
1592 error = (*ifp->if_ioctl)(ifp, SIOCSIFFLAGS, (caddr_t)&ifr);
1594 log(LOG_INFO, "%s%d: promiscuous mode %s\n",
1595 ifp->if_name, ifp->if_unit,
1596 (ifp->if_flags & IFF_PROMISC) ? "enabled" : "disabled");
1599 ifp->if_pcount = oldpcount;
1600 ifp->if_flags = oldflags;
1606 * Return interface configuration
1607 * of system. List may be used
1608 * in later ioctl's (above) to get
1609 * other information.
1617 struct ifconf *ifc = (struct ifconf *)data;
1620 struct ifreq ifr, *ifrp;
1621 int space = ifc->ifc_len, error = 0;
1623 ifrp = ifc->ifc_req;
1624 TAILQ_FOREACH(ifp, &ifnet, if_link) {
1628 if (space < sizeof(ifr))
1630 ifnlen = snprintf(workbuf, sizeof(workbuf),
1631 "%s%d", ifp->if_name, ifp->if_unit);
1632 if(ifnlen + 1 > sizeof ifr.ifr_name) {
1633 error = ENAMETOOLONG;
1636 strcpy(ifr.ifr_name, workbuf);
1640 TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
1641 struct sockaddr *sa = ifa->ifa_addr;
1643 if (space < sizeof(ifr))
1645 if (jailed(curthread->td_ucred) &&
1646 prison_if(curthread->td_ucred, sa))
1650 if (cmd == OSIOCGIFCONF) {
1651 struct osockaddr *osa =
1652 (struct osockaddr *)&ifr.ifr_addr;
1654 osa->sa_family = sa->sa_family;
1655 error = copyout((caddr_t)&ifr, (caddr_t)ifrp,
1660 if (sa->sa_len <= sizeof(*sa)) {
1662 error = copyout((caddr_t)&ifr, (caddr_t)ifrp,
1666 if (space < sizeof (ifr) + sa->sa_len -
1669 space -= sa->sa_len - sizeof(*sa);
1670 error = copyout((caddr_t)&ifr, (caddr_t)ifrp,
1671 sizeof (ifr.ifr_name));
1673 error = copyout((caddr_t)sa,
1674 (caddr_t)&ifrp->ifr_addr, sa->sa_len);
1675 ifrp = (struct ifreq *)
1676 (sa->sa_len + (caddr_t)&ifrp->ifr_addr);
1680 space -= sizeof (ifr);
1685 bzero((caddr_t)&ifr.ifr_addr, sizeof(ifr.ifr_addr));
1686 error = copyout((caddr_t)&ifr, (caddr_t)ifrp,
1690 space -= sizeof (ifr);
1694 ifc->ifc_len -= space;
1699 * Just like if_promisc(), but for all-multicast-reception mode.
1702 if_allmulti(ifp, onswitch)
1711 if (ifp->if_amcount++ == 0) {
1712 ifp->if_flags |= IFF_ALLMULTI;
1713 ifr.ifr_flags = ifp->if_flags & 0xffff;
1714 ifr.ifr_flagshigh = ifp->if_flags >> 16;
1715 error = ifp->if_ioctl(ifp, SIOCSIFFLAGS, (caddr_t)&ifr);
1718 if (ifp->if_amcount > 1) {
1721 ifp->if_amcount = 0;
1722 ifp->if_flags &= ~IFF_ALLMULTI;
1723 ifr.ifr_flags = ifp->if_flags & 0xffff;;
1724 ifr.ifr_flagshigh = ifp->if_flags >> 16;
1725 error = ifp->if_ioctl(ifp, SIOCSIFFLAGS, (caddr_t)&ifr);
1736 * Add a multicast listenership to the interface in question.
1737 * The link layer provides a routine which converts
1740 if_addmulti(ifp, sa, retifma)
1741 struct ifnet *ifp; /* interface to manipulate */
1742 struct sockaddr *sa; /* address to add */
1743 struct ifmultiaddr **retifma;
1745 struct sockaddr *llsa, *dupsa;
1747 struct ifmultiaddr *ifma;
1750 * If the matching multicast address already exists
1751 * then don't add a new one, just add a reference
1753 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
1754 if (equal(sa, ifma->ifma_addr)) {
1755 ifma->ifma_refcount++;
1763 * Give the link layer a chance to accept/reject it, and also
1764 * find out which AF_LINK address this maps to, if it isn't one
1767 if (ifp->if_resolvemulti) {
1768 error = ifp->if_resolvemulti(ifp, &llsa, sa);
1769 if (error) return error;
1774 MALLOC(ifma, struct ifmultiaddr *, sizeof *ifma, M_IFMADDR, M_WAITOK);
1775 MALLOC(dupsa, struct sockaddr *, sa->sa_len, M_IFMADDR, M_WAITOK);
1776 bcopy(sa, dupsa, sa->sa_len);
1778 ifma->ifma_addr = dupsa;
1779 ifma->ifma_lladdr = llsa;
1780 ifma->ifma_ifp = ifp;
1781 ifma->ifma_refcount = 1;
1782 ifma->ifma_protospec = 0;
1783 rt_newmaddrmsg(RTM_NEWMADDR, ifma);
1786 * Some network interfaces can scan the address list at
1787 * interrupt time; lock them out.
1790 TAILQ_INSERT_HEAD(&ifp->if_multiaddrs, ifma, ifma_link);
1792 if (retifma != NULL)
1796 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
1797 if (equal(ifma->ifma_addr, llsa))
1801 ifma->ifma_refcount++;
1803 MALLOC(ifma, struct ifmultiaddr *, sizeof *ifma,
1804 M_IFMADDR, M_WAITOK);
1805 MALLOC(dupsa, struct sockaddr *, llsa->sa_len,
1806 M_IFMADDR, M_WAITOK);
1807 bcopy(llsa, dupsa, llsa->sa_len);
1808 ifma->ifma_addr = dupsa;
1809 ifma->ifma_ifp = ifp;
1810 ifma->ifma_refcount = 1;
1812 TAILQ_INSERT_HEAD(&ifp->if_multiaddrs, ifma, ifma_link);
1817 * We are certain we have added something, so call down to the
1818 * interface to let them know about it.
1821 ifp->if_ioctl(ifp, SIOCADDMULTI, 0);
1828 * Remove a reference to a multicast address on this interface. Yell
1829 * if the request does not match an existing membership.
1832 if_delmulti(ifp, sa)
1834 struct sockaddr *sa;
1836 struct ifmultiaddr *ifma;
1839 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link)
1840 if (equal(sa, ifma->ifma_addr))
1845 if (ifma->ifma_refcount > 1) {
1846 ifma->ifma_refcount--;
1850 rt_newmaddrmsg(RTM_DELMADDR, ifma);
1851 sa = ifma->ifma_lladdr;
1853 TAILQ_REMOVE(&ifp->if_multiaddrs, ifma, ifma_link);
1855 * Make sure the interface driver is notified
1856 * in the case of a link layer mcast group being left.
1858 if (ifma->ifma_addr->sa_family == AF_LINK && sa == 0)
1859 ifp->if_ioctl(ifp, SIOCDELMULTI, 0);
1861 free(ifma->ifma_addr, M_IFMADDR);
1862 free(ifma, M_IFMADDR);
1867 * Now look for the link-layer address which corresponds to
1868 * this network address. It had been squirreled away in
1869 * ifma->ifma_lladdr for this purpose (so we don't have
1870 * to call ifp->if_resolvemulti() again), and we saved that
1871 * value in sa above. If some nasty deleted the
1872 * link-layer address out from underneath us, we can deal because
1873 * the address we stored was is not the same as the one which was
1874 * in the record for the link-layer address. (So we don't complain
1877 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link)
1878 if (equal(sa, ifma->ifma_addr))
1883 if (ifma->ifma_refcount > 1) {
1884 ifma->ifma_refcount--;
1889 TAILQ_REMOVE(&ifp->if_multiaddrs, ifma, ifma_link);
1890 ifp->if_ioctl(ifp, SIOCDELMULTI, 0);
1892 free(ifma->ifma_addr, M_IFMADDR);
1893 free(sa, M_IFMADDR);
1894 free(ifma, M_IFMADDR);
1900 * Set the link layer address on an interface.
1902 * At this time we only support certain types of interfaces,
1903 * and we don't allow the length of the address to change.
1906 if_setlladdr(struct ifnet *ifp, const u_char *lladdr, int len)
1908 struct sockaddr_dl *sdl;
1912 ifa = ifaddr_byindex(ifp->if_index);
1915 sdl = (struct sockaddr_dl *)ifa->ifa_addr;
1918 if (len != sdl->sdl_alen) /* don't allow length to change */
1920 switch (ifp->if_type) {
1921 case IFT_ETHER: /* these types use struct arpcom */
1926 bcopy(lladdr, ((struct arpcom *)ifp->if_softc)->ac_enaddr, len);
1927 bcopy(lladdr, LLADDR(sdl), len);
1933 * If the interface is already up, we need
1934 * to re-init it in order to reprogram its
1937 if ((ifp->if_flags & IFF_UP) != 0) {
1938 ifp->if_flags &= ~IFF_UP;
1939 ifr.ifr_flags = ifp->if_flags & 0xffff;
1940 ifr.ifr_flagshigh = ifp->if_flags >> 16;
1941 (*ifp->if_ioctl)(ifp, SIOCSIFFLAGS, (caddr_t)&ifr);
1942 ifp->if_flags |= IFF_UP;
1943 ifr.ifr_flags = ifp->if_flags & 0xffff;
1944 ifr.ifr_flagshigh = ifp->if_flags >> 16;
1945 (*ifp->if_ioctl)(ifp, SIOCSIFFLAGS, (caddr_t)&ifr);
1948 * Also send gratuitous ARPs to notify other nodes about
1949 * the address change.
1951 TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
1952 if (ifa->ifa_addr != NULL &&
1953 ifa->ifa_addr->sa_family == AF_INET)
1954 arp_ifinit(ifp, ifa);
1961 struct ifmultiaddr *
1962 ifmaof_ifpforaddr(sa, ifp)
1963 struct sockaddr *sa;
1966 struct ifmultiaddr *ifma;
1968 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link)
1969 if (equal(ifma->ifma_addr, sa))
1975 SYSCTL_NODE(_net, PF_LINK, link, CTLFLAG_RW, 0, "Link layers");
1976 SYSCTL_NODE(_net_link, 0, generic, CTLFLAG_RW, 0, "Generic link-management");