From 80a71aff07c9cc1fb18adb17c5cff1cb1d0e038a Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Sun, 31 Dec 2017 12:25:50 +0100 Subject: [PATCH] netlink.so. Refactor (simplify) and fix problem with loss of events An interface may come up with IFF_RUNNING already set, but we would only detect IFF_UP. This patch simplfies the code a lot by pivoting the qualifier from using ifi_change to ifi_flags, which is the actual current status of an interface. Signed-off-by: Joachim Nilsson --- plugins/netlink.c | 52 ++++++++++++++++++++--------------------------- 1 file changed, 22 insertions(+), 30 deletions(-) diff --git a/plugins/netlink.c b/plugins/netlink.c index b6f03e99..12288e1c 100644 --- a/plugins/netlink.c +++ b/plugins/netlink.c @@ -118,45 +118,37 @@ static void nl_link(struct nlmsghdr *nlmsg) switch (nlmsg->nlmsg_type) { case RTM_NEWLINK: /* - * New interface has appearad, or interface flags has changed. + * 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, ifi_change 0x%x", ifname, i->ifi_change); - if (i->ifi_change & IFF_UP) { - snprintf(msg, sizeof(msg), "net/%s/up", ifname); + _d("%s: New link, flags 0x%x, change 0x%x", ifname, i->ifi_flags, i->ifi_change); + snprintf(msg, sizeof(msg), "net/%s/exist", ifname); + cond_set(msg); - if (i->ifi_flags & IFF_UP) - cond_set(msg); - else - cond_clear(msg); - - if (string_compare("lo", ifname)) { - snprintf(msg, sizeof(msg), "net/%s/exist", ifname); - cond_set(msg); - } - } else if (i->ifi_change & IFF_RUNNING) { - snprintf(msg, sizeof(msg), "net/%s/running", ifname); - - if (i->ifi_flags & IFF_RUNNING) - cond_set(msg); - else - cond_clear(msg); - - if (string_compare("lo", ifname)) { - snprintf(msg, sizeof(msg), "net/%s/exist", ifname); - cond_set(msg); - } - } else { - snprintf(msg, sizeof(msg), "net/%s/exist", ifname); + snprintf(msg, sizeof(msg), "net/%s/up", ifname); + if (i->ifi_flags & IFF_UP) cond_set(msg); - } + else + cond_clear(msg); + + snprintf(msg, sizeof(msg), "net/%s/running", ifname); + if (i->ifi_flags & IFF_RUNNING) + cond_set(msg); + else + cond_clear(msg); break; case RTM_DELLINK: - /* NOTE: Interface has dissapeared, not link down ... */ - _d("%s: Delete link", ifname); + /* NOTE: Interface has disappeared, not link down ... */ + _e("%s: Delete link", ifname); snprintf(msg, sizeof(msg), "net/%s/exist", ifname); cond_clear(msg); + + snprintf(msg, sizeof(msg), "net/%s/up", ifname); + cond_clear(msg); + + snprintf(msg, sizeof(msg), "net/%s/running", ifname); + cond_clear(msg); break; case RTM_NEWADDR: