svn commit: trunk/busybox: applets archival coreutils e2fsprogs/old etc...

vda at busybox.net vda at busybox.net
Mon Dec 24 14:09:29 UTC 2007


Author: vda
Date: 2007-12-24 06:09:19 -0800 (Mon, 24 Dec 2007)
New Revision: 20675

Log:
nameif: extended matching (Nico Erfurth <masta at perlgolf.de>)
*: whitespace fixes

function                                             old     new   delta
prepend_new_eth_table                                  -     304    +304
nameif_main                                          620     684     +64
cc_macaddr                                            51       -     -51
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 1/0 up/down: 368/-51)           Total: 317 bytes



Modified:
   trunk/busybox/applets/applet_tables.c
   trunk/busybox/archival/unzip.c
   trunk/busybox/coreutils/echo.c
   trunk/busybox/coreutils/tr.c
   trunk/busybox/e2fsprogs/old_e2fsprogs/blkid/dev.c
   trunk/busybox/e2fsprogs/old_e2fsprogs/blkid/tag.c
   trunk/busybox/editors/sed_summary.htm
   trunk/busybox/examples/bootfloppy/bootfloppy.txt
   trunk/busybox/examples/devfsd.conf
   trunk/busybox/examples/udhcp/udhcpd.conf
   trunk/busybox/libbb/lineedit.c
   trunk/busybox/networking/Config.in
   trunk/busybox/networking/nameif.c
   trunk/busybox/util-linux/more.c


Changeset:
Modified: trunk/busybox/applets/applet_tables.c
===================================================================
--- trunk/busybox/applets/applet_tables.c	2007-12-24 12:16:24 UTC (rev 20674)
+++ trunk/busybox/applets/applet_tables.c	2007-12-24 14:09:19 UTC (rev 20675)
@@ -65,7 +65,7 @@
 	i = open(argv[1], O_WRONLY | O_TRUNC | O_CREAT, 0666);
 	if (i < 0)
 		return 1;
-	dup2(i, 1);		
+	dup2(i, 1);
 
 	/* Keep in sync with include/busybox.h! */
 

Modified: trunk/busybox/archival/unzip.c
===================================================================
--- trunk/busybox/archival/unzip.c	2007-12-24 12:16:24 UTC (rev 20674)
+++ trunk/busybox/archival/unzip.c	2007-12-24 14:09:19 UTC (rev 20675)
@@ -66,7 +66,7 @@
 struct BUG_zip_header_must_be_26_bytes {
 	char BUG_zip_header_must_be_26_bytes[
 		offsetof(zip_header_t, formatted.extra_len) + 2 ==
-	    		ZIP_HEADER_LEN ? 1 : -1];
+			ZIP_HEADER_LEN ? 1 : -1];
 };
 
 #define FIX_ENDIANNESS(zip_header) do { \

Modified: trunk/busybox/coreutils/echo.c
===================================================================
--- trunk/busybox/coreutils/echo.c	2007-12-24 12:16:24 UTC (rev 20674)
+++ trunk/busybox/coreutils/echo.c	2007-12-24 14:09:19 UTC (rev 20675)
@@ -293,6 +293,6 @@
 	}
  ret:
 	/* TODO: implement and use full_writev? */
-	return writev(1, io, (cur_io - io)) >= 0; 
+	return writev(1, io, (cur_io - io)) >= 0;
 }
 #endif

Modified: trunk/busybox/coreutils/tr.c
===================================================================
--- trunk/busybox/coreutils/tr.c	2007-12-24 12:16:24 UTC (rev 20674)
+++ trunk/busybox/coreutils/tr.c	2007-12-24 14:09:19 UTC (rev 20675)
@@ -182,7 +182,7 @@
 	ssize_t read_chars = 0;
 	size_t in_index = 0, out_index = 0;
 	unsigned last = UCHAR_MAX + 1; /* not equal to any char */
-	unsigned char coded, c; 
+	unsigned char coded, c;
 	unsigned char *output = xmalloc(BUFSIZ);
 	char *vector = xzalloc((ASCII+1) * 3);
 	char *invec  = vector + (ASCII+1);

