From 1abd43384b84979b285aa0ce9f2faddd2df7fbcf Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Sun, 7 Mar 2021 12:20:59 +0100 Subject: [PATCH] plugins: netlink: minor refactor, collapse for-loop Signed-off-by: Joachim Wiberg --- plugins/netlink.c | 65 +++++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 33 deletions(-) diff --git a/plugins/netlink.c b/plugins/netlink.c index aafc2f6b..a33c4eec 100644 --- a/plugins/netlink.c +++ b/plugins/netlink.c @@ -131,44 +131,43 @@ static void nl_link(struct nlmsghdr *nlmsg, ssize_t len) return; } - while (RTA_OK(a, la)) { - if (a->rta_type == IFLA_IFNAME) { - strlcpy(ifname, RTA_DATA(a), sizeof(ifname)); - 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; + for (; RTA_OK(a, la); a = RTA_NEXT(a, la)) { + if (a->rta_type != IFLA_IFNAME) + continue; - case RTM_DELLINK: - /* NOTE: Interface has disappeared, not link down ... */ - _d("%s: Delete link", ifname); - net_cond_set(ifname, "exist", 0); - net_cond_set(ifname, "up", 0); - net_cond_set(ifname, "running", 0); - break; + strlcpy(ifname, RTA_DATA(a), sizeof(ifname)); + 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_NEWADDR: - _d("%s: New Address", ifname); - break; + case RTM_DELLINK: + /* NOTE: Interface has disappeared, not link down ... */ + _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: - _d("%s: Deconfig Address", ifname); - break; + case RTM_NEWADDR: + _d("%s: New Address", ifname); + break; - default: - _d("%s: Msg 0x%x", ifname, nlmsg->nlmsg_type); - break; - } + case RTM_DELADDR: + _d("%s: Deconfig Address", ifname); + break; + + default: + _d("%s: Msg 0x%x", ifname, nlmsg->nlmsg_type); + break; } - - a = RTA_NEXT(a, la); } }