Commit graph

303 commits

Author SHA1 Message Date
Robin Ebert
879e4f3546
cli: add support for connection.dns-over-tls 2021-10-15 10:00:46 +02:00
Thomas Haller
d4a367b482
nmcli: make relatives path for nmcli connection load absolute
NetworkManager (the daemon) has no defined working directory, so
it can only handle absolute path names. This is in general and also for
the LoadConnections() D-Bus call.

That means, nmcli should make relative paths absolute.

We don't use g_canonicalize_filename() because that also cleans up
double slash and "/./". I don't think we should do that in this case, we
should only prepend $PWD to make the path absolute.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/794
2021-09-13 09:32:57 +02:00
Thomas Haller
047d2c1d92
all: prefer g_snprintf() over snprintf()
While both functions are basically the same, the majority of the time
we use g_snprintf(). There is no strong reason to prefer one or the
other, but let's keep using one variant.
2021-08-26 23:05:13 +02:00
Gris Ge
9958510f28
bond: add support of queue_id of bond port
Introduced `NMSettingBondPort` to hold the new setting class with single
property `NM_SETTING_BOND_PORT_QUEUE_ID`.

For dbus interface, please use `bond-port` as setting name and
`queue-id` as property name.

Unit test cases for ifcfg reader and writer included.

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

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

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/952
2021-08-26 23:04:31 +02:00
Thomas Haller
ea49b50651
all: add some README.md files describing the purpose of our sources 2021-08-19 17:51:11 +02:00
Thomas Haller
2f3c2647d2
nmcli/docs: fix address order in ipv46.addresses documentation for man nm-settings-nmcli
For IPv4, the order is not like for IPv6. Of course not.

Fixes: 7aa4ad0fa2 ('nmcli/docs: better describe ipv[46].addresses in `man nm-settings-nmcli`')
2021-08-19 14:00:03 +02:00
Thomas Haller
7aa4ad0fa2
nmcli/docs: better describe ipv[46].addresses in man nm-settings-nmcli 2021-08-17 19:56:39 +02:00
Vojtech Bubela
9d40226b00
nmcli: edit output of nmcli so it shows more inormation about routes
Edit nmcli command to show additional information about the routes
(both route4 and route6).

If there is information about next hop or metric in the route
structure it will be shown in addition to destination and prefix.
2021-08-02 09:37:02 +02:00
Thomas Haller
593cb57eb6
all: rename nm_utils_strdict_*() to nm_strdict_*() 2021-08-02 09:26:48 +02:00
Thomas Haller
3587cbd827
all: rename nm_utils_strsplit_set*() to nm_strsplit_set*() 2021-08-02 09:26:47 +02:00
Thomas Haller
4ac66a4215
all: rename nm_utils_strdup_reset*() to nm_strdup_reset*() 2021-08-02 09:26:47 +02:00
Thomas Haller
72433a10f4
cli: fix leak of text for libreadline
Coverity warns about this:

    Error: RESOURCE_LEAK (CWE-772):
    NetworkManager-1.32.4/src/nmcli/agent.c:87: alloc_fn: Storage is returned from allocation function "g_strdup".
    NetworkManager-1.32.4/src/nmcli/agent.c:87: var_assign: Assigning: "pre_input_deftext" = storage returned from "g_strdup(secret->value)".
    NetworkManager-1.32.4/src/nmcli/agent.c:87: overwrite_var: Overwriting "pre_input_deftext" in "pre_input_deftext = g_strdup(secret->value)" leaks the storage that "pre_input_deftext" points to.
    #   85|               /* Prefill the password if we have it. */
    #   86|               rl_startup_hook   = set_deftext;
    #   87|->             pre_input_deftext = g_strdup(secret->value);
    #   88|           }
    #   89|           if (secret->no_prompt_entry_id)

    Error: RESOURCE_LEAK (CWE-772):
    NetworkManager-1.32.4/src/nmcli/common.c:712: alloc_fn: Storage is returned from allocation function "g_strdup".
    NetworkManager-1.32.4/src/nmcli/common.c:712: var_assign: Assigning: "nmc_rl_pre_input_deftext" = storage returned from "g_strdup(secret->value)".
    NetworkManager-1.32.4/src/nmcli/common.c:712: overwrite_var: Overwriting "nmc_rl_pre_input_deftext" in "nmc_rl_pre_input_deftext = g_strdup(secret->value)" leaks the storage that "nmc_rl_pre_input_deftext" points to.
    #  710|                           /* Prefill the password if we have it. */
    #  711|                           rl_startup_hook          = nmc_rl_set_deftext;
    #  712|->                         nmc_rl_pre_input_deftext = g_strdup(secret->value);
    #  713|                       }
    #  714|                   }
