Commit graph

25087 commits

Author SHA1 Message Date
Thomas Haller
cfa2981271 core: merge branch 'th/nm-dhcp-config-merge'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/423
2020-02-21 16:01:20 +01:00
Thomas Haller
121d446354 device: merge nm_device_get_dhcp[46]_config() to nm_device_get_dhcp_config() 2020-02-21 15:59:44 +01:00
Thomas Haller
26f208aec3 core: add common base class NMDhcpConfig for NMDhcp[46]Config and merge them
The advantage is that the API is now the same for IPv4 and IPv6: it's
all nm_dhcp_config_*() and we can (easier) treat the address family
generically.

We still need two distinct GObject types, mainly because of the
glue code for exposing the object on D-Bus as NMDBusObject. Of course,
that could be solved differently, but as it is, it's quite nice.
2020-02-21 15:59:44 +01:00
Thomas Haller
cd03d39a6d core: rename "nm-dhcp4-config.[ch]" to "nm-dhcp-config.[hc]" before merge
NMDhcp4Config and NMDhcp6Config will get a common base type NMDhcpConfig
and be merged. In preparation, rename the file.
2020-02-21 15:59:44 +01:00
Thomas Haller
c8d043dd94 core: avoid duplicate lookup in nm_utils_strdict_to_variant()
Collect the full list of key and values, while sorting the key.
This way, we don't need to lookup the values by key later.
2020-02-21 15:59:44 +01:00
Thomas Haller
f13c7e3bbd shared: extend NM_GOBJECT_PROPERTIES_DEFINE*() macros to append suffix to defined names
This way, we will be able to use the macro multiple times in the same
source file by using different suffixes.
2020-02-21 15:59:44 +01:00
Thomas Haller
d07a85a2f9 platform: merge branch 'th/platform-link-type-metadata'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/421
2020-02-21 15:34:49 +01:00
Thomas Haller
6dcb4bd308 platform: use nm_streq() instead of strcmp() 2020-02-21 15:31:22 +01:00
Thomas Haller
acb397c995 platform: use binary search to lookup NMLinkType for devtype 2020-02-21 15:31:22 +01:00
Thomas Haller
19ad044359 platform: use binary search to lookup NMLinkType for rtnl_type 2020-02-21 15:31:22 +01:00
Thomas Haller
4f5e3765b0 platform: index LinkDesc array by NMLinkType
No need to iterate over the whole array, when we can just index
it by the link type that we look for.
2020-02-21 15:31:22 +01:00
Thomas Haller
6db35d95a5 platform: don't assign meaning to NMLinkType numeric values
It would be better if we would be able to use NMLinkType enum
as an index (e.g. into an array of LinkDesc structures). For that,
it is necessary that the enum is just consecutive numbers.

Don't assign special meaning to the enum. Also, this was only
used at two places, that we can solve differently.
2020-02-21 15:31:22 +01:00
Thomas Haller
4f9f228fed libnm: disable "-Wtautological-constant-out-of-range-compare" warning with clang
Seen on Debian 9, clang-3.8 (1:3.8.1-24):

    ../libnm-core/nm-setting-bond.c:596:49: error: comparison of constant 32 with expression of type 'NMBondMode' is always true [-Werror,-Wtautological-constant-out-of-range-compare]
            nm_assert (_NM_INT_NOT_NEGATIVE (mode) && mode < 32);
                                                      ~~~~ ^ ~~

This warning is not useful. While it may be implementation defined how enum
values outside the defined ones are handled, we commonly rely on placing
special numeric values in enums (e.g. ((NMEnumType) -1)).

An enum is (with our compilers) just a glorified integer, and there is nothing
preventing it from being outside the enum values. The warning is not helpful
and outright wrong. Disable it.

See-also: https://bugs.llvm.org//show_bug.cgi?id=16154

Fixes: 957bb2e111 ('libnm: use binary search for _nm_setting_bond_option_supported() implementation')
2020-02-21 10:43:55 +01:00
Thomas Haller
16df1c179d build/autotools: fix passing AM_CFLAGS when building libnm-core
With `./configure --enable-more-asserts`, we add extra -W flags to
AM_CFLAGS. This variable is only used, if the per-library override
libnm_core_libnm_core_la_CFLAGS is unspecified ([1]).

