Commit graph

15711 commits

Author SHA1 Message Date
Thomas Haller
5245fc6c75
platform: rename nmp_lookup_init_object() to nmp_lookup_init_object_by_ifindex()
In the past, nmp_lookup_init_object() could both lookup all object for a
certain ifindex, and lookup all objects of a type. That fallback path
already leads to an assertion failure fora while now, so nobody should
be using this function to lookup all objects of a certain type (for
what, we have nmp_lookup_init_obj_type()).

Now, remove the fallback path, and rename the function to what it really
does.
2022-06-30 14:08:41 +02:00
Thomas Haller
902812ce49
platform: use memset() in _nmp_object_stackinit_from_class()
NMPObject is a union. It's not clear to me that C guarnatees that
designated initializers will meaningfully set all fields to zero. Use
memset() instead.
2022-06-30 14:08:40 +02:00
Lubomir Rintel
af447c493c merge: branch 'lr/client-ask-mode'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1282
2022-06-30 11:15:18 +02:00
Lubomir Rintel
9a70d4e819 tests/client: add interactive add test 2022-06-30 10:20:44 +02:00
Lubomir Rintel
a3f0db06e4 tests/client: do not consult expected result files if no checks require them
Perhaps the test is not using call_nmcli*(), but still wants to use
@nm_test decorator to set up the mock service.
2022-06-30 10:20:44 +02:00
Lubomir Rintel
9570224e86 tests/client: add a pexpect-based test runner
Useful for testing interactive commands against a mock service.
2022-06-30 10:20:44 +02:00
Thomas Haller
e6a33c04eb
all: make "ipv6.addr-gen-mode" configurable by global default
It can be useful to choose a different "ipv6.addr-gen-mode". And it can be
useful to override the default for a set of profiles.

For example, in cloud or in a data center, stable-privacy might not be
the best choice. Add a mechanism to override the default via global defaults
in NetworkManager.conf:

  # /etc/NetworkManager/conf.d/90-ipv6-addr-gen-mode-override.conf
  [connection-90-ipv6-addr-gen-mode-override]
  match-device=type:ethernet
  ipv6.addr-gen-mode=0

"ipv6.addr-gen-mode" is a special property, because its default depends on
the component that configures the profile.

- when read from disk (keyfile and ifcfg-rh), a missing addr-gen-mode
  key means to default to "eui64".
- when configured via D-Bus, a missing addr-gen-mode property means to
  default to "stable-privacy".
- libnm's ip6-config::addr-gen-mode property defaults to
  "stable-privacy".
- when some tool creates a profile, they either can explicitly
  set the mode, or they get the default of the underlying mechanisms
  above.

  - nm-initrd-generator explicitly sets "eui64" for profiles it creates.
  - nmcli doesn' explicitly set it, but inherits the default form
    libnm's ip6-config::addr-gen-mode.
  - when NM creates a auto-default-connection for ethernet ("Wired connection 1"),
    it inherits the default from libnm's ip6-config::addr-gen-mode.

Global connection defaults only take effect when the per-profile
value is set to a special default/unset value. To account for the
different cases above, we add two such special values: "default" and
"default-or-eui64". That's something we didn't do before, but it seams
useful and easy to understand.

Also, this neatly expresses the current behaviors we already have. E.g.
if you don't specify the "addr-gen-mode" in a keyfile, "default-or-eui64"
is a pretty clear thing.

Note that usually we cannot change default values, in particular not for
libnm's properties. That is because we don't serialize the default
values to D-Bus/keyfile, so if we change the default, we change
behavior. Here we change from "stable-privacy" to "default" and
from "eui64" to "default-or-eui64". That means, the user only experiences
a change in behavior, if they have a ".conf" file that overrides the default.

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

See-also: https://github.com/coreos/fedora-coreos-tracker/issues/907

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1213
2022-06-29 07:38:48 +02:00
Thomas Haller
7f766014c5
team: specify cli-type for teamdctl_connect() to select usock/dbus
teamdctl_connect() has a parameter cli_type. If unspecified, the
library will try usock, dbus (if enabled) and zmq (if enabled).

Trying to use the unix socket if we expect to use D-Bus can be bad. For
example, it might cause SELinux denials.

