mirror of
https://github.com/troglobit/finit.git
synced 2026-11-10 16:31:21 +00:00
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 <troglobit@gmail.com>
This commit is contained in:
1 parent
04a4653e9b
commit
80a71aff07
1 file changed
+22
-30
+22
-30
@@ -118,45 +118,37 @@ static void nl_link(struct nlmsghdr *nlmsg)
|
|||||||
switch (nlmsg->nlmsg_type) {
|
switch (nlmsg->nlmsg_type) {
|
||||||
case RTM_NEWLINK:
|
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
|
* Check ifi_flags here to see if the interface is UP/DOWN
|
||||||
*/
|
*/
|
||||||
_d("%s: New link, ifi_change 0x%x", ifname, i->ifi_change);
|
_d("%s: New link, flags 0x%x, change 0x%x", ifname, i->ifi_flags, i->ifi_change);
|
||||||
if (i->ifi_change & IFF_UP) {
|
snprintf(msg, sizeof(msg), "net/%s/exist", ifname);
|
||||||
snprintf(msg, sizeof(msg), "net/%s/up", ifname);
|
cond_set(msg);
|
||||||
|
|
||||||
if (i->ifi_flags & IFF_UP)
|
snprintf(msg, sizeof(msg), "net/%s/up", ifname);
|
||||||
cond_set(msg);
|
if (i->ifi_flags & IFF_UP)
|
||||||
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);
|
|
||||||
cond_set(msg);
|
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;
|
break;
|
||||||
|
|
||||||
case RTM_DELLINK:
|
case RTM_DELLINK:
|
||||||
/* NOTE: Interface has dissapeared, not link down ... */
|
/* NOTE: Interface has disappeared, not link down ... */
|
||||||
_d("%s: Delete link", ifname);
|
_e("%s: Delete link", ifname);
|
||||||
snprintf(msg, sizeof(msg), "net/%s/exist", ifname);
|
snprintf(msg, sizeof(msg), "net/%s/exist", ifname);
|
||||||
cond_clear(msg);
|
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;
|
break;
|
||||||
|
|
||||||
case RTM_NEWADDR:
|
case RTM_NEWADDR:
|
||||||
|
|||||||
Reference in new issue
Block a user