tunnels: harmonize cleanup done on skb on xmit path
authorNicolas Dichtel <nicolas.dichtel@6wind.com>
Mon, 2 Sep 2013 13:34:57 +0000 (15:34 +0200)
committerDavid S. Miller <davem@davemloft.net>
Wed, 4 Sep 2013 04:27:25 +0000 (00:27 -0400)
The goal of this patch is to harmonize cleanup done on a skbuff on xmit 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>
drivers/net/vxlan.c
include/net/ip6_tunnel.h
include/net/ip_tunnels.h
net/ipv4/ip_tunnel.c
net/ipv4/ip_tunnel_core.c
net/ipv6/ip6_gre.c
net/ipv6/ip6_tunnel.c
net/ipv6/sit.c
net/openvswitch/vport-gre.c

index a334bfb91c5a1cac97f92fa454d56c83e842bb0a..ebda3a1c2f31117622687bc7b5ec89b3b2da6186 100644 (file)
@@ -1397,6 +1397,8 @@ static int vxlan6_xmit_skb(struct vxlan_sock *vs,
                skb->encapsulation = 1;
        }
 
+       skb_scrub_packet(skb, false);
+
        min_headroom = LL_RESERVED_SPACE(dst->dev) + dst->header_len
                        + VXLAN_HLEN + sizeof(struct ipv6hdr)
                        + (vlan_tx_tag_present(skb) ? VLAN_HLEN : 0);
@@ -1432,7 +1434,6 @@ static int vxlan6_xmit_skb(struct vxlan_sock *vs,
        memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt));
        IPCB(skb)->flags &= ~(IPSKB_XFRM_TUNNEL_SIZE | IPSKB_XFRM_TRANSFORMED |
                              IPSKB_REROUTED);
