Commit graph

13300 commits

Author SHA1 Message Date
Beniamino Galvani
613f74b545 initrd: merge branch 'bg/initrd-mac-iface'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/632
2020-09-24 10:55:13 +02:00
Thomas Haller
7141537097
l3cfg/tests: add unit test for NML3Cfg 2020-09-24 09:44:04 +02:00
Thomas Haller
3695949151
l3cfg/device: drop NML3Cfg references from NMDevice for now
Adding NML3Cfg support is a large effort that is done in parallel.
While already parts of the code is merged, it is not actually used
yet. Remove the parts from NMDevice that interact with NML3Cfg
before we actually start using it.

The point is that we might want to do a release before switching
over to the new way. For that release, we should not have the unused
code in NMDevice.

This patch will later be restored and extended.
2020-09-24 09:44:03 +02:00
Thomas Haller
441de0f0f8
l3cfg: fix leaking l3_config_datas array in NML3Cfg
But also take a reference whenever we have any configurations
registered. Registering a configuration means to automatically
keep the instance alive.

Any user must take care to unregister again when it no longer requires
the configuration.
2020-09-24 09:44:02 +02:00
Thomas Haller
042112ea2d
l3cfg: various fixes for l3cfg 2020-09-24 09:44:01 +02:00
Thomas Haller
d627ec7075
platform/tests: add nmtstp_platform_ip_addresses_assert() test helper 2020-09-24 09:44:00 +02:00
Thomas Haller
9f91e0b26d
platform/tests: add nmtstp_platform_ip_address_find() test util 2020-09-24 09:43:59 +02:00
Thomas Haller
e232ce93d0
platform: add NM_PLATFORM_IP[46]_ADDRESS_INIT() helper macros 2020-09-24 09:43:58 +02:00
Thomas Haller
23a6965ce2
l3cfg: add nm_l3_config_data_log() function 2020-09-24 09:43:56 +02:00
Thomas Haller
7ff1beabdb
l3cfg: let l3cfg emit signal on idle handler for platform changes
Currently all NMDevice instance register to the platform change signals,
then if a signal for their IP ifindex appears, they schedule a task on
an idle handler. That is wasteful.

NML3Cfg already gets a notification on an idle handler and can just re-emit
it to the respective listeners.

With this, there is only one subscriber to the platform signals (NMNetns)
which then multiplexes the signals to the right NML3Cfg instances, and
further.
2020-09-24 09:43:55 +02:00
Thomas Haller
000ad171e3
l3cfg: add nm_l3cfg_has_commited_ipv6_pending_dad() function
This will be used for tracking IPv6 addresses that still have DAD pending.
Currently, NMDevice does it differently (see "dad6").
2020-09-24 09:43:55 +02:00
Thomas Haller
dbfb7fe2d7
l3cfg: add nm_l3_config_data_lookup_address_6() helper 2020-09-24 09:43:54 +02:00
Thomas Haller
62f2c5a879
platform: refactor nm_platform_ip6_address_get() function to accept pointer instead of "struct in6_addr"
While C is fine with accepting structs as function arguments,
we usually don't do that for IPv6 addresses. Accept a pointer
instead.
2020-09-24 09:43:54 +02:00
Thomas Haller
1215b6cc30
l3cfg: track both the commited and the currently merged l3cd instance
The caller may want to know the merge NML3ConfigData as it would be used
for the next commit, without already committing it.

Track both the NML3ConfigData instance that is merged from the
registered items, and the one that was used the last time during
commit.
2020-09-24 09:43:54 +02:00
Thomas Haller
79913fb446
l3cfg: allow %NULL argument for nm_l3_config_data_ref()
It's often convenient not to require the caller to check for
%NULL. On the other hand, there are cases where having a %NULL instance
is a bug, so gracefully accepting %NULL might hide bugs.

