summaryrefslogtreecommitdiffstats
path: root/include/ulogd/ulogd.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/ulogd/ulogd.h')
-rw-r--r--include/ulogd/ulogd.h60
1 files changed, 52 insertions, 8 deletions
diff --git a/include/ulogd/ulogd.h b/include/ulogd/ulogd.h
index 1636a8c..c7cf402 100644
--- a/include/ulogd/ulogd.h
+++ b/include/ulogd/ulogd.h
@@ -18,6 +18,7 @@
#include <signal.h> /* need this because of extension-sighandler */
#include <sys/types.h>
#include <inttypes.h>
+#include <netinet/in.h>
#include <string.h>
#include <config.h>
@@ -28,11 +29,6 @@
/* types without length */
#define ULOGD_RET_NONE 0x0000
-#define __packed __attribute__((packed))
-#define __noreturn __attribute__((noreturn))
-#define __cold __attribute__((cold))
-
-#define __packed __attribute__((packed))
#define ULOGD_RET_INT8 0x0001
#define ULOGD_RET_INT16 0x0002
@@ -139,36 +135,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)
@@ -207,6 +209,46 @@ static inline void *ikey_get_ptr(struct ulogd_key *key)
return key->u.source->u.value.ptr;
}
+/**
+ * Convert IPv4 address (as 32-bit unsigned integer) to IPv6 address: add 96-bit
+ * prefix "::ffff" to get IPv6 address "::ffff:a.b.c.d".
+ */
+static inline struct in6_addr *
+uint32_to_ipv6(uint32_t ipv4, struct in6_addr *ipv6)
+{
+ static const uint8_t IPV4_IN_IPV6_PREFIX[12] = {
+ [10] = 0xff,
+ [11] = 0xff,
+ };
+ uint8_t *p = ipv6->s6_addr;
+
+ memcpy(p, IPV4_IN_IPV6_PREFIX, sizeof(IPV4_IN_IPV6_PREFIX));
+ p += sizeof(IPV4_IN_IPV6_PREFIX);
+ memcpy(p, &ipv4, sizeof(ipv4));
+
+ return ipv6;
+}
+
+static inline void
+format_ipv6(char *buf, size_t size, const struct in6_addr *ipv6)
+{
+ unsigned i = 0;
+
+ if (size > 2 + sizeof (*ipv6) * 2) {
+ buf[i++] = '0';
+ buf[i++] = 'x';
+
+ for (unsigned j = 0; i < sizeof(*ipv6); j += 4, i += 8) {
+ sprintf(buf + i, "%02hhx%02hhx%02hhx%02hhx",
+ ipv6->s6_addr[j + 0],
+ ipv6->s6_addr[j + 1],
+ ipv6->s6_addr[j + 2],
+ ipv6->s6_addr[j + 3]);
+ }
+ }
+ buf[i] = '\0';
+}
+
struct ulogd_pluginstance_stack;
struct ulogd_pluginstance;
@@ -299,8 +341,9 @@ void ulogd_register_plugin(struct ulogd_plugin *me);
/* allocate a new ulogd_key */
struct ulogd_key *alloc_ret(const uint16_t type, const char*);
-/* write a message to the daemons' logfile */
-void __ulogd_log(int level, char *file, int line, const char *message, ...);
+/* write a message to the daemon's logfile */
+void __ulogd_log(int level, char *file, int line, const char *message, ...)
+ __attribute__((format(printf, 4, 5)));
/* macro for logging including filename and line number */
#define ulogd_log(level, format, args...) \
__ulogd_log(level, __FILE__, __LINE__, format, ## args)
@@ -313,6 +356,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))