2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 1982, 1986, 1991, 1993
5 * The Regents of the University of California. All rights reserved.
6 * Copyright (C) 2001 WIDE Project. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * @(#)in.c 8.4 (Berkeley) 1/9/95
35 #include <sys/cdefs.h>
36 __FBSDID("$FreeBSD$");
38 #include "opt_mpath.h"
40 #include <sys/param.h>
41 #include <sys/eventhandler.h>
42 #include <sys/systm.h>
43 #include <sys/sockio.h>
44 #include <sys/malloc.h>
46 #include <sys/socket.h>
48 #include <sys/kernel.h>
51 #include <sys/rmlock.h>
52 #include <sys/sysctl.h>
53 #include <sys/syslog.h>
57 #include <net/if_var.h>
58 #include <net/if_arp.h>
59 #include <net/if_dl.h>
60 #include <net/if_llatbl.h>
61 #include <net/if_types.h>
62 #include <net/route.h>
65 #include <netinet/if_ether.h>
66 #include <netinet/in.h>
67 #include <netinet/in_var.h>
68 #include <netinet/in_pcb.h>
69 #include <netinet/ip_var.h>
70 #include <netinet/ip_carp.h>
71 #include <netinet/igmp_var.h>
72 #include <netinet/udp.h>
73 #include <netinet/udp_var.h>
75 static int in_aifaddr_ioctl(u_long, caddr_t, struct ifnet *, struct thread *);
76 static int in_difaddr_ioctl(u_long, caddr_t, struct ifnet *, struct thread *);
77 static int in_gifaddr_ioctl(u_long, caddr_t, struct ifnet *, struct thread *);
79 static void in_socktrim(struct sockaddr_in *);
80 static void in_purgemaddrs(struct ifnet *);
82 VNET_DEFINE_STATIC(int, nosameprefix);
83 #define V_nosameprefix VNET(nosameprefix)
84 SYSCTL_INT(_net_inet_ip, OID_AUTO, no_same_prefix, CTLFLAG_VNET | CTLFLAG_RW,
85 &VNET_NAME(nosameprefix), 0,
86 "Refuse to create same prefixes on different interfaces");
88 VNET_DECLARE(struct inpcbinfo, ripcbinfo);
89 #define V_ripcbinfo VNET(ripcbinfo)
91 static struct sx in_control_sx;
92 SX_SYSINIT(in_control_sx, &in_control_sx, "in_control");
95 * Return 1 if an internet address is for a ``local'' host
96 * (one to which we have a connection).
99 in_localaddr(struct in_addr in)
101 struct rm_priotracker in_ifa_tracker;
102 u_long i = ntohl(in.s_addr);
103 struct in_ifaddr *ia;
105 IN_IFADDR_RLOCK(&in_ifa_tracker);
106 CK_STAILQ_FOREACH(ia, &V_in_ifaddrhead, ia_link) {
107 if ((i & ia->ia_subnetmask) == ia->ia_subnet) {
108 IN_IFADDR_RUNLOCK(&in_ifa_tracker);
112 IN_IFADDR_RUNLOCK(&in_ifa_tracker);
117 * Return 1 if an internet address is for the local host and configured
118 * on one of its interfaces.
121 in_localip(struct in_addr in)
123 struct rm_priotracker in_ifa_tracker;
124 struct in_ifaddr *ia;
126 IN_IFADDR_RLOCK(&in_ifa_tracker);
127 LIST_FOREACH(ia, INADDR_HASH(in.s_addr), ia_hash) {
128 if (IA_SIN(ia)->sin_addr.s_addr == in.s_addr) {
129 IN_IFADDR_RUNLOCK(&in_ifa_tracker);
133 IN_IFADDR_RUNLOCK(&in_ifa_tracker);
138 * Return 1 if an internet address is configured on an interface.
141 in_ifhasaddr(struct ifnet *ifp, struct in_addr in)
144 struct in_ifaddr *ia;
147 CK_STAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
148 if (ifa->ifa_addr->sa_family != AF_INET)
150 ia = (struct in_ifaddr *)ifa;
151 if (ia->ia_addr.sin_addr.s_addr == in.s_addr) {
152 IF_ADDR_RUNLOCK(ifp);
156 IF_ADDR_RUNLOCK(ifp);
162 * Return a reference to the interface address which is different to
163 * the supplied one but with same IP address value.
165 static struct in_ifaddr *
166 in_localip_more(struct in_ifaddr *ia)
168 struct rm_priotracker in_ifa_tracker;
169 in_addr_t in = IA_SIN(ia)->sin_addr.s_addr;
170 struct in_ifaddr *it;
172 IN_IFADDR_RLOCK(&in_ifa_tracker);
173 LIST_FOREACH(it, INADDR_HASH(in), ia_hash) {
174 if (it != ia && IA_SIN(it)->sin_addr.s_addr == in) {
175 ifa_ref(&it->ia_ifa);
176 IN_IFADDR_RUNLOCK(&in_ifa_tracker);
180 IN_IFADDR_RUNLOCK(&in_ifa_tracker);
186 * Determine whether an IP address is in a reserved set of addresses
187 * that may not be forwarded, or whether datagrams to that destination
191 in_canforward(struct in_addr in)
193 u_long i = ntohl(in.s_addr);
195 if (IN_EXPERIMENTAL(i) || IN_MULTICAST(i) || IN_LINKLOCAL(i) ||
196 IN_ZERONET(i) || IN_LOOPBACK(i))
202 * Trim a mask in a sockaddr
205 in_socktrim(struct sockaddr_in *ap)
207 char *cplim = (char *) &ap->sin_addr;
208 char *cp = (char *) (&ap->sin_addr + 1);
211 while (--cp >= cplim)
213 (ap)->sin_len = cp - (char *) (ap) + 1;
219 * Generic internet control operations (ioctl's).
222 in_control(struct socket *so, u_long cmd, caddr_t data, struct ifnet *ifp,
225 struct ifreq *ifr = (struct ifreq *)data;
226 struct sockaddr_in *addr = (struct sockaddr_in *)&ifr->ifr_addr;
228 struct in_ifaddr *ia;
232 return (EADDRNOTAVAIL);
235 * Filter out 4 ioctls we implement directly. Forward the rest
236 * to specific functions and ifp->if_ioctl().
245 sx_xlock(&in_control_sx);
246 error = in_gifaddr_ioctl(cmd, data, ifp, td);
247 sx_xunlock(&in_control_sx);
250 sx_xlock(&in_control_sx);
251 error = in_difaddr_ioctl(cmd, data, ifp, td);
252 sx_xunlock(&in_control_sx);
254 case OSIOCAIFADDR: /* 9.x compat */
256 sx_xlock(&in_control_sx);
257 error = in_aifaddr_ioctl(cmd, data, ifp, td);
258 sx_xunlock(&in_control_sx);
264 /* We no longer support that old commands. */
267 if (ifp->if_ioctl == NULL)
269 return ((*ifp->if_ioctl)(ifp, cmd, data));
272 if (addr->sin_addr.s_addr != INADDR_ANY &&
273 prison_check_ip4(td->td_ucred, &addr->sin_addr) != 0)
274 return (EADDRNOTAVAIL);
277 * Find address for this interface, if it exists. If an
278 * address was specified, find that one instead of the
279 * first one on the interface, if possible.
282 CK_STAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
283 if (ifa->ifa_addr->sa_family != AF_INET)
285 ia = (struct in_ifaddr *)ifa;
286 if (ia->ia_addr.sin_addr.s_addr == addr->sin_addr.s_addr)
290 CK_STAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link)
291 if (ifa->ifa_addr->sa_family == AF_INET) {
292 ia = (struct in_ifaddr *)ifa;
293 if (prison_check_ip4(td->td_ucred,
294 &ia->ia_addr.sin_addr) == 0)
299 IF_ADDR_RUNLOCK(ifp);
300 return (EADDRNOTAVAIL);
310 if ((ifp->if_flags & IFF_BROADCAST) == 0) {
314 *addr = ia->ia_broadaddr;
318 if ((ifp->if_flags & IFF_POINTOPOINT) == 0) {
322 *addr = ia->ia_dstaddr;
326 *addr = ia->ia_sockmask;
330 IF_ADDR_RUNLOCK(ifp);
336 in_aifaddr_ioctl(u_long cmd, caddr_t data, struct ifnet *ifp, struct thread *td)
338 const struct in_aliasreq *ifra = (struct in_aliasreq *)data;
339 const struct sockaddr_in *addr = &ifra->ifra_addr;
340 const struct sockaddr_in *broadaddr = &ifra->ifra_broadaddr;
341 const struct sockaddr_in *mask = &ifra->ifra_mask;
342 const struct sockaddr_in *dstaddr = &ifra->ifra_dstaddr;
343 const int vhid = (cmd == SIOCAIFADDR) ? ifra->ifra_vhid : 0;
345 struct in_ifaddr *ia;
349 error = priv_check(td, PRIV_NET_ADDIFADDR);
354 * ifra_addr must be present and be of INET family.
355 * ifra_broadaddr/ifra_dstaddr and ifra_mask are optional.
357 if (addr->sin_len != sizeof(struct sockaddr_in) ||
358 addr->sin_family != AF_INET)
360 if (broadaddr->sin_len != 0 &&
361 (broadaddr->sin_len != sizeof(struct sockaddr_in) ||
362 broadaddr->sin_family != AF_INET))
364 if (mask->sin_len != 0 &&
365 (mask->sin_len != sizeof(struct sockaddr_in) ||
366 mask->sin_family != AF_INET))
368 if ((ifp->if_flags & IFF_POINTOPOINT) &&
369 (dstaddr->sin_len != sizeof(struct sockaddr_in) ||
370 dstaddr->sin_addr.s_addr == INADDR_ANY))
371 return (EDESTADDRREQ);
372 if (vhid != 0 && carp_attach_p == NULL)
373 return (EPROTONOSUPPORT);
376 * See whether address already exist.
381 CK_STAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
382 struct in_ifaddr *it;
384 if (ifa->ifa_addr->sa_family != AF_INET)
387 it = (struct in_ifaddr *)ifa;
388 if (it->ia_addr.sin_addr.s_addr == addr->sin_addr.s_addr &&
389 prison_check_ip4(td->td_ucred, &addr->sin_addr) == 0)
394 IF_ADDR_RUNLOCK(ifp);
397 (void )in_difaddr_ioctl(cmd, data, ifp, td);
399 ifa = ifa_alloc(sizeof(struct in_ifaddr), M_WAITOK);
400 ia = (struct in_ifaddr *)ifa;
401 ifa->ifa_addr = (struct sockaddr *)&ia->ia_addr;
402 ifa->ifa_dstaddr = (struct sockaddr *)&ia->ia_dstaddr;
403 ifa->ifa_netmask = (struct sockaddr *)&ia->ia_sockmask;
404 callout_init_rw(&ia->ia_garp_timer, &ifp->if_addr_lock,
405 CALLOUT_RETURNUNLOCKED);
409 if (mask->sin_len != 0) {
410 ia->ia_sockmask = *mask;
411 ia->ia_subnetmask = ntohl(ia->ia_sockmask.sin_addr.s_addr);
413 in_addr_t i = ntohl(addr->sin_addr.s_addr);
416 * Be compatible with network classes, if netmask isn't
417 * supplied, guess it based on classes.
420 ia->ia_subnetmask = IN_CLASSA_NET;
421 else if (IN_CLASSB(i))
422 ia->ia_subnetmask = IN_CLASSB_NET;
424 ia->ia_subnetmask = IN_CLASSC_NET;
425 ia->ia_sockmask.sin_addr.s_addr = htonl(ia->ia_subnetmask);
427 ia->ia_subnet = ntohl(addr->sin_addr.s_addr) & ia->ia_subnetmask;
428 in_socktrim(&ia->ia_sockmask);
430 if (ifp->if_flags & IFF_BROADCAST) {
431 if (broadaddr->sin_len != 0) {
432 ia->ia_broadaddr = *broadaddr;
433 } else if (ia->ia_subnetmask == IN_RFC3021_MASK) {
434 ia->ia_broadaddr.sin_addr.s_addr = INADDR_BROADCAST;
435 ia->ia_broadaddr.sin_len = sizeof(struct sockaddr_in);
436 ia->ia_broadaddr.sin_family = AF_INET;
438 ia->ia_broadaddr.sin_addr.s_addr =
439 htonl(ia->ia_subnet | ~ia->ia_subnetmask);
440 ia->ia_broadaddr.sin_len = sizeof(struct sockaddr_in);
441 ia->ia_broadaddr.sin_family = AF_INET;
445 if (ifp->if_flags & IFF_POINTOPOINT)
446 ia->ia_dstaddr = *dstaddr;
448 /* XXXGL: rtinit() needs this strange assignment. */
449 if (ifp->if_flags & IFF_LOOPBACK)
450 ia->ia_dstaddr = ia->ia_addr;
453 error = (*carp_attach_p)(&ia->ia_ifa, vhid);
458 /* if_addrhead is already referenced by ifa_alloc() */
460 CK_STAILQ_INSERT_TAIL(&ifp->if_addrhead, ifa, ifa_link);
461 IF_ADDR_WUNLOCK(ifp);
463 ifa_ref(ifa); /* in_ifaddrhead */
465 CK_STAILQ_INSERT_TAIL(&V_in_ifaddrhead, ia, ia_link);
466 LIST_INSERT_HEAD(INADDR_HASH(ia->ia_addr.sin_addr.s_addr), ia, ia_hash);
470 * Give the interface a chance to initialize
471 * if this is its first address,
472 * and to validate the address if necessary.
474 if (ifp->if_ioctl != NULL) {
475 error = (*ifp->if_ioctl)(ifp, SIOCSIFADDR, (caddr_t)ia);
481 * Add route for the network.
486 if (ifp->if_flags & (IFF_LOOPBACK|IFF_POINTOPOINT))
489 error = in_addprefix(ia, flags);
495 * Add a loopback route to self.
497 if (vhid == 0 && (ifp->if_flags & IFF_LOOPBACK) == 0 &&
498 ia->ia_addr.sin_addr.s_addr != INADDR_ANY &&
499 !((ifp->if_flags & IFF_POINTOPOINT) &&
500 ia->ia_dstaddr.sin_addr.s_addr == ia->ia_addr.sin_addr.s_addr)) {
501 struct in_ifaddr *eia;
503 eia = in_localip_more(ia);
506 error = ifa_add_loopback_route((struct ifaddr *)ia,
507 (struct sockaddr *)&ia->ia_addr);
511 ifa_free(&eia->ia_ifa);
514 if (iaIsFirst && (ifp->if_flags & IFF_MULTICAST)) {
515 struct in_addr allhosts_addr;
516 struct in_ifinfo *ii;
518 ii = ((struct in_ifinfo *)ifp->if_afdata[AF_INET]);
519 allhosts_addr.s_addr = htonl(INADDR_ALLHOSTS_GROUP);
521 error = in_joingroup(ifp, &allhosts_addr, NULL,
526 * Note: we don't need extra reference for ifa, since we called
527 * with sx lock held, and ifaddr can not be deleted in concurrent
530 EVENTHANDLER_INVOKE(ifaddr_event_ext, ifp, ifa, IFADDR_EVENT_ADD);
536 (void )in_scrubprefix(ia, LLE_STATIC);
539 if (ia->ia_ifa.ifa_carp)
540 (*carp_detach_p)(&ia->ia_ifa, false);
543 CK_STAILQ_REMOVE(&ifp->if_addrhead, &ia->ia_ifa, ifaddr, ifa_link);
544 IF_ADDR_WUNLOCK(ifp);
545 ifa_free(&ia->ia_ifa); /* if_addrhead */
548 CK_STAILQ_REMOVE(&V_in_ifaddrhead, ia, in_ifaddr, ia_link);
549 LIST_REMOVE(ia, ia_hash);
551 ifa_free(&ia->ia_ifa); /* in_ifaddrhead */
557 in_difaddr_ioctl(u_long cmd, caddr_t data, struct ifnet *ifp, struct thread *td)
559 const struct ifreq *ifr = (struct ifreq *)data;
560 const struct sockaddr_in *addr = (const struct sockaddr_in *)
563 struct in_ifaddr *ia;
564 bool deleteAny, iaIsLast;
568 error = priv_check(td, PRIV_NET_DELIFADDR);
573 if (addr->sin_len != sizeof(struct sockaddr_in) ||
574 addr->sin_family != AF_INET)
582 CK_STAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
583 struct in_ifaddr *it;
585 if (ifa->ifa_addr->sa_family != AF_INET)
588 it = (struct in_ifaddr *)ifa;
589 if (deleteAny && ia == NULL && (td == NULL ||
590 prison_check_ip4(td->td_ucred, &it->ia_addr.sin_addr) == 0))
593 if (it->ia_addr.sin_addr.s_addr == addr->sin_addr.s_addr &&
594 (td == NULL || prison_check_ip4(td->td_ucred,
595 &addr->sin_addr) == 0))
603 IF_ADDR_WUNLOCK(ifp);
604 return (EADDRNOTAVAIL);
607 CK_STAILQ_REMOVE(&ifp->if_addrhead, &ia->ia_ifa, ifaddr, ifa_link);
608 IF_ADDR_WUNLOCK(ifp);
609 ifa_free(&ia->ia_ifa); /* if_addrhead */
612 CK_STAILQ_REMOVE(&V_in_ifaddrhead, ia, in_ifaddr, ia_link);
613 LIST_REMOVE(ia, ia_hash);
617 * in_scrubprefix() kills the interface route.
619 in_scrubprefix(ia, LLE_STATIC);
622 * in_ifadown gets rid of all the rest of
623 * the routes. This is not quite the right
624 * thing to do, but at least if we are running
625 * a routing process they will come back.
627 in_ifadown(&ia->ia_ifa, 1);
629 if (ia->ia_ifa.ifa_carp)
630 (*carp_detach_p)(&ia->ia_ifa, cmd == SIOCAIFADDR);
633 * If this is the last IPv4 address configured on this
634 * interface, leave the all-hosts group.
635 * No state-change report need be transmitted.
637 if (iaIsLast && (ifp->if_flags & IFF_MULTICAST)) {
638 struct in_ifinfo *ii;
640 ii = ((struct in_ifinfo *)ifp->if_afdata[AF_INET]);
641 if (ii->ii_allhosts) {
642 (void)in_leavegroup(ii->ii_allhosts, NULL);
643 ii->ii_allhosts = NULL;
648 if (callout_stop(&ia->ia_garp_timer) == 1) {
649 ifa_free(&ia->ia_ifa);
651 IF_ADDR_WUNLOCK(ifp);
653 EVENTHANDLER_INVOKE(ifaddr_event_ext, ifp, &ia->ia_ifa,
655 ifa_free(&ia->ia_ifa); /* in_ifaddrhead */
661 in_gifaddr_ioctl(u_long cmd, caddr_t data, struct ifnet *ifp, struct thread *td)
663 struct in_aliasreq *ifra = (struct in_aliasreq *)data;
664 const struct sockaddr_in *addr = &ifra->ifra_addr;
665 struct epoch_tracker et;
667 struct in_ifaddr *ia;
670 * ifra_addr must be present and be of INET family.
672 if (addr->sin_len != sizeof(struct sockaddr_in) ||
673 addr->sin_family != AF_INET)
677 * See whether address exist.
680 NET_EPOCH_ENTER_ET(et);
681 CK_STAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
682 struct in_ifaddr *it;
684 if (ifa->ifa_addr->sa_family != AF_INET)
687 it = (struct in_ifaddr *)ifa;
688 if (it->ia_addr.sin_addr.s_addr == addr->sin_addr.s_addr &&
689 prison_check_ip4(td->td_ucred, &addr->sin_addr) == 0) {
695 NET_EPOCH_EXIT_ET(et);
696 return (EADDRNOTAVAIL);
699 ifra->ifra_mask = ia->ia_sockmask;
700 if ((ifp->if_flags & IFF_POINTOPOINT) &&
701 ia->ia_dstaddr.sin_family == AF_INET)
702 ifra->ifra_dstaddr = ia->ia_dstaddr;
703 else if ((ifp->if_flags & IFF_BROADCAST) &&
704 ia->ia_broadaddr.sin_family == AF_INET)
705 ifra->ifra_broadaddr = ia->ia_broadaddr;
707 memset(&ifra->ifra_broadaddr, 0,
708 sizeof(ifra->ifra_broadaddr));
710 NET_EPOCH_EXIT_ET(et);
714 #define rtinitflags(x) \
715 ((((x)->ia_ifp->if_flags & (IFF_LOOPBACK | IFF_POINTOPOINT)) != 0) \
719 * Check if we have a route for the given prefix already or add one accordingly.
722 in_addprefix(struct in_ifaddr *target, int flags)
724 struct rm_priotracker in_ifa_tracker;
725 struct in_ifaddr *ia;
726 struct in_addr prefix, mask, p, m;
729 if ((flags & RTF_HOST) != 0) {
730 prefix = target->ia_dstaddr.sin_addr;
733 prefix = target->ia_addr.sin_addr;
734 mask = target->ia_sockmask.sin_addr;
735 prefix.s_addr &= mask.s_addr;
738 IN_IFADDR_RLOCK(&in_ifa_tracker);
739 /* Look for an existing address with the same prefix, mask, and fib */
740 CK_STAILQ_FOREACH(ia, &V_in_ifaddrhead, ia_link) {
741 if (rtinitflags(ia)) {
742 p = ia->ia_dstaddr.sin_addr;
744 if (prefix.s_addr != p.s_addr)
747 p = ia->ia_addr.sin_addr;
748 m = ia->ia_sockmask.sin_addr;
749 p.s_addr &= m.s_addr;
751 if (prefix.s_addr != p.s_addr ||
752 mask.s_addr != m.s_addr)
755 if (target->ia_ifp->if_fib != ia->ia_ifp->if_fib)
759 * If we got a matching prefix route inserted by other
760 * interface address, we are done here.
762 if (ia->ia_flags & IFA_ROUTE) {
764 if (ia->ia_addr.sin_addr.s_addr ==
765 target->ia_addr.sin_addr.s_addr) {
766 IN_IFADDR_RUNLOCK(&in_ifa_tracker);
771 if (V_nosameprefix) {
772 IN_IFADDR_RUNLOCK(&in_ifa_tracker);
777 fibnum = V_rt_add_addr_allfibs ? RT_ALL_FIBS :
778 target->ia_ifp->if_fib;
779 rt_addrmsg(RTM_ADD, &target->ia_ifa, fibnum);
780 IN_IFADDR_RUNLOCK(&in_ifa_tracker);
785 IN_IFADDR_RUNLOCK(&in_ifa_tracker);
788 * No-one seem to have this prefix route, so we try to insert it.
790 error = rtinit(&target->ia_ifa, (int)RTM_ADD, flags);
792 target->ia_flags |= IFA_ROUTE;
797 * Removes either all lle entries for given @ia, or lle
798 * corresponding to @ia address.
801 in_scrubprefixlle(struct in_ifaddr *ia, int all, u_int flags)
803 struct sockaddr_in addr, mask;
804 struct sockaddr *saddr, *smask;
807 saddr = (struct sockaddr *)&addr;
808 bzero(&addr, sizeof(addr));
809 addr.sin_len = sizeof(addr);
810 addr.sin_family = AF_INET;
811 smask = (struct sockaddr *)&mask;
812 bzero(&mask, sizeof(mask));
813 mask.sin_len = sizeof(mask);
814 mask.sin_family = AF_INET;
815 mask.sin_addr.s_addr = ia->ia_subnetmask;
821 * Remove all L2 entries matching given prefix.
822 * Convert address to host representation to avoid
823 * doing this on every callback. ia_subnetmask is already
824 * stored in host representation.
826 addr.sin_addr.s_addr = ntohl(ia->ia_addr.sin_addr.s_addr);
827 lltable_prefix_free(AF_INET, saddr, smask, flags);
829 /* Remove interface address only */
830 addr.sin_addr.s_addr = ia->ia_addr.sin_addr.s_addr;
831 lltable_delete_addr(LLTABLE(ifp), LLE_IFADDR, saddr);
836 * If there is no other address in the system that can serve a route to the
837 * same prefix, remove the route. Hand over the route to the new address
841 in_scrubprefix(struct in_ifaddr *target, u_int flags)
843 struct rm_priotracker in_ifa_tracker;
844 struct in_ifaddr *ia;
845 struct in_addr prefix, mask, p, m;
849 * Remove the loopback route to the interface address.
851 if ((target->ia_addr.sin_addr.s_addr != INADDR_ANY) &&
852 !(target->ia_ifp->if_flags & IFF_LOOPBACK) &&
853 (flags & LLE_STATIC)) {
854 struct in_ifaddr *eia;
857 * XXXME: add fib-aware in_localip.
858 * We definitely don't want to switch between
859 * prefixes in different fibs.
861 eia = in_localip_more(target);
864 error = ifa_switch_loopback_route((struct ifaddr *)eia,
865 (struct sockaddr *)&target->ia_addr);
866 ifa_free(&eia->ia_ifa);
868 error = ifa_del_loopback_route((struct ifaddr *)target,
869 (struct sockaddr *)&target->ia_addr);
873 if (rtinitflags(target)) {
874 prefix = target->ia_dstaddr.sin_addr;
877 prefix = target->ia_addr.sin_addr;
878 mask = target->ia_sockmask.sin_addr;
879 prefix.s_addr &= mask.s_addr;
882 if ((target->ia_flags & IFA_ROUTE) == 0) {
885 fibnum = V_rt_add_addr_allfibs ? RT_ALL_FIBS :
886 target->ia_ifp->if_fib;
887 rt_addrmsg(RTM_DELETE, &target->ia_ifa, fibnum);
890 * Removing address from !IFF_UP interface or
891 * prefix which exists on other interface (along with route).
892 * No entries should exist here except target addr.
893 * Given that, delete this entry only.
895 in_scrubprefixlle(target, 0, flags);
899 IN_IFADDR_RLOCK(&in_ifa_tracker);
900 CK_STAILQ_FOREACH(ia, &V_in_ifaddrhead, ia_link) {
901 if (rtinitflags(ia)) {
902 p = ia->ia_dstaddr.sin_addr;
904 if (prefix.s_addr != p.s_addr)
907 p = ia->ia_addr.sin_addr;
908 m = ia->ia_sockmask.sin_addr;
909 p.s_addr &= m.s_addr;
911 if (prefix.s_addr != p.s_addr ||
912 mask.s_addr != m.s_addr)
916 if ((ia->ia_ifp->if_flags & IFF_UP) == 0)
920 * If we got a matching prefix address, move IFA_ROUTE and
921 * the route itself to it. Make sure that routing daemons
924 if ((ia->ia_flags & IFA_ROUTE) == 0) {
925 ifa_ref(&ia->ia_ifa);
926 IN_IFADDR_RUNLOCK(&in_ifa_tracker);
927 error = rtinit(&(target->ia_ifa), (int)RTM_DELETE,
928 rtinitflags(target));
930 target->ia_flags &= ~IFA_ROUTE;
932 log(LOG_INFO, "in_scrubprefix: err=%d, old prefix delete failed\n",
934 /* Scrub all entries IFF interface is different */
935 in_scrubprefixlle(target, target->ia_ifp != ia->ia_ifp,
937 error = rtinit(&ia->ia_ifa, (int)RTM_ADD,
938 rtinitflags(ia) | RTF_UP);
940 ia->ia_flags |= IFA_ROUTE;
942 log(LOG_INFO, "in_scrubprefix: err=%d, new prefix add failed\n",
944 ifa_free(&ia->ia_ifa);
948 IN_IFADDR_RUNLOCK(&in_ifa_tracker);
951 * remove all L2 entries on the given prefix
953 in_scrubprefixlle(target, 1, flags);
956 * As no-one seem to have this prefix, we can remove the route.
958 error = rtinit(&(target->ia_ifa), (int)RTM_DELETE, rtinitflags(target));
960 target->ia_flags &= ~IFA_ROUTE;
962 log(LOG_INFO, "in_scrubprefix: err=%d, prefix delete failed\n", error);
972 struct ifaddr *ifa, *nifa;
973 struct ifaliasreq ifr;
976 CK_STAILQ_FOREACH(ifp, &V_ifnet, if_link) {
977 /* Cannot lock here - lock recursion. */
978 /* IF_ADDR_RLOCK(ifp); */
979 CK_STAILQ_FOREACH_SAFE(ifa, &ifp->if_addrhead, ifa_link, nifa) {
980 if (ifa->ifa_addr->sa_family != AF_INET)
984 * This is ugly but the only way for legacy IP to
985 * cleanly remove addresses and everything attached.
987 bzero(&ifr, sizeof(ifr));
988 ifr.ifra_addr = *ifa->ifa_addr;
989 if (ifa->ifa_dstaddr)
990 ifr.ifra_broadaddr = *ifa->ifa_dstaddr;
991 (void)in_control(NULL, SIOCDIFADDR, (caddr_t)&ifr,
994 /* IF_ADDR_RUNLOCK(ifp); */
996 igmp_domifdetach(ifp);
1002 in_ifaddr_broadcast(struct in_addr in, struct in_ifaddr *ia)
1005 return ((in.s_addr == ia->ia_broadaddr.sin_addr.s_addr ||
1007 * Check for old-style (host 0) broadcast, but
1008 * taking into account that RFC 3021 obsoletes it.
1010 (ia->ia_subnetmask != IN_RFC3021_MASK &&
1011 ntohl(in.s_addr) == ia->ia_subnet)) &&
1013 * Check for an all one subnetmask. These
1014 * only exist when an interface gets a secondary
1017 ia->ia_subnetmask != (u_long)0xffffffff);
1021 * Return 1 if the address might be a local broadcast address.
1024 in_broadcast(struct in_addr in, struct ifnet *ifp)
1029 if (in.s_addr == INADDR_BROADCAST ||
1030 in.s_addr == INADDR_ANY)
1032 if ((ifp->if_flags & IFF_BROADCAST) == 0)
1036 * Look through the list of addresses for a match
1037 * with a broadcast address.
1040 CK_STAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link)
1041 if (ifa->ifa_addr->sa_family == AF_INET &&
1042 in_ifaddr_broadcast(in, (struct in_ifaddr *)ifa)) {
1046 IF_ADDR_RUNLOCK(ifp);
1051 * On interface removal, clean up IPv4 data structures hung off of the ifnet.
1054 in_ifdetach(struct ifnet *ifp)
1057 in_pcbpurgeif0(&V_ripcbinfo, ifp);
1058 in_pcbpurgeif0(&V_udbinfo, ifp);
1059 in_pcbpurgeif0(&V_ulitecbinfo, ifp);
1060 in_purgemaddrs(ifp);
1064 * Make sure all multicast deletions invoking if_ioctl() are
1065 * completed before returning. Else we risk accessing a freed
1066 * ifnet structure pointer.
1068 inm_release_wait(NULL);
1072 * Delete all IPv4 multicast address records, and associated link-layer
1073 * multicast address records, associated with ifp.
1074 * XXX It looks like domifdetach runs AFTER the link layer cleanup.
1075 * XXX This should not race with ifma_protospec being set during
1076 * a new allocation, if it does, we have bigger problems.
1079 in_purgemaddrs(struct ifnet *ifp)
1081 struct in_multi_head purgeinms;
1082 struct in_multi *inm;
1083 struct ifmultiaddr *ifma, *next;
1085 SLIST_INIT(&purgeinms);
1086 IN_MULTI_LIST_LOCK();
1089 * Extract list of in_multi associated with the detaching ifp
1090 * which the PF_INET layer is about to release.
1091 * We need to do this as IF_ADDR_LOCK() may be re-acquired
1092 * by code further down.
1096 CK_STAILQ_FOREACH_SAFE(ifma, &ifp->if_multiaddrs, ifma_link, next) {
1097 if (ifma->ifma_addr->sa_family != AF_INET ||
1098 ifma->ifma_protospec == NULL)
1100 inm = (struct in_multi *)ifma->ifma_protospec;
1101 inm_rele_locked(&purgeinms, inm);
1102 if (__predict_false(ifma_restart)) {
1103 ifma_restart = true;
1107 IF_ADDR_WUNLOCK(ifp);
1109 inm_release_list_deferred(&purgeinms);
1111 IN_MULTI_LIST_UNLOCK();
1115 struct llentry base;
1118 #define IN_LLTBL_DEFAULT_HSIZE 32
1119 #define IN_LLTBL_HASH(k, h) \
1120 (((((((k >> 8) ^ k) >> 8) ^ k) >> 8) ^ k) & ((h) - 1))
1123 * Do actual deallocation of @lle.
1126 in_lltable_destroy_lle_unlocked(epoch_context_t ctx)
1128 struct llentry *lle;
1130 lle = __containerof(ctx, struct llentry, lle_epoch_ctx);
1131 LLE_LOCK_DESTROY(lle);
1132 LLE_REQ_DESTROY(lle);
1133 free(lle, M_LLTABLE);
1137 * Called by the datapath to indicate that
1138 * the entry was used.
1141 in_lltable_mark_used(struct llentry *lle)
1145 lle->r_skip_req = 0;
1146 LLE_REQ_UNLOCK(lle);
1150 * Called by LLE_FREE_LOCKED when number of references
1154 in_lltable_destroy_lle(struct llentry *lle)
1158 epoch_call(net_epoch_preempt, &lle->lle_epoch_ctx, in_lltable_destroy_lle_unlocked);
1161 static struct llentry *
1162 in_lltable_new(struct in_addr addr4, u_int flags)
1164 struct in_llentry *lle;
1166 lle = malloc(sizeof(struct in_llentry), M_LLTABLE, M_NOWAIT | M_ZERO);
1167 if (lle == NULL) /* NB: caller generates msg */
1171 * For IPv4 this will trigger "arpresolve" to generate
1174 lle->base.la_expire = time_uptime; /* mark expired */
1175 lle->base.r_l3addr.addr4 = addr4;
1176 lle->base.lle_refcnt = 1;
1177 lle->base.lle_free = in_lltable_destroy_lle;
1178 LLE_LOCK_INIT(&lle->base);
1179 LLE_REQ_INIT(&lle->base);
1180 callout_init(&lle->base.lle_timer, 1);
1182 return (&lle->base);
1185 #define IN_ARE_MASKED_ADDR_EQUAL(d, a, m) ( \
1186 ((((d).s_addr ^ (a).s_addr) & (m).s_addr)) == 0 )
1189 in_lltable_match_prefix(const struct sockaddr *saddr,
1190 const struct sockaddr *smask, u_int flags, struct llentry *lle)
1192 struct in_addr addr, mask, lle_addr;
1194 addr = ((const struct sockaddr_in *)saddr)->sin_addr;
1195 mask = ((const struct sockaddr_in *)smask)->sin_addr;
1196 lle_addr.s_addr = ntohl(lle->r_l3addr.addr4.s_addr);
1198 if (IN_ARE_MASKED_ADDR_EQUAL(lle_addr, addr, mask) == 0)
1201 if (lle->la_flags & LLE_IFADDR) {
1204 * Delete LLE_IFADDR records IFF address & flag matches.
1205 * Note that addr is the interface address within prefix
1207 * Note also we should handle 'ifdown' cases without removing
1210 if (addr.s_addr == lle_addr.s_addr && (flags & LLE_STATIC) != 0)
1215 /* flags & LLE_STATIC means deleting both dynamic and static entries */
1216 if ((flags & LLE_STATIC) || !(lle->la_flags & LLE_STATIC))
1223 in_lltable_free_entry(struct lltable *llt, struct llentry *lle)
1225 size_t pkts_dropped;
1227 LLE_WLOCK_ASSERT(lle);
1228 KASSERT(llt != NULL, ("lltable is NULL"));
1230 /* Unlink entry from table if not already */
1231 if ((lle->la_flags & LLE_LINKED) != 0) {
1232 IF_AFDATA_WLOCK_ASSERT(llt->llt_ifp);
1233 lltable_unlink_entry(llt, lle);
1236 /* Drop hold queue */
1237 pkts_dropped = llentry_free(lle);
1238 ARPSTAT_ADD(dropped, pkts_dropped);
1242 in_lltable_rtcheck(struct ifnet *ifp, u_int flags, const struct sockaddr *l3addr)
1244 struct rt_addrinfo info;
1245 struct sockaddr_in rt_key, rt_mask;
1246 struct sockaddr rt_gateway;
1249 KASSERT(l3addr->sa_family == AF_INET,
1250 ("sin_family %d", l3addr->sa_family));
1252 bzero(&rt_key, sizeof(rt_key));
1253 rt_key.sin_len = sizeof(rt_key);
1254 bzero(&rt_mask, sizeof(rt_mask));
1255 rt_mask.sin_len = sizeof(rt_mask);
1256 bzero(&rt_gateway, sizeof(rt_gateway));
1257 rt_gateway.sa_len = sizeof(rt_gateway);
1259 bzero(&info, sizeof(info));
1260 info.rti_info[RTAX_DST] = (struct sockaddr *)&rt_key;
1261 info.rti_info[RTAX_NETMASK] = (struct sockaddr *)&rt_mask;
1262 info.rti_info[RTAX_GATEWAY] = (struct sockaddr *)&rt_gateway;
1264 if (rib_lookup_info(ifp->if_fib, l3addr, NHR_REF, 0, &info) != 0)
1267 rt_flags = info.rti_flags;
1270 * If the gateway for an existing host route matches the target L3
1271 * address, which is a special route inserted by some implementation
1272 * such as MANET, and the interface is of the correct type, then
1273 * allow for ARP to proceed.
1275 if (rt_flags & RTF_GATEWAY) {
1276 if (!(rt_flags & RTF_HOST) || !info.rti_ifp ||
1277 info.rti_ifp->if_type != IFT_ETHER ||
1278 (info.rti_ifp->if_flags & (IFF_NOARP | IFF_STATICARP)) != 0 ||
1279 memcmp(rt_gateway.sa_data, l3addr->sa_data,
1280 sizeof(in_addr_t)) != 0) {
1281 rib_free_info(&info);
1285 rib_free_info(&info);
1288 * Make sure that at least the destination address is covered
1289 * by the route. This is for handling the case where 2 or more
1290 * interfaces have the same prefix. An incoming packet arrives
1291 * on one interface and the corresponding outgoing packet leaves
1292 * another interface.
1294 if (!(rt_flags & RTF_HOST) && info.rti_ifp != ifp) {
1295 const char *sa, *mask, *addr, *lim;
1296 const struct sockaddr_in *l3sin;
1298 mask = (const char *)&rt_mask;
1300 * Just being extra cautious to avoid some custom
1301 * code getting into trouble.
1303 if ((info.rti_addrs & RTA_NETMASK) == 0)
1306 sa = (const char *)&rt_key;
1307 addr = (const char *)l3addr;
1308 l3sin = (const struct sockaddr_in *)l3addr;
1309 lim = addr + l3sin->sin_len;
1311 for ( ; addr < lim; sa++, mask++, addr++) {
1312 if ((*sa ^ *addr) & *mask) {
1314 char addrbuf[INET_ADDRSTRLEN];
1316 log(LOG_INFO, "IPv4 address: \"%s\" "
1317 "is not on the network\n",
1318 inet_ntoa_r(l3sin->sin_addr, addrbuf));
1328 static inline uint32_t
1329 in_lltable_hash_dst(const struct in_addr dst, uint32_t hsize)
1332 return (IN_LLTBL_HASH(dst.s_addr, hsize));
1336 in_lltable_hash(const struct llentry *lle, uint32_t hsize)
1339 return (in_lltable_hash_dst(lle->r_l3addr.addr4, hsize));
1343 in_lltable_fill_sa_entry(const struct llentry *lle, struct sockaddr *sa)
1345 struct sockaddr_in *sin;
1347 sin = (struct sockaddr_in *)sa;
1348 bzero(sin, sizeof(*sin));
1349 sin->sin_family = AF_INET;
1350 sin->sin_len = sizeof(*sin);
1351 sin->sin_addr = lle->r_l3addr.addr4;
1354 static inline struct llentry *
1355 in_lltable_find_dst(struct lltable *llt, struct in_addr dst)
1357 struct llentry *lle;
1358 struct llentries *lleh;
1361 hashidx = in_lltable_hash_dst(dst, llt->llt_hsize);
1362 lleh = &llt->lle_head[hashidx];
1363 CK_LIST_FOREACH(lle, lleh, lle_next) {
1364 if (lle->la_flags & LLE_DELETED)
1366 if (lle->r_l3addr.addr4.s_addr == dst.s_addr)
1374 in_lltable_delete_entry(struct lltable *llt, struct llentry *lle)
1377 lle->la_flags |= LLE_DELETED;
1378 EVENTHANDLER_INVOKE(lle_event, lle, LLENTRY_DELETED);
1380 log(LOG_INFO, "ifaddr cache = %p is deleted\n", lle);
1385 static struct llentry *
1386 in_lltable_alloc(struct lltable *llt, u_int flags, const struct sockaddr *l3addr)
1388 const struct sockaddr_in *sin = (const struct sockaddr_in *)l3addr;
1389 struct ifnet *ifp = llt->llt_ifp;
1390 struct llentry *lle;
1391 char linkhdr[LLE_MAX_LINKHDR];
1395 KASSERT(l3addr->sa_family == AF_INET,
1396 ("sin_family %d", l3addr->sa_family));
1399 * A route that covers the given address must have
1400 * been installed 1st because we are doing a resolution,
1403 if (!(flags & LLE_IFADDR) &&
1404 in_lltable_rtcheck(ifp, flags, l3addr) != 0)
1407 lle = in_lltable_new(sin->sin_addr, flags);
1409 log(LOG_INFO, "lla_lookup: new lle malloc failed\n");
1412 lle->la_flags = flags;
1413 if (flags & LLE_STATIC)
1414 lle->r_flags |= RLLE_VALID;
1415 if ((flags & LLE_IFADDR) == LLE_IFADDR) {
1416 linkhdrsize = LLE_MAX_LINKHDR;
1417 if (lltable_calc_llheader(ifp, AF_INET, IF_LLADDR(ifp),
1418 linkhdr, &linkhdrsize, &lladdr_off) != 0) {
1419 epoch_call(net_epoch_preempt, &lle->lle_epoch_ctx, in_lltable_destroy_lle_unlocked);
1422 lltable_set_entry_addr(ifp, lle, linkhdr, linkhdrsize,
1424 lle->la_flags |= LLE_STATIC;
1425 lle->r_flags |= (RLLE_VALID | RLLE_IFADDR);
1432 * Return NULL if not found or marked for deletion.
1433 * If found return lle read locked.
1435 static struct llentry *
1436 in_lltable_lookup(struct lltable *llt, u_int flags, const struct sockaddr *l3addr)
1438 const struct sockaddr_in *sin = (const struct sockaddr_in *)l3addr;
1439 struct llentry *lle;
1441 IF_AFDATA_LOCK_ASSERT(llt->llt_ifp);
1442 KASSERT(l3addr->sa_family == AF_INET,
1443 ("sin_family %d", l3addr->sa_family));
1444 KASSERT((flags & (LLE_UNLOCKED | LLE_EXCLUSIVE)) !=
1445 (LLE_UNLOCKED | LLE_EXCLUSIVE),
1446 ("wrong lle request flags: %#x", flags));
1448 lle = in_lltable_find_dst(llt, sin->sin_addr);
1451 if (flags & LLE_UNLOCKED)
1454 if (flags & LLE_EXCLUSIVE)
1460 * If the afdata lock is not held, the LLE may have been unlinked while
1461 * we were blocked on the LLE lock. Check for this case.
1463 if (__predict_false((lle->la_flags & LLE_LINKED) == 0)) {
1464 if (flags & LLE_EXCLUSIVE)
1474 in_lltable_dump_entry(struct lltable *llt, struct llentry *lle,
1475 struct sysctl_req *wr)
1477 struct ifnet *ifp = llt->llt_ifp;
1480 struct rt_msghdr rtm;
1481 struct sockaddr_in sin;
1482 struct sockaddr_dl sdl;
1484 struct sockaddr_dl *sdl;
1487 bzero(&arpc, sizeof(arpc));
1488 /* skip deleted entries */
1489 if ((lle->la_flags & LLE_DELETED) == LLE_DELETED)
1491 /* Skip if jailed and not a valid IP of the prison. */
1492 lltable_fill_sa_entry(lle,(struct sockaddr *)&arpc.sin);
1493 if (prison_if(wr->td->td_ucred, (struct sockaddr *)&arpc.sin) != 0)
1496 * produce a msg made of:
1498 * struct sockaddr_in; (IPv4)
1499 * struct sockaddr_dl;
1501 arpc.rtm.rtm_msglen = sizeof(arpc);
1502 arpc.rtm.rtm_version = RTM_VERSION;
1503 arpc.rtm.rtm_type = RTM_GET;
1504 arpc.rtm.rtm_flags = RTF_UP;
1505 arpc.rtm.rtm_addrs = RTA_DST | RTA_GATEWAY;
1508 if (lle->la_flags & LLE_PUB)
1509 arpc.rtm.rtm_flags |= RTF_ANNOUNCE;
1512 sdl->sdl_family = AF_LINK;
1513 sdl->sdl_len = sizeof(*sdl);
1514 sdl->sdl_index = ifp->if_index;
1515 sdl->sdl_type = ifp->if_type;
1516 if ((lle->la_flags & LLE_VALID) == LLE_VALID) {
1517 sdl->sdl_alen = ifp->if_addrlen;
1518 bcopy(lle->ll_addr, LLADDR(sdl), ifp->if_addrlen);
1521 bzero(LLADDR(sdl), ifp->if_addrlen);
1524 arpc.rtm.rtm_rmx.rmx_expire =
1525 lle->la_flags & LLE_STATIC ? 0 : lle->la_expire;
1526 arpc.rtm.rtm_flags |= (RTF_HOST | RTF_LLDATA);
1527 if (lle->la_flags & LLE_STATIC)
1528 arpc.rtm.rtm_flags |= RTF_STATIC;
1529 if (lle->la_flags & LLE_IFADDR)
1530 arpc.rtm.rtm_flags |= RTF_PINNED;
1531 arpc.rtm.rtm_index = ifp->if_index;
1532 error = SYSCTL_OUT(wr, &arpc, sizeof(arpc));
1537 static struct lltable *
1538 in_lltattach(struct ifnet *ifp)
1540 struct lltable *llt;
1542 llt = lltable_allocate_htbl(IN_LLTBL_DEFAULT_HSIZE);
1543 llt->llt_af = AF_INET;
1546 llt->llt_lookup = in_lltable_lookup;
1547 llt->llt_alloc_entry = in_lltable_alloc;
1548 llt->llt_delete_entry = in_lltable_delete_entry;
1549 llt->llt_dump_entry = in_lltable_dump_entry;
1550 llt->llt_hash = in_lltable_hash;
1551 llt->llt_fill_sa_entry = in_lltable_fill_sa_entry;
1552 llt->llt_free_entry = in_lltable_free_entry;
1553 llt->llt_match_prefix = in_lltable_match_prefix;
1554 llt->llt_mark_used = in_lltable_mark_used;
1561 in_domifattach(struct ifnet *ifp)
1563 struct in_ifinfo *ii;
1565 ii = malloc(sizeof(struct in_ifinfo), M_IFADDR, M_WAITOK|M_ZERO);
1567 ii->ii_llt = in_lltattach(ifp);
1568 ii->ii_igmp = igmp_domifattach(ifp);
1574 in_domifdetach(struct ifnet *ifp, void *aux)
1576 struct in_ifinfo *ii = (struct in_ifinfo *)aux;
1578 igmp_domifdetach(ifp);
1579 lltable_free(ii->ii_llt);