Commit graph

470 commits

Author SHA1 Message Date
Thomas Haller dc40288849 all: use NM_CACHED_QUARK_FCN() to define cached quarks 2017-02-10 14:33:52 +01:00
Thomas Haller 7d6b8bab70 all: use NM_CACHED_QUARK_FCN() instead of G_DEFINE_QUARK()
I think NM_CACHED_QUARK_FCN() is better because:

- the implementation is in our hand, meaning it is clear that
  putting a "static" before NM_CACHED_QUARK_FCN() is guaranteed to
  work -- without relying on G_DEFINE_QUARK() to be defined in a way
  that this works (in fact, we currently never do that and instead
  make all functions non-static).
- it does not construct function names by appending "_quark".
  Thus you can grep for the entire function name and finding
  the place where it is implemented.
- same with the stings, where the new macro doesn't stringify the
  argument, which is less surpising. Again, now you can grep
  for the string including the double quoting.

(yes, I really use grep to understand the source-code)
2017-02-10 14:33:52 +01:00
Thomas Haller 7c6c8f0d8b all: cleanup switch fall-through comments for -Wimplicit-fallthrough warning
The -Wimplicit-fallthrough=3 warning is quite flexible of accepting
a fall-through warning.

Some comments were missing or not detected correctly.

Thereby, also change all other comments to follow the exact
same pattern.
2017-02-06 16:45:20 +01:00
Lubomir Rintel 0822cbb032 libnm/object: lower the severity of the dangling object warning
The user can't do much about it and we can recover. This is a temporary
measure to avoid unnecessarily bothering the user.

(cherry picked from commit 7fec0755c9)
2017-01-19 16:15:42 +01:00
Lubomir Rintel b916d9dfe0 build: fix build with older gi
Fixes: 6c96aafaa9
(cherry picked from commit 22722b7732)
2017-01-19 14:18:26 +01:00
Lubomir Rintel 2ee8462774 build: make the doc generator find the right libnm.so
At some point gobject-introspection added an API to add a library path
and stopped honoring the LD_LIBRARY_PATH (a bug, according to GI
documentation?).

(cherry picked from commit 6c96aafaa9)
2017-01-19 11:21:38 +01:00
Jiří Klimeš 215152d0a1 libnm: (trivial): add missing return description in comment block 2017-01-17 10:34:16 +01:00
Beniamino Galvani d252a99fa2 libnm-core: add NMSettingMacsec
The new NMSettingMacsec contains information necessary to establish a
MACsec connection. At the moment we support two different MACsec
modes, both using wpa_supplicant: PSK and EAP.

PSK mode is based on a static CAK key for the MACsec key agreement
protocol, while EAP mode derives keys from a 802.1x authentication and
thus requires the presence of a NMSetting8021x in the connection.
2017-01-16 17:37:14 +01:00
Beniamino Galvani 67adbda83e core,libnm: introduce NMDeviceMacsec
At the moment the device only exposes the current link status, but
cannot create new links.
2017-01-16 17:37:14 +01:00
Lubomir Rintel 84c57c34bc libnm-core/8021x: add pkcs11: scheme for certificates and keys
The getters just return the whole URI as-is, without any mangling.
2017-01-06 15:56:11 +01:00
Lubomir Rintel ac0563d784 libnm-core: add nm_utils_is_valid_iface_name()
Version of nm_utils_iface_valid_name() with error reporting.
2017-01-06 15:11:56 +01:00
Thomas Haller 16aeac5c3e libnm: add nm_utils_version() function to query libnm version at runtime
if (nm_utils_version () < NM_ENCODE_VERSION (1, 5, 0))
        g_error ("Requires at least version 1.5.0");
2016-12-20 16:51:58 +01:00
Thomas Haller fee104621e libnm/dns: fix memleak in demarshal_dns_configuration
Fixes: a8d6005256
2016-12-14 13:19:37 +01:00
Beniamino Galvani a8d6005256 libnm: implement support for DNS manager properties 2016-12-12 22:06:24 +01:00
mirh 48402cd526 build: fix compilation with Python3
has_key() has long been dropped
https://docs.python.org/3.1/whatsnew/3.0.html#builtins

Should still work with anything from 2.3 onwards

