Commit Graph

21088 Commits

Author SHA1 Message Date
Thomas Haller
610ca87016 wifi: don't use :1 bitfield for gboolean type
gboolean is a typedef for "int".

While older compilers might treat such bitfields as unsigned ([1]),
commonly such a bitfield is signed and can only contain the values 0
and -1.

We only want to use numeric 1 for TRUE, hence, creating such bitfields
is wrong, or at least error prone.

In fact, in this case it's a bug, because later we compare
it with a regular gboolean

  if (priv->scanning != new_scanning)

[1] https://lgtm.com/rules/1506024027114/

Fixes: e0f9677018
2018-08-26 18:30:45 +02:00
Thomas Haller
8aa8d74710 systemd: update code from upstream (2018-08-26)
This is a direct dump from systemd git.

======

SYSTEMD_DIR=../systemd
COMMIT=56663345dfb1dd3ff23cac5fbc955aba54477efa

(
  cd "$SYSTEMD_DIR"
  git checkout "$COMMIT"
  git reset --hard
  git clean -fdx
)

git ls-files :/src/systemd/src/ \
             :/shared/nm-utils/unaligned.h | \
  xargs -d '\n' rm -f

nm_copy_sd() {
    mkdir -p "./src/systemd/$(dirname "$1")"
    cp "$SYSTEMD_DIR/$1" "./src/systemd/$1"
}

nm_copy_sd_shared() {
    mkdir -p "./shared/nm-utils/"
    cp "$SYSTEMD_DIR/$1" "./shared/nm-utils/${1##*/}"
}

