nixos/network-interfaces: Add mstpd support for bridges
This commit is contained in:
parent
3a3a53d6a7
commit
9a7766e054
@ -254,6 +254,7 @@
|
|||||||
./services/networking/kippo.nix
|
./services/networking/kippo.nix
|
||||||
./services/networking/mailpile.nix
|
./services/networking/mailpile.nix
|
||||||
./services/networking/minidlna.nix
|
./services/networking/minidlna.nix
|
||||||
|
./services/networking/mstpd.nix
|
||||||
./services/networking/murmur.nix
|
./services/networking/murmur.nix
|
||||||
./services/networking/nat.nix
|
./services/networking/nat.nix
|
||||||
./services/networking/networkmanager.nix
|
./services/networking/networkmanager.nix
|
||||||
|
33
nixos/modules/services/networking/mstpd.nix
Normal file
33
nixos/modules/services/networking/mstpd.nix
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
{ config, lib, pkgs, ... }:
|
||||||
|
let
|
||||||
|
cfg = config.services.mstpd;
|
||||||
|
in
|
||||||
|
with lib;
|
||||||
|
{
|
||||||
|
options.services.mstpd = {
|
||||||
|
|
||||||
|
enable = mkOption {
|
||||||
|
default = false;
|
||||||
|
type = types.bool;
|
||||||
|
description = ''
|
||||||
|
Whether to enable the multiple spanning tree protocol daemon.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
config = mkIf cfg.enable {
|
||||||
|
environment.systemPackages = [ pkgs.mstpd ];
|
||||||
|
|
||||||
|
systemd.services.mstpd = {
|
||||||
|
description = "Multiple Spanning Tree Protocol Daemon";
|
||||||
|
wantedBy = [ "network.target" ];
|
||||||
|
unitConfig.ConditionCapability = "CAP_NET_ADMIN";
|
||||||
|
serviceConfig = {
|
||||||
|
Type = "forking";
|
||||||
|
ExecStart = "@${pkgs.mstpd}/bin/mstpd mstpd";
|
||||||
|
PIDFile = "/run/mstpd.pid";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
@ -37,6 +37,8 @@ let
|
|||||||
ip link del "${i}" 2>/dev/null || true
|
ip link del "${i}" 2>/dev/null || true
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
needsMstpd = any ({ rstp, ... }: rstp) (attrValues cfg.bridges);
|
||||||
|
|
||||||
in
|
in
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -185,13 +187,14 @@ in
|
|||||||
in
|
in
|
||||||
{ description = "Bridge Interface ${n}";
|
{ description = "Bridge Interface ${n}";
|
||||||
wantedBy = [ "network.target" (subsystemDevice n) ];
|
wantedBy = [ "network.target" (subsystemDevice n) ];
|
||||||
bindsTo = deps;
|
bindsTo = deps ++ optional v.rstp "mstpd.service";
|
||||||
after = [ "network-pre.target" ] ++ deps
|
partOf = optional v.rstp "mstpd.service";
|
||||||
|
after = [ "network-pre.target" "mstpd.service" ] ++ deps
|
||||||
++ concatMap (i: [ "network-addresses-${i}.service" "network-link-${i}.service" ]) v.interfaces;
|
++ concatMap (i: [ "network-addresses-${i}.service" "network-link-${i}.service" ]) v.interfaces;
|
||||||
before = [ "network-interfaces.target" (subsystemDevice n) ];
|
before = [ "network-interfaces.target" (subsystemDevice n) ];
|
||||||
serviceConfig.Type = "oneshot";
|
serviceConfig.Type = "oneshot";
|
||||||
serviceConfig.RemainAfterExit = true;
|
serviceConfig.RemainAfterExit = true;
|
||||||
path = [ pkgs.iproute ];
|
path = [ pkgs.iproute ] ++ optional v.rstp pkgs.mstpd;
|
||||||
script = ''
|
script = ''
|
||||||
# Remove Dead Interfaces
|
# Remove Dead Interfaces
|
||||||
echo "Removing old bridge ${n}..."
|
echo "Removing old bridge ${n}..."
|
||||||
@ -206,6 +209,13 @@ in
|
|||||||
ip link set "${i}" up
|
ip link set "${i}" up
|
||||||
'')}
|
'')}
|
||||||
|
|
||||||
|
# Enable rstp on the interface
|
||||||
|
${optionalString v.rstp ''
|
||||||
|
echo 1 >/sys/class/net/${n}/bridge/stp_state
|
||||||
|
mstpctl addbridge "${n}"
|
||||||
|
mstpctl setforcevers "${n}" rstp
|
||||||
|
''}
|
||||||
|
|
||||||
ip link set "${n}" up
|
ip link set "${n}" up
|
||||||
'';
|
'';
|
||||||
postStop = ''
|
postStop = ''
|
||||||
@ -343,6 +353,8 @@ in
|
|||||||
KERNEL=="tun", TAG+="systemd"
|
KERNEL=="tun", TAG+="systemd"
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
services.mstpd = mkIf needsMstpd { enable = true; };
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -368,6 +368,13 @@ in
|
|||||||
"The physical network interfaces connected by the bridge.";
|
"The physical network interfaces connected by the bridge.";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
rstp = mkOption {
|
||||||
|
example = true;
|
||||||
|
default = false;
|
||||||
|
type = types.bool;
|
||||||
|
description = "Whether the bridge interface should enable rstp.";
|
||||||
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user