Commit graph

15036 commits

Author SHA1 Message Date
Thomas Haller
419be57dbc
libnm: support direct string properties as NMRefString
Several properties like "connection.type" are enum-like and only take a few
known values. We can use a NMRefString to share their instances.

Currently nm_setting_duplicate() does not yet explicitly handle direct properties.
But it should, because it can handle them more efficiently. If it would do that, it
would be very cheap to "copy" a NMRefString. But even with the current implementation
will the result be deduplicated.
2022-01-18 16:22:38 +01:00
Thomas Haller
3b803a9d70
glib-aux: add nmtst_ref_string_find() helper
This is only for unit testing (hence the "nmtst" prefix)
to check whether a ref-string is/isn't interned.
2022-01-18 16:22:36 +01:00
Thomas Haller
28018d6985
glib-aux: add nm_ref_string_reset_str_upcast() helper 2022-01-18 16:22:34 +01:00
Thomas Haller
39c308f370
libnm: cleanup redundant code for direct properties of NMSetting 2022-01-18 16:22:32 +01:00
Thomas Haller
1d4a80cf7f
libnm: refactor some NMSetting to use direct properties for int64 2022-01-18 16:22:30 +01:00
Thomas Haller
72e523830c
libnm: refactor some NMSetting to use direct properties for string 2022-01-18 16:22:28 +01:00
Thomas Haller
aea47ed206
libnm: implement "wireguard.private-key" as direct string property
"wireguard.private-key" is special, because the setter does some unusual
normalization. To implement that, we need to use "direct_hook.set_string_func".
2022-01-18 16:22:27 +01:00
Thomas Haller
20d6793065
libnm: refactor some NMSetting to use direct properties for uint32 2022-01-18 16:22:25 +01:00
Thomas Haller
208df83491
libnm: refactor some NMSetting to use direct properties for int32 2022-01-18 16:22:24 +01:00
Thomas Haller
822042d9f9
libnm: add hook for setting direct string property
We want that our properties have little special cases and follow a
few common behaviors. For example, we have string properties, and those
should mostly behave the same (e.g. by being "direct-string"
properties).

That is already not fully enough, because we have slightly different
behaviors. For example, we have string properties that should have their
whitespace stripped, that should be ascii case down converted, that
should be normalized IP or MAC addresses. So far, that was expressed via
simple fields in NMSettInfoProperty, like NMSettInfoProperty's
direct_set_string_ascii_strdown field.

But that is not enough. In particular, for "wireguard.private-key" we
perform a different kind of normalization (base64 parsing, and taking
care not to leak secret in memory). It seems to special to add a boolean
flag "direct_set_string_wireguard_private_key".

Instead, add a hook that can cover that.

We need a hook, because we want one setter implementation throughout. Commonly,
we have at least two setters: the GObject set_property() and from D-Bus.
Both should call into the same underlying implementation, to avoid code
duplication. For that, the tweaked behavior must be "down", that is at
the deepest point in the call stack where we set the string. That's why
we need the hook. The alternative would be two special implementation
for GObject and D-Bus setters (and in the future we might add setters
from keyfile).
2022-01-18 16:22:22 +01:00
Thomas Haller
46f0bc4e70
libnm: pass more parameters to _property_direct_set_string() in NMSetting
Both callers themselves needed to call _nm_setting_get_private(),
only to pass it to _property_direct_set_string().

Instead, pass the necessary parameters to _property_direct_set_string(),
so it can do that itself.

This additional parameters will be necessary when we add a hook for
setting the string.
2022-01-18 16:22:21 +01:00
Thomas Haller
99d898cf1f
libnm: rework caching of virtual-iface-name for infiniband setting
We cache the virtual-iface-name. The caching is also part of the API as
nm_setting_infiniband_get_virtual_interface_name() returns a const
string.

As the value is computed and based on the parent and the p-key, we must
clear the cache when the parent or p-key changes (or detect that it's
invalid).

