Commit graph

31024 commits

Author SHA1 Message Date
Thomas Haller
cc36baa5c7
glib-aux: add nm_str_truncate() helper 2022-09-23 11:43:27 +02:00
Thomas Haller
d1fd6eb53b
libnm: fix API break in "nm-utils.h" for NM_UTILS_INET_ADDRSTRLEN
This is part of public API, and was wrongly renamed during some internal
refactoring.

Reported-by: Eivind Næss <eivnaes@yahoo.com>

Fixes: 08eff4c46e ('glib-aux: rename IP address related helpers from "nm-inet-utils.h"')
2022-09-22 08:24:38 +02:00
Beniamino Galvani
23ce9cff99 libnm-core: allow empty slave-type with a NMSettingBondPort
It is allowed to have a connection with empty connection.slave-type
and a NMSettingBondPort; the property will be set automatically during
normalization if a master is set, otherwise the setting will be removed.

With this change, it becomes possible to remove a port from a bond
from nmcli, turning it into a non-slave connection. Before, this used
to fail with:

  $ nmcli connection add type ethernet ifname test con-name test+ connection.master bond0 connection.slave-type bond
  $ nmcli connection modify test+ connection.master '' connection.slave-type ''
  Error: Failed to modify connection 'test+': connection.slave-type: A connection with a 'bond-port' setting must have the slave-type set to 'bond'

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

Fixes: 9958510f28 ('bond: add support of queue_id of bond port')
2022-09-21 13:24:14 +02:00
Thomas Haller
6e0ede9d65
contrib: add "nm-code-format.sh -u" parameter
Reformatting the entire source tree takes quite long. For fast
development it's useful to only check the files that changes on the
current checkout.

For that there was already the "-F|--fast" option, but that only
compared the files that changed compared to HEAD^.

What actually would be useful is to check the files that changed on the
current branch, compared to some upstream commit. Add "-u|--upstream"
option to specify the upstream commit (usually "main").

As a special twist,

  ./contrib/scripts/nm-code-format.sh -u

is the same as

  ./contrib/scripts/nm-code-format.sh -u main
2022-09-21 10:22:32 +02:00
Thomas Haller
a939324a78
firewall: merge branch 'th/firewall-cleanup'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1379
2022-09-21 10:10:02 +02:00
Thomas Haller
b74e2cbfaa
firewall: move logging stdin argument to nft call 2022-09-21 10:08:52 +02:00
Thomas Haller
cfeecbedff
firewall: expose nm_firewall_nft_call() in header file 2022-09-21 10:08:52 +02:00
Thomas Haller
0a0c197916
firewall-utils: move _append() macro to be used by other places 2022-09-21 10:08:51 +02:00
Thomas Haller
dc66fb7d04
firewall/trivial: rename nm_firewall_config_apply() to nm_firewall_config_apply_sync()
Sync/blocking methods are ugly. Their name should highlight this.
Also, we may have an async variant, so we will need the "good" name
for apply() and apply_finish().
2022-09-21 10:08:35 +02:00
Thomas Haller
7362ad6266
firewall: more renaming and splitting _fw_nft_set_shared()
Blocking calls are ugly. Rename those to have a "_sync()" suffix.
Also, split from _fw_nft_set_shared() the part that constructs the
stdin for nft.
2022-09-19 18:51:39 +02:00
Thomas Haller
7ad3fb1956
firewall/trivial: rename nm_firewall_config_new() to nm_firewall_config_new_shared() 2022-09-19 18:51:38 +02:00
Thomas Haller
e185f7966d
firewall/trivial: rename "shared"/"add" argument in firewall utils to "up" 2022-09-19 18:51:37 +02:00
Thomas Haller
8a0aa2c8ac
bond: merge branch 'th/bond-opt-cleanup'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1380
2022-09-19 18:50:06 +02:00
Thomas Haller
b1a72d0f21
bond: use _nm_setting_bond_opt_value_as_intbool() in _platform_lnk_bond_init_from_setting()
Previously, we used _nm_utils_ascii_str_to_bool(). That can accept any
kind of input (like "true"), so one might think that this is better to
use on user-input. However, NMSettingBond already validates the these
options are integers (either "0" or "1"). So a value like "true"
could never be here.

