Commit graph

24304 commits

Author SHA1 Message Date
Thomas Haller
6662536d44 libnm: include "nm-types.h" in "nm-libnm-utils.h"
We now include "libnm/nm-libnm-utils.h" for all compilation of libnm sources.
Let that one also include "nm-types.h". In the end, it's anyway needed
almost everywhere.
2019-10-18 22:09:18 +02:00
Thomas Haller
4400f6de77 libnm: include "nm-libnm-utils.h" by default in libnm sources
The majority of sources in "libnm/" are implementations of NMObject.
"nm-libnm-utils.h" will contain common definitions for handling such
objects. This means, most of the source files under libnm will require
this include. Include it by default.
2019-10-18 22:09:18 +02:00
Thomas Haller
419ce1178e libnm: move wincaps_to_dash() function to "nm-libnm-utils.h"
We will need it, if only for testing/asserting.
2019-10-18 22:09:18 +02:00
Thomas Haller
166095fe4e libnm: don't use GSimpleAsyncResult for nm_client_new_async()
As we don't have any data or our own, we don't need a
GSimpleAsyncResult/GTask. Just pass the caller's @callback to
g_async_initable_new_async().
2019-10-18 22:09:18 +02:00
Thomas Haller
a5b2ba02ea libnm: add logging NML_DBUS_LOG*() for debugging D-Bus for NMClient
Commonly, a library (like libnm) is not supposed to log anything.
Logging is not a suitable way to notify the calling application
about anything. When something of importance happens, then the
application must be notified via the library's API.

However, logging can be very useful for debugging to see what is going
on. Add a logging macro that by default does nothing, but can be turned
on via an environment variable "LIBNM_CLIENT_DEBUG=debug".

Another point is that libnm relies on the server side NetworkManager
D-Bus interface to be in an expected manner. For example, we require a
D-Bus object "org.freedesktop.NetworkManager" to be present and certain
D-Bus interfaces implemented.

However libnm should treat NetworkManager as external and untrusted component.
That means, we cannot assert against the expectations we have. There are two
reasons for this:

  - a bug in NetworkManager, dbus-daemon or else may cause such errors.
    This must not trigger an assertion failure in the client
    application, at least not unless requested.

  - libnm must be forward and backward compatible against a different
    NetworkManager server version. That is only possibly by ignoring
    anything that is unexpected. Asserting by default might prevent
    to implement API changes, both on libnm and server side.

Note that we also don't notify the calling application via dedicated
API. On the one hand, these things *can* happen. On the other hand, what
would the calling appication do about it anyway? libnm by default must
just behave gracefully and pretend all is good.

For testing, development and debugging that is however not useful. We
want the user to opt in to strict API validation. The user will be able
to do that by setting "LIBNM_CLIENT_DEBUG=warning", which causes API
violations being logged with g_warning(). These are assertions when
running with G_DEBUG=fatal-warnings.

This is inspired by GDBus' G_DBUS_DEBUG variable.

Note that LIBNM_CLIENT_DEBUG environment variables is undocumented, unstable
API. It's used for debugging and testing of the current libnm version at hand.
There is no guaranteed stable behavior how a different libnm version
might behave.
2019-10-18 22:09:18 +02:00
Thomas Haller
27fa6bad0c libnm: add NM_CLIENT_DBUS_NAME_OWNER property
It's not yet implemented. But obviously it's interesting to
get the name owner to which the NMClient is currently connected.

Note only that: the name-owner property really says whether
NM is currently running or not.
2019-10-18 22:09:18 +02:00
Thomas Haller
b2f7197b29 libnm: add NM_CLIENT_DBUS_CONNECTION property
The used GDBusConnection should be configurable when creating the
NMClient instance. Automatically choosing one of the g_bus_get()
singletons is fine by default, but it's an unnecessary limitation.
2019-10-18 22:09:18 +02:00
Thomas Haller
fe24797241 libnm: remember the caller's GMainContext when creating NMClient
We will require this later. The NMClient shall be tied to the GMainContext
at the moment when the instance gets created. This allows the user to have
multiple, indendent NMClient instances (on different threads and GMainContext).

