802.1Q VLAN implementation for Linux

PLUG: Check out LANforge traffic generation and WAN simulation
test equipment based on the Linux operating system:
LANforge is similar to Charriot and Smartbits for traffic generation needs. It can
generate Ethernet, UDP, TCP, HTTP, FTP, VOIP (SIP, RTP) and other protocols.
LANforge-ICE is a WAN emulator and network-impairment test tool. It can inject latency,
jitter, packet loss and other network abnormalities in a controlled fashion.

802.1Q VLAN code is now part of the official kernel, and has been for years
and years. MAC-VLAN code has been added since around 2.6.29.
It is very unlikely that you need to download anything from this site, the
packages are left here for posterity's sake.
Please send questions and bug reports to the linux network mailing list:
netdev@vger.kernel.org.

802.1Q VLANs and MAC-VLANs can be created with the 'ip' utility
(vconfig works for vlans, but is crufty and deprecated).

Scales well in critical paths: O(n), where n is the number of PHYSICAL ethernet interfaces,
and that is only on ingress. O(1) in every other critical path, as far as I know.

Supports MULTICAST

Can change MAC address of VLAN.

Multiple naming conventions supported, and adjustable at runtime.

Optional header-reordering, to make the VLAN interface look JUST LIKE
an Ethernet interface. This fixes some problems with DHCPd and anything else
that uses a SOCK_PACKET socket. Default setting is off, which works for
every other protocol I know about, and is slightly faster.

Updated MAC-VLAN code and completed testing. Based on Alex Zeffertt's
work but much has been re-written and he cannot be held responsible!
Please send all bug reports to the VLAN mailing list. The Candela Technologies unified
patch is the thing to apply now, and it contains various other not-necessarily-VLAN
related bits and pieces.

Really fixed (and tested) MAC change-ability. When you set the MAC address on
a VLAN, it will also attempt to set the underlying device to PROMISCious mode
(otherwise, the VLAN will not receive any packets.)

Hashed-device lookup is disabled by default because some people had trouble with
the 'lo' device. Please feel free to re-enable by editing the line in net/core/dev.c
(search for #define BEN_FAST_DEV_LOOKUP).

vconfig should warn when creating VLAN 1, because that VLAN is not compatible with many
switches.

Added support for MULTICAST to the VLAN devices. Thanks to
Gleb & Co for most of
that code.

Added the ability to set the MAC address on the VLAN. For now, you'll either need
to set your Ethernet NIC into PROMISC mode, or maybe figure out some multi-cast
ethernet address to set on the NIC. This has not been tested well at all.

Added a hashed device-name lookup scheme. This greatly speeds up ifconfig -a.
I was able to run an ifconfig -a in 20 seconds on a Celeron 500, with 4000
vlan devices configured!!

Added vlan_test.pl to help me find dumb bugs. Feel free to make this much
more powerful, and send the code back to me!

vconfig.c has been converted to C code now, instead of C++. Thanks to MATHIEU.

Significantly cleaned up the code w/out decreasing any useful functionality,
I believe.

Removed the DHCP stuff from the VLAN distribution.

Release 0.0.12 (gz) For Kernel: 2.2.16, 2.4.pre7 August 27, 2000:
Added ability to re-order the VLAN packet so that it looks like a real ethernet
packet for the ingress pathway. This should help DHCP and other programs that insist
on reading the raw buffer and then make assumptions about byte offsets. I don't have
a good way to test this fully, so consider it experimental :) This behavior can be
changed at run-time, and is set on a per-VLAN basis. The default is NOT to reorder the
header, which has been the only behavior up untill this point. The vconfig
program can set/clear the flag, by using a VLAN IOCTL. You can read the flag's value
from the /proc/net/vlan/vlan* files.

You can also set a default priority on a NON-VLAN device. This priority will only
be used when the default_VID for the device is set as well. This priority won't
be mapped anywhere, just copied straight into the skb->priority. It is a uint16.

The 2.3 patch is now the 2.4 patch, and it has been tested against 2.4.pre7.