Use _nm_setting_bond_opt_value_as_intbool() because that asserts that
the option if of the expected type (integer).
2022-09-19 13:05:52 +02:00
Thomas Haller
b7c56c3ae1
bond: make _platform_lnk_bond_init_from_setting() more readable via a macro
Use macros to make the code shorter and easier to read.
2022-09-19 13:05:52 +02:00
Thomas Haller
489a1b8f1e
bond: add _nm_setting_bond_opt_value_as_intbool() helper
Bond option values are just strings, however, some of them get
validated to be numbers, etc.

We also have effectively boolean values, like "use-carrier". Internally,
this is not validates as a boolean (_nm_utils_ascii_str_to_bool()) but
instead is an integer of either "0" or "1".

Add a helper function_nm_setting_bond_opt_value_as_intbool() to access
and parse such values.
2022-09-19 13:05:51 +02:00
Thomas Haller
a19458e11d
bond: assert integer range in _nm_setting_bond_opt_value_as_u{8,16,32}()
The bond setting does some minimal validation of the options.
At least for those number typed values, it validates that the
string can be interpreted as a number and is within a certain range.

Add nm_assert() checks to our opt_value_u$SIZE() functions, that the
requested option is validated to be in a range which is sufficiently
narrow to be converted to the requested type. If that were not the case,
we would need some special handling (or question whether the option should
be retrieved as this type).
2022-09-19 13:05:51 +02:00
Thomas Haller
692edc3bc5
nmcli: fix nmcli connection add -h output for optional ifname parameter
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/1089
2022-09-15 19:51:39 +02:00
Thomas Haller
98575bd513
initrd: generate initrd generator profiles with autoconnect-priority -100
... and profiles from firmware with autoconnect-priority -200.

In general, after switch root we remember the still activated profile in
/run, and NetworkManager would take over the device with the same
profile as before. In that case, autoconnect and autoconnect-priority
doesn't matter.

Autoconnect only matters when having a device in disconnected state and
not being blocked from autoconnect. For example, if you unplug and
replug the cable. In that case, it does make sense to me that
user-provided profiles from real-root are preferred.

To me the reasons for this change is not very strong (but neither are
the reasons against it). Read the discussion on rhbz #2089707.

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

Co-authored-by: Lubomir Rintel <lkundrak@v3.sk>

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1376
2022-09-15 18:23:57 +02:00
Thomas Haller
d8aacba3b2
platform: fix tracking similar objects in NMPGlobalTracker
NMPGlobalTracker allows to track objects for independent users/callers.
That is, callers that are not aware whether another caller tracks the
same/similar object. It thus groups all objects by their nmp_object_id_equal()
(as `TrackObjData` struct), while keeping a list of each individually tracked
object (as `TrackData` struct which honors the object and the user-tag parameter).

When the same caller (based on the user-tag) tracks the same object again, then
NMPGlobalTracker will only track it once and combine the objects. That is done by
also having a dictionary for the `TrackData` entries (`self->by_data`).

This latter dictionary lookup wrongly considered nmp_object_id_equal().
Instead, it needs to consider all minor differences of the objects, and
use nmp_object_equal().

For example, for NMPlatformMptcpAddress, only the "address" is part of
the ID. Other fields, like the MPTCP flags are not. Imagine a profile is
active with MPTCP endpoints configured with flags "subflow". During reapply,
the user can only update the MPTCP flags (e.g. to "signal"). When that happens,
the caller (NML3Cfg) would track a new NMPlatformMptcpAddress instance, that only
differs by MPTCP flags. In this case, we need to track the new address for the
differences that it has according to nmp_object_equal(), and not
nmp_object_id_equal().

Due to this bug, reapply might not work correctly. For other supported types (routing
rules and routes) this bug may have been harder to reproduce, because most attributes
of rules/routes are also part of the ID and because it's uncommon to reapply a minor
change to a rule/route.

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

