VLANs (not) understood

Yes, yes, I’ve read everyone’s threads, comments, tutorials, videos, explanations, etc.

No, really, I have.

For example, this thread is great:

http://forum.mikrotik.com/t/vlan-tutorial-understanding-menu-interface-bridge-vlan/164722/1

But, you all might not like it, and I’m not claiming to be an subject matter expert on VLANS (for sure), but I am quite good at communicating, explaining, and conceptualizing how others can grasp concepts.

After many decades of near-continuous learning in one form or another, I have also (justifiably) concluded that if I’m not understanding, many (many) others are not understanding also.

So, before I proceed I want to state that I truly have enormous respect for everyone here who has a deep understanding and mastery of VLANS. I mean no disrespect whatsoever. That said, it is clear to me that the way VLANs are explained has been less than easy to comprehend.

I have taken quotes and writings from various threads here and written the explanation below. I am certain that there are errors. I am certain that there are many ommissions. I am asking that people who know more than me help me make this a better summary. My hope is that together we can come up with a way to explain how Mikrotik VLANs work. Yes, I know it has been done many many times. I have watched the videos and read the tutorials. And I know this is a complex topic. And yet myself and many others come here (and I’m sure this goes on elsewhere also) begging for help because of of being in a state of massive vlan-confusion.

So, can the experts here please read this and let me know what I got wrong?

I will then attempt to incorporate those comments into a wordy, verbose, excessive, and long-winded but hopefully clear and helpful document that others (and myself) will find helpful.


Here goes:


\

  1. ADD BRIDGE:

“/interface/bridge add” creates a bridge with one or two roles (sometimes the word used is “personality”): (1) Switch-like and/or (2) bridge-between-CPU-and-switch (understood as #2 role when property includes “interface,” “tagged,” or “untagged”).

Why we need to consider these roles or personalities as distinct is unclear.

Properties of this command include:

vlan-filtering is a property that effectively turns on VLAN recognition on the bridge and between bridge and switch (within the single device).

Properties that define the interfaction between CPU and switch are: admin-mac, ingress-filtering, frame-types, pvid

These apply only to the bridge port connecting to CPU, they don’t affect other (explicitly configured) ports.

Bridge interface has to be explicitly configured under bridge vlan as VLAN member according to how CPU needs to interact with network.




2) DEFINE BRIDGE PORTS:

/interface/bridge/port defines ingress behavior and adds physical (and some types of logical) interfaces to a bridge.

The properties that define port behavior for ingress frames include:

frame-types: defines what kind of frames can pass port on ingress.

If “frame-types” is set to admit-only-tagged, then untagged frames are dropped on ingress.

If “frame-types” is set to admit-only-untagged-and-priority-tagged, then any VLAN-tagged frames will be dropped on ingress, and, untagged frames will be tagged with the pvid.

If “frame-types” is set to admit-any, then no frames will be dropped on ingress.

If port has ingress-filtering=yes, then port will check the value of VLAN-ID for ingress frames against contents of VLAN table which is constructed in /interface/bridge/vlan section and then act according to check result.

A side note: every port has PVID set with default value of PVID=1. However, pvid=1 is not shown in an export, but it will show using “print”. An export will show when non-default settings are used. But it’s only used if untagged frames are allowed on ingress. And this default setting is the reason for discouraging use of VID=1 for tagged traffic – that is, it’s only too easy to forget about untagged dedault and then VLAN subnet integrity is compromised.


3) MAKE BRIDGE VLAN TABLE:

“/interface bridge vlan” determines which frames can leave (egress) the router by creating a VLAN table in which each configured vlan-id has a list of member ports.

Frames can only egress through a port which is a member of its vlan-id.

If port is “tagged member,” then VLAN tag will stay attached on egress.

If port is an “untagged member,” then VLAN tag will be stripped on egress.

The “tagged” and “untagged” properties of the command identify which ports are “tagged members” and which are “untagged members” for the specified vlan-id.

If port has property ingress-filtering=yes set, then port will only allow frames to pass on ingress if port is member of corresponding VLAN in this config section
each VLAN member port can either be tagged or untagged member.

If port has frame-types set to admit-only-untagged-and-priority-tagged or admit-all in bridge port section, then that port will be automatically added as an untagged port to the VLAN row (withing the table) with VID equal to the PVID of port (as set in /interface/bridge/port).

