[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    =?us-ascii?Q?=5BPATCH=5D=20ifplugd?=
From:       Maxim Kry¾anovskı <xmaks () email ! cz>
Date:       2010-03-27 12:12:54
Message-ID: 4849.1655.2299-18146-591379584-1269691974 () email ! cz
[Download RAW message or body]

Hi Denis,

please consider the following patches:

-- the detect_link_auto serialization

function                                             old     new   delta
.rodata                                           131770  131810     +40
detect_link_auto                                     202     125     -77
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 40/-77)            Total: -37 bytes

-- the first with attempt to reuse strings

function                                             old     new   delta
network_ioctl                                         43      49      +6
.rodata                                           131770  131709     -61
detect_link_auto                                     202     125     -77
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 6/-138)           Total: -132 bytes


Thanks.
--
maks
["=?us-ascii?Q?ifplugd=2Edetect=5Flink=5Fauto=2Epatch?=" (text/x-patch)]

diff --git a/networking/ifplugd.c b/networking/ifplugd.c
index 3567dea..3ad4bde 100644
--- a/networking/ifplugd.c
+++ b/networking/ifplugd.c
@@ -406,10 +406,20 @@ static smallint detect_link_wlan(void)
 
 static smallint detect_link_auto(void)
 {
-	const char *method;
 	smallint iface_status;
 	smallint sv_logmode;
 
+	struct {
+		const char *name;
+		smallint (*func)(void);
+	} method[] = {
+		{"SIOCETHTOOL", &detect_link_ethtool},
+		{"SIOCGMIIPHY", &detect_link_mii},
+		{"SIOCDEVPRIVATE", &detect_link_priv},
+		{"wireless extension", &detect_link_wlan},
+		{"IFF_RUNNING", &detect_link_iff},
+	};
+
 	if (G.cached_detect_link_func) {
 		iface_status = G.cached_detect_link_func();
 		if (iface_status != IFSTATUS_ERR)
@@ -417,48 +427,17 @@ static smallint detect_link_auto(void)
 	}
 
 	sv_logmode = logmode;
-	logmode = LOGMODE_NONE;
-
-	iface_status = detect_link_ethtool();
-	if (iface_status != IFSTATUS_ERR) {
-		G.cached_detect_link_func = detect_link_ethtool;
-		method = "SIOCETHTOOL";
- found_method:
+	for (int i = 0; i < 5; i++) {
+		logmode = LOGMODE_NONE;
+		iface_status = method[i].func();
 		logmode = sv_logmode;
-		bb_error_msg("using %s detection mode", method);
-		return iface_status;
-	}
-
-	iface_status = detect_link_mii();
-	if (iface_status != IFSTATUS_ERR) {
-		G.cached_detect_link_func = detect_link_mii;
-		method = "SIOCGMIIPHY";
-		goto found_method;
-	}
-
-	iface_status = detect_link_priv();
-	if (iface_status != IFSTATUS_ERR) {
-		G.cached_detect_link_func = detect_link_priv;
-		method = "SIOCDEVPRIVATE";
-		goto found_method;
-	}
-
-	iface_status = detect_link_wlan();
-	if (iface_status != IFSTATUS_ERR) {
-		G.cached_detect_link_func = detect_link_wlan;
-		method = "wireless extension";
-		goto found_method;
-	}
-
-	iface_status = detect_link_iff();
-	if (iface_status != IFSTATUS_ERR) {
-		G.cached_detect_link_func = detect_link_iff;
-		method = "IFF_RUNNING";
-		goto found_method;
+		if (iface_status != IFSTATUS_ERR) {
+			G.cached_detect_link_func = method[i].func;
+			bb_error_msg("using %s detection mode", method[i].name);
+			break;
+		}
 	}
-
-	logmode = sv_logmode;
-	return iface_status; /* IFSTATUS_ERR */
+	return iface_status;
 }
 
 static smallint detect_link(void)

["=?us-ascii?Q?ifplugd=2Edetect=5Flink=5Fauto=2Eattempt=5Fto=5Freuse=5Fstrings=2Epatch?=" (text/x-patch)]

diff --git a/networking/ifplugd.c b/networking/ifplugd.c
index 3567dea..aea7a2b 100644
--- a/networking/ifplugd.c
+++ b/networking/ifplugd.c
@@ -214,7 +214,7 @@ static int network_ioctl(int request, void* data, const char *errmsg)
 {
 	int r = ioctl(ioctl_fd, request, data);
 	if (r < 0 && errmsg)
-		bb_perror_msg(errmsg);
+		bb_perror_msg("%s failed", errmsg);
 	return r;
 }
 
@@ -239,7 +239,7 @@ static void up_iface(void)
 		return;
 
 	set_ifreq_to_ifname(&ifrequest);
-	if (network_ioctl(SIOCGIFFLAGS, &ifrequest, "can't get interface flags") < 0) {
+	if (network_ioctl(SIOCGIFFLAGS, &ifrequest, "get interface flags") < 0) {
 		G.iface_exists = 0;
 		return;
 	}
@@ -248,7 +248,7 @@ static void up_iface(void)
 		ifrequest.ifr_flags |= IFF_UP;
 		/* Let user know we mess up with interface */
 		bb_error_msg("upping interface");
-		if (network_ioctl(SIOCSIFFLAGS, &ifrequest, "can't set interface flags") < 0)
+		if (network_ioctl(SIOCSIFFLAGS, &ifrequest, "set interface flags") < 0)
 			xfunc_die();
 	}
 
@@ -307,13 +307,13 @@ static smallint detect_link_mii(void)
 
 	set_ifreq_to_ifname(&ifreq);
 
-	if (network_ioctl(SIOCGMIIPHY, &ifreq, "SIOCGMIIPHY failed") < 0) {
+	if (network_ioctl(SIOCGMIIPHY, &ifreq, "SIOCGMIIPHY") < 0) {
 		return IFSTATUS_ERR;
 	}
 
 	mii->reg_num = 1;
 
-	if (network_ioctl(SIOCGMIIREG, &ifreq, "SIOCGMIIREG failed") < 0) {
+	if (network_ioctl(SIOCGMIIREG, &ifreq, "SIOCGMIIREG") < 0) {
 		return IFSTATUS_ERR;
 	}
 
@@ -327,13 +327,13 @@ static smallint detect_link_priv(void)
 
 	set_ifreq_to_ifname(&ifreq);
 
-	if (network_ioctl(SIOCDEVPRIVATE, &ifreq, "SIOCDEVPRIVATE failed") < 0) {
+	if (network_ioctl(SIOCDEVPRIVATE, &ifreq, "SIOCDEVPRIVATE") < 0) {
 		return IFSTATUS_ERR;
 	}
 
 	mii->reg_num = 1;
 
-	if (network_ioctl(SIOCDEVPRIVATE+1, &ifreq, "SIOCDEVPRIVATE+1 failed") < 0) {
+	if (network_ioctl(SIOCDEVPRIVATE+1, &ifreq, "SIOCDEVPRIVATE+1") < 0) {
 		return IFSTATUS_ERR;
 	}
 
@@ -350,7 +350,7 @@ static smallint detect_link_ethtool(void)
 	edata.cmd = ETHTOOL_GLINK;
 	ifreq.ifr_data = (void*) &edata;
 
-	if (network_ioctl(SIOCETHTOOL, &ifreq, "ETHTOOL_GLINK failed") < 0) {
+	if (network_ioctl(SIOCETHTOOL, &ifreq, "ETHTOOL_GLINK") < 0) {
 		return IFSTATUS_ERR;
 	}
 
@@ -363,7 +363,7 @@ static smallint detect_link_iff(void)
 
 	set_ifreq_to_ifname(&ifreq);
 
-	if (network_ioctl(SIOCGIFFLAGS, &ifreq, "SIOCGIFFLAGS failed") < 0) {
+	if (network_ioctl(SIOCGIFFLAGS, &ifreq, "SIOCGIFFLAGS") < 0) {
 		return IFSTATUS_ERR;
 	}
 
@@ -387,7 +387,7 @@ static smallint detect_link_wlan(void)
 	memset(&iwrequest, 0, sizeof(struct iwreq));
 	strncpy_IFNAMSIZ(iwrequest.ifr_ifrn.ifrn_name, G.iface);
 
-	if (network_ioctl(SIOCGIWAP, &iwrequest, "SIOCGIWAP failed") < 0) {
+	if (network_ioctl(SIOCGIWAP, &iwrequest, "SIOCGIWAP") < 0) {
 		return IFSTATUS_ERR;
 	}
 
@@ -406,10 +406,20 @@ static smallint detect_link_wlan(void)
 
 static smallint detect_link_auto(void)
 {
-	const char *method;
 	smallint iface_status;
 	smallint sv_logmode;
 
+	struct {
+		const char *name;
+		smallint (*func)(void);
+	} method[] = {
+		{"SIOCETHTOOL", &detect_link_ethtool},
+		{"SIOCGMIIPHY", &detect_link_mii},
+		{"SIOCDEVPRIVATE", &detect_link_priv},
+		{"wireless extension", &detect_link_wlan},
+		{"IFF_RUNNING", &detect_link_iff},
+	};
+
 	if (G.cached_detect_link_func) {
 		iface_status = G.cached_detect_link_func();
 		if (iface_status != IFSTATUS_ERR)
@@ -417,48 +427,17 @@ static smallint detect_link_auto(void)
 	}
 
 	sv_logmode = logmode;
-	logmode = LOGMODE_NONE;
-
-	iface_status = detect_link_ethtool();
-	if (iface_status != IFSTATUS_ERR) {
-		G.cached_detect_link_func = detect_link_ethtool;
-		method = "SIOCETHTOOL";
- found_method:
+	for (int i = 0; i < 5; i++) {
+		logmode = LOGMODE_NONE;
+		iface_status = method[i].func();
 		logmode = sv_logmode;
-		bb_error_msg("using %s detection mode", method);
-		return iface_status;
-	}
-
-	iface_status = detect_link_mii();
-	if (iface_status != IFSTATUS_ERR) {
-		G.cached_detect_link_func = detect_link_mii;
-		method = "SIOCGMIIPHY";
-		goto found_method;
-	}
-
-	iface_status = detect_link_priv();
-	if (iface_status != IFSTATUS_ERR) {
-		G.cached_detect_link_func = detect_link_priv;
-		method = "SIOCDEVPRIVATE";
-		goto found_method;
-	}
-
-	iface_status = detect_link_wlan();
-	if (iface_status != IFSTATUS_ERR) {
-		G.cached_detect_link_func = detect_link_wlan;
-		method = "wireless extension";
-		goto found_method;
-	}
-
-	iface_status = detect_link_iff();
-	if (iface_status != IFSTATUS_ERR) {
-		G.cached_detect_link_func = detect_link_iff;
-		method = "IFF_RUNNING";
-		goto found_method;
+		if (iface_status != IFSTATUS_ERR) {
+			G.cached_detect_link_func = method[i].func;
+			bb_error_msg("using %s detection mode", method[i].name);
+			break;
+		}
 	}
-
-	logmode = sv_logmode;
-	return iface_status; /* IFSTATUS_ERR */
+	return iface_status;
 }
 
 static smallint detect_link(void)


_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic