Commit graph

30278 commits

Author SHA1 Message Date
Thomas Haller
d2f71b273e
audit: handle error from audit_encode_nv_string()
audit_encode_nv_string() is documented that it might fail. Handle
the error.

Also, the returned string was allocated with malloc(). We must free
that with free()/nm_auto_free, not g_free()/gs_free.
2022-05-09 15:33:54 +02:00
Thomas Haller
9ee37e42e1
platform: reorder fields in __NMPlatformIPRoute_COMMON for tight packing 2022-05-09 15:22:45 +02:00
Thomas Haller
36409d0747
platform: use flexible array members for "NMPlatformIPAddress.address_ptr"/"NMPlatformIPRoute.network_ptr"
Try to workaround a coverity warning:

 30. NetworkManager-1.39.3/src/core/vpn/nm-vpn-connection.c:2000:
     overrun-buffer-val: Overrunning array "address.ax.address_ptr" of 1
     bytes by passing it to a function which accesses it at byte offset 3.
2022-05-09 15:20:35 +02:00
Lubomir Rintel
6525e8a7d7 merge: branch 'lr/gtkdoc'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1211
2022-05-06 18:50:26 +02:00
Lubomir Rintel
99d92e2f10 libnm-client: fix some comments
Correct the mismatched arguments and descriptions, likely a copy &
paste error.
2022-05-06 18:33:27 +02:00
Lubomir Rintel
a3174af914 libnm: fix placement of some "Since:" tags
libnm-client-impl/nm-client.c:8398: warning: multi-line since docs found
  libnm-client-impl/nm-device-macvlan.c:115: warning: multi-line since docs found
  libnm-client-impl/nm-device-vxlan.c:540: warning: multi-line since docs found
  libnm-client-impl/nm-device-vxlan.c:92: warning: multi-line since docs found
  libnm-core-impl/nm-setting-ethtool.c:41: warning: multi-line since docs found
  libnm-core-impl/nm-setting-ip-config.c:2475: warning: multi-line since docs found
  libnm-core-impl/nm-setting-ip-config.c:2504: warning: multi-line since docs found
2022-05-06 18:33:27 +02:00
Lubomir Rintel
649314ddaa libnm: replace nm-types.h by defining the types in respective headers
The typedefs in nm-types.h confuse gtkdoc-scan. It generates a
libnm-sections.txt file like this:

  <SECTION>
  <FILE>nm-types</FILE>
  <TITLE>NMDeviceOvs</TITLE>
  NMAccessPoint
  NMActiveConnection
  NMCheckpoint
  NMClient
  NMDevice
  ...

Note the wrongly picked title and, more importantly, the object types in
a bogus section. This in turn makes gtkdoc-mkdb fail to include the
property and signal documentation in appropriate sections.

Without nm-types.h, we need to mind the header dependencies. This means
that we need to order the headers that define types before the ones that
use them. Also, we need to break the depencency loops in few palces.
2022-05-06 18:33:27 +02:00
Thomas Haller
53cfb30beb
n-dhcp4: re-import git-subtree for 'src/n-dhcp4'
git subtree pull --prefix src/n-dhcp4 git@github.com:nettools/n-dhcp4.git master --squash
2022-05-06 13:49:04 +02:00
Thomas Haller
3a49d158e0 Squashed 'src/n-dhcp4/' changes from 64513e31c01a..e4af93228e37
e4af93228e37 probe: forget lease after a NAK
c39e1fe74463 connection: discard NAKs from other servers in SELECTING

git-subtree-dir: src/n-dhcp4
git-subtree-split: e4af93228e3772bbb443ec1237252e6a2f3e3dd7
2022-05-06 13:48:25 +02:00
Beniamino Galvani
e141cd45d6
n-dhcp4/probe: forget lease after a NAK
If we have a lease and we get a NAK renewing/rebinding it, the lease
is lost.

Without this, probe->current_lease remains set and after the next
DISCOVER/OFFER round, any call to n_dhcp4_client_lease_select() will
fail at:

        if (lease->probe->current_lease)
                return -ENOTRECOVERABLE;

