Commit graph

217 commits

Author SHA1 Message Date
David Woodhouse
715921a1fd nmcli, nmtui: reduce duplication around openconnect auth helper
Pull a bunch of stuff into nm_vpn_openconnect_authenticate_helper() that
both callers were doing for themselves, and make its API a bit simpler.
It's given the NMSettingVpn and the GPtrArray of secrets, and it simply
succeeds or fails.
2023-05-11 13:15:53 +01:00
David Woodhouse
f8d82c7f10 nmcli, nmtui: update authentication for OpenConnect
Since OpenConnect 8.20, 'openconnect --authenticate' will return the
full gateway URL, including the hostname and the path. This allows
servers behind SNI-based proxies to work. To ensure we end up at the
same IP address even behind round-robin DNS, there is a separate
--resolve argument.

Update nmcli/nmtui to use this, as NetworkManager-openconnect does.

Shift some of the logic into the nm_vpn_openconnect_authenticate_helper()
function instead of duplicating it in the callers.

Also, pass the correct protocol in rather than only supporting Cisco
AnyConnect.
2023-05-11 13:15:53 +01:00
Fernando Fernandez Mancera
2f0571f193 bonding: add support to prio property in bond ports
Add per port priority support for bond active port re-selection during
failover. A higher number means a higher priority in selection. The
primary port still has the highest priority. This option is only
compatible with active-backup, balance-tlb and balance-alb modes.
2023-05-03 10:44:06 +02:00
Marc Muehlfeld
0cb43c9e42
man: rewrite ipv4.method and ipv6.method man page descriptions
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/1275

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1611
2023-04-27 09:09:11 +02:00
Thomas Haller
21cf2dc58f
libnm,core: make "default${CONNECTION}" the built-in stable ID
The "connection.stable-id" supports placeholders like "${CONNECTION}" or
"${DEVICE}".

The stable-id can also be specified in global connection defaults in
NetworkManager.conf, by leaving it unset in the profile. Global
connection defaults always follow the pattern, that they correspond to a
per-profile property, and only when the per-profile value indicates a
special default/unset value, the global connection default is consulted.
Finally, if the global connection default is also not configured in
NetworkManager.conf, a built-in default is used (which may not be
constant either, for example ipv6.ip6-privacy's built-in default depends
on a sysctl value).

In any case, every possible configuration that can be achieved should be
configurable both per-profile and via global connection default. That
was not given for the stable-id, because the built-in default generated
an ID in a way that could not be explicitly expressed otherwise.

So you could not:
- explicitly set the per-profile value to the built-in default, to avoid
  that the global-connection-default overwrites it.
- explicitly set the global-connection-default to the built-in default,
  to avoid that a lower priority [connection*] section overwrites the
  stable-id again.

Fix that inconsistency to make it possible to explicitly set the
built-in default.

Change behavior for literally "default${CONNECTION}" and make it behave
as the built-in default. Also document that the built-in default has that
value.

It's unlikely that this breaks an existing configuration, but of course,
if any user configured "connection.stable-id=default${CONNECTION}", then
the behavior changes for them.
2023-04-21 12:49:18 +02:00
Beniamino Galvani
f9c1d06e64 libnm,nmcli: add ipv6.dhcp-pd-hint property
Add a new property to specify a hint for DHCPv6 prefix delegation.
2023-04-03 16:04:55 +02:00
Thomas Haller
6043910bff
doc: use "Returns:" annotation instead of deprecated aliases 2023-03-29 11:46:48 +02:00
Thomas Haller
98dd4180ec
all: various fixes to gtk-doc annotations
- drop annotations from "@error" which has defaults.

- ensure all annotations are on the same line. That's useful
  when searching for an annotation, to find the line that specifies
  the argument name.

