Commit Graph

25139 Commits

Author SHA1 Message Date
Thomas Haller
4087024a9b shared: move assertion in _NM_UTILS_STRING_TABLE_LOOKUP_DEFINE()
Move the assertion for valid LIST first. It only checks static data,
and regardless of the entry_cmd, it should be done first.

Fixes: f4d12f7b59 ('shared: add NM_UTILS_STRING_TABLE_LOOKUP_STRUCT_DEFINE() macro for lookup of structs')
2020-03-02 16:20:50 +01:00
Thomas Haller
8b63fd8cc0 shared: fix handling %NULL argument in nm_ref_string_equals_str()
Fixes: 190a8ed425 ('shared: add nm_ref_string_equals_str() helper')
2020-03-02 15:49:41 +01:00
Thomas Haller
30e90b0d95 license: add Tambet to RELICENSE.md
https://mail.gnome.org/archives/networkmanager-list/2020-March/msg00000.html
2020-03-02 12:33:46 +01:00
Antonio Cardace
50da785be1 nm-setting-bond: fix '[up|down]delay', 'miimon' validation
Just looking at the hashtable entry of 'updelay' and 'downdelay' options
is wrong, we have to inspect their values to check if they're
actually enabled or not.

Otherwise bond connections with valid settings will fail
when created:

$ nmcli c add type bond ifname bond99 bond.options miimon=0,updelay=0,mode=0
Error: Failed to add 'bond-bond99' connection: bond.options: 'updelay' option requires 'miimon' option to be set

Also add unit tests.

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

Fixes: d595f7843e ('libnm: add libnm/libnm-core (part 1)')
2020-02-28 15:45:34 +01:00
Thomas Haller
7625e2483f license: add Pavel to RELICENSE.md
https://mail.gnome.org/archives/networkmanager-list/2020-February/msg00040.html
2020-02-28 08:45:44 +01:00
Thomas Haller
e9ca7eee2c device/trivial: move code around
Or patterns is to have the property get/set functions before
the object's create/destroy code. Move it.
2020-02-26 18:25:27 +01:00
Thomas Haller
32ea8a3e36 device: merge branch 'th/device-cleanup-properties' 2020-02-26 18:05:00 +01:00
Thomas Haller
0622ad5a91 device/trivial: rename property enums for statistics properties of NMDevice
The name of the property name should resemble the define for the
name.
2020-02-26 18:04:01 +01:00
Thomas Haller
4bff811b75 device/trivial: add comment about NMDevice properties writable from D-Bus
These are special. Their setter gets called via D-Bus' SetProperty.
Mark them with a comment.
2020-02-26 18:03:44 +01:00
Thomas Haller
acb9615060 device: don't make NM_DEVICE_(IP|DHCP)(4|6)_CONFIG properties writable
It's not necessary, nor used, nor actually implemented.
2020-02-26 17:54:15 +01:00
Thomas Haller
5c00980c13 device: don't make NM_DEVICE_DRIVER_VERSION property writable 2020-02-26 17:54:15 +01:00
Thomas Haller
e347886a5f device: don't make NM_DEVICE_FIRMWARE_VERSION property writable 2020-02-26 17:54:15 +01:00
Thomas Haller
8d5c4b26e4 device: don't make NM_DEVICE_FIRMWARE_MISSING property writable
It's not necessary nor used.
2020-02-26 17:54:15 +01:00
Thomas Haller
13059ff784 device: don't make NM_DEVICE_IP4_ADDRESS property writable
It's not necessary nor used.
2020-02-26 17:54:15 +01:00
Thomas Haller
b9f6283c80 libnm,all: merge branch 'th/libnm-interface-name-cleanup'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/416
2020-02-26 17:52:22 +01:00
Thomas Haller
3efe070dfc libnm: validate "connection.interface-name" at one place only
Don't spread the validation for the interface name between multiple
places. There should be one place only, so when you search for how
this property gets verified, you can find the single place.