Fixes: b8398b9e79 ('platform: add NMPRulesManager for syncing routing rules')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1375
2022-09-15 18:18:26 +02:00
Thomas Haller
1282d9c6b2
all: merge branch 'th/g-array-index'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1368
2022-09-15 18:14:05 +02:00
Thomas Haller
e6b9f6ecd0
contrib: discourage g_array_index() in "checkpatch.pl" 2022-09-15 12:39:08 +02:00
Thomas Haller
ffd8baa49f
all: use nm_g_array_{index,first,last,index_p}() instead of g_array_index()
These variants provide additional nm_assert() checks, and are thus
preferable.

Note that we cannot just blindly replace &g_array_index() with
&nm_g_array_index(), because the latter would not allow getting a
pointer at index [arr->len]. That might be a valid (though uncommon)
usecase. The correct replacement of &g_array_index() is thus
nm_g_array_index_p().

I checked the code manually and replaced uses of nm_g_array_index_p()
with &nm_g_array_index(), if that was a safe thing to do. The latter
seems preferable, because it is familar to &g_array_index().
2022-09-15 12:39:07 +02:00
Thomas Haller
07b32d5d22
glib-aux: add nm_g_array_index() macro and improve nm_g_array_index_p() macros
Add nm_g_array_index() as a replacement for g_array_index(). The value
of nm_g_array_index(), nm_g_array_index_p(), nm_g_array_first() and
nm_g_array_last() is that they add nm_assert() checks for valid
parameters.

nm_g_array_{first,last}() now returns an lvalue and not a pointer.
As such, they are just shorthands for nm_g_array_index() at index
0 and len-1, respectively.

`nm_g_array_index_p(arr, Type, idx)` is almost the same as
`&nm_g_array_index(arr, Type, idx)`. The only difference (and why the
former variant exists), is that nm_g_array_index_p() allows to get a
pointer one after the end.

This means, this is correct and valid to do:

   // arr->len might be zero
   arr = nm_g_array_index_p(arr, Type, 0);
   for (i = 0; i < arr->len; i++, arr++)
       ...

   ptr = nm_g_array_index_p(arr, Type, 0);
   end = nm_g_array_index_p(arr, Type, arr->len);
   for (; ptr < end; ptr++)
       ...

This would not be valid to do with nm_g_array_{index,first,last}().

Also fix supporting "const GArray *arr" parameter. Of course, the function
casts the constness away. Technically, that matches the fact that arr->data
is also not a const pointer. In practice, we might want to propagate the
constness of the container to the constness of the element lookup. While
doable, that is not implemented.
2022-09-15 12:39:06 +02:00
Thomas Haller
2c8dcbeaf9
all: use nm_g_array_append_new() at various places 2022-09-15 12:39:06 +02:00
Thomas Haller
ef8fa9f6aa
device/adsl: make argument of callback for platform-changed-signal const 2022-09-14 20:36:13 +02:00
Thomas Haller
c92fe1bfa0
bond: merge branch 'ff/bond_primary'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1362
2022-09-13 10:42:43 +02:00
Fernando Fernandez Mancera
4fd90fb6cc bond: fix primary bond option when the link is not present
Bond option netlink support requires primary property to be a ifindex
instead of the interface name. This is a workaround for supporting
specifying a primary that does not exist yet.

```
nmcli con add type bond ifname mybond0 bond.options "mode=active-backup,primary=veth1"
Connection 'bond-mybond0' (38100ef9-11e2-4003-aff9-cb2d152ce34f) successfully added.
nmcli con add type ethernet ifname veth1 master mybond0

cat /sys/class/net/mybond0/bonding/primary
veth1
```

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1362

Fixes: e064eb9d13 ('bond: use netlink to set bond options')
2022-09-13 10:32:40 +02:00
Thomas Haller
c28dd78c05 platform: use signed int for NMPlatformLnkBond.primary
On netlink API, the attribute is indeed u32. However, this is an ifindex
which in most other kernel APIs and in NetworkManager code is a signed
integer. Note that of course kernel would only ever assign numbers that
are valid ifindexes, thus in the suitable range.
2022-09-13 10:31:05 +02:00
Thomas Haller
6d95c406db platform: don't fallback to IFLA_BOND_ACTIVE_SLAVE for the primary
The IFLA_BOND_ACTIVE_SLAVE and IFLA_BOND_PRIMARY are not the same.
If the primary is not set, then that's it. Don't fallback.

