[270] | 1 | /*
|
---|
| 2 | * TINET (TCP/IP Protocol Stack)
|
---|
| 3 | *
|
---|
[331] | 4 | * Copyright (C) 2001-2017 by Dep. of Computer Science and Engineering
|
---|
[270] | 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, 1988, 1990, 1993, 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_timer.c 8.2 (Berkeley) 5/24/95
|
---|
| 67 | * $FreeBSD: src/sys/netinet/tcp_timer.c,v 1.28.2.1 1999/08/29 16:29:56 peter Exp $
|
---|
| 68 | */
|
---|
| 69 |
|
---|
| 70 | #ifdef TARGET_KERNEL_ASP
|
---|
| 71 |
|
---|
| 72 | #include <kernel.h>
|
---|
| 73 | #include <sil.h>
|
---|
| 74 | #include "kernel_cfg.h"
|
---|
| 75 |
|
---|
| 76 | #endif /* of #ifdef TARGET_KERNEL_ASP */
|
---|
| 77 |
|
---|
| 78 | #ifdef TARGET_KERNEL_JSP
|
---|
| 79 |
|
---|
| 80 | #include <s_services.h>
|
---|
| 81 | #include <t_services.h>
|
---|
| 82 | #include "kernel_id.h"
|
---|
| 83 |
|
---|
| 84 | #endif /* of #ifdef TARGET_KERNEL_JSP */
|
---|
| 85 |
|
---|
| 86 | #include <tinet_defs.h>
|
---|
| 87 | #include <tinet_config.h>
|
---|
| 88 |
|
---|
| 89 | #include <net/if.h>
|
---|
| 90 | #include <net/if_ppp.h>
|
---|
| 91 | #include <net/if_loop.h>
|
---|
| 92 | #include <net/ethernet.h>
|
---|
[331] | 93 | #include <net/net_endian.h>
|
---|
[270] | 94 | #include <net/net_var.h>
|
---|
| 95 | #include <net/net_timer.h>
|
---|
| 96 |
|
---|
| 97 | #include <netinet/in.h>
|
---|
| 98 | #include <netinet/in_var.h>
|
---|
| 99 | #include <netinet/ip.h>
|
---|
| 100 | #include <netinet/tcp.h>
|
---|
| 101 | #include <netinet/tcp_var.h>
|
---|
| 102 | #include <netinet/tcp_fsm.h>
|
---|
| 103 | #include <netinet/tcp_seq.h>
|
---|
[331] | 104 | #include <netinet/tcp_timer.h>
|
---|
[270] | 105 |
|
---|
| 106 | #ifdef SUPPORT_TCP
|
---|
| 107 |
|
---|
| 108 | /*
|
---|
| 109 | * 局所関数
|
---|
| 110 | */
|
---|
| 111 |
|
---|
| 112 | static T_TCP_CEP *tcp_timers (T_TCP_CEP *cep, int_t tix);
|
---|
| 113 |
|
---|
| 114 | #if defined(NUM_TCP_TW_CEP_ENTRY) && NUM_TCP_TW_CEP_ENTRY > 0
|
---|
| 115 |
|
---|
| 116 | static void tcp_tw_timo (void);
|
---|
| 117 |
|
---|
| 118 | #endif /* of #if defined(NUM_TCP_TW_CEP_ENTRY) && NUM_TCP_TW_CEP_ENTRY > 0 */
|
---|
| 119 |
|
---|
| 120 | /*
|
---|
| 121 | * バックオフ時間
|
---|
| 122 | *
|
---|
| 123 | * 再送を行うたびに、タイムアウトの時間を延長する。
|
---|
| 124 | */
|
---|
| 125 |
|
---|
| 126 | const static uint8_t tcp_back_off[] = {
|
---|
| 127 | UINT_C(1), UINT_C(2), UINT_C(4), UINT_C(8),
|
---|
| 128 | UINT_C(16), UINT_C(32), UINT_C(64), UINT_C(64),
|
---|
| 129 | UINT_C(64), UINT_C(64), UINT_C(64), UINT_C(64),
|
---|
| 130 | UINT_C(64)
|
---|
| 131 | };
|
---|
| 132 |
|
---|
| 133 | #define TCP_TOTAL_BACK_OFF 511 /* バックオフ時間の合計 */
|
---|
| 134 |
|
---|
| 135 | /*
|
---|
| 136 | * tcp_timers -- タイムアウト処理
|
---|
| 137 | */
|
---|
| 138 |
|
---|
| 139 | static T_TCP_CEP *
|
---|
| 140 | tcp_timers (T_TCP_CEP *cep, int_t tix)
|
---|
| 141 | {
|
---|
| 142 | uint16_t win;
|
---|
| 143 |
|
---|
| 144 |
|
---|
| 145 | switch (tix) {
|
---|
| 146 |
|
---|
| 147 | /*
|
---|
| 148 | * 再送タイマ
|
---|
| 149 | */
|
---|
| 150 | case TCP_TIM_REXMT:
|
---|
| 151 |
|
---|
| 152 | /*
|
---|
| 153 | * 最大再送回数 (TCP_MAX_REXMT_SHIFT、標準 12 回) になったときは、
|
---|
| 154 | * コネクションを切断する。
|
---|
| 155 | */
|
---|
| 156 | if (++ cep->rxtshift > TCP_MAX_REXMT_SHIFT) {
|
---|
| 157 | cep->rxtshift = TCP_MAX_REXMT_SHIFT;
|
---|
| 158 | cep->net_error = EV_REXMTMO;
|
---|
| 159 | cep = tcp_drop(cep, E_CLS);
|
---|
| 160 | break;
|
---|
| 161 | }
|
---|
| 162 |
|
---|
| 163 | /*
|
---|
| 164 | * 再送タイムアウトを計算する。
|
---|
| 165 | */
|
---|
| 166 | cep->rxtcur = tcp_range_set((T_TCP_TIME)(tcp_rexmt_val(cep) * tcp_back_off[cep->rxtshift]),
|
---|
| 167 | (T_TCP_TIME)TCP_TVAL_MIN,
|
---|
| 168 | (T_TCP_TIME)TCP_TVAL_MAX_REXMT);
|
---|
| 169 | cep->timer[TCP_TIM_REXMT] = cep->rxtcur;
|
---|
| 170 |
|
---|
| 171 | /*
|
---|
| 172 | * srtt: 平滑化された RTT
|
---|
| 173 | * rttvar: 平滑化された分散
|
---|
| 174 | *
|
---|
| 175 | * 再送回数が最大再送回数の 1/4 になったときは、
|
---|
| 176 | * 平滑化された分散 (rttvar) に srtt を加算し、
|
---|
| 177 | * 平滑化された RTT を 0 にする。
|
---|
| 178 | *
|
---|
| 179 | */
|
---|
| 180 | if (cep->rxtshift > TCP_MAX_REXMT_SHIFT / 4) {
|
---|
| 181 | cep->rttvar += (cep->srtt >> TCP_SRTT_SHIFT);
|
---|
| 182 | cep->srtt = 0;
|
---|
| 183 | }
|
---|
| 184 |
|
---|
| 185 | /*
|
---|
| 186 | * snd_nxt: 次に送信する SEQ、この時点では、前回送信した SEQ
|
---|
| 187 | * snd_una: 未確認の最小送信 SEQ または、確認された最大送信 SEQ
|
---|
| 188 | *
|
---|
| 189 | * 前回送信した SEQ (snd_nxt) を
|
---|
| 190 | * 確認された最大送信 SEQ (snd_una) まで戻す。
|
---|
| 191 | */
|
---|
| 192 | cep->snd_nxt = cep->snd_una;
|
---|
| 193 | cep->flags |= TCP_CEP_FLG_ACK_NOW;
|
---|
| 194 |
|
---|
| 195 | /*
|
---|
| 196 | * rtt: 往復時間の計測を中止する。
|
---|
| 197 | */
|
---|
| 198 | cep->rtt = 0;
|
---|
| 199 |
|
---|
| 200 | /*
|
---|
| 201 | * 送信ウインドの設定
|
---|
| 202 | *
|
---|
| 203 | * snd_wnd: 相手の受信可能ウィンドサイズ
|
---|
| 204 | * snd_cwnd: 輻輳ウィンドサイズ
|
---|
| 205 | * maxseg : 相手の最大受信セグメントサイズ
|
---|
| 206 | *
|
---|
| 207 | * 相手の受信可能ウィンドサイズ (snd_wnd) か、
|
---|
| 208 | * 輻輳ウィンドサイズ (snd_cwnd) の
|
---|
| 209 | * どちらか小さいサイズの 1/2 を、更に
|
---|
| 210 | * 相手の最大受信セグメントサイズ (maxseg) で割った値。
|
---|
| 211 | * ただし、2 以上
|
---|
| 212 | */
|
---|
| 213 | if (cep->snd_wnd < cep->snd_cwnd)
|
---|
| 214 | win = cep->snd_wnd / 2 / cep->maxseg;
|
---|
| 215 | else
|
---|
| 216 | win = cep->snd_cwnd / 2 / cep->maxseg;
|
---|
| 217 |
|
---|
| 218 | if (win < 2)
|
---|
| 219 | win = 2;
|
---|
| 220 |
|
---|
| 221 | /*
|
---|
| 222 | * 輻輳ウィンドサイズ (snd_cwnd) は
|
---|
| 223 | * 相手の受信可能ウィンドサイズ (snd_wnd) に、
|
---|
| 224 | * 輻輳ウィンドサイズのしきい値 (snd_ssthresh) は
|
---|
| 225 | * 相手の受信可能ウィンドサイズ (snd_wnd) の win 倍に
|
---|
| 226 | * 設定する。
|
---|
| 227 | */
|
---|
| 228 | cep->snd_cwnd = cep->maxseg;
|
---|
| 229 | cep->snd_ssthresh = win * cep->maxseg;
|
---|
| 230 | cep->dupacks = 0;
|
---|
| 231 |
|
---|
| 232 | /* 出力をポストする。*/
|
---|
| 233 | cep->flags |= TCP_CEP_FLG_POST_OUTPUT;
|
---|
| 234 | sig_sem(SEM_TCP_POST_OUTPUT);
|
---|
| 235 | break;
|
---|
| 236 |
|
---|
| 237 | /*
|
---|
| 238 | * 持続タイマ
|
---|
| 239 | */
|
---|
| 240 | case TCP_TIM_PERSIST:
|
---|
| 241 |
|
---|
| 242 | /*
|
---|
| 243 | * 最大再送回数 (TCP_MAX_REXMT_SHIFT、標準 12 回) を超えていて、
|
---|
| 244 | * アイドル時間が、保留タイマの標準値 (TCP_TVAL_KEEP_IDLE、
|
---|
| 245 | * 標準 2 * 60 * 60 秒) 以上か、
|
---|
| 246 | * 再送タイムアウト値 * バックオフ時間の合計以上なら
|
---|
| 247 | * コネクションを切断する。
|
---|
| 248 | */
|
---|
| 249 | if (cep->rxtshift > TCP_MAX_REXMT_SHIFT &&
|
---|
| 250 | (cep->idle >= TCP_TVAL_KEEP_IDLE ||
|
---|
| 251 | cep->idle >= tcp_rexmt_val(cep) * TCP_TOTAL_BACK_OFF)) {
|
---|
| 252 | cep->net_error = EV_REXMTMO;
|
---|
| 253 | cep = tcp_drop(cep, E_CLS);
|
---|
| 254 | break;
|
---|
| 255 | }
|
---|
| 256 |
|
---|
| 257 | /* 持続タイマを再設定し、出力をポストする。*/
|
---|
| 258 | tcp_set_persist_timer(cep);
|
---|
| 259 |
|
---|
| 260 | cep->flags |= TCP_CEP_FLG_FORCE | TCP_CEP_FLG_FORCE_CLEAR | TCP_CEP_FLG_POST_OUTPUT;
|
---|
| 261 | sig_sem(SEM_TCP_POST_OUTPUT);
|
---|
| 262 | break;
|
---|
| 263 |
|
---|
| 264 | /*
|
---|
| 265 | * 保留 (keep alive) タイマ
|
---|
| 266 | */
|
---|
| 267 | case TCP_TIM_KEEP:
|
---|
| 268 |
|
---|
| 269 | /*
|
---|
| 270 | * コネクションが開設されるまでにタイムアウトしたら
|
---|
| 271 | * コネクションの開設を中止する。
|
---|
| 272 | */
|
---|
| 273 | if (cep->fsm_state < TCP_FSM_ESTABLISHED) {
|
---|
| 274 | cep->net_error = EV_REXMTMO;
|
---|
| 275 | cep = tcp_drop(cep, E_CLS);
|
---|
| 276 | break;
|
---|
| 277 | }
|
---|
| 278 |
|
---|
| 279 | #ifdef TCP_CFG_ALWAYS_KEEP
|
---|
| 280 |
|
---|
| 281 | else if (cep->fsm_state < TCP_FSM_CLOSING) {
|
---|
| 282 | if (cep->idle >= TCP_TVAL_KEEP_IDLE +
|
---|
| 283 | TCP_TVAL_KEEP_COUNT * TCP_TVAL_KEEP_INTERVAL) {
|
---|
| 284 | cep->net_error = EV_REXMTMO;
|
---|
| 285 | cep = tcp_drop(cep, E_CLS);
|
---|
| 286 | break;
|
---|
| 287 | }
|
---|
| 288 | else
|
---|
| 289 | tcp_respond(NULL, cep, cep->rcv_nxt, cep->snd_una - 1,
|
---|
| 290 | cep->rbufsz - cep->rwbuf_count, 0);
|
---|
| 291 | cep->timer[TCP_TIM_KEEP] = TCP_TVAL_KEEP_INTERVAL;
|
---|
| 292 | }
|
---|
| 293 | else
|
---|
| 294 | cep->timer[TCP_TIM_KEEP] = TCP_TVAL_KEEP_IDLE;
|
---|
| 295 |
|
---|
| 296 | #else /* of #ifdef TCP_CFG_ALWAYS_KEEP */
|
---|
| 297 |
|
---|
| 298 | cep->timer[TCP_TIM_KEEP] = TCP_TVAL_KEEP_IDLE;
|
---|
| 299 |
|
---|
| 300 | #endif /* of #ifdef TCP_CFG_ALWAYS_KEEP */
|
---|
| 301 |
|
---|
| 302 | break;
|
---|
| 303 |
|
---|
| 304 | /*
|
---|
| 305 | * 2MSL タイマ
|
---|
| 306 | */
|
---|
| 307 | case TCP_TIM_2MSL:
|
---|
| 308 |
|
---|
| 309 | if (cep->fsm_state != TCP_FSM_TIME_WAIT &&
|
---|
| 310 | cep->idle <= TCP_TVAL_KEEP_COUNT * TCP_TVAL_KEEP_INTERVAL)
|
---|
| 311 | cep->timer[TCP_TIM_2MSL] = TCP_TVAL_KEEP_INTERVAL;
|
---|
| 312 | else
|
---|
| 313 | cep = tcp_close(cep);
|
---|
| 314 | break;
|
---|
| 315 | }
|
---|
| 316 |
|
---|
| 317 | return cep;
|
---|
| 318 | }
|
---|
| 319 |
|
---|
| 320 | /*
|
---|
| 321 | * tcp_cancel_timers -- 全てのタイマをキャンセルする。
|
---|
| 322 | */
|
---|
| 323 |
|
---|
| 324 | void
|
---|
| 325 | tcp_cancel_timers (T_TCP_CEP *cep)
|
---|
| 326 | {
|
---|
| 327 | int_t ix;
|
---|
| 328 |
|
---|
| 329 | for (ix = NUM_TCP_TIMERS; ix -- > 0; )
|
---|
| 330 | cep->timer[ix] = 0;
|
---|
| 331 | }
|
---|
| 332 |
|
---|
| 333 | #if defined(NUM_TCP_TW_CEP_ENTRY) && NUM_TCP_TW_CEP_ENTRY > 0
|
---|
| 334 |
|
---|
| 335 | /*
|
---|
| 336 | * tcp_tw_timo -- Time Wait 用 TCP 通信端点のタイムアウト処理
|
---|
| 337 | */
|
---|
| 338 |
|
---|
| 339 | void
|
---|
| 340 | tcp_tw_timo (void)
|
---|
| 341 | {
|
---|
| 342 | T_TCP_CEP *cep, *lcep;
|
---|
| 343 | T_TCP_TWCEP* twcep;
|
---|
| 344 | T_TCP_TIME longer;
|
---|
| 345 | int_t frees, waits;
|
---|
| 346 |
|
---|
| 347 | /*
|
---|
| 348 | * Time Wait 用 TCP 通信端点でタイムアウトのエントリを探索し、
|
---|
| 349 | * 探索したエントリを空きにする。
|
---|
| 350 | */
|
---|
| 351 | frees = 0;
|
---|
| 352 | for (twcep = &tcp_twcep[NUM_TCP_TW_CEP_ENTRY]; twcep -- != tcp_twcep; )
|
---|
| 353 | if (twcep->fsm_state == TCP_FSM_TIME_WAIT && -- twcep->timer_2msl == 0) {
|
---|
| 354 | twcep->fsm_state = TCP_FSM_CLOSED;
|
---|
| 355 | frees ++;
|
---|
| 356 | }
|
---|
| 357 |
|
---|
| 358 | /*
|
---|
| 359 | * Time Wait 用 TCP 通信端点の空きエントリが発生したら
|
---|
| 360 | * 標準 TCP 通信端点で Time Wait 中の TCP 通信端点を探索し、
|
---|
| 361 | * 必要な情報を Time Wait 用 TCP 通信端点に移して、
|
---|
| 362 | * 標準の TCP 通信端点を開放する。
|
---|
| 363 | */
|
---|
| 364 | if (frees > 0) {
|
---|
| 365 | waits = 0;
|
---|
| 366 | for (cep = &tcp_cep[tmax_tcp_cepid]; cep -- != tcp_cep; )
|
---|
| 367 | if (cep->fsm_state == TCP_FSM_TIME_WAIT)
|
---|
| 368 | waits ++;
|
---|
| 369 | if (waits > frees)
|
---|
| 370 | waits = frees;
|
---|
| 371 |
|
---|
| 372 | /*
|
---|
| 373 | * もっとも長い間 Time Wait している TCP 通信端点を開放する。
|
---|
| 374 | */
|
---|
| 375 | while (waits > 0) {
|
---|
| 376 | longer = TCP_TVAL_MSL * 2;
|
---|
| 377 | lcep = NULL;
|
---|
| 378 | for (cep = &tcp_cep[tmax_tcp_cepid]; cep -- != tcp_cep; )
|
---|
| 379 | if (cep->fsm_state == TCP_FSM_TIME_WAIT && cep->timer[TCP_TIM_2MSL] < longer) {
|
---|
| 380 | longer = cep->timer[TCP_TIM_2MSL];
|
---|
| 381 | lcep = cep;
|
---|
| 382 | }
|
---|
| 383 | if (lcep != NULL) {
|
---|
| 384 | tcp_move_twcep(lcep);
|
---|
| 385 | waits --;
|
---|
| 386 | }
|
---|
| 387 | else
|
---|
| 388 | break;
|
---|
| 389 | }
|
---|
| 390 | }
|
---|
| 391 | }
|
---|
| 392 |
|
---|
| 393 | #endif /* of #if defined(NUM_TCP_TW_CEP_ENTRY) && NUM_TCP_TW_CEP_ENTRY > 0 */
|
---|
| 394 |
|
---|
| 395 | /*
|
---|
| 396 | * tcp_slow_timo -- 500 [ms] 毎に呼出される TCP タイムアウト関数
|
---|
| 397 | */
|
---|
| 398 |
|
---|
| 399 | void
|
---|
| 400 | tcp_slow_timo (void *ignore)
|
---|
| 401 | {
|
---|
| 402 | T_TCP_CEP *cep;
|
---|
| 403 | int_t cix, tix;
|
---|
| 404 |
|
---|
| 405 | for (cix = tmax_tcp_cepid; cix -- > 0; ) {
|
---|
| 406 | cep = &tcp_cep[cix];
|
---|
| 407 | if (!(cep->fsm_state == TCP_FSM_CLOSED || cep->fsm_state == TCP_FSM_LISTEN)) {
|
---|
| 408 | for (tix = NUM_TCP_TIMERS; cep != NULL && tix -- > 0; ) {
|
---|
| 409 | if (cep->timer[tix] != 0 && -- cep->timer[tix] == 0) {
|
---|
| 410 | cep = tcp_timers(cep, tix);
|
---|
| 411 | }
|
---|
| 412 | }
|
---|
| 413 | if (cep != NULL) {
|
---|
| 414 | cep->idle ++;
|
---|
| 415 | if (cep->rtt) {
|
---|
| 416 | cep->rtt ++;
|
---|
| 417 | }
|
---|
| 418 | }
|
---|
| 419 | }
|
---|
| 420 | }
|
---|
| 421 |
|
---|
| 422 | #if defined(NUM_TCP_TW_CEP_ENTRY) && NUM_TCP_TW_CEP_ENTRY > 0
|
---|
| 423 |
|
---|
| 424 | tcp_tw_timo();
|
---|
| 425 |
|
---|
| 426 | #endif /* of #if defined(NUM_TCP_TW_CEP_ENTRY) && NUM_TCP_TW_CEP_ENTRY > 0 */
|
---|
| 427 |
|
---|
| 428 | if (tcp_iss != 0) {
|
---|
| 429 | tcp_iss += TCP_ISS_INCR() / TCP_SLOW_HZ;
|
---|
| 430 | }
|
---|
| 431 |
|
---|
| 432 | timeout(tcp_slow_timo, NULL, TCP_SLOW_TMO);
|
---|
| 433 | }
|
---|
| 434 |
|
---|
| 435 | #ifdef TCP_CFG_DELAY_ACK
|
---|
| 436 |
|
---|
| 437 | /*
|
---|
| 438 | * tcp_fast_timo -- 200 [ms] 毎に呼出される TCP タイムアウト関数
|
---|
| 439 | */
|
---|
| 440 |
|
---|
| 441 | void
|
---|
| 442 | tcp_fast_timo (void *ignore)
|
---|
| 443 | {
|
---|
| 444 | T_TCP_CEP *cep;
|
---|
| 445 | int_t cix;
|
---|
| 446 |
|
---|
| 447 | for (cix = tmax_tcp_cepid; cix -- > 0; ) {
|
---|
| 448 | cep = &tcp_cep[cix];
|
---|
| 449 | if (cep->flags & TCP_CEP_FLG_DEL_ACK) {
|
---|
| 450 | cep->flags &= ~TCP_CEP_FLG_DEL_ACK;
|
---|
| 451 | cep->flags |= TCP_CEP_FLG_ACK_NOW | TCP_CEP_FLG_POST_OUTPUT;
|
---|
| 452 | sig_sem(SEM_TCP_POST_OUTPUT);
|
---|
| 453 | }
|
---|
| 454 | }
|
---|
| 455 |
|
---|
| 456 | timeout(tcp_fast_timo, NULL, TCP_FAST_TMO);
|
---|
| 457 | }
|
---|
| 458 |
|
---|
| 459 | #endif/* of #ifdef TCP_CFG_DELAY_ACK */
|
---|
| 460 |
|
---|
| 461 | /*
|
---|
| 462 | * tcp_range_set -- 時間を指定した範囲に設定する。
|
---|
| 463 | */
|
---|
| 464 |
|
---|
| 465 | T_TCP_TIME
|
---|
| 466 | tcp_range_set (T_TCP_TIME value, T_TCP_TIME tvmin, T_TCP_TIME tvmax)
|
---|
| 467 | {
|
---|
| 468 | if ((uint32_t)value < (uint32_t)tvmin)
|
---|
| 469 | return tvmin;
|
---|
| 470 | else if ((uint32_t)value > (uint32_t)tvmax)
|
---|
| 471 | return tvmax;
|
---|
| 472 | else
|
---|
| 473 | return value;
|
---|
| 474 | }
|
---|
| 475 |
|
---|
| 476 | /*
|
---|
| 477 | * tcp_set_persist_timer -- 持続タイマの設定
|
---|
| 478 | */
|
---|
| 479 |
|
---|
| 480 | void
|
---|
| 481 | tcp_set_persist_timer (T_TCP_CEP *cep)
|
---|
| 482 | {
|
---|
| 483 | T_TCP_TIME time;
|
---|
| 484 |
|
---|
| 485 | /*
|
---|
| 486 | * srtt: 平滑化された RTT
|
---|
| 487 | * rttvar: 平滑化された分散
|
---|
| 488 | */
|
---|
| 489 | time = ((cep->srtt >> 2) + cep->rttvar) >> 1;
|
---|
| 490 |
|
---|
| 491 | /*
|
---|
| 492 | * 再送タイマも設定されていれば回復不能エラー
|
---|
| 493 | */
|
---|
| 494 | if (cep->timer[TCP_TIM_REXMT])
|
---|
| 495 | /* %%% panic("tcp_output REXMT"); %%% */;
|
---|
| 496 |
|
---|
| 497 | /*
|
---|
| 498 | * 持続タイマを設定する。
|
---|
| 499 | */
|
---|
| 500 | cep->timer[TCP_TIM_PERSIST] = tcp_range_set((T_TCP_TIME)(time * tcp_back_off[cep->rxtshift]),
|
---|
| 501 | (T_TCP_TIME)TCP_TVAL_MIN_PERSIST,
|
---|
| 502 | (T_TCP_TIME)TCP_TVAL_MAX_PERSIST);
|
---|
| 503 |
|
---|
| 504 | /*
|
---|
| 505 | * 再送回数を更新する。
|
---|
| 506 | */
|
---|
| 507 | if (cep->rxtshift < TCP_MAX_REXMT_SHIFT)
|
---|
| 508 | cep->rxtshift ++;
|
---|
| 509 | }
|
---|
| 510 |
|
---|
| 511 | #endif /* of #ifdef SUPPORT_TCP */
|
---|