Commit graph

13268 commits

Author SHA1 Message Date
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
Thomas Haller
3b8b683f8a
l3cfg: add nm_l3cfg_get_pllink() helper
NML3Cfg already keeps track of the current NMPlatformLink object.
Allow accessing it directly from an NML3Cfg instance, which saves
a cache lookup from NMPlatform.
2020-09-11 16:18:34 +02:00
Thomas Haller
16e59cc37c
l3cfg: support tracking the DHCP lease in NML3ConfigData 2020-09-11 16:18:34 +02:00
Thomas Haller
2fd53eb509
core: add NMDhcpLease typedef and simple accessor functions 2020-09-11 16:18:34 +02:00
Thomas Haller
1001dca698
device: remove unused dhcp4.root_path field 2020-09-11 10:45:36 +02:00
Thomas Haller
58da09439a
libnm,core: deprecate "active_slave" and alias it for "primary"
Setting "active_slave" fails unless the slave is currently present and
IFF_UP. That complicates the code, because we cannot set the property
at any time, but only under the right circumstances.

But really, "active_slave" option is something for debugging. It's not
an option which should be set by NetworkManager. The right option
instead is "primary", which will tell kernel to make the slave active,
when it is ready.

Deprecate the "active_slave" option and make it an alias for "primary".

https://bugzilla.redhat.com/show_bug.cgi?id=1856640
2020-09-10 22:09:58 +02:00
Thomas Haller
22ff4bfd18
device: cleanup code in NMDeviceBond's update_connection() 2020-09-10 22:09:58 +02:00
Thomas Haller
f807b68376
device: inline check_changed_options() in can_reapply_change()
Code doesn't get simpler by having more functions -- if these functions
are only called once.

What actually is a problem is repeated, redundant code. Like the list of
bond options that can be reapplied. But the function didn't help to
avoid repeating the list.
2020-09-10 22:09:57 +02:00
Thomas Haller
5402943420
device: unify setting of bond options
Add a macro for the list of bond options we are going to set. By seeing
them side-by-side, it is hopefully simpler to see that all options are
specified correctly.

We see that:

- the *_SUBSET defines don't include the options that we are explicitly
  setting, that is "mode", "active_slave" and "arp_ip_target".

- OPTIONS_REAPPLY_SUBSET contains 4 options less than OPTIONS_APPLY_SUBSET:
  "ad_select", "ad_user_port_key", "lacp_rate" and "tlb_dynamic_lb".
  These are the options that are marked as BOND_OPTFLAG_IFDOWN in
  kernel.
2020-09-10 22:09:57 +02:00
Thomas Haller
0ea73cdcec
device: remove duplicate option "primary" from list to reapply 2020-09-10 22:09:57 +02:00
Thomas Haller
2eea22ae95
device: allow "active_slave" and "arp_ip_target" bond option for reapply
I guess the idea was to only accept options that can be changed without
taking the interface !IFF_UP. "active_slave" is wrongly omitted from
that list.

Also, "active_slave" option doesn't really make sense for NetworkManager
to configure. Instead "primary" should be used. In the future, we should
re-map the properties and deprecate "active_slave" for "primary" ([1]).

Fixes: 746dc119a6 ('bond: let 'reapply()' reapply all supported options')

[1] https://bugzilla.redhat.com/show_bug.cgi?id=1856640#c19

https://bugzilla.redhat.com/show_bug.cgi?id=1876577
2020-09-10 22:09:57 +02:00
Beniamino Galvani
a017936223 device: fix wrongly considering ipv6.may-fail for ipv4
Fixes: 5e71f01605 ('device: merge stage3 and stage4 ip-config function for IPv4 and IPv6')
2020-09-09 11:02:57 +02:00
Beniamino Galvani
ec12912908 device: enforce the absence of a master during activation
If the connection doesn't specify a master, ensure that the device is
released from any master in platform.

https://bugzilla.redhat.com/show_bug.cgi?id=1869079
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/616
2020-09-07 16:29:37 +02:00
Thomas Haller
4038a8ff99
core: accept void pointer in nm_dbus_object_export() and related
NMDBusObject is an abstract type which provides the glue code for exposing
a GObject on D-Bus. We almost never use that type directly, so as it was
before, we always had to use a C cast to convince the compiler that this
is right.

Being always required to cast is not very useful, nor more typesafe.
Just use a void pointer instead.
2020-09-07 16:11:52 +02:00
Thomas Haller
47e2ff0a71
l3cfg: add nm_l3cfg_commit_type*() API for tracking the level for committing changes
NML3Cfg manages one ifindex. In the future, we may want that multiple
NMDevice and/or NMVpnConnection instances independently contribute their
NML3ConfigData to the NML3Cfg instance.

That means, at any time somebody may want to call nm_l3cfg_platform_commit()
to apply the changes. Even ACD internally may do that, when configuration
changes (e.g. an IP address passes ACD check). We thus need to know
whether we are assuming, updating or reapplying the settings.