That requires to move the special handling for OVS interfaces to
NMSettingConnection.
Since we already have _nm_setting_ovs_interface_verify_interface_type(),
that is easy.
2020-02-26 17:51:14 +01:00
Thomas Haller
294de8487e shared: add NMU_IFACE_OVS_OR_KERNEL for nm_utils_ifname_valid()
Depending on the type, OVS interfaces also have a corresponding netdev
in kernel (e.g. type "internal" does, type "patch" does not).

Such a case is neither NMU_IFACE_OVS nor NMU_IFACE_KERNEL (alone). There should
be a special type to represent those cases.

Add NMU_IFACE_OVS_OR_KERNEL for that.
2020-02-26 17:51:14 +01:00
Thomas Haller
807cddc754 shared: add NMU_IFACE_ANY for nm_utils_ifname_valid()
nm_utils_ifname_valid() is to validate "connection.interface-name"
property. But the exact validation depends on the connection type.

Add "NMU_IFACE_ANY" to validate the name to check whether it would be
valid for any connection type.

This is for completeness and for places where the caller might not know
the connection type.
2020-02-26 17:51:14 +01:00
Thomas Haller
a11edd4a82 libnm: always return normalized-type from _nm_setting_ovs_interface_verify_interface_type()
We should return the chosen type whenever we can verify the setting.
Previously, the normalized-type output argument was only set when
normalization was actually necessary.

On most cases, the caller cares whether the setting verifies and which
interface type is chosen. It's much less likely that a caller cares
only about the normalized-type if normalization is actually necessary.

Whenever we return TRUE (indicating that the setting is valid), also
return the chosen interface-type.
2020-02-26 17:51:14 +01:00
Thomas Haller
07b7c82d04 libnm: allow _nm_setting_ovs_interface_verify_interface_type() without NMSettingOvsInterface instance
_nm_setting_ovs_interface_verify_interface_type() does verify and
normalize both. Especially for verify, it's useful to run the operation
without having a NMSettingOvsInterface instance, because we might
want to know how normalization would react, if we had a
NMSettingOvsInterface instance.

Allow for that.
2020-02-26 17:51:14 +01:00
Thomas Haller
aa6bc2868d ifcfg-rh: use nm_utils_ifname_valid() for validating interface-name in reader
Maybe the reader should not try to add its own validation. It
could just read the value, set it in the profile, and let
nm_connection_verify() handle it.

However:

 - in this form the code only logs a warning about invalid setting.
   If we let it come to nm_connection_verify(), the connection profile
   will be entirely rejected. I think this makes sense, because ifcfg
   files may be edited by the user and we don't know what is out there.

 - it's nicer to show a warning that specifically mentions the DEVICE=
   variable. There error message we get from nm_connection_verify()
   is no longer aware of ifcfg peculiarities.

Instead: use the appropriate validation function.
2020-02-26 17:51:13 +01:00
Thomas Haller
de19631e9f libnm: remove redundant check from "nm-setting-bond.c"'s validate_ifname() 2020-02-26 17:51:13 +01:00
Thomas Haller
f725209bb4 settings: simplify property setter from GVariant to NMSettingConnection:interface-name
The interface-name property has several deprecated aliases, like
"bridge.interface-name". For backward compatibility, we keep handling
them.

In particular, the "missing_from_dbus_fcn" handler is set. This handles
the case where GVariant only contains the deprecated form, but not
"connection.interface-name".

Previously, from_dbus_fcn() would check whether the deprecated form was
present, and -- only if that form was invalid -- prefer it. The idea was
to fail validation if the deprecated property was invalid.

I think that is not necessary. Just completely ignore the deprecated property,
if the new property is present.

What might make sense is to check whether the deprecated and the new
form are both present, that they are identical. However, I don't think
that is worth the effort.
2020-02-26 17:51:13 +01:00
Thomas Haller
47a654d398 clients: use nm_utils_ifname_valid() to validate interface name in nm_vpn_wireguard_import()
We use the filename of the imported .conf file for "connection.interface-name".
That follows what `wg-quick` does.

