Commit Graph

52 Commits

Author SHA1 Message Date
Lubomir Rintel
faae84370f dispatcher: don't abort when VPN connections have no IPv4
They don't need it. Also, we shouldn't assert on something that can be
done via a D-Bus API.
2015-11-13 16:13:40 +01:00
Lubomir Rintel
06da353242 core: separate active and applied connection
Clone the connection upon activation. This makes it safe for the user
to modify the original connection while it is activated.

This involves several changes:

- NMActiveConnection gets @settings_connection and @applied_connection.
  To support add-and-activate, we constructing a NMActiveConnection with
  no connection set. Previously, we would set the "connection" field to
  a temporary NMConnection. Now NMManager piggybacks this temporary
  connection as object-data (TAG_ACTIVE_CONNETION_ADD_AND_ACTIVATE).

- get rid of the functions nm_active_connection_get_connection_type()
  and nm_active_connection_get_connection_uuid(). From their names
  it is unclear whether this returns the settings or applied connection.
  The (few) callers should figure that out themselves.

- rename nm_active_connection_get_id() to
  nm_active_connection_get_settings_connection_id(). This function
  is only used internally for logging.

- dispatcher calls now get two connections as well. The
  applied-connection is used for the connection data, while
  the settings-connection is used for the connection path.

- needs special handling for properties that apply immediately
  when changed (nm_device_reapply_settings_immediately()).

Co-Authored-By: Thomas Haller <thaller@redhat.com>

https://bugzilla.gnome.org/show_bug.cgi?id=724041
2015-09-18 17:32:11 +02:00
Lubomir Rintel
629a5396e4 dispatcher: don't send object path for devices which are no longer exported
They may be unexported upon shutdown.

  Program received signal SIGTRAP, Trace/breakpoint trap.
  0x00007ffff48271db in _g_log_abort (breakpoint=1) at gmessages.c:316
  316         G_BREAKPOINT ();
  (gdb) bt
  #0  0x00007ffff48271db in g_logv (breakpoint=1) at gmessages.c:316
  #1  0x00007ffff48271db in g_logv (log_domain=0x7ffff488d8ce "GLib", log_level=G_LOG_LEVEL_CRITICAL, format=<optimized out>, args=args@entry=0x7fffffffd4d0) at gmessages.c:1073
  #2  0x00007ffff482734f in g_log (log_domain=log_domain@entry=0x7ffff488d8ce "GLib", log_level=log_level@entry=G_LOG_LEVEL_CRITICAL, format=format@entry=0x7ffff48971dd "%s: assertion '%s' failed") at gmessages.c:1111
  #3  0x00007ffff4827389 in g_return_if_fail_warning (log_domain=log_domain@entry=0x7ffff488d8ce "GLib", pretty_function=pretty_function@entry=0x7ffff48e7d00 <__func__.5406> "g_variant_is_object_path", expression=expression@entry=0x7ffff48e9af2 "string != NULL") at gmessages.c:1120
  #4  0x00007ffff485511a in g_variant_is_object_path (string=<optimized out>) at gvariant.c:1351
  #5  0x00007ffff4855129 in g_variant_new_object_path (object_path=0x0) at gvariant.c:1325
  #6  0x00000000004b9567 in _dispatcher_call (dhcp6_props=<synthetic pointer>, dhcp4_props=<synthetic pointer>, ip6_builder=0x7fffffffd7b0, ip4_builder=0x7fffffffd730, dev_builder=0x7fffffffd6b0, device=0x9621f0 [NMDeviceEthernet]) at nm-dispatcher.c:242
  #7  0x00000000004b9567 in _dispatcher_call (action=action@entry=DISPATCHER_ACTION_VPN_DOWN, blocking=blocking@entry=1, connection=<optimized out>, device=device@entry=0x9621f0 [NMDeviceEthernet], vpn_iface=0x9e2650 "tun1", vpn_ip4_config=vpn_ip4_config@entry=0x0, vpn_ip6_config=0x0, callback=0x0, user_data=0x0, out_call_id=0x0) at nm-dispatcher.c:545
  #8  0x00000000004b98c2 in nm_dispatcher_call_vpn_sync (action=action@entry=DISPATCHER_ACTION_VPN_DOWN, connection=<optimized out>, parent_device=parent_device@entry=0x9621f0 [NMDeviceEthernet], vpn_iface=<optimized out>, vpn_ip4_config=vpn_ip4_config@entry=0x0, vpn_ip6_config=vpn_ip6_config@entry=0x0) at nm-dispatcher.c:740
  #9  0x0000000000571986 in _set_vpn_state (connection=0xa08270 [NMVpnConnection], vpn_state=<optimized out>, reason=NM_VPN_CONNECTION_STATE_REASON_SERVICE_STOPPED, quitting=1) at vpn-manager/nm-vpn-connection.c:427
  #10 0x00000000005764b6 in nm_vpn_connection_disconnect (connection=<optimized out>, reason=<optimized out>, quitting=<optimized out>) at vpn-manager/nm-vpn-connection.c:1909
  #11 0x000000000057759e in nm_vpn_service_stop_connections (service=0x9aa1c0 [NMVpnService], quitting=1, reason=NM_VPN_CONNECTION_STATE_REASON_SERVICE_STOPPED) at vpn-manager/nm-vpn-service.c:149
  #12 0x0000000000576e12 in dispose (object=0x9175a0 [NMVpnManager]) at vpn-manager/nm-vpn-manager.c:284
  #13 0x00007ffff4b24fec in g_object_unref (_object=0x9175a0) at gobject.c:3137
  #14 0x00000000004d0e75 in dispose (object=0x88a2c0 [NMManager]) at nm-manager.c:5061
  #15 0x00007ffff4b24fec in g_object_unref (_object=0x88a2c0) at gobject.c:3137
  #16 0x0000000000444e08 in _nm_singleton_instance_destroy () at NetworkManagerUtils.c:138
  #17 0x00007ffff7de97b7 in _dl_fini () at dl-fini.c:252
  #18 0x00007ffff4444778 in __run_exit_handlers (status=status@entry=0, listp=0x7ffff47d0618 <__exit_funcs>, run_list_atexit=run_list_atexit@entry=true) at exit.c:82
  #19 0x00007ffff44447c5 in __GI_exit (status=status@entry=0) at exit.c:104
  #20 0x0000000000445b80 in main (argc=1, argv=0x7fffffffdee8) at main.c:458
  (gdb)
