percpu: add __percpu sparse annotations to net
[safe/jmp/linux-2.6] / net / ipv4 / af_inet.c
index d6770f2..33b7dff 100644 (file)
 #include <linux/mroute.h>
 #endif
 
-extern void ip_mc_drop_socket(struct sock *sk);
 
 /* The inetsw table contains everything that inet_create needs to
  * build a new socket.
@@ -125,7 +124,6 @@ static struct list_head inetsw[SOCK_MAX];
 static DEFINE_SPINLOCK(inetsw_lock);
 
 struct ipv4_config ipv4_config;
-
 EXPORT_SYMBOL(ipv4_config);
 
 /* New destruction routine */
@@ -140,12 +138,12 @@ void inet_sock_destruct(struct sock *sk)
        sk_mem_reclaim(sk);
 
        if (sk->sk_type == SOCK_STREAM && sk->sk_state != TCP_CLOSE) {
-               printk("Attempt to release TCP socket in state %d %p\n",
+               pr_err("Attempt to release TCP socket in state %d %p\n",
                       sk->sk_state, sk);
                return;
        }
        if (!sock_flag(sk, SOCK_DEAD)) {
-               printk("Attempt to release alive inet socket %p\n", sk);
+               pr_err("Attempt to release alive inet socket %p\n", sk);
                return;
        }
 
@@ -158,6 +156,7 @@ void inet_sock_destruct(struct sock *sk)
        dst_release(sk->sk_dst_cache);
        sk_refcnt_debug_dec(sk);
 }
+EXPORT_SYMBOL(inet_sock_destruct);
 
 /*
  *     The routines beyond this point handle the behaviour of an AF_INET
@@ -175,12 +174,12 @@ static int inet_autobind(struct sock *sk)
        /* We may need to bind the socket. */
        lock_sock(sk);
        inet = inet_sk(sk);
-       if (!inet->num) {
+       if (!inet->inet_num) {
                if (sk->sk_prot->get_port(sk, 0)) {
                        release_sock(sk);
                        return -EAGAIN;
                }
-               inet->sport = htons(inet->num);
+               inet->inet_sport = htons(inet->inet_num);
        }
        release_sock(sk);
        return 0;
@@ -220,6 +219,7 @@ out:
        release_sock(sk);
        return err;
 }
+EXPORT_SYMBOL(inet_listen);
 
 u32 inet_ehash_secret __read_mostly;
 EXPORT_SYMBOL(inet_ehash_secret);
@@ -244,7 +244,7 @@ EXPORT_SYMBOL(build_ehash_secret);
 static inline int inet_netns_ok(struct net *net, int protocol)
 {
        int hash;
-       struct net_protocol *ipprot;
+       const struct net_protocol *ipprot;
 
        if (net_eq(net, &init_net))
                return 1;
@@ -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 (answer->capability > 0 && !capable(answer->capability))
+       if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
                goto out_rcu_unlock;
 
        err = -EAFNOSUPPORT;
@@ -354,7 +355,7 @@ lookup_protocol:
        inet->is_icsk = (INET_PROTOSW_ICSK & answer_flags) != 0;
 
        if (SOCK_RAW == sock->type) {
-               inet->num = protocol;
+               inet->inet_num = protocol;
                if (IPPROTO_RAW == protocol)
                        inet->hdrincl = 1;
        }
@@ -364,30 +365,30 @@ lookup_protocol:
        else
                inet->pmtudisc = IP_PMTUDISC_WANT;
 
-       inet->id = 0;
+       inet->inet_id = 0;
 
        sock_init_data(sock, sk);
 
        sk->sk_destruct    = inet_sock_destruct;
-       sk->sk_family      = PF_INET;
        sk->sk_protocol    = protocol;
        sk->sk_backlog_rcv = sk->sk_prot->backlog_rcv;
 
        inet->uc_ttl    = -1;
        inet->mc_loop   = 1;
        inet->mc_ttl    = 1;
+       inet->mc_all    = 1;
        inet->mc_index  = 0;
        inet->mc_list   = NULL;
 
        sk_refcnt_debug_inc(sk);
 
-       if (inet->num) {
+       if (inet->inet_num) {
                /* It assumes that any protocol which allows
                 * the user to assign a number at socket
                 * creation time automatically
                 * shares.
                 */
-               inet->sport = htons(inet->num);
+               inet->inet_sport = htons(inet->inet_num);
                /* Add to protocol hash chains. */
                sk->sk_prot->hash(sk);
        }
@@ -436,9 +437,11 @@ int inet_release(struct socket *sock)
        }
        return 0;
 }
