Commit graph

154 commits

Author SHA1 Message Date
Beniamino Galvani
40897db056 nmcli: fix crash in "nmcli device monitor"
Fix the following crash:

  $ nmcli device monitor a
  Error: Device 'a' not found.
  Segmentation fault (core dumped)

Found by coverity:

  1. NetworkManager-1.41.3/src/nmcli/devices.c:0: scope_hint: In function 'do_devices_monitor'
  2. NetworkManager-1.41.3/src/nmcli/devices.c:2932:28: warning[-Wanalyzer-null-dereference]: dereference of NULL 'devices'
     2930|       }
     2931|
     2932|->     for (i = 0; i < devices->len; i++)
     2933|           device_watch(nmc, g_ptr_array_index(devices, i));
     2934|

Fixes: 2074b28976 ('nmcli/devices: return GPtrArray instead of GSList from get_device_list()')
2022-10-19 16:11:55 +02:00
Lubomir Rintel
37582fc384 style: fix code formatting
Fixes: b784da83d2 ('nmcli: show sriov capability in "nmcli" output')
2022-10-17 17:40:40 +02:00
Lubomir Rintel
b784da83d2 nmcli: show sriov capability in "nmcli" output
This is sometimes interesting to know.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1431
2022-10-17 10:25:11 +02:00
gaoxingwang
2a0bbd788b
nmcli: fix typo 'exiting' -> 'existing'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/1115

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1424
2022-10-12 15:41:48 +02:00
Thomas Haller
d5d6823558
cli: fix translation string for error message in set_property()
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/1112
2022-10-11 09:43:26 +02:00
Thomas Haller
8899ecc0d8
tools: preserve newlines and indentation in "generate-docs-nm-property-infos.py"
Our docs can be long. It's important to be able to express paragraphs.
Honor a blank line to include a newline. For XML often whitespace is
ignored, but our tools can choose to honor the newline.

Also, don't strip the whitespace from the beginning and the end.
We keep whitespace for a certain indentation level, but additional
whitespace gets preserved. This is less important, because regular
spaces is indeed irrelevant. But when we write the annotations, we
should be in full control over spaces.
2022-10-06 13:40:29 +02:00
Beniamino Galvani
1a77108dcb nmcli: don't show state-reason for "nmcli device connect" errors
It's confusing to show a state-reason number different from nmcli
return values.
2022-10-04 10:06:54 +02:00
Beniamino Galvani
5cf9395b94 nmcli: fix return code on "nmcli device connect" error
Before:
  $ nmcli device connect veth0; echo $?
  Error: Connection activation failed: (5) IP configuration could not be reserved (no available address, timeout, etc.).
  0

After
  $ nmcli device connect veth0; echo $?
  Error: Connection activation failed: (5) IP configuration could not be reserved (no available address, timeout, etc.).
  4

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/902
2022-10-04 10:06:54 +02:00
Thomas Haller
7adde3f2fc
nmcli: don't print warning in nmcli connection import about duplicate parameters
It seems uncommon that a command line tool warns about duplicate
paramters. Usually, the latter just overwrites the former. That is also
useful so that you can have for example an alias that sets a default
type

  nmcli_import="nmcli connection import type keyfile"

but still call it like

  nmcli_import file $FILE type openvpn

This is a change in behavior. Not only stop we printing a warning, we
will now prefer the latter argument. Previously, the first was honored.
This change in behavior is a problem, but such uses were warned against
in the past, and hopefully nobody did this or relied on this.
2022-10-03 13:59:12 +02:00
Thomas Haller
046e36b4fd
nmcli: allow selecting profiles by partial UUID
For convenience, allow also to match the UUID by prefix -- if the
"uuid" selector is used.

Note that still, there must be only one candidate found. The "uuid"
selector guarantees to find a unique connection.

  $ nmcli -f connection.uuid,connection.id connection show uuid eb43d80c
2022-09-28 13:27:14 +02:00
Thomas Haller
baf9b38650
nmcli: ensure profiles matching by "uuid","path" selector are unique
The "connection.uuid" and the D-Bus path are supposed to be unique on
D-Bus. Anything else indicates to a bug somewhere.

Still, with `nmcli connection $operation [uuid|path] $arg ...` ensure
that the result is always unique.

In practice, this should make no difference. In the case of an
unexpected duplicate, it seems better to fail and uphold the
guarantee that these selectors give unique results.

