proto-shell: handle the "available" config flag
authorFelix Fietkau <nbd@openwrt.org>
Thu, 27 Oct 2011 19:09:47 +0000 (21:09 +0200)
committerFelix Fietkau <nbd@openwrt.org>
Thu, 27 Oct 2011 19:09:47 +0000 (21:09 +0200)
interface.c
proto-shell.c
proto.h

index a8f7b8f..787d7d9 100644 (file)
@@ -184,6 +184,8 @@ interface_claim_device(struct interface *iface)
                if (dev)
                        device_add_user(&iface->main_dev, dev);
        }
                if (dev)
                        device_add_user(&iface->main_dev, dev);
        }
+       if (iface->proto_handler->flags & PROTO_FLAG_INIT_AVAILABLE)
+               interface_set_available(iface, true);
 }
 
 
 }
 
 
@@ -517,8 +519,8 @@ interface_update(struct vlist_tree *tree, struct vlist_node *node_new,
                set_config_state(if_old, IFC_REMOVE);
        } else if (node_new) {
                D(INTERFACE, "Create interface '%s'\n", if_new->name);
                set_config_state(if_old, IFC_REMOVE);
        } else if (node_new) {
                D(INTERFACE, "Create interface '%s'\n", if_new->name);
-               interface_claim_device(if_new);
                proto_init_interface(if_new, if_new->config);
                proto_init_interface(if_new, if_new->config);
+               interface_claim_device(if_new);
                netifd_ubus_add_interface(if_new);
        }
 }
                netifd_ubus_add_interface(if_new);
        }
 }
index b40b456..51a6dac 100644 (file)
@@ -25,6 +25,7 @@ struct proto_shell_handler {
        struct proto_handler proto;
        struct config_param_list config;
        char *config_buf;
        struct proto_handler proto;
        struct config_param_list config;
        char *config_buf;
+       bool init_available;
        char script_name[];
 };
 
        char script_name[];
 };
 
@@ -615,6 +616,10 @@ proto_shell_add_handler(const char *script, 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 = get_field(obj, "available", json_type_boolean);
+       if (tmp && json_object_get_boolean(tmp))
+               handler->proto.flags |= PROTO_FLAG_INIT_AVAILABLE;
+
        config = get_field(obj, "config", json_type_array);
        if (config)
                handler->config_buf = proto_shell_parse_config(&handler->config, config);
        config = get_field(obj, "config", json_type_array);
        if (config)
                handler->config_buf = proto_shell_parse_config(&handler->config, config);
diff --git a/proto.h b/proto.h
index 57426bd..c401d6f 100644 (file)
--- a/proto.h
+++ b/proto.h
@@ -19,6 +19,7 @@ enum interface_proto_cmd {
 enum {
        PROTO_FLAG_IMMEDIATE = (1 << 0),
        PROTO_FLAG_NODEV = (1 << 1),
 enum {
        PROTO_FLAG_IMMEDIATE = (1 << 0),
        PROTO_FLAG_NODEV = (1 << 1),
+       PROTO_FLAG_INIT_AVAILABLE = (1 << 2),
 };
 
 struct interface_proto_state {
 };
 
 struct interface_proto_state {