2021-07-29 15:02:24 +02:00
Thomas Haller
4c3aac899e
all: unify and rename strv helper API
Naming is important, because the name of a thing should give you a good
idea what it does. Also, to find a thing, it needs a good name in the
first place. But naming is also hard.

Historically, some strv helper API was named as nm_utils_strv_*(),
and some API had a leading underscore (as it is internal API).

This was all inconsistent. Do some renaming and try to unify things.

We get rid of the leading underscore if this is just a regular
(internal) helper. But not for example from _nm_strv_find_first(),
because that is the implementation of nm_strv_find_first().

  - _nm_utils_strv_cleanup()                 -> nm_strv_cleanup()
  - _nm_utils_strv_cleanup_const()           -> nm_strv_cleanup_const()
  - _nm_utils_strv_cmp_n()                   -> _nm_strv_cmp_n()
  - _nm_utils_strv_dup()                     -> _nm_strv_dup()
  - _nm_utils_strv_dup_packed()              -> _nm_strv_dup_packed()
  - _nm_utils_strv_find_first()              -> _nm_strv_find_first()
  - _nm_utils_strv_sort()                    -> _nm_strv_sort()
  - _nm_utils_strv_to_ptrarray()             -> nm_strv_to_ptrarray()
  - _nm_utils_strv_to_slist()                -> nm_strv_to_gslist()
  - nm_utils_strv_cmp_n()                    -> nm_strv_cmp_n()
  - nm_utils_strv_dup()                      -> nm_strv_dup()
  - nm_utils_strv_dup_packed()               -> nm_strv_dup_packed()
  - nm_utils_strv_dup_shallow_maybe_a()      -> nm_strv_dup_shallow_maybe_a()
  - nm_utils_strv_equal()                    -> nm_strv_equal()
  - nm_utils_strv_find_binary_search()       -> nm_strv_find_binary_search()
  - nm_utils_strv_find_first()               -> nm_strv_find_first()
  - nm_utils_strv_make_deep_copied()         -> nm_strv_make_deep_copied()
  - nm_utils_strv_make_deep_copied_n()       -> nm_strv_make_deep_copied_n()
  - nm_utils_strv_make_deep_copied_nonnull() -> nm_strv_make_deep_copied_nonnull()
  - nm_utils_strv_sort()                     -> nm_strv_sort()

Note that no names are swapped and none of the new names existed
previously. That means, all the new names are really new, which
simplifies to find errors due to this larger refactoring. E.g. if
you backport a patch from after this change to an old branch, you'll
get a compiler error and notice that something is missing.
2021-07-29 10:26:50 +02:00
Lukasz Majewski
d1dad6ae27
cli: Provide optional support for libedit instead of readline
The libreadline starting from version 6 is licensed as GPLv3. For some
use cases it is not acceptable to use this license.

In the NetworkManager the libreadline is used by nmcli.
This change allows using libedit instead of libreadline.

Following adjustments were made:
1. The history_set_history_state() is not supported in the libedit.
   Instead, the where_history() with remove_history() were used to remove
   the history content if needed.

2. rl_complete_with_tilde_expansion - it is the binary flag used only
   when one wants to have the expansion support. The libedit is not
   supporting and hence exporting this flag.
2021-07-14 17:16:45 +02:00
Lukasz Majewski
823445021a
cli: Provide rl_completion_display_matches_hook function only for libreadline
When one wants to compile the nmcli with libedit (GPLv2 replacement of
libreadline) the rl_completion_display_matches_hook hook shall be left
untouched (as NULL) as it is not supported in libedit.
2021-07-14 17:16:45 +02:00
Lukasz Majewski
f47d55fc66
cli: Fix for rl_startup_hook function signatures mismatch (-lreadline vs -ledit)
The rl_startup_hook function has different prototype in libreadline and
in the libedit.

