Commit graph

206 commits

Author SHA1 Message Date
Beniamino Galvani
90dca9e0c9 dns: log DNS servers at TRACE level
Be more verbose at TRACE level and log the DNS servers associated to
configurations. This will help to debug issues like [0].

[0] https://bugzilla.redhat.com/show_bug.cgi?id=1348887

(cherry picked from commit a5d1db08f8)
2016-06-28 16:45:53 +02:00
Beniamino Galvani
98741c802c dns: remove nm-dns-utils.c and nm-dns-utils.h
The functions in the two files seem to belong to nm-dns-dnsmasq.c as
nobody else is using them.

(cherry picked from commit 6c5a5c9f2a)
2016-06-10 11:14:38 +02:00
Beniamino Galvani
c3c2ed489c dns: add reverse DNS IPv6 entries to dnsmasq
https://bugzilla.gnome.org/show_bug.cgi?id=767174
(cherry picked from commit ae763642d8)
2016-06-10 11:14:38 +02:00
Beniamino Galvani
70bd800038 dns: add CIDR reverse DNS IPv4 entries to dnsmasq
When a reverse DNS entry must be added to dnsmasq, instead of
considering IP addresses as classful use the prefix to compute one or
more "in-addr.arpa" according to CIDR rules.

https://bugzilla.gnome.org/show_bug.cgi?id=767174
(cherry picked from commit 4d1e7dc23c)
2016-06-10 11:14:38 +02:00
Thomas Haller
f95b7b9654 dns: minor fix of logging with unset dns mode
With
  [main]
  #dns=

we would see in the log:
  dns-mgr: init: dns=(null), rc-manager=symlink

Instead, it should be
  dns-mgr: init: dns=default, rc-manager=symlink

Also, we should avoid logging NULL values with "%s", although
glib's printf is fine with that.

(cherry picked from commit bcb88d540e)
2016-06-10 11:14:38 +02:00
Thomas Haller
2826c7ad0f dns: update detection of immutable resolv.conf
Before, we would first check whether the file is immuable before
parsing main.rc-manager setting. That means, if you configured

  [main]
  dns=default
  rc-manager=unmanged

we would still first try to detect whether the file is immutable.
The result of course is only minor, e.g. showing up in logging
as rc-manager=immutable instead of rc-manager=unmanged.
Also, an immutable resolv.conf would suppress a warning about
a bogus rc-manager setting.

Also, when selecting rc-manager=symlink and resolv.conf is a symlink
to an immutable file, we don't actually care about that. The reason is,
that if the link-target is not /var/run/NetworkManager/resolv.conf,
we anyway wouldn't modify the file.

The effect of this change is pretty minor, now in logging you would see:
  dns-mgr: init: dns=default, rc-manager=symlink
  dns-mgr: update-resolv-conf: write internal file /var/run/NetworkManager/resolv.conf succeeded but don't update /etc/resolv.conf as it points to /some/where/else
instead of
  dns-mgr: init: dns=default, rc-manager=immutable
  dns-mgr: update-resolv-conf: write internal file /var/run/NetworkManager/resolv.conf succeeded

Which feels slightly more right.

Note that symlinks cannot have file attributes.

(cherry picked from commit 4711867915)
2016-06-10 11:14:38 +02:00
Thomas Haller
486fc0eade dns: follow resolv.conf if it is a symlink for 'rc-manager=file'
Until before 1.2.0, NetworkManager would always write resolv.conf as file, but
if /etc/resolv.conf was a symlink, it would follow the link instead of
replacing it with a file ([1], [2]).

With 1.2.0, we initially dropped that behavior and added a new 'rc-manager=none'
which writes resolv.conf to /var/run/NetworkManager and symlinks resolv.conf [3].
In case resolv.conf being already a symlink to another target, it would
not be replaced [4].
Later, we added 'rc-manager=file', which always writes /etc/resolv.conf as
file [5].

With 1.4.0, we will rename 'rc-manager=none' to 'rc-manager=symlink' [6].

This commit now fixes 'rc-manager=file' to restores the pre-1.2 behavior
and follow symlinks.

[1] 5761e328b8
[2] https://bugs.launchpad.net/ubuntu/+source/network-manager/+bug/324233
[3] 4805be2ed2
[4] 583568e12f
[5] 288799713d
[6] cd6a469668

