[git commit master] ifplugd: code shrink; expanded comments

Denys Vlasenko vda.linux at googlemail.com
Tue Mar 30 13:49:57 UTC 2010


commit: http://git.busybox.net/busybox/commit/?id=2004fa1bc8dee80f5f9ea3f59ab77c64075b3d6e
branch: http://git.busybox.net/busybox/commit/?id=refs/heads/master

Signed-off-by: Maxim Kryzhanovsky <xmaks at email.cz>
Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 networking/ifplugd.c |   26 +++++++++++---------------
 1 files changed, 11 insertions(+), 15 deletions(-)

diff --git a/networking/ifplugd.c b/networking/ifplugd.c
index 3739108..f398cca 100644
--- a/networking/ifplugd.c
+++ b/networking/ifplugd.c
@@ -1,6 +1,6 @@
 /* vi: set sw=4 ts=4: */
 /*
- * ifplugd for busybox
+ * ifplugd for busybox, based on ifplugd 0.28 (written by Lennart Poettering).
  *
  * Copyright (C) 2009 Maksym Kryzhanovskyy <xmaks at email.cz>
  *
@@ -22,7 +22,11 @@
 #include <linux/wireless.h>
 
 /*
-TODO: describe compat status here.
+From initial port to busybox, removed most of the redundancy by
+converting implementation of a polymorphic interface to the strict
+functional style. The main role is run a script when link state
+changed, other activities like audio signal or detailed reports
+are on the script itself.
 
 One questionable point of the design is netlink usage:
 
@@ -500,38 +504,30 @@ static NOINLINE int check_existence_through_netlink(void)
 
 		mhdr = (struct nlmsghdr*)replybuf;
 		while (bytes > 0) {
-			if (!NLMSG_OK(mhdr, bytes)
-			 || bytes < sizeof(struct nlmsghdr)
-			 || bytes < mhdr->nlmsg_len
-			) {
+			if (!NLMSG_OK(mhdr, bytes)) {
 				bb_error_msg("netlink packet too small or truncated");
 				return -1;
 			}
 
 			if (mhdr->nlmsg_type == RTM_NEWLINK || mhdr->nlmsg_type == RTM_DELLINK) {
 				struct rtattr *attr;
-				struct ifinfomsg *imsg;
 				int attr_len;
 
-				imsg = NLMSG_DATA(mhdr);
-
 				if (mhdr->nlmsg_len < NLMSG_LENGTH(sizeof(struct ifinfomsg))) {
 					bb_error_msg("netlink packet too small or truncated");
 					return -1;
 				}
 
-				attr = (struct rtattr*)((char*)imsg + NLMSG_ALIGN(sizeof(struct ifinfomsg)));
-				attr_len = NLMSG_PAYLOAD(mhdr, sizeof(struct ifinfomsg));
+				attr = IFLA_RTA(NLMSG_DATA(mhdr));
+				attr_len = IFLA_PAYLOAD(mhdr);
 
 				while (RTA_OK(attr, attr_len)) {
 					if (attr->rta_type == IFLA_IFNAME) {
-						char ifname[IFNAMSIZ + 1];
 						int len = RTA_PAYLOAD(attr);
-
 						if (len > IFNAMSIZ)
 							len = IFNAMSIZ;
-						memcpy(ifname, RTA_DATA(attr), len);
-						if (strcmp(G.iface, ifname) == 0) {
+
+						if (strncmp(G.iface, RTA_DATA(attr), len) == 0) {
 							G.iface_exists = (mhdr->nlmsg_type == RTM_NEWLINK);
 						}
 					}
-- 
1.6.3.3



More information about the busybox-cvs mailing list