1 /*- 2 * Copyright (c) 1982, 1986, 1988, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 4. Neither the name of the University nor the names of its contributors 14 * may be used to endorse or promote products derived from this software 15 * without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 * @(#)if_ether.c 8.1 (Berkeley) 6/10/93 30 */ 31 32 /* 33 * Ethernet address resolution protocol. 34 * TODO: 35 * add "inuse/lock" bit (or ref. count) along with valid bit 36 */ 37 38 #include <sys/cdefs.h> 39 __FBSDID("$FreeBSD$"); 40 41 #include "opt_inet.h" 42 43 #include <sys/param.h> 44 #include <sys/kernel.h> 45 #include <sys/lock.h> 46 #include <sys/queue.h> 47 #include <sys/sysctl.h> 48 #include <sys/systm.h> 49 #include <sys/mbuf.h> 50 #include <sys/malloc.h> 51 #include <sys/proc.h> 52 #include <sys/rmlock.h> 53 #include <sys/socket.h> 54 #include <sys/syslog.h> 55 56 #include <net/if.h> 57 #include <net/if_var.h> 58 #include <net/if_dl.h> 59 #include <net/if_types.h> 60 #include <net/netisr.h> 61 #include <net/ethernet.h> 62 #include <net/route.h> 63 #include <net/vnet.h> 64 65 #include <netinet/in.h> 66 #include <netinet/in_fib.h> 67 #include <netinet/in_var.h> 68 #include <net/if_llatbl.h> 69 #include <netinet/if_ether.h> 70 #ifdef INET 71 #include <netinet/ip_carp.h> 72 #endif 73 74 #include <security/mac/mac_framework.h> 75 76 #define SIN(s) ((const struct sockaddr_in *)(s)) 77 78 static struct timeval arp_lastlog; 79 static int arp_curpps; 80 static int arp_maxpps = 1; 81 82 /* Simple ARP state machine */ 83 enum arp_llinfo_state { 84 ARP_LLINFO_INCOMPLETE = 0, /* No LLE data */ 85 ARP_LLINFO_REACHABLE, /* LLE is valid */ 86 ARP_LLINFO_VERIFY, /* LLE is valid, need refresh */ 87 ARP_LLINFO_DELETED, /* LLE is deleted */ 88 }; 89 90 SYSCTL_DECL(_net_link_ether); 91 static SYSCTL_NODE(_net_link_ether, PF_INET, inet, CTLFLAG_RW, 0, ""); 92 static SYSCTL_NODE(_net_link_ether, PF_ARP, arp, CTLFLAG_RW, 0, ""); 93 94 /* timer values */ 95 static VNET_DEFINE(int, arpt_keep) = (20*60); /* once resolved, good for 20 96 * minutes */ 97 static VNET_DEFINE(int, arp_maxtries) = 5; 98 static VNET_DEFINE(int, arp_proxyall) = 0; 99 static VNET_DEFINE(int, arpt_down) = 20; /* keep incomplete entries for 100 * 20 seconds */ 101 static VNET_DEFINE(int, arpt_rexmit) = 1; /* retransmit arp entries, sec*/ 102 VNET_PCPUSTAT_DEFINE(struct arpstat, arpstat); /* ARP statistics, see if_arp.h */ 103 VNET_PCPUSTAT_SYSINIT(arpstat); 104 105 #ifdef VIMAGE 106 VNET_PCPUSTAT_SYSUNINIT(arpstat); 107 #endif /* VIMAGE */ 108 109 static VNET_DEFINE(int, arp_maxhold) = 1; 110 111 #define V_arpt_keep VNET(arpt_keep) 112 #define V_arpt_down VNET(arpt_down) 113 #define V_arpt_rexmit VNET(arpt_rexmit) 114 #define V_arp_maxtries VNET(arp_maxtries) 115 #define V_arp_proxyall VNET(arp_proxyall) 116 #define V_arp_maxhold VNET(arp_maxhold) 117 118 SYSCTL_INT(_net_link_ether_inet, OID_AUTO, max_age, CTLFLAG_VNET | CTLFLAG_RW, 119 &VNET_NAME(arpt_keep), 0, 120 "ARP entry lifetime in seconds"); 121 SYSCTL_INT(_net_link_ether_inet, OID_AUTO, maxtries, CTLFLAG_VNET | CTLFLAG_RW, 122 &VNET_NAME(arp_maxtries), 0, 123 "ARP resolution attempts before returning error"); 124 SYSCTL_INT(_net_link_ether_inet, OID_AUTO, proxyall, CTLFLAG_VNET | CTLFLAG_RW, 125 &VNET_NAME(arp_proxyall), 0, 126 "Enable proxy ARP for all suitable requests"); 127 SYSCTL_INT(_net_link_ether_inet, OID_AUTO, wait, CTLFLAG_VNET | CTLFLAG_RW, 128 &VNET_NAME(arpt_down), 0, 129 "Incomplete ARP entry lifetime in seconds"); 130 SYSCTL_VNET_PCPUSTAT(_net_link_ether_arp, OID_AUTO, stats, struct arpstat, 131 arpstat, "ARP statistics (struct arpstat, net/if_arp.h)"); 132 SYSCTL_INT(_net_link_ether_inet, OID_AUTO, maxhold, CTLFLAG_VNET | CTLFLAG_RW, 133 &VNET_NAME(arp_maxhold), 0, 134 "Number of packets to hold per ARP entry"); 135 SYSCTL_INT(_net_link_ether_inet, OID_AUTO, max_log_per_second, 136 CTLFLAG_RW, &arp_maxpps, 0, 137 "Maximum number of remotely triggered ARP messages that can be " 138 "logged per second"); 139 140 #define ARP_LOG(pri, ...) do { \ 141 if (ppsratecheck(&arp_lastlog, &arp_curpps, arp_maxpps)) \ 142 log((pri), "arp: " __VA_ARGS__); \ 143 } while (0) 144 145 146 static void arp_init(void); 147 static void arpintr(struct mbuf *); 148 static void arptimer(void *); 149 #ifdef INET 150 static void in_arpinput(struct mbuf *); 151 #endif 152 153 static void arp_check_update_lle(struct arphdr *ah, struct in_addr isaddr, 154 struct ifnet *ifp, int bridged, struct llentry *la); 155 static void arp_mark_lle_reachable(struct llentry *la); 156 static void arp_iflladdr(void *arg __unused, struct ifnet *ifp); 157 158 static eventhandler_tag iflladdr_tag; 159 160 static const struct netisr_handler arp_nh = { 161 .nh_name = "arp", 162 .nh_handler = arpintr, 163 .nh_proto = NETISR_ARP, 164 .nh_policy = NETISR_POLICY_SOURCE, 165 }; 166 167 /* 168 * Timeout routine. Age arp_tab entries periodically. 169 */ 170 static void 171 arptimer(void *arg) 172 { 173 struct llentry *lle = (struct llentry *)arg; 174 struct ifnet *ifp; 175 int r_skip_req; 176 177 if (lle->la_flags & LLE_STATIC) { 178 return; 179 } 180 LLE_WLOCK(lle); 181 if (callout_pending(&lle->lle_timer)) { 182 /* 183 * Here we are a bit odd here in the treatment of 184 * active/pending. If the pending bit is set, it got 185 * rescheduled before I ran. The active 186 * bit we ignore, since if it was stopped 187 * in ll_tablefree() and was currently running 188 * it would have return 0 so the code would 189 * not have deleted it since the callout could 190 * not be stopped so we want to go through 191 * with the delete here now. If the callout 192 * was restarted, the pending bit will be back on and 193 * we just want to bail since the callout_reset would 194 * return 1 and our reference would have been removed 195 * by arpresolve() below. 196 */ 197 LLE_WUNLOCK(lle); 198 return; 199 } 200 ifp = lle->lle_tbl->llt_ifp; 201 CURVNET_SET(ifp->if_vnet); 202 203 switch (lle->ln_state) { 204 case ARP_LLINFO_REACHABLE: 205 206 /* 207 * Expiration time is approaching. 208 * Let's try to refresh entry if it is still 209 * in use. 210 * 211 * Set r_skip_req to get feedback from 212 * fast path. Change state and re-schedule 213 * ourselves. 214 */ 215 LLE_REQ_LOCK(lle); 216 lle->r_skip_req = 1; 217 LLE_REQ_UNLOCK(lle); 218 lle->ln_state = ARP_LLINFO_VERIFY; 219 callout_schedule(&lle->lle_timer, hz * V_arpt_rexmit); 220 LLE_WUNLOCK(lle); 221 CURVNET_RESTORE(); 222 return; 223 case ARP_LLINFO_VERIFY: 224 LLE_REQ_LOCK(lle); 225 r_skip_req = lle->r_skip_req; 226 LLE_REQ_UNLOCK(lle); 227 228 if (r_skip_req == 0 && lle->la_preempt > 0) { 229 /* Entry was used, issue refresh request */ 230 struct in_addr dst; 231 dst = lle->r_l3addr.addr4; 232 lle->la_preempt--; 233 callout_schedule(&lle->lle_timer, hz * V_arpt_rexmit); 234 LLE_WUNLOCK(lle); 235 arprequest(ifp, NULL, &dst, NULL); 236 CURVNET_RESTORE(); 237 return; 238 } 239 /* Nothing happened. Reschedule if not too late */ 240 if (lle->la_expire > time_uptime) { 241 callout_schedule(&lle->lle_timer, hz * V_arpt_rexmit); 242 LLE_WUNLOCK(lle); 243 CURVNET_RESTORE(); 244 return; 245 } 246 break; 247 case ARP_LLINFO_INCOMPLETE: 248 case ARP_LLINFO_DELETED: 249 break; 250 } 251 252 if ((lle->la_flags & LLE_DELETED) == 0) { 253 int evt; 254 255 if (lle->la_flags & LLE_VALID) 256 evt = LLENTRY_EXPIRED; 257 else 258 evt = LLENTRY_TIMEDOUT; 259 EVENTHANDLER_INVOKE(lle_event, lle, evt); 260 } 261 262 callout_stop(&lle->lle_timer); 263 264 /* XXX: LOR avoidance. We still have ref on lle. */ 265 LLE_WUNLOCK(lle); 266 IF_AFDATA_LOCK(ifp); 267 LLE_WLOCK(lle); 268 269 /* Guard against race with other llentry_free(). */ 270 if (lle->la_flags & LLE_LINKED) { 271 LLE_REMREF(lle); 272 lltable_unlink_entry(lle->lle_tbl, lle); 273 } 274 IF_AFDATA_UNLOCK(ifp); 275 276 size_t pkts_dropped = llentry_free(lle); 277 278 ARPSTAT_ADD(dropped, pkts_dropped); 279 ARPSTAT_INC(timeouts); 280 281 CURVNET_RESTORE(); 282 } 283 284 /* 285 * Broadcast an ARP request. Caller specifies: 286 * - arp header source ip address 287 * - arp header target ip address 288 * - arp header source ethernet address 289 */ 290 void 291 arprequest(struct ifnet *ifp, const struct in_addr *sip, 292 const struct in_addr *tip, u_char *enaddr) 293 { 294 struct mbuf *m; 295 struct arphdr *ah; 296 struct sockaddr sa; 297 u_char *carpaddr = NULL; 298 299 if (sip == NULL) { 300 /* 301 * The caller did not supply a source address, try to find 302 * a compatible one among those assigned to this interface. 303 */ 304 struct ifaddr *ifa; 305 306 IF_ADDR_RLOCK(ifp); 307 TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) { 308 if (ifa->ifa_addr->sa_family != AF_INET) 309 continue; 310 311 if (ifa->ifa_carp) { 312 if ((*carp_iamatch_p)(ifa, &carpaddr) == 0) 313 continue; 314 sip = &IA_SIN(ifa)->sin_addr; 315 } else { 316 carpaddr = NULL; 317 sip = &IA_SIN(ifa)->sin_addr; 318 } 319 320 if (0 == ((sip->s_addr ^ tip->s_addr) & 321 IA_MASKSIN(ifa)->sin_addr.s_addr)) 322 break; /* found it. */ 323 } 324 IF_ADDR_RUNLOCK(ifp); 325 if (sip == NULL) { 326 printf("%s: cannot find matching address\n", __func__); 327 return; 328 } 329 } 330 if (enaddr == NULL) 331 enaddr = carpaddr ? carpaddr : (u_char *)IF_LLADDR(ifp); 332 333 if ((m = m_gethdr(M_NOWAIT, MT_DATA)) == NULL) 334 return; 335 m->m_len = sizeof(*ah) + 2 * sizeof(struct in_addr) + 336 2 * ifp->if_addrlen; 337 m->m_pkthdr.len = m->m_len; 338 M_ALIGN(m, m->m_len); 339 ah = mtod(m, struct arphdr *); 340 bzero((caddr_t)ah, m->m_len); 341 #ifdef MAC 342 mac_netinet_arp_send(ifp, m); 343 #endif 344 ah->ar_pro = htons(ETHERTYPE_IP); 345 ah->ar_hln = ifp->if_addrlen; /* hardware address length */ 346 ah->ar_pln = sizeof(struct in_addr); /* protocol address length */ 347 ah->ar_op = htons(ARPOP_REQUEST); 348 bcopy(enaddr, ar_sha(ah), ah->ar_hln); 349 bcopy(sip, ar_spa(ah), ah->ar_pln); 350 bcopy(tip, ar_tpa(ah), ah->ar_pln); 351 sa.sa_family = AF_ARP; 352 sa.sa_len = 2; 353 m->m_flags |= M_BCAST; 354 m_clrprotoflags(m); /* Avoid confusing lower layers. */ 355 (*ifp->if_output)(ifp, m, &sa, NULL); 356 ARPSTAT_INC(txrequests); 357 } 358 359 /* 360 * Resolve an IP address into an ethernet address - heavy version. 361 * Used internally by arpresolve(). 362 * We have already checked than we can't use existing lle without 363 * modification so we have to acquire LLE_EXCLUSIVE lle lock. 364 * 365 * On success, desten and flags are filled in and the function returns 0; 366 * If the packet must be held pending resolution, we return EWOULDBLOCK 367 * On other errors, we return the corresponding error code. 368 * Note that m_freem() handles NULL. 369 */ 370 static int 371 arpresolve_full(struct ifnet *ifp, int is_gw, int create, struct mbuf *m, 372 const struct sockaddr *dst, u_char *desten, uint32_t *pflags) 373 { 374 struct llentry *la = NULL, *la_tmp; 375 struct mbuf *curr = NULL; 376 struct mbuf *next = NULL; 377 int error, renew; 378 379 if (pflags != NULL) 380 *pflags = 0; 381 382 if (create == 0) { 383 IF_AFDATA_RLOCK(ifp); 384 la = lla_lookup(LLTABLE(ifp), LLE_EXCLUSIVE, dst); 385 IF_AFDATA_RUNLOCK(ifp); 386 } 387 if (la == NULL && (ifp->if_flags & (IFF_NOARP | IFF_STATICARP)) == 0) { 388 la = lltable_alloc_entry(LLTABLE(ifp), 0, dst); 389 if (la == NULL) { 390 log(LOG_DEBUG, 391 "arpresolve: can't allocate llinfo for %s on %s\n", 392 inet_ntoa(SIN(dst)->sin_addr), if_name(ifp)); 393 m_freem(m); 394 return (EINVAL); 395 } 396 397 IF_AFDATA_WLOCK(ifp); 398 LLE_WLOCK(la); 399 la_tmp = lla_lookup(LLTABLE(ifp), LLE_EXCLUSIVE, dst); 400 /* Prefer ANY existing lle over newly-created one */ 401 if (la_tmp == NULL) 402 lltable_link_entry(LLTABLE(ifp), la); 403 IF_AFDATA_WUNLOCK(ifp); 404 if (la_tmp != NULL) { 405 lltable_free_entry(LLTABLE(ifp), la); 406 la = la_tmp; 407 } 408 } 409 if (la == NULL) { 410 m_freem(m); 411 return (EINVAL); 412 } 413 414 if ((la->la_flags & LLE_VALID) && 415 ((la->la_flags & LLE_STATIC) || la->la_expire > time_uptime)) { 416 bcopy(&la->ll_addr, desten, ifp->if_addrlen); 417 418 /* Check if we have feedback request from arptimer() */ 419 if (la->r_skip_req != 0) { 420 LLE_REQ_LOCK(la); 421 la->r_skip_req = 0; /* Notify that entry was used */ 422 LLE_REQ_UNLOCK(la); 423 } 424 if (pflags != NULL) 425 *pflags = la->la_flags & (LLE_VALID|LLE_IFADDR); 426 LLE_WUNLOCK(la); 427 return (0); 428 } 429 430 renew = (la->la_asked == 0 || la->la_expire != time_uptime); 431 /* 432 * There is an arptab entry, but no ethernet address 433 * response yet. Add the mbuf to the list, dropping 434 * the oldest packet if we have exceeded the system 435 * setting. 436 */ 437 if (m != NULL) { 438 if (la->la_numheld >= V_arp_maxhold) { 439 if (la->la_hold != NULL) { 440 next = la->la_hold->m_nextpkt; 441 m_freem(la->la_hold); 442 la->la_hold = next; 443 la->la_numheld--; 444 ARPSTAT_INC(dropped); 445 } 446 } 447 if (la->la_hold != NULL) { 448 curr = la->la_hold; 449 while (curr->m_nextpkt != NULL) 450 curr = curr->m_nextpkt; 451 curr->m_nextpkt = m; 452 } else 453 la->la_hold = m; 454 la->la_numheld++; 455 } 456 /* 457 * Return EWOULDBLOCK if we have tried less than arp_maxtries. It 458 * will be masked by ether_output(). Return EHOSTDOWN/EHOSTUNREACH 459 * if we have already sent arp_maxtries ARP requests. Retransmit the 460 * ARP request, but not faster than one request per second. 461 */ 462 if (la->la_asked < V_arp_maxtries) 463 error = EWOULDBLOCK; /* First request. */ 464 else 465 error = is_gw != 0 ? EHOSTUNREACH : EHOSTDOWN; 466 467 if (renew) { 468 int canceled; 469 470 LLE_ADDREF(la); 471 la->la_expire = time_uptime; 472 canceled = callout_reset(&la->lle_timer, hz * V_arpt_down, 473 arptimer, la); 474 if (canceled) 475 LLE_REMREF(la); 476 la->la_asked++; 477 LLE_WUNLOCK(la); 478 arprequest(ifp, NULL, &SIN(dst)->sin_addr, NULL); 479 return (error); 480 } 481 482 LLE_WUNLOCK(la); 483 return (error); 484 } 485 486 /* 487 * Resolve an IP address into an ethernet address. 488 * On input: 489 * ifp is the interface we use 490 * is_gw != 0 if @dst represents gateway to some destination 491 * m is the mbuf. May be NULL if we don't have a packet. 492 * dst is the next hop, 493 * desten is the storage to put LL address. 494 * flags returns subset of lle flags: LLE_VALID | LLE_IFADDR 495 * 496 * On success, desten and flags are filled in and the function returns 0; 497 * If the packet must be held pending resolution, we return EWOULDBLOCK 498 * On other errors, we return the corresponding error code. 499 * Note that m_freem() handles NULL. 500 */ 501 int 502 arpresolve(struct ifnet *ifp, int is_gw, struct mbuf *m, 503 const struct sockaddr *dst, u_char *desten, uint32_t *pflags) 504 { 505 struct llentry *la = 0; 506 507 if (pflags != NULL) 508 *pflags = 0; 509 510 if (m != NULL) { 511 if (m->m_flags & M_BCAST) { 512 /* broadcast */ 513 (void)memcpy(desten, 514 ifp->if_broadcastaddr, ifp->if_addrlen); 515 return (0); 516 } 517 if (m->m_flags & M_MCAST) { 518 /* multicast */ 519 ETHER_MAP_IP_MULTICAST(&SIN(dst)->sin_addr, desten); 520 return (0); 521 } 522 } 523 524 IF_AFDATA_RLOCK(ifp); 525 la = lla_lookup(LLTABLE(ifp), LLE_UNLOCKED, dst); 526 if (la != NULL && (la->r_flags & RLLE_VALID) != 0) { 527 /* Entry found, let's copy lle info */ 528 bcopy(&la->ll_addr, desten, ifp->if_addrlen); 529 if (pflags != NULL) 530 *pflags = LLE_VALID | (la->r_flags & RLLE_IFADDR); 531 /* Check if we have feedback request from arptimer() */ 532 if (la->r_skip_req != 0) { 533 LLE_REQ_LOCK(la); 534 la->r_skip_req = 0; /* Notify that entry was used */ 535 LLE_REQ_UNLOCK(la); 536 } 537 IF_AFDATA_RUNLOCK(ifp); 538 return (0); 539 } 540 IF_AFDATA_RUNLOCK(ifp); 541 542 return (arpresolve_full(ifp, is_gw, 1, m, dst, desten, pflags)); 543 } 544 545 /* 546 * Common length and type checks are done here, 547 * then the protocol-specific routine is called. 548 */ 549 static void 550 arpintr(struct mbuf *m) 551 { 552 struct arphdr *ar; 553 struct ifnet *ifp; 554 char *layer; 555 int hlen; 556 557 ifp = m->m_pkthdr.rcvif; 558 559 if (m->m_len < sizeof(struct arphdr) && 560 ((m = m_pullup(m, sizeof(struct arphdr))) == NULL)) { 561 ARP_LOG(LOG_NOTICE, "packet with short header received on %s\n", 562 if_name(ifp)); 563 return; 564 } 565 ar = mtod(m, struct arphdr *); 566 567 /* Check if length is sufficient */ 568 if (m->m_len < arphdr_len(ar)) { 569 m = m_pullup(m, arphdr_len(ar)); 570 if (m == NULL) { 571 ARP_LOG(LOG_NOTICE, "short packet received on %s\n", 572 if_name(ifp)); 573 return; 574 } 575 ar = mtod(m, struct arphdr *); 576 } 577 578 hlen = 0; 579 layer = ""; 580 switch (ntohs(ar->ar_hrd)) { 581 case ARPHRD_ETHER: 582 hlen = ETHER_ADDR_LEN; /* RFC 826 */ 583 layer = "ethernet"; 584 break; 585 case ARPHRD_IEEE802: 586 hlen = 6; /* RFC 1390, FDDI_ADDR_LEN */ 587 layer = "fddi"; 588 break; 589 case ARPHRD_ARCNET: 590 hlen = 1; /* RFC 1201, ARC_ADDR_LEN */ 591 layer = "arcnet"; 592 break; 593 case ARPHRD_INFINIBAND: 594 hlen = 20; /* RFC 4391, INFINIBAND_ALEN */ 595 layer = "infiniband"; 596 break; 597 case ARPHRD_IEEE1394: 598 hlen = 0; /* SHALL be 16 */ /* RFC 2734 */ 599 layer = "firewire"; 600 601 /* 602 * Restrict too long harware addresses. 603 * Currently we are capable of handling 20-byte 604 * addresses ( sizeof(lle->ll_addr) ) 605 */ 606 if (ar->ar_hln >= 20) 607 hlen = 16; 608 break; 609 default: 610 ARP_LOG(LOG_NOTICE, 611 "packet with unknown harware format 0x%02d received on %s\n", 612 ntohs(ar->ar_hrd), if_name(ifp)); 613 m_freem(m); 614 return; 615 } 616 617 if (hlen != 0 && hlen != ar->ar_hln) { 618 ARP_LOG(LOG_NOTICE, 619 "packet with invalid %s address length %d received on %s\n", 620 layer, ar->ar_hln, if_name(ifp)); 621 m_freem(m); 622 return; 623 } 624 625 ARPSTAT_INC(received); 626 switch (ntohs(ar->ar_pro)) { 627 #ifdef INET 628 case ETHERTYPE_IP: 629 in_arpinput(m); 630 return; 631 #endif 632 } 633 m_freem(m); 634 } 635 636 #ifdef INET 637 /* 638 * ARP for Internet protocols on 10 Mb/s Ethernet. 639 * Algorithm is that given in RFC 826. 640 * In addition, a sanity check is performed on the sender 641 * protocol address, to catch impersonators. 642 * We no longer handle negotiations for use of trailer protocol: 643 * Formerly, ARP replied for protocol type ETHERTYPE_TRAIL sent 644 * along with IP replies if we wanted trailers sent to us, 645 * and also sent them in response to IP replies. 646 * This allowed either end to announce the desire to receive 647 * trailer packets. 648 * We no longer reply to requests for ETHERTYPE_TRAIL protocol either, 649 * but formerly didn't normally send requests. 650 */ 651 static int log_arp_wrong_iface = 1; 652 static int log_arp_movements = 1; 653 static int log_arp_permanent_modify = 1; 654 static int allow_multicast = 0; 655 656 SYSCTL_INT(_net_link_ether_inet, OID_AUTO, log_arp_wrong_iface, CTLFLAG_RW, 657 &log_arp_wrong_iface, 0, 658 "log arp packets arriving on the wrong interface"); 659 SYSCTL_INT(_net_link_ether_inet, OID_AUTO, log_arp_movements, CTLFLAG_RW, 660 &log_arp_movements, 0, 661 "log arp replies from MACs different than the one in the cache"); 662 SYSCTL_INT(_net_link_ether_inet, OID_AUTO, log_arp_permanent_modify, CTLFLAG_RW, 663 &log_arp_permanent_modify, 0, 664 "log arp replies from MACs different than the one in the permanent arp entry"); 665 SYSCTL_INT(_net_link_ether_inet, OID_AUTO, allow_multicast, CTLFLAG_RW, 666 &allow_multicast, 0, "accept multicast addresses"); 667 668 static void 669 in_arpinput(struct mbuf *m) 670 { 671 struct rm_priotracker in_ifa_tracker; 672 struct arphdr *ah; 673 struct ifnet *ifp = m->m_pkthdr.rcvif; 674 struct llentry *la = NULL, *la_tmp; 675 struct ifaddr *ifa; 676 struct in_ifaddr *ia; 677 struct sockaddr sa; 678 struct in_addr isaddr, itaddr, myaddr; 679 u_int8_t *enaddr = NULL; 680 int op; 681 int bridged = 0, is_bridge = 0; 682 int carped; 683 struct sockaddr_in sin; 684 struct sockaddr *dst; 685 struct nhop4_basic nh4; 686 687 sin.sin_len = sizeof(struct sockaddr_in); 688 sin.sin_family = AF_INET; 689 sin.sin_addr.s_addr = 0; 690 691 if (ifp->if_bridge) 692 bridged = 1; 693 if (ifp->if_type == IFT_BRIDGE) 694 is_bridge = 1; 695 696 /* 697 * We already have checked that mbuf contains enough contiguous data 698 * to hold entire arp message according to the arp header. 699 */ 700 ah = mtod(m, struct arphdr *); 701 702 /* 703 * ARP is only for IPv4 so we can reject packets with 704 * a protocol length not equal to an IPv4 address. 705 */ 706 if (ah->ar_pln != sizeof(struct in_addr)) { 707 ARP_LOG(LOG_NOTICE, "requested protocol length != %zu\n", 708 sizeof(struct in_addr)); 709 goto drop; 710 } 711 712 if (allow_multicast == 0 && ETHER_IS_MULTICAST(ar_sha(ah))) { 713 ARP_LOG(LOG_NOTICE, "%*D is multicast\n", 714 ifp->if_addrlen, (u_char *)ar_sha(ah), ":"); 715 goto drop; 716 } 717 718 op = ntohs(ah->ar_op); 719 (void)memcpy(&isaddr, ar_spa(ah), sizeof (isaddr)); 720 (void)memcpy(&itaddr, ar_tpa(ah), sizeof (itaddr)); 721 722 if (op == ARPOP_REPLY) 723 ARPSTAT_INC(rxreplies); 724 725 /* 726 * For a bridge, we want to check the address irrespective 727 * of the receive interface. (This will change slightly 728 * when we have clusters of interfaces). 729 */ 730 IN_IFADDR_RLOCK(&in_ifa_tracker); 731 LIST_FOREACH(ia, INADDR_HASH(itaddr.s_addr), ia_hash) { 732 if (((bridged && ia->ia_ifp->if_bridge == ifp->if_bridge) || 733 ia->ia_ifp == ifp) && 734 itaddr.s_addr == ia->ia_addr.sin_addr.s_addr && 735 (ia->ia_ifa.ifa_carp == NULL || 736 (*carp_iamatch_p)(&ia->ia_ifa, &enaddr))) { 737 ifa_ref(&ia->ia_ifa); 738 IN_IFADDR_RUNLOCK(&in_ifa_tracker); 739 goto match; 740 } 741 } 742 LIST_FOREACH(ia, INADDR_HASH(isaddr.s_addr), ia_hash) 743 if (((bridged && ia->ia_ifp->if_bridge == ifp->if_bridge) || 744 ia->ia_ifp == ifp) && 745 isaddr.s_addr == ia->ia_addr.sin_addr.s_addr) { 746 ifa_ref(&ia->ia_ifa); 747 IN_IFADDR_RUNLOCK(&in_ifa_tracker); 748 goto match; 749 } 750 751 #define BDG_MEMBER_MATCHES_ARP(addr, ifp, ia) \ 752 (ia->ia_ifp->if_bridge == ifp->if_softc && \ 753 !bcmp(IF_LLADDR(ia->ia_ifp), IF_LLADDR(ifp), ifp->if_addrlen) && \ 754 addr == ia->ia_addr.sin_addr.s_addr) 755 /* 756 * Check the case when bridge shares its MAC address with 757 * some of its children, so packets are claimed by bridge 758 * itself (bridge_input() does it first), but they are really 759 * meant to be destined to the bridge member. 760 */ 761 if (is_bridge) { 762 LIST_FOREACH(ia, INADDR_HASH(itaddr.s_addr), ia_hash) { 763 if (BDG_MEMBER_MATCHES_ARP(itaddr.s_addr, ifp, ia)) { 764 ifa_ref(&ia->ia_ifa); 765 ifp = ia->ia_ifp; 766 IN_IFADDR_RUNLOCK(&in_ifa_tracker); 767 goto match; 768 } 769 } 770 } 771 #undef BDG_MEMBER_MATCHES_ARP 772 IN_IFADDR_RUNLOCK(&in_ifa_tracker); 773 774 /* 775 * No match, use the first inet address on the receive interface 776 * as a dummy address for the rest of the function. 777 */ 778 IF_ADDR_RLOCK(ifp); 779 TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) 780 if (ifa->ifa_addr->sa_family == AF_INET && 781 (ifa->ifa_carp == NULL || 782 (*carp_iamatch_p)(ifa, &enaddr))) { 783 ia = ifatoia(ifa); 784 ifa_ref(ifa); 785 IF_ADDR_RUNLOCK(ifp); 786 goto match; 787 } 788 IF_ADDR_RUNLOCK(ifp); 789 790 /* 791 * If bridging, fall back to using any inet address. 792 */ 793 IN_IFADDR_RLOCK(&in_ifa_tracker); 794 if (!bridged || (ia = TAILQ_FIRST(&V_in_ifaddrhead)) == NULL) { 795 IN_IFADDR_RUNLOCK(&in_ifa_tracker); 796 goto drop; 797 } 798 ifa_ref(&ia->ia_ifa); 799 IN_IFADDR_RUNLOCK(&in_ifa_tracker); 800 match: 801 if (!enaddr) 802 enaddr = (u_int8_t *)IF_LLADDR(ifp); 803 carped = (ia->ia_ifa.ifa_carp != NULL); 804 myaddr = ia->ia_addr.sin_addr; 805 ifa_free(&ia->ia_ifa); 806 if (!bcmp(ar_sha(ah), enaddr, ifp->if_addrlen)) 807 goto drop; /* it's from me, ignore it. */ 808 if (!bcmp(ar_sha(ah), ifp->if_broadcastaddr, ifp->if_addrlen)) { 809 ARP_LOG(LOG_NOTICE, "link address is broadcast for IP address " 810 "%s!\n", inet_ntoa(isaddr)); 811 goto drop; 812 } 813 814 if (ifp->if_addrlen != ah->ar_hln) { 815 ARP_LOG(LOG_WARNING, "from %*D: addr len: new %d, " 816 "i/f %d (ignored)\n", ifp->if_addrlen, 817 (u_char *) ar_sha(ah), ":", ah->ar_hln, 818 ifp->if_addrlen); 819 goto drop; 820 } 821 822 /* 823 * Warn if another host is using the same IP address, but only if the 824 * IP address isn't 0.0.0.0, which is used for DHCP only, in which 825 * case we suppress the warning to avoid false positive complaints of 826 * potential misconfiguration. 827 */ 828 if (!bridged && !carped && isaddr.s_addr == myaddr.s_addr && 829 myaddr.s_addr != 0) { 830 ARP_LOG(LOG_ERR, "%*D is using my IP address %s on %s!\n", 831 ifp->if_addrlen, (u_char *)ar_sha(ah), ":", 832 inet_ntoa(isaddr), ifp->if_xname); 833 itaddr = myaddr; 834 ARPSTAT_INC(dupips); 835 goto reply; 836 } 837 if (ifp->if_flags & IFF_STATICARP) 838 goto reply; 839 840 bzero(&sin, sizeof(sin)); 841 sin.sin_len = sizeof(struct sockaddr_in); 842 sin.sin_family = AF_INET; 843 sin.sin_addr = isaddr; 844 dst = (struct sockaddr *)&sin; 845 IF_AFDATA_RLOCK(ifp); 846 la = lla_lookup(LLTABLE(ifp), LLE_EXCLUSIVE, dst); 847 IF_AFDATA_RUNLOCK(ifp); 848 if (la != NULL) 849 arp_check_update_lle(ah, isaddr, ifp, bridged, la); 850 else if (itaddr.s_addr == myaddr.s_addr) { 851 /* 852 * Reply to our address, but no lle exists yet. 853 * do we really have to create an entry? 854 */ 855 la = lltable_alloc_entry(LLTABLE(ifp), 0, dst); 856 if (la == NULL) 857 goto drop; 858 lltable_set_entry_addr(ifp, la, ar_sha(ah)); 859 860 IF_AFDATA_WLOCK(ifp); 861 LLE_WLOCK(la); 862 la_tmp = lla_lookup(LLTABLE(ifp), LLE_EXCLUSIVE, dst); 863 864 /* 865 * Check if lle still does not exists. 866 * If it does, that means that we either 867 * 1) have configured it explicitly, via 868 * 1a) 'arp -s' static entry or 869 * 1b) interface address static record 870 * or 871 * 2) it was the result of sending first packet to-host 872 * or 873 * 3) it was another arp reply packet we handled in 874 * different thread. 875 * 876 * In all cases except 3) we definitely need to prefer 877 * existing lle. For the sake of simplicity, prefer any 878 * existing lle over newly-create one. 879 */ 880 if (la_tmp == NULL) 881 lltable_link_entry(LLTABLE(ifp), la); 882 IF_AFDATA_WUNLOCK(ifp); 883 884 if (la_tmp == NULL) { 885 arp_mark_lle_reachable(la); 886 LLE_WUNLOCK(la); 887 } else { 888 /* Free newly-create entry and handle packet */ 889 lltable_free_entry(LLTABLE(ifp), la); 890 la = la_tmp; 891 la_tmp = NULL; 892 arp_check_update_lle(ah, isaddr, ifp, bridged, la); 893 /* arp_check_update_lle() returns @la unlocked */ 894 } 895 la = NULL; 896 } 897 reply: 898 if (op != ARPOP_REQUEST) 899 goto drop; 900 ARPSTAT_INC(rxrequests); 901 902 if (itaddr.s_addr == myaddr.s_addr) { 903 /* Shortcut.. the receiving interface is the target. */ 904 (void)memcpy(ar_tha(ah), ar_sha(ah), ah->ar_hln); 905 (void)memcpy(ar_sha(ah), enaddr, ah->ar_hln); 906 } else { 907 struct llentry *lle = NULL; 908 909 sin.sin_addr = itaddr; 910 IF_AFDATA_RLOCK(ifp); 911 lle = lla_lookup(LLTABLE(ifp), 0, (struct sockaddr *)&sin); 912 IF_AFDATA_RUNLOCK(ifp); 913 914 if ((lle != NULL) && (lle->la_flags & LLE_PUB)) { 915 (void)memcpy(ar_tha(ah), ar_sha(ah), ah->ar_hln); 916 (void)memcpy(ar_sha(ah), &lle->ll_addr, ah->ar_hln); 917 LLE_RUNLOCK(lle); 918 } else { 919 920 if (lle != NULL) 921 LLE_RUNLOCK(lle); 922 923 if (!V_arp_proxyall) 924 goto drop; 925 926 /* XXX MRT use table 0 for arp reply */ 927 if (fib4_lookup_nh_basic(0, itaddr, 0, 0, &nh4) != 0) 928 goto drop; 929 930 /* 931 * Don't send proxies for nodes on the same interface 932 * as this one came out of, or we'll get into a fight 933 * over who claims what Ether address. 934 */ 935 if (nh4.nh_ifp == ifp) 936 goto drop; 937 938 (void)memcpy(ar_tha(ah), ar_sha(ah), ah->ar_hln); 939 (void)memcpy(ar_sha(ah), enaddr, ah->ar_hln); 940 941 /* 942 * Also check that the node which sent the ARP packet 943 * is on the interface we expect it to be on. This 944 * avoids ARP chaos if an interface is connected to the 945 * wrong network. 946 */ 947 948 /* XXX MRT use table 0 for arp checks */ 949 if (fib4_lookup_nh_basic(0, isaddr, 0, 0, &nh4) != 0) 950 goto drop; 951 if (nh4.nh_ifp != ifp) { 952 ARP_LOG(LOG_INFO, "proxy: ignoring request" 953 " from %s via %s\n", 954 inet_ntoa(isaddr), ifp->if_xname); 955 goto drop; 956 } 957 958 #ifdef DEBUG_PROXY 959 printf("arp: proxying for %s\n", inet_ntoa(itaddr)); 960 #endif 961 } 962 } 963 964 if (itaddr.s_addr == myaddr.s_addr && 965 IN_LINKLOCAL(ntohl(itaddr.s_addr))) { 966 /* RFC 3927 link-local IPv4; always reply by broadcast. */ 967 #ifdef DEBUG_LINKLOCAL 968 printf("arp: sending reply for link-local addr %s\n", 969 inet_ntoa(itaddr)); 970 #endif 971 m->m_flags |= M_BCAST; 972 m->m_flags &= ~M_MCAST; 973 } else { 974 /* default behaviour; never reply by broadcast. */ 975 m->m_flags &= ~(M_BCAST|M_MCAST); 976 } 977 (void)memcpy(ar_tpa(ah), ar_spa(ah), ah->ar_pln); 978 (void)memcpy(ar_spa(ah), &itaddr, ah->ar_pln); 979 ah->ar_op = htons(ARPOP_REPLY); 980 ah->ar_pro = htons(ETHERTYPE_IP); /* let's be sure! */ 981 m->m_len = sizeof(*ah) + (2 * ah->ar_pln) + (2 * ah->ar_hln); 982 m->m_pkthdr.len = m->m_len; 983 m->m_pkthdr.rcvif = NULL; 984 sa.sa_family = AF_ARP; 985 sa.sa_len = 2; 986 m_clrprotoflags(m); /* Avoid confusing lower layers. */ 987 (*ifp->if_output)(ifp, m, &sa, NULL); 988 ARPSTAT_INC(txreplies); 989 return; 990 991 drop: 992 m_freem(m); 993 } 994 #endif 995 996 /* 997 * Checks received arp data against existing @la. 998 * Updates lle state/performs notification if necessary. 999 */ 1000 static void 1001 arp_check_update_lle(struct arphdr *ah, struct in_addr isaddr, struct ifnet *ifp, 1002 int bridged, struct llentry *la) 1003 { 1004 struct sockaddr sa; 1005 struct mbuf *m_hold, *m_hold_next; 1006 1007 LLE_WLOCK_ASSERT(la); 1008 1009 /* the following is not an error when doing bridging */ 1010 if (!bridged && la->lle_tbl->llt_ifp != ifp) { 1011 if (log_arp_wrong_iface) 1012 ARP_LOG(LOG_WARNING, "%s is on %s " 1013 "but got reply from %*D on %s\n", 1014 inet_ntoa(isaddr), 1015 la->lle_tbl->llt_ifp->if_xname, 1016 ifp->if_addrlen, (u_char *)ar_sha(ah), ":", 1017 ifp->if_xname); 1018 LLE_WUNLOCK(la); 1019 return; 1020 } 1021 if ((la->la_flags & LLE_VALID) && 1022 bcmp(ar_sha(ah), &la->ll_addr, ifp->if_addrlen)) { 1023 if (la->la_flags & LLE_STATIC) { 1024 LLE_WUNLOCK(la); 1025 if (log_arp_permanent_modify) 1026 ARP_LOG(LOG_ERR, 1027 "%*D attempts to modify " 1028 "permanent entry for %s on %s\n", 1029 ifp->if_addrlen, 1030 (u_char *)ar_sha(ah), ":", 1031 inet_ntoa(isaddr), ifp->if_xname); 1032 return; 1033 } 1034 if (log_arp_movements) { 1035 ARP_LOG(LOG_INFO, "%s moved from %*D " 1036 "to %*D on %s\n", 1037 inet_ntoa(isaddr), 1038 ifp->if_addrlen, 1039 (u_char *)&la->ll_addr, ":", 1040 ifp->if_addrlen, (u_char *)ar_sha(ah), ":", 1041 ifp->if_xname); 1042 } 1043 } 1044 1045 /* Check if something has changed */ 1046 if (memcmp(&la->ll_addr, ar_sha(ah), ifp->if_addrlen) != 0 || 1047 (la->la_flags & LLE_VALID) == 0) { 1048 /* Perform real LLE update */ 1049 /* use afdata WLOCK to update fields */ 1050 LLE_ADDREF(la); 1051 LLE_WUNLOCK(la); 1052 IF_AFDATA_WLOCK(ifp); 1053 LLE_WLOCK(la); 1054 1055 /* 1056 * Since we droppped LLE lock, other thread might have deleted 1057 * this lle. Check and return 1058 */ 1059 if ((la->la_flags & LLE_DELETED) != 0) { 1060 IF_AFDATA_WUNLOCK(ifp); 1061 LLE_FREE_LOCKED(la); 1062 return; 1063 } 1064 1065 /* Update data */ 1066 lltable_set_entry_addr(ifp, la, ar_sha(ah)); 1067 1068 IF_AFDATA_WUNLOCK(ifp); 1069 LLE_REMREF(la); 1070 1071 /* Clear fast path feedback request if set */ 1072 la->r_skip_req = 0; 1073 } 1074 1075 arp_mark_lle_reachable(la); 1076 1077 /* 1078 * The packets are all freed within the call to the output 1079 * routine. 1080 * 1081 * NB: The lock MUST be released before the call to the 1082 * output routine. 1083 */ 1084 if (la->la_hold != NULL) { 1085 m_hold = la->la_hold; 1086 la->la_hold = NULL; 1087 la->la_numheld = 0; 1088 lltable_fill_sa_entry(la, &sa); 1089 LLE_WUNLOCK(la); 1090 for (; m_hold != NULL; m_hold = m_hold_next) { 1091 m_hold_next = m_hold->m_nextpkt; 1092 m_hold->m_nextpkt = NULL; 1093 /* Avoid confusing lower layers. */ 1094 m_clrprotoflags(m_hold); 1095 (*ifp->if_output)(ifp, m_hold, &sa, NULL); 1096 } 1097 } else 1098 LLE_WUNLOCK(la); 1099 } 1100 1101 static void 1102 arp_mark_lle_reachable(struct llentry *la) 1103 { 1104 int canceled, wtime; 1105 1106 LLE_WLOCK_ASSERT(la); 1107 1108 la->ln_state = ARP_LLINFO_REACHABLE; 1109 EVENTHANDLER_INVOKE(lle_event, la, LLENTRY_RESOLVED); 1110 1111 if (!(la->la_flags & LLE_STATIC)) { 1112 LLE_ADDREF(la); 1113 la->la_expire = time_uptime + V_arpt_keep; 1114 wtime = V_arpt_keep - V_arp_maxtries * V_arpt_rexmit; 1115 if (wtime < 0) 1116 wtime = V_arpt_keep; 1117 canceled = callout_reset(&la->lle_timer, 1118 hz * wtime, arptimer, la); 1119 if (canceled) 1120 LLE_REMREF(la); 1121 } 1122 la->la_asked = 0; 1123 la->la_preempt = V_arp_maxtries; 1124 } 1125 1126 /* 1127 * Add pernament link-layer record for given interface address. 1128 */ 1129 static __noinline void 1130 arp_add_ifa_lle(struct ifnet *ifp, const struct sockaddr *dst) 1131 { 1132 struct llentry *lle, *lle_tmp; 1133 1134 /* 1135 * Interface address LLE record is considered static 1136 * because kernel code relies on LLE_STATIC flag to check 1137 * if these entries can be rewriten by arp updates. 1138 */ 1139 lle = lltable_alloc_entry(LLTABLE(ifp), LLE_IFADDR | LLE_STATIC, dst); 1140 if (lle == NULL) { 1141 log(LOG_INFO, "arp_ifinit: cannot create arp " 1142 "entry for interface address\n"); 1143 return; 1144 } 1145 1146 IF_AFDATA_WLOCK(ifp); 1147 LLE_WLOCK(lle); 1148 /* Unlink any entry if exists */ 1149 lle_tmp = lla_lookup(LLTABLE(ifp), LLE_EXCLUSIVE, dst); 1150 if (lle_tmp != NULL) 1151 lltable_unlink_entry(LLTABLE(ifp), lle_tmp); 1152 1153 lltable_link_entry(LLTABLE(ifp), lle); 1154 IF_AFDATA_WUNLOCK(ifp); 1155 1156 if (lle_tmp != NULL) 1157 EVENTHANDLER_INVOKE(lle_event, lle_tmp, LLENTRY_EXPIRED); 1158 1159 EVENTHANDLER_INVOKE(lle_event, lle, LLENTRY_RESOLVED); 1160 LLE_WUNLOCK(lle); 1161 if (lle_tmp != NULL) 1162 lltable_free_entry(LLTABLE(ifp), lle_tmp); 1163 } 1164 1165 void 1166 arp_ifinit(struct ifnet *ifp, struct ifaddr *ifa) 1167 { 1168 const struct sockaddr_in *dst_in; 1169 const struct sockaddr *dst; 1170 1171 if (ifa->ifa_carp != NULL) 1172 return; 1173 1174 dst = ifa->ifa_addr; 1175 dst_in = (const struct sockaddr_in *)dst; 1176 1177 if (ntohl(dst_in->sin_addr.s_addr) == INADDR_ANY) 1178 return; 1179 arp_announce_ifaddr(ifp, dst_in->sin_addr, IF_LLADDR(ifp)); 1180 1181 arp_add_ifa_lle(ifp, dst); 1182 } 1183 1184 void 1185 arp_announce_ifaddr(struct ifnet *ifp, struct in_addr addr, u_char *enaddr) 1186 { 1187 1188 if (ntohl(addr.s_addr) != INADDR_ANY) 1189 arprequest(ifp, &addr, &addr, enaddr); 1190 } 1191 1192 /* 1193 * Sends gratuitous ARPs for each ifaddr to notify other 1194 * nodes about the address change. 1195 */ 1196 static __noinline void 1197 arp_handle_ifllchange(struct ifnet *ifp) 1198 { 1199 struct ifaddr *ifa; 1200 1201 TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) { 1202 if (ifa->ifa_addr->sa_family == AF_INET) 1203 arp_ifinit(ifp, ifa); 1204 } 1205 } 1206 1207 /* 1208 * A handler for interface link layer address change event. 1209 */ 1210 static __noinline void 1211 arp_iflladdr(void *arg __unused, struct ifnet *ifp) 1212 { 1213 1214 if ((ifp->if_flags & IFF_UP) != 0) 1215 arp_handle_ifllchange(ifp); 1216 } 1217 1218 static void 1219 arp_init(void) 1220 { 1221 1222 netisr_register(&arp_nh); 1223 if (IS_DEFAULT_VNET(curvnet)) 1224 iflladdr_tag = EVENTHANDLER_REGISTER(iflladdr_event, 1225 arp_iflladdr, NULL, EVENTHANDLER_PRI_ANY); 1226 } 1227 SYSINIT(arp, SI_SUB_PROTO_DOMAIN, SI_ORDER_ANY, arp_init, 0); 1228