https://github.com/NetworkManager/NetworkManager/pull/7
(cherry picked from commit 718fd22436)
2016-06-10 11:14:38 +02:00
Thomas Haller
0b4ea9cbf1 dns: refactor logging statements to use _rc_manager_to_string()
Reuse _rc_manager_to_string() to stringify the rc-manager mode.
Also fix typo "rc-managed=file".

(cherry picked from commit 9418f81528)
2016-06-10 11:14:38 +02:00
Thomas Haller
390778edec config,dns: support Reload flags to specify that only parts should be reloaded
Support 3 new flags for Reload:

  - 0x01 (CONF): reload the configuration from disk
  - 0x02 (DNS_RC): write DNS configuration to resolv.conf
  - 0x04 (DNS_FULL): restart DNS plugin

Omitting all flags is the same as reloading everything, thus SIGHUP.

(cherry picked from commit 0acee97220)
2016-06-10 11:14:38 +02:00
Thomas Haller
d175654fca config: refactor change-flags to be a cause/reason which triggered the change
For the most part, this patch just renames some change-flags, but
doesn't change much about them. The new name should better express
what they are.

A config-change signal can be emitted for different reasons:
when we receive a signal (SIGHUP, SIGUSR1, SIGUSR2) or for internal
reasons like resetting of no-auto-default or setting internal
values.

Depending on the reason, we want to perform different actions.
For example:
 - we reload the configuration from disk on SIGHUP, but not for
   SIGUSR1.
 - For SIGUSR1 and SIGHUP, we want to update-dns, but not for SIGUSR2.

Another part of the change-flags encodes which part of the configuration
actually changed. Often, these parts can only change when re-reading
from disk (e.g. a SIGUSR1 will not change any configuration inside
NMConfig).

Later, we will have more causes, and accordingly more fine-grained
effects of what should be done on reload.

(cherry picked from commit eb6140a772)
2016-06-10 11:14:37 +02:00
Thomas Haller
bcc955fcc9 dns: reload DNS plugin in SIGHUP
Previously, on SIGHUP we would re-read the configuration and possibly
reconfigure DNS. However, if the DNS plugin didn't change, we would
not restart it. That is good, because restarting the DNS plugin shortly
interrupts name resolution.

dnsmasq might depend on additional configuration from /etc/NetworkManager/dnsmasq.d,
thus, the user also needs a way to restart the plugin to pickup the
configuration. For that, it could just kill the dnsmasq instance, but
that means, ratelimiting will hit and restarting dnsmasq too often
might bork the plugin for 5 minutes.

Now, on SIGHUP, also restart the DNS plugin. The advantage is that
one signal reloads everything, including the dnsmasq instance, without
ratelimiting.
The disadvantage is, that it shortly interrupts name resolution.

(cherry picked from commit 9ae307347b)
2016-06-10 11:14:37 +02:00
Thomas Haller
b3124f7477 dns: reset plugin-ratelimiting when clearing plugin
This also fixes cancelling the timeout in dispose().
Just to be explicit, also cancel it in dispose(),
although dispose() alreay calls _clear_plugin().

(cherry picked from commit a920155d0b)
2016-06-10 11:14:37 +02:00
Thomas Haller
cff8c257d3 dns: explicitly stop DNS plugin in manager
_clear_plugin() should explicitly stop the DNS plugin, instead of just
unreferencing it. Unreferencing does not necessarily mean, that the
plugin will be destroyed right away.

(cherry picked from commit e1d5b27c4f)
2016-06-10 11:14:37 +02:00
Thomas Haller
f065794eeb dns: embed private data in NMDnsManager struct
Make NMDnsManager an opaque type and embed the private data
directly in struct _NMDnsManager.

(cherry picked from commit 7d808e523b)
2016-06-10 11:14:37 +02:00
Thomas Haller
30642a674e dns: remove unused signal slot for NM_DNS_MANAGER_CONFIG_CHANGED
(cherry picked from commit bcbbaaa182)
2016-06-10 11:14:37 +02:00
Thomas Haller
f21fb793f2 dns: add configure option "--with-config-dns-rc-manager-default" for default of main.rc-manager
Downstream might want to choose a different default value for
main.rc-manager setting (and it can does so, by compiling with
explicit resolvconf or netconfig support).

Make the default configurable at build-time and also embed it into
the manual page of "NetworkManager.conf".