Usually we avoid this problem be never specifying library_CFLAGS, but
placing all our per-library flags to library_CPPFLAGS. While that is a
bit of a hack and misuse of CPPFLAGS, it works well (enough).

This was broken recently. The effect was, that libnm-core was not
build with AM_CFLAGS flags. Fix it.

[1] https://www.gnu.org/software/automake/manual/html_node/Flag-Variables-Ordering.html

Fixes: d2d6a68697 ('build: use -fcommon when building libnm-core')
2020-02-21 10:07:54 +01:00
Thomas Haller
1bc5a7c778 contrib/scripts: add "checkpatch-git-post-commit-hook" script to contrib/
This can be used as git post-commit hook.
2020-02-21 07:40:10 +01:00
Antonio Cardace
2b0689b9ae nm-setting-bond: do not shadow stack variable with same name
GCC complains about this when compiling with -Wshadow

Fixes: 8775c25c33 ('libnm: verify bond option in defined order')
2020-02-21 07:30:21 +01:00
Yuri Chornoivan
ce59e749fb po: update Ukrainian (uk) translation
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/420
2020-02-20 15:26:31 +01:00
Thomas Haller
1fbfbf743d bond: merge branch 'th/bond-allow-arp-validate'
https://bugzilla.redhat.com/show_bug.cgi?id=1789437

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/418
2020-02-19 17:28:33 +01:00
Thomas Haller
8775c25c33 libnm: verify bond option in defined order
verify() should validate options in a deterministic order, so that
the same profile (with same libnm version) gives the same failure
reason every time.

Hence, visit the options in sorted order, like we do for nm_setting_bond_get_option().
2020-02-19 17:15:26 +01:00
Thomas Haller
ae1008b239 libnm: sort "mode" in nm_setting_bond_get_option() first
Internally, the options are tracked in a hash table and of undefined
sort order. However, nm_setting_bond_get_option() always returns a stable
(sorted) order.

Move "mode" as first, because that is usually the most interesting option.

The effect is:

  $ nmcli -o connection show "$BOND_PROFILE"
  ...
  -bond.options:  arp_interval=5,arp_ip_target=192.168.7.7,arp_validate=active,mode=balance-rr,use_carrier=0
  +bond.options:  mode=balance-rr,arp_interval=5,arp_ip_target=192.168.7.7,arp_validate=active,use_carrier=0

This doesn't affect keyfile, which sorts the hash keys themself (and
doesn't treat the "mode" special).

