summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2014-07-23 23:10:00 +0200
committerTom Gundersen <teg@jklm.no>2014-07-23 23:54:52 +0200
commit6073b6f26ab9fc6bf335faa7073ec443eef093fd (patch)
treed851475cf1dc89b22f454d1577dd976196b4ef88
parentb0e39c8284b5195850a58e4efcce2f059bdcc6ad (diff)
resolved: don't read DHCP leases
networkd will expose both statically configured DNS servers and servers receieved over DHCP in sd_network_get_dns(), so no need to keep the distinction in resolved.
-rw-r--r--src/resolve/resolved-dns-server.c25
-rw-r--r--src/resolve/resolved-dns-server.h2
-rw-r--r--src/resolve/resolved-link.c57
-rw-r--r--src/resolve/resolved-link.h5
-rw-r--r--src/resolve/resolved-manager.c12
5 files changed, 30 insertions, 71 deletions
diff --git a/src/resolve/resolved-dns-server.c b/src/resolve/resolved-dns-server.c
index 734441bccd..f33cf5d961 100644
--- a/src/resolve/resolved-dns-server.c
+++ b/src/resolve/resolved-dns-server.c
@@ -24,7 +24,6 @@
int dns_server_new(
Manager *m,
DnsServer **ret,
- DnsServerSource source,
Link *l,
int family,
const union in_addr_union *in_addr) {
@@ -33,30 +32,23 @@ int dns_server_new(
assert(m);
assert(in_addr);
- assert(source < _DNS_SERVER_SOURCE_MAX);
s = new0(DnsServer, 1);
if (!s)
return -ENOMEM;
- s->source = source;
s->family = family;
s->address = *in_addr;
- if (source == DNS_SERVER_LINK) {
- assert(l);
- LIST_FIND_TAIL(servers, l->link_dns_servers, tail);
- LIST_INSERT_AFTER(servers, l->link_dns_servers, tail, s);
- s->link = l;
- } else if (source == DNS_SERVER_DHCP) {
- assert(l);
- LIST_FIND_TAIL(servers, l->dhcp_dns_servers, tail);
- LIST_INSERT_AFTER(servers, l->dhcp_dns_servers, tail, s);
+ if (l) {
+ LIST_FIND_TAIL(servers, l->dns_servers, tail);
+ LIST_INSERT_AFTER(servers, l->dns_servers, tail, s);
s->link = l;
+ s->source = DNS_SERVER_LINK;
} else {
- assert(!l);
LIST_FIND_TAIL(servers, m->dns_servers, tail);
LIST_INSERT_AFTER(servers, m->dns_servers, tail, s);
+ s->source = DNS_SERVER_SYSTEM;
}
s->manager = m;
@@ -74,12 +66,7 @@ DnsServer* dns_server_free(DnsServer *s) {
if (s->source == DNS_SERVER_LINK) {
if (s->link)
- LIST_REMOVE(servers, s->link->link_dns_servers, s);
- } else if (s->source == DNS_SERVER_DHCP) {
-
- if (s->link)
- LIST_REMOVE(servers, s->link->dhcp_dns_servers, s);
-
+ LIST_REMOVE(servers, s->link->dns_servers, s);
} else if (s->source == DNS_SERVER_SYSTEM) {
if (s->manager)
diff --git a/src/resolve/resolved-dns-server.h b/src/resolve/resolved-dns-server.h
index 2b0b99649d..45a7c4ff3b 100644
--- a/src/resolve/resolved-dns-server.h
+++ b/src/resolve/resolved-dns-server.h
@@ -33,7 +33,6 @@ typedef enum DnsServerSource DnsServerSource;
enum DnsServerSource {
DNS_SERVER_SYSTEM,
DNS_SERVER_LINK,
- DNS_SERVER_DHCP,
_DNS_SERVER_SOURCE_MAX
};
@@ -54,7 +53,6 @@ struct DnsServer {
int dns_server_new(
Manager *m,
DnsServer **s,
- DnsServerSource source,
Link *l,
int family,
const union in_addr_union *address);
diff --git a/src/resolve/resolved-link.c b/src/resolve/resolved-link.c
index 43f60d8bb6..16f41a2604 100644
--- a/src/resolve/resolved-link.c
+++ b/src/resolve/resolved-link.c
@@ -22,7 +22,6 @@
#include <net/if.h>
#include "sd-network.h"
-#include "dhcp-lease-internal.h"
#include "strv.h"
#include "resolved-link.h"
@@ -71,11 +70,8 @@ Link *link_free(Link *l) {
dns_scope_free(l->llmnr_ipv4_scope);
dns_scope_free(l->llmnr_ipv6_scope);
- while (l->dhcp_dns_servers)
- dns_server_free(l->dhcp_dns_servers);
-
- while (l->link_dns_servers)
- dns_server_free(l->link_dns_servers);
+ while (l->dns_servers)
+ dns_server_free(l->dns_servers);
free(l);
return NULL;
@@ -86,7 +82,7 @@ static void link_allocate_scopes(Link *l) {
assert(l);
- if (l->link_dns_servers || l->dhcp_dns_servers) {
+ if (l->dns_servers) {
if (!l->unicast_scope) {
r = dns_scope_new(l->manager, &l->unicast_scope, l, DNS_PROTOCOL_DNS, AF_UNSPEC);
if (r < 0)
@@ -136,7 +132,7 @@ int link_update_rtnl(Link *l, sd_rtnl_message *m) {
return 0;
}
-static int link_update_link_dns_servers(Link *l) {
+static int link_update_dns_servers(Link *l) {
_cleanup_free_ struct in_addr *nameservers = NULL;
_cleanup_free_ struct in6_addr *nameservers6 = NULL;
DnsServer *s, *nx;
@@ -144,7 +140,7 @@ static int link_update_link_dns_servers(Link *l) {
assert(l);
- LIST_FOREACH(servers, s, l->link_dns_servers)
+ LIST_FOREACH(servers, s, l->dns_servers)
s->marked = true;
n = sd_network_get_dns(l->ifindex, &nameservers);
@@ -156,11 +152,11 @@ static int link_update_link_dns_servers(Link *l) {
for (i = 0; i < n; i++) {
union in_addr_union a = { .in = nameservers[i] };
- s = link_find_dns_server(l, DNS_SERVER_LINK, AF_INET, &a);
+ s = link_find_dns_server(l, AF_INET, &a);
if (s)
s->marked = false;
else {
- r = dns_server_new(l->manager, NULL, DNS_SERVER_LINK, l, AF_INET, &a);
+ r = dns_server_new(l->manager, NULL, l, AF_INET, &a);
if (r < 0)
goto clear;
}
@@ -175,25 +171,25 @@ static int link_update_link_dns_servers(Link *l) {
for (i = 0; i < n; i++) {
union in_addr_union a = { .in6 = nameservers6[i] };
- s = link_find_dns_server(l, DNS_SERVER_LINK, AF_INET6, &a);
+ s = link_find_dns_server(l, AF_INET6, &a);
if (s)
s->marked = false;
else {
- r = dns_server_new(l->manager, NULL, DNS_SERVER_LINK, l, AF_INET6, &a);
+ r = dns_server_new(l->manager, NULL, l, AF_INET6, &a);
if (r < 0)
goto clear;
}
}
- LIST_FOREACH_SAFE(servers, s, nx, l->link_dns_servers)
+ LIST_FOREACH_SAFE(servers, s, nx, l->dns_servers)
if (s->marked)
dns_server_free(s);
return 0;
clear:
- while (l->link_dns_servers)
- dns_server_free(l->link_dns_servers);
+ while (l->dns_servers)
+ dns_server_free(l->dns_servers);
return r;
}
@@ -201,7 +197,7 @@ clear:
int link_update_monitor(Link *l) {
assert(l);
- link_update_link_dns_servers(l);
+ link_update_dns_servers(l);
link_allocate_scopes(l);
return 0;
@@ -242,14 +238,12 @@ LinkAddress *link_find_address(Link *l, int family, union in_addr_union *in_addr
return NULL;
}
-DnsServer* link_find_dns_server(Link *l, DnsServerSource source, int family, union in_addr_union *in_addr) {
- DnsServer *first, *s;
+DnsServer* link_find_dns_server(Link *l, int family, union in_addr_union *in_addr) {
+ DnsServer *s;
assert(l);
- first = source == DNS_SERVER_DHCP ? l->dhcp_dns_servers : l->link_dns_servers;
-
- LIST_FOREACH(servers, s, first)
+ LIST_FOREACH(servers, s, l->dns_servers)
if (s->family == family && in_addr_equal(family, &s->address, in_addr))
return s;
@@ -260,9 +254,7 @@ DnsServer *link_get_dns_server(Link *l) {
assert(l);
if (!l->current_dns_server)
- l->current_dns_server = l->link_dns_servers;
- if (!l->current_dns_server)
- l->current_dns_server = l->dhcp_dns_servers;
+ l->current_dns_server = l->dns_servers;
return l->current_dns_server;
}
@@ -273,13 +265,7 @@ void link_next_dns_server(Link *l) {
/* Switch to the next DNS server */
if (!l->current_dns_server) {
- l->current_dns_server = l->link_dns_servers;
- if (l->current_dns_server)
- return;
- }
-
- if (!l->current_dns_server) {
- l->current_dns_server = l->dhcp_dns_servers;
+ l->current_dns_server = l->dns_servers;
if (l->current_dns_server)
return;
}
@@ -292,12 +278,7 @@ void link_next_dns_server(Link *l) {
return;
}
- if (l->current_dns_server->source == DNS_SERVER_LINK)
- l->current_dns_server = l->dhcp_dns_servers;
- else {
- assert(l->current_dns_server->source == DNS_SERVER_DHCP);
- l->current_dns_server = l->link_dns_servers;
- }
+ l->current_dns_server = l->dns_servers;
}
int link_address_new(Link *l, LinkAddress **ret, int family, union in_addr_union *in_addr) {
diff --git a/src/resolve/resolved-link.h b/src/resolve/resolved-link.h
index bd32a702fc..cef0400b21 100644
--- a/src/resolve/resolved-link.h
+++ b/src/resolve/resolved-link.h
@@ -52,8 +52,7 @@ struct Link {
LIST_HEAD(LinkAddress, addresses);
- LIST_HEAD(DnsServer, link_dns_servers);
- LIST_HEAD(DnsServer, dhcp_dns_servers);
+ LIST_HEAD(DnsServer, dns_servers);
DnsServer *current_dns_server;
DnsScope *unicast_scope;
@@ -74,7 +73,7 @@ int link_update_monitor(Link *l);
bool link_relevant(Link *l, int family);
LinkAddress* link_find_address(Link *l, int family, union in_addr_union *in_addr);
-DnsServer* link_find_dns_server(Link *l, DnsServerSource source, int family, union in_addr_union *in_addr);
+DnsServer* link_find_dns_server(Link *l, int family, union in_addr_union *in_addr);
DnsServer* link_get_dns_server(Link *l);
void link_next_dns_server(Link *l);
diff --git a/src/resolve/resolved-manager.c b/src/resolve/resolved-manager.c
index 19ea678de0..f4fa197d49 100644
--- a/src/resolve/resolved-manager.c
+++ b/src/resolve/resolved-manager.c
@@ -29,8 +29,6 @@
#include "rtnl-util.h"
#include "event-util.h"
#include "network-util.h"
-#include "sd-dhcp-lease.h"
-#include "dhcp-lease-internal.h"
#include "network-internal.h"
#include "conf-parser.h"
#include "socket-util.h"
@@ -326,7 +324,7 @@ static int parse_dns_server_string(Manager *m, const char *string) {
if (manager_find_dns_server(m, family, &addr))
continue;
- r = dns_server_new(m, NULL, DNS_SERVER_SYSTEM, NULL, family, &addr);
+ r = dns_server_new(m, NULL, NULL, family, &addr);
if (r < 0)
return r;
}
@@ -517,13 +515,9 @@ int manager_write_resolv_conf(Manager *m) {
"# resolv.conf(5) in a different way, replace the symlink by a\n"
"# static file or a different symlink.\n\n", f);
- HASHMAP_FOREACH(l, m->links, i) {
- LIST_FOREACH(servers, s, l->link_dns_servers)
- write_resolve_conf_server(s, f, &count);
-
- LIST_FOREACH(servers, s, l->dhcp_dns_servers)
+ HASHMAP_FOREACH(l, m->links, i)
+ LIST_FOREACH(servers, s, l->dns_servers)
write_resolve_conf_server(s, f, &count);
- }
LIST_FOREACH(servers, s, m->dns_servers)
write_resolve_conf_server(s, f, &count);