From d4cf078cb71a943af0dcaa51ed5f950df0fdeca3 Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Sun, 23 Nov 2008 23:59:44 +0100 Subject: add ukey_* function for key assignation This patch cleans up the current key assignation by introducing a set of functions ukey_* to set the key value as Eric Leblond and we discussed during the latest Netfilter Workshop. This patch is based on an idea from Holger Eitzenberger. Signed-off-by: Eric Leblond --- include/ulogd/ulogd.h | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/ulogd/ulogd.h b/include/ulogd/ulogd.h index 776111a..3f6d784 100644 --- a/include/ulogd/ulogd.h +++ b/include/ulogd/ulogd.h @@ -18,6 +18,7 @@ #include #include /* need this because of extension-sighandler */ #include +#include #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) @@ -126,6 +127,64 @@ struct ulogd_keyset { unsigned int type; }; +static inline void okey_set_b(struct ulogd_key *key, u_int8_t value) +{ + key->u.value.b = value; + key->flags |= ULOGD_RETF_VALID; +} + +static inline void okey_set_u8(struct ulogd_key *key, u_int8_t value) +{ + key->u.value.ui8 = value; + key->flags |= ULOGD_RETF_VALID; +} + +static inline void okey_set_u16(struct ulogd_key *key, u_int16_t value) +{ + key->u.value.ui16 = value; + key->flags |= ULOGD_RETF_VALID; +} + +static inline void okey_set_u32(struct ulogd_key *key, u_int32_t value) +{ + key->u.value.ui32 = value; + key->flags |= ULOGD_RETF_VALID; +} + +static inline void okey_set_u128(struct ulogd_key *key, const void *value) +{ + memcpy(key->u.value.ui128, value, 16); + key->flags |= ULOGD_RETF_VALID; +} + +static inline void okey_set_ptr(struct ulogd_key *key, void *value) +{ + key->u.value.ptr = value; + key->flags |= ULOGD_RETF_VALID; +} + +static inline u_int8_t ikey_get_u8(struct ulogd_key *key) +{ + return key->u.source->u.value.ui8; +} + +static inline u_int16_t ikey_get_u16(struct ulogd_key *key) +{ + return key->u.source->u.value.ui16; +} + +static inline u_int32_t ikey_get_u32(struct ulogd_key *key) +{ + return key->u.source->u.value.ui32; +} + +#define ikey_get_u128 ikey_get_ptr + +static inline void *ikey_get_ptr(struct ulogd_key *key) +{ + return key->u.source->u.value.ptr; +} + struct ulogd_pluginstance_stack; struct ulogd_pluginstance; struct ulogd_plugin { @@ -221,7 +280,6 @@ void __ulogd_log(int level, char *file, int line, const char *message, ...); #define IS_NEEDED(x) (x.flags & ULOGD_RETF_NEEDED) #define SET_NEEDED(x) (x.flags |= ULOGD_RETF_NEEDED) -#define GET_VALUE(res, x) (res[x].u.source->u.value) #define GET_FLAGS(res, x) (res[x].u.source->flags) #define pp_is_valid(res, x) \ (res[x].u.source && (GET_FLAGS(res, x) & ULOGD_RETF_VALID)) -- cgit v1.2.3