Commit graph

51 commits

Author SHA1 Message Date
Beniamino Galvani
08ce20481c all: add a new ipv{4,6}.required-timeout property
Add a new property to specify the minimum time interval in
milliseconds for which dynamic IP configuration should be tried before
the connection succeeds.

This property is useful for example if both IPv4 and IPv6 are enabled
and are allowed to fail. Normally the connection succeeds as soon as
one of the two address families completes; by setting a required
timeout for e.g. IPv4, one can ensure that even if IP6 succeeds
earlier than IPv4, NetworkManager waits some time for IPv4 before the
connection becomes active.

(cherry picked from commit cb5960cef7)
2021-07-05 17:17:19 +02:00
Thomas Haller
eea912dfb3
libnm: expose nm_ip_address_dup(), nm_ip_route_dup() API in libnm
This fixes commit 21c8a6b20e ('libnm-core, all: merge IPv4 and IPv6
address/route types'), which introduced this API but didn't export it
in the library. In practice this API is thus only usable since 1.32.0.

(cherry picked from commit 05f2a0b024)
2021-06-15 19:13:27 +02:00
Thomas Haller
5d50e7d78d
Revert "libnm: introduce the new get_ports() in bridge/bond API"
Let's instead add a generic nm_device_get_ports() function.
Also, only adding new API is maybe not sufficient. We should
at the same time deprecate and alias the D-Bus API, like was done
for commit 067a3d6c08 ('nm-device: expose via D-Bus the 'hw-address'
property').

This reverts commit 754143f4e8.
2021-06-02 12:05:26 +02:00
Fernando Fernandez Mancera
754143f4e8
libnm: introduce the new get_ports() in bridge/bond API
This patch is introducing get_ports() in bridge and bond API. In
addition, the existing get_slaves() functions are being marked as
deprecated.

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/878
2021-06-02 09:20:29 +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
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
Gris Ge
652ddca04c
ethtool: Introducing PAUSE support
Introducing ethtool PAUSE support with:

 * ethtool.pause-autoneg on/off
 * ethtool.pause-rx on/off
 * ethtool.pause-tx on/off

Limitations:
 * When `ethtool.pause-autoneg` is set to true, the `ethtool.pause-rx`
   and `ethtool.pause-tx` will be ignored. We don't have warning for
   this yet.

Unit test case included.

Signed-off-by: Gris Ge <fge@redhat.com>

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/829
2021-05-12 18:04:46 +02:00
Thomas Haller
02dbba49d6
libnm: fix leak in nm_vpn_service_plugin_read_vpn_details()
Found by Coverity:

  Error: RESOURCE_LEAK (CWE-772):
  NetworkManager-1.31.3/src/libnm-client-impl/nm-vpn-service-plugin.c:814: alloc_fn: Storage is returned from allocation function "g_string_new".
  NetworkManager-1.31.3/src/libnm-client-impl/nm-vpn-service-plugin.c:814: var_assign: Assigning: "key" = storage returned from "g_string_new(line->str + strlen("DATA_KEY="))".
  NetworkManager-1.31.3/src/libnm-client-impl/nm-vpn-service-plugin.c:815: var_assign: Assigning: "str" = "key".
  NetworkManager-1.31.3/src/libnm-client-impl/nm-vpn-service-plugin.c:855: leaked_storage: Variable "str" going out of scope leaks the storage it points to.
  NetworkManager-1.31.3/src/libnm-client-impl/nm-vpn-service-plugin.c:855: leaked_storage: Variable "key" going out of scope leaks the storage it points to.
  #  853|           NM_SET_OUT(out_secrets, g_steal_pointer(&secrets));
  #  854|       }
  #  855|->     return success;
  #  856|   }
  #  857|

Fixes: 3dfb72b926 ('service-plugin: allow continuations in the auth-dialog protocol')
2021-05-11 13:56:45 +02:00
Wen Liang
86dcb31ab3
build: replace ./tools/generate-docs-nm-property-infos.pl with python script
In order to have more structured settings in man page and make it more
manageable to generate the docbook, it is recommended to use python
script to replace `./tools/generate-docs-nm-property-infos.pl` (this
tool is used to parse the comment section starting with `---nmcli---`,
`---dbus---`, `---keyfile---`, `---ifcfg-rh---`).

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

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/824
2021-05-05 15:28:17 +02:00
Thomas Haller
21321ac736
clang-format: reformat code with clang 12
The format depends on the version of the tool. Now that Fedora 34 is
released, update to clang 12 (clang-tools-extra-12.0.0-0.3.rc1.fc34.x86_64).
2021-05-04 13:56:26 +02:00
Fernando Fernandez Mancera
d946aa0c50 wired-setting: add support to accept-all-mac-addresses
This patch is introducing the wired setting accept-all-mac-addresses
property. The value corresponds to the kernel flag IFF_PROMISC.

When accept-all-mac-address is enabled, the interface will accept all
the packets without checking the destination mac address.

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
2021-04-22 18:57:30 +00:00
Thomas Haller
34e4a3ef17
libnm/doc: clarify GMainContext handling in NMClient documentation
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/819
2021-04-19 09:31:48 +02:00
Thomas Haller
4d6f659e13
all: use nm_g_variant_singleton_a*() helpers 2021-04-16 11:44:19 +02:00
Thomas Haller
6b64fac06d
libnm: fix nm_device_set_autoconnect() to use correct D-Bus property name
Fixes: ce0e898fb4 ('libnm: refactor caching of D-Bus objects in NMClient')
2021-04-09 12:37:21 +02:00
Thomas Haller
49d69bc1b0
libnm: add comment about context-busy-watcher and g_dbus_connection_signal_unsubscribe() 2021-03-29 21:05:38 +02:00
Thomas Haller
193a6ac3e5
libnm: better explain nm_client_new()/nm_client_new_async() 2021-03-29 18:33:35 +02:00
Thomas Haller
89a6671e5f
libnm: cleanup handling of cancellation for initializing NMClient 2021-03-29 18:33:31 +02:00
Thomas Haller
6e4cdae256
all: split "range" variant of nm_utils_ptrarray_find_binary_search()
nm_utils_ptrarray_find_binary_search() had two additional output
arguments: the first and last index -- in case the sorted list contains
duplicates.

That's nice, and was used in the past. But now, those output arguments
are no longer used.

So drop them from nm_utils_ptrarray_find_binary_search().

Actually, we could now also drop the previous variant
nm_utils_ptrarray_find_binary_search_range(), as it's only used by unit
tests. However, although not rocket science, getting this right is not
entirely trivial, so lets keep the code in case we need it again.
2021-03-16 09:55:49 +01:00
Thomas Haller
cba3113607
libnm: guard against empty attribute names for NMLldpNeighbor
The libnm API NMLldpNeighbor does not accept "" as an attribute name.
And it does not need to, because a reasonable NetworkManager should
never expose such names.

However, we should not trust NetworkManager to be reasonable. Check that
the attribute name is not empty.
2021-03-12 18:56:43 +01:00
Thomas Haller
84d64217f8
libnm: call nm_lldp_neighbor_get_attr_value() from redundant helpers 2021-03-12 18:56:42 +01:00
Thomas Haller
626a83d025
libnm/trivial: move code
Move nm_lldp_neighbor_get_attr_value() first. The other functions are all redundant
and should possibly be deprecated.
2021-03-12 18:56:41 +01:00
Thomas Haller
be40c8fdf7
libnm: for boxed type NMLldpNeighbor only ref the instance instead of deep cloning
There is no public API to modify a NMLldpNeighbor instance. They are only
created by NMDevice and afterwards immutable. There is no point to duplicate
them, when we can just take a ref.

Note that this means we must be careful if we ever add API to mutate a
NMLldpNeighbor. But immutable types are awesome, so we probably should
never do that anyway.
2021-03-12 18:56:41 +01:00
Thomas Haller
ae881b7b5b
libnm: minor cleanup of NMLldpNeighbor getters 2021-03-12 18:56:40 +01:00
Thomas Haller
88e22b6832
libnm: sort attributes in nm_lldp_neighbor_get_attr_names()
A hash table gives values in undefined order. Sort them, to
get a stable order.
2021-03-12 18:56:40 +01:00
Thomas Haller
f8e19f805f
libnm: make NMLldpNeighbor ref-counting thread-safe
At least ref-counting should be thread safe for our public API.

Note that NMLldpNeighbor has no public API for mutating a neighbor
instance. Especially for immutable types, it is very attractive that
ref-counting is thread-safe.

Also use slice allocator for NMLldpNeighbor structs.
2021-03-12 18:56:40 +01:00
Thomas Haller
4d609dd92f
libnm: fix exporting nm_setting_match_new() symbol 2021-03-11 19:00:34 +01:00
Thomas Haller
452ba8408c
build/meson: cleanup tests 2021-02-28 18:56:08 +01:00
Thomas Haller
d81b5c4129
build/meson: cleanup libnm-client-impl 2021-02-28 10:44:08 +01:00
Thomas Haller
20c955fd61
build/meson: don't link static library libnm_client_impl with helper
Per convention, we shall no link our static libraries with other static
libraries of our own. The purpose is that we only link static libraries
at the end of each build product (that is, in executables, shared
libraries and shared modules).
2021-02-28 10:42:06 +01:00
Thomas Haller
4c98a45270
build/meson: drop libnm_nm_default_dep dependency 2021-02-28 10:42:06 +01:00
Thomas Haller
70836d6a08
build/meson: explicitly link libnm-crypto 2021-02-28 10:42:06 +01:00
Thomas Haller
c9bbd15597
build/meson: explicitly link libnm-core-aux-intern 2021-02-28 10:42:05 +01:00
Thomas Haller
e2004d2849
build/meson: cleanup dependencies for libnm-core-impl 2021-02-28 10:42:05 +01:00
Thomas Haller
e52d59f6c2
build/meson: cleanup dependencies for libnm-core-aux-intern 2021-02-28 10:42:05 +01:00
Thomas Haller
cac8e895b6
build/meson: cleanup dependencies for libnm-udev-aux 2021-02-28 10:42:04 +01:00
Thomas Haller
fd69080c9b
build/meson: cleanup dependencies for libnm-systemd-shared 2021-02-28 10:42:04 +01:00
Thomas Haller
309dccf5f9
build/meson: cleanup libnm-glib-aux dependencies
Avoid dependencies but explicitly link the static library where it is
used.

This also fixes that we linked libnm-log-core into
libnm-settings-plugin-ifcfg-rh.so, which duplicated the symbols
while it should used them from NetworkManager.
2021-02-28 10:42:04 +01:00
Thomas Haller
8bfe1ebcec
build/introspection: cleanup dependencies for libnmdbus in meson 2021-02-24 12:50:25 +01:00
Thomas Haller
635d84b896
build: remove "shared/" from include search path
There is nothing left there.
2021-02-24 12:49:06 +01:00
Thomas Haller
d6681a0429
shared: move "nm-compat.[hc]" to "src/contrib/"
"nm-compat.h" is not intended to be used by NetworkManager itself.
Instead, it's intended to be copied into the source tree of VPN plugins,
as adapter for different libnm versions.

Move it to "src/contrib/".
2021-02-24 12:49:01 +01:00
Thomas Haller
ad91579bb8
shared: move "nm-vpn-editor-plugin-call.h" to "src/contrib/" 2021-02-24 12:48:51 +01:00
Thomas Haller
fa288f65f6
shared: move "nm-vpn-plugin-utils.c" to "src/contrib/"
This file is not actually to be used by NetworkManager itself.
Instead, every (glib based) VPN plugin will want something like this,
hence we have a copy here.

Move it to a new directory "src/contrib/".
2021-02-24 12:48:46 +01:00
Thomas Haller
a03a03fbe9
libnm/tests: add static helper library "src/libnm-client-test/"
This helper code is already used by several of our unit tests.
Compile it as a separate library.

Previously, the source code lingered unmotivated under "shared/",
which is confusing.
2021-02-24 12:48:42 +01:00