1. 10 Aug, 2018 3 commits
    • Thomas Haller's avatar
      libnm: rework setting metadata for property handling · 37938043
      Thomas Haller authored
      NMSetting internally already tracked a list of all proper GObject properties
      and D-Bus-only properties.
      
      Rework the tracking of the list, so that:
      
      - instead of attaching the data to the GType of the setting via
        g_type_set_qdata(), it is tracked in a static array indexed by
        NMMetaSettingType. This allows to find the setting-data by simple
        pointer arithmetic, instead of taking a look and iterating (like
        g_type_set_qdata() does).
      
        Note, that this is still thread safe, because the static table entry is
        initialized in the class-init function with _nm_setting_class_commit().
        And it only accessed by following a NMSettingClass instance, thus
        the class constructor already ran (maybe not for all setting classes,
        but for the particular one that we look up).
      
        I think this makes initialization of the metadata simpler to
        understand.
        Previously, in a first phase each class would attach the metadata
        to the GType as setting_property_overrides_quark(). Then during
        nm_setting_class_ensure_properties() it would merge them and
        set as setting_properties_quark(). Now, during the first phase,
        we only incrementally build a properties_override GArray, which
        we finally hand over during nm_setting_class_commit().
      
      - sort the property infos by name and do binary search.
      
      Also expose this meta data types as internal API in nm-setting-private.h.
      While not accessed yet, it can prove beneficial, to have direct (internal)
      access to these structures.
      
      Also, rename NMSettingProperty to NMSettInfoProperty to use a distinct
      naming scheme. We already have 40+ subclasses of NMSetting that are called
      NMSetting*. Likewise, NMMetaSetting* is heavily used already. So, choose a
      new, distinct name.
      37938043
    • Thomas Haller's avatar
      libnm: use NMMetaSettingInfo for tracking setting priority · 9c47e2ce
      Thomas Haller authored
      Previously, each (non abstract) NMSetting class had to register
      its name and priority via _nm_register_setting().
      
      Note, that libnm-core.la already links against "nm-meta-setting.c",
      which also redundantly keeps track of the settings name and gtype
      as well.
      
      Re-use NMMetaSettingInfo also in libnm-core.la, to track this meta
      data.
      
      The goal is to get rid of private data structures that track
      meta data about NMSetting classes. In this case, "registered_settings"
      hash. Instead, we should have one place where all this meta data
      is tracked. This was, it is also accessible as internal API,
      which can be useful (for keyfile).
      
      Note that NMSettingClass has some overlap with NMMetaSettingInfo.
      One difference is, that NMMetaSettingInfo is const, while NMSettingClass
      is only initialized during the class_init() method. Appart from that,
      it's mostly a matter of taste, whether we attach meta data to
      NMSettingClass, to NMMetaSettingInfo, or to a static-array indexed
      by NMMetaSettingType.
      
      Note, that previously, _nm_register_setting() was private API. That
      means, no user could subclass a functioning NMSetting instance. The same
      is still true: NMMetaSettingInfo is internal API and users cannot access
      it to create their own NMSetting subclasses. But that is almost desired.
      libnm is not designed, to be extensible via subclassing, nor is it
      clear why that would be a useful thing to do. One day, we should remove
      the NMSetting and NMSettingClass definitions from public headers. Their
      only use is subclassing the types, which however does not work.
      
      While libnm-core was linking already against nm-meta-setting.c,
      nm_meta_setting_infos was unreferenced. So, this change increases
      the binary size of libnm and NetworkManager (1032 bytes). Note however
      that roughly the same information was previously allocated at runtime.
      9c47e2ce
    • Thomas Haller's avatar
      libnm/trivial: cleanup variable names in settings' class-init functions · 23adc373
      Thomas Haller authored
      - Don't use @parent_class name. This local variable (and @object_class) is
        the class instance up-cast to the pointer types of the parents. The point
        here is not that it is the direct parent. The point is, that it's the
        NMSettingClass type.
        Also, it can only be used inconsistently, in face of NMSettingIP4Config,
        who's parent type is NMSettingIPConfig. Clearly, inside
        nm-setting-ip4-config.c we wouldn't want to use the "parent_class"
        name. Consistently rename @parent_class to @setting_class.
      
      - Also rename the pointer to the own class to @klass. "setting_class" is also the
        wrong name for that, because the right name would be something like
        "setting_6lowpan_class".
        However, "klass" is preferred over the latter, because we commonly create new
        GObject implementations by copying an existing one. Generic names like "klass"
        and "self" inside a type implementation make that simpler.
      
      - drop useless comments like
      
           /* virtual functions */
           /* Properties */
      
        It's better to logically and visually structure the code, and avoid trival
        remarks about that. They only end up being used inconsistently. If you
        even need a stronger visual separator, then an 80 char /****/ line
        should be preferred.
      23adc373
  2. 11 Jul, 2018 1 commit
    • Thomas Haller's avatar
      all: don't use gchar/gshort/gint/glong but C types · e1c7a2b5
      Thomas Haller authored
      We commonly don't use the glib typedefs for char/short/int/long,
      but their C types directly.
      
          $ git grep '\<g\(char\|short\|int\|long\|float\|double\)\>' | wc -l
          587
          $ git grep '\<\(char\|short\|int\|long\|float\|double\)\>' | wc -l
          21114
      
      One could argue that using the glib typedefs is preferable in
      public API (of our glib based libnm library) or where it clearly
      is related to glib, like during
      
        g_object_set (obj, PROPERTY, (gint) value, NULL);
      
      However, that argument does not seem strong, because in practice we don't
      follow that argument today, and seldomly use the glib typedefs.
      Also, the style guide for this would be hard to formalize, because
      "using them where clearly related to a glib" is a very loose suggestion.
      
      Also note that glib typedefs will always just be typedefs of the
      underlying C types. There is no danger of glib changing the meaning
      of these typedefs (because that would be a major API break of glib).
      
      A simple style guide is instead: don't use these typedefs.
      
      No manual actions, I only ran the bash script:
      
        FILES=($(git ls-files '*.[hc]'))
        sed -i \
            -e 's/\<g\(char\|short\|int\|long\|float\|double\)\>\( [^ ]\)/\1\2/g' \
            -e 's/\<g\(char\|short\|int\|long\|float\|double\)\>  /\1   /g' \
            -e 's/\<g\(char\|short\|int\|long\|float\|double\)\>/\1/g' \
            "${FILES[@]}"
      e1c7a2b5
  3. 01 Jul, 2018 1 commit
    • Thomas Haller's avatar
      libnm: avoid constructor function for registering NMSetting types · fa9fe466
      Thomas Haller authored
      constructor functions are ugly, because code is running before
      main() starts. Instead, as the registration code for NMSetting types
      is insid the GType constructor, we just need to ensure at the
      right place, that the GType was created.
      
      The right place here is _register_settings_ensure_inited(), because
      that is called before we need the registration information.
      fa9fe466
  4. 26 Mar, 2018 2 commits
  5. 15 Dec, 2017 1 commit
    • Thomas Haller's avatar
      all: don't use NM_FLAGS_HAS() with non-constant argument · c696a226
      Thomas Haller authored
      NM_FLAGS_HAS() uses a static-assert that the second argument is a
      single flag (power of two). With a single flag, NM_FLAGS_HAS(),
      NM_FLAGS_ANY() and NM_FLAGS_ALL() are all identical.
      
      The second argument must be a compile time constant, and if that is
      not the case, one must not use NM_FLAGS_HAS().
      
      Use NM_FLAGS_ANY() in these cases.
      c696a226
  6. 08 Dec, 2017 1 commit
    • Thomas Haller's avatar
      libnm: use nm_utils_named_values_from_str_dict() · b11eac1a
      Thomas Haller authored
      Make use of NMUtilsNamedValue in nm_utils_format_variant_attributes().
      This avoids creating a GList and sorting it.
      
      Also, reuse nm_utils_named_values_from_str_dict() in
      nm_setting_bond_get_option().
      b11eac1a
  7. 21 Nov, 2017 3 commits
  8. 16 Nov, 2017 1 commit
    • Thomas Haller's avatar
      all: use nm_str_hash() instead of g_str_hash() · a6be2f4a
      Thomas Haller authored
      We also do this for libnm and libnm-core, where it causes visible changes
      in behavior. But if somebody would rely on the hashing implementation
      for hash tables, it would be seriously flawed.
      a6be2f4a
  9. 11 Aug, 2017 1 commit
  10. 22 Jun, 2017 1 commit
  11. 07 Jun, 2017 1 commit
  12. 05 Jun, 2017 1 commit
    • Beniamino Galvani's avatar
      libnm-core: remove unsupported bond options during normalization · f25e008e
      Beniamino Galvani authored
      In an ideal world, we should not validate connections containing
      options not valid for the current bond mode. However adding such
      restriction now means that during an upgrade to the new NM version
      some connections that were valid before become invalid, possibly
      disrupting connectivity.
      
      Instead, consider invalid options as a normalizable error and remove
      them during normalization.
      
      Converting the setting to a "canonical" form without invalid options
      is important for the connection matching logic, where such invalid
      options can cause false mismatches.
      f25e008e
  13. 02 Jun, 2017 1 commit
    • Thomas Haller's avatar
      all: replace uses of inet_aton() and friends · ea6648ce
      Thomas Haller authored
      rpmdiff complains about uses of inet_aton, inet_makeaddr, inet_netof,
      inet_ntoa under the IPv6 section:
      
         usr/sbin/NetworkManager on aarch64 i686 x86_64 ppc ppc64 ppc64le s390 s390x uses function inet_aton, which may impact IPv6 support
      
      I think the warning is bogus, but refactor our code to avoid it.
      
      Note that systemd code still uses them, so it don't avoid the rpmdiff
      warning. But let's not diverge our systemd import from upstream for this.
      
      - for NMSettingBond:validate_ip() also avoid g_strsplit_set() which
        allocates a full strv. Instead, we can do with one g_strdup().
      
      - for test-resolvconf-capture.c, replace the functions with macros.
        Macros should be avoided usually, but for test asserts they are
        more convenient as they preserved the __FILE__:__LINE__ of where
        the assertion fails.
      ea6648ce
  14. 31 May, 2017 1 commit
  15. 27 Apr, 2017 2 commits
  16. 28 Mar, 2017 1 commit
    • Thomas Haller's avatar
      libnm: document to allow omitting argument to get-options functions · 1601d2ca
      Thomas Haller authored
      These functions return static information, and don't require
      a @setting argument. The list of options is interesting even
      when having now setting instance at hand.
      
      Document this to promise the user that passing %NULL is allowed.
      
      It was allowed since when those functions were added.
      1601d2ca
  17. 06 Feb, 2017 1 commit
    • Thomas Haller's avatar
      build: fix -Wold-style-declaration warnings · cb365b33
      Thomas Haller authored
          libnm-core/nm-setting-bond.c:502:1: error: ‘static’ is not at beginning of declaration [-Werror=old-style-declaration]
           const static struct {
           ^~~~~
      
          In file included from clients/cli/common.c:32:0:
          ./clients/common/nm-vpn-helpers.h:27:1: error: ‘typedef’ is not at beginning of declaration [-Werror=old-style-declaration]
           } typedef VpnPasswordName;
          ^
      cb365b33
  18. 06 Jan, 2017 1 commit
  19. 22 Sep, 2016 1 commit
    • Thomas Haller's avatar
      libnm: relax comparison of bond-option for INFERRABLE match · 0fb723e7
      Thomas Haller authored
      When comparing the bond-settings of an activated device against
      the settings from the connection, some properties might easily
      differ. Hack them around in NMSettingBond:compare_property().
      
      For example:
      
      the setting in the connection has:
          [bond]
          mode=active-backup
      
      later, the device gets:
          [bond]
          active_slave=inf_ib0
          fail_over_mac=active
          mode=active-backup
      
      Note that the fail_over_mac changes due to:
        kernel: nm-bond: enslaved VLAN challenged slave inf_ib0. Adding VLANs will be blocked as long as inf_ib0 is part of bond nm-bond
        kernel: nm-bond: The slave device specified does not support setting the MAC address
        kernel: nm-bond: Setting fail_over_mac to active for active-backup mode
      
      https://bugzilla.redhat.com/show_bug.cgi?id=1375558
      0fb723e7
  20. 06 Jul, 2016 2 commits
  21. 29 Mar, 2016 4 commits
  22. 19 Feb, 2016 1 commit
    • Thomas Haller's avatar
      all: cleanup includes and let "nm-default.h" include "config.h" · 8bace23b
      Thomas Haller authored
      - All internal source files (except "examples", which are not internal)
        should include "config.h" first. As also all internal source
        files should include "nm-default.h", let "config.h" be included
        by "nm-default.h" and include "nm-default.h" as first in every
        source file.
        We already wanted to include "nm-default.h" before other headers
        because it might contains some fixes (like "nm-glib.h" compatibility)
        that is required first.
      
      - After including "nm-default.h", we optinally allow for including the
        corresponding header file for the source file at hand. The idea
        is to ensure that each header file is self contained.
      
      - Don't include "config.h" or "nm-default.h" in any header file
        (except "nm-sd-adapt.h"). Public headers anyway must not include
        these headers, and internal headers are never included after
        "nm-default.h", as of the first previous point.
      
      - Include all internal headers with quotes instead of angle brackets.
        In practice it doesn't matter, because in our public headers we must
        include other headers with angle brackets. As we use our public
        headers also to compile our interal source files, effectively the
        result must be the same. Still do it for consistency.
      
      - Except for <config.h> itself. Include it with angle brackets as suggested by
        https://www.gnu.org/software/autoconf/manual/autoconf.html#Configuration-Headers
      8bace23b
  23. 05 Aug, 2015 1 commit
  24. 13 Jan, 2015 2 commits
  25. 19 Nov, 2014 2 commits
    • Dan Winship's avatar
      libnm: Override parts of nm-setting-docs.xml · 36156b70
      Dan Winship authored
      Add "---dbus---" sections to the NMSetting property docs, in the same
      style as the plugin docs, parse them out into a file
      "nm-setting-docs-overrides.xml", and use them to override the GObject
      property docs in nm-setting-docs.xml.
      
      This lets us put more D-Bus-specific information in the setting docs,
      without cluttering up the property docs, and it also lets us document
      dbus-only properties.
      36156b70
    • Dan Winship's avatar
      libnm, libnm-util: move settings doc generation to libnm-core · c1448698
      Dan Winship authored
      Move the settings/plugins doc generation from libnm-util to
      libnm-core, since libnm-util isn't being updated for all new
      properties.
      
      With this commit, the keyfile and ifcfg-rh documentation is basically
      unchanged, except that deprecated properties are now gone, and new
      properties have been added, and the sections are in a different order.
      (generate-plugin-docs.pl just outputs the settings in Makefile order,
      and they were unsorted in libnm-util, but are sorted in libnm-core).
      
      The settings documentation used for nm-settings.5, the D-Bus API docs,
      and the nmcli help is changed a bit more at this point, and mostly for
      the worse, since the libnm-core setting properties don't match up with
      the D-Bus API as well as the libnm-util ones do. To be fixed...
      
      (I also removed the "plugins docs" line in each plugin docs comment
      block while moving them, since those blocks will be used for more than
      just plugins soon, and it's sort of obvious anyway.)
      c1448698
  26. 15 Nov, 2014 1 commit
    • Dan Winship's avatar
      libnm: add some missing (transfer) annotations · a41aff37
      Dan Winship authored
      All the old "const GByteArray" methods got changed to return a GBytes
      instead, but since they aren't declared "const" any more, we need to
      explicitly annotate them "(transfer none)".
      
      Also, the scanner apparently doesn't recognize that an (out)
      "const char **" is "(transfer none)", so annotate that in two places
      too
      a41aff37
  27. 13 Nov, 2014 2 commits
    • Dan Winship's avatar
      libnm*: fix library gettext usage · 53f5e9af
      Dan Winship authored
      Libraries need to include <gi18n-lib.h>, not <gi18n.h>, so that _()
      will get defined to "dgettext (GETTEXT_DOMAIN, string)" rather than
      "gettext (string)" (which will use the program's default domain, which
      works fine for programs in the NetworkManager tree, but not for
      external users). Likewise, we need to call bindtextdomain() so that
      gettext can find the translations if the library is installed in a
      different prefix from the program using it (and
      bind_textdomain_codeset(), so it will know the translations are in
      UTF-8 even if the locale isn't).
      
      (The fact that no one noticed this was broken before is because the
      libraries didn't really start returning useful translated strings much
      until 0.9.10, and none of the out-of-tree clients have been updated to
      actually show those strings to users yet.)
      53f5e9af
    • Dan Winship's avatar
      all: consistently include config.h · 3bfb163a
      Dan Winship authored
      config.h should be included from every .c file, and it should be
      included before any other include. Fix that.
      
      (As a side effect of how I did this, this also changes us to
      consistently use "config.h" rather than <config.h>. To the extent that
      it matters [which is not much], quotes are more correct anyway, since
      we're talking about a file in our own build tree, not a system
      include.)
      3bfb163a