Commit graph

26225 commits

Author SHA1 Message Date
Thomas Haller
030d68aef7
shared: add nm_assert() to "nm-std-aux.h"
Having assertion macros that are disabled by default, is not
only useful for our glib code, but should also be available
for nm-std-aux. Move the macros.
2020-07-06 11:45:37 +02:00
Thomas Haller
5dd923cd86
shared: add "nm-std-aux/nm-std-aux.h" header
"nm-std-aux" is an utility library that has no glib depdencency. That
is the difference to "nm-glib-aux".
2020-07-06 11:10:43 +02:00
Beniamino Galvani
15492e6c50 ovs: merge branch 'bg/ovs-mac-pt2'
https://bugzilla.redhat.com/show_bug.cgi?id=1852106
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/557
2020-07-06 09:45:33 +02:00
Beniamino Galvani
77b6ce7d04 device: don't reset the MAC without ifindex
nm_device_cleanup() can be called when the device no longer has an
ifindex. In such case, don't try to reset the MAC address as that
would lead to an assertion failure.
2020-07-06 09:44:16 +02:00
Beniamino Galvani
47ec3d14d4 ovs: also set cloned MAC address via netlink
We already set the MAC of OVS interfaces in the ovsdb. Unfortunately,
vswitchd doesn't create the interface with the given MAC from the
beginning, but first creates it with a random MAC and then changes it.

This causes a race condition: as soon as NM sees the new link, it
starts IP configuration on it and (possibly later) vswitchd will
change the MAC.

To avoid this, also set the desired MAC via netlink before starting IP
configuration.

https://bugzilla.redhat.com/show_bug.cgi?id=1852106
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/483
2020-07-06 09:44:16 +02:00
Beniamino Galvani
5d4c8521a3 ovs: set MAC address on the bridge for local interfaces
When a user creates a ovs-interface with the same name of the parent
ovs-bridge, openvswitch considers the interface as the "local
interface" [1] and assigns the MAC address of the bridge to the
interface [2].

This is confusing for users, as the cloned MAC property is ignored in
some cases, depending on the ovs-interface name.

Instead, detect when the interface is local and set the MAC from the
ovs-interface connection in the bridge table.

[1] https://github.com/openvswitch/ovs/blob/v2.13.0/vswitchd/vswitch.xml#L2546
[2] https://github.com/openvswitch/ovs/blob/v2.13.0/vswitchd/bridge.c#L4744
2020-07-06 09:44:16 +02:00
Beniamino Galvani
fbac6217b1 initrd: merge branch 'bg/initrd-bootif'
https://bugzilla.redhat.com/show_bug.cgi?id=1853277
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/562
2020-07-03 22:10:35 +02:00
Beniamino Galvani
5fa97d7796 initrd: write the hostname to stdout with --stdout
Don't try to open /run/NetworkManager/initrd when called with
--stdout, but instead write the hostname to the standard output.

Fixes: ff70adf873 ('initrd: save hostname to a file in /run')
2020-07-03 22:08:22 +02:00
Beniamino Galvani
3023c70e4e initrd: fix generating default BOOTIF= connection
There is a bug when parsing a BOOTIF= without any existing
connection. The generated connection doesn't have wired setting and
later we try to access it:

 # nm-initrd-generator --stdout -- BOOTIF=01-50-50-00-9f-21-21
  (nm-initrd-generator:1546): libnm-CRITICAL **: ((libnm-core/nm-setting-wired.c:205)): assertion '<dropped>' failed
  (nm-initrd-generator:1546): GLib-GObject-CRITICAL **: g_object_set: assertion 'G_IS_OBJECT (object)' failed

Fix this.

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

Fixes: 25a2b6e14f ('initrd: rework command line parsing')
2020-07-03 22:08:22 +02:00
Beniamino Galvani
79f70bf5d6 initrd: fix generation of MTU and cloned-mac-address for masters
Setting a MTU or a cloned MAC for bonds/bridges/teams fails with:

 # nm-initrd-generator -- bond=bond0:eno1,eno2:mode=802.3ad
    ip=192.168.1.5::192.168.1.254:255.255.255.0:MyServer:bond0:none::01:02:03:04:05:06
    bootdev=bond0 nameserver=192.168.1.1

 <warn> cmdline-reader: 'bond' does not support setting cloned-mac-address