nm_copy_sd "src/basic/alloc-util.c"
nm_copy_sd "src/basic/alloc-util.h"
nm_copy_sd "src/basic/async.h"
nm_copy_sd "src/basic/env-util.c"
nm_copy_sd "src/basic/env-util.h"
nm_copy_sd "src/basic/escape.c"
nm_copy_sd "src/basic/escape.h"
nm_copy_sd "src/basic/ether-addr-util.c"
nm_copy_sd "src/basic/ether-addr-util.h"
nm_copy_sd "src/basic/extract-word.c"
nm_copy_sd "src/basic/extract-word.h"
nm_copy_sd "src/basic/fileio.c"
nm_copy_sd "src/basic/fileio.h"
nm_copy_sd "src/basic/fd-util.c"
nm_copy_sd "src/basic/fd-util.h"
nm_copy_sd "src/basic/fs-util.c"
nm_copy_sd "src/basic/fs-util.h"
nm_copy_sd "src/basic/hash-funcs.c"
nm_copy_sd "src/basic/hash-funcs.h"
nm_copy_sd "src/basic/hashmap.c"
nm_copy_sd "src/basic/hashmap.h"
nm_copy_sd "src/basic/hexdecoct.c"
nm_copy_sd "src/basic/hexdecoct.h"
nm_copy_sd "src/basic/hostname-util.c"
nm_copy_sd "src/basic/hostname-util.h"
nm_copy_sd "src/basic/in-addr-util.c"
nm_copy_sd "src/basic/in-addr-util.h"
nm_copy_sd "src/basic/io-util.c"
nm_copy_sd "src/basic/io-util.h"
nm_copy_sd "src/basic/list.h"
nm_copy_sd "src/basic/log.h"
nm_copy_sd "src/basic/macro.h"
nm_copy_sd "src/basic/mempool.h"
nm_copy_sd "src/basic/mempool.c"
nm_copy_sd "src/basic/parse-util.c"
nm_copy_sd "src/basic/parse-util.h"
nm_copy_sd "src/basic/path-util.c"
nm_copy_sd "src/basic/path-util.h"
nm_copy_sd "src/basic/prioq.h"
nm_copy_sd "src/basic/prioq.c"
nm_copy_sd "src/basic/process-util.h"
nm_copy_sd "src/basic/process-util.c"
nm_copy_sd "src/basic/random-util.c"
nm_copy_sd "src/basic/random-util.h"
nm_copy_sd "src/basic/refcnt.h"
nm_copy_sd "src/basic/set.h"
nm_copy_sd "src/basic/signal-util.h"
nm_copy_sd "src/basic/siphash24.h"
nm_copy_sd "src/basic/socket-util.c"
nm_copy_sd "src/basic/socket-util.h"
nm_copy_sd "src/basic/sparse-endian.h"
nm_copy_sd "src/basic/stat-util.c"
nm_copy_sd "src/basic/stat-util.h"
nm_copy_sd "src/basic/stdio-util.h"
nm_copy_sd "src/basic/string-table.c"
nm_copy_sd "src/basic/string-table.h"
nm_copy_sd "src/basic/string-util.c"
nm_copy_sd "src/basic/string-util.h"
nm_copy_sd "src/basic/strv.c"
nm_copy_sd "src/basic/strv.h"
nm_copy_sd "src/basic/time-util.c"
nm_copy_sd "src/basic/time-util.h"
nm_copy_sd "src/basic/umask-util.h"
nm_copy_sd_shared "src/basic/unaligned.h"
nm_copy_sd "src/basic/utf8.c"
nm_copy_sd "src/basic/utf8.h"
nm_copy_sd "src/basic/util.c"
nm_copy_sd "src/basic/util.h"
nm_copy_sd "src/libsystemd-network/arp-util.c"
nm_copy_sd "src/libsystemd-network/arp-util.h"
nm_copy_sd "src/libsystemd-network/dhcp6-internal.h"
nm_copy_sd "src/libsystemd-network/dhcp6-lease-internal.h"
nm_copy_sd "src/libsystemd-network/dhcp6-network.c"
nm_copy_sd "src/libsystemd-network/dhcp6-option.c"
nm_copy_sd "src/libsystemd-network/dhcp6-protocol.h"
nm_copy_sd "src/libsystemd-network/dhcp-identifier.c"
nm_copy_sd "src/libsystemd-network/dhcp-identifier.h"
nm_copy_sd "src/libsystemd-network/dhcp-internal.h"
nm_copy_sd "src/libsystemd-network/dhcp-lease-internal.h"
nm_copy_sd "src/libsystemd-network/dhcp-network.c"
nm_copy_sd "src/libsystemd-network/dhcp-option.c"
nm_copy_sd "src/libsystemd-network/dhcp-packet.c"
nm_copy_sd "src/libsystemd-network/dhcp-protocol.h"
nm_copy_sd "src/libsystemd-network/lldp-internal.h"
nm_copy_sd "src/libsystemd-network/lldp-neighbor.c"
nm_copy_sd "src/libsystemd-network/lldp-neighbor.h"
nm_copy_sd "src/libsystemd-network/lldp-network.c"
nm_copy_sd "src/libsystemd-network/lldp-network.h"
nm_copy_sd "src/libsystemd-network/network-internal.c"
nm_copy_sd "src/libsystemd-network/network-internal.h"
nm_copy_sd "src/libsystemd-network/sd-dhcp6-client.c"
nm_copy_sd "src/libsystemd-network/sd-dhcp6-lease.c"
nm_copy_sd "src/libsystemd-network/sd-dhcp-client.c"
nm_copy_sd "src/libsystemd-network/sd-dhcp-lease.c"
nm_copy_sd "src/libsystemd-network/sd-ipv4ll.c"
nm_copy_sd "src/libsystemd-network/sd-ipv4acd.c"
nm_copy_sd "src/libsystemd-network/sd-lldp.c"
nm_copy_sd "src/libsystemd/sd-event/sd-event.c"
nm_copy_sd "src/libsystemd/sd-id128/id128-util.c"
nm_copy_sd "src/libsystemd/sd-id128/id128-util.h"
nm_copy_sd "src/libsystemd/sd-id128/sd-id128.c"
nm_copy_sd "src/shared/dns-domain.c"
nm_copy_sd "src/shared/dns-domain.h"
nm_copy_sd "src/systemd/_sd-common.h"
nm_copy_sd "src/systemd/sd-dhcp6-client.h"
nm_copy_sd "src/systemd/sd-dhcp6-lease.h"
nm_copy_sd "src/systemd/sd-dhcp-client.h"
nm_copy_sd "src/systemd/sd-dhcp-lease.h"
nm_copy_sd "src/systemd/sd-event.h"
nm_copy_sd "src/systemd/sd-ndisc.h"
nm_copy_sd "src/systemd/sd-id128.h"
nm_copy_sd "src/systemd/sd-ipv4acd.h"
nm_copy_sd "src/systemd/sd-ipv4ll.h"
nm_copy_sd "src/systemd/sd-lldp.h"
2018-08-26 15:48:17 +02:00
Lubomir Rintel
bd3472fb82 vpn-service-plugin: cancel the connect timer on has_ipv4=has_ipv6=false
NetworkManager considers a connection w/o L3 configuration fine and connected.
Don't make VPN plugins commit suicide in such case.
2018-08-23 17:15:38 +02:00
Thomas Haller
5f2c39fa29 wifi: merge branch 'th/wifi-gbytes-ssid'
https://github.com/NetworkManager/NetworkManager/pull/182
2018-08-22 11:13:10 +02:00
Thomas Haller
f1bc0f0bf2 wifi: refactor nm_wifi_ap_set_ssid() to accept GBytes
- have two variants of functions to set the SSID of an access point:
  one that passes SSID as GBytes, and one that passes it as plain
  data with length. Accepting a GBytes allows to share the immutable
  GBytes instance.

