Commit graph

586 commits

Author SHA1 Message Date
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
Beniamino Galvani 2f4b3392d5 n-acd: use RFC 5227 timeout for announcements
When doing announcements, use the the timeout specified by RFC
5227. Note that timeout_multiplier might be 0.

This aligns behavior to upstream version of n-acd.
2018-05-29 11:18:30 +02:00
Thomas Haller f11bb3d93d shared: minor cleanup of nm_utils_get_start_time_for_pid() 2018-05-26 20:11:04 +02:00
Francesco Giudici 869009ab11 shared/trivial: fix typo on comment 2018-05-24 16:21:28 +02:00
Thomas Haller 7ba3f4f35b shared: add nm_utils_dbus_path_cmp() helper
At various places we sort our D-Bus paths. For example,
server sorts them before exporting them on D-Bus.

Server knows well, that a lot of these paths are build
by attaching an incrementing number as last component.
It looks nicer to sort by this number, instead of strictly
lexical with strcmp().

Note that this handles the cases correctly where paths have
different prefixes, or where they don't end with a number.
2018-05-14 17:53:03 +02:00
Thomas Haller 3b0d50475b shared: add nm_utils_dbus_path_get_last_component() helper 2018-05-14 17:53:03 +02:00
Thomas Haller bb649fc3cd shared: add nm_utf8_collate0() helper
Like g_utf8_collate(), which complains about NULL strings.
2018-05-14 17:53:03 +02:00
Thomas Haller 8d5febbb38 shared: add NM_CMP_DIRECT_STRCMP0() macro 2018-05-14 17:53:03 +02:00
Thomas Haller 9628aabc2f tests: use libnm via pygobject in tools/test-networkmanager-service.py
tools/test-networkmanager-service.py is our NetworkManager stub server.

NetworkManager uses libnm(-core) heavily, for example to decide whether
a connection verifies (nm_connection_verify()) and for normalizing
connections (nm_connection_normalize()).

If the stub server wants to mimic NetworkManager, it also must use these
function. Luckily, we already can do so, by loading libnm using python
GObject introspection.

We already correctly set GI_TYPELIB_PATH search path, so that the
correct libnm is loaded -- provided that we build with introspection
enabled.

We still need to gracefully fail, if starting the stub server fails.
That requries some extra effort. If the stub server notices that
something is missing, it shall exit with status 77. That will cause
the tests to g_test_skip().
2018-05-11 16:51:20 +02:00
Thomas Haller 11fedad544 tests: minor code cleanup of nmtst_main_loop_run() 2018-05-11 16:51:20 +02:00
Thomas Haller 34122c874e shared: add NM_PID_T_INVAL macro for invalid PIDs 2018-05-11 16:51:20 +02:00
Thomas Haller 286db5049e shared: add nm_auto_unref_gsource cleanup macro 2018-05-11 16:51:20 +02:00
Lubomir Rintel e69d386975 all: use the elvis operator wherever possible
Coccinelle:

  @@
  expression a, b;
  @@
  -a ? a : b
  +a ?: b

Applied with:

  spatch --sp-file ternary.cocci --in-place --smpl-spacing --dir .

With some manual adjustments on spots that Cocci didn't catch for
reasons unknown.

Thanks to the marvelous effort of the GNU compiler developer we can now
spare a couple of bits that could be used for more important things,
like this commit message. Standards commitees yet have to catch up.
2018-05-10 14:36:58 +02:00
Lubomir Rintel f0c1efbf42 all: add and utilize nm_utils_is_separator()
It is meant to be rather similar in nature to isblank() or
g_ascii_isspace().

Sadly, isblank() is locale dependent while g_ascii_isspace() also considers
vertical whitespace as a space. That's no good for configuration files that
are strucutured into lines, which happens to be a pretty common case.
2018-05-10 14:35:52 +02:00
Beniamino Galvani 1b5925ce88 all: remove consecutive empty lines
Normalize coding style by removing consecutive empty lines from C
sources and headers.

https://github.com/NetworkManager/NetworkManager/pull/108
2018-04-30 16:24:52 +02:00
Thomas Haller dc138da420 shared: add nm_utils_user_data_pack() and unpack helpers 2018-04-24 09:03:39 +02:00
Thomas Haller 9329844929 systemd: merge branch systemd into master 2018-04-23 13:35:52 +02:00
Thomas Haller c4dd620889 systemd: update code from upstream (2018-04-23)
This is a direct dump from systemd git.

======

SYSTEMD_DIR=../systemd
COMMIT=41d0da0f6a800b7f1d56d6d15cf90edb6c062050

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

git ls-files :/src/systemd/src/ \
             :/shared/nm-utils/siphash24.c \
             :/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_shared "src/basic/siphash24.c"
nm_copy_sd_shared "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/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-04-23 10:20:55 +02:00
Lubomir Rintel de8bf7421d n-acd: don't use a return value in deallocator
...so that its prototype is compatible with GDestroyNotify:

src/devices/nm-acd-manager.c: In function ‘destroy_address_info’:
/usr/include/glib-2.0/glib/gmem.h:120:31: error: cast between incompatible function types from ‘NAcd * (*)(NAcd *)’ {aka ‘struct NAcd * (*)(struct NAcd *)’} to ‘void (*)(void *)’ [-Werror=cast-function-type]
     GDestroyNotify _destroy = (GDestroyNotify) (destroy);                      \
                               ^
src/devices/nm-acd-manager.c:430:2: note: in expansion of macro ‘g_clear_pointer’
  g_clear_pointer (&info->acd, n_acd_free);
  ^~~~~~~~~~~~~~~

The same change was done upstream, so the subsequent subtree pull of n-acd
won't mess this up.
2018-04-23 09:50:12 +02:00
Thomas Haller bc1b15cf05 shared: move cmp functions to nm-shared-utils.c
For one, these functions are not often needed. No need to define them in the
"nm-macros-internal.h" header, which is included everywhere. Move them to
"nm-shared-utils.h", which must be explicitly included.

Also, these functions are usually not called directly, but by passing their
function pointer to a sort function or similar. There is no point in having
defined in the header file.
2018-04-19 09:36:41 +02:00
Beniamino Galvani 7ac93a03b0 build: meson: link NM against n-acd 2018-04-18 15:22:18 +02:00
Beniamino Galvani 19876b4cfe shared: drop duplicate c-list.h header
Use the one from the project just imported.
2018-04-18 15:22:14 +02:00
Beniamino Galvani 5f8737bdd5 shared: fix nmtst_main_loop_run()
If the main loop is quit before the timeout expires, we leave the
timeout source running on the main loop context. Since we usually
create the main loop using the default context, the source will fire
on the next main loop we create during the test.

Therefore, destroy the timeout source if it is still active.

Fixes: 766f31507b
2018-04-18 15:22:12 +02:00
Beniamino Galvani 8c3023d471 n-acd: use CLOCK_MONOTONIC timers on older kernels
The README states that a kernel >= 3.0 is enough, however
CLOCK_BOOTTIME is only available since kernel 3.15.

Fall back to CLOCK_MONOTONIC when CLOCK_BOOTTIME is not available.

See: https://github.com/nettools/n-acd/pull/3

Signed-off-by: Beniamino Galvani <bgalvani@redhat.com>
2018-04-18 15:22:10 +02:00
Beniamino Galvani 8a01bdc2d1 Merge commit '23cbce4bc9c70fc33d3413fc1b9a5f3303498036' as 'shared/n-acd'
Imported n-acd code with command:

  git subtree add --prefix shared/n-acd git@github.com:nettools/n-acd.git a68b55992dd7b38bdb9dbbdba4a9284ff2c2cce3 --squash

To update the library use:

  git subtree pull --prefix shared/n-acd git@github.com:nettools/n-acd.git master --squash
2018-04-18 15:21:26 +02:00
Beniamino Galvani b16b4a4362 Merge commit 'afe2594a7799d3113470c40664c6eda88b83c7e5' as 'shared/c-list'
Imported c-list code with command:

  git subtree add --prefix shared/c-list/ git@github.com:c-util/c-list.git master --squash

To update the library use:

  git subtree pull --prefix shared/c-list/ git@github.com:c-util/c-list.git master --squash
2018-04-18 15:20:40 +02:00
Beniamino Galvani 579f17cfee Merge commit '1ea09eb549dbd910ea593e01fb6f746ae20b4beb' as 'shared/c-siphash'
Imported c-siphash code with command:

  git subtree add --prefix shared/c-siphash/ git@github.com:c-util/c-siphash.git master --squash

To update the library use:

  git subtree pull --prefix shared/c-siphash/ git@github.com:c-util/c-siphash.git master --squash
2018-04-18 15:20:01 +02:00
Beniamino Galvani aca671fff0 all: replace "it's" with "its" where needed 2018-04-18 14:14:07 +02:00
Thomas Haller 56a3f3bba9 shared: add nm_utils_dbus_normalize_object_path() helper 2018-04-18 07:55:15 +02:00
Thomas Haller be9a5ab308 shared: add nm_utils_strv_sort() helper 2018-04-18 07:55:15 +02:00
Thomas Haller 458b422468 shared: add NM_CAST_STRV_*() helper macros 2018-04-18 07:55:15 +02:00
Thomas Haller e5e8f86c3d shared: move nm_utils_get_start_time_for_pid() to shared/nm-utils
We will also use it in nmcli later. It will be needed when we replace
polkit_unix_process_new_for_owner(). Which is still far down the road.
2018-04-16 16:03:14 +02:00
Beniamino Galvani 919f6b6d75 shared: use value infos in _nm_utils_enum_to_str_full 2018-04-13 17:02:55 +02:00
Thomas Haller 770015f512 shared/tests: add nmtst_assert_nonnull() macro
There is g_assert_nonnull(), however that doesn't return
the pointer. Returning the pointer can be convenient...
2018-04-09 20:16:30 +02:00
Thomas Haller 84b303217e nmtst: add nmtst_get_rand_bool() util 2018-04-09 20:16:30 +02:00
Thomas Haller 2cda3770a3 shared: add nm_pstr_hash() and nm_pstr_equal() 2018-04-06 11:51:21 +02:00
Thomas Haller 422e326cba shared: add nm_c_list_contains_entry() helper 2018-04-05 17:45:30 +02:00
Thomas Haller b2edcdc939 shared/nm-glib: add compat implementation for g_autofree
Eventually, we should replace our uses of libgsystem's gsystem-local-alloc.h
by glib's g_auto*. As a first tiny step, add a compat implementation for g_autofree,
so that we could at least go ahead and use it instead of gs_free.

