Commit graph

13000 commits

Author SHA1 Message Date
Thomas Haller
e189d65ab6
lldp: expose raw LLDP message on D-Bus
Also, track sd_lldp_neighbor instance directly.

sd_lldp_neighbor is a perfectly reasonable container for keeping
track of the LLDP neighbor information. Just keep a reference to
it, and don't clone the data. Especially since the LLDP library
keeps a reference to this instance as well.

Also, to compare whether two neighbors are the same, it is sufficient
to only consider the raw data. Everything else depends on these fields
anyway.

This is only possible and useful becuase sd_lldp_neighbor is of course
immutable. It wouldn't make sense otherwise, but it also would be bad
design to mutate the sd_lldp_neighbor instances.

This couples our code slightly more to the systemd code, which we usually
try to avoid. But when we move away in the future from systemd LLDP library,
we anyway need to rework this heavily (and then too, we wouldn't want
to clone the data, when we could just share the reference).
2020-06-11 16:51:46 +02:00
Thomas Haller
597e717659
lldp: track LLDP_ATTR_TYPE_ARRAY_OF_VARIANTS as array instead of CList
Allocating and growing the buffer with realloc isn't really
complicated. Do that instead of using a CList.

Also, if there is only one element, then we can track it in-place.
2020-06-11 16:49:27 +02:00
Thomas Haller
89795fbe3d
lldp: rework _lldp_attr_id_to_name() to lookup by ID
NM_UTILS_LOOKUP_STR_DEFINE() is implemented via a switch statement.
You'd expect that the compiler could optimize that to plain lookup,
since all indexes are consecutive numbers. Anyway, my compiler doesn't,
so use the array ourself.

Note that NM_UTILS_LOOKUP_STR_DEFINE() is exactly intended to lookup
by enum/integer, if the enum values are not consecutive numbers. It may
not be best, when you can directly use the numbers as lookup index.
2020-06-11 16:49:27 +02:00
Thomas Haller
2aab266dac
lldp: rename LLDP_ATTR_TYPE_VARDICT to LLDP_ATTR_TYPE_VARIANT
VARDICT sounds like it would be a variant of "a{sv}" type. But it
can be really any GVariant. Rename to make the type more generic.

This will be used to also hold a binary variant of type "ay".
2020-06-11 16:49:27 +02:00
Thomas Haller
9b7c5ca12d
lldp: fix lldp_neighbor_equal() to compare variants
Fixes: 8200078ec5 ('lldp: support IEEE 802.3 TLVs')
2020-06-11 16:49:27 +02:00
Thomas Haller
7c0d73d94a
lldp: fix lldp_neighbor_equal() to compare lists of variants
Fixes: 6c52d946fc ('lldp: add support for management address TLV')
2020-06-11 16:49:27 +02:00
Thomas Haller
8cd9b87c91
lldp: backslash escape untrusted chassis-id,port-id strings
This is a serious issue, because this is not guaranteed to be UTF-8
data.

Fixes: 07a9364d9c ('device: export list of LLDP neighbors through D-Bus')
2020-06-11 16:49:27 +02:00
Thomas Haller
2b52b003f8
lldp/tests: assert for expected GVariant when parsing LLDP neighbor
Currently the LLDP parsing code uses GVariantBuild, which possibly does not
ensure a stable order of elements. Thus the test may not be stable.

However, that will be fixed very soon.
2020-06-11 16:49:27 +02:00
Thomas Haller
2d50370e07
lldp/tests: add test for parsing LLDP frame 2020-06-11 16:49:27 +02:00
Thomas Haller
4aa657086e
lldp/tests: assert for variant lookup in tests 2020-06-11 16:49:27 +02:00
Thomas Haller
505aee6598
supplicant: use macros to initialize config options 2020-06-11 11:06:30 +02:00
Thomas Haller
4afd62246b
supplicant: use binary search to lookup option in "nm-supplicant-settings-verify" 2020-06-11 11:06:30 +02:00
Thomas Haller
1fc1a40dd5
supplicant: remove unused str_allowed_multiple field from options 2020-06-11 11:06:30 +02:00
Thomas Haller
941277a9d6
supplicant: remove unused, duplicate "pac_file" entry from opt_table 2020-06-11 11:06:29 +02:00
Thomas Haller
97f5c684dc
supplicant: rename OptType enum to have "NM" prefix
Names in header files should have a "NM" prefix. Rename.
2020-06-11 11:06:29 +02:00
Thomas Haller
f2f82c13b5
supplicant: move strv lists into option meta data
Have the string list definition closer to the option where it is used.
2020-06-11 11:06:29 +02:00
Thomas Haller
03b3e0bfd6
supplicant: nicer align code in "nm-supplicant-settings-verify.c"
Yes, fewer lines of code is often better, if that means the code itself is
simpler. Code doesn't get simpler by cramping more in the same line.
Have every value on a separate line.