Currently this is still unused, it will be later.
2019-10-18 22:09:18 +02:00
Thomas Haller
ec63919818 libnm/trivial: move code in "nm-client.c" 2019-10-18 22:09:18 +02:00
Thomas Haller
15cc1d8770 libnm: avoid g_object_notify() in favor of _notify()
This looks up the GParamSpec from the obj_properties and is
thus more efficient. Also, the generated _notify() function
has the proper argument type and is thus generally preferable.
2019-10-18 22:09:18 +02:00
Thomas Haller
e761d230c3 libnm: use obj_properties array in libnm and cleanup
This is not merely cosmetic. I will need the obj_properties
array to lookup GParamSpec by their PROP_* enum value. The
alternative would be lookup by name, which is more expensive.
2019-10-18 22:09:18 +02:00
Thomas Haller
aa00469e80 libnm/trivial: rename property enum to match property name 2019-10-18 22:09:18 +02:00
Thomas Haller
389c2ebe8a libnm: fix GObject properties of "NMDeviceModem"
Fixes: f18b09b3f6 ('libnm/modem: add device id getter')
Fixes: 0b3dd18c2b ('libnm/modem: add network id getter')
Fixes: 8e270de05e ('libnm/modem: add APN getter')
2019-10-18 22:09:18 +02:00
Thomas Haller
57c1b03c5c libnm: add G_PARAM_STATIC_STRINGS flag to NM_VPN_SERVICE_PLUGIN_DBUS_WATCH_PEER property 2019-10-18 22:09:18 +02:00
Thomas Haller
f1bd85634a libnm: belatedly add GObject property "NMDeviceOvs{Bridge,Port}:slaves"
Fixes: 5f30a2b525 ('libnm: add accessors for ovs port/bridge slaves')
2019-10-18 22:09:18 +02:00
Thomas Haller
26391a92da libnm: remove unused enum value from "nm-object.c" 2019-10-18 22:09:18 +02:00
Thomas Haller
58a48acfd9 libnm: rework caching singleton value in _nm_dbus_bus_type()
No need for g_once_init_enter(). In case of a race, we can just
twice determine the value. As long as only one thread wins the race,
this is totally fine (also, both threads probably would give the same
result anyway).
2019-10-18 22:09:18 +02:00
Thomas Haller
a57a1ba2fc libnm/tests: add test for checking types
If a "nm_${TYPE}_class_init()" function has a bug, then this
code only runs when the class gets instanciated. And for types
like NMDeviceBridge, that didn't happen for unit tests (so far).

Instanciate all glib types. In the future we may want to perform
additional checks on the types.
2019-10-18 22:09:18 +02:00
Thomas Haller
8f37a0ae0a build: link "nm-enum-types.c" with the base "liblibnm" instead of "libnm"
This way the symbols are also available to the unit tests.
2019-10-18 22:09:18 +02:00
Thomas Haller
69de5ee4e9 shared: move nm_utils_parse_debug_string() from core to shared 2019-10-18 22:09:18 +02:00
Thomas Haller
308beb85fe shared: add nm_c_list_for_each_entry_prev() helper macro
It's non-trivial to get this right. Add the macro for iterating the list
in reverse.
2019-10-18 22:09:18 +02:00
Thomas Haller
c02710bb0f shared: add nm_g_source_destroy_and_unref() helper 2019-10-18 22:09:18 +02:00
Lubomir Rintel
79b383e3b7 merge: branch 'lr/nmcli-d-wifi-show'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/272
2019-10-18 17:39:41 +02:00
Lubomir Rintel
7061341a41 cli: add "nmcli d wifi show"
A quick overview of the currently connected Wi-Fi network, including
credentials. Comes handy if someone wants to connect more devices to
their Hotspot or the same network as they are connected to.
2019-10-18 17:38:57 +02:00
Lubomir Rintel
976eebae73 cli/devices: keep the AddAndActivateInfo alive until the activation ends
In a future commit it will be useful to know whether the activation
details when the activation succeeds.

This also makes the state tracking of the ongoing activation more
elegant, since we got our device and AC neatly packed together and we
can treat their respective state changes consistently.
2019-10-18 17:38:57 +02:00
Lubomir Rintel
8766d05ea9 cli/devices: on connecting a device, don't uselessly look it up from the ac
For quite some time we already pass the AddAndActivateInfo for device
connect too, and that one remembers the device.
2019-10-18 17:38:57 +02:00
Lubomir Rintel
2ca172ebea utils: correct caching of can_show_graphics
It's being forgotten unless it's also static. Spotted by Thomas in the
code that was copied from here.
2019-10-18 17:38:57 +02:00
Beniamino Galvani
a5f22dbc5d dhcp: merge branch 'bg/dhcp-invalid-hostname'
https://bugzilla.redhat.com/show_bug.cgi?id=1744427
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/310
2019-10-18 06:34:54 +02:00
Beniamino Galvani
2da4d54ac3 dhcp: ignore hostname when invalid
The hostname used for DHCP can be the one obtained from the hostnamed
service and is not guaranteed to be valid, at least with systemd
239. Instead of sending an invalid DHCP option to the server or
failing due to later checks in clients, ignore the hostname and log a
warning when it is invalid.

