From alexs@snark.rinet.ru  Fri Jan 27 17:53:44 2006
Return-Path: <alexs@snark.rinet.ru>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 670A416A420
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 27 Jan 2006 17:53:44 +0000 (GMT)
	(envelope-from alexs@snark.rinet.ru)
Received: from snark.rinet.ru (snark.rinet.ru [195.54.192.73])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 2A59643D6B
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 27 Jan 2006 17:53:42 +0000 (GMT)
	(envelope-from alexs@snark.rinet.ru)
Received: from snark.rinet.ru (alexs@localhost.rinet.ru [127.0.0.1])
	by snark.rinet.ru (8.13.4/8.13.4) with ESMTP id k0RHsY9S063996;
	Fri, 27 Jan 2006 20:54:34 +0300 (MSK)
	(envelope-from alexs@snark.rinet.ru)
Received: (from alexs@localhost)
	by snark.rinet.ru (8.13.4/8.13.4/Submit) id k0RHsYbI063995;
	Fri, 27 Jan 2006 20:54:34 +0300 (MSK)
	(envelope-from alexs)
Message-Id: <200601271754.k0RHsYbI063995@snark.rinet.ru>
Date: Fri, 27 Jan 2006 20:54:34 +0300 (MSK)
From: Alex Semenyaka <alexs@snark.rinet.ru>
Reply-To: Alex Semenyaka <alexs@snark.rinet.ru>
To: FreeBSD-gnats-submit@freebsd.org
Cc: glebius@cell.sick.ru
Subject: /etc/nework.subr cannot handle interfaces like bge0.13 properly
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         92433
>Category:       conf
>Synopsis:       [patch] /etc/network.subr cannot handle interfaces like bge0.13 properly
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    brooks
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Jan 27 18:00:15 GMT 2006
>Closed-Date:    Tue Aug 22 19:43:07 GMT 2006
>Last-Modified:  Tue Aug 22 19:43:07 GMT 2006
>Originator:     Alex Semenyaka
>Release:        FreeBSD 6.0-STABLE amd64
>Organization:
ZAO "SonicDuo"
>Environment:
FreeBSD packets-sr2.sonicduo.com 6.0-RELEASE FreeBSD 6.0-RELEASE #0: Thu Nov  3 09:36:13 UTC 2005     root@x64.samsco.home:/usr/obj/usr/src/sys/GENERIC  i386

>Description:

	The interface name like "bge0.13" listed as the cloned interfaces in the /etc/rc.conf cannot be
	handled by /etc/network.subr properly. Thus interfaces with those names cannot be configured.

>How-To-Repeat:
	1. Add the interface with the dot in the name to the list of cloned interfaces.
	2. Add configuration for it.
	3. Run
		/etc/rc.d/netif start
>Fix:

	1) Add procedure to trasform interface names with dots with the names without dot.
	In this way they will be used in the configuration strings of /etc/rc.conf. Example:
	from "bge0.13" will obtain "bge0_13". The corresponding config-string in /etc/rc.conf
	will be

ifconfig_bge0_13="inet 10.0.13.1 netmask 255.255.255.0"

	2) classify procedures from network.subr into the three groups. First group needs
	real name of the interface only, so we can feed it as is without changes. Second one
	needs only modifyed name to work with the configuration. Third group needs both.
	3) In the procedures belonging to the third group we will transform the real interface
	name to the name without dot to use inside and pass as the argument to the procedures
	from the second group.

Here is the patch for FreeBSD 6.0-RELEASE. If this change is acceptable I'll prepare the patch
for CURRENT.


--- network.subr.old    Fri Jan 27 20:08:21 2006
+++ network.subr        Fri Jan 27 20:28:55 2006
@@ -30,6 +30,21 @@
 # Requires that rc.conf be loaded first.
 #

+# cfg_ifname if
+#      Evaluate the name for the dotted VLAN interface which should
+#      be used inrc.conf (for example, makes "bge0_1" from "bge0.1")
+#      and print it out to the stdout.
+cfg_ifname()
+{
+       _devpart=${1%.*}
+       _vlanpart=${1#*.}
+       if [ -n "${_vlanpart}" ]; then
+               echo "${_devpart}_${_vlanpart}"
+       else
+               echo $1
+       fi
+}
+
 # ifconfig_up if
 #      Evaluate ifconfig(8) arguments for interface $if and
 #      run ifconfig(8) with those arguments. It returns 0 if
@@ -41,14 +56,16 @@
 {
        _cfg=1

-       ifconfig_args=`ifconfig_getargs $1`
+       _cfgif="`cfg_ifname "$1"`"
+
+       ifconfig_args=`ifconfig_getargs "${_cfgif}"`
        if [ -n "${ifconfig_args}" ]; then
                ifconfig $1 up
                eval "ifconfig $1 ${ifconfig_args}"
                _cfg=0
        fi

-       if wpaif $1; then
+       if wpaif "${_cfgif}"; then
                if [ $_cfg -ne 0 ] ; then
                        ifconfig $1 up
                fi
@@ -56,7 +73,7 @@
                _cfg=0          # XXX: not sure this should count
        fi

-       if dhcpif $1; then
+       if dhcpif "${_cfgif}"; then
                if [ $_cfg -ne 0 ] ; then
                        ifconfig $1 up
                fi
@@ -78,6 +95,8 @@
        _ifs="^"
        _cfg=1

+       _cfgif="`cfg_ifname "$1"`"
+
        inetList="`ifconfig $1 | grep 'inet ' | tr "\n" "$_ifs"`"

        oldifs="$IFS"
@@ -95,12 +114,12 @@
        done
        IFS="$oldifs"

-       if wpaif $1; then
+       if wpaif "${_cfgif}"; then
                /etc/rc.d/wpa_supplicant stop $1
                _cfg=0
        fi

-       if dhcpif $1; then
+       if dhcpif "${_cfgif}"; then
                /etc/rc.d/dhclient stop $1
                _cfg=0
        fi
@@ -108,7 +127,7 @@
        return $_cfg
 }

-# _ifconfig_getargs if
+# _ifconfig_getargs cfgif
 #      Echos the arguments for the supplied interface to stdout.
 #      returns 1 if empty.  In general, ifconfig_getargs should be used
 #      outside this file.
@@ -124,7 +143,7 @@
        echo "$_args"
 }

