summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHolger Eitzenberger <heitzenberger@astaro.com>2009-10-21 10:46:19 +0200
committerHarald Welte <laforge@gnumonks.org>2010-10-21 19:15:38 +0200
commita8f9b62e71da91dfaf5ce23749372c11ac1915d5 (patch)
tree9818a7fa8328d7f7163576d8b2b233d358513080
parent4380da73f79f78918478ffe488b574c4741742aa (diff)
Add native key type in_addr
Signed-off-by: Holger Eitzenberger <holger@eitzenberger.org>
-rw-r--r--include/ulogd/plugin.h4
-rw-r--r--input/flow/ulogd_inpflow_NFCT.c4
-rw-r--r--output/ulogd_output_NACCT.c24
-rw-r--r--output/ulogd_output_OPRINT.c5
-rw-r--r--src/plugin.c25
5 files changed, 46 insertions, 16 deletions
diff --git a/include/ulogd/plugin.h b/include/ulogd/plugin.h
index a6f7fa7..16c22ff 100644
--- a/include/ulogd/plugin.h
+++ b/include/ulogd/plugin.h
@@ -80,6 +80,7 @@ struct ulogd_value {
uint64_t ui64;
void *ptr;
char *str;
+ struct in_addr in;
struct in6_addr in6;
};
};
@@ -165,6 +166,7 @@ void key_set_u64(struct ulogd_key *, uint64_t);
void key_set_bool(struct ulogd_key *, bool);
void key_set_ptr(struct ulogd_key *, void *);
void key_set_str(struct ulogd_key *, char *);
+void key_set_in(struct ulogd_key *, const struct in_addr *);
void key_set_in6(struct ulogd_key *, const struct in6_addr *);
/* key accessors */
@@ -179,6 +181,7 @@ uint64_t key_u64(const struct ulogd_key *);
bool key_bool(const struct ulogd_key *);
void *key_ptr(const struct ulogd_key *);
char *key_str(const struct ulogd_key *);
+void key_in(const struct ulogd_key *, struct in_addr *);
void key_in6(const struct ulogd_key *, struct in6_addr *);
/* src key accessors */
@@ -193,6 +196,7 @@ uint64_t key_src_u64(const struct ulogd_key *);
bool key_src_bool(const struct ulogd_key *);
void *key_src_ptr(const struct ulogd_key *);
char *key_src_str(const struct ulogd_key *);
+void key_src_in(const struct ulogd_key *, struct in_addr *);
void key_src_in6(const struct ulogd_key *, struct in6_addr *);
enum ulogd_ktype key_type(const struct ulogd_key *);
diff --git a/input/flow/ulogd_inpflow_NFCT.c b/input/flow/ulogd_inpflow_NFCT.c
index d734753..f3e018a 100644
--- a/input/flow/ulogd_inpflow_NFCT.c
+++ b/input/flow/ulogd_inpflow_NFCT.c
@@ -668,8 +668,8 @@ propagate_ct(struct ulogd_pluginstance *pi, struct conntrack *ct)
ct->time[STOP].tv_sec = t_now;
if (ct->tuple.family == AF_INET) {
- key_set_u32(&out[O_IP_SADDR], ct->tuple.src.in.s_addr);
- key_set_u32(&out[O_IP_DADDR], ct->tuple.dst.in.s_addr);
+ key_set_in(&out[O_IP_SADDR], &ct->tuple.src.in);
+ key_set_in(&out[O_IP_DADDR], &ct->tuple.dst.in);
} else if (ct->tuple.family == AF_INET6) {
key_set_in6(&out[O_IP6_SADDR], &ct->tuple.src.in6);
key_set_in6(&out[O_IP6_DADDR], &ct->tuple.dst.in6);
diff --git a/output/ulogd_output_NACCT.c b/output/ulogd_output_NACCT.c
index 80c7f87..7db1ea9 100644
--- a/output/ulogd_output_NACCT.c
+++ b/output/ulogd_output_NACCT.c
@@ -90,27 +90,31 @@ nacct_interp(struct ulogd_pluginstance *pi, unsigned *flags)
struct nacct_priv *priv = upi_priv(pi);
struct ulogd_key *in = pi->input.keys;
static char buf[80];
+ struct in_addr saddr, daddr;
int len;
+ key_src_in(&in[InIpSAddr], &saddr);
+ key_src_in(&in[InIpDAddr], &daddr);
+
/* try to be as close to nacct as possible. Instead of nacct's
'timestamp' value use 'flow.end.sec' */
if (key_src_u8(&in[InIpProto]) == IPPROTO_ICMP) {
len = sprintf(buf, "%u\t%u\t%s\t%u\t%s\t%u\t%u\t%u\n",
- key_src_u32(&in[InFlowEndSec]),
- key_src_u8(&in[InIpProto]),
- inet_ntoa((struct in_addr){ key_src_u32(&in[InIpSAddr]) }),
- key_src_u8(&in[InIcmpType]),
- inet_ntoa((struct in_addr){ key_src_u32(&in[InIpDAddr]) }),
- key_src_u8(&in[InIcmpCode]),
- key_src_u32(&in[InRawInPktCnt]),
- key_src_u32(&in[InRawInPktLen]));
+ key_src_u32(&in[InFlowEndSec]),
+ key_src_u8(&in[InIpProto]),
+ inet_ntoa(saddr),
+ key_src_u8(&in[InIcmpType]),
+ inet_ntoa(daddr),
+ key_src_u8(&in[InIcmpCode]),
+ key_src_u32(&in[InRawInPktCnt]),
+ key_src_u32(&in[InRawInPktLen]));
} else {
len = sprintf(buf, "%u\t%u\t%s\t%u\t%s\t%u\t%u\t%u\n",
key_src_u32(&in[InFlowEndSec]),
key_src_u8(&in[InIpProto]),
- inet_ntoa((struct in_addr){ key_src_u32(&in[InIpSAddr]) }),
+ inet_ntoa(saddr),
key_src_u16(&in[InL4SPort]),
- inet_ntoa((struct in_addr){ key_src_u32(&in[InIpDAddr]) }),
+ inet_ntoa(daddr),
key_src_u16(&in[InL4DPort]),
key_src_u32(&in[InRawInPktCnt]),
key_src_u32(&in[InRawInPktLen]));
diff --git a/output/ulogd_output_OPRINT.c b/output/ulogd_output_OPRINT.c
index 6b59fe7..526acc7 100644
--- a/output/ulogd_output_OPRINT.c
+++ b/output/ulogd_output_OPRINT.c
@@ -135,8 +135,9 @@ opr_interp(struct ulogd_pluginstance *upi, unsigned *flags)
case ULOGD_RET_IPADDR:
{
- struct in_addr addr = (struct in_addr){ key_u32(key), };
-
+ struct in_addr addr;
+
+ key_in(key, &addr);
inet_ntop(AF_INET, &addr, opi->buf, OPR_BUF_LEN);
fprintf(opi->of, "%s=%s\n", key->name, opi->buf);
break;
diff --git a/src/plugin.c b/src/plugin.c
index 8359c1b..dae74a2 100644
--- a/src/plugin.c
+++ b/src/plugin.c
@@ -861,7 +861,7 @@ ulogd_value_to_ascii(const struct ulogd_value *val, char *buf, size_t len)
break;
case ULOGD_RET_IPADDR:
- inet_ntop(AF_INET, &val->ui32, buf, len);
+ inet_ntop(AF_INET, &val->in, buf, len);
nchars = strlen(buf);
break;
@@ -995,6 +995,15 @@ key_set_str(struct ulogd_key *key, char *str)
}
void
+key_set_in(struct ulogd_key *key, const struct in_addr *addr)
+{
+ __check_set(key, ULOGD_RET_IPADDR);
+
+ memcpy(&key->val.in, addr, sizeof(struct in_addr));
+ key->flags |= ULOGD_RETF_VALID;
+}
+
+void
key_set_in6(struct ulogd_key *key, const struct in6_addr *addr)
{
__check_set(key, ULOGD_RET_IP6ADDR);
@@ -1109,10 +1118,16 @@ key_str(const struct ulogd_key *key)
}
void
+key_in(const struct ulogd_key *key, struct in_addr *addr)
+{
+ __check_get(key, ULOGD_RET_IPADDR);
+ memcpy(addr, &key->val.in, sizeof(*addr));
+}
+
+void
key_in6(const struct ulogd_key *key, struct in6_addr *addr)
{
__check_get(key, ULOGD_RET_IP6ADDR);
-
memcpy(addr, &key->val.in6, sizeof(*addr));
}
@@ -1182,6 +1197,12 @@ key_src_str(const struct ulogd_key *key)
}
void
+key_src_in(const struct ulogd_key *key, struct in_addr *addr)
+{
+ return key_in(key_src(key), addr);
+}
+
+void
key_src_in6(const struct ulogd_key *key, struct in6_addr *addr)
{
return key_in6(key_src(key), addr);