Commit graph

560 commits

Author SHA1 Message Date
Beniamino Galvani
fcfaf78c91
l3cfg: fix dns options in _init_from_connection_ip() 2021-09-30 15:10:18 +02:00
Thomas Haller
5efd3134e4
l3cfg: accept NULL NML3ConfigData for several getters
We often want to be pedantic about not accepting %NULL for getters (or ref,
unref, etc). Often that is also inconvenient, so we would need to write:

  if (l3cd)
      strv = nm_l3_config_data_get_nameservers(l3cd, addr_family, &len);
  else
      len = 0;

(and, make sure that strv does not trigger a maybe-uninitialized warning).

Being pedanic here is more cumbersome than helpful. Accept NULL to return
the sensible default.

Also add nm_l3_config_data_get_dns_priority_or_default() helper which maps
NULL or a missing value to zero. This is also only for convenience for certain
callers.
2021-09-30 15:10:18 +02:00
Thomas Haller
17fd1e4708
l3cfg/trivial: explain commit-type in code comments 2021-09-29 09:26:43 +02:00
Beniamino Galvani
8a06d66d0e
l3cfg: fix nm_l3cfg_commit_type_register() to set commit_type and add debug logging
Co-authored-by: Thomas Haller <thaller@redhat.com>
2021-09-28 22:18:13 +02:00
Thomas Haller
78c716cfaf
l3cfg: track "never-default" in NML3Cfg 2021-09-28 13:20:28 +02:00
Thomas Haller
c9a833c910
l3cfg: drop nm_l3cfg_property_emit_register() API
The idea was that NMIPConfig would register itself with the property (like "address-data")
and then NML3Cfg would emit the property changed notification.

However, we can already achive that via the regular notification, in particular
by listening to NM_L3_CONFIG_NOTIFY_TYPE_PLATFORM_CHANGE_ON_IDLE notification.

Also, NML3Cfg does not really understand the details when the property should
be emitted. For example, many routes not not exposed via "route-data" property,
and changes to those should not trigger a notification.

Drop the unused API.
2021-09-27 10:09:50 +02:00
Thomas Haller
e47dd2ee22
l3cfg: configure dependent routes when creating combined config 2021-09-27 07:55:32 +02:00
Thomas Haller
ed1536c890
l3cfg: fix assertion failure in _l3_hook_add_obj_cb()
With nm_l3cfg_get_combined_l3cd(), we can get the commited or
the combined (next) l3cd. The commits is easy, it's cached already.

However, the combined needs to be computed first, if there were any
changes. For that we call _l3cfg_update_combined_config(), which then
also calls nm_l3_config_data_merge().

But in non-commit mode, _l3cfg_update_combined_config() doesn't call
_l3_acd_data_add_all(), so in _l3_hook_add_obj_cb() the ACD data may
not be as expected. This can previously hit an assertion.
2021-09-25 10:10:17 +02:00
Thomas Haller
d68fa91199
platform/tests: fix assertion failure in NMTstpAcdDefender
Seems we can get a DOWN event during unit tests. I don't really
understand why, but let's ignore it.

  [...]
  #4  0x000055e365777786 in _l3_acd_nacd_event (fd=<optimized out>, condition=<optimized out>, user_data=0x55e367566270) at src/core/platform/tests/test-common.c:2703
  #5  0x00007f4399c224cf in g_main_dispatch (context=0x55e36755fce0) at ../glib/gmain.c:3337
  #6  g_main_context_dispatch (context=0x55e36755fce0) at ../glib/gmain.c:4055
  #7  0x00007f4399c764f8 in g_main_context_iterate.constprop.0 (context=context@entry=0x55e36755fce0, block=block@entry=1, dispatch=dispatch@entry=1, self=<optimized out>)
      at ../glib/gmain.c:4131
  #8  0x00007f4399c1fc03 in g_main_context_iteration (context=0x55e36755fce0, context@entry=0x0, may_block=may_block@entry=1) at ../glib/gmain.c:4196
  #9  0x000055e365770719 in test_l3_ipv6ll (test_data=<optimized out>) at src/core/tests/test-l3cfg.c:1024
