tcp_input.c (9d4fb27db90043cd2640e4bc778f9c755d3c17c1) tcp_input.c (4957faade11b3a278c3b3cade3411ddc20afa791)
1/*
2 * INET An implementation of the TCP/IP protocol suite for the LINUX
3 * operating system. INET is implemented using the BSD Socket
4 * interface as the means of communication with the user level.
5 *
6 * Implementation of the Transmission Control Protocol(TCP).
7 *
8 * Authors: Ross Biro

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

3693 return 0;
3694}
3695
3696/* Look for tcp options. Normally only called on SYN and SYNACK packets.
3697 * But, this can also be called on packets in the established flow when
3698 * the fast version below fails.
3699 */
3700void tcp_parse_options(struct sk_buff *skb, struct tcp_options_received *opt_rx,
1/*
2 * INET An implementation of the TCP/IP protocol suite for the LINUX
3 * operating system. INET is implemented using the BSD Socket
4 * interface as the means of communication with the user level.
5 *
6 * Implementation of the Transmission Control Protocol(TCP).
7 *
8 * Authors: Ross Biro

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

3693 return 0;
3694}
3695
3696/* Look for tcp options. Normally only called on SYN and SYNACK packets.
3697 * But, this can also be called on packets in the established flow when
3698 * the fast version below fails.
3699 */
3700void tcp_parse_options(struct sk_buff *skb, struct tcp_options_received *opt_rx,
3701 int estab, struct dst_entry *dst)
3701 u8 **hvpp, int estab, struct dst_entry *dst)
3702{
3703 unsigned char *ptr;
3704 struct tcphdr *th = tcp_hdr(skb);
3705 int length = (th->doff * 4) - sizeof(struct tcphdr);
3706
3707 ptr = (unsigned char *)(th + 1);
3708 opt_rx->saw_tstamp = 0;
3709

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

3780#ifdef CONFIG_TCP_MD5SIG
3781 case TCPOPT_MD5SIG:
3782 /*
3783 * The MD5 Hash has already been
3784 * checked (see tcp_v{4,6}_do_rcv()).
3785 */
3786 break;
3787#endif
3702{
3703 unsigned char *ptr;
3704 struct tcphdr *th = tcp_hdr(skb);
3705 int length = (th->doff * 4) - sizeof(struct tcphdr);
3706
3707 ptr = (unsigned char *)(th + 1);
3708 opt_rx->saw_tstamp = 0;
3709

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

3780#ifdef CONFIG_TCP_MD5SIG
3781 case TCPOPT_MD5SIG:
3782 /*
3783 * The MD5 Hash has already been
3784 * checked (see tcp_v{4,6}_do_rcv()).
3785 */
3786 break;
3787#endif
3788 }
3788 case TCPOPT_COOKIE:
3789 /* This option is variable length.
3790 */
3791 switch (opsize) {
3792 case TCPOLEN_COOKIE_BASE:
3793 /* not yet implemented */
3794 break;
3795 case TCPOLEN_COOKIE_PAIR:
3796 /* not yet implemented */
3797 break;
3798 case TCPOLEN_COOKIE_MIN+0:
3799 case TCPOLEN_COOKIE_MIN+2:
3800 case TCPOLEN_COOKIE_MIN+4:
3801 case TCPOLEN_COOKIE_MIN+6:
3802 case TCPOLEN_COOKIE_MAX:
3803 /* 16-bit multiple */
3804 opt_rx->cookie_plus = opsize;
3805 *hvpp = ptr;
3806 default:
3807 /* ignore option */
3808 break;
3809 };
3810 break;
3811 };
3789
3790 ptr += opsize-2;
3791 length -= opsize;
3792 }
3793 }
3794}
3795
3796static int tcp_parse_aligned_timestamp(struct tcp_sock *tp, struct tcphdr *th)

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

3808 }
3809 return 0;
3810}
3811
3812/* Fast parse options. This hopes to only see timestamps.
3813 * If it is wrong it falls back on tcp_parse_options().
3814 */
3815static int tcp_fast_parse_options(struct sk_buff *skb, struct tcphdr *th,
3812
3813 ptr += opsize-2;
3814 length -= opsize;
3815 }
3816 }
3817}
3818
3819static int tcp_parse_aligned_timestamp(struct tcp_sock *tp, struct tcphdr *th)

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

