Commit graph

1763 commits

Author SHA1 Message Date
Eliot Lear
295e6678dd dhcp: add support for MUD URL (RFC 8520)
[thaller@redhat.com: rewritten commit message]

https://tools.ietf.org/html/rfc8520
https://blog.apnic.net/2019/05/14/protecting-the-internet-of-things-with-mud/

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

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/463
2020-04-24 10:07:38 +02:00
Thomas Haller
411255d51f cli: unset "ipv[46].never-default" when setting "ipv[46].gateway"
Since commit c1907a218a ('libnm-core: remove gateway when
never-default=yes in NMSettingIPConfig'), the gateway gets normalized
away when the profile has never-default set.

That means,

  $ nmcli connection modify "$PROFILE" ipv4.never-default yes ipv4.gateway 192.168.77.1

does not set the gateway. Likewise, if your profile has already never-default
enabled,

  $ nmcli connection modify "$PROFILE" ipv4.gateway 192.168.77.1

will have no effect. That is confusing and undesirable.

Note that we don't adjust the GObject property setter for "gateway" to clear
never-default. I feel, setting one property in libnm should preferably
not unset another (there are exceptions to the rule, like for team
properties). However, for nmcli it's clear in which order properties
are set, so this change is right for the client tool.

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

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/475
2020-04-22 21:04:42 +02:00
Thomas Haller
115291a46f wireguard: don't let explicit gateway override WireGuard's peer route
The profile's "ipv4.gateway" and "ipv6.gateway" has only one real
purpose: to define the next hop of a static default route.

Usually, when specifying a gateway in this way, the default route from
other addressing methods (like DHCPv4 or IPv6 autoconf) gets ignored.

If you have a WireGuard peer with "AllowedIPs=0.0.0.0/0" and
"wireguard.peer-routes" enabled, NetworkManager would automatically add
a route to the peer. Previously, if the user also set a gateway, that
route was suppressed.

That doesn't feel right. Note that configuring a gateway on a WireGuard
profile is likely to be wrong to begin with. At least, unless you take
otherwise care to avoid routing loops. If you take care, setting a
gateway may work, but it would feel clearer to instead just add an
explicit /0 manual route instead.

Also, note that usually you don't need a gateway anyway. WireGuard is a
Layer 3 (IP) tunnel, where the next hop is alway just the other side of
the tunnel. The next hop has little effect on the routes that you
configure on a WireGuard interface. What however matters is whether a
default route is present or not.

Also, an explicit gateway probably works badly with "ipv[46].ip4-auto-default-route",
because in that case the automatism should add a /0 peer-route route in a
separate routing table. The explicit gateway interferes with that too.

Nonetheless, without this patch it's not obvious why the /0 peer
route gets suppressed when a gateway is set. Don't allow for that, and
always add the peer-route.

Probably the profile's gateway setting is still wrong and causes the
profile not to work. But at least, you see all routes configured, and
it's clearer where the (wrong) default route to the gateway comes from.
2020-04-22 11:36:51 +02:00
Thomas Haller
5da82ee3ea wireguard: suppress automatic "wireguard.peer-routes" for default routes if "ipv[46].never-default" is enabled
Enabling both peer-routes and never-default conflicts with having
AllowedIPs set to a default route. Let never-default win.
2020-04-22 11:05:39 +02:00
Thomas Haller
5e47fb630b dns: add trust-ad DNS option only if all contributing settings agree
https://bugzilla.redhat.com/show_bug.cgi?id=1825285
2020-04-20 15:54:43 +02:00
Thomas Haller
e261e941fd libnm: document supported "ipv[46].dns-option" values 2020-04-20 15:54:43 +02:00
Antonio Cardace
a5916de599
ethtool: refactor how options are hidden if default
Just use the new flag NMMetaPropertyInfo.
2020-04-16 10:52:46 +02:00
Antonio Cardace
3af07fd415
bridge: make some advanced options hidden if default
The options are:
  * group-address
  * multicast-querier
  * multicast-query-use-ifaddr
  * multicast-router
  * vlan-stats-enabled
  * vlan-protocol
2020-04-16 10:52:45 +02:00
Thomas Haller
69eca25391
cli: let _print_fill() hide option if NM_META_ACCESSOR_GET_OUT_FLAGS_HIDE is set
Regardless, whether the option is also currently the default.
2020-04-16 10:52:45 +02:00
Antonio Cardace
b94fcb2a94
clients: allow properties to be hidden if they have the default value 2020-04-16 10:52:42 +02:00
Thomas Haller
3e1e63e57d cli/polkit: make parsing polkit-agent-helper-1 protocol more conforming
- in io_watch_have_data(), ensure that we handle incomplete lines
that don't yet have a newline by waiting for more data. That means,
if the current content of the in_buffer does not have a newline, we
wait longer.

- in io_watch_have_data(), implement (and ignore) certain commands
instead of failing the request.

- in io_watch_have_data(), no longer g_compress() the entire line.
"polkitagenthelper-pam.c" never backslash escapes the command, it
only escapes the arguments. Of course, there should be no difference
in practice, except that we don't want to handle escape sequences
in the commands.

- in io_watch_have_data(), compare SUCCESS/FAILURE literally.
"polkitagenthelper-pam.c" never appends any trailing garbage to these
commands, and we shouldn't handle that (although "polkitagentsession.c"
does).