- convert a few plain docs into gtkdoc annotations.
2023-03-29 11:46:48 +02:00
Fernando Fernandez Mancera
9d4bbf78f0 dns: add support to no-aaaa option
Users can set `no-aaaa` DNS option to suppress AAAA queries made by the
stub resolver, including AAAA lookups triggered by NSS-based interfaces
such as getaddrinfo. Only DNS lookups are affected.
2023-03-28 12:53:58 +02:00
Beniamino Galvani
231128d28d nmcli: increase strength of generated hotspot passwords
The password currently generated has ~48 bits of entropy; increase the
length from 8 to 12 to get ~70 bits. While at it, exclude characters
that look similar and might be entered wrongly by users.
2023-03-28 09:58:29 +02:00
Beniamino Galvani
e446d2b632 nmcli: don't set a fixed channel for wifi hotspots
Since commit f18bf17dea ('wifi: cleanup
ensure_hotspot_frequency()'), NetworkManager automatically selects a
stable channel for AP connections that don't specify a fixed one. The
advantage of this approach is that NM can select a channel that works
well in the current regulatory domain.

However, nmcli still sets fixed channels 1 for 2.4GHz and 7 for 5GHz
when using the "device wifi hotspot". In particular, channel 7 on 5GHz
seems a bad choice because according to [1] it is not usable anywhere
in the world.

It seems difficult to select channel that works everywhere in the 5GHz
band, so it's better to not set a channel in the profile and let NM
find a usable one. For consistency, do the same also for the 2.4GHz
band even if the default choice (channel 1) should always work; by
letting NM choose a channel, different hotspot created with nmcli have
the chance of using different bands and not interfere with each other.

[1] https://en.wikipedia.org/wiki/List_of_WLAN_channels
2023-03-28 09:46:11 +02:00
Beniamino Galvani
ac2fb0e93d nmcli: fix generating hotspot password
The generated password was all non-alphanumeric characters.

Fixes: 6e96d71731 ('all: use nm_random_*() instead of g_random_*()')
2023-03-28 09:46:11 +02:00
Corentin Noël
5d28a0dd89
doc: replace all (allow-none) annotations by (optional) and/or (nullable)
The (allow-none) annotation is deprecated since a long time now, it is better to
use (nullable) and/or (optional) which clarifies what it means with the (out)
annotation.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1551
2023-03-27 11:49:43 +02:00
Thomas Haller
99c375bbce
cli: drop showing "connection.read-only" property
This property has no meaning. It also was only read-only. So while
dropping it from the output is an API break, it hopefully does not break
anybody.
2023-03-27 11:22:47 +02:00
Thomas Haller
8ecd5a675a
libnm: make "connection.read-only" as deprecated
This has no more meaning, and is always false.
2023-03-27 11:22:46 +02:00
Thomas Haller
9487191a4d
libnm: better explain wifi.seen-bssids property 2023-03-27 11:22:45 +02:00
Thomas Haller
cec89aa2e4
cli: drop unused readonly properties "wifi.{rate,tx-power}"
These properties were never implemented. Also, they were not settable
via nmcli. Drop them from being shown. This is an API break, but
hopefully something that does not affect anybody in a bad way.
2023-03-27 11:22:45 +02:00
Thomas Haller
0b9c9832b7
libnm: mark unused properties "wifi.{rate,tx-power}" as deprecated
They were never implemented nor used.
2023-03-27 11:22:44 +02:00
Yuri Chornoivan
3844c012df
libnm: fix minor typos in documentation
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1580
2023-03-23 12:52:02 +01:00
Joao Machado
7c54d26ad6 libnmc-setting/docs: how to disable ip-tunnel.encapsulation-limit (ip6) 2023-03-13 08:41:45 +00:00
Thomas Haller
0ebfffb5eb
libnm/docs: mention "ipv[46].dhcp-iaid=stable" to be affected by "connection.stable-id" 2023-03-08 09:04:32 +01:00
Lubomir Rintel
33ca7a0c83 nmcli: set LESSSECURE=1 (unless already set)
Apparently, the pager being able to execute commands takes some people
by surprpise, making their poor configuration choices have consequences.

Let's pray for some mercy on their souls with the LESSECURE variable,
which makes less less likely to conduct evil deeds.

Systemd also deals with this, but being systemd they make it as
complicated as possible. We just set it unconditionally, hoping nobody
wanted the extra functionality and they're in only for the scrolling.
If anyone minds they can just set LESSSECURE=0 and we'll leave it alone.

See also: SYSTEMD_PAGERSECURE in systemctl(1) manual.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1559
2023-03-07 20:12:00 +01:00
Beniamino Galvani
39bfcf7aab all: add "link" setting
Introduce a new "link" setting that holds properties that are related
to the kernel link.
2023-03-02 16:51:16 +01:00
liaohanqin
2f8694c439 nmcli: add WPA-EAP-SUITE-B-192 to SECURITY 2023-03-01 13:59:32 +00:00
Fernando Fernandez Mancera
b5e347b313 client/tests: adjust expected output for new order of replace-local-rule
Now replace-local-rule is under routing-rules and therefore expected
output need to be adjusted in tests.
2023-02-22 22:20:41 +00:00
Fernando Fernandez Mancera
d2ca44ffc6 all: add new "ipv[46].replace-local-rule" setting
This setting allows the user to remove the local route rule that is
autogenerated for both IPv4 and IPv6. By default, NetworkManager won't
touch the local route rule.
2023-02-21 15:36:38 +01:00
Thomas Haller
f36fabc0fa
libnm/docs: improve documentation for ipv[46].dhcp-iaid setting 2023-02-21 09:20:51 +01:00
Sven Schwermer
db3b112846
libnm: Add initial EPS parameters to gsm settings
The configure flag and APN for the initial EPS bearer are used when
bringing up cellular modem connections. These settings are only relevant
for LTE modems.

Signed-off-by: Sven Schwermer <sven.schwermer@disruptive-technologies.com>
2023-02-20 12:59:39 +01:00
Thomas Haller
b32e4c941a
nmcli: replace all uses of g_print()/g_printerr() with nmc_print()/nmc_printerr()
The main purpose is to simplify printf debugging and manual testing.  We
can now trivially patch the code so that all output from nmcli gets
(additionally) written to a file. That is useful when debugging a unit
test in "test-client.py". Thereby we can duplicate all messages via
nm_utils_print(), which is in sync with the debug messages from libnm
and which honors LIBNM_CLIENT_DEBUG_FILE.
2023-02-08 10:11:18 +01:00
Thomas Haller
4cf94f30c7
nmcli: add nmc_print()/nmc_printerr() macros
These will replace the direct calls to g_print()/g_printerr() in nmcli.
There are two purposes.

1) the new macros embody the concept of "printing something from nmcli".
   It means, we can `git grep` for those functions, and find all the
   relevant places, without hitting the irrelevant ones (e.g. tests that
   also use g_print()).

