Skip to content

Commit 73e20b7

Browse files
David Aherndavem330
authored andcommitted
net: vrf: Add support for PREROUTING rules on vrf device
Add support for PREROUTING rules with skb->dev set to the vrf device. INPUT rules are already allowed. Provides symmetry with the output path which allows POSTROUTING rules. Signed-off-by: David Ahern <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 8297f2d commit 73e20b7

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

drivers/net/vrf.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,25 @@ static int vrf_get_saddr(struct net_device *dev, struct flowi4 *fl4)
779779
return rc;
780780
}
781781

782+
static int vrf_rcv_finish(struct net *net, struct sock *sk, struct sk_buff *skb)
783+
{
784+
return 0;
785+
}
786+
787+
static struct sk_buff *vrf_rcv_nfhook(u8 pf, unsigned int hook,
788+
struct sk_buff *skb,
789+
struct net_device *dev)
790+
{
791+
struct net *net = dev_net(dev);
792+
793+
nf_reset(skb);
794+
795+
if (NF_HOOK(pf, hook, net, NULL, skb, dev, NULL, vrf_rcv_finish) < 0)
796+
skb = NULL; /* kfree_skb(skb) handled by nf code */
797+
798+
return skb;
799+
}
800+
782801
#if IS_ENABLED(CONFIG_IPV6)
783802
/* neighbor handling is done with actual device; do not want
784803
* to flip skb->dev for those ndisc packets. This really fails
@@ -899,6 +918,7 @@ static struct sk_buff *vrf_ip6_rcv(struct net_device *vrf_dev,
899918
if (need_strict)
900919
vrf_ip6_input_dst(skb, vrf_dev, orig_iif);
901920

921+
skb = vrf_rcv_nfhook(NFPROTO_IPV6, NF_INET_PRE_ROUTING, skb, vrf_dev);
902922
out:
903923
return skb;
904924
}
@@ -929,6 +949,7 @@ static struct sk_buff *vrf_ip_rcv(struct net_device *vrf_dev,
929949
dev_queue_xmit_nit(skb, vrf_dev);
930950
skb_pull(skb, skb->mac_len);
931951

952+
skb = vrf_rcv_nfhook(NFPROTO_IPV4, NF_INET_PRE_ROUTING, skb, vrf_dev);
932953
out:
933954
return skb;
934955
}

0 commit comments

Comments
 (0)