Also, next we will accept matching prefixes of the UUID. While partial
match will then be supported, it should still be unique. That is, the
"uuid" specifier should always only yield one result. While this patch
should make not difference in practice today (albeit enforcing something
that should be valid), it will make a difference then.
2022-09-28 13:27:14 +02:00
Vojtech Bubela
c32823d5e9
wpa_supplicant: add tls_disable_time_checks flag to phase 1 auth flags
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/978

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1378
2022-09-28 08:53:55 +02:00
Thomas Haller
692edc3bc5
nmcli: fix nmcli connection add -h output for optional ifname parameter
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/1089
2022-09-15 19:51:39 +02:00
Thomas Haller
ffd8baa49f
all: use nm_g_array_{index,first,last,index_p}() instead of g_array_index()
These variants provide additional nm_assert() checks, and are thus
preferable.

Note that we cannot just blindly replace &g_array_index() with
&nm_g_array_index(), because the latter would not allow getting a
pointer at index [arr->len]. That might be a valid (though uncommon)
usecase. The correct replacement of &g_array_index() is thus
nm_g_array_index_p().

I checked the code manually and replaced uses of nm_g_array_index_p()
with &nm_g_array_index(), if that was a safe thing to do. The latter
seems preferable, because it is familar to &g_array_index().
2022-09-15 12:39:07 +02:00
Lubomir Rintel
d3ffd2f90a setting-bridge,wireless: improve some deprecation warnings
The documentation paragraph contained deprecation information redundant
with the deprecation tag. It looks ugly when rendered into a manual
page.
2022-09-07 11:06:38 +02:00
Lubomir Rintel
09c402d903 setting-8021x: add deprecation tags
Add deprecation tags to "subject-match" and "phase2-subject-match"
properties and adjust the documentation slightly.

They've been deprecated since commit 64b76ba906 ('libnm-core: add
domain-suffix-match properties to NMSetting8021x').
2022-09-07 11:04:17 +02:00
Lubomir Rintel
4d42b81d2a generate-docs-nm-settings-docs-gir: move deprecation info to a separate tag
Previously, the deprecation data was included in <description*>, in form
of an integer. E.g.:

  /**
   * NMSettingLala:hello:
   *
   * Does this and that.
   *
   * Deprecated: 1.12: Be sad instead.
   **/

Results in:

  <property name="hello">
    <description>Does this and that. Deprecated: 1</description>
  </property>

Let's make it do this instead:

  <property name="hello">
    <description>Does this and that.</description>
    <deprecated since="1.12">Be sad instead.</description>
  </property>
2022-09-07 11:01:40 +02:00
Vojtech Bubela
5fde7814dc ovs: add ofport_request option to ovs interface
Add option to set ofport_request when configuring ovs interface. When
connection with ofport_request configured is activated ovsdb will first
try to activated on the port set by ofport_request.
2022-09-02 08:46:36 +00:00
Lubomir Rintel
222bd85fdc nmcli: don't translate "%s"
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1354
2022-09-01 13:07:23 +02:00
Thomas Haller
fcf32d81bd
nmcli: allow changing the UUID of a profile in offline mode
It is useful to modify the UUID in offline mode. Otherwise, it's
cumbersome to clone a profile, because the cloned profile will
have the same UUID (and NetworkManager cannot load them both
at the same time).

  umask 077
  nmcli --offline connection modify \
      connection.id profile2 \
      connection.uuid new \
    < /etc/NetworkManager/system-connections/profile1.nmconnection \
    > /etc/NetworkManager/system-connections/profile2.nmconnection \

The doctext doesn't actually work for `man nm-settings-nmcli`. The
generation of our docs is still an incomprehensible mess that needs
fixing.
2022-08-31 19:20:11 +02:00
Thomas Haller
71a111bb9c
nmcli: add get_env_flags() accessor to NMMetaEnvironment for checking offline mode
We will want to know whether we are in offline mode.
Add an accessor to get environment flags, which libnmc-setting
can use.
2022-08-31 19:20:11 +02:00
Thomas Haller
56d0d35516
mptcp: rework "connection.mptcp-flags" for enabling MPTCP
1) The "enabled-on-global-iface" flag was odd. Instead, have only
and "enabled" flag and skip (by default) endpoints on interface
that have no default route. With the new flag "also-without-default-route",
this can be overruled. So previous "enabled-on-global-default" now is
the same as "enabled", and "enabled" from before behaves now like
"enabled,also-without-default-route".