Previously, we were simply clearing the value in the set_property() function,
which is the only setter of these two properties. If we make these
properties "direct properties", then they will be directly set via
from_dbus_fcn() which bypasses the GObject setter. Which is a problem
for the cache invalidation.

We could either not make those properties direct properties. The problem
is that direct properties are nice, and they will in the future
implement further optimizations for them. Also, they are the default
implementation, and it seems clearer to build something on top of that,
instead of deviating from the default.

Instead, let the caching detect when the value needs to be regenerated.
2022-01-18 16:22:20 +01:00
Thomas Haller
1ed46739c0
libnm: drop unused property implementation for DOUBLE type
We don't have a property of type double, that would need this.
2022-01-18 16:22:19 +01:00
Thomas Haller
710c54760c
libnm: add direct property type "int64" 2022-01-18 16:22:18 +01:00
Thomas Haller
5e7400c832
libnm: add flag to map zero to NULL in _nm_utils_ipaddr_canonical_or_invalid()
This seems a questionable thing to do, and should be made clearer by
having a parameter (that makes you think about what is happening here).

Also, the normalization for vxlan.remote does not perform this mapping,
so the parameter is there so that the approach can handle both flavors.
2022-01-18 16:22:17 +01:00
Thomas Haller
1f58244268
libnm: let direct string property support AF_UNSPEC for normalizing IP addresses 2022-01-18 16:22:16 +01:00
Thomas Haller
adf7a742b4
libnm: support AF_UNSPEC in _nm_utils_ipaddr_canonical_or_invalid() 2022-01-18 16:22:15 +01:00
Thomas Haller
16bf47f8ca
libnm: automatically clear secret string for direct string properties
Let's sprinkle some snake ointment.

This is questionable, because we copy secrets all over the place where
we their deallocation (and clearing) is not in our control. For example,
the GValue setter/getter copies the string (but does not clean the
secret). Also, when converting the property to a GVariant, we won't
clear it. So this does not catch a lot of cases.

Still, if we can with relative ease avoid leaking the string at some
places, do it.
2022-01-18 16:22:15 +01:00
Thomas Haller
171287d94b
libnm: implement gsm.apn as direct string property 2022-01-18 16:22:14 +01:00
Thomas Haller
360d5f0998
libnm: add direct_set_string_strip flag for direct string property 2022-01-18 16:22:13 +01:00
Thomas Haller
2b6f166cdf
libnm: drop unused g_type_class_add_private() from NMSettingVeth
Fixes: cd0cf9229d ('veth: add support to configure veth interfaces')
2022-01-18 16:22:13 +01:00
Thomas Haller
91653ea784
libnm: make caching of encodings in nm_utils_ssid_to_utf8() thread safe
libnm's data structures are commonly not thread safe (like
NMConnection). However, it must be possible that all operations can
operate on *different* data in a thread safe manner. That means, we need
to take care about our global variables.

nm_utils_ssid_to_utf8() uses a list of encodings, which gets cached.

- replace the GHashTables with a static list. Since it doesn't cost
  anything, make the list sorted and look it up via binary search.
2022-01-18 16:22:12 +01:00
Thomas Haller
a5f7f89b04
dhcp: use NM_STR_HAS_PREFIX() instead of strncmp() 2022-01-18 16:22:12 +01:00
Thomas Haller
09a266e87d
glib-aux: add NM_G_PARAM_SPEC_CAST_INT64() helper 2022-01-18 16:22:12 +01:00
Thomas Haller
9a8c23879a
all: don't use strlen() to check whether string is empty/non-empty 2022-01-18 16:22:12 +01:00
Thomas Haller
fa87ef6cd3
glib-aux: add nm_strstrip_dup() helper 2022-01-18 16:22:11 +01:00
Thomas Haller
3378ec1236
glib-aux: add nm_strdup_reset_secret() helper 2022-01-18 16:22:11 +01:00
Thomas Haller
f924b4382e
glib-aux/tests: add nmtst_assert_strv() helper macro 2022-01-18 16:22:11 +01:00
Thomas Haller
c810fe24fe
glib-aux: define nm_direct_hash/nm_str_hash as macros
nm_hash_str() has the proper name and signature for that it does.
That is, it has a "nm_hash_*" prefix and the parameter is of type
"const char *".
nm_hash_str() has this name because it is primarily about hashing.

