Commit Graph

28395 Commits

Author SHA1 Message Date
Thomas Haller
6646ee6546 libnm/tests: avoid potential crash in test code test_nm_utils_escaped_tokens()
It causes a Coverity warning, so let's work around it.
2021-05-26 15:46:00 +02:00
Thomas Haller
bbe39ed095 libnm: use cleanup attribute in NMVpnPluginOld's _connect_generic() 2021-05-26 15:45:59 +02:00
Thomas Haller
e56f126071 libnm: fix error handling in NMVpnPluginOld's _connect_generic()
Also Coverity found that something is wrong here:

   Error: FORWARD_NULL (CWE-476): [#def361]
   NetworkManager-1.31.5/src/libnm-client-impl/nm-vpn-plugin-old.c:441: var_compare_op: Comparing "connection" to null implies that "connection" might be null.
   NetworkManager-1.31.5/src/libnm-client-impl/nm-vpn-plugin-old.c:489: var_deref_model: Passing null pointer "connection" to "g_object_unref", which dereferences it.
   #  487|       }
   #  488|
   #  489|->     g_object_unref(connection);
   #  490|   }
   #  491|

Fixes: 6793a32a8c ('libnm: port to GDBus')
2021-05-26 15:45:59 +02:00
Thomas Haller
8db23d47e4 ifcfg-rh: minor cleanup in svEscape() 2021-05-26 15:45:59 +02:00
Thomas Haller
370316fc3e ifcfg-rh: allocate exact buffer in _escape_ansic()
Previously, we would allocate a buffer of the worst case, that is,
4 times the number of bytes, in case all of them require octal escaping.

Coverity doesn't like _escape_ansic() for another reason:

   Error: NULL_RETURNS (CWE-476): [#def298]
   NetworkManager-1.31.5/src/core/settings/plugins/ifcfg-rh/shvar.c:161: returned_null: "g_malloc" returns "NULL".
   NetworkManager-1.31.5/src/core/settings/plugins/ifcfg-rh/shvar.c:161: alias: Assigning: "q" = "dest = g_malloc(strlen(source) * 4UL + 1UL + 3UL)". Both pointers are now "NULL".
   NetworkManager-1.31.5/src/core/settings/plugins/ifcfg-rh/shvar.c:163: dereference: Incrementing a pointer which might be null: "q".
   #  161|       q = dest = g_malloc(strlen(source) * 4 + 1 + 3);
   #  162|
   #  163|->     *q++ = '$';
   #  164|       *q++ = '\'';
   #  165|

It doesn't recognize that g_malloc() shouldn't return NULL (because
we never request zero bytes).

I am not sure how to avoid that, but let's rework the code to first count
how many characters we exactly need. It think that should also help with
the coverity warning.

Doing exact allocation requires first to count the number of required
bytes. It still might be worth it, because we might keep the allocated
strings a bit longer around.
2021-05-26 15:45:59 +02:00
Thomas Haller
f305a411cf libnm: abort read in nm_vpn_service_plugin_read_vpn_details() on '\0'
We expect to read NUL terminated strings. Upon NUL, we should do
something. Assume this is EOF.
2021-05-26 15:45:58 +02:00
Thomas Haller
6bf7908d05 libnm: abort huge read in nm_vpn_service_plugin_read_vpn_details()
There is no need to accept such a huge read. Abort.
2021-05-26 15:45:58 +02:00
Thomas Haller
4a9fcb0fc3 libnm: buffer reads in nm_vpn_service_plugin_read_vpn_details()
It seems very ugly to read one byte at a time. Use a naive buffered
reader, so that we can read multiple bytes at a time, and return them
one by one.

Also, this now keeps state of any error/EOF. Once we reach EOF, we won't
read again. The previous code did that too, but I think this code is
easier to read.
2021-05-26 15:45:58 +02:00
Thomas Haller
1338a2ef96 libnm: avoid sleep in nm_vpn_service_plugin_read_vpn_details()
Polling with sleep() is really ugly. Use poll() instead.
2021-05-26 15:45:58 +02:00
Thomas Haller
ddf1942bfb libnm: avoid g_warning() in nm_vpn_service_plugin_read_vpn_details()
g_warning() and printing to stdout/stderr are not suitable actions
for a library. If there is something important, find a way to report the
condition to the caller. If it's not important, stay quiet.
2021-05-26 15:45:58 +02:00
Thomas Haller
f0dc95e517 libnm: avoid strcmp in nm_vpn_service_plugin_read_vpn_details() 2021-05-26 15:45:57 +02:00
Thomas Haller
62c1944e7d libnm: fix logic and double free in nm_vpn_service_plugin_read_vpn_details()
"val" and "key" are now marked as nm_auto. They are freed at the end,
and we should not free them before breaking the loop (at least not,
without also clearing the variables).

Fixes: 02dbba49d6 ('libnm: fix leak in nm_vpn_service_plugin_read_vpn_details()')
2021-05-26 15:45:57 +02:00
Thomas Haller
8da91cd85f glib-aux: add nm_clear_g_string() helper
Since g_string_free() takes an additional argument,
it's not direclty usable with nm_clear_pointer(ptr, g_string_free);

As workaround, add nm_clear_g_string() helper.
2021-05-26 15:45:57 +02:00
Thomas Haller
c3d3429916 tools: drop spurious whitespace in "src/libnm-client-impl/nm-property-infos-*.xml"
<nm-setting-docs>
  -  <setting name="6lowpan">
  +<setting name="6lowpan">
   </setting>
2021-05-26 15:33:29 +02:00
Wen Liang
18839361ac bond: support tlb_dynamic_lb in balance-alb mode
In kernel, `tlb_dynamic_lb` is supported to configure in bonding mode
`balance-alb`. Therefore, add the support in NetworkManager to avoid
undesirable limitation.

Kernel previously had such limitation and it was removed in
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=e79c1055749e3183a2beee04a24da378623329c5.

Signed-off-by: Wen Liang <liangwen12year@gmail.com>

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

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/868
2021-05-26 14:57:21 +02:00
Thomas Haller
8ba66f8ec9 trivial: improve code comments 2021-05-26 12:07:11 +02:00
Thomas Haller
174f7bd27b core: rework string handling in enslave_slave()
Coverity doesn't like the previous code:

  Error: RESOURCE_LEAK (CWE-772): [#def34] [important]
  NetworkManager-1.31.5/src/core/devices/team/nm-device-team.c:835: alloc_fn: Storage is returned from allocation function "g_strdup".
  NetworkManager-1.31.5/src/core/devices/team/nm-device-team.c:835: noescape: Resource "g_strdup(config)" is not freed or pointed-to in "g_strdelimit".
  NetworkManager-1.31.5/src/core/devices/team/nm-device-team.c:835: leaked_storage: Failing to save or free storage allocated by "g_strdup(config)" leaks it.
  #  833|                       char *sanitized_config;
  #  834|
  #  835|->                     sanitized_config = g_strdelimit(g_strdup(config), "\r\n", ' ');
  #  836|                       err = teamdctl_port_config_update_raw(priv->tdc, slave_iface, sanitized_config);
  #  837|                       g_free(sanitized_config);

Maybe this works better.
2021-05-25 13:56:42 +02:00
Thomas Haller
ff9f2d27ec bluetooth: ensure function-like behavior of _LOG_bzobj() macro
We want that macros behave like functions, in that they evaluate all
their arguments exactly once.
2021-05-25 13:27:26 +02:00
Thomas Haller
95085acec3 update references from "freenode" to "Libera.Chat" 2021-05-25 11:09:37 +02:00
Thomas Haller
0448d3b931 contrib/rpm: merge branch 'th/contrib-rpm-fixes'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/865
2021-05-21 17:14:27 +02:00
Thomas Haller
847d6b31d4 contrib/rpm: remove "Obsoletes: NetworkManager-{atm,bt}"
These subpackages existed before commit 886366d0fd ('contrib/rpm:
update spec file after renaming NM plugins') (2014, before 0.9.9.95).

rpm warns about unversioned obsoletes like:

  It's not recommended to have unversioned Obsoletes: Obsoletes: NetworkManager-atm
  It's not recommended to have unversioned Obsoletes: Obsoletes: NetworkManager-bt

These packages are so long gone by now, let's just drop the Obsoletes.
2021-05-21 09:58:16 +02:00
Thomas Haller
871faa3ba7 contrib/rpm: remove "Obsoletes: dhcdbd"
"dhcdbd" is gone since 2007. Drop it. Also, rpm doesn't really like
unversioned obsoletes and warns:

    It's not recommended to have unversioned Obsoletes: Obsoletes: dhcdbd
2021-05-21 09:34:47 +02:00
Thomas Haller
f215c9a7fa contrib/rpm: don't have build dependency for iptables
We really only require "iptables" as build dependency to autodetect the
path where iptables is installed. On Fedora/RHEL, this is always /usr/sbin,
so we can just as well hard code this.

Alternatively, if the autodetection is really necessary, we would also require
a build dependency on /usr/sbin/nft. That seems a waste.
2021-05-21 09:34:46 +02:00
Thomas Haller
199807b2ec contrib/rpm: add rhel-8 specific libndp dependeny 2021-05-21 09:34:46 +02:00
Thomas Haller
8c7da8afc6 build: merge branch 'liangwen12year:wl/xml_rework3'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/863
2021-05-20 10:48:11 +02:00
Wen Liang
c3504f7e62 Rewrite ./tools/generate-docs-nm-property-infos.py with XML library
Instead of writing XML text word by word, it is less error prone to
write with XML library.

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2021-05-20 10:41:20 +02:00
Wen Liang
dd38eb1f76 Adjust property tag format in nm-property-infos-*.xml
In order to make the generated XML file format consistent before and
after using XML library, adjust `property` tag format.

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2021-05-20 10:41:19 +02:00
Beniamino Galvani
481ccd2ad2 release: bump version to 1.31.5 (development) 2021-05-19 21:04:53 +02:00
Thomas Haller
2d5489dcbb glib-aux: minor cleanup in nm_uuid_is_valid_nm() 2021-05-19 10:56:36 +02:00
Beniamino Galvani
1b7300ace9 merge: branch 'fix_reader_accept_all' into 'main'
ifcfg: fix wired reader for ACCEPT_ALL_MAC_ADDRESSES key

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/858
2021-05-19 08:42:11 +00:00
Fernando Fernandez Mancera
38246b1802 ifcfg: fix wired reader for ACCEPT_ALL_MAC_ADDRESSES key
When the ACCEPT_ALL_MAC_ADDRESSES key is found by the wired reader, the
wired setting was not being created.

Fixes: d946aa0c50 ('wired-setting: add support to accept-all-mac-addresses')
Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
2021-05-19 08:40:41 +00:00
Beniamino Galvani
a7cf9046d3 core: merge branch 'bg/rh1955101'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/855
https://bugzilla.redhat.com/show_bug.cgi?id=1955101
2021-05-19 10:31:39 +02:00
Beniamino Galvani
a3f35ea5cc ovs: block auto activation of ovs-interfaces until ovsdb is ready
Otherwise the device tries to activate too early and fails.
2021-05-19 10:29:11 +02:00
Beniamino Galvani
e694f2cec1 manager: fix active_connection_find()
Commit 33b9fa3a3c ("manager: Keep volatile/external connections
while referenced by async_op_lst") changed active_connection_find() to
also return active connections that are not yet activating but are
waiting authorization.

This has side effect for other callers of the function. In particular,
_get_activatable_connections_filter() should exclude only ACs that are
really active, not those waiting for authorization.

Otherwise, in ensure_master_active_connection() all the ACs waiting
authorization are missed and we might fail to find the right master
AC.

Add an argument to active_connection_find to select whether include
ACs waiting authorization.

Fixes: 33b9fa3a3c ('manager: Keep volatile/external connections while referenced by async_op_lst')

https://bugzilla.redhat.com/show_bug.cgi?id=1955101
2021-05-19 10:29:11 +02:00
Mejans
eeae36fd12 po: update Occitan (oc) translation
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/861
2021-05-19 10:14:16 +02:00
Thomas Haller
aef9b95aaa dhcp: map "static" DHCP state for dhcpcd to bound
A user might configure /etc/dhcpcd.conf to contain static fallback addresses.
In that case, the dhcpcd plugin reports the state as "static". Let's treat
that the same way as bound.

Note that this is not an officially supported or endorsed way of
configuring fallback addresses in NetworkManager. Rather, when using
DHCP plugins, the user can hack the system and make unsupported
modifications in /etc/dhcpcd.conf or /etc/dhcp. This change only makes
it a bit easier to do it.

See-also: https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/579#note_922758

https://bugzilla.gnome.org/show_bug.cgi?id=768362

Based-on-patch-by: gordonb3 <gordon@bosvangennip.nl>
2021-05-19 09:21:48 +02:00
Thomas Haller
c34e36bb8d Revert "Rewrite ./tools/generate-docs-nm-property-infos.py with XML library"
This breaks build on RHEL7, probably due to an older python version.
Revert for now.

This reverts commit a83fb33840.
2021-05-18 16:00:25 +02:00
Thomas Haller
890eda4db8 core: merge branch 'th/l3cfg-18'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/854
2021-05-18 13:43:44 +02:00
Thomas Haller
75a64dd199 core: add nm_l3_config_data_iter_ip_{address,route}_for_each() helpers 2021-05-18 09:41:55 +02:00
Thomas Haller
4d929cc023 l3cfg: add more getters to NML3ConfigData 2021-05-18 09:41:55 +02:00
Thomas Haller
82cd0a8689 glib-aux: add nm_ip_addr_from_packed_array() helper 2021-05-18 09:41:54 +02:00
Thomas Haller
0abc14b3a0 core: remove unused best_ip_config_[46] field in NMDnsManager 2021-05-18 09:41:54 +02:00
Thomas Haller
55b722820d l3cfg: fix nm_l3_config_data_new_clone() to make exact copy
We use the merge function to initialize the cloned instance.
Previously, merge did not always copy all properties, so the
cloned instance might not have been identical. Fix that.
2021-05-18 09:41:54 +02:00
Thomas Haller
71eefff6e7 core: return instance from nm_dhcp_lease_ref()/nm_dhcp_lease_unref() for convenience 2021-05-18 09:41:53 +02:00
Thomas Haller
4ef4201b0a core: make IS_IPv4 variable an "int" type
gboolean is a typedef for int, so there is no difference in behavior.
However, we use IS_IPv4 as index into arrays of length two. Making
it "int" seems more approriate. Also, this is what all the other
(similar) code does.
2021-05-18 09:41:53 +02:00
Thomas Haller
bb1a495213 device: refactor dhcp-anycast-address handling for OLPC mesh device
dhcp-anycast-address is only set by OLPC mesh device. It's ugly to have
this in form of a nm_device_set_dhcp_anycast_address() method, because
that means to cache the address in NMDevice. Meaning, we have more state
in NMDevice, where it's not clear where it comes from.

Instead, whenever we need to DHCP anycast address, as the subclass to
provide it (if any). This way, it gets extracted from the currently
applied connection at the moment when it is needed. Beyond that, the
setting is not duplicated/cached in NMDevice anymore.
2021-05-18 09:41:53 +02:00
Thomas Haller
ca6d30cb24 libnm: comment "olpc-mesh.dhcp-anycast-address" only working with dhclient 2021-05-18 09:41:52 +02:00
Thomas Haller
5aa7e254bd dhcp: refactor DHCP anycast_address to be property of NMDhcpClient
Instead of passing the setting on during ip4_start()/ip6_start(), make
it a property of NMDhcpClient.

This property is currently only set by OLPC devices, and is only
implemented by NMDhcpDhclient. As such, it also does not need to change
or get reset. Hence, and immutable, construct-only property is clearer,
because we don't have to pass parameters to ip[46]_start().

Arguably, the parameter is still there, but being immutable and always
set, make it easier to reason about it.
2021-05-18 09:41:52 +02:00
Thomas Haller
658c6a4146 ethtool: merge branch 'th/ethtool-autoneg-consistency'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/857
2021-05-18 08:41:31 +02:00
Thomas Haller
98a89a05ec core: explicitly disable ethtool.pause-autoneg when setting pause-rx/pause-tx
Kernel will coerce values like

    ethtool -A eth0 autoneg on rx off

to have autonet still on.

Also, if autoneg on the interface is enabled, then `ethtool  -A eth0 tx off`
has no effect.

In NetworkManager, the user cannot configure "autoneg on" together with
any rx/tx settings. That would render the profile invalid. However, we
also need to take care that a profile

  nmcli connection add ... ethtool.pause-autoneg ignore ethtool.pause-tx off

really means off. That means, we must coerce an unspecified autoneg
setting to "off".
2021-05-17 23:31:21 +02:00