laurenceman / rpms / iptables

Forked from rpms/iptables 5 years ago
Clone

Blame SOURCES/0048-Revert-ebtables-use-extrapositioned-negation-consist.patch

029dc7
From af890b239555d52c269d224ada6382381320585d Mon Sep 17 00:00:00 2001
029dc7
From: Phil Sutter <phil@nwl.cc>
029dc7
Date: Tue, 5 Feb 2019 18:18:02 +0100
029dc7
Subject: [PATCH] Revert "ebtables: use extrapositioned negation consistently"
029dc7
029dc7
This reverts commit 5f508b76a0cebaf91965ffa678089222e2d47964.
029dc7
029dc7
While attempts at unifying syntax between arp-, eb- and iptables-nft
029dc7
increase the opportunity for more code-sharing, they are problematic
029dc7
when it comes to compatibility. Accepting the old syntax on input helps,
029dc7
but due to the fact that neither arptables nor ebtables support --check
029dc7
command we must expect for users to test existence of a rule by
029dc7
comparing input with output. If that happens in a script, deviating from
029dc7
the old syntax in output has a high chance of breaking it.
029dc7
029dc7
Therefore revert Florian's patch changing inversion character position
029dc7
in output and review the old code for consistency - the only thing
029dc7
changed on top of the actual revert is ebtables' own copy of
029dc7
print_iface() to make it adhere to the intrapositioned negation scheme
029dc7
used throughout ebtables.
029dc7
029dc7
Added extension tests by the reverted commit have been kept.
029dc7
029dc7
Signed-off-by: Phil Sutter <phil@nwl.cc>
029dc7
Signed-off-by: Florian Westphal <fw@strlen.de>
029dc7
(cherry picked from commit 35b22e82fa62e10950d8e0fa53a755d4abadf346)
029dc7
Signed-off-by: Phil Sutter <psutter@redhat.com>
029dc7
---
029dc7
 extensions/libebt_802_3.c    |  4 ++--
029dc7
 extensions/libebt_802_3.t    |  2 +-
029dc7
 extensions/libebt_arp.c      | 14 +++++++-------
029dc7
 extensions/libebt_arp.t      |  8 ++++----
029dc7
 extensions/libebt_ip.c       | 16 ++++++++--------
029dc7
 extensions/libebt_ip.t       |  6 +++---
029dc7
 extensions/libebt_ip6.c      | 14 +++++++-------
029dc7
 extensions/libebt_ip6.t      |  6 +++---
029dc7
 extensions/libebt_mark_m.c   |  2 +-
029dc7
 extensions/libebt_mark_m.t   |  4 ++--
029dc7
 extensions/libebt_pkttype.c  |  5 +----
029dc7
 extensions/libebt_pkttype.t  | 13 +++++++------
029dc7
 extensions/libebt_standard.t |  4 ++--
029dc7
 extensions/libebt_stp.c      |  5 ++---
029dc7
 extensions/libebt_vlan.c     | 13 ++++---------
029dc7
 extensions/libebt_vlan.t     | 10 +++++-----
029dc7
 iptables/nft-bridge.c        |  6 +++---
029dc7
 17 files changed, 62 insertions(+), 70 deletions(-)
029dc7
029dc7
diff --git a/extensions/libebt_802_3.c b/extensions/libebt_802_3.c
029dc7
index 9e91d05262591..f05d02ead5a4a 100644
029dc7
--- a/extensions/libebt_802_3.c
029dc7
+++ b/extensions/libebt_802_3.c
029dc7
@@ -98,15 +98,15 @@ static void br802_3_print(const void *ip, const struct xt_entry_match *match,
029dc7
 	struct ebt_802_3_info *info = (struct ebt_802_3_info *)match->data;
029dc7
 
029dc7
 	if (info->bitmask & EBT_802_3_SAP) {
029dc7
+		printf("--802_3-sap ");
029dc7
 		if (info->invflags & EBT_802_3_SAP)
029dc7
 			printf("! ");
029dc7
-		printf("--802_3-sap ");
029dc7
 		printf("0x%.2x ", info->sap);
029dc7
 	}
029dc7
 	if (info->bitmask & EBT_802_3_TYPE) {
029dc7
+		printf("--802_3-type ");
029dc7
 		if (info->invflags & EBT_802_3_TYPE)
029dc7
 			printf("! ");
029dc7
-		printf("--802_3-type ");
029dc7
 		printf("0x%.4x ", ntohs(info->type));
029dc7
 	}
029dc7
 }