https://bugzilla.redhat.com/show_bug.cgi?id=1744427
2019-10-17 18:05:20 +02:00
Beniamino Galvani
38f942e038 shared: export systemd dns and hostname validation functions 2019-10-17 18:04:29 +02:00
Beniamino Galvani
319a39cac6 shared: fix function return value 2019-10-17 18:04:29 +02:00
Ilya Shipitsin
c0f4c2f2e6 platform: silence cppcheck warning about NULL pointer dereference
found by cppcheck

[src/platform/nm-platform.c:4143] -> [src/platform/nm-platform.c:4141] -> [src/platform/nm-platform.c:3912] -> [src/platform/nm-platform.c:3884]: (warning) Null pointer dereference: addresses

[bgalvani@redhat.com: reworded commit message]

https://github.com/NetworkManager/NetworkManager/pull/353
2019-10-17 15:13:18 +02:00
Thomas Haller
cb4bd173eb libnm: fix nm_device_delete_async() after GDBusConnection rework
Fixes: c1046dd803 ('libnm: implement nm_device_delete()/nm_device_delete_async() by using GDBusConnection directly')
2019-10-17 15:06:24 +02:00
Thomas Haller
198591a694 libnm: merge branch 'th/libnm-no-dbus-codegen-1'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/299
2019-10-16 18:02:42 +02:00
Thomas Haller
558dacce89 libnm: implement nm_client_add_connection*() by using GDBusConnection directly 2019-10-16 08:56:01 +02:00
Thomas Haller
5f31fd3951 libnm: implement nm_client_save_hostname_async() by using GDBusConnection directly 2019-10-16 08:56:01 +02:00
Thomas Haller
90487ef509 shared: allow "NMRefString" typedef to be forward declared by naming the struct 2019-10-16 08:56:00 +02:00
Thomas Haller
c92eb66d38 libnm: implement nm_client_save_hostname() by using GDBusConnection directly 2019-10-16 08:56:00 +02:00
Thomas Haller
356f1f6f33 libnm: implement nm_client_reload_connections_async() by using GDBusConnection directly 2019-10-16 08:56:00 +02:00
Thomas Haller
89c1007f92 libnm: implement nm_client_reload_connections() by using GDBusConnection directly 2019-10-16 08:56:00 +02:00
Thomas Haller
4af6219226 libnm: implement nm_client_load_connections_async() by using GDBusConnection directly 2019-10-16 08:56:00 +02:00
Thomas Haller
d795bcd730 libnm: implement nm_client_load_connections() by using GDBusConnection directly 2019-10-16 08:56:00 +02:00
Thomas Haller
c1046dd803 libnm: implement nm_device_delete()/nm_device_delete_async() by using GDBusConnection directly 2019-10-16 08:56:00 +02:00
Thomas Haller
6ee416d247 libnm: implement nm_device_disconnect()/nm_device_disconnect_async() by using GDBusConnection directly 2019-10-16 08:56:00 +02:00
Thomas Haller
bafabddece libnm: implement nm_device_get_applied_connection()/nm_device_get_applied_connection_async() by using GDBusConnection directly 2019-10-16 08:56:00 +02:00
Thomas Haller
3a66761b92 libnm: implement nm_device_reapply()/nm_device_reapply_async() by using GDBusConnection directly 2019-10-16 08:56:00 +02:00
Thomas Haller
36df8eabe6 libnm: implement nm_remote_connection_get_secrets()/nm_remote_connection_get_secrets_async() by using GDBusConnection directly 2019-10-16 08:56:00 +02:00
Thomas Haller
fb3d91db30 libnm: implement nm_remote_connection_delete()/nm_remote_connection_delete_async() by using GDBusConnection directly 2019-10-16 08:56:00 +02:00
Thomas Haller
dd94a8c0a9 libnm: implement nm_remote_connection_save()/nm_remote_connection_save_async() by using GDBusConnection directly 2019-10-16 08:56:00 +02:00
Thomas Haller
eff5e730ef libnm: implement nm_remote_connection_update2() by using GDBusConnection directly
Also, implement nm_remote_connection_commit_changes_async() by calling
nm_remote_connection_update2(). It already was also calling the
Update2() D-Bus method.
2019-10-16 08:56:00 +02:00