Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 17 Apr 2004 16:25:06 -0400
From:      "Adam C. Migus" <adam@migus.org>
To:        current@freebsd.org
Subject:   VLAN support in rcNG [PATCH]
Message-ID:  <1082233506.408192a2c476a@webservices.migus.org>

next in thread | raw e-mail | index | archive | help
This message is in MIME format.

---MOQ10822335069561d2e9704345db832404d092d7d590
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit

The following is a patch that adds support for vlan creation and
destruction within rcNG.  Using the patch it's possible, for example,
to create a vlan, `vlan0' with the following directives in rc.conf:

vlan_interfaces="vlan0"
ifconfig_vlan0="DHCP"
ifconfig_vlan0_vlan_dev="xl0"
ifconfig_vlan0_vlan_tag="2"

Is this patch of general interest?  Should I submit a PR?

The patch (also attached):

--- etc/network.subr.orig       Sat Apr 17 16:13:28 2004
+++ etc/network.subr    Sat Apr 17 16:03:04 2004
@@ -250,6 +250,47 @@
        return $_ret
 }
  
+# Create vlan interfaces.
+#
+vlan_up()
+{
+       _prefix=
+       _list=
+       for ifn in ${vlan_interfaces}; do
+               ifconfig ${ifn} create
+               if [ $? -eq 0 ]; then
+                       _list="${_list}${_prefix}${ifn}"
+                       [ -z "$_prefix" ] && _prefix=' '
+                       eval local _v_dev=\$ifconfig_${ifn}_vlan_dev
+                       eval local _v_tag=\$ifconfig_${ifn}_vlan_tag
+                       if [ -n "${_v_dev}" -a -n "${_v_tag}" ]; then
+                               ifconfig ${ifn} vlan ${_v_tag} vlandev
${_v_dev}+                               if [ $? -ne 0 ]; then
+                                       debug "Vlan: cannot set vlan
dev/tag."
+                               fi
+                       fi
+               fi
+       done
+       debug "Vlan created: ${_list}"
+}
+
+# Destroy vlan interfaces. Destroyed interfaces are echoed
+# to standard output.
+#
+vlan_down()
+{
+       _prefix=
+       _list=
+       for ifn in ${vlan_interfaces}; do
+               ifconfig ${ifn} destroy
+               if [ $? -eq 0 ]; then
+                       _list="${_list}${_prefix}${ifn}"
+                       [ -z "$_prefix" ] && _prefix=' '
+               fi
+       done
+       debug "Destroyed vlans: ${_list}"
+}
+
 #
 # list_net_interfaces type
 #      List all network interfaces. The type of interface returned
--- etc/rc.d/netif.orig Sat Apr 17 15:57:48 2004
+++ etc/rc.d/netif      Sat Apr 17 15:57:40 2004
@@ -50,6 +50,9 @@
                # Create cloned interfaces
                clone_up
  
+               # Create cloned interfaces
+               vlan_up
+
                # Create IPv6<-->IPv4 tunnels
                gif_up
        fi
--- etc/defaults/rc.conf.orig   Sat Apr 17 16:06:53 2004
+++ etc/defaults/rc.conf        Sat Apr 17 16:11:49 2004
@@ -108,6 +108,10 @@
 network_interfaces="auto"      # List of network interfaces (or
"auto").
 cloned_interfaces=""           # List of cloned network interfaces to
create.
 #cloned_interfaces="gif0 gif1 gif2 gif3" # Pre-cloning GENERIC config.
+vlan_interfaces=""             # List of vlan network interfaces to
create.
+#vlan_interfaces="vlan0"       # Sample vlan entry.
+#ifconfig_vlan0_vlan_dev=""    # Physical interface associated with
this vlan.
+#ifconfig_vlan0_vlan_tag=""    # Vlan tag associated with this vlan.
 ifconfig_lo0="inet 127.0.0.1"  # default loopback device
configuration.
 #ifconfig_lo0_alias0="inet 127.0.0.254 netmask 0xffffffff" # Sample
alias entry.
 #ifconfig_ed0_ipx="ipx 0x00010010"     # Sample IPX address family
entry.

-- 
Adam C. Migus -- http://people.migus.org/~adam/

---MOQ10822335069561d2e9704345db832404d092d7d590
Content-Type: application/octet-stream; name="FreeBSD-5.x-vlan.patch"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="FreeBSD-5.x-vlan.patch"

LS0tIGV0Yy9uZXR3b3JrLnN1YnIub3JpZwlTYXQgQXByIDE3IDE2OjEzOjI4IDIwMDQKKysrIGV0
Yy9uZXR3b3JrLnN1YnIJU2F0IEFwciAxNyAxNjowMzowNCAyMDA0CkBAIC0yNTAsNiArMjUwLDQ3
IEBACiAJcmV0dXJuICRfcmV0CiB9CiAKKyMgQ3JlYXRlIHZsYW4gaW50ZXJm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mV0d29yayBpbnRl
cmZhY2VzIHRvIGNyZWF0ZS4KKyN2bGFuX2ludGVyZmFjZXM9InZsYW4wIgkjIFNhbXBsZSB2bGFu
IGVudHJ5LgorI2lmY29uZmlnX3ZsYW4wX3ZsYW5fZGV2PSIiCSMgUGh5c2ljYWwgaW50ZXJmYWNl
IGFzc29jaWF0ZWQgd2l0aCB0aGlzIHZsYW4uCisjaWZjb25maWdfdmxhbjBfdmxhbl90YWc9IiIJ
IyBWbGFuIHRhZyBhc3NvY2lhdGVkIHdpdGggdGhpcyB2bGFuLgogaWZjb25maWdfbG8wPSJpbmV0
IDEyNy4wLjAuMSIJIyBkZWZhdWx0IGxvb3BiYWNrIGRldmljZSBjb25maWd1cmF0aW9uLgogI2lm
Y29uZmlnX2xvMF9hbGlhczA9ImluZXQgMTI3LjAuMC4yNTQgbmV0bWFzayAweGZmZmZmZmZmIiAj
IFNhbXBsZSBhbGlhcyBlbnRyeS4KICNpZmNvbmZpZ19lZDBfaXB4PSJpcHggMHgwMDAxMDAxMCIJ
IyBTYW1wbGUgSVBYIGFkZHJlc3MgZmFtaWx5IGVudHJ5Lgo=

---MOQ10822335069561d2e9704345db832404d092d7d590--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1082233506.408192a2c476a>