As in:

 [5325.1313] dhcp4 (veth0): send REQUEST of 172.25.1.200 to 255.255.255.255
 [5325.1434] dhcp4 (veth0): received NACK from 172.25.1.1
 [5325.1435] dhcp4 (veth0): client event 3 (RETRACTED)
 [5325.1436] dhcp4 (veth0): send DISCOVER to 255.255.255.255
 [5325.1641] dhcp4 (veth0): received OFFER of 172.25.1.200 from 172.25.1.1
 [5325.1641] dhcp4 (veth0): client event (OFFER)
 [5325.1641] dhcp4 (veth0): selecting lease failed: -131 (ENOTRECOVERABLE)

Upstream: https://github.com/nettools/n-dhcp4/pull/33
Upstream: e4af93228e

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/993

e43b1791a3 ('Merge commit 'e23b3c9c3ac86b065eef002fa5c4321cc4a87df2' as 'shared/n-dhcp4'')
2022-05-06 10:23:03 +02:00
Thomas Haller
192864ed3d
c-list: re-import git-subtree for 'src/c-list'
git subtree pull --prefix src/c-list git@github.com:c-util/c-list.git main --squash
2022-05-06 10:02:17 +02:00
Thomas Haller
106825f7c5 Squashed 'src/c-list/' changes from a0970f12f1f4..b86ba656ac22
b86ba656ac22 c-list: add c_list_split()
76900e4e3625 build: align with new c-util style

git-subtree-dir: src/c-list
git-subtree-split: b86ba656ac22b00fe785b2f058123e807f97c109
2022-05-06 10:02:08 +02:00
Thomas Haller
e69f011d60
c-rbtree: re-import git-subtree for 'src/c-rbtree'
git subtree pull --prefix src/c-rbtree git@github.com:c-util/c-rbtree.git main --squash
2022-05-06 09:58:08 +02:00
Thomas Haller
8d2d37446d Squashed 'src/c-rbtree/' changes from 8aa7bd1828ee..9b9713aeb9ec
9b9713aeb9ec build: update docs
7d38954dfd69 c-rbtree: document c_rbtree_entry() better
401241d4db02 build: always build test-parallel
337eb6c06d48 build: declare meson dependency
5741c13745cc ci: switch to new c-util CI workflow
39f870caf0aa build: drop redundant _GNU_SOURCE
cd315e186cf0 build: define 'ptrace' option
a1fb0a3296ae build: drop old submodules
739c1e982d74 build: re-order build definitions alphabetically
e98d4ed5a863 build: rework dependency handling
f9dd3852b8de build: use both_libraries()

git-subtree-dir: src/c-rbtree
git-subtree-split: 9b9713aeb9eca98566a85c8c90a02942ea430819
2022-05-06 09:57:51 +02:00
Thomas Haller
c3b8ef3539
c-siphash: re-import git-subtree for 'src/c-siphash'
git subtree pull --prefix src/c-siphash git@github.com:c-util/c-siphash.git main --squash
2022-05-06 09:52:00 +02:00
Thomas Haller
2750002547 Squashed 'src/c-siphash/' changes from eb87a9c4a5b0..1da8a0d46bfd
1da8a0d46bfd build: align with new c-util style

git-subtree-dir: src/c-siphash
git-subtree-split: 1da8a0d46bfdf07dc263a33ea9f22682db7dbea0
2022-05-06 09:51:44 +02:00
Thomas Haller
2e2bc2a4c0
c-stdaux: re-import git-subtree for 'src/c-stdaux'
git subtree pull --prefix src/c-stdaux git@github.com:c-util/c-stdaux.git main --squash
2022-05-06 09:46:30 +02:00
Thomas Haller
1c260f5a96 Squashed 'src/c-stdaux/' changes from f20e1cf2dfb1..99fe83cd5698
99fe83cd5698 build: update copyright
344b3ca8ce29 build: declare meson dependency
0e0982fd327e ci: use v1 of cabuild
9d2dafc4aaa4 ci: enable matrix-mode
822e358e60bb ci: switch to new C-Util CI
45b322aa6fb4 ci: try out new cabuild workflow

