Skip to contentSkip to conversation

nft: use payload matching for layer 4 protocol

PATCH In review Pablo Neira Ayuso 2 participants 2 messages Jun 9, 2023 – Jun 16, 2023 netfilter

lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH 1/1 nft: use payload matching for layer 4 protocol

This is an IPv4 header, which does not require the special handling as in IPv6, use the payload matching instead of meta l4proto which is slightly faster in this case.

---
 iptables/nft-ipv4.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
iptables/nft-ipv4.c +2 -1
index d67d8198bfaf..2a5d25d8694e 100644
@@ -61,7 +61,8 @@ static int nft_ipv4_add(struct nft_handle *h, struct nftnl_rule *r,
 
 	if (cs->fw.ip.proto != 0) {
 		op = nft_invflags2cmp(cs->fw.ip.invflags, XT_INV_PROTO);
-		add_l4proto(h, r, cs->fw.ip.proto, op);
+		add_proto(h, r, offsetof(struct iphdr, protocol),
+			  sizeof(uint8_t), cs->fw.ip.proto, op);
 	}
 
 	if (cs->fw.ip.flags & IPT_F_FRAG) {
Signature · 1 line
2.30.2
reviewer
#1 lore raw
Quoted 3 lines · Pablo Neira Ayuso

This is an IPv4 header, which does not require the special handling as in IPv6, use the payload matching instead of meta l4proto which is slightly faster in this case.

Interestingly, xlate code did this distinction between IPv4 and IPv6 already. So using a payload match here is actually more consistent.

Patch applied, thanks!