Still, change it.
2020-09-24 09:43:53 +02:00
Thomas Haller
dea59122e7
shared: move nm_utils_hwaddr_ntoa_buf() to shared/ as _nm_utils_hwaddr_ntoa()
The name is better as it mirrors nm_utils_hwaddr_aton(). Also, move
it to shared/ so it can be reused (and inlined).
2020-09-23 13:57:37 +02:00
Thomas Haller
dc3a477884
all/style: remove duplicate semicolon (";;") in sources 2020-09-23 12:43:47 +02:00
Beniamino Galvani
364c7c278a initrd: fix parsing IPv6 prefix length
The generator didn't accept prefix lengths > 32 for IPv6:

$ src/initrd/nm-initrd-generator --stdout -- ip=[fd01::1]:::40::ens0
 <warn>  [1600851580.7875] cmdline-reader: Invalid IP mask: 40

https://bugzilla.redhat.com/show_bug.cgi?id=1879795
2020-09-23 11:00:19 +02:00
Thomas Haller
b8811d97a4
all: require a semicolon after NM_CACHED_QUARK_FCN() 2020-09-23 10:55:17 +02:00
Beniamino Galvani
f223644291 initrd: accept mac address as interface specifier
The interface can be specified either by name or MAC address:

ip=192.0.2.2:::::eth0
ip=192.0.2.2:::::00-11-22-33-44-55

https://bugzilla.redhat.com/show_bug.cgi?id=1879795
2020-09-23 10:29:24 +02:00
Thomas Haller
e8dd19bb01
shared: extend nm_utils_hexstr2bin_full() to require hexdigits in pairs
nm_utils_hexstr2bin_full() is our general hexstr to binary parsing
method. It uses (either mandatory or optional) delimiters. Before,
if delimiters are in use, it would accept individual hexdigits.
E.g. "a:b" would be accepted as "0a:0b:.

Add an argument that prevents accepting such single digits.
2020-09-22 17:40:41 +02:00
Thomas Haller
5e84143378
core: assert that nm_dbus_utils_get_property() returns a variant of the expected type
g_dbus_gvalue_to_gvariant() doesn't check/assert that the value has the
right variant signature, if the value is already a GVariant.

Add an assertion.
2020-09-18 15:26:40 +02:00
Thomas Haller
51b7d351fa
core: fix D-Bus type for "org.freedesktop.NetworkManager.Capabilities" property
Fixes: 297d4985ab ('core/dbus: rework D-Bus implementation to use lower layer GDBusConnection API')
2020-09-18 15:26:39 +02:00
Thomas Haller
0a579fd16e
device: return same singleton variant for NM_DEVICE_IP4_ADDRESS property
All our devices will return the same value on D-Bus: a "u" variant with zero value.
Since NMDBusObject caches all the property values, we can share the instance.
2020-09-18 15:26:38 +02:00
Thomas Haller
72d6062cb0
device: break deprecated "Ip4Address" D-Bus property of Device interface
The "Ip4Address" property of "org.freedesktop.NetworkManager.Device"
interface is deprecated since version 0.9.9.1 (2013). Also, the property
is not exposed by libnm and generally not useful.

Drop the code to maintain it. The property still exists but always
returns 0 (0.0.0.0).
2020-09-18 15:26:21 +02:00
Thomas Haller
535fb95745
l3cd/ndisc: add nm_ndisc_data_to_l3cd() helper
NML3ConfigData is a simple container structure that contains no logic.
Also, DHCP code already is intimately related to NMIP[46]Config (for
now, later that will be NML3ConfigData).

It makes sense that NMNDisc is aware of NML3ConfigData and knows how to
conver the RA data into an l3cd instance.
2020-09-15 18:58:50 +02:00
Thomas Haller
d69b8ecd34
l3cfg: add nm_l3_config_data_clear_searches() API 2020-09-15 18:58:49 +02:00
Thomas Haller
b850cea874
l3cfg: add nm_l3_config_data_{get,set}_ip6_mtu() API 2020-09-15 18:07:24 +02:00
Thomas Haller
9802c89972
l3cfg: add nm_l3_config_data_{get,set}_ndisc_*() API 2020-09-15 17:45:35 +02:00
Thomas Haller
ef26ed3092
l3cfg: fix handling of mtu during nm_l3_config_data_merge()
Fixes: 25d404dadb ('l3cfg: add more API to NML3ConfigData')
2020-09-15 16:06:33 +02:00
Thomas Haller
81d7009956
l3cfg: track ip6_privacy (use_tempaddr) in NML3ConfigData
NMDevice currently configures use_tempaddr sysctl itself. Later,
NML3Cfg should do that, so we need to keep track of that as part
of the configuration.
2020-09-15 16:06:32 +02:00
Thomas Haller
be5f7ab7c9
device/ndisc: explicitly call nm_ndisc_stop() during addrconf6_cleanup() 2020-09-15 15:37:19 +02:00
Thomas Haller
6ce482c526
device/ndisc: add nm_ndisc_stop() method
It is bad style to rely on the last unref of an object for stopping
the operation. With a ref-counted object you should never rely on
anybody else still having (or not having) a reference. Hence, you
should not rely on stopping the ND during the last unref.