git-subtree-dir: src/c-stdaux
git-subtree-split: 99fe83cd5698b406f1cd991989551aac299f3d29
2022-05-06 09:46:16 +02:00
Thomas Haller
ebe8a9b292
cloud-setup: merge branch 'th/cloud-setup-aliyun-primary-ip'
https://bugzilla.redhat.com/show_bug.cgi?id=2079849
2022-05-05 08:36:28 +02:00
Thomas Haller
7d71aff247
cloud-setup: only pass config-iface-data as user-data for async functions
From config_iface_data->get_config_data we have access to the other pointer
already. No need to allocate a user data.
2022-05-05 08:29:53 +02:00
Thomas Haller
1e696c7e93
cloud-setup: use union for NMCSProviderGetConfigIfaceData.priv
Use a union, it makes more sense.

Note that with union, C's struct initialization might not sufficiently
set all fields to the default. In practice yes, but theoretically in C
a NULL pointer and floats must not have all zero bits, so the following
is not guaranteed to work:

    struct {
        int some_field;
        union {
             void *v_ptr;
             int v_int;
        };
    } variable = {
        .some_field = 24,
    };

    assert(variable.union.v_ptr == 0);
    assert(variable.union.v_int == 0);

When initializing the variable, we should not rely on automatically
initialize all union members correctly. It cannot at the same time
set NULL pointers and zero integers -- well, on our architectures it
probably can, but not as far as guaranteed by C language.
We need to know which union field we are going to use and initialize
it explicitly.
As we know the provider type, we can do that.

Also, maybe in the future we need special free/unref calls when
destroying the type specific data in NMCSProviderGetConfigIfaceData.
As we know the provider, we can.

Note that having type specific data in NMCSProviderGetConfigIfaceData.priv
is a layering violation. But it is still simpler than implementing
type specific handlers (callbacks) or tracking the data somewhere else.
After all, we know at compile time all the existing provider types.
2022-05-05 08:29:53 +02:00
Thomas Haller
069946cda1
cloud-setup: track config-task-data in iface-data
Let NMCSProviderGetConfigIfaceData.get_config_data have a pointer to the
NMCSProviderGetConfigTaskData. This will allow two things:

- at several places we pass on `nm_utils_user_data_pack(get_config_data,
  config_iface_data)` as user data. We can avoid that, by just letting
  config_iface_data have a pointer to get_config_data.

- NMCSProviderGetConfigIfaceData contains a provider specific field
  "priv". That may also require special initialization or destruction,
  depending on the type. We thus need access to the provider type,
  which we have via iface_data->get_config_data->self.

Also let NMCSProviderGetConfigTaskData have a pointer "self" to the
NMCSProvider. While there was already the "task", which contains the
provider as source-object, this is more convenient.
2022-05-05 08:22:57 +02:00
Thomas Haller
191baf84e2
cloud-setup: reorder addresses to honor "primary_ip_address"
The order of IPv4 addresses matters, in particular if they are in
the same subnet. Kernel will mark all but the first one as "secondary".
In NetworkManager's ipv4.addresses, the first address is the primary.

It seems that on aliyun cloud, "private-ipv4s" URL may give the
addresses in arbitrary order. The primary can be fetched from
"primary-ip-address".

Fix that by also fetching "primary-ip-address". Then, resort the array
so that the primary is the first one in the list.

https://bugzilla.redhat.com/show_bug.cgi?id=2079849
2022-05-05 08:22:56 +02:00
Thomas Haller
298784aa92
release: bump version to 1.39.3 (development) 2022-05-04 14:59:31 +02:00
Yi Zhao
53952446a7
build/meson: add dependency libnm_client_public_dep for "libnm-client-test"
Fix parallel build error:
| In file included from ../NetworkManager-1.36.0/src/libnm-client-test/nm-test-utils-impl.c:10:
| ../NetworkManager-1.36.0/src/libnm-client-public/NetworkManager.h:47:10: fatal error: nm-enum-types.h: No such file or directory
|    47 | #include "nm-enum-types.h"
|       |          ^~~~~~~~~~~~~~~~~