https://github.com/NetworkManager/NetworkManager/pull/11
2016-11-29 22:03:01 +01:00
Jiří Klimeš 544f7d3683 agent: don't clear "error", g_simple_async_result_take_error() overtakes it
From valgrind:
==21921== Invalid free() / delete / delete[] / realloc()
==21921==    at 0x4C2CD5A: free (vg_replace_malloc.c:530)
==21921==    by 0x81C4F2D: g_free (gmem.c:189)
==21921==    by 0x81AB021: g_error_free (gerror.c:491)
==21921==    by 0x81AB325: g_clear_error (gerror.c:674)
==21921==    by 0x767B555: reg_request_cb (nm-secret-agent-old.c:616)
==21921==    by 0x7A211F2: g_task_return_now (gtask.c:1107)
==21921==    by 0x7A21228: complete_in_idle_cb (gtask.c:1121)
==21921==    by 0x81BF6B9: g_main_dispatch (gmain.c:3154)
==21921==    by 0x81BF6B9: g_main_context_dispatch (gmain.c:3769)
==21921==    by 0x81BFA6F: g_main_context_iterate.isra.29 (gmain.c:3840)
==21921==    by 0x81BFB1B: g_main_context_iteration (gmain.c:3901)
==21921==    by 0x7A4748C: g_application_run (gapplication.c:2381)
==21921==    by 0x118AEF: main (main.c:81)

It caused memory corruption and may result in strange nm-applet crashes.
2016-11-25 14:31:47 +01:00
Lubomir Rintel 743d372d72 libnm/vpn-service-plugin: transition to STOPPED state from INIT too
We may want to stop the plugin before we started connecting e.g. when the
plugin NeedsSecrets but we can't supply them.
2016-11-24 14:13:13 +01:00
Lubomir Rintel 972e0d2803 all: rename the introspection data to use the interface paths in names
This makes it easier to install the files with proper names.
Also, it makes the makefile rules slightly simpler.

Lastly, the documentation is now generated into docs/api, which makes it
possible to get rid of the awkward relative file names in docbook.
2016-11-23 15:43:42 +01:00
Lubomir Rintel 6143e71464 libnm/generate-plugin-docs: don't replace newlines with spaces
That serves no purpose whatsoever.
2016-11-21 18:34:50 +01:00
Lubomir Rintel 3b64dc9cbd libnm/generate-plugin-docs: drop YAML dependency
It makes little sense to produce a YAML and then decompose it.
2016-11-21 18:15:42 +01:00
Lubomir Rintel cb61dd113c libnm/client: do not autostart the service
Apparently, the client is used by the services we depend on (firewalld),
and an attempt to start the service would deadlock them.

This was an accidental change anyway.

Related firewalld change: https://github.com/t-woerner/firewalld/pull/171
2016-11-16 19:52:24 +01:00
Lubomir Rintel 55ba649b0e libnm: fixup accidental proxy removal
Fixes: 4b7b518958
2016-11-14 20:46:27 +01:00
Lubomir Rintel 4b7b518958 libnm: avoid leaking the interface proxies
_nm_object_get_proxy()'s semantics changed with the object-manager
branch merge: it now takes a reference.
2016-11-14 20:22:23 +01:00
Lubomir Rintel 446858cf8d libnm/client: unref all the objects on dispose
We created them, we own them.
2016-11-14 20:22:23 +01:00
Lubomir Rintel dfa90861e8 libnm/tests: increase timeout in nm-client test
Otherwise the test may fail in valgrind.
2016-11-14 20:22:23 +01:00
Beniamino Galvani 5dfc571971 libnm: initialize @device_type of device objects
Before switching to the ObjectManager, the D-Bus property was used to
decide the actual type of the device and the property set manually by
each subclass in its _init() function. Now we determine objects type
based on their D-Bus interface and therefore we can handle the
property like all others, ensuring that we return a known value in
get_property() to avoid warnings in GLib.

This fixes the missing initialization of the property which causes
regressions on clients as nm-applet.

Fixes: 1f5b48a59e
2016-11-14 13:38:26 +01:00
Lubomir Rintel 32d60ccc6f libnm/nm-object: gracefully skip unknown objects
They indicate a server bug (a dangling path of an object that does not
exist). The best we can do probably is to just ignore them and warn.

