Skip to contentSkip to conversation

netfilter: rpfilter: skip locally generated bcast, too

PATCH Superseded Florian Westphal 2 participants 3 messages Apr 12, 2013 – Apr 16, 2013

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Florian Westphal

author maintainer
#0 lore raw

PATCH 1/1 netfilter: rpfilter: skip locally generated bcast, too

Alex Efros reported rpfilter module doesn't match following packets:
IN=br.qemu SRC=192.168.2.1 DST=192.168.2.255 [ .. ] (netfilter bugzilla #814).

Problem is that network stack arranges for the locally generated broadcasts to appear on the interface they were sent out, so the IFF_LOOPBACK check doesn't trigger.

As -m rpfilter is restricted to PREROUTING, we can check for existing skb_dst instead, it catches locally-generated broad/multicast case, too.

---
 net/ipv4/netfilter/ipt_rpfilter.c  |    2 +-
 net/ipv6/netfilter/ip6t_rpfilter.c |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
net/ipv4/netfilter/ipt_rpfilter.c +1 -1
index c301300..601abf2 100644
@@ -76,7 +76,7 @@ static bool rpfilter_mt(const struct sk_buff *skb, struct xt_action_param *par)
 	info = par->matchinfo;
 	invert = info->flags & XT_RPFILTER_INVERT;
 
-	if (par->in->flags & IFF_LOOPBACK)
+	if (skb_dst(skb)) /* locally generated? */
 		return true ^ invert;
 
 	iph = ip_hdr(skb);
net/ipv6/netfilter/ip6t_rpfilter.c +1 -1
index 5060d54..8767991 100644
@@ -78,7 +78,7 @@ static bool rpfilter_mt(const struct sk_buff *skb, struct xt_action_param *par)
 	struct ipv6hdr *iph;
 	bool invert = info->flags & XT_RPFILTER_INVERT;
 
-	if (par->in->flags & IFF_LOOPBACK)
+	if (skb_dst(skb)) /* locally generated? */
 		return true ^ invert;
 
 	iph = ipv6_hdr(skb);
Signature · 1 line
1.7.8.6
#1 lore raw

Hi Florian,

Quoted 22 lines · Florian Westphal

Alex Efros reported rpfilter module doesn't match following packets:
IN=br.qemu SRC=192.168.2.1 DST=192.168.2.255 [ .. ] (netfilter bugzilla #814).

Problem is that network stack arranges for the locally generated broadcasts to appear on the interface they were sent out, so the IFF_LOOPBACK check doesn't trigger.

As -m rpfilter is restricted to PREROUTING, we can check for existing skb_dst instead, it catches locally-generated broad/multicast case, too.

---
 net/ipv4/netfilter/ipt_rpfilter.c  |    2 +-
 net/ipv6/netfilter/ip6t_rpfilter.c |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
net/ipv4/netfilter/ipt_rpfilter.c +0 -0
index c301300..601abf2 100644

net/ipv4/netfilter/ipt_rpfilter.c static bool rpfilter_mt(const struct sk_buff *skb, struct xt_action_param *par) · line 79

Quoted 5 lines
net/ipv4/netfilter/ipt_rpfilter.c +1 -1
@@ -76,7 +76,7 @@ static bool rpfilter_mt(const struct sk_buff *skb, struct xt_action_param *par)
 	info = par->matchinfo;
 	invert = info->flags & XT_RPFILTER_INVERT;
 
-	if (par->in->flags & IFF_LOOPBACK)
+	if (skb_dst(skb)) /* locally generated? */

I'd prefer if this is narrowed down to locally generated traffic in the same way we do in nf_conntrack_broadcast.c.

author maintainer
#2 lore raw
Quoted 10 lines · Pablo Neira Ayuso

Hi Florian,

Quoted 8 lines
net/ipv4/netfilter/ipt_rpfilter.c +0 -0
index c301300..601abf2 100644
@@ -76,7 +76,7 @@ static bool rpfilter_mt(const struct sk_buff *skb, struct xt_action_param *par)
 	info = par->matchinfo;
 	invert = info->flags & XT_RPFILTER_INVERT;
 
Quoted 5 lines

net/ipv4/netfilter/ipt_rpfilter.c static bool rpfilter_mt(const struct sk_buff *skb, struct xt_action_param *par) · line 79

Quoted 2 lines
net/ipv4/netfilter/ipt_rpfilter.c +1 -1
-	if (par->in->flags & IFF_LOOPBACK)
+	if (skb_dst(skb)) /* locally generated? */

I'd prefer if this is narrowed down to locally generated traffic in the same way we do in nf_conntrack_broadcast.c.

Fair enough, i will change it.