Date: Fri, 27 Aug 2010 13:17:17 +0400 From: pluknet <pluknet@gmail.com> To: Doug Barton <dougb@freebsd.org> Cc: FreeBSD Current <freebsd-current@freebsd.org>, freebsd-rc@freebsd.org Subject: Re: [RFC] ifconfig description support in rc.d Message-ID: <AANLkTintgji3vzrb8XuUQHWp%2B7YDvHtd7ynP0MmV0oZr@mail.gmail.com> In-Reply-To: <4C76CA06.5010001@FreeBSD.org> References: <AANLkTinfOSQGnk0%2BPK6iM0=v5CZn2vcmJZbA8TvgGbfr@mail.gmail.com> <4C76CA06.5010001@FreeBSD.org>
next in thread | previous in thread | raw e-mail | index | archive | help
[-- Attachment #1 --]
On 27 August 2010 00:09, Doug Barton <dougb@freebsd.org> wrote:
> On 08/26/2010 12:53 PM, pluknet wrote:
>>
>> [cc'ing current@ as rc@ looks too quite]
>>
>> Hi.
>>
>> Since ifconfig has grown to label interfaces with
>> ifconfig $ifname description "foobar", what about
>> to give it more life and store i/face descriptions
>> semi-permanently, so they will survive between reboots?
>>
>> This patch adds a functionality to rc.d to label
>> interfaces at boot time.
>>
>> Comments are welcome.
>
> This seems like a good addition, thanks. Please also write a patch for
> rc.conf.5 to describe this new functionality and I'll be happy to commit it.
Xin Li helped me with updating rc.conf.5 (thanks!).
It's included in attached patch.
> One note below.
>
>
>> --- etc/network.subr (revision 211280)
>> +++ etc/network.subr (working copy)
>> @@ -1187,6 +1187,24 @@
>> return 0
>> }
>>
>> +# ifnet_descr
>> +# Add description to all requested interfaces.
>> +#
>> +ifnet_descr()
>> +{
>> + local _if _ifdescr
>> +
>> + # ifconfig_IF_descr
>> + for _if in `ifconfig -l`; do
>> + _ifdescr="`get_if_var $_if ifconfig_IF_descr`"
>> + if [ ! -z "$_ifdescr" ]; then
>
> This is probably better as [ -n "$_ifdescr" ]
>
This was blindly copy&pasted after ifnet_rename().
So, it makes sense probably to change test expression there as well.
[see ifnet_rename() proposed change below inline]
This change to ifnet_rename() is not included in attached patch
to not complicate things unnecessarily for now.
Index: etc/network.subr
===================================================================
--- etc/network.subr (revision 211280)
+++ etc/network.subr (working copy)
@@ -1179,7 +1179,7 @@
# ifconfig_IF_name
for _if in `ifconfig -l`; do
_ifname=`get_if_var $_if ifconfig_IF_name`
- if [ ! -z "$_ifname" ]; then
+ if [ -n "$_ifname" ]; then
ifconfig $_if name $_ifname
fi
done
--
wbr,
pluknet
[-- Attachment #2 --]
Index: etc/rc.d/netif
===================================================================
--- etc/rc.d/netif (revision 211280)
+++ etc/rc.d/netif (working copy)
@@ -75,6 +75,9 @@
# Rename interfaces.
ifnet_rename
+
+ # Give description to interfaces.
+ ifnet_descr
fi
# Configure the interface(s).
Index: etc/network.subr
===================================================================
--- etc/network.subr (revision 211280)
+++ etc/network.subr (working copy)
@@ -1187,6 +1187,24 @@
return 0
}
+# ifnet_descr
+# Add description to all requested interfaces.
+#
+ifnet_descr()
+{
+ local _if _ifdescr
+
+ # ifconfig_IF_descr
+ for _if in `ifconfig -l`; do
+ _ifdescr="`get_if_var $_if ifconfig_IF_descr`"
+ if [ -n "$_ifdescr" ]; then
+ ifconfig $_if descr "$_ifdescr"
+ fi
+ done
+
+ 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 211280)
+++ etc/defaults/rc.conf (working copy)
@@ -215,6 +215,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_arg_vlan0="vlan 102" # vlan tag for vlan0 device
#wlans_ath0="wlan0" # wlan(4) interfaces for ath0 device
Index: share/man/man5/rc.conf.5
===================================================================
--- share/man/man5/rc.conf.5 (revision 209664)
+++ share/man/man5/rc.conf.5 (working copy)
@@ -1128,6 +1128,19 @@
variables.
.Pp
If a
+.Va ifconfig_ Ns Ao Ar interface Ac Ns Va _descr
+variable is set, the interface would be assigned the description
+specified by the variable.
+.Pp
+To assign an description of
+.Dq Uplink to Gigabit Switch 1
+on the interface named
+.Li em0 :
+.Bd -literal
+ifconfig_em0_descr="Uplink to Gigabit Switch 1"
+.Ed
+.Pp
+If a
.Va vlans_ Ns Aq Ar interface
variable is set,
a
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?AANLkTintgji3vzrb8XuUQHWp%2B7YDvHtd7ynP0MmV0oZr>
