bridge: add support for configuring extra vlans for the bridge itself
[project/netifd.git] / proto-shell.c
index 4391cdd0cd2ca6e2b4a8c42e5e8d2630600ecb88..bc3c41dcba85ac46cff02db88b9d3ee8e9fc2a57 100644 (file)
@@ -44,7 +44,6 @@ struct proto_shell_handler {
        char *config_buf;
        char *script_name;
        bool init_available;
-       bool no_proto_task;
 
        struct uci_blob_param_list config;
 };
@@ -130,7 +129,7 @@ proto_shell_update_host_dep(struct proto_shell_dependency *dep)
        }
 
        if (!dep->any)
-               iface = interface_ip_add_target_route(&dep->host, dep->v6, iface);
+               iface = interface_ip_add_target_route(&dep->host, dep->v6, iface, false);
 
        if (!iface)
                goto out;
@@ -182,11 +181,6 @@ proto_shell_handler(struct interface_proto_state *proto,
                        state->sm = S_SETUP;
                        break;
 
-               case S_SETUP_ABORT:
-               case S_TEARDOWN:
-               case S_SETUP:
-                       return 0;
-
                default:
                        return -1;
                }
@@ -213,7 +207,8 @@ proto_shell_handler(struct interface_proto_state *proto,
                                state->sm = S_SETUP_ABORT;
                                return 0;
                        }
-               /* fall through if no script task is running */
+               /* if no script task is running */
+               fallthrough;
                case S_IDLE:
                        action = "teardown";
                        state->renew_pending = false;