https://bugzilla.gnome.org/show_bug.cgi?id=794294
2018-03-27 10:36:12 +02:00
Thomas Haller 938d9a82cf shared: add nm_utils_hash_keys_to_array() helper 2018-03-27 09:58:00 +02:00
Thomas Haller f7b2ebc87a shared: fix typecheck in NM_PTRARRAY_LEN()
Previously, NM_PTRARRAY_LEN() would not work if the pointer type is
an opaque type, which is common. For example:

  NMConnection *const*connections = ...;
2018-03-20 15:08:18 +01:00
Thomas Haller 63ca07f492 shared: add nm_clear_pointer() and implement existing nm_clear_*() based on it
Add an alternative to g_clear_pointer(). The differences are:

  - nm_clear_pointer() is more type safe as it does not cast neither the
    pointer nor the destroy function. Commonly, the types should be compatible
    and not requiring a cast. Casting in the macro eliminates some of the
    compilers type checking. For example, while
       g_clear_pointer (&priv->hash_table, g_ptr_array_unref);
    compiles, nm_clear_pointer() would prevent such an invalid use.

  - also, clear the destination pointer *before* invoking the destroy
    function. Destroy might emit signals (like weak-pointer callbacks
    of GArray clear functions). Clear the destination first, so that
    we don't leave a dangling pointer there.

  - return TRUE/FALSE depending on whether there was a pointer to clear.

I tested that redefining g_clear_pointer()/g_clear_object() with our
more typesafe nm_* variants still compiles and indicates no bugs. So
that is good. It's not really expected that turning on more static checks
would yield a large number of bugs, because generally our code is in a good
shape already. We have few such bugs, because we already turn all all warnings
and extra checks that make sense. That however is not an argument for
not introducing (and using) a more resticted implementation.
2018-03-19 15:51:17 +01:00
Thomas Haller 4cbe3eaaca shared: clear destination pointer in nm_clear_*() functions first
It's slightly more correct to first clear the pointer location
before invoking the destroy function. The destroy function might
emit other callbacks, and at a certain point the pointer becomes
dangling. Avoid this danling pointer, by first clearing the
memory, and then destroing the instance.
2018-03-19 15:50:15 +01:00
Thomas Haller 39db757e44 shared: don't validate type-string in G_VARIANT_TYPE() cast macro in production code 2018-03-12 17:44:35 +01:00
Thomas Haller b0b5cfb7f2 shared: add nm_g_variant_unref_floating() helper 2018-03-10 16:49:30 +01:00
Thomas Haller 14ffe6bc55 dbus: extend NM_DEFINE_GDBUS*() helper macros 2018-03-10 16:49:30 +01:00
Thomas Haller 23e4ef5092 systemd: merge branch systemd into master 2018-02-15 10:26:10 +01:00
Thomas Haller 4d923233f2 systemd: update code from upstream (2018-02-14)
This is a direct dump from systemd git on 2018-02-14, git commit
cac26f0bc8c8b73796fd6da862b919b1e0a969bc.

======

SYSTEMD_DIR=../systemd
COMMIT=cac26f0bc8c8b73796fd6da862b919b1e0a969bc

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

git ls-files :/src/systemd/src/ \
             :/shared/nm-utils/siphash24.c \
             :/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_shared "src/basic/siphash24.c"
nm_copy_sd_shared "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/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-02-14 17:52:02 +01:00
Thomas Haller d46de19a9a shared: add nm_steal_int() helper 2018-02-12 13:29:03 +01:00
Thomas Haller 4e5bef3951 shared: add macros to define GDBus registration info 2018-02-12 13:29:03 +01:00
Thomas Haller 7a956644d4 shared: add NM_UNCONST_PTR() and NM_UNCONST_PPTR()
Add macros that cast away the constness of a pointer, but
ensure that the type of the pointer is as expected.

Unfortunately, there is no way (AFAIK) to remove the constness of
a variable, without explicitly passing @type to the macro.
2018-02-12 13:29:03 +01:00
Lubomir Rintel ee916a1e9e all: fix -Wcast-function-type warnings
GCC 8.0's -Wcast-function-type objects casting function pointers to ones
with incompatible prototypes. Sometimes we do that on purpose though.

Notably, the g_source_set_callback()'s func argument can point to functions
of various prototypes. Also, libnm-glib/nm-remote-connection is perhaps
just not worth reworking, that would just be a waste of time.

A cast to void(*)(void) avoids the GCC warning, let's use it.
2018-02-08 17:11:46 +01:00
Lubomir Rintel 411e72b3c9 shared/utils/dedup-multi: make nm_dedup_multi_obj_unref() return void
This makes its prototype compatible with GDestroyNotify so that GCC 8.0
won't warn.

The return value is not used anywhere and the unref() functions typically
don't return any.
2018-02-08 17:11:46 +01:00
Lubomir Rintel fc4552d391 shared/utils: don't warn of unknown warning disables with clang
When pushing a warning disable with clang, always disable
-Wunknown-warning-option first -- it might be that clang wouldn't warn
of what we're trying to disable because it doesn't recognize it in the
first place. That is entierely okay.

With clang-5.0.0:

    CC       libnm/tests/libnm_tests_test_secret_agent-test-secret-agent.o
  In file included from libnm/tests/test-secret-agent.c:29:
  In file included from ./shared/nm-test-libnm-utils.h:23:
  ./shared/nm-utils/nm-test-utils.h:432:3: error: unknown warning group '-Wunused-but-set-variable', ignored [-Werror,-Wunknown-warning-option]
                  NM_PRAGMA_WARNING_DISABLE("-Wunused-but-set-variable")
                  ^
  ./shared/nm-utils/nm-macros-internal.h:223:9: note: expanded from macro 'NM_PRAGMA_WARNING_DISABLE'
          _Pragma(_NM_PRAGMA_WARNING_DO(warning))
          ^
  <scratch space>:204:25: note: expanded from here
   GCC diagnostic ignored "-Wunused-but-set-variable"
                          ^
  1 error generated.
2018-01-24 09:53:38 +01:00
Thomas Haller 4da1480cfd version: rename macro NM_VERSION_CUR_STABLE to NM_API_VERSION
NM_API_VERSION is a better name. It's not the current stable
version, but the version number of the API which the current
NM_VERSION provides. In practice, NM_API_VERSION is either identical
to NM_VERSION (in case of a release) or NM_VERSION is a development
version leading up the the upcoming NM_API_VERSION.

For example, with the new name the check

  #if NM_VERSION != NM_API_VERSION
  # warning this is an development version
  #endif

makes more sense.
2018-01-23 10:54:11 +01:00
Thomas Haller 165fe65eef version: calculate NM_VERSION_CUR_STABLE based on the version numbers
We have a well defined versioning scheme and a defined way how
the version number indicates a stable version. We can simply
calculate NM_VERSION_CUR_STABLE based on the version numbers.
2018-01-23 10:50:34 +01:00
Thomas Haller 9ef17869b5 version: drop NM_VERSION_MAX_ALLOWED defines for internal build
It already defaults to the right value. We only need to define
NM_VERSION_MIN_REQUIRED, so that parts of our internal build
can make use of deprecated API.
2018-01-23 10:50:34 +01:00
Thomas Haller 8a040c6883 version: combine NM_VERSION_CUR_STABLE and NM_VERSION_NEXT_STABLE
We don't need to have two version defines "CUR" and "NEXT".

The main purpose of these macros (if not their only), is to
make NM_AVAILABLE_IN_* and NM_DEPRECATED_IN_* macros work.

1) At the precise commit of a release, "CUR" and "NEXT" must be identical,
because whenever the user configures NM_VERSION_MIN_REQUIRED and
NM_VERSION_MAX_ALLOWED, then they both compare against the current
version, at which point "CUR" == "NEXT".

2) Every other commit aside the release, is a development version that leads
up the the next coming release. But as far as versioning is concerned, such
a development version should be treated like that future release. It's unstable
API and it may or may not be close to later API of the release. But
we shall treat it as that version. Hence, also in this case, we want to
set both "NM_VERSION_CUR_STABLE" and again NEXT to the future version.

This makes NM_VERSION_NEXT_STABLE redundant.

Previously, the separation between current and next version would for
example allow that NM_VERSION_CUR_STABLE is the previously release
stable API, and NM_VERSION_NEXT_STABLE is the version of the next upcoming
stable API. So, we could allow "examples" to make use of development
API, but other(?) internal code still restrict to unstable API. But it's
unclear which other code would want to avoid current development.

