proto-shell: add dns server support
[project/netifd.git] / proto-shell.c
index ee2366f..3ed4b8e 100644 (file)
@@ -43,15 +43,22 @@ struct proto_shell_state {
        struct uloop_process proto_task;
 };
 
+static void
+kill_process(struct uloop_process *proc)
+{
+       if (!proc->pending)
+               return;
+
+       kill(proc->pid, SIGTERM);
+       uloop_process_delete(proc);
+}
+
 static int
 start_process(const char **argv, struct uloop_process *proc)
 {
        int pid;
 
-       if (proc->pending) {
-               kill(proc->pid, SIGTERM);
-               uloop_process_delete(proc);
-       }
+       kill_process(proc);
 
        if ((pid = fork()) < 0)
                return -1;
@@ -148,6 +155,8 @@ proto_shell_teardown_cb(struct uloop_process *p, int ret)
 
        state = container_of(p, struct proto_shell_state, teardown_task);
 
+       kill_process(&state->proto_task);
+
        if (state->l3_dev.dev)
                device_remove_user(&state->l3_dev);
 
@@ -160,6 +169,8 @@ proto_shell_task_cb(struct uloop_process *p, int ret)
        struct proto_shell_state *state;
 
        state = container_of(p, struct proto_shell_state, proto_task);
+       if (state->teardown_pending || state->teardown_task.pending)
+               return;
 
        state->proto.proto_event(&state->proto, IFPEV_LINK_LOST);
        proto_shell_handler(&state->proto, PROTO_CMD_TEARDOWN, false);
@@ -292,6 +303,7 @@ enum {
        NOTIFY_IP6ADDR,
        NOTIFY_ROUTES,
        NOTIFY_ROUTES6,
+       NOTIFY_DNS,
        __NOTIFY_LAST
 };
 
@@ -305,6 +317,7 @@ static const struct blobmsg_policy notify_attr[__NOTIFY_LAST] = {
        [NOTIFY_IP6ADDR] = { .name = "ip6addr", .type = BLOBMSG_TYPE_ARRAY },
        [NOTIFY_ROUTES] = { .name = "routes", .type = BLOBMSG_TYPE_ARRAY },
        [NOTIFY_ROUTES6] = { .name = "routes6", .type = BLOBMSG_TYPE_ARRAY },
+       [NOTIFY_DNS] = { .name = "dns", .type = BLOBMSG_TYPE_ARRAY },
 };
 
 static int
@@ -348,6 +361,9 @@ proto_shell_update_link(struct proto_shell_state *state, struct blob_attr **tb)
        if ((cur = tb[NOTIFY_ROUTES6]) != NULL)
                proto_shell_parse_route_list(state->proto.iface, cur, true);
 
+       if ((cur = tb[NOTIFY_DNS]) != NULL)
+               interface_add_dns_server_list(state->proto.iface, cur);
+
        return 0;
 }