Skip to contentSkip to conversation

evaluate: bail out if ct saddr/daddr dependency cannot be inserted

PATCH In review Florian Westphal 2 participants 2 messages Apr 2, 2025 – Apr 7, 2025 netfilter

lore
Share & tools
lore

Florian Westphal

author maintainer
#0 lore raw

PATCH 1/1 evaluate: bail out if ct saddr/daddr dependency cannot be inserted

If we have an incomplete rule like "ct original saddr" in inet
family, this function generates an error because it can't determine the required protocol dependency, hinting at missing ip/ip6 keyword.

We should not go on in this case to avoid a redundant followup error:

nft add rule inet f c ct original saddr 1.2.3.4
Error: cannot determine ip protocol version, use "ip saddr" or "ip6 saddr" instead add rule inet f c ct original saddr 1.2.3.4

                  ^^^^^^^^^^^^^^^^^

Error: Could not parse symbolic invalid expression add rule inet f c ct original saddr 1.2.3.4

After this change only the first error is shown.

Fixes 2b29ea5f3c3e ("src: ct: add eval part to inject dependencies for ct saddr/daddr")
---
 src/evaluate.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
src/evaluate.c +2 -1
index 0c8af09492d1..d6bb18ba2aa0 100644
@@ -1190,7 +1190,8 @@ static int expr_evaluate_ct(struct eval_ctx *ctx, struct expr **expr)
 	switch (ct->ct.key) {
 	case NFT_CT_SRC:
 	case NFT_CT_DST:
-		ct_gen_nh_dependency(ctx, ct);
+		if (ct_gen_nh_dependency(ctx, ct) < 0)
+			return -1;
 		break;
 	case NFT_CT_SRC_IP:
 	case NFT_CT_DST_IP:
Signature · 1 line
2.49.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Florian Westphal

If we have an incomplete rule like "ct original saddr" in inet
family, this function generates an error because it can't determine the required protocol dependency, hinting at missing ip/ip6 keyword.

We should not go on in this case to avoid a redundant followup error:

nft add rule inet f c ct original saddr 1.2.3.4
Error: cannot determine ip protocol version, use "ip saddr" or "ip6 saddr" instead add rule inet f c ct original saddr 1.2.3.4

Quoted 8 lines
                  ^^^^^^^^^^^^^^^^^

Error: Could not parse symbolic invalid expression add rule inet f c ct original saddr 1.2.3.4

After this change only the first error is shown.

Fixes 2b29ea5f3c3e ("src: ct: add eval part to inject dependencies for ct saddr/daddr")

Thanks Florian

Quoted 22 lines
---
 src/evaluate.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
src/evaluate.c +2 -1
index 0c8af09492d1..d6bb18ba2aa0 100644
@@ -1190,7 +1190,8 @@ static int expr_evaluate_ct(struct eval_ctx *ctx, struct expr **expr)
 	switch (ct->ct.key) {
 	case NFT_CT_SRC:
 	case NFT_CT_DST:
-		ct_gen_nh_dependency(ctx, ct);
+		if (ct_gen_nh_dependency(ctx, ct) < 0)
+			return -1;
 		break;
 	case NFT_CT_SRC_IP:
 	case NFT_CT_DST_IP:
Signature · 1 line
2.49.0