- both functions now also support clearing the SSID. In
  nm_wifi_ap_update_from_properties(), if the GVariant specifies
  a "SSID", we always update the access point. We already support
  chaging the SSID, so why not support changing it to *no* SSID
  (hidden).
2018-08-22 10:49:34 +02:00
Thomas Haller
5cd4e6f3e6 wifi: don't use GBytesArray for NMWifiAP's ssid
GBytes makes more sense, because it's immutable.

Also, since at other places we use GBytes, having
different types is combersome and requires needless
conversions.

Also:

- avoid nm_utils_escape_ssid() instead of _nm_utils_ssid_to_string().
  We use nm_utils_escape_ssid() when we want to log the SSID. However, it
  does not escape newlines, which is bad.

- also no longer use nm_utils_same_ssid(). Since it no longer
  treated trailing NUL special, it is not different from
  g_bytes_equal().

- also, don't use nm_utils_ssid_to_utf8() for logging anymore.
  For logging, _nm_utils_ssid_escape_utf8safe() is better because
  it is loss-less escaping which can be unambigously reverted.
2018-08-22 10:49:34 +02:00
Thomas Haller
331d44afa6 wifi: don't ignore trailing NUL byte when comparing SSID
nm_utils_same_ssid() has a comment

 * Earlier versions of the Linux kernel added a NULL byte to the end of the
 * SSID to enable easy printing of the SSID on the console or in a terminal,
 * but this behavior was problematic (SSIDs are simply byte arrays, not strings)
 * and thus was changed.  This function compensates for that behavior at the
 * cost of some compatibility with odd SSIDs that may legitimately have trailing
 * NULLs, even though that is functionally pointless.

and the functionality was introduced by commit
ccb13f0bdd.

There was only place left that calls nm_utils_same_ssid().
I really don't think this is the right approach, nor is it clear
that this is still necessary. Also, it seems to only matter with
WEXT, and we should not have such an ugly hack in all cases.
2018-08-22 10:49:34 +02:00
Thomas Haller
57c371e32f shared: add nm_utils_buf_utf8safe_escape() util
We already have nm_utils_str_utf8safe_escape() to convert a
NUL termianted string to an UTF-8 string. nm_utils_str_utf8safe_escape()
operates under the assumption, that the input strig is already valid UTF-8
and returns the input string verbatim. That way, in the common expected
cases, the string just looks like a regular UTF-8 string.
However, in case there are invalid UTF-8 sequences (or a backslash
escape characters), the function will use backslash escaping to encode
the input string as a valid UTF-8 sequence. Note that the escaped
sequence, can be reverted to the original non-UTF-8 string via
unescape.
An example, where this is useful are file names or interface names.
Which are not in a defined encoding, but NUL terminated and commonly ASCII or
UTF-8 encoded.

Extend this, to also handle not NUL terminated buffers. The same
applies, except that the process cannot be reverted via g_strcompress()
-- because the NUL character cannot be unescaped.

This will be useful to escape a Wi-Fi SSID. Commonly we expect the SSID
to be in UTF-8/ASCII encoding and we want to print it verbatim. Only
if that is not the case, we fallback to backslash escaping. However, the
orginal value can be fully recovered via unescape(). The difference
between an SSID and a filename is, that the former can contain '\0'
bytes.
2018-08-22 10:49:34 +02:00
Thomas Haller
ced0dd2e4a wifi: use GBytes for ssids scan list
Use GBytes instead of GBytesArray. GBytes is immutable and
can be shared.

