1 //==========================================================================
3 // src/sys/netinet/if_ether.c
5 //==========================================================================
6 //####BSDCOPYRIGHTBEGIN####
8 // -------------------------------------------
10 // Portions of this software may have been derived from OpenBSD,
11 // FreeBSD or other sources, and are covered by the appropriate
12 // copyright disclaimers included herein.
14 // Portions created by Red Hat are
15 // Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
17 // -------------------------------------------
19 //####BSDCOPYRIGHTEND####
20 //==========================================================================
23 * Copyright (c) 1982, 1986, 1988, 1993
24 * The Regents of the University of California. All rights reserved.
26 * Redistribution and use in source and binary forms, with or without
27 * modification, are permitted provided that the following conditions
29 * 1. Redistributions of source code must retain the above copyright
30 * notice, this list of conditions and the following disclaimer.
31 * 2. Redistributions in binary form must reproduce the above copyright
32 * notice, this list of conditions and the following disclaimer in the
33 * documentation and/or other materials provided with the distribution.
34 * 3. All advertising materials mentioning features or use of this software
35 * must display the following acknowledgement:
36 * This product includes software developed by the University of
37 * California, Berkeley and its contributors.
38 * 4. Neither the name of the University nor the names of its contributors
39 * may be used to endorse or promote products derived from this software
40 * without specific prior written permission.
42 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
43 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
45 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
46 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
47 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
48 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
49 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
50 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
51 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
54 * @(#)if_ether.c 8.1 (Berkeley) 6/10/93
55 * $FreeBSD: src/sys/netinet/if_ether.c,v 1.64.2.11 2001/07/25 17:27:56 jlemon Exp $
59 * Ethernet address resolution protocol.
61 * add "inuse/lock" bit (or ref. count) along with valid bit
64 #include <sys/param.h>
65 #include <sys/queue.h>
66 #include <sys/sysctl.h>
68 #include <sys/malloc.h>
69 #include <sys/socket.h>
72 #include <net/if_dl.h>
73 #include <net/if_types.h>
74 #include <net/route.h>
75 #include <net/netisr.h>
76 #include <net/if_llc.h>
78 #include <net/ethernet.h>
79 #include <net/bridge.h>
82 #include <netinet/in.h>
83 #include <netinet/in_var.h>
84 #include <netinet/if_ether.h>
86 #include <net/iso88025.h>
88 #define SIN(s) ((struct sockaddr_in *)s)
89 #define SDL(s) ((struct sockaddr_dl *)s)
91 SYSCTL_DECL(_net_link_ether);
92 SYSCTL_NODE(_net_link_ether, PF_INET, inet, CTLFLAG_RW, 0, "");
95 static int arpt_prune = (5*60*1); /* walk list every 5 minutes */
96 static int arpt_keep = (20*60); /* once resolved, good for 20 more minutes */
97 static int arpt_down = 20; /* once declared down, don't send for 20 sec */
99 SYSCTL_INT(_net_link_ether_inet, OID_AUTO, prune_intvl, CTLFLAG_RW,
101 SYSCTL_INT(_net_link_ether_inet, OID_AUTO, max_age, CTLFLAG_RW,
103 SYSCTL_INT(_net_link_ether_inet, OID_AUTO, host_down_time, CTLFLAG_RW,
106 #define rt_expire rt_rmx.rmx_expire
109 LIST_ENTRY(llinfo_arp) la_le;
110 struct rtentry *la_rt;
111 struct mbuf *la_hold; /* last packet until resolved/timeout */
112 long la_asked; /* last time we QUERIED for this addr */
113 #define la_timer la_rt->rt_rmx.rmx_expire /* deletion time in seconds */
116 static LIST_HEAD(, llinfo_arp) llinfo_arp;
118 struct ifqueue arpintrq = {0, 0, 0, 50};
119 static int arp_inuse, arp_allocated;
121 static int arp_maxtries = 5;
122 static int useloopback = 1; /* use loopback interface for local traffic */
123 static int arp_proxyall = 0;
125 SYSCTL_INT(_net_link_ether_inet, OID_AUTO, maxtries, CTLFLAG_RW,
126 &arp_maxtries, 0, "");
127 SYSCTL_INT(_net_link_ether_inet, OID_AUTO, useloopback, CTLFLAG_RW,
128 &useloopback, 0, "");
129 SYSCTL_INT(_net_link_ether_inet, OID_AUTO, proxyall, CTLFLAG_RW,
130 &arp_proxyall, 0, "");
132 static void arp_rtrequest __P((int, struct rtentry *, struct sockaddr *));
133 static void arprequest __P((struct arpcom *,
134 struct in_addr *, struct in_addr *, u_char *));
135 static void arpintr __P((void));
136 static void arptfree __P((struct llinfo_arp *));
137 static void arptimer __P((void *));
138 static struct llinfo_arp
139 *arplookup __P((u_long, int, int));
141 static void in_arpinput __P((struct mbuf *));
145 * Timeout routine. Age arp_tab entries periodically.
149 arptimer(ignored_arg)
153 register struct llinfo_arp *la = llinfo_arp.lh_first;
154 struct llinfo_arp *ola;
156 timeout(arptimer, (caddr_t)0, arpt_prune * hz);
157 while ((ola = la) != 0) {
158 register struct rtentry *rt = la->la_rt;
159 la = la->la_le.le_next;
160 if (rt->rt_expire && rt->rt_expire <= time_second)
161 arptfree(ola); /* timer has expired, clear */
167 * Parallel to llc_rtrequest.
170 arp_rtrequest(req, rt, sa)
172 register struct rtentry *rt;
175 register struct sockaddr *gate = rt->rt_gateway;
176 register struct llinfo_arp *la = (struct llinfo_arp *)rt->rt_llinfo;
177 static struct sockaddr_dl null_sdl = {sizeof(null_sdl), AF_LINK};
178 static int arpinit_done;
182 LIST_INIT(&llinfo_arp);
183 timeout(arptimer, (caddr_t)0, hz);
184 register_netisr(NETISR_ARP, arpintr);
186 if (rt->rt_flags & RTF_GATEWAY)
192 * XXX: If this is a manually added route to interface
193 * such as older version of routed or gated might provide,
194 * restore cloning bit.
196 if ((rt->rt_flags & RTF_HOST) == 0 &&
197 SIN(rt_mask(rt))->sin_addr.s_addr != 0xffffffff)
198 rt->rt_flags |= RTF_CLONING;
199 if (rt->rt_flags & RTF_CLONING) {
201 * Case 1: This route should come from a route to iface.
203 rt_setgate(rt, rt_key(rt),
204 (struct sockaddr *)&null_sdl);
205 gate = rt->rt_gateway;
206 SDL(gate)->sdl_type = rt->rt_ifp->if_type;
207 SDL(gate)->sdl_index = rt->rt_ifp->if_index;
208 rt->rt_expire = time_second;
211 /* Announce a new entry if requested. */
212 if (rt->rt_flags & RTF_ANNOUNCE)
213 arprequest((struct arpcom *)rt->rt_ifp,
214 &SIN(rt_key(rt))->sin_addr,
215 &SIN(rt_key(rt))->sin_addr,
216 (u_char *)LLADDR(SDL(gate)));
219 if (gate->sa_family != AF_LINK ||
220 gate->sa_len < sizeof(null_sdl)) {
221 log(LOG_DEBUG, "arp_rtrequest: bad gateway value\n");
224 SDL(gate)->sdl_type = rt->rt_ifp->if_type;
225 SDL(gate)->sdl_index = rt->rt_ifp->if_index;
227 break; /* This happens on a route change */
229 * Case 2: This route may come from cloning, or a manual route
230 * add with a LL address.
232 R_Malloc(la, struct llinfo_arp *, sizeof(*la));
233 rt->rt_llinfo = (caddr_t)la;
235 log(LOG_DEBUG, "arp_rtrequest: malloc failed\n");
238 arp_inuse++, arp_allocated++;
239 Bzero(la, sizeof(*la));
241 rt->rt_flags |= RTF_LLINFO;
242 LIST_INSERT_HEAD(&llinfo_arp, la, la_le);
246 * This keeps the multicast addresses from showing up
247 * in `arp -a' listings as unresolved. It's not actually
248 * functional. Then the same for broadcast.
250 if (IN_MULTICAST(ntohl(SIN(rt_key(rt))->sin_addr.s_addr))) {
251 ETHER_MAP_IP_MULTICAST(&SIN(rt_key(rt))->sin_addr,
253 SDL(gate)->sdl_alen = 6;
256 if (in_broadcast(SIN(rt_key(rt))->sin_addr, rt->rt_ifp)) {
257 memcpy(LLADDR(SDL(gate)), etherbroadcastaddr, 6);
258 SDL(gate)->sdl_alen = 6;
263 if (SIN(rt_key(rt))->sin_addr.s_addr ==
264 (IA_SIN(rt->rt_ifa))->sin_addr.s_addr) {
266 * This test used to be
267 * if (loif.if_flags & IFF_UP)
268 * It allowed local traffic to be forced
269 * through the hardware by configuring the loopback down.
270 * However, it causes problems during network configuration
271 * for boards that can't receive packets they send.
272 * It is now necessary to clear "useloopback" and remove
273 * the route to force traffic out to the hardware.
276 Bcopy(((struct arpcom *)rt->rt_ifp)->ac_enaddr,
277 LLADDR(SDL(gate)), SDL(gate)->sdl_alen = 6);
288 LIST_REMOVE(la, la_le);
290 rt->rt_flags &= ~RTF_LLINFO;
292 m_freem(la->la_hold);
298 * Broadcast an ARP request. Caller specifies:
299 * - arp header source ip address
300 * - arp header target ip address
301 * - arp header source ethernet address
304 arprequest(ac, sip, tip, enaddr)
305 register struct arpcom *ac;
306 register struct in_addr *sip, *tip;
307 register u_char *enaddr;
309 register struct mbuf *m;
310 register struct ether_header *eh;
311 register struct ether_arp *ea;
313 static u_char llcx[] = { 0x82, 0x40, LLC_SNAP_LSAP, LLC_SNAP_LSAP,
314 LLC_UI, 0x00, 0x00, 0x00, 0x08, 0x06 };
316 if ((m = m_gethdr(M_DONTWAIT, MT_DATA)) == NULL)
318 m->m_pkthdr.rcvif = (struct ifnet *)0;
319 switch (ac->ac_if.if_type) {
321 m->m_len = sizeof(*ea) + sizeof(llcx);
322 m->m_pkthdr.len = sizeof(*ea) + sizeof(llcx);
323 MH_ALIGN(m, sizeof(*ea) + sizeof(llcx));
324 (void)memcpy(mtod(m, caddr_t), llcx, sizeof(llcx));
325 (void)memcpy(sa.sa_data, etherbroadcastaddr, 6);
326 (void)memcpy(sa.sa_data + 6, enaddr, 6);
327 sa.sa_data[6] |= TR_RII;
328 sa.sa_data[12] = TR_AC;
329 sa.sa_data[13] = TR_LLC_FRAME;
330 ea = (struct ether_arp *)(mtod(m, char *) + sizeof(llcx));
331 bzero((caddr_t)ea, sizeof (*ea));
332 ea->arp_hrd = htons(ARPHRD_IEEE802);
337 * This may not be correct for types not explicitly
338 * listed, but this is our best guess
341 m->m_len = sizeof(*ea);
342 m->m_pkthdr.len = sizeof(*ea);
343 MH_ALIGN(m, sizeof(*ea));
344 ea = mtod(m, struct ether_arp *);
345 eh = (struct ether_header *)sa.sa_data;
346 bzero((caddr_t)ea, sizeof (*ea));
347 /* if_output will not swap */
348 eh->ether_type = htons(ETHERTYPE_ARP);
349 (void)memcpy(eh->ether_dhost, etherbroadcastaddr,
350 sizeof(eh->ether_dhost));
351 ea->arp_hrd = htons(ARPHRD_ETHER);
354 ea->arp_pro = htons(ETHERTYPE_IP);
355 ea->arp_hln = sizeof(ea->arp_sha); /* hardware address length */
356 ea->arp_pln = sizeof(ea->arp_spa); /* protocol address length */
357 ea->arp_op = htons(ARPOP_REQUEST);
358 (void)memcpy(ea->arp_sha, enaddr, sizeof(ea->arp_sha));
359 (void)memcpy(ea->arp_spa, sip, sizeof(ea->arp_spa));
360 (void)memcpy(ea->arp_tpa, tip, sizeof(ea->arp_tpa));
361 sa.sa_family = AF_UNSPEC;
362 sa.sa_len = sizeof(sa);
363 (*ac->ac_if.if_output)(&ac->ac_if, m, &sa, (struct rtentry *)0);
367 * Resolve an IP address into an ethernet address. If success,
368 * desten is filled in. If there is no entry in arptab,
369 * set one up and broadcast a request for the IP address.
370 * Hold onto this mbuf and resend it once the address
371 * is finally resolved. A return value of 1 indicates
372 * that desten has been filled in and the packet should be sent
373 * normally; a 0 return indicates that the packet has been
374 * taken over here, either now or for later transmission.
377 arpresolve(ac, rt, m, dst, desten, rt0)
378 register struct arpcom *ac;
379 register struct rtentry *rt;
381 register struct sockaddr *dst;
382 register u_char *desten;
385 struct llinfo_arp *la = 0;
386 struct sockaddr_dl *sdl;
388 if (m->m_flags & M_BCAST) { /* broadcast */
389 (void)memcpy(desten, etherbroadcastaddr, sizeof(etherbroadcastaddr));
392 if (m->m_flags & M_MCAST) { /* multicast */
393 ETHER_MAP_IP_MULTICAST(&SIN(dst)->sin_addr, desten);
397 la = (struct llinfo_arp *)rt->rt_llinfo;
399 la = arplookup(SIN(dst)->sin_addr.s_addr, 1, 0);
403 if (la == 0 || rt == 0) {
404 log(LOG_DEBUG, "arpresolve: can't allocate llinfo for %s%s%s\n",
405 inet_ntoa(SIN(dst)->sin_addr), la ? "la" : "",
410 sdl = SDL(rt->rt_gateway);
412 * Check the address family and length is valid, the address
413 * is resolved; otherwise, try to resolve.
415 if ((rt->rt_expire == 0 || rt->rt_expire > time_second) &&
416 sdl->sdl_family == AF_LINK && sdl->sdl_alen != 0) {
417 bcopy(LLADDR(sdl), desten, sdl->sdl_alen);
421 * If ARP is disabled on this interface, stop.
423 * Probably should not allocate empty llinfo struct if we are
424 * not going to be sending out an arp request.
426 if (ac->ac_if.if_flags & IFF_NOARP)
429 * There is an arptab entry, but no ethernet address
430 * response yet. Replace the held mbuf with this
434 m_freem(la->la_hold);
437 rt->rt_flags &= ~RTF_REJECT;
438 if (la->la_asked == 0 || rt->rt_expire != time_second) {
439 rt->rt_expire = time_second;
440 if (la->la_asked++ < arp_maxtries)
442 &SIN(rt->rt_ifa->ifa_addr)->sin_addr,
443 &SIN(dst)->sin_addr, ac->ac_enaddr);
445 rt->rt_flags |= RTF_REJECT;
446 rt->rt_expire += arpt_down;
456 * Common length and type checks are done here,
457 * then the protocol-specific routine is called.
462 register struct mbuf *m;
463 register struct arphdr *ar;
466 while (arpintrq.ifq_head) {
468 IF_DEQUEUE(&arpintrq, m);
470 if (m == 0 || (m->m_flags & M_PKTHDR) == 0)
473 if (m->m_len < sizeof(struct arphdr) &&
474 ((m = m_pullup(m, sizeof(struct arphdr))) == NULL)) {
475 log(LOG_ERR, "arp: runt packet -- m_pullup failed\n");
478 ar = mtod(m, struct arphdr *);
480 if (ntohs(ar->ar_hrd) != ARPHRD_ETHER
481 && ntohs(ar->ar_hrd) != ARPHRD_IEEE802) {
483 "arp: unknown hardware address format (0x%d)\n",
489 if (m->m_pkthdr.len < sizeof(struct arphdr) + 2 * ar->ar_hln
491 log(LOG_ERR, "arp: runt packet\n");
496 switch (ntohs(ar->ar_pro)) {
509 * ARP for Internet protocols on 10 Mb/s Ethernet.
510 * Algorithm is that given in RFC 826.
511 * In addition, a sanity check is performed on the sender
512 * protocol address, to catch impersonators.
513 * We no longer handle negotiations for use of trailer protocol:
514 * Formerly, ARP replied for protocol type ETHERTYPE_TRAIL sent
515 * along with IP replies if we wanted trailers sent to us,
516 * and also sent them in response to IP replies.
517 * This allowed either end to announce the desire to receive
519 * We no longer reply to requests for ETHERTYPE_TRAIL protocol either,
520 * but formerly didn't normally send requests.
522 static int log_arp_wrong_iface = 1;
524 SYSCTL_INT(_net_link_ether_inet, OID_AUTO, log_arp_wrong_iface, CTLFLAG_RW,
525 &log_arp_wrong_iface, 0,
526 "log arp packets arriving on the wrong interface");
532 register struct ether_arp *ea;
533 register struct arpcom *ac = (struct arpcom *)m->m_pkthdr.rcvif;
534 struct ether_header *eh;
535 struct iso88025_header *th = (struct iso88025_header *)0;
536 register struct llinfo_arp *la = 0;
537 register struct rtentry *rt;
538 struct in_ifaddr *ia, *maybe_ia = 0;
539 struct sockaddr_dl *sdl;
541 struct in_addr isaddr, itaddr, myaddr;
544 if (m->m_len < sizeof(struct ether_arp) &&
545 (m = m_pullup(m, sizeof(struct ether_arp))) == NULL) {
546 log(LOG_ERR, "in_arp: runt packet -- m_pullup failed\n");
550 ea = mtod(m, struct ether_arp *);
551 op = ntohs(ea->arp_op);
552 (void)memcpy(&isaddr, ea->arp_spa, sizeof (isaddr));
553 (void)memcpy(&itaddr, ea->arp_tpa, sizeof (itaddr));
554 for (ia = in_ifaddrhead.tqh_first; ia; ia = ia->ia_link.tqe_next) {
556 * For a bridge, we want to check the address irrespective
557 * of the receive interface. (This will change slightly
558 * when we have clusters of interfaces).
561 #define BRIDGE_TEST (do_bridge)
563 #define BRIDGE_TEST (0) /* cc will optimise the test away */
565 if ((BRIDGE_TEST) || (ia->ia_ifp == &ac->ac_if)) {
567 if ((itaddr.s_addr == ia->ia_addr.sin_addr.s_addr) ||
568 (isaddr.s_addr == ia->ia_addr.sin_addr.s_addr)) {
577 myaddr = ia ? ia->ia_addr.sin_addr : maybe_ia->ia_addr.sin_addr;
578 if (!bcmp((caddr_t)ea->arp_sha, (caddr_t)ac->ac_enaddr,
579 sizeof (ea->arp_sha))) {
580 m_freem(m); /* it's from me, ignore it. */
583 if (!bcmp((caddr_t)ea->arp_sha, (caddr_t)etherbroadcastaddr,
584 sizeof (ea->arp_sha))) {
586 "arp: ether address is broadcast for IP address %s!\n",
591 if (isaddr.s_addr == myaddr.s_addr) {
593 "arp: %6p is using my IP address %s!\n",
594 ea->arp_sha, inet_ntoa(isaddr));
598 la = arplookup(isaddr.s_addr, itaddr.s_addr == myaddr.s_addr, 0);
599 if (la && (rt = la->la_rt) && (sdl = SDL(rt->rt_gateway))) {
600 /* the following is not an error when doing bridging */
601 if (!BRIDGE_TEST && rt->rt_ifp != &ac->ac_if) {
602 if (log_arp_wrong_iface)
603 log(LOG_ERR, "arp: %s is on %s%d but got reply from %6p on %s%d\n",
605 rt->rt_ifp->if_name, rt->rt_ifp->if_unit,
607 ac->ac_if.if_name, ac->ac_if.if_unit);
611 bcmp((caddr_t)ea->arp_sha, LLADDR(sdl), sdl->sdl_alen)) {
613 log(LOG_INFO, "arp: %s moved from %6p to %6p on %s%d\n",
614 inet_ntoa(isaddr), (u_char *)LLADDR(sdl),
616 ac->ac_if.if_name, ac->ac_if.if_unit);
619 "arp: %6p attempts to modify permanent entry for %s on %s%d\n",
620 ea->arp_sha, inet_ntoa(isaddr),
621 ac->ac_if.if_name, ac->ac_if.if_unit);
625 (void)memcpy(LLADDR(sdl), ea->arp_sha, sizeof(ea->arp_sha));
626 sdl->sdl_alen = sizeof(ea->arp_sha);
627 sdl->sdl_rcf = (u_short)0;
629 * If we receive an arp from a token-ring station over
630 * a token-ring nic then try to save the source
633 if (ac->ac_if.if_type == IFT_ISO88025) {
634 th = (struct iso88025_header *)m->m_pkthdr.header;
635 rif_len = TR_RCF_RIFLEN(th->rcf);
636 if ((th->iso88025_shost[0] & TR_RII) &&
638 sdl->sdl_rcf = th->rcf;
639 sdl->sdl_rcf ^= htons(TR_RCF_DIR);
640 memcpy(sdl->sdl_route, th->rd, rif_len - 2);
641 sdl->sdl_rcf &= ~htons(TR_RCF_BCST_MASK);
643 * Set up source routing information for
646 m->m_data -= rif_len;
648 m->m_pkthdr.len += rif_len;
650 th->iso88025_shost[0] &= ~TR_RII;
654 m->m_pkthdr.len += 8;
655 th->rcf = sdl->sdl_rcf;
657 sdl->sdl_rcf = (u_short)0;
660 rt->rt_expire = time_second + arpt_keep;
661 rt->rt_flags &= ~RTF_REJECT;
664 (*ac->ac_if.if_output)(&ac->ac_if, la->la_hold,
670 if (op != ARPOP_REQUEST) {
674 if (itaddr.s_addr == myaddr.s_addr) {
675 /* I am the target */
676 (void)memcpy(ea->arp_tha, ea->arp_sha, sizeof(ea->arp_sha));
677 (void)memcpy(ea->arp_sha, ac->ac_enaddr, sizeof(ea->arp_sha));
679 la = arplookup(itaddr.s_addr, 0, SIN_PROXY);
681 struct sockaddr_in sin;
688 bzero(&sin, sizeof sin);
689 sin.sin_family = AF_INET;
690 sin.sin_len = sizeof sin;
691 sin.sin_addr = itaddr;
693 rt = rtalloc1((struct sockaddr *)&sin, 0, 0UL);
699 * Don't send proxies for nodes on the same interface
700 * as this one came out of, or we'll get into a fight
701 * over who claims what Ether address.
703 if (rt->rt_ifp == &ac->ac_if) {
708 (void)memcpy(ea->arp_tha, ea->arp_sha, sizeof(ea->arp_sha));
709 (void)memcpy(ea->arp_sha, ac->ac_enaddr, sizeof(ea->arp_sha));
712 printf("arp: proxying for %s\n",
717 (void)memcpy(ea->arp_tha, ea->arp_sha, sizeof(ea->arp_sha));
718 sdl = SDL(rt->rt_gateway);
719 (void)memcpy(ea->arp_sha, LLADDR(sdl), sizeof(ea->arp_sha));
723 (void)memcpy(ea->arp_tpa, ea->arp_spa, sizeof(ea->arp_spa));
724 (void)memcpy(ea->arp_spa, &itaddr, sizeof(ea->arp_spa));
725 ea->arp_op = htons(ARPOP_REPLY);
726 ea->arp_pro = htons(ETHERTYPE_IP); /* let's be sure! */
727 switch (ac->ac_if.if_type) {
729 /* Re-arrange the source/dest address */
730 memcpy(th->iso88025_dhost, th->iso88025_shost,
731 sizeof(th->iso88025_dhost));
732 memcpy(th->iso88025_shost, ac->ac_enaddr,
733 sizeof(th->iso88025_shost));
734 /* Set the source routing bit if neccesary */
735 if (th->iso88025_dhost[0] & TR_RII) {
736 th->iso88025_dhost[0] &= ~TR_RII;
737 if (TR_RCF_RIFLEN(th->rcf) > 2)
738 th->iso88025_shost[0] |= TR_RII;
740 /* Copy the addresses, ac and fc into sa_data */
741 memcpy(sa.sa_data, th->iso88025_dhost,
742 sizeof(th->iso88025_dhost) * 2);
743 sa.sa_data[(sizeof(th->iso88025_dhost) * 2)] = TR_AC;
744 sa.sa_data[(sizeof(th->iso88025_dhost) * 2) + 1] = TR_LLC_FRAME;
749 * May not be correct for types not explictly
750 * listed, but it is our best guess.
753 eh = (struct ether_header *)sa.sa_data;
754 (void)memcpy(eh->ether_dhost, ea->arp_tha,
755 sizeof(eh->ether_dhost));
756 eh->ether_type = htons(ETHERTYPE_ARP);
759 sa.sa_family = AF_UNSPEC;
760 sa.sa_len = sizeof(sa);
761 (*ac->ac_if.if_output)(&ac->ac_if, m, &sa, (struct rtentry *)0);
771 register struct llinfo_arp *la;
773 register struct rtentry *rt = la->la_rt;
774 register struct sockaddr_dl *sdl;
777 if (rt->rt_refcnt > 0 && (sdl = SDL(rt->rt_gateway)) &&
778 sdl->sdl_family == AF_LINK) {
781 rt->rt_flags &= ~RTF_REJECT;
784 rtrequest(RTM_DELETE, rt_key(rt), (struct sockaddr *)0, rt_mask(rt),
785 0, (struct rtentry **)0);
788 * Lookup or enter a new address in arptab.
790 static struct llinfo_arp *
791 arplookup(addr, create, proxy)
795 register struct rtentry *rt;
796 static struct sockaddr_inarp sin = {sizeof(sin), AF_INET };
799 sin.sin_addr.s_addr = addr;
800 sin.sin_other = proxy ? SIN_PROXY : 0;
801 rt = rtalloc1((struct sockaddr *)&sin, create, 0UL);
806 if (rt->rt_flags & RTF_GATEWAY)
807 why = "host is not on local network";
808 else if ((rt->rt_flags & RTF_LLINFO) == 0)
809 why = "could not allocate llinfo";
810 else if (rt->rt_gateway->sa_family != AF_LINK)
811 why = "gateway route is not ours";
814 log(LOG_DEBUG, "arplookup %s failed: %s\n",
815 inet_ntoa(sin.sin_addr), why);
820 return ((struct llinfo_arp *)rt->rt_llinfo);
828 if (ntohl(IA_SIN(ifa)->sin_addr.s_addr) != INADDR_ANY)
829 arprequest(ac, &IA_SIN(ifa)->sin_addr,
830 &IA_SIN(ifa)->sin_addr, ac->ac_enaddr);
831 ifa->ifa_rtrequest = arp_rtrequest;
832 ifa->ifa_flags |= RTF_CLONING;