diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2024-01-11 08:55:53 +0100 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2024-01-11 09:03:25 +0100 |
commit | 0705e05c3da22d1df2a2bf28e30fa8eb5419000c (patch) | |
tree | 20778a3251db939b88c748fbe5d01addec389aec /src | |
parent | json: introduce json_dispatch_byte_array_iovec() and json_dispatch_in_addr() (diff) | |
download | systemd-0705e05c3da22d1df2a2bf28e30fa8eb5419000c.tar.xz systemd-0705e05c3da22d1df2a2bf28e30fa8eb5419000c.zip |
sd-dhcp-client-id: introduce json_dispatch_client_id()
Diffstat (limited to 'src')
-rw-r--r-- | src/libsystemd-network/dhcp-client-id-internal.h | 3 | ||||
-rw-r--r-- | src/libsystemd-network/sd-dhcp-client-id.c | 17 |
2 files changed, 20 insertions, 0 deletions
diff --git a/src/libsystemd-network/dhcp-client-id-internal.h b/src/libsystemd-network/dhcp-client-id-internal.h index 72f13de24e..655f17b2e9 100644 --- a/src/libsystemd-network/dhcp-client-id-internal.h +++ b/src/libsystemd-network/dhcp-client-id-internal.h @@ -4,6 +4,7 @@ #include "sd-dhcp-client-id.h" #include "dhcp-duid-internal.h" +#include "json.h" #include "macro.h" #include "siphash24.h" #include "sparse-endian.h" @@ -55,3 +56,5 @@ static inline bool client_id_data_size_is_valid(size_t size) { void client_id_hash_func(const sd_dhcp_client_id *client_id, struct siphash *state); int client_id_compare_func(const sd_dhcp_client_id *a, const sd_dhcp_client_id *b); + +int json_dispatch_client_id(const char *name, JsonVariant *variant, JsonDispatchFlags flags, void *userdata); diff --git a/src/libsystemd-network/sd-dhcp-client-id.c b/src/libsystemd-network/sd-dhcp-client-id.c index 5752a44e8a..cab04f05e5 100644 --- a/src/libsystemd-network/sd-dhcp-client-id.c +++ b/src/libsystemd-network/sd-dhcp-client-id.c @@ -2,6 +2,7 @@ #include "alloc-util.h" #include "dhcp-client-id-internal.h" +#include "iovec-util.h" #include "unaligned.h" #include "utf8.h" @@ -177,3 +178,19 @@ int client_id_compare_func(const sd_dhcp_client_id *a, const sd_dhcp_client_id * return memcmp_nn(a->raw, a->size, b->raw, b->size); } + +int json_dispatch_client_id(const char *name, JsonVariant *variant, JsonDispatchFlags flags, void *userdata) { + sd_dhcp_client_id *client_id = ASSERT_PTR(userdata); + _cleanup_(iovec_done) struct iovec iov = {}; + int r; + + r = json_dispatch_byte_array_iovec(name, variant, flags, &iov); + if (r < 0) + return r; + + r = sd_dhcp_client_id_set_raw(client_id, iov.iov_base, iov.iov_len); + if (r < 0) + return json_log(variant, flags, r, "Failed to set DHCP client ID from JSON field '%s': %m", strna(name)); + + return 0; +} |