changeset 154:09661cbdfc13

Apply iface name patch, no we can get `ifconfig PPP`
author ray@terran.dlink.ua
date Thu, 30 Jun 2011 12:01:14 +0300
parents 58094c23d93d
children 52ab441b5cbd
files contrib/mpd/src/iface.c contrib/mpd/src/iface.h
diffstat 2 files changed, 40 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/mpd/src/iface.c	Thu Jun 30 12:00:19 2011 +0300
+++ b/contrib/mpd/src/iface.c	Thu Jun 30 12:01:14 2011 +0300
@@ -70,6 +70,7 @@
     SET_ADDRS,
     SET_ROUTE,
     SET_MTU,
+    SET_NAME,
     SET_UP_SCRIPT,
     SET_DOWN_SCRIPT,
     SET_ENABLE,
@@ -142,6 +143,8 @@
 	IfaceSetCommand, NULL, 2, (void *) SET_ROUTE },
     { "mtu {size}",			"Set max allowed interface MTU",
 	IfaceSetCommand, NULL, 2, (void *) SET_MTU },
+    { "name {name}",			"Set interface name",
+	IfaceSetCommand, NULL, 2, (void *) SET_NAME },
     { "up-script [{progname}]",		"Interface up script",
 	IfaceSetCommand, NULL, 2, (void *) SET_UP_SCRIPT },
     { "down-script [{progname}]",	"Interface down script",
@@ -1333,6 +1336,38 @@
       }
       break;
 
+    case SET_NAME:
+      {
+	char *name = av[0];
+	struct ifreq ifr;
+	int s;
+
+	if (strlen(name) >= IF_NAMESIZE)
+	  Error("Interface name too long, >15 characters");
+
+	/* Get socket */
+	if ((s = socket(PF_INET, SOCK_DGRAM, 0)) < 0) {
+	  Error("[%s] IFACE: Can't get socket to set name", ctx->bund->name);
+	}
+
+	/* Set name of interface */
+	memset(&ifr, 0, sizeof(ifr));
+	strlcpy(ifr.ifr_name, iface->ifname, sizeof(ifr.ifr_name));
+	ifr.ifr_data = (caddr_t)name;
+	Log(LG_IFACE2, ("[%s] IFACE: setting %s name to %s",
+	  ctx->bund->name, iface->ifname, name));
+	if (ioctl(s, SIOCSIFNAME, (char *)&ifr) != -1) {
+	  close(s);
+	  /* Save name */
+	  strlcpy(iface->ifname, name, sizeof(iface->ifname));
+	} else {
+	  close(s);
+	  Error("[%s] IFACE: ioctl(%s, %s)", ctx->bund->name,
+	    iface->ifname, "SIOCSIFNAME");
+	}
+      }
+      break;
+
     case SET_UP_SCRIPT:
       switch (ac) {
 	case 0:
@@ -1917,7 +1952,7 @@
 
     /* Connect graph to the iface node. */
     strcpy(cn.ourhook, hook);
-    snprintf(cn.path, sizeof(cn.path), "%s:", b->iface.ifname);
+    snprintf(cn.path, sizeof(cn.path), "%s:", b->iface.ngname);
     strcpy(cn.peerhook, NG_IFACE_HOOK_INET);
     if (NgSendMsg(gLinksCsock, path,
     	    NGM_GENERIC_COOKIE, NGM_CONNECT, &cn, sizeof(cn)) < 0) {
@@ -2006,7 +2041,7 @@
     snprintf(path, sizeof(path), "[%x]:", b->nodeID);
     NgFuncDisconnect(gLinksCsock, b->name, path, NG_PPP_HOOK_INET);
 
-    snprintf(path, sizeof(path), "%s:", b->iface.ifname);
+    snprintf(path, sizeof(path), "%s:", b->iface.ngname);
     NgFuncDisconnect(gLinksCsock, b->name, path, NG_IFACE_HOOK_INET);
 }
 
@@ -2037,7 +2072,7 @@
 
     /* Connect graph to the iface node. */
     strcpy(cn.ourhook, hook);
-    snprintf(cn.path, sizeof(cn.path), "%s:", b->iface.ifname);
+    snprintf(cn.path, sizeof(cn.path), "%s:", b->iface.ngname);
     strcpy(cn.peerhook, NG_IFACE_HOOK_INET6);
     if (NgSendMsg(gLinksCsock, path,
     	    NGM_GENERIC_COOKIE, NGM_CONNECT, &cn, sizeof(cn)) < 0) {
@@ -2069,7 +2104,7 @@
     snprintf(path, sizeof(path), "[%x]:", b->nodeID);
     NgFuncDisconnect(gLinksCsock, b->name, path, NG_PPP_HOOK_IPV6);
 
-    snprintf(path, sizeof(path), "%s:", b->iface.ifname);
+    snprintf(path, sizeof(path), "%s:", b->iface.ngname);
     NgFuncDisconnect(gLinksCsock, b->name, path, NG_IFACE_HOOK_INET6);
 }
 
--- a/contrib/mpd/src/iface.h	Thu Jun 30 12:00:19 2011 +0300
+++ b/contrib/mpd/src/iface.h	Thu Jun 30 12:01:14 2011 +0300
@@ -90,6 +90,7 @@
   
   struct ifacestate {
     char		ifname[IFNAMSIZ];	/* Name of my interface */
+    char		ngname[IFNAMSIZ];	/* Name of my Netgraph node */
     uint		ifindex;		/* System interface index */
     struct ifaceconf	conf;
     u_char		traffic[IFACE_IDLE_SPLIT];	/* Mark any traffic */