Based-on-patch-by: Dan Williams <dcbw@redhat.com>
2016-11-11 17:57:09 +01:00
Lubomir Rintel 9d31d09bcb libnm/manager: don't fail the object if we can't get the permissions
It's not fatal and the NMObject's initialization shouldn't fail. Just
write out a polite warning and leave the permissions in UNKNOWN state.
2016-11-11 17:42:07 +01:00
Lubomir Rintel 32dfa563d1 libnm/nm-manager: don't block the object creation on permissions
The GetPermissions call is very expensive (~400ms here, an extra
NM->polkit call for every known permission while polkit being really
slow to answer) yet seldom needed.

There's no methods to access the permissions -- they're only
communicated via signals.

Unfortunately, we don't know when a signal is hooked, so we still need
to kick of the call. Nevertheless, we don't need to wait for it to
finish.
2016-11-11 16:18:03 +01:00
Lubomir Rintel d441271109 libnm/client: drop some unneeded includes 2016-11-10 18:11:15 +01:00
Lubomir Rintel 1f5b48a59e libnm: use the o.fd.DBus.ObjectManager API for object management
This speeds up the initial object tree load significantly. Also, it
reduces the object management complexity by shifting the duties to
GDBusObjectManager.

The lifetime of all NMObjects is now managed by the NMClient via the
object manager. The NMClient creates the NMObjects for GDBus objects,
triggers the initialization and serves as an object registry (replaces
the nm-cache).

The ObjectManager uses the o.fd.DBus.ObjectManager API to learn of the
object creation, removal and property changes. It takes care of the
property changes so that we don't have to and lets us always see a
consistent object state.  Thus at the time we learn of a new object we
already know its properties.

The NMObject unfortunately can't be made synchronously initializable as
the NMRemoteConnection's settings are not managed with standard
o.fd.DBus Properties and ObjectManager APIs and thus are not known to
the ObjectManager.  Thus most of the asynchronous object property
changing code in nm-object.c is preserved. The objects notify the
properties that reference them of their initialization in from their
init_finish() methods, thus the asynchronously created objects are not
allowed to fail creation (or the dependees would wait forever). Not a
problem -- if a connection can't get its Settings, it's either invisible
or being removed (presumably we'd learn of the removal from the object
manager soon).

The NMObjects can't be created by the object manager itself, since we
can't determine the resulting object type in proxy_type() yet (we can't
tell from the name and can't access the interface list). Therefore the
GDBusObject is coupled with a NMObject later on.

Lastly, now that all the objects are managed by the object manager, the
NMRemoteSettings and NMManager go away when the daemon is stopped. The
complexity of dealing with calls to NMClient that would require any of
the resources that these objects manage (connection or device lists,
etc.) had to be moved to NMClient. The bright side is that his allows
for removal all of the daemon presence tracking from NMObject.
2016-11-10 16:48:48 +01:00
Lubomir Rintel ff3eb24c15 libnm: change the secret agent to use the generated GDBus bindings
It allows us to drop _nm_dbus_register_proxy_type() and _nm_dbus_new_proxy_*()
once they're not used by the rest of libnm anymore.
2016-11-10 16:48:48 +01:00
Lubomir Rintel bbed63213a libnm/tests: work around ObjectManager bogus warning
We should eventually fix this in Gio, but I guess we need to keep the
workaround for the time being anyway.
2016-11-10 16:48:48 +01:00
Lubomir Rintel ed21a820a7 libnm/tests: connection might not be gone at the time manager signals removal
The assumption is not too useful to the library user anyway -- it could easily
be that there's some other link to the object in the object tree.

More importantly, when the objects are managed by the object manager,
we don't destroy the object until we see it actually removed on the
D-Bus. That makes more sense anyway.
2016-11-10 16:48:47 +01:00
Lubomir Rintel 7007c9853c libnm: order the property updates
Don't let a later property update finish than the sooner one.