@@ -297,7 +292,7 @@ proto_shell_task_finish(struct proto_shell_state *state,
        case S_IDLE:
                if (task == &state->proto_task)
                        state->proto.proto_event(&state->proto, IFPEV_LINK_LOST);
-               /* fall through */
+               fallthrough;
        case S_SETUP:
                if (task == &state->proto_task)
                        proto_shell_handler(&state->proto, PROTO_CMD_TEARDOWN,
@@ -306,7 +301,7 @@ proto_shell_task_finish(struct proto_shell_state *state,
                        if (state->renew_pending)
                                proto_shell_handler(&state->proto,
                                                    PROTO_CMD_RENEW, false);
-                       else if (!state->handler->no_proto_task &&
+                       else if (!(state->handler->proto.flags & PROTO_FLAG_NO_TASK) &&
                                 !state->proto_task.uloop.pending &&
                                 state->sm == S_SETUP)
                                proto_shell_handler(&state->proto,
@@ -406,7 +401,7 @@ proto_shell_parse_route_list(struct interface *iface, struct blob_attr *attr,
                             bool v6)
 {
        struct blob_attr *cur;
-       int rem;
+       size_t rem;
 
        blobmsg_for_each_attr(cur, attr, rem) {
                if (blobmsg_type(cur) != BLOBMSG_TYPE_TABLE) {
@@ -418,11 +413,28 @@ proto_shell_parse_route_list(struct interface *iface, struct blob_attr *attr,
        }
 }
 
+static void
+proto_shell_parse_neighbor_list(struct interface *iface, struct blob_attr *attr,
+                               bool v6)
+{
+       struct blob_attr *cur;
+       size_t rem;
+
+       blobmsg_for_each_attr(cur, attr, rem) {
+               if (blobmsg_type(cur) != BLOBMSG_TYPE_TABLE) {
+                       DPRINTF("Ignore wrong neighbor type: %d\n", blobmsg_type(cur));
+                       continue;
+               }
+
+               interface_ip_add_neighbor(iface, cur, v6);
+       }
+}
+
 static void
 proto_shell_parse_data(struct interface *iface, struct blob_attr *attr)
 {
        struct blob_attr *cur;
-       int rem;
+       size_t rem;
 
        blobmsg_for_each_attr(cur, attr, rem)
                interface_add_data(iface, cur);
@@ -461,6 +473,8 @@ enum {
        NOTIFY_HOST,
        NOTIFY_DNS,
        NOTIFY_DNS_SEARCH,
+       NOTIFY_NEIGHBORS,
+       NOTIFY_NEIGHBORS6,
        __NOTIFY_LAST
 };
 
@@ -482,6 +496,8 @@ static const struct blobmsg_policy notify_attr[__NOTIFY_LAST] = {
        [NOTIFY_HOST] = { .name = "host", .type = BLOBMSG_TYPE_STRING },
        [NOTIFY_DNS] = { .name = "dns", .type = BLOBMSG_TYPE_ARRAY },
        [NOTIFY_DNS_SEARCH] = { .name = "dns_search", .type = BLOBMSG_TYPE_ARRAY },
+       [NOTIFY_NEIGHBORS]= {.name = "neighbor", .type = BLOBMSG_TYPE_ARRAY},
+       [NOTIFY_NEIGHBORS6]= {.name = "neighbor6", .type = BLOBMSG_TYPE_ARRAY},
 };
 
 static int
@@ -539,10 +555,10 @@ proto_shell_update_link(struct proto_shell_state *state, struct blob_attr *data,
                        return UBUS_STATUS_UNKNOWN_ERROR;
 
                device_set_present(dev, true);
-
-               interface_update_start(iface);
        }
 
+       interface_update_start(iface, keep);
+
        proto_apply_ip_settings(iface, data, addr_ext);
 
        if ((cur = tb[NOTIFY_ROUTES]) != NULL)
@@ -551,6 +567,12 @@ proto_shell_update_link(struct proto_shell_state *state, struct blob_attr *data,
        if ((cur = tb[NOTIFY_ROUTES6]) != NULL)
                proto_shell_parse_route_list(state->proto.iface, cur, true);
 
+       if ((cur = tb[NOTIFY_NEIGHBORS]) != NULL)
+               proto_shell_parse_neighbor_list(state->proto.iface, cur, false);
+
+       if ((cur = tb[NOTIFY_NEIGHBORS6]) != NULL)
+               proto_shell_parse_neighbor_list(state->proto.iface, cur, true);
+
        if ((cur = tb[NOTIFY_DNS]))
                interface_add_dns_server_list(&iface->proto_ip, cur);
 
@@ -563,8 +585,7 @@ proto_shell_update_link(struct proto_shell_state *state, struct blob_attr *data,
        interface_update_complete(state->proto.iface);
 
        if ((state->sm != S_SETUP_ABORT) && (state->sm != S_TEARDOWN)) {
-               if (!keep)
-                       state->proto.proto_event(&state->proto, IFPEV_UP);
+               state->proto.proto_event(&state->proto, IFPEV_UP);
                state->sm = S_IDLE;
        }
 
@@ -576,7 +597,7 @@ fill_string_list(struct blob_attr *attr, char **argv, int max)
 {
        struct blob_attr *cur;
        int argc = 0;
-       int rem;
+       size_t rem;
 
        if (!attr)
                goto out;
@@ -585,7 +606,7 @@ fill_string_list(struct blob_attr *attr, char **argv, int max)
                if (blobmsg_type(cur) != BLOBMSG_TYPE_STRING)
                        return false;
 
-               if (!blobmsg_check_attr(cur, NULL))
+               if (!blobmsg_check_attr(cur, false))
                        return false;
 
                argv[argc++] = blobmsg_data(cur);
@@ -650,7 +671,7 @@ proto_shell_notify_error(struct proto_shell_state *state, struct blob_attr **tb)
        struct blob_attr *cur;
        char *data[16];
        int n_data = 0;
-       int rem;
+       size_t rem;
 
        if (!tb[NOTIFY_ERROR])
                return UBUS_STATUS_INVALID_ARGUMENT;
@@ -662,7 +683,7 @@ proto_shell_notify_error(struct proto_shell_state *state, struct blob_attr **tb)
                if (blobmsg_type(cur) != BLOBMSG_TYPE_STRING)
                        goto error;
 
-               if (!blobmsg_check_attr(cur, NULL))
+               if (!blobmsg_check_attr(cur, false))
                        goto error;
 
                data[n_data++] = blobmsg_data(cur);
@@ -743,7 +764,7 @@ proto_shell_setup_failed(struct proto_shell_state *state)
        switch (state->sm) {
        case S_IDLE:
                state->proto.proto_event(&state->proto, IFPEV_LINK_LOST);
-               /* fall through */
+               fallthrough;
        case S_SETUP:
                proto_shell_handler(&state->proto, PROTO_CMD_TEARDOWN, false);
                break;
@@ -892,7 +913,8 @@ proto_shell_add_handler(const char *script, const char *name, json_object *obj)
                handler->proto.flags |= PROTO_FLAG_NODEV;
 
        tmp = json_get_field(obj, "no-proto-task", json_type_boolean);
-       handler->no_proto_task = tmp && json_object_get_boolean(tmp);
+       if (tmp && json_object_get_boolean(tmp))
+               handler->proto.flags |= PROTO_FLAG_NO_TASK;
 
        tmp = json_get_field(obj, "available", json_type_boolean);
        if (tmp && json_object_get_boolean(tmp))