f796f8a8e68cc3fb8079b9df7953466a9887beae
2 * Copyright (c) 1982, 1986, 1988, 1990, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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
33 * From: @(#)tcp_input.c 8.5 (Berkeley) 4/10/94
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/malloc.h>
41 #include <sys/protosw.h>
42 #include <sys/socket.h>
43 #include <sys/socketvar.h>
44 #include <sys/errno.h>
45 #include <sys/queue.h>
46 #include <sys/kernel.h>
49 #include <net/route.h>
51 #include <netinet/in.h>
52 #include <netinet/in_systm.h>
53 #include <netinet/ip.h>
54 #include <netinet/in_pcb.h>
55 #include <netinet/ip_var.h>
56 #include <netinet/tcp.h>
57 #include <netinet/tcp_fsm.h>
58 #include <netinet/tcp_seq.h>
59 #include <netinet/tcp_timer.h>
60 #include <netinet/tcp_var.h>
61 #include <netinet/tcpip.h>
63 #include <netinet/tcp_debug.h>
64 struct tcpiphdr tcp_saveti
;
67 int tcprexmtthresh
= 3;
70 struct tcpstat tcpstat
;
73 struct inpcbinfo tcbinfo
;
75 #endif /* TUBA_INCLUDE */
78 * Insert segment ti into reassembly queue of tcp with
79 * control block tp. Return TH_FIN if reassembly now includes
80 * a segment with FIN. The macro form does the common case inline
81 * (segment is the next to be received on an established connection,
82 * and the queue is empty), avoiding linkage into and removal
83 * from the queue and repetition of various conversions.
84 * Set DELACK for segments received in order, but ack immediately
85 * when segments are out of order (so fast retransmit can work).
88 #define TCP_REASS(tp, ti, m, so, flags) { \
89 if ((ti)->ti_seq == (tp)->rcv_nxt && \
90 (tp)->seg_next == (struct tcpiphdr *)(tp) && \
91 (tp)->t_state == TCPS_ESTABLISHED) { \
92 if (ti->ti_flags & TH_PUSH) \
93 tp->t_flags |= TF_ACKNOW; \
95 tp->t_flags |= TF_DELACK; \
96 (tp)->rcv_nxt += (ti)->ti_len; \
97 flags = (ti)->ti_flags & TH_FIN; \
98 tcpstat.tcps_rcvpack++;\
99 tcpstat.tcps_rcvbyte += (ti)->ti_len;\
100 sbappend(&(so)->so_rcv, (m)); \
103 (flags) = tcp_reass((tp), (ti), (m)); \
104 tp->t_flags |= TF_ACKNOW; \
108 #define TCP_REASS(tp, ti, m, so, flags) { \
109 if ((ti)->ti_seq == (tp)->rcv_nxt && \
110 (tp)->seg_next == (struct tcpiphdr *)(tp) && \
111 (tp)->t_state == TCPS_ESTABLISHED) { \
112 tp->t_flags |= TF_DELACK; \
113 (tp)->rcv_nxt += (ti)->ti_len; \
114 flags = (ti)->ti_flags & TH_FIN; \
115 tcpstat.tcps_rcvpack++;\
116 tcpstat.tcps_rcvbyte += (ti)->ti_len;\
117 sbappend(&(so)->so_rcv, (m)); \
120 (flags) = tcp_reass((tp), (ti), (m)); \
121 tp->t_flags |= TF_ACKNOW; \
129 register struct tcpcb
*tp
;
130 register struct tcpiphdr
*ti
;
133 register struct tcpiphdr
*q
;
134 struct socket
*so
= tp
->t_inpcb
->inp_socket
;
138 * Call with ti==0 after become established to
139 * force pre-ESTABLISHED data up to user socket.
145 * Find a segment which begins after this one does.
147 for (q
= tp
->seg_next
; q
!= (struct tcpiphdr
*)tp
;
148 q
= (struct tcpiphdr
*)q
->ti_next
)
149 if (SEQ_GT(q
->ti_seq
, ti
->ti_seq
))
153 * If there is a preceding segment, it may provide some of
154 * our data already. If so, drop the data from the incoming
155 * segment. If it provides all of our data, drop us.
157 if ((struct tcpiphdr
*)q
->ti_prev
!= (struct tcpiphdr
*)tp
) {
159 q
= (struct tcpiphdr
*)q
->ti_prev
;
160 /* conversion to int (in i) handles seq wraparound */
161 i
= q
->ti_seq
+ q
->ti_len
- ti
->ti_seq
;
163 if (i
>= ti
->ti_len
) {
164 tcpstat
.tcps_rcvduppack
++;
165 tcpstat
.tcps_rcvdupbyte
+= ti
->ti_len
;
168 * Try to present any queued data
169 * at the left window edge to the user.
170 * This is needed after the 3-WHS
173 goto present
; /* ??? */
179 q
= (struct tcpiphdr
*)(q
->ti_next
);
181 tcpstat
.tcps_rcvoopack
++;
182 tcpstat
.tcps_rcvoobyte
+= ti
->ti_len
;
183 REASS_MBUF(ti
) = m
; /* XXX */
186 * While we overlap succeeding segments trim them or,
187 * if they are completely covered, dequeue them.
189 while (q
!= (struct tcpiphdr
*)tp
) {
190 register int i
= (ti
->ti_seq
+ ti
->ti_len
) - q
->ti_seq
;
196 m_adj(REASS_MBUF(q
), i
);
199 q
= (struct tcpiphdr
*)q
->ti_next
;
200 m
= REASS_MBUF((struct tcpiphdr
*)q
->ti_prev
);
206 * Stick new segment in its place.
208 insque(ti
, q
->ti_prev
);
212 * Present data to user, advancing rcv_nxt through
213 * completed sequence space.
215 if (!TCPS_HAVEESTABLISHED(tp
->t_state
))
218 if (ti
== (struct tcpiphdr
*)tp
|| ti
->ti_seq
!= tp
->rcv_nxt
)
221 tp
->rcv_nxt
+= ti
->ti_len
;
222 OS_DbgPrint(OSK_MID_TRACE
,("Added %d to rcv_nxt (result %d)\n",
223 ti
->ti_len
, tp
->rcv_nxt
));
224 flags
= ti
->ti_flags
& TH_FIN
;
227 ti
= (struct tcpiphdr
*)ti
->ti_next
;
228 if (so
->so_state
& SS_CANTRCVMORE
)
231 sbappend(&so
->so_rcv
, m
);
232 } while (ti
!= (struct tcpiphdr
*)tp
&& ti
->ti_seq
== tp
->rcv_nxt
);
238 * TCP input routine, follows pages 65-76 of the
239 * protocol specification dated September, 1981 very closely.
243 register struct mbuf
*m
;
246 register struct tcpiphdr
*ti
;
247 register struct inpcb
*inp
;
251 register struct tcpcb
*tp
= 0;
252 register int tiflags
;
253 struct socket
*so
= 0;
254 int todrop
, acked
, ourfinisacked
, needoutput
= 0;
255 struct in_addr laddr
;
259 struct tcpopt to
; /* options in this segment */
260 struct rmxp_tao
*taop
; /* pointer to our TAO cache entry */
261 struct rmxp_tao tao_noncached
; /* in case there's no cached entry */
265 bzero((char *)&to
, sizeof(to
));
267 tcpstat
.tcps_rcvtotal
++;
269 * Get IP and TCP header together in first mbuf.
270 * Note: IP leaves IP header in first mbuf.
272 ti
= mtod(m
, struct tcpiphdr
*);
273 if (iphlen
> sizeof (struct ip
))
274 ip_stripoptions(m
, (struct mbuf
*)0);
275 if (m
->m_len
< sizeof (struct tcpiphdr
)) {
276 if ((m
= m_pullup(m
, sizeof (struct tcpiphdr
))) == 0) {
277 tcpstat
.tcps_rcvshort
++;
280 ti
= mtod(m
, struct tcpiphdr
*);
284 * Checksum extended TCP header and data.
286 tlen
= ((struct ip
*)ti
)->ip_len
;
287 len
= sizeof (struct ip
) + tlen
;
288 ti
->ti_next
= ti
->ti_prev
= 0;
290 ti
->ti_len
= (u_short
)tlen
;
292 #ifndef __REACTOS__ /* Checksum already done in IPReceive */
293 ti
->ti_sum
= in_cksum(m
, len
);
295 printf("TCP: Bad Checksum\n");
296 tcpstat
.tcps_rcvbadsum
++;
300 #endif /* TUBA_INCLUDE */
303 * Check that TCP offset makes sense,
304 * pull out TCP options and adjust length. XXX
306 off
= ti
->ti_off
<< 2;
307 if (off
< sizeof (struct tcphdr
) || off
> tlen
) {
308 tcpstat
.tcps_rcvbadoff
++;
313 if (off
> sizeof (struct tcphdr
)) {
314 if (m
->m_len
< sizeof(struct ip
) + off
) {
315 if ((m
= m_pullup(m
, sizeof (struct ip
) + off
)) == 0) {
316 tcpstat
.tcps_rcvshort
++;
319 ti
= mtod(m
, struct tcpiphdr
*);
321 optlen
= off
- sizeof (struct tcphdr
);
322 optp
= mtod(m
, caddr_t
) + sizeof (struct tcpiphdr
);
324 tiflags
= ti
->ti_flags
;
327 * Convert TCP protocol specific fields to host format.
335 * Drop TCP, IP headers and TCP options.
337 m
->m_data
+= sizeof(struct tcpiphdr
)+off
-sizeof(struct tcphdr
);
338 m
->m_len
-= sizeof(struct tcpiphdr
)+off
-sizeof(struct tcphdr
);
341 * Locate pcb for segment.
345 * First look for an exact match.
347 inp
= in_pcblookuphash(&tcbinfo
, ti
->ti_src
, ti
->ti_sport
,
348 ti
->ti_dst
, ti
->ti_dport
);
350 * ...and if that fails, do a wildcard search.
353 inp
= in_pcblookup(&tcb
, ti
->ti_src
, ti
->ti_sport
,
354 ti
->ti_dst
, ti
->ti_dport
, INPLOOKUP_WILDCARD
);
358 * If the state is CLOSED (i.e., TCB does not exist) then
359 * all data in the incoming segment is discarded.
360 * If the TCB exists but is in CLOSED state, it is embryonic,
361 * but should either do a listen or a connect soon.
368 if (tp
->t_state
== TCPS_CLOSED
)
371 /* Unscale the window into a 32-bit value. */
372 if ((tiflags
& TH_SYN
) == 0)
373 tiwin
= ti
->ti_win
<< tp
->snd_scale
;
377 so
= inp
->inp_socket
;
378 if (so
->so_options
& (SO_DEBUG
|SO_ACCEPTCONN
)) {
380 if (so
->so_options
& SO_DEBUG
) {
381 ostate
= tp
->t_state
;
385 if (so
->so_options
& SO_ACCEPTCONN
) {
386 register struct tcpcb
*tp0
= tp
;
388 if ((tiflags
& (TH_RST
|TH_ACK
|TH_SYN
)) != TH_SYN
) {
390 * Note: dropwithreset makes sure we don't
391 * send a RST in response to a RST.
393 if (tiflags
& TH_ACK
) {
394 tcpstat
.tcps_badsyn
++;
399 so2
= sonewconn(so
, 0);
401 unsigned int i
, j
, qlen
;
404 static long old_mono_secs
;
405 static unsigned int cur_cnt
, old_cnt
;
407 tcpstat
.tcps_listendrop
++;
410 * Keep a decaying average of the number
411 * of overruns we've been getting.
413 if ((i
= (mono_time
.tv_sec
-
414 old_mono_secs
)) != 0) {
415 old_mono_secs
= mono_time
.tv_sec
;
416 old_cnt
= cur_cnt
/ i
;
425 * If we've been getting a lot of hits,
426 * random drop an incomplete connection
427 * from the queue, otherwise, fall through
428 * so we head-drop from the queue.
431 if (++cur_cnt
> qlen
|| old_cnt
> qlen
) {
432 rnd
= (314159 * rnd
+ 66329) & 0xffff;
433 j
= ((qlen
+ 1) * rnd
) >> 16;
439 tcp_drop(sototcpcb(so2
), ETIMEDOUT
);
440 so2
= sonewconn(so
, 0);
447 * This is ugly, but ....
449 * Mark socket as temporary until we're
450 * committed to keeping it. The code at
451 * ``drop'' and ``dropwithreset'' check the
452 * flag dropsocket to see if the temporary
453 * socket created here should be discarded.
454 * We mark the socket as discardable until
455 * we're committed to it below in TCPS_LISTEN.
458 inp
= (struct inpcb
*)so
->so_pcb
;
459 inp
->inp_laddr
= ti
->ti_dst
;
460 inp
->inp_lport
= ti
->ti_dport
;
463 inp
->inp_options
= ip_srcroute();
466 tp
->t_state
= TCPS_LISTEN
;
467 tp
->t_flags
|= tp0
->t_flags
& (TF_NOPUSH
|TF_NOOPT
);
469 /* Compute proper scaling value from buffer space */
470 while (tp
->request_r_scale
< TCP_MAX_WINSHIFT
&&
471 TCP_MAXWIN
<< tp
->request_r_scale
< so
->so_rcv
.sb_hiwat
)
472 tp
->request_r_scale
++;
477 * Segment received on connection.
478 * Reset idle time and keep-alive timer.
481 if (TCPS_HAVEESTABLISHED(tp
->t_state
))
482 tp
->t_timer
[TCPT_KEEP
] = tcp_keepidle
;
485 * Process options if not in LISTEN state,
486 * else do it below (after getting remote address).
488 if (tp
->t_state
!= TCPS_LISTEN
)
489 tcp_dooptions(tp
, optp
, optlen
, ti
, &to
);
492 * Header prediction: check for the two common cases
493 * of a uni-directional data xfer. If the packet has
494 * no control flags, is in-sequence, the window didn't
495 * change and we're not retransmitting, it's a
496 * candidate. If the length is zero and the ack moved
497 * forward, we're the sender side of the xfer. Just
498 * free the data acked & wake any higher level process
499 * that was blocked waiting for space. If the length
500 * is non-zero and the ack didn't move, we're the
501 * receiver side. If we're getting packets in-order
502 * (the reassembly queue is empty), add the data to
503 * the socket buffer and note that we need a delayed ack.
504 * Make sure that the hidden state-flags are also off.
505 * Since we check for TCPS_ESTABLISHED above, it can only
508 if (tp
->t_state
== TCPS_ESTABLISHED
&&
509 (tiflags
& (TH_SYN
|TH_FIN
|TH_RST
|TH_URG
|TH_ACK
)) == TH_ACK
&&
510 ((tp
->t_flags
& (TF_NEEDSYN
|TF_NEEDFIN
)) == 0) &&
511 ((to
.to_flag
& TOF_TS
) == 0 ||
512 TSTMP_GEQ(to
.to_tsval
, tp
->ts_recent
)) &&
514 * Using the CC option is compulsory if once started:
515 * the segment is OK if no T/TCP was negotiated or
516 * if the segment has a CC option equal to CCrecv
518 ((tp
->t_flags
& (TF_REQ_CC
|TF_RCVD_CC
)) != (TF_REQ_CC
|TF_RCVD_CC
) ||
519 ((to
.to_flag
& TOF_CC
) != 0 && to
.to_cc
== tp
->cc_recv
)) &&
520 ti
->ti_seq
== tp
->rcv_nxt
&&
521 tiwin
&& tiwin
== tp
->snd_wnd
&&
522 tp
->snd_nxt
== tp
->snd_max
) {
525 * If last ACK falls within this segment's sequence numbers,
526 * record the timestamp.
527 * NOTE that the test is modified according to the latest
528 * proposal of the tcplw@cray.com list (Braden 1993/04/26).
530 if ((to
.to_flag
& TOF_TS
) != 0 &&
531 SEQ_LEQ(ti
->ti_seq
, tp
->last_ack_sent
)) {
532 tp
->ts_recent_age
= tcp_now
;
533 tp
->ts_recent
= to
.to_tsval
;
536 if (ti
->ti_len
== 0) {
537 if (SEQ_GT(ti
->ti_ack
, tp
->snd_una
) &&
538 SEQ_LEQ(ti
->ti_ack
, tp
->snd_max
) &&
539 tp
->snd_cwnd
>= tp
->snd_wnd
) {
541 * this is a pure ack for outstanding data.
543 ++tcpstat
.tcps_predack
;
544 if ((to
.to_flag
& TOF_TS
) != 0)
546 tcp_now
- to
.to_tsecr
+ 1);
547 else if (tp
->t_rtt
&&
548 SEQ_GT(ti
->ti_ack
, tp
->t_rtseq
))
549 tcp_xmit_timer(tp
, tp
->t_rtt
);
550 acked
= ti
->ti_ack
- tp
->snd_una
;
551 tcpstat
.tcps_rcvackpack
++;
552 tcpstat
.tcps_rcvackbyte
+= acked
;
553 sbdrop(&so
->so_snd
, acked
);
554 tp
->snd_una
= ti
->ti_ack
;
558 * If all outstanding data are acked, stop
559 * retransmit timer, otherwise restart timer
560 * using current (possibly backed-off) value.
561 * If process is waiting for space,
562 * wakeup/selwakeup/signal. If data
563 * are ready to send, let tcp_output
564 * decide between more output or persist.
566 if (tp
->snd_una
== tp
->snd_max
)
567 tp
->t_timer
[TCPT_REXMT
] = 0;
568 else if (tp
->t_timer
[TCPT_PERSIST
] == 0)
569 tp
->t_timer
[TCPT_REXMT
] = tp
->t_rxtcur
;
571 if (so
->so_snd
.sb_flags
& SB_NOTIFY
)
573 if (so
->so_snd
.sb_cc
)
574 (void) tcp_output(tp
);
577 } else if (ti
->ti_ack
== tp
->snd_una
&&
578 tp
->seg_next
== (struct tcpiphdr
*)tp
&&
579 ti
->ti_len
<= sbspace(&so
->so_rcv
)) {
581 * this is a pure, in-sequence data packet
582 * with nothing on the reassembly queue and
583 * we have enough buffer space to take it.
585 ++tcpstat
.tcps_preddat
;
586 tp
->rcv_nxt
+= ti
->ti_len
;
587 OS_DbgPrint(OSK_MID_TRACE
,("Added %d to rcv_nxt\n", ti
->ti_len
- sizeof(struct ip
)));
588 tcpstat
.tcps_rcvpack
++;
589 tcpstat
.tcps_rcvbyte
+= ti
->ti_len
;
591 * Add data to socket buffer.
593 sbappend(&so
->so_rcv
, m
);
597 * If this is a short packet, then ACK now - with Nagel
598 * congestion avoidance sender won't send more until
601 if (tiflags
& TH_PUSH
) {
602 tp
->t_flags
|= TF_ACKNOW
;
605 tp
->t_flags
|= TF_DELACK
;
608 tp
->t_flags
|= TF_DELACK
;
615 * Calculate amount of space in receive window,
616 * and then do TCP input processing.
617 * Receive window is amount of space in rcv queue,
618 * but not less than advertised window.
622 win
= sbspace(&so
->so_rcv
);
625 tp
->rcv_wnd
= max(win
, (int)(tp
->rcv_adv
- tp
->rcv_nxt
));
628 switch (tp
->t_state
) {
631 * If the state is LISTEN then ignore segment if it contains an RST.
632 * If the segment contains an ACK then it is bad and send a RST.
633 * If it does not contain a SYN then it is not interesting; drop it.
634 * Don't bother responding if the destination was a broadcast.
635 * Otherwise initialize tp->rcv_nxt, and tp->irs, select an initial
636 * tp->iss, and send a segment:
637 * <SEQ=ISS><ACK=RCV_NXT><CTL=SYN,ACK>
638 * Also initialize tp->snd_nxt to tp->iss+1 and tp->snd_una to tp->iss.
639 * Fill in remote peer address fields if not previously specified.
640 * Enter SYN_RECEIVED state, and process any other fields of this
641 * segment in this state.
645 register struct sockaddr_in
*sin
;
647 if (tiflags
& TH_RST
)
649 if (tiflags
& TH_ACK
)
651 if ((tiflags
& TH_SYN
) == 0)
654 * RFC1122 4.2.3.10, p. 104: discard bcast/mcast SYN
655 * in_broadcast() should never return true on a received
656 * packet with M_BCAST not set.
658 if (m
->m_flags
& (M_BCAST
|M_MCAST
) ||
659 IN_MULTICAST(ntohl(ti
->ti_dst
.s_addr
)))
661 am
= m_get(M_DONTWAIT
, MT_SONAME
); /* XXX */
664 am
->m_len
= sizeof (struct sockaddr_in
);
665 sin
= mtod(am
, struct sockaddr_in
*);
666 sin
->sin_family
= AF_INET
;
667 sin
->sin_len
= sizeof(*sin
);
668 sin
->sin_addr
= ti
->ti_src
;
669 sin
->sin_port
= ti
->ti_sport
;
670 bzero((caddr_t
)sin
->sin_zero
, sizeof(sin
->sin_zero
));
671 laddr
= inp
->inp_laddr
;
672 if (inp
->inp_laddr
.s_addr
== INADDR_ANY
)
673 inp
->inp_laddr
= ti
->ti_dst
;
674 if (in_pcbconnect(inp
, am
)) {
675 inp
->inp_laddr
= laddr
;
680 tp
->t_template
= tcp_template(tp
);
681 if (tp
->t_template
== 0) {
682 tp
= tcp_drop(tp
, ENOBUFS
);
683 dropsocket
= 0; /* socket is already gone */
686 if ((taop
= tcp_gettaocache(inp
)) == NULL
) {
687 taop
= &tao_noncached
;
688 bzero(taop
, sizeof(*taop
));
690 tcp_dooptions(tp
, optp
, optlen
, ti
, &to
);
695 tcp_iss
+= TCP_ISSINCR
/2;
696 tp
->irs
= ti
->ti_seq
;
700 * Initialization of the tcpcb for transaction;
701 * set SND.WND = SEG.WND,
702 * initialize CCsend and CCrecv.
704 tp
->snd_wnd
= tiwin
; /* initial send-window */
705 tp
->cc_send
= CC_INC(tcp_ccgen
);
706 tp
->cc_recv
= to
.to_cc
;
708 * Perform TAO test on incoming CC (SEG.CC) option, if any.
709 * - compare SEG.CC against cached CC from the same host,
711 * - if SEG.CC > chached value, SYN must be new and is accepted
712 * immediately: save new CC in the cache, mark the socket
713 * connected, enter ESTABLISHED state, turn on flag to
714 * send a SYN in the next segment.
715 * A virtual advertised window is set in rcv_adv to
716 * initialize SWS prevention. Then enter normal segment
717 * processing: drop SYN, process data and FIN.
718 * - otherwise do a normal 3-way handshake.
720 if ((to
.to_flag
& TOF_CC
) != 0) {
721 if (taop
->tao_cc
!= 0 && CC_GT(to
.to_cc
, taop
->tao_cc
)) {
722 taop
->tao_cc
= to
.to_cc
;
723 tp
->t_state
= TCPS_ESTABLISHED
;
726 * If there is a FIN, or if there is data and the
727 * connection is local, then delay SYN,ACK(SYN) in
728 * the hope of piggy-backing it on a response
729 * segment. Otherwise must send ACK now in case
730 * the other side is slow starting.
732 if ((tiflags
& TH_FIN
) || (ti
->ti_len
!= 0 &&
733 in_localaddr(inp
->inp_faddr
)))
734 tp
->t_flags
|= (TF_DELACK
| TF_NEEDSYN
);
736 tp
->t_flags
|= (TF_ACKNOW
| TF_NEEDSYN
);
739 * Limit the `virtual advertised window' to TCP_MAXWIN
740 * here. Even if we requested window scaling, it will
741 * become effective only later when our SYN is acked.
743 tp
->rcv_adv
+= min(tp
->rcv_wnd
, TCP_MAXWIN
);
744 tcpstat
.tcps_connects
++;
746 tp
->t_timer
[TCPT_KEEP
] = tcp_keepinit
;
747 dropsocket
= 0; /* committed to socket */
748 tcpstat
.tcps_accepts
++;
751 /* else do standard 3-way handshake */
754 * No CC option, but maybe CC.NEW:
755 * invalidate cached value.
760 * TAO test failed or there was no CC option,
761 * do a standard 3-way handshake.
763 tp
->t_flags
|= TF_ACKNOW
;
764 tp
->t_state
= TCPS_SYN_RECEIVED
;
765 tp
->t_timer
[TCPT_KEEP
] = tcp_keepinit
;
766 dropsocket
= 0; /* committed to socket */
767 tcpstat
.tcps_accepts
++;
772 * If the state is SYN_RECEIVED:
773 * do just the ack and RST checks from SYN_SENT state.
774 * If the state is SYN_SENT:
775 * if seg contains an ACK, but not for our SYN, drop the input.
776 * if seg contains a RST, then drop the connection.
777 * if seg does not contain SYN, then drop it.
778 * Otherwise this is an acceptable SYN segment
779 * initialize tp->rcv_nxt and tp->irs
780 * if seg contains ack then advance tp->snd_una
781 * if SYN has been acked change to ESTABLISHED else SYN_RCVD state
782 * arrange for segment to be acked (eventually)
783 * continue processing rest of data/controls, beginning with URG
785 case TCPS_SYN_RECEIVED
:
787 if ((taop
= tcp_gettaocache(inp
)) == NULL
) {
788 taop
= &tao_noncached
;
789 bzero(taop
, sizeof(*taop
));
792 if ((tiflags
& TH_ACK
) &&
793 (SEQ_LEQ(ti
->ti_ack
, tp
->iss
) ||
794 SEQ_GT(ti
->ti_ack
, tp
->snd_max
))) {
796 * If we have a cached CCsent for the remote host,
797 * hence we haven't just crashed and restarted,
798 * do not send a RST. This may be a retransmission
799 * from the other side after our earlier ACK was lost.
800 * Our new SYN, when it arrives, will serve as the
803 if (taop
->tao_ccsent
!= 0)
808 if (tiflags
& TH_RST
) {
809 if (tiflags
& TH_ACK
)
810 tp
= tcp_drop(tp
, ECONNREFUSED
);
813 if (tp
->t_state
== TCPS_SYN_RECEIVED
)
815 if ((tiflags
& TH_SYN
) == 0)
817 tp
->snd_wnd
= ti
->ti_win
; /* initial send window */
818 tp
->cc_recv
= to
.to_cc
; /* foreign CC */
820 tp
->irs
= ti
->ti_seq
;
822 if (tiflags
& TH_ACK
) {
824 * Our SYN was acked. If segment contains CC.ECHO
825 * option, check it to make sure this segment really
826 * matches our SYN. If not, just drop it as old
827 * duplicate, but send an RST if we're still playing
830 if ((to
.to_flag
& TOF_CCECHO
) &&
831 tp
->cc_send
!= to
.to_ccecho
) {
832 if (taop
->tao_ccsent
!= 0)
837 tcpstat
.tcps_connects
++;
839 /* Do window scaling on this connection? */
840 if ((tp
->t_flags
& (TF_RCVD_SCALE
|TF_REQ_SCALE
)) ==
841 (TF_RCVD_SCALE
|TF_REQ_SCALE
)) {
842 tp
->snd_scale
= tp
->requested_s_scale
;
843 tp
->rcv_scale
= tp
->request_r_scale
;
845 /* Segment is acceptable, update cache if undefined. */
846 if (taop
->tao_ccsent
== 0)
847 taop
->tao_ccsent
= to
.to_ccecho
;
849 tp
->rcv_adv
+= tp
->rcv_wnd
;
850 tp
->snd_una
++; /* SYN is acked */
852 * If there's data, delay ACK; if there's also a FIN
853 * ACKNOW will be turned on later.
856 tp
->t_flags
|= TF_DELACK
;
858 tp
->t_flags
|= TF_ACKNOW
;
860 * Received <SYN,ACK> in SYN_SENT[*] state.
862 * SYN_SENT --> ESTABLISHED
863 * SYN_SENT* --> FIN_WAIT_1
865 if (tp
->t_flags
& TF_NEEDFIN
) {
866 tp
->t_state
= TCPS_FIN_WAIT_1
;
867 tp
->t_flags
&= ~TF_NEEDFIN
;
870 tp
->t_state
= TCPS_ESTABLISHED
;
871 tp
->t_timer
[TCPT_KEEP
] = tcp_keepidle
;
875 * Received initial SYN in SYN-SENT[*] state => simul-
876 * taneous open. If segment contains CC option and there is
877 * a cached CC, apply TAO test; if it succeeds, connection is
878 * half-synchronized. Otherwise, do 3-way handshake:
879 * SYN-SENT -> SYN-RECEIVED
880 * SYN-SENT* -> SYN-RECEIVED*
881 * If there was no CC option, clear cached CC value.
883 tp
->t_flags
|= TF_ACKNOW
;
884 tp
->t_timer
[TCPT_REXMT
] = 0;
885 if (to
.to_flag
& TOF_CC
) {
886 if (taop
->tao_cc
!= 0 &&
887 CC_GT(to
.to_cc
, taop
->tao_cc
)) {
889 * update cache and make transition:
890 * SYN-SENT -> ESTABLISHED*
891 * SYN-SENT* -> FIN-WAIT-1*
893 taop
->tao_cc
= to
.to_cc
;
894 if (tp
->t_flags
& TF_NEEDFIN
) {
895 tp
->t_state
= TCPS_FIN_WAIT_1
;
896 tp
->t_flags
&= ~TF_NEEDFIN
;
898 tp
->t_state
= TCPS_ESTABLISHED
;
899 tp
->t_timer
[TCPT_KEEP
] = tcp_keepidle
;
901 tp
->t_flags
|= TF_NEEDSYN
;
903 tp
->t_state
= TCPS_SYN_RECEIVED
;
905 /* CC.NEW or no option => invalidate cache */
907 tp
->t_state
= TCPS_SYN_RECEIVED
;
913 * Advance ti->ti_seq to correspond to first data byte.
914 * If data, trim to stay within window,
915 * dropping FIN if necessary.
918 if (ti
->ti_len
> tp
->rcv_wnd
) {
919 todrop
= ti
->ti_len
- tp
->rcv_wnd
;
921 ti
->ti_len
= tp
->rcv_wnd
;
923 tcpstat
.tcps_rcvpackafterwin
++;
924 tcpstat
.tcps_rcvbyteafterwin
+= todrop
;
926 tp
->snd_wl1
= ti
->ti_seq
- 1;
927 tp
->rcv_up
= ti
->ti_seq
;
929 * Client side of transaction: already sent SYN and data.
930 * If the remote host used T/TCP to validate the SYN,
931 * our data will be ACK'd; if so, enter normal data segment
932 * processing in the middle of step 5, ack processing.
933 * Otherwise, goto step 6.
935 if (tiflags
& TH_ACK
)
939 * If the state is LAST_ACK or CLOSING or TIME_WAIT:
940 * if segment contains a SYN and CC [not CC.NEW] option:
941 * if state == TIME_WAIT and connection duration > MSL,
942 * drop packet and send RST;
944 * if SEG.CC > CCrecv then is new SYN, and can implicitly
945 * ack the FIN (and data) in retransmission queue.
946 * Complete close and delete TCPCB. Then reprocess
947 * segment, hoping to find new TCPCB in LISTEN state;
949 * else must be old SYN; drop it.
950 * else do normal processing.
955 if ((tiflags
& TH_SYN
) &&
956 (to
.to_flag
& TOF_CC
) && tp
->cc_recv
!= 0) {
957 if (tp
->t_state
== TCPS_TIME_WAIT
&&
958 tp
->t_duration
> TCPTV_MSL
)
960 if (CC_GT(to
.to_cc
, tp
->cc_recv
)) {
967 break; /* continue normal processing */
971 * States other than LISTEN or SYN_SENT.
972 * First check timestamp, if present.
973 * Then check the connection count, if present.
974 * Then check that at least some bytes of segment are within
975 * receive window. If segment begins before rcv_nxt,
976 * drop leading data (and SYN); if nothing left, just ack.
978 * RFC 1323 PAWS: If we have a timestamp reply on this segment
979 * and it's less than ts_recent, drop it.
981 if ((to
.to_flag
& TOF_TS
) != 0 && (tiflags
& TH_RST
) == 0 &&
982 tp
->ts_recent
&& TSTMP_LT(to
.to_tsval
, tp
->ts_recent
)) {
984 /* Check to see if ts_recent is over 24 days old. */
985 if ((int)(tcp_now
- tp
->ts_recent_age
) > TCP_PAWS_IDLE
) {
987 * Invalidate ts_recent. If this segment updates
988 * ts_recent, the age will be reset later and ts_recent
989 * will get a valid value. If it does not, setting
990 * ts_recent to zero will at least satisfy the
991 * requirement that zero be placed in the timestamp
992 * echo reply when ts_recent isn't valid. The
993 * age isn't reset until we get a valid ts_recent
994 * because we don't want out-of-order segments to be
995 * dropped when ts_recent is old.
999 tcpstat
.tcps_rcvduppack
++;
1000 tcpstat
.tcps_rcvdupbyte
+= ti
->ti_len
;
1001 tcpstat
.tcps_pawsdrop
++;
1008 * If T/TCP was negotiated and the segment doesn't have CC,
1009 * or if it's CC is wrong then drop the segment.
1010 * RST segments do not have to comply with this.
1012 if ((tp
->t_flags
& (TF_REQ_CC
|TF_RCVD_CC
)) == (TF_REQ_CC
|TF_RCVD_CC
) &&
1013 ((to
.to_flag
& TOF_CC
) == 0 || tp
->cc_recv
!= to
.to_cc
) &&
1014 (tiflags
& TH_RST
) == 0)
1017 todrop
= tp
->rcv_nxt
- ti
->ti_seq
;
1019 if (tiflags
& TH_SYN
) {
1029 * Following if statement from Stevens, vol. 2, p. 960.
1031 if (todrop
> ti
->ti_len
1032 || (todrop
== ti
->ti_len
&& (tiflags
& TH_FIN
) == 0)) {
1034 * Any valid FIN must be to the left of the window.
1035 * At this point the FIN must be a duplicate or out
1036 * of sequence; drop it.
1041 * Send an ACK to resynchronize and drop any data.
1042 * But keep on processing for RST or ACK.
1044 tp
->t_flags
|= TF_ACKNOW
;
1045 todrop
= ti
->ti_len
;
1046 tcpstat
.tcps_rcvduppack
++;
1047 tcpstat
.tcps_rcvdupbyte
+= todrop
;
1049 tcpstat
.tcps_rcvpartduppack
++;
1050 tcpstat
.tcps_rcvpartdupbyte
+= todrop
;
1053 ti
->ti_seq
+= todrop
;
1054 ti
->ti_len
-= todrop
;
1055 if (ti
->ti_urp
> todrop
)
1056 ti
->ti_urp
-= todrop
;
1064 * If new data are received on a connection after the
1065 * user processes are gone, then RST the other end.
1067 if ((so
->so_state
& SS_NOFDREF
) &&
1068 tp
->t_state
> TCPS_CLOSE_WAIT
&& ti
->ti_len
) {
1070 tcpstat
.tcps_rcvafterclose
++;
1075 * If segment ends after window, drop trailing data
1076 * (and PUSH and FIN); if nothing left, just ACK.
1078 todrop
= (ti
->ti_seq
+ti
->ti_len
) - (tp
->rcv_nxt
+tp
->rcv_wnd
);
1080 tcpstat
.tcps_rcvpackafterwin
++;
1081 if (todrop
>= ti
->ti_len
) {
1082 tcpstat
.tcps_rcvbyteafterwin
+= ti
->ti_len
;
1084 * If a new connection request is received
1085 * while in TIME_WAIT, drop the old connection
1086 * and start over if the sequence numbers
1087 * are above the previous ones.
1089 if (tiflags
& TH_SYN
&&
1090 tp
->t_state
== TCPS_TIME_WAIT
&&
1091 SEQ_GT(ti
->ti_seq
, tp
->rcv_nxt
)) {
1092 iss
= tp
->rcv_nxt
+ TCP_ISSINCR
;
1097 * If window is closed can only take segments at
1098 * window edge, and have to drop data and PUSH from
1099 * incoming segments. Continue processing, but
1100 * remember to ack. Otherwise, drop segment
1103 if (tp
->rcv_wnd
== 0 && ti
->ti_seq
== tp
->rcv_nxt
) {
1104 tp
->t_flags
|= TF_ACKNOW
;
1105 tcpstat
.tcps_rcvwinprobe
++;
1109 tcpstat
.tcps_rcvbyteafterwin
+= todrop
;
1111 ti
->ti_len
-= todrop
;
1112 tiflags
&= ~(TH_PUSH
|TH_FIN
);
1116 * If last ACK falls within this segment's sequence numbers,
1117 * record its timestamp.
1118 * NOTE that the test is modified according to the latest
1119 * proposal of the tcplw@cray.com list (Braden 1993/04/26).
1121 if ((to
.to_flag
& TOF_TS
) != 0 &&
1122 SEQ_LEQ(ti
->ti_seq
, tp
->last_ack_sent
)) {
1123 tp
->ts_recent_age
= tcp_now
;
1124 tp
->ts_recent
= to
.to_tsval
;
1128 * If the RST bit is set examine the state:
1129 * SYN_RECEIVED STATE:
1130 * If passive open, return to LISTEN state.
1131 * If active open, inform user that connection was refused.
1132 * ESTABLISHED, FIN_WAIT_1, FIN_WAIT2, CLOSE_WAIT STATES:
1133 * Inform user that connection was reset, and close tcb.
1134 * CLOSING, LAST_ACK, TIME_WAIT STATES
1137 if (tiflags
&TH_RST
) switch (tp
->t_state
) {
1139 case TCPS_SYN_RECEIVED
:
1140 so
->so_error
= ECONNREFUSED
;
1143 case TCPS_ESTABLISHED
:
1144 case TCPS_FIN_WAIT_1
:
1145 case TCPS_FIN_WAIT_2
:
1146 case TCPS_CLOSE_WAIT
:
1147 so
->so_error
= ECONNRESET
;
1149 tp
->t_state
= TCPS_CLOSED
;
1150 tcpstat
.tcps_drops
++;
1156 case TCPS_TIME_WAIT
:
1162 * If a SYN is in the window, then this is an
1163 * error and we send an RST and drop the connection.
1165 if (tiflags
& TH_SYN
) {
1166 tp
= tcp_drop(tp
, ECONNRESET
);
1171 * If the ACK bit is off: if in SYN-RECEIVED state or SENDSYN
1172 * flag is on (half-synchronized state), then queue data for
1173 * later processing; else drop segment and return.
1175 if ((tiflags
& TH_ACK
) == 0) {
1176 if (tp
->t_state
== TCPS_SYN_RECEIVED
||
1177 (tp
->t_flags
& TF_NEEDSYN
))
1186 switch (tp
->t_state
) {
1189 * In SYN_RECEIVED state if the ack ACKs our SYN then enter
1190 * ESTABLISHED state and continue processing, otherwise
1193 case TCPS_SYN_RECEIVED
:
1194 if (SEQ_GT(tp
->snd_una
, ti
->ti_ack
) ||
1195 SEQ_GT(ti
->ti_ack
, tp
->snd_max
))
1198 tcpstat
.tcps_connects
++;
1200 /* Do window scaling? */
1201 if ((tp
->t_flags
& (TF_RCVD_SCALE
|TF_REQ_SCALE
)) ==
1202 (TF_RCVD_SCALE
|TF_REQ_SCALE
)) {
1203 tp
->snd_scale
= tp
->requested_s_scale
;
1204 tp
->rcv_scale
= tp
->request_r_scale
;
1207 * Upon successful completion of 3-way handshake,
1208 * update cache.CC if it was undefined, pass any queued
1209 * data to the user, and advance state appropriately.
1211 if ((taop
= tcp_gettaocache(inp
)) != NULL
&&
1213 taop
->tao_cc
= tp
->cc_recv
;
1217 * SYN-RECEIVED -> ESTABLISHED
1218 * SYN-RECEIVED* -> FIN-WAIT-1
1220 if (tp
->t_flags
& TF_NEEDFIN
) {
1221 tp
->t_state
= TCPS_FIN_WAIT_1
;
1222 tp
->t_flags
&= ~TF_NEEDFIN
;
1224 tp
->t_state
= TCPS_ESTABLISHED
;
1225 tp
->t_timer
[TCPT_KEEP
] = tcp_keepidle
;
1228 * If segment contains data or ACK, will call tcp_reass()
1229 * later; if not, do so now to pass queued data to user.
1231 if (ti
->ti_len
== 0 && (tiflags
& TH_FIN
) == 0)
1232 (void) tcp_reass(tp
, (struct tcpiphdr
*)0,
1234 tp
->snd_wl1
= ti
->ti_seq
- 1;
1238 * In ESTABLISHED state: drop duplicate ACKs; ACK out of range
1239 * ACKs. If the ack is in the range
1240 * tp->snd_una < ti->ti_ack <= tp->snd_max
1241 * then advance tp->snd_una to ti->ti_ack and drop
1242 * data from the retransmission queue. If this ACK reflects
1243 * more up to date window information we update our window information.
1245 case TCPS_ESTABLISHED
:
1246 case TCPS_FIN_WAIT_1
:
1247 case TCPS_FIN_WAIT_2
:
1248 case TCPS_CLOSE_WAIT
:
1251 case TCPS_TIME_WAIT
:
1253 if (SEQ_LEQ(ti
->ti_ack
, tp
->snd_una
)) {
1254 if (ti
->ti_len
== 0 && tiwin
== tp
->snd_wnd
) {
1255 tcpstat
.tcps_rcvdupack
++;
1257 * If we have outstanding data (other than
1258 * a window probe), this is a completely
1259 * duplicate ack (ie, window info didn't
1260 * change), the ack is the biggest we've
1261 * seen and we've seen exactly our rexmt
1262 * threshhold of them, assume a packet
1263 * has been dropped and retransmit it.
1264 * Kludge snd_nxt & the congestion
1265 * window so we send only this one
1268 * We know we're losing at the current
1269 * window size so do congestion avoidance
1270 * (set ssthresh to half the current window
1271 * and pull our congestion window back to
1272 * the new ssthresh).
1274 * Dup acks mean that packets have left the
1275 * network (they're now cached at the receiver)
1276 * so bump cwnd by the amount in the receiver
1277 * to keep a constant cwnd packets in the
1280 if (tp
->t_timer
[TCPT_REXMT
] == 0 ||
1281 ti
->ti_ack
!= tp
->snd_una
)
1283 else if (++tp
->t_dupacks
== tcprexmtthresh
) {
1284 tcp_seq onxt
= tp
->snd_nxt
;
1286 min(tp
->snd_wnd
, tp
->snd_cwnd
) / 2 /
1291 tp
->snd_ssthresh
= win
* tp
->t_maxseg
;
1292 tp
->t_timer
[TCPT_REXMT
] = 0;
1294 tp
->snd_nxt
= ti
->ti_ack
;
1295 tp
->snd_cwnd
= tp
->t_maxseg
;
1296 (void) tcp_output(tp
);
1297 tp
->snd_cwnd
= tp
->snd_ssthresh
+
1298 tp
->t_maxseg
* tp
->t_dupacks
;
1299 if (SEQ_GT(onxt
, tp
->snd_nxt
))
1302 } else if (tp
->t_dupacks
> tcprexmtthresh
) {
1303 tp
->snd_cwnd
+= tp
->t_maxseg
;
1304 (void) tcp_output(tp
);
1312 * If the congestion window was inflated to account
1313 * for the other side's cached packets, retract it.
1315 if (tp
->t_dupacks
> tcprexmtthresh
&&
1316 tp
->snd_cwnd
> tp
->snd_ssthresh
)
1317 tp
->snd_cwnd
= tp
->snd_ssthresh
;
1319 if (SEQ_GT(ti
->ti_ack
, tp
->snd_max
)) {
1320 tcpstat
.tcps_rcvacktoomuch
++;
1324 * If we reach this point, ACK is not a duplicate,
1325 * i.e., it ACKs something we sent.
1327 if (tp
->t_flags
& TF_NEEDSYN
) {
1329 * T/TCP: Connection was half-synchronized, and our
1330 * SYN has been ACK'd (so connection is now fully
1331 * synchronized). Go to non-starred state,
1332 * increment snd_una for ACK of SYN, and check if
1333 * we can do window scaling.
1335 tp
->t_flags
&= ~TF_NEEDSYN
;
1337 /* Do window scaling? */
1338 if ((tp
->t_flags
& (TF_RCVD_SCALE
|TF_REQ_SCALE
)) ==
1339 (TF_RCVD_SCALE
|TF_REQ_SCALE
)) {
1340 tp
->snd_scale
= tp
->requested_s_scale
;
1341 tp
->rcv_scale
= tp
->request_r_scale
;
1346 acked
= ti
->ti_ack
- tp
->snd_una
;
1347 tcpstat
.tcps_rcvackpack
++;
1348 tcpstat
.tcps_rcvackbyte
+= acked
;
1351 * If we have a timestamp reply, update smoothed
1352 * round trip time. If no timestamp is present but
1353 * transmit timer is running and timed sequence
1354 * number was acked, update smoothed round trip time.
1355 * Since we now have an rtt measurement, cancel the
1356 * timer backoff (cf., Phil Karn's retransmit alg.).
1357 * Recompute the initial retransmit timer.
1359 if (to
.to_flag
& TOF_TS
)
1360 tcp_xmit_timer(tp
, tcp_now
- to
.to_tsecr
+ 1);
1361 else if (tp
->t_rtt
&& SEQ_GT(ti
->ti_ack
, tp
->t_rtseq
))
1362 tcp_xmit_timer(tp
,tp
->t_rtt
);
1365 * If all outstanding data is acked, stop retransmit
1366 * timer and remember to restart (more output or persist).
1367 * If there is more data to be acked, restart retransmit
1368 * timer, using current (possibly backed-off) value.
1370 if (ti
->ti_ack
== tp
->snd_max
) {
1371 tp
->t_timer
[TCPT_REXMT
] = 0;
1373 } else if (tp
->t_timer
[TCPT_PERSIST
] == 0)
1374 tp
->t_timer
[TCPT_REXMT
] = tp
->t_rxtcur
;
1377 * If no data (only SYN) was ACK'd,
1378 * skip rest of ACK processing.
1384 * When new data is acked, open the congestion window.
1385 * If the window gives us less than ssthresh packets
1386 * in flight, open exponentially (maxseg per packet).
1387 * Otherwise open linearly: maxseg per window
1388 * (maxseg^2 / cwnd per packet).
1391 register u_int cw
= tp
->snd_cwnd
;
1392 register u_int incr
= tp
->t_maxseg
;
1394 if (cw
> tp
->snd_ssthresh
)
1395 incr
= incr
* incr
/ cw
;
1396 tp
->snd_cwnd
= min(cw
+ incr
, TCP_MAXWIN
<<tp
->snd_scale
);
1398 if (acked
> so
->so_snd
.sb_cc
) {
1399 tp
->snd_wnd
-= so
->so_snd
.sb_cc
;
1400 sbdrop(&so
->so_snd
, (int)so
->so_snd
.sb_cc
);
1403 sbdrop(&so
->so_snd
, acked
);
1404 tp
->snd_wnd
-= acked
;
1407 if (so
->so_snd
.sb_flags
& SB_NOTIFY
)
1409 tp
->snd_una
= ti
->ti_ack
;
1410 if (SEQ_LT(tp
->snd_nxt
, tp
->snd_una
))
1411 tp
->snd_nxt
= tp
->snd_una
;
1413 switch (tp
->t_state
) {
1416 * In FIN_WAIT_1 STATE in addition to the processing
1417 * for the ESTABLISHED state if our FIN is now acknowledged
1418 * then enter FIN_WAIT_2.
1420 case TCPS_FIN_WAIT_1
:
1421 if (ourfinisacked
) {
1423 * If we can't receive any more
1424 * data, then closing user can proceed.
1425 * Starting the timer is contrary to the
1426 * specification, but if we don't get a FIN
1427 * we'll hang forever.
1429 if (so
->so_state
& SS_CANTRCVMORE
) {
1430 soisdisconnected(so
);
1431 tp
->t_timer
[TCPT_2MSL
] = tcp_maxidle
;
1433 tp
->t_state
= TCPS_FIN_WAIT_2
;
1438 * In CLOSING STATE in addition to the processing for
1439 * the ESTABLISHED state if the ACK acknowledges our FIN
1440 * then enter the TIME-WAIT state, otherwise ignore
1444 if (ourfinisacked
) {
1445 tp
->t_state
= TCPS_TIME_WAIT
;
1446 tcp_canceltimers(tp
);
1447 /* Shorten TIME_WAIT [RFC-1644, p.28] */
1448 if (tp
->cc_recv
!= 0 &&
1449 tp
->t_duration
< TCPTV_MSL
)
1450 tp
->t_timer
[TCPT_2MSL
] =
1451 tp
->t_rxtcur
* TCPTV_TWTRUNC
;
1453 tp
->t_timer
[TCPT_2MSL
] = 2 * TCPTV_MSL
;
1454 soisdisconnected(so
);
1459 * In LAST_ACK, we may still be waiting for data to drain
1460 * and/or to be acked, as well as for the ack of our FIN.
1461 * If our FIN is now acknowledged, delete the TCB,
1462 * enter the closed state and return.
1465 if (ourfinisacked
) {
1472 * In TIME_WAIT state the only thing that should arrive
1473 * is a retransmission of the remote FIN. Acknowledge
1474 * it and restart the finack timer.
1476 case TCPS_TIME_WAIT
:
1477 tp
->t_timer
[TCPT_2MSL
] = 2 * TCPTV_MSL
;
1484 * Update window information.
1485 * Don't look at window if no ACK: TAC's send garbage on first SYN.
1487 if ((tiflags
& TH_ACK
) &&
1488 (SEQ_LT(tp
->snd_wl1
, ti
->ti_seq
) ||
1489 (tp
->snd_wl1
== ti
->ti_seq
&& (SEQ_LT(tp
->snd_wl2
, ti
->ti_ack
) ||
1490 (tp
->snd_wl2
== ti
->ti_ack
&& tiwin
> tp
->snd_wnd
))))) {
1491 /* keep track of pure window updates */
1492 if (ti
->ti_len
== 0 &&
1493 tp
->snd_wl2
== ti
->ti_ack
&& tiwin
> tp
->snd_wnd
)
1494 tcpstat
.tcps_rcvwinupd
++;
1495 tp
->snd_wnd
= tiwin
;
1496 tp
->snd_wl1
= ti
->ti_seq
;
1497 tp
->snd_wl2
= ti
->ti_ack
;
1498 if (tp
->snd_wnd
> tp
->max_sndwnd
)
1499 tp
->max_sndwnd
= tp
->snd_wnd
;
1504 * Process segments with URG.
1506 if ((tiflags
& TH_URG
) && ti
->ti_urp
&&
1507 TCPS_HAVERCVDFIN(tp
->t_state
) == 0) {
1509 * This is a kludge, but if we receive and accept
1510 * random urgent pointers, we'll crash in
1511 * soreceive. It's hard to imagine someone
1512 * actually wanting to send this much urgent data.
1514 if (ti
->ti_urp
+ so
->so_rcv
.sb_cc
> sb_max
) {
1515 ti
->ti_urp
= 0; /* XXX */
1516 tiflags
&= ~TH_URG
; /* XXX */
1517 goto dodata
; /* XXX */
1520 * If this segment advances the known urgent pointer,
1521 * then mark the data stream. This should not happen
1522 * in CLOSE_WAIT, CLOSING, LAST_ACK or TIME_WAIT STATES since
1523 * a FIN has been received from the remote side.
1524 * In these states we ignore the URG.
1526 * According to RFC961 (Assigned Protocols),
1527 * the urgent pointer points to the last octet
1528 * of urgent data. We continue, however,
1529 * to consider it to indicate the first octet
1530 * of data past the urgent section as the original
1531 * spec states (in one of two places).
1533 if (SEQ_GT(ti
->ti_seq
+ti
->ti_urp
, tp
->rcv_up
)) {
1534 tp
->rcv_up
= ti
->ti_seq
+ ti
->ti_urp
;
1535 so
->so_oobmark
= so
->so_rcv
.sb_cc
+
1536 (tp
->rcv_up
- tp
->rcv_nxt
) - 1;
1537 if (so
->so_oobmark
== 0)
1538 so
->so_state
|= SS_RCVATMARK
;
1540 tp
->t_oobflags
&= ~(TCPOOB_HAVEDATA
| TCPOOB_HADDATA
);
1543 * Remove out of band data so doesn't get presented to user.
1544 * This can happen independent of advancing the URG pointer,
1545 * but if two URG's are pending at once, some out-of-band
1546 * data may creep in... ick.
1548 if (ti
->ti_urp
<= (u_long
)ti
->ti_len
1550 && (so
->so_options
& SO_OOBINLINE
) == 0
1553 tcp_pulloutofband(so
, ti
, m
);
1556 * If no out of band data is expected,
1557 * pull receive urgent pointer along
1558 * with the receive window.
1560 if (SEQ_GT(tp
->rcv_nxt
, tp
->rcv_up
))
1561 tp
->rcv_up
= tp
->rcv_nxt
;
1565 * Process the segment text, merging it into the TCP sequencing queue,
1566 * and arranging for acknowledgment of receipt if necessary.
1567 * This process logically involves adjusting tp->rcv_wnd as data
1568 * is presented to the user (this happens in tcp_usrreq.c,
1569 * case PRU_RCVD). If a FIN has already been received on this
1570 * connection then we just ignore the text.
1572 if ((ti
->ti_len
|| (tiflags
&TH_FIN
)) &&
1573 TCPS_HAVERCVDFIN(tp
->t_state
) == 0) {
1574 TCP_REASS(tp
, ti
, m
, so
, tiflags
);
1576 * Note the amount of data that peer has sent into
1577 * our window, in order to estimate the sender's
1580 len
= so
->so_rcv
.sb_hiwat
- (tp
->rcv_adv
- tp
->rcv_nxt
);
1587 * If FIN is received ACK the FIN and let the user know
1588 * that the connection is closing.
1590 if (tiflags
& TH_FIN
) {
1591 if (TCPS_HAVERCVDFIN(tp
->t_state
) == 0) {
1594 * If connection is half-synchronized
1595 * (ie NEEDSYN flag on) then delay ACK,
1596 * so it may be piggybacked when SYN is sent.
1597 * Otherwise, since we received a FIN then no
1598 * more input can be expected, send ACK now.
1600 if (tp
->t_flags
& TF_NEEDSYN
)
1601 tp
->t_flags
|= TF_DELACK
;
1603 tp
->t_flags
|= TF_ACKNOW
;
1606 switch (tp
->t_state
) {
1609 * In SYN_RECEIVED and ESTABLISHED STATES
1610 * enter the CLOSE_WAIT state.
1612 case TCPS_SYN_RECEIVED
:
1613 case TCPS_ESTABLISHED
:
1614 tp
->t_state
= TCPS_CLOSE_WAIT
;
1618 * If still in FIN_WAIT_1 STATE FIN has not been acked so
1619 * enter the CLOSING state.
1621 case TCPS_FIN_WAIT_1
:
1622 tp
->t_state
= TCPS_CLOSING
;
1626 * In FIN_WAIT_2 state enter the TIME_WAIT state,
1627 * starting the time-wait timer, turning off the other
1630 case TCPS_FIN_WAIT_2
:
1631 tp
->t_state
= TCPS_TIME_WAIT
;
1632 tcp_canceltimers(tp
);
1633 /* Shorten TIME_WAIT [RFC-1644, p.28] */
1634 if (tp
->cc_recv
!= 0 &&
1635 tp
->t_duration
< TCPTV_MSL
) {
1636 tp
->t_timer
[TCPT_2MSL
] =
1637 tp
->t_rxtcur
* TCPTV_TWTRUNC
;
1638 /* For transaction client, force ACK now. */
1639 tp
->t_flags
|= TF_ACKNOW
;
1642 tp
->t_timer
[TCPT_2MSL
] = 2 * TCPTV_MSL
;
1643 soisdisconnected(so
);
1647 * In TIME_WAIT state restart the 2 MSL time_wait timer.
1649 case TCPS_TIME_WAIT
:
1650 tp
->t_timer
[TCPT_2MSL
] = 2 * TCPTV_MSL
;
1655 if (so
->so_options
& SO_DEBUG
)
1656 tcp_trace(TA_INPUT
, ostate
, tp
, &tcp_saveti
, 0);
1660 * Return any desired output.
1662 if (needoutput
|| (tp
->t_flags
& TF_ACKNOW
))
1663 (void) tcp_output(tp
);
1668 * Generate an ACK dropping incoming segment if it occupies
1669 * sequence space, where the ACK reflects our state.
1671 if (tiflags
& TH_RST
)
1674 if (so
->so_options
& SO_DEBUG
)
1675 tcp_trace(TA_DROP
, ostate
, tp
, &tcp_saveti
, 0);
1678 tp
->t_flags
|= TF_ACKNOW
;
1679 (void) tcp_output(tp
);
1684 * Generate a RST, dropping incoming segment.
1685 * Make ACK acceptable to originator of segment.
1686 * Don't bother to respond if destination was broadcast/multicast.
1688 if ((tiflags
& TH_RST
) || m
->m_flags
& (M_BCAST
|M_MCAST
) ||
1689 IN_MULTICAST(ntohl(ti
->ti_dst
.s_addr
)))
1692 if (tp
== 0 || (tp
->t_inpcb
->inp_socket
->so_options
& SO_DEBUG
))
1693 tcp_trace(TA_DROP
, ostate
, tp
, &tcp_saveti
, 0);
1695 if (tiflags
& TH_ACK
)
1696 tcp_respond(tp
, ti
, m
, (tcp_seq
)0, ti
->ti_ack
, TH_RST
);
1698 if (tiflags
& TH_SYN
)
1700 tcp_respond(tp
, ti
, m
, ti
->ti_seq
+ti
->ti_len
, (tcp_seq
)0,
1703 /* destroy temporarily created socket */
1710 * Drop space held by incoming segment and return.
1713 if (tp
== 0 || (tp
->t_inpcb
->inp_socket
->so_options
& SO_DEBUG
))
1714 tcp_trace(TA_DROP
, ostate
, tp
, &tcp_saveti
, 0);
1717 /* destroy temporarily created socket */
1721 #ifndef TUBA_INCLUDE
1725 tcp_dooptions(tp
, cp
, cnt
, ti
, to
)
1729 struct tcpiphdr
*ti
;
1735 for (; cnt
> 0; cnt
-= optlen
, cp
+= optlen
) {
1737 if (opt
== TCPOPT_EOL
)
1739 if (opt
== TCPOPT_NOP
)
1752 if (optlen
!= TCPOLEN_MAXSEG
)
1754 if (!(ti
->ti_flags
& TH_SYN
))
1756 bcopy((char *) cp
+ 2, (char *) &mss
, sizeof(mss
));
1761 if (optlen
!= TCPOLEN_WINDOW
)
1763 if (!(ti
->ti_flags
& TH_SYN
))
1765 tp
->t_flags
|= TF_RCVD_SCALE
;
1766 tp
->requested_s_scale
= min(cp
[2], TCP_MAX_WINSHIFT
);
1769 case TCPOPT_TIMESTAMP
:
1770 if (optlen
!= TCPOLEN_TIMESTAMP
)
1772 to
->to_flag
|= TOF_TS
;
1773 bcopy((char *)cp
+ 2,
1774 (char *)&to
->to_tsval
, sizeof(to
->to_tsval
));
1775 NTOHL(to
->to_tsval
);
1776 bcopy((char *)cp
+ 6,
1777 (char *)&to
->to_tsecr
, sizeof(to
->to_tsecr
));
1778 NTOHL(to
->to_tsecr
);
1781 * A timestamp received in a SYN makes
1782 * it ok to send timestamp requests and replies.
1784 if (ti
->ti_flags
& TH_SYN
) {
1785 tp
->t_flags
|= TF_RCVD_TSTMP
;
1786 tp
->ts_recent
= to
->to_tsval
;
1787 tp
->ts_recent_age
= tcp_now
;
1791 if (optlen
!= TCPOLEN_CC
)
1793 to
->to_flag
|= TOF_CC
;
1794 bcopy((char *)cp
+ 2,
1795 (char *)&to
->to_cc
, sizeof(to
->to_cc
));
1798 * A CC or CC.new option received in a SYN makes
1799 * it ok to send CC in subsequent segments.
1801 if (ti
->ti_flags
& TH_SYN
)
1802 tp
->t_flags
|= TF_RCVD_CC
;
1805 if (optlen
!= TCPOLEN_CC
)
1807 if (!(ti
->ti_flags
& TH_SYN
))
1809 to
->to_flag
|= TOF_CCNEW
;
1810 bcopy((char *)cp
+ 2,
1811 (char *)&to
->to_cc
, sizeof(to
->to_cc
));
1814 * A CC or CC.new option received in a SYN makes
1815 * it ok to send CC in subsequent segments.
1817 tp
->t_flags
|= TF_RCVD_CC
;
1820 if (optlen
!= TCPOLEN_CC
)
1822 if (!(ti
->ti_flags
& TH_SYN
))
1824 to
->to_flag
|= TOF_CCECHO
;
1825 bcopy((char *)cp
+ 2,
1826 (char *)&to
->to_ccecho
, sizeof(to
->to_ccecho
));
1827 NTOHL(to
->to_ccecho
);
1831 if (ti
->ti_flags
& TH_SYN
)
1832 tcp_mss(tp
, mss
); /* sets t_maxseg */
1836 * Pull out of band byte out of a segment so
1837 * it doesn't appear in the user's data queue.
1838 * It is still reflected in the segment length for
1839 * sequencing purposes.
1842 tcp_pulloutofband(so
, ti
, m
)
1844 struct tcpiphdr
*ti
;
1845 register struct mbuf
*m
;
1847 int cnt
= ti
->ti_urp
- 1;
1850 if (m
->m_len
> cnt
) {
1851 char *cp
= mtod(m
, caddr_t
) + cnt
;
1852 struct tcpcb
*tp
= sototcpcb(so
);
1855 tp
->t_oobflags
|= TCPOOB_HAVEDATA
;
1856 bcopy(cp
+1, cp
, (unsigned)(m
->m_len
- cnt
- 1));
1865 panic("tcp_pulloutofband");
1869 * Collect new round-trip time estimate
1870 * and update averages and current timeout.
1873 tcp_xmit_timer(tp
, rtt
)
1874 register struct tcpcb
*tp
;
1877 register short delta
;
1879 tcpstat
.tcps_rttupdated
++;
1881 if (tp
->t_srtt
!= 0) {
1883 * srtt is stored as fixed point with 3 bits after the
1884 * binary point (i.e., scaled by 8). The following magic
1885 * is equivalent to the smoothing algorithm in rfc793 with
1886 * an alpha of .875 (srtt = rtt/8 + srtt*7/8 in fixed
1887 * point). Adjust rtt to origin 0.
1889 delta
= rtt
- 1 - (tp
->t_srtt
>> TCP_RTT_SHIFT
);
1890 if ((tp
->t_srtt
+= delta
) <= 0)
1893 * We accumulate a smoothed rtt variance (actually, a
1894 * smoothed mean difference), then set the retransmit
1895 * timer to smoothed rtt + 4 times the smoothed variance.
1896 * rttvar is stored as fixed point with 2 bits after the
1897 * binary point (scaled by 4). The following is
1898 * equivalent to rfc793 smoothing with an alpha of .75
1899 * (rttvar = rttvar*3/4 + |delta| / 4). This replaces
1900 * rfc793's wired-in beta.
1904 delta
-= (tp
->t_rttvar
>> TCP_RTTVAR_SHIFT
);
1905 if ((tp
->t_rttvar
+= delta
) <= 0)
1909 * No rtt measurement yet - use the unsmoothed rtt.
1910 * Set the variance to half the rtt (so our first
1911 * retransmit happens at 3*rtt).
1913 tp
->t_srtt
= rtt
<< TCP_RTT_SHIFT
;
1914 tp
->t_rttvar
= rtt
<< (TCP_RTTVAR_SHIFT
- 1);
1920 * the retransmit should happen at rtt + 4 * rttvar.
1921 * Because of the way we do the smoothing, srtt and rttvar
1922 * will each average +1/2 tick of bias. When we compute
1923 * the retransmit timer, we want 1/2 tick of rounding and
1924 * 1 extra tick because of +-1/2 tick uncertainty in the
1925 * firing of the timer. The bias will give us exactly the
1926 * 1.5 tick we need. But, because the bias is
1927 * statistical, we have to test that we don't drop below
1928 * the minimum feasible timer (which is 2 ticks).
1930 TCPT_RANGESET(tp
->t_rxtcur
, TCP_REXMTVAL(tp
),
1931 tp
->t_rttmin
, TCPTV_REXMTMAX
);
1934 * We received an ack for a packet that wasn't retransmitted;
1935 * it is probably safe to discard any error indications we've
1936 * received recently. This isn't quite right, but close enough
1937 * for now (a route might have failed after we sent a segment,
1938 * and the return path might not be symmetrical).
1940 tp
->t_softerror
= 0;
1944 * Determine a reasonable value for maxseg size.
1945 * If the route is known, check route for mtu.
1946 * If none, use an mss that can be handled on the outgoing
1947 * interface without forcing IP to fragment; if bigger than
1948 * an mbuf cluster (MCLBYTES), round down to nearest multiple of MCLBYTES
1949 * to utilize large mbufs. If no route is found, route has no mtu,
1950 * or the destination isn't local, use a default, hopefully conservative
1951 * size (usually 512 or the default IP max size, but no more than the mtu
1952 * of the interface), as we can't discover anything about intervening
1953 * gateways or networks. We also initialize the congestion/slow start
1954 * window to be a single segment if the destination isn't local.
1955 * While looking at the routing entry, we also initialize other path-dependent
1956 * parameters from pre-set or cached values in the routing entry.
1958 * Also take into account the space needed for options that we
1959 * send regularly. Make maxseg shorter by that amount to assure
1960 * that we can send maxseg amount of data even when the options
1961 * are present. Store the upper limit of the length of options plus
1964 * NOTE that this routine is only called when we process an incoming
1965 * segment, for outgoing segments only tcp_mssopt is called.
1967 * In case of T/TCP, we call this routine during implicit connection
1968 * setup as well (offer = -1), to initialize maxseg from the cached
1976 register struct rtentry
*rt
;
1978 register int rtt
, mss
;
1982 struct rmxp_tao
*taop
;
1983 int origoffer
= offer
;
1986 if ((rt
= tcp_rtlookup(inp
)) == NULL
) {
1987 tp
->t_maxopd
= tp
->t_maxseg
= tcp_mssdflt
;
1993 so
= inp
->inp_socket
;
1995 taop
= rmx_taop(rt
->rt_rmx
);
1997 * Offer == -1 means that we didn't receive SYN yet,
1998 * use cached value in that case;
2001 offer
= taop
->tao_mssopt
;
2003 * Offer == 0 means that there was no MSS on the SYN segment,
2004 * in this case we use tcp_mssdflt.
2007 offer
= tcp_mssdflt
;
2010 * Sanity check: make sure that maxopd will be large
2011 * enough to allow some data on segments even is the
2012 * all the option space is used (40bytes). Otherwise
2013 * funny things may happen in tcp_output.
2015 offer
= max(offer
, 64);
2016 taop
->tao_mssopt
= offer
;
2019 * While we're here, check if there's an initial rtt
2020 * or rttvar. Convert from the route-table units
2021 * to scaled multiples of the slow timeout timer.
2023 if (tp
->t_srtt
== 0 && (rtt
= rt
->rt_rmx
.rmx_rtt
)) {
2025 * XXX the lock bit for RTT indicates that the value
2026 * is also a minimum value; this is subject to time.
2028 if (rt
->rt_rmx
.rmx_locks
& RTV_RTT
)
2029 tp
->t_rttmin
= rtt
/ (RTM_RTTUNIT
/ PR_SLOWHZ
);
2030 tp
->t_srtt
= rtt
/ (RTM_RTTUNIT
/ (PR_SLOWHZ
* TCP_RTT_SCALE
));
2031 tcpstat
.tcps_usedrtt
++;
2032 if (rt
->rt_rmx
.rmx_rttvar
) {
2033 tp
->t_rttvar
= rt
->rt_rmx
.rmx_rttvar
/
2034 (RTM_RTTUNIT
/ (PR_SLOWHZ
* TCP_RTTVAR_SCALE
));
2035 tcpstat
.tcps_usedrttvar
++;
2037 /* default variation is +- 1 rtt */
2039 tp
->t_srtt
* TCP_RTTVAR_SCALE
/ TCP_RTT_SCALE
;
2041 TCPT_RANGESET(tp
->t_rxtcur
,
2042 ((tp
->t_srtt
>> 2) + tp
->t_rttvar
) >> 1,
2043 tp
->t_rttmin
, TCPTV_REXMTMAX
);
2046 * if there's an mtu associated with the route, use it
2048 if (rt
->rt_rmx
.rmx_mtu
)
2049 mss
= rt
->rt_rmx
.rmx_mtu
- sizeof(struct tcpiphdr
);
2052 mss
= ifp
->if_mtu
- sizeof(struct tcpiphdr
);
2053 if (!in_localaddr(inp
->inp_faddr
))
2054 mss
= min(mss
, tcp_mssdflt
);
2056 mss
= min(mss
, offer
);
2058 * maxopd stores the maximum length of data AND options
2059 * in a segment; maxseg is the amount of data in a normal
2060 * segment. We need to store this value (maxopd) apart
2061 * from maxseg, because now every segment carries options
2062 * and thus we normally have somewhat less data in segments.
2067 * In case of T/TCP, origoffer==-1 indicates, that no segments
2068 * were received yet. In this case we just guess, otherwise
2069 * we do the same as before T/TCP.
2071 if ((tp
->t_flags
& (TF_REQ_TSTMP
|TF_NOOPT
)) == TF_REQ_TSTMP
&&
2073 (tp
->t_flags
& TF_RCVD_TSTMP
) == TF_RCVD_TSTMP
))
2074 mss
-= TCPOLEN_TSTAMP_APPA
;
2075 if ((tp
->t_flags
& (TF_REQ_CC
|TF_NOOPT
)) == TF_REQ_CC
&&
2077 (tp
->t_flags
& TF_RCVD_CC
) == TF_RCVD_CC
))
2078 mss
-= TCPOLEN_CC_APPA
;
2080 #if (MCLBYTES & (MCLBYTES - 1)) == 0
2082 mss
&= ~(MCLBYTES
-1);
2085 mss
= mss
/ MCLBYTES
* MCLBYTES
;
2088 * If there's a pipesize, change the socket buffer
2089 * to that size. Make the socket buffers an integral
2090 * number of mss units; if the mss is larger than
2091 * the socket buffer, decrease the mss.
2094 if ((bufsize
= rt
->rt_rmx
.rmx_sendpipe
) == 0)
2096 bufsize
= so
->so_snd
.sb_hiwat
;
2100 bufsize
= roundup(bufsize
, mss
);
2101 if (bufsize
> sb_max
)
2103 (void)sbreserve(&so
->so_snd
, bufsize
);
2108 if ((bufsize
= rt
->rt_rmx
.rmx_recvpipe
) == 0)
2110 bufsize
= so
->so_rcv
.sb_hiwat
;
2111 if (bufsize
> mss
) {
2112 bufsize
= roundup(bufsize
, mss
);
2113 if (bufsize
> sb_max
)
2115 (void)sbreserve(&so
->so_rcv
, bufsize
);
2118 * Don't force slow-start on local network.
2120 if (!in_localaddr(inp
->inp_faddr
))
2123 if (rt
->rt_rmx
.rmx_ssthresh
) {
2125 * There's some sort of gateway or interface
2126 * buffer limit on the path. Use this to set
2127 * the slow start threshhold, but set the
2128 * threshold to no less than 2*mss.
2130 tp
->snd_ssthresh
= max(2 * mss
, rt
->rt_rmx
.rmx_ssthresh
);
2131 tcpstat
.tcps_usedssthresh
++;
2136 * Determine the MSS option to send on an outgoing SYN.
2144 rt
= tcp_rtlookup(tp
->t_inpcb
);
2148 return rt
->rt_ifp
->if_mtu
- sizeof(struct tcpiphdr
);
2153 #endif /* TUBA_INCLUDE */