Commit Graph

95 Commits

Author SHA1 Message Date
Javier Arteaga
1427719116 libnm: introduce NMDeviceWireGuard 2018-08-06 08:34:27 +02:00
Thomas Haller
e1c7a2b5d0 all: don't use gchar/gshort/gint/glong but C types
We commonly don't use the glib typedefs for char/short/int/long,
but their C types directly.

    $ git grep '\<g\(char\|short\|int\|long\|float\|double\)\>' | wc -l
    587
    $ git grep '\<\(char\|short\|int\|long\|float\|double\)\>' | wc -l
    21114

One could argue that using the glib typedefs is preferable in
public API (of our glib based libnm library) or where it clearly
is related to glib, like during

  g_object_set (obj, PROPERTY, (gint) value, NULL);

However, that argument does not seem strong, because in practice we don't
follow that argument today, and seldomly use the glib typedefs.
Also, the style guide for this would be hard to formalize, because
"using them where clearly related to a glib" is a very loose suggestion.

Also note that glib typedefs will always just be typedefs of the
underlying C types. There is no danger of glib changing the meaning
of these typedefs (because that would be a major API break of glib).

A simple style guide is instead: don't use these typedefs.

No manual actions, I only ran the bash script:

  FILES=($(git ls-files '*.[hc]'))
  sed -i \
      -e 's/\<g\(char\|short\|int\|long\|float\|double\)\>\( [^ ]\)/\1\2/g' \
      -e 's/\<g\(char\|short\|int\|long\|float\|double\)\>  /\1   /g' \
      -e 's/\<g\(char\|short\|int\|long\|float\|double\)\>/\1/g' \
      "${FILES[@]}"
2018-07-11 12:02:06 +02:00
Lubomir Rintel
3cd9322298 libnm: add support form 6LoWPAN devices 2018-06-26 16:21:55 +02:00
Lubomir Rintel
a3baf1ca21 libnm: add support for WPAN devices 2018-06-26 16:21:55 +02:00
Thomas Haller
d4093a3a2c clients/tests: add python test script for nmcli tests
Add a test which runs nmcli against our stub NetworkManager
service and compares the output.

The output formats of nmcli are complicated and not easily understood.
For example how --mode tabular|multiline interacts with selecting
output-fields (--fields) and output modes ([default]|--terse|--pretty).
Also, there are things like `nmcli connection show --order $FIELD_SPEC`.

We need unit tests to ensure that we don't change the output
accidentally.
2018-05-11 16:51:20 +02:00
Beniamino Galvani
1b5925ce88 all: remove consecutive empty lines
Normalize coding style by removing consecutive empty lines from C
sources and headers.

https://github.com/NetworkManager/NetworkManager/pull/108
2018-04-30 16:24:52 +02:00
Thomas Haller
735dc41bd0 libnm: rework checkpoint API
The libnm API fir checkpoints was only introduced with 1.11. It
is not yet stable, so there is still time to adjust it. Note that
this changes API/ABI of the development branch.

Changes:

- we only add async variants of the checkpoint functions. I believe
  that synchronous D-Bus methods are fundamentally flawed, because
  they mess up the ordering of events.
  Rename the async functions by removing the "_async" suffix. This
  matches glib style, for which the async form is also not specially
  marked.

- for function that refere to a particular checkpoint (rollback and
  destroy), accept the D-Bus path as string, instead of an NMCheckpoint
  instance. This form is more flexible, because it allows to use
  the function without having a NMCheckpoint instance at hand. On the
  other hand, if one has a NMCheckpoint instance, he can trivially
  obtain the path to make the call.
2018-04-04 14:02:13 +02:00
Thomas Haller
f67303221b checkpoint: allow resetting the rollback timeout via D-Bus
This allows to adjust the timeout of an existing checkpoint.

The main usecase of checkpoints, is to have a fail-safe when
configuring the network remotely. By allowing to reset the timeout,
the user can perform a series of actions, and keep bumping the
timeout. That way, the entire series is still guarded by the same
checkpoint, but the user can start with short timeout, and
re-adjust the timeout as he goes along.

