Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 19 Nov 2010 13:55:42 +0300
From:      Sergey Kandaurov <pluknet@gmail.com>
To:        Hiroki Sato <hrs@freebsd.org>
Cc:        dougb@freebsd.org, freebsd-rc@freebsd.org, freebsd-current@freebsd.org
Subject:   Re: [RFC] ifconfig description support in rc.d
Message-ID:  <AANLkTimOWhC1PHSu0SaUavTAPrhyNESdOWgAEEbxehBF@mail.gmail.com>
In-Reply-To: <20101011.192914.82309657.hrs@allbsd.org>
References:  <AANLkTinfOSQGnk0%2BPK6iM0=v5CZn2vcmJZbA8TvgGbfr@mail.gmail.com> <4C76CA06.5010001@FreeBSD.org> <AANLkTintgji3vzrb8XuUQHWp%2B7YDvHtd7ynP0MmV0oZr@mail.gmail.com> <20101011.192914.82309657.hrs@allbsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help

[-- Attachment #1 --]
On 11 October 2010 14:29, Hiroki Sato <hrs@freebsd.org> wrote:
> Hi,
>
> pluknet <pluknet@gmail.com> wrote
>  in <AANLkTintgji3vzrb8XuUQHWp+7YDvHtd7ynP0MmV0oZr@mail.gmail.com>:
>
> pl> On 27 August 2010 00:09, Doug Barton <dougb@freebsd.org> wrote:
> pl> > On 08/26/2010 12:53 PM, pluknet wrote:
> pl> >>
> pl> >> [cc'ing current@ as rc@ looks too quite]
> pl> >>
> pl> >> Hi.
> pl> >>
> pl> >> Since ifconfig has grown to label interfaces with
> pl> >> ifconfig $ifname description "foobar", what about
> pl> >> to give it more life and store i/face descriptions
> pl> >> semi-permanently, so they will survive between reboots?
> pl> >>
> pl> >> This patch adds a functionality to rc.d to label
> pl> >> interfaces at boot time.
> pl> >>
> pl> >> Comments are welcome.
> pl> >
> pl> > This seems like a good addition, thanks. Please also write a patch for
> pl> > rc.conf.5 to describe this new functionality and I'll be happy to commit it.
> pl>
> pl> Xin Li helped me with updating rc.conf.5 (thanks!).
> pl> It's included in attached patch.
> (snip)
> pl> >> +       # ifconfig_IF_descr
> pl> >> +       for _if in `ifconfig -l`; do
>
>  I think using "ifconfig -l" here is not a good idea.  Setting a
>  description for each interface in a function invoked by ifn_start()
>  would be better.
>
>  This is beacuse the netif script can be run not only at boottime but
>  also via devd or by hand for a specific interface.  So, if the
>  ifnet_descr is there, "/etc/rc.d/netif start IF" does not make it
>  run.  Since the description is a per-interface property,
>  "/etc/rc.d/netif start IF" should set one, and "/etc/rc.d/netif stop
>  IF" should clear one, IMHO.
>
>  Also, "ifconfig -l" is not compatible with $network_interfaces, so
>  you need to use list_net_interface() for that purpose instead (if you
>  move ifnet_descr() into ifn_start() it is useless, though).
>

Actually, both versions were developed at the same time.
This one follows "netif" approach. Somehow it was rejected
by me for some reasons which I don't remember for now.
That's why I didn't include it to my original message.

Please, see attached.

-- 
wbr,
pluknet

P.S.
Google marks patches as (application/octet-stream). Bad Google.

[-- Attachment #2 --]
Index: etc/network.subr
===================================================================
--- etc/network.subr	(revision 215423)
+++ etc/network.subr	(working copy)
@@ -47,6 +47,7 @@
 	ipv4_up ${ifn} && cfg=0
 	ipv6_up ${ifn} && cfg=0
 	ipx_up ${ifn} && cfg=0
+	ifdescr_up ${ifn} && cfg=0
 	childif_create ${ifn} && cfg=0
 
 	return $cfg
@@ -69,6 +70,7 @@
 	ipv4_down ${ifn} && cfg=0
 	ifconfig_down ${ifn} && cfg=0
 	ifscript_down ${ifn} && cfg=0
+	ifdescr_down ${ifn} && cfg=0
 	childif_destroy ${ifn} && cfg=0
 
 	return $cfg
@@ -1214,6 +1216,35 @@
 	return 0
 }
 
+# ifdescr_up if
+#	Add description to the interface $if.
+#
+ifdescr_up()
+{
+	local _if _ifdescr
+
+	_if=$1
+	_ifdescr="`get_if_var $_if ifconfig_IF_descr`"
+	if [ ! -z "$_ifdescr" ]; then
+		ifconfig $_if descr "$_ifdescr"
+	fi
+
+	return 0
+}
+
+# ifdescr_down if
+#	Remove description from the interface $if.
+#
+ifdescr_down()
+{
+	local _if _ifdescr
+
+	_if=$1
+	ifconfig $_if -descr
+
+	return 0
+}
+
 # list_net_interfaces type
 #	List all network interfaces. The type of interface returned
 #	can be controlled by the type argument. The type
Index: etc/defaults/rc.conf
===================================================================
--- etc/defaults/rc.conf	(revision 215423)
+++ etc/defaults/rc.conf	(working copy)
@@ -214,6 +214,7 @@
 #ifconfig_ed0_ipv6="inet6 2001:db8:1::1 prefixlen 64" # Sample IPv6 addr entry
 #ifconfig_ed0_alias0="inet6 2001:db8:2::1 prefixlen 64" # Sample IPv6 alias
 #ifconfig_fxp0_name="net0"	# Change interface name from fxp0 to net0.
+#ifconfig_fxp0_descr="Uplink to Switch 2"	# Label fxp0 interface
 #vlans_fxp0="101 vlan0"		# vlan(4) interfaces for fxp0 device
 #create_args_vlan0="vlan 102"	# vlan tag for vlan0 device
 #wlans_ath0="wlan0"		# wlan(4) interfaces for ath0 device

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