Modified: trunk/busybox/e2fsprogs/old_e2fsprogs/blkid/dev.c
===================================================================
--- trunk/busybox/e2fsprogs/old_e2fsprogs/blkid/dev.c	2007-12-24 12:16:24 UTC (rev 20674)
+++ trunk/busybox/e2fsprogs/old_e2fsprogs/blkid/dev.c	2007-12-24 14:09:19 UTC (rev 20675)
@@ -161,7 +161,7 @@
 int main(int argc, char **argv)
 {
 	blkid_dev_iterate	iter;
-	blkid_cache 		cache = NULL;
+	blkid_cache		cache = NULL;
 	blkid_dev		dev;
 	int			c, ret;
 	char			*tmp;

Modified: trunk/busybox/e2fsprogs/old_e2fsprogs/blkid/tag.c
===================================================================
--- trunk/busybox/e2fsprogs/old_e2fsprogs/blkid/tag.c	2007-12-24 12:16:24 UTC (rev 20674)
+++ trunk/busybox/e2fsprogs/old_e2fsprogs/blkid/tag.c	2007-12-24 14:09:19 UTC (rev 20675)
@@ -364,7 +364,7 @@
 int main(int argc, char **argv)
 {
 	blkid_tag_iterate	iter;
-	blkid_cache 		cache = NULL;
+	blkid_cache		cache = NULL;
 	blkid_dev		dev;
 	int			c, ret, found;
 	int			flags = BLKID_DEV_FIND;

Modified: trunk/busybox/editors/sed_summary.htm
===================================================================
--- trunk/busybox/editors/sed_summary.htm	2007-12-24 12:16:24 UTC (rev 20674)
+++ trunk/busybox/editors/sed_summary.htm	2007-12-24 14:09:19 UTC (rev 20675)
@@ -120,7 +120,7 @@
 
 <dt><b>N</b> [<em>address1</em>[,<em>address2</em>]]<b>N</b></dt>
 <dd>Append next input line to contents of pattern space; the new line is
-separated from the previous contents of the pattern space by a newline.  
+separated from the previous contents of the pattern space by a newline.
 (This command is designed to allow pattern matches across two
 lines.  Using \n to match the embedded newline, you can match
 patterns across multiple lines.)</p></dd>

Modified: trunk/busybox/examples/bootfloppy/bootfloppy.txt
===================================================================
--- trunk/busybox/examples/bootfloppy/bootfloppy.txt	2007-12-24 12:16:24 UTC (rev 20674)
+++ trunk/busybox/examples/bootfloppy/bootfloppy.txt	2007-12-24 14:09:19 UTC (rev 20675)
@@ -76,7 +76,7 @@
 
  - Make device files in /dev:
 
- 	This can be done by running the 'mkdevs.sh' script. If you want the gory
+	This can be done by running the 'mkdevs.sh' script. If you want the gory
 	details, you can read the script.
 
  - Make necessary files in /etc:

Modified: trunk/busybox/examples/devfsd.conf
===================================================================
--- trunk/busybox/examples/devfsd.conf	2007-12-24 12:16:24 UTC (rev 20674)
+++ trunk/busybox/examples/devfsd.conf	2007-12-24 14:09:19 UTC (rev 20675)
@@ -78,7 +78,7 @@
 UNREGISTER	^radio0$		EXECUTE /bin/rm -f radio
 
 # ALSA stuff
-#LOOKUP 		snd 		MODLOAD ACTION snd
+#LOOKUP		snd		MODLOAD ACTION snd
 
 # Uncomment this to let PAM manage devfs
 # Not supported by busybox

Modified: trunk/busybox/examples/udhcp/udhcpd.conf
===================================================================
--- trunk/busybox/examples/udhcp/udhcpd.conf	2007-12-24 12:16:24 UTC (rev 20674)
+++ trunk/busybox/examples/udhcp/udhcpd.conf	2007-12-24 14:09:19 UTC (rev 20675)
@@ -2,7 +2,7 @@
 
 # The start and end of the IP lease block
 
-start 		192.168.0.20	#default: 192.168.0.20
+start		192.168.0.20	#default: 192.168.0.20
 end		192.168.0.254	#default: 192.168.0.254
 
 
@@ -67,7 +67,7 @@
 
 #notify_file				#default: (no script)
 
-#notify_file	dumpleases 	# <--- useful for debugging
+#notify_file	dumpleases	# <--- useful for debugging
 
 # The following are bootp specific options, setable by udhcpd.
 

Modified: trunk/busybox/libbb/lineedit.c
===================================================================
--- trunk/busybox/libbb/lineedit.c	2007-12-24 12:16:24 UTC (rev 20674)
+++ trunk/busybox/libbb/lineedit.c	2007-12-24 14:09:19 UTC (rev 20675)
@@ -136,7 +136,7 @@
 #define command_ps       (S.command_ps      )
 #define cmdedit_prompt   (S.cmdedit_prompt  )
 #define num_ok_lines     (S.num_ok_lines    )
-#define user_buf         (S.user_buf        ) 
+#define user_buf         (S.user_buf        )
 #define home_pwd_buf     (S.home_pwd_buf    )
 #define matches          (S.matches         )
 #define num_matches      (S.num_matches     )

Modified: trunk/busybox/networking/Config.in
===================================================================
--- trunk/busybox/networking/Config.in	2007-12-24 12:16:24 UTC (rev 20674)
+++ trunk/busybox/networking/Config.in	2007-12-24 14:09:19 UTC (rev 20675)
@@ -549,6 +549,19 @@
 	  # Comment
 	  new_interface_name    XX:XX:XX:XX:XX:XX
 
+config FEATURE_NAMEIF_EXTENDED
+	bool "Extended nameif"
+	default n
+	depends on NAMEIF
+	help
+	  This extends the nameif syntax to support the bus_info and driver
+	  checks. The syntax is compatible to the normal nameif.
+	  File format:
+	    new_interface_name  driver=asix bus=usb-0000:00:08.2-3
+	    new_interface_name  bus=usb-0000:00:08.2-3 00:80:C8:38:91:B5
+	    new_interface_name  mac=00:80:C8:38:91:B5
+	    new_interface_name  00:80:C8:38:91:B5
+
 config NC
 	bool "nc"
 	default n

Modified: trunk/busybox/networking/nameif.c
===================================================================
--- trunk/busybox/networking/nameif.c	2007-12-24 12:16:24 UTC (rev 20674)
+++ trunk/busybox/networking/nameif.c	2007-12-24 14:09:19 UTC (rev 20675)
@@ -13,8 +13,8 @@
 #include <syslog.h>
 #include <net/if.h>
 #include <netinet/ether.h>
+#include <linux/sockios.h>
 
-
 /* Older versions of net/if.h do not appear to define IF_NAMESIZE. */
 #ifndef IF_NAMESIZE
 #  ifdef IFNAMSIZ
@@ -34,138 +34,214 @@
 #define ifr_newname ifr_ifru.ifru_slave
 #endif
 
-typedef struct mactable_s {
-	struct mactable_s *next;
-	struct mactable_s *prev;
+typedef struct ethtable_s {
+	struct ethtable_s *next;
+	struct ethtable_s *prev;
 	char *ifname;
 	struct ether_addr *mac;
-} mactable_t;
+#if ENABLE_FEATURE_NAMEIF_EXTENDED
+	char *bus_info;
+	char *driver;
+#endif
+} ethtable_t;
 
-/* Check ascii str_macaddr, convert and copy to *mac */
-static struct ether_addr *cc_macaddr(const char *str_macaddr)
+#if ENABLE_FEATURE_NAMEIF_EXTENDED
+/* Cut'n'paste from ethtool.h */
+#define ETHTOOL_BUSINFO_LEN 32
+/* these strings are set to whatever the driver author decides... */
+struct ethtool_drvinfo {
+	__u32 cmd;
+	char  driver[32]; /* driver short name, "tulip", "eepro100" */
+	char  version[32];  /* driver version string */
+	char  fw_version[32]; /* firmware version string, if applicable */
+	char  bus_info[ETHTOOL_BUSINFO_LEN];  /* Bus info for this IF. */
+        /* For PCI devices, use pci_dev->slot_name. */
+	char  reserved1[32];
+	char  reserved2[16];
+	__u32 n_stats;  /* number of u64's from ETHTOOL_GSTATS */
+	__u32 testinfo_len;
+	__u32 eedump_len; /* Size of data from ETHTOOL_GEEPROM (bytes) */
+	__u32 regdump_len;  /* Size of data from ETHTOOL_GREGS (bytes) */
+};
+#define ETHTOOL_GDRVINFO  0x00000003 /* Get driver info. */
+#endif
+
+
+static void nameif_parse_selector(ethtable_t *ch, char *selector)
 {
-	struct ether_addr *lmac, *mac;
+	struct ether_addr *lmac;
+#if ENABLE_FEATURE_NAMEIF_EXTENDED
+	int found_selector = 0;
 
-	lmac = ether_aton(str_macaddr);
-	if (lmac == NULL)
-		bb_error_msg_and_die("cannot parse MAC %s", str_macaddr);
-	mac = xmalloc(ETH_ALEN);
-	memcpy(mac, lmac, ETH_ALEN);
+	while (*selector) {
+		char *next;
+#endif
+		selector = skip_whitespace(selector);
+#if ENABLE_FEATURE_NAMEIF_EXTENDED
+		if (*selector == '\0')
+			break;
+		/* Search for the end .... */
+		next = skip_non_whitespace(selector);
+		if (*next)
+			*next++ = '\0';
+		/* Check for selectors, mac= is assumed */
+		if (strncmp(selector, "bus=", 4) == 0) {
+			ch->bus_info = xstrdup(selector + 4);
+			found_selector++;
+		} else if (strncmp(selector, "driver=", 7) == 0) {
+			ch->driver = xstrdup(selector + 7);
+			found_selector++;
+		} else {
+#endif
+			lmac = ether_aton(selector + (strncmp(selector, "mac=", 4) == 0 ? 4 : 0));
+			/* Check ascii selector, convert and copy to *mac */
+			if (lmac == NULL)
+				bb_error_msg_and_die("cannot parse %s", selector);
+			ch->mac = xmalloc(ETH_ALEN);
+			memcpy(ch->mac, lmac, ETH_ALEN);
+#if  ENABLE_FEATURE_NAMEIF_EXTENDED
+			found_selector++;
+		};
+		selector = next;
+	}
+	if (found_selector == 0)
+		bb_error_msg_and_die("no selectors found for %s", ch->ifname);
+#endif
+}
 
-	return mac;
+static void prepend_new_eth_table(ethtable_t **clist, char *ifname, char *selector)
+{
+	ethtable_t *ch;
+	if (strlen(ifname) >= IF_NAMESIZE)
+		bb_error_msg_and_die("interface name '%s' too long", ifname);
+	ch = xzalloc(sizeof(*ch));
+	ch->ifname = ifname;
+	nameif_parse_selector(ch, selector);
+	ch->next = *clist;
+	if (*clist)
+		(*clist)->prev = ch;
+	*clist = ch;
 }
 
 int nameif_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int nameif_main(int argc, char **argv)
 {
-	mactable_t *clist = NULL;
+	ethtable_t *clist = NULL;
 	FILE *ifh;
 	const char *fname = "/etc/mactab";
 	char *line;
+	char *line_ptr;
+	int linenum;
 	int ctl_sk;
-	int if_index = 1;
-	mactable_t *ch;
+	ethtable_t *ch;
 
 	if (1 & getopt32(argv, "sc:", &fname)) {
 		openlog(applet_name, 0, LOG_LOCAL0);
 		logmode = LOGMODE_SYSLOG;
 	}
+	argc -= optind;
+	argv += optind;
 
-	if ((argc - optind) & 1)
+	if (argc & 1)
 		bb_show_usage();
 
-	if (optind < argc) {
-		char **a = argv + optind;
-
-		while (*a) {
-			if (strlen(*a) > IF_NAMESIZE)
-				bb_error_msg_and_die("interface name '%s' "
-					    "too long", *a);
-			ch = xzalloc(sizeof(mactable_t));
-			ch->ifname = xstrdup(*a++);
-			ch->mac = cc_macaddr(*a++);
-			if (clist)
-				clist->prev = ch;
-			ch->next = clist;
-			clist = ch;
+	if (argc) {
+		while (*argv) {
+			char *ifname = xstrdup(*argv++);
+			prepend_new_eth_table(&clist, ifname, *argv++);
 		}
 	} else {
 		ifh = xfopen(fname, "r");
-
 		while ((line = xmalloc_fgets(ifh)) != NULL) {
-			char *line_ptr;
-			size_t name_length;
+			char *next;
 
-			line_ptr = line + strspn(line, " \t");
+			line_ptr = skip_whitespace(line);
 			if ((line_ptr[0] == '#') || (line_ptr[0] == '\n')) {
 				free(line);
 				continue;
 			}
-			name_length = strcspn(line_ptr, " \t");
-			ch = xzalloc(sizeof(mactable_t));
-			ch->ifname = xstrndup(line_ptr, name_length);
-			if (name_length > IF_NAMESIZE)
-				bb_error_msg_and_die("interface name '%s' "
-						"too long", ch->ifname);
-			line_ptr += name_length;
-			line_ptr += strspn(line_ptr, " \t");
-			name_length = strspn(line_ptr, "0123456789ABCDEFabcdef:");
-			line_ptr[name_length] = '\0';
-			ch->mac = cc_macaddr(line_ptr);
-			if (clist)
-				clist->prev = ch;
-			ch->next = clist;
-			clist = ch;
+			next = skip_non_whitespace(line_ptr);
+			if (*next)
+				*next++ = '\0';
+			prepend_new_eth_table(&clist, line_ptr, next);
 			free(line);
 		}
 		fclose(ifh);
 	}
 
 	ctl_sk = xsocket(PF_INET, SOCK_DGRAM, 0);
+	ifh = xfopen("/proc/net/dev", "r");
 
+	linenum = 0;
 	while (clist) {
 		struct ifreq ifr;
+#if  ENABLE_FEATURE_NAMEIF_EXTENDED
+		struct ethtool_drvinfo drvinfo;
+#endif
 
-		memset(&ifr, 0, sizeof(struct ifreq));
-		if_index++;
-		ifr.ifr_ifindex = if_index;
+		line = xmalloc_fgets(ifh);
+		if (line == NULL)
+			break; /* Seems like we're done */
+		if (linenum++ < 2 )
+			goto next_line; /* Skip the first two lines */
 
-		/* Get ifname by index or die */
-		if (ioctl(ctl_sk, SIOCGIFNAME, &ifr))
-			break;
+		/* Find the current interface name and copy it to ifr.ifr_name */
+		line_ptr = skip_whitespace(line);
+		*skip_non_whitespace(line_ptr) = '\0';
 
-		/* Has this device hwaddr? */
-		if (ioctl(ctl_sk, SIOCGIFHWADDR, &ifr))
-			continue;
+		memset(&ifr, 0, sizeof(struct ifreq));
+		strncpy(ifr.ifr_name, line_ptr, sizeof(ifr.ifr_name));
 
-		/* Search for mac like in ifr.ifr_hwaddr.sa_data */
-		for (ch = clist; ch; ch = ch->next)
-			if (!memcmp(ch->mac, ifr.ifr_hwaddr.sa_data, ETH_ALEN))
-				break;
+#if ENABLE_FEATURE_NAMEIF_EXTENDED
+		/* Check for driver etc. */
+		memset(&drvinfo, 0, sizeof(struct ethtool_drvinfo));
+		drvinfo.cmd = ETHTOOL_GDRVINFO;
+		ifr.ifr_data = (caddr_t) &drvinfo;
+		/* Get driver and businfo first, so we have it in drvinfo */
+		ioctl(ctl_sk, SIOCETHTOOL, &ifr);
+#endif
+		ioctl(ctl_sk, SIOCGIFHWADDR, &ifr);
 
-		/* Nothing found for current ifr.ifr_hwaddr.sa_data */
-		if (ch == NULL)
-			continue;
-
-		strcpy(ifr.ifr_newname, ch->ifname);
-		ioctl_or_perror_and_die(ctl_sk, SIOCSIFNAME, &ifr,
+		/* Search the list for a matching device */
+		for (ch = clist; ch; ch = ch->next) {
+#if ENABLE_FEATURE_NAMEIF_EXTENDED
+			if (ch->bus_info && strcmp(ch->bus_info, drvinfo.bus_info) != 0)
+				continue;
+			if (ch->driver && strcmp(ch->driver, drvinfo.driver) != 0)
+				continue;
+#endif
+			if (ch->mac && memcmp(ch->mac, ifr.ifr_hwaddr.sa_data, ETH_ALEN) != 0)
+				continue;
+			/* if we came here, all selectors have matched */
+			goto found;
+		}
+		/* Nothing found for current interface */
+		goto next_line;
+ found:
+		if (strcmp(ifr.ifr_name, ch->ifname) != 0) {
+			strcpy(ifr.ifr_newname, ch->ifname);
+			ioctl_or_perror_and_die(ctl_sk, SIOCSIFNAME, &ifr,
 					"cannot change ifname %s to %s",
 					ifr.ifr_name, ch->ifname);
-
+		}
 		/* Remove list entry of renamed interface */
-		if (ch->prev != NULL) {
-			(ch->prev)->next = ch->next;
-		} else {
+		if (ch->prev != NULL)
+			ch->prev->next = ch->next;
+		else
 			clist = ch->next;
-		}
 		if (ch->next != NULL)
-			(ch->next)->prev = ch->prev;
+			ch->next->prev = ch->prev;
 		if (ENABLE_FEATURE_CLEAN_UP) {
 			free(ch->ifname);
 			free(ch->mac);
 			free(ch);
 		}
+ next_line:
+		free(line);
 	}
+	if (ENABLE_FEATURE_CLEAN_UP) {
+		fclose(ifh);
+	};
 
 	return 0;
 }

Modified: trunk/busybox/util-linux/more.c
===================================================================
--- trunk/busybox/util-linux/more.c	2007-12-24 12:16:24 UTC (rev 20674)
+++ trunk/busybox/util-linux/more.c	2007-12-24 14:09:19 UTC (rev 20675)
@@ -165,7 +165,7 @@
 			if (c == '\t') {
 				spaces = CONVERTED_TAB_SIZE - 1;
 				c = ' ';
- 			}
+			}
 
 			/*
 			 * There are two input streams to worry about here:




More information about the busybox-cvs mailing list