Commit Graph

138 Commits

Author SHA1 Message Date
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
Dan Williams
0a3a345b71 dns: remove newlines from errors 2016-01-26 11:26:41 -06:00
Dan Williams
af189b3295 dns: clean up error paths in dns-manager
Specifically for resolvconf, if the write succeeded, but the pclose()
failed error would be left NULL and SR_ERROR would be returned, which
caused a crash in nm_dns_manager_end_updates().
2016-01-26 11:25:50 -06:00
Beniamino Galvani
96b11af92d dns: fix generation of global configuration for dnsmasq
Fixes: ae9e82354a
2016-01-25 21:46:11 +01:00
Beniamino Galvani
64ac910131 dns-manager: prevent DNS plugins from respawning too quickly
If dnsmasq (or another DNS plugin) exits immediately (for example due
to an already used port), the DNS manager keeps restarting it forever,
wasting system resources and filling logs.

Add a simple rate-limiting mechanism.

https://bugzilla.gnome.org/show_bug.cgi?id=760691
2016-01-21 10:40:08 +01:00
Beniamino Galvani
fbd3286955 core,libnm: use nm_clear_g_source() where possible
Replacement was done with commands:

spatch --sp-file nm_clear_g_source.cocci --in-place --smpl-spacing --dir src
spatch --sp-file nm_clear_g_source.cocci --in-place --smpl-spacing --dir libnm

where nm_clear_g_source.cocci contains:

@@
expression e;
@@
- if (e) {
-    g_source_remove (e);
-    e = 0;
- }
+ nm_clear_g_source (&e);
2016-01-06 21:25:55 +01:00
Thomas Haller
9587867349 logging: swap names of logging macros _LOGT() and _LOGt()
Previsously, _LOGT() could be disabled at compile time. Thus it
was different then the other macros _LOGD(), _LOGI(), etc.

OTOH, _LOGt() was the macro that always was compiled in.

Swap the name of the macros. Now the upper-case macros are always
enabled, while the lower-case macro _LOGt() is enabled depending
on compile configuration.
2015-11-06 14:16:41 +01:00
Lubomir Rintel
a07f1000ba dns-unbound: use the correct path when calling dnssec-trigger-script
Debian systems don't have /usr/libexec, so the script is installed in
a different path.

Based on a patch from Arto Jantunen <viiru@debian.org>
2015-10-30 11:15:51 +01:00
Beniamino Galvani
ae9e82354a dns: add support for global configuration in DNS manager
Modify the DNS manager to use the static global DNS configuration when
available. In addition, change DNS plugins interface to accept a new
argument for global configuration and add support for this new
parameter to the dnsmasq plugin.
2015-10-01 09:05:08 +02:00
Beniamino Galvani
d7b72b2a3e dns-manager: fix DNS options syntax in resolv.conf
Fixes: e7ff906f91
2015-09-22 20:43:08 +02:00
Thomas Haller
bbf56bf286 dns: fix bug setting dns-mode
Fixes: 18d2825ceb
2015-09-09 18:41:11 +02:00
Thomas Haller
18d2825ceb dns: unify some logging statements for dns-manager
In update_dns(), prefix the logging lines with "update-dns:".
In init_resolv_conf_mode(), explicitly log the selected mode.
2015-09-04 14:25:23 +02:00
Thomas Haller
ed7198ad99 dns: fix logging in nm_dns_manager_end_updates() 2015-09-04 13:45:13 +02:00
Thomas Haller
de4357d9f4 dns: use _LOG*() macros in "nm-dns-manager.c" 2015-09-04 13:45:13 +02:00
Thomas Haller
9dbc63ac71 dns: add _LOG*() macros to "nm-dns-manager.c" 2015-09-04 13:45:13 +02:00
Thomas Haller
1d06000696 dns/trivial: rename @mgr variable to @self 2015-09-04 13:45:13 +02:00
Dan Winship
22e1a97e12 all: drop includes to <glib/gi18n.h> for "nm-default.h"
The localization headers are now included via "nm-default.h".

Also fixes several places, where we wrongly included <glib/gi18n-lib.h>
instead of <glib/gi18n.h>. For example under "clients/" directory.
2015-08-05 15:35:51 +02:00
Thomas Haller
19c3ea948a all: make use of new header file "nm-default.h" 2015-08-05 15:32:40 +02:00
Dan Winship
3452ee2a0e all: rename nm-glib-compat.h to nm-glib.h, use everywhere
Rather than randomly including one or more of <glib.h>,
<glib-object.h>, and <gio/gio.h> everywhere (and forgetting to include
"nm-glib-compat.h" most of the time), rename nm-glib-compat.h to
nm-glib.h, include <gio/gio.h> from there, and then change all .c
files in NM to include "nm-glib.h" rather than including the glib
headers directly.

