From 5e5cd11724f6cf86edc5796e6b805573c767f757 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Thu, 13 Oct 2011 14:58:51 +0200 Subject: [PATCH] add functions for adding dns servers to the proto list, hook them up in proto-static.c --- config/network | 1 + interface-ip.c | 38 ++++++++++++++++++++++++++++++++++++++ interface-ip.h | 2 ++ proto-static.c | 6 ++++++ 4 files changed, 47 insertions(+) diff --git a/config/network b/config/network index 6e9d7a6..e39164a 100644 --- a/config/network +++ b/config/network @@ -33,6 +33,7 @@ config interface lan2 option ipaddr 192.168.1.1 option netmask 255.255.255.0 option gateway 192.168.1.2 + option dns '192.168.1.5 192.168.1.6' config interface wan option proto pppoe diff --git a/interface-ip.c b/interface-ip.c index d2e1461..c0a1bb9 100644 --- a/interface-ip.c +++ b/interface-ip.c @@ -79,6 +79,44 @@ interface_update_proto_route(struct vlist_tree *tree, } } +void +interface_add_dns_server(struct interface *iface, const char *str) +{ + struct dns_server *s; + + s = calloc(1, sizeof(*s)); + s->af = AF_INET; + if (inet_pton(s->af, str, &s->addr.in)) + goto add; + + s->af = AF_INET6; + if (inet_pton(s->af, str, &s->addr.in)) + goto add; + + free(s); + return; + +add: + list_add_tail(&s->list, &iface->proto_dns_servers); +} + +void +interface_add_dns_server_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 23782ad..91703a1 100644 --- a/interface-ip.h +++ b/interface-ip.h @@ -55,6 +55,8 @@ 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_clear_dns(struct interface *iface); void interface_write_resolv_conf(void); diff --git a/proto-static.c b/proto-static.c index 17cff0a..f5d676a 100644 --- a/proto-static.c +++ b/proto-static.c @@ -17,6 +17,7 @@ enum { OPT_NETMASK, OPT_GATEWAY, OPT_IP6GW, + OPT_DNS, __OPT_MAX, }; @@ -26,11 +27,13 @@ static const struct blobmsg_policy static_attrs[__OPT_MAX] = { [OPT_NETMASK] = { .name = "netmask", .type = BLOBMSG_TYPE_STRING }, [OPT_GATEWAY] = { .name = "gateway", .type = BLOBMSG_TYPE_STRING }, [OPT_IP6GW] = { .name = "ip6gw", .type = BLOBMSG_TYPE_STRING }, + [OPT_DNS] = { .name = "dns", .type = BLOBMSG_TYPE_ARRAY }, }; static const union config_param_info static_attr_info[__OPT_MAX] = { [OPT_IPADDR] = { .type = BLOBMSG_TYPE_STRING }, [OPT_IP6ADDR] = { .type = BLOBMSG_TYPE_STRING }, + [OPT_DNS] = { .type = BLOBMSG_TYPE_STRING }, }; static const struct config_param_list static_attr_list = { @@ -140,6 +143,9 @@ proto_apply_static_settings(struct interface *iface, struct blob_attr *attr) goto out; } + if (tb[OPT_DNS]) + interface_add_dns_server_list(iface, tb[OPT_DNS]); + return 0; error: -- 2.30.2