rtsock: Fill in the correct rtm_index for RTM_ADD and RTM_CHANGE messages.
[dragonfly.git] / sys / netinet / if_ether.c
CommitLineData
f3ed2586
JH
1/*
2 * Copyright (c) 2004, 2005 The DragonFly Project. All rights reserved.
3 *
4 * This code is derived from software contributed to The DragonFly Project
5 * by Jeffrey M. Hsu.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of The DragonFly Project nor the names of its
16 * contributors may be used to endorse or promote products derived
17 * from this software without specific, prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
25 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
29 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32
984263bc
MD
33/*
34 * Copyright (c) 1982, 1986, 1988, 1993
35 * The Regents of the University of California. All rights reserved.
36 *
37 * Redistribution and use in source and binary forms, with or without
38 * modification, are permitted provided that the following conditions
39 * are met:
40 * 1. Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * 2. Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in the
44 * documentation and/or other materials provided with the distribution.
45 * 3. All advertising materials mentioning features or use of this software
46 * must display the following acknowledgement:
47 * This product includes software developed by the University of
48 * California, Berkeley and its contributors.
49 * 4. Neither the name of the University nor the names of its contributors
50 * may be used to endorse or promote products derived from this software
51 * without specific prior written permission.
52 *
53 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
54 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
55 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
56 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
57 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
58 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
59 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
60 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
61 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
62 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
63 * SUCH DAMAGE.
64 *
65 * @(#)if_ether.c 8.1 (Berkeley) 6/10/93
66 * $FreeBSD: src/sys/netinet/if_ether.c,v 1.64.2.23 2003/04/11 07:23:15 fjoe Exp $
b95665d8 67 * $DragonFly: src/sys/netinet/if_ether.c,v 1.59 2008/11/22 11:03:35 sephe Exp $
984263bc
MD
68 */
69
70/*
71 * Ethernet address resolution protocol.
72 * TODO:
73 * add "inuse/lock" bit (or ref. count) along with valid bit
74 */
75
76#include "opt_inet.h"
0d16ba1d 77#include "opt_carp.h"
984263bc
MD
78
79#include <sys/param.h>
80#include <sys/kernel.h>
81#include <sys/queue.h>
82#include <sys/sysctl.h>
83#include <sys/systm.h>
84#include <sys/mbuf.h>
85#include <sys/malloc.h>
86#include <sys/socket.h>
87#include <sys/syslog.h>
65fd4168 88#include <sys/lock.h>
984263bc
MD
89
90#include <net/if.h>
91#include <net/if_dl.h>
92#include <net/if_types.h>
93#include <net/route.h>
94#include <net/netisr.h>
95#include <net/if_llc.h>
984263bc
MD
96
97#include <netinet/in.h>
98#include <netinet/in_var.h>
99#include <netinet/if_ether.h>
100
4599cf19
MD
101#include <sys/thread2.h>
102#include <sys/msgport2.h>
103#include <net/netmsg2.h>
104
0d16ba1d
MD
105#ifdef CARP
106#include <netinet/ip_carp.h>
107#endif
108
984263bc
MD
109#define SIN(s) ((struct sockaddr_in *)s)
110#define SDL(s) ((struct sockaddr_dl *)s)
111
112SYSCTL_DECL(_net_link_ether);
113SYSCTL_NODE(_net_link_ether, PF_INET, inet, CTLFLAG_RW, 0, "");
114
115/* timer values */
116static int arpt_prune = (5*60*1); /* walk list every 5 minutes */
117static int arpt_keep = (20*60); /* once resolved, good for 20 more minutes */
118static int arpt_down = 20; /* once declared down, don't send for 20 sec */
119
120SYSCTL_INT(_net_link_ether_inet, OID_AUTO, prune_intvl, CTLFLAG_RW,
121 &arpt_prune, 0, "");
f23061d4 122SYSCTL_INT(_net_link_ether_inet, OID_AUTO, max_age, CTLFLAG_RW,
984263bc
MD
123 &arpt_keep, 0, "");
124SYSCTL_INT(_net_link_ether_inet, OID_AUTO, host_down_time, CTLFLAG_RW,
125 &arpt_down, 0, "");
126
f23061d4 127#define rt_expire rt_rmx.rmx_expire
984263bc
MD
128
129struct llinfo_arp {
130 LIST_ENTRY(llinfo_arp) la_le;
131 struct rtentry *la_rt;
132 struct mbuf *la_hold; /* last packet until resolved/timeout */
a6f79f3a 133 struct lwkt_port *la_msgport; /* last packet's msgport */
a916e847 134 u_short la_preempt; /* countdown for pre-expiry arps */
984263bc 135 u_short la_asked; /* #times we QUERIED following expiration */
984263bc
MD
136};
137
ecdefdda 138static LIST_HEAD(, llinfo_arp) llinfo_arp_list[MAXCPU];
984263bc 139
984263bc
MD
140static int arp_maxtries = 5;
141static int useloopback = 1; /* use loopback interface for local traffic */
142static int arp_proxyall = 0;
143
144SYSCTL_INT(_net_link_ether_inet, OID_AUTO, maxtries, CTLFLAG_RW,
145 &arp_maxtries, 0, "");
146SYSCTL_INT(_net_link_ether_inet, OID_AUTO, useloopback, CTLFLAG_RW,
147 &useloopback, 0, "");
148SYSCTL_INT(_net_link_ether_inet, OID_AUTO, proxyall, CTLFLAG_RW,
149 &arp_proxyall, 0, "");
150
ed2327fe
SZ
151static int arp_mpsafe = 0;
152TUNABLE_INT("net.link.ether.inet.arp_mpsafe", &arp_mpsafe);
153
799975d0 154static void arp_rtrequest(int, struct rtentry *, struct rt_addrinfo *);
1dfeb73c
SZ
155static void arprequest(struct ifnet *, const struct in_addr *,
156 const struct in_addr *, const u_char *);
157static void arprequest_async(struct ifnet *, const struct in_addr *,
158 const struct in_addr *, const u_char *);
4599cf19 159static void arpintr(struct netmsg *);
799975d0
SZ
160static void arptfree(struct llinfo_arp *);
161static void arptimer(void *);
162static struct llinfo_arp *
163 arplookup(in_addr_t, boolean_t, boolean_t);
984263bc 164#ifdef INET
799975d0 165static void in_arpinput(struct mbuf *);
984263bc
MD
166#endif
167
ecdefdda 168static struct callout arptimer_ch[MAXCPU];
ac311540 169
984263bc
MD
170/*
171 * Timeout routine. Age arp_tab entries periodically.
172 */
173/* ARGSUSED */
174static void
f23061d4 175arptimer(void *ignored_arg)
984263bc 176{
2e9572df 177 struct llinfo_arp *la, *nla;
984263bc 178
1cae611f 179 crit_enter();
ecdefdda 180 LIST_FOREACH_MUTABLE(la, &llinfo_arp_list[mycpuid], la_le, nla) {
2e9572df 181 if (la->la_rt->rt_expire && la->la_rt->rt_expire <= time_second)
799975d0 182 arptfree(la);
984263bc 183 }
ecdefdda 184 callout_reset(&arptimer_ch[mycpuid], arpt_prune * hz, arptimer, NULL);
1cae611f 185 crit_exit();
984263bc
MD
186}
187
188/*
189 * Parallel to llc_rtrequest.
190 */
191static void
f23061d4 192arp_rtrequest(int req, struct rtentry *rt, struct rt_addrinfo *info)
984263bc 193{
2256ba69 194 struct sockaddr *gate = rt->rt_gateway;
f23061d4
JH
195 struct llinfo_arp *la = rt->rt_llinfo;
196
5fe66e68 197 struct sockaddr_dl null_sdl = { sizeof null_sdl, AF_LINK };
ecdefdda 198 static boolean_t arpinit_done[MAXCPU];
984263bc 199
ecdefdda
MD
200 if (!arpinit_done[mycpuid]) {
201 arpinit_done[mycpuid] = TRUE;
202 callout_init(&arptimer_ch[mycpuid]);
203 callout_reset(&arptimer_ch[mycpuid], hz, arptimer, NULL);
984263bc
MD
204 }
205 if (rt->rt_flags & RTF_GATEWAY)
206 return;
984263bc 207
f23061d4 208 switch (req) {
984263bc
MD
209 case RTM_ADD:
210 /*
211 * XXX: If this is a manually added route to interface
212 * such as older version of routed or gated might provide,
213 * restore cloning bit.
214 */
f23061d4 215 if (!(rt->rt_flags & RTF_HOST) &&
984263bc
MD
216 SIN(rt_mask(rt))->sin_addr.s_addr != 0xffffffff)
217 rt->rt_flags |= RTF_CLONING;
218 if (rt->rt_flags & RTF_CLONING) {
219 /*
220 * Case 1: This route should come from a route to iface.
221 */
222 rt_setgate(rt, rt_key(rt),
0c3c561c 223 (struct sockaddr *)&null_sdl);
984263bc
MD
224 gate = rt->rt_gateway;
225 SDL(gate)->sdl_type = rt->rt_ifp->if_type;
226 SDL(gate)->sdl_index = rt->rt_ifp->if_index;
227 rt->rt_expire = time_second;
228 break;
229 }
230 /* Announce a new entry if requested. */
9c94ab97 231 if (rt->rt_flags & RTF_ANNOUNCE) {
77e3dc77 232 arprequest_async(rt->rt_ifp,
984263bc
MD
233 &SIN(rt_key(rt))->sin_addr,
234 &SIN(rt_key(rt))->sin_addr,
f23061d4 235 LLADDR(SDL(gate)));
9c94ab97 236 }
984263bc
MD
237 /*FALLTHROUGH*/
238 case RTM_RESOLVE:
239 if (gate->sa_family != AF_LINK ||
f23061d4 240 gate->sa_len < sizeof(struct sockaddr_dl)) {
984263bc
MD
241 log(LOG_DEBUG, "arp_rtrequest: bad gateway value\n");
242 break;
243 }
244 SDL(gate)->sdl_type = rt->rt_ifp->if_type;
245 SDL(gate)->sdl_index = rt->rt_ifp->if_index;
f23061d4 246 if (la != NULL)
984263bc
MD
247 break; /* This happens on a route change */
248 /*
249 * Case 2: This route may come from cloning, or a manual route
250 * add with a LL address.
251 */
0c3c561c 252 R_Malloc(la, struct llinfo_arp *, sizeof *la);
f23061d4
JH
253 rt->rt_llinfo = la;
254 if (la == NULL) {
984263bc
MD
255 log(LOG_DEBUG, "arp_rtrequest: malloc failed\n");
256 break;
257 }
f23061d4 258 bzero(la, sizeof *la);
984263bc
MD
259 la->la_rt = rt;
260 rt->rt_flags |= RTF_LLINFO;
ecdefdda 261 LIST_INSERT_HEAD(&llinfo_arp_list[mycpuid], la, la_le);
984263bc
MD
262
263#ifdef INET
264 /*
265 * This keeps the multicast addresses from showing up
266 * in `arp -a' listings as unresolved. It's not actually
267 * functional. Then the same for broadcast.
268 */
ce6da440 269 if (IN_MULTICAST(ntohl(SIN(rt_key(rt))->sin_addr.s_addr))) {
984263bc
MD
270 ETHER_MAP_IP_MULTICAST(&SIN(rt_key(rt))->sin_addr,
271 LLADDR(SDL(gate)));
272 SDL(gate)->sdl_alen = 6;
273 rt->rt_expire = 0;
274 }
275 if (in_broadcast(SIN(rt_key(rt))->sin_addr, rt->rt_ifp)) {
c401f0fd 276 memcpy(LLADDR(SDL(gate)), rt->rt_ifp->if_broadcastaddr,
984263bc
MD
277 rt->rt_ifp->if_addrlen);
278 SDL(gate)->sdl_alen = rt->rt_ifp->if_addrlen;
279 rt->rt_expire = 0;
280 }
281#endif
282
283 if (SIN(rt_key(rt))->sin_addr.s_addr ==
284 (IA_SIN(rt->rt_ifa))->sin_addr.s_addr) {
f23061d4
JH
285 /*
286 * This test used to be
287 * if (loif.if_flags & IFF_UP)
288 * It allowed local traffic to be forced
289 * through the hardware by configuring the
290 * loopback down. However, it causes problems
291 * during network configuration for boards
292 * that can't receive packets they send. It
293 * is now necessary to clear "useloopback" and
294 * remove the route to force traffic out to
295 * the hardware.
296 */
984263bc 297 rt->rt_expire = 0;
2e9572df 298 bcopy(IF_LLADDR(rt->rt_ifp), LLADDR(SDL(gate)),
984263bc
MD
299 SDL(gate)->sdl_alen = rt->rt_ifp->if_addrlen);
300 if (useloopback)
301 rt->rt_ifp = loif;
984263bc
MD
302 }
303 break;
304
305 case RTM_DELETE:
f23061d4 306 if (la == NULL)
984263bc 307 break;
984263bc 308 LIST_REMOVE(la, la_le);
f23061d4 309 rt->rt_llinfo = NULL;
984263bc 310 rt->rt_flags &= ~RTF_LLINFO;
f23061d4 311 if (la->la_hold != NULL)
984263bc 312 m_freem(la->la_hold);
f23061d4 313 Free(la);
799975d0 314 break;
984263bc
MD
315 }
316}
317
77e3dc77 318static struct mbuf *
1dfeb73c
SZ
319arpreq_alloc(struct ifnet *ifp, const struct in_addr *sip,
320 const struct in_addr *tip, const u_char *enaddr)
984263bc 321{
2256ba69 322 struct mbuf *m;
2256ba69 323 struct arphdr *ah;
984263bc
MD
324 u_short ar_hrd;
325
74f1caca 326 if ((m = m_gethdr(MB_DONTWAIT, MT_DATA)) == NULL)
77e3dc77 327 return NULL;
69e8ff02 328 m->m_pkthdr.rcvif = NULL;
f23061d4 329
984263bc 330 switch (ifp->if_type) {
984263bc
MD
331 case IFT_ETHER:
332 /*
333 * This may not be correct for types not explicitly
334 * listed, but this is our best guess
335 */
336 default:
337 ar_hrd = htons(ARPHRD_ETHER);
338
339 m->m_len = arphdr_len2(ifp->if_addrlen, sizeof(struct in_addr));
340 m->m_pkthdr.len = m->m_len;
341 MH_ALIGN(m, m->m_len);
342
984263bc
MD
343 ah = mtod(m, struct arphdr *);
344 break;
345 }
346
347 ah->ar_hrd = ar_hrd;
348 ah->ar_pro = htons(ETHERTYPE_IP);
349 ah->ar_hln = ifp->if_addrlen; /* hardware address length */
350 ah->ar_pln = sizeof(struct in_addr); /* protocol address length */
351 ah->ar_op = htons(ARPOP_REQUEST);
f23061d4 352 memcpy(ar_sha(ah), enaddr, ah->ar_hln);
984263bc 353 memset(ar_tha(ah), 0, ah->ar_hln);
f23061d4
JH
354 memcpy(ar_spa(ah), sip, ah->ar_pln);
355 memcpy(ar_tpa(ah), tip, ah->ar_pln);
984263bc 356
77e3dc77
SZ
357 return m;
358}
359
360static void
361arpreq_send(struct ifnet *ifp, struct mbuf *m)
362{
363 struct sockaddr sa;
364 struct ether_header *eh;
365
366 switch (ifp->if_type) {
367 case IFT_ETHER:
368 /*
369 * This may not be correct for types not explicitly
370 * listed, but this is our best guess
371 */
372 default:
373 eh = (struct ether_header *)sa.sa_data;
374 /* if_output() will not swap */
375 eh->ether_type = htons(ETHERTYPE_ARP);
376 memcpy(eh->ether_dhost, ifp->if_broadcastaddr, ifp->if_addrlen);
377 break;
378 }
379
984263bc 380 sa.sa_family = AF_UNSPEC;
77e3dc77 381 sa.sa_len = sizeof(sa);
799975d0 382 ifp->if_output(ifp, m, &sa, NULL);
984263bc
MD
383}
384
77e3dc77
SZ
385static void
386arpreq_send_handler(struct netmsg *nmsg)
387{
388 struct mbuf *m = ((struct netmsg_packet *)nmsg)->nm_packet;
389 struct ifnet *ifp = nmsg->nm_lmsg.u.ms_resultp;
390
391 arpreq_send(ifp, m);
392 /* nmsg was embedded in the mbuf, do not reply! */
393}
394
395/*
396 * Broadcast an ARP request. Caller specifies:
397 * - arp header source ip address
398 * - arp header target ip address
399 * - arp header source ethernet address
400 *
401 * NOTE: Caller MUST NOT hold ifp's serializer
402 */
403static void
1dfeb73c
SZ
404arprequest(struct ifnet *ifp, const struct in_addr *sip,
405 const struct in_addr *tip, const u_char *enaddr)
77e3dc77
SZ
406{
407 struct mbuf *m;
408
409 m = arpreq_alloc(ifp, sip, tip, enaddr);
410 if (m == NULL)
411 return;
412 arpreq_send(ifp, m);
413}
414
415/*
416 * Same as arprequest(), except:
417 * - Caller is allowed to hold ifp's serializer
418 * - Network output is done in TDF_NETWORK kernel thread
419 */
420static void
1dfeb73c
SZ
421arprequest_async(struct ifnet *ifp, const struct in_addr *sip,
422 const struct in_addr *tip, const u_char *enaddr)
77e3dc77
SZ
423{
424 struct mbuf *m;
425 struct netmsg_packet *pmsg;
426
427 m = arpreq_alloc(ifp, sip, tip, enaddr);
428 if (m == NULL)
429 return;
430
431 pmsg = &m->m_hdr.mh_netmsg;
432 netmsg_init(&pmsg->nm_netmsg, &netisr_apanic_rport, 0,
433 arpreq_send_handler);
434 pmsg->nm_packet = m;
435 pmsg->nm_netmsg.nm_lmsg.u.ms_resultp = ifp;
436
437 lwkt_sendmsg(cpu_portfn(mycpuid), &pmsg->nm_netmsg.nm_lmsg);
438}
439
984263bc
MD
440/*
441 * Resolve an IP address into an ethernet address. If success,
442 * desten is filled in. If there is no entry in arptab,
443 * set one up and broadcast a request for the IP address.
444 * Hold onto this mbuf and resend it once the address
445 * is finally resolved. A return value of 1 indicates
446 * that desten has been filled in and the packet should be sent
447 * normally; a 0 return indicates that the packet has been
448 * taken over here, either now or for later transmission.
449 */
450int
799975d0
SZ
451arpresolve(struct ifnet *ifp, struct rtentry *rt0, struct mbuf *m,
452 struct sockaddr *dst, u_char *desten)
984263bc 453{
f23061d4
JH
454 struct rtentry *rt;
455 struct llinfo_arp *la = NULL;
984263bc
MD
456 struct sockaddr_dl *sdl;
457
458 if (m->m_flags & M_BCAST) { /* broadcast */
c401f0fd 459 memcpy(desten, ifp->if_broadcastaddr, ifp->if_addrlen);
984263bc
MD
460 return (1);
461 }
ce6da440 462 if (m->m_flags & M_MCAST) {/* multicast */
984263bc 463 ETHER_MAP_IP_MULTICAST(&SIN(dst)->sin_addr, desten);
f23061d4 464 return (1);
984263bc 465 }
f23061d4
JH
466 if (rt0 != NULL) {
467 if (rt_llroute(dst, rt0, &rt) != 0) {
468 m_freem(m);
469 return 0;
470 }
471 la = rt->rt_llinfo;
472 }
473 if (la == NULL) {
474 la = arplookup(SIN(dst)->sin_addr.s_addr, TRUE, FALSE);
475 if (la != NULL)
984263bc
MD
476 rt = la->la_rt;
477 }
f23061d4 478 if (la == NULL || rt == NULL) {
984263bc 479 log(LOG_DEBUG, "arpresolve: can't allocate llinfo for %s%s%s\n",
5fe66e68
JH
480 inet_ntoa(SIN(dst)->sin_addr), la ? "la" : " ",
481 rt ? "rt" : "");
984263bc
MD
482 m_freem(m);
483 return (0);
484 }
485 sdl = SDL(rt->rt_gateway);
486 /*
487 * Check the address family and length is valid, the address
488 * is resolved; otherwise, try to resolve.
489 */
490 if ((rt->rt_expire == 0 || rt->rt_expire > time_second) &&
491 sdl->sdl_family == AF_LINK && sdl->sdl_alen != 0) {
492 /*
493 * If entry has an expiry time and it is approaching,
494 * see if we need to send an ARP request within this
495 * arpt_down interval.
496 */
497 if ((rt->rt_expire != 0) &&
a916e847 498 (time_second + la->la_preempt > rt->rt_expire)) {
984263bc
MD
499 arprequest(ifp,
500 &SIN(rt->rt_ifa->ifa_addr)->sin_addr,
501 &SIN(dst)->sin_addr,
502 IF_LLADDR(ifp));
a916e847 503 la->la_preempt--;
f23061d4 504 }
984263bc
MD
505
506 bcopy(LLADDR(sdl), desten, sdl->sdl_alen);
507 return 1;
508 }
509 /*
510 * If ARP is disabled on this interface, stop.
511 * XXX
512 * Probably should not allocate empty llinfo struct if we are
513 * not going to be sending out an arp request.
514 */
515 if (ifp->if_flags & IFF_NOARP) {
516 m_freem(m);
517 return (0);
518 }
519 /*
520 * There is an arptab entry, but no ethernet address
521 * response yet. Replace the held mbuf with this
522 * latest one.
523 */
f23061d4 524 if (la->la_hold != NULL)
984263bc
MD
525 m_freem(la->la_hold);
526 la->la_hold = m;
c244d613 527 la->la_msgport = curnetport;
03f869ef 528 if (rt->rt_expire || ((rt->rt_flags & RTF_STATIC) && !sdl->sdl_alen)) {
984263bc
MD
529 rt->rt_flags &= ~RTF_REJECT;
530 if (la->la_asked == 0 || rt->rt_expire != time_second) {
531 rt->rt_expire = time_second;
532 if (la->la_asked++ < arp_maxtries) {
533 arprequest(ifp,
534 &SIN(rt->rt_ifa->ifa_addr)->sin_addr,
535 &SIN(dst)->sin_addr,
536 IF_LLADDR(ifp));
537 } else {
538 rt->rt_flags |= RTF_REJECT;
539 rt->rt_expire += arpt_down;
a916e847
JH
540 la->la_asked = 0;
541 la->la_preempt = arp_maxtries;
984263bc 542 }
984263bc
MD
543 }
544 }
545 return (0);
546}
547
548/*
549 * Common length and type checks are done here,
550 * then the protocol-specific routine is called.
551 */
4599cf19 552static void
9eeaa8a9 553arpintr(struct netmsg *msg)
984263bc 554{
9eeaa8a9 555 struct mbuf *m = ((struct netmsg_packet *)msg)->nm_packet;
2256ba69 556 struct arphdr *ar;
8bde602d 557 u_short ar_hrd;
984263bc 558
8bde602d 559 if (m->m_len < sizeof(struct arphdr) &&
db597c8a 560 (m = m_pullup(m, sizeof(struct arphdr))) == NULL) {
8bde602d 561 log(LOG_ERR, "arp: runt packet -- m_pullup failed\n");
db597c8a 562 return;
8bde602d
JH
563 }
564 ar = mtod(m, struct arphdr *);
565
566 ar_hrd = ntohs(ar->ar_hrd);
db597c8a
SZ
567 if (ar_hrd != ARPHRD_ETHER && ar_hrd != ARPHRD_IEEE802) {
568 log(LOG_ERR, "arp: unknown hardware address format (0x%2D)\n",
8bde602d 569 (unsigned char *)&ar->ar_hrd, "");
db597c8a
SZ
570 m_freem(m);
571 return;
8bde602d 572 }
984263bc 573
db597c8a
SZ
574 if (m->m_pkthdr.len < arphdr_len(ar)) {
575 if ((m = m_pullup(m, arphdr_len(ar))) == NULL) {
576 log(LOG_ERR, "arp: runt packet\n");
577 return;
578 }
579 ar = mtod(m, struct arphdr *);
8bde602d
JH
580 }
581
582 switch (ntohs(ar->ar_pro)) {
984263bc 583#ifdef INET
db597c8a
SZ
584 case ETHERTYPE_IP:
585 in_arpinput(m);
586 return;
984263bc 587#endif
984263bc 588 }
8bde602d 589 m_freem(m);
6aad077d 590 /* msg was embedded in the mbuf, do not reply! */
984263bc
MD
591}
592
593#ifdef INET
594/*
595 * ARP for Internet protocols on 10 Mb/s Ethernet.
596 * Algorithm is that given in RFC 826.
597 * In addition, a sanity check is performed on the sender
598 * protocol address, to catch impersonators.
599 * We no longer handle negotiations for use of trailer protocol:
600 * Formerly, ARP replied for protocol type ETHERTYPE_TRAIL sent
601 * along with IP replies if we wanted trailers sent to us,
602 * and also sent them in response to IP replies.
603 * This allowed either end to announce the desire to receive
604 * trailer packets.
605 * We no longer reply to requests for ETHERTYPE_TRAIL protocol either,
606 * but formerly didn't normally send requests.
607 */
608static int log_arp_wrong_iface = 1;
984263bc 609SYSCTL_INT(_net_link_ether_inet, OID_AUTO, log_arp_wrong_iface, CTLFLAG_RW,
799975d0
SZ
610 &log_arp_wrong_iface, 0,
611 "log arp packets arriving on the wrong interface");
984263bc 612
a6f79f3a
SZ
613static void
614arp_hold_output(struct netmsg *nmsg)
615{
616 struct mbuf *m = ((struct netmsg_packet *)nmsg)->nm_packet;
617 struct rtentry *rt;
618 struct ifnet *ifp;
619
620 rt = nmsg->nm_lmsg.u.ms_resultp;
621 ifp = m->m_pkthdr.rcvif;
622 m->m_pkthdr.rcvif = NULL;
623
624 ifp->if_output(ifp, m, rt_key(rt), rt);
625
626 /* Drop the reference count bumped by the sender */
627 RTFREE(rt);
628
629 /* nmsg was embedded in the mbuf, do not reply! */
630}
631
ecdefdda
MD
632static void
633arp_update_oncpu(struct mbuf *m, in_addr_t saddr, boolean_t create,
634 boolean_t dologging)
635{
636 struct arphdr *ah = mtod(m, struct arphdr *);
637 struct ifnet *ifp = m->m_pkthdr.rcvif;
638 struct llinfo_arp *la;
639 struct sockaddr_dl *sdl;
640 struct rtentry *rt;
ecdefdda
MD
641
642 la = arplookup(saddr, create, FALSE);
643 if (la && (rt = la->la_rt) && (sdl = SDL(rt->rt_gateway))) {
644 struct in_addr isaddr = { saddr };
645
646 /* the following is not an error when doing bridging */
a8d45119 647 if (rt->rt_ifp != ifp) {
e090f4c1 648 if (dologging && log_arp_wrong_iface) {
ecdefdda
MD
649 log(LOG_ERR,
650 "arp: %s is on %s "
651 "but got reply from %*D on %s\n",
652 inet_ntoa(isaddr),
653 rt->rt_ifp->if_xname,
654 ifp->if_addrlen, (u_char *)ar_sha(ah), ":",
655 ifp->if_xname);
656 }
657 return;
658 }
659 if (sdl->sdl_alen &&
660 bcmp(ar_sha(ah), LLADDR(sdl), sdl->sdl_alen)) {
661 if (rt->rt_expire != 0) {
e090f4c1 662 if (dologging) {
ecdefdda
MD
663 log(LOG_INFO,
664 "arp: %s moved from %*D to %*D on %s\n",
665 inet_ntoa(isaddr),
666 ifp->if_addrlen, (u_char *)LLADDR(sdl),
667 ":", ifp->if_addrlen,
668 (u_char *)ar_sha(ah), ":",
669 ifp->if_xname);
670 }
671 } else {
e090f4c1 672 if (dologging) {
ecdefdda 673 log(LOG_ERR,
799975d0
SZ
674 "arp: %*D attempts to modify "
675 "permanent entry for %s on %s\n",
676 ifp->if_addrlen, (u_char *)ar_sha(ah),
677 ":", inet_ntoa(isaddr), ifp->if_xname);
ecdefdda
MD
678 }
679 return;
680 }
681 }
682 /*
683 * sanity check for the address length.
684 * XXX this does not work for protocols with variable address
685 * length. -is
686 */
e090f4c1 687 if (dologging && sdl->sdl_alen && sdl->sdl_alen != ah->ar_hln) {
ecdefdda
MD
688 log(LOG_WARNING,
689 "arp from %*D: new addr len %d, was %d",
690 ifp->if_addrlen, (u_char *) ar_sha(ah), ":",
691 ah->ar_hln, sdl->sdl_alen);
692 }
693 if (ifp->if_addrlen != ah->ar_hln) {
e090f4c1 694 if (dologging) {
ecdefdda 695 log(LOG_WARNING,
799975d0
SZ
696 "arp from %*D: addr len: new %d, i/f %d "
697 "(ignored)",
ecdefdda
MD
698 ifp->if_addrlen, (u_char *) ar_sha(ah), ":",
699 ah->ar_hln, ifp->if_addrlen);
700 }
701 return;
702 }
703 memcpy(LLADDR(sdl), ar_sha(ah), sdl->sdl_alen = ah->ar_hln);
ecdefdda
MD
704 if (rt->rt_expire != 0)
705 rt->rt_expire = time_second + arpt_keep;
706 rt->rt_flags &= ~RTF_REJECT;
707 la->la_asked = 0;
708 la->la_preempt = arp_maxtries;
709
710 /*
711 * This particular cpu might have been holding an mbuf
712 * pending ARP resolution. If so, transmit the mbuf now.
713 */
714 if (la->la_hold != NULL) {
a6f79f3a
SZ
715 struct mbuf *m = la->la_hold;
716 struct lwkt_port *port = la->la_msgport;
717 struct netmsg_packet *pmsg;
718
ecdefdda 719 la->la_hold = NULL;
a6f79f3a
SZ
720 la->la_msgport = NULL;
721
722 m_adj(m, sizeof(struct ether_header));
723
724 /*
725 * Make sure that this rtentry will not be freed
726 * before the packet is processed on the target
727 * msgport. The reference count will be dropped
728 * in the handler associated with this packet.
729 */
730 rt->rt_refcnt++;
731
732 pmsg = &m->m_hdr.mh_netmsg;
733 netmsg_init(&pmsg->nm_netmsg, &netisr_apanic_rport,
d6f338fc
SZ
734 MSGF_MPSAFE | MSGF_PRIORITY,
735 arp_hold_output);
a6f79f3a
SZ
736 pmsg->nm_packet = m;
737
738 /* Record necessary information */
739 m->m_pkthdr.rcvif = ifp;
740 pmsg->nm_netmsg.nm_lmsg.u.ms_resultp = rt;
741
742 lwkt_sendmsg(port, &pmsg->nm_netmsg.nm_lmsg);
ecdefdda
MD
743 }
744 }
745}
746
747#ifdef SMP
748
749struct netmsg_arp_update {
4599cf19 750 struct netmsg netmsg;
ecdefdda
MD
751 struct mbuf *m;
752 in_addr_t saddr;
753 boolean_t create;
754};
755
799975d0 756static void arp_update_msghandler(struct netmsg *);
ecdefdda
MD
757
758#endif
759
760/*
761 * Called from arpintr() - this routine is run from a single cpu.
762 */
984263bc 763static void
f23061d4 764in_arpinput(struct mbuf *m)
984263bc 765{
2256ba69
RG
766 struct arphdr *ah;
767 struct ifnet *ifp = m->m_pkthdr.rcvif;
984263bc 768 struct ether_header *eh;
2256ba69 769 struct rtentry *rt;
b2632176 770 struct ifaddr_container *ifac;
f8983475 771 struct in_ifaddr_container *iac;
5bd4422e 772 struct in_ifaddr *ia = NULL;
984263bc
MD
773 struct sockaddr sa;
774 struct in_addr isaddr, itaddr, myaddr;
ecdefdda
MD
775#ifdef SMP
776 struct netmsg_arp_update msg;
777#endif
5bd4422e 778 uint8_t *enaddr = NULL;
ecdefdda 779 int op;
984263bc
MD
780 int req_len;
781
782 req_len = arphdr_len2(ifp->if_addrlen, sizeof(struct in_addr));
783 if (m->m_len < req_len && (m = m_pullup(m, req_len)) == NULL) {
784 log(LOG_ERR, "in_arp: runt packet -- m_pullup failed\n");
785 return;
786 }
787
788 ah = mtod(m, struct arphdr *);
789 op = ntohs(ah->ar_op);
f23061d4
JH
790 memcpy(&isaddr, ar_spa(ah), sizeof isaddr);
791 memcpy(&itaddr, ar_tpa(ah), sizeof itaddr);
5bd4422e
SZ
792
793 myaddr.s_addr = INADDR_ANY;
794#ifdef CARP
795 if (ifp->if_carp != NULL) {
796 get_mplock();
797 if (ifp->if_carp != NULL &&
798 carp_iamatch(ifp->if_carp, &itaddr, &isaddr, &enaddr)) {
799 rel_mplock();
800 myaddr = itaddr;
801 goto match;
802 }
803 rel_mplock();
804 }
805#endif
806
984263bc 807 /*
ed5bc924
SS
808 * Check both target and sender IP addresses:
809 *
810 * If we receive the packet on the interface owning the address,
811 * then accept the address.
812 *
813 * For a bridge, we accept the address if the receive interface and
814 * the interface owning the address are on the same bridge.
815 * (This will change slightly when we have clusters of interfaces).
984263bc 816 */
f8983475
SZ
817 LIST_FOREACH(iac, INADDR_HASH(itaddr.s_addr), ia_hash) {
818 ia = iac->ia;
819
ed5bc924
SS
820 /* Skip all ia's which don't match */
821 if (itaddr.s_addr != ia->ia_addr.sin_addr.s_addr)
822 continue;
5bd4422e
SZ
823#ifdef CARP
824 if (ia->ia_ifp->if_type == IFT_CARP)
825 continue;
826#endif
ed5bc924
SS
827 if (ia->ia_ifp == ifp)
828 goto match;
829
ac93838f 830 if (ifp->if_bridge && ia->ia_ifp &&
ed5bc924 831 ifp->if_bridge == ia->ia_ifp->if_bridge)
ac93838f 832 goto match;
ac93838f 833 }
f8983475
SZ
834 LIST_FOREACH(iac, INADDR_HASH(isaddr.s_addr), ia_hash) {
835 ia = iac->ia;
836
ed5bc924
SS
837 /* Skip all ia's which don't match */
838 if (isaddr.s_addr != ia->ia_addr.sin_addr.s_addr)
839 continue;
5bd4422e
SZ
840#ifdef CARP
841 if (ia->ia_ifp->if_type == IFT_CARP)
842 continue;
843#endif
ed5bc924
SS
844 if (ia->ia_ifp == ifp)
845 goto match;
846
ac93838f 847 if (ifp->if_bridge && ia->ia_ifp &&
ed5bc924 848 ifp->if_bridge == ia->ia_ifp->if_bridge)
ac93838f 849 goto match;
ac93838f 850 }
984263bc
MD
851 /*
852 * No match, use the first inet address on the receive interface
853 * as a dummy address for the rest of the function.
854 */
b2632176
SZ
855 TAILQ_FOREACH(ifac, &ifp->if_addrheads[mycpuid], ifa_link) {
856 struct ifaddr *ifa = ifac->ifa;
857
984263bc
MD
858 if (ifa->ifa_addr && ifa->ifa_addr->sa_family == AF_INET) {
859 ia = ifatoia(ifa);
860 goto match;
861 }
984263bc 862 }
ed5bc924
SS
863 /*
864 * If we got here, we didn't find any suitable interface,
865 * so drop the packet.
866 */
867 m_freem(m);
868 return;
869
984263bc 870match:
0d16ba1d 871 if (!enaddr)
5bd4422e
SZ
872 enaddr = (uint8_t *)IF_LLADDR(ifp);
873 if (myaddr.s_addr == INADDR_ANY)
874 myaddr = ia->ia_addr.sin_addr;
0d16ba1d 875 if (!bcmp(ar_sha(ah), enaddr, ifp->if_addrlen)) {
984263bc
MD
876 m_freem(m); /* it's from me, ignore it. */
877 return;
878 }
c401f0fd 879 if (!bcmp(ar_sha(ah), ifp->if_broadcastaddr, ifp->if_addrlen)) {
984263bc
MD
880 log(LOG_ERR,
881 "arp: link address is broadcast for IP address %s!\n",
882 inet_ntoa(isaddr));
883 m_freem(m);
884 return;
885 }
c3749f74 886 if (isaddr.s_addr == myaddr.s_addr && myaddr.s_addr != 0) {
984263bc
MD
887 log(LOG_ERR,
888 "arp: %*D is using my IP address %s!\n",
889 ifp->if_addrlen, (u_char *)ar_sha(ah), ":",
890 inet_ntoa(isaddr));
891 itaddr = myaddr;
892 goto reply;
893 }
ecdefdda 894#ifdef SMP
4599cf19
MD
895 netmsg_init(&msg.netmsg, &curthread->td_msgport, 0,
896 arp_update_msghandler);
ecdefdda
MD
897 msg.m = m;
898 msg.saddr = isaddr.s_addr;
899 msg.create = (itaddr.s_addr == myaddr.s_addr);
a22c590e 900 lwkt_domsg(rtable_portfn(0), &msg.netmsg.nm_lmsg, 0);
e090f4c1 901#else
ecdefdda
MD
902 arp_update_oncpu(m, isaddr.s_addr, (itaddr.s_addr == myaddr.s_addr),
903 TRUE);
e090f4c1 904#endif
984263bc
MD
905reply:
906 if (op != ARPOP_REQUEST) {
907 m_freem(m);
908 return;
909 }
910 if (itaddr.s_addr == myaddr.s_addr) {
911 /* I am the target */
f23061d4 912 memcpy(ar_tha(ah), ar_sha(ah), ah->ar_hln);
0d16ba1d 913 memcpy(ar_sha(ah), enaddr, ah->ar_hln);
984263bc 914 } else {
ecdefdda
MD
915 struct llinfo_arp *la;
916
f23061d4 917 la = arplookup(itaddr.s_addr, FALSE, SIN_PROXY);
984263bc
MD
918 if (la == NULL) {
919 struct sockaddr_in sin;
920
921 if (!arp_proxyall) {
922 m_freem(m);
923 return;
924 }
925
926 bzero(&sin, sizeof sin);
927 sin.sin_family = AF_INET;
928 sin.sin_len = sizeof sin;
929 sin.sin_addr = itaddr;
930
f3ed2586 931 rt = rtpurelookup((struct sockaddr *)&sin);
0c3c561c 932 if (rt == NULL) {
984263bc
MD
933 m_freem(m);
934 return;
935 }
be23faf1 936 --rt->rt_refcnt;
984263bc
MD
937 /*
938 * Don't send proxies for nodes on the same interface
939 * as this one came out of, or we'll get into a fight
940 * over who claims what Ether address.
941 */
942 if (rt->rt_ifp == ifp) {
984263bc
MD
943 m_freem(m);
944 return;
945 }
f23061d4 946 memcpy(ar_tha(ah), ar_sha(ah), ah->ar_hln);
0d16ba1d 947 memcpy(ar_sha(ah), enaddr, ah->ar_hln);
984263bc 948#ifdef DEBUG_PROXY
a6ec04bc 949 kprintf("arp: proxying for %s\n", inet_ntoa(itaddr));
984263bc
MD
950#endif
951 } else {
ecdefdda
MD
952 struct sockaddr_dl *sdl;
953
984263bc 954 rt = la->la_rt;
f23061d4 955 memcpy(ar_tha(ah), ar_sha(ah), ah->ar_hln);
984263bc 956 sdl = SDL(rt->rt_gateway);
f23061d4 957 memcpy(ar_sha(ah), LLADDR(sdl), ah->ar_hln);
984263bc
MD
958 }
959 }
960
f23061d4
JH
961 memcpy(ar_tpa(ah), ar_spa(ah), ah->ar_pln);
962 memcpy(ar_spa(ah), &itaddr, ah->ar_pln);
984263bc
MD
963 ah->ar_op = htons(ARPOP_REPLY);
964 ah->ar_pro = htons(ETHERTYPE_IP); /* let's be sure! */
965 switch (ifp->if_type) {
984263bc 966 case IFT_ETHER:
984263bc
MD
967 /*
968 * May not be correct for types not explictly
969 * listed, but it is our best guess.
970 */
971 default:
972 eh = (struct ether_header *)sa.sa_data;
0c3c561c 973 memcpy(eh->ether_dhost, ar_tha(ah), sizeof eh->ether_dhost);
984263bc
MD
974 eh->ether_type = htons(ETHERTYPE_ARP);
975 break;
976 }
977 sa.sa_family = AF_UNSPEC;
0c3c561c 978 sa.sa_len = sizeof sa;
799975d0 979 ifp->if_output(ifp, m, &sa, NULL);
984263bc 980}
ecdefdda
MD
981
982#ifdef SMP
983
799975d0 984static void
4599cf19 985arp_update_msghandler(struct netmsg *netmsg)
ecdefdda 986{
4599cf19 987 struct netmsg_arp_update *msg = (struct netmsg_arp_update *)netmsg;
ecdefdda
MD
988 int nextcpu;
989
e090f4c1 990 arp_update_oncpu(msg->m, msg->saddr, msg->create, mycpuid == 0);
ecdefdda
MD
991
992 nextcpu = mycpuid + 1;
799975d0 993 if (nextcpu < ncpus)
4599cf19 994 lwkt_forwardmsg(rtable_portfn(nextcpu), &msg->netmsg.nm_lmsg);
799975d0 995 else
4599cf19 996 lwkt_replymsg(&msg->netmsg.nm_lmsg, 0);
ecdefdda
MD
997}
998
799975d0 999#endif /* SMP */
ecdefdda 1000
799975d0 1001#endif /* INET */
984263bc
MD
1002
1003/*
03f869ef
MD
1004 * Free an arp entry. If the arp entry is actively referenced or represents
1005 * a static entry we only clear it back to an unresolved state, otherwise
1006 * we destroy the entry entirely.
1007 *
1008 * Note that static entries are created when route add ... -interface is used
1009 * to create an interface route to a (direct) destination.
984263bc
MD
1010 */
1011static void
5fe66e68 1012arptfree(struct llinfo_arp *la)
984263bc 1013{
2256ba69
RG
1014 struct rtentry *rt = la->la_rt;
1015 struct sockaddr_dl *sdl;
f23061d4 1016
03f869ef 1017 if (rt == NULL)
984263bc 1018 panic("arptfree");
03f869ef 1019 sdl = SDL(rt->rt_gateway);
5fe66e68
JH
1020 if (sdl != NULL &&
1021 ((rt->rt_refcnt > 0 && sdl->sdl_family == AF_LINK) ||
1022 (rt->rt_flags & RTF_STATIC))) {
984263bc
MD
1023 sdl->sdl_alen = 0;
1024 la->la_preempt = la->la_asked = 0;
1025 rt->rt_flags &= ~RTF_REJECT;
1026 return;
1027 }
f23061d4 1028 rtrequest(RTM_DELETE, rt_key(rt), NULL, rt_mask(rt), 0, NULL);
984263bc 1029}
0c3c561c 1030
984263bc
MD
1031/*
1032 * Lookup or enter a new address in arptab.
1033 */
1034static struct llinfo_arp *
f23061d4 1035arplookup(in_addr_t addr, boolean_t create, boolean_t proxy)
984263bc 1036{
2256ba69 1037 struct rtentry *rt;
f3ed2586 1038 struct sockaddr_inarp sin = { sizeof sin, AF_INET };
f23061d4 1039 const char *why = NULL;
984263bc
MD
1040
1041 sin.sin_addr.s_addr = addr;
1042 sin.sin_other = proxy ? SIN_PROXY : 0;
f3ed2586
JH
1043 if (create)
1044 rt = rtlookup((struct sockaddr *)&sin);
1045 else
1046 rt = rtpurelookup((struct sockaddr *)&sin);
f23061d4
JH
1047 if (rt == NULL)
1048 return (NULL);
984263bc
MD
1049 rt->rt_refcnt--;
1050
1051 if (rt->rt_flags & RTF_GATEWAY)
1052 why = "host is not on local network";
f23061d4 1053 else if (!(rt->rt_flags & RTF_LLINFO))
984263bc
MD
1054 why = "could not allocate llinfo";
1055 else if (rt->rt_gateway->sa_family != AF_LINK)
1056 why = "gateway route is not ours";
1057
8fd3e627
MD
1058 if (why) {
1059 if (create) {
1060 log(LOG_DEBUG, "arplookup %s failed: %s\n",
1061 inet_ntoa(sin.sin_addr), why);
1062 }
f23061d4
JH
1063 if (rt->rt_refcnt <= 0 && (rt->rt_flags & RTF_WASCLONED)) {
1064 /* No references to this route. Purge it. */
1065 rtrequest(RTM_DELETE, rt_key(rt), rt->rt_gateway,
be23faf1 1066 rt_mask(rt), rt->rt_flags, NULL);
8fd3e627 1067 }
f23061d4 1068 return (NULL);
984263bc 1069 }
f23061d4 1070 return (rt->rt_llinfo);
984263bc
MD
1071}
1072
1073void
f23061d4 1074arp_ifinit(struct ifnet *ifp, struct ifaddr *ifa)
984263bc 1075{
57dff79c 1076 if (IA_SIN(ifa)->sin_addr.s_addr != INADDR_ANY) {
77e3dc77
SZ
1077 arprequest_async(ifp, &IA_SIN(ifa)->sin_addr,
1078 &IA_SIN(ifa)->sin_addr, IF_LLADDR(ifp));
57dff79c 1079 }
984263bc
MD
1080 ifa->ifa_rtrequest = arp_rtrequest;
1081 ifa->ifa_flags |= RTF_CLONING;
1082}
1083
0d16ba1d 1084void
5bd4422e 1085arp_iainit(struct ifnet *ifp, const struct in_addr *addr, const u_char *enaddr)
0d16ba1d 1086{
5bd4422e
SZ
1087 if (addr->s_addr != INADDR_ANY)
1088 arprequest_async(ifp, addr, addr, enaddr);
0d16ba1d
MD
1089}
1090
984263bc
MD
1091static void
1092arp_init(void)
1093{
ed2327fe 1094 uint32_t flags;
ecdefdda
MD
1095 int cpu;
1096
1097 for (cpu = 0; cpu < ncpus2; cpu++)
1098 LIST_INIT(&llinfo_arp_list[cpu]);
ed2327fe
SZ
1099
1100 if (arp_mpsafe) {
1101 flags = NETISR_FLAG_MPSAFE;
1102 kprintf("arp: MPSAFE\n");
1103 } else {
1104 flags = NETISR_FLAG_NOTMPSAFE;
1105 }
1106 netisr_register(NETISR_ARP, cpu0_portfn, arpintr, flags);
984263bc
MD
1107}
1108
1109SYSINIT(arp, SI_SUB_PROTO_DOMAIN, SI_ORDER_ANY, arp_init, 0);