mirror of
https://github.com/troglobit/finit.git
synced 2026-10-27 12:20:54 +00:00
plugins: netlink: minor refactor, collapse for-loop
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
1 parent
70a1acc210
commit
1abd43384b
1 file changed
+32
-33
+32
-33
@@ -131,44 +131,43 @@ static void nl_link(struct nlmsghdr *nlmsg, ssize_t len)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (RTA_OK(a, la)) {
|
for (; RTA_OK(a, la); a = RTA_NEXT(a, la)) {
|
||||||
if (a->rta_type == IFLA_IFNAME) {
|
if (a->rta_type != IFLA_IFNAME)
|
||||||
strlcpy(ifname, RTA_DATA(a), sizeof(ifname));
|
continue;
|
||||||
switch (nlmsg->nlmsg_type) {
|
|
||||||
case RTM_NEWLINK:
|
|
||||||
/*
|
|
||||||
* New interface has appeared, or interface flags has changed.
|
|
||||||
* Check ifi_flags here to see if the interface is UP/DOWN
|
|
||||||
*/
|
|
||||||
_d("%s: New link, flags 0x%x, change 0x%x", ifname, i->ifi_flags, i->ifi_change);
|
|
||||||
net_cond_set(ifname, "exist", 1);
|
|
||||||
net_cond_set(ifname, "up", i->ifi_flags & IFF_UP);
|
|
||||||
net_cond_set(ifname, "running", i->ifi_flags & IFF_RUNNING);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case RTM_DELLINK:
|
strlcpy(ifname, RTA_DATA(a), sizeof(ifname));
|
||||||
/* NOTE: Interface has disappeared, not link down ... */
|
switch (nlmsg->nlmsg_type) {
|
||||||
_d("%s: Delete link", ifname);
|
case RTM_NEWLINK:
|
||||||
net_cond_set(ifname, "exist", 0);
|
/*
|
||||||
net_cond_set(ifname, "up", 0);
|
* New interface has appeared, or interface flags has changed.
|
||||||
net_cond_set(ifname, "running", 0);
|
* Check ifi_flags here to see if the interface is UP/DOWN
|
||||||
break;
|
*/
|
||||||
|
_d("%s: New link, flags 0x%x, change 0x%x", ifname, i->ifi_flags, i->ifi_change);
|
||||||
|
net_cond_set(ifname, "exist", 1);
|
||||||
|
net_cond_set(ifname, "up", i->ifi_flags & IFF_UP);
|
||||||
|
net_cond_set(ifname, "running", i->ifi_flags & IFF_RUNNING);
|
||||||
|
break;
|
||||||
|
|
||||||
case RTM_NEWADDR:
|
case RTM_DELLINK:
|
||||||
_d("%s: New Address", ifname);
|
/* NOTE: Interface has disappeared, not link down ... */
|
||||||
break;
|
_d("%s: Delete link", ifname);
|
||||||
|
net_cond_set(ifname, "exist", 0);
|
||||||
|
net_cond_set(ifname, "up", 0);
|
||||||
|
net_cond_set(ifname, "running", 0);
|
||||||
|
break;
|
||||||
|
|
||||||
case RTM_DELADDR:
|
case RTM_NEWADDR:
|
||||||
_d("%s: Deconfig Address", ifname);
|
_d("%s: New Address", ifname);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
case RTM_DELADDR:
|
||||||
_d("%s: Msg 0x%x", ifname, nlmsg->nlmsg_type);
|
_d("%s: Deconfig Address", ifname);
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
default:
|
||||||
|
_d("%s: Msg 0x%x", ifname, nlmsg->nlmsg_type);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
a = RTA_NEXT(a, la);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user