24f428
From da851982df4020460fe4fa005dd99be4357ff9bd Mon Sep 17 00:00:00 2001
24f428
From: Eric Garver <e@erig.me>
24f428
Date: Fri, 2 Nov 2018 14:10:38 -0400
24f428
Subject: [PATCH 4/5] rich rules: fix mark action
24f428
24f428
They were being placed in the wrong (and nonexistent) chain. Also add
24f428
test coverage for the "mark" action.
24f428
24f428
Fixes: 7c5f5f4d12ee ("fw_zone: push rich rule generation to backend")
24f428
Tested-by: Felix Kaechele <heffer@fedoraproject.org>
24f428
(cherry picked from commit 5d36e0f55887c6204e07bd8095ead1ce2d535ddb)
24f428
---
24f428
 src/firewall/core/ipXtables.py | 4 ++--
24f428
 src/firewall/core/nftables.py  | 4 ++--
24f428
 src/tests/firewall-cmd.at      | 1 +
24f428
 3 files changed, 5 insertions(+), 4 deletions(-)
24f428
24f428
diff --git a/src/firewall/core/ipXtables.py b/src/firewall/core/ipXtables.py
24f428
index 11aebec6e05a..b98ba5228e68 100644
24f428
--- a/src/firewall/core/ipXtables.py
24f428
+++ b/src/firewall/core/ipXtables.py
24f428
@@ -807,10 +807,10 @@ class ip4tables(object):
24f428
             chain = "%s_deny" % target
24f428
             rule_action = [ "-j", "DROP" ]
24f428
         elif type(rich_rule.action) == Rich_Mark:
24f428
-            chain = "%s_allow" % target
24f428
-            table = "mangle"
24f428
             target = DEFAULT_ZONE_TARGET.format(chain=SHORTCUTS["PREROUTING"],
24f428
                                                 zone=zone)
24f428
+            table = "mangle"
24f428
+            chain = "%s_allow" % target
24f428
             rule_action = [ "-j", "MARK", "--set-xmark", rich_rule.action.set ]
24f428
         else:
24f428
             raise FirewallError(INVALID_RULE,
24f428
diff --git a/src/firewall/core/nftables.py b/src/firewall/core/nftables.py
24f428
index cd05b2c3137e..69236a9600c2 100644
24f428
--- a/src/firewall/core/nftables.py
24f428
+++ b/src/firewall/core/nftables.py
24f428
@@ -723,10 +723,10 @@ class nftables(object):
24f428
             chain = "%s_%s_deny" % (table, target)
24f428
             rule_action = ["drop"]
24f428
         elif type(rich_rule.action) == Rich_Mark:
24f428
-            table = "mangle"
24f428
-            chain = "%s_%s_allow" % (table, target)
24f428
             target = DEFAULT_ZONE_TARGET.format(chain=SHORTCUTS["PREROUTING"],
24f428
                                                 zone=zone)
24f428
+            table = "mangle"
24f428
+            chain = "%s_%s_allow" % (table, target)
24f428
             rule_action = ["meta", "mark", "set", rich_rule.action.set]
24f428
         else:
24f428
             raise FirewallError(INVALID_RULE,
24f428
diff --git a/src/tests/firewall-cmd.at b/src/tests/firewall-cmd.at
24f428
index f496b67e4a35..82ffa9f52b47 100644
24f428
--- a/src/tests/firewall-cmd.at
24f428
+++ b/src/tests/firewall-cmd.at
24f428
@@ -863,6 +863,7 @@ FWD_START_TEST([rich rules good])
24f428
     rich_rule_test([rule forward-port port="66" to-port="666" to-addr="192.168.100.2" protocol="sctp" family="ipv4" source address="192.168.2.100"])
24f428
     rich_rule_test([rule forward-port port="99" to-port="999" to-addr="1::2:3:4:7" protocol="dccp" family="ipv6" source address="1:2:3:4:6::"])
24f428
     rich_rule_test([rule forward-port port="99" to-port="10999" to-addr="1::2:3:4:7" protocol="dccp" family="ipv6" source address="1:2:3:4:6::"])
24f428
+    rich_rule_test([rule family="ipv4" port port="222" protocol="tcp" mark set="0xff"])
24f428
 FWD_END_TEST
24f428
 FWD_START_TEST([rich rules audit])
24f428
 	CHECK_LOG_AUDIT
24f428
-- 
24f428
2.18.0
24f428