Skip to content

Commit 9ee83b0

Browse files
Liping Zhanggregkh
authored andcommitted
netfilter: nft_meta: deal with PACKET_LOOPBACK in netdev family
[ Upstream commit f169fd695b192dd7b23aff8e69d25a1bc881bbfa ] After adding the following nft rule, then ping 224.0.0.1: # nft add rule netdev t c pkttype host counter The warning complain message will be printed out again and again: WARNING: CPU: 0 PID: 10182 at net/netfilter/nft_meta.c:163 \ nft_meta_get_eval+0x3fe/0x460 [nft_meta] [...] Call Trace: <IRQ> dump_stack+0x85/0xc2 __warn+0xcb/0xf0 warn_slowpath_null+0x1d/0x20 nft_meta_get_eval+0x3fe/0x460 [nft_meta] nft_do_chain+0xff/0x5e0 [nf_tables] So we should deal with PACKET_LOOPBACK in netdev family too. For ipv4, convert it to PACKET_BROADCAST/MULTICAST according to the destination address's type; For ipv6, convert it to PACKET_MULTICAST directly. Signed-off-by: Liping Zhang <zlpnobody@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org> Signed-off-by: Sasha Levin <alexander.levin@verizon.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent cfb2cb3 commit 9ee83b0

1 file changed

Lines changed: 27 additions & 1 deletion

File tree

net/netfilter/nft_meta.c

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,34 @@ void nft_meta_get_eval(const struct nft_expr *expr,
151151
else
152152
*dest = PACKET_BROADCAST;
153153
break;
154+
case NFPROTO_NETDEV:
155+
switch (skb->protocol) {
156+
case htons(ETH_P_IP): {
157+
int noff = skb_network_offset(skb);
158+
struct iphdr *iph, _iph;
159+
160+
iph = skb_header_pointer(skb, noff,
161+
sizeof(_iph), &_iph);
162+
if (!iph)
163+
goto err;
164+
165+
if (ipv4_is_multicast(iph->daddr))
166+
*dest = PACKET_MULTICAST;
167+
else
168+
*dest = PACKET_BROADCAST;
169+
170+
break;
171+
}
172+
case htons(ETH_P_IPV6):
173+
*dest = PACKET_MULTICAST;
174+
break;
175+
default:
176+
WARN_ON_ONCE(1);
177+
goto err;
178+
}
179+
break;
154180
default:
155-
WARN_ON(1);
181+
WARN_ON_ONCE(1);
156182
goto err;
157183
}
158184
break;

0 commit comments

Comments
 (0)