The libnm API only implements the async form (at least for now).
Sync methods are fundamentally wrong with D-Bus, and it's probably
not needed. Also, follow glib convenction, where the async form
doesn't have the _async name suffix. Also, accept a D-Bus path
as argument, not a NMCheckpoint instance. The libnm API should
not be more restricted than the underlying D-Bus API. It would
be cumbersome to require the user to lookup the NMCheckpoint
instance first, especially since libnm doesn't provide an efficient
or convenient lookup-by-path method. On the other hand, retrieving
the path from a NMCheckpoint instance is always possible.
2018-04-04 14:02:13 +02:00
Corentin Noël
468a019333 gobject-introspection: made several fixes to the annotations
https://bugzilla.gnome.org/show_bug.cgi?id=794658
2018-03-26 12:45:49 +02:00
Benjamin Berg
26c215e22d Add calls to g_simple_async_result_set_check_cancellable
If an operation is cancelled through the GCancellable, then the idiom is
that the operation is always cancelled, even if it has finished
successfully. To ensure this is the case, add calls to
g_simple_async_result_set_check_cancellable everywhere.

Without this, e.g. gnome-control-center will crash when switching away
from the power panel quickly, as the NMClient creation finishes
asynchronously and g-c-c assume that G_IO_ERROR_CANCELLED is returned to
ensure it doesn't access the now invalid user_data parameter.

https://bugzilla.gnome.org/show_bug.cgi?id=794088
2018-03-08 14:52:45 +01:00
Pavel Šimerda
c4f655579c libnm: fix empty statements that were supposed to return NULL
Discovered thanks to `-Wunused-value` when building on openSUSE Leap 42.3.
2018-01-17 19:20:03 +01:00
Beniamino Galvani
c3efedf54b libnm: add checkpoint support 2017-11-09 10:12:30 +01:00
Lubomir Rintel
c81005b846 libnm/client: proxy *_enabled and metered properties to the right object
They're provided by the Manager, not by the RemoteSettings.
2017-11-02 09:04:42 +01:00
Lubomir Rintel
3f74528a0b libnm: add support for ovs-bridge devices 2017-10-30 17:40:09 +01:00
Lubomir Rintel
c536d7e666 libnm: add support for ovs-port devices 2017-10-30 17:40:09 +01:00
Lubomir Rintel
e5c19377ec libnm: add support for ovs-interface devices 2017-10-30 17:40:08 +01:00
Beniamino Galvani
7758071c28 libnm: disconnect signal handlers from old object-manager
When NM is restarted and a new object-manager is created, ensure that
signal handlers are disconnected from the old one.