https://bugzilla.redhat.com/show_bug.cgi?id=1337222
(cherry picked from commit 51791c4772)
2016-06-10 11:14:37 +02:00
Beniamino Galvani
2f12f48560 dns: specify egress interface for each dnsmasq upstream server
Currently we don't specify to dnsmasq which interface must be used to
contact a given nameserver and so requests can be sent through the
wrong interface.

Fix this by concatenating a @interface prefix to each server (unless
an IPv6 interface scope-id is already present).

https://bugzilla.gnome.org/show_bug.cgi?id=765153
(cherry picked from commit b71e104d33)
2016-06-10 11:14:37 +02:00
Beniamino Galvani
c42f455251 dns: assert early that @iface is not NULL
Under no circumstance should a non-global configuration with NULL or
empty iface be added to the DNS manager. Assert this early and remove
other unnecessary checks.

(cherry picked from commit 027f4c65ac)
2016-06-10 11:14:37 +02:00
Beniamino Galvani
46ab13eda1 dns: properly remove existing configurations
When a configuration is replaced by another with different metadata,
disconnect signals and clear @best_conf pointers. Also, the check in
remove_ip_config() was wrong.

Fixes: 8e6d442477
Fixes: 570d73979b
(cherry picked from commit fc8cc8393e)
2016-06-10 11:14:37 +02:00
Beniamino Galvani
e392ee6b8d dns: use DNS priority from IP configuration
Use the ipvx.dns-priority when sorting the array of
configurations. When a negative value is found, all following entries
with a greater value are skipped.

(cherry picked from commit 570d73979b)
2016-06-10 11:14:37 +02:00
Beniamino Galvani
95310a5dec core: use default value for ipvx.dns-priority
Fall back to system default value for ipvx.dns-priority when it's zero
in the setting. For VPNs the default value is 50; for other
connections is 100, but it depends also on the content of
[connection*] sections in NetworkManager.conf.

(cherry picked from commit 77ded12da4)
2016-06-10 11:14:37 +02:00
Beniamino Galvani
41e6540141 dns: pass config data array to plugins
Export NMDnsIPConfigData to DNS plugins and use it to pass additional
information about configurations.

(cherry picked from commit e53aa0dcff)
2016-06-10 11:11:53 +02:00
Beniamino Galvani
a3401f0bf4 dns: use a single array for all configurations
In a following commit configurations will be ordered by their
priority; arrange them in a single array to make this simpler. Also,
instead of using g_object_set_data() to store metadata, introduce a
NMDnsIPConfigData structure.

(cherry picked from commit 8e6d442477)
2016-06-10 11:11:53 +02:00
Beniamino Galvani
21b520b469 dns: don't use the global configuration to compute initial hash
If the initial hash includes the global configuration, every update
attempt will be skipped because the configuration never changes, and
resolv.conf will never be updated. Instead, use a NULL global
configuration to compute the hash and force an initial update.

(cherry picked from commit 16d5c8222b)
2016-06-10 11:11:53 +02:00
Thomas Haller
b952f54cb1 dns: add new rc-manager=unmanaged
The following settings are effectively identical:

    dns=none,rc-manager=*any*
    dns=none,rc-manager=unmanaged
    dns=default,rc-manager=unmanaged

The new setting is only there for completeness and only
makes sense for a dns plugin.

(cherry picked from commit 2789345d5b)
2016-06-10 11:11:53 +02:00
Thomas Haller
6ae3119f86 dns: merge the dns "mode" and "rc-manager"
Already previously, the mode and rc-manager were intertwined in a complicated
way:

  - dns=none effectively disables rc-manager.

  - if resolv.conf was immutable, it would disable the rc-manager
    by setting "resolv_conf_mode=NM_DNS_MANAGER_RESOLV_CONF_UNMANAGED".

  - resolv_conf_mode was anyway a redundant piece of information to
    rc_manager.

