Files
napalm-ubiquiti/docs/PORT_VLANS.md
T

3.1 KiB
Raw Blame History

How a UniFi switch port's VLANs are stored

What the driver relies on when it reads a port's VLANs from the controller and, later, writes them. Sources: go-unifi's generated structs per controller version (unifi/device.generated.go, unifi/port_profile.generated.go, read at 01866ea, 10.6.109), terraform-provider-unifi unifi/device_tagged_networks.go (ad90c73), sirkirby/unifi-mcp switch_manager.py (ab0d5fe). MPL-2.0 sources were read, not copied.

Networks (rest/networkconf)

  • A network can be tagged on a switch port when its purpose is corporate, guest or vlan-only. wan, remote-user-vpn, site-vpn and vpn-client are not switch VLANs.
  • Its VLAN ID is vlan when vlan_enabled is true. The Default LAN carries no vlan: it is VLAN 1 (the controller refuses vlan: 1).

Where a port's VLANs live, by controller version

Controller Port profile (rest/portconf) Per port (device.port_overrides[])
7.2–7.3 forward (all, native, customize, disabled), native_networkconf_id, tagged_networkconf_ids portconf_id only: VLANs come from a profile
7.4 excluded_networkconf_ids replaces tagged_networkconf_ids native_networkconf_id, excluded_networkconf_ids, forward
8.2 – 10.x adds tagged_vlan_mgmt (auto, block_all, custom) adds tagged_vlan_mgmt

The effective VLANs of a port

  1. The port's entry in port_overrides (by port_idx), if any.
  2. Otherwise, or for a field the override leaves out, the port profile named by portconf_id (the override's, else the port's in port_table).
  3. Otherwise the default: the Default LAN untagged, every taggable network tagged.

Native (untagged): native_networkconf_id, else the Default LAN.

Tagged:

tagged_vlan_mgmt forward (older) Tagged networks
auto all every taggable network but the native one
block_all native none
custom customize every taggable network but the native one and excluded_networkconf_ids (older: exactly tagged_networkconf_ids)
— disabled none, and no native either

Writing (later stage)

  • PUT /api/s/<site>/rest/device/<_id> with {"port_overrides": [...]} replaces the whole array: a port left out returns to its defaults. Read the device right before, change one entry, write all, read again. Serialise writes per device.
  • A tagged list is not stored on a port override (checked by the terraform provider on 9.5.21, 10.0.162, 11.0.103): write tagged_vlan_mgmt: custom plus the complement as excluded_networkconf_ids. The native network cannot be excluded (api.err.NativeVlanCannotBeExcluded).
  • Keep forward in step: block_all → native, custom → customize, auto → all.
  • Manual VLAN fields and a profile are exclusive in practice: a manual port has no portconf_id.
  • setting_preference is not a profile-vs-manual switch; round-trip the controller's value.
  • The Integration API has no port VLAN write (its only port action is POWER_CYCLE), so port VLANs go through the classic API on every version.