From nobody@FreeBSD.org  Fri Jun 17 18:05:16 2005
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 71AB516A427
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 17 Jun 2005 18:05:16 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 38A0643D66
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 17 Jun 2005 18:05:09 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.13.1/8.13.1) with ESMTP id j5HI58hR062663
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 17 Jun 2005 18:05:08 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id j5HI58hv062662;
	Fri, 17 Jun 2005 18:05:08 GMT
	(envelope-from nobody)
Message-Id: <200506171805.j5HI58hv062662@www.freebsd.org>
Date: Fri, 17 Jun 2005 18:05:08 GMT
From: Nuno Antunes <nuno.antunes@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [PATCH] ifconfig ifname.tag does not automatically load if_vlan module
X-Send-Pr-Version: www-2.3

>Number:         82367
>Category:       bin
>Synopsis:       [PATCH] ifconfig ifname.tag does not automatically load if_vlan module
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    yar
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Jun 17 18:10:19 GMT 2005
>Closed-Date:    Mon Oct 03 02:50:39 GMT 2005
>Last-Modified:  Mon Oct 03 02:50:39 GMT 2005
>Originator:     Nuno Antunes
>Release:        FreeBSD 6.0-CURRENT i386
>Organization:
>Environment:
System: FreeBSD Zuul 6.0-CURRENT FreeBSD 6.0-CURRENT #6: Wed Jun 8 17:48:16 WEST 2005 sdx@Zuul:/usr/obj/usr/src/sys/ZUUL i386
>Description:
      When creating a vlan interface using the ifname.tag syntax, ifconfig  does not automatically load the required if_vlan module.
>How-To-Repeat:
      Creating a a vlan interface using the ifconfig ifname.tag syntax whithout the if_vlan module loaded or statically compliled to the kernel will trigger this.

        # ifconfig rl0.10
        ifconfig: SIOCIFCREATE: Invalid argument
>Fix:
      I think the following patch solves the problem. (This is my first pr and patch, so please analyse code carefully as it might be wrong).

Please take special attention to the removed comparisson of the interface full name to the module name on the check for already loaded modules. This might break loading interface modules whose name ends in a digit (or others). But if the comparisson is kept it will prevent if_vlan from loading, because for example strncmp("rl0.10,  "rl0", 3) == 0 will make the function return prematurely. Is there a better way to prevent this?

Sorry for sending code via the web send-pr interface but I could not send it otherwise.



--- ifconfig.c.orig     Fri Jun 17 14:47:38 2005
+++ ifconfig.c  Fri Jun 17 16:08:19 2005
@@ -966,12 +966,18 @@
        int fileid, modid;
        char ifkind[35], *cp, *dp;

-       /* turn interface and unit into module name */
-       strcpy(ifkind, "if_");
-       for (cp = name, dp = ifkind + 3;
-           (*cp != 0) && !isdigit(*cp); cp++, dp++)
-               *dp = *cp;
-       *dp = 0;
+       /* is the interface name in the <ifname>.<tag> format? */
+       if (index(name, '.') != NULL) {
+               strcpy(ifkind, "if_vlan");
+       }
+       else {
+               /* turn interface and unit into module name */
+               strncpy(ifkind, "if_", sizeof(ifkind));
+               for (cp = name, dp = ifkind + 3;
+                   (*cp != 0) && !isdigit(*cp); cp++, dp++)
+                       *dp = *cp;
+               *dp = 0;
+       }

        /* scan files in kernel */
        mstat.version = sizeof(struct module_stat);
@@ -988,8 +994,7 @@
                                cp = mstat.name;
                        }
                        /* already loaded? */
-                       if (strncmp(name, cp, strlen(cp)) == 0 ||
-                           strncmp(ifkind, cp, strlen(cp)) == 0)
+                       if (strncmp(ifkind, cp, strlen(cp)) == 0)
                                return;
                }
        }

>Release-Note:
>Audit-Trail:

From: Nuno Antunes <nuno.antunes@gmail.com>
To: bug-followup@freebsd.org
Cc:  
Subject: Re: bin/82367: [PATCH] ifconfig ifname.tag does not automatically load if_vlan module
Date: Fri, 17 Jun 2005 22:46:34 +0100

 Hi,
 
 sorry, the reproduction command is=20
 
     ifconfig rl0.10 create
 
 (the create argument was missing)
 
 Best regards,
 Nuno

From: Brooks Davis <brooks@one-eyed-alien.net>
To: Nuno Antunes <nuno.antunes@gmail.com>
Cc: freebsd-gnats-submit@freebsd.org
Subject: Re: bin/82367: [PATCH] ifconfig ifname.tag does not automatically load if_vlan module
Date: Fri, 17 Jun 2005 16:20:53 -0700

 I think this is a bad idea.  There is nothing that says that all
 interfaces containing '.' characters in their name are vlans.  If you
 want to create vlans this way, load the module first.
 
 -- Brooks
State-Changed-From-To: open->closed 
State-Changed-By: yar 
State-Changed-When: Mon Oct 3 02:40:39 GMT 2005 
State-Changed-Why:  
I'm sorry to close this PR, but indeed the interface name 
handling in FreeBSD is too sophisticated to assume that 
rl0.10 will always stand for vlan 10 on rl0.  As a matter 
of fact, the kernel iterates over all loaded drivers 
to see which one claims the interface name to create, 
and each driver provides a function that determines if 
the name belongs to this driver.  You see, there is no 
simple 1-to-1 correspondence between an interface name 
and the respective driver. 

ifconfig(8) tries to guess interface type from its name, 
but this is really primitive and tricky because it doesn't 
quite correspond to what happens in the kernel. 


Responsible-Changed-From-To: freebsd-bugs->yar 
Responsible-Changed-By: yar 
Responsible-Changed-When: Mon Oct 3 02:40:39 GMT 2005 
Responsible-Changed-Why:  
Just looking after vlan(4) sometimes. 

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