Also, vertically align the table.
2020-06-11 11:06:29 +02:00
Thomas Haller
e7a74721be
supplicant: fix verification of key_mgmt config for FT-FILS-SHA{256,384}
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/468

Fixes: d17a0a0905 ('supplicant: allow fast transition for WPA-PSK and WPA-EAP')
2020-06-11 11:06:19 +02:00
Beniamino Galvani
024e983c8e manager: change autoconnect-slaves logic for already active slaves
Autoconnect-slaves currently forces an activation of all slaves, even
if there is already an active connection for them. This is bad because
at boot slaves first try to autoconnect, then the autoconnect-slaves
of the master kicks in and disconnects/reactivates them.

The only reason why the forceful reactivation was added was to fix
[1]; in that scenario, a slave connection is already active as
non-slave; then it is updated to be a slave; later, the master with
autoconnect-slaves is manually activated. NetworkManager should detect
that the slave connection must now be activated by autoconnect-slaves.

Add a specific check for such situation, instead of always
reactivating all slaves.

[1] https://bugzilla.redhat.com/show_bug.cgi?id=1845018

Fixes: 4985ca5ada ('manager: allow autoconnect-slaves to reconnect the same connection')
2020-06-11 10:25:48 +02:00
Thomas Haller
16cff1149a
core: fix taking over external connection after restart
When we restart the daemon, it would find the previously present external
connection and assume it. We need to keep it as external.
2020-06-10 19:45:46 +02:00
Thomas Haller
8d6dbd1746
core: add "external" flag for active connections of external devices 2020-06-10 19:45:46 +02:00
Thomas Haller
96c9703b50
core: add "external" flag for connections of external devices
When a device is not marked as unmanaged, but also not actively managed
by NetworkManager, then NetworkManager will generate an in-memory
profile to represent the active state, if the device is up and
configured (with an IP address).

Such profiles are commonly named like "eth0", and they are utterly
confusing to users, because they look as if NetworkManager actually
manages the device, when it really just shows that somebody else configures
the device.

We should express this better in the UI, hence add flags to indicate
that.

In practice, such profiles are UNSAVED, NM_GENERATED, and VOLATILE. But
add an explicit flag to represent that.

https://bugzilla.redhat.com/show_bug.cgi?id=1816202
2020-06-10 19:45:46 +02:00
Beniamino Galvani
ffeac35f04 ovs: ignore failures of patch interfaces
When there are two patch ports connected, each of them must reference
the other; however they can't be created in a single transaction
because they are part of different bridges (so, different
connections). Therefore, the first patch that gets activated will
always fail with "No usable peer $x exists in 'system' datapath" until
the second patch exists.

In theory we could also match the error message, however this doesn't
seem very robust as the message may slightly change in the future.
2020-06-10 09:58:25 +02:00
David Bauer
5490011782 nm-supplicant-interface: parse 802.11 IEs after security
Psrse the 802.11 IEs after parsing the security information.

Previously the OWE transition mode flag was potentially removed
in case the security properties changed.

Signed-off-by: David Bauer <mail@david-bauer.net>
2020-06-09 16:07:04 +02:00
David Bauer
45ab623c12 nm-supplicant-interface: fix removal of OWE flag from non-transition mode BSSIDs
Commit 37e7fa38c2 ("nm-supplicant-interface: enable OWE security
when transition mode is available") adds the OWE security flag in
case a valid OWE transtition mode IE is present on the beacon.

It also removes the OWE security flag in case the Iinformation elements
of a beacon are updated and a OWE transition mode IE can't be found.

When a pure OWE AP updates it's Information Elements (e.g. BSS Load
Element), the OWE security flag is falsely removed.

