mirror of
https://github.com/sheumann/hush.git
synced 2025-01-03 00:31:16 +00:00
ifplugd: code shrink; expanded comments
Signed-off-by: Maxim Kryzhanovsky <xmaks@email.cz> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
eab75f6049
commit
2004fa1bc8
@ -1,6 +1,6 @@
|
|||||||
/* vi: set sw=4 ts=4: */
|
/* 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@email.cz>
|
* Copyright (C) 2009 Maksym Kryzhanovskyy <xmaks@email.cz>
|
||||||
*
|
*
|
||||||
@ -22,7 +22,11 @@
|
|||||||
#include <linux/wireless.h>
|
#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:
|
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;
|
mhdr = (struct nlmsghdr*)replybuf;
|
||||||
while (bytes > 0) {
|
while (bytes > 0) {
|
||||||
if (!NLMSG_OK(mhdr, bytes)
|
if (!NLMSG_OK(mhdr, bytes)) {
|
||||||
|| bytes < sizeof(struct nlmsghdr)
|
|
||||||
|| bytes < mhdr->nlmsg_len
|
|
||||||
) {
|
|
||||||
bb_error_msg("netlink packet too small or truncated");
|
bb_error_msg("netlink packet too small or truncated");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mhdr->nlmsg_type == RTM_NEWLINK || mhdr->nlmsg_type == RTM_DELLINK) {
|
if (mhdr->nlmsg_type == RTM_NEWLINK || mhdr->nlmsg_type == RTM_DELLINK) {
|
||||||
struct rtattr *attr;
|
struct rtattr *attr;
|
||||||
struct ifinfomsg *imsg;
|
|
||||||
int attr_len;
|
int attr_len;
|
||||||
|
|
||||||
imsg = NLMSG_DATA(mhdr);
|
|
||||||
|
|
||||||
if (mhdr->nlmsg_len < NLMSG_LENGTH(sizeof(struct ifinfomsg))) {
|
if (mhdr->nlmsg_len < NLMSG_LENGTH(sizeof(struct ifinfomsg))) {
|
||||||
bb_error_msg("netlink packet too small or truncated");
|
bb_error_msg("netlink packet too small or truncated");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
attr = (struct rtattr*)((char*)imsg + NLMSG_ALIGN(sizeof(struct ifinfomsg)));
|
attr = IFLA_RTA(NLMSG_DATA(mhdr));
|
||||||
attr_len = NLMSG_PAYLOAD(mhdr, sizeof(struct ifinfomsg));
|
attr_len = IFLA_PAYLOAD(mhdr);
|
||||||
|
|
||||||
while (RTA_OK(attr, attr_len)) {
|
while (RTA_OK(attr, attr_len)) {
|
||||||
if (attr->rta_type == IFLA_IFNAME) {
|
if (attr->rta_type == IFLA_IFNAME) {
|
||||||
char ifname[IFNAMSIZ + 1];
|
|
||||||
int len = RTA_PAYLOAD(attr);
|
int len = RTA_PAYLOAD(attr);
|
||||||
|
|
||||||
if (len > IFNAMSIZ)
|
if (len > IFNAMSIZ)
|
||||||
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);
|
G.iface_exists = (mhdr->nlmsg_type == RTM_NEWLINK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user