| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
|
| 3 |
#include "sd-bus.h" |
| 4 |
#include "sd-dhcp-client.h" |
| 5 |
|
| 6 |
#include "alloc-util.h" |
| 7 |
#include "bus-object.h" |
| 8 |
#include "dhcp-client-internal.h" |
| 9 |
#include "networkd-dhcp4-bus.h" |
| 10 |
#include "networkd-link-bus.h" |
| 11 |
#include "networkd-link.h" |
| 12 |
#include "networkd-manager.h" |
| 13 |
|
| 14 |
static int property_get_dhcp_client_state( |
| 15 |
sd_bus *bus, |
| 16 |
const char *path, |
| 17 |
const char *interface, |
| 18 |
const char *property, |
| 19 |
sd_bus_message *reply, |
| 20 |
void *userdata, |
| 21 |
sd_bus_error *error) { |
| 22 |
|
| 23 |
Link *l = ASSERT_PTR(userdata); |
| 24 |
sd_dhcp_client *c; |
| 25 |
|
| 26 |
assert(reply); |
| 27 |
|
| 28 |
c = l->dhcp_client; |
| 29 |
if (!c) |
| 30 |
return sd_bus_message_append(reply, "s", "disabled"); |
| 31 |
|
| 32 |
return sd_bus_message_append(reply, "s", dhcp_state_to_string(dhcp_client_get_state(c))); |
| 33 |
} |
| 34 |
|
| 35 |
static int dhcp_client_emit_changed(Link *link, char **properties) { |
| 36 |
_cleanup_free_ char *path = NULL; |
| 37 |
|
| 38 |
assert(link); |
| 39 |
|
| 40 |
if (sd_bus_is_ready(link->manager->bus) <= 0) |
| 41 |
return 0; |
| 42 |
|
| 43 |
path = link_bus_path(link); |
| 44 |
if (!path) |
| 45 |
return log_oom(); |
| 46 |
|
| 47 |
return sd_bus_emit_properties_changed_strv( |
| 48 |
link->manager->bus, |
| 49 |
path, |
| 50 |
"org.freedesktop.network1.DHCPv4Client", |
| 51 |
properties); |
| 52 |
} |
| 53 |
|
| 54 |
int dhcp_client_callback_bus(sd_dhcp_client *c, int event, void *userdata) { |
| 55 |
Link *l = ASSERT_PTR(userdata); |
| 56 |
|
| 57 |
return dhcp_client_emit_changed(l, STRV_MAKE("State")); |
| 58 |
} |
| 59 |
|
| 60 |
static const sd_bus_vtable dhcp_client_vtable[] = { |
| 61 |
SD_BUS_VTABLE_START(0), |
| 62 |
|
| 63 |
SD_BUS_PROPERTY("State", "s", property_get_dhcp_client_state, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), |
| 64 |
|
| 65 |
SD_BUS_VTABLE_END |
| 66 |
}; |
| 67 |
|
| 68 |
const BusObjectImplementation dhcp_client_object = { |
| 69 |
"/org/freedesktop/network1/link", |
| 70 |
"org.freedesktop.network1.DHCPv4Client", |
| 71 |
.fallback_vtables = BUS_FALLBACK_VTABLES({dhcp_client_vtable, link_object_find}), |
| 72 |
.node_enumerator = link_node_enumerator, |
| 73 |
}; |