Skip to content

Commit

Permalink
dev: introduce skb_scrub_packet()
Browse files Browse the repository at this point in the history
The goal of this new function is to perform all needed cleanup before sending
an skb into another netns.

Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
NicolasDichtel authored and davem330 committed Jun 28, 2013
1 parent 38ae92d commit 621e84d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
1 change: 1 addition & 0 deletions include/linux/skbuff.h
Original file line number Diff line number Diff line change
Expand Up @@ -2384,6 +2384,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 struct sk_buff *skb_segment(struct sk_buff *skb,
netdev_features_t features);
Expand Down
11 changes: 1 addition & 10 deletions net/core/dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -1652,22 +1652,13 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
}
}

skb_orphan(skb);

if (unlikely(!is_skb_forwardable(dev, skb))) {
atomic_long_inc(&dev->rx_dropped);
kfree_skb(skb);
return NET_RX_DROP;
}
skb->skb_iif = 0;
skb_dst_drop(skb);
skb->tstamp.tv64 = 0;
skb->pkt_type = PACKET_HOST;
skb_scrub_packet(skb);
skb->protocol = eth_type_trans(skb, dev);
skb->mark = 0;
secpath_reset(skb);
nf_reset(skb);
nf_reset_trace(skb);
return netif_rx(skb);
}
EXPORT_SYMBOL_GPL(dev_forward_skb);
Expand Down
23 changes: 23 additions & 0 deletions net/core/skbuff.c
Original file line number Diff line number Diff line change
Expand Up @@ -3492,3 +3492,26 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
return true;
}
EXPORT_SYMBOL(skb_try_coalesce);

/**
* skb_scrub_packet - scrub an skb before sending it to another netns
*
* @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.
*/
void skb_scrub_packet(struct sk_buff *skb)
{
skb_orphan(skb);
skb->tstamp.tv64 = 0;
skb->pkt_type = PACKET_HOST;
skb->skb_iif = 0;
skb_dst_drop(skb);
skb->mark = 0;
secpath_reset(skb);
nf_reset(skb);
nf_reset_trace(skb);
}
EXPORT_SYMBOL_GPL(skb_scrub_packet);

0 comments on commit 621e84d

Please sign in to comment.