Commit graph

13405 commits

Author SHA1 Message Date
Beniamino Galvani
f70ee67058 dns: sd-resolved: reset interface configuration on deactivation
If an update doesn't contain an interface but the previous update did,
the systemd-resolved DNS plugin must send a request to clear the
previous configuration. Otherwise the previous DNS configuration would
persist even after interface deactivation.

https://bugzilla.redhat.com/show_bug.cgi?id=1888229
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/662
2020-10-29 17:23:28 +01:00
Thomas Haller
ed82bbe986
core: use nm_clear_pointer() instead of g_clear_pointer()
Our macro is more type-safe than glib's, because it does
not C cast the arguments. It seems preferable in general.
2020-10-28 13:59:22 +01:00
Thomas Haller
33041e04af
core: use nm_utils_share_rules_add_all_rules() from NMDevice 2020-10-27 17:40:20 +01:00
Thomas Haller
be7bf38a3a
core: add nm_utils_share_rules_add_all_rules() for constructing iptables rules 2020-10-27 17:40:19 +01:00
Thomas Haller
701654b930
core: refactor tracking of shared-rules to use NMUtilsShareRules
It's a bit ugly that NMActRequest also tracks the shared rules.
Why? It's just some additional state (the rules) and some additional
actions that should be done when activating/deactivating the profile.
NMActRequest also doesn't track the NMDhcpClient, so why these shared
rules?

Also, removing the rules from an object destructor is ugly. NMActRequest
is a GObject and ref-counted. We should not make assumptions when the
last reference gets releases, at least not in cases like this, where
we hand out the reference and the object is passed around through large
parts of the source code.

For now, still let NMActRequest keep track of NMUtilsShareRules.
Later this will be refactored too.
2020-10-27 17:40:19 +01:00
Thomas Haller
0c2d5fc972
core: add NMUtilsShareRules API for handling IP tables rules
Currently, shared rules are tracked by NMActRequest. Add a small
type for tracking the shared rules.
2020-10-27 17:07:57 +01:00
Thomas Haller
0438820805
device: use static array for modules in share_init()
A static const array is marked as immutable by the linker.
This is what we want, because there is no need to change this
array.

Also, the tailing %NULL entry is not necessary, we can just
iterate over the fixed number of elements.
2020-10-27 17:04:21 +01:00
Thomas Haller
379dde287c
l3cfg: let NML3Cfg return a singleton NML3IPv4LL instance
NML3Cfg is the manager instance for one interface (ifindex). For one
interface, it is not supported (nor useful) to run IPv4LL multiple
times. Hence, let NML3Cfg manage and return a single instance.
2020-10-27 17:04:20 +01:00
Thomas Haller
291b3a52b7
l3cfg: add NM_ACD_TIMEOUT_RFC5227_MSEC define 2020-10-27 17:04:20 +01:00
Thomas Haller
6dd557c324
l3cfg: add nm_l3_ipv4ll_is_timed_out() for letting IPv4LL reach a failed state
We may want to handle cases where we cannot assign a IPv4LL address
even after multiple attempts.

Add a new property nm_l3_ipv4ll_is_timed_out() to get into a failed
state. The user may choose to fail the activation or ignore it.

Also, remove some unused code and fix minor issues in NML3IPv4LL.
2020-10-27 17:04:20 +01:00
Thomas Haller
931573dfda
shared: rename nm_add_u32_clamped() to nm_add_clamped_u32() 2020-10-27 17:04:19 +01:00
Thomas Haller
39026b64eb
device/wifi: remove unused function nm_wifi_ap_set_ssid_arr() 2020-10-27 14:10:38 +01:00
Thomas Haller
eb36380335
device/wifi: don't reset the SSID of a NMWifiAP to unknown
For hidden networks, we usually don't have an SSID. We try to match
and fill the SSID based on the profiles that we have:

  <debug> [1603798852.9918] device[6b383dca267b6878] (wlp2s0): matched hidden AP AA:BB:CC:DD:EE:FF => "SSID"

