Skip to contentSkip to conversation

tests: xlate: generalize owner

PATCH Applied Pablo M. Bermudo Garay 2 participants 6 messages Jun 5, 2017 – Jun 6, 2017 netfilter

lore
Share & tools
lore
#3 lore raw

PATCH 3/3 xtables-translate: fix double space before comment

In reply to Pablo M. Bermudo Garay

When a comment translation immediately follows a counter statement, two spaces are printed between "counter" and "comment" keywords.

The counter statement is almost always followed by a target, so we need to move the space following "counter" to the beginning of the target translation.

---
 iptables/nft-ipv4.c          |  2 +-
 iptables/nft-ipv6.c          |  2 +-
 iptables/xtables-translate.c | 11 ++++++-----
 3 files changed, 8 insertions(+), 7 deletions(-)
iptables/nft-ipv4.c +1 -1
index e5947a7c..cf311513 100644
@@ -488,7 +488,7 @@ static int nft_ipv4_xlate(const void *data, struct xt_xlate *xl)
 		return ret;
 
 	/* Always add counters per rule, as in iptables */
-	xt_xlate_add(xl, "counter ");
+	xt_xlate_add(xl, "counter");
 	ret = xlate_action(cs, !!(cs->fw.ip.flags & IPT_F_GOTO), xl);
 
 	comment = xt_xlate_get_comment(xl);
iptables/nft-ipv6.c +1 -1
index 9cf4058f..53526369 100644
@@ -437,7 +437,7 @@ static int nft_ipv6_xlate(const void *data, struct xt_xlate *xl)
 		return ret;
 
 	/* Always add counters per rule, as in iptables */
-	xt_xlate_add(xl, "counter ");
+	xt_xlate_add(xl, "counter");
 	ret = xlate_action(cs, !!(cs->fw6.ipv6.flags & IP6T_F_GOTO), xl);
 
 	comment = xt_xlate_get_comment(xl);
iptables/xtables-translate.c +6 -5
index e049f24e..3e6c7051 100644
@@ -60,12 +60,13 @@ int xlate_action(const struct iptables_command_state *cs, bool goto_set,
 	if (cs->target != NULL) {
 		/* Standard target? */
 		if (strcmp(cs->jumpto, XTC_LABEL_ACCEPT) == 0)
-			xt_xlate_add(xl, "accept");
+			xt_xlate_add(xl, " accept");
 		else if (strcmp(cs->jumpto, XTC_LABEL_DROP) == 0)
-			xt_xlate_add(xl, "drop");
+			xt_xlate_add(xl, " drop");
 		else if (strcmp(cs->jumpto, XTC_LABEL_RETURN) == 0)
-			xt_xlate_add(xl, "return");
+			xt_xlate_add(xl, " return");
 		else if (cs->target->xlate) {
+			xt_xlate_add(xl, " ");
 			struct xt_xlate_tg_params params = {
 				.ip		= (const void *)&cs->fw,
 				.target		= cs->target->t,
@@ -79,9 +80,9 @@ int xlate_action(const struct iptables_command_state *cs, bool goto_set,
 	} else if (strlen(cs->jumpto) > 0) {
 		/* Not standard, then it's a go / jump to chain */
 		if (goto_set)
-			xt_xlate_add(xl, "goto %s", cs->jumpto);
+			xt_xlate_add(xl, " goto %s", cs->jumpto);
 		else
-			xt_xlate_add(xl, "jump %s", cs->jumpto);
+			xt_xlate_add(xl, " jump %s", cs->jumpto);
 	}
 
 	return ret;
Signature · 1 line
2.11.0
#0 lore raw

PATCH 1/3 tests: xlate: generalize owner

The owner name was hard-coded in the owner extension translation test. The translation process requires the user to exist in the system, so this commit replaces it with the usual UID_MIN value (1000).

---
 extensions/libxt_owner.txlate | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
extensions/libxt_owner.txlate +1 -1
index eeca168b..86fb0585 100644
@@ -4,5 +4,5 @@ nft add rule ip nat OUTPUT tcp dport 80 skuid 0 counter accept
 iptables-translate -t nat -A OUTPUT -p tcp --dport 80 -m owner --gid-owner 0-10 -j ACCEPT
 nft add rule ip nat OUTPUT tcp dport 80 skgid 0-10 counter accept
 
-iptables-translate -t nat -A OUTPUT -p tcp --dport 80 -m owner ! --uid-owner pablo -j ACCEPT
+iptables-translate -t nat -A OUTPUT -p tcp --dport 80 -m owner ! --uid-owner 1000 -j ACCEPT
 nft add rule ip nat OUTPUT tcp dport 80 skuid != 1000 counter accept
Signature · 1 line
2.11.0
#1 lore raw

PATCH 2/3 libip6t_icmp6: xlate: remove leftover space

This change should have been included in commit f035be35c749 ("xtables-translate: fix multiple spaces issue"), but was forgotten.

---
 extensions/libip6t_icmp6.c | 2 --
 1 file changed, 2 deletions(-)
extensions/libip6t_icmp6.c +0 -2
index b49a241d..37c2bcb8 100644
@@ -282,8 +282,6 @@ static int icmp6_xlate(struct xt_xlate *xl,
 	if (!type_xlate_print(xl, info->type, info->code[0], info->code[1]))
 		return 0;
 
-	xt_xlate_add(xl, " ");
-
 	return 1;
 }
 
Signature · 1 line
2.11.0
maintainer Applied
#5 lore raw
In reply to Pablo M. Bermudo Garay
Quoted 3 lines · Pablo M. Bermudo Garay

The owner name was hard-coded in the owner extension translation test. The translation process requires the user to exist in the system, so this commit replaces it with the usual UID_MIN value (1000).

Applied, thanks.

#2 lore raw

Re: [PATCH iptables 2/3] libip6t_icmp6: xlate: remove leftover space

In reply to Pablo M. Bermudo Garay
Quoted 2 lines · Pablo M. Bermudo Garay

This change should have been included in commit f035be35c749 ("xtables-translate: fix multiple spaces issue"), but was forgotten.

Also applied, thanks.

#4 lore raw

Re: [PATCH iptables 3/3] xtables-translate: fix double space before comment

In reply to Pablo M. Bermudo Garay
Quoted 6 lines · Pablo M. Bermudo Garay

When a comment translation immediately follows a counter statement, two spaces are printed between "counter" and "comment" keywords.

The counter statement is almost always followed by a target, so we need to move the space following "counter" to the beginning of the target translation.

Neat, applied, thanks.