Skip to content

Commit

Permalink
skb: allow skb_scrub_packet() to be used by tunnels
Browse files Browse the repository at this point in the history
This function was only used when a packet was sent to another netns. Now, it can
also be used after tunnel encapsulation or decapsulation.

Only skb_orphan() should not be done when a packet is not crossing netns.

Signed-off-by: Nicolas Dichtel <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
NicolasDichtel authored and davem330 committed Sep 4, 2013
1 parent 1179618 commit 8b27f27
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion include/linux/skbuff.h
Original file line number Diff line number Diff line change
Expand Up @@ -2392,7 +2392,7 @@ extern void skb_split(struct sk_buff *skb,
struct sk_buff *skb1, const u32 len);
extern int skb_shift(struct sk_buff *tgt, struct sk_buff *skb,
int shiftlen);
extern void skb_scrub_packet(struct sk_buff *skb);
extern void skb_scrub_packet(struct sk_buff *skb, bool xnet);

extern struct sk_buff *skb_segment(struct sk_buff *skb,
netdev_features_t features);
Expand Down
2 changes: 1 addition & 1 deletion net/core/dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -1697,7 +1697,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
* call skb_scrub_packet() after it to clear pkt_type _after_ calling
* eth_type_trans().
*/
skb_scrub_packet(skb);
skb_scrub_packet(skb, true);

return netif_rx(skb);
}
Expand Down
19 changes: 12 additions & 7 deletions net/core/skbuff.c
Original file line number Diff line number Diff line change
Expand Up @@ -3500,17 +3500,22 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
EXPORT_SYMBOL(skb_try_coalesce);

/**
* skb_scrub_packet - scrub an skb before sending it to another netns
* skb_scrub_packet - scrub an skb
*
* @skb: buffer to clean
*
* skb_scrub_packet can be used to clean an skb before injecting it in
* another namespace. We have to clear all information in the skb that
* could impact namespace isolation.
* @xnet: packet is crossing netns
*
* skb_scrub_packet can be used after encapsulating or decapsulting a packet
* into/from a tunnel. Some information have to be cleared during these
* operations.
* skb_scrub_packet can also be used to clean a skb before injecting it in
* another namespace (@xnet == true). We have to clear all information in the
* skb that could impact namespace isolation.
*/
void skb_scrub_packet(struct sk_buff *skb)
void skb_scrub_packet(struct sk_buff *skb, bool xnet)
{
skb_orphan(skb);
if (xnet)
skb_orphan(skb);
skb->tstamp.tv64 = 0;
skb->pkt_type = PACKET_HOST;
skb->skb_iif = 0;
Expand Down
4 changes: 2 additions & 2 deletions net/ipv4/ip_tunnel.c
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ int ip_tunnel_rcv(struct ip_tunnel *tunnel, struct sk_buff *skb,
}

if (!net_eq(tunnel->net, dev_net(tunnel->dev)))
skb_scrub_packet(skb);
skb_scrub_packet(skb, true);

gro_cells_receive(&tunnel->gro_cells, skb);
return 0;
Expand Down Expand Up @@ -615,7 +615,7 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
}

if (!net_eq(tunnel->net, dev_net(dev)))
skb_scrub_packet(skb);
skb_scrub_packet(skb, true);

if (tunnel->err_count > 0) {
if (time_before(jiffies,
Expand Down
4 changes: 2 additions & 2 deletions net/ipv6/ip6_tunnel.c
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ static int ip6_tnl_rcv(struct sk_buff *skb, __u16 protocol,
tstats->rx_bytes += skb->len;

if (!net_eq(t->net, dev_net(t->dev)))
skb_scrub_packet(skb);
skb_scrub_packet(skb, true);

netif_rx(skb);

Expand Down Expand Up @@ -1002,7 +1002,7 @@ static int ip6_tnl_xmit2(struct sk_buff *skb,
}

if (!net_eq(t->net, dev_net(dev)))
skb_scrub_packet(skb);
skb_scrub_packet(skb, true);

/*
* Okay, now see if we can stuff it in the buffer as-is.
Expand Down
4 changes: 2 additions & 2 deletions net/ipv6/sit.c
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ static int ipip6_rcv(struct sk_buff *skb)
tstats->rx_bytes += skb->len;

if (!net_eq(tunnel->net, dev_net(tunnel->dev)))
skb_scrub_packet(skb);
skb_scrub_packet(skb, true);
netif_rx(skb);

return 0;
Expand Down Expand Up @@ -861,7 +861,7 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb,
}

if (!net_eq(tunnel->net, dev_net(dev)))
skb_scrub_packet(skb);
skb_scrub_packet(skb, true);

/*
* Okay, now see if we can stuff it in the buffer as-is.
Expand Down

0 comments on commit 8b27f27

Please sign in to comment.