Commit graph

28199 commits

Author SHA1 Message Date
Thomas Haller
ea67f48050
cli: handle empty/unset values for "gsm.apn" property
Most string properties can be either %NULL (unset) or a non-empty
string.

For a few properties, like "gsm.apn", also the empty word is a valid
value. That makes it problematic to use from nmcli, because

  nmcli connection modify "$PROFILE" gsm.apn ""

means to reset the default (NULL). How to configure the empty word?
For the APN, "" has a specific meaning, distinct from NULL, so we
need to be able to represent that.

The other problem with nmcli is that

  nmcli -g gsm.apn connection show "$PROFILE"

is supposed to give you a value that you an set again, like

  X="$(nmcli -g gsm.apn connection show "$PROFILE"; echo x)"
  nmcli connection modify "$PROFILE2" gsm.apn "${X%$'\n'x}"

but for %NULL and "" the output would be the same.

The "solution" to that is interpreting "" as NULL (like we always did)
and a non-empty string that contains all whitespace, like a string with
one whitespace less. This way, all values can be expressed.

Note that in case of "gsm.apn", the string is anyway internally
normalized with g_strstrip(), so a string with all whitespace was
not expressable.
2021-05-03 10:11:25 +02:00
Thomas Haller
10567386f0
cli/tests: add unit test for checking setting/getting of "gsm.apn"
"gsm.apn" is special, because it can both be %NULL and "".

Add a test for how we handle that.
2021-05-03 10:11:24 +02:00
Thomas Haller
2c37a34d53
cli: fix RETURN_STR_EMPTYUNSET() macro for printing handle_emptyunset string
This was currently unused, because actually no property of type string
had handle_emptyunuset set.

Fixes: e9ee4e39f1 ('cli: handle string properties that can both be empty and %NULL')
2021-05-03 10:11:24 +02:00
Thomas Haller
95932ab577
cli: reset GSM's APN/username/password when setting auto-config
Otherwise,

  nmcli connection modify "$GSM_PROFILE" gsm.auto-config yes

has no effect -- if APN/username/password is set.
2021-05-03 10:11:23 +02:00
Thomas Haller
40032f4614
cli: fix resetting values via property alias
Property aliases should really just be shortcuts for one fully spelled
out property (sometimes, they do more like "master").

Anyway, we must also handle resetting the value, otherwise:

  $ nmcli connection add type gsm apn ""

will still result in "gsm.apn=internet", unlike

  $ nmcli connection add type gsm gsm.apn ""
2021-05-03 10:11:23 +02:00
Thomas Haller
a97c6f70ed
cli: use _pt_gobject_ternary for ternary properties
This accepts more formats, like also yes/on instead of only
true.
2021-05-03 10:11:22 +02:00
Thomas Haller
3f0812e504
cli: add _pt_gobject_ternary property type
This will be used for NMTernary properties. The get() method
is still the same as for _pt_gobject_enum, but the setter
and complete functions are more flexible to also allow yes/true
and any unique abbreviations.
2021-05-03 10:11:22 +02:00
Thomas Haller
7df7d46bfe
cli: make nmc_string_to_ternary() more flexible
- use strstrip() to remove leading and trailing whitespace
- use _nm_utils_ascii_str_to_int64() for parsing numeric values
  like -1, 0 and 1. In particular, this now also allows passing
  the numeric values.
- also accept "default" as valid value for NM_TERNARY_DEFAULT.

With this change, nmc_string_to_ternary() can also parse everything that
we commonly and currently parse with _nm_utils_enum_from_str_full()
and NM_TYPE_TERNARY. This will allow to configure ternary values in
a more flexible way.
2021-05-03 10:11:21 +02:00
Thomas Haller
bd9f941a3a
cli: make nmc_string_to_bool() more flexible
- use strstrip() to remove leading and trailing whitespace
- use _nm_utils_ascii_str_to_int64() for parsing numeric values
  like 0 and 1. The difference is small, for one, it also accepts
  hex numbers like 0x1. More interestingly, it uses our common
  number parsing function, and we will later do the same for
  parsing ternaries.
2021-05-03 10:11:21 +02:00
Thomas Haller
1731fcf35e
cli: improve error message about ambigious text in nmc_string_to_bool()
The "on x off" is confusing. Use "on, off".
2021-05-03 10:11:21 +02:00
Thomas Haller
f62ecc97c8
cli: use proper GError codes in "nm-client-utils.c"
g_set_error(error, 1, 0, ...) is not right. "1" is not a valid GQuark,
we should initialize proper error instances.

Use nm_utils_error_set() for that.

