NetworkManager/src
Thomas Haller 5022aff2c8
libnm: rework verify/normalize of "ovs-port.trunks" property
Since normalize already sorts the array, and verify needs to check
whether the array is sorted, we can implement verify() more efficiently.

In the usual case (where the property is normalized), we can just
iterate over the list and check that the ranges are increasing and
non-overlapping.

Only if that fails, do a shallow-copy of the array, sort it, and check
again. If it's still invalid after sorting, verification fails.

We don't need to create a GHashTable which adds all elements in between
the ranges. While the algorithm with hash table is O(n), the new version
with sorting is O(n*ln(n)). But of course, since the overall number of
range elements is limited to 4096, they are really both O(1). But more
importantly, it's just faster to iterate over the list and sort it, than
to fill a hash table.

---

Test with -O2, more-asserts=0:

  diff --git c/src/libnm-core-impl/tests/test-setting.c w/src/libnm-core-impl/tests/test-setting.c
  index 00fc838d1794..a0991b36d9d7 100644
  --- c/src/libnm-core-impl/tests/test-setting.c
  +++ w/src/libnm-core-impl/tests/test-setting.c
  @@ -5266,5 +5266,5 @@ static void
   test_ovs_port_trunks(void)
   {
  -    const guint                   N_RUN = 10;
  +    const guint                   N_RUN = 10000;
       guint                         i_run;
       gs_unref_object NMConnection *con = NULL;

  $ make -j src/libnm-core-impl/tests/test-setting && \
  libtool --mode=execute \
    perf stat -r 5 -B \
      src/libnm-core-impl/tests/test-setting -p /libnm/test_ovs_port_trunks

Before:

          8,114.55 msec task-clock:u                     #    0.998 CPUs utilized            ( +-  0.20% )
                 0      context-switches:u               #    0.000 /sec
                 0      cpu-migrations:u                 #    0.000 /sec
               341      page-faults:u                    #   41.980 /sec                     ( +-  0.16% )
    25,172,559,932      cycles:u                         #    3.099 GHz                      ( +-  0.12% )
    39,221,096,221      instructions:u                   #    1.56  insn per cycle           ( +-  0.04% )
     5,721,519,798      branches:u                       #  704.373 M/sec                    ( +-  0.07% )
       230,728,395      branch-misses:u                  #    4.04% of all branches          ( +-  0.28% )

            8.1340 +- 0.0179 seconds time elapsed  ( +-  0.22% )

After:

          4,300.62 msec task-clock:u                     #    0.999 CPUs utilized            ( +-  0.34% )
                 0      context-switches:u               #    0.000 /sec
                 0      cpu-migrations:u                 #    0.000 /sec
               342      page-faults:u                    #   79.435 /sec                     ( +-  0.20% )
    13,231,554,996      cycles:u                         #    3.073 GHz                      ( +-  0.27% )
    20,676,554,955      instructions:u                   #    1.55  insn per cycle           ( +-  0.07% )
     3,101,429,604      branches:u                       #  720.354 M/sec                    ( +-  0.11% )
       118,808,950      branch-misses:u                  #    3.83% of all branches          ( +-  0.34% )

            4.3068 +- 0.0143 seconds time elapsed  ( +-  0.33% )
2023-01-17 16:40:52 +01:00
..
c-list c-list: re-import git-subtree for 'src/c-list' 2022-07-19 09:02:36 +02:00
c-rbtree c-rbtree: re-import git-subtree for 'src/c-rbtree' 2022-11-23 18:00:31 +01:00
c-siphash c-siphash: re-import git-subtree for 'src/c-siphash' 2022-11-23 18:00:33 +01:00
c-stdaux c-stdaux: re-import git-subtree for 'src/c-stdaux' 2022-12-16 13:47:32 +01:00
contrib all: adjust glib-mkenums annotations for automated formatting 2022-02-08 11:14:01 +01:00
core libnm: allocate internal array for "ovs-port.trunks" only when needed 2023-01-17 16:40:51 +01:00
libnm-base libnm-base: fix bogus and unnecessary cast in nm_ethtool_data_get_by_optname() 2022-12-06 17:10:44 +01:00
libnm-client-aux-extern libnm: add internal nmc_client_has_{version_info_v,version_info_capability,capability}() helper 2022-12-14 17:33:56 +01:00
libnm-client-impl all: add support for ovs-dpdk n-rxq-desc and n-txq-desc 2023-01-17 08:45:04 +01:00
libnm-client-public core: add "VersionInfo" property on D-Bus and NMClient 2022-12-14 17:31:15 +01:00
libnm-client-test build/meson: add dependency libnm_client_public_dep for "libnm-client-test" 2022-05-04 08:56:58 +02:00
libnm-core-aux-extern format: reformat source tree with clang-format 13.0 2021-11-29 09:31:09 +00:00
libnm-core-aux-intern libnm: add nm_auto_unref_range cleanup macro 2023-01-17 16:40:51 +01:00
libnm-core-impl libnm: rework verify/normalize of "ovs-port.trunks" property 2023-01-17 16:40:52 +01:00
libnm-core-intern ovs: add support for "other_config" settings 2023-01-11 21:49:36 +01:00
libnm-core-public all: add support for ovs-dpdk n-rxq-desc and n-txq-desc 2023-01-17 08:45:04 +01:00
libnm-crypto all: fix various "-Wcast-align=strict" warnings 2022-12-09 09:15:56 +01:00
libnm-glib-aux glib-aux: use struct initialization in nm_dedup_multi_index_new() 2023-01-17 16:26:51 +01:00
libnm-lldp lldp: add libnm-lldp as fork of systemd's sd_lldp_rx 2022-10-25 10:59:00 +02:00
libnm-log-core glib-aux: drop nm_str_buf_init() for NM_STR_BUF_INIT() 2022-05-09 19:18:30 +02:00
libnm-log-null all: add some README.md files describing the purpose of our sources 2021-08-19 17:51:11 +02:00
libnm-platform libnm,platform: fix range for "weight" property of next hops for routes 2023-01-17 14:05:13 +01:00
libnm-std-aux all: use _NM_G_TYPE_CHECK_INSTANCE_CAST() for internal uses 2022-12-16 10:55:03 +01:00
libnm-systemd-core systemd: fix various "-Wcast-align=strict" warnings 2022-12-09 09:15:56 +01:00
libnm-systemd-shared systemd: fix various "-Wcast-align=strict" warnings 2022-12-09 09:15:56 +01:00
libnm-udev-aux format: reformat source tree with clang-format 13.0 2021-11-29 09:31:09 +00:00
libnmc-base all: use _NM_G_TYPE_CHECK_INSTANCE_CAST() for internal uses 2022-12-16 10:55:03 +01:00
libnmc-setting all: add support for ovs-dpdk n-rxq-desc and n-txq-desc 2023-01-17 08:45:04 +01:00
libnmt-newt all: use _NM_G_TYPE_CHECK_INSTANCE_CAST() for internal uses 2022-12-16 10:55:03 +01:00
linux-headers all: add src/nm-compat-headers for patching included system headers 2022-09-23 11:43:33 +02:00
n-acd modules: patch meson subprojects to use local dependencies 2022-07-25 10:27:33 +02:00
n-dhcp4 n-dhcp4: re-import git-subtree for 'src/n-dhcp4' 2022-08-11 14:47:04 +02:00
nm-cloud-setup all: use _NM_G_TYPE_CHECK_INSTANCE_CAST() for internal uses 2022-12-16 10:55:03 +01:00
nm-compat-headers all: add src/nm-compat-headers for patching included system headers 2022-09-23 11:43:33 +02:00
nm-daemon-helper daemon-helper: include "libnm-std-aux/nm-default-std.h" as first in "nm-daemon-helper.c" 2022-05-09 19:20:19 +02:00
nm-dispatcher clang-format: reformat code with clang-format 15.0.4-1.fc37 2022-11-23 09:17:21 +01:00
nm-initrd-generator clang-format: reformat code with clang-format 15.0.4-1.fc37 2022-11-23 09:17:21 +01:00
nm-online clang-format: reformat code with clang-format 15.0.4-1.fc37 2022-11-23 09:17:21 +01:00
nm-priv-helper all: drop redundant includes 2022-05-09 19:20:18 +02:00
nmcli all: add support for ovs-dpdk n-rxq-desc and n-txq-desc 2023-01-17 08:45:04 +01:00
nmtui nmtui: fix memory leak 2022-12-22 11:48:59 +01:00
tests all: add new "ipv[46].auto-route-ext-gw" setting 2023-01-09 09:35:52 +01:00
meson.build Squashed 'src/c-stdaux/' changes from 4e78ffaea49d..2d3877aabd7d 2022-11-23 18:00:35 +01:00
README.md nm-sudo: rename to nm-priv-helper 2022-01-11 21:46:55 +01:00

src/

Most of the subdirectories are static helper libraries, which get linked into one of the final build artifacts (like libnm, nmcli or NetworkManager). Static libraries are internal API.

The only public API is libnm, which is a shared library provided client implementations.

Our own clients (like nmcli and nmtui) also use libnm, the shared library. But they also use additional static helper libraries.

The daemon statically links against a part of libnm, the part that provides connection profiles. That is libnm-core. libnm-core is thus statically linked with libnm and the daemon. It does not get linked by clients that already link with libnm (like nmtui).

Read the individual README.md files in the subdirectories for details:

Directory Description
core/ the NetworkManager daemon
nmcli/ nmcli application, a command line client for NetworkManager
nmtui/ nmtui application, a text UI client for NetworkManager
nm-cloud-setup/ service to automatically configure NetworkManager in cloud environment
nm-initrd-generator/ generates NetworkManager configuration by parsing kernel command line options for dracut/initrd
nm-dispatcher/ NetworkManager-dispatcher service to run user scripts
nm-online/ application which checks whether NetworkManager is done, for implementing NetworkManager-wait-online.service
nm-priv-helper/ internal service for privileged operations
nm-daemon-helper/ internal helper binary spawned by NetworkManager
libnm-std-aux/ internal helper library for standard C
libnm-glib-aux/ internal helper library for glib
libnm-log-null/ internal helper library with dummy (null) logging backend
libnm-log-core/ internal helper library with logging backend (syslog) used by daemon
libnm-base/ internal helper library with base definitions
libnm-platform/ internal helper library for netlink and other platform/kernel API
libnm-udev-aux/ internal helper library for libudev
libnm-core-public/ public API of libnm (libnm-core part)
libnm-core-intern/ internal API of libnm-core, used by libnm and daemon
libnm-core-impl/ implementation of libnm-core
libnm-core-aux-intern/ internal helper library on top of libnm-core (used by libnm-core itself)
libnm-core-aux-extern/ internal helper library on top of libnm-core (not used by libnm-core)
libnm-client-public/ public API of libnm (NMClient part)
libnm-client-impl/ implementation of libnm (NMClient)
libnm-client-aux-extern/ internal helper library on top of libnm (not used by libnm itself)
libnmc-base/ internal helper library for libnm clients
libnmc-setting/ internal helper library for setting connection profiles (used by nmcli)
libnmt-newt/ internal helper library for libnewt for nmtui
linux-headers/ extra Linux kernel UAPI headers
contrib/ sources that are not used by NetworkManager itself
tests/ unit tests that are not specific to one of the other directories
libnm-client-test/ internal helper library with test utils for libnm
c-list/ fork of c-util helper library for intrusive, doubly linked list
c-rbtree/ fork of c-util helper library for intrusive Red-Black Tree
c-siphash/ fork of c-util helper library for SIPHash24
c-stdaux/ fork of c-util general purpose helpers for standard C
n-acd/ fork of nettools IPv4 ACD library
n-dhcp4/ fork of nettools DHCPv4 library
libnm-systemd-core/ fork of systemd code as network library
libnm-systemd-shared/ fork of systemd code as general purpose library