Introduce a new NM_802_11_AP_SEC_KEY_MGMT_OWE_TM security flag and use
it exclusively for OWE transition mode. Don't use the
M_802_11_AP_SEC_KEY_MGMT_OWE security flag on transition-mode APs.

Signed-off-by: David Bauer <mail@david-bauer.net>
2020-06-09 16:07:04 +02:00
Beniamino Galvani
934777120b tc: add support for tbf qdisc
Add support for Token Bucket Filter queueing discipline.
2020-06-08 15:31:42 +02:00
Beniamino Galvani
b22b4f9101 tc: add support for sfq qdisc
Add support for Stochastic Fairness Queueing queueing discipline.
2020-06-08 15:31:42 +02:00
Beniamino Galvani
283f7d0b30 move tc parsing out of nm-device.c
The logic to create platform qdiscs from a setting does not belong to
NMDevice. Move it to NetworkManagerUtils.h.
2020-06-08 15:31:41 +02:00
Thomas Haller
46da6e2905
systemd: fix wrong assertion in sd_lldp_get_neighbors() 2020-06-05 18:20:28 +02:00
Thomas Haller
ab2395c966
device/lldp: drop our own rate limiting for maximum number of LLDP neighbours
Systemd's LLDP client also internally tracks all neighbours, and it thus
already needs a maximum already. For systemd, that is currently 128.
We don't need to implement our own rate limiting on top of that,
because if we wouldn't trust the LLDP client to get this right,
it would be DoS-able already.

Also decrease the number of maximum neighbours from 4k to 128.
Note that already previously we wouldn't ever get more than 128
entries.
2020-06-05 17:05:24 +02:00
Thomas Haller
7d9ba20893
device/lldp: minor cleanups in "nm-lldp-listener.c" 2020-06-05 16:47:09 +02:00
Thomas Haller
7ecc1cfaaf
platform: assert struct alignment of NMPlatformIPRoute/NMPlatformIPAddress type 2020-06-05 15:14:30 +02:00
Thomas Haller
e2f83d4e92
keyfile: add NMKeyfileHandlerFlags
nm_keyfile_read() and nm_keyfile_write() will be public API.
As such, it must be flexible and extendible for future needs.
There is already the handler callback that fully solves this
(e.g. a future handler event could request whether a certain
behavior is enabled or not).

As additional possibility for future extension, add a flags
argument. Currently no flags are implemented.
2020-06-05 09:17:21 +02:00
Thomas Haller
00b3a3505a
keyfile: add nm_keyfile_handler_data_warn_get() and construct message lazy
Add an accessor for the warning event.

Also, as we now have an accessor, we can construct the warning
message only if it actually needed.
2020-06-05 09:17:20 +02:00
Thomas Haller
7d47a8fdbf
keyfile: add handler context for all parser callbacks
From inside a callback 4 properties are potentially interesting
to all callbacks: the currenty group, key, setting and property-name.

