Commit Graph

59 Commits

Author SHA1 Message Date
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
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
Thomas Haller
1a190b9038 shared: fix -Wtype-limits warning in nm_glib_check_version() macro
Fix it by converting the macro to an inline function. It's anyway
nicer.

    $ make src/src_libNetworkManagerBase_la-main-utils.lo
      CC       src/src_libNetworkManagerBase_la-main-utils.lo
    In file included from ./shared/nm-utils/nm-macros-internal.h:29:0,
                     from ./shared/nm-default.h:178,
                     from src/main-utils.c:22:
    src/main-utils.c: In function ‘nm_main_utils_setup_signals’:
    ./shared/nm-utils/nm-glib.h:144:36: error: comparison of unsigned expression >= 0 is always true [-Werror=type-limits]
                  && glib_micro_version >= (micro))))
                                        ^
    src/main-utils.c:82:6: note: in expansion of macro ‘nm_glib_check_version’
      if (nm_glib_check_version (2, 36, 0)) {
          ^~~~~~~~~~~~~~~~~~~~~
    cc1: all warnings being treated as errors
    Makefile:12312: recipe for target 'src/src_libNetworkManagerBase_la-main-utils.lo' failed
2017-02-06 19:27:21 +01:00
Thomas Haller
a165907554 shared: add nm_utils_strv_find_first() helper
Make _nm_utils_strv_find_first() accessible outside of libnm-core
by copying it from "libnm-core/nm-core-internal.h" (and rename it).
2017-02-04 17:54:49 +01:00
Thomas Haller
641eb7fd12 shared/tests: add nmtst_rand_perm_gslist() helper
(cherry picked from commit 7b84c73331)
2017-01-20 21:18:31 +01:00
Thomas Haller
61da320d62 shared: add nm_offsetofend() macro 2017-01-16 17:20:35 +01:00
Thomas Haller
142009c6a5 shared: add nm_str_realloc() 2017-01-09 14:50:33 +01:00
Thomas Haller
f779c51f87 shared: move nm_utils_strbuf_*() helper to shared/nm-utils 2017-01-05 11:13:17 +01:00
Thomas Haller
207a663948 shared: add nm_str_skip_leading_spaces() macro 2016-12-25 15:38:00 +01:00
Thomas Haller
d2b9f37455 libnm: add public macro NM_VERSION for the current build-time version of libnm 2016-12-20 16:51:52 +01:00
Thomas Haller
99e1e4d6a1 shared: add NM_AUTO_PROTECT_ERRNO
Similar to systemd's PROTECT_ERRNO. The difference it, that it doesn't
treat the auto-variable as internal, so it is allowed to use it. E.g.

    if (!(fd = open (...)) {
        NM_AUTO_PROTECT_ERRNO (errno_saved);
        printf ("error: %s", g_strerror (errno_saved));
        return FALSE;
    }
2016-12-13 11:26:58 +01:00
Thomas Haller
312cea870d shared: add nm_auto_close and nm_auto_fclose
We already have gs_fd_close, which however doesn't preserve
errno and only checks for fd != -1. Add our own define.

Downside is, we have to include stdio.h and errno.h,
which effectively ends up to be included *everywhere*.
2016-12-13 11:26:58 +01:00
Thomas Haller
f5e6f1d65b shared: add nmtst_auto_unlinkfile cleanup macro 2016-11-09 12:07:33 +01:00
Thomas Haller
b204801b7e shared: add nmtst_file_get_contents() 2016-11-09 12:07:33 +01:00
Thomas Haller
858daf57bc shared: add NM_STRCHAR_ALL() and NM_STRCHAR_ANY() macros 2016-11-09 12:07:33 +01:00
Thomas Haller
5789bfa5d9 shared: minor cleanup in _nm_utils_ascii_str_to_int64() using const pointer 2016-11-02 12:04:49 +01:00
Thomas Haller
ba950cedee shared: add nm_assert_se() macro
We usually don't build NM with g_assert() disabled (G_DISABLE_ASSERT).
But even if we would, there is no assertion macro that always evaluates
the condition for possible side effects.

I think that is a useful thing to have.
2016-10-28 16:28:29 +02:00
Thomas Haller
34970e4141 shared: make nm_str_not_empty() inline function instead of macro
It was a macro to pass on the non-const-ness of the argument, but
that just doesn't make sense.

That is a signature

  char *nm_str_not_empty (char *)

does not make sense, because you cannot transfer ownership
conditionally without additional checks to avoid a leak. Which makes
this form is pointless. For example:

    char *
    foo (void)
    {
        char *s;

        s = _create_value ();
        return nm_str_not_empty (s); /* leaks "" */
    }
2016-10-24 10:14:02 +02:00
Beniamino Galvani
22cc119da5 shared: add unaligned.h
The file, imported from systemd sources, contains macros for accessing
potentially unaligned data in a safe way (i.e. byte-wise).
2016-10-14 11:16:13 +02:00
Thomas Haller
6b904a51ee shared: re-define _G_BOOLEAN_EXPR() to allow nesting g_assert()
g_assert() uses G_LIKELY(), which in turn uses _G_BOOLEAN_EXPR().
As glib's version of _G_BOOLEAN_EXPR() uses a local variable
_g_boolean_var_, we cannot nest a G_LIKELY() inside a G_LIKELY(),
or inside a g_assert(), or a g_assert() inside a g_assert().

Workaround that, by redefining the macro.

I already encountered this problem before, when having a nm_assert()
inside a ({...}) block, inside a g_assert(). Then I just avoided that
combination, but this situation is quite easy to encounter.
2016-10-11 13:14:43 +02:00
Thomas Haller
9ff1fa4ae1 shared: add NM_DECIMAL_STR_MAX() macro 2016-10-11 11:37:46 +02:00
Thomas Haller
c5f4e36fd9 shared: assert against buffer length in nm_sprintf_buf() 2016-10-11 11:37:46 +02:00
Thomas Haller
84346d172a shared: add NMTST_UUID_INIT() macro 2016-10-05 14:46:18 +02:00
Thomas Haller
b4e66c4818 shared: add nm_clear_g_free() 2016-10-03 12:02:34 +02:00
Thomas Haller
a83eb773ce all: modify line separator comments to be 80 chars wide
sed 's#^/\*\{5\}\*\+/$#/*****************************************************************************/#' $(git grep -l '\*\{5\}' | grep '\.[hc]$') -i
2016-10-03 12:01:15 +02:00
Thomas Haller
ee86069601 shared: add test for NM_SET_OUT() 2016-09-26 17:00:38 +02:00
Thomas Haller
c3ecca225c core: add _nm_utils_array_find_binary_search()
Also add nm_cmp_uint32_p_with_data(). Will be used later.
2016-09-23 15:49:29 +02:00
Thomas Haller
b1fd5a06c4 macros: simplify NM_IN_SET() and NM_IN_STRSET() macros
and support up to 16 arguments.
2016-09-22 16:34:22 +02:00
Thomas Haller
1206fd066b shared: add nm_utils_syslog_coerce_from_nm() util
When a VPN plugin logs to syslog(), it should not use the syslog
levels that were passed in by NetworkManager directly. Instead,
it must map LOG_NOTICE to LOG_INFO and LOG_INFO to LOG_DEBUG.

Add a utility function does gets that right.
2016-09-19 15:35:33 +02:00
Thomas Haller
2cae9ba348 shared: add _NM_GET_PRIVATE() macro 2016-09-08 00:21:21 +02:00
Thomas Haller
b2016fd2a5 shared: add NM_MIN()/NM_MAX() macros to replace glib's MIN()/MAX() 2016-09-08 00:21:21 +02:00
Thomas Haller
3227b9017b shared: add helper macros nm_str_not_empty() and nm_strdup_not_empty() 2016-09-06 16:07:02 +02:00
Thomas Haller
6d2680acf1 nm-glib.h: fix compatibility wrapper for g_variant_new_take_string()
g_variant_new_from_bytes() is itself only available since 2.36, thus
using it triggers a deprecation warning itself.
2016-08-11 19:21:55 +02:00
Thomas Haller
80d52e3230 nm-glib: add compatibility wrapper for g_variant_new_take_string() 2016-08-11 11:54:18 +02:00
Thomas Haller
de2ce68a9f shared: add NM_VPN_PLUGIN_CONFIG_PROXY_PAC to "nm-vpn-plugin-macros.h" for VPN plugins
Soon we will add proxy support where VPN plugins set a property
NM_VPN_PLUGIN_CONFIG_PROXY_PAC.

All a VPN plugin needs to make use of this new setting is the
NM_VPN_PLUGIN_CONFIG_PROXY_PAC define.

We don't want that older plugins (still compatible with libnm 1.2 API)
require a new API only for this define. Define it instead in
"shared/nm-utils/nm-vpn-plugin-macros.h" as fallback.

https://mail.gnome.org/archives/networkmanager-list/2016-June/msg00154.html
2016-07-06 13:54:35 +02:00
Thomas Haller
4041bf966f shared: add nm_strquote_a() helper 2016-07-05 23:08:22 +02:00
Thomas Haller
375d3e1cb8 vpn: support option to preserve previous routing information on VPN config update
On openvpn restart, the VPN helper script is invoked without full routing information.
Thus, the routes will be dropped because the helper script cannot provide them
on update.

Add an option "preserve-route" which tells NetworkManager to preserve
and reuse the previous configuration.

https://bugzilla.redhat.com/show_bug.cgi?id=1231338
https://bugzilla.gnome.org/show_bug.cgi?id=750873
2016-07-04 10:31:05 +02:00
Beniamino Galvani
a5d1db08f8 dns: log DNS servers at TRACE level
Be more verbose at TRACE level and log the DNS servers associated to
configurations. This will help to debug issues like [0].

[0] https://bugzilla.redhat.com/show_bug.cgi?id=1348887
2016-06-28 16:24:28 +02:00