tcp_timewait.c (50477) | tcp_timewait.c (50673) |
---|---|
1/* 2 * Copyright (c) 1982, 1986, 1988, 1990, 1993, 1995 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 17 unchanged lines hidden (view full) --- 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * @(#)tcp_subr.c 8.2 (Berkeley) 5/24/95 | 1/* 2 * Copyright (c) 1982, 1986, 1988, 1990, 1993, 1995 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 17 unchanged lines hidden (view full) --- 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * @(#)tcp_subr.c 8.2 (Berkeley) 5/24/95 |
34 * $FreeBSD: head/sys/netinet/tcp_timewait.c 50477 1999-08-28 01:08:13Z peter $ | 34 * $FreeBSD: head/sys/netinet/tcp_timewait.c 50673 1999-08-30 21:17:07Z jlemon $ |
35 */ 36 37#include "opt_compat.h" 38#include "opt_tcpdebug.h" 39 40#include <sys/param.h> 41#include <sys/systm.h> | 35 */ 36 37#include "opt_compat.h" 38#include "opt_tcpdebug.h" 39 40#include <sys/param.h> 41#include <sys/systm.h> |
42#include <sys/callout.h> |
|
42#include <sys/kernel.h> 43#include <sys/sysctl.h> 44#include <sys/malloc.h> 45#include <sys/mbuf.h> 46#include <sys/proc.h> 47#include <sys/socket.h> 48#include <sys/socketvar.h> 49#include <sys/protosw.h> --- 19 unchanged lines hidden (view full) --- 69#ifdef TCPDEBUG 70#include <netinet/tcp_debug.h> 71#endif 72 73int tcp_mssdflt = TCP_MSS; 74SYSCTL_INT(_net_inet_tcp, TCPCTL_MSSDFLT, mssdflt, CTLFLAG_RW, 75 &tcp_mssdflt , 0, "Default TCP Maximum Segment Size"); 76 | 43#include <sys/kernel.h> 44#include <sys/sysctl.h> 45#include <sys/malloc.h> 46#include <sys/mbuf.h> 47#include <sys/proc.h> 48#include <sys/socket.h> 49#include <sys/socketvar.h> 50#include <sys/protosw.h> --- 19 unchanged lines hidden (view full) --- 70#ifdef TCPDEBUG 71#include <netinet/tcp_debug.h> 72#endif 73 74int tcp_mssdflt = TCP_MSS; 75SYSCTL_INT(_net_inet_tcp, TCPCTL_MSSDFLT, mssdflt, CTLFLAG_RW, 76 &tcp_mssdflt , 0, "Default TCP Maximum Segment Size"); 77 |
78#if 0 |
|
77static int tcp_rttdflt = TCPTV_SRTTDFLT / PR_SLOWHZ; 78SYSCTL_INT(_net_inet_tcp, TCPCTL_RTTDFLT, rttdflt, CTLFLAG_RW, 79 &tcp_rttdflt , 0, "Default maximum TCP Round Trip Time"); | 79static int tcp_rttdflt = TCPTV_SRTTDFLT / PR_SLOWHZ; 80SYSCTL_INT(_net_inet_tcp, TCPCTL_RTTDFLT, rttdflt, CTLFLAG_RW, 81 &tcp_rttdflt , 0, "Default maximum TCP Round Trip Time"); |
82#endif |
|
80 81static int tcp_do_rfc1323 = 1; 82SYSCTL_INT(_net_inet_tcp, TCPCTL_DO_RFC1323, rfc1323, CTLFLAG_RW, 83 &tcp_do_rfc1323 , 0, "Enable rfc1323 (high performance TCP) extensions"); 84 85static int tcp_do_rfc1644 = 0; 86SYSCTL_INT(_net_inet_tcp, TCPCTL_DO_RFC1644, rfc1644, CTLFLAG_RW, 87 &tcp_do_rfc1644 , 0, "Enable rfc1644 (TTCP) extensions"); --- 29 unchanged lines hidden (view full) --- 117#define ALIGNMENT 32 118#define ALIGNM1 (ALIGNMENT - 1) 119struct inp_tp { 120 union { 121 struct inpcb inp; 122 char align[(sizeof(struct inpcb) + ALIGNM1) & ~ALIGNM1]; 123 } inp_tp_u; 124 struct tcpcb tcb; | 83 84static int tcp_do_rfc1323 = 1; 85SYSCTL_INT(_net_inet_tcp, TCPCTL_DO_RFC1323, rfc1323, CTLFLAG_RW, 86 &tcp_do_rfc1323 , 0, "Enable rfc1323 (high performance TCP) extensions"); 87 88static int tcp_do_rfc1644 = 0; 89SYSCTL_INT(_net_inet_tcp, TCPCTL_DO_RFC1644, rfc1644, CTLFLAG_RW, 90 &tcp_do_rfc1644 , 0, "Enable rfc1644 (TTCP) extensions"); --- 29 unchanged lines hidden (view full) --- 120#define ALIGNMENT 32 121#define ALIGNM1 (ALIGNMENT - 1) 122struct inp_tp { 123 union { 124 struct inpcb inp; 125 char align[(sizeof(struct inpcb) + ALIGNM1) & ~ALIGNM1]; 126 } inp_tp_u; 127 struct tcpcb tcb; |
128 struct callout inp_tp_rexmt, inp_tp_persist, inp_tp_keep, inp_tp_2msl; 129 struct callout inp_tp_delack; |
|
125}; 126#undef ALIGNMENT 127#undef ALIGNM1 128 129/* 130 * Tcp initialization 131 */ 132void 133tcp_init() 134{ 135 int hashsize; 136 137 tcp_iss = random(); /* wrong, but better than a constant */ 138 tcp_ccgen = 1; 139 tcp_cleartaocache(); | 130}; 131#undef ALIGNMENT 132#undef ALIGNM1 133 134/* 135 * Tcp initialization 136 */ 137void 138tcp_init() 139{ 140 int hashsize; 141 142 tcp_iss = random(); /* wrong, but better than a constant */ 143 tcp_ccgen = 1; 144 tcp_cleartaocache(); |
145 146 tcp_delacktime = TCPTV_DELACK; 147 tcp_keepinit = TCPTV_KEEP_INIT; 148 tcp_keepidle = TCPTV_KEEP_IDLE; 149 tcp_keepintvl = TCPTV_KEEPINTVL; 150 tcp_maxpersistidle = TCPTV_KEEP_IDLE; 151 tcp_msl = TCPTV_MSL; 152 |
|
140 LIST_INIT(&tcb); 141 tcbinfo.listhead = &tcb; 142 TUNABLE_INT_FETCH("net.inet.tcp.tcbhashsize", TCBHASHSIZE, hashsize); 143 if (!powerof2(hashsize)) { 144 printf("WARNING: TCB hash size not a power of 2\n"); 145 hashsize = 512; /* safe default */ 146 } 147 tcp_tcbhashsize = hashsize; 148 tcbinfo.hashbase = hashinit(hashsize, M_PCB, &tcbinfo.hashmask); 149 tcbinfo.porthashbase = hashinit(hashsize, M_PCB, 150 &tcbinfo.porthashmask); 151 tcbinfo.ipi_zone = zinit("tcpcb", sizeof(struct inp_tp), maxsockets, 152 ZONE_INTERRUPT, 0); | 153 LIST_INIT(&tcb); 154 tcbinfo.listhead = &tcb; 155 TUNABLE_INT_FETCH("net.inet.tcp.tcbhashsize", TCBHASHSIZE, hashsize); 156 if (!powerof2(hashsize)) { 157 printf("WARNING: TCB hash size not a power of 2\n"); 158 hashsize = 512; /* safe default */ 159 } 160 tcp_tcbhashsize = hashsize; 161 tcbinfo.hashbase = hashinit(hashsize, M_PCB, &tcbinfo.hashmask); 162 tcbinfo.porthashbase = hashinit(hashsize, M_PCB, 163 &tcbinfo.porthashmask); 164 tcbinfo.ipi_zone = zinit("tcpcb", sizeof(struct inp_tp), maxsockets, 165 ZONE_INTERRUPT, 0); |
166 |
|
153 if (max_protohdr < sizeof(struct tcpiphdr)) 154 max_protohdr = sizeof(struct tcpiphdr); 155 if (max_linkhdr + sizeof(struct tcpiphdr) > MHLEN) 156 panic("tcp_init"); 157} 158 159/* 160 * Create template to be used to send tcp packets on a connection. --- 138 unchanged lines hidden (view full) --- 299 register struct tcpcb *tp; 300 301 it = (struct inp_tp *)inp; 302 tp = &it->tcb; 303 bzero((char *) tp, sizeof(struct tcpcb)); 304 tp->t_segq = NULL; 305 tp->t_maxseg = tp->t_maxopd = tcp_mssdflt; 306 | 167 if (max_protohdr < sizeof(struct tcpiphdr)) 168 max_protohdr = sizeof(struct tcpiphdr); 169 if (max_linkhdr + sizeof(struct tcpiphdr) > MHLEN) 170 panic("tcp_init"); 171} 172 173/* 174 * Create template to be used to send tcp packets on a connection. --- 138 unchanged lines hidden (view full) --- 313 register struct tcpcb *tp; 314 315 it = (struct inp_tp *)inp; 316 tp = &it->tcb; 317 bzero((char *) tp, sizeof(struct tcpcb)); 318 tp->t_segq = NULL; 319 tp->t_maxseg = tp->t_maxopd = tcp_mssdflt; 320 |
321 /* Set up our timeouts. */ 322 callout_init(tp->tt_rexmt = &it->inp_tp_rexmt); 323 callout_init(tp->tt_persist = &it->inp_tp_persist); 324 callout_init(tp->tt_keep = &it->inp_tp_keep); 325 callout_init(tp->tt_2msl = &it->inp_tp_2msl); 326 callout_init(tp->tt_delack = &it->inp_tp_delack); 327 |
|
307 if (tcp_do_rfc1323) 308 tp->t_flags = (TF_REQ_SCALE|TF_REQ_TSTMP); 309 if (tcp_do_rfc1644) 310 tp->t_flags |= TF_REQ_CC; 311 tp->t_inpcb = inp; /* XXX */ 312 /* 313 * Init srtt to TCPTV_SRTTBASE (0), so we can tell that we have no 314 * rtt estimate. Set rttvar so that srtt + 4 * rttvar gives 315 * reasonable initial retransmit time. 316 */ 317 tp->t_srtt = TCPTV_SRTTBASE; 318 tp->t_rttvar = ((TCPTV_RTOBASE - TCPTV_SRTTBASE) << TCP_RTTVAR_SHIFT) / 4; 319 tp->t_rttmin = TCPTV_MIN; 320 tp->t_rxtcur = TCPTV_RTOBASE; 321 tp->snd_cwnd = TCP_MAXWIN << TCP_MAX_WINSHIFT; 322 tp->snd_ssthresh = TCP_MAXWIN << TCP_MAX_WINSHIFT; | 328 if (tcp_do_rfc1323) 329 tp->t_flags = (TF_REQ_SCALE|TF_REQ_TSTMP); 330 if (tcp_do_rfc1644) 331 tp->t_flags |= TF_REQ_CC; 332 tp->t_inpcb = inp; /* XXX */ 333 /* 334 * Init srtt to TCPTV_SRTTBASE (0), so we can tell that we have no 335 * rtt estimate. Set rttvar so that srtt + 4 * rttvar gives 336 * reasonable initial retransmit time. 337 */ 338 tp->t_srtt = TCPTV_SRTTBASE; 339 tp->t_rttvar = ((TCPTV_RTOBASE - TCPTV_SRTTBASE) << TCP_RTTVAR_SHIFT) / 4; 340 tp->t_rttmin = TCPTV_MIN; 341 tp->t_rxtcur = TCPTV_RTOBASE; 342 tp->snd_cwnd = TCP_MAXWIN << TCP_MAX_WINSHIFT; 343 tp->snd_ssthresh = TCP_MAXWIN << TCP_MAX_WINSHIFT; |
344 tp->t_rcvtime = ticks; |
|
323 inp->inp_ip_ttl = ip_defttl; 324 inp->inp_ppcb = (caddr_t)tp; 325 return (tp); /* XXX */ 326} 327 328/* 329 * Drop a TCP connection, reporting 330 * the specified error. If connection is synchronized, --- 31 unchanged lines hidden (view full) --- 362 register struct mbuf *q; 363 register struct mbuf *nq; 364 struct inpcb *inp = tp->t_inpcb; 365 struct socket *so = inp->inp_socket; 366 register struct rtentry *rt; 367 int dosavessthresh; 368 369 /* | 345 inp->inp_ip_ttl = ip_defttl; 346 inp->inp_ppcb = (caddr_t)tp; 347 return (tp); /* XXX */ 348} 349 350/* 351 * Drop a TCP connection, reporting 352 * the specified error. If connection is synchronized, --- 31 unchanged lines hidden (view full) --- 384 register struct mbuf *q; 385 register struct mbuf *nq; 386 struct inpcb *inp = tp->t_inpcb; 387 struct socket *so = inp->inp_socket; 388 register struct rtentry *rt; 389 int dosavessthresh; 390 391 /* |
392 * Make sure that all of our timers are stopped before we 393 * delete the PCB. 394 */ 395 callout_stop(tp->tt_rexmt); 396 callout_stop(tp->tt_persist); 397 callout_stop(tp->tt_keep); 398 callout_stop(tp->tt_2msl); 399 callout_stop(tp->tt_delack); 400 401 /* |
|
370 * If we got enough samples through the srtt filter, 371 * save the rtt and rttvar in the routing entry. 372 * 'Enough' is arbitrarily defined as the 16 samples. 373 * 16 samples is enough for the srtt filter to converge 374 * to within 5% of the correct value; fewer samples and 375 * we could save a very bogus rtt. 376 * 377 * Don't update the default route's characteristics and don't 378 * update anything that the user "locked". 379 */ 380 if (tp->t_rttupdated >= 16 && 381 (rt = inp->inp_route.ro_rt) && 382 ((struct sockaddr_in *)rt_key(rt))->sin_addr.s_addr != INADDR_ANY) { 383 register u_long i = 0; 384 385 if ((rt->rt_rmx.rmx_locks & RTV_RTT) == 0) { 386 i = tp->t_srtt * | 402 * If we got enough samples through the srtt filter, 403 * save the rtt and rttvar in the routing entry. 404 * 'Enough' is arbitrarily defined as the 16 samples. 405 * 16 samples is enough for the srtt filter to converge 406 * to within 5% of the correct value; fewer samples and 407 * we could save a very bogus rtt. 408 * 409 * Don't update the default route's characteristics and don't 410 * update anything that the user "locked". 411 */ 412 if (tp->t_rttupdated >= 16 && 413 (rt = inp->inp_route.ro_rt) && 414 ((struct sockaddr_in *)rt_key(rt))->sin_addr.s_addr != INADDR_ANY) { 415 register u_long i = 0; 416 417 if ((rt->rt_rmx.rmx_locks & RTV_RTT) == 0) { 418 i = tp->t_srtt * |
387 (RTM_RTTUNIT / (PR_SLOWHZ * TCP_RTT_SCALE)); | 419 (RTM_RTTUNIT / (hz * TCP_RTT_SCALE)); |
388 if (rt->rt_rmx.rmx_rtt && i) 389 /* 390 * filter this update to half the old & half 391 * the new values, converting scale. 392 * See route.h and tcp_var.h for a 393 * description of the scaling constants. 394 */ 395 rt->rt_rmx.rmx_rtt = 396 (rt->rt_rmx.rmx_rtt + i) / 2; 397 else 398 rt->rt_rmx.rmx_rtt = i; 399 tcpstat.tcps_cachedrtt++; 400 } 401 if ((rt->rt_rmx.rmx_locks & RTV_RTTVAR) == 0) { 402 i = tp->t_rttvar * | 420 if (rt->rt_rmx.rmx_rtt && i) 421 /* 422 * filter this update to half the old & half 423 * the new values, converting scale. 424 * See route.h and tcp_var.h for a 425 * description of the scaling constants. 426 */ 427 rt->rt_rmx.rmx_rtt = 428 (rt->rt_rmx.rmx_rtt + i) / 2; 429 else 430 rt->rt_rmx.rmx_rtt = i; 431 tcpstat.tcps_cachedrtt++; 432 } 433 if ((rt->rt_rmx.rmx_locks & RTV_RTTVAR) == 0) { 434 i = tp->t_rttvar * |
403 (RTM_RTTUNIT / (PR_SLOWHZ * TCP_RTTVAR_SCALE)); | 435 (RTM_RTTUNIT / (hz * TCP_RTTVAR_SCALE)); |
404 if (rt->rt_rmx.rmx_rttvar && i) 405 rt->rt_rmx.rmx_rttvar = 406 (rt->rt_rmx.rmx_rttvar + i) / 2; 407 else 408 rt->rt_rmx.rmx_rttvar = i; 409 tcpstat.tcps_cachedrttvar++; 410 } 411 /* --- 317 unchanged lines hidden (view full) --- 729 mss = mss / MCLBYTES * MCLBYTES; 730#endif 731 if (so->so_snd.sb_hiwat < mss) 732 mss = so->so_snd.sb_hiwat; 733 734 tp->t_maxseg = mss; 735 736 tcpstat.tcps_mturesent++; | 436 if (rt->rt_rmx.rmx_rttvar && i) 437 rt->rt_rmx.rmx_rttvar = 438 (rt->rt_rmx.rmx_rttvar + i) / 2; 439 else 440 rt->rt_rmx.rmx_rttvar = i; 441 tcpstat.tcps_cachedrttvar++; 442 } 443 /* --- 317 unchanged lines hidden (view full) --- 761 mss = mss / MCLBYTES * MCLBYTES; 762#endif 763 if (so->so_snd.sb_hiwat < mss) 764 mss = so->so_snd.sb_hiwat; 765 766 tp->t_maxseg = mss; 767 768 tcpstat.tcps_mturesent++; |
737 tp->t_rtt = 0; | 769 tp->t_rtttime = 0; |
738 tp->snd_nxt = tp->snd_una; 739 tcp_output(tp); 740 } 741} 742 743/* 744 * Look-up the routing entry to the peer of this inpcb. If no route 745 * is found and it cannot be allocated the return NULL. This routine --- 57 unchanged lines hidden --- | 770 tp->snd_nxt = tp->snd_una; 771 tcp_output(tp); 772 } 773} 774 775/* 776 * Look-up the routing entry to the peer of this inpcb. If no route 777 * is found and it cannot be allocated the return NULL. This routine --- 57 unchanged lines hidden --- |