[NET]: Remove unused "mibalign" argument for snmp_mib_init().
[safe/jmp/linux-2.6] / net / ipv4 / af_inet.c
index 658e797..7f8b27f 100644 (file)
@@ -67,7 +67,7 @@
  *             2 of the License, or (at your option) any later version.
  */
 
-#include <linux/config.h>
+#include <linux/err.h>
 #include <linux/errno.h>
 #include <linux/types.h>
 #include <linux/socket.h>
@@ -79,6 +79,7 @@
 #include <linux/string.h>
 #include <linux/sockios.h>
 #include <linux/net.h>
+#include <linux/capability.h>
 #include <linux/fcntl.h>
 #include <linux/mm.h>
 #include <linux/interrupt.h>
 #include <linux/init.h>
 #include <linux/poll.h>
 #include <linux/netfilter_ipv4.h>
+#include <linux/random.h>
 
 #include <asm/uaccess.h>
 #include <asm/system.h>
 
-#include <linux/smp_lock.h>
 #include <linux/inet.h>
 #include <linux/igmp.h>
+#include <linux/inetdevice.h>
 #include <linux/netdevice.h>
 #include <net/ip.h>
 #include <net/protocol.h>
 #include <net/arp.h>
 #include <net/route.h>
 #include <net/ip_fib.h>
+#include <net/inet_connection_sock.h>
 #include <net/tcp.h>
 #include <net/udp.h>
+#include <net/udplite.h>
 #include <linux/skbuff.h>
 #include <net/sock.h>
 #include <net/raw.h>
 #include <linux/mroute.h>
 #endif
 
-DEFINE_SNMP_STAT(struct linux_mib, net_statistics);
-
-#ifdef INET_REFCNT_DEBUG
-atomic_t inet_sock_nr;
-#endif
+DEFINE_SNMP_STAT(struct linux_mib, net_statistics) __read_mostly;
 
 extern void ip_mc_drop_socket(struct sock *sk);
 
@@ -126,6 +126,10 @@ extern void ip_mc_drop_socket(struct sock *sk);
 static struct list_head inetsw[SOCK_MAX];
 static DEFINE_SPINLOCK(inetsw_lock);
 
+struct ipv4_config ipv4_config;
+
+EXPORT_SYMBOL(ipv4_config);
+
 /* New destruction routine */
 
 void inet_sock_destruct(struct sock *sk)
@@ -150,14 +154,9 @@ void inet_sock_destruct(struct sock *sk)
        BUG_TRAP(!sk->sk_wmem_queued);
        BUG_TRAP(!sk->sk_forward_alloc);
 
-       if (inet->opt)
-               kfree(inet->opt);
+       kfree(inet->opt);
        dst_release(sk->sk_dst_cache);
-#ifdef INET_REFCNT_DEBUG
-       atomic_dec(&inet_sock_nr);
-       printk(KERN_DEBUG "INET socket %p released, %d are still alive\n",
-              sk, atomic_read(&inet_sock_nr));
-#endif
+       sk_refcnt_debug_dec(sk);
 }
 
 /*
@@ -210,7 +209,7 @@ int inet_listen(struct socket *sock, int backlog)
         * we can only allow the backlog to be adjusted.
         */
        if (old_state != TCP_LISTEN) {
-               err = tcp_listen_start(sk);
+               err = inet_csk_listen_start(sk, backlog);
                if (err)
                        goto out;
        }
@@ -222,11 +221,31 @@ out:
        return err;
 }
 
+u32 inet_ehash_secret __read_mostly;
+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);
+}
+EXPORT_SYMBOL(build_ehash_secret);
+
 /*
  *     Create an inet socket.
  */
 