For hash tables, glib has g_str_hash() and g_str_equal(). We want
to replace g_str_hash() with our implementation (nm_hash_str()) because
that uses siphash24 with a random seed.
But in those cases we want to use the more familiar name "nm_str_hash()",
which reminds of g_str_hash() and follows the pattern of g_str_equal().
Thus:

  g_hash_table_new(nm_str_hash, g_str_equal);

is preferable over

  g_hash_table_new(nm_hash_str, g_str_equal);

Hence, we have (and had) nm_str_hash() effectively an alias to
nm_hash_str.

The question is: which name is preferable? Or should they be both present
for their slightly distinct uses? The approach taken here is to have
both names, to reflect their purpose better.

But as the usage of nm_str_hash is as function pointer for GHashTable, it was
not an inline function and we'd pay a small overhead with this approach of
aliasing. Avoid that overhead by defining nm_str_hash with the C
preprocessor.

For similar reasons, do that for nm_direct_hash.
2022-01-18 14:36:31 +01:00
Thomas Haller
b8392757ec
platform/readme: detail problem about IPv6 multihop routes 2022-01-18 12:00:02 +01:00
Thomas Haller
c60988ca6c
glib-aux: use atomic operation in _nm_assert_on_main_thread() instead of taking GMutex
In basically all cases, we can use an atomic operation to get the
cached TID. The lock we only need to initialize/invalidate the cached
value.
2022-01-17 13:46:55 +01:00
Thomas Haller
bcce368e55
clang-format: mark FOR_EACH_DELAYED_ACTION() as a ForEachMacro 2022-01-13 15:25:17 +01:00
Beniamino Galvani
ae28d2251a core: set force-commit flag for generated routes
The force-commit flag is used to force the commit of an address or a
route from DHCP/RA even when it was removed from platform externally
(for example because it expired). Routes generated from the l3cd
should also have the flag set.

Without this, NM properly re-adds the DHCP address after the lease is
lost and obtained again, but fails to add the prefix-route.

Fixes: 2838b1c5e8 ('core: track force-commit flag for l3cd and platform objects')

https://bugzilla.redhat.com/show_bug.cgi?id=2033991
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1049
2022-01-12 15:01:42 +01:00
Lubomir Rintel
3e12c6ff81 ipv4ll: fix assert on external LL address removal
Consider externally removed IPv4LL bad, proceed as if a collision was
detected. Otherwise we trip an assert:

  <trace> [1641816260.3963] l3cfg[b8bf8cd16ec4732e,ifindex=47]: emit signal (platform-change-on-idle, obj-type-flags=0x14)
  **
  nm:ERROR:src/core/nm-l3-ipv4ll.c:888:_ipv4ll_state_change: code should not be reached
  Aborted (core dumped)

  #3  0x00007f41621d020e in g_assertion_message_expr (domain=domain@entry=0x5559cd829140 "nm",
      file=file@entry=0x5559cd823e51 "src/core/nm-l3-ipv4ll.c",
      line=line@entry=888, func=func@entry=0x5559cd824d30 <__func__.38810> "_ipv4ll_state_change",
      expr=expr@entry=0x0) at gtestutils.c:2556
  #4  0x00005559cd719686 in _ipv4ll_state_change (self=0x5559cef886c0,
      is_on_idle_handler=0) at src/core/nm-l3-ipv4ll.c:888
  #8  0x00007f41626a5093 in <emit signal ??? on instance 0x5559ceffaa30 [NML3Cfg]>
      (instance=instance@entry=0x5559ceffaa30, signal_id=<optimized out>,
       detail=detail@entry=0) at gsignal.c:3448
  #9  0x00005559cd511a03 in _nm_l3cfg_emit_signal_notify
      (self=self@entry=0x5559ceffaa30 [NML3Cfg], notify_data=notify_data@entry=0x7ffd1caa8640)
      at src/core/nm-l3cfg.c:576
  #10 0x00005559cd5122dc in _nm_l3cfg_emit_signal_notify_acd_event (self=0x5559ceffaa30 [NML3Cfg],
      acd_data=<optimized out>) at src/core/nm-l3cfg.c:2008
  #11 0x00005559cd512463 in _nm_l3cfg_emit_signal_notify_acd_event_all
      (self=0x5559ceffaa30 [NML3Cfg]) at src/core/nm-l3cfg.c:2041
  #12 0x00005559cd5194ef in _l3_acd_nacd_event (fd=<optimized out>, condition=<optimized out>,
      user_data=<optimized out>) at src/core/nm-l3cfg.c:1536
  #13 0x00007f41621a895d in g_main_dispatch (context=0x5559ceec8bc0) at gmain.c:3193
  #14 0x00007f41621a895d in g_main_context_dispatch (context=context@entry=0x5559ceec8bc0)
      at gmain.c:3873
  #15 0x00007f41621a8d18 in g_main_context_iterate (context=0x5559ceec8bc0, block=block@entry=1,
      dispatch=dispatch@entry=1, self=<optimized out>) at gmain.c:3946
  #16 0x00007f41621a9042 in g_main_loop_run (loop=0x5559ceea40f0) at gmain.c:4142
  #17 0x00005559cd47c7a4 in main (argc=<optimized out>, argv=<optimized out>)
      at src/core/main.c:511