It is also the type that we natively get from
nm_setting_wireless_get_ssid(). This way we avoid some
conversions.
2018-08-22 10:49:34 +02:00
Thomas Haller
f5792881a0 device: avoid intermediary GByteArray when creating DUID GBytes
Creating it directly is simple enough.
2018-08-22 10:49:34 +02:00
Thomas Haller
5b5b651bcf dhcp/trivial: add fixme comments to nm_dhcp_dhclient_unescape_duid() 2018-08-22 10:49:34 +02:00
Thomas Haller
dba19ebd7d all: avoid useless cast of g_free() to GDestroyNotify 2018-08-22 10:49:34 +02:00
Thomas Haller
dc316c8afe wifi: use GBytes instead of GBytesArray for tracking blobs in supplicant 2018-08-22 10:49:34 +02:00
Thomas Haller
4607970288 wifi/olpc: fix setting SSID for OLPC mesh in complete_connection()
NM_SETTING_OLPC_MESH_SSID is of type GBytes, not GByteArray.
2018-08-22 10:49:34 +02:00
Thomas Haller
39efc65096 platform: drop unused virtual function NMPlatformClass.wifi_get_ssid() 2018-08-22 10:49:34 +02:00
Thomas Haller
e730f7429d libnm: replace _nm_utils_bytes_to_dbus() with nm_utils_gbytes_get_variant_ay() 2018-08-22 10:49:34 +02:00
Thomas Haller
c06a55958b shared: add nm_utils_gbytes_to_variant_ay() util 2018-08-22 10:49:30 +02:00
Christian K
cd79a22d18 po: update German translation
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/9
2018-08-21 17:59:02 +02:00
Lubomir Rintel
de615e3136 po: fix a typo in fr translation
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/5
2018-08-20 19:18:14 +02:00
Lubomir Rintel
20d905e590 platform: if AF_INET6 is not available, don't warn
These should be logged on DEBUG level:

  <warn>  platform-linux: do-change-link[2]: failure changing link: failure 97 (Address family not supported by protocol)
  <warn>  device (wlo1): failed to enable userspace IPv6LL address handling (unspecified)

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/10
2018-08-20 19:16:38 +02:00
Lubomir Rintel
0004404cb1 ip4-config: fix a typo
(cherry picked from commit 0550003ef0b71cd4342519c06d8bc3c92b4f64ea)
2018-08-19 13:56:14 +02:00
Lubomir Rintel
2d3d1bbc96 po/ja: translations from the Red Hat translators
(cherry picked from commit 7af38dc4fc802e4f897aeeb1532ca9099a2c5333)
2018-08-19 13:56:12 +02:00
Beniamino Galvani
e96851673b build: fix meson build with -Dppp=false
meson.build:897:15: ERROR: Unknown variable "pppd_plugin_dir".

Fixes: a75ab799e4

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/7
2018-08-15 11:35:44 +02:00
Rafael Fontenelle
02c11bb349 po: update Brazilian Portuguese translation
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/3
2018-08-15 11:30:22 +02:00
Lubomir Rintel
304e211640 device: cope with devices' failure to provide reason for incompatibility
Pretty sure we get this right now, but if we don't let's fail more
sensibly.
2018-08-14 18:23:23 +02:00
Lubomir Rintel
587de11903 wifi: provide reasons for connection incompatibility
The callers assume that we set an error on returning FALSE.

Mostly copied from the IWD implementation.
2018-08-14 18:23:22 +02:00
Lubomir Rintel
eaa83eedc5 iwd: improve error messages
Fix errors, typoes and ambiguities.
2018-08-14 18:23:21 +02:00
Thomas Haller
72db613ca7 release: bump version to 1.13.3 (development) 2018-08-13 10:00:45 +02:00
Thomas Haller
61976d2c20 release: update NEWS 2018-08-13 09:59:33 +02:00
Lubomir Rintel
3e8eef5389 utils/test: don't assert on debug level messages
They come and go in GLib core for all sorts of purposes. Don't let that
break our tests.
2018-08-11 11:45:03 +02:00
Beniamino Galvani
0103bb33a6 merge: branch 'bg/wildcard-match-rh1555012'
https://bugzilla.redhat.com/show_bug.cgi?id=1555012
https://github.com/NetworkManager/NetworkManager/pull/181
2018-08-11 09:59:13 +02:00
Beniamino Galvani
81978e36ba device: support match.interface-name
Add support for matching a connection with the new
match.interface-name property.
2018-08-11 09:41:07 +02:00
Beniamino Galvani
d47e0beb7d ifcfg-rh: add support for 'match' setting 2018-08-11 09:41:07 +02:00
Beniamino Galvani
9b9dce9486 all: add 'match' setting
Add a new 'match' setting containing properties to match a connection
to devices. At the moment only the interface-name property is present
and, contrary to connection.interface-name, it allows the use of
wildcards.
2018-08-11 09:41:07 +02:00
Beniamino Galvani
6a51d393b2 shared: add @allow_escaping argument to @nm_utils_strsplit_set 2018-08-11 09:41:07 +02:00
Beniamino Galvani
593f6efeae libnm-core: remove wrong annotation in NMSettingIPConfig 2018-08-11 09:41:07 +02:00
Beniamino Galvani
e0bbaf6a39 shared: add space escape functions 2018-08-11 09:41:07 +02:00
Thomas Haller
da3b72d842 all/ethtool: merge branch 'th/ethtool-options-rh1335409-1'
Add support for setting offload features (akin to ethtool's
-K|--offload|--feature).

