Skip to contentSkip to conversation

tcp_xlate: Enclose LH flag values in parentheses

PATCH In review Phil Sutter 2 participants 2 messages Nov 29, 2016 netfilter

lore
Share & tools
lore

Phil Sutter

author reviewer
#0 lore raw

PATCH 1/1 tcp_xlate: Enclose LH flag values in parentheses

This fixes TCP flags matches:

| $ iptables-translate -A invalid -p tcp --tcp-flags SYN,FIN SYN,FIN -j DROP | nft add rule ip filter invalid tcp flags & fin|syn == fin|syn counter drop

Although the generated rule is syntactically correct and accepted by nft, it will be interpreted in a different way than expected since binary AND takes precedence over OR.

---
 extensions/libxt_tcp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
extensions/libxt_tcp.c +2 -2
index 7f68b81288725..58f3c0a0c3c28 100644
@@ -435,9 +435,9 @@ static int tcp_xlate(struct xt_xlate *xl,
 		return 0;
 
 	if (tcpinfo->flg_mask || (tcpinfo->invflags & XT_TCP_INV_FLAGS)) {
-		xt_xlate_add(xl, "%stcp flags & ", space);
+		xt_xlate_add(xl, "%stcp flags & (", space);
 		print_tcp_xlate(xl, tcpinfo->flg_mask);
-		xt_xlate_add(xl, " %s ",
+		xt_xlate_add(xl, ") %s ",
 			   tcpinfo->invflags & XT_TCP_INV_FLAGS ? "!=": "==");
 		print_tcp_xlate(xl, tcpinfo->flg_cmp);
 	}
Signature · 1 line
2.10.0
#1 lore raw
Quoted 8 lines · Phil Sutter

This fixes TCP flags matches:

| $ iptables-translate -A invalid -p tcp --tcp-flags SYN,FIN SYN,FIN -j DROP | nft add rule ip filter invalid tcp flags & fin|syn == fin|syn counter drop

Although the generated rule is syntactically correct and accepted by nft, it will be interpreted in a different way than expected since binary AND takes precedence over OR.

And this one also applied, thanks!