]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
networkd: expose nsid via dbus
authorLennart Poettering <lennart@poettering.net>
Fri, 12 Jan 2024 10:49:12 +0000 (11:49 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 12 Jan 2024 20:43:34 +0000 (21:43 +0100)
man/org.freedesktop.network1.xml
src/network/networkd-manager-bus.c

index c6cadee177f134fe056ef6822f01e38b53862297..1d8ce0de8114e8888322fad0f6e00091351afcff 100644 (file)
@@ -87,6 +87,8 @@ node /org/freedesktop/network1 {
       readonly s OnlineState = '...';
       @org.freedesktop.DBus.Property.EmitsChangedSignal("const")
       readonly t NamespaceId = ...;
+      @org.freedesktop.DBus.Property.EmitsChangedSignal("false")
+      readonly u NamespaceNSID = ...;
   };
   interface org.freedesktop.DBus.Peer { ... };
   interface org.freedesktop.DBus.Introspectable { ... };
@@ -148,8 +150,6 @@ node /org/freedesktop/network1 {
 
     <!--property OnlineState is not documented!-->
 
-    <!--property NamespaceId is not documented!-->
-
     <!--Autogenerated cross-references for systemd.directives, do not edit-->
 
     <variablelist class="dbus-interface" generated="True" extra-ref="org.freedesktop.network1.Manager"/>
@@ -212,11 +212,24 @@ node /org/freedesktop/network1 {
 
     <variablelist class="dbus-property" generated="True" extra-ref="NamespaceId"/>
 
+    <variablelist class="dbus-property" generated="True" extra-ref="NamespaceNSID"/>
+
     <!--End of Autogenerated section-->
 
     <para>
       Provides information about the manager.
     </para>
+
+    <refsect2>
+      <title>Properties</title>
+
+      <para><varname>NamespaceId</varname> contains the inode number of the network namespace that the
+      network service runs in. A client may compare this with the inode number of its own network namespace
+      to verify whether the service manages the same network namespace.</para>
+
+      <para><varname>NamespaceNSID</varname> contains the "nsid" identifier the kernel maintains for the
+      network namespace, if there's one assigned.</para>
+    </refsect2>
   </refsect1>
 
   <refsect1>
@@ -584,5 +597,9 @@ $ gdbus introspect --system \
       <title>DHCPv6 Client Object</title>
       <para><varname>State</varname> was added in version 255.</para>
     </refsect2>
+    <refsect2>
+      <title>Manager Object</title>
+      <para><varname>NamespaceNSID</varname> was added in version 256.</para>
+    </refsect2>
   </refsect1>
 </refentry>
index a8906f81c1ba606f0326a73979b31e6a5438d8cd..035537c869aa73ca33ecd94e060bc5fa250ee955 100644 (file)
@@ -279,6 +279,31 @@ static int property_get_namespace_id(
         return sd_bus_message_append(reply, "t", id);
 }
 
+static int property_get_namespace_nsid(
+                sd_bus *bus,
+                const char *path,
+                const char *interface,
+                const char *property,
+                sd_bus_message *reply,
+                void *userdata,
+                sd_bus_error *error) {
+
+        uint32_t nsid = UINT32_MAX;
+        int r;
+
+        assert(bus);
+        assert(reply);
+
+        /* Returns our own "nsid", which is another ID for the network namespace, different from the inode
+         * number. */
+
+        r = netns_get_nsid(/* netnsfd= */ -EBADF, &nsid);
+        if (r < 0)
+                log_warning_errno(r, "Failed to query network nsid, ignoring: %m");
+
+        return sd_bus_message_append(reply, "u", nsid);
+}
+
 static const sd_bus_vtable manager_vtable[] = {
         SD_BUS_VTABLE_START(0),
 
@@ -289,6 +314,7 @@ static const sd_bus_vtable manager_vtable[] = {
         SD_BUS_PROPERTY("IPv6AddressState", "s", property_get_address_state, offsetof(Manager, ipv6_address_state), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
         SD_BUS_PROPERTY("OnlineState", "s", property_get_online_state, offsetof(Manager, online_state), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
         SD_BUS_PROPERTY("NamespaceId", "t", property_get_namespace_id, 0, SD_BUS_VTABLE_PROPERTY_CONST),
+        SD_BUS_PROPERTY("NamespaceNSID", "u", property_get_namespace_nsid, 0, 0),
 
         SD_BUS_METHOD_WITH_ARGS("ListLinks",
                                 SD_BUS_NO_ARGS,