summaryrefslogtreecommitdiffstats
path: root/input/packet
diff options
context:
space:
mode:
authorlaforge <laforge>2005-04-17 15:16:18 +0000
committerlaforge <laforge>2005-04-17 15:16:18 +0000
commit29b6d125769417262b4841fe78e46813127a5d71 (patch)
tree8dd4760d07d83ad0309294eb1a07cef0e741b5ec /input/packet
parent9951ab9f02424d84ce1f176540a12285a5a11d69 (diff)
current working state (doesn't compile yet)
Diffstat (limited to 'input/packet')
-rw-r--r--input/packet/ulogd_inppkt_ULOG.c98
1 files changed, 50 insertions, 48 deletions
diff --git a/input/packet/ulogd_inppkt_ULOG.c b/input/packet/ulogd_inppkt_ULOG.c
index 640b86c..92e3ffa 100644
--- a/input/packet/ulogd_inppkt_ULOG.c
+++ b/input/packet/ulogd_inppkt_ULOG.c
@@ -1,12 +1,17 @@
/* ulogd_inppkt_ULOG.c - stackable input plugin for ULOG packets -> ulogd2
- * (C) 2004 by Harald Welte <laforge@gnumonks.org>
+ * (C) 2004-2005 by Harald Welte <laforge@gnumonks.org>
*/
-#include <ulogd/ulogd.h>
-#include <ulogd/conffile.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <ulogd/ulogd.h>
#include <libipulog/libipulog.h>
+#ifndef ULOGD_NLGROUP_DEFAULT
+#define ULOGD_NLGROUP_DEFAULT 32
+#endif
+
/* Size of the socket recevive memory. Should be at least the same size as the
* 'nlbufsiz' module loadtime parameter of ipt_ULOG.o
* If you have _big_ in-kernel queues, you may have to increase this number. (
@@ -19,13 +24,15 @@
struct ulog_input {
struct ipulog_handle *libulog_h;
- static unsigned char *libulog_buf;
- static struct ulogd_fd ulog_fd;
+ unsigned char *libulog_buf;
+ struct ulogd_fd ulog_fd;
};
/* configuration entries */
-static struct config_entry ulog_ces[] = {
+static struct config_keyset libulog_kset = {
+ .num_ces = 10,
+ .ces = {
{
.key = "bufsize",
.type = CONFIG_TYPE_INT,
@@ -44,25 +51,12 @@ static struct config_entry ulog_ces[] = {
.options = CONFIG_OPT_NONE,
.u.value = ULOGD_RMEM_DEFAULT,
},
+ }
};
#define bufsiz_ce(x) (x[0])
#define nlgroup_ce(x) (x[1])
-#define rmem_cd(x) (x[2])
-
-#if 0
-static config_entry_t bufsiz_ce = { NULL, "bufsize", CONFIG_TYPE_INT,
- CONFIG_OPT_NONE, 0,
- { value: ULOGD_BUFSIZE_DEFAULT } };
-
-static config_entry_t nlgroup_ce = { &bufsiz_ce, "nlgroup", CONFIG_TYPE_INT,
- CONFIG_OPT_NONE, 0,
- { value: ULOGD_NLGROUP_DEFAULT } };
-
-static config_entry_t rmem_ce = { &nlgroup_ce, "rmem", CONFIG_TYPE_INT,
- CONFIG_OPT_NONE, 0,
- { value: ULOGD_RMEM_DEFAULT } };
-#endif
+#define rmem_ce(x) (x[2])
static struct ulogd_key output_keys[] = {
@@ -138,13 +132,13 @@ static int interp_packet(struct ulogd_pluginstance *ip, ulog_packet_msg_t *pkt)
unsigned char *p;
int i;
char *buf, *oldbuf = NULL;
- ulog_iret_t *ret = ip->result;
+ struct ulogd_key *ret = ip->output;
if (pkt->mac_len) {
buf = (char *) malloc(3 * pkt->mac_len + 1);
if (!buf) {
ulogd_log(ULOGD_ERROR, "OOM!!!\n");
- return NULL;
+ return -1;
}
*buf = '\0';
@@ -152,52 +146,55 @@ static int interp_packet(struct ulogd_pluginstance *ip, ulog_packet_msg_t *pkt)
oldbuf = buf;
for (i = 0; i < pkt->mac_len; i++, p++)
sprintf(buf, "%s%02x%c", oldbuf, *p, i==pkt->mac_len-1 ? ' ':':');
- ret[0].value.ptr = buf;
+ ret[0].u.value.ptr = buf;
ret[0].flags |= ULOGD_RETF_VALID;
}
/* include pointer to raw ipv4 packet */
- ret[1].value.ptr = pkt->payload;
+ ret[1].u.value.ptr = pkt->payload;
ret[1].flags |= ULOGD_RETF_VALID;
- ret[2].value.ui32 = pkt->data_len;
+ ret[2].u.value.ui32 = pkt->data_len;
ret[2].flags |= ULOGD_RETF_VALID;
- ret[3].value.ui32 = 1;
+ ret[3].u.value.ui32 = 1;
ret[3].flags |= ULOGD_RETF_VALID;
- ret[4].value.ptr = pkt->prefix;
+ ret[4].u.value.ptr = pkt->prefix;
ret[4].flags |= ULOGD_RETF_VALID;
/* god knows why timestamp_usec contains crap if timestamp_sec == 0
* if (pkt->timestamp_sec || pkt->timestamp_usec) { */
if (pkt->timestamp_sec) {
- ret[5].value.ui32 = pkt->timestamp_sec;
+ ret[5].u.value.ui32 = pkt->timestamp_sec;
ret[5].flags |= ULOGD_RETF_VALID;
- ret[6].value.ui32 = pkt->timestamp_usec;
+ ret[6].u.value.ui32 = pkt->timestamp_usec;
ret[6].flags |= ULOGD_RETF_VALID;
} else {
ret[5].flags &= ~ULOGD_RETF_VALID;
ret[6].flags &= ~ULOGD_RETF_VALID;
}
- ret[7].value.ui32 = pkt->mark;
+ ret[7].u.value.ui32 = pkt->mark;
ret[7].flags |= ULOGD_RETF_VALID;
- ret[8].value.ptr = pkt->indev_name;
+ ret[8].u.value.ptr = pkt->indev_name;
ret[8].flags |= ULOGD_RETF_VALID;
- ret[9].value.ptr = pkt->outdev_name;
+ ret[9].u.value.ptr = pkt->outdev_name;
ret[9].flags |= ULOGD_RETF_VALID;
- return ret;
+ return 0;
}
-static struct ulog_read_cb(int fd, void *param)
+static int ulog_read_cb(int fd, unsigned int what, void *param)
{
struct ulogd_pluginstance *upi = (struct ulogd_pluginstance *)param;
- struct ulog_input *u = (struct ulog_input *)param->private;
+ struct ulog_input *u = (struct ulog_input *)upi->private;
ulog_packet_msg_t *upkt;
int len;
+ if (!(what & ULOGD_FD_READ))
+ return 0;
+
while (len = ipulog_read(u->libulog_h, u->libulog_buf,
- bufsiz_ce.u.value, 1)) {
+ bufsiz_ce(upi->configs).u.value, 1)) {
if (len <= 0) {
/* this is not supposed to happen */
ulogd_log(ULOGD_ERROR, "ipulog_read = %d! "
@@ -207,7 +204,7 @@ static struct ulog_read_cb(int fd, void *param)
}
while ((upkt = ipulog_get_packet(u->libulog_h,
u->libulog_buf, len))) {
- DEBUGP("==> ulog packet received\n");
+ ulogd_log(ULOGD_DEBUG, "==> ulog packet received\n");
interp_packet(upi, upkt);
}
}
@@ -227,23 +224,23 @@ static struct ulogd_pluginstance *init(struct ulogd_plugin *pl)
upi->input = NULL;
/* FIXME: upi->output = */
- ui->libulog_buf = malloc(bufsiz_ce.u.value);
+ ui->libulog_buf = malloc(bufsiz_ce(upi->configs).u.value);
if (!ui->libulog_buf)
goto out_buf;
ui->libulog_h = ipulog_create_handle(
- ipulog_group2gmask(nlgroup_ce.u.value),
- rmem_ce.u.value);
- if (!libulog_h)
+ ipulog_group2gmask(nlgroup_ce(upi->configs).u.value),
+ rmem_ce(upi->configs).u.value);
+ if (!ui->libulog_h)
goto out_handle;
- ui->ulog_fd.fd = ui->libulog_h->fd;
+ ui->ulog_fd.fd = ipulog_get_fd(ui->libulog_h);
ui->ulog_fd.cb = &ulog_read_cb;
ui->ulog_fd.data = upi;
ulogd_register_fd(&ui->ulog_fd);
- return ui;
+ return upi;
out_handle:
free(ui->libulog_buf);
out_buf:
@@ -253,6 +250,12 @@ out_buf:
static int fini(struct ulogd_pluginstance *pi)
{
+ struct ulog_input *ui = (struct ulog_input *)pi->private;
+
+ ulogd_unregister_fd(&ui->ulog_fd);
+ free(pi);
+
+ return 0;
}
struct ulogd_plugin libulog_plugin = {
@@ -262,13 +265,12 @@ struct ulogd_plugin libulog_plugin = {
},
.output = {
.type = ULOGD_DTYPE_RAW,
- .keys = &ulog_output_key,
- .num = 10,
+ .keys = &output_keys,
+ .num_keys = sizeof(output_keys)/sizeof(struct ulogd_key),
},
.constructor = &init,
.destructor = &fini,
- .num_configs = (sizeof(ulog_ces)/sizeof(struct config_entry)),
- .configs = &ulog_ces,
+ .config_kset = &libulog_kset,
};
void _init(void)