xref: /freebsd/sys/netinet/if_ether.h (revision 26a8b0bf7e0b0c3ed382481b849b7d1d873d460a)
1df8bae1dSRodney W. Grimes /*
2df8bae1dSRodney W. Grimes  * Copyright (c) 1982, 1986, 1993
3df8bae1dSRodney W. Grimes  *	The Regents of the University of California.  All rights reserved.
4df8bae1dSRodney W. Grimes  *
5df8bae1dSRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
6df8bae1dSRodney W. Grimes  * modification, are permitted provided that the following conditions
7df8bae1dSRodney W. Grimes  * are met:
8df8bae1dSRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
9df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
10df8bae1dSRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
11df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
12df8bae1dSRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
13df8bae1dSRodney W. Grimes  * 3. All advertising materials mentioning features or use of this software
14df8bae1dSRodney W. Grimes  *    must display the following acknowledgement:
15df8bae1dSRodney W. Grimes  *	This product includes software developed by the University of
16df8bae1dSRodney W. Grimes  *	California, Berkeley and its contributors.
17df8bae1dSRodney W. Grimes  * 4. Neither the name of the University nor the names of its contributors
18df8bae1dSRodney W. Grimes  *    may be used to endorse or promote products derived from this software
19df8bae1dSRodney W. Grimes  *    without specific prior written permission.
20df8bae1dSRodney W. Grimes  *
21df8bae1dSRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22df8bae1dSRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23df8bae1dSRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24df8bae1dSRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25df8bae1dSRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26df8bae1dSRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27df8bae1dSRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28df8bae1dSRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29df8bae1dSRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30df8bae1dSRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31df8bae1dSRodney W. Grimes  * SUCH DAMAGE.
32df8bae1dSRodney W. Grimes  *
33ef91e528SGarrett Wollman  *	@(#)if_ether.h	8.3 (Berkeley) 5/2/95
3426a8b0bfSPoul-Henning Kamp  *	$Id: if_ether.h,v 1.14 1996/03/23 01:32:30 fenner Exp $
35df8bae1dSRodney W. Grimes  */
36df8bae1dSRodney W. Grimes 
37707f139eSPaul Richards #ifndef _NETINET_IF_ETHER_H_
38707f139eSPaul Richards #define _NETINET_IF_ETHER_H_
39707f139eSPaul Richards 
4026a8b0bfSPoul-Henning Kamp #include <net/ethernet.h>
415f6d32c7SBill Paul 
42df8bae1dSRodney W. Grimes #define	ETHERTYPE_PUP		0x0200	/* PUP protocol */
43df8bae1dSRodney W. Grimes #define	ETHERTYPE_IP		0x0800	/* IP protocol */
44df8bae1dSRodney W. Grimes #define ETHERTYPE_ARP		0x0806	/* Addr. resolution protocol */
45df8bae1dSRodney W. Grimes #define ETHERTYPE_REVARP	0x8035	/* reverse Addr. resolution protocol */
46df8bae1dSRodney W. Grimes 
47df8bae1dSRodney W. Grimes /*
48df8bae1dSRodney W. Grimes  * The ETHERTYPE_NTRAILER packet types starting at ETHERTYPE_TRAIL have
49df8bae1dSRodney W. Grimes  * (type-ETHERTYPE_TRAIL)*512 bytes of data followed
50df8bae1dSRodney W. Grimes  * by an ETHER type (as given above) and then the (variable-length) header.
51df8bae1dSRodney W. Grimes  */
52df8bae1dSRodney W. Grimes #define	ETHERTYPE_TRAIL		0x1000		/* Trailer packet */
53df8bae1dSRodney W. Grimes #define	ETHERTYPE_NTRAILER	16
54df8bae1dSRodney W. Grimes 
5526a8b0bfSPoul-Henning Kamp #define	ETHERMTU	(ETHER_MAX_LEN-ETHER_HDR_LEN-ETHER_CRC_LEN)
5626a8b0bfSPoul-Henning Kamp #define	ETHERMIN	(ETHER_MIN_LEN-ETHER_HDR_LEN-ETHER_CRC_LEN)
57df8bae1dSRodney W. Grimes 
58df8bae1dSRodney W. Grimes #ifdef KERNEL
59df8bae1dSRodney W. Grimes /*
60df8bae1dSRodney W. Grimes  * Macro to map an IP multicast address to an Ethernet multicast address.
61df8bae1dSRodney W. Grimes  * The high-order 25 bits of the Ethernet address are statically assigned,
62df8bae1dSRodney W. Grimes  * and the low-order 23 bits are taken from the low end of the IP address.
63df8bae1dSRodney W. Grimes  */
64df8bae1dSRodney W. Grimes #define ETHER_MAP_IP_MULTICAST(ipaddr, enaddr) \
65df8bae1dSRodney W. Grimes 	/* struct in_addr *ipaddr; */ \
6626a8b0bfSPoul-Henning Kamp 	/* u_char enaddr[ETHER_ADDR_LEN];	   */ \
67df8bae1dSRodney W. Grimes { \
68df8bae1dSRodney W. Grimes 	(enaddr)[0] = 0x01; \
69df8bae1dSRodney W. Grimes 	(enaddr)[1] = 0x00; \
70df8bae1dSRodney W. Grimes 	(enaddr)[2] = 0x5e; \
71df8bae1dSRodney W. Grimes 	(enaddr)[3] = ((u_char *)ipaddr)[1] & 0x7f; \
72df8bae1dSRodney W. Grimes 	(enaddr)[4] = ((u_char *)ipaddr)[2]; \
73df8bae1dSRodney W. Grimes 	(enaddr)[5] = ((u_char *)ipaddr)[3]; \
74df8bae1dSRodney W. Grimes }
75df8bae1dSRodney W. Grimes #endif
76df8bae1dSRodney W. Grimes 
77df8bae1dSRodney W. Grimes /*
78df8bae1dSRodney W. Grimes  * Ethernet Address Resolution Protocol.
79df8bae1dSRodney W. Grimes  *
80df8bae1dSRodney W. Grimes  * See RFC 826 for protocol description.  Structure below is adapted
81df8bae1dSRodney W. Grimes  * to resolving internet addresses.  Field names used correspond to
82df8bae1dSRodney W. Grimes  * RFC 826.
83df8bae1dSRodney W. Grimes  */
84df8bae1dSRodney W. Grimes struct	ether_arp {
85df8bae1dSRodney W. Grimes 	struct	arphdr ea_hdr;	/* fixed-size header */
8626a8b0bfSPoul-Henning Kamp 	u_char	arp_sha[ETHER_ADDR_LEN];	/* sender hardware address */
87df8bae1dSRodney W. Grimes 	u_char	arp_spa[4];	/* sender protocol address */
8826a8b0bfSPoul-Henning Kamp 	u_char	arp_tha[ETHER_ADDR_LEN];	/* target hardware address */
89df8bae1dSRodney W. Grimes 	u_char	arp_tpa[4];	/* target protocol address */
90df8bae1dSRodney W. Grimes };
91df8bae1dSRodney W. Grimes #define	arp_hrd	ea_hdr.ar_hrd
92df8bae1dSRodney W. Grimes #define	arp_pro	ea_hdr.ar_pro
93df8bae1dSRodney W. Grimes #define	arp_hln	ea_hdr.ar_hln
94df8bae1dSRodney W. Grimes #define	arp_pln	ea_hdr.ar_pln
95df8bae1dSRodney W. Grimes #define	arp_op	ea_hdr.ar_op
96df8bae1dSRodney W. Grimes 
97df8bae1dSRodney W. Grimes 
98df8bae1dSRodney W. Grimes /*
99df8bae1dSRodney W. Grimes  * Structure shared between the ethernet driver modules and
100df8bae1dSRodney W. Grimes  * the address resolution code.  For example, each ec_softc or il_softc
101df8bae1dSRodney W. Grimes  * begins with this structure.
102df8bae1dSRodney W. Grimes  */
103df8bae1dSRodney W. Grimes struct	arpcom {
1044a5f1499SDavid Greenman 	/*
1054a5f1499SDavid Greenman 	 * The ifnet struct _must_ be at the head of this structure.
1064a5f1499SDavid Greenman 	 */
107df8bae1dSRodney W. Grimes 	struct 	ifnet ac_if;		/* network-visible interface */
10826a8b0bfSPoul-Henning Kamp 	u_char	ac_enaddr[ETHER_ADDR_LEN];		/* ethernet hardware address */
109df8bae1dSRodney W. Grimes 	struct	ether_multi *ac_multiaddrs; /* list of ether multicast addrs */
110df8bae1dSRodney W. Grimes 	int	ac_multicnt;		/* length of ac_multiaddrs list */
111df8bae1dSRodney W. Grimes };
112df8bae1dSRodney W. Grimes 
113df8bae1dSRodney W. Grimes struct sockaddr_inarp {
114df8bae1dSRodney W. Grimes 	u_char	sin_len;
115df8bae1dSRodney W. Grimes 	u_char	sin_family;
116df8bae1dSRodney W. Grimes 	u_short sin_port;
117df8bae1dSRodney W. Grimes 	struct	in_addr sin_addr;
118df8bae1dSRodney W. Grimes 	struct	in_addr sin_srcaddr;
119df8bae1dSRodney W. Grimes 	u_short	sin_tos;
120df8bae1dSRodney W. Grimes 	u_short	sin_other;
121df8bae1dSRodney W. Grimes #define SIN_PROXY 1
122df8bae1dSRodney W. Grimes };
123df8bae1dSRodney W. Grimes /*
124df8bae1dSRodney W. Grimes  * IP and ethernet specific routing flags
125df8bae1dSRodney W. Grimes  */
126df8bae1dSRodney W. Grimes #define	RTF_USETRAILERS	RTF_PROTO1	/* use trailers */
127df8bae1dSRodney W. Grimes #define RTF_ANNOUNCE	RTF_PROTO2	/* announce new arp entry */
128df8bae1dSRodney W. Grimes 
129df8bae1dSRodney W. Grimes #ifdef	KERNEL
13026a8b0bfSPoul-Henning Kamp extern u_char	etherbroadcastaddr[ETHER_ADDR_LEN];
13126a8b0bfSPoul-Henning Kamp extern u_char	ether_ipmulticast_min[ETHER_ADDR_LEN];
13226a8b0bfSPoul-Henning Kamp extern u_char	ether_ipmulticast_max[ETHER_ADDR_LEN];
133f23b4c91SGarrett Wollman extern struct	ifqueue arpintrq;
134df8bae1dSRodney W. Grimes 
1355df72964SGarrett Wollman int	arpresolve __P((struct arpcom *, struct rtentry *, struct mbuf *,
1365df72964SGarrett Wollman 			struct sockaddr *, u_char *, struct rtentry *));
137dd2e4102SGarrett Wollman void	arp_ifinit __P((struct arpcom *, struct ifaddr *));
138df8bae1dSRodney W. Grimes int	ether_addmulti __P((struct ifreq *, struct arpcom *));
139df8bae1dSRodney W. Grimes int	ether_delmulti __P((struct ifreq *, struct arpcom *));
140df8bae1dSRodney W. Grimes 
141df8bae1dSRodney W. Grimes /*
142df8bae1dSRodney W. Grimes  * Ethernet multicast address structure.  There is one of these for each
143df8bae1dSRodney W. Grimes  * multicast address or range of multicast addresses that we are supposed
144df8bae1dSRodney W. Grimes  * to listen to on a particular interface.  They are kept in a linked list,
145df8bae1dSRodney W. Grimes  * rooted in the interface's arpcom structure.  (This really has nothing to
146df8bae1dSRodney W. Grimes  * do with ARP, or with the Internet address family, but this appears to be
147df8bae1dSRodney W. Grimes  * the minimally-disrupting place to put it.)
148df8bae1dSRodney W. Grimes  */
149df8bae1dSRodney W. Grimes struct ether_multi {
15026a8b0bfSPoul-Henning Kamp 	u_char	enm_addrlo[ETHER_ADDR_LEN];		/* low  or only address of range */
15126a8b0bfSPoul-Henning Kamp 	u_char	enm_addrhi[ETHER_ADDR_LEN];		/* high or only address of range */
152df8bae1dSRodney W. Grimes 	struct	arpcom *enm_ac;		/* back pointer to arpcom */
153df8bae1dSRodney W. Grimes 	u_int	enm_refcount;		/* no. claims to this addr/range */
154df8bae1dSRodney W. Grimes 	struct	ether_multi *enm_next;	/* ptr to next ether_multi */
155df8bae1dSRodney W. Grimes };
156df8bae1dSRodney W. Grimes 
157df8bae1dSRodney W. Grimes /*
158df8bae1dSRodney W. Grimes  * Structure used by macros below to remember position when stepping through
159df8bae1dSRodney W. Grimes  * all of the ether_multi records.
160df8bae1dSRodney W. Grimes  */
161df8bae1dSRodney W. Grimes struct ether_multistep {
162df8bae1dSRodney W. Grimes 	struct ether_multi  *e_enm;
163df8bae1dSRodney W. Grimes };
164df8bae1dSRodney W. Grimes 
165df8bae1dSRodney W. Grimes /*
166df8bae1dSRodney W. Grimes  * Macro for looking up the ether_multi record for a given range of Ethernet
167df8bae1dSRodney W. Grimes  * multicast addresses connected to a given arpcom structure.  If no matching
168df8bae1dSRodney W. Grimes  * record is found, "enm" returns NULL.
169df8bae1dSRodney W. Grimes  */
170df8bae1dSRodney W. Grimes #define ETHER_LOOKUP_MULTI(addrlo, addrhi, ac, enm) \
17126a8b0bfSPoul-Henning Kamp 	/* u_char addrlo[ETHER_ADDR_LEN]; */ \
17226a8b0bfSPoul-Henning Kamp 	/* u_char addrhi[ETHER_ADDR_LEN]; */ \
173df8bae1dSRodney W. Grimes 	/* struct arpcom *ac; */ \
174df8bae1dSRodney W. Grimes 	/* struct ether_multi *enm; */ \
175df8bae1dSRodney W. Grimes { \
176df8bae1dSRodney W. Grimes 	for ((enm) = (ac)->ac_multiaddrs; \
177df8bae1dSRodney W. Grimes 	    (enm) != NULL && \
17826a8b0bfSPoul-Henning Kamp 	    (bcmp((enm)->enm_addrlo, (addrlo), ETHER_ADDR_LEN) != 0 || \
17926a8b0bfSPoul-Henning Kamp 	     bcmp((enm)->enm_addrhi, (addrhi), ETHER_ADDR_LEN) != 0); \
180df8bae1dSRodney W. Grimes 		(enm) = (enm)->enm_next); \
181df8bae1dSRodney W. Grimes }
182df8bae1dSRodney W. Grimes 
183df8bae1dSRodney W. Grimes /*
184df8bae1dSRodney W. Grimes  * Macro to step through all of the ether_multi records, one at a time.
185df8bae1dSRodney W. Grimes  * The current position is remembered in "step", which the caller must
186df8bae1dSRodney W. Grimes  * provide.  ETHER_FIRST_MULTI(), below, must be called to initialize "step"
187df8bae1dSRodney W. Grimes  * and get the first record.  Both macros return a NULL "enm" when there
188df8bae1dSRodney W. Grimes  * are no remaining records.
189df8bae1dSRodney W. Grimes  */
190df8bae1dSRodney W. Grimes #define ETHER_NEXT_MULTI(step, enm) \
191df8bae1dSRodney W. Grimes 	/* struct ether_multistep step; */  \
192df8bae1dSRodney W. Grimes 	/* struct ether_multi *enm; */  \
193df8bae1dSRodney W. Grimes { \
194df8bae1dSRodney W. Grimes 	if (((enm) = (step).e_enm) != NULL) \
195df8bae1dSRodney W. Grimes 		(step).e_enm = (enm)->enm_next; \
196df8bae1dSRodney W. Grimes }
197df8bae1dSRodney W. Grimes 
198df8bae1dSRodney W. Grimes #define ETHER_FIRST_MULTI(step, ac, enm) \
199df8bae1dSRodney W. Grimes 	/* struct ether_multistep step; */ \
200df8bae1dSRodney W. Grimes 	/* struct arpcom *ac; */ \
201df8bae1dSRodney W. Grimes 	/* struct ether_multi *enm; */ \
202df8bae1dSRodney W. Grimes { \
203df8bae1dSRodney W. Grimes 	(step).e_enm = (ac)->ac_multiaddrs; \
204df8bae1dSRodney W. Grimes 	ETHER_NEXT_MULTI((step), (enm)); \
205df8bae1dSRodney W. Grimes }
206df8bae1dSRodney W. Grimes 
207df8bae1dSRodney W. Grimes #endif
208707f139eSPaul Richards 
209707f139eSPaul Richards #endif
210