Skip to content

Commit f169fd6

Browse files
Liping Zhangummakynes
authored andcommitted
netfilter: nft_meta: deal with PACKET_LOOPBACK in netdev family
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 <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 9a6d876 commit f169fd6

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

net/netfilter/nft_meta.c

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,34 @@ void nft_meta_get_eval(const struct nft_expr *expr,
156156
case NFPROTO_IPV6:
157157
*dest = PACKET_MULTICAST;
158158
break;
159+
case NFPROTO_NETDEV:
160+
switch (skb->protocol) {
161+
case htons(ETH_P_IP): {
162+
int noff = skb_network_offset(skb);
163+
struct iphdr *iph, _iph;
164+
165+
iph = skb_header_pointer(skb, noff,
166+
sizeof(_iph), &_iph);
167+
if (!iph)
168+
goto err;
169+
170+
if (ipv4_is_multicast(iph->daddr))
171+
*dest = PACKET_MULTICAST;
172+
else
173+
*dest = PACKET_BROADCAST;
174+
175+
break;
176+
}
177+
case htons(ETH_P_IPV6):
178+
*dest = PACKET_MULTICAST;
179+
break;
180+
default:
181+
WARN_ON_ONCE(1);
182+
goto err;
183+
}
184+
break;
159185
default:
160-
WARN_ON(1);
186+
WARN_ON_ONCE(1);
161187
goto err;
162188
}
163189
break;

0 commit comments

Comments
 (0)