Commit graph

1871 commits

Author SHA1 Message Date
Thomas Haller 70971d1141
all: avoid wrong compiler warning about uninitalized variables with LTO
Seems with LTO the compiler can sometimes think that thes variables are
uninitialized. Usually those code paths are only after an assertion was
hit (g_return*()), but we still need to workaround the warning.
2020-08-17 15:18:02 +02:00
Thomas Haller 3df662f534
settings: rework wait-device-timeout handling and consider device compatibility
A profile can configure "connection.wait-device-timeout" to indicate
that startup complete is blocked until a suitable device around.
This is useful for NetworkManager-wait-online and initrd mode.

Previously, we looked at NMPlatform whether a link with matching
interface-name was present. That is wrong because it cannot handle
profiles that rely on "ethernet.mac-address" setting or other "match"
settings. Also, the mere presence of the link does not yet mean
that the NMDevice was created and ready. In fact, there is a race here:
NMPlatform indicates that the device is ready (unblocking NMSettings),
but there is no corresponding NMDevice yet which keeps NetworkManager
busy to block startup complete.

Rework this. Now, only check whether there is a compatible device for
the profile.

Since we wait for compatible devices, it works now not only for the
interface name. Note that we do some optimizations so that we don't have
to re-evaluate all profiles (w.r.t. all devices) whenever something on the
device changes: we only care about this when all devices finally become
ready.

Also, we no longer start the timeout for "connection.wait-device-timeout"
when the profile appears. Instead, there is one system-wide start time
(NMSettingsPrivate.startup_complete_start_timestamp_msec). That simplifies
code and makes sense: we start waiting when NetworkManager is starting, not
when the profile gets added. Also, we wait for all profiles to become
ready together.
2020-08-12 16:40:56 +02:00
Thomas Haller 4c94a9736b
cloud-setup: rework error handling and completion for EC2 provider
Make the error handling similar to the other provider implementations.

- only actually return once all callbacks completed.

- cache the first error and report it.
2020-07-30 09:18:40 +02:00
Thomas Haller 9887ea5b61
cloud-setup: cleanup error handling in Azure provider
- drop AzureData.success field. It is redundant to have AzureData.error set.
  Also it was actually unused.

- ensure that we keep the first error passed during
  _get_config_maybe_task_return(). Once we set an error, that error gets
  returned. There is a twist here, that we prefer cancellation errors
  over other error reasons.
2020-07-30 09:18:40 +02:00
Thomas Haller 2582694b46
cloud-setup: cleanup error handling in GCP provider
- drop GCPData.success field. It is redundant to have GCPData.error set.
  Also, it's meaningless to indicate failure, if we don't have an error
  at hand.

- ensure that we keep the first error passed during
  _get_config_maybe_task_return(). Once we set an error, that error gets
  returned. There is a twist here, that we prefer cancellation errors
  over other error reasons.

- in _get_config_fip_cb(), ensure to call _get_config_maybe_task_return()
  even if we are not yet ready. That is useful to record a potential
  error.
2020-07-30 09:18:40 +02:00
Sayed Shah df6cdd4315
cloud-setup: fix the host address for azure
Fixes: e7ac7290bd ('cloud-setup: add tool for automatic IP configuration in cloud')
2020-07-30 09:16:42 +02:00
Sayed Shah e7ac7290bd
cloud-setup: add tool for automatic IP configuration in cloud
This is a tool for automatically configuring networking in azure
cloud environment.

This add a provider implementation for Azure that when detected fetches
the private ip addressess and the subnet prefix of configured internal
load balancers.

Once this information is fetched from the metadata server, it instructs
NetworkManager to add private ip addressess and subnet prefix for each
interface detected.

It is inspired by SuSE's cloud-netconfig ([1], [2]) and Azure Instance Metadata service [3].

[1] https://www.suse.com/c/multi-nic-cloud-netconfig-ec2-azure/
[2] https://github.com/SUSE-Enceladus/cloud-netconfig
[3] https://docs.microsoft.com/en-us/azure/virtual-machines/linux/instance-metadata-service

It is also intended to work without configuration. The main point is
that you boot an image with NetworkManager and nm-cloud-setup enabled,
and it just works.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/572
2020-07-29 15:56:15 +02:00
Thomas Haller e73bd2cf5f
cloud-setup: always replace addresses, routes and rules in _nmc_mangle_connection()
If the list of addresses, routes and rules is empty, we still want to mangle
the applied connection, to also have an empty list.

