Commit graph

28238 commits

Author SHA1 Message Date
Thomas Haller
ce65fc52a8
glib-aux: add nm_uuid_is_valid() helper 2021-05-04 15:51:55 +02:00
Thomas Haller
b12f116a02
glib-aux: add nm_uuid_is_valid_nmlegacy() helper 2021-05-04 15:51:53 +02:00
Thomas Haller
2fcabf5699
all: only include "libnm-glib-aux/nm-uuid.h" where needed
Don't let "nm-core-internal.h" (which is a very popular header itself)
drag in "nm-uuid.h".
2021-05-04 15:51:51 +02:00
Thomas Haller
414ce2236e
glib-aux: add NMUuidType enum for nm_uuid_generate_from_string()
Let's have an enum instead of plain "int" and #define.
2021-05-04 15:51:50 +02:00
Thomas Haller
995c78245e
glib-aux/trivial: rename NMUuid API 2021-05-04 15:51:49 +02:00
Thomas Haller
78297db721
libnm,glib-aux: move nm_utils_uuid_*() API to libnm-glib-aux 2021-05-04 15:51:47 +02:00
Thomas Haller
c5985db7cf
libnm,glib-aux: move nm_crypto_md5_hash() to "libnm-glib-aux"
This only uses glib's md5 code and has no dependency on our
crypto libraries (gnutls, nss).

Move it to "libnm-glib-aux" so it can be freely used.

Maybe it deserves a better name, but "nm-shared-utils.h" is a heap of
various utility functions, it's hard to name them well.
2021-05-04 15:51:46 +02:00
Thomas Haller
73cfc4097a
libnm,glib-aux: add and use nm_uuid_generate_random_str*() helpers 2021-05-04 15:51:45 +02:00
Thomas Haller
dd1a618745
libnm,glib-aux: move nm_utils_uuid_is_null() to "nm-uuid.h" 2021-05-04 15:51:45 +02:00
Thomas Haller
73b9883c6f
build: don't link libnm/libnm-core against libuuid
We use util-linux's libuuid for handling UUIDs. But UUIDs are
really a trivial thing, at least the portion that we use.

Reimplement the parse/unparse/generate_random() methods and drop
the dependency. Note that no other libraries from our dependency chain
was dragging in libuuid, so thereby we really get rid of the dependency.

We still require libuuid for building, because it is used by an example
program. Maybe that should be changed, to avoid the build dependency.
But that can be done at a later time.
2021-05-04 15:51:44 +02:00
Thomas Haller
7a15144f75
glib-aux: use nm_uuid_generate_random() helper 2021-05-04 15:51:43 +02:00
Thomas Haller
b4608b3ff7
glib-aux: add nm_uuid_generate_random() helper 2021-05-04 15:51:43 +02:00
Thomas Haller
42d67415b4
glib-aux: use nm_uuid_parse() helper 2021-05-04 15:51:42 +02:00
Thomas Haller
e7568e29b2
glib-aux: add nm_uuid_parse() helper 2021-05-04 15:51:42 +02:00
Thomas Haller
596bf4b91b
glib-aux: use nm_uuid_unparse() 2021-05-04 15:51:42 +02:00
Thomas Haller
cd45ad4acf
glib-aux: add nm_uuid_unparse() 2021-05-04 15:51:42 +02:00
Thomas Haller
daebb11af8
glib-aux: move NMUuid to "src/libnm-glib-aux/nm-uuid.h" 2021-05-04 15:51:41 +02:00
Thomas Haller
50add1c75a
glib-aux: add "nm-uuid.[ch]" sources 2021-05-04 15:51:41 +02:00
Thomas Haller
36d92182a8
libnm-core/tests: add test for connection.uuid of settings 2021-05-04 15:51:41 +02:00
Thomas Haller
05130b6e10
ifupdown: replace _str_has_prefix() by NM_STR_HAS_PREFIX() 2021-05-04 15:51:41 +02:00
Thomas Haller
901f0bdeb3
gitlab-ci: fix running Fedora 34 test by default
- the container that is also "pages_build" should always
  run automatically. This can replace the "always" tag.

- comment out the "always: 33" part, because we no longer need
  it. It was also wrong, because by now we should run Fedora 34
  automatically.
2021-05-04 15:42:26 +02:00
Thomas Haller
264db0695a
gitlab: merge branch 'th/gitlab-update-f34'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/838
2021-05-04 13:58:48 +02:00
Thomas Haller
ebde0a3506
gitlab: update pages build to use Fedora 34 container 2021-05-04 13:56:28 +02:00
Thomas Haller
fb2ea999ea
clang-format: update "nm-code-format-container.sh" script to use Fedora 34 container 2021-05-04 13:56:27 +02:00
Thomas Haller
21321ac736
clang-format: reformat code with clang 12
The format depends on the version of the tool. Now that Fedora 34 is
released, update to clang 12 (clang-tools-extra-12.0.0-0.3.rc1.fc34.x86_64).
2021-05-04 13:56:26 +02:00
Thomas Haller
b32dc4f2cf
gitlab: add Fedora 34 container for CI pipeline 2021-05-04 13:56:25 +02:00
Thomas Haller
94ba38962f
contrib: install clang-format via REQUIRED_PACKAGES
On Fedora 33, we get it automatically because "clang" package
has an indirect (weak) dependency for clang-tools-extra. On
Fedora 34, that is no loger the case.

