Commit graph

98 commits

Author SHA1 Message Date
Dan Winship 6793a32a8c libnm: port to GDBus
Port libnm-core/libnm to GDBus.

The NetworkManager daemon continues to use dbus-glib; the
previously-added connection hash/variant conversion methods are now
moved to NetworkManagerUtils (along with a few other utilities that
are now only needed by the daemon code).
2014-09-18 11:51:09 -04:00
Dan Winship acf86f68b3 libnm-core: change connection hash tables to variants in API
In preparation for porting to GDBus, make nm_connection_to_dbus(),
etc, represent connections as GVariants of type 'a{sa{sv}}' rather
than as GHashTables-of-GHashTables-of-GValues.

This means we're constantly converting back and forth internally, but
this is just a stepping stone on the way to the full GDBus port, and
all of that code will go away again later.
2014-09-18 11:51:09 -04:00
Dan Winship 8d26c45184 dispatcher: make test-dispatcher-envp not take an argument
Compile srcdir into test-dispatcher-envp rather than passing it on the
command-line, to make it easier to run by hand, and so we can use
automake's TESTS support.
2014-09-18 11:34:21 -04:00
Dan Winship 1a5cfc1f45 dispatcher: port to GDBus
Port nm-dispatcher to GDBus, mostly, using dbus-glib's GVariant
utilities to translate the return value of nm_connection_to_dbus().
2014-09-18 11:26:59 -04:00
Dan Winship 408e86dd35 dispatcher: trivial code rearrangement
Reorganize some code in preparation for the GDBus port. (Most of the
diff is actually just reindentation.)

This also makes explicit something that was probably a bug;
IP4_NUM_ROUTES is always set, even if it's "0" (while the same is not
true of IP6_NUM_ROUTES). (This behavior is preserved for
compatibility.)
2014-09-18 11:04:26 -04:00
Dan Winship 4fab71b466 callouts: port nm-avahi-autoipd.action to GDBus 2014-09-18 11:04:25 -04:00
Dan Winship 773d3f0ab6 libnm-core: rename NMConnection to/from_hash methods
Rename nm_connection_to_hash() to nm_connection_to_dbus(), and
nm_connection_new_from_hash() to nm_connection_new_from_dbus(). In
addition to clarifying that this is specifically the D-Bus
serialization format, these names will also work better in the
GDBus-based future where the serialization format is GVariant, not
GHashTable.

Also, move NMSettingHashFlags to nm-connection.h, and rename it
NMConnectionSerializationFlags.
2014-09-04 09:17:36 -04:00
Thomas Haller e1de236db1 build: add configure option not to install udev rules
Previously, user could only change the udev base directory,
but not disabling installation entirely.

Support this now with:
  ./configure --with-udev-dir=no
or
  ./configure --without-udev-dir

Also, just passing '--with-udev-dir' equals '--with-udev-dir=yes'.
Treat 'yes' equal to the default '/lib/udev'.

Also, check that the path is an absolute path starting with a '/'.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-08-26 19:37:51 +02:00
Thomas Haller ef32da01fa all: add nm-core-internal.h header
Add a header file to expose private utility functions from libnm-core
that can be used by NetworkManager (core) and libnm.so. The header
is also used to give privileged access to libnm-core. Since NM links
statically, these functions are not exported and not part of public ABI.

This also removes the NM_UTILS_PRIVATE_CALL() macro and libnm.so no
longer exports nm_utils_get_private().

Before, this functionality was partly declared in nm-utils-private.h.
This was wrong because nm-utils-private.h is for functionality
entirely private to libnm-core.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-08-22 15:22:16 +02:00
Dan Winship e1ba13a426 libnm-core, libnm, core: make NMConnection an interface
The fact that NMRemoteConnection has to be an NMConnection and
therefore can't be an NMObject means that it needs to reimplement bits
of NMObject functionality (and likewise NMObject needs some special
magic to deal with it). Likewise, we will need a daemon-side
equivalent of NMObject as part of the gdbus port, and we would want
NMSettingsConnection to be able to inherit from this as well.

