nixos/networking/nat: add option for protocol

This commit adds an option to allow udp port forwarding (see #24894).

Phil 4f277bd9 e84c717d

Changed files
+10 -3
nixos
modules
services
networking
+10 -3
nixos/modules/services/networking/nat.nix
···
# 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}
···
destination = mkOption {
type = types.str;
example = "10.0.0.1:80";
-
description = "Forward tcp connection to destination ip:port";
};
};
});
default = [];
-
example = [ { sourcePort = 8080; destination = "10.0.0.1:80"; } ];
description =
''
List of forwarded ports from the external interface to
···
# NAT from external ports to internal ports.
${concatMapStrings (fwd: ''
iptables -w -t nat -A nixos-nat-pre \
+
-i ${cfg.externalInterface} -p ${fwd.proto} \
--dport ${builtins.toString fwd.sourcePort} \
-j DNAT --to-destination ${fwd.destination}
'') cfg.forwardPorts}
···
destination = mkOption {
type = types.str;
example = "10.0.0.1:80";
+
description = "Forward connection to destination ip:port";
+
};
+
+
proto = mkOption {
+
type = types.str;
+
default = "tcp";
+
example = "udp";
+
description = "Protocol of forwarded connection";
};
};
});
default = [];
+
example = [ { sourcePort = 8080; destination = "10.0.0.1:80"; proto = "tcp"; } ];
description =
''
List of forwarded ports from the external interface to