LinuxQuestions.org

LinuxQuestions.org (http://www.linuxquestions.org/questions/index.php)
-   Linux - Networking (http://www.linuxquestions.org/questions/forumdisplay.php?f=3)
-   -   Any source documentation for ifcfg VLAN id 'dot' device names? (http://www.linuxquestions.org/questions/showthread.php?t=4175449215)

jnielsen7 02-08-2013 02:50 PM

Any source documentation for ifcfg VLAN id 'dot' device names?
 
If you have ever implemented the 802.1q VLAN protocol in Linux you quickly discover that in your ifcfg-* files (RHEL: /etc/sysconfig/network-scripts/ifcfg-ethX) you will have to use a dot or period, the '.', in the device name for the "DEVICE=" value (ex: DEVICE=eth0.20, which will create a subinterface on eth0 - which probably is not VLAN tagging - and will send all traffic over that subinterface with a VLAN id of 20). Also, alternately if you want simple subinterfaces without VLAN tagging you can just use a colon (ex: DEVICE=eth0:1). However aside from config HOWTOs and blogs (which all seems to be word-of-mouth and no-source-citation) this feature of Linux 802.1q tagging seems fairly undocumented and I have looked fairly extensively online for anything relevant (not to mention it is difficult to Google for a special character that you can only call 'dot'). I do not care if I have to look at source code but I would like to know where the syntax rules are (especially for delimiters) for what determines and creates the right "type" of interface based on the device ':' or '.' notation in the ifcfg-* files.

Also, it seems that there is an alternate way to assign vlans to interfaces with the vconfig tool, which makes me wonder if whatever parses the ifcfg-* files shares with it the same code underneath. The only other relevant piece of information that I've been able to find is that the kernel module 8021q seems to be involved ("lsmod | grep 8021q") and that sometimes NIC specific drivers which are also loaded into the kernel will use it (in the "Used by" column of lsmod). I've poked around in /proc/net/vlan/ but still cannot figure out what implements the '.' dot notation to indicate that it should create a VLAN.

Is there a man page that I missed or will I have to dig through source code?

Thanks,
Josh

Ser Olmy 02-09-2013 08:14 AM

When you add a VLAN subinterface (with a dot and a number), you are indeed configuring 802.1q VLAN tagging. This is handled by the 8021q kernel module. Traffic sent to a VLAN subinterface will be sent out the parent interface with a 8021q header, and the VLAN tag always corresponds to the subinterface number.

The "interface:alias" format is just a way of adding layer 3 addresses to an existing interface. The "alias" part can be any alphanumeric string; eth0:0, wlan1:secondary and eth1.23:test2 are valid aliases of the eth0, wlan1 and eth1.23 interfaces respectively. Since it is possible to add and remove addresses with the ip addr add and ip addr del commands, the alias format is no longer required and, as I understand it, deprecated.

The vconfig command is not an alternate method of configuring a VLAN interface, it is the method. The ifcfg-* files are simply parsed by other scripts or tools, and in the end the vconfig command is run with the relevant parameters.

(At least that's how it used to work; it's entirely possible that more recent inventions like NetworkManager does this with a direct system call rather than relying on vconfig.)

jnielsen7 02-11-2013 09:18 AM

Quote:

Originally Posted by Ser Olmy (Post 4887591)
When you add a VLAN subinterface (with a dot and a number), you are indeed configuring 802.1q VLAN tagging. This is handled by the 8021q kernel module. Traffic sent to a VLAN subinterface will be sent out the parent interface with a 8021q header, and the VLAN tag always corresponds to the subinterface number.

The "interface:alias" format is just a way of adding layer 3 addresses to an existing interface. The "alias" part can be any alphanumeric string; eth0:0, wlan1:secondary and eth1.23:test2 are valid aliases of the eth0, wlan1 and eth1.23 interfaces respectively. Since it is possible to add and remove addresses with the ip addr add and ip addr del commands, the alias format is no longer required and, as I understand it, deprecated.

The vconfig command is not an alternate method of configuring a VLAN interface, it is the method. The ifcfg-* files are simply parsed by other scripts or tools, and in the end the vconfig command is run with the relevant parameters.

(At least that's how it used to work; it's entirely possible that more recent inventions like NetworkManager does this with a direct system call rather than relying on vconfig.)

Thank you, that is helpful information. I actually was not aware that what came after a colon was an alias, and I thought it had to be numeric, so that was informative. This is probably enough information for what I need, although I suppose as a fun project some time I could look for those "scripts or tools" that parse the ifcfg-* files.

Thanks again,
Josh

jnielsen7 07-26-2013 12:49 PM

I have since found a small bit of documentation for the interface:alias colon delimited notation in the Kernel source documentation in the Documentation/networking/alias.txt file: https://www.kernel.org/doc/Documenta...king/alias.txt. It also says there that is is deprecated but is maintained/allowed for backwards compatability.

As for VLAN tagging on interfaces using the dot notation in device names of /etc/sysconfig/network-scripts/ifcfg-* configuration files:

It appears that the dot notation in the network device is indeed specified/implemented in the code for the the 8021q kernel module itself, and whatever parses the ifcfg-* files (I still don't know that does that - where is that code?) is meant to find/expect a "device=eth[X].[VID]" name for the network interface - otherwise the kernel module could not use it.

From this page (http://www.candelatech.com/~greear/vlan.html) the Release Notes for version 1.0.3 of the 8021q module notes the following:
  • One of those requests was to change the default naming scheme to eth0.5, for a VLAN of VID 5 on eth0. You can over-ride this naming behaviour with the vconfig tool.
It looks like previously there already was a "non-padded" vid version of this though (called VLAN_NAME_TYPE_RAW_PLUS_VID) like: eth0.0005 for VID 5 so I'm still not sure when the first decision was made to use a dot, but I think it primarily is made that way for the benefit of providing a delimiter in the kernel module's code in any case.

I downloaded that version of the code from that page and looked at the patch file and found the relevant code.

First an ENUM list of various name types/notations that are valid:

Code:

enum vlan_name_types {
        VLAN_NAME_TYPE_PLUS_VID, /* Name will look like:  vlan0005 */
        VLAN_NAME_TYPE_RAW_PLUS_VID, /* name will look like:  eth1.0005 */
        VLAN_NAME_TYPE_PLUS_VID_NO_PAD, /* Name will look like:  vlan5 */
        VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD, /* Name will look like:  eth0.5 */
        VLAN_NAME_TYPE_HIGHEST
};

Then it chooses the name type VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD as a default to have names like eth[X].[VID] (e.g. eth0.5):

Code:

/** These may be changed at run-time through IOCTLs */
unsigned short vlan_name_type = VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD; /* determines interface naming scheme */
unsigned long vlan_bad_proto_recvd = 0; /* Counter for how many NON-VLAN protos we've received on a VLAN. */

Then here is the code that uses it in the register_802_1Q_vlan_device function/subroutine:

Code:

struct net_device *register_802_1Q_vlan_device(const char* eth_IF_name,
                                              unsigned short VLAN_ID) {
...
...

#ifdef VLAN_DEBUG
                                printk(VLAN_DBG "About to allocate name, vlan_name_type: %i\n", vlan_name_type);
#endif

 switch (vlan_name_type) {
                                  case VLAN_NAME_TYPE_RAW_PLUS_VID:
                                        /* name will look like:  eth1.0005 */
                                        sprintf(new_dev->name, "%s.%.4i", real_dev->name, VLAN_ID);
                                        break;
                                  case VLAN_NAME_TYPE_PLUS_VID_NO_PAD:
                                        /* Put our vlan.VID in the name.
                                          Name will look like:  vlan5 */
                                        sprintf(new_dev->name, "vlan%i", VLAN_ID);
                                        break;
                                  case VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD:
                                        /* Put our vlan.VID in the name.
                                          Name will look like:  eth0.5 */
                                        sprintf(new_dev->name, "%s.%i", real_dev->name, VLAN_ID);
                                        break;
                                  case VLAN_NAME_TYPE_PLUS_VID:
                                        /* Put our vlan.VID in the name.
                                          Name will look like:  vlan0005 */
                                  default:
                                        /* default case */
                                        sprintf(new_dev->name, "vlan%.4i", VLAN_ID);
                                }/* switch */

#ifdef VLAN_DEBUG
                                printk(VLAN_DBG "Allocated new name -:%s:-\n", new_dev->name);
#endif
                                /* set up method calls */
                                new_dev->init = vlan_dev_init;
                                new_dev->destructor = vlan_dev_destruct;
           
                                /* new_dev->ifindex = 0;  it will be set when added to
                                * the global list.
                                * iflink is set as well. */
           
                                new_dev->get_stats = vlan_dev_get_stats;
           
                                /* IFF_BROADCAST|IFF_MULTICAST; ??? */
                                new_dev->flags = real_dev->flags;
                                new_dev->flags &= ~IFF_UP;

                                /* Make this thing known as a VLAN device */
                                new_dev->more_flags |= IFF_802_1Q_VLAN;

...
...
}

If anyone knows about any notes not interspersed in code, as to how the ifcfg-* files are parsed and the device name passed to vconfig, please let me know.

That's as far as I care to go for now into digging for the sources of those notations.


All times are GMT -5. The time now is 07:47 AM.