Solve this problem by making NMConnection into an interface, and
having NMRemoteConnection and NMSettingsConnection implement it. (We
use some hacks to keep the GHashTable of NMSettings objects inside
nm-connection.c rather than having to be implemented by the
implementations.)

Since NMConnection is no longer an instantiable type, this adds
NMSimpleConnection to replace the various non-D-Bus-based uses of
NMConnection throughout the code. nm_connection_new() becomes
nm_simple_connection_new(), nm_connection_new_from_hash() becomes
nm_simple_connection_new_from_hash(), and nm_connection_duplicate()
becomes nm_simple_connection_new_clone().
2014-08-16 10:17:53 -04:00
Dan Winship c81fb49aa5 all: fix up multiple-include-guard defines
Previously, src/nm-ip4-config.h, libnm/nm-ip4-config.h, and
libnm-glib/nm-ip4-config.h all used "NM_IP4_CONFIG_H" as an include
guard, which meant that nm-test-utils.h could not tell which of them
was being included (and so, eg, if you tried to include
nm-ip4-config.h in a libnm test, it would fail to compile because
nm-test-utils.h was referring to symbols in src/nm-ip4-config.h).

Fix this by changing the include guards in the non-API-stable parts of
the tree:

  - libnm-glib/nm-ip4-config.h remains   NM_IP4_CONFIG_H
  - libnm/nm-ip4-config.h now uses     __NM_IP4_CONFIG_H__
  - src/nm-ip4-config.h now uses       __NETWORKMANAGER_IP4_CONFIG_H__

And likewise for all other headers.

The two non-"nm"-prefixed headers, libnm/NetworkManager.h and
src/NetworkManagerUtils.h are now __NETWORKMANAGER_H__ and
__NETWORKMANAGER_UTILS_H__ respectively, which, while not entirely
consistent with the general scheme, do still mostly make sense in
isolation.
2014-08-16 10:17:14 -04:00
Dan Winship d0b05b34d5 libnm: add NetworkManager.h, disallow including individual headers
Add NetworkManager.h, which includes all of the other NM header, and
require all external users of libnm to use that rather than the
individual headers.

(An exception is made for nm-dbus-interface.h,
nm-vpn-dbus-interface.h, and nm-version.h, which can be included
separately.)
2014-08-01 14:34:40 -04:00
Dan Winship 3ddce74803 libnm: rename NetworkManager.h and NetworkManagerVPN.h
"NetworkManager.h"'s name (and non-standard capitalization) suggest
that it's some sort of high-level super-important header, but it's
really just low-level D-Bus stuff. Rename it to "nm-dbus-interface.h"
and likewise "NetworkManagerVPN.h" to "nm-vpn-dbus-interface.h"
2014-08-01 14:34:40 -04:00
Dan Winship f441cf2b90 libnm: consistently use "INTERFACE" rather than "IFACE" in macros
Most D-Bus interface name macros used "INTERFACE" in their name (eg,
NM_DBUS_INTERFACE), but a few used "IFACE" instead (eg,
NM_DBUS_IFACE_SETTINGS). Make them consistent.
2014-08-01 14:34:06 -04:00
Dan Winship a7c4d53d03 all: port everything to libnm
Since the API has not changed at this point, this is mostly just a
matter of updating Makefiles, and changing references to the library
name in comments.

NetworkManager cannot link to libnm due to the duplicated type/symbol
names. So it links to libnm-core.la directly, which means that
NetworkManager gets a separate copy of that code from libnm.so.
Everything else links to libnm.
2014-08-01 14:34:05 -04:00
Dan Winship 30c74c6007 build: more srcdir!=builddir fixes
nm-version.h was getting disted, making srcdir!=builddir work for
tarball builds, but not for git builds.

