liminix/modules/bridge/primary.nix
Raito Bezarius 1322de1ee0
All checks were successful
build liminix / build_vm_qemu_mips (push) Successful in 39m35s
build liminix / build_zyxel-nwa50ax_mips (push) Successful in 39m35s
build liminix / test_shell_customization (push) Successful in 39m31s
build liminix / test_hostapd (push) Successful in 39m52s
feat: add support for untagged frames
Should cover egress & ingress.

Signed-off-by: Raito Bezarius <masterancpp@gmail.com>
2024-12-09 01:25:52 +01:00

31 lines
995 B
Nix

{
liminix
, ifwait
, lib
}:
{ ifname, macAddressFromInterface ? null, untagged } :
let
inherit (liminix.services) oneshot;
inherit (lib) optional optionalString;
# This enables vlan_filtering if we do make use of it.
extra = if untagged.enable then " vlan_filtering 1 vlan_default_pvid ${toString untagged.default-pvid}" else "";
in oneshot rec {
name = "${ifname}.link";
up = ''
${if macAddressFromInterface == null then
"ip link add name ${ifname} type bridge${extra}"
else
"ip link add name ${ifname} address $(output ${macAddressFromInterface} ether) type bridge${extra}"}
${optionalString untagged.enable
"bridge vlan add vid ${toString untagged.pvid} dev ${ifname} pvid untagged self"}
(in_outputs ${name}
echo ${ifname} > ifname
cat /sys/class/net/${ifname}/address > ether
)
'';
down = "ip link delete ${ifname}";
dependencies = optional (macAddressFromInterface != null) macAddressFromInterface;
}