xref: /original-bsd/sys/netinet/if_ether.h (revision e58d00f4)
1 /*
2  * Copyright (c) 1982, 1986 Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  *
7  *	@(#)if_ether.h	7.8 (Berkeley) 07/06/92
8  */
9 
10 /*
11  * Structure of a 10Mb/s Ethernet header.
12  */
13 struct	ether_header {
14 	u_char	ether_dhost[6];
15 	u_char	ether_shost[6];
16 	u_short	ether_type;
17 };
18 
19 #define	ETHERTYPE_PUP		0x0200	/* PUP protocol */
20 #define	ETHERTYPE_IP		0x0800	/* IP protocol */
21 #define ETHERTYPE_ARP		0x0806	/* Addr. resolution protocol */
22 #define ETHERTYPE_REVARP	0x8035	/* reverse Addr. resolution protocol */
23 
24 /*
25  * The ETHERTYPE_NTRAILER packet types starting at ETHERTYPE_TRAIL have
26  * (type-ETHERTYPE_TRAIL)*512 bytes of data followed
27  * by an ETHER type (as given above) and then the (variable-length) header.
28  */
29 #define	ETHERTYPE_TRAIL		0x1000		/* Trailer packet */
30 #define	ETHERTYPE_NTRAILER	16
31 
32 #define	ETHERMTU	1500
33 #define	ETHERMIN	(60-14)
34 
35 #ifdef KERNEL
36 /*
37  * Macro to map an IP multicast address to an Ethernet multicast address.
38  * The high-order 25 bits of the Ethernet address are statically assigned,
39  * and the low-order 23 bits are taken from the low end of the IP address.
40  */
41 #define ETHER_MAP_IP_MULTICAST(ipaddr, enaddr) \
42 	/* struct in_addr *ipaddr; */ \
43 	/* u_char enaddr[6];	   */ \
44 { \
45 	(enaddr)[0] = 0x01; \
46 	(enaddr)[1] = 0x00; \
47 	(enaddr)[2] = 0x5e; \
48 	(enaddr)[3] = ((u_char *)ipaddr)[1] & 0x7f; \
49 	(enaddr)[4] = ((u_char *)ipaddr)[2]; \
50 	(enaddr)[5] = ((u_char *)ipaddr)[3]; \
51 }
52 #endif
53 
54 /*
55  * Ethernet Address Resolution Protocol.
56  *
57  * See RFC 826 for protocol description.  Structure below is adapted
58  * to resolving internet addresses.  Field names used correspond to
59  * RFC 826.
60  */
61 struct	ether_arp {
62 	struct	arphdr ea_hdr;	/* fixed-size header */
63 	u_char	arp_sha[6];	/* sender hardware address */
64 	u_char	arp_spa[4];	/* sender protocol address */
65 	u_char	arp_tha[6];	/* target hardware address */
66 	u_char	arp_tpa[4];	/* target protocol address */
67 };
68 #define	arp_hrd	ea_hdr.ar_hrd
69 #define	arp_pro	ea_hdr.ar_pro
70 #define	arp_hln	ea_hdr.ar_hln
71 #define	arp_pln	ea_hdr.ar_pln
72 #define	arp_op	ea_hdr.ar_op
73 
74 
75 /*
76  * Structure shared between the ethernet driver modules and
77  * the address resolution code.  For example, each ec_softc or il_softc
78  * begins with this structure.
79  */
80 struct	arpcom {
81 	struct 	ifnet ac_if;		/* network-visible interface */
82 	u_char	ac_enaddr[6];		/* ethernet hardware address */
83 	struct	in_addr ac_ipaddr;	/* copy of ip address- XXX */
84 	struct	ether_multi *ac_multiaddrs; /* list of ether multicast addrs */
85 	int	ac_multicnt;		/* length of ac_multiaddrs list */
86 };
87 
88 /*
89  * Internet to ethernet address resolution table.
90  */
91 struct	arptab {
92 	struct	in_addr at_iaddr;	/* internet address */
93 	u_char	at_enaddr[6];		/* ethernet address */
94 	u_char	at_timer;		/* minutes since last reference */
95 	u_char	at_flags;		/* flags */
96 	struct	mbuf *at_hold;		/* last packet until resolved/timeout */
97 }; /* XXX: only used to define SIOCGARP, which is no longer supported */
98 
99 struct llinfo_arp {
100 	struct	llinfo_arp *la_next;
101 	struct	llinfo_arp *la_prev;
102 	struct	rtentry *la_rt;
103 	struct	mbuf *la_hold;		/* last packet until resolved/timeout */
104 	long	la_asked;		/* last time we QUERIED for this addr */
105 #define la_timer la_rt->rt_rmx.rmx_expire /* deletion time in seconds */
106 };
107 
108 struct sockaddr_inarp {
109 	u_char	sin_len;
110 	u_char	sin_family;
111 	u_short sin_port;
112 	struct	in_addr sin_addr;
113 	struct	in_addr sin_srcaddr;
114 	u_short	sin_tos;
115 	u_short	sin_other;
116 #define SIN_PROXY 1
117 };
118 /*
119  * IP and ethernet specific routing flags
120  */
121 #define	RTF_USETRAILERS	RTF_PROTO1	/* use trailers */
122 #define RTF_ANNOUNCE	RTF_PROTO2	/* announce new arp entry */
123 
124 #ifdef	KERNEL
125 u_char	etherbroadcastaddr[6];
126 #if defined(ISO) && !defined(MULTICAST)
127 #define MULTICAST 1
128 #endif
129 #ifdef MULTICAST
130 u_char	ether_ipmulticast_min[6];
131 u_char	ether_ipmulticast_max[6];
132 #endif
133 
134 struct	llinfo_arp *arptnew __P((struct in_addr *));
135 struct	llinfo_arp llinfo_arp;		/* head of the llinfo queue */
136 int	ether_output __P((struct ifnet *, struct mbuf *, struct sockaddr *,
137 			  struct rtentry *));
138 int	ether_input __P((struct ifnet *, struct ether_header *, struct mbuf *));
139 char	*ether_sprintf __P((u_char *));
140 void	arp_rtrequest __P((int, struct rtentry *, struct sockaddr *));
141 struct	ifqueue arpintrq;
142 
143 /* XXX These probably belong elsewhere */
144 void	in_arpinput __P((struct mbuf *));
145 void	arpwhohas __P((struct arpcom *, struct in_addr *));
146 
147 #ifdef MULTICAST
148 /*
149  * Ethernet multicast address structure.  There is one of these for each
150  * multicast address or range of multicast addresses that we are supposed
151  * to listen to on a particular interface.  They are kept in a linked list,
152  * rooted in the interface's arpcom structure.  (This really has nothing to
153  * do with ARP, or with the Internet address family, but this appears to be
154  * the minimally-disrupting place to put it.)
155  */
156 struct ether_multi {
157 	u_char	enm_addrlo[6];		/* low  or only address of range */
158 	u_char	enm_addrhi[6];		/* high or only address of range */
159 	struct	arpcom *enm_ac;		/* back pointer to arpcom */
160 	u_int	enm_refcount;		/* no. claims to this addr/range */
161 	struct	ether_multi *enm_next;	/* ptr to next ether_multi */
162 };
163 
164 #ifdef KERNEL
165 /*
166  * Structure used by macros below to remember position when stepping through
167  * all of the ether_multi records.
168  */
169 struct ether_multistep {
170 	struct ether_multi  *e_enm;
171 };
172 
173 /*
174  * Macro for looking up the ether_multi record for a given range of Ethernet
175  * multicast addresses connected to a given arpcom structure.  If no matching
176  * record is found, "enm" returns NULL.
177  */
178 #define ETHER_LOOKUP_MULTI(addrlo, addrhi, ac, enm) \
179 	/* u_char addrlo[6]; */ \
180 	/* u_char addrhi[6]; */ \
181 	/* struct arpcom *ac; */ \
182 	/* struct ether_multi *enm; */ \
183 { \
184 	for ((enm) = (ac)->ac_multiaddrs; \
185 	    (enm) != NULL && \
186 	    (bcmp((enm)->enm_addrlo, (addrlo), 6) != 0 || \
187 	     bcmp((enm)->enm_addrhi, (addrhi), 6) != 0); \
188 		(enm) = (enm)->enm_next); \
189 }
190 
191 /*
192  * Macro to step through all of the ether_multi records, one at a time.
193  * The current position is remembered in "step", which the caller must
194  * provide.  ETHER_FIRST_MULTI(), below, must be called to initialize "step"
195  * and get the first record.  Both macros return a NULL "enm" when there
196  * are no remaining records.
197  */
198 #define ETHER_NEXT_MULTI(step, enm) \
199 	/* struct ether_multistep step; */  \
200 	/* struct ether_multi *enm; */  \
201 { \
202 	if (((enm) = (step).e_enm) != NULL) \
203 		(step).e_enm = (enm)->enm_next; \
204 }
205 
206 #define ETHER_FIRST_MULTI(step, ac, enm) \
207 	/* struct ether_multistep step; */ \
208 	/* struct arpcom *ac; */ \
209 	/* struct ether_multi *enm; */ \
210 { \
211 	(step).e_enm = (ac)->ac_multiaddrs; \
212 	ETHER_NEXT_MULTI((step), (enm)); \
213 }
214 #endif
215 #endif
216 #endif
217