net: rfs: enable RFS before first data packet is received
[pandora-kernel.git] / net / ipv4 / af_inet.c
index 807d83c..eae1f67 100644 (file)
 #include <net/tcp.h>
 #include <net/udp.h>
 #include <net/udplite.h>
+#include <net/ping.h>
 #include <linux/skbuff.h>
 #include <net/sock.h>
 #include <net/raw.h>
@@ -153,7 +154,7 @@ void inet_sock_destruct(struct sock *sk)
        WARN_ON(sk->sk_wmem_queued);
        WARN_ON(sk->sk_forward_alloc);
 
-       kfree(inet->opt);
+       kfree(rcu_dereference_protected(inet->inet_opt, 1));
        dst_release(rcu_dereference_check(sk->sk_dst_cache, 1));
        sk_refcnt_debug_dec(sk);
 }
@@ -464,6 +465,9 @@ int inet_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
        if (addr_len < sizeof(struct sockaddr_in))
                goto out;
 
+       if (addr->sin_family != AF_INET)
+               goto out;
+
        chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
 
        /* Not specified by any standard per-se, however it breaks too
@@ -672,6 +676,7 @@ int inet_accept(struct socket *sock, struct socket *newsock, int flags)
 
        lock_sock(sk2);
 
+       sock_rps_record_flow(sk2);
        WARN_ON(!((1 << sk2->sk_state) &
                  (TCPF_ESTABLISHED | TCPF_CLOSE_WAIT | TCPF_CLOSE)));
 
@@ -1008,6 +1013,14 @@ static struct inet_protosw inetsw_array[] =
                .flags =      INET_PROTOSW_PERMANENT,
        },
 
+       {
+               .type =       SOCK_DGRAM,
+               .protocol =   IPPROTO_ICMP,
+               .prot =       &ping_prot,
+               .ops =        &inet_dgram_ops,
+               .no_check =   UDP_CSUM_DEFAULT,
+               .flags =      INET_PROTOSW_REUSE,
+       },
 
        {
               .type =       SOCK_RAW,
@@ -1103,14 +1116,19 @@ static int inet_sk_reselect_saddr(struct sock *sk)
        struct inet_sock *inet = inet_sk(sk);
        __be32 old_saddr = inet->inet_saddr;
        __be32 daddr = inet->inet_daddr;
+       struct flowi4 *fl4;
        struct rtable *rt;
        __be32 new_saddr;
+       struct ip_options_rcu *inet_opt;
 
-       if (inet->opt && inet->opt->srr)
-               daddr = inet->opt->faddr;
+       inet_opt = rcu_dereference_protected(inet->inet_opt,
+                                            sock_owned_by_user(sk));
+       if (inet_opt && inet_opt->opt.srr)
+               daddr = inet_opt->opt.faddr;
 
        /* Query new route. */
-       rt = ip_route_connect(daddr, 0, RT_CONN_FLAGS(sk),
+       fl4 = &inet->cork.fl.u.ip4;
+       rt = ip_route_connect(fl4, daddr, 0, RT_CONN_FLAGS(sk),
                              sk->sk_bound_dev_if, sk->sk_protocol,
                              inet->inet_sport, inet->inet_dport, sk, false);
        if (IS_ERR(rt))
@@ -1118,7 +1136,7 @@ static int inet_sk_reselect_saddr(struct sock *sk)
 
        sk_setup_caps(sk, &rt->dst);
 
-       new_saddr = rt->rt_src;
+       new_saddr = fl4->saddr;
 
        if (new_saddr == old_saddr)
                return 0;
@@ -1147,6 +1165,8 @@ int inet_sk_rebuild_header(struct sock *sk)
        struct inet_sock *inet = inet_sk(sk);
        struct rtable *rt = (struct rtable *)__sk_dst_check(sk, 0);
        __be32 daddr;
+       struct ip_options_rcu *inet_opt;
+       struct flowi4 *fl4;
        int err;
 
        /* Route is OK, nothing to do. */
@@ -1154,10 +1174,14 @@ int inet_sk_rebuild_header(struct sock *sk)
                return 0;
 
        /* Reroute. */
+       rcu_read_lock();
+       inet_opt = rcu_dereference(inet->inet_opt);
        daddr = inet->inet_daddr;
-       if (inet->opt && inet->opt->srr)
-               daddr = inet->opt->faddr;
-       rt = ip_route_output_ports(sock_net(sk), sk, daddr, inet->inet_saddr,
+       if (inet_opt && inet_opt->opt.srr)
+               daddr = inet_opt->opt.faddr;
+       rcu_read_unlock();
+       fl4 = &inet->cork.fl.u.ip4;
+       rt = ip_route_output_ports(sock_net(sk), fl4, sk, daddr, inet->inet_saddr,
                                   inet->inet_dport, inet->inet_sport,
                                   sk->sk_protocol, RT_CONN_FLAGS(sk),
                                   sk->sk_bound_dev_if);
@@ -1186,7 +1210,7 @@ EXPORT_SYMBOL(inet_sk_rebuild_header);
 
 static int inet_gso_send_check(struct sk_buff *skb)
 {
-       struct iphdr *iph;
+       const struct iphdr *iph;
        const struct net_protocol *ops;
        int proto;
        int ihl;
@@ -1293,7 +1317,7 @@ static struct sk_buff **inet_gro_receive(struct sk_buff **head,
        const struct net_protocol *ops;
        struct sk_buff **pp = NULL;
        struct sk_buff *p;
-       struct iphdr *iph;
+       const struct iphdr *iph;
        unsigned int hlen;
        unsigned int off;
        unsigned int id;
@@ -1516,6 +1540,7 @@ static const struct net_protocol udp_protocol = {
 
 static const struct net_protocol icmp_protocol = {
        .handler =      icmp_rcv,
+       .err_handler =  ping_err,
        .no_policy =    1,
        .netns_ok =     1,
 };
@@ -1631,6 +1656,10 @@ static int __init inet_init(void)
        if (rc)
                goto out_unregister_udp_proto;
 
+       rc = proto_register(&ping_prot, 1);
+       if (rc)
+               goto out_unregister_raw_proto;
+
        /*
         *      Tell SOCKET that we are alive...
         */
@@ -1686,6 +1715,8 @@ static int __init inet_init(void)
        /* Add UDP-Lite (RFC 3828) */
        udplite4_register();
 
+       ping_init();
+
        /*
         *      Set the ICMP layer up
         */
@@ -1716,6 +1747,8 @@ static int __init inet_init(void)
        rc = 0;
 out:
        return rc;
+out_unregister_raw_proto:
+       proto_unregister(&raw_prot);
 out_unregister_udp_proto:
        proto_unregister(&udp_prot);
 out_unregister_tcp_proto:
@@ -1740,11 +1773,15 @@ static int __init ipv4_proc_init(void)
                goto out_tcp;
        if (udp4_proc_init())
                goto out_udp;
+       if (ping_proc_init())
+               goto out_ping;
        if (ip_misc_proc_init())
                goto out_misc;
 out:
        return rc;
 out_misc:
+       ping_proc_exit();
+out_ping:
        udp4_proc_exit();
 out_udp:
        tcp4_proc_exit();