Commit graph

184 commits

Author SHA1 Message Date
Thomas Haller
51791c4772 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
2016-05-23 21:49:42 +02:00
Beniamino Galvani
b71e104d33 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
2016-05-18 11:10:05 +02:00
Beniamino Galvani
027f4c65ac 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.
2016-05-18 11:10:05 +02:00
Beniamino Galvani
fc8cc8393e 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
2016-05-13 17:46:09 +02:00
Beniamino Galvani
570d73979b 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.
2016-05-12 17:14:13 +02:00
Beniamino Galvani
77ded12da4 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.
2016-05-12 17:13:50 +02:00
Beniamino Galvani
e53aa0dcff dns: pass config data array to plugins
Export NMDnsIPConfigData to DNS plugins and use it to pass additional
information about configurations.
2016-05-12 17:13:49 +02:00
Beniamino Galvani
8e6d442477 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.
2016-05-12 17:13:42 +02:00
Beniamino Galvani
16d5c8222b 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.
2016-05-12 16:16:16 +02:00
Thomas Haller
ba90c9601c all: replace nm_unauto() by g_steal_pointer()
They do essentially the same.
2016-05-12 14:28:44 +02:00
Beniamino Galvani
c0d322720a core: introduce nm_utils_dnsmasq_status_to_string() 2016-05-02 15:06:43 +02:00
Thomas Haller
2789345d5b 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.
2016-04-26 13:58:28 +02:00
Thomas Haller
161f86b5b3 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.
2016-04-26 13:58:28 +02:00
Thomas Haller
83fd710005 dns: when clearing "plugin" always disconnect signal handlers 2016-04-26 13:58:28 +02:00
Thomas Haller
a252dfdb9d 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.
2016-04-26 13:58:28 +02:00
Thomas Haller
aea2d98e2d 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.
2016-04-26 13:58:28 +02:00
Thomas Haller
cd6a469668 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.
2016-04-26 13:58:27 +02:00
Thomas Haller
3d3f71acec 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
2016-04-21 19:58:47 +02:00
Thomas Haller
baaec81aea dns: various cleanup for new dnsmasq's D-Bus support 2016-04-21 16:24:15 +02:00
Mathieu Trudel-Lapierre
18282df0aa 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
2016-04-21 15:32:07 +02:00
Thomas Haller
44a61eda77 dns: add and use _NMLOG() logging macro in nm-dns-plugin.c 2016-04-21 15:32:07 +02:00
Thomas Haller
4d5ca7f9de 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.
2016-04-21 15:32:07 +02:00
Thomas Haller
252258eb2a dns: remove unnecessary finalize() implementation from NMDnsPlugin
dispose() already calls nm_dns_plugin_child_kill(), which clears
both pidfile and progname.
2016-04-21 15:32:07 +02:00
Thomas Haller
de9ad6bd8c dns: minor code cleanup in NMDnsPlugin 2016-04-21 15:32:07 +02:00
Thomas Haller
c486c38962 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".
2016-04-20 18:47:07 +02:00
Beniamino Galvani
f439f05237 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
2016-04-18 11:29:25 +02:00
Beniamino Galvani
89306ebb2e dns-manager: add 'priv' pointer to object structure 2016-04-18 11:29:09 +02:00
Beniamino Galvani
317f70997b dns: fix debug message
Fixes: 5f9d348c20
2016-04-15 22:01:56 +02:00
Beniamino Galvani
b88ce6d044 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.
2016-04-15 11:56:29 +02:00
Thomas Haller
c328cf52f2 dnsmasq: fix using '%' delimiter to scope link local with zone-id
Since long, dnsmasq supports scoping the IPv6 address
with '@<interface-name>'. Since 2.58, it also supports
'%' as delimiter, which is the standard way to specify
the zone-id (rfc6874).

Since 2.73, specifying the scope with '@' as "server"
address is no longer working properly, thus breaking
NetworkManager with dnsmasq >= 2.73.

To work around that, use '%' delimiter. That breaks pre-2.58
users that have a DNS server on a link local address, but that
seems acceptable as that version was released in January 2012.

