Commit graph

10920 commits

Author SHA1 Message Date
Thomas Haller
884a28b28c connectivity: avoid busy looping with connectivity-check failed
It seems, curl_multi_socket_action() can fail with

  connectivity check failed: 4

where "4" means CURLM_INTERNAL_ERROR.

When that happens, it also seems that the file descriptor may still have data
to read, so the glib IO callback _con_curl_socketevent_cb() will be called in
an endless loop. Thereby, keeping the CPU busy with doing nothing (useful).

Workaround by disabling polling on the file descriptor when something
goes wrong.

Note that optimally we would cancel the affected connectivity-check
right away. However, due to the design of libcurl's API, from within
_con_curl_socketevent_cb() we don't know which connectivity-checks
are affected by a failure on this file descriptor. So, all we can do
is avoid polling on the (possibly) broken file descriptor. Note that
we anyway always schedule a timeout of last resort for each check. Even
if something goes very wrong, we will fail the check within 15 seconds.

https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=903996
2018-07-24 17:15:15 +02:00
Thomas Haller
970af59731 connectivity: add compile time check that "curl_socket_t" is a typedef to plain "int"
On non-Windows, libcurl's "curl_socket_t" type is just a typedef for
int. We rely on that, because we use it as file descriptor.

Add a compile time check to ensure that.
2018-07-24 15:39:12 +02:00
Thomas Haller
cd0bd8a2ee connectivity/trivial: rename socket argument in multi_socket_cb() callback
"s" might be a good name for a temporary string.

But here it's really a file descriptor. Call it "fd".
2018-07-24 15:38:23 +02:00
Thomas Haller
a24f118a1f connectivity/trivial: rename local functions to avoid "curl" prefix
Since this is "C" there are not namespaces and libraries commonly choose
a particular name prefix for their symbols.

In case of libcurl, that is "curl_".

We should avoid using the same name prefix, and choose something distinct.
2018-07-24 15:02:58 +02:00
Thomas Haller
3000ade72a core: improve error message when activating profile
Before:

    $ nmcli connection up my-wired
    Error: Connection activation failed: No suitable device found for this connection.

After:

    $ nmcli connection up my-wired
    Error: Connection activation failed: No suitable device found for this connection (device eth0 not available because device has no carrier).

This relies on nm_manager_get_best_device_for_connection() giving a
suitable error. That is however a bit complicated, because if no
suitable device is found, it's not immediately clear what is the
exact reason. E.g. if you try to activate a Wi-Fi profile, the
failure reason

    "SSID is not visible"

is better than

    "Wi-Fi profile cannot activate on ethernet device".

This is controlled by carefully setting the failure codes
NM_UTILS_ERROR_CONNECTION_AVAILABLE_* to indicate an absolute
relevance of the failure. And subsequently, by selecting the failure
with the highest relevance. This might still need some improvements,
for example by reordering checks (so that more relevant failures
are handled first) and tweaking the error relevance.
2018-07-24 09:39:09 +02:00
Thomas Haller
e9f6bb0bbb core: improve error message when activating profile on device
Before:

    $ nmcli connection up my-wired ifname eth0
    Error: Connection activation failed: Connection 'my-wired' is not available on the device eth0 at this time.

After:

    $ nmcli connection up my-wired ifname eth0
    Error: Connection activation failed: Connection 'my-wired' is not available on device eth0 because device has no carrier
2018-07-24 09:39:09 +02:00
Thomas Haller
7bad40109e core: return error reason from nm_manager_get_best_device_for_connection()
Still unused, but will be used to give a better failure reason when
no device is found.

The difficulty here is to select the failure message from the most appropriate
device. This might still need some tweaking by setting the error codes accordingly
and re-ordering checks so that failure cares that are more accurate are handled
first.
2018-07-24 09:39:09 +02:00
Thomas Haller
33a88ca566 core: give better error reason why device is incompatible with profile
Note the special error codes  NM_UTILS_ERROR_CONNECTION_AVAILABLE_*.
This will be used to determine, whether the profile is fundamentally
incompatible with the device, or whether just some other properties
mismatch. That information will be importand during a plain `nmcli
connection up`, where NetworkManager searches all devices for a device
to activate. If no device is found (and multiple errors happened),
we want to show the error that is most likely relevant for the user.

Also note, how NMDevice's check_connection_compatible() uses the new
class field "device_class->connection_type_check_compatible" to simplify
checks for compatible profiles.

The error reason is still unused.
2018-07-24 09:39:09 +02:00
Thomas Haller
570e1fa75b core: give better error reason why device is unavailable
The error reason is still unused.
2018-07-24 09:39:09 +02:00
Thomas Haller
2ce4167967 device: replace NM_DEVICE_CLASS_DECLARE_TYPES() macro by explicit initialization
It seems to me the NM_DEVICE_CLASS_DECLARE_TYPES() macro confuses more
than helping. Let's explicitly initialize the two fields, albeit with
another helper macro NM_DEVICE_DEFINE_LINK_TYPES() to get the list of
link-types right.

For consistency, also leave nop-lines like

  device_class->connection_type_supported = NULL;
  device_class->link_types = NM_DEVICE_DEFINE_LINK_TYPES ();

because all NMDevice class init methods should have this same
boiler plate code and to make it explicit that this is intended.
And there are only 3 occurences where this actually comes into play.
2018-07-24 09:39:09 +02:00
Thomas Haller
c9883b85a2 device: also use NM_DEVICE_CLASS_DECLARE_TYPES() for types without link-types
NMDeviceOvsPort and NMDeviceOvsInterface don't have an underlying link-type from platform.
Still use NM_DEVICE_CLASS_DECLARE_TYPES() macro, for consistancy reasons.

This requires to extend NM_DEVICE_CLASS_DECLARE_TYPES() macro, to support
a variadic argument list with zero link-types.
2018-07-24 09:39:09 +02:00
Thomas Haller
87a60c4596 device: use NM_DEVICE_CLASS_DECLARE_TYPES() to set connection_type_supported of device class
the macro already does it just fine. Use it.
2018-07-24 09:39:09 +02:00
Thomas Haller
0cbf2c8c2a device: wrap NM_DEVICE_CLASS_DECLARE_TYPES() macro with do-while block 2018-07-24 09:39:09 +02:00
Thomas Haller
b9ae79c273 device/trivial: rename NMDeviceClass.connection_type to connection_type_supported
The term "connection_type" is overused. Give it a more distinct name.
2018-07-24 09:39:09 +02:00
Thomas Haller
0b8e1fd971 core/trival: rename nm_device_match_hwaddr() function to nm_device_match_parent_hwaddr()
This name is better, because it compares the MAC address of the device's
parent.
2018-07-24 09:39:09 +02:00
Thomas Haller
c3ab0ed60f device/trivial: rename parent-class variable in device class constructor
The majority of device implementations name their parent-class variable
"device_class". That also makes more sense as it is more consistant.
E.g. "parent" sounds like it's the direct parent, but that is not
the crucial point here. The crucial point at this place, is that we
access the NMDeviceClass typed pointer. Rename.
2018-07-24 09:39:09 +02:00
Thomas Haller
39f47e2f7e wwan/trivial: rename NMModemClass.check_connection_compatible() to use unique name
We also have NMDeviceClass.check_connection_compatible(). It is preferable
to use unique names, especially for the virtual function table. A reasonable
thing to do is grep for the function name to find all places that implement
this function. But if different classes use the same name, grep just
turns up annoying false positives.
2018-07-24 09:39:09 +02:00
Lubomir Rintel
159ff23268 dhcp/dhclient-utils: skip over dhclient.conf blocks
Extend the lame-ass dhclient.conf parser to ignore the blocks we can't
do anything useful about: alias{}, pseudo{} and even lease{}.

Note that there's still a lot of cases we can't handle without a
full-fledged dhclient.conf parser -- notably the files that don't use
line breaks to separate the statements.

That is probably okay -- the whole thing is probably mostly useless and
we shall ever bother only about cases that actually cause trouble.

https://github.com/NetworkManager/NetworkManager/pull/153
2018-07-23 12:33:51 +02:00
Thomas Haller
9a08276756 systemd: revert local modification for -std=gnu89 compilation and missing __STDC_VERSION__
We used to build with -std=gnu89 so commit 1391bdfa61
added a local patch to systemd code to avoid compilation error due to
missing __STDC_VERSION__ define.

In the meantime, since commit ba2b2de3ad
and commit b9bc20f4da, we also use -std=gnu99
and thus __STDC_VERSION__ is defined.

Revert our local modification.
2018-07-17 17:50:20 +02:00
Thomas Haller
a75ab799e4 build: create "config-extra.h" header instead of passing directory variables via CFLAGS
1) the command line gets shorter. I frequently run `make V=1` to see
   the command line arguments for the compiler, and there is a lot
   of noise.

2) define each of these variables at one place. This makes it easy
   to verify that for all compilation units, a particular
   define has the same value. Previously that was not obvious or
   even not the case (see commit e5d1a71396
   and commit d63cf1ef2f).
   The point is to avoid redundancy.

3) not all compilation units need all defines. In fact, most modules
   would only need a few of these defines. We aimed to pass the necessary
   minium of defines to each compilation unit, but that was non-obvious
   to get right and often we set a define that wasn't used. See for example
   "src_settings_plugins_ibft_cppflags" which needlessly had "-DSYSCONFDIR".
   This question is now entirely avoided by just defining all variables in
   a header. We don't care to find the minimum, because every component
   gets anyway all defines from the header.