However, we should not clear that value again on the next update:

  <trace> [1603798856.5724] sup-iface[66c1a0883a262394,0,wlp2s0]: BSS /fi/w1/wpa_supplicant1/Interfaces/0/BSSs/3 updated
  <debug> [1603798856.5726] device[6b383dca267b6878] (wlp2s0): wifi-ap: updated AA:BB:CC:DD:EE:FF (none)

Once we have a SSID, we can only update it to a better value,
but not clear it.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/438

Fixes: b83f07916a ('supplicant: large rework of wpa_supplicant handling')
2020-10-27 14:10:35 +01:00
Antonio Cardace
983798d945
l3cfg: fix typo in test
Signed-off-by: Antonio Cardace <acardace@redhat.com>
2020-10-23 18:30:33 +02:00
Thomas Haller
17269b0520
l3cfg: add support for IPv4 link local addresses (ipv4ll) to NML3Cfg
NML3Cfg already handles IPv4 ACD. IPv4LL is just a small additional
layer on top of that, so it makes sense that it also is handled by
NML3Cfg.

Also, the overall goal is that multiple NMDevice and NMVpnConnection
instances can cooperate independently. So if multiple "users" enable
IPv4LL on an interface, then we should only run it once. This is
achieved by NML3IPv4LL's API where users register what they want,
and NML3IPv4LL figures out what that means as a whole.

Also, we thus will no longer need to use sd_ipv4ll/n-ipv4ll, because
we implement it ourself.
2020-10-23 17:11:57 +02:00
Thomas Haller
3caf419df6
l3cfg: combine NML3AcdAddrTrackInfo and AcdTrackData
On the one hand, we want to keep the private fields internal. On the
other hand, we want to directly expose the NML3AcdAddrTrackInfo, so
that the user can access them without copying or calling a function.

Previously, there was some union ugliness and some padding involved.
That was probably correct, but lets solve this somewhat nicer by
having the private fields in a "_priv" struct and use NML3AcdAddrTrackInfo
throughout.
2020-10-23 17:11:56 +02:00
Thomas Haller
3874e061d4
platform/tests: add NMTstpAcdDefender helper for testing 2020-10-23 17:11:55 +02:00
Thomas Haller
60da4cb494
platform: interpret metric_any for routes to accept offset for default metric
The DHCP client likes to order multiple default routes by adding
them with different, increasing metric.

To support that, let "metric_any" not completely disable the "metric"
field, but instead interpret it as an offset that should be added to
the default metric.
2020-10-23 17:11:55 +02:00
Thomas Haller
f6a8aca1b4
l3cfg/tests: cleanup l3cfg tests and set a fixed MAC address on the test interfaces
It's better to have a well-known, fixed MAC address on our test veth
devices.

Also, because later we will test IPv4 link local addressing, which
generates addresses by hashing the MAC address (among others).
2020-10-23 17:11:55 +02:00
Thomas Haller
15f5d10352
l3cfg: add nm_netns_get_l3cfg() accessor
This is more for debugging and testing. Usually you want to call
nm_netns_access_l3cfg() which creates a NML3Cfg instance, if necessary.
2020-10-23 17:11:54 +02:00
Thomas Haller
b38fbb3bf6
l3cfg: add nm_l3_acd_addr_info_find_track_info() helper 2020-10-23 17:11:54 +02:00
Thomas Haller
4561b3c114
l3cfg: various bugfixes in NML3Cfg
- fix iterating logic in nm_l3cfg_add_config()

- fix preserving order during nm_l3cfg_commit_type_register()

- fix logic in _l3cfg_externally_removed_objs_drop_unused() to handle
  all object types and not only routes.

- in nm-l3-config-data.c, fix coercing the route metric from metric_any
  to the default metric.