Now there are only two relevant settings: priv->plugin and
priv->rc_manager. And they can be set independently from each other.
Before that was not possible. For example, you could not set a
dns plugin with rc-manager=unmanaged (the only way to achive that
was via an immutable resolv.conf or by having rc-manager=symlink
and let resolv.conf link somewhere else.

(cherry picked from commit 161f86b5b3)
2016-06-10 11:11:53 +02:00
Thomas Haller
5504af286d dns: when clearing "plugin" always disconnect signal handlers
(cherry picked from commit 83fd710005)
2016-06-10 11:11:53 +02:00
Thomas Haller
b36408d882 dns: initialize rc-manager in init_resolv_conf_mode()
The "dns" and "rc-manager" properties are strongly related. Initialize them
together in init_resolv_conf_mode().

One difference is, that we now set rc_manager before setting the mode.
But that shouldn't matter.

(cherry picked from commit a252dfdb9d)
2016-06-10 11:11:53 +02:00
Thomas Haller
25edbf3fb6 dns: split parsing of rc-manager out of init_resolv_conf_manager()
Makes more sense in the next commit, when init_resolv_conf_manager()
gets merged with init_resolv_conf_mode(). Bear with me.

(cherry picked from commit aea2d98e2d)
2016-06-10 11:11:53 +02:00
Thomas Haller
8a68c92956 dns: rename "rc-manager=none" to "symlink"
We already have "rc-manager=file", rename "rc-manager=none" to "symlink"
because that better describes what it is actually doing. Of course, the
old name is still accepted.

(cherry picked from commit cd6a469668)
2016-06-10 11:11:53 +02:00
Thomas Haller
5a24c74ebe dns: add trace logging when writing resolv.conf
It is interesting to find in the logfile when we write to "/etc/resolv.conf"
or our internal version "/var/run/NetworkManager/resolv.conf".

(cherry picked from commit c486c38962)
2016-06-10 11:11:53 +02:00
Beniamino Galvani
44f0a50d1a dns-manager: properly handle multiple VPN configurations
Now that we support multiple VPNs active at the same time, the DNS
manager must be able to keep a list of all the VPN configurations and
give them a higher priority than other configurations.

Before this commit all the VPN configuration except one were
considered as normal configurations.

https://bugzilla.gnome.org/show_bug.cgi?id=764689
(cherry picked from commit f439f05237)
2016-06-10 11:11:53 +02:00
Beniamino Galvani
38200371a8 dns-manager: add 'priv' pointer to object structure
(cherry picked from commit 89306ebb2e)
2016-06-10 11:11:53 +02:00
Beniamino Galvani
223b65f072 dns: fix debug message
Fixes: 5f9d348c20
(cherry picked from commit 317f70997b)
2016-06-10 11:11:53 +02:00
Beniamino Galvani
a845ab0197 dns: update caching plugins on configuration change signal
A HUP or USR1 signal forces the rewrite of DNS configuration, however
caching plugins are ignored when using dns=dnsmasq and so the real
servers are written to resolv.conf:

 $ cat /etc/resolv.conf
 nameserver 127.0.0.1

 # killall -USR1 NetworkManager

 $ cat /etc/resolv.conf
 nameserver 192.168.1.1

Set @no_caching to FALSE when calling update_dns() after a signal to
take caching plugins into account.

(cherry picked from commit b88ce6d044)
2016-06-10 11:11:53 +02:00
Thomas Haller
62b3d27e1d Revert "Remove dns VPN/DEVICE DNS config before adding different one"
This reverts commit 68122212e0.
2016-06-10 02:29:51 +02:00
Thomas Haller
1f8ba33d87 dnsmasq: properly handling respawning of dnsmask
Otherwise, when killing dnsmasq it does not get respawned:

    dnsmasq[0x560dd7e43cf0]: dnsmasq exited normally
    dns-mgr: plugin dnsmasq child quit unexpectedly
    dns-mgr: update-dns: updating resolv.conf
    dns-mgr: config:      100 best    v4 enp0s25
    dns-mgr: config:      100 best    v6 enp0s25
    dns-mgr: config:      100 default v6 lo
    dns-mgr: config:      100 default v4 lo
    dns-mgr: update-dns: updating plugin dnsmasq
    dnsmasq[0x560dd7e43cf0]: adding nameserver '192.168.0.2@enp0s25'
    dnsmasq[0x560dd7e43cf0]: trying to update dnsmasq nameservers
    dns-mgr: update-resolv-conf: write internal file /var/run/NetworkManager/resolv.conf succeeded but don't update /etc/resolv.conf as it points to resolv.conf.nm
    dnsmasq[0x560dd7e43cf0]: dnsmasq disappeared

Previously, we would create priv->dnsmasq proxy only once,
and not respawn the process at all.

https://bugzilla.gnome.org/show_bug.cgi?id=766996
(cherry picked from commit 2e7f4aeb60)
2016-06-02 19:03:00 +02:00
Thomas Haller
2deee52867 dns: log when dnsmasq process exits normally
(cherry picked from commit a64d70f0df)
2016-06-02 19:02:54 +02:00
Beniamino Galvani
84b0bb5ec8 core: introduce nm_utils_dnsmasq_status_to_string()
(cherry picked from commit c0d322720a)
2016-06-02 19:02:48 +02:00
Nikolay Martynov
68122212e0 Remove dns VPN/DEVICE DNS config before adding different one
It turnes out that 'nm_dns_manager_add_ip{4,6}_config' can be called to add VPN/DEVICE
config for device that already has one. On this case old config gets overwritten in
'priv->ip{4,6}_{vpn,device}_config' but is not removed from 'priv->configs'.
The result of that is that old config still being applyed but is treated as 'other'
config.

Apart from being a slight memory leak this has user facing consequences: if old config
was a split DNS VPN config 'split DNS' part will no longer work and those DNS servers
will be used as 'global' DNS servers.

This patch addresses the problem by making sure old values in 'priv->ip{4,6}_{vpn,device}_config'
are removed from 'priv->configs' before new values are applyed.

Signed-off-by: Nikolay Martynov <mar.kolya@gmail.com>
2016-05-29 13:50:09 +02:00
Beniamino Galvani
a701e5b7ba dns: clear dnsmasq cache after an update
When the list of DNS servers changes, old DNS entries cached by
dnsmasq must be invalidated as the answers returned by new servers may
be different (especially, old NXDOMAIN entries may now be valid). Call
the dnsmasq "ClearCache" D-Bus method to achieve this.

https://bugzilla.redhat.com/show_bug.cgi?id=1338731
(cherry picked from commit 4feb58b50b)
2016-05-28 09:41:33 +02:00
Beniamino Galvani
7541ca0692 dns/dnsmasq: cancel pending update on dispose
There might be a pending "SetServersEx" D-Bus call when the plugin is
destroyed, ensure it gets canceled.

(cherry picked from commit d376787ce1)
2016-05-28 09:41:31 +02:00
Beniamino Galvani
dd3dfad583 dns/dnsmasq: use servers without split DNS if no domain was received
When a VPN server doesn't push any DNS domain, we want to use the
received servers for all queries.

https://bugzilla.gnome.org/show_bug.cgi?id=766769
2016-05-26 09:53:22 +02:00
Thomas Haller
b04db262cb all: replace nm_unauto() by g_steal_pointer()
They do essentially the same.

(cherry picked from commit ba90c9601c)
2016-05-12 14:35:14 +02:00
Thomas Haller
3341365e29 dns: avoid using global "/etc/dnsmasq.conf" config for dnsmasq
Pass an empty configuration file otherwise dnsmasq loads
"/etc/dnsmasq.conf".

We already allow for a config.d/ directory "/etc/NetworkManager/dnsmasq.d"
to allow the user to overwrite configuration. We don't want to consider
the global config file.

Fixes: 497a8aa5c6
(cherry picked from commit 3d3f71acec)
2016-04-22 13:40:17 +02:00
Thomas Haller
99168f6009 dns: various cleanup for new dnsmasq's D-Bus support
(cherry picked from commit baaec81aea)
2016-04-22 13:39:23 +02:00
Mathieu Trudel-Lapierre
08673a623f dns: use DBus to make dnsmasq nameserver changes
Use DBus to make nameserver updates rather than restarting the dnsmasq binary
again and again.

Signed-off-by: Mathieu Trudel-Lapierre <mathieu.trudel-lapierre@canonical.com>

https://mail.gnome.org/archives/networkmanager-list/2016-March/msg00144.html
(cherry picked from commit 18282df0aa)
2016-04-22 13:39:23 +02:00
Thomas Haller
9f3c8f3e01 dns: add and use _NMLOG() logging macro in nm-dns-plugin.c
(cherry picked from commit 44a61eda77)
2016-04-22 13:39:23 +02:00
Thomas Haller
4fa0f205b6 dns: cleanup managing child process for NMDnsPlugin
The 4 private fields pid, watch_id, progname and pidfile strictly
belong together. When spawning a child, we set all 4 of them and
when killing the child all get cleared. Cleanup to code to always
set those 4 fields together.

(cherry picked from commit 4d5ca7f9de)
2016-04-22 13:39:23 +02:00
Thomas Haller
3571356d9d dns: remove unnecessary finalize() implementation from NMDnsPlugin
dispose() already calls nm_dns_plugin_child_kill(), which clears
both pidfile and progname.

(cherry picked from commit 252258eb2a)
2016-04-22 13:39:23 +02:00