Signed-off-by: Yi Zhao <yi.zhao@windriver.com>

Fixes: a03a03fbe9 ('libnm/tests: add static helper library "src/libnm-client-test/"')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1206
2022-05-04 08:56:58 +02:00
Beniamino Galvani
3fff6770f8 device: merge branch 'bg/enslave-async'
https://bugzilla.redhat.com/show_bug.cgi?id=2052441
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1202
2022-05-03 13:20:27 +02:00
Beniamino Galvani
af9ed3eb2f ovs: add FIXME about cancellable operations 2022-05-03 13:19:24 +02:00
Beniamino Galvani
c503f5b214 ovs: attach port asynchronously
The attach operation needs to be asynchronous as we should wait the
result from ovsdb.

https://bugzilla.redhat.com/show_bug.cgi?id=2052441
2022-05-03 13:19:24 +02:00
Beniamino Galvani
9fcbc6b37d device: make attach_port() asynchronous
For some device types the attach-port operation doesn't complete
immediately. NMDevice needs to wait that the operation completes
before proceeding (for example, before starting stage3 for the port).

Change attach_port() so that it can return TERNARY_DEFAULT to indicate
that the operation will complete asynchronously. Most of devices are
not affected by this and can continue returning TRUE/FALSE as before
without callback.
2022-05-03 13:19:24 +02:00
Beniamino Galvani
bcc958c411 device: rename {enslave,release}_slave() to {attach,detach}_port()
Rename the enslave_slave() and release_slave() device methods to
attach_port() and detach_port().
2022-05-03 13:19:23 +02:00
Beniamino Galvani
6f6c044739 ovsdb: fix memory leak
@error was leaked when created inside the function.

While at it, remove the goto.

Fixes: 830a5a14cb ('device: add support for OpenVSwitch devices')
2022-05-03 13:19:23 +02:00
Thomas Haller
f3db8049b7
NEWS: update
Resync latest changes from nm-1-38 branch.
2022-05-03 12:30:00 +02:00
Thomas Haller
7dda0b94bc
platform: merge branch 'th/platform-address-sync-one-by-one'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1200
2022-05-03 10:01:06 +02:00
Thomas Haller
9b930cd962
platform: simplify loop for IPv6 addresses in nm_platform_ip_address_sync() 2022-05-03 09:45:33 +02:00
Thomas Haller
b52941ac34
platform: fix handling IPv6 address index in nm_platform_ip_address_sync()
Fixes: 4a548423b9 ('core: change order/priority of static IPv6 addresses relative to autoconf6/DHCPv6')
2022-05-03 09:45:32 +02:00
Thomas Haller
a6fd641634
platform: re-configure one address at a time in nm_platform_ip_address_sync()
Try to do one change at a time when reconfiguring addresses, to not
remove several/all addresses at once.

For IP addresses, kernel cares about the order in which they were added.
This mostly affects source address selection, and the "secondary" flag
for IPv4 addresses. The order is thus related to the priority of an
address.

There is no direct kernel API to change the order. Instead, we have to
add them in the correct order. During a sync, if an address already
exists in the wrong order, we need to remove it, and re-add it.
Btw, with IPv4 addresses added first via netlink are the primary
address, while with IPv6 it's reverse.

Previously, we would first iterate over all addresses and remove those
that had a conflicting order. This means, that we would potentially
remove all addresses for a short while, before readding them. That seems
problematic.