2021-09-25 10:10:17 +02:00
Thomas Haller
a446e490f9
l3cfg: mediate commit_type with nm_l3cfg_commit_on_idle_schedule()
We have nm_l3cfg_commit(), however that is synchronous and triggers an
avalanche of side effects. So it should be avoided if a component is
not aware of the current circumstances in which it gets called (most of them).

The alternative is nm_l3cfg_commit_on_idle_schedule(), but previously
that only supported the auto type.

Two changes:

- add a commit_type parameter to nm_l3cfg_commit_on_idle_schedule().
  This allows to explicitly select a type for the next commit.
  Previously, if the caller wanted for example to trigger a reapply
  once, they had to register a handle, trigger the commit and unregister
  the handle again. This basically allows to specify an ad-hoc commit
  type that is only used once.

- if an explicit commit type is requested, then still always combine
  it with auto. That means, we always use the "maximum" of what is
  requested and what is registered.
2021-09-24 21:48:39 +02:00
Thomas Haller
ddfd1e8ddf
device: minor cleanup in reapply_cb() 2021-09-24 18:03:05 +02:00
Thomas Haller
70a077e4d8
l3cfg: add nm_l3cfg_check_ready() helper 2021-09-23 21:17:43 +02:00
Thomas Haller
145950d0c2
l3cfg/trivial: add code comment about NM_L3_CONFIG_NOTIFY_TYPE_PLATFORM_CHANGE 2021-09-23 11:06:28 +02:00
Thomas Haller
a1b6896b14
trivial: update fixme comment
The proper tag is "l3cfg" not "next". Currently "next" branch and l3cfg rework
is the same, but in the future we might have other "next" branches, while "l3cfg"
is the tag to indicate this effort.
2021-09-23 10:55:12 +02:00
Thomas Haller
e8a63b0ab5
device: use proper define NM_SETTING_IP6_CONFIG_METHOD_SHARED in addrconf6_start() 2021-09-23 10:31:59 +02:00
Thomas Haller
642c160e59
core: use nm_clear_g_free() instead of g_clear_pointer() 2021-09-22 17:25:31 +02:00
Thomas Haller
d6ab4d24cf
l3cfg/trivial: rename parameter in nm_l3cfg_remove_config() 2021-09-21 09:12:23 +02:00
Thomas Haller
79d4b67681
l3cfg: add nm_l3_config_data_lookup_address_4() helper 2021-09-21 09:11:54 +02:00
Thomas Haller
b1ad3f1ba5
l3cfg: return any IPv4/IPv6 route from nm_l3_config_data_get_best_default_route() 2021-09-21 08:36:14 +02:00
Thomas Haller
a8866095dd
core/ndisc: move nm_lndp_ndisc_get_sysctl() to "nm-ndisc.[ch]"
NMNDisc has two implementations: lndp and fake. Fake only exists as a
stub for unit tests, otherwise there is no purpose to it. Also, we won't
ever add another implementation beside lndp. If lndp is not suitable, it
would be replaced, but not accompanied by a second implementation.

As such, nm_lndp_ndisc_get_sysctl() has no purpose to be in
"nm-lndp-ndisc.c". This split does not exist to abstract "nm-ndisc.c"
from NMPlatform. It exists to make it easier to test.
2021-09-20 13:59:10 +02:00
Beniamino Galvani
d50c4eba9e core: disable tc cache by default
We no longer use tc objects from the platform cache; disable caching
by default.

