[398] | 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, 1994, 1995
|
---|
| 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 | * @(#)tcp_var.h 8.4 (Berkeley) 5/24/95
|
---|
| 67 | * $FreeBSD: src/sys/netinet/tcp_var.h,v 1.49.2.1 1999/08/29 16:29:57 peter Exp $
|
---|
| 68 | */
|
---|
| 69 |
|
---|
| 70 | #ifndef _TCP_VAR_H_
|
---|
| 71 | #define _TCP_VAR_H_
|
---|
| 72 |
|
---|
| 73 | /*
|
---|
| 74 | * TCP ヘッダ・ペイロードアクセスマクロ
|
---|
| 75 | */
|
---|
| 76 |
|
---|
| 77 | #define GET_TCP_HDR(nbuf,thoff) ((T_TCP_HDR*)((uint8_t*)((nbuf)->buf) + thoff))
|
---|
| 78 | #define GET_TCP_OPT(nbuf,thoff) ((uint8_t*)((nbuf)->buf) + thoff + TCP_HDR_SIZE)
|
---|
| 79 | #define GET_TCP_SDU(nbuf,thoff) ((uint8_t*)((nbuf)->buf) + thoff + GET_TCP_HDR_SIZE(nbuf,thoff))
|
---|
| 80 |
|
---|
| 81 | #define GET_TCP_HDR_OFFSET(nbuf) (GET_IF_IP_HDR_SIZE(nbuf))
|
---|
| 82 |
|
---|
| 83 | #define GET_TCP_HDR_SIZE(nbuf,thoff) (TCP_HDR_LEN(GET_TCP_HDR(nbuf,thoff)->doff))
|
---|
| 84 |
|
---|
| 85 | #define GET_IP_TCP_HDR_SIZE(nbuf,thoff) (GET_IP_HDR_SIZE(nbuf) + GET_TCP_HDR_SIZE(nbuf,thoff))
|
---|
| 86 | #define GET_IF_IP_TCP_HDR_SIZE(nbuf,thoff) \
|
---|
| 87 | (IF_HDR_SIZE + GET_IP_TCP_HDR_SIZE(nbuf,thoff))
|
---|
| 88 | #define IF_IP_TCP_HDR_SIZE(nbuf) (IF_IP_HDR_SIZE(nbuf) + TCP_HDR_SIZE)
|
---|
| 89 | #define IF_IP_TCP_HDR_OFFSET(nbuf) (IF_IP_HDR_SIZE(nbuf))
|
---|
| 90 | #define IF_IP_TCP_NET_HDR_SIZE(addr) (IF_IP_NET_HDR_SIZE(addr) + TCP_HDR_SIZE)
|
---|
| 91 | #define IF_IP_TCP_NET_HDR_OFFSET(addr) (IF_IP_NET_HDR_SIZE(addr))
|
---|
| 92 |
|
---|
| 93 | /*
|
---|
| 94 | * TINET 1.1 との互換性のための定義
|
---|
| 95 | */
|
---|
| 96 |
|
---|
| 97 | #if !defined(_IP6_CFG) && defined(_IP4_CFG)
|
---|
| 98 |
|
---|
| 99 | #define IP4_TCP_HDR_SIZE IP_TCP_HDR_SIZE
|
---|
| 100 | #define IF_IP4_TCP_HDR_SIZE IF_IP_TCP_HDR_SIZE
|
---|
| 101 | #define GET_IP4_TCP_HDR_SIZE(nbuf) GET_IP_TCP_HDR_SIZE1(nbuf)
|
---|
| 102 | #define GET_IF_IP4_TCP_HDR_SIZE(nbuf) GET_IF_IP_TCP_HDR_SIZE1(nbuf)
|
---|
| 103 |
|
---|
| 104 | #endif /* of #if !defined(_IP6_CFG) && defined(_IP4_CFG) */
|
---|
| 105 |
|
---|
| 106 | /*
|
---|
| 107 | * TINET 1.3 との互換性のための定義
|
---|
| 108 | */
|
---|
| 109 |
|
---|
| 110 | #define TMIN_TCP_CREPID TMIN_TCP_REPID
|
---|
| 111 | #define TNUM_TCP_CREPID TNUM_TCP_REPID
|
---|
| 112 |
|
---|
| 113 | #define TMIN_TCP_CCEPID TMIN_TCP_CEPID
|
---|
| 114 | #define TNUM_TCP_CCEPID TNUM_TCP_CEPID
|
---|
| 115 |
|
---|
| 116 | /*
|
---|
| 117 | * コールバック関数の定義
|
---|
| 118 | */
|
---|
| 119 |
|
---|
| 120 | typedef ER (*t_tcp_callback)(ID cepid, FN fncd, void *p_parblk);
|
---|
| 121 |
|
---|
| 122 | /*
|
---|
| 123 | * TCP で使用する変数の型の定義
|
---|
| 124 | */
|
---|
| 125 |
|
---|
| 126 | typedef uint32_t T_TCP_SEQ;
|
---|
| 127 | typedef uint16_t T_TCP_SEG;
|
---|
| 128 | typedef uint16_t T_TCP_WND;
|
---|
| 129 | typedef int16_t T_TCP_TIME;
|
---|
| 130 |
|
---|
| 131 | /*
|
---|
| 132 | * TCP タイマ変数
|
---|
| 133 | */
|
---|
| 134 |
|
---|
| 135 | #define NUM_TCP_TIMERS 4 /* TCP のタイマ数 */
|
---|
| 136 |
|
---|
| 137 | /*
|
---|
| 138 | * TCP 受付口
|
---|
| 139 | */
|
---|
| 140 |
|
---|
| 141 | /* IPv6 用 TCP 受付口 */
|
---|
| 142 |
|
---|
| 143 | typedef struct t_tcp6_rep {
|
---|
| 144 |
|
---|
| 145 | /*
|
---|
| 146 | * ITRON TCP/IP API、TCP 受付口と同じメンバ
|
---|
| 147 | */
|
---|
| 148 | ATR repatr; /* 受付口属性 */
|
---|
| 149 | T_IPV6EP myaddr; /* 自分のアドレス */
|
---|
| 150 |
|
---|
| 151 | #ifdef TCP_CFG_EXTENTIONS
|
---|
| 152 | uint16_t flags; /* 受付口フラグ */
|
---|
| 153 | ID semid_lock; /* 受付口ロック */
|
---|
| 154 | #endif /* of #ifdef TCP_CFG_EXTENTIONS */
|
---|
| 155 |
|
---|
| 156 | } T_TCP6_REP;
|
---|
| 157 |
|
---|
| 158 | /* IPv4 用 TCP 受付口 */
|
---|
| 159 |
|
---|
| 160 | typedef struct t_tcp4_rep {
|
---|
| 161 |
|
---|
| 162 | /*
|
---|
| 163 | * ITRON TCP/IP API、TCP 受付口と同じメンバ
|
---|
| 164 | */
|
---|
| 165 | ATR repatr; /* 受付口属性 */
|
---|
| 166 | T_IPV4EP myaddr; /* 自分のアドレス */
|
---|
| 167 |
|
---|
| 168 | #ifdef TCP_CFG_EXTENTIONS
|
---|
| 169 | uint16_t flags; /* 受付口フラグ */
|
---|
| 170 | ID semid_lock; /* 受付口ロック */
|
---|
| 171 | #endif /* of #ifdef TCP_CFG_EXTENTIONS */
|
---|
| 172 |
|
---|
| 173 | } T_TCP4_REP;
|
---|
| 174 |
|
---|
| 175 | #if defined(_IP6_CFG)
|
---|
| 176 |
|
---|
| 177 | #define T_TCP_REP T_TCP6_REP
|
---|
| 178 |
|
---|
| 179 | #else /* of #if defined(_IP6_CFG) */
|
---|
| 180 |
|
---|
| 181 | #if defined(_IP4_CFG)
|
---|
| 182 |
|
---|
| 183 | #define T_TCP_REP T_TCP4_REP
|
---|
| 184 |
|
---|
| 185 | #endif /* of #if defined(_IP4_CFG) */
|
---|
| 186 |
|
---|
| 187 | #endif /* of #if defined(_IP6_CFG) */
|
---|
| 188 |
|
---|
| 189 | #define T_TCP_REP_DEFINED
|
---|
| 190 |
|
---|
| 191 | /*
|
---|
| 192 | * 受付口フラグ
|
---|
| 193 | */
|
---|
| 194 |
|
---|
| 195 | #define TCP_REP_FLG_DYNAMIC UINT_C(0x0400) /* 動的生成・削除可能受付口。 */
|
---|
| 196 | #define TCP_REP_FLG_VALID UINT_C(0x0800) /* 生成済みで有効な受付口。 */
|
---|
| 197 |
|
---|
| 198 | /*
|
---|
| 199 | * TCP 通信端点
|
---|
| 200 | */
|
---|
| 201 |
|
---|
| 202 | #ifndef T_NET_BUF_DEFINED
|
---|
| 203 |
|
---|
| 204 | typedef struct t_net_buf T_NET_BUF;
|
---|
| 205 |
|
---|
| 206 | #define T_NET_BUF_DEFINED
|
---|
| 207 |
|
---|
| 208 | #endif /* of #ifndef T_NET_BUF_DEFINED */
|
---|
| 209 |
|
---|
| 210 | typedef struct t_tcp_cep {
|
---|
| 211 |
|
---|
| 212 | /*
|
---|
| 213 | * ITRON TCP/IP API、TCP 通信端点と同じメンバ
|
---|
| 214 | */
|
---|
| 215 | ATR cepatr; /* 通信端点属性 */
|
---|
| 216 | void *sbuf; /* 送信用ウィンドバッファ */
|
---|
| 217 | int_t sbufsz; /* 送信用ウィンドバッファサイズ */
|
---|
| 218 | void *rbuf; /* 受信用ウィンドバッファ */
|
---|
| 219 | int_t rbufsz; /* 受信用ウィンドバッファサイズ */
|
---|
| 220 | t_tcp_callback callback; /* コールバック関数 */
|
---|
| 221 |
|
---|
| 222 | /*
|
---|
| 223 | * TINET 独自のメンバ
|
---|
| 224 | */
|
---|
| 225 | uint32_t flags; /* 通信端点フラグ */
|
---|
| 226 | ID semid_lock; /* 通信端点ロック */
|
---|
| 227 | ID est_flgid; /* コネクション状態イベントフラグ */
|
---|
| 228 | ID snd_flgid; /* 送信イベントフラグ */
|
---|
| 229 | ID rcv_flgid; /* 受信イベントフラグ */
|
---|
| 230 | ID snd_tskid; /* 送信タスク識別子 */
|
---|
| 231 | ID rcv_tskid; /* 受信タスク識別子 */
|
---|
| 232 | uint8_t *sbuf_rptr; /* 送信用読み出しポインタ */
|
---|
| 233 | uint8_t *sbuf_wptr; /* 送信用書き込みポインタ */
|
---|
| 234 | uint8_t *rbuf_rptr; /* 受信用読み出しポインタ */
|
---|
| 235 | uint8_t *rbuf_wptr; /* 受信用書き込みポインタ */
|
---|
| 236 | T_TCP_SEQ snd_ssthresh; /* 輻輳ウィンドサイズ(snd_cwnd) */
|
---|
| 237 | /* のしきい値 */
|
---|
| 238 | T_TCP_TIME rxtcur; /* 現在の再送タイムアウト */
|
---|
| 239 | T_TCP_TIME srtt; /* 平滑化された RTT */
|
---|
| 240 | T_TCP_TIME rttvar; /* 平滑化された分散 */
|
---|
| 241 | T_TCP_WND snd_cwnd; /* 輻輳ウィンドサイズ */
|
---|
| 242 |
|
---|
| 243 | /*
|
---|
| 244 | * 相手の最大受信セグメントサイズ
|
---|
| 245 | *
|
---|
| 246 | * オリジナルでは、一般のセグメントの最大サイズ (t_maxseg) と、
|
---|
| 247 | * オプション付きのセグメントの最大サイズ (t_maxopd) が別に
|
---|
| 248 | * なっている。これは、現在のインターネットでは、オプション付きの
|
---|
| 249 | * セグメントのほうが多いからと説明されているためである。
|
---|
| 250 | * 本実装では、最大セグメントサイズオプション以外のオプションは
|
---|
| 251 | * 実装しないので、t_maxseg の使用する。
|
---|
| 252 | */
|
---|
| 253 | T_TCP_SEG maxseg;
|
---|
| 254 |
|
---|
| 255 | int16_t snd_tfn; /* 送信動作中の API 機能コード */
|
---|
| 256 | int16_t rcv_tfn; /* 受信動作中の API 機能コード */
|
---|
| 257 |
|
---|
| 258 | #ifdef TCP_CFG_NON_BLOCKING
|
---|
| 259 |
|
---|
| 260 | T_IPEP *p_dstaddr; /* 相手のアドレスへのポインタ */
|
---|
| 261 | T_IPEP *p_myaddr; /* 自分のアドレスへのポインタ */
|
---|
| 262 |
|
---|
| 263 | #if defined(_IP6_CFG) && defined(_IP4_CFG)
|
---|
| 264 | T_IPV4EP *p_dstaddr4; /* 相手のアドレスへのポインタ */
|
---|
| 265 | T_IPV4EP *p_myaddr4; /* 自分のアドレスへのポインタ */
|
---|
| 266 | #endif
|
---|
| 267 |
|
---|
| 268 | int16_t snd_nblk_tfn; /* 送信動作中の API 機能コード */
|
---|
| 269 | int16_t rcv_nblk_tfn; /* 受信動作中の API 機能コード */
|
---|
| 270 | void *snd_data; /* 送信データ領域の先頭アドレス */
|
---|
| 271 | int_t snd_len; /* 送信データ領域の長さ */
|
---|
| 272 | void *rcv_data; /* 受信データ領域の先頭アドレス */
|
---|
| 273 | int_t rcv_len; /* 受信データ領域の長さ */
|
---|
| 274 | void **snd_p_buf; /* 送信バッファへのポインタ */
|
---|
| 275 | void **rcv_p_buf; /* 受信バッファへのポインタ */
|
---|
| 276 |
|
---|
| 277 | #endif /* of #ifdef TCP_CFG_NON_BLOCKING */
|
---|
| 278 |
|
---|
| 279 | #ifdef TCP_CFG_SWBUF_CSAVE
|
---|
| 280 | T_NET_BUF *swbufq; /* 送信ウィンドバッファキュー */
|
---|
| 281 | #endif
|
---|
| 282 |
|
---|
| 283 | /*
|
---|
| 284 | * これ以降のメンバーは tcp_init_cep() 関数でゼロクリアーされる。
|
---|
| 285 | */
|
---|
| 286 |
|
---|
| 287 | T_TCP_TIME timer[NUM_TCP_TIMERS]; /* TCP のタイマ */
|
---|
| 288 | T_IPEP dstaddr; /* 相手のアドレス */
|
---|
| 289 | T_IPEP myaddr; /* 自分のアドレス */
|
---|
| 290 | T_NET_BUF *reassq; /* 受信再構成キュー */
|
---|
| 291 |
|
---|
| 292 | #if defined(_IP6_CFG)
|
---|
| 293 |
|
---|
| 294 | #if defined(_IP4_CFG)
|
---|
| 295 |
|
---|
| 296 | T_TCP4_REP *rep4; /* IPv4 用受付口 */
|
---|
| 297 |
|
---|
| 298 | #endif /* of #if defined(_IP4_CFG) */
|
---|
| 299 |
|
---|
| 300 | T_TCP6_REP *rep; /* IPv6 用受付口 */
|
---|
| 301 |
|
---|
| 302 | #else /* of #if defined(_IP6_CFG) */
|
---|
| 303 |
|
---|
| 304 | #if defined(_IP4_CFG)
|
---|
| 305 |
|
---|
| 306 | T_TCP4_REP *rep; /* IPv4 用受付口 */
|
---|
| 307 |
|
---|
| 308 | #endif /* of #if defined(_IP4_CFG) */
|
---|
| 309 |
|
---|
| 310 | #endif /* of #if defined(_IP6_CFG) */
|
---|
| 311 |
|
---|
| 312 |
|
---|
| 313 | #ifdef TCP_CFG_RWBUF_CSAVE
|
---|
| 314 | T_NET_BUF *rwbufq; /* 受信ウィンドバッファキュー */
|
---|
| 315 | #endif
|
---|
| 316 |
|
---|
| 317 | #ifdef TCP_CFG_EXTENTIONS
|
---|
| 318 | T_TCP_HDR *urg_tcph; /* 緊急データ入りのセグメントの TCP ヘッダ */
|
---|
| 319 | T_TCP_SEQ snd_up; /* 送信した緊急ポインタ */
|
---|
| 320 | T_TCP_SEQ rcv_up; /* 受信した緊急ポインタ */
|
---|
| 321 | #endif /* of #ifdef TCP_CFG_EXTENTIONS */
|
---|
| 322 |
|
---|
| 323 | T_TCP_SEQ snd_una; /* 未確認の最小送信 SEQ つまり */
|
---|
| 324 | /* 確認された最大送信 SEQ */
|
---|
| 325 | T_TCP_SEQ snd_max; /* 送信した最大 SEQ */
|
---|
| 326 | T_TCP_SEQ snd_nxt; /* 次に送信する SEQ */
|
---|
| 327 | T_TCP_SEQ snd_old_nxt; /* 元の snd_nxt */
|
---|
| 328 | T_TCP_SEQ snd_wl1; /* 前回ウィンドを更新した SEQ */
|
---|
| 329 | T_TCP_SEQ snd_wl2; /* 前回ウィンドを更新した ACK */
|
---|
| 330 | T_TCP_SEQ iss; /* 自分の SEQ の初期値 */
|
---|
| 331 | T_TCP_SEQ irs; /* 相手の SEQ の初期値 */
|
---|
| 332 | T_TCP_SEQ rcv_nxt; /* 受信を期待している最小の SEQ */
|
---|
| 333 | T_TCP_SEQ rcv_adv; /* 受信を期待している最大の SEQ */
|
---|
| 334 | T_TCP_SEQ rcv_wnd; /* 受信可能なウィンドサイズ */
|
---|
| 335 | T_TCP_SEQ rtseq; /* 時間計測を始めた SEQ */
|
---|
| 336 | T_TCP_SEQ last_ack_sent; /* 最後に送信した ACK */
|
---|
| 337 | T_TCP_TIME idle; /* アイドル時間 */
|
---|
| 338 | ER error; /* 非同期に発生したエラー */
|
---|
| 339 | ER net_error; /* ネットワークのエラー状態 */
|
---|
| 340 | T_TCP_WND snd_wnd; /* 相手の受信可能ウィンドサイズ */
|
---|
| 341 | T_TCP_WND max_sndwnd; /* 今までの最大送信ウィンドサイズ */
|
---|
| 342 | T_TCP_TIME rtt; /* 往復時間 */
|
---|
| 343 | uint16_t swbuf_count; /* 送信ウィンドバッファの使用中サイズ */
|
---|
| 344 | uint16_t rwbuf_count; /* 受信ウィンドバッファの使用中サイズ */
|
---|
| 345 | uint16_t rcv_buf_len; /* tcp_rcv_buf の割当て長 */
|
---|
| 346 | uint16_t get_buf_len; /* tcp_rcv_buf の割当て長 */
|
---|
| 347 | uint8_t rxtshift; /* 再送信回数の log(2) */
|
---|
| 348 | uint8_t fsm_state; /* FSM 状態 */
|
---|
| 349 | uint8_t dupacks; /* 再送 ACK 数 */
|
---|
| 350 |
|
---|
| 351 | #if defined(TCP_CFG_RWBUF_CSAVE) && defined(TCP_CFG_RWBUF_CSAVE_MAX_QUEUES)
|
---|
| 352 | uint16_t rwbufq_entries; /* 受信ウィンドバッファキューのエントリ数 */
|
---|
| 353 | #endif
|
---|
| 354 |
|
---|
| 355 | } T_TCP_CEP;
|
---|
| 356 |
|
---|
| 357 | #define T_TCP6_CEP T_TCP_CEP
|
---|
| 358 | #define T_TCP4_CEP T_TCP_CEP
|
---|
| 359 |
|
---|
| 360 | /*
|
---|
| 361 | * Time Wait 用 TCP 通信端点
|
---|
| 362 | */
|
---|
| 363 |
|
---|
| 364 | typedef struct t_tcp_twcep {
|
---|
| 365 | int_t rbufsz; /* 受信用ウィンドバッファサイズ */
|
---|
| 366 | T_TCP_TIME timer_2msl; /* 2MSL タイマ */
|
---|
| 367 | T_IPEP dstaddr; /* 相手のアドレス */
|
---|
| 368 | T_IPEP myaddr; /* 自分のアドレス */
|
---|
| 369 | T_TCP_SEQ snd_una; /* 未確認の最小送信 SEQ つまり */
|
---|
| 370 | /* 確認された最大送信 SEQ */
|
---|
| 371 | T_TCP_SEQ rcv_nxt; /* 受信を期待している最小の SEQ */
|
---|
| 372 | uint16_t rwbuf_count; /* 受信ウィンドバッファの使用中サイズ */
|
---|
| 373 | uint8_t fsm_state; /* FSM 状態 */
|
---|
| 374 | uint8_t flags; /* 通信端点フラグ */
|
---|
| 375 |
|
---|
| 376 | } T_TCP_TWCEP;
|
---|
| 377 |
|
---|
| 378 | #define T_TCP_CEP_DEFINED
|
---|
| 379 |
|
---|
| 380 | /*
|
---|
| 381 | * TCP 通信端点の状態フラグ
|
---|
| 382 | */
|
---|
| 383 |
|
---|
| 384 | #define TCP_CEP_FLG_IPV4 ULONG_C(0x00000001) /* IPv4 用。 */
|
---|
| 385 | #define TCP_CEP_FLG_ACK_NOW ULONG_C(0x00000100) /* 直ちに相手に ACK を送る。 */
|
---|
| 386 | #define TCP_CEP_FLG_DEL_ACK ULONG_C(0x00000200) /* ACK を遅延する。 */
|
---|
| 387 | #define TCP_CEP_FLG_SENT_FIN ULONG_C(0x00000400) /* FIN を送ってある。 */
|
---|
| 388 | #define TCP_CEP_FLG_NEED_SYN ULONG_C(0x00000800) /* SYN を送信する。 */
|
---|
| 389 | #define TCP_CEP_FLG_NEED_FIN ULONG_C(0x00001000) /* FIN を送信する。 */
|
---|
| 390 | #define TCP_CEP_FLG_FORCE ULONG_C(0x00002000) /* 強制送信。 */
|
---|
| 391 | #define TCP_CEP_FLG_NO_PUSH ULONG_C(0x00004000) /* push しない。 */
|
---|
| 392 | #define TCP_CEP_FLG_NO_DELAY ULONG_C(0x00008000) /* 遅延しない。 */
|
---|
| 393 | #define TCP_CEP_FLG_FORCE_CLEAR ULONG_C(0x00010000) /* 強制送信した後フラグをクリアーする。*/
|
---|
| 394 | #define TCP_CEP_FLG_POST_OUTPUT ULONG_C(0x00020000) /* 送信を開始する。 */
|
---|
| 395 | #define TCP_CEP_FLG_RESERVE_OUTPUT ULONG_C(0x00040000) /* 送信を予約する。 */
|
---|
| 396 | #define TCP_CEP_FLG_DYNAMIC ULONG_C(0x00100000) /* 動的生成・削除可能通信端点。 */
|
---|
| 397 | #define TCP_CEP_FLG_VALID ULONG_C(0x00200000) /* 生成済みで有効な通信端点。 */
|
---|
| 398 | #define TCP_CEP_FLG_CLOSE_AFTER_OUTPUT ULONG_C(0x00400000) /* 送信した後コネクションを閉じる。*/
|
---|
| 399 | #define TCP_CEP_FLG_RESTORE_NEXT_OUTPUT ULONG_C(0x00800000) /* 送信した後、snd_nxt を元に戻す。*/
|
---|
| 400 |
|
---|
| 401 | /* 送受信ウィンドバッファの省コピー機能 */
|
---|
| 402 | #define TCP_CEP_FLG_WBCS_NBUF_REQ ULONG_C(0x80000000) /* ネットワークバッファ割当て要求*/
|
---|
| 403 | #define TCP_CEP_FLG_WBCS_MASK ULONG_C(0x70000000) /* マスク */
|
---|
| 404 | #define TCP_CEP_FLG_WBCS_FREE ULONG_C(0x00000000) /* 送信ウィンドバッファ未使用 */
|
---|
| 405 | #define TCP_CEP_FLG_WBCS_WOPEN_PEND ULONG_C(0x10000000) /* 相手の受信ウィンドの開き待ち */
|
---|
| 406 | #define TCP_CEP_FLG_WBCS_NBUF_PEND ULONG_C(0x20000000) /* ネットワークバッファ予約待ち */
|
---|
| 407 | #define TCP_CEP_FLG_WBCS_NBUF_RSVD ULONG_C(0x30000000) /* ネットワークバッファ予約済み */
|
---|
| 408 | #define TCP_CEP_FLG_WBCS_NBUF_READY ULONG_C(0x40000000) /* ネットワークバッファ割当て済み*/
|
---|
| 409 | #define TCP_CEP_FLG_WBCS_SEND_READY ULONG_C(0x50000000) /* 送信可能 */
|
---|
| 410 | #define TCP_CEP_FLG_WBCS_SENT ULONG_C(0x60000000) /* 送信済みで、ACK待ち */
|
---|
| 411 | #define TCP_CEP_FLG_WBCS_ACKED ULONG_C(0x70000000) /* 送信済みで、ACK完了 */
|
---|
| 412 |
|
---|
| 413 | /* 初期化から除外するフラグの定義 */
|
---|
| 414 | #define TCP_CEP_FLG_NOT_CLEAR (TCP_CEP_FLG_WBCS_NBUF_REQ|TCP_CEP_FLG_WBCS_MASK|\
|
---|
| 415 | TCP_CEP_FLG_DYNAMIC|TCP_CEP_FLG_VALID|TCP_CEP_FLG_IPV4)
|
---|
| 416 |
|
---|
| 417 | /*
|
---|
| 418 | * 通信端点イベントフラグ
|
---|
| 419 | */
|
---|
| 420 |
|
---|
| 421 | #define TCP_CEP_EVT_ESTABLISHED ULONG_C(0x00000001) /* コネクション確立 */
|
---|
| 422 | #define TCP_CEP_EVT_CLOSED ULONG_C(0x00000002) /* 未使用状態 */
|
---|
| 423 | #define TCP_CEP_EVT_SWBUF_READY ULONG_C(0x00000004) /* 送信ウィンドバッファ空き */
|
---|
| 424 | #define TCP_CEP_EVT_RWBUF_READY ULONG_C(0x00000008) /* 送信ウィンドバッファデータあり*/
|
---|
| 425 | #define TCP_CEP_EVT_ALL ULONG_C(0xffffffff) /* 全イベント */
|
---|
| 426 |
|
---|
| 427 | /*
|
---|
| 428 | * 追加 API 機能・事象コード
|
---|
| 429 | */
|
---|
| 430 |
|
---|
| 431 | /* TCP 関係 */
|
---|
| 432 |
|
---|
| 433 | #define TFN_TCP_UNDEF (0)
|
---|
| 434 |
|
---|
| 435 | /*
|
---|
| 436 | * srtt: 平滑化された RTT
|
---|
| 437 | * rttvar: 平滑化された分散
|
---|
| 438 | * rtt: 測定された往復時間
|
---|
| 439 | *
|
---|
| 440 | * 平滑化された RTT (srtt) と平滑化された分散 (rttvar) を
|
---|
| 441 | * 整数型で計算するために、左シフトしてスケールする。
|
---|
| 442 | * srtt は 2 進小数点以下 3 ビット、
|
---|
| 443 | * rttvar は 2 進小数点以下 2 ビットを保持する。
|
---|
| 444 | */
|
---|
| 445 |
|
---|
| 446 | #define TCP_DELTA_SHIFT 2
|
---|
| 447 | /* 差分 = rtt/8 + srtt*7/8 の計算のためのシフト値 */
|
---|
| 448 | #define TCP_SRTT_SHIFT (TCP_DELTA_SHIFT + 3)
|
---|
| 449 | /* srtt のシフト値、3(+2)ビット */
|
---|
| 450 | #define TCP_RTTVAR_SHIFT (TCP_DELTA_SHIFT + 2)
|
---|
| 451 | /* rttvar のシフト値、2(+2)ビット */
|
---|
| 452 | #define TCP_SRTT_SCALE (1<<TCP_SRTT_SHIFT)
|
---|
| 453 | #define TCP_RTTVAR_SCALE (1<<TCP_RTTVAR_SHIFT)
|
---|
| 454 |
|
---|
| 455 | /*
|
---|
| 456 | * 高速再転送を開始する再送 ACK 数のしきい値
|
---|
| 457 | */
|
---|
| 458 |
|
---|
| 459 | #define MAX_TCP_REXMT_THRESH 3
|
---|
| 460 |
|
---|
| 461 | /*
|
---|
| 462 | * 受信再構成キューでの TCP ヘッダ
|
---|
| 463 | */
|
---|
| 464 |
|
---|
| 465 | typedef struct t_tcp_q_hdr {
|
---|
| 466 | uint16_t sport; /* 送信元ポート番号 */
|
---|
| 467 | uint16_t dport; /* 宛先ポート番号 */
|
---|
| 468 |
|
---|
| 469 | uint32_t seq; /* SEQ 番号 */
|
---|
| 470 |
|
---|
| 471 | T_NET_BUF *next; /* 次のセグメント、元は ACK 番号(ack) */
|
---|
| 472 |
|
---|
| 473 | uint8_t doff; /* データオフセット(上位4ビット) */
|
---|
| 474 | uint8_t flags; /* フラグ(下位6ビット) */
|
---|
| 475 | uint16_t soff; /* SDU オフセット、元はウィンドサイズ(win) */
|
---|
| 476 |
|
---|
| 477 | uint16_t slen; /* SDU 長、元はチェックサム(sum) */
|
---|
| 478 | uint16_t urp; /* 緊急ポインタ(SDU 長補正) */
|
---|
| 479 | } __attribute__((packed, aligned(2)))T_TCP_Q_HDR;
|
---|
| 480 |
|
---|
| 481 | #define GET_TCP_Q_HDR(nbuf,thoff) ((T_TCP_Q_HDR*)((uint8_t*)((nbuf)->buf) + thoff))
|
---|
| 482 |
|
---|
| 483 | /*
|
---|
| 484 | * オブジェクト ID の最小値の定義
|
---|
| 485 | */
|
---|
| 486 |
|
---|
| 487 | #define TMIN_TCP_REPID 1 /* TCP 受付口 ID の最小値 */
|
---|
| 488 | #define TMIN_TCP6_REPID 1 /* TCP/IPv6 受付口 ID の最小値 */
|
---|
| 489 | #define TMIN_TCP4_REPID (TNUM_TCP6_REPID+1) /* TCP/IPv4 受付口 ID の最小値 */
|
---|
| 490 |
|
---|
| 491 | #define TMIN_TCP_CEPID 1 /* TCP 通信端点 ID の最小値 */
|
---|
| 492 | #define TMIN_TCP6_CEPID 1 /* TCP/IPv6 通信端点 ID の最小値 */
|
---|
| 493 | #define TMIN_TCP4_CEPID (TNUM_TCP6_CEPID+1) /* TCP/IPv4 通信端点 ID の最小値 */
|
---|
| 494 |
|
---|
| 495 | #define TMIN_TCP_TWCEPID 1 /* Time Wait 用 TCP 通信端点 ID の最小値 */
|
---|
| 496 |
|
---|
| 497 | /*
|
---|
| 498 | * 制御セグメント(データなし)サイズのネットワークバッファ
|
---|
| 499 | */
|
---|
| 500 |
|
---|
| 501 | #if defined(IF_HDR_SIZE) && defined(IP_HDR_SIZE)
|
---|
| 502 |
|
---|
| 503 | typedef struct t_net_buf_cseg {
|
---|
| 504 | uint16_t len; /* データの長さ */
|
---|
| 505 | uint8_t idix; /* mpfid のインデックス */
|
---|
| 506 | uint8_t flags; /* フラグ */
|
---|
| 507 | #ifdef IF_ETHER_NIC_NET_BUF_ALIGN
|
---|
| 508 | uint8_t nalign[IF_ETHER_NIC_NET_BUF_ALIGN];
|
---|
| 509 | #endif
|
---|
| 510 | #if CPU_NET_ALIGN == 4 && IF_HDR_ALIGN != 4
|
---|
| 511 | uint8_t halign[4 - IF_HDR_ALIGN];
|
---|
| 512 | #endif
|
---|
| 513 | uint8_t buf[IF_HDR_SIZE + IP_HDR_SIZE + TCP_HDR_SIZE];
|
---|
| 514 | /* バッファ本体 */
|
---|
| 515 | } T_NET_BUF_CSEG;
|
---|
| 516 |
|
---|
| 517 | #endif /* of #if defined(IF_HDR_SIZE) && defined(IP_HDR_SIZE) */
|
---|
| 518 |
|
---|
| 519 | /*
|
---|
| 520 | * SNMP の 管理情報ベース (MIB)
|
---|
| 521 | */
|
---|
| 522 |
|
---|
| 523 | typedef struct t_tcp_stats {
|
---|
| 524 | uint32_t tcpActiveOpens;
|
---|
| 525 | uint32_t tcpPassiveOpens;
|
---|
| 526 | uint32_t tcpAttemptFails;
|
---|
| 527 | uint32_t tcpEstabResets;
|
---|
| 528 | /* uint32_t tcpCurrEstab;*/
|
---|
| 529 | uint32_t tcpInSegs;
|
---|
| 530 | uint32_t tcpOutSegs;
|
---|
| 531 | uint32_t tcpRetransSegs;
|
---|
| 532 | uint32_t tcpInErrs;
|
---|
| 533 | uint32_t tcpOutRsts;
|
---|
| 534 | } T_TCP_STATS;
|
---|
| 535 |
|
---|
| 536 | /*
|
---|
| 537 | * 関数シミュレーションマクロ
|
---|
| 538 | */
|
---|
| 539 |
|
---|
| 540 | /* TCP 受付口 */
|
---|
| 541 |
|
---|
| 542 | #define VALID_TCP6_REPID(id) (TMIN_TCP6_REPID<=(id)&&(id)<=tmax_tcp6_repid)
|
---|
| 543 | #define VALID_TCP4_REPID(id) (TMIN_TCP4_REPID<=(id)&&(id)<=tmax_tcp4_repid)
|
---|
| 544 |
|
---|
| 545 | #define INDEX_TCP6_REP(id) ((id)-TMIN_TCP6_REPID)
|
---|
| 546 | #define INDEX_TCP4_REP(id) ((id)-TMIN_TCP4_REPID)
|
---|
| 547 |
|
---|
| 548 | #define GET_TCP6_REP(id) (&(tcp6_rep[INDEX_TCP6_REP(id)]))
|
---|
| 549 | #define GET_TCP4_REP(id) (&(tcp4_rep[INDEX_TCP4_REP(id)]))
|
---|
| 550 |
|
---|
| 551 | #define GET_TCP6_REPID(rep) ((ID)(((rep)-tcp6_rep)+TMIN_TCP6_REPID))
|
---|
| 552 | #define GET_TCP4_REPID(rep) ((ID)(((rep)-tcp4_rep)+TMIN_TCP4_REPID))
|
---|
| 553 |
|
---|
| 554 | #ifdef TCP_CFG_EXTENTIONS
|
---|
| 555 |
|
---|
| 556 | #define VALID_TCP_REP(rep) (((rep)->flags&TCP_REP_FLG_VALID)!=0)
|
---|
| 557 | #define DYNAMIC_TCP_REP(rep) (((rep)->flags&TCP_REP_FLG_DYNAMIC)!=0)
|
---|
| 558 |
|
---|
| 559 | #else /* of #ifdef TCP_CFG_EXTENTIONS */
|
---|
| 560 |
|
---|
| 561 | #define VALID_TCP_REP(rep) (true)
|
---|
| 562 | #define DYNAMIC_TCP_REP(rep) (false)
|
---|
| 563 |
|
---|
| 564 | #endif /* of #ifdef TCP_CFG_EXTENTIONS */
|
---|
| 565 |
|
---|
| 566 | /* TCP 通信端点 */
|
---|
| 567 |
|
---|
| 568 | #define VALID_TCP_CEPID(id) (TMIN_TCP_CEPID<=(id)&&(id)<=tmax_tcp_cepid)
|
---|
| 569 | #define INDEX_TCP_CEP(id) ((id)-TMIN_TCP_CEPID)
|
---|
| 570 |
|
---|
| 571 | #define GET_TCP_CEP(id) (&(tcp_cep[INDEX_TCP_CEP(id)]))
|
---|
| 572 |
|
---|
| 573 | #define GET_TCP_CEPID(cep) ((ID)(((cep)-tcp_cep)+TMIN_TCP_CEPID))
|
---|
| 574 | #define GET_TCP_TWCEPID(cep) ((ID)(((cep)-tcp_twcep)+TMIN_TCP_TWCEPID))
|
---|
| 575 |
|
---|
| 576 | #define VALID_TCP_CEP(cep) (((cep)->flags&TCP_CEP_FLG_VALID)!=0)
|
---|
| 577 | #define DYNAMIC_TCP_CEP(cep) (((cep)->flags&TCP_CEP_FLG_DYNAMIC)!=0)
|
---|
| 578 | #define TCP_IS_CEP_IPV6(cep) (((cep)->flags&TCP_CEP_FLG_IPV4)==0)
|
---|
| 579 | #define TCP_IS_CEP_IPV4(cep) (((cep)->flags&TCP_CEP_FLG_IPV4)!=0)
|
---|
| 580 |
|
---|
| 581 | #define IS_TFN_TCP_RCV(t) ((t)==TFN_TCP_ACP_CEP||(t)==TFN_TCP_RCV_DAT||\
|
---|
| 582 | (t)==TFN_TCP_CLS_CEP||\
|
---|
| 583 | (t)==TFN_TCP_RCV_BUF||(t)==TFN_TCP_REL_BUF||\
|
---|
| 584 | (t)==TFN_TCP_RCV_OOB)
|
---|
| 585 |
|
---|
| 586 | #define VALID_TFN_TCP_CAN(t) ((t)==TFN_TCP_ACP_CEP||(t)==TFN_TCP_CON_CEP||\
|
---|
| 587 | (t)==TFN_TCP_CLS_CEP||\
|
---|
| 588 | (t)==TFN_TCP_SND_DAT||(t)==TFN_TCP_RCV_DAT||\
|
---|
| 589 | (t)==TFN_TCP_GET_BUF||(t)==TFN_TCP_RCV_BUF||\
|
---|
| 590 | (t)==TFN_TCP_SND_OOB||\
|
---|
| 591 | (t)==TFN_TCP_ALL)
|
---|
| 592 |
|
---|
| 593 | #define VALID_URG_POINTER(urg) (TCP_CFG_URG_OFFSET==0||urg!=0)
|
---|
| 594 |
|
---|
| 595 | /*
|
---|
| 596 | * 全域変数
|
---|
| 597 | */
|
---|
| 598 |
|
---|
| 599 | extern uint8_t tcp_initialized;
|
---|
| 600 |
|
---|
| 601 | extern T_TCP_STATS tcp_stats;
|
---|
| 602 |
|
---|
| 603 | /* TCP 受付口 */
|
---|
| 604 |
|
---|
| 605 | extern T_TCP6_REP tcp6_rep[];
|
---|
| 606 | extern T_TCP4_REP tcp4_rep[];
|
---|
| 607 |
|
---|
| 608 | #if defined(SUPPORT_INET6)
|
---|
| 609 | #define tcp_rep tcp6_rep
|
---|
| 610 | #elif defined(SUPPORT_INET4)
|
---|
| 611 | #define tcp_rep tcp4_rep
|
---|
| 612 | #endif
|
---|
| 613 |
|
---|
| 614 | extern const ID tmax_tcp_repid;
|
---|
| 615 |
|
---|
| 616 | #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4)
|
---|
| 617 | extern const ID tmax_tcp6_repid;
|
---|
| 618 | extern const ID tmax_tcp4_repid;
|
---|
| 619 | #else
|
---|
| 620 | #define tmax_tcp6_repid tmax_tcp_repid
|
---|
| 621 | #define tmax_tcp4_repid tmax_tcp_repid
|
---|
| 622 | #endif
|
---|
| 623 |
|
---|
| 624 | /* TCP 通信端点 */
|
---|
| 625 |
|
---|
| 626 | extern T_TCP_CEP tcp_cep[];
|
---|
| 627 | extern T_TCP_TWCEP tcp_twcep[];
|
---|
| 628 |
|
---|
| 629 | extern const ID tmax_tcp_cepid;
|
---|
| 630 |
|
---|
| 631 | #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4)
|
---|
| 632 | extern const ID tmax_tcp6_cepid;
|
---|
| 633 | extern const ID tmax_tcp4_cepid;
|
---|
| 634 | #else
|
---|
| 635 | #define tmax_tcp6_cepid tmax_tcp_cepid
|
---|
| 636 | #define tmax_tcp4_cepid tmax_tcp_cepid
|
---|
| 637 | #endif
|
---|
| 638 |
|
---|
| 639 | /*
|
---|
| 640 | * Inline 関数
|
---|
| 641 | */
|
---|
| 642 |
|
---|
| 643 | #ifndef TCP_CFG_RWBUF_CSAVE
|
---|
| 644 |
|
---|
| 645 | /*
|
---|
| 646 | * TCP 通信端点の受信ウィンドバッファの省コピー機能が
|
---|
| 647 | * 無効の場合は何もしないためのダミーの関数
|
---|
| 648 | */
|
---|
| 649 |
|
---|
| 650 | /*
|
---|
| 651 | * tcp_free_rwbufq -- 受信ウィンドバッファキューを解放する。
|
---|
| 652 | */
|
---|
| 653 |
|
---|
| 654 | Inline void
|
---|
| 655 | tcp_free_rwbufq_ncs (T_TCP_CEP *cep)
|
---|
| 656 | {
|
---|
| 657 | }
|
---|
| 658 |
|
---|
| 659 | #endif /* of #ifndef TCP_CFG_RWBUF_CSAVE */
|
---|
| 660 |
|
---|
| 661 | #ifdef TCP_CFG_SWBUF_CSAVE_ONLY
|
---|
| 662 |
|
---|
| 663 | /*
|
---|
| 664 | * TCP 通信端点の送信ウィンドバッファの省コピー機能のみが
|
---|
| 665 | * 有効の場合は何もしないためのダミーの関数
|
---|
| 666 | */
|
---|
| 667 |
|
---|
| 668 | /*
|
---|
| 669 | * tcp_read_swbuf_cs -- 送信ウィンドバッファからデータを読み出す。
|
---|
| 670 | */
|
---|
| 671 |
|
---|
| 672 | Inline void
|
---|
| 673 | tcp_read_swbuf_cs (T_TCP_CEP *cep, T_NET_BUF *output, uint_t len, uint_t doff)
|
---|
| 674 | {
|
---|
| 675 | }
|
---|
| 676 |
|
---|
| 677 | #endif /* of #ifdef TCP_CFG_SWBUF_CSAVE_ONLY */
|
---|
| 678 |
|
---|
| 679 | #ifndef TCP_CFG_SWBUF_CSAVE
|
---|
| 680 |
|
---|
| 681 | /*
|
---|
| 682 | * TCP 通信端点の送信ウィンドバッファの省コピー機能が
|
---|
| 683 | * 無効の場合は何もしないためのダミーの関数
|
---|
| 684 | */
|
---|
| 685 |
|
---|
| 686 | /*
|
---|
| 687 | * tcp_free_swbufq -- 送信ウィンドバッファキューを解放する。
|
---|
| 688 | */
|
---|
| 689 |
|
---|
| 690 | Inline void
|
---|
| 691 | tcp_free_swbufq_ncs (T_TCP_CEP *cep)
|
---|
| 692 | {
|
---|
| 693 | }
|
---|
| 694 |
|
---|
| 695 | /*
|
---|
| 696 | * tcp_alloc_swbuf -- 送信ウィンドバッファ用のネットワークバッファの割り当てを指示する。
|
---|
| 697 | */
|
---|
| 698 |
|
---|
| 699 | Inline void
|
---|
| 700 | tcp_alloc_swbuf_ncs (T_TCP_CEP *cep)
|
---|
| 701 | {
|
---|
| 702 | }
|
---|
| 703 |
|
---|
| 704 | /*
|
---|
| 705 | * tcp_push_res_nbuf -- ネットワークバッファを予約する。
|
---|
| 706 | */
|
---|
| 707 |
|
---|
| 708 | Inline T_NET_BUF *
|
---|
| 709 | tcp_push_res_nbuf_ncs (T_NET_BUF *nbuf)
|
---|
| 710 | {
|
---|
| 711 | return nbuf;
|
---|
| 712 | }
|
---|
| 713 |
|
---|
| 714 | /*
|
---|
| 715 | * tcp_pull_res_nbuf -- 予約してあるネットワークバッファ返す。
|
---|
| 716 | */
|
---|
| 717 |
|
---|
| 718 | Inline T_NET_BUF *
|
---|
| 719 | tcp_pull_res_nbuf_ncs (ATR nbatr)
|
---|
| 720 | {
|
---|
| 721 | return NULL;
|
---|
| 722 | }
|
---|
| 723 |
|
---|
| 724 | #endif /* of #ifndef TCP_CFG_SWBUF_CSAVE */
|
---|
| 725 |
|
---|
| 726 | /*
|
---|
| 727 | * TCP 通信端点の受信ウィンドバッファの省コピー機能の切り替えマクロ
|
---|
| 728 | */
|
---|
| 729 |
|
---|
| 730 | #ifdef TCP_CFG_RWBUF_CSAVE
|
---|
| 731 |
|
---|
| 732 | #ifdef TCP_CFG_RWBUF_CSAVE_ONLY
|
---|
| 733 |
|
---|
| 734 | #define TCP_FREE_RWBUFQ(cep) tcp_free_rwbufq_cs(cep)
|
---|
| 735 | #define TCP_DROP_RWBUF(cep,len) tcp_drop_rwbuf_cs(cep,len)
|
---|
| 736 | #define TCP_READ_RWBUF(cep,data,len) tcp_read_rwbuf_cs(cep,data,len)
|
---|
| 737 | #define TCP_GET_RWBUF_ADDR(cep,buf) tcp_get_rwbuf_addr_cs(cep,buf)
|
---|
| 738 | #define TCP_WRITE_RWBUF(cep,input,thoff) tcp_write_rwbuf_cs(cep,input,thoff)
|
---|
| 739 |
|
---|
| 740 | #else /* of #ifdef TCP_CFG_RWBUF_CSAVE_ONLY */
|
---|
| 741 |
|
---|
| 742 | #define TCP_FREE_RWBUFQ(cep) tcp_free_rwbufq(cep)
|
---|
| 743 | #define TCP_DROP_RWBUF(cep,len) tcp_drop_rwbuf(cep,len)
|
---|
| 744 | #define TCP_READ_RWBUF(cep,data,len) tcp_read_rwbuf(cep,data,len)
|
---|
| 745 | #define TCP_GET_RWBUF_ADDR(cep,buf) tcp_get_rwbuf_addr(cep,buf)
|
---|
| 746 | #define TCP_WRITE_RWBUF(cep,input,thoff) tcp_write_rwbuf(cep,input,thoff)
|
---|
| 747 |
|
---|
| 748 | #endif /* of #ifdef TCP_CFG_RWBUF_CSAVE_ONLY */
|
---|
| 749 |
|
---|
| 750 | #else /* of #ifdef TCP_CFG_RWBUF_CSAVE */
|
---|
| 751 |
|
---|
| 752 | #define TCP_FREE_RWBUFQ(cep) tcp_free_rwbufq_ncs(cep)
|
---|
| 753 | #define TCP_DROP_RWBUF(cep,len) tcp_drop_rwbuf_ncs(cep,len)
|
---|
| 754 | #define TCP_READ_RWBUF(cep,data,len) tcp_read_rwbuf_ncs(cep,data,len)
|
---|
| 755 | #define TCP_GET_RWBUF_ADDR(cep,buf) tcp_get_rwbuf_addr_ncs(cep,buf)
|
---|
| 756 | #define TCP_WRITE_RWBUF(cep,input,thoff) tcp_write_rwbuf_ncs(cep,input,thoff)
|
---|
| 757 |
|
---|
| 758 | #endif /* of #ifdef TCP_CFG_RWBUF_CSAVE */
|
---|
| 759 |
|
---|
| 760 | /*
|
---|
| 761 | * TCP 通信端点の送信ウィンドバッファの省コピー機能の切り替えマクロ
|
---|
| 762 | */
|
---|
| 763 |
|
---|
| 764 | #ifdef TCP_CFG_SWBUF_CSAVE
|
---|
| 765 |
|
---|
| 766 | #define TCP_PUSH_RES_NBUF(nbuf) tcp_push_res_nbuf(nbuf)
|
---|
| 767 | #define TCP_PULL_RES_NBUF(atr) tcp_pull_res_nbuf(atr)
|
---|
| 768 |
|
---|
| 769 | #ifdef TCP_CFG_SWBUF_CSAVE_ONLY
|
---|
| 770 |
|
---|
| 771 | #define TCP_FREE_SWBUFQ(cep) tcp_free_swbufq_cs(cep)
|
---|
| 772 | #define TCP_ALLOC_SWBUF(cep) tcp_alloc_swbuf_cs(cep)
|
---|
| 773 | #define TCP_DROP_SWBUF(cep,len) tcp_drop_swbuf_cs(cep,len)
|
---|
| 774 | #define TCP_WRITE_SWBUF(cep,data,len) tcp_write_swbuf_cs(cep,data,len)
|
---|
| 775 | #define TCP_READ_SWBUF(cep,output,len,doff) tcp_read_swbuf_cs(cep,output,len,doff)
|
---|
| 776 | #define TCP_WAIT_SWBUF(cep,tmout) tcp_wait_swbuf_cs(cep,tmout)
|
---|
| 777 | #define TCP_GET_SWBUF_ADDR(cep,buf) tcp_get_swbuf_addr_cs(cep,buf)
|
---|
| 778 | #define TCP_SEND_SWBUF(cep,len) tcp_send_swbuf_cs(cep,len)
|
---|
| 779 | #define TCP_IS_SWBUF_FULL(cep) tcp_is_swbuf_full_cs(cep)
|
---|
| 780 |
|
---|
| 781 | #else /* of #ifdef TCP_CFG_SWBUF_CSAVE_ONLY */
|
---|
| 782 |
|
---|
| 783 | #define TCP_FREE_SWBUFQ(cep) tcp_free_swbufq(cep)
|
---|
| 784 | #define TCP_ALLOC_SWBUF(cep) tcp_alloc_swbuf(cep)
|
---|
| 785 | #define TCP_DROP_SWBUF(cep,len) tcp_drop_swbuf(cep,len)
|
---|
| 786 | #define TCP_WRITE_SWBUF(cep,data,len) tcp_write_swbuf(cep,data,len)
|
---|
| 787 | #define TCP_READ_SWBUF(cep,output,len,doff) tcp_read_swbuf(cep,output,len,doff)
|
---|
| 788 | #define TCP_WAIT_SWBUF(cep,tmout) tcp_wait_swbuf(cep,tmout)
|
---|
| 789 | #define TCP_GET_SWBUF_ADDR(cep,buf) tcp_get_swbuf_addr(cep,buf)
|
---|
| 790 | #define TCP_SEND_SWBUF(cep,len) tcp_send_swbuf(cep,len)
|
---|
| 791 | #define TCP_IS_SWBUF_FULL(cep) tcp_is_swbuf_full(cep)
|
---|
| 792 |
|
---|
| 793 | #endif /* of #ifdef TCP_CFG_SWBUF_CSAVE_ONLY */
|
---|
| 794 |
|
---|
| 795 | #else /* of #ifdef TCP_CFG_SWBUF_CSAVE */
|
---|
| 796 |
|
---|
| 797 | #define TCP_READ_SWBUF(cep,output,len,doff) tcp_read_swbuf_ncs(cep,output,len,doff)
|
---|
| 798 | #define TCP_FREE_SWBUFQ(cep) tcp_free_swbufq_ncs(cep)
|
---|
| 799 | #define TCP_ALLOC_SWBUF(cep) tcp_alloc_swbuf_ncs(cep)
|
---|
| 800 | #define TCP_PUSH_RES_NBUF(nbuf) tcp_push_res_nbuf_ncs(nbuf)
|
---|
| 801 | #define TCP_PULL_RES_NBUF(atr) tcp_pull_res_nbuf_ncs(atr)
|
---|
| 802 | #define TCP_DROP_SWBUF(cep,len) tcp_drop_swbuf_ncs(cep,len)
|
---|
| 803 | #define TCP_WRITE_SWBUF(cep,data,len) tcp_write_swbuf_ncs(cep,data,len)
|
---|
| 804 | #define TCP_WAIT_SWBUF(cep,tmout) tcp_wait_swbuf_ncs(cep,tmout)
|
---|
| 805 | #define TCP_GET_SWBUF_ADDR(cep,buf) tcp_get_swbuf_addr_ncs(cep,buf)
|
---|
| 806 | #define TCP_SEND_SWBUF(cep,len) tcp_send_swbuf_ncs(cep,len)
|
---|
| 807 | #define TCP_IS_SWBUF_FULL(cep) tcp_is_swbuf_full_ncs(cep)
|
---|
| 808 |
|
---|
| 809 | #endif /* of #ifdef TCP_CFG_SWBUF_CSAVE */
|
---|
| 810 |
|
---|
| 811 | /*
|
---|
| 812 | * 関数
|
---|
| 813 | */
|
---|
| 814 |
|
---|
| 815 | extern uint_t tcp_input (T_NET_BUF **inputp, uint_t *offp, uint_t *nextp);
|
---|
| 816 | extern void tcp_init (void);
|
---|
| 817 | extern void tcp_init_iss (void);
|
---|
| 818 | extern T_TCP_CEP *tcp_close (T_TCP_CEP *cep);
|
---|
| 819 | extern T_TCP_CEP *tcp_drop (T_TCP_CEP *cep, ER err);
|
---|
| 820 | extern void tcp_respond (T_NET_BUF *nbuf, T_TCP_CEP *cep,
|
---|
| 821 | T_TCP_SEQ ack, T_TCP_SEQ seq, uint_t rbfree, uint8_t flags);
|
---|
| 822 | extern ER tcp_get_segment (T_NET_BUF **nbuf, T_TCP_CEP *cep,
|
---|
| 823 | uint_t optlen, uint_t len, uint_t maxlen, ATR nbatr, TMO tmout);
|
---|
| 824 | extern ER tcpn_get_segment (T_NET_BUF **nbuf, T_TCP_CEP *cep,
|
---|
| 825 | uint_t optlen, uint_t len, uint_t maxlen, ATR nbatr, TMO tmout);
|
---|
| 826 | extern void tcp_init_cep (T_TCP_CEP *cep);
|
---|
| 827 | extern void tcp_notify (T_NET_BUF *input, int code);
|
---|
| 828 | extern T_TCP_TIME tcp_rexmt_val (T_TCP_CEP *cep);
|
---|
| 829 | extern void tcp_set_persist_timer (T_TCP_CEP *cep);
|
---|
| 830 | extern void tcp_cancel_timers (T_TCP_CEP *cep);
|
---|
| 831 | extern void tcp_alloc_auto_port (T_TCP_CEP *cep);
|
---|
| 832 | extern ER tcp_alloc_port (T_TCP_CEP *cep, uint16_t portno);
|
---|
| 833 | extern ER tcp_lock_cep (ID cepid, T_TCP_CEP **p_cep, FN tfn);
|
---|
| 834 | extern void tcp_free_reassq (T_TCP_CEP *cep);
|
---|
| 835 | extern ER tcp_can_send_more (T_TCP_CEP *cep, FN fncd, TMO tmout);
|
---|
| 836 | extern ER tcp_can_recv_more (ER *error, T_TCP_CEP *cep, FN fncd, TMO tmout);
|
---|
| 837 | extern uint8_t tcp_move_ra2rw (T_TCP_CEP *cep, uint8_t flags);
|
---|
| 838 | extern uint8_t tcp_write_raque (T_NET_BUF *input, T_TCP_CEP *cep, uint_t thoff, uint8_t flags);
|
---|
| 839 | extern ER tcp_wait_rwbuf (T_TCP_CEP *cep, TMO tmout);
|
---|
| 840 | extern T_TCP_CEP *tcp_user_closed (T_TCP_CEP *cep);
|
---|
| 841 | extern T_TCP_CEP *tcp_find_cep (T_NET_BUF *input, uint_t off);
|
---|
| 842 | extern T_TCP_TWCEP*tcp_find_twcep (T_NET_BUF *input, uint_t off);
|
---|
| 843 | extern bool_t tcp_is_addr_accept (T_NET_BUF *input, uint_t off);
|
---|
| 844 | extern void tcp_move_twcep (T_TCP_CEP *cep);
|
---|
| 845 |
|
---|
| 846 | /*
|
---|
| 847 | * TCP 通信端点の受信ウィンドバッファ用関数
|
---|
| 848 | */
|
---|
| 849 |
|
---|
| 850 | /*
|
---|
| 851 | * TCP 通信端点の受信ウィンドバッファの省コピー機能が有効の場合、
|
---|
| 852 | * 関数の選択に使用する。
|
---|
| 853 | */
|
---|
| 854 |
|
---|
| 855 | extern void tcp_free_rwbufq (T_TCP_CEP *cep);
|
---|
| 856 | extern void tcp_drop_rwbuf (T_TCP_CEP *cep, uint_t len);
|
---|
| 857 | extern void tcp_write_rwbuf (T_TCP_CEP *cep, T_NET_BUF *input, uint_t tcpoff);
|
---|
| 858 | extern uint_t tcp_read_rwbuf (T_TCP_CEP *cep, void *data, uint_t len);
|
---|
| 859 | extern uint_t tcp_get_rwbuf_addr (T_TCP_CEP *cep, void **p_buf);
|
---|
| 860 |
|
---|
| 861 | /*
|
---|
| 862 | * TCP 通信端点の受信ウィンドバッファの省コピー機能用関数
|
---|
| 863 | */
|
---|
| 864 |
|
---|
| 865 | extern void tcp_free_rwbufq_cs (T_TCP_CEP *cep);
|
---|
| 866 | extern void tcp_drop_rwbuf_cs (T_TCP_CEP *cep, uint_t len);
|
---|
| 867 | extern void tcp_write_rwbuf_cs (T_TCP_CEP *cep, T_NET_BUF *input, uint_t tcpoff);
|
---|
| 868 | extern uint_t tcp_read_rwbuf_cs (T_TCP_CEP *cep, void *data, uint_t len);
|
---|
| 869 | extern uint_t tcp_get_rwbuf_addr_cs (T_TCP_CEP *cep, void **p_buf);
|
---|
| 870 |
|
---|
| 871 | /*
|
---|
| 872 | * TCP 通信端点の受信ウィンドバッファの【非】省コピー機能用関数
|
---|
| 873 | */
|
---|
| 874 |
|
---|
| 875 | extern void tcp_free_rwbufq_ncs (T_TCP_CEP *cep);
|
---|
| 876 | extern void tcp_drop_rwbuf_ncs (T_TCP_CEP *cep, uint_t len);
|
---|
| 877 | extern void tcp_write_rwbuf_ncs (T_TCP_CEP *cep, T_NET_BUF *input, uint_t tcpoff);
|
---|
| 878 | extern uint_t tcp_read_rwbuf_ncs (T_TCP_CEP *cep, void *data, uint_t len);
|
---|
| 879 | extern uint_t tcp_get_rwbuf_addr_ncs (T_TCP_CEP *cep, void **p_buf);
|
---|
| 880 |
|
---|
| 881 | /*
|
---|
| 882 | * TCP 通信端点の送信ウィンドバッファ用関数
|
---|
| 883 | */
|
---|
| 884 |
|
---|
| 885 | /*
|
---|
| 886 | * TCP 通信端点の送信ウィンドバッファの省コピー機能が有効の場合、
|
---|
| 887 | * 関数の選択に使用する。
|
---|
| 888 | */
|
---|
| 889 |
|
---|
| 890 | extern void tcp_free_swbufq (T_TCP_CEP *cep);
|
---|
| 891 | extern void tcp_drop_swbuf (T_TCP_CEP *cep, uint_t len);
|
---|
| 892 | extern ER_UINT tcp_write_swbuf (T_TCP_CEP *cep, void *data, uint_t len);
|
---|
| 893 | extern void tcp_read_swbuf (T_TCP_CEP *cep, T_NET_BUF *output, uint_t len, uint_t doff);
|
---|
| 894 | extern void tcp_send_swbuf (T_TCP_CEP *cep, uint_t len);
|
---|
| 895 | extern ER_UINT tcp_get_swbuf_addr (T_TCP_CEP *cep, void **p_buf);
|
---|
| 896 | extern ER tcp_wait_swbuf (T_TCP_CEP *cep, TMO tmout);
|
---|
| 897 | extern T_NET_BUF *tcp_push_res_nbuf (T_NET_BUF *buf);
|
---|
| 898 | extern T_NET_BUF *tcp_pull_res_nbuf (ATR nbatr);
|
---|
| 899 | extern void tcp_alloc_swbuf (T_TCP_CEP *cep);
|
---|
| 900 | extern bool_t tcp_is_swbuf_full (T_TCP_CEP *cep);
|
---|
| 901 | extern void tcp_init_swbuf (T_TCP_CEP *cep);
|
---|
| 902 |
|
---|
| 903 | /*
|
---|
| 904 | * TCP 通信端点の送信ウィンドバッファの省コピー機能用関数
|
---|
| 905 | */
|
---|
| 906 |
|
---|
| 907 | extern void tcp_free_swbufq_cs (T_TCP_CEP *cep);
|
---|
| 908 | extern void tcp_drop_swbuf_cs (T_TCP_CEP *cep, uint_t len);
|
---|
| 909 | extern ER_UINT tcp_write_swbuf_cs (T_TCP_CEP *cep, void *data, uint_t len);
|
---|
| 910 | extern void tcp_read_swbuf_cs (T_TCP_CEP *cep, T_NET_BUF *output, uint_t len, uint_t doff);
|
---|
| 911 | extern void tcp_send_swbuf_cs (T_TCP_CEP *cep, uint_t len);
|
---|
| 912 | extern ER_UINT tcp_get_swbuf_addr_cs (T_TCP_CEP *cep, void **p_buf);
|
---|
| 913 | extern ER tcp_wait_swbuf_cs (T_TCP_CEP *cep, TMO tmout);
|
---|
| 914 | extern void tcp_alloc_swbuf_cs (T_TCP_CEP *cep);
|
---|
| 915 | extern bool_t tcp_is_swbuf_full_cs (T_TCP_CEP *cep);
|
---|
| 916 |
|
---|
| 917 | /*
|
---|
| 918 | * TCP 通信端点の送信ウィンドバッファの【非】省コピー機能用関数
|
---|
| 919 | */
|
---|
| 920 |
|
---|
| 921 | extern void tcp_free_swbufq_ncs (T_TCP_CEP *cep);
|
---|
| 922 | extern void tcp_drop_swbuf_ncs (T_TCP_CEP *cep, uint_t len);
|
---|
| 923 | extern ER_UINT tcp_write_swbuf_ncs (T_TCP_CEP *cep, void *data, uint_t len);
|
---|
| 924 | extern void tcp_read_swbuf_ncs (T_TCP_CEP *cep, T_NET_BUF *output, uint_t len, uint_t doff);
|
---|
| 925 | extern void tcp_send_swbuf_ncs (T_TCP_CEP *cep, uint_t len);
|
---|
| 926 | extern ER_UINT tcp_get_swbuf_addr_ncs (T_TCP_CEP *cep, void **p_buf);
|
---|
| 927 | extern ER tcp_wait_swbuf_ncs (T_TCP_CEP *cep, TMO tmout);
|
---|
| 928 | extern T_NET_BUF *tcp_push_res_nbuf_ncs (T_NET_BUF *buf);
|
---|
| 929 | extern T_NET_BUF *tcp_pull_res_nbuf_ncs (ATR nbatr);
|
---|
| 930 | extern void tcp_alloc_swbuf_ncs (T_TCP_CEP *cep);
|
---|
| 931 | extern bool_t tcp_is_swbuf_full_ncs (T_TCP_CEP *cep);
|
---|
| 932 |
|
---|
| 933 | /*
|
---|
| 934 | * TCP ヘッダのトレース出力機能用関数
|
---|
| 935 | */
|
---|
| 936 | extern void tcp_output_trace (T_NET_BUF *output, T_TCP_CEP *cep);
|
---|
| 937 | extern void tcp_input_trace (T_NET_BUF *input, T_TCP_CEP *cep);
|
---|
| 938 |
|
---|
| 939 | /* TCP 出力タスク */
|
---|
| 940 |
|
---|
| 941 | extern void tcp_output_task(intptr_t exinf);
|
---|
| 942 |
|
---|
| 943 | #endif /* of #ifndef _TCP_VAR_H_ */
|
---|