Commit graph

412 commits

Author SHA1 Message Date
Thomas Haller d32da2daaa shared: move nm_utils_array_find_binary_search() to shared utils 2018-08-10 10:38:19 +02:00
Thomas Haller b5bdfdc773 shared: add nm_utils_hash_table_equal() util
Add utility function to compare the content of two
hash tables for equality.
2018-08-10 10:38:19 +02:00
Thomas Haller b6c094e55e build/meson: fix naming of shared_nm_meta_setting_c variable 2018-08-10 10:38:19 +02:00
Thomas Haller 852abf3d3d all/style: write elvis operator ?: without space
By far most of the time, we write "?:" and not "? :". Adjust
the few places that don't.
2018-08-09 17:06:18 +02:00
Thomas Haller ccf6bdb0e2 shared: add nm_gobject_notify_together() helper
NM_GOBJECT_PROPERTIES_DEFINE() defines a helper function
_notify() to emit a GObject property changed notification.

Add another helper function to emit multiple notifications
together, and freeze/thaw the notification before.

This is particularly useful, because our D-Bus glue in
"nm-dbus-object.c" hooks into dispatch_properties_changed(),
to emit a combined PropertiesChanged signal for multiple
properties. By carefully freezing/thawing the notifications,
the exported objects can combine changes of multiple properties
in one D-Bus signal.

This helper is here to make that simpler.

Note that the compiler still has no problem to inline _notify()
entirey. So, in a non-debug build, there is little difference in
the generated code. It can even nicely inline calls like

    nm_gobject_notify_together (self, PROP_ADDRESS_DATA,
                                      PROP_ADDRESSES);
2018-08-01 14:26:36 +02:00
Thomas Haller d209966c29 shared/c-list: re-import from latest c-util/c-list
$ git subtree pull --prefix shared/c-list/ git@github.com:c-util/c-list.git 071841c28d96e9104761af815a7ea367390c3174 --squash
2018-08-01 12:57:34 +02:00
Lubomir Rintel 9c6ff7fe18 build: do not randomize tests by default
We don't want the users to default to running the code paths in tests that
we didn't check before. They may end up failing randomly.
2018-07-24 20:10:45 +02:00
Thomas Haller 246b747540 shared: add special error codes to NM_UTILS_ERROR
Will be used next.
2018-07-24 09:39:09 +02:00
Thomas Haller 0ee782d03e shared: add nm_utils_error_set*() helper macros
Add helper macros to type less.
2018-07-24 09:39:09 +02:00
Thomas Haller 0d3bb64008 shared: support zero arguments for NM_NARG() macro
It relies on the GCC extension ##__VA_ARGS__, but we
do that on various places already.

Also add a test.
2018-07-24 09:39:09 +02:00
Thomas Haller 196d7c8ca5 shared: use nm_auto() macro to define other nm_auto_* macros 2018-07-18 10:27:39 +02:00
Thomas Haller d0b3702b37 shared: cleanup nm_auto implementations
- Reuse NM_AUTO_DEFINE*() where possible.
- Consistently name the cleanup functions for "nm_auto_xzy" as
  _nm_auto_xzy().
2018-07-18 10:21:27 +02:00
Thomas Haller e9d9fc3fa0 shared/gsystem-local-alloc: merge "gsystem-local-alloc.h" into "nm-macros-shared.h"
We only have a certain granularity of how our headers in "shared/nm-utils"
can be used independently.

For example, it's not supported to use "nm-macros-internal.h" without
"gsystem-local-alloc.h". Likewise, you cannot use "nm-glib.h" directly,
you always get it together with "nm-macros-internal.h".

This is, we don't support to use certain headers entirely independently,
because usually you anyway want to use them together.

As such, no longer support "gsystem-local-alloc.h", but merge the
remainder into "nm-macros-internal.h". There is really no reason
to support arbitrary flexibility of including individual bits. You
want cleanup-macros? Include "nm-macros-internal.h".

Merge the headers.
2018-07-18 10:21:27 +02:00
Thomas Haller c2245e3e5c shared/trivial: whitespace 2018-07-18 10:21:27 +02:00
Thomas Haller a38782f378 shared/trivial: rename GS_DEFINE_CLEANUP_FUNCTION_*() macros
To be consistent with our other nm_auto* related functions.
2018-07-18 10:21:27 +02:00
Thomas Haller 904e8b8ca0 shared/gsystem-local-alloc: rename unused gs_* cleanup macros
These cleanup macros are unused by NetworkManager code. Note that
since "shared/nm-utils" is used by applet and VPN plugins, theoretically,
they could be used there. I didn't check that, but breaking API of
"shared/nm-utils" is fine (as long as we catch it with a compilation
error).

