Commit Graph

21088 Commits

Author SHA1 Message Date
Lubomir Rintel
31aa2cfe29 cli: use a palette to implement coloring
This basically replaces the (NMMetaTermColor, NMMetaTermFormat) combo
with NMMetaColor that describes the colored element semantically as
opposed to storing the raw attributes.

A (currently static) paletted is used to translate the semantic color
code to the actual ANSI controle sequence. This matches what
terminal-colors.d(5) schemes use, making it convenient to implement
customizable palettes.
2018-05-10 14:36:58 +02:00
Lubomir Rintel
9dfe825840 cli: rework enabling and disabling colors
This actually makes very little difference at the moment, but will make
things more confortable later on, when the logic of enabling/disabling
coloring will involve terminal-colors.d(5).

Instead of deciding whether to use colors lazily with use_colors(), it's
done very early on nmcli initialization and a boolean use_colors field
is stored in the NmcConfig instance instead of the raw tristate option
of NmcColorOption type (which is now confined to nmcli.c).

Wherever the NmcColorOption was used previously, the whole NmcConfig
instance is passed around. That might seem pointless (since only the
use_colors boolean is actually used at the moment), but will be utilized
to pass around the actual color palette in future.
2018-05-10 14:36:58 +02:00
Lubomir Rintel
56a5b27389 cli: drop --prompt-color
It's undocumented, useless, somewhat expensive in volume of code and
probably just downright stupid. We'll get a more general way to set
colors.

Hacking in some code to keep this working wouldn't be too difficult, but
it seems entirely pointless.
2018-05-10 14:36:58 +02:00
Lubomir Rintel
30d67c99ea cli: use static initializer for NmCli
It's perhaps but a small improvement here, but will make things a lot
more convenient when the color palette will be added.
2018-05-10 14:36:58 +02:00
Lubomir Rintel
f70abef5c6 cli: drop a useless comment
Thomas doesn't like it and who am I to argue with him.
2018-05-10 14:36:58 +02:00
Lubomir Rintel
bf7529823e cli: do not leave dangling pointers in a global struct
Makes Thomas content and happy..
2018-05-10 14:36:58 +02:00
Lubomir Rintel
e69d386975 all: use the elvis operator wherever possible
Coccinelle:

  @@
  expression a, b;
  @@
  -a ? a : b
  +a ?: b

Applied with:

  spatch --sp-file ternary.cocci --in-place --smpl-spacing --dir .

With some manual adjustments on spots that Cocci didn't catch for
reasons unknown.

Thanks to the marvelous effort of the GNU compiler developer we can now
spare a couple of bits that could be used for more important things,
like this commit message. Standards commitees yet have to catch up.
2018-05-10 14:36:58 +02:00
Lubomir Rintel
f0c1efbf42 all: add and utilize nm_utils_is_separator()
It is meant to be rather similar in nature to isblank() or
g_ascii_isspace().

Sadly, isblank() is locale dependent while g_ascii_isspace() also considers
vertical whitespace as a space. That's no good for configuration files that
are strucutured into lines, which happens to be a pretty common case.
2018-05-10 14:35:52 +02:00
Beniamino Galvani
1829126f3a device: start IP configuration when master carrier goes up
If the master has no carrier in act_stage3_ip6_config_start(), we set
IP state WAIT and wait until carrier goes up before starting IP
configuration.

However, in carrier_changed() if the device state is ACTIVATED we only
call nm_device_update_dynamic_ip_setup(), which just restarts DHCP if
it was already running.

Let's also ensure that we start IP configuration if the IP state is
WAIT.

Fixes: b0f6baad90

https://bugzilla.redhat.com/show_bug.cgi?id=1575944
2018-05-09 14:20:02 +02:00
Lubomir Rintel
8e066af7d5 core-utils: don't load modules not ending with ".so"
This prevents attempts to load garbage from the module directory.
2018-05-09 13:16:59 +02:00
Lubomir Rintel
57e06bc0b8 merge: branch 'lr/version-dir'
https://github.com/NetworkManager/NetworkManager/pull/104
2018-05-09 12:59:57 +02:00
Lubomir Rintel
6384ad4ee1 build: qualify plugin dir name with a version string
This makes package updates more robust, avoiding in-place replaces of
the plugins.

