xref: /freebsd/sys/netinet/if_ether.c (revision 8e6b01171e30297084bb0b4457c4183c2746aacc)
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  * 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.
20  *
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
31  * SUCH DAMAGE.
32  *
33  *	@(#)if_ether.c	8.1 (Berkeley) 6/10/93
34  * $Id: if_ether.c,v 1.19 1995/10/05 20:08:39 wollman Exp $
35  */
36 
37 /*
38  * Ethernet address resolution protocol.
39  * TODO:
40  *	add "inuse/lock" bit (or ref. count) along with valid bit
41  */
42 
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/malloc.h>
46 #include <sys/mbuf.h>
47 #include <sys/socket.h>
48 #include <sys/time.h>
49 #include <sys/kernel.h>
50 #include <sys/errno.h>
51 #include <sys/ioctl.h>
52 #include <sys/syslog.h>
53 #include <sys/queue.h>
54 
55 #include <net/if.h>
56 #include <net/if_dl.h>
57 #include <net/route.h>
58 #include <net/netisr.h>
59 
60 #include <netinet/in.h>
61 #include <netinet/in_systm.h>
62 #include <netinet/in_var.h>
63 #include <netinet/ip.h>
64 #include <netinet/if_ether.h>
65 
66 #define SIN(s) ((struct sockaddr_in *)s)
67 #define SDL(s) ((struct sockaddr_dl *)s)
68 #define SRP(s) ((struct sockaddr_inarp *)s)
69 
70 /*
71  * ARP trailer negotiation.  Trailer protocol is not IP specific,
72  * but ARP request/response use IP addresses.
73  */
74 #define ETHERTYPE_IPTRAILERS ETHERTYPE_TRAIL
75 
76 
77 /* timer values */
78 int	arpt_prune = (5*60*1);	/* walk list every 5 minutes */
79 int	arpt_keep = (20*60);	/* once resolved, good for 20 more minutes */
80 int	arpt_down = 20;		/* once declared down, don't send for 20 secs */
81 #define	rt_expire rt_rmx.rmx_expire
82 
83 struct llinfo_arp {
84 	LIST_ENTRY(llinfo_arp) la_le;
85 	struct	rtentry *la_rt;
86 	struct	mbuf *la_hold;		/* last packet until resolved/timeout */
87 	long	la_asked;		/* last time we QUERIED for this addr */
88 #define la_timer la_rt->rt_rmx.rmx_expire /* deletion time in seconds */
89 };
90 static	LIST_HEAD(, llinfo_arp) llinfo_arp;
91 
92 static	void arprequest __P((struct arpcom *, u_long *, u_long *, u_char *));
93 static	void arptfree __P((struct llinfo_arp *));
94 static	void arptimer __P((void *));
95 static	struct llinfo_arp *arplookup __P((u_long, int, int));
96 static	void in_arpinput __P((struct mbuf *));
97 
98 struct	ifqueue arpintrq = {0, 0, 0, 50};
99 int	arp_inuse, arp_allocated, arp_intimer;
100 int	arp_maxtries = 5;
101 int	useloopback = 1;	/* use loopback interface for local traffic */
102 int	arpinit_done = 0;
103 
104 #ifdef	ARP_PROXYALL
105 int	arp_proxyall = 1;
106 #endif
107 
108 /*
109  * Timeout routine.  Age arp_tab entries periodically.
110  */
111 /* ARGSUSED */
112 static void
113 arptimer(ignored_arg)
114 	void *ignored_arg;
115 {
116 	int s = splnet();
117 	register struct llinfo_arp *la = llinfo_arp.lh_first;
118 	struct llinfo_arp *ola;
119 
120 	timeout(arptimer, (caddr_t)0, arpt_prune * hz);
121 	while ((ola = la) != 0) {
122 		register struct rtentry *rt = la->la_rt;
123 		la = la->la_le.le_next;
124 		if (rt->rt_expire && rt->rt_expire <= time.tv_sec)
125 			arptfree(ola); /* timer has expired, clear */
126 	}
127 	splx(s);
128 }
129 
130 /*
131  * Parallel to llc_rtrequest.
132  */
133 static void
134 arp_rtrequest(req, rt, sa)
135 	int req;
136 	register struct rtentry *rt;
137 	struct sockaddr *sa;
138 {
139 	register struct sockaddr *gate = rt->rt_gateway;
140 	register struct llinfo_arp *la = (struct llinfo_arp *)rt->rt_llinfo;
141 	static struct sockaddr_dl null_sdl = {sizeof(null_sdl), AF_LINK};
142 
143 	if (!arpinit_done) {
144 		arpinit_done = 1;
145 		LIST_INIT(&llinfo_arp);
146 		timeout(arptimer, (caddr_t)0, hz);
147 	}
148 	if (rt->rt_flags & RTF_GATEWAY)
149 		return;
150 	switch (req) {
151 
152 	case RTM_ADD:
153 		/*
154 		 * XXX: If this is a manually added route to interface
155 		 * such as older version of routed or gated might provide,
156 		 * restore cloning bit.
157 		 */
158 		if ((rt->rt_flags & RTF_HOST) == 0 &&
159 		    SIN(rt_mask(rt))->sin_addr.s_addr != 0xffffffff)
160 			rt->rt_flags |= RTF_CLONING;
161 		if (rt->rt_flags & RTF_CLONING) {
162 			/*
163 			 * Case 1: This route should come from a route to iface.
164 			 */
165 			rt_setgate(rt, rt_key(rt),
166 					(struct sockaddr *)&null_sdl);
167 			gate = rt->rt_gateway;
168 			SDL(gate)->sdl_type = rt->rt_ifp->if_type;
169 			SDL(gate)->sdl_index = rt->rt_ifp->if_index;
170 			rt->rt_expire = time.tv_sec;
171 			break;
172 		}
173 		/* Announce a new entry if requested. */
174 		if (rt->rt_flags & RTF_ANNOUNCE)
175 			arprequest((struct arpcom *)rt->rt_ifp,
176 			    &SIN(rt_key(rt))->sin_addr.s_addr,
177 			    &SIN(rt_key(rt))->sin_addr.s_addr,
178 			    (u_char *)LLADDR(SDL(gate)));
179 		/*FALLTHROUGH*/
180 	case RTM_RESOLVE:
181 		if (gate->sa_family != AF_LINK ||
182 		    gate->sa_len < sizeof(null_sdl)) {
183 			log(LOG_DEBUG, "arp_rtrequest: bad gateway value\n");
184 			break;
185 		}
186 		SDL(gate)->sdl_type = rt->rt_ifp->if_type;
187 		SDL(gate)->sdl_index = rt->rt_ifp->if_index;
188 		if (la != 0)
189 			break; /* This happens on a route change */
190 		/*
191 		 * Case 2:  This route may come from cloning, or a manual route
192 		 * add with a LL address.
193 		 */
194 		R_Malloc(la, struct llinfo_arp *, sizeof(*la));
195 		rt->rt_llinfo = (caddr_t)la;
196 		if (la == 0) {
197 			log(LOG_DEBUG, "arp_rtrequest: malloc failed\n");
198 			break;
199 		}
200 		arp_inuse++, arp_allocated++;
201 		Bzero(la, sizeof(*la));
202 		la->la_rt = rt;
203 		rt->rt_flags |= RTF_LLINFO;
204 		LIST_INSERT_HEAD(&llinfo_arp, la, la_le);
205 		if (SIN(rt_key(rt))->sin_addr.s_addr ==
206 		    (IA_SIN(rt->rt_ifa))->sin_addr.s_addr) {
207 		    /*
208 		     * This test used to be
209 		     *	if (loif.if_flags & IFF_UP)
210 		     * It allowed local traffic to be forced
211 		     * through the hardware by configuring the loopback down.
212 		     * However, it causes problems during network configuration
213 		     * for boards that can't receive packets they send.
214 		     * It is now necessary to clear "useloopback" and remove
215 		     * the route to force traffic out to the hardware.
216 		     */
217 			rt->rt_expire = 0;
218 			Bcopy(((struct arpcom *)rt->rt_ifp)->ac_enaddr,
219 				LLADDR(SDL(gate)), SDL(gate)->sdl_alen = 6);
220 			if (useloopback)
221 				rt->rt_ifp = loif;
222 
223 		}
224 		break;
225 
226 	case RTM_DELETE:
227 		if (la == 0)
228 			break;
229 		arp_inuse--;
230 		LIST_REMOVE(la, la_le);
231 		rt->rt_llinfo = 0;
232 		rt->rt_flags &= ~RTF_LLINFO;
233 		if (la->la_hold)
234 			m_freem(la->la_hold);
235 		Free((caddr_t)la);
236 	}
237 }
238 
239 /*
240  * Broadcast an ARP packet, asking who has addr on interface ac.
241  */
242 void
243 arpwhohas(ac, addr)
244 	register struct arpcom *ac;
245 	register struct in_addr *addr;
246 {
247 	arprequest(ac, &ac->ac_ipaddr.s_addr, &addr->s_addr, ac->ac_enaddr);
248 }
249 
250 /*
251  * Broadcast an ARP request. Caller specifies:
252  *	- arp header source ip address
253  *	- arp header target ip address
254  *	- arp header source ethernet address
255  */
256 static void
257 arprequest(ac, sip, tip, enaddr)
258 	register struct arpcom *ac;
259 	register u_long *sip, *tip;
260 	register u_char *enaddr;
261 {
262 	register struct mbuf *m;
263 	register struct ether_header *eh;
264 	register struct ether_arp *ea;
265 	struct sockaddr sa;
266 
267 	if ((m = m_gethdr(M_DONTWAIT, MT_DATA)) == NULL)
268 		return;
269 	m->m_len = sizeof(*ea);
270 	m->m_pkthdr.len = sizeof(*ea);
271 	MH_ALIGN(m, sizeof(*ea));
272 	ea = mtod(m, struct ether_arp *);
273 	eh = (struct ether_header *)sa.sa_data;
274 	bzero((caddr_t)ea, sizeof (*ea));
275 	(void)memcpy(eh->ether_dhost, etherbroadcastaddr, sizeof(eh->ether_dhost));
276 	eh->ether_type = ETHERTYPE_ARP;		/* if_output will swap */
277 	ea->arp_hrd = htons(ARPHRD_ETHER);
278 	ea->arp_pro = htons(ETHERTYPE_IP);
279 	ea->arp_hln = sizeof(ea->arp_sha);	/* hardware address length */
280 	ea->arp_pln = sizeof(ea->arp_spa);	/* protocol address length */
281 	ea->arp_op = htons(ARPOP_REQUEST);
282 	(void)memcpy(ea->arp_sha, enaddr, sizeof(ea->arp_sha));
283 	(void)memcpy(ea->arp_spa, sip, sizeof(ea->arp_spa));
284 	(void)memcpy(ea->arp_tpa, tip, sizeof(ea->arp_tpa));
285 	sa.sa_family = AF_UNSPEC;
286 	sa.sa_len = sizeof(sa);
287 	(*ac->ac_if.if_output)(&ac->ac_if, m, &sa, (struct rtentry *)0);
288 }
289 
290 /*
291  * Resolve an IP address into an ethernet address.  If success,
292  * desten is filled in.  If there is no entry in arptab,
293  * set one up and broadcast a request for the IP address.
294  * Hold onto this mbuf and resend it once the address
295  * is finally resolved.  A return value of 1 indicates
296  * that desten has been filled in and the packet should be sent
297  * normally; a 0 return indicates that the packet has been
298  * taken over here, either now or for later transmission.
299  */
300 int
301 arpresolve(ac, rt, m, dst, desten, rt0)
302 	register struct arpcom *ac;
303 	register struct rtentry *rt;
304 	struct mbuf *m;
305 	register struct sockaddr *dst;
306 	register u_char *desten;
307 	struct rtentry *rt0;
308 {
309 	register struct llinfo_arp *la;
310 	struct sockaddr_dl *sdl;
311 
312 	if (m->m_flags & M_BCAST) {	/* broadcast */
313 		(void)memcpy(desten, etherbroadcastaddr, sizeof(etherbroadcastaddr));
314 		return (1);
315 	}
316 	if (m->m_flags & M_MCAST) {	/* multicast */
317 		ETHER_MAP_IP_MULTICAST(&SIN(dst)->sin_addr, desten);
318 		return(1);
319 	}
320 	if (rt)
321 		la = (struct llinfo_arp *)rt->rt_llinfo;
322 	else {
323 		la = arplookup(SIN(dst)->sin_addr.s_addr, 1, 0);
324 		if (la)
325 			rt = la->la_rt;
326 	}
327 	if (la == 0 || rt == 0) {
328 		log(LOG_DEBUG, "arpresolve: can't allocate llinfo\n");
329 		m_freem(m);
330 		return (0);
331 	}
332 	sdl = SDL(rt->rt_gateway);
333 	/*
334 	 * Check the address family and length is valid, the address
335 	 * is resolved; otherwise, try to resolve.
336 	 */
337 	if ((rt->rt_expire == 0 || rt->rt_expire > time.tv_sec) &&
338 	    sdl->sdl_family == AF_LINK && sdl->sdl_alen != 0) {
339 		(void)memcpy(desten, LLADDR(sdl), sdl->sdl_alen);
340 		return 1;
341 	}
342 	/*
343 	 * There is an arptab entry, but no ethernet address
344 	 * response yet.  Replace the held mbuf with this
345 	 * latest one.
346 	 */
347 	if (la->la_hold)
348 		m_freem(la->la_hold);
349 	la->la_hold = m;
350 	if (rt->rt_expire) {
351 		rt->rt_flags &= ~RTF_REJECT;
352 		if (la->la_asked == 0 || rt->rt_expire != time.tv_sec) {
353 			rt->rt_expire = time.tv_sec;
354 			if (la->la_asked++ < arp_maxtries)
355 				arpwhohas(ac, &(SIN(dst)->sin_addr));
356 			else {
357 				rt->rt_flags |= RTF_REJECT;
358 				rt->rt_expire += arpt_down;
359 				la->la_asked = 0;
360 			}
361 
362 		}
363 	}
364 	return (0);
365 }
366 
367 /*
368  * Common length and type checks are done here,
369  * then the protocol-specific routine is called.
370  */
371 void
372 arpintr(void)
373 {
374 	register struct mbuf *m;
375 	register struct arphdr *ar;
376 	int s;
377 
378 	while (arpintrq.ifq_head) {
379 		s = splimp();
380 		IF_DEQUEUE(&arpintrq, m);
381 		splx(s);
382 		if (m == 0 || (m->m_flags & M_PKTHDR) == 0)
383 			panic("arpintr");
384 		if (m->m_len >= sizeof(struct arphdr) &&
385 		    (ar = mtod(m, struct arphdr *)) &&
386 		    ntohs(ar->ar_hrd) == ARPHRD_ETHER &&
387 		    m->m_len >=
388 		      sizeof(struct arphdr) + 2 * ar->ar_hln + 2 * ar->ar_pln)
389 
390 			    switch (ntohs(ar->ar_pro)) {
391 
392 			    case ETHERTYPE_IP:
393 			    case ETHERTYPE_IPTRAILERS:
394 				    in_arpinput(m);
395 				    continue;
396 			    }
397 		m_freem(m);
398 	}
399 }
400 
401 NETISR_SET(NETISR_ARP, arpintr);
402 
403 /*
404  * ARP for Internet protocols on 10 Mb/s Ethernet.
405  * Algorithm is that given in RFC 826.
406  * In addition, a sanity check is performed on the sender
407  * protocol address, to catch impersonators.
408  * We no longer handle negotiations for use of trailer protocol:
409  * Formerly, ARP replied for protocol type ETHERTYPE_TRAIL sent
410  * along with IP replies if we wanted trailers sent to us,
411  * and also sent them in response to IP replies.
412  * This allowed either end to announce the desire to receive
413  * trailer packets.
414  * We no longer reply to requests for ETHERTYPE_TRAIL protocol either,
415  * but formerly didn't normally send requests.
416  */
417 static void
418 in_arpinput(m)
419 	struct mbuf *m;
420 {
421 	register struct ether_arp *ea;
422 	register struct arpcom *ac = (struct arpcom *)m->m_pkthdr.rcvif;
423 	struct ether_header *eh;
424 	register struct llinfo_arp *la = 0;
425 	register struct rtentry *rt;
426 	struct in_ifaddr *ia, *maybe_ia = 0;
427 	struct sockaddr_dl *sdl;
428 	struct sockaddr sa;
429 	struct in_addr isaddr, itaddr, myaddr;
430 	int op;
431 
432 	ea = mtod(m, struct ether_arp *);
433 	op = ntohs(ea->arp_op);
434 	(void)memcpy(&isaddr, ea->arp_spa, sizeof (isaddr));
435 	(void)memcpy(&itaddr, ea->arp_tpa, sizeof (itaddr));
436 	for (ia = in_ifaddr; ia; ia = ia->ia_next)
437 		if (ia->ia_ifp == &ac->ac_if) {
438 			maybe_ia = ia;
439 			if ((itaddr.s_addr == ia->ia_addr.sin_addr.s_addr) ||
440 			     (isaddr.s_addr == ia->ia_addr.sin_addr.s_addr))
441 				break;
442 		}
443 	if (maybe_ia == 0)
444 		goto out;
445 	myaddr = ia ? ia->ia_addr.sin_addr : maybe_ia->ia_addr.sin_addr;
446 	if (!bcmp((caddr_t)ea->arp_sha, (caddr_t)ac->ac_enaddr,
447 	    sizeof (ea->arp_sha)))
448 		goto out;	/* it's from me, ignore it. */
449 	if (!bcmp((caddr_t)ea->arp_sha, (caddr_t)etherbroadcastaddr,
450 	    sizeof (ea->arp_sha))) {
451 		log(LOG_ERR,
452 		    "arp: ether address is broadcast for IP address %s!\n",
453 		    inet_ntoa(isaddr));
454 		goto out;
455 	}
456 	if (isaddr.s_addr == myaddr.s_addr) {
457 		log(LOG_ERR,
458 		   "duplicate IP address %s! sent from ethernet address: %s\n",
459 		   inet_ntoa(isaddr), ether_sprintf(ea->arp_sha));
460 		itaddr = myaddr;
461 		goto reply;
462 	}
463 	la = arplookup(isaddr.s_addr, itaddr.s_addr == myaddr.s_addr, 0);
464 	if (la && (rt = la->la_rt) && (sdl = SDL(rt->rt_gateway))) {
465 		if (sdl->sdl_alen &&
466 		    bcmp((caddr_t)ea->arp_sha, LLADDR(sdl), sdl->sdl_alen))
467 			log(LOG_INFO, "arp info overwritten for %s by %s\n",
468 			    inet_ntoa(isaddr), ether_sprintf(ea->arp_sha));
469 		(void)memcpy(LLADDR(sdl), ea->arp_sha, sizeof(ea->arp_sha));
470 		sdl->sdl_alen = sizeof(ea->arp_sha);
471 		if (rt->rt_expire)
472 			rt->rt_expire = time.tv_sec + arpt_keep;
473 		rt->rt_flags &= ~RTF_REJECT;
474 		la->la_asked = 0;
475 		if (la->la_hold) {
476 			(*ac->ac_if.if_output)(&ac->ac_if, la->la_hold,
477 				rt_key(rt), rt);
478 			la->la_hold = 0;
479 		}
480 	}
481 reply:
482 	if (op != ARPOP_REQUEST) {
483 	out:
484 		m_freem(m);
485 		return;
486 	}
487 	if (itaddr.s_addr == myaddr.s_addr) {
488 		/* I am the target */
489 		(void)memcpy(ea->arp_tha, ea->arp_sha, sizeof(ea->arp_sha));
490 		(void)memcpy(ea->arp_sha, ac->ac_enaddr, sizeof(ea->arp_sha));
491 	} else {
492 		la = arplookup(itaddr.s_addr, 0, SIN_PROXY);
493 		if (la == NULL) {
494 #ifdef ARP_PROXYALL
495 			struct sockaddr_in sin;
496 
497 			if(!arp_proxyall) goto out;
498 
499 			bzero(&sin, sizeof sin);
500 			sin.sin_family = AF_INET;
501 			sin.sin_len = sizeof sin;
502 			sin.sin_addr = itaddr;
503 
504 			rt = rtalloc1((struct sockaddr *)&sin, 0, 0UL);
505 			if( !rt )
506 				goto out;
507 			/*
508 			 * Don't send proxies for nodes on the same interface
509 			 * as this one came out of, or we'll get into a fight
510 			 * over who claims what Ether address.
511 			 */
512 			if(rt->rt_ifp == &ac->ac_if) {
513 				rtfree(rt);
514 				goto out;
515 			}
516 			(void)memcpy(ea->arp_tha, ea->arp_sha, sizeof(ea->arp_sha));
517 			(void)memcpy(ea->arp_sha, ac->ac_enaddr, sizeof(ea->arp_sha));
518 			rtfree(rt);
519 #ifdef DEBUG_PROXY
520 			printf("arp: proxying for %s\n",
521 			       inet_ntoa(itaddr));
522 #endif
523 #else
524 			goto out;
525 #endif
526 		} else {
527 			rt = la->la_rt;
528 			(void)memcpy(ea->arp_tha, ea->arp_sha, sizeof(ea->arp_sha));
529 			sdl = SDL(rt->rt_gateway);
530 			(void)memcpy(ea->arp_sha, LLADDR(sdl), sizeof(ea->arp_sha));
531 		}
532 	}
533 
534 	(void)memcpy(ea->arp_tpa, ea->arp_spa, sizeof(ea->arp_spa));
535 	(void)memcpy(ea->arp_spa, &itaddr, sizeof(ea->arp_spa));
536 	ea->arp_op = htons(ARPOP_REPLY);
537 	ea->arp_pro = htons(ETHERTYPE_IP); /* let's be sure! */
538 	eh = (struct ether_header *)sa.sa_data;
539 	(void)memcpy(eh->ether_dhost, ea->arp_tha, sizeof(eh->ether_dhost));
540 	eh->ether_type = ETHERTYPE_ARP;
541 	sa.sa_family = AF_UNSPEC;
542 	sa.sa_len = sizeof(sa);
543 	(*ac->ac_if.if_output)(&ac->ac_if, m, &sa, (struct rtentry *)0);
544 	return;
545 }
546 
547 /*
548  * Free an arp entry.
549  */
550 static void
551 arptfree(la)
552 	register struct llinfo_arp *la;
553 {
554 	register struct rtentry *rt = la->la_rt;
555 	register struct sockaddr_dl *sdl;
556 	if (rt == 0)
557 		panic("arptfree");
558 	if (rt->rt_refcnt > 0 && (sdl = SDL(rt->rt_gateway)) &&
559 	    sdl->sdl_family == AF_LINK) {
560 		sdl->sdl_alen = 0;
561 		la->la_asked = 0;
562 		rt->rt_flags &= ~RTF_REJECT;
563 		return;
564 	}
565 	rtrequest(RTM_DELETE, rt_key(rt), (struct sockaddr *)0, rt_mask(rt),
566 			0, (struct rtentry **)0);
567 }
568 /*
569  * Lookup or enter a new address in arptab.
570  */
571 static struct llinfo_arp *
572 arplookup(addr, create, proxy)
573 	u_long addr;
574 	int create, proxy;
575 {
576 	register struct rtentry *rt;
577 	static struct sockaddr_inarp sin = {sizeof(sin), AF_INET };
578 	const char *why = 0;
579 
580 	sin.sin_addr.s_addr = addr;
581 	sin.sin_other = proxy ? SIN_PROXY : 0;
582 	rt = rtalloc1((struct sockaddr *)&sin, create, 0UL);
583 	if (rt == 0)
584 		return (0);
585 	rt->rt_refcnt--;
586 
587 	if(rt->rt_flags & RTF_GATEWAY)
588 		why = "host is not on local network";
589 	else if((rt->rt_flags & RTF_LLINFO) == 0)
590 		why = "could not allocate llinfo";
591 	else if(rt->rt_gateway->sa_family != AF_LINK)
592 		why = "gateway route is not ours";
593 
594 	if(why && create) {
595 		log(LOG_DEBUG, "arplookup %s failed: %s\n",
596 		    inet_ntoa(sin.sin_addr), why);
597 		return 0;
598 	} else if(why) {
599 		return 0;
600 	}
601 	return ((struct llinfo_arp *)rt->rt_llinfo);
602 }
603 
604 int
605 arpioctl(cmd, data)
606 	int cmd;
607 	caddr_t data;
608 {
609 	return (EOPNOTSUPP);
610 }
611 
612 void
613 arp_ifinit(ac, ifa)
614 	struct arpcom *ac;
615 	struct ifaddr *ifa;
616 {
617 	ac->ac_ipaddr = IA_SIN(ifa)->sin_addr;
618 	arpwhohas(ac, &ac->ac_ipaddr);
619 	ifa->ifa_rtrequest = arp_rtrequest;
620 	ifa->ifa_flags |= RTF_CLONING;
621 }
622