We need to explicitly install it.
2021-05-04 13:56:19 +02:00
Beniamino Galvani
23cc0bf335 manager: fix assertion failure in active_connection_find()
Active-connections in the async_op_lst are not guaranteed to have a
settings-connection. In particular, the settings-connection for an
AddAndActivate() AC is set only after the authorization succeeds. Use
the non-asserting variant of the function to fix the following
failure:

 nm_active_connection_get_settings_connection: assertion 'sett_conn' failed

 1    _g_log_abort()
 2    g_logv()
 3    g_log()
 4    _nm_g_return_if_fail_warning.constprop.14()
 5    nm_active_connection_get_settings_connection()
 6    active_connection_find()
 7    _get_activatable_connections_filter()
 8    nm_settings_get_connections_clone()
 9    nm_manager_get_activatable_connections()
 10   auto_activate_device_cb()
 11   g_idle_dispatch()
 12   g_main_context_dispatch()
 13   g_main_context_iterate.isra.21()
 14   g_main_loop_run()
 15   main()

Fixes: 33b9fa3a3c ('manager: Keep volatile/external connections while referenced by async_op_lst')

https://bugzilla.redhat.com/show_bug.cgi?id=1933719
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/834
2021-05-04 08:48:29 +02:00
Thomas Haller
ad2226eacd
core/firewalld: use changeZoneOfInterface() instead of deprecated changeZone()
`man firewalld.dbus` comments that changeZone() is deprecated.
Apparently this is the case since 0.3.3-1 (2013).

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/836
2021-05-04 08:26:42 +02:00
Beniamino Galvani
a3306d538c merge: branch 'bg/dns-update-on-sigusr1'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/832
2021-05-03 22:22:57 +02:00
Beniamino Galvani
a0aa727af2 nmcli: remove nmc_dbus_call_sync()
The function is unused now. All operations should be asynchronous so
that nmcli keeps running the main loop.
2021-05-03 22:22:01 +02:00
Beniamino Galvani
9d0aca6757 nmcli: invoke ReloadConnections() D-Bus method asynchronously 2021-05-03 22:22:01 +02:00
Beniamino Galvani
1d82c39bfa nmcli: invoke Reload() D-Bus method asynchronously
Invoke Reload() asynchronously and run the main loop. In this way, the
polkit agent built into nmcli can be used to authenticate the reload
request.

Fixes: 5afcf9c045 ('cli: add 'general reload' command')
2021-05-03 22:22:01 +02:00
Beniamino Galvani
126ee6a1e8 libnm-glib-aux: add nm_dbus_call()
Add nm_dbus_call() to get a D-Bus connection and call a method
asynchronously.
2021-05-03 22:13:46 +02:00
Beniamino Galvani
43fc984989 man: document the 'nmcli general reload' command 2021-05-03 22:13:36 +02:00
Beniamino Galvani
fa1f628bce core: force emission of DNS_CONFIG_CHANGED signal on SIGUSR1
If the configuration contains dns=none and resolv.conf is updated
through a dispatcher script, currently there is no way to tell NM that
the content of resolv.conf changed, so that it can restart a hostname
resolution.

Use SIGUSR1 (and SIGHUP) for that.
2021-05-03 22:13:36 +02:00
Thomas Haller
caea7514cb
platform: cleanup ethtool calls in "nm-platform-utils.c"
- consistently check for success/failure of _ethtool_call_handle()
  with "< 0" / ">= 0".

- drop unnecessary memset(). In the past, I argued to add this because
  there were obscure cases with valgrind where this made a difference.
  As it's not clear when/how that is necessary, drop it again.
  Also, we want to prefer explicit struct initialization over memset(),
  so if memset() would be necessary, those places would be problematic
  as well.

- inline unnecessary helper functions. They had only one caller and
  only make the code more verbose.

- use _ethtool_call_once() instead of _ethtool_call_handle() at places
  where we use the handle only once. The handle and _ethtool_call_handle()
  are useful to cache and reuse the file descriptor and the interface
  name. If we only make one call with the handle, we can use
  _ethtool_call_once() instead.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/830
2021-05-03 13:57:07 +02:00
Thomas Haller
d800009552
libnm: add missing "---end---" tag for ifcfg-rh's "dhcp-hostname-flags" doc
This missing tag confuses the parser and it results in an error in
`man nm-settings-ifcfg-rh`.
2021-05-03 10:41:13 +02:00
Thomas Haller
14ca8962fd
nmcli: merge branch 'th/nmcli-gsm-fixes'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/827
2021-05-03 10:39:53 +02:00
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