Commit graph

28559 commits

Author SHA1 Message Date
Beniamino Galvani
e29d2f2200 NEWS: update 2021-06-16 15:30:02 +02:00
Beniamino Galvani
0cd20f94d0 firewall: fix double free
Fixes: 9ebdb967de ('firewall: implement masquerading for shared mode with nftables')
2021-06-15 19:40:59 +02:00
Thomas Haller
05f2a0b024
libnm: expose nm_ip_address_dup(), nm_ip_route_dup() API in libnm
This fixes commit 21c8a6b20e ('libnm-core, all: merge IPv4 and IPv6
address/route types'), which introduced this API but didn't export it
in the library. In practice this API is thus only usable since 1.32.0.
2021-06-15 19:11:57 +02:00
Thomas Haller
654bb92a69
firewall: use nm_g_main_context_push_thread_default_if_necessary() in _fw_nft_call_communicate_cb()
There is no need to push (and pop) the same main-context.
2021-06-15 18:25:22 +02:00
Thomas Haller
897c6a5744
firewall: fix signalling timeout error reason from _fw_nft_call()
During timeout we cancel the (internal) GCancellable. But the overall
error reason is not cancellation by the user, it's timeout. Fix
the error reason.

Fixes: 9ebdb967de ('firewall: implement masquerading for shared mode with nftables')
2021-06-15 18:15:56 +02:00
Thomas Haller
b8ae2dfa70
core/trivial: add comment about GMainContext to nm_shutdown_wait_obj_register_full() 2021-06-15 18:15:56 +02:00
Thomas Haller
79d9441567
firewall: change default for firewall-backend to "nftables""
It seems that the nftables backend works well. Let's change the default.
This will also be backported to nm-1-32 branch, for 1.32.0 release.

This reverts commit 0609f1f31c.
2021-06-14 11:17:25 +02:00
Thomas Haller
be4b997e4f
examples: add "examples/python/gi/nm-up-many.py"
It's an example for how to use libnm and asynchronous API.
But it's also a script I will use to test activating many
profiles in parallel.

Also add a test script that creates many veth interfaces and connection
profiles. So now you can do:

   sudo NUM_DEVS=100 contrib/scripts/test-create-many-device-setup.sh setup
   ./examples/python/gi/nm-up-many.py c-a{1..100}

and cleanup with

   nmcli connection down c-a{1..100}
   sudo contrib/scripts/test-create-many-device-setup.sh cleanup

Of course, be careful to do this on your production machine.
2021-06-11 22:48:41 +02:00
Thomas Haller
c47ad0f754
all: merge branch 'th/coverity-fixes'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/883
2021-06-11 22:44:08 +02:00
Thomas Haller
14ec96f262
libnm/tests: avoid coverity warning in test_setting_connection_secondaries_verify()
nm_strvarray_get_strv() returns the input pointer itself, if _secondaries is NULL.
It does so intentionally and correctly to create an artificial empty strv array.

Coverity doesn't like this. Try to workaround the warning:

    Error: ARRAY_VS_SINGLETON (CWE-119): [#def484]
    NetworkManager-1.31.90/src/libnm-core-impl/tests/test-setting.c:4544: address_of: Taking address with "&_secondaries" yields a singleton pointer.
    NetworkManager-1.31.90/src/libnm-core-impl/tests/test-setting.c:4544: identity_transfer: Passing "&_secondaries" as argument 1 to function "nm_strvarray_get_strv", which returns that argument.
    NetworkManager-1.31.90/src/libnm-core-impl/tests/test-setting.c:4544: callee_ptr_arith: Passing "_Generic (nm_strvarray_get_strv(&_secondaries, NULL), char const * const * : (char const * const *)nm_strvarray_get_strv(&_secondaries, NULL), char const ** : (char const * const *)nm_strvarray_get_strv(&_secondaries, NULL), char * const * : (char const * const *)nm_strvarray_get_strv(&_secondaries, NULL), char ** : (char const * const *)nm_strvarray_get_strv(&_secondaries, NULL), void const * : (char const * const *)nm_strvarray_get_strv(&_secondaries, NULL), void * : (char const * const *)nm_strvarray_get_strv(&_secondaries, NULL), char const * const * const : (char const * const *)nm_strvarray_get_strv(&_secondaries, NULL), char const ** const : (char const * const *)nm_strvarray_get_strv(&_secondaries, NULL), char * const * const : (char const * const *)nm_strvarray_get_strv(&_secondaries, NULL), char ** const : (char const * const *)nm_strvarray_get_strv(&_secondaries, NULL), void const * const : (char const * const *)nm_strvarray_get_strv(&_secondaries, NULL), void * const : (char const * const *)nm_strvarray_get_strv(&_secondaries, NULL))" to function "_nm_utils_strv_cmp_n" which uses it as an array. This might corrupt or misinterpret adjacent memory locations.
    # 4542|       G_STMT_END
    # 4543|
    # 4544|->         _assert_secondaries(s_con, (const char *const *) arr->pdata);
    # 4545|
    # 4546|           /* reimplement the normalization that we expect to happen and
2021-06-11 22:42:45 +02:00
Thomas Haller
627503ad86
cli: avoid coverity warning in do_connection_down()
Error: USE_AFTER_FREE (CWE-416): [#def729] [important]
    NetworkManager-1.31.90/src/nmcli/connections.c:3288: freed_arg: "connection_cb_info_finish" frees "info".
    NetworkManager-1.31.90/src/nmcli/connections.c:3287: pass_freed_arg: Passing freed pointer "info" as an argument to "g_signal_handlers_disconnect_matched".
    # 3285|
    # 3286|               if (info) {
    # 3287|->                 g_signal_handlers_disconnect_by_func(active, down_active_connection_state_cb, info);
    # 3288|                   connection_cb_info_finish(info, active);
    # 3289|               }
2021-06-11 22:42:45 +02:00
Thomas Haller
7825609f1f
glib-aux/tests: avoid coverity warning in test_nm_g_source_sentinel()
Coverity wrongly think there is a use after free in the test:

    Error: USE_AFTER_FREE (CWE-416): [#def559] [important]
    NetworkManager-1.31.90/src/libnm-glib-aux/tests/test-shared-general.c:1305: alias: Assigning: "s1" = "_s". Now both point to the same storage.
    NetworkManager-1.31.90/src/libnm-glib-aux/tests/test-shared-general.c:1324: freed_arg: "g_source_unref" frees "s1".
    NetworkManager-1.31.90/src/libnm-glib-aux/tests/test-shared-general.c:1330: deref_after_free: Dereferencing freed pointer "s1".
    # 1328|               s2 = nm_g_source_sentinel_get(0);
    # 1329|               g_assert(s2 == s1);
    # 1330|->             g_assert_cmpint(g_atomic_int_get(&s1->ref_count), >=, 1);
    # 1331|           }
    # 1332|       }

Rework the code in the hope to avoid the false warning.
2021-06-11 22:42:44 +02:00
Thomas Haller
c87433ebd2
platform: avoid wrong coverity warning in nmp_utils_sysctl_open_netdir()
The warning is wrong, because we already assert for the string length a few
lines earlier.

  Error: STRING_OVERFLOW (CWE-120): [#def595]
  NetworkManager-1.31.90/src/libnm-platform/nm-platform-utils.c:1896: fixed_size_dest: You might overrun the 16-character fixed-size string "ifname_buf_last_try" by copying "ifname" without checking the length.
  # 1894|           if (nm_streq(ifname, ifname_buf_last_try))
  # 1895|               return -1;
  # 1896|->         strcpy(ifname_buf_last_try, ifname);
  # 1897|
  # 1898|           fd_dir = open(sysdir, O_DIRECTORY | O_CLOEXEC);
2021-06-11 22:42:44 +02:00
Thomas Haller
b57167fe74
libnm: merge branch 'th/libnm-core-hide-structs'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/888
2021-06-11 22:35:35 +02:00
Thomas Haller
0206642ec3
NEWS: update 2021-06-11 22:32:25 +02:00
Thomas Haller
860b280248
libnm: hide NMSimpleConnection type from public headers 2021-06-11 22:32:24 +02:00
Thomas Haller
e46d484fae
libnm: hide NMSetting types from public headers
When subclassing a GObject type, the class and object structs
must be available and defined in the header.

For libnm, and in particular for NMSetting classes, we don't want
users to subclass NMSetting. It also doesn't work, because libnm
has internal code that is necessary to hook up the NMSetting class.
You cannot define your own type and make it work together with
libnm.

Having the structs in public headers limits what we can do with them.
For example, we could embed the private data directly in the structures
and avoid the additional indirection.

This is an API break, but for something that most likely nobody cares
about. Or better, nobody should care about. API is not what is
accidentally defined in a header, API was the library provides to
meaningfully use. Subclassing these types is not meaningful and was
only accidentally possible so far.

Only hide the structs for now. More cleanup is possible later. We shall
however aim to keep the padding and struct layout to not also break ABI.
2021-06-11 22:32:24 +02:00
Thomas Haller
0d6c35a6d9
core: avoid accessing opaque NMSetting type
Next, NMSetting will be hidden from public headers and become an opaque type.
We cannot do typeof(*setting) anymore.
2021-06-11 22:32:12 +02:00
Beniamino Galvani
c89ac8f0c7 device: remove unused variable
Fixes: 620fbb7894 ('device: use nm_device_resolve_address()')
2021-06-11 21:58:02 +02:00
Beniamino Galvani
a68b63a859 merge: branch 'bg/resolve-helper'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/877
2021-06-11 21:44:38 +02:00
Beniamino Galvani
620fbb7894 device: use nm_device_resolve_address() 2021-06-11 21:43:12 +02:00
Beniamino Galvani
27eae4043b device: add a nm_device_resolve_address()
The new function resolve an address via DNS, first by using
systemd-resolved (disabling synthesized results) and then by spawning
the daemon helper.

Trying systemd-resolved via D-Bus before spawning the helper is
important to get a correct result. Suppose that resolv.conf points to
the local stub listener at 127.0.0.53; if NM only spawns the helper,
the helper will query the local systemd-resolved which could return a
synthesized result.

Therefore, we first query systemd-resolved with NO_SYNTHESIZE and
then, in case of error, we spawn the helper.
2021-06-11 21:43:12 +02:00
Beniamino Galvani
7285bc56a9 dns: add function to retrieve the systemd-resolved plugin instance
Now that we have nm_dns_systemd_resolved_resolve_address(), we also
need a way to obtain a reference to the plugin.
2021-06-11 21:43:12 +02:00
Beniamino Galvani
648b0848f1 nm-daemon-helper: implement 'resolve-address' operation
Implement a new operation to resolve the hostname from an
address. Note the call to __nss_configure_lookup("hosts", "dns"): this
configures the glibc Name Service Switch (NSS) to only use DNS,
bypassing other modules that might be configured in
/etc/nsswitch.conf. Other modules like 'myhostname' or 'resolve' can
return synthesized names, while we are only interested in real DNS
results.
2021-06-11 21:43:12 +02:00
Beniamino Galvani
6ac21ba916 core: add infrastructure for spawning a helper process 2021-06-11 21:43:12 +02:00
Beniamino Galvani
326dde6d53 core,nm-dispatcher: use nm_utils_get_process_exit_status_desc() 2021-06-11 21:43:11 +02:00
Beniamino Galvani
517852dccd libnm-glib-aux: add nm_utils_get_process_exit_status_desc() 2021-06-11 21:43:11 +02:00
Beniamino Galvani
9e69d921c1 dns/resolved: fix memory leak
'v_name' must be freed. Pass ownership to the result element.

Fixes: e7b76f6757 ('dns/resolved: add API for ResolveAddress call')
2021-06-11 21:43:11 +02:00
Thomas Haller
5ccc5e10b9 shared: add nm_ip_addr_init() helper 2021-06-11 21:43:11 +02:00
Thomas Haller
39d71ee356
contrib: update NM-log script to highlight "enslaving to master" messages 2021-06-11 10:54:15 +02:00
Andrew Zaborowski
35a1d89a96
iwd: Don't add connection.interface-name by default
This setting can't be handled IWD (e.g. during autoactivations performed
by IWD) and although for manual activations NM will probably check it,
there's no reason for the IWD backend to restrict new profiles to one
interface plus when running IWD the udev permanent interface naming is
likely to be broken.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/886
2021-06-10 23:30:11 +02:00
Simon McVittie
18c76388f0
libnm: Don't crash if service tells us a new key management mode
The NetworkManager service sometimes adds new key management modes.
If it does, an older client library (perhaps in a container, or loaded
into a pre-existing process before an upgrade) shouldn't crash when
talking to a newer NetworkManager service over D-Bus.

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

Signed-off-by: Simon McVittie <smcv@collabora.com>

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/887
2021-06-10 23:16:59 +02:00
Thomas Haller
7d063726c2
libnm/tests: fix compilation error with old gcc not supporting __auto_type
Fixes: 23adeed244 ('glib-aux: use NM_VA_ARGS_FOREACH() to implement NM_HASH_COMBINE_BOOLS()')
2021-06-10 13:28:15 +02:00
Thomas Haller
17be7ea72e
glib-aux: mark result of nm_g_slice_free_fcn() as warn_unused_result
It's tempting to mix up

    nm_g_slice_free(arg)

with

    nm_g_slice_free_fcn(arg)

Use __attribute((__warn_unused_result__)) to catch such bugs.
2021-06-10 11:08:58 +02:00
Thomas Haller
5abf61f53a
glib-aux: fix formatting for _nm_g_slice_free_fcn_define() by adding semicolon 2021-06-10 11:08:57 +02:00
Thomas Haller
ae14caf05d
std-aux: add NM_ENSURE_IS_TYPE() macro 2021-06-10 11:08:57 +02:00
Thomas Haller
cf1b7d43df
std-aux: add _nm_warn_unused_result define 2021-06-10 10:36:58 +02:00
Thomas Haller
01df4a5ad0
supplicant: fix leaking handle in nm_supplicant_manager_create_interface()
Found by valgrind.

Fixes: b83f07916a ('supplicant: large rework of wpa_supplicant handling')
2021-06-10 10:36:58 +02:00
Thomas Haller
6813a4fe75
bluez: fix leak of private data "conn_data_elems" in NMBluezManager
Found by valgrind.

Fixes: 4154d9618c ('bluetooth: refactor BlueZ handling and let NMBluezManager cache ObjectManager data')
2021-06-10 10:36:58 +02:00
Thomas Haller
85c6ab97ef
tools: add debug printf statements to "tools/generate-docs-nm-settings-docs-merge.py"
It's hard to understand what "tools/generate-docs-nm-settings-docs-merge.py"
does. Add dbg() statements that are all NOP by default. But the user can
easily patch the code to print what is happening. This is only for
debugging the script.
2021-06-09 12:46:32 +02:00
Thomas Haller
e831a67cbc
contrib/rpm: configure defaults for iptables/nftables when generating distribution tarball 2021-06-08 17:40:17 +02:00
Sibo Dong
5c1181c6f3
bash-completion: localize the prev variable
The prev variable is not localzed in the nmcli Bash completion script,
which calls _init_completion.

Even though prev does not appear in the completion script, it should
still be localized. This variable may otherwise appear in the user's
environment and clobber a user-defined variable of the same name, which
is bad.

Localize the prev variable.

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

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/882
2021-06-08 11:37:03 +02:00
Thomas Haller
9662f24995
all: merge branch 'th/va-args-join'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/881
2021-06-08 08:24:36 +02:00
Thomas Haller
07002f7320
core: remove _nul_sentinel from UuidData struct
The user really must not treat UuidData.bin as a NUL terminated string.
The _nul_sentinel is not necessary. And if by chance the user makes this
fatal mistake, then UuidData.str will still be there to NUL terminate the
buffer, the content is garbage either way.

Remove the sentinel.
2021-06-08 08:24:14 +02:00
Thomas Haller
2b2c818e03
glib-aux/uuid: use NMUuid typed argument for nm_uuid_generate_from_string*()
nm_uuid_generate_from_string*() accepts an optional namespace parameter,
to seed the hashing. This previously was a UUID in string format, so it
first had to be parsed.

Rework the code to pass a NMUuid instance that can be used directly.
Also, as the type_args parameter is always of the same type, change
the argument from a void pointer to "const NMUuid *" pointer.
2021-06-08 08:24:14 +02:00
Thomas Haller
10e5f10f9d
glib-aux/uuid: add NM_UUID_INIT() macro 2021-06-08 08:24:13 +02:00
Thomas Haller
23adeed244
glib-aux: use NM_VA_ARGS_FOREACH() to implement NM_HASH_COMBINE_BOOLS() 2021-06-08 08:24:12 +02:00
Thomas Haller
b7ade9e20d
glib-aux: use NM_VA_ARGS_FOREACH() to implement NM_HASH_COMBINE_VALS() 2021-06-08 08:24:12 +02:00
Thomas Haller
1ccfde7ee6
libnm/tests: add test for NM_NARG() with 120 parameters 2021-06-08 08:24:11 +02:00
Thomas Haller
f98d47f77d
glib-aux: implement varidic macros NM_UTILS_{LOOKUP,ENUM2STR}_DEFINE() with NM_VA_ARGS_JOIN()
The previous implementation of these macros simply relied on the
__VA_ARGS__ to be expended and joined with ','. That make that work
inside the switch statement, the macros expanded to

   switch (val) {
       (void) 0, (void) 0;
   case 0x1:
       s = " ""value" "";
       break;
       (void) 0, (void) 0;
   };

Those NOP statements cause lgtm.com to complain "Dead code due to goto
or break statement".

Implement these macros differently using NM_VA_ARGS_JOIN().
2021-06-08 08:24:11 +02:00