4) this also avoids the situation, where a module that previously did
   not use a particular define gets modified to require it. Previously,
   that would have required to identify the missing define, and add
   it to the CFLAGS of the complation unit. Since every compilation
   now includes "config-extra.h", all defines are available everywhere.

5) the fact that each define is now available in all compilation units
   could be perceived as a downside. But it isn't, because these defines
   should have a unique name and one specific value. Defining the same
   name with different values, or refer to the same value by different
   names is a bug, not a desirable feature. Since these defines should
   be unique accross the entire tree, there is no problem in providing
   them to every compilation unit.

6) the reason why we generate "config-extra.h" this way, instead of using
   AC_DEFINE() in configure.ac, is due to the particular handling of
   autoconf for directory variables. See [1].
   With meson, it would be trivial to put them into "config.h.meson".
   While that is not easy with autoconf, the "config-extra.h" workaround
   seems still preferable to me.

[1] https://www.gnu.org/software/autoconf/manual/autoconf-2.63/html_node/Installation-Directory-Variables.html
2018-07-17 17:46:39 +02:00
Thomas Haller
1c2033301c hostname: drop define IFCFG_DIR which is only used once
Also, "src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-common.h"
already has a define IFCFG_DIR, but with a different value.
We shouldn't name different things the same.
2018-07-17 17:46:01 +02:00
Thomas Haller
31a0881f3c keyfile: use gs_unref_keyfile in nms_keyfile_reader_from_file() 2018-07-17 15:09:53 +02:00
Thomas Haller
e512cec770 platform: merge 'jbeta:wireguard-genl-family-lifetime'
https://github.com/NetworkManager/NetworkManager/pull/161
2018-07-13 17:37:24 +02:00
Jan Alexander Steffens (heftig)
21f955b4dd wifi/ifd: Allow D-Bus activation to launch iwd
iwd does not ship activation configuration yet; until then we simply
fail the way we already do.

https://bugzilla.gnome.org/show_bug.cgi?id=796805
2018-07-13 15:58:35 +02:00
Javier Arteaga
6ea0cd1300 platform: put wireguard_family_id in NMPObjectLink
Limit the lifetime of the cached genl family ID to the lifetime of the
interface so we correctly handle module reloads.

https://github.com/NetworkManager/NetworkManager/pull/161
2018-07-13 10:38:42 +02:00
Beniamino Galvani
260cded3d6 device: destroy pending acd-managers when the device disconnects
We previously kept any acd-manager running if the device was
disconnected. It was possible to trigger a crash by setting a long
dad-timeout and interrupting the activation request:

  nmcli con add type ethernet ifname eth0 con-name eth0+ ip4 1.2.3.4/32
  nmcli con mod eth0+ ipv4.dad-timeout 10000
  nmcli -w 2 con up eth0+
  nmcli con down eth0+

After this, the n-acd timer would fire after 10 seconds and try to
disconnect an already disconnected device, throwing the assertion:

  NetworkManager:ERROR:src/devices/nm-device.c:9845:
  activate_stage5_ip4_config_result: assertion failed: (req)

Fixes: 28f6e8b4d2
2018-07-11 17:27:11 +02:00
Thomas Haller
ca9981eb5d connectivity: downgrade verbosity of error logging
Such failures during connectivity checks, may happen frequently
and due to external causes. Don't log with error level to avoid
spamming the logfile.
2018-07-11 16:43:28 +02:00
Beniamino Galvani
c02d1c488f ifcfg-rh: SR-IOV support 2018-07-11 16:16:22 +02:00
Beniamino Galvani
53c2951f61 device: configure SR-IOV 2018-07-11 16:16:22 +02:00
Beniamino Galvani
8720dd3df1 platform: add support for changing VF attributes 2018-07-11 16:16:22 +02:00
Beniamino Galvani
7df3333879 platform: allow setting drivers-autoprobe on SR-IOV PFs
It is possible to tell kernel not to automatically autoprobe drivers
for VFs. This is useful, for example, if the VF must be used by a VM.
2018-07-11 16:16:22 +02:00
Beniamino Galvani
347e0d8b5a ifcfg-rh: add @match_key_type argument to svGetKeys()
Add a @match_key_type to svGetKeys() to filter the keys to be returned.
2018-07-11 16:16:22 +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
8d65f636e1 devices/ovs: expose slaves on D-Bus for OVS bridges and ports 2018-07-10 13:12:02 +02:00
Beniamino Galvani
522e49edd6 policy: track best active connections rather than best devices
If a VPN with default route is activated, the Manager's
PrimaryConnection property is not updated to indicate the VPN as
primary connection.

This happens because the PrimaryConnection property gets updated when
the default_ipX_device property of NMPolicy changes, and the primary
connection is set to the activation request currently pending on the
default device. We select the base (for example, ethernet) device as
best device and therefore the NMActRequest active on it is selected as
primary connection.

