summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/network/networkd-manager-bus.c42
-rw-r--r--src/network/org.freedesktop.network1.conf4
2 files changed, 46 insertions, 0 deletions
diff --git a/src/network/networkd-manager-bus.c b/src/network/networkd-manager-bus.c
index 4374d3db60..b52e3f7dd6 100644
--- a/src/network/networkd-manager-bus.c
+++ b/src/network/networkd-manager-bus.c
@@ -3,10 +3,50 @@
#include "alloc-util.h"
#include "bus-util.h"
#include "networkd-link-bus.h"
+#include "networkd-link.h"
#include "networkd-manager-bus.h"
#include "networkd-manager.h"
+#include "path-util.h"
#include "strv.h"
+static int method_list_links(sd_bus_message *message, void *userdata, sd_bus_error *error) {
+ _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
+ Manager *manager = userdata;
+ Iterator i;
+ Link *link;
+ int r;
+
+ r = sd_bus_message_new_method_return(message, &reply);
+ if (r < 0)
+ return r;
+
+ r = sd_bus_message_open_container(reply, 'a', "(iso)");
+ if (r < 0)
+ return r;
+
+ HASHMAP_FOREACH(link, manager->links, i) {
+ _cleanup_free_ char *path = NULL;
+
+ path = link_bus_path(link);
+ if (!path)
+ return -ENOMEM;
+
+ r = sd_bus_message_append(
+ reply, "(iso)",
+ link->ifindex,
+ link->ifname,
+ empty_to_root(path));
+ if (r < 0)
+ return r;
+ }
+
+ r = sd_bus_message_close_container(reply);
+ if (r < 0)
+ return r;
+
+ return sd_bus_send(NULL, reply, NULL);
+}
+
const sd_bus_vtable manager_vtable[] = {
SD_BUS_VTABLE_START(0),
@@ -14,6 +54,8 @@ const sd_bus_vtable manager_vtable[] = {
SD_BUS_PROPERTY("CarrierState", "s", property_get_carrier_state, offsetof(Manager, carrier_state), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
SD_BUS_PROPERTY("AddressState", "s", property_get_address_state, offsetof(Manager, address_state), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
+ SD_BUS_METHOD("ListLinks", NULL, "a(iso)", method_list_links, SD_BUS_VTABLE_UNPRIVILEGED),
+
SD_BUS_VTABLE_END
};
diff --git a/src/network/org.freedesktop.network1.conf b/src/network/org.freedesktop.network1.conf
index 52dad33668..279da06a98 100644
--- a/src/network/org.freedesktop.network1.conf
+++ b/src/network/org.freedesktop.network1.conf
@@ -36,6 +36,10 @@
send_interface="org.freedesktop.DBus.Properties"
send_member="GetAll"/>
+ <allow send_destination="org.freedesktop.network1"
+ send_interface="org.freedesktop.network1.Manager"
+ send_member="ListLinks"/>
+
<allow receive_sender="org.freedesktop.network1"/>
</policy>