Deleted Added
sdiff udiff text old ( 253571 ) new ( 254889 )
full compact
1/*-
2 * Copyright (c) 1982, 1986, 1988, 1990, 1993, 1994, 1995
3 * The Regents of the University of California. All rights reserved.
4 * Copyright (c) 2007-2008,2010
5 * Swinburne University of Technology, Melbourne, Australia.
6 * Copyright (c) 2009-2010 Lawrence Stewart <lstewart@freebsd.org>
7 * Copyright (c) 2010 The FreeBSD Foundation
8 * Copyright (c) 2010-2011 Juniper Networks, Inc.

--- 34 unchanged lines hidden (view full) ---

43 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
44 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
45 * SUCH DAMAGE.
46 *
47 * @(#)tcp_input.c 8.12 (Berkeley) 5/24/95
48 */
49
50#include <sys/cdefs.h>
51__FBSDID("$FreeBSD: head/sys/netinet/tcp_input.c 253571 2013-07-23 14:14:24Z ae $");
52
53#include "opt_ipfw.h" /* for ipfw_fwd */
54#include "opt_inet.h"
55#include "opt_inet6.h"
56#include "opt_ipsec.h"
57#include "opt_tcpdebug.h"
58
59#include <sys/param.h>
60#include <sys/kernel.h>
61#include <sys/hhook.h>
62#include <sys/malloc.h>
63#include <sys/mbuf.h>
64#include <sys/proc.h> /* for proc0 declaration */
65#include <sys/protosw.h>
66#include <sys/signalvar.h>
67#include <sys/socket.h>
68#include <sys/socketvar.h>
69#include <sys/sysctl.h>
70#include <sys/syslog.h>
71#include <sys/systm.h>
72
73#include <machine/cpu.h> /* before tcp_seq.h, for tcp_random18() */
74
75#include <vm/uma.h>
76
77#include <net/if.h>
78#include <net/route.h>
79#include <net/vnet.h>
80
81#define TCPSTATES /* for logging */
82
83#include <netinet/cc.h>
84#include <netinet/in.h>
85#include <netinet/in_pcb.h>
86#include <netinet/in_systm.h>
87#include <netinet/in_var.h>
88#include <netinet/ip.h>
89#include <netinet/ip_icmp.h> /* required for icmp_var.h */
90#include <netinet/icmp_var.h> /* for ICMP_BANDLIM */
91#include <netinet/ip_var.h>
92#include <netinet/ip_options.h>

--- 590 unchanged lines hidden (view full) ---

683
684 /*
685 * Checksum extended TCP header and data.
686 */
687 len = off0 + tlen;
688 bzero(ipov->ih_x1, sizeof(ipov->ih_x1));
689 ipov->ih_len = htons(tlen);
690 th->th_sum = in_cksum(m, len);
691 }
692 if (th->th_sum) {
693 TCPSTAT_INC(tcps_rcvbadsum);
694 goto drop;
695 }
696 /* Re-initialization for later version check */
697 ip->ip_v = IPVERSION;
698 }
699#endif /* INET */

--- 679 unchanged lines hidden (view full) ---

