svn commit: r247885 - stable/8/sys/netgraph
Andriy Gapon
avg at FreeBSD.org
Wed Mar 6 11:00:48 UTC 2013
Author: avg
Date: Wed Mar 6 11:00:47 2013
New Revision: 247885
URL: http://svnweb.freebsd.org/changeset/base/247885
Log:
MFC r246245,246324: ng_ether: track interface renaming
Modified:
stable/8/sys/netgraph/ng_ether.c
Directory Properties:
stable/8/sys/ (props changed)
stable/8/sys/netgraph/ (props changed)
Modified: stable/8/sys/netgraph/ng_ether.c
==============================================================================
--- stable/8/sys/netgraph/ng_ether.c Wed Mar 6 10:52:01 2013 (r247884)
+++ stable/8/sys/netgraph/ng_ether.c Wed Mar 6 11:00:47 2013 (r247885)
@@ -115,6 +115,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[] = {
{
@@ -212,6 +214,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
******************************************************************/
@@ -284,6 +304,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;
@@ -321,10 +342,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);
}
/*
@@ -380,6 +400,38 @@ 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;
+
+ /* Only ethernet interfaces are of interest. */
+ if (ifp->if_type != IFT_ETHER
+ && ifp->if_type != IFT_L2VLAN)
+ return;
+
+ /*
+ * Just return if it's a new interface without an ng_ether companion.
+ */
+ node = IFP2NG(ifp);
+ 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
******************************************************************/
@@ -779,6 +831,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:
@@ -791,6 +846,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;
More information about the svn-src-stable
mailing list