Refactor the code to track these properties in NMKeyfileHandlerData
and distinguish between the property name and the keyfile key.
2020-06-05 09:17:19 +02:00
Thomas Haller
ab7d0c62f9
keyfile: rework error reporting from read/write handler
Setting the error on the callback does not work well from bindings.
Instead, let bindings call a (future) nm_keyfile_handler_data_fail_with_error()
function on the handler_data to indicate failure.
2020-06-05 09:17:18 +02:00
Thomas Haller
0bfdb26973
keyfile: add NMKeyfileHandlerData typedef for arguments of keyfile callbacks
As the keyfile handler callback will become public API, it needs to be
usable via bindings. A plain void pointer is not usable. Instead, add
a new type that can be used via introspection.
2020-06-05 09:17:18 +02:00
Thomas Haller
18c1fe6ed8
keyfile: merge NMKeyfile{Read,Write}Type as NMKeyfileHandlerType
This will become public API. The enum for read and write callback
serves very similar purposes. Merge them so that we have fewer
types in the public API.
2020-06-05 09:17:14 +02:00
Thomas Haller
65b6fc7871
nettools: reimport nettools' n-dhcp4 and rework logging
git subtree pull --prefix shared/n-dhcp4/ git@github.com:nettools/n-dhcp4.git master --squash
2020-06-03 22:34:22 +02:00
Thomas Haller
cc3e23d2e5 Squashed 'shared/n-dhcp4/' changes from fb1d43449ba8..6876b73ec113
6876b73ec113 all: rework logging to append logging messages to the event queue
65ca0e4bea32 client: check length of client id for n_dhcp4_client_config_set_client_id()
6a9ca10b7ad6 client: close timer file descriptor explicitly when EPOLL_CTL_ADD fails
e5f3b27f5301 connection: don't fail dispatch in case of receive errors
68790d5ec950 connection: keep trying after a failure in send()
788b03891cd0 n-dhcp4: fix logging macro
6cd0fd5e8b3f probe: request previous address after expiration
ef11c7079ad7 connection: avoid double free of NDhcp4Outgoing
922a9a2326e7 n-dhcp4: fix initialization of the 'secs' DHCP header field
7fff54117436 outgoing: fix uninitialized variable in n_dhcp4_outgoing_append()
27547faaf258 probe: move back to INIT after lease expires
d07cb4e32884 incoming: accept options that are longer than requested
34d365e2267f client: handle invalid return codes gracefully during n_dhcp4_client_dispatch()
2e8c6017f85b n-dhcp4: use packet socket in rebinding state
9a7c82143c06 n-dhcp4: support init-reboot state
e615e3f5b063 n-dhcp4/socket: use SO_REUSEADDR on UDP socket
8dbfa1ad2549 merge branch 'bengal:log'
6e50189fba86 n-dhcp4: log outgoing packets
aea0315d3862 n-dhcp4: log incoming packets
1ca64a82393d n-dhcp4: add logging API
72c16a0028ac client-probe: fix state transitions on timer dispatch
c023ae2ad829 merge branch 'leasetime'
780f94c333ca lease: add n_dhcp4_client_lease_get_basetime()
a94378274cf4 incoming: don't handle 0xFFFFFFFF timestamps special in n_dhcp4_incoming_query_u32()
6bb277aefe0b probe: unconditionally pass ownership of message in n_dhcp4_client_probe_dispatch_io()
1cf87c90c6a1 probe: fix leaking message during client probe
55239cef2d63 lease: remove unreachable code in n_dhcp4_incoming_get_timeouts()
fa5ee7903061 lease: expose the server IP address
0cfce4a4fe07 all: merge branch 'th/build-centos76'
cae4868e5f7e all: avoid {net,linux}/if.h clashes on old distros
05859a3e4d32 all: avoid c_min() macro to work with old GCC
0be7033dd940 probe: arm timers in bound state
8735cdb0f95f ci: switch to c-util automation
a0bb7c69a11a client: fallback to CLOCK_MONOTONIC for timerfd
308cb242caf7 ci: disable valgrind run
468c93195ad3 build: update submodules
9d0f690f9ee8 ci: switch to github actions
9ba143a037bb probe: allocate memory of right size in n_dhcp4_client_probe_option_new()
2546aa2c809d util/link: suppress gcc warning
e4a01f5870a6 ci: drop broken armv7hl
2e2fbfa18f2c build: update submodules
6277dfd20eca Merge pull request #2 from NetworkManager/th/declaration-after-statement
1b660ae2d12a outgoing: avoid "-Werror=declaration-after-statement" warning with static_assert
f34a54cd9719 client/probe: fix memory leak
21e68f3bba80 client/connection: fix memory leak