Fixes the following:
  assertion failed: (object_manager == priv->object_manager)

 #0  __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
 #1  __GI_abort () at abort.c:90
 #2  g_assertion_message (domain=domain@entry=0x7fcac0b845ff "libnm", file=file@entry=0x7fcac0b84c95 "libnm/nm-client.c", line=line@entry=2506, func=func@entry=0x7fcac0b863a0 <__func__.34881> "name_owner_changed", message=message@entry=0x7fcac20b05f0 "assertion failed: (object_manager == priv->object_manager)") at gtestutils.c:2429
 #3  g_assertion_message_expr (domain=domain@entry=0x7fcac0b845ff "libnm", file=file@entry=0x7fcac0b84c95 "libnm/nm-client.c", line=line@entry=2506, func=func@entry=0x7fcac0b863a0 <__func__.34881> "name_owner_changed", expr=expr@entry=0x7fcac0b856a0 "object_manager == priv->object_manager") at gtestutils.c:2444
 #4  name_owner_changed (object=<optimized out>, pspec=<optimized out>, user_data=0x7fcac204e480) at libnm/nm-client.c:2506
 #8  <emit signal notify:name-owner on instance 0x7fcac2053c60 [GDBusObjectManagerClient]> (instance=instance@entry=0x7fcac2053c60, signal_id=<optimized out>, detail=<optimized out>) at gsignal.c:3439
     #5  g_closure_invoke (closure=0x7fcac20af390, return_value=return_value@entry=0x0, n_param_values=2, param_values=param_values@entry=0x7ffde58d9ec0, invocation_hint=invocation_hint@entry=0x7ffde58d9e60) at gclosure.c:801
     #6  signal_emit_unlocked_R (node=node@entry=0x7fcac2052090, detail=detail@entry=185, instance=instance@entry=0x7fcac2053c60, emission_return=emission_return@entry=0x0, instance_and_params=instance_and_params@entry=0x7ffde58d9ec0) at gsignal.c:3627
     #7  g_signal_emit_valist (instance=<optimized out>, signal_id=<optimized out>, detail=<optimized out>, var_args=var_args@entry=0x7ffde58da050) at gsignal.c:3383
 #9  g_object_dispatch_properties_changed (object=0x7fcac2053c60 [GDBusObjectManagerClient], n_pspecs=<optimized out>, pspecs=<optimized out>) at gobject.c:1061
 #10 g_object_notify (pspec=<optimized out>, object=0x7fcac2053c60 [GDBusObjectManagerClient]) at gobject.c:1155
 #11 g_object_notify (object=object@entry=0x7fcac2053c60 [GDBusObjectManagerClient], property_name=property_name@entry=0x7fcabe9d2b29 "name-owner") at gobject.c:1202
 #12 on_notify_g_name_owner (object=<optimized out>, pspec=<optimized out>, user_data=0x7fcac2053c60) at gdbusobjectmanagerclient.c:1262
 #16 <emit signal notify:g-name-owner on instance 0x7fcaa8004440 [GDBusProxy]> (instance=instance@entry=0x7fcaa8004440, signal_id=<optimized out>, detail=<optimized out>) at gsignal.c:3439
     #13 g_closure_invoke (closure=0x7fcaa80194f0, return_value=return_value@entry=0x0, n_param_values=2, param_values=param_values@entry=0x7ffde58da370, invocation_hint=invocation_hint@entry=0x7ffde58da310) at gclosure.c:801
     #14 signal_emit_unlocked_R (node=node@entry=0x7fcac2052090, detail=detail@entry=299, instance=instance@entry=0x7fcaa8004440, emission_return=emission_return@entry=0x0, instance_and_params=instance_and_params@entry=0x7ffde58da370) at gsignal.c:3627
     #15 g_signal_emit_valist (instance=<optimized out>, signal_id=<optimized out>, detail=<optimized out>, var_args=var_args@entry=0x7ffde58da500) at gsignal.c:3383
 #17 g_object_dispatch_properties_changed (object=0x7fcaa8004440 [GDBusProxy], n_pspecs=<optimized out>, pspecs=<optimized out>) at gobject.c:1061
 #18 g_object_notify (pspec=<optimized out>, object=0x7fcaa8004440 [GDBusProxy]) at gobject.c:1155
 #19 g_object_notify (object=object@entry=0x7fcaa8004440 [GDBusProxy], property_name=property_name@entry=0x7fcabe9d2b27 "g-name-owner") at gobject.c:1202
 #20 on_name_owner_changed (connection=<optimized out>, sender_name=<optimized out>, object_path=<optimized out>, interface_name=<optimized out>, signal_name=<optimized out>, parameters=<optimized out>, user_data=0x7fcaa8015b50) at gdbusproxy.c:1353
 #21 emit_signal_instance_in_idle_cb (data=0x7fcaa40ff400) at gdbusconnection.c:3701
 #22 g_main_context_dispatch (context=0x7fcac204eea0) at gmain.c:3152
 #23 g_main_context_dispatch (context=context@entry=0x7fcac204eea0) at gmain.c:3767
 #24 g_main_context_iterate (context=context@entry=0x7fcac204eea0, block=block@entry=1, dispatch=dispatch@entry=1, self=<optimized out>) at gmain.c:3838
 #25 g_main_context_iteration (context=0x7fcac204eea0, context@entry=0x0, may_block=may_block@entry=1) at gmain.c:3899
 #26 nmc_readline_helper (prompt=prompt@entry=0x7fcac2087f60 "The connection is not saved. Do you really want to quit? (yes/no) [no] ") at clients/cli/common.c:986
 #27 nmc_readline (prompt_fmt=<optimized out>) at clients/cli/common.c:1055
 #28 confirm_quit () at clients/cli/connections.c:6459
 #29 do_connection_edit (connection_type=<optimized out>, connection=0x7fcac208eca0, nmc=0x7fcac12a3a60 <nm_cli>) at clients/cli/connections.c:7611
 #30 do_connection_edit (nmc=0x7fcac12a3a60 <nm_cli>, argc=1, argv=0x7ffde58db0b0) at clients/cli/connections.c:7948
 #31 call_cmd (nmc=0x7fcac12a3a60 <nm_cli>, simple=0x7fcac2052490 [GSimpleAsyncResult], cmd=0x7fcac1291ae0 <connection_cmds+128>, argc=2, argv=0x7ffde58db0a8) at clients/cli/common.c:1315
 #32 got_client (source_object=<optimized out>, res=<optimized out>, user_data=0x7fcac2051830) at clients/cli/common.c:1297
 #33 g_simple_async_result_complete (simple=0x7fcac2052500 [GSimpleAsyncResult]) at gsimpleasyncresult.c:801
 #34 client_inited (source=0x7fcac204e480 [NMClient], result=0x7fcac20565f0, user_data=0x7fcac2052500) at libnm/nm-client.c:1839
 #35 g_simple_async_result_complete (simple=0x7fcac20565f0 [GSimpleAsyncResult]) at gsimpleasyncresult.c:801
 #36 init_async_complete (init_data=init_data@entry=0x7fcac2046820) at libnm/nm-client.c:2339
 #37 async_inited_obj_nm (init_data=0x7fcac2046820) at libnm/nm-client.c:2337
 #38 async_inited_obj_nm (object=0x7fcac2073080 [NMRemoteConnection], result=0x7fcac2089ed0, user_data=0x7fcac2046820) at libnm/nm-client.c:2357
 #39 g_simple_async_result_complete (simple=0x7fcac2089ed0 [GSimpleAsyncResult]) at gsimpleasyncresult.c:801
 #40 init_async_parent_inited (error=0x0, init_data=0x7fcaa408a0f0) at libnm/nm-remote-connection.c:677
 #41 init_async_parent_inited (source=<optimized out>, result=<optimized out>, user_data=0x7fcaa408a0f0) at libnm/nm-remote-connection.c:689
 #42 g_simple_async_result_complete (simple=0x7fcac2089c30 [GSimpleAsyncResult]) at gsimpleasyncresult.c:801
 #43 complete_in_idle_cb (data=<optimized out>) at gsimpleasyncresult.c:813
 #44 g_main_context_dispatch (context=0x7fcac204eea0) at gmain.c:3152
 #45 g_main_context_dispatch (context=context@entry=0x7fcac204eea0) at gmain.c:3767
 #46 g_main_context_iterate (context=0x7fcac204eea0, block=block@entry=1, dispatch=dispatch@entry=1, self=<optimized out>) at gmain.c:3838
 #47 g_main_loop_run (loop=0x7fcac2045ab0) at gmain.c:4032
 #48 main (argc=<optimized out>, argv=<optimized out>) at clients/cli/nmcli.c:642

