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/in.h>
60 #include <netinet/in_var.h>
61 #include <netinet/in_pcb.h>
62 #include <netinet/ip_var.h>
63 #include <netinet/igmp_var.h>
64 #include <netinet/udp.h>
65 #include <netinet/udp_var.h>
67 static int in_mask2len(struct in_addr *);
68 static void in_len2mask(struct in_addr *, int);
69 static int in_lifaddr_ioctl(struct socket *, u_long, caddr_t,
70 struct ifnet *, struct thread *);
72 static int in_addprefix(struct in_ifaddr *, int);
73 static int in_scrubprefix(struct in_ifaddr *, u_int);
74 static void in_socktrim(struct sockaddr_in *);
75 static int in_ifinit(struct ifnet *,
76 struct in_ifaddr *, struct sockaddr_in *, int);
77 static void in_purgemaddrs(struct ifnet *);
79 static VNET_DEFINE(int, subnetsarelocal);
80 #define V_subnetsarelocal VNET(subnetsarelocal)
81 SYSCTL_VNET_INT(_net_inet_ip, OID_AUTO, subnets_are_local, CTLFLAG_RW,
82 &VNET_NAME(subnetsarelocal), 0,
83 "Treat all subnets as directly connected");
84 static VNET_DEFINE(int, sameprefixcarponly);
85 #define V_sameprefixcarponly VNET(sameprefixcarponly)
86 SYSCTL_VNET_INT(_net_inet_ip, OID_AUTO, same_prefix_carp_only, CTLFLAG_RW,
87 &VNET_NAME(sameprefixcarponly), 0,
88 "Refuse to create same prefixes on different interfaces");
90 VNET_DECLARE(struct inpcbinfo, ripcbinfo);
91 #define V_ripcbinfo VNET(ripcbinfo)
93 VNET_DECLARE(struct arpstat, arpstat); /* ARP statistics, see if_arp.h */
94 #define V_arpstat VNET(arpstat)
97 * Return 1 if an internet address is for a ``local'' host
98 * (one to which we have a connection). If subnetsarelocal
99 * is true, this includes other subnets of the local net.
100 * Otherwise, it includes only the directly-connected (sub)nets.
103 in_localaddr(struct in_addr in)
105 register u_long i = ntohl(in.s_addr);
106 register struct in_ifaddr *ia;
109 if (V_subnetsarelocal) {
110 TAILQ_FOREACH(ia, &V_in_ifaddrhead, ia_link) {
111 if ((i & ia->ia_netmask) == ia->ia_net) {
117 TAILQ_FOREACH(ia, &V_in_ifaddrhead, ia_link) {
118 if ((i & ia->ia_subnetmask) == ia->ia_subnet) {
129 * Return 1 if an internet address is for the local host and configured
130 * on one of its interfaces.
133 in_localip(struct in_addr in)
135 struct in_ifaddr *ia;
138 LIST_FOREACH(ia, INADDR_HASH(in.s_addr), ia_hash) {
139 if (IA_SIN(ia)->sin_addr.s_addr == in.s_addr) {
149 * Determine whether an IP address is in a reserved set of addresses
150 * that may not be forwarded, or whether datagrams to that destination
154 in_canforward(struct in_addr in)
156 register u_long i = ntohl(in.s_addr);
159 if (IN_EXPERIMENTAL(i) || IN_MULTICAST(i) || IN_LINKLOCAL(i))
162 net = i & IN_CLASSA_NET;
163 if (net == 0 || net == (IN_LOOPBACKNET << IN_CLASSA_NSHIFT))
170 * Trim a mask in a sockaddr
173 in_socktrim(struct sockaddr_in *ap)
175 register char *cplim = (char *) &ap->sin_addr;
176 register char *cp = (char *) (&ap->sin_addr + 1);
179 while (--cp >= cplim)
181 (ap)->sin_len = cp - (char *) (ap) + 1;
188 struct in_addr *mask;
194 for (x = 0; x < sizeof(*mask); x++) {
199 if (x < sizeof(*mask)) {
200 for (y = 0; y < 8; y++) {
201 if ((p[x] & (0x80 >> y)) == 0)
209 in_len2mask(struct in_addr *mask, int len)
215 bzero(mask, sizeof(*mask));
216 for (i = 0; i < len / 8; i++)
219 p[i] = (0xff00 >> (len % 8)) & 0xff;
223 * Generic internet control operations (ioctl's).
225 * ifp is NULL if not an interface-specific ioctl.
229 in_control(struct socket *so, u_long cmd, caddr_t data, struct ifnet *ifp,
232 register struct ifreq *ifr = (struct ifreq *)data;
233 register struct in_ifaddr *ia, *iap;
234 register struct ifaddr *ifa;
235 struct in_addr allhosts_addr;
237 struct in_ifinfo *ii;
238 struct in_aliasreq *ifra = (struct in_aliasreq *)data;
239 struct sockaddr_in oldaddr;
240 int error, hostIsNew, iaIsNew, maskIsNew;
246 allhosts_addr.s_addr = htonl(INADDR_ALLHOSTS_GROUP);
249 * Filter out ioctls we implement directly; forward the rest on to
250 * in_lifaddr_ioctl() and ifp->if_ioctl().
267 error = priv_check(td, PRIV_NET_ADDIFADDR);
273 return in_lifaddr_ioctl(so, cmd, data, ifp, td);
277 error = priv_check(td, PRIV_NET_DELIFADDR);
283 return in_lifaddr_ioctl(so, cmd, data, ifp, td);
288 return in_lifaddr_ioctl(so, cmd, data, ifp, td);
291 if (ifp == NULL || ifp->if_ioctl == NULL)
293 return ((*ifp->if_ioctl)(ifp, cmd, data));
297 return (EADDRNOTAVAIL);
300 * Security checks before we get involved in any work.
309 error = priv_check(td, PRIV_NET_ADDIFADDR);
317 error = priv_check(td, PRIV_NET_DELIFADDR);
325 * Find address for this interface, if it exists.
327 * If an alias address was specified, find that one instead of the
328 * first one on the interface, if possible.
330 dst = ((struct sockaddr_in *)&ifr->ifr_addr)->sin_addr;
332 LIST_FOREACH(iap, INADDR_HASH(dst.s_addr), ia_hash) {
333 if (iap->ia_ifp == ifp &&
334 iap->ia_addr.sin_addr.s_addr == dst.s_addr) {
335 if (td == NULL || prison_check_ip4(td->td_ucred,
342 ifa_ref(&ia->ia_ifa);
346 TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
348 if (iap->ia_addr.sin_family == AF_INET) {
350 prison_check_ip4(td->td_ucred,
351 &iap->ia_addr.sin_addr) != 0)
358 ifa_ref(&ia->ia_ifa);
359 IF_ADDR_RUNLOCK(ifp);
368 if (ifra->ifra_addr.sin_family == AF_INET) {
369 struct in_ifaddr *oia;
372 for (oia = ia; ia; ia = TAILQ_NEXT(ia, ia_link)) {
373 if (ia->ia_ifp == ifp &&
374 ia->ia_addr.sin_addr.s_addr ==
375 ifra->ifra_addr.sin_addr.s_addr)
378 if (ia != NULL && ia != oia)
379 ifa_ref(&ia->ia_ifa);
380 if (oia != NULL && ia != oia)
381 ifa_free(&oia->ia_ifa);
383 if ((ifp->if_flags & IFF_POINTOPOINT)
384 && (cmd == SIOCAIFADDR)
385 && (ifra->ifra_dstaddr.sin_addr.s_addr
387 error = EDESTADDRREQ;
391 if (cmd == SIOCDIFADDR && ia == NULL) {
392 error = EADDRNOTAVAIL;
400 ia = (struct in_ifaddr *)
401 malloc(sizeof *ia, M_IFADDR, M_NOWAIT |
410 ifa->ifa_addr = (struct sockaddr *)&ia->ia_addr;
411 ifa->ifa_dstaddr = (struct sockaddr *)&ia->ia_dstaddr;
412 ifa->ifa_netmask = (struct sockaddr *)&ia->ia_sockmask;
414 ia->ia_sockmask.sin_len = 8;
415 ia->ia_sockmask.sin_family = AF_INET;
416 if (ifp->if_flags & IFF_BROADCAST) {
417 ia->ia_broadaddr.sin_len = sizeof(ia->ia_addr);
418 ia->ia_broadaddr.sin_family = AF_INET;
422 ifa_ref(ifa); /* if_addrhead */
424 TAILQ_INSERT_TAIL(&ifp->if_addrhead, ifa, ifa_link);
425 IF_ADDR_WUNLOCK(ifp);
426 ifa_ref(ifa); /* in_ifaddrhead */
428 TAILQ_INSERT_TAIL(&V_in_ifaddrhead, ia, ia_link);
440 error = EADDRNOTAVAIL;
447 * Most paths in this switch return directly or via out. Only paths
448 * that remove the address break in order to hit common removal code.
452 *((struct sockaddr_in *)&ifr->ifr_addr) = ia->ia_addr;
456 if ((ifp->if_flags & IFF_BROADCAST) == 0) {
460 *((struct sockaddr_in *)&ifr->ifr_dstaddr) = ia->ia_broadaddr;
464 if ((ifp->if_flags & IFF_POINTOPOINT) == 0) {
468 *((struct sockaddr_in *)&ifr->ifr_dstaddr) = ia->ia_dstaddr;
472 *((struct sockaddr_in *)&ifr->ifr_addr) = ia->ia_sockmask;
476 if ((ifp->if_flags & IFF_POINTOPOINT) == 0) {
480 oldaddr = ia->ia_dstaddr;
481 ia->ia_dstaddr = *(struct sockaddr_in *)&ifr->ifr_dstaddr;
482 if (ifp->if_ioctl != NULL) {
483 error = (*ifp->if_ioctl)(ifp, SIOCSIFDSTADDR,
486 ia->ia_dstaddr = oldaddr;
490 if (ia->ia_flags & IFA_ROUTE) {
491 ia->ia_ifa.ifa_dstaddr = (struct sockaddr *)&oldaddr;
492 rtinit(&(ia->ia_ifa), (int)RTM_DELETE, RTF_HOST);
493 ia->ia_ifa.ifa_dstaddr =
494 (struct sockaddr *)&ia->ia_dstaddr;
495 rtinit(&(ia->ia_ifa), (int)RTM_ADD, RTF_HOST|RTF_UP);
500 if ((ifp->if_flags & IFF_BROADCAST) == 0) {
504 ia->ia_broadaddr = *(struct sockaddr_in *)&ifr->ifr_broadaddr;
508 error = in_ifinit(ifp, ia,
509 (struct sockaddr_in *) &ifr->ifr_addr, 1);
510 if (error != 0 && iaIsNew)
513 ii = ((struct in_ifinfo *)ifp->if_afdata[AF_INET]);
515 (ifp->if_flags & IFF_MULTICAST) != 0) {
516 error = in_joingroup(ifp, &allhosts_addr,
517 NULL, &ii->ii_allhosts);
519 EVENTHANDLER_INVOKE(ifaddr_event, ifp);
525 ia->ia_sockmask.sin_addr = ifra->ifra_addr.sin_addr;
526 ia->ia_subnetmask = ntohl(ia->ia_sockmask.sin_addr.s_addr);
533 if (ia->ia_addr.sin_family == AF_INET) {
534 if (ifra->ifra_addr.sin_len == 0) {
535 ifra->ifra_addr = ia->ia_addr;
537 } else if (ifra->ifra_addr.sin_addr.s_addr ==
538 ia->ia_addr.sin_addr.s_addr)
541 if (ifra->ifra_mask.sin_len) {
544 * Need to scrub the prefix here in case
545 * the issued command is SIOCAIFADDR with
546 * the same address, but with a different
547 * prefix length. And if the prefix length
548 * is the same as before, then the call is
549 * un-necessarily executed here.
551 in_ifscrub(ifp, ia, LLE_STATIC);
552 ia->ia_sockmask = ifra->ifra_mask;
553 ia->ia_sockmask.sin_family = AF_INET;
555 ntohl(ia->ia_sockmask.sin_addr.s_addr);
558 if ((ifp->if_flags & IFF_POINTOPOINT) &&
559 (ifra->ifra_dstaddr.sin_family == AF_INET)) {
560 in_ifscrub(ifp, ia, LLE_STATIC);
561 ia->ia_dstaddr = ifra->ifra_dstaddr;
562 maskIsNew = 1; /* We lie; but the effect's the same */
564 if (ifra->ifra_addr.sin_family == AF_INET &&
565 (hostIsNew || maskIsNew))
566 error = in_ifinit(ifp, ia, &ifra->ifra_addr, 0);
567 if (error != 0 && iaIsNew)
570 if ((ifp->if_flags & IFF_BROADCAST) &&
571 (ifra->ifra_broadaddr.sin_family == AF_INET))
572 ia->ia_broadaddr = ifra->ifra_broadaddr;
574 ii = ((struct in_ifinfo *)ifp->if_afdata[AF_INET]);
576 (ifp->if_flags & IFF_MULTICAST) != 0) {
577 error = in_joingroup(ifp, &allhosts_addr,
578 NULL, &ii->ii_allhosts);
580 EVENTHANDLER_INVOKE(ifaddr_event, ifp);
586 * in_ifscrub kills the interface route.
588 in_ifscrub(ifp, ia, LLE_STATIC);
591 * in_ifadown gets rid of all the rest of
592 * the routes. This is not quite the right
593 * thing to do, but at least if we are running
594 * a routing process they will come back.
596 in_ifadown(&ia->ia_ifa, 1);
597 EVENTHANDLER_INVOKE(ifaddr_event, ifp);
602 panic("in_control: unsupported ioctl");
606 /* Re-check that ia is still part of the list. */
607 TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
608 if (ifa == &ia->ia_ifa)
613 * If we lost the race with another thread, there is no need to
614 * try it again for the next loop as there is no other exit
615 * path between here and out.
617 IF_ADDR_WUNLOCK(ifp);
618 error = EADDRNOTAVAIL;
621 TAILQ_REMOVE(&ifp->if_addrhead, &ia->ia_ifa, ifa_link);
622 IF_ADDR_WUNLOCK(ifp);
623 ifa_free(&ia->ia_ifa); /* if_addrhead */
626 TAILQ_REMOVE(&V_in_ifaddrhead, ia, ia_link);
627 if (ia->ia_addr.sin_family == AF_INET) {
628 struct in_ifaddr *if_ia;
630 LIST_REMOVE(ia, ia_hash);
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.
638 IFP_TO_IA(ifp, if_ia);
640 ii = ((struct in_ifinfo *)ifp->if_afdata[AF_INET]);
642 if (ii->ii_allhosts) {
643 (void)in_leavegroup_locked(ii->ii_allhosts,
645 ii->ii_allhosts = NULL;
649 ifa_free(&if_ia->ia_ifa);
652 ifa_free(&ia->ia_ifa); /* in_ifaddrhead */
655 ifa_free(&ia->ia_ifa);
661 * SIOCGLIFADDR: get first address. (?!?)
662 * SIOCGLIFADDR with IFLR_PREFIX:
663 * get first address that matches the specified prefix.
664 * SIOCALIFADDR: add the specified address.
665 * SIOCALIFADDR with IFLR_PREFIX:
666 * EINVAL since we can't deduce hostid part of the address.
667 * SIOCDLIFADDR: delete the specified address.
668 * SIOCDLIFADDR with IFLR_PREFIX:
669 * delete the first address that matches the specified prefix.
671 * EINVAL on invalid parameters
672 * EADDRNOTAVAIL on prefix match failed/specified address not found
673 * other values may be returned from in_ioctl()
676 in_lifaddr_ioctl(struct socket *so, u_long cmd, caddr_t data,
677 struct ifnet *ifp, struct thread *td)
679 struct if_laddrreq *iflr = (struct if_laddrreq *)data;
683 if (data == NULL || ifp == NULL) {
684 panic("invalid argument to in_lifaddr_ioctl");
690 /* address must be specified on GET with IFLR_PREFIX */
691 if ((iflr->flags & IFLR_PREFIX) == 0)
696 /* address must be specified on ADD and DELETE */
697 if (iflr->addr.ss_family != AF_INET)
699 if (iflr->addr.ss_len != sizeof(struct sockaddr_in))
701 /* XXX need improvement */
702 if (iflr->dstaddr.ss_family
703 && iflr->dstaddr.ss_family != AF_INET)
705 if (iflr->dstaddr.ss_family
706 && iflr->dstaddr.ss_len != sizeof(struct sockaddr_in))
709 default: /*shouldn't happen*/
712 if (sizeof(struct in_addr) * 8 < iflr->prefixlen)
718 struct in_aliasreq ifra;
720 if (iflr->flags & IFLR_PREFIX)
723 /* copy args to in_aliasreq, perform ioctl(SIOCAIFADDR). */
724 bzero(&ifra, sizeof(ifra));
725 bcopy(iflr->iflr_name, ifra.ifra_name,
726 sizeof(ifra.ifra_name));
728 bcopy(&iflr->addr, &ifra.ifra_addr, iflr->addr.ss_len);
730 if (iflr->dstaddr.ss_family) { /*XXX*/
731 bcopy(&iflr->dstaddr, &ifra.ifra_dstaddr,
732 iflr->dstaddr.ss_len);
735 ifra.ifra_mask.sin_family = AF_INET;
736 ifra.ifra_mask.sin_len = sizeof(struct sockaddr_in);
737 in_len2mask(&ifra.ifra_mask.sin_addr, iflr->prefixlen);
739 return (in_control(so, SIOCAIFADDR, (caddr_t)&ifra, ifp, td));
744 struct in_ifaddr *ia;
745 struct in_addr mask, candidate, match;
746 struct sockaddr_in *sin;
748 bzero(&mask, sizeof(mask));
749 bzero(&match, sizeof(match));
750 if (iflr->flags & IFLR_PREFIX) {
751 /* lookup a prefix rather than address. */
752 in_len2mask(&mask, iflr->prefixlen);
754 sin = (struct sockaddr_in *)&iflr->addr;
755 match.s_addr = sin->sin_addr.s_addr;
756 match.s_addr &= mask.s_addr;
758 /* if you set extra bits, that's wrong */
759 if (match.s_addr != sin->sin_addr.s_addr)
763 /* on getting an address, take the 1st match */
764 /* on deleting an address, do exact match */
765 if (cmd != SIOCGLIFADDR) {
766 in_len2mask(&mask, 32);
767 sin = (struct sockaddr_in *)&iflr->addr;
768 match.s_addr = sin->sin_addr.s_addr;
773 TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
774 if (ifa->ifa_addr->sa_family != AF_INET)
776 if (match.s_addr == 0)
778 candidate.s_addr = ((struct sockaddr_in *)&ifa->ifa_addr)->sin_addr.s_addr;
779 candidate.s_addr &= mask.s_addr;
780 if (candidate.s_addr == match.s_addr)
785 IF_ADDR_RUNLOCK(ifp);
787 return (EADDRNOTAVAIL);
788 ia = (struct in_ifaddr *)ifa;
790 if (cmd == SIOCGLIFADDR) {
791 /* fill in the if_laddrreq structure */
792 bcopy(&ia->ia_addr, &iflr->addr, ia->ia_addr.sin_len);
794 if ((ifp->if_flags & IFF_POINTOPOINT) != 0) {
795 bcopy(&ia->ia_dstaddr, &iflr->dstaddr,
796 ia->ia_dstaddr.sin_len);
798 bzero(&iflr->dstaddr, sizeof(iflr->dstaddr));
801 in_mask2len(&ia->ia_sockmask.sin_addr);
803 iflr->flags = 0; /*XXX*/
808 struct in_aliasreq ifra;
810 /* fill in_aliasreq and do ioctl(SIOCDIFADDR) */
811 bzero(&ifra, sizeof(ifra));
812 bcopy(iflr->iflr_name, ifra.ifra_name,
813 sizeof(ifra.ifra_name));
815 bcopy(&ia->ia_addr, &ifra.ifra_addr,
816 ia->ia_addr.sin_len);
817 if ((ifp->if_flags & IFF_POINTOPOINT) != 0) {
818 bcopy(&ia->ia_dstaddr, &ifra.ifra_dstaddr,
819 ia->ia_dstaddr.sin_len);
821 bcopy(&ia->ia_sockmask, &ifra.ifra_dstaddr,
822 ia->ia_sockmask.sin_len);
825 return (in_control(so, SIOCDIFADDR, (caddr_t)&ifra,
831 return (EOPNOTSUPP); /*just for safety*/
835 * Delete any existing route for an interface.
838 in_ifscrub(struct ifnet *ifp, struct in_ifaddr *ia, u_int flags)
841 in_scrubprefix(ia, flags);
845 * Initialize an interface's internet address
846 * and routing table entry.
849 in_ifinit(struct ifnet *ifp, struct in_ifaddr *ia, struct sockaddr_in *sin,
852 register u_long i = ntohl(sin->sin_addr.s_addr);
853 struct sockaddr_in oldaddr;
854 int s = splimp(), flags = RTF_UP, error = 0;
856 oldaddr = ia->ia_addr;
857 if (oldaddr.sin_family == AF_INET)
858 LIST_REMOVE(ia, ia_hash);
860 if (ia->ia_addr.sin_family == AF_INET) {
862 LIST_INSERT_HEAD(INADDR_HASH(ia->ia_addr.sin_addr.s_addr),
867 * Give the interface a chance to initialize
868 * if this is its first address,
869 * and to validate the address if necessary.
871 if (ifp->if_ioctl != NULL) {
872 error = (*ifp->if_ioctl)(ifp, SIOCSIFADDR, (caddr_t)ia);
875 /* LIST_REMOVE(ia, ia_hash) is done in in_control */
876 ia->ia_addr = oldaddr;
878 if (ia->ia_addr.sin_family == AF_INET)
879 LIST_INSERT_HEAD(INADDR_HASH(
880 ia->ia_addr.sin_addr.s_addr), ia, ia_hash);
883 * If oldaddr family is not AF_INET (e.g.
884 * interface has been just created) in_control
885 * does not call LIST_REMOVE, and we end up
886 * with bogus ia entries in hash
888 LIST_REMOVE(ia, ia_hash);
895 ia->ia_ifa.ifa_addr = (struct sockaddr *)&oldaddr;
896 in_ifscrub(ifp, ia, LLE_STATIC);
897 ia->ia_ifa.ifa_addr = (struct sockaddr *)&ia->ia_addr;
900 ia->ia_netmask = IN_CLASSA_NET;
901 else if (IN_CLASSB(i))
902 ia->ia_netmask = IN_CLASSB_NET;
904 ia->ia_netmask = IN_CLASSC_NET;
906 * The subnet mask usually includes at least the standard network part,
907 * but may may be smaller in the case of supernetting.
908 * If it is set, we believe it.
910 if (ia->ia_subnetmask == 0) {
911 ia->ia_subnetmask = ia->ia_netmask;
912 ia->ia_sockmask.sin_addr.s_addr = htonl(ia->ia_subnetmask);
914 ia->ia_netmask &= ia->ia_subnetmask;
915 ia->ia_net = i & ia->ia_netmask;
916 ia->ia_subnet = i & ia->ia_subnetmask;
917 in_socktrim(&ia->ia_sockmask);
919 * XXX: carp(4) does not have interface route
921 if (ifp->if_type == IFT_CARP)
924 * Add route for the network.
926 ia->ia_ifa.ifa_metric = ifp->if_metric;
927 if (ifp->if_flags & IFF_BROADCAST) {
928 ia->ia_broadaddr.sin_addr.s_addr =
929 htonl(ia->ia_subnet | ~ia->ia_subnetmask);
930 ia->ia_netbroadcast.s_addr =
931 htonl(ia->ia_net | ~ ia->ia_netmask);
932 } else if (ifp->if_flags & IFF_LOOPBACK) {
933 ia->ia_dstaddr = ia->ia_addr;
935 } else if (ifp->if_flags & IFF_POINTOPOINT) {
936 if (ia->ia_dstaddr.sin_family != AF_INET)
940 if ((error = in_addprefix(ia, flags)) != 0)
943 if (ia->ia_addr.sin_addr.s_addr == INADDR_ANY)
946 if (ifp->if_flags & IFF_POINTOPOINT) {
947 if (ia->ia_dstaddr.sin_addr.s_addr == ia->ia_addr.sin_addr.s_addr)
953 * add a loopback route to self
955 if (V_useloopback && !(ifp->if_flags & IFF_LOOPBACK)) {
958 bzero(&ia_ro, sizeof(ia_ro));
959 *((struct sockaddr_in *)(&ia_ro.ro_dst)) = ia->ia_addr;
960 rtalloc_ign_fib(&ia_ro, 0, RT_DEFAULT_FIB);
961 if ((ia_ro.ro_rt != NULL) && (ia_ro.ro_rt->rt_ifp != NULL) &&
962 (ia_ro.ro_rt->rt_ifp == V_loif)) {
963 RT_LOCK(ia_ro.ro_rt);
964 RT_ADDREF(ia_ro.ro_rt);
965 RTFREE_LOCKED(ia_ro.ro_rt);
967 error = ifa_add_loopback_route((struct ifaddr *)ia,
968 (struct sockaddr *)&ia->ia_addr);
970 ia->ia_flags |= IFA_RTSELF;
971 if (ia_ro.ro_rt != NULL)
978 #define rtinitflags(x) \
979 ((((x)->ia_ifp->if_flags & (IFF_LOOPBACK | IFF_POINTOPOINT)) != 0) \
983 * Generate a routing message when inserting or deleting
984 * an interface address alias.
986 static void in_addralias_rtmsg(int cmd, struct in_addr *prefix,
987 struct in_ifaddr *target)
990 struct sockaddr_in *pfx_addr;
991 struct rtentry msg_rt;
994 * This is a bit questionable because there is no
995 * additional route entry added/deleted for an address
996 * alias. Therefore this route report is inaccurate.
998 bzero(&pfx_ro, sizeof(pfx_ro));
999 pfx_addr = (struct sockaddr_in *)(&pfx_ro.ro_dst);
1000 pfx_addr->sin_len = sizeof(*pfx_addr);
1001 pfx_addr->sin_family = AF_INET;
1002 pfx_addr->sin_addr = *prefix;
1003 rtalloc_ign_fib(&pfx_ro, 0, 0);
1004 if (pfx_ro.ro_rt != NULL) {
1005 msg_rt = *pfx_ro.ro_rt;
1008 * Point the gateway to the new interface
1009 * address as if a new prefix route entry has
1010 * been added through the new address alias.
1011 * All other parts of the rtentry is accurate,
1012 * e.g., rt_key, rt_mask, rt_ifp etc.
1015 (struct sockaddr *)&target->ia_addr;
1017 (struct ifaddr *)target,
1019 RTFREE(pfx_ro.ro_rt);
1025 * Check if we have a route for the given prefix already or add one accordingly.
1028 in_addprefix(struct in_ifaddr *target, int flags)
1030 struct in_ifaddr *ia;
1031 struct in_addr prefix, mask, p, m;
1034 if ((flags & RTF_HOST) != 0) {
1035 prefix = target->ia_dstaddr.sin_addr;
1038 prefix = target->ia_addr.sin_addr;
1039 mask = target->ia_sockmask.sin_addr;
1040 prefix.s_addr &= mask.s_addr;
1044 TAILQ_FOREACH(ia, &V_in_ifaddrhead, ia_link) {
1045 if (rtinitflags(ia)) {
1046 p = ia->ia_dstaddr.sin_addr;
1048 if (prefix.s_addr != p.s_addr)
1051 p = ia->ia_addr.sin_addr;
1052 m = ia->ia_sockmask.sin_addr;
1053 p.s_addr &= m.s_addr;
1055 if (prefix.s_addr != p.s_addr ||
1056 mask.s_addr != m.s_addr)
1061 * If we got a matching prefix route inserted by other
1062 * interface address, we are done here.
1064 if (ia->ia_flags & IFA_ROUTE) {
1066 if (ia->ia_addr.sin_addr.s_addr ==
1067 target->ia_addr.sin_addr.s_addr) {
1068 IN_IFADDR_RUNLOCK();
1073 if (V_sameprefixcarponly &&
1074 target->ia_ifp->if_type != IFT_CARP &&
1075 ia->ia_ifp->if_type != IFT_CARP) {
1076 IN_IFADDR_RUNLOCK();
1079 in_addralias_rtmsg(RTM_ADD, &prefix, target);
1080 IN_IFADDR_RUNLOCK();
1085 IN_IFADDR_RUNLOCK();
1088 * No-one seem to have this prefix route, so we try to insert it.
1090 error = rtinit(&target->ia_ifa, (int)RTM_ADD, flags);
1092 target->ia_flags |= IFA_ROUTE;
1096 extern void arp_ifscrub(struct ifnet *ifp, uint32_t addr);
1099 * If there is no other address in the system that can serve a route to the
1100 * same prefix, remove the route. Hand over the route to the new address
1104 in_scrubprefix(struct in_ifaddr *target, u_int flags)
1106 struct in_ifaddr *ia;
1107 struct in_addr prefix, mask, p;
1109 struct sockaddr_in prefix0, mask0;
1112 * Remove the loopback route to the interface address.
1113 * The "useloopback" setting is not consulted because if the
1114 * user configures an interface address, turns off this
1115 * setting, and then tries to delete that interface address,
1116 * checking the current setting of "useloopback" would leave
1117 * that interface address loopback route untouched, which
1118 * would be wrong. Therefore the interface address loopback route
1119 * deletion is unconditional.
1121 if ((target->ia_addr.sin_addr.s_addr != INADDR_ANY) &&
1122 !(target->ia_ifp->if_flags & IFF_LOOPBACK) &&
1123 (target->ia_flags & IFA_RTSELF)) {
1127 bzero(&ia_ro, sizeof(ia_ro));
1128 *((struct sockaddr_in *)(&ia_ro.ro_dst)) = target->ia_addr;
1129 rtalloc_ign_fib(&ia_ro, 0, 0);
1130 if ((ia_ro.ro_rt != NULL) && (ia_ro.ro_rt->rt_ifp != NULL) &&
1131 (ia_ro.ro_rt->rt_ifp == V_loif)) {
1132 RT_LOCK(ia_ro.ro_rt);
1133 if (ia_ro.ro_rt->rt_refcnt <= 1)
1135 else if (flags & LLE_STATIC) {
1136 RT_REMREF(ia_ro.ro_rt);
1137 target->ia_flags &= ~IFA_RTSELF;
1139 RTFREE_LOCKED(ia_ro.ro_rt);
1141 if (freeit && (flags & LLE_STATIC)) {
1142 error = ifa_del_loopback_route((struct ifaddr *)target,
1143 (struct sockaddr *)&target->ia_addr);
1145 target->ia_flags &= ~IFA_RTSELF;
1147 if ((flags & LLE_STATIC) &&
1148 !(target->ia_ifp->if_flags & IFF_NOARP))
1149 /* remove arp cache */
1150 arp_ifscrub(target->ia_ifp, IA_SIN(target)->sin_addr.s_addr);
1153 if (rtinitflags(target))
1154 prefix = target->ia_dstaddr.sin_addr;
1156 prefix = target->ia_addr.sin_addr;
1157 mask = target->ia_sockmask.sin_addr;
1158 prefix.s_addr &= mask.s_addr;
1161 if ((target->ia_flags & IFA_ROUTE) == 0) {
1162 in_addralias_rtmsg(RTM_DELETE, &prefix, target);
1167 TAILQ_FOREACH(ia, &V_in_ifaddrhead, ia_link) {
1168 if (rtinitflags(ia))
1169 p = ia->ia_dstaddr.sin_addr;
1171 p = ia->ia_addr.sin_addr;
1172 p.s_addr &= ia->ia_sockmask.sin_addr.s_addr;
1175 if ((prefix.s_addr != p.s_addr) ||
1176 !(ia->ia_ifp->if_flags & IFF_UP))
1180 * If we got a matching prefix address, move IFA_ROUTE and
1181 * the route itself to it. Make sure that routing daemons
1184 * XXX: a special case for carp(4) interface - this should
1185 * be more generally specified as an interface that
1186 * doesn't support such action.
1188 if ((ia->ia_flags & IFA_ROUTE) == 0
1189 && (ia->ia_ifp->if_type != IFT_CARP)) {
1190 ifa_ref(&ia->ia_ifa);
1191 IN_IFADDR_RUNLOCK();
1192 error = rtinit(&(target->ia_ifa), (int)RTM_DELETE,
1193 rtinitflags(target));
1195 target->ia_flags &= ~IFA_ROUTE;
1197 log(LOG_INFO, "in_scrubprefix: err=%d, old prefix delete failed\n",
1199 error = rtinit(&ia->ia_ifa, (int)RTM_ADD,
1200 rtinitflags(ia) | RTF_UP);
1202 ia->ia_flags |= IFA_ROUTE;
1204 log(LOG_INFO, "in_scrubprefix: err=%d, new prefix add failed\n",
1206 ifa_free(&ia->ia_ifa);
1210 IN_IFADDR_RUNLOCK();
1213 * remove all L2 entries on the given prefix
1215 bzero(&prefix0, sizeof(prefix0));
1216 prefix0.sin_len = sizeof(prefix0);
1217 prefix0.sin_family = AF_INET;
1218 prefix0.sin_addr.s_addr = target->ia_subnet;
1219 bzero(&mask0, sizeof(mask0));
1220 mask0.sin_len = sizeof(mask0);
1221 mask0.sin_family = AF_INET;
1222 mask0.sin_addr.s_addr = target->ia_subnetmask;
1223 lltable_prefix_free(AF_INET, (struct sockaddr *)&prefix0,
1224 (struct sockaddr *)&mask0, flags);
1227 * As no-one seem to have this prefix, we can remove the route.
1229 error = rtinit(&(target->ia_ifa), (int)RTM_DELETE, rtinitflags(target));
1231 target->ia_flags &= ~IFA_ROUTE;
1233 log(LOG_INFO, "in_scrubprefix: err=%d, prefix delete failed\n", error);
1240 * Return 1 if the address might be a local broadcast address.
1243 in_broadcast(struct in_addr in, struct ifnet *ifp)
1245 register struct ifaddr *ifa;
1248 if (in.s_addr == INADDR_BROADCAST ||
1249 in.s_addr == INADDR_ANY)
1251 if ((ifp->if_flags & IFF_BROADCAST) == 0)
1253 t = ntohl(in.s_addr);
1255 * Look through the list of addresses for a match
1256 * with a broadcast address.
1258 #define ia ((struct in_ifaddr *)ifa)
1259 TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link)
1260 if (ifa->ifa_addr->sa_family == AF_INET &&
1261 (in.s_addr == ia->ia_broadaddr.sin_addr.s_addr ||
1262 in.s_addr == ia->ia_netbroadcast.s_addr ||
1264 * Check for old-style (host 0) broadcast.
1266 t == ia->ia_subnet || t == ia->ia_net) &&
1268 * Check for an all one subnetmask. These
1269 * only exist when an interface gets a secondary
1272 ia->ia_subnetmask != (u_long)0xffffffff)
1279 * On interface removal, clean up IPv4 data structures hung off of the ifnet.
1282 in_ifdetach(struct ifnet *ifp)
1285 in_pcbpurgeif0(&V_ripcbinfo, ifp);
1286 in_pcbpurgeif0(&V_udbinfo, ifp);
1287 in_purgemaddrs(ifp);
1291 * Delete all IPv4 multicast address records, and associated link-layer
1292 * multicast address records, associated with ifp.
1293 * XXX It looks like domifdetach runs AFTER the link layer cleanup.
1294 * XXX This should not race with ifma_protospec being set during
1295 * a new allocation, if it does, we have bigger problems.
1298 in_purgemaddrs(struct ifnet *ifp)
1300 LIST_HEAD(,in_multi) purgeinms;
1301 struct in_multi *inm, *tinm;
1302 struct ifmultiaddr *ifma;
1304 LIST_INIT(&purgeinms);
1308 * Extract list of in_multi associated with the detaching ifp
1309 * which the PF_INET layer is about to release.
1310 * We need to do this as IF_ADDR_LOCK() may be re-acquired
1311 * by code further down.
1314 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
1315 if (ifma->ifma_addr->sa_family != AF_INET ||
1316 ifma->ifma_protospec == NULL)
1319 KASSERT(ifma->ifma_protospec != NULL,
1320 ("%s: ifma_protospec is NULL", __func__));
1322 inm = (struct in_multi *)ifma->ifma_protospec;
1323 LIST_INSERT_HEAD(&purgeinms, inm, inm_link);
1325 IF_ADDR_RUNLOCK(ifp);
1327 LIST_FOREACH_SAFE(inm, &purgeinms, inm_link, tinm) {
1328 LIST_REMOVE(inm, inm_link);
1329 inm_release_locked(inm);
1336 #include <net/if_dl.h>
1337 #include <netinet/if_ether.h>
1340 struct llentry base;
1341 struct sockaddr_in l3_addr4;
1344 static struct llentry *
1345 in_lltable_new(const struct sockaddr *l3addr, u_int flags)
1347 struct in_llentry *lle;
1349 lle = malloc(sizeof(struct in_llentry), M_LLTABLE, M_DONTWAIT | M_ZERO);
1350 if (lle == NULL) /* NB: caller generates msg */
1354 * For IPv4 this will trigger "arpresolve" to generate
1357 lle->base.la_expire = time_second; /* mark expired */
1358 lle->l3_addr4 = *(const struct sockaddr_in *)l3addr;
1359 lle->base.lle_refcnt = 1;
1360 LLE_LOCK_INIT(&lle->base);
1361 callout_init_rw(&lle->base.la_timer, &lle->base.lle_lock,
1362 CALLOUT_RETURNUNLOCKED);
1364 return (&lle->base);
1368 * Deletes an address from the address table.
1369 * This function is called by the timer functions
1370 * such as arptimer() and nd6_llinfo_timer(), and
1371 * the caller does the locking.
1374 in_lltable_free(struct lltable *llt, struct llentry *lle)
1377 LLE_LOCK_DESTROY(lle);
1378 free(lle, M_LLTABLE);
1382 #define IN_ARE_MASKED_ADDR_EQUAL(d, a, m) ( \
1383 (((ntohl((d)->sin_addr.s_addr) ^ (a)->sin_addr.s_addr) & (m)->sin_addr.s_addr)) == 0 )
1386 in_lltable_prefix_free(struct lltable *llt,
1387 const struct sockaddr *prefix,
1388 const struct sockaddr *mask,
1391 const struct sockaddr_in *pfx = (const struct sockaddr_in *)prefix;
1392 const struct sockaddr_in *msk = (const struct sockaddr_in *)mask;
1393 struct llentry *lle, *next;
1395 size_t pkts_dropped;
1397 IF_AFDATA_WLOCK(llt->llt_ifp);
1398 for (i = 0; i < LLTBL_HASHTBL_SIZE; i++) {
1399 LIST_FOREACH_SAFE(lle, &llt->lle_head[i], lle_next, next) {
1402 * (flags & LLE_STATIC) means deleting all entries
1403 * including static ARP entries
1405 if (IN_ARE_MASKED_ADDR_EQUAL((struct sockaddr_in *)L3_ADDR(lle),
1407 ((flags & LLE_STATIC) || !(lle->la_flags & LLE_STATIC))) {
1409 if (callout_stop(&lle->la_timer))
1411 pkts_dropped = llentry_free(lle);
1412 ARPSTAT_ADD(dropped, pkts_dropped);
1416 IF_AFDATA_WUNLOCK(llt->llt_ifp);
1421 in_lltable_rtcheck(struct ifnet *ifp, u_int flags, const struct sockaddr *l3addr)
1425 KASSERT(l3addr->sa_family == AF_INET,
1426 ("sin_family %d", l3addr->sa_family));
1428 /* XXX rtalloc1 should take a const param */
1429 rt = rtalloc1(__DECONST(struct sockaddr *, l3addr), 0, 0);
1435 * If the gateway for an existing host route matches the target L3
1436 * address, which is a special route inserted by some implementation
1437 * such as MANET, and the interface is of the correct type, then
1438 * allow for ARP to proceed.
1440 if (rt->rt_flags & RTF_GATEWAY) {
1441 if (!(rt->rt_flags & RTF_HOST) || !rt->rt_ifp ||
1442 rt->rt_ifp->if_type != IFT_ETHER ||
1443 (rt->rt_ifp->if_flags &
1444 (IFF_NOARP | IFF_STATICARP)) != 0 ||
1445 memcmp(rt->rt_gateway->sa_data, l3addr->sa_data,
1446 sizeof(in_addr_t)) != 0) {
1453 * Make sure that at least the destination address is covered
1454 * by the route. This is for handling the case where 2 or more
1455 * interfaces have the same prefix. An incoming packet arrives
1456 * on one interface and the corresponding outgoing packet leaves
1457 * another interface.
1459 if (!(rt->rt_flags & RTF_HOST) && rt->rt_ifp != ifp) {
1460 const char *sa, *mask, *addr, *lim;
1463 mask = (const char *)rt_mask(rt);
1465 * Just being extra cautious to avoid some custom
1466 * code getting into trouble.
1473 sa = (const char *)rt_key(rt);
1474 addr = (const char *)l3addr;
1475 len = ((const struct sockaddr_in *)l3addr)->sin_len;
1478 for ( ; addr < lim; sa++, mask++, addr++) {
1479 if ((*sa ^ *addr) & *mask) {
1481 log(LOG_INFO, "IPv4 address: \"%s\" is not on the network\n",
1482 inet_ntoa(((const struct sockaddr_in *)l3addr)->sin_addr));
1495 * Return NULL if not found or marked for deletion.
1496 * If found return lle read locked.
1498 static struct llentry *
1499 in_lltable_lookup(struct lltable *llt, u_int flags, const struct sockaddr *l3addr)
1501 const struct sockaddr_in *sin = (const struct sockaddr_in *)l3addr;
1502 struct ifnet *ifp = llt->llt_ifp;
1503 struct llentry *lle;
1504 struct llentries *lleh;
1507 IF_AFDATA_LOCK_ASSERT(ifp);
1508 KASSERT(l3addr->sa_family == AF_INET,
1509 ("sin_family %d", l3addr->sa_family));
1511 hashkey = sin->sin_addr.s_addr;
1512 lleh = &llt->lle_head[LLATBL_HASH(hashkey, LLTBL_HASHMASK)];
1513 LIST_FOREACH(lle, lleh, lle_next) {
1514 struct sockaddr_in *sa2 = (struct sockaddr_in *)L3_ADDR(lle);
1515 if (lle->la_flags & LLE_DELETED)
1517 if (sa2->sin_addr.s_addr == sin->sin_addr.s_addr)
1522 if (flags & LLE_DELETE)
1523 log(LOG_INFO, "interface address is missing from cache = %p in delete\n", lle);
1525 if (!(flags & LLE_CREATE))
1528 * A route that covers the given address must have
1529 * been installed 1st because we are doing a resolution,
1532 if (!(flags & LLE_IFADDR) &&
1533 in_lltable_rtcheck(ifp, flags, l3addr) != 0)
1536 lle = in_lltable_new(l3addr, flags);
1538 log(LOG_INFO, "lla_lookup: new lle malloc failed\n");
1541 lle->la_flags = flags & ~LLE_CREATE;
1542 if ((flags & (LLE_CREATE | LLE_IFADDR)) == (LLE_CREATE | LLE_IFADDR)) {
1543 bcopy(IF_LLADDR(ifp), &lle->ll_addr, ifp->if_addrlen);
1544 lle->la_flags |= (LLE_VALID | LLE_STATIC);
1548 lle->lle_head = lleh;
1549 lle->la_flags |= LLE_LINKED;
1550 LIST_INSERT_HEAD(lleh, lle, lle_next);
1551 } else if (flags & LLE_DELETE) {
1552 if (!(lle->la_flags & LLE_IFADDR) || (flags & LLE_IFADDR)) {
1554 lle->la_flags |= LLE_DELETED;
1556 log(LOG_INFO, "ifaddr cache = %p is deleted\n", lle);
1558 if ((lle->la_flags &
1559 (LLE_STATIC | LLE_IFADDR)) == LLE_STATIC)
1567 if (LLE_IS_VALID(lle)) {
1568 if (flags & LLE_EXCLUSIVE)
1578 in_lltable_dump(struct lltable *llt, struct sysctl_req *wr)
1580 #define SIN(lle) ((struct sockaddr_in *) L3_ADDR(lle))
1581 struct ifnet *ifp = llt->llt_ifp;
1582 struct llentry *lle;
1585 struct rt_msghdr rtm;
1586 struct sockaddr_inarp sin;
1587 struct sockaddr_dl sdl;
1591 LLTABLE_LOCK_ASSERT();
1594 for (i = 0; i < LLTBL_HASHTBL_SIZE; i++) {
1595 LIST_FOREACH(lle, &llt->lle_head[i], lle_next) {
1596 struct sockaddr_dl *sdl;
1598 /* skip deleted entries */
1599 if ((lle->la_flags & LLE_DELETED) == LLE_DELETED)
1601 /* Skip if jailed and not a valid IP of the prison. */
1602 if (prison_if(wr->td->td_ucred, L3_ADDR(lle)) != 0)
1605 * produce a msg made of:
1607 * struct sockaddr_inarp; (IPv4)
1608 * struct sockaddr_dl;
1610 bzero(&arpc, sizeof(arpc));
1611 arpc.rtm.rtm_msglen = sizeof(arpc);
1612 arpc.rtm.rtm_version = RTM_VERSION;
1613 arpc.rtm.rtm_type = RTM_GET;
1614 arpc.rtm.rtm_flags = RTF_UP;
1615 arpc.rtm.rtm_addrs = RTA_DST | RTA_GATEWAY;
1616 arpc.sin.sin_family = AF_INET;
1617 arpc.sin.sin_len = sizeof(arpc.sin);
1618 arpc.sin.sin_addr.s_addr = SIN(lle)->sin_addr.s_addr;
1621 if (lle->la_flags & LLE_PUB) {
1622 arpc.rtm.rtm_flags |= RTF_ANNOUNCE;
1624 if (lle->la_flags & LLE_PROXY)
1625 arpc.sin.sin_other = SIN_PROXY;
1629 sdl->sdl_family = AF_LINK;
1630 sdl->sdl_len = sizeof(*sdl);
1631 sdl->sdl_index = ifp->if_index;
1632 sdl->sdl_type = ifp->if_type;
1633 if ((lle->la_flags & LLE_VALID) == LLE_VALID) {
1634 sdl->sdl_alen = ifp->if_addrlen;
1635 bcopy(&lle->ll_addr, LLADDR(sdl), ifp->if_addrlen);
1638 bzero(LLADDR(sdl), ifp->if_addrlen);
1641 arpc.rtm.rtm_rmx.rmx_expire =
1642 lle->la_flags & LLE_STATIC ? 0 : lle->la_expire;
1643 arpc.rtm.rtm_flags |= (RTF_HOST | RTF_LLDATA);
1644 if (lle->la_flags & LLE_STATIC)
1645 arpc.rtm.rtm_flags |= RTF_STATIC;
1646 arpc.rtm.rtm_index = ifp->if_index;
1647 error = SYSCTL_OUT(wr, &arpc, sizeof(arpc));
1657 in_domifattach(struct ifnet *ifp)
1659 struct in_ifinfo *ii;
1660 struct lltable *llt;
1662 ii = malloc(sizeof(struct in_ifinfo), M_IFADDR, M_WAITOK|M_ZERO);
1664 llt = lltable_init(ifp, AF_INET);
1666 llt->llt_free = in_lltable_free;
1667 llt->llt_prefix_free = in_lltable_prefix_free;
1668 llt->llt_lookup = in_lltable_lookup;
1669 llt->llt_dump = in_lltable_dump;
1673 ii->ii_igmp = igmp_domifattach(ifp);
1679 in_domifdetach(struct ifnet *ifp, void *aux)
1681 struct in_ifinfo *ii = (struct in_ifinfo *)aux;
1683 igmp_domifdetach(ifp);
1684 lltable_free(ii->ii_llt);