2) What was also odd, as that the fallback default value for the flags
depends on "/proc/sys/net/mptcp/enabled". There was not one fixed
fallback default, instead the used fallback value was either
"enabled-on-global-iface,subflow" or "disabled".
Usually that is not a problem (e.g. the default value for
"ipv6.ip6-privacy" also depends on use_tempaddr sysctl). In this case
it is a problem, because the mptcp-flags (for better or worse) encode
different things at the same time.
Consider that the mptcp-flags can also have their default configured in
"NetworkManager.conf", a user who wants to switch the address flags
could previously do:

  [connection.mptcp]
  connection.mptcp-flags=0x32   # enabled-on-global-iface,signal,subflow

but then the global toggle "/proc/sys/net/mptcp/enabled" was no longer
honored. That means, MPTCP handling was always on, even if the sysctl was
disabled. Now, "enabled" means that it's only enabled if the sysctl
is enabled too. Now the user could write to "NetworkManager.conf"

  [connection.mptcp]
  connection.mptcp-flags=0x32   # enabled,signal,subflow

and MPTCP handling would still be disabled unless the sysctl
is enabled.

There is now also a new flag "also-without-sysctl", so if you want
to really enable MPTCP handling regardless of the sysctl, you can.
The point of that might be, that we still can configure endpoints,
even if kernel won't do anything with them. Then you could just flip
the sysctl, and it would start working (as NetworkManager configured
the endpoints already).

Fixes: eb083eece5 ('all: add NMMptcpFlags and connection.mptcp-flags property')
(cherry picked from commit c00873e08f)
2022-08-25 23:12:53 +02:00
Thomas Haller
86879692c6
libnm: reword documentation for "ipv4.gateway" and "ipv6.gateway"
(cherry picked from commit 0e26203e02)
2022-08-23 16:39:04 +02:00
Thomas Haller
3117198f15
Revert "wifi: support "802-1x.phase1-auth-flags=tls-allow-unsafe-renegotiation" flag"
There is still no agreement, about how to name this option, or whether
it should exist at all. Revert the addition of the flag.

As the new release is coming up, drop the new API.

https://bugzilla.redhat.com/show_bug.cgi?id=2072070#c64
https://bugzilla.redhat.com/show_bug.cgi?id=2077973#c24
http://lists.infradead.org/pipermail/hostap/2022-July/040665.html

This reverts commit a5a4aea2e6.
2022-08-11 19:36:26 +02:00
Thomas Haller
f64dff6939
all: drop various NMMptcpFlags
The default behavior might be sufficient. Drop those flags for now,
and figure out a good solution when we have an actual use-case.
2022-08-09 08:02:56 +02:00
Thomas Haller
eb083eece5
all: add NMMptcpFlags and connection.mptcp-flags property 2022-08-09 08:02:54 +02:00
avery
ebdf3bd376
nmcli-completion: fix support for embedded quote characters
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/455

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1325

Fixes: 9d2290135c ('cli: make nmcli do its own command completion')
2022-08-04 08:59:01 +02:00
Lubomir Rintel
d3d1cd2b3e nmcli: move an assignment down to where the value needed
It's happier there. No change in behavior.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1317
2022-07-29 13:07:38 +02:00
Lubomir Rintel
a3ce5aa50e nmcli: do not assume active connection has a settings connection
The reproducer for another problem tripped an assertion failure:

  $ nmcli con del act-conn
  Connection 'act-conn' (...) successfully deleted.
  $ nmcli con down another-conn

  (process:94552): nm-CRITICAL **: 17:07:21.170: ((src/libnm-client-impl/nm-remote-connection.c:593)): assertion '<dropped>' failed
  Connection 'another-conn' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/4)
  $

What happens is that the second invocation, when resolving the
connection name into a NMRemoteConnection object, assumes an active
connection has a settings connection.

This assumption is likely to be wrong immediately after deleting a
connection was active, before giving the active connection enough time
to fully deactivate.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1317
2022-07-29 13:07:34 +02:00
Christian Glombek
f00e747beb
libnm-client: Add public nm_conn_wireguard_import() func
This commit moves the `nm_vpn_wireguard_import()` function
implementation from `libnmc-base` to `libnm-client-impl`, renaming it to
`nm_conn_wireguard_import()`.

A new `nm_conn_utils` header file is added in `libnm-client-public`.

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

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1299
2022-07-21 14:53:26 +02:00
Thomas Haller
d8a4b3bec2
all: reformat with clang-format (clang-tools-extra-14.0.0-1.fc36) and update gitlab-ci to f36 2022-07-06 11:06:53 +02:00
Thomas Haller
9bfe690ab7
libnm/docs: expand documentation for wireguard.ip4-auto-default-route 2022-06-30 21:30:49 +02:00
Thomas Haller
e6a33c04eb
all: make "ipv6.addr-gen-mode" configurable by global default
It can be useful to choose a different "ipv6.addr-gen-mode". And it can be
useful to override the default for a set of profiles.

