Skip to content

Commit 8b27f27

Browse files
NicolasDichteldavem330
authored andcommitted
skb: allow skb_scrub_packet() to be used by tunnels
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]>
1 parent 1179618 commit 8b27f27

File tree

6 files changed

+20
-15
lines changed

6 files changed

+20
-15
lines changed

include/linux/skbuff.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2392,7 +2392,7 @@ extern void skb_split(struct sk_buff *skb,
23922392
struct sk_buff *skb1, const u32 len);
23932393
extern int skb_shift(struct sk_buff *tgt, struct sk_buff *skb,
23942394
int shiftlen);
2395-
extern void skb_scrub_packet(struct sk_buff *skb);
2395+
extern void skb_scrub_packet(struct sk_buff *skb, bool xnet);
23962396

23972397
extern struct sk_buff *skb_segment(struct sk_buff *skb,
23982398
netdev_features_t features);

net/core/dev.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1697,7 +1697,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
16971697
* call skb_scrub_packet() after it to clear pkt_type _after_ calling
16981698
* eth_type_trans().
16991699
*/
1700-
skb_scrub_packet(skb);
1700+
skb_scrub_packet(skb, true);
17011701

17021702
return netif_rx(skb);
17031703
}

net/core/skbuff.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3500,17 +3500,22 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
35003500
EXPORT_SYMBOL(skb_try_coalesce);
35013501

35023502
/**
3503-
* skb_scrub_packet - scrub an skb before sending it to another netns
3503+
* skb_scrub_packet - scrub an skb
35043504
*
35053505
* @skb: buffer to clean
3506-
*
3507-
* skb_scrub_packet can be used to clean an skb before injecting it in
3508-
* another namespace. We have to clear all information in the skb that
3509-
* could impact namespace isolation.
3506+
* @xnet: packet is crossing netns
3507+
*
3508+
* skb_scrub_packet can be used after encapsulating or decapsulting a packet
3509+
* into/from a tunnel. Some information have to be cleared during these
3510+
* operations.
3511+
* skb_scrub_packet can also be used to clean a skb before injecting it in
3512+
* another namespace (@xnet == true). We have to clear all information in the
3513+
* skb that could impact namespace isolation.
35103514
*/
3511-
void skb_scrub_packet(struct sk_buff *skb)
3515+
void skb_scrub_packet(struct sk_buff *skb, bool xnet)
35123516
{
3513-
skb_orphan(skb);
3517+
if (xnet)
3518+
skb_orphan(skb);
35143519
skb->tstamp.tv64 = 0;
35153520
skb->pkt_type = PACKET_HOST;
35163521
skb->skb_iif = 0;

net/ipv4/ip_tunnel.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ int ip_tunnel_rcv(struct ip_tunnel *tunnel, struct sk_buff *skb,
462462
}
463463

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

467467
gro_cells_receive(&tunnel->gro_cells, skb);
468468
return 0;
@@ -615,7 +615,7 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
615615
}
616616

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

620620
if (tunnel->err_count > 0) {
621621
if (time_before(jiffies,

net/ipv6/ip6_tunnel.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,7 @@ static int ip6_tnl_rcv(struct sk_buff *skb, __u16 protocol,
830830
tstats->rx_bytes += skb->len;
831831

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

835835
netif_rx(skb);
836836

@@ -1002,7 +1002,7 @@ static int ip6_tnl_xmit2(struct sk_buff *skb,
10021002
}
10031003

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

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

net/ipv6/sit.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ static int ipip6_rcv(struct sk_buff *skb)
622622
tstats->rx_bytes += skb->len;
623623

624624
if (!net_eq(tunnel->net, dev_net(tunnel->dev)))
625-
skb_scrub_packet(skb);
625+
skb_scrub_packet(skb, true);
626626
netif_rx(skb);
627627

628628
return 0;
@@ -861,7 +861,7 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb,
861861
}
862862

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

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

0 commit comments

Comments
 (0)