Commit graph

139 commits

Author SHA1 Message Date
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 7b84c73331 shared/tests: add nmtst_rand_perm_gslist() helper 2017-01-20 21:05:58 +01:00
Thomas Haller d5685c183c release: bump version to 1.7.0 (development)
belatedly...
2017-01-18 18:37:06 +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 6070fe697a build: allow specifying the python interpreter for building
As build-requirement, we either require
  - python2 with python-gobject-base
  - python3 with python3-gobject-base
Previously, we would require that a plain `python` gives the desired
interpreter version.

If somebody's "/usr/bin/env python" however points to a different
python version, there was no easy way to change it -- aside
resetting the $PATH variable to some desired "python" binary.

Now, you can specify it during configure:

  ./configure PYTHON=python3 ...

This especially matters, if you only have python3-gobject-base
installed, you /usr/bin/python is a symlink to python2.

https://bugzilla.gnome.org/show_bug.cgi?id=775768
2016-12-14 19:00:42 +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 24f566afa0 build: merge shared/Makefile.am into parent Makefile.am 2016-10-13 21:36:06 +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 eb8da4c282 build: disable type checks in G_TYPE_CHECK_INSTANCE_CAST() macros (bgo#771120)
Avoid the pointless overhead. Even glib disables them unless you build
with --enable-debug.

https://bugzilla.gnome.org/show_bug.cgi?id=771120
2016-09-12 13:53:34 +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
Lubomir Rintel b2eb64a439 release: bump version to 1.5.0 (development) 2016-08-17 16:20:42 +02:00
Alfonso Sanchez-Beato 6fb0de0a8b auth: check when setting statistics refresh rate 2016-08-17 16:08:20 +02:00
Beniamino Galvani a52d4654ec checkpoint: use polkit to check permission 2016-08-17 14:55:34 +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 3d30004710 build: cleanup src/Makefile.am
- reorder entries in src/Makefile.am so that general names
  are all at the beginning (AM_CPPFLAGS, sbin_PROGRAMS)
  and the names for a certain library/binary are grouped
  together
- have libNetworkManager.la reuse libNetworkManagerBase.la.
- let all components in src/Makefile.am use the same AM_CPPFLAGS,
  except libsystem-nm.la.
- move callouts/nm-dispatcher-api.h to shared/ directory. It
  is obviously not internal API to callouts, and callouts is
  not a library. Thus, the right place is shared/.
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 42940fd66b shared: drop function name from g_return_val_if_reached()
When using g_return_val_if_reached(), the default macro would include
the function name. This name is increasing the binary size. Replace
it in non-debug builds.
2016-07-05 20:46:49 +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
Thomas Haller 8eed67122c device: extend MAC address handling including randomization for ethernet and wifi
Extend the "ethernet.cloned-mac-address" and "wifi.cloned-mac-address"
settings. Instead of specifying an explicit MAC address, the additional
special values "permanent", "preserve", "random", "random-bia", "stable" and
"stable-bia" are supported.

"permanent" means to use the permanent hardware address. Previously that
was the default if no explict cloned-mac-address was set. The default is
thus still "permanent", but it can be overwritten by global
configuration.

"preserve" means not to configure the MAC address when activating the
device. That was actually the default behavior before introducing MAC
address handling with commit 1b49f941a6.

"random" and "random-bia" use a randomized MAC address for each
connection. "stable" and "stable-bia" use a generated, stable
address based on some token. The "bia" suffix says to generate a
burned-in address. The stable method by default uses as token the
connection UUID, but the token can be explicitly choosen via
"stable:<TOKEN>" and "stable-bia:<TOKEN>".

On a D-Bus level, the "cloned-mac-address" is a bytestring and thus
cannot express the new forms. It is replaced by the new
"assigned-mac-address" field. For the GObject property, libnm's API,
nmcli, keyfile, etc. the old name "cloned-mac-address" is still used.
Deprecating the old field seems more complicated then just extending
the use of the existing "cloned-mac-address" field, although the name
doesn't match well with the extended meaning.

There is some overlap with the "wifi.mac-address-randomization" setting.

https://bugzilla.gnome.org/show_bug.cgi?id=705545
https://bugzilla.gnome.org/show_bug.cgi?id=708820
https://bugzilla.gnome.org/show_bug.cgi?id=758301
2016-06-30 08:29:56 +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
Thomas Haller caeaa78918 nm-glib: implement compatibility macro for g_strv_contains() differently
Otherwise, deprecation warnings are not properly suppressed for

  g_return_if_fail (g_strv_contains (strv, str));
2016-06-17 12:25:33 +02:00