[270] | 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 | * ä¸è¨èä½æ¨©è
|
---|
| 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: tcp_timer.c 270 2017-02-09 04:03:47Z coas-nagasima $
|
---|
| 44 | */
|
---|
| 45 |
|
---|
| 46 | /*
|
---|
| 47 | * Copyright (c) 1982, 1986, 1988, 1990, 1993, 1995
|
---|
| 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 | * @(#)tcp_timer.c 8.2 (Berkeley) 5/24/95
|
---|
| 79 | * $FreeBSD: src/sys/netinet/tcp_timer.c,v 1.28.2.1 1999/08/29 16:29:56 peter Exp $
|
---|
| 80 | */
|
---|
| 81 |
|
---|
| 82 | #ifdef TARGET_KERNEL_ASP
|
---|
| 83 |
|
---|
| 84 | #include <kernel.h>
|
---|
| 85 | #include <sil.h>
|
---|
| 86 | #include "kernel_cfg.h"
|
---|
| 87 |
|
---|
| 88 | #endif /* of #ifdef TARGET_KERNEL_ASP */
|
---|
| 89 |
|
---|
| 90 | #ifdef TARGET_KERNEL_JSP
|
---|
| 91 |
|
---|
| 92 | #include <s_services.h>
|
---|
| 93 | #include <t_services.h>
|
---|
| 94 | #include "kernel_id.h"
|
---|
| 95 |
|
---|
| 96 | #endif /* of #ifdef TARGET_KERNEL_JSP */
|
---|
| 97 |
|
---|
| 98 | #include <tinet_defs.h>
|
---|
| 99 | #include <tinet_config.h>
|
---|
| 100 |
|
---|
| 101 | #include <net/if.h>
|
---|
| 102 | #include <net/if_ppp.h>
|
---|
| 103 | #include <net/if_loop.h>
|
---|
| 104 | #include <net/ethernet.h>
|
---|
| 105 | #include <net/net.h>
|
---|
| 106 | #include <net/net_var.h>
|
---|
| 107 | #include <net/net_buf.h>
|
---|
| 108 | #include <net/net_timer.h>
|
---|
| 109 |
|
---|
| 110 | #include <netinet/in.h>
|
---|
| 111 | #include <netinet/in_var.h>
|
---|
| 112 | #include <netinet6/in6.h>
|
---|
| 113 | #include <netinet6/in6_var.h>
|
---|
| 114 | #include <netinet/ip.h>
|
---|
| 115 | #include <netinet/ip6.h>
|
---|
| 116 | #include <netinet/tcp.h>
|
---|
| 117 | #include <netinet/tcp_timer.h>
|
---|
| 118 | #include <netinet/tcp_var.h>
|
---|
| 119 | #include <netinet/tcp_fsm.h>
|
---|
| 120 | #include <netinet/tcp_seq.h>
|
---|
| 121 |
|
---|
| 122 | #ifdef SUPPORT_TCP
|
---|
| 123 |
|
---|
| 124 | /*
|
---|
| 125 | * å±æé¢æ°
|
---|
| 126 | */
|
---|
| 127 |
|
---|
| 128 | static T_TCP_CEP *tcp_timers (T_TCP_CEP *cep, int_t tix);
|
---|
| 129 |
|
---|
| 130 | #if defined(NUM_TCP_TW_CEP_ENTRY) && NUM_TCP_TW_CEP_ENTRY > 0
|
---|
| 131 |
|
---|
| 132 | static void tcp_tw_timo (void);
|
---|
| 133 |
|
---|
| 134 | #endif /* of #if defined(NUM_TCP_TW_CEP_ENTRY) && NUM_TCP_TW_CEP_ENTRY > 0 */
|
---|
| 135 |
|
---|
| 136 | /*
|
---|
| 137 | * ããã¯ãªãæé
|
---|
| 138 | *
|
---|
| 139 | * åéãè¡ããã³ã«ãã¿ã¤ã ã¢ã¦ãã®æéã延é·ããã
|
---|
| 140 | */
|
---|
| 141 |
|
---|
| 142 | const static uint8_t tcp_back_off[] = {
|
---|
| 143 | UINT_C(1), UINT_C(2), UINT_C(4), UINT_C(8),
|
---|
| 144 | UINT_C(16), UINT_C(32), UINT_C(64), UINT_C(64),
|
---|
| 145 | UINT_C(64), UINT_C(64), UINT_C(64), UINT_C(64),
|
---|
| 146 | UINT_C(64)
|
---|
| 147 | };
|
---|
| 148 |
|
---|
| 149 | #define TCP_TOTAL_BACK_OFF 511 /* ããã¯ãªãæéã®åè¨ */
|
---|
| 150 |
|
---|
| 151 | /*
|
---|
| 152 | * tcp_timers -- ã¿ã¤ã ã¢ã¦ãå¦ç
|
---|
| 153 | */
|
---|
| 154 |
|
---|
| 155 | static T_TCP_CEP *
|
---|
| 156 | tcp_timers (T_TCP_CEP *cep, int_t tix)
|
---|
| 157 | {
|
---|
| 158 | uint16_t win;
|
---|
| 159 |
|
---|
| 160 |
|
---|
| 161 | switch (tix) {
|
---|
| 162 |
|
---|
| 163 | /*
|
---|
| 164 | * åéã¿ã¤ã
|
---|
| 165 | */
|
---|
| 166 | case TCP_TIM_REXMT:
|
---|
| 167 |
|
---|
| 168 | /*
|
---|
| 169 | * æ大åéåæ° (TCP_MAX_REXMT_SHIFTãæ¨æº 12 å) ã«ãªã£ãã¨ãã¯ã
|
---|
| 170 | * ã³ãã¯ã·ã§ã³ãåæããã
|
---|
| 171 | */
|
---|
| 172 | if (++ cep->rxtshift > TCP_MAX_REXMT_SHIFT) {
|
---|
| 173 | cep->rxtshift = TCP_MAX_REXMT_SHIFT;
|
---|
| 174 | cep->net_error = EV_REXMTMO;
|
---|
| 175 | cep = tcp_drop(cep, E_CLS);
|
---|
| 176 | break;
|
---|
| 177 | }
|
---|
| 178 |
|
---|
| 179 | /*
|
---|
| 180 | * åéã¿ã¤ã ã¢ã¦ããè¨ç®ããã
|
---|
| 181 | */
|
---|
| 182 | cep->rxtcur = tcp_range_set((T_TCP_TIME)(tcp_rexmt_val(cep) * tcp_back_off[cep->rxtshift]),
|
---|
| 183 | (T_TCP_TIME)TCP_TVAL_MIN,
|
---|
| 184 | (T_TCP_TIME)TCP_TVAL_MAX_REXMT);
|
---|
| 185 | cep->timer[TCP_TIM_REXMT] = cep->rxtcur;
|
---|
| 186 |
|
---|
| 187 | /*
|
---|
| 188 | * srtt: å¹³æ»åããã RTT
|
---|
| 189 | * rttvar: å¹³æ»åãããåæ£
|
---|
| 190 | *
|
---|
| 191 | * åéåæ°ãæ大åéåæ°ã® 1/4 ã«ãªã£ãã¨ãã¯ã
|
---|
| 192 | * å¹³æ»åãããåæ£ (rttvar) ã« srtt ãå ç®ãã
|
---|
| 193 | * å¹³æ»åããã RTT ã 0 ã«ããã
|
---|
| 194 | *
|
---|
| 195 | */
|
---|
| 196 | if (cep->rxtshift > TCP_MAX_REXMT_SHIFT / 4) {
|
---|
| 197 | cep->rttvar += (cep->srtt >> TCP_SRTT_SHIFT);
|
---|
| 198 | cep->srtt = 0;
|
---|
| 199 | }
|
---|
| 200 |
|
---|
| 201 | /*
|
---|
| 202 | * snd_nxt: 次ã«éä¿¡ãã SEQããã®æç¹ã§ã¯ãååéä¿¡ãã SEQ
|
---|
| 203 | * snd_una: æªç¢ºèªã®æå°éä¿¡ SEQ ã¾ãã¯ã確èªãããæ大éä¿¡ SEQ
|
---|
| 204 | *
|
---|
| 205 | * ååéä¿¡ãã SEQ (snd_nxt) ã
|
---|
| 206 | * 確èªãããæ大éä¿¡ SEQ (snd_una) ã¾ã§æ»ãã
|
---|
| 207 | */
|
---|
| 208 | cep->snd_nxt = cep->snd_una;
|
---|
| 209 | cep->flags |= TCP_CEP_FLG_ACK_NOW;
|
---|
| 210 |
|
---|
| 211 | /*
|
---|
| 212 | * rtt: å¾å¾©æéã®è¨æ¸¬ãä¸æ¢ããã
|
---|
| 213 | */
|
---|
| 214 | cep->rtt = 0;
|
---|
| 215 |
|
---|
| 216 | /*
|
---|
| 217 | * éä¿¡ã¦ã¤ã³ãã®è¨å®
|
---|
| 218 | *
|
---|
| 219 | * snd_wnd: ç¸æã®åä¿¡å¯è½ã¦ã£ã³ããµã¤ãº
|
---|
| 220 | * snd_cwnd: 輻輳ã¦ã£ã³ããµã¤ãº
|
---|
| 221 | * maxseg : ç¸æã®æ大åä¿¡ã»ã°ã¡ã³ããµã¤ãº
|
---|
| 222 | *
|
---|
| 223 | * ç¸æã®åä¿¡å¯è½ã¦ã£ã³ããµã¤ãº (snd_wnd) ãã
|
---|
| 224 | * 輻輳ã¦ã£ã³ããµã¤ãº (snd_cwnd) ã®
|
---|
| 225 | * ã©ã¡ããå°ãããµã¤ãºã® 1/2 ããæ´ã«
|
---|
| 226 | * ç¸æã®æ大åä¿¡ã»ã°ã¡ã³ããµã¤ãº (maxseg) ã§å²ã£ãå¤ã
|
---|
| 227 | * ãã ãã2 以ä¸
|
---|
| 228 | */
|
---|
| 229 | if (cep->snd_wnd < cep->snd_cwnd)
|
---|
| 230 | win = cep->snd_wnd / 2 / cep->maxseg;
|
---|
| 231 | else
|
---|
| 232 | win = cep->snd_cwnd / 2 / cep->maxseg;
|
---|
| 233 |
|
---|
| 234 | if (win < 2)
|
---|
| 235 | win = 2;
|
---|
| 236 |
|
---|
| 237 | /*
|
---|
| 238 | * 輻輳ã¦ã£ã³ããµã¤ãº (snd_cwnd) ã¯
|
---|
| 239 | * ç¸æã®åä¿¡å¯è½ã¦ã£ã³ããµã¤ãº (snd_wnd) ã«ã
|
---|
| 240 | * 輻輳ã¦ã£ã³ããµã¤ãºã®ãããå¤ (snd_ssthresh) ã¯
|
---|
| 241 | * ç¸æã®åä¿¡å¯è½ã¦ã£ã³ããµã¤ãº (snd_wnd) ã® win åã«
|
---|
| 242 | * è¨å®ããã
|
---|
| 243 | */
|
---|
| 244 | cep->snd_cwnd = cep->maxseg;
|
---|
| 245 | cep->snd_ssthresh = win * cep->maxseg;
|
---|
| 246 | cep->dupacks = 0;
|
---|
| 247 |
|
---|
| 248 | /* åºåããã¹ãããã*/
|
---|
| 249 | cep->flags |= TCP_CEP_FLG_POST_OUTPUT;
|
---|
| 250 | sig_sem(SEM_TCP_POST_OUTPUT);
|
---|
| 251 | break;
|
---|
| 252 |
|
---|
| 253 | /*
|
---|
| 254 | * æç¶ã¿ã¤ã
|
---|
| 255 | */
|
---|
| 256 | case TCP_TIM_PERSIST:
|
---|
| 257 |
|
---|
| 258 | /*
|
---|
| 259 | * æ大åéåæ° (TCP_MAX_REXMT_SHIFTãæ¨æº 12 å) ãè¶
|
---|
| 260 | ãã¦ãã¦ã
|
---|
| 261 | * ã¢ã¤ãã«æéããä¿çã¿ã¤ãã®æ¨æºå¤ (TCP_TVAL_KEEP_IDLEã
|
---|
| 262 | * æ¨æº 2 * 60 * 60 ç§) 以ä¸ãã
|
---|
| 263 | * åéã¿ã¤ã ã¢ã¦ãå¤ * ããã¯ãªãæéã®åè¨ä»¥ä¸ãªã
|
---|
| 264 | * ã³ãã¯ã·ã§ã³ãåæããã
|
---|
| 265 | */
|
---|
| 266 | if (cep->rxtshift > TCP_MAX_REXMT_SHIFT &&
|
---|
| 267 | (cep->idle >= TCP_TVAL_KEEP_IDLE ||
|
---|
| 268 | cep->idle >= tcp_rexmt_val(cep) * TCP_TOTAL_BACK_OFF)) {
|
---|
| 269 | cep->net_error = EV_REXMTMO;
|
---|
| 270 | cep = tcp_drop(cep, E_CLS);
|
---|
| 271 | break;
|
---|
| 272 | }
|
---|
| 273 |
|
---|
| 274 | /* æç¶ã¿ã¤ããåè¨å®ããåºåããã¹ãããã*/
|
---|
| 275 | tcp_set_persist_timer(cep);
|
---|
| 276 |
|
---|
| 277 | cep->flags |= TCP_CEP_FLG_FORCE | TCP_CEP_FLG_FORCE_CLEAR | TCP_CEP_FLG_POST_OUTPUT;
|
---|
| 278 | sig_sem(SEM_TCP_POST_OUTPUT);
|
---|
| 279 | break;
|
---|
| 280 |
|
---|
| 281 | /*
|
---|
| 282 | * ä¿ç (keep alive) ã¿ã¤ã
|
---|
| 283 | */
|
---|
| 284 | case TCP_TIM_KEEP:
|
---|
| 285 |
|
---|
| 286 | /*
|
---|
| 287 | * ã³ãã¯ã·ã§ã³ãéè¨ãããã¾ã§ã«ã¿ã¤ã ã¢ã¦ãããã
|
---|
| 288 | * ã³ãã¯ã·ã§ã³ã®éè¨ãä¸æ¢ããã
|
---|
| 289 | */
|
---|
| 290 | if (cep->fsm_state < TCP_FSM_ESTABLISHED) {
|
---|
| 291 | cep->net_error = EV_REXMTMO;
|
---|
| 292 | cep = tcp_drop(cep, E_CLS);
|
---|
| 293 | break;
|
---|
| 294 | }
|
---|
| 295 |
|
---|
| 296 | #ifdef TCP_CFG_ALWAYS_KEEP
|
---|
| 297 |
|
---|
| 298 | else if (cep->fsm_state < TCP_FSM_CLOSING) {
|
---|
| 299 | if (cep->idle >= TCP_TVAL_KEEP_IDLE +
|
---|
| 300 | TCP_TVAL_KEEP_COUNT * TCP_TVAL_KEEP_INTERVAL) {
|
---|
| 301 | cep->net_error = EV_REXMTMO;
|
---|
| 302 | cep = tcp_drop(cep, E_CLS);
|
---|
| 303 | break;
|
---|
| 304 | }
|
---|
| 305 | else
|
---|
| 306 | tcp_respond(NULL, cep, cep->rcv_nxt, cep->snd_una - 1,
|
---|
| 307 | cep->rbufsz - cep->rwbuf_count, 0);
|
---|
| 308 | cep->timer[TCP_TIM_KEEP] = TCP_TVAL_KEEP_INTERVAL;
|
---|
| 309 | }
|
---|
| 310 | else
|
---|
| 311 | cep->timer[TCP_TIM_KEEP] = TCP_TVAL_KEEP_IDLE;
|
---|
| 312 |
|
---|
| 313 | #else /* of #ifdef TCP_CFG_ALWAYS_KEEP */
|
---|
| 314 |
|
---|
| 315 | cep->timer[TCP_TIM_KEEP] = TCP_TVAL_KEEP_IDLE;
|
---|
| 316 |
|
---|
| 317 | #endif /* of #ifdef TCP_CFG_ALWAYS_KEEP */
|
---|
| 318 |
|
---|
| 319 | break;
|
---|
| 320 |
|
---|
| 321 | /*
|
---|
| 322 | * 2MSL ã¿ã¤ã
|
---|
| 323 | */
|
---|
| 324 | case TCP_TIM_2MSL:
|
---|
| 325 |
|
---|
| 326 | if (cep->fsm_state != TCP_FSM_TIME_WAIT &&
|
---|
| 327 | cep->idle <= TCP_TVAL_KEEP_COUNT * TCP_TVAL_KEEP_INTERVAL)
|
---|
| 328 | cep->timer[TCP_TIM_2MSL] = TCP_TVAL_KEEP_INTERVAL;
|
---|
| 329 | else
|
---|
| 330 | cep = tcp_close(cep);
|
---|
| 331 | break;
|
---|
| 332 | }
|
---|
| 333 |
|
---|
| 334 | return cep;
|
---|
| 335 | }
|
---|
| 336 |
|
---|
| 337 | /*
|
---|
| 338 | * tcp_cancel_timers -- å
|
---|
| 339 | ¨ã¦ã®ã¿ã¤ãããã£ã³ã»ã«ããã
|
---|
| 340 | */
|
---|
| 341 |
|
---|
| 342 | void
|
---|
| 343 | tcp_cancel_timers (T_TCP_CEP *cep)
|
---|
| 344 | {
|
---|
| 345 | int_t ix;
|
---|
| 346 |
|
---|
| 347 | for (ix = NUM_TCP_TIMERS; ix -- > 0; )
|
---|
| 348 | cep->timer[ix] = 0;
|
---|
| 349 | }
|
---|
| 350 |
|
---|
| 351 | #if defined(NUM_TCP_TW_CEP_ENTRY) && NUM_TCP_TW_CEP_ENTRY > 0
|
---|
| 352 |
|
---|
| 353 | /*
|
---|
| 354 | * tcp_tw_timo -- Time Wait ç¨ TCP é信端ç¹ã®ã¿ã¤ã ã¢ã¦ãå¦ç
|
---|
| 355 | */
|
---|
| 356 |
|
---|
| 357 | void
|
---|
| 358 | tcp_tw_timo (void)
|
---|
| 359 | {
|
---|
| 360 | T_TCP_CEP *cep, *lcep;
|
---|
| 361 | T_TCP_TWCEP* twcep;
|
---|
| 362 | T_TCP_TIME longer;
|
---|
| 363 | int_t frees, waits;
|
---|
| 364 |
|
---|
| 365 | /*
|
---|
| 366 | * Time Wait ç¨ TCP é信端ç¹ã§ã¿ã¤ã ã¢ã¦ãã®ã¨ã³ããªãæ¢ç´¢ãã
|
---|
| 367 | * æ¢ç´¢ããã¨ã³ããªã空ãã«ããã
|
---|
| 368 | */
|
---|
| 369 | frees = 0;
|
---|
| 370 | for (twcep = &tcp_twcep[NUM_TCP_TW_CEP_ENTRY]; twcep -- != tcp_twcep; )
|
---|
| 371 | if (twcep->fsm_state == TCP_FSM_TIME_WAIT && -- twcep->timer_2msl == 0) {
|
---|
| 372 | twcep->fsm_state = TCP_FSM_CLOSED;
|
---|
| 373 | frees ++;
|
---|
| 374 | }
|
---|
| 375 |
|
---|
| 376 | /*
|
---|
| 377 | * Time Wait ç¨ TCP é信端ç¹ã®ç©ºãã¨ã³ããªãçºçããã
|
---|
| 378 | * æ¨æº TCP é信端ç¹ã§ Time Wait ä¸ã® TCP é信端ç¹ãæ¢ç´¢ãã
|
---|
| 379 | * å¿
|
---|
| 380 | è¦ãªæ
|
---|
| 381 | å ±ã Time Wait ç¨ TCP é信端ç¹ã«ç§»ãã¦ã
|
---|
| 382 | * æ¨æºã® TCP é信端ç¹ãéæ¾ããã
|
---|
| 383 | */
|
---|
| 384 | if (frees > 0) {
|
---|
| 385 | waits = 0;
|
---|
| 386 | for (cep = &tcp_cep[tmax_tcp_cepid]; cep -- != tcp_cep; )
|
---|
| 387 | if (cep->fsm_state == TCP_FSM_TIME_WAIT)
|
---|
| 388 | waits ++;
|
---|
| 389 | if (waits > frees)
|
---|
| 390 | waits = frees;
|
---|
| 391 |
|
---|
| 392 | /*
|
---|
| 393 | * ãã£ã¨ãé·ãé Time Wait ãã¦ãã TCP é信端ç¹ãéæ¾ããã
|
---|
| 394 | */
|
---|
| 395 | while (waits > 0) {
|
---|
| 396 | longer = TCP_TVAL_MSL * 2;
|
---|
| 397 | lcep = NULL;
|
---|
| 398 | for (cep = &tcp_cep[tmax_tcp_cepid]; cep -- != tcp_cep; )
|
---|
| 399 | if (cep->fsm_state == TCP_FSM_TIME_WAIT && cep->timer[TCP_TIM_2MSL] < longer) {
|
---|
| 400 | longer = cep->timer[TCP_TIM_2MSL];
|
---|
| 401 | lcep = cep;
|
---|
| 402 | }
|
---|
| 403 | if (lcep != NULL) {
|
---|
| 404 | tcp_move_twcep(lcep);
|
---|
| 405 | waits --;
|
---|
| 406 | }
|
---|
| 407 | else
|
---|
| 408 | break;
|
---|
| 409 | }
|
---|
| 410 | }
|
---|
| 411 | }
|
---|
| 412 |
|
---|
| 413 | #endif /* of #if defined(NUM_TCP_TW_CEP_ENTRY) && NUM_TCP_TW_CEP_ENTRY > 0 */
|
---|
| 414 |
|
---|
| 415 | /*
|
---|
| 416 | * tcp_slow_timo -- 500 [ms] æ¯ã«å¼åºããã TCP ã¿ã¤ã ã¢ã¦ãé¢æ°
|
---|
| 417 | */
|
---|
| 418 |
|
---|
| 419 | void
|
---|
| 420 | tcp_slow_timo (void *ignore)
|
---|
| 421 | {
|
---|
| 422 | T_TCP_CEP *cep;
|
---|
| 423 | int_t cix, tix;
|
---|
| 424 |
|
---|
| 425 | for (cix = tmax_tcp_cepid; cix -- > 0; ) {
|
---|
| 426 | cep = &tcp_cep[cix];
|
---|
| 427 | if (!(cep->fsm_state == TCP_FSM_CLOSED || cep->fsm_state == TCP_FSM_LISTEN)) {
|
---|
| 428 | for (tix = NUM_TCP_TIMERS; cep != NULL && tix -- > 0; ) {
|
---|
| 429 | if (cep->timer[tix] != 0 && -- cep->timer[tix] == 0) {
|
---|
| 430 | cep = tcp_timers(cep, tix);
|
---|
| 431 | }
|
---|
| 432 | }
|
---|
| 433 | if (cep != NULL) {
|
---|
| 434 | cep->idle ++;
|
---|
| 435 | if (cep->rtt) {
|
---|
| 436 | cep->rtt ++;
|
---|
| 437 | }
|
---|
| 438 | }
|
---|
| 439 | }
|
---|
| 440 | }
|
---|
| 441 |
|
---|
| 442 | #if defined(NUM_TCP_TW_CEP_ENTRY) && NUM_TCP_TW_CEP_ENTRY > 0
|
---|
| 443 |
|
---|
| 444 | tcp_tw_timo();
|
---|
| 445 |
|
---|
| 446 | #endif /* of #if defined(NUM_TCP_TW_CEP_ENTRY) && NUM_TCP_TW_CEP_ENTRY > 0 */
|
---|
| 447 |
|
---|
| 448 | if (tcp_iss != 0) {
|
---|
| 449 | tcp_iss += TCP_ISS_INCR() / TCP_SLOW_HZ;
|
---|
| 450 | }
|
---|
| 451 |
|
---|
| 452 | timeout(tcp_slow_timo, NULL, TCP_SLOW_TMO);
|
---|
| 453 | }
|
---|
| 454 |
|
---|
| 455 | #ifdef TCP_CFG_DELAY_ACK
|
---|
| 456 |
|
---|
| 457 | /*
|
---|
| 458 | * tcp_fast_timo -- 200 [ms] æ¯ã«å¼åºããã TCP ã¿ã¤ã ã¢ã¦ãé¢æ°
|
---|
| 459 | */
|
---|
| 460 |
|
---|
| 461 | void
|
---|
| 462 | tcp_fast_timo (void *ignore)
|
---|
| 463 | {
|
---|
| 464 | T_TCP_CEP *cep;
|
---|
| 465 | int_t cix;
|
---|
| 466 |
|
---|
| 467 | for (cix = tmax_tcp_cepid; cix -- > 0; ) {
|
---|
| 468 | cep = &tcp_cep[cix];
|
---|
| 469 | if (cep->flags & TCP_CEP_FLG_DEL_ACK) {
|
---|
| 470 | cep->flags &= ~TCP_CEP_FLG_DEL_ACK;
|
---|
| 471 | cep->flags |= TCP_CEP_FLG_ACK_NOW | TCP_CEP_FLG_POST_OUTPUT;
|
---|
| 472 | sig_sem(SEM_TCP_POST_OUTPUT);
|
---|
| 473 | }
|
---|
| 474 | }
|
---|
| 475 |
|
---|
| 476 | timeout(tcp_fast_timo, NULL, TCP_FAST_TMO);
|
---|
| 477 | }
|
---|
| 478 |
|
---|
| 479 | #endif/* of #ifdef TCP_CFG_DELAY_ACK */
|
---|
| 480 |
|
---|
| 481 | /*
|
---|
| 482 | * tcp_range_set -- æéãæå®ããç¯å²ã«è¨å®ããã
|
---|
| 483 | */
|
---|
| 484 |
|
---|
| 485 | T_TCP_TIME
|
---|
| 486 | tcp_range_set (T_TCP_TIME value, T_TCP_TIME tvmin, T_TCP_TIME tvmax)
|
---|
| 487 | {
|
---|
| 488 | if ((uint32_t)value < (uint32_t)tvmin)
|
---|
| 489 | return tvmin;
|
---|
| 490 | else if ((uint32_t)value > (uint32_t)tvmax)
|
---|
| 491 | return tvmax;
|
---|
| 492 | else
|
---|
| 493 | return value;
|
---|
| 494 | }
|
---|
| 495 |
|
---|
| 496 | /*
|
---|
| 497 | * tcp_set_persist_timer -- æç¶ã¿ã¤ãã®è¨å®
|
---|
| 498 | */
|
---|
| 499 |
|
---|
| 500 | void
|
---|
| 501 | tcp_set_persist_timer (T_TCP_CEP *cep)
|
---|
| 502 | {
|
---|
| 503 | T_TCP_TIME time;
|
---|
| 504 |
|
---|
| 505 | /*
|
---|
| 506 | * srtt: å¹³æ»åããã RTT
|
---|
| 507 | * rttvar: å¹³æ»åãããåæ£
|
---|
| 508 | */
|
---|
| 509 | time = ((cep->srtt >> 2) + cep->rttvar) >> 1;
|
---|
| 510 |
|
---|
| 511 | /*
|
---|
| 512 | * åéã¿ã¤ããè¨å®ããã¦ããã°å復ä¸è½ã¨ã©ã¼
|
---|
| 513 | */
|
---|
| 514 | if (cep->timer[TCP_TIM_REXMT])
|
---|
| 515 | /* %%% panic("tcp_output REXMT"); %%% */;
|
---|
| 516 |
|
---|
| 517 | /*
|
---|
| 518 | * æç¶ã¿ã¤ããè¨å®ããã
|
---|
| 519 | */
|
---|
| 520 | cep->timer[TCP_TIM_PERSIST] = tcp_range_set((T_TCP_TIME)(time * tcp_back_off[cep->rxtshift]),
|
---|
| 521 | (T_TCP_TIME)TCP_TVAL_MIN_PERSIST,
|
---|
| 522 | (T_TCP_TIME)TCP_TVAL_MAX_PERSIST);
|
---|
| 523 |
|
---|
| 524 | /*
|
---|
| 525 | * åéåæ°ãæ´æ°ããã
|
---|
| 526 | */
|
---|
| 527 | if (cep->rxtshift < TCP_MAX_REXMT_SHIFT)
|
---|
| 528 | cep->rxtshift ++;
|
---|
| 529 | }
|
---|
| 530 |
|
---|
| 531 | #endif /* of #ifdef SUPPORT_TCP */
|
---|