[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_subr.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_subr.c 8.2 (Berkeley) 5/24/95
|
---|
| 79 | * $FreeBSD: src/sys/netinet/tcp_subr.c,v 1.49.2.4 1999/08/29 16:29:55 peter Exp $
|
---|
| 80 | */
|
---|
| 81 |
|
---|
| 82 | #include <stdarg.h>
|
---|
| 83 | #include <string.h>
|
---|
| 84 |
|
---|
| 85 | #ifdef TARGET_KERNEL_ASP
|
---|
| 86 |
|
---|
| 87 | #include <kernel.h>
|
---|
| 88 | #include <sil.h>
|
---|
| 89 | #include <syssvc/serial.h>
|
---|
| 90 | #include <t_syslog.h>
|
---|
| 91 | #include "kernel_cfg.h"
|
---|
| 92 |
|
---|
| 93 | #endif /* of #ifdef TARGET_KERNEL_ASP */
|
---|
| 94 |
|
---|
| 95 | #ifdef TARGET_KERNEL_JSP
|
---|
| 96 |
|
---|
| 97 | #include <s_services.h>
|
---|
| 98 | #include <t_services.h>
|
---|
| 99 | #include "kernel_id.h"
|
---|
| 100 |
|
---|
| 101 | #endif /* of #ifdef TARGET_KERNEL_JSP */
|
---|
| 102 |
|
---|
| 103 | #include <tinet_defs.h>
|
---|
| 104 | #include <tinet_config.h>
|
---|
| 105 |
|
---|
| 106 | #include <net/if.h>
|
---|
| 107 | #include <net/if_ppp.h>
|
---|
| 108 | #include <net/if_loop.h>
|
---|
| 109 | #include <net/ethernet.h>
|
---|
| 110 | #include <net/if_arp.h>
|
---|
| 111 | #include <net/ppp_ipcp.h>
|
---|
| 112 | #include <net/net.h>
|
---|
| 113 | #include <net/net_var.h>
|
---|
| 114 | #include <net/net_buf.h>
|
---|
| 115 | #include <net/net_timer.h>
|
---|
| 116 | #include <net/net_count.h>
|
---|
| 117 |
|
---|
| 118 | #include <netinet/in.h>
|
---|
| 119 | #include <netinet6/in6.h>
|
---|
| 120 | #include <netinet6/in6_var.h>
|
---|
| 121 | #include <netinet/in_var.h>
|
---|
| 122 | #include <netinet/ip.h>
|
---|
| 123 | #include <netinet/ip_var.h>
|
---|
| 124 | #include <netinet/ip6.h>
|
---|
| 125 | #include <netinet6/ip6_var.h>
|
---|
| 126 | #include <netinet6/nd6.h>
|
---|
| 127 | #include <netinet/tcp.h>
|
---|
| 128 | #include <netinet/tcp_timer.h>
|
---|
| 129 | #include <netinet/tcp_var.h>
|
---|
| 130 | #include <netinet/tcp_fsm.h>
|
---|
| 131 | #include <netinet/tcp_seq.h>
|
---|
| 132 | #include <netinet/in_itron.h>
|
---|
| 133 |
|
---|
| 134 | #ifdef SUPPORT_TCP
|
---|
| 135 |
|
---|
| 136 | /*
|
---|
| 137 | * å
|
---|
| 138 | ¨åå¤æ°
|
---|
| 139 | */
|
---|
| 140 |
|
---|
| 141 | /*
|
---|
| 142 | * TCP ã® SEQ ã®åæå¤ãããã°ã©ã ãèµ·åãã¦ãæåã« TCP ã»ã°ã¡ã³ãã
|
---|
| 143 | * éåä¿¡ããã¨ãã«ãget_tim() ã«ããåæåããã
|
---|
| 144 | */
|
---|
| 145 | T_TCP_SEQ tcp_iss = 0;
|
---|
| 146 |
|
---|
| 147 | #ifdef SUPPORT_MIB
|
---|
| 148 |
|
---|
| 149 | /*
|
---|
| 150 | * SNMP 㮠管çæ
|
---|
| 151 | å ±ãã¼ã¹ (MIB)
|
---|
| 152 | */
|
---|
| 153 |
|
---|
| 154 | T_TCP_STATS tcp_stats;
|
---|
| 155 |
|
---|
| 156 | #endif /* of #ifdef SUPPORT_MIB */
|
---|
| 157 |
|
---|
| 158 | /*
|
---|
| 159 | * å±æå¤æ°
|
---|
| 160 | */
|
---|
| 161 |
|
---|
| 162 | static uint16_t tcp_port_auto = TCP_PORT_FIRST_AUTO; /* èªåå²ãå½ã¦çªå· */
|
---|
| 163 |
|
---|
| 164 | /*
|
---|
| 165 | * tcp_free_reassq -- åä¿¡åæ§æãã¥ã¼ã®ãããã¯ã¼ã¯ãããã¡ã解æ¾ããã
|
---|
| 166 | *
|
---|
| 167 | * 注æ:
|
---|
| 168 | * å¿
|
---|
| 169 | è¦ã§ããã°ããã®é¢æ°ãå¼ã³åºãåã«ãé信端ç¹ãããã¯ãã
|
---|
| 170 | * æ»ã£ãå¾ã解é¤ããå¿
|
---|
| 171 | è¦ãããã
|
---|
| 172 | */
|
---|
| 173 |
|
---|
| 174 | void
|
---|
| 175 | tcp_free_reassq (T_TCP_CEP *cep)
|
---|
| 176 | {
|
---|
| 177 | T_NET_BUF *q, *nq;
|
---|
| 178 |
|
---|
| 179 | for (q = cep->reassq; q != NULL; q = nq) {
|
---|
| 180 | nq = GET_TCP_Q_HDR(q, GET_TCP_IP_Q_HDR(q)->thoff)->next;
|
---|
| 181 | syscall(rel_net_buf(q));
|
---|
| 182 | }
|
---|
| 183 | cep->reassq = NULL;
|
---|
| 184 | NET_COUNT_TCP(net_count_tcp[NC_TCP_FREE_RCV_QUEUE], 1);
|
---|
| 185 | }
|
---|
| 186 |
|
---|
| 187 | /*
|
---|
| 188 | * tcp_alloc_auto_port -- èªåå²ãå½ã¦ãã¼ãçªå·ãè¨å®ããã
|
---|
| 189 | */
|
---|
| 190 |
|
---|
| 191 | void
|
---|
| 192 | tcp_alloc_auto_port (T_TCP_CEP *cep)
|
---|
| 193 | {
|
---|
| 194 | int_t ix;
|
---|
| 195 | uint16_t portno;
|
---|
| 196 |
|
---|
| 197 | while (true) {
|
---|
| 198 | portno = tcp_port_auto ++;
|
---|
| 199 | if (tcp_port_auto > TCP_PORT_LAST_AUTO)
|
---|
| 200 | tcp_port_auto = TCP_PORT_FIRST_AUTO;
|
---|
| 201 |
|
---|
| 202 | #ifdef TCP_CFG_PASSIVE_OPEN
|
---|
| 203 |
|
---|
| 204 | for (ix = tmax_tcp_repid; ix -- > 0; ) {
|
---|
| 205 |
|
---|
| 206 | #ifdef TCP_CFG_EXTENTIONS
|
---|
| 207 |
|
---|
| 208 | if (VALID_TCP_REP(&tcp_rep[ix]) && tcp_rep[ix].myaddr.portno == portno) {
|
---|
| 209 | portno = TCP_PORTANY;
|
---|
| 210 | break;
|
---|
| 211 | }
|
---|
| 212 |
|
---|
| 213 | #else /* of #ifdef TCP_CFG_EXTENTIONS */
|
---|
| 214 |
|
---|
| 215 | if (tcp_rep[ix].myaddr.portno == portno) {
|
---|
| 216 | portno = TCP_PORTANY;
|
---|
| 217 | break;
|
---|
| 218 | }
|
---|
| 219 |
|
---|
| 220 | #endif /* of #ifdef TCP_CFG_EXTENTIONS */
|
---|
| 221 |
|
---|
| 222 | }
|
---|
| 223 |
|
---|
| 224 | #endif /* of #ifdef TCP_CFG_PASSIVE_OPEN */
|
---|
| 225 |
|
---|
| 226 | if (portno != TCP_PORTANY) {
|
---|
| 227 |
|
---|
| 228 | syscall(wai_sem(SEM_TCP_CEP));
|
---|
| 229 | for (ix = tmax_tcp_cepid; ix -- > 0; ) {
|
---|
| 230 | if (VALID_TCP_CEP(&tcp_cep[ix]) && tcp_cep[ix].myaddr.portno == portno) {
|
---|
| 231 | portno = TCP_PORTANY;
|
---|
| 232 | break;
|
---|
| 233 | }
|
---|
| 234 | }
|
---|
| 235 |
|
---|
| 236 | if (portno != TCP_PORTANY) {
|
---|
| 237 | cep->myaddr.portno = portno;
|
---|
| 238 | syscall(sig_sem(SEM_TCP_CEP));
|
---|
| 239 | return;
|
---|
| 240 | }
|
---|
| 241 | syscall(sig_sem(SEM_TCP_CEP));
|
---|
| 242 | }
|
---|
| 243 | }
|
---|
| 244 | }
|
---|
| 245 |
|
---|
| 246 | /*
|
---|
| 247 | * tcp_alloc_port -- æå®ããããã¼ãçªå·ãè¨å®ããã
|
---|
| 248 | */
|
---|
| 249 |
|
---|
| 250 | ER
|
---|
| 251 | tcp_alloc_port (T_TCP_CEP *cep, uint16_t portno)
|
---|
| 252 | {
|
---|
| 253 | int_t ix;
|
---|
| 254 |
|
---|
| 255 | syscall(wai_sem(SEM_TCP_CEP));
|
---|
| 256 | for (ix = tmax_tcp_cepid; ix -- > 0; )
|
---|
| 257 | if (VALID_TCP_CEP(cep) && tcp_cep[ix].myaddr.portno == portno) {
|
---|
| 258 | syscall(sig_sem(SEM_TCP_CEP));
|
---|
| 259 | return E_PAR;
|
---|
| 260 | }
|
---|
| 261 | cep->myaddr.portno = portno;
|
---|
| 262 | syscall(sig_sem(SEM_TCP_CEP));
|
---|
| 263 | return E_OK;
|
---|
| 264 | }
|
---|
| 265 |
|
---|
| 266 | /*
|
---|
| 267 | * tcp_init -- TCP ã¢ã¸ã¥ã¼ã«ã®åæå
|
---|
| 268 | */
|
---|
| 269 |
|
---|
| 270 | void
|
---|
| 271 | tcp_init (void)
|
---|
| 272 | {
|
---|
| 273 | timeout(tcp_slow_timo, NULL, TCP_SLOW_TMO);
|
---|
| 274 |
|
---|
| 275 | #ifdef TCP_CFG_DELAY_ACK
|
---|
| 276 |
|
---|
| 277 | timeout(tcp_fast_timo, NULL, TCP_FAST_TMO);
|
---|
| 278 |
|
---|
| 279 | #endif/* of #ifdef TCP_CFG_DELAY_ACK */
|
---|
| 280 | }
|
---|
| 281 |
|
---|
| 282 | /*
|
---|
| 283 | * tcp_init_iss ã·ã¼ã±ã³ã¹çªå·ãåæåããã
|
---|
| 284 | */
|
---|
| 285 |
|
---|
| 286 | void
|
---|
| 287 | tcp_init_iss (void)
|
---|
| 288 | {
|
---|
| 289 | SYSTIM now;
|
---|
| 290 |
|
---|
| 291 | #ifdef SUPPORT_ETHER
|
---|
| 292 |
|
---|
| 293 | T_IF_SOFTC *ic;
|
---|
| 294 |
|
---|
| 295 | ic = IF_ETHER_NIC_GET_SOFTC();
|
---|
| 296 | syscall(get_tim(&now));
|
---|
| 297 | net_srand(now + (ic->ifaddr.lladdr[2] << 24)
|
---|
| 298 | + (ic->ifaddr.lladdr[3] << 16)
|
---|
| 299 | + (ic->ifaddr.lladdr[4] << 8)
|
---|
| 300 | + (ic->ifaddr.lladdr[5] ));
|
---|
| 301 |
|
---|
| 302 | #else /* of #ifdef SUPPORT_ETHER */
|
---|
| 303 |
|
---|
| 304 | syscall(get_tim(&now));
|
---|
| 305 | net_srand(now);
|
---|
| 306 |
|
---|
| 307 | #endif /* of #ifdef SUPPORT_ETHER */
|
---|
| 308 |
|
---|
| 309 | tcp_iss = net_rand();
|
---|
| 310 | }
|
---|
| 311 |
|
---|
| 312 | /*
|
---|
| 313 | * tcp_close -- ã³ãã¯ã·ã§ã³ãéæ¾ããã
|
---|
| 314 | */
|
---|
| 315 |
|
---|
| 316 | T_TCP_CEP *
|
---|
| 317 | tcp_close (T_TCP_CEP *cep)
|
---|
| 318 | {
|
---|
| 319 | /* ã¿ã¤ãã¼ãåæ¢ããã*/
|
---|
| 320 | tcp_cancel_timers(cep);
|
---|
| 321 |
|
---|
| 322 | /*
|
---|
| 323 | * é信端ç¹ãããã¯ãã
|
---|
| 324 | * åä¿¡åæ§æãã¥ã¼ã®ãããã¯ã¼ã¯ãããã¡ã解æ¾ããã
|
---|
| 325 | */
|
---|
| 326 | syscall(wai_sem(cep->semid_lock));
|
---|
| 327 | tcp_free_reassq(cep);
|
---|
| 328 | syscall(sig_sem(cep->semid_lock));
|
---|
| 329 |
|
---|
| 330 | /* ç¶æ
|
---|
| 331 | ãæªä½¿ç¨ã«ããã*/
|
---|
| 332 | cep->fsm_state = TCP_FSM_CLOSED;
|
---|
| 333 |
|
---|
| 334 | /*
|
---|
| 335 | * 以ä¸ã«é¢ä¿ããªããã©ã°ãã¯ãªã¢ã¼ããã
|
---|
| 336 | * ã»éåä¿¡ã¦ã£ã³ããããã¡ã®çã³ãã¼æ©è½
|
---|
| 337 | * ã»åçãªé信端ç¹ã®çæã»åé¤æ©è½
|
---|
| 338 | */
|
---|
| 339 | cep->flags &= (TCP_CEP_FLG_WBCS_NBUF_REQ | TCP_CEP_FLG_WBCS_MASK |
|
---|
| 340 | TCP_CEP_FLG_DYNAMIC | TCP_CEP_FLG_VALID);
|
---|
| 341 |
|
---|
| 342 | #ifdef TCP_CFG_NON_BLOCKING
|
---|
| 343 |
|
---|
| 344 | if (cep->snd_nblk_tfn != TFN_TCP_UNDEF || cep->rcv_nblk_tfn != TFN_TCP_UNDEF) {
|
---|
| 345 | /* ãã³ããããã³ã°ã³ã¼ã« */
|
---|
| 346 |
|
---|
| 347 | #ifdef TCP_CFG_NON_BLOCKING_COMPAT14
|
---|
| 348 |
|
---|
| 349 | if (!IS_PTR_DEFINED(cep->callback))
|
---|
| 350 | syslog(LOG_WARNING, "[TCP] no call back, CEP: %d.", GET_TCP_CEPID(cep));
|
---|
| 351 | else {
|
---|
| 352 | if (cep->rcv_nblk_tfn != TFN_TCP_UNDEF) {
|
---|
| 353 | ER_UINT len;
|
---|
| 354 |
|
---|
| 355 | switch (cep->rcv_nblk_tfn) {
|
---|
| 356 |
|
---|
| 357 | case TFN_TCP_ACP_CEP:
|
---|
| 358 | /* TCP é信端ç¹ããTCP åä»å£ã解æ¾ããã*/
|
---|
| 359 | cep->rep = NULL;
|
---|
| 360 | (*cep->callback)(GET_TCP_CEPID(cep), cep->rcv_nblk_tfn, (void*)E_CLS);
|
---|
| 361 | break;
|
---|
| 362 |
|
---|
| 363 | case TFN_TCP_RCV_BUF:
|
---|
| 364 |
|
---|
| 365 | /* åä¿¡ã¦ã£ã³ããããã¡ã®ç©ºã¢ãã¬ã¹ãç²å¾ããã*/
|
---|
| 366 | len = TCP_GET_RWBUF_ADDR(cep, cep->rcv_p_buf);
|
---|
| 367 |
|
---|
| 368 | /* ç°å¸¸åæçã®ã¨ã©ã¼ãè¨å®ããã*/
|
---|
| 369 | if (cep->error == E_TMOUT)
|
---|
| 370 | len = E_CLS;
|
---|
| 371 | else if (cep->error < 0)
|
---|
| 372 | len = cep->error;
|
---|
| 373 |
|
---|
| 374 | (*cep->callback)(GET_TCP_CEPID(cep), cep->rcv_nblk_tfn, (void*)(uint32_t)len);
|
---|
| 375 | break;
|
---|
| 376 |
|
---|
| 377 | case TFN_TCP_RCV_DAT:
|
---|
| 378 |
|
---|
| 379 | /* åä¿¡ã¦ã£ã³ããããã¡ãããã¼ã¿ãåãåºãã*/
|
---|
| 380 | len = TCP_READ_RWBUF(cep, cep->rcv_data, (uint_t)cep->rcv_len);
|
---|
| 381 |
|
---|
| 382 | /* ç°å¸¸åæçã®ã¨ã©ã¼ãè¨å®ããã*/
|
---|
| 383 | if (cep->error == E_TMOUT)
|
---|
| 384 | len = E_CLS;
|
---|
| 385 | else if (cep->error != E_OK)
|
---|
| 386 | len = cep->error;
|
---|
| 387 |
|
---|
| 388 | (*cep->callback)(GET_TCP_CEPID(cep), cep->rcv_nblk_tfn, (void*)(uint32_t)len);
|
---|
| 389 | break;
|
---|
| 390 |
|
---|
| 391 | case TFN_TCP_CLS_CEP:
|
---|
| 392 |
|
---|
| 393 | if (cep->error == E_TMOUT)
|
---|
| 394 | (*cep->callback)(GET_TCP_CEPID(cep), cep->rcv_nblk_tfn, (void*)E_CLS);
|
---|
| 395 | else
|
---|
| 396 | (*cep->callback)(GET_TCP_CEPID(cep), cep->rcv_nblk_tfn, (void*)cep->error);
|
---|
| 397 | break;
|
---|
| 398 |
|
---|
| 399 | default:
|
---|
| 400 | syslog(LOG_WARNING, "[TCP] unexp TFN: %s.", in_strtfn((FN)cep->rcv_nblk_tfn));
|
---|
| 401 | break;
|
---|
| 402 | }
|
---|
| 403 |
|
---|
| 404 | /* è¨æ¶ããã¦ããã¿ã¹ã¯ ID 㨠API æ©è½ã³ã¼ããã¯ãªã¢ã¼ããã*/
|
---|
| 405 | cep->rcv_tskid = TA_NULL;
|
---|
| 406 | cep->rcv_tfn = cep->rcv_nblk_tfn = TFN_TCP_UNDEF;
|
---|
| 407 | }
|
---|
| 408 |
|
---|
| 409 | if (cep->snd_nblk_tfn != TFN_TCP_UNDEF) {
|
---|
| 410 |
|
---|
| 411 | switch (cep->snd_nblk_tfn) {
|
---|
| 412 |
|
---|
| 413 | case TFN_TCP_CON_CEP:
|
---|
| 414 | /* TCP é信端ç¹ãã TCP åä»å£ã解æ¾ããã*/
|
---|
| 415 | cep->rep = NULL;
|
---|
| 416 | (*cep->callback)(GET_TCP_CEPID(cep), cep->snd_nblk_tfn, (void*)E_CLS);
|
---|
| 417 | break;
|
---|
| 418 |
|
---|
| 419 | case TFN_TCP_SND_DAT:
|
---|
| 420 | case TFN_TCP_GET_BUF:
|
---|
| 421 | if (cep->error == E_TMOUT)
|
---|
| 422 | (*cep->callback)(GET_TCP_CEPID(cep), cep->snd_nblk_tfn, (void*)E_CLS);
|
---|
| 423 | else
|
---|
| 424 | (*cep->callback)(GET_TCP_CEPID(cep), cep->snd_nblk_tfn, (void*)cep->error);
|
---|
| 425 | break;
|
---|
| 426 |
|
---|
| 427 | default:
|
---|
| 428 | syslog(LOG_WARNING, "[TCP] unexp TFN: %s.", in_strtfn((FN)cep->snd_nblk_tfn));
|
---|
| 429 | break;
|
---|
| 430 | }
|
---|
| 431 |
|
---|
| 432 | /* è¨æ¶ããã¦ããã¿ã¹ã¯ ID 㨠API æ©è½ã³ã¼ããã¯ãªã¢ã¼ããã*/
|
---|
| 433 | cep->snd_tskid = TA_NULL;
|
---|
| 434 | cep->snd_tfn = cep->snd_nblk_tfn = TFN_TCP_UNDEF;
|
---|
| 435 | }
|
---|
| 436 |
|
---|
| 437 | }
|
---|
| 438 |
|
---|
| 439 | #else /* of #ifdef TCP_CFG_NON_BLOCKING_COMPAT14 */
|
---|
| 440 |
|
---|
| 441 | if (!IS_PTR_DEFINED(cep->callback))
|
---|
| 442 | syslog(LOG_WARNING, "[TCP] no call back, CEP: %d.", GET_TCP_CEPID(cep));
|
---|
| 443 | else {
|
---|
| 444 | if (cep->rcv_nblk_tfn != TFN_TCP_UNDEF) {
|
---|
| 445 | ER_UINT len;
|
---|
| 446 |
|
---|
| 447 | switch (cep->rcv_nblk_tfn) {
|
---|
| 448 |
|
---|
| 449 | case TFN_TCP_ACP_CEP:
|
---|
| 450 | /* TCP é信端ç¹ããTCP åä»å£ã解æ¾ããã*/
|
---|
| 451 | cep->rep = NULL;
|
---|
| 452 | len = E_CLS;
|
---|
| 453 | (*cep->callback)(GET_TCP_CEPID(cep), cep->rcv_nblk_tfn, (void*)&len);
|
---|
| 454 | break;
|
---|
| 455 |
|
---|
| 456 | case TFN_TCP_RCV_BUF:
|
---|
| 457 |
|
---|
| 458 | /* åä¿¡ã¦ã£ã³ããããã¡ã®ç©ºã¢ãã¬ã¹ãç²å¾ããã*/
|
---|
| 459 | len = TCP_GET_RWBUF_ADDR(cep, cep->rcv_p_buf);
|
---|
| 460 |
|
---|
| 461 | /* ç°å¸¸åæçã®ã¨ã©ã¼ãè¨å®ããã*/
|
---|
| 462 | if (cep->error == E_TMOUT)
|
---|
| 463 | len = E_CLS;
|
---|
| 464 | else if (cep->error < 0)
|
---|
| 465 | len = cep->error;
|
---|
| 466 |
|
---|
| 467 | (*cep->callback)(GET_TCP_CEPID(cep), cep->rcv_nblk_tfn, (void*)&len);
|
---|
| 468 | break;
|
---|
| 469 |
|
---|
| 470 | case TFN_TCP_RCV_DAT:
|
---|
| 471 |
|
---|
| 472 | /* åä¿¡ã¦ã£ã³ããããã¡ãããã¼ã¿ãåãåºãã*/
|
---|
| 473 | len = TCP_READ_RWBUF(cep, cep->rcv_data, (uint_t)cep->rcv_len);
|
---|
| 474 |
|
---|
| 475 | /* ç°å¸¸åæçã®ã¨ã©ã¼ãè¨å®ããã*/
|
---|
| 476 | if (cep->error == E_TMOUT)
|
---|
| 477 | len = E_CLS;
|
---|
| 478 | else if (cep->error != E_OK)
|
---|
| 479 | len = cep->error;
|
---|
| 480 |
|
---|
| 481 | (*cep->callback)(GET_TCP_CEPID(cep), cep->rcv_nblk_tfn, (void*)&len);
|
---|
| 482 | break;
|
---|
| 483 |
|
---|
| 484 | case TFN_TCP_CLS_CEP:
|
---|
| 485 | if (cep->error == E_TMOUT)
|
---|
| 486 | len = E_CLS;
|
---|
| 487 | else
|
---|
| 488 | len = cep->error;
|
---|
| 489 | (*cep->callback)(GET_TCP_CEPID(cep), cep->rcv_nblk_tfn, (void*)&len);
|
---|
| 490 | break;
|
---|
| 491 |
|
---|
| 492 | default:
|
---|
| 493 | syslog(LOG_WARNING, "[TCP] unexp TFN: %s.", in_strtfn((FN)cep->rcv_nblk_tfn));
|
---|
| 494 | break;
|
---|
| 495 | }
|
---|
| 496 |
|
---|
| 497 | /* è¨æ¶ããã¦ããã¿ã¹ã¯ ID 㨠API æ©è½ã³ã¼ããã¯ãªã¢ã¼ããã*/
|
---|
| 498 | cep->rcv_tskid = TA_NULL;
|
---|
| 499 | cep->rcv_tfn = cep->rcv_nblk_tfn = TFN_TCP_UNDEF;
|
---|
| 500 | }
|
---|
| 501 |
|
---|
| 502 | if (cep->snd_nblk_tfn != TFN_TCP_UNDEF) {
|
---|
| 503 | ER_UINT len;
|
---|
| 504 |
|
---|
| 505 | switch (cep->snd_nblk_tfn) {
|
---|
| 506 |
|
---|
| 507 | case TFN_TCP_CON_CEP:
|
---|
| 508 | /* TCP é信端ç¹ãã TCP åä»å£ã解æ¾ããã*/
|
---|
| 509 | cep->rep = NULL;
|
---|
| 510 | len = E_CLS;
|
---|
| 511 | (*cep->callback)(GET_TCP_CEPID(cep), cep->snd_nblk_tfn, (void*)&len);
|
---|
| 512 | break;
|
---|
| 513 |
|
---|
| 514 | case TFN_TCP_SND_DAT:
|
---|
| 515 | case TFN_TCP_GET_BUF:
|
---|
| 516 | if (cep->error == E_TMOUT)
|
---|
| 517 | len = E_CLS;
|
---|
| 518 | else
|
---|
| 519 | len = cep->error;
|
---|
| 520 | (*cep->callback)(GET_TCP_CEPID(cep), cep->rcv_nblk_tfn, (void*)&len);
|
---|
| 521 | break;
|
---|
| 522 |
|
---|
| 523 | default:
|
---|
| 524 | syslog(LOG_WARNING, "[TCP] unexp TFN: %s.", in_strtfn((FN)cep->snd_nblk_tfn));
|
---|
| 525 | break;
|
---|
| 526 | }
|
---|
| 527 |
|
---|
| 528 | /* è¨æ¶ããã¦ããã¿ã¹ã¯ ID 㨠API æ©è½ã³ã¼ããã¯ãªã¢ã¼ããã*/
|
---|
| 529 | cep->snd_tskid = TA_NULL;
|
---|
| 530 | cep->snd_tfn = cep->snd_nblk_tfn = TFN_TCP_UNDEF;
|
---|
| 531 | }
|
---|
| 532 |
|
---|
| 533 | }
|
---|
| 534 |
|
---|
| 535 | #endif /* of #ifdef TCP_CFG_NON_BLOCKING_COMPAT14 */
|
---|
| 536 |
|
---|
| 537 | /*
|
---|
| 538 | * é信端ç¹ãããã¯ãã
|
---|
| 539 | * éåä¿¡ã¦ã£ã³ããããã¡ãã¥ã¼ã®ãããã¯ã¼ã¯ãããã¡ã解æ¾ããã
|
---|
| 540 | */
|
---|
| 541 | syscall(wai_sem(cep->semid_lock));
|
---|
| 542 | TCP_FREE_RWBUFQ(cep);
|
---|
| 543 | TCP_FREE_SWBUFQ(cep);
|
---|
| 544 | syscall(sig_sem(cep->semid_lock));
|
---|
| 545 |
|
---|
| 546 | /* æªä½¿ç¨ã«ãªã£ããã¨ãç¥ãããã*/
|
---|
| 547 | syscall(set_flg(cep->est_flgid, TCP_CEP_EVT_CLOSED));
|
---|
| 548 | }
|
---|
| 549 | else { /* éãã³ããããã³ã°ã³ã¼ã« */
|
---|
| 550 |
|
---|
| 551 | #endif /* of #ifdef TCP_CFG_NON_BLOCKING */
|
---|
| 552 |
|
---|
| 553 | /* è¨æ¶ããã¦ããã¿ã¹ã¯ ID 㨠API æ©è½ã³ã¼ããã¯ãªã¢ã¼ããã*/
|
---|
| 554 | cep->snd_tskid = cep->rcv_tskid = TA_NULL;
|
---|
| 555 | cep->snd_tfn = cep->rcv_tfn = TFN_TCP_UNDEF;
|
---|
| 556 |
|
---|
| 557 | /*
|
---|
| 558 | * é信端ç¹ãããã¯ãã
|
---|
| 559 | * éåä¿¡ã¦ã£ã³ããããã¡ãã¥ã¼ã®ãããã¯ã¼ã¯ãããã¡ã解æ¾ããã
|
---|
| 560 | */
|
---|
| 561 | syscall(wai_sem(cep->semid_lock));
|
---|
| 562 | TCP_FREE_RWBUFQ(cep);
|
---|
| 563 | TCP_FREE_SWBUFQ(cep);
|
---|
| 564 | syscall(sig_sem(cep->semid_lock));
|
---|
| 565 |
|
---|
| 566 | /* æªä½¿ç¨ã«ãªã£ããã¨ãç¥ãããã*/
|
---|
| 567 | syscall(set_flg(cep->est_flgid, TCP_CEP_EVT_CLOSED));
|
---|
| 568 |
|
---|
| 569 | /*
|
---|
| 570 | * å
|
---|
| 571 | ¥åºåã¿ã¹ã¯ãèµ·åºãã¦ã
|
---|
| 572 | * éåä¿¡ä¸å¯ã«ãªã£ããã¨ãç¥ãããã
|
---|
| 573 | */
|
---|
| 574 | syscall(set_flg(cep->snd_flgid, TCP_CEP_EVT_SWBUF_READY));
|
---|
| 575 | syscall(set_flg(cep->rcv_flgid, TCP_CEP_EVT_RWBUF_READY));
|
---|
| 576 |
|
---|
| 577 | #ifdef TCP_CFG_NON_BLOCKING
|
---|
| 578 |
|
---|
| 579 | }
|
---|
| 580 |
|
---|
| 581 | #endif /* of #ifdef TCP_CFG_NON_BLOCKING */
|
---|
| 582 |
|
---|
| 583 | return NULL;
|
---|
| 584 | }
|
---|
| 585 |
|
---|
| 586 | /*
|
---|
| 587 | * tcp_drop -- TCP æ¥ç¶ãç ´æ£ããã
|
---|
| 588 | */
|
---|
| 589 |
|
---|
| 590 | T_TCP_CEP *
|
---|
| 591 | tcp_drop (T_TCP_CEP *cep, ER errno)
|
---|
| 592 | {
|
---|
| 593 | #ifdef SUPPORT_MIB
|
---|
| 594 |
|
---|
| 595 | if ((cep->fsm_state == TCP_FSM_SYN_SENT) || (cep->fsm_state == TCP_FSM_SYN_RECVD)) {
|
---|
| 596 | NET_COUNT_MIB(tcp_stats.tcpAttemptFails, 1);
|
---|
| 597 | }
|
---|
| 598 |
|
---|
| 599 | #endif /* of #ifdef SUPPORT_MIB */
|
---|
| 600 |
|
---|
| 601 | cep->error = errno;
|
---|
| 602 | if (TCP_FSM_HAVE_RCVD_SYN(cep->fsm_state)) {
|
---|
| 603 | cep->fsm_state = TCP_FSM_CLOSED;
|
---|
| 604 |
|
---|
| 605 | /* éä¿¡ã¨ãéä¿¡å¾ã³ãã¯ã·ã§ã³ã®åæãæ示ããã*/
|
---|
| 606 | cep->flags |= TCP_CEP_FLG_POST_OUTPUT | TCP_CEP_FLG_CLOSE_AFTER_OUTPUT;
|
---|
| 607 | sig_sem(SEM_TCP_POST_OUTPUT);
|
---|
| 608 | }
|
---|
| 609 | else
|
---|
| 610 | cep = tcp_close(cep);
|
---|
| 611 | return cep;
|
---|
| 612 | }
|
---|
| 613 |
|
---|
| 614 | /*
|
---|
| 615 | * tcp_respond -- TCP ã®åä¸ã¡ãã»ã¼ã¸ãéä¿¡ããã
|
---|
| 616 | */
|
---|
| 617 |
|
---|
| 618 | void
|
---|
| 619 | tcp_respond (T_NET_BUF *output, T_TCP_CEP *cep,
|
---|
| 620 | T_TCP_SEQ ack, T_TCP_SEQ seq, uint_t rbfree, uint8_t flags)
|
---|
| 621 | {
|
---|
| 622 | T_IP_HDR *iph;
|
---|
| 623 | T_TCP_HDR *tcph;
|
---|
| 624 | uint_t win = 0;
|
---|
| 625 |
|
---|
| 626 | if ((flags & TCP_FLG_RST) == 0)
|
---|
| 627 | win = rbfree;
|
---|
| 628 |
|
---|
| 629 | /*
|
---|
| 630 | * output ã NULL ã§ãªããã°ãããã¯å
|
---|
| 631 | ¥åããã»ã°ã¡ã³ãã®
|
---|
| 632 | * net_buf ã§ããã®ã¾ã¾åå©ç¨ããã
|
---|
| 633 | */
|
---|
| 634 | if (output != NULL) {
|
---|
| 635 | T_IN_ADDR ipaddr;
|
---|
| 636 | uint16_t portno;
|
---|
| 637 |
|
---|
| 638 | /*
|
---|
| 639 | * IPv4 ã§ã¯ãIP ãããã®ãªãã·ã§ã³ãåé¤ããã
|
---|
| 640 | * IPv6 ã§ã¯ãæ¡å¼µããããåé¤ããã
|
---|
| 641 | */
|
---|
| 642 | if (IP_REMOVE_OPTIONS(output) != E_OK) {
|
---|
| 643 | syscall(rel_net_buf(output));
|
---|
| 644 | return;
|
---|
| 645 | }
|
---|
| 646 |
|
---|
| 647 | iph = GET_IP_HDR(output);
|
---|
| 648 |
|
---|
| 649 | /* IP ã¢ãã¬ã¹ã交æããã*/
|
---|
| 650 | ipaddr = iph->src;
|
---|
| 651 | iph->src = iph->dst;
|
---|
| 652 | iph->dst = ipaddr;
|
---|
| 653 |
|
---|
| 654 | #if defined(SUPPORT_INET6)
|
---|
| 655 |
|
---|
| 656 | /* ãã©ããã¯ã¯ã©ã¹ã¨ããã¼ã©ãã«ãã¯ãªã¢ããã*/
|
---|
| 657 | iph->vcf = htonl(IP6_MAKE_VCF(IP6_VCF_V(ntohl(iph->vcf)), 0));
|
---|
| 658 |
|
---|
| 659 | #endif /* of #if defined(SUPPORT_INET6) */
|
---|
| 660 |
|
---|
| 661 | /* TCP SDU é·ã 0 ã«ããã*/
|
---|
| 662 | SET_IP_SDU_SIZE(iph, TCP_HDR_SIZE);
|
---|
| 663 |
|
---|
| 664 | tcph = GET_TCP_HDR(output, IF_IP_TCP_HDR_OFFSET);
|
---|
| 665 |
|
---|
| 666 | /* ãã¼ãçªå·ã交æããã*/
|
---|
| 667 | portno = tcph->sport;
|
---|
| 668 | tcph->sport = tcph->dport;
|
---|
| 669 | tcph->dport = portno;
|
---|
| 670 |
|
---|
| 671 | /* TCP ãããã«æ
|
---|
| 672 | å ±ãè¨å®ããã*/
|
---|
| 673 | tcph->doff = TCP_MAKE_DATA_OFF(TCP_HDR_SIZE);
|
---|
| 674 | }
|
---|
| 675 |
|
---|
| 676 | /* cep ã NULL ã§ããã°ãä½ãããªãã§çµäºããã*/
|
---|
| 677 | else if (cep == NULL)
|
---|
| 678 | return;
|
---|
| 679 | else {
|
---|
| 680 | if (tcp_get_segment(&output, cep, 0,
|
---|
| 681 | 0, (uint_t)(net_buf_max_siz() - IF_IP_TCP_HDR_SIZE),
|
---|
| 682 | NBA_SEARCH_ASCENT, TMO_TCP_GET_NET_BUF) != E_OK)
|
---|
| 683 | return;
|
---|
| 684 | tcph = GET_TCP_HDR(output, IF_IP_TCP_HDR_OFFSET);
|
---|
| 685 | flags |= TCP_FLG_ACK;
|
---|
| 686 | }
|
---|
| 687 |
|
---|
| 688 | tcph->seq = htonl(seq);
|
---|
| 689 | tcph->ack = htonl(ack);
|
---|
| 690 | tcph->win = htons(win);
|
---|
| 691 | tcph->flags = flags;
|
---|
| 692 | tcph->urp = tcph->sum = 0;
|
---|
| 693 |
|
---|
| 694 | /*
|
---|
| 695 | * ãã§ãã¯ãµã ãè¨å®ããã
|
---|
| 696 | */
|
---|
| 697 | tcph->sum = IN_CKSUM(output, IPPROTO_TCP, IF_IP_TCP_HDR_OFFSET,
|
---|
| 698 | (uint_t)GET_TCP_HDR_SIZE2(output, IF_IP_TCP_HDR_OFFSET));
|
---|
| 699 |
|
---|
| 700 | /* ãããã¯ã¼ã¯ãããã¡é·ã調æ´ããã*/
|
---|
| 701 | output->len = (uint16_t)GET_IF_IP_TCP_HDR_SIZE2(output, IF_IP_TCP_HDR_OFFSET);
|
---|
| 702 |
|
---|
| 703 | #ifdef TCP_CFG_TRACE
|
---|
| 704 |
|
---|
| 705 | tcp_output_trace(output, cep);
|
---|
| 706 |
|
---|
| 707 | #endif /* of #ifdef TCP_CFG_TRACE */
|
---|
| 708 |
|
---|
| 709 | /* ãããã¯ã¼ã¯å±¤ (IP) ã®åºåé¢æ°ãå¼ã³åºãã*/
|
---|
| 710 | IP_OUTPUT(output, TMO_TCP_OUTPUT);
|
---|
| 711 | }
|
---|
| 712 |
|
---|
| 713 | /*
|
---|
| 714 | * tcp_set_header -- TCP ããããè¨å®ããã
|
---|
| 715 | */
|
---|
| 716 |
|
---|
| 717 | void
|
---|
| 718 | tcp_set_header (T_NET_BUF *nbuf, T_TCP_CEP *cep, uint_t thoff, uint_t optlen)
|
---|
| 719 | {
|
---|
| 720 | T_TCP_HDR *tcph = GET_TCP_HDR(nbuf, thoff);
|
---|
| 721 |
|
---|
| 722 | /* TCP ãããã«æ
|
---|
| 723 | å ±ãè¨å®ããã*/
|
---|
| 724 | tcph->sport = htons(cep->myaddr.portno);
|
---|
| 725 | tcph->dport = htons(cep->dstaddr.portno);
|
---|
| 726 | tcph->doff = TCP_MAKE_DATA_OFF(TCP_HDR_SIZE + optlen);
|
---|
| 727 | tcph->sum = tcph->flags = 0;
|
---|
| 728 | }
|
---|
| 729 |
|
---|
| 730 | /*
|
---|
| 731 | * tcp_get_segment -- TCP ã»ã°ã¡ã³ããç²å¾ããããããè¨å®ããã
|
---|
| 732 | *
|
---|
| 733 | * æ»ãå¤ ã¨ã©ã¼ã³ã¼ã
|
---|
| 734 | * optlen ãªãã·ã§ã³ãµã¤ãºã4 ãªã¯ãããåä½
|
---|
| 735 | * len TCP SDU ãµã¤ãº
|
---|
| 736 | */
|
---|
| 737 |
|
---|
| 738 | ER
|
---|
| 739 | tcp_get_segment (T_NET_BUF **nbuf, T_TCP_CEP *cep,
|
---|
| 740 | uint_t optlen, uint_t len, uint_t maxlen, ATR nbatr, TMO tmout)
|
---|
| 741 | {
|
---|
| 742 | ER error;
|
---|
| 743 |
|
---|
| 744 | /* IP ãã¼ã¿ã°ã©ã ãç²å¾ããã*/
|
---|
| 745 | if ((error = IN_GET_DATAGRAM(nbuf,
|
---|
| 746 | (uint_t)(TCP_HDR_SIZE + optlen + len),
|
---|
| 747 | (uint_t)(TCP_HDR_SIZE + maxlen),
|
---|
| 748 | &cep->dstaddr.ipaddr,
|
---|
| 749 | &cep->myaddr.ipaddr,
|
---|
| 750 | IPPROTO_TCP, IP_DEFTTL, nbatr, tmout)) != E_OK) {
|
---|
| 751 | syslog(LOG_WARNING, "[TCP] NET BUF busy, len:%4d, CEP: %d.",
|
---|
| 752 | (uint16_t)(TCP_HDR_SIZE + optlen + len), GET_TCP_CEPID(cep));
|
---|
| 753 | return error;
|
---|
| 754 | }
|
---|
| 755 |
|
---|
| 756 | /* TCP ãããã«æ
|
---|
| 757 | å ±ãè¨å®ããã*/
|
---|
| 758 | tcp_set_header(*nbuf, cep, IF_IP_TCP_HDR_OFFSET, optlen);
|
---|
| 759 |
|
---|
| 760 | return E_OK;
|
---|
| 761 | }
|
---|
| 762 |
|
---|
| 763 | /*
|
---|
| 764 | * tcp_can_send_more -- éä¿¡ã§ããããé信端ç¹ã®ç¶æ
|
---|
| 765 | ãè¦ãã
|
---|
| 766 | */
|
---|
| 767 |
|
---|
| 768 | ER
|
---|
| 769 | tcp_can_send_more (T_TCP_CEP *cep, FN fncd, TMO tmout)
|
---|
| 770 | {
|
---|
| 771 | ER error;
|
---|
| 772 |
|
---|
| 773 | /* éä¿¡ã§ããããCEP ã® FSM ç¶æ
|
---|
| 774 | ãè¦ãã*/
|
---|
| 775 | if (!TCP_FSM_CAN_SEND_MORE(cep->fsm_state)) {
|
---|
| 776 | if ((error = cep->error) == E_OK)
|
---|
| 777 | error = E_OBJ;
|
---|
| 778 |
|
---|
| 779 | #ifdef TCP_CFG_NON_BLOCKING
|
---|
| 780 |
|
---|
| 781 | /* ã¿ã¤ã ã¢ã¦ãããã§ãã¯ããã*/
|
---|
| 782 | if (tmout == TMO_NBLK) { /* ãã³ããããã³ã°ã³ã¼ã« */
|
---|
| 783 |
|
---|
| 784 | if (!IS_PTR_DEFINED(cep->callback))
|
---|
| 785 | error = E_OBJ;
|
---|
| 786 | else {
|
---|
| 787 |
|
---|
| 788 | #ifdef TCP_CFG_NON_BLOCKING_COMPAT14
|
---|
| 789 |
|
---|
| 790 | /* ã³ã¼ã«ããã¯é¢æ°ãå¼ã³åºãã*/
|
---|
| 791 | (*cep->callback)(GET_TCP_CEPID(cep), fncd, (void*)error);
|
---|
| 792 |
|
---|
| 793 | #else /* of #ifdef TCP_CFG_NON_BLOCKING_COMPAT14 */
|
---|
| 794 |
|
---|
| 795 | /* ã³ã¼ã«ããã¯é¢æ°ãå¼ã³åºãã*/
|
---|
| 796 | (*cep->callback)(GET_TCP_CEPID(cep), fncd, (void*)&error);
|
---|
| 797 |
|
---|
| 798 | #endif /* of #ifdef TCP_CFG_NON_BLOCKING_COMPAT14 */
|
---|
| 799 |
|
---|
| 800 | error = E_WBLK;
|
---|
| 801 | }
|
---|
| 802 | }
|
---|
| 803 |
|
---|
| 804 | #endif /* of #ifdef TCP_CFG_NON_BLOCKING */
|
---|
| 805 |
|
---|
| 806 | }
|
---|
| 807 | else {
|
---|
| 808 |
|
---|
| 809 | #ifdef TCP_CFG_SWBUF_CSAVE
|
---|
| 810 |
|
---|
| 811 | error = E_OK;
|
---|
| 812 |
|
---|
| 813 | #else /* of #ifdef TCP_CFG_SWBUF_CSAVE */
|
---|
| 814 |
|
---|
| 815 | if (!IS_PTR_DEFINED(cep->sbuf)) {
|
---|
| 816 |
|
---|
| 817 | #ifdef TCP_CFG_NON_BLOCKING
|
---|
| 818 |
|
---|
| 819 | /* ã¿ã¤ã ã¢ã¦ãããã§ãã¯ããã*/
|
---|
| 820 | if (tmout == TMO_NBLK) { /* ãã³ããããã³ã°ã³ã¼ã« */
|
---|
| 821 | if (!IS_PTR_DEFINED(cep->callback))
|
---|
| 822 | error = E_OBJ;
|
---|
| 823 | else {
|
---|
| 824 |
|
---|
| 825 | #ifdef TCP_CFG_NON_BLOCKING_COMPAT14
|
---|
| 826 |
|
---|
| 827 | /* ã³ã¼ã«ããã¯é¢æ°ãå¼ã³åºãã*/
|
---|
| 828 | (*cep->callback)(GET_TCP_CEPID(cep), fncd, (void*)E_OBJ);
|
---|
| 829 |
|
---|
| 830 | #else /* of #ifdef TCP_CFG_NON_BLOCKING_COMPAT14 */
|
---|
| 831 |
|
---|
| 832 | /* ã³ã¼ã«ããã¯é¢æ°ãå¼ã³åºãã*/
|
---|
| 833 | error = E_OBJ;
|
---|
| 834 | (*cep->callback)(GET_TCP_CEPID(cep), fncd, (void*)&error);
|
---|
| 835 |
|
---|
| 836 | #endif /* of #ifdef TCP_CFG_NON_BLOCKING_COMPAT14 */
|
---|
| 837 |
|
---|
| 838 | error = E_WBLK;
|
---|
| 839 | }
|
---|
| 840 | }
|
---|
| 841 | else
|
---|
| 842 |
|
---|
| 843 | #endif /* of #ifdef TCP_CFG_NON_BLOCKING */
|
---|
| 844 |
|
---|
| 845 | error = E_OBJ;
|
---|
| 846 | }
|
---|
| 847 | else
|
---|
| 848 | error = E_OK;
|
---|
| 849 |
|
---|
| 850 | #endif /* of #ifdef TCP_CFG_SWBUF_CSAVE */
|
---|
| 851 |
|
---|
| 852 | }
|
---|
| 853 |
|
---|
| 854 | return error;
|
---|
| 855 | }
|
---|
| 856 |
|
---|
| 857 | /*
|
---|
| 858 | * tcp_can_recv_more -- åä¿¡ã§ããããé信端ç¹ã®ç¶æ
|
---|
| 859 | ãè¦ãã
|
---|
| 860 | *
|
---|
| 861 | * 注æ: æ»ãå¤
|
---|
| 862 | *
|
---|
| 863 | * E_OK åä¿¡å¯è½
|
---|
| 864 | * E_OBJ ç¸æããåæãããããã¨ã©ã¼ãçºçããã
|
---|
| 865 | */
|
---|
| 866 |
|
---|
| 867 | ER
|
---|
| 868 | tcp_can_recv_more (ER *error, T_TCP_CEP *cep, FN fncd, TMO tmout)
|
---|
| 869 | {
|
---|
| 870 | /*
|
---|
| 871 | * åä¿¡ã§ããããfsm_state ãè¦ããåä¿¡ã§ããªãå ´åã¯
|
---|
| 872 | * é·ã 0ãã¾ãã¯ã¨ã©ã¼ãè¿ãã
|
---|
| 873 | */
|
---|
| 874 | if (!TCP_FSM_CAN_RECV_MORE(cep->fsm_state) &&
|
---|
| 875 | cep->rwbuf_count == 0 && cep->reassq == NULL) {
|
---|
| 876 | *error = cep->error;
|
---|
| 877 |
|
---|
| 878 | #ifdef TCP_CFG_NON_BLOCKING
|
---|
| 879 |
|
---|
| 880 | /* ã¿ã¤ã ã¢ã¦ãããã§ãã¯ããã*/
|
---|
| 881 | if (tmout == TMO_NBLK) { /* ãã³ããããã³ã°ã³ã¼ã« */
|
---|
| 882 |
|
---|
| 883 | if (!IS_PTR_DEFINED(cep->callback))
|
---|
| 884 | *error = E_OBJ;
|
---|
| 885 | else {
|
---|
| 886 | #ifdef TCP_CFG_NON_BLOCKING_COMPAT14
|
---|
| 887 |
|
---|
| 888 | /* ã³ã¼ã«ããã¯é¢æ°ãå¼ã³åºãã*/
|
---|
| 889 | (*cep->callback)(GET_TCP_CEPID(cep), fncd, (void*)*error);
|
---|
| 890 |
|
---|
| 891 | #else /* of #ifdef TCP_CFG_NON_BLOCKING_COMPAT14 */
|
---|
| 892 |
|
---|
| 893 | /* ã³ã¼ã«ããã¯é¢æ°ãå¼ã³åºãã*/
|
---|
| 894 | (*cep->callback)(GET_TCP_CEPID(cep), fncd, (void*)error);
|
---|
| 895 |
|
---|
| 896 | #endif /* of #ifdef TCP_CFG_NON_BLOCKING_COMPAT14 */
|
---|
| 897 |
|
---|
| 898 | *error = E_WBLK;
|
---|
| 899 | }
|
---|
| 900 | }
|
---|
| 901 |
|
---|
| 902 | #endif /* of #ifdef TCP_CFG_NON_BLOCKING */
|
---|
| 903 |
|
---|
| 904 | /*
|
---|
| 905 | * é信端ç¹ãããã¯ãã¦ã
|
---|
| 906 | * åä¿¡ã¦ã£ã³ããããã¡ãã¥ã¼ã®ãããã¯ã¼ã¯ãããã¡ã解æ¾ããã
|
---|
| 907 | */
|
---|
| 908 | syscall(wai_sem(cep->semid_lock));
|
---|
| 909 | TCP_FREE_RWBUFQ(cep);
|
---|
| 910 | syscall(sig_sem(cep->semid_lock));
|
---|
| 911 |
|
---|
| 912 | return E_OBJ;
|
---|
| 913 | }
|
---|
| 914 | else {
|
---|
| 915 |
|
---|
| 916 | #ifndef TCP_CFG_RWBUF_CSAVE
|
---|
| 917 |
|
---|
| 918 | if (!IS_PTR_DEFINED(cep->rbuf)) {
|
---|
| 919 |
|
---|
| 920 | #ifdef TCP_CFG_NON_BLOCKING
|
---|
| 921 |
|
---|
| 922 | /* ã¿ã¤ã ã¢ã¦ãããã§ãã¯ããã*/
|
---|
| 923 | if (tmout == TMO_NBLK) { /* ãã³ããããã³ã°ã³ã¼ã« */
|
---|
| 924 | if (!IS_PTR_DEFINED(cep->callback))
|
---|
| 925 | *error = E_OBJ;
|
---|
| 926 | else {
|
---|
| 927 |
|
---|
| 928 | #ifdef TCP_CFG_NON_BLOCKING_COMPAT14
|
---|
| 929 |
|
---|
| 930 | /* ã³ã¼ã«ããã¯é¢æ°ãå¼ã³åºãã*/
|
---|
| 931 | (*cep->callback)(GET_TCP_CEPID(cep), fncd, (void*)E_OBJ);
|
---|
| 932 |
|
---|
| 933 | #else /* of #ifdef TCP_CFG_NON_BLOCKING_COMPAT14 */
|
---|
| 934 |
|
---|
| 935 | /* ã³ã¼ã«ããã¯é¢æ°ãå¼ã³åºãã*/
|
---|
| 936 | *error = E_OBJ;
|
---|
| 937 | (*cep->callback)(GET_TCP_CEPID(cep), fncd, (void*)error);
|
---|
| 938 |
|
---|
| 939 | #endif /* of #ifdef TCP_CFG_NON_BLOCKING_COMPAT14 */
|
---|
| 940 |
|
---|
| 941 | *error = E_WBLK;
|
---|
| 942 | }
|
---|
| 943 | }
|
---|
| 944 | else
|
---|
| 945 |
|
---|
| 946 | #endif /* of #ifdef TCP_CFG_NON_BLOCKING */
|
---|
| 947 |
|
---|
| 948 | *error = E_OBJ;
|
---|
| 949 |
|
---|
| 950 | return E_OBJ;
|
---|
| 951 | }
|
---|
| 952 |
|
---|
| 953 | #endif /* of #ifndef TCP_CFG_RWBUF_CSAVE */
|
---|
| 954 |
|
---|
| 955 | return E_OK;
|
---|
| 956 | }
|
---|
| 957 | }
|
---|
| 958 |
|
---|
| 959 | /*
|
---|
| 960 | * tcp_wait_rwbuf -- åä¿¡ã¦ã£ã³ããããã¡ã«ãã¼ã¿ãå
|
---|
| 961 | ¥ãã®ãå¾
|
---|
| 962 | ã¤ã
|
---|
| 963 | */
|
---|
| 964 |
|
---|
| 965 | ER
|
---|
| 966 | tcp_wait_rwbuf (T_TCP_CEP *cep, TMO tmout)
|
---|
| 967 | {
|
---|
| 968 | ER error;
|
---|
| 969 | FLGPTN flag;
|
---|
| 970 |
|
---|
| 971 | if (cep->rwbuf_count == 0) {
|
---|
| 972 | /* åä¿¡ã¦ã£ã³ããããã¡ã«ãã¼ã¿ããªããã°ãå
|
---|
| 973 | ¥åãããã¾ã§å¾
|
---|
| 974 | ã¤ã*/
|
---|
| 975 | while (cep->rwbuf_count == 0) {
|
---|
| 976 | if ((error = twai_flg(cep->rcv_flgid, TCP_CEP_EVT_RWBUF_READY, TWF_ORW, &flag, tmout)) != E_OK) {
|
---|
| 977 | return error;
|
---|
| 978 | }
|
---|
| 979 | syscall(clr_flg(cep->rcv_flgid, (FLGPTN)(~TCP_CEP_EVT_RWBUF_READY)));
|
---|
| 980 |
|
---|
| 981 | /*
|
---|
| 982 | * åä¿¡ã§ããããfsm_state ãè¦ããåä¿¡ã§ããªãç¶æ
|
---|
| 983 | ã§ã
|
---|
| 984 | * åä¿¡ã¦ã£ã³ããããã¡ã«æåããªãå ´åã¯çµäºããã
|
---|
| 985 | */
|
---|
| 986 | if (!TCP_FSM_CAN_RECV_MORE(cep->fsm_state) &&
|
---|
| 987 | cep->rwbuf_count == 0 && cep->reassq == NULL) {
|
---|
| 988 |
|
---|
| 989 | /*
|
---|
| 990 | * é信端ç¹ãããã¯ãã¦ã
|
---|
| 991 | * åä¿¡ã¦ã£ã³ããããã¡ãã¥ã¼ã®ãããã¯ã¼ã¯ãããã¡ã解æ¾ããã
|
---|
| 992 | */
|
---|
| 993 | #ifdef TCP_CFG_RWBUF_CSAVE
|
---|
| 994 | #endif
|
---|
| 995 | syscall(wai_sem(cep->semid_lock));
|
---|
| 996 | TCP_FREE_RWBUFQ(cep);
|
---|
| 997 | syscall(sig_sem(cep->semid_lock));
|
---|
| 998 |
|
---|
| 999 | return cep->error;
|
---|
| 1000 | }
|
---|
| 1001 | }
|
---|
| 1002 | }
|
---|
| 1003 | else
|
---|
| 1004 | syscall(clr_flg(cep->rcv_flgid, (FLGPTN)(~TCP_CEP_EVT_RWBUF_READY)));
|
---|
| 1005 |
|
---|
| 1006 | return E_OK;
|
---|
| 1007 | }
|
---|
| 1008 |
|
---|
| 1009 | /*
|
---|
| 1010 | * tcp_move_ra2rw -- åä¿¡åæ§æãã¥ã¼ã§åæ§æããã»ã°ã¡ã³ããåä¿¡ã¦ã£ã³ããããã¡ã«æ¸ãè¾¼ãã
|
---|
| 1011 | */
|
---|
| 1012 |
|
---|
| 1013 | uint8_t
|
---|
| 1014 | tcp_move_ra2rw (T_TCP_CEP *cep, uint8_t flags)
|
---|
| 1015 | {
|
---|
| 1016 | T_NET_BUF *q;
|
---|
| 1017 | T_TCP_Q_HDR *qhdr;
|
---|
| 1018 |
|
---|
| 1019 | /*
|
---|
| 1020 | * åä¿¡ãã¼ã¿ãåä¿¡ã¦ã£ã³ããããã¡ã«æ¸ãè¾¼ã¿ã
|
---|
| 1021 | * rcv_nxt ãå®äºãã SEQ ã ãé²ããã
|
---|
| 1022 | */
|
---|
| 1023 | if (TCP_FSM_HAVE_ESTABLISHED(cep->fsm_state)) {
|
---|
| 1024 | while (cep->reassq != NULL) {
|
---|
| 1025 | q = cep->reassq;
|
---|
| 1026 | qhdr = GET_TCP_Q_HDR(q, GET_TCP_IP_Q_HDR(q)->thoff);
|
---|
| 1027 | if (qhdr->seq != cep->rcv_nxt)
|
---|
| 1028 | break;
|
---|
| 1029 |
|
---|
| 1030 | /* 次ã®ã»ã°ã¡ã³ãã«é²ãã*/
|
---|
| 1031 | cep->reassq = qhdr->next;
|
---|
| 1032 |
|
---|
| 1033 | /* FIN ãã©ã°ã®ã¿æ®ãã*/
|
---|
| 1034 | flags &= TCP_FLG_FIN;
|
---|
| 1035 |
|
---|
| 1036 | /* ãã¼ã¿ãåä¿¡ã¦ã£ã³ããããã¡ã«æ¸ãè¾¼ãã*/
|
---|
| 1037 | TCP_WRITE_RWBUF(cep, q, (uint_t)(GET_TCP_IP_Q_HDR(q)->thoff));
|
---|
| 1038 | }
|
---|
| 1039 | }
|
---|
| 1040 | if (cep->reassq != NULL) {
|
---|
| 1041 | cep->flags |= TCP_CEP_FLG_ACK_NOW;
|
---|
| 1042 | flags &= ~TCP_FLG_FIN;
|
---|
| 1043 | }
|
---|
| 1044 | return flags;
|
---|
| 1045 | }
|
---|
| 1046 |
|
---|
| 1047 | /*
|
---|
| 1048 | * tcp_write_raque -- åä¿¡ã»ã°ã¡ã³ããåæ§æãã¦ãåä¿¡åæ§æãã¥ã¼ã«ç¹ãã
|
---|
| 1049 | */
|
---|
| 1050 |
|
---|
| 1051 | uint8_t
|
---|
| 1052 | tcp_write_raque (T_NET_BUF *input, T_TCP_CEP *cep, uint_t thoff, uint8_t flags)
|
---|
| 1053 | {
|
---|
| 1054 | T_NET_BUF *new;
|
---|
| 1055 | T_NET_BUF *p, *q, *nq;
|
---|
| 1056 | T_TCP_Q_HDR *qhdr, *inqhdr = GET_TCP_Q_HDR(input, thoff);
|
---|
| 1057 | int32_t len;
|
---|
| 1058 |
|
---|
| 1059 | /* TCP ãããã®ä½ç½®ãä¿åããã*/
|
---|
| 1060 | GET_TCP_IP_Q_HDR(input)->thoff = thoff;
|
---|
| 1061 |
|
---|
| 1062 | /*
|
---|
| 1063 | * MAX_TCP_REALLOC_SIZE 以ä¸ã®å ´åã¯ãæ°ãã«ãããã¯ã¼ã¯ãããã¡ã
|
---|
| 1064 | * å²å½ã¦ã¦ããã¼ã¿ãã³ãã¼ããã
|
---|
| 1065 | * ãã®ã¨ããIP ã®ãªãã·ã§ã³ï¼æ¡å¼µãããï¼ã¨ TCP ã®ãªãã·ã§ã³ã¯åé¤ããã
|
---|
| 1066 | */
|
---|
| 1067 | len = IF_IP_TCP_HDR_SIZE + inqhdr->slen;
|
---|
| 1068 |
|
---|
| 1069 | if (len <= MAX_TCP_REALLOC_SIZE) {
|
---|
| 1070 |
|
---|
| 1071 | /*
|
---|
| 1072 | * ãããã¯ã¼ã¯ãããã¡ã確ä¿ã§ããªãã¨ãã¯å²å½ã¦ãªãã
|
---|
| 1073 | */
|
---|
| 1074 | if (tget_net_buf(&new, (uint_t)len, TMO_TCP_GET_NET_BUF) != E_OK)
|
---|
| 1075 | new = NULL;
|
---|
| 1076 | }
|
---|
| 1077 | else
|
---|
| 1078 | new = NULL;
|
---|
| 1079 |
|
---|
| 1080 | /*
|
---|
| 1081 | * inqhdr->seq
|
---|
| 1082 | * |
|
---|
| 1083 | * |<------- inqhdr->slen ------->|
|
---|
| 1084 | * v v
|
---|
| 1085 | * +------------------------------+
|
---|
| 1086 | * | input |
|
---|
| 1087 | * +------------------------------+
|
---|
| 1088 | * ^ ^
|
---|
| 1089 | * |<----- slen ----->|
|
---|
| 1090 | * |
|
---|
| 1091 | * soff
|
---|
| 1092 | *
|
---|
| 1093 | */
|
---|
| 1094 | inqhdr->soff = 0;
|
---|
| 1095 |
|
---|
| 1096 | /*
|
---|
| 1097 | * ä»å追å ããã»ã°ã¡ã³ãããå(p)ã¨å¾(q)ã®ã»ã°ã¡ã³ããæ¢ãã
|
---|
| 1098 | *
|
---|
| 1099 | * +-------------------------+
|
---|
| 1100 | * | p |
|
---|
| 1101 | * +-------------------------+
|
---|
| 1102 | * ^ +---------------------------+
|
---|
| 1103 | * p->seq | input |
|
---|
| 1104 | * +---------------------------+
|
---|
| 1105 | * ^ +-------------------------+
|
---|
| 1106 | * inqhdr->seq | q |
|
---|
| 1107 | * +-------------------------+
|
---|
| 1108 | * ^
|
---|
| 1109 | * q->seq
|
---|
| 1110 | */
|
---|
| 1111 | for (q = cep->reassq, p = NULL; q != NULL; ) {
|
---|
| 1112 | qhdr = GET_TCP_Q_HDR(q, GET_TCP_IP_Q_HDR(q)->thoff);
|
---|
| 1113 | if (SEQ_GT(qhdr->seq, inqhdr->seq))
|
---|
| 1114 | break;
|
---|
| 1115 | p = q;
|
---|
| 1116 | q = qhdr->next;
|
---|
| 1117 | }
|
---|
| 1118 |
|
---|
| 1119 | /*
|
---|
| 1120 | * å(p)ã®ã»ã°ã¡ã³ããããã°ãæ¢ã«ãä»åã¨åãã»ã°ã¡ã³ãã
|
---|
| 1121 | * ãããã¨ãããããã®å ´åã¯ããã®é¨åã¾ãã¯å
|
---|
| 1122 | ¨ã¦ãç ´æ£ããã
|
---|
| 1123 | *
|
---|
| 1124 | * qhdr->seq
|
---|
| 1125 | * |
|
---|
| 1126 | * |<----- qhdr->slen ------>|
|
---|
| 1127 | * v v
|
---|
| 1128 | * +-------------------------+
|
---|
| 1129 | * | p |
|
---|
| 1130 | * +-------------------------+
|
---|
| 1131 | * <--len -->
|
---|
| 1132 | * +---------------------------+
|
---|
| 1133 | * | input |
|
---|
| 1134 | * +---------------------------+
|
---|
| 1135 | * ^
|
---|
| 1136 | * inqhdr->seq
|
---|
| 1137 | */
|
---|
| 1138 | if (p != NULL) {
|
---|
| 1139 | qhdr = GET_TCP_Q_HDR(p, GET_TCP_IP_Q_HDR(p)->thoff);
|
---|
| 1140 | len = qhdr->seq + qhdr->slen - inqhdr->seq;
|
---|
| 1141 | if (len > 0) {
|
---|
| 1142 |
|
---|
| 1143 | /*
|
---|
| 1144 | * len ãæ£ã§ããã°ãå(p) ã®ã»ã°ã¡ã³ãã¨ä»åã®
|
---|
| 1145 | * ã»ã°ã¡ã³ããéãªã£ã¦ããã
|
---|
| 1146 | */
|
---|
| 1147 | if (len >= inqhdr->slen) {
|
---|
| 1148 |
|
---|
| 1149 | /*
|
---|
| 1150 | * len ãä»åã®ã»ã°ã¡ã³ãã¨åããªã
|
---|
| 1151 | * ã¾ã£ããåãã»ã°ã¡ã³ããªã®ã§ä½ãããªãã
|
---|
| 1152 | */
|
---|
| 1153 | if (new != NULL) {
|
---|
| 1154 | syscall(rel_net_buf(new));
|
---|
| 1155 | }
|
---|
| 1156 |
|
---|
| 1157 | syscall(rel_net_buf(input));
|
---|
| 1158 | return flags;
|
---|
| 1159 | }
|
---|
| 1160 |
|
---|
| 1161 | /*
|
---|
| 1162 | * 追å ããã»ã°ã¡ã³ãã® SDU ã len ååã«è©°ããã
|
---|
| 1163 | */
|
---|
| 1164 | inqhdr->seq += len;
|
---|
| 1165 | inqhdr->soff += (uint16_t)len;
|
---|
| 1166 | inqhdr->slen -= (uint16_t)len;
|
---|
| 1167 | }
|
---|
| 1168 | }
|
---|
| 1169 |
|
---|
| 1170 | /*
|
---|
| 1171 | * ãã¥ã¼ã«ã¤ãªãåã«ãæ°ãããããã¯ã¼ã¯ãããã¡ã«ãã¼ã¿ã移ãã
|
---|
| 1172 | * TCP ã®ãªãã·ã§ã³ã¯åé¤ããã
|
---|
| 1173 | */
|
---|
| 1174 | if (new != NULL) {
|
---|
| 1175 | memcpy(new->buf, input->buf, (size_t)(thoff + TCP_HDR_SIZE));
|
---|
| 1176 | memcpy((uint8_t*)GET_TCP_HDR(new, thoff) + TCP_HDR_SIZE,
|
---|
| 1177 | GET_TCP_SDU(input, thoff), (size_t)(inqhdr->slen));
|
---|
| 1178 | syscall(rel_net_buf(input));
|
---|
| 1179 | input = new;
|
---|
| 1180 | inqhdr = GET_TCP_Q_HDR(input, thoff);
|
---|
| 1181 | inqhdr->doff = (uint8_t)TCP_MAKE_DATA_OFF(TCP_HDR_SIZE);
|
---|
| 1182 | }
|
---|
| 1183 |
|
---|
| 1184 | /*
|
---|
| 1185 | * éãªãå¾(q)ã®ã»ã°ã¡ã³ãã調æ´ããã
|
---|
| 1186 | *
|
---|
| 1187 | * inqhdr->seq
|
---|
| 1188 | * |
|
---|
| 1189 | * |<----- inqhdr->slen ---->|
|
---|
| 1190 | * v v
|
---|
| 1191 | * +-------------------------+
|
---|
| 1192 | * | input |
|
---|
| 1193 | * +-------------------------+
|
---|
| 1194 | * <--len -->
|
---|
| 1195 | * +---------------------------+
|
---|
| 1196 | * | q |
|
---|
| 1197 | * +---------------------------+
|
---|
| 1198 | * ^
|
---|
| 1199 | * qhdr->seq
|
---|
| 1200 | */
|
---|
| 1201 | while (q != NULL) {
|
---|
| 1202 | qhdr = GET_TCP_Q_HDR(q, GET_TCP_IP_Q_HDR(q)->thoff);
|
---|
| 1203 | len = inqhdr->seq + inqhdr->slen - qhdr->seq;
|
---|
| 1204 | if (len <= 0)
|
---|
| 1205 | /* len ãè² ãªãéãªã£ã¦ããªãã*/
|
---|
| 1206 | break;
|
---|
| 1207 | else if (len < qhdr->slen) {
|
---|
| 1208 |
|
---|
| 1209 | /*
|
---|
| 1210 | * å¾ãã§éãªã£ã¦ããã»ã°ã¡ã³ãã® SDU ã len ååã«è©°ããã
|
---|
| 1211 | *
|
---|
| 1212 | * inqhdr->seq
|
---|
| 1213 | * |
|
---|
| 1214 | * |<----- inqhdr->slen ---->|
|
---|
| 1215 | * v v
|
---|
| 1216 | * +-------------------------+
|
---|
| 1217 | * | input |
|
---|
| 1218 | * +-------------------------+
|
---|
| 1219 | * <--len -->
|
---|
| 1220 | * +------+---------------------------+
|
---|
| 1221 | * | | q |
|
---|
| 1222 | * +------+---------------------------+
|
---|
| 1223 | * ^--------->
|
---|
| 1224 | * qhdr->seq
|
---|
| 1225 | * qhdr->soff
|
---|
| 1226 | */
|
---|
| 1227 | qhdr->seq += len;
|
---|
| 1228 | qhdr->soff += (uint16_t)len;
|
---|
| 1229 | qhdr->slen -= (uint16_t)len;
|
---|
| 1230 | break;
|
---|
| 1231 | }
|
---|
| 1232 | nq = qhdr->next;
|
---|
| 1233 | if (p)
|
---|
| 1234 | GET_TCP_Q_HDR(p, GET_TCP_IP_Q_HDR(p)->thoff)->next = nq;
|
---|
| 1235 | else
|
---|
| 1236 | cep->reassq = nq;
|
---|
| 1237 | syscall(rel_net_buf(q));
|
---|
| 1238 | q = nq;
|
---|
| 1239 | }
|
---|
| 1240 |
|
---|
| 1241 | if (p == NULL) {
|
---|
| 1242 | inqhdr->next = cep->reassq;
|
---|
| 1243 | cep->reassq = input;
|
---|
| 1244 | }
|
---|
| 1245 | else {
|
---|
| 1246 | inqhdr->next = GET_TCP_Q_HDR(p, GET_TCP_IP_Q_HDR(p)->thoff)->next;
|
---|
| 1247 | GET_TCP_Q_HDR(p, GET_TCP_IP_Q_HDR(p)->thoff)->next = input;
|
---|
| 1248 | }
|
---|
| 1249 |
|
---|
| 1250 | return tcp_move_ra2rw(cep, flags);
|
---|
| 1251 | }
|
---|
| 1252 |
|
---|
| 1253 | /*
|
---|
| 1254 | * tcp_rexmt_val -- åéã¿ã¤ã ã¢ã¦ãå¤ãè¿ãã
|
---|
| 1255 | */
|
---|
| 1256 |
|
---|
| 1257 | T_TCP_TIME
|
---|
| 1258 | tcp_rexmt_val (T_TCP_CEP *cep)
|
---|
| 1259 | {
|
---|
| 1260 | T_TCP_TIME val;
|
---|
| 1261 |
|
---|
| 1262 | val = ((cep->srtt >> (TCP_SRTT_SHIFT - TCP_DELTA_SHIFT)) + cep->rttvar) >> TCP_DELTA_SHIFT;
|
---|
| 1263 | if (val < TCP_TVAL_MIN)
|
---|
| 1264 | return TCP_TVAL_MIN;
|
---|
| 1265 | else
|
---|
| 1266 | return val;
|
---|
| 1267 | }
|
---|
| 1268 |
|
---|
| 1269 | /*
|
---|
| 1270 | * tcp_init_cep -- é信端ç¹ãåæåããã
|
---|
| 1271 | */
|
---|
| 1272 |
|
---|
| 1273 | void
|
---|
| 1274 | tcp_init_cep (T_TCP_CEP *cep)
|
---|
| 1275 | {
|
---|
| 1276 | #ifdef TCP_CFG_RWBUF_CSAVE
|
---|
| 1277 | /*
|
---|
| 1278 | * åä¿¡ã¦ã£ã³ããããã¡ã®çã³ãã¼æ©è½ãæå¹ã«ããå ´åã
|
---|
| 1279 | * åä¿¡ã¦ã£ã³ããããã¡ãå
|
---|
| 1280 | ¨ã¦è§£æ¾ãããªããã¨ãããã®ã§ã
|
---|
| 1281 | * ããã§è§£æ¾ããã
|
---|
| 1282 | */
|
---|
| 1283 | if (cep->rwbufq != NULL) {
|
---|
| 1284 | cep->rwbuf_count = 0;
|
---|
| 1285 | TCP_FREE_RWBUFQ(cep);
|
---|
| 1286 | }
|
---|
| 1287 | #endif /* of #ifdef TCP_CFG_RWBUF_CSAVE */
|
---|
| 1288 |
|
---|
| 1289 | memset((uint8_t*)cep + offsetof(T_TCP_CEP, timer), 0,
|
---|
| 1290 | sizeof(T_TCP_CEP) - offsetof(T_TCP_CEP, timer));
|
---|
| 1291 |
|
---|
| 1292 | cep->sbuf_rptr = cep->sbuf_wptr = cep->sbuf;
|
---|
| 1293 | cep->rbuf_rptr = cep->rbuf_wptr = cep->rbuf;
|
---|
| 1294 |
|
---|
| 1295 | cep->maxseg = DEF_TCP_SND_SEG; /* éä¿¡æ大ã»ã°ã¡ã³ããµã¤ãº */
|
---|
| 1296 | cep->srtt = TCP_TVAL_SRTT_BASE; /* æ»ãããªç§»åå¹³å */
|
---|
| 1297 | cep->rttvar = ((TCP_TVAL_RTO_BASE - TCP_TVAL_SRTT_BASE) << TCP_RTTVAR_SHIFT) / 4;
|
---|
| 1298 | /* æ»ãããªåæ£ */
|
---|
| 1299 | cep->rxtcur = TCP_TVAL_RTO_BASE; /* ç¾å¨ã®åéå¤ */
|
---|
| 1300 | cep->snd_cwnd = MAX_TCP_WIN_SIZE; /* 輻輳ã¦ã£ã³ããµã¤ãº */
|
---|
| 1301 | cep->snd_ssthresh= MAX_TCP_WIN_SIZE; /* 輻輳ã¦ã£ã³ããµã¤ãº(snd_cwnd)ã® å¶éå¤ */
|
---|
| 1302 |
|
---|
| 1303 | /*
|
---|
| 1304 | * 以ä¸ã«é¢ä¿ããªããã©ã°ãã¯ãªã¢ã¼ããã
|
---|
| 1305 | * ã»éåä¿¡ã¦ã£ã³ããããã¡ã®çã³ãã¼æ©è½
|
---|
| 1306 | * ã»åçãªé信端ç¹ã®çæã»åé¤æ©è½
|
---|
| 1307 | */
|
---|
| 1308 | cep->flags &= (TCP_CEP_FLG_WBCS_NBUF_REQ | TCP_CEP_FLG_WBCS_MASK |
|
---|
| 1309 | TCP_CEP_FLG_DYNAMIC | TCP_CEP_FLG_VALID);
|
---|
| 1310 |
|
---|
| 1311 | /* ã»ããã©ãåæåããã*/
|
---|
| 1312 | sig_sem (cep->semid_lock);
|
---|
| 1313 |
|
---|
| 1314 | /* ãã©ã°ãåæåããã*/
|
---|
| 1315 | syscall(set_flg(cep->snd_flgid, TCP_CEP_EVT_SWBUF_READY));
|
---|
| 1316 | syscall(clr_flg(cep->rcv_flgid, TCP_CEP_EVT_RWBUF_READY));
|
---|
| 1317 | }
|
---|
| 1318 |
|
---|
| 1319 | /*
|
---|
| 1320 | * tcp_notify -- ICMP ã¨ã©ã¼ã®å¦ç
|
---|
| 1321 | */
|
---|
| 1322 |
|
---|
| 1323 | void
|
---|
| 1324 | tcp_notify (T_NET_BUF *input, ER error)
|
---|
| 1325 | {
|
---|
| 1326 | T_IP_HDR *iph;
|
---|
| 1327 | T_TCP_HDR *tcph;
|
---|
| 1328 | T_TCP_CEP *cep;
|
---|
| 1329 |
|
---|
| 1330 | iph = GET_IP_HDR(input);
|
---|
| 1331 | tcph = GET_TCP_HDR(input, GET_TCP_HDR_OFFSET(input));
|
---|
| 1332 |
|
---|
| 1333 | if ((cep = tcp_find_cep(&iph->src, tcph->sport, &iph->dst, tcph->dport)) != NULL) {
|
---|
| 1334 |
|
---|
| 1335 | /*
|
---|
| 1336 | * ã³ãã¯ã·ã§ã³éè¨æ¸ã§ããã¹ãå°éä¸è½ã¨ã©ã¼ã®å ´åã¯ã
|
---|
| 1337 | * åéã«ããå¦çããã
|
---|
| 1338 | */
|
---|
| 1339 | if (cep->fsm_state == TCP_FSM_ESTABLISHED &&
|
---|
| 1340 | (error == EV_NURCH || error == EV_HURCH || error == EV_HDOWN))
|
---|
| 1341 | return;
|
---|
| 1342 |
|
---|
| 1343 | /*
|
---|
| 1344 | * ã³ãã¯ã·ã§ã³éè¨ä¸ãåãã¨ã©ã¼ãä½åº¦ãåä¿¡ããå ´åã¯ã
|
---|
| 1345 | * å¾
|
---|
| 1346 | ã¡ç¶æ
|
---|
| 1347 | ã解é¤ãã対å¿ããé¢æ°ã«ã¨ã©ã¼ãè¿ãããã
|
---|
| 1348 | */
|
---|
| 1349 | if (cep->fsm_state < TCP_FSM_ESTABLISHED && cep->rxtshift > 3 && cep->net_error != E_OK) {
|
---|
| 1350 | cep->error = E_CLS;
|
---|
| 1351 | tcp_close(cep);
|
---|
| 1352 | }
|
---|
| 1353 | else {
|
---|
| 1354 | cep->net_error = error;
|
---|
| 1355 |
|
---|
| 1356 | /* éä¿¡ãæ示ããã*/
|
---|
| 1357 | cep->flags |= TCP_CEP_FLG_POST_OUTPUT;
|
---|
| 1358 | sig_sem(SEM_TCP_POST_OUTPUT);
|
---|
| 1359 | }
|
---|
| 1360 | }
|
---|
| 1361 | }
|
---|
| 1362 |
|
---|
| 1363 | /*
|
---|
| 1364 | * tcp_find_cep -- ãã¼ãçªå·ãã TCP é信端ç¹ãå¾ãã
|
---|
| 1365 | *
|
---|
| 1366 | * 注æ: dstaddr ã¯ã
|
---|
| 1367 | * TINET-1.2 ãããããã¯ã¼ã¯ãã¤ããªã¼ãã
|
---|
| 1368 | * TINET-1.1 ã¾ã§ã¯ããã¹ããã¤ããªã¼ã
|
---|
| 1369 | */
|
---|
| 1370 |
|
---|
| 1371 | T_TCP_CEP*
|
---|
| 1372 | tcp_find_cep (T_IN_ADDR *dstaddr, uint16_t dstport, T_IN_ADDR *peeraddr, uint16_t peerport)
|
---|
| 1373 | {
|
---|
| 1374 | T_TCP_CEP* cep;
|
---|
| 1375 |
|
---|
| 1376 | /*
|
---|
| 1377 | * ç¶æ
|
---|
| 1378 | ã SYN éä¿¡æ¸ã¿ä»¥å¾ã¯ã
|
---|
| 1379 | * IP ã¢ãã¬ã¹ã¨ãã¼ãçªå·ãä¸è´ããé信端ç¹ãæ¢ç´¢ããã
|
---|
| 1380 | */
|
---|
| 1381 | for (cep = &tcp_cep[tmax_tcp_cepid]; cep -- != tcp_cep; ) {
|
---|
| 1382 | if (cep->fsm_state >= TCP_FSM_SYN_SENT &&
|
---|
| 1383 | IN_IS_DSTADDR_ACCEPT (&cep->myaddr.ipaddr, dstaddr) &&
|
---|
| 1384 | IN_ARE_NET_ADDR_EQUAL(&cep->dstaddr.ipaddr, peeraddr) &&
|
---|
| 1385 | dstport == cep->myaddr.portno &&
|
---|
| 1386 | peerport == cep->dstaddr.portno)
|
---|
| 1387 | return cep;
|
---|
| 1388 | }
|
---|
| 1389 |
|
---|
| 1390 | /* ååãªã¼ãã³ä¸ã®é信端ç¹ãæ¢ç´¢ããã*/
|
---|
| 1391 | for (cep = &tcp_cep[tmax_tcp_cepid]; cep -- != tcp_cep; ) {
|
---|
| 1392 | if (cep->fsm_state == TCP_FSM_LISTEN &&
|
---|
| 1393 | IN_IS_DSTADDR_ACCEPT(&cep->myaddr.ipaddr, dstaddr) &&
|
---|
| 1394 | dstport == cep->myaddr.portno)
|
---|
| 1395 | return cep;
|
---|
| 1396 | }
|
---|
| 1397 |
|
---|
| 1398 | return NULL;
|
---|
| 1399 | }
|
---|
| 1400 |
|
---|
| 1401 | /*
|
---|
| 1402 | * tcp_lock_cep -- TCP é信端ç¹ãããã¯ããã
|
---|
| 1403 | */
|
---|
| 1404 |
|
---|
| 1405 | ER
|
---|
| 1406 | tcp_lock_cep (ID cepid, T_TCP_CEP **p_cep, FN tfn)
|
---|
| 1407 | {
|
---|
| 1408 | T_TCP_CEP *cep;
|
---|
| 1409 | ER error = E_OK;
|
---|
| 1410 |
|
---|
| 1411 | *p_cep = NULL;
|
---|
| 1412 |
|
---|
| 1413 | /* TCP éä¿¡ç«¯ç¹ ID ããã§ãã¯ããã*/
|
---|
| 1414 | if (!VAID_TCP_CEPID(cepid))
|
---|
| 1415 | return E_ID;
|
---|
| 1416 |
|
---|
| 1417 | /* TCP é信端ç¹ãå¾ãã*/
|
---|
| 1418 | cep = GET_TCP_CEP(cepid);
|
---|
| 1419 |
|
---|
| 1420 | /* TCP é信端ç¹ãããã¯ããã*/
|
---|
| 1421 | syscall(wai_sem(cep->semid_lock));
|
---|
| 1422 |
|
---|
| 1423 | /* TCP é信端ç¹ããã§ãã¯ããã*/
|
---|
| 1424 | if (!VALID_TCP_CEP(cep)) {
|
---|
| 1425 | syscall(sig_sem(cep->semid_lock));
|
---|
| 1426 | return E_NOEXS;
|
---|
| 1427 | }
|
---|
| 1428 |
|
---|
| 1429 | /*
|
---|
| 1430 | * API æ©è½ã³ã¼ãã¨ã¿ã¹ã¯èå¥åãè¨é²ããã
|
---|
| 1431 | * ãã§ã«è¨é²ããã¦ããã°ããã³ãã£ã³ã°ä¸ãªã®ã§ã¨ã©ã¼
|
---|
| 1432 | */
|
---|
| 1433 | if (IS_TFN_TCP_RCV(tfn)) {
|
---|
| 1434 | if (cep->rcv_tfn != TFN_TCP_UNDEF ||
|
---|
| 1435 | (tfn == TFN_TCP_ACP_CEP && cep->snd_tfn == TFN_TCP_CON_CEP))
|
---|
| 1436 | error = E_OBJ;
|
---|
| 1437 | else {
|
---|
| 1438 | get_tid(&(cep->rcv_tskid));
|
---|
| 1439 | cep->rcv_tfn = tfn;
|
---|
| 1440 | }
|
---|
| 1441 | }
|
---|
| 1442 | else {
|
---|
| 1443 | if (cep->snd_tfn != TFN_TCP_UNDEF ||
|
---|
| 1444 | (tfn == TFN_TCP_CON_CEP && cep->rcv_tfn == TFN_TCP_ACP_CEP) ||
|
---|
| 1445 | (tfn == TFN_TCP_CON_CEP && cep->rcv_tfn == TFN_TCP_CLS_CEP))
|
---|
| 1446 | error = E_OBJ;
|
---|
| 1447 | else {
|
---|
| 1448 | get_tid(&(cep->snd_tskid));
|
---|
| 1449 | cep->snd_tfn = tfn;
|
---|
| 1450 | }
|
---|
| 1451 | }
|
---|
| 1452 |
|
---|
| 1453 | /* é信端ç¹ã®ããã¯ã解é¤ããã*/
|
---|
| 1454 | syscall(sig_sem(cep->semid_lock));
|
---|
| 1455 |
|
---|
| 1456 | *p_cep = cep;
|
---|
| 1457 | return error;
|
---|
| 1458 | }
|
---|
| 1459 |
|
---|
| 1460 | #ifdef TCP_CFG_TRACE
|
---|
| 1461 |
|
---|
| 1462 | #ifndef CONSOLE_PORTID
|
---|
| 1463 | #define CONSOLE_PORTID LOGTASK_PORTID
|
---|
| 1464 | #endif
|
---|
| 1465 |
|
---|
| 1466 | /*
|
---|
| 1467 | * ã³ãã¯ã·ã§ã³ã®ç¶æ
|
---|
| 1468 |
|
---|
| 1469 | */
|
---|
| 1470 |
|
---|
| 1471 | static const char tcp_strfsm[][3] = {
|
---|
| 1472 | { 'C', 'D', '\0' },
|
---|
| 1473 | { 'L', 'I', '\0' },
|
---|
| 1474 | { 'S', 'S', '\0' },
|
---|
| 1475 | { 'S', 'R', '\0' },
|
---|
| 1476 | { 'E', 'S', '\0' },
|
---|
| 1477 | { 'C', 'W', '\0' },
|
---|
| 1478 | { 'F', '1', '\0' },
|
---|
| 1479 | { 'C', 'G', '\0' },
|
---|
| 1480 | { 'L', 'A', '\0' },
|
---|
| 1481 | { 'F', '2', '\0' },
|
---|
| 1482 | { 'T', 'W', '\0' },
|
---|
| 1483 | };
|
---|
| 1484 |
|
---|
| 1485 | /*
|
---|
| 1486 | * trace_putchar -- ã·ãªã¢ã«ãã¼ãã¸ã®æååºå
|
---|
| 1487 | */
|
---|
| 1488 |
|
---|
| 1489 | static void
|
---|
| 1490 | trace_putchar (ID portid, char ch)
|
---|
| 1491 | {
|
---|
| 1492 | serial_wri_dat(portid, &ch, 1);
|
---|
| 1493 | /*cpu_putc(ch);*/
|
---|
| 1494 | }
|
---|
| 1495 |
|
---|
| 1496 | /*
|
---|
| 1497 | * ã·ãªã¢ã«ãã¼ãã¸ã®æ¸å¼ä»æåååºåã©ã¤ãã©ãª
|
---|
| 1498 | */
|
---|
| 1499 |
|
---|
| 1500 | /*
|
---|
| 1501 | * æ°å¤å¤æã®ããã®å¤æ表
|
---|
| 1502 | */
|
---|
| 1503 |
|
---|
| 1504 | static const char radhex[] = "0123456789abcdef";
|
---|
| 1505 | static const char radHEX[] = "0123456789ABCDEF";
|
---|
| 1506 |
|
---|
| 1507 | /*
|
---|
| 1508 | * convert -- trace_printf ã®æ°å¤å¤æ
|
---|
| 1509 | */
|
---|
| 1510 |
|
---|
| 1511 | static int_t
|
---|
| 1512 | convert (ID portid, long_t val, int_t radix,
|
---|
| 1513 | const char *radchar, int_t width, bool_t minus, char padchar)
|
---|
| 1514 | {
|
---|
| 1515 | char digits[24];
|
---|
| 1516 | int_t ix, pad, pchars;
|
---|
| 1517 |
|
---|
| 1518 | ix = 0;
|
---|
| 1519 | do {
|
---|
| 1520 | if (minus)
|
---|
| 1521 | digits[ix ++] = radchar[val % radix];
|
---|
| 1522 | else
|
---|
| 1523 | digits[ix ++] = radchar[(ulong_t)val % radix];
|
---|
| 1524 | val /= radix;
|
---|
| 1525 | } while (val != 0);
|
---|
| 1526 |
|
---|
| 1527 | if (minus)
|
---|
| 1528 | digits[ix ++] = '-';
|
---|
| 1529 |
|
---|
| 1530 | if (width > ix)
|
---|
| 1531 | pchars = width;
|
---|
| 1532 | else
|
---|
| 1533 | pchars = ix;
|
---|
| 1534 |
|
---|
| 1535 | for (pad = ix; pad < width; pad ++)
|
---|
| 1536 | trace_putchar(portid, padchar);
|
---|
| 1537 |
|
---|
| 1538 | while (ix -- > 0)
|
---|
| 1539 | trace_putchar(portid, digits[ix]);
|
---|
| 1540 |
|
---|
| 1541 | return pchars;
|
---|
| 1542 | }
|
---|
| 1543 |
|
---|
| 1544 | /*
|
---|
| 1545 | * trace_printf -- ã·ãªã¢ã«ãã¼ãã¸ã®æ¸å¼ä»æåååºå
|
---|
| 1546 | */
|
---|
| 1547 |
|
---|
| 1548 | static void
|
---|
| 1549 | trace_printf (ID portid, const char *fmt, ...)
|
---|
| 1550 | {
|
---|
| 1551 | va_list ap;
|
---|
| 1552 | ulong_t val;
|
---|
| 1553 | char padchar, *str;
|
---|
| 1554 | int_t ch, width, longflag;
|
---|
| 1555 |
|
---|
| 1556 | va_start(ap, fmt);
|
---|
| 1557 | while ((ch = *fmt ++) != '\0') {
|
---|
| 1558 | if (ch != '%') { /* æ¸å¼æå®ä»¥å¤ */
|
---|
| 1559 | trace_putchar(portid, (char)ch);
|
---|
| 1560 | continue;
|
---|
| 1561 | }
|
---|
| 1562 |
|
---|
| 1563 | width = longflag = 0;
|
---|
| 1564 | padchar = ' ';
|
---|
| 1565 | if ((ch = *fmt ++) == '0') { /* ä¸ä½æ¡ã® 0 */
|
---|
| 1566 | padchar = '0';
|
---|
| 1567 | ch = *fmt ++;
|
---|
| 1568 | }
|
---|
| 1569 |
|
---|
| 1570 | while ('0' <= ch && ch <= '9') { /* åºåå¹
|
---|
| 1571 | */
|
---|
| 1572 | width = width * 10 + ch - '0';
|
---|
| 1573 | ch = *fmt ++;
|
---|
| 1574 | }
|
---|
| 1575 |
|
---|
| 1576 | while (ch == 'l') { /* long (long) ã®æå® */
|
---|
| 1577 | longflag ++;
|
---|
| 1578 | ch = *fmt ++;
|
---|
| 1579 | }
|
---|
| 1580 |
|
---|
| 1581 | switch (ch) {
|
---|
| 1582 | case 'd':
|
---|
| 1583 | val = longflag ? (ulong_t)va_arg(ap, long_t)
|
---|
| 1584 | : (ulong_t)va_arg(ap, int_t);
|
---|
| 1585 | if (val >= 0)
|
---|
| 1586 | convert(portid, val, 10, radhex, width, false, padchar);
|
---|
| 1587 | else
|
---|
| 1588 | convert(portid, -val, 10, radhex, width, true, padchar);
|
---|
| 1589 | break;
|
---|
| 1590 |
|
---|
| 1591 | case 'u':
|
---|
| 1592 | val = longflag ? (ulong_t)va_arg(ap, ulong_t)
|
---|
| 1593 | : (ulong_t)va_arg(ap, uint_t);
|
---|
| 1594 | convert(portid, val, 10, radhex, width, false, padchar);
|
---|
| 1595 | break;
|
---|
| 1596 |
|
---|
| 1597 | case 'x':
|
---|
| 1598 | val = longflag ? (ulong_t)va_arg(ap, ulong_t)
|
---|
| 1599 | : (ulong_t)va_arg(ap, uint_t);
|
---|
| 1600 | convert(portid, val, 16, radhex, width, false, padchar);
|
---|
| 1601 | break;
|
---|
| 1602 |
|
---|
| 1603 | case 'X':
|
---|
| 1604 | val = longflag ? (ulong_t)va_arg(ap, ulong_t)
|
---|
| 1605 | : (ulong_t)va_arg(ap, uint_t);
|
---|
| 1606 | convert(portid, val, 16, radHEX, width, false, padchar);
|
---|
| 1607 | break;
|
---|
| 1608 |
|
---|
| 1609 | case 'c':
|
---|
| 1610 | ch = va_arg(ap, int_t);
|
---|
| 1611 | trace_putchar(portid, (char)ch);
|
---|
| 1612 | break;
|
---|
| 1613 |
|
---|
| 1614 | case 's':
|
---|
| 1615 | str = va_arg(ap, char*);
|
---|
| 1616 | while ((ch = *str ++) != '\0')
|
---|
| 1617 | trace_putchar(portid, (char)ch);
|
---|
| 1618 | break;
|
---|
| 1619 |
|
---|
| 1620 | case '%':
|
---|
| 1621 | trace_putchar(portid, '%');
|
---|
| 1622 | break;
|
---|
| 1623 |
|
---|
| 1624 | case '0':
|
---|
| 1625 | fmt --;
|
---|
| 1626 | break;
|
---|
| 1627 |
|
---|
| 1628 | default:
|
---|
| 1629 | break;
|
---|
| 1630 | }
|
---|
| 1631 |
|
---|
| 1632 | }
|
---|
| 1633 | va_end(ap);
|
---|
| 1634 | }
|
---|
| 1635 |
|
---|
| 1636 | /*
|
---|
| 1637 | * TCP ãã©ã°æåå
|
---|
| 1638 | */
|
---|
| 1639 |
|
---|
| 1640 | static char *
|
---|
| 1641 | get_tcp_flag_str (char *buf, uint8_t flags)
|
---|
| 1642 | {
|
---|
| 1643 | static char tcp_flag_str[] = "FSRPAU";
|
---|
| 1644 |
|
---|
| 1645 | int_t bit, mask = 1;
|
---|
| 1646 |
|
---|
| 1647 | for (bit = 0; bit < sizeof(tcp_flag_str); bit ++) {
|
---|
| 1648 | buf[sizeof(tcp_flag_str) - bit - 1] = (char)((flags & mask) ? tcp_flag_str[bit] : '-');
|
---|
| 1649 | mask <<= 1;
|
---|
| 1650 | }
|
---|
| 1651 | buf[sizeof(tcp_flag_str)] = '\0';
|
---|
| 1652 | return buf;
|
---|
| 1653 | }
|
---|
| 1654 |
|
---|
| 1655 | /*
|
---|
| 1656 | * éä¿¡ TCP ãããã®ãã¬ã¼ã¹åºå
|
---|
| 1657 | */
|
---|
| 1658 |
|
---|
| 1659 | void
|
---|
| 1660 | tcp_output_trace (T_NET_BUF *output, T_TCP_CEP *cep)
|
---|
| 1661 | {
|
---|
| 1662 | SYSTIM time;
|
---|
| 1663 | T_IP_HDR *iph;
|
---|
| 1664 | T_TCP_HDR *tcph;
|
---|
| 1665 | char buf[9];
|
---|
| 1666 |
|
---|
| 1667 | if (!(TCP_CFG_TRACE_LPORTNO == TCP_PORTANY || cep->myaddr.portno == TCP_CFG_TRACE_LPORTNO) ||
|
---|
| 1668 | !(TCP_CFG_TRACE_RPORTNO == TCP_PORTANY || cep->dstaddr.portno == TCP_CFG_TRACE_RPORTNO))
|
---|
| 1669 | return;
|
---|
| 1670 |
|
---|
| 1671 | #if defined(SUPPORT_INET4)
|
---|
| 1672 |
|
---|
| 1673 | if (!(TCP_CFG_TRACE_IPV4_RADDR == IPV4_ADDRANY || cep->dstaddr.ipaddr == TCP_CFG_TRACE_IPV4_RADDR))
|
---|
| 1674 | return;
|
---|
| 1675 |
|
---|
| 1676 | #endif /* of #if defined(SUPPORT_INET4) */
|
---|
| 1677 |
|
---|
| 1678 | syscall(wai_sem(SEM_TCP_TRACE));
|
---|
| 1679 | syscall(get_tim(&time));
|
---|
| 1680 | iph = GET_IP_HDR(output);
|
---|
| 1681 | tcph = GET_TCP_HDR(output, GET_TCP_HDR_OFFSET(output));
|
---|
| 1682 | if (time > 99999999)
|
---|
| 1683 | trace_printf(CONSOLE_PORTID, "=O%10d", time / 1000);
|
---|
| 1684 | else
|
---|
| 1685 | trace_printf(CONSOLE_PORTID, "=O%6d.%03d", time / 1000, time % 1000);
|
---|
| 1686 | if (cep == NULL)
|
---|
| 1687 | trace_printf(CONSOLE_PORTID, "=c:-- s:-- f:-----");
|
---|
| 1688 | else
|
---|
| 1689 | trace_printf(CONSOLE_PORTID, "=c:%2d s:%s f:%05x",
|
---|
| 1690 | GET_TCP_CEPID(cep),
|
---|
| 1691 | tcp_strfsm[cep->fsm_state], cep->flags);
|
---|
| 1692 | trace_printf(CONSOLE_PORTID, ":%s", get_tcp_flag_str(buf, tcph->flags));
|
---|
| 1693 | if (cep->fsm_state >= TCP_FSM_ESTABLISHED)
|
---|
| 1694 | trace_printf(CONSOLE_PORTID, " s:%10u a:%10u",
|
---|
| 1695 | ntohl(tcph->seq) - cep->iss,
|
---|
| 1696 | ntohl(tcph->ack) - cep->irs);
|
---|
| 1697 | else
|
---|
| 1698 | trace_printf(CONSOLE_PORTID, " s:%10u a:%10u",
|
---|
| 1699 | ntohl(tcph->seq), ntohl(tcph->ack));
|
---|
| 1700 | trace_printf(CONSOLE_PORTID, " w:%5d l:%4d>\n",
|
---|
| 1701 | ntohs(tcph->win),
|
---|
| 1702 | GET_IP_SDU_SIZE(iph) - TCP_HDR_LEN(tcph->doff));
|
---|
| 1703 | syscall(sig_sem(SEM_TCP_TRACE));
|
---|
| 1704 | }
|
---|
| 1705 |
|
---|
| 1706 | /*
|
---|
| 1707 | * åä¿¡ TCP ãããã®ãã¬ã¼ã¹åºå
|
---|
| 1708 | *
|
---|
| 1709 | * 注æ: TCP ãããå
|
---|
| 1710 | ã¯ããã§ã«ãã¹ããã¤ããªã¼ã
|
---|
| 1711 | */
|
---|
| 1712 |
|
---|
| 1713 | void
|
---|
| 1714 | tcp_input_trace (T_NET_BUF *input, T_TCP_CEP *cep)
|
---|
| 1715 | {
|
---|
| 1716 | SYSTIM time;
|
---|
| 1717 | T_IP_HDR *iph;
|
---|
| 1718 | T_TCP_HDR *tcph;
|
---|
| 1719 | char buf[9];
|
---|
| 1720 |
|
---|
| 1721 | if (!(TCP_CFG_TRACE_LPORTNO == TCP_PORTANY || cep->myaddr.portno == TCP_CFG_TRACE_LPORTNO) ||
|
---|
| 1722 | !(TCP_CFG_TRACE_RPORTNO == TCP_PORTANY || cep->dstaddr.portno == TCP_CFG_TRACE_RPORTNO))
|
---|
| 1723 | return;
|
---|
| 1724 |
|
---|
| 1725 | #if defined(SUPPORT_INET4)
|
---|
| 1726 |
|
---|
| 1727 | if (!(TCP_CFG_TRACE_IPV4_RADDR == IPV4_ADDRANY || cep->dstaddr.ipaddr == TCP_CFG_TRACE_IPV4_RADDR))
|
---|
| 1728 | return;
|
---|
| 1729 |
|
---|
| 1730 | #endif /* of #if defined(SUPPORT_INET4) */
|
---|
| 1731 |
|
---|
| 1732 | syscall(wai_sem(SEM_TCP_TRACE));
|
---|
| 1733 | syscall(get_tim(&time));
|
---|
| 1734 | iph = GET_IP_HDR(input);
|
---|
| 1735 | tcph = GET_TCP_HDR(input, GET_TCP_HDR_OFFSET(input));
|
---|
| 1736 | if (time > 99999999)
|
---|
| 1737 | trace_printf(CONSOLE_PORTID, "<I%10d", time / 1000);
|
---|
| 1738 | else
|
---|
| 1739 | trace_printf(CONSOLE_PORTID, "<I%6d.%03d", time / 1000, time % 1000);
|
---|
| 1740 | if (cep == NULL)
|
---|
| 1741 | trace_printf(CONSOLE_PORTID, "=c:-- s:-- f:-----");
|
---|
| 1742 | else
|
---|
| 1743 | trace_printf(CONSOLE_PORTID, "=c:%2d s:%s f:%05x",
|
---|
| 1744 | GET_TCP_CEPID(cep),
|
---|
| 1745 | tcp_strfsm[cep->fsm_state], cep->flags);
|
---|
| 1746 | trace_printf(CONSOLE_PORTID, ":%s", get_tcp_flag_str(buf, tcph->flags));
|
---|
| 1747 | if (cep->fsm_state >= TCP_FSM_SYN_RECVD)
|
---|
| 1748 | trace_printf(CONSOLE_PORTID, " a:%10u s:%10u", tcph->ack - cep->iss, tcph->seq - cep->irs);
|
---|
| 1749 | else
|
---|
| 1750 | trace_printf(CONSOLE_PORTID, " a:%10u s:%10u", tcph->ack, tcph->seq);
|
---|
| 1751 | trace_printf(CONSOLE_PORTID, " w:%5d l:%4d=\n",
|
---|
| 1752 | tcph->win, GET_IP_SDU_SIZE(iph) - TCP_HDR_LEN(tcph->doff));
|
---|
| 1753 | syscall(sig_sem(SEM_TCP_TRACE));
|
---|
| 1754 | }
|
---|
| 1755 |
|
---|
| 1756 | #endif /* of #ifdef TCP_CFG_TRACE */
|
---|
| 1757 |
|
---|
| 1758 | #endif /* of #ifdef SUPPORT_TCP */
|
---|