summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--configure.ac4
-rw-r--r--filter/raw2packet/ulogd_raw2packet_BASE.c15
-rw-r--r--filter/ulogd_filter_IP2BIN.c33
-rw-r--r--filter/ulogd_filter_IP2HBIN.c9
-rw-r--r--include/ulogd/ulogd.h50
-rw-r--r--output/ipfix/ulogd_output_IPFIX.c3
-rw-r--r--output/pcap/ulogd_output_PCAP.c50
-rw-r--r--output/sqlite3/ulogd_output_SQLITE3.c20
-rw-r--r--output/ulogd_output_GPRINT.c32
-rw-r--r--output/ulogd_output_OPRINT.c89
-rw-r--r--src/ulogd.c9
-rw-r--r--util/db.c19
-rw-r--r--util/printpkt.c5
13 files changed, 203 insertions, 135 deletions
diff --git a/configure.ac b/configure.ac
index 6ee29ce..3c9249e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2,7 +2,7 @@ dnl Process this file with autoconf to produce a configure script.
AC_INIT([ulogd], [2.0.8])
AC_PREREQ([2.50])
AC_CONFIG_AUX_DIR([build-aux])
-AM_INIT_AUTOMAKE([-Wall foreign tar-pax no-dist-gzip dist-bzip2 1.10b subdir-objects])
+AM_INIT_AUTOMAKE([-Wall foreign tar-pax no-dist-gzip dist-xz 1.10b subdir-objects])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_MACRO_DIR([m4])
@@ -92,7 +92,7 @@ AS_IF([test "x$enable_pgsql" != "xno"], [
AS_IF([command -v "$pg_config" >/dev/null], [
- libpq_CFLAGS="`$pg_config --includedir`"
+ libpq_CFLAGS="-I`$pg_config --includedir`"
libpq_LIBS="`$pg_config --libdir` -lpq"
AC_SUBST([libpq_CFLAGS])
diff --git a/filter/raw2packet/ulogd_raw2packet_BASE.c b/filter/raw2packet/ulogd_raw2packet_BASE.c
index 9117d27..09e9313 100644
--- a/filter/raw2packet/ulogd_raw2packet_BASE.c
+++ b/filter/raw2packet/ulogd_raw2packet_BASE.c
@@ -645,7 +645,7 @@ static int _interp_icmp(struct ulogd_pluginstance *pi, struct icmphdr *icmph,
break;
case ICMP_REDIRECT:
case ICMP_PARAMETERPROB:
- okey_set_u32(&ret[KEY_ICMP_GATEWAY], ntohl(icmph->un.gateway));
+ okey_set_u32(&ret[KEY_ICMP_GATEWAY], icmph->un.gateway);
break;
case ICMP_DEST_UNREACH:
if (icmph->code == ICMP_FRAG_NEEDED) {
@@ -896,18 +896,23 @@ static int _interp_arp(struct ulogd_pluginstance *pi, uint32_t len)
struct ulogd_key *ret = pi->output.keys;
const struct ether_arp *arph =
ikey_get_ptr(&pi->input.keys[INKEY_RAW_PCKT]);
+ uint32_t arp_spa, arp_tpa;
if (len < sizeof(struct ether_arp))
return ULOGD_IRET_OK;
- okey_set_u16(&ret[KEY_ARP_HTYPE], ntohs(arph->arp_hrd));
- okey_set_u16(&ret[KEY_ARP_PTYPE], ntohs(arph->arp_pro));
+ okey_set_u16(&ret[KEY_ARP_HTYPE], ntohs(arph->arp_hrd));
+ okey_set_u16(&ret[KEY_ARP_PTYPE], ntohs(arph->arp_pro));
okey_set_u16(&ret[KEY_ARP_OPCODE], ntohs(arph->arp_op));
okey_set_ptr(&ret[KEY_ARP_SHA], (void *)&arph->arp_sha);
- okey_set_ptr(&ret[KEY_ARP_SPA], (void *)&arph->arp_spa);
okey_set_ptr(&ret[KEY_ARP_THA], (void *)&arph->arp_tha);
- okey_set_ptr(&ret[KEY_ARP_TPA], (void *)&arph->arp_tpa);
+
+ memcpy(&arp_spa, arph->arp_spa, sizeof(arp_spa));
+ memcpy(&arp_tpa, arph->arp_tpa, sizeof(arp_tpa));
+
+ okey_set_u32(&ret[KEY_ARP_SPA], arp_spa);
+ okey_set_u32(&ret[KEY_ARP_TPA], arp_tpa);
return ULOGD_IRET_OK;
}
diff --git a/filter/ulogd_filter_IP2BIN.c b/filter/ulogd_filter_IP2BIN.c
index 74e4683..7f7bea5 100644
--- a/filter/ulogd_filter_IP2BIN.c
+++ b/filter/ulogd_filter_IP2BIN.c
@@ -116,27 +116,12 @@ static struct ulogd_key ip2bin_keys[] = {
static char ipbin_array[MAX_KEY - START_KEY + 1][IPADDR_LENGTH];
-/**
- * Convert IPv4 address (as 32-bit unsigned integer) to IPv6 address:
- * add 96 bits prefix "::ffff:" to get IPv6 address "::ffff:a.b.c.d".
- */
-static inline void uint32_to_ipv6(const uint32_t ipv4, struct in6_addr *ipv6)
-{
- ipv6->s6_addr32[0] = 0x00000000;
- ipv6->s6_addr32[1] = 0x00000000;
- ipv6->s6_addr32[2] = htonl(0xffff);
- ipv6->s6_addr32[3] = ipv4;
-}
-
static int ip2bin(struct ulogd_key *inp, int index, int oindex)
{
char family = ikey_get_u8(&inp[KEY_OOB_FAMILY]);
char convfamily = family;
- unsigned char *addr8;
struct in6_addr *addr;
struct in6_addr ip4_addr;
- char *buffer;
- int i, written;
if (family == AF_BRIDGE) {
if (!pp_is_valid(inp, KEY_OOB_PROTOCOL)) {
@@ -176,23 +161,7 @@ static int ip2bin(struct ulogd_key *inp, int index, int oindex)
return ULOGD_IRET_ERR;
}
- buffer = ipbin_array[oindex];
- /* format IPv6 to BINARY(16) as "0x..." */
- buffer[0] = '0';
- buffer[1] = 'x';
- buffer += 2;
- addr8 = &addr->s6_addr[0];
- for (i = 0; i < 4; i++) {
- written = sprintf(buffer, "%02x%02x%02x%02x",
- addr8[0], addr8[1], addr8[2], addr8[3]);
- if (written != 2 * 4) {
- buffer[0] = 0;
- return ULOGD_IRET_ERR;
- }
- buffer += written;
- addr8 += 4;
- }
- buffer[0] = 0;
+ format_ipv6(ipbin_array[oindex], IPADDR_LENGTH, addr);
return ULOGD_IRET_OK;
}
diff --git a/filter/ulogd_filter_IP2HBIN.c b/filter/ulogd_filter_IP2HBIN.c
index 2711f9c..081616e 100644
--- a/filter/ulogd_filter_IP2HBIN.c
+++ b/filter/ulogd_filter_IP2HBIN.c
@@ -157,15 +157,14 @@ static int interp_ip2hbin(struct ulogd_pluginstance *pi)
if (pp_is_valid(inp, i)) {
switch (convfamily) {
case AF_INET:
- okey_set_u32(&ret[i-START_KEY],
- ntohl(ikey_get_u32(&inp[i])));
+ okey_set_u32(&ret[i - START_KEY],
+ ntohl(ikey_get_u32(&inp[i])));
break;
case AF_INET6:
- okey_set_ptr(&ret[i-START_KEY],
- (struct in6_addr *)ikey_get_u128(&inp[i]));
+ okey_set_u128(&ret[i - START_KEY],
+ ikey_get_u128(&inp[i]));
break;
default:
- ;
break;
}
}
diff --git a/include/ulogd/ulogd.h b/include/ulogd/ulogd.h
index 092d9f5..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>
@@ -134,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)
@@ -202,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;
@@ -309,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))
diff --git a/output/ipfix/ulogd_output_IPFIX.c b/output/ipfix/ulogd_output_IPFIX.c
index 4863d00..1c0f730 100644
--- a/output/ipfix/ulogd_output_IPFIX.c
+++ b/output/ipfix/ulogd_output_IPFIX.c
@@ -426,6 +426,9 @@ static int ipfix_interp(struct ulogd_pluginstance *pi)
if (!(GET_FLAGS(pi->input.keys, InIpSaddr) & ULOGD_RETF_VALID))
return ULOGD_IRET_OK;
+ if (GET_LENGTH(pi->input.keys, InIpSaddr) != sizeof(data->saddr))
+ return ULOGD_IRET_OK;
+
oid = oid_ce(pi->config_kset).u.value;
mtu = mtu_ce(pi->config_kset).u.value;
send_template = send_template_ce(pi->config_kset).u.string;
diff --git a/output/pcap/ulogd_output_PCAP.c b/output/pcap/ulogd_output_PCAP.c
index e7798f2..19ce47f 100644
--- a/output/pcap/ulogd_output_PCAP.c
+++ b/output/pcap/ulogd_output_PCAP.c
@@ -220,33 +220,26 @@ static int append_create_outfile(struct ulogd_pluginstance *upi)
{
struct pcap_instance *pi = (struct pcap_instance *) &upi->private;
char *filename = upi->config_kset->ces[0].u.string;
- struct stat st_dummy;
- int exist = 0;
-
- if (stat(filename, &st_dummy) == 0 && st_dummy.st_size > 0)
- exist = 1;
-
- if (!exist) {
- pi->of = fopen(filename, "w");
- if (!pi->of) {
- ulogd_log(ULOGD_ERROR, "can't open pcap file %s: %s\n",
- filename,
- strerror(errno));
- return -EPERM;
- }
- if (!write_pcap_header(pi)) {
- ulogd_log(ULOGD_ERROR, "can't write pcap header: %s\n",
- strerror(errno));
- return -ENOSPC;
- }
- } else {
- pi->of = fopen(filename, "a");
- if (!pi->of) {
- ulogd_log(ULOGD_ERROR, "can't open pcap file %s: %s\n",
- filename,
- strerror(errno));
- return -EPERM;
- }
+ struct stat st_of;
+ FILE *of;
+
+ of = fopen(filename, "a");
+ if (!of) {
+ ulogd_log(ULOGD_ERROR, "can't open pcap file %s: %s\n",
+ filename,
+ strerror(errno));
+ return -EPERM;
+ }
+
+ if (pi->of)
+ fclose(pi->of);
+ pi->of = of;
+
+ if (fstat(fileno(pi->of), &st_of) == 0 && st_of.st_size == 0 &&
+ !write_pcap_header(pi)) {
+ ulogd_log(ULOGD_ERROR, "can't write pcap header: %s\n",
+ strerror(errno));
+ return -ENOSPC;
}
return 0;
@@ -254,12 +247,9 @@ static int append_create_outfile(struct ulogd_pluginstance *upi)
static void signal_pcap(struct ulogd_pluginstance *upi, int signal)
{
- struct pcap_instance *pi = (struct pcap_instance *) &upi->private;
-
switch (signal) {
case SIGHUP:
ulogd_log(ULOGD_NOTICE, "reopening capture file\n");
- fclose(pi->of);
append_create_outfile(upi);
break;
default:
diff --git a/output/sqlite3/ulogd_output_SQLITE3.c b/output/sqlite3/ulogd_output_SQLITE3.c
index 0a9ad67..6aeb7a3 100644
--- a/output/sqlite3/ulogd_output_SQLITE3.c
+++ b/output/sqlite3/ulogd_output_SQLITE3.c
@@ -33,6 +33,7 @@
#include <stdlib.h>
#include <string.h>
#include <arpa/inet.h>
+#include <netinet/in.h>
#include <ulogd/ulogd.h>
#include <ulogd/conffile.h>
#include <sqlite3.h>
@@ -145,6 +146,10 @@ sqlite3_interp(struct ulogd_pluginstance *pi)
}
switch (f->key->type) {
+ case ULOGD_RET_BOOL:
+ ret = sqlite3_bind_int(priv->p_stmt, i, k_ret->u.value.b);
+ break;
+
case ULOGD_RET_INT8:
ret = sqlite3_bind_int(priv->p_stmt, i, k_ret->u.value.i8);
break;
@@ -158,7 +163,7 @@ sqlite3_interp(struct ulogd_pluginstance *pi)
break;
case ULOGD_RET_INT64:
- ret = sqlite3_bind_int(priv->p_stmt, i, k_ret->u.value.i64);
+ ret = sqlite3_bind_int64(priv->p_stmt, i, k_ret->u.value.i64);
break;
case ULOGD_RET_UINT8:
@@ -174,17 +179,20 @@ sqlite3_interp(struct ulogd_pluginstance *pi)
break;
case ULOGD_RET_IPADDR:
- case ULOGD_RET_UINT64:
- ret = sqlite3_bind_int64(priv->p_stmt, i, k_ret->u.value.ui64);
+ if (k_ret->len == sizeof(struct in_addr))
+ ret = sqlite3_bind_int(priv->p_stmt, i,
+ k_ret->u.value.ui32);
+ else
+ ret = sqlite3_bind_null(priv->p_stmt, i);
break;
- case ULOGD_RET_BOOL:
- ret = sqlite3_bind_int(priv->p_stmt, i, k_ret->u.value.b);
+ case ULOGD_RET_UINT64:
+ ret = sqlite3_bind_int64(priv->p_stmt, i, k_ret->u.value.ui64);
break;
case ULOGD_RET_STRING:
ret = sqlite3_bind_text(priv->p_stmt, i, k_ret->u.value.ptr,
- strlen(k_ret->u.value.ptr), SQLITE_STATIC);
+ strlen(k_ret->u.value.ptr), SQLITE_STATIC);
break;
default:
diff --git a/output/ulogd_output_GPRINT.c b/output/ulogd_output_GPRINT.c
index eeeec6a..37829fa 100644
--- a/output/ulogd_output_GPRINT.c
+++ b/output/ulogd_output_GPRINT.c
@@ -27,6 +27,8 @@
#include <time.h>
#include <errno.h>
#include <inttypes.h>
+#include <arpa/inet.h>
+#include <netinet/in.h>
#include <ulogd/ulogd.h>
#include <ulogd/conffile.h>
@@ -69,12 +71,6 @@ static struct config_keyset gprint_kset = {
},
};
-#define NIPQUAD(addr) \
- ((unsigned char *)&addr)[0], \
- ((unsigned char *)&addr)[1], \
- ((unsigned char *)&addr)[2], \
- ((unsigned char *)&addr)[3]
-
static int gprint_interp(struct ulogd_pluginstance *upi)
{
struct gprint_priv *opi = (struct gprint_priv *) &upi->private;
@@ -158,20 +154,36 @@ static int gprint_interp(struct ulogd_pluginstance *upi)
rem -= ret;
size += ret;
break;
- case ULOGD_RET_IPADDR:
+ case ULOGD_RET_IPADDR: {
+ struct in6_addr ipv6addr;
+ struct in_addr ipv4addr;
+ int family;
+ void *addr;
+
ret = snprintf(buf+size, rem, "%s=", key->name);
if (ret < 0)
break;
rem -= ret;
size += ret;
- ret = snprintf(buf+size, rem, "%u.%u.%u.%u,",
- NIPQUAD(key->u.value.ui32));
- if (ret < 0)
+ if (key->len == sizeof(ipv6addr)) {
+ memcpy(ipv6addr.s6_addr, key->u.value.ui128,
+ sizeof(ipv6addr.s6_addr));
+ addr = &ipv6addr;
+ family = AF_INET6;
+ } else {
+ ipv4addr.s_addr = key->u.value.ui32;
+ addr = &ipv4addr;
+ family = AF_INET;
+ }
+ if (!inet_ntop(family, addr, buf + size, rem))
break;
+ ret = strlen(buf + size);
+
rem -= ret;
size += ret;
break;
+ }
default:
/* don't know how to interpret this key. */
break;
diff --git a/output/ulogd_output_OPRINT.c b/output/ulogd_output_OPRINT.c
index 6fde445..13934ff 100644
--- a/output/ulogd_output_OPRINT.c
+++ b/output/ulogd_output_OPRINT.c
@@ -24,6 +24,8 @@
#include <string.h>
#include <errno.h>
#include <inttypes.h>
+#include <arpa/inet.h>
+#include <netinet/in.h>
#include <ulogd/ulogd.h>
#include <ulogd/conffile.h>
@@ -31,18 +33,6 @@
#define ULOGD_OPRINT_DEFAULT "/var/log/ulogd_oprint.log"
#endif
-#define NIPQUAD(addr) \
- ((unsigned char *)&addr)[0], \
- ((unsigned char *)&addr)[1], \
- ((unsigned char *)&addr)[2], \
- ((unsigned char *)&addr)[3]
-
-#define HIPQUAD(addr) \
- ((unsigned char *)&addr)[3], \
- ((unsigned char *)&addr)[2], \
- ((unsigned char *)&addr)[1], \
- ((unsigned char *)&addr)[0]
-
struct oprint_priv {
FILE *of;
};
@@ -59,38 +49,61 @@ static int oprint_interp(struct ulogd_pluginstance *upi)
if (!ret)
ulogd_log(ULOGD_NOTICE, "no result for %s ?!?\n",
upi->input.keys[i].name);
-
+
if (!IS_VALID(*ret))
continue;
fprintf(opi->of,"%s=", ret->name);
switch (ret->type) {
- case ULOGD_RET_STRING:
- fprintf(opi->of, "%s\n",
- (char *) ret->u.value.ptr);
- break;
- case ULOGD_RET_BOOL:
- case ULOGD_RET_INT8:
- case ULOGD_RET_INT16:
- case ULOGD_RET_INT32:
- fprintf(opi->of, "%d\n", ret->u.value.i32);
- break;
- case ULOGD_RET_UINT8:
- case ULOGD_RET_UINT16:
- case ULOGD_RET_UINT32:
- fprintf(opi->of, "%u\n", ret->u.value.ui32);
+ case ULOGD_RET_STRING:
+ fprintf(opi->of, "%s\n", (char *) ret->u.value.ptr);
+ break;
+ case ULOGD_RET_BOOL:
+ case ULOGD_RET_INT8:
+ case ULOGD_RET_INT16:
+ case ULOGD_RET_INT32:
+ fprintf(opi->of, "%d\n", ret->u.value.i32);
+ break;
+ case ULOGD_RET_INT64:
+ fprintf(opi->of, "%" PRId64 "\n", ret->u.value.i64);
+ break;
+ case ULOGD_RET_UINT8:
+ case ULOGD_RET_UINT16:
+ case ULOGD_RET_UINT32:
+ fprintf(opi->of, "%u\n", ret->u.value.ui32);
+ break;
+ case ULOGD_RET_UINT64:
+ fprintf(opi->of, "%" PRIu64 "\n", ret->u.value.ui64);
+ break;
+ case ULOGD_RET_IPADDR: {
+ char addrbuf[INET6_ADDRSTRLEN + 1] = "";
+ struct in6_addr ipv6addr;
+ struct in_addr ipv4addr;
+ int family;
+ void *addr;
+
+ if (ret->len == sizeof(ipv6addr)) {
+ memcpy(ipv6addr.s6_addr, ret->u.value.ui128,
+ sizeof(ipv6addr.s6_addr));
+ addr = &ipv6addr;
+ family = AF_INET6;
+ } else {
+ ipv4addr.s_addr = ret->u.value.ui32;
+ addr = &ipv4addr;
+ family = AF_INET;
+ }
+ if (!inet_ntop(family, addr, addrbuf, sizeof(addrbuf)))
break;
- case ULOGD_RET_UINT64:
- fprintf(opi->of, "%" PRIu64 "\n", ret->u.value.ui64);
- break;
- case ULOGD_RET_IPADDR:
- fprintf(opi->of, "%u.%u.%u.%u\n",
- HIPQUAD(ret->u.value.ui32));
- break;
- case ULOGD_RET_NONE:
- fprintf(opi->of, "<none>\n");
- break;
- default: fprintf(opi->of, "default\n");
+
+ fprintf(opi->of, "%s\n", addrbuf);
+ break;
+ }
+ case ULOGD_RET_NONE:
+ fprintf(opi->of, "<none>\n");
+ break;
+ default:
+ fprintf(opi->of, "default\n");
+ break;
}
}
if (upi->config_kset->ces[1].u.value != 0)
diff --git a/src/ulogd.c b/src/ulogd.c
index 8ea9793..6c5ff9a 100644
--- a/src/ulogd.c
+++ b/src/ulogd.c
@@ -1334,6 +1334,15 @@ static void stop_pluginstances()
(*pi->plugin->stop)(pi);
pi->private[0] = 0;
}
+
+ /* NB: plugin->stop() might access other plugin instances,
+ * so we cannot free right away.
+ */
+ }
+ }
+
+ llist_for_each_entry(stack, &ulogd_pi_stacks, stack_list) {
+ llist_for_each_entry_safe(pi, npi, &stack->list, list) {
free(pi);
}
}
diff --git a/util/db.c b/util/db.c
index ebd9f15..749a45f 100644
--- a/util/db.c
+++ b/util/db.c
@@ -344,6 +344,9 @@ static void __format_query_db(struct ulogd_pluginstance *upi, char *start)
}
switch (res->type) {
+ case ULOGD_RET_BOOL:
+ sprintf(stmt_ins, "'%d',", res->u.value.b);
+ break;
case ULOGD_RET_INT8:
sprintf(stmt_ins, "%d,", res->u.value.i8);
break;
@@ -363,16 +366,24 @@ static void __format_query_db(struct ulogd_pluginstance *upi, char *start)
sprintf(stmt_ins, "%u,", res->u.value.ui16);
break;
case ULOGD_RET_IPADDR:
- /* fallthrough when logging IP as uint32_t */
+ if (res->len == sizeof(struct in_addr))
+ sprintf(stmt_ins, "%u,", res->u.value.ui32);
+ else {
+ struct in6_addr ipv6;
+ char addrbuf[2 + sizeof(ipv6) * 2 + 1];
+
+ memcpy(ipv6.s6_addr, res->u.value.ui128,
+ sizeof(ipv6.s6_addr));
+ format_ipv6(addrbuf, sizeof(addrbuf), &ipv6);
+ sprintf(stmt_ins, "%s,", addrbuf);
+ }
+ break;
case ULOGD_RET_UINT32:
sprintf(stmt_ins, "%u,", res->u.value.ui32);
break;
case ULOGD_RET_UINT64:
sprintf(stmt_ins, "%" PRIu64 ",", res->u.value.ui64);
break;
- case ULOGD_RET_BOOL:
- sprintf(stmt_ins, "'%d',", res->u.value.b);
- break;
case ULOGD_RET_STRING:
*(stmt_ins++) = '\'';
if (res->u.value.ptr) {
diff --git a/util/printpkt.c b/util/printpkt.c
index b9b47b2..09a2194 100644
--- a/util/printpkt.c
+++ b/util/printpkt.c
@@ -260,11 +260,12 @@ static int printpkt_ipv4(struct ulogd_key *res, char *buf)
ikey_get_u16(&res[KEY_ICMP_ECHOSEQ]));
break;
case ICMP_PARAMETERPROB:
+ paddr = ikey_get_u32(&res[KEY_ICMP_GATEWAY]);
buf_cur += sprintf(buf_cur, "PARAMETER=%u ",
- ikey_get_u32(&res[KEY_ICMP_GATEWAY]) >> 24);
+ *(uint8_t *) &paddr);
break;
case ICMP_REDIRECT:
- paddr = ikey_get_u32(&res[KEY_ICMP_GATEWAY]),
+ paddr = ikey_get_u32(&res[KEY_ICMP_GATEWAY]);
buf_cur += sprintf(buf_cur, "GATEWAY=%s ",
inet_ntop(AF_INET,
&paddr,