1 | /*
|
---|
2 | * TINET (TCP/IP Protocol Stack)
|
---|
3 | *
|
---|
4 | * Copyright (C) 2001-2017 by Dep. of Computer Science and Engineering
|
---|
5 | * Tomakomai National College of Technology, JAPAN
|
---|
6 | *
|
---|
7 | * ä¸è¨èä½æ¨©è
|
---|
8 | ã¯ï¼ä»¥ä¸ã® (1)ï½(4) ã®æ¡ä»¶ãï¼Free Software Foundation
|
---|
9 | * ã«ãã£ã¦å
|
---|
10 | ¬è¡¨ããã¦ãã GNU General Public License ã® Version 2 ã«è¨
|
---|
11 | * è¿°ããã¦ããæ¡ä»¶ãæºããå ´åã«éãï¼æ¬ã½ããã¦ã§ã¢ï¼æ¬ã½ããã¦ã§ã¢
|
---|
12 | * ãæ¹å¤ãããã®ãå«ãï¼ä»¥ä¸åãï¼ã使ç¨ã»è¤è£½ã»æ¹å¤ã»åé
|
---|
13 | å¸ï¼ä»¥ä¸ï¼
|
---|
14 | * å©ç¨ã¨å¼ã¶ï¼ãããã¨ãç¡åã§è¨±è«¾ããï¼
|
---|
15 | * (1) æ¬ã½ããã¦ã§ã¢ãã½ã¼ã¹ã³ã¼ãã®å½¢ã§å©ç¨ããå ´åã«ã¯ï¼ä¸è¨ã®èä½
|
---|
16 | * 権表示ï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãï¼ãã®ã¾ã¾ã®å½¢ã§ã½ã¼
|
---|
17 | * ã¹ã³ã¼ãä¸ã«å«ã¾ãã¦ãããã¨ï¼
|
---|
18 | * (2) æ¬ã½ããã¦ã§ã¢ãï¼ã©ã¤ãã©ãªå½¢å¼ãªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
19 | * ç¨ã§ããå½¢ã§åé
|
---|
20 | å¸ããå ´åã«ã¯ï¼åé
|
---|
21 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨
|
---|
22 | * è
|
---|
23 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®èä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨
|
---|
24 | * ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
25 | * (3) æ¬ã½ããã¦ã§ã¢ãï¼æ©å¨ã«çµã¿è¾¼ããªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
26 | * ç¨ã§ããªãå½¢ã§åé
|
---|
27 | å¸ããå ´åã«ã¯ï¼æ¬¡ã®æ¡ä»¶ãæºãããã¨ï¼
|
---|
28 | * (a) åé
|
---|
29 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨è
|
---|
30 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è
|
---|
31 | * ä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
32 | * (4) æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ
|
---|
33 | * 害ãããï¼ä¸è¨èä½æ¨©è
|
---|
34 | ããã³TOPPERSããã¸ã§ã¯ããå
|
---|
35 | 責ãããã¨ï¼
|
---|
36 | *
|
---|
37 | * æ¬ã½ããã¦ã§ã¢ã¯ï¼ç¡ä¿è¨¼ã§æä¾ããã¦ãããã®ã§ããï¼ä¸è¨èä½æ¨©è
|
---|
38 | ã
|
---|
39 | * ãã³TOPPERSããã¸ã§ã¯ãã¯ï¼æ¬ã½ããã¦ã§ã¢ã«é¢ãã¦ï¼ãã®é©ç¨å¯è½æ§ã
|
---|
40 | * å«ãã¦ï¼ãããªãä¿è¨¼ãè¡ããªãï¼ã¾ãï¼æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´
|
---|
41 | * æ¥çã¾ãã¯éæ¥çã«çãããããªãæ害ã«é¢ãã¦ãï¼ãã®è²¬ä»»ãè² ããªãï¼
|
---|
42 | *
|
---|
43 | * @(#) $Id: ethernet.h 317 2017-08-03 13:14:26Z coas-nagasima $
|
---|
44 | */
|
---|
45 |
|
---|
46 | /*
|
---|
47 | * Copyright (c) 1982, 1986, 1989, 1993
|
---|
48 | * The Regents of the University of California. All rights reserved.
|
---|
49 | *
|
---|
50 | * Redistribution and use in source and binary forms, with or without
|
---|
51 | * modification, are permitted provided that the following conditions
|
---|
52 | * are met:
|
---|
53 | * 1. Redistributions of source code must retain the above copyright
|
---|
54 | * notice, this list of conditions and the following disclaimer.
|
---|
55 | * 2. Redistributions in binary form must reproduce the above copyright
|
---|
56 | * notice, this list of conditions and the following disclaimer in the
|
---|
57 | * documentation and/or other materials provided with the distribution.
|
---|
58 | * 3. All advertising materials mentioning features or use of this software
|
---|
59 | * must display the following acknowledgement:
|
---|
60 | * This product includes software developed by the University of
|
---|
61 | * California, Berkeley and its contributors.
|
---|
62 | * 4. Neither the name of the University nor the names of its contributors
|
---|
63 | * may be used to endorse or promote products derived from this software
|
---|
64 | * without specific prior written permission.
|
---|
65 | *
|
---|
66 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
---|
67 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
---|
68 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
---|
69 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
---|
70 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
---|
71 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
---|
72 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
---|
73 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
---|
74 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
---|
75 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
---|
76 | * SUCH DAMAGE.
|
---|
77 | *
|
---|
78 | * Fundamental constants relating to ethernet.
|
---|
79 | *
|
---|
80 | * $FreeBSD: src/sys/net/ethernet.h,v 1.9.2.1 1999/08/29 16:28:13 peter Exp $
|
---|
81 | *
|
---|
82 | */
|
---|
83 |
|
---|
84 | #ifndef _ETHERNET_H_
|
---|
85 | #define _ETHERNET_H_
|
---|
86 |
|
---|
87 | #ifdef SUPPORT_ETHER
|
---|
88 |
|
---|
89 | /*
|
---|
90 | * ãã£ã¼ã«ãé·
|
---|
91 | */
|
---|
92 |
|
---|
93 | #define ETHER_ADDR_LEN 6 /* Ethernet (MAC) Address */
|
---|
94 | #define ETHER_TYPE_LEN 2 /* Type */
|
---|
95 | #define ETHER_CRC_LEN 4 /* CRC */
|
---|
96 |
|
---|
97 | /*
|
---|
98 | * ãã¬ã¼ã é· (Ethernet ããã㨠CRC ãå«ã)
|
---|
99 | */
|
---|
100 |
|
---|
101 | #define ETHER_MIN_LEN 64
|
---|
102 | #define ETHER_MAX_LEN (IF_MTU + sizeof(T_ETHER_HDR) + ETHER_CRC_LEN)
|
---|
103 |
|
---|
104 | /*
|
---|
105 | * Ethernet ããã
|
---|
106 | */
|
---|
107 |
|
---|
108 | #ifndef IF_ETHER_NIC_HDR_ALIGN
|
---|
109 | #error IF_ETHER_NIC_HDR_ALIGN expected.
|
---|
110 | #endif /* of #ifndef IF_ETHER_NIC_HDR_ALIGN */
|
---|
111 |
|
---|
112 | #if defined(__RX)
|
---|
113 |
|
---|
114 | #pragma pack
|
---|
115 | typedef struct t_ether_header {
|
---|
116 |
|
---|
117 | #if IF_ETHER_NIC_HDR_ALIGN != 0
|
---|
118 |
|
---|
119 | uint8_t align[IF_ETHER_NIC_HDR_ALIGN]; /* ã¢ã©ã¤ã³èª¿æ´ */
|
---|
120 |
|
---|
121 | #endif /* of #if IF_ETHER_NIC_HDR_ALIGN != 0 */
|
---|
122 |
|
---|
123 | uint8_t dhost[ETHER_ADDR_LEN];
|
---|
124 | uint8_t shost[ETHER_ADDR_LEN];
|
---|
125 | uint16_t type;
|
---|
126 | } T_ETHER_HDR;
|
---|
127 | #pragma packoption
|
---|
128 |
|
---|
129 | #elif defined(TOPPERS_S810_CLG3_85) /* of #if defined(__RX) */
|
---|
130 |
|
---|
131 | typedef struct t_ether_header {
|
---|
132 |
|
---|
133 | #if IF_ETHER_NIC_HDR_ALIGN != 0
|
---|
134 |
|
---|
135 | uint8_t align[IF_ETHER_NIC_HDR_ALIGN]; /* ã¢ã©ã¤ã³èª¿æ´ */
|
---|
136 |
|
---|
137 | #endif /* of #if IF_ETHER_NIC_HDR_ALIGN != 0 */
|
---|
138 |
|
---|
139 | uint8_t dhost[ETHER_ADDR_LEN];
|
---|
140 | uint8_t shost[ETHER_ADDR_LEN];
|
---|
141 | uint16_t type;
|
---|
142 | } T_ETHER_HDR;
|
---|
143 |
|
---|
144 | #else /* of #if defined(__RX) */
|
---|
145 |
|
---|
146 | typedef struct t_ether_header {
|
---|
147 |
|
---|
148 | #if IF_ETHER_NIC_HDR_ALIGN != 0
|
---|
149 |
|
---|
150 | uint8_t align[IF_ETHER_NIC_HDR_ALIGN]; /* ã¢ã©ã¤ã³èª¿æ´ */
|
---|
151 |
|
---|
152 | #endif /* of #if IF_ETHER_NIC_HDR_ALIGN != 0 */
|
---|
153 |
|
---|
154 | uint8_t dhost[ETHER_ADDR_LEN];
|
---|
155 | uint8_t shost[ETHER_ADDR_LEN];
|
---|
156 | uint16_t type;
|
---|
157 | } __attribute__((packed))T_ETHER_HDR;
|
---|
158 |
|
---|
159 | #endif /* of #if defined(__RX) */
|
---|
160 |
|
---|
161 | #define GET_ETHER_HDR(nbuf) ((T_ETHER_HDR*)((nbuf)->buf))
|
---|
162 |
|
---|
163 | /*
|
---|
164 | * MAC ã¢ãã¬ã¹ã®å®ç¾©
|
---|
165 | */
|
---|
166 |
|
---|
167 | #define ETHER_MCAST_ADDR UINT_C(0x01) /* ãã«ããã£ã¹ãã»ã¢ãã¬ã¹ */
|
---|
168 | #define ETHER_LOCAL_ADDR UINT_C(0x02) /* ãã¼ã«ã«ã»ã¢ãã¬ã¹ */
|
---|
169 |
|
---|
170 | typedef struct t_ether_addr {
|
---|
171 | uint8_t lladdr[ETHER_ADDR_LEN];
|
---|
172 | } T_ETHER_ADDR;
|
---|
173 |
|
---|
174 | /*
|
---|
175 | * Type ãã£ã¼ã«ã
|
---|
176 | */
|
---|
177 |
|
---|
178 | #define ETHER_TYPE_IP UINT_C(0x0800) /* IPv4 */
|
---|
179 | #define ETHER_TYPE_ARP UINT_C(0x0806) /* ARP */
|
---|
180 | #define ETHER_TYPE_IPV6 UINT_C(0x86dd) /* IPv6 */
|
---|
181 |
|
---|
182 | /*
|
---|
183 | * ã¤ã³ã¿ãã§ã¼ã¹ã®é¸æãã¯ã
|
---|
184 | */
|
---|
185 |
|
---|
186 | #define T_IF_HDR T_ETHER_HDR /* ã¤ã³ã¿ãã§ã¼ã¹ã®ããã */
|
---|
187 | #define T_IF_ADDR T_ETHER_ADDR /* ã¤ã³ã¿ãã§ã¼ã¹ã®ã¢ãã¬ã¹ */
|
---|
188 | #define IF_HDR_ALIGN 2 /* ãããã®ã¢ã©ã¤ã³åä½ */
|
---|
189 | #define IF_MTU 1500 /* ã¤ã³ã¿ãã§ã¼ã¹ã® MTU */
|
---|
190 | #define IF_MIN_LEN ETHER_MIN_LEN /* ã¤ã³ã¿ã¼ãã§ã¼ã¹ãã¬ã¼ã ã®æçé· */
|
---|
191 |
|
---|
192 | #define IF_OUTPUT(o,d,g,t) ether_output(o,d,g,t) /* ã¤ã³ã¿ãã§ã¼ã¹ã®åºåé¢æ° */
|
---|
193 | #define IF_RAW_OUTPUT(o,t) ether_raw_output(o,t) /* ã¤ã³ã¿ãã§ã¼ã¹ã®åºåé¢æ°ãã¢ãã¬ã¹è§£æ±ºç¡ã */
|
---|
194 | #define IF_SET_PROTO(b,p) (GET_ETHER_HDR(b)->type = htons(p))
|
---|
195 | /* ã¤ã³ã¿ãã§ã¼ã¹ã®ãããã³ã«è¨å®é¢æ° */
|
---|
196 | #define IF_SOFTC_TO_IFADDR(s) ((T_IF_ADDR*)(s)->ifaddr.lladdr)
|
---|
197 | /* ã½ããã¦ã§ã¢æ
|
---|
198 | å ±ãã MAC ã¢ãã¬ã¹ãåãåºã */
|
---|
199 | #define IF_GET_IFNET() ether_get_ifnet() /* ãããã¯ã¼ã¯ã¤ã³ã¿ãã§ã¼ã¹æ§é ä½ãè¿ãã */
|
---|
200 | #define IF_TYPE IFT_ETHER /* ã¤ã³ã¿ãã§ã¼ã¹ã®å */
|
---|
201 | #define IF_SRAND() ether_srand() /* ã¤ã³ã¿ãã§ã¼ã¹ã®ä¹±æ°åæå¤ */
|
---|
202 |
|
---|
203 | /* IPv4 é¢ä¿ */
|
---|
204 |
|
---|
205 | #define IF_PROTO_IP ETHER_TYPE_IP /* ã¤ã³ã¿ãã§ã¼ã¹ã® IPv4 ãããã³ã«æå® */
|
---|
206 | #define IF_PROTO_ARP ETHER_TYPE_ARP /* ã¤ã³ã¿ãã§ã¼ã¹ã® ARP ãããã³ã«æå® */
|
---|
207 |
|
---|
208 | /* IPv6 é¢ä¿ */
|
---|
209 |
|
---|
210 | #define MAX_IF_MADDR_CNT 2 /* ã¤ã³ã¿ãã§ã¼ã¹ã®ãã«ããã£ã¹ãã¢ãã¬ã¹é
|
---|
211 | åã®æ大ãµã¤ãº */
|
---|
212 | #define IF_MADDR_INIT { { { 0, 0, 0, 0, 0, 0 } }, { { 0, 0, 0, 0, 0, 0 } } }
|
---|
213 | /* ã¤ã³ã¿ãã§ã¼ã¹ã®ãã«ããã£ã¹ãã¢ãã¬ã¹é
|
---|
214 | åã®åæå */
|
---|
215 | #define IF_PROTO_IPV6 ETHER_TYPE_IPV6 /* ã¤ã³ã¿ãã§ã¼ã¹ã® IPv6 ãããã³ã«æå® */
|
---|
216 | #define IF_ADDMULTI(s) IF_ETHER_NIC_ADDMULTI(s)
|
---|
217 | /* ãã«ããã£ã¹ãã¢ãã¬ã¹ã®ç»é² */
|
---|
218 | #define IF_IN6_NEED_CACHE(i) (true) /* è¿é£æ¢ç´¢ãã£ãã·ã¥ã使ç¨ããã */
|
---|
219 | #define IF_IN6_IFID(i,a) IF_ETHER_NIC_IN6_IFID(i,a)
|
---|
220 | /* ã¤ã³ã¿ãã§ã¼ã¹èå¥åã®è¨å® */
|
---|
221 | #define IF_IN6_RESOLVE_MULTICAST(i,m) \
|
---|
222 | ether_in6_resolve_multicast(i,m)
|
---|
223 | /* ã¤ã³ã¿ãã§ã¼ã¹ã®ãã«ããã£ã¹ãã¢ãã¬ã¹ã¸ã®å¤æ */
|
---|
224 |
|
---|
225 | /*
|
---|
226 | * åæ¹åç
|
---|
227 | §
|
---|
228 | */
|
---|
229 |
|
---|
230 | #ifndef T_IFNET_DEFINED
|
---|
231 |
|
---|
232 | typedef struct t_ifnet T_IFNET;
|
---|
233 |
|
---|
234 | #define T_IFNET_DEFINED
|
---|
235 |
|
---|
236 | #endif /* of #ifndef T_IFNET_DEFINED */
|
---|
237 |
|
---|
238 | #ifndef T_IF_SOFTC_DEFINED
|
---|
239 |
|
---|
240 | typedef struct t_if_softc T_IF_SOFTC;
|
---|
241 |
|
---|
242 | #define T_IF_SOFTC_DEFINED
|
---|
243 |
|
---|
244 | #endif /* of #ifndef T_IF_SOFTC_DEFINED */
|
---|
245 |
|
---|
246 | #ifndef T_IN4_ADDR_DEFINED
|
---|
247 |
|
---|
248 | typedef uint32_t T_IN4_ADDR;
|
---|
249 |
|
---|
250 | #define T_IN4_ADDR_DEFINED
|
---|
251 |
|
---|
252 | #endif /* of #ifndef T_IN4_ADDR_DEFINED */
|
---|
253 |
|
---|
254 | #ifndef T_NET_BUF_DEFINED
|
---|
255 |
|
---|
256 | typedef struct t_net_buf T_NET_BUF;
|
---|
257 |
|
---|
258 | #define T_NET_BUF_DEFINED
|
---|
259 |
|
---|
260 | #endif /* of #ifndef T_NET_BUF_DEFINED */
|
---|
261 |
|
---|
262 | /*
|
---|
263 | * ãããã¯ã¼ã¯ã¤ã³ã¿ãã§ã¼ã¹ã«ä¾åããªãã½ããã¦ã§ã¢æ
|
---|
264 | å ±
|
---|
265 | */
|
---|
266 |
|
---|
267 | #ifdef T_IF_ETHER_NIC_SOFTC
|
---|
268 |
|
---|
269 | struct t_if_softc {
|
---|
270 | T_IF_ADDR ifaddr; /* ãããã¯ã¼ã¯ã¤ã³ã¿ãã§ã¼ã¹ã®ã¢ãã¬ã¹ */
|
---|
271 | uint16_t timer; /* éä¿¡ã¿ã¤ã ã¢ã¦ã */
|
---|
272 | T_IF_ETHER_NIC_SOFTC *sc; /* ãã£ãã¤ã¹ä¾åã®ã½ããã¦ã§ã¢æ
|
---|
273 | å ± */
|
---|
274 | ID semid_txb_ready; /* éä¿¡ã»ããã© */
|
---|
275 | ID semid_rxb_ready; /* åä¿¡ã»ããã© */
|
---|
276 |
|
---|
277 | #ifdef _IP6_CFG
|
---|
278 |
|
---|
279 | T_IF_ADDR maddrs[MAX_IF_MADDR_CNT]; /* ãã«ããã£ã¹ãã¢ãã¬ã¹ãªã¹ã */
|
---|
280 |
|
---|
281 | #endif /* of #ifdef _IP6_CFG */
|
---|
282 | };
|
---|
283 |
|
---|
284 | #endif /* of #ifdef T_IF_ETHER_NIC_SOFTC */
|
---|
285 |
|
---|
286 | /*
|
---|
287 | * å¤æ°
|
---|
288 | */
|
---|
289 |
|
---|
290 | #ifdef ETHER_CFG_COLLECT_ADDR
|
---|
291 |
|
---|
292 | T_ETHER_ADDR ether_collect_addr;
|
---|
293 |
|
---|
294 | #endif /* of #ifdef ETHER_CFG_COLLECT_ADDR */
|
---|
295 |
|
---|
296 | /*
|
---|
297 | * é¢æ°
|
---|
298 | */
|
---|
299 |
|
---|
300 | #ifdef _IP6_CFG
|
---|
301 |
|
---|
302 | /* åæ¹åç
|
---|
303 | § */
|
---|
304 |
|
---|
305 | #ifndef T_IN6_ADDR_DEFINED
|
---|
306 |
|
---|
307 | typedef struct t_in6_addr T_IN6_ADDR;
|
---|
308 |
|
---|
309 | #define T_IN6_ADDR_DEFINED
|
---|
310 |
|
---|
311 | #endif /* of #ifndef T_IN6_ADDR_DEFINED */
|
---|
312 |
|
---|
313 | extern ER ether_in6_resolve_multicast(T_ETHER_ADDR *ifaddr, const T_IN6_ADDR *maddr);
|
---|
314 |
|
---|
315 | #endif /* of #ifdef _IP6_CFG */
|
---|
316 |
|
---|
317 | extern T_IFNET *ether_get_ifnet (void);
|
---|
318 | extern ER ether_output (T_NET_BUF *data, const void *dst, T_IF_ADDR *gw, TMO tmout);
|
---|
319 | extern ER ether_raw_output (T_NET_BUF *data, TMO tmout);
|
---|
320 | extern uint32_t ether_srand (void);
|
---|
321 |
|
---|
322 | #endif /* of #ifdef SUPPORT_ETHER */
|
---|
323 |
|
---|
324 | #endif /* of #ifndef _ETHERNET_H_ */
|
---|