For example:

“/interface bridge vlan add bridge=bridge tagged=ether1 untagged=bridge vlan-id=10”

means that bridge will allow frames with vlan-id=10 to leave the router through ether1 with its vlan tag intact. And, will allow vlan-id=1- frames to egress the router on the bridge port after it strips the vlan tag.


Another example:

“/interface bridge vlan add bridge=BR1 tagged=ether1 untagged=BR1 vlan-ids=42”

means that the bridge named “BR1” will act as a bridge between switch and cpu where ether1 is a tagged member of vlan-id=42, and BR1 is an untagged member of vlan-id=42

Because if we consider personalities separate, it becomes very clear to which personality each of properties apply and what is its effect (there are no properties which affect more than single personality). Of course it’s also possible to not bother with different personalities and just learn by heart what each property means.

For example: frame-types … some people assume that setting frame-types on bridge affects all bridge ports (or even to bridge - the switch-like personality). If one understands that bridge is also CPU-facing bridge port, then it becomes clear that frame-types property applies to this personality.

I think your two examples are not quite the usual configurations. Normally the bridge CPU port (bridge and BR1 in your examples) is added to the tagged list, not the untagged list.

I’m so glad you addressed this.

I am very interested to understand why we use the term “personality.”

Specifically, when a bridge in ROS is set up we do not specify whether it is a ‘switch bridge’ or a ‘cpu bridge.’ That is to say, there is only 1 type of bridge.

Is it correct to say therefore that a bridge can serve different purposes depending on the configuration parameters?

For example, if a bridge is set up like this:

/interface bridge
add name=bridge1

then the created bridge will be a bridge that does nothing more than allow switching facility between it’s member ports?

On the other hand, if we execute:

/interface bridge
add admin-mac=F4:1E:57:8F:2D:85 auto-mac=no comment=defconf name=bridge port-cost-mode=short vlan-filtering=yes
add frame-types=admit-only-vlan-tagged name=test-bridge vlan-filtering=yes

The resulting bridge will be a bridge that passes frames between the bridge’s member ports and the CPU?

But, to be clear, is the following correct: There is only 1 type of bridge and it will either involve the CPU or not depending on the parameters or configuration settings.

Yes! Thank you! This is what is needed: Common scenarios or usages to use as examples.

Are these more commonly used forms of the configuration:

/interface bridge vlan
add bridge=bridge comment="VLAN20 egress ether4" tagged=bridge untagged=ether4 vlan-ids=20
add bridge=bridge comment="VLAN 30,40 egress ether2 port connected to AP" tagged=bridge,ether2,ether3 vlan-ids=30,40

And, very importantly, does this code mean:

VLAN20: frames tagged as vlan-id=20 will egress to the bridge (for processing by the CPU) with their vlan tags intact AND those same frames (i.e., with vlan-id=20 tag) will also egress on ether4 with their vlan tags stripped

VLAN30 and VLAN30: frames tagged with either vlan-id=20 or vlan-id=30 will egreess on ports bridge, ether2, and ether3 with their vlan tags intact.

Yes, and those frames that come to the CPU port (bridge) tagged, you “use” them by adding corresponding interfaces under /interface vlan with interface=bridge. Those interfaces pick the frames with the corresponding VLAN ID tagged (from the CPU port) and strip the tags so that they can be used as untagged frames coming from the corresponding /interface vlan interfaces (in-interface). When you send frames out of the /interface vlan interfaces (out-interface), those VLAN interfaces add the VLAN tag with the correct Id and use the CPU port to put the tagged frames on the switch chip. The switch chip then forwards the frames to the other egress ports.

Please bare with me – the likelyhood of me understanding this correctly is not high. How close am I:

The following config command creates vlan interfaces that associate the bridge (which we can also call the cpu port) to a name and an vlan-id.

/interface vlan
add interface=bridge name=vlan-interface20 vlan-id=20

And this single config command from the previously discussed config commands:

/interface bridge vlan
add bridge=bridge comment="VLAN20 egress ether4" tagged=bridge untagged=ether4 vlan-ids=20

will send (that is, allow egress from switch to bridge of) frames tagged with vlan-id=20 to the bridge.

At that time, the frames arriving (ingressing from switch to bridge) to the vlan interface named “vlan-interface20” will have their vlan tags stripped.

