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 3cdfbdb..d370cae 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 7b18cef..b9833d3 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 73a3b55..5b89b17 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;