2015-08-19 15:32:13 +02:00
Dan Winship
1cf35cb26b core: final gdbus porting
Port remaining bits to gdbus and remove stray dbus-glib references

Drop the dbus-glib version check from configure, since nothing depends
on new dbus-glib any more.

Move nm-dbus-glib-types.h and nm-gvaluearray-compat.h from include/ to
libnm-util/ since they are now only used by libnm-util and libnm-glib.
2015-08-10 09:41:26 -04:00
Thomas Haller
19c3ea948a all: make use of new header file "nm-default.h" 2015-08-05 15:32:40 +02:00
Dan Winship
02370be7f3 core: rename NMDBusManager to NMBusManager
Our gdbus generated types use the same names as their corresponding
"real" types, but with "NM" changed to "NMDBus".

Unfortunately, that means that introspection/nmdbus-manager.c (the
generated type for src/nm-manager.c) uses the same type name as the
entirely unrelated src/nm-dbus-manager.c.

Fix this by removing the "d" from src/nm-dbus-manager.c. (We could
rename the generated type instead, but then it becomes inconsistent
with all the other generated types, and we're already using it as
"NMDBusManager" in libnm/nm-manager.c.)
2015-07-24 13:25:48 -04:00
Dan Winship
94078a139a core: port NMDhcp4Config/NMDhcp6Config to GVariant
In the gdbus port, the :options properties will be GVariant-valued
(and thus immutable), so having APIs that let you repeatedly modify
them would make things complicated. Since we actually only ever set
all the options at once, just change the APIs to do that, rather than
setting the options one-by-one.

Since nm-dispatcher already works in terms of GVariant, it makes
things simpler there if NMDhcp[46]Config can return its options as a
GVariant. And since we'll need it to be a GVariant internally later
anyway, just port everything to GVariant now, and convert it to a
GHashTable for dbus-glib only in get_property().
2015-07-24 13:25:47 -04:00
Dan Winship
c1dd3b6eed core: move D-Bus export/unexport into NMExportedObject
Move D-Bus export/unexport handling into NMExportedObject and remove
type-specific export/get_path methods (export paths are now specified
at the class level, and NMExportedObject handles the counters for all
exported types automatically).