To fix this issue, arguments of hook function has been wrapped to C
preprocessor macro and properly adjusted.
2021-07-14 17:16:45 +02:00
Ana Cabral
34b499f1ef nmcli: include 'searches' field for nmcli device show
Merge Request !919
2021-07-09 15:21:08 -03:00
Thomas Haller
a09ade23e1
cli: reorder command list in nmc_command_func_device()
Sort asciibetically, at least as long as there is no conflicting
prefix that should be preferred.
2021-07-09 16:41:31 +02:00
Vojtech Bubela
6f3b2dbf6f
cli: sort entries in src/nmcli/devices.c by alphabetical order
Sort entries in src/nmcli/devices.c (on line 5023 - 5036)
by alphabetical order. The Order is violated in cases where
the sort would affect previous behaviour.

Example: `nmcli d d` is still shortcut for `nmcli device disconnect`
instead of `nmcli device delete`.
2021-07-09 16:41:31 +02:00
Thomas Haller
69cb2b3f24
cli: fix list of commands in nmc_command_func_device() 2021-07-09 16:01:54 +02:00
Vojtech Bubela
5cd1b2669d
cli: add alias to nmcli device connect|disconnect
nmcli now accepts `nmcli device up|down` which works the same way as
`nmcli device connect|disconnect`

I also edited man pages of nmcli with new options.
2021-07-09 16:01:47 +02:00
Thomas Haller
4e109bacab
clang-format: use "IndentPPDirectives:None" instead of "BeforeHash"
Subjectively, I think this looks better.
2021-07-09 08:49:06 +02:00
Thomas Haller
d0349f17b7
cli: fail nmcli connection up $PROFILE ifname $DEVICE for non-existing virtual device
$ nmcli connection add type dummy con-name x autoconnect no ipv4.method disabled ipv6.method disabled ifname d0
  $ mcli connection up x ifname bogus
  Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/12)

This is not right. A non-existing ifname argument was simply ignored
and nmcli would tell NetworkManager to activate the profile (on any
device).

Instead, if the user specifies a device argument, also for a virtual
type, it must exist.

Note that usually for virtual devices (like 'dummy'), the device
in fact does not exist, so passing `ifname` is likely to fail.
If the device already exists, then the command is no going to work
as expected, with

  $ mcli connection up x ifname d0

succeeding, while

  $ mcli connection up x ifname d1

fails (as intended) with

  Error: device 'd1' not compatible with connection 'x': The interface names of the device and the connection didn't match..
2021-07-08 17:20:15 +02:00
Thomas Haller
bb3c93bfd4
cli: improve error message for device not found
$ nmcli connection add type ethernet con-name x autoconnect no ipv4.method disabled ipv6.method disabled
  $ nmcli connection up x ifname bogus
  Error: device 'bogus' not compatible with connection 'x'.

Better would be:

  Error: device 'bogus' not found for connection 'x'.
