Skip to contentSkip to conversation

vrf: check forwarding on the original netdevice when generating ICMP dest unreachable

PATCH Superseded Stephen Suryaputra 2 participants 4 messages Feb 28, 2018

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 vrf: check forwarding on the original netdevice when generating ICMP dest unreachable

When ip_error() is called the device is the l3mdev master instead of the original device. So the forwarding check should be on the original one.

Changes from v1:
- Only need to reset the device on which __in_dev_get_rcu() is done (per David Ahern).

---
 net/ipv4/route.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
net/ipv4/route.c +9 -2
index a4f44d8..89c020f 100644
@@ -930,19 +930,26 @@ void ip_rt_send_redirect(struct sk_buff *skb)
 
 static int ip_error(struct sk_buff *skb)
 {
-	struct in_device *in_dev = __in_dev_get_rcu(skb->dev);
 	struct rtable *rt = skb_rtable(skb);
+	struct net_device *dev = skb->dev;
+	struct in_device *in_dev;
 	struct inet_peer *peer;
 	unsigned long now;
 	struct net *net;
 	bool send;
 	int code;
 
+	net = dev_net(rt->dst.dev);
+
+	if (netif_is_l3_master(skb->dev))
+		dev = __dev_get_by_index(net, IPCB(skb)->iif);
+
+	in_dev = __in_dev_get_rcu(dev);
+
 	/* IP on this device is disabled. */
 	if (!in_dev)
 		goto out;
 
-	net = dev_net(rt->dst.dev);
 	if (!IN_DEV_FORWARD(in_dev)) {
 		switch (rt->dst.error) {
 		case EHOSTUNREACH:
Signature · 1 line
2.7.4
#1 lore raw
Quoted 24 lines · Stephen Suryaputra

When ip_error() is called the device is the l3mdev master instead of the original device. So the forwarding check should be on the original one.

Changes from v1:
- Only need to reset the device on which __in_dev_get_rcu() is done (per David Ahern).

---
 net/ipv4/route.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
net/ipv4/route.c +2 -1
index a4f44d8..89c020f 100644
@@ -930,19 +930,26 @@ void ip_rt_send_redirect(struct sk_buff *skb)
 
 static int ip_error(struct sk_buff *skb)
 {
-	struct in_device *in_dev = __in_dev_get_rcu(skb->dev);
 	struct rtable *rt = skb_rtable(skb);
+	struct net_device *dev = skb->dev;
+	struct in_device *in_dev;

net/ipv4/route.c void ip_rt_send_redirect(struct sk_buff *skb) · line 945

Quoted 10 lines
net/ipv4/route.c +4 -0
 	struct inet_peer *peer;
 	unsigned long now;
 	struct net *net;
 	bool send;
 	int code;
 
+	net = dev_net(rt->dst.dev);
+
+	if (netif_is_l3_master(skb->dev))
+		dev = __dev_get_by_index(net, IPCB(skb)->iif);

Do need to handle the device disappearing.
if (!dev)

	goto out;
Quoted 12 lines
net/ipv4/route.c +3 -1
+
+	in_dev = __in_dev_get_rcu(dev);
+
 	/* IP on this device is disabled. */
 	if (!in_dev)
 		goto out;
 
-	net = dev_net(rt->dst.dev);
 	if (!IN_DEV_FORWARD(in_dev)) {
 		switch (rt->dst.error) {
 		case EHOSTUNREACH:
#2 lore raw

The concern only applies when the skb->dev is an l3mdev master, right? After I sent v2, I'm worried that rt shouldn't be derefrenced if in_dev is NULL. Even though I think it should be ok, it's better to keep the original execution order. So, how about this before I put another patch? The net for the iif is derived from skb->dev.

net/ipv4/route.c +10 -1
index a4f44d8..9a29225 100644
@@ -930,14 +930,23 @@ void ip_rt_send_redirect(struct sk_buff *skb)
 
 static int ip_error(struct sk_buff *skb)
 {
-       struct in_device *in_dev = __in_dev_get_rcu(skb->dev);
        struct rtable *rt = skb_rtable(skb);
+       struct net_device *dev = skb->dev;
+       struct in_device *in_dev;
        struct inet_peer *peer;
        unsigned long now;
        struct net *net;
        bool send;
        int code;
 
+       if (netif_is_l3_master(skb->dev)) {
+               dev = __dev_get_by_index(dev_net(skb->dev), IPCB(skb)->iif);
+               if (!dev)
+                       goto out;
+       }
+
+       in_dev = __in_dev_get_rcu(dev);
+
        /* IP on this device is disabled. */
        if (!in_dev)
                goto out;
Quoted 53 lines · David Ahern
Quoted 24 lines · Stephen Suryaputra

When ip_error() is called the device is the l3mdev master instead of the original device. So the forwarding check should be on the original one.

Changes from v1:
- Only need to reset the device on which __in_dev_get_rcu() is done (per David Ahern).

---
 net/ipv4/route.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
net/ipv4/route.c +2 -1
index a4f44d8..89c020f 100644
@@ -930,19 +930,26 @@ void ip_rt_send_redirect(struct sk_buff *skb)
 
 static int ip_error(struct sk_buff *skb)
 {
-     struct in_device *in_dev = __in_dev_get_rcu(skb->dev);
      struct rtable *rt = skb_rtable(skb);
+     struct net_device *dev = skb->dev;
+     struct in_device *in_dev;

net/ipv4/route.c void ip_rt_send_redirect(struct sk_buff *skb) · line 945

Quoted 10 lines
net/ipv4/route.c +4 -0
      struct inet_peer *peer;
      unsigned long now;
      struct net *net;
      bool send;
      int code;
 
+     net = dev_net(rt->dst.dev);
+
+     if (netif_is_l3_master(skb->dev))
+             dev = __dev_get_by_index(net, IPCB(skb)->iif);

Do need to handle the device disappearing.
if (!dev)

        goto out;
Quoted 12 lines
net/ipv4/route.c +3 -1
+
+     in_dev = __in_dev_get_rcu(dev);
+
      /* IP on this device is disabled. */
      if (!in_dev)
              goto out;
 
-     net = dev_net(rt->dst.dev);
      if (!IN_DEV_FORWARD(in_dev)) {
              switch (rt->dst.error) {
              case EHOSTUNREACH:
#3 lore raw
Quoted 26 lines · Stephen Suryaputra

The concern only applies when the skb->dev is an l3mdev master, right? After I sent v2, I'm worried that rt shouldn't be derefrenced if in_dev is NULL. Even though I think it should be ok, it's better to keep the original execution order. So, how about this before I put another patch? The net for the iif is derived from skb->dev.

net/ipv4/route.c +3 -1
index a4f44d8..9a29225 100644
@@ -930,14 +930,23 @@ void ip_rt_send_redirect(struct sk_buff *skb)
 
 static int ip_error(struct sk_buff *skb)
 {
-       struct in_device *in_dev = __in_dev_get_rcu(skb->dev);
        struct rtable *rt = skb_rtable(skb);
+       struct net_device *dev = skb->dev;
+       struct in_device *in_dev;
        struct inet_peer *peer;
        unsigned long now;
        struct net *net;
        bool send;
        int code;
 
+       if (netif_is_l3_master(skb->dev)) {

net/ipv4/route.c void ip_rt_send_redirect(struct sk_buff *skb) · line 952

Quoted 10 lines
net/ipv4/route.c +7 -0
+               dev = __dev_get_by_index(dev_net(skb->dev), IPCB(skb)->iif);
+               if (!dev)
+                       goto out;
+       }
+
+       in_dev = __in_dev_get_rcu(dev);
+
        /* IP on this device is disabled. */
        if (!in_dev)
                goto out;

Using dev_net from skb is fine, preferable really since the real ingress device and the VRF device have to be in the same network namespace.