Since all exportable objects now use the same get_path() method, we
can also add some helper methods to simplify get_property()
implementations for object-path and object-path-array properties.
2015-07-24 13:25:47 -04:00
Dan Winship
f3d10b3ec8 core: add missing g_dbus_error_strip_remote_error() calls 2015-07-24 13:25:47 -04: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
7914a6b6bd dispatcher: fix crash due to wrong signature of variant for argument of "Action" D-Bus call
Fixes: 8da83a2ba3

https://bugzilla.gnome.org/show_bug.cgi?id=747456
2015-04-07 19:18:15 +02:00
Dan Winship
8da83a2ba3 core: port the daemon side of the dispatcher to gdbus 2015-04-03 16:58:40 -04:00
Lubomir Rintel
a43f95b0ac trivial: remove a tautological compare
Unsigned enum is always >= 0.
2015-03-19 11:48:49 +01:00
Dan Winship
849ae9eed6 dispatcher: add an env var indicating a connection is "external"
Add CONNECTION_EXTERNAL=1 to the environment when dispatching actions
on a "generated-assumed" connection (ie, one that was created outside
of NM).
2015-01-19 11:19:33 -05:00
Dan Winship
bd2deace70 dispatcher: pass CONNECTION_FILENAME to dispatcher scripts 2015-01-12 09:53:21 -05:00
Dan Winship
3bfb163a74 all: consistently include config.h
config.h should be included from every .c file, and it should be
included before any other include. Fix that.

(As a side effect of how I did this, this also changes us to
consistently use "config.h" rather than <config.h>. To the extent that
it matters [which is not much], quotes are more correct anyway, since
we're talking about a file in our own build tree, not a system
include.)
2014-11-13 17:18:42 -05:00
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
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
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
3ac0f52878 libnm, core, cli, tui: fix the capitalization of various types
GLib/Gtk have mostly settled on the convention that two-letter
acronyms in type names remain all-caps (eg, "IO"), but longer acronyms
become initial-caps-only (eg, "Tcp").

