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