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$
|
---|
44 | */
|
---|
45 |
|
---|
46 | /*
|
---|
47 | * Copyright (c) 1982, 1986, 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 | * @(#)ip_var.h 8.2 (Berkeley) 1/9/95
|
---|
79 | * $FreeBSD: src/sys/netinet/ip_var.h,v 1.45.2.1 1999/08/29 16:29:51 peter Exp $
|
---|
80 | */
|
---|
81 |
|
---|
82 | #ifndef _IP4_VAR_H_
|
---|
83 | #define _IP4_VAR_H_
|
---|
84 |
|
---|
85 | /*
|
---|
86 | * IPv4 ãããã»ãã¤ãã¼ãã¢ã¯ã»ã¹ãã¯ã
|
---|
87 | */
|
---|
88 |
|
---|
89 | #define IF_IP4_HDR_SIZE (IF_HDR_SIZE + IP4_HDR_SIZE)
|
---|
90 |
|
---|
91 | #define GET_IP4_HDR(nbuf) ((T_IP4_HDR*)((nbuf)->buf + IF_HDR_SIZE))
|
---|
92 | #define GET_IP4_SDU(nbuf) ((uint8_t*)((nbuf)->buf) + GET_IF_IP4_HDR_SIZE(nbuf))
|
---|
93 |
|
---|
94 | #define GET_IP4_HDR_SIZE(nbuf) ((uint8_t)IP4_VHL_HL(GET_IP4_HDR(nbuf)->vhl) << 2)
|
---|
95 | #define GET_IP4_SDU_SIZE(nbuf) (ntohs(GET_IP4_HDR(nbuf)->len) - GET_IP4_HDR_SIZE(nbuf))
|
---|
96 | #define GET_IF_IP4_HDR_SIZE(nbuf) (IF_HDR_SIZE + (GET_IP4_HDR_SIZE(nbuf)))
|
---|
97 |
|
---|
98 | #define SET_IP4_SDU_SIZE(nbuf,slen) (GET_IP4_HDR(nbuf)->len=(uint16_t)htons((slen) + IP4_HDR_SIZE))
|
---|
99 |
|
---|
100 | /*
|
---|
101 | * IP ã® MSS ãµã¤ãºã®ãããã¯ã¼ã¯ãããã¡
|
---|
102 | */
|
---|
103 |
|
---|
104 | typedef struct t_net_buf_ip_mss {
|
---|
105 | uint16_t len; /* ãã¼ã¿ã®é·ã */
|
---|
106 | uint8_t idix; /* mpfid ã®ã¤ã³ããã¯ã¹ */
|
---|
107 | uint8_t flags; /* ãã©ã° */
|
---|
108 | #ifdef IF_ETHER_MULTI_NIC
|
---|
109 | uint8_t conn_pos;
|
---|
110 | #endif
|
---|
111 | #ifdef IF_ETHER_NIC_NET_BUF_ALIGN
|
---|
112 | uint8_t nalign[IF_ETHER_NIC_NET_BUF_ALIGN];
|
---|
113 | #endif
|
---|
114 | #if CPU_NET_ALIGN == 4 && IF_HDR_ALIGN != 4
|
---|
115 | uint8_t halign[4 - IF_HDR_ALIGN];
|
---|
116 | #endif
|
---|
117 | uint8_t buf[IF_HDR_SIZE + IP4_MSS];
|
---|
118 | /* ãããã¡æ¬ä½ */
|
---|
119 | } T_NET_BUF_IP_MSS;
|
---|
120 |
|
---|
121 | /*
|
---|
122 | * 65536 ãªã¯ããããµã¤ãºã®ãããã¯ã¼ã¯ãããã¡
|
---|
123 | */
|
---|
124 |
|
---|
125 | typedef struct t_net_buf4_65536 {
|
---|
126 | uint16_t len; /* ãã¼ã¿ã®é·ã */
|
---|
127 | uint8_t idix; /* mpfid ã®ã¤ã³ããã¯ã¹ */
|
---|
128 | uint8_t flags; /* ãã©ã° */
|
---|
129 | #ifdef IF_ETHER_MULTI_NIC
|
---|
130 | uint8_t conn_pos;
|
---|
131 | #endif
|
---|
132 | #ifdef IF_ETHER_NIC_NET_BUF_ALIGN
|
---|
133 | uint8_t nalign[IF_ETHER_NIC_NET_BUF_ALIGN];
|
---|
134 | #endif
|
---|
135 | #if CPU_NET_ALIGN == 4 && IF_HDR_ALIGN != 4
|
---|
136 | uint8_t halign[4 - IF_HDR_ALIGN];
|
---|
137 | #endif
|
---|
138 | uint8_t buf[IF_IP4_HDR_SIZE + 65536];
|
---|
139 | /* ãããã¡æ¬ä½ */
|
---|
140 | #if defined(IF_PDU_HDR_PADDING)
|
---|
141 | uint8_t padding[IF_PDU_HDR_PADDING];
|
---|
142 | #endif /* ãããã®ä½å */
|
---|
143 | } T_NET_BUF4_65536;
|
---|
144 |
|
---|
145 | #ifdef IP4_CFG_FRAGMENT
|
---|
146 |
|
---|
147 | /*
|
---|
148 | * åæ§æãã¥ã¼ç¨ IPv4 ãããã®å®ç¾©
|
---|
149 | */
|
---|
150 |
|
---|
151 | typedef struct t_qip4_hdr {
|
---|
152 | uint8_t vhl; /* version << 4 | header length >> 2 */
|
---|
153 | /* length 㯠4 octets åä½ */
|
---|
154 | uint8_t type; /* type of services */
|
---|
155 | uint16_t len; /* total length */
|
---|
156 |
|
---|
157 | uint16_t id; /* identification */
|
---|
158 | uint16_t flg_off; /* fragment flag & offset */
|
---|
159 |
|
---|
160 | uint8_t ttl; /* time to live */
|
---|
161 | uint8_t proto; /* protocol */
|
---|
162 | uint16_t sum; /* checksum */
|
---|
163 |
|
---|
164 | uint32_t src; /* source address */
|
---|
165 |
|
---|
166 | T_NET_BUF *next; /* 次㮠IPv4 ãã©ã°ã¡ã³ã */
|
---|
167 | } __attribute__((packed, aligned(2))) T_QIP4_HDR;
|
---|
168 |
|
---|
169 | #define QIP4_HDR_SIZE (sizeof(T_QIP4_HDR))
|
---|
170 | #define IF_QIP4_HDR_SIZE (IF_HDR_SIZE + QIP4_HDR_SIZE)
|
---|
171 |
|
---|
172 | #define GET_QIP4_HDR(nbuf) ((T_QIP4_HDR*)((nbuf)->buf + IF_HDR_SIZE))
|
---|
173 | #define GET_QIP4_SDU(nbuf) ((uint8_t*)(nbuf)->buf + GET_IF_QIP4_HDR_SIZE(nbuf))
|
---|
174 |
|
---|
175 | #define GET_QIP4_HDR_SIZE(iph) ((uint8_t)IP4_VHL_HL((iph)->vhl) << 2)
|
---|
176 | #define GET_IF_QIP4_HDR_SIZE(nbuf) (IF_HDR_SIZE + (GET_QIP4_HDR_SIZE(GET_QIP4_HDR(nbuf))))
|
---|
177 |
|
---|
178 | /*
|
---|
179 | * ãã¼ã¿ã°ã©ã åæ§æç¨ãããã¯ã¼ã¯ãããã¡
|
---|
180 | */
|
---|
181 |
|
---|
182 | typedef struct t_net_buf4_reassm {
|
---|
183 | uint16_t len; /* ãã¼ã¿ã®é·ã */
|
---|
184 | uint8_t idix; /* mpfid ã®ã¤ã³ããã¯ã¹ */
|
---|
185 | uint8_t flags; /* ãã©ã° */
|
---|
186 | #ifdef IF_ETHER_MULTI_NIC
|
---|
187 | uint8_t conn_pos;
|
---|
188 | #endif
|
---|
189 | #ifdef IF_ETHER_NIC_NET_BUF_ALIGN
|
---|
190 | uint8_t nalign[IF_ETHER_NIC_NET_BUF_ALIGN];
|
---|
191 | #endif
|
---|
192 | #if CPU_NET_ALIGN == 4 && IF_HDR_ALIGN != 4
|
---|
193 | uint8_t align[4 - IF_HDR_ALIGN];
|
---|
194 | #endif
|
---|
195 | uint8_t buf[IP4_CFG_FRAG_REASSM_SIZE];
|
---|
196 | /* ãããã¡æ¬ä½ */
|
---|
197 | } __attribute__((packed, aligned(2))) T_NET_BUF4_REASSM;
|
---|
198 |
|
---|
199 | #endif /* of #ifdef IP4_CFG_FRAGMENT */
|
---|
200 |
|
---|
201 | /*
|
---|
202 | * TCP ã®åæ§æãã¥ã¼ã«ããã IPv4 ãããã®å®ç¾©
|
---|
203 | */
|
---|
204 |
|
---|
205 | typedef struct t_ip4_tcp_q_hdr {
|
---|
206 | uint8_t vhl; /* version << 4 | header length >> 2 */
|
---|
207 | /* length 㯠4 octets åä½ */
|
---|
208 | uint8_t type; /* type of services */
|
---|
209 | uint16_t len; /* total length */
|
---|
210 |
|
---|
211 | uint16_t id; /* identification */
|
---|
212 | uint16_t flg_off; /* fragment flag & offset */
|
---|
213 |
|
---|
214 | uint8_t ttl; /* time to live */
|
---|
215 | uint8_t proto; /* protocol */
|
---|
216 | uint16_t thoff; /* TCP ãããã®ãªãã»ãã */
|
---|
217 |
|
---|
218 | T_IN4_ADDR src; /* source address */
|
---|
219 | T_IN4_ADDR dst; /* destination address */
|
---|
220 | } __attribute__((packed, aligned(2))) T_IP4_TCP_Q_HDR;
|
---|
221 |
|
---|
222 | #ifdef SUPPORT_MIB
|
---|
223 |
|
---|
224 | /*
|
---|
225 | * SNMP 㮠管çæ
|
---|
226 | å ±ãã¼ã¹ (MIB)
|
---|
227 | */
|
---|
228 |
|
---|
229 | typedef struct t_ip_stats {
|
---|
230 | uint32_t ipInReceives;
|
---|
231 | uint32_t ipInHdrErrors;
|
---|
232 | uint32_t ipInAddrErrors;
|
---|
233 | /* uint32_t ipForwDatagrams;*/
|
---|
234 | uint32_t ipInUnknownProtos;
|
---|
235 | /* uint32_t ipInDiscards;*/
|
---|
236 | uint32_t ipInDelivers;
|
---|
237 | uint32_t ipOutRequests;
|
---|
238 | uint32_t ipOutDiscards;
|
---|
239 | /* uint32_t ipOutNoRoutes;*/
|
---|
240 |
|
---|
241 | #ifdef IP4_CFG_FRAGMENT
|
---|
242 |
|
---|
243 | uint32_t ipReasmReqds;
|
---|
244 | uint32_t ipReasmOKs;
|
---|
245 | uint32_t ipReasmFails;
|
---|
246 | uint32_t ipFragOKs;
|
---|
247 | uint32_t ipFragFails;
|
---|
248 | uint32_t ipFragCreates;
|
---|
249 |
|
---|
250 | #else /* of #ifdef IP4_CFG_FRAGMENT */
|
---|
251 |
|
---|
252 | uint32_t ipReasmReqds;
|
---|
253 | /* uint32_t ipReasmOKs;*/
|
---|
254 | uint32_t ipReasmFails;
|
---|
255 | /* uint32_t ipFragOKs;*/
|
---|
256 | /* uint32_t ipFragFails;*/
|
---|
257 | /* uint32_t ipFragCreates;*/
|
---|
258 |
|
---|
259 | #endif /* of #ifdef IP4_CFG_FRAGMENT */
|
---|
260 |
|
---|
261 | } T_IP_STATS;
|
---|
262 |
|
---|
263 | extern T_IP_STATS ip_stats;
|
---|
264 |
|
---|
265 | #endif /* of #ifdef SUPPORT_MIB */
|
---|
266 |
|
---|
267 | /*
|
---|
268 | * é¢æ°
|
---|
269 | */
|
---|
270 |
|
---|
271 | extern void ip_frag_timer (void);
|
---|
272 | extern void ip_init (void);
|
---|
273 | extern ER ip_remove_options (T_NET_BUF *nbuf);
|
---|
274 | extern ER ip_output (T_NET_BUF *nbuf, TMO tmout);
|
---|
275 | extern void ip_exchg_addr (T_NET_BUF *nbuf);
|
---|
276 |
|
---|
277 | #endif /* of #ifndef _IP4_VAR_H_ */
|
---|