Also, the points 1) and 2) were badly understood. Note that for our
previousy releases, we usually didn't bump the macros at the stable
release (and if we did, we didn't set them to be the same). While using
two macros might be more powerful, it is hard to grok and easy to
forget to bump the macros a the right time. One macro shall suffice.

All this also means, that *immediately* after making a new release, we shall
bump the version number in `configure.ac` and "NM_VERSION_CUR_STABLE".
2018-01-23 10:50:34 +01:00
Thomas Haller dd2d55ca57 tests: fix test setup after requiring glib 2.40
Also, g_test_expect_message() no longer needs to suppress
deprecation warnings.

Fixes: 8a46b25cfa
2018-01-22 08:31:00 +01:00
Lubomir Rintel 8a46b25cfa all: require glib 2.40
RHEL 7.1 and Ubuntu 14.04 LTS both have this.

https://bugzilla.gnome.org/show_bug.cgi?id=792323
2018-01-18 11:45:36 +01:00
Lubomir Rintel 1443bf77e8 all: require jansson 2.5
It was released Sep 19 2013 and Ubuntu 14.04 LTS (trusty) ships it.

https://bugzilla.gnome.org/show_bug.cgi?id=792323
2018-01-18 11:45:24 +01:00
Iñigo Martínez 5e16bcf268 meson: Improve dependency system
Some targets are missing dependencies on some generated sources in
the meson port. These makes the build to fail due to missing source
files on a highly parallelized build.

These dependencies have been resolved by taking advantage of meson's
internal dependencies which can be used to pass source files,
include directories, libraries and compiler flags.

One of such internal dependencies called `core_dep` was already in
use. However, in order to avoid any confusion with another new
internal dependency called `nm_core_dep`, which is used to include
directories and source files from the `libnm-core` directory, the
`core_dep` dependency has been renamed to `nm_dep`.

These changes have allowed minimizing the build details which are
inherited by using those dependencies. The parallelized build has
also been improved.
2018-01-10 12:20:17 +01:00
Thomas Haller 901aa0315b shared: add nm_cmp_int2ptr_p_with_data() helper
A cmp() implementation, for sorting an array with pointers, where each
pointer is an inteter according to GPOINTER_TO_INT().

That cames for example handy, if you have a GHashTable with keys
GINT_TO_POINTER(). Then you get the list of keys via
g_hash_table_get_keys_as_array() and want to sort them.
2018-01-09 14:24:54 +01:00
Thomas Haller 2aad517b0b shared: add NMCListElem
Sometimes, we want to use CList to track a simple data item. But contrary
to GList/GSList, we need to define a structure to hold the data pointer
and the CList member.

Add a generic NMCListElem type that can be used for such simple uses.

Before you ask: why not use GList/GSList? Because even simple operations
like g_list_append() is O(n), which kinda defeats the purpose of having
a doubly linked list.

This code is added to a new header file nm-c-list.h, the reason is that
there is no other good place:
  - "nm-utils/c-list.h" is a clone of upstream, it should not deviate.
  - "nm-utils/c-list-util.h" contains our utils functions for c-list.h
    but should be plain C, independent of glib.
  - "nm-utils/nm-shared-utils.h" contains our glib related utilities,
    but it should not drag in "c-list.h".
So, "nm-c-list.h" is a utility libray that extends "c-list.h" and
requires glib.
2018-01-09 14:24:53 +01:00
Thomas Haller 66b80bd652 tests: add NMTST_EXPECT*() macros
Will be used next...
2018-01-08 12:38:53 +01:00
Thomas Haller 22ef6a507a build: refine the NETWORKMANAGER_COMPILATION define
Note that:

 - we compile some source files multiple times. Most notably those
   under "shared/".

 - we include a default header "shared/nm-default.h" in every source
   file. This header is supposed to setup a common environment by defining
   and including parts that are commonly used. As we always include the
   same header, the header must behave differently depending
   one whether the compilation is for libnm-core, NetworkManager or
   libnm-glib. E.g. it must include <glib/gi18n.h> or <glib/gi18n-lib.h>
   depending on whether we compile a library or an application.

For that, the source files need the NETWORKMANAGER_COMPILATION #define
to behave accordingly.

Extend the define to be composed of flags. These flags are all named
NM_NETWORKMANAGER_COMPILATION_WITH_*, they indicate which part of the
build are available. E.g. when building libnm-core.la itself, then
WITH_LIBNM_CORE, WITH_LIBNM_CORE_INTERNAL, and WITH_LIBNM_CORE_PRIVATE
are available. When building NetworkManager, WITH_LIBNM_CORE_PRIVATE
is not available but the internal parts are still accessible. When
building nmcli, only WITH_LIBNM_CORE (the public part) is available.
This granularily controls the build.
2018-01-08 12:38:53 +01:00
Thomas Haller 916f53ac24 shared: implement c_list_sort() as non-recursive merge-sort
This is still the very same approach (in the way the array is split
and how elements are compared). The only difference is that the
recursive implementation is replaced by a non-recursive one.

It's (still) stable, top-down merge-sort.

The non-recursive implementation better, because it avoids the overhead
of the function call to recurse.
2018-01-03 16:41:47 +01:00
Thomas Haller feeb70ef89 shared: split helper functions out of c_list_sort()
Just to make it clearer what happens.

The compiler can (and possibly will) inline these
static functions just fine.
2018-01-03 16:02:13 +01:00
Thomas Haller 8342a66cb6 shared/compat: minor refactoring of compat code
Don't cache the entire GPtrArray, just the plain strv.
Also, use parentheses for sizeof().
2017-12-22 15:53:22 +01:00
Jan Alexander Steffens (heftig) 76207194d1 shared/compat: Fix memory handling of nm_setting_vpn_get_*_keys (v2)
The compat implementations return a (transfer none) strv instead of a
(transfer container) one. This has caused double frees in nm-applet:
https://bugs.archlinux.org/task/56772

We still need to copy the keys because nm_setting_vpn_foreach_* provides
us with copies that are freed after the iteration.

Fix this by handing out a duplicate of the array.

Fixes: 272439cb20

https://mail.gnome.org/archives/networkmanager-list/2017-December/msg00070.html
2017-12-22 15:53:05 +01:00
Jan Alexander Steffens (heftig) 64fcfc62bb Revert "shared/compat: fix memory handling of nm_setting_vpn_get_*_keys"
This reverts commit 8ac8c01162.

The fix was bad because the keys do not come from NMSettingVpn's hash
table but are copies that are freed by nm_setting_vpn_foreach_* before
it returns.

https://mail.gnome.org/archives/networkmanager-list/2017-December/msg00069.html
2017-12-22 15:52:41 +01:00
Jan Alexander Steffens (heftig) 8ac8c01162 shared/compat: fix memory handling of nm_setting_vpn_get_*_keys
The compat implementations return a (transfer none) strv instead of a
(transfer container) one. This has caused double frees in nm-applet:
https://bugs.archlinux.org/task/56772

Don't copy the keys and don't free the container later.

[thaller@redhat.com: patch adjusted to avoid compiler warning]

Fixes: 272439cb20
2017-12-21 09:51:10 +01:00
Lubomir Rintel 6672c5e92e all: get rid of a handful of unused-but-set variables 2017-12-18 13:29:32 +01:00
Thomas Haller d5c212b145 shared: add nm_utils_strv_make_deep_copied() helper
At several places we create strv arrays where the
strings themself are not deep-copied.

This helper function iterates over such an "const char **"
array, clones the strings, and updates the strv array
inplace to be a "char **" strv array.

This helper function is to reduce code duplication.
2017-12-18 12:10:11 +01:00
Thomas Haller fe7b4641d6 shared: add nm_utils_strdict_get_keys() helper
At various places we get the (string) keys of a GHashTable.
Add a helper function that does that, including an argument
for optional sorting.

The helper function is there to get reduce code duplication.
2017-12-18 11:56:54 +01:00
Thomas Haller 974501fdcf shared: add static assert for nm_g_slice_free_fcn() argument 2017-12-15 11:48:38 +01:00
Iñigo Martínez 03637ad8b5 build: add initial support for meson build system
meson is a build system focused on speed an ease of use, which
helps speeding up the software development. This patch adds meson
support along autotools.

[thaller@redhat.com: rebased patch and adjusted for iwd support]

https://mail.gnome.org/archives/networkmanager-list/2017-December/msg00022.html
2017-12-13 15:48:50 +01:00
Thomas Haller 8c0dfd7188 systemd: merge branch systemd into master
Systemd instroduces a macro _fallthrough_, see
https://github.com/systemd/systemd/pull/7389.
However, it does not yet seem conclusive how to
handle this properly in ever situation.

While shared/nm-utils/siphash24.c makes use of
the new macro, don't do that in our fork. siphash24.h
does not include all systemd headers, hence _fallthrough_
is not defined. We could re-implement it as _nm_fallthrough,
but given the open questions, that doesn't seem the
2017-12-13 10:41:18 +01:00
Thomas Haller 2fb7479e82 macros: add _nm_fallthrough macro
Systemd introduced a _fallthrough_ macro in
https://github.com/systemd/systemd/pull/7389.

There might still be some issue with it, but as
I am going to re-import the latest systemd code,
we get them too.

We need it, because "shared/nm-utils/siphash24.c"
will use it too, and that source file does not include
the other systemd macros. So, we will need to re-define
it.
2017-12-13 10:41:01 +01:00
Thomas Haller ac29b8cf8a systemd: update code from upstream (2017-12-13)
This is a direct dump from systemd git on 2017-12-13, git commit
18a121f9b462e2241c4a590f0a47f5351cd47e0f.

======

SYSTEMD_DIR=../systemd
COMMIT=18a121f9b462e2241c4a590f0a47f5351cd47e0f

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

git ls-files :/src/systemd/src/ \
             :/shared/nm-utils/siphash24.c \
             :/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_shared "src/basic/siphash24.c"
nm_copy_sd_shared "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/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"
2017-12-13 09:09:50 +01:00
Lubomir Rintel 92f8f30d47 clients: add tc qdisc support
What works:

  nmcli c add con-name dum0 ifname dum0 type dummy \
      tc.qdiscs 'ingress, root pfifo_fast'
  nmcli c modify dum0 -tc.qdiscs 'root pfifo_fast'
  nmcli c modify dum0 +tc.qdiscs 'root handle 666: fq_codel'
2017-12-11 10:52:23 +01:00
Thomas Haller 097bd72e2e shared: add nm_utils_named_values_from_str_dict()
NMUtilsNamedValue's purpose is precisely to create
a list and sort by entires.

Add nm_utils_named_values_from_str_dict() as helper
function to do that.
2017-12-08 18:47:37 +01:00
Thomas Haller 7ca601d529 shared: propagate type for g_object_ref()
See related bug https://bugzilla.gnome.org/show_bug.cgi?id=790697
2017-12-06 10:34:28 +01:00
Thomas Haller 011a609bd4 shared/trivial: fix type on comment 2017-12-05 19:57:25 +01:00
Thomas Haller de92e88161 shared: fix nm_utils_strsplit_set() to increase buffer size exponentially 2017-11-29 16:26:28 +01:00
Thomas Haller b6efac9ec2 c-list: re-import latest version of c-list.h from upstream
Most notably, it renames
  c_list_unlink_init() -> c_list_unlink()
  c_list_unlink() -> c_list_unlink_stale()

  $ sed -e 's/\<c_list_unlink\>/c_list_unlink_old/g' \
        -e 's/\<c_list_unlink_init\>/c_list_unlink/g' \
        -e 's/\<c_list_unlink_old\>/c_list_unlink_stale/g' \
        $(git grep -l c_list_unlink -- ':(exclude)shared/nm-utils/c-list.h') \
        -i
2017-11-28 11:26:39 +01:00
Thomas Haller 5befde7d7d shared: add nm_g_object_set_property_*() helper 2017-11-23 18:43:48 +01:00
Thomas Haller 272439cb20 shared/compat: add compat for nm_setting_vpn_get_data_keys() and nm_setting_vpn_get_secret_keys() 2017-11-23 14:44:25 +01:00
Thomas Haller 1cb147663b shared: add nm-utils/nm-compat.h 2017-11-23 14:44:25 +01:00
Thomas Haller 48960ba8da shared: add nm_construct_name_a() macro 2017-11-23 14:44:24 +01:00
Thomas Haller 3adce12898 shared: add NMUtilsNamedEntry
It is common to have some data indexed by a name.
If you want to sort a list of such data, you would
have to re-implement your own compare function each time.

Instead, add NMUtilsNamedEntry which as first field has
the name. So, you can create your own struct:

  struct my_data {
    const char *name;
    ... other fields
  }

and compare them with with nm_utils_named_entry_cmp().

For convenience, add another struct NMUtilsNamedValue, which
has only one data field, a pointer.
2017-11-21 13:48:48 +01:00
Thomas Haller b8c87a7ceb test: conditionally enable assertion macros depending on libnm version
The test utility library "nm-utils/nm-test-utils.h" is also used
by applet and VPN plugins. They may not yet use 1.10 API.
2017-11-20 19:52:59 +01:00
Thomas Haller 97f8d21674 shared: add nm_auto_free_secret macro 2017-11-20 11:37:24 +01:00
Thomas Haller ac95f7da0b build: include "siphash24.c" source in "nm-hash-utils.c"
This allows the compiler to inline the siphash24*() functions
for nm_hash_ptr() and nm_hash_str() (even without LTO).

This of course only applies to nm_hash_ptr() and nm_hash_str(),
which are implemented in "nm-hash-utils.c" itself. All other
nm_hash_*() functions are inline functions in "nm-hash-utils.h",
and thus these functions can be inlined instead. That is, in
other cases, the nm_hash_*() function instead can be inlined.
For nm_hash_ptr() and nm_hash_str() instead we want to inline the
siphash24*() functions.

So, no longer compile "siphash24.c" directly. Instead, only
build "nm-hash-utils.c" which internally #include "siphash24.c".
2017-11-16 11:49:52 +01:00
Thomas Haller 3ee8de20c4 all: include "nm-utils/nm-hash-utils.h" by default
Next we will use siphash24() instead of the glib version g_direct_hash() or
g_str_hash(). Hence, the "nm-utils/nm-hash-utils.h" header becomes very
fundamental and will be needed basically everywhere.

Instead of requiring the users to include them, let it be included via
"nm-default.h" header.
2017-11-16 11:49:51 +01:00
Thomas Haller ecd106101b shared: use siphash24() for nm_hash_ptr()
siphash24() mixes the bits much better then our naive xor.
Don't bypass siphash24(). We supposedly use it for the
better hashing properties, so use it also for pointers.
2017-11-16 11:49:51 +01:00
Thomas Haller c3d98a3df6 shared: optimize nm_hash_str() for NULL to not use siphash24() 2017-11-16 11:49:51 +01:00
Thomas Haller 3751cceeec shared: inline fast-path for hash _get_hash_key() 2017-11-16 11:49:51 +01:00
Thomas Haller 6fbd280b35 shared: add nm_hash_static() to get a static hash key
When using siphash24(), the hash value depends on the hashed input
and the key from _get_hash_key(). If the input is static, so is also
the result of siphash24(), albeit the bits are scrabbled more.

Add a nm_hash_static() to get such a static key, but without actually
doing siphash24(). The static key is also xored with a static_seed.

For that, also mangle the first byte of the hash key using siphash24()
itself. That is, because nm_hash_static() only uses the first guint of the
random key. Hence, we want that this first guint has all the entropy
of the entire key. We use siphash24() itself, to mangle all bits
of the 16 byte key into the first guint.
2017-11-16 11:48:05 +01:00
Thomas Haller 5b29c2e5b9 all: use nm_close() instead of close() 2017-11-14 15:10:42 +01:00
Thomas Haller f4780f85ae shared: always call close() from nm_close() wrapper
The nm_close() wrapper should behave exactly the same as calling
close() directly. This is well known, documented behavior.

The only addition on top of that, should be the nm_assert() to catch
double-closing.

Prevously, when passing a negative file descriptor, we wouldn't properly
set errno. Also, the call would not show up in strace, which it should
(at least, if libc's close actually makes the syscall).

I would argue, that passing a negative file descriptor is a bug already
and we should never do that. Maybe we should even assert non-negative
fds. I don't do that now, because I am not sufficiently confident.
Anyway, the change should have not practical effect, because we
shouldn't actually pass negative fds already.
2017-11-14 15:09:26 +01:00
Thomas Haller a9d1f5e543 shared: add nm_ip_addr_set() helper 2017-11-13 11:35:44 +01:00
Thomas Haller 632e8ac885 shared/trivial: move code 2017-11-13 11:35:44 +01:00
Thomas Haller 557d83bf2d build: detect compiler features _Generic() and __auto_type in configure script
There is still a fallback detection in "shared/nm-utils/nm-macros-internal.h",
so that VPN-plugins and applet don't need to bother about adding these
configure checks.
2017-11-13 11:35:44 +01:00
Thomas Haller bdfdabea51 shared: propagate constness in _NM_GET_PRIVATE_PTR()
The _NM_GET_PRIVATE() macro already preserved and propagated
the constness of @self to the resulting private pointer.

_NM_GET_PRIVATE_PTR() didn't do that. Extend the macro,
to make that possible.
2017-11-13 11:35:44 +01:00
Thomas Haller 03efc9e2c9 shared: fix detection of _Generic() support 2017-11-13 11:35:44 +01:00
Francesco Giudici b6c0498b04 shared: add json_boolean_value support in jansson.h
Released in jansson version 2.7, added for compatibility with older
jannson verions.
2017-11-09 17:56:15 +01:00
Thomas Haller 595aaf0f3e all: update compatiblity for older libjansson versions
- nm-ovsdb.c uses json_load_callback(), which is jansson v2.4.
  Hence, it cannot build the OVS plugin in our Travis-CI, which is
  still on Ubuntu Precise. Disable building the plugin in travis and
  add a compiler warning when building against an older version.

- since jansson v2.3, there is json_object_key_to_iter() to implement
  the for-each macros. Use it in json_object_foreach_safe() when
  available.
2017-11-09 17:34:39 +01:00
Thomas Haller 11b241eb1c shared: add jansson.h compatibility and utils header 2017-11-09 17:32:22 +01:00
Francesco Giudici 85cc5db7a4 shared: trivial: add space before comment close 2017-11-09 17:17:00 +01:00
Thomas Haller b339a2742a shared: make NM_CONSTCAST() macro variadic
We need to pass more alias-types. Instead of having numbered
versions, use variadic number of macro arguments.

Also, fix build failure with old compiler:

  In file included from src/nm-ip6-config.c:24:
  ./src/nm-ip6-config.h:44:29: error: controlling expression type 'typeof (ipconf_iter->current->obj)' (aka 'const void *const') not compatible with any generic association type
                  *out_address = has_next ? NMP_OBJECT_CAST_IP6_ADDRESS (ipconf_iter->current->obj) : NULL;
                                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Fixes: b1810d7a68
2017-11-09 14:15:34 +01:00
Thomas Haller b1810d7a68 shared: rework _NM_GET_PRIVATE() to use _Generic()
_NM_GET_PRIVATE() used typeof() to propagate constness of the @self
pointer. However, that means, it could only be used with a self pointer
of the exact type. That means, you explicitly had to cast from (GObject *)
or from (void *).
The requirement is cumbersome, and often led us to either create @self
pointer we didn't need:

    NMDeviceVlan *self = NM_DEVICE_VLAN (device);
    NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE (self);

or casting:

    NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE ((NMDevice *) device);

In both cases we forcefully cast the source variable, loosing help from
the compiler to detect a bug.

For "nm-linux-platform.c", instead we commonly have a pointer of type
NMPlatform. Hence, we always forcefully cast the type via _NM_GET_PRIVATE_VOID().

Rework the macro to use _Generic(). If compiler supports _Generic(), then we
will get all compile time checks as desired. If the compiler doesn't support
_Generic(), it will still work. You don't get the compile-time checking of course,
but you'd notice that something is wrong once you build with a suitable
compiler.
2017-11-09 10:57:13 +01:00
Beniamino Galvani cec215147a shared: update version macros for 1.11
Fixes: c2c44d16f4
2017-11-03 17:05:04 +01:00
Thomas Haller 93315d01da tests: add nmtst_assert_connection_has_settings() helper 2017-10-30 21:46:55 +01:00
Lubomir Rintel aec8d36b3e clients: add support for ovs-bridge setting 2017-10-30 17:40:09 +01:00
Lubomir Rintel 6f73b4608a clients: add support for ovs-port setting 2017-10-30 17:40:09 +01:00
Lubomir Rintel 6dcd54b0de clients: add support for ovs-interface setting 2017-10-30 17:40:09 +01:00
Lubomir Rintel e7ab81098a clients: add support for ovs-patch setting 2017-10-30 17:40:09 +01:00
Thomas Haller de65d3da91 shared: fix nm_steal_fd() for handling zero file descriptor
Zero is a valid file descriptor.

Fixes: 956b3e8bd5
2017-10-30 11:44:37 +01:00
Beniamino Galvani ef52122469 shared: fix compilation on 32-bit archictectures
shared/nm-utils/nm-hash-utils.c:110:3: error: right shift count >= width of type [-Werror]
   h = h ^ ((guint) (((uintptr_t) ptr) >> 32)) ^ ((guint) ((uintptr_t) ptr));
   ^

Even if the branch is not reached on 32-bit architectures, the
compiler still emits a warning for the 32-bit right shift.

Fixes: ee76b0979f
2017-10-26 15:13:40 +02:00
Thomas Haller 956b3e8bd5 shared: add nm_steal_fd() helper function 2017-10-19 15:49:58 +02:00
Beniamino Galvani 1bc1809e11 shared: introduce nm_close()
nm_close() is like close(), but throws an assertion if the input fd is
>=0 and invalid. Passing an invalid (i.e. already closed) fd to
close() is a programming error with potentially catastrophic effects,
as another thread may reuse the closed fd.
2017-10-19 15:49:50 +02:00
Thomas Haller 268e0cd22e systemd: update code from upstream (2017-10-11)
This is a direct dump from systemd git on 2017-10-11, git commit
0da812036f6fd60a7b5477fafb2eead9e98f4c78.

======

SYSTEMD_DIR=../systemd
COMMIT=0da812036f6fd60a7b5477fafb2eead9e98f4c78

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

git ls-files :/src/systemd/src/ \
             :/shared/nm-utils/siphash24.c \
             :/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_shared "src/basic/siphash24.c"
nm_copy_sd_shared "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/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"
2017-10-18 13:38:03 +02:00
Thomas Haller cfe8546df9 all: extend hash functions with an NMHashState argument
We often want to cascade hashing, meaning, to combine the
outcome of various hash functions in a larger hash.

Instead of having each hash function return a guint hash value,
accept a hash state argument. This saves the overhead of initializing
and completing the intermediate hash states.
It also avoids loosing entropy when we reduce the larger hash state
into the intermediate guint hash value.
2017-10-18 13:29:22 +02:00
Thomas Haller 2f56de7492 all: add helper functions for nm_hash_update*()
By using a macro, we don't cast all the types to guint. Instead,
we use their native types directly. Hence, we don't need
nm_hash_update_uint64() nor nm_hash_update_ptr().
Also, for types smaller then guint like char, we save hashing
the all zero bytes.
2017-10-18 13:29:22 +02:00
Thomas Haller ee76b0979f all: use siphash24 for hashing
siphash24() is wildly used by projects nowadays.

It's certainly slower then our djb hashing that we used before.
But quite likely it's fast enough for us, given how wildly it is
used. I think it would be hard to profile NetworkManager to show
that the performance of hash tables is the issue, be it with
djb or siphash24.

Certainly with siphash24() it's much harder to exploit the hashing
algorithm to cause worst case hash operations (provided that the
seed is kept private). Does this better resistance against a denial
of service matter for us? Probably not, but let's better be safe then
sorry.

Note that systemd's implementation uses a different seed for each hash
table (at least, after the hash table grows to a certain size).
We don't do that and use only one global seed.
2017-10-18 13:27:02 +02:00
Thomas Haller 0e9e35e309 all: refactor hashing by introducing NMHashState
The privious NM_HASH_* macros directly operated on a guint value
and were thus close to the actual implementation.

Replace them by adding a NMHashState struct and accessors to
update the hash state. This hides the implementation better
and would allow us to carry more state. For example, we could
switch to siphash24() transparently.

For now, we still do a form basically djb2 hashing, albeit with
differing start seed.

Also add nm_hash_str() and nm_str_hash():

- nm_hash_str() is our own string hashing implementation

- nm_str_hash() is our own string implementation, but with a
  GHashFunc signature, suitable to pass it to g_hash_table_new().
  Also, it has this name in order to remind you of g_str_hash(),
  which it is replacing.
2017-10-18 13:05:00 +02:00
Thomas Haller 281d2d9fad shared: split random and hash utils
"nm-utils/nm-shared-utils.h" shall contain utility function without other
dependencies. It is intended to be used by other projects as-is.

nm_utils_random_bytes() requires getrandom() and a HAVE_GETRANDOM configure
check. That makes it more cumbersome to re-use "nm-shared-utils.h", in
cases where you don't care about nm_utils_random_bytes().

Split nm_utils_random_bytes() out to a separate file.

Same for hash utils, which depend on nm_utils_random_bytes(). Also, hash
utils will eventually be extended to use siphash24.
2017-10-17 20:02:59 +02:00
Thomas Haller acbab884ee shared: add _NM_ENSURE_TYPE() macro 2017-10-17 20:02:59 +02:00
Thomas Haller bdb8e65434 shared: add _nm_align() and _nm_alignof() macros 2017-10-17 20:02:59 +02:00
Thomas Haller c978b9dfe5 core: randomize hash seed with a global seed
This makes hashing non-deterministic with the aim to
make it harder to exploit hash collisions.

Non-deterministic also means that for unit testing
we will get different values on each run. But since we
shall never assign any meaning to these hash values
nor rely on them being stable between restarts (or
upgrades), that doesn't hurt.
2017-10-13 12:47:55 +02:00
Thomas Haller 4a2798434e core: introduce NM_HASH_INIT() to initialize hash seed
Introduce a NM_HASH_INIT() function. It makes the places
where we initialize a hash with a certain seed visually clear.

Also, move them from "shared/nm-utils/nm-shared-utils.h" to
"shared/nm-utils/nm-macros-internal.h". We might want to
have NM_HASH_INIT() non-inline (hence, define it in the
source file).
2017-10-13 12:47:55 +02:00
Thomas Haller b01a453ca2 core: add nm_utils_random_bytes() and use getrandom()
Add a new function nm_utils_random_bytes().

This function now preferably uses getrandom() syscall if it is
available.

As fallback, it always tries to fill the buffer from /dev/urandom.
If it cannot, as last fallback it uses GRand, which cannot fail.
Hence, the function always sets some (pseudo) random bytes.

It also returns FALSE if the obtained bytes are possibly not good
randomness.
2017-10-13 12:47:55 +02:00
Thomas Haller 93ea7a5905 shared: move nm_utils_fd_*() from src/ to shared/nm-utils/
The functions are general purpose and independent from NetworkManager core.
Move them to "shared/nm-utils/" so they can be used independently.
2017-10-13 12:47:55 +02:00
Thomas Haller 373684fdc0 shared: add _nm_thread_local macro
Copied and adjusted from systemd.
2017-10-13 12:47:55 +02:00
Beniamino Galvani d554f535af shared: fix gtk-doc build warning
Fixes the following:

 shared/nm-utils/nm-shared-utils.c:136: Warning: NetworkManager: GTK-Doc comment block end token "*/" should not be preceded by comment text:
 * Returns: the input buffer with the quoted string. */
2017-10-13 12:10:02 +02:00
Thomas Haller 147394687e shared: add nm_utils_addr_family_to_size() 2017-10-09 22:05:35 +02:00
Thomas Haller 6a3005ea72 shared: add nm_strstrip_avoid_copy() 2017-10-09 22:05:35 +02:00
Thomas Haller a31f1706e5 shared: guarantee output argument of nm_utils_parse_inaddr_bin() is only set on success
The documentation of inet_pton() is not clear about what happens
when parsing fails. Guarantee that the output is only modified
on success.
2017-10-06 11:08:39 +02:00
Thomas Haller a0aec7efea shared: pass addr_family as first argument to nm_utils_parse_inaddr*()
The addr_family should be the first argument. It mirrors inet_pton()
and is just nicer.

Also, rename the argument from "family" to "addr_family".
2017-10-06 11:08:39 +02:00
Thomas Haller f1009bcde3 shared: add nm_strquote() util
We already have nm_strquote_a(). That is useful, but uses alloca(), hence it
is ill suited to be called from a macro, inside a loop, or from a function
that should be inlined.

Instead, add nm_strquote() that has the same purpose but writes to a provided
string buffer.
2017-10-06 11:08:39 +02:00
Thomas Haller 1348b7c83a shared: move utils NM_UTILS_ENUM2STR*, NM_UTILS_FLAGS2STR*, and nm_utils_to_string_buffer_init()
These are just simple utility functions, not tied to NetworkManager
core. Move them to shared/nm-utils, so that they may be reused
otherwise.
2017-10-05 11:50:31 +02:00
Thomas Haller c17e0f7197 shared: add nm_utils_addr_family_to_char() 2017-10-02 13:50:56 +02:00
Thomas Haller f7616eee1e shared: move nm_dedup_multi_obj_ref() to header as inline
nm_dedup_multi_obj_ref() is a trivial function, that only uses the field
which is already declared in the same header file. Move it to the header
so that it can be inlined (without LTO).
2017-09-26 19:31:17 +02:00
Thomas Haller daa4604c12 shared: add nm_utils_strsplit_set() helper
A replacement for g_strsplit_set(). While g_strsplit_set()
does (n+1) malloc and n slice allocations, this needs
roughtly (O(log(n))) mallocs.

Another difference from g_strsplit_set() is that this function
treats multiple delimiters as one (and thus never returns empty
words). While I can see that sometimes you may want to keep empty
words (like parsing a CSV file and preserve empty cells), we usually
use this function for splitting user input. In such case, we want
to treat multiple delimiters as one.
2017-09-18 20:14:09 +02:00
Thomas Haller f6a727685e shared: add nm_utils_parse_inaddr_prefix_bin() helper 2017-09-18 20:14:09 +02:00
Thomas Haller dd0617547d shared: add NMIPAddr struct 2017-09-18 20:14:09 +02:00
Thomas Haller 569b443233 shared: add nm-glib.h compat implementation for g_variant_new_printf() 2017-09-18 20:14:09 +02:00
Thomas Haller 2cc1813340 core: workaround configuring IPv6 routes with "src" (RTA_PREFSRC)
Kernel does not allow to add IPv6 routes with "src", as long as the
corresponding address is still tentative (related bug rh#1457196).

The workaround for this is cumbersome. First, when we fail to add such a
route with "pref_src", we guess that it happend due to this issue. In
that case, nm_ip6_config_commit() returns the list of routes that could
not be added for the moment (but hopefully can be added later).

We track this list in NMDevice, and keep trying to merge the routes
back into ip6_config. In order to not try indefinitely, keep track of a
timestamp when we tried to add this route for the first time.

Another uglyness is that pending tentative routes don't explicitly block
activation. In practice they may do, because for these routes we also have
an IPv6 address that is still doing DAD, so the IP configuration is
still pending due to that.

https://bugzilla.redhat.com/show_bug.cgi?id=1452684
2017-09-15 17:28:48 +02:00
Thomas Haller 959944d623 shared: add nm_g_object_ref_set() and nm_clear_g_object()
- nm_clear_g_object() is like g_clear_object() but:

  - it returns a boolean value, indicating that something was cleared.

  - it includes an nm_assert() to check that the pointer is still
    valid.

  - it uses typeof() instead of blindly casting the argument.

- nm_g_object_ref_set() combines nm_clear_g_object() and resetting
  the pointer to a new object, including taking a reference.

  - also returns a boolean, indicating whether something changed.

  - it gets the order of operations right: first it increses the
    ref-count, before unrefing the old object.

  - like nm_clear_g_object() and nm_clear_g_free() it first sets
    the destination to NULL, instead of leaving a dangling pointer
    for the duraction of the unref/free call.

- fix nm_clear_g_free() not to use a possibly dangling pointer.
  Striclty speaking, that is undefined behavior.
2017-09-08 11:05:04 +02:00
Thomas Haller 19716df23d shared: add nm_g_object_class_find_property_from_gtype() util
And relax the type for nm_auto_unref_gtypeclass macro. Like
g_type_class_unref() itself, you usually don't use it with a GTypeClass
base class, but some subtype like GObjectClass.
2017-09-07 18:10:06 +02:00
Thomas Haller 506fca65b3 tui: guess the prefix length (netmask) of private IPv4 addresses and routes based on network class
For RFC1918 private IPv4addresses, guess a better prefix length for
addresses and routes.

nmtui is an interactive program. It makes sense to be a bit smarter
about what the user probably meant.

It would be nice if nmtui would update the entry field immediately when
the cursor leaves the field, to show the guessed prefix length. However,
that is not easily possible, so lets to that another time.

For IPv6 addresses, default to /64 instead of /128.

https://bugzilla.redhat.com/show_bug.cgi?id=1474295
2017-09-05 18:44:04 +02:00
Thomas Haller b434d7d436 shared: add nm_utils_ip_is_site_local() 2017-09-05 18:44:04 +02:00
Thomas Haller 7319fdd74a shared: add _nm_utils_ip4_*() utils functions
(cherry picked from commit e9c0b1851b88cef8a0e74d9e8701e0ef548e092a)
2017-09-05 16:19:57 +02:00
Thomas Haller 4adda2b79a core: fix clearing dirty flag in _nm_ip_config_add_obj()
We rely on clearing the dirty flag. For example in nm_ip4_config_replace(),
we first mark all entries dirty, then force-append the ones we keep,
and finally remove the ones that are still dirty.

Since _nm_ip_config_add_obj() short-cuts nm_dedup_multi_index_add_full(),
it must clear the dirty flag on its own.
2017-08-31 13:13:24 +02:00
Thomas Haller d36f847e51 core: workaround compiler waring in for-each macros for NMIP4Config/NMIP6Config (again)
Compiler wouldn't recognize that the @route/@address argument is always
initialized. The right workaround seems to let the next() functions always
set the value.
2017-08-31 09:40:41 +02:00
Thomas Haller d686636bf0 core: avoid compiler warning in nm_ip_config_iter_ip4_address_for_each() macro
In file included from src/nm-ip6-config.c:24:0:
  src/nm-ip6-config.c: In function ‘nm_ip6_config_create_setting’:
  src/nm-ip6-config.c:734:62: error: the address of ‘address’ will always evaluate as ‘true’ [-Werror=address]
    nm_ip_config_iter_ip6_address_for_each (&ipconf_iter, self, &address) {
                                                                ^
  src/nm-ip6-config.h:60:17: note: in definition of macro ‘nm_ip_config_iter_ip6_address_for_each’
       for (({ if (address) { *(((const NMPlatformIP6Address **) address)) = NULL; } }), nm_ip_config_iter_ip6_address_init ((iter), (self)); \
                   ^

Fixes: 6e9aa9402a
2017-08-30 20:09:15 +02:00
Thomas Haller f0de7d347f platform: add non-exclusive routes and drop route-manager
Previously, we would add exclusive routes via netlink message flags
NLM_F_CREATE | NLM_F_REPLACE for RTM_NEWROUTE. Similar to `ip route replace`.
Using that form of RTM_NEWROUTE message, we could only add a certain
route with a certain network/plen,metric triple once. That was already
hugely inconvenient, because

 - when configuring routes, multiple (managed) interfaces may get
   conflicting routes (multihoming). Only one of the routes can be actually
   configured using `ip route replace`, so we need to track routes that are
   currently shadowed.

 - when configuring routes, we might replace externally configured
   routes on unmanaged interfaces. We should not interfere with such
   routes.

That was worked around by having NMRouteManager (and NMDefaultRouteManager).
NMRouteManager would keep a list of the routes which NetworkManager would like
to configure, even if momentarily being unable to do so due to conflicting routes.
This worked mostly well but was complicated. It involved bumping metrics to
avoid conflicts for device routes, as we might require them for gateway routes.

Drop that now. Instead, use the corresponding of `ip route append` to configure
routes. This allows NetworkManager to confiure (almost) all routes that we care.
Especially, it can configure all routes on a managed interface, without
replacing/interfering with routes on other interfaces. Hence, NMRouteManager
becomes obsolete.

It practice it is a bit more complicated because:

 - when adding an IPv4 address, kernel will automatically create a device route
   for the subnet. We should avoid that by using the IFA_F_NOPREFIXROUTE flag for
   IPv4 addresses (still to-do). But as kernel may not support that flag for IPv4
   addresses yet (and we don't require such a kernel yet), we still need functionality
   similar to nm_route_manager_ip4_route_register_device_route_purge_list().
   This functionality is now handled via nm_platform_ip4_dev_route_blacklist_set().

 - trying to configure an IPv6 route with a source address will be rejected
   by kernel as long as the address is tentative (see related bug rh#1457196).
   Preferably, NMDevice would keep the list of routes which should be configured,
   while kernel would have the list of what actually is configured. There is a
   feed-back loop where both affect each other (for example, when externally deleting
   a route, NMDevice must forget about it too). Previously, NMRouteManager would have
   the task of remembering all routes which we currently want to configure, but cannot
   due to conflicting routes.
   We get rid of that, because now we configure non-exclusive routes. We however still
   will need to remember IPv6 routes with a source address, that currently cannot be
   configured yet. Hence, we will need to keep track of routes that
   currently cannot be configured, but later may be.
   That is still not done yet, as NMRouteManager didn't handle this
   correctly either.
2017-08-24 10:48:03 +02:00
Thomas Haller 2f693fb68c shared: return deleted object from nm_dedup_multi_index_remove_obj()
For completeness of the API. remove_obj() is basically a shortcut
of nm_dedup_multi_index_lookup_obj() combined with
nm_dedup_multi_index_remove_entry(). As such, it is useful to return
the actually deleted object. Note that the lookup needle @obj is not
necessarily the same instance as the one that will be removed, it's
only an instance that compares equal according to the index's equality
operator.
2017-08-23 18:37:21 +02:00
Thomas Haller 3fc501e833 shared: indicate changes when only reordering happens during nm_dedup_multi_index_add()
The return value shall indicate whether the add-call changed anything.
Reordering shall count as a change too.

On the other hand, clearing the dirty flag of the entry does not count
as a change.
2017-08-23 18:37:21 +02:00
Thomas Haller d100ce28e0 shared: add nm_g_slice_free_fcn() util
Useful, when you need a GDestroyNotify function for g_slice_free() of
a certain type.
2017-08-23 18:37:21 +02:00
James Henstridge 4dd30b784c manager: add connectivity-check-{available,enabled} properties.
https://bugzilla.gnome.org/show_bug.cgi?id=785117
2017-08-17 22:31:47 +02:00
Thomas Haller cdd8c65799 platform: fix cache to use kernel's notion for equality of routes
Until now, NetworkManager's platform cache for routes used the quadruple
network/plen,metric,ifindex for equaliy. That is not kernel's
understanding of how routes behave. For example, with `ip route append`
you can add two IPv4 routes that only differ by their gateway. To
the previous form of platform cache, these two routes would wrongly
look identical, as the cache could not contain both routes. This also
easily leads to cache-inconsistencies.

Now that we have NM_PLATFORM_IP_ROUTE_CMP_TYPE_ID, fix the route's
compare operator to match kernel's.

Well, not entirely. Kernel understands more properties for routes then
NetworkManager. Some of these properties may also be part of the ID according
to kernel. To NetworkManager such routes would still look identical as
they only differ in a property that is not understood. This can still
cause cache-inconsistencies. The only fix here is to add support for
all these properties in NetworkManager as well. However, it's less serious,
because with this commit we support several of the more important properties.
See also the related bug rh#1337855 for kernel.

Another difficulty is that `ip route replace` and `ip route change`
changes an existing route. The replaced route has the same
NM_PLATFORM_IP_ROUTE_CMP_TYPE_WEAK_ID, but differ in the actual
NM_PLATFORM_IP_ROUTE_CMP_TYPE_ID:

    # ip -d -4 route show dev v
    # ip monitor route &
    # ip route add 192.168.5.0/24 dev v
    192.168.5.0/24 dev v scope link
    # ip route change 192.168.5.0/24 dev v scope 10
    192.168.5.0/24 dev v scope 10
    # ip -d -4 route show dev v
    unicast 192.168.5.0/24 proto boot scope 10

Note that we only got one RTM_NEWROUTE message, although from NMPCache's
point of view, a new route (with a particular ID) was added and another
route (with a different ID) was deleted. The cumbersome workaround is,
to keep an ordered list of the routes, and figure out which route was
replaced in response to an RTM_NEWROUTE. In absence of bugs, this should
work fine. However, as we only rely on events, we might wrongly
introduce a cache-inconsistancy as well. See the related bug rh#1337860.

Also drop nm_platform_ip4_route_get() and the like. The ID of routes
is complex, so it makes little sense to look up a route directly.
2017-08-12 16:04:28 +02:00
Thomas Haller 9012ae00aa shared: add nm_dedup_multi_entry_reorder() function
This allows to reorder elements in NMDedupMultiIndex.
2017-08-12 16:02:11 +02:00
Thomas Haller 3e1914e4fc platform: cleanup lookup API for objects in NMPCache 2017-08-12 16:02:11 +02:00
Thomas Haller 80e585a65d test: redirect glib logging to stdout
Default g_log() logs to stdout for INFO level and higher, but logs to stderr
for DEBUG/TRACE. That is annoying, because especially when redirecting the streams,
the messages get mixed up. Install a log handler and just print to stdout for
the tests.
2017-08-12 16:02:11 +02:00
Thomas Haller 8d03caf599 shared: cleanup NM_CMP_*() macros 2017-07-31 15:13:31 +02:00
Thomas Haller b9fd352eca shared: move NM_CMP_*() helper macros to shared header 2017-07-31 15:13:31 +02:00
Thomas Haller 4057a31017 core: simplify NMDedupMultiIter by storing CList pointer
Let next and head pointers point to the CList value, instead of
NMDedupMultiEntry.
2017-07-25 06:44:12 +02:00
Thomas Haller 22edeb5b69 core: track addresses for NMIP4Config/NMIP6Config via NMDedupMultiIndex
Reasons:

 - it adds an O(1) lookup index for accessing NMIPxConfig's addresses.
   Hence, operations like merge/intersect have now runtime O(n) instead
   of O(n^2).
   Arguably, we expect low numbers of addresses in general. For low
   numbers, the O(n^2) doesn't matter and quite likely in those cases
   the previous implementation was just fine -- maybe even faster.
   But the simple case works fine either way. It's important to scale
   well in the exceptional case.
 - the tracked objects can be shared between the various NMPI4Config,
   NMIP6Config instances with NMPlatform and everybody else.
 - the NMPObject can be treated generically, meaning it enables code to
   handle both IPv4 and IPv6, or addresses and routes. See for example
   _nm_ip_config_add_obj().
 - I want core to evolve to somewhere where we don't keep copies of
   NMPlatformIP4Address, et al. instances. Instead they shall all be
   shared. I hope this will reduce memory consumption (although tracking a
   reference consumes some memory too). Also, it shortcuts nmp_object_equal()
   when comparing the same object. Calling nmp_object_equal() on the
   identical objects would be a common case after the hash function
   pre-evaluates equality.
2017-07-25 06:44:12 +02:00
Thomas Haller 1c5d98292a c-list: add c_list_sort()
Add a stable, recursive merge sort for CList.

This could be improved by doing an iterative implementation.
The recursive implementation's stack depth is not an issue,
as it is bound by O(ln(n)). But an iterative implementation
would safe the overhead of O(n*log(n)) function calls and be
potentially faster.
2017-07-25 06:42:14 +02:00
Thomas Haller ad5f5c81ef core: shortcut equal operator for identical object reference in NMDedupMultiIndex
And get rid of the unused obj_full_equality_allows_different_class.
It's hard to grasp how to implement different object types that can compare
despite having different klasses. The idea was, that stack allocated
objects (used as lookup needles), are some small lightweight objects,
that still compare equal to the full instance. But it's unused. Drop it.
2017-07-10 21:55:00 +02:00
Thomas Haller 930da031b2 core: fix NMDedupMultiIndex's _dict_idx_entries_hash()
Don't overwrite @h.

Fixes: f9202c2ac1
2017-07-10 21:55:00 +02:00
Thomas Haller b2112ff471 platform: refactor NMPObject cast macros using _Generic()
This way, we also accept void pointers, while preserving constness.
2017-07-05 22:17:42 +02:00
Thomas Haller aeaa1b3b98 platform: refactor nm_dedup_multi_objs_to_ptr_array_head()
by moving the core functionality to "nm-dedup-multi.c".

As the ref-counting mechanism now is part of "nm-dedup-multi.c",
this works better and is reusable outside of platform.
2017-07-05 18:37:39 +02:00
Thomas Haller 28340588d9 core: remove NMDedupMultiBox object and track NMDedupMultiObj instances directly
Implement the reference counting of NMPObject as part of
NMDedupMultiObj and get rid of NMDedupMultiBox.

With this change, the NMPObject is aware in which NMDedupMultiIndex
instance it is tracked.

- this saves an additional GSlice allocation for the NMDedupMultiBox.

- it is immediately known, whether an NMPObject is tracked by a
  certain NMDedupMultiIndex or not. This saves an additional hash
  lookup.

- previously, when all idx-types cease to reference an NMDedupMultiObj
  instance, it was removed. Now, a tracked objects stays in the
  NMDedupMultiIndex until it's last reference is deleted. This possibly
  extends the lifetime of the object and we may reuse it better.

- it is no longer possible to add one object to more then one
  NMDedupMultiIndex instance. As we anyway want to have only one
  instance to deduplicate the objects, this is fine.

- the ref-counting implementation is now part of NMDedupMultiObj.
  Previously, NMDedupMultiIndex could also track objects that were
  not ref-counted. Hoever, the object anyway *must* implement the
  NMDedupMultiObj API, so this flexibility is unneeded and was not
  used.

- a downside is, that NMPObject grows by one pointer size, even if
  it isn't tracked in the NMDedupMultiIndex. But we really want to
  put all objects into the index for sharing and deduplication. So
  this downside should be acceptable. Still, code like
  nmp_object_stackinit*() needs to handle a larger object.
2017-07-05 18:37:39 +02:00
Thomas Haller 55e66cc7e6 platform: implement hash function for NMPlatformLnk types 2017-07-05 18:37:39 +02:00
Thomas Haller f9202c2ac1 shared: add NMDedupMultiIndex "nm-dedup-multi.h"
Add the NMDedupMultiIndex cache. It basically tracks
objects as doubly linked list. With the addition that
each object and the list head is indexed by a hash table.
Also, it supports tracking multiple distinct lists,
all indexed by the idx-type instance.
It also deduplicates the tracked objects and shares them.

 - the objects that can be put into the cache must be immutable
   and ref-counted. That is, the cache will deduplicate them
   and share the reference. Also, as these objects are immutable
   and ref-counted, it is safe that users outside the cache
   own them too (as long as they keep them immutable and manage
   their reference properly).

   The deduplication uses obj_id_hash_func() and obj_id_equal_func().
   These functions must cover *every* aspect of the objects when
   comparing equality. For example nm_platform_ip4_route_cmp()
   would be a function that qualifies as obj_id_equal_func().

   The cache creates references to the objects as needed and
   gives them back. This happens via obj_get_ref() and
   obj_put_ref(). Note that obj_get_ref() is free to create
   a new object, for example to convert a stack-allocated object
   to a (ref-counted) heap allocated one.

   The deduplication process creates NMDedupIndexBox instances
   which are the ref-counted entity. In principle, the objects
   themself don't need to be ref-counted as that is handled by
   the boxing instance.

 - The cache doesn't only do deduplication. It is a multi-index,
   meaning, callers add objects using a index handle NMDedupMultiIdxType.
   The NMDedupMultiIdxType instance is the access handle to lookup
   the list and objects inside the cache. Note that the idx-type
   instance may partition the objects in distinct lists.

For all operations there are cross-references and  hash table lookups.
Hence, every operation of this data structure is O(1) and the memory
overhead for an index tracking an object is constant.

The cache preserves ordering (due to linked list) and exposes the list
as public API. This allows users to iterate the list without any
additional copying of elements.
2017-07-05 14:22:10 +02:00
Thomas Haller b8bc80bcdb all: add base object type in "nm-obj.h"
Platform has it's own, simple implementation of object types:
NMPObject. Extract a base type and move it to "shared/nm-utils/nm-obj.h"
so it can be reused.

The base type is trival, but it allows us to implement other objects
which are compatible with NMPObjects. Currently there is no API for generic
NMObjBaseInst type, so compatible in this case only means, that they
can be used in the same context (see example below).
The only thing that you can do with a NMObjBaseInst is check it's
NMObjBaseClass.

Incidentally, NMObjBaseInst is also made compatible to GTypeInstance.
It means, an NMObjBaseInst is not necessarily a valid GTypeInstance (like NMPObject
is not), but it could be implemented as such.

For example, you could do:

    if (NMP_CLASS_IS_VALID ((NMPClass *) obj->klass)) {
        /* is an NMPObject */
    } else if (G_TYPE_CHECK_INSTANCE_TYPE (obj, NM_TYPE_SOMETHING)) {
        /* it a NMSometing GType */
    } else {
        /* something else? */
    }

The reason why NMPObject is not implemented as proper GTypeInstance is
because it would require us to register a GType (like
g_type_register_fundamental). However, then the NMPClass struct can
no longer be const and immutable memory. But we could.

NMObjBaseInst may or may not be a GTypeInstance. In a sense, it's
a base type of GTypeInstance and all our objects should be based
on it (optionally, they we may make them valid GTypes too).
2017-07-05 14:22:10 +02:00
Thomas Haller 489e346e87 shared: add NM_HASH_COMBINE() function 2017-07-05 14:22:10 +02:00
Thomas Haller 26f04fd886 shared: update c-list
Reimport c-list from upstream. It allows iterating over const-list.
Upstream commit is 17e7781b3fe26e06bbe3817e8ed7418d80f63feb "build: update NEWS".
2017-07-05 14:22:10 +02:00
Thomas Haller bb53b46bd1 shared: add nm_gstring_prepare() util 2017-06-14 14:04:57 +02:00
Thomas Haller 75f3c026eb shared/tests: expose end-time from NMTST_WAIT() macro 2017-05-31 10:46:43 +02:00
Thomas Haller 5235b1740f shared/tests: document how to disable slow tests at compile-time 2017-05-31 10:46:43 +02:00
Thomas Haller ba05819c89 ifcfg-rh/tests: add test for reading NETMASK property 2017-05-30 11:10:19 +02:00
Yuri Chornoivan 0050e8bd34 all: fix typos in documentation, translated strings and comments
https://bugzilla.gnome.org/show_bug.cgi?id=783173
2017-05-28 17:33:37 +02:00
Thomas Haller 1056a28231 tests: extend nmtst_add_test_func() with setup and teardown functions 2017-05-27 23:16:56 +02:00
Thomas Haller a2663803c3 shared: refactor nm_utils_is_power_of_two() to return false for 0
Returning TRUE for zero makes no sense. Obviously, zero is not a power
of two.

Also, the function is used to check whether a number has only one bit
(flag) set, so, an alternative name would be "has-one-bit-set", which
also should return FALSE for zero. All callers didn't really care for
the previous meaning "has-at-most-one-bit-set".

This also avoids the issue of checking (x >= 0), which causes
-Wtype-limits warnings for unsigned types. Which was avoided
by doing (x == 0 || x > 0), which caused -Wlogical-op warning,
which then was avoided (x == 0 || (x > 0 && 1)). Just don't.
2017-05-22 14:01:07 +02:00
Francesco Giudici 7c2ecaa4e0 build: work around GCC -Wlogical-op for "nm_utils_is_power_of_two" macros
We recently added -Wlogical-op in our build process
(commit #41e7fca59762dc928c9d67b555b1409c3477b2b0).
Seems that old versions of gcc (4.8.x) will hit that warning with our
implementation of our "nm_utils_is_power_of_two" and
"test_nm_utils_is_power_of_two_do" macros.
Fool it just adding an always TRUE check.
2017-05-22 12:05:51 +02:00
Thomas Haller df6d27b33a shared: add nm_utils_str_utf8safe_*() API to sanitize UTF-8 strings
Use C-style backslash escaping to sanitize non-UTF-8 strings.
The functions are compatible with glib's g_strcompress() and
g_strescape().

The difference is only that g_strescape() escapes all non-printable,
non ASCII character as well, while nm_utils_str_utf8safe_escape()
-- depending on the flags -- preserves valid UTF-8 sequence except
backslash.

The flags allow to optionally escape ASCII control characters and
all non-ASCII (valid UTF-8) characters. But the option to preserve
valid UTF-8 (non-ASCII) characters verbatim, is what distinguishes
from g_strescape().
2017-05-19 09:46:08 +02:00
Thomas Haller c15eae92c0 libnm: don't cunescape \x00 encoding in nm_udev_utils_property_decode()
UDev never creates such invalid escape sequences. Anyway,
we cannot accept a NUL character at this point. Just take
the ill escape verbatim -- it should never happen anyway.
2017-05-19 09:46:08 +02:00
Thomas Haller 9594ee6e69 libnm: fix unterminated NUL string when parsing UDev properties
This can result in trailing garbage (which fails UTF-8 validation
checks) or even worse, in read-out-of-bounds.

Fixes: 6808bf8195

https://bugzilla.redhat.com/show_bug.cgi?id=1443114
https://bugzilla.redhat.com/show_bug.cgi?id=1451160
https://bugzilla.redhat.com/show_bug.cgi?id=1451286
2017-05-19 09:46:08 +02:00
Thomas Haller d079846330 shared: add "nm-utils/c-list.h" header
Include the circular, doubly-linked list implementation from
c-util/c-list [1], commit 864051de6e7e1c93c782064fbe3a86b4c17ac466.

[1] https://github.com/c-util/c-list
2017-05-11 18:26:07 +02:00
Thomas Haller 0893c3756e utils: fix maybe-uninitialized in "nm-udev-utils.c"
CC       shared/nm-utils/libnm_core_libnm_core_la-nm-udev-utils.lo
    In file included from ./shared/nm-utils/nm-glib.h:27:0,
                     from ./shared/nm-utils/nm-macros-internal.h:29,
                     from ./shared/nm-default.h:178,
                     from shared/nm-utils/nm-udev-utils.c:21:
    shared/nm-utils/nm-udev-utils.c: In function ‘nm_udev_client_enumerate_new’:
    ./shared/nm-utils/gsystem-local-alloc.h:53:50: error: ‘to_free’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
     GS_DEFINE_CLEANUP_FUNCTION(void*, gs_local_free, g_free)
                                                      ^~~~~~
    shared/nm-utils/nm-udev-utils.c:147:18: note: ‘to_free’ was declared here
        gs_free char *to_free;
                      ^~~~~~~
    In file included from ./shared/nm-utils/nm-glib.h:27:0,
                     from ./shared/nm-utils/nm-macros-internal.h:29,
                     from ./shared/nm-default.h:178,
                     from shared/nm-utils/nm-udev-utils.c:21:
    shared/nm-utils/nm-udev-utils.c: In function ‘nm_udev_client_new’:
    ./shared/nm-utils/gsystem-local-alloc.h:53:50: error: ‘to_free’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
     GS_DEFINE_CLEANUP_FUNCTION(void*, gs_local_free, g_free)
                                                      ^~~~~~
    shared/nm-utils/nm-udev-utils.c:243:20: note: ‘to_free’ was declared here
          gs_free char *to_free;
                        ^~~~~~~

Fixes: e32839838e
2017-05-10 15:34:23 +02:00
Thomas Haller 1f40bb13cf shared: cast from/to argument to unsigned for GFlags in _nm_utils_enum_get_values() 2017-04-27 18:01:58 +02:00
Beniamino Galvani d19553392b libnm-core,shared: fix typo in '(allow-none)' annotation 2017-04-27 09:00:55 +02:00
Thomas Haller 83a6f36207 cli: don't mark field names for translation
Before refactoring nmcli recently, field names were marked for translation.
Note that for the property names, marking them had no effect as only
plain strings can be marked with N_().

Note how --fields are also an input argument. The input should be
independent of the locale and not translated. Likewise, when printing
the header names, they should not be translated to match the --fields
option.

    $ LANG=de_DE.utf8 nmcli --fields GENERAL.DEVICE device show enp0s25
    GENERAL.GERÄT:                          enp0s25

Drop the translation marks.
2017-04-23 23:45:02 +02:00
Thomas Haller 6dfb3e9ffb cli/trivial: remove whitespace between N_ macro and parenthesis
For _() and N_() we don't have a space before the parenthesis.
Be consistent about that.
2017-04-19 18:27:19 +02:00
Thomas Haller 6c2727af14 cli: add meta data for NMSettingGeneric 2017-04-12 14:12:20 +02:00
Thomas Haller 7861ce7560 shared: add NM_PTRARRAY_EMPTY() util 2017-04-12 11:24:03 +02:00
Thomas Haller 31d0d0ef83 shared: add NM_PTRARRAY_LEN() utility macro
I used to use g_strv_length ((char **) p) instead, but that feels
ugly because it g_strv_length() is not designed to operate on
arbitrary pointer arrays.
2017-04-12 11:24:03 +02:00
Thomas Haller 9800b1dccc libnm: move public nm_utils_enum_*() functions back to libnm-core
Commit a8730c51c8 moved the enum
utils from libnm-core to shared/nm-utils.

However, three of those functions are part of public API in libnm.
So, when statically linking against "shared/nm-utils/nm-enum-utils.c"
and dynamically linking against libnm.so, those symbols are present
twice and cause a linker failure.

Fix that by moving the public API back to libnm-core.

Fixes: a8730c51c8
2017-04-05 18:38:31 +02:00
Thomas Haller d5bcc5826e shared: move NM_UTILS_LOOKUP() macro shared utils 2017-04-05 16:53:06 +02:00
Thomas Haller d1c6d64e6a shared: move _nm_utils_strv_cleanup() to shared utils 2017-04-05 16:53:06 +02:00
Thomas Haller b9fa0e0a19 utils: add _nm_utils_enum_from_str_full() to support aliases 2017-03-30 13:09:58 +02:00
Thomas Haller a8730c51c8 libnm: move enum utils to new shared file shared/nm-utils/nm-enum-utils.h
libnm contains the public function nm_utils_enum_from_str() et al.
The function is not flexible enough for nmcli's usecase. So, I would
need another public function like nm_utils_enum_from_str_full() that
has an extended API.

That was already required previously for ifcfg-rh writer, but in that
case I could just add it as internal API as libnm-core is linked statically
with NetworkManager.

I don't want to commit to a public API for an utility function. So move
the code instead to the shared directory, so that nmcli may link
statically against it and use the internal API.
2017-03-30 13:09:58 +02:00
Thomas Haller f53218ed7c cli: add property type for enum and showcase for ipv6.addr-gen-mode 2017-03-30 13:09:58 +02:00
Thomas Haller 23298bfc88 cli: move utils function from common.h to nm-meta-setting-desc.c
These functions are only used by nm-meta-setting-desc.c. Make them internal.
Unfortunately, they are part of "common.h" which cannot be used without
the rest of nmcli. Still todo.
2017-03-30 13:09:58 +02:00
Thomas Haller b5c8622ad3 cli: split nm-meta-setting-desc out of settings
This part contains static functions and variables to describe
settings. It is distinct from the mechanism to use them, or
access them.

Split it out.

It still uses clients/cli/common.h and clients/cli/utils.h
which shall be fixed next.
2017-03-30 13:09:58 +02:00
Thomas Haller e1d60712d9 cli: add property-info for the rest 2017-03-30 13:09:57 +02:00
Thomas Haller 3690311b02 meta: add table @nm_meta_setting_infos of all settings types 2017-03-30 13:09:55 +02:00
Lubomir Rintel 1fcb3b40c2 release: bump version to 1.9.0 (development) 2017-03-28 16:34:22 +02:00
Thomas Haller e4c0a4d0f2 shared: minor change to NM_FLAGS_HAS() and nm_utils_is_power_of_two() macros
NM_FLAGS_HAS() should reject negative flag values. So check for > 0.
Also change parentheses and line wrap.
2017-03-23 18:04:13 +01:00
Thomas Haller 6808bf8195 udev: add and use nm_udev_utils_property_decode() function
DRY.
2017-03-22 12:41:06 +01:00
Thomas Haller c48c13b8e5 udev: only create monitor in NMUdevClient when needed
GUdevClient always creates a monitor instance, even if there are no subsystems
or handlers defined. Hence the first iteration of NMUdevClient did that as
well.

I think that can be avoided however. We only need a monitor when there is
a event handler subscribed. Contrary to GUdevClient, we know that from the
very beginning.
2017-03-22 12:41:06 +01:00
Thomas Haller e32839838e udev: drop libgudev in favor of libudev
libgudev is just a wrapper around libudev. We can
use libudev directly and drop the dependency for
libgudev.
2017-03-22 12:41:06 +01:00
Beniamino Galvani f4a8a7f2a6 shared: increase max number of args for _NM_UTILS_MACRO_REST
30 should be enough for anybody.
2017-03-21 18:46:52 +01:00
Thomas Haller c59532ee40 shared: trigger -Wenum-conversion warning in NM_IN_SET*() macros
and add NM_IN_SET*_TYPED() macros, which allow to explicitly select
the type of "x".
2017-03-16 18:27:33 +01:00
Thomas Haller c2dc1c6fa3 shared/trivial: minor style fixes in "nm-utils/nm-macros-internal.h" 2017-03-16 12:09:22 +01:00
Thomas Haller e207e53450 all: use "static inline" instead of "inline static" 2017-03-14 11:23:46 +01:00
Thomas Haller 7d88bd24f3 shared: add _NM_GET_PRIVATE_VOID() macro
_NM_GET_PRIVATE() macro is used to implement a standard private-getter, but it
requires that "self" is a pointer of either "const type *" or "type *". That
is great in most cases, but sometimes we have predominatly self pointers of
different type, so it would require a lot of casts.

Add a different form _NM_GET_PRIVATE_VOID() where self pointer can be any
non-const pointer and returns a non-const private pointer after casting.
2017-03-10 11:06:02 +01:00
Beniamino Galvani c55c631233 shared: add test utilities for IP routes
Add utility functions to check the value of a route attribute.
2017-03-06 15:20:25 +01:00
Thomas Haller 9a64168c87 all: use "static inline" keywords instead of "inline static"
Use a consistent order of "static inline". This seems the prefered
order in general, and we also use it more often already.
2017-02-23 15:28:27 +01:00
Thomas Haller 2c9ef8cf2e shared: move NMSetting8021xSchemeVtable to "shared/nm-setting-metadata.h" 2017-02-17 19:52:13 +01:00
Thomas Haller c79e84368a all: add new "shared/nm-setting-metadata.h" file
"shared/nm-setting-metadata.h" will contain data structures
to handle NM setting properties in a generic way.

For now, this is internal API, but shared between libnm-core (which
extends to libnm, NetworkManager, device-plugins, settings-plugins),
and nmcli.

Related: https://bugzilla.gnome.org/show_bug.cgi?id=732292
2017-02-17 19:51:53 +01:00
Thomas Haller 7e3b47deac shared: cleanup nm_strquote_a() and nm_sprintf_bufa()
- simplify nm_strquote_a().

- use '"' for quoting instad of '\''.

- have nm_sprintf_bufa() evalute @n_elements only once.
2017-02-10 17:31:16 +01:00
Thomas Haller 7d6b8bab70 all: use NM_CACHED_QUARK_FCN() instead of G_DEFINE_QUARK()
I think NM_CACHED_QUARK_FCN() is better because:

- the implementation is in our hand, meaning it is clear that
  putting a "static" before NM_CACHED_QUARK_FCN() is guaranteed to
  work -- without relying on G_DEFINE_QUARK() to be defined in a way
  that this works (in fact, we currently never do that and instead
  make all functions non-static).
- it does not construct function names by appending "_quark".
  Thus you can grep for the entire function name and finding
  the place where it is implemented.
- same with the stings, where the new macro doesn't stringify the
  argument, which is less surpising. Again, now you can grep
  for the string including the double quoting.

(yes, I really use grep to understand the source-code)
2017-02-10 14:33:52 +01:00
Thomas Haller 23040d68fc shared: add NM_CACHED_QUARK() and NM_CACHED_QUARK_FCN() macros
NM_CACHED_QUARK_FCN() is a replacement for G_DEFINE_QUARK().
G_DEFINE_QUARK() is mostly used to define GError quarks. As
such, it always appends _quark() to the function name, which
is unfavorable because it makes it harder to grep for the
definition of the function.

In general I think that macros that defined symbols by concatenating
something should be avoided because that makes it harder to locate
where the symbol was defined.
2017-02-10 14:33:52 +01:00