https://bugzilla.redhat.com/show_bug.cgi?id=1335409
https://github.com/NetworkManager/NetworkManager/pull/179
2018-08-10 10:39:00 +02:00
Thomas Haller
da109a291c all/ethtool: add support for all currently supported kernel features
As of upstream kernel v4.18-rc8.

Note that we name the features like they are called in ethtool's
ioctl API ETH_SS_FEATURES.

Except, for features like "tx-gro", which ethtool utility aliases
as "gro". So, for those features where ethtool has a built-in,
alternative name, we prefer the alias.

And again, note that a few aliases of ethtool utility ("sg", "tso", "tx")
actually affect more than one underlying kernel feature.

Note that 3 kernel features which are announced via ETH_SS_FEATURES are
explicitly exluded because kernel marks them as "never_changed":

    #define NETIF_F_NEVER_CHANGE (NETIF_F_VLAN_CHALLENGED | \
                                  NETIF_F_LLTX | NETIF_F_NETNS_LOCAL)
2018-08-10 10:38:19 +02:00
Thomas Haller
9e7c960fad cli: hide ethtool options form nmcli connection show "$PROFILE" output
We will add a large number of offload features. That means, the output
of `nmcli connection show "$PROFILE"` would be very verbose, in case
the profile has a [ethtool] option.

Since this is newly added API, don't do that. Don't show ethtool properties
that are left unset.

A minor problem here is, that it becomes no longer obvious which
properties exist. We should however counter that by documentation.
Also, one could do:

  $ nmcli connection modify "$PROFILE" ethtool.xxx x
  Error: invalid property 'xxx': 'xxx' not among [feature-gro, feature-gso, feature-lro, feature-ntuple, feature-rx, feature-rxhash, feature-rxvlan, feature-sg, feature-tso, feature-tx, feature-txvlan, feature-tx-tcp6-segmentation, feature-tx-tcp-segmentation].

Likewise, bash completion still works as one would expect.

  $ nmcli --complete-args connection modify "$PROFILE" ethtool.
  ethtool.feature-gro
  ethtool.feature-gso
  ethtool.feature-lro
  [...]

Note the output of

  $ nmcli -f ethtool.feature-gro connection show "$PROFILE"

gives now nothing (if there is an ethtool section, but not this
particular feature). Maybe this shouldn't be like that. On the other
hand, specifying a connection setting that doesn't exist also gives
no output:

  $ nmcli -f bond connection show "$PROFILE"

So, maybe this behavior is fine.
2018-08-10 10:38:19 +02:00
Thomas Haller
582ee91145 cli: add functionality to hide properties from output
Historically, nmcli printed all fields during operations like
`nmcli connection show "$PROFILE"`. As we supported more and
more options, this resulted in a verbose output, of most properties
just being the default values.

To counter that, we added the '-overview' option. When given,
it would hide options that are set at their default. This option
was not the default, to preserve established behavior.

However, for new options, we can afford to hide them. Add a mechanism,
that property getters can mark their value to be hidden. At the moment,
there is no way to show these properties. However, we could add a
'-verbose' option, with the opposite meaning of '-overview'. Anyway,
that does not seem necessary at the moment.