- in _l3cfg_externally_removed_objs_drop_unused() and
  _l3cfg_externally_removed_objs_track() ensure that the object is kept
  alive long enough. The externally_removed_objs_hash hash keeps a
  reference to the object, so when removing it, we either must no longer
  access the object, or delay the destruction until later.
2020-10-23 17:11:54 +02:00
Thomas Haller
ad18612c36
core: remove error checking for nm_auth_chain_new_subject() which cannot fail
nm_auth_chain_new_subject() cannot return %NULL, so these checks are only
noise. Also, there are already calls that correctly rely on the fact that
this function cannot fail.

We use glib, where memory allocation by definition cannot fail. That means,
a lot of functions simply cannot fail in our code base. This is a very nice
property (to have an functions that cannot fail), so don't add error
checking that is not useful.
2020-10-23 12:23:08 +02:00
Antonio Cardace
b6a18e0593
manager: fix very bad usage of 'nm_utils_user_data_unpack'
This results in the args of 'nm_utils_user_data_unpack'
containing random data potentially also from the
previous stack-frame which is really really bad.

Signed-off-by: Antonio Cardace <acardace@redhat.com>
Fixes: b50702775f ('device: implement auth-request as async operation nm_manager_device_auth_request()')
2020-10-22 17:38:08 +02:00
Thomas Haller
515df289de
all/trivial: fix formatting 2020-10-22 17:22:09 +02:00
Andrew Zaborowski
ada71a4af6 iwd: Remove a redundant set_current_ap call
set_current_ap is always called before remove_all_aps.
2020-10-22 16:58:27 +02:00
Andrew Zaborowski
d868ce153e iwd: Use platform-utils to update signal/rate/bssid/frequency
Use a periodic_update callback similar to the wpa_supplicant backend.
While there also update one unrelated comment.
2020-10-22 16:58:27 +02:00
Andrew Zaborowski
e0394689b3 platform/wifi: Cache GET_STATION dump data between calls
The wifi backends call nm_platform_wifi_get_quality and
nm_platform_wifi_get_rate one after another in periodic_update (every
6s) and the same information is queried twice, synchronously.  For the
lack of a better mechanism to decide whether we're still inside the same
periodic_update call, store the timestamp in msecs and reuse the data
for 500ms.
2020-10-22 16:58:27 +02:00
Andrew Zaborowski
277e8eaa1f platform/wifi: Use GET_STATION instead of GET_SCAN dumps
As an optimization, use the NL80211_CMD_GET_STATION dump data instead
of the NL80211_CMD_GET_SCAN dump + GET_STATION command (non-dump) to
implement the following methods:
wifi_nl80211_get_bssid
wifi_nl80211_get_rate
wifi_nl80211_get_qual

GET_STATION records vary in size from a few hundred bytes to a few kB.
GET_SCAN records are usually on the few hundred bytes side, but there
can be many of them.  In managed mode there will only be one
GET_STATION record.  In AdHoc mode there may be more.  These methods are
not used in AP or Mesh mode.

So without that patch we'd have a GET_SCAN dump that could be quite big
and then a GET_STATION with one record.  Now it should be a GET_STATION
dump with one record or a few records, in any case fewer synchronous
commands is better.  Additionally this should now not depend on the
currently-connected BSS being in the kernel's scan result cache.

The downside is that the signal strength is "optional" in the
GET_STATION records, depends on the driver's capabilities.  Most
mainline drivers do seem to include it (the mac80211 based ones and a
few full-mac ones) but I can't know if all of them do.
2020-10-22 16:58:27 +02:00
Andrew Zaborowski
c6456dd104 platform/wifi: Read frequency from NL80211_CMD_GET_INTERFACE
As an optimization, implement wifi_nl80211_get_freq() using the
GET_INTERFACE nl8022 command instead of the GET_SCAN dump.
The GET_SCAN dump can be over 10kB of data that the kernel has to build
and we have to parse.  Additionally the GET_SCAN dump is not guaranteed
to contain the currently-connected BSS if there was no recent scan (30s),
or if the recent scan missed the beacon from the current BSS, or if the
recent scan was for a subset of channels/SSIDs/BSSIDs etc. and the last
full scan was already flushed.  Scan results are flushed after (I think)
30 seconds or if a new scan has the flush flag set.

