tunnels: harmonize cleanup done on skb on rx path
authorNicolas Dichtel <nicolas.dichtel@6wind.com>
Mon, 2 Sep 2013 13:34:58 +0000 (15:34 +0200)
committerDavid S. Miller <davem@davemloft.net>
Wed, 4 Sep 2013 04:27:26 +0000 (00:27 -0400)
The goal of this patch is to harmonize cleanup done on a skbuff on rx path.
Before this patch, behaviors were different depending of the tunnel type.

Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/dst.h
net/ipv4/ip_tunnel.c
net/ipv4/ipmr.c
net/ipv6/ip6_gre.c
net/ipv6/ip6_tunnel.c
net/ipv6/ip6mr.c
net/ipv6/sit.c

index 1f8fd109e2254f10118929fe96e073bbceb13f5a..3bc4865f82679137077db4dd82c177bd39b51515 100644 (file)
@@ -311,11 +311,13 @@ static inline void skb_dst_force(struct sk_buff *skb)
  *     __skb_tunnel_rx - prepare skb for rx reinsert
  *     @skb: buffer
  *     @dev: tunnel device
+ *     @net: netns for packet i/o
  *
  *     After decapsulation, packet is going to re-enter (netif_rx()) our stack,
  *     so make some cleanups. (no accounting done)
  */
-static inline void __skb_tunnel_rx(struct sk_buff *skb, struct net_device *dev)
+static inline void __skb_tunnel_rx(struct sk_buff *skb, struct net_device *dev,
+                                  struct net *net)
 {
        skb->dev = dev;
 
@@ -327,8 +329,7 @@ static inline void __skb_tunnel_rx(struct sk_buff *skb, struct net_device *dev)
        if (!skb->l4_rxhash)
                skb->rxhash = 0;
        skb_set_queue_mapping(skb, 0);
-       skb_dst_drop(skb);
-       nf_reset(skb);
+       skb_scrub_packet(skb, !net_eq(net, dev_net(dev)));
 }
 
 /**
@@ -340,12 +341,13 @@ static inline void __skb_tunnel_rx(struct sk_buff *skb, struct net_device *dev)
  *     so make some cleanups, and perform accounting.
  *     Note: this accounting is not SMP safe.
  */
-static inline void skb_tunnel_rx(struct sk_buff *skb, struct net_device *dev)
+static inline void skb_tunnel_rx(struct sk_buff *skb, struct net_device *dev,
+                                struct net *net)
 {
        /* TODO : stats should be SMP safe */
        dev->stats.rx_packets++;
        dev->stats.rx_bytes += skb->len;
-       __skb_tunnel_rx(skb, dev);
+       __skb_tunnel_rx(skb, dev, net);
 }
 
 /* Children define the path of the packet through the
index 88d7d7d1eccbee342ee3dae8420697d4fdfdfc27..ac9fabe0300f613e87bbe4d70e9c861fbc95889e 100644 (file)
@@ -461,8 +461,7 @@ int ip_tunnel_rcv(struct ip_tunnel *tunnel, struct sk_buff *skb,
                skb->dev = tunnel->dev;
        }
 
-       if (!net_eq(tunnel->net, dev_net(tunnel->dev)))
-               skb_scrub_packet(skb, true);
+       skb_scrub_packet(skb, !net_eq(tunnel->net, dev_net(tunnel->dev)));
 
        gro_cells_receive(&tunnel->gro_cells, skb);
        return 0;
index bacc0bcf48ce5b1cec365e5886d820492d41566d..9ae54b09254f158d82d6b86adafe04776c830775 100644 (file)
@@ -2067,9 +2067,8 @@ static int __pim_rcv(struct mr_table *mrt, struct sk_buff *skb,
        skb_reset_network_header(skb);
        skb->protocol = htons(ETH_P_IP);
        skb->ip_summed = CHECKSUM_NONE;
-       skb->pkt_type = PACKET_HOST;
 
-       skb_tunnel_rx(skb, reg_dev);
+       skb_tunnel_rx(skb, reg_dev, dev_net(reg_dev));
 
        netif_rx(skb);
 
index f179ff1f56ec061270993de9cf0197819dbba7b1..db992a373011241afcbc3094a683474b67742290 100644 (file)
@@ -509,8 +509,6 @@ static int ip6gre_rcv(struct sk_buff *skb)
                        goto drop;
                }
 
-               secpath_reset(skb);
-
                skb->protocol = gre_proto;
                /* WCCP version 1 and 2 protocol decoding.
                 * - Change protocol to IP
@@ -525,7 +523,6 @@ static int ip6gre_rcv(struct sk_buff *skb)
                skb->mac_header = skb->network_header;
                __pskb_pull(skb, offset);
                skb_postpull_rcsum(skb, skb_transport_header(skb), offset);
-               skb->pkt_type = PACKET_HOST;
 
                if (((flags&GRE_CSUM) && csum) ||
                    (!(flags&GRE_CSUM) && tunnel->parms.i_flags&GRE_CSUM)) {
@@ -557,7 +554,7 @@ static int ip6gre_rcv(struct sk_buff *skb)
                        skb_postpull_rcsum(skb, eth_hdr(skb), ETH_HLEN);
                }
 
-               __skb_tunnel_rx(skb, tunnel->dev);
+               __skb_tunnel_rx(skb, tunnel->dev, tunnel->net);
 
                skb_reset_network_header(skb);
 
index ecbcdbd4bc4fa7bbb34ede10a1a36c17fb5da3f9..55999d923f265be4f6151437c0ee07523cfca503 100644 (file)
@@ -802,14 +802,12 @@ static int ip6_tnl_rcv(struct sk_buff *skb, __u16 protocol,
                        rcu_read_unlock();
                        goto discard;
                }
-               secpath_reset(skb);
                skb->mac_header = skb->network_header;
                skb_reset_network_header(skb);
                skb->protocol = htons(protocol);
-               skb->pkt_type = PACKET_HOST;
                memset(skb->cb, 0, sizeof(struct inet6_skb_parm));
 
-               __skb_tunnel_rx(skb, t->dev);
+               __skb_tunnel_rx(skb, t->dev, t->net);
 
                err = dscp_ecn_decapsulate(t, ipv6h, skb);
                if (unlikely(err)) {
@@ -829,9 +827,6 @@ static int ip6_tnl_rcv(struct sk_buff *skb, __u16 protocol,
                tstats->rx_packets++;
                tstats->rx_bytes += skb->len;
 
-               if (!net_eq(t->net, dev_net(t->dev)))
-                       skb_scrub_packet(skb, true);
-
                netif_rx(skb);
 
                rcu_read_unlock();
index a60a84ef04f7f880b23479e9f8fa047b3905af75..f365310bfcca30420a9cce321c1875d7f4319c21 100644 (file)
@@ -672,9 +672,8 @@ static int pim6_rcv(struct sk_buff *skb)
        skb_reset_network_header(skb);
        skb->protocol = htons(ETH_P_IPV6);
        skb->ip_summed = CHECKSUM_NONE;
-       skb->pkt_type = PACKET_HOST;
 
-       skb_tunnel_rx(skb, reg_dev);
+       skb_tunnel_rx(skb, reg_dev, dev_net(reg_dev));
 
        netif_rx(skb);
 
index 82b425b9b7d2a977d4321e9f9d0e2c507ef37ff2..19abcc9d6a1a4f1ed07392927e27d05b0bba8301 100644 (file)
@@ -581,12 +581,10 @@ static int ipip6_rcv(struct sk_buff *skb)
                    tunnel->parms.iph.protocol != 0)
                        goto out;
 
-               secpath_reset(skb);
                skb->mac_header = skb->network_header;
                skb_reset_network_header(skb);
                IPCB(skb)->flags = 0;
                skb->protocol = htons(ETH_P_IPV6);
-               skb->pkt_type = PACKET_HOST;
 
                if (tunnel->dev->priv_flags & IFF_ISATAP) {
                        if (!isatap_chksrc(skb, iph, tunnel)) {
@@ -603,7 +601,7 @@ static int ipip6_rcv(struct sk_buff *skb)
                        }
                }
 
-               __skb_tunnel_rx(skb, tunnel->dev);
+               __skb_tunnel_rx(skb, tunnel->dev, tunnel->net);
 
                err = IP_ECN_decapsulate(iph, skb);
                if (unlikely(err)) {
@@ -621,8 +619,6 @@ static int ipip6_rcv(struct sk_buff *skb)
                tstats->rx_packets++;
                tstats->rx_bytes += skb->len;
 
-               if (!net_eq(tunnel->net, dev_net(tunnel->dev)))
-                       skb_scrub_packet(skb, true);
                netif_rx(skb);
 
                return 0;