- when io_watch_have_data() completes with success, we cannot destroy
AuthRequest right away. It probably still has data pending that we first
need to write to the polkit helper. Wait longer, and let io_watch_can_write()
complete the request.

- ensure we always answer the GDBusMethodInvocation. Otherwise, it gets
leaked.

- use NMStrBuf instead of GString.
2020-04-10 10:44:57 +02:00
Thomas Haller
277925c36a cli/polkit: suppress stderr from polkit-agent-helper when prompting for polkit authentication
Otherwise, we get an additional error message form the helper:

  $ nmcli --ask device wifi rescan
  System policy prevents Wi-Fi scans
  (action_id: org.freedesktop.NetworkManager.wifi.scan)
  password (user): •••••••
  polkit-agent-helper-1: pam_authenticate failed: Authentication failure
  Error: org.freedesktop.NetworkManager.wifi.scan request failed: not authorized.
2020-04-10 10:44:56 +02:00
Thomas Haller
d4a20fe360 cli/polkit: rework parsing identities for polkit request
The identities are in a nested dictionary of variants. We only want
to pick the "unix-user" values that we can handle.
2020-04-10 10:44:54 +02:00
Thomas Haller
b0759e9662 cli/polkit: reject unknown D-Bus methods 2020-04-10 10:44:53 +02:00
Thomas Haller
0dbb9c279e cli/polkit: rename NM_POLKIT_LISTENER_SIGNAL_REQUEST signal to "request-sync"
The response is blocking, which generally is rather ugly. Let's not fix
that now, but at least rename the signal so that it clearly points this
out.
2020-04-10 10:44:52 +02:00
Thomas Haller
7d91208218 cli/polkit: avoid G_DECLARE_FINAL_TYPE() in nm-polkit-listener.h
G_DECLARE_FINAL_TYPE() is glib 2.44, while we currently still only require glib 2.40.
2020-04-10 10:44:51 +02:00
Thomas Haller
aede8fa554 cli: remove redundant return value from NMCCommand funcs
Many func implementations are asynchronous, that means, they
cannot return right away. Instead, they record the return value
in nmc->result_value.

The return value from the command functions was thus redundant.
In the best case, the return value agrees with the cached result
in nmc->result_value, in which it was unnecessary. In the worst case,
they disagree, and overwrite each other.

