proto-shell: Support teardown on layer 3 link loss
authorHans Dedecker <dedeckeh@gmail.com>
Thu, 11 Aug 2016 13:53:25 +0000 (15:53 +0200)
committerFelix Fietkau <nbd@nbd.name>
Thu, 11 Aug 2016 17:33:47 +0000 (19:33 +0200)
Commit c6858766 added interface teardown support on layer 3 device link loss
mainly for shell protocols who have no proto task like xl2tp. However for
shell protocols having a proto task it is not always the correct action to
teardown the interface; as an example the PPP daemon can be put into
persist state trying to re-establish the link via a hold-off mechanism
if layer 3 link loss is detected.
Therefore shell handlers can enable via TEARDOWN_ON_L3_LINK_DOWN a proto
flag which will teardown the interface when layer 3 link loss is detected

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
interface.c
proto-shell.c
proto.h
scripts/netifd-proto.sh

index b9833d30b5cfaa1f34c4ab3c081e84ad2b88dccf..0b9893ccad49fc4b84b698aa9d735203ebd30960 100644 (file)
@@ -414,7 +414,8 @@ interface_l3_dev_cb(struct device_user *dep, enum device_event ev)
 
        switch (ev) {
        case DEV_EVENT_LINK_DOWN:
-               interface_proto_event(iface->proto, PROTO_CMD_TEARDOWN, false);
+               if (iface->proto_handler->flags & PROTO_FLAG_TEARDOWN_ON_L3_LINK_DOWN)
+                       interface_proto_event(iface->proto, PROTO_CMD_TEARDOWN, false);
                break;
        default:
                break;
index 25dec00990979ec31d8c180a7bdb64e02027b128..4391cdd0cd2ca6e2b4a8c42e5e8d2630600ecb88 100644 (file)
@@ -906,6 +906,10 @@ proto_shell_add_handler(const char *script, const char *name, json_object *obj)
        if (tmp && json_object_get_boolean(tmp))
                handler->proto.flags |= PROTO_FLAG_LASTERROR;
 
+       tmp = json_get_field(obj, "teardown-on-l3-link-down", json_type_boolean);
+       if (tmp && json_object_get_boolean(tmp))
+               handler->proto.flags |= PROTO_FLAG_TEARDOWN_ON_L3_LINK_DOWN;
+
        config = json_get_field(obj, "config", json_type_array);
        if (config)
                handler->config_buf = netifd_handler_parse_config(&handler->config, config);
diff --git a/proto.h b/proto.h
index 87dec4e9f948d865beed5d8e8dc118e28289236d..8f50fdc21f2ee3e9eca52e6440edcc3758255c8c 100644 (file)
--- a/proto.h
+++ b/proto.h
@@ -38,6 +38,7 @@ enum {
        PROTO_FLAG_RENEW_AVAILABLE = (1 << 3),
        PROTO_FLAG_FORCE_LINK_DEFAULT = (1 << 4),
        PROTO_FLAG_LASTERROR = (1 << 5),
+       PROTO_FLAG_TEARDOWN_ON_L3_LINK_DOWN = (1 << 6),
 };
 
 struct interface_proto_state {
index 447f0f660f2c099654940801e0a2e5c650769df1..64b3cab92e05e70bbbcf3b7dd51ce623327d7de8 100644 (file)
@@ -365,6 +365,7 @@ init_proto() {
                                no_proto_task=0
                                available=0
                                renew_handler=0
+                               teardown_on_l3_link_down=0
 
                                add_default_handler "proto_$1_init_config"
 
@@ -378,6 +379,7 @@ init_proto() {
                                json_add_boolean available "$available"
                                json_add_boolean renew-handler "$renew_handler"
                                json_add_boolean lasterror "$lasterror"
+                               json_add_boolean teardown-on-l3-link-down "$teardown_on_l3_link_down"
                                json_dump
                        }
                ;;