In IWD we do occasionally do partial scans (on a subset of channels or
for a specific SSID) with the flush flag.  In that case the previous
wifi_nl80211_get_freq() logic would probably return 0.
2020-10-22 16:58:27 +02:00
Thomas Haller
cc030b9112
all/trivial: rename local variable for user_data for nm_utils_user_data_unpack()
In almost all cases, the variable of this kind is named "user_data".
Rename it for consistency.
2020-10-22 15:14:44 +02:00
barinet
676fe327d4
libnm,core: allow VXLAN connections without an explicit remote VTEP
[thaller@redhat.com: squashed commits, resolve merge conflict and coding
 style]

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/645
2020-10-20 13:45:19 +02:00
Thomas Haller
290e515311
libnm/bond: remove validation from nm_setting_bond_add_option() and explicitly validate
For historic reasons is NMSettingBond implemented differently from other
settings. It uses a strdict, and adds some validation on top of that.
The idea was probably to be able to treat bond options more generically.
But in practice we cannot treat them as opaque values, but need to know,
validate and understand all the options. Thus, this implementation with a
strdict is not nice.

The user can set the GObject property NM_SETTING_BOND_OPTIONS to any
strdict, and the setter performs no validation or normalization. That
is probably good, because g_object_set() cannot return an error to
signalize invalid settings. As often, we have corresponding C API like
nm_setting_bond_add_option() and nm_setting_bond_remove_option(). It
should be possible to get the same result both with the C API and with
the GObject property setting. Since there is already a way to set
certain invalid values, it does not help if the C API tries to prevent
that. That implies, that also add-option does not perform additional
validation and sets whatever the user asks.

Remove all validation from nm_setting_bond_add_option() and
nm_setting_bond_remove_option(). This validation was anyway only very
basic. It was calling nm_setting_bond_validate_option(), which can check
whether the string is (for example) and integer, but it cannot do
validation beyond one option. In most cases, the validation needs to
take into account the bond mode or other options, so validating one
option in isolation is not very useful.

Proper validation should instead be done via nm_connection_verify().
However, due to another historic oddity, that verification is very
forgiving too and doesn't reject many invalid settings when it should.
That is hard to fix, because making validation more strict can break
existing (and working) configurations. However, verify() already contains
basic validation via nm_setting_bond_validate_option(). So in the previous
behavior nm_setting_bond_add_option() would silently do nothing (only
returning %FALSE) for invalid options, while now it would add the
invalid options to the dictionary -- only to have it later fail validation
during nm_connection_verify(). That is a slight change in behavior, however it
seems preferable.

It seems preferable and acceptable because most users that call
nm_setting_bond_add_option() already understand the meaning and valid
values. Keyfile and ifcfg-rh readers are the few exceptions, which really just
parse a string dictionary, without need to understand them. But nmtui
or nmstate already know the option they want to set. They don't expect
a failure there, nor do they need the validation.

Note that this change in behavior could be dangerous for example for the
keyfile/ifcfg-rh readers, which silently ignored errors before. We
don't want them to start failing if they read invalid options from a
file, so instead let those callers explicitly pre-validate the value
and log an warning.

https://bugzilla.redhat.com/show_bug.cgi?id=1887523
2020-10-19 23:18:43 +02:00
Beniamino Galvani
317171ed6e initrd: generate infiniband connections
Generate infiniband connections based on the interface name or MAC
address length.

https://bugzilla.redhat.com/show_bug.cgi?id=1883173
2020-10-19 19:03:00 +02:00
Andrew Zaborowski
c92ad05cee
iwd: Avoid ConnectHiddenNetwork() if network is visible
If the target hidden network is already recorded by IWD with its SSID
during a previous active scan, use the Network.Connect() API instead of
Station.ConnectHiddenNetwork() which would fail in IWD version up to
1.9.  This is a rare corner case scenario though.