Hiding properties from output is only acceptable for new properties
(otherwise we badly change behavior), and if the properties are set
at their default values (otherwise, we hide important information).
2018-08-10 10:38:19 +02:00
Thomas Haller
8c752076aa device: implement setting ethtool offload features 2018-08-10 10:38:19 +02:00
Thomas Haller
c085b6e3a7 platform/ethtool: add code to get/set offload features via ethtool
Also, add two more features "tx-tcp-segmentation" and
"tx-tcp6-segmentation". There are two reasons for that:

 - systemd-networkd supports setting these two features,
   so lets support them too (apparently they are important
   enough for networkd).

 - these two features are already implicitly covered by "tso".
   Like for the "ethtool" program, "tso" is an alias for several
   actual features. By adding two features that are already
   also covered by an alias (which sets multiple kernel names
   at once), we showcase how aliases for the same feature can
   coexist. In particular, note how setting
   "tso on tx-tcp6-segmentation off" will behave as one would
   expect: all 4 tso features covered by the alias are enabled,
   except that particular one.
2018-08-10 10:38:19 +02:00
Thomas Haller
14f963cde3 platform/mii: use SocketHandle also for nmp_utils_mii_supports_carrier_detect()
There is little difference in practice because there is only one caller.
Still re-use the SocketHandle also for mii. If only, to make it clear
that SocketHandle is not only suitable for ethtool, but also mii.
2018-08-10 10:38:19 +02:00
Thomas Haller
bdd9f7482c platform/ethtool: add SocketHandle to reuse socket for ethtool requests
Previously, each call to ethtool_get() would resolve the ifindex and
create a new socket for the ethtool request.

This is partly done, because ethtool only supports making requests by
name. Since interfaces can be renamed, this is inherrently racy. So,
we want to fetch the latest name shortly before making the request.

Some functions like nmp_utils_ethtool_supports_vlans() require multiple
ioctls. And next, we will introduce more ethtool functions, that make an
even larger number of individual requests.

Add a simple SocketHandle struct, to create the socket once and reuse
it for multiple requests. This is still entirely internal API in
"nm-platform-utils.c".
2018-08-10 10:38:19 +02:00
Thomas Haller
29266e0086 platform/ethtool: split functions for ETHTOOL_GSTRINGS
ethtool_get_stringset() will be used later, independently.

Also, don't trust and ensure that the block of strings
returned by ETHTOOL_GSTRINGS are NUL terminated.
2018-08-10 10:38:19 +02:00
Thomas Haller
b7c8e3dbfa shared: add NM_DIV_ROUND_UP() helper macro
Inspired by ethtool's DIV_ROUND_UP() and systemd's DIV_ROUND_UP().
2018-08-10 10:38:19 +02:00
Thomas Haller
df30651b89 libnm, cli, ifcfg-rh: add NMSettingEthtool setting
Note that in NetworkManager API (D-Bus, libnm, and nmcli),
the features are called "feature-xyz". The "feature-" prefix
is used, because NMSettingEthtool possibly will gain support
for options that are not only -K|--offload|--features, for
example -C|--coalesce.

The "xzy" suffix is either how ethtool utility calls the feature
("tso", "rx"). Or, if ethtool utility specifies no alias for that
feature, it's the name from kernel's ETH_SS_FEATURES ("tx-tcp6-segmentation").
If possible, we prefer ethtool utility's naming.

Also note, how the features "feature-sg", "feature-tso", and
"feature-tx" actually refer to multiple underlying kernel features
at once. This too follows what ethtool utility does.

The functionality is not yet implemented server-side.
2018-08-10 10:38:19 +02:00
Thomas Haller
4e0f1b16b9 libnm: add generic-data for implementing NMSetting
Add a new way how NMSetting subclasses can be implemented.

Currently, most NMSetting implementations realize all their properties
via GObject properties. That has some downsides:

 - the biggest one, is the large effort to add new properties.
   Most of them are implemented on a one-by-one basis and they come
   with additional API (like native getter functions).
   It makes it cumbersome to add more properties.

 - for certain properties, it's hard to encode them entirely in
   a GObject property. That results in unusable API like
   NM_SETTING_IP_CONFIG_ADDRESSES, NM_SETTING_BOND_OPTIONS,
   NM_SETTING_USER_DATA. These complex valued properties only
   exist, because we currently always need GObject properties
   to even implement simple functionality. For example,
   nm_setting_duplicate() is entirely implemented via
   nm_setting_enumerate_values(), which can only iterate
   GObject properies. There is no reason why this is necessary.
   Note also how nmcli badly handles bond options and VPN
   data. That is only a shortcoming of nmcli and wouldn't
   need to be that way. But it happend, because we didn't
   keep an open mind that settings might be more than just
   accessing GObject properties.

 - a major point of NMSetting is to convert to/from a GVariant
   from the D-Bus API. As NMSetting needs to squeeze all values
   into the static GObject structure, there is no place to
   encode invalid or unknown properties. Optimally,
   _nm_setting_new_from_dbus() does not loose any information
   and a subsequent _nm_setting_to_dbus() can restore the original
   variant. That is interesting, because we want that an older
   libnm client can talk to a newer NetworkManager version. The
   client needs to handle unknown properties gracefully to stay
   forward compatible. However, it also should not just drop the
   properties on the floor.
   Note however, optimally we want that nm_setting_verify() still
   can reject settings that have such unknown/invalid values. So,
   it should be possible to create an NMSetting instance without
   error or loosing information. But verify() should be usable to
   identify such settings as invalid.