The only exception where the cache is needed is in tc tests, as we
look into the platform there to check that objects look as expected.
2021-09-20 13:27:16 +02:00
Beniamino Galvani
864e4e6369 platform: allow disabling caching of tc objects
Introduce a construct-only property for platform objects to enable or
disable the caching of tc objects. When disabled, the netlink socket
doesn't receive netlink events for tc objects, and objects are never
added to the cache. This commit doesn't change behavior yet.
2021-09-20 13:27:16 +02:00
Beniamino Galvani
c896973deb platform: drop test-tc-fake
It doesn't seem useful to have a copy of the test which does nothing.
2021-09-20 13:27:15 +02:00
Beniamino Galvani
e0691f9528 device: ensure tc_commit() is called only once per activation
Stage2 can be called multiple times. Ensure that tc_commit() is only
called the first time. This is important now that tc synchronization
requires to clear all qdiscs and recreate them.
2021-09-20 13:27:15 +02:00
Beniamino Galvani
3981bff2a0 core: rework tc sync functions
Update nm_platform_qdisc_sync() and nm_platform_tfilter_sync() to
avoid looking into the platform cache, so that we no longer require to
keep tc and qdiscs in the cache.

There is no API in kernel to retrieve tc objects only for a specific
interface, so NM had to receive all tc events, even for unmanaged
interfaces.  This could cause high CPU usage in some scenarios with
many objects.

Instead, try to delete root qdiscs and filters and then add the known
ones.

