svn commit: trunk/busybox/networking

vda at busybox.net vda at busybox.net
Mon Apr 21 02:21:46 UTC 2008


Author: vda
Date: 2008-04-20 19:21:45 -0700 (Sun, 20 Apr 2008)
New Revision: 21786

Log:
*: s/IF_NAMESIZE/IFNAMSIZ/, regularize its use a bit.

function                                             old     new   delta
strncpy_IFNAMSIZ                                       -      13     +13
set_slave_mtu                                         39      37      -2
set_slave_hwaddr                                      52      50      -2
set_master_hwaddr                                     52      50      -2
set_if_flags                                          40      38      -2
get_if_settings                                      101      98      -3
ifenslave_main                                      1680    1661     -19
vconfig_main                                         306     280     -26
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/7 up/down: 13/-56)            Total: -43 bytes



Modified:
   trunk/busybox/networking/Config.in
   trunk/busybox/networking/brctl.c
   trunk/busybox/networking/ifconfig.c
   trunk/busybox/networking/ifenslave.c
   trunk/busybox/networking/interface.c
   trunk/busybox/networking/nameif.c
   trunk/busybox/networking/vconfig.c


Changeset:
Modified: trunk/busybox/networking/Config.in
===================================================================
--- trunk/busybox/networking/Config.in	2008-04-20 14:45:43 UTC (rev 21785)
+++ trunk/busybox/networking/Config.in	2008-04-21 02:21:45 UTC (rev 21786)
@@ -576,7 +576,7 @@
 	  Renamed interfaces MUST be in the down state.
 	  It is possible to use a file (default: /etc/mactab)
 	  with list of new interface names and MACs.
-	  Maximum interface name length: IF_NAMESIZE = 16
+	  Maximum interface name length: IFNAMSIZ = 16
 	  File fields are separated by space or tab.
 	  File format:
 	  # Comment

Modified: trunk/busybox/networking/brctl.c
===================================================================
--- trunk/busybox/networking/brctl.c	2008-04-20 14:45:43 UTC (rev 21785)
+++ trunk/busybox/networking/brctl.c	2008-04-21 02:21:45 UTC (rev 21786)
@@ -137,7 +137,7 @@
 
 				if (!if_indextoname(bridx[i], brname))
 					bb_perror_msg_and_die("can't get bridge name for index %d", i);
-				safe_strncpy(ifr.ifr_name, brname, IFNAMSIZ);
+				strncpy(ifr.ifr_name, brname, IFNAMSIZ);
 
 				arm_ioctl(args, BRCTL_GET_BRIDGE_INFO,
 							(unsigned long) &bi, 0);
@@ -191,7 +191,7 @@
 		if (!*argv) /* all but 'addif/delif' need at least two arguments */
 			bb_show_usage();
 
-		safe_strncpy(ifr.ifr_name, br, IFNAMSIZ);
+		strncpy(ifr.ifr_name, br, IFNAMSIZ);
 		if (key == ARG_addif || key == ARG_delif) { /* addif or delif */
 			brif = *argv;
 			ifr.ifr_ifindex = if_nametoindex(brif);

Modified: trunk/busybox/networking/ifconfig.c
===================================================================
--- trunk/busybox/networking/ifconfig.c	2008-04-20 14:45:43 UTC (rev 21785)
+++ trunk/busybox/networking/ifconfig.c	2008-04-21 02:21:45 UTC (rev 21786)
@@ -315,7 +315,7 @@
 	sockfd = xsocket(AF_INET, SOCK_DGRAM, 0);
 
 	/* get interface name */
-	safe_strncpy(ifr.ifr_name, *argv, IFNAMSIZ);
+	strncpy(ifr.ifr_name, *argv, IFNAMSIZ);
 
 	/* Process the remaining arguments. */
 	while (*++argv != (char *) NULL) {

Modified: trunk/busybox/networking/ifenslave.c
===================================================================
--- trunk/busybox/networking/ifenslave.c	2008-04-20 14:45:43 UTC (rev 21785)
+++ trunk/busybox/networking/ifenslave.c	2008-04-21 02:21:45 UTC (rev 21786)
@@ -148,6 +148,10 @@
 static int enslave(char *master_ifname, char *slave_ifname);
 static int release(char *master_ifname, char *slave_ifname);
 
+static void strncpy_IFNAMSIZ(char *dst, const char *src)
+{
+	strncpy(dst, src, IFNAMSIZ);
+}
 
 int ifenslave_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int ifenslave_main(int argc ATTRIBUTE_UNUSED, char **argv)
@@ -302,7 +306,7 @@
 	struct ethtool_drvinfo info;
 
 	memset(&ifr, 0, sizeof(ifr));
-	strncpy(ifr.ifr_name, master_ifname, IFNAMSIZ);
+	strncpy_IFNAMSIZ(ifr.ifr_name, master_ifname);
 	ifr.ifr_data = (caddr_t)&info;
 
 	info.cmd = ETHTOOL_GDRVINFO;
@@ -332,8 +336,8 @@
 			slave_ifname);
 	}
 
