xref: /original-bsd/sys/netinet/if_ether.h (revision 4e889fb4)
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.9 (Berkeley) 01/08/93
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 u_char	ether_ipmulticast_min[6];
127 u_char	ether_ipmulticast_max[6];
128 
129 struct	llinfo_arp *arptnew __P((struct in_addr *));
130 struct	llinfo_arp llinfo_arp;		/* head of the llinfo queue */
131 int	ether_output __P((struct ifnet *, struct mbuf *, struct sockaddr *,
132 			  struct rtentry *));
133 int	ether_input __P((struct ifnet *, struct ether_header *, struct mbuf *));
134 char	*ether_sprintf __P((u_char *));
135 void	arp_rtrequest __P((int, struct rtentry *, struct sockaddr *));
136 struct	ifqueue arpintrq;
137 
138 /* XXX These probably belong elsewhere */
139 void	in_arpinput __P((struct mbuf *));
140 void	arpwhohas __P((struct arpcom *, struct in_addr *));
141 
142 /*
143  * Ethernet multicast address structure.  There is one of these for each
144  * multicast address or range of multicast addresses that we are supposed
145  * to listen to on a particular interface.  They are kept in a linked list,
146  * rooted in the interface's arpcom structure.  (This really has nothing to
147  * do with ARP, or with the Internet address family, but this appears to be
148  * the minimally-disrupting place to put it.)
149  */
150 struct ether_multi {
151 	u_char	enm_addrlo[6];		/* low  or only address of range */
152 	u_char	enm_addrhi[6];		/* high or only address of range */
153 	struct	arpcom *enm_ac;		/* back pointer to arpcom */
154 	u_int	enm_refcount;		/* no. claims to this addr/range */
155 	struct	ether_multi *enm_next;	/* ptr to next ether_multi */
156 };
157 
158 #ifdef KERNEL
159 /*
160  * Structure used by macros below to remember position when stepping through
161  * all of the ether_multi records.
162  */
163 struct ether_multistep {
164 	struct ether_multi  *e_enm;
165 };
166 
167 /*
168  * Macro for looking up the ether_multi record for a given range of Ethernet
169  * multicast addresses connected to a given arpcom structure.  If no matching
170  * record is found, "enm" returns NULL.
171  */
172 #define ETHER_LOOKUP_MULTI(addrlo, addrhi, ac, enm) \
173 	/* u_char addrlo[6]; */ \
174 	/* u_char addrhi[6]; */ \
175 	/* struct arpcom *ac; */ \
176 	/* struct ether_multi *enm; */ \
177 { \
178 	for ((enm) = (ac)->ac_multiaddrs; \
179 	    (enm) != NULL && \
180 	    (bcmp((enm)->enm_addrlo, (addrlo), 6) != 0 || \
181 	     bcmp((enm)->enm_addrhi, (addrhi), 6) != 0); \
182 		(enm) = (enm)->enm_next); \
183 }
184 
185 /*
186  * Macro to step through all of the ether_multi records, one at a time.
187  * The current position is remembered in "step", which the caller must
188  * provide.  ETHER_FIRST_MULTI(), below, must be called to initialize "step"
189  * and get the first record.  Both macros return a NULL "enm" when there
190  * are no remaining records.
191  */
192 #define ETHER_NEXT_MULTI(step, enm) \
193 	/* struct ether_multistep step; */  \
194 	/* struct ether_multi *enm; */  \
195 { \
196 	if (((enm) = (step).e_enm) != NULL) \
197 		(step).e_enm = (enm)->enm_next; \
198 }
199 
200 #define ETHER_FIRST_MULTI(step, ac, enm) \
201 	/* struct ether_multistep step; */ \
202 	/* struct arpcom *ac; */ \
203 	/* struct ether_multi *enm; */ \
204 { \
205 	(step).e_enm = (ac)->ac_multiaddrs; \
206 	ETHER_NEXT_MULTI((step), (enm)); \
207 }
208 #endif
209 #endif
210