Historically, we use libgsystem's gsystem-local-alloc header and their
"gs_*" macros. However, they are not really our style and don't have
a nm-prefix (like the rest of our code). We keep the gs_ names, because
they are wildly used and because we wanted to keep gsystem-local-alloc
in sync with upstream (which is no longer the case).

Our own cleanup macros are always called "nm_auto_*". So, at least
for the unused "gs_*" macros, rename them to "nm_auto_*".

Don't drop them, despite they being unused. The reason is, that we should
make use of cleanup functions more eagerly. Dropping them now -- because
they are momentarily unused -- hampers using them in the future. We
often don't use the cleanup macros at places where I think we should,
so by dropping them, we hamper future use.
2018-07-18 10:21:27 +02:00
Thomas Haller 5513af2e14 shared/trivial: add comment to nm_auto_free
It's not obvious why we have "nm_auto_free" along "gs_free".
Explain it.

Also, define the cleanup function first, then the nm-auto macro.
2018-07-18 10:21:27 +02:00
Thomas Haller 1546db05bd shared/gsystem-local-alloc: remove unused "gs_fd_close" cleanup macro
Drop unused "gs_fd_close" macro, now that we no longer care about keeping
"gsystem-local-alloc.h" header in sync with (unmaintained) upstream.

Also, our own "nm_auto_close" macro should be preferred, because

 - it preserves errno

 - it uses nm_close(), which asserts against EBADF.
2018-07-18 10:21:27 +02:00
Thomas Haller 0814ed8080 shared/gsystem-local-alloc: fix gs_free_variant_iter/gs_local_variant_builder_unref
Wrong signature, but they are unused anyway.

Fixes: 98c71df8a3
2018-07-18 10:21:27 +02:00
Thomas Haller a75ab799e4 build: create "config-extra.h" header instead of passing directory variables via CFLAGS
1) the command line gets shorter. I frequently run `make V=1` to see
   the command line arguments for the compiler, and there is a lot
   of noise.

2) define each of these variables at one place. This makes it easy
   to verify that for all compilation units, a particular
   define has the same value. Previously that was not obvious or
   even not the case (see commit e5d1a71396
   and commit d63cf1ef2f).
   The point is to avoid redundancy.

3) not all compilation units need all defines. In fact, most modules
   would only need a few of these defines. We aimed to pass the necessary
   minium of defines to each compilation unit, but that was non-obvious
   to get right and often we set a define that wasn't used. See for example
   "src_settings_plugins_ibft_cppflags" which needlessly had "-DSYSCONFDIR".
   This question is now entirely avoided by just defining all variables in
   a header. We don't care to find the minimum, because every component
   gets anyway all defines from the header.

4) this also avoids the situation, where a module that previously did
   not use a particular define gets modified to require it. Previously,
   that would have required to identify the missing define, and add
   it to the CFLAGS of the complation unit. Since every compilation
   now includes "config-extra.h", all defines are available everywhere.

5) the fact that each define is now available in all compilation units
   could be perceived as a downside. But it isn't, because these defines
   should have a unique name and one specific value. Defining the same
   name with different values, or refer to the same value by different
   names is a bug, not a desirable feature. Since these defines should
   be unique accross the entire tree, there is no problem in providing
   them to every compilation unit.

6) the reason why we generate "config-extra.h" this way, instead of using
   AC_DEFINE() in configure.ac, is due to the particular handling of
   autoconf for directory variables. See [1].
   With meson, it would be trivial to put them into "config.h.meson".
   While that is not easy with autoconf, the "config-extra.h" workaround
   seems still preferable to me.

[1] https://www.gnu.org/software/autoconf/manual/autoconf-2.63/html_node/Installation-Directory-Variables.html
2018-07-17 17:46:39 +02:00
Thomas Haller 98c71df8a3 shared/gsystem-local-alloc: strongly type gs_* cleanup functions
At various places, use the correct type for the pointer, this
allows the compiler to be more helpful.

For gs_free, gs_unref_object, and nm_auto_free, the pointer type is
of course still 'void *'.

