SUNRPC: Fix xs_setup_bc_tcp()
[safe/jmp/linux-2.6] / net / ipv4 / ip_input.c
index 043f640..f8ab7a3 100644 (file)
@@ -8,7 +8,7 @@
  * Authors:    Ross Biro
  *             Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
  *             Donald Becker, <becker@super.org>
- *             Alan Cox, <Alan.Cox@linux.org>
+ *             Alan Cox, <alan@lxorguk.ukuu.org.uk>
  *             Richard Underwood
  *             Stefan Becker, <stefanb@yello.ping.de>
  *             Jorge Cwik, <jorge@laser.satlink.net>
 #include <linux/kernel.h>
 #include <linux/string.h>
 #include <linux/errno.h>
+#include <linux/slab.h>
 
 #include <linux/net.h>
 #include <linux/socket.h>
 #include <linux/netlink.h>
 
 /*
- *     SNMP management statistics
- */
-
-DEFINE_SNMP_STAT(struct ipstats_mib, ip_statistics) __read_mostly;
-
-/*
  *     Process Router Attention IP option
  */
 int ip_call_ra_chain(struct sk_buff *skb)
@@ -167,10 +162,10 @@ int ip_call_ra_chain(struct sk_buff *skb)
                /* If socket is bound to an interface, only report
                 * the packet if it came  from that interface.
                 */
-               if (sk && inet_sk(sk)->num == protocol &&
+               if (sk && inet_sk(sk)->inet_num == protocol &&
                    (!sk->sk_bound_dev_if ||
                     sk->sk_bound_dev_if == dev->ifindex) &&
-                   sock_net(sk) == dev_net(dev)) {
+                   net_eq(sock_net(sk), dev_net(dev))) {
                        if (ip_hdr(skb)->frag_off & htons(IP_MF | IP_OFFSET)) {
                                if (ip_defrag(skb, IP_DEFRAG_CALL_RA_CHAIN)) {
                                        read_unlock(&ip_ra_lock);
@@ -208,16 +203,24 @@ static int ip_local_deliver_finish(struct sk_buff *skb)
        {
                int protocol = ip_hdr(skb)->protocol;
                int hash, raw;
-               struct net_protocol *ipprot;
+               const struct net_protocol *ipprot;
 
        resubmit:
                raw = raw_local_deliver(skb, protocol);
 
                hash = protocol & (MAX_INET_PROTOS - 1);
                ipprot = rcu_dereference(inet_protos[hash]);
-               if (ipprot != NULL && (net == &init_net || ipprot->netns_ok)) {
+               if (ipprot != NULL) {
                        int ret;
 
+                       if (!net_eq(net, &init_net) && !ipprot->netns_ok) {
+                               if (net_ratelimit())
+                                       printk("%s: proto %d isn't netns-ready\n",
+                                               __func__, protocol);
+                               kfree_skb(skb);
+                               goto out;
+                       }
+
                        if (!ipprot->no_policy) {
                                if (!xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb)) {
                                        kfree_skb(skb);
@@ -300,10 +303,8 @@ static inline int ip_rcv_options(struct sk_buff *skb)
                        if (!IN_DEV_SOURCE_ROUTE(in_dev)) {
                                if (IN_DEV_LOG_MARTIANS(in_dev) &&
                                    net_ratelimit())
-                                       printk(KERN_INFO "source route option "
-                                              NIPQUAD_FMT " -> " NIPQUAD_FMT "\n",
-                                              NIPQUAD(iph->saddr),
-                                              NIPQUAD(iph->daddr));
+                                       printk(KERN_INFO "source route option %pI4 -> %pI4\n",
+                                              &iph->saddr, &iph->daddr);
                                in_dev_put(in_dev);
                                goto drop;
                        }
@@ -329,7 +330,7 @@ static int ip_rcv_finish(struct sk_buff *skb)
         *      Initialise the virtual path cache for the packet. It describes
         *      how the packet travels inside Linux networking.
         */
-       if (skb->dst == NULL) {
+       if (skb_dst(skb) == NULL) {
                int err = ip_route_input(skb, iph->daddr, iph->saddr, iph->tos,
                                         skb->dev);
                if (unlikely(err)) {
@@ -344,24 +345,26 @@ static int ip_rcv_finish(struct sk_buff *skb)
        }
 
 #ifdef CONFIG_NET_CLS_ROUTE
-       if (unlikely(skb->dst->tclassid)) {
+       if (unlikely(skb_dst(skb)->tclassid)) {
                struct ip_rt_acct *st = per_cpu_ptr(ip_rt_acct, smp_processor_id());
-               u32 idx = skb->dst->tclassid;
+               u32 idx = skb_dst(skb)->tclassid;
                st[idx&0xFF].o_packets++;
-               st[idx&0xFF].o_bytes+=skb->len;
+               st[idx&0xFF].o_bytes += skb->len;
                st[(idx>>16)&0xFF].i_packets++;
-               st[(idx>>16)&0xFF].i_bytes+=skb->len;
+               st[(idx>>16)&0xFF].i_bytes += skb->len;
        }
 #endif
 
        if (iph->ihl > 5 && ip_rcv_options(skb))
                goto drop;
 
-       rt = skb->rtable;
-       if (rt->rt_type == RTN_MULTICAST)
-               IP_INC_STATS_BH(dev_net(rt->u.dst.dev), IPSTATS_MIB_INMCASTPKTS);
-       else if (rt->rt_type == RTN_BROADCAST)
-               IP_INC_STATS_BH(dev_net(rt->u.dst.dev), IPSTATS_MIB_INBCASTPKTS);
+       rt = skb_rtable(skb);
+       if (rt->rt_type == RTN_MULTICAST) {
+               IP_UPD_PO_STATS_BH(dev_net(rt->u.dst.dev), IPSTATS_MIB_INMCAST,
+                               skb->len);
+       } else if (rt->rt_type == RTN_BROADCAST)
+               IP_UPD_PO_STATS_BH(dev_net(rt->u.dst.dev), IPSTATS_MIB_INBCAST,
+                               skb->len);
 
        return dst_input(skb);
 
@@ -384,7 +387,8 @@ int ip_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt,
        if (skb->pkt_type == PACKET_OTHERHOST)
                goto drop;
 
-       IP_INC_STATS_BH(dev_net(dev), IPSTATS_MIB_INRECEIVES);
+
+       IP_UPD_PO_STATS_BH(dev_net(dev), IPSTATS_MIB_IN, skb->len);
 
        if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL) {
                IP_INC_STATS_BH(dev_net(dev), IPSTATS_MIB_INDISCARDS);
@@ -437,6 +441,9 @@ int ip_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt,
        /* Remove any debris in the socket control block */
        memset(IPCB(skb), 0, sizeof(struct inet_skb_parm));
 
+       /* Must drop socket now because of tproxy. */
+       skb_orphan(skb);
+
        return NF_HOOK(PF_INET, NF_INET_PRE_ROUTING, skb, dev, NULL,
                       ip_rcv_finish);
 
@@ -447,5 +454,3 @@ drop:
 out:
        return NET_RX_DROP;
 }
-
-EXPORT_SYMBOL(ip_statistics);