zones: restrict default ACCEPT rules to NEW ctstate
authorJo-Philipp Wich <jo@mein.io>
Mon, 8 Aug 2016 13:52:28 +0000 (15:52 +0200)
committerJo-Philipp Wich <jo@mein.io>
Mon, 8 Aug 2016 14:16:04 +0000 (16:16 +0200)
Restrict the per-zone default accept rules to only accept streams with
conntrack state NEW when drop_invalid is disabled.

This commit hardens the firewall in order to allow disabling drop_invalid
by default since ctstate INVALID also matches desired traffic like IPv6
neighbour discovery messages.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
zones.c

diff --git a/zones.c b/zones.c
index 66c70a5e6ce66b062e0ae9efaf6e67655c61b443..368243564c306d6ad0c173b07efb3d0ca7e62db2 100644 (file)
--- a/zones.c
+++ b/zones.c
@@ -348,6 +348,10 @@ print_interface_rule(struct fw3_ipt_handle *handle, struct fw3_state *state,
                                r = fw3_ipt_rule_create(handle, NULL, dev, NULL, sub, NULL);
                                fw3_ipt_rule_target(r, jump_target(t));
                                fw3_ipt_rule_extra(r, zone->extra_src);
+
+                               if (t == FW3_FLAG_ACCEPT && !state->defaults.drop_invalid)
+                                       fw3_ipt_rule_extra(r, "-m conntrack --ctstate NEW");
+
                                fw3_ipt_rule_replace(r, "zone_%s_src_%s", zone->name,
                                                     fw3_flag_names[t]);
                        }
@@ -357,6 +361,10 @@ print_interface_rule(struct fw3_ipt_handle *handle, struct fw3_state *state,
                                r = fw3_ipt_rule_create(handle, NULL, NULL, dev, NULL, sub);
                                fw3_ipt_rule_target(r, jump_target(t));
                                fw3_ipt_rule_extra(r, zone->extra_dest);
+
+                               if (t == FW3_FLAG_ACCEPT && !state->defaults.drop_invalid)
+                                       fw3_ipt_rule_extra(r, "-m conntrack --ctstate NEW");
+
                                fw3_ipt_rule_replace(r, "zone_%s_dest_%s", zone->name,
                                                     fw3_flag_names[t]);
                        }