1. 18 Apr, 2019 1 commit
    • Thomas Haller's avatar
      shared: move most of "shared/nm-utils" to "shared/nm-glib-aux" · 80db06f7
      Thomas Haller authored
      From the files under "shared/nm-utils" we build an internal library
      that provides glib-based helper utilities.
      Move the files of that basic library to a new subdirectory
      "shared/nm-glib-aux" and rename the helper library "libnm-core-base.la"
      to "libnm-glib-aux.la".
       - the name "utils" is overused in our code-base. Everything's an
         "utils". Give this thing a more distinct name.
       - there were additional files under "shared/nm-utils", which are not
         part of this internal library "libnm-utils-base.la". All the files
         that are part of this library should be together in the same
         directory, but files that are not, should not be there.
       - the new name should better convey what this library is and what is isn't:
         it's a set of utilities and helper functions that extend glib with
         funcitonality that we commonly need.
      There are still some files left under "shared/nm-utils". They have less
      a unifying propose to be in their own directory, so I leave them there
      for now. But at least they are separate from "shared/nm-glib-aux",
      which has a very clear purpose.
  2. 12 Apr, 2019 1 commit
  3. 04 Apr, 2019 4 commits
  4. 25 Mar, 2019 1 commit
  5. 13 Feb, 2019 2 commits
    • Thomas Haller's avatar
      shared: make nm_streq() and nm_streq0() inline functions · 2fa7a7c2
      Thomas Haller authored
      There is no advantage in having these as macros. Make them
      inline functions, compiler should be able to decide that they
      are in fact inlinable.
      Also, don't call g_strcmp0() for nm_streq0(). It means we first
      have to call glib function, only to call a glibc function. No need
      for this abstraction.
    • Thomas Haller's avatar
      shared: add NM_STR_HAS_SUFFIX() · 4fab0d09
      Thomas Haller authored
      Contrary to g_str_has_suffix(), it exploits the fact the the suffix length
      is known at compile time. No need to call a glib function, to find out what
      we already know, to call strcmp().
      Instead just calculate the string length and call memcmp().
  6. 07 Feb, 2019 1 commit
    • Thomas Haller's avatar
      macros: don't use __externally_visible__ attribute for clang · 06701e95
      Thomas Haller authored
      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 \
  7. 05 Feb, 2019 2 commits
  8. 04 Feb, 2019 3 commits
    • Thomas Haller's avatar
      shared: add NM_CONST_MAX() macro · b52d3e2a
      Thomas Haller authored
      There is:
       1) glib's MAX() macro, which evaluates arguments multiple times,
          but yields a constant expression, if the arguments are constant.
       2) NM's NM_MAX() macro, which evaluates arguments exactly once,
          but never yields a constant expression.
       3) systemd's MAX() which is like NM_MAX().
      Now, it's sensible to use
          char buf[MAX (A_CONSTANT, ANOTHER_CONSTANT)];
      and this works with glib's variant (1).
      However, when we include systemd headers, 1) gets redefined to 3), and
      above no longer works. That is because we we don't allow VLA and systemd's
      macro gives not a constant expression.
      Add NM_CONST_MAX() macro which is like systemd's CONST_MAX(). It can
      only operate on constant arguments.
    • Beniamino Galvani's avatar
      build: fix building with LTO · e6cf4213
      Beniamino Galvani authored
      Building with link-time optimization requires some tricks explained
      in [1].
      [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=48200#c28
    • Beniamino Galvani's avatar
  9. 15 Jan, 2019 2 commits
    • Thomas Haller's avatar
      all: add static assertion for maximumg alloca() allocated buffer · 3263cab5
      Thomas Haller authored
      Add a compile time check that the buffer that we allocate on the stack
      is reasonably small.
    • Thomas Haller's avatar
      all/trivial: rename NM_UTILS_LOOKUP_STR() to have "_A" suffix · 617bdbd8
      Thomas Haller authored
      NM_UTILS_LOOKUP_STR() uses alloca(). Partly to avoid the overhead of
      malloc(), but more important because it's convenient to use. It does
      not require to declare a varible to manage the lifetime of the heap
      It's quite safe, because the stack allocation is of a fixed size of only
      a few bytes. Overall, I think the convenience that we get (resulting in
      simpler code) outweighs the danger of stack allocation in this case. It's
      still worth it.
      However, as it uses alloca(), it still must not be used inside a (unbound)
      loop and it is obviously a macro.
      Rename the macros to have a _A() suffix. This should make the
      peculiarities more apparent.
  10. 14 Jan, 2019 1 commit
  11. 07 Jan, 2019 1 commit
    • Thomas Haller's avatar
      shared: add NM_STR_HAS_PREFIX() macro · e3ea8ecd
      Thomas Haller authored
      Commonly, the prefix is a string constant. We don't need to call
      g_str_has_prefix() for that, which first requires strlen() on
      the prefix. All the information is readily available.
      Add a macro for that.
  12. 02 Jan, 2019 1 commit
    • Thomas Haller's avatar
      shared/trivial: add comment about compat macro _NM_CC_SUPPORT_GENERIC w.r.t. C11 · 616abe86
      Thomas Haller authored
      C11 provides _Generic(). Until now we used it when the compiler supports
      it (in extended --std=gnu99 mode). In practice, now that we require C11
      it should always be present.
      We will drop compatibility code in the future. For now, just add a comment
      and keep it. The reason is, that "shared/nm-utils/nm-macros-internal.h"
      may be used by VPN plugins or applet, which may or may not yet bump to
      C11. Keeping it for now, allows for an easier update.
  13. 19 Dec, 2018 1 commit
    • Thomas Haller's avatar
      dhcp: fix static-route handling for intenal client and support multiple default routes · 9a6a3540
      Thomas Haller authored
      Preface: RFC 3442 (The Classless Static Route Option for Dynamic Host
      Configuration Protocol (DHCP) version 4) states:
         If the DHCP server returns both a Classless Static Routes option and
         a Router option, the DHCP client MUST ignore the Router option.
         Similarly, if the DHCP server returns both a Classless Static Routes
         option and a Static Routes option, the DHCP client MUST ignore the
         Static Routes option.
      - sd_dhcp_lease_get_routes() returns the combination of both option 33
      (static routes) and 121 (classless static routes). If classless static
      routes are provided, the state routes must be ignored.
      - we collect the options hash that we expose on D-Bus. For that purpose,
      we must not merge both option types as classless static routes. Instead,
      we want to expose the values like we received them originally: as two
      different options.
      - we continue our deviation from RFC 3442, when receiving classless static
      routes with option 3 (Router), we only ignore the router if we didn't
      already receive a default route via classless static routes.
      - in the past, NetworkManager treated the default route specially, and
      one device could only have one default route. That limitation was
      already (partly) lifted by commit 5c299454
      (core: rework tracking of gateway/default-route in ip-config). However,
      from DHCP we still would only accept one default route. Fix that for
      internal client. Installing multiple default routes might make sense, as
      kernel apparently can skip unreachable routers (as it notes via ICMP
      messages) (rh#1634657).
  14. 11 Dec, 2018 1 commit
  15. 01 Dec, 2018 3 commits
    • Beniamino Galvani's avatar
      shared: add double underscores to attribute names · 6dfb4227
      Beniamino Galvani authored
      From [1]:
        You may optionally specify attribute names with ‘__’ preceding and
        following the name. This allows you to use them in header files
        without being concerned about a possible macro of the same name. For
        example, you may use the attribute name __noreturn__ instead of
      [1] https://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html#Attribute-Syntax
    • Beniamino Galvani's avatar
      core: add checks on connection default properties · 446e5b27
      Beniamino Galvani authored
      Add a new CON_DEFAULT() macro that places a property name into a
      special section used at runtime to check whether it is a supported
      connection default.
      Unfortunately, this mechanism doesn't work for plugins so we have to
      enumerate the connection defaults from plugins in the daemon using
      another CON_DEFAULT_NOP() macro.
    • Thomas Haller's avatar
      shared: allow optional trailing comma in NM_MAKE_STRV() · c6f8c063
      Thomas Haller authored
      Supporting a trailing comma in NM_MAKE_STRV() can be desirable, because it
      allows to extend the code with less noise in the diff.
      Now, there may or may not be a trailing comma at the end.
      There is a downside to this: the following no longer work:
        const char *const v1[]  = NM_MAKE_STRV ("a", "b");
        const char *const v2[3] = NM_MAKE_STRV ("a", "b");
      but then, above can be written more simply already as:
        const char *const v1[]  = { "a", "b", NULL };
        const char *const v2[3] = { "a", "b" };
      so the fact that the macro won't work in that case may be preferable,
      because it forces you to use the already existing better variant.
  16. 12 Nov, 2018 1 commit
  17. 18 Oct, 2018 1 commit
    • Thomas Haller's avatar
      shared: improve length check in nm_construct_name_a() · 39bd412d
      Thomas Haller authored
      Refactor the check so that integer overflow cannot happen. Realistically,
      it anyway couldn't happen, because _name is nowhere near the size of
      G_MAXSIZE. Still, avoid such code. Also, the operands involved here are
      constants, so the extra check can anyway be resolved at compile-time.
  18. 04 Oct, 2018 1 commit
    • Thomas Haller's avatar
      shared: avoid invoking g_free() with NULL from gs_free cleanup attribute · d060b7b3
      Thomas Haller authored
      In general, it's fine to pass %NULL to g_free().
      However, consider:
          char *
          foo (void)
              gs_free char *value = NULL;
              value = g_strdup ("hi");
              return g_steal_pointer (&value);
      gs_free, gs_local_free(), and g_steal_pointer() are all inlinable.
      Here the compiler can easily recognize that we always pass %NULL to
      g_free(). But with the previous implementation, the compiler would
      not omit the call to g_free().
      Similar patterns happen all over the place:
          baz (void)
              gs_free char *value = NULL;
              if (!some_check ())
                  return FALSE;
              value = get_value ();
              if (!value)
                  return FALSE;
              return TRUE;
      in this example, g_free() is only required after setting @value to
      Note that this does increase the binary side a bit (4k for libnm, 8k
      for NetworkManager, with "-O2").
  19. 30 Sep, 2018 1 commit
    • Rafael Fontenelle's avatar
      Fix typos · 34fd6289
      Rafael Fontenelle authored
      [thaller@redhat.com: fix generated clients/common/settings-docs.h.in file
         and fix wrong change in src/systemd/src/libsystemd/sd-event/sd-event.c]
  20. 04 Sep, 2018 4 commits
    • Thomas Haller's avatar
      shared: rename PROP_0 in NM_GOBJECT_PROPERTIES_DEFINE() and skip it in nm_gobject_notify_together() · c366c155
      Thomas Haller authored
      PROP_0 is how we commonly name this property when we don't use
      Also, allow to skip PROP_0 in nm_gobject_notify_together(), that
      is handy to optionally invoke a notification, like
        nm_gobject_notify_together (obj,
                                    changed ? PROP_OTHER : PROP_0);
    • Thomas Haller's avatar
      shared: add nm-secret-utils.h helper · b2325087
      Thomas Haller authored
      We already had nm_free_secret() to clear the secret out
      of a NUL terminated string. That works well for secrets
      which are strings, it can be used with a cleanup attribute
      (nm_auto_free_secret) and as a cleanup function for a
      However, it does not work for secrets which are binary.
      For those, we must also track the length of the allocated
      data and clear it.
      Add two new structs NMSecretPtr and NMSecretBuf to help
      with that.
    • Thomas Haller's avatar
      shared: drop unnecessary NM_AUTO_DEFINE_FCN_STRUCT() macro · 74815fd8
      Thomas Haller authored
      It serves no purpose, as it just directly calls the function. We don't
      need to define this intermediary.
    • Thomas Haller's avatar
      shared: add nm_auto_unref_bytearray macro · f15d82bc
      Thomas Haller authored
      Internally, GByteArray is actually a GArray, so it would be safe to
      use "gs_unref_array" macro. However, that is rather ugly, and means
      to rely on an internal implementation detail of GByteArray.
      Instead, add a cleanup macro for GByteArray.
  21. 10 Aug, 2018 1 commit
  22. 09 Aug, 2018 1 commit
  23. 01 Aug, 2018 1 commit
    • Thomas Haller's avatar
      shared: add nm_gobject_notify_together() helper · ccf6bdb0
      Thomas Haller authored
      NM_GOBJECT_PROPERTIES_DEFINE() defines a helper function
      _notify() to emit a GObject property changed notification.
      Add another helper function to emit multiple notifications
      together, and freeze/thaw the notification before.
      This is particularly useful, because our D-Bus glue in
      "nm-dbus-object.c" hooks into dispatch_properties_changed(),
      to emit a combined PropertiesChanged signal for multiple
      properties. By carefully freezing/thawing the notifications,
      the exported objects can combine changes of multiple properties
      in one D-Bus signal.
      This helper is here to make that simpler.
      Note that the compiler still has no problem to inline _notify()
      entirey. So, in a non-debug build, there is little difference in
      the generated code. It can even nicely inline calls like
          nm_gobject_notify_together (self, PROP_ADDRESS_DATA,
  24. 24 Jul, 2018 1 commit
  25. 18 Jul, 2018 3 commits
    • Thomas Haller's avatar
    • Thomas Haller's avatar
      shared: cleanup nm_auto implementations · d0b3702b
      Thomas Haller authored
      - Reuse NM_AUTO_DEFINE*() where possible.
      - Consistently name the cleanup functions for "nm_auto_xzy" as
    • Thomas Haller's avatar
      shared/gsystem-local-alloc: merge "gsystem-local-alloc.h" into "nm-macros-shared.h" · e9d9fc3f
      Thomas Haller authored
      We only have a certain granularity of how our headers in "shared/nm-utils"
      can be used independently.
      For example, it's not supported to use "nm-macros-internal.h" without
      "gsystem-local-alloc.h". Likewise, you cannot use "nm-glib.h" directly,
      you always get it together with "nm-macros-internal.h".
      This is, we don't support to use certain headers entirely independently,
      because usually you anyway want to use them together.
      As such, no longer support "gsystem-local-alloc.h", but merge the
      remainder into "nm-macros-internal.h". There is really no reason
      to support arbitrary flexibility of including individual bits. You
      want cleanup-macros? Include "nm-macros-internal.h".
      Merge the headers.