Also drop the !nm_wifi_ap_get_supplicant_path(ap) check, I'm not
sure when if ever that condition can be true, more so now that we're
checking nm_wifi_ap_get_fake(ap) before that.
2020-10-19 18:49:30 +02:00
Andrew Zaborowski
a6ece1557c
iwd: Track InterfacesAdded/Removed signals for Networks
Until now we didn't rely on InterfacesAdded and InterfacesRemoved
signals for tracking when IWD finds new Wi-Fi networks or expires
networks not seen in the latest scans.  Instead we'd request the whole
list of networks currently seen by IWD every time the Station.Scanning
property would go from true to false.  However the
Station.GetOrderedNetworks() IWD method that we use has a deficiency
up until 1.9 (I plan to fix it soon) where it won't show the hidden
network discovered in the course of the last ConnectHiddenNetwork() call
if that call was unsuccessful, in other words where the new network has
not been saved as a Known Network.  A new ConnectHiddenNetwork() will
fail with the "NotHidden" error, so we have to use the Network.Connect()
call for such a network but to find it out we need to track the
InterfacesAdded signals.  Doing this may also improve autoconnect speed
in some cases so overall I think it's a good idea.
2020-10-19 18:49:29 +02:00
Andrew Zaborowski
3b6c5d5839
iwd: Don't start new secret request if we sent one already
When IWD asks us for a secret check that we're in NM_DEVICE_STATE_CONFIG
and not for example already in NM_DEVICE_STATE_NEED_AUTH.  I believe that
should only happen if IWD is aborting the previous connection attempt and
connecting to a different network due to a timeout or due to somebody
outside NM calling Connect() on an IWD network object...

Guessing what IWD is doing this way is a bit fragile in the long term
but we have to do that as long as we want to override IWD's internal
autoconnect, which I guess we may be able to stop doing at some point.
2020-10-19 18:47:21 +02:00
Andrew Zaborowski
61e4b5a230
iwd: Don't auto-scan while waiting for secrets
IWD's Station.State property remains at "connect" or "disconnected"
while IWD is waiting for secrets for a new conncetion, so if we want to
scan only when NM might be in auto-connect (which was the goal) we need
to also look at NMDevice's state.  We want to scan whenever wifi is
disconnected and there's no active connection request, which is the same
as saying whever priv->current_ap is unset so for simplicity look at
priv->current_ap.  Also in schedule_periodic_scan() don't check whether
Station.State is "disconnected" because priv->can_scan is equivalent to
Station.State being one of ("disconnected", "connected").
2020-10-19 18:47:21 +02:00
Andrew Zaborowski
4f83960ff5
iwd: Hidden networks cleanup
Hidden networks are supported in the iwd backend since 1.24.0 but some
places in the code have not been updated to reflect this.

In check_connection_available copy the hidden network check and
corresponding comment from the wpa_supplicant backend.  In
act_stage1_prepare drop a straight "hidden networks are unsupported"
comment and a check -- fortunately this check happened to be ineffective
because @mode was more often NULL than NM_SETTING_WIRELESS_MODE_INFRA so
nm_streq0 was not enough.  Update comments elsewhere.

