1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 #include "sd-dhcp-server.h"
5 #include "alloc-util.h"
6 #include "bus-common-errors.h"
8 #include "dhcp-server-internal.h"
9 #include "networkd-dhcp-server-bus.h"
10 #include "networkd-link-bus.h"
11 #include "networkd-manager.h"
14 static int property_get_leases(
17 const char *interface
,
19 sd_bus_message
*reply
,
21 sd_bus_error
*error
) {
33 return sd_bus_error_setf(error
, SD_BUS_ERROR_NOT_SUPPORTED
, "Link %s has no DHCP server.", l
->ifname
);
35 r
= sd_bus_message_open_container(reply
, 'a', "(uayayayayt)");
39 HASHMAP_FOREACH(lease
, s
->leases_by_client_id
, i
) {
40 r
= sd_bus_message_open_container(reply
, 'r', "uayayayayt");
44 r
= sd_bus_message_append(reply
, "u", (uint32_t)AF_INET
);
48 r
= sd_bus_message_append_array(reply
, 'y', lease
->client_id
.data
, lease
->client_id
.length
);
52 r
= sd_bus_message_append_array(reply
, 'y', &lease
->address
, sizeof(lease
->address
));
56 r
= sd_bus_message_append_array(reply
, 'y', &lease
->gateway
, sizeof(lease
->gateway
));
60 r
= sd_bus_message_append_array(reply
, 'y', &lease
->chaddr
, sizeof(lease
->chaddr
));
64 r
= sd_bus_message_append_basic(reply
, 't', &lease
->expiration
);
68 r
= sd_bus_message_close_container(reply
);
73 return sd_bus_message_close_container(reply
);
76 static int dhcp_server_emit_changed(Link
*link
, const char *property
, ...) {
77 _cleanup_free_
char *path
= NULL
;
82 path
= link_bus_path(link
);
86 l
= strv_from_stdarg_alloca(property
);
88 return sd_bus_emit_properties_changed_strv(
91 "org.freedesktop.network1.DHCPServer",
95 void dhcp_server_callback(sd_dhcp_server
*s
, uint64_t event
, void *data
) {
100 if (event
& SD_DHCP_SERVER_EVENT_LEASE_CHANGED
)
101 (void) dhcp_server_emit_changed(l
, "Leases", NULL
);
105 const sd_bus_vtable dhcp_server_vtable
[] = {
106 SD_BUS_VTABLE_START(0),
108 SD_BUS_PROPERTY("Leases", "a(uayayayayt)", property_get_leases
, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE
),