029dc7
diff --git a/extensions/libebt_802_3.t b/extensions/libebt_802_3.t
029dc7
index 61081bd6983a8..ddfb2f0a72baf 100644
029dc7
--- a/extensions/libebt_802_3.t
029dc7
+++ b/extensions/libebt_802_3.t
029dc7
@@ -1,3 +1,3 @@
029dc7
 :INPUT,FORWARD,OUTPUT
029dc7
-! --802_3-sap 0x0a -j CONTINUE;=;OK
029dc7
+--802_3-sap ! 0x0a -j CONTINUE;=;OK
029dc7
 --802_3-type 0x000a -j RETURN;=;OK
029dc7
diff --git a/extensions/libebt_arp.c b/extensions/libebt_arp.c
029dc7
index c1b0ab1db0cf1..a062b7e7e5864 100644
029dc7
--- a/extensions/libebt_arp.c
029dc7
+++ b/extensions/libebt_arp.c
029dc7
@@ -338,51 +338,51 @@ static void brarp_print(const void *ip, const struct xt_entry_match *match, int
029dc7
 
029dc7
 	if (arpinfo->bitmask & EBT_ARP_OPCODE) {
029dc7
 		int opcode = ntohs(arpinfo->opcode);
029dc7
+		printf("--arp-op ");
029dc7
 		if (arpinfo->invflags & EBT_ARP_OPCODE)
029dc7
 			printf("! ");
029dc7
-		printf("--arp-op ");
029dc7
 		if (opcode > 0 && opcode <= ARRAY_SIZE(opcodes))
029dc7
 			printf("%s ", opcodes[opcode - 1]);
029dc7
 		else
029dc7
 			printf("%d ", opcode);
029dc7
 	}
029dc7
 	if (arpinfo->bitmask & EBT_ARP_HTYPE) {
029dc7
+		printf("--arp-htype ");
029dc7
 		if (arpinfo->invflags & EBT_ARP_HTYPE)
029dc7
 			printf("! ");
029dc7
-		printf("--arp-htype ");
029dc7
 		printf("%d ", ntohs(arpinfo->htype));
029dc7
 	}
029dc7
 	if (arpinfo->bitmask & EBT_ARP_PTYPE) {
029dc7
+		printf("--arp-ptype ");
029dc7
 		if (arpinfo->invflags & EBT_ARP_PTYPE)
029dc7
 			printf("! ");
029dc7
-		printf("--arp-ptype ");
029dc7
 		printf("0x%x ", ntohs(arpinfo->ptype));
029dc7
 	}
029dc7
 	if (arpinfo->bitmask & EBT_ARP_SRC_IP) {
029dc7
+		printf("--arp-ip-src ");
029dc7
 		if (arpinfo->invflags & EBT_ARP_SRC_IP)
029dc7
 			printf("! ");
029dc7
-		printf("--arp-ip-src ");
029dc7
 		printf("%s%s ", xtables_ipaddr_to_numeric((const struct in_addr*) &arpinfo->saddr),
029dc7
 		       xtables_ipmask_to_numeric((const struct in_addr*)&arpinfo->smsk));
029dc7
 	}
029dc7
 	if (arpinfo->bitmask & EBT_ARP_DST_IP) {
029dc7
+		printf("--arp-ip-dst ");
029dc7
 		if (arpinfo->invflags & EBT_ARP_DST_IP)
029dc7
 			printf("! ");
029dc7
-		printf("--arp-ip-dst ");
029dc7
 		printf("%s%s ", xtables_ipaddr_to_numeric((const struct in_addr*) &arpinfo->daddr),
029dc7
 		       xtables_ipmask_to_numeric((const struct in_addr*)&arpinfo->dmsk));
029dc7
 	}
029dc7
 	if (arpinfo->bitmask & EBT_ARP_SRC_MAC) {
029dc7
+		printf("--arp-mac-src ");
029dc7
 		if (arpinfo->invflags & EBT_ARP_SRC_MAC)
029dc7
 			printf("! ");
029dc7
-		printf("--arp-mac-src ");
029dc7
 		xtables_print_mac_and_mask(arpinfo->smaddr, arpinfo->smmsk);
029dc7
 		printf(" ");
029dc7
 	}
029dc7
 	if (arpinfo->bitmask & EBT_ARP_DST_MAC) {
029dc7
+		printf("--arp-mac-dst ");
029dc7
 		if (arpinfo->invflags & EBT_ARP_DST_MAC)
029dc7
 			printf("! ");
029dc7
-		printf("--arp-mac-dst ");
029dc7
 		xtables_print_mac_and_mask(arpinfo->dmaddr, arpinfo->dmmsk);
029dc7
 		printf(" ");
029dc7
 	}
029dc7
diff --git a/extensions/libebt_arp.t b/extensions/libebt_arp.t
029dc7
index a05ab12dc566f..14ff0f097cfd8 100644
029dc7
--- a/extensions/libebt_arp.t
029dc7
+++ b/extensions/libebt_arp.t
029dc7
@@ -1,11 +1,11 @@
029dc7
 :INPUT,FORWARD,OUTPUT
029dc7
 -p ARP --arp-op Request;=;OK
029dc7
--p ARP ! --arp-htype 1;=;OK
029dc7
+-p ARP --arp-htype ! 1;=;OK
029dc7
 -p ARP --arp-ptype 0x2;=;OK
029dc7
 -p ARP --arp-ip-src 1.2.3.4;=;OK
029dc7
--p ARP ! --arp-ip-dst 1.2.3.4;=;OK
029dc7
--p ARP ! --arp-ip-src 0.0.0.0;=;OK
029dc7
--p ARP ! --arp-ip-dst 0.0.0.0/8;=;OK
029dc7
+-p ARP ! --arp-ip-dst 1.2.3.4;-p ARP --arp-ip-dst ! 1.2.3.4 -j CONTINUE;OK
029dc7
+-p ARP --arp-ip-src ! 0.0.0.0;=;OK
029dc7
+-p ARP --arp-ip-dst ! 0.0.0.0/8;=;OK
029dc7
 -p ARP --arp-mac-src 00:de:ad:be:ef:00;=;OK
029dc7
 -p ARP --arp-mac-dst de:ad:be:ef:00:00/ff:ff:ff:ff:00:00;=;OK
029dc7
 -p ARP --arp-gratuitous;=;OK
029dc7
diff --git a/extensions/libebt_ip.c b/extensions/libebt_ip.c
029dc7
index d48704fe1c802..acb9bfcdbbd9f 100644
029dc7
--- a/extensions/libebt_ip.c
029dc7
+++ b/extensions/libebt_ip.c
029dc7
@@ -472,35 +472,35 @@ static void brip_print(const void *ip, const struct xt_entry_match *match,
029dc7
 	struct in_addr *addrp, *maskp;
029dc7
 
029dc7
 	if (info->bitmask & EBT_IP_SOURCE) {
029dc7
+		printf("--ip-src ");
029dc7
 		if (info->invflags & EBT_IP_SOURCE)
029dc7
 			printf("! ");
029dc7
-		printf("--ip-src ");
029dc7
 		addrp = (struct in_addr *)&info->saddr;
029dc7
 		maskp = (struct in_addr *)&info->smsk;
029dc7
 		printf("%s%s ", xtables_ipaddr_to_numeric(addrp),
029dc7
 		       xtables_ipmask_to_numeric(maskp));
029dc7
 	}
029dc7
 	if (info->bitmask & EBT_IP_DEST) {
029dc7
+		printf("--ip-dst ");
029dc7
 		if (info->invflags & EBT_IP_DEST)
029dc7
 			printf("! ");
029dc7
-		printf("--ip-dst ");
029dc7
 		addrp = (struct in_addr *)&info->daddr;
029dc7
 		maskp = (struct in_addr *)&info->dmsk;
029dc7
 		printf("%s%s ", xtables_ipaddr_to_numeric(addrp),
029dc7
 		       xtables_ipmask_to_numeric(maskp));
029dc7
 	}
029dc7
 	if (info->bitmask & EBT_IP_TOS) {
029dc7
+		printf("--ip-tos ");
029dc7
 		if (info->invflags & EBT_IP_TOS)
029dc7
 			printf("! ");
029dc7
-		printf("--ip-tos ");
029dc7
 		printf("0x%02X ", info->tos);
029dc7
 	}
029dc7
 	if (info->bitmask & EBT_IP_PROTO) {
029dc7
 		struct protoent *pe;
029dc7
 
029dc7
+		printf("--ip-proto ");
029dc7
 		if (info->invflags & EBT_IP_PROTO)
029dc7
 			printf("! ");
029dc7
-		printf("--ip-proto ");
029dc7
 		pe = getprotobynumber(info->protocol);
029dc7
 		if (pe == NULL) {
029dc7
 			printf("%d ", info->protocol);
029dc7
@@ -509,28 +509,28 @@ static void brip_print(const void *ip, const struct xt_entry_match *match,
029dc7
 		}
029dc7
 	}
029dc7
 	if (info->bitmask & EBT_IP_SPORT) {
029dc7
+		printf("--ip-sport ");
029dc7
 		if (info->invflags & EBT_IP_SPORT)
029dc7
 			printf("! ");
029dc7
-		printf("--ip-sport ");
029dc7
 		print_port_range(info->sport);
029dc7
 	}
029dc7
 	if (info->bitmask & EBT_IP_DPORT) {
029dc7
+		printf("--ip-dport ");
029dc7
 		if (info->invflags & EBT_IP_DPORT)
029dc7
 			printf("! ");
029dc7
-		printf("--ip-dport ");
029dc7
 		print_port_range(info->dport);
029dc7
 	}
029dc7
 	if (info->bitmask & EBT_IP_ICMP) {
029dc7
+		printf("--ip-icmp-type ");
029dc7
 		if (info->invflags & EBT_IP_ICMP)
029dc7
 			printf("! ");
029dc7
-		printf("--ip-icmp-type ");
029dc7
 		ebt_print_icmp_type(icmp_codes, ARRAY_SIZE(icmp_codes),
029dc7
 				    info->icmp_type, info->icmp_code);
029dc7
 	}
029dc7
 	if (info->bitmask & EBT_IP_IGMP) {
029dc7
+		printf("--ip-igmp-type ");
029dc7
 		if (info->invflags & EBT_IP_IGMP)
029dc7
 			printf("! ");
029dc7
-		printf("--ip-igmp-type ");
029dc7
 		ebt_print_icmp_type(igmp_types, ARRAY_SIZE(igmp_types),
029dc7
 				    info->igmp_type, NULL);
029dc7
 	}
029dc7
diff --git a/extensions/libebt_ip.t b/extensions/libebt_ip.t
029dc7
index 01a91a7385fcc..8be5dfbb22309 100644
029dc7
--- a/extensions/libebt_ip.t
029dc7
+++ b/extensions/libebt_ip.t
029dc7
@@ -1,13 +1,13 @@
029dc7
 :INPUT,FORWARD,OUTPUT
029dc7
--p ip --ip-src ! 192.168.0.0/24 -j ACCEPT;-p IPv4 ! --ip-src 192.168.0.0/24 -j ACCEPT;OK
029dc7
+-p ip --ip-src ! 192.168.0.0/24 -j ACCEPT;-p IPv4 --ip-src ! 192.168.0.0/24 -j ACCEPT;OK
029dc7
 -p IPv4 --ip-dst 10.0.0.1;=;OK
029dc7
 -p IPv4 --ip-tos 0xFF;=;OK
029dc7
--p IPv4 ! --ip-tos 0xFF;=;OK
029dc7
+-p IPv4 --ip-tos ! 0xFF;=;OK
029dc7
 -p IPv4 --ip-proto tcp --ip-dport 22;=;OK
029dc7
 -p IPv4 --ip-proto udp --ip-sport 1024:65535;=;OK
029dc7
 -p IPv4 --ip-proto 253;=;OK
029dc7
 -p IPv4 --ip-proto icmp --ip-icmp-type echo-request;=;OK
029dc7
 -p IPv4 --ip-proto icmp --ip-icmp-type 1/1;=;OK
029dc7
--p ip --ip-protocol icmp --ip-icmp-type ! 1:10;-p IPv4 --ip-proto icmp ! --ip-icmp-type 1:10/0:255 -j CONTINUE;OK
029dc7
+-p ip --ip-protocol icmp --ip-icmp-type ! 1:10;-p IPv4 --ip-proto icmp --ip-icmp-type ! 1:10/0:255 -j CONTINUE;OK
029dc7
 --ip-proto icmp --ip-icmp-type 1/1;=;FAIL
029dc7
 ! -p ip --ip-proto icmp --ip-icmp-type 1/1;=;FAIL
029dc7
diff --git a/extensions/libebt_ip6.c b/extensions/libebt_ip6.c
029dc7
index b727764903ffa..b8a5a5d8c3a92 100644
029dc7
--- a/extensions/libebt_ip6.c
029dc7
+++ b/extensions/libebt_ip6.c
029dc7
@@ -399,31 +399,31 @@ static void brip6_print(const void *ip, const struct xt_entry_match *match,
029dc7
 	struct ebt_ip6_info *ipinfo = (struct ebt_ip6_info *)match->data;
029dc7
 
029dc7
 	if (ipinfo->bitmask & EBT_IP6_SOURCE) {
029dc7
+		printf("--ip6-src ");
029dc7
 		if (ipinfo->invflags & EBT_IP6_SOURCE)
029dc7
 			printf("! ");
029dc7
-		printf("--ip6-src ");
029dc7
 		printf("%s", xtables_ip6addr_to_numeric(&ipinfo->saddr));
029dc7
 		printf("%s ", xtables_ip6mask_to_numeric(&ipinfo->smsk));
029dc7
 	}
029dc7
 	if (ipinfo->bitmask & EBT_IP6_DEST) {
029dc7
+		printf("--ip6-dst ");
029dc7
 		if (ipinfo->invflags & EBT_IP6_DEST)
029dc7
 			printf("! ");
029dc7
-		printf("--ip6-dst ");
029dc7
 		printf("%s", xtables_ip6addr_to_numeric(&ipinfo->daddr));
029dc7
 		printf("%s ", xtables_ip6mask_to_numeric(&ipinfo->dmsk));
029dc7
 	}
029dc7
 	if (ipinfo->bitmask & EBT_IP6_TCLASS) {
029dc7
+		printf("--ip6-tclass ");
029dc7
 		if (ipinfo->invflags & EBT_IP6_TCLASS)
029dc7
 			printf("! ");
029dc7
-		printf("--ip6-tclass ");
029dc7
 		printf("0x%02X ", ipinfo->tclass);
029dc7
 	}
029dc7
 	if (ipinfo->bitmask & EBT_IP6_PROTO) {
029dc7
 		struct protoent *pe;
029dc7
 
029dc7
+		printf("--ip6-proto ");
029dc7
 		if (ipinfo->invflags & EBT_IP6_PROTO)
029dc7
 			printf("! ");
029dc7
-		printf("--ip6-proto ");
029dc7
 		pe = getprotobynumber(ipinfo->protocol);
029dc7
 		if (pe == NULL) {
029dc7
 			printf("%d ", ipinfo->protocol);
029dc7
@@ -432,21 +432,21 @@ static void brip6_print(const void *ip, const struct xt_entry_match *match,
029dc7
 		}
029dc7
 	}
029dc7
 	if (ipinfo->bitmask & EBT_IP6_SPORT) {
029dc7
+		printf("--ip6-sport ");
029dc7
 		if (ipinfo->invflags & EBT_IP6_SPORT)
029dc7
 			printf("! ");
029dc7
-		printf("--ip6-sport ");
029dc7
 		print_port_range(ipinfo->sport);
029dc7
 	}
029dc7
 	if (ipinfo->bitmask & EBT_IP6_DPORT) {
029dc7
+		printf("--ip6-dport ");
029dc7
 		if (ipinfo->invflags & EBT_IP6_DPORT)
029dc7
 			printf("! ");
029dc7
-		printf("--ip6-dport ");
029dc7
 		print_port_range(ipinfo->dport);
029dc7
 	}
029dc7
 	if (ipinfo->bitmask & EBT_IP6_ICMP6) {
029dc7
+		printf("--ip6-icmp-type ");
029dc7
 		if (ipinfo->invflags & EBT_IP6_ICMP6)
029dc7
 			printf("! ");
029dc7
-		printf("--ip6-icmp-type ");
029dc7
 		print_icmp_type(ipinfo->icmpv6_type, ipinfo->icmpv6_code);
029dc7
 	}
029dc7
 }
029dc7
diff --git a/extensions/libebt_ip6.t b/extensions/libebt_ip6.t
029dc7
index 6b3221ea58f62..fa1038af25649 100644
029dc7
--- a/extensions/libebt_ip6.t
029dc7
+++ b/extensions/libebt_ip6.t
029dc7
@@ -1,15 +1,15 @@
029dc7
 :INPUT,FORWARD,OUTPUT
029dc7
--p ip6 ! --ip6-src dead::beef/64 -j ACCEPT;-p IPv6 ! --ip6-src dead::/64 -j ACCEPT;OK
029dc7
+-p ip6 --ip6-src ! dead::beef/64 -j ACCEPT;-p IPv6 --ip6-src ! dead::/64 -j ACCEPT;OK
029dc7
 -p IPv6 --ip6-dst dead:beef::/64 -j ACCEPT;=;OK
029dc7
 -p IPv6 --ip6-dst f00:ba::;=;OK
029dc7
 -p IPv6 --ip6-tclass 0xFF;=;OK
029dc7
 -p IPv6 --ip6-proto tcp --ip6-dport 22;=;OK
029dc7
--p IPv6 --ip6-proto tcp ! --ip6-dport 22;=;OK
029dc7
+-p IPv6 --ip6-proto tcp --ip6-dport ! 22;=;OK
029dc7
 -p IPv6 --ip6-proto udp --ip6-sport 1024:65535;=;OK
029dc7
 -p IPv6 --ip6-proto 253;=;OK
029dc7
 -p IPv6 --ip6-proto ipv6-icmp --ip6-icmp-type echo-request -j CONTINUE;=;OK
029dc7
 -p IPv6 --ip6-proto ipv6-icmp --ip6-icmp-type echo-request;=;OK
029dc7
 -p ip6 --ip6-protocol icmpv6 --ip6-icmp-type 1/1;-p IPv6 --ip6-proto ipv6-icmp --ip6-icmp-type communication-prohibited -j CONTINUE;OK
029dc7
--p IPv6 --ip6-proto ipv6-icmp ! --ip6-icmp-type 1:10/0:255;=;OK
029dc7
+-p IPv6 --ip6-proto ipv6-icmp --ip6-icmp-type ! 1:10/0:255;=;OK
029dc7
 --ip6-proto ipv6-icmp ! --ip6-icmp-type 1:10/0:255;=;FAIL
029dc7
 ! -p IPv6 --ip6-proto ipv6-icmp ! --ip6-icmp-type 1:10/0:255;=;FAIL
029dc7
diff --git a/extensions/libebt_mark_m.c b/extensions/libebt_mark_m.c
029dc7
index 64ad926f19959..2462d0af7d0bc 100644
029dc7
--- a/extensions/libebt_mark_m.c
029dc7
+++ b/extensions/libebt_mark_m.c
029dc7
@@ -86,9 +86,9 @@ static void brmark_m_print(const void *ip, const struct xt_entry_match *match,
029dc7
 {
029dc7
 	struct ebt_mark_m_info *info = (struct ebt_mark_m_info *)match->data;
029dc7
 
029dc7
+	printf("--mark ");
029dc7
 	if (info->invert)
029dc7
 		printf("! ");
029dc7
-	printf("--mark ");
029dc7
 	if (info->bitmask == EBT_MARK_OR)
029dc7
 		printf("/0x%lx ", info->mask);
029dc7
 	else if (info->mask != 0xffffffff)
029dc7
diff --git a/extensions/libebt_mark_m.t b/extensions/libebt_mark_m.t
029dc7
index 9ad41704fbb82..00035427f8b6e 100644
029dc7
--- a/extensions/libebt_mark_m.t
029dc7
+++ b/extensions/libebt_mark_m.t
029dc7
@@ -1,6 +1,6 @@
029dc7
 :INPUT,FORWARD,OUTPUT
029dc7
 --mark 42;--mark 0x2a;OK
029dc7
---mark ! 42;! --mark 0x2a;OK
029dc7
+--mark ! 42;--mark ! 0x2a;OK
029dc7
 --mark 42/0xff;--mark 0x2a/0xff;OK
029dc7
-! --mark 0x1/0xff;=;OK
029dc7
+--mark ! 0x1/0xff;=;OK
029dc7
 --mark /0x2;=;OK
029dc7
diff --git a/extensions/libebt_pkttype.c b/extensions/libebt_pkttype.c
029dc7
index 265674d19bde6..4e2d19de7983b 100644
029dc7
--- a/extensions/libebt_pkttype.c
029dc7
+++ b/extensions/libebt_pkttype.c
029dc7
@@ -75,10 +75,7 @@ static void brpkttype_print(const void *ip, const struct xt_entry_match *match,
029dc7
 {
029dc7
 	struct ebt_pkttype_info *pt = (struct ebt_pkttype_info *)match->data;
029dc7
 
029dc7
-	if (pt->invert)
029dc7
-		printf("! ");
029dc7
-
029dc7
-	printf("--pkttype-type ");
029dc7
+	printf("--pkttype-type %s", pt->invert ? "! " : "");
029dc7
 
029dc7
 	if (pt->pkt_type < ARRAY_SIZE(classes))
029dc7
 		printf("%s ", classes[pt->pkt_type]);
029dc7
diff --git a/extensions/libebt_pkttype.t b/extensions/libebt_pkttype.t
029dc7
index f870f5c7f05c4..e3b95ded4903e 100644
029dc7
--- a/extensions/libebt_pkttype.t
029dc7
+++ b/extensions/libebt_pkttype.t
029dc7
@@ -1,13 +1,14 @@
029dc7
 :INPUT,FORWARD,OUTPUT
029dc7
+! --pkttype-type host;--pkttype-type ! host -j CONTINUE;OK
029dc7
 --pkttype-type host;=;OK
029dc7
-! --pkttype-type host;=;OK
029dc7
+--pkttype-type ! host;=;OK
029dc7
 --pkttype-type broadcast;=;OK
029dc7
-! --pkttype-type broadcast;=;OK
029dc7
+--pkttype-type ! broadcast;=;OK
029dc7
 --pkttype-type multicast;=;OK
029dc7
-! --pkttype-type multicast;=;OK
029dc7
+--pkttype-type ! multicast;=;OK
029dc7
 --pkttype-type otherhost;=;OK
029dc7
-! --pkttype-type otherhost;=;OK
029dc7
+--pkttype-type ! otherhost;=;OK
029dc7
 --pkttype-type outgoing;=;OK
029dc7
-! --pkttype-type outgoing;=;OK
029dc7
+--pkttype-type ! outgoing;=;OK
029dc7
 --pkttype-type loopback;=;OK
029dc7
-! --pkttype-type loopback;=;OK
029dc7
+--pkttype-type ! loopback;=;OK
029dc7
diff --git a/extensions/libebt_standard.t b/extensions/libebt_standard.t
029dc7
index 72081fd6575a0..0d678fb23c439 100644
029dc7
--- a/extensions/libebt_standard.t
029dc7
+++ b/extensions/libebt_standard.t
029dc7
@@ -6,6 +6,6 @@
029dc7
 -d de:ad:be:ef:00:00 -j CONTINUE;=;OK
029dc7
 -d de:ad:be:ef:0:00/ff:ff:ff:ff:0:0 -j DROP;-d de:ad:be:ef:00:00/ff:ff:ff:ff:00:00 -j DROP;OK
029dc7
 -p ARP -j ACCEPT;=;OK
029dc7
-! -p ARP -j ACCEPT;=;OK
029dc7
+-p ! ARP -j ACCEPT;=;OK
029dc7
 -p 0 -j ACCEPT;=;FAIL
029dc7
-! -p 0 -j ACCEPT;=;FAIL
029dc7
+-p ! 0 -j ACCEPT;=;FAIL
029dc7
diff --git a/extensions/libebt_stp.c b/extensions/libebt_stp.c
029dc7
index 33e4c8d9c615d..06cf93b8d8449 100644
029dc7
--- a/extensions/libebt_stp.c
029dc7
+++ b/extensions/libebt_stp.c
029dc7
@@ -307,9 +307,8 @@ static void brstp_print(const void *ip, const struct xt_entry_match *match,
029dc7
 	for (i = 0; i < STP_NUMOPS; i++) {
029dc7
 		if (!(stpinfo->bitmask & (1 << i)))
029dc7
 			continue;
029dc7
-		if (stpinfo->invflags & (1 << i))
029dc7
-			printf("! ");
029dc7
-		printf("--%s ", brstp_opts[i].name);
029dc7
+		printf("--%s %s", brstp_opts[i].name,
029dc7
+		       (stpinfo->invflags & (1 << i)) ? "! " : "");
029dc7
 		if (EBT_STP_TYPE == (1 << i)) {
029dc7
 			if (stpinfo->type == BPDU_TYPE_CONFIG)
029dc7
 				printf("%s", BPDU_TYPE_CONFIG_STRING);
029dc7
diff --git a/extensions/libebt_vlan.c b/extensions/libebt_vlan.c
029dc7
index 4a2eb7126895e..a2a9dcce531ce 100644
029dc7
--- a/extensions/libebt_vlan.c
029dc7
+++ b/extensions/libebt_vlan.c
029dc7
@@ -108,19 +108,14 @@ static void brvlan_print(const void *ip, const struct xt_entry_match *match,
029dc7
 	struct ebt_vlan_info *vlaninfo = (struct ebt_vlan_info *) match->data;
029dc7
 
029dc7
 	if (vlaninfo->bitmask & EBT_VLAN_ID) {
029dc7
-		if (vlaninfo->invflags & EBT_VLAN_ID)
029dc7
-			printf("! ");
029dc7
-		printf("--vlan-id %d ", vlaninfo->id);
029dc7
+		printf("--vlan-id %s%d ", (vlaninfo->invflags & EBT_VLAN_ID) ? "! " : "", vlaninfo->id);
029dc7
 	}
029dc7
 	if (vlaninfo->bitmask & EBT_VLAN_PRIO) {
029dc7
-		if (vlaninfo->invflags & EBT_VLAN_PRIO)
029dc7
-			printf("! ");
029dc7
-		printf("--vlan-prio %d ", vlaninfo->prio);
029dc7
+		printf("--vlan-prio %s%d ", (vlaninfo->invflags & EBT_VLAN_PRIO) ? "! " : "", vlaninfo->prio);
029dc7
 	}
029dc7
 	if (vlaninfo->bitmask & EBT_VLAN_ENCAP) {
029dc7
-		if (vlaninfo->invflags & EBT_VLAN_ENCAP)
029dc7
-			printf("! ");
029dc7
-		printf("--vlan-encap %4.4X ", ntohs(vlaninfo->encap));
029dc7
+		printf("--vlan-encap %s", (vlaninfo->invflags & EBT_VLAN_ENCAP) ? "! " : "");
029dc7
+		printf("%4.4X ", ntohs(vlaninfo->encap));
029dc7
 	}
029dc7
 }
029dc7
 
029dc7
diff --git a/extensions/libebt_vlan.t b/extensions/libebt_vlan.t
029dc7
index 106374cd9cb80..81c795854fca0 100644
029dc7
--- a/extensions/libebt_vlan.t
029dc7
+++ b/extensions/libebt_vlan.t
029dc7
@@ -1,13 +1,13 @@
029dc7
 :INPUT,FORWARD,OUTPUT
029dc7
 -p 802_1Q --vlan-id 42;=;OK
029dc7
--p 802_1Q ! --vlan-id 42;=;OK
029dc7
+-p 802_1Q --vlan-id ! 42;=;OK
029dc7
 -p 802_1Q --vlan-prio 1;=;OK
029dc7
--p 802_1Q ! --vlan-prio 1;=;OK
029dc7
+-p 802_1Q --vlan-prio ! 1;=;OK
029dc7
 -p 802_1Q --vlan-encap ip;-p 802_1Q --vlan-encap 0800 -j CONTINUE;OK
029dc7
 -p 802_1Q --vlan-encap 0800 ;=;OK
029dc7
--p 802_1Q ! --vlan-encap 0800 ;=;OK
029dc7
--p 802_1Q --vlan-encap IPv6 ! --vlan-id 1;-p 802_1Q ! --vlan-id 1 --vlan-encap 86DD -j CONTINUE;OK
029dc7
--p 802_1Q ! --vlan-id 1 --vlan-encap 86DD;=;OK
029dc7
+-p 802_1Q --vlan-encap ! 0800 ;=;OK
029dc7
+-p 802_1Q --vlan-encap IPv6 ! --vlan-id 1;-p 802_1Q --vlan-id ! 1 --vlan-encap 86DD -j CONTINUE;OK
029dc7
+-p 802_1Q --vlan-id ! 1 --vlan-encap 86DD;=;OK
029dc7
 --vlan-encap ip;=;FAIL
029dc7
 --vlan-id 2;=;FAIL
029dc7
 --vlan-prio 1;=;FAIL
029dc7
diff --git a/iptables/nft-bridge.c b/iptables/nft-bridge.c
029dc7
index 43b3e3e9649b8..2b79ca951cd92 100644
029dc7
--- a/iptables/nft-bridge.c
029dc7
+++ b/iptables/nft-bridge.c
029dc7
@@ -344,7 +344,7 @@ static void nft_rule_to_ebtables_command_state(const struct nftnl_rule *r,
029dc7
 static void print_iface(const char *option, const char *name, bool invert)
029dc7
 {
029dc7
 	if (*name)
029dc7
-		printf("%s%s %s ", invert ? "! " : "", option, name);
029dc7
+		printf("%s%s %s ", option, invert ? " !" : "", name);
029dc7
 }
029dc7
 
029dc7
 static void nft_bridge_print_table_header(const char *tablename)
029dc7
@@ -389,9 +389,9 @@ static void print_mac(char option, const unsigned char *mac,
029dc7
 		      const unsigned char *mask,
029dc7
 		      bool invert)
029dc7
 {
029dc7
+	printf("-%c ", option);
029dc7
 	if (invert)
029dc7
 		printf("! ");
029dc7
-	printf("-%c ", option);
029dc7
 	ebt_print_mac_and_mask(mac, mask);
029dc7
 	printf(" ");
029dc7
 }
029dc7
@@ -406,9 +406,9 @@ static void print_protocol(uint16_t ethproto, bool invert, unsigned int bitmask)
029dc7
 	if (bitmask & EBT_NOPROTO)
029dc7
 		return;
029dc7
 
029dc7
+	printf("-p ");
029dc7
 	if (invert)
029dc7
 		printf("! ");
029dc7
-	printf("-p ");
029dc7
 
029dc7
 	if (bitmask & EBT_802_3) {
029dc7
 		printf("length ");
029dc7
-- 
029dc7
2.21.0
029dc7