Add an explicit nm_ndisc_stop() function.
2020-09-15 15:36:19 +02:00
Thomas Haller
e8eaaa78d1
device/ndisc: let calling code determine the used RA timeout for NMNDisc
Previously, if we passed ra_timeout 0 to NMNDisc, then it would
calculate the effective timeout based on the router-solicitations
and the router-solicitation-interval.

The caller may want to know the used timeout, to also run its own timers
with the same timeout. Hence, it cannot leave this automatism internal
to NMNDisc.
2020-09-15 15:08:03 +02:00
Thomas Haller
f295e1313a
core: use _nm_utils_inet4_ntop() instead of nm_utils_inet4_ntop()
nm_utils_inet4_ntop() is public API of libnm. Also, it accepts a
%NULL buffer to use a static buffer. That is error prone and we
should not use such convenience behavior for our own code.
2020-09-15 15:08:02 +02:00
Thomas Haller
026389fc1f
supplicant: fix crash in _scan_notify_allowed() when supplicant disconnects
When stopping wpa_supplicant, I got an assertion failure:

  #0  g_logv (log_domain=0x55f8e4a43013 "NetworkManager", log_level=G_LOG_LEVEL_CRITICAL, format=<optimized out>, args=<optimized out>) at ../glib/gmessages.c:1377
  #1  0x00007f2d33245233 in g_log (log_domain=log_domain@entry=0x55f8e4a43013 "NetworkManager", log_level=log_level@entry=G_LOG_LEVEL_CRITICAL, format=format@entry=0x7f2d332976ff "%s: assertion '%s' failed") at ../glib/gmessages.c:1415
  #2  0x00007f2d33245a2d in g_return_if_fail_warning (log_domain=log_domain@entry=0x55f8e4a43013 "NetworkManager", pretty_function=pretty_function@entry=0x55f8e4acc1e0 <__func__.14> "nm_supplicant_interface_get_state", expression=expression@entry=0x55f8e4acb450 "NM_IS_SUPPLICANT_INTERFACE (self)") at ../glib/gmessages.c:2771
  #3  0x000055f8e49ab3f2 in nm_supplicant_interface_get_state (self=0x0) at src/supplicant/nm-supplicant-interface.c:2581
  #4  0x00007f2d1f7307a4 in _scan_notify_allowed (self=self@entry=0x55f8e5199cf0 [NMDeviceWifi], do_kickoff=do_kickoff@entry=NM_TERNARY_FALSE) at src/devices/wifi/nm-device-wifi.c:514
  #5  0x00007f2d1f730ed3 in supplicant_iface_state (self=0x55f8e5199cf0 [NMDeviceWifi], new_state=<optimized out>, old_state=NM_SUPPLICANT_INTERFACE_STATE_COMPLETED, disconnect_reason=<optimized out>, is_real_signal=<optimized out>) at src/devices/wifi/nm-device-wifi.c:2492
  #6  0x00007f2d32339af0 in ffi_call_unix64 () at ../src/x86/unix64.S:76
  #7  0x00007f2d323392ab in ffi_call (cif=cif@entry=0x7ffcaf6c3120, fn=fn@entry=0x7f2d1f731920 <supplicant_iface_state_cb>, rvalue=<optimized out>, avalue=avalue@entry=0x7ffcaf6c3050) at ../src/x86/ffi64.c:525
  #12 0x00007f2d3334ac63 in <emit signal ??? on instance 0x55f8e4f49bb0 [NMSupplicantInterface]> (instance=instance@entry=0x55f8e4f49bb0, signal_id=<optimized out>, detail=detail@entry=0) at ../gobject/gsignal.c:3554
      #8  0x00007f2d3333238d in g_cclosure_marshal_generic (closure=closure@entry=0x55f8e521eb10, return_gvalue=return_gvalue@entry=0x0, n_param_values=n_param_values@entry=4, param_values=param_values@entry=0x7ffcaf6c3320, invocation_hint=invocation_hint@entry=0x7ffcaf6c32a0, marshal_data=marshal_data@entry=0x0) at ../gobject/gclosure.c:1500
      #9  0x00007f2d3333188a in g_closure_invoke (closure=0x55f8e521eb10, return_value=return_value@entry=0x0, n_param_values=4, param_values=param_values@entry=0x7ffcaf6c3320, invocation_hint=invocation_hint@entry=0x7ffcaf6c32a0) at ../gobject/gclosure.c:810
      #10 0x00007f2d33344423 in signal_emit_unlocked_R (node=node@entry=0x7f2d200066c0, detail=detail@entry=0, instance=instance@entry=0x55f8e4f49bb0, emission_return=emission_return@entry=0x0, instance_and_params=instance_and_params@entry=0x7ffcaf6c3320) at ../gobject/gsignal.c:3742
      #11 0x00007f2d3334aaf9 in g_signal_emit_valist (instance=<optimized out>, signal_id=<optimized out>, detail=<optimized out>, var_args=var_args@entry=0x7ffcaf6c34f0) at ../gobject/gsignal.c:3498
  #13 0x000055f8e49a880b in _emit_signal_state (disconnect_reason=0, old_state=NM_SUPPLICANT_INTERFACE_STATE_COMPLETED, new_state=<optimized out>, self=0x55f8e4f49bb0 [NMSupplicantInterface]) at src/supplicant/nm-supplicant-interface.c:1083
  #14 set_state_down (self=0x55f8e4f49bb0 [NMSupplicantInterface], force_remove_from_supplicant=0, reason=0x55f8e4acd918 "InterfaceRemoved signal from wpa_supplicant") at src/supplicant/nm-supplicant-interface.c:1083
  #15 0x000055f8e49acb0b in _supp_iface_remove_one (self=0x55f8e51990c0 [NMSupplicantManager], supp_iface=0x55f8e4f49bb0 [NMSupplicantInterface], force_remove_from_supplicant=0, reason=0x55f8e4acd918 "InterfaceRemoved signal from wpa_supplicant") at src/supplicant/nm-supplicant-manager.c:1067
  #16 0x000055f8e49accec in _dbus_interface_removed_cb (connection=<optimized out>, sender_name=0x7f2d20038f20 ":1.4741", object_path=<optimized out>, signal_interface_name=<optimized out>, signal_name=<optimized out>, parameters=<optimized out>, user_data=0x55f8e51990c0) at src/supplicant/nm-supplicant-manager.c:902
  #17 0x00007f2d33483c0f in emit_signal_instance_in_idle_cb (data=data@entry=0x7f2d20034750) at ../gio/gdbusconnection.c:3777
  #18 0x00007f2d3323945b in g_idle_dispatch (source=source@entry=0x7f2d20038db0, callback=0x7f2d33483b90 <emit_signal_instance_in_idle_cb>, user_data=0x7f2d20034750) at ../glib/gmain.c:5755
  #19 0x00007f2d3323d78f in g_main_dispatch (context=0x55f8e4ee31e0) at ../glib/gmain.c:3309
  #20 g_main_context_dispatch (context=0x55f8e4ee31e0) at ../glib/gmain.c:3974
  #21 0x00007f2d3323db18 in g_main_context_iterate (context=0x55f8e4ee31e0, block=block@entry=1, dispatch=dispatch@entry=1, self=<optimized out>) at ../glib/gmain.c:4047
  #22 0x00007f2d3323de33 in g_main_loop_run (loop=0x55f8e4ec4d20) at ../glib/gmain.c:4241
  #23 0x000055f8e4755a3b in main (argc=<optimized out>, argv=<optimized out>) at src/main.c:456