Also, remove "-I${top_builddir}/include" from all Makefile.ams, since
there's nothing generated in include/ any more.
2014-07-15 11:37:19 -04:00
Thomas Haller 02747203c6 dispatcher: silence warning about sub-directories in dispatcher directory
Especially now that we have the 'pre-up.d/' and 'pre-down.d/' directories,
silently skip over any sub directories inside the dispatcher directory.

Fixes warning:
  nm-dispatcher: Cannot execute '/etc/NetworkManager/dispatcher.d/pre-up.d': not a regular file.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-17 19:15:31 +02:00
Thomas Haller 589272facf dispatcher: fix leak in callouts/nm-dispatcher
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-17 19:09:56 +02:00
Thomas Haller c8e7953333 dispatcher/trivial: rename variables for script directory to NMD_SCRIPT_DIR_* 2014-06-16 19:18:57 +02:00
Dan Williams 33e5e1c500 dispatcher: don't warn on non-critical missing directory error 2014-06-06 18:28:03 -05:00
Thomas Haller fb88ec99f1 build: create dispatcher directories pre-down.d and pre-up.d
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-07 01:17:16 +02:00
Dan Williams 02252224e2 dispatcher: bump overall timeout to 10 minutes (rh #982734) (rh #1048345)
Since NM now handles long-running dispatcher scripts better, allow them
to run for really long times.
2014-06-06 13:43:47 -05:00
Dan Williams fd5761ecb2 dispatcher: don't use NULL error domains
glib doesn't like it, plus we don't use the error anyway, so just
return the constant error string.
2014-06-06 13:43:47 -05:00
Dan Williams 1383f4bc14 dispatcher: use separate directories for pre-up/pre-down events
To ensure that NetworkManager does not block needlessly for events
which have no scripts, require scripts that respond to blocking
events to opt into the action.
2014-06-06 13:43:46 -05:00
Dan Williams 5150cb88c2 dispatcher: only dispatch if scripts exist
If there are no dispatcher scripts, don't bother dispatching any
events.  This saves some time configuring networking if the event
would have no effect anyway.
2014-06-06 13:43:45 -05:00
Dan Williams 4cc13befd3 dispatcher: rename executable to 'nm-dispatcher' 2014-06-06 13:43:45 -05:00
Jiří Klimeš 98ae6e06d2 all: g_type_init() has been deprecated in GLib 2.35.0
g_type_init() deprecation:
https://bugzilla.gnome.org/show_bug.cgi?id=686161
2014-05-27 16:58:21 +02:00
Thomas Haller ab0c37d042 dispatcher/test: fix tests after adding PATH environment variable
These tests were broken by commit 45ed459ae3.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-04-22 12:24:25 +02:00
Dan Winship 3b197de59f dispatcher: add better debugging
Add LOGD_DISPATCH, and if it's set to DEBUG, tell nm-dispatcher to log
additional information about each script it runs.
2014-04-18 11:33:15 -04:00
Dan Winship 45ed459ae3 dispatcher: Leave PATH set in the dispatcher script environment
https://bugzilla.gnome.org/show_bug.cgi?id=724657
2014-04-18 11:32:13 -04:00
Dan Winship 731ca771f8 dispatcher: only dispatch one request at a time (rh #1061212)
The dispatcher only runs one script at a time for any given request,
but would dispatch multiple requests in parallel. So if a device was
brought up and then back down quickly, it could end up dispatching the
"down" scripts while the "up" scripts were still running. Or if two
devices came up at the same time, two instances of the same "up"
script might run at the same time, which could cause problems if they
both tried to modify the same file.

Fix this by only dispatching the scripts for a single request at a
time.
2014-04-18 11:32:09 -04:00
Dan Winship d9334503d7 dispatcher: bump script timeout up to 20 seconds (rh #1048345)
The dispatcher would kill scripts after 3 seconds, but on
heavily-loaded machines, that was sometimes too short even for simple
scripts. Bump the timeout up to 20 seconds instead (and change the
10-second quit-on-idle timer to not run when a script is running).

Also change the D-Bus call timeout in the daemon to 30 seconds, so
that it only triggers if something goes really wrong and the action
timeout fails.
2014-04-18 11:29:14 -04:00
Dan Winship 1d0b50c2c4 build: add some missing -DNM_VERSION_MAX_ALLOWED
Add -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE to a bunch of
Makefile.ams that were missing it and might eventually need it.
2014-04-07 11:30:18 -04:00
Dan Winship 9c4d86ee80 libnm-util, libnm-glib: add versioned deprecation/availability macros
Add versioned NM_DEPRECATED_IN_* and NM_AVAILABLE_IN_* macros, and tag
new/deprecated functions accordingly. (All currently-deprecated
functions are assumed to have been deprecated in 0.9.10.)

Add NM_VERSION_MIN_REQUIRED and NM_VERSION_MAX_ALLOWED macros which
can be set to determine which versions will cause warnings.

With the current settings, external consumers of the
libnm-util/libnm-glib APIs will have MIN_REQUIRED and MAX_ALLOWED both
set to NM_VERSION_0_9_8 by default, meaning they will get warnings
about functions added in 0.9.10. NM internally sets
NM_VERSION_MAX_ALLOWED to NM_VERSION_NEXT_STABLE to ensure that it is
always allowed to use all APIs.
2014-02-13 11:24:37 -05:00
Thomas Haller 6f2cfe263e all: refactor to make use of nm_utils_inet[46]_ntop functions
https://bugzilla.gnome.org/show_bug.cgi?id=711684

Signed-off-by: Thomas Haller <thaller@redhat.com>
2013-12-09 17:21:22 +01:00
Thomas Haller 073cc01f52 dispatcher: fix crash while logging from signal handler
Bug rh#1017884 describes a crash, where dbus_init() failed, which causes
a g_warning(). While writing the warning, a SIGTERM hit, and the
signal_handler() tries to call again g_message().

The logging functions of glib are not reentrant and call abort() when
invoked recursivly. The solution, is to use g_unix_signal_add, which
will dispatch the handler on the mainloop asynchronously.

This bug is not that serious, because the dispatcher was about to
terminate anyway. However, it gets registered as a crash by the system
(ABRT).

https://bugzilla.redhat.com/show_bug.cgi?id=1017884

Signed-off-by: Thomas Haller <thaller@redhat.com>
2013-11-19 00:20:12 +01:00
Thomas Haller f059298896 trivial: whitespace fix
Signed-off-by: Thomas Haller <thaller@redhat.com>
2013-11-07 21:32:08 +01:00
Thomas Haller 3eb1d5e902 core: cleanup freeing of glib collections of pointers
When freeing one of the collections such as GArray, GPtrArray, GSList,
etc. it is common that the items inside the connections must be
freed/unrefed too.

The previous code often iterated over the collection first with
e.g. g_ptr_array_foreach and passing e.g. g_free as GFunc argument.
For one, this has the problem, that g_free has a different signature
GDestroyNotify then the expected GFunc. Moreover, this can be
simplified either by setting a clear function
(g_ptr_array_set_clear_func) or by passing the destroy function to the
free function (g_slist_free_full).

Signed-off-by: Thomas Haller <thaller@redhat.com>
2013-10-22 19:53:57 +02:00
Thomas Haller e670528778 dispatcher: fix memory leak in nm-dispatcher-action
Signed-off-by: Thomas Haller <thaller@redhat.com>
2013-10-22 19:53:46 +02:00
Dan Winship bfce3f7dc8 build: switch from $(INCLUDES) to $(AM_CPPFLAGS) to make automake happy
Unfortunately, $(AM_CPPFLAGS) gets overridden by per-target _CPPFLAGS
variables, which $(INCLUDES) did not, so this requires some additional
changes.

In most places, I have just gotten rid of the per-target _CPPFLAGS
variables; in directories with a single target, the per-target
variable is unnecessary, and in directories with multiple targets, the
per-target variable is often undesirable, since it forces some files
to be compiled twice, even though there ends up being no difference
between the two files.
2013-08-22 11:49:16 -04:00
Pavel Šimerda 320a9d16a3 all: replace struct in_addr with guint32 2013-08-03 00:15:07 -05:00
Jiří Klimeš 12955fcda6 dispatcher: fix tests after ac536c2124
We need to use G_TYPE_STRV instead of DBUS_TYPE_G_ARRAY_OF_STRING, because
G_TYPE_STRV will be the type that will come to the dispatcher over D-Bus.
2013-06-24 13:57:52 +02:00
Tomas Hozza ac536c2124 dispatcher: expose domains in IP4/6 config
Previously the function add_domains() expected the
"domains" value to be of type DBUS_TYPE_G_ARRAY_OF_STRING
but the value is in fact of type G_TYPE_STRV. Also
added check to log critical message in case of "val"
not holding G_TYPE_STRV type.

This caused dispatcher not to export IPx_DOMAINS
environment variable.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2013-06-21 16:27:23 -05:00
Dan Williams 06a415d9ea systemd: add service for dispatcher (rh #948433) 2013-06-03 10:53:07 -05:00
Dan Williams b69171061c dhcp: use private socket to return status if available
Allows DHCP to work when a bus daemon isn't running.  This also
fixes a race condition where when multiple interfaces are attempting
to get a DHCP lease at the same time, if one DHCP client instance
triggers the callout, that instance gets the bus name, and any
other client triggering the callout at that time will fail because
the bus name is already taken.  Since this commit allows using
a private socket, where no process has a bus name, this race is
avoided.

Also move the DHCP helper from callouts/ to src/dhcp-manager/ to
consolidate all the DHCP stuff and clean up some of the helper's
code.
2013-04-08 11:30:31 -05:00
Jiří Klimeš 82fb1978a4 all: use G_VALUE_INIT to initialize GValue variables
It makes the initializations more explicit.
G_VALUE_INIT is available since glib 2.30, and NM now require glib >= 2.32
2013-03-25 08:41:18 +01:00
Dan Winship f936400c38 tests: clean up gtester usage
Use g_test_add_func() and g_test_add_data_func() to simplify the test
cases, getting rid of the GLIB_CHECK_VERSION calls in the process.
2013-02-26 13:07:33 +01:00
Dan Winship ed9e2d8377 build: avoid GValueArray deprecation warnings
Avoid warnings about GValueArray being deprecated by adding macros
that wrap G_GNUC_BEGIN_IGNORE_DEPRECATIONS /
G_GNUC_END_IGNORE_DEPRECATIONS around the GValueArray calls.
2013-02-26 13:07:33 +01:00
Pavel Šimerda faa1bcb540 build: improve documentation and test configure options
Use --enable-doc and --enable-tests instead of --with-docs and
--with-tests. This is consistent with other features and with
--enable-gtk-doc option. Support current variants as fallback.

Don't build tests unless --enable-tests is specified.
2012-11-13 20:23:06 +01:00
Pavel Šimerda d82669d3fd build: unify NetworkManager path handling (some paths are changed)
Use autoconf/automake variables for NetworkManager paths. Use
NetworkManager subdirectory where appropriate.

Files in /var/run (or /run on some distros) are moved into a separate
directory as is usual with other daemons. It makes the filesystem
more readable and file prefixing unnecessary.

/var/run/NetworkManager.pid -> /var/run/NetworkManager/NetworkManager.pid
/var/run/nm-dns-dnsmasq.pid -> /var/run/NetworkManager/dnsmasq.pid
/var/run/nm-dns-dnsmasq.conf -> /var/run/NetworkManager/dnsmasq.conf

The /var/run/NetworkManager directory is created at runtime, if it doesn't
exist.

Note: Path-based security policies like SELinux and AppArmor may need to
be adapted.
2012-11-05 14:01:47 +01:00