forked from zentralwerk/network
nixos-module/server/lxc-containers: check and shorten ifnames more
This commit is contained in:
parent
46ca027d80
commit
58047f565e
|
@ -24,9 +24,15 @@ let
|
|||
# linux iface name max length = 15
|
||||
shortenNetName = name:
|
||||
if builtins.match "priv(.*)" name != null
|
||||
then "pr" + builtins.substring 4 9 name
|
||||
then "p" + builtins.substring 4 9 name
|
||||
else name;
|
||||
|
||||
checkIfname = ifname: let
|
||||
len = builtins.stringLength ifname;
|
||||
in if len > 15
|
||||
then throw "Interface name ${ifname} is ${toString (len - 15)} chars too long."
|
||||
else ifname;
|
||||
|
||||
# `lxc.net.*` formatter for lxc.container.conf files
|
||||
netConfig = ctName: interfaces:
|
||||
let
|
||||
|
@ -35,17 +41,17 @@ let
|
|||
ifData = interfaces.${netName};
|
||||
in {
|
||||
type = ifData.type;
|
||||
name = netName;
|
||||
name = checkIfname netName;
|
||||
flags = "up";
|
||||
hwaddr = if ifData ? hwaddr && ifData.hwaddr != null
|
||||
then ifData.hwaddr
|
||||
else "0A:14:48:xx:xx:xx";
|
||||
} // (lib.optionalAttrs (ifData.type == "veth") {
|
||||
veth.pair = "${ctName}-${shortenNetName netName}";
|
||||
veth.mode = "bridge";
|
||||
link = "${netName}";
|
||||
veth.pair = checkIfname "${shortenNetName ctName}-${shortenNetName netName}";
|
||||
veth.mode = checkIfname "bridge";
|
||||
link = checkIfname netName;
|
||||
}) // (lib.optionalAttrs (ifData.type == "phys") {
|
||||
link = "ext-${netName}";
|
||||
link = checkIfname "ext-${netName}";
|
||||
})
|
||||
) (builtins.attrNames interfaces);
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user