However, we also validate that the interface name is valid UTF-8
(otherwise -- as it currently is -- the setting couldn't be send via
D-Bus). As such, we have stricter requirements.

We want to fail early and tell the user when the filename is unsuitable.
Failing later gives a worse user experience, because the failure message
about invalid "connection.interface-name" wouldn't make it clear that
the filename is wrong.

Use the appropriate function to validate "connection.interface-name".

Before:

    $ touch $'./a\344b.conf'
    $ nmcli connection import type wireguard file $'./a\344b.conf'
    Error: failed to import './a?b.conf': Failed to create WireGuard connection: connection.interface-name: 'a?b': interface name must be UTF-8 encoded.

Now:

    $ nmcli connection import type wireguard file $'./a\344b.conf'
    Error: failed to import './a?b.conf': The name of the WireGuard config must be a valid interface name followed by ".conf".
2020-02-26 17:51:13 +01:00
Thomas Haller
41480d48ae libnm: don't validate "connection.interface-name" from "nm-setting-infiniband.c"'s verify()
There should not be multiple places to validate the interface-name.

The check in "nm-setting-infiniband.c" is unnecessary and wrong.

It's unnecessary, because _nm_connection_verify() takes care to
first verify the NMSettingConnection instance.

It's wrong, because it does not check the property the same way as
NMSettingConnection does (e.g. it does not check for valid UTF-8).
2020-02-26 17:51:13 +01:00
Thomas Haller
74e2203e19 libnm: in find_virtual_interface_name() ensure return value stays alive
It's not clear that the returned string is still valid after we
unref the GVariant that contains it. Also return the reference to
the variant.
2020-02-26 17:51:13 +01:00
Thomas Haller
f3dd41ad7e libnm: validate settings in _nm_connection_verify() in defined order
Fully sort the settings in _nm_connection_verify(). Previously, only the
NMSettingConnection instance was sorted first (as required). The remaining
settings were in undefined order. That means, we would validate settings
in undefined order, and if multiple settings have an issue, the reported
error would be undefined.

Instead, use nm_connection_get_settings() which fully sorts the settings
(and of course, sorts NMSettingConnection first as we require it).

Also, this way we no longer need to allocate multiple GSList instances
but only malloc() one array large enough to contain all settings.
2020-02-26 17:51:13 +01:00
Thomas Haller
0718098dcb libnm: use nm_utils_hash_values_to_array() to implement nm_connection_get_settings() 2020-02-26 17:51:13 +01:00
Thomas Haller
d4d9e9e7bb shared: reject reserved names from "connection.interface-name"
"all" and "default" never works.

"bonding_masters" works if you unload the bonding module. Well,
that should not really be called working...

Reject these names.
2020-02-26 17:51:13 +01:00
Thomas Haller
ef567805bb shared: reject '%' from nm_utils_ifname_valid() for kernel names
Generally, it's dangerous to reject values that were accepted
previously. This will lead to NetworkManager being unable to load
a profile from disk, which was loadable previously.

On the other hand, kernel would not have treated this setting as
it was intended. So, I would argue that the such a setting was not
working (as intended) anyway.

We can only hope that users don't configure arbitrary interface names.
It generally isn't a good idea to do, so "breaking" such things is less
of a concern.
2020-02-26 17:51:13 +01:00
Thomas Haller
b15a9b3dc4 supplicant: allocate blobs hash table lazily for supplicant config
It's very unlikely that we have actual blobs for a Wi-Fi network.
That is because the settings plugins (keyfile, ifcfg-rh) convert
blobs to files on disk when writing the profile. So, you can only
have them by editing the files directly to contain blobs.