2) by having one place, we can trivially change it. That is useful for
   printf debugging. For example, "test-client.py" runs nmcli and
   captures and compares the output.  With libnm we can set
   LIBNM_CLIENT_DEBUG and LIBNM_CLIENT_DEBUG_FILE to print libnm debug
   messages to a file. But we cannot trivially synchronize the messages
   from nmcli with that output (also because they are consumed by the test
   and not immediately accessible). This would be easy, if we temporarily
   could patch nmc_print*() to also log to nm_utils_print(). The new macros
   will allow doing that at one place.

For example, patch the "#if 0" and run:

  $ LIBNM_CLIENT_DEBUG=trace \
    LIBNM_CLIENT_DEBUG_FILE='xxx.%p' \
    NMTST_USE_VALGRIND=1 \
    LIBTOOL="/bin/sh ./libtool"
    ./src/tests/client/test-client.sh -- -k monitor
2023-02-08 10:11:17 +01:00
Thomas Haller
4b2ded7a4a
nmcli/trivial: rename nmc_print() to nmc_print_table()
nmc_print() will be used for something else. Rename. Also,
nmc_print_table() is the better name anyway because the function does  a
lot of formatting and not simple printf().
2023-02-08 10:11:16 +01:00
Thomas Haller
d3e2e9dc20
nmcli/trivial: rename monitor functions in internal header file
Identifiers in our headers should have a "nm" prefix. Rename.
2023-02-08 10:11:15 +01:00
Thomas Haller
ea3e61047f
cli: fix leaking "value" string in ask_option()
Fixes: c5324ed285 ('nmcli: streamline connection addition')
2023-02-08 09:51:25 +01:00
Thomas Haller
5dc07174d3
cli: use "free()" for string from readline
Since glib 2.45, we are guaranteed that g_free() just calls free(), so
both can be used interchangeably. However, we still only depend on glib
2.40.

In any case, it's ugly to mix the two. Memory allocated by plain
malloc(), should be only freed with free(). The buffer in question comes
from readline, which allocates it using the system allocator.