Then, the frames can be processed (such as routed or firewalled by the cpu) and returned to “vlan-interface20” and attached the the vlan tags for egress out the bridge to the switch.



Close?

Yes. And that’s the reason why if you add a VLAN interface to /interface vlan with interface=bridge then “bridge” needs to be in the tagged list of that VLAN ID. Since a few versions RouterOS dynamically adds that to the /interface bridge vlan table for you if you did not do it explicitly. And that’s also why putting bridge in the untagged list of that VLAN entry is wrong.

The CPU port “bridge” should only appear in the untagged list of the VLAN ID that “bridge” has in its PVID field, and only if frame-types (of “bridge”) is set to admit-all or admit-only-untagged-and-priority-tagged. And current RouterOS version also dynamically adds the entry with untagged=bridge for that VLAN ID if you didn’t do that.

We can think of it this way:

  • if a tagged frame arrives at the CPU port (from the switch chip) with VLAN ID matching the PVID of the “bridge” (and there is the corresponding entry with untagged=bridge). Then the tag is removed from the frame, and the interface that can consume that frame is the “bridge” interface (the one under /interface bridge).

  • If a tagged frame arrives at the CPU port (from the switch chip) and the ID is not PVID and is accepted (/interface bridge vlan table is checked) then it can be consumed by the associated vlan interface with the correct ID listed under /interface vlan.

You lost me with this.

“corresponding entry?”

“consumed?”

“correct id listed?”

The entry in /interface bridge vlan, with the VLAN ID matching the PVID of the bridge (under /interface bridge), and that has “bridge” in its untagged list. The entry that (if you have not explicitly done it yourself) is automatically created if the bridge has frame-types admit-all or admit-only-untagged-and-priority-tagged. Which means the entry only does not exist if the bridge port has frame-types admit-only-vlan-tagged.


The interface that can take the frames (no longer tagged) and make them available for the other parts of the router to use. For example, a DHCP server instance that you have created with interface=that_vlan_interface.(or interface=bridge in when we talk about the bridge as consumer of the frame).


I’ll reorder the sentence so that it becomes:

“then it can be consumed by the interface that is in the /interface vlan list, and that interface has the matching VLAN ID”.

I’m sorry, but I just cannot decipher this.

You can call them “functionality” if you wish. But, as already mentioned, term “bridge” is overloaded with (actually) 3 distinct features with only vague connection (but they are strongly connected). There’s no need to go into details about those 3 features, @sindy did it splendidly in this forum topic. Since they are distinct, but not unconnected, I like to call them “personalities” (just like dr. Jekyll and Mr. Hyde … but in this case, all personalities are active at all times, it only depends from which perspective one looks at bridge).