https://bugzilla.redhat.com/show_bug.cgi?id=2028404
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1059
2022-01-12 14:58:29 +01:00
Thomas Haller
56a051de56
platform: log when blocking poll() returns for reading netlink socket
Try to debug a hang in platform code, presumably during poll().
This logging seems useful for debugging this particular issue,
but it might be useful in general.
2022-01-12 13:34:44 +01:00
Thomas Haller
ba9b199cfd
platform: clamp timestamp in event_handler_read_netlink() 2022-01-12 13:34:44 +01:00
Thomas Haller
a79efac2fe
platform/trivial: rename "now_ns" to "now_nsec"
I was already doing such renaming at various places. Let's be consistent
and clear. It was (slightly) confusing was "ns" means.
2022-01-12 13:34:44 +01:00
Thomas Haller
abf39ed046
platform: log wait time in event_handler_read_netlink() 2022-01-12 13:34:43 +01:00
Thomas Haller
65cdbd355f
platform: fix type for timestamp in delayed_action_wait_for_nl_response_complete_check()
Fixes: d074ffc836 ('platform: refactor completing netlink responses in event_handler_read_netlink()')
2022-01-12 13:34:39 +01:00
Beniamino Galvani
d68ab6b8f0 nm-sudo: rename to nm-priv-helper
The name "nm-sudo" reminds of the "sudo" tool, and this is a bit
confusing because it's not related. Rename the service to
"nm-priv-helper", which stands for "NM privileged helper".

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/938
2022-01-11 21:46:55 +01:00
Beniamino Galvani
9f3d2a09ea supplicant: enable SAE-H2E
H2E (hash to element) is a newer method for generating the PWE
(password element) for SAE, alternative to the existing
"hunting-and-pecking". It is considered more secure and it is
mandatory for the WPA3 certification; also, SAE in the 6GHz band can
only use H2E (hunting-and-pecking is disallowed).

Enable H2E in addition to hunting-and-pecking.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/753
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1045
2022-01-11 21:39:04 +01:00
Lubomir Rintel
5f0ddaa610 Revert "nm-device: avoid starting ac6 if l3cfg is not there"
This reverts commit bb0a31e6eb.

