diff mbox series

[nf-next] netfilter: nft_meta: infer ptktype from IP address from the output path

Message ID 20211026112521.1278472-1-pablo@netfilter.org
State Changes Requested
Delegated to: Pablo Neira
Headers show
Series [nf-next] netfilter: nft_meta: infer ptktype from IP address from the output path | expand

Commit Message

Pablo Neira Ayuso Oct. 26, 2021, 11:25 a.m. UTC
meta pkttype always says 0 (host) from the output path. The code to
infer the packet type from the IP address is already in place for
loopback traffic, extend it to infer it the packet type from the output,
postrouting and egress path too.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 net/netfilter/nft_meta.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/net/netfilter/nft_meta.c b/net/netfilter/nft_meta.c
index 516e74635bae..58a87205be8e 100644
--- a/net/netfilter/nft_meta.c
+++ b/net/netfilter/nft_meta.c
@@ -371,7 +371,11 @@  void nft_meta_get_eval(const struct nft_expr *expr,
 		break;
 #endif
 	case NFT_META_PKTTYPE:
-		if (skb->pkt_type != PACKET_LOOPBACK) {
+		if (skb->pkt_type != PACKET_LOOPBACK &&
+		    nft_hook(pkt) != NF_INET_LOCAL_OUT &&
+		    nft_hook(pkt) != NF_INET_POST_ROUTING &&
+		    (nft_pf(pkt) == NFPROTO_NETDEV &&
+		     nft_hook(pkt) != NF_NETDEV_EGRESS)) {
 			nft_reg_store8(dest, skb->pkt_type);
 			break;
 		}