liminix/modules/bridge/primary.nix
Raito Bezarius e402f8b929
Some checks failed
build liminix / build_vm_qemu_mips (push) Has been cancelled
build liminix / test_hostapd (push) Has been cancelled
build liminix / test_shell_customization (push) Has been cancelled
build liminix / build_zyxel-nwa50ax_mips (push) Has been cancelled
feat: add support for untagged frames
Should cover egress & ingress.

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

31 lines
963 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 0" 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;
}