+EXPORT_SYMBOL(inet_release);
 
 /* It is off by default, see below. */
 int sysctl_ip_nonlocal_bind __read_mostly;
+EXPORT_SYMBOL(sysctl_ip_nonlocal_bind);
 
 int inet_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
 {
@@ -492,27 +495,27 @@ int inet_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
 
        /* Check these errors (active socket, double bind). */
        err = -EINVAL;
-       if (sk->sk_state != TCP_CLOSE || inet->num)
+       if (sk->sk_state != TCP_CLOSE || inet->inet_num)
                goto out_release_sock;
 
-       inet->rcv_saddr = inet->saddr = addr->sin_addr.s_addr;
+       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
        if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
-               inet->saddr = 0;  /* Use device */
+               inet->inet_saddr = 0;  /* Use device */
 
        /* Make sure we are allowed to bind here. */
        if (sk->sk_prot->get_port(sk, snum)) {
-               inet->saddr = inet->rcv_saddr = 0;
+               inet->inet_saddr = inet->inet_rcv_saddr = 0;
                err = -EADDRINUSE;
                goto out_release_sock;
        }
 
-       if (inet->rcv_saddr)
+       if (inet->inet_rcv_saddr)
                sk->sk_userlocks |= SOCK_BINDADDR_LOCK;
        if (snum)
                sk->sk_userlocks |= SOCK_BINDPORT_LOCK;
-       inet->sport = htons(inet->num);
-       inet->daddr = 0;
-       inet->dport = 0;
+       inet->inet_sport = htons(inet->inet_num);
+       inet->inet_daddr = 0;
+       inet->inet_dport = 0;
        sk_dst_reset(sk);
        err = 0;
 out_release_sock:
@@ -520,6 +523,7 @@ out_release_sock:
 out:
        return err;
 }
+EXPORT_SYMBOL(inet_bind);
 
 int inet_dgram_connect(struct socket *sock, struct sockaddr * uaddr,
                       int addr_len, int flags)
@@ -529,10 +533,11 @@ int inet_dgram_connect(struct socket *sock, struct sockaddr * uaddr,
        if (uaddr->sa_family == AF_UNSPEC)
                return sk->sk_prot->disconnect(sk, flags);
 
-       if (!inet_sk(sk)->num && inet_autobind(sk))
+       if (!inet_sk(sk)->inet_num && inet_autobind(sk))
                return -EAGAIN;
        return sk->sk_prot->connect(sk, (struct sockaddr *)uaddr, addr_len);
 }
+EXPORT_SYMBOL(inet_dgram_connect);
 
 static long inet_wait_for_connect(struct sock *sk, long timeo)
 {
@@ -642,6 +647,7 @@ sock_error:
                sock->state = SS_DISCONNECTING;
        goto out;
 }
+EXPORT_SYMBOL(inet_stream_connect);
 
 /*
  *     Accept a pending connection. The TCP layer now gives BSD semantics.
@@ -669,6 +675,7 @@ int inet_accept(struct socket *sock, struct socket *newsock, int flags)
 do_err:
        return err;
 }
+EXPORT_SYMBOL(inet_accept);
 
 
 /*
@@ -679,27 +686,28 @@ int inet_getname(struct socket *sock, struct sockaddr *uaddr,
 {
        struct sock *sk         = sock->sk;
        struct inet_sock *inet  = inet_sk(sk);
-       struct sockaddr_in *sin = (struct sockaddr_in *)uaddr;
+       DECLARE_SOCKADDR(struct sockaddr_in *, sin, uaddr);
 
        sin->sin_family = AF_INET;
        if (peer) {
-               if (!inet->dport ||
+               if (!inet->inet_dport ||
                    (((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_SYN_SENT)) &&
                     peer == 1))
                        return -ENOTCONN;
-               sin->sin_port = inet->dport;
-               sin->sin_addr.s_addr = inet->daddr;
+               sin->sin_port = inet->inet_dport;
+               sin->sin_addr.s_addr = inet->inet_daddr;
        } else {
-               __be32 addr = inet->rcv_saddr;
+               __be32 addr = inet->inet_rcv_saddr;
                if (!addr)
-                       addr = inet->saddr;
-               sin->sin_port = inet->sport;
+                       addr = inet->inet_saddr;
+               sin->sin_port = inet->inet_sport;
                sin->sin_addr.s_addr = addr;
        }
        memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
        *uaddr_len = sizeof(*sin);
        return 0;
 }
+EXPORT_SYMBOL(inet_getname);
 
 int inet_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg,
                 size_t size)
@@ -707,19 +715,21 @@ int inet_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg,
        struct sock *sk = sock->sk;
 
        /* We may need to bind the socket. */
