diff options
author | Eric Dumazet <edumazet@google.com> | 2015-01-30 00:35:05 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2015-02-02 02:06:19 -0500 |
commit | bdbbb8527b6f6a358dbcb70dac247034d665b8e4 (patch) | |
tree | d3c764600d9d7a18956943fcb5c0de8f2e0a6c43 /net/ipv4/tcp_ipv4.c | |
parent | 0d32ef8cef9aa8f375e128f78b77caceaa7e8da0 (diff) |
ipv4: tcp: get rid of ugly unicast_sock
In commit be9f4a44e7d41 ("ipv4: tcp: remove per net tcp_sock")
I tried to address contention on a socket lock, but the solution
I chose was horrible :
commit 3a7c384ffd57e ("ipv4: tcp: unicast_sock should not land outside
of TCP stack") addressed a selinux regression.
commit 0980e56e506b ("ipv4: tcp: set unicast_sock uc_ttl to -1")
took care of another regression.
commit b5ec8eeac46 ("ipv4: fix ip_send_skb()") fixed another regression.
commit 811230cd85 ("tcp: ipv4: initialize unicast_sock sk_pacing_rate")
was another shot in the dark.
Really, just use a proper socket per cpu, and remove the skb_orphan()
call, to re-enable flow control.
This solves a serious problem with FQ packet scheduler when used in
hostile environments, as we do not want to allocate a flow structure
for every RST packet sent in response to a spoofed packet.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4/tcp_ipv4.c')
-rw-r--r-- | net/ipv4/tcp_ipv4.c | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index a3f72d7fc06c..d22f54482bab 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c | |||
@@ -683,7 +683,8 @@ static void tcp_v4_send_reset(struct sock *sk, struct sk_buff *skb) | |||
683 | arg.bound_dev_if = sk->sk_bound_dev_if; | 683 | arg.bound_dev_if = sk->sk_bound_dev_if; |
684 | 684 | ||
685 | arg.tos = ip_hdr(skb)->tos; | 685 | arg.tos = ip_hdr(skb)->tos; |
686 | ip_send_unicast_reply(net, skb, &TCP_SKB_CB(skb)->header.h4.opt, | 686 | ip_send_unicast_reply(*this_cpu_ptr(net->ipv4.tcp_sk), |
687 | skb, &TCP_SKB_CB(skb)->header.h4.opt, | ||
687 | ip_hdr(skb)->saddr, ip_hdr(skb)->daddr, | 688 | ip_hdr(skb)->saddr, ip_hdr(skb)->daddr, |
688 | &arg, arg.iov[0].iov_len); | 689 | &arg, arg.iov[0].iov_len); |
689 | 690 | ||
@@ -767,7 +768,8 @@ static void tcp_v4_send_ack(struct sk_buff *skb, u32 seq, u32 ack, | |||
767 | if (oif) | 768 | if (oif) |
768 | arg.bound_dev_if = oif; | 769 | arg.bound_dev_if = oif; |
769 | arg.tos = tos; | 770 | arg.tos = tos; |
770 | ip_send_unicast_reply(net, skb, &TCP_SKB_CB(skb)->header.h4.opt, | 771 | ip_send_unicast_reply(*this_cpu_ptr(net->ipv4.tcp_sk), |
772 | skb, &TCP_SKB_CB(skb)->header.h4.opt, | ||
771 | ip_hdr(skb)->saddr, ip_hdr(skb)->daddr, | 773 | ip_hdr(skb)->saddr, ip_hdr(skb)->daddr, |
772 | &arg, arg.iov[0].iov_len); | 774 | &arg, arg.iov[0].iov_len); |
773 | 775 | ||
@@ -2428,14 +2430,39 @@ struct proto tcp_prot = { | |||
2428 | }; | 2430 | }; |
2429 | EXPORT_SYMBOL(tcp_prot); | 2431 | EXPORT_SYMBOL(tcp_prot); |
2430 | 2432 | ||
2433 | static void __net_exit tcp_sk_exit(struct net *net) | ||
2434 | { | ||
2435 | int cpu; | ||
2436 | |||
2437 | for_each_possible_cpu(cpu) | ||
2438 | inet_ctl_sock_destroy(*per_cpu_ptr(net->ipv4.tcp_sk, cpu)); | ||
2439 | free_percpu(net->ipv4.tcp_sk); | ||
2440 | } | ||
2441 | |||
2431 | static int __net_init tcp_sk_init(struct net *net) | 2442 | static int __net_init tcp_sk_init(struct net *net) |
2432 | { | 2443 | { |
2444 | int res, cpu; | ||
2445 | |||
2446 | net->ipv4.tcp_sk = alloc_percpu(struct sock *); | ||
2447 | if (!net->ipv4.tcp_sk) | ||
2448 | return -ENOMEM; | ||
2449 | |||
2450 | for_each_possible_cpu(cpu) { | ||
2451 | struct sock *sk; | ||
2452 | |||
2453 | res = inet_ctl_sock_create(&sk, PF_INET, SOCK_RAW, | ||
2454 | IPPROTO_TCP, net); | ||
2455 | if (res) | ||
2456 | goto fail; | ||
2457 | *per_cpu_ptr(net->ipv4.tcp_sk, cpu) = sk; | ||
2458 | } | ||
2433 | net->ipv4.sysctl_tcp_ecn = 2; | 2459 | net->ipv4.sysctl_tcp_ecn = 2; |
2434 | return 0; | 2460 | return 0; |
2435 | } | ||
2436 | 2461 | ||
2437 | static void __net_exit tcp_sk_exit(struct net *net) | 2462 | fail: |
2438 | { | 2463 | tcp_sk_exit(net); |
2464 | |||
2465 | return res; | ||
2439 | } | 2466 | } |
2440 | 2467 | ||
2441 | static void __net_exit tcp_sk_exit_batch(struct list_head *net_exit_list) | 2468 | static void __net_exit tcp_sk_exit_batch(struct list_head *net_exit_list) |