Previously, if an upgrade transaction was terminated, NetworkManager
library could end up being of a different version than the plugins.
If the user was unfortunate enough to connect using a connection that
required a plugin (say, Wi-Fi), he would be left without a network
connection making it somewhat inconvenient to recover from the botched
upgrade.

This makes the whole situation a little bit less sad.
2018-05-09 12:59:39 +02:00
Lubomir Rintel
6aac441f1c meson: distinguish arch specific and arch neutral lib dir
Plugins go to the arch specific place while conf.d/ and VPN/ are in
lib/. Use the same naming as is used with autoconf.
2018-05-09 12:59:39 +02:00
Lubomir Rintel
84a6010718 meson: quote dist_version properly 2018-05-09 12:59:39 +02:00
Lubomir Rintel
121be232ad session-monitor: avoid an assertion failure if there's no session monitor
The constructor can bail out early, not setting monitor->sd.watch:

  (NetworkManager:373): GLib-CRITICAL **: 20:35:58.601: g_source_remove: assertion 'tag > 0' failed
2018-05-09 12:59:08 +02:00
Beniamino Galvani
9e7a324916 platform: fix adding direct route to gateway
Without ifindex, adding the direct route to gateway fails:

 platform: route-sync: failure to add IPv6 route: fd02::/64 via fd01::1 dev 1635 metric 101 mss 0 rt-src user: No route to host (113); try adding direct route to gateway fd01::1/128 via :: metric 101 mss 0 rt-src user
 platform: route: append     IPv6 route: fd01::1/128 via :: metric 101 mss 0 rt-src user
 platform-linux: delayed-action: schedule wait-for-nl-response (seq 269, timeout in 0.199999195, response-type 0)
 platform-linux: delayed-action: handle wait-for-nl-response (any)
 platform-linux: netlink: recvmsg: new message NLMSG_ERROR, flags 0, seq 269
 platform-linux: netlink: recvmsg: error message from kernel: No such device (19) for request 269

Fixes: c9f89cafdf
2018-05-07 17:15:34 +02:00
Thomas Haller
896ea5252b build: add missing dependencies for building nmcli 2018-05-05 15:28:24 +02:00
Beniamino Galvani
ed817e9ca3 libnm: export nm_connection_get_setting_tc_config()
Fixes: da13c7a1a4
2018-05-05 10:45:33 +02:00
Thomas Haller
30a4fa454d checkpoint: fix D-Bus operation to destroy checkpoint
When passing "/" to destroy all checkpoints, wrongly no
checkpoint was destroyed.

When passing a particular path that should be destroyed,
wrongly all checkpoints were destroyed.

Fixes: 79458a558b
2018-05-03 14:38:10 +02:00
Lubomir Rintel
43e3ebfaa2 build: add a missing dependency
Parallel make failed for me:

  /usr/bin/xsltproc --output man/nm-settings-keyfile.xml ...
    ... man/nm-settings-keyfile.xsl libnm/nm-settings-keyfile-docs.xml
  man/nm-settings-keyfile.xsl:4: warning: failed to load external entity "man/common.ent"
  %entities;
            ^
  man/nm-settings-keyfile.xsl:26: parser error : Entity 'NM_VERSION' not defined
          <refmiscinfo class="version">&NM_VERSION;</refmiscinfo>
                                                   ^
  cannot parse man/nm-settings-keyfile.xsl
  make[2]: *** [Makefile:18130: man/nm-settings-keyfile.xml] Error 4
