mirror of
https://github.com/freebsd/freebsd-src.git
synced 2024-12-03 14:48:57 +00:00
bring in ARP support for variable length link level addresses
Reviewed by: jdp Approved by: jdp Obtained from: NetBSD MFC after: 6 weeks
This commit is contained in:
parent
ca8f579ceb
commit
322dcb8d3d
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=84931
@ -429,6 +429,7 @@ if_attach(ifp)
|
||||
sdl->sdl_data[--namelen] = 0xff;
|
||||
TAILQ_INSERT_HEAD(&ifp->if_addrhead, ifa, ifa_link);
|
||||
}
|
||||
ifp->if_broadcastaddr = 0; /* reliably crash if used uninitialized */
|
||||
}
|
||||
|
||||
/*
|
||||
|
149
sys/net/if_arc.h
Normal file
149
sys/net/if_arc.h
Normal file
@ -0,0 +1,149 @@
|
||||
/* $NetBSD: if_arc.h,v 1.13 1999/11/19 20:41:19 thorpej Exp $ */
|
||||
/* $FreeBSD$ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1982, 1986, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* from: NetBSD: if_ether.h,v 1.10 1994/06/29 06:37:55 cgd Exp
|
||||
* @(#)if_ether.h 8.1 (Berkeley) 6/10/93
|
||||
*/
|
||||
|
||||
#ifndef _NET_IF_ARC_H_
|
||||
#define _NET_IF_ARC_H_
|
||||
|
||||
/*
|
||||
* Arcnet address - 1 octets
|
||||
* don't know who uses this.
|
||||
*/
|
||||
struct arc_addr {
|
||||
u_int8_t arc_addr_octet[1];
|
||||
} __attribute__((__packed__));
|
||||
|
||||
/*
|
||||
* Structure of a 2.5MB/s Arcnet header.
|
||||
* as given to interface code.
|
||||
*/
|
||||
struct arc_header {
|
||||
u_int8_t arc_shost;
|
||||
u_int8_t arc_dhost;
|
||||
u_int8_t arc_type;
|
||||
/*
|
||||
* only present for newstyle encoding with LL fragmentation.
|
||||
* Don't use sizeof(anything), use ARC_HDR{,NEW}LEN instead.
|
||||
*/
|
||||
u_int8_t arc_flag;
|
||||
u_int16_t arc_seqid;
|
||||
|
||||
/*
|
||||
* only present in exception packets (arc_flag == 0xff)
|
||||
*/
|
||||
u_int8_t arc_type2; /* same as arc_type */
|
||||
u_int8_t arc_flag2; /* real flag value */
|
||||
u_int16_t arc_seqid2; /* real seqid value */
|
||||
} __attribute__((__packed__));
|
||||
|
||||
#define ARC_ADDR_LEN 1
|
||||
|
||||
#define ARC_HDRLEN 3
|
||||
#define ARC_HDRNEWLEN 6
|
||||
#define ARC_HDRNEWLEN_EXC 10
|
||||
|
||||
/* these lengths are data link layer length - 2*ARC_ADDR_LEN */
|
||||
#define ARC_MIN_LEN 1
|
||||
#define ARC_MIN_FORBID_LEN 254
|
||||
#define ARC_MAX_FORBID_LEN 256
|
||||
#define ARC_MAX_LEN 508
|
||||
|
||||
|
||||
/* RFC 1051 */
|
||||
#define ARCTYPE_IP_OLD 240 /* IP protocol */
|
||||
#define ARCTYPE_ARP_OLD 241 /* address resolution protocol */
|
||||
|
||||
/* RFC 1201 */
|
||||
#define ARCTYPE_IP 212 /* IP protocol */
|
||||
#define ARCTYPE_ARP 213 /* address resolution protocol */
|
||||
#define ARCTYPE_REVARP 214 /* reverse addr resolution protocol */
|
||||
|
||||
#define ARCTYPE_ATALK 221 /* Appletalk */
|
||||
#define ARCTYPE_BANIAN 247 /* Banyan Vines */
|
||||
#define ARCTYPE_IPX 250 /* Novell IPX */
|
||||
|
||||
#define ARCTYPE_INET6 0xc4 /* IPng */
|
||||
#define ARCTYPE_DIAGNOSE 0x80 /* as per ANSI/ATA 878.1 */
|
||||
|
||||
#define ARCMTU 507
|
||||
#define ARCMIN 0
|
||||
|
||||
#define ARC_PHDS_MAXMTU 60480
|
||||
|
||||
struct arccom {
|
||||
struct ifnet ac_if; /* network-visible interface */
|
||||
|
||||
u_int16_t ac_seqid; /* seq. id used by PHDS encap. */
|
||||
|
||||
u_int8_t arc_shost;
|
||||
u_int8_t arc_dhost;
|
||||
u_int8_t arc_type;
|
||||
|
||||
u_int8_t dummy0;
|
||||
u_int16_t dummy1;
|
||||
int sflag, fsflag, rsflag;
|
||||
struct mbuf *curr_frag;
|
||||
|
||||
struct ac_frag {
|
||||
u_int8_t af_maxflag; /* from first packet */
|
||||
u_int8_t af_lastseen; /* last split flag seen */
|
||||
u_int16_t af_seqid;
|
||||
struct mbuf *af_packet;
|
||||
} ac_fragtab[256]; /* indexed by sender ll address */
|
||||
};
|
||||
|
||||
#ifdef _KERNEL
|
||||
extern u_int8_t arcbroadcastaddr;
|
||||
extern int arc_ipmtu; /* XXX new ip only, no RFC 1051! */
|
||||
|
||||
void arc_ifattach __P((struct ifnet *, u_int8_t));
|
||||
void arc_ifdetach __P((struct ifnet *));
|
||||
void arc_storelladdr __P((struct ifnet *, u_int8_t));
|
||||
char *arc_sprintf __P((u_int8_t *));
|
||||
int arc_isphds __P((int));
|
||||
void arc_input __P((struct ifnet *, struct mbuf *));
|
||||
int arc_output __P((struct ifnet *, struct mbuf *,
|
||||
struct sockaddr *, struct rtentry *));
|
||||
int arc_ioctl __P((struct ifnet *, int, caddr_t));
|
||||
|
||||
void arc_frag_init __P((struct ifnet *));
|
||||
struct mbuf * arc_frag_next __P((struct ifnet *));
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* _NET_IF_ARC_H_ */
|
@ -51,6 +51,7 @@ struct arphdr {
|
||||
u_short ar_hrd; /* format of hardware address */
|
||||
#define ARPHRD_ETHER 1 /* ethernet hardware format */
|
||||
#define ARPHRD_IEEE802 6 /* token-ring hardware format */
|
||||
#define ARPHRD_ARCNET 7 /* arcnet hardware format */
|
||||
#define ARPHRD_FRELAY 15 /* frame relay hardware format */
|
||||
u_short ar_pro; /* format of protocol address */
|
||||
u_char ar_hln; /* length of hardware address */
|
||||
@ -74,6 +75,15 @@ struct arphdr {
|
||||
#endif
|
||||
};
|
||||
|
||||
#define ar_sha(ap) (((caddr_t)((ap)+1)) + 0)
|
||||
#define ar_spa(ap) (((caddr_t)((ap)+1)) + (ap)->ar_hln)
|
||||
#define ar_tha(ap) (((caddr_t)((ap)+1)) + (ap)->ar_hln + (ap)->ar_pln)
|
||||
#define ar_tpa(ap) (((caddr_t)((ap)+1)) + 2*(ap)->ar_hln + (ap)->ar_pln)
|
||||
|
||||
#define arphdr_len2(ar_hln, ar_pln) \
|
||||
(sizeof(struct arphdr) + 2*(ar_hln) + 2*(ar_pln))
|
||||
#define arphdr_len(ap) (arphdr_len2((ap)->ar_hln, (ap)->ar_pln))
|
||||
|
||||
/*
|
||||
* ARP ioctl request
|
||||
*/
|
||||
|
@ -178,7 +178,7 @@ ether_output(ifp, m, dst, rt0)
|
||||
switch (dst->sa_family) {
|
||||
#ifdef INET
|
||||
case AF_INET:
|
||||
if (!arpresolve(ac, rt, m, dst, edst, rt0))
|
||||
if (!arpresolve(ifp, rt, m, dst, edst, rt0))
|
||||
return (0); /* if not yet resolved */
|
||||
off = m->m_pkthdr.len - m->m_len;
|
||||
type = htons(ETHERTYPE_IP);
|
||||
@ -663,6 +663,7 @@ ether_ifattach(ifp, bpf)
|
||||
ifp->if_resolvemulti = ether_resolvemulti;
|
||||
if (ifp->if_baudrate == 0)
|
||||
ifp->if_baudrate = 10000000;
|
||||
ifp->if_broadcastaddr = etherbroadcastaddr;
|
||||
ifa = ifaddr_byindex(ifp->if_index);
|
||||
KASSERT(ifa != NULL, ("%s: no lladdr!\n", __FUNCTION__));
|
||||
sdl = (struct sockaddr_dl *)ifa->ifa_addr;
|
||||
@ -715,7 +716,7 @@ ether_ioctl(ifp, command, data)
|
||||
#ifdef INET
|
||||
case AF_INET:
|
||||
ifp->if_init(ifp->if_softc); /* before arpwhohas */
|
||||
arp_ifinit(IFP2AC(ifp), ifa);
|
||||
arp_ifinit(ifp, ifa);
|
||||
break;
|
||||
#endif
|
||||
#ifdef IPX
|
||||
|
@ -166,7 +166,7 @@ fddi_output(ifp, m, dst, rt0)
|
||||
#ifdef INET
|
||||
case AF_INET: {
|
||||
#if !defined(__bsdi__) || _BSDI_VERSION >= 199401
|
||||
if (!ARPRESOLVE(ac, rt, m, dst, edst, rt0))
|
||||
if (!ARPRESOLVE(ifp, rt, m, dst, edst, rt0))
|
||||
return (0); /* if not yet resolved */
|
||||
#else
|
||||
int usetrailers;
|
||||
@ -525,6 +525,7 @@ fddi_ifattach(ifp)
|
||||
#ifdef IFF_NOTRAILERS
|
||||
ifp->if_flags |= IFF_NOTRAILERS;
|
||||
#endif
|
||||
ifp->if_broadcastaddr = fddibroadcastaddr;
|
||||
#if defined(__FreeBSD__)
|
||||
ifa = ifaddr_byindex(ifp->if_index);
|
||||
sdl = (struct sockaddr_dl *)ifa->ifa_addr;
|
||||
|
@ -101,6 +101,7 @@ iso88025_ifattach(struct ifnet *ifp)
|
||||
ifp->if_baudrate = TR_16MBPS; /* 16Mbit should be a safe default */
|
||||
if (ifp->if_mtu == 0)
|
||||
ifp->if_mtu = ISO88025_DEFAULT_MTU;
|
||||
ifp->if_broadcastaddr = etherbroadcastaddr;
|
||||
|
||||
ifa = ifaddr_byindex(ifp->if_index);
|
||||
if (ifa == 0) {
|
||||
@ -142,7 +143,7 @@ iso88025_ioctl(struct ifnet *ifp, int command, caddr_t data)
|
||||
#ifdef INET
|
||||
case AF_INET:
|
||||
ifp->if_init(ifp->if_softc); /* before arpwhohas */
|
||||
arp_ifinit((struct arpcom *)ifp, ifa);
|
||||
arp_ifinit(ifp, ifa);
|
||||
break;
|
||||
#endif /* INET */
|
||||
#ifdef IPX
|
||||
@ -272,7 +273,7 @@ iso88025_output(ifp, m, dst, rt0)
|
||||
switch (dst->sa_family) {
|
||||
#ifdef INET
|
||||
case AF_INET:
|
||||
if (!arpresolve(ac, rt, m, dst, edst, rt0))
|
||||
if (!arpresolve(ifp, rt, m, dst, edst, rt0))
|
||||
return (0); /* if not yet resolved */
|
||||
snap_type = ETHERTYPE_IP;
|
||||
break;
|
||||
|
@ -158,6 +158,7 @@ struct ifnet {
|
||||
struct ifqueue if_snd; /* output queue */
|
||||
struct ifqueue *if_poll_slowq; /* input queue for slow devices */
|
||||
struct ifprefixhead if_prefixhead; /* list of prefixes per if */
|
||||
u_int8_t *if_broadcastaddr; /* linklevel broadcast bytestring */
|
||||
};
|
||||
|
||||
typedef void if_init_f_t __P((void *));
|
||||
@ -447,6 +448,9 @@ void if_clone_detach __P((struct if_clone *));
|
||||
int if_clone_create __P((char *, int));
|
||||
int if_clone_destroy __P((const char *));
|
||||
|
||||
#define IF_LLADDR(ifp) \
|
||||
LLADDR((struct sockaddr_dl *) ifaddr_byindex((ifp)->if_index)->ifa_addr)
|
||||
|
||||
#endif /* _KERNEL */
|
||||
|
||||
#endif /* !_NET_IF_VAR_H_ */
|
||||
|
@ -581,7 +581,7 @@ vlan_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
|
||||
switch (ifa->ifa_addr->sa_family) {
|
||||
#ifdef INET
|
||||
case AF_INET:
|
||||
arp_ifinit(&ifv->ifv_ac, ifa);
|
||||
arp_ifinit(&ifv->ifv_if, ifa);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
|
@ -68,6 +68,7 @@
|
||||
#include <netinet/in_var.h>
|
||||
#include <netinet/if_ether.h>
|
||||
|
||||
#include <net/if_arc.h>
|
||||
#include <net/iso88025.h>
|
||||
|
||||
#define SIN(s) ((struct sockaddr_in *)s)
|
||||
@ -116,7 +117,7 @@ SYSCTL_INT(_net_link_ether_inet, OID_AUTO, proxyall, CTLFLAG_RW,
|
||||
|
||||
static void arp_init __P((void));
|
||||
static void arp_rtrequest __P((int, struct rtentry *, struct sockaddr *));
|
||||
static void arprequest __P((struct arpcom *,
|
||||
static void arprequest __P((struct ifnet *,
|
||||
struct in_addr *, struct in_addr *, u_char *));
|
||||
static void arpintr __P((void));
|
||||
static void arptfree __P((struct llinfo_arp *));
|
||||
@ -196,7 +197,7 @@ arp_rtrequest(req, rt, sa)
|
||||
}
|
||||
/* Announce a new entry if requested. */
|
||||
if (rt->rt_flags & RTF_ANNOUNCE)
|
||||
arprequest((struct arpcom *)rt->rt_ifp,
|
||||
arprequest(rt->rt_ifp,
|
||||
&SIN(rt_key(rt))->sin_addr,
|
||||
&SIN(rt_key(rt))->sin_addr,
|
||||
(u_char *)LLADDR(SDL(gate)));
|
||||
@ -233,15 +234,17 @@ arp_rtrequest(req, rt, sa)
|
||||
* in `arp -a' listings as unresolved. It's not actually
|
||||
* functional. Then the same for broadcast.
|
||||
*/
|
||||
if (IN_MULTICAST(ntohl(SIN(rt_key(rt))->sin_addr.s_addr))) {
|
||||
if (IN_MULTICAST(ntohl(SIN(rt_key(rt))->sin_addr.s_addr))
|
||||
&& rt->rt_ifp->if_type != IFT_ARCNET) {
|
||||
ETHER_MAP_IP_MULTICAST(&SIN(rt_key(rt))->sin_addr,
|
||||
LLADDR(SDL(gate)));
|
||||
SDL(gate)->sdl_alen = 6;
|
||||
rt->rt_expire = 0;
|
||||
}
|
||||
if (in_broadcast(SIN(rt_key(rt))->sin_addr, rt->rt_ifp)) {
|
||||
memcpy(LLADDR(SDL(gate)), etherbroadcastaddr, 6);
|
||||
SDL(gate)->sdl_alen = 6;
|
||||
memcpy(LLADDR(SDL(gate)), rt->rt_ifp->if_broadcastaddr,
|
||||
rt->rt_ifp->if_addrlen);
|
||||
SDL(gate)->sdl_alen = rt->rt_ifp->if_addrlen;
|
||||
rt->rt_expire = 0;
|
||||
}
|
||||
#endif
|
||||
@ -259,8 +262,8 @@ arp_rtrequest(req, rt, sa)
|
||||
* the route to force traffic out to the hardware.
|
||||
*/
|
||||
rt->rt_expire = 0;
|
||||
Bcopy(((struct arpcom *)rt->rt_ifp)->ac_enaddr,
|
||||
LLADDR(SDL(gate)), SDL(gate)->sdl_alen = 6);
|
||||
Bcopy(IF_LLADDR(rt->rt_ifp), LLADDR(SDL(gate)),
|
||||
SDL(gate)->sdl_alen = rt->rt_ifp->if_addrlen);
|
||||
if (useloopback)
|
||||
rt->rt_ifp = loif;
|
||||
|
||||
@ -287,35 +290,54 @@ arp_rtrequest(req, rt, sa)
|
||||
* - arp header source ethernet address
|
||||
*/
|
||||
static void
|
||||
arprequest(ac, sip, tip, enaddr)
|
||||
register struct arpcom *ac;
|
||||
arprequest(ifp, sip, tip, enaddr)
|
||||
register struct ifnet *ifp;
|
||||
register struct in_addr *sip, *tip;
|
||||
register u_char *enaddr;
|
||||
{
|
||||
register struct mbuf *m;
|
||||
register struct ether_header *eh;
|
||||
register struct ether_arp *ea;
|
||||
register struct arc_header *arh;
|
||||
register struct arphdr *ah;
|
||||
struct sockaddr sa;
|
||||
static u_char llcx[] = { 0x82, 0x40, LLC_SNAP_LSAP, LLC_SNAP_LSAP,
|
||||
LLC_UI, 0x00, 0x00, 0x00, 0x08, 0x06 };
|
||||
u_short ar_hrd;
|
||||
|
||||
if ((m = m_gethdr(M_DONTWAIT, MT_DATA)) == NULL)
|
||||
return;
|
||||
m->m_pkthdr.rcvif = (struct ifnet *)0;
|
||||
switch (ac->ac_if.if_type) {
|
||||
switch (ifp->if_type) {
|
||||
case IFT_ARCNET:
|
||||
ar_hrd = htons(ARPHRD_ARCNET);
|
||||
|
||||
m->m_len = arphdr_len2(ifp->if_addrlen, sizeof(struct in_addr));
|
||||
m->m_pkthdr.len = m->m_len;
|
||||
MH_ALIGN(m, m->m_len);
|
||||
|
||||
arh = (struct arc_header *)sa.sa_data;
|
||||
arh->arc_dhost = *ifp->if_broadcastaddr;
|
||||
arh->arc_type = ARCTYPE_ARP;
|
||||
|
||||
ah = mtod(m, struct arphdr *);
|
||||
break;
|
||||
|
||||
case IFT_ISO88025:
|
||||
m->m_len = sizeof(*ea) + sizeof(llcx);
|
||||
m->m_pkthdr.len = sizeof(*ea) + sizeof(llcx);
|
||||
MH_ALIGN(m, sizeof(*ea) + sizeof(llcx));
|
||||
ar_hrd = htons(ARPHRD_IEEE802);
|
||||
|
||||
m->m_len = sizeof(llcx) +
|
||||
arphdr_len2(ifp->if_addrlen, sizeof(struct in_addr));
|
||||
m->m_pkthdr.len = m->m_len;
|
||||
MH_ALIGN(m, m->m_len);
|
||||
|
||||
(void)memcpy(mtod(m, caddr_t), llcx, sizeof(llcx));
|
||||
(void)memcpy(sa.sa_data, etherbroadcastaddr, 6);
|
||||
(void)memcpy(sa.sa_data, ifp->if_broadcastaddr, 6);
|
||||
(void)memcpy(sa.sa_data + 6, enaddr, 6);
|
||||
sa.sa_data[6] |= TR_RII;
|
||||
sa.sa_data[12] = TR_AC;
|
||||
sa.sa_data[13] = TR_LLC_FRAME;
|
||||
ea = (struct ether_arp *)(mtod(m, char *) + sizeof(llcx));
|
||||
bzero((caddr_t)ea, sizeof (*ea));
|
||||
ea->arp_hrd = htons(ARPHRD_IEEE802);
|
||||
|
||||
ah = (struct arphdr *)(mtod(m, char *) + sizeof(llcx));
|
||||
break;
|
||||
case IFT_FDDI:
|
||||
case IFT_ETHER:
|
||||
@ -324,29 +346,34 @@ arprequest(ac, sip, tip, enaddr)
|
||||
* listed, but this is our best guess
|
||||
*/
|
||||
default:
|
||||
m->m_len = sizeof(*ea);
|
||||
m->m_pkthdr.len = sizeof(*ea);
|
||||
MH_ALIGN(m, sizeof(*ea));
|
||||
ea = mtod(m, struct ether_arp *);
|
||||
ar_hrd = htons(ARPHRD_ETHER);
|
||||
|
||||
m->m_len = arphdr_len2(ifp->if_addrlen, sizeof(struct in_addr));
|
||||
m->m_pkthdr.len = m->m_len;
|
||||
MH_ALIGN(m, m->m_len);
|
||||
|
||||
eh = (struct ether_header *)sa.sa_data;
|
||||
bzero((caddr_t)ea, sizeof (*ea));
|
||||
/* if_output will not swap */
|
||||
eh->ether_type = htons(ETHERTYPE_ARP);
|
||||
(void)memcpy(eh->ether_dhost, etherbroadcastaddr,
|
||||
(void)memcpy(eh->ether_dhost, ifp->if_broadcastaddr,
|
||||
sizeof(eh->ether_dhost));
|
||||
ea->arp_hrd = htons(ARPHRD_ETHER);
|
||||
|
||||
ah = mtod(m, struct arphdr *);
|
||||
break;
|
||||
}
|
||||
ea->arp_pro = htons(ETHERTYPE_IP);
|
||||
ea->arp_hln = sizeof(ea->arp_sha); /* hardware address length */
|
||||
ea->arp_pln = sizeof(ea->arp_spa); /* protocol address length */
|
||||
ea->arp_op = htons(ARPOP_REQUEST);
|
||||
(void)memcpy(ea->arp_sha, enaddr, sizeof(ea->arp_sha));
|
||||
(void)memcpy(ea->arp_spa, sip, sizeof(ea->arp_spa));
|
||||
(void)memcpy(ea->arp_tpa, tip, sizeof(ea->arp_tpa));
|
||||
|
||||
ah->ar_hrd = ar_hrd;
|
||||
ah->ar_pro = htons(ETHERTYPE_IP);
|
||||
ah->ar_hln = ifp->if_addrlen; /* hardware address length */
|
||||
ah->ar_pln = sizeof(struct in_addr); /* protocol address length */
|
||||
ah->ar_op = htons(ARPOP_REQUEST);
|
||||
(void)memcpy(ar_sha(ah), enaddr, ah->ar_hln);
|
||||
(void)memcpy(ar_spa(ah), sip, ah->ar_pln);
|
||||
(void)memcpy(ar_tpa(ah), tip, ah->ar_pln);
|
||||
|
||||
sa.sa_family = AF_UNSPEC;
|
||||
sa.sa_len = sizeof(sa);
|
||||
(*ac->ac_if.if_output)(&ac->ac_if, m, &sa, (struct rtentry *)0);
|
||||
(*ifp->if_output)(ifp, m, &sa, (struct rtentry *)0);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -360,8 +387,8 @@ arprequest(ac, sip, tip, enaddr)
|
||||
* taken over here, either now or for later transmission.
|
||||
*/
|
||||
int
|
||||
arpresolve(ac, rt, m, dst, desten, rt0)
|
||||
register struct arpcom *ac;
|
||||
arpresolve(ifp, rt, m, dst, desten, rt0)
|
||||
register struct ifnet *ifp;
|
||||
register struct rtentry *rt;
|
||||
struct mbuf *m;
|
||||
register struct sockaddr *dst;
|
||||
@ -372,10 +399,10 @@ arpresolve(ac, rt, m, dst, desten, rt0)
|
||||
struct sockaddr_dl *sdl;
|
||||
|
||||
if (m->m_flags & M_BCAST) { /* broadcast */
|
||||
(void)memcpy(desten, etherbroadcastaddr, sizeof(etherbroadcastaddr));
|
||||
(void)memcpy(desten, ifp->if_broadcastaddr, ifp->if_addrlen);
|
||||
return (1);
|
||||
}
|
||||
if (m->m_flags & M_MCAST) { /* multicast */
|
||||
if (m->m_flags & M_MCAST && ifp->if_type != IFT_ARCNET) {/* multicast */
|
||||
ETHER_MAP_IP_MULTICAST(&SIN(dst)->sin_addr, desten);
|
||||
return(1);
|
||||
}
|
||||
@ -409,7 +436,7 @@ arpresolve(ac, rt, m, dst, desten, rt0)
|
||||
* Probably should not allocate empty llinfo struct if we are
|
||||
* not going to be sending out an arp request.
|
||||
*/
|
||||
if (ac->ac_if.if_flags & IFF_NOARP)
|
||||
if (ifp->if_flags & IFF_NOARP)
|
||||
return (0);
|
||||
/*
|
||||
* There is an arptab entry, but no ethernet address
|
||||
@ -424,9 +451,10 @@ arpresolve(ac, rt, m, dst, desten, rt0)
|
||||
if (la->la_asked == 0 || rt->rt_expire != time_second) {
|
||||
rt->rt_expire = time_second;
|
||||
if (la->la_asked++ < arp_maxtries)
|
||||
arprequest(ac,
|
||||
arprequest(ifp,
|
||||
&SIN(rt->rt_ifa->ifa_addr)->sin_addr,
|
||||
&SIN(dst)->sin_addr, ac->ac_enaddr);
|
||||
&SIN(dst)->sin_addr,
|
||||
IF_LLADDR(ifp));
|
||||
else {
|
||||
rt->rt_flags |= RTF_REJECT;
|
||||
rt->rt_expire += arpt_down;
|
||||
@ -464,7 +492,8 @@ arpintr()
|
||||
ar = mtod(m, struct arphdr *);
|
||||
|
||||
if (ntohs(ar->ar_hrd) != ARPHRD_ETHER
|
||||
&& ntohs(ar->ar_hrd) != ARPHRD_IEEE802) {
|
||||
&& ntohs(ar->ar_hrd) != ARPHRD_IEEE802
|
||||
&& ntohs(ar->ar_hrd) != ARPHRD_ARCNET) {
|
||||
log(LOG_ERR,
|
||||
"arp: unknown hardware address format (0x%2D)\n",
|
||||
(unsigned char *)&ar->ar_hrd, "");
|
||||
@ -472,8 +501,8 @@ arpintr()
|
||||
continue;
|
||||
}
|
||||
|
||||
if (m->m_pkthdr.len < sizeof(struct arphdr) + 2 * ar->ar_hln
|
||||
+ 2 * ar->ar_pln) {
|
||||
if (m->m_pkthdr.len < arphdr_len(ar) &&
|
||||
(m = m_pullup(m, arphdr_len(ar))) == NULL) {
|
||||
log(LOG_ERR, "arp: runt packet\n");
|
||||
m_freem(m);
|
||||
continue;
|
||||
@ -520,9 +549,10 @@ static void
|
||||
in_arpinput(m)
|
||||
struct mbuf *m;
|
||||
{
|
||||
register struct ether_arp *ea;
|
||||
register struct arpcom *ac = (struct arpcom *)m->m_pkthdr.rcvif;
|
||||
register struct arphdr *ah;
|
||||
register struct ifnet *ifp = m->m_pkthdr.rcvif;
|
||||
struct ether_header *eh;
|
||||
struct arc_header *arh;
|
||||
struct iso88025_header *th = (struct iso88025_header *)0;
|
||||
register struct llinfo_arp *la = 0;
|
||||
register struct rtentry *rt;
|
||||
@ -532,17 +562,18 @@ in_arpinput(m)
|
||||
struct sockaddr sa;
|
||||
struct in_addr isaddr, itaddr, myaddr;
|
||||
int op, rif_len;
|
||||
int req_len;
|
||||
|
||||
if (m->m_len < sizeof(struct ether_arp) &&
|
||||
(m = m_pullup(m, sizeof(struct ether_arp))) == NULL) {
|
||||
req_len = arphdr_len2(ifp->if_addrlen, sizeof(struct in_addr));
|
||||
if (m->m_len < req_len && (m = m_pullup(m, req_len)) == NULL) {
|
||||
log(LOG_ERR, "in_arp: runt packet -- m_pullup failed\n");
|
||||
return;
|
||||
}
|
||||
|
||||
ea = mtod(m, struct ether_arp *);
|
||||
op = ntohs(ea->arp_op);
|
||||
(void)memcpy(&isaddr, ea->arp_spa, sizeof (isaddr));
|
||||
(void)memcpy(&itaddr, ea->arp_tpa, sizeof (itaddr));
|
||||
ah = mtod(m, struct arphdr *);
|
||||
op = ntohs(ah->ar_op);
|
||||
(void)memcpy(&isaddr, ar_spa(ah), sizeof (isaddr));
|
||||
(void)memcpy(&itaddr, ar_tpa(ah), sizeof (itaddr));
|
||||
#ifdef BRIDGE
|
||||
#define BRIDGE_TEST (do_bridge)
|
||||
#else
|
||||
@ -554,18 +585,18 @@ in_arpinput(m)
|
||||
* when we have clusters of interfaces).
|
||||
*/
|
||||
LIST_FOREACH(ia, INADDR_HASH(itaddr.s_addr), ia_hash)
|
||||
if ((BRIDGE_TEST || (ia->ia_ifp == &ac->ac_if)) &&
|
||||
if ((BRIDGE_TEST || (ia->ia_ifp == ifp)) &&
|
||||
itaddr.s_addr == ia->ia_addr.sin_addr.s_addr)
|
||||
goto match;
|
||||
LIST_FOREACH(ia, INADDR_HASH(isaddr.s_addr), ia_hash)
|
||||
if ((BRIDGE_TEST || (ia->ia_ifp == &ac->ac_if)) &&
|
||||
if ((BRIDGE_TEST || (ia->ia_ifp == ifp)) &&
|
||||
isaddr.s_addr == ia->ia_addr.sin_addr.s_addr)
|
||||
goto match;
|
||||
/*
|
||||
* No match, use the first address on the receive interface
|
||||
* as a dummy address for the rest of the function.
|
||||
*/
|
||||
ifa = TAILQ_FIRST(&ac->ac_if.if_addrhead);
|
||||
ifa = TAILQ_FIRST(&ifp->if_addrhead);
|
||||
if (ifa == NULL) {
|
||||
m_freem(m);
|
||||
return;
|
||||
@ -573,63 +604,82 @@ in_arpinput(m)
|
||||
ia = ifatoia(ifa);
|
||||
match:
|
||||
myaddr = ia->ia_addr.sin_addr;
|
||||
if (!bcmp((caddr_t)ea->arp_sha, (caddr_t)ac->ac_enaddr,
|
||||
sizeof (ea->arp_sha))) {
|
||||
if (!bcmp(ar_sha(ah), IF_LLADDR(ifp), ifp->if_addrlen)) {
|
||||
m_freem(m); /* it's from me, ignore it. */
|
||||
return;
|
||||
}
|
||||
if (!bcmp((caddr_t)ea->arp_sha, (caddr_t)etherbroadcastaddr,
|
||||
sizeof (ea->arp_sha))) {
|
||||
if (!bcmp(ar_sha(ah), ifp->if_broadcastaddr, ifp->if_addrlen)) {
|
||||
log(LOG_ERR,
|
||||
"arp: ether address is broadcast for IP address %s!\n",
|
||||
"arp: link address is broadcast for IP address %s!\n",
|
||||
inet_ntoa(isaddr));
|
||||
m_freem(m);
|
||||
return;
|
||||
}
|
||||
if (isaddr.s_addr == myaddr.s_addr) {
|
||||
log(LOG_ERR,
|
||||
"arp: %6D is using my IP address %s!\n",
|
||||
ea->arp_sha, ":", inet_ntoa(isaddr));
|
||||
"arp: %*D is using my IP address %s!\n",
|
||||
ifp->if_addrlen, (u_char *)ar_sha(ah), ":",
|
||||
inet_ntoa(isaddr));
|
||||
itaddr = myaddr;
|
||||
goto reply;
|
||||
}
|
||||
la = arplookup(isaddr.s_addr, itaddr.s_addr == myaddr.s_addr, 0);
|
||||
if (la && (rt = la->la_rt) && (sdl = SDL(rt->rt_gateway))) {
|
||||
/* the following is not an error when doing bridging */
|
||||
if (!BRIDGE_TEST && rt->rt_ifp != &ac->ac_if) {
|
||||
if (!BRIDGE_TEST && rt->rt_ifp != ifp) {
|
||||
if (log_arp_wrong_iface)
|
||||
log(LOG_ERR, "arp: %s is on %s%d but got reply from %6D on %s%d\n",
|
||||
log(LOG_ERR, "arp: %s is on %s%d but got reply from %*D on %s%d\n",
|
||||
inet_ntoa(isaddr),
|
||||
rt->rt_ifp->if_name, rt->rt_ifp->if_unit,
|
||||
ea->arp_sha, ":",
|
||||
ac->ac_if.if_name, ac->ac_if.if_unit);
|
||||
ifp->if_addrlen, (u_char *)ar_sha(ah), ":",
|
||||
ifp->if_name, ifp->if_unit);
|
||||
goto reply;
|
||||
}
|
||||
if (sdl->sdl_alen &&
|
||||
bcmp((caddr_t)ea->arp_sha, LLADDR(sdl), sdl->sdl_alen)) {
|
||||
bcmp(ar_sha(ah), LLADDR(sdl), sdl->sdl_alen)) {
|
||||
if (rt->rt_expire) {
|
||||
if (log_arp_movements)
|
||||
log(LOG_INFO, "arp: %s moved from %6D to %6D on %s%d\n",
|
||||
inet_ntoa(isaddr), (u_char *)LLADDR(sdl), ":",
|
||||
ea->arp_sha, ":",
|
||||
ac->ac_if.if_name, ac->ac_if.if_unit);
|
||||
log(LOG_INFO, "arp: %s moved from %*D to %*D on %s%d\n",
|
||||
inet_ntoa(isaddr),
|
||||
ifp->if_addrlen, (u_char *)LLADDR(sdl), ":",
|
||||
ifp->if_addrlen, (u_char *)ar_sha(ah), ":",
|
||||
ifp->if_name, ifp->if_unit);
|
||||
} else {
|
||||
log(LOG_ERR,
|
||||
"arp: %6D attempts to modify permanent entry for %s on %s%d\n",
|
||||
ea->arp_sha, ":", inet_ntoa(isaddr),
|
||||
ac->ac_if.if_name, ac->ac_if.if_unit);
|
||||
"arp: %*D attempts to modify permanent entry for %s on %s%d\n",
|
||||
ifp->if_addrlen, (u_char *)ar_sha(ah), ":",
|
||||
inet_ntoa(isaddr), ifp->if_name, ifp->if_unit);
|
||||
goto reply;
|
||||
}
|
||||
}
|
||||
(void)memcpy(LLADDR(sdl), ea->arp_sha, sizeof(ea->arp_sha));
|
||||
sdl->sdl_alen = sizeof(ea->arp_sha);
|
||||
/*
|
||||
* sanity check for the address length.
|
||||
* XXX this does not work for protocols with variable address
|
||||
* length. -is
|
||||
*/
|
||||
if (sdl->sdl_alen &&
|
||||
sdl->sdl_alen != ah->ar_hln) {
|
||||
log(LOG_WARNING,
|
||||
"arp from %*D: new addr len %d, was %d",
|
||||
ifp->if_addrlen, (u_char *) ar_sha(ah), ":",
|
||||
ah->ar_hln, sdl->sdl_alen);
|
||||
}
|
||||
if (ifp->if_addrlen != ah->ar_hln) {
|
||||
log(LOG_WARNING,
|
||||
"arp from %*D: addr len: new %d, i/f %d (ignored)",
|
||||
ifp->if_addrlen, (u_char *) ar_sha(ah), ":",
|
||||
ah->ar_hln, ifp->if_addrlen);
|
||||
goto reply;
|
||||
}
|
||||
(void)memcpy(LLADDR(sdl), ar_sha(ah),
|
||||
sdl->sdl_alen = ah->ar_hln);
|
||||
sdl->sdl_rcf = (u_short)0;
|
||||
/*
|
||||
* If we receive an arp from a token-ring station over
|
||||
* a token-ring nic then try to save the source
|
||||
* routing info.
|
||||
*/
|
||||
if (ac->ac_if.if_type == IFT_ISO88025) {
|
||||
if (ifp->if_type == IFT_ISO88025) {
|
||||
th = (struct iso88025_header *)m->m_pkthdr.header;
|
||||
rif_len = TR_RCF_RIFLEN(th->rcf);
|
||||
if ((th->iso88025_shost[0] & TR_RII) &&
|
||||
@ -660,7 +710,7 @@ match:
|
||||
rt->rt_flags &= ~RTF_REJECT;
|
||||
la->la_asked = 0;
|
||||
if (la->la_hold) {
|
||||
(*ac->ac_if.if_output)(&ac->ac_if, la->la_hold,
|
||||
(*ifp->if_output)(ifp, la->la_hold,
|
||||
rt_key(rt), rt);
|
||||
la->la_hold = 0;
|
||||
}
|
||||
@ -672,8 +722,8 @@ reply:
|
||||
}
|
||||
if (itaddr.s_addr == myaddr.s_addr) {
|
||||
/* I am the target */
|
||||
(void)memcpy(ea->arp_tha, ea->arp_sha, sizeof(ea->arp_sha));
|
||||
(void)memcpy(ea->arp_sha, ac->ac_enaddr, sizeof(ea->arp_sha));
|
||||
(void)memcpy(ar_tha(ah), ar_sha(ah), ah->ar_hln);
|
||||
(void)memcpy(ar_sha(ah), IF_LLADDR(ifp), ah->ar_hln);
|
||||
} else {
|
||||
la = arplookup(itaddr.s_addr, 0, SIN_PROXY);
|
||||
if (la == NULL) {
|
||||
@ -699,13 +749,13 @@ reply:
|
||||
* as this one came out of, or we'll get into a fight
|
||||
* over who claims what Ether address.
|
||||
*/
|
||||
if (rt->rt_ifp == &ac->ac_if) {
|
||||
if (rt->rt_ifp == ifp) {
|
||||
rtfree(rt);
|
||||
m_freem(m);
|
||||
return;
|
||||
}
|
||||
(void)memcpy(ea->arp_tha, ea->arp_sha, sizeof(ea->arp_sha));
|
||||
(void)memcpy(ea->arp_sha, ac->ac_enaddr, sizeof(ea->arp_sha));
|
||||
(void)memcpy(ar_tha(ah), ar_sha(ah), ah->ar_hln);
|
||||
(void)memcpy(ar_sha(ah), IF_LLADDR(ifp), ah->ar_hln);
|
||||
rtfree(rt);
|
||||
|
||||
/*
|
||||
@ -721,11 +771,11 @@ reply:
|
||||
m_freem(m);
|
||||
return;
|
||||
}
|
||||
if (rt->rt_ifp != &ac->ac_if) {
|
||||
if (rt->rt_ifp != ifp) {
|
||||
log(LOG_INFO, "arp_proxy: ignoring request"
|
||||
" from %s via %s%d, expecting %s%d\n",
|
||||
inet_ntoa(isaddr), ac->ac_if.if_name,
|
||||
ac->ac_if.if_unit, rt->rt_ifp->if_name,
|
||||
inet_ntoa(isaddr), ifp->if_name,
|
||||
ifp->if_unit, rt->rt_ifp->if_name,
|
||||
rt->rt_ifp->if_unit);
|
||||
rtfree(rt);
|
||||
m_freem(m);
|
||||
@ -739,22 +789,28 @@ reply:
|
||||
#endif
|
||||
} else {
|
||||
rt = la->la_rt;
|
||||
(void)memcpy(ea->arp_tha, ea->arp_sha, sizeof(ea->arp_sha));
|
||||
(void)memcpy(ar_tha(ah), ar_sha(ah), ah->ar_hln);
|
||||
sdl = SDL(rt->rt_gateway);
|
||||
(void)memcpy(ea->arp_sha, LLADDR(sdl), sizeof(ea->arp_sha));
|
||||
(void)memcpy(ar_sha(ah), LLADDR(sdl), ah->ar_hln);
|
||||
}
|
||||
}
|
||||
|
||||
(void)memcpy(ea->arp_tpa, ea->arp_spa, sizeof(ea->arp_spa));
|
||||
(void)memcpy(ea->arp_spa, &itaddr, sizeof(ea->arp_spa));
|
||||
ea->arp_op = htons(ARPOP_REPLY);
|
||||
ea->arp_pro = htons(ETHERTYPE_IP); /* let's be sure! */
|
||||
switch (ac->ac_if.if_type) {
|
||||
(void)memcpy(ar_tpa(ah), ar_spa(ah), ah->ar_pln);
|
||||
(void)memcpy(ar_spa(ah), &itaddr, ah->ar_pln);
|
||||
ah->ar_op = htons(ARPOP_REPLY);
|
||||
ah->ar_pro = htons(ETHERTYPE_IP); /* let's be sure! */
|
||||
switch (ifp->if_type) {
|
||||
case IFT_ARCNET:
|
||||
arh = (struct arc_header *)sa.sa_data;
|
||||
arh->arc_dhost = *ar_tha(ah);
|
||||
arh->arc_type = ARCTYPE_ARP;
|
||||
break;
|
||||
|
||||
case IFT_ISO88025:
|
||||
/* Re-arrange the source/dest address */
|
||||
memcpy(th->iso88025_dhost, th->iso88025_shost,
|
||||
sizeof(th->iso88025_dhost));
|
||||
memcpy(th->iso88025_shost, ac->ac_enaddr,
|
||||
memcpy(th->iso88025_shost, IF_LLADDR(ifp),
|
||||
sizeof(th->iso88025_shost));
|
||||
/* Set the source routing bit if neccesary */
|
||||
if (th->iso88025_dhost[0] & TR_RII) {
|
||||
@ -776,14 +832,14 @@ reply:
|
||||
*/
|
||||
default:
|
||||
eh = (struct ether_header *)sa.sa_data;
|
||||
(void)memcpy(eh->ether_dhost, ea->arp_tha,
|
||||
(void)memcpy(eh->ether_dhost, ar_tha(ah),
|
||||
sizeof(eh->ether_dhost));
|
||||
eh->ether_type = htons(ETHERTYPE_ARP);
|
||||
break;
|
||||
}
|
||||
sa.sa_family = AF_UNSPEC;
|
||||
sa.sa_len = sizeof(sa);
|
||||
(*ac->ac_if.if_output)(&ac->ac_if, m, &sa, (struct rtentry *)0);
|
||||
(*ifp->if_output)(ifp, m, &sa, (struct rtentry *)0);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
@ -846,13 +902,13 @@ arplookup(addr, create, proxy)
|
||||
}
|
||||
|
||||
void
|
||||
arp_ifinit(ac, ifa)
|
||||
struct arpcom *ac;
|
||||
arp_ifinit(ifp, ifa)
|
||||
struct ifnet *ifp;
|
||||
struct ifaddr *ifa;
|
||||
{
|
||||
if (ntohl(IA_SIN(ifa)->sin_addr.s_addr) != INADDR_ANY)
|
||||
arprequest(ac, &IA_SIN(ifa)->sin_addr,
|
||||
&IA_SIN(ifa)->sin_addr, ac->ac_enaddr);
|
||||
arprequest(ifp, &IA_SIN(ifa)->sin_addr,
|
||||
&IA_SIN(ifa)->sin_addr, IF_LLADDR(ifp));
|
||||
ifa->ifa_rtrequest = arp_rtrequest;
|
||||
ifa->ifa_flags |= RTF_CLONING;
|
||||
}
|
||||
|
@ -114,9 +114,9 @@ extern u_char ether_ipmulticast_min[ETHER_ADDR_LEN];
|
||||
extern u_char ether_ipmulticast_max[ETHER_ADDR_LEN];
|
||||
extern struct ifqueue arpintrq;
|
||||
|
||||
int arpresolve __P((struct arpcom *, struct rtentry *, struct mbuf *,
|
||||
int arpresolve __P((struct ifnet *, struct rtentry *, struct mbuf *,
|
||||
struct sockaddr *, u_char *, struct rtentry *));
|
||||
void arp_ifinit __P((struct arpcom *, struct ifaddr *));
|
||||
void arp_ifinit __P((struct ifnet *, struct ifaddr *));
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user