At that point, don't always create the GHashTable for blobs.
2020-02-26 12:27:36 +01:00
Thomas Haller
9add51ef16 license: add Sigfox to RELICENSE.md
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/365
2020-02-24 15:56:52 +01:00
Beniamino Galvani
47f81864ba ovs: merge branch 'bg/ovs-no-bridge-rh1797696'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/422
https://bugzilla.redhat.com/show_bug.cgi?id=1797696
2020-02-24 15:02:06 +01:00
Beniamino Galvani
c5c49995b1 ovs: fail port enslavement when the bridge device is not found
Fail the enslavement of the ovs port if the bridge device is not
found, instead of generating assertions and potentially crash later.

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

Fixes: 101e65d2bb ('ovs: allow changing mac address of bridges and interfaces')
2020-02-24 15:00:46 +01:00
Beniamino Galvani
c8b5a3f91a ovs: fail port enslavement when the bridge AC is not found
The previous code tried to get the bridge active connection and it
used the port active connection instead in case of failure. This
doesn't seem right, as in nm-ovsdb.c the bridge AC is used to get the
bridge settings (including the uuid, interface name, and cloned mac).

In case of failure getting the bridge AC we should just fail.

Fixes: 830a5a14cb ('device: add support for OpenVSwitch devices')
2020-02-24 15:00:46 +01:00
Beniamino Galvani
5a7b83ea0a n-dhcp4: keep trying after a failure in send()
Currently if an error is encountered during a send() of a message, the
client fails and there is no possibility of recover, since no timers
are armed after a failed event dispatch. An easy way to reproduce a
failure is to add a firewall rule like:

  iptables -A OUTPUT -p udp --dport 67 -j REJECT

which makes the send() fail with EPERM during the renew. In such case,
the client should continue (failing) until it reaches the rebind phase
at T2, when it will be able to renew the lease using the packet
socket.