Only NetworkManager API deprecated "active-slave" and uses it as
alias for "primary". That does not mean, kernel/netlink does that.
2022-09-13 10:30:58 +02:00
Thomas Haller
89cbe126c4
libnm-core-impl/tests: style fix 2022-09-13 09:51:45 +02:00
Wen Liang
6e2fd1b509
dummy: drop NM_DEVICE_DUMMY_GET_PRIVATE()
Unused, and wouldn't work because the private struct and field does not
exist.
2022-09-12 07:39:13 +02:00
Thomas Haller
5cfb9d9f78
contrib: setup "nm-in-container.sh" on start via rc.local script
We need to mount sysfs, so that `ip netns exec` works.
Do that automatically when starting the system container, via rc.local.

While at it, use `podman build --squash-all` to speedup the building of
the container image.
2022-09-09 17:46:00 +02:00
Thomas Haller
e27e250ef8
core: merge branch 'th/fix-print-config-duplicates'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1373
2022-09-09 16:24:26 +02:00
Thomas Haller
527061ed48
glib-aux/trivial: fix typo in code comment 2022-09-09 16:21:53 +02:00
Thomas Haller
f1c1d93bc5
core/config: use NM_STR_HAS_PREFIX() instead of g_str_has_prefix()
With C literals as prefix, this macro is more efficient as it
just expands to a strncmp(). Also, it accepts NULL string.
2022-09-09 16:21:53 +02:00
Thomas Haller
f6345180b1
core/config: fix duplicate entires in NetworkManager --print-config output
_nm_config_data_log_sort() is used for sorting the groups in the
keyfile during nm_config_data_log(). The idea is to present the keyfile
in a defined, but useful order.

However, it is not a total order. That is, it will return c=0 (equal) for
certain groups, if the pre-existing order in the GKeyFile should be
honored. For example, we want to sort all [device*] sections close to
each other, but we want to preserve their relative order. In that case,
the function would return 0 although the group names differed.

Also, _nm_config_data_log_sort() does not expect to receive duplicate names.
It would return c!=0 for comparing "device" and "device".

This means, _nm_config_data_log_sort() is fine for sorting the input as
we have it. However, it cannot be used to binary search the groups. This
caused that some sections might be duplicated in the `NetworkManager
--print-config` output. Otherwise, it had no bad effects.

Fixes(no-backport): 78d34d7c2e ('config: fix printing default values for missing sections')
2022-09-09 16:21:53 +02:00
Thomas Haller
e7f76d025f
build: fix regenerating "nm-property-infos-%.xml" files on changes
Imagine checking out the loopback feature branch and building. Thereby the
"src/libnm-client-impl/nm-property-infos-%.xml" files get generated
and contains a `<setting name="loopback"/>`.

Then switch back to `main` branch and type make again. Note that none
of the "src/libnm-core-impl/nm-setting-*.c" files changed, except that
"nm-setting-loopback.c" got removed.

Consequently, the XML won't be regenerated and the followup steps will
fail due to the leftover reference to the non-existing setting.

Fix that by regenerating "nm-property-infos-%.xml" if "libnm-core-impl.la"
changes.
2022-09-09 15:43:45 +02:00
Thomas Haller
a4cf48f8bc
glib-aux,platform: merge branch 'th/misc'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1370
2022-09-08 19:46:48 +02:00
Thomas Haller
bd6e60f2dc
platform: simplify nm_platform_ip_route_get_prune_list() to not reuse variables
This optimization seems unnecessary. Just initialize a new route struct
and use it. The advantage is that we can have the variable in the scope
closer to where it's used, and don't need to think about what happens
outside the scope.
2022-09-08 19:43:59 +02:00
Wen Liang
96d266cf51
platform: add NMPIPAddressSyncFlags parameter to nm_platform_ip_address_sync()
Previously, nm_platform_ip_address_sync() would always add the "IFA_F_NOPREFIXROUTE"
flag. Add a way to let the caller control that.

Add a flags argument, with a new flag "with-noprefixroute". By default
(with flags "none"), nm_platform_ip_address_sync() would no longer
add "IFA_F_NOPREFIXROUTE" flag, but the caller can now opt-in to that.