-       if (!inet_sk(sk)->num && inet_autobind(sk))
+       if (!inet_sk(sk)->inet_num && 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)
+static ssize_t inet_sendpage(struct socket *sock, struct page *page, int offset,
+                            size_t size, int flags)
 {
        struct sock *sk = sock->sk;
 
        /* We may need to bind the socket. */
-       if (!inet_sk(sk)->num && inet_autobind(sk))
+       if (!inet_sk(sk)->inet_num && inet_autobind(sk))
                return -EAGAIN;
 
        if (sk->sk_prot->sendpage)
@@ -781,6 +791,7 @@ int inet_shutdown(struct socket *sock, int how)
        release_sock(sk);
        return err;
 }
+EXPORT_SYMBOL(inet_shutdown);
 
 /*
  *     ioctl() calls you can issue on an INET socket. Most of these are
@@ -799,44 +810,45 @@ int inet_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
        struct net *net = sock_net(sk);
 
        switch (cmd) {
-               case SIOCGSTAMP:
-                       err = sock_get_timestamp(sk, (struct timeval __user *)arg);
-                       break;
-               case SIOCGSTAMPNS:
-                       err = sock_get_timestampns(sk, (struct timespec __user *)arg);
-                       break;
-               case SIOCADDRT:
-               case SIOCDELRT:
-               case SIOCRTMSG:
-                       err = ip_rt_ioctl(net, cmd, (void __user *)arg);
-                       break;
-               case SIOCDARP:
-               case SIOCGARP:
-               case SIOCSARP:
-                       err = arp_ioctl(net, cmd, (void __user *)arg);
-                       break;
-               case SIOCGIFADDR:
-               case SIOCSIFADDR:
-               case SIOCGIFBRDADDR:
-               case SIOCSIFBRDADDR:
-               case SIOCGIFNETMASK:
-               case SIOCSIFNETMASK:
-               case SIOCGIFDSTADDR:
-               case SIOCSIFDSTADDR:
-               case SIOCSIFPFLAGS:
-               case SIOCGIFPFLAGS:
-               case SIOCSIFFLAGS:
-                       err = devinet_ioctl(net, cmd, (void __user *)arg);
-                       break;
-               default:
-                       if (sk->sk_prot->ioctl)
-                               err = sk->sk_prot->ioctl(sk, cmd, arg);
-                       else
-                               err = -ENOIOCTLCMD;
-                       break;
+       case SIOCGSTAMP:
+               err = sock_get_timestamp(sk, (struct timeval __user *)arg);
+               break;
+       case SIOCGSTAMPNS:
+               err = sock_get_timestampns(sk, (struct timespec __user *)arg);
+               break;
+       case SIOCADDRT:
+       case SIOCDELRT:
+       case SIOCRTMSG:
+               err = ip_rt_ioctl(net, cmd, (void __user *)arg);
+               break;
+       case SIOCDARP:
+       case SIOCGARP:
+       case SIOCSARP:
+               err = arp_ioctl(net, cmd, (void __user *)arg);
+               break;
+       case SIOCGIFADDR:
+       case SIOCSIFADDR:
+       case SIOCGIFBRDADDR:
+       case SIOCSIFBRDADDR:
+       case SIOCGIFNETMASK:
+       case SIOCSIFNETMASK:
+       case SIOCGIFDSTADDR:
+       case SIOCSIFDSTADDR:
+       case SIOCSIFPFLAGS:
+       case SIOCGIFPFLAGS:
+       case SIOCSIFFLAGS:
+               err = devinet_ioctl(net, cmd, (void __user *)arg);
+               break;
+       default:
+               if (sk->sk_prot->ioctl)
+                       err = sk->sk_prot->ioctl(sk, cmd, arg);
+               else
+                       err = -ENOIOCTLCMD;
+               break;
        }
        return err;
 }
+EXPORT_SYMBOL(inet_ioctl);
 
 const struct proto_ops inet_stream_ops = {
        .family            = PF_INET,
@@ -863,6 +875,7 @@ const struct proto_ops inet_stream_ops = {
        .compat_getsockopt = compat_sock_common_getsockopt,
 #endif
 };
+EXPORT_SYMBOL(inet_stream_ops);
 
 const struct proto_ops inet_dgram_ops = {
        .family            = PF_INET,
@@ -888,6 +901,7 @@ const struct proto_ops inet_dgram_ops = {
        .compat_getsockopt = compat_sock_common_getsockopt,
 #endif
 };
+EXPORT_SYMBOL(inet_dgram_ops);
 
 /*
  * For SOCK_RAW sockets; should be the same as inet_dgram_ops but without
@@ -918,7 +932,7 @@ static const struct proto_ops inet_sockraw_ops = {
 #endif
 };
 
-static struct net_proto_family inet_family_ops = {
+static const struct net_proto_family inet_family_ops = {
        .family = PF_INET,
        .create = inet_create,
        .owner  = THIS_MODULE,
@@ -934,7 +948,6 @@ static struct inet_protosw inetsw_array[] =
                .protocol =   IPPROTO_TCP,
                .prot =       &tcp_prot,
                .ops =        &inet_stream_ops,
-               .capability = -1,
                .no_check =   0,
                .flags =      INET_PROTOSW_PERMANENT |
                              INET_PROTOSW_ICSK,
@@ -945,7 +958,6 @@ static struct inet_protosw inetsw_array[] =
                .protocol =   IPPROTO_UDP,
                .prot =       &udp_prot,
                .ops =        &inet_dgram_ops,
-               .capability = -1,
                .no_check =   UDP_CSUM_DEFAULT,
                .flags =      INET_PROTOSW_PERMANENT,
        },
@@ -956,7 +968,6 @@ static struct inet_protosw inetsw_array[] =
               .protocol =   IPPROTO_IP,        /* wild card */
               .prot =       &raw_prot,
               .ops =        &inet_sockraw_ops,
