Commit graph

173 commits

Author SHA1 Message Date
Thomas Haller
36f8de25c4
all: fix various "-Wcast-align=strict" warnings
The warning "-Wcast-align=strict" seems useful and will be enabled
next. Fix places that currently cause the warning by using the
new macro NM_CAST_ALIGN(). This macro also nm_assert()s that the alignment
is correct.
2022-12-09 09:15:56 +01:00
Thomas Haller
1bf73642dc
all: fix "-Wcast-align=strict" warnings for GArray casts
GArray.data is a char pointer. Most of the time we track other data in
a GArray. Casting that pointer can trigger "-Wcast-align=strict"
warnings.

Avoid them. Most of the time, instead use the nm_g_array*() helpers,
which also assert that the expected element size is correct.
2022-12-09 09:15:55 +01:00
Thomas Haller
977c1e76a8
all: use nm_g_array_first()/nm_g_array_first_p() where suitable 2022-12-09 09:15:53 +01:00
Beniamino Galvani
9ae0605055 libnm: accept "dot1q-tunnel" as vlan mode for ovs-ports
openvswitch accepts "dot1q-tunnel" as vlan mode:

    A dot1q-tunnel port is somewhat like an access port. Like an
    access port, it carries packets on the single VLAN specified
    in  the  tag  column and this VLAN, called the service VLAN,
    does not appear in an 802.1Q header for packets that ingress
    or  egress  on the port. The main difference lies in the be‐
    havior when packets that include a 802.1Q header ingress  on
    the  port.  Whereas  an  access  port  drops such packets, a
    dot1q-tunnel port treats these  as  double-tagged  with  the
    outer  service  VLAN  tag  and the inner customer VLAN taken
    from the 802.1Q header. Correspondingly, to  egress  on  the
    port,  a packet outer VLAN (or only VLAN) must be tag, which
    is removed before egress, which exposes the inner (customer)
    VLAN if one is present.

Support this mode.
2022-11-25 14:15:41 +01:00
Beniamino Galvani
b64e690db8 libnm: add ovs-port.trunks property
Add a new "ovs-port.trunks" property that indicates which VLANs are
trunked by the port.

At ovsdb level the property is just an array of integers; on the
command line, ovs-vsctl accepts ranges and expands them.

In NetworkManager the ovs-port setting stores the trunks directly as a
list of ranges.
2022-11-25 14:15:41 +01:00
Wen Liang
e8618f03d7
support loopback interface
Support managing the loopback interface through NM as the users want to
set the proper mtu for loopback interface when forwarding the packets.
Additionally, the IP addresses, DNS, route and routing rules are also
allowed to configure for the loopback connection profiles.

https://bugzilla.redhat.com/show_bug.cgi?id=2060905
2022-11-23 20:51:22 +01:00
Thomas Haller
3fb8c0f614
clang-format: reformat code with clang-format 15.0.4-1.fc37
This is the version shipped in Fedora 37. As Fedora 37 is now out, the
core developers switch to it. Our gitlab-ci will also use that as base
image for the check-{patch.tree} tests and to generate the pages. There
is a need that everybody agrees on which clang-format version to use,
and that version should be the one of the currently used Fedora release.

Also update the used Fedora image in "contrib/scripts/nm-code-format-container.sh"
script.

The gitlab-ci still needs update in the following commit. The change
in isolation will break the "check-tree" test.
2022-11-23 09:17:21 +01:00
Beniamino Galvani
dfe63d9eb3 macsec: document the format of CAK and CKN properties 2022-11-16 10:36:39 +01:00
Lubomir Rintel
fe2eddd67c nmcli/monitor: always print running status on monitor startup
Previously we'd note if NM is stopped, but not if it's running.
I suppose it's nice for the user to know that the monitor started
running, but, it's also important for the monitor to be testable (so
that we know that we are ready to start adding mock objects, etc.)

This also gets rids of some duplication at expense of a little less
nuanced message.
2022-11-13 15:24:19 +01:00
Lubomir Rintel
117a440cd9 libnm: fix a large amount of Since tags
Some comments are malformed, some are missing altogether.
2022-11-08 11:40:18 +01:00
Thomas Haller
1bfe908c2e
nmcli: rename "generate-docs-nm-settings-nmcli" to "gen-metadata-nm-settings-nmcli"
This is the better name, becuse this is not in particular about "docs".
It's about generating an XML with the information from the settings
meta data for nmcli.

We will do something similar with the libnm-core meta data.
2022-10-31 09:11:30 +01:00
Thomas Haller
139f4b4b2e
build: pass both filenames to "tools/check-compare-generated.sh" script
It just feels nicer to be explicit about the filenames and
not rely on a specific naming.

Also, in meson we can directly pass the target as argument, which
expands to the filename but also adds a dependency.
2022-10-31 09:11:30 +01:00
Thomas Haller
489f65bf9c
build/meson fix "gen-metadata-nm-settings-nmcli.xml.in" without enable_docs
Fixes: ab8fdb73e6 ('build: commit pre-generated "generate-docs-nm-settings-nmcli.xml" to git')
2022-10-31 09:11:30 +01:00
Thomas Haller
0622ed7051
cli: cleanup connecting state change signal
It seems really ugly, to pass a callback function of wrong
signature. Granted, it probably works due to the C calling
convention, but it seems odd.

Use callbacks of the proper type instead. Then we also don'
need g_signal_connect_swapped().

While at it, rename. "connected_state_cb()" seems a bad name.
2022-10-28 08:52:08 +02:00
Thomas Haller
d5be1c706e
dns/resolved: set DoT server name (SNI) in systemd-resolved
Unfortunately, for this we require SetLinkDNSEx() API from v246.
That adds extra complexity.

If the configuration contains no server name, we continue using
SetLinkDNS(). Otherwise, at first we try using SetLinkDNSEx().
We will notice if that method is unsupported, reconfigure with
SetLinkDNS(), and set a flag to not try that again.
2022-10-27 09:11:38 +02:00
Thomas Haller
6f9090538f
dns: accept DoT SNI server name in "ipv[46].dns" settings 2022-10-27 09:11:31 +02:00
Thomas Haller
619032c6d0
cli: increase buffer in pager_fallback()
The stack is large enough. Let's use a larger buffer.
2022-10-24 08:53:04 +02:00
Thomas Haller
e843a7caa2
cli: don't use unsafe functions in pager_fallback()
The pager_fallback() runs in the forked child process.
As such, it can only use functions from `man signal-safety`
or that are explicitly allowed.

We are mostly good, but g_printerr() is not allowed. It can deadlock.
Just avoid it. It's not very to print those error messages anyway.
2022-10-24 08:53:03 +02:00
Thomas Haller
a35d8ff769
cli: don't call setenv() after fork
setenv() cannot be called after fork, because it might allocate memory,
which can deadlock.

Instead, prepare the environment and use execvpe().

`man 2 fork` says:

  After a fork() in a multithreaded program, the child can safely call
  only async-signal-safe functions (see signal-safety(7)) until such time
  as it calls execve(2).

This means, we are quite strongly limited what can be done in the child
process, before exec. setenv() is not listed as async-signal-safe, obviously
because it allocates memory, and malloc() isn't async-signal-safe either.

See also glib's documentation of GSpawnChildSetupFunc ([1]) about what
can be done in the child process.

[1] 08cb200aec/glib/gspawn.h (L124)
2022-10-24 08:53:03 +02:00
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