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>
index | next in thread | raw e-mail
[-- Attachment #1 --]
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/
[-- Attachment #2 --]
--- 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.
help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1082233506.408192a2c476a>