Fixes: 7500e90b53 ('wifi: rework scanning of Wi-Fi device')
2020-09-15 15:00:14 +02:00
Sayed Shah
518187e8db platform: add support for mcast_hash_max netlink attribute for bridges
Adding the mcast_hash_max property. The value must be the power of 2.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/624
2020-09-15 13:41:29 +02:00
Thomas Haller
3338ea0530
device: track used shared-ips via NMNetns
Note that when NetworkManager tries to allocate more than 256 networks,
then previously the allocation would fail. We no longer fail, but log an
error and reuse the last address (10.42.255.1/24).

It's simpler to have code that cannot fail, because it's often hard to
handle failure properly. Also, if the user would configure two shared
profiles that explicitly use the same subnet, we also wouldn't fail. Why
not? Is that not a problem as well? If it is not, there is no need to
fail in this case. If it is a problem, then it would be much more
important to handle this case otherwise -- since it's more likely to
activate two profiles that accidentally use the same subnet than
activating 257+ shared profiles.
2020-09-14 17:30:59 +02:00
Thomas Haller
3fcfb53c4b
core: add nm_netns_shared_ip_reserve() API
Add a better way of tracking the shared IP addresses that are in use.
This will replace NMDevice's usage of a global hash table. For one, the
API is more formalized with reserve() and release() functions.
Also, it ties the used IP addresses to the netns, which would be more
correct (in the future when we may support more netns).
2020-09-14 17:28:10 +02:00
Thomas Haller
2535b3a539
device/trivial: move code around 2020-09-11 16:18:44 +02:00
Thomas Haller
3d6fef2d9a
platform: add nm_platform_iter_obj_for_each() macro 2020-09-11 16:18:42 +02:00
Thomas Haller
b6c3211fcc
core: use nm_platform_ip6_address_match() in nm_ip6_config_find_first_address() 2020-09-11 16:18:41 +02:00
Thomas Haller
94fbc7bdba
platform: add nm_platform_ip6_address_match() 2020-09-11 16:18:40 +02:00
Thomas Haller
345aeefaf3
dhcp: drop "event_id" parameter from NM_DHCP_CLIENT_SIGNAL_STATE_CHANGED signal
It is solely computed from the lease information (the GHashTable).
No need to pass it along as separate argument in NM_DHCP_CLIENT_SIGNAL_STATE_CHANGED,
especially since it only applies to IPv6.
2020-09-11 16:18:39 +02:00
Thomas Haller
ee447cbb52
device: mark NMDevicePrivate.sys_iface_state as const
It's important to find place in code where are field (state) gets
mutated. Make sys_iface_state field const, but add a mutable alias
via a union. You can now grep for places that change the field.
2020-09-11 16:18:38 +02:00
Thomas Haller
b6dc2e15d2
device/trivial: unify (rename) functions in "nm-device.c" 2020-09-11 16:18:37 +02:00
Thomas Haller
ed8d7ae264
core: move nm_utils_generate_duid_from_machine_id() to "nm-core-utils.c" 2020-09-11 16:18:36 +02:00
Thomas Haller
b23825f457
l3cfg: add nm_l3cfg_get_combined_l3cd() function 2020-09-11 16:18:36 +02:00
Thomas Haller
d16776b5fd
l3cfg: gracefully accept %NULL argument in nm_l3_config_data_lookup_objs()
This way we can safely iterate over a %NULL instance with
nm_l3_config_data_iter_obj_for_each(). This avoids a NULL check,
which in this case seems more annoying than helpful.
2020-09-11 16:18:35 +02:00
Thomas Haller
6358d10688
l3cfg: add nm_l3cfg_get_best_default_route() function
This is the best default route that we commited the last time (if any).
It may not reflect what is currently configured (in NMPlatform) and it
may not reflect the latest changes since nm_l3cfg_add_config().
2020-09-11 16:18:35 +02:00