NM was inconsistent, with most long acronyms using initial caps only
(Adsl, Cdma, Dcb, Gsm, Olpc, Vlan), but others using all caps (DHCP,
PPP, PPPOE, VPN). Fix libnm and src/ to use initial-caps only for all
three-or-more-letter-long acronyms (and update nmcli and nmtui for the
libnm changes).
2014-08-01 14:34:06 -04:00
Dan Winship
b28f6526c2 core: fill in nm-types.h, clean out other headers
Clean up some of the cross-includes between headers (which made it so
that, eg, if you included NetworkManagerUtils.h in a test program, you
would need to build the test with -I$(top_srcdir)/src/platform, and if
you included nm-device.h you'd need $(POLKIT_CFLAGS)) by moving all
GObject struct definitions for src/ and src/settings/ into nm-types.h
(which already existed to solve the NMDevice/NMActRequest circular
references).

Update various .c files to explicitly include the headers they used to
get implicitly, and remove some now-unnecessary -I options from
Makefiles.
2014-07-23 10:56:26 -04:00
Thomas Haller
0d45284aa7 dispatcher: suppress log warning when nm-dispatcher is disabled in systemd
When 'nm-dispatcher' is not running because its systemd service
'NetworkManager-dispatcher.service' is not enabled, any calls to the dispatcher
will fail with an error of typ DBUS_ERROR:DBUS_GERROR_REMOTE_EXCEPTION (32):

  "Unit dbus-org.freedesktop.nm-dispatcher.service failed to load: No such file or directory."

This clutters the logfile with warnings, although the user probably
disabled the service on purpose.

Special case this particular (recurring) failure and downgrade the warning
to debug level.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-20 17:25:01 +02:00
Thomas Haller
0a7a7f5e4d dispatcher: better detection for dispatcher scripts
Previously, we would not check the content of the script directory.
This meant, that "/etc/NetworkManager/dispatcher.d" almost always
contained something, namely the "pre-up.d" and "pre-down.d" directories.

Improve that by searching the directories for at least one
executable file.

Also, debug log the detected state of the dispatcher directories.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-16 19:19:10 +02:00
Thomas Haller
c674f26cd1 dispatcher: for debug logging, truncate the (expected) script name when showing dispatcher results
Only truncate the script name to "basename" if the directory is the expected
one. Otherwise we print the raw value as returned by the dispatcher service.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-16 19:18:57 +02:00
Thomas Haller
0c54ab217e dispatcher: skip callouts for empty script directory based on dispatcher action type
Before, there was only one combined variable checking whether any dispatcher scripts
are present at all. This meant for example, that a call to PRE_UP was still sent out
even if no scripts were in pre-up.d/ directory.

Optimize this, by distinguishing between the dispatcher type and the script directories.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-16 19:18:57 +02:00
Thomas Haller
10780592c8 dispatcher/trivial: move code
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-16 19:18:57 +02:00
Thomas Haller
b317e79b5b dispatcher: improve debug logging for dispatcher callouts
- ensure, that dispatcher_results_process() logs a line even if no scripts
were run. This way we alyways know when the callout returns.

- log a line when cancelling a dispatcher call

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-16 19:18:57 +02:00
Thomas Haller
c8e7953333 dispatcher/trivial: rename variables for script directory to NMD_SCRIPT_DIR_* 2014-06-16 19:18:57 +02:00
Yegor Yefremov
c62639d572 nm-dispatcher: explicitly include gio/gio.h
Without this header Buildroot's build complains about unknown
types like GFile etc.

Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com>
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-11 18:53:13 +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
df601ad68c dispatcher: enhance debug logging
Attach a request ID to every request, and print that out in the debug
messages so you can see which results match up with which dispatcher
requests.
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
27cb927d8f dispatcher: convert action_to_string to a table
Oddly, this increases the compiled+stripped size of the object file
by 24 bytes (8296 -> 8320), but I think it produces more readable code.
2014-06-06 13:43:46 -05:00
Dan Williams
19d7386b2f dispatcher: add PRE_UP states
This event runs before a connection/device is announced as
"activated" or "connected", to enable scripts to do things
before applications begin using connectivity.  For example,
this could be used to manage /etc/resolv.conf outside of
NetworkManager and ensure that resolv.conf had correct
information before DNS is used.

Note that this is different than the Debian or Gentoo "pre-up"
event used in /etc/network/interfaces, as that event runs before
any L2 configuration has started.  If we really need an event
like that, we'll add it later as "lower-up".
2014-06-06 13:43:46 -05:00
Dan Williams
286e926ee8 dispatcher: robustify canceling dispatcher calls
Thomas pointed out that using the address of the DispatcherInfo
structure as the dispatcher call ID could cause a mis-cancelation
if malloc re-used the same block in the future.  While the code
should be correctly clearing call IDs after the callback runs
or is canceled, just use numeric IDs to avoid potential crashses.
2014-06-06 13:43:46 -05:00
Dan Williams
90b747fa11 dispatcher: add synchronous dispatcher calls
On shutdown we can't defer the response to a callback, so we need to
use synchronous D-Bus calls.  Second, sometimes we want to block on
the dispatcher response, like for pre-down.
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
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
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 Williams
3cab4ee6cd dispatcher: handle VPN connections without interface names 2014-01-24 09:42:51 -06:00
Thomas Haller
97935382f4 coverity: fix various warnings detected with Coverity
These are (most likely) only warnings and not severe bugs.
Some of these changes are mostly made to get a clean run of
Coverity without any warnings.

Error found by running Coverity scan

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

Co-Authored-By: Jiří Klimeš <jklimes@redhat.com>
Signed-off-by: Thomas Haller <thaller@redhat.com>
2013-11-13 15:29:24 +01:00
Tomas Hozza
6b93150d0d dispatcher: publish vpn_ip6_config 2013-06-21 17:46:19 +02:00
Dan Williams
04cb58eacd core: convert the DBus manager to a single-ref object
It's created very, very early and never needs to be unrefed
by anything except the main() function.
2013-05-20 16:38:33 -03:00
Dan Williams
a096ef8f87 core: fix more GValueArray deprecation fallout 2013-02-27 18:09:52 +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
Jiří Klimeš
b95b6c8aa1 core: fix a crash due to GValueArray/GArray freeing mismatch (rh #865009) 2012-10-11 15:41:48 +02:00
Dan Williams
d42d41c1ac core: add cancelation to dispatcher calls 2012-09-11 17:17:58 -05:00
Dan Williams
15ca7cd56c core: add dispatcher callbacks and simplify dispatcher function prototypes
Remove unused args for the non-VPN cases to cut down on the NULL NULL NULL
stuff since we're also adding two more arguments.  Add the ability for
callers to give a callback that should be called when the dispatcher is
done.
2012-09-11 17:06:16 -05:00