[PATCH] net:ipv4: Packet is not forwarded when ingress interface is not configured with bc_forwarding

STALE1982d

3 messages, 2 authors, 2021-03-01 · open the first message on its own page

[PATCH] net:ipv4: Packet is not forwarded when ingress interface is not configured with bc_forwarding

From: Henry Shen <hidden>
Date: 2021-03-01 00:54:58

Allow an IPv4 packet with a destination address of broadcast to be forwarded 
if the ingress interface is not configured with bc_forwarding but the egress 
interface is. This is inline with Cisco's implementation of directed 
broadcast.

Henry Shen (1):
  net:ipv4: Fix pakcet not forwarded when ingress interface is not
    configured with bc_forwarding

 net/ipv4/route.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

-- 
2.30.1

[PATCH] net:ipv4: Packet is not forwarded if bc_forwarding not configured on ingress interface

From: Henry Shen <hidden>
Date: 2021-03-01 00:54:22

When an IPv4 packet with a destination address of broadcast is received
on an ingress interface, it will not be forwarded out of the egress
interface if the ingress interface is not configured with bc_forwarding 
but the egress interface is. If both the ingress and egress interfaces
are configured with bc_forwarding, the packet can be forwarded
successfully.

This patch is to be inline with Cisco's implementation that packet can be 
forwarded if ingress interface is NOT configured with bc_forwarding, 
but egress interface is.

Signed-off-by: Henry Shen <redacted>
---
 net/ipv4/route.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index 02d81d79deeb..d082b199b8c6 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -2101,6 +2101,8 @@ static int ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr,
 	struct rtable	*rth;
 	struct flowi4	fl4;
 	bool do_cache = true;
+	struct in_device *out_dev;
+	int		rcv_local = 0;
 
 	/* IP on this device is disabled. */
 
@@ -2176,12 +2178,20 @@ static int ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr,
 	}
 
 	if (res->type == RTN_BROADCAST) {
+		out_dev = in_dev_get(FIB_RES_DEV(*res));
+		if (!out_dev)
+			goto out;
+
+		if (in_dev == out_dev)
+			rcv_local = 1;
+		in_dev_put(out_dev);
 		if (IN_DEV_BFORWARD(in_dev))
 			goto make_route;
 		/* not do cache if bc_forwarding is enabled */
 		if (IPV4_DEVCONF_ALL(net, BC_FORWARDING))
 			do_cache = false;
-		goto brd_input;
+		if (rcv_local)
+			goto brd_input;
 	}
 
 	if (res->type == RTN_LOCAL) {
@@ -2197,7 +2207,8 @@ static int ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr,
 		goto no_route;
 	}
 	if (res->type != RTN_UNICAST)
-		goto martian_destination;
+		if (res->type != RTN_BROADCAST)
+			goto martian_destination;
 
 make_route:
 	err = ip_mkroute_input(skb, res, in_dev, daddr, saddr, tos, flkeys);
-- 
2.30.1

Re: [PATCH] net:ipv4: Packet is not forwarded if bc_forwarding not configured on ingress interface

From: David Ahern <hidden>
Date: 2021-03-01 03:21:40

On 2/28/21 5:53 PM, Henry Shen wrote:
When an IPv4 packet with a destination address of broadcast is received
on an ingress interface, it will not be forwarded out of the egress
interface if the ingress interface is not configured with bc_forwarding 
but the egress interface is. If both the ingress and egress interfaces
are configured with bc_forwarding, the packet can be forwarded
successfully.

This patch is to be inline with Cisco's implementation that packet can be 
forwarded if ingress interface is NOT configured with bc_forwarding, 
but egress interface is.
In Linux, forwarding decisions are made based on the ingress device, not
the egress device.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help