Skip to contentSkip to conversation

objopt: restrict NFCT_GOPT_IS_{S,D}PAT to supported layer 4 protocols

PATCH New Pablo Neira Ayuso 1 participant 1 message Jun 10 netfilter

lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH v2 1/1 objopt: restrict NFCT_GOPT_IS_{S,D}PAT to supported layer 4 protocols

If layer 4 protocol has no ports, then return false. Otherwise, users like the conntrack utility filtering does not properly work with layer 4 protocol such as ICMP and ICMPv6.

Fixes b4c3a23c884c ("Introduce the new libnetfilter_conntrack API, features:")

---
v2: - incorrect field, use .protonum, not .l3protonum
- update Fixes: tag

 src/conntrack/objopt.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
src/conntrack/objopt.c +22 -0
index 1581480667e5..7e8d71d15fbe 100644
@@ -182,8 +182,27 @@ static int getobjopt_is_dnat(const struct nf_conntrack *ct)
 	}
 }
 
+static bool l4proto_has_ports(const struct nf_conntrack *ct)
+{
+	switch (ct->head.orig.protonum) {
+	case IPPROTO_UDP:
+	case IPPROTO_UDPLITE:
+	case IPPROTO_SCTP:
+	case IPPROTO_TCP:
+	case IPPROTO_DCCP:
+		break;
+	default:
+		return false;
+	}
+
+	return true;
+}
+
 static int getobjopt_is_spat(const struct nf_conntrack *ct)
 {
+	if (!l4proto_has_ports(ct))
+		return 0;
+
 	return ((test_bit(ATTR_STATUS, ct->head.set) ?
 		ct->status & IPS_SRC_NAT_DONE : 1) &&
 		ct->repl.l4dst.tcp.port !=
@@ -192,6 +211,9 @@ static int getobjopt_is_spat(const struct nf_conntrack *ct)
 
 static int getobjopt_is_dpat(const struct nf_conntrack *ct)
 {
+	if (!l4proto_has_ports(ct))
+		return 0;
+
 	return ((test_bit(ATTR_STATUS, ct->head.set) ?
 		ct->status & IPS_DST_NAT_DONE : 1) &&
 		ct->repl.l4src.tcp.port !=
Signature · 1 line
2.47.3