Skip to content

Commit b93dd49

Browse files
Mahesh Bandewardavem330
authored andcommitted
ipvlan: Scrub skb before crossing the namespace boundry
The earlier patch c3aaa06 (ipvlan: scrub skb before routing in L3 mode.) did this but only for TX path in L3 mode. This patch extends it for both the modes for TX/RX path. Signed-off-by: Mahesh Bandewar <maheshb@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 16eab55 commit b93dd49

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

drivers/net/ipvlan/ipvlan_core.c

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,18 @@ void ipvlan_process_multicast(struct work_struct *work)
254254
}
255255
}
256256

257+
static void ipvlan_skb_crossing_ns(struct sk_buff *skb, struct net_device *dev)
258+
{
259+
bool xnet = true;
260+
261+
if (dev)
262+
xnet = !net_eq(dev_net(skb->dev), dev_net(dev));
263+
264+
skb_scrub_packet(skb, xnet);
265+
if (dev)
266+
skb->dev = dev;
267+
}
268+
257269
static int ipvlan_rcv_frame(struct ipvl_addr *addr, struct sk_buff **pskb,
258270
bool local)
259271
{
@@ -280,7 +292,7 @@ static int ipvlan_rcv_frame(struct ipvl_addr *addr, struct sk_buff **pskb,
280292

281293
*pskb = skb;
282294
}
283-
skb->dev = dev;
295+
ipvlan_skb_crossing_ns(skb, dev);
284296

285297
if (local) {
286298
skb->pkt_type = PACKET_HOST;
@@ -347,7 +359,7 @@ static struct ipvl_addr *ipvlan_addr_lookup(struct ipvl_port *port,
347359
return addr;
348360
}
349361

350-
static int ipvlan_process_v4_outbound(struct sk_buff *skb, bool xnet)
362+
static int ipvlan_process_v4_outbound(struct sk_buff *skb)
351363
{
352364
const struct iphdr *ip4h = ip_hdr(skb);
353365
struct net_device *dev = skb->dev;
@@ -370,7 +382,6 @@ static int ipvlan_process_v4_outbound(struct sk_buff *skb, bool xnet)
370382
ip_rt_put(rt);
371383
goto err;
372384
}
373-
skb_scrub_packet(skb, xnet);
374385
skb_dst_set(skb, &rt->dst);
375386
err = ip_local_out(net, skb->sk, skb);
376387
if (unlikely(net_xmit_eval(err)))
@@ -385,7 +396,7 @@ static int ipvlan_process_v4_outbound(struct sk_buff *skb, bool xnet)
385396
return ret;
386397
}
387398

388-
static int ipvlan_process_v6_outbound(struct sk_buff *skb, bool xnet)
399+
static int ipvlan_process_v6_outbound(struct sk_buff *skb)
389400
{
390401
const struct ipv6hdr *ip6h = ipv6_hdr(skb);
391402
struct net_device *dev = skb->dev;
@@ -408,7 +419,6 @@ static int ipvlan_process_v6_outbound(struct sk_buff *skb, bool xnet)
408419
dst_release(dst);
409420
goto err;
410421
}
411-
skb_scrub_packet(skb, xnet);
412422
skb_dst_set(skb, dst);
413423
err = ip6_local_out(net, skb->sk, skb);
414424
if (unlikely(net_xmit_eval(err)))
@@ -423,7 +433,7 @@ static int ipvlan_process_v6_outbound(struct sk_buff *skb, bool xnet)
423433
return ret;
424434
}
425435

426-
static int ipvlan_process_outbound(struct sk_buff *skb, bool xnet)
436+
static int ipvlan_process_outbound(struct sk_buff *skb)
427437
{
428438
struct ethhdr *ethh = eth_hdr(skb);
429439
int ret = NET_XMIT_DROP;
@@ -447,9 +457,9 @@ static int ipvlan_process_outbound(struct sk_buff *skb, bool xnet)
447457
}
448458

449459
if (skb->protocol == htons(ETH_P_IPV6))
450-
ret = ipvlan_process_v6_outbound(skb, xnet);
460+
ret = ipvlan_process_v6_outbound(skb);
451461
else if (skb->protocol == htons(ETH_P_IP))
452-
ret = ipvlan_process_v4_outbound(skb, xnet);
462+
ret = ipvlan_process_v4_outbound(skb);
453463
else {
454464
pr_warn_ratelimited("Dropped outbound packet type=%x\n",
455465
ntohs(skb->protocol));
@@ -485,7 +495,6 @@ static int ipvlan_xmit_mode_l3(struct sk_buff *skb, struct net_device *dev)
485495
void *lyr3h;
486496
struct ipvl_addr *addr;
487497
int addr_type;
488-
bool xnet;
489498

490499
lyr3h = ipvlan_get_L3_hdr(skb, &addr_type);
491500
if (!lyr3h)
@@ -496,9 +505,8 @@ static int ipvlan_xmit_mode_l3(struct sk_buff *skb, struct net_device *dev)
496505
return ipvlan_rcv_frame(addr, &skb, true);
497506

498507
out:
499-
xnet = !net_eq(dev_net(skb->dev), dev_net(ipvlan->phy_dev));
500-
skb->dev = ipvlan->phy_dev;
501-
return ipvlan_process_outbound(skb, xnet);
508+
ipvlan_skb_crossing_ns(skb, ipvlan->phy_dev);
509+
return ipvlan_process_outbound(skb);
502510
}
503511

504512
static int ipvlan_xmit_mode_l2(struct sk_buff *skb, struct net_device *dev)
@@ -528,11 +536,12 @@ static int ipvlan_xmit_mode_l2(struct sk_buff *skb, struct net_device *dev)
528536
return dev_forward_skb(ipvlan->phy_dev, skb);
529537

530538
} else if (is_multicast_ether_addr(eth->h_dest)) {
539+
ipvlan_skb_crossing_ns(skb, NULL);
531540
ipvlan_multicast_enqueue(ipvlan->port, skb);
532541
return NET_XMIT_SUCCESS;
533542
}
534543

535-
skb->dev = ipvlan->phy_dev;
544+
ipvlan_skb_crossing_ns(skb, ipvlan->phy_dev);
536545
return dev_queue_xmit(skb);
537546
}
538547

@@ -622,8 +631,10 @@ static rx_handler_result_t ipvlan_handle_mode_l2(struct sk_buff **pskb,
622631
* when work-queue processes this frame. This is
623632
* achieved by returning RX_HANDLER_PASS.
624633
*/
625-
if (nskb)
634+
if (nskb) {
635+
ipvlan_skb_crossing_ns(nskb, NULL);
626636
ipvlan_multicast_enqueue(port, nskb);
637+
}
627638
}
628639
} else {
629640
struct ipvl_addr *addr;

0 commit comments

Comments
 (0)