nmc->result_value is state. Tracking state is hard, and there should
be fewer places where the state gets mutated. Also, the rules how that
happened should be clearer. Drop the redundant, conflicting mechanism.
2020-04-10 10:44:37 +02:00
Thomas Haller
c5d45848dd cli: mark argv argument for command line parsing as const
It's bad style to pass the argv argument around and mutate it.
We shouldn't mutate it, and not assume that it stays around after
the function returns to the caller (meaning, we should clone the
array if we intend to use it later).

Add const specifier.
2020-04-10 10:27:27 +02:00
Thomas Haller
3a451141bd cli: merge implementations for do_networking_on_off() 2020-04-10 10:27:27 +02:00
Thomas Haller
d39f5c264b cli: pass cmd to NMCCommand.func()
It is useful from inside a function to know the command that it belongs to.
Currently we have do_networking_on() and do_networking_off() as separate
functions. However, these are basically the same with a minor difference.
If the func callback could know the "cmd" that it was called for, these
function can be combined.

Of course, without passing the NMCCommand instance, you still can
achieve the same results, especially as the NMCCommand instances are
static and known at compile time: just have separate func
implementations. But by passing the command to the function, they
*can* be combined, which is a useful thing to do.
2020-04-10 10:27:27 +02:00
Thomas Haller
e05f35f9f1 cli: cleanup NMCCommand and declarations of func implementations
- move the main func declarations to nmcli.h and give them a common
prefix "nmc_command_func_" prefix.

- remove some of the header files that are now empty. In fact, these
headers did not really declare some well separated module. While we
probably should structure the code in nmcli better with better layering,
it was not and still is not. Having these dummy headers don't mean that
the code is well structured and they serve little purpose.

- move the static NMCommand lists variables into the function scope
where they are used.
2020-04-10 10:27:27 +02:00
Thomas Haller
25bec53602 clients/trivial: remove obsolete comment from test-client.py howto
This would only be necessary when editing the test themselves,
to not only remove individual tests, but entire test runs.
It's not necessary to describe that in the howto.
2020-04-09 14:10:56 +02:00
Thomas Haller
7b630d8dba clients: set ipv4.dns-priority to a exclusive value (-10) when importing WireGuard profiles 2020-04-08 13:47:26 +02:00
Thomas Haller
88756703cf clients: set routing search domain with nameservers when importing WireGuard profile
When the users configure a DNS server on the interface, they likely
want to use it, regardless whether there is a default route on the
device.

For that to work, add an explicit "~" search domain.

Otherwise, by default NetworkManager only adds the special search domain
only on devices that have a "best default route" (nm_ip_config_best_default_route_is).
But that only considers a best default route in the main table, and
WireGuard (with ipx-auto-default-route) adds the default route to a
separate table. The heuristic to determine best devices works not well
with policy routing, so explicitly add this search domain during import.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/405
2020-04-08 12:33:56 +02:00
Thomas Haller
9e35b16032 clients: use nm_utils_inet_ntop_dup() in nm_vpn_wireguard_import() 2020-04-08 12:18:40 +02:00
Thomas Haller
d66cbb113d clients/trivial: fix outdated code comment about Table=auto in nm_vpn_wireguard_import() 2020-04-08 12:18:40 +02:00
Antonio Cardace
ad052c3d67
nm-setting-bridge: add 'multicast-querier' bridge option
https://bugzilla.redhat.com/show_bug.cgi?id=1755768
2020-04-06 09:56:11 +02:00
Antonio Cardace
a685cce70a
nm-setting-bridge: add 'multicast-query-use-ifaddr' bridge option
https://bugzilla.redhat.com/show_bug.cgi?id=1755768
2020-04-06 09:56:11 +02:00
Antonio Cardace
e01d3b4c2b
nm-setting-bridge: add 'multicast-router' bridge option
Also add related unit test.

https://bugzilla.redhat.com/show_bug.cgi?id=1755768
2020-04-06 09:56:11 +02:00
Antonio Cardace
bd30491f42
nm-setting-bridge: add 'vlan-stats-enabled' bridge option
https://bugzilla.redhat.com/show_bug.cgi?id=1755768
2020-04-06 09:56:11 +02:00
Antonio Cardace
f5352ff656
nm-setting-bridge: add 'vlan-protocol' bridge option
Also add related unit test.