1379 if ((thflags & TH_RST) == 0 ||
1380 (tp->t_state == TCPS_SYN_SENT) == 0)
1381 goto dropunlock;
1382 }
1383 sig_checked = 1;
1384 }
1385#endif
1386
1387 /*
1388 * Segment belongs to a connection in SYN_SENT, ESTABLISHED or later
1389 * state. tcp_do_segment() always consumes the mbuf chain, unlocks
1390 * the inpcb, and unlocks pcbinfo.
1391 */
1392 tcp_do_segment(m, th, so, tp, drop_hdrlen, tlen, iptos, ti_locked);
1393 INP_INFO_UNLOCK_ASSERT(&V_tcbinfo);
1394 return;
1395
1396dropwithreset:
1397 if (ti_locked == TI_WLOCKED) {
1398 INP_INFO_WUNLOCK(&V_tcbinfo);
1399 ti_locked = TI_UNLOCKED;
1400 }
1401#ifdef INVARIANTS
1402 else {
1403 KASSERT(ti_locked == TI_UNLOCKED, ("%s: dropwithreset "
1404 "ti_locked: %d", __func__, ti_locked));

--- 5 unchanged lines hidden (view full) ---

1410 tcp_dropwithreset(m, th, tp, tlen, rstreason);
1411 INP_WUNLOCK(inp);
1412 } else
1413 tcp_dropwithreset(m, th, NULL, tlen, rstreason);
1414 m = NULL; /* mbuf chain got consumed. */
1415 goto drop;
1416
1417dropunlock:
1418 if (ti_locked == TI_WLOCKED) {
1419 INP_INFO_WUNLOCK(&V_tcbinfo);
1420 ti_locked = TI_UNLOCKED;
1421 }
1422#ifdef INVARIANTS
1423 else {
1424 KASSERT(ti_locked == TI_UNLOCKED, ("%s: dropunlock "
1425 "ti_locked: %d", __func__, ti_locked));

--- 479 unchanged lines hidden (view full) ---

1905 */
1906 case TCPS_SYN_SENT:
1907 if ((thflags & TH_ACK) &&
1908 (SEQ_LEQ(th->th_ack, tp->iss) ||
1909 SEQ_GT(th->th_ack, tp->snd_max))) {
1910 rstreason = BANDLIM_UNLIMITED;
1911 goto dropwithreset;
1912 }
1913 if ((thflags & (TH_ACK|TH_RST)) == (TH_ACK|TH_RST))
1914 tp = tcp_drop(tp, ECONNREFUSED);
1915 if (thflags & TH_RST)
1916 goto drop;
1917 if (!(thflags & TH_SYN))
1918 goto drop;
1919
1920 tp->irs = th->th_seq;
1921 tcp_rcvseqinit(tp);
1922 if (thflags & TH_ACK) {

--- 28 unchanged lines hidden (view full) ---

1951 /*
1952 * Received <SYN,ACK> in SYN_SENT[*] state.
1953 * Transitions:
1954 * SYN_SENT --> ESTABLISHED
1955 * SYN_SENT* --> FIN_WAIT_1
1956 */
1957 tp->t_starttime = ticks;
1958 if (tp->t_flags & TF_NEEDFIN) {
1959 tp->t_state = TCPS_FIN_WAIT_1;
1960 tp->t_flags &= ~TF_NEEDFIN;
1961 thflags &= ~TH_SYN;
1962 } else {
1963 tp->t_state = TCPS_ESTABLISHED;
1964 cc_conn_init(tp);
1965 tcp_timer_activate(tp, TT_KEEP,
1966 TP_KEEPIDLE(tp));
1967 }
1968 } else {
1969 /*
1970 * Received initial SYN in SYN-SENT[*] state =>
1971 * simultaneous open. If segment contains CC option
1972 * and there is a cached CC, apply TAO test.
1973 * If it succeeds, connection is * half-synchronized.
1974 * Otherwise, do 3-way handshake:
1975 * SYN-SENT -> SYN-RECEIVED
1976 * SYN-SENT* -> SYN-RECEIVED*
1977 * If there was no CC option, clear cached CC value.
1978 */
1979 tp->t_flags |= (TF_ACKNOW | TF_NEEDSYN);
1980 tcp_timer_activate(tp, TT_REXMT, 0);
1981 tp->t_state = TCPS_SYN_RECEIVED;
1982 }
1983
1984 KASSERT(ti_locked == TI_WLOCKED, ("%s: trimthenstep6: "
1985 "ti_locked %d", __func__, ti_locked));
1986 INP_INFO_WLOCK_ASSERT(&V_tcbinfo);
1987 INP_WLOCK_ASSERT(tp->t_inpcb);
1988
1989 /*

--- 121 unchanged lines hidden (view full) ---

2111 case TCPS_CLOSE_WAIT:
2112 so->so_error = ECONNRESET;
2113 close:
2114 KASSERT(ti_locked == TI_WLOCKED,
2115 ("tcp_do_segment: TH_RST 1 ti_locked %d",
2116 ti_locked));
2117 INP_INFO_WLOCK_ASSERT(&V_tcbinfo);
2118
2119 tp->t_state = TCPS_CLOSED;
2120 TCPSTAT_INC(tcps_drops);
2121 tp = tcp_close(tp);
2122 break;
2123
2124 case TCPS_CLOSING:
2125 case TCPS_LAST_ACK:
2126 KASSERT(ti_locked == TI_WLOCKED,
2127 ("tcp_do_segment: TH_RST 2 ti_locked %d",

--- 228 unchanged lines hidden (view full) ---

2356 }
2357 /*
2358 * Make transitions:
2359 * SYN-RECEIVED -> ESTABLISHED
2360 * SYN-RECEIVED* -> FIN-WAIT-1
2361 */
2362 tp->t_starttime = ticks;
2363 if (tp->t_flags & TF_NEEDFIN) {
2364 tp->t_state = TCPS_FIN_WAIT_1;
2365 tp->t_flags &= ~TF_NEEDFIN;
2366 } else {
2367 tp->t_state = TCPS_ESTABLISHED;
2368 cc_conn_init(tp);
2369 tcp_timer_activate(tp, TT_KEEP, TP_KEEPIDLE(tp));
2370 }
2371 /*
2372 * If segment contains data or ACK, will call tcp_reass()
2373 * later; if not, do so now to pass queued data to user.
2374 */
2375 if (tlen == 0 && (thflags & TH_FIN) == 0)

--- 371 unchanged lines hidden (view full) ---

2747 */
2748 if (so->so_rcv.sb_state & SBS_CANTRCVMORE) {
2749 soisdisconnected(so);
2750 tcp_timer_activate(tp, TT_2MSL,
2751 (tcp_fast_finwait2_recycle ?
2752 tcp_finwait2_timeout :
2753 TP_MAXIDLE(tp)));
2754 }
2755 tp->t_state = TCPS_FIN_WAIT_2;
2756 }
2757 break;
2758
2759 /*
2760 * In CLOSING STATE in addition to the processing for
2761 * the ESTABLISHED state if the ACK acknowledges our FIN
2762 * then enter the TIME-WAIT state, otherwise ignore
2763 * the segment.

--- 209 unchanged lines hidden (view full) ---

2973 /*
2974 * In SYN_RECEIVED and ESTABLISHED STATES
2975 * enter the CLOSE_WAIT state.
2976 */
2977 case TCPS_SYN_RECEIVED:
2978 tp->t_starttime = ticks;
2979 /* FALLTHROUGH */
2980 case TCPS_ESTABLISHED:
2981 tp->t_state = TCPS_CLOSE_WAIT;
2982 break;
2983
2984 /*
2985 * If still in FIN_WAIT_1 STATE FIN has not been acked so
2986 * enter the CLOSING state.
2987 */
2988 case TCPS_FIN_WAIT_1:
2989 tp->t_state = TCPS_CLOSING;
2990 break;
2991
2992 /*
2993 * In FIN_WAIT_2 state enter the TIME_WAIT state,
2994 * starting the time-wait timer, turning off the other
2995 * standard timers.
2996 */
2997 case TCPS_FIN_WAIT_2:

--- 715 unchanged lines hidden ---