Commit graph

286 commits

Author SHA1 Message Date
Beniamino Galvani
4e0804b7ec release: bump version to 1.10.15 (development) 2018-11-20 11:04:30 +01:00
Beniamino Galvani
19339501a7 release: bump version to 1.10.14 2018-11-20 10:53:20 +01:00
Thomas Haller
f2590e86b3 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.

(cherry picked from commit 901aa0315b)
2018-10-19 18:39:32 +02:00
Thomas Haller
fb64e268bb 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.

(cherry picked from commit 2aad517b0b)
2018-10-19 18:39:32 +02:00
Thomas Haller
e74f310d30 release: bump version to 1.10.13 (development) 2018-09-18 15:21:37 +02:00
Thomas Haller
912548d37a release: bump version to 1.10.12 2018-09-18 15:21:37 +02:00
Thomas Haller
ce5b8ac8a4 release: bump version to 1.10.11 (development) 2018-06-16 08:48:38 +02:00
Thomas Haller
25c3239d04 release: bump version to 1.10.10 2018-06-16 08:48:38 +02:00
Beniamino Galvani
7ce845a2a2 release: bump version to 1.10.9 (development) 2018-05-11 16:20:59 +02:00
Beniamino Galvani
cb96d787c9 release: bump version to 1.10.8 2018-05-11 16:18:31 +02:00
Lubomir Rintel
42913505a3 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.

(cherry picked from commit ee916a1e9e)
2018-04-12 14:07:51 +02:00
Lubomir Rintel
77e4af1991 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.

(cherry picked from commit 411e72b3c9)
2018-04-12 14:07:35 +02:00
Thomas Haller
4c9ebd5abb release: bump version to 1.10.7 (development) 2018-03-12 13:51:59 +01:00
Thomas Haller
dd8cf21cea release: bump version to 1.10.6 2018-03-12 13:51:59 +01:00
Lubomir Rintel
2405959132 release: bump version to 1.10.5 (development) 2018-02-05 11:04:49 +01:00
Lubomir Rintel
f781411ceb release: bump version to 1.10.4 2018-02-05 11:03:52 +01:00
Lubomir Rintel
356f1131f3 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.

(cherry picked from commit fc4552d391)
2018-01-24 09:55:18 +01:00
Beniamino Galvani
1bcbf88a62 release: bump version to 1.10.3 (development) 2017-12-12 02:45:52 +01:00
Lubomir Rintel
47e5e3ba7d 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'

(cherry picked from commit 92f8f30d47)
2017-12-11 19:06:31 +01:00
Thomas Haller
85b1c11b8f shared: propagate type for g_object_ref()
See related bug https://bugzilla.gnome.org/show_bug.cgi?id=790697

(cherry picked from commit 7ca601d529)
2017-12-06 10:44:45 +01:00
Thomas Haller
e36b647c4b shared/trivial: fix type on comment
(cherry picked from commit 011a609bd4)
2017-12-06 09:35:43 +01:00
Thomas Haller
7135097762 shared: fix nm_utils_strsplit_set() to increase buffer size exponentially
(cherry picked from commit de92e88161)
2017-11-29 19:15:30 +01:00
Thomas Haller
bf7661189e 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

(cherry picked from commit b6efac9ec2)
2017-11-28 12:04:15 +01:00
Thomas Haller
1ec51d02bd shared: add nm_g_object_set_property_*() helper
(cherry picked from commit 5befde7d7d)
2017-11-24 08:29:23 +01:00
Thomas Haller
7e1e1c1f7f 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.

(cherry picked from commit 3adce12898)
2017-11-21 14:14:25 +01:00
Thomas Haller
fc2894508e all: use nm_close() instead of close()
(cherry picked from commit 5b29c2e5b9)
2017-11-14 15:17:02 +01:00
Thomas Haller
334846906e 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.

(cherry picked from commit f4780f85ae)
2017-11-14 15:17:01 +01:00
Thomas Haller
02b339f170 shared: add nm_ip_addr_set() helper
(cherry picked from commit a9d1f5e543)
2017-11-13 14:43:07 +01:00
Thomas Haller
cfe4d61a12 shared/trivial: move code
(cherry picked from commit 632e8ac885)
2017-11-13 14:43:07 +01:00
Thomas Haller
d9c5f7c9fb 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.

(cherry picked from commit 557d83bf2d)
2017-11-13 14:43:07 +01:00
Thomas Haller
5282469098 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.

(cherry picked from commit bdfdabea51)
2017-11-13 14:43:07 +01:00
Thomas Haller
5d940b73fe shared: fix detection of _Generic() support
(cherry picked from commit 03efc9e2c9)
2017-11-13 14:43:07 +01:00
Francesco Giudici
dcdb1e5fd0 shared: trivial: add space before comment close
(cherry picked from commit 85cc5db7a4)
2017-11-13 14:37:37 +01:00
Thomas Haller
dd02e4bfce 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
(cherry picked from commit b339a2742a)
2017-11-13 14:37:30 +01:00
Thomas Haller
fda3458201 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.

(cherry picked from commit b1810d7a68)
2017-11-13 14:37:21 +01:00
Thomas Haller
ddc889ff6b release: bump version to 1.10.1 (development) 2017-11-13 13:58:18 +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
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