summaryrefslogtreecommitdiff
path: root/src/network/networkd-link-bus.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/network/networkd-link-bus.c')
-rw-r--r--src/network/networkd-link-bus.c155
1 files changed, 144 insertions, 11 deletions
diff --git a/src/network/networkd-link-bus.c b/src/network/networkd-link-bus.c
index 1a1524dfb4..10ec08351a 100644
--- a/src/network/networkd-link-bus.c
+++ b/src/network/networkd-link-bus.c
@@ -1,5 +1,3 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
/***
This file is part of systemd.
@@ -19,11 +17,13 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include "alloc-util.h"
#include "bus-util.h"
-#include "strv.h"
-
-#include "networkd.h"
#include "networkd-link.h"
+#include "networkd.h"
+#include "parse-util.h"
+#include "strv.h"
+#include "dhcp-lease-internal.h"
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_operational_state, link_operstate, LinkOperationalState);
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_administrative_state, link_state, LinkState);
@@ -37,6 +37,50 @@ const sd_bus_vtable link_vtable[] = {
SD_BUS_VTABLE_END
};
+static int get_private_options(sd_bus *bus,
+ const char *path,
+ const char *interface,
+ const char *property,
+ sd_bus_message *reply,
+ void *userdata,
+ sd_bus_error *error) {
+ sd_dhcp_lease *lease = userdata;
+ struct sd_dhcp_raw_option *option = NULL;
+ int r;
+
+ assert(bus);
+ assert(reply);
+ assert(lease);
+
+ r = sd_bus_message_open_container(reply, SD_BUS_TYPE_ARRAY, "{yay}");
+ if (r < 0)
+ return r;
+
+ LIST_FOREACH(options, option, lease->private_options) {
+ r = sd_bus_message_open_container(reply, SD_BUS_TYPE_DICT_ENTRY, "yay");
+ if (r < 0)
+ return r;
+ r = sd_bus_message_append(reply, "y", option->tag);
+ if (r < 0)
+ return r;
+ r = sd_bus_message_append_array(reply, 'y', option->data, option->length);
+ if (r < 0)
+ return r;
+ r = sd_bus_message_close_container(reply);
+ if (r < 0)
+ return r;
+ }
+ return sd_bus_message_close_container(reply);
+}
+
+const sd_bus_vtable lease_vtable[] = {
+ SD_BUS_VTABLE_START(0),
+
+ SD_BUS_PROPERTY("PrivateOptions", "a{yay}", get_private_options, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
+
+ SD_BUS_VTABLE_END
+};
+
static char *link_bus_path(Link *link) {
_cleanup_free_ char *ifindex = NULL;
char *p;
@@ -55,18 +99,40 @@ static char *link_bus_path(Link *link) {
return p;
}
+static char *lease_bus_path(Link *link) {
+ _cleanup_free_ char *p = NULL;
+ char *ret = NULL;
+ int r;
+
+ assert(link);
+
+ p = link_bus_path(link);
+ if (!p)
+ return NULL;
+
+ r = sd_bus_path_encode(p, "lease", &ret);
+ if (r < 0)
+ return NULL;
+
+ return ret;
+}
+
int link_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error) {
_cleanup_strv_free_ char **l = NULL;
Manager *m = userdata;
+ unsigned c = 0;
Link *link;
Iterator i;
- int r;
assert(bus);
assert(path);
assert(m);
assert(nodes);
+ l = new0(char*, hashmap_size(m->links) + 1);
+ if (!l)
+ return -ENOMEM;
+
HASHMAP_FOREACH(link, m->links, i) {
char *p;
@@ -74,11 +140,46 @@ int link_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***
if (!p)
return -ENOMEM;
- r = strv_consume(&l, p);
- if (r < 0)
- return r;
+ l[c++] = p;
+ }
+
+ l[c] = NULL;
+ *nodes = l;
+ l = NULL;
+
+ return 1;
+}
+
+int lease_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error) {
+ _cleanup_strv_free_ char **l = NULL;
+ Manager *m = userdata;
+ unsigned c = 0;
+ Link *link;
+ Iterator i;
+
+ assert(bus);
+ assert(path);
+ assert(m);
+ assert(nodes);
+
+ l = new0(char*, hashmap_size(m->links) + 1);
+ if (!l)
+ return -ENOMEM;
+
+ HASHMAP_FOREACH(link, m->links, i) {
+ char *p;
+
+ if (!link->dhcp_lease)
+ continue;
+
+ p = lease_bus_path(link);
+ if (!p)
+ return -ENOMEM;
+
+ l[c++] = p;
}
+ l[c] = NULL;
*nodes = l;
l = NULL;
@@ -98,10 +199,10 @@ int link_object_find(sd_bus *bus, const char *path, const char *interface, void
assert(found);
r = sd_bus_path_decode(path, "/org/freedesktop/network1/link", &identifier);
- if (r < 0)
+ if (r <= 0)
return 0;
- r = safe_atoi(identifier, &ifindex);
+ r = parse_ifindex(identifier, &ifindex);
if (r < 0)
return 0;
@@ -114,6 +215,38 @@ int link_object_find(sd_bus *bus, const char *path, const char *interface, void
return 1;
}
+int lease_object_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error) {
+ _cleanup_free_ char *identifier = NULL;
+ Manager *m = userdata;
+ Link *link;
+ int ifindex, r;
+
+ assert(bus);
+ assert(path);
+ assert(interface);
+ assert(m);
+ assert(found);
+
+ r = sd_bus_path_decode_many(path, "/org/freedesktop/network1/link/%/lease", &identifier);
+ if (r <= 0)
+ return 0;
+
+ r = parse_ifindex(identifier, &ifindex);
+ if (r < 0)
+ return 0;
+
+ r = link_get(m, ifindex, &link);
+ if (r < 0)
+ return 0;
+
+ if (!link->dhcp_lease)
+ return 0;
+
+ *found = link->dhcp_lease;
+
+ return 1;
+}
+
int link_send_changed(Link *link, const char *property, ...) {
_cleanup_free_ char *p = NULL;
char **l;