1. 11 Dec, 2018 1 commit
    • Thomas Haller's avatar
      dbus: add nm_dbus_manager_get_dbus_connection() helper · 703178f5
      Thomas Haller authored
      The NMDBusManager owns a reference to the system bus. Expose it, so we
      can use it. Note that g_bus_get() -- as alternative to get the systembus
      singleton -- is asynchronous, and g_bus_get_sync() has an API that makes
      one wonder what it does. Since we already have a reference to the connection
      object we want to use, expose it.
      703178f5
  2. 28 Aug, 2018 1 commit
    • Thomas Haller's avatar
      settings: use delegation instead of inheritance for NMSettingsConnection and NMConnection · 38273a88
      Thomas Haller authored
      NMConnection is an interface, which is implemented by the types
      NMSimpleConnection (libnm-core), NMSettingsConnection (src) and
      NMRemoteConnection (libnm).
      
      NMSettingsConnection does a lot of things already:
      
        1) it "is-a" NMDBusObject and exports the API of a connection profile
           on D-Bus
        2) it interacts with NMSettings and contains functionality
           for tracking the profiles.
        3) it is the base-class of types like NMSKeyfileConnection and
           NMIfcfgConnection. These handle how the profile is persisted
           on disk.
        4) it implements NMConnection interface, to itself track the
           settings of the profile.
      
      3) and 4) would be better implemented via delegation than inheritance.
      
      Address 4) and don't let NMSettingsConnection implemente the NMConnection
      interface. Instead, a settings-connection references now a NMSimpleConnection
      instance, to which it delegates for keeping the actual profiles.
      
      Advantages:
      
        - by delegating, there is a clearer separation of what
          NMSettingsConnection does. For example, in C we often required
          casts from NMSettingsConnection to NMConnection. NMConnection
          is a very trivial object with very little logic. When we have
          a NMConnection instance at hand, it's good to know that it is
          *only* that simple instead of also being an entire
          NMSettingsConnection instance.
      
          The main purpose of this patch is to simplify the code by separating
          the NMConnection from the NMSettingsConnection. We should generally
          be aware whether we handle a NMSettingsConnection or a trivial
          NMConnection instance. Now, because NMSettingsConnection no longer
          "is-a" NMConnection, this distinction is apparent.
      
        - NMConnection is implemented as an interface and we create
          NMSimpleConnection instances whenever we need a real instance.
          In GLib, interfaces have a performance overhead, that we needlessly
          pay all the time. With this change, we no longer require
          NMConnection to be an interface. Thus, in the future we could compile
          a version of libnm-core for the daemon, where NMConnection is not an
          interface but a GObject implementation akin to NMSimpleConnection.
      
        - In the previous implementation, we cannot treat NMConnection immutable
          and copy-on-write.
          For example, when NMDevice needs a snapshot of the activated
          profile as applied-connection, all it can do is clone the entire
          NMSettingsConnection as a NMSimpleConnection.
          Likewise, when we get a NMConnection instance and want to keep
          a reference to it, we cannot do that, because we never know
          who also references and modifies the instance.
          By separating NMSettingsConnection we could in the future have
          NMConnection immutable and copy-on-write, to avoid all unnecessary
          clones.
      38273a88
  3. 24 Apr, 2018 1 commit
    • Thomas Haller's avatar
      core/dbus: stop NMDBusManager and reject future method calls · 3d2da8cd
      Thomas Haller authored
      During shutdown, we will need to still iterate the main loop
      to do a coordinated shutdown. Currently we do not, and we just
      exit, leaving a lot of objects hanging.
      
      If we are going to fix that, we need during shutdown tell
      NMDBusManager to reject all future operations.
      
      Note that property getters and "GetManagerObjects" call is not
      blocked. It continues to work.
      
      Certainly for some operations, we want to allow them to be called even
      during shutdown. However, these have to opt-in.
      
      This also fixes an uglyness, where nm_dbus_manager_start() would
      get the set-property-handler and the @manager as user-data. However,
      NMDBusManager will always outlife NMManager, hence, after NMManager
      is destroyed, the user-data would be a dangling pointer. Currently
      that is not an issue, because
        - we always leak NMManager
        - we don't run the mainloop during shutdown
      3d2da8cd
  4. 23 Apr, 2018 1 commit
    • Beniamino Galvani's avatar
      core: fix bus initialization order · 4672499b
      Beniamino Galvani authored
      We currently start the bus manager only after the creation of a
      NMManager because the NMManager is needed to handle set-property bus
      calls. However, objects created by NMManager
      (e.g. NMDnsSystemdResolved) need a bus connection and so their
      initialization currently fail.
      
      To fix this, split nm_dbus_manager_start() in two parts: first only
      create the connection and acquire the bus.  After this step the
      NMManager can be set up. In the second step, set NMManager as the
      set-property handler and start exporting objects on the bus.
      
      Fixes: 297d4985
      4672499b
  5. 12 Mar, 2018 2 commits
    • Thomas Haller's avatar
      core/dbus: rework D-Bus implementation to use lower layer GDBusConnection API · 297d4985
      Thomas Haller authored
      Previously, we used the generated GDBusInterfaceSkeleton types and glued
      them via the NMExportedObject base class to our NM types. We also used
      GDBusObjectManagerServer.
      
      Don't do that anymore. The resulting code was more complicated despite (or
      because?) using generated classes. It was hard to understand, complex, had
      ordering-issues, and had a runtime and memory overhead.
      
      This patch refactors this entirely and uses the lower layer API GDBusConnection
      directly. It replaces the generated code, GDBusInterfaceSkeleton, and
      GDBusObjectManagerServer. All this is now done by NMDbusObject and NMDBusManager
      and static descriptor instances of type GDBusInterfaceInfo.
      
      This adds a net plus of more then 1300 lines of hand written code. I claim
      that this implementation is easier to understand. Note that previously we
      also required extensive and complex glue code to bind our objects to the
      generated skeleton objects. Instead, now glue our objects directly to
      GDBusConnection. The result is more immediate and gets rid of layers of
      code in between.
      Now that the D-Bus glue us more under our control, we can address issus and
      bottlenecks better, instead of adding code to bend the generated skeletons
      to our needs.
      
      Note that the current implementation now only supports one D-Bus connection.
      That was effectively the case already, although there were places (and still are)
      where the code pretends it could also support connections from a private socket.
      We dropped private socket support mainly because it was unused, untested and
      buggy, but also because GDBusObjectManagerServer could not export the same
      objects on multiple connections. Now, it would be rather straight forward to
      fix that and re-introduce ObjectManager on each private connection. But this
      commit doesn't do that yet, and the new code intentionally supports only one
      D-Bus connection.
      Also, the D-Bus startup was simplified. There is no retry, either nm_dbus_manager_start()
      succeeds, or it detects the initrd case. In the initrd case, bus manager never tries to
      connect to D-Bus. Since the initrd scenario is not yet used/tested, this is good enough
      for the moment. It could be easily extended later, for example with polling whether the
      system bus appears (like was done previously). Also, restart of D-Bus daemon isn't
      supported either -- just like before.
      
      Note how NMDBusManager now implements the ObjectManager D-Bus interface
      directly.
      
      Also, this fixes race issues in the server, by no longer delaying
      PropertiesChanged signals. NMExportedObject would collect changed
      properties and send the signal out in idle_emit_properties_changed()
      on idle. This messes up the ordering of change events w.r.t. other
      signals and events on the bus. Note that not only NMExportedObject
      messed up the ordering. Also the generated code would hook into
      notify() and process change events in and idle handle, exhibiting the
      same ordering issue too.
      No longer do that. PropertiesChanged signals will be sent right away
      by hooking into dispatch_properties_changed(). This means, changing
      a property in quick succession will no longer be combined and is
      guaranteed to emit signals for each individual state. Quite possibly
      we emit now more PropertiesChanged signals then before.
      However, we are now able to group a set of changes by using standard
      g_object_freeze_notify()/g_object_thaw_notify(). We probably should
      make more use of that.
      
      Also, now that our signals are all handled in the right order, we
      might find places where we still emit them in the wrong order. But that
      is then due to the order in which our GObjects emit signals, not due
      to an ill behavior of the D-Bus glue. Possibly we need to identify
      such ordering issues and fix them.
      
      Numbers (for contrib/rpm --without debug on x86_64):
      
      - the patch changes the code size of NetworkManager by
        - 2809360 bytes
        + 2537528 bytes (-9.7%)
      
      - Runtime measurements are harder because there is a large variance
        during testing. In other words, the numbers are not reproducible.
        Currently, the implementation performs no caching of GVariants at all,
        but it would be rather simple to add it, if that turns out to be
        useful.
        Anyway, without strong claim, it seems that the new form tends to
        perform slightly better. That would be no surprise.
      
        $ time (for i in {1..1000}; do nmcli >/dev/null || break; echo -n .;  done)
        - real    1m39.355s
        + real    1m37.432s
      
        $ time (for i in {1..2000}; do busctl call org.freedesktop.NetworkManager /org/freedesktop org.freedesktop.DBus.ObjectManager GetManagedObjects > /dev/null || break; echo -n .; done)
        - real    0m26.843s
        + real    0m25.281s
      
      - Regarding RSS size, just looking at the processes in similar
        conditions, doesn't give a large difference. On my system they
        consume about 19MB RSS. It seems that the new version has a
        slightly smaller RSS size.
        - 19356 RSS
        + 18660 RSS
      297d4985
    • Thomas Haller's avatar
      core: rename "nm-bus-manager.h" to "nm-dbus-manager.h" · a1f37964
      Thomas Haller authored
      The next commit will completely rework NMBusManager and replace
      NMExportedObject by a new type NMDBusObject.
      
      Originally, NMDBusObject was added along NMExportedObject to ease
      the rework and have compilable, intermediate stages of refactoring. Now,
      I think the new name is better, because NMDBusObject is very strongly related
      to the bus manager and the old name NMExportedObject didn't make that
      clear.
      
      I also slighly prefer the name NMDBusObject over NMBusObject, hence
      for consistancy, also rename NMBusManager to NMDBusManager.
      
      This commit only renames the file for a nicer diff in the next commit.
      It does not actually update the type name in sources. That will be done
      later.
      a1f37964
  6. 04 Oct, 2016 1 commit
    • Thomas Haller's avatar
      core: refactor private data in "src" · 4d37f7a1
      Thomas Haller authored
      - use _NM_GET_PRIVATE() and _NM_GET_PRIVATE_PTR() everywhere.
      
      - reorder statements, to have GObject related functions (init, dispose,
        constructed) at the bottom of each file and in a consistent order w.r.t.
        each other.
      
      - unify whitespaces in signal and properties declarations.
      
      - use NM_GOBJECT_PROPERTIES_DEFINE() and _notify()
      
      - drop unused signal slots in class structures
      
      - drop unused header files for device factories
      4d37f7a1
  7. 23 Aug, 2016 2 commits
    • Beniamino Galvani's avatar
      core: check valid uid for D-Bus load_connection(s)/set_logging calls · 772a9cb0
      Beniamino Galvani authored
      Commit 4c7fa8df ("core: drop root requirement for
      load_connection(s)/set_logging D-Bus calls") removed the enforcing of
      permission in the daemon for such methods since the D-Bus daemon
      configuration already does that. That change also allows clients to
      send a request and not wait for a response, since we don't have to
      check the caller credentials in the daemon.
      
      In the future we might switch to polkit for these methods, breaking
      clients that don't wait for a reponse, so it seems better to prevent
      from beginning such behavior.
      
      Fixes: 4c7fa8df
      (cherry picked from commit dd27b79c)
      772a9cb0
    • Beniamino Galvani's avatar
      core: check valid uid for D-Bus load_connection(s)/set_logging calls · dd27b79c
      Beniamino Galvani authored
      Commit 4c7fa8df ("core: drop root requirement for
      load_connection(s)/set_logging D-Bus calls") removed the enforcing of
      permission in the daemon for such methods since the D-Bus daemon
      configuration already does that. That change also allows clients to
      send a request and not wait for a response, since we don't have to
      check the caller credentials in the daemon.
      
      In the future we might switch to polkit for these methods, breaking
      clients that don't wait for a reponse, so it seems better to prevent
      from beginning such behavior.
      
      Fixes: 4c7fa8df
      dd27b79c
  8. 17 Aug, 2016 2 commits
    • Thomas Haller's avatar
      all: cleanup includes in header files · 0bdcab10
      Thomas Haller authored
      - don't include "nm-default.h" in header files. Every source file must
        include as first header "nm-default.h", thus our headers get the
        default include already implicitly.
      
      - we don't support compiling NetworkManager itself with a C++ compiler. Remove
        G_BEGIN_DECLS/G_END_DECLS from internal headers. We do however support
        users of libnm to use C++, thus they stay in public headers.
      
      (cherry picked from commit f19aff89)
      0bdcab10
    • Thomas Haller's avatar
      all: cleanup includes in header files · f19aff89
      Thomas Haller authored
      - don't include "nm-default.h" in header files. Every source file must
        include as first header "nm-default.h", thus our headers get the
        default include already implicitly.
      
      - we don't support compiling NetworkManager itself with a C++ compiler. Remove
        G_BEGIN_DECLS/G_END_DECLS from internal headers. We do however support
        users of libnm to use C++, thus they stay in public headers.
      f19aff89
  9. 11 Aug, 2016 1 commit
  10. 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
  11. 18 Nov, 2015 1 commit
    • Dan Williams's avatar
      exported-object: add support for DBus ObjectManager interface · b023d075
      Dan Williams authored
      NMExportedObject now derives from GDBusObjectSkeleton, which is what
      GDBusObjectManagerServer wants.  The main GDBusConnection and each
      private server connection now gets a new GDBusObjectManagerServer,
      and exported objects are registered with that instead of individually
      exporting each GDBusInterfaceSkeleton.
      
      Previously exported objects were not referenced by the BusManager,
      but instead removed from the exports hash via weak references.  The
      GDBusObjectManagerServer instead references exported objects, which
      can make them live much longer than they did before.
      Co-Authored-By: Thomas Haller's avatarThomas Haller <thaller@redhat.com>
      b023d075
  12. 16 Sep, 2015 1 commit
    • Thomas Haller's avatar
      core: refactor NMBusManager to hold reference to NMExportedObject directly · a55c87a2
      Thomas Haller authored
      Previously, nm_bus_manager_register_object() would take various D-Bus
      skeleton objects that were associated with one NMExportedObject.
      This was confusing, in that these skeleton objects are all for the
      same NMObject but correspond to different D-Bus interfaces.
      
      Also, setting the D-Bus property "Managed" of a Device is broken
      because we might retrieve the wrong skeleton.
      
      Now, the NMBusManager has a reference to the exported object directly.
      The skeleton interface instances instead are now exposed by the NMExportedObject.
      a55c87a2
  13. 25 Aug, 2015 1 commit
    • Thomas Haller's avatar
      secret-agent: fix detection of disapearing secret-agent · 9b35d29d
      Thomas Haller authored
      The signal "notify:g-name-owner" is only emitted for well-known
      names, but not for unique connection names (":1.x") such as the secret
      agent's connection. Also, it will not be emited for private connections.
      
      That meant that when the client disconnected without explicitly
      unregistering, the NMSecretAgent was not cleaned up and leaked
      indefinitely.
      As only one instance of secret agent with a certain 'identifier/uid'
      pair can register, this bug also prevented the client from registering
      until restart of NetworkManager.
      
      Fixes: df670681
      9b35d29d
  14. 10 Aug, 2015 1 commit
  15. 05 Aug, 2015 2 commits
  16. 24 Jul, 2015 1 commit
    • Dan Winship's avatar
      core: rename NMDBusManager to NMBusManager · 02370be7
      Dan Winship authored
      Our gdbus generated types use the same names as their corresponding
      "real" types, but with "NM" changed to "NMDBus".
      
      Unfortunately, that means that introspection/nmdbus-manager.c (the
      generated type for src/nm-manager.c) uses the same type name as the
      entirely unrelated src/nm-dbus-manager.c.
      
      Fix this by removing the "d" from src/nm-dbus-manager.c. (We could
      rename the generated type instead, but then it becomes inconsistent
      with all the other generated types, and we're already using it as
      "NMDBusManager" in libnm/nm-manager.c.)
      02370be7