Merge branch 'master' of master.kernel.org:/pub/scm/linux/kernel/git/davem/net-2.6
[linux-2.6.git] / net / ipv4 / af_inet.c
index 180ec4c..1b745d4 100644 (file)
@@ -86,6 +86,7 @@
 #include <linux/poll.h>
 #include <linux/netfilter_ipv4.h>
 #include <linux/random.h>
+#include <linux/slab.h>
 
 #include <asm/uaccess.h>
 #include <asm/system.h>
 #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>
@@ -152,8 +154,8 @@ void inet_sock_destruct(struct sock *sk)
        WARN_ON(sk->sk_wmem_queued);
        WARN_ON(sk->sk_forward_alloc);
 
-       kfree(inet->opt);
-       dst_release(sk->sk_dst_cache);
+       kfree(rcu_dereference_protected(inet->inet_opt, 1));
+       dst_release(rcu_dereference_check(sk->sk_dst_cache, 1));
        sk_refcnt_debug_dec(sk);
 }
 EXPORT_SYMBOL(inet_sock_destruct);
@@ -226,18 +228,16 @@ EXPORT_SYMBOL(inet_ehash_secret);
 
 /*
  * inet_ehash_secret must be set exactly once
- * Instead of using a dedicated spinlock, we (ab)use inetsw_lock
  */
 void build_ehash_secret(void)
 {
        u32 rnd;
+
        do {
                get_random_bytes(&rnd, sizeof(rnd));
        } while (rnd == 0);
-       spin_lock_bh(&inetsw_lock);
-       if (!inet_ehash_secret)
-               inet_ehash_secret = rnd;
-       spin_unlock_bh(&inetsw_lock);
+
+       cmpxchg(&inet_ehash_secret, 0, rnd);
 }
 EXPORT_SYMBOL(build_ehash_secret);
 
@@ -262,7 +262,8 @@ static inline int inet_netns_ok(struct net *net, int protocol)
  *     Create an inet socket.
  */
 
-static int inet_create(struct net *net, struct socket *sock, int protocol)
+static int inet_create(struct net *net, struct socket *sock, int protocol,
+                      int kern)
 {
        struct sock *sk;
        struct inet_protosw *answer;
@@ -325,7 +326,7 @@ lookup_protocol:
        }
 
        err = -EPERM;
-       if (sock->type == SOCK_RAW && !capable(CAP_NET_RAW))
+       if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
                goto out_rcu_unlock;
 
        err = -EAFNOSUPPORT;
@@ -353,6 +354,8 @@ lookup_protocol:
        inet = inet_sk(sk);
        inet->is_icsk = (INET_PROTOSW_ICSK & answer_flags) != 0;
 