2021-07-08 17:20:15 +02:00
Thomas Haller
409c87af2c
cli: replace strcmp() uses with nm_streq()/NM_IN_STRSET() 2021-07-08 17:20:15 +02:00
Beniamino Galvani
cb5960cef7 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.
2021-07-05 15:15:44 +02:00
Thomas Haller
09fb7877a9
build: fix linking libnm-log-null into different test programs
We require these, otherwise we can get a linker error about
_nm_utils_monotonic_timestamp_initialized symbol being undefined.
2021-07-05 14:51:27 +02:00
Thomas Haller
30940222cc
libnm: better document "ethernet.s390-options" property 2021-07-02 08:28:30 +02:00
Thomas Haller
70e5d8e5bd
all: don't explicitly include <glib-unix.h>
We get it now always by "nm-macros-internal.h".
2021-06-28 13:31:34 +02:00
Thomas Haller
48d345d62f
libnm/docs: better explain "connection.autoconnect{,-priority}" 2021-06-22 13:06:38 +02:00
Thomas Haller
91f5c5e763
cli: avoid coverity warning in do_connection_down()
Error: USE_AFTER_FREE (CWE-416): [#def729] [important]
    NetworkManager-1.31.90/src/nmcli/connections.c:3288: freed_arg: "connection_cb_info_finish" frees "info".
    NetworkManager-1.31.90/src/nmcli/connections.c:3287: pass_freed_arg: Passing freed pointer "info" as an argument to "g_signal_handlers_disconnect_matched".
    # 3285|
    # 3286|               if (info) {
    # 3287|->                 g_signal_handlers_disconnect_by_func(active, down_active_connection_state_cb, info);
    # 3288|                   connection_cb_info_finish(info, active);
    # 3289|               }

(cherry picked from commit 627503ad86)
2021-06-11 22:44:31 +02:00
Sibo Dong
1e0252fa8f
bash-completion: localize the prev variable
The prev variable is not localzed in the nmcli Bash completion script,
which calls _init_completion.

Even though prev does not appear in the completion script, it should
still be localized. This variable may otherwise appear in the user's
environment and clobber a user-defined variable of the same name, which
is bad.

Localize the prev variable.

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

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/882
(cherry picked from commit 5c1181c6f3)
2021-06-08 11:38:45 +02:00
Beniamino Galvani
a48edd0410 core,libnm: don't touch device TC configuration by default
NetworkManager supports a very limited set of qdiscs. If users want to
configure a unsupported qdisc, they need to do it outside of
NetworkManager using tc.

The problem is that NM also removes all qdiscs and filters during
activation if the connection doesn't contain a TC setting. Therefore,
setting TC configuration outside of NM is hard because users need to
do it *after* the connection is up (for example through a dispatcher
script).

Let NM consider the presence (or absence) of a TC setting in the
connection to determine whether NM should configure (or not) qdiscs
and filters on the interface. We already do something similar for
SR-IOV configuration.

Since new connections don't have the TC setting, the new behavior
(ignore existing configuration) will be the default. The impact of
this change in different scenarios is:

 - the user previously configured TC settings via NM. This continues
   to work as before;

 - the user didn't set any qdiscs or filters in the connection, and
   expected NM to clear them from the interface during activation.
   Here there is a change in behavior, but it seems unlikely that
   anybody relied on the old one;

 - the user didn't care about qdiscs and filters; NM removed all
   qdiscs upon activation, and so the default qdisc from kernel was
   used. After this change, NM will not touch qdiscs and the default
   qdisc will be used, as before;

 - the user set a different qdisc via tc and NM cleared it during
   activation. Now this will work as expected.

So, the new default behavior seems better than the previous one.

https://bugzilla.redhat.com/show_bug.cgi?id=1928078
2021-06-03 09:01:57 +02:00
Thomas Haller
ea60f273af
cli: minor cleanup of code in "devices.c"
- declare each variable on a separate line.

- use nm_auto_free_gstring instead of explicit free.
2021-05-27 10:42:10 +02:00
Thomas Haller
550434a026
cli: workaround coverity false positive in "devices.c"
Error: RESOURCE_LEAK (CWE-772): [#def268] [important]
    NetworkManager-1.31.5/src/nmcli/devices.c:1367: alloc_fn: Storage is returned from allocation function "g_string_free".
    NetworkManager-1.31.5/src/nmcli/devices.c:1367: leaked_storage: Ignoring storage allocated by "g_string_free(security_str, 0)" leaks it.
    # 1365|       g_ptr_array_add(info->output_data, arr);
    # 1366|
    # 1367|->     g_string_free(security_str, FALSE);
    # 1368|   }
    # 1369|

    Error: RESOURCE_LEAK (CWE-772): [#def269] [important]
    NetworkManager-1.31.5/src/nmcli/devices.c:1451: alloc_fn: Storage is returned from allocation function "g_string_free".
    NetworkManager-1.31.5/src/nmcli/devices.c:1451: leaked_storage: Ignoring storage allocated by "g_string_free(slaves_str, 0)" leaks it.
    # 1449|       print_data(&nmc->nmc_config, &nmc->pager_data, out_indices, NULL, 0, &out);
    # 1450|
    # 1451|->     g_string_free(slaves_str, FALSE);
    # 1452|
    # 1453|       return TRUE;

    Error: RESOURCE_LEAK (CWE-772): [#def270] [important]
    NetworkManager-1.31.5/src/nmcli/devices.c:1517: alloc_fn: Storage is returned from allocation function "g_string_free".
    NetworkManager-1.31.5/src/nmcli/devices.c:1517: leaked_storage: Ignoring storage allocated by "g_string_free(slaves_str, 0)" leaks it.
    # 1515|       print_data(&nmc->nmc_config, &nmc->pager_data, out_indices, NULL, 0, &out);
    # 1516|
    # 1517|->     g_string_free(slaves_str, FALSE);
    # 1518|
    # 1519|       return TRUE;
2021-05-27 10:34:41 +02:00
Thomas Haller
ca6d30cb24
libnm: comment "olpc-mesh.dhcp-anycast-address" only working with dhclient 2021-05-18 09:41:52 +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
e5f37477c0
cli: fix leak in print_wifi_connection()
Found by Coverity:

  Error: RESOURCE_LEAK (CWE-772): [#def297] [important]
  NetworkManager-1.31.3/src/nmcli/devices.c:4610: alloc_fn: Storage is returned from allocation function "nm_utils_ssid_to_utf8".
  NetworkManager-1.31.3/src/nmcli/devices.c:4610: var_assign: Assigning: "ssid" = storage returned from "nm_utils_ssid_to_utf8(g_bytes_get_data(ssid_bytes, NULL), g_bytes_get_size(ssid_bytes))".
  NetworkManager-1.31.3/src/nmcli/devices.c:4612: noescape: Resource "ssid" is not freed or pointed-to in "g_print".
  NetworkManager-1.31.3/src/nmcli/devices.c:4642: noescape: Resource "ssid" is not freed or pointed-to in "string_append_mecard".
  NetworkManager-1.31.3/src/nmcli/devices.c:4654: leaked_storage: Variable "ssid" going out of scope leaks the storage it points to.
  # 4652|
  # 4653|       g_print("\n");
  # 4654|-> }
  # 4655|
  # 4656|   static gboolean

Fixes: 7061341a41 ('cli: add "nmcli d wifi show"')
2021-05-11 13:56:50 +02:00
Jonas Dreßler
e06f9508d1
libnm-core: Rewrite comment of key-mgmt property
The key-mgmt property of NMSettingWirelessSecurity is slightly confusing
when you know there's also a wpa_supplicant configuration option called
"key_mgmt". Our property is not the same as that supplicant option even
though they do have things in common. NMs key-mgmt is not exactly meant
to configure which AKM suites you want to use, but rather which method
of wifi security is being used (so "wpa2+wpa3 personal", "wpa3 personal
only" or "wpa3 enterprise only").

Try to make this a bit clearer in the documentation of the property by
rewriting it and listing those security methods.
2021-05-06 22:23:28 +02:00
Beniamino Galvani
a0aa727af2 nmcli: remove nmc_dbus_call_sync()
The function is unused now. All operations should be asynchronous so
that nmcli keeps running the main loop.
2021-05-03 22:22:01 +02:00
Beniamino Galvani
9d0aca6757 nmcli: invoke ReloadConnections() D-Bus method asynchronously 2021-05-03 22:22:01 +02:00
Beniamino Galvani
1d82c39bfa nmcli: invoke Reload() D-Bus method asynchronously
Invoke Reload() asynchronously and run the main loop. In this way, the
polkit agent built into nmcli can be used to authenticate the reload
request.

Fixes: 5afcf9c045 ('cli: add 'general reload' command')
2021-05-03 22:22:01 +02:00
Beniamino Galvani
43fc984989 man: document the 'nmcli general reload' command 2021-05-03 22:13:36 +02:00
Thomas Haller
40032f4614
cli: fix resetting values via property alias
Property aliases should really just be shortcuts for one fully spelled
out property (sometimes, they do more like "master").

Anyway, we must also handle resetting the value, otherwise:

  $ nmcli connection add type gsm apn ""

will still result in "gsm.apn=internet", unlike

  $ nmcli connection add type gsm gsm.apn ""
2021-05-03 10:11:23 +02:00
Thomas Haller
f62ecc97c8
cli: use proper GError codes in "nm-client-utils.c"
g_set_error(error, 1, 0, ...) is not right. "1" is not a valid GQuark,
we should initialize proper error instances.

Use nm_utils_error_set() for that.

Also, the code previously hacked the numeric value "1" to indicate
ambiguous text. Add and use a new error code NM_UTILS_ERROR_AMBIGUOUS
for that.
2021-05-03 10:11:21 +02:00
Thomas Haller
1f33a59a0f
cli: use const argument for nmc_string_is_valid()
With a const argument, we can make variables static const,
which means the linker loads the memory as read only.

Also, use NM_CAST_STRV_CC() macro, which casts the argument
accordingly.
2021-05-03 10:11:20 +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
Fernando Fernandez Mancera
27e37a4b17 interface-flags: expose NM_DEVICE_INTERFACE_FLAG_PROMISC
This patch is introducing NM_DEVICE_INTERFACE_FLAG_PROMISC in
interface_flags. The flag represents IFF_PROMISC kernel flag.

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
2021-04-22 18:57:30 +00:00
Thomas Haller
a55c10c6cb
nmcli/trivial: add comment about stability of connection-add success message 2021-04-17 08:36:55 +02:00
Thomas Haller
f34841e196
all: use nm_g_variant_new_ay() helper 2021-04-16 11:44:19 +02:00