For example, in cloud or in a data center, stable-privacy might not be
the best choice. Add a mechanism to override the default via global defaults
in NetworkManager.conf:

  # /etc/NetworkManager/conf.d/90-ipv6-addr-gen-mode-override.conf
  [connection-90-ipv6-addr-gen-mode-override]
  match-device=type:ethernet
  ipv6.addr-gen-mode=0

"ipv6.addr-gen-mode" is a special property, because its default depends on
the component that configures the profile.

- when read from disk (keyfile and ifcfg-rh), a missing addr-gen-mode
  key means to default to "eui64".
- when configured via D-Bus, a missing addr-gen-mode property means to
  default to "stable-privacy".
- libnm's ip6-config::addr-gen-mode property defaults to
  "stable-privacy".
- when some tool creates a profile, they either can explicitly
  set the mode, or they get the default of the underlying mechanisms
  above.

  - nm-initrd-generator explicitly sets "eui64" for profiles it creates.
  - nmcli doesn' explicitly set it, but inherits the default form
    libnm's ip6-config::addr-gen-mode.
  - when NM creates a auto-default-connection for ethernet ("Wired connection 1"),
    it inherits the default from libnm's ip6-config::addr-gen-mode.

Global connection defaults only take effect when the per-profile
value is set to a special default/unset value. To account for the
different cases above, we add two such special values: "default" and
"default-or-eui64". That's something we didn't do before, but it seams
useful and easy to understand.

Also, this neatly expresses the current behaviors we already have. E.g.
if you don't specify the "addr-gen-mode" in a keyfile, "default-or-eui64"
is a pretty clear thing.

Note that usually we cannot change default values, in particular not for
libnm's properties. That is because we don't serialize the default
values to D-Bus/keyfile, so if we change the default, we change
behavior. Here we change from "stable-privacy" to "default" and
from "eui64" to "default-or-eui64". That means, the user only experiences
a change in behavior, if they have a ".conf" file that overrides the default.

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

See-also: https://github.com/coreos/fedora-coreos-tracker/issues/907

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1213
2022-06-29 07:38:48 +02:00
Lubomir Rintel
cd2945f223 nmcli/connections: fix setting ifname with "--ask c add"
We almost always do the wrong thing in interactive add:

The software devices generally require an interactive name, but we don't
insist of asking for them; treating them as optional:

  $ nmcli -a c add type dummy
  There is 1 optional setting for General settings.
  Do you want to provide it? (yes/no) [yes]

For some interface types (bridges, bonds, ...) we make up a name, presumably
for historical reasons. But we don't give the user an option to modify
them:

  $ nmcli -a c add type bridge
  <not asking for interface name at all>
  There are 9 optional settings for Bridge device.
  Do you want to provide them? (yes/no) [yes]

This fixes the above use cases -- still set the default, but be sure to
ask:

  $ nmcli -a c add type dummy
  Interface name:

  $ nmcli -a c add type bridge
  Interface name [nm-bridge1]:

Beautiful.
2022-06-24 00:30:04 +02:00
Lubomir Rintel
647e255362 nmcli/connections: make sure the connection has a base setting
Do the same bookkeeping as would happen upon setting the "type" option
when the connection has a connection.type set upon its addition.

Otherwise the --ask mode is sad:

  $ nmcli --ask c add connection.type team
  ** nm:ERROR:src/nmcli/connections.c:5648:connection_get_base_meta_setting_type: assertion failed: (base_setting)
  Bail out! nm:ERROR:src/nmcli/connections.c:5648:connection_get_base_meta_setting_type: assertion failed: (base_setting)
  Aborted (core dumped)
2022-06-24 00:30:04 +02:00
Lubomir Rintel
e3fa6dfd7f nmcli/connections: factor out code run after new connection's type is set
After the connection's type is set, some bookkeeping is necessary for
the interactive (--ask) mode: appropriate setting need to be added and
options enabled.

Currently it happens in an option setter; which runs when the "type"
options is present on the command line, or the value is set in a
response to interactive mode:

  $ nmcli --ask c add type team

  $ nmcli --ask c add
  Connection type: team

But not when the property is set directly:

  $ nmcli --ask c add connection.type team
  ** nm:ERROR:src/nmcli/connections.c:5648:connection_get_base_meta_setting_type: assertion failed: (base_setting)
  Bail out! nm:ERROR:src/nmcli/connections.c:5648:connection_get_base_meta_setting_type: assertion failed: (base_setting)
  Aborted (core dumped)