+       inet->nodefrag = 0;
+
        if (SOCK_RAW == sock->type) {
                inet->inet_num = protocol;
                if (IPPROTO_RAW == protocol)
@@ -417,6 +420,8 @@ int inet_release(struct socket *sock)
        if (sk) {
                long timeout;
 
+               sock_rps_reset_flow(sk);
+
                /* Applications forget to leave groups before exiting */
                ip_mc_drop_socket(sk);
 
@@ -460,6 +465,11 @@ 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) {
+               err = -EAFNOSUPPORT;
+               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
@@ -529,6 +539,8 @@ int inet_dgram_connect(struct socket *sock, struct sockaddr * uaddr,
 {
        struct sock *sk = sock->sk;
 
+       if (addr_len < sizeof(uaddr->sa_family))
+               return -EINVAL;
        if (uaddr->sa_family == AF_UNSPEC)
                return sk->sk_prot->disconnect(sk, flags);
 
@@ -542,7 +554,7 @@ static long inet_wait_for_connect(struct sock *sk, long timeo)
 {
        DEFINE_WAIT(wait);
 
-       prepare_to_wait(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE);
+       prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
 
        /* Basic assumption: if someone sets sk->sk_err, he _must_
         * change state of the socket from TCP_SYN_*.
@@ -555,9 +567,9 @@ static long inet_wait_for_connect(struct sock *sk, long timeo)
                lock_sock(sk);
                if (signal_pending(current) || !timeo)
                        break;
-               prepare_to_wait(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE);
+               prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
        }
-       finish_wait(sk->sk_sleep, &wait);
+       finish_wait(sk_sleep(sk), &wait);
        return timeo;
 }
 
@@ -572,6 +584,9 @@ int inet_stream_connect(struct socket *sock, struct sockaddr *uaddr,
        int err;
        long timeo;
 
+       if (addr_len < sizeof(uaddr->sa_family))
+               return -EINVAL;
+
        lock_sock(sk);
 
        if (uaddr->sa_family == AF_UNSPEC) {
@@ -663,6 +678,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)));
 
@@ -713,29 +729,51 @@ int inet_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg,
 {
        struct sock *sk = sock->sk;
 
+       sock_rps_record_flow(sk);
+
        /* We may need to bind the socket. */
-       if (!inet_sk(sk)->inet_num && inet_autobind(sk))
+       if (!inet_sk(sk)->inet_num && !sk->sk_prot->no_autobind &&
+           inet_autobind(sk))
                return -EAGAIN;
 
        return sk->sk_prot->sendmsg(iocb, sk, msg, size);
 }
 EXPORT_SYMBOL(inet_sendmsg);
 
-
-static ssize_t inet_sendpage(struct socket *sock, struct page *page, int offset,
-                            size_t size, int flags)
+ssize_t inet_sendpage(struct socket *sock, struct page *page, int offset,
+                     size_t size, int flags)
 {
        struct sock *sk = sock->sk;
 
+       sock_rps_record_flow(sk);
+
        /* We may need to bind the socket. */
-       if (!inet_sk(sk)->inet_num && inet_autobind(sk))
+       if (!inet_sk(sk)->inet_num && !sk->sk_prot->no_autobind &&
+           inet_autobind(sk))
                return -EAGAIN;
 
        if (sk->sk_prot->sendpage)
                return sk->sk_prot->sendpage(sk, page, offset, size, flags);
        return sock_no_sendpage(sock, page, offset, size, flags);
 }
+EXPORT_SYMBOL(inet_sendpage);
 
+int inet_recvmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg,
+                size_t size, int flags)
+{
+       struct sock *sk = sock->sk;
+       int addr_len = 0;
+       int err;
+
+       sock_rps_record_flow(sk);
+
+       err = sk->sk_prot->recvmsg(iocb, sk, msg, size, flags & MSG_DONTWAIT,
+                                  flags & ~MSG_DONTWAIT, &addr_len);
+       if (err >= 0)
+               msg->msg_namelen = addr_len;
+       return err;
+}
+EXPORT_SYMBOL(inet_recvmsg);
 
 int inet_shutdown(struct socket *sock, int how)
 {
@@ -849,6 +887,19 @@ int inet_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
 }
 EXPORT_SYMBOL(inet_ioctl);
 
+#ifdef CONFIG_COMPAT
+int inet_compat_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
+{
+       struct sock *sk = sock->sk;
+       int err = -ENOIOCTLCMD;
+
+       if (sk->sk_prot->compat_ioctl)
+               err = sk->sk_prot->compat_ioctl(sk, cmd, arg);
+
+       return err;
+}
+#endif
+
 const struct proto_ops inet_stream_ops = {
        .family            = PF_INET,
        .owner             = THIS_MODULE,
@@ -864,14 +915,15 @@ const struct proto_ops inet_stream_ops = {
        .shutdown          = inet_shutdown,
        .setsockopt        = sock_common_setsockopt,
        .getsockopt        = sock_common_getsockopt,
-       .sendmsg           = tcp_sendmsg,
-       .recvmsg           = sock_common_recvmsg,
+       .sendmsg           = inet_sendmsg,
+       .recvmsg           = inet_recvmsg,
        .mmap              = sock_no_mmap,
-       .sendpage          = tcp_sendpage,
+       .sendpage          = inet_sendpage,
        .splice_read       = tcp_splice_read,
 #ifdef CONFIG_COMPAT
        .compat_setsockopt = compat_sock_common_setsockopt,
        .compat_getsockopt = compat_sock_common_getsockopt,
+       .compat_ioctl      = inet_compat_ioctl,
 #endif
 };
 EXPORT_SYMBOL(inet_stream_ops);
@@ -892,12 +944,13 @@ const struct proto_ops inet_dgram_ops = {
        .setsockopt        = sock_common_setsockopt,
        .getsockopt        = sock_common_getsockopt,
        .sendmsg           = inet_sendmsg,
-       .recvmsg           = sock_common_recvmsg,
+       .recvmsg           = inet_recvmsg,
        .mmap              = sock_no_mmap,
        .sendpage          = inet_sendpage,
 #ifdef CONFIG_COMPAT
        .compat_setsockopt = compat_sock_common_setsockopt,
        .compat_getsockopt = compat_sock_common_getsockopt,
+       .compat_ioctl      = inet_compat_ioctl,
 #endif
 };
 EXPORT_SYMBOL(inet_dgram_ops);
@@ -922,12 +975,13 @@ static const struct proto_ops inet_sockraw_ops = {
        .setsockopt        = sock_common_setsockopt,
        .getsockopt        = sock_common_getsockopt,
        .sendmsg           = inet_sendmsg,
-       .recvmsg           = sock_common_recvmsg,
+       .recvmsg           = inet_recvmsg,
        .mmap              = sock_no_mmap,
        .sendpage          = inet_sendpage,
 #ifdef CONFIG_COMPAT
        .compat_setsockopt = compat_sock_common_setsockopt,
        .compat_getsockopt = compat_sock_common_getsockopt,
+       .compat_ioctl      = inet_compat_ioctl,
 #endif
 };
 
@@ -961,6 +1015,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,
@@ -1054,27 +1116,29 @@ int sysctl_ip_dynaddr __read_mostly;
 static int inet_sk_reselect_saddr(struct sock *sk)
 {
        struct inet_sock *inet = inet_sk(sk);
-       int err;
-       struct rtable *rt;
        __be32 old_saddr = inet->inet_saddr;
-       __be32 new_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. */
-       err = ip_route_connect(&rt, daddr, 0,
-                              RT_CONN_FLAGS(sk),
-                              sk->sk_bound_dev_if,
-                              sk->sk_protocol,
-                              inet->inet_sport, inet->inet_dport, sk, 0);
-       if (err)
-               return err;
+       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))
+               return PTR_ERR(rt);
 
-       sk_setup_caps(sk, &rt->u.dst);
+       sk_setup_caps(sk, &rt->dst);
 
-       new_saddr = rt->rt_src;
+       new_saddr = fl4->saddr;
 
        if (new_saddr == old_saddr)
                return 0;
@@ -1103,6 +1167,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. */
@@ -1110,36 +1176,23 @@ 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;
-{
-       struct flowi fl = {
-               .oif = sk->sk_bound_dev_if,
-               .mark = sk->sk_mark,
-               .nl_u = {
-                       .ip4_u = {
-                               .daddr  = daddr,
-                               .saddr  = inet->inet_saddr,
-                               .tos    = RT_CONN_FLAGS(sk),
-                       },
-               },
-               .proto = sk->sk_protocol,
-               .flags = inet_sk_flowi_flags(sk),
-               .uli_u = {
-                       .ports = {
-                               .sport = inet->inet_sport,
-                               .dport = inet->inet_dport,
-                       },
-               },
-       };
-
-       security_sk_classify_flow(sk, &fl);
-       err = ip_route_output_flow(sock_net(sk), &rt, &fl, sk, 0);
-}
-       if (!err)
-               sk_setup_caps(sk, &rt->u.dst);
-       else {
+       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);
+       if (!IS_ERR(rt)) {
+               err = 0;
+               sk_setup_caps(sk, &rt->dst);
+       } else {
+               err = PTR_ERR(rt);
+
                /* Routing failed... */
                sk->sk_route_caps = 0;
                /*
@@ -1159,7 +1212,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;
@@ -1192,7 +1245,7 @@ out:
        return err;
 }
 
-static struct sk_buff *inet_gso_segment(struct sk_buff *skb, int features)
+static struct sk_buff *inet_gso_segment(struct sk_buff *skb, u32 features)
 {
        struct sk_buff *segs = ERR_PTR(-EINVAL);
        struct iphdr *iph;
@@ -1266,7 +1319,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;
@@ -1295,8 +1348,8 @@ static struct sk_buff **inet_gro_receive(struct sk_buff **head,
        if (unlikely(ip_fast_csum((u8 *)iph, iph->ihl)))
                goto out_unlock;
 
-       id = ntohl(*(u32 *)&iph->id);
-       flush = (u16)((ntohl(*(u32 *)iph) ^ skb_gro_len(skb)) | (id ^ IP_DF));
+       id = ntohl(*(__be32 *)&iph->id);
+       flush = (u16)((ntohl(*(__be32 *)iph) ^ skb_gro_len(skb)) | (id ^ IP_DF));
        id >>= 16;
 
        for (p = *head; p; p = p->next) {
@@ -1309,8 +1362,8 @@ static struct sk_buff **inet_gro_receive(struct sk_buff **head,
 
                if ((iph->protocol ^ iph2->protocol) |
                    (iph->tos ^ iph2->tos) |
-                   (iph->saddr ^ iph2->saddr) |
-                   (iph->daddr ^ iph2->daddr)) {
+                   ((__force u32)iph->saddr ^ (__force u32)iph2->saddr) |
+                   ((__force u32)iph->daddr ^ (__force u32)iph2->daddr)) {
                        NAPI_GRO_CB(p)->same_flow = 0;
                        continue;
                }
@@ -1384,43 +1437,73 @@ int inet_ctl_sock_create(struct sock **sk, unsigned short family,
 }
 EXPORT_SYMBOL_GPL(inet_ctl_sock_create);
 
-unsigned long snmp_fold_field(void *mib[], int offt)
+unsigned long snmp_fold_field(void __percpu *mib[], int offt)
 {
        unsigned long res = 0;
-       int i;
+       int i, j;
 
        for_each_possible_cpu(i) {
-               res += *(((unsigned long *) per_cpu_ptr(mib[0], i)) + offt);
-               res += *(((unsigned long *) per_cpu_ptr(mib[1], i)) + offt);
+               for (j = 0; j < SNMP_ARRAY_SZ; j++)
+                       res += *(((unsigned long *) per_cpu_ptr(mib[j], i)) + offt);
        }
        return res;
 }
 EXPORT_SYMBOL_GPL(snmp_fold_field);
 
-int snmp_mib_init(void *ptr[2], size_t mibsize)
+#if BITS_PER_LONG==32
+
+u64 snmp_fold_field64(void __percpu *mib[], int offt, size_t syncp_offset)
+{
+       u64 res = 0;
+       int cpu;
+
+       for_each_possible_cpu(cpu) {
+               void *bhptr;
+               struct u64_stats_sync *syncp;
+               u64 v;
+               unsigned int start;
+
+               bhptr = per_cpu_ptr(mib[0], cpu);
+               syncp = (struct u64_stats_sync *)(bhptr + syncp_offset);
+               do {
+                       start = u64_stats_fetch_begin_bh(syncp);
+                       v = *(((u64 *) bhptr) + offt);
+               } while (u64_stats_fetch_retry_bh(syncp, start));
+
+               res += v;
+       }
+       return res;
+}
+EXPORT_SYMBOL_GPL(snmp_fold_field64);
+#endif
+
+int snmp_mib_init(void __percpu *ptr[2], size_t mibsize, size_t align)
 {
        BUG_ON(ptr == NULL);
-       ptr[0] = __alloc_percpu(mibsize, __alignof__(unsigned long long));
+       ptr[0] = __alloc_percpu(mibsize, align);
        if (!ptr[0])
-               goto err0;
-       ptr[1] = __alloc_percpu(mibsize, __alignof__(unsigned long long));
-       if (!ptr[1])
-               goto err1;
+               return -ENOMEM;
+#if SNMP_ARRAY_SZ == 2
+       ptr[1] = __alloc_percpu(mibsize, align);
+       if (!ptr[1]) {
+               free_percpu(ptr[0]);
+               ptr[0] = NULL;
+               return -ENOMEM;
+       }
+#endif
        return 0;
-err1:
-       free_percpu(ptr[0]);
-       ptr[0] = NULL;
-err0:
-       return -ENOMEM;
 }
 EXPORT_SYMBOL_GPL(snmp_mib_init);
 
-void snmp_mib_free(void *ptr[2])
+void snmp_mib_free(void __percpu *ptr[SNMP_ARRAY_SZ])
 {
+       int i;
+
        BUG_ON(ptr == NULL);
-       free_percpu(ptr[0]);
-       free_percpu(ptr[1]);
-       ptr[0] = ptr[1] = NULL;
+       for (i = 0; i < SNMP_ARRAY_SZ; i++) {
+               free_percpu(ptr[i]);
+               ptr[i] = NULL;
+       }
 }
 EXPORT_SYMBOL_GPL(snmp_mib_free);
 
@@ -1453,62 +1536,70 @@ 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,
 };
 
 static __net_init int ipv4_mib_init_net(struct net *net)
 {
-       if (snmp_mib_init((void **)net->mib.tcp_statistics,
-                         sizeof(struct tcp_mib)) < 0)
+       if (snmp_mib_init((void __percpu **)net->mib.tcp_statistics,
+                         sizeof(struct tcp_mib),
+                         __alignof__(struct tcp_mib)) < 0)
                goto err_tcp_mib;
-       if (snmp_mib_init((void **)net->mib.ip_statistics,
-                         sizeof(struct ipstats_mib)) < 0)
+       if (snmp_mib_init((void __percpu **)net->mib.ip_statistics,
+                         sizeof(struct ipstats_mib),
+                         __alignof__(struct ipstats_mib)) < 0)
                goto err_ip_mib;
-       if (snmp_mib_init((void **)net->mib.net_statistics,
-                         sizeof(struct linux_mib)) < 0)
+       if (snmp_mib_init((void __percpu **)net->mib.net_statistics,
+                         sizeof(struct linux_mib),
+                         __alignof__(struct linux_mib)) < 0)
                goto err_net_mib;
-       if (snmp_mib_init((void **)net->mib.udp_statistics,
-                         sizeof(struct udp_mib)) < 0)
+       if (snmp_mib_init((void __percpu **)net->mib.udp_statistics,
+                         sizeof(struct udp_mib),
+                         __alignof__(struct udp_mib)) < 0)
                goto err_udp_mib;
-       if (snmp_mib_init((void **)net->mib.udplite_statistics,
-                         sizeof(struct udp_mib)) < 0)
+       if (snmp_mib_init((void __percpu **)net->mib.udplite_statistics,
+                         sizeof(struct udp_mib),
+                         __alignof__(struct udp_mib)) < 0)
                goto err_udplite_mib;
-       if (snmp_mib_init((void **)net->mib.icmp_statistics,
-                         sizeof(struct icmp_mib)) < 0)
+       if (snmp_mib_init((void __percpu **)net->mib.icmp_statistics,
+                         sizeof(struct icmp_mib),
+                         __alignof__(struct icmp_mib)) < 0)
                goto err_icmp_mib;
-       if (snmp_mib_init((void **)net->mib.icmpmsg_statistics,
-                         sizeof(struct icmpmsg_mib)) < 0)
+       if (snmp_mib_init((void __percpu **)net->mib.icmpmsg_statistics,
+                         sizeof(struct icmpmsg_mib),
+                         __alignof__(struct icmpmsg_mib)) < 0)
                goto err_icmpmsg_mib;
 
        tcp_mib_init(net);
        return 0;
 
 err_icmpmsg_mib:
-       snmp_mib_free((void **)net->mib.icmp_statistics);
+       snmp_mib_free((void __percpu **)net->mib.icmp_statistics);
 err_icmp_mib:
-       snmp_mib_free((void **)net->mib.udplite_statistics);
+       snmp_mib_free((void __percpu **)net->mib.udplite_statistics);
 err_udplite_mib:
-       snmp_mib_free((void **)net->mib.udp_statistics);
+       snmp_mib_free((void __percpu **)net->mib.udp_statistics);
 err_udp_mib:
-       snmp_mib_free((void **)net->mib.net_statistics);
+       snmp_mib_free((void __percpu **)net->mib.net_statistics);
 err_net_mib:
-       snmp_mib_free((void **)net->mib.ip_statistics);
+       snmp_mib_free((void __percpu **)net->mib.ip_statistics);
 err_ip_mib:
-       snmp_mib_free((void **)net->mib.tcp_statistics);
+       snmp_mib_free((void __percpu **)net->mib.tcp_statistics);
 err_tcp_mib:
        return -ENOMEM;
 }
 
 static __net_exit void ipv4_mib_exit_net(struct net *net)
 {
-       snmp_mib_free((void **)net->mib.icmpmsg_statistics);
-       snmp_mib_free((void **)net->mib.icmp_statistics);
-       snmp_mib_free((void **)net->mib.udplite_statistics);
-       snmp_mib_free((void **)net->mib.udp_statistics);
-       snmp_mib_free((void **)net->mib.net_statistics);
-       snmp_mib_free((void **)net->mib.ip_statistics);
-       snmp_mib_free((void **)net->mib.tcp_statistics);
+       snmp_mib_free((void __percpu **)net->mib.icmpmsg_statistics);
+       snmp_mib_free((void __percpu **)net->mib.icmp_statistics);
+       snmp_mib_free((void __percpu **)net->mib.udplite_statistics);
+       snmp_mib_free((void __percpu **)net->mib.udp_statistics);
+       snmp_mib_free((void __percpu **)net->mib.net_statistics);
+       snmp_mib_free((void __percpu **)net->mib.ip_statistics);
+       snmp_mib_free((void __percpu **)net->mib.tcp_statistics);
 }
 
 static __net_initdata struct pernet_operations ipv4_mib_ops = {
@@ -1545,9 +1636,13 @@ static int __init inet_init(void)
 
        BUILD_BUG_ON(sizeof(struct inet_skb_parm) > sizeof(dummy_skb->cb));
 
+       sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
+       if (!sysctl_local_reserved_ports)
+               goto out;
+
        rc = proto_register(&tcp_prot, 1);
        if (rc)
-               goto out;
+               goto out_free_reserved_ports;
 
        rc = proto_register(&udp_prot, 1);
        if (rc)
@@ -1557,6 +1652,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...
         */
@@ -1612,6 +1711,8 @@ static int __init inet_init(void)
        /* Add UDP-Lite (RFC 3828) */
        udplite4_register();
 
+       ping_init();
+
        /*
         *      Set the ICMP layer up
         */
@@ -1642,10 +1743,14 @@ 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:
        proto_unregister(&tcp_prot);
+out_free_reserved_ports:
+       kfree(sysctl_local_reserved_ports);
        goto out;
 }
 
@@ -1664,11 +1769,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();