nm-cloud-setup has certain expectations. For example, that the static addresses,
routes and rules of the active connection is entirely under the control of the
tool. For example, so it usually replaces the lists entirely. It also should do
that, if the new list is empty.

Maybe, one day there could be more complex merging strategies, where the user could
also add static addresses, routes, or rules to the profile, and nm-cloud-setup
would preserve them. However, that is not implemented, nor is it clear how exactly
that would work.
2020-07-20 19:02:57 +02:00
Thomas Haller ba42189bb9
all: add trailing semicolon to NM_UTILS_LOOKUP_DEFINE()/NM_GOBJECT_PROPERTIES_DEFINE*() 2020-07-19 12:12:58 +02:00
Thomas Haller b17e3cf707
all: add trailing semicolon to NM_AUTO_DEFINE_FCN_*() uses 2020-07-19 12:01:56 +02:00
Sayed Shah e3cd3b73ed
cloud-setup: don't require delimiter in 'nmcs_utils_hwaddr_normalize'
Azure gives MAC address without delimiter. So, make the normalize function
more liberal so that it can accept this format.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/576
2020-07-14 19:10:29 +02:00
Thomas Haller 5deb71625d
cli: fix leak in do_device_modify() and minor cleanup 2020-07-13 17:16:28 +02:00
Thomas Haller 09c94bc24f
cli: fix accessing argv with zero elements in nmc_process_connection_properties()
Without this, `nmcli device modify "$DEVICE"` leads to a crash. At least
since commit c5d45848dd ('cli: mark argv argument for command line
parsing as const'), when this happens.

That is, because it passes a NULL strv array with argc being set to
zero. nmc_process_connection_properties() is not supposed to access
the array, if there are no elements there.

Fixes: c5d45848dd ('cli: mark argv argument for command line parsing as const')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/492
2020-07-13 17:15:56 +02:00
Frazer Clews 16abfca78a
cloud-setup: fix nmcs_utils_poll argument ordering
the order of the arguments in the header and C file did not match

Fixes: 69f048bf0c ('cloud-setup: add tool for automatic IP configuration in cloud')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/574
2020-07-13 13:13:58 +02:00
Thomas Haller 61d4bc62e0
tui: fix default values for bond options in nmtui
When configuring miimon settings, the updelay/downdelay fields with
value zero may not be stored in the setting.

For example:

- have a profile with "mode=balance-rr,arp_interval=11,arp_ip_target=10.10.10.1,miimon=10"
  Switch the link monitoring mode to "MII" and press <OK>. Previously,
  the change of the link monitoring did not update the settings, and
  nothing was changed.

- when loading settings, initialize all fields with the values from the
  settings, regardless whether they are currently visible or not.
  Otherwise, if you edit a profile with
  "mode=balance-rr,arp_interval=11,arp_ip_target=10.10.10.1,miimon=10"
  and switch link monitoring mode to "MII", the miimon setting was not
  initialized to 10.

- accept empty bond settings, for example for updelay. In that case,
  initialize the text input to "0". Likewise, when the text entry is
  empty, set the bond option to the respective default.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/488
2020-07-11 15:06:28 +02:00
Thomas Haller 211d799817
tui: fix alternating miimon/arp_interval settings for bond options in nmtui 2020-07-11 11:18:54 +02:00
Thomas Haller b55578bf6e
cli: fix alternating miimon/arp_interval settings for bond options in nmcli
Before 1.24, nm_setting_bond_add_option() would clear
miimon/arp_interval settings when the respective other was set.

That was no longer done, with the effect that enabling (for example)
miimon on a bond profile that has arp_interval enabled, sets both
conflicting options.

That is not a severe problem, because the profile still validates.
However, at runtime only one of the settings can be actually configured.

Fix that, by restoring the previous behavior for the client. But note
that this time it's implemented in the client, and not in libnm's
nm_setting_bond_add_option().
2020-07-11 11:18:54 +02:00
Thomas Haller 6ab25c8255
docs: fix pre-generated documentation "clients/common/settings-docs.h.in"
Fixes: 4e33f8cd89 ('all: fix minor typos')
2020-07-07 11:38:20 +02:00
Yuri Chornoivan 4e33f8cd89
all: fix minor typos
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/565
2020-07-07 11:33: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 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 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
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
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
Antonio Cardace a2b699f40f
nmcs-gcp: add support for Google Cloud Platform load balancers
This add a provider implementation for GCP that when detected fetches
the ip addresses of configured internal load balancers.

Once this information is fetched from the metadata server it instructs
NetworkManager to add local routes for each found forwarded-ip.

https://bugzilla.redhat.com/show_bug.cgi?id=1821787
2020-06-26 16:47:56 +02:00
Antonio Cardace 75a84677ca
nmcs-main: support adding additional routes
This allows a provider to only add additional routes to the applied profile

https://bugzilla.redhat.com/show_bug.cgi?id=1821787
2020-06-26 16:47:56 +02:00
Antonio Cardace 053bce438b
nmcs-http: add param to GET API to set custom HTTP headers
https://bugzilla.redhat.com/show_bug.cgi?id=1821787
2020-06-26 16:47:56 +02:00
Antonio Cardace 1095cef9a1
main: remove unused argument 2020-06-26 16:47:56 +02:00
Antonio Cardace d46da9072a
nmcs: fix indentation 2020-06-26 16:47:56 +02:00
Antonio Cardace 3bd30f6064
nmcs: add error message when a HTTP request times out
https://bugzilla.redhat.com/show_bug.cgi?id=1821787
2020-06-26 16:47:55 +02:00
Antonio Cardace e09bd2339a
nmcs-http: remove the timeout once expired
libcurl's documentation for CURLMOPT_TIMERFUNCTION requires the
application to install a non-repeating timer.

https://curl.haxx.se/libcurl/c/CURLMOPT_TIMERFUNCTION.html

So let's remove the GSource once expired.

Fixes: 69f048bf0c ('cloud-setup: add tool for automatic IP configuration in cloud')
2020-06-26 16:47:55 +02:00
Antonio Cardace 427fbc85f0
nmcs-http: fix multiple HTTP request bug
Since just a single pointer is used to store the socket's GSource
if more than 1 consecutive request was done through the same
HTTP provider the 2nd request would clear the GSource associated to
the second request causing the 1st HTTP request to never complete
and end up in a expired timeout.

Use a hashtable instead so we can correctly track all requests.

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

Fixes: 69f048bf0c ('cloud-setup: add tool for automatic IP configuration in cloud')
2020-06-26 16:47:52 +02:00
Thomas Haller 824ad6275d
libnm/match: extend syntax for match patterns with '|', '&', '!' and '\\'
For simple matches like match.interface-name, match.driver, and
match.path, arguably what we had was fine. There each element
(like "eth*") is a wildcard for a single name (like "eth1").

However, for match.kernel-command-line, the elements match individual
command line options, so we should have more flexibility of whether
a parameter is optional or mandatory. Extend the syntax for that.

- the elements can now be prefixed by either '|' or '&'. This makes
  optional or mandatory elements, respectively. The entire match
  evaluates to true if all mandatory elements match (if any) and
  at least one of the optional elements (if any).
  As before, if neither '|' nor '&' is specified, then the element
  is optional (that means, "foo" is the same as "|foo").

- the exclamation mark is still used to invert the match. If used
  alone (like "!foo") it is a shortcut for defining a mandatory match
  ("&!foo").

- the backslash can now be used to escape the special characters
  above. Basically, the special characters ('|', '&', '!') are
  stripped from the start of the element. If what is left afterwards
  is a backslash, it also gets stripped and the remainder is the
  pattern. For example, "\\&foo" has the pattern "&foo" where
  '&' is no longer treated specially. This special handling of
  the backslash is only done at the beginning of the element (after
  the optional special characters). The remaining string is part
  of the pattern, where backslashes might have their own meaning.

This change is mostly backward compatible, except for existing matches
that started with one of the special characters '|', '&', '!', and '\\'.
2020-06-26 13:29:01 +02:00
Beniamino Galvani 3ecfd13ded cli: fix reference count handling in hotspot error path
The connection is automatically unreferenced when the function
returns.

Fixes: 9c5ea0917d ('devices: reuse the hotspot connection if we find appropriate one'):
2020-06-18 14:25:58 +02:00
Sayed Shah be822b52e6
all: reformat python files with python black
Part of !537.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/537
2020-06-15 16:40:38 +02:00
Beniamino Galvani 808e837149 all: add "path" property to the match setting
Add a new "path" property to the match setting, which can be used to
restrict a connection to devices with a given hardware path. The new
property is a list of patterns that are matched against the ID_PATH
udev property of devices.

ID_PATH represents the topological persistent path of a device and
typically contains a subsystem string (pci, usb, platform, etc.) and a
subsystem-specific identifier. Some examples of paths are:

 pci-0000:00:02.0
 pci-0000:00:14.0-usb-0:5:1.0
 platform-1c40000.ethernet

systemd-networkd also has a "Path=" option to match a device by udev
ID_PATH.
2020-06-12 16:04:06 +02:00