This was pushed by accident.
2022-01-11 14:57:48 +01:00
Lubomir Rintel
fccb5608f3 nm-device: clean up IP methods if we lose ifindex
If the ovs interface goes away, the ifindex gets zeroed out and l3cfg is
cleaned. We can't follow up with IP configuration. Bad things happen if
we try to:

  #0  0x00007f769734c895 in _g_log_abort (breakpoint=1) at gmessages.c:580
  #1  0x00007f769734db98 in g_logv (log_domain=0x55b2472d8840 "nm",
        log_level=G_LOG_LEVEL_CRITICAL, format=<optimized out>,
        args=args@entry=0x7fff4041b9d0) at gmessages.c:1391
  #2  0x00007f769734dd63 in g_log (log_domain=log_domain@entry=0x55b2472d8840 "nm",
        log_level=log_level@entry=G_LOG_LEVEL_CRITICAL,
        format=format@entry=0x7f769739a620 "%s: assertion '%s' failed") at gmessages.c:1432
  #3  0x00007f769734e59d in g_return_if_fail_warning
      (log_domain=log_domain@entry=0x55b2472d8840 "nm",
        pretty_function=pretty_function@entry=0x55b2472d5fe0 <__func__.39677> "nm_lndp_ndisc_new",
        expression=expression@entry=0x55b2472d5fa3 "NM_IS_L3CFG(config->l3cfg)")
        at gmessages.c:2809
  #4  0x000055b2471ce3fa in nm_lndp_ndisc_new (config=config@entry=0x7fff4041bb30)
        at src/core/ndisc/nm-lndp-ndisc.c:680
  #5  0x000055b247123b32 in _dev_ipac6_start (self=self@entry=0x55b248078360 [NMDeviceOvsInterface])
        at src/core/devices/nm-device.c:11287
  #6  0x000055b2471232f8 in _dev_ipac6_start_continue (self=0x55b248078360 [NMDeviceOvsInterface])
        at src/core/devices/nm-device.c:11338
  #7  0x000055b2471232f8 in _dev_ipll6_set_llstate (self=0x55b248078360 [NMDeviceOvsInterface],
        llstate=<optimized out>, lladdr=<optimized out>) at src/core/devices/nm-device.c:10541
  #8  0x000055b2471c9e8b in _emit_changed_on_idle_cb (user_data=user_data@entry=0x55b24807bdd0)
        at src/core/nm-l3-ipv6ll.c:221
  #9  0x00007f769734327b in g_idle_dispatch (source=0x55b248119200,
        callback=0x55b2471c9ce0 <_emit_changed_on_idle_cb>,
        user_data=0x55b24807bdd0) at gmain.c:5579
  #10 0x00007f769734695d in g_main_dispatch (context=0x55b247f56bc0) at gmain.c:3193
  #11 0x00007f769734695d in g_main_context_dispatch (context=context@entry=0x55b247f56bc0)
        at gmain.c:3873
  #12 0x00007f7697346d18 in g_main_context_iterate (context=0x55b247f56bc0,
        block=block@entry=1, dispatch=dispatch@entry=1, self=<optimized out>) at gmain.c:3946
  #13 0x00007f7697347042 in g_main_loop_run (loop=0x55b247f320f0) at gmain.c:4142
  #14 0x000055b246f26b64 in main (argc=<optimized out>,
        argv=<optimized out>) at src/core/main.c:511

https://bugzilla.redhat.com/show_bug.cgi?id=2012934
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1044

Fixes-test: @ovs_cloned_mac_set_on_iface
2022-01-11 14:55:38 +01:00
Lubomir Rintel
bb0a31e6eb nm-device: avoid starting ac6 if l3cfg is not there
If the ovs interface goes away, the ifindex gets zeroed out and l3cfg is
cleaned. Avoid starting ac6 in that case -- add checks similar to what
we do for ll6.

