From c2692b0fe414df398f310c38c0261c7e98066f93 Mon Sep 17 00:00:00 2001 From: Jeremy Sowden Date: Mon, 21 Aug 2023 20:42:27 +0100 Subject: src: record length of integer key values Signed-off-by: Jeremy Sowden Signed-off-by: Florian Westphal --- include/ulogd/ulogd.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/ulogd/ulogd.h b/include/ulogd/ulogd.h index 092d9f5..cb01740 100644 --- a/include/ulogd/ulogd.h +++ b/include/ulogd/ulogd.h @@ -134,36 +134,42 @@ static inline void okey_set_b(struct ulogd_key *key, uint8_t value) { key->u.value.b = value; key->flags |= ULOGD_RETF_VALID; + key->len = sizeof(key->u.value.b); } static inline void okey_set_u8(struct ulogd_key *key, uint8_t value) { key->u.value.ui8 = value; key->flags |= ULOGD_RETF_VALID; + key->len = sizeof(key->u.value.ui8); } static inline void okey_set_u16(struct ulogd_key *key, uint16_t value) { key->u.value.ui16 = value; key->flags |= ULOGD_RETF_VALID; + key->len = sizeof(key->u.value.ui16); } static inline void okey_set_u32(struct ulogd_key *key, uint32_t value) { key->u.value.ui32 = value; key->flags |= ULOGD_RETF_VALID; + key->len = sizeof(key->u.value.ui32); } static inline void okey_set_u64(struct ulogd_key *key, uint64_t value) { key->u.value.ui64 = value; key->flags |= ULOGD_RETF_VALID; + key->len = sizeof(key->u.value.ui64); } static inline void okey_set_u128(struct ulogd_key *key, const void *value) { - memcpy(key->u.value.ui128, value, 16); + memcpy(key->u.value.ui128, value, sizeof(key->u.value.ui128)); key->flags |= ULOGD_RETF_VALID; + key->len = sizeof(key->u.value.ui128); } static inline void okey_set_ptr(struct ulogd_key *key, void *value) @@ -309,6 +315,7 @@ void __ulogd_log(int level, char *file, int line, const char *message, ...) #define SET_NEEDED(x) (x.flags |= ULOGD_RETF_NEEDED) #define GET_FLAGS(res, x) (res[x].u.source->flags) +#define GET_LENGTH(res, x) (res[x].u.source->len) #define pp_is_valid(res, x) \ (res[x].u.source && (GET_FLAGS(res, x) & ULOGD_RETF_VALID)) -- cgit v1.2.3