-              .capability = CAP_NET_RAW,
               .no_check =   UDP_CSUM_DEFAULT,
               .flags =      INET_PROTOSW_REUSE,
        }
@@ -1004,8 +1015,6 @@ void inet_register_protosw(struct inet_protosw *p)
 out:
        spin_unlock_bh(&inetsw_lock);
 
-       synchronize_net();
-
        return;
 
 out_permanent:
@@ -1019,6 +1028,7 @@ out_illegal:
               p->type);
        goto out;
 }
+EXPORT_SYMBOL(inet_register_protosw);
 
 void inet_unregister_protosw(struct inet_protosw *p)
 {
@@ -1034,6 +1044,7 @@ void inet_unregister_protosw(struct inet_protosw *p)
                synchronize_net();
        }
 }
+EXPORT_SYMBOL(inet_unregister_protosw);
 
 /*
  *      Shall we try to damage output packets if routing dev changes?
@@ -1046,9 +1057,9 @@ 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->saddr;
+       __be32 old_saddr = inet->inet_saddr;
        __be32 new_saddr;
-       __be32 daddr = inet->daddr;
+       __be32 daddr = inet->inet_daddr;
 
        if (inet->opt && inet->opt->srr)
                daddr = inet->opt->faddr;
@@ -1058,7 +1069,7 @@ static int inet_sk_reselect_saddr(struct sock *sk)
                               RT_CONN_FLAGS(sk),
                               sk->sk_bound_dev_if,
                               sk->sk_protocol,
-                              inet->sport, inet->dport, sk, 0);
+                              inet->inet_sport, inet->inet_dport, sk, 0);
        if (err)
                return err;
 
@@ -1074,7 +1085,7 @@ static int inet_sk_reselect_saddr(struct sock *sk)
                       __func__, &old_saddr, &new_saddr);
        }
 
-       inet->saddr = inet->rcv_saddr = new_saddr;
+       inet->inet_saddr = inet->inet_rcv_saddr = new_saddr;
 
        /*
         * XXX The only one ugly spot where we need to
@@ -1100,16 +1111,17 @@ int inet_sk_rebuild_header(struct sock *sk)
                return 0;
 
        /* Reroute. */
