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.c 317 2017-08-03 13:14:26Z coas-nagasima $
|
---|
44 | */
|
---|
45 |
|
---|
46 | /*
|
---|
47 | * Ethernet å¦çã¿ã¹ã¯ã®æ¬ä½
|
---|
48 | */
|
---|
49 |
|
---|
50 | #include <string.h>
|
---|
51 |
|
---|
52 | #ifdef TARGET_KERNEL_ASP
|
---|
53 |
|
---|
54 | #include <kernel.h>
|
---|
55 | #include <sil.h>
|
---|
56 | #include <t_syslog.h>
|
---|
57 | #include "kernel_cfg.h"
|
---|
58 |
|
---|
59 | #endif /* of #ifdef TARGET_KERNEL_ASP */
|
---|
60 |
|
---|
61 | #ifdef TARGET_KERNEL_JSP
|
---|
62 |
|
---|
63 | #include <s_services.h>
|
---|
64 | #include <t_services.h>
|
---|
65 | #include "kernel_id.h"
|
---|
66 |
|
---|
67 | #endif /* of #ifdef TARGET_KERNEL_JSP */
|
---|
68 |
|
---|
69 | #include <tinet_defs.h>
|
---|
70 | #include <tinet_config.h>
|
---|
71 |
|
---|
72 | #include <net/if.h>
|
---|
73 | #include <net/ethernet.h>
|
---|
74 | #include <net/if_llc.h>
|
---|
75 | #include <net/if_arp.h>
|
---|
76 | #include <net/net.h>
|
---|
77 | #include <net/net_endian.h>
|
---|
78 | #include <net/net_var.h>
|
---|
79 | #include <net/net_buf.h>
|
---|
80 | #include <net/net_timer.h>
|
---|
81 | #include <net/net_count.h>
|
---|
82 |
|
---|
83 | #include <netinet/in.h>
|
---|
84 | #include <netinet/in_var.h>
|
---|
85 | #include <netinet/if_ether.h>
|
---|
86 |
|
---|
87 | #include <netinet6/if6_ether.h>
|
---|
88 | #include <netinet6/nd6.h>
|
---|
89 |
|
---|
90 | #include <net/if_var.h>
|
---|
91 |
|
---|
92 | #ifdef SUPPORT_ETHER
|
---|
93 |
|
---|
94 | /*
|
---|
95 | * å¤æ°
|
---|
96 | */
|
---|
97 |
|
---|
98 | #if defined(_IP4_CFG)
|
---|
99 |
|
---|
100 | const uint8_t ether_broad_cast_addr[ETHER_ADDR_LEN] = {
|
---|
101 | UINT_C(0xff), UINT_C(0xff), UINT_C(0xff),
|
---|
102 | UINT_C(0xff), UINT_C(0xff), UINT_C(0xff)
|
---|
103 | };
|
---|
104 |
|
---|
105 | #endif /* of #if defined(_IP4_CFG) */
|
---|
106 |
|
---|
107 | /*
|
---|
108 | * å¤æ°
|
---|
109 | */
|
---|
110 |
|
---|
111 | /* ãããã¯ã¼ã¯ã¤ã³ã¿ãã§ã¼ã¹æ§é ä½ */
|
---|
112 |
|
---|
113 | static T_IFNET ether_ifnet;
|
---|
114 |
|
---|
115 | #ifdef SUPPORT_MIB
|
---|
116 |
|
---|
117 | /* SNMP 㮠管çæ
|
---|
118 | å ±ãã¼ã¹ (MIB) */
|
---|
119 |
|
---|
120 | T_IF_STATS if_stats;
|
---|
121 |
|
---|
122 | #endif /* of #ifdef SUPPORT_MIB */
|
---|
123 |
|
---|
124 | #ifdef ETHER_CFG_802_WARNING
|
---|
125 |
|
---|
126 | /*
|
---|
127 | * é¢æ°
|
---|
128 | */
|
---|
129 |
|
---|
130 | static void ieee_802_input (T_NET_BUF *input);
|
---|
131 |
|
---|
132 | /*
|
---|
133 | * ieee_802_input -- IEEE 802.3 å
|
---|
134 | ¥åå¦ç
|
---|
135 | */
|
---|
136 |
|
---|
137 | static void
|
---|
138 | ieee_802_input (T_NET_BUF *input)
|
---|
139 | {
|
---|
140 | T_8023MAC_HDR *mhdr;
|
---|
141 | T_8022SNAP_HDR *shdr;
|
---|
142 |
|
---|
143 | mhdr = GET_8023MAC_HDR(input);
|
---|
144 | shdr = GET_8022SNAP_HDR(input);
|
---|
145 | syslog(LOG_WARNING, "[ETHER] unexp 802.3 from: %s, proto: 0x%04x.",
|
---|
146 | mac2str(NULL, mhdr->shost), ntohs(*(uint16_t*)&shdr->type));
|
---|
147 | }
|
---|
148 |
|
---|
149 | #endif /* of #ifdef ETHER_CFG_802_WARNING */
|
---|
150 |
|
---|
151 | /*
|
---|
152 | * ether_srand -- ä¹±æ°ãåæå¤ãè¿ãã
|
---|
153 | */
|
---|
154 |
|
---|
155 | uint32_t
|
---|
156 | ether_srand (void)
|
---|
157 | {
|
---|
158 | T_IF_SOFTC *ic;
|
---|
159 | uint32_t rval;
|
---|
160 |
|
---|
161 | ic = IF_ETHER_NIC_GET_SOFTC();
|
---|
162 | rval = (ic->ifaddr.lladdr[2] << 24)
|
---|
163 | + (ic->ifaddr.lladdr[3] << 16)
|
---|
164 | + (ic->ifaddr.lladdr[4] << 8)
|
---|
165 | + (ic->ifaddr.lladdr[5] );
|
---|
166 |
|
---|
167 | #ifdef ETHER_CFG_COLLECT_ADDR
|
---|
168 |
|
---|
169 | rval += (ether_collect_addr.lladdr[2] << 24)
|
---|
170 | + (ether_collect_addr.lladdr[3] << 16)
|
---|
171 | + (ether_collect_addr.lladdr[4] << 8)
|
---|
172 | + (ether_collect_addr.lladdr[5] );
|
---|
173 |
|
---|
174 | #endif /* of #ifdef ETHER_CFG_COLLECT_ADDR */
|
---|
175 |
|
---|
176 | return rval;
|
---|
177 | }
|
---|
178 |
|
---|
179 | /*
|
---|
180 | * ether_get_ifnet -- ãããã¯ã¼ã¯ã¤ã³ã¿ãã§ã¼ã¹æ§é ä½ãè¿ãã
|
---|
181 | */
|
---|
182 |
|
---|
183 | T_IFNET *
|
---|
184 | ether_get_ifnet (void)
|
---|
185 | {
|
---|
186 | return ðer_ifnet;
|
---|
187 | }
|
---|
188 |
|
---|
189 | #if defined(_IP6_CFG)
|
---|
190 |
|
---|
191 | /*
|
---|
192 | * ether_in6_resolve_multicast -- ã¤ã¼ãµãããã®ãã«ããã£ã¹ãã¢ãã¬ã¹ã¸ã®å¤æ
|
---|
193 | */
|
---|
194 |
|
---|
195 | ER
|
---|
196 | ether_in6_resolve_multicast (T_ETHER_ADDR *ifaddr, const T_IN6_ADDR *maddr)
|
---|
197 | {
|
---|
198 | /* ãã«ããã£ã¹ãã¢ãã¬ã¹ããã§ãã¯ããã*/
|
---|
199 | if (!IN6_IS_ADDR_MULTICAST(maddr))
|
---|
200 | return E_PAR;
|
---|
201 |
|
---|
202 | /* ã¤ã¼ãµãããã®ãã«ããã£ã¹ãã¢ãã¬ã¹ã¸ã®å¤æ */
|
---|
203 | ether_map_ipv6_multicast(ifaddr, maddr);
|
---|
204 |
|
---|
205 | return E_OK;
|
---|
206 | }
|
---|
207 |
|
---|
208 | #endif /* of #if defined(_IP6_CFG) */
|
---|
209 |
|
---|
210 | /*
|
---|
211 | * ether_raw_output -- Ethernet ã¤ã³ã¿ãã§ã¼ã¹ã®åºåé¢æ°ãMAC ã¢ãã¬ã¹è§£æ±ºç¡ã
|
---|
212 | */
|
---|
213 |
|
---|
214 | ER
|
---|
215 | ether_raw_output (T_NET_BUF *output, TMO tmout)
|
---|
216 | {
|
---|
217 | ER error = E_OK;
|
---|
218 |
|
---|
219 | /* Ethernet åºåãã¥ã¼ã«æå
|
---|
220 | ¥ããã*/
|
---|
221 | if ((error = tsnd_dtq(DTQ_ETHER_OUTPUT, (intptr_t)output, tmout)) != E_OK) {
|
---|
222 | NET_COUNT_ETHER(net_count_ether.out_err_packets, 1);
|
---|
223 | NET_COUNT_MIB(if_stats.ifOutDiscards, 1);
|
---|
224 |
|
---|
225 | /* IF ã§ãããã¯ã¼ã¯ãããã¡ãéæ¾ããªããã©ã°ããã§ãã¯ããã*/
|
---|
226 | if ((output->flags & NB_FLG_NOREL_IFOUT) == 0) {
|
---|
227 | syscall(rel_net_buf(output));
|
---|
228 | }
|
---|
229 | else {
|
---|
230 | output->flags &= (uint8_t)~NB_FLG_NOREL_IFOUT;
|
---|
231 | }
|
---|
232 | IF_ETHER_NIC_RESET(IF_ETHER_NIC_GET_SOFTC());
|
---|
233 | }
|
---|
234 | return error;
|
---|
235 | }
|
---|
236 |
|
---|
237 | /*
|
---|
238 | * ether_output -- Ethernet ã¤ã³ã¿ãã§ã¼ã¹ã®åºåé¢æ°ãMAC ã¢ãã¬ã¹è§£æ±ºæã
|
---|
239 | */
|
---|
240 |
|
---|
241 | ER
|
---|
242 | ether_output (T_NET_BUF *output, const void *dst, T_IF_ADDR *gw, TMO tmout)
|
---|
243 | {
|
---|
244 | T_IF_SOFTC *ic;
|
---|
245 | ER error = E_OK;
|
---|
246 |
|
---|
247 | /* éä¿¡å
|
---|
248 | MAC ã¢ãã¬ã¹ãè¨å®ããã*/
|
---|
249 | ic = IF_ETHER_NIC_GET_SOFTC();
|
---|
250 | memcpy(GET_ETHER_HDR(output)->shost, ic->ifaddr.lladdr, ETHER_ADDR_LEN);
|
---|
251 |
|
---|
252 | switch(ntohs(GET_ETHER_HDR(output)->type)) {
|
---|
253 |
|
---|
254 | #if defined(_IP4_CFG)
|
---|
255 |
|
---|
256 | case ETHER_TYPE_IP: /* IPv4 */
|
---|
257 | if (arp_resolve(&ic->ifaddr, output, *(uint32_t*)dst)) { /* true ãªãã¢ãã¬ã¹è§£æ±ºæ¸ */
|
---|
258 | error = ether_raw_output(output, tmout);
|
---|
259 | }
|
---|
260 | break;
|
---|
261 |
|
---|
262 | #endif /* of #if defined(_IP4_CFG) */
|
---|
263 |
|
---|
264 | #if defined(_IP6_CFG)
|
---|
265 |
|
---|
266 | case ETHER_TYPE_IPV6: /* IPv6 */
|
---|
267 | error = nd6_storelladdr((T_ETHER_ADDR*)GET_ETHER_HDR(output)->dhost,
|
---|
268 | (const T_IN6_ADDR*)dst, gw);
|
---|
269 | if (error == E_OK)
|
---|
270 | error = ether_raw_output(output, tmout);
|
---|
271 |
|
---|
272 | /* IF ã§ãããã¯ã¼ã¯ãããã¡ãéæ¾ããªããã©ã°ããã§ãã¯ããã*/
|
---|
273 | else if ((output->flags & NB_FLG_NOREL_IFOUT) == 0) {
|
---|
274 | syscall(rel_net_buf(output));
|
---|
275 | }
|
---|
276 | else {
|
---|
277 | output->flags &= (uint8_t)~NB_FLG_NOREL_IFOUT;
|
---|
278 | }
|
---|
279 | break;
|
---|
280 |
|
---|
281 | #endif /* of #if defined(_IP6_CFG) */
|
---|
282 |
|
---|
283 | default:
|
---|
284 | NET_COUNT_MIB(if_stats.ifOutErrors, 1);
|
---|
285 |
|
---|
286 | /* IF ã§ãããã¯ã¼ã¯ãããã¡ãéæ¾ããªããã©ã°ããã§ãã¯ããã*/
|
---|
287 | if ((output->flags & NB_FLG_NOREL_IFOUT) == 0) {
|
---|
288 | syscall(rel_net_buf(output));
|
---|
289 | }
|
---|
290 | else {
|
---|
291 | output->flags &= (uint8_t)~NB_FLG_NOREL_IFOUT;
|
---|
292 | }
|
---|
293 | error = E_PAR;
|
---|
294 | break;
|
---|
295 | }
|
---|
296 |
|
---|
297 | if (error != E_OK)
|
---|
298 | NET_COUNT_ETHER(net_count_ether.out_err_packets, 1);
|
---|
299 | return error;
|
---|
300 | }
|
---|
301 |
|
---|
302 | /*
|
---|
303 | * Ethernet åºåã¿ã¹ã¯
|
---|
304 | */
|
---|
305 |
|
---|
306 | void
|
---|
307 | ether_output_task(intptr_t exinf)
|
---|
308 | {
|
---|
309 | T_IF_SOFTC *ic;
|
---|
310 | T_NET_BUF *output;
|
---|
311 | ID tskid;
|
---|
312 |
|
---|
313 | get_tid(&tskid);
|
---|
314 | syslog(LOG_NOTICE, "[ETHER OUTPUT:%d] started.", tskid);
|
---|
315 |
|
---|
316 | ic = IF_ETHER_NIC_GET_SOFTC();
|
---|
317 |
|
---|
318 | while (true) {
|
---|
319 | while (rcv_dtq(DTQ_ETHER_OUTPUT, (intptr_t*)&output) == E_OK) {
|
---|
320 | NET_COUNT_ETHER(net_count_ether.out_octets, output->len);
|
---|
321 | NET_COUNT_MIB(if_stats.ifOutOctets, output->len + 8);
|
---|
322 | NET_COUNT_ETHER(net_count_ether.out_packets, 1);
|
---|
323 |
|
---|
324 | #ifdef SUPPORT_MIB
|
---|
325 | if ((*(GET_ETHER_HDR(output)->dhost) & ETHER_MCAST_ADDR) == 0) {
|
---|
326 | NET_COUNT_MIB(if_stats.ifOutUcastPkts, 1);
|
---|
327 | }
|
---|
328 | else {
|
---|
329 | NET_COUNT_MIB(if_stats.ifOutNUcastPkts, 1);
|
---|
330 | }
|
---|
331 | #endif /* of #ifdef SUPPORT_MIB */
|
---|
332 |
|
---|
333 | syscall(wai_sem(ic->semid_txb_ready));
|
---|
334 |
|
---|
335 | IF_ETHER_NIC_START(ic, output);
|
---|
336 |
|
---|
337 | #ifndef ETHER_NIC_CFG_RELEASE_NET_BUF
|
---|
338 |
|
---|
339 | if ((output->flags & NB_FLG_NOREL_IFOUT) == 0) {
|
---|
340 | syscall(rel_net_buf(output));
|
---|
341 | }
|
---|
342 | else {
|
---|
343 | output->flags &= (uint8_t)~NB_FLG_NOREL_IFOUT;
|
---|
344 |
|
---|
345 | #ifdef SUPPORT_TCP
|
---|
346 | sig_sem(SEM_TCP_POST_OUTPUT);
|
---|
347 | #endif /* of #ifdef SUPPORT_TCP */
|
---|
348 | }
|
---|
349 |
|
---|
350 | #endif /* of #ifndef ETHER_NIC_CFG_RELEASE_NET_BUF */
|
---|
351 |
|
---|
352 | }
|
---|
353 | }
|
---|
354 | }
|
---|
355 |
|
---|
356 | /*
|
---|
357 | * Ethernet å
|
---|
358 | ¥åã¿ã¹ã¯
|
---|
359 | */
|
---|
360 |
|
---|
361 | void
|
---|
362 | ether_input_task(intptr_t exinf)
|
---|
363 | {
|
---|
364 | T_IF_SOFTC *ic;
|
---|
365 | T_NET_BUF *input;
|
---|
366 | T_ETHER_HDR *eth;
|
---|
367 | ID tskid;
|
---|
368 | uint16_t proto;
|
---|
369 | uint8_t rcount = 0;
|
---|
370 |
|
---|
371 | /* ãããã¯ã¼ã¯ã¤ã³ã¿ãã§ã¼ã¹ç®¡çãåæåããã*/
|
---|
372 | ifinit();
|
---|
373 |
|
---|
374 | /* ã¤ã¼ãµããããããã¯ã¼ã¯ã¤ã³ã¿ãã§ã¼ã¹ç®¡çãåæåããã*/
|
---|
375 |
|
---|
376 | #if defined(_IP4_CFG)
|
---|
377 |
|
---|
378 | ether_ifnet.in4_ifaddr.addr = IPV4_ADDR_LOCAL; /* IPv4 ã¢ãã¬ã¹ */
|
---|
379 | ether_ifnet.in4_ifaddr.mask = IPV4_ADDR_LOCAL_MASK; /* ãµãããããã¹ã¯ */
|
---|
380 |
|
---|
381 | #endif /* of #if defined(_IP4_CFG) */
|
---|
382 |
|
---|
383 | /* NIC ãåæåããã*/
|
---|
384 | ic = IF_ETHER_NIC_GET_SOFTC();
|
---|
385 | IF_ETHER_NIC_PROBE(ic);
|
---|
386 | IF_ETHER_NIC_INIT(ic);
|
---|
387 |
|
---|
388 | /* Ethernet åºåã¿ã¹ã¯ãèµ·åãã */
|
---|
389 | syscall(act_tsk(ETHER_OUTPUT_TASK));
|
---|
390 |
|
---|
391 | /* ãããã¯ã¼ã¯ã¿ã¤ãã¿ã¹ã¯ãèµ·åãã */
|
---|
392 | syscall(act_tsk(NET_TIMER_TASK));
|
---|
393 |
|
---|
394 | get_tid(&tskid);
|
---|
395 |
|
---|
396 | syslog(LOG_NOTICE, "[ETHER INPUT:%2d] started on MAC Addr: %s.",
|
---|
397 | tskid, mac2str(NULL, ic->ifaddr.lladdr));
|
---|
398 |
|
---|
399 | #if defined(_IP4_CFG)
|
---|
400 |
|
---|
401 | /* ARP ãåæåããã*/
|
---|
402 | arp_init();
|
---|
403 |
|
---|
404 | #endif /* of #if defined(_IP4_CFG) */
|
---|
405 |
|
---|
406 | ether_ifnet.ic = ic;
|
---|
407 |
|
---|
408 | /* ä¹±æ°çæãåæåããã*/
|
---|
409 | net_srand(0);
|
---|
410 |
|
---|
411 | while (true) {
|
---|
412 | syscall(wai_sem(ic->semid_rxb_ready));
|
---|
413 | if ((input = IF_ETHER_NIC_READ(ic)) != NULL) {
|
---|
414 | NET_COUNT_ETHER(net_count_ether.in_octets, input->len);
|
---|
415 | NET_COUNT_MIB(if_stats.ifInOctets, input->len + 8);
|
---|
416 | NET_COUNT_ETHER(net_count_ether.in_packets, 1);
|
---|
417 | eth = GET_ETHER_HDR(input);
|
---|
418 | proto = ntohs(eth->type);
|
---|
419 |
|
---|
420 | /* ä¹±æ°çæãåæåããã*/
|
---|
421 | if (rcount == 0) {
|
---|
422 |
|
---|
423 | #ifdef ETHER_CFG_COLLECT_ADDR
|
---|
424 | memcpy(ether_collect_addr.lladdr, eth->shost,
|
---|
425 | sizeof(ether_collect_addr.lladdr));
|
---|
426 | #endif /* of #ifdef ETHER_CFG_COLLECT_ADDR */
|
---|
427 |
|
---|
428 | net_srand(0);
|
---|
429 | }
|
---|
430 | rcount ++;
|
---|
431 |
|
---|
432 |
|
---|
433 | #ifdef SUPPORT_MIB
|
---|
434 | if ((*eth->dhost & ETHER_MCAST_ADDR) == 0) {
|
---|
435 | NET_COUNT_MIB(if_stats.ifInUcastPkts, 1);
|
---|
436 | }
|
---|
437 | else {
|
---|
438 | NET_COUNT_MIB(if_stats.ifInNUcastPkts, 1);
|
---|
439 | }
|
---|
440 | #endif /* of #ifdef SUPPORT_MIB */
|
---|
441 |
|
---|
442 | #if defined(_IP4_CFG) && defined(ETHER_CFG_ACCEPT_ALL)
|
---|
443 |
|
---|
444 | if ((*eth->dhost & ETHER_MCAST_ADDR) && *eth->dhost != 0xff) {
|
---|
445 |
|
---|
446 | #ifdef ETHER_CFG_MCAST_WARNING
|
---|
447 |
|
---|
448 | if (proto <= 1500)
|
---|
449 | proto = ntohs(*(uint16_t*)&(GET_8022SNAP_HDR(input)->type));
|
---|
450 | syslog(LOG_WARNING, "[ETHER] mcast addr from: %s, to: %s, proto: 0x%04x.",
|
---|
451 | mac2str(NULL, eth->shost), mac2str(NULL, eth->dhost), proto);
|
---|
452 |
|
---|
453 | #endif /* of #ifdef ETHER_CFG_MCAST_WARNING */
|
---|
454 |
|
---|
455 | NET_COUNT_ETHER(net_count_ether.in_err_packets, 1);
|
---|
456 | NET_COUNT_MIB(if_stats.ifInErrors, 1);
|
---|
457 | syscall(rel_net_buf(input));
|
---|
458 | continue;
|
---|
459 | }
|
---|
460 |
|
---|
461 | #endif /* of #if defined(_IP4_CFG) && defined(ETHER_CFG_ACCEPT_ALL) */
|
---|
462 |
|
---|
463 | switch(proto) {
|
---|
464 |
|
---|
465 | #if defined(_IP4_CFG)
|
---|
466 |
|
---|
467 | case ETHER_TYPE_IP: /* IP */
|
---|
468 | ip_input(input);
|
---|
469 | break;
|
---|
470 |
|
---|
471 | case ETHER_TYPE_ARP: /* ARP */
|
---|
472 | arp_input(&ic->ifaddr, input);
|
---|
473 | break;
|
---|
474 |
|
---|
475 | #endif /* of #if defined(_IP4_CFG) */
|
---|
476 |
|
---|
477 | #if defined(_IP6_CFG)
|
---|
478 |
|
---|
479 | case ETHER_TYPE_IPV6: /* IPv6 */
|
---|
480 | ip6_input(input);
|
---|
481 | break;
|
---|
482 |
|
---|
483 | #endif /* of #if defined(_IP6_CFG) */
|
---|
484 |
|
---|
485 | default:
|
---|
486 |
|
---|
487 | #ifdef ETHER_CFG_UNEXP_WARNING
|
---|
488 |
|
---|
489 | #ifdef ETHER_CFG_802_WARNING
|
---|
490 |
|
---|
491 | if (proto <= 1500)
|
---|
492 | ieee_802_input(input);
|
---|
493 | else
|
---|
494 | syslog(LOG_NOTICE, "[ETHER] unexp proto from: %s, proto: 0x%04x.",
|
---|
495 | mac2str(NULL, GET_ETHER_HDR(input)->shost), proto);
|
---|
496 |
|
---|
497 | #else /* of #ifdef ETHER_CFG_802_WARNING */
|
---|
498 |
|
---|
499 | syslog(LOG_INFO, "[ETHER] unexp proto from: %s, proto: 0x%04x.",
|
---|
500 | mac2str(NULL, GET_ETHER_HDR(input)->shost), proto);
|
---|
501 |
|
---|
502 | #endif /* of #ifdef ETHER_CFG_802_WARNING */
|
---|
503 |
|
---|
504 | #endif /* of #ifdef ETHER_CFG_UNEXP_WARNING */
|
---|
505 |
|
---|
506 | NET_COUNT_ETHER(net_count_ether.in_err_packets, 1);
|
---|
507 | NET_COUNT_MIB(if_stats.ifUnknownProtos, 1);
|
---|
508 | syscall(rel_net_buf(input));
|
---|
509 | break;
|
---|
510 | }
|
---|
511 | }
|
---|
512 | }
|
---|
513 | }
|
---|
514 |
|
---|
515 | #endif /* of #ifdef SUPPORT_ETHER */
|
---|