Commit Graph

158 Commits

Author SHA1 Message Date
Thomas Haller
78629830c8 all: add "libnm-core/nm-default-libnm-core.h" as replacement for "nm-default.h" 2021-02-09 12:38:18 +01:00
Thomas Haller
3389192703 libnm/docs: explain that edns0/trust-ad is automatically added to DNS options
Since commit f91a8ef332 ('dns: add edns0 and trust-ad options when
using local resolver') we automatically set these options.

Document it.
2021-01-26 17:04:28 +01:00
Thomas Haller
977ea352a0 all: update deprecated SPDX license identifiers
These SPDX license identifiers are deprecated ([1]). Update them.

[1] https://spdx.org/licenses/

  sed \
     -e '1 s%^/\* SPDX-License-Identifier: \(GPL-2.0\|LGPL-2.1\)+ \*/$%/* SPDX-License-Identifier: \1-or-later */%' \
     -e '1,2 s%^\(--\|#\|//\) SPDX-License-Identifier: \(GPL-2.0\|LGPL-2.1\)+$%\1 SPDX-License-Identifier: \2-or-later%' \
     -i \
     $(git grep -l SPDX-License-Identifier -- \
         ':(exclude)shared/c-*/' \
         ':(exclude)shared/n-*/' \
         ':(exclude)shared/systemd/src' \
         ':(exclude)src/systemd/src')
2021-01-05 09:46:21 +01:00
Thomas Haller
034db883b3 Revert "dns: change default DNS priority of VPNs to -50"
Revert this change. One problem is that none of the current GUIs
(nm-connection-editor, gnome-control-center, plasma-nm) expose the
dns-priority option. So, users tend to have their profile value set to
0. Changing the default means for them not only a change in behavior,
but its hard to fix via the GUI.

Also, what other call DNS leaks, is Split DNS to some. Both uses make
sense, but have conflicting goals. The default cannot accommodate both
at the same time.

Also, with split DNS enabled (dnsmasq, systemd-resolved), the concern
for DNS leaks is smaller. Imagine:

  Wi-Fi profile with ipv4.dns-priority (effectively) 100, domain "example.com".
  VPN profile with ipv4.dns-priority (effectively) 50 and a default route.

That is a common setup that one gets by default (and what probably many
users have today). In such a case with split DNS enabled, the Wi-Fi's DNS
server only sees requests for "*.example.com". So, it does not leak
everything.

Hence, revert this change before 1.28.0 release to the earlier behavior.

This reverts commit af13081bec.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/688
(cherry picked from commit ff71bbdc42)
2020-11-23 19:00:15 +01:00
Beniamino Galvani
f10e4fe8c8 dns: change default DNS priority of VPNs to -50
Change the default DNS priority of VPNs to -50, to avoid leaking
queries out of full-tunnel VPNs.

This is a change in behavior. In particular:

 - when using dns=default (i.e. no split-dns) before this patch both
   VPN and the local name server were added (in this order) to
   resolv.conf; the result was that depending on resolv.conf options
   and resolver implementation, the name servers were tried in a
   certain manner which does not prevent DNS leaks.
   With this change, only the VPN name server is added to resolv.conf.

 - When using a split-dns plugin (systemd-resolved or dnsmasq), before
   this patch the full-tunnel VPN would get all queries except those
   ending in a local domain, that would instead be directed to the
   local server.
   After this patch, the VPN gets all queries.

To revert to the old behavior, set the DNS priority to 50 in the
connection profile.

(cherry picked from commit af13081bec)
2020-10-09 10:31:18 +02:00
Thomas Haller
88071abb43 all: unify comment style for SPDX-License-Identifier tag
Our coding style recommends C style comments (/* */) instead of C++
(//). Also, systemd (which we partly fork) uses C style comments for
the SPDX-License-Identifier.

Unify the style.

  $ sed -i '1 s#// SPDX-License-Identifier: \([^ ]\+\)$#/* SPDX-License-Identifier: \1 */#' -- $(git ls-files -- '*.[hc]' '*.[hc]pp')
2020-09-29 16:50:53 +02:00
Thomas Haller
8841d529e1 format: manually replace remaining tabs with spaces and reformat 2020-09-29 09:12:27 +02:00
Thomas Haller
740b092fda format: replace tabs for indentation in code comments
sed -i \
     -e 's/^'$'\t'' \*/     */g' \
     -e 's/^'$'\t\t'' \*/         */g' \
     -e 's/^'$'\t\t\t'' \*/             */g' \
     -e 's/^'$'\t\t\t\t'' \*/                 */g' \
     -e 's/^'$'\t\t\t\t\t'' \*/                     */g' \
     -e 's/^'$'\t\t\t\t\t\t'' \*/                         */g' \
     -e 's/^'$'\t\t\t\t\t\t\t'' \*/                             */g' \
     $(git ls-files -- '*.[hc]')
2020-09-28 16:07:52 +02:00
Antonio Cardace
328fb90f3e all: reformat all with new clang-format style
Run:

    ./contrib/scripts/nm-code-format.sh -i
    ./contrib/scripts/nm-code-format.sh -i

Yes, it needs to run twice because the first run doesn't yet produce the
final result.

Signed-off-by: Antonio Cardace <acardace@redhat.com>
2020-09-28 16:07:51 +02:00
Thomas Haller
dc3a477884 all/style: remove duplicate semicolon (";;") in sources 2020-09-23 12:43:47 +02:00
Thomas Haller
e8e5c12480 libnm: hide nm_setting_ip_config_next_valid_dns_option() function from headers
nm_setting_ip_config_next_valid_dns_option() API was added in libnm 1.2, but
it was never exported in the ABI of libnm. It thus was unusable, and any user
trying to link against it would have been unable to do so.

Hide the API now entirely. It doesn't seem a very nice API. If we want to
allow the user to validate option names, we should expose such a function
to validate an option (not to fetch the next valid option from a
profile).

Fixes: 019943bb5d ('libnm-core: add dns-options property to NMSettingIPConfig')
2020-09-22 18:04:11 +02:00
Thomas Haller
d65fdda8df libnm/doc: improve description for ipv[46].dns-priority and ipv[46].dns-search regarding DNS leaks 2020-09-14 13:09:54 +02:00
Beniamino Galvani
757fa4711f all: add ipv4.dhcp-reject-servers property
Add a new dhcp-reject-servers property to the ipv4 setting, that
allows specifying a list of server-ids from which offers should be
rejected.
2020-08-26 17:28:45 +02:00
Yuri Chornoivan
4e33f8cd89 all: fix minor typos
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/565
2020-07-07 11:33:46 +02:00
Sayed Shah
7337ab8959 all: fix typo in man pages
There should be a comma after 'Otherwise' and 'Currently'.

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

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/560
2020-07-03 10:48:04 +02:00
Thomas Haller
936e457cc0 libnm: use NMStrBuf in nm_ip_routing_rule_to_string() 2020-06-26 09:29:54 +02:00
Thomas Haller
bb6c2d7371 libnm: ensure stable behavior in _nm_ip_route_attribute_validate_all()
Check the attributes in a defined, stable order. This is necessary,
so that consistently the same error gets reported.
2020-06-19 17:14:10 +02:00
Antonio Cardace
7781f78435 setting-ip-config: validate route attributes in verify()
It's better to verify these route attributes so that the user can be
notified early if something is not supported or invalid.

The downside is that some incorrect profiles (with invalid route attributes)
that previously would work since this commit will not anymore as
the incorrect bits don't get ignored but rejected instead.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/407
https://bugzilla.redhat.com/show_bug.cgi?id=1821787
2020-06-16 10:01:26 +02:00
Antonio Cardace
5d0d13f570 platform: add support for local routes
Also update unit tests.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/407
https://bugzilla.redhat.com/show_bug.cgi?id=1821787
2020-06-16 10:01:22 +02:00
Thomas Haller
0f22f77b1c shared: support stripping whitespace from nm_utils_buf_utf8safe_unescape()
When parsing user input if is often convenient to allow stripping whitespace.
Especially with escaped strings, the user could still escape the whitespace,
if the space should be taken literally.

Add support for that to nm_utils_buf_utf8safe_unescape().

Note that this is not the same as calling g_strstrip() before/after
unescape. That is, because nm_utils_buf_utf8safe_unescape() correctly
preserves escaped whitespace. If you call g_strstrip() before/after
the unescape, you don't know whether the whitespace is escaped.
2020-05-13 10:28:04 +02:00
Thomas Haller
a352a40a08 libnm/doc: clarify use of "ipv[46].gateway in nm-settings manual
(cherry picked from commit fc837cbb6f)
2020-04-26 13:30:13 +02:00
Thomas Haller
fae37528d9 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
(cherry picked from commit 411255d51f)
2020-04-22 21:06:24 +02:00
Thomas Haller
d78dadc9eb dns: add trust-ad DNS option only if all contributing settings agree
https://bugzilla.redhat.com/show_bug.cgi?id=1825285
(cherry picked from commit 5e47fb630b)
2020-04-20 15:55:51 +02:00
Thomas Haller
ccb043d78c libnm: document supported "ipv[46].dns-option" values
(cherry picked from commit e261e941fd)
2020-04-20 15:55:50 +02:00
Beniamino Galvani
5b83609b01 libnm-core: add 'no-reload' and 'trust-ad' resolv.conf options
https://sourceware.org/git/?p=glibc.git;a=blob;f=resolv/res_init.c;h=95dce098aa7ec80f2e36f5c25022641d65e1d5e5;hb=9ea3686266dca3f004ba874745a4087a89682617#l681

https://bugzilla.redhat.com/show_bug.cgi?id=1825285
(cherry picked from commit 40b2cf7a0c)
2020-04-20 11:32:56 +02:00
Antonio Cardace
6e9a36ab9f all: use nm_utils_ifname_valid_kernel() instead of nm_utils_is_valid_iface_name()
nm_utils_is_valid_iface_name() is a public API of libnm-core, let's use
our internal API.

$ sed -i 's/\<nm_utils_is_valid_iface_name\>/nm_utils_ifname_valid_kernel/g' $(git grep -l nm_utils_is_valid_iface_name)
2020-02-17 15:27:35 +01:00
Thomas Haller
e34db042af libnm/doc: explain values for dhcp-timeout setting 2020-02-17 14:43:12 +01:00
Thomas Haller
8e636186c0 core: for WireGuard devices use a default dns-priority of 50 (like for VPNs) 2020-02-12 11:55:30 +01:00
Beniamino Galvani
bf4b53d453 libnm-core: fix documentation of dns-priority property
Clarify that VPNs are considered first in case of same priority, and
also that it's the *best* default route that matters.
2020-02-12 11:06:40 +01:00
Thomas Haller
8f3b43f009 all: use nm_utils_ipaddr_is_valid() instead of nm_utils_ipaddr_valid()
We should use the same "is-valid" function everywhere.

Since nm_utils_ipaddr_valid() is part of libnm, it does not qualify.

Use nm_utils_ipaddr_is_valid() instead.
2020-01-28 11:17:41 +01:00
Thomas Haller
e49e509262 libnm: use nm_utils_addr_family_to_size() in "nm-setting-ip-config.c" 2020-01-28 11:17:41 +01:00
Thomas Haller
1cab6367b2 libnm: don't have G_PARAM_CONSTRUCT properties in NMSetting instances
G_PARAM_CONSTRUCT cause to explicitly initialize the property during
object construction. This is an unnecessary overhead that we can easily
avoid.

The overhead is because G_PARAM_CONSTRUCT parameters are always set with
g_object_set() before calling constructed(). Even if they are not specified
during g_object_new(), in which case it calls set with the property's default
value. This also requires g_object_new() to iterate all properties to
find and sort the construct properties.

NMSetting are supposed to be simple classes. They don't need to have
their properties initialized before object construction completes.
Especially if the default values are NULL or zero, in which case there
is nothing to do. If the default value is not NULL or zero, we need
to initialize the field instead in the nm_setting*_init() function.
2019-12-24 07:47:50 +01:00
Thomas Haller
0de6cd2d68 libnm: sort fields in NMSetting structures by size and alignment 2019-12-24 07:45:24 +01:00
Thomas Haller
61381b8ee4 libnm: add nm_ip_address_cmp_full() function
Not being able to compare two NMIPAddress instances is a major
limitation. Add nm_ip_address_cmp_full(). The choice here for adding
a "cmp()" function instead of a "equals()" function is that cmp is
more useful. We only want to add one of the two, so choose the
more powerful one. Yes, usually its also not the variant we want
or the variant that is convenient to use, such is life.

Compare this to:

  - nm_ip_route_equal_full(), which is an equal() method and not
    a cmp().

  - nm_ip_route_equal_full() which has a guint flags argument,
    instead of a typedef for an enum, with a proper generated
    GType.
2019-11-28 19:20:33 +01:00
Beniamino Galvani
1bde86396b libnm: add ipvx.dhcp-hostname-flags properties
When using the dhclient DHCP backend users can tweak the behavior in
the dhclient configuration file. One of the options that was reported
as useful in the past was the FQDN flags [1] [2].

Add native support for FQDN flags to NM by introducing new
ipv{4,6}.dhcp-hostname-flags properties.

[1] https://bugzilla.redhat.com/show_bug.cgi?id=1684595
[2] https://bugzilla.redhat.com/show_bug.cgi?id=1255507
2019-11-28 17:56:35 +01:00
Thomas Haller
b9f1beb06e all: add support for "scope" attribute for IPv4 routes
- systemd-networkd and initscripts both support it.

- it seems suggested to configure routes with scope "link" on AWS.

- the scope is only supported for IPv4 routes. Kernel ignores the
  attribute for IPv6 routes.

- we don't support the aliases like "link" or "global". Instead
  only the numeric value is supported. This is different from
  systemd-networkd, which accepts names like "global" and "link",
  but no numerical values. I think restricting ourself only to
  the aliases unnecessarily limits what is possible on netlink.
  The alternative would be to allow aliases and numbers both,
  but that causes multiple ways to define something and has
  thus downsides. So, only numeric values.

- when setting rtm_scope to RT_SCOPE_NOWHERE (0, the default), kernel
  will coerce that to RT_SCOPE_LINK. This ambiguity of nowhere vs. link
  is a problem, but we don't do anything about it.

- The other problem is, that when deleting a route with scope RT_SCOPE_NOWHERE,
  this acts as a wild care and removes the first route that matches (given the
  other route attributes). That means, NetworkManager has no meaningful
  way to delete a route with scope zero, there is always the danger that
  we might delete the wrong route. But this is nothing new to this
  patch. The problem existed already previously, except that
  NetworkManager could only add routes with scope nowhere (i.e. link).
2019-11-28 00:11:15 +01:00
Thomas Haller
7cadc5e465 libnm: lookup route attributes attribute spec via binary search 2019-11-27 16:06:00 +01:00
Beniamino Galvani
37a10e9ba4 all: support 'stable' DHCP IAID
Support a new DHCP IAID special value 'stable' that generates the IAID
based on the stable-id, a per-host key and the interface name.
2019-11-11 10:33:31 +01:00
Beniamino Galvani
56a1a5426a all: add ipvX.dhcp-iaid properties
Add new ipv4.dhcp-iaid and ipv6.dhcp-iaid properties to specify a DHCP
IAID.
2019-11-11 10:31:33 +01:00
Thomas Haller
3b69f02164 all: unify format of our Copyright source code comments
```bash

readarray -d '' FILES < <(
  git ls-files -z \
    ':(exclude)po' \
    ':(exclude)shared/c-rbtree' \
    ':(exclude)shared/c-list' \
    ':(exclude)shared/c-siphash' \
    ':(exclude)shared/c-stdaux' \
    ':(exclude)shared/n-acd' \
    ':(exclude)shared/n-dhcp4' \
    ':(exclude)src/systemd/src' \
    ':(exclude)shared/systemd/src' \
    ':(exclude)m4' \
    ':(exclude)COPYING*'
  )

sed \
  -e 's/^\(--\|#\| \*\) *\(([cC]) *\)\?Copyright \+\(\(([cC])\) \+\)\?\(\(20\|19\)[0-9][0-9]\) *[-–] *\(\(20\|19\)[0-9][0-9]\) \+\([^ ].*\)$/\1 C1pyright#\5 - \7#\9/' \
  -e 's/^\(--\|#\| \*\) *\(([cC]) *\)\?Copyright \+\(\(([cC])\) \+\)\?\(\(20\|19\)[0-9][0-9]\) *[,] *\(\(20\|19\)[0-9][0-9]\) \+\([^ ].*\)$/\1 C2pyright#\5, \7#\9/' \
  -e 's/^\(--\|#\| \*\) *\(([cC]) *\)\?Copyright \+\(\(([cC])\) \+\)\?\(\(20\|19\)[0-9][0-9]\) \+\([^ ].*\)$/\1 C3pyright#\5#\7/' \
  -e 's/^Copyright \(\(20\|19\)[0-9][0-9]\) \+\([^ ].*\)$/C4pyright#\1#\3/' \
  -i \
  "${FILES[@]}"

echo ">>> untouched Copyright lines"
git grep Copyright "${FILES[@]}"

echo ">>> Copyright lines with unusual extra"
git grep '\<C[0-9]pyright#' "${FILES[@]}" | grep -i reserved

sed \
  -e 's/\<C[0-9]pyright#\([^#]*\)#\(.*\)$/Copyright (C) \1 \2/' \
  -i \
  "${FILES[@]}"

```

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/298
2019-10-02 17:03:52 +02:00
Thomas Haller
a1b575b07b libnm/trivial: rename _properties_override_add_*() to _nm_properties_override_*()
These macros/functions are in a header file. Everything in a header file
should have an "nm" prefix. Rename.
2019-09-30 08:23:19 +02:00
Thomas Haller
275d850d1b libnm: replace _properties_override_add_override() with _properties_override_add_gobj() 2019-09-30 08:23:19 +02:00
Thomas Haller
0129954203 libnm: replace _properties_override_add_dbus_only() with _properties_override_add_virt()
We have too many _properties_override_add*() variants. They basically are all the
same. Drop _properties_override_add_dbus_only() and use _properties_override_add_virt()
instead.

Also, I am always confused by the term "synth". We shouldn't treat
non-GObject-based properties as somehow odd that need to be synthesized.
2019-09-30 08:23:19 +02:00
Thomas Haller
3f36f69156 libnm: refactor NMSettInfoProperty to save memory for simple properties
In total, we register 447 property informations. Out of these,
326 are plain, GObject property based without special implementations.

The NMSettInfoProperty had all function pointers directly embedded,
currently this amounts to 5 function pointers and the "dbus_type" field.

That means, at runtime we have 326 times trivial implementations with
waste 326*6*8 bytes of NULL pointers. We can compact these by moving
them to a separate structure.

Before:

    447 * 5 function pointers
    447 * "dbus_type" pointer
    = 2682 pointers

After:

    447 * 1 pointers (for NMSettInfoProperty.property_type)
     89 * 6 pointers (for the distinct NMSettInfoPropertType data)
    = 981 pointers

So, in total this saves 13608 byes of runtime memory (on 64 bit arch).

The 89 NMSettInfoPropertType instances are the remaining distinct instances.
Note that every NMSettInfoProperty has a "property_type" pointer, but most of them are
shared. That is because the underlying type and the operations are the same.

Also nice is that the NMSettInfoPropertType are actually constant,
static fields and initialized very early.

This change also makes sense form a design point of view. Previously,
NMSettInfoProperty contained both per-property data (the "name") but
also the behavior. Now, the "behavioral" part is moved to a separate
structure (where it is also shared). That means, the parts that are
concerned with the type of the property (the behavior) are separate
from the actual data of the property.
2019-09-30 08:23:19 +02:00
Lubomir Rintel
24028a2246 all: SPDX header conversion
$ find * -type f |xargs perl contrib/scripts/spdx.pl
  $ git rm contrib/scripts/spdx.pl
2019-09-10 11:19:56 +02:00
Thomas Haller
c167e0140b all: allow configuring default-routes as manual, static routes
Up until now, a default-route (with prefix length zero) could not
be configured directly. The user could only set ipv4.gateway,
ipv4.never-default, ipv4.route-metric and ipv4.route-table to influence
the setting of the default-route (respectively for IPv6).

That is a problematic limitation. For one, whether a route has prefix
length zero or non-zero does not make a fundamental difference. Also,
it makes it impossible to configure all the routing attributes that one can
configure otherwise for static routes. For example, the default-route could
not be configured as "onlink", could not have a special MTU, nor could it be
placed in a dedicated routing table.

Fix that by lifting the restriction. Note that "ipv4.never-default" does
not apply to /0 manual routes. Likewise, the previous manners of
configuring default-routes ("ipv4.gateway") don't conflict with manual
default-routes.

Server-side this all the pieces are already in place to accept a default-route
as static routes. This was done by earlier commits like 5c299454b4
('core: rework tracking of gateway/default-route in ip-config').

A long time ago, NMIPRoute would assert that the prefix length is
positive. That was relaxed by commit a2e93f2de4 ('libnm: allow zero
prefix length for NMIPRoute'), already before 1.0.0. Using libnm from
before 1.0.0 would result in assertion failures.

Note that the default-route-metric-penalty based on connectivity
checking applies to all /0 routes, even these static routes. Be they
added due to DHCP, "ipv4.gateway", "ipv4.routes" or "wireguard.peer-routes".
I wonder whether doing that unconditionally is desirable, and maybe
there should be a way to opt-out/opt-in for the entire profile or even
per-routes.

https://bugzilla.redhat.com/show_bug.cgi?id=1714438
2019-08-13 10:45:04 +02:00
Thomas Haller
539db43619 libnm: avoid heap allocation for checking valid routes in nm_ip_route_attribute_validate() 2019-08-13 10:45:04 +02:00
Thomas Haller
66088a09b2 libnm: when stringifying policy routing rule place "not" specifier after "priority"
Otherwise, it just looks odd:

  "not priority 31265 from 0.0.0.0/0 fwmark 0xcb87 table 52103"

Better is:

  "priority 31265 not from 0.0.0.0/0 fwmark 0xcb87 table 52103"

The "not" specifier should come after the priority. It makes more sense
to read it that way. As far as parsing the string is concerned, the
order does not matter. So this change in behavior is no problem.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/228
2019-08-05 10:16:10 +02:00
Lubomir Rintel
3c6644db32 all: codespell fixes
Codespel run with the same arguments as described in
commit 58510ed566 ('docs: misc. typos pt2').
2019-07-24 11:30:19 +02:00
Thomas Haller
6ea56bc04c libnm,core: add support for "suppress_prefixlength" rule attribute
WireGuard's wq-quick configures such rules to avoid routing loops.
While we currently don't have an automatic solution for this, at least
we should support it via explicit user configuration.

One problem is that suppress_prefixlength is relatively new and kernel
might not support this attribute. That can lead to odd results, because
the NetworkManager is valid but it cannot be configured on the current
kernel. But this is a general problem, and we would require a general
solution. The solution cannot be to only support rule attributes that
are supported by the oldest possible kernel. It's not clear how much of
a problem there really is, or which general solution is required (if
any).
2019-07-16 10:03:17 +02:00