if_ether.c revision 84102
11541Srgrimes/*
21541Srgrimes * Copyright (c) 1982, 1986, 1988, 1993
31541Srgrimes *	The Regents of the University of California.  All rights reserved.
41541Srgrimes *
51541Srgrimes * Redistribution and use in source and binary forms, with or without
61541Srgrimes * modification, are permitted provided that the following conditions
71541Srgrimes * are met:
81541Srgrimes * 1. Redistributions of source code must retain the above copyright
91541Srgrimes *    notice, this list of conditions and the following disclaimer.
101541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
111541Srgrimes *    notice, this list of conditions and the following disclaimer in the
121541Srgrimes *    documentation and/or other materials provided with the distribution.
131541Srgrimes * 3. All advertising materials mentioning features or use of this software
141541Srgrimes *    must display the following acknowledgement:
151541Srgrimes *	This product includes software developed by the University of
161541Srgrimes *	California, Berkeley and its contributors.
171541Srgrimes * 4. Neither the name of the University nor the names of its contributors
181541Srgrimes *    may be used to endorse or promote products derived from this software
191541Srgrimes *    without specific prior written permission.
201541Srgrimes *
211541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
221541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
231541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
241541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
251541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
261541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
271541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
281541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
291541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
301541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
311541Srgrimes * SUCH DAMAGE.
321541Srgrimes *
331541Srgrimes *	@(#)if_ether.c	8.1 (Berkeley) 6/10/93
3450477Speter * $FreeBSD: head/sys/netinet/if_ether.c 84102 2001-09-29 04:34:11Z jlemon $
351541Srgrimes */
361541Srgrimes
371541Srgrimes/*
381541Srgrimes * Ethernet address resolution protocol.
391541Srgrimes * TODO:
401541Srgrimes *	add "inuse/lock" bit (or ref. count) along with valid bit
411541Srgrimes */
421541Srgrimes
4332350Seivind#include "opt_inet.h"
4441793Sluigi#include "opt_bdg.h"
4532350Seivind
461541Srgrimes#include <sys/param.h>
4712693Sphk#include <sys/kernel.h>
4844078Sdfr#include <sys/queue.h>
4912693Sphk#include <sys/sysctl.h>
501541Srgrimes#include <sys/systm.h>
5112693Sphk#include <sys/mbuf.h>
521541Srgrimes#include <sys/malloc.h>
5318892Sbde#include <sys/socket.h>
541541Srgrimes#include <sys/syslog.h>
551541Srgrimes
561541Srgrimes#include <net/if.h>
571541Srgrimes#include <net/if_dl.h>
5844165Sjulian#include <net/if_types.h>
591541Srgrimes#include <net/route.h>
608426Swollman#include <net/netisr.h>
6158313Slile#include <net/if_llc.h>
6271963Sjulian#ifdef BRIDGE
6371963Sjulian#include <net/ethernet.h>
6471963Sjulian#include <net/bridge.h>
6571963Sjulian#endif
661541Srgrimes
671541Srgrimes#include <netinet/in.h>
681541Srgrimes#include <netinet/in_var.h>
691541Srgrimes#include <netinet/if_ether.h>
701541Srgrimes
7144627Sjulian#include <net/iso88025.h>
7244627Sjulian
731541Srgrimes#define SIN(s) ((struct sockaddr_in *)s)
741541Srgrimes#define SDL(s) ((struct sockaddr_dl *)s)
751541Srgrimes
7644078SdfrSYSCTL_DECL(_net_link_ether);
7712942SwollmanSYSCTL_NODE(_net_link_ether, PF_INET, inet, CTLFLAG_RW, 0, "");
781541Srgrimes
7912693Sphk/* timer values */
8012942Swollmanstatic int arpt_prune = (5*60*1); /* walk list every 5 minutes */
8112942Swollmanstatic int arpt_keep = (20*60); /* once resolved, good for 20 more minutes */
8212942Swollmanstatic int arpt_down = 20;	/* once declared down, don't send for 20 sec */
831541Srgrimes
8412942SwollmanSYSCTL_INT(_net_link_ether_inet, OID_AUTO, prune_intvl, CTLFLAG_RW,
8512942Swollman	   &arpt_prune, 0, "");
8612942SwollmanSYSCTL_INT(_net_link_ether_inet, OID_AUTO, max_age, CTLFLAG_RW,
8712942Swollman	   &arpt_keep, 0, "");
8812942SwollmanSYSCTL_INT(_net_link_ether_inet, OID_AUTO, host_down_time, CTLFLAG_RW,
8912942Swollman	   &arpt_down, 0, "");
9012693Sphk
911541Srgrimes#define	rt_expire rt_rmx.rmx_expire
921541Srgrimes
9311225Swollmanstruct llinfo_arp {
9460938Sjake	LIST_ENTRY(llinfo_arp) la_le;
9511225Swollman	struct	rtentry *la_rt;
9611225Swollman	struct	mbuf *la_hold;		/* last packet until resolved/timeout */
9711225Swollman	long	la_asked;		/* last time we QUERIED for this addr */
9811225Swollman#define la_timer la_rt->rt_rmx.rmx_expire /* deletion time in seconds */
9911225Swollman};
10012693Sphk
10160938Sjakestatic	LIST_HEAD(, llinfo_arp) llinfo_arp;
10211225Swollman
10369152Sjlemonstruct	ifqueue arpintrq;
10412820Sphkstatic int	arp_inuse, arp_allocated;
1051541Srgrimes
10612693Sphkstatic int	arp_maxtries = 5;
10712942Swollmanstatic int	useloopback = 1; /* use loopback interface for local traffic */
10812942Swollmanstatic int	arp_proxyall = 0;
1093282Swollman
11012942SwollmanSYSCTL_INT(_net_link_ether_inet, OID_AUTO, maxtries, CTLFLAG_RW,
11112942Swollman	   &arp_maxtries, 0, "");
11212942SwollmanSYSCTL_INT(_net_link_ether_inet, OID_AUTO, useloopback, CTLFLAG_RW,
11312942Swollman	   &useloopback, 0, "");
11412942SwollmanSYSCTL_INT(_net_link_ether_inet, OID_AUTO, proxyall, CTLFLAG_RW,
11512942Swollman	   &arp_proxyall, 0, "");
11612693Sphk
11769152Sjlemonstatic void	arp_init __P((void));
11812877Sbdestatic void	arp_rtrequest __P((int, struct rtentry *, struct sockaddr *));
11936908Sjulianstatic void	arprequest __P((struct arpcom *,
12036908Sjulian			struct in_addr *, struct in_addr *, u_char *));
12112693Sphkstatic void	arpintr __P((void));
12212693Sphkstatic void	arptfree __P((struct llinfo_arp *));
12312693Sphkstatic void	arptimer __P((void *));
12412693Sphkstatic struct llinfo_arp
12512693Sphk		*arplookup __P((u_long, int, int));
12632350Seivind#ifdef INET
12712693Sphkstatic void	in_arpinput __P((struct mbuf *));
12832350Seivind#endif
12912693Sphk
1301541Srgrimes/*
1311541Srgrimes * Timeout routine.  Age arp_tab entries periodically.
1321541Srgrimes */
1331541Srgrimes/* ARGSUSED */
1341541Srgrimesstatic void
1351541Srgrimesarptimer(ignored_arg)
1361541Srgrimes	void *ignored_arg;
1371541Srgrimes{
1381541Srgrimes	int s = splnet();
13971999Sphk	register struct llinfo_arp *la = LIST_FIRST(&llinfo_arp);
14011225Swollman	struct llinfo_arp *ola;
1411541Srgrimes
1421541Srgrimes	timeout(arptimer, (caddr_t)0, arpt_prune * hz);
14311225Swollman	while ((ola = la) != 0) {
1441541Srgrimes		register struct rtentry *rt = la->la_rt;
14571999Sphk		la = LIST_NEXT(la, la_le);
14634961Sphk		if (rt->rt_expire && rt->rt_expire <= time_second)
14711225Swollman			arptfree(ola); /* timer has expired, clear */
1481541Srgrimes	}
1491541Srgrimes	splx(s);
1501541Srgrimes}
1511541Srgrimes
1521541Srgrimes/*
1531541Srgrimes * Parallel to llc_rtrequest.
1541541Srgrimes */
1555196Swollmanstatic void
1561541Srgrimesarp_rtrequest(req, rt, sa)
1571541Srgrimes	int req;
1581541Srgrimes	register struct rtentry *rt;
1591541Srgrimes	struct sockaddr *sa;
1601541Srgrimes{
1611541Srgrimes	register struct sockaddr *gate = rt->rt_gateway;
1621541Srgrimes	register struct llinfo_arp *la = (struct llinfo_arp *)rt->rt_llinfo;
1631541Srgrimes	static struct sockaddr_dl null_sdl = {sizeof(null_sdl), AF_LINK};
16412693Sphk	static int arpinit_done;
1651541Srgrimes
1661541Srgrimes	if (!arpinit_done) {
1671541Srgrimes		arpinit_done = 1;
16811225Swollman		LIST_INIT(&llinfo_arp);
1691541Srgrimes		timeout(arptimer, (caddr_t)0, hz);
17057178Speter		register_netisr(NETISR_ARP, arpintr);
1711541Srgrimes	}
1721541Srgrimes	if (rt->rt_flags & RTF_GATEWAY)
1731541Srgrimes		return;
1741541Srgrimes	switch (req) {
1751541Srgrimes
1761541Srgrimes	case RTM_ADD:
1771541Srgrimes		/*
1781541Srgrimes		 * XXX: If this is a manually added route to interface
1791541Srgrimes		 * such as older version of routed or gated might provide,
1801541Srgrimes		 * restore cloning bit.
1811541Srgrimes		 */
1821541Srgrimes		if ((rt->rt_flags & RTF_HOST) == 0 &&
1831541Srgrimes		    SIN(rt_mask(rt))->sin_addr.s_addr != 0xffffffff)
1841541Srgrimes			rt->rt_flags |= RTF_CLONING;
1851541Srgrimes		if (rt->rt_flags & RTF_CLONING) {
1861541Srgrimes			/*
1871541Srgrimes			 * Case 1: This route should come from a route to iface.
1881541Srgrimes			 */
1891541Srgrimes			rt_setgate(rt, rt_key(rt),
1901541Srgrimes					(struct sockaddr *)&null_sdl);
1911541Srgrimes			gate = rt->rt_gateway;
1921541Srgrimes			SDL(gate)->sdl_type = rt->rt_ifp->if_type;
1931541Srgrimes			SDL(gate)->sdl_index = rt->rt_ifp->if_index;
19434961Sphk			rt->rt_expire = time_second;
1951541Srgrimes			break;
1961541Srgrimes		}
1971541Srgrimes		/* Announce a new entry if requested. */
1981541Srgrimes		if (rt->rt_flags & RTF_ANNOUNCE)
1991541Srgrimes			arprequest((struct arpcom *)rt->rt_ifp,
20036908Sjulian			    &SIN(rt_key(rt))->sin_addr,
20136908Sjulian			    &SIN(rt_key(rt))->sin_addr,
2021541Srgrimes			    (u_char *)LLADDR(SDL(gate)));
2031541Srgrimes		/*FALLTHROUGH*/
2041541Srgrimes	case RTM_RESOLVE:
2051541Srgrimes		if (gate->sa_family != AF_LINK ||
2061541Srgrimes		    gate->sa_len < sizeof(null_sdl)) {
2076568Sdg			log(LOG_DEBUG, "arp_rtrequest: bad gateway value\n");
2081541Srgrimes			break;
2091541Srgrimes		}
2101541Srgrimes		SDL(gate)->sdl_type = rt->rt_ifp->if_type;
2111541Srgrimes		SDL(gate)->sdl_index = rt->rt_ifp->if_index;
2121541Srgrimes		if (la != 0)
2131541Srgrimes			break; /* This happens on a route change */
2141541Srgrimes		/*
2151541Srgrimes		 * Case 2:  This route may come from cloning, or a manual route
2161541Srgrimes		 * add with a LL address.
2171541Srgrimes		 */
2181541Srgrimes		R_Malloc(la, struct llinfo_arp *, sizeof(*la));
2191541Srgrimes		rt->rt_llinfo = (caddr_t)la;
2201541Srgrimes		if (la == 0) {
2211541Srgrimes			log(LOG_DEBUG, "arp_rtrequest: malloc failed\n");
2221541Srgrimes			break;
2231541Srgrimes		}
2241541Srgrimes		arp_inuse++, arp_allocated++;
2251541Srgrimes		Bzero(la, sizeof(*la));
2261541Srgrimes		la->la_rt = rt;
2271541Srgrimes		rt->rt_flags |= RTF_LLINFO;
22811225Swollman		LIST_INSERT_HEAD(&llinfo_arp, la, la_le);
22913926Swollman
23032350Seivind#ifdef INET
23113926Swollman		/*
23213926Swollman		 * This keeps the multicast addresses from showing up
23313926Swollman		 * in `arp -a' listings as unresolved.  It's not actually
23413926Swollman		 * functional.  Then the same for broadcast.
23513926Swollman		 */
23613926Swollman		if (IN_MULTICAST(ntohl(SIN(rt_key(rt))->sin_addr.s_addr))) {
23713926Swollman			ETHER_MAP_IP_MULTICAST(&SIN(rt_key(rt))->sin_addr,
23813926Swollman					       LLADDR(SDL(gate)));
23913926Swollman			SDL(gate)->sdl_alen = 6;
24016576Speter			rt->rt_expire = 0;
24113926Swollman		}
24213926Swollman		if (in_broadcast(SIN(rt_key(rt))->sin_addr, rt->rt_ifp)) {
24313926Swollman			memcpy(LLADDR(SDL(gate)), etherbroadcastaddr, 6);
24413926Swollman			SDL(gate)->sdl_alen = 6;
24516576Speter			rt->rt_expire = 0;
24613926Swollman		}
24732350Seivind#endif
24813926Swollman
2491541Srgrimes		if (SIN(rt_key(rt))->sin_addr.s_addr ==
2501541Srgrimes		    (IA_SIN(rt->rt_ifa))->sin_addr.s_addr) {
2511541Srgrimes		    /*
2521541Srgrimes		     * This test used to be
2531541Srgrimes		     *	if (loif.if_flags & IFF_UP)
2541541Srgrimes		     * It allowed local traffic to be forced
2551541Srgrimes		     * through the hardware by configuring the loopback down.
2561541Srgrimes		     * However, it causes problems during network configuration
2571541Srgrimes		     * for boards that can't receive packets they send.
2581541Srgrimes		     * It is now necessary to clear "useloopback" and remove
2591541Srgrimes		     * the route to force traffic out to the hardware.
2601541Srgrimes		     */
2611541Srgrimes			rt->rt_expire = 0;
2621541Srgrimes			Bcopy(((struct arpcom *)rt->rt_ifp)->ac_enaddr,
2631541Srgrimes				LLADDR(SDL(gate)), SDL(gate)->sdl_alen = 6);
2641541Srgrimes			if (useloopback)
2658090Spst				rt->rt_ifp = loif;
2661541Srgrimes
2671541Srgrimes		}
2681541Srgrimes		break;
2691541Srgrimes
2701541Srgrimes	case RTM_DELETE:
2711541Srgrimes		if (la == 0)
2721541Srgrimes			break;
2731541Srgrimes		arp_inuse--;
27411225Swollman		LIST_REMOVE(la, la_le);
2751541Srgrimes		rt->rt_llinfo = 0;
2761541Srgrimes		rt->rt_flags &= ~RTF_LLINFO;
2771541Srgrimes		if (la->la_hold)
2781541Srgrimes			m_freem(la->la_hold);
2791541Srgrimes		Free((caddr_t)la);
2801541Srgrimes	}
2811541Srgrimes}
2821541Srgrimes
2831541Srgrimes/*
2841541Srgrimes * Broadcast an ARP request. Caller specifies:
2851541Srgrimes *	- arp header source ip address
2861541Srgrimes *	- arp header target ip address
2871541Srgrimes *	- arp header source ethernet address
2881541Srgrimes */
2891541Srgrimesstatic void
2901541Srgrimesarprequest(ac, sip, tip, enaddr)
2911541Srgrimes	register struct arpcom *ac;
29236908Sjulian	register struct in_addr *sip, *tip;
2931541Srgrimes	register u_char *enaddr;
2941541Srgrimes{
2951541Srgrimes	register struct mbuf *m;
2961541Srgrimes	register struct ether_header *eh;
2971541Srgrimes	register struct ether_arp *ea;
2981541Srgrimes	struct sockaddr sa;
29958313Slile	static u_char	llcx[] = { 0x82, 0x40, LLC_SNAP_LSAP, LLC_SNAP_LSAP,
30058313Slile				   LLC_UI, 0x00, 0x00, 0x00, 0x08, 0x06 };
3011541Srgrimes
3021541Srgrimes	if ((m = m_gethdr(M_DONTWAIT, MT_DATA)) == NULL)
3031541Srgrimes		return;
30444456Swpaul	m->m_pkthdr.rcvif = (struct ifnet *)0;
30544627Sjulian	switch (ac->ac_if.if_type) {
30644627Sjulian	case IFT_ISO88025:
30758313Slile		m->m_len = sizeof(*ea) + sizeof(llcx);
30858313Slile		m->m_pkthdr.len = sizeof(*ea) + sizeof(llcx);
30958313Slile		MH_ALIGN(m, sizeof(*ea) + sizeof(llcx));
31058313Slile		(void)memcpy(mtod(m, caddr_t), llcx, sizeof(llcx));
31144627Sjulian		(void)memcpy(sa.sa_data, etherbroadcastaddr, 6);
31244627Sjulian		(void)memcpy(sa.sa_data + 6, enaddr, 6);
31358313Slile		sa.sa_data[6] |= TR_RII;
31458313Slile		sa.sa_data[12] = TR_AC;
31558313Slile		sa.sa_data[13] = TR_LLC_FRAME;
31658313Slile		ea = (struct ether_arp *)(mtod(m, char *) + sizeof(llcx));
31744627Sjulian		bzero((caddr_t)ea, sizeof (*ea));
31844627Sjulian		ea->arp_hrd = htons(ARPHRD_IEEE802);
31944627Sjulian		break;
32051320Slile	case IFT_FDDI:
32151320Slile	case IFT_ETHER:
32251320Slile		/*
32351320Slile		 * This may not be correct for types not explicitly
32451320Slile		 * listed, but this is our best guess
32551320Slile		 */
32644627Sjulian	default:
32751320Slile		m->m_len = sizeof(*ea);
32851320Slile		m->m_pkthdr.len = sizeof(*ea);
32951320Slile		MH_ALIGN(m, sizeof(*ea));
33051320Slile		ea = mtod(m, struct ether_arp *);
33151320Slile		eh = (struct ether_header *)sa.sa_data;
33251320Slile		bzero((caddr_t)ea, sizeof (*ea));
33351320Slile		/* if_output will not swap */
33451320Slile		eh->ether_type = htons(ETHERTYPE_ARP);
33551320Slile		(void)memcpy(eh->ether_dhost, etherbroadcastaddr,
33651320Slile		    sizeof(eh->ether_dhost));
33751320Slile		ea->arp_hrd = htons(ARPHRD_ETHER);
33851320Slile		break;
33944627Sjulian	}
3401541Srgrimes	ea->arp_pro = htons(ETHERTYPE_IP);
3411541Srgrimes	ea->arp_hln = sizeof(ea->arp_sha);	/* hardware address length */
3421541Srgrimes	ea->arp_pln = sizeof(ea->arp_spa);	/* protocol address length */
3431541Srgrimes	ea->arp_op = htons(ARPOP_REQUEST);
3448384Sdg	(void)memcpy(ea->arp_sha, enaddr, sizeof(ea->arp_sha));
3458384Sdg	(void)memcpy(ea->arp_spa, sip, sizeof(ea->arp_spa));
3468384Sdg	(void)memcpy(ea->arp_tpa, tip, sizeof(ea->arp_tpa));
3471541Srgrimes	sa.sa_family = AF_UNSPEC;
3481541Srgrimes	sa.sa_len = sizeof(sa);
3491541Srgrimes	(*ac->ac_if.if_output)(&ac->ac_if, m, &sa, (struct rtentry *)0);
3501541Srgrimes}
3511541Srgrimes
3521541Srgrimes/*
3531541Srgrimes * Resolve an IP address into an ethernet address.  If success,
3541541Srgrimes * desten is filled in.  If there is no entry in arptab,
3551541Srgrimes * set one up and broadcast a request for the IP address.
3561541Srgrimes * Hold onto this mbuf and resend it once the address
3571541Srgrimes * is finally resolved.  A return value of 1 indicates
3581541Srgrimes * that desten has been filled in and the packet should be sent
3591541Srgrimes * normally; a 0 return indicates that the packet has been
3601541Srgrimes * taken over here, either now or for later transmission.
3611541Srgrimes */
3621541Srgrimesint
3633514Swollmanarpresolve(ac, rt, m, dst, desten, rt0)
3641541Srgrimes	register struct arpcom *ac;
3651541Srgrimes	register struct rtentry *rt;
3661541Srgrimes	struct mbuf *m;
3671541Srgrimes	register struct sockaddr *dst;
3681541Srgrimes	register u_char *desten;
3693514Swollman	struct rtentry *rt0;
3701541Srgrimes{
37178295Sjlemon	struct llinfo_arp *la = 0;
3721541Srgrimes	struct sockaddr_dl *sdl;
3731541Srgrimes
3741541Srgrimes	if (m->m_flags & M_BCAST) {	/* broadcast */
3758384Sdg		(void)memcpy(desten, etherbroadcastaddr, sizeof(etherbroadcastaddr));
3761541Srgrimes		return (1);
3771541Srgrimes	}
3781541Srgrimes	if (m->m_flags & M_MCAST) {	/* multicast */
3791541Srgrimes		ETHER_MAP_IP_MULTICAST(&SIN(dst)->sin_addr, desten);
3801541Srgrimes		return(1);
3811541Srgrimes	}
3821541Srgrimes	if (rt)
3831541Srgrimes		la = (struct llinfo_arp *)rt->rt_llinfo;
38442775Sfenner	if (la == 0) {
3853311Sphk		la = arplookup(SIN(dst)->sin_addr.s_addr, 1, 0);
3863311Sphk		if (la)
3871541Srgrimes			rt = la->la_rt;
3881541Srgrimes	}
3891541Srgrimes	if (la == 0 || rt == 0) {
39036308Sphk		log(LOG_DEBUG, "arpresolve: can't allocate llinfo for %s%s%s\n",
39136308Sphk			inet_ntoa(SIN(dst)->sin_addr), la ? "la" : "",
39236308Sphk				rt ? "rt" : "");
3931541Srgrimes		m_freem(m);
3941541Srgrimes		return (0);
3951541Srgrimes	}
3961541Srgrimes	sdl = SDL(rt->rt_gateway);
3971541Srgrimes	/*
3981541Srgrimes	 * Check the address family and length is valid, the address
3991541Srgrimes	 * is resolved; otherwise, try to resolve.
4001541Srgrimes	 */
40134961Sphk	if ((rt->rt_expire == 0 || rt->rt_expire > time_second) &&
4021541Srgrimes	    sdl->sdl_family == AF_LINK && sdl->sdl_alen != 0) {
40316206Sbde		bcopy(LLADDR(sdl), desten, sdl->sdl_alen);
4041541Srgrimes		return 1;
4051541Srgrimes	}
4061541Srgrimes	/*
40778295Sjlemon	 * If ARP is disabled on this interface, stop.
40878295Sjlemon	 * XXX
40978295Sjlemon	 * Probably should not allocate empty llinfo struct if we are
41078295Sjlemon	 * not going to be sending out an arp request.
41178295Sjlemon	 */
41278295Sjlemon	if (ac->ac_if.if_flags & IFF_NOARP)
41378295Sjlemon		return (0);
41478295Sjlemon	/*
4151541Srgrimes	 * There is an arptab entry, but no ethernet address
4161541Srgrimes	 * response yet.  Replace the held mbuf with this
4171541Srgrimes	 * latest one.
4181541Srgrimes	 */
4191541Srgrimes	if (la->la_hold)
4201541Srgrimes		m_freem(la->la_hold);
4211541Srgrimes	la->la_hold = m;
4221541Srgrimes	if (rt->rt_expire) {
4231541Srgrimes		rt->rt_flags &= ~RTF_REJECT;
42434961Sphk		if (la->la_asked == 0 || rt->rt_expire != time_second) {
42534961Sphk			rt->rt_expire = time_second;
4261541Srgrimes			if (la->la_asked++ < arp_maxtries)
42714761Sfenner			    arprequest(ac,
42836908Sjulian			        &SIN(rt->rt_ifa->ifa_addr)->sin_addr,
42936908Sjulian				&SIN(dst)->sin_addr, ac->ac_enaddr);
4301541Srgrimes			else {
4311541Srgrimes				rt->rt_flags |= RTF_REJECT;
4321541Srgrimes				rt->rt_expire += arpt_down;
4331541Srgrimes				la->la_asked = 0;
4341541Srgrimes			}
4351541Srgrimes
4361541Srgrimes		}
4371541Srgrimes	}
4381541Srgrimes	return (0);
4391541Srgrimes}
4401541Srgrimes
4411541Srgrimes/*
4421541Srgrimes * Common length and type checks are done here,
4431541Srgrimes * then the protocol-specific routine is called.
4441541Srgrimes */
44512693Sphkstatic void
44631884Sbdearpintr()
4471541Srgrimes{
44859143Swes	register struct mbuf *m;
4491541Srgrimes	register struct arphdr *ar;
45059143Swes	int s;
4511541Srgrimes
4521541Srgrimes	while (arpintrq.ifq_head) {
4531541Srgrimes		s = splimp();
4541541Srgrimes		IF_DEQUEUE(&arpintrq, m);
4551541Srgrimes		splx(s);
4561541Srgrimes		if (m == 0 || (m->m_flags & M_PKTHDR) == 0)
4571541Srgrimes			panic("arpintr");
45857900Srwatson
45957900Srwatson                if (m->m_len < sizeof(struct arphdr) &&
46058499Sdillon                    ((m = m_pullup(m, sizeof(struct arphdr))) == NULL)) {
46158758Sjoerg			log(LOG_ERR, "arp: runt packet -- m_pullup failed\n");
46257900Srwatson			continue;
46357900Srwatson		}
46457900Srwatson		ar = mtod(m, struct arphdr *);
4651541Srgrimes
46657900Srwatson		if (ntohs(ar->ar_hrd) != ARPHRD_ETHER
46757900Srwatson		    && ntohs(ar->ar_hrd) != ARPHRD_IEEE802) {
46857900Srwatson			log(LOG_ERR,
46958758Sjoerg			    "arp: unknown hardware address format (0x%2D)\n",
47057900Srwatson			    (unsigned char *)&ar->ar_hrd, "");
47157900Srwatson			m_freem(m);
47257900Srwatson			continue;
47357900Srwatson		}
4741541Srgrimes
47559143Swes		if (m->m_pkthdr.len < sizeof(struct arphdr) + 2 * ar->ar_hln
47657900Srwatson		    + 2 * ar->ar_pln) {
47758770Sjoerg			log(LOG_ERR, "arp: runt packet\n");
47857900Srwatson			m_freem(m);
47957900Srwatson			continue;
48057900Srwatson		}
48157900Srwatson
48257900Srwatson		switch (ntohs(ar->ar_pro)) {
48332350Seivind#ifdef INET
48457900Srwatson			case ETHERTYPE_IP:
48557900Srwatson				in_arpinput(m);
48657900Srwatson				continue;
48732350Seivind#endif
48857900Srwatson		}
4891541Srgrimes		m_freem(m);
4901541Srgrimes	}
4911541Srgrimes}
4921541Srgrimes
49332350Seivind#ifdef INET
4941541Srgrimes/*
4951541Srgrimes * ARP for Internet protocols on 10 Mb/s Ethernet.
4961541Srgrimes * Algorithm is that given in RFC 826.
4971541Srgrimes * In addition, a sanity check is performed on the sender
4981541Srgrimes * protocol address, to catch impersonators.
4991541Srgrimes * We no longer handle negotiations for use of trailer protocol:
5001541Srgrimes * Formerly, ARP replied for protocol type ETHERTYPE_TRAIL sent
5011541Srgrimes * along with IP replies if we wanted trailers sent to us,
5021541Srgrimes * and also sent them in response to IP replies.
5031541Srgrimes * This allowed either end to announce the desire to receive
5041541Srgrimes * trailer packets.
5051541Srgrimes * We no longer reply to requests for ETHERTYPE_TRAIL protocol either,
5061541Srgrimes * but formerly didn't normally send requests.
5071541Srgrimes */
50870699Salfredstatic int log_arp_wrong_iface = 1;
50982893Salfredstatic int log_arp_movements = 1;
51070699Salfred
51170699SalfredSYSCTL_INT(_net_link_ether_inet, OID_AUTO, log_arp_wrong_iface, CTLFLAG_RW,
51270699Salfred	&log_arp_wrong_iface, 0,
51370699Salfred	"log arp packets arriving on the wrong interface");
51482893SalfredSYSCTL_INT(_net_link_ether_inet, OID_AUTO, log_arp_movements, CTLFLAG_RW,
51582893Salfred        &log_arp_movements, 0,
51682966Salfred        "log arp replies from MACs different than the one in the cache");
51770699Salfred
51882893Salfred
5191541Srgrimesstatic void
5201541Srgrimesin_arpinput(m)
5211541Srgrimes	struct mbuf *m;
5221541Srgrimes{
5231541Srgrimes	register struct ether_arp *ea;
5241541Srgrimes	register struct arpcom *ac = (struct arpcom *)m->m_pkthdr.rcvif;
5251541Srgrimes	struct ether_header *eh;
52644627Sjulian	struct iso88025_header *th = (struct iso88025_header *)0;
5271541Srgrimes	register struct llinfo_arp *la = 0;
5281541Srgrimes	register struct rtentry *rt;
52984102Sjlemon	struct ifaddr *ifa;
53084102Sjlemon	struct in_ifaddr *ia;
5311541Srgrimes	struct sockaddr_dl *sdl;
5321541Srgrimes	struct sockaddr sa;
5331541Srgrimes	struct in_addr isaddr, itaddr, myaddr;
53458313Slile	int op, rif_len;
5351541Srgrimes
53674851Syar	if (m->m_len < sizeof(struct ether_arp) &&
53774851Syar	    (m = m_pullup(m, sizeof(struct ether_arp))) == NULL) {
53874851Syar		log(LOG_ERR, "in_arp: runt packet -- m_pullup failed\n");
53974851Syar		return;
54074851Syar	}
54174851Syar
5421541Srgrimes	ea = mtod(m, struct ether_arp *);
5431541Srgrimes	op = ntohs(ea->arp_op);
5448384Sdg	(void)memcpy(&isaddr, ea->arp_spa, sizeof (isaddr));
5458384Sdg	(void)memcpy(&itaddr, ea->arp_tpa, sizeof (itaddr));
54672056Sjulian#ifdef BRIDGE
54772056Sjulian#define BRIDGE_TEST (do_bridge)
54871963Sjulian#else
54972056Sjulian#define BRIDGE_TEST (0) /* cc will optimise the test away */
55041793Sluigi#endif
55184102Sjlemon	/*
55284102Sjlemon	 * For a bridge, we want to check the address irrespective
55384102Sjlemon	 * of the receive interface. (This will change slightly
55484102Sjlemon	 * when we have clusters of interfaces).
55584102Sjlemon	 */
55684102Sjlemon	LIST_FOREACH(ia, INADDR_HASH(itaddr.s_addr), ia_hash)
55784102Sjlemon		if ((BRIDGE_TEST || (ia->ia_ifp == &ac->ac_if)) &&
55884102Sjlemon		    itaddr.s_addr == ia->ia_addr.sin_addr.s_addr)
55984102Sjlemon			goto match;
56084102Sjlemon	LIST_FOREACH(ia, INADDR_HASH(isaddr.s_addr), ia_hash)
56184102Sjlemon		if ((BRIDGE_TEST || (ia->ia_ifp == &ac->ac_if)) &&
56284102Sjlemon		    isaddr.s_addr == ia->ia_addr.sin_addr.s_addr)
56384102Sjlemon			goto match;
56484102Sjlemon	/*
56584102Sjlemon	 * No match, use the first address on the receive interface
56684102Sjlemon	 * as a dummy address for the rest of the function.
56784102Sjlemon	 */
56884102Sjlemon	ifa = TAILQ_FIRST(&ac->ac_if.if_addrhead);
56984102Sjlemon	if (ifa == NULL) {
57012693Sphk		m_freem(m);
57112693Sphk		return;
57212693Sphk	}
57384102Sjlemon	ia = ifatoia(ifa);
57484102Sjlemonmatch:
57584102Sjlemon	myaddr = ia->ia_addr.sin_addr;
5761541Srgrimes	if (!bcmp((caddr_t)ea->arp_sha, (caddr_t)ac->ac_enaddr,
57712693Sphk	    sizeof (ea->arp_sha))) {
57812693Sphk		m_freem(m);	/* it's from me, ignore it. */
57912693Sphk		return;
58012693Sphk	}
5811541Srgrimes	if (!bcmp((caddr_t)ea->arp_sha, (caddr_t)etherbroadcastaddr,
5821541Srgrimes	    sizeof (ea->arp_sha))) {
5831541Srgrimes		log(LOG_ERR,
5844069Swollman		    "arp: ether address is broadcast for IP address %s!\n",
5857088Swollman		    inet_ntoa(isaddr));
58612693Sphk		m_freem(m);
58712693Sphk		return;
5881541Srgrimes	}
5891541Srgrimes	if (isaddr.s_addr == myaddr.s_addr) {
5901541Srgrimes		log(LOG_ERR,
59119794Sfenner		   "arp: %6D is using my IP address %s!\n",
59219794Sfenner		   ea->arp_sha, ":", inet_ntoa(isaddr));
5931541Srgrimes		itaddr = myaddr;
5941541Srgrimes		goto reply;
5951541Srgrimes	}
5961541Srgrimes	la = arplookup(isaddr.s_addr, itaddr.s_addr == myaddr.s_addr, 0);
5971541Srgrimes	if (la && (rt = la->la_rt) && (sdl = SDL(rt->rt_gateway))) {
59872270Sluigi		/* the following is not an error when doing bridging */
59972270Sluigi		if (!BRIDGE_TEST && rt->rt_ifp != &ac->ac_if) {
60072270Sluigi			if (log_arp_wrong_iface)
60171963Sjulian				log(LOG_ERR, "arp: %s is on %s%d but got reply from %6D on %s%d\n",
60271963Sjulian				    inet_ntoa(isaddr),
60371963Sjulian				    rt->rt_ifp->if_name, rt->rt_ifp->if_unit,
60471963Sjulian				    ea->arp_sha, ":",
60571963Sjulian				    ac->ac_if.if_name, ac->ac_if.if_unit);
60672270Sluigi			goto reply;
60739389Sfenner		}
6081541Srgrimes		if (sdl->sdl_alen &&
60946568Speter		    bcmp((caddr_t)ea->arp_sha, LLADDR(sdl), sdl->sdl_alen)) {
61082893Salfred			if (rt->rt_expire) {
61182893Salfred			    if (log_arp_movements)
61282893Salfred				log(LOG_INFO, "arp: %s moved from %6D to %6D on %s%d\n",
61382893Salfred				    inet_ntoa(isaddr), (u_char *)LLADDR(sdl), ":",
61482893Salfred				    ea->arp_sha, ":",
61582893Salfred				    ac->ac_if.if_name, ac->ac_if.if_unit);
61682893Salfred			} else {
61739389Sfenner			    log(LOG_ERR,
61852377Ssheldonh				"arp: %6D attempts to modify permanent entry for %s on %s%d\n",
61939389Sfenner				ea->arp_sha, ":", inet_ntoa(isaddr),
62039389Sfenner				ac->ac_if.if_name, ac->ac_if.if_unit);
62139389Sfenner			    goto reply;
62239389Sfenner			}
62346568Speter		}
6248384Sdg		(void)memcpy(LLADDR(sdl), ea->arp_sha, sizeof(ea->arp_sha));
6258384Sdg		sdl->sdl_alen = sizeof(ea->arp_sha);
62658313Slile                sdl->sdl_rcf = (u_short)0;
62745705Seivind		/*
62845705Seivind		 * If we receive an arp from a token-ring station over
62945705Seivind		 * a token-ring nic then try to save the source
63045705Seivind		 * routing info.
63145705Seivind		 */
63245705Seivind		if (ac->ac_if.if_type == IFT_ISO88025) {
63344627Sjulian			th = (struct iso88025_header *)m->m_pkthdr.header;
63458313Slile			rif_len = TR_RCF_RIFLEN(th->rcf);
63558313Slile			if ((th->iso88025_shost[0] & TR_RII) &&
63658313Slile			    (rif_len > 2)) {
63758313Slile				sdl->sdl_rcf = th->rcf;
63858313Slile				sdl->sdl_rcf ^= htons(TR_RCF_DIR);
63958313Slile				memcpy(sdl->sdl_route, th->rd, rif_len - 2);
64058313Slile				sdl->sdl_rcf &= ~htons(TR_RCF_BCST_MASK);
64151320Slile				/*
64251320Slile				 * Set up source routing information for
64351320Slile				 * reply packet (XXX)
64451320Slile				 */
64558313Slile				m->m_data -= rif_len;
64658313Slile				m->m_len  += rif_len;
64758313Slile				m->m_pkthdr.len += rif_len;
64844627Sjulian			} else {
64958313Slile				th->iso88025_shost[0] &= ~TR_RII;
65044627Sjulian			}
65150512Slile			m->m_data -= 8;
65250512Slile			m->m_len  += 8;
65350512Slile			m->m_pkthdr.len += 8;
65444627Sjulian			th->rcf = sdl->sdl_rcf;
65545705Seivind		} else {
65658313Slile			sdl->sdl_rcf = (u_short)0;
65744627Sjulian		}
6581541Srgrimes		if (rt->rt_expire)
65934961Sphk			rt->rt_expire = time_second + arpt_keep;
6601541Srgrimes		rt->rt_flags &= ~RTF_REJECT;
6611541Srgrimes		la->la_asked = 0;
6621541Srgrimes		if (la->la_hold) {
6631541Srgrimes			(*ac->ac_if.if_output)(&ac->ac_if, la->la_hold,
6641541Srgrimes				rt_key(rt), rt);
6651541Srgrimes			la->la_hold = 0;
6661541Srgrimes		}
6671541Srgrimes	}
6681541Srgrimesreply:
6691541Srgrimes	if (op != ARPOP_REQUEST) {
6701541Srgrimes		m_freem(m);
6711541Srgrimes		return;
6721541Srgrimes	}
6731541Srgrimes	if (itaddr.s_addr == myaddr.s_addr) {
6741541Srgrimes		/* I am the target */
6758384Sdg		(void)memcpy(ea->arp_tha, ea->arp_sha, sizeof(ea->arp_sha));
6768384Sdg		(void)memcpy(ea->arp_sha, ac->ac_enaddr, sizeof(ea->arp_sha));
6771541Srgrimes	} else {
6781541Srgrimes		la = arplookup(itaddr.s_addr, 0, SIN_PROXY);
6793282Swollman		if (la == NULL) {
6803282Swollman			struct sockaddr_in sin;
6813282Swollman
68212693Sphk			if (!arp_proxyall) {
68312693Sphk				m_freem(m);
68412693Sphk				return;
68512693Sphk			}
6863282Swollman
6873282Swollman			bzero(&sin, sizeof sin);
6883282Swollman			sin.sin_family = AF_INET;
6893282Swollman			sin.sin_len = sizeof sin;
6903282Swollman			sin.sin_addr = itaddr;
6913282Swollman
6925101Swollman			rt = rtalloc1((struct sockaddr *)&sin, 0, 0UL);
69312693Sphk			if (!rt) {
69412693Sphk				m_freem(m);
69512693Sphk				return;
69612693Sphk			}
6973282Swollman			/*
6983282Swollman			 * Don't send proxies for nodes on the same interface
6993282Swollman			 * as this one came out of, or we'll get into a fight
7003282Swollman			 * over who claims what Ether address.
7013282Swollman			 */
70212693Sphk			if (rt->rt_ifp == &ac->ac_if) {
7033282Swollman				rtfree(rt);
70412693Sphk				m_freem(m);
70512693Sphk				return;
7063282Swollman			}
7078384Sdg			(void)memcpy(ea->arp_tha, ea->arp_sha, sizeof(ea->arp_sha));
7088384Sdg			(void)memcpy(ea->arp_sha, ac->ac_enaddr, sizeof(ea->arp_sha));
7093282Swollman			rtfree(rt);
71063080Sdwmalone
71163080Sdwmalone			/*
71263080Sdwmalone			 * Also check that the node which sent the ARP packet
71363080Sdwmalone			 * is on the the interface we expect it to be on. This
71463080Sdwmalone			 * avoids ARP chaos if an interface is connected to the
71563080Sdwmalone			 * wrong network.
71663080Sdwmalone			 */
71763080Sdwmalone			sin.sin_addr = isaddr;
71863080Sdwmalone
71963080Sdwmalone			rt = rtalloc1((struct sockaddr *)&sin, 0, 0UL);
72063080Sdwmalone			if (!rt) {
72163080Sdwmalone				m_freem(m);
72263080Sdwmalone				return;
72363080Sdwmalone			}
72463080Sdwmalone			if (rt->rt_ifp != &ac->ac_if) {
72563080Sdwmalone				log(LOG_INFO, "arp_proxy: ignoring request"
72663080Sdwmalone				    " from %s via %s%d, expecting %s%d\n",
72763080Sdwmalone				    inet_ntoa(isaddr), ac->ac_if.if_name,
72863080Sdwmalone				    ac->ac_if.if_unit, rt->rt_ifp->if_name,
72963080Sdwmalone				    rt->rt_ifp->if_unit);
73063080Sdwmalone				rtfree(rt);
73163080Sdwmalone				m_freem(m);
73263080Sdwmalone				return;
73363080Sdwmalone			}
73463080Sdwmalone			rtfree(rt);
73563080Sdwmalone
7364069Swollman#ifdef DEBUG_PROXY
7378876Srgrimes			printf("arp: proxying for %s\n",
7387088Swollman			       inet_ntoa(itaddr));
7394069Swollman#endif
7403282Swollman		} else {
7413282Swollman			rt = la->la_rt;
7428384Sdg			(void)memcpy(ea->arp_tha, ea->arp_sha, sizeof(ea->arp_sha));
7433282Swollman			sdl = SDL(rt->rt_gateway);
7448384Sdg			(void)memcpy(ea->arp_sha, LLADDR(sdl), sizeof(ea->arp_sha));
7453282Swollman		}
7461541Srgrimes	}
7471541Srgrimes
7488384Sdg	(void)memcpy(ea->arp_tpa, ea->arp_spa, sizeof(ea->arp_spa));
7498384Sdg	(void)memcpy(ea->arp_spa, &itaddr, sizeof(ea->arp_spa));
7501541Srgrimes	ea->arp_op = htons(ARPOP_REPLY);
7511541Srgrimes	ea->arp_pro = htons(ETHERTYPE_IP); /* let's be sure! */
75245705Seivind	switch (ac->ac_if.if_type) {
75345705Seivind	case IFT_ISO88025:
75444627Sjulian		/* Re-arrange the source/dest address */
75551320Slile		memcpy(th->iso88025_dhost, th->iso88025_shost,
75651320Slile		    sizeof(th->iso88025_dhost));
75751320Slile		memcpy(th->iso88025_shost, ac->ac_enaddr,
75851320Slile		    sizeof(th->iso88025_shost));
75944627Sjulian		/* Set the source routing bit if neccesary */
76058313Slile		if (th->iso88025_dhost[0] & TR_RII) {
76158313Slile			th->iso88025_dhost[0] &= ~TR_RII;
76258313Slile			if (TR_RCF_RIFLEN(th->rcf) > 2)
76358313Slile				th->iso88025_shost[0] |= TR_RII;
76444627Sjulian		}
76544627Sjulian		/* Copy the addresses, ac and fc into sa_data */
76651320Slile		memcpy(sa.sa_data, th->iso88025_dhost,
76751320Slile		    sizeof(th->iso88025_dhost) * 2);
76858313Slile		sa.sa_data[(sizeof(th->iso88025_dhost) * 2)] = TR_AC;
76958313Slile		sa.sa_data[(sizeof(th->iso88025_dhost) * 2) + 1] = TR_LLC_FRAME;
77044627Sjulian		break;
77145705Seivind	case IFT_ETHER:
77251320Slile	case IFT_FDDI:
77351320Slile	/*
77451320Slile	 * May not be correct for types not explictly
77551320Slile	 * listed, but it is our best guess.
77651320Slile	 */
77751320Slile	default:
77844627Sjulian		eh = (struct ether_header *)sa.sa_data;
77951320Slile		(void)memcpy(eh->ether_dhost, ea->arp_tha,
78051320Slile		    sizeof(eh->ether_dhost));
78144627Sjulian		eh->ether_type = htons(ETHERTYPE_ARP);
78244627Sjulian		break;
78344627Sjulian	}
7841541Srgrimes	sa.sa_family = AF_UNSPEC;
7851541Srgrimes	sa.sa_len = sizeof(sa);
7861541Srgrimes	(*ac->ac_if.if_output)(&ac->ac_if, m, &sa, (struct rtentry *)0);
7871541Srgrimes	return;
7881541Srgrimes}
78932350Seivind#endif
7901541Srgrimes
7911541Srgrimes/*
7921541Srgrimes * Free an arp entry.
7931541Srgrimes */
7941541Srgrimesstatic void
7951541Srgrimesarptfree(la)
7961541Srgrimes	register struct llinfo_arp *la;
7971541Srgrimes{
7981541Srgrimes	register struct rtentry *rt = la->la_rt;
7991541Srgrimes	register struct sockaddr_dl *sdl;
8001541Srgrimes	if (rt == 0)
8011541Srgrimes		panic("arptfree");
8021541Srgrimes	if (rt->rt_refcnt > 0 && (sdl = SDL(rt->rt_gateway)) &&
8031541Srgrimes	    sdl->sdl_family == AF_LINK) {
8041541Srgrimes		sdl->sdl_alen = 0;
8051541Srgrimes		la->la_asked = 0;
8061541Srgrimes		rt->rt_flags &= ~RTF_REJECT;
8071541Srgrimes		return;
8081541Srgrimes	}
8091541Srgrimes	rtrequest(RTM_DELETE, rt_key(rt), (struct sockaddr *)0, rt_mask(rt),
8101541Srgrimes			0, (struct rtentry **)0);
8111541Srgrimes}
8121541Srgrimes/*
8131541Srgrimes * Lookup or enter a new address in arptab.
8141541Srgrimes */
8151541Srgrimesstatic struct llinfo_arp *
8161541Srgrimesarplookup(addr, create, proxy)
8171541Srgrimes	u_long addr;
8181541Srgrimes	int create, proxy;
8191541Srgrimes{
8201541Srgrimes	register struct rtentry *rt;
8211541Srgrimes	static struct sockaddr_inarp sin = {sizeof(sin), AF_INET };
8224069Swollman	const char *why = 0;
8231541Srgrimes
8241541Srgrimes	sin.sin_addr.s_addr = addr;
8251541Srgrimes	sin.sin_other = proxy ? SIN_PROXY : 0;
8265101Swollman	rt = rtalloc1((struct sockaddr *)&sin, create, 0UL);
8271541Srgrimes	if (rt == 0)
8281541Srgrimes		return (0);
8291541Srgrimes	rt->rt_refcnt--;
8304069Swollman
83112693Sphk	if (rt->rt_flags & RTF_GATEWAY)
8324069Swollman		why = "host is not on local network";
83312693Sphk	else if ((rt->rt_flags & RTF_LLINFO) == 0)
8344069Swollman		why = "could not allocate llinfo";
83512693Sphk	else if (rt->rt_gateway->sa_family != AF_LINK)
8364069Swollman		why = "gateway route is not ours";
8374069Swollman
83812693Sphk	if (why && create) {
8394069Swollman		log(LOG_DEBUG, "arplookup %s failed: %s\n",
8407088Swollman		    inet_ntoa(sin.sin_addr), why);
8414069Swollman		return 0;
84212693Sphk	} else if (why) {
8434069Swollman		return 0;
8441541Srgrimes	}
8451541Srgrimes	return ((struct llinfo_arp *)rt->rt_llinfo);
8461541Srgrimes}
8471541Srgrimes
8485195Swollmanvoid
8495195Swollmanarp_ifinit(ac, ifa)
8505195Swollman	struct arpcom *ac;
8515195Swollman	struct ifaddr *ifa;
8525195Swollman{
85325822Stegge	if (ntohl(IA_SIN(ifa)->sin_addr.s_addr) != INADDR_ANY)
85436908Sjulian		arprequest(ac, &IA_SIN(ifa)->sin_addr,
85536908Sjulian			       &IA_SIN(ifa)->sin_addr, ac->ac_enaddr);
8565195Swollman	ifa->ifa_rtrequest = arp_rtrequest;
8575195Swollman	ifa->ifa_flags |= RTF_CLONING;
8585195Swollman}
85969152Sjlemon
86069152Sjlemonstatic void
86169152Sjlemonarp_init(void)
86269152Sjlemon{
86369152Sjlemon
86469152Sjlemon	arpintrq.ifq_maxlen = 50;
86569152Sjlemon	mtx_init(&arpintrq.ifq_mtx, "arp_inq", MTX_DEF);
86669152Sjlemon}
86769152Sjlemon
86869152SjlemonSYSINIT(arp, SI_SUB_PROTO_DOMAIN, SI_ORDER_ANY, arp_init, 0);
869