This catches wrong uses like

   gs_strfreev char *wrong1 = NULL;
   gs_strfreev const char **wrong2 = NULL;
   gs_free_error GError **p_error = NULL;
   gs_unref_array GPtrArray *ptr_array = NULL;

Note that long time ago we copied "gsystem-local-alloc.h" header
from libgsystem library. Until now, we didn't apply any local
modification to this file, to keep it in sync with upstream.
However, upstream libgsystem is not maintained anymore, so there
is no reason to stay in sync with upstream.
2018-07-11 16:38:12 +02:00
Beniamino Galvani a2f12994b7 cli: add support for configuring SR-IOV 2018-07-11 16:16:22 +02:00
Thomas Haller 634b2d1ce2 shared: add nm_auto_vfree macro
This really is the same as gs_strfreev / g_strfreev().
However, the difference is, that the former has the notion
of freeing strv arrays (char **), while this in general
frees an array of pointers. Implementation-wise, they are
the same.
2018-07-11 16:16:22 +02:00
Thomas Haller fe07d6a404 shared: add nm_hash_val() macro
A helper macro, to combine the steps for hashing one value.
2018-07-11 16:16:22 +02:00
Thomas Haller e1c7a2b5d0 all: don't use gchar/gshort/gint/glong but C types
We commonly don't use the glib typedefs for char/short/int/long,
but their C types directly.

    $ git grep '\<g\(char\|short\|int\|long\|float\|double\)\>' | wc -l
    587
    $ git grep '\<\(char\|short\|int\|long\|float\|double\)\>' | wc -l
    21114

One could argue that using the glib typedefs is preferable in
public API (of our glib based libnm library) or where it clearly
is related to glib, like during

  g_object_set (obj, PROPERTY, (gint) value, NULL);

However, that argument does not seem strong, because in practice we don't
follow that argument today, and seldomly use the glib typedefs.
Also, the style guide for this would be hard to formalize, because
"using them where clearly related to a glib" is a very loose suggestion.

Also note that glib typedefs will always just be typedefs of the
underlying C types. There is no danger of glib changing the meaning
of these typedefs (because that would be a major API break of glib).

A simple style guide is instead: don't use these typedefs.

No manual actions, I only ran the bash script:

  FILES=($(git ls-files '*.[hc]'))
  sed -i \
      -e 's/\<g\(char\|short\|int\|long\|float\|double\)\>\( [^ ]\)/\1\2/g' \
      -e 's/\<g\(char\|short\|int\|long\|float\|double\)\>  /\1   /g' \
      -e 's/\<g\(char\|short\|int\|long\|float\|double\)\>/\1/g' \
      "${FILES[@]}"
2018-07-11 12:02:06 +02:00
Thomas Haller bf593304ef shared: ensure "nm-glib.h" is not used without "nm-macros-internal.h"
Note how "nm-glib.h" uses _nm_printf() macro, which is defined in
"nm-macros-internal.h". There are many ways how to solve that
problem.

For example, we could define certain _nm_*() macros in "nm-glib.h"
itself. However, that is a bit awkward, because optimally "nm-glib.h"
only provides functions that are strictly related to glib compatiblity.
_nm_printf() is used by "nm-glib.h" for its own implementation, it should
not provide (or reimplement) this macro.

We solve this instead by enforcing what NetworkManager already does.
NetworkManager never includes "nm-glib.h" directly, instead
"nm-macros-internal.h" is the only place that includes the glib compat
header. It means, you cannot use "nm-glib.h" without
"nm-macros-internal.h". But that is a reasonable compromise, with
respect to granularity. The granularity at the moment is: if you use
anything from "shared/nm-utils", you almost always need at least
"nm-macros-internal.h" header (and automatically also get "nm-glib.h"
and "gsystem-local-alloc.h"). It's not intended, to use "nm-glib.h"
directly.

This makes "nm-glib.h" an implementation detail of "nm-macros-internal.h"
and it only exists to separate code that is related to glib compatibility to
its own header.
2018-07-09 16:30:12 +02:00
Thomas Haller 62cd6afd98 shared/trivial: prettify nm-glib.h compat implementation by grouping code 2018-07-09 16:30:12 +02:00
Thomas Haller 56ddc8904d shared: restore compat code in nm-glib.h for 2.32 compatibility
In commit 8a46b25cfa, NetworkManager
bumped its glib dependency to 2.40 or newer.

"nm-glib.h" header is precisely the compatiblity implementation that we
use to cope with older glib versions. Note, that the same implementation
is also used by applet and VPN plugins.

