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