Why Are VLAN Interface Names Forced to Start With 'vlan0'

Started by Al Muckart, Today at 06:00:46 AM

Previous topic - Next topic
OPNsense won't let me create a VLAN interface whose name doesn't start with 'vlan0'.

This isn't a FreeBSD restriction, and it makes it impossible to properly associate a VLAN subinterface's name with its parent. It also eats five of the 15 characters available for naming.

Is it inherited from pfSense or is there some hidden reason for it?

Thanks.

This is not a FreeBSD restriction, nor is it inherited from pfSense. In fact, I raised similar concerns when the naming scheme was changed back in 2022.

There were essentially three reasons for the current restrictions:

1. Support for stacked VLANs (QinQ): The old naming convention (`igb0_vlan100`) was abandoned in 22.1.4 because stacked VLANs (`igb0_vlan100_vlan200`) could exceed FreeBSD's 15-character interface name limit.

  https://forum.opnsense.org/index.php?topic=27931.0

2. Avoiding naming collisions: The leading zero is intentional to avoid collisions with interface names automatically generated by FreeBSD's interface cloning mechanism. The actual commit that introduced the stricter validation can be found here:

  https://github.com/opnsense/core/commit/2d74c6b641d7dfd0594cb4e8ca84b25667c599bf

3. Legacy code: This is probably the most relevant reason for not allowing arbitrary names. Franco explained in a German forum thread in January 2023 that OPNsense has historically relied on string matching of interface names to determine interface types. Unfortunately, these checks are not consistent throughout the codebase. Allowing arbitrary names could therefore cause subtle problems, while refactoring those checks could introduce regressions.

  https://forum.opnsense.org/index.php?topic=31802.0

Technically, you can still rename VLAN interfaces by editing `config.xml`, provided you update all references accordingly. I would be cautious about completely arbitrary names, though, given Franco's explanation.

IMHO, decoupling VLAN interface names from their parent interfaces and enforcing a particular naming convention are two separate design decisions. While I can understand the rationale for the former, the latter appears to be primarily a consequence of technical debt rather than an inherent technical necessity.

It would be interesting to know whether these limitations in the OPNsense codebase still exist today as technical debt to the same extent as they did in 2022/2023.
Intel N100, 4* I226-V, 2* 82559, 16 GByte, 500 GByte NVME, Leox LXT-010H-D

1100 down / 450 up, Bufferbloat A+

Thank you for that considered and detailed explanation, I really appreciate it.

We'd briefly discussed extending device names to 32 characters (or even 64) with FreeBSD devs which would free this up a bit more, but it's quite tedious to do this while also retaining kernel compatibility with the short fixed name already embedded in existing structures. A nicer alternative would be an alias name which doesn't have this restriction but it adds a lot of plumbing which nobody has committed to.

Even with longer names embedding information into the device names has downsides during reconfiguration where e.g. a parent changes or when stacking for QinQ or adding the IDs to them which. em0.1.2 looks pretty innocent, but if you fiddle with the VLAN which has ID 1 you're forcing a rename of the device which brings life cycle concerns and you also don't know how the kernel reacts on such renames with certain drivers (are they going to reset what you don't actually want).

The much nicer way would be to use a UUID as a device name, but that would also raise some complaints by people. We can't do it anyway, because 16 characters is a bit short either way.


Cheers,
Franco

Quote from: Al Muckart on <strong>Today</strong> at 09:40:24 AMThank you for that considered and detailed explanation, I really appreciate it.
+1 :)

I was a bit confused by all of this too when setting up my first VLAN Interface at the time, but eventually learned to live with it's weirdness, however totally forgot to ask why it is the way it is...

Now I know!
Weird guy who likes everything Linux and *BSD on PC/Laptop/Tablet/Mobile and funny little ARM based boards :)