https://bugzilla.redhat.com/show_bug.cgi?id=1471245
2017-09-05 09:31:59 +02:00
Thomas Haller
72baa8e30b libnm: add gtk-doc Since markers for new API and missing enum documentation 2017-08-17 23:08:44 +02:00
James Henstridge
0480dae749 client: expose connectivity-check-{available,enabled} properties
https://bugzilla.gnome.org/show_bug.cgi?id=785117
2017-08-17 22:31:47 +02:00
Beniamino Galvani
df72cad107 device: add NMDevicePPP
The new device type represents a PPP interface, and will implement the
activation of new-style PPPoE connections, i.e. the ones that don't
claim the parent device.
2017-08-05 08:03:15 +02:00
Thomas Haller
196bae36bb libnm: refactor name-owner check for object-manager 2017-06-29 09:58:28 +02:00
Thomas Haller
a73e73eae1 libnm: move check for pending_init to init_async_complete() 2017-06-29 09:58:28 +02:00
Thomas Haller
4f0a621d43 libnm: fix leaking init_data in got_object_manager()
Only happens if there are no objects, which would be very unusual.
2017-06-29 09:58:28 +02:00
Thomas Haller
958ae36c17 libnm: assert in async_inited_obj_nm() for existing pending_init count 2017-06-29 09:58:28 +02:00
Thomas Haller
efac9ecadd libnm/trivial: move code 2017-06-29 09:58:28 +02:00
Thomas Haller
d5efcc1115 libnm: clear cancellable in new_object_manager() before emitting signal
Emitting signals may have side-effects. Just clear the cancellable
first, it is handled for good.
2017-06-29 09:57:51 +02:00
Thomas Haller
e0ddf64522 libnm: fix leaking cancellable in NMClient's name_owner_changed() 2017-06-29 09:56:32 +02:00
Thomas Haller
df6e2e2e78 libnm: fix getting self pointer in NMClient's new_object_manager() 2017-06-29 09:56:32 +02:00
Thomas Haller
880a7061f2 libnm: clear NMClientPrivate.object_manager in name_owner_changed()
Don't leave dangling pointers.
2017-06-29 09:56:32 +02:00
Thomas Haller
45d6147098 Revert "libnm: don't use async constructor for GDBusObjectManager"
Strangely, this breaks

  systemctl restart NetworkManager
  nmcli connection up "$NAME"

