proto-shell: allow running protocols without proto_task.
authorYousong Zhou <yszhou4tech@gmail.com>
Tue, 19 May 2015 12:38:32 +0000 (20:38 +0800)
committerFelix Fietkau <nbd@openwrt.org>
Sat, 23 May 2015 14:44:46 +0000 (16:44 +0200)
Adds a new config parameter "no-proto-task" for noting that no
proto_task will be running for this protocol type.  This is required
since then change in commit "d0dcf74 proto-shell: retry setup if the
proto handler script quits without changing the state or starting a
process".

The change is mainly for protocols like xl2tpd in which control commands
are sent to another daemon xl2tpd to start L2TP negotiation and pppd
process who is not under netifd's control as proto_task as is the case
in other ppp related protocols like pppoe, pptp, etc.

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
proto-shell.c
scripts/netifd-proto.sh

index bc4c658..50f1b5b 100644 (file)
@@ -44,6 +44,7 @@ struct proto_shell_handler {
        char *config_buf;
        char *script_name;
        bool init_available;
        char *config_buf;
        char *script_name;
        bool init_available;
+       bool no_proto_task;
 
        struct uci_blob_param_list config;
 };
 
        struct uci_blob_param_list config;
 };
@@ -284,11 +285,12 @@ proto_shell_task_finish(struct proto_shell_state *state,
                if (task == &state->proto_task)
                        proto_shell_handler(&state->proto, PROTO_CMD_TEARDOWN,
                                            false);
                if (task == &state->proto_task)
                        proto_shell_handler(&state->proto, PROTO_CMD_TEARDOWN,
                                            false);
-               if (task == &state->script_task) {
+               else if (task == &state->script_task) {
                        if (state->renew_pending)
                                proto_shell_handler(&state->proto,
                                                    PROTO_CMD_RENEW, false);
                        if (state->renew_pending)
                                proto_shell_handler(&state->proto,
                                                    PROTO_CMD_RENEW, false);
-                       else if (!state->proto_task.uloop.pending &&
+                       else if (!state->handler->no_proto_task &&
+                                !state->proto_task.uloop.pending &&
                                 state->sm == S_SETUP)
                                proto_shell_handler(&state->proto,
                                                    PROTO_CMD_TEARDOWN,
                                 state->sm == S_SETUP)
                                proto_shell_handler(&state->proto,
                                                    PROTO_CMD_TEARDOWN,
@@ -818,6 +820,12 @@ 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_NODEV;
 
        if (tmp && json_object_get_boolean(tmp))
                handler->proto.flags |= PROTO_FLAG_NODEV;
 
+       tmp = json_get_field(obj, "no-proto-task", json_type_boolean);
+       if (tmp && json_object_get_boolean(tmp))
+               handler->no_proto_task = true;
+       else
+               handler->no_proto_task = false;
+
        tmp = json_get_field(obj, "available", json_type_boolean);
        if (tmp && json_object_get_boolean(tmp))
                handler->proto.flags |= PROTO_FLAG_INIT_AVAILABLE;
        tmp = json_get_field(obj, "available", json_type_boolean);
        if (tmp && json_object_get_boolean(tmp))
                handler->proto.flags |= PROTO_FLAG_INIT_AVAILABLE;
index 95c1bb3..447f0f6 100644 (file)
@@ -362,6 +362,7 @@ init_proto() {
                dump)
                        add_protocol() {
                                no_device=0
                dump)
                        add_protocol() {
                                no_device=0
+                               no_proto_task=0
                                available=0
                                renew_handler=0
 
                                available=0
                                renew_handler=0
 
@@ -373,6 +374,7 @@ init_proto() {
                                eval "proto_$1_init_config"
                                json_close_array
                                json_add_boolean no-device "$no_device"
                                eval "proto_$1_init_config"
                                json_close_array
                                json_add_boolean no-device "$no_device"
+                               json_add_boolean no-proto-task "$no_proto_task"
                                json_add_boolean available "$available"
                                json_add_boolean renew-handler "$renew_handler"
                                json_add_boolean lasterror "$lasterror"
                                json_add_boolean available "$available"
                                json_add_boolean renew-handler "$renew_handler"
                                json_add_boolean lasterror "$lasterror"