]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
cb323159 | 2 | * Copyright (c) 2000-2017 Apple Inc. All rights reserved. |
5d5c5d0d | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
0a7de745 | 5 | * |
2d21ac55 A |
6 | * This file contains Original Code and/or Modifications of Original Code |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. The rights granted to you under the License | |
10 | * may not be used to create, or enable the creation or redistribution of, | |
11 | * unlawful or unlicensed copies of an Apple operating system, or to | |
12 | * circumvent, violate, or enable the circumvention or violation of, any | |
13 | * terms of an Apple operating system software license agreement. | |
0a7de745 | 14 | * |
2d21ac55 A |
15 | * Please obtain a copy of the License at |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
0a7de745 | 17 | * |
2d21ac55 A |
18 | * The Original Code and all software distributed under the License are |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
8f6c56a5 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
23 | * Please see the License for the specific language governing rights and | |
24 | * limitations under the License. | |
0a7de745 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
1c79356b A |
27 | */ |
28 | /* | |
29 | * Fundamental constants relating to ethernet. | |
30 | * | |
31 | */ | |
32 | ||
33 | #ifndef _NET_ETHERNET_H_ | |
34 | #define _NET_ETHERNET_H_ | |
f427ee49 | 35 | #ifndef DRIVERKIT |
9bccf70c | 36 | #include <sys/appleapiopts.h> |
0a7de745 | 37 | #include <sys/types.h> /* u_ types */ |
f427ee49 A |
38 | #else |
39 | #include <sys/_types.h> | |
40 | #include <sys/_types/_u_char.h> | |
41 | #include <sys/_types/_u_short.h> | |
42 | #endif /* DRIVERKIT */ | |
1c79356b A |
43 | |
44 | /* | |
45 | * The number of bytes in an ethernet (MAC) address. | |
46 | */ | |
0a7de745 | 47 | #define ETHER_ADDR_LEN 6 |
1c79356b A |
48 | |
49 | /* | |
50 | * The number of bytes in the type field. | |
51 | */ | |
0a7de745 | 52 | #define ETHER_TYPE_LEN 2 |
1c79356b A |
53 | |
54 | /* | |
55 | * The number of bytes in the trailing CRC field. | |
56 | */ | |
0a7de745 | 57 | #define ETHER_CRC_LEN 4 |
1c79356b A |
58 | |
59 | /* | |
60 | * The length of the combined header. | |
61 | */ | |
0a7de745 | 62 | #define ETHER_HDR_LEN (ETHER_ADDR_LEN*2+ETHER_TYPE_LEN) |
1c79356b A |
63 | |
64 | /* | |
65 | * The minimum packet length. | |
66 | */ | |
0a7de745 | 67 | #define ETHER_MIN_LEN 64 |
1c79356b A |
68 | |
69 | /* | |
70 | * The maximum packet length. | |
71 | */ | |
0a7de745 | 72 | #define ETHER_MAX_LEN 1518 |
1c79356b | 73 | |
6d2010ae A |
74 | /* |
75 | * Mbuf adjust factor to force 32-bit alignment of IP header. | |
76 | * Drivers should do m_adj(m, ETHER_ALIGN) when setting up a | |
77 | * receive so the upper layers get the IP header properly aligned | |
78 | * past the 14-byte Ethernet header. | |
79 | */ | |
80 | #define ETHER_ALIGN 2 /* driver adjust for IP hdr alignment */ | |
81 | ||
1c79356b A |
82 | /* |
83 | * A macro to validate a length with | |
84 | */ | |
0a7de745 | 85 | #define ETHER_IS_VALID_LEN(foo) \ |
1c79356b A |
86 | ((foo) >= ETHER_MIN_LEN && (foo) <= ETHER_MAX_LEN) |
87 | ||
88 | /* | |
89 | * Structure of a 10Mb/s Ethernet header. | |
90 | */ | |
0a7de745 A |
91 | typedef struct ether_header { |
92 | u_char ether_dhost[ETHER_ADDR_LEN]; | |
93 | u_char ether_shost[ETHER_ADDR_LEN]; | |
94 | u_short ether_type; | |
d9a64523 | 95 | } ether_header_t; |
1c79356b A |
96 | |
97 | /* | |
98 | * Structure of a 48-bit Ethernet address. | |
99 | */ | |
0a7de745 | 100 | typedef struct ether_addr { |
1c79356b | 101 | u_char octet[ETHER_ADDR_LEN]; |
d9a64523 | 102 | } ether_addr_t; |
1c79356b A |
103 | |
104 | #define ether_addr_octet octet | |
105 | ||
0a7de745 A |
106 | #define ETHERTYPE_PUP 0x0200 /* PUP protocol */ |
107 | #define ETHERTYPE_IP 0x0800 /* IP protocol */ | |
108 | #define ETHERTYPE_ARP 0x0806 /* Addr. resolution protocol */ | |
109 | #define ETHERTYPE_REVARP 0x8035 /* reverse Addr. resolution protocol */ | |
110 | #define ETHERTYPE_VLAN 0x8100 /* IEEE 802.1Q VLAN tagging */ | |
111 | #define ETHERTYPE_IPV6 0x86dd /* IPv6 */ | |
112 | #define ETHERTYPE_PAE 0x888e /* EAPOL PAE/802.1x */ | |
113 | #define ETHERTYPE_RSN_PREAUTH 0x88c7 /* 802.11i / RSN Pre-Authentication */ | |
114 | #define ETHERTYPE_PTP 0x88f7 /* IEEE 1588 Precision Time Protocol */ | |
115 | #define ETHERTYPE_LOOPBACK 0x9000 /* used to test interfaces */ | |
1c79356b | 116 | /* XXX - add more useful types here */ |
cb323159 | 117 | #define ETHERTYPE_IEEE802154 0x0809 /* 802.15.4 */ |
1c79356b A |
118 | |
119 | /* | |
120 | * The ETHERTYPE_NTRAILER packet types starting at ETHERTYPE_TRAIL have | |
121 | * (type-ETHERTYPE_TRAIL)*512 bytes of data followed | |
122 | * by an ETHER type (as given above) and then the (variable-length) header. | |
123 | */ | |
0a7de745 A |
124 | #define ETHERTYPE_TRAIL 0x1000 /* Trailer packet */ |
125 | #define ETHERTYPE_NTRAILER 16 | |
1c79356b | 126 | |
0a7de745 A |
127 | #define ETHERMTU (ETHER_MAX_LEN-ETHER_HDR_LEN-ETHER_CRC_LEN) |
128 | #define ETHERMIN (ETHER_MIN_LEN-ETHER_HDR_LEN-ETHER_CRC_LEN) | |
1c79356b | 129 | |
f427ee49 | 130 | #ifndef DRIVERKIT |
91447636 A |
131 | #ifdef KERNEL_PRIVATE |
132 | /* | |
133 | * The following are used by ethernet interfaces. | |
134 | */ | |
135 | ||
0a7de745 | 136 | struct ether_addr *ether_aton(const char *); |
91447636 A |
137 | |
138 | #ifdef BSD_KERNEL_PRIVATE | |
0a7de745 | 139 | extern u_char etherbroadcastaddr[ETHER_ADDR_LEN]; |
6d2010ae | 140 | |
5ba3f43e A |
141 | #if defined (__arm__) |
142 | ||
143 | #include <string.h> | |
144 | ||
145 | static __inline__ int | |
146 | _ether_cmp(const void * a, const void * b) | |
147 | { | |
0a7de745 | 148 | return memcmp(a, b, ETHER_ADDR_LEN); |
5ba3f43e A |
149 | } |
150 | ||
151 | #else /* __arm__ */ | |
6d2010ae A |
152 | |
153 | static __inline__ int | |
154 | _ether_cmp(const void * a, const void * b) | |
155 | { | |
156 | const u_int16_t * a_s = (const u_int16_t *)a; | |
157 | const u_int16_t * b_s = (const u_int16_t *)b; | |
0a7de745 | 158 | |
6d2010ae | 159 | if (a_s[0] != b_s[0] |
0a7de745 A |
160 | || a_s[1] != b_s[1] |
161 | || a_s[2] != b_s[2]) { | |
162 | return 1; | |
6d2010ae | 163 | } |
0a7de745 | 164 | return 0; |
6d2010ae A |
165 | } |
166 | ||
5ba3f43e | 167 | #endif /* __arm__ */ |
6d2010ae | 168 | #endif /* BSD_KERNEL_PRIVATE */ |
b7266188 A |
169 | |
170 | #define ETHER_IS_MULTICAST(addr) (*(addr) & 0x01) /* is address mcast/bcast? */ | |
171 | ||
91447636 | 172 | #endif /* KERNEL_PRIVATE */ |
1c79356b | 173 | |
9bccf70c | 174 | #ifndef KERNEL |
1c79356b A |
175 | #include <sys/cdefs.h> |
176 | ||
177 | /* | |
178 | * Ethernet address conversion/parsing routines. | |
179 | */ | |
180 | __BEGIN_DECLS | |
181 | ||
0a7de745 A |
182 | int ether_hostton(const char *, struct ether_addr *); |
183 | int ether_line(const char *, struct ether_addr *, char *); | |
184 | char *ether_ntoa(const struct ether_addr *); | |
185 | struct ether_addr *ether_aton(const char *); | |
186 | int ether_ntohost(char *, const struct ether_addr *); | |
1c79356b A |
187 | __END_DECLS |
188 | #endif /* !KERNEL */ | |
f427ee49 | 189 | #endif /* DRIVERKIT */ |
1c79356b A |
190 | |
191 | #endif /* !_NET_ETHERNET_H_ */ |