0
0
Fork 0
mirror of https://github.com/NixOS/nixpkgs.git synced 2025-07-12 05:16:25 +03:00

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

This reverts commit 431a98b12b.

Breaks nixos tests: http://hydra.nixos.org/build/35538207
This commit is contained in:
Domen Kožar 2016-05-12 11:02:43 +01:00
parent 323cd39016
commit 25e3c091a0

View file

@ -12,9 +12,6 @@ let
dest = if cfg.externalIP == null then "-j MASQUERADE" else "-j SNAT --to-source ${cfg.externalIP}"; 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 = '' flushNat = ''
iptables -w -t nat -D PREROUTING -j nixos-nat-pre 2>/dev/null|| true 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 iptables -w -t nat -F nixos-nat-pre 2>/dev/null || true
@ -39,20 +36,19 @@ let
# NAT the marked packets. # NAT the marked packets.
${optionalString (cfg.internalInterfaces != []) '' ${optionalString (cfg.internalInterfaces != []) ''
iptables -w -t nat -A nixos-nat-post -m mark --mark 1 \ iptables -w -t nat -A nixos-nat-post -m mark --mark 1 \
${externalInterfaceFilter "-o"} ${dest} -o ${cfg.externalInterface} ${dest}
''} ''}
# NAT packets coming from the internal IPs. # NAT packets coming from the internal IPs.
${concatMapStrings (range: '' ${concatMapStrings (range: ''
iptables -w -t nat -A nixos-nat-post \ iptables -w -t nat -A nixos-nat-post \
-s '${range}' \! -d '${range}' -s '${range}' -o ${cfg.externalInterface} ${dest}
${externalInterfaceFilter "-o"} ${dest}
'') cfg.internalIPs} '') cfg.internalIPs}
# NAT from external ports to internal ports. # NAT from external ports to internal ports.
${concatMapStrings (fwd: '' ${concatMapStrings (fwd: ''
iptables -w -t nat -A nixos-nat-pre \ iptables -w -t nat -A nixos-nat-pre \
${externalInterfaceFilter "-i"} -p tcp \ -i ${cfg.externalInterface} -p tcp \
--dport ${builtins.toString fwd.sourcePort} \ --dport ${builtins.toString fwd.sourcePort} \
-j DNAT --to-destination ${fwd.destination} -j DNAT --to-destination ${fwd.destination}
'') cfg.forwardPorts} '') cfg.forwardPorts}
@ -104,8 +100,7 @@ in
}; };
networking.nat.externalInterface = mkOption { networking.nat.externalInterface = mkOption {
type = types.nullOr types.str; type = types.str;
default = null;
example = "eth1"; example = "eth1";
description = description =
'' ''