https://bugzilla.redhat.com/show_bug.cgi?id=1755768
2020-04-06 09:56:11 +02:00
Antonio Cardace
93e38cbe56
nm-setting-bridge: add 'group-address' bridge option
Also add related unit test.

https://bugzilla.redhat.com/show_bug.cgi?id=1755768
2020-04-06 09:56:11 +02:00
Thomas Haller
421784d2f1 cli: support backslash escaping for cli options like vpn.data, vpn.secrets, bond.options, ethernet.s390-options
This is obviously a change in behavior, as we now honor backslash
escape sequences. With this change, all string values can be expressed,
both as option keys and values.

Previously, you could for example not set vpn.secrets to have a ','
and you could not set vpn.data to

  nmcli connection modify "$PROFILE" +vpn.data 'ipsec-ike = aes256-sha2_256-modp2048,aes256-sha2_256-modp1536'

Use a relatively simple backslash escaping scheme. The main goal of
the scheme is that it doesn't change behavior for the majority of cases.
It only changes behavior for setting an option if:

  - the string contains a backslash

  - and if the backslash proceeds one of the few characters that support
    escaping now (white space, ',', '\\', and '=').

The only downside here is that backslash is only treated special, if it
preceeds a character that requires escaping. That makes the behavior
non intuitive. However, it allows to write most backslashes without
escaping them as "\\\\" and thus keep previous behavior.

The nmcli getters now also escape the options accordingly. That means,
the string printed by the getter is also a valid input for the setter.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/390
2020-04-04 19:53:03 +02:00
Thomas Haller
db035d113b cli: simplify _value_strsplit() by using nm_utils_strsplit_set_full()
The two modes VALUE_STRSPLIT_MODE_OBJLIST and VALUE_STRSPLIT_MODE_MULTILIST
basically do regular split and afterwards g_strstrip() all values and
remove empty tokens.

That is what the NM_UTILS_STRSPLIT_SET_FLAGS_STRSTRIP flag already does.
Use it.

There should be no change in behavior.
2020-04-04 19:51:34 +02:00
Thomas Haller
d9381362a5 cli: allow setting VPN data and secrets to empty values 2020-04-04 19:51:34 +02:00
Thomas Haller
038d53a745 cli: hide nm_cli global variable from public headers 2020-04-04 19:28:41 +02:00
Thomas Haller
30b8bb476a cli: avoid using nm_cli global variable in print_data() 2020-04-04 19:28:41 +02:00
Thomas Haller
dbf697c759 cli: avoid passing full NmCli global variable to nm_cli_spawn_pager()
We should not use global variables, and we should minimize the state
that we pass around. Instead of requiring the full NmCli struct in
nm_cli_spawn_pager(), pass only the necessary data.

This reduces our use of global variables.
2020-04-04 19:28:41 +02:00
Thomas Haller
7627173c0e cli: make nmc_meta_environment_arg const pointer
Of course, we later pass the point on, where we need to cast the constness away
again. This is more a reminder that we aren't suppost to change the variable.
2020-04-04 19:28:41 +02:00
Thomas Haller
873f4795b2 cli: add and use nm_cli_global_readline global variable
We should try to avoid access to global variables. For libreadline
callbacks we still need a global variable.

Introduce a global variable nm_cli_global_readline, specially for this
use. It makes the places clear where we use it, and discourages
the use at other places, where we better avoid global variables.
2020-04-04 19:28:41 +02:00
Thomas Haller
93a6bcc8a2 cli: fix nmcli device wifi list --rescan=yes to wait
Fixes: db396cea9d ('cli: rework do_device_wifi_list() to scan and print Wi-Fi list')
2020-04-03 11:26:49 +02:00
Thomas Haller
46dd4d0fbf meson: merge branch 'inigomartinez/meson-license'
Add SPDX license headers for meson files.