Also, combine the two functions together since they are related. In
particular, removing all qdiscs also removes all attached filters.
2021-09-20 13:27:15 +02:00
Thomas Haller
0d4840c484
l3cfg: fix assertion in NM_IS_L3_CONFIG_DATA() to allow NULL 2021-09-16 20:54:49 +02:00
Thomas Haller
882168c728
l3cfg: accept %NULL argument to nm_l3_config_data_seal()
There is always a question between convenience of allowing %NULL (and
do nothing) and strictly require the user to check the argument to not
be %NULL. In this case, it's more convenient to accept NULL, than require
the callers to check for it.
2021-09-16 20:54:49 +02:00
Thomas Haller
e1667650f4
l3cfg: fix leak of ObjStateData's os_plobj
Fixes: 6b92c89486 ('l3cfg: track platform object in NML3Cfg's object state')
2021-09-16 09:30:58 +02:00
Thomas Haller
17e4da8bf3
device: suppress warning for external device if it is down (!IFF_UP)
External devices are not to be touched by NetworkManager. If it is down,
that is not something to warn about.
2021-09-16 08:40:04 +02:00
Thomas Haller
571ce653fd
device: set up device also while "assuming"
"assuming" means to gracefully take over after restart. The result
should be a working configuration with a device fully managed by
NetworkManager.

If we are assuming, and the interface is down we still want to set it
up.
2021-09-16 08:38:25 +02:00
Thomas Haller
c2ab21a1b9
ifupdown: downgrade warning about missing /etc/network/interfaces file
I don't think this warrants a warning. It's important to keep the number
of warnings and errors in the log low, and only print such messages if
there is really something that requires attention by the user. If you
run without /etc/network/interfaces, then this is pretty much expected
and the warning isn't going to tell you anything useful.
2021-09-16 08:35:05 +02:00
Thomas Haller
6b92c89486
l3cfg: track platform object in NML3Cfg's object state
NML3Cfg tracks the state of each object (that is addresses and routes).
Previously, it had a boolean flag "os_in_platform", that should be
true if (and only if) we have a corresponding NMPObject in the platform
cache.

But NMPObjects are immutable and ref-counted. That means, we can just as
well track the reference to the NMPObject from the cache. The advantage
is that we have an index (dictionary) to find the object state, and by
tracking the platform object, we have it easily accessible.
2021-09-15 23:23:19 +02:00
Thomas Haller
2ab0eba106
l3cfg/ipv6ll: add NM_L3_IPV6LL_STATE_DEFUNCT enum
This is not used by NML3IPv6LL, but is useful for the callers to have
an additional pseudo value at their disposal.
2021-09-15 22:08:42 +02:00
Thomas Haller
05c05b7a80
l3cfg: allow injecting default dns-priority for NML3ConfigData
NML3ConfigData is supposed to be immutable. It can be initialized from a
NMConnection, and its DNS priority property might be zero.

For the DNS priority, the value can be overwritten by global defaults.
We thus need to inject the default value at the right place.
2021-09-15 22:08:42 +02:00
Thomas Haller
45bcedb77e
core: move NM_DNS_PRIORITY_DEFAULT_{NORMAL,VPN} to libnm-base
We will use these values from NML3Cfg, and it seems wrong that NML3Cfg
would include "dns/nm-dns-manager.h" for this.

Enums are very "static". They have no logic, and there is less need to
separate the code well. Meaning, it doesn't hurt to define this enum
in "libnm-base/nm-base.h" which can be included by (almost) anybody.
2021-09-15 22:08:42 +02:00
Philip Withnall
0ad77d05b9
nm-active-connection: Emit device-metered-changed if device changes
The new device might have a different metered status from the old one.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Fixes: 04d5804dd5 ('nm-manager: add 'metered' property')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/982
2021-09-15 20:26:29 +02:00
Thomas Haller
3a3613b561
ovs: avoid asking nm-sudo if ovsdb socket does not exist
Starting with OVS plugin installed but OVS service stopped, would lead to

   <trace> [1631531732.8896] ovsdb: connect: opening /run/openvswitch/db.sock failed ("error connecting socket (No such file or directory)"). Retry with nm-sudo
   ...
   <trace> [1631531732.9751] ovsdb: connect: failure to get FD from nm-sudo: GDBus.Error:org.gtk.GDBus.UnmappedGError.Quark._g_2dio_2derror_2dquark.Code1: error connecting socket (No such file or directory)

If we already know that the socket file does not exist, we don't need to ask nm-sudo.
That would only make sense, if nm-sudo somehow saw a different file systemd than
NetworkManager, but that is (currently) not the case.
2021-09-13 22:45:40 +02:00
Vojtech Bubela
195bef5bae
core: fix typo in function name nmp_object_ip_route_is_best_default_route() 2021-09-13 16:56:54 +02:00
Thomas Haller
4257cc1bee
platform/tests: fix test failure for "platform_ip_address_pretty_sort_cmp"
The memory layout of the NMPlatformIPAddress structure changed. The unit test
needs to be adjusted.

Fixes: 9ec9a92f17 ('platform: avoid bitfield at end of __NMPlatformIPAddress_COMMON macro')
2021-09-13 14:42:11 +02:00
Thomas Haller
60000c72c3
core/trivial: fix spelling in comment 2021-09-13 09:22:22 +02:00
josef radinger
3f5cb1f932
core/trivial: fix small typo Ipv vs IPv
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/978
2021-09-13 09:22:17 +02:00
Thomas Haller
aa070fb821
core: add NML3IPv6LL helper
This helper class is supposed to encapsulate most logic about
configuring IPv6 link local addresses and exposes a simpler API in order
to simplify NMDevice. Currently this logic is spread out in NMDevice.

Also, NML3IPv6LL directly uses NML3Cfg, thereby freeing NMDevice to care
about that too much.

For several reasons, NML3IPv6LL works different than NML3IPv4LL.
For one, with IPv6 we need to configure the address in kernel, which does
DAD for us. So, NML3IPv6LL will tell NML3Cfg to configure those
addresses that it wants to probe. For IPv4, it only tells NML3Cfg to do
ACD, without configuring anything yet. That is left to the caller.
2021-09-10 13:26:52 +02:00
Thomas Haller
929eae245d
l3cfg: implement NM_L3CFG_CONFIG_FLAGS_ASSUME_CONFIG_ONCE and rework object state
NML3Cfg tracks state about all addresses/routes. It needs that (at
least) for the following reaons:

1) if a address/route gets added by NetworkManager and then gets
  externally removed then it is presumed that the user did this. In this
  case, we remember that ("externally-removed") to not re-add the
  address/route, until we do a full reapply. This was previously
  tracked as "externally_removed_objs_hash".

