X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fnetifd.git;a=blobdiff_plain;f=proto-shell.c;h=4cff09134f3a610077cd1e3cc88774f039b99b8c;hp=f0738a98b5191a6fb220f9eafb7866e08f41d942;hb=8a1a1dda9cfff45a7cd48f5d108d0174fadd84ee;hpb=f365db4c75b7e824eb785be487b0afc18a45ef7f diff --git a/proto-shell.c b/proto-shell.c index f0738a9..4cff091 100644 --- a/proto-shell.c +++ b/proto-shell.c @@ -41,8 +41,6 @@ struct proto_shell_state { struct proto_shell_handler *handler; struct blob_attr *config; - struct device_user l3_dev; - struct uloop_timeout teardown_timeout; struct netifd_process script_task; @@ -201,6 +199,8 @@ proto_shell_free(struct interface_proto_state *proto) struct proto_shell_state *state; state = container_of(proto, struct proto_shell_state, proto); + netifd_kill_process(&state->script_task); + netifd_kill_process(&state->proto_task); free(state->config); free(state); } @@ -222,6 +222,31 @@ proto_shell_parse_route_list(struct interface *iface, struct blob_attr *attr, } } +static void +proto_shell_parse_data(struct interface *iface, struct blob_attr *attr) +{ + struct blob_attr *cur; + int rem; + + blobmsg_for_each_attr(cur, attr, rem) + interface_add_data(iface, cur); +} + +static struct device * +proto_shell_create_tunnel(const char *name, struct blob_attr *attr) +{ + struct device *dev; + struct blob_buf b; + + memset(&b, 0, sizeof(b)); + blob_buf_init(&b, 0); + blob_put(&b, 0, blobmsg_data(attr), blobmsg_data_len(attr)); + dev = device_create(name, &tunnel_device_type, blob_data(b.head)); + blob_buf_free(&b); + + return dev; +} + enum { NOTIFY_ACTION, NOTIFY_ERROR, @@ -234,7 +259,8 @@ enum { NOTIFY_ADDR_EXT, NOTIFY_ROUTES, NOTIFY_ROUTES6, - NOTIFY_DNS_SEARCH, + NOTIFY_TUNNEL, + NOTIFY_DATA, __NOTIFY_LAST }; @@ -250,15 +276,17 @@ static const struct blobmsg_policy notify_attr[__NOTIFY_LAST] = { [NOTIFY_ADDR_EXT] = { .name = "address-external", .type = BLOBMSG_TYPE_BOOL }, [NOTIFY_ROUTES] = { .name = "routes", .type = BLOBMSG_TYPE_ARRAY }, [NOTIFY_ROUTES6] = { .name = "routes6", .type = BLOBMSG_TYPE_ARRAY }, - [NOTIFY_DNS_SEARCH] = { .name = "dns_search", .type = BLOBMSG_TYPE_ARRAY }, + [NOTIFY_TUNNEL] = { .name = "tunnel", .type = BLOBMSG_TYPE_TABLE }, + [NOTIFY_DATA] = { .name = "data", .type = BLOBMSG_TYPE_TABLE }, }; static int proto_shell_update_link(struct proto_shell_state *state, struct blob_attr *data, struct blob_attr **tb) { - struct interface_ip_settings *ip; struct interface *iface = state->proto.iface; struct blob_attr *cur; + struct device *dev; + const char *devname; int dev_create = 1; bool addr_ext = false; bool up; @@ -282,16 +310,22 @@ proto_shell_update_link(struct proto_shell_state *state, struct blob_attr *data, if (!iface->main_dev.dev) return UBUS_STATUS_INVALID_ARGUMENT; } else { - if (state->l3_dev.dev) - device_remove_user(&state->l3_dev); + devname = blobmsg_data(tb[NOTIFY_IFNAME]); + if (tb[NOTIFY_TUNNEL]) { + dev = proto_shell_create_tunnel(devname, + tb[NOTIFY_TUNNEL]); + if (!dev) + return UBUS_STATUS_INVALID_ARGUMENT; + } else { + dev = device_get(devname, dev_create); + if (!dev) + return UBUS_STATUS_NOT_FOUND; + } - device_add_user(&state->l3_dev, - device_get(blobmsg_data(tb[NOTIFY_IFNAME]), dev_create)); - iface->l3_dev = &state->l3_dev; - device_claim(&state->l3_dev); + interface_set_l3_dev(iface, dev); + device_claim(&iface->l3_dev); } - ip = &iface->proto_ip; interface_update_start(iface); proto_apply_ip_settings(iface, data, addr_ext); @@ -301,12 +335,13 @@ 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_DNS_SEARCH]) != NULL) - interface_add_dns_search_list(ip, cur); - interface_update_complete(state->proto.iface); state->proto.proto_event(&state->proto, IFPEV_UP); + state->sm = S_IDLE; + + if ((cur = tb[NOTIFY_DATA])) + proto_shell_parse_data(state->proto.iface, cur); return 0; }