From 21ff11503eb283f52bc5abc47fbb05d80bae0d01 Mon Sep 17 00:00:00 2001 From: Raito Bezarius Date: Sun, 1 Sep 2024 14:56:08 +0200 Subject: [PATCH] fix(bridge): pick up MAC from another interface This avoids the OPERSTATE unknown when the bridge is brought up but the members are not ready yet. This will make OPERSTATE to down, enabling us to wait until we have brought up completely all the members. Signed-off-by: Raito Bezarius --- modules/bridge/default.nix | 6 ++++++ modules/bridge/primary.nix | 11 ++++++++--- pkgs/liminix-tools/networking/default.nix | 1 + 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/modules/bridge/default.nix b/modules/bridge/default.nix index 32df4a5..fd779f8 100644 --- a/modules/bridge/default.nix +++ b/modules/bridge/default.nix @@ -28,6 +28,12 @@ in type = types.str; description = "bridge interface name to create"; }; + + macAddressFromInterface = mkOption { + type = types.nullOr liminix.lib.types.service; + default = null; + description = "reuse mac address from an existing interface service"; + }; }; members = config.system.callService ./members.nix { primary = mkOption { diff --git a/modules/bridge/primary.nix b/modules/bridge/primary.nix index c25e5fe..aa7822c 100644 --- a/modules/bridge/primary.nix +++ b/modules/bridge/primary.nix @@ -3,15 +3,20 @@ , ifwait , lib }: -{ ifname } : +{ ifname, macAddressFromInterface ? null } : let inherit (liminix.services) bundle oneshot; - inherit (lib) mkOption types; + inherit (lib) mkOption types optional; in oneshot rec { name = "${ifname}.link"; up = '' - ip link add name ${ifname} type bridge + ${if macAddressFromInterface == null then + "ip link add name ${ifname} type bridge" + else + "ip link add name ${ifname} address $(output ${macAddressFromInterface} ether) type bridge"} ${liminix.networking.ifup name ifname} ''; down = "ip link set down dev ${ifname}"; + + dependencies = optional (macAddressFromInterface != null) macAddressFromInterface; } diff --git a/pkgs/liminix-tools/networking/default.nix b/pkgs/liminix-tools/networking/default.nix index aed7c4e..b51b367 100644 --- a/pkgs/liminix-tools/networking/default.nix +++ b/pkgs/liminix-tools/networking/default.nix @@ -9,6 +9,7 @@ ip link set up dev ${ifname} (in_outputs ${name} echo ${ifname} > ifname + cat /sys/class/net/${ifname}/address > ether ) ''; }