xref: /freebsd/sys/netinet/if_ether.h (revision 4963f4cd96d2963c9a6845a6886aa6fcf8995903)
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
344963f4cdSGarrett Wollman  *	$Id: if_ether.h,v 1.15 1996/08/06 21:14:28 phk 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>
414963f4cdSGarrett Wollman #include <net/if_arp.h>
425f6d32c7SBill Paul 
43df8bae1dSRodney W. Grimes #define	ETHERTYPE_PUP		0x0200	/* PUP protocol */
44df8bae1dSRodney W. Grimes #define	ETHERTYPE_IP		0x0800	/* IP protocol */
45df8bae1dSRodney W. Grimes #define ETHERTYPE_ARP		0x0806	/* Addr. resolution protocol */
46df8bae1dSRodney W. Grimes #define ETHERTYPE_REVARP	0x8035	/* reverse Addr. resolution protocol */
47df8bae1dSRodney W. Grimes 
48df8bae1dSRodney W. Grimes /*
49df8bae1dSRodney W. Grimes  * The ETHERTYPE_NTRAILER packet types starting at ETHERTYPE_TRAIL have
50df8bae1dSRodney W. Grimes  * (type-ETHERTYPE_TRAIL)*512 bytes of data followed
51df8bae1dSRodney W. Grimes  * by an ETHER type (as given above) and then the (variable-length) header.
52df8bae1dSRodney W. Grimes  */
53df8bae1dSRodney W. Grimes #define	ETHERTYPE_TRAIL		0x1000		/* Trailer packet */
54df8bae1dSRodney W. Grimes #define	ETHERTYPE_NTRAILER	16
55df8bae1dSRodney W. Grimes 
5626a8b0bfSPoul-Henning Kamp #define	ETHERMTU	(ETHER_MAX_LEN-ETHER_HDR_LEN-ETHER_CRC_LEN)
5726a8b0bfSPoul-Henning Kamp #define	ETHERMIN	(ETHER_MIN_LEN-ETHER_HDR_LEN-ETHER_CRC_LEN)
58df8bae1dSRodney W. Grimes 
59df8bae1dSRodney W. Grimes #ifdef KERNEL
60df8bae1dSRodney W. Grimes /*
61df8bae1dSRodney W. Grimes  * Macro to map an IP multicast address to an Ethernet multicast address.
62df8bae1dSRodney W. Grimes  * The high-order 25 bits of the Ethernet address are statically assigned,
63df8bae1dSRodney W. Grimes  * and the low-order 23 bits are taken from the low end of the IP address.
64df8bae1dSRodney W. Grimes  */
65df8bae1dSRodney W. Grimes #define ETHER_MAP_IP_MULTICAST(ipaddr, enaddr) \
66df8bae1dSRodney W. Grimes 	/* struct in_addr *ipaddr; */ \
6726a8b0bfSPoul-Henning Kamp 	/* u_char enaddr[ETHER_ADDR_LEN];	   */ \
68df8bae1dSRodney W. Grimes { \
69df8bae1dSRodney W. Grimes 	(enaddr)[0] = 0x01; \
70df8bae1dSRodney W. Grimes 	(enaddr)[1] = 0x00; \
71df8bae1dSRodney W. Grimes 	(enaddr)[2] = 0x5e; \
72df8bae1dSRodney W. Grimes 	(enaddr)[3] = ((u_char *)ipaddr)[1] & 0x7f; \
73df8bae1dSRodney W. Grimes 	(enaddr)[4] = ((u_char *)ipaddr)[2]; \
74df8bae1dSRodney W. Grimes 	(enaddr)[5] = ((u_char *)ipaddr)[3]; \
75df8bae1dSRodney W. Grimes }
76df8bae1dSRodney W. Grimes #endif
77df8bae1dSRodney W. Grimes 
78df8bae1dSRodney W. Grimes /*
79df8bae1dSRodney W. Grimes  * Ethernet Address Resolution Protocol.
80df8bae1dSRodney W. Grimes  *
81df8bae1dSRodney W. Grimes  * See RFC 826 for protocol description.  Structure below is adapted
82df8bae1dSRodney W. Grimes  * to resolving internet addresses.  Field names used correspond to
83df8bae1dSRodney W. Grimes  * RFC 826.
84df8bae1dSRodney W. Grimes  */
85df8bae1dSRodney W. Grimes struct	ether_arp {
86df8bae1dSRodney W. Grimes 	struct	arphdr ea_hdr;	/* fixed-size header */
8726a8b0bfSPoul-Henning Kamp 	u_char	arp_sha[ETHER_ADDR_LEN];	/* sender hardware address */
88df8bae1dSRodney W. Grimes 	u_char	arp_spa[4];	/* sender protocol address */
8926a8b0bfSPoul-Henning Kamp 	u_char	arp_tha[ETHER_ADDR_LEN];	/* target hardware address */
90df8bae1dSRodney W. Grimes 	u_char	arp_tpa[4];	/* target protocol address */
91df8bae1dSRodney W. Grimes };
92df8bae1dSRodney W. Grimes #define	arp_hrd	ea_hdr.ar_hrd
93df8bae1dSRodney W. Grimes #define	arp_pro	ea_hdr.ar_pro
94df8bae1dSRodney W. Grimes #define	arp_hln	ea_hdr.ar_hln
95df8bae1dSRodney W. Grimes #define	arp_pln	ea_hdr.ar_pln
96df8bae1dSRodney W. Grimes #define	arp_op	ea_hdr.ar_op
97df8bae1dSRodney W. Grimes 
98df8bae1dSRodney W. Grimes 
99df8bae1dSRodney W. Grimes /*
100df8bae1dSRodney W. Grimes  * Structure shared between the ethernet driver modules and
101df8bae1dSRodney W. Grimes  * the address resolution code.  For example, each ec_softc or il_softc
102df8bae1dSRodney W. Grimes  * begins with this structure.
103df8bae1dSRodney W. Grimes  */
104df8bae1dSRodney W. Grimes struct	arpcom {
1054a5f1499SDavid Greenman 	/*
1064a5f1499SDavid Greenman 	 * The ifnet struct _must_ be at the head of this structure.
1074a5f1499SDavid Greenman 	 */
108df8bae1dSRodney W. Grimes 	struct 	ifnet ac_if;		/* network-visible interface */
10926a8b0bfSPoul-Henning Kamp 	u_char	ac_enaddr[ETHER_ADDR_LEN];		/* ethernet hardware address */
110df8bae1dSRodney W. Grimes 	struct	ether_multi *ac_multiaddrs; /* list of ether multicast addrs */
111df8bae1dSRodney W. Grimes 	int	ac_multicnt;		/* length of ac_multiaddrs list */
112df8bae1dSRodney W. Grimes };
113df8bae1dSRodney W. Grimes 
114df8bae1dSRodney W. Grimes struct sockaddr_inarp {
115df8bae1dSRodney W. Grimes 	u_char	sin_len;
116df8bae1dSRodney W. Grimes 	u_char	sin_family;
117df8bae1dSRodney W. Grimes 	u_short sin_port;
118df8bae1dSRodney W. Grimes 	struct	in_addr sin_addr;
119df8bae1dSRodney W. Grimes 	struct	in_addr sin_srcaddr;
120df8bae1dSRodney W. Grimes 	u_short	sin_tos;
121df8bae1dSRodney W. Grimes 	u_short	sin_other;
122df8bae1dSRodney W. Grimes #define SIN_PROXY 1
123df8bae1dSRodney W. Grimes };
124df8bae1dSRodney W. Grimes /*
125df8bae1dSRodney W. Grimes  * IP and ethernet specific routing flags
126df8bae1dSRodney W. Grimes  */
127df8bae1dSRodney W. Grimes #define	RTF_USETRAILERS	RTF_PROTO1	/* use trailers */
128df8bae1dSRodney W. Grimes #define RTF_ANNOUNCE	RTF_PROTO2	/* announce new arp entry */
129df8bae1dSRodney W. Grimes 
130df8bae1dSRodney W. Grimes #ifdef	KERNEL
13126a8b0bfSPoul-Henning Kamp extern u_char	etherbroadcastaddr[ETHER_ADDR_LEN];
13226a8b0bfSPoul-Henning Kamp extern u_char	ether_ipmulticast_min[ETHER_ADDR_LEN];
13326a8b0bfSPoul-Henning Kamp extern u_char	ether_ipmulticast_max[ETHER_ADDR_LEN];
134f23b4c91SGarrett Wollman extern struct	ifqueue arpintrq;
135df8bae1dSRodney W. Grimes 
1365df72964SGarrett Wollman int	arpresolve __P((struct arpcom *, struct rtentry *, struct mbuf *,
1375df72964SGarrett Wollman 			struct sockaddr *, u_char *, struct rtentry *));
138dd2e4102SGarrett Wollman void	arp_ifinit __P((struct arpcom *, struct ifaddr *));
139df8bae1dSRodney W. Grimes int	ether_addmulti __P((struct ifreq *, struct arpcom *));
140df8bae1dSRodney W. Grimes int	ether_delmulti __P((struct ifreq *, struct arpcom *));
141df8bae1dSRodney W. Grimes 
142df8bae1dSRodney W. Grimes /*
143df8bae1dSRodney W. Grimes  * Ethernet multicast address structure.  There is one of these for each
144df8bae1dSRodney W. Grimes  * multicast address or range of multicast addresses that we are supposed
145df8bae1dSRodney W. Grimes  * to listen to on a particular interface.  They are kept in a linked list,
146df8bae1dSRodney W. Grimes  * rooted in the interface's arpcom structure.  (This really has nothing to
147df8bae1dSRodney W. Grimes  * do with ARP, or with the Internet address family, but this appears to be
148df8bae1dSRodney W. Grimes  * the minimally-disrupting place to put it.)
149df8bae1dSRodney W. Grimes  */
150df8bae1dSRodney W. Grimes struct ether_multi {
15126a8b0bfSPoul-Henning Kamp 	u_char	enm_addrlo[ETHER_ADDR_LEN];		/* low  or only address of range */
15226a8b0bfSPoul-Henning Kamp 	u_char	enm_addrhi[ETHER_ADDR_LEN];		/* high or only address of range */
153df8bae1dSRodney W. Grimes 	struct	arpcom *enm_ac;		/* back pointer to arpcom */
154df8bae1dSRodney W. Grimes 	u_int	enm_refcount;		/* no. claims to this addr/range */
155df8bae1dSRodney W. Grimes 	struct	ether_multi *enm_next;	/* ptr to next ether_multi */
156df8bae1dSRodney W. Grimes };
157df8bae1dSRodney W. Grimes 
158df8bae1dSRodney W. Grimes /*
159df8bae1dSRodney W. Grimes  * Structure used by macros below to remember position when stepping through
160df8bae1dSRodney W. Grimes  * all of the ether_multi records.
161df8bae1dSRodney W. Grimes  */
162df8bae1dSRodney W. Grimes struct ether_multistep {
163df8bae1dSRodney W. Grimes 	struct ether_multi  *e_enm;
164df8bae1dSRodney W. Grimes };
165df8bae1dSRodney W. Grimes 
166df8bae1dSRodney W. Grimes /*
167df8bae1dSRodney W. Grimes  * Macro for looking up the ether_multi record for a given range of Ethernet
168df8bae1dSRodney W. Grimes  * multicast addresses connected to a given arpcom structure.  If no matching
169df8bae1dSRodney W. Grimes  * record is found, "enm" returns NULL.
170df8bae1dSRodney W. Grimes  */
171df8bae1dSRodney W. Grimes #define ETHER_LOOKUP_MULTI(addrlo, addrhi, ac, enm) \
17226a8b0bfSPoul-Henning Kamp 	/* u_char addrlo[ETHER_ADDR_LEN]; */ \
17326a8b0bfSPoul-Henning Kamp 	/* u_char addrhi[ETHER_ADDR_LEN]; */ \
174df8bae1dSRodney W. Grimes 	/* struct arpcom *ac; */ \
175df8bae1dSRodney W. Grimes 	/* struct ether_multi *enm; */ \
176df8bae1dSRodney W. Grimes { \
177df8bae1dSRodney W. Grimes 	for ((enm) = (ac)->ac_multiaddrs; \
178df8bae1dSRodney W. Grimes 	    (enm) != NULL && \
17926a8b0bfSPoul-Henning Kamp 	    (bcmp((enm)->enm_addrlo, (addrlo), ETHER_ADDR_LEN) != 0 || \
18026a8b0bfSPoul-Henning Kamp 	     bcmp((enm)->enm_addrhi, (addrhi), ETHER_ADDR_LEN) != 0); \
181df8bae1dSRodney W. Grimes 		(enm) = (enm)->enm_next); \
182df8bae1dSRodney W. Grimes }
183df8bae1dSRodney W. Grimes 
184df8bae1dSRodney W. Grimes /*
185df8bae1dSRodney W. Grimes  * Macro to step through all of the ether_multi records, one at a time.
186df8bae1dSRodney W. Grimes  * The current position is remembered in "step", which the caller must
187df8bae1dSRodney W. Grimes  * provide.  ETHER_FIRST_MULTI(), below, must be called to initialize "step"
188df8bae1dSRodney W. Grimes  * and get the first record.  Both macros return a NULL "enm" when there
189df8bae1dSRodney W. Grimes  * are no remaining records.
190df8bae1dSRodney W. Grimes  */
191df8bae1dSRodney W. Grimes #define ETHER_NEXT_MULTI(step, enm) \
192df8bae1dSRodney W. Grimes 	/* struct ether_multistep step; */  \
193df8bae1dSRodney W. Grimes 	/* struct ether_multi *enm; */  \
194df8bae1dSRodney W. Grimes { \
195df8bae1dSRodney W. Grimes 	if (((enm) = (step).e_enm) != NULL) \
196df8bae1dSRodney W. Grimes 		(step).e_enm = (enm)->enm_next; \
197df8bae1dSRodney W. Grimes }
198df8bae1dSRodney W. Grimes 
199df8bae1dSRodney W. Grimes #define ETHER_FIRST_MULTI(step, ac, enm) \
200df8bae1dSRodney W. Grimes 	/* struct ether_multistep step; */ \
201df8bae1dSRodney W. Grimes 	/* struct arpcom *ac; */ \
202df8bae1dSRodney W. Grimes 	/* struct ether_multi *enm; */ \
203df8bae1dSRodney W. Grimes { \
204df8bae1dSRodney W. Grimes 	(step).e_enm = (ac)->ac_multiaddrs; \
205df8bae1dSRodney W. Grimes 	ETHER_NEXT_MULTI((step), (enm)); \
206df8bae1dSRodney W. Grimes }
207df8bae1dSRodney W. Grimes 
208df8bae1dSRodney W. Grimes #endif
209707f139eSPaul Richards 
210707f139eSPaul Richards #endif
211