Commit graph

22207 commits

Author SHA1 Message Date
Thomas Haller
047998f80a all: cache errno in local variable before using it 2019-02-12 08:50:28 +01:00
Thomas Haller
b7bb744973 libnm,core: use _nm_utils_ascii_str_to_uint64() instead of strtol()
Using strtol() correctly proves to be hard.

Usually, we want to also check that the end pointer is points to the end
of the string. Othewise, we silently accept trailing garbage.
2019-02-12 08:50:28 +01:00
Thomas Haller
a3370af3a8 all: drop unnecessary includes of <errno.h> and <string.h>
"nm-macros-interal.h" already includes <errno.h> and <string.h>.
No need to include it everywhere else too.
2019-02-12 08:50:28 +01:00
Thomas Haller
32a847a61f systemd/trivial: adjust naming of include guard define 2019-02-12 08:50:28 +01:00
Thomas Haller
65884733ec all: minor coding style fixes (space before parentheses) 2019-02-11 15:22:57 +01:00
Beniamino Galvani
3a0f7114fe platform: limit the maximum size of sysctl cache
When the logging level is DEBUG or TRACE, we keep all the sysctl
values we read in a cache to log how they change. Currently there is
no limit on the size of this cache and it can take a large amount of
memory.

Implement a LRU cache where the oldest entries are deleted to make
space for new ones.

https://github.com/NetworkManager/NetworkManager/pull/294
2019-02-10 10:38:54 +01:00
Thomas Haller
fb1baa636b build,ci: merge branch 'th/missing-braces-warning'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/81
2019-02-09 08:53:06 +01:00
Thomas Haller
668dc1cd02 core: use NM_CMP_*() macro in route_compare()
nm_ip_route_get_prefix() and plen are guint type, hence the following
is not correct:

    plen = nm_ip_route_get_prefix (route1);
    r = plen - nm_ip_route_get_prefix (route2);
    if (r)
         return r > 0 ? 1 : -1;

Use the macro, it gets subtle cases like this right.

Fixes: b32bb36c61
2019-02-09 07:14:32 +01:00
Thomas Haller
167142c38e build/meson: build with c_std=gnu11
For autotools, we already updated to C11 (gnu11) with commit
066357aa47 ("build: bump C standard
to (gcc's) C11").
2019-02-09 07:14:32 +01:00
Thomas Haller
557271fa6a gitlab-ci: rename build-jobs in gitlab-ci
It just looks nicer.
2019-02-09 07:14:32 +01:00
Thomas Haller
53aac0233c build/ci: enable --werror for meson builds
This enables -Werror for meson builds on gitlab-ci and semaphore.
Not on Travis, the compiler there is too old, giving too many bogus
warnings.

This reverts commit 928d68d04a ("m4:
disable -Wmissing-braces for newer clang").
2019-02-08 20:14:50 +01:00
Thomas Haller
ff5944ce03 contrib/rpm: enable warnings and fatal-warnings with meson build 2019-02-08 20:14:50 +01:00
Thomas Haller
c537e5fd25 build: re-enable "-Wmissing-braces" warning
We should always get the nesting in struct initializers right.
Everyhing else is error-prone, and the warning is good.

Enable it.
2019-02-08 20:14:50 +01:00
Thomas Haller
c236dc161d device: avoid "-Wmissing-braces" warning for initializing "struct in6_addr"
The right way is IN6_ADDR_INIT_ANY.

While at it, don't initialize multiple variables in the same line.

    ../src/devices/nm-device-ip-tunnel.c:153:29: error: suggest braces around initialization of subobject [-Werror,-Wmissing-braces]
            struct in6_addr local6 = { 0 }, remote6 = { 0 };
                                       ^
                                       {}
2019-02-08 20:14:50 +01:00
Thomas Haller
3458c02acb platform/tests: avoid "-Wmissing-braces" warning in "test-route.c" 2019-02-08 20:14:50 +01:00
Thomas Haller
395174f659 shared: avoid "-Wmissing-braces" warning initalizing NMIPAddr
NMIPAddr contains an unnamed union. We have to either explicitly
initialize one field, or omit it.

    ../shared/nm-utils/nm-shared-utils.c:38:36: error: suggest braces around initialization of subobject [-Werror,-Wmissing-braces]
    const NMIPAddr nm_ip_addr_zero = { 0 };
                                       ^
                                       {}
2019-02-08 20:14:50 +01:00
Thomas Haller
814bcf5575 libnm: avoid "-Wmissing-braces" warning for intializing NMUuid 2019-02-08 20:14:50 +01:00
Thomas Haller
fcb7001302 cli: avoid "-Wmissing-braces" warning for INT_VALUE_INFOS() and ENUM_VALUE_INFOS()
Also fix indentations and enforce that each block is terminated by a
trailing comma.
2019-02-08 20:14:50 +01:00
Thomas Haller
a44d276f55 libnm: avoid "-Wmissing-braces" warning for test-link.c
../src/platform/tests/test-link.c: In function ‘_test_wireguard_change’:
    ../src/platform/tests/test-link.c:861:16: warning: missing braces around initializer [-Wmissing-braces]
         endpoint = (NMSockAddrUnion) {
                    ^
    ../src/platform/tests/test-link.c:864:21:
           .sin_addr   = nmtst_inet4_from_string (nm_sprintf_buf (s_addr, "192.168.7.%d", i)),
                         {                                                                   }
    ../src/platform/tests/test-link.c:861:16: warning: missing braces around initializer [-Wmissing-braces]
         endpoint = (NMSockAddrUnion) {
                    ^
    ../src/platform/tests/test-link.c:864:21:
           .sin_addr   = nmtst_inet4_from_string (nm_sprintf_buf (s_addr, "192.168.7.%d", i)),
                         {
2019-02-08 20:14:50 +01:00
Thomas Haller
ce8b053674 libnm: avoid "-Wmissing-braces" warning for teams _prop_to_keys array
[1/384] Compiling C object 'libnm-core/2b1af02@@nm-core@sta/nm-setting-team.c.o'.
    ../libnm-core/nm-setting-team.c:649:77: warning: missing braces around initializer [-Wmissing-braces]
     static const _NMUtilsTeamPropertyKeys _prop_to_keys[_PROPERTY_ENUMS_LAST] = {
                                                                                 ^
      [PROP_CONFIG] =                      { NULL, NULL, NULL, 0 },
                                                               { }

And use designated initializers.
2019-02-08 20:14:50 +01:00
Thomas Haller
4f931a1920 tests: avoid "-Wmissing-braces" warning in test_nm_utils_dhcp_client_id_systemd_node_specific()
[1/2] Compiling C object 'src/tests/a4ccf2d@@test-general@exe/test-general.c.o'.
    ../src/tests/test-general.c: In function ‘test_nm_utils_dhcp_client_id_systemd_node_specific’:
    ../src/tests/test-general.c:2056:16: warning: missing braces around initializer [-Wmissing-braces]
      } d_array[] = {
                    ^
    ../src/tests/test-general.c:2058:20:
        .machine_id = { 0xcb, 0xc2, 0x2e, 0x47, 0x41, 0x8e, 0x40, 0x2a, 0xa7, 0xb3, 0x0d, 0xea, 0x92, 0x83, 0x94, 0xef },
                        {
2019-02-08 20:14:50 +01:00
Thomas Haller
6eaf52a509 wifi/iwd: avoid "-Wstrict-aliasing" warning in nm_device_iwd_set_dbus_object()
The cast is bogus and leads to a compiler warning:

    [424/583] Compiling C object src/devices/wifi/914a32e@@nm-device-plugin-wifi@sha/nm-device-iwd.c.o.
    In file included from ../shared/nm-default.h:293,
                     from ../src/devices/wifi/nm-device-iwd.c:21:
    ../src/devices/wifi/nm-device-iwd.c: In function ‘nm_device_iwd_set_dbus_object’:
    ../src/devices/wifi/nm-device-iwd.c:2404:28: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
      if (!nm_g_object_ref_set ((GObject **) &priv->dbus_obj, (GObject *) object))
    ../shared/nm-utils/nm-macros-internal.h:1048:13: note: in definition of macro ‘nm_g_object_ref_set’
       typeof (*(pp)) *const _pp = (pp); \
                 ^~
2019-02-08 20:14:50 +01:00
Thomas Haller
2510f60e92 cli: avoid "-Wduplicate-decl-specifier" warning in nmcli's resolve_color_alias()
[1/2] Compiling C object 'clients/cli/2641089@@nmcli@exe/nmcli.c.o'.
    ../clients/cli/nmcli.c: In function ‘resolve_color_alias’:
    ../clients/cli/nmcli.c:507:4: warning: duplicate ‘const’ declaration specifier [-Wduplicate-decl-specifier]
      } const aliases[] = {
        ^~~~~
2019-02-08 20:14:50 +01:00
Thomas Haller
2fe9ade10d tests: avoid "-Wduplicate-decl-specifier" warning in test_duplicate_decl_specifier()
The test should check the behavior with "const typeof(a)" in a macro,
where "a" itself is const. For that we don't need a double const
declaration of v2.

Also, that fixes an actual compiler warning:

    ../src/tests/test-general.c: In function ‘test_duplicate_decl_specifier’:
    ../src/tests/test-general.c:1669:8: warning: duplicate ‘const’ declaration specifier [-Wduplicate-decl-specifier]
      const const int v2 = 3;
            ^~~~~
2019-02-08 20:14:50 +01:00
Thomas Haller
7a8a4a5fa3 clients: avoid "-Wduplicate-decl-specifier" warning in array declarions in "nm-vpn-helpers.c"
[1/5] Compiling C object 'clients/common/913ef36@@nmc-base@sta/nm-vpn-helpers.c.o'.
    ../clients/common/nm-vpn-helpers.c: In function ‘nm_vpn_get_secret_names’:
    ../clients/common/nm-vpn-helpers.c:118:31: warning: duplicate ‘const’ declaration specifier [-Wduplicate-decl-specifier]
      static const VpnPasswordName const generic_vpn_secrets[] = {
                                   ^~~~~
2019-02-08 20:14:50 +01:00
Thomas Haller
9c3a59341f shared: fix static array declaration for _by_name in "nm-ethtool-utils.c"
[1/73] Compiling C object 'libnm-core/2b1af02@@nm-core@sta/.._shared_nm-ethtool-utils.c.o'.
    ../shared/nm-ethtool-utils.c:93:14: warning: duplicate 'const' declaration specifier [-Wduplicate-decl-specifier]
     const guint8 const _by_name[_NM_ETHTOOL_ID_NUM] = {
                  ^~~~~
2019-02-08 20:14:50 +01:00
Thomas Haller
7b18bd1fa8 build/meson: disable "-Wgnu-variable-sized-type-not-at-end warning"
It's not useful for us.

    In file included from ../src/systemd/src/libsystemd/sd-event/sd-event.c:14:
    ../src/systemd/src/libsystemd/sd-event/event-source.h:195:36: error: field 'buffer' with variable sized type 'union inotify_event_buffer' not at the end of a struct or class is a GNU extension [-Werror,-Wgnu-variable-sized-type-not-at-end]
            union inotify_event_buffer buffer;
                                       ^
2019-02-08 20:14:50 +01:00
Thomas Haller
dc4f6f6656 gitlab-ci: fix moving docs-html
Seems .git directory is somehow shared/cached between CI runs.
Use /tmp instead.
2019-02-08 20:14:19 +01:00
Thomas Haller
aacb3c4f5b connectivity: merge branch 'th/connectivity-rp-filter' 2019-02-08 17:28:58 +01:00
Thomas Haller
983b430075 device: print warning when rp_filter is set to strict with connectivity checking 2019-02-08 16:34:18 +01:00
Thomas Haller
45f4f573ca contrib/rpm: add comment to "20-connectivity-{fedora,redhat}.conf" about rp_filter 2019-02-08 16:24:25 +01:00
Thomas Haller
4023012cd1 man: add a warning to NetworkManager.conf manual for rp_filter and connectivity checking 2019-02-08 16:05:36 +01:00
Thomas Haller
bba33ba20c gitlab-ci: log timestamp of test steps 2019-02-08 10:35:37 +01:00
Thomas Haller
211ac0ddad gitlab-ci: fix generating pages
Fixes: bdac03fe9a
2019-02-08 08:08:07 +01:00
Thomas Haller
7b8a9a2927 gitlab-ci: merge branch 'th/gitlab-ci-clang'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/79
2019-02-07 17:34:44 +01:00
Thomas Haller
bdac03fe9a gitlab-ci: build with clang and do multiple builds in one test-step
Also, let one docker image do multiple builds. We fetch a fedora docker
image, and then install 250 MB of packages. That alone takes a lot of
time and resources. Instead of running a large number of docker images
that only do one build, let one image do several builds.

Also, install ccache. Hopefully this way we can benefit from
building the same sources multiple times.

Also note that building docs does not work currently with clang,
due to g-ir-scanner. See commit 05568860cce5332977d92b85f7c25b8ed646cd58.
2019-02-07 17:31:37 +01:00
Thomas Haller
389197fa81 gitlab-ci: allow enabling/disabling building documentation in "nm-ci-run.sh"
g-ir-scanner does not support building with clang, due to [1], [2], [3].

It triggers

    checking if /usr/bin/g-ir-scanner works... no (compiler failure -- check config.log)
    configure: error: introspection enabled but can't be used

with

    clang-7: error: unknown argument: '-fstack-clash-protection'

See also commit 99b92fd992, which adds this configure
check.

Honor the environment variable WITH_DOCS to allow the caller to overwrite
the automatic detection that the script does.

[1] https://bugzilla.gnome.org/show_bug.cgi?id=757934
[2] https://gitlab.gnome.org/GNOME/gobject-introspection/issues/150
[3] c14d037228
2019-02-07 17:31:31 +01:00
Thomas Haller
6505a781cf contrib: install python3-gobject as REQUIRED_PACKAGES
To run the tests with python3, we need python3-gobject.

Note that "contrib/fedora/REQUIRED_PACKAGES" is called by
"contrib/scripts/nm-ci-run.sh" script to install the packages
in Fedora.
2019-02-07 17:31:05 +01:00
Thomas Haller
06701e9532 macros: don't use __externally_visible__ attribute for clang
clang does not support externally_visible:

    ../libnm/nm-access-point.c:243:1: error: unknown attribute externally_visible ignored [-Werror,-Wunknown-attributes]
    NM_BACKPORT_SYMBOL (libnm_1_0_6, int, nm_access_point_get_last_seen, (NMAccessPoint *ap), (ap));
    ^
    ../shared/nm-utils/nm-macros-internal.h:1299:74: note: expanded from macro NM_BACKPORT_SYMBOL
    #define NM_BACKPORT_SYMBOL(version, return_type, func, args_typed, args) \
                                                                             ^
    ../shared/nm-utils/nm-macros-internal.h:1292:17: note: expanded from macro _NM_BACKPORT_SYMBOL_IMPL
    __attribute__ ((externally_visible)) return_type versioned_func args_typed \
                    ^
2019-02-07 17:31:05 +01:00
Thomas Haller
68d7e63886 iwd: drop unused variable in disconnect()
Fixes: a6f13d3c69
2019-02-07 17:31:05 +01:00
Thomas Haller
74e9468c51 ofono: drop unused variable in disconnect()
Fixes: 9b935fad9b
2019-02-07 17:31:05 +01:00
Thomas Haller
e95cf643c3 cli: drop invalid validation for default-routes in nmcli
Currently, default-routes cannot be added like regular static-routes
as ipv4.routes setting.
Instead, one has to configure "ipv4.gateway" and "ipv4.never-default".
That of course should be fixed, for example to configure a default-route
in different routing tables.

As it is, both nmcli's parse function and libnm's
NMSettingIPConfig:verify() functions reject default-routes.

But nmcli goes way beyond that, it also rejects all networks with
"0.0.0.0"/"::" even if their prefix length is not zero. Such routes are
not default-routes, and nmcli has no business rejecting them. The
correct way for checking for a default-route is to check the prefix-length
for zero.

Drop the wrong validation in nmcli.

Note, it may still not be the best idea to add catch-all routes like
"0.0.0.0/1" and "128.0.0.0/1". It just defeats what counts as a default-route.
NM has other means (like configuring the route-metric) to handle routing
in face of multiple interfaces. But sure, whatever works for you.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/114
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/75
2019-02-07 17:21:40 +01:00
Thomas Haller
a0b976ac8b contrib/rpm: quote snapshot/git_sha variables in spec-file
Otherwise the following fails:

    $ ./contrib/fedora/rpm/build_clean.sh -g -s x.1
    ...
    error: parse error in expression
    error: /data/src/_NetworkManager/contrib/fedora/rpm/NetworkManager.20190207-165257.XOkW4i/SPECS/NetworkManager.spec:35: bad %if condition
    ERROR: rpmbuild FAILED

Even with the fix, not all characters are allowed:

    $ ./contrib/fedora/rpm/build_clean.sh -g -s x-1
    ...
    error: line 112: Illegal char '-' (0x2d) in: Release: 22165.x-1.25b13e2053.fc29
    ERROR: rpmbuild FAILED
2019-02-07 16:55:31 +01:00
Thomas Haller
db98070214 build/meson: add dependency of libnm to libnm-core
We need to build libnm-core first. Especially, because libnm
sources require the "libnm-core/nm-core-enum-types.h" header
to be generated first.

Add a missing dependency.
2019-02-06 13:36:22 +01:00
Thomas Haller
052734a8d3 build/meson: cleanup of libnm/meson.build
"libnm/fake-typelib/meson.build" modifies the variable "sources",
which is defined by the outer "libnm/meson.build" file.

That is confusing. If a variable is not only used within one "meson.build"
file alone, it should have a unique name. Rename the variable to
"libnm_utils_sources".

Also avoid local variable "deps" which is only used at one place.
2019-02-06 13:35:26 +01:00
Thomas Haller
708f810515 Revert "clients/tests: fix client tests"
This reverts commit dc1187a161.
2019-02-06 12:12:51 +01:00
Thomas Haller
e357d15023 Revert "cli: verify connections before sending them over to daemon"
Just calling nm_connection_verify() is not correct. We need
nm_connection_normalize() because otherwise we miss out on places
where we have common normalization steps implemented to fix a
connection. This is also what server-side is done.

Revert the patch, as it breaks CI tests.

I wonder also whether this is the right place. There are already
several places in "clients/cli/connections.c" that call verify()
and normalize(). These places should be unified so that there is
one place where we complete the connection. And it probably should be
done as a separate step before the add_new_connection()/update_connection()
calls.

This reverts commit ca58bcca0c.
2019-02-06 11:51:38 +01:00
Thomas Haller
d25ed0820c all: don't use "static inline" in source files
For static functions inside a module, the compiler determines on its own
whether to inline the function.

Also, "inline" was used at some places that don't immediatly look like
candidates for inlining. It was most likely a copy&paste error.
2019-02-06 09:31:00 +01:00
Thomas Haller
bb341900dd all: avoid backslash escape double quote inside single quote
It's not necessary.
2019-02-06 09:30:59 +01:00
Thomas Haller
de1741e2d0 systemd: merge branch systemd into master 2019-02-06 09:28:36 +01:00