Revert "nixos/nat: Allow nat without an externalInterface"

This reverts commit 431a98b12b5e1cc51181da815870dda5e23709f8.

Breaks nixos tests: http://hydra.nixos.org/build/35538207

Changed files
+4 -9
nixos
modules
services
networking
+4 -9
nixos/modules/services/networking/nat.nix
···
dest = if cfg.externalIP == null then "-j MASQUERADE" else "-j SNAT --to-source ${cfg.externalIP}";
-
externalInterfaceFilter = param:
-
optionalString (cfg.externalInterface != null) "${param} ${cfg.externalInterface}";
-
flushNat = ''
iptables -w -t nat -D PREROUTING -j nixos-nat-pre 2>/dev/null|| true
iptables -w -t nat -F nixos-nat-pre 2>/dev/null || true
···
# NAT the marked packets.
${optionalString (cfg.internalInterfaces != []) ''
iptables -w -t nat -A nixos-nat-post -m mark --mark 1 \
-
${externalInterfaceFilter "-o"} ${dest}
''}
# NAT packets coming from the internal IPs.
${concatMapStrings (range: ''
iptables -w -t nat -A nixos-nat-post \
-
-s '${range}' \! -d '${range}'
-
${externalInterfaceFilter "-o"} ${dest}
'') cfg.internalIPs}
# NAT from external ports to internal ports.
${concatMapStrings (fwd: ''
iptables -w -t nat -A nixos-nat-pre \
-
${externalInterfaceFilter "-i"} -p tcp \
--dport ${builtins.toString fwd.sourcePort} \
-j DNAT --to-destination ${fwd.destination}
'') cfg.forwardPorts}
···
};
networking.nat.externalInterface = mkOption {
-
type = types.nullOr types.str;
-
default = null;
example = "eth1";
description =
''
···
dest = if cfg.externalIP == null then "-j MASQUERADE" else "-j SNAT --to-source ${cfg.externalIP}";
flushNat = ''
iptables -w -t nat -D PREROUTING -j nixos-nat-pre 2>/dev/null|| true
iptables -w -t nat -F nixos-nat-pre 2>/dev/null || true
···
# NAT the marked packets.
${optionalString (cfg.internalInterfaces != []) ''
iptables -w -t nat -A nixos-nat-post -m mark --mark 1 \
+
-o ${cfg.externalInterface} ${dest}
''}
# NAT packets coming from the internal IPs.
${concatMapStrings (range: ''
iptables -w -t nat -A nixos-nat-post \
+
-s '${range}' -o ${cfg.externalInterface} ${dest}
'') cfg.internalIPs}
# NAT from external ports to internal ports.
${concatMapStrings (fwd: ''
iptables -w -t nat -A nixos-nat-pre \
+
-i ${cfg.externalInterface} -p tcp \
--dport ${builtins.toString fwd.sourcePort} \
-j DNAT --to-destination ${fwd.destination}
'') cfg.forwardPorts}
···
};
networking.nat.externalInterface = mkOption {
+
type = types.str;
example = "eth1";
description =
''