NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
18.1k stars 14.15k forks source link

Configuring a 16 character long bridge interface name is accepted but the generated systemd netdev unit fails #101273

Open grische opened 4 years ago

grische commented 4 years ago

Describe the bug When creating an interface with a name with exactly 16 characters, the configuration is accepted but the generated systemd netdev unit fails.

To Reproduce Steps to reproduce the behavior:

  1. Create network configuration with an interface name of 16 characters in the configuration.nix
  2. Build the configuration (which succeeds)
  3. Apply the configuration (which fails)

Expected behavior Throw an error during validation/building

Screenshots

Oct 21 18:32:18 dummy rfk5zk7vg1v0xnp8lpmc2af9r4hrf1hi-unit-script-abcdef1234567890-netdev-start[24536]: Removing old bridge abcdef1234567890...
Oct 21 18:32:18 dummy rfk5zk7vg1v0xnp8lpmc2af9r4hrf1hi-unit-script-abcdef1234567890-netdev-start[24536]: Adding bridge abcdef1234567890...
Oct 21 18:32:18 dummy rfk5zk7vg1v0xnp8lpmc2af9r4hrf1hi-unit-script-abcdef1234567890-netdev-start[24536]: Error: argument "abcdef1234567890" is wrong: "name" not a valid ifname
Oct 21 18:32:18 dummy systemd[1]: abcdef1234567890-netdev.service: Main process exited, code=exited, status=255/EXCEPTION
Oct 21 18:32:18 dummy wqw2h4is2ll0357vfpl74368xmffqx3v-unit-script-abcdef1234567890-netdev-post-stop[24539]: Cannot find device "abcdef1234567890"
Oct 21 18:32:18 dummy wqw2h4is2ll0357vfpl74368xmffqx3v-unit-script-abcdef1234567890-netdev-post-stop[24539]: Cannot find device "abcdef1234567890"
Oct 21 18:32:18 dummy systemd[1]: abcdef1234567890-netdev.service: Failed with result 'exit-code'.
Oct 21 18:32:18 dummy systemd[1]: Failed to start Bridge Interface abcdef1234567890.

The config

  networking = {
    hostName = "dummy";

    bridges = {
      "abcdef1234567890" = {
        interfaces = [];
       };
    };

Additional context

NixOS channel 20.03

andir commented 4 years ago

Yeah, we should probably be stricter with the device names. Those are fixed to IFNAMSIZ (16) and require a zero byte at the end. So linux permits at most 15 characters for device names and that is likely why systemd is refusing this.

After a quick look a this we should add a maxStringLength function to nixos/modules/system/boot/systemd-lib.nix like so:

{ # …
maxStringLength = num: s: stringLength s <= num;
# …
assertMaxStringLength = name: max: group: attr: optional (attr ? ${name} && ! maxStringLength max attr.${name})
     "Error on systemd ${group} field `${name}` maximum permitted string length of ${toString max} exceeded with value `${attr.${name}}.";

and then add it in nixos/modules/system/boot/systemd-lib.nix for Link, Netdev and probably Network each on the Name field.

arianvp commented 3 years ago

https://github.com/systemd/systemd/blob/master/NEWS#L1496-L1506 might be related. udev now supports longer AlternativeNames

stale[bot] commented 3 years ago

I marked this as stale due to inactivity. → More info

fadenb commented 3 years ago

Still relevant