-	strncpy(ifr.ifr_name, master_ifname, IFNAMSIZ);
-	strncpy(ifr.ifr_slave, slave_ifname, IFNAMSIZ);
+	strncpy_IFNAMSIZ(ifr.ifr_name, master_ifname);
+	strncpy_IFNAMSIZ(ifr.ifr_slave, slave_ifname);
 	if (ioctl(skfd, SIOCBONDCHANGEACTIVE, &ifr) < 0
 	 && ioctl(skfd, BOND_CHANGE_ACTIVE_OLD, &ifr) < 0
 	) {
@@ -448,8 +452,8 @@
 	}
 
 	/* Do the real thing */
-	strncpy(ifr.ifr_name, master_ifname, IFNAMSIZ);
-	strncpy(ifr.ifr_slave, slave_ifname, IFNAMSIZ);
+	strncpy_IFNAMSIZ(ifr.ifr_name, master_ifname);
+	strncpy_IFNAMSIZ(ifr.ifr_slave, slave_ifname);
 	if (ioctl(skfd, SIOCBONDENSLAVE, &ifr) < 0
 	 && ioctl(skfd, BOND_ENSLAVE_OLD, &ifr) < 0
 	) {
@@ -484,8 +488,8 @@
 		return 1;
 	}
 
-	strncpy(ifr.ifr_name, master_ifname, IFNAMSIZ);
-	strncpy(ifr.ifr_slave, slave_ifname, IFNAMSIZ);
+	strncpy_IFNAMSIZ(ifr.ifr_name, master_ifname);
+	strncpy_IFNAMSIZ(ifr.ifr_slave, slave_ifname);
 	if (ioctl(skfd, SIOCBONDRELEASE, &ifr) < 0
 	 && ioctl(skfd, BOND_RELEASE_OLD, &ifr) < 0
 	) {
@@ -508,11 +512,11 @@
 {
 	int res;
 
-	strncpy(dd->mtu.ifr_name, ifname, IFNAMSIZ);
+	strncpy_IFNAMSIZ(dd->mtu.ifr_name, ifname);
 	res = ioctl(skfd, SIOCGIFMTU, &dd->mtu);
-	strncpy(dd->flags.ifr_name, ifname, IFNAMSIZ);
+	strncpy_IFNAMSIZ(dd->flags.ifr_name, ifname);
 	res |= ioctl(skfd, SIOCGIFFLAGS, &dd->flags);
-	strncpy(dd->hwaddr.ifr_name, ifname, IFNAMSIZ);
+	strncpy_IFNAMSIZ(dd->hwaddr.ifr_name, ifname);
 	res |= ioctl(skfd, SIOCGIFHWADDR, &dd->hwaddr);
 
 	return res;
@@ -520,7 +524,7 @@
 
 static int get_slave_flags(char *slave_ifname)
 {
-	strncpy(slave.flags.ifr_name, slave_ifname, IFNAMSIZ);
+	strncpy_IFNAMSIZ(slave.flags.ifr_name, slave_ifname);
 	return ioctl(skfd, SIOCGIFFLAGS, &slave.flags);
 }
 
@@ -528,7 +532,7 @@
 {
 	struct ifreq ifr;
 
-	strncpy(ifr.ifr_name, master_ifname, IFNAMSIZ);
+	strncpy_IFNAMSIZ(ifr.ifr_name, master_ifname);
 	memcpy(&(ifr.ifr_hwaddr), hwaddr, sizeof(struct sockaddr));
 	return ioctl(skfd, SIOCSIFHWADDR, &ifr);
 }
@@ -537,7 +541,7 @@
 {
 	struct ifreq ifr;
 
-	strncpy(ifr.ifr_name, slave_ifname, IFNAMSIZ);
+	strncpy_IFNAMSIZ(ifr.ifr_name, slave_ifname);
 	memcpy(&(ifr.ifr_hwaddr), hwaddr, sizeof(struct sockaddr));
 	return ioctl(skfd, SIOCSIFHWADDR, &ifr);
 }
@@ -547,7 +551,7 @@
 	struct ifreq ifr;
 
 	ifr.ifr_mtu = mtu;
-	strncpy(ifr.ifr_name, slave_ifname, IFNAMSIZ);
+	strncpy_IFNAMSIZ(ifr.ifr_name, slave_ifname);
 	return ioctl(skfd, SIOCSIFMTU, &ifr);
 }
 
@@ -556,7 +560,7 @@
 	struct ifreq ifr;
 
 	ifr.ifr_flags = flags;
-	strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
+	strncpy_IFNAMSIZ(ifr.ifr_name, ifname);
 	return ioctl(skfd, SIOCSIFFLAGS, &ifr);
 }
 