Instead, first track all addresses that are in the wrong order. And in
the step when we add/update the address, remove it. We now only remove
and address shortly before re-adding it. This way the time for which the
address on the interface is missing is shorter. More importantly, we will
never remove all addresses at the same time.
2022-05-03 09:45:32 +02:00
Beniamino Galvani
ee7240783a dhcp: merge branch 'bg/dhcp-lease-rundir'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1190
2022-05-03 09:14:06 +02:00
Beniamino Galvani
6ab5c4e578 core: save DHCP lease information in state file in /run
DHCP leases for a given interface are already exported on D-Bus
through DHCP4Config and DHCP6Config objects. It is useful to have the
same information also available on the filesystem so that it can be
easily used by scripts.

NM already saves some information about DHCP leases in /var, however
that directory can only be accessed by root, for good reasons.

Append lease options to the existing state file
/run/NetworkManager/devices/$ifindex. Contrary to /var this directory
is not persistent, but it seems more correct to expose the lease only
when it is active and not after it expired or after a reboot.

Since the file is in keyfile format, we add new [dhcp4] and [dhcp6]
sections; however, since some options have the same name for DHCPv4
and DHCPv6, we add a "dhcp4." or "dhcp6." prefix to make the parsing
by scripts (e.g. via "grep") easier.

The option name is the same we use on D-Bus. Since some DHCPv6 options
also have a "dhcp6_" prefix, the key name can contain "dhcp6" twice.

The new sections look like this:

  [dhcp4]
  dhcp4.broadcast_address=172.25.1.255
  dhcp4.dhcp_lease_time=120
  dhcp4.dhcp_server_identifier=172.25.1.4
  dhcp4.domain_name_servers=172.25.1.4
  dhcp4.domain_search=example.com
  dhcp4.expiry=1641214444
  dhcp4.ip_address=172.25.1.182
  dhcp4.next_server=172.25.1.4
  dhcp4.routers=172.25.1.4
  dhcp4.subnet_mask=255.255.255.0

  [dhcp6]
  dhcp6.dhcp6_name_servers=fd01::1
  dhcp6.dhcp6_ntp_servers=ntp.example.com
  dhcp6.ip6_address=fd01::1aa
2022-05-03 09:12:12 +02:00
Beniamino Galvani
96d8637ced core: add nm_dhcp_config_get_option_values()
Introduce a function to return an array of name-value tuples for DHCP
options.
2022-05-03 09:08:16 +02:00
Beniamino Galvani
15a4211303 dhcp: fix logging domain
Fix wrong domain when logging a lease:

  dhcp6 (veth0):   valid_lft 7200
  dhcp6 (veth0):   preferred_lft 5400
  dhcp6 (veth0):   address fd00:db8:db8::11:2233:4455
  dhcp (veth0):   domain search 'domain'
2022-05-03 09:07:29 +02:00
Beniamino Galvani
f20ac6bdc7 dhcp: improve logging for DHCPv6 merged leases
Instead of logging the event-id, which is composed from options that
are already visible in the log, it's more interesting to log that the
lease was merged.
2022-05-03 09:07:29 +02:00
Thomas Haller
e5d4194673
build/meson: avoid compiler warning generating "NM-1.0.gir"
In glib_dep we specify

  "-DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_40 -DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_40"

which is the dependency we use almost everywhere. With g-ir-scanner
this causes compiler warnings:

    [xxx] Generating NM-1.0.gir with a custom command
    /src/NetworkManager/build/tmp-introspectnas6f9u5/NM-1.0.c: In function ‘dump_object_type’:
    /src/NetworkManager/build/tmp-introspectnas6f9u5/NM-1.0.c:252:13: warning: Not available before 2.70
      252 |   if (G_TYPE_IS_FINAL (type))
          |             ^~~~~~~~~~~~~~~~~
    /src/NetworkManager/build/tmp-introspectnas6f9u5/NM-1.0.c: In function ‘dump_fundamental_type’:
    /src/NetworkManager/build/tmp-introspectnas6f9u5/NM-1.0.c:370:13: warning: Not available before 2.70
      370 |   if (G_TYPE_IS_FINAL (type))
          |             ^~~~~~~~~~~~~~~~~
    g-ir-scanner: link: gcc -o /src/NetworkManager/build/tmp-introspectnas6f9u5/NM-1.0 /src/NetworkManager/build/tmp-introspectnas6f9u5/NM-1.0.o -L. -Wl,-rpath,. -Wl,--no-as-needed -L/src/NetworkManager/build/src/libnm-client-impl -Wl,-rpath,/src/NetworkManager/build/src/libnm-client-impl -lnm -lgio-2.0 -lgobject-2.0 -lglib-2.0 -lgmodule-2.0 -ludev -lgirepository-1.0 -lgio-2.0 -lgobject-2.0 -Wl,--export-dynamic -lgmodule-2.0 -pthread -lglib-2.0 -lglib-2.0