Bad things happen otherwise:

  #0  0x00007f769734c895 in _g_log_abort (breakpoint=1) at gmessages.c:580
  #1  0x00007f769734db98 in g_logv (log_domain=0x55b2472d8840 "nm",
        log_level=G_LOG_LEVEL_CRITICAL, format=<optimized out>,
        args=args@entry=0x7fff4041b9d0) at gmessages.c:1391
  #2  0x00007f769734dd63 in g_log (log_domain=log_domain@entry=0x55b2472d8840 "nm",
        log_level=log_level@entry=G_LOG_LEVEL_CRITICAL,
        format=format@entry=0x7f769739a620 "%s: assertion '%s' failed") at gmessages.c:1432
  #3  0x00007f769734e59d in g_return_if_fail_warning
      (log_domain=log_domain@entry=0x55b2472d8840 "nm",
        pretty_function=pretty_function@entry=0x55b2472d5fe0 <__func__.39677> "nm_lndp_ndisc_new",
        expression=expression@entry=0x55b2472d5fa3 "NM_IS_L3CFG(config->l3cfg)")
        at gmessages.c:2809
  #4  0x000055b2471ce3fa in nm_lndp_ndisc_new (config=config@entry=0x7fff4041bb30)
        at src/core/ndisc/nm-lndp-ndisc.c:680
  #5  0x000055b247123b32 in _dev_ipac6_start (self=self@entry=0x55b248078360 [NMDeviceOvsInterface])
        at src/core/devices/nm-device.c:11287
  #6  0x000055b2471232f8 in _dev_ipac6_start_continue (self=0x55b248078360 [NMDeviceOvsInterface])
        at src/core/devices/nm-device.c:11338
  #7  0x000055b2471232f8 in _dev_ipll6_set_llstate (self=0x55b248078360 [NMDeviceOvsInterface],
        llstate=<optimized out>, lladdr=<optimized out>) at src/core/devices/nm-device.c:10541
  #8  0x000055b2471c9e8b in _emit_changed_on_idle_cb (user_data=user_data@entry=0x55b24807bdd0)
        at src/core/nm-l3-ipv6ll.c:221
  #9  0x00007f769734327b in g_idle_dispatch (source=0x55b248119200,
        callback=0x55b2471c9ce0 <_emit_changed_on_idle_cb>,
        user_data=0x55b24807bdd0) at gmain.c:5579
  #10 0x00007f769734695d in g_main_dispatch (context=0x55b247f56bc0) at gmain.c:3193
  #11 0x00007f769734695d in g_main_context_dispatch (context=context@entry=0x55b247f56bc0)
        at gmain.c:3873
  #12 0x00007f7697346d18 in g_main_context_iterate (context=0x55b247f56bc0,
        block=block@entry=1, dispatch=dispatch@entry=1, self=<optimized out>) at gmain.c:3946
  #13 0x00007f7697347042 in g_main_loop_run (loop=0x55b247f320f0) at gmain.c:4142
  #14 0x000055b246f26b64 in main (argc=<optimized out>,
        argv=<optimized out>) at src/core/main.c:511
2022-01-11 14:53:26 +01:00
Thomas Haller
d5f917e702
bluetooth: fix invalid assertion in NMBluezManager:dispose()
We need to first free "priv->bzobjs", which then will unlink all bzobjs
from the lists. The assert needs to go after.

https://bugzilla.redhat.com/show_bug.cgi?id=2028427

Fixes: 4154d9618c ('bluetooth: refactor BlueZ handling and let NMBluezManager cache ObjectManager data')
2022-01-11 10:10:35 +01:00
Ana Cabral
74c08c7084 openvswitch: Add ovs-dpdk n_rxq property
https://bugzilla.redhat.com/show_bug.cgi?id=2001563
2022-01-10 22:48:30 +00:00
Ana Cabral
29cf10ec24 version: add 1.36 macros 2022-01-10 22:48:30 +00:00
Ana Cabral
f0cb75f669 trivial: fix typos 2022-01-10 22:48:30 +00:00
Ana Cabral
d6395f7ee7 core/ovs: fix setting dpdk-devargs JSON to NULL
NMSettingOvsDpdk does not have a verify() implementation that would prevent
the devargs property from being NULL. We must thus anticipate and handle
a NULL value.

Fixes: ae4152120a ('ovs/ovsdb: add support for setting dpdk devargs option')
2022-01-10 22:48:30 +00:00
Thomas Haller
20eb6df215
core: simplify code in nm_dns_manager_set_hostname() 2022-01-10 20:43:18 +01:00