@@ -580,7 +584,7 @@
 {
 	struct ifreq ifr;
 
-	strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
+	strncpy_IFNAMSIZ(ifr.ifr_name, ifname);
 	ifr.ifr_addr.sa_family = AF_INET;
 	memset(ifr.ifr_addr.sa_data, 0, sizeof(ifr.ifr_addr.sa_data));
 	return ioctl(skfd, SIOCSIFADDR, &ifr);
@@ -603,7 +607,7 @@
 	int i;
 
 	for (i = 0; i < ARRAY_SIZE(ifra); i++) {
-		strncpy(ifr.ifr_name, master_ifname, IFNAMSIZ);
+		strncpy_IFNAMSIZ(ifr.ifr_name, master_ifname);
 		res = ioctl(skfd, ifra[i].g_ioctl, &ifr);
 		if (res < 0) {
 			ifr.ifr_addr.sa_family = AF_INET;
@@ -611,7 +615,7 @@
 			       sizeof(ifr.ifr_addr.sa_data));
 		}
 
-		strncpy(ifr.ifr_name, slave_ifname, IFNAMSIZ);
+		strncpy_IFNAMSIZ(ifr.ifr_name, slave_ifname);
 		res = ioctl(skfd, ifra[i].s_ioctl, &ifr);
 		if (res < 0)
 			return res;

Modified: trunk/busybox/networking/interface.c
===================================================================
--- trunk/busybox/networking/interface.c	2008-04-20 14:45:43 UTC (rev 21785)
+++ trunk/busybox/networking/interface.c	2008-04-21 02:21:45 UTC (rev 21786)
@@ -321,23 +321,23 @@
 
 struct interface {
 	struct interface *next, *prev;
-	char name[IFNAMSIZ];	/* interface name        */
-	short type;			/* if type               */
-	short flags;		/* various flags         */
-	int metric;			/* routing metric        */
-	int mtu;			/* MTU value             */
-	int tx_queue_len;	/* transmit queue length */
-	struct ifmap map;	/* hardware setup        */
-	struct sockaddr addr;	/* IP address            */
-	struct sockaddr dstaddr;	/* P-P IP address        */
-	struct sockaddr broadaddr;	/* IP broadcast address  */
-	struct sockaddr netmask;	/* IP network mask       */
+	char name[IFNAMSIZ];                    /* interface name        */
+	short type;                             /* if type               */
+	short flags;                            /* various flags         */
+	int metric;                             /* routing metric        */
+	int mtu;                                /* MTU value             */
+	int tx_queue_len;                       /* transmit queue length */
+	struct ifmap map;                       /* hardware setup        */
+	struct sockaddr addr;                   /* IP address            */
+	struct sockaddr dstaddr;                /* P-P IP address        */
+	struct sockaddr broadaddr;              /* IP broadcast address  */
+	struct sockaddr netmask;                /* IP network mask       */
 	int has_ip;
-	char hwaddr[32];	/* HW address            */
+	char hwaddr[32];                        /* HW address            */
 	int statistics_valid;
-	struct user_net_device_stats stats;	/* statistics            */
-	int keepalive;		/* keepalive value for SLIP */
-	int outfill;		/* outfill value for SLIP */
+	struct user_net_device_stats stats;     /* statistics            */
+	int keepalive;                          /* keepalive value for SLIP */
+	int outfill;                            /* outfill value for SLIP */
 };
 
 
@@ -388,7 +388,7 @@
 	}
 
 	new = xzalloc(sizeof(*new));
