diff options
Diffstat (limited to 'net/ipv4/tcp_ipv4.c')
-rw-r--r-- | net/ipv4/tcp_ipv4.c | 98 |
1 files changed, 41 insertions, 57 deletions
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index cd17f009aede..94d1a7757ff7 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c | |||
@@ -72,7 +72,6 @@ | |||
72 | #include <net/inet_common.h> | 72 | #include <net/inet_common.h> |
73 | #include <net/timewait_sock.h> | 73 | #include <net/timewait_sock.h> |
74 | #include <net/xfrm.h> | 74 | #include <net/xfrm.h> |
75 | #include <net/netdma.h> | ||
76 | #include <net/secure_seq.h> | 75 | #include <net/secure_seq.h> |
77 | #include <net/tcp_memcontrol.h> | 76 | #include <net/tcp_memcontrol.h> |
78 | #include <net/busy_poll.h> | 77 | #include <net/busy_poll.h> |
@@ -90,7 +89,6 @@ int sysctl_tcp_tw_reuse __read_mostly; | |||
90 | int sysctl_tcp_low_latency __read_mostly; | 89 | int sysctl_tcp_low_latency __read_mostly; |
91 | EXPORT_SYMBOL(sysctl_tcp_low_latency); | 90 | EXPORT_SYMBOL(sysctl_tcp_low_latency); |
92 | 91 | ||
93 | |||
94 | #ifdef CONFIG_TCP_MD5SIG | 92 | #ifdef CONFIG_TCP_MD5SIG |
95 | static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key, | 93 | static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key, |
96 | __be32 daddr, __be32 saddr, const struct tcphdr *th); | 94 | __be32 daddr, __be32 saddr, const struct tcphdr *th); |
@@ -431,15 +429,16 @@ void tcp_v4_err(struct sk_buff *icmp_skb, u32 info) | |||
431 | break; | 429 | break; |
432 | 430 | ||
433 | icsk->icsk_backoff--; | 431 | icsk->icsk_backoff--; |
434 | inet_csk(sk)->icsk_rto = (tp->srtt_us ? __tcp_set_rto(tp) : | 432 | icsk->icsk_rto = tp->srtt_us ? __tcp_set_rto(tp) : |
435 | TCP_TIMEOUT_INIT) << icsk->icsk_backoff; | 433 | TCP_TIMEOUT_INIT; |
436 | tcp_bound_rto(sk); | 434 | icsk->icsk_rto = inet_csk_rto_backoff(icsk, TCP_RTO_MAX); |
437 | 435 | ||
438 | skb = tcp_write_queue_head(sk); | 436 | skb = tcp_write_queue_head(sk); |
439 | BUG_ON(!skb); | 437 | BUG_ON(!skb); |
440 | 438 | ||
441 | remaining = icsk->icsk_rto - min(icsk->icsk_rto, | 439 | remaining = icsk->icsk_rto - |
442 | tcp_time_stamp - TCP_SKB_CB(skb)->when); | 440 | min(icsk->icsk_rto, |
441 | tcp_time_stamp - tcp_skb_timestamp(skb)); | ||
443 | 442 | ||
444 | if (remaining) { | 443 | if (remaining) { |
445 | inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS, | 444 | inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS, |
@@ -681,8 +680,9 @@ static void tcp_v4_send_reset(struct sock *sk, struct sk_buff *skb) | |||
681 | 680 | ||
682 | net = dev_net(skb_dst(skb)->dev); | 681 | net = dev_net(skb_dst(skb)->dev); |
683 | arg.tos = ip_hdr(skb)->tos; | 682 | arg.tos = ip_hdr(skb)->tos; |
684 | ip_send_unicast_reply(net, skb, ip_hdr(skb)->saddr, | 683 | ip_send_unicast_reply(net, skb, &TCP_SKB_CB(skb)->header.h4.opt, |
685 | ip_hdr(skb)->daddr, &arg, arg.iov[0].iov_len); | 684 | ip_hdr(skb)->saddr, ip_hdr(skb)->daddr, |
685 | &arg, arg.iov[0].iov_len); | ||
686 | 686 | ||
687 | TCP_INC_STATS_BH(net, TCP_MIB_OUTSEGS); | 687 | TCP_INC_STATS_BH(net, TCP_MIB_OUTSEGS); |
688 | TCP_INC_STATS_BH(net, TCP_MIB_OUTRSTS); | 688 | TCP_INC_STATS_BH(net, TCP_MIB_OUTRSTS); |
@@ -764,8 +764,9 @@ static void tcp_v4_send_ack(struct sk_buff *skb, u32 seq, u32 ack, | |||
764 | if (oif) | 764 | if (oif) |
765 | arg.bound_dev_if = oif; | 765 | arg.bound_dev_if = oif; |
766 | arg.tos = tos; | 766 | arg.tos = tos; |
767 | ip_send_unicast_reply(net, skb, ip_hdr(skb)->saddr, | 767 | ip_send_unicast_reply(net, skb, &TCP_SKB_CB(skb)->header.h4.opt, |
768 | ip_hdr(skb)->daddr, &arg, arg.iov[0].iov_len); | 768 | ip_hdr(skb)->saddr, ip_hdr(skb)->daddr, |
769 | &arg, arg.iov[0].iov_len); | ||
769 | 770 | ||
770 | TCP_INC_STATS_BH(net, TCP_MIB_OUTSEGS); | 771 | TCP_INC_STATS_BH(net, TCP_MIB_OUTSEGS); |
771 | } | 772 | } |
@@ -879,28 +880,6 @@ bool tcp_syn_flood_action(struct sock *sk, | |||
879 | } | 880 | } |
880 | EXPORT_SYMBOL(tcp_syn_flood_action); | 881 | EXPORT_SYMBOL(tcp_syn_flood_action); |
881 | 882 | ||
882 | /* | ||
883 | * Save and compile IPv4 options into the request_sock if needed. | ||
884 | */ | ||
885 | static struct ip_options_rcu *tcp_v4_save_options(struct sk_buff *skb) | ||
886 | { | ||
887 | const struct ip_options *opt = &(IPCB(skb)->opt); | ||
888 | struct ip_options_rcu *dopt = NULL; | ||
889 | |||
890 | if (opt && opt->optlen) { | ||
891 | int opt_size = sizeof(*dopt) + opt->optlen; | ||
892 | |||
893 | dopt = kmalloc(opt_size, GFP_ATOMIC); | ||
894 | if (dopt) { | ||
895 | if (ip_options_echo(&dopt->opt, skb)) { | ||
896 | kfree(dopt); | ||
897 | dopt = NULL; | ||
898 | } | ||
899 | } | ||
900 | } | ||
901 | return dopt; | ||
902 | } | ||
903 | |||
904 | #ifdef CONFIG_TCP_MD5SIG | 883 | #ifdef CONFIG_TCP_MD5SIG |
905 | /* | 884 | /* |
906 | * RFC2385 MD5 checksumming requires a mapping of | 885 | * RFC2385 MD5 checksumming requires a mapping of |
@@ -1269,7 +1248,7 @@ struct request_sock_ops tcp_request_sock_ops __read_mostly = { | |||
1269 | .send_ack = tcp_v4_reqsk_send_ack, | 1248 | .send_ack = tcp_v4_reqsk_send_ack, |
1270 | .destructor = tcp_v4_reqsk_destructor, | 1249 | .destructor = tcp_v4_reqsk_destructor, |
1271 | .send_reset = tcp_v4_send_reset, | 1250 | .send_reset = tcp_v4_send_reset, |
1272 | .syn_ack_timeout = tcp_syn_ack_timeout, | 1251 | .syn_ack_timeout = tcp_syn_ack_timeout, |
1273 | }; | 1252 | }; |
1274 | 1253 | ||
1275 | static const struct tcp_request_sock_ops tcp_request_sock_ipv4_ops = { | 1254 | static const struct tcp_request_sock_ops tcp_request_sock_ipv4_ops = { |
@@ -1429,7 +1408,7 @@ static struct sock *tcp_v4_hnd_req(struct sock *sk, struct sk_buff *skb) | |||
1429 | 1408 | ||
1430 | #ifdef CONFIG_SYN_COOKIES | 1409 | #ifdef CONFIG_SYN_COOKIES |
1431 | if (!th->syn) | 1410 | if (!th->syn) |
1432 | sk = cookie_v4_check(sk, skb, &(IPCB(skb)->opt)); | 1411 | sk = cookie_v4_check(sk, skb); |
1433 | #endif | 1412 | #endif |
1434 | return sk; | 1413 | return sk; |
1435 | } | 1414 | } |
@@ -1559,7 +1538,17 @@ bool tcp_prequeue(struct sock *sk, struct sk_buff *skb) | |||
1559 | skb_queue_len(&tp->ucopy.prequeue) == 0) | 1538 | skb_queue_len(&tp->ucopy.prequeue) == 0) |
1560 | return false; | 1539 | return false; |
1561 | 1540 | ||
1562 | skb_dst_force(skb); | 1541 | /* Before escaping RCU protected region, we need to take care of skb |
1542 | * dst. Prequeue is only enabled for established sockets. | ||
1543 | * For such sockets, we might need the skb dst only to set sk->sk_rx_dst | ||
1544 | * Instead of doing full sk_rx_dst validity here, let's perform | ||
1545 | * an optimistic check. | ||
1546 | */ | ||
1547 | if (likely(sk->sk_rx_dst)) | ||
1548 | skb_dst_drop(skb); | ||
1549 | else | ||
1550 | skb_dst_force(skb); | ||
1551 | |||
1563 | __skb_queue_tail(&tp->ucopy.prequeue, skb); | 1552 | __skb_queue_tail(&tp->ucopy.prequeue, skb); |
1564 | tp->ucopy.memory += skb->truesize; | 1553 | tp->ucopy.memory += skb->truesize; |
1565 | if (tp->ucopy.memory > sk->sk_rcvbuf) { | 1554 | if (tp->ucopy.memory > sk->sk_rcvbuf) { |
@@ -1624,11 +1613,19 @@ int tcp_v4_rcv(struct sk_buff *skb) | |||
1624 | 1613 | ||
1625 | th = tcp_hdr(skb); | 1614 | th = tcp_hdr(skb); |
1626 | iph = ip_hdr(skb); | 1615 | iph = ip_hdr(skb); |
1616 | /* This is tricky : We move IPCB at its correct location into TCP_SKB_CB() | ||
1617 | * barrier() makes sure compiler wont play fool^Waliasing games. | ||
1618 | */ | ||
1619 | memmove(&TCP_SKB_CB(skb)->header.h4, IPCB(skb), | ||
1620 | sizeof(struct inet_skb_parm)); | ||
1621 | barrier(); | ||
1622 | |||
1627 | TCP_SKB_CB(skb)->seq = ntohl(th->seq); | 1623 | TCP_SKB_CB(skb)->seq = ntohl(th->seq); |
1628 | TCP_SKB_CB(skb)->end_seq = (TCP_SKB_CB(skb)->seq + th->syn + th->fin + | 1624 | TCP_SKB_CB(skb)->end_seq = (TCP_SKB_CB(skb)->seq + th->syn + th->fin + |
1629 | skb->len - th->doff * 4); | 1625 | skb->len - th->doff * 4); |
1630 | TCP_SKB_CB(skb)->ack_seq = ntohl(th->ack_seq); | 1626 | TCP_SKB_CB(skb)->ack_seq = ntohl(th->ack_seq); |
1631 | TCP_SKB_CB(skb)->when = 0; | 1627 | TCP_SKB_CB(skb)->tcp_flags = tcp_flag_byte(th); |
1628 | TCP_SKB_CB(skb)->tcp_tw_isn = 0; | ||
1632 | TCP_SKB_CB(skb)->ip_dsfield = ipv4_get_dsfield(iph); | 1629 | TCP_SKB_CB(skb)->ip_dsfield = ipv4_get_dsfield(iph); |
1633 | TCP_SKB_CB(skb)->sacked = 0; | 1630 | TCP_SKB_CB(skb)->sacked = 0; |
1634 | 1631 | ||
@@ -1670,18 +1667,8 @@ process: | |||
1670 | bh_lock_sock_nested(sk); | 1667 | bh_lock_sock_nested(sk); |
1671 | ret = 0; | 1668 | ret = 0; |
1672 | if (!sock_owned_by_user(sk)) { | 1669 | if (!sock_owned_by_user(sk)) { |
1673 | #ifdef CONFIG_NET_DMA | 1670 | if (!tcp_prequeue(sk, skb)) |
1674 | struct tcp_sock *tp = tcp_sk(sk); | ||
1675 | if (!tp->ucopy.dma_chan && tp->ucopy.pinned_list) | ||
1676 | tp->ucopy.dma_chan = net_dma_find_channel(); | ||
1677 | if (tp->ucopy.dma_chan) | ||
1678 | ret = tcp_v4_do_rcv(sk, skb); | 1671 | ret = tcp_v4_do_rcv(sk, skb); |
1679 | else | ||
1680 | #endif | ||
1681 | { | ||
1682 | if (!tcp_prequeue(sk, skb)) | ||
1683 | ret = tcp_v4_do_rcv(sk, skb); | ||
1684 | } | ||
1685 | } else if (unlikely(sk_add_backlog(sk, skb, | 1672 | } else if (unlikely(sk_add_backlog(sk, skb, |
1686 | sk->sk_rcvbuf + sk->sk_sndbuf))) { | 1673 | sk->sk_rcvbuf + sk->sk_sndbuf))) { |
1687 | bh_unlock_sock(sk); | 1674 | bh_unlock_sock(sk); |
@@ -1765,9 +1752,11 @@ void inet_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb) | |||
1765 | { | 1752 | { |
1766 | struct dst_entry *dst = skb_dst(skb); | 1753 | struct dst_entry *dst = skb_dst(skb); |
1767 | 1754 | ||
1768 | dst_hold(dst); | 1755 | if (dst) { |
1769 | sk->sk_rx_dst = dst; | 1756 | dst_hold(dst); |
1770 | inet_sk(sk)->rx_dst_ifindex = skb->skb_iif; | 1757 | sk->sk_rx_dst = dst; |
1758 | inet_sk(sk)->rx_dst_ifindex = skb->skb_iif; | ||
1759 | } | ||
1771 | } | 1760 | } |
1772 | EXPORT_SYMBOL(inet_sk_rx_dst_set); | 1761 | EXPORT_SYMBOL(inet_sk_rx_dst_set); |
1773 | 1762 | ||
@@ -1841,11 +1830,6 @@ void tcp_v4_destroy_sock(struct sock *sk) | |||
1841 | } | 1830 | } |
1842 | #endif | 1831 | #endif |
1843 | 1832 | ||
1844 | #ifdef CONFIG_NET_DMA | ||
1845 | /* Cleans up our sk_async_wait_queue */ | ||
1846 | __skb_queue_purge(&sk->sk_async_wait_queue); | ||
1847 | #endif | ||
1848 | |||
1849 | /* Clean prequeue, it must be empty really */ | 1833 | /* Clean prequeue, it must be empty really */ |
1850 | __skb_queue_purge(&tp->ucopy.prequeue); | 1834 | __skb_queue_purge(&tp->ucopy.prequeue); |
1851 | 1835 | ||
@@ -2183,7 +2167,7 @@ int tcp_seq_open(struct inode *inode, struct file *file) | |||
2183 | 2167 | ||
2184 | s = ((struct seq_file *)file->private_data)->private; | 2168 | s = ((struct seq_file *)file->private_data)->private; |
2185 | s->family = afinfo->family; | 2169 | s->family = afinfo->family; |
2186 | s->last_pos = 0; | 2170 | s->last_pos = 0; |
2187 | return 0; | 2171 | return 0; |
2188 | } | 2172 | } |
2189 | EXPORT_SYMBOL(tcp_seq_open); | 2173 | EXPORT_SYMBOL(tcp_seq_open); |