mirror of
https://github.com/systemd/systemd.git
synced 2024-12-23 21:35:11 +03:00
networkd: hardcode a set of default dns servers
Similarly to NTP servers, this can be set at compile-time.
This commit is contained in:
parent
332bc31992
commit
e16cb2e4ef
11
configure.ac
11
configure.ac
@ -877,6 +877,7 @@ fi
|
||||
AM_CONDITIONAL(ENABLE_POLKIT, [test "x$have_polkit" = "xyes"])
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
have_networkd=no
|
||||
AC_ARG_ENABLE(networkd, AS_HELP_STRING([--disable-networkd], [disable networkd]))
|
||||
if test "x$enable_networkd" != "xno"; then
|
||||
AC_DEFINE(ENABLE_NETWORKD, 1, [Define if networkd support is to be enabled])
|
||||
@ -886,6 +887,15 @@ AS_IF([test "x$have_networkd" = "xyes" -a "x$have_kmod" != "xyes"],
|
||||
[AC_MSG_ERROR([networkd requires kmod])])
|
||||
AM_CONDITIONAL(ENABLE_NETWORKD, [test "x$have_networkd" = "xyes"])
|
||||
|
||||
AC_ARG_WITH(dns-servers,
|
||||
AS_HELP_STRING([--with-dns-servers=DNSSERVERS],
|
||||
[Space-separated list of default DNS servers]),
|
||||
[DNS_SERVERS="$withval"],
|
||||
[DNS_SERVERS="8.8.8.8 8.8.4.4"])
|
||||
|
||||
AC_DEFINE_UNQUOTED(DNS_SERVERS, ["$DNS_SERVERS"], [Default DNS Servers])
|
||||
AC_SUBST(DNS_SERVERS)
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
have_efi=no
|
||||
AC_ARG_ENABLE(efi, AS_HELP_STRING([--disable-efi], [disable EFI support]))
|
||||
@ -1189,6 +1199,7 @@ AC_MSG_RESULT([
|
||||
time epoch: ${TIME_EPOCH}
|
||||
localed: ${have_localed}
|
||||
networkd: ${have_networkd}
|
||||
default DNS servers: ${DNS_SERVERS}
|
||||
coredump: ${have_coredump}
|
||||
polkit: ${have_polkit}
|
||||
efi: ${have_efi}
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
#include "path-util.h"
|
||||
#include "networkd.h"
|
||||
#include "network-internal.h"
|
||||
#include "libudev-private.h"
|
||||
#include "udev-util.h"
|
||||
#include "rtnl-util.h"
|
||||
@ -74,6 +75,41 @@ static int setup_signals(Manager *m) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int set_fallback_dns(Manager *m, const char *string) {
|
||||
char *word, *state;
|
||||
size_t length;
|
||||
int r;
|
||||
|
||||
assert(m);
|
||||
assert(string);
|
||||
|
||||
FOREACH_WORD_QUOTED(word, length, string, state) {
|
||||
_cleanup_address_free_ Address *address = NULL;
|
||||
Address *tail;
|
||||
_cleanup_free_ char *addrstr = NULL;
|
||||
|
||||
r = address_new_dynamic(&address);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
addrstr = strndup(word, length);
|
||||
if (!addrstr)
|
||||
return -ENOMEM;
|
||||
|
||||
r = net_parse_inaddr(addrstr, &address->family, &address->in_addr);
|
||||
if (r < 0) {
|
||||
log_debug("Ignoring invalid DNS address '%s'", addrstr);
|
||||
continue;
|
||||
}
|
||||
|
||||
LIST_FIND_TAIL(addresses, m->fallback_dns, tail);
|
||||
LIST_INSERT_AFTER(addresses, m->fallback_dns, tail, address);
|
||||
address = NULL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int manager_new(Manager **ret) {
|
||||
_cleanup_manager_free_ Manager *m = NULL;
|
||||
int r;
|
||||
@ -86,6 +122,10 @@ int manager_new(Manager **ret) {
|
||||
if (!m->state_file)
|
||||
return -ENOMEM;
|
||||
|
||||
r = set_fallback_dns(m, DNS_SERVERS);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = sd_event_default(&m->event);
|
||||
if (r < 0)
|
||||
return r;
|
||||
@ -494,6 +534,14 @@ int manager_update_resolv_conf(Manager *m) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!count) {
|
||||
Address *address;
|
||||
|
||||
LIST_FOREACH(addresses, address, m->fallback_dns)
|
||||
append_dns(f, &address->in_addr.in,
|
||||
address->family, &count);
|
||||
}
|
||||
|
||||
fflush(f);
|
||||
|
||||
if (ferror(f) || rename(temp_path, "/run/systemd/network/resolv.conf") < 0) {
|
||||
|
@ -254,6 +254,7 @@ struct Manager {
|
||||
Hashmap *links;
|
||||
Hashmap *netdevs;
|
||||
LIST_HEAD(Network, networks);
|
||||
LIST_HEAD(Address, fallback_dns);
|
||||
|
||||
usec_t network_dirs_ts_usec;
|
||||
struct kmod_ctx *kmod_ctx;
|
||||
|
Loading…
Reference in New Issue
Block a user