Skip to contentSkip to conversation

xtables-translate-restore: do not escape quotes

PATCH Applied Pablo M. Bermudo Garay 2 participants 2 messages Aug 31, 2016 – Sep 5, 2016 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 xtables-translate-restore: do not escape quotes

If quotes are escaped, nft -f is unable to parse and load the translated ruleset.

---

Changes in v3:
- Add a new field to the iptables_command_state struct instead of propagate 'bool restore' argument.

 iptables/xshared.h           | 1 +
 iptables/xtables-translate.c | 6 ++++--
 2 files changed, 5 insertions(+), 2 deletions(-)
iptables/xshared.h +1 -0
index 6eb8eb8..18b1cf3 100644
@@ -63,6 +63,7 @@ struct iptables_command_state {
 	int proto_used;
 	const char *jumpto;
 	char **argv;
+	bool restore;
 };
 
 typedef int (*mainfunc_t)(int, char **);
iptables/xtables-translate.c +4 -2
index 3c577ed..689533f 100644
@@ -70,7 +70,7 @@ int xlate_action(const struct iptables_command_state *cs, bool goto_set,
 				.ip		= (const void *)&cs->fw,
 				.target		= cs->target->t,
 				.numeric	= numeric,
-				.escape_quotes	= true,
+				.escape_quotes	= !cs->restore,
 			};
 			ret = cs->target->xlate(xl, &params);
 		}
@@ -97,7 +97,7 @@ int xlate_matches(const struct iptables_command_state *cs, struct xt_xlate *xl)
 			.ip		= (const void *)&cs->fw,
 			.match		= matchp->match->m,
 			.numeric	= numeric,
-			.escape_quotes	= true,
+			.escape_quotes	= !cs->restore,
 		};
 
 		if (!matchp->match->xlate)
@@ -226,6 +226,8 @@ static int do_command_xlate(struct nft_handle *h, int argc, char *argv[],
 
 	do_parse(h, argc, argv, &p, &cs, &args);
 
+	cs.restore = restore;
+
 	if (!restore)
 		printf("nft ");
 
Signature · 1 line
2.9.3
maintainer Applied
#1 lore raw
Quoted 2 lines · Pablo M. Bermudo Garay

If quotes are escaped, nft -f is unable to parse and load the translated ruleset.

Applied, thanks.

It would be good to set 'cs->restore' in iptables and ip6tables.

Currently this is left unset and not used, which leaves things in inconsistent state. Please follow up on this.