source: EcnlProtoTool/trunk/asp3_dcre/tinet/netinet/ip_var.h@ 321

Last change on this file since 321 was 321, checked in by coas-nagasima, 7 years ago

文字コードを設定

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-chdr;charset=UTF-8
File size: 9.7 KB
Line 
1/*
2 * TINET (TCP/IP Protocol Stack)
3 *
4 * Copyright (C) 2001-2009 by Dep. of Computer Science and Engineering
5 * Tomakomai National College of Technology, JAPAN
6 *
7 * 上記著作権者は,以下の (1)~(4) の条件か,Free Software Foundation
8 * によって公表されている GNU General Public License の Version 2 に記
9 * 述されている条件を満たす場合に限り,本ソフトウェア(本ソフトウェア
10 * を改変したものを含む.以下同じ)を使用・複製・改変・再配布(以下,
11 * 利用と呼ぶ)することを無償で許諾する.
12 * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
13 * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
14 * スコード中に含まれていること.
15 * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
16 * 用できる形で再配布する場合には,再配布に伴うドキュメント(利用
17 * 者マニュアルなど)に,上記の著作権表示,この利用条件および下記
18 * の無保証規定を掲載すること.
19 * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
20 * 用できない形で再配布する場合には,次の条件を満たすこと.
21 * (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
22 * 作権表示,この利用条件および下記の無保証規定を掲載すること.
23 * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
24 * 害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
25 *
26 * 本ソフトウェアは,無保証で提供されているものである.上記著作権者お
27 * よびTOPPERSプロジェクトは,本ソフトウェアに関して,その適用可能性も
28 * 含めて,いかなる保証も行わない.また,本ソフトウェアの利用により直
29 * 接的または間接的に生じたいかなる損害に関しても,その責任を負わない.
30 *
31 * @(#) $Id$
32 */
33
34/*
35 * Copyright (c) 1982, 1986, 1993
36 * The Regents of the University of California. All rights reserved.
37 *
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
40 * are met:
41 * 1. Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * 2. Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in the
45 * documentation and/or other materials provided with the distribution.
46 * 3. All advertising materials mentioning features or use of this software
47 * must display the following acknowledgement:
48 * This product includes software developed by the University of
49 * California, Berkeley and its contributors.
50 * 4. Neither the name of the University nor the names of its contributors
51 * may be used to endorse or promote products derived from this software
52 * without specific prior written permission.
53 *
54 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
55 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
56 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
57 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
58 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
59 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
60 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
61 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
62 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
63 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64 * SUCH DAMAGE.
65 *
66 * @(#)ip_var.h 8.2 (Berkeley) 1/9/95
67 * $FreeBSD: src/sys/netinet/ip_var.h,v 1.45.2.1 1999/08/29 16:29:51 peter Exp $
68 */
69
70#ifndef _IP_VAR_H_
71#define _IP_VAR_H_
72
73/*
74 * IPv4 ヘッダ・ペイロードアクセスマクロ
75 */
76
77#define IF_IP4_HDR_SIZE (IF_HDR_SIZE + IP4_HDR_SIZE)
78
79#define GET_IP4_HDR(nbuf) ((T_IP4_HDR*)((nbuf)->buf + IF_HDR_SIZE))
80#define GET_IP4_SDU(nbuf) ((uint8_t*)((nbuf)->buf) + GET_IF_IP4_HDR_SIZE(nbuf))
81
82#define GET_IP4_HDR_SIZE(iph) ((uint8_t)IP4_VHL_HL((iph)->vhl) << 2)
83#define GET_IP4_SDU_SIZE(iph) (ntohs((iph)->len) - GET_IP4_HDR_SIZE(iph))
84#define GET_IF_IP4_HDR_SIZE(nbuf) (IF_HDR_SIZE + (GET_IP4_HDR_SIZE(GET_IP4_HDR(nbuf))))
85
86#define SET_IP4_SDU_SIZE(iph,slen) ((iph)->len=(uint16_t)htons((slen) + IP4_HDR_SIZE))
87
88/*
89 * IPv4 と IPv6 をコンパイル時に選択するためのマクロ
90 */
91
92#if defined(SUPPORT_INET4)
93
94#define T_TCP_IP_Q_HDR T_TCP_IP4_Q_HDR
95
96#define IF_IP_HDR_SIZE IF_IP4_HDR_SIZE
97
98#define GET_IP_HDR(nbuf) GET_IP4_HDR(nbuf)
99#define GET_IP_SDU(nbuf) GET_IP4_SDU(nbuf)
100
101#define GET_IP_HDR_SIZE(iph) GET_IP4_HDR_SIZE(iph)
102#define GET_IP_SDU_SIZE(iph) GET_IP4_SDU_SIZE(iph)
103#define GET_IF_IP_HDR_SIZE(nbuf) GET_IF_IP4_HDR_SIZE(nbuf)
104
105#define SET_IP_SDU_SIZE(iph,len) SET_IP4_SDU_SIZE(iph,len)
106
107#define IP_OUTPUT(nbuf,tmout) ip_output(nbuf,tmout)
108#define IP_INIT() ip_init()
109#define IP_REMOVE_OPTIONS(nbuf) ip_remove_options(nbuf)
110
111#endif /* of #if defined(SUPPORT_INET4) */
112
113/*
114 * IP の MSS サイズのネットワークバッファ
115 */
116
117typedef struct t_net_buf_ip_mss {
118 uint16_t len; /* データの長さ */
119 uint8_t idix; /* mpfid のインデックス */
120 uint8_t flags; /* フラグ */
121#ifdef IF_ETHER_NIC_NET_BUF_ALIGN
122 uint8_t nalign[IF_ETHER_NIC_NET_BUF_ALIGN];
123#endif
124#if CPU_NET_ALIGN == 4 && IF_HDR_ALIGN != 4
125 uint8_t halign[4 - IF_HDR_ALIGN];
126#endif
127 uint8_t buf[IF_HDR_SIZE + IP4_MSS];
128 /* バッファ本体 */
129 } T_NET_BUF_IP_MSS;
130
131/*
132 * 65536 オクテットサイズのネットワークバッファ
133 */
134
135typedef struct t_net_buf4_65536 {
136 uint16_t len; /* データの長さ */
137 uint8_t idix; /* mpfid のインデックス */
138 uint8_t flags; /* フラグ */
139#ifdef IF_ETHER_NIC_NET_BUF_ALIGN
140 uint8_t nalign[IF_ETHER_NIC_NET_BUF_ALIGN];
141#endif
142#if CPU_NET_ALIGN == 4 && IF_HDR_ALIGN != 4
143 uint8_t halign[4 - IF_HDR_ALIGN];
144#endif
145 uint8_t buf[IF_IP4_HDR_SIZE + 65536];
146 /* バッファ本体 */
147#if defined(IF_PDU_HDR_PADDING)
148 uint8_t padding[IF_PDU_HDR_PADDING];
149#endif /* ヘッダの余分 */
150 } T_NET_BUF4_65536;
151
152#ifdef IP4_CFG_FRAGMENT
153
154/*
155 * 再構成キュー用 IPv4 ヘッダの定義
156 */
157
158typedef struct t_qip4_hdr {
159 uint8_t vhl; /* version << 4 | header length >> 2 */
160 /* length は 4 octets 単位 */
161 uint8_t type; /* type of services */
162 uint16_t len; /* total length */
163
164 uint16_t id; /* identification */
165 uint16_t flg_off; /* fragment flag & offset */
166
167 uint8_t ttl; /* time to live */
168 uint8_t proto; /* protocol */
169 uint16_t sum; /* checksum */
170
171 uint32_t src; /* source address */
172
173 T_NET_BUF *next; /* 次の IPv4 フラグメント */
174 } __attribute__((packed, aligned(2)))T_QIP4_HDR;
175
176#define QIP4_HDR_SIZE (sizeof(T_QIP4_HDR))
177#define IF_QIP4_HDR_SIZE (IF_HDR_SIZE + QIP4_HDR_SIZE)
178
179#define GET_QIP4_HDR(nbuf) ((T_QIP4_HDR*)((nbuf)->buf + IF_HDR_SIZE))
180#define GET_QIP4_SDU(nbuf) ((uint8_t*)(nbuf)->buf + GET_IF_QIP4_HDR_SIZE(nbuf))
181
182#define GET_QIP4_HDR_SIZE(iph) ((uint8_t)IP4_VHL_HL((iph)->vhl) << 2)
183#define GET_IF_QIP4_HDR_SIZE(nbuf) (IF_HDR_SIZE + (GET_QIP4_HDR_SIZE(GET_QIP4_HDR(nbuf))))
184
185/*
186 * データグラム再構成用ネットワークバッファ
187 */
188
189typedef struct t_net_buf4_reassm {
190 uint16_t len; /* データの長さ */
191 uint8_t idix; /* mpfid のインデックス */
192 uint8_t flags; /* フラグ */
193#ifdef IF_ETHER_NIC_NET_BUF_ALIGN
194 uint8_t nalign[IF_ETHER_NIC_NET_BUF_ALIGN];
195#endif
196#if CPU_NET_ALIGN == 4 && IF_HDR_ALIGN != 4
197 uint8_t align[4 - IF_HDR_ALIGN];
198#endif
199 uint8_t buf[IP4_CFG_FRAG_REASSM_SIZE];
200 /* バッファ本体 */
201 } T_NET_BUF4_REASSM;
202
203#endif /* of #ifdef IP4_CFG_FRAGMENT */
204
205/*
206 * TCP の再構成キューにおける IPv4 ヘッダの定義
207 */
208
209typedef struct t_tcp_ip4_q_hdr {
210 uint8_t vhl; /* version << 4 | header length >> 2 */
211 /* length は 4 octets 単位 */
212 uint8_t type; /* type of services */
213 uint16_t len; /* total length */
214
215 uint16_t id; /* identification */
216 uint16_t flg_off; /* fragment flag & offset */
217
218 uint8_t ttl; /* time to live */
219 uint8_t proto; /* protocol */
220 uint16_t thoff; /* TCP ヘッダのオフセット */
221
222 T_IN4_ADDR src; /* source address */
223 T_IN4_ADDR dst; /* destination address */
224 } __attribute__((packed, aligned(2)))T_TCP_IP4_Q_HDR;
225
226#ifdef SUPPORT_MIB
227
228/*
229 * SNMP の 管理情報ベース (MIB)
230 */
231
232typedef struct t_ip_stats {
233 uint32_t ipInReceives;
234 uint32_t ipInHdrErrors;
235 uint32_t ipInAddrErrors;
236/* uint32_t ipForwDatagrams;*/
237 uint32_t ipInUnknownProtos;
238/* uint32_t ipInDiscards;*/
239 uint32_t ipInDelivers;
240 uint32_t ipOutRequests;
241 uint32_t ipOutDiscards;
242/* uint32_t ipOutNoRoutes;*/
243
244#ifdef IP4_CFG_FRAGMENT
245
246 uint32_t ipReasmReqds;
247 uint32_t ipReasmOKs;
248 uint32_t ipReasmFails;
249 uint32_t ipFragOKs;
250 uint32_t ipFragFails;
251 uint32_t ipFragCreates;
252
253#else /* of #ifdef IP4_CFG_FRAGMENT */
254
255 uint32_t ipReasmReqds;
256/* uint32_t ipReasmOKs;*/
257 uint32_t ipReasmFails;
258/* uint32_t ipFragOKs;*/
259/* uint32_t ipFragFails;*/
260/* uint32_t ipFragCreates;*/
261
262#endif /* of #ifdef IP4_CFG_FRAGMENT */
263
264} T_IP_STATS;
265
266extern T_IP_STATS ip_stats;
267
268#endif /* of #ifdef SUPPORT_MIB */
269
270/*
271 * 関数
272 */
273
274extern void ip_frag_timer (void);
275extern void ip_init (void);
276extern ER ip_remove_options (T_NET_BUF *nbuf);
277extern ER ip_output (T_NET_BUF *nbuf, TMO tmout);
278
279#endif /* of #ifndef _IP_VAR_H_ */
Note: See TracBrowser for help on using the repository browser.