[317] | 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 | * 上記著作権者は,以下の (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 _IP4_VAR_H_
|
---|
| 71 | #define _IP4_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(nbuf) ((uint8_t)IP4_VHL_HL(GET_IP4_HDR(nbuf)->vhl) << 2)
|
---|
| 83 | #define GET_IP4_SDU_SIZE(nbuf) (ntohs(GET_IP4_HDR(nbuf)->len) - GET_IP4_HDR_SIZE(nbuf))
|
---|
| 84 | #define GET_IF_IP4_HDR_SIZE(nbuf) (IF_HDR_SIZE + (GET_IP4_HDR_SIZE(nbuf)))
|
---|
| 85 |
|
---|
| 86 | #define SET_IP4_SDU_SIZE(nbuf,slen) (GET_IP4_HDR(nbuf)->len=(uint16_t)htons((slen) + IP4_HDR_SIZE))
|
---|
| 87 |
|
---|
| 88 | /*
|
---|
| 89 | * IP の MSS サイズのネットワークバッファ
|
---|
| 90 | */
|
---|
| 91 |
|
---|
| 92 | typedef struct t_net_buf_ip_mss {
|
---|
| 93 | uint16_t len; /* データの長さ */
|
---|
| 94 | uint8_t idix; /* mpfid のインデックス */
|
---|
| 95 | uint8_t flags; /* フラグ */
|
---|
| 96 | #ifdef IF_ETHER_NIC_NET_BUF_ALIGN
|
---|
| 97 | uint8_t nalign[IF_ETHER_NIC_NET_BUF_ALIGN];
|
---|
| 98 | #endif
|
---|
| 99 | #if CPU_NET_ALIGN == 4 && IF_HDR_ALIGN != 4
|
---|
| 100 | uint8_t halign[4 - IF_HDR_ALIGN];
|
---|
| 101 | #endif
|
---|
| 102 | uint8_t buf[IF_HDR_SIZE + IP4_MSS];
|
---|
| 103 | /* バッファ本体 */
|
---|
| 104 | } T_NET_BUF_IP_MSS;
|
---|
| 105 |
|
---|
| 106 | /*
|
---|
| 107 | * 65536 オクテットサイズのネットワークバッファ
|
---|
| 108 | */
|
---|
| 109 |
|
---|
| 110 | typedef struct t_net_buf4_65536 {
|
---|
| 111 | uint16_t len; /* データの長さ */
|
---|
| 112 | uint8_t idix; /* mpfid のインデックス */
|
---|
| 113 | uint8_t flags; /* フラグ */
|
---|
| 114 | #ifdef IF_ETHER_NIC_NET_BUF_ALIGN
|
---|
| 115 | uint8_t nalign[IF_ETHER_NIC_NET_BUF_ALIGN];
|
---|
| 116 | #endif
|
---|
| 117 | #if CPU_NET_ALIGN == 4 && IF_HDR_ALIGN != 4
|
---|
| 118 | uint8_t halign[4 - IF_HDR_ALIGN];
|
---|
| 119 | #endif
|
---|
| 120 | uint8_t buf[IF_IP4_HDR_SIZE + 65536];
|
---|
| 121 | /* バッファ本体 */
|
---|
| 122 | #if defined(IF_PDU_HDR_PADDING)
|
---|
| 123 | uint8_t padding[IF_PDU_HDR_PADDING];
|
---|
| 124 | #endif /* ヘッダの余分 */
|
---|
| 125 | } T_NET_BUF4_65536;
|
---|
| 126 |
|
---|
| 127 | #ifdef IP4_CFG_FRAGMENT
|
---|
| 128 |
|
---|
| 129 | /*
|
---|
| 130 | * 再構成キュー用 IPv4 ヘッダの定義
|
---|
| 131 | */
|
---|
| 132 |
|
---|
| 133 | typedef struct t_qip4_hdr {
|
---|
| 134 | uint8_t vhl; /* version << 4 | header length >> 2 */
|
---|
| 135 | /* length は 4 octets 単位 */
|
---|
| 136 | uint8_t type; /* type of services */
|
---|
| 137 | uint16_t len; /* total length */
|
---|
| 138 |
|
---|
| 139 | uint16_t id; /* identification */
|
---|
| 140 | uint16_t flg_off; /* fragment flag & offset */
|
---|
| 141 |
|
---|
| 142 | uint8_t ttl; /* time to live */
|
---|
| 143 | uint8_t proto; /* protocol */
|
---|
| 144 | uint16_t sum; /* checksum */
|
---|
| 145 |
|
---|
| 146 | uint32_t src; /* source address */
|
---|
| 147 |
|
---|
| 148 | T_NET_BUF *next; /* 次の IPv4 フラグメント */
|
---|
| 149 | } T_QIP4_HDR;
|
---|
| 150 |
|
---|
| 151 | #define QIP4_HDR_SIZE (sizeof(T_QIP4_HDR))
|
---|
| 152 | #define IF_QIP4_HDR_SIZE (IF_HDR_SIZE + QIP4_HDR_SIZE)
|
---|
| 153 |
|
---|
| 154 | #define GET_QIP4_HDR(nbuf) ((T_QIP4_HDR*)((nbuf)->buf + IF_HDR_SIZE))
|
---|
| 155 | #define GET_QIP4_SDU(nbuf) ((uint8_t*)(nbuf)->buf + GET_IF_QIP4_HDR_SIZE(nbuf))
|
---|
| 156 |
|
---|
| 157 | #define GET_QIP4_HDR_SIZE(iph) ((uint8_t)IP4_VHL_HL((iph)->vhl) << 2)
|
---|
| 158 | #define GET_IF_QIP4_HDR_SIZE(nbuf) (IF_HDR_SIZE + (GET_QIP4_HDR_SIZE(GET_QIP4_HDR(nbuf))))
|
---|
| 159 |
|
---|
| 160 | /*
|
---|
| 161 | * データグラム再構成用ネットワークバッファ
|
---|
| 162 | */
|
---|
| 163 |
|
---|
| 164 | typedef struct t_net_buf4_reassm {
|
---|
| 165 | uint16_t len; /* データの長さ */
|
---|
| 166 | uint8_t idix; /* mpfid のインデックス */
|
---|
| 167 | uint8_t flags; /* フラグ */
|
---|
| 168 | #ifdef IF_ETHER_NIC_NET_BUF_ALIGN
|
---|
| 169 | uint8_t nalign[IF_ETHER_NIC_NET_BUF_ALIGN];
|
---|
| 170 | #endif
|
---|
| 171 | #if CPU_NET_ALIGN == 4 && IF_HDR_ALIGN != 4
|
---|
| 172 | uint8_t align[4 - IF_HDR_ALIGN];
|
---|
| 173 | #endif
|
---|
| 174 | uint8_t buf[IP4_CFG_FRAG_REASSM_SIZE];
|
---|
| 175 | /* バッファ本体 */
|
---|
| 176 | } T_NET_BUF4_REASSM;
|
---|
| 177 |
|
---|
| 178 | #endif /* of #ifdef IP4_CFG_FRAGMENT */
|
---|
| 179 |
|
---|
| 180 | /*
|
---|
| 181 | * TCP の再構成キューにおける IPv4 ヘッダの定義
|
---|
| 182 | */
|
---|
| 183 |
|
---|
| 184 | typedef struct t_ip4_tcp_q_hdr {
|
---|
| 185 | uint8_t vhl; /* version << 4 | header length >> 2 */
|
---|
| 186 | /* length は 4 octets 単位 */
|
---|
| 187 | uint8_t type; /* type of services */
|
---|
| 188 | uint16_t len; /* total length */
|
---|
| 189 |
|
---|
| 190 | uint16_t id; /* identification */
|
---|
| 191 | uint16_t flg_off; /* fragment flag & offset */
|
---|
| 192 |
|
---|
| 193 | uint8_t ttl; /* time to live */
|
---|
| 194 | uint8_t proto; /* protocol */
|
---|
| 195 | uint16_t thoff; /* TCP ヘッダのオフセット */
|
---|
| 196 |
|
---|
| 197 | T_IN4_ADDR src; /* source address */
|
---|
| 198 | T_IN4_ADDR dst; /* destination address */
|
---|
| 199 | } T_IP4_TCP_Q_HDR;
|
---|
| 200 |
|
---|
| 201 | #ifdef SUPPORT_MIB
|
---|
| 202 |
|
---|
| 203 | /*
|
---|
| 204 | * SNMP の 管理情報ベース (MIB)
|
---|
| 205 | */
|
---|
| 206 |
|
---|
| 207 | typedef struct t_ip_stats {
|
---|
| 208 | uint32_t ipInReceives;
|
---|
| 209 | uint32_t ipInHdrErrors;
|
---|
| 210 | uint32_t ipInAddrErrors;
|
---|
| 211 | /* uint32_t ipForwDatagrams;*/
|
---|
| 212 | uint32_t ipInUnknownProtos;
|
---|
| 213 | /* uint32_t ipInDiscards;*/
|
---|
| 214 | uint32_t ipInDelivers;
|
---|
| 215 | uint32_t ipOutRequests;
|
---|
| 216 | uint32_t ipOutDiscards;
|
---|
| 217 | /* uint32_t ipOutNoRoutes;*/
|
---|
| 218 |
|
---|
| 219 | #ifdef IP4_CFG_FRAGMENT
|
---|
| 220 |
|
---|
| 221 | uint32_t ipReasmReqds;
|
---|
| 222 | uint32_t ipReasmOKs;
|
---|
| 223 | uint32_t ipReasmFails;
|
---|
| 224 | uint32_t ipFragOKs;
|
---|
| 225 | uint32_t ipFragFails;
|
---|
| 226 | uint32_t ipFragCreates;
|
---|
| 227 |
|
---|
| 228 | #else /* of #ifdef IP4_CFG_FRAGMENT */
|
---|
| 229 |
|
---|
| 230 | uint32_t ipReasmReqds;
|
---|
| 231 | /* uint32_t ipReasmOKs;*/
|
---|
| 232 | uint32_t ipReasmFails;
|
---|
| 233 | /* uint32_t ipFragOKs;*/
|
---|
| 234 | /* uint32_t ipFragFails;*/
|
---|
| 235 | /* uint32_t ipFragCreates;*/
|
---|
| 236 |
|
---|
| 237 | #endif /* of #ifdef IP4_CFG_FRAGMENT */
|
---|
| 238 |
|
---|
| 239 | } T_IP_STATS;
|
---|
| 240 |
|
---|
| 241 | extern T_IP_STATS ip_stats;
|
---|
| 242 |
|
---|
| 243 | #endif /* of #ifdef SUPPORT_MIB */
|
---|
| 244 |
|
---|
| 245 | /*
|
---|
| 246 | * 関数
|
---|
| 247 | */
|
---|
| 248 |
|
---|
| 249 | extern void ip_frag_timer (void);
|
---|
| 250 | extern void ip_init (void);
|
---|
| 251 | extern ER ip_remove_options (T_NET_BUF *nbuf);
|
---|
| 252 | extern ER ip_output (T_NET_BUF *nbuf, TMO tmout);
|
---|
| 253 | extern void ip_exchg_addr (T_NET_BUF *nbuf);
|
---|
| 254 |
|
---|
| 255 | #endif /* of #ifndef _IP4_VAR_H_ */
|
---|