Commit graph

21377 commits

Author SHA1 Message Date
Thomas Haller
dfd376963e device: merge branch 'th/device-set-mac-addr-no-down'
https://bugzilla.redhat.com/show_bug.cgi?id=1639274

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/54

(cherry picked from commit a8f0da9f91)
2018-11-29 14:12:52 +01:00
Thomas Haller
ca4e28ea2b device: avoid taking down link to change MAC address
A lot of drivers actually support changing the MAC address of a link
without taking it down.

Taking down a link is very bad, because kernel will remove routes
and IPv6 addresses.

For example, if the user used a dispatcher script to add routes,
these will be lost. Note that we may change the MAC address of a
device any time. For example, a VLAN device watches the parent's
MAC address and configures it (with a logging message "parent hardware
address changed to ...").

Try first whether we can change the MAC address without taking the
link down. Only if that fails, retry with taking it down first.

https://bugzilla.redhat.com/show_bug.cgi?id=1639274
(cherry picked from commit e206a34732)
2018-11-29 14:07:10 +01:00
Thomas Haller
f8a13422f1 platform: add nm_platform_link_get_ifi_flags() helper
Add helper nm_platform_link_get_ifi_flags() to access the
ifi-flags.

This replaces the internal API _link_get_flags() and makes it public.
However, the return value also allows to distinguish between errors
and valid flags.

Also, consider non-visible links. These are links that are in netlink,
but not visible in udev. The ifi-flags are inherrently netlink specific,
so it seems wrong to pretend that the link doesn't exist.

(cherry picked from commit b445b1f8fe)
2018-11-29 14:06:32 +01:00
Sebastien Fabre
b2eb897bc0 dbus: register object manager object before requesting dbus name
Working on NetworkManager 1.12.4 and sometimes (rarely), when creating
a NM client object before NetworkManager service start, this object will
never be running.
In that case, we can see the following log:
"[GLIB-GLib-GIO WARN] Error calling GetManagedObjects() when name
owner :1.5 for name org.freedesktop.NetworkManager came back:
GDBus.Error:org.freedesktop.DBus.Error.UnknownMethod:
No such interface 'org.freedesktop.DBus.ObjectManager' on object
at path /org/freedesktop".

Object Manager object shall be registered before requesting dbus name
to be sure that 'org.freedesktop.Dbus.ObjectManager' interface is present
when name owner change is received by libnm.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/51

(cherry picked from commit dc0cdbb57e)
2018-11-29 07:58:05 +01:00
Thomas Haller
66cbca1f21 platform/tests: fix assertion for unit test for address lifetime
Sometimes the test fail:

    $ make -j 10 src/platform/tests/test-address-linux
    $ while true; do
          NMTST_DEBUG=d ./tools/run-nm-test.sh src/platform/tests/test-address-linux 2>&1 > log.txt || break;
      done

fails with:

    ERROR: src/platform/tests/test-address-linux - Bail out! test:ERROR:src/platform/tests/test-common.c:790:nmtstp_ip_address_assert_lifetime: assertion failed (adr <= lft): (1001 <= 1000)

That is, because of a wrong check. Fix it.

(cherry picked from commit e180464bcc)
2018-11-28 16:17:33 +01:00
Patrick Talbert
e28bfa41a0 clients: Fix typo in _dump_team_link_watcher output
This makes the output of a 'con show' for a team device look suspect.

Signed-off-by: Patrick Talbert <ptalbert@redhat.com>

Fixes: 4657390d45

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/53
(cherry picked from commit 25a0739658)
2018-11-23 17:41:42 +01:00
Beniamino Galvani
05c27c3c50 lldp: fix parsing of vlan-name attribute
We used to read 3 bytes after the TLV, fix this.

Also, check that string length is at most 32 bytes as specified in
figure E.3 of IEEE 802.1AB-2009.

Fixes: 18133ea142

https://bugzilla.redhat.com/show_bug.cgi?id=1652210
(cherry picked from commit e909778710)
2018-11-22 09:43:18 +01:00
Lubomir Rintel
379eff21ed dhcp: drop unused variable
src/dhcp/nm-dhcp-client.c:552:16: error: unused variable 'str' [-Werror,-Wunused-variable]
        gs_free char *str = NULL;
                      ^

Fixes: 787f4b57cd
(cherry picked from commit 6f111b3d2e)
2018-11-22 07:37:32 +01:00
Beniamino Galvani
dca89e15b1 build: dist initrd meson.build files
Fixes: b544f7243d

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/77
(cherry picked from commit ca0c025486)
2018-11-22 07:37:14 +01:00
Beniamino Galvani
738962dbfe build: meson: fix wrong man page link
Fixes: 98b4a19a53

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/78
(cherry picked from commit 38299a1d78)
2018-11-22 07:37:00 +01:00
Lubomir Rintel
f7e6f0044c libnm/remote-connection: fix "flags" property getter
Fixes: acc8244ca2

https://github.com/NetworkManager/NetworkManager/pull/250
(cherry picked from commit 42e4d09844)
2018-11-21 11:50:36 +01:00
Beniamino Galvani
6af71ce4f4 cli: merge branch 'bg/cli-editor-save-rh1546805'
https://github.com/NetworkManager/NetworkManager/pull/244
https://bugzilla.redhat.com/show_bug.cgi?id=1546805
(cherry picked from commit 8af4f76638)
2018-11-20 15:28:00 +01:00
Beniamino Galvani
3af068a5de cli: wait for changed signal after updating a connection
In editor_menu_main(), after saving a connection we wait that the
Update2() D-Bus call returns and then we copy the NMRemoteConnection
instance over to @connection.

This assumes that when Update2() returns the remote connection
instance is already updated with new settings. Indeed, on server side
the NMSettingsConnection first emits the "Updated" signal and then
returns to Update2(). However, the Updated signal doesn't include the
new setting values and so libnm has to fire an asynchronous
nmdbus_settings_connection_call_get_setting() to fetch the new
settings, which terminates after the Update2().

So, to be sure that the remote connection got updated we have also to
listen to the connection-changed signal, which is always emitted after
an update.

https://bugzilla.redhat.com/show_bug.cgi?id=1546805
(cherry picked from commit a370faeb59)
2018-11-20 15:27:36 +01:00
Beniamino Galvani
d09e33f38c cli: editor: reload secrets after updating connection
Connection secrets are lost after calling
nm_connection_replace_settings_from_connection() because @con_tmp
doesn't contain secrets; refetch them like we do when starting the
editor.

(cherry picked from commit 096eef61d4)
2018-11-20 15:27:34 +01:00
Beniamino Galvani
c3233a6c17 libnm-core: macsec: don't require a cak in verify()
CAK is a connection secret and can be NULL for various reasons
(agent-owned, no permissions to get secrets, etc.). verify() must not
require it.

Fixes: 474a0dbfbe
(cherry picked from commit 8d5b01619b)
2018-11-20 15:27:30 +01:00
Thomas Haller
d5cf3a9776 libnm/macsec: tighten up verification and normalize mka_cak/mka_ckn properties
(cherry picked from commit 474a0dbfbe)
2018-11-20 15:27:22 +01:00
Lubomir Rintel
8ff9a51ca1 rpm: add a bundled(systemd) provide
Required by Fedora Packaging Standards [1] and also really useful.

[1] https://fedoraproject.org/wiki/Bundled_Libraries?rd=Packaging:Bundled_Libraries#Requirement_if_you_bundle

https://github.com/NetworkManager/NetworkManager/pull/247
https://bugzilla.redhat.com/show_bug.cgi?id=1645462

(cherry picked from commit adc0150e7f)
2018-11-16 09:55:47 +01:00
Thomas Haller
f92d2d7766 contrib/rpm: don't depend NetworkManager-ovs package on openvswitch on RHEL
On RHEL, openvswitch package is not in the base set of packages. Hence,
we cannot depend NetworkManager-ovs package on openvswitch.

This isn't really a problem, because NetworkManager's OVS plugin must
anyway behave graceful when openvswich service is not running or not
available. It only means, that a user who wants to use the OVS plugin
needs to explicitly install the openvswitch package.

https://bugzilla.redhat.com/show_bug.cgi?id=1629178
https://bugzilla.redhat.com/show_bug.cgi?id=1633190
(cherry picked from commit 669bd33022)
2018-11-16 09:52:30 +01:00
Benjamin Berg
bbef6cf44a systemd: fix crash by unrefing event sources before re-adding them
In certain cases the timeouts may not have been unref'ed before they
need to be re-added. Add the appropriate unref calls to ensure we don't
register the timeout multiple times.

This fixes possible cases where timeouts are triggered multiple times
and even on destroyed DHCPv6 clients.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/73

(cherry picked from commit e179202e47)
2018-11-15 14:51:05 +01:00
Thomas Haller
aa7acb0ae3 build: avoid header conflict for <linux/if.h> and <net/if.h> with "nm-platform.h"
In the past, the headers "linux/if.h" and "net/if.h" were incompatible.
That means, we can either include one or the other, but not both.
This is fixed in the meantime, however the issue still exists when
building against older kernel/glibc.

That means, including one of these headers from a header file
is problematic. In particular if it's a header like "nm-platform.h",
which itself is dragged in by many other headers.

Avoid that by not including these headers from "platform.h", but instead
from the source files where needed (or possibly from less popular header
files).

Currently there is no problem. However, this allows an unknowing user to
include <net/if.h> at the same time with "nm-platform.h", which is easy
to get wrong.

(cherry picked from commit 37e47fbdab)
2018-11-14 14:39:10 +01:00
Thomas Haller
8f4e4cc54f dhcp: merge branch 'th/dhcp-client-id-mac-rh1640494'
https://github.com/NetworkManager/NetworkManager/pull/243

(cherry picked from commit 2799634082)
2018-11-14 14:18:54 +01:00
Thomas Haller
62a5ff605b dhcp: initialize hostname as construct-property
The hostname property is only initialized once, early on during
start. Move the initialization even earlier during object constructions.
This effectively makes the hostname an immutable property.

This also makes sense, because the hostname is used by IPv4 and
IPv6 DHCP instances alike.

(cherry picked from commit 787f4b57cd)
2018-11-14 14:18:06 +01:00
Thomas Haller
22ffd02f87 core/trivial: add code comment about DHCP client-id/DUID
(cherry picked from commit e9630e7d57)
2018-11-14 14:18:06 +01:00
Thomas Haller
525830a4a0 dhcp: add "ipv4.dhcp-client-id=duid" setting
Add a new mode for the DHCPv4 client identifier.

"duid" is what the internal (systemd) DHCP client already does by
default. It is also the same as used by systemd-networkd's
"ClientIdentifier=duid" setting. What we still lack (compared to
networkd) are a way to overwrite IAID and the DUID.

Previously, this mode was used by the internal DHCP plugin
by default. However, it could not be explicitly configured.
In general, our default values should also be explicitly selectable.
Now the "duid" client identifier can also be used with the "dhclient"
plugin.

(cherry picked from commit 8861ac2976)
2018-11-14 14:18:06 +01:00
Thomas Haller
cb50647144 dhcp: always require hwaddr in internal DHCP clint ip6_start()
Note how client_start() in NMDhcpManager already asserts
that we have a MAC address. It's always present, like
for the IPv6 case.

(cherry picked from commit dfdd4e3bd3)
2018-11-14 14:18:06 +01:00
Thomas Haller
0983f14be6 doc: add hint about ipv4.dhcp-client-id=stable
(cherry picked from commit 5ef93c3323)
2018-11-14 14:18:06 +01:00
Thomas Haller
f70e762a4f all: add "${MAC}" substituion for "connection.stable-id"
We already had "${DEVICE}" which uses the interface name.
In times of predictable interface naming, that works well.
It allows the user to generate IDs per device which don't
change when the hardware is replaced.

"${MAC}" is similar, except that is uses the permanent MAC
address of the device. The substitution results in the empty
word, if the device has no permanent MAC address (like software
devices).

The per-device substitutions "${DEVICE}" and "${MAC}" are especially
interesting with "connection.multi-connect=multiple".

(cherry picked from commit 7ffbf71276)
2018-11-14 14:18:06 +01:00
Thomas Haller
a31edf0b3e dhcp: cleanup error handling in internal DHCP client's start
- use nm_auto to return early when something goes wrong

- don't modify NMDhcpClient's state until the end, when it looks
  like we are (almost) started successfully.

- for IPv4, only attempt to load the lease if we actually are
  interested in the address. Also, reduce the scope of the lease
  variable, to the one place where we need it.

(cherry picked from commit ab314065b8)
2018-11-14 14:18:06 +01:00
Thomas Haller
b21652b8d0 dhcp: don't load IPv4 client-id from lease file
The client-id is something that we want to determine top-down.
Meaning, if the user specifies it via ipv4.dhcp-client-id, then it
should be used. If the user leaves it unspecified, we choose a
default stable client-id. For the internal DHCP plugin, this is
a node specific client-id based on

  - the predictable interface name
  - and /etc/machine-id

It's not clear, why we should allow specifying the client-id in
the lease file as a third source of configuration. It really pushes
the configuration first down (when we do DHCP without lease file),
to store an additional bit of configuration for future DHCP attempts.

If the machine-id or the interface-name changes, then so does the
default client-id. In this case, also "ipv4.dhcp-client-id=stable"
changes. It's fair to require that the user keeps the machine-id
stable, if the machine identity doesn't change.

Also, the lease files are stored in /var/lib/NetworkManager, which
is more volatile than /etc/machine-id. So, if we think that machine-id
and interface-name is not stable, why would we assume that we have
a suitable lease file?

Also, if you do:

   nmcli connection add con-name "$PROFILE" ... ipv4.dhcp-client-id ''
   nmcli connection up $PROFILE
   nmcli connection modify "$PROFILE" ipv4.dhcp-client-id mac
   nmcli connection up $PROFILE
   nmcli connection modify "$PROFILE" ipv4.dhcp-client-id ''
   nmcli connection up $PROFILE

wouldn't you expect that the original (default) client-id is used again?

Also, this works badly with global connection defaults in
NetworkManager.conf. If you configure a connection default, previously
already this would always force the client-id and overrule the lease.
That is reasonable, but in which case would you ever want to use
the client-id from the lease?

(cherry picked from commit 5b9bc174d1)
2018-11-14 14:18:06 +01:00
Thomas Haller
d54b444cb4 dhcp: cleanup initializing IPv4 client-id for internal DHCP
- if we leave the client-id of sd_dhcp_client unset, it will
  anyway generate a node-specific client-id (and may fail if
  "/etc/machine-id" is invalid).
  Anticipate that, and don't let the client-id unset. In case
  we have no client-id from configuration or lease, just generate
  the id ourself (using the same algorithm). The advantage is,
  that we know it upfront and can store the client-id in the
  NMDhcpClient instance. We no longer need to peel it out from
  the lease later.

- to generate the IPv4 client-id, we need a valid MAC address. Also,
  sd_dhcp_client needs a MAC address for dhcp_network_bind_raw_socket()
  as well. Just require that a MAC address is always needed. Likewise,
  we need a valid ifindex and ifname set.

- likewise for IPv6 and IPv4, cleanup detecting the arptype and
  checking MAC address length. sd_dhcp_client_set_mac() is overly
  strict at asserting input arguments, so we must validate them anyway.

- also, now that we always initialize the client-id when starting
  the DHCP client, there is no need to retroactively extract it
  again when we receive the first lease.

(cherry picked from commit c3e7e6170d)
2018-11-14 14:18:06 +01:00
Thomas Haller
71e3db4f56 dhcp/trivial: wrap lines in calling client_start()
A possible issue is that client_start() has about 136 arguments.
It doesn't get simpler by saving lines of code and writing them
all in the same line.

Wrap the lines.

While at it, use "FALSE" for "enforce_duid" argument, instead of "0".
It's a boolean.

(cherry picked from commit ce1cfd7232)
2018-11-14 14:18:06 +01:00
Thomas Haller
1fecb5ec9d dhcp: minor refactoring return paths in NMDhcpDhclient.get_duid()
(cherry picked from commit d6d2b7296f)
2018-11-14 14:18:06 +01:00
Thomas Haller
93eb69a0e9 dhcp: use cleanup attribute for get_dhclient_leasefile()
(cherry picked from commit b833d68d68)
2018-11-14 14:18:06 +01:00
Thomas Haller
cc0c056885 dhcp: don't pass duid to client ip6_start() and stop()
We don't do that for ip4_start() either. The duid/client-id
is stored inside the NMDhcpClient instance, and the function can
access it from there.

Maybe, it is often preferable to have stateless objects and not
relying on ip4_start() to obtain the client ID from the client's
state. However, the purpose of the NMDhcpClient object is to
hold state about DHCP. To simplify the complexity of objects that
inherrently have state, we should be careful about mutating the state.
It adds little additional complexity of only reading the state when
needed anyway. In fact, it adds complexity, because previously
it wasn't enough to check all callers of nm_dhcp_client_get_client_id()
to see where the client-id is used. Instead, one would also need to
follow the @duid argument several layers of the call stack.

(cherry picked from commit 7d55b1348b)
2018-11-14 14:18:06 +01:00
Thomas Haller
0e6c84e806 dhcp: refactor nm_dhcp_dhclient_save_duid() to accept original DUID
There should be lower layers that are concerned with writing
and reading dhclient configuration files. It's wrong to
have a nm_dhcp_dhclient_save_duid() function which requires
the caller to pre-escape the string to write. The caller shouldn't
be concerned with the file format, that's why the function
is used in the first place.

(cherry picked from commit cd9e418fbe)
2018-11-14 14:18:06 +01:00
Thomas Haller
d347c927cd dhcp: merge "duid" and "client_id" field in NMDhcpClient
We only used "client_id" for IPv4 and "duid" for IPv6. Merge them.

Another advantage is, that we can share the logging functionality
of _set_client_id().

(cherry picked from commit 7e341b73e0)
2018-11-14 14:18:06 +01:00
Thomas Haller
981a54024b dhcp: drop unused nm_dhcp_dhclient_get_client_id_from_config_file()
Drop unused function.

Aside from that, dhclient configuration files support a very complex
syntax. The parser was very naive and insufficient in parsing such
files. It's good we can just drop it.

(cherry picked from commit 025157d597)
2018-11-14 14:18:06 +01:00
Thomas Haller
a6095fd043 dhcp: don't re-read DHCP client ID from configuration file for dhclient
Why would we do this? The configuration file we are reading back was
written by NetworkManager in the first place.

Maybe when assuming a connection after restart, this information could
be interesting. It however is not actually relevant.

Note how nm_dhcp_client_get_client_id() has only very few callers.

  - nm_device_spawn_iface_helper() in 'nm-device.c'. In this case,
    we either should use the client-id which we used when starting
    DHCP, or none at all.

  - ip4_start() in 'nm-dhcp-dhclient.c', but this is before starting
    DHCP client and before it was re-read from configuration file.

  - in "src/dhcp/nm-dhcp-systemd.c", but this has no effect for
    the dhclient plugin.

(cherry picked from commit 5411fb0cc6)
2018-11-14 14:18:06 +01:00
Thomas Haller
3b8d882658 dhcp: reimplement node-specific DHCP client-id generation from systemd
Our internal DHCP client (from systemd) defaults to a particular client ID.
It is currently exposed as nm_sd_utils_generate_default_dhcp_client_id()
and is based on the systemd implementation.

One problem with that is, that it internally looks up the interface name
with if_indextoname() and reads /etc/machine-id. Both makes it harder
for testing.

Another problem is, that this way of generating the client-id is
currently limited to internal client. Why? If you use dhclient plugin,
you may still want to use the same algorithm. Also, there is no explict
"ipv4.dhcp-client-id" mode to select this client-id (so that it could
be used in combination with "dhclient" plugin).
As such, this code will be useful also aside systemd DHCP plugin.
Hence, the function should not be obviously tied to systemd code.

The implementation is simple enough, and since we already have a
unit-test, refactor the code to our own implementation.

(cherry picked from commit a55795772a)
2018-11-14 14:18:06 +01:00
Thomas Haller
13bf09fbd9 dhcp: test systemd's default DHCP client identifier generation
Internal DHCP client generates a default client ID. For one,
we should ensure that this algorithm does not change without
us noticing, for example, when upgrading systemd code. Add
a test, that the generation algorithm works as we expect.

Also note, that the generation algorithm uses siphash24().
That means, siphash24() implementation also must not change
in the future, to ensure the client ID doesn't change. As we
patch systemd sources to use shared/c-siphash, this is not
obviously the case. Luckily c-siphash and systemd's siphash24 do
agree, so all is good. The test is here to ensure that.

Also, previously the generation algorithm is not exposed as a
function, sd_dhcp_client will just generate a client-id when
it needs it. However, later we want to know (and set) the client
id before starting DHCP and not leave it unspecified to an
implementation detail.

This patch only adds a unit-test for the existing DHCP client
ID generation to have something for comparison. In the next
commit this will change further.

(cherry picked from commit 187d356198)
2018-11-14 14:18:06 +01:00
Thomas Haller
b04c033007 core: cleanup generating DUID in nm-device.c
- use NMUuid type where appropriate.

- no error handling for generate_duid_from_machine_id().
  It cannot fail anymore.

- add thread-safety to generate_duid_from_machine_id() with
  double-checked locking.

- use unions for converting the sha256 digest to the target
  type.

(cherry picked from commit 50121ee028)
2018-11-14 14:18:06 +01:00
Thomas Haller
10e280686e core: pass boot-id to nm_utils_stable_id_parse()
For testing purpose, it's bad to let nm_utils_stable_id_parse()
directly access nm_utils_get_boot_id_str(). Instead, the function
should have no side-effects.

Since the boot-id is anyway cached, accessing it is cheap. Even
if it likely won't be needed.

(cherry picked from commit c51e63feb6)
2018-11-14 14:18:05 +01:00
Thomas Haller
0c1ee8c68e core: don't persist secret-key for tests
Tests might access the secret-key.

For CI builds we may very well build NM as root and also run
unit tests. In such a situation it's bad to persist the secret
key. For example, the SELinux label may be wrong, and subsequently
starting NetworkManager may cause errors. Avoid persisting the secret
key for tests.

(cherry picked from commit 581e1c3269)
2018-11-14 14:18:05 +01:00
Thomas Haller
36ca7dd2c0 core: refactor loading machine-id and cache it
Previously, whenever we needed /etc/machine-id we would re-load it
from file. The are 3 downsides of that:

 - the smallest downside is the runtime overhead of repeatedly
   reading the file and parse it.

 - as we read it multiple times, it may change anytime. Most
   code in NetworkManager does not expect or handle a change of
   the machine-id.
   Generally, the admin should make sure that the machine-id is properly
   initialized before NetworkManager starts, and not change it. As such,
   a change of the machine-id should never happen in practice.
   But if it would change, we would get odd behaviors. Note for example
   how generate_duid_from_machine_id() already cached the generated DUID
   and only read it once.
   It's better to pick the machine-id once, and rely to use the same
   one for the remainder of the program.
   If the admin wants to change the machine-id, NetworkManager must be
   restarted as well (in case the admin cares).
   Also, as we now only load it once, it makes sense to log an error
   (once) when we fail to read the machine-id.

 - previously, loading the machine-id could fail each time. And we
   have to somehow handle that error. It seems, the best thing what we
   anyway can do, is to log an error once and continue with a fake
   machine-id. Here we add a fake machine-id based on the secret-key
   or the boot-id. Now obtaining a machine-id can no longer fail
   and error handling is no longer necessary.

Also, ensure that a machine-id of all zeros is not valid.

Technically, a machine-id is not an RFC 4122 UUID. But it's
the same size, so we also use NMUuid data structure for it.

While at it, also refactor caching of the boot-id and the secret
key. In particular, fix the thread-safety of the double-checked
locking implementations.

(cherry picked from commit 8308311264)
2018-11-14 14:18:02 +01:00
Thomas Haller
7494145649 core: add "nm-sd-utils.h" to access system internal helper
We have a fork of a lot of useful systemd helper code.
However, until now we shyed away from using it aside from
the bits that we really need.

That means, although we have some really nice implementations
in our source-tree, we didn't use them. Either we were missing
them, or we had to re-implement them.

Add "nm-sd-utils.h" header to very carefully make internal
systemd API accessible to the rest of core.

This is not intended as a vehicle to access all of internal
API. Instead, this must be used with care, and only a hand picked
selection of functions must be exposed. Use with caution, but where it
makes sense.

(cherry picked from commit eece5aff09)
2018-11-14 14:17:34 +01:00
Thomas Haller
81024a9772 core: minor cleanup of initializing nm_utils_get_testing()
- add a commnt about thread-safety.

- minor refactoring initializing the value in nm_utils_get_testing().
  Instead of returning the flags we just set, go back to the begin
  and re-read the value (which must be initialized by now). No big
  difference, but feels a bit nicer to me.

(cherry picked from commit e1413111a7)
2018-11-14 14:17:34 +01:00
Thomas Haller
16bde2d1ec dhcp: log client-id of DHCP instance
(cherry picked from commit 2af1dc1d28)
2018-11-14 14:17:34 +01:00
Thomas Haller
d4c9401780 all: cleanup GChecksum handling
- prefer nm_auto_free_checksum over explicit free.
- use nm_utils_checksum_get_digest*().
- prefer defines for digest length.
- assume g_checksum_new() cannot fail.

(cherry picked from commit eb9f950a33)
2018-11-14 14:17:34 +01:00
Thomas Haller
5dc8a14576 libnm: cleanup _nm_utils_hexstr2bin*() helper
Add 3 variants of _nm_utils_hexstr2bin*():

  - _nm_utils_hexstr2bin_full(), which takes a preallocated
    buffer and fills it.
  - _nm_utils_hexstr2bin_alloc() which returns a malloc'ed
    buffer
  - _nm_utils_hexstr2bin_buf(), which fills a preallocated
    buffer of a specific size.

(cherry picked from commit be6c7fa5f6)
2018-11-14 14:17:34 +01:00
Thomas Haller
b4626ba2e7 shared: add nm_utils_checksum_get_digest*() helper
The GChecksum API is cumbersome to use.

For example, g_checksum_get_digest() requires a length input/output
argument. At the same time, GChecksum does not allow you to query its
checksum-type nor the desired digest-length. When you have a GChecksum
at hand, you must always know the digest-length you are going to use.
So, the length parameter is only good for asserting.

Add a macro to make that more convenient.

Benefits: it's less lines of code, and we always do all the asserts
that are due.

(cherry picked from commit 3746845204)
2018-11-14 14:17:34 +01:00