git-subtree-dir: shared/n-dhcp4
git-subtree-split: 6876b73ec113328712a5cdc2ffb9497fd774c0e2
2020-06-03 22:21:50 +02:00
Thomas Haller
462877084f
core: fix maybe-uninitialized warning in periodic_update_active_connection_timestamps()
../src/nm-manager.c: In function periodic_update_active_connection_timestamps:
  ../src/nm-manager.c:7358:43: error: t may be used uninitialized in this function [-Werror=maybe-uninitialized]
     nm_settings_connection_update_timestamp (nm_active_connection_get_settings_connection (ac),
                                             ^
Fixes: 6f3ae8a563 ('core: in periodic_update_active_connection_timestamps() use same timestamp')
2020-06-03 20:03:34 +02:00
Thomas Haller
aeb81183de
core: drop mask argument from nm_settings_connection_autoconnect_blocked_reason_get()
We don't need the mask argument. If the caller wants to check only for certain
flags, she can do that right away with

  NM_FLAGS_ANY (nm_settings_connection_autoconnect_blocked_reason_get (sett_con), flags)
2020-06-03 18:35:54 +02:00
Alfonso Sánchez-Beato
440a5c03b3
settings: unblock autoconnect on new secrets
When the secrets for a connection are updated, unblock autoconnection
in case it had been blocked previously due to bad or no
secrets. Otherwise we would need to manually activate the connection
or restart NM to get another try with the new secrets.
2020-06-03 18:29:12 +02:00
Alfonso Sánchez-Beato
fcfc12d50f
settings: move up autoconnect initialization functions
Move autoconnect initialization functions up so we can use them from
update_auth_cb.
2020-06-03 18:29:12 +02:00
Thomas Haller
835175e4fb
Revert "wifi: don't autoconnect to networks that have never been successful"
As commit ccfe5fec8d ('wifi: don't autoconnect to networks that have
never been successful') explains, Wi-Fi profiles only autoconnected
if they had no or a positive timestamp.

The problem that tried to solve is when a user accidentally clicks on a
Wi-Fi network in applet. Then the created profile may not be usable
(because of wrong credentials). To avoid indefinitely to autoconnect,
uch a profile will have a timestamp of 0, which prevents further
auto activations.

However, I find that problematic.

An important use case is pre-deploying profiles. In that case, the user
cannot set the timestamp, because the timestamp cache
/var/lib/NetworkManager/timestamps is internal, undocumented API. Also,
ifcfg-rh doesn't support the timestamp and anyway, does the timestamp
of the NMConnection does not get honored (only the one from the
timestamps file).
Maybe that could be an alternative solution here, to allow the user to
mark profiles as "I really want it to autoconnect". But that seems
unnecessary and wrong to me.

The problem really is that the user cannot do anything to ensure that
autoconnect will work tomorrow (short of editing the timestamps
database). The problem is that the property of whether a profile
every connected successfully is not in direct control of the user (it
depends on external conditions).

If the user has bogus profiles configured, those profiles should be
deleted (or autoconnect disabled) and not keep autoconnect blocked.

Also note that if you are at home and accidentally click on your
neighbour's Wi-Fi network, then you presumably still also have a working
profile to your own network. That usable profile will have a more
recent timestamp and be preferred during autoconnect already.

This reverts commit ccfe5fec8d.

https://bugzilla.redhat.com/show_bug.cgi?id=1781253
2020-06-03 18:25:33 +02:00
Thomas Haller
a9d20141b9
core: log changes to the profile timestamp 2020-06-03 18:25:33 +02:00
Thomas Haller
c3db3e0044
core: don't do anything if there are no changes in nm_settings_connection_update_timestamp()
Updating the timestamp marks the keyfile database as dirty. Avoid
that, if there is no change. Of course, nm_key_file_db_set_value()
itself already checks whether the are any changes, and does nothing
if there aren't.

Simply perform the check earlier, to do nothing.
2020-06-03 18:25:32 +02:00
Thomas Haller
6f3ae8a563
core: in periodic_update_active_connection_timestamps() use same timestamp
When performing  a synchronous action together (like iterating
over all settings and set the current timestamp), it's nicer
to pretend that all this would happen instantaneously. That means,
ensure we use the same timestamp throughout.

On a minor point, there really is no need to call time() multiple times.
2020-06-03 18:25:11 +02:00
Thomas Haller
968b444603
initrd: drop unused include of platform header 2020-06-03 18:08:37 +02:00
Thomas Haller
1c2d9581e9
initrd: use nm_streq()/NM_IN_STRSET() instead of strcmp()
Code like

»···»···if (strcmp (tag, "net.ifnames") == 0)
»···»···»···net_ifnames = strcmp (argument, "0") != 0;

is really hard to understand (at least to me). Compare to

»···»···if (nm_streq (tag, "net.ifnames"))
»···»···»···net_ifnames = !nm_streq (argument, "0");
2020-06-03 18:00:05 +02:00