interface: report link up events for force_link interfaces
authorFelix Fietkau <nbd@nbd.name>
Fri, 29 Jul 2016 14:12:17 +0000 (16:12 +0200)
committerFelix Fietkau <nbd@nbd.name>
Fri, 29 Jul 2016 14:12:45 +0000 (16:12 +0200)
Signed-off-by: Felix Fietkau <nbd@nbd.name>
interface-event.c
interface.c
interface.h

index 3cdfbdbd9214f00dfd45a84b4ba5ce3ee672dd70..d370caec4c9b9d3b821c6f0fab9bc5ac45989abd 100644 (file)
@@ -30,7 +30,14 @@ static void task_complete(struct uloop_process *proc, int ret);
 static struct uloop_process task = {
        .cb = task_complete,
 };
-static const char * const eventnames[] = {"ifdown", "ifup", "ifupdate", "free", "reload"};
+static const char * const eventnames[] = {
+       [IFEV_DOWN] = "ifdown",
+       [IFEV_UP] = "ifup",
+       [IFEV_UPDATE] = "ifupdate",
+       [IFEV_FREE] = "free",
+       [IFEV_RELOAD] = "reload",
+       [IFEV_LINK_UP] = "iflink",
+};
 
 static void
 run_cmd(const char *ifname, const char *device, enum interface_event event,
@@ -178,6 +185,7 @@ static void interface_event_cb(struct interface_user *dep, struct interface *ifa
                               enum interface_event ev)
 {
        switch (ev) {
+               case IFEV_LINK_UP:
                case IFEV_UP:
                case IFEV_UPDATE:
                case IFEV_DOWN:
index 7b18cef58a47d8aed15c0e568652a54b1d8d2ae7..b9833d30b5cfaa1f34c4ab3c081e84ad2b88dccf 100644 (file)
@@ -260,6 +260,7 @@ mark_interface_down(struct interface *iface)
        if (state == IFS_DOWN)
                return;
 
+       iface->link_up_event = false;
        iface->state = IFS_DOWN;
        if (state == IFS_UP)
                interface_event(iface, IFEV_DOWN);
@@ -355,6 +356,11 @@ interface_set_link_state(struct interface *iface, bool new_state)
        netifd_log_message(L_NOTICE, "Interface '%s' has link connectivity %s\n", iface->name, new_state ? "" : "loss");
        iface->link_state = new_state;
        interface_check_state(iface);
+
+       if (new_state && iface->force_link && iface->state == IFS_UP && !iface->link_up_event) {
+               interface_event(iface, IFEV_LINK_UP);
+               iface->link_up_event = true;
+       }
 }
 
 static void
@@ -550,8 +556,7 @@ interface_alias_cb(struct interface_user *dep, struct interface *iface, enum int
        case IFEV_FREE:
                interface_remove_user(dep);
                break;
-       case IFEV_RELOAD:
-       case IFEV_UPDATE:
+       default:
                break;
        }
 }
index 73a3b556ec0a76979d9aa2f1c500c181a0c6bc92..5b89b176e5b2f95d849e981e1d70ceb7137b63c4 100644 (file)
@@ -26,6 +26,7 @@ enum interface_event {
        IFEV_UPDATE,
        IFEV_FREE,
        IFEV_RELOAD,
+       IFEV_LINK_UP,
 };
 
 enum interface_state {
@@ -113,6 +114,7 @@ struct interface {
        bool force_link;
        bool dynamic;
        bool policy_rules_set;
+       bool link_up_event;
 
        time_t start_time;
        enum interface_state state;