3831 }
3832 return 0;
3833}
3834
3835/* Fast parse options. This hopes to only see timestamps.
3836 * If it is wrong it falls back on tcp_parse_options().
3837 */
3838static int tcp_fast_parse_options(struct sk_buff *skb, struct tcphdr *th,
3816 struct tcp_sock *tp)
3839 struct tcp_sock *tp, u8 **hvpp)
3817{
3840{
3818 if (th->doff == sizeof(struct tcphdr) >> 2) {
3841 /* In the spirit of fast parsing, compare doff directly to constant
3842 * values. Because equality is used, short doff can be ignored here.
3843 */
3844 if (th->doff == (sizeof(*th) / 4)) {
3819 tp->rx_opt.saw_tstamp = 0;
3820 return 0;
3821 } else if (tp->rx_opt.tstamp_ok &&
3845 tp->rx_opt.saw_tstamp = 0;
3846 return 0;
3847 } else if (tp->rx_opt.tstamp_ok &&
3822 th->doff == (sizeof(struct tcphdr)>>2)+(TCPOLEN_TSTAMP_ALIGNED>>2)) {
3848 th->doff == ((sizeof(*th) + TCPOLEN_TSTAMP_ALIGNED) / 4)) {
3823 if (tcp_parse_aligned_timestamp(tp, th))
3824 return 1;
3825 }
3849 if (tcp_parse_aligned_timestamp(tp, th))
3850 return 1;
3851 }
3826 tcp_parse_options(skb, &tp->rx_opt, 1, NULL);
3852 tcp_parse_options(skb, &tp->rx_opt, hvpp, 1, NULL);
3827 return 1;
3828}
3829
3830#ifdef CONFIG_TCP_MD5SIG
3831/*
3832 * Parse MD5 Signature option
3833 */
3834u8 *tcp_parse_md5sig_option(struct tcphdr *th)

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

5072#endif /* CONFIG_NET_DMA */
5073
5074/* Does PAWS and seqno based validation of an incoming segment, flags will
5075 * play significant role here.
5076 */
5077static int tcp_validate_incoming(struct sock *sk, struct sk_buff *skb,
5078 struct tcphdr *th, int syn_inerr)
5079{
3853 return 1;
3854}
3855
3856#ifdef CONFIG_TCP_MD5SIG
3857/*
3858 * Parse MD5 Signature option
3859 */
3860u8 *tcp_parse_md5sig_option(struct tcphdr *th)

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

5098#endif /* CONFIG_NET_DMA */
5099
5100/* Does PAWS and seqno based validation of an incoming segment, flags will
5101 * play significant role here.
5102 */
5103static int tcp_validate_incoming(struct sock *sk, struct sk_buff *skb,
5104 struct tcphdr *th, int syn_inerr)
5105{
5106 u8 *hash_location;
5080 struct tcp_sock *tp = tcp_sk(sk);
5081
5082 /* RFC1323: H1. Apply PAWS check first. */
5107 struct tcp_sock *tp = tcp_sk(sk);
5108
5109 /* RFC1323: H1. Apply PAWS check first. */
5083 if (tcp_fast_parse_options(skb, th, tp) && tp->rx_opt.saw_tstamp &&
5110 if (tcp_fast_parse_options(skb, th, tp, &hash_location) &&
5111 tp->rx_opt.saw_tstamp &&
5084 tcp_paws_discard(sk, skb)) {
5085 if (!th->rst) {
5086 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_PAWSESTABREJECTED);
5087 tcp_send_dupack(sk, skb);
5088 goto discard;
5089 }
5090 /* Reset is accepted even if it did not pass PAWS. */
5091 }

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

5363discard:
5364 __kfree_skb(skb);
5365 return 0;
5366}
5367
5368static int tcp_rcv_synsent_state_process(struct sock *sk, struct sk_buff *skb,
5369 struct tcphdr *th, unsigned len)
5370{
5112 tcp_paws_discard(sk, skb)) {
5113 if (!th->rst) {
5114 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_PAWSESTABREJECTED);
5115 tcp_send_dupack(sk, skb);
5116 goto discard;
5117 }
5118 /* Reset is accepted even if it did not pass PAWS. */
5119 }

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

5391discard:
5392 __kfree_skb(skb);
5393 return 0;
5394}
5395
5396static int tcp_rcv_synsent_state_process(struct sock *sk, struct sk_buff *skb,
5397 struct tcphdr *th, unsigned len)
5398{
5371 struct tcp_sock *tp = tcp_sk(sk);
5399 u8 *hash_location;
5372 struct inet_connection_sock *icsk = inet_csk(sk);
5400 struct inet_connection_sock *icsk = inet_csk(sk);
5373 int saved_clamp = tp->rx_opt.mss_clamp;
5401 struct tcp_sock *tp = tcp_sk(sk);
5374 struct dst_entry *dst = __sk_dst_get(sk);
5402 struct dst_entry *dst = __sk_dst_get(sk);
5403 struct tcp_cookie_values *cvp = tp->cookie_values;
5404 int saved_clamp = tp->rx_opt.mss_clamp;
5375
5405
5376 tcp_parse_options(skb, &tp->rx_opt, 0, dst);
5406 tcp_parse_options(skb, &tp->rx_opt, &hash_location, 0, dst);
5377
5378 if (th->ack) {
5379 /* rfc793:
5380 * "If the state is SYN-SENT then
5381 * first check the ACK bit
5382 * If the ACK bit is set
5383 * If SEG.ACK =< ISS, or SEG.ACK > SND.NXT, send
5384 * a reset (unless the RST bit is set, if so drop

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

5465 tcp_mtup_init(sk);
5466 tcp_sync_mss(sk, icsk->icsk_pmtu_cookie);
5467 tcp_initialize_rcv_mss(sk);
5468
5469 /* Remember, tcp_poll() does not lock socket!
5470 * Change state from SYN-SENT only after copied_seq
5471 * is initialized. */
5472 tp->copied_seq = tp->rcv_nxt;
5407
5408 if (th->ack) {
5409 /* rfc793:
5410 * "If the state is SYN-SENT then
5411 * first check the ACK bit
5412 * If the ACK bit is set
5413 * If SEG.ACK =< ISS, or SEG.ACK > SND.NXT, send
5414 * a reset (unless the RST bit is set, if so drop

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

5495 tcp_mtup_init(sk);
5496 tcp_sync_mss(sk, icsk->icsk_pmtu_cookie);
5497 tcp_initialize_rcv_mss(sk);
5498
5499 /* Remember, tcp_poll() does not lock socket!
5500 * Change state from SYN-SENT only after copied_seq
5501 * is initialized. */
5502 tp->copied_seq = tp->rcv_nxt;
5503
5504 if (cvp != NULL &&
5505 cvp->cookie_pair_size > 0 &&
5506 tp->rx_opt.cookie_plus > 0) {
5507 int cookie_size = tp->rx_opt.cookie_plus
5508 - TCPOLEN_COOKIE_BASE;
5509 int cookie_pair_size = cookie_size
5510 + cvp->cookie_desired;
5511
5512 /* A cookie extension option was sent and returned.
5513 * Note that each incoming SYNACK replaces the
5514 * Responder cookie. The initial exchange is most
5515 * fragile, as protection against spoofing relies
5516 * entirely upon the sequence and timestamp (above).
5517 * This replacement strategy allows the correct pair to
5518 * pass through, while any others will be filtered via
5519 * Responder verification later.
5520 */
5521 if (sizeof(cvp->cookie_pair) >= cookie_pair_size) {
5522 memcpy(&cvp->cookie_pair[cvp->cookie_desired],
5523 hash_location, cookie_size);
5524 cvp->cookie_pair_size = cookie_pair_size;
5525 }
5526 }
5527
5473 smp_mb();
5474 tcp_set_state(sk, TCP_ESTABLISHED);
5475
5476 security_inet_conn_established(sk, skb);
5477
5478 /* Make sure socket is routed, for correct metrics. */
5479 icsk->icsk_af_ops->rebuild_header(sk);
5480

--- 372 unchanged lines hidden ---
5528 smp_mb();
5529 tcp_set_state(sk, TCP_ESTABLISHED);
5530
5531 security_inet_conn_established(sk, skb);
5532
5533 /* Make sure socket is routed, for correct metrics. */
5534 icsk->icsk_af_ops->rebuild_header(sk);
5535

--- 372 unchanged lines hidden ---