This wouldn't happen most of time, apart from a special case when the
latter update of a object array property is to an empty list.
In that case the latter update would complete sooner and when the
earlier update finishes the list would contain objects which are
supposed to be gone already.
2016-11-10 16:48:47 +01:00
Lubomir Rintel df46c59775 nm-object: initialize the object buffer to zero 2016-11-10 16:48:47 +01:00
Beniamino Galvani 75127b1348 libnm: add missing device includes in NetworkManager.h
And also sort the setting includes alphabetically.
2016-11-09 17:45:34 +01:00
Thomas Haller e028edd1c5 libnm/trivial: fix code comment for internal header libnm/nm-manager.h 2016-11-08 14:27:07 +01:00
Thomas Haller 95ab69b761 libnm: coerce empty strings to NULL for D-Bus properties
On D-Bus level, string (s) or object paths (o) cannot be NULL.
Thus, whenver server exposes such an object, it gets automatically
coerced to "" or "/", respectively.

On client side, libnm should coerce certain properties back, for which
"" is just not a sensible value.

For example, an empty NM_DEVICE_ETHERNET_HW_ADDRESS should be instead
exposed as NULL.

Technically, this is an API change. However, all users were well advised
to expect both NULL and "" as possible return values and handle them
accordingly.
2016-10-24 10:14:02 +02:00
Thomas Haller 21d7aa9204 libnm: minor refactoring by using g_clear_object() and nm_str_not_empty() 2016-10-24 10:14:02 +02:00
Thomas Haller c4198d45e3 libnm: avoid possibly NULL address for NMDeviceVlan calling nm_utils_hwaddr_matches() 2016-10-24 10:14:02 +02:00
Thomas Haller 7eb054d099 libnm: fix memleak in NMDeviceVxlan 2016-10-24 10:14:02 +02:00
Thomas Haller 7aefbcb622 build: merge "libnm/tests/Makefile.am" into toplevel Makefile 2016-10-19 17:16:08 +02:00
Thomas Haller 9061432d55 build: merge "libnm/Makefile.am" into toplevel Makefile 2016-10-19 17:16:07 +02:00
Thomas Haller cd98705d21 tests: combine "run-test-valgrind.sh" and "run-test-dbus-session.sh" in "run-nm-test.sh"
No need to have two test-runners. Combine them, and call tests always
via "tools/run-nm-test.sh".

Yes, this brings an overhead, that we now always invoke the test with
a test wrapper script, also --without-vagrind. Previously, that was only
necessary for libnm tests that require their own D-Bus session.

Later we will do non-recursive Makefiles, thus all tests should have the
same LOG_COMPILER.
2016-10-19 15:26:30 +02:00
Thomas Haller 274de2555b build/trivial: rename VALGRIND_RULES in Makefile.am to NM_LOG_COMPILER 2016-10-19 15:26:30 +02:00
Beniamino Galvani 51d7a18f2e libnm-core: introduce connection.autoconnect-retries property
While technically it's already possible to implement a fail-over
mechanism using multiple connections (for example, defining a higher
priority DHCP connection with short DHCP timeout and a lower priority
one with static address), in practice this doesn't work well as we try
to autoactivate each connection 4 times before switching to the next
one.

Introduce a connection.autoconnect-retries property that can be used
to change the number of retries. The special value 0 means infinite
and can be used to try the connection forever. A -1 value means the
global configured default, which is equal to 4 unless overridden.

https://bugzilla.gnome.org/show_bug.cgi?id=763524
2016-10-16 10:08:13 +02:00
Beniamino Galvani 0a61317870 libnm: disconnect devices' signals when disposing manager
We connect signal handlers to devices when they appear, but don't
disconnect the handlers when the manager instance is destroyed. This
can cause crashes as device_ac_changed() is called on an invalid
manager instance.

Disconnect the handlers from dispose().

https://bugzilla.redhat.com/show_bug.cgi?id=1383758
2016-10-14 10:44:18 +02:00
Thomas Haller c7853a1415 build: add extra dependencies for linker-version-script for NetworkManager and libnm.so 2016-10-14 10:33:30 +02:00
Thomas Haller 0e47b327dc libnm: move backported symbols from libnm-core to libnm
Backported symbols only make sense for libnm itself, not for
libnm-core which is statically linked with NetworkManager and
nm-ifcace-helper. Declaring the symbols in libnm-core, means
that NetworkManager binary also contains them, although there
are not used.

Move them to libnm.
2016-10-13 21:33:33 +02:00