This however does affect ifcfg-rh writer how it writes the BONDING_OPTS
variable. I think this change is fine and preferable.
2020-02-19 17:15:26 +01:00
Thomas Haller
5ccab333d0 libnm: cleanup string comparison in "nm-setting-bond.c"
strcmp() is hard to understand visually. Especially when different patterns
are mixed, like:

    if (   !strcmp (name, NM_SETTING_BOND_OPTION_MIIMON)
        && strcmp (value, "0") != 0) {
2020-02-19 17:15:26 +01:00
Thomas Haller
18c8f43c34 libnm: use binary search for finding bond options to validate 2020-02-19 17:15:26 +01:00
Thomas Haller
957bb2e111 libnm: use binary search for _nm_setting_bond_option_supported() implementation 2020-02-19 16:24:55 +01:00
Thomas Haller
cba938f3ee shared: add nm_utils_named_values_from_str_dict_full() to allow different sort order (or none) 2020-02-19 16:24:55 +01:00
Thomas Haller
f4d12f7b59 shared: add NM_UTILS_STRING_TABLE_LOOKUP_STRUCT_DEFINE() macro for lookup of structs 2020-02-19 15:35:07 +01:00
Thomas Haller
14461e7217 shared: add NM_MORE_ASSERT_ONCE() macro 2020-02-19 15:35:07 +01:00
Thomas Haller
d9d51dd42d device: allow setting "arp_validate" with supported bond modes
arp_validate is allowed for several bonding modes, at least since commit [1].

The validation was too strict. Just use set_bond_attr() directly, that
already correctly encodes whether to set the value or not.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=13ac34a8866e31b31db6237c73aa558aff84d765
2020-02-19 10:39:55 +01:00
Beniamino Galvani
efc04b1285 Revert "core: create virtual device on settings changes in idle handler"
When AddConnection() or Update() terminate, the (unrealized) virtual
device should be already be available, otherwise an activation attempt
of that connection can fail.

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

This reverts commit c163207b07.
2020-02-19 10:03:58 +01:00
Thomas Haller
eb74d5f65f shared/trivial: add code comment to nm_utils_ifname_valid_kernel() 2020-02-18 13:23:50 +01:00
Thomas Haller
82fb8b00b4 shared: check for valid UTF-8 in nm_utils_ifname_valid()
The interface name might come from the command line or from a filename
(like during nm_vpn_wireguard_import()). It's not clear that this
is valid UTF-8. Asserting against that requires the caller to ensure
that the encoding is valid. That is cumbersome, especially since we anyway
check. Just report a regular error.
2020-02-18 13:23:50 +01:00
Antonio Cardace
ed5a647ad1 nm-shared-utils: relax ovs ifname check to accept any (non-space) ASCII printable char
quoting 'man ovs-vswitchd.conf.db':
"The name must be alphanumeric and must not contain forward or backward
slashes."

OVS actually accepts a wider range of chars (all printable UTF-8 chars),
NetworkManager restricts this to ASCII char as it's a safer option for
now since OVS is not well documented on this matter.

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

Fixes: e7d72a14f6 ('libnm-core: use different ifname validation function for OVS bridges, ports and interfaces')
2020-02-18 13:11:21 +01:00
Beniamino Galvani
82697358e3 device: fix handling of DHCP grace period
'grace_pending' was never initialized.

Fixes: 0c52c18b56 ('device: unify handling of grace-period for DHCPv4 and DHCPv6 (2)')
2020-02-18 09:59:32 +01:00
Beniamino Galvani
e24fd88494 ovs: merge branch 'bg/ovs-deactivate-async-pt2'
https://bugzilla.redhat.com/show_bug.cgi?id=1787989
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/412
2020-02-17 19:03:42 +01:00
Beniamino Galvani
e9fc1dea43 ovs: discard link updates when deactivating
When the ovs interface gets deactivated, it is released from the
master port and we call nm_device_update_from_platform_link (dev,
NULL) to ignore any later event for the interface. This is important
especially because it sets a zero ifindex on the interface and so,
later when the link disappears, we don't unmanage the device but
directly remove it.

However, since ovs commands are queued, the link could appear during
the deactivation and we need to ignore such events. Add a new device
method can_update_from_platform_link() for such purpose.
2020-02-17 19:03:29 +01:00
Beniamino Galvani
9c49f8a879 ovs: rework asynchronous deactivation of ovs interfaces
Tracking the deletion of link by ifindex is difficult because the
ifindex of the device is updated through delayed (idle) calls in
NMDevice and so there is the possibility that at a certain time the
device ifindex is not in sync with platform state. It seems simpler to
watch instead the interface name. The ugly thing is that the interface
name can be changed externally, but if users do that on an activating
device they are looking for trouble.

Also change the deactivate code to deal with the scenario where we
already created the interface in the ovsdb but the link didn't show up
yet. To ensure a proper cleanup we must wait that the link appears and
then goes away; however the link may never appear if vswitchd sees
only the last state in ovsdb, and so we must use a ugly timeout to
avoid waiting forever.

https://bugzilla.redhat.com/show_bug.cgi?id=1787989
2020-02-17 19:03:29 +01:00
Beniamino Galvani
3286918bd9 n-dhcp4: request previous address after expiration
If the lease expires and the client start again sending a discover,
request the previous address.
2020-02-17 18:58:47 +01:00
Thomas Haller
037507f790 shared: fix returning out_len from nm_utils_hash_values_to_array()
The only affected caller is nm_modem_manager_get_modems(), which
is used by NMDeviceBt for DUN connections. This is rather bad.

Fixes: 4154d9618c ('bluetooth: refactor BlueZ handling and let NMBluezManager cache ObjectManager data')
Fixes: e688e70b37 ('shared: add nm_utils_hash_values_to_array() helper')
2020-02-17 17:54:10 +01:00
Antonio Cardace
63eabe0dbf Merge branch 'ac/ovs_ifname_length' into 'master'
[ac/ovs ifname length]

See merge request NetworkManager/NetworkManager!408
2020-02-17 15:05:26 +00:00
Antonio Cardace
e7d72a14f6 libnm-core: use different ifname validation function for OVS bridges, ports and interfaces
OVS bridges and ports do not have the length limitation of 15 bytes, the
only requirements are that all chars must be alphanumeric and not be
forward or backward slashes.

For OVS interfaces only 'patch' types do not have the length limit, all
the other types do (according to whether they have a corresponding
kernel link or not).

Add related unit test.

https://bugzilla.redhat.com/show_bug.cgi?id=1788432
2020-02-17 15:27:35 +01:00
Antonio Cardace
15e87b80f3 nm-setting-ovs-interface: remove unneeded check on 'self'
'self' is guaranteed of being not-NULL since we have the
assertion 'g_return_val_if_fail (NM_IS_SETTING_OVS_INTERFACE (self),FALSE);'
at the beginning of the function.
2020-02-17 15:27:35 +01:00
Antonio Cardace
72f7ad75dc libnm-core: add assertion for valid 'error' argument in nm_utils_is_valid_iface_name() 2020-02-17 15:27:35 +01:00
Antonio Cardace
6e9a36ab9f all: use nm_utils_ifname_valid_kernel() instead of nm_utils_is_valid_iface_name()
nm_utils_is_valid_iface_name() is a public API of libnm-core, let's use
our internal API.

$ sed -i 's/\<nm_utils_is_valid_iface_name\>/nm_utils_ifname_valid_kernel/g' $(git grep -l nm_utils_is_valid_iface_name)
2020-02-17 15:27:35 +01:00
Antonio Cardace
550f538564 nm-shared-utils: add nm_utils_ifname_valid*() to shared utils
Move the body of nm_utils_is_valid_iface_name() to
nm_utils_ifname_valid_kernel() so that it's shared between NM and
clients.
2020-02-17 15:27:35 +01:00
Antonio Cardace
15a8595575 nmcli: remove interface length check in nmcli
nmcli should not perform checks on the interface name length,
this kind of operations should only be performed by the NetworkManager
daemon and not be duplicated inside cli applications.
2020-02-17 15:27:35 +01:00
Antonio Cardace
0cac094c93 nm-device-factory: remove ifname check as it prevents activating OVS connections 2020-02-17 15:27:35 +01:00
Antonio Cardace
9e27252c27 nm-dhcp-client: use nm_assert() to check ifname
so that it gets compiled out in production builds, this check is
carried out anyway when the connection is created.
2020-02-17 15:27:35 +01:00
Thomas Haller
439ac7f7c2 license: add Michael to RELICENSE.md
https://mail.gnome.org/archives/networkmanager-list/2020-February/msg00012.html
2020-02-17 15:23:56 +01:00
Thomas Haller
04bb97d4c1 libnm: move nm_setting_ip6_config_get_ra_timeout() to "libnm_1_22_8" symbol version
nm_setting_ip6_config_get_ra_timeout() was backported to nm-1-22 branch, and
will be released as 1.22.8. As such, on the stable branch the symbol will be
placed in a separate symbol version ("libnm_1_22_8").

To support the upgrade path from 1.22.8+ to 1.23+, we want this symbol
also present on master.

At that point, we don't need to duplicate the symbol. Just add the same linker
symbol version also to master.
2020-02-17 15:18:58 +01:00
Thomas Haller
3719c0fe84 all: merge branch 'th/ra-timeout-2'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/414
2020-02-17 14:45:39 +01:00
Thomas Haller
cab8b857ca device: more unify handling of DHCP data for IPv4/IPv6 (client, config, state_sigid, was_active)
At this point, just move the fields in their respective address-family
specific structure. We don't use it generically yet, but instead always
explicitly select IPv4 or IPv6. But this would allow to access those
fields by address-family in the future.
2020-02-17 14:45:09 +01:00