2 * Copyright (c) 1982, 1986, 1988, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * @(#)if_ether.c 8.1 (Berkeley) 6/10/93
38 * Ethernet address resolution protocol.
40 * add "inuse/lock" bit (or ref. count) along with valid bit
46 #include <sys/param.h>
47 #include <sys/kernel.h>
48 #include <sys/queue.h>
49 #include <sys/sysctl.h>
50 #include <sys/systm.h>
52 #include <sys/malloc.h>
53 #include <sys/socket.h>
54 #include <sys/syslog.h>
57 #include <net/if_dl.h>
58 #include <net/if_types.h>
59 #include <net/route.h>
60 #include <net/netisr.h>
62 #include <netinet/in.h>
63 #include <netinet/in_var.h>
64 #include <netinet/if_ether.h>
66 #include <net/iso88025.h>
68 #define SIN(s) ((struct sockaddr_in *)s)
69 #define SDL(s) ((struct sockaddr_dl *)s)
71 SYSCTL_DECL(_net_link_ether);
72 SYSCTL_NODE(_net_link_ether, PF_INET, inet, CTLFLAG_RW, 0, "");
75 static int arpt_prune = (5*60*1); /* walk list every 5 minutes */
76 static int arpt_keep = (20*60); /* once resolved, good for 20 more minutes */
77 static int arpt_down = 20; /* once declared down, don't send for 20 sec */
79 SYSCTL_INT(_net_link_ether_inet, OID_AUTO, prune_intvl, CTLFLAG_RW,
81 SYSCTL_INT(_net_link_ether_inet, OID_AUTO, max_age, CTLFLAG_RW,
83 SYSCTL_INT(_net_link_ether_inet, OID_AUTO, host_down_time, CTLFLAG_RW,
86 #define rt_expire rt_rmx.rmx_expire
89 LIST_ENTRY(llinfo_arp) la_le;
90 struct rtentry *la_rt;
91 struct mbuf *la_hold; /* last packet until resolved/timeout */
92 long la_asked; /* last time we QUERIED for this addr */
93 #define la_timer la_rt->rt_rmx.rmx_expire /* deletion time in seconds */
96 static LIST_HEAD(, llinfo_arp) llinfo_arp;
98 struct ifqueue arpintrq = {0, 0, 0, 50};
99 static int arp_inuse, arp_allocated;
101 static int arp_maxtries = 5;
102 static int useloopback = 1; /* use loopback interface for local traffic */
103 static int arp_proxyall = 0;
105 SYSCTL_INT(_net_link_ether_inet, OID_AUTO, maxtries, CTLFLAG_RW,
106 &arp_maxtries, 0, "");
107 SYSCTL_INT(_net_link_ether_inet, OID_AUTO, useloopback, CTLFLAG_RW,
108 &useloopback, 0, "");
109 SYSCTL_INT(_net_link_ether_inet, OID_AUTO, proxyall, CTLFLAG_RW,
110 &arp_proxyall, 0, "");
112 static void arp_rtrequest __P((int, struct rtentry *, struct sockaddr *));
113 static void arprequest __P((struct arpcom *,
114 struct in_addr *, struct in_addr *, u_char *));
115 static void arpintr __P((void));
116 static void arptfree __P((struct llinfo_arp *));
117 static void arptimer __P((void *));
118 static struct llinfo_arp
119 *arplookup __P((u_long, int, int));
121 static void in_arpinput __P((struct mbuf *));
125 * Timeout routine. Age arp_tab entries periodically.
129 arptimer(ignored_arg)
133 register struct llinfo_arp *la = llinfo_arp.lh_first;
134 struct llinfo_arp *ola;
136 timeout(arptimer, (caddr_t)0, arpt_prune * hz);
137 while ((ola = la) != 0) {
138 register struct rtentry *rt = la->la_rt;
139 la = la->la_le.le_next;
140 if (rt->rt_expire && rt->rt_expire <= time_second)
141 arptfree(ola); /* timer has expired, clear */
147 * Parallel to llc_rtrequest.
150 arp_rtrequest(req, rt, sa)
152 register struct rtentry *rt;
155 register struct sockaddr *gate = rt->rt_gateway;
156 register struct llinfo_arp *la = (struct llinfo_arp *)rt->rt_llinfo;
157 static struct sockaddr_dl null_sdl = {sizeof(null_sdl), AF_LINK};
158 static int arpinit_done;
162 LIST_INIT(&llinfo_arp);
163 timeout(arptimer, (caddr_t)0, hz);
165 if (rt->rt_flags & RTF_GATEWAY)
171 * XXX: If this is a manually added route to interface
172 * such as older version of routed or gated might provide,
173 * restore cloning bit.
175 if ((rt->rt_flags & RTF_HOST) == 0 &&
176 SIN(rt_mask(rt))->sin_addr.s_addr != 0xffffffff)
177 rt->rt_flags |= RTF_CLONING;
178 if (rt->rt_flags & RTF_CLONING) {
180 * Case 1: This route should come from a route to iface.
182 rt_setgate(rt, rt_key(rt),
183 (struct sockaddr *)&null_sdl);
184 gate = rt->rt_gateway;
185 SDL(gate)->sdl_type = rt->rt_ifp->if_type;
186 SDL(gate)->sdl_index = rt->rt_ifp->if_index;
187 rt->rt_expire = time_second;
190 /* Announce a new entry if requested. */
191 if (rt->rt_flags & RTF_ANNOUNCE)
192 arprequest((struct arpcom *)rt->rt_ifp,
193 &SIN(rt_key(rt))->sin_addr,
194 &SIN(rt_key(rt))->sin_addr,
195 (u_char *)LLADDR(SDL(gate)));
198 if (gate->sa_family != AF_LINK ||
199 gate->sa_len < sizeof(null_sdl)) {
200 log(LOG_DEBUG, "arp_rtrequest: bad gateway value\n");
203 SDL(gate)->sdl_type = rt->rt_ifp->if_type;
204 SDL(gate)->sdl_index = rt->rt_ifp->if_index;
206 break; /* This happens on a route change */
208 * Case 2: This route may come from cloning, or a manual route
209 * add with a LL address.
211 R_Malloc(la, struct llinfo_arp *, sizeof(*la));
212 rt->rt_llinfo = (caddr_t)la;
214 log(LOG_DEBUG, "arp_rtrequest: malloc failed\n");
217 arp_inuse++, arp_allocated++;
218 Bzero(la, sizeof(*la));
220 rt->rt_flags |= RTF_LLINFO;
221 LIST_INSERT_HEAD(&llinfo_arp, la, la_le);
225 * This keeps the multicast addresses from showing up
226 * in `arp -a' listings as unresolved. It's not actually
227 * functional. Then the same for broadcast.
229 if (IN_MULTICAST(ntohl(SIN(rt_key(rt))->sin_addr.s_addr))) {
230 ETHER_MAP_IP_MULTICAST(&SIN(rt_key(rt))->sin_addr,
232 SDL(gate)->sdl_alen = 6;
235 if (in_broadcast(SIN(rt_key(rt))->sin_addr, rt->rt_ifp)) {
236 memcpy(LLADDR(SDL(gate)), etherbroadcastaddr, 6);
237 SDL(gate)->sdl_alen = 6;
242 if (SIN(rt_key(rt))->sin_addr.s_addr ==
243 (IA_SIN(rt->rt_ifa))->sin_addr.s_addr) {
245 * This test used to be
246 * if (loif.if_flags & IFF_UP)
247 * It allowed local traffic to be forced
248 * through the hardware by configuring the loopback down.
249 * However, it causes problems during network configuration
250 * for boards that can't receive packets they send.
251 * It is now necessary to clear "useloopback" and remove
252 * the route to force traffic out to the hardware.
255 Bcopy(((struct arpcom *)rt->rt_ifp)->ac_enaddr,
256 LLADDR(SDL(gate)), SDL(gate)->sdl_alen = 6);
267 LIST_REMOVE(la, la_le);
269 rt->rt_flags &= ~RTF_LLINFO;
271 m_freem(la->la_hold);
277 * Broadcast an ARP request. Caller specifies:
278 * - arp header source ip address
279 * - arp header target ip address
280 * - arp header source ethernet address
283 arprequest(ac, sip, tip, enaddr)
284 register struct arpcom *ac;
285 register struct in_addr *sip, *tip;
286 register u_char *enaddr;
288 register struct mbuf *m;
289 register struct ether_header *eh;
290 register struct ether_arp *ea;
293 if ((m = m_gethdr(M_DONTWAIT, MT_DATA)) == NULL)
295 m->m_pkthdr.rcvif = (struct ifnet *)0;
296 switch (ac->ac_if.if_type) {
298 m->m_len = sizeof(*ea) + 10;
299 m->m_pkthdr.len = sizeof(*ea) + 10;
300 MH_ALIGN(m, sizeof(*ea) + 10);
301 (void)memcpy(mtod(m, caddr_t),
302 "\x82\x40\xaa\xaa\x03\x00\x00\x00\x08\x06", 10);
303 (void)memcpy(sa.sa_data, etherbroadcastaddr, 6);
304 (void)memcpy(sa.sa_data + 6, enaddr, 6);
305 sa.sa_data[6] |= 0x80;
306 sa.sa_data[12] = 0x10;
307 sa.sa_data[13] = 0x40;
308 ea = (struct ether_arp *)(mtod(m, char *) + 10);
309 bzero((caddr_t)ea, sizeof (*ea));
310 ea->arp_hrd = htons(ARPHRD_IEEE802);
315 * This may not be correct for types not explicitly
316 * listed, but this is our best guess
319 m->m_len = sizeof(*ea);
320 m->m_pkthdr.len = sizeof(*ea);
321 MH_ALIGN(m, sizeof(*ea));
322 ea = mtod(m, struct ether_arp *);
323 eh = (struct ether_header *)sa.sa_data;
324 bzero((caddr_t)ea, sizeof (*ea));
325 /* if_output will not swap */
326 eh->ether_type = htons(ETHERTYPE_ARP);
327 (void)memcpy(eh->ether_dhost, etherbroadcastaddr,
328 sizeof(eh->ether_dhost));
329 ea->arp_hrd = htons(ARPHRD_ETHER);
332 ea->arp_pro = htons(ETHERTYPE_IP);
333 ea->arp_hln = sizeof(ea->arp_sha); /* hardware address length */
334 ea->arp_pln = sizeof(ea->arp_spa); /* protocol address length */
335 ea->arp_op = htons(ARPOP_REQUEST);
336 (void)memcpy(ea->arp_sha, enaddr, sizeof(ea->arp_sha));
337 (void)memcpy(ea->arp_spa, sip, sizeof(ea->arp_spa));
338 (void)memcpy(ea->arp_tpa, tip, sizeof(ea->arp_tpa));
339 sa.sa_family = AF_UNSPEC;
340 sa.sa_len = sizeof(sa);
341 (*ac->ac_if.if_output)(&ac->ac_if, m, &sa, (struct rtentry *)0);
345 * Resolve an IP address into an ethernet address. If success,
346 * desten is filled in. If there is no entry in arptab,
347 * set one up and broadcast a request for the IP address.
348 * Hold onto this mbuf and resend it once the address
349 * is finally resolved. A return value of 1 indicates
350 * that desten has been filled in and the packet should be sent
351 * normally; a 0 return indicates that the packet has been
352 * taken over here, either now or for later transmission.
355 arpresolve(ac, rt, m, dst, desten, rt0)
356 register struct arpcom *ac;
357 register struct rtentry *rt;
359 register struct sockaddr *dst;
360 register u_char *desten;
363 register struct llinfo_arp *la = 0;
364 struct sockaddr_dl *sdl;
366 if (m->m_flags & M_BCAST) { /* broadcast */
367 (void)memcpy(desten, etherbroadcastaddr, sizeof(etherbroadcastaddr));
370 if (m->m_flags & M_MCAST) { /* multicast */
371 ETHER_MAP_IP_MULTICAST(&SIN(dst)->sin_addr, desten);
375 la = (struct llinfo_arp *)rt->rt_llinfo;
377 la = arplookup(SIN(dst)->sin_addr.s_addr, 1, 0);
381 if (la == 0 || rt == 0) {
382 log(LOG_DEBUG, "arpresolve: can't allocate llinfo for %s%s%s\n",
383 inet_ntoa(SIN(dst)->sin_addr), la ? "la" : "",
388 sdl = SDL(rt->rt_gateway);
390 * Check the address family and length is valid, the address
391 * is resolved; otherwise, try to resolve.
393 if ((rt->rt_expire == 0 || rt->rt_expire > time_second) &&
394 sdl->sdl_family == AF_LINK && sdl->sdl_alen != 0) {
395 bcopy(LLADDR(sdl), desten, sdl->sdl_alen);
399 * There is an arptab entry, but no ethernet address
400 * response yet. Replace the held mbuf with this
404 m_freem(la->la_hold);
407 rt->rt_flags &= ~RTF_REJECT;
408 if (la->la_asked == 0 || rt->rt_expire != time_second) {
409 rt->rt_expire = time_second;
410 if (la->la_asked++ < arp_maxtries)
412 &SIN(rt->rt_ifa->ifa_addr)->sin_addr,
413 &SIN(dst)->sin_addr, ac->ac_enaddr);
415 rt->rt_flags |= RTF_REJECT;
416 rt->rt_expire += arpt_down;
426 * Common length and type checks are done here,
427 * then the protocol-specific routine is called.
432 register struct mbuf *m;
433 register struct arphdr *ar;
436 while (arpintrq.ifq_head) {
438 IF_DEQUEUE(&arpintrq, m);
440 if (m == 0 || (m->m_flags & M_PKTHDR) == 0)
442 if (m->m_len >= sizeof(struct arphdr) &&
443 (ar = mtod(m, struct arphdr *)) &&
444 (ntohs(ar->ar_hrd) == ARPHRD_ETHER ||
445 ntohs(ar->ar_hrd) == ARPHRD_IEEE802) &&
447 sizeof(struct arphdr) + 2 * ar->ar_hln + 2 * ar->ar_pln)
449 switch (ntohs(ar->ar_pro)) {
461 NETISR_SET(NETISR_ARP, arpintr);
466 * ARP for Internet protocols on 10 Mb/s Ethernet.
467 * Algorithm is that given in RFC 826.
468 * In addition, a sanity check is performed on the sender
469 * protocol address, to catch impersonators.
470 * We no longer handle negotiations for use of trailer protocol:
471 * Formerly, ARP replied for protocol type ETHERTYPE_TRAIL sent
472 * along with IP replies if we wanted trailers sent to us,
473 * and also sent them in response to IP replies.
474 * This allowed either end to announce the desire to receive
476 * We no longer reply to requests for ETHERTYPE_TRAIL protocol either,
477 * but formerly didn't normally send requests.
483 register struct ether_arp *ea;
484 register struct arpcom *ac = (struct arpcom *)m->m_pkthdr.rcvif;
485 struct ether_header *eh;
486 struct iso88025_header *th = (struct iso88025_header *)0;
487 register struct llinfo_arp *la = 0;
488 register struct rtentry *rt;
489 struct in_ifaddr *ia, *maybe_ia = 0;
490 struct sockaddr_dl *sdl;
492 struct in_addr isaddr, itaddr, myaddr;
495 ea = mtod(m, struct ether_arp *);
496 op = ntohs(ea->arp_op);
497 (void)memcpy(&isaddr, ea->arp_spa, sizeof (isaddr));
498 (void)memcpy(&itaddr, ea->arp_tpa, sizeof (itaddr));
499 for (ia = in_ifaddrhead.tqh_first; ia; ia = ia->ia_link.tqe_next)
502 * For a bridge, we want to check the address irrespective
503 * of the receive interface. (This will change slightly
504 * when we have clusters of interfaces).
508 if (ia->ia_ifp == &ac->ac_if) {
511 if ((itaddr.s_addr == ia->ia_addr.sin_addr.s_addr) ||
512 (isaddr.s_addr == ia->ia_addr.sin_addr.s_addr))
519 myaddr = ia ? ia->ia_addr.sin_addr : maybe_ia->ia_addr.sin_addr;
520 if (!bcmp((caddr_t)ea->arp_sha, (caddr_t)ac->ac_enaddr,
521 sizeof (ea->arp_sha))) {
522 m_freem(m); /* it's from me, ignore it. */
525 if (!bcmp((caddr_t)ea->arp_sha, (caddr_t)etherbroadcastaddr,
526 sizeof (ea->arp_sha))) {
528 "arp: ether address is broadcast for IP address %s!\n",
533 if (isaddr.s_addr == myaddr.s_addr) {
535 "arp: %6D is using my IP address %s!\n",
536 ea->arp_sha, ":", inet_ntoa(isaddr));
540 la = arplookup(isaddr.s_addr, itaddr.s_addr == myaddr.s_addr, 0);
541 if (la && (rt = la->la_rt) && (sdl = SDL(rt->rt_gateway))) {
542 #ifndef BRIDGE /* the following is not an error when doing bridging */
543 if (rt->rt_ifp != &ac->ac_if) {
544 log(LOG_ERR, "arp: %s is on %s%d but got reply from %6D on %s%d\n",
546 rt->rt_ifp->if_name, rt->rt_ifp->if_unit,
548 ac->ac_if.if_name, ac->ac_if.if_unit);
553 bcmp((caddr_t)ea->arp_sha, LLADDR(sdl), sdl->sdl_alen)) {
555 log(LOG_INFO, "arp: %s moved from %6D to %6D on %s%d\n",
556 inet_ntoa(isaddr), (u_char *)LLADDR(sdl), ":",
558 ac->ac_if.if_name, ac->ac_if.if_unit);
561 "arp: %6D attempts to modify permanent entry for %s on %s%d\n",
562 ea->arp_sha, ":", inet_ntoa(isaddr),
563 ac->ac_if.if_name, ac->ac_if.if_unit);
567 (void)memcpy(LLADDR(sdl), ea->arp_sha, sizeof(ea->arp_sha));
568 sdl->sdl_alen = sizeof(ea->arp_sha);
571 * If we receive an arp from a token-ring station over
572 * a token-ring nic then try to save the source
575 if (ac->ac_if.if_type == IFT_ISO88025) {
576 th = (struct iso88025_header *)m->m_pkthdr.header;
577 if ((th->iso88025_shost[0] & 0x80) &&
578 ((th->rcf & 0x001f) > 2)) {
579 sdl->sdl_rcf = (th->rcf & 0x8000) ?
582 memcpy(sdl->sdl_route, th->rseg,
583 (th->rcf & 0x001f) - 2);
584 sdl->sdl_rcf = sdl->sdl_rcf & 0xff1f;
586 * Set up source routing information for
589 m->m_data -= (th->rcf & 0x001f);
590 m->m_len += (th->rcf & 0x001f);
591 m->m_pkthdr.len += (th->rcf & 0x001f);
593 th->iso88025_shost[0] &= 0x7f;
597 m->m_pkthdr.len += 8;
598 th->rcf = sdl->sdl_rcf;
603 rt->rt_expire = time_second + arpt_keep;
604 rt->rt_flags &= ~RTF_REJECT;
607 (*ac->ac_if.if_output)(&ac->ac_if, la->la_hold,
613 if (op != ARPOP_REQUEST) {
617 if (itaddr.s_addr == myaddr.s_addr) {
618 /* I am the target */
619 (void)memcpy(ea->arp_tha, ea->arp_sha, sizeof(ea->arp_sha));
620 (void)memcpy(ea->arp_sha, ac->ac_enaddr, sizeof(ea->arp_sha));
622 la = arplookup(itaddr.s_addr, 0, SIN_PROXY);
624 struct sockaddr_in sin;
631 bzero(&sin, sizeof sin);
632 sin.sin_family = AF_INET;
633 sin.sin_len = sizeof sin;
634 sin.sin_addr = itaddr;
636 rt = rtalloc1((struct sockaddr *)&sin, 0, 0UL);
642 * Don't send proxies for nodes on the same interface
643 * as this one came out of, or we'll get into a fight
644 * over who claims what Ether address.
646 if (rt->rt_ifp == &ac->ac_if) {
651 (void)memcpy(ea->arp_tha, ea->arp_sha, sizeof(ea->arp_sha));
652 (void)memcpy(ea->arp_sha, ac->ac_enaddr, sizeof(ea->arp_sha));
655 printf("arp: proxying for %s\n",
660 (void)memcpy(ea->arp_tha, ea->arp_sha, sizeof(ea->arp_sha));
661 sdl = SDL(rt->rt_gateway);
662 (void)memcpy(ea->arp_sha, LLADDR(sdl), sizeof(ea->arp_sha));
666 (void)memcpy(ea->arp_tpa, ea->arp_spa, sizeof(ea->arp_spa));
667 (void)memcpy(ea->arp_spa, &itaddr, sizeof(ea->arp_spa));
668 ea->arp_op = htons(ARPOP_REPLY);
669 ea->arp_pro = htons(ETHERTYPE_IP); /* let's be sure! */
670 switch (ac->ac_if.if_type) {
672 /* Re-arrange the source/dest address */
673 memcpy(th->iso88025_dhost, th->iso88025_shost,
674 sizeof(th->iso88025_dhost));
675 memcpy(th->iso88025_shost, ac->ac_enaddr,
676 sizeof(th->iso88025_shost));
677 /* Set the source routing bit if neccesary */
678 if (th->iso88025_dhost[0] & 0x80) {
679 th->iso88025_dhost[0] &= 0x7f;
680 if ((th->rcf & 0x001f) - 2)
681 th->iso88025_shost[0] |= 0x80;
683 /* Copy the addresses, ac and fc into sa_data */
684 memcpy(sa.sa_data, th->iso88025_dhost,
685 sizeof(th->iso88025_dhost) * 2);
686 sa.sa_data[(sizeof(th->iso88025_dhost) * 2)] = 0x10;
687 sa.sa_data[(sizeof(th->iso88025_dhost) * 2) + 1] = 0x40;
692 * May not be correct for types not explictly
693 * listed, but it is our best guess.
696 eh = (struct ether_header *)sa.sa_data;
697 (void)memcpy(eh->ether_dhost, ea->arp_tha,
698 sizeof(eh->ether_dhost));
699 eh->ether_type = htons(ETHERTYPE_ARP);
702 sa.sa_family = AF_UNSPEC;
703 sa.sa_len = sizeof(sa);
704 (*ac->ac_if.if_output)(&ac->ac_if, m, &sa, (struct rtentry *)0);
714 register struct llinfo_arp *la;
716 register struct rtentry *rt = la->la_rt;
717 register struct sockaddr_dl *sdl;
720 if (rt->rt_refcnt > 0 && (sdl = SDL(rt->rt_gateway)) &&
721 sdl->sdl_family == AF_LINK) {
724 rt->rt_flags &= ~RTF_REJECT;
727 rtrequest(RTM_DELETE, rt_key(rt), (struct sockaddr *)0, rt_mask(rt),
728 0, (struct rtentry **)0);
731 * Lookup or enter a new address in arptab.
733 static struct llinfo_arp *
734 arplookup(addr, create, proxy)
738 register struct rtentry *rt;
739 static struct sockaddr_inarp sin = {sizeof(sin), AF_INET };
742 sin.sin_addr.s_addr = addr;
743 sin.sin_other = proxy ? SIN_PROXY : 0;
744 rt = rtalloc1((struct sockaddr *)&sin, create, 0UL);
749 if (rt->rt_flags & RTF_GATEWAY)
750 why = "host is not on local network";
751 else if ((rt->rt_flags & RTF_LLINFO) == 0)
752 why = "could not allocate llinfo";
753 else if (rt->rt_gateway->sa_family != AF_LINK)
754 why = "gateway route is not ours";
757 log(LOG_DEBUG, "arplookup %s failed: %s\n",
758 inet_ntoa(sin.sin_addr), why);
763 return ((struct llinfo_arp *)rt->rt_llinfo);
771 if (ntohl(IA_SIN(ifa)->sin_addr.s_addr) != INADDR_ANY)
772 arprequest(ac, &IA_SIN(ifa)->sin_addr,
773 &IA_SIN(ifa)->sin_addr, ac->ac_enaddr);
774 ifa->ifa_rtrequest = arp_rtrequest;
775 ifa->ifa_flags |= RTF_CLONING;