However, applet and VPN plugins don't yet require 2.40 glib. Also,
they don't yet require NetworkManager 1.12.0 API (which was the one
that bumped the glib requirement to 2.40). Hence, when "nm-glib.h"
is used in applet or VPN, it must still cope with older versions,
although, the code is not used by NetworkManager itself.

Partly revert 8a46b25cfa so that nm-glib.h
again works for 2.32 or newer.

The same is true, also for "nm-test-utils.h", which is also used by
applet and VPN plugins.
2018-07-09 16:30:12 +02:00
Michael Biebl 7ab7dc9487 Increase timeout in test-nm-client to 30s
On slow architectures it can take longer then 3s for the test service to
start up.
2018-07-05 16:48:06 +02:00
Lubomir Rintel 29636535b2 client: support 6lowpan setting 2018-06-26 16:21:55 +02:00
Lubomir Rintel 5da77c0e2c client: support wpan setting 2018-06-26 16:21:55 +02:00
Thomas Haller e2ef7cad57 tests: add nmtstc_auto_service_cleanup macro 2018-06-25 12:13:28 +02:00
Thomas Haller ae21723d2a shared: use nm_hash_update() instead of c_siphash_append()
In our own code, there are very few places where we should
call c_siphash_append() directly. This is not one of them.
2018-06-22 14:19:49 +02:00
Thomas Haller 86dc1f1394 tests: expose current state in local context of NMTST_WAIT()
Inside the loop-handler, it can be interesting to know the current iteration,
and how much time is left.
2018-06-20 14:45:27 +02:00
Thomas Haller f468602d50 shared: support nm_g_slice_free_fcn() for arguments with sizeof() of 10 bytes
On m68k architecture, the struct

    typedef struct {
        gint64 timestamp_ms;
        bool dirty;
    } IP6RoutesTemporaryNotAvailableData;

ends up being of a previously unhandled size. Causing a compile time
assertion to fail.

Support argument sizes of 10 bytes for nm_g_slice_free_fcn().
2018-06-19 14:44:51 +02:00
Thomas Haller fb9edd5edd release: bump version to 1.13.0 (development) 2018-06-15 17:16:18 +02:00
Lubomir Rintel 07fd0502f6 wifi: expose LastScan as milliseconds not seconds
This doesn't wrap around in 68 years of uptime and is consistent with
o.fd.NM.Checkpoint.Created.
2018-06-15 16:23:30 +02:00
Thomas Haller 13f860970a systemd: merge branch systemd into master 2018-06-15 15:56:04 +02:00
Thomas Haller 353810ccc1 systemd: update code from upstream (2018-06-15)
This is a direct dump from systemd git.

======

SYSTEMD_DIR=../systemd
COMMIT=88f375b8c28806633d22ed99f6a5f1194c78ed73

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

git ls-files :/src/systemd/src/ \
             :/shared/nm-utils/siphash24.h \
             :/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/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-06-15 15:18:28 +02:00
Thomas Haller 9586d2794a shared: simplify nm_g_object_ref_set()
Also, assign *_pp before unref-ing the old value. Calling
g_object_unref() on the old value, might invoke callbacks
that are out of control of nm_g_object_ref_set(). During
that time, the pointer should already be assigned the new value,
instead of having an intermediate %NULL value. In most cases,
this would of course not matter, but there is no need to let
anyone see an intermediate %NULL value for a moment.

Also, don't use typeof(**_pp), which would not work with opaque
types (like we commonly have).
2018-06-15 09:07:19 +02:00
Thomas Haller b18c9e44ed shared/trivial: add code comment to explain NMUtilsEnumValueInfo consistency rules 2018-06-01 12:26:07 +02:00
Thomas Haller f445128af4 build/meson: fix meson build for shared files
The files in shared/nm-utils are not compiled as one static library,
instead each subproject that needs (parts of) them, re-compiles the
files individually.

The major reason for that is, because we might have different compile
flags, depending on whether we build libnm-core or
libnm-util/libnm-glib. Actually, I think that is not really the case,
and maybe this should be refactored, to indeed build them all as a
static library first.

Anyway, libnm-util, libnm-glib, clients' common lib, they all need a
different set of shared files that they should compile. Refactor
"shared/meson.build" to account for that and handle it like autotools
does.