Fix this.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/460
2020-07-03 22:02:34 +02:00
Thomas Haller
b2f03544a7
ndisc/tests: fix assertion in "test-ndisc-fake.c"
First I wanted to fix

  test:ERROR:../src/ndisc/tests/test-ndisc-fake.c:373:test_preference_changed_cb: assertion failed (_a->timestamp == (data->timestamp1 + 3)): (9 == 10)

but that leads to a different failure:

  test:ERROR:../src/ndisc/tests/test-ndisc-fake.c:375:test_preference_changed_cb: assertion failed (_a->lifetime == (9)): (10 == 9)

Instead, the start and end times must match exact (in their duration),
we only allow them to be shifted by up to one second.

Fixes: 8209095ee1 ('ndisc/tests: relax the assertion in "test-ndisc-fake.c"')
2020-07-03 19:29:46 +02:00
Thomas Haller
4af93f848d
cloud-setup: fix invalid assertion in nm_http_client_get_finish()
Fixes: 53bdd81800 ('cloud-setup: ensure that nm_http_client_get_finish() always returns success or error')
2020-07-03 19:03:32 +02:00
Thomas Haller
2a1e621704
cli: suppress "(unknown)" output in terse mode for device properties HWADDR and DRIVER
$ nmcli -f GENERAL.HWADDR device show ovsport0
  GENERAL.HWADDR: (unknown)

but:

  $ nmcli -f GENERAL.HWADDR --terse device show ovsport0
  GENERAL.HWADDR:

This is an API change of nmcli.
2020-07-03 11:40:11 +02:00
Thomas Haller
05a84be550
cli: add nmc_meta_generic_get_str_i18n_null() helper 2020-07-03 11:37:45 +02:00
Sayed Shah
7337ab8959
all: fix typo in man pages
There should be a comma after 'Otherwise' and 'Currently'.

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

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/560
2020-07-03 10:48:04 +02:00
Thomas Haller
66e2d8c38a
cloud-setup: merge branch 'th/cloud-setup-various'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/553
2020-07-03 10:41:46 +02:00
Thomas Haller
9702f79db6
cloud-setup: don't check redundant error results from nm_http_client_poll_get_finish()
nm_http_client_poll_get_finish() can only either succeed (returning TRUE
and setting no GError), or failing (returning FALSE and setting GError).