As we anyway require libteam to use D-Bus, if D-Bus is available,
explicitly select the cli type.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1255
2022-06-27 14:04:40 +02:00
Beniamino Galvani
bf9a2babb4 platform: fix routing rule test failure
Since kernel 5.18 there is a stricter validation [1][2] on the tos
field of routing rules, that must not include ECN bits.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=f55fbb6afb8d701e3185e31e73f5ea9503a66744
[2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=a410a0cf98854a698a519bfbeb604145da384c0e

Fixes the following failure:

  >>> src/core/platform/tests/test-route-linux
  >>> ...
  # NetworkManager-MESSAGE: <warn>  [1656321515.6604] platform-linux: do-add-rule: failure 22 (Invalid argument - Invalid dsfield (tos): ECN bits must be 0)
  >>> failing... errno=-22, rule=[routing-rule,0x13d6e80,1,+alive,+visible; [6] 0: from all tos 0xff fwmark 0x4/0 suppress_prefixlen -459579276 action-214 protocol 255]
  >>> existing rule: * [routing-rule,0x13d71e0,2,+alive,+visible; [6] 0: from all sport 65534 lookup 10009 suppress_prefixlen 0 none]
  >>> existing rule:   [routing-rule,0x13d7280,2,+alive,+visible; [4] 0: from all fwmark 0/0x9a7e9992 ipproto 255 suppress_prefixlen 0 realms 0x00000008 none protocol 71]
  >>> existing rule:   [routing-rule,0x13d7320,2,+alive,+visible; [6] 598928157: from all suppress_prefixlen 0 none]
  >>> existing rule:   [routing-rule,0x13d73c0,2,+alive,+visible; [4] 0: from 192.192.5.200/8 lookup 254 suppress_prefixlen 0 none protocol 9]
  >>> existing rule:   [routing-rule,0x13d7460,2,+alive,+visible; [4] 0: from all ipproto 3 suppress_prefixlen 0 realms 0xffffffff none protocol 5]
  >>> existing rule:   [routing-rule,0x13d7500,2,+alive,+visible; [4] 0: from all fwmark 0x1/0 lookup 254 suppress_prefixlen 0 action-124 protocol 4]
  >>> existing rule:   [routing-rule,0x13d75a0,2,+alive,+visible; [4] 0: from all suppress_prefixlen 0 action-109]
  0:      from all fwmark 0/0x9a7e9992 ipproto ipproto-255 realms 8 none proto 71
  0:      from 192.192.5.200/8 lookup main suppress_prefixlength 0 none proto ra
  0:      from all ipproto ggp realms 65535/65535 none proto 5
  0:      from all fwmark 0x1/0 lookup main suppress_prefixlength 0 124 proto static
  0:      from all 109
  0:      from all sport 65534 lookup 10009 suppress_prefixlength 0 none
  598928157:      from all none
  Bail out! nm:ERROR:../src/core/platform/tests/test-route.c:1787:test_rule: assertion failed (r == 0): (-22 == 0)

Fixes: 5ae2431b0f ('platform/tests: add tests for handling policy routing rules')
2022-06-27 13:31:08 +02:00
Beniamino Galvani
90e7afc2cd libnm,core: add support for {rto_min,quickack,advmss} route attributes 2022-06-27 11:38:43 +02:00
Beniamino Galvani
2cc02a3a1b platform: add support for {rto_min,quickack,lock-advmss} route attributes 2022-06-27 11:38:43 +02:00
Beniamino Galvani
33f89f5978 ifcfg-rh: support reading boolean route attributes 2022-06-27 11:38:43 +02:00
Thomas Haller
ff694f42a7
dhcp/systemd: pass client instance to lease_to_ip6_config()
This makes it more consistent with nettools' lease_to_ip4_config().
The benefit of having a self pointer, is that it provides the necessary
context for logging. Without it, these functions cannot correctly log.

At this point, it's clearer to get the necessary data directly from the
DHCP client instance, instead of having the caller passing them on
(redundantly).
2022-06-27 10:53:40 +02:00
Thomas Haller
c7c57e8fb9
dhcp/nettools: log message about guessing subnet mask for IPv4 2022-06-27 10:53:40 +02:00
Thomas Haller
f0d132bda9
dhcp: add nm_dhcp_client_create_l3cd() helper 2022-06-27 10:53:39 +02:00
Thomas Haller
c06e6390a4
dhcp/nettools: normalize subnet netmask in nettools client
For an IPv4 subnet mask we expect that all the leading bits are set (no
"holes"). But _nm_utils_ip4_netmask_to_prefix() does not enforce that,
and tries to make the best of it.

In face of a netmask with holes, normalize the mask.
2022-06-27 10:53:39 +02:00
Thomas Haller
57dfa999f7
dhcp/nettools: accept missing "subnet mask" (option 1) in DHCP lease
Do the same as dhclient plugin in nm_dhcp_utils_ip4_config_from_options().

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/1037
2022-06-27 10:53:36 +02:00
Thomas Haller
863b71a8fe
all: use internal _nm_utils_ip4_netmask_to_prefix()
We have two variants of the function: nm_utils_ip4_netmask_to_prefix()
and _nm_utils_ip4_netmask_to_prefix(). The former only exists because it
is public API in libnm. Internally, only use the latter.
2022-06-27 10:50:24 +02:00
Thomas Haller
05014b328f
glib-aux: add _nm_utils_ip4_netmask_to_prefix() helper
nm_utils_ip4_netmask_to_prefix() and nm_utils_ip4_prefix_to_netmask()
are public API in libnm.

We thus already have an internal implementation _nm_utils_ip4_prefix_to_netmask(),
for non-libnm users. Internally, we should never use the libnm variant.

For consistency and so that we have the helper available in
libnm-glib-aux, add _nm_utils_ip4_netmask_to_prefix().
2022-06-27 10:50:23 +02:00
Thomas Haller
7a33870bf1
libnm: assert nm_utils_ip4_prefix_to_netmask() for valid IPv4 prefix length
There was already an nm_assert() assertion. Upgrade this
to a g_return_val_if_fail(). This function is public API,
so this is potentially an API break. But it should highlight
a bug in the caller.
2022-06-27 10:50:13 +02:00
Lubomir Rintel
8e6f55ce82 platform: fix build with kernels < 5.7
Fixes: 919a61bc53 ('platform/netlink: extend nl_nlmsghdr_to_str() for genl messages')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1280
2022-06-27 09:08:00 +02:00
Thomas Haller
ae6fe90851
ifcfg-rh: fix serializing lock route attributes
The lock attribute is a boolean, it can also be FALSE. We need
to handle that case, and don't add serialize "$NAME lock 0" for them.
2022-06-27 08:29:27 +02:00
Thomas Haller
efca0b8fa6
ifcfg-rh: in get_route_attributes_string() check prefix for "lock" names
In practice, the profile probably validates, so all the
attribute names are well-known. There is thus no attribute
name that has "lock-" in the middle of the string.

Still, fix it. We want to match only at the begin of the
name.
2022-06-27 08:29:26 +02:00
Thomas Haller
3628cf4805
core: log boot-id when NetworkManager starts
In a logfile, the "is starting" message is an interesting point
that indicates when NetworkManager is starting. Include
also the boot-id in the log, so that we can know whether this
was a restart from the same boot.

Also drop the "for the first time" part.

  <info>  [1656057181.8920] NetworkManager (version 1.39.7) is starting... (after a restart, asserts:10000, boot:486b1052-4bf8-48af-8f15-f3e85c3321f6)
2022-06-27 08:28:56 +02:00
Thomas Haller
8f80f3d446
glib-aux: make code in nm_uuid_is_valid_nm() clearer
Setting `NM_SET_OUT(out_normalized, !is_normalized)` is correct, but looks
odd and required a long code comment.

Try to write the same code differently, I think it is easier to
read and requires less comment to explain.
2022-06-24 21:15:11 +02:00
Thomas Haller
e3a0157141
glib-aux: pass string length to nm_uuid_generate_from_string() in nm_uuid_is_valid_nm()
No need to recompute the length. We have it already.
Also no need to NUL terminate the string.
2022-06-24 21:15:11 +02:00
Lubomir Rintel
33688caabc merge: branch 'lr/ask-mode'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1215
2022-06-24 17:17:59 +02:00
Beniamino Galvani
f8885d0724 core: avoid stale entries in the DNS manager for non-virtual devices
_dev_l3_register_l3cds() schedules a commit, but if the device has
commit type NONE, that doesn't emit a l3cd-changed. Do it manually,
to ensure that entries are removed from the DNS manager.

Related: b86388bef3 ('core: avoid stale entries in the DNS manager')
Fixes: 58287cbcc0 ('core: rework IP configuration in NetworkManager using layer 3 configuration')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/995
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1268
2022-06-24 12:02:45 +02:00
Thomas Haller
f8e061d7d6
platform/netlink: expose genl_ctrl_policy policy in header 2022-06-24 11:03:40 +02:00
Thomas Haller
4f405c5a07
platform/netlink: drop nl_socket_set_ext_ack() API
We just always want to set this. No need for a setter that is only
called once.
2022-06-24 11:03:39 +02:00
Thomas Haller
9cd986ba2e
platform/netlink: simplify socket flags and use boolean fields
- replace "s_flags" field by explicit boolean fields.

- "s_msg_peek" now is simplified. Previously, we would default
  to peek, unless the user caller nl_socket_disable_msg_peek()
  or set nl_socket_set_msg_buf_size(). Simplify that. We now
  default to peek, unless NL_SOCKET_FLAGS_DISABLE_MSG_PEEK is set.

  We have no callers that call nl_socket_set_msg_buf_size(),
  so we can simplify that logic and just enable peeking by default.

- keep "s_auto_ack" field, although it is always TRUE and there
  is no API to toggle that. However, it is kept as a self-documenting
  thing, so we would know the relevant places where auto-ack matters.

- drop nl_socket_disable_msg_peek(). We have no caller of this function
  and we can set peeking in nl_socket_new(). We also don't need to
  change it after creation of the socket.
2022-06-24 11:03:38 +02:00
Thomas Haller
c09b37f3c7
platform/netlink: add flags argument to nl_socket_new()
The real purpose is that we set the socket options before bind().
For that, we need to be able to specify the flag during nl_socket_new().

Another reason is that these are common questions to ponder while
creating a netlink socket. There shouldn't be several setter functions,
just specify the flag right away. These parameters are not going to
change afterwards (at least, we don't need/use that and we don't have
API for that either).
2022-06-24 11:03:37 +02:00
Thomas Haller
919a61bc53
platform/netlink: extend nl_nlmsghdr_to_str() for genl messages
Print more details for generic netlink messages.

Also, pass the group that we obtained via NETLINK_PKTINFO.

Also, factor out simple to-string methods.
2022-06-24 11:03:36 +02:00
Thomas Haller
51b707357d
platform/netlink: add reading NETLINK_PKTINFO in nl_recv()
We will need this, for getting nl_pktinfo control messages
that contain the extended destination group number.

Also, drop NL_SOCK_PASSCRED. It was only used to not iterate over the
control messages, but doing that should be cheap.
2022-06-24 11:03:35 +02:00
Thomas Haller
39320e26cd
platform/netlink: minor cleanup in _netlink_recv_handle()
- drop "abort_parsing" variable, it was redundant.
- rename event_valid_msg(), as this is about NETLINK_ROUTE.
- rename "err" variable to "retval".
2022-06-24 11:03:35 +02:00
Thomas Haller
88df542b6b
platform/netlink: move generic code in _netlink_recv_handle()
This also applies to genl messages. Move the code.
2022-06-24 11:03:34 +02:00
Thomas Haller
b1abd3ebdd
platform/netlink: add nl_msg_lite struct to avoid allocating netlink message
There really is no need for two(!) heap allocations while parsing
the netlink message. We already have it in the buffer. Just use it.

Note that netlink attributes need to be aligned to 4 bytes. But
nlmsg_next() already ensures that, so not even for alignment purpose we
need to clone the message.

Create a new "struct nl_msg_lite" that can hold pointers to everything
we need.
2022-06-24 11:03:34 +02:00
Thomas Haller
1460adc918
platform/netlink: add const modifier for genl functions 2022-06-24 11:03:33 +02:00
Lubomir Rintel
cd2945f223 nmcli/connections: fix setting ifname with "--ask c add"
We almost always do the wrong thing in interactive add:

The software devices generally require an interactive name, but we don't
insist of asking for them; treating them as optional:

  $ nmcli -a c add type dummy
  There is 1 optional setting for General settings.
  Do you want to provide it? (yes/no) [yes]

For some interface types (bridges, bonds, ...) we make up a name, presumably
for historical reasons. But we don't give the user an option to modify
them:

  $ nmcli -a c add type bridge
  <not asking for interface name at all>
  There are 9 optional settings for Bridge device.
  Do you want to provide them? (yes/no) [yes]

This fixes the above use cases -- still set the default, but be sure to
ask:

  $ nmcli -a c add type dummy
  Interface name:

  $ nmcli -a c add type bridge
  Interface name [nm-bridge1]:

Beautiful.
2022-06-24 00:30:04 +02:00
Lubomir Rintel
647e255362 nmcli/connections: make sure the connection has a base setting
Do the same bookkeeping as would happen upon setting the "type" option
when the connection has a connection.type set upon its addition.

Otherwise the --ask mode is sad:

  $ nmcli --ask c add connection.type team
  ** nm:ERROR:src/nmcli/connections.c:5648:connection_get_base_meta_setting_type: assertion failed: (base_setting)
  Bail out! nm:ERROR:src/nmcli/connections.c:5648:connection_get_base_meta_setting_type: assertion failed: (base_setting)
  Aborted (core dumped)
2022-06-24 00:30:04 +02:00
Lubomir Rintel
e3fa6dfd7f nmcli/connections: factor out code run after new connection's type is set
After the connection's type is set, some bookkeeping is necessary for
the interactive (--ask) mode: appropriate setting need to be added and
options enabled.

Currently it happens in an option setter; which runs when the "type"
options is present on the command line, or the value is set in a
response to interactive mode:

  $ nmcli --ask c add type team

  $ nmcli --ask c add
  Connection type: team

But not when the property is set directly:

  $ nmcli --ask c add connection.type team
  ** nm:ERROR:src/nmcli/connections.c:5648:connection_get_base_meta_setting_type: assertion failed: (base_setting)
  Bail out! nm:ERROR:src/nmcli/connections.c:5648:connection_get_base_meta_setting_type: assertion failed: (base_setting)
  Aborted (core dumped)

This doesn't fix the issue -- a followup commit (hopefully) will.
2022-06-24 00:30:04 +02:00
Lubomir Rintel
b171dcec0d nmcli/connections: use the current value in default in ask_option()
For new connections, this ensures the value in square brackets on
interactive add are always correct.

Apart from that, this allows us to initialize some non-default values
before asking (such as making up an interface name for some software
devices), and inform the user about what we picked:

  Interface name [nm-bridge]:
2022-06-24 00:30:04 +02:00
Lubomir Rintel
ad7ac866db nmcli/connections: don't ask to ask with --ask
This is slightly annoying:

  $ nmcli -a c add type ethernet
  There is 1 optional setting for General settings.

No point in asking if there's just one option. Just ask right away:

  $ nmcli -a c add type ethernet
  Interface name:
2022-06-24 00:30:04 +02:00
Lubomir Rintel
69e65a9b0e nmcli/connections: make sure the connection has a type
We use it before we validate the connection, thus need to check if it's
actually there.
2022-06-24 00:30:04 +02:00
Lubomir Rintel
cf62f0e3a1 nmcli/connections: make enable_options() always enable an option 2022-06-24 00:30:04 +02:00
Lubomir Rintel
6fee8aa454 nmcli/connections: make opts argument to enable_options() optional
This makes things slightly less annoying when dealing with options that
map nicely to properties (unlike bridge options).
2022-06-24 00:30:04 +02:00
Lubomir Rintel
a5e099d008 nmcli/connections: allow empty lists with "--ask c add"
The interactive add is not too enthusiastic about not providing a value
in a list.

That is before on getting an empty line in ask_option() we take a
shortcut instead of dispatching to set_option(). That way we skip
setting the PROPERTY_INF_FLAG_DISABLED flag, causing the option to
be included in questionnaire_one_optional()'s info list.

There's no reason to avoid calling set_option() if we don't get a value;
set_option() handles NULL value just fine.

  $ nmcli -a c add
  Connection type: dummy
  There is 1 optional setting for General settings.
  Do you want to provide it? (yes/no) [yes]
  Interface name [*]: lala
  There are 2 optional settings for IPv4 protocol.
  Do you want to provide them? (yes/no) [yes]
  You can specify this option more than once. Press <Enter> when you're done.
  IPv4 address (IP[/plen]) [none]:
  You can specify this option more than once. Press <Enter> when you're done.
  IPv4 address (IP[/plen]) [none]:
  You can specify this option more than once. Press <Enter> when you're done.
  IPv4 address (IP[/plen]) [none]:
  ...
2022-06-24 00:30:04 +02:00
Lubomir Rintel
d51140d2ab nmcli/connections: do not remove a bond option unless reset is allowed
If we're setting an option with no value given and no reset allowed,
let's just set the default value.
2022-06-24 00:30:04 +02:00
Lubomir Rintel
0cb971d1d6 nmcli/connections: pass allow_reset to check_and_set() callback
Like the regular set_option() handler, the special ones also need to
know whether to reset an option or keep the value.
2022-06-24 00:30:04 +02:00
Lubomir Rintel
fe82c3a37a libnmc-setting: fix default suggestions for some options
These are just plain wrong.
2022-06-24 00:29:58 +02:00