Yes, there’s only one type of bridge. But it’s flexible in what functions it does do (or at all), depending on how it’s set up. According to different personalities :wink::

  1. the CPU-facing bridge port. It’s created automatically with the creation of bridge and is permanently attached as bridge port. But it can be “disconnected” in a sense that it’s not referenced by any other configuration at all (e.g. it doesn’t have IP address bound, it doesn’t have VLAN interface attached, etc.). Just the same as with e.g. “dummy” switch with multiple ethernet RJ45 ports, but one is physically blocked and no ethernet device is ever connected to that RJ45 port. The port exists, but it’s never used. However it will never show as “not connected” (unlike physical RJ45 ports) due to existence of switch-facing interface discussed in bullet #3 below.
  2. the switch-like personality: it’s always there, without it one could not add multiple interfaces as bridge ports (in essence: that’s the reason for existence of /interface/bridge/port sub-tree). And it’s in use as soon as one adds first interface as bridge port … because that would be the second port of the bridge (the first being above mentioned CPU-facing bridge port) and this personality does forwarding of ethernet frames between different bridge ports according to it’s own forwarding rules.
    This personality can execute different functions if they are enabled and configured, e.g.:
  • handling of VLAN tags (tagging, untagging, filtering, etc.) if bridge has vlan-filtering enabled
    • running bridge filters if configured
    • running IP firewall rules against passing frames if configured
    • etc.
      Since bridge functions largely overlap with functions of a typical switch chip, those functions can be offloaded to switch chip if it exists and functions enabled and configured are supported by the particular switch chip type.
      It may be worth noticing that when a bridge only has one member port, otherwise connected to hardware switch chip, there’s nothing to be offloaded to actual hardware. Hardware only acts on frames passing between ports directly attached to it. But it doesn’t accept frames from (software) bridge, perform some function and return resulting frame back to (software) bridge. Example of such working would be traffic between e.g. wifi interface and eoip interface where bridge has to manipulate VLAN headers. It will always be the software performing these functions for traffic between said interfaces, frames won’t be passed to switch chip. OTOH the same bridge won’t even touch frames which will pass e.g. ether1 and ether2 (if ether1 and ether2 are ports of the same bridge as beforementioned wifi1 and eoip interfaces) if bridge functions are offloaded to switch chip. And all of this means that it’s pointless to force HW offload of bridge which has only one member port attached to switch chip.
  1. switch-facing interface which is also created automatically with the creation of bridge and is permanently mapped to bridge CPU-facing port. Here one has to define what is interface (in contrast with port). In this sense interface is entity which allows L3 stack (e.g. IPv4, IPv6, etc.) to set it’s own attributes (e.g. IP address) and communicate with certain L2 domain (e.g. physical ethernet infastructure, or VLAN). And port is an L2 connection point (which talks to L1 … e.g. ethernet port adds ethernet envelope to L3 packet and passes it down to MII which can work with electrical signals over UTP). Again one can decide not to use it by not attaching any L3 configuration to it.
    A side note: MAC address settings on bridge apply to this personality because bridge only needs MAC when router (the L3 entity) communicates with devices, connected to the same L2 domain. A switch doesn’t “leave traces” in switched frames, hence it doesn’t need own MAC address.

And, as mentioned, each of these 3 personalities are configured individually. Clearly personality #2 (switch-like entity) is unique (software) personality inside a routerboard device (no other entities can do switching between member ports. Other two personalities are each member of larger family of similar entities:

  1. CPU-facing port is similar to ethernet ports, WiFi interfaces, L2 tunneling interfaces (such as EOIP) … which can all be used as bridge ports … or directly as L3 interfaces
  2. switch-facing interface is mostly L2 port, as seen “from the other side” (all L2 ports can also serve as interfaces, used by ROS). But there are interfaces which can’t be used as ports (or as L2 entities if you want), e.g. all L3 tunneling interfaces, such as IPIP, wireguard, etc. If one want so use such interface, L3 setup is required (e.g. IP address set and referenced in routing configuration).

Example of using bridge as solely L2 entity (so avoiding personalities #1 and #3) but in a non-trivial way, would be:

/interface/bridge
add bridge=BRexample vlan-filtering=yes ingress-filtering=yes frame-types=admit-only-vlan-tagged
# the later property in bridge definition is in this example only set to invalidate the implicit PVID setting
/interface/bridge/port
add bridge=BRexample interface=ether1 pvid=666 frame-types=admit-only-untagged-and-priority-tagged ingress-filtering=yes
add bridge=BRexample interface=sfp-sfpplus1 frame-types=admit-only-vlan-tagged ingress-filtering=yes
add bridge=BRexample interface=wifi1 pvid=333 frame-types=admit-only-untagged-and-priority-tagged ingress-filtering=yes
/interface/bridge/vlan
add bridge=BRexample tagged=sfp-sfpplus1 untagged=wifi1 vlan-ids=333
add bridge=BRexample tagged=sfp-sfpplus1 untagged=ether1 vlan-ids=666

(definition of untagged ports in /interface/bridge/vlan is not necessary in recent ROS versions, but they are there to make example clear)

So bridge CPU-facing port is set as tagged-only but it’s not set as member of any VLANs. Enabling ingress-filtering is important to ensure that bridge switch-facing interface can not inject frames with VID set to “foreign” VLAN IDs … and in this case, all VLAN IDs are “foreign” as bridge is not member of any VLANs. And due to setting frame-types=admit-only-vlan-tagged that’s also true for (implicitly set) PVID=1. If it was not for this setting, bridge would be (untagged) member of VLAN1 which would make possible to inject frames to VLAN 1.

So bridge switch-facing interface is effectively disabled as no traffic between bridge CPU-facing port and the rest of switch-like entity is allowed. Which leaves only personality #2 (switch-like entity) alive and kicking.