https://bugzilla.gnome.org/show_bug.cgi?id=764839
2016-04-11 11:13:17 +02:00
Thomas Haller
f7729751da core: use defines for signal names in NMDnsManager and NMFirewallManager 2016-04-04 16:48:10 +02:00
Thomas Haller
2b394d0092 dns-manager: use NM_IN_SET() in condition 2016-04-03 14:54:37 +02:00
Thomas Haller
fd496fd887 dns-manager: fix compute_hash() to skip over duplicate other configs
Fixes: f76aa4f77c
2016-04-03 14:54:34 +02:00
Beniamino Galvani
3b3a4e1c8b dns: fix error cleanup in kill_existing()
Fixes: 3e66813db2
2016-03-24 10:21:53 +01:00
Thomas Haller
a0f7967386 dns: always reload the dns configuration mode on SIGHUP 2016-03-23 09:09:06 +01:00
Thomas Haller
0c4b2d8c89 dns: enable dns plugins also with immutable resolv.conf
We check whether /etc/resolv.conf is set as immutable. But even then
we still want to support our dns plugins like dnsmasq and unbound.
2016-03-23 09:09:06 +01:00
Thomas Haller
288799713d dns: add new "rc-manager=file" 2016-03-23 09:09:06 +01:00
Thomas Haller
22df466ed3 dns: split create_resolv_conf() out of write_resolv_conf() 2016-03-23 09:09:06 +01:00
Thomas Haller
f73621a545 dns: refactor NMDnsManagerResolvConfMode to string conversion 2016-03-23 09:09:06 +01:00
Thomas Haller
4faaa3eb0b dns: fix _NMLOG() macro
The buffer was too small to contain _NMLOG_PREFIX_NAME and the pointer,
resulting in truncated messages like:

  dns-mgr[0x561d1183d: set resolv-conf-mode: none
2016-03-23 09:08:35 +01:00
Thomas Haller
3bcc0e5cea dnsmasq: use _LOG() macros
The _LOG*() macros based on _NMLOG() prefix each line with a
context. Since we no longer log the location of the logging line,
this is the more important.
2016-03-22 16:50:50 +01:00
Thomas Haller
3e66813db2 dns: refactor kill_existing() to always unlink pidfile
When a pidfile exists, it is always stale after this point
and kill_existing() should always unlink it.

Also, refactor kill_existing() to use nm_utils_kill_process_sync()
which waits for the process to be gone.
2016-03-22 16:45:00 +01:00
Thomas Haller
ca733526e6 dns: cleanup disposing of NMDnsPlugin 2016-03-22 16:45:00 +01:00
Thomas Haller
6673d3ad7a dns: refactor cleanup and unlink of pidfile 2016-03-22 16:45:00 +01:00
Mathieu Trudel-Lapierre
2bb769cf10 dns: cleanup pid file when dnsmasq process terminated
[thaller@redhat.com: extracted the patch from a larger one]

https://mail.gnome.org/archives/networkmanager-list/2016-March/msg00144.html

Signed-off-by: Mathieu Trudel-Lapierre <mathieu.trudel-lapierre@canonical.com>
2016-03-22 16:44:33 +01:00
Thomas Haller
99ef0d26e2 dns/trivial: fix indention 2016-03-22 16:30:38 +01:00
Thomas Haller
cd4f84b738 all: don't include error->code in log messages
GError codes are only unique per domain, so logging the code without
also indicating the domain is not helpful. And anyway, if the error
messages are not distinctive enough to tell the whole story then we
should fix the error messages.

Based-on-patch-by: Dan Winship <danw@gnome.org>
2016-03-03 18:54:20 +01:00
Thomas Haller
01b9b4104c all: clean-up usage of GError
Functions that take a GError** MUST fill it in on error. There is no
need to check whether error is NULL if the function it was passed to
had a failing return value.

Likewise, a proper GError must have a non-NULL message, so there's no
need to double-check that either.

Based-on-patch-by: Dan Winship <danw@gnome.org>
2016-03-03 18:54:20 +01:00
Thomas Haller
8bace23beb all: cleanup includes and let "nm-default.h" include "config.h"
- All internal source files (except "examples", which are not internal)
  should include "config.h" first. As also all internal source
  files should include "nm-default.h", let "config.h" be included
  by "nm-default.h" and include "nm-default.h" as first in every
  source file.
  We already wanted to include "nm-default.h" before other headers
  because it might contains some fixes (like "nm-glib.h" compatibility)
  that is required first.

- After including "nm-default.h", we optinally allow for including the
  corresponding header file for the source file at hand. The idea
  is to ensure that each header file is self contained.

- Don't include "config.h" or "nm-default.h" in any header file
  (except "nm-sd-adapt.h"). Public headers anyway must not include
  these headers, and internal headers are never included after
  "nm-default.h", as of the first previous point.

- Include all internal headers with quotes instead of angle brackets.
  In practice it doesn't matter, because in our public headers we must
  include other headers with angle brackets. As we use our public
  headers also to compile our interal source files, effectively the
  result must be the same. Still do it for consistency.

- Except for <config.h> itself. Include it with angle brackets as suggested by
  https://www.gnu.org/software/autoconf/manual/autoconf.html#Configuration-Headers
2016-02-19 17:53:25 +01:00
Thomas Haller
da4ae74fff dns: don't add an IP-addresss-like hostname to the search domains
https://bugzilla.gnome.org/show_bug.cgi?id=761302
2016-02-01 10:20:50 +01:00