Another change is, that "shared_c_siphash_dep" no longer advertises
"include_directories: include_directories('c-siphash/src')". We don't
put c-siphash.h into the include search path. Users who need it, should
include it via "#include <c-siphash/src/c-siphash.h>". The only exception
is when building shared_n_acd library, which is not under our control.
2018-05-31 15:59:38 +02:00
Thomas Haller b8b6100c78 all: replace systemd's siphash24 with c-siphash
Originally, we used "nm-utils/siphash24.c", which was copied
from systemd's source tree. It was both used by our own NetworkManager
code, and by our internal systemd fork.

Then, we added "shared/c-siphash" as a dependency for n-acd.

Now, drop systemd's implementation and use c-siphash also
for our internal purpose. Also, let systemd code use c-siphash,
by patching "src/systemd/src/basic/siphash24.h".
2018-05-31 15:59:38 +02:00
Thomas Haller b7426e91db build: use default NM_BUILD_* defines for tests
Use two common defines NM_BUILD_SRCDIR and NM_BUILD_BUILDDIR
for specifying the location of srcdir and builddir.

Note that this is only relevant for tests, as they expect
a certain layout of the directories, to find files that concern
them.
2018-05-31 15:59:38 +02:00
Thomas Haller 82b088ab5f build: don't add shared/nm-utils directory to include search path
All users are supposed to include files from nm-utils by fully specifying
the path. -I.*shared/nm-utils is wrong.

Only, systemd code likes to include "siphash24.h" directly. Instead of
adding "-Ishared/nm-utils" to the search path, add an intermediary
header to sd-adapt. Note, that in the meantime we anyway should rework
siphash24 to use shared/c-siphash instead.

This also fixes build for meson, which was broken recently.
2018-05-31 15:59:38 +02:00
Thomas Haller 54356ac8c7 shared: don't use nm_str_hash() in "nm-enum-utils.c"
This was only used for some extra assertions. It' is not essential.
If this would be for real usage, we should add a dependancy so that
nm-utils/nm-enum-utils.c requires nm-hash-utils.h. But as it is,
this is not necessary.

This fixes build for meson, which wrongly tries to build nm-enum-utils.c
for libnm-util, but then fails to include nm-hash-utils.c. That should
be fixed independently.

Fixes: 84a6eff106
2018-05-30 11:57:10 +02:00
Thomas Haller 84a6eff106 shared: don't allow aliases re-numbering in _nm_utils_enum_from_str_full()
For _nm_utils_enum_to_str_full(), we always first look whether we have
an alias/nick for the numeric value, and preferably use that. That makes a
lot of sense, as it allows the caller to provide better names (aliases),
which are preferred over the name from the GLib type. It renames the
numeric value.

For the reverse conversion, this makes less sense. A name should have a
unique numeric value. That is, we should not use one name that maps to
a different numeric value based on value_infos and GLib type. IOW, we
should not re-number names.

Add an assertion that we don't provide such a value_infos parameter,
that conflicts with names from GLib type.

Also, although the case where GLib type and value_infos disagree is now
forbidden by an assert, reorder the statements in _nm_utils_enum_from_str_full()
too. There is no difference in practice, but it mirros what we do in the
to-str case.
2018-05-29 16:28:09 +02:00
Thomas Haller 3021a8cf6b shared/trivial: rename local variable class
There is no real problem with using "class" in C. However, it would
be a keyword in C++. Just avoid it, and use "klass" instead.
2018-05-29 15:18:54 +02:00
Thomas Haller 3c6bd6769b shared: fix parsing aliases for flags in _nm_utils_enum_from_str_full()
Otherwise, the last alias overwrites previous values.

Fixes: b9fa0e0a19
2018-05-29 13:14:01 +02:00
Beniamino Galvani d082af6b5c n-acd: better handle interfaces going temporarily down
NM sometimes brings an interface temporarily down (for example to
change a VLAN MAC to align it to the parent interface's one). When
this happens, any recv() or send() in n-acd fails, the n-acd instance
is reset to the initial state and a DOWN event is reported to the
manager, which currently does not handle it. The result is an
inconsistent state.

There is no simple way of dealing with the DOWN event in the
manager. What we can do instead is to:

 - ignore errors during recv() because there is really nothing we can
   do, except for waiting timeouts to expire;

 - during probe, ignore errors during send() so that we don't exceed
   the probe timeout;

 - during announcement, retry after a send() error to ensure we send
   all 3 announcements.

https://bugzilla.redhat.com/show_bug.cgi?id=1578675
2018-05-29 11:18:30 +02:00