Dynamic VLAN membership of wired ports?

I'm looking at whether (wired) router ports could be assigned to VLANs dynamically based on automated topology discovery.

I understand that VLAN membership per port is defined in the Network/Switch configuration.

  1. When is this config read? Once only at boot time?

  2. Is it possible to place a wired connection in a certain VLAN via daemon software e.g. via a call to the kernel?

  3. What would be required to make that configuration change effective?

nothing/ port down up/ complete reboot

Thanks.

Sounds like you could script something to do this using uci

  1. Yes, when network service starts
  2. Dunno about some daemon, but you can change all the core settings using uci, see link
  3. Make your changes then call uci commit and maybe reload network service for some changes I guess. Test it out for your use case.

On boot, whenever netifd is restarted, upon calling ifup or ubus call network reload. However the switch related portions of this config are actually processed by the swconfig executable which is triggered through the network init script.

Yes, via netlink. You need to use the equivalent of what ip link add link eth0 name eth0.100 type vlan id 100 does internally. If eth0 happens to be wired to an swconfig switch, you need to program the switch IC via swconfig (or its internal netlink apis) as well.

After making the appropriate netlink calls roughly equivalent to ip link add link eth0 name eth0.100 type vlan id 100; swconfig dev switch0 vlan 100 set ports "a b c d"; swconfig dev switch0 apply, the config should be effective immediately.

1 Like

This is great information. Thanks!