2 * Copyright (c) 1982, 1986, 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 * Copyright (C) 2001 WIDE Project. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 4. Neither the name of the University nor the names of its contributors
15 * may be used to endorse or promote products derived from this software
16 * without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * @(#)in.c 8.4 (Berkeley) 1/9/95
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
36 #include "opt_mpath.h"
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/sockio.h>
41 #include <sys/malloc.h>
43 #include <sys/socket.h>
45 #include <sys/kernel.h>
47 #include <sys/sysctl.h>
48 #include <sys/syslog.h>
51 #include <net/if_var.h>
52 #include <net/if_arp.h>
53 #include <net/if_dl.h>
54 #include <net/if_llatbl.h>
55 #include <net/if_types.h>
56 #include <net/route.h>
59 #include <netinet/if_ether.h>
60 #include <netinet/in.h>
61 #include <netinet/in_var.h>
62 #include <netinet/in_pcb.h>
63 #include <netinet/ip_var.h>
64 #include <netinet/ip_carp.h>
65 #include <netinet/igmp_var.h>
66 #include <netinet/udp.h>
67 #include <netinet/udp_var.h>
69 static int in_mask2len(struct in_addr *);
70 static void in_len2mask(struct in_addr *, int);
71 static int in_lifaddr_ioctl(struct socket *, u_long, caddr_t,
72 struct ifnet *, struct thread *);
74 static void in_socktrim(struct sockaddr_in *);
75 static int in_ifinit(struct ifnet *, struct in_ifaddr *,
76 struct sockaddr_in *, int, int, int);
77 static void in_purgemaddrs(struct ifnet *);
79 static VNET_DEFINE(int, nosameprefix);
80 #define V_nosameprefix VNET(nosameprefix)
81 SYSCTL_VNET_INT(_net_inet_ip, OID_AUTO, no_same_prefix, CTLFLAG_RW,
82 &VNET_NAME(nosameprefix), 0,
83 "Refuse to create same prefixes on different interfaces");
85 VNET_DECLARE(struct inpcbinfo, ripcbinfo);
86 #define V_ripcbinfo VNET(ripcbinfo)
88 VNET_DECLARE(struct arpstat, arpstat); /* ARP statistics, see if_arp.h */
89 #define V_arpstat VNET(arpstat)
92 * Return 1 if an internet address is for a ``local'' host
93 * (one to which we have a connection).
96 in_localaddr(struct in_addr in)
98 register u_long i = ntohl(in.s_addr);
99 register struct in_ifaddr *ia;
102 TAILQ_FOREACH(ia, &V_in_ifaddrhead, ia_link) {
103 if ((i & ia->ia_subnetmask) == ia->ia_subnet) {
113 * Return 1 if an internet address is for the local host and configured
114 * on one of its interfaces.
117 in_localip(struct in_addr in)
119 struct in_ifaddr *ia;
122 LIST_FOREACH(ia, INADDR_HASH(in.s_addr), ia_hash) {
123 if (IA_SIN(ia)->sin_addr.s_addr == in.s_addr) {
133 * Determine whether an IP address is in a reserved set of addresses
134 * that may not be forwarded, or whether datagrams to that destination
138 in_canforward(struct in_addr in)
140 register u_long i = ntohl(in.s_addr);
143 if (IN_EXPERIMENTAL(i) || IN_MULTICAST(i) || IN_LINKLOCAL(i))
146 net = i & IN_CLASSA_NET;
147 if (net == 0 || net == (IN_LOOPBACKNET << IN_CLASSA_NSHIFT))
154 * Trim a mask in a sockaddr
157 in_socktrim(struct sockaddr_in *ap)
159 register char *cplim = (char *) &ap->sin_addr;
160 register char *cp = (char *) (&ap->sin_addr + 1);
163 while (--cp >= cplim)
165 (ap)->sin_len = cp - (char *) (ap) + 1;
172 struct in_addr *mask;
178 for (x = 0; x < sizeof(*mask); x++) {
183 if (x < sizeof(*mask)) {
184 for (y = 0; y < 8; y++) {
185 if ((p[x] & (0x80 >> y)) == 0)
193 in_len2mask(struct in_addr *mask, int len)
199 bzero(mask, sizeof(*mask));
200 for (i = 0; i < len / 8; i++)
203 p[i] = (0xff00 >> (len % 8)) & 0xff;
207 * Generic internet control operations (ioctl's).
209 * ifp is NULL if not an interface-specific ioctl.
213 in_control(struct socket *so, u_long cmd, caddr_t data, struct ifnet *ifp,
216 register struct ifreq *ifr = (struct ifreq *)data;
217 register struct in_ifaddr *ia, *iap;
218 register struct ifaddr *ifa;
219 struct in_addr allhosts_addr;
221 struct in_ifinfo *ii;
222 struct in_aliasreq *ifra = (struct in_aliasreq *)data;
223 struct sockaddr_in oldaddr;
224 int error, hostIsNew, iaIsNew, maskIsNew;
229 * Pre-10.x compat: OSIOCAIFADDR passes a shorter
230 * struct in_aliasreq, without ifra_vhid.
232 if (cmd == OSIOCAIFADDR)
238 allhosts_addr.s_addr = htonl(INADDR_ALLHOSTS_GROUP);
241 * Filter out ioctls we implement directly; forward the rest on to
242 * in_lifaddr_ioctl() and ifp->if_ioctl().
253 * ifra_addr must be present and be of INET family.
254 * ifra_broadaddr and ifra_mask are optional.
256 if (ifra->ifra_addr.sin_len != sizeof(struct sockaddr_in) ||
257 ifra->ifra_addr.sin_family != AF_INET)
259 if (ifra->ifra_broadaddr.sin_len != 0 &&
260 (ifra->ifra_broadaddr.sin_len !=
261 sizeof(struct sockaddr_in) ||
262 ifra->ifra_broadaddr.sin_family != AF_INET))
266 * ifconfig(8) in pre-10.x doesn't set sin_family for the
267 * mask. The code is disabled for the 10.x timeline, to
268 * make SIOCAIFADDR compatible with 9.x ifconfig(8).
269 * The code should be enabled in 11.x
271 if (ifra->ifra_mask.sin_len != 0 &&
272 (ifra->ifra_mask.sin_len != sizeof(struct sockaddr_in) ||
273 ifra->ifra_mask.sin_family != AF_INET))
281 if (ifr->ifr_addr.sa_family != AF_INET ||
282 ifr->ifr_addr.sa_len != sizeof(struct sockaddr_in))
288 error = priv_check(td, PRIV_NET_ADDIFADDR);
294 return in_lifaddr_ioctl(so, cmd, data, ifp, td);
298 error = priv_check(td, PRIV_NET_DELIFADDR);
304 return in_lifaddr_ioctl(so, cmd, data, ifp, td);
309 return in_lifaddr_ioctl(so, cmd, data, ifp, td);
312 if (ifp == NULL || ifp->if_ioctl == NULL)
314 return ((*ifp->if_ioctl)(ifp, cmd, data));
318 return (EADDRNOTAVAIL);
321 * Security checks before we get involved in any work.
330 error = priv_check(td, PRIV_NET_ADDIFADDR);
338 error = priv_check(td, PRIV_NET_DELIFADDR);
346 * Find address for this interface, if it exists.
348 * If an alias address was specified, find that one instead of the
349 * first one on the interface, if possible.
351 dst = ((struct sockaddr_in *)&ifr->ifr_addr)->sin_addr;
353 LIST_FOREACH(iap, INADDR_HASH(dst.s_addr), ia_hash) {
354 if (iap->ia_ifp == ifp &&
355 iap->ia_addr.sin_addr.s_addr == dst.s_addr) {
356 if (td == NULL || prison_check_ip4(td->td_ucred,
363 ifa_ref(&ia->ia_ifa);
367 TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
369 if (iap->ia_addr.sin_family == AF_INET) {
371 prison_check_ip4(td->td_ucred,
372 &iap->ia_addr.sin_addr) != 0)
379 ifa_ref(&ia->ia_ifa);
389 if (ifra->ifra_addr.sin_family == AF_INET) {
390 struct in_ifaddr *oia;
393 for (oia = ia; ia; ia = TAILQ_NEXT(ia, ia_link)) {
394 if (ia->ia_ifp == ifp &&
395 ia->ia_addr.sin_addr.s_addr ==
396 ifra->ifra_addr.sin_addr.s_addr)
399 if (ia != NULL && ia != oia)
400 ifa_ref(&ia->ia_ifa);
401 if (oia != NULL && ia != oia)
402 ifa_free(&oia->ia_ifa);
404 if ((ifp->if_flags & IFF_POINTOPOINT)
405 && (cmd == SIOCAIFADDR)
406 && (ifra->ifra_dstaddr.sin_addr.s_addr
408 error = EDESTADDRREQ;
412 if (cmd == SIOCDIFADDR && ia == NULL) {
413 error = EADDRNOTAVAIL;
421 ia = (struct in_ifaddr *)
422 malloc(sizeof *ia, M_IFADDR, M_NOWAIT |
431 ifa->ifa_addr = (struct sockaddr *)&ia->ia_addr;
432 ifa->ifa_dstaddr = (struct sockaddr *)&ia->ia_dstaddr;
433 ifa->ifa_netmask = (struct sockaddr *)&ia->ia_sockmask;
435 ia->ia_sockmask.sin_len = 8;
436 ia->ia_sockmask.sin_family = AF_INET;
437 if (ifp->if_flags & IFF_BROADCAST) {
438 ia->ia_broadaddr.sin_len = sizeof(ia->ia_addr);
439 ia->ia_broadaddr.sin_family = AF_INET;
443 ifa_ref(ifa); /* if_addrhead */
445 TAILQ_INSERT_TAIL(&ifp->if_addrhead, ifa, ifa_link);
447 ifa_ref(ifa); /* in_ifaddrhead */
449 TAILQ_INSERT_TAIL(&V_in_ifaddrhead, ia, ia_link);
461 error = EADDRNOTAVAIL;
468 * Most paths in this switch return directly or via out. Only paths
469 * that remove the address break in order to hit common removal code.
473 *((struct sockaddr_in *)&ifr->ifr_addr) = ia->ia_addr;
477 if ((ifp->if_flags & IFF_BROADCAST) == 0) {
481 *((struct sockaddr_in *)&ifr->ifr_dstaddr) = ia->ia_broadaddr;
485 if ((ifp->if_flags & IFF_POINTOPOINT) == 0) {
489 *((struct sockaddr_in *)&ifr->ifr_dstaddr) = ia->ia_dstaddr;
493 *((struct sockaddr_in *)&ifr->ifr_addr) = ia->ia_sockmask;
497 if ((ifp->if_flags & IFF_POINTOPOINT) == 0) {
501 oldaddr = ia->ia_dstaddr;
502 ia->ia_dstaddr = *(struct sockaddr_in *)&ifr->ifr_dstaddr;
503 if (ifp->if_ioctl != NULL) {
504 error = (*ifp->if_ioctl)(ifp, SIOCSIFDSTADDR,
507 ia->ia_dstaddr = oldaddr;
511 if (ia->ia_flags & IFA_ROUTE) {
512 ia->ia_ifa.ifa_dstaddr = (struct sockaddr *)&oldaddr;
513 rtinit(&(ia->ia_ifa), (int)RTM_DELETE, RTF_HOST);
514 ia->ia_ifa.ifa_dstaddr =
515 (struct sockaddr *)&ia->ia_dstaddr;
516 rtinit(&(ia->ia_ifa), (int)RTM_ADD, RTF_HOST|RTF_UP);
521 if ((ifp->if_flags & IFF_BROADCAST) == 0) {
525 ia->ia_broadaddr = *(struct sockaddr_in *)&ifr->ifr_broadaddr;
529 error = in_ifinit(ifp, ia,
530 (struct sockaddr_in *) &ifr->ifr_addr, 1, 0, 0);
531 if (error != 0 && iaIsNew)
534 ii = ((struct in_ifinfo *)ifp->if_afdata[AF_INET]);
536 (ifp->if_flags & IFF_MULTICAST) != 0) {
537 error = in_joingroup(ifp, &allhosts_addr,
538 NULL, &ii->ii_allhosts);
540 EVENTHANDLER_INVOKE(ifaddr_event, ifp);
546 ia->ia_sockmask.sin_addr = ((struct sockaddr_in *)
547 &ifr->ifr_addr)->sin_addr;
548 ia->ia_subnetmask = ntohl(ia->ia_sockmask.sin_addr.s_addr);
555 if (ifra->ifra_addr.sin_addr.s_addr ==
556 ia->ia_addr.sin_addr.s_addr)
558 if (ifra->ifra_mask.sin_len) {
561 * Need to scrub the prefix here in case
562 * the issued command is SIOCAIFADDR with
563 * the same address, but with a different
564 * prefix length. And if the prefix length
565 * is the same as before, then the call is
566 * un-necessarily executed here.
568 in_ifscrub(ifp, ia, LLE_STATIC);
569 ia->ia_sockmask = ifra->ifra_mask;
570 ia->ia_sockmask.sin_family = AF_INET;
572 ntohl(ia->ia_sockmask.sin_addr.s_addr);
575 if ((ifp->if_flags & IFF_POINTOPOINT) &&
576 (ifra->ifra_dstaddr.sin_family == AF_INET)) {
577 in_ifscrub(ifp, ia, LLE_STATIC);
578 ia->ia_dstaddr = ifra->ifra_dstaddr;
579 maskIsNew = 1; /* We lie; but the effect's the same */
581 if (hostIsNew || maskIsNew)
582 error = in_ifinit(ifp, ia, &ifra->ifra_addr, 0,
583 maskIsNew, (ocmd == cmd ? ifra->ifra_vhid : 0));
584 if (error != 0 && iaIsNew)
587 if ((ifp->if_flags & IFF_BROADCAST) &&
588 ifra->ifra_broadaddr.sin_len)
589 ia->ia_broadaddr = ifra->ifra_broadaddr;
591 ii = ((struct in_ifinfo *)ifp->if_afdata[AF_INET]);
593 (ifp->if_flags & IFF_MULTICAST) != 0) {
594 error = in_joingroup(ifp, &allhosts_addr,
595 NULL, &ii->ii_allhosts);
597 EVENTHANDLER_INVOKE(ifaddr_event, ifp);
603 * in_ifscrub kills the interface route.
605 in_ifscrub(ifp, ia, LLE_STATIC);
608 * in_ifadown gets rid of all the rest of
609 * the routes. This is not quite the right
610 * thing to do, but at least if we are running
611 * a routing process they will come back.
613 in_ifadown(&ia->ia_ifa, 1);
614 EVENTHANDLER_INVOKE(ifaddr_event, ifp);
619 panic("in_control: unsupported ioctl");
622 if (ia->ia_ifa.ifa_carp)
623 (*carp_detach_p)(&ia->ia_ifa);
626 /* Re-check that ia is still part of the list. */
627 TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
628 if (ifa == &ia->ia_ifa)
633 * If we lost the race with another thread, there is no need to
634 * try it again for the next loop as there is no other exit
635 * path between here and out.
638 error = EADDRNOTAVAIL;
641 TAILQ_REMOVE(&ifp->if_addrhead, &ia->ia_ifa, ifa_link);
643 ifa_free(&ia->ia_ifa); /* if_addrhead */
646 TAILQ_REMOVE(&V_in_ifaddrhead, ia, ia_link);
648 LIST_REMOVE(ia, ia_hash);
651 * If this is the last IPv4 address configured on this
652 * interface, leave the all-hosts group.
653 * No state-change report need be transmitted.
657 ii = ((struct in_ifinfo *)ifp->if_afdata[AF_INET]);
659 if (ii->ii_allhosts) {
660 (void)in_leavegroup_locked(ii->ii_allhosts, NULL);
661 ii->ii_allhosts = NULL;
665 ifa_free(&iap->ia_ifa);
667 ifa_free(&ia->ia_ifa); /* in_ifaddrhead */
670 ifa_free(&ia->ia_ifa);
676 * SIOCGLIFADDR: get first address. (?!?)
677 * SIOCGLIFADDR with IFLR_PREFIX:
678 * get first address that matches the specified prefix.
679 * SIOCALIFADDR: add the specified address.
680 * SIOCALIFADDR with IFLR_PREFIX:
681 * EINVAL since we can't deduce hostid part of the address.
682 * SIOCDLIFADDR: delete the specified address.
683 * SIOCDLIFADDR with IFLR_PREFIX:
684 * delete the first address that matches the specified prefix.
686 * EINVAL on invalid parameters
687 * EADDRNOTAVAIL on prefix match failed/specified address not found
688 * other values may be returned from in_ioctl()
691 in_lifaddr_ioctl(struct socket *so, u_long cmd, caddr_t data,
692 struct ifnet *ifp, struct thread *td)
694 struct if_laddrreq *iflr = (struct if_laddrreq *)data;
698 if (data == NULL || ifp == NULL) {
699 panic("invalid argument to in_lifaddr_ioctl");
705 /* address must be specified on GET with IFLR_PREFIX */
706 if ((iflr->flags & IFLR_PREFIX) == 0)
711 /* address must be specified on ADD and DELETE */
712 if (iflr->addr.ss_family != AF_INET)
714 if (iflr->addr.ss_len != sizeof(struct sockaddr_in))
716 /* XXX need improvement */
717 if (iflr->dstaddr.ss_family
718 && iflr->dstaddr.ss_family != AF_INET)
720 if (iflr->dstaddr.ss_family
721 && iflr->dstaddr.ss_len != sizeof(struct sockaddr_in))
724 default: /*shouldn't happen*/
727 if (sizeof(struct in_addr) * 8 < iflr->prefixlen)
733 struct in_aliasreq ifra;
735 if (iflr->flags & IFLR_PREFIX)
738 /* copy args to in_aliasreq, perform ioctl(SIOCAIFADDR_IN6). */
739 bzero(&ifra, sizeof(ifra));
740 bcopy(iflr->iflr_name, ifra.ifra_name,
741 sizeof(ifra.ifra_name));
743 bcopy(&iflr->addr, &ifra.ifra_addr, iflr->addr.ss_len);
745 if (iflr->dstaddr.ss_family) { /*XXX*/
746 bcopy(&iflr->dstaddr, &ifra.ifra_dstaddr,
747 iflr->dstaddr.ss_len);
750 ifra.ifra_mask.sin_family = AF_INET;
751 ifra.ifra_mask.sin_len = sizeof(struct sockaddr_in);
752 in_len2mask(&ifra.ifra_mask.sin_addr, iflr->prefixlen);
754 return (in_control(so, SIOCAIFADDR, (caddr_t)&ifra, ifp, td));
759 struct in_ifaddr *ia;
760 struct in_addr mask, candidate, match;
761 struct sockaddr_in *sin;
763 bzero(&mask, sizeof(mask));
764 bzero(&match, sizeof(match));
765 if (iflr->flags & IFLR_PREFIX) {
766 /* lookup a prefix rather than address. */
767 in_len2mask(&mask, iflr->prefixlen);
769 sin = (struct sockaddr_in *)&iflr->addr;
770 match.s_addr = sin->sin_addr.s_addr;
771 match.s_addr &= mask.s_addr;
773 /* if you set extra bits, that's wrong */
774 if (match.s_addr != sin->sin_addr.s_addr)
778 /* on getting an address, take the 1st match */
779 /* on deleting an address, do exact match */
780 if (cmd != SIOCGLIFADDR) {
781 in_len2mask(&mask, 32);
782 sin = (struct sockaddr_in *)&iflr->addr;
783 match.s_addr = sin->sin_addr.s_addr;
787 TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
788 if (ifa->ifa_addr->sa_family != AF_INET6)
790 if (match.s_addr == 0)
792 candidate.s_addr = ((struct sockaddr_in *)&ifa->ifa_addr)->sin_addr.s_addr;
793 candidate.s_addr &= mask.s_addr;
794 if (candidate.s_addr == match.s_addr)
798 return (EADDRNOTAVAIL);
799 ia = (struct in_ifaddr *)ifa;
801 if (cmd == SIOCGLIFADDR) {
802 /* fill in the if_laddrreq structure */
803 bcopy(&ia->ia_addr, &iflr->addr, ia->ia_addr.sin_len);
805 if ((ifp->if_flags & IFF_POINTOPOINT) != 0) {
806 bcopy(&ia->ia_dstaddr, &iflr->dstaddr,
807 ia->ia_dstaddr.sin_len);
809 bzero(&iflr->dstaddr, sizeof(iflr->dstaddr));
812 in_mask2len(&ia->ia_sockmask.sin_addr);
814 iflr->flags = 0; /*XXX*/
818 struct in_aliasreq ifra;
820 /* fill in_aliasreq and do ioctl(SIOCDIFADDR_IN6) */
821 bzero(&ifra, sizeof(ifra));
822 bcopy(iflr->iflr_name, ifra.ifra_name,
823 sizeof(ifra.ifra_name));
825 bcopy(&ia->ia_addr, &ifra.ifra_addr,
826 ia->ia_addr.sin_len);
827 if ((ifp->if_flags & IFF_POINTOPOINT) != 0) {
828 bcopy(&ia->ia_dstaddr, &ifra.ifra_dstaddr,
829 ia->ia_dstaddr.sin_len);
831 bcopy(&ia->ia_sockmask, &ifra.ifra_dstaddr,
832 ia->ia_sockmask.sin_len);
834 return (in_control(so, SIOCDIFADDR, (caddr_t)&ifra,
840 return (EOPNOTSUPP); /*just for safety*/
844 * Delete any existing route for an interface.
847 in_ifscrub(struct ifnet *ifp, struct in_ifaddr *ia, u_int flags)
850 in_scrubprefix(ia, flags);
854 * Initialize an interface's internet address
855 * and routing table entry.
858 in_ifinit(struct ifnet *ifp, struct in_ifaddr *ia, struct sockaddr_in *sin,
859 int scrub, int masksupplied, int vhid)
861 register u_long i = ntohl(sin->sin_addr.s_addr);
862 int flags = RTF_UP, error = 0;
865 in_scrubprefix(ia, LLE_STATIC);
868 if (ia->ia_addr.sin_family == AF_INET)
869 LIST_REMOVE(ia, ia_hash);
871 LIST_INSERT_HEAD(INADDR_HASH(ia->ia_addr.sin_addr.s_addr),
876 if (carp_attach_p != NULL)
877 error = (*carp_attach_p)(&ia->ia_ifa, vhid);
879 error = EPROTONOSUPPORT;
885 * Give the interface a chance to initialize
886 * if this is its first address,
887 * and to validate the address if necessary.
889 if (ifp->if_ioctl != NULL &&
890 (error = (*ifp->if_ioctl)(ifp, SIOCSIFADDR, (caddr_t)ia)) != 0)
891 /* LIST_REMOVE(ia, ia_hash) is done in in_control */
895 * Be compatible with network classes, if netmask isn't supplied,
896 * guess it based on classes.
900 ia->ia_subnetmask = IN_CLASSA_NET;
901 else if (IN_CLASSB(i))
902 ia->ia_subnetmask = IN_CLASSB_NET;
904 ia->ia_subnetmask = IN_CLASSC_NET;
905 ia->ia_sockmask.sin_addr.s_addr = htonl(ia->ia_subnetmask);
907 ia->ia_subnet = i & ia->ia_subnetmask;
908 in_socktrim(&ia->ia_sockmask);
910 * Add route for the network.
912 ia->ia_ifa.ifa_metric = ifp->if_metric;
913 if (ifp->if_flags & IFF_BROADCAST) {
914 if (ia->ia_subnetmask == IN_RFC3021_MASK)
915 ia->ia_broadaddr.sin_addr.s_addr = INADDR_BROADCAST;
917 ia->ia_broadaddr.sin_addr.s_addr =
918 htonl(ia->ia_subnet | ~ia->ia_subnetmask);
919 } else if (ifp->if_flags & IFF_LOOPBACK) {
920 ia->ia_dstaddr = ia->ia_addr;
922 } else if (ifp->if_flags & IFF_POINTOPOINT) {
923 if (ia->ia_dstaddr.sin_family != AF_INET)
927 if (!vhid && (error = in_addprefix(ia, flags)) != 0)
930 if (ia->ia_addr.sin_addr.s_addr == INADDR_ANY)
933 if (ifp->if_flags & IFF_POINTOPOINT &&
934 ia->ia_dstaddr.sin_addr.s_addr == ia->ia_addr.sin_addr.s_addr)
938 * add a loopback route to self
940 if (V_useloopback && !vhid && !(ifp->if_flags & IFF_LOOPBACK)) {
943 bzero(&ia_ro, sizeof(ia_ro));
944 *((struct sockaddr_in *)(&ia_ro.ro_dst)) = ia->ia_addr;
945 rtalloc_ign_fib(&ia_ro, 0, 0);
946 if ((ia_ro.ro_rt != NULL) && (ia_ro.ro_rt->rt_ifp != NULL) &&
947 (ia_ro.ro_rt->rt_ifp == V_loif)) {
948 RT_LOCK(ia_ro.ro_rt);
949 RT_ADDREF(ia_ro.ro_rt);
950 RTFREE_LOCKED(ia_ro.ro_rt);
952 error = ifa_add_loopback_route((struct ifaddr *)ia,
953 (struct sockaddr *)&ia->ia_addr);
955 ia->ia_flags |= IFA_RTSELF;
956 if (ia_ro.ro_rt != NULL)
963 #define rtinitflags(x) \
964 ((((x)->ia_ifp->if_flags & (IFF_LOOPBACK | IFF_POINTOPOINT)) != 0) \
968 * Generate a routing message when inserting or deleting
969 * an interface address alias.
971 static void in_addralias_rtmsg(int cmd, struct in_addr *prefix,
972 struct in_ifaddr *target)
975 struct sockaddr_in *pfx_addr;
976 struct rtentry msg_rt;
979 * This is a bit questionable because there is no
980 * additional route entry added/deleted for an address
981 * alias. Therefore this route report is inaccurate.
983 bzero(&pfx_ro, sizeof(pfx_ro));
984 pfx_addr = (struct sockaddr_in *)(&pfx_ro.ro_dst);
985 pfx_addr->sin_len = sizeof(*pfx_addr);
986 pfx_addr->sin_family = AF_INET;
987 pfx_addr->sin_addr = *prefix;
988 rtalloc_ign_fib(&pfx_ro, 0, 0);
989 if (pfx_ro.ro_rt != NULL) {
990 msg_rt = *pfx_ro.ro_rt;
993 * Point the gateway to the new interface
994 * address as if a new prefix route entry has
995 * been added through the new address alias.
996 * All other parts of the rtentry is accurate,
997 * e.g., rt_key, rt_mask, rt_ifp etc.
1000 (struct sockaddr *)&target->ia_addr;
1002 (struct ifaddr *)target,
1004 RTFREE(pfx_ro.ro_rt);
1010 * Check if we have a route for the given prefix already or add one accordingly.
1013 in_addprefix(struct in_ifaddr *target, int flags)
1015 struct in_ifaddr *ia;
1016 struct in_addr prefix, mask, p, m;
1019 if ((flags & RTF_HOST) != 0) {
1020 prefix = target->ia_dstaddr.sin_addr;
1023 prefix = target->ia_addr.sin_addr;
1024 mask = target->ia_sockmask.sin_addr;
1025 prefix.s_addr &= mask.s_addr;
1029 TAILQ_FOREACH(ia, &V_in_ifaddrhead, ia_link) {
1030 if (rtinitflags(ia)) {
1031 p = ia->ia_dstaddr.sin_addr;
1033 if (prefix.s_addr != p.s_addr)
1036 p = ia->ia_addr.sin_addr;
1037 m = ia->ia_sockmask.sin_addr;
1038 p.s_addr &= m.s_addr;
1040 if (prefix.s_addr != p.s_addr ||
1041 mask.s_addr != m.s_addr)
1046 * If we got a matching prefix route inserted by other
1047 * interface address, we are done here.
1049 if (ia->ia_flags & IFA_ROUTE) {
1051 if (ia->ia_addr.sin_addr.s_addr ==
1052 target->ia_addr.sin_addr.s_addr) {
1053 IN_IFADDR_RUNLOCK();
1058 if (V_nosameprefix) {
1059 IN_IFADDR_RUNLOCK();
1062 in_addralias_rtmsg(RTM_ADD, &prefix, target);
1063 IN_IFADDR_RUNLOCK();
1068 IN_IFADDR_RUNLOCK();
1071 * No-one seem to have this prefix route, so we try to insert it.
1073 error = rtinit(&target->ia_ifa, (int)RTM_ADD, flags);
1075 target->ia_flags |= IFA_ROUTE;
1080 * If there is no other address in the system that can serve a route to the
1081 * same prefix, remove the route. Hand over the route to the new address
1085 in_scrubprefix(struct in_ifaddr *target, u_int flags)
1087 struct in_ifaddr *ia;
1088 struct in_addr prefix, mask, p, m;
1090 struct sockaddr_in prefix0, mask0;
1093 * Remove the loopback route to the interface address.
1094 * The "useloopback" setting is not consulted because if the
1095 * user configures an interface address, turns off this
1096 * setting, and then tries to delete that interface address,
1097 * checking the current setting of "useloopback" would leave
1098 * that interface address loopback route untouched, which
1099 * would be wrong. Therefore the interface address loopback route
1100 * deletion is unconditional.
1102 if ((target->ia_addr.sin_addr.s_addr != INADDR_ANY) &&
1103 !(target->ia_ifp->if_flags & IFF_LOOPBACK) &&
1104 (target->ia_flags & IFA_RTSELF)) {
1108 bzero(&ia_ro, sizeof(ia_ro));
1109 *((struct sockaddr_in *)(&ia_ro.ro_dst)) = target->ia_addr;
1110 rtalloc_ign_fib(&ia_ro, 0, 0);
1111 if ((ia_ro.ro_rt != NULL) && (ia_ro.ro_rt->rt_ifp != NULL) &&
1112 (ia_ro.ro_rt->rt_ifp == V_loif)) {
1113 RT_LOCK(ia_ro.ro_rt);
1114 if (ia_ro.ro_rt->rt_refcnt <= 1)
1116 else if (flags & LLE_STATIC) {
1117 RT_REMREF(ia_ro.ro_rt);
1118 target->ia_flags &= ~IFA_RTSELF;
1120 RTFREE_LOCKED(ia_ro.ro_rt);
1122 if (freeit && (flags & LLE_STATIC)) {
1123 error = ifa_del_loopback_route((struct ifaddr *)target,
1124 (struct sockaddr *)&target->ia_addr);
1126 target->ia_flags &= ~IFA_RTSELF;
1128 if ((flags & LLE_STATIC) &&
1129 !(target->ia_ifp->if_flags & IFF_NOARP))
1130 /* remove arp cache */
1131 arp_ifscrub(target->ia_ifp, IA_SIN(target)->sin_addr.s_addr);
1134 if (rtinitflags(target)) {
1135 prefix = target->ia_dstaddr.sin_addr;
1138 prefix = target->ia_addr.sin_addr;
1139 mask = target->ia_sockmask.sin_addr;
1140 prefix.s_addr &= mask.s_addr;
1143 if ((target->ia_flags & IFA_ROUTE) == 0) {
1144 in_addralias_rtmsg(RTM_DELETE, &prefix, target);
1149 TAILQ_FOREACH(ia, &V_in_ifaddrhead, ia_link) {
1150 if (rtinitflags(ia)) {
1151 p = ia->ia_dstaddr.sin_addr;
1153 if (prefix.s_addr != p.s_addr)
1156 p = ia->ia_addr.sin_addr;
1157 m = ia->ia_sockmask.sin_addr;
1158 p.s_addr &= m.s_addr;
1160 if (prefix.s_addr != p.s_addr ||
1161 mask.s_addr != m.s_addr)
1165 if ((ia->ia_ifp->if_flags & IFF_UP) == 0)
1169 * If we got a matching prefix address, move IFA_ROUTE and
1170 * the route itself to it. Make sure that routing daemons
1173 if ((ia->ia_flags & IFA_ROUTE) == 0) {
1174 ifa_ref(&ia->ia_ifa);
1175 IN_IFADDR_RUNLOCK();
1176 error = rtinit(&(target->ia_ifa), (int)RTM_DELETE,
1177 rtinitflags(target));
1179 target->ia_flags &= ~IFA_ROUTE;
1181 log(LOG_INFO, "in_scrubprefix: err=%d, old prefix delete failed\n",
1183 error = rtinit(&ia->ia_ifa, (int)RTM_ADD,
1184 rtinitflags(ia) | RTF_UP);
1186 ia->ia_flags |= IFA_ROUTE;
1188 log(LOG_INFO, "in_scrubprefix: err=%d, new prefix add failed\n",
1190 ifa_free(&ia->ia_ifa);
1194 IN_IFADDR_RUNLOCK();
1197 * remove all L2 entries on the given prefix
1199 bzero(&prefix0, sizeof(prefix0));
1200 prefix0.sin_len = sizeof(prefix0);
1201 prefix0.sin_family = AF_INET;
1202 prefix0.sin_addr.s_addr = target->ia_subnet;
1203 bzero(&mask0, sizeof(mask0));
1204 mask0.sin_len = sizeof(mask0);
1205 mask0.sin_family = AF_INET;
1206 mask0.sin_addr.s_addr = target->ia_subnetmask;
1207 lltable_prefix_free(AF_INET, (struct sockaddr *)&prefix0,
1208 (struct sockaddr *)&mask0, flags);
1211 * As no-one seem to have this prefix, we can remove the route.
1213 error = rtinit(&(target->ia_ifa), (int)RTM_DELETE, rtinitflags(target));
1215 target->ia_flags &= ~IFA_ROUTE;
1217 log(LOG_INFO, "in_scrubprefix: err=%d, prefix delete failed\n", error);
1224 * Return 1 if the address might be a local broadcast address.
1227 in_broadcast(struct in_addr in, struct ifnet *ifp)
1229 register struct ifaddr *ifa;
1232 if (in.s_addr == INADDR_BROADCAST ||
1233 in.s_addr == INADDR_ANY)
1235 if ((ifp->if_flags & IFF_BROADCAST) == 0)
1237 t = ntohl(in.s_addr);
1239 * Look through the list of addresses for a match
1240 * with a broadcast address.
1242 #define ia ((struct in_ifaddr *)ifa)
1243 TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link)
1244 if (ifa->ifa_addr->sa_family == AF_INET &&
1245 (in.s_addr == ia->ia_broadaddr.sin_addr.s_addr ||
1247 * Check for old-style (host 0) broadcast, but
1248 * taking into account that RFC 3021 obsoletes it.
1250 (ia->ia_subnetmask != IN_RFC3021_MASK &&
1251 t == ia->ia_subnet)) &&
1253 * Check for an all one subnetmask. These
1254 * only exist when an interface gets a secondary
1257 ia->ia_subnetmask != (u_long)0xffffffff)
1264 * On interface removal, clean up IPv4 data structures hung off of the ifnet.
1267 in_ifdetach(struct ifnet *ifp)
1270 in_pcbpurgeif0(&V_ripcbinfo, ifp);
1271 in_pcbpurgeif0(&V_udbinfo, ifp);
1272 in_purgemaddrs(ifp);
1276 * Delete all IPv4 multicast address records, and associated link-layer
1277 * multicast address records, associated with ifp.
1278 * XXX It looks like domifdetach runs AFTER the link layer cleanup.
1279 * XXX This should not race with ifma_protospec being set during
1280 * a new allocation, if it does, we have bigger problems.
1283 in_purgemaddrs(struct ifnet *ifp)
1285 LIST_HEAD(,in_multi) purgeinms;
1286 struct in_multi *inm, *tinm;
1287 struct ifmultiaddr *ifma;
1289 LIST_INIT(&purgeinms);
1293 * Extract list of in_multi associated with the detaching ifp
1294 * which the PF_INET layer is about to release.
1295 * We need to do this as IF_ADDR_LOCK() may be re-acquired
1296 * by code further down.
1299 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
1300 if (ifma->ifma_addr->sa_family != AF_INET ||
1301 ifma->ifma_protospec == NULL)
1304 KASSERT(ifma->ifma_protospec != NULL,
1305 ("%s: ifma_protospec is NULL", __func__));
1307 inm = (struct in_multi *)ifma->ifma_protospec;
1308 LIST_INSERT_HEAD(&purgeinms, inm, inm_link);
1310 IF_ADDR_UNLOCK(ifp);
1312 LIST_FOREACH_SAFE(inm, &purgeinms, inm_link, tinm) {
1313 LIST_REMOVE(inm, inm_link);
1314 inm_release_locked(inm);
1322 struct llentry base;
1323 struct sockaddr_in l3_addr4;
1326 static struct llentry *
1327 in_lltable_new(const struct sockaddr *l3addr, u_int flags)
1329 struct in_llentry *lle;
1331 lle = malloc(sizeof(struct in_llentry), M_LLTABLE, M_DONTWAIT | M_ZERO);
1332 if (lle == NULL) /* NB: caller generates msg */
1335 callout_init(&lle->base.la_timer, CALLOUT_MPSAFE);
1337 * For IPv4 this will trigger "arpresolve" to generate
1340 lle->base.la_expire = time_uptime; /* mark expired */
1341 lle->l3_addr4 = *(const struct sockaddr_in *)l3addr;
1342 lle->base.lle_refcnt = 1;
1343 LLE_LOCK_INIT(&lle->base);
1348 * Deletes an address from the address table.
1349 * This function is called by the timer functions
1350 * such as arptimer() and nd6_llinfo_timer(), and
1351 * the caller does the locking.
1354 in_lltable_free(struct lltable *llt, struct llentry *lle)
1357 LLE_LOCK_DESTROY(lle);
1358 free(lle, M_LLTABLE);
1362 #define IN_ARE_MASKED_ADDR_EQUAL(d, a, m) ( \
1363 (((ntohl((d)->sin_addr.s_addr) ^ (a)->sin_addr.s_addr) & (m)->sin_addr.s_addr)) == 0 )
1366 in_lltable_prefix_free(struct lltable *llt,
1367 const struct sockaddr *prefix,
1368 const struct sockaddr *mask,
1371 const struct sockaddr_in *pfx = (const struct sockaddr_in *)prefix;
1372 const struct sockaddr_in *msk = (const struct sockaddr_in *)mask;
1373 struct llentry *lle, *next;
1375 size_t pkts_dropped;
1377 for (i=0; i < LLTBL_HASHTBL_SIZE; i++) {
1378 LIST_FOREACH_SAFE(lle, &llt->lle_head[i], lle_next, next) {
1381 * (flags & LLE_STATIC) means deleting all entries
1382 * including static ARP entries
1384 if (IN_ARE_MASKED_ADDR_EQUAL((struct sockaddr_in *)L3_ADDR(lle),
1386 ((flags & LLE_STATIC) || !(lle->la_flags & LLE_STATIC))) {
1389 canceled = callout_drain(&lle->la_timer);
1393 pkts_dropped = llentry_free(lle);
1394 ARPSTAT_ADD(dropped, pkts_dropped);
1402 in_lltable_rtcheck(struct ifnet *ifp, u_int flags, const struct sockaddr *l3addr)
1406 KASSERT(l3addr->sa_family == AF_INET,
1407 ("sin_family %d", l3addr->sa_family));
1409 /* XXX rtalloc1 should take a const param */
1410 rt = rtalloc1(__DECONST(struct sockaddr *, l3addr), 0, 0);
1416 * If the gateway for an existing host route matches the target L3
1417 * address, which is a special route inserted by some implementation
1418 * such as MANET, and the interface is of the correct type, then
1419 * allow for ARP to proceed.
1421 if (rt->rt_flags & RTF_GATEWAY) {
1422 if (!(rt->rt_flags & RTF_HOST) || !rt->rt_ifp ||
1423 rt->rt_ifp->if_type != IFT_ETHER ||
1424 (rt->rt_ifp->if_flags &
1425 (IFF_NOARP | IFF_STATICARP)) != 0 ||
1426 memcmp(rt->rt_gateway->sa_data, l3addr->sa_data,
1427 sizeof(in_addr_t)) != 0) {
1434 * Make sure that at least the destination address is covered
1435 * by the route. This is for handling the case where 2 or more
1436 * interfaces have the same prefix. An incoming packet arrives
1437 * on one interface and the corresponding outgoing packet leaves
1438 * another interface.
1440 if (!(rt->rt_flags & RTF_HOST) && rt->rt_ifp != ifp) {
1441 const char *sa, *mask, *addr, *lim;
1444 mask = (const char *)rt_mask(rt);
1446 * Just being extra cautious to avoid some custom
1447 * code getting into trouble.
1454 sa = (const char *)rt_key(rt);
1455 addr = (const char *)l3addr;
1456 len = ((const struct sockaddr_in *)l3addr)->sin_len;
1459 for ( ; addr < lim; sa++, mask++, addr++) {
1460 if ((*sa ^ *addr) & *mask) {
1462 log(LOG_INFO, "IPv4 address: \"%s\" is not on the network\n",
1463 inet_ntoa(((const struct sockaddr_in *)l3addr)->sin_addr));
1476 * Return NULL if not found or marked for deletion.
1477 * If found return lle read locked.
1479 static struct llentry *
1480 in_lltable_lookup(struct lltable *llt, u_int flags, const struct sockaddr *l3addr)
1482 const struct sockaddr_in *sin = (const struct sockaddr_in *)l3addr;
1483 struct ifnet *ifp = llt->llt_ifp;
1484 struct llentry *lle;
1485 struct llentries *lleh;
1488 IF_AFDATA_LOCK_ASSERT(ifp);
1489 KASSERT(l3addr->sa_family == AF_INET,
1490 ("sin_family %d", l3addr->sa_family));
1492 hashkey = sin->sin_addr.s_addr;
1493 lleh = &llt->lle_head[LLATBL_HASH(hashkey, LLTBL_HASHMASK)];
1494 LIST_FOREACH(lle, lleh, lle_next) {
1495 struct sockaddr_in *sa2 = (struct sockaddr_in *)L3_ADDR(lle);
1496 if (lle->la_flags & LLE_DELETED)
1498 if (sa2->sin_addr.s_addr == sin->sin_addr.s_addr)
1503 if (flags & LLE_DELETE)
1504 log(LOG_INFO, "interface address is missing from cache = %p in delete\n", lle);
1506 if (!(flags & LLE_CREATE))
1509 * A route that covers the given address must have
1510 * been installed 1st because we are doing a resolution,
1513 if (!(flags & LLE_IFADDR) &&
1514 in_lltable_rtcheck(ifp, flags, l3addr) != 0)
1517 lle = in_lltable_new(l3addr, flags);
1519 log(LOG_INFO, "lla_lookup: new lle malloc failed\n");
1522 lle->la_flags = flags & ~LLE_CREATE;
1523 if ((flags & (LLE_CREATE | LLE_IFADDR)) == (LLE_CREATE | LLE_IFADDR)) {
1524 bcopy(IF_LLADDR(ifp), &lle->ll_addr, ifp->if_addrlen);
1525 lle->la_flags |= (LLE_VALID | LLE_STATIC);
1529 lle->lle_head = lleh;
1530 LIST_INSERT_HEAD(lleh, lle, lle_next);
1531 } else if (flags & LLE_DELETE) {
1532 if (!(lle->la_flags & LLE_IFADDR) || (flags & LLE_IFADDR)) {
1534 lle->la_flags = LLE_DELETED;
1535 EVENTHANDLER_INVOKE(arp_update_event, lle);
1538 log(LOG_INFO, "ifaddr cache = %p is deleted\n", lle);
1544 if (LLE_IS_VALID(lle)) {
1545 if (flags & LLE_EXCLUSIVE)
1555 in_lltable_dump(struct lltable *llt, struct sysctl_req *wr)
1557 #define SIN(lle) ((struct sockaddr_in *) L3_ADDR(lle))
1558 struct ifnet *ifp = llt->llt_ifp;
1559 struct llentry *lle;
1562 struct rt_msghdr rtm;
1563 struct sockaddr_inarp sin;
1564 struct sockaddr_dl sdl;
1568 LLTABLE_LOCK_ASSERT();
1571 for (i = 0; i < LLTBL_HASHTBL_SIZE; i++) {
1572 LIST_FOREACH(lle, &llt->lle_head[i], lle_next) {
1573 struct sockaddr_dl *sdl;
1575 /* skip deleted entries */
1576 if ((lle->la_flags & LLE_DELETED) == LLE_DELETED)
1578 /* Skip if jailed and not a valid IP of the prison. */
1579 if (prison_if(wr->td->td_ucred, L3_ADDR(lle)) != 0)
1582 * produce a msg made of:
1584 * struct sockaddr_inarp; (IPv4)
1585 * struct sockaddr_dl;
1587 bzero(&arpc, sizeof(arpc));
1588 arpc.rtm.rtm_msglen = sizeof(arpc);
1589 arpc.rtm.rtm_version = RTM_VERSION;
1590 arpc.rtm.rtm_type = RTM_GET;
1591 arpc.rtm.rtm_flags = RTF_UP;
1592 arpc.rtm.rtm_addrs = RTA_DST | RTA_GATEWAY;
1593 arpc.sin.sin_family = AF_INET;
1594 arpc.sin.sin_len = sizeof(arpc.sin);
1595 arpc.sin.sin_addr.s_addr = SIN(lle)->sin_addr.s_addr;
1598 if (lle->la_flags & LLE_PUB) {
1599 arpc.rtm.rtm_flags |= RTF_ANNOUNCE;
1601 if (lle->la_flags & LLE_PROXY)
1602 arpc.sin.sin_other = SIN_PROXY;
1606 sdl->sdl_family = AF_LINK;
1607 sdl->sdl_len = sizeof(*sdl);
1608 sdl->sdl_index = ifp->if_index;
1609 sdl->sdl_type = ifp->if_type;
1610 if ((lle->la_flags & LLE_VALID) == LLE_VALID) {
1611 sdl->sdl_alen = ifp->if_addrlen;
1612 bcopy(&lle->ll_addr, LLADDR(sdl), ifp->if_addrlen);
1615 bzero(LLADDR(sdl), ifp->if_addrlen);
1618 arpc.rtm.rtm_rmx.rmx_expire =
1619 lle->la_flags & LLE_STATIC ? 0 : lle->la_expire;
1620 arpc.rtm.rtm_flags |= (RTF_HOST | RTF_LLDATA);
1621 if (lle->la_flags & LLE_STATIC)
1622 arpc.rtm.rtm_flags |= RTF_STATIC;
1623 arpc.rtm.rtm_index = ifp->if_index;
1624 error = SYSCTL_OUT(wr, &arpc, sizeof(arpc));
1634 in_domifattach(struct ifnet *ifp)
1636 struct in_ifinfo *ii;
1637 struct lltable *llt;
1639 ii = malloc(sizeof(struct in_ifinfo), M_IFADDR, M_WAITOK|M_ZERO);
1641 llt = lltable_init(ifp, AF_INET);
1643 llt->llt_free = in_lltable_free;
1644 llt->llt_prefix_free = in_lltable_prefix_free;
1645 llt->llt_lookup = in_lltable_lookup;
1646 llt->llt_dump = in_lltable_dump;
1650 ii->ii_igmp = igmp_domifattach(ifp);
1656 in_domifdetach(struct ifnet *ifp, void *aux)
1658 struct in_ifinfo *ii = (struct in_ifinfo *)aux;
1660 igmp_domifdetach(ifp);
1661 lltable_free(ii->ii_llt);