Checking for both is redundant and unnecessary.
2020-07-03 10:34:29 +02:00
Thomas Haller
53bdd81800
cloud-setup: ensure that nm_http_client_get_finish() always returns success or error 2020-07-03 10:34:29 +02:00
Thomas Haller
eb2dfa9b41
cloud-setup: always report success or an GError from nm_http_client_poll_get_finish()/nmcs_utils_poll_finish()
Since commit 3bd30f6064 ('nmcs: add error message when a HTTP request times
out'), the case where polling returns %FALSE without an error is no
longer possible. This is preferable, because it follows a consistent
API where a function clearly fails or succeeds.

So, checking for the error code and the returned boolean is redundant and
unnecessary.
2020-07-03 10:34:29 +02:00
Thomas Haller
ceb75f8ab4
cloud-setup: remove debugging message from _poll_cancelled_cb() 2020-07-03 10:34:28 +02:00
Thomas Haller
2fbc8717ca
cloud-setup: use stack allocated buffer for temporary strings in "nmcs-provider-gcp.c"
The maximum length of these strings is known and small. Use
a buffer on the stack for them.
2020-07-03 10:34:28 +02:00
Thomas Haller
3d61b28941
cloud-setup: don't use a GString in loop in _get_net_ifaces_list_cb()
nm_utils_parse_next_line() operates on the response buffer obtained
from NMHttpClient. We own this buffer, and we also can rely on the fact
that the buffer has a trailing NUL byte after the data.

There is no need to copy the string to a GString, just use it directly.
2020-07-03 10:34:28 +02:00
Thomas Haller
62aec7acd3
cloud-setup: don't use a GString in _get_config_ips_list_cb()
nm_utils_parse_next_line() operates on the response buffer obtained
from NMHttpClient. We own this buffer, and we also can rely on the fact
that the buffer has a trailing NUL byte after the data.

There is no need to clone the string to a GString, just use it directly.
2020-07-03 10:34:28 +02:00
Thomas Haller
c9c54709b8
cloud-setup: use NMStrBuf in NMHttpClient to track response 2020-07-03 10:34:27 +02:00
Thomas Haller
39733352d6
cloud-setup: use NMStrBuf in nmcs_utils_uri_build_concat_v() 2020-07-03 10:34:27 +02:00
Thomas Haller
4f542384c3
cloud-setup: use nm_utils_parse_next_line() in _get_config_metadata_ready_check()
nm_utils_parse_next_line() has more flexible handling of line endings
(for example, also accpting "\0", "\r", "\r\n"). Use it.
2020-07-03 10:34:27 +02:00
Thomas Haller
e2bd722358
shared: refactor nm_utils_parse_next_line() and add tests
- add unit test for nm_utils_parse_next_line()

- as line delimiter also accept "\r\n" and "\r" (beside "\n", "\0" and
  EOF).

- fix returning lines with embedded "\0" characters. The line ends
  on the first "\n" or "\0", whatever comes first. The code before
  didn't ensure that with:

     line_end = memchr (line_start, '\n', *inout_len);
     if (!line_end)
         line_end = memchr (line_start, '\0', *inout_len);
2020-07-03 10:34:27 +02:00
Thomas Haller
e7357419cd
shared: add nm_str_buf_finalize_to_gbytes() helper 2020-07-03 10:34:26 +02:00
Thomas Haller
befd971b45
cloud-setup: assert that NMHttpClient returns NUL terminated buffer
The behavior is documented at various places, so this assert is less
to actually assert it, but as making this condition obvious to the
reader of the code.
2020-07-03 10:34:26 +02:00
Thomas Haller
e3bbd267c3
cloud-setup: add gtk-doc comment for nm_http_client_get_finish()
NMHttpClient guarantees that the returned response is %NUL terminated after the
returned length of the buffer. That guarantee is important and should be documented.
2020-07-03 10:34:26 +02:00
Thomas Haller
460afe6d50
cloud-setup: fix allocating buffer for GetConfigMetadataMac in _get_config_metadata_ready_check()
It's not a severe issue, because the GetConfigMetadataData struct is
larger than GetConfigMetadataMac.

Fixes: 69f048bf0c ('cloud-setup: add tool for automatic IP configuration in cloud')
2020-07-03 10:34:26 +02:00
Thomas Haller
8209095ee1
ndisc/tests: relax the assertion in "test-ndisc-fake.c"
test:ERROR:../src/ndisc/tests/test-ndisc-fake.c:373:test_preference_changed_cb: assertion failed (_a->timestamp == (data->timestamp1 + 3)): (9 == 10)
2020-07-03 10:34:15 +02:00
Beniamino Galvani
2c50438987 device: restart DHCP only for devices that are active or activating
do_sleep_wake() tries to restart DHCP for all devices, even ones that
are disconnecting. When a device is disconnecting, it still has a DHCP
client instance but we shouldn't restart it because it makes no sense;
and especially, the device could be already removed.

https://bugzilla.redhat.com/show_bug.cgi?id=1852612
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/561
2020-07-03 09:31:35 +02:00
Thomas Haller
9fa59c156b
gitlab-ci: check "examples/python/gi/nm-wg-set" with black 2020-07-02 17:44:29 +02:00
Thomas Haller
38b7556c65
build: check "examples/python/gi/nm-wg-set" with black 2020-07-02 17:44:21 +02:00
Thomas Haller
1acd64b7a2
examples: run python black on "examples/python/gi/nm-wg-set"
black by default only considers files that have a ".py" extension.
2020-07-02 17:37:12 +02:00
Thomas Haller
3b896cc642
ndisc/tests: make assertion checks a macro and not a function in test-ndisc-fake
By having it a function, the assertion failure does not show the line
number of the origin. Make them a macro, so that we see where exactly it
failed.
2020-07-02 16:28:49 +02:00
Beniamino Galvani
76baf6e0ba wifi: merge branch 'bg/ap-isolation'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/469
2020-07-01 17:47:53 +02:00
Beniamino Galvani
4db4801038 supplicant,device: support AP isolation
Support setting the ApIsolate property of the supplicant interface
during association and resetting it to zero during disconnection.
2020-07-01 17:36:20 +02:00
Beniamino Galvani
dbfe219d5b all: add ap-isolation property to wifi setting
Add a new 'ap-isolation' property to the wifi setting, useful to
prevent communication between wireless clients.
2020-07-01 17:36:20 +02:00
Beniamino Galvani
47817a576c ifcfg-rh: add generic shvar getter and setter for ternary variables 2020-07-01 17:36:20 +02:00
Thomas Haller
1cf11ccbca
libnm: fix leak in nm_utils_is_json_object()
Fixes: 32f78ae6c3 ('libnm: expose nm_utils_is_json_object() utility function')
2020-07-01 15:42:06 +02:00
Thomas Haller
03dc759026
modem: suppress deprecated warning from libmm for MM_MODEM_CAPABILITY_LTE_ADVANCED
On Ubuntu 20.10, we build against ModemManager 1.14.0 and get a compiler warning:

  ../src/devices/wwan/nm-modem-broadband.c: In function 'try_create_connect_properties':
  ../src/devices/wwan/nm-modem-broadband.c:492:2: error: 'MMModemCapabilityDeprecated' is deprecated [-Werror=deprecated-declarations]
    492 |  if (MODEM_CAPS_3GPP (ctx->caps)) {
        |  ^~

Suppress it.

An alternative would be to drop the flag entirely. It seems the flag
was never used (and never will be used). But if that's true, there is
little harm done checking it. If it's not true, we better keep checking
for older versions.

0cd76bf1c4
2020-06-30 18:00:33 +02:00
Thomas Haller
3d542b55ed
platform/tests: avoid test failures accepting route added signals
/route/ip6: NMPlatformSignalAssert: ../src/platform/tests/test-route.c:331, test_ip6_route(): failure to accept signal [0,2] times: ip6-route-changed-added ifindex 0 (3 times received)
2020-06-30 17:23:45 +02:00
Beniamino Galvani
5423a92b0f wifi: renew dynamic IP configuration after roaming
There are some APs that require a DHCP transaction before allowing
other traffic. This is meant to improve security by preventing the use
of static addresses. Currently we don't renew DHCP after roaming to a
new AP and this can lead to broken connectivity with APs that
implement the check described above. Also, even if unlikely, the new
AP could be in a different layer 3 network and so the old address
could be no longer valid.

Renew dynamic IP configuration after we detect the supplicant decided
to roam to a new AP. Note that we only trigger a DHCP client restart;
the DHCP client already implements the logic to renew the previous
address and fall back to a full request in case of NAK or timeout.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/449
2020-06-30 17:08:56 +02:00
Thomas Haller
f1af22452d
ifcfg-rh,libnm: merge branch 'th/ifcfg-bridge-writer'
https://bugzilla.redhat.com/show_bug.cgi?id=1845608

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/554
2020-06-30 16:31:47 +02:00
Thomas Haller
b9aa7ef81c
libnm/doc: clarify values for "bridge.multicast-router"
Kernel (sysfs) and iproute2 only use numbers for the multicast_router
option. It's confusing that we name the options differently. Anyway,
that cannot be changed anymore. Clarify the meanings in the
documentation.

https://bugzilla.redhat.com/show_bug.cgi?id=1845608
2020-06-30 16:30:38 +02:00
Thomas Haller
13327555d6
ifcfg-rh: hard code the defaults for bridge settings in write_bridge_setting()
Code like "get_setting_default_uint (s_bridge, NM_SETTING_BRIDGE_FORWARD_DELAY)" looks
up the default value of the GObject property. That default value is
known at build type. Looking it up is an unnecessary overhead, for
something that is already known.

Also, the code isn't generic (meaning, it doesn't iterate of a set of
properties names and treats them without explicitly naming each
property). If we already name the property for which we want the default
value, we can just as well name the default value.

Additionally, add an assertion that what we would look up matches
to what we think is the default.
2020-06-30 16:30:38 +02:00
Thomas Haller
58d193432d
ifcfg-rh: use guint type for handling nm_setting_bridge_get_ageing_time() return value
It returns guint, not guint32. Use the appropriate type.
2020-06-30 16:30:37 +02:00
Thomas Haller
15ec888597
ifcfg-rh: use nm_gstring_add_space_delimiter() in write_bridge_setting() 2020-06-30 16:30:34 +02:00