Work around that.

Meson's gnome.generate_gir() is not very flexibly in allowing to
pass extra `--cflags-begin {} --cflags-end` parameters.
Hack around by adding a pseudo dependency that resets
these defines.

See-also: https://gitlab.gnome.org/GNOME/gobject-introspection/-/merge_requests/331
See-also: 1234e5583a ('build/autotools: avoid compiler warning generating "NM-1.0.gir"')
2022-05-02 22:05:06 +02:00
Thomas Haller
7fd6804e2a
tests/client: improve readme for how to get test-client.py regenerate the test data 2022-05-02 19:03:32 +02:00
Thomas Haller
3ce3ed4c92
examples: improve finding last checkpoint in "checkpoint.py"
This is a python example. We should do nice things, like
using max() for finding the maximum, instead of sorting.
2022-05-02 18:04:37 +02:00
Thomas Haller
6a04bcc59d
core: transfer ownership of strbuf data in _fw_nft_set()
In practice there is little difference.

Previously, "strbuf" would own the string until the end of the function,
when the "nm_auto_str_buf" cleanup attribute destroys it. In the
meantime, we would pass it on to _fw_nft_call_sync(), which in fact
won't access the string after returning.

Instead, we can just transfer ownership to the GBytes instance. That seems
more logical and safer than aliasing the buffer owned by NMStrBuf with
a g_bytes_new_static(). That way, we don't add a non-obvious restriction
on the lifetime of the string. The lifetime is now guarded by the GBytes
instance, which, could be referenced and kept alive longer.

There is also no runtime/memory overhead in doing this.
2022-05-02 16:43:42 +02:00
Adrian Freihofer
04ce34d8dc version: add 1.40 macros 2022-05-01 14:12:20 +02:00
Thomas Haller
e766ca4e7c
contrib: improve nm-in-container.d scripts
Get `ip netns exec` to work. Now we can start stuff in their
own namespace, which is much cleaner.
2022-04-28 19:33:14 +02:00
Thomas Haller
bf058554bd
platform: reorder fields to pack structs in "nm-platform.h" 2022-04-28 16:45:02 +02:00
Thomas Haller
f1f8ae5a83
libnm: drop NM_DEPRECATED_IN_1_2/NM_AVAILABLE_IN_1_2 macros from structs in libnm headers
On rhel-8.7, we are going to no longer use the pre-generated docs, but
instead generate them on build time with "gtk-doc-1.28-4.el8".

That version of gtk-doc has problems with these deprecated/available
macros on the structs, so it will generate:

  /usr/share/gtk-doc/html/libnm/libnm-nm-vpn-service-plugin.html
  /usr/share/gtk-doc/html/libnm/libnm-nm-vpn-plugin-old.html

instead of

  /usr/share/gtk-doc/html/libnm/NMVpnServicePlugin.html
  /usr/share/gtk-doc/html/libnm/NMVpnPluginOld.html

Newer gtk-doc versions don't have this problem.

But as we usually don't use these macros on typedefs (only on functions), and as
1.2 is very old already, it seems simpler to just drop this (instead of
fixing gtk-doc).

See-also: https://bugzilla.redhat.com/show_bug.cgi?id=1995915
2022-04-28 16:39:42 +02:00
Thomas Haller
0ddc664526
trivial: fix code format 2022-04-28 13:39:23 +02:00