-	safe_strncpy(new->name, name, IFNAMSIZ);
+	strncpy(new->name, name, IFNAMSIZ);
 	nextp = ife ? &ife->next : &int_list;
 	new->prev = ife;
 	new->next = *nextp;

Modified: trunk/busybox/networking/nameif.c
===================================================================
--- trunk/busybox/networking/nameif.c	2008-04-20 14:45:43 UTC (rev 21785)
+++ trunk/busybox/networking/nameif.c	2008-04-21 02:21:45 UTC (rev 21786)
@@ -16,16 +16,11 @@
 #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
-#    define IF_NAMESIZE IFNAMSIZ
-#  else
-#    define IF_NAMESIZE 16
-#  endif
+#ifndef IFNAMSIZ
+#define IFNAMSIZ 16
 #endif
 
-/* take from linux/sockios.h */
+/* Taken from linux/sockios.h */
 #define SIOCSIFNAME	0x8923	/* set interface name */
 
 /* Octets in one Ethernet addr, from <linux/if_ether.h> */
@@ -111,7 +106,7 @@
 static void prepend_new_eth_table(ethtable_t **clist, char *ifname, char *selector)
 {
 	ethtable_t *ch;
-	if (strlen(ifname) >= IF_NAMESIZE)
+	if (strlen(ifname) >= IFNAMSIZ)
 		bb_error_msg_and_die("interface name '%s' too long", ifname);
 	ch = xzalloc(sizeof(*ch));
 	ch->ifname = xstrdup(ifname);

Modified: trunk/busybox/networking/vconfig.c
===================================================================
--- trunk/busybox/networking/vconfig.c	2008-04-20 14:45:43 UTC (rev 21785)
+++ trunk/busybox/networking/vconfig.c	2008-04-21 02:21:45 UTC (rev 21786)
@@ -133,10 +133,7 @@
 	if (ifr.cmd == SET_VLAN_NAME_TYPE_CMD) { /* set_name_type */
 		ifr.u.name_type = *xfind_str(name_types+1, argv[1]);
 	} else {
-		if (strlen(argv[1]) >= IF_NAMESIZE) {
-			bb_error_msg_and_die("if_name >= %d chars", IF_NAMESIZE);
-		}
-		strcpy(ifr.device1, argv[1]);
+		strncpy(ifr.device1, argv[1], IFNAMSIZ);
 		p = argv[2];
 
 		/* I suppose one could try to combine some of the function calls below,




More information about the busybox-cvs mailing list