2018-05-02 14:55:01 +02:00
Lubomir Rintel
2244352583 auth-manager: use the correct function to deallocate a GError
This one ruins the party.
2018-05-02 14:55:01 +02:00
Thomas Haller
b3880b3142 build: fix missing dependency when building clients/tui/newt/libnmt-newt.a
We need to declare explicit dependencies, otherwise, the required header
files may not yet be created when building nmtui helper library.
2018-05-02 13:03:59 +02:00
Beniamino Galvani
37dc58f6c7 libnm: add missing device includes to NetworkManager.h 2018-05-02 09:14:56 +02:00
Thomas Haller
c2bdd44c4d core: merge branch 'th/manager-activation-cleanup'
https://github.com/NetworkManager/NetworkManager/pull/106
2018-05-01 10:45:05 +02:00
Thomas Haller
5ab7f6f108 manager: search all existing active connections during nm_manager_get_best_device_for_connection()
In nm_manager_get_best_device_for_connection(), not only check whether the first found
active-connection has a device. There might be multiple candidates, in which case iterate
over them and figure out which one is the most suitable.

Also, despite the found @ac has the same settings-connection, it does not
mean that the connection is available on the device. Extend the check and
only return compatible and ready devices. This can easily happen that
the settings-connection was modified in the meantime and no longer is
compatible with the device (despite currently being active on the
device, but with the previous settings).
2018-04-30 16:36:30 +02:00
Thomas Haller
f1a58e7517 manager: disconnect all conflicting concurrent active connections in _internal_activate_device()
It is possible, that there are multiple such conflicting connections.
Maybe not now, but with connecition cardinality it will soon be.

Find and disconnect them all.
2018-04-30 16:36:30 +02:00
Thomas Haller
9ab3d019e4 core: rework nm_device_steal_connection()
nm_device_steal_connection() was a bit misleading. It only had one caller,
and what _internal_activate_device() really wants it to deactivate all
other active-connections for the same connection. Hence, it already
performed a lookup for the active-connection that should be disconnected,
only to then lookup the device, and tell it to steal the connection.

Note, that if existing_ac happens to be neither the queued nor the currenct
active connection, then previously it would have done nothing. It's
unclear when that exactly can happen, however, we can avoid that
question entirely.

Instead of having steal-connection(), have a disconnect-active-connection().
If there is no matching device, it will just set the active-connection's
state to DISCONNECTED. Which in turn does nothing, if the state is
already DISCONNECTED.
2018-04-30 16:36:30 +02:00
Thomas Haller
3a2fbab09b core: don't consider deactivating active-connection when checking for concurrent activations
At various places we check whether we have an active-connection already.

For example, when activating a new connection in _internal_activate_device(),
we might want to "nm_device_steal_connection()" if the same profile is
already active.

However, the max-state argument was not accurate in several cases. For
the purpose of finding concurrent activations, we don't care about
active-connections that are already in state DEACTIVATING. Only those
that are ACTIVATED or before.
2018-04-30 16:36:30 +02:00
Thomas Haller
36ed7ef084 manager: minor refactoring of active_connection_find_by_connection()
active_connection_find_by_connection() (or how it was called previously) is
a simpler wrapper around active_connection_find(), which accepts a NMConnection
argument, that may or may not be a NMSettingsConnection.

It always passed NM_ACTIVE_CONNECTION_STATE_DEACTIVATING as max_state, and I think
that one of the two callers don't should do that. A later commit will change that.
So, we also want to pass @max_state as argument to active_connection_find_by_connection().
At that point, make active_connection_find_by_connection() identical to
active_connection_find(), with the only exception, that it accepts a
NMConnection and does automatically do the right thing (either lookup by
pointer equality or by uuid).
2018-04-30 16:36:29 +02:00
Thomas Haller
9424aa0562 manager: extend helper function to find all matching active-connections
... instead of just the first.

It's not used yet, and there is no change in behavior.
2018-04-30 16:36:29 +02:00
Thomas Haller
9c2785f31c core: only abort conflicting activations for certain activation types
There are various places where we do an internal activation (with an
internal auth-subject). In several of these places, the
ACTIVATION_REASON is USER_REQUEST.