-       daddr = inet->daddr;
+       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->saddr,
+                               .saddr  = inet->inet_saddr,
                                .tos    = RT_CONN_FLAGS(sk),
                        },
                },
@@ -1117,8 +1129,8 @@ int inet_sk_rebuild_header(struct sock *sk)
                .flags = inet_sk_flowi_flags(sk),
                .uli_u = {
                        .ports = {
-                               .sport = inet->sport,
-                               .dport = inet->dport,
+                               .sport = inet->inet_sport,
+                               .dport = inet->inet_dport,
                        },
                },
        };
@@ -1144,13 +1156,12 @@ int inet_sk_rebuild_header(struct sock *sk)
 
        return err;
 }
-
 EXPORT_SYMBOL(inet_sk_rebuild_header);
 
 static int inet_gso_send_check(struct sk_buff *skb)
 {
        struct iphdr *iph;
-       struct net_protocol *ops;
+       const struct net_protocol *ops;
        int proto;
        int ihl;
        int err = -EINVAL;
@@ -1186,10 +1197,11 @@ static struct sk_buff *inet_gso_segment(struct sk_buff *skb, int features)
 {
        struct sk_buff *segs = ERR_PTR(-EINVAL);
        struct iphdr *iph;
-       struct net_protocol *ops;
+       const struct net_protocol *ops;
        int proto;
        int ihl;
        int id;
+       unsigned int offset = 0;
 
        if (!(features & NETIF_F_V4_CSUM))
                features &= ~NETIF_F_SG;
@@ -1232,7 +1244,14 @@ static struct sk_buff *inet_gso_segment(struct sk_buff *skb, int features)
        skb = segs;
        do {
                iph = ip_hdr(skb);
-               iph->id = htons(id++);
+               if (proto == IPPROTO_UDP) {
+                       iph->id = htons(id);
+                       iph->frag_off = htons(offset >> 3);
+                       if (skb->next != NULL)
+                               iph->frag_off |= htons(IP_MF);
+                       offset += (skb->len - skb->mac_len - iph->ihl * 4);
+               } else
+                       iph->id = htons(id++);
                iph->tot_len = htons(skb->len - skb->mac_len);
                iph->check = 0;
                iph->check = ip_fast_csum(skb_network_header(skb), iph->ihl);
@@ -1245,17 +1264,24 @@ out:
 static struct sk_buff **inet_gro_receive(struct sk_buff **head,
                                         struct sk_buff *skb)
 {
-       struct net_protocol *ops;
+       const struct net_protocol *ops;
        struct sk_buff **pp = NULL;
        struct sk_buff *p;
        struct iphdr *iph;
+       unsigned int hlen;
+       unsigned int off;
+       unsigned int id;
        int flush = 1;
        int proto;
-       int id;
 
-       iph = skb_gro_header(skb, sizeof(*iph));
-       if (unlikely(!iph))
-               goto out;
+       off = skb_gro_offset(skb);
+       hlen = off + sizeof(*iph);
+       iph = skb_gro_header_fast(skb, off);
+       if (skb_gro_header_hard(skb, hlen)) {
+               iph = skb_gro_header_slow(skb, hlen, off);
+               if (unlikely(!iph))
+                       goto out;
+       }
 
        proto = iph->protocol & (MAX_INET_PROTOS - 1);
 
@@ -1264,15 +1290,15 @@ static struct sk_buff **inet_gro_receive(struct sk_buff **head,
        if (!ops || !ops->gro_receive)
                goto out_unlock;
 
-       if (iph->version != 4 || iph->ihl != 5)
+       if (*(u8 *)iph != 0x45)
                goto out_unlock;
 
        if (unlikely(ip_fast_csum((u8 *)iph, iph->ihl)))
                goto out_unlock;
 
-       flush = ntohs(iph->tot_len) != skb_gro_len(skb) ||
-               iph->frag_off != htons(IP_DF);
-       id = ntohs(iph->id);
+       id = ntohl(*(u32 *)&iph->id);
+       flush = (u16)((ntohl(*(u32 *)iph) ^ skb_gro_len(skb)) | (id ^ IP_DF));
+       id >>= 16;
 
        for (p = *head; p; p = p->next) {
                struct iphdr *iph2;
@@ -1282,17 +1308,18 @@ static struct sk_buff **inet_gro_receive(struct sk_buff **head,
 
                iph2 = ip_hdr(p);
 
-               if (iph->protocol != iph2->protocol ||
-                   iph->tos != iph2->tos ||
-                   memcmp(&iph->saddr, &iph2->saddr, 8)) {
+               if ((iph->protocol ^ iph2->protocol) |
+                   (iph->tos ^ iph2->tos) |
+                   (iph->saddr ^ iph2->saddr) |
+                   (iph->daddr ^ iph2->daddr)) {
                        NAPI_GRO_CB(p)->same_flow = 0;
                        continue;
                }
 
                /* All fields must match except length and checksum. */
                NAPI_GRO_CB(p)->flush |=
-                       memcmp(&iph->frag_off, &iph2->frag_off, 4) ||
-                       (u16)(ntohs(iph2->id) + NAPI_GRO_CB(p)->count) != id;
+                       (iph->ttl ^ iph2->ttl) |
+                       ((u16)(ntohs(iph2->id) + NAPI_GRO_CB(p)->count) ^ id);
 
                NAPI_GRO_CB(p)->flush |= flush;
        }
@@ -1314,7 +1341,7 @@ out:
 
 static int inet_gro_complete(struct sk_buff *skb)
 {
-       struct net_protocol *ops;
+       const struct net_protocol *ops;
        struct iphdr *iph = ip_hdr(skb);
        int proto = iph->protocol & (MAX_INET_PROTOS - 1);
        int err = -ENOSYS;
@@ -1356,10 +1383,9 @@ int inet_ctl_sock_create(struct sock **sk, unsigned short family,
        }
        return rc;
 }
-
 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;
@@ -1372,13 +1398,13 @@ unsigned long snmp_fold_field(void *mib[], int offt)
 }
 EXPORT_SYMBOL_GPL(snmp_fold_field);
 
-int snmp_mib_init(void *ptr[2], size_t mibsize)
+int snmp_mib_init(void __percpu *ptr[2], size_t mibsize)
 {
        BUG_ON(ptr == NULL);
-       ptr[0] = __alloc_percpu(mibsize);
+       ptr[0] = __alloc_percpu(mibsize, __alignof__(unsigned long long));
        if (!ptr[0])
                goto err0;
-       ptr[1] = __alloc_percpu(mibsize);
+       ptr[1] = __alloc_percpu(mibsize, __alignof__(unsigned long long));
        if (!ptr[1])
                goto err1;
        return 0;
@@ -1390,7 +1416,7 @@ err0:
 }
 EXPORT_SYMBOL_GPL(snmp_mib_init);
 
-void snmp_mib_free(void *ptr[2])
+void snmp_mib_free(void __percpu *ptr[2])
 {
        BUG_ON(ptr == NULL);
        free_percpu(ptr[0]);
@@ -1400,13 +1426,13 @@ void snmp_mib_free(void *ptr[2])
 EXPORT_SYMBOL_GPL(snmp_mib_free);
 
 #ifdef CONFIG_IP_MULTICAST
-static struct net_protocol igmp_protocol = {
+static const struct net_protocol igmp_protocol = {
        .handler =      igmp_rcv,
        .netns_ok =     1,
 };
 #endif
 
-static struct net_protocol tcp_protocol = {
+static const struct net_protocol tcp_protocol = {
        .handler =      tcp_v4_rcv,
        .err_handler =  tcp_v4_err,
        .gso_send_check = tcp_v4_gso_send_check,
@@ -1417,14 +1443,16 @@ static struct net_protocol tcp_protocol = {
        .netns_ok =     1,
 };
 
-static struct net_protocol udp_protocol = {
+static const struct net_protocol udp_protocol = {
        .handler =      udp_rcv,
        .err_handler =  udp_err,
+       .gso_send_check = udp4_ufo_send_check,
+       .gso_segment = udp4_ufo_fragment,
        .no_policy =    1,
        .netns_ok =     1,
 };
 
-static struct net_protocol icmp_protocol = {
+static const struct net_protocol icmp_protocol = {
        .handler =      icmp_rcv,
        .no_policy =    1,
        .netns_ok =     1,
@@ -1432,25 +1460,25 @@ static struct net_protocol icmp_protocol = {
 
 static __net_init int ipv4_mib_init_net(struct net *net)
 {
-       if (snmp_mib_init((void **)net->mib.tcp_statistics,
+       if (snmp_mib_init((void __percpu **)net->mib.tcp_statistics,
                          sizeof(struct tcp_mib)) < 0)
                goto err_tcp_mib;
-       if (snmp_mib_init((void **)net->mib.ip_statistics,
+       if (snmp_mib_init((void __percpu **)net->mib.ip_statistics,
                          sizeof(struct ipstats_mib)) < 0)
                goto err_ip_mib;
-       if (snmp_mib_init((void **)net->mib.net_statistics,
+       if (snmp_mib_init((void __percpu **)net->mib.net_statistics,
                          sizeof(struct linux_mib)) < 0)
                goto err_net_mib;
-       if (snmp_mib_init((void **)net->mib.udp_statistics,
+       if (snmp_mib_init((void __percpu **)net->mib.udp_statistics,
                          sizeof(struct udp_mib)) < 0)
                goto err_udp_mib;
-       if (snmp_mib_init((void **)net->mib.udplite_statistics,
+       if (snmp_mib_init((void __percpu **)net->mib.udplite_statistics,
                          sizeof(struct udp_mib)) < 0)
                goto err_udplite_mib;
-       if (snmp_mib_init((void **)net->mib.icmp_statistics,
+       if (snmp_mib_init((void __percpu **)net->mib.icmp_statistics,
                          sizeof(struct icmp_mib)) < 0)
                goto err_icmp_mib;
-       if (snmp_mib_init((void **)net->mib.icmpmsg_statistics,
+       if (snmp_mib_init((void __percpu **)net->mib.icmpmsg_statistics,
                          sizeof(struct icmpmsg_mib)) < 0)
                goto err_icmpmsg_mib;
 
@@ -1458,30 +1486,30 @@ static __net_init int ipv4_mib_init_net(struct net *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 = {
@@ -1500,8 +1528,8 @@ static int ipv4_proc_init(void);
  *     IP protocol layer initialiser
  */
 
-static struct packet_type ip_packet_type = {
-       .type = __constant_htons(ETH_P_IP),
+static struct packet_type ip_packet_type __read_mostly = {
+       .type = cpu_to_be16(ETH_P_IP),
        .func = ip_rcv,
        .gso_send_check = inet_gso_send_check,
        .gso_segment = inet_gso_segment,
@@ -1661,19 +1689,3 @@ static int __init ipv4_proc_init(void)
 
 MODULE_ALIAS_NETPROTO(PF_INET);
 
-EXPORT_SYMBOL(inet_accept);
-EXPORT_SYMBOL(inet_bind);
-EXPORT_SYMBOL(inet_dgram_connect);
-EXPORT_SYMBOL(inet_dgram_ops);
-EXPORT_SYMBOL(inet_getname);
-EXPORT_SYMBOL(inet_ioctl);
-EXPORT_SYMBOL(inet_listen);
-EXPORT_SYMBOL(inet_register_protosw);
-EXPORT_SYMBOL(inet_release);
-EXPORT_SYMBOL(inet_sendmsg);
-EXPORT_SYMBOL(inet_shutdown);
-EXPORT_SYMBOL(inet_sock_destruct);
-EXPORT_SYMBOL(inet_stream_connect);
-EXPORT_SYMBOL(inet_stream_ops);
-EXPORT_SYMBOL(inet_unregister_protosw);
-EXPORT_SYMBOL(sysctl_ip_nonlocal_bind);