This patch fixes the problem by properly selecting the VPN as
primary. It seems a better choice to track best active connections
directly from NMPolicy instead of going through two steps.
2018-07-09 14:56:59 +02:00
Beniamino Galvani
e1888ad4e5 policy: choose best VPN based on metrics
As the FIXME suggests, select the VPN with best metric to determine
the best IP config.
2018-07-09 13:34:29 +02:00
Beniamino Galvani
e205664ba8 manager: accept non-null device for VPN activations
Commit 10753c3616 ("manager: merge VPN handling into
_new_active_connection()") added a check to fail the activation of
VPNs when a device is passed to ActivateConnection(), since the device
argument is ignored for VPNs.

This broke activating VPNs from nm-applet as nm-applet sets both the
specific_object (parent-connection) and device arguments in the
activation request.

Note that we already check in _new_active_connection() that when a
device is supplied, it matches the device of the parent
connection. Therefore, the check can be dropped.

Reported-by: Michael Biebl <biebl@debian.org>
Fixes: 10753c3616

https://github.com/NetworkManager/NetworkManager/pull/159
2018-07-09 13:28:47 +02:00
Thomas Haller
530b82a372 build/meson: fix meson build without pppd
Fixes: 1cdb36b8de
2018-07-09 12:02:37 +02:00
Thomas Haller
4e4b363cc2 platform: reduce logging level for wireguard messages 2018-07-09 11:42:35 +02:00
Thomas Haller
67f50f64d9 platform: fix -Werror=maybe-uninitialized in _new_from_nl_link()
Fixes: 0827d4c2e4
2018-07-09 11:36:43 +02:00
Lubomir Rintel
b200e5d8ed platform/linux: drop an unused variable
Fixes: 2ac5860a06
2018-07-09 11:32:09 +02:00
Jan Tojnar
1cdb36b8de ppp-manager: use configured pppd path
Path to pppd can be set via configure flag but the source code ignores it.

Let's use PPPD_PATH like other calls of nm_utils_find_helper do.

https://bugzilla.gnome.org/show_bug.cgi?id=796752
2018-07-09 11:27:13 +02:00
Lubomir Rintel
79ddef403c merge: branch 'wireguard-platform' of https://github.com/jbeta/NetworkManager
https://github.com/NetworkManager/NetworkManager/pull/143
2018-07-09 11:08:12 +02:00
Olivier Gayot
d1a98d6892 device: fix order of params in nm_match_spec_device prototype
The following commit:

  b869d9cc0 device: add spec "driver:" to match devices

added two parameters ("driver" and "driver_version") to the
nm_match_spec_device() function.

However, the definition of the function and its declaration are not
consistent.

The prototype shows:
  nm_match_spec_device (const GSList *specs,
                        const char *interface_name,
                        const char *driver,
                        const char *driver_version,
                        const char *device_type,

But the definition shows:
  nm_match_spec_device (const GSList *specs,
                        const char *interface_name,
                        const char *device_type,
                        const char *driver,
                        const char *driver_version,

Since all parameters are pointers to const char, the type checking
succeeds at compile time.

All currently existing invocations of the function are correct and pass
the arguments in the order described in the definition/implementation.
This patch only changes the prototype so that potential future
invocations don't end up buggy.

Fixes: b869d9cc0d
2018-07-06 14:48:42 +02:00
Beniamino Galvani
fc99aad378 ip-tunnel: allow wired setting for some tunnel modes
gretap and ip6gretap ip-tunnel interfaces encapsulate L2 packets over
IP. Allow adding a wired setting for such connections so that users
can change the interface MAC.
2018-07-02 17:55:14 +02:00
Beniamino Galvani
3f9f9f7fa2 ip-tunnel: add support for ip6gre and ip6gretap tunnel connections 2018-07-02 17:55:14 +02:00
Beniamino Galvani
f9199c7fb5 ip-tunnel: add support for gretap tunnel connections 2018-07-02 17:55:14 +02:00
Beniamino Galvani
09a868a24e platform: add ip6gre/ip6gretap tunnels support
Add platform support for IP6GRE and IP6GRETAP tunnels. The former is a
virtual tunnel interface for GRE over IPv6 and the latter is the L2
variant.

The platform code internally reuses and extends the same structure
used by IPv6 tunnels.
2018-07-02 17:55:14 +02:00
Beniamino Galvani
4c2862b958 platform: add gretap tunnels support
Add platform support for GRETAP tunnels (Virtual L2 tunnel interface
GRE over IPv4) partially reusing the existing GRE code.
2018-07-02 17:55:14 +02:00
Beniamino Galvani
cdad8c6df9 platform: uniform logging for link-add functions
Print all the platform-lnk attributes in a consistent manner.
2018-07-02 17:55:14 +02:00