There's still one of two corner cases where the user-experience will not
be perfect for hidden networks due to iwd limitations, I'll try to work
around them in another commit.
2020-10-19 18:47:21 +02:00
Andrew Zaborowski
6c5068ee5a
iwd: Don't use nm_utils_error_set_literal with a non-literal
I first noticed a format string with missing parameters and then that
the compiler wasn't complaining and that's because
nm_utils_error_set_literal doesn't take a format string.
2020-10-19 18:47:20 +02:00
Andrew Zaborowski
6cf475e6db
iwd: Better checks before setting NO_SECRETS reason
When a connection fails and IWD returns net.connman.iwd.Aborted, we know
whether the abort is caused by us cancelling a secrets request so use
tha knowledge to decide whether to use the NM_DEVICE_STATE_REASON_NO_SECRETS
reason code for the state switch to NM_DEVICE_STATE_FAILED.
2020-10-19 18:47:20 +02:00
Andrew Zaborowski
b7d3e99a28
iwd: Drop IWD pre-1.0 and pre-0.8 compatiblity bits 2020-10-19 18:47:20 +02:00
Andrew Zaborowski
0d6911d529
iwd: Use the INCOMPATIBLE reason code for connection unavailable
Use the NM_UTILS_ERROR_CONNECTION_AVAILABLE_INCOMPATIBLE constant in
place of NM_UTILS_ERROR_CONNECTION_AVAILABLE_TEMPORARY more often in
check_connection_compatible as appropriate.
2020-10-19 18:34:58 +02:00
Thomas Haller
96c2aee186
l3cfg/tests: add unit tests for NML3Cfg 2020-10-13 13:46:07 +02:00
Thomas Haller
b8f9d7b5dd
l3cfg: rework ACD handling in NML3Cfg to support handling conflicts
Heavily rework NML3Cfg's ACD handling.

- the (user facing) API changed, so that we can ask the current ACD
  state of an address with nm_l3cfg_get_acd_addr_info(). So, the
  acd-event signal is only to notify when the state changes, it does
  not carry information that you couldn't fetch anytime.

- add clearer ACD states (NML3AcdAddrState). The current (ACD) state
  of an address is important and becomes part of the information that
  we expose.

- add new ACD state "USED", when ACD fails. This blocks the address from
  being used. Usually the caller would either remove the (used) address
  or force reconfigure it (by setting acd_timeout_msec to zero).

- add new ACD state "CONFLICT". Previously conflicts were not handled.
  Now the API allows to specify the defend policy. A conflicted address
  also gets blocked from being used.

- add new ACD state "EXTERNAL_REMOVED". This happens when we have an
  address we wanted to configure, but then the address is no longer
  on the interface. For example because the user removed it from the
  interface. This also leaves the device indefinitely blocked, and
  is important to stop announcing the address.

- add a new ACD state "READY". This indicates that the address is ready
  to be configured, but not yet actually configured on the device. This
  is the step before "DEFENDING".
2020-10-13 13:46:06 +02:00
Thomas Haller
79664aa106
l3cfg: handle flag "ip4acd_not_ready" for IPv4 addresses
ACD is handled by NML3Cfg and it intercepts the IP addresses when
merging the NML3ConfigData.

Originally, I thought that in such a case, the merged l3cd instance
would simply not contain any addresses that ACD have still pending or
which have a conflict.

However, I think it's better (clearer and possibly useful), to still
merge such addresses, but flag them that they are ignored when syncing
the addresses to platform.
2020-10-13 13:43:21 +02:00
Thomas Haller
e155e4a153
platform: add NMPlatformIP4Address.ip4acd_not_ready flag
It is not yet used, but it will be used to mark instances that
are not supposed to be configured in platform, because ACD is
either still pending of failed.
2020-10-13 13:39:01 +02:00
Thomas Haller
422294974c
platform: fix handlng of NMPlatformIP4Address.use_ip4_broadcast_address to be considered for hash/cmp functions
This is an important field. The hash/cmp function cannot just honor
nm_platform_ip4_broadcast_address_from_addr().
2020-10-13 13:39:01 +02:00
Thomas Haller
28bbe2a798
shared,platform: take pointer to NMEtherAddr in NM_ETHER_ADDR_FORMAT_VAL() macro
It seems nicer to require a pointer than the plain struct.
2020-10-13 12:56:25 +02:00
Thomas Haller
6807774b7d
clang-format: mark "nm_platform_iter_obj_for_each()"/"nm_l3_config_data_iter_*()" as ForEachMacros 2020-10-13 12:56:25 +02:00