-static int inet_create(struct socket *sock, int protocol)
+static int inet_create(struct net *net, struct socket *sock, int protocol)
 {
        struct sock *sk;
        struct list_head *p;
@@ -235,12 +254,23 @@ static int inet_create(struct socket *sock, int protocol)
        struct proto *answer_prot;
        unsigned char answer_flags;
        char answer_no_check;
+       int try_loading_module = 0;
        int err;
 
+       if (net != &init_net)
+               return -EAFNOSUPPORT;
+
+       if (sock->type != SOCK_RAW &&
+           sock->type != SOCK_DGRAM &&
+           !inet_ehash_secret)
+               build_ehash_secret();
+
        sock->state = SS_UNCONNECTED;
 
        /* Look for the requested type/protocol pair. */
        answer = NULL;
+lookup_protocol:
+       err = -ESOCKTNOSUPPORT;
        rcu_read_lock();
        list_for_each_rcu(p, &inetsw[sock->type]) {
                answer = list_entry(p, struct inet_protosw, list);
@@ -258,18 +288,35 @@ static int inet_create(struct socket *sock, int protocol)
                        if (IPPROTO_IP == answer->protocol)
                                break;
                }
+               err = -EPROTONOSUPPORT;
                answer = NULL;
        }
 
-       err = -ESOCKTNOSUPPORT;
-       if (!answer)
-               goto out_rcu_unlock;
+       if (unlikely(answer == NULL)) {
+               if (try_loading_module < 2) {
+                       rcu_read_unlock();
+                       /*
+                        * Be more specific, e.g. net-pf-2-proto-132-type-1
+                        * (net-pf-PF_INET-proto-IPPROTO_SCTP-type-SOCK_STREAM)
+                        */
+                       if (++try_loading_module == 1)
+                               request_module("net-pf-%d-proto-%d-type-%d",
+                                              PF_INET, protocol, sock->type);
+                       /*
+                        * Fall back to generic, e.g. net-pf-2-proto-132
+                        * (net-pf-PF_INET-proto-IPPROTO_SCTP)
+                        */
+                       else
+                               request_module("net-pf-%d-proto-%d",
+                                              PF_INET, protocol);
+                       goto lookup_protocol;
+               } else
+                       goto out_rcu_unlock;
+       }
+
        err = -EPERM;
        if (answer->capability > 0 && !capable(answer->capability))
                goto out_rcu_unlock;
-       err = -EPROTONOSUPPORT;
-       if (!protocol)
-               goto out_rcu_unlock;
 
        sock->ops = answer->ops;
        answer_prot = answer->prot;
@@ -280,7 +327,7 @@ static int inet_create(struct socket *sock, int protocol)
        BUG_TRAP(answer_prot->slab != NULL);
 
        err = -ENOBUFS;
-       sk = sk_alloc(PF_INET, GFP_KERNEL, answer_prot, 1);
+       sk = sk_alloc(net, PF_INET, GFP_KERNEL, answer_prot);
        if (sk == NULL)
                goto out;
 
@@ -290,6 +337,7 @@ static int inet_create(struct socket *sock, int protocol)
                sk->sk_reuse = 1;
 
        inet = inet_sk(sk);
