From 52c36d741c05db2350ad1d240f6bd5d72237d8fd Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Fri, 14 Oct 2011 00:47:17 +0200 Subject: [PATCH] proto-shell: add dns search domains --- dummy/netifd-proto.sh | 7 +++++++ interface-ip.c | 32 ++++++++++++++++++++++++++++++++ interface-ip.h | 1 + proto-shell.c | 5 +++++ 4 files changed, 45 insertions(+) diff --git a/dummy/netifd-proto.sh b/dummy/netifd-proto.sh index 0af99b2..0f703a2 100755 --- a/dummy/netifd-proto.sh +++ b/dummy/netifd-proto.sh @@ -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" } diff --git a/interface-ip.c b/interface-ip.c index 28c608a..a5efad5 100644 --- a/interface-ip.c +++ b/interface-ip.c @@ -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) { diff --git a/interface-ip.h b/interface-ip.h index 6049d14..6ad9b42 100644 --- a/interface-ip.h +++ b/interface-ip.h @@ -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); diff --git a/proto-shell.c b/proto-shell.c index c90f65c..127a79d 100644 --- a/proto-shell.c +++ b/proto-shell.c @@ -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); -- 2.11.0