[PATCH] renaming interfaces with ifconfig

Tobias Diedrich ranma at tdiedrich.de
Tue Nov 29 17:24:03 UTC 2005


Hi,

while I've seen that busybox at least in SVN supports nameif, the
following (slightly hacky) patch to ifconfig would provide the basic
interface renaming functionality with less code.
Also, AFAICS nameif only works for interfaces with a MAC address,
but in my case I'm more interested in renaming tun-Devices to assign
static names to my OpenVPN tunnels.

Index: networking/Config.in
===================================================================
--- networking/Config.in	(revision 12545)
+++ networking/Config.in	(working copy)
@@ -181,6 +181,15 @@
 	  Setting this will make ifconfig attempt to find the broadcast
 	  automatically if the value '+' is used.
 
+config CONFIG_FEATURE_IFCONFIG_NAME
+	bool "  Allow renaming of interfaces with option \"name\""
+	default n
+	depends on CONFIG_IFCONFIG
+	help
+	  Renames the specified interface.  For interfaces with MAC-Addresses
+	  nameif is probably the better tool, but this option is smaller and
+	  should work with any interface.
+
 config CONFIG_IFUPDOWN
 	bool "ifupdown"
 	default n
Index: networking/ifconfig.c
===================================================================
--- networking/ifconfig.c	(revision 12545)
+++ networking/ifconfig.c	(working copy)
@@ -134,6 +134,11 @@
 #define A_HOSTNAME          0
 #define A_BROADCAST         0
 #endif
+#ifdef CONFIG_FEATURE_IFCONFIG_NAME
+#define A_IFNAME         0xc0	/* Set if it is new ifname. */
+#else
+#define A_IFNAME            0
+#endif
 
 /*
  * These defines are for dealing with the A_CAST_TYPE field.
@@ -164,6 +169,7 @@
 #define ARG_DSTADDR      (A_ARG_REQ | A_CAST_HOST_COPY_RESOLVE)
 #define ARG_NETMASK      (A_ARG_REQ | A_CAST_HOST_COPY_RESOLVE | A_NETMASK)
 #define ARG_BROADCAST    (A_ARG_REQ | A_CAST_HOST_COPY_RESOLVE | A_SET_AFTER | A_BROADCAST)
+#define ARG_IFNAME       (A_ARG_REQ | A_IFNAME)
 #define ARG_HW           (A_ARG_REQ | A_CAST_HOST_COPY_IN_ETHER)
 #define ARG_POINTOPOINT  (A_ARG_REQ | A_CAST_HOST_COPY_RESOLVE | A_SET_AFTER)
 #define ARG_KEEPALIVE    (A_ARG_REQ | A_CAST_CHAR_PTR)
@@ -203,6 +209,9 @@
 	{"SIOCSIFDSTADDR", SIOCSIFDSTADDR, ifreq_offsetof(ifr_dstaddr)},
 	{"SIOCSIFNETMASK", SIOCSIFNETMASK, ifreq_offsetof(ifr_netmask)},
 	{"SIOCSIFBRDADDR", SIOCSIFBRDADDR, ifreq_offsetof(ifr_broadaddr)},
+#ifdef CONFIG_FEATURE_IFCONFIG_NAME
+	{"SIOCSIFNAME",    SIOCSIFNAME,    ifreq_offsetof(ifr_newname)},
+#endif
 #ifdef CONFIG_FEATURE_IFCONFIG_HW
 	{"SIOCSIFHWADDR",  SIOCSIFHWADDR,  ifreq_offsetof(ifr_hwaddr)},
 #endif
@@ -233,6 +242,9 @@
 	{"dstaddr",     N_ARG,         ARG_DSTADDR,     0},
 	{"netmask",     N_ARG,         ARG_NETMASK,     0},
 	{"broadcast",   N_ARG | M_CLR, ARG_BROADCAST,   IFF_BROADCAST},
+#ifdef CONFIG_FEATURE_IFCONFIG_NAME
+	{"name",        N_ARG | M_CLR, ARG_IFNAME,      0},
+#endif
 #ifdef CONFIG_FEATURE_IFCONFIG_HW
 	{"hw",          N_ARG, ARG_HW,                  0},
 #endif
@@ -479,6 +491,9 @@
 #endif
 					memcpy((((char *) (&ifr)) + a1op->ifr_offset),
 						   p, sizeof(struct sockaddr));
+				} else if ((mask & A_IFNAME) == A_IFNAME && A_IFNAME) {
+					safe_strncpy(ifr.ifr_newname, *argv, IFNAMSIZ);
+					mask = 0;
 				} else {
 					unsigned long i = strtoul(*argv, NULL, 0);
 
Cheers,

-- 
Tobias						PGP: http://9ac7e0bc.uguu.de



More information about the busybox mailing list