kern/154850: ng_ether fails to name nodes when the associated interface contains dots or colons

Nikolay Denev ndenev at gmail.com
Thu Feb 17 18:20:10 UTC 2011


>Number:         154850
>Category:       kern
>Synopsis:       ng_ether fails to name nodes when the associated interface contains dots or colons
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Feb 17 18:20:10 UTC 2011
>Closed-Date:
>Last-Modified:
>Originator:     Nikolay Denev
>Release:        FreeBSD-8-STABLE
>Organization:
>Environment:
>Description:
As discussed here : http://lists.freebsd.org/pipermail/freebsd-net/2011-February/027986.html
ng_ether(4) fails to name newly created nodes when their associated interface has netgraph reserved
characters in the name (dots and colons).
While colons are uncommon in interface names, dots are used for vlan interfaces.

>How-To-Repeat:
Assuming that the physical interface is em(4) :
# ifconfig em0.13 create
# kldload ng_ether
# ngctl -l

And the newly created ether node for the em0.13 vlan interface will be <unnamed>.

>Fix:
The attached patch still names the ether nodes with the same name as their associated interface,
but replaces all occurences of dots or colons in the string so ng_name_node() would not fail.

Patch attached with submission follows:

--- sys/netgraph/ng_ether.c.orig	2011-02-15 19:29:09.706568297 +0200
+++ sys/netgraph/ng_ether.c	2011-02-16 15:11:03.138114973 +0200
@@ -285,6 +285,8 @@
 {
 	priv_p priv;
 	node_p node;
+	int i;
+	char name[IFNAMSIZ];
 
 	/*
 	 * Do not create / attach an ether node to this ifnet if
@@ -319,10 +321,22 @@
 	IFP2NG(ifp) = node;
 	priv->hwassist = ifp->if_hwassist;
 
-	/* Try to give the node the same name as the interface */
-	if (ng_name_node(node, ifp->if_xname) != 0) {
+	/*
+	 * Try to give the node the same name as the interface
+	 * replacing netgraph reserved characters (dot and colon)
+	 */
+	for (i = 0; i < IFNAMSIZ; i++) {
+		if (ifp->if_xname[i] == '.' || ifp->if_xname[i] == ':') {
+			name[i] = '_';
+		} else {
+			name[i] = ifp->if_xname[i];
+		}
+		if (ifp->if_xname[i] == '\0')
+			break;
+	}
+	if (ng_name_node(node, name) != 0) {
 		log(LOG_WARNING, "%s: can't name node %s\n",
-		    __func__, ifp->if_xname);
+		    __func__, name);
 	}
 }
 
--- share/man/man4/ng_ether.4.orig	2011-02-16 15:16:11.775255282 +0200
+++ share/man/man4/ng_ether.4	2011-02-16 15:18:53.114257799 +0200
@@ -54,7 +54,8 @@
 module is loaded into the kernel, a node is automatically created
 for each Ethernet interface in the system.
 Each node will attempt to name itself with the same name
-as the associated interface.
+as the associated interface, substituting netgraph reserved
+characters in the name with underscores.
 .Pp
 Three hooks are supported:
 .Va lower , upper ,


>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-bugs mailing list