1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
3 #include "sd-dhcp-client.h"
5 #include "alloc-util.h"
6 #include "bus-common-errors.h"
8 #include "dhcp-client-internal.h"
9 #include "networkd-dhcp4-bus.h"
10 #include "networkd-link-bus.h"
11 #include "networkd-manager.h"
12 #include "string-table.h"
15 static int property_get_dhcp_client_state(
18 const char *interface
,
20 sd_bus_message
*reply
,
22 sd_bus_error
*error
) {
24 Link
*l
= ASSERT_PTR(userdata
);
31 return sd_bus_message_append(reply
, "s", "disabled");
33 return sd_bus_message_append(reply
, "s", dhcp_state_to_string(dhcp_client_get_state(c
)));
36 static int dhcp_client_emit_changed(Link
*link
, const char *property
, ...) {
37 _cleanup_free_
char *path
= NULL
;
42 if (sd_bus_is_ready(link
->manager
->bus
) <= 0)
45 path
= link_bus_path(link
);
49 l
= strv_from_stdarg_alloca(property
);
51 return sd_bus_emit_properties_changed_strv(
54 "org.freedesktop.network1.DHCPv4Client",
58 int dhcp_client_callback_bus(sd_dhcp_client
*c
, int event
, void *userdata
) {
59 Link
*l
= ASSERT_PTR(userdata
);
61 return dhcp_client_emit_changed(l
, "State", NULL
);
64 static const sd_bus_vtable dhcp_client_vtable
[] = {
65 SD_BUS_VTABLE_START(0),
67 SD_BUS_PROPERTY("State", "s", property_get_dhcp_client_state
, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE
),
72 const BusObjectImplementation dhcp_client_object
= {
73 "/org/freedesktop/network1/link",
74 "org.freedesktop.network1.DHCPv4Client",
75 .fallback_vtables
= BUS_FALLBACK_VTABLES({dhcp_client_vtable
, link_object_find
}),
76 .node_enumerator
= link_node_enumerator
,