1c398230bSWarner Losh /*- 2df8bae1dSRodney W. Grimes * Copyright (c) 1982, 1986, 1988, 1993 3df8bae1dSRodney W. Grimes * The Regents of the University of California. All rights reserved. 4df8bae1dSRodney W. Grimes * 5df8bae1dSRodney W. Grimes * Redistribution and use in source and binary forms, with or without 6df8bae1dSRodney W. Grimes * modification, are permitted provided that the following conditions 7df8bae1dSRodney W. Grimes * are met: 8df8bae1dSRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 9df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer. 10df8bae1dSRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 11df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 12df8bae1dSRodney W. Grimes * documentation and/or other materials provided with the distribution. 13df8bae1dSRodney W. Grimes * 4. Neither the name of the University nor the names of its contributors 14df8bae1dSRodney W. Grimes * may be used to endorse or promote products derived from this software 15df8bae1dSRodney W. Grimes * without specific prior written permission. 16df8bae1dSRodney W. Grimes * 17df8bae1dSRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18df8bae1dSRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19df8bae1dSRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20df8bae1dSRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21df8bae1dSRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22df8bae1dSRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23df8bae1dSRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24df8bae1dSRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25df8bae1dSRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26df8bae1dSRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27df8bae1dSRodney W. Grimes * SUCH DAMAGE. 28df8bae1dSRodney W. Grimes * 29df8bae1dSRodney W. Grimes * @(#)if_ether.c 8.1 (Berkeley) 6/10/93 30c3aac50fSPeter Wemm * $FreeBSD$ 31df8bae1dSRodney W. Grimes */ 32df8bae1dSRodney W. Grimes 33df8bae1dSRodney W. Grimes /* 34df8bae1dSRodney W. Grimes * Ethernet address resolution protocol. 35df8bae1dSRodney W. Grimes * TODO: 36df8bae1dSRodney W. Grimes * add "inuse/lock" bit (or ref. count) along with valid bit 37df8bae1dSRodney W. Grimes */ 38df8bae1dSRodney W. Grimes 391d5e9e22SEivind Eklund #include "opt_inet.h" 4019527d3eSRobert Watson #include "opt_mac.h" 41a9771948SGleb Smirnoff #include "opt_carp.h" 421d5e9e22SEivind Eklund 43df8bae1dSRodney W. Grimes #include <sys/param.h> 44df8bae1dSRodney W. Grimes #include <sys/kernel.h> 45ce02431fSDoug Rabson #include <sys/queue.h> 46885f1aa4SPoul-Henning Kamp #include <sys/sysctl.h> 47885f1aa4SPoul-Henning Kamp #include <sys/systm.h> 48885f1aa4SPoul-Henning Kamp #include <sys/mbuf.h> 49885f1aa4SPoul-Henning Kamp #include <sys/malloc.h> 504458ac71SBruce Evans #include <sys/socket.h> 51885f1aa4SPoul-Henning Kamp #include <sys/syslog.h> 52df8bae1dSRodney W. Grimes 53df8bae1dSRodney W. Grimes #include <net/if.h> 54df8bae1dSRodney W. Grimes #include <net/if_dl.h> 55722012ccSJulian Elischer #include <net/if_types.h> 56df8bae1dSRodney W. Grimes #include <net/route.h> 57748e0b0aSGarrett Wollman #include <net/netisr.h> 58b149dd6cSLarry Lile #include <net/if_llc.h> 59c8f8e9c1SJulian Elischer #include <net/ethernet.h> 60df8bae1dSRodney W. Grimes 61df8bae1dSRodney W. Grimes #include <netinet/in.h> 62df8bae1dSRodney W. Grimes #include <netinet/in_var.h> 63df8bae1dSRodney W. Grimes #include <netinet/if_ether.h> 64df8bae1dSRodney W. Grimes 65322dcb8dSMax Khon #include <net/if_arc.h> 66fda82fc2SJulian Elischer #include <net/iso88025.h> 67fda82fc2SJulian Elischer 68a9771948SGleb Smirnoff #ifdef DEV_CARP 69a9771948SGleb Smirnoff #include <netinet/ip_carp.h> 70a9771948SGleb Smirnoff #endif 71a9771948SGleb Smirnoff 72aed55708SRobert Watson #include <security/mac/mac_framework.h> 73aed55708SRobert Watson 74df8bae1dSRodney W. Grimes #define SIN(s) ((struct sockaddr_in *)s) 75df8bae1dSRodney W. Grimes #define SDL(s) ((struct sockaddr_dl *)s) 76df8bae1dSRodney W. Grimes 77ce02431fSDoug Rabson SYSCTL_DECL(_net_link_ether); 78602d513cSGarrett Wollman SYSCTL_NODE(_net_link_ether, PF_INET, inet, CTLFLAG_RW, 0, ""); 79df8bae1dSRodney W. Grimes 80df8bae1dSRodney W. Grimes /* timer values */ 81602d513cSGarrett Wollman static int arpt_prune = (5*60*1); /* walk list every 5 minutes */ 82602d513cSGarrett Wollman static int arpt_keep = (20*60); /* once resolved, good for 20 more minutes */ 83885f1aa4SPoul-Henning Kamp 84602d513cSGarrett Wollman SYSCTL_INT(_net_link_ether_inet, OID_AUTO, prune_intvl, CTLFLAG_RW, 85bd2b686fSEd Maste &arpt_prune, 0, "ARP table prune interval in seconds"); 86602d513cSGarrett Wollman SYSCTL_INT(_net_link_ether_inet, OID_AUTO, max_age, CTLFLAG_RW, 87bd2b686fSEd Maste &arpt_keep, 0, "ARP entry lifetime in seconds"); 88885f1aa4SPoul-Henning Kamp 89df8bae1dSRodney W. Grimes #define rt_expire rt_rmx.rmx_expire 90df8bae1dSRodney W. Grimes 9166800f57SGarrett Wollman struct llinfo_arp { 92e3975643SJake Burkholder LIST_ENTRY(llinfo_arp) la_le; 9366800f57SGarrett Wollman struct rtentry *la_rt; 9466800f57SGarrett Wollman struct mbuf *la_hold; /* last packet until resolved/timeout */ 95022695f8SOrion Hodson u_short la_preempt; /* countdown for pre-expiry arps */ 96e1ff74c5SGleb Smirnoff u_short la_asked; /* # requests sent */ 9766800f57SGarrett Wollman }; 9866800f57SGarrett Wollman 99e3975643SJake Burkholder static LIST_HEAD(, llinfo_arp) llinfo_arp; 100df8bae1dSRodney W. Grimes 1011cafed39SJonathan Lemon static struct ifqueue arpintrq; 102d1dd20beSSam Leffler static int arp_allocated; 103df8bae1dSRodney W. Grimes 104885f1aa4SPoul-Henning Kamp static int arp_maxtries = 5; 105602d513cSGarrett Wollman static int useloopback = 1; /* use loopback interface for local traffic */ 106885f1aa4SPoul-Henning Kamp static int arp_proxyall = 0; 107d1dd20beSSam Leffler static struct callout arp_callout; 108602d513cSGarrett Wollman 109602d513cSGarrett Wollman SYSCTL_INT(_net_link_ether_inet, OID_AUTO, maxtries, CTLFLAG_RW, 110bd2b686fSEd Maste &arp_maxtries, 0, "ARP resolution attempts before returning error"); 111602d513cSGarrett Wollman SYSCTL_INT(_net_link_ether_inet, OID_AUTO, useloopback, CTLFLAG_RW, 112bd2b686fSEd Maste &useloopback, 0, "Use the loopback interface for local traffic"); 113602d513cSGarrett Wollman SYSCTL_INT(_net_link_ether_inet, OID_AUTO, proxyall, CTLFLAG_RW, 114bd2b686fSEd Maste &arp_proxyall, 0, "Enable proxy ARP for all suitable requests"); 115885f1aa4SPoul-Henning Kamp 1164d77a549SAlfred Perlstein static void arp_init(void); 1174d77a549SAlfred Perlstein static void arp_rtrequest(int, struct rtentry *, struct rt_addrinfo *); 1184d77a549SAlfred Perlstein static void arprequest(struct ifnet *, 1194d77a549SAlfred Perlstein struct in_addr *, struct in_addr *, u_char *); 1201cafed39SJonathan Lemon static void arpintr(struct mbuf *); 1214d77a549SAlfred Perlstein static void arptimer(void *); 1221ed7bf1eSGleb Smirnoff static struct rtentry 1234d77a549SAlfred Perlstein *arplookup(u_long, int, int); 1241d5e9e22SEivind Eklund #ifdef INET 1254d77a549SAlfred Perlstein static void in_arpinput(struct mbuf *); 1261d5e9e22SEivind Eklund #endif 12728e82295SGarrett Wollman 128df8bae1dSRodney W. Grimes /* 129df8bae1dSRodney W. Grimes * Timeout routine. Age arp_tab entries periodically. 130df8bae1dSRodney W. Grimes */ 131df8bae1dSRodney W. Grimes /* ARGSUSED */ 132df8bae1dSRodney W. Grimes static void 1331ed7bf1eSGleb Smirnoff arptimer(void * __unused unused) 134df8bae1dSRodney W. Grimes { 135c996428cSJeffrey Hsu struct llinfo_arp *la, *ola; 136df8bae1dSRodney W. Grimes 13793f79889SJeffrey Hsu RADIX_NODE_HEAD_LOCK(rt_tables[AF_INET]); 1381ed7bf1eSGleb Smirnoff LIST_FOREACH_SAFE(la, &llinfo_arp, la_le, ola) { 139c996428cSJeffrey Hsu struct rtentry *rt = la->la_rt; 1401ed7bf1eSGleb Smirnoff 1411ed7bf1eSGleb Smirnoff RT_LOCK(rt); 142fe53256dSAndre Oppermann if (rt->rt_expire && rt->rt_expire <= time_uptime) { 1431ed7bf1eSGleb Smirnoff struct sockaddr_dl *sdl = SDL(rt->rt_gateway); 1441ed7bf1eSGleb Smirnoff 1451ed7bf1eSGleb Smirnoff KASSERT(sdl->sdl_family == AF_LINK, ("sdl_family %d", 1461ed7bf1eSGleb Smirnoff sdl->sdl_family)); 1471ed7bf1eSGleb Smirnoff if (rt->rt_refcnt > 1) { 1481ed7bf1eSGleb Smirnoff sdl->sdl_alen = 0; 1491ed7bf1eSGleb Smirnoff la->la_preempt = la->la_asked = 0; 1501ed7bf1eSGleb Smirnoff RT_UNLOCK(rt); 1511ed7bf1eSGleb Smirnoff continue; 1521ed7bf1eSGleb Smirnoff } 1531ed7bf1eSGleb Smirnoff RT_UNLOCK(rt); 1541ed7bf1eSGleb Smirnoff /* 1551ed7bf1eSGleb Smirnoff * XXX: LIST_REMOVE() is deep inside rtrequest(). 1561ed7bf1eSGleb Smirnoff */ 1571ed7bf1eSGleb Smirnoff rtrequest(RTM_DELETE, rt_key(rt), NULL, rt_mask(rt), 0, 1581ed7bf1eSGleb Smirnoff NULL); 1591ed7bf1eSGleb Smirnoff continue; 1601ed7bf1eSGleb Smirnoff } 1611ed7bf1eSGleb Smirnoff RT_UNLOCK(rt); 162df8bae1dSRodney W. Grimes } 16393f79889SJeffrey Hsu RADIX_NODE_HEAD_UNLOCK(rt_tables[AF_INET]); 164d1dd20beSSam Leffler 165d1dd20beSSam Leffler callout_reset(&arp_callout, arpt_prune * hz, arptimer, NULL); 166df8bae1dSRodney W. Grimes } 167df8bae1dSRodney W. Grimes 168df8bae1dSRodney W. Grimes /* 169df8bae1dSRodney W. Grimes * Parallel to llc_rtrequest. 170df8bae1dSRodney W. Grimes */ 171b2774d00SGarrett Wollman static void 1728071913dSRuslan Ermilov arp_rtrequest(req, rt, info) 173df8bae1dSRodney W. Grimes int req; 174e952fa39SMatthew N. Dodd struct rtentry *rt; 1758071913dSRuslan Ermilov struct rt_addrinfo *info; 176df8bae1dSRodney W. Grimes { 177e952fa39SMatthew N. Dodd struct sockaddr *gate; 178e952fa39SMatthew N. Dodd struct llinfo_arp *la; 179df8bae1dSRodney W. Grimes static struct sockaddr_dl null_sdl = {sizeof(null_sdl), AF_LINK}; 180067a8babSMax Laier struct in_ifaddr *ia; 181067a8babSMax Laier struct ifaddr *ifa; 182df8bae1dSRodney W. Grimes 183d1dd20beSSam Leffler RT_LOCK_ASSERT(rt); 184d1dd20beSSam Leffler 185df8bae1dSRodney W. Grimes if (rt->rt_flags & RTF_GATEWAY) 186df8bae1dSRodney W. Grimes return; 187d1dd20beSSam Leffler gate = rt->rt_gateway; 188d1dd20beSSam Leffler la = (struct llinfo_arp *)rt->rt_llinfo; 189df8bae1dSRodney W. Grimes switch (req) { 190df8bae1dSRodney W. Grimes 191df8bae1dSRodney W. Grimes case RTM_ADD: 192df8bae1dSRodney W. Grimes /* 193df8bae1dSRodney W. Grimes * XXX: If this is a manually added route to interface 194df8bae1dSRodney W. Grimes * such as older version of routed or gated might provide, 195df8bae1dSRodney W. Grimes * restore cloning bit. 196df8bae1dSRodney W. Grimes */ 197df8bae1dSRodney W. Grimes if ((rt->rt_flags & RTF_HOST) == 0 && 198d6fa5d28SBruce M Simpson rt_mask(rt) != NULL && 199df8bae1dSRodney W. Grimes SIN(rt_mask(rt))->sin_addr.s_addr != 0xffffffff) 200df8bae1dSRodney W. Grimes rt->rt_flags |= RTF_CLONING; 201df8bae1dSRodney W. Grimes if (rt->rt_flags & RTF_CLONING) { 202df8bae1dSRodney W. Grimes /* 203df8bae1dSRodney W. Grimes * Case 1: This route should come from a route to iface. 204df8bae1dSRodney W. Grimes */ 205df8bae1dSRodney W. Grimes rt_setgate(rt, rt_key(rt), 206df8bae1dSRodney W. Grimes (struct sockaddr *)&null_sdl); 207df8bae1dSRodney W. Grimes gate = rt->rt_gateway; 208df8bae1dSRodney W. Grimes SDL(gate)->sdl_type = rt->rt_ifp->if_type; 209df8bae1dSRodney W. Grimes SDL(gate)->sdl_index = rt->rt_ifp->if_index; 210fe53256dSAndre Oppermann rt->rt_expire = time_uptime; 211df8bae1dSRodney W. Grimes break; 212df8bae1dSRodney W. Grimes } 213df8bae1dSRodney W. Grimes /* Announce a new entry if requested. */ 214df8bae1dSRodney W. Grimes if (rt->rt_flags & RTF_ANNOUNCE) 215322dcb8dSMax Khon arprequest(rt->rt_ifp, 216ed7509acSJulian Elischer &SIN(rt_key(rt))->sin_addr, 217ed7509acSJulian Elischer &SIN(rt_key(rt))->sin_addr, 218df8bae1dSRodney W. Grimes (u_char *)LLADDR(SDL(gate))); 219df8bae1dSRodney W. Grimes /*FALLTHROUGH*/ 220df8bae1dSRodney W. Grimes case RTM_RESOLVE: 221df8bae1dSRodney W. Grimes if (gate->sa_family != AF_LINK || 222df8bae1dSRodney W. Grimes gate->sa_len < sizeof(null_sdl)) { 223d1dd20beSSam Leffler log(LOG_DEBUG, "%s: bad gateway %s%s\n", __func__, 224beb2ced8SBruce M Simpson inet_ntoa(SIN(rt_key(rt))->sin_addr), 225beb2ced8SBruce M Simpson (gate->sa_family != AF_LINK) ? 226c3b52d64SBruce M Simpson " (!AF_LINK)": ""); 227df8bae1dSRodney W. Grimes break; 228df8bae1dSRodney W. Grimes } 229df8bae1dSRodney W. Grimes SDL(gate)->sdl_type = rt->rt_ifp->if_type; 230df8bae1dSRodney W. Grimes SDL(gate)->sdl_index = rt->rt_ifp->if_index; 231df8bae1dSRodney W. Grimes if (la != 0) 232df8bae1dSRodney W. Grimes break; /* This happens on a route change */ 233df8bae1dSRodney W. Grimes /* 234df8bae1dSRodney W. Grimes * Case 2: This route may come from cloning, or a manual route 235df8bae1dSRodney W. Grimes * add with a LL address. 236df8bae1dSRodney W. Grimes */ 237d1dd20beSSam Leffler R_Zalloc(la, struct llinfo_arp *, sizeof(*la)); 238df8bae1dSRodney W. Grimes rt->rt_llinfo = (caddr_t)la; 239df8bae1dSRodney W. Grimes if (la == 0) { 240d1dd20beSSam Leffler log(LOG_DEBUG, "%s: malloc failed\n", __func__); 241df8bae1dSRodney W. Grimes break; 242df8bae1dSRodney W. Grimes } 243d1dd20beSSam Leffler arp_allocated++; 2441ed7bf1eSGleb Smirnoff /* 2451ed7bf1eSGleb Smirnoff * We are storing a route entry outside of radix tree. So, 2461ed7bf1eSGleb Smirnoff * it can be found and accessed by other means than radix 2471ed7bf1eSGleb Smirnoff * lookup. The routing code assumes that any rtentry detached 2481ed7bf1eSGleb Smirnoff * from radix can be destroyed safely. To prevent this, we 2491ed7bf1eSGleb Smirnoff * add an additional reference. 2501ed7bf1eSGleb Smirnoff */ 2511ed7bf1eSGleb Smirnoff RT_ADDREF(rt); 252df8bae1dSRodney W. Grimes la->la_rt = rt; 253df8bae1dSRodney W. Grimes rt->rt_flags |= RTF_LLINFO; 25493f79889SJeffrey Hsu RADIX_NODE_HEAD_LOCK_ASSERT(rt_tables[AF_INET]); 25566800f57SGarrett Wollman LIST_INSERT_HEAD(&llinfo_arp, la, la_le); 256cbb0b46aSGarrett Wollman 2571d5e9e22SEivind Eklund #ifdef INET 258cbb0b46aSGarrett Wollman /* 259cbb0b46aSGarrett Wollman * This keeps the multicast addresses from showing up 260cbb0b46aSGarrett Wollman * in `arp -a' listings as unresolved. It's not actually 261cbb0b46aSGarrett Wollman * functional. Then the same for broadcast. 262cbb0b46aSGarrett Wollman */ 263c448c89cSJonathan Lemon if (IN_MULTICAST(ntohl(SIN(rt_key(rt))->sin_addr.s_addr)) && 264c448c89cSJonathan Lemon rt->rt_ifp->if_type != IFT_ARCNET) { 265cbb0b46aSGarrett Wollman ETHER_MAP_IP_MULTICAST(&SIN(rt_key(rt))->sin_addr, 266cbb0b46aSGarrett Wollman LLADDR(SDL(gate))); 267cbb0b46aSGarrett Wollman SDL(gate)->sdl_alen = 6; 26851a109a1SPeter Wemm rt->rt_expire = 0; 269cbb0b46aSGarrett Wollman } 270cbb0b46aSGarrett Wollman if (in_broadcast(SIN(rt_key(rt))->sin_addr, rt->rt_ifp)) { 271322dcb8dSMax Khon memcpy(LLADDR(SDL(gate)), rt->rt_ifp->if_broadcastaddr, 272322dcb8dSMax Khon rt->rt_ifp->if_addrlen); 273322dcb8dSMax Khon SDL(gate)->sdl_alen = rt->rt_ifp->if_addrlen; 27451a109a1SPeter Wemm rt->rt_expire = 0; 275cbb0b46aSGarrett Wollman } 2761d5e9e22SEivind Eklund #endif 277cbb0b46aSGarrett Wollman 278067a8babSMax Laier TAILQ_FOREACH(ia, &in_ifaddrhead, ia_link) { 279067a8babSMax Laier if (ia->ia_ifp == rt->rt_ifp && 280067a8babSMax Laier SIN(rt_key(rt))->sin_addr.s_addr == 281067a8babSMax Laier (IA_SIN(ia))->sin_addr.s_addr) 282067a8babSMax Laier break; 283067a8babSMax Laier } 284067a8babSMax Laier if (ia) { 285df8bae1dSRodney W. Grimes /* 286df8bae1dSRodney W. Grimes * This test used to be 287df8bae1dSRodney W. Grimes * if (loif.if_flags & IFF_UP) 288df8bae1dSRodney W. Grimes * It allowed local traffic to be forced 289df8bae1dSRodney W. Grimes * through the hardware by configuring the loopback down. 290df8bae1dSRodney W. Grimes * However, it causes problems during network configuration 291df8bae1dSRodney W. Grimes * for boards that can't receive packets they send. 292df8bae1dSRodney W. Grimes * It is now necessary to clear "useloopback" and remove 293df8bae1dSRodney W. Grimes * the route to force traffic out to the hardware. 294df8bae1dSRodney W. Grimes */ 295df8bae1dSRodney W. Grimes rt->rt_expire = 0; 296ac912b2dSLuigi Rizzo bcopy(IF_LLADDR(rt->rt_ifp), LLADDR(SDL(gate)), 297322dcb8dSMax Khon SDL(gate)->sdl_alen = rt->rt_ifp->if_addrlen); 298402865f6SJohn-Mark Gurney if (useloopback) { 299f5fea3ddSPaul Traina rt->rt_ifp = loif; 300402865f6SJohn-Mark Gurney rt->rt_rmx.rmx_mtu = loif->if_mtu; 301402865f6SJohn-Mark Gurney } 302df8bae1dSRodney W. Grimes 303067a8babSMax Laier /* 304067a8babSMax Laier * make sure to set rt->rt_ifa to the interface 305067a8babSMax Laier * address we are using, otherwise we will have trouble 306067a8babSMax Laier * with source address selection. 307067a8babSMax Laier */ 308067a8babSMax Laier ifa = &ia->ia_ifa; 309067a8babSMax Laier if (ifa != rt->rt_ifa) { 310067a8babSMax Laier IFAFREE(rt->rt_ifa); 311067a8babSMax Laier IFAREF(ifa); 312067a8babSMax Laier rt->rt_ifa = ifa; 313067a8babSMax Laier } 314df8bae1dSRodney W. Grimes } 315df8bae1dSRodney W. Grimes break; 316df8bae1dSRodney W. Grimes 317df8bae1dSRodney W. Grimes case RTM_DELETE: 318df8bae1dSRodney W. Grimes if (la == 0) 319df8bae1dSRodney W. Grimes break; 32093f79889SJeffrey Hsu RADIX_NODE_HEAD_LOCK_ASSERT(rt_tables[AF_INET]); 32166800f57SGarrett Wollman LIST_REMOVE(la, la_le); 3221ed7bf1eSGleb Smirnoff RT_REMREF(rt); 323df8bae1dSRodney W. Grimes rt->rt_llinfo = 0; 324df8bae1dSRodney W. Grimes rt->rt_flags &= ~RTF_LLINFO; 325df8bae1dSRodney W. Grimes if (la->la_hold) 326df8bae1dSRodney W. Grimes m_freem(la->la_hold); 327df8bae1dSRodney W. Grimes Free((caddr_t)la); 328df8bae1dSRodney W. Grimes } 329df8bae1dSRodney W. Grimes } 330df8bae1dSRodney W. Grimes 331df8bae1dSRodney W. Grimes /* 332df8bae1dSRodney W. Grimes * Broadcast an ARP request. Caller specifies: 333df8bae1dSRodney W. Grimes * - arp header source ip address 334df8bae1dSRodney W. Grimes * - arp header target ip address 335df8bae1dSRodney W. Grimes * - arp header source ethernet address 336df8bae1dSRodney W. Grimes */ 337df8bae1dSRodney W. Grimes static void 338322dcb8dSMax Khon arprequest(ifp, sip, tip, enaddr) 339e952fa39SMatthew N. Dodd struct ifnet *ifp; 340e952fa39SMatthew N. Dodd struct in_addr *sip, *tip; 341e952fa39SMatthew N. Dodd u_char *enaddr; 342df8bae1dSRodney W. Grimes { 343e952fa39SMatthew N. Dodd struct mbuf *m; 344e952fa39SMatthew N. Dodd struct arphdr *ah; 345df8bae1dSRodney W. Grimes struct sockaddr sa; 346df8bae1dSRodney W. Grimes 347a163d034SWarner Losh if ((m = m_gethdr(M_DONTWAIT, MT_DATA)) == NULL) 348df8bae1dSRodney W. Grimes return; 34964bf80ceSMatthew N. Dodd m->m_len = sizeof(*ah) + 2*sizeof(struct in_addr) + 35064bf80ceSMatthew N. Dodd 2*ifp->if_data.ifi_addrlen; 35164bf80ceSMatthew N. Dodd m->m_pkthdr.len = m->m_len; 35264bf80ceSMatthew N. Dodd MH_ALIGN(m, m->m_len); 35364bf80ceSMatthew N. Dodd ah = mtod(m, struct arphdr *); 35464bf80ceSMatthew N. Dodd bzero((caddr_t)ah, m->m_len); 35519527d3eSRobert Watson #ifdef MAC 35619527d3eSRobert Watson mac_create_mbuf_linklayer(ifp, m); 35719527d3eSRobert Watson #endif 358322dcb8dSMax Khon ah->ar_pro = htons(ETHERTYPE_IP); 359322dcb8dSMax Khon ah->ar_hln = ifp->if_addrlen; /* hardware address length */ 360322dcb8dSMax Khon ah->ar_pln = sizeof(struct in_addr); /* protocol address length */ 361322dcb8dSMax Khon ah->ar_op = htons(ARPOP_REQUEST); 36264bf80ceSMatthew N. Dodd bcopy((caddr_t)enaddr, (caddr_t)ar_sha(ah), ah->ar_hln); 36364bf80ceSMatthew N. Dodd bcopy((caddr_t)sip, (caddr_t)ar_spa(ah), ah->ar_pln); 36464bf80ceSMatthew N. Dodd bcopy((caddr_t)tip, (caddr_t)ar_tpa(ah), ah->ar_pln); 36564bf80ceSMatthew N. Dodd sa.sa_family = AF_ARP; 36664bf80ceSMatthew N. Dodd sa.sa_len = 2; 36764bf80ceSMatthew N. Dodd m->m_flags |= M_BCAST; 368322dcb8dSMax Khon (*ifp->if_output)(ifp, m, &sa, (struct rtentry *)0); 36964bf80ceSMatthew N. Dodd 37064bf80ceSMatthew N. Dodd return; 371df8bae1dSRodney W. Grimes } 372df8bae1dSRodney W. Grimes 373df8bae1dSRodney W. Grimes /* 374cd46a114SLuigi Rizzo * Resolve an IP address into an ethernet address. 375cd46a114SLuigi Rizzo * On input: 376cd46a114SLuigi Rizzo * ifp is the interface we use 377cd46a114SLuigi Rizzo * dst is the next hop, 378cd46a114SLuigi Rizzo * rt0 is the route to the final destination (possibly useless) 379cd46a114SLuigi Rizzo * m is the mbuf 380cd46a114SLuigi Rizzo * desten is where we want the address. 381cd46a114SLuigi Rizzo * 382cd46a114SLuigi Rizzo * On success, desten is filled in and the function returns 0; 383cd46a114SLuigi Rizzo * If the packet must be held pending resolution, we return EWOULDBLOCK 384cd46a114SLuigi Rizzo * On other errors, we return the corresponding error code. 385df8bae1dSRodney W. Grimes */ 386df8bae1dSRodney W. Grimes int 387cd46a114SLuigi Rizzo arpresolve(struct ifnet *ifp, struct rtentry *rt0, struct mbuf *m, 388f7c5baa1SLuigi Rizzo struct sockaddr *dst, u_char *desten) 389df8bae1dSRodney W. Grimes { 3901ed7bf1eSGleb Smirnoff struct llinfo_arp *la = NULL; 3911ed7bf1eSGleb Smirnoff struct rtentry *rt = NULL; 392df8bae1dSRodney W. Grimes struct sockaddr_dl *sdl; 393cd46a114SLuigi Rizzo int error; 394df8bae1dSRodney W. Grimes 395df8bae1dSRodney W. Grimes if (m->m_flags & M_BCAST) { /* broadcast */ 396322dcb8dSMax Khon (void)memcpy(desten, ifp->if_broadcastaddr, ifp->if_addrlen); 397cd46a114SLuigi Rizzo return (0); 398df8bae1dSRodney W. Grimes } 399322dcb8dSMax Khon if (m->m_flags & M_MCAST && ifp->if_type != IFT_ARCNET) {/* multicast */ 400df8bae1dSRodney W. Grimes ETHER_MAP_IP_MULTICAST(&SIN(dst)->sin_addr, desten); 401cd46a114SLuigi Rizzo return (0); 402df8bae1dSRodney W. Grimes } 4031ed7bf1eSGleb Smirnoff 4041ed7bf1eSGleb Smirnoff if (rt0 != NULL) { 4051ed7bf1eSGleb Smirnoff error = rt_check(&rt, &rt0, dst); 4061ed7bf1eSGleb Smirnoff if (error) { 4071ed7bf1eSGleb Smirnoff m_freem(m); 4081ed7bf1eSGleb Smirnoff return error; 409df8bae1dSRodney W. Grimes } 4101ed7bf1eSGleb Smirnoff la = (struct llinfo_arp *)rt->rt_llinfo; 4111ed7bf1eSGleb Smirnoff if (la == NULL) 4121ed7bf1eSGleb Smirnoff RT_UNLOCK(rt); 4131ed7bf1eSGleb Smirnoff } 4141ed7bf1eSGleb Smirnoff if (la == NULL) { 4151ed7bf1eSGleb Smirnoff /* 4161ed7bf1eSGleb Smirnoff * We enter this block in case if rt0 was NULL, 4171ed7bf1eSGleb Smirnoff * or if rt found by rt_check() didn't have llinfo. 4181ed7bf1eSGleb Smirnoff */ 4191ed7bf1eSGleb Smirnoff rt = arplookup(SIN(dst)->sin_addr.s_addr, 1, 0); 4201ed7bf1eSGleb Smirnoff if (rt == NULL) { 4211ed7bf1eSGleb Smirnoff log(LOG_DEBUG, 4221ed7bf1eSGleb Smirnoff "arpresolve: can't allocate route for %s\n", 4231ed7bf1eSGleb Smirnoff inet_ntoa(SIN(dst)->sin_addr)); 424df8bae1dSRodney W. Grimes m_freem(m); 425cd46a114SLuigi Rizzo return (EINVAL); /* XXX */ 426df8bae1dSRodney W. Grimes } 4271ed7bf1eSGleb Smirnoff la = (struct llinfo_arp *)rt->rt_llinfo; 4281ed7bf1eSGleb Smirnoff if (la == NULL) { 4291ed7bf1eSGleb Smirnoff RT_UNLOCK(rt); 4301ed7bf1eSGleb Smirnoff log(LOG_DEBUG, 4311ed7bf1eSGleb Smirnoff "arpresolve: can't allocate llinfo for %s\n", 4321ed7bf1eSGleb Smirnoff inet_ntoa(SIN(dst)->sin_addr)); 4331ed7bf1eSGleb Smirnoff m_freem(m); 4341ed7bf1eSGleb Smirnoff return (EINVAL); /* XXX */ 4351ed7bf1eSGleb Smirnoff } 4361ed7bf1eSGleb Smirnoff } 437df8bae1dSRodney W. Grimes sdl = SDL(rt->rt_gateway); 438df8bae1dSRodney W. Grimes /* 439df8bae1dSRodney W. Grimes * Check the address family and length is valid, the address 440df8bae1dSRodney W. Grimes * is resolved; otherwise, try to resolve. 441df8bae1dSRodney W. Grimes */ 442fe53256dSAndre Oppermann if ((rt->rt_expire == 0 || rt->rt_expire > time_uptime) && 443df8bae1dSRodney W. Grimes sdl->sdl_family == AF_LINK && sdl->sdl_alen != 0) { 444a20e2538SGleb Smirnoff 445a20e2538SGleb Smirnoff bcopy(LLADDR(sdl), desten, sdl->sdl_alen); 446a20e2538SGleb Smirnoff 447f0f3379eSOrion Hodson /* 448f0f3379eSOrion Hodson * If entry has an expiry time and it is approaching, 449e1ff74c5SGleb Smirnoff * send an ARP request. 450f0f3379eSOrion Hodson */ 451f0f3379eSOrion Hodson if ((rt->rt_expire != 0) && 452fe53256dSAndre Oppermann (time_uptime + la->la_preempt > rt->rt_expire)) { 453a20e2538SGleb Smirnoff struct in_addr sin = 454a20e2538SGleb Smirnoff SIN(rt->rt_ifa->ifa_addr)->sin_addr; 455a20e2538SGleb Smirnoff 456022695f8SOrion Hodson la->la_preempt--; 457a20e2538SGleb Smirnoff RT_UNLOCK(rt); 458a20e2538SGleb Smirnoff arprequest(ifp, &sin, &SIN(dst)->sin_addr, 459a20e2538SGleb Smirnoff IF_LLADDR(ifp)); 460a20e2538SGleb Smirnoff return (0); 461f0f3379eSOrion Hodson } 462f0f3379eSOrion Hodson 4631ed7bf1eSGleb Smirnoff RT_UNLOCK(rt); 464cd46a114SLuigi Rizzo return (0); 465df8bae1dSRodney W. Grimes } 466df8bae1dSRodney W. Grimes /* 467deb62e28SRuslan Ermilov * If ARP is disabled or static on this interface, stop. 46808aadfbbSJonathan Lemon * XXX 46908aadfbbSJonathan Lemon * Probably should not allocate empty llinfo struct if we are 47008aadfbbSJonathan Lemon * not going to be sending out an arp request. 47108aadfbbSJonathan Lemon */ 472deb62e28SRuslan Ermilov if (ifp->if_flags & (IFF_NOARP | IFF_STATICARP)) { 4731ed7bf1eSGleb Smirnoff RT_UNLOCK(rt); 47447891de1SRuslan Ermilov m_freem(m); 475cd46a114SLuigi Rizzo return (EINVAL); 47647891de1SRuslan Ermilov } 47708aadfbbSJonathan Lemon /* 478df8bae1dSRodney W. Grimes * There is an arptab entry, but no ethernet address 479df8bae1dSRodney W. Grimes * response yet. Replace the held mbuf with this 480df8bae1dSRodney W. Grimes * latest one. 481df8bae1dSRodney W. Grimes */ 482df8bae1dSRodney W. Grimes if (la->la_hold) 483df8bae1dSRodney W. Grimes m_freem(la->la_hold); 484df8bae1dSRodney W. Grimes la->la_hold = m; 485e1ff74c5SGleb Smirnoff 486e1ff74c5SGleb Smirnoff KASSERT(rt->rt_expire > 0, ("sending ARP request for static entry")); 487e1ff74c5SGleb Smirnoff 488e1ff74c5SGleb Smirnoff /* 489e1ff74c5SGleb Smirnoff * Return EWOULDBLOCK if we have tried less than arp_maxtries. It 490e1ff74c5SGleb Smirnoff * will be masked by ether_output(). Return EHOSTDOWN/EHOSTUNREACH 491e1ff74c5SGleb Smirnoff * if we have already sent arp_maxtries ARP requests. Retransmit the 492e1ff74c5SGleb Smirnoff * ARP request, but not faster than one request per second. 493e1ff74c5SGleb Smirnoff */ 494e1ff74c5SGleb Smirnoff if (la->la_asked < arp_maxtries) 495e1ff74c5SGleb Smirnoff error = EWOULDBLOCK; /* First request. */ 496e1ff74c5SGleb Smirnoff else 497e1ff74c5SGleb Smirnoff error = (rt == rt0) ? EHOSTDOWN : EHOSTUNREACH; 498e1ff74c5SGleb Smirnoff 49995ebcabeSMaxim Konovalov if (la->la_asked == 0 || rt->rt_expire != time_uptime) { 500a20e2538SGleb Smirnoff struct in_addr sin = 501a20e2538SGleb Smirnoff SIN(rt->rt_ifa->ifa_addr)->sin_addr; 502a20e2538SGleb Smirnoff 503e1ff74c5SGleb Smirnoff rt->rt_expire = time_uptime; 50495ebcabeSMaxim Konovalov la->la_asked++; 505a20e2538SGleb Smirnoff RT_UNLOCK(rt); 506e1ff74c5SGleb Smirnoff 507a20e2538SGleb Smirnoff arprequest(ifp, &sin, &SIN(dst)->sin_addr, 508322dcb8dSMax Khon IF_LLADDR(ifp)); 509e1ff74c5SGleb Smirnoff } else 5101ed7bf1eSGleb Smirnoff RT_UNLOCK(rt); 511e1ff74c5SGleb Smirnoff 512e1ff74c5SGleb Smirnoff return (error); 513df8bae1dSRodney W. Grimes } 514df8bae1dSRodney W. Grimes 515df8bae1dSRodney W. Grimes /* 516df8bae1dSRodney W. Grimes * Common length and type checks are done here, 517df8bae1dSRodney W. Grimes * then the protocol-specific routine is called. 518df8bae1dSRodney W. Grimes */ 519885f1aa4SPoul-Henning Kamp static void 5201cafed39SJonathan Lemon arpintr(struct mbuf *m) 521df8bae1dSRodney W. Grimes { 5221cafed39SJonathan Lemon struct arphdr *ar; 523df8bae1dSRodney W. Grimes 52476ec7b2fSRobert Watson if (m->m_len < sizeof(struct arphdr) && 52584365e2bSMatthew Dillon ((m = m_pullup(m, sizeof(struct arphdr))) == NULL)) { 526e44d6283SJoerg Wunsch log(LOG_ERR, "arp: runt packet -- m_pullup failed\n"); 5271cafed39SJonathan Lemon return; 52876ec7b2fSRobert Watson } 52976ec7b2fSRobert Watson ar = mtod(m, struct arphdr *); 53076ec7b2fSRobert Watson 5311cafed39SJonathan Lemon if (ntohs(ar->ar_hrd) != ARPHRD_ETHER && 5321cafed39SJonathan Lemon ntohs(ar->ar_hrd) != ARPHRD_IEEE802 && 533b8b33234SDoug Rabson ntohs(ar->ar_hrd) != ARPHRD_ARCNET && 534b8b33234SDoug Rabson ntohs(ar->ar_hrd) != ARPHRD_IEEE1394) { 5351cafed39SJonathan Lemon log(LOG_ERR, "arp: unknown hardware address format (0x%2D)\n", 53676ec7b2fSRobert Watson (unsigned char *)&ar->ar_hrd, ""); 53776ec7b2fSRobert Watson m_freem(m); 5381cafed39SJonathan Lemon return; 53976ec7b2fSRobert Watson } 54076ec7b2fSRobert Watson 54131175791SRuslan Ermilov if (m->m_len < arphdr_len(ar)) { 54278e2d2bdSRuslan Ermilov if ((m = m_pullup(m, arphdr_len(ar))) == NULL) { 543f72d9d83SJoerg Wunsch log(LOG_ERR, "arp: runt packet\n"); 54476ec7b2fSRobert Watson m_freem(m); 5451cafed39SJonathan Lemon return; 54676ec7b2fSRobert Watson } 54778e2d2bdSRuslan Ermilov ar = mtod(m, struct arphdr *); 54878e2d2bdSRuslan Ermilov } 549df8bae1dSRodney W. Grimes 550df8bae1dSRodney W. Grimes switch (ntohs(ar->ar_pro)) { 5511d5e9e22SEivind Eklund #ifdef INET 552df8bae1dSRodney W. Grimes case ETHERTYPE_IP: 553df8bae1dSRodney W. Grimes in_arpinput(m); 5541cafed39SJonathan Lemon return; 5551d5e9e22SEivind Eklund #endif 556df8bae1dSRodney W. Grimes } 557df8bae1dSRodney W. Grimes m_freem(m); 558df8bae1dSRodney W. Grimes } 559df8bae1dSRodney W. Grimes 5601d5e9e22SEivind Eklund #ifdef INET 561df8bae1dSRodney W. Grimes /* 562df8bae1dSRodney W. Grimes * ARP for Internet protocols on 10 Mb/s Ethernet. 563df8bae1dSRodney W. Grimes * Algorithm is that given in RFC 826. 564df8bae1dSRodney W. Grimes * In addition, a sanity check is performed on the sender 565df8bae1dSRodney W. Grimes * protocol address, to catch impersonators. 566df8bae1dSRodney W. Grimes * We no longer handle negotiations for use of trailer protocol: 567df8bae1dSRodney W. Grimes * Formerly, ARP replied for protocol type ETHERTYPE_TRAIL sent 568df8bae1dSRodney W. Grimes * along with IP replies if we wanted trailers sent to us, 569df8bae1dSRodney W. Grimes * and also sent them in response to IP replies. 570df8bae1dSRodney W. Grimes * This allowed either end to announce the desire to receive 571df8bae1dSRodney W. Grimes * trailer packets. 572df8bae1dSRodney W. Grimes * We no longer reply to requests for ETHERTYPE_TRAIL protocol either, 573df8bae1dSRodney W. Grimes * but formerly didn't normally send requests. 574df8bae1dSRodney W. Grimes */ 5753269187dSAlfred Perlstein static int log_arp_wrong_iface = 1; 576e3d123d6SAlfred Perlstein static int log_arp_movements = 1; 57739393906SGleb Smirnoff static int log_arp_permanent_modify = 1; 5783269187dSAlfred Perlstein 5793269187dSAlfred Perlstein SYSCTL_INT(_net_link_ether_inet, OID_AUTO, log_arp_wrong_iface, CTLFLAG_RW, 5803269187dSAlfred Perlstein &log_arp_wrong_iface, 0, 5813269187dSAlfred Perlstein "log arp packets arriving on the wrong interface"); 582e3d123d6SAlfred Perlstein SYSCTL_INT(_net_link_ether_inet, OID_AUTO, log_arp_movements, CTLFLAG_RW, 583e3d123d6SAlfred Perlstein &log_arp_movements, 0, 58475ce3221SAlfred Perlstein "log arp replies from MACs different than the one in the cache"); 58539393906SGleb Smirnoff SYSCTL_INT(_net_link_ether_inet, OID_AUTO, log_arp_permanent_modify, CTLFLAG_RW, 58639393906SGleb Smirnoff &log_arp_permanent_modify, 0, 58739393906SGleb Smirnoff "log arp replies from MACs different than the one in the permanent arp entry"); 588e3d123d6SAlfred Perlstein 5893269187dSAlfred Perlstein 590df8bae1dSRodney W. Grimes static void 591df8bae1dSRodney W. Grimes in_arpinput(m) 592df8bae1dSRodney W. Grimes struct mbuf *m; 593df8bae1dSRodney W. Grimes { 594e952fa39SMatthew N. Dodd struct arphdr *ah; 595e952fa39SMatthew N. Dodd struct ifnet *ifp = m->m_pkthdr.rcvif; 5961ed7bf1eSGleb Smirnoff struct llinfo_arp *la; 597e952fa39SMatthew N. Dodd struct rtentry *rt; 598ca925d9cSJonathan Lemon struct ifaddr *ifa; 599ca925d9cSJonathan Lemon struct in_ifaddr *ia; 600df8bae1dSRodney W. Grimes struct sockaddr_dl *sdl; 601df8bae1dSRodney W. Grimes struct sockaddr sa; 602df8bae1dSRodney W. Grimes struct in_addr isaddr, itaddr, myaddr; 6031ed7bf1eSGleb Smirnoff struct mbuf *hold; 604a9771948SGleb Smirnoff u_int8_t *enaddr = NULL; 605b149dd6cSLarry Lile int op, rif_len; 606322dcb8dSMax Khon int req_len; 6078f867517SAndrew Thompson int bridged = 0; 608422a115aSGleb Smirnoff #ifdef DEV_CARP 6092ef4a436SGleb Smirnoff int carp_match = 0; 610422a115aSGleb Smirnoff #endif 611df8bae1dSRodney W. Grimes 61274948aa6SAndrew Thompson if (ifp->if_bridge) 6138f867517SAndrew Thompson bridged = 1; 6148f867517SAndrew Thompson 615322dcb8dSMax Khon req_len = arphdr_len2(ifp->if_addrlen, sizeof(struct in_addr)); 616322dcb8dSMax Khon if (m->m_len < req_len && (m = m_pullup(m, req_len)) == NULL) { 6174cbc8ad1SYaroslav Tykhiy log(LOG_ERR, "in_arp: runt packet -- m_pullup failed\n"); 6184cbc8ad1SYaroslav Tykhiy return; 6194cbc8ad1SYaroslav Tykhiy } 6204cbc8ad1SYaroslav Tykhiy 621322dcb8dSMax Khon ah = mtod(m, struct arphdr *); 622322dcb8dSMax Khon op = ntohs(ah->ar_op); 623322dcb8dSMax Khon (void)memcpy(&isaddr, ar_spa(ah), sizeof (isaddr)); 624322dcb8dSMax Khon (void)memcpy(&itaddr, ar_tpa(ah), sizeof (itaddr)); 62532439868SGleb Smirnoff 626ca925d9cSJonathan Lemon /* 627ca925d9cSJonathan Lemon * For a bridge, we want to check the address irrespective 628ca925d9cSJonathan Lemon * of the receive interface. (This will change slightly 629ca925d9cSJonathan Lemon * when we have clusters of interfaces). 630a9771948SGleb Smirnoff * If the interface does not match, but the recieving interface 631a9771948SGleb Smirnoff * is part of carp, we call carp_iamatch to see if this is a 632a9771948SGleb Smirnoff * request for the virtual host ip. 633a9771948SGleb Smirnoff * XXX: This is really ugly! 634ca925d9cSJonathan Lemon */ 6352ef4a436SGleb Smirnoff LIST_FOREACH(ia, INADDR_HASH(itaddr.s_addr), ia_hash) { 6367f2d8767SAndrew Thompson if (((bridged && ia->ia_ifp->if_bridge != NULL) || 637235073f4SAndrew Thompson (ia->ia_ifp == ifp)) && 6382ef4a436SGleb Smirnoff itaddr.s_addr == ia->ia_addr.sin_addr.s_addr) 639ca925d9cSJonathan Lemon goto match; 6402ef4a436SGleb Smirnoff #ifdef DEV_CARP 6412ef4a436SGleb Smirnoff if (ifp->if_carp != NULL && 6422ef4a436SGleb Smirnoff carp_iamatch(ifp->if_carp, ia, &isaddr, &enaddr) && 6432ef4a436SGleb Smirnoff itaddr.s_addr == ia->ia_addr.sin_addr.s_addr) { 6442ef4a436SGleb Smirnoff carp_match = 1; 6452ef4a436SGleb Smirnoff goto match; 6462ef4a436SGleb Smirnoff } 6472ef4a436SGleb Smirnoff #endif 6482ef4a436SGleb Smirnoff } 649ca925d9cSJonathan Lemon LIST_FOREACH(ia, INADDR_HASH(isaddr.s_addr), ia_hash) 6507f2d8767SAndrew Thompson if (((bridged && ia->ia_ifp->if_bridge != NULL) || 651235073f4SAndrew Thompson (ia->ia_ifp == ifp)) && 652ca925d9cSJonathan Lemon isaddr.s_addr == ia->ia_addr.sin_addr.s_addr) 653ca925d9cSJonathan Lemon goto match; 654ca925d9cSJonathan Lemon /* 655d8b84d9eSJonathan Lemon * No match, use the first inet address on the receive interface 656ca925d9cSJonathan Lemon * as a dummy address for the rest of the function. 657ca925d9cSJonathan Lemon */ 658d8b84d9eSJonathan Lemon TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) 6594b97d7afSYaroslav Tykhiy if (ifa->ifa_addr->sa_family == AF_INET) { 660ec691a10SJonathan Lemon ia = ifatoia(ifa); 661ec691a10SJonathan Lemon goto match; 662ec691a10SJonathan Lemon } 663ec691a10SJonathan Lemon /* 664ec691a10SJonathan Lemon * If bridging, fall back to using any inet address. 665ec691a10SJonathan Lemon */ 6668f867517SAndrew Thompson if (!bridged || (ia = TAILQ_FIRST(&in_ifaddrhead)) == NULL) 667b2a8ac7cSLuigi Rizzo goto drop; 668ca925d9cSJonathan Lemon match: 669a9771948SGleb Smirnoff if (!enaddr) 670a9771948SGleb Smirnoff enaddr = (u_int8_t *)IF_LLADDR(ifp); 671ca925d9cSJonathan Lemon myaddr = ia->ia_addr.sin_addr; 672a9771948SGleb Smirnoff if (!bcmp(ar_sha(ah), enaddr, ifp->if_addrlen)) 673b2a8ac7cSLuigi Rizzo goto drop; /* it's from me, ignore it. */ 674322dcb8dSMax Khon if (!bcmp(ar_sha(ah), ifp->if_broadcastaddr, ifp->if_addrlen)) { 675df8bae1dSRodney W. Grimes log(LOG_ERR, 676322dcb8dSMax Khon "arp: link address is broadcast for IP address %s!\n", 677ef0cdf33SGarrett Wollman inet_ntoa(isaddr)); 678b2a8ac7cSLuigi Rizzo goto drop; 679df8bae1dSRodney W. Grimes } 68000fcf9d1SRobert Watson /* 68100fcf9d1SRobert Watson * Warn if another host is using the same IP address, but only if the 68200fcf9d1SRobert Watson * IP address isn't 0.0.0.0, which is used for DHCP only, in which 68300fcf9d1SRobert Watson * case we suppress the warning to avoid false positive complaints of 68400fcf9d1SRobert Watson * potential misconfiguration. 68500fcf9d1SRobert Watson */ 686f69453caSAndrew Thompson if (!bridged && isaddr.s_addr == myaddr.s_addr && myaddr.s_addr != 0) { 687df8bae1dSRodney W. Grimes log(LOG_ERR, 688322dcb8dSMax Khon "arp: %*D is using my IP address %s!\n", 689322dcb8dSMax Khon ifp->if_addrlen, (u_char *)ar_sha(ah), ":", 690322dcb8dSMax Khon inet_ntoa(isaddr)); 691df8bae1dSRodney W. Grimes itaddr = myaddr; 692df8bae1dSRodney W. Grimes goto reply; 693df8bae1dSRodney W. Grimes } 694deb62e28SRuslan Ermilov if (ifp->if_flags & IFF_STATICARP) 695deb62e28SRuslan Ermilov goto reply; 6961ed7bf1eSGleb Smirnoff rt = arplookup(isaddr.s_addr, itaddr.s_addr == myaddr.s_addr, 0); 6971ed7bf1eSGleb Smirnoff if (rt != NULL) { 6981ed7bf1eSGleb Smirnoff la = (struct llinfo_arp *)rt->rt_llinfo; 6991ed7bf1eSGleb Smirnoff if (la == NULL) { 7001ed7bf1eSGleb Smirnoff RT_UNLOCK(rt); 7011ed7bf1eSGleb Smirnoff goto reply; 7021ed7bf1eSGleb Smirnoff } 7031ed7bf1eSGleb Smirnoff } else 7041ed7bf1eSGleb Smirnoff goto reply; 7051ed7bf1eSGleb Smirnoff 7061ed7bf1eSGleb Smirnoff /* The following is not an error when doing bridging. */ 7078f867517SAndrew Thompson if (!bridged && rt->rt_ifp != ifp 708422a115aSGleb Smirnoff #ifdef DEV_CARP 709422a115aSGleb Smirnoff && (ifp->if_type != IFT_CARP || !carp_match) 710422a115aSGleb Smirnoff #endif 711422a115aSGleb Smirnoff ) { 7123269187dSAlfred Perlstein if (log_arp_wrong_iface) 7139bf40edeSBrooks Davis log(LOG_ERR, "arp: %s is on %s but got reply from %*D on %s\n", 714dd9b6ddeSBill Fenner inet_ntoa(isaddr), 7159bf40edeSBrooks Davis rt->rt_ifp->if_xname, 716322dcb8dSMax Khon ifp->if_addrlen, (u_char *)ar_sha(ah), ":", 7179bf40edeSBrooks Davis ifp->if_xname); 7181ed7bf1eSGleb Smirnoff RT_UNLOCK(rt); 719dd9b6ddeSBill Fenner goto reply; 720dd9b6ddeSBill Fenner } 7211ed7bf1eSGleb Smirnoff sdl = SDL(rt->rt_gateway); 722df8bae1dSRodney W. Grimes if (sdl->sdl_alen && 723322dcb8dSMax Khon bcmp(ar_sha(ah), LLADDR(sdl), sdl->sdl_alen)) { 724e3d123d6SAlfred Perlstein if (rt->rt_expire) { 725e3d123d6SAlfred Perlstein if (log_arp_movements) 7269bf40edeSBrooks Davis log(LOG_INFO, "arp: %s moved from %*D to %*D on %s\n", 727322dcb8dSMax Khon inet_ntoa(isaddr), 728322dcb8dSMax Khon ifp->if_addrlen, (u_char *)LLADDR(sdl), ":", 729322dcb8dSMax Khon ifp->if_addrlen, (u_char *)ar_sha(ah), ":", 7309bf40edeSBrooks Davis ifp->if_xname); 731e3d123d6SAlfred Perlstein } else { 73239393906SGleb Smirnoff RT_UNLOCK(rt); 73339393906SGleb Smirnoff if (log_arp_permanent_modify) 73439393906SGleb Smirnoff log(LOG_ERR, "arp: %*D attempts to modify " 73539393906SGleb Smirnoff "permanent entry for %s on %s\n", 736322dcb8dSMax Khon ifp->if_addrlen, (u_char *)ar_sha(ah), ":", 7379bf40edeSBrooks Davis inet_ntoa(isaddr), ifp->if_xname); 738dd9b6ddeSBill Fenner goto reply; 739dd9b6ddeSBill Fenner } 740dfd5dee1SPeter Wemm } 741322dcb8dSMax Khon /* 742322dcb8dSMax Khon * sanity check for the address length. 743322dcb8dSMax Khon * XXX this does not work for protocols with variable address 744322dcb8dSMax Khon * length. -is 745322dcb8dSMax Khon */ 746322dcb8dSMax Khon if (sdl->sdl_alen && 747322dcb8dSMax Khon sdl->sdl_alen != ah->ar_hln) { 748322dcb8dSMax Khon log(LOG_WARNING, 749322dcb8dSMax Khon "arp from %*D: new addr len %d, was %d", 750322dcb8dSMax Khon ifp->if_addrlen, (u_char *) ar_sha(ah), ":", 751322dcb8dSMax Khon ah->ar_hln, sdl->sdl_alen); 752322dcb8dSMax Khon } 753322dcb8dSMax Khon if (ifp->if_addrlen != ah->ar_hln) { 754322dcb8dSMax Khon log(LOG_WARNING, 755322dcb8dSMax Khon "arp from %*D: addr len: new %d, i/f %d (ignored)", 756322dcb8dSMax Khon ifp->if_addrlen, (u_char *) ar_sha(ah), ":", 757322dcb8dSMax Khon ah->ar_hln, ifp->if_addrlen); 7581ed7bf1eSGleb Smirnoff RT_UNLOCK(rt); 759322dcb8dSMax Khon goto reply; 760322dcb8dSMax Khon } 761322dcb8dSMax Khon (void)memcpy(LLADDR(sdl), ar_sha(ah), 762322dcb8dSMax Khon sdl->sdl_alen = ah->ar_hln); 763243c4c6dSEivind Eklund /* 764243c4c6dSEivind Eklund * If we receive an arp from a token-ring station over 765243c4c6dSEivind Eklund * a token-ring nic then try to save the source 766243c4c6dSEivind Eklund * routing info. 767243c4c6dSEivind Eklund */ 768322dcb8dSMax Khon if (ifp->if_type == IFT_ISO88025) { 769f7a679b2SGleb Smirnoff struct iso88025_header *th = NULL; 770f7a679b2SGleb Smirnoff struct iso88025_sockaddr_dl_data *trld; 771f7a679b2SGleb Smirnoff 772fda82fc2SJulian Elischer th = (struct iso88025_header *)m->m_pkthdr.header; 77342fdfc12SKelly Yancey trld = SDL_ISO88025(sdl); 774b149dd6cSLarry Lile rif_len = TR_RCF_RIFLEN(th->rcf); 775b149dd6cSLarry Lile if ((th->iso88025_shost[0] & TR_RII) && 776b149dd6cSLarry Lile (rif_len > 2)) { 77742fdfc12SKelly Yancey trld->trld_rcf = th->rcf; 77842fdfc12SKelly Yancey trld->trld_rcf ^= htons(TR_RCF_DIR); 77942fdfc12SKelly Yancey memcpy(trld->trld_route, th->rd, rif_len - 2); 78042fdfc12SKelly Yancey trld->trld_rcf &= ~htons(TR_RCF_BCST_MASK); 781f9083fdbSLarry Lile /* 782f9083fdbSLarry Lile * Set up source routing information for 783f9083fdbSLarry Lile * reply packet (XXX) 784f9083fdbSLarry Lile */ 785b149dd6cSLarry Lile m->m_data -= rif_len; 786b149dd6cSLarry Lile m->m_len += rif_len; 787b149dd6cSLarry Lile m->m_pkthdr.len += rif_len; 788fda82fc2SJulian Elischer } else { 789b149dd6cSLarry Lile th->iso88025_shost[0] &= ~TR_RII; 790c3a2190cSKelly Yancey trld->trld_rcf = 0; 791fcf11853SLarry Lile } 792fda82fc2SJulian Elischer m->m_data -= 8; 793fda82fc2SJulian Elischer m->m_len += 8; 794fcf11853SLarry Lile m->m_pkthdr.len += 8; 79542fdfc12SKelly Yancey th->rcf = trld->trld_rcf; 796fda82fc2SJulian Elischer } 797df8bae1dSRodney W. Grimes if (rt->rt_expire) 798fe53256dSAndre Oppermann rt->rt_expire = time_uptime + arpt_keep; 799022695f8SOrion Hodson la->la_asked = 0; 800022695f8SOrion Hodson la->la_preempt = arp_maxtries; 8011ed7bf1eSGleb Smirnoff hold = la->la_hold; 8021ed7bf1eSGleb Smirnoff la->la_hold = NULL; 8031ed7bf1eSGleb Smirnoff RT_UNLOCK(rt); 8041ed7bf1eSGleb Smirnoff if (hold != NULL) 8051ed7bf1eSGleb Smirnoff (*ifp->if_output)(ifp, hold, rt_key(rt), rt); 8061ed7bf1eSGleb Smirnoff 807df8bae1dSRodney W. Grimes reply: 808b2a8ac7cSLuigi Rizzo if (op != ARPOP_REQUEST) 809b2a8ac7cSLuigi Rizzo goto drop; 810df8bae1dSRodney W. Grimes if (itaddr.s_addr == myaddr.s_addr) { 811df8bae1dSRodney W. Grimes /* I am the target */ 812322dcb8dSMax Khon (void)memcpy(ar_tha(ah), ar_sha(ah), ah->ar_hln); 813a9771948SGleb Smirnoff (void)memcpy(ar_sha(ah), enaddr, ah->ar_hln); 814df8bae1dSRodney W. Grimes } else { 8151ed7bf1eSGleb Smirnoff rt = arplookup(itaddr.s_addr, 0, SIN_PROXY); 8161ed7bf1eSGleb Smirnoff if (rt == NULL) { 81728e82295SGarrett Wollman struct sockaddr_in sin; 81828e82295SGarrett Wollman 819b2a8ac7cSLuigi Rizzo if (!arp_proxyall) 820b2a8ac7cSLuigi Rizzo goto drop; 82128e82295SGarrett Wollman 82228e82295SGarrett Wollman bzero(&sin, sizeof sin); 82328e82295SGarrett Wollman sin.sin_family = AF_INET; 82428e82295SGarrett Wollman sin.sin_len = sizeof sin; 82528e82295SGarrett Wollman sin.sin_addr = itaddr; 82628e82295SGarrett Wollman 82731246bc2SGarrett Wollman rt = rtalloc1((struct sockaddr *)&sin, 0, 0UL); 828b2a8ac7cSLuigi Rizzo if (!rt) 829b2a8ac7cSLuigi Rizzo goto drop; 83028e82295SGarrett Wollman /* 83128e82295SGarrett Wollman * Don't send proxies for nodes on the same interface 83228e82295SGarrett Wollman * as this one came out of, or we'll get into a fight 83328e82295SGarrett Wollman * over who claims what Ether address. 83428e82295SGarrett Wollman */ 835322dcb8dSMax Khon if (rt->rt_ifp == ifp) { 83628e82295SGarrett Wollman rtfree(rt); 837b2a8ac7cSLuigi Rizzo goto drop; 83828e82295SGarrett Wollman } 839322dcb8dSMax Khon (void)memcpy(ar_tha(ah), ar_sha(ah), ah->ar_hln); 840a9771948SGleb Smirnoff (void)memcpy(ar_sha(ah), enaddr, ah->ar_hln); 84128e82295SGarrett Wollman rtfree(rt); 842cc728227SDavid Malone 843cc728227SDavid Malone /* 844cc728227SDavid Malone * Also check that the node which sent the ARP packet 845cc728227SDavid Malone * is on the the interface we expect it to be on. This 846cc728227SDavid Malone * avoids ARP chaos if an interface is connected to the 847cc728227SDavid Malone * wrong network. 848cc728227SDavid Malone */ 849cc728227SDavid Malone sin.sin_addr = isaddr; 850cc728227SDavid Malone 851cc728227SDavid Malone rt = rtalloc1((struct sockaddr *)&sin, 0, 0UL); 852b2a8ac7cSLuigi Rizzo if (!rt) 853b2a8ac7cSLuigi Rizzo goto drop; 854322dcb8dSMax Khon if (rt->rt_ifp != ifp) { 855cc728227SDavid Malone log(LOG_INFO, "arp_proxy: ignoring request" 8569bf40edeSBrooks Davis " from %s via %s, expecting %s\n", 8579bf40edeSBrooks Davis inet_ntoa(isaddr), ifp->if_xname, 8589bf40edeSBrooks Davis rt->rt_ifp->if_xname); 859cc728227SDavid Malone rtfree(rt); 860b2a8ac7cSLuigi Rizzo goto drop; 861cc728227SDavid Malone } 862cc728227SDavid Malone rtfree(rt); 863cc728227SDavid Malone 864ac234f93SGarrett Wollman #ifdef DEBUG_PROXY 865ac234f93SGarrett Wollman printf("arp: proxying for %s\n", 866ef0cdf33SGarrett Wollman inet_ntoa(itaddr)); 867ac234f93SGarrett Wollman #endif 86828e82295SGarrett Wollman } else { 869510b360fSGleb Smirnoff /* 870510b360fSGleb Smirnoff * Return proxied ARP replies only on the interface 8715feebeebSAndrew Thompson * or bridge cluster where this network resides. 8725feebeebSAndrew Thompson * Otherwise we may conflict with the host we are 8735feebeebSAndrew Thompson * proxying for. 874510b360fSGleb Smirnoff */ 8755feebeebSAndrew Thompson if (rt->rt_ifp != ifp && 8765feebeebSAndrew Thompson (rt->rt_ifp->if_bridge != ifp->if_bridge || 8775feebeebSAndrew Thompson ifp->if_bridge == NULL)) { 878510b360fSGleb Smirnoff RT_UNLOCK(rt); 879510b360fSGleb Smirnoff goto drop; 880510b360fSGleb Smirnoff } 881df8bae1dSRodney W. Grimes sdl = SDL(rt->rt_gateway); 8821ed7bf1eSGleb Smirnoff (void)memcpy(ar_tha(ah), ar_sha(ah), ah->ar_hln); 883322dcb8dSMax Khon (void)memcpy(ar_sha(ah), LLADDR(sdl), ah->ar_hln); 8841ed7bf1eSGleb Smirnoff RT_UNLOCK(rt); 88528e82295SGarrett Wollman } 886df8bae1dSRodney W. Grimes } 887df8bae1dSRodney W. Grimes 888d0558157SBruce M Simpson if (itaddr.s_addr == myaddr.s_addr && 889d0558157SBruce M Simpson IN_LINKLOCAL(ntohl(itaddr.s_addr))) { 890d0558157SBruce M Simpson /* RFC 3927 link-local IPv4; always reply by broadcast. */ 891d0558157SBruce M Simpson #ifdef DEBUG_LINKLOCAL 892d0558157SBruce M Simpson printf("arp: sending reply for link-local addr %s\n", 893d0558157SBruce M Simpson inet_ntoa(itaddr)); 894d0558157SBruce M Simpson #endif 895d0558157SBruce M Simpson m->m_flags |= M_BCAST; 896d0558157SBruce M Simpson m->m_flags &= ~M_MCAST; 897d0558157SBruce M Simpson } else { 898d0558157SBruce M Simpson /* default behaviour; never reply by broadcast. */ 899d0558157SBruce M Simpson m->m_flags &= ~(M_BCAST|M_MCAST); 900d0558157SBruce M Simpson } 901322dcb8dSMax Khon (void)memcpy(ar_tpa(ah), ar_spa(ah), ah->ar_pln); 902322dcb8dSMax Khon (void)memcpy(ar_spa(ah), &itaddr, ah->ar_pln); 903322dcb8dSMax Khon ah->ar_op = htons(ARPOP_REPLY); 904322dcb8dSMax Khon ah->ar_pro = htons(ETHERTYPE_IP); /* let's be sure! */ 90564bf80ceSMatthew N. Dodd m->m_len = sizeof(*ah) + (2 * ah->ar_pln) + (2 * ah->ar_hln); 90664bf80ceSMatthew N. Dodd m->m_pkthdr.len = m->m_len; 90764bf80ceSMatthew N. Dodd sa.sa_family = AF_ARP; 90864bf80ceSMatthew N. Dodd sa.sa_len = 2; 909322dcb8dSMax Khon (*ifp->if_output)(ifp, m, &sa, (struct rtentry *)0); 910df8bae1dSRodney W. Grimes return; 911b2a8ac7cSLuigi Rizzo 912b2a8ac7cSLuigi Rizzo drop: 913b2a8ac7cSLuigi Rizzo m_freem(m); 914df8bae1dSRodney W. Grimes } 9151d5e9e22SEivind Eklund #endif 916df8bae1dSRodney W. Grimes 917df8bae1dSRodney W. Grimes /* 918df8bae1dSRodney W. Grimes * Lookup or enter a new address in arptab. 919df8bae1dSRodney W. Grimes */ 9201ed7bf1eSGleb Smirnoff static struct rtentry * 921df8bae1dSRodney W. Grimes arplookup(addr, create, proxy) 922df8bae1dSRodney W. Grimes u_long addr; 923df8bae1dSRodney W. Grimes int create, proxy; 924df8bae1dSRodney W. Grimes { 925e952fa39SMatthew N. Dodd struct rtentry *rt; 926d1dd20beSSam Leffler struct sockaddr_inarp sin; 927ac234f93SGarrett Wollman const char *why = 0; 928df8bae1dSRodney W. Grimes 929d1dd20beSSam Leffler bzero(&sin, sizeof(sin)); 930d1dd20beSSam Leffler sin.sin_len = sizeof(sin); 931d1dd20beSSam Leffler sin.sin_family = AF_INET; 932df8bae1dSRodney W. Grimes sin.sin_addr.s_addr = addr; 933d1dd20beSSam Leffler if (proxy) 934d1dd20beSSam Leffler sin.sin_other = SIN_PROXY; 93531246bc2SGarrett Wollman rt = rtalloc1((struct sockaddr *)&sin, create, 0UL); 936df8bae1dSRodney W. Grimes if (rt == 0) 937df8bae1dSRodney W. Grimes return (0); 938ac234f93SGarrett Wollman 939ac234f93SGarrett Wollman if (rt->rt_flags & RTF_GATEWAY) 940ac234f93SGarrett Wollman why = "host is not on local network"; 941ac234f93SGarrett Wollman else if ((rt->rt_flags & RTF_LLINFO) == 0) 942ac234f93SGarrett Wollman why = "could not allocate llinfo"; 943ac234f93SGarrett Wollman else if (rt->rt_gateway->sa_family != AF_LINK) 944ac234f93SGarrett Wollman why = "gateway route is not ours"; 945ac234f93SGarrett Wollman 946fedf1d01SBruce M Simpson if (why) { 947d1dd20beSSam Leffler #define ISDYNCLONE(_rt) \ 948d1dd20beSSam Leffler (((_rt)->rt_flags & (RTF_STATIC | RTF_WASCLONED)) == RTF_WASCLONED) 949d1dd20beSSam Leffler if (create) 950ac234f93SGarrett Wollman log(LOG_DEBUG, "arplookup %s failed: %s\n", 951ef0cdf33SGarrett Wollman inet_ntoa(sin.sin_addr), why); 952b75bead1SBruce M Simpson /* 953b75bead1SBruce M Simpson * If there are no references to this Layer 2 route, 954b75bead1SBruce M Simpson * and it is a cloned route, and not static, and 955b75bead1SBruce M Simpson * arplookup() is creating the route, then purge 956b75bead1SBruce M Simpson * it from the routing table as it is probably bogus. 957b75bead1SBruce M Simpson */ 9589c63e9dbSSam Leffler if (rt->rt_refcnt == 1 && ISDYNCLONE(rt)) 9599c63e9dbSSam Leffler rtexpunge(rt); 9609c63e9dbSSam Leffler RTFREE_LOCKED(rt); 961fedf1d01SBruce M Simpson return (0); 962d1dd20beSSam Leffler #undef ISDYNCLONE 963d1dd20beSSam Leffler } else { 9647138d65cSSam Leffler RT_REMREF(rt); 9651ed7bf1eSGleb Smirnoff return (rt); 966df8bae1dSRodney W. Grimes } 967d1dd20beSSam Leffler } 968df8bae1dSRodney W. Grimes 969dd2e4102SGarrett Wollman void 970322dcb8dSMax Khon arp_ifinit(ifp, ifa) 971322dcb8dSMax Khon struct ifnet *ifp; 972dd2e4102SGarrett Wollman struct ifaddr *ifa; 973dd2e4102SGarrett Wollman { 974dd570d4dSTor Egge if (ntohl(IA_SIN(ifa)->sin_addr.s_addr) != INADDR_ANY) 975322dcb8dSMax Khon arprequest(ifp, &IA_SIN(ifa)->sin_addr, 976322dcb8dSMax Khon &IA_SIN(ifa)->sin_addr, IF_LLADDR(ifp)); 977dd2e4102SGarrett Wollman ifa->ifa_rtrequest = arp_rtrequest; 978dd2e4102SGarrett Wollman ifa->ifa_flags |= RTF_CLONING; 979dd2e4102SGarrett Wollman } 980df5e1987SJonathan Lemon 981a9771948SGleb Smirnoff void 982a9771948SGleb Smirnoff arp_ifinit2(ifp, ifa, enaddr) 983a9771948SGleb Smirnoff struct ifnet *ifp; 984a9771948SGleb Smirnoff struct ifaddr *ifa; 985a9771948SGleb Smirnoff u_char *enaddr; 986a9771948SGleb Smirnoff { 987a9771948SGleb Smirnoff if (ntohl(IA_SIN(ifa)->sin_addr.s_addr) != INADDR_ANY) 988a9771948SGleb Smirnoff arprequest(ifp, &IA_SIN(ifa)->sin_addr, 989a9771948SGleb Smirnoff &IA_SIN(ifa)->sin_addr, enaddr); 990a9771948SGleb Smirnoff ifa->ifa_rtrequest = arp_rtrequest; 991a9771948SGleb Smirnoff ifa->ifa_flags |= RTF_CLONING; 992a9771948SGleb Smirnoff } 993a9771948SGleb Smirnoff 994df5e1987SJonathan Lemon static void 995df5e1987SJonathan Lemon arp_init(void) 996df5e1987SJonathan Lemon { 997df5e1987SJonathan Lemon 998df5e1987SJonathan Lemon arpintrq.ifq_maxlen = 50; 9996008862bSJohn Baldwin mtx_init(&arpintrq.ifq_mtx, "arp_inq", NULL, MTX_DEF); 1000532cf61bSPeter Wemm LIST_INIT(&llinfo_arp); 1001d1dd20beSSam Leffler callout_init(&arp_callout, CALLOUT_MPSAFE); 10027902224cSSam Leffler netisr_register(NETISR_ARP, arpintr, &arpintrq, NETISR_MPSAFE); 1003cfff63f1SLuigi Rizzo callout_reset(&arp_callout, hz, arptimer, NULL); 1004df5e1987SJonathan Lemon } 1005df5e1987SJonathan Lemon SYSINIT(arp, SI_SUB_PROTO_DOMAIN, SI_ORDER_ANY, arp_init, 0); 1006