From nobody@FreeBSD.org  Thu Feb 17 18:15:59 2011
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 602D5106564A
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 17 Feb 2011 18:15:59 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 330478FC1A
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 17 Feb 2011 18:15:59 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id p1HIFxdq064868
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 17 Feb 2011 18:15:59 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id p1HIFwWO064867;
	Thu, 17 Feb 2011 18:15:58 GMT
	(envelope-from nobody)
Message-Id: <201102171815.p1HIFwWO064867@red.freebsd.org>
Date: Thu, 17 Feb 2011 18:15:58 GMT
From: Nikolay Denev <ndenev@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: ng_ether fails to name nodes when the associated interface contains dots or colons
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         154850
>Category:       kern
>Synopsis:       [netgraph] [patch] ng_ether fails to name nodes when the associated interface contains dots or colons
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-net
>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:  Sat Feb  2 12:00:00 UTC 2013
>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:
Responsible-Changed-From-To: freebsd-bugs->freebsd-net 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Fri Feb 18 00:15:50 UTC 2011 
Responsible-Changed-Why:  
Over to maintainer(s). 

http://www.freebsd.org/cgi/query-pr.cgi?pr=154850 

From: st41ker <st41ker@st41ker.net>
To: bug-followup@FreeBSD.org, ndenev@gmail.com
Cc:  
Subject: Re: kern/154850: [netgraph] [patch] ng_ether fails to name nodes
 when the associated interface contains dots or colons
Date: Mon, 09 Apr 2012 17:07:39 +0300

 Hello,
 
 Mentioned issue still exists in the FreeBSD-9-STABLE branch (it seems 
 like every branch is affected).
 
 According to new rc subsystem (check the /etc/network.subr) where vlans 
 are created - they're all using dots in ifnames.
 Also, function get_if_var() already has mentioned code for the replacing 
 ". - / +" to "_".
 So mentioned patch will not break anything, even users ngctl scripts, 
 since that users just can not use dots there by design.
 
 Thank you.
 
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/154850: commit references a PR
Date: Sat,  2 Feb 2013 11:54:12 +0000 (UTC)

 Author: avg
 Date: Sat Feb  2 11:54:00 2013
 New Revision: 246245
 URL: http://svnweb.freebsd.org/changeset/base/246245
 
 Log:
   ng_ether: track interface renaming
   
   Also sanitize interface names that can potentially contain characters
   that are prohibited in netgraph names.
   
   PR:		kern/154850 (sanitizing of names)
   Discussed with:	eri, melifaro
   Submitted by:	Nikolay Denev <ndenev@gmail.com> (sanitizing code)
   Reviewed by:	eri, glebius
   MFC after:	17 days
 
 Modified:
   head/sys/netgraph/ng_ether.c
 
 Modified: head/sys/netgraph/ng_ether.c
 ==============================================================================
 --- head/sys/netgraph/ng_ether.c	Sat Feb  2 11:41:05 2013	(r246244)
 +++ head/sys/netgraph/ng_ether.c	Sat Feb  2 11:54:00 2013	(r246245)
 @@ -117,6 +117,8 @@ static ng_rcvdata_t	ng_ether_rcvdata;
  static ng_disconnect_t	ng_ether_disconnect;
  static int		ng_ether_mod_event(module_t mod, int event, void *data);
  
 +static eventhandler_tag	ng_ether_ifnet_arrival_cookie;
 +
  /* List of commands and how to convert arguments to/from ASCII */
  static const struct ng_cmdlist ng_ether_cmdlist[] = {
  	{
 @@ -214,6 +216,24 @@ static struct ng_type ng_ether_typestruc
  NETGRAPH_INIT(ether, &ng_ether_typestruct);
  
  /******************************************************************
 +		    UTILITY FUNCTIONS
 +******************************************************************/
 +static void
 +ng_ether_sanitize_ifname(const char *ifname, char *name)
 +{
 +	int i;
 +
 +	for (i = 0; i < IFNAMSIZ; i++) {
 +		if (ifname[i] == '.' || ifname[i] == ':')
 +			name[i] = '_';
 +		else
 +			name[i] = ifname[i];
 +		if (name[i] == '\0')
 +			break;
 +	}
 +}
 +
 +/******************************************************************
  		    ETHERNET FUNCTION HOOKS
  ******************************************************************/
  
 @@ -282,6 +302,7 @@ ng_ether_output(struct ifnet *ifp, struc
  static void
  ng_ether_attach(struct ifnet *ifp)
  {
 +	char name[IFNAMSIZ];
  	priv_p priv;
  	node_p node;
  
 @@ -319,10 +340,9 @@ ng_ether_attach(struct ifnet *ifp)
  	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) {
 -		log(LOG_WARNING, "%s: can't name node %s\n",
 -		    __func__, ifp->if_xname);
 -	}
 +	ng_ether_sanitize_ifname(ifp->if_xname, name);
 +	if (ng_name_node(node, name) != 0)
 +		log(LOG_WARNING, "%s: can't name node %s\n", __func__, name);
  }
  
  /*
 @@ -378,6 +398,32 @@ ng_ether_link_state(struct ifnet *ifp, i
  	}
  }
  
 +/*
 + * Interface arrival notification handler.
 + * The notification is produced in two cases:
 + *  o a new interface arrives
 + *  o an existing interface got renamed
 + * Currently the first case is handled by ng_ether_attach via special
 + * hook ng_ether_attach_p.
 + */
 +static void
 +ng_ether_ifnet_arrival_event(void *arg __unused, struct ifnet *ifp)
 +{
 +	char name[IFNAMSIZ];
 +	node_p node = IFP2NG(ifp);
 +
 +	/*
 +	 * Just return if it's a new interface without an ng_ether companion.
 +	 */
 +	if (node == NULL)
 +		return;
 +
 +	/* Try to give the node the same name as the new interface name */
 +	ng_ether_sanitize_ifname(ifp->if_xname, name);
 +	if (ng_name_node(node, name) != 0)
 +		log(LOG_WARNING, "%s: can't re-name node %s\n", __func__, name);
 +}
 +
  /******************************************************************
  		    NETGRAPH NODE METHODS
  ******************************************************************/
 @@ -771,6 +817,9 @@ ng_ether_mod_event(module_t mod, int eve
  		ng_ether_input_orphan_p = ng_ether_input_orphan;
  		ng_ether_link_state_p = ng_ether_link_state;
  
 +		ng_ether_ifnet_arrival_cookie =
 +		    EVENTHANDLER_REGISTER(ifnet_arrival_event,
 +		    ng_ether_ifnet_arrival_event, NULL, EVENTHANDLER_PRI_ANY);
  		break;
  
  	case MOD_UNLOAD:
 @@ -783,6 +832,9 @@ ng_ether_mod_event(module_t mod, int eve
  		 * is MOD_UNLOAD, so there's no need to detach any nodes.
  		 */
  
 +		EVENTHANDLER_DEREGISTER(ifnet_arrival_event,
 +		    ng_ether_ifnet_arrival_cookie);
 +
  		/* Unregister function hooks */
  		ng_ether_attach_p = NULL;
  		ng_ether_detach_p = NULL;
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
>Unformatted:
