proto-shell: add dns search domains
authorFelix Fietkau <nbd@openwrt.org>
Thu, 13 Oct 2011 22:47:17 +0000 (00:47 +0200)
committerFelix Fietkau <nbd@openwrt.org>
Thu, 13 Oct 2011 22:47:17 +0000 (00:47 +0200)
dummy/netifd-proto.sh
interface-ip.c
interface-ip.h
proto-shell.c

index 0af99b2..0f703a2 100755 (executable)
@@ -59,6 +59,12 @@ proto_add_dns_server() {
        jshn_append PROTO_DNS "$address"
 }
 
+proto_add_dns_search() {
+       local address="$1"
+
+       jshn_append PROTO_DNS_SEARCH "$address"
+}
+
 proto_add_ipv4_address() {
        local address="$1"
        local mask="$2"
@@ -133,6 +139,7 @@ proto_send_update() {
        _proto_push_array "route" "$PROTO_ROUTE" _proto_push_route
        _proto_push_array "route6" "$PROTO_ROUTE6" _proto_push_route
        _proto_push_array "dns" "$PROTO_DNS" _proto_push_ip
+       _proto_push_array "dns_search" "$PROTO_DNS_SEARCH" _proto_push_ip
        _proto_notify "$interface"
 }
 
index 28c608a..a5efad5 100644 (file)
@@ -119,6 +119,38 @@ interface_add_dns_server_list(struct interface *iface, struct blob_attr *list)
        }
 }
 
+void
+interface_add_dns_search_domain(struct interface *iface, const char *str)
+{
+       struct dns_search_domain *s;
+       int len = strlen(str);
+
+       s = calloc(1, sizeof(*s) + len + 1);
+       if (!s)
+               return;
+
+       D(INTERFACE, "Add DNS search domain: %s\n", str);
+       memcpy(s->name, str, len);
+       list_add_tail(&s->list, &iface->proto_dns_search);
+}
+
+void
+interface_add_dns_search_list(struct interface *iface, struct blob_attr *list)
+{
+       struct blob_attr *cur;
+       int rem;
+
+       blobmsg_for_each_attr(cur, list, rem) {
+               if (blobmsg_type(cur) != BLOBMSG_TYPE_STRING)
+                       continue;
+
+               if (!blobmsg_check_attr(cur, NULL))
+                       continue;
+
+               interface_add_dns_server(iface, blobmsg_data(cur));
+       }
+}
+
 static void
 interface_clear_dns_servers(struct interface *iface)
 {
index 6049d14..6ad9b42 100644 (file)
@@ -57,6 +57,7 @@ struct dns_search_domain {
 void interface_ip_init(struct interface *iface);
 void interface_add_dns_server(struct interface *iface, const char *str);
 void interface_add_dns_server_list(struct interface *iface, struct blob_attr *list);
+void interface_add_dns_search_list(struct interface *iface, struct blob_attr *list);
 void interface_clear_dns(struct interface *iface);
 void interface_write_resolv_conf(void);
 
index c90f65c..127a79d 100644 (file)
@@ -318,6 +318,7 @@ enum {
        NOTIFY_ROUTES,
        NOTIFY_ROUTES6,
        NOTIFY_DNS,
+       NOTIFY_DNS_SEARCH,
        __NOTIFY_LAST
 };
 
@@ -333,6 +334,7 @@ static const struct blobmsg_policy notify_attr[__NOTIFY_LAST] = {
        [NOTIFY_ROUTES] = { .name = "routes", .type = BLOBMSG_TYPE_ARRAY },
        [NOTIFY_ROUTES6] = { .name = "routes6", .type = BLOBMSG_TYPE_ARRAY },
        [NOTIFY_DNS] = { .name = "dns", .type = BLOBMSG_TYPE_ARRAY },
+       [NOTIFY_DNS_SEARCH] = { .name = "dns_search", .type = BLOBMSG_TYPE_ARRAY },
 };
 
 static int
@@ -381,6 +383,9 @@ proto_shell_update_link(struct proto_shell_state *state, struct blob_attr **tb)
        if ((cur = tb[NOTIFY_DNS]) != NULL)
                interface_add_dns_server_list(state->proto.iface, cur);
 
+       if ((cur = tb[NOTIFY_DNS_SEARCH]) != NULL)
+               interface_add_dns_search_list(state->proto.iface, cur);
+
        interface_ip_update_complete(state->proto.iface);
 
        state->proto.proto_event(&state->proto, IFPEV_UP);