In general, a failure to send a packet should not cause the failure of
the client.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/419
https://bugzilla.redhat.com/show_bug.cgi?id=1806516
2020-02-24 14:58:33 +01:00
Beniamino Galvani
910267cf5f n-dhcp4: fix logging macro
The level can be a complex expression, don't use it directly in the
macro.
2020-02-24 14:58:24 +01:00
Thomas Haller
9f2014ac64 shared: fix suffix for NM_GOBJECT_PROPERTIES_DEFINE_BASE*() for multiple definitions
To really use multiple NM_GOBJECT_PROPERTIES_DEFINE_BASE*() defines in
the same source file, several fixes to the suffix handling are
necessary. This fixes commit f13c7e3bbd ('shared: extend
NM_GOBJECT_PROPERTIES_DEFINE*() macros to append suffix to defined
names') to really work.

Fixes: f13c7e3bbd ('shared: extend NM_GOBJECT_PROPERTIES_DEFINE*() macros to append suffix to defined names')
2020-02-24 13:13:34 +01:00
Thomas Haller
f12b830a94 gitlab-ci: fix deploying documentation after switching to Fedora 31
Fixes: ec8068ec0c ('gitlab-ci: add "t_fedora:32" and by default build on Fedora 31')
2020-02-22 13:57:56 +01:00
Thomas Haller
9848589fbf platform: avoid compiler warning in _NMP_OBJECT_TYPE_IS_OBJ_WITH_IFINDEX()
Surisingly, the compiler may detect the remaining obj_type in
the default switch. Then, inlining nmp_class_from_type() it may detect
that this is only possible to hit with an out or range access to
_nmp_classes array.

Rework the code to avoid that compiler warning. It's either way not
supposed to happen.

Also, drop the default switch case and explicitly list the enum values.
Otherwise it is error prone to forget a switch case.
2020-02-22 12:09:56 +01:00
Thomas Haller
fd0d292caf platform: belatedly add NMP_OBJECT_TYPE_LNK_VRF to _NMP_OBJECT_TYPE_IS_OBJ_WITH_IFINDEX()
Fixes: 7c73c6a038 ('platform: add VRF support')
2020-02-22 12:09:56 +01:00
Thomas Haller
46bc6d93d6 release: bump version to 1.23.2-dev 2020-02-21 20:35:02 +01:00
Thomas Haller
cb2c00d823 all: merge branch 'th/fix-gitlab-ci-failures' 2020-02-21 20:34:34 +01:00
Thomas Haller
c437d6c60a libnm-core/tests: avoid -Wstring-compare in unit test for NM_IN_SET()
Clang 10 doesn't like NM_IN_SET() with strings and is right about that:

    ../libnm-core/tests/test-general.c:7763:9: error: result of comparison against a string literal is unspecified (use an explicit string comparison function instead) [-Werror,-Wstring-compare]
            (void) NM_IN_SET ("a",  "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16");
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

However, NM_IN_STRSET() should work.
2020-02-21 18:27:40 +01:00
Thomas Haller
86dfc4b099 build: disable -Wimplicit-fallthrough warning with clang
Seems clang 10 got support for -Wimplicit-fallthrough, but does
not honor the code comments to suppress the warning. What a
disaster.

Try to detect it.

See-also: https://github.com/ClangBuiltLinux/linux/issues/   #636
See-also: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=e2079e93f562c7f7a030eb7642017ee5eabaaa10
2020-02-21 18:27:40 +01:00
Thomas Haller
ffa098edae all: unify spelling of "fall-through" comment for switch statements
We used "/* fall through */" and "/* fall-through */" inconsistently.
Rename to use only one variant.
2020-02-21 18:24:25 +01:00
Thomas Haller
95891e78e7 build/meson: fix missing dependency when building nm-libnm-aux
[351/932] Compiling C object libnm/fdede0a@@nm-libnm-aux@sta/.._shared_nm-libnm-aux_nm-libnm-aux.c.o.
    FAILED: libnm/fdede0a@@nm-libnm-aux@sta/.._shared_nm-libnm-aux_nm-libnm-aux.c.o
    gcc -Ilibnm/fdede0a@@nm-libnm-aux@sta -Ilibnm -I../libnm -Ilibnm-core -I../libnm-core -I. -I../ -Ishared -I../shared -I/usr/include/gio-unix-2.0 -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/uuid -fdiagnostics-color=always -pipe -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wextra -Werror -std=gnu11 -O2 -g -Wall -Wextra -Wdeclaration-after-statement -Wfloat-equal -Wformat-nonliteral -Wformat-security -Wimplicit-fallthrough -Wimplicit-function-declaration -Winit-self -Wlogical-op -Wmissing-declarations -Wmissing-include-dirs -Wmissing-prototypes -Wpointer-arith -Wshadow -Wshift-negative-value -Wstrict-prototypes -Wundef -Wvla -Wno-duplicate-decl-specifier -Wno-format-truncation -Wno-format-y2k -Wno-missing-field-initializers -Wno-pragmas -Wno-sign-compare -Wno-unknown-pragmas -Wno-unused-parameter -Wpointer-arith -Wshadow -Wstrict-prototypes -Wundef -fno-strict-aliasing -fPIC -pthread -DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_40 -DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_40 -DG_LOG_DOMAIN=libnmc -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_CLIENT -MD -MQ libnm/fdede0a@@nm-libnm-aux@sta/.._shared_nm-libnm-aux_nm-libnm-aux.c.o -MF libnm/fdede0a@@nm-libnm-aux@sta/.._shared_nm-libnm-aux_nm-libnm-aux.c.o.d -o libnm/fdede0a@@nm-libnm-aux@sta/.._shared_nm-libnm-aux_nm-libnm-aux.c.o -c ../shared/nm-libnm-aux/nm-libnm-aux.c
    In file included from ../libnm-core/nm-connection.h:14,
                     from ../libnm/nm-types.h:12,
                     from ../libnm/nm-object.h:14,
                     from ../libnm/nm-access-point.h:14,
                     from ../libnm/NetworkManager.h:11,
                     from ../shared/nm-default.h:288,
                     from ../shared/nm-libnm-aux/nm-libnm-aux.c:3:
    ../libnm-core/nm-core-types.h:13:10: fatal error: nm-core-enum-types.h: No such file or directory
       13 | #include "nm-core-enum-types.h"
          |          ^~~~~~~~~~~~~~~~~~~~~~
    compilation terminated.
2020-02-21 18:24:25 +01:00
Thomas Haller
ec8068ec0c gitlab-ci: add "t_fedora:32" and by default build on Fedora 31 2020-02-21 18:24:25 +01:00
Thomas Haller
3e616c306d tests: ignore valgrind warnings for unhandled syscalls in libnm,service-provider tests
Otherwise, we get test failures with valgrind on fedora:rawhide
(valgrind-3.15.0-18.fc33.x86_64.rpm, gcc-10.0.1-0.8.fc33.x86_64,
glib2-devel-2.63.5-3.fc33.x86_64):

    >>>> PRINT VALGRIND LOGS (valgrind test) (start)
    + find -name '*.valgrind-log' -print0
    + xargs -0 grep -H '^'
    ./src/devices/wwan/tests/test-service-providers.valgrind-log:--95634-- WARNING: unhandled amd64-linux syscall: 315
    ./src/devices/wwan/tests/test-service-providers.valgrind-log:--95634-- You may be able to write your own handler.
    ./src/devices/wwan/tests/test-service-providers.valgrind-log:--95634-- Read the file README_MISSING_SYSCALL_OR_IOCTL.
    ./src/devices/wwan/tests/test-service-providers.valgrind-log:--95634-- Nevertheless we consider this a bug.  Please report
    ./src/devices/wwan/tests/test-service-providers.valgrind-log:--95634-- it at http://valgrind.org/support/bug_reports.html.
    ./libnm/tests/test-remote-settings-client.valgrind-log:--95245-- WARNING: unhandled amd64-linux syscall: 315
    ./libnm/tests/test-remote-settings-client.valgrind-log:--95245-- You may be able to write your own handler.
    ./libnm/tests/test-remote-settings-client.valgrind-log:--95245-- Read the file README_MISSING_SYSCALL_OR_IOCTL.
    ./libnm/tests/test-remote-settings-client.valgrind-log:--95245-- Nevertheless we consider this a bug.  Please report
    ./libnm/tests/test-remote-settings-client.valgrind-log:--95245-- it at http://valgrind.org/support/bug_reports.html.
    ./libnm/tests/test-secret-agent.valgrind-log:--95280-- WARNING: unhandled amd64-linux syscall: 315
    ./libnm/tests/test-secret-agent.valgrind-log:--95280-- You may be able to write your own handler.
    ./libnm/tests/test-secret-agent.valgrind-log:--95280-- Read the file README_MISSING_SYSCALL_OR_IOCTL.
    ./libnm/tests/test-secret-agent.valgrind-log:--95280-- Nevertheless we consider this a bug.  Please report
    ./libnm/tests/test-secret-agent.valgrind-log:--95280-- it at http://valgrind.org/support/bug_reports.html.
    ./libnm/tests/test-nm-client.valgrind-log:--95208-- WARNING: unhandled amd64-linux syscall: 315
    ./libnm/tests/test-nm-client.valgrind-log:--95208-- You may be able to write your own handler.
    ./libnm/tests/test-nm-client.valgrind-log:--95208-- Read the file README_MISSING_SYSCALL_OR_IOCTL.
    ./libnm/tests/test-nm-client.valgrind-log:--95208-- Nevertheless we consider this a bug.  Please report
    ./libnm/tests/test-nm-client.valgrind-log:--95208-- it at http://valgrind.org/support/bug_reports.html.
    + echo '>>>> PRINT VALGRIND LOGS (valgrind test) (done)'
    >>>> PRINT VALGRIND LOGS (valgrind test) (done)
2020-02-21 18:24:25 +01:00
Thomas Haller
b4e48b5ce5 license: minor spelling fixes in RELICENSE.md 2020-02-21 17:52:28 +01:00