It seems that with this change, libnm misses some events from D-Bus.
It looks like there is something seriously broken. Before fixing it,
revert the previous state.

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

This reverts commit 529d620a59.
2017-06-29 09:56:32 +02:00
Thomas Haller
7cd4711e31 Revert "libnm: refactor error handling in got_object_manager()"
This reverts commit c5370ea71a.
2017-06-29 09:56:32 +02:00
Thomas Haller
c5370ea71a libnm: refactor error handling in got_object_manager() 2017-06-19 17:20:34 +02:00
Thomas Haller
529d620a59 libnm: don't use async constructor for GDBusObjectManager
The current implementation of GDBusObjectManagerClient implements
GAsyncInitableIface, however it simply runs GInitableIface's
synchronous init on another thread.

I suspect that there are races in the way that is implemented.
For one, we see crashes and warnings (rh#1450075, rh#1457769,
rh#1457223). Also, it seems very wrong to me, how GDBusObjectManagerClient
mixes asynchronous signals (on_control_proxy_g_signal) with
synchronously getting all objects (process_get_all_result,
GetManagedObjects).

I think we should ditch GDBusObjectManager altogether, including the
gdbus-codegen skeletons. They add layers of code, for something that
should be simple to do directly. For now, just don't do asynchronous
initialization on another thread, so we at least avoid this kind of
multithreadding issue.

This may make the initialization of NMClient a bit slower.
2017-06-19 17:19:48 +02:00
Thomas Haller
c5a48b7a0b libnm: complete async result in got_object_manager() also when cancelled
Cancelling an operation shall not mean to not invoke the result callback.
The result callback is *always* to be invoked.
2017-06-19 17:19:17 +02:00
Francesco Giudici
23bc781063 all/trivial: fix few comment typos 2017-05-15 15:52:21 +02:00
Thomas Haller
c26229f91b libnm: fix showing UDEV properties for device
https://mail.gnome.org/archives/networkmanager-list/2017-March/msg00065.html

Fixes: c7ccdf5fc8
(cherry picked from commit c06308a10c)
2017-03-29 09:43:32 +02:00
Thomas Haller
c7ccdf5fc8 libnm/udev: cache and reuse udev instance for NMDevice
No need to create a separate NMUdevClient instance for all devices.
Instead, have one "struct udev" instance in NMClient and pass
it down during object construction.
2017-03-22 12:41:06 +01:00
Lubomir Rintel
40ffb962be libnm/active-connection: track reason for state changes
Note that the reason tracking starts as soon as the object exists (which
is immediately after GDBusObject is created), not when the asynchronous
NMObject initialization finishes. That is so that we the reason changes
in between are not lost.

The vpn-connection should probably be doing the same.
2017-03-17 10:21:19 +01:00
Thomas Haller
ec2681d4db all: use nm_clear_g_cancellable() 2017-03-13 12:00:23 +01:00
Beniamino Galvani
b42f780e04 core: add support for dummy devices
Add support for creating dummy devices. This commit adds a D-Bus
interface 'org.freedesktop.NetworkManager.Device.Dummy' which is used
primarily for determining the device type but does not carry any
properties.
2017-02-22 21:05:04 +01:00
Thomas Haller
dc40288849 all: use NM_CACHED_QUARK_FCN() to define cached quarks 2017-02-10 14:33:52 +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
Beniamino Galvani
a8d6005256 libnm: implement support for DNS manager properties 2016-12-12 22:06:24 +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
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
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
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
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
Thomas Haller
a83eb773ce all: modify line separator comments to be 80 chars wide
sed 's#^/\*\{5\}\*\+/$#/*****************************************************************************/#' $(git grep -l '\*\{5\}' | grep '\.[hc]$') -i
2016-10-03 12:01:15 +02:00