Skip to content

Commit

Permalink
nixos/wireguard: add option to set mtu
Browse files Browse the repository at this point in the history
Some networks can only transfer packets with a lower than normal maximum
transfer unit size. In these cases, it is necessary to set a MTU that
works for the given upstream network.
  • Loading branch information
digital committed Sep 28, 2022
1 parent 084509a commit eb49174
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions nixos/modules/services/networking/wireguard.nix
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,19 @@ let
differently.
'';
};

mtu = mkOption {
default = null;
type = with types; nullOr int;
example = 1280;
description = lib.mdDoc ''
Set the maximum transmission unit in bytes for the wireguard
interface. Beware that the wireguard packets have a header that may
add up to 80 bytes to the mtu. By default, the MTU is (1500 - 80) =
1420. However, if the MTU of the upstream network is lower, the MTU
of the wireguard network has to be adjusted as well.
'';
};
};

};
Expand Down Expand Up @@ -412,6 +425,7 @@ let
${ipPreMove} link add dev "${name}" type wireguard
${optionalString (values.interfaceNamespace != null && values.interfaceNamespace != values.socketNamespace) ''${ipPreMove} link set "${name}" netns "${ns}"''}
${optionalString (values.mtu != null) ''${ipPreMove} link set "${name}" mtu ${toString values.mtu}''}
${concatMapStringsSep "\n" (ip:
''${ipPostMove} address add "${ip}" dev "${name}"''
Expand Down

0 comments on commit eb49174

Please sign in to comment.