+       inet->is_icsk = (INET_PROTOSW_ICSK & answer_flags) != 0;
 
        if (SOCK_RAW == sock->type) {
                inet->num = protocol;
@@ -317,9 +365,7 @@ static int inet_create(struct socket *sock, int protocol)
        inet->mc_index  = 0;
        inet->mc_list   = NULL;
 
-#ifdef INET_REFCNT_DEBUG
-       atomic_inc(&inet_sock_nr);
-#endif
+       sk_refcnt_debug_inc(sk);
 
        if (inet->num) {
                /* It assumes that any protocol which allows
@@ -378,7 +424,7 @@ int inet_release(struct socket *sock)
 }
 
 /* It is off by default, see below. */
-int sysctl_ip_nonlocal_bind;
+int sysctl_ip_nonlocal_bind __read_mostly;
 
 int inet_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
 {
@@ -536,7 +582,7 @@ int inet_stream_connect(struct socket *sock, struct sockaddr *uaddr,
                if (err < 0)
                        goto out;
 
-               sock->state = SS_CONNECTING;
+               sock->state = SS_CONNECTING;
 
                /* Just entered SS_CONNECTING state; the only
                 * difference is that return value in non-blocking
@@ -630,7 +676,7 @@ int inet_getname(struct socket *sock, struct sockaddr *uaddr,
                sin->sin_port = inet->dport;
                sin->sin_addr.s_addr = inet->daddr;
        } else {
-               __u32 addr = inet->rcv_saddr;
+               __be32 addr = inet->rcv_saddr;
                if (!addr)
                        addr = inet->saddr;
                sin->sin_port = inet->sport;
@@ -741,6 +787,9 @@ int inet_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
                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:
@@ -765,80 +814,93 @@ int inet_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
                        err = devinet_ioctl(cmd, (void __user *)arg);
                        break;
                default:
-                       if (!sk->sk_prot->ioctl ||
-                           (err = sk->sk_prot->ioctl(sk, cmd, arg)) ==
-                                                               -ENOIOCTLCMD)
-                               err = dev_ioctl(cmd, (void __user *)arg);
+                       if (sk->sk_prot->ioctl)
+                               err = sk->sk_prot->ioctl(sk, cmd, arg);
+                       else
+                               err = -ENOIOCTLCMD;
                        break;
        }
        return err;
 }
 
-struct proto_ops inet_stream_ops = {
-       .family =       PF_INET,
-       .owner =        THIS_MODULE,
-       .release =      inet_release,
-       .bind =         inet_bind,
-       .connect =      inet_stream_connect,
-       .socketpair =   sock_no_socketpair,
-       .accept =       inet_accept,
-       .getname =      inet_getname,
-       .poll =         tcp_poll,
-       .ioctl =        inet_ioctl,
-       .listen =       inet_listen,
-       .shutdown =     inet_shutdown,
-       .setsockopt =   sock_common_setsockopt,
-       .getsockopt =   sock_common_getsockopt,
-       .sendmsg =      inet_sendmsg,
-       .recvmsg =      sock_common_recvmsg,
-       .mmap =         sock_no_mmap,
-       .sendpage =     tcp_sendpage
+const struct proto_ops inet_stream_ops = {
+       .family            = PF_INET,
+       .owner             = THIS_MODULE,
+       .release           = inet_release,
+       .bind              = inet_bind,
+       .connect           = inet_stream_connect,
+       .socketpair        = sock_no_socketpair,
+       .accept            = inet_accept,
+       .getname           = inet_getname,
+       .poll              = tcp_poll,
+       .ioctl             = inet_ioctl,
+       .listen            = inet_listen,
+       .shutdown          = inet_shutdown,
+       .setsockopt        = sock_common_setsockopt,
+       .getsockopt        = sock_common_getsockopt,
+       .sendmsg           = tcp_sendmsg,
+       .recvmsg           = sock_common_recvmsg,
+       .mmap              = sock_no_mmap,
+       .sendpage          = tcp_sendpage,
+       .splice_read       = tcp_splice_read,
+#ifdef CONFIG_COMPAT
+       .compat_setsockopt = compat_sock_common_setsockopt,
+       .compat_getsockopt = compat_sock_common_getsockopt,
+#endif
 };
 
-struct proto_ops inet_dgram_ops = {
-       .family =       PF_INET,
-       .owner =        THIS_MODULE,
-       .release =      inet_release,
-       .bind =         inet_bind,
-       .connect =      inet_dgram_connect,
-       .socketpair =   sock_no_socketpair,
-       .accept =       sock_no_accept,
-       .getname =      inet_getname,
-       .poll =         udp_poll,
-       .ioctl =        inet_ioctl,
-       .listen =       sock_no_listen,
-       .shutdown =     inet_shutdown,
-       .setsockopt =   sock_common_setsockopt,
-       .getsockopt =   sock_common_getsockopt,
-       .sendmsg =      inet_sendmsg,
-       .recvmsg =      sock_common_recvmsg,
-       .mmap =         sock_no_mmap,
-       .sendpage =     inet_sendpage,
+const struct proto_ops inet_dgram_ops = {
+       .family            = PF_INET,
+       .owner             = THIS_MODULE,
+       .release           = inet_release,
+       .bind              = inet_bind,
+       .connect           = inet_dgram_connect,
+       .socketpair        = sock_no_socketpair,
+       .accept            = sock_no_accept,
+       .getname           = inet_getname,
+       .poll              = udp_poll,
+       .ioctl             = inet_ioctl,
+       .listen            = sock_no_listen,
+       .shutdown          = inet_shutdown,
+       .setsockopt        = sock_common_setsockopt,
+       .getsockopt        = sock_common_getsockopt,
+       .sendmsg           = inet_sendmsg,
+       .recvmsg           = sock_common_recvmsg,
+       .mmap              = sock_no_mmap,
+       .sendpage          = inet_sendpage,
+#ifdef CONFIG_COMPAT
+       .compat_setsockopt = compat_sock_common_setsockopt,
+       .compat_getsockopt = compat_sock_common_getsockopt,
+#endif
 };
 
 /*
  * For SOCK_RAW sockets; should be the same as inet_dgram_ops but without
  * udp_poll
  */
-static struct proto_ops inet_sockraw_ops = {
-       .family =       PF_INET,
-       .owner =        THIS_MODULE,
-       .release =      inet_release,
-       .bind =         inet_bind,
-       .connect =      inet_dgram_connect,
-       .socketpair =   sock_no_socketpair,
-       .accept =       sock_no_accept,
-       .getname =      inet_getname,
-       .poll =         datagram_poll,
-       .ioctl =        inet_ioctl,
-       .listen =       sock_no_listen,
-       .shutdown =     inet_shutdown,
-       .setsockopt =   sock_common_setsockopt,
-       .getsockopt =   sock_common_getsockopt,
-       .sendmsg =      inet_sendmsg,
-       .recvmsg =      sock_common_recvmsg,
-       .mmap =         sock_no_mmap,
-       .sendpage =     inet_sendpage,
+static const struct proto_ops inet_sockraw_ops = {
+       .family            = PF_INET,
+       .owner             = THIS_MODULE,
+       .release           = inet_release,
+       .bind              = inet_bind,
+       .connect           = inet_dgram_connect,
+       .socketpair        = sock_no_socketpair,
+       .accept            = sock_no_accept,
+       .getname           = inet_getname,
+       .poll              = datagram_poll,
+       .ioctl             = inet_ioctl,
+       .listen            = sock_no_listen,
+       .shutdown          = inet_shutdown,
+       .setsockopt        = sock_common_setsockopt,
+       .getsockopt        = sock_common_getsockopt,
+       .sendmsg           = inet_sendmsg,
+       .recvmsg           = sock_common_recvmsg,
+       .mmap              = sock_no_mmap,
+       .sendpage          = inet_sendpage,
+#ifdef CONFIG_COMPAT
+       .compat_setsockopt = compat_sock_common_setsockopt,
+       .compat_getsockopt = compat_sock_common_getsockopt,
+#endif
 };
 
 static struct net_proto_family inet_family_ops = {
@@ -847,48 +909,45 @@ static struct net_proto_family inet_family_ops = {
        .owner  = THIS_MODULE,
 };
 
-
-extern void tcp_init(void);
-extern void tcp_v4_init(struct net_proto_family *);
-
 /* Upon startup we insert all the elements in inetsw_array[] into
  * the linked list inetsw.
  */
 static struct inet_protosw inetsw_array[] =
 {
-        {
-                .type =       SOCK_STREAM,
-                .protocol =   IPPROTO_TCP,
-                .prot =       &tcp_prot,
-                .ops =        &inet_stream_ops,
-                .capability = -1,
-                .no_check =   0,
-                .flags =      INET_PROTOSW_PERMANENT,
-        },
-
-        {
-                .type =       SOCK_DGRAM,
-                .protocol =   IPPROTO_UDP,
-                .prot =       &udp_prot,
-                .ops =        &inet_dgram_ops,
-                .capability = -1,
-                .no_check =   UDP_CSUM_DEFAULT,
-                .flags =      INET_PROTOSW_PERMANENT,
+       {
+               .type =       SOCK_STREAM,
+               .protocol =   IPPROTO_TCP,
+               .prot =       &tcp_prot,
+               .ops =        &inet_stream_ops,
+               .capability = -1,
+               .no_check =   0,
+               .flags =      INET_PROTOSW_PERMANENT |
+                             INET_PROTOSW_ICSK,
+       },
+
+       {
+               .type =       SOCK_DGRAM,
+               .protocol =   IPPROTO_UDP,
+               .prot =       &udp_prot,
+               .ops =        &inet_dgram_ops,
+               .capability = -1,
+               .no_check =   UDP_CSUM_DEFAULT,
+               .flags =      INET_PROTOSW_PERMANENT,
        },
-        
+
 
        {
-               .type =       SOCK_RAW,
-               .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,
+              .type =       SOCK_RAW,
+              .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,
        }
 };
 
-#define INETSW_ARRAY_LEN (sizeof(inetsw_array) / sizeof(struct inet_protosw))
+#define INETSW_ARRAY_LEN ARRAY_SIZE(inetsw_array)
 
 void inet_register_protosw(struct inet_protosw *p)
 {
@@ -923,7 +982,7 @@ void inet_register_protosw(struct inet_protosw *p)
        /* Add the new entry after the last permanent entry if any, so that
         * the new entry does not override a permanent entry when matched with
         * a wild-card protocol. But it is allowed to override any existing
-        * non-permanent entry.  This means that when we remove this entry, the 
+        * non-permanent entry.  This means that when we remove this entry, the
         * system automatically returns to the old behavior.
         */
        list_add_rcu(&p->list, last_perm);
@@ -961,6 +1020,255 @@ void inet_unregister_protosw(struct inet_protosw *p)
        }
 }
 
+/*
+ *      Shall we try to damage output packets if routing dev changes?
+ */
+
+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->saddr;
+       __be32 new_saddr;
+       __be32 daddr = inet->daddr;
+
+       if (inet->opt && inet->opt->srr)
+               daddr = inet->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->sport, inet->dport, sk, 0);
+       if (err)
+               return err;
+
+       sk_setup_caps(sk, &rt->u.dst);
+
+       new_saddr = rt->rt_src;
+
+       if (new_saddr == old_saddr)
+               return 0;
+
+       if (sysctl_ip_dynaddr > 1) {
+               printk(KERN_INFO "%s(): shifting inet->"
+                                "saddr from %d.%d.%d.%d to %d.%d.%d.%d\n",
+                      __FUNCTION__,
+                      NIPQUAD(old_saddr),
+                      NIPQUAD(new_saddr));
+       }
+
+       inet->saddr = inet->rcv_saddr = new_saddr;
+
+       /*
+        * XXX The only one ugly spot where we need to
+        * XXX really change the sockets identity after
+        * XXX it has entered the hashes. -DaveM
+        *
+        * Besides that, it does not check for connection
+        * uniqueness. Wait for troubles.
+        */
+       __sk_prot_rehash(sk);
+       return 0;
+}
+
+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;
+       int err;
+
+       /* Route is OK, nothing to do. */
+       if (rt)
+               return 0;
+
+       /* Reroute. */
+       daddr = inet->daddr;
+       if (inet->opt && inet->opt->srr)
+               daddr = inet->opt->faddr;
+{
+       struct flowi fl = {
+               .oif = sk->sk_bound_dev_if,
+               .nl_u = {
+                       .ip4_u = {
+                               .daddr  = daddr,
+                               .saddr  = inet->saddr,
+                               .tos    = RT_CONN_FLAGS(sk),
+                       },
+               },
+               .proto = sk->sk_protocol,
+               .uli_u = {
+                       .ports = {
+                               .sport = inet->sport,
+                               .dport = inet->dport,
+                       },
+               },
+       };
+
+       security_sk_classify_flow(sk, &fl);
+       err = ip_route_output_flow(&rt, &fl, sk, 0);
+}
+       if (!err)
+               sk_setup_caps(sk, &rt->u.dst);
+       else {
+               /* Routing failed... */
+               sk->sk_route_caps = 0;
+               /*
+                * Other protocols have to map its equivalent state to TCP_SYN_SENT.
+                * DCCP maps its DCCP_REQUESTING state to TCP_SYN_SENT. -acme
+                */
+               if (!sysctl_ip_dynaddr ||
+                   sk->sk_state != TCP_SYN_SENT ||
+                   (sk->sk_userlocks & SOCK_BINDADDR_LOCK) ||
+                   (err = inet_sk_reselect_saddr(sk)) != 0)
+                       sk->sk_err_soft = -err;
+       }
+
+       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;
+       int proto;
+       int ihl;
+       int err = -EINVAL;
+
+       if (unlikely(!pskb_may_pull(skb, sizeof(*iph))))
+               goto out;
+
+       iph = ip_hdr(skb);
+       ihl = iph->ihl * 4;
+       if (ihl < sizeof(*iph))
+               goto out;
+
+       if (unlikely(!pskb_may_pull(skb, ihl)))
+               goto out;
+
+       __skb_pull(skb, ihl);
+       skb_reset_transport_header(skb);
+       iph = ip_hdr(skb);
+       proto = iph->protocol & (MAX_INET_PROTOS - 1);
+       err = -EPROTONOSUPPORT;
+
+       rcu_read_lock();
+       ops = rcu_dereference(inet_protos[proto]);
+       if (likely(ops && ops->gso_send_check))
+               err = ops->gso_send_check(skb);
+       rcu_read_unlock();
+
+out:
+       return err;
+}
+
+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;
+       int proto;
+       int ihl;
+       int id;
+
+       if (!(features & NETIF_F_V4_CSUM))
+               features &= ~NETIF_F_SG;
+
+       if (unlikely(skb_shinfo(skb)->gso_type &
+                    ~(SKB_GSO_TCPV4 |
+                      SKB_GSO_UDP |
+                      SKB_GSO_DODGY |
+                      SKB_GSO_TCP_ECN |
+                      0)))
+               goto out;
+
+       if (unlikely(!pskb_may_pull(skb, sizeof(*iph))))
+               goto out;
+
+       iph = ip_hdr(skb);
+       ihl = iph->ihl * 4;
+       if (ihl < sizeof(*iph))
+               goto out;
+
+       if (unlikely(!pskb_may_pull(skb, ihl)))
+               goto out;
+
+       __skb_pull(skb, ihl);
+       skb_reset_transport_header(skb);
+       iph = ip_hdr(skb);
+       id = ntohs(iph->id);
+       proto = iph->protocol & (MAX_INET_PROTOS - 1);
+       segs = ERR_PTR(-EPROTONOSUPPORT);
+
+       rcu_read_lock();
+       ops = rcu_dereference(inet_protos[proto]);
+       if (likely(ops && ops->gso_segment))
+               segs = ops->gso_segment(skb, features);
+       rcu_read_unlock();
+
+       if (!segs || unlikely(IS_ERR(segs)))
+               goto out;
+
+       skb = segs;
+       do {
+               iph = ip_hdr(skb);
+               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);
+       } while ((skb = skb->next));
+
+out:
+       return segs;
+}
+
+unsigned long snmp_fold_field(void *mib[], int offt)
+{
+       unsigned long res = 0;
+       int i;
+
+       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);
+       }
+       return res;
+}
+EXPORT_SYMBOL_GPL(snmp_fold_field);
+
+int snmp_mib_init(void *ptr[2], size_t mibsize)
+{
+       BUG_ON(ptr == NULL);
+       ptr[0] = __alloc_percpu(mibsize);
+       if (!ptr[0])
+               goto err0;
+       ptr[1] = __alloc_percpu(mibsize);
+       if (!ptr[1])
+               goto err1;
+       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])
+{
+       BUG_ON(ptr == NULL);
+       free_percpu(ptr[0]);
+       free_percpu(ptr[1]);
+       ptr[0] = ptr[1] = NULL;
+}
+EXPORT_SYMBOL_GPL(snmp_mib_free);
+
 #ifdef CONFIG_IP_MULTICAST
 static struct net_protocol igmp_protocol = {
        .handler =      igmp_rcv,
@@ -970,6 +1278,8 @@ static struct net_protocol igmp_protocol = {
 static struct net_protocol tcp_protocol = {
        .handler =      tcp_v4_rcv,
        .err_handler =  tcp_v4_err,
+       .gso_send_check = tcp_v4_gso_send_check,
+       .gso_segment =  tcp_tso_segment,
        .no_policy =    1,
 };
 
@@ -985,29 +1295,60 @@ static struct net_protocol icmp_protocol = {
 
 static int __init init_ipv4_mibs(void)
 {
-       net_statistics[0] = alloc_percpu(struct linux_mib);
-       net_statistics[1] = alloc_percpu(struct linux_mib);
-       ip_statistics[0] = alloc_percpu(struct ipstats_mib);
-       ip_statistics[1] = alloc_percpu(struct ipstats_mib);
-       icmp_statistics[0] = alloc_percpu(struct icmp_mib);
-       icmp_statistics[1] = alloc_percpu(struct icmp_mib);
-       tcp_statistics[0] = alloc_percpu(struct tcp_mib);
-       tcp_statistics[1] = alloc_percpu(struct tcp_mib);
-       udp_statistics[0] = alloc_percpu(struct udp_mib);
-       udp_statistics[1] = alloc_percpu(struct udp_mib);
-       if (!
-           (net_statistics[0] && net_statistics[1] && ip_statistics[0]
-            && ip_statistics[1] && tcp_statistics[0] && tcp_statistics[1]
-            && udp_statistics[0] && udp_statistics[1]))
-               return -ENOMEM;
-
-       (void) tcp_mib_init();
+       if (snmp_mib_init((void **)net_statistics,
+                         sizeof(struct linux_mib)) < 0)
+               goto err_net_mib;
+       if (snmp_mib_init((void **)ip_statistics,
+                         sizeof(struct ipstats_mib)) < 0)
+               goto err_ip_mib;
+       if (snmp_mib_init((void **)icmp_statistics,
+                         sizeof(struct icmp_mib)) < 0)
+               goto err_icmp_mib;
+       if (snmp_mib_init((void **)icmpmsg_statistics,
+                         sizeof(struct icmpmsg_mib)) < 0)
+               goto err_icmpmsg_mib;
+       if (snmp_mib_init((void **)tcp_statistics,
+                         sizeof(struct tcp_mib)) < 0)
+               goto err_tcp_mib;
+       if (snmp_mib_init((void **)udp_statistics,
+                         sizeof(struct udp_mib)) < 0)
+               goto err_udp_mib;
+       if (snmp_mib_init((void **)udplite_statistics,
+                         sizeof(struct udp_mib)) < 0)
+               goto err_udplite_mib;
+
+       tcp_mib_init();
 
        return 0;
+
+err_udplite_mib:
+       snmp_mib_free((void **)udp_statistics);
+err_udp_mib:
+       snmp_mib_free((void **)tcp_statistics);
+err_tcp_mib:
+       snmp_mib_free((void **)icmpmsg_statistics);
+err_icmpmsg_mib:
+       snmp_mib_free((void **)icmp_statistics);
+err_icmp_mib:
+       snmp_mib_free((void **)ip_statistics);
+err_ip_mib:
+       snmp_mib_free((void **)net_statistics);
+err_net_mib:
+       return -ENOMEM;
 }
 
 static int ipv4_proc_init(void);
-extern void ipfrag_init(void);
+
+/*
+ *     IP protocol layer initialiser
+ */
+
+static struct packet_type ip_packet_type = {
+       .type = __constant_htons(ETH_P_IP),
+       .func = ip_rcv,
+       .gso_send_check = inet_gso_send_check,
+       .gso_segment = inet_gso_segment,
+};
 
 static int __init inet_init(void)
 {
@@ -1016,10 +1357,7 @@ static int __init inet_init(void)
        struct list_head *r;
        int rc = -EINVAL;
 
-       if (sizeof(struct inet_skb_parm) > sizeof(dummy_skb->cb)) {
-               printk(KERN_CRIT "%s: panic\n", __FUNCTION__);
-               goto out;
-       }
+       BUILD_BUG_ON(sizeof(struct inet_skb_parm) > sizeof(dummy_skb->cb));
 
        rc = proto_register(&tcp_prot, 1);
        if (rc)
@@ -1034,10 +1372,10 @@ static int __init inet_init(void)
                goto out_unregister_udp_proto;
 
        /*
-        *      Tell SOCKET that we are alive... 
+        *      Tell SOCKET that we are alive...
         */
 
-       (void)sock_register(&inet_family_ops);
+       (void)sock_register(&inet_family_ops);
 
        /*
         *      Add all the base protocols.
@@ -1067,9 +1405,9 @@ static int __init inet_init(void)
 
        arp_init();
 
-       /*
-        *      Set the IP module up
-        */
+       /*
+        *      Set the IP module up
+        */
 
        ip_init();
 
@@ -1078,6 +1416,8 @@ static int __init inet_init(void)
        /* Setup TCP slab cache for open requests. */
        tcp_init();
 
+       /* Add UDP-Lite (RFC 3828) */
+       udplite4_register();
 
        /*
         *      Set the ICMP layer up
@@ -1093,44 +1433,32 @@ static int __init inet_init(void)
 #endif
        /*
         *      Initialise per-cpu ipv4 mibs
-        */ 
+        */
 
-       if(init_ipv4_mibs())
+       if (init_ipv4_mibs())
                printk(KERN_CRIT "inet_init: Cannot init ipv4 mibs\n"); ;
-       
+
        ipv4_proc_init();
 
        ipfrag_init();
 
+       dev_add_pack(&ip_packet_type);
+
        rc = 0;
 out:
        return rc;
-out_unregister_tcp_proto:
-       proto_unregister(&tcp_prot);
 out_unregister_udp_proto:
        proto_unregister(&udp_prot);
+out_unregister_tcp_proto:
+       proto_unregister(&tcp_prot);
        goto out;
 }
 
-module_init(inet_init);
+fs_initcall(inet_init);
 
 /* ------------------------------------------------------------------------ */
 
 #ifdef CONFIG_PROC_FS
-extern int  fib_proc_init(void);
-extern void fib_proc_exit(void);
-#ifdef CONFIG_IP_FIB_TRIE
-extern int  fib_stat_proc_init(void);
-extern void fib_stat_proc_exit(void);
-#endif
-extern int  ip_misc_proc_init(void);
-extern int  raw_proc_init(void);
-extern void raw_proc_exit(void);
-extern int  tcp4_proc_init(void);
-extern void tcp4_proc_exit(void);
-extern int  udp4_proc_init(void);
-extern void udp4_proc_exit(void);
-
 static int __init ipv4_proc_init(void)
 {
        int rc = 0;
@@ -1143,19 +1471,11 @@ static int __init ipv4_proc_init(void)
                goto out_udp;
        if (fib_proc_init())
                goto out_fib;
-#ifdef CONFIG_IP_FIB_TRIE
-         if (fib_stat_proc_init())
-                 goto out_fib_stat;
- #endif
        if (ip_misc_proc_init())
                goto out_misc;
 out:
        return rc;
 out_misc:
-#ifdef CONFIG_IP_FIB_TRIE
-       fib_stat_proc_exit();
-out_fib_stat:
-#endif
        fib_proc_exit();
 out_fib:
        udp4_proc_exit();
@@ -1194,7 +1514,3 @@ EXPORT_SYMBOL(inet_stream_ops);
 EXPORT_SYMBOL(inet_unregister_protosw);
 EXPORT_SYMBOL(net_statistics);
 EXPORT_SYMBOL(sysctl_ip_nonlocal_bind);
-
-#ifdef INET_REFCNT_DEBUG
-EXPORT_SYMBOL(inet_sock_nr);
-#endif