2) when NML3Cfg configures a address/route in kernel, and later the
  address/route is no longer to be configured, then NML3Cfg needs to
  delete it again. It thus needs to remember which addresses/routes
  it configured earlier to remove them. This was previously tracked via
  "last_addresses_x" and "last_routes_x".

3) kernel rejects configuring certain routes while a related IPv6
  address is still tentative. That means, NML3Cfg needs to detect that,
  remember it, and retry later. That is previously tracked as
  "routes_temporary_not_available_hash".

4) during NM_L3_CFG_COMMIT_TYPE_ASSUME, we don't remove extraneous
  and don't add missing addresses/routes. This commit mode is done
  while assuming a device, that is, gracefully taking over after
  a restart. However, sometimes while assuming a device we forcefully
  want to configure an address/route. That happens for example if we
  do IPv6 link local addressing. Then we really want to add that
  address/route, even in assume mode. That is what the
  NM_L3CFG_CONFIG_FLAGS_ASSUME_CONFIG_ONCE flag does, and to implement
  that we need to track whether we already tried to add the
  address/route previously. This is something new.

Consolidate these various states in a new "obj_state_hash" and
"ObjStateData" structure. This solves above points the following way:

1) to track externally removed objects, we have a flag in ObjStateData
  that indicates whether the object was every configured and whether
  it currently is configured. Based on that we make decisions to
  configure (or not) an address. See "_obj_states_sync_filter()".

2) we now mark objects that NML3Cfg configured, which are still in platform
  and which are no longer to be configured as "zombies".

3) this is now tracked via ObjStateData's "os_temporary_not_available_lst".

4) with the available ObjStateData we can make appropriate decisions
  in "_obj_states_sync_filter()".
2021-09-10 13:26:52 +02:00
Thomas Haller
8a3d913de8
l3cfg: add NM_L3CFG_CONFIG_FLAGS_ASSUME_CONFIG_ONCE flag
It's a bit tricky how this flag works. It's needed for IPv6
link local addresses, which commits changes in %NM_L3_CFG_COMMIT_TYPE_ASSUME
mode. See the code comments how it works.

This commit only adds the flags and let's the NMPlatformIP{Address,Route}
properly track it. What is still needed is to actually implement any
meaning to that during the sync.
2021-09-08 18:33:44 +02:00
Thomas Haller
a909a4b305
platform: move ip4acd_not_ready flag to NMPlatformIP4Address
This flag is only relevant for IPv4. That is, because the way we do
ACD/DAD is fundamentally different between IPv4 and IPv6. For IPv4, we
use libn-acd while IPv6 we configure the address in kernel and wait for
the tentative flag to go away.
2021-09-08 18:33:44 +02:00
Thomas Haller
2eb7983a04
l3cfg: refactor modification of address in nm_l3_config_data_merge() 2021-09-08 18:33:43 +02:00
Thomas Haller
075bdefb71
l3cfg: also call nm_l3_config_data_merge()'s add-obj-hook for routes 2021-09-08 18:33:43 +02:00
Thomas Haller
cfebd0e504
l3cfg: add a "result" structure to nm_l3_config_data_merge()'s add-obj-hook 2021-09-08 18:33:43 +02:00
Thomas Haller
3b92ad8b6d
l3cfg: change NM_L3_CONFIG_MERGE_FLAGS_ONLY_FOR_ACD to be a NML3CfgConfigFlags value
It's really not related to NML3ConfigMergeFlags, but fits better
to NML3CfgConfigFlags.
2021-09-08 18:33:43 +02:00
Thomas Haller
4c3eed28cd
l3cfg: add config_flags argument to nm_l3cfg_add_config()
We will need to present additional options for tracking the configuration.
Add a flags argument.
2021-09-08 18:33:43 +02:00