They also have a few upsides.

 - libnm is heavily oriented around GObject. So, we generate
   our nm-settings manual based on the gtk-doc. Note however,
   how we fail to generate a useful manual for bond.options.
   Also note, that there is no reason we couldn't generate
   great documentation, even if the properties are not GObject
   properties.

 - GObject properties do give some functionality like meta-data,
   data binding and notification. However, the meta-data is not
   sufficient on its own. Note how keyfile and nmcli need extensive
   descriptor tables on top of GObject properties, to make this
   useful. Note how GObject notifications for NMSetting instances
   are usually not useful, aside for data binding like nmtui does.

Also note how NMSettingBond already follows a different paradigm
than using GObject properties. Nowdays, NMSettingBond is considered
a mistake (related bug rh#1032808). Many ideas of NMSettingBond
are flawed, like exposing an inferiour API that reduces everything
to a string hash. Also, it only implemented the options hash inside
NMSettingBond. That means, if we would consider this a good style,
we would have to duplicate this approach in each new setting
implementation.

Add a new style to track data for NMSetting subclasses. It keeps
an internal hash table with all GVariant properies. Also, the
functionality is hooked into NMSetting base class, so all future
subclasses that follow this way, can benefit from this. This approach
has a few similiarties with NMSettingBond, but avoids its flaws.

With this, we also no longer need GObject properties (if we would
also implement generating useful documentation based on non-gkt-doc).
They may be added as accessors if they are useful, but there is no
need for them.

Also, handling the properties as a hash of variants invites for a
more generic approach when handling them. While we still could add
accessors that operate on a one-by-one bases, this leads to a more
generic usage where we apply common functionality to a set of properties.

Also, this is for the moment entirely internal and an implementation
detail. It's entirely up to the NMSetting subclass to make use of this
new style. Also, there are little hooks for the subclass available.
If they turn out to be necessary, they might be added. However, for
the moment, the functionality is restricted to what is useful and
necessary.
2018-08-10 10:38:19 +02:00
Thomas Haller
3793804314 libnm: rework setting metadata for property handling
NMSetting internally already tracked a list of all proper GObject properties
and D-Bus-only properties.

Rework the tracking of the list, so that:

- instead of attaching the data to the GType of the setting via
  g_type_set_qdata(), it is tracked in a static array indexed by
  NMMetaSettingType. This allows to find the setting-data by simple
  pointer arithmetic, instead of taking a look and iterating (like
  g_type_set_qdata() does).

  Note, that this is still thread safe, because the static table entry is
  initialized in the class-init function with _nm_setting_class_commit().
  And it only accessed by following a NMSettingClass instance, thus
  the class constructor already ran (maybe not for all setting classes,
  but for the particular one that we look up).

  I think this makes initialization of the metadata simpler to
  understand.
  Previously, in a first phase each class would attach the metadata
  to the GType as setting_property_overrides_quark(). Then during
  nm_setting_class_ensure_properties() it would merge them and
  set as setting_properties_quark(). Now, during the first phase,
  we only incrementally build a properties_override GArray, which
  we finally hand over during nm_setting_class_commit().

- sort the property infos by name and do binary search.

Also expose this meta data types as internal API in nm-setting-private.h.
While not accessed yet, it can prove beneficial, to have direct (internal)
access to these structures.

Also, rename NMSettingProperty to NMSettInfoProperty to use a distinct
naming scheme. We already have 40+ subclasses of NMSetting that are called
NMSetting*. Likewise, NMMetaSetting* is heavily used already. So, choose a
new, distinct name.
2018-08-10 10:38:19 +02:00