Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f83a7ea

Browse files
Florian Westphalummakynes
authored andcommitted
netfilter: xt_rpfilter: skip locally generated broadcast/multicast, 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 torvalds#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 rtable instead, it catches locally-generated broad/multicast case, too. Signed-off-by: Florian Westphal <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 5add189 commit f83a7ea

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

net/ipv4/netfilter/ipt_rpfilter.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ static bool rpfilter_lookup_reverse(struct flowi4 *fl4,
6666
return dev_match;
6767
}
6868

69+
static bool rpfilter_is_local(const struct sk_buff *skb)
70+
{
71+
const struct rtable *rt = skb_rtable(skb);
72+
return rt && (rt->rt_flags & RTCF_LOCAL);
73+
}
74+
6975
static bool rpfilter_mt(const struct sk_buff *skb, struct xt_action_param *par)
7076
{
7177
const struct xt_rpfilter_info *info;
@@ -76,7 +82,7 @@ static bool rpfilter_mt(const struct sk_buff *skb, struct xt_action_param *par)
7682
info = par->matchinfo;
7783
invert = info->flags & XT_RPFILTER_INVERT;
7884

79-
if (par->in->flags & IFF_LOOPBACK)
85+
if (rpfilter_is_local(skb))
8086
return true ^ invert;
8187

8288
iph = ip_hdr(skb);

net/ipv6/netfilter/ip6t_rpfilter.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,20 @@ static bool rpfilter_lookup_reverse6(const struct sk_buff *skb,
7171
return ret;
7272
}
7373

74+
static bool rpfilter_is_local(const struct sk_buff *skb)
75+
{
76+
const struct rt6_info *rt = (const void *) skb_dst(skb);
77+
return rt && (rt->rt6i_flags & RTF_LOCAL);
78+
}
79+
7480
static bool rpfilter_mt(const struct sk_buff *skb, struct xt_action_param *par)
7581
{
7682
const struct xt_rpfilter_info *info = par->matchinfo;
7783
int saddrtype;
7884
struct ipv6hdr *iph;
7985
bool invert = info->flags & XT_RPFILTER_INVERT;
8086

81-
if (par->in->flags & IFF_LOOPBACK)
87+
if (rpfilter_is_local(skb))
8288
return true ^ invert;
8389

8490
iph = ipv6_hdr(skb);

0 commit comments

Comments
 (0)