2 * Copyright (c) 1982, 1986, 1988, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 4. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * @(#)if_ether.c 8.1 (Berkeley) 6/10/93
33 * Ethernet address resolution protocol.
35 * add "inuse/lock" bit (or ref. count) along with valid bit
38 #include <sys/cdefs.h>
39 __FBSDID("$FreeBSD$");
42 #include "opt_route.h"
45 #include <sys/param.h>
46 #include <sys/kernel.h>
47 #include <sys/queue.h>
48 #include <sys/sysctl.h>
49 #include <sys/systm.h>
51 #include <sys/malloc.h>
53 #include <sys/socket.h>
54 #include <sys/syslog.h>
55 #include <sys/vimage.h>
58 #include <net/if_dl.h>
59 #include <net/if_types.h>
60 #include <net/route.h>
61 #include <net/netisr.h>
62 #include <net/if_llc.h>
63 #include <net/ethernet.h>
66 #include <netinet/in.h>
67 #include <netinet/in_var.h>
68 #include <net/if_llatbl.h>
69 #include <netinet/if_ether.h>
70 #include <netinet/vinet.h>
72 #include <net/if_arc.h>
73 #include <net/iso88025.h>
76 #include <netinet/ip_carp.h>
79 #include <security/mac/mac_framework.h>
81 #define SIN(s) ((struct sockaddr_in *)s)
82 #define SDL(s) ((struct sockaddr_dl *)s)
84 SYSCTL_DECL(_net_link_ether);
85 SYSCTL_NODE(_net_link_ether, PF_INET, inet, CTLFLAG_RW, 0, "");
89 static int arpt_keep; /* once resolved, good for 20 more minutes */
90 static int arp_maxtries;
91 int useloopback; /* use loopback interface for local traffic */
92 static int arp_proxyall;
95 SYSCTL_V_INT(V_NET, vnet_inet, _net_link_ether_inet, OID_AUTO, max_age,
96 CTLFLAG_RW, arpt_keep, 0, "ARP entry lifetime in seconds");
98 SYSCTL_V_INT(V_NET, vnet_inet, _net_link_ether_inet, OID_AUTO, maxtries,
99 CTLFLAG_RW, arp_maxtries, 0,
100 "ARP resolution attempts before returning error");
101 SYSCTL_V_INT(V_NET, vnet_inet, _net_link_ether_inet, OID_AUTO, useloopback,
102 CTLFLAG_RW, useloopback, 0,
103 "Use the loopback interface for local traffic");
104 SYSCTL_V_INT(V_NET, vnet_inet, _net_link_ether_inet, OID_AUTO, proxyall,
105 CTLFLAG_RW, arp_proxyall, 0,
106 "Enable proxy ARP for all suitable requests");
108 static void arp_init(void);
109 static int arp_iattach(const void *);
110 void arprequest(struct ifnet *,
111 struct in_addr *, struct in_addr *, u_char *);
112 static void arpintr(struct mbuf *);
113 static void arptimer(void *);
115 static void in_arpinput(struct mbuf *);
118 static const struct netisr_handler arp_nh = {
120 .nh_handler = arpintr,
121 .nh_proto = NETISR_ARP,
122 .nh_policy = NETISR_POLICY_SOURCE,
125 #ifndef VIMAGE_GLOBALS
126 static const vnet_modinfo_t vnet_arp_modinfo = {
127 .vmi_id = VNET_MOD_ARP,
129 .vmi_dependson = VNET_MOD_INET,
130 .vmi_iattach = arp_iattach
132 #endif /* !VIMAGE_GLOBALS */
135 void arp_ifscrub(struct ifnet *ifp, uint32_t addr);
138 * called by in_ifscrub to remove entry from the table when
139 * the interface goes away
142 arp_ifscrub(struct ifnet *ifp, uint32_t addr)
144 struct sockaddr_in addr4;
146 bzero((void *)&addr4, sizeof(addr4));
147 addr4.sin_len = sizeof(addr4);
148 addr4.sin_family = AF_INET;
149 addr4.sin_addr.s_addr = addr;
150 CURVNET_SET(ifp->if_vnet);
152 lla_lookup(LLTABLE(ifp), (LLE_DELETE | LLE_IFADDR),
153 (struct sockaddr *)&addr4);
154 IF_AFDATA_UNLOCK(ifp);
160 * Timeout routine. Age arp_tab entries periodically.
166 struct llentry *lle = (struct llentry *)arg;
169 panic("%s: NULL entry!\n", __func__);
172 ifp = lle->lle_tbl->llt_ifp;
175 if (((lle->la_flags & LLE_DELETED)
176 || (time_second >= lle->la_expire))
177 && (!callout_pending(&lle->la_timer) &&
178 callout_active(&lle->la_timer)))
179 (void) llentry_free(lle);
182 * Still valid, just drop our reference
184 LLE_FREE_LOCKED(lle);
186 IF_AFDATA_UNLOCK(ifp);
190 * Broadcast an ARP request. Caller specifies:
191 * - arp header source ip address
192 * - arp header target ip address
193 * - arp header source ethernet address
196 arprequest(struct ifnet *ifp, struct in_addr *sip, struct in_addr *tip,
204 /* XXX don't believe this can happen (or explain why) */
206 * The caller did not supply a source address, try to find
207 * a compatible one among those assigned to this interface.
211 TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
212 if (!ifa->ifa_addr ||
213 ifa->ifa_addr->sa_family != AF_INET)
215 sip = &SIN(ifa->ifa_addr)->sin_addr;
216 if (0 == ((sip->s_addr ^ tip->s_addr) &
217 SIN(ifa->ifa_netmask)->sin_addr.s_addr) )
218 break; /* found it. */
221 printf("%s: cannot find matching address\n", __func__);
226 if ((m = m_gethdr(M_DONTWAIT, MT_DATA)) == NULL)
228 m->m_len = sizeof(*ah) + 2*sizeof(struct in_addr) +
229 2*ifp->if_data.ifi_addrlen;
230 m->m_pkthdr.len = m->m_len;
231 MH_ALIGN(m, m->m_len);
232 ah = mtod(m, struct arphdr *);
233 bzero((caddr_t)ah, m->m_len);
235 mac_netinet_arp_send(ifp, m);
237 ah->ar_pro = htons(ETHERTYPE_IP);
238 ah->ar_hln = ifp->if_addrlen; /* hardware address length */
239 ah->ar_pln = sizeof(struct in_addr); /* protocol address length */
240 ah->ar_op = htons(ARPOP_REQUEST);
241 bcopy((caddr_t)enaddr, (caddr_t)ar_sha(ah), ah->ar_hln);
242 bcopy((caddr_t)sip, (caddr_t)ar_spa(ah), ah->ar_pln);
243 bcopy((caddr_t)tip, (caddr_t)ar_tpa(ah), ah->ar_pln);
244 sa.sa_family = AF_ARP;
246 m->m_flags |= M_BCAST;
247 (*ifp->if_output)(ifp, m, &sa, NULL);
251 * Resolve an IP address into an ethernet address.
253 * ifp is the interface we use
254 * rt0 is the route to the final destination (possibly useless)
255 * m is the mbuf. May be NULL if we don't have a packet.
256 * dst is the next hop,
257 * desten is where we want the address.
259 * On success, desten is filled in and the function returns 0;
260 * If the packet must be held pending resolution, we return EWOULDBLOCK
261 * On other errors, we return the corresponding error code.
262 * Note that m_freem() handles NULL.
265 arpresolve(struct ifnet *ifp, struct rtentry *rt0, struct mbuf *m,
266 struct sockaddr *dst, u_char *desten, struct llentry **lle)
268 INIT_VNET_INET(ifp->if_vnet);
269 struct llentry *la = 0;
275 if (m->m_flags & M_BCAST) {
278 ifp->if_broadcastaddr, ifp->if_addrlen);
281 if (m->m_flags & M_MCAST && ifp->if_type != IFT_ARCNET) {
283 ETHER_MAP_IP_MULTICAST(&SIN(dst)->sin_addr, desten);
290 IF_AFDATA_RLOCK(ifp);
291 la = lla_lookup(LLTABLE(ifp), flags, dst);
292 IF_AFDATA_RUNLOCK(ifp);
293 if ((la == NULL) && ((flags & LLE_EXCLUSIVE) == 0)
294 && ((ifp->if_flags & (IFF_NOARP | IFF_STATICARP)) == 0)) {
295 flags |= (LLE_CREATE | LLE_EXCLUSIVE);
296 IF_AFDATA_WLOCK(ifp);
297 la = lla_lookup(LLTABLE(ifp), flags, dst);
298 IF_AFDATA_WUNLOCK(ifp);
301 if (flags & LLE_CREATE)
303 "arpresolve: can't allocate llinfo for %s\n",
304 inet_ntoa(SIN(dst)->sin_addr));
309 if ((la->la_flags & LLE_VALID) &&
310 ((la->la_flags & LLE_STATIC) || la->la_expire > time_uptime)) {
311 bcopy(&la->ll_addr, desten, ifp->if_addrlen);
313 * If entry has an expiry time and it is approaching,
314 * see if we need to send an ARP request within this
315 * arpt_down interval.
317 if (!(la->la_flags & LLE_STATIC) &&
318 time_uptime + la->la_preempt > la->la_expire) {
319 arprequest(ifp, NULL,
320 &SIN(dst)->sin_addr, IF_LLADDR(ifp));
330 if (la->la_flags & LLE_STATIC) { /* should not happen! */
331 log(LOG_DEBUG, "arpresolve: ouch, empty static llinfo for %s\n",
332 inet_ntoa(SIN(dst)->sin_addr));
338 renew = (la->la_asked == 0 || la->la_expire != time_uptime);
339 if ((renew || m != NULL) && (flags & LLE_EXCLUSIVE) == 0) {
340 flags |= LLE_EXCLUSIVE;
345 * There is an arptab entry, but no ethernet address
346 * response yet. Replace the held mbuf with this
350 if (la->la_hold != NULL)
351 m_freem(la->la_hold);
353 if (renew == 0 && (flags & LLE_EXCLUSIVE)) {
354 flags &= ~LLE_EXCLUSIVE;
360 * Return EWOULDBLOCK if we have tried less than arp_maxtries. It
361 * will be masked by ether_output(). Return EHOSTDOWN/EHOSTUNREACH
362 * if we have already sent arp_maxtries ARP requests. Retransmit the
363 * ARP request, but not faster than one request per second.
365 if (la->la_asked < V_arp_maxtries)
366 error = EWOULDBLOCK; /* First request. */
369 (rt0->rt_flags & RTF_GATEWAY) ? EHOSTDOWN : EHOSTUNREACH;
373 la->la_expire = time_uptime;
374 callout_reset(&la->la_timer, hz, arptimer, la);
377 arprequest(ifp, NULL, &SIN(dst)->sin_addr,
382 if (flags & LLE_EXCLUSIVE)
390 * Common length and type checks are done here,
391 * then the protocol-specific routine is called.
394 arpintr(struct mbuf *m)
398 if (m->m_len < sizeof(struct arphdr) &&
399 ((m = m_pullup(m, sizeof(struct arphdr))) == NULL)) {
400 log(LOG_ERR, "arp: runt packet -- m_pullup failed\n");
403 ar = mtod(m, struct arphdr *);
405 if (ntohs(ar->ar_hrd) != ARPHRD_ETHER &&
406 ntohs(ar->ar_hrd) != ARPHRD_IEEE802 &&
407 ntohs(ar->ar_hrd) != ARPHRD_ARCNET &&
408 ntohs(ar->ar_hrd) != ARPHRD_IEEE1394) {
409 log(LOG_ERR, "arp: unknown hardware address format (0x%2D)\n",
410 (unsigned char *)&ar->ar_hrd, "");
415 if (m->m_len < arphdr_len(ar)) {
416 if ((m = m_pullup(m, arphdr_len(ar))) == NULL) {
417 log(LOG_ERR, "arp: runt packet\n");
421 ar = mtod(m, struct arphdr *);
424 switch (ntohs(ar->ar_pro)) {
436 * ARP for Internet protocols on 10 Mb/s Ethernet.
437 * Algorithm is that given in RFC 826.
438 * In addition, a sanity check is performed on the sender
439 * protocol address, to catch impersonators.
440 * We no longer handle negotiations for use of trailer protocol:
441 * Formerly, ARP replied for protocol type ETHERTYPE_TRAIL sent
442 * along with IP replies if we wanted trailers sent to us,
443 * and also sent them in response to IP replies.
444 * This allowed either end to announce the desire to receive
446 * We no longer reply to requests for ETHERTYPE_TRAIL protocol either,
447 * but formerly didn't normally send requests.
449 static int log_arp_wrong_iface = 1;
450 static int log_arp_movements = 1;
451 static int log_arp_permanent_modify = 1;
453 SYSCTL_INT(_net_link_ether_inet, OID_AUTO, log_arp_wrong_iface, CTLFLAG_RW,
454 &log_arp_wrong_iface, 0,
455 "log arp packets arriving on the wrong interface");
456 SYSCTL_INT(_net_link_ether_inet, OID_AUTO, log_arp_movements, CTLFLAG_RW,
457 &log_arp_movements, 0,
458 "log arp replies from MACs different than the one in the cache");
459 SYSCTL_INT(_net_link_ether_inet, OID_AUTO, log_arp_permanent_modify, CTLFLAG_RW,
460 &log_arp_permanent_modify, 0,
461 "log arp replies from MACs different than the one in the permanent arp entry");
465 in_arpinput(struct mbuf *m)
468 struct ifnet *ifp = m->m_pkthdr.rcvif;
469 struct llentry *la = NULL;
472 struct in_ifaddr *ia;
474 struct in_addr isaddr, itaddr, myaddr;
475 u_int8_t *enaddr = NULL;
479 int bridged = 0, is_bridge = 0;
483 struct sockaddr_in sin;
484 sin.sin_len = sizeof(struct sockaddr_in);
485 sin.sin_family = AF_INET;
486 sin.sin_addr.s_addr = 0;
487 INIT_VNET_INET(ifp->if_vnet);
491 if (ifp->if_type == IFT_BRIDGE)
494 req_len = arphdr_len2(ifp->if_addrlen, sizeof(struct in_addr));
495 if (m->m_len < req_len && (m = m_pullup(m, req_len)) == NULL) {
496 log(LOG_ERR, "in_arp: runt packet -- m_pullup failed\n");
500 ah = mtod(m, struct arphdr *);
501 op = ntohs(ah->ar_op);
502 (void)memcpy(&isaddr, ar_spa(ah), sizeof (isaddr));
503 (void)memcpy(&itaddr, ar_tpa(ah), sizeof (itaddr));
506 * For a bridge, we want to check the address irrespective
507 * of the receive interface. (This will change slightly
508 * when we have clusters of interfaces).
509 * If the interface does not match, but the recieving interface
510 * is part of carp, we call carp_iamatch to see if this is a
511 * request for the virtual host ip.
512 * XXX: This is really ugly!
514 LIST_FOREACH(ia, INADDR_HASH(itaddr.s_addr), ia_hash) {
515 if (((bridged && ia->ia_ifp->if_bridge != NULL) ||
516 ia->ia_ifp == ifp) &&
517 itaddr.s_addr == ia->ia_addr.sin_addr.s_addr)
520 if (ifp->if_carp != NULL &&
521 carp_iamatch(ifp->if_carp, ia, &isaddr, &enaddr) &&
522 itaddr.s_addr == ia->ia_addr.sin_addr.s_addr) {
528 LIST_FOREACH(ia, INADDR_HASH(isaddr.s_addr), ia_hash)
529 if (((bridged && ia->ia_ifp->if_bridge != NULL) ||
530 ia->ia_ifp == ifp) &&
531 isaddr.s_addr == ia->ia_addr.sin_addr.s_addr)
534 #define BDG_MEMBER_MATCHES_ARP(addr, ifp, ia) \
535 (ia->ia_ifp->if_bridge == ifp->if_softc && \
536 !bcmp(IF_LLADDR(ia->ia_ifp), IF_LLADDR(ifp), ifp->if_addrlen) && \
537 addr == ia->ia_addr.sin_addr.s_addr)
539 * Check the case when bridge shares its MAC address with
540 * some of its children, so packets are claimed by bridge
541 * itself (bridge_input() does it first), but they are really
542 * meant to be destined to the bridge member.
545 LIST_FOREACH(ia, INADDR_HASH(itaddr.s_addr), ia_hash) {
546 if (BDG_MEMBER_MATCHES_ARP(itaddr.s_addr, ifp, ia)) {
552 #undef BDG_MEMBER_MATCHES_ARP
555 * No match, use the first inet address on the receive interface
556 * as a dummy address for the rest of the function.
558 TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link)
559 if (ifa->ifa_addr->sa_family == AF_INET) {
564 * If bridging, fall back to using any inet address.
566 if (!bridged || (ia = TAILQ_FIRST(&V_in_ifaddrhead)) == NULL)
570 enaddr = (u_int8_t *)IF_LLADDR(ifp);
571 myaddr = ia->ia_addr.sin_addr;
572 if (!bcmp(ar_sha(ah), enaddr, ifp->if_addrlen))
573 goto drop; /* it's from me, ignore it. */
574 if (!bcmp(ar_sha(ah), ifp->if_broadcastaddr, ifp->if_addrlen)) {
576 "arp: link address is broadcast for IP address %s!\n",
581 * Warn if another host is using the same IP address, but only if the
582 * IP address isn't 0.0.0.0, which is used for DHCP only, in which
583 * case we suppress the warning to avoid false positive complaints of
584 * potential misconfiguration.
586 if (!bridged && isaddr.s_addr == myaddr.s_addr && myaddr.s_addr != 0) {
588 "arp: %*D is using my IP address %s on %s!\n",
589 ifp->if_addrlen, (u_char *)ar_sha(ah), ":",
590 inet_ntoa(isaddr), ifp->if_xname);
594 if (ifp->if_flags & IFF_STATICARP)
597 bzero(&sin, sizeof(sin));
598 sin.sin_len = sizeof(struct sockaddr_in);
599 sin.sin_family = AF_INET;
600 sin.sin_addr = isaddr;
601 flags = (itaddr.s_addr == myaddr.s_addr) ? LLE_CREATE : 0;
602 flags |= LLE_EXCLUSIVE;
604 la = lla_lookup(LLTABLE(ifp), flags, (struct sockaddr *)&sin);
605 IF_AFDATA_UNLOCK(ifp);
607 /* the following is not an error when doing bridging */
608 if (!bridged && la->lle_tbl->llt_ifp != ifp
610 && (ifp->if_type != IFT_CARP || !carp_match)
613 if (log_arp_wrong_iface)
614 log(LOG_ERR, "arp: %s is on %s "
615 "but got reply from %*D on %s\n",
617 la->lle_tbl->llt_ifp->if_xname,
618 ifp->if_addrlen, (u_char *)ar_sha(ah), ":",
622 if ((la->la_flags & LLE_VALID) &&
623 bcmp(ar_sha(ah), &la->ll_addr, ifp->if_addrlen)) {
624 if (la->la_flags & LLE_STATIC) {
626 "arp: %*D attempts to modify permanent "
627 "entry for %s on %s\n",
628 ifp->if_addrlen, (u_char *)ar_sha(ah), ":",
629 inet_ntoa(isaddr), ifp->if_xname);
632 if (log_arp_movements) {
633 log(LOG_INFO, "arp: %s moved from %*D "
637 (u_char *)&la->ll_addr, ":",
638 ifp->if_addrlen, (u_char *)ar_sha(ah), ":",
643 if (ifp->if_addrlen != ah->ar_hln) {
645 "arp from %*D: addr len: new %d, i/f %d (ignored)",
646 ifp->if_addrlen, (u_char *) ar_sha(ah), ":",
647 ah->ar_hln, ifp->if_addrlen);
650 (void)memcpy(&la->ll_addr, ar_sha(ah), ifp->if_addrlen);
651 la->la_flags |= LLE_VALID;
653 if (!(la->la_flags & LLE_STATIC)) {
654 la->la_expire = time_uptime + V_arpt_keep;
655 callout_reset(&la->la_timer, hz * V_arpt_keep,
659 la->la_preempt = V_arp_maxtries;
660 if (la->la_hold != NULL) {
663 memcpy(&sa, L3_ADDR(la), sizeof(sa));
666 (*ifp->if_output)(ifp, m0, &sa, NULL);
671 if (op != ARPOP_REQUEST)
674 if (itaddr.s_addr == myaddr.s_addr) {
675 /* Shortcut.. the receiving interface is the target. */
676 (void)memcpy(ar_tha(ah), ar_sha(ah), ah->ar_hln);
677 (void)memcpy(ar_sha(ah), enaddr, ah->ar_hln);
679 struct llentry *lle = NULL;
684 sin.sin_addr = itaddr;
685 /* XXX MRT use table 0 for arp reply */
686 rt = in_rtalloc1((struct sockaddr *)&sin, 0, 0UL, 0);
691 * Don't send proxies for nodes on the same interface
692 * as this one came out of, or we'll get into a fight
693 * over who claims what Ether address.
695 if (!rt->rt_ifp || rt->rt_ifp == ifp) {
699 IF_AFDATA_LOCK(rt->rt_ifp);
700 lle = lla_lookup(LLTABLE(rt->rt_ifp), 0, (struct sockaddr *)&sin);
701 IF_AFDATA_UNLOCK(rt->rt_ifp);
705 (void)memcpy(ar_tha(ah), ar_sha(ah), ah->ar_hln);
706 (void)memcpy(ar_sha(ah), &lle->ll_addr, ah->ar_hln);
712 * Also check that the node which sent the ARP packet
713 * is on the the interface we expect it to be on. This
714 * avoids ARP chaos if an interface is connected to the
717 sin.sin_addr = isaddr;
719 /* XXX MRT use table 0 for arp checks */
720 rt = in_rtalloc1((struct sockaddr *)&sin, 0, 0UL, 0);
723 if (rt->rt_ifp != ifp) {
724 log(LOG_INFO, "arp_proxy: ignoring request"
725 " from %s via %s, expecting %s\n",
726 inet_ntoa(isaddr), ifp->if_xname,
727 rt->rt_ifp->if_xname);
734 printf("arp: proxying for %s\n",
741 if (itaddr.s_addr == myaddr.s_addr &&
742 IN_LINKLOCAL(ntohl(itaddr.s_addr))) {
743 /* RFC 3927 link-local IPv4; always reply by broadcast. */
744 #ifdef DEBUG_LINKLOCAL
745 printf("arp: sending reply for link-local addr %s\n",
748 m->m_flags |= M_BCAST;
749 m->m_flags &= ~M_MCAST;
751 /* default behaviour; never reply by broadcast. */
752 m->m_flags &= ~(M_BCAST|M_MCAST);
754 (void)memcpy(ar_tpa(ah), ar_spa(ah), ah->ar_pln);
755 (void)memcpy(ar_spa(ah), &itaddr, ah->ar_pln);
756 ah->ar_op = htons(ARPOP_REPLY);
757 ah->ar_pro = htons(ETHERTYPE_IP); /* let's be sure! */
758 m->m_len = sizeof(*ah) + (2 * ah->ar_pln) + (2 * ah->ar_hln);
759 m->m_pkthdr.len = m->m_len;
760 sa.sa_family = AF_ARP;
762 (*ifp->if_output)(ifp, m, &sa, NULL);
773 arp_ifinit(struct ifnet *ifp, struct ifaddr *ifa)
777 if (ntohl(IA_SIN(ifa)->sin_addr.s_addr) != INADDR_ANY) {
778 arprequest(ifp, &IA_SIN(ifa)->sin_addr,
779 &IA_SIN(ifa)->sin_addr, IF_LLADDR(ifp));
781 * interface address is considered static entry
782 * because the output of the arp utility shows
783 * that L2 entry as permanent
786 lle = lla_lookup(LLTABLE(ifp), (LLE_CREATE | LLE_IFADDR | LLE_STATIC),
787 (struct sockaddr *)IA_SIN(ifa));
788 IF_AFDATA_UNLOCK(ifp);
790 log(LOG_INFO, "arp_ifinit: cannot create arp "
791 "entry for interface address\n");
795 ifa->ifa_rtrequest = NULL;
799 arp_ifinit2(struct ifnet *ifp, struct ifaddr *ifa, u_char *enaddr)
801 if (ntohl(IA_SIN(ifa)->sin_addr.s_addr) != INADDR_ANY)
802 arprequest(ifp, &IA_SIN(ifa)->sin_addr,
803 &IA_SIN(ifa)->sin_addr, enaddr);
804 ifa->ifa_rtrequest = NULL;
808 arp_iattach(const void *unused __unused)
810 INIT_VNET_INET(curvnet);
812 V_arpt_keep = (20*60); /* once resolved, good for 20 more minutes */
814 V_useloopback = 1; /* use loopback interface for local traffic */
824 #ifndef VIMAGE_GLOBALS
825 vnet_mod_register(&vnet_arp_modinfo);
830 netisr_register(&arp_nh);
832 SYSINIT(arp, SI_SUB_PROTO_DOMAIN, SI_ORDER_ANY, arp_init, 0);