I think it is wrong to generally abort all internal activations, except
AUTOCONNECT_SLAVES ones. I think, aborting an activation should be
opt-in instead of opt-out.

To me it seems, we want to abort the activation based on the activation
reason. For now, opt-in to EXTERNAL, ASSUME and AUTOCONNECT only. If
there are additional cases where we should abort activation, we should
add yet another reason and not use USER_REQUEST.
2018-04-30 16:36:29 +02:00
Thomas Haller
5a1f84b085 core: add activation-reasons for external/assume connections
Until now, we only really cared about whether a connection was activated
with reason NM_ACTIVATION_REASON_AUTOCONNECT_SLAVES or not.

Now however, we will care about whether a connection was activated via
(genuine) autoconnect by NMPolicy, or external/assume by NMManager.
Add a new reason to distinguish between them.
2018-04-30 16:36:29 +02:00
Thomas Haller
feb1ec1e87 settings: avoid lookup in nm_settings_has_connection()
There is no need to perform a lookup by path. NMSettings is a singleton,
it has the connection exactly iff the connection is linked.

Also add an assertion to double-check that the results agree with
the previous implementation.
2018-04-30 16:36:29 +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
Beniamino Galvani
e09b2314b9 manager: fix assertion in nm_manager_activate_connection()
nm_manager_activate_connection() should not require a device to be
passed in for VPN connections because when the argument is NULL the
actual device will be determined by _new_active_connection().

