summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/iptables.nix27
1 files changed, 15 insertions, 12 deletions
diff --git a/modules/iptables.nix b/modules/iptables.nix
index a2308183..04fa4e7b 100644
--- a/modules/iptables.nix
+++ b/modules/iptables.nix
@@ -245,23 +245,26 @@
};
# Rules for an iptables chain, as nft include statements of translated files.
- # In one inet table, rules from extra apply to both families, so they keep
- # their place relative to extra4 and extra6: after them in nat, before them
- # in filter, like in the separate iptables and ip6tables tables.
+ # iptables applies extra to both families and extra4 or extra6 to one. In
+ # one inet table, each family gets its own copy, restricted by meta nfproto,
+ # in iptables' order: extra before the family's rules in filter, after them
+ # in nat.
extraRules = order: table: chain: let
- rule = position: tool: rules: {
+ rule = family: tool: let
+ common = cfg.extra.${table}.${chain};
+ specific = cfg."extra${family}".${table}.${chain};
+ rules = if table == "nat" then specific ++ common else common ++ specific;
+ in {
enable = rules != [];
- order = order + position;
- text = translate tool table chain rules;
+ inherit order;
+ text = translate tool "ipv${family}" table chain rules;
};
- nat = table == "nat";
in {
- tv-iptables-extra = rule (if nat then 2 else 0) "iptables" cfg.extra.${table}.${chain};
- tv-iptables-extra4 = rule (if nat then 0 else 1) "iptables" cfg.extra4.${table}.${chain};
- tv-iptables-extra6 = rule (if nat then 1 else 2) "ip6tables" cfg.extra6.${table}.${chain};
+ tv-iptables-ipv4 = rule "4" "iptables";
+ tv-iptables-ipv6 = rule "6" "ip6tables";
};
- translate = tool: table: chain: rules: let
+ translate = tool: nfproto: table: chain: rules: let
input = pkgs.writeText "tv-iptables-${tool}-${table}-${chain}" ''
*${table}
${lib.optionalString (table == "filter") ''
@@ -283,7 +286,7 @@
} ''
${tool}-restore-translate -f ${input} > translated
sed -n 's/^add rule [a-z0-9]* ${table} ${chain} \(.*\)/\1/p' translated |
- sed 's/ counter / /' > $out
+ sed "s/ counter / /; s/^/meta nfproto ${nfproto} /" > $out
test "$(wc -l < $out)" = ${toString (lib.length rules)}
'';
in