This is the documentation for the latest (master) development branch of Zephyr. If you are looking for the documentation of previous releases, use the drop-down menu on the left and select the desired version.

Virtual LAN (VLAN) Support

Overview

Virtual LAN (VLAN) is a partitioned and isolated computer network at the data link layer (OSI layer 2). For ethernet network this refers to IEEE 802.1Q

In Zephyr, each individual VLAN is modeled as a virtual network interface. This means that there is an ethernet network interface that corresponds to a real physical ethernet port in the system. A virtual network interface is created for each VLAN, and this virtual network interface connects to the real network interface. This is similar to how Linux implements VLANs. The eth0 is the real network interface and vlan0 is a virtual network interface that is run on top of eth0.

VLAN support must be enabled at compile time by setting option CONFIG_NET_VLAN and CONFIG_NET_VLAN_COUNT to reflect how many network interfaces there will be in the system. For example, if there is one network interface without VLAN support, and two with VLAN support, the CONFIG_NET_VLAN_COUNT option should be set to 3.

Even if VLAN is enabled in a prj.conf file, the VLAN needs to be activated at runtime by the application. The VLAN API provides a net_eth_vlan_enable() function to do that. The application needs to give the network interface and desired VLAN tag as a parameter to that function. The VLAN tagging for a given network interface can be disabled by a net_eth_vlan_disable() function. The application needs to configure the VLAN network interface itself, such as setting the IP address, etc.

See also the VLAN sample application for API usage example. The source code for that sample application can be found at samples/net/vlan.

The net-shell module contains net vlan add and net vlan del commands that can be used to enable or disable VLAN tags for a given network interface.

See the IEEE 802.1Q spec for more information about ethernet VLANs.

API Reference

group vlan_api

VLAN definitions and helpers.

Defines

NET_VLAN_TAG_UNSPEC

Unspecified VLAN tag value

Functions

uint16_t net_eth_vlan_get_vid(uint16_t tci)

Get VLAN identifier from TCI.

Return

VLAN identifier.

Parameters
  • tci: VLAN tag control information.

uint8_t net_eth_vlan_get_dei(uint16_t tci)

Get Drop Eligible Indicator from TCI.

Return

Drop eligible indicator.

Parameters
  • tci: VLAN tag control information.

uint8_t net_eth_vlan_get_pcp(uint16_t tci)

Get Priority Code Point from TCI.

Return

Priority code point.

Parameters
  • tci: VLAN tag control information.

uint16_t net_eth_vlan_set_vid(uint16_t tci, uint16_t vid)

Set VLAN identifier to TCI.

Return

New TCI value.

Parameters
  • tci: VLAN tag control information.

  • vid: VLAN identifier.

uint16_t net_eth_vlan_set_dei(uint16_t tci, bool dei)

Set Drop Eligible Indicator to TCI.

Return

New TCI value.

Parameters
  • tci: VLAN tag control information.

  • dei: Drop eligible indicator.

uint16_t net_eth_vlan_set_pcp(uint16_t tci, uint8_t pcp)

Set Priority Code Point to TCI.

Return

New TCI value.

Parameters
  • tci: VLAN tag control information.

  • pcp: Priority code point.