Fixes: 995229181c ('cli: remove editor thread')
2023-02-08 09:51:25 +01:00
Thomas Haller
89734c7553
cli: avoid leak in readline_cb() overwriting previous line
Such leaks show up in valgrind, and are simply bugs.

Also, various callers (not all of them, which is another bug!) like to
take ownership of the returned string and free it. That means, we leave
a dangling pointer in the global variable, which is very ugly and error
prone.

Also, the callers like to free the string with g_free(), which is not
appropriate for the "rl_string" memory which was allocated by readline.
It must be freed with free(). Avoid that, by cloning the string using
the glib allocator.

Fixes: 995229181c ('cli: remove editor thread')
2023-02-08 09:51:25 +01:00
Thomas Haller
6e96d71731
all: use nm_random_*() instead of g_random_*()
g_random_*() is based on GRand, which is not a CSPRNG. Instead, rely on
kernel to give us good random numbers, which is what nm_random_*() does.

Note that nm_random_*() calls getrandom() (or reads /dev/urandom), which
most likely is slower than GRand. It doesn't matter for our uses though.

It is cumbersome to review all uses of g_rand_*() whether their usage of
a non-cryptographically secure generator is appropriate. Instead, just
always use an appropriate function, thereby avoiding this question. Even
glib documentation refers to reading "/dev/urandom" as alternative. Which
is what nm_random_*() does. These days, it seems unnecessary to not use
the best random generator available, unless it's not fast enough or you
need a stable/seedable stream of random numbers.

In particular in nmcli, we used g_random_int_range() to generate
passwords. That is not appropriate. Sure, it's *only* for the hotspot,
but still.
2023-01-30 10:51:13 +01:00
Thomas Haller
108ab677e4
nmcli/style: fix clang-format style
Fixes: 8132045d5f ('nmcli: fix typos in nmcli output')
2023-01-27 08:32:39 +01:00
Michael Biebl
8132045d5f
nmcli: fix typos in nmcli output
Spotted by lintian:
  I: network-manager: spelling-error-in-binary writting writing [usr/bin/nmcli]
  I: network-manager: spelling-error-in-binary wihout without [usr/lib/x86_64-linux-gnu/NetworkManager/1.40.12/libnm-device-plugin-wifi.so]

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1515
2023-01-27 08:00:02 +01:00
Beniamino Galvani
f930d55fea all: add support for ovs-dpdk n-rxq-desc and n-txq-desc
https://bugzilla.redhat.com/show_bug.cgi?id=2156385

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1500
2023-01-17 08:45:04 +01:00
Thomas Haller
a259303e1d
ovs: add support for "other_config" settings
See `man ovs-vswitchd.conf.db` for documentation of "other_config" keys.

https://bugzilla.redhat.com/show_bug.cgi?id=2151455
2023-01-11 21:49:36 +01:00
Frederic Martinsons
4509c303fa
all: add new "ipv[46].auto-route-ext-gw" setting
For external gateway route management. This setting allows an user
to deactivate the automatic route addition to the external gateway.
It can be especially useful when a VPN inside another VPN is used.

Signed-off-by: Frederic Martinsons <frederic.martinsons@unabiz.com>

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

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1491
2023-01-09 09:35:52 +01:00
Beniamino Galvani
a39ec8ca75 nmcli: fix double free
src/nmcli/devices.c:1196: double_free: Calling "_nm_auto_strfreev" frees pointer "arg_arr" which has already been freed.

Fixes: c5d45848dd ('cli: mark argv argument for command line parsing as const')
2022-12-22 11:24:37 +01:00
Beniamino Galvani
199eb725ad libnm: support VTI properties in the ip-tunnel setting
Add the fwmark property and allow setting input and output key for VTI
tunnels.
2022-12-21 14:04:44 +01:00
Beniamino Galvani
1bbde12e57 libnm,nmcli: add vlan.protocol property
Introduce a "vlan.protocol" property that specifies the protocol of a
VLAN, which controls the tag (EtherType) used for encapsulation.

Regular VLANs use 802.1Q (tag 0x8100). To implement VLAN stacking it's
sometimes useful to have 802.1ad VLANs with tag 0x88A8.

The property is a string instead of e.g. an enum because this allows
maximum flexibility in the future. For example, it becomes possible to
specify an arbitrary number in case if the kernel ever allows it.
2022-12-14 11:33:03 +01:00
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