Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 30 Apr 2008 14:01:21 -0400
From:      "Niki Denev" <nike_d@cytexbg.com>
To:        freebsd-net@freebsd.org
Subject:   [PATCH] autoload if_vlan.ko on vlan creation
Message-ID:  <2e77fc10804301101i57c73a32n8273f7a8a96b7e6f@mail.gmail.com>

next in thread | raw e-mail | index | archive | help
------=_Part_2525_18964599.1209578481602
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Hi,

I've noticed that autoloading of if_vlan.ko on vlan creation does not work
in the case when the vlans are specified with the interface name. i.e. :
fxp0.5
And the problem is that ifmaybeload() in ifconfig.c expects that all
interfaces
are in the format : if_${driver}${number}, which is not the case for vlans
created
in the above mentioned way (which is much more easier and intuitive IMHO)
This patch fixes this for me, and probably others may find it useful.

P.S.: Because of the assumption for the interface name that ifmaybeload()
does,
this patch looks more like a hack and probably a better way could be found
for handling this case.
P.S2: If "ifconfig fxp0." is typed this will autoload if_vlan.ko because we
have a dot after the first number
in the interface name (there is no check if there are other digits after the
dot). I'm not sure
if a more strict check is needed though because I can't imagine this can
cause any real problems.

--- ifconfig.c.orig    2008-04-30 12:29:25.000000000 -0400
+++ ifconfig.c    2008-04-30 12:44:50.000000000 -0400
@@ -935,18 +935,21 @@
     if (noload)
         return;

-    /* trim the interface number off the end */
+    /* locate interface number beginning */
     strlcpy(ifname, name, sizeof(ifname));
     for (dp = ifname; *dp != 0; dp++)
-        if (isdigit(*dp)) {
-            *dp = 0;
+        if (isdigit(*dp))
             break;
-        }

-    /* turn interface and unit into module name */
-    strcpy(ifkind, "if_");
-    strlcpy(ifkind + MOD_PREFIX_LEN, ifname,
-        sizeof(ifkind) - MOD_PREFIX_LEN);
+    /* check the special case for vlan interfaces */
+    if (strchr(dp, '.')) {
+        strcpy(ifkind, "if_vlan");
+    } else {
+        /* turn interface and unit into module name */
+        strcpy(ifkind, "if_");
+        strlcpy(ifkind + MOD_PREFIX_LEN, ifname,
+            sizeof(ifkind) - MOD_PREFIX_LEN);
+    }

     /* scan files in kernel */
     mstat.version = sizeof(struct module_stat);

------=_Part_2525_18964599.1209578481602
Content-Type: text/x-patch; name=ifconfig-vlan_create.patch
Content-Transfer-Encoding: base64
X-Attachment-Id: f_ffo5m1pu0
Content-Disposition: attachment; filename=ifconfig-vlan_create.patch

LS0tIGlmY29uZmlnLmMub3JpZwkyMDA4LTA0LTMwIDEyOjI5OjI1LjAwMDAwMDAwMCAtMDQwMAor
KysgaWZjb25maWcuYwkyMDA4LTA0LTMwIDEyOjQ0OjUwLjAwMDAwMDAwMCAtMDQwMApAQCAtOTM1
LDE4ICs5MzUsMjEgQEAKIAlpZiAobm9sb2FkKQogCQlyZXR1cm47CiAKLQkvKiB0cmltIHRoZSBp
bnRlcmZhY2UgbnVtYmVyIG9mZiB0aGUgZW5kICovCisJLyogbG9jYXRlIGludGVyZmFjZSBudW1i
ZXIgYmVnaW5uaW5nICovCiAJc3RybGNweShpZm5hbWUsIG5hbWUsIHNpemVvZihpZm5hbWUpKTsK
IAlmb3IgKGRwID0gaWZuYW1lOyAqZHAgIT0gMDsgZHArKykKLQkJaWYgKGlzZGlnaXQoKmRwKSkg
ewotCQkJKmRwID0gMDsKKwkJaWYgKGlzZGlnaXQoKmRwKSkKIAkJCWJyZWFrOwotCQl9CiAKLQkv
KiB0dXJuIGludGVyZmFjZSBhbmQgdW5pdCBpbnRvIG1vZHVsZSBuYW1lICovCi0Jc3RyY3B5KGlm
a2luZCwgImlmXyIpOwotCXN0cmxjcHkoaWZraW5kICsgTU9EX1BSRUZJWF9MRU4sIGlmbmFtZSwK
LQkgICAgc2l6ZW9mKGlma2luZCkgLSBNT0RfUFJFRklYX0xFTik7CisJLyogY2hlY2sgdGhlIHNw
ZWNpYWwgY2FzZSBmb3IgdmxhbiBpbnRlcmZhY2VzICovCisJaWYgKHN0cmNocihkcCwgJy4nKSkg
eworCQlzdHJjcHkoaWZraW5kLCAiaWZfdmxhbiIpOworCX0gZWxzZSB7CisJCS8qIHR1cm4gaW50
ZXJmYWNlIGFuZCB1bml0IGludG8gbW9kdWxlIG5hbWUgKi8KKwkJc3RyY3B5KGlma2luZCwgImlm
XyIpOworCQlzdHJsY3B5KGlma2luZCArIE1PRF9QUkVGSVhfTEVOLCBpZm5hbWUsCisJCSAgICBz
aXplb2YoaWZraW5kKSAtIE1PRF9QUkVGSVhfTEVOKTsKKwl9CiAKIAkvKiBzY2FuIGZpbGVzIGlu
IGtlcm5lbCAqLwogCW1zdGF0LnZlcnNpb24gPSBzaXplb2Yoc3RydWN0IG1vZHVsZV9zdGF0KTsK

------=_Part_2525_18964599.1209578481602--



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