Commit graph

25068 commits

Author SHA1 Message Date
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
Thomas Haller
0c52c18b56 device: unify handling of grace-period for DHCPv4 and DHCPv6 (2) 2020-02-17 14:45:09 +01:00
Thomas Haller
49b4fce2d3 device: unify handling of grace-period for DHCPv4 and DHCPv6 (1)
Often, the code paths for IPv4 and IPv6 are very similar. We should try
to unify those code paths. The main advantage of doing that, is that
we don't unintentionally end up doing different things. And of course,
it removes duplicate code.

In a first step, unify handling of the grace timeout for DHCPv4 and
DHCPv6.
2020-02-17 14:45:09 +01:00
Thomas Haller
eae862e385 shared: add LOGD_DHCP_from_addr_family() helper 2020-02-17 14:45:09 +01:00
Thomas Haller
4c993f6bbb all: merge branch 'th/ra-timeout'
https://bugzilla.redhat.com/show_bug.cgi?id=1801158

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/414
2020-02-17 14:44:17 +01:00
Thomas Haller
9dde86d02c ndisc: implement "ipv6.ra-timeout" property 2020-02-17 14:43:13 +01:00
Thomas Haller
10f0253f2e ndisc: rename NM_NDISC_RA_TIMEOUT signal to NM_NDISC_RA_TIMEOUT_SIGNAL
We will add a property NM_NDISC_RA_TIMEOUT for which this name is better
suited. The problem is really that our convention for object properties
and signals defines have no prefix to indicate whether it's a property
or a signal.

Rename.
2020-02-17 14:43:13 +01:00
Thomas Haller
b2e30b3c9a ndisc: improve logging message with nm_ndisc_start() and minor cleanup 2020-02-17 14:43:13 +01:00
Thomas Haller
de4aeb34e3 libnm,cli,ifcfg-rh: add ipv6.ra-timeout configuration option 2020-02-17 14:43:13 +01:00
Thomas Haller
0d8f55a1cb cli: add support for "ipv6.dhcp-timeout" property
It was internally supported, but not by nmcli.
2020-02-17 14:43:13 +01:00
Thomas Haller
843c546b84 ifcfg-rh: belatedly add support for "ipv6.dhcp-timeout" setting 2020-02-17 14:43:13 +01:00
Thomas Haller
9b82d29f5f ifcfg-rh: fix potential crash with variadic argument make_ip6_setting()
It is undefined behavior and can lead to crashes or memory corruption.
In practice, this only had an issue on Big Endian systems.

Fixes: fdbf4ae5e6 ('ifcfg-rh: add IPV4_DHCP_TIMEOUT key for ipv4.dhcp-timeout property')
2020-02-17 14:43:13 +01:00
Thomas Haller
d06092acbd ifcfg-rh: inline unnecessary function write_ip6_setting_dhcp_hostname()
If a function is only called once, it may not help to simplify the code
but make it more complicated. It would only simplify the code, if it
had a clear, distinct purpose. That isn't the case here. Also, the
IPv4 writer doesn't have such a function either. Drop and inline it.
2020-02-17 14:43:13 +01:00
Thomas Haller
4c101f36ec device: don't schedule grace timeout if dhcp-timeout is infinity
It feels wrong to schedule a timeout with G_MAXUINT32, if we actually
disabled the timeout. Of course, in practice there should be little
difference.
2020-02-17 14:43:13 +01:00
Thomas Haller
be4129bb2d device/trivial: rename get_dhcp_timeout() virtual function to have a unique name
This is C, we have almost no IDE support. And ctags/cscope is much more
helpful if we use unique names.

Don't use the get_dhcp_timeout() name, because that is already used in
"src/devices/nm-device.c" already. Rename.
2020-02-17 14:43:12 +01:00
Thomas Haller
e34db042af libnm/doc: explain values for dhcp-timeout setting 2020-02-17 14:43:12 +01:00
Beniamino Galvani
e127a82370 Revert "manager: drop devices_inited field in NManagerPrivate for devices_inited_id"
After this change the startup-complete event is reached too early,
even before priv->devices_inited_id is initialized.

This reverts commit d50856b5c6.
2020-02-17 13:30:35 +01:00
Thomas Haller
b2d3ba33a7 license: merge branch 'th/fix-lgpl-license-violations' (part 1)
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/390
2020-02-16 15:59:46 +01:00
Thomas Haller
6963ecf0d1 license: relicense "libnm-core/nm-errors.h" under LGPL-2.1+
$ git shortlog -n -s a3e75f3294 -- libnm-core/nm-errors.h
      11    Dan Winship
       5    Thomas Haller
       2    Beniamino Galvani

Note that the header also contains code that was copied from other
files. However, that code originates from libnm itself (and thus was
already LGPL licensed).

All contributors agreed to the relicensing according to "RELICENSE.md".
2020-02-16 15:55:55 +01:00
Thomas Haller
2dde55203b license: relicense "shared/systemd/sd-adapt-shared/nm-sd-adapt-shared.h" under LGPL-2.1+
$ git shortlog -n -s a3e75f3294 -- shared/systemd/sd-adapt-shared/nm-sd-adapt-shared.h src/systemd/sd-adapt-core/nm-sd-adapt-core.c src/systemd/sd-adapt/nm-sd-adapt.'[hc]' src/systemd/nm-sd-adapt.'[hc]' src/dhcp-manager/systemd-dhcp/nm-sd-adapt.'[hc]'
      46    Thomas Haller
       7    Beniamino Galvani
       3    Lubomir Rintel
       2    Dan Williams
       2    Dan Winship
       1    Glenn Washburn
       1    Jiří Klimeš

Note that the contribution to the file by Glenn was removed in
commit e27b15c00d ('all: remove CLOCK_BOOTTIME defintions'), so
it is no longer relevant.

All other contributors agreed to the relicensing according to "RELICENSE.md".
2020-02-16 15:45:08 +01:00