As far as I can tell, according to RELICENSE.md file, almost everybody
who contributed to the meson files agreed to the LGPL-2.1+ licensing.
This entails the vast majority of code in question.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/397
2020-03-28 12:45:19 +01:00
Niklas Goerke
bddba4ca8b Add domain_match mode for wifi certificate domain comparison
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/308
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/437
2020-03-23 20:31:09 +01:00
Thomas Haller
27c0d9d8b7 clients/tests: comment return code by signal in test output
Otherwise, we just see "returncode: -11", which isn't very clear.
By default, our test nmcli invocations should never exit by a signal.
Usually, when we encounter a signal, it indicates to a bug and a crash
during the test.

Print more information about the exit code.

    returncode: -11 (SIGNAL SIGSEGV)
2020-03-23 13:30:13 +01:00
Beniamino Galvani
2334a27692 cli: support setting removal 2020-03-23 11:42:57 +01:00
Beniamino Galvani
0d0c79d5ab libnm-core: slightly improve sriov setting documentation 2020-03-23 11:42:57 +01:00
Thomas Haller
52dbab7d07 all: use nm_clear_pointer() instead of g_clear_pointer()
g_clear_pointer() would always cast the destroy notify function
pointer to GDestroyNotify. That means, it lost some type safety, like

   GPtrArray *ptr_arr = ...

   g_clear_pointer (&ptr_arr, g_array_unref);

Since glib 2.58 ([1]), g_clear_pointer() is also more type safe. But
this is not used by NetworkManager, because we don't set
GLIB_VERSION_MIN_REQUIRED to 2.58.

[1] f9a9902aac

We have nm_clear_pointer() to avoid this issue for a long time (pre
1.12.0). Possibly we should redefine in our source tree g_clear_pointer()
as nm_clear_pointer(). However, I don't like to patch glib functions
with our own variant. Arguably, we do patch g_clear_error() in
such a manner. But there the point is to make the function inlinable.

Also, nm_clear_pointer() returns a boolean that indicates whether
anything was cleared. That is sometimes useful. I think we should
just consistently use nm_clear_pointer() instead, which does always
the preferable thing.

Replace:

   sed 's/\<g_clear_pointer *(\([^;]*\), *\([a-z_A-Z0-9]\+\) *)/nm_clear_pointer (\1, \2)/g' $(git grep -l g_clear_pointer) -i
2020-03-23 11:22:38 +01:00
Thomas Haller
073994ca42 all: use nm_clear_g_free() instead of g_clear_pointer()
I think it's preferable to use nm_clear_g_free() instead of
g_clear_pointer(, g_free). The reasons are not very strong,
but I think it is overall preferable to have a shorthand for this
frequently used functionality.

   sed 's/\<g_clear_pointer *(\([^;]*\), *\(g_free\) *)/nm_clear_g_free (\1)/g' $(git grep -l g_clear_pointer) -i
2020-03-23 11:05:34 +01:00
Thomas Haller
42edeb62a3 cli: use async method D-Bus for nmcli radio wifi on|off
Showcase nm_client_dbus_set_property().

Thereby, also print error messages and return an error if
the command fails.

Also, enable PolicyKit authentication (although, I think there are
some bugs with this still).
2020-03-23 09:38:23 +01:00
Thomas Haller
c6c15c2c25 cli: use async method D-Bus for nmcli networking on|off
Previously, we would call the synchronous nm_client_networking_set_enabled()
method. There were 3 problems:

1) nmcli ignored the return value, that means, if the request failed with
  access denied it would just silently pretend that it succeeded.

2) nmcli first called nmc_start_polkit_agent_start_try(), but when
  invoking the synchronous method, the main context is busy and a
  polkit request cannot possibly be handled.

3) nm_client_networking_set_enabled() is deprecated.

Fix all of these, by calling the D-Bus method directly.

Policykit authentication requests are only handled partly. There
seems to be an unrelated race/bug. Now it works sometimes.
2020-03-23 09:37:53 +01:00