Commit graph

12687 commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
d50856b5c6 manager: drop devices_inited field in NManagerPrivate for devices_inited_id
It is redundant. Drop it.

Also, we don't need to cancel and reschedule the idle source in
nm_manager_start(). First of all, it really shouldn't be pending.
Second, contrary to a timer, when an idle source is already pending,
then the pending one will run at the right time.
2020-02-14 11:56:44 +01:00
Thomas Haller
de62da297e all: drop explicit casts from _GET_PRIVATE() macro calls
The _GET_PRIVATE() macros are all implemented based on
_NM_GET_PRIVATE(). That macro tries to be more type safe and uses
_Generic() to do the right thing. Explicitly casting is not only
unnecessary, it defeats these (static) type checks.

Don't do that.
2020-02-14 11:04:46 +01:00
Thomas Haller
d165787b54 device/trivial: add FIXME comment about simplifying deactivate_async() 2020-02-14 10:10:26 +01:00
Thomas Haller
f0bc4aa525 device: move supplicant_timeout_id into supplicant struct in NMDeviceEthernetPrivate
The supplicant struct is there to group related variables.

Move supplicant_timeout_id there.
2020-02-14 09:48:37 +01:00
Thomas Haller
c23c2e2f94 device: reorder fields in NMDeviceEthernetPrivate struct 2020-02-14 09:48:37 +01:00
Thomas Haller
098c0d5092 device: inline "struct Supplicant" to where it is used 2020-02-14 09:48:37 +01:00
Thomas Haller
984e94f01d supplicant: expose nm_supplicant_driver_to_string() helper function
Will be useful later.
2020-02-14 09:48:37 +01:00
Thomas Haller
cd31437024 shared: drop _STATIC variant of macros that define functions
Several macros are used to define function. They had a "_STATIC" variant,
to define the function as static.

I think those macros should not try to abstract entirely what they do.
They should not accept the function scope as argument (or have two
variants per scope). This also because it might make sense to add
additional __attribute__(()) to the function. That only works, if
the macro does not pretend to *not* define a plain function.

Instead, embrace what the function does and let the users place the
function scope as they see fit.

This also follows what is already done with

    static NM_CACHED_QUARK_FCN ("autoconnect-root", autoconnect_root_quark)
2020-02-13 17:17:07 +01:00
Thomas Haller
487141d4a8 shared: add entry_cmd argument to NM_UTILS_STRING_TABLE_LOOKUP_DEFINE*() macro
This extra argument allows to tweak whether to assert for the input argument name.
2020-02-13 10:46:34 +01:00
Antonio Cardace
904050dd2d nm-logging: fix stack-use-after-scope error detected by asan
asan error:

==6291==ERROR: AddressSanitizer: stack-use-after-scope on address 0x7ffe6af12880 at pc 0x7fc8dd3321cd bp 0x7ffe6af11be0 sp 0x7ffe6af11388
READ of size 15 at 0x7ffe6af12880 thread T0
    #0 0x7fc8dd3321cc  (/lib64/libasan.so.5+0x4e1cc)
    #1 0x7fc8dcebcf29 in sd_journal_sendv ../src/journal/journal-send.c:226
    #2 0x74d834 in _nm_log_impl ../src/nm-logging.c:778
    #3 0x42485c in main ../src/main.c:379
    #4 0x7fc8dca1b1a2 in __libc_start_main (/lib64/libc.so.6+0x271a2)
    #5 0x427e3d in _start (/work/NetworkManager/build/src/NetworkManager+0x427e3d)

Address 0x7ffe6af12880 is located in stack of thread T0 at offset 736 in frame
    #0 0x74c26f in _nm_log_impl ../src/nm-logging.c:663

  This frame has 9 object(s):
    [48, 56) 's_log_domains' (line 744)
    [80, 88) 'l_log_domains' (line 745)
    [112, 128) 'tv' (line 666)
    [144, 168) 'args' (line 664)
    [208, 240) 'g_copy' (line 670)
    [272, 312) 'cur_log_state_copy' (line 669)
    [352, 392) 'iov_free_data' (line 730)
    [432, 672) 'iov_data' (line 728)
    [736, 1024) 's_log_domains_buf' (line 743) <== Memory access at offset 736 is inside this variable
2020-02-12 16:21:47 +01:00
Thomas Haller
8e636186c0 core: for WireGuard devices use a default dns-priority of 50 (like for VPNs) 2020-02-12 11:55:30 +01:00
Thomas Haller
7d87d2b8da device: add nm_device_is_vpn() function 2020-02-12 11:55:30 +01:00
Thomas Haller
c69d703017 all: use g_ascii_strcasecmp() instead of the locale dependent strcasecmp()
In all the cases, we don't want to perform locale dependent comparison.

  $ sed -i 's/\<strcasecmp\>/g_ascii_\0/g' $(git grep -w -l strcasecmp -- ':(exclude)shared/systemd/' )
2020-02-11 15:23:06 +01:00