svn commit: r202169 - in stable/7: etc etc/defaults etc/rc.d share/man/man5

John Baldwin jhb at FreeBSD.org
Tue Jan 12 20:06:04 UTC 2010


Author: jhb
Date: Tue Jan 12 20:06:04 2010
New Revision: 202169
URL: http://svn.freebsd.org/changeset/base/202169

Log:
  MFC 201215:
  Add support for configuring vlan(4) interfaces as child devices similar to
  wlan(4) interfaces.  vlan(4) interfaces are listed via a new 'vlans_<IF>'
  variable.  If a vlan interface is a number, then that number is treated as
  the vlan tag for the interface and the interface will be named '<IF>.<tag>'.
  Otherwise, the vlan tag must be provided via a vlan parameter in a
  'create_args_<vlan>' variable.
  
  While I'm here, fix a few nits in rc.conf(5) and mention create_args_<IF> in
  the description of cloned_interfaces.
  
  The changes for 7.x are a bit larger as they introduce childif_create() and
  childif_destroy() and move ifn_start() and ifn_stop() from rc.d/netif to
  network.subr.

Modified:
  stable/7/etc/defaults/rc.conf
  stable/7/etc/network.subr
  stable/7/etc/rc.d/netif
  stable/7/share/man/man5/rc.conf.5   (contents, props changed)
Directory Properties:
  stable/7/etc/   (props changed)
  stable/7/share/man/man5/   (props changed)

Modified: stable/7/etc/defaults/rc.conf
==============================================================================
--- stable/7/etc/defaults/rc.conf	Tue Jan 12 19:59:54 2010	(r202168)
+++ stable/7/etc/defaults/rc.conf	Tue Jan 12 20:06:04 2010	(r202169)
@@ -192,6 +192,8 @@ ifconfig_lo0="inet 127.0.0.1"	# default 
 #ifconfig_lo0_alias0="inet 127.0.0.254 netmask 0xffffffff" # Sample alias entry.
 #ifconfig_ed0_ipx="ipx 0x00010010"	# Sample IPX address family entry.
 #ifconfig_fxp0_name="net0"	# Change interface name from fxp0 to net0.
+#vlans_fxp0="101 vlan0"		# vlan(4) interfaces for fxp0 device
+#create_arg_vlan0="vlan 102"	# vlan tag for vlan0 device
 #ipv4_addrs_fxp0="192.168.0.1/24 192.168.1.1-5/28" # example IPv4 address entry.
 #
 #autobridge_interfaces="bridge0"	# List of bridges to check 

Modified: stable/7/etc/network.subr
==============================================================================
--- stable/7/etc/network.subr	Tue Jan 12 19:59:54 2010	(r202168)
+++ stable/7/etc/network.subr	Tue Jan 12 20:06:04 2010	(r202169)
@@ -30,6 +30,48 @@
 # Requires that rc.conf be loaded first.
 #
 
+# ifn_start ifn
+#	Bring up and configure an interface.  If some configuration is
+#	applied print the interface configuration.
+#
+ifn_start()
+{
+	local ifn cfg
+	ifn="$1"
+	cfg=1
+
+	[ -z "$ifn" ] && err 1 "ifn_start called without an interface"
+
+	ifscript_up ${ifn} && cfg=0
+	ifconfig_up ${ifn} && cfg=0
+	ipv4_up ${ifn} && cfg=0
+	ipx_up ${ifn} && cfg=0
+	childif_create ${ifn} && cfg=0
+
+	return $cfg
+}
+
+# ifn_stop ifn
+#	Shutdown and de-configure an interface.  If action is taken
+#	print the interface name.
+#
+ifn_stop()
+{
+	local ifn cfg
+	ifn="$1"
+	cfg=1
+
+	[ -z "$ifn" ] && err 1 "ifn_stop called without an interface"
+
+	ipx_down ${ifn} && cfg=0
+	ipv4_down ${ifn} && cfg=0
+	ifconfig_down ${ifn} && cfg=0
+	ifscript_down ${ifn} && cfg=0
+	childif_destroy ${ifn} && cfg=0
+
+	return $cfg
+}
+
 # ifconfig_up if
 #	Evaluate ifconfig(8) arguments for interface $if and
 #	run ifconfig(8) with those arguments. It returns 0 if
@@ -452,6 +494,70 @@ clone_down()
 	debug "Destroyed clones: ${_list}"
 }
 