-# ifconfig_getargs if
+# ifconfig_getargs cfgif
 #      Takes the result from _ifconfig_getargs and removes pseudo
 #      args such as DHCP and WPA.
 ifconfig_getargs()
@@ -152,7 +171,7 @@
        echo $_args
 }

-# autoif
+# autoif cfgif
 #      Returns 0 if the interface should be automaticly configured at
 #      boot time and 1 otherwise.
 autoif()
@@ -168,7 +187,7 @@
        return 0
 }

-# dhcpif if
+# dhcpif cfgif
 #      Returns 0 if the interface is a DHCP interface and 1 otherwise.
 dhcpif()
 {
@@ -183,7 +202,7 @@
        return 1
 }

-# wpaif if
+# wpaif cfgif
 #      Returns 0 if the interface is a WPA interface and 1 otherwise.
 wpaif()
 {
@@ -207,8 +226,11 @@
 {
        _ret=1
        alias=0
+
+       _cfgif="`cfg_ifname "$1"`"
+
        while : ; do
-               eval ifconfig_args=\$ifconfig_$1_alias${alias}
+               eval ifconfig_args=\$ifconfig_${_cfgif}_alias${alias}
                if [ -n "${ifconfig_args}" ]; then
                        ifconfig $1 ${ifconfig_args} alias
                        alias=$((${alias} + 1))
@@ -229,8 +251,11 @@
 {
        _ret=1
        alias=0
+
+       _cfgif="`cfg_ifname "$1"`"
+
        while : ; do
-               eval ifconfig_args=\$ifconfig_$1_alias${alias}
+               eval ifconfig_args=\$ifconfig_${_cfgif}_alias${alias}
                if [ -n "${ifconfig_args}" ]; then
                        ifconfig $1 ${ifconfig_args} -alias
                        alias=$((${alias} + 1))
@@ -380,7 +405,8 @@
        _ifn_list="`ifconfig -l`"
        [ -z "$_ifn_list" ] && return 0
        for _if in ${_ifn_list} ; do
-               eval _ifname=\$ifconfig_${_if}_name
+               _cfgif="`cfg_ifname "$1"`"
+               eval _ifname=\$ifconfig_${_cfgif}_name
                if [ ! -z "$_ifname" ]; then
                        ifconfig $_if name $_ifname
                fi
@@ -438,11 +464,12 @@
        _aprefix=
        _bprefix=
        for _if in ${_tmplist} ; do
-               if dhcpif $_if; then
-                       _dhcplist="${_dhcplist}${_aprefix}${_if}"
+               _cfgif="`cfg_ifname "$1"`"
+               if dhcpif $_cfgif; then
+                       _dhcplist="${_dhcplist}${_aprefix}${_cfgif}"
                        [ -z "$_aprefix" ] && _aprefix=' '
-               elif [ -n "`_ifconfig_getargs $if`" ]; then
-                       _nodhcplist="${_nodhcplist}${_bprefix}${_if}"
+               elif [ -n "`_ifconfig_getargs $cfgif`" ]; then
+                       _nodhcplist="${_nodhcplist}${_bprefix}${_cfgif}"
                        [ -z "$_bprefix" ] && _bprefix=' '
                fi
        done
@@ -560,8 +587,9 @@

        for i in $interfaces; do
                alias=0
+               _cfgif="`cfg_ifname "$i"`"
                while : ; do
-                       eval ipv6_ifconfig=\$ipv6_ifconfig_${i}_alias${alias}
+                       eval ipv6_ifconfig=\$ipv6_ifconfig_${_cfgif}_alias${alias}
                        if [ -z "${ipv6_ifconfig}" ]; then
                                break;
                        fi

>Release-Note:
>Audit-Trail:

From: Andrew Thompson <thompsa@freebsd.org>
To: bug-followup@freebsd.org
Cc:  
Subject: Re: conf/92433: [patch] /etc/network.subr cannot handle interfaces like bge0.13 properly
Date: Sat, 28 Jan 2006 08:33:21 +1300

 This is related to conf/88974, please close both when patched.
 
State-Changed-From-To: open->patched 
State-Changed-By: brooks 
State-Changed-When: Thu Apr 13 06:52:29 UTC 2006 
State-Changed-Why:  
Committed a more general patch to HEAD. 


Responsible-Changed-From-To: freebsd-bugs->brooks 
Responsible-Changed-By: brooks 
Responsible-Changed-When: Thu Apr 13 06:52:29 UTC 2006 
Responsible-Changed-Why:  
Committed a more general patch to HEAD. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=92433 
State-Changed-From-To: patched->closed 
State-Changed-By: brooks 
State-Changed-When: Tue Aug 22 19:42:15 UTC 2006 
State-Changed-Why:  
Fix merged to RELENG_6. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=92433 
>Unformatted:
