From b0b11b2295fbb8399949139d82156e123e005902 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Sat, 19 May 2012 23:21:54 +0200 Subject: [PATCH] move dns server/search list parsing to interface core to support peerdns=0 + static entries --- config/network | 1 + interface-ip.c | 6 ++++-- interface.c | 29 +++++++++++++++++++++++++++-- proto-shell.c | 10 ++++++++++ proto.c | 17 ----------------- utils.c | 11 +++++++++++ utils.h | 1 + 7 files changed, 54 insertions(+), 21 deletions(-) diff --git a/config/network b/config/network index 17c7f98..0fa7af4 100644 --- a/config/network +++ b/config/network @@ -51,6 +51,7 @@ config interface pptp option proto pptp option server 1.1.1.1 option peerdns 0 + option dns 192.168.10.1 config route option target 192.168.0.1 diff --git a/interface-ip.c b/interface-ip.c index 1a22980..3b545ca 100644 --- a/interface-ip.c +++ b/interface-ip.c @@ -544,8 +544,10 @@ void interface_ip_set_enabled(struct interface_ip_settings *ip, bool enabled) void interface_ip_update_start(struct interface_ip_settings *ip) { - vlist_simple_update(&ip->dns_servers); - vlist_simple_update(&ip->dns_search); + if (ip != &ip->iface->config_ip) { + vlist_simple_update(&ip->dns_servers); + vlist_simple_update(&ip->dns_search); + } vlist_update(&ip->route); vlist_update(&ip->addr); } diff --git a/interface.c b/interface.c index b97f4ce..edf9b27 100644 --- a/interface.c +++ b/interface.c @@ -33,6 +33,8 @@ enum { IFACE_ATTR_AUTO, IFACE_ATTR_DEFAULTROUTE, IFACE_ATTR_PEERDNS, + IFACE_ATTR_DNS, + IFACE_ATTR_DNS_SEARCH, IFACE_ATTR_METRIC, IFACE_ATTR_MAX }; @@ -44,11 +46,18 @@ static const struct blobmsg_policy iface_attrs[IFACE_ATTR_MAX] = { [IFACE_ATTR_DEFAULTROUTE] = { .name = "defaultroute", .type = BLOBMSG_TYPE_BOOL }, [IFACE_ATTR_PEERDNS] = { .name = "peerdns", .type = BLOBMSG_TYPE_BOOL }, [IFACE_ATTR_METRIC] = { .name = "metric", .type = BLOBMSG_TYPE_INT32 }, + [IFACE_ATTR_DNS] = { .name = "dns", .type = BLOBMSG_TYPE_ARRAY }, + [IFACE_ATTR_DNS_SEARCH] = { .name = "dns_search", .type = BLOBMSG_TYPE_ARRAY }, +}; + +static const union config_param_info iface_attr_info[IFACE_ATTR_MAX] = { + [IFACE_ATTR_DNS] = { .type = BLOBMSG_TYPE_STRING }, }; const struct config_param_list interface_attr_list = { .n_params = IFACE_ATTR_MAX, .params = iface_attrs, + .info = iface_attr_info, }; static void @@ -395,6 +404,12 @@ interface_init(struct interface *iface, const char *name, iface->proto_ip.no_dns = !blobmsg_get_bool_default(tb[IFACE_ATTR_PEERDNS], true); + if ((cur = tb[IFACE_ATTR_DNS])) + interface_add_dns_server_list(&iface->config_ip, cur); + + if ((cur = tb[IFACE_ATTR_DNS_SEARCH])) + interface_add_dns_search_list(&iface->config_ip, cur); + iface->config_autostart = iface->autostart; } @@ -575,6 +590,13 @@ interface_update_complete(struct interface *iface) } static void +interface_replace_dns(struct interface_ip_settings *old, struct interface_ip_settings *new) +{ + vlist_simple_replace(&new->dns_servers, &old->dns_servers); + vlist_simple_replace(&new->dns_search, &old->dns_search); +} + +static void interface_change_config(struct interface *if_old, struct interface *if_new) { struct blob_attr *old_config = if_old->config; @@ -620,8 +642,11 @@ interface_change_config(struct interface *if_old, struct interface *if_new) interface_ip_set_enabled(&if_old->proto_ip, false); interface_ip_set_enabled(&if_old->proto_ip, if_new->proto_ip.enabled); } - if (UPDATE(proto_ip.no_dns)) - interface_write_resolv_conf(); + + UPDATE(proto_ip.no_dns); + interface_replace_dns(&if_old->config_ip, &if_new->config_ip); + interface_replace_dns(&if_old->proto_ip, &if_new->proto_ip); + interface_write_resolv_conf(); #undef UPDATE diff --git a/proto-shell.c b/proto-shell.c index 5309a55..2317209 100644 --- a/proto-shell.c +++ b/proto-shell.c @@ -381,6 +381,8 @@ enum { NOTIFY_DATA, NOTIFY_KEEP, NOTIFY_HOST, + NOTIFY_DNS, + NOTIFY_DNS_SEARCH, __NOTIFY_LAST }; @@ -400,6 +402,8 @@ static const struct blobmsg_policy notify_attr[__NOTIFY_LAST] = { [NOTIFY_DATA] = { .name = "data", .type = BLOBMSG_TYPE_TABLE }, [NOTIFY_KEEP] = { .name = "keep", .type = BLOBMSG_TYPE_BOOL }, [NOTIFY_HOST] = { .name = "host", .type = BLOBMSG_TYPE_STRING }, + [NOTIFY_DNS] = { .name = "dns", .type = BLOBMSG_TYPE_ARRAY }, + [NOTIFY_DNS_SEARCH] = { .name = "dns_search", .type = BLOBMSG_TYPE_ARRAY }, }; static int @@ -464,6 +468,12 @@ 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])) + interface_add_dns_server_list(&iface->proto_ip, cur); + + if ((cur = tb[NOTIFY_DNS_SEARCH])) + interface_add_dns_search_list(&iface->proto_ip, cur); + interface_update_complete(state->proto.iface); if (!keep) diff --git a/proto.c b/proto.c index 8266e81..c3bd19d 100644 --- a/proto.c +++ b/proto.c @@ -32,8 +32,6 @@ enum { OPT_BROADCAST, OPT_GATEWAY, OPT_IP6GW, - OPT_DNS, - OPT_DNS_SEARCH, __OPT_MAX, }; @@ -44,14 +42,11 @@ static const struct blobmsg_policy proto_ip_attributes[__OPT_MAX] = { [OPT_BROADCAST] = { .name = "broadcast", .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 }, - [OPT_DNS_SEARCH] = { .name = "dns_search", .type = BLOBMSG_TYPE_ARRAY }, }; static const union config_param_info proto_ip_attr_info[__OPT_MAX] = { [OPT_IPADDR] = { .type = BLOBMSG_TYPE_STRING }, [OPT_IP6ADDR] = { .type = BLOBMSG_TYPE_STRING }, - [OPT_DNS] = { .type = BLOBMSG_TYPE_STRING }, }; const struct config_param_list proto_ip_attr = { @@ -339,12 +334,6 @@ proto_apply_static_ip_settings(struct interface *iface, struct blob_attr *attr) goto out; } - if ((cur = tb[OPT_DNS])) - interface_add_dns_server_list(&iface->proto_ip, cur); - - if ((cur = tb[OPT_DNS_SEARCH])) - interface_add_dns_search_list(&iface->proto_ip, cur); - return 0; error: @@ -387,12 +376,6 @@ proto_apply_ip_settings(struct interface *iface, struct blob_attr *attr, bool ex goto out; } - if ((cur = tb[OPT_DNS])) - interface_add_dns_server_list(&iface->proto_ip, cur); - - if ((cur = tb[OPT_DNS_SEARCH])) - interface_add_dns_search_list(&iface->proto_ip, cur); - return 0; error: diff --git a/utils.c b/utils.c index 156b025..f1143c5 100644 --- a/utils.c +++ b/utils.c @@ -119,6 +119,17 @@ vlist_simple_flush(struct vlist_simple_tree *tree) } void +vlist_simple_replace(struct vlist_simple_tree *dest, struct vlist_simple_tree *old) +{ + struct vlist_simple_node *n, *tmp; + + list_for_each_entry_safe(n, tmp, &old->list, list) { + list_del(&n->list); + vlist_simple_add(dest, n); + } +} + +void vlist_simple_flush_all(struct vlist_simple_tree *tree) { tree->version = -1; diff --git a/utils.h b/utils.h index 893d3d3..5b6c5e7 100644 --- a/utils.h +++ b/utils.h @@ -98,6 +98,7 @@ void __vlist_simple_init(struct vlist_simple_tree *tree, int offset); void vlist_simple_delete(struct vlist_simple_tree *tree, struct vlist_simple_node *node); void vlist_simple_flush(struct vlist_simple_tree *tree); void vlist_simple_flush_all(struct vlist_simple_tree *tree); +void vlist_simple_replace(struct vlist_simple_tree *dest, struct vlist_simple_tree *old); static inline void vlist_simple_update(struct vlist_simple_tree *tree) { -- 2.11.0