Also, the code previously hacked the numeric value "1" to indicate
ambiguous text. Add and use a new error code NM_UTILS_ERROR_AMBIGUOUS
for that.
2021-05-03 10:11:21 +02:00
Thomas Haller
a4d3c7a900
cli: add _set_fcn_gobject_bool_impl() helper
Will be used next.
2021-05-03 10:11:21 +02:00
Thomas Haller
1f33a59a0f
cli: use const argument for nmc_string_is_valid()
With a const argument, we can make variables static const,
which means the linker loads the memory as read only.

Also, use NM_CAST_STRV_CC() macro, which casts the argument
accordingly.
2021-05-03 10:11:20 +02:00
Beniamino Galvani
bf6214ef32 merge: branch 'bg/dbus-path'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/831
2021-04-30 17:02:06 +02:00
Beniamino Galvani
aaed69e5d7 contrib/rpm: install D-Bus service files to /usr in RHEL8
When supported by the D-Bus daemon, it's better to have service files
in /usr rather than in /etc. Change the path for RHEL 8.

See also commit ef8c292881 ('contrib/rpm: install D-Bus service
files to /usr if we can').
2021-04-30 17:00:50 +02:00
Beniamino Galvani
299a6af3ee build: install D-Bus service files to /usr by default
Service files shipped by distribution should be in /usr.
2021-04-30 17:00:50 +02:00
Beniamino Galvani
d65b67e381 wifi: merge branch 'wifi-auth-alg-general-fixes'
Some fixes for creating wpa_supplicant config.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/826
2021-04-30 08:30:42 +00:00
Jonas Dreßler
b876e76518 supplicant/config: Make sure PMF gets enabled with wpa-eap-suite-b-192
wpa-eap-suite-b-192 key-mgmt method uses special values for "pairwise"
and "group" ciphers, we can also handle that a few lines underneath
where those are set to make this a bit easier to read.

We currently set the supplicants PMF config (ieee80211w) inside an if
block that tries to detect whether WPA is used. That if-block doesn't
include the "wpa-eap-suite-b-192" case because we want special
"pairwise" and "group" handling for wpa-eap-suite-b-192. This means
we're currently missing to enable PMF in the "wpa-eap-suite-b-192" case,
even though it's set to REQUIRED.

Fix it by moving the "pairwise" and "group" special-casing down a bit so
we can include "wpa-eap-suite-b-192" in the "Only WPA-specific things
when using WPA" check, that will make sure ieee80211w gets set in the
wpa-eap-suite-b-192 case.
2021-04-30 07:38:20 +00:00
Jonas Dreßler
aab56adeea libnm-core: Correctly check for "sae" or "none" when wifi mesh is used
A small bug sneaked into commit 3ef3733c81 ('wireless-security: ensure
Mesh networks can't use anything but SAE') during review: Instead of
allowing only "sae" or "none" as key-mgmt, we now disallow "sae" and
"none", but allow anything else. This is obviously not what was
intended, so fix the check.

Also move the valid_key_mgmt check back up to where it was before that
commit, it seems we want to apply that check in all cases.
2021-04-30 07:38:20 +00:00
Jonas Dreßler
97a49430bb libnm-core: Correct an error message
wpa-eap-suite-b-192 is also valid here, so mention it in the error
message.
2021-04-30 07:38:20 +00:00
Jonas Dreßler
29c7debf40 supplicant/config: Remove superfluous check to disable PMF
We only set the "ieee80211w" option in the wpa_supplicant config in case
we're using WPA (see the if-block underneath), otherwise the value of
"pmf" is completely ignored. That means the override here (in case WPA
isn't used) isn't getting applied anyway, so just remove it.
2021-04-30 07:38:20 +00:00
Jonas Dreßler
dcd032055c supplicant/config: Add a comment mentioning global pmf config value
It looks a bit weird on the first glance that we do nothing when
NM_SETTING_WIRELESS_SECURITY_PMF_OPTIONAL is used. The reason for this
is that we already intialize the global option "pmf" of wpa_supplicant
to "1" (optional), so add a brief comment about that here.
2021-04-30 07:38:20 +00:00
Thomas Haller
6400c33915
libnm/trivial: add code comment for _peers_dbus_only_synth() handling of allowed-ips 2021-04-29 17:27:32 +02:00
Thomas Haller
12f25d965d
man: add example script to manual how to enable nm-cloud-setup 2021-04-29 13:41:15 +02:00
Thomas Haller
e7d7ed53d4
dns: merge branch 'th/systemd-resolved-resolve'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/825
2021-04-28 13:21:19 +02:00
Thomas Haller
e7b76f6757
dns/resolved: add API for ResolveAddress call
ResolveAddress is a simple D-Bus API. One might think that it does not
require much logic, and we would just make the D-Bus call directly.

However, we want to ensure that we always sent our latest DNS
configuration to systemd-resolved first, before making any D-Bus request
to resolve a name.

Also, as we D-Bus activate the service and watch the name owner, we
want to handle that. If a user resolves a name while we are still D-Bus
activating, then we need to queue the request.

This adds some complexity in the implementation. But the benefit is that
the API becomes simple from the user's point of view. The queuing and
avoiding race conditions is handled internally.

The implementation does not use standard glib patterns with GAsyncResult
GTask and GCancellable. I find implementing them correctly is more
effort and leads to a less nice API. That might be fine for public API,
which should follow glib style. But this is entirely internal, and
returning a NMDnsSystemdResolvedResolveHandle that allows cancellation
seems more convenient to me.
2021-04-28 13:20:03 +02:00
Thomas Haller
5cc6932d5a
dns/resolved: use unique D-Bus name for systemd-resolved request
As we already track the current name owner, it seems wrong to make
requests to the well-known name. It theoretically opens a race
where we would talk to the wrong systemd-resolved instance.

So far, we didn't care and it didn't make much of a difference.
Still, let's talk to the process that we expect.
2021-04-28 13:20:03 +02:00
Thomas Haller
e7d78e90a3
dns/resolved: track D-Bus owner of resolved D-Bus service 2021-04-28 13:20:03 +02:00
Thomas Haller
4285eed8eb
dns/resolved: add watchdog D-Bus activating systemd-resolved
Currently, it doesn't actually do anything (beside logging).
Will be used next.
2021-04-28 13:20:02 +02:00
Thomas Haller
8ee5ec00f9
dns/trivial: rename NMDnsSystemdResolvedPrivate.request_queue_to_send to "send_updates_waiting"
The previous name seems confusing to me.
2021-04-28 13:20:02 +02:00
Thomas Haller
92f742f66b
dns/resolved: add ensure_resolved_running() helper method
Factor out the code. We will use it next.
2021-04-28 13:20:02 +02:00
Thomas Haller
42938a7f52
dhpc: merge branch 'th/dhcp-request-broadcast'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/822
2021-04-28 13:10:31 +02:00
Thomas Haller
2ae5e7aa26
dhcp: set request_broadcast for devices that set udev ID_NET_DHCP_BROADCAST
For infiniband, request_broadcast is automatically (and always) enabled.
Otherwise, we usually don't enable it, and (unlike systemd-networkd),
there is currently no configuration option to enable it.

Still honor the new udev property that can indicate to enable the flag
per device.

See-also: https://github.com/systemd/systemd/pull/ ### 19346
2021-04-28 13:10:15 +02:00
Thomas Haller
4acbb0fdc9
dhcp: add client_flags argument to nm_dhcp_manager_start_ip[46]() 2021-04-28 13:10:14 +02:00
Thomas Haller
b6b38af8aa
dhcp: simplifiy tracking of client flags in client_start() 2021-04-28 13:10:14 +02:00
Thomas Haller
a5cfa6e4f4
dhcp: refactor NMDhcpClient to use client flags
The DHCP client has potentially a large number of options,
including boolean options (flags). It is cumbersome to implement
them one by one. Instead, make more prominent use of NMDhcpClientFlags.
2021-04-28 13:10:13 +02:00
Thomas Haller
48a3cebce5
core: use _nm_utils_ascii_str_to_bool() to parse boolean udev properties
Previously, we used nm_udev_utils_property_as_boolean(), which was
taken from g_udev_device_get_property_as_boolean(). That function
accepts "1" and "true" (with ASCII case insensitive).

When we parse a flag, there is no need to reject "no", "yes" or
"on"/"off" as invalid (and thus return FALSE). We have a boolean
parse method _nm_utils_ascii_str_to_bool(), which parses everything
that nm_udev_utils_property_as_boolean() accepts, and more.

Be liberal in what we accept, so use our general parse function.
2021-04-28 13:10:13 +02:00
Thomas Haller
3762e8f0c5
platform: add nmp_object_link_udev_device_get_property_value() helper 2021-04-28 13:10:13 +02:00
Thomas Haller
47fa919720
platform: expose nm_platform_link_get_udev_property() function 2021-04-28 13:10:13 +02:00
Thomas Haller
2c9924482a
wifi/iwd: merge branch 'verdre:iwd-backend-fixes'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/828
2021-04-27 19:53:14 +02:00
Jonas Dreßler
77ef56714d
iwd: Don't add comments about PSK passphrase to config files
g_key_file_set_comment() has slightly weird API that will fail to set a
comment if it doesn't find the group. This is the case here since we
haven't set any strings under the [Security] group yet.

Fixing this is kind of ugly, so for now just don't add that comment in
the case where we don't have the [Security] group.
2021-04-27 19:52:48 +02:00
Jonas Dreßler
971dcc0777
iwd: Actually update iwd config in mirror_connection() if needed
There are cases where the settings didn't actually change and we just
want to ensure NM and iwd settings are in sync (one such case would be
when a setting was changed while iwd wasn't running, here we want to
synchronize all settings when starting up iwd).

We're already doing this and calling sett_conn_changed() from
mirror_connection() on all connections after adding an interface, the
actual settings synchronization code doesn't get executed though because
we're passing 0 as update_reason, which means we bail out early from
sett_conn_changed().

To make sure we actually update the iwd network configurations in that
case, too, pass UPDATE_REASON_UPDATE_NON_SECRET as the update reason to
sett_conn_changed(), which is the correct update reason in this case.
2021-04-27 19:52:48 +02:00
Jonas Dreßler
c8608d7cc3
iwd: Correctly compare autoconnected states
Quite obviously, we want to update the AutoConnect setting of the iwd
network in case the NM and iwd settings differ, not if they are the
same. So check for unequality here instead of equality, which fixes the
AutoConnect setting's synchronization.

Fixes: 4229c97012 ('iwd: Mirror NM connections to IWD network config files'):
2021-04-27 19:52:43 +02:00
Beniamino Galvani
b9929b647b m4: fix readline macro
The macro always overwrites LIBS and the result is that every binary
links against libreadline.

Instead, save the library to READLINE_LIBS.

See also: 94274c6fcd ('build: fix wrongly linking against libreadline in all applications')

Fixes: af360238be ('m4/ax_lib_readline.m4: Update after running aclocal')
2021-04-27 10:33:59 +02:00
Thomas Haller
43a0c6c111
core: fix assertion failure in device's activate_stage2_device_config()
Fixes: d946aa0c50 ('wired-setting: add support to accept-all-mac-addresses')
2021-04-26 21:17:18 +02:00
Thomas Haller
23a200d19e
checkpatch: warn about uses of strcmp()/g_strcmp0()
Using strcmp()/g_strcmp0() for checking for string equality is hard
to read. We should prefer our streq variants -- unless, you really
mean cmp.
2021-04-26 09:53:11 +02:00
Thomas Haller
4d3de2721d
core: merge branch 'balrog-kun:drop-secrets-cache'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/814
2021-04-23 15:04:42 +02:00
Andrew Zaborowski
16457cb303
settings: Drop NMSettingsConnection's system secrets cache
Apparently moving secrets between priv->connection and
priv->system_secrets in the various places throughout
NMSettingsConnection is no longer needed and has no effect on the
state of the D-Bus object or the gobject visible from outside.  It
seems that it was needed for the secrets handling in NMDevice
subclasses before the introduction of the applied connection concept
but now nm_connection_need_secrets() is called in those subclasses
directly on the applied connection object and the secrets obtained
from multiple nm_settings_connection_get_secrets calls are also
collected directly in the applied connection's settings.

Drop the system secrets cache mechanism as a cause of a minor memory
overhead, some code overhead and also a source of some unneeded gobject
signals as the connection settings were being updated.

Note: the NM_SETTINGS_CONNECTION_UPDATE_REASON_CLEAR_SYSTEM_SECRETS and
NM_SETTINGS_CONNECTION_UPDATE_REASON_RESET_SYSTEM_SECRETS flags in the
SettingsConnection update signals appear to only have been used by the
SettingsConnection internally to keep priv->system_secrets up to date.
They can have potential other uses in the handlers of those signals so I
kept them.  Unlike some of the other NMSettingsConnectionUpdateReason
values these are actual update *reasons* and not flags telling the
settings backends how to handle a specific change in the settings.
2021-04-23 15:00:51 +02:00
Andrew Zaborowski
d1566d7b4b
settings: Drop nm_settings_connection_clear_secrets
All usages of nm_settings_connection_clear_secrets() outside of the
NMSettingsConnection implementation were setting the
clear_cached_system_secrets parameter to FALSE which meant that the
operation was a no-op since the system-secrets cache kept a copy of the
secrets being cleared and any access to the SettingsConnection through
the D-Bus API or the class methods would behave the same as without the
call, with the exception of directly reading the settings from the
result of nm_settings_connection_get_connection().  The calls would
still generate D-Bus and gobject signals however, which were redundant.

Drop the method and its calls from the rest of NM code as not needed and
potentially confusing.  The comments preceding these calls implied that
they were needed so that the next activation attempt would be forced to
use nm_settings_connection_get_secrets() but this was the case probably
only before the applied connection concept was introduced.

Also drop two nm_active_connection_clear_secrets() uses in
NMVpnConnection, right before the teardown of the active connection,
that could only possibly have any effect if they affected the
NMSettingsConnection, but as mentioned earlier the
nm_settings_connection_clear_secrets() use inside
nm_active_connection_clear_secrets() didn't do anything and is now
removed.

The one internal use of nm_active_connection_clear_secrets() in the
D-Bus ClearSecrets() implementation is inlined.
2021-04-23 15:00:51 +02:00
Beniamino Galvani
9b3fd5965b release: bump version to 1.31.3 (development) 2021-04-22 23:04:27 +02:00