tcp_timewait.c revision 14546
1107191Sru/* 2107191Sru * Copyright (c) 1982, 1986, 1988, 1990, 1993, 1995 3107191Sru * The Regents of the University of California. All rights reserved. 4107191Sru * 5107191Sru * Redistribution and use in source and binary forms, with or without 6107191Sru * modification, are permitted provided that the following conditions 7107191Sru * are met: 8107191Sru * 1. Redistributions of source code must retain the above copyright 9107191Sru * notice, this list of conditions and the following disclaimer. 10107191Sru * 2. Redistributions in binary form must reproduce the above copyright 11107191Sru * notice, this list of conditions and the following disclaimer in the 12107191Sru * documentation and/or other materials provided with the distribution. 13107191Sru * 3. All advertising materials mentioning features or use of this software 14107191Sru * must display the following acknowledgement: 15175571Strhodes * This product includes software developed by the University of 16107191Sru * California, Berkeley and its contributors. 17107191Sru * 4. Neither the name of the University nor the names of its contributors 18107191Sru * may be used to endorse or promote products derived from this software 19107191Sru * without specific prior written permission. 20107191Sru * 21107191Sru * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22107191Sru * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23107191Sru * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24107191Sru * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25107191Sru * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26107191Sru * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27175571Strhodes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28175573Strhodes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29107191Sru * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30107191Sru * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31107191Sru * SUCH DAMAGE. 32107191Sru * 33107191Sru * @(#)tcp_subr.c 8.2 (Berkeley) 5/24/95 34107191Sru * $Id: tcp_subr.c,v 1.25 1995/12/20 17:42:28 wollman Exp $ 35107191Sru */ 36107191Sru 37107191Sru#include <sys/param.h> 38107191Sru#include <sys/queue.h> 39107191Sru#include <sys/proc.h> 40107191Sru#include <sys/systm.h> 41107191Sru#include <sys/kernel.h> 42107191Sru#include <sys/sysctl.h> 43107191Sru#include <sys/malloc.h> 44107191Sru#include <sys/mbuf.h> 45107191Sru#include <sys/socket.h> 46107191Sru#include <sys/socketvar.h> 47107191Sru#include <sys/protosw.h> 48107191Sru#include <sys/errno.h> 49107191Sru 50107191Sru#include <net/route.h> 51107191Sru#include <net/if.h> 52107191Sru 53107191Sru#include <netinet/in.h> 54107191Sru#include <netinet/in_systm.h> 55107191Sru#include <netinet/ip.h> 56107191Sru#include <netinet/in_pcb.h> 57107191Sru#include <netinet/in_var.h> 58107191Sru#include <netinet/ip_var.h> 59107191Sru#include <netinet/ip_icmp.h> 60107191Sru#include <netinet/tcp.h> 61107191Sru#include <netinet/tcp_fsm.h> 62107191Sru#include <netinet/tcp_seq.h> 63107191Sru#include <netinet/tcp_timer.h> 64107191Sru#include <netinet/tcp_var.h> 65107191Sru#include <netinet/tcpip.h> 66107191Sru#ifdef TCPDEBUG 67107191Sru#include <netinet/tcp_debug.h> 68107191Sru#endif 69107191Sru 70107191Sruint tcp_mssdflt = TCP_MSS; 71107191SruSYSCTL_INT(_net_inet_tcp, TCPCTL_MSSDFLT, mssdflt, 72107191Sru CTLFLAG_RW, &tcp_mssdflt , 0, ""); 73107191Sru 74107191Srustatic int tcp_rttdflt = TCPTV_SRTTDFLT / PR_SLOWHZ; 75107191SruSYSCTL_INT(_net_inet_tcp, TCPCTL_RTTDFLT, rttdflt, 76107191Sru CTLFLAG_RW, &tcp_rttdflt , 0, ""); 77107191Sru 78107191Srustatic int tcp_do_rfc1323 = 1; 79107191SruSYSCTL_INT(_net_inet_tcp, TCPCTL_DO_RFC1323, rfc1323, 80107191Sru CTLFLAG_RW, &tcp_do_rfc1323 , 0, ""); 81107191Sru 82107191Srustatic int tcp_do_rfc1644 = 1; 83107191SruSYSCTL_INT(_net_inet_tcp, TCPCTL_DO_RFC1644, rfc1644, 84107191Sru CTLFLAG_RW, &tcp_do_rfc1644 , 0, ""); 85107191Sru 86107191Srustatic void tcp_cleartaocache(void); 87107191Srustatic void tcp_notify __P((struct inpcb *, int)); 88107191Sru 89107191Sru/* 90107191Sru * Target size of TCP PCB hash table. Will be rounded down to a prime 91107191Sru * number. 92107191Sru */ 93107191Sru#ifndef TCBHASHSIZE 94107191Sru#define TCBHASHSIZE 128 95107191Sru#endif 96107191Sru 97107191Sru/* 98107191Sru * Tcp initialization 99107191Sru */ 100157661Sbrueffervoid 101107191Srutcp_init() 102107191Sru{ 103175571Strhodes 104175571Strhodes tcp_iss = random(); /* wrong, but better than a constant */ 105175571Strhodes tcp_ccgen = 1; 106175571Strhodes tcp_cleartaocache(); 107175571Strhodes LIST_INIT(&tcb); 108175571Strhodes tcbinfo.listhead = &tcb; 109175571Strhodes tcbinfo.hashbase = phashinit(TCBHASHSIZE, M_PCB, &tcbinfo.hashsize); 110175571Strhodes if (max_protohdr < sizeof(struct tcpiphdr)) 111107191Sru max_protohdr = sizeof(struct tcpiphdr); 112107191Sru if (max_linkhdr + sizeof(struct tcpiphdr) > MHLEN) 113107191Sru panic("tcp_init"); 114107191Sru} 115107191Sru 116107191Sru/* 117107191Sru * Create template to be used to send tcp packets on a connection. 118107191Sru * Call after host entry created, allocates an mbuf and fills 119107191Sru * in a skeletal tcp/ip header, minimizing the amount of work 120107191Sru * necessary when the connection is used. 121107191Sru */ 122107191Srustruct tcpiphdr * 123107191Srutcp_template(tp) 124107191Sru struct tcpcb *tp; 125107191Sru{ 126107191Sru register struct inpcb *inp = tp->t_inpcb; 127107191Sru register struct mbuf *m; 128107191Sru register struct tcpiphdr *n; 129107191Sru 130107191Sru if ((n = tp->t_template) == 0) { 131107191Sru m = m_get(M_DONTWAIT, MT_HEADER); 132107191Sru if (m == NULL) 133107191Sru return (0); 134107191Sru m->m_len = sizeof (struct tcpiphdr); 135107191Sru n = mtod(m, struct tcpiphdr *); 136107191Sru } 137107191Sru n->ti_next = n->ti_prev = 0; 138107191Sru n->ti_x1 = 0; 139107191Sru n->ti_pr = IPPROTO_TCP; 140107191Sru n->ti_len = htons(sizeof (struct tcpiphdr) - sizeof (struct ip)); 141107191Sru n->ti_src = inp->inp_laddr; 142107191Sru n->ti_dst = inp->inp_faddr; 143107191Sru n->ti_sport = inp->inp_lport; 144107191Sru n->ti_dport = inp->inp_fport; 145174776Sru n->ti_seq = 0; 146107191Sru n->ti_ack = 0; 147107191Sru n->ti_x2 = 0; 148107191Sru n->ti_off = 5; 149107191Sru n->ti_flags = 0; 150107191Sru n->ti_win = 0; 151107191Sru n->ti_sum = 0; 152107191Sru n->ti_urp = 0; 153107191Sru return (n); 154107191Sru} 155107191Sru 156107191Sru/* 157107191Sru * Send a single message to the TCP at address specified by 158107191Sru * the given TCP/IP header. If m == 0, then we make a copy 159107191Sru * of the tcpiphdr at ti and send directly to the addressed host. 160107191Sru * This is used to force keep alive messages out using the TCP 161107191Sru * template for a connection tp->t_template. If flags are given 162107191Sru * then we send a message back to the TCP which originated the 163107191Sru * segment ti, and discard the mbuf containing it and any other 164107191Sru * attached mbufs. 165107191Sru * 166107191Sru * In any case the ack and sequence number of the transmitted 167107191Sru * segment are as specified by the parameters. 168107191Sru */ 169107191Sruvoid 170107191Srutcp_respond(tp, ti, m, ack, seq, flags) 171107191Sru struct tcpcb *tp; 172107191Sru register struct tcpiphdr *ti; 173107191Sru register struct mbuf *m; 174107191Sru tcp_seq ack, seq; 175107191Sru int flags; 176107191Sru{ 177107191Sru register int tlen; 178107191Sru int win = 0; 179107191Sru struct route *ro = 0; 180107191Sru 181107191Sru if (tp) { 182107191Sru win = sbspace(&tp->t_inpcb->inp_socket->so_rcv); 183107191Sru ro = &tp->t_inpcb->inp_route; 184107191Sru } 185107191Sru if (m == 0) { 186107191Sru m = m_gethdr(M_DONTWAIT, MT_HEADER); 187107191Sru if (m == NULL) 188107191Sru return; 189107191Sru#ifdef TCP_COMPAT_42 190107191Sru tlen = 1; 191107191Sru#else 192107191Sru tlen = 0; 193107191Sru#endif 194107191Sru m->m_data += max_linkhdr; 195107191Sru *mtod(m, struct tcpiphdr *) = *ti; 196107191Sru ti = mtod(m, struct tcpiphdr *); 197107191Sru flags = TH_ACK; 198107191Sru } else { 199107191Sru m_freem(m->m_next); 200107191Sru m->m_next = 0; 201107191Sru m->m_data = (caddr_t)ti; 202107191Sru m->m_len = sizeof (struct tcpiphdr); 203107191Sru tlen = 0; 204107191Sru#define xchg(a,b,type) { type t; t=a; a=b; b=t; } 205107191Sru xchg(ti->ti_dst.s_addr, ti->ti_src.s_addr, u_long); 206107191Sru xchg(ti->ti_dport, ti->ti_sport, u_short); 207107191Sru#undef xchg 208107191Sru } 209107191Sru ti->ti_len = htons((u_short)(sizeof (struct tcphdr) + tlen)); 210107191Sru tlen += sizeof (struct tcpiphdr); 211107191Sru m->m_len = tlen; 212107191Sru m->m_pkthdr.len = tlen; 213107191Sru m->m_pkthdr.rcvif = (struct ifnet *) 0; 214107191Sru ti->ti_next = ti->ti_prev = 0; 215107191Sru ti->ti_x1 = 0; 216 ti->ti_seq = htonl(seq); 217 ti->ti_ack = htonl(ack); 218 ti->ti_x2 = 0; 219 ti->ti_off = sizeof (struct tcphdr) >> 2; 220 ti->ti_flags = flags; 221 if (tp) 222 ti->ti_win = htons((u_short) (win >> tp->rcv_scale)); 223 else 224 ti->ti_win = htons((u_short)win); 225 ti->ti_urp = 0; 226 ti->ti_sum = 0; 227 ti->ti_sum = in_cksum(m, tlen); 228 ((struct ip *)ti)->ip_len = tlen; 229 ((struct ip *)ti)->ip_ttl = ip_defttl; 230#ifdef TCPDEBUG 231 if (tp == NULL || (tp->t_inpcb->inp_socket->so_options & SO_DEBUG)) 232 tcp_trace(TA_OUTPUT, 0, tp, ti, 0); 233#endif 234 (void) ip_output(m, NULL, ro, 0, NULL); 235} 236 237/* 238 * Create a new TCP control block, making an 239 * empty reassembly queue and hooking it to the argument 240 * protocol control block. 241 */ 242struct tcpcb * 243tcp_newtcpcb(inp) 244 struct inpcb *inp; 245{ 246 register struct tcpcb *tp; 247 248 tp = malloc(sizeof(*tp), M_PCB, M_NOWAIT); 249 if (tp == NULL) 250 return ((struct tcpcb *)0); 251 bzero((char *) tp, sizeof(struct tcpcb)); 252 tp->seg_next = tp->seg_prev = (struct tcpiphdr *)tp; 253 tp->t_maxseg = tp->t_maxopd = tcp_mssdflt; 254 255 if (tcp_do_rfc1323) 256 tp->t_flags = (TF_REQ_SCALE|TF_REQ_TSTMP); 257 if (tcp_do_rfc1644) 258 tp->t_flags |= TF_REQ_CC; 259 tp->t_inpcb = inp; 260 /* 261 * Init srtt to TCPTV_SRTTBASE (0), so we can tell that we have no 262 * rtt estimate. Set rttvar so that srtt + 2 * rttvar gives 263 * reasonable initial retransmit time. 264 */ 265 tp->t_srtt = TCPTV_SRTTBASE; 266 tp->t_rttvar = tcp_rttdflt * PR_SLOWHZ << 2; 267 tp->t_rttmin = TCPTV_MIN; 268 TCPT_RANGESET(tp->t_rxtcur, 269 ((TCPTV_SRTTBASE >> 2) + (TCPTV_SRTTDFLT << 2)) >> 1, 270 TCPTV_MIN, TCPTV_REXMTMAX); 271 tp->snd_cwnd = TCP_MAXWIN << TCP_MAX_WINSHIFT; 272 tp->snd_ssthresh = TCP_MAXWIN << TCP_MAX_WINSHIFT; 273 inp->inp_ip.ip_ttl = ip_defttl; 274 inp->inp_ppcb = (caddr_t)tp; 275 return (tp); 276} 277 278/* 279 * Drop a TCP connection, reporting 280 * the specified error. If connection is synchronized, 281 * then send a RST to peer. 282 */ 283struct tcpcb * 284tcp_drop(tp, errno) 285 register struct tcpcb *tp; 286 int errno; 287{ 288 struct socket *so = tp->t_inpcb->inp_socket; 289 290 if (TCPS_HAVERCVDSYN(tp->t_state)) { 291 tp->t_state = TCPS_CLOSED; 292 (void) tcp_output(tp); 293 tcpstat.tcps_drops++; 294 } else 295 tcpstat.tcps_conndrops++; 296 if (errno == ETIMEDOUT && tp->t_softerror) 297 errno = tp->t_softerror; 298 so->so_error = errno; 299 return (tcp_close(tp)); 300} 301 302/* 303 * Close a TCP control block: 304 * discard all space held by the tcp 305 * discard internet protocol block 306 * wake up any sleepers 307 */ 308struct tcpcb * 309tcp_close(tp) 310 register struct tcpcb *tp; 311{ 312 register struct tcpiphdr *t; 313 struct inpcb *inp = tp->t_inpcb; 314 struct socket *so = inp->inp_socket; 315 register struct mbuf *m; 316#ifdef RTV_RTT 317 register struct rtentry *rt; 318 319 /* 320 * If we got enough samples through the srtt filter, 321 * save the rtt and rttvar in the routing entry. 322 * 'Enough' is arbitrarily defined as the 16 samples. 323 * 16 samples is enough for the srtt filter to converge 324 * to within 5% of the correct value; fewer samples and 325 * we could save a very bogus rtt. 326 * 327 * Don't update the default route's characteristics and don't 328 * update anything that the user "locked". 329 */ 330 if (tp->t_rttupdated >= 16 && 331 (rt = inp->inp_route.ro_rt) && 332 ((struct sockaddr_in *)rt_key(rt))->sin_addr.s_addr != INADDR_ANY) { 333 register u_long i = 0; 334 335 if ((rt->rt_rmx.rmx_locks & RTV_RTT) == 0) { 336 i = tp->t_srtt * 337 (RTM_RTTUNIT / (PR_SLOWHZ * TCP_RTT_SCALE)); 338 if (rt->rt_rmx.rmx_rtt && i) 339 /* 340 * filter this update to half the old & half 341 * the new values, converting scale. 342 * See route.h and tcp_var.h for a 343 * description of the scaling constants. 344 */ 345 rt->rt_rmx.rmx_rtt = 346 (rt->rt_rmx.rmx_rtt + i) / 2; 347 else 348 rt->rt_rmx.rmx_rtt = i; 349 tcpstat.tcps_cachedrtt++; 350 } 351 if ((rt->rt_rmx.rmx_locks & RTV_RTTVAR) == 0) { 352 i = tp->t_rttvar * 353 (RTM_RTTUNIT / (PR_SLOWHZ * TCP_RTTVAR_SCALE)); 354 if (rt->rt_rmx.rmx_rttvar && i) 355 rt->rt_rmx.rmx_rttvar = 356 (rt->rt_rmx.rmx_rttvar + i) / 2; 357 else 358 rt->rt_rmx.rmx_rttvar = i; 359 tcpstat.tcps_cachedrttvar++; 360 } 361 /* 362 * update the pipelimit (ssthresh) if it has been updated 363 * already or if a pipesize was specified & the threshhold 364 * got below half the pipesize. I.e., wait for bad news 365 * before we start updating, then update on both good 366 * and bad news. 367 */ 368 if (((rt->rt_rmx.rmx_locks & RTV_SSTHRESH) == 0 && 369 ((i = tp->snd_ssthresh) != 0) && rt->rt_rmx.rmx_ssthresh) || 370 i < (rt->rt_rmx.rmx_sendpipe / 2)) { 371 /* 372 * convert the limit from user data bytes to 373 * packets then to packet data bytes. 374 */ 375 i = (i + tp->t_maxseg / 2) / tp->t_maxseg; 376 if (i < 2) 377 i = 2; 378 i *= (u_long)(tp->t_maxseg + sizeof (struct tcpiphdr)); 379 if (rt->rt_rmx.rmx_ssthresh) 380 rt->rt_rmx.rmx_ssthresh = 381 (rt->rt_rmx.rmx_ssthresh + i) / 2; 382 else 383 rt->rt_rmx.rmx_ssthresh = i; 384 tcpstat.tcps_cachedssthresh++; 385 } 386 } 387#endif /* RTV_RTT */ 388 /* free the reassembly queue, if any */ 389 t = tp->seg_next; 390 while (t != (struct tcpiphdr *)tp) { 391 t = (struct tcpiphdr *)t->ti_next; 392 m = REASS_MBUF((struct tcpiphdr *)t->ti_prev); 393 remque(t->ti_prev); 394 m_freem(m); 395 } 396 if (tp->t_template) 397 (void) m_free(dtom(tp->t_template)); 398 free(tp, M_PCB); 399 inp->inp_ppcb = 0; 400 soisdisconnected(so); 401 in_pcbdetach(inp); 402 tcpstat.tcps_closed++; 403 return ((struct tcpcb *)0); 404} 405 406void 407tcp_drain() 408{ 409 410} 411 412/* 413 * Notify a tcp user of an asynchronous error; 414 * store error as soft error, but wake up user 415 * (for now, won't do anything until can select for soft error). 416 */ 417static void 418tcp_notify(inp, error) 419 struct inpcb *inp; 420 int error; 421{ 422 register struct tcpcb *tp = (struct tcpcb *)inp->inp_ppcb; 423 register struct socket *so = inp->inp_socket; 424 425 /* 426 * Ignore some errors if we are hooked up. 427 * If connection hasn't completed, has retransmitted several times, 428 * and receives a second error, give up now. This is better 429 * than waiting a long time to establish a connection that 430 * can never complete. 431 */ 432 if (tp->t_state == TCPS_ESTABLISHED && 433 (error == EHOSTUNREACH || error == ENETUNREACH || 434 error == EHOSTDOWN)) { 435 return; 436 } else if (tp->t_state < TCPS_ESTABLISHED && tp->t_rxtshift > 3 && 437 tp->t_softerror) 438 so->so_error = error; 439 else 440 tp->t_softerror = error; 441 wakeup((caddr_t) &so->so_timeo); 442 sorwakeup(so); 443 sowwakeup(so); 444} 445 446void 447tcp_ctlinput(cmd, sa, vip) 448 int cmd; 449 struct sockaddr *sa; 450 void *vip; 451{ 452 register struct ip *ip = vip; 453 register struct tcphdr *th; 454 void (*notify) __P((struct inpcb *, int)) = tcp_notify; 455 456 if (cmd == PRC_QUENCH) 457 notify = tcp_quench; 458#if 1 459 else if (cmd == PRC_MSGSIZE) 460 notify = tcp_mtudisc; 461#endif 462 else if (!PRC_IS_REDIRECT(cmd) && 463 ((unsigned)cmd > PRC_NCMDS || inetctlerrmap[cmd] == 0)) 464 return; 465 if (ip) { 466 th = (struct tcphdr *)((caddr_t)ip + (ip->ip_hl << 2)); 467 in_pcbnotify(&tcb, sa, th->th_dport, ip->ip_src, th->th_sport, 468 cmd, notify); 469 } else 470 in_pcbnotify(&tcb, sa, 0, zeroin_addr, 0, cmd, notify); 471} 472 473/* 474 * When a source quench is received, close congestion window 475 * to one segment. We will gradually open it again as we proceed. 476 */ 477void 478tcp_quench(inp, errno) 479 struct inpcb *inp; 480 int errno; 481{ 482 struct tcpcb *tp = intotcpcb(inp); 483 484 if (tp) 485 tp->snd_cwnd = tp->t_maxseg; 486} 487 488#if 1 489/* 490 * When `need fragmentation' ICMP is received, update our idea of the MSS 491 * based on the new value in the route. Also nudge TCP to send something, 492 * since we know the packet we just sent was dropped. 493 * This duplicates some code in the tcp_mss() function in tcp_input.c. 494 */ 495void 496tcp_mtudisc(inp, errno) 497 struct inpcb *inp; 498 int errno; 499{ 500 struct tcpcb *tp = intotcpcb(inp); 501 struct rtentry *rt; 502 struct rmxp_tao *taop; 503 struct socket *so = inp->inp_socket; 504 int offered; 505 int mss; 506 507 if (tp) { 508 rt = tcp_rtlookup(inp); 509 if (!rt || !rt->rt_rmx.rmx_mtu) { 510 tp->t_maxopd = tp->t_maxseg = tcp_mssdflt; 511 return; 512 } 513 taop = rmx_taop(rt->rt_rmx); 514 offered = taop->tao_mssopt; 515 mss = rt->rt_rmx.rmx_mtu - sizeof(struct tcpiphdr); 516 if (offered) 517 mss = min(mss, offered); 518 /* 519 * XXX - The above conditional probably violates the TCP 520 * spec. The problem is that, since we don't know the 521 * other end's MSS, we are supposed to use a conservative 522 * default. But, if we do that, then MTU discovery will 523 * never actually take place, because the conservative 524 * default is much less than the MTUs typically seen 525 * on the Internet today. For the moment, we'll sweep 526 * this under the carpet. 527 * 528 * The conservative default might not actually be a problem 529 * if the only case this occurs is when sending an initial 530 * SYN with options and data to a host we've never talked 531 * to before. Then, they will reply with an MSS value which 532 * will get recorded and the new parameters should get 533 * recomputed. For Further Study. 534 */ 535 if (tp->t_maxopd <= mss) 536 return; 537 tp->t_maxopd = mss; 538 539 if ((tp->t_flags & (TF_REQ_TSTMP|TF_NOOPT)) == TF_REQ_TSTMP && 540 (tp->t_flags & TF_RCVD_TSTMP) == TF_RCVD_TSTMP) 541 mss -= TCPOLEN_TSTAMP_APPA; 542 if ((tp->t_flags & (TF_REQ_CC|TF_NOOPT)) == TF_REQ_CC && 543 (tp->t_flags & TF_RCVD_CC) == TF_RCVD_CC) 544 mss -= TCPOLEN_CC_APPA; 545#if (MCLBYTES & (MCLBYTES - 1)) == 0 546 if (mss > MCLBYTES) 547 mss &= ~(MCLBYTES-1); 548#else 549 if (mss > MCLBYTES) 550 mss = mss / MCLBYTES * MCLBYTES; 551#endif 552 if (so->so_snd.sb_hiwat < mss) 553 mss = so->so_snd.sb_hiwat; 554 555 tp->t_maxseg = mss; 556 557 tcpstat.tcps_mturesent++; 558 tp->t_rtt = 0; 559 tp->snd_nxt = tp->snd_una; 560 tcp_output(tp); 561 } 562} 563#endif 564 565/* 566 * Look-up the routing entry to the peer of this inpcb. If no route 567 * is found and it cannot be allocated the return NULL. This routine 568 * is called by TCP routines that access the rmx structure and by tcp_mss 569 * to get the interface MTU. 570 */ 571struct rtentry * 572tcp_rtlookup(inp) 573 struct inpcb *inp; 574{ 575 struct route *ro; 576 struct rtentry *rt; 577 578 ro = &inp->inp_route; 579 rt = ro->ro_rt; 580 if (rt == NULL || !(rt->rt_flags & RTF_UP)) { 581 /* No route yet, so try to acquire one */ 582 if (inp->inp_faddr.s_addr != INADDR_ANY) { 583 ro->ro_dst.sa_family = AF_INET; 584 ro->ro_dst.sa_len = sizeof(ro->ro_dst); 585 ((struct sockaddr_in *) &ro->ro_dst)->sin_addr = 586 inp->inp_faddr; 587 rtalloc(ro); 588 rt = ro->ro_rt; 589 } 590 } 591 return rt; 592} 593 594/* 595 * Return a pointer to the cached information about the remote host. 596 * The cached information is stored in the protocol specific part of 597 * the route metrics. 598 */ 599struct rmxp_tao * 600tcp_gettaocache(inp) 601 struct inpcb *inp; 602{ 603 struct rtentry *rt = tcp_rtlookup(inp); 604 605 /* Make sure this is a host route and is up. */ 606 if (rt == NULL || 607 (rt->rt_flags & (RTF_UP|RTF_HOST)) != (RTF_UP|RTF_HOST)) 608 return NULL; 609 610 return rmx_taop(rt->rt_rmx); 611} 612 613/* 614 * Clear all the TAO cache entries, called from tcp_init. 615 * 616 * XXX 617 * This routine is just an empty one, because we assume that the routing 618 * routing tables are initialized at the same time when TCP, so there is 619 * nothing in the cache left over. 620 */ 621static void 622tcp_cleartaocache(void) 623{ } 624