mirror of
https://github.com/ilyakooo0/nixpkgs.git
synced 2024-12-26 12:53:59 +03:00
nixos/network-interfaces: Fix rstp support
This commit is contained in:
parent
1ec68e0d13
commit
8e5ef7da54
@ -37,8 +37,6 @@ 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
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -194,7 +192,7 @@ in
|
|||||||
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 ] ++ optional v.rstp pkgs.mstpd;
|
path = [ pkgs.iproute ];
|
||||||
script = ''
|
script = ''
|
||||||
# Remove Dead Interfaces
|
# Remove Dead Interfaces
|
||||||
echo "Removing old bridge ${n}..."
|
echo "Removing old bridge ${n}..."
|
||||||
@ -209,11 +207,9 @@ in
|
|||||||
ip link set "${i}" up
|
ip link set "${i}" up
|
||||||
'')}
|
'')}
|
||||||
|
|
||||||
# Enable rstp on the interface
|
# Enable stp on the interface
|
||||||
${optionalString v.rstp ''
|
${optionalString v.rstp ''
|
||||||
echo 1 >/sys/class/net/${n}/bridge/stp_state
|
echo 2 >/sys/class/net/${n}/bridge/stp_state
|
||||||
mstpctl addbridge "${n}"
|
|
||||||
mstpctl setforcevers "${n}" rstp
|
|
||||||
''}
|
''}
|
||||||
|
|
||||||
ip link set "${n}" up
|
ip link set "${n}" up
|
||||||
@ -353,8 +349,6 @@ in
|
|||||||
KERNEL=="tun", TAG+="systemd"
|
KERNEL=="tun", TAG+="systemd"
|
||||||
'';
|
'';
|
||||||
|
|
||||||
services.mstpd = mkIf needsMstpd { enable = true; };
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,35 @@ let
|
|||||||
|
|
||||||
slaveIfs = map (i: cfg.interfaces.${i}) (filter (i: cfg.interfaces ? ${i}) slaves);
|
slaveIfs = map (i: cfg.interfaces.${i}) (filter (i: cfg.interfaces ? ${i}) slaves);
|
||||||
|
|
||||||
|
rstpBridges = flip filterAttrs cfg.bridges (_: { rstp, ... }: rstp);
|
||||||
|
|
||||||
|
needsMstpd = rstpBridges != { };
|
||||||
|
|
||||||
|
bridgeStp = optional needsMstpd (pkgs.writeTextFile {
|
||||||
|
name = "bridge-stp";
|
||||||
|
executable = true;
|
||||||
|
destination = "/bin/bridge-stp";
|
||||||
|
text = ''
|
||||||
|
#!${pkgs.stdenv.shell} -e
|
||||||
|
export PATH="${pkgs.mstpd}/bin"
|
||||||
|
|
||||||
|
BRIDGES=(${concatStringsSep " " (attrNames rstpBridges)})
|
||||||
|
for BRIDGE in $BRIDGES; do
|
||||||
|
if [ "$BRIDGE" = "$1" ]; then
|
||||||
|
if [ "$2" = "start" ]; then
|
||||||
|
mstpctl addbridge "$BRIDGE"
|
||||||
|
exit 0
|
||||||
|
elif [ "$2" = "stop" ]; then
|
||||||
|
mstpctl delbridge "$BRIDGE"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
exit 1
|
||||||
|
'';
|
||||||
|
});
|
||||||
|
|
||||||
# We must escape interfaces due to the systemd interpretation
|
# We must escape interfaces due to the systemd interpretation
|
||||||
subsystemDevice = interface:
|
subsystemDevice = interface:
|
||||||
"sys-subsystem-net-devices-${escapeSystemdPath interface}.device";
|
"sys-subsystem-net-devices-${escapeSystemdPath interface}.device";
|
||||||
@ -683,7 +712,7 @@ in
|
|||||||
pkgs.iw
|
pkgs.iw
|
||||||
pkgs.rfkill
|
pkgs.rfkill
|
||||||
pkgs.openresolv
|
pkgs.openresolv
|
||||||
];
|
] ++ bridgeStp;
|
||||||
|
|
||||||
systemd.targets."network-interfaces" =
|
systemd.targets."network-interfaces" =
|
||||||
{ description = "All Network Interfaces";
|
{ description = "All Network Interfaces";
|
||||||
@ -731,6 +760,9 @@ in
|
|||||||
ip link set "${i.name}" mtu "${toString i.mtu}"
|
ip link set "${i.name}" mtu "${toString i.mtu}"
|
||||||
'';
|
'';
|
||||||
})));
|
})));
|
||||||
|
|
||||||
|
services.mstpd = mkIf needsMstpd { enable = true; };
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user