summaryrefslogtreecommitdiffstats
path: root/input/flow/ulogd_inpflow_CTNL.c
diff options
context:
space:
mode:
Diffstat (limited to 'input/flow/ulogd_inpflow_CTNL.c')
-rw-r--r--input/flow/ulogd_inpflow_CTNL.c72
1 files changed, 37 insertions, 35 deletions
diff --git a/input/flow/ulogd_inpflow_CTNL.c b/input/flow/ulogd_inpflow_CTNL.c
index 6f47bad..6bbd282 100644
--- a/input/flow/ulogd_inpflow_CTNL.c
+++ b/input/flow/ulogd_inpflow_CTNL.c
@@ -9,21 +9,21 @@
* as published by the Free Software Foundation
*/
+#include <errno.h>
#include <ulogd/ulogd.h>
#include <libnfnetlink/libnfnetlink.h>
#include <libnfnetlink_conntrack/libnfnetlink_conntrack.h>
-static struct ulogd_ctnl_pluginstance {
- struct ulogd_pluginstance upi;
- struct ctnl_handle cth;
+struct ctnl_pluginstance {
+ struct ctnl_handle *cth;
struct ulogd_fd ctnl_fd;
};
+#if 0
static int ctnl_parser(struct ulogd_pluginstance *pi,
- struct nfattr *attr, struct nlmsghdr *nlh)
+ struct nfattr *_attr, struct nlmsghdr *nlh)
{
struct nfattr *attr = NFM_NFA(NLMSG_DATA(nlh));
- unsigned int attrlen = nlh->nlmsg_len - NLMSG_ALIGN(min_len);
struct ip_conntrack_tuple *orig;
struct cta_countrs *ctr;
@@ -47,6 +47,7 @@ static int ctnl_parser(struct ulogd_pluginstance *pi,
}
return 0;
}
+#endif
static int event_handler(struct sockaddr_nl *sock, struct nlmsghdr *nlh,
void *arg)
@@ -62,12 +63,14 @@ static int event_handler(struct sockaddr_nl *sock, struct nlmsghdr *nlh,
if (nlh->nlmsg_len < min_len)
return -EINVAL;
+#if 0
if (type == IPCTNL_MSG_CT_NEW && flags & NLM_F_CREATE) {
/* FIXME: build hash table with timestamp of start of
* connection */
} else if (type == IPCTNL_MSG_CT_DELETE) {
/* We have the final count of bytes for this connection */
}
+#endif
return 0;
}
@@ -75,14 +78,15 @@ static struct ctnl_msg_handler new_h = {
.type = IPCTNL_MSG_CT_NEW,
.handler = event_handler,
};
-static struct ctnl_msg_Handler destroy_h = {
+
+static struct ctnl_msg_handler destroy_h = {
.type = IPCTNL_MSG_CT_DELETE,
.handler = event_handler,
};
static int read_cb_ctnl(int fd, unsigned int what, void *param)
{
- struct ulogd_ctnl_pluginstance *cpi =
+ struct ctnl_pluginstance *cpi =
(struct ulogd_ctnl_pluginstance *) param;
if (!(what & ULOGD_FD_READ))
@@ -92,30 +96,25 @@ static int read_cb_ctnl(int fd, unsigned int what, void *param)
ctnl_event_conntrack(&cpi->cth, AF_INET);
}
-static struct ulogd_pluginstance *constructor_ctnl(struct ulogd_plugin *pl)
+static int constructor_ctnl(struct ulogd_pluginstance *upi)
{
- struct ulogd_ctnl_pluginstance *cpi = malloc(sizeof *cpi);
-
- if (!cpu)
- return NULL;
+ struct ctnl_pluginstance *cpi =
+ (struct ctnl_pluginstance *)upi->private;
memset(cpi, NULL, sizeof(*cpi));
- cpi->plugin = pl;
- cpi->input = FIXME;
- cpi->output = FIXME;
-
- if (ctnl_open(&cpi->cth, NFGRP_IPV4_CT_TCP|NFGRP_IPV4_CT_UDP) < 0) {
- print("error\n");
- return NULL;
+ /* FIXME: make eventmask configurable */
+ cpi->cth = ctnl_open(NFNL_SUBSYS_CTNETLINK, NF_NETLINK_CONNTRACK_NEW|
+ NF_NETLINK_CONNTRACK_DESTROY);
+ if (!cph->cth) {
+ print("error opening ctnetlink\n");
+ return -1;
}
- ctnl_register_handler(&cpi->cth, &new_h);
- ctnl_register_handler(&cpi->cth, &destroy_h);
-
- /* FIXME: ctnl interface must allow usage of external select
- * loop */
- cpi->ctnl_fd.fd = ctnl_get_fd(&cpi->cth);
+ ctnl_register_handler(cpi->cth, &new_h);
+ ctnl_register_handler(cpi->cth, &destroy_h);
+
+ cpi->ctnl_fd.fd = ctnl_fd(cpi->cth);
cpi->ctnl_fd.cb = &read_cb_ctnl;
cpi->ctnl_fd.data = cpi;
@@ -127,7 +126,7 @@ static struct ulogd_pluginstance *constructor_ctnl(struct ulogd_plugin *pl)
static int destructor_ctnl(struct ulogd_pluginstance *pi)
{
- struct ulogd_ctnl_pluginstance *cpi = (void *) pi;
+ struct ctnl_pluginstance *cpi = (void *) pi;
if (ctnl_close(&cpi->cth) < 0) {
print("error2\n");
@@ -198,21 +197,24 @@ static struct ulogd_key ctnl_okeys[] = {
static struct ulogd_plugin ctnl_plugin = {
.name = "CTNL",
.input = {
- .keys = NULL,
- .num_keys = 0,
- .type = ULOGD_DTYPE_NULL,
+ .type = ULOGD_DTYPE_SOURCE,
},
.output = {
.keys = &ctnl_okeys,
- .num_keys = sizeof(ctnl_okeys)/sizeof(struct ulogd_key),
+ .num_keys = ARRAY_SIZE(ctnl_okeys),
.type = ULOGD_DTYPE_FLOW,
},
- .interp = ,
- .constructor = &constructor_ctnl,
- .descructor = &destructor_ctnl,
- .config_kset = ,
+ .config_kset = ,
+ .interp = ,
+ .configure =
+ .start = &constructor_ctnl,
+ .stop = &destructor_ctnl,
};
+void __attribute__ ((constructor)) init(void);
-
+void init(void)
+{
+ ulogd_register_plugin(&ctnl_plugin);
+}