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