Release 0.0.11 (gz) For Kernel: 2.2.13/14, 2.3.99 April 23, 2000:
Added real support for PRIORITY. Through IOCTL calls (see the vconfig program), you can set
explicit ingress and egress mappings to/from the VLAN QOS bits and the sk_buff->priority
field. This is not tested very well, as I don't know much about how people really use the
priority field... Took out the round-robin aggretation that went in in rls 0.10, as it was
mainly just a hack, and doing link aggregation at a lower level and then putting VLAN on
top of that virtual device probably makes more sense. The vconfig program changed to support
the new features..here's it's new usage:

Usage: add [interface-name] [vlan_id]
rem [vlan-name]
set_dflt [interface-name] [vlan_id]
add_port [port-name] [vlan_id]
rem_port [port-name] [vlan_id]
set_egress_map [vlan-name] [skb_priority] [vlan_qos]
set_ingress_map [vlan-name] [skb_priority] [vlan_qos]
set_name_type [name-type]
set_bind_mode [bind-type]
* The [interface-name] is the name of the ethernet card that hosts
the VLAN you are talking about.
* The port-name is the name of the physical interface that a VLAN
may be attached to.
* The vlan_id is the identifier (0-4095) of the VLAN you are operating on.
* skb_priority is the priority in the socket buffer (sk_buff).
* vlan_qos is the 3 bit priority in the VLAN header
* name-type: VLAN_PLUS_VID (vlan0005), VLAN_PLUS_VID_NO_PAD (vlan5),
DEV_PLUS_VID (eth0.0005), DEV_PLUS_VID_NO_PAD (eth0.5)
* bind-type: PER_DEVICE # Allows vlan 5 on eth0 and eth1 to be unique.
PER_KERNEL # Forces vlan 5 to be unique across all devices.

The 2.3 patches have been ported foward to 2.3.99, thanks to Patrick for the vlanproc.c
updates!

Now, you should have a vlan directory in your home directory. You only have
to patch the kernel if you are using Linux 2.4.14 or earlier. Now,
read the README or other docs to figure out what kernel it patches against.
A list of mirrors are kept at www.kernel.org.
Unzip and un-tar this in your home directory as well, which should
create a linux directory in your $HOME directory. Example:
tar -xvzf linux-2.2.14.tar.gz

Now add the VLAN kernel changes to the kernel if your kernel requires it. I finally figured
out how to do patches that diff can handle (I think I did it right at least!). You
will find the patch in the vlan directory. It will be called: vlan.patch,
or something equally straight-foward. Apply the patch to your kernel:

cd $HOME/linux
patch -p 1 < $HOME/vlan/[vlan.patch]

Your new, patched, kernel should be in your INCLUDE path before trying to
compile the vconfig program. One way to get things working is to link $HOME/linux
to the 'linux' directory that you just un-zipped and patched. A command might
be something like:
cd $HOME; ln -s /home/greear/kernel/2.4/linux.dev linux

Build the vconfig program in the $HOME/vlan directory:cd $HOME/vlan
make

Now, time to compile your new kernel! Use the make xconfig
command in your $HOME/linux directory to select your kernel options. The
option related to 802.1Q VLANs is found under the Networking options.
If the option is not highlighted, make sure you select "Experimental Drivers"
in one of the first xconfig menus.

Assuming your kernel compiled cleanly (yell if it didn't and you think my
code broke it!!), you are now ready to try it out!! Install your kernel
in the normal manner (fix up your /etc/lilo.conf file appropriately and
run lilo as root.) Reboot your computer and choose your new kernel.

As your computer comes back to life, there will be little sign that you are
now 802.1Q capable, other than a line spit out during the boot process.
There should be a config programs in your $HOME/vlan
directory: vconfig. vconfig is used
to create and destroy VLAN devices. So, lets create a VLAN device on your
first ethernet NIC. vconfig<return> will list a short spiel on how to
use it. The vconfig command I usually use is:

vconfig add eth0 5

This attempts to create a VLAN device with VLAN-ID of 5 on the eth0 device.
If you want to delete a VLAN, use something like:

vconfig rem eth0.5

You will also need to give it an ip, eg: ifconfig -i eth0.5 192.168.2.1
and configure it UP: ifconfig -i eth0.5 up

NOTE: You can get lots of VLAN related configuration information from
the /proc/net/vlan/* files by using 'cat' or 'more' to look at them.

Please get in contact with me if you have suggestions, patches, or other
comments.