[PATCH] renaming interfaces with ifconfig

Tobias Diedrich ranma at tdiedrich.de
Fri Dec 2 17:44:02 UTC 2005


Rob Landley wrote:

> I've glanced at it.  The code looks pretty straightforward.
> 
> Could you add a patch to usage.h to show how to use it, please?

Sure.

Index: include/usage.h
===================================================================
--- include/usage.h	(revision 12643)
+++ include/usage.h	(working copy)
@@ -1222,6 +1222,11 @@
 #else
 #  define USAGE_IPV6(a)
 #endif
+#ifdef CONFIG_FEATURE_IFCONFIG_NAME
+#  define USAGE_IFCONFIG_NAME(a) a
+#else
+#  define USAGE_IFCONFIG_NAME(a)
+#endif
 
 #define ifconfig_trivial_usage \
 	USAGE_IFCONFIG_OPT_A("[-a]") " <interface> [<address>]"
@@ -1233,6 +1238,7 @@
 	"\t[[-]broadcast [<address>]]  [[-]pointopoint [<address>]]\n" \
 	"\t[netmask <address>]  [dstaddr <address>]\n" \
 	USAGE_SIOCSKEEPALIVE("\t[outfill <NN>] [keepalive <NN>]\n") \
+	USAGE_IFCONFIG_NAME("\t[name <newname>]\n") \
 	"\t" USAGE_IFCONFIG_HW("[hw ether <address>]  ") \
 	"[metric <NN>]  [mtu <NN>]\n" \
 	"\t[[-]trailers]  [[-]arp]  [[-]allmulti]\n" \
Index: networking/ifconfig.c
===================================================================
--- networking/ifconfig.c	(revision 12643)
+++ 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);
 
Index: networking/Config.in
===================================================================
--- networking/Config.in	(revision 12643)
+++ 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

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



More information about the busybox mailing list