[BusyBox] Support setting MAC addresses w/ ip

Rainer Weikusat rainer.weikusat at sncag.com
Wed Jul 27 18:00:01 UTC 2005


The busybox-variant of iproute2 does not support configuration
of "hardware" addresses (both broadcast and other). While the code to
configure these parameters is still in place, apparently, someone
modified the argument parsing code to no longer recognize the
'address' and 'broadcast' arguments to the 'ip link set' command.
I do not quite understand why someone would want to cripple his or her
utilities and at least I need to be able to do that.

The change from 'return -1' to 'exit(-1)' is consistent with the
other code and prevents the usage message from showing up for correct
uses which failed for "other reasons", eg attempting to change the MAC
of an interface that is presently up.

Index: busybox/networking/libiproute/iplink.c
===================================================================
RCS file: /data/repo/busybox/networking/libiproute/iplink.c,v
retrieving revision 1.1.1.1
retrieving revision 1.3
diff -u -r1.1.1.1 -r1.3
--- busybox/networking/libiproute/iplink.c	30 Nov 2004 16:02:32 -0000	1.1.1.1
+++ busybox/networking/libiproute/iplink.c	27 Jul 2005 17:43:14 -0000	1.3
@@ -285,6 +285,18 @@
 				flags |= IFF_NOARP;
 			} else
 				return on_off("noarp");
+		} else if (strcmp(*argv, "address") == 0) {
+			NEXT_ARG();
+			
+			if (newaddr)
+				duparg2("address", *argv);
+			newaddr = *argv;
+		} else if (strcmp(*argv, "broadcast") == 0) {
+			NEXT_ARG();
+
+			if (newbrd)
+				duparg2("broadcast", *argv);
+			newbrd = *argv;
 		} else {
                         if (strcmp(*argv, "dev") == 0) {
 				NEXT_ARG();
@@ -316,8 +328,7 @@
 	}
 
 	if (newname && strcmp(dev, newname)) {
-		if (do_changename(dev, newname) < 0)
-			return -1;
+		if (do_changename(dev, newname) < 0) exit(-1);
 		dev = newname;
 	}
 	if (qlen != -1) {
@@ -331,11 +342,11 @@
 	if (newaddr || newbrd) {
 		if (newbrd) {
 			if (set_address(&ifr1, 1) < 0)
-				return -1;
+				exit(-1);
 		}
 		if (newaddr) {
 			if (set_address(&ifr0, 0) < 0)
-				return -1;
+				exit(-1);
 		}
 	}
 	if (mask)



More information about the busybox mailing list