(Public headers files still have to include the real glib headers,
since nm-glib.h isn't installed...)

Also, remove glib includes from header files that are already
including a base object header file (which must itself already include
the glib headers).
2015-07-24 13:25:47 -04:00
Thomas Haller
68f1203c7c dns: rewrite "resolv.conf" on SIGHUP and SIGUSR1
Also rewrite resolv.conf if the configuration didn't actually change.
Especially, react on SIGUSR1 which does not reload the configuration but
only writes "resolv.conf".

https://bugzilla.redhat.com/show_bug.cgi?id=1062301
2015-06-25 22:02:18 +02:00
Beniamino Galvani
a6f5aeeb28 dns: fall back to writing resolv.conf when other methods are not available
After commits:

de0d623680 dns: don't fall back to other methods when resolvconf or netconfig fail
e573977b80 dns: allow runtime selection of resolv.conf manager

the method used to write /etc/resolv.conf is specified by a
configuration parameter and NM doesn't try other methods if the chosen
one has not success.

Restore the fallback to the 'none' method if resolvconf or netconfig
executables are not available, so that when the value of 'rc-manager'
is misconfigured the system continues to work properly.

https://bugzilla.gnome.org/show_bug.cgi?id=749286
2015-05-26 13:33:47 +02:00
Thomas Haller
533f9fa2d2 libnm: move internal dns-option helpers to "nm-core-internal.h"
"nm-utils-private.h" should not be used outside of libnm-core/.
core/ should only use public API or "nm-core-internal.h".

Also, "nm-setting-ip-config.h" is a public header and should
not contain internal defines. Move them to "nm-core-internal.h"
too.

Fixes: 019943bb5d
2015-05-20 12:42:14 +02:00
Beniamino Galvani
8e46a737db dns: don't update error when writing private resolv.conf
When update_dns() fails, callers expect 'error' argument to point to a
non-NULL error; but we are reusing the same variable when calling
update_resolv_conf() to update the private resolv.conf and thus the
function may return an empty error on failure.

Don't reuse the same error and pass a NULL argument instead, since we
don't care about errors when updating private resolv.conf.

Fixes: 5f9d348c20
2015-05-19 10:38:55 +02:00
Beniamino Galvani
045938074d dns: accept NULL error argument in update_resolv_conf() 2015-05-19 10:38:52 +02:00
Beniamino Galvani
e7ff906f91 dns-manager: add support for DNS options 2015-05-13 17:15:34 +02:00
Beniamino Galvani
6edc737173 dns: don't override DHCP-supplied search order with domain
NM always prepends the list of DNS domains received through DHCP to
the search list in /etc/resolv.conf, overriding the DHCP-supplied DNS
domain search order. This behavior is not entirely correct since it
changes the search order provided by system administrators.

We cannot simply avoid adding the DNS domain list to the search list
because this would break some configurations that rely on the 'domain'
option to deliver the search list.

This patch modifies the behavior of DNS manager to:
 - insert the DHCP-provided 'domain' at the end of 'searches' option
   so that 'searches' is always preferred
 - ignore 'domain' if 'searches' option exists and 'domain' is a
   single domain

https://bugzilla.gnome.org/show_bug.cgi?id=748900
2015-05-08 10:21:28 +02:00
Dan Williams
f575c6a5cb dns: clear error before updating resolv.conf
If the resolv.conf method failed, don't trigger a warning by overwriting
an already-set error.
2015-05-06 14:55:46 -05:00
Thomas Haller
5f0c23f106 dns-manager: fail dns config if netconfig exits with non-zero status
If netconfig does not exit with zero status signal, assume
configuration failed and signal an error.
2015-05-05 16:39:18 +02:00
Thomas Haller
6b646a1e37 dns-manager: use nm_utils_kill_child_sync() to wait for netconfig to exit 2015-05-05 16:39:18 +02:00
Thomas Haller
a8c158dbec dns-manager: fix missing include
dns-manager must include <gio/gio.h> itself. Otherwise
compilation only works with WITH_LIBSOUP, which includes
<gio/gio.h> via <libsoup/soup.h>.

This is an old error, but unnoticed until ad6dbc504b
which makes use of gio.h also without NETCONFIG_PATH.
2015-05-04 11:44:13 +02:00
Beniamino Galvani
e573977b80 dns: allow runtime selection of resolv.conf manager
Add a new 'rc-manager' configuration parameter that allows to select
the strategy used to write resolv.conf; currently supported values
are: none|resolvconf|netconfig, 'none' meaning that NM directly writes
the file.

The default value of the parameter is 'none'; however if a
RESOLVCONF_PATH (or NETCONFIG_PATH) is specified at build time, the
default value will be 'resolvconf' (or 'netconfig').
2015-05-04 09:42:25 +02:00
Beniamino Galvani
de0d623680 dns: don't fall back to other methods when resolvconf or netconfig fail 2015-05-04 09:42:25 +02:00
Beniamino Galvani
5f9d348c20 dns: always write a private resolv.conf to runtime directory
https://bugzilla.gnome.org/show_bug.cgi?id=747821
2015-05-04 09:42:25 +02:00
Beniamino Galvani
fa19fc0a7a build: fix compile warnings in DNS manager
Fixes the following warnings in nm-dns-manager.c with NETCONFIG_PATH set:

  dns-manager/nm-dns-manager.c: In function 'dispatch_netconfig':
  dns-manager/nm-dns-manager.c:313:2: warning: implicit declaration of function 'waitpid' [-Wimplicit-function-declaration]
    ret = waitpid (pid, NULL, 0);
    ^
  dns-manager/nm-dns-manager.c:271:14: warning: unused variable 'tmp' [-Wunused-variable]
    char *str, *tmp;
                ^
  dns-manager/nm-dns-manager.c:329:13: warning: 'ret' may be used uninitialized in this function [-Wmaybe-uninitialized]
    return ret > 0;
               ^
2015-04-01 15:52:24 +02:00
Beniamino Galvani
3db2e9d013 build: fix compile error in DNS manager
Fixes the following error in nm-dns-manager.c with NETCONFIG_PATH set:

  dns-manager/nm-dns-manager.c:320:4: error: too many arguments to function 'g_set_error_literal'
      g_set_error_literal (error,
2015-04-01 15:52:21 +02:00
Dan Williams
09a05f6c3e dns: refresh DNS if plugin child quits unexpectedly (bgo #728342)
If the child dies, or something kills the child externally, refresh
DNS which should respawn the child, similar to what we do with
wpa_supplicant, teamd, etc.

https://bugzilla.gnome.org/show_bug.cgi?id=728342
2015-03-27 16:19:14 -05:00
Dan Williams
06f25a3ec7 dns: ensure that update_dns() always returns a GError on failure
Callers may expect this, so make sure we do it.
2015-03-27 16:19:13 -05:00
Dan Williams
cc8d9f778c dns: refactor building IP config lists for plugins (bgo #728342)
Don't bother building the lists if no DNS plugins are enabled.

https://bugzilla.gnome.org/show_bug.cgi?id=728342
2015-03-27 16:17:10 -05:00
Dan Williams
452c224656 dns: kill plugin child synchronously to avoid restart race (rh #1161232) (bgo #728342)
NM was killing the dnsmasq local caching nameserver process and immediately
starting a new one, and new process couldn't bind to 127.0.0.1 because the
old one hadn't quit yet.  Thus the new process quit, and the user was
left with no split DNS at all.

While this does introduce more synchronous waiting into the connection
process, it's not that much time and NM will kill dnsmasq if it hasn't
quit after 1 second.  The longer-term fix is to use dnsmasq's D-Bus
interface to update DNS without respawning it.

https://bugzilla.gnome.org/show_bug.cgi?id=728342
https://bugzilla.redhat.com/show_bug.cgi?id=1161232
2015-03-27 16:17:10 -05:00
Lubomir Rintel
73e8aeadba dns-manager: react to dns management mode changes
Load a different plugin when the configuration changes.
2015-02-25 18:25:04 +01:00
Lubomir Rintel
aa672b2dc2 config: move dns mode configuration to NMConfigData
This will make is possible for the NMDnsManager to watch for
configuration changes.
2015-02-25 18:25:04 +01:00
Thomas Haller
4c691cf69e trival/whitespace: fix indention in nm-dns-manager.c
Fixes: 583568e12f
2015-01-21 17:30:05 +01:00
Dan Winship
fb792af7cb core: add nm_utils_setpgid(), and use it
Add nm_utils_setpgid() as a g_spawn*() child setup function for
calling setpgid(), and use it where appropriate rather than
reimplementing it every time.
2015-01-19 11:29:13 -05:00
Dan Winship
c22e3f327a core, dispatcher: drop unnecessary setpgid() calls
There's no point in calling setpgid() on short-lived processes, so
remove the setpgid() calls when spawning dispatcher scripts, iptables,
iscsiadmin, and netconf.
2015-01-19 11:29:13 -05:00
Dan Winship
c5b3e93792 core: use GUnixSignalWatchSource to simplify signal handling
Replace the pthread_sigwait()-based signal handling with
g_unix_signal_add()-based handling, and get rid of all the
now-unnecessary calls to nm_unblock_posix_signals() when spawning
subprocesses.

As a bonus, this also fixes the "^C in gdb kills NM too" bug.
2015-01-19 11:29:13 -05:00
Thomas Haller
e439637ada core: declare nm_dns_manager_get() using NM_DEFINE_SINGLETON_GETTER() 2015-01-12 12:10:02 +01:00
Pavel Šimerda
583568e12f dns-manager: don't replace /etc/resolv.conf installed by other tools
Resolves:

 * https://bugzilla.gnome.org/show_bug.cgi?id=732941
 * https://bugzilla.redhat.com/show_bug.cgi?id=1116999

Acked-By: Dan Williams <dcbw@redhat.com>
Acked-By: Thomas Haller <thaller@redhat.com>
2014-12-23 13:34:25 +01:00