diff options
| author | Maxim Kryzhanovsky <xmaks@email.cz> | 2010-03-30 15:49:57 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-03-30 15:49:57 +0200 |
| commit | 2004fa1bc8dee80f5f9ea3f59ab77c64075b3d6e (patch) | |
| tree | d1277daa0f3b302ac0f3058cd7dc4c43cfa9a03a | |
| parent | eab75f6049595a5f4261abf73a87ea8d6f6ae0f9 (diff) | |
| download | busybox-w32-2004fa1bc8dee80f5f9ea3f59ab77c64075b3d6e.tar.gz busybox-w32-2004fa1bc8dee80f5f9ea3f59ab77c64075b3d6e.tar.bz2 busybox-w32-2004fa1bc8dee80f5f9ea3f59ab77c64075b3d6e.zip | |
ifplugd: code shrink; expanded comments
Signed-off-by: Maxim Kryzhanovsky <xmaks@email.cz>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| -rw-r--r-- | networking/ifplugd.c | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/networking/ifplugd.c b/networking/ifplugd.c index 373910863..f398cca22 100644 --- a/networking/ifplugd.c +++ b/networking/ifplugd.c | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* vi: set sw=4 ts=4: */ | 1 | /* vi: set sw=4 ts=4: */ |
| 2 | /* | 2 | /* |
| 3 | * ifplugd for busybox | 3 | * ifplugd for busybox, based on ifplugd 0.28 (written by Lennart Poettering). |
| 4 | * | 4 | * |
| 5 | * Copyright (C) 2009 Maksym Kryzhanovskyy <xmaks@email.cz> | 5 | * Copyright (C) 2009 Maksym Kryzhanovskyy <xmaks@email.cz> |
| 6 | * | 6 | * |
| @@ -22,7 +22,11 @@ | |||
| 22 | #include <linux/wireless.h> | 22 | #include <linux/wireless.h> |
| 23 | 23 | ||
| 24 | /* | 24 | /* |
| 25 | TODO: describe compat status here. | 25 | From initial port to busybox, removed most of the redundancy by |
| 26 | converting implementation of a polymorphic interface to the strict | ||
| 27 | functional style. The main role is run a script when link state | ||
| 28 | changed, other activities like audio signal or detailed reports | ||
| 29 | are on the script itself. | ||
| 26 | 30 | ||
| 27 | One questionable point of the design is netlink usage: | 31 | One questionable point of the design is netlink usage: |
| 28 | 32 | ||
| @@ -500,38 +504,30 @@ static NOINLINE int check_existence_through_netlink(void) | |||
| 500 | 504 | ||
| 501 | mhdr = (struct nlmsghdr*)replybuf; | 505 | mhdr = (struct nlmsghdr*)replybuf; |
| 502 | while (bytes > 0) { | 506 | while (bytes > 0) { |
| 503 | if (!NLMSG_OK(mhdr, bytes) | 507 | if (!NLMSG_OK(mhdr, bytes)) { |
| 504 | || bytes < sizeof(struct nlmsghdr) | ||
| 505 | || bytes < mhdr->nlmsg_len | ||
| 506 | ) { | ||
| 507 | bb_error_msg("netlink packet too small or truncated"); | 508 | bb_error_msg("netlink packet too small or truncated"); |
| 508 | return -1; | 509 | return -1; |
| 509 | } | 510 | } |
| 510 | 511 | ||
| 511 | if (mhdr->nlmsg_type == RTM_NEWLINK || mhdr->nlmsg_type == RTM_DELLINK) { | 512 | if (mhdr->nlmsg_type == RTM_NEWLINK || mhdr->nlmsg_type == RTM_DELLINK) { |
| 512 | struct rtattr *attr; | 513 | struct rtattr *attr; |
| 513 | struct ifinfomsg *imsg; | ||
| 514 | int attr_len; | 514 | int attr_len; |
| 515 | 515 | ||
| 516 | imsg = NLMSG_DATA(mhdr); | ||
| 517 | |||
| 518 | if (mhdr->nlmsg_len < NLMSG_LENGTH(sizeof(struct ifinfomsg))) { | 516 | if (mhdr->nlmsg_len < NLMSG_LENGTH(sizeof(struct ifinfomsg))) { |
| 519 | bb_error_msg("netlink packet too small or truncated"); | 517 | bb_error_msg("netlink packet too small or truncated"); |
| 520 | return -1; | 518 | return -1; |
| 521 | } | 519 | } |
| 522 | 520 | ||
| 523 | attr = (struct rtattr*)((char*)imsg + NLMSG_ALIGN(sizeof(struct ifinfomsg))); | 521 | attr = IFLA_RTA(NLMSG_DATA(mhdr)); |
| 524 | attr_len = NLMSG_PAYLOAD(mhdr, sizeof(struct ifinfomsg)); | 522 | attr_len = IFLA_PAYLOAD(mhdr); |
| 525 | 523 | ||
| 526 | while (RTA_OK(attr, attr_len)) { | 524 | while (RTA_OK(attr, attr_len)) { |
| 527 | if (attr->rta_type == IFLA_IFNAME) { | 525 | if (attr->rta_type == IFLA_IFNAME) { |
| 528 | char ifname[IFNAMSIZ + 1]; | ||
| 529 | int len = RTA_PAYLOAD(attr); | 526 | int len = RTA_PAYLOAD(attr); |
| 530 | |||
| 531 | if (len > IFNAMSIZ) | 527 | if (len > IFNAMSIZ) |
| 532 | len = IFNAMSIZ; | 528 | len = IFNAMSIZ; |
| 533 | memcpy(ifname, RTA_DATA(attr), len); | 529 | |
| 534 | if (strcmp(G.iface, ifname) == 0) { | 530 | if (strncmp(G.iface, RTA_DATA(attr), len) == 0) { |
| 535 | G.iface_exists = (mhdr->nlmsg_type == RTM_NEWLINK); | 531 | G.iface_exists = (mhdr->nlmsg_type == RTM_NEWLINK); |
| 536 | } | 532 | } |
| 537 | } | 533 | } |