-       skb_dst_drop(skb);
        skb_dst_set(skb, dst);
 
        if (!skb_is_gso(skb) && !(dst->dev->features & NETIF_F_IPV6_CSUM)) {
@@ -1528,7 +1529,8 @@ int vxlan_xmit_skb(struct vxlan_sock *vs,
        if (err)
                return err;
 
-       return iptunnel_xmit(rt, skb, src, dst, IPPROTO_UDP, tos, ttl, df);
+       return iptunnel_xmit(rt, skb, src, dst, IPPROTO_UDP, tos, ttl, df,
+                            false);
 }
 EXPORT_SYMBOL_GPL(vxlan_xmit_skb);
 
index 2265b0bf97e523817ea307d554451c4cebe4fc58..6d1549c4893cbec83ab2aec280b08c650dff0cfd 100644 (file)
@@ -75,7 +75,6 @@ static inline void ip6tunnel_xmit(struct sk_buff *skb, struct net_device *dev)
        struct net_device_stats *stats = &dev->stats;
        int pkt_len, err;
 
-       nf_reset(skb);
        pkt_len = skb->len;
        err = ip6_local_out(skb);
 
index 94fe8fd07bc9686a2feca2756cd65d6cdb3fab83..a0a4a100f5c9a74ce544097dee5f3d25e68e8b9b 100644 (file)
@@ -148,7 +148,7 @@ static inline u8 ip_tunnel_ecn_encap(u8 tos, const struct iphdr *iph,
 int iptunnel_pull_header(struct sk_buff *skb, int hdr_len, __be16 inner_proto);
 int iptunnel_xmit(struct rtable *rt, struct sk_buff *skb,
                  __be32 src, __be32 dst, __u8 proto,
-                 __u8 tos, __u8 ttl, __be16 df);
+                 __u8 tos, __u8 ttl, __be16 df, bool xnet);
 
 static inline void iptunnel_xmit_stats(int err,
                                       struct net_device_stats *err_stats,
index b0e74e17088f72f99924575d1d3bebee95660561..88d7d7d1eccbee342ee3dae8420697d4fdfdfc27 100644 (file)
@@ -614,9 +614,6 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
                goto tx_error;
        }
 
-       if (!net_eq(tunnel->net, dev_net(dev)))
-               skb_scrub_packet(skb, true);
-
        if (tunnel->err_count > 0) {
                if (time_before(jiffies,
                                tunnel->err_time + IPTUNNEL_ERR_TIMEO)) {
@@ -655,7 +652,8 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
        }
 
        err = iptunnel_xmit(rt, skb, fl4.saddr, fl4.daddr, protocol,
-                           ip_tunnel_ecn_encap(tos, inner_iph, skb), ttl, df);
+                           ip_tunnel_ecn_encap(tos, inner_iph, skb), ttl, df,
+                           !net_eq(tunnel->net, dev_net(dev)));
        iptunnel_xmit_stats(err, &dev->stats, dev->tstats);
 
        return;
index e82045842351e7aab07b1585127497aec1bc0cee..d6c856b17fd4ff22c0034af676a648730dffce82 100644 (file)
 
 int iptunnel_xmit(struct rtable *rt, struct sk_buff *skb,
                  __be32 src, __be32 dst, __u8 proto,
-                 __u8 tos, __u8 ttl, __be16 df)
+                 __u8 tos, __u8 ttl, __be16 df, bool xnet)
 {
        int pkt_len = skb->len;
        struct iphdr *iph;
        int err;
 
-       nf_reset(skb);
-       secpath_reset(skb);
+       skb_scrub_packet(skb, xnet);
+
        skb->rxhash = 0;
-       skb_dst_drop(skb);
        skb_dst_set(skb, &rt->dst);
        memset(IPCB(skb), 0, sizeof(*IPCB(skb)));
 
index f2d0a42f80576b7bbeaebe7009fe6a476fb07236..f179ff1f56ec061270993de9cf0197819dbba7b1 100644 (file)
@@ -694,6 +694,8 @@ static netdev_tx_t ip6gre_xmit2(struct sk_buff *skb,
                        tunnel->err_count = 0;
        }
 
+       skb_scrub_packet(skb, !net_eq(tunnel->net, dev_net(dev)));
+
        max_headroom = LL_RESERVED_SPACE(tdev) + gre_hlen + dst->header_len;
 
        if (skb_headroom(skb) < max_headroom || skb_shared(skb) ||
@@ -710,8 +712,6 @@ static netdev_tx_t ip6gre_xmit2(struct sk_buff *skb,
                skb = new_skb;
        }
 
-       skb_dst_drop(skb);
-
        if (fl6->flowi6_mark) {
                skb_dst_set(skb, dst);
                ndst = NULL;
index 72372ac90159b63206d0986ec7a81f1c0f4a9987..ecbcdbd4bc4fa7bbb34ede10a1a36c17fb5da3f9 100644 (file)
@@ -1001,8 +1001,7 @@ static int ip6_tnl_xmit2(struct sk_buff *skb,
                goto tx_err_dst_release;
        }
 
-       if (!net_eq(t->net, dev_net(dev)))
-               skb_scrub_packet(skb, true);
+       skb_scrub_packet(skb, !net_eq(t->net, dev_net(dev)));
 
        /*
         * Okay, now see if we can stuff it in the buffer as-is.
@@ -1021,7 +1020,6 @@ static int ip6_tnl_xmit2(struct sk_buff *skb,
                consume_skb(skb);
                skb = new_skb;
        }
-       skb_dst_drop(skb);
        if (fl6->flowi6_mark) {
                skb_dst_set(skb, dst);
                ndst = NULL;
index b2e44f478e146369c3029d703037b81aa94964a7..82b425b9b7d2a977d4321e9f9d0e2c507ef37ff2 100644 (file)
@@ -860,9 +860,6 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb,
                        tunnel->err_count = 0;
        }
 
-       if (!net_eq(tunnel->net, dev_net(dev)))
-               skb_scrub_packet(skb, true);
-
        /*
         * Okay, now see if we can stuff it in the buffer as-is.
         */
@@ -889,7 +886,7 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb,
        tos = INET_ECN_encapsulate(tos, ipv6_get_dsfield(iph6));
 
        err = iptunnel_xmit(rt, skb, fl4.saddr, fl4.daddr, IPPROTO_IPV6, tos,
-                           ttl, df);
+                           ttl, df, !net_eq(tunnel->net, dev_net(dev)));
        iptunnel_xmit_stats(err, &dev->stats, dev->tstats);
        return NETDEV_TX_OK;
 
index 9b3713ef831ec699246172ea5c64bc1f9f72d473..c99dea543d648dbd377c7168cad517c8bc76bf76 100644 (file)
@@ -179,7 +179,7 @@ static int gre_tnl_send(struct vport *vport, struct sk_buff *skb)
        return iptunnel_xmit(rt, skb, fl.saddr,
                             OVS_CB(skb)->tun_key->ipv4_dst, IPPROTO_GRE,
                             OVS_CB(skb)->tun_key->ipv4_tos,
-                            OVS_CB(skb)->tun_key->ipv4_ttl, df);
+                            OVS_CB(skb)->tun_key->ipv4_ttl, df, false);
 err_free_rt:
        ip_rt_put(rt);
 error: