Commit graph

28 commits

Author SHA1 Message Date
Thomas Haller
46eb75d746
ifcfg-rh/trivial: move code 2021-05-12 13:43:36 +02:00
Thomas Haller
dd3aa1224a
ifcfg-rh: use NMStrBuf in svUnescape()
This is a popular, low-level function. Let's use NMStrBuf.

Also, Coverity wrongly things that there is a leak here. This change
should also avoid that:

    Error: RESOURCE_LEAK (CWE-772):
    NetworkManager-1.31.3/src/core/settings/plugins/ifcfg-rh/shvar.c:411: alloc_arg: "_gstr_init" allocates memory that is stored into "str".
    NetworkManager-1.31.3/src/core/settings/plugins/ifcfg-rh/shvar.c:423: noescape: Resource "str" is not freed or pointed-to in "g_string_append_len".
    NetworkManager-1.31.3/src/core/settings/plugins/ifcfg-rh/shvar.c:619: leaked_storage: Variable "str" going out of scope leaks the storage it points to.
    #  617|           nm_assert(!str);
    #  618|           *to_free = NULL;
    #  619|->         return "";
    #  620|       }
    #  621|

Profile:

We run test-ifcfg-rh which calls svUnescape() under realistic circumstances.
However, the test does too many other things that svUnescape() would be
measurable. So use the following patch, to run the tested code more frequently:

    diff --git a/src/core/settings/plugins/ifcfg-rh/shvar.c b/src/core/settings/plugins/ifcfg-rh/shvar.c
    index c6099dd1731c..18a907113ea9 100644
    --- a/src/core/settings/plugins/ifcfg-rh/shvar.c
    +++ b/src/core/settings/plugins/ifcfg-rh/shvar.c
    @@ -645,6 +645,24 @@ out_error:
         return NULL;
     }

    +#define svUnescape(value, to_free)                   \
    +    ({                                               \
    +        const char *_value = (value);                \
    +        const char *_result;                         \
    +        int         _i;                              \
    +                                                     \
    +        for (_i = 0; TRUE; _i++) {                   \
    +            gs_free char *_to_free;                  \
    +                                                     \
    +            _result = svUnescape(_value, &_to_free); \
    +            if (_i < 1000)                           \
    +                continue;                            \
    +            *(to_free) = g_steal_pointer(&_to_free); \
    +            break;                                   \
    +        }                                            \
    +        _result;                                     \
    +    })
    +
     /*****************************************************************************/

     shvarFile *

Build:

    CFLAGS='-O2' ./autogen.sh --with-more-asserts=0
    make -j 10 src/core/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh && \
        src/core/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh &&
        perf stat -r 50 -B src/core/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh

Before:

 Performance counter stats for 'src/core/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh' (20 runs):

            590.56 msec task-clock:u              #    0.972 CPUs utilized            ( +-  0.48% )
                 0      context-switches:u        #    0.000 K/sec
                 0      cpu-migrations:u          #    0.000 K/sec
             1,091      page-faults:u             #    0.002 M/sec                    ( +-  0.12% )
     2,022,618,453      cycles:u                  #    3.425 GHz                      ( +-  0.33% )
     4,165,011,633      instructions:u            #    2.06  insn per cycle           ( +-  0.01% )
     1,168,673,648      branches:u                # 1978.910 M/sec                    ( +-  0.01% )
         8,279,364      branch-misses:u           #    0.71% of all branches          ( +-  0.14% )

           0.60739 +- 0.00292 seconds time elapsed  ( +-  0.48% )

After:

 Performance counter stats for 'src/core/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh' (50 runs):

            580.19 msec task-clock:u              #    0.972 CPUs utilized            ( +-  0.33% )
                 0      context-switches:u        #    0.000 K/sec
                 0      cpu-migrations:u          #    0.000 K/sec
             1,092      page-faults:u             #    0.002 M/sec                    ( +-  0.08% )
     1,956,368,933      cycles:u                  #    3.372 GHz                      ( +-  0.22% )
     4,106,984,148      instructions:u            #    2.10  insn per cycle           ( +-  0.01% )
     1,087,931,864      branches:u                # 1875.143 M/sec                    ( +-  0.01% )
         7,731,041      branch-misses:u           #    0.71% of all branches          ( +-  0.15% )

           0.59680 +- 0.00193 seconds time elapsed  ( +-  0.32% )

The run time varies greatly. But it can be seen that the new code is consistently
faster.
2021-05-11 13:56:23 +02:00
Thomas Haller
7065d75b91
ifcfg-rh: avoid cloning vlans array in write_bridge_vlans() 2021-05-11 13:53:52 +02:00
Thomas Haller
f5685e5bc9
ifcfg-rh: add comment about unreachable code in write_bridge_vlans() 2021-05-11 13:53:52 +02:00
Thomas Haller
5b36f215f4
ifcfg-rh: fix code that looks like a leak in write_bridge_vlans()
"string" is leaked in the error case. But in practice, this cannot
happen because nm_bridge_vlan_to_str() cannot fail.

While at it, replace GString by NMStrBuf.

Thanks Coverity:

    Error: RESOURCE_LEAK (CWE-772):
    NetworkManager-1.31.3/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c:1565: alloc_fn: Storage is returned from allocation function "g_string_new".
    NetworkManager-1.31.3/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c:1565: var_assign: Assigning: "string" = storage returned from "g_string_new("")".
    NetworkManager-1.31.3/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c:1572: leaked_storage: Variable "string" going out of scope leaks the storage it points to.
    # 1570|           vlan_str = nm_bridge_vlan_to_str(vlan, error);
    # 1571|           if (!vlan_str)
    # 1572|->             return FALSE;
    # 1573|           if (string->len > 0)
    # 1574|               g_string_append(string, ",");
2021-05-11 13:53:52 +02:00
Fernando Fernandez Mancera
eee4332e8f
ifcfg: fix ACCEPT_ALL_MAC_ADDRESSES for virtual interfaces
The rh-ifcfg plugin was missing the writting code for
ACCEPT_ALL_MAC_ADDRESSES property in virtual interfaces.

https://bugzilla.redhat.com/show_bug.cgi?id=1942331

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>

Fixes: d946aa0c50 ('wired-setting: add support to accept-all-mac-addresses')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/846
2021-05-10 22:54:50 +02:00
Thomas Haller
2fcabf5699
all: only include "libnm-glib-aux/nm-uuid.h" where needed
Don't let "nm-core-internal.h" (which is a very popular header itself)
drag in "nm-uuid.h".
2021-05-04 15:51:51 +02:00
Thomas Haller
995c78245e
glib-aux/trivial: rename NMUuid API 2021-05-04 15:51:49 +02:00
Thomas Haller
73cfc4097a
libnm,glib-aux: add and use nm_uuid_generate_random_str*() helpers 2021-05-04 15:51:45 +02:00
Thomas Haller
05130b6e10
ifupdown: replace _str_has_prefix() by NM_STR_HAS_PREFIX() 2021-05-04 15:51:41 +02:00
Thomas Haller
21321ac736
clang-format: reformat code with clang 12
The format depends on the version of the tool. Now that Fedora 34 is
released, update to clang 12 (clang-tools-extra-12.0.0-0.3.rc1.fc34.x86_64).
2021-05-04 13:56:26 +02:00
Fernando Fernandez Mancera
d946aa0c50 wired-setting: add support to accept-all-mac-addresses
This patch is introducing the wired setting accept-all-mac-addresses
property. The value corresponds to the kernel flag IFF_PROMISC.

When accept-all-mac-address is enabled, the interface will accept all
the packets without checking the destination mac address.

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
2021-04-22 18:57:30 +00:00
Andrew Zaborowski
38ac64ba62
glib-aux: Set file timestamps in nm_utils_file_set_contents
Extend nm_utils_file_set_contents to be able to optionally set the last
access + last modification times on the file being created, in addition
to the mode.
2021-04-19 18:11:11 +02:00
Thomas Haller
5d6532f2d7
ifcfg-rh: always honor "$VLAN_ID" in ifcfg files
initscripts don't support "$VLAN_ID". They actually support "$VID",
which NetworkManager doesn't.

"$VLAN_ID" was introduced by commit 10b32be37b ('ifcfg-rh: various VLAN
cleanups'). It has a comment about "backward compatibility" for the case
where the reader would ignore "$VLAN_ID" if "$DEVICE"'s name contains
a suffix that is parsable as VLAN ID.

That is wrong. If a new feature gets introduce (like NetworkManager
supporting "$VLAN_ID"), then there is no way that an older version of the
tool -- which doesn't know the new feature yet (initscripts) -- supports it.
This is not what backward compatibility means. Backward compatibility
means that if a user has an old ifcfg-file without "$VLAN_ID", then we
continue parsing it as before.

Consider, when a user (or NetworkManager) writes a configuration

  DEVICE=vlan9
  PHYSDEV=eth0
  VLAN_ID=10

then it makes no sense to ignore VLAN_ID=10 and use "9" instead.
Otherwise the user (or NetworkManager) should not have written the
file this way.

Also, NetworkManager profiles support "connection.interface-name=vlan9"
together with "vlan.id=10". Such a configuration is valid and must be
expressible in ifcfg-rh format. The ifcfg-rh writer code did not somehow
restrict the setting of "$VLAN_ID" to account for this odd behavior. Whenever
NetworkManager in the past wrote VLAN_ID variable to file, it really meant
it.

https://bugzilla.redhat.com/show_bug.cgi?id=1907960

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/794
2021-03-29 21:12:47 +02:00
Thomas Haller
008302aa4e
all: use NM_IW_ESSID_MAX_SIZE define instead of literally 32 2021-03-18 11:38:21 +01:00
Thomas Haller
7fde244ed2
libnm: don't assert against valid s390-option keys in nm_setting_wired_add_s390_option()
Asserting against user input is not nice, because it always requires the
caller to check the value first. Don't do that.

Also, don't even check. You can set NM_SETTING_WIRED_S390_OPTIONS
property to any values (except duplicated keys). The C add function
should not be more limited than that. This is also right because
we have verify() which checks for valid settings. And it does so beyond
only checking the keys.

So you could set NM_SETTING_WIRED_S390_OPTIONS properties to invalid
keys. And you could use nm_setting_wired_add_s390_option() to set
invalid values. No need to let nm_setting_wired_add_s390_option() check
for valid keys.
2021-03-16 09:55:49 +01:00
Thomas Haller
604b1d0331
platform: move more platform code to src/libnm-platform/ 2021-03-05 11:27:16 +01:00
Thomas Haller
a8c34b9dcf
build: move "shared/nm-std-aux" to "src/libnm-std-aux" 2021-02-24 12:48:24 +01:00
Thomas Haller
9dc84b32b0
build: move "shared/nm-{glib-aux,log-null,log-core}" to "src/libnm-{glib-aux,log-null,log-core}" 2021-02-24 12:48:20 +01:00
Thomas Haller
4d12a6ac3d
build: move "shared/nm-{base,udev-aux}" to "src/libnm-{base,udev-aux}" 2021-02-24 12:48:19 +01:00
Thomas Haller
39225258d6
build: move "shared/systemd" to "src/libnm-systemd-shared" 2021-02-24 12:48:16 +01:00
Thomas Haller
341b6e0704
all: change G_LOG_DOMAIN to "nm"
glib requires G_LOG_DOMAIN defined so that log messages are labeled
to belong to NetworkManager or libnm.

However, we don't actually want to use glib logging. Our library libnm
MUST not log anything, because it spams the user's stdout/stderr.
Instead, a library must report notable events via its API. Note that
there is also LIBNM_CLIENT_DEBUG to explicitly enable debug logging,
but that doesn't use glib logging either.

Also, the daemon does not use glib logging instead it logs to syslog.
When run with `--debug`.

Hence, it's not useful for us to define different G_LOG_DOMAIN per
library/application, because none of our libraries/applications should
use glib logging.

It also gets slightly confusing, because we have the static library like
`src/libnm-core-impl`, which is both linked into `libnm` (the library)
and `NetworkManager` (the daemon). Which logging domain should they use?

Set the G_LOG_DOMAIN to "nm" everywhere. But no longer do it via `-D`
arguments to the compiler.

See-also: https://developer.gnome.org/glib/stable/glib-Message-Logging.html#G-LOG-DOMAIN:CAPS
2021-02-18 19:46:57 +01:00
Thomas Haller
fdf9614ba7
build: move "libnm-core/" to "src/" and split it
"libnm-core/" is rather complicated. It provides a static library that
is linked into libnm.so and NetworkManager. It also contains public
headers (like "nm-setting.h") which are part of public libnm API.

Then we have helper libraries ("libnm-core/nm-libnm-core-*/") which
only rely on public API of libnm-core, but are themself static
libraries that can be used by anybody who uses libnm-core. And
"libnm-core/nm-libnm-core-intern" is used by libnm-core itself.

Move "libnm-core/" to "src/". But also split it in different
directories so that they have a clearer purpose.

The goal is to have a flat directory hierarchy. The "src/libnm-core*/"
directories correspond to the different modules (static libraries and set
of headers that we have). We have different kinds of such modules because
of how we combine various code together. The directory layout now reflects
this.
2021-02-18 19:46:51 +01:00
Thomas Haller
c971ee2267
libnm: merge libnm-keyfile into libnm-core
Before there was a licensing conflict between the keyfile code
(libnm-keyfile) and libnm. The latter would require LGPL-2.1+ while
keyfile code was GPL-2.0+.

Consequently we were linking libnm-keyfile into the daemon, but not in
libnm.so.

This conflict has been resolved and keyfile API is part of libnm.so.
There is no more need to build a separate (intermediary) library. Merge
them.

This also makes sense because keyfile code needs access to private code
from libnm-core. It is closely tied to libnm-core, so that building them
separate makes no sense (anymore).
2021-02-09 12:38:19 +01:00
Thomas Haller
b13a2b27e9
all: move shared/nm-meta-setting.[hc] to libnm-core and clients
"shared/nm-meta-setting.[hc]" contains meta data about settings.
As such it is similarly used by libnm-core (as internal API) and
by clients (as extension of public API of libnm). However, it must
be compiled twice, because while it defines in both cases a
NMMetaSettingInfo type, these types are different between internal and
public API.
Hence, the files must also be compiled twice (and differently), once
against libnm-core and once against the client helper library.

Previously, the file was under "shared/", but there it's a bit odd
it doesn't clearly belong anywhere.

There are two goals here:

 - copy the file to the two places where it is used. We also have
   a "check-tree" unit test that ensures those files don't diverge in
   the future.

 - we no longer require CFLAGS set during built. Instead, the sources
   should control the build. For that we have new (simple) headers
   "nm-meta-setting-base.h" that define the right behavior for the
   impl files.

There is still an ugliness (among several): the files must be named the
same for libnm-core and clients/common. Preferably, all our sources have
unique names, but that is not possible with this scheme (without
introducing other ugliness). To mitigate that, include the files only at
one exact place.
2021-02-09 12:38:19 +01:00
Thomas Haller
dc2afc9b77
all: add "src/core/nm-default-daemon.h" as replacement for "nm-default.h" 2021-02-09 12:38:18 +01:00
Thomas Haller
f72278eff7
ethtool: add more offload features that kernel supports
New features:

 - ethtool.feature-macsec-hw-offload
 - ethtool.feature-rx-gro-list
 - ethtool.feature-rx-udp-gro-forwarding
 - ethtool.feature-tls-hw-rx-offload
 - ethtool.feature-tx-gso-list
 - ethtool.feature-tx-tunnel-remcsum-segmentation

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/735
2021-02-08 15:11:11 +01:00
Thomas Haller
ac1a9e03e4
all: move "src/" directory to "src/core/"
Currently "src/" mostly contains the source code of the daemon.
I say mostly, because that is not true, there are also the device,
settings, wwan, ppp plugins, the initrd generator, the pppd and dhcp
helper, and probably more.

Also we have source code under libnm-core/, libnm/, clients/, and
shared/ directories. That is all confusing.

We should have one "src" directory, that contains subdirectories. Those
subdirectories should contain individual parts (libraries or
applications), that possibly have dependencies on other subdirectories.
There should be a flat hierarchy of directories under src/, which
contains individual modules.

As the name "src/" is already taken, that prevents any sensible
restructuring of the code.

As a first step, move "src/" to "src/core/". This gives space to
reorganize the code better by moving individual components into "src/".

For inspiration, look at systemd's "src/" directory.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/743
2021-02-04 09:45:55 +01:00