Add API so users can register their "commit" preference.
2020-09-07 16:11:51 +02:00
Thomas Haller
4c07d34505
l3cfg: add nm_l3_config_data_has_routes_with_type_local() helper 2020-09-07 16:11:51 +02:00
Thomas Haller
c328c10227
l3cfg: more integration of NMDevice with l3cfg
Add more code that will be used later for glueing NMDevice with NML3Cfg
and NML3ConfigData. The code is not yet really used.
2020-09-07 16:11:50 +02:00
Thomas Haller
bd054bf6fd
l3cfg: remove changed flag from nm_l3cfg_add_config()/nm_l3cfg_remove_config() 2020-09-07 16:11:50 +02:00
Thomas Haller
41b9d44f9b
l3cfg: drop unused NM_L3_CONFIG_MERGE_FLAGS_EXTERNAL
The current approach also tracks external configuration in an NMIP[46]Config, and
we need to special handle those. In the future, we only want to track what we actually
want to configure. So this flag won't be used with NML3Cfg/NML3ConfigData.
2020-09-07 16:11:50 +02:00
Thomas Haller
38b2239146
l3cfg: add more l3cfg API that will be used next 2020-09-07 16:11:50 +02:00
Thomas Haller
e89a095673
l3cfg: add nm_l3_config_data_get_blacklisted_ip4_routes() util
We will need to prune routes that kernel adds (and we don't want).
2020-09-07 16:11:49 +02:00
Thomas Haller
0ab341b9e6
l3cfg: add nm_l3_config_data_get_domains() accessor 2020-09-07 16:11:49 +02:00
Thomas Haller
137d02a7e6
platform: add nm_platform_ip_address_get_peer_address() helper 2020-09-07 16:11:49 +02:00
Thomas Haller
e4f04267bb
l3cfg: implement IPv4 DAD/ACD (address collision detection) in NML3Cfg
Currently, NMDevice does ACD. It intercepts certain NMIP4Config
instances, and tries to perform ACD on the addresses. I think this
functionality should be handled by NML3Cfg instead.

For one, NML3Cfg sees all configurations, and can perform ACD for all
(relevant) addresses. Also, it moves logic away from NMDevice and makes
the functionality available without an NMDevice. As such, it also will
allow that independent "controllers" contribute NML3ConfigData instances
and ACD will performed for all of them (as requested).

This will be our implementation for IPv4 ACD (https://tools.ietf.org/html/rfc5227)
based on nettools' n-acd library.

The code is not actually tested yes, because NMDevice did not yet switch
over to use NML3Cfg. Once that happens, surely issues with this patch
will be found that will need fixing.
2020-09-03 11:52:39 +02:00
Thomas Haller
f81360bbbf
platform: add nm_platform_ip4_address_addr_to_hash() helper
This will only have one particular use, from NNL3Cfg. However, it seems
general enough to place it in "nm-platform.h".
2020-09-03 11:39:39 +02:00
Thomas Haller
bff23d15d4
initrd/tests: fix memleak in test_dhcp_vendor_class_id()
Having leaks in the tests, breaks running the test under valgrind. There
must be no leaks.

Fixes: c056cb9306 ('initrd: parse 'rd.net.dhcp.vendor-class' kernel cmdline arg')
2020-09-03 11:36:39 +02:00
Thomas Haller
c7a724fd53
all: replace cleanup macro "gs_free_slist" by "nm_auto_free_slist" 2020-09-02 17:46:43 +02:00
Thomas Haller
426a4c9d50
all: replace cleanup macro "gs_unref_keyfile" by "nm_auto_unref_keyfile" 2020-09-02 17:46:43 +02:00
Thomas Haller
b1e7fb9757
core: log message about secret-key version and filename 2020-09-02 15:12:53 +02:00
Thomas Haller
4a084a2bcb
shared: rename "gs_local_option_context" to "nm_auto_free_option_context"
The "gs_*" macros originate from the (no longer existing) libgsystem library.
We still have them, because so far we didn't go through the effort of
renaming the API.

Aside that oddity, our cleanup API is called "nm_auto*". There is no need
to add new API with the old name.
2020-09-02 10:36:58 +02:00
Antonio Cardace
d5c05d07c7
initrd: fix memory leak
Signed-off-by: Antonio Cardace <acardace@redhat.com>
Fixes: 9f9609555d ('initrd: add configuration generator')
2020-09-01 19:05:10 +02:00
Antonio Cardace
c056cb9306
initrd: parse 'rd.net.dhcp.vendor-class' kernel cmdline arg
This arguments makes NM set the ipv4.dhcp-vendor-class-identifier
property for all connections.

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

Signed-off-by: Antonio Cardace <acardace@redhat.com>
2020-09-01 11:14:46 +02:00
Antonio Cardace
5cca669ff3
core: add 'dhcp-vendor-class-identifier' validation function
So that it can be reused.

Signed-off-by: Antonio Cardace <acardace@redhat.com>
2020-09-01 09:34:29 +02:00