+# childif_create
+#	Create and configure child interfaces.  Return 0 if child
+#	interfaces are created.
+#
+childif_create()
+{
+	local cfg child child_vlans create_args ifn i
+	cfg=1
+	ifn=$1
+
+	# Create vlan interfaces
+	child_vlans=`get_if_var $ifn vlans_IF`
+
+	if [ -n "${child_vlans}" ]; then
+		load_kld if_vlan
+	fi
+
+	for child in ${child_vlans}; do
+		if expr $child : '[1-9][0-9]*$' >/dev/null 2>&1; then
+			child="${ifn}.${child}"
+			create_args=`get_if_var $child create_args_IF`
+			ifconfig $child create ${create_args} && cfg=0
+		else
+			create_args="vlandev $ifn `get_if_var $child create_args_IF`"
+			if expr $child : 'vlan[0-9][0-9]*$' >/dev/null 2>&1; then
+				ifconfig $child create ${create_args} && cfg=0
+			else
+				i=`ifconfig vlan create ${create_args}`
+				ifconfig $i name $child && cfg=0
+			fi
+		fi
+		if autoif $child; then
+			ifn_start $child
+		fi
+	done
+
+	return ${cfg}
+}
+
+# childif_destroy
+#	Destroy child interfaces.
+#
+childif_destroy()
+{
+	local cfg child child_vlans ifn
+	cfg=1
+
+	child_vlans=`get_if_var $ifn vlans_IF`
+	for child in ${child_vlans}; do
+		if expr $child : '[1-9][0-9]*$' >/dev/null 2>&1; then
+			child="${ifn}.${child}"
+		fi
+		if ! ifexists $child; then
+			continue
+		fi
+		if autoif $child; then
+			ifn_stop $child
+		fi
+		ifconfig $child destroy && cfg=0
+	done
+
+	return ${cfg}
+}
+
 # Create netgraph nodes.
 #
 ng_mkpeer() {

Modified: stable/7/etc/rc.d/netif
==============================================================================
--- stable/7/etc/rc.d/netif	Tue Jan 12 19:59:54 2010	(r202168)
+++ stable/7/etc/rc.d/netif	Tue Jan 12 20:06:04 2010	(r202169)
@@ -149,37 +149,5 @@ network_common()
 	debug "The following interfaces were not configured: $_fail"
 }
 
-ifn_start()
-{
-	local ifn cfg
-	ifn="$1"
-	cfg=1
-
-	[ -z "$ifn" ] && return 1
-
-	ifscript_up ${ifn} && cfg=0
-	ifconfig_up ${ifn} && cfg=0
-	ipv4_up ${ifn} && cfg=0
-	ipx_up ${ifn} && cfg=0
-
-	return $cfg
-}
-
-ifn_stop()
-{
-	local ifn cfg
-	ifn="$1"
-	cfg=1
-
-	[ -z "$ifn" ] && return 1
-
-	ipx_down ${ifn} && cfg=0
-	ipv4_down ${ifn} && cfg=0
-	ifconfig_down ${ifn} && cfg=0
-	ifscript_down ${ifn} && cfg=0
-
-	return $cfg
-}
-
 load_rc_config $name
 run_rc_command $*

Modified: stable/7/share/man/man5/rc.conf.5
==============================================================================
--- stable/7/share/man/man5/rc.conf.5	Tue Jan 12 19:59:54 2010	(r202168)
+++ stable/7/share/man/man5/rc.conf.5	Tue Jan 12 20:06:04 2010	(r202169)
@@ -1149,6 +1149,45 @@ and
 .Va ifconfig_ Ns Ao Ar interface Ac Ns Va _alias Ns Aq Ar n
 variables.
 .Pp
+If a
+.Va vlans_ Ns Aq Ar interface
+variable is set,
+a
+.Xr vlan 4
+interface will be created for each item in the list with the
+.Ar vlandev
+argument set to
+.Ar interface .
+If a vlan interface's name is a number,
+then that number is used as the vlan tag and the new vlan interface is
+named
+.Ar interface . Ns Ar tag .
+Otherwise,
+the vlan tag must be specified via a
+.Va vlan
+parameter in the
+.Va create_args_ Ns Aq Ar interface
+variable.
+.Pp
+To create a vlan device named
+.Li em0.101
+on
+.Li em0
+with the vlan tag 101:
+.Bd -literal
+vlans_em0="101"
+.Ed
+.Pp
+To create a vlan device named
+.Li myvlan
+on
+.Li em0
+with the vlan tag 102:
+.Bd -literal
+vlans_em0="myvlan"
+create_args_myvlan="vlan 102"
+.Ed
+.Pp
 If the
 .Va ifconfig_ Ns Aq Ar interface
 contains the keyword
@@ -1205,7 +1244,7 @@ This is intended to replace the no longe
 .Va pccard_ifconfig
 variable.
 .Pp
-It is also possible to rename interface by doing:
+It is also possible to rename an interface by doing:
 .Bd -literal
 ifconfig_ed0_name="net0"
 ifconfig_net0="inet 192.0.2.1 netmask 0xffffff00"
@@ -1242,6 +1281,12 @@ Now this works only for IPv6 link local 
 .It Va cloned_interfaces
 .Pq Vt str
 Set to the list of clonable network interfaces to create on this host.
+Further cloning arguments may be passed to the
+.Xr ifconfig 8
+.Cm create
+command for each interface by setting the
+.Va create_args_ Ns Aq Ar interface
+variable.
 Entries in
 .Va cloned_interfaces
 are automatically appended to


More information about the svn-src-stable-7 mailing list