The purpose is that on "lo" interface we will want to let kernel
handle the prefix route. So have a per-ifindex opt-in for controlling
this.

During nm_platform_ip_address_flush() we use "none" flags, because the
function anyway doesn't add any addresses, so it wouldn't matter.

There is no change in behavior.

Co-authored-by: Thomas Haller <thaller@redhat.com>
2022-09-08 19:43:31 +02:00
Wen Liang
ef51d0f980
libnm-base,all: add and use NM_LOOPBACK_IFINDEX define
Co-authored-by: Thomas Haller <thaller@redhat.com>
2022-09-08 19:42:02 +02:00
Wen Liang
75349dc566
glib-aux: add "NM_IPV4LO_NETWORK" defines and similar
Co-authored-by: Thomas Haller <thaller@redhat.com>
2022-09-08 19:42:01 +02:00
Thomas Haller
c413d7c657
glib-aux: add NM_IN6ADDR_INIT() macro and use it 2022-09-08 19:42:01 +02:00
Thomas Haller
03bf4a3425
platform/tests: use NM_ETHER_ADDR_INIT() macro 2022-09-08 19:41:56 +02:00
Thomas Haller
70060d570b
libnm: avoid serializing "ipv6.addr-gen-mode" default to D-Bus
When serializing setting properties to GVariant/D-Bus, we usually
omit values that are set to the default. That is done by libnm(-core),
so it happens both on the daemon and client side. That might be
useful to avoid a large number of properties on D-Bus.

Before changing the default value for "ipv6.addr-gen-mode" ([1]), we
would not serialize the previous default value ("stable-privacy").
Now we would serialize the new default value ("default). This change
causes problems.

Scenario 1: have a profile in the daemon with "ipv6.addr-gen-mode=stable-privacy",
have an older daemon version before [1] and a newer client after [1]. Result:

  The daemon exposes the profile on D-Bus without the addr-gen-mode
  field (because it's the default). To the client, that is interpreted
  differently, as "ipv6.addr-gen-mode=default". This is already somewhat
  a problem.
  More severe is when modifying the profile, the client would now serialize
  the value "default" on D-Bus, which the older daemon rejects as invalid.
  That means, you could not modify the profile, unless also resetting
  addr-gen-mode to "stable-privacy" or "eui64".

You can imagine other scenarios where either the daemon or the client is
before/after change [1] and the addr-gen-mode is set to either "default"
or "stable-privacy". Depending on what scenario you look, that can either be
good or bad.

Scenario 1 is pretty bad, because it means `dnf upgrade NetworkManager
&& nmcli connection modify ...` will fail (if the daemon was not
restated). So try to fix Scenario 1, by also not serializing the new
default value on D-Bus. Of course, some of the scenarios will get
different problems, by exacerbating one side misunderstanding the actually
set value and interpreting a missing value on D-Bus wrongly.  But those
problems are likely less severe.

In case both client and daemon are older/newer than [1], it doesn't
matter either way. The problem happens with different version and is
caused by a change of the default value.

[1] e6a33c04eb

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1372
2022-09-08 17:32:16 +02:00
Thomas Haller
3a6a07e11e
man: update "--print-config" text in man NetworkManager 2022-09-08 16:19:11 +02:00
Thomas Haller
8686eb5927
contrib: fix syntax error in "configure-for-system.sh" 2022-09-08 15:29:10 +02:00
Lubomir Rintel
a1de6810df device: don't ignore external slave removals
We've been outright ignoring master-slave checks if the link ended up
without a master since commit 2e22880894 ('device: don't remove the
device from master if its link has no master').

This was done to deal with OpenVSwitch port-interface relationship,
where the interface's platform link lacked an actual master in platform
(what matters there is the OVSDB entry), but the fix was too wide.

Let's limit the special case to devices whose were not enslaved to
masters that lack a platform link, which pretty much happens for
OpenVSwitch only.

Morale: Write better commit messages of future you is going to be upset
Fixes: 2e22880894 ('device: don't remove the device from master if its link has no master')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1358
2022-09-08 12:17:50 +02:00
Thomas Haller
cfc36db2b7
release: bump version to 1.41.2 (development) 2022-09-08 10:31:30 +02:00