tcp_timewait.c revision 34881
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
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 *    must display the following acknowledgement:
15 *	This product includes software developed by the University of
16 *	California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 *    may be used to endorse or promote products derived from this software
19 *    without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
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 *	$Id: tcp_subr.c,v 1.42 1998/01/27 09:15:10 davidg Exp $
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/kernel.h>
43#include <sys/sysctl.h>
44#include <sys/malloc.h>
45#include <sys/mbuf.h>
46#include <sys/socket.h>
47#include <sys/socketvar.h>
48#include <sys/protosw.h>
49#include <vm/vm_zone.h>
50
51#include <net/route.h>
52#include <net/if.h>
53
54#define _IP_VHL
55#include <netinet/in.h>
56#include <netinet/in_systm.h>
57#include <netinet/ip.h>
58#include <netinet/in_pcb.h>
59#include <netinet/in_var.h>
60#include <netinet/ip_var.h>
61#include <netinet/tcp.h>
62#include <netinet/tcp_fsm.h>
63#include <netinet/tcp_seq.h>
64#include <netinet/tcp_timer.h>
65#include <netinet/tcp_var.h>
66#include <netinet/tcpip.h>
67#ifdef TCPDEBUG
68#include <netinet/tcp_debug.h>
69#endif
70
71int 	tcp_mssdflt = TCP_MSS;
72SYSCTL_INT(_net_inet_tcp, TCPCTL_MSSDFLT, mssdflt,
73	CTLFLAG_RW, &tcp_mssdflt , 0, "");
74
75static int 	tcp_rttdflt = TCPTV_SRTTDFLT / PR_SLOWHZ;
76SYSCTL_INT(_net_inet_tcp, TCPCTL_RTTDFLT, rttdflt,
77	CTLFLAG_RW, &tcp_rttdflt , 0, "");
78
79static int	tcp_do_rfc1323 = 1;
80SYSCTL_INT(_net_inet_tcp, TCPCTL_DO_RFC1323, rfc1323,
81	CTLFLAG_RW, &tcp_do_rfc1323 , 0, "");
82
83static int	tcp_do_rfc1644 = 1;
84SYSCTL_INT(_net_inet_tcp, TCPCTL_DO_RFC1644, rfc1644,
85	CTLFLAG_RW, &tcp_do_rfc1644 , 0, "");
86
87static void	tcp_cleartaocache __P((void));
88static void	tcp_notify __P((struct inpcb *, int));
89
90/*
91 * Target size of TCP PCB hash tables. Must be a power of two.
92 */
93#ifndef TCBHASHSIZE
94#define TCBHASHSIZE	512
95#endif
96
97/*
98 * This is the actual shape of what we allocate using the zone
99 * allocator.  Doing it this way allows us to protect both structures
100 * using the same generation count, and also eliminates the overhead
101 * of allocating tcpcbs separately.  By hiding the structure here,
102 * we avoid changing most of the rest of the code (although it needs
103 * to be changed, eventually, for greater efficiency).
104 */
105#define ALIGNMENT	32
106#define	ALIGNM1		(ALIGNMENT-1)
107struct	inp_tp {
108	union {
109		struct	inpcb inp;
110		char	align[(sizeof(struct inpcb) + ALIGNM1) & ~ALIGNM1];
111	} inp_tp_u;
112	struct	tcpcb tcb;
113};
114#undef ALIGNMENT
115#undef ALIGNM1
116
117/*
118 * Tcp initialization
119 */
120void
121tcp_init()
122{
123
124	tcp_iss = random();	/* wrong, but better than a constant */
125	tcp_ccgen = 1;
126	tcp_cleartaocache();
127	LIST_INIT(&tcb);
128	tcbinfo.listhead = &tcb;
129	tcbinfo.hashbase = hashinit(TCBHASHSIZE, M_PCB, &tcbinfo.hashmask);
130	tcbinfo.porthashbase = hashinit(TCBHASHSIZE, M_PCB, &tcbinfo.porthashmask);
131	/* For the moment, we just worry about putting inpcbs here. */
132	/*
133	 * Rationale for a maximum of `nmbclusters':
134	 * 	1) It's a convenient value, sized by config, based on
135	 *	   parameters already known to be tweakable as needed
136	 *	   for network-intensive systems.
137	 *	2) Under the Old World Order, when pcbs were stored in
138	 *	   mbufs, it was of course impossible to have more
139	 *	   pcbs than mbufs.
140	 *	3) The zone allocator doesn't allocate physical memory
141	 *	   for this many pcbs; it just sizes the virtual
142	 *	   address space appropriately.  Thus, even for very large
143	 *	   values of nmbclusters, we don't actually take up much
144	 *	   memory unless required.
145	 */
146	tcbinfo.ipi_zone = zinit("tcpcb", sizeof(struct inp_tp), nmbclusters,
147				 ZONE_INTERRUPT, 0);
148	if (max_protohdr < sizeof(struct tcpiphdr))
149		max_protohdr = sizeof(struct tcpiphdr);
150	if (max_linkhdr + sizeof(struct tcpiphdr) > MHLEN)
151		panic("tcp_init");
152}
153
154/*
155 * Create template to be used to send tcp packets on a connection.
156 * Call after host entry created, allocates an mbuf and fills
157 * in a skeletal tcp/ip header, minimizing the amount of work
158 * necessary when the connection is used.
159 */
160struct tcpiphdr *
161tcp_template(tp)
162	struct tcpcb *tp;
163{
164	register struct inpcb *inp = tp->t_inpcb;
165	register struct mbuf *m;
166	register struct tcpiphdr *n;
167
168	if ((n = tp->t_template) == 0) {
169		m = m_get(M_DONTWAIT, MT_HEADER);
170		if (m == NULL)
171			return (0);
172		m->m_len = sizeof (struct tcpiphdr);
173		n = mtod(m, struct tcpiphdr *);
174	}
175	n->ti_next = n->ti_prev = 0;
176	n->ti_x1 = 0;
177	n->ti_pr = IPPROTO_TCP;
178	n->ti_len = htons(sizeof (struct tcpiphdr) - sizeof (struct ip));
179	n->ti_src = inp->inp_laddr;
180	n->ti_dst = inp->inp_faddr;
181	n->ti_sport = inp->inp_lport;
182	n->ti_dport = inp->inp_fport;
183	n->ti_seq = 0;
184	n->ti_ack = 0;
185	n->ti_x2 = 0;
186	n->ti_off = 5;
187	n->ti_flags = 0;
188	n->ti_win = 0;
189	n->ti_sum = 0;
190	n->ti_urp = 0;
191	return (n);
192}
193
194/*
195 * Send a single message to the TCP at address specified by
196 * the given TCP/IP header.  If m == 0, then we make a copy
197 * of the tcpiphdr at ti and send directly to the addressed host.
198 * This is used to force keep alive messages out using the TCP
199 * template for a connection tp->t_template.  If flags are given
200 * then we send a message back to the TCP which originated the
201 * segment ti, and discard the mbuf containing it and any other
202 * attached mbufs.
203 *
204 * In any case the ack and sequence number of the transmitted
205 * segment are as specified by the parameters.
206 *
207 * NOTE: If m != NULL, then ti must point to *inside* the mbuf.
208 */
209void
210tcp_respond(tp, ti, m, ack, seq, flags)
211	struct tcpcb *tp;
212	register struct tcpiphdr *ti;
213	register struct mbuf *m;
214	tcp_seq ack, seq;
215	int flags;
216{
217	register int tlen;
218	int win = 0;
219	struct route *ro = 0;
220	struct route sro;
221
222	if (tp) {
223		win = sbspace(&tp->t_inpcb->inp_socket->so_rcv);
224		ro = &tp->t_inpcb->inp_route;
225	} else {
226		ro = &sro;
227		bzero(ro, sizeof *ro);
228	}
229	if (m == 0) {
230		m = m_gethdr(M_DONTWAIT, MT_HEADER);
231		if (m == NULL)
232			return;
233#ifdef TCP_COMPAT_42
234		tlen = 1;
235#else
236		tlen = 0;
237#endif
238		m->m_data += max_linkhdr;
239		*mtod(m, struct tcpiphdr *) = *ti;
240		ti = mtod(m, struct tcpiphdr *);
241		flags = TH_ACK;
242	} else {
243		m_freem(m->m_next);
244		m->m_next = 0;
245		m->m_data = (caddr_t)ti;
246		m->m_len = sizeof (struct tcpiphdr);
247		tlen = 0;
248#define xchg(a,b,type) { type t; t=a; a=b; b=t; }
249		xchg(ti->ti_dst.s_addr, ti->ti_src.s_addr, u_long);
250		xchg(ti->ti_dport, ti->ti_sport, u_short);
251#undef xchg
252	}
253	ti->ti_len = htons((u_short)(sizeof (struct tcphdr) + tlen));
254	tlen += sizeof (struct tcpiphdr);
255	m->m_len = tlen;
256	m->m_pkthdr.len = tlen;
257	m->m_pkthdr.rcvif = (struct ifnet *) 0;
258	ti->ti_next = ti->ti_prev = 0;
259	ti->ti_x1 = 0;
260	ti->ti_seq = htonl(seq);
261	ti->ti_ack = htonl(ack);
262	ti->ti_x2 = 0;
263	ti->ti_off = sizeof (struct tcphdr) >> 2;
264	ti->ti_flags = flags;
265	if (tp)
266		ti->ti_win = htons((u_short) (win >> tp->rcv_scale));
267	else
268		ti->ti_win = htons((u_short)win);
269	ti->ti_urp = 0;
270	ti->ti_sum = 0;
271	ti->ti_sum = in_cksum(m, tlen);
272	((struct ip *)ti)->ip_len = tlen;
273	((struct ip *)ti)->ip_ttl = ip_defttl;
274#ifdef TCPDEBUG
275	if (tp == NULL || (tp->t_inpcb->inp_socket->so_options & SO_DEBUG))
276		tcp_trace(TA_OUTPUT, 0, tp, ti, 0);
277#endif
278	(void) ip_output(m, NULL, ro, 0, NULL);
279	if (ro == &sro && ro->ro_rt) {
280		RTFREE(ro->ro_rt);
281	}
282}
283
284/*
285 * Create a new TCP control block, making an
286 * empty reassembly queue and hooking it to the argument
287 * protocol control block.  The `inp' parameter must have
288 * come from the zone allocator set up in tcp_init().
289 */
290struct tcpcb *
291tcp_newtcpcb(inp)
292	struct inpcb *inp;
293{
294	struct	inp_tp *it;
295	register struct tcpcb *tp;
296
297	it = (struct inp_tp *)inp;
298	tp = &it->tcb;
299	bzero((char *) tp, sizeof(struct tcpcb));
300	tp->seg_next = tp->seg_prev = (struct tcpiphdr *)tp;
301	tp->t_maxseg = tp->t_maxopd = tcp_mssdflt;
302
303	if (tcp_do_rfc1323)
304		tp->t_flags = (TF_REQ_SCALE|TF_REQ_TSTMP);
305	if (tcp_do_rfc1644)
306		tp->t_flags |= TF_REQ_CC;
307	tp->t_inpcb = inp;	/* XXX */
308	/*
309	 * Init srtt to TCPTV_SRTTBASE (0), so we can tell that we have no
310	 * rtt estimate.  Set rttvar so that srtt + 4 * rttvar gives
311	 * reasonable initial retransmit time.
312	 */
313	tp->t_srtt = TCPTV_SRTTBASE;
314	tp->t_rttvar = ((TCPTV_RTOBASE - TCPTV_SRTTBASE) << TCP_RTTVAR_SHIFT) / 4;
315	tp->t_rttmin = TCPTV_MIN;
316	tp->t_rxtcur = TCPTV_RTOBASE;
317	tp->snd_cwnd = TCP_MAXWIN << TCP_MAX_WINSHIFT;
318	tp->snd_ssthresh = TCP_MAXWIN << TCP_MAX_WINSHIFT;
319	inp->inp_ip_ttl = ip_defttl;
320	inp->inp_ppcb = (caddr_t)tp;
321	return (tp);		/* XXX */
322}
323
324/*
325 * Drop a TCP connection, reporting
326 * the specified error.  If connection is synchronized,
327 * then send a RST to peer.
328 */
329struct tcpcb *
330tcp_drop(tp, errno)
331	register struct tcpcb *tp;
332	int errno;
333{
334	struct socket *so = tp->t_inpcb->inp_socket;
335
336	if (TCPS_HAVERCVDSYN(tp->t_state)) {
337		tp->t_state = TCPS_CLOSED;
338		(void) tcp_output(tp);
339		tcpstat.tcps_drops++;
340	} else
341		tcpstat.tcps_conndrops++;
342	if (errno == ETIMEDOUT && tp->t_softerror)
343		errno = tp->t_softerror;
344	so->so_error = errno;
345	return (tcp_close(tp));
346}
347
348/*
349 * Close a TCP control block:
350 *	discard all space held by the tcp
351 *	discard internet protocol block
352 *	wake up any sleepers
353 */
354struct tcpcb *
355tcp_close(tp)
356	register struct tcpcb *tp;
357{
358	register struct tcpiphdr *t;
359	struct inpcb *inp = tp->t_inpcb;
360	struct socket *so = inp->inp_socket;
361	register struct mbuf *m;
362	register struct rtentry *rt;
363	int dosavessthresh;
364
365	/*
366	 * If we got enough samples through the srtt filter,
367	 * save the rtt and rttvar in the routing entry.
368	 * 'Enough' is arbitrarily defined as the 16 samples.
369	 * 16 samples is enough for the srtt filter to converge
370	 * to within 5% of the correct value; fewer samples and
371	 * we could save a very bogus rtt.
372	 *
373	 * Don't update the default route's characteristics and don't
374	 * update anything that the user "locked".
375	 */
376	if (tp->t_rttupdated >= 16 &&
377	    (rt = inp->inp_route.ro_rt) &&
378	    ((struct sockaddr_in *)rt_key(rt))->sin_addr.s_addr != INADDR_ANY) {
379		register u_long i = 0;
380
381		if ((rt->rt_rmx.rmx_locks & RTV_RTT) == 0) {
382			i = tp->t_srtt *
383			    (RTM_RTTUNIT / (PR_SLOWHZ * TCP_RTT_SCALE));
384			if (rt->rt_rmx.rmx_rtt && i)
385				/*
386				 * filter this update to half the old & half
387				 * the new values, converting scale.
388				 * See route.h and tcp_var.h for a
389				 * description of the scaling constants.
390				 */
391				rt->rt_rmx.rmx_rtt =
392				    (rt->rt_rmx.rmx_rtt + i) / 2;
393			else
394				rt->rt_rmx.rmx_rtt = i;
395			tcpstat.tcps_cachedrtt++;
396		}
397		if ((rt->rt_rmx.rmx_locks & RTV_RTTVAR) == 0) {
398			i = tp->t_rttvar *
399			    (RTM_RTTUNIT / (PR_SLOWHZ * TCP_RTTVAR_SCALE));
400			if (rt->rt_rmx.rmx_rttvar && i)
401				rt->rt_rmx.rmx_rttvar =
402				    (rt->rt_rmx.rmx_rttvar + i) / 2;
403			else
404				rt->rt_rmx.rmx_rttvar = i;
405			tcpstat.tcps_cachedrttvar++;
406		}
407		/*
408		 * The old comment here said:
409		 * update the pipelimit (ssthresh) if it has been updated
410		 * already or if a pipesize was specified & the threshhold
411		 * got below half the pipesize.  I.e., wait for bad news
412		 * before we start updating, then update on both good
413		 * and bad news.
414		 *
415		 * But we want to save the ssthresh even if no pipesize is
416		 * specified explicitly in the route, because such
417		 * connections still have an implicit pipesize specified
418		 * by the global tcp_sendspace.  In the absence of a reliable
419		 * way to calculate the pipesize, it will have to do.
420		 */
421		i = tp->snd_ssthresh;
422#if 1
423		if (rt->rt_rmx.rmx_sendpipe != 0)
424			dosavessthresh = (i < rt->rt_rmx.rmx_sendpipe / 2);
425		else
426			dosavessthresh = (i < so->so_snd.sb_hiwat / 2);
427#else
428		dosavessthresh = (i < rt->rt_rmx.rmx_sendpipe / 2);
429#endif
430		if (((rt->rt_rmx.rmx_locks & RTV_SSTHRESH) == 0 &&
431		     i != 0 && rt->rt_rmx.rmx_ssthresh != 0)
432		    || dosavessthresh) {
433			/*
434			 * convert the limit from user data bytes to
435			 * packets then to packet data bytes.
436			 */
437			i = (i + tp->t_maxseg / 2) / tp->t_maxseg;
438			if (i < 2)
439				i = 2;
440			i *= (u_long)(tp->t_maxseg + sizeof (struct tcpiphdr));
441			if (rt->rt_rmx.rmx_ssthresh)
442				rt->rt_rmx.rmx_ssthresh =
443				    (rt->rt_rmx.rmx_ssthresh + i) / 2;
444			else
445				rt->rt_rmx.rmx_ssthresh = i;
446			tcpstat.tcps_cachedssthresh++;
447		}
448	}
449	/* free the reassembly queue, if any */
450	t = tp->seg_next;
451	while (t != (struct tcpiphdr *)tp) {
452		t = (struct tcpiphdr *)t->ti_next;
453		m = REASS_MBUF((struct tcpiphdr *)t->ti_prev);
454		remque(t->ti_prev);
455		m_freem(m);
456	}
457	if (tp->t_template)
458		(void) m_free(dtom(tp->t_template));
459	inp->inp_ppcb = NULL;
460	soisdisconnected(so);
461	in_pcbdetach(inp);
462	tcpstat.tcps_closed++;
463	return ((struct tcpcb *)0);
464}
465
466void
467tcp_drain()
468{
469
470}
471
472/*
473 * Notify a tcp user of an asynchronous error;
474 * store error as soft error, but wake up user
475 * (for now, won't do anything until can select for soft error).
476 */
477static void
478tcp_notify(inp, error)
479	struct inpcb *inp;
480	int error;
481{
482	register struct tcpcb *tp = (struct tcpcb *)inp->inp_ppcb;
483	register struct socket *so = inp->inp_socket;
484
485	/*
486	 * Ignore some errors if we are hooked up.
487	 * If connection hasn't completed, has retransmitted several times,
488	 * and receives a second error, give up now.  This is better
489	 * than waiting a long time to establish a connection that
490	 * can never complete.
491	 */
492	if (tp->t_state == TCPS_ESTABLISHED &&
493	     (error == EHOSTUNREACH || error == ENETUNREACH ||
494	      error == EHOSTDOWN)) {
495		return;
496	} else if (tp->t_state < TCPS_ESTABLISHED && tp->t_rxtshift > 3 &&
497	    tp->t_softerror)
498		so->so_error = error;
499	else
500		tp->t_softerror = error;
501	wakeup((caddr_t) &so->so_timeo);
502	sorwakeup(so);
503	sowwakeup(so);
504}
505
506void
507tcp_ctlinput(cmd, sa, vip)
508	int cmd;
509	struct sockaddr *sa;
510	void *vip;
511{
512	register struct ip *ip = vip;
513	register struct tcphdr *th;
514	void (*notify) __P((struct inpcb *, int)) = tcp_notify;
515
516	if (cmd == PRC_QUENCH)
517		notify = tcp_quench;
518#if 1
519	else if (cmd == PRC_MSGSIZE)
520		notify = tcp_mtudisc;
521#endif
522	else if (!PRC_IS_REDIRECT(cmd) &&
523		 ((unsigned)cmd > PRC_NCMDS || inetctlerrmap[cmd] == 0))
524		return;
525	if (ip) {
526		th = (struct tcphdr *)((caddr_t)ip
527				       + (IP_VHL_HL(ip->ip_vhl) << 2));
528		in_pcbnotify(&tcb, sa, th->th_dport, ip->ip_src, th->th_sport,
529			cmd, notify);
530	} else
531		in_pcbnotify(&tcb, sa, 0, zeroin_addr, 0, cmd, notify);
532}
533
534/*
535 * When a source quench is received, close congestion window
536 * to one segment.  We will gradually open it again as we proceed.
537 */
538void
539tcp_quench(inp, errno)
540	struct inpcb *inp;
541	int errno;
542{
543	struct tcpcb *tp = intotcpcb(inp);
544
545	if (tp)
546		tp->snd_cwnd = tp->t_maxseg;
547}
548
549#if 1
550/*
551 * When `need fragmentation' ICMP is received, update our idea of the MSS
552 * based on the new value in the route.  Also nudge TCP to send something,
553 * since we know the packet we just sent was dropped.
554 * This duplicates some code in the tcp_mss() function in tcp_input.c.
555 */
556void
557tcp_mtudisc(inp, errno)
558	struct inpcb *inp;
559	int errno;
560{
561	struct tcpcb *tp = intotcpcb(inp);
562	struct rtentry *rt;
563	struct rmxp_tao *taop;
564	struct socket *so = inp->inp_socket;
565	int offered;
566	int mss;
567
568	if (tp) {
569		rt = tcp_rtlookup(inp);
570		if (!rt || !rt->rt_rmx.rmx_mtu) {
571			tp->t_maxopd = tp->t_maxseg = tcp_mssdflt;
572			return;
573		}
574		taop = rmx_taop(rt->rt_rmx);
575		offered = taop->tao_mssopt;
576		mss = rt->rt_rmx.rmx_mtu - sizeof(struct tcpiphdr);
577		if (offered)
578			mss = min(mss, offered);
579		/*
580		 * XXX - The above conditional probably violates the TCP
581		 * spec.  The problem is that, since we don't know the
582		 * other end's MSS, we are supposed to use a conservative
583		 * default.  But, if we do that, then MTU discovery will
584		 * never actually take place, because the conservative
585		 * default is much less than the MTUs typically seen
586		 * on the Internet today.  For the moment, we'll sweep
587		 * this under the carpet.
588		 *
589		 * The conservative default might not actually be a problem
590		 * if the only case this occurs is when sending an initial
591		 * SYN with options and data to a host we've never talked
592		 * to before.  Then, they will reply with an MSS value which
593		 * will get recorded and the new parameters should get
594		 * recomputed.  For Further Study.
595		 */
596		if (tp->t_maxopd <= mss)
597			return;
598		tp->t_maxopd = mss;
599
600		if ((tp->t_flags & (TF_REQ_TSTMP|TF_NOOPT)) == TF_REQ_TSTMP &&
601		    (tp->t_flags & TF_RCVD_TSTMP) == TF_RCVD_TSTMP)
602			mss -= TCPOLEN_TSTAMP_APPA;
603		if ((tp->t_flags & (TF_REQ_CC|TF_NOOPT)) == TF_REQ_CC &&
604		    (tp->t_flags & TF_RCVD_CC) == TF_RCVD_CC)
605			mss -= TCPOLEN_CC_APPA;
606#if	(MCLBYTES & (MCLBYTES - 1)) == 0
607		if (mss > MCLBYTES)
608			mss &= ~(MCLBYTES-1);
609#else
610		if (mss > MCLBYTES)
611			mss = mss / MCLBYTES * MCLBYTES;
612#endif
613		if (so->so_snd.sb_hiwat < mss)
614			mss = so->so_snd.sb_hiwat;
615
616		tp->t_maxseg = mss;
617
618		tcpstat.tcps_mturesent++;
619		tp->t_rtt = 0;
620		tp->snd_nxt = tp->snd_una;
621		tcp_output(tp);
622	}
623}
624#endif
625
626/*
627 * Look-up the routing entry to the peer of this inpcb.  If no route
628 * is found and it cannot be allocated the return NULL.  This routine
629 * is called by TCP routines that access the rmx structure and by tcp_mss
630 * to get the interface MTU.
631 */
632struct rtentry *
633tcp_rtlookup(inp)
634	struct inpcb *inp;
635{
636	struct route *ro;
637	struct rtentry *rt;
638
639	ro = &inp->inp_route;
640	rt = ro->ro_rt;
641	if (rt == NULL || !(rt->rt_flags & RTF_UP)) {
642		/* No route yet, so try to acquire one */
643		if (inp->inp_faddr.s_addr != INADDR_ANY) {
644			ro->ro_dst.sa_family = AF_INET;
645			ro->ro_dst.sa_len = sizeof(ro->ro_dst);
646			((struct sockaddr_in *) &ro->ro_dst)->sin_addr =
647				inp->inp_faddr;
648			rtalloc(ro);
649			rt = ro->ro_rt;
650		}
651	}
652	return rt;
653}
654
655/*
656 * Return a pointer to the cached information about the remote host.
657 * The cached information is stored in the protocol specific part of
658 * the route metrics.
659 */
660struct rmxp_tao *
661tcp_gettaocache(inp)
662	struct inpcb *inp;
663{
664	struct rtentry *rt = tcp_rtlookup(inp);
665
666	/* Make sure this is a host route and is up. */
667	if (rt == NULL ||
668	    (rt->rt_flags & (RTF_UP|RTF_HOST)) != (RTF_UP|RTF_HOST))
669		return NULL;
670
671	return rmx_taop(rt->rt_rmx);
672}
673
674/*
675 * Clear all the TAO cache entries, called from tcp_init.
676 *
677 * XXX
678 * This routine is just an empty one, because we assume that the routing
679 * routing tables are initialized at the same time when TCP, so there is
680 * nothing in the cache left over.
681 */
682static void
683tcp_cleartaocache()
684{
685}
686