This doesn't fix the issue -- a followup commit (hopefully) will.
2022-06-24 00:30:04 +02:00
Lubomir Rintel
b171dcec0d nmcli/connections: use the current value in default in ask_option()
For new connections, this ensures the value in square brackets on
interactive add are always correct.

Apart from that, this allows us to initialize some non-default values
before asking (such as making up an interface name for some software
devices), and inform the user about what we picked:

  Interface name [nm-bridge]:
2022-06-24 00:30:04 +02:00
Lubomir Rintel
ad7ac866db nmcli/connections: don't ask to ask with --ask
This is slightly annoying:

  $ nmcli -a c add type ethernet
  There is 1 optional setting for General settings.

No point in asking if there's just one option. Just ask right away:

  $ nmcli -a c add type ethernet
  Interface name:
2022-06-24 00:30:04 +02:00
Lubomir Rintel
69e65a9b0e nmcli/connections: make sure the connection has a type
We use it before we validate the connection, thus need to check if it's
actually there.
2022-06-24 00:30:04 +02:00
Lubomir Rintel
cf62f0e3a1 nmcli/connections: make enable_options() always enable an option 2022-06-24 00:30:04 +02:00
Lubomir Rintel
6fee8aa454 nmcli/connections: make opts argument to enable_options() optional
This makes things slightly less annoying when dealing with options that
map nicely to properties (unlike bridge options).
2022-06-24 00:30:04 +02:00
Lubomir Rintel
a5e099d008 nmcli/connections: allow empty lists with "--ask c add"
The interactive add is not too enthusiastic about not providing a value
in a list.

That is before on getting an empty line in ask_option() we take a
shortcut instead of dispatching to set_option(). That way we skip
setting the PROPERTY_INF_FLAG_DISABLED flag, causing the option to
be included in questionnaire_one_optional()'s info list.

There's no reason to avoid calling set_option() if we don't get a value;
set_option() handles NULL value just fine.

  $ nmcli -a c add
  Connection type: dummy
  There is 1 optional setting for General settings.
  Do you want to provide it? (yes/no) [yes]
  Interface name [*]: lala
  There are 2 optional settings for IPv4 protocol.
  Do you want to provide them? (yes/no) [yes]
  You can specify this option more than once. Press <Enter> when you're done.
  IPv4 address (IP[/plen]) [none]:
  You can specify this option more than once. Press <Enter> when you're done.
  IPv4 address (IP[/plen]) [none]:
  You can specify this option more than once. Press <Enter> when you're done.
  IPv4 address (IP[/plen]) [none]:
  ...
2022-06-24 00:30:04 +02:00
Lubomir Rintel
d51140d2ab nmcli/connections: do not remove a bond option unless reset is allowed
If we're setting an option with no value given and no reset allowed,
let's just set the default value.
2022-06-24 00:30:04 +02:00
Lubomir Rintel
0cb971d1d6 nmcli/connections: pass allow_reset to check_and_set() callback
Like the regular set_option() handler, the special ones also need to
know whether to reset an option or keep the value.
2022-06-24 00:30:04 +02:00
Lubomir Rintel
0e2ddfd071 nmcli/devices: fix a crash
This is not good:

  $ nmcli device delete nm-bond
  Segmentation fault (core dumped)

Fixes: 5f9d2927ed ("nmcli/devices: use GPtrArray from get_device_list() directly")
2022-06-23 15:12:19 +02:00
Lubomir Rintel
9f9c82f39b merge: branch 'lr/nmcli-checkpoint'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1207
2022-06-23 11:49:48 +02:00
Thomas Haller
3ee61f0913
libnm/docs: add comment about background scanning to wifi.bssid property 2022-06-21 10:36:05 +02:00
David Bauer
02e35f5b20
nmcli: distinguish OWE-TM from OWE BSS
Distinguish a OWE-TM enabled BSS (which itself is unencrypted) from the
OWE BSS actually employing encryption.

Signed-off-by: David Bauer <mail@david-bauer.net>
2022-06-17 19:50:40 +02:00
Thomas Haller
612528af89
libnm/docs: elaborate how ipv4.dns-search/ipv6.dns-search works 2022-06-17 19:32:41 +02:00
Thomas Haller
7cfa8a01cd
cli: reformat file to look better
Comments on the same line as field names are not rendered well by clang-format.
Even if manually edited, it seems not a preferable way to comment on a field.
Move the comment in the line before.
2022-06-16 11:02:20 +02:00