1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 #ifndef _NETINET_IF_ETHER_H_
36 #define _NETINET_IF_ETHER_H_
37
38
39
40
41 #define ETHER_ADDR_LEN 6
42 #define ETHER_TYPE_LEN 2
43 #define ETHER_CRC_LEN 4
44 #define ETHER_HDR_LEN ((ETHER_ADDR_LEN * 2) + ETHER_TYPE_LEN)
45 #define ETHER_MIN_LEN 64
46 #define ETHER_MAX_LEN 1518
47 #define ETHER_MAX_DIX_LEN 1536
48
49
50
51
52 #define ETHER_VLAN_ENCAP_LEN 4
53
54
55
56
57
58
59
60 #define ETHER_ALIGN 2
61
62
63
64
65 struct ether_addr {
66 u_int8_t ether_addr_octet[ETHER_ADDR_LEN];
67 };
68
69
70
71
72 struct ether_header {
73 u_int8_t ether_dhost[ETHER_ADDR_LEN];
74 u_int8_t ether_shost[ETHER_ADDR_LEN];
75 u_int16_t ether_type;
76 };
77
78 #include <net/ethertypes.h>
79
80 #define ETHER_IS_MULTICAST(addr) (*(addr) & 0x01)
81
82 #define ETHERMTU (ETHER_MAX_LEN - ETHER_HDR_LEN - ETHER_CRC_LEN)
83 #define ETHERMIN (ETHER_MIN_LEN - ETHER_HDR_LEN - ETHER_CRC_LEN)
84
85
86
87
88 #define ETHER_CRC_POLY_LE 0xedb88320
89 #define ETHER_CRC_POLY_BE 0x04c11db6
90
91
92
93
94 #define M_HASFCS M_LINK0
95
96 #ifdef _KERNEL
97
98
99
100
101
102 #define ETHER_MAP_IP_MULTICAST(ipaddr, enaddr) \
103 \
104 \
105 { \
106 (enaddr)[0] = 0x01; \
107 (enaddr)[1] = 0x00; \
108 (enaddr)[2] = 0x5e; \
109 (enaddr)[3] = ((u_int8_t *)ipaddr)[1] & 0x7f; \
110 (enaddr)[4] = ((u_int8_t *)ipaddr)[2]; \
111 (enaddr)[5] = ((u_int8_t *)ipaddr)[3]; \
112 }
113
114
115
116
117
118
119 #define ETHER_MAP_IPV6_MULTICAST(ip6addr, enaddr) \
120 \
121 \
122 { \
123 (enaddr)[0] = 0x33; \
124 (enaddr)[1] = 0x33; \
125 (enaddr)[2] = ((u_int8_t *)ip6addr)[12]; \
126 (enaddr)[3] = ((u_int8_t *)ip6addr)[13]; \
127 (enaddr)[4] = ((u_int8_t *)ip6addr)[14]; \
128 (enaddr)[5] = ((u_int8_t *)ip6addr)[15]; \
129 }
130 #endif
131
132
133
134
135
136
137
138
139 struct ether_arp {
140 struct arphdr ea_hdr;
141 u_int8_t arp_sha[ETHER_ADDR_LEN];
142 u_int8_t arp_spa[4];
143 u_int8_t arp_tha[ETHER_ADDR_LEN];
144 u_int8_t arp_tpa[4];
145 };
146 #define arp_hrd ea_hdr.ar_hrd
147 #define arp_pro ea_hdr.ar_pro
148 #define arp_hln ea_hdr.ar_hln
149 #define arp_pln ea_hdr.ar_pln
150 #define arp_op ea_hdr.ar_op
151
152
153
154
155
156
157 struct arpcom {
158 struct ifnet ac_if;
159 u_int8_t ac_enaddr[ETHER_ADDR_LEN];
160 char ac__pad[2];
161 LIST_HEAD(, ether_multi) ac_multiaddrs;
162 int ac_multicnt;
163 int ac_multirangecnt;
164
165 };
166
167 struct llinfo_arp {
168 LIST_ENTRY(llinfo_arp) la_list;
169 struct rtentry *la_rt;
170 struct mbuf *la_hold;
171 long la_asked;
172 #define la_timer la_rt->rt_rmx.rmx_expire
173 };
174
175 struct sockaddr_inarp {
176 u_int8_t sin_len;
177 u_int8_t sin_family;
178 u_int16_t sin_port;
179 struct in_addr sin_addr;
180 struct in_addr sin_srcaddr;
181 u_int16_t sin_tos;
182 u_int16_t sin_other;
183 #define SIN_PROXY 1
184 };
185
186
187
188
189 #define RTF_USETRAILERS RTF_PROTO1
190 #define RTF_ANNOUNCE RTF_PROTO2
191 #define RTF_PERMANENT_ARP RTF_PROTO3
192
193 #ifdef _KERNEL
194 extern u_int8_t etherbroadcastaddr[ETHER_ADDR_LEN];
195 extern u_int8_t ether_ipmulticast_min[ETHER_ADDR_LEN];
196 extern u_int8_t ether_ipmulticast_max[ETHER_ADDR_LEN];
197 extern struct ifqueue arpintrq;
198
199 void arpwhohas(struct arpcom *, struct in_addr *);
200 void arpintr(void);
201 int arpresolve(struct arpcom *,
202 struct rtentry *, struct mbuf *, struct sockaddr *, u_char *);
203 void arp_ifinit(struct arpcom *, struct ifaddr *);
204 void arp_rtrequest(int, struct rtentry *, struct rt_addrinfo *);
205
206 int ether_addmulti(struct ifreq *, struct arpcom *);
207 int ether_delmulti(struct ifreq *, struct arpcom *);
208 int ether_multiaddr(struct sockaddr *, u_int8_t[], u_int8_t[]);
209 #endif
210
211
212
213
214
215
216
217
218
219 struct ether_multi {
220 u_int8_t enm_addrlo[ETHER_ADDR_LEN];
221 u_int8_t enm_addrhi[ETHER_ADDR_LEN];
222 struct arpcom *enm_ac;
223 u_int enm_refcount;
224 LIST_ENTRY(ether_multi) enm_list;
225 };
226
227
228
229
230
231 struct ether_multistep {
232 struct ether_multi *e_enm;
233 };
234
235
236
237
238
239
240 #define ETHER_LOOKUP_MULTI(addrlo, addrhi, ac, enm) \
241 \
242 \
243 \
244 \
245 { \
246 for ((enm) = LIST_FIRST(&(ac)->ac_multiaddrs); \
247 (enm) != LIST_END(&(ac)->ac_multiaddrs) && \
248 (bcmp((enm)->enm_addrlo, (addrlo), ETHER_ADDR_LEN) != 0 || \
249 bcmp((enm)->enm_addrhi, (addrhi), ETHER_ADDR_LEN) != 0); \
250 (enm) = LIST_NEXT((enm), enm_list)); \
251 }
252
253
254
255
256
257
258
259
260 #define ETHER_NEXT_MULTI(step, enm) \
261 \
262 \
263 { \
264 if (((enm) = (step).e_enm) != NULL) \
265 (step).e_enm = LIST_NEXT((enm), enm_list); \
266 }
267
268 #define ETHER_FIRST_MULTI(step, ac, enm) \
269 \
270 \
271 \
272 { \
273 (step).e_enm = LIST_FIRST(&(ac)->ac_multiaddrs); \
274 ETHER_NEXT_MULTI((step), (enm)); \
275 }
276
277 #ifdef _KERNEL
278
279 extern struct ifnet *myip_ifp;
280
281 int arpioctl(u_long, caddr_t);
282 void arprequest(struct ifnet *, u_int32_t *, u_int32_t *, u_int8_t *);
283 void revarpinput(struct mbuf *);
284 void in_revarpinput(struct mbuf *);
285 void revarprequest(struct ifnet *);
286 int revarpwhoarewe(struct ifnet *, struct in_addr *, struct in_addr *);
287 int revarpwhoami(struct in_addr *, struct ifnet *);
288 int db_show_arptab(void);
289
290 u_int32_t ether_crc32_le(const u_int8_t *, size_t);
291 u_int32_t ether_crc32_be(const u_int8_t *, size_t);
292
293 #else
294
295 __BEGIN_DECLS
296 char *ether_ntoa(struct ether_addr *);
297 struct ether_addr *ether_aton(const char *);
298 int ether_ntohost(char *, struct ether_addr *);
299 int ether_hostton(const char *, struct ether_addr *);
300 int ether_line(const char *, struct ether_addr *, char *);
301 __END_DECLS
302
303 #endif
304 #endif