Fixes: 10753c3616
https://bugzilla.redhat.com/show_bug.cgi?id=1570545
https://github.com/NetworkManager/NetworkManager/pull/109
2018-04-30 16:23:01 +02:00
Stas Solovey
416b2c020b po: updated Russian (ru) translation (bgo #794738)
https://bugzilla.gnome.org/show_bug.cgi?id=794738
2018-04-27 13:33:58 +02:00
Thomas Haller
bca6bdb9f8 connectivity: merge branch 'th/connectivity-check-on-activated'
https://github.com/NetworkManager/NetworkManager/pull/103
2018-04-27 12:33:36 +02:00
Thomas Haller
2b8802d8ec device/connectivity: refactor concheck_periodic_schedule_do()
Instead of passing the interval for the timeout, let concheck_periodic_schedule_do()
figure it out on its own. It only depends on cur-interval and
cur-basetime.

Additionally, pass now_ns timestamp, because we already made
decisions based on this particular timestamp. We don't want to
re-evalutate the current time but ensure to use the same timestamp.

There is no change in behavior, it just seems nicer this way.
2018-04-27 12:33:19 +02:00
Thomas Haller
25ccd3d95d device: force a connectivity check when reaching device-state "activated"
When the device-state changes to "activated", force a connectivity check
right away. Something possibly happened that affected connectivity.

Also, reduce the interval time down to CONCHECK_P_PROBE_INTERVAL to
start probing again.
2018-04-27 12:33:19 +02:00
Thomas Haller
bca28c8c0c libnm/doc: explicitly point out privacy issue of setting wifi.hidden 2018-04-26 16:52:40 +02:00
Thomas Haller
701ef05d4f iwd: fix crash updating scan list when comparing new APs
Fixes: d7b1a911d9
2018-04-24 21:55:56 +02:00
Andreas Henriksson
be28790183 iwd: fix assertion failure when requesting scan
if device *is* a NM_DEVICE_IWD, then make sure to not pass that to
_nm_device_wifi_request_scan (which asserts on anything else than a
NM_DEVICE_WIFI device).

The crash can be triggered by enabling wifi.backend=iwd and clicking
on the 'select network' item in gnome shell for example. The journal
output looks like this:

NetworkManager[1861]: invalid cast from 'NMDeviceIwd' to 'NMDeviceWifi'
NetworkManager[1861]: **
NetworkManager[1861]: NetworkManager:ERROR:src/devices/wifi/nm-device-wifi.c:1127:_nm_device_wifi_request_scan: assertion failed: ((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) ((_obj)); GType __t = ((nm_device_wifi_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))
systemd[1]: NetworkManager.service: Main process exited, code=dumped, status=6/ABRT
systemd[1]: NetworkManager.service: Failed with result 'core-dump'.

Fixes: 297d4985ab

https://github.com/NetworkManager/NetworkManager/pull/107
2018-04-24 21:27:25 +02:00
Thomas Haller
9731b06b78 device: fix nm_device_get_type_description() for veth devices
Without this, nm_device_get_type_description() would quite likely
return "ethernet" for NMDeviceVeth types. This is wrong and was
broken recently.

Fixes: 0775602574
2018-04-24 21:00:17 +02:00
Thomas Haller
5f8f427361 core: merge branch 'th/core-fixes-for-shutdown'
https://github.com/NetworkManager/NetworkManager/pull/98
2018-04-24 12:30:40 +02:00
Thomas Haller
3d2da8cd05 core/dbus: stop NMDBusManager and reject future method calls
During shutdown, we will need to still iterate the main loop
to do a coordinated shutdown. Currently we do not, and we just
exit, leaving a lot of objects hanging.

If we are going to fix that, we need during shutdown tell
NMDBusManager to reject all future operations.

Note that property getters and "GetManagerObjects" call is not
blocked. It continues to work.

Certainly for some operations, we want to allow them to be called even
during shutdown. However, these have to opt-in.

This also fixes an uglyness, where nm_dbus_manager_start() would
get the set-property-handler and the @manager as user-data. However,
NMDBusManager will always outlife NMManager, hence, after NMManager
is destroyed, the user-data would be a dangling pointer. Currently
that is not an issue, because
  - we always leak NMManager
  - we don't run the mainloop during shutdown
2018-04-24 10:25:26 +02:00
Thomas Haller
5b199b2e7d core/trivial: add FIXME comments about clean shutdown at exit 2018-04-24 10:25:26 +02:00
Thomas Haller
8b5f641211 settings: pass in authentication subject to nm_settings_add_connection_dbus()
nm_settings_add_connection_dbus() has two callers. One of them is NMManager
during AddAndActivate. In this case, the NMActiveConnection already created
an auth-subject. Re-use it.

Note how creating an auth-subject involves reading procfs to determine
whether the process still exists. This is not about the additional
overhead of that, but about the race where the process could drop
of in the meantime. The calling process might be gone now, and we would
fail creating the auth-subject. There is no need for that, because we
already evaluated all information we need. Quite likely, in the case
of this race, PolicyKit will also determine that the process is gone
and fail authorization too. But that's PolicyKit's decision to make,
not nm_settings_add_connection_dbus()'s.
2018-04-24 10:25:26 +02:00
Thomas Haller
f4fc62bad8 manager: track pending authorizations for activating connections
We cannot just fire off asynchronous actions without keeping a handle
to them. Otherwise, it's impossible for NMManager to know which
asynchronous operations are pending, and more importantly: it cannot
cancel them.

One day, I want that we do a clean shutdown, where NetworkManager stops
all pending operations, and cleans up everything. That implies, that
every operation is cancellable in a timely manner.

Rework pending nm_active_connection_authorize() calls to be tracked in a
list, so that they are still reachable to NMManager. Note that currently
NMManager does not yet try to cancel these operations ever. However, it
would now be possible to do so.
2018-04-24 10:25:26 +02:00
Thomas Haller
dc2004ddfb core: fix cancelling of authorization request for active connection
The async authorization request also carries user-data and its result
must always be handled. For example, it might carry a GDBusMethodInvocation
context, which must be returned and freed.

Hence, when cancelling the request, we must always invoke the callback.

Also, when the NMActiveConnection progresses to state disconnected,
automatically abort the authorization request.
2018-04-24 10:23:14 +02:00
Thomas Haller
9a579171b5 core: fix unreachable assertion in nm_active_connection_set_state() 2018-04-24 09:03:39 +02:00