add a protocol event for link loss
authorFelix Fietkau <nbd@openwrt.org>
Sun, 11 Sep 2011 19:38:11 +0000 (21:38 +0200)
committerFelix Fietkau <nbd@openwrt.org>
Sun, 11 Sep 2011 19:38:11 +0000 (21:38 +0200)
interface.c
proto-shell.c
proto.h

index 72ecf4d975cb64b07c30ebc1ccee9e66153f271e..a5675f7a77a35cc90d441fd755a0b028294219ab 100644 (file)
@@ -185,6 +185,13 @@ interface_proto_cb(struct interface_proto_state *state, enum interface_proto_eve
 
                mark_interface_down(iface);
                break;
+       case IFPEV_LINK_LOST:
+               if (iface->state != IFS_UP)
+                       return;
+
+               iface->state = IFS_SETUP;
+               interface_event(iface, IFEV_DOWN);
+               break;
        }
 }
 
index 1481b66e2773aee616c3b6c3e3c200b6c198f484..bb42c982b5f532477ba880c309e131d0922e0379 100644 (file)
@@ -60,15 +60,6 @@ run_script(const char **argv, struct uloop_process *proc)
        return 0;
 }
 
-static void
-proto_shell_set_down(struct proto_shell_state *state)
-{
-       if (!state->l3_dev.dev)
-               return;
-
-       device_remove_user(&state->l3_dev);
-}
-
 static int
 proto_shell_handler(struct interface_proto_state *proto,
                    enum interface_proto_cmd cmd, bool force)
@@ -145,8 +136,8 @@ proto_shell_teardown_cb(struct uloop_process *p, int ret)
        struct proto_shell_state *state;
 
        state = container_of(p, struct proto_shell_state, teardown_task);
-       proto_shell_set_down(state);
        state->proto.proto_event(&state->proto, IFPEV_DOWN);
+       device_remove_user(&state->l3_dev);
 }
 
 static void
@@ -194,7 +185,7 @@ proto_shell_notify(struct interface_proto_state *proto, struct blob_attr *attr)
                state->proto.iface->l3_dev = &state->l3_dev;
                state->proto.proto_event(&state->proto, IFPEV_UP);
        } else {
-               proto_shell_set_down(state);
+               state->proto.proto_event(&state->proto, IFPEV_LINK_LOST);
        }
 
        return 0;
diff --git a/proto.h b/proto.h
index c1b97b267e1bcaf892c7108666c009b2bc659ec0..b4a1d04474d31e74aff3ccc9524a8464d3e00403 100644 (file)
--- a/proto.h
+++ b/proto.h
@@ -8,6 +8,7 @@ struct proto_handler;
 enum interface_proto_event {
        IFPEV_UP,
        IFPEV_DOWN,
+       IFPEV_LINK_LOST,
 };
 
 enum interface_proto_cmd {