summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
author/C=DE/ST=Berlin/L=Berlin/O=Netfilter Project/OU=Development/CN=laforge/emailAddress=laforge@netfilter.org </C=DE/ST=Berlin/L=Berlin/O=Netfilter Project/OU=Development/CN=laforge/emailAddress=laforge@netfilter.org>2005-08-08 17:08:03 +0000
committer/C=DE/ST=Berlin/L=Berlin/O=Netfilter Project/OU=Development/CN=laforge/emailAddress=laforge@netfilter.org </C=DE/ST=Berlin/L=Berlin/O=Netfilter Project/OU=Development/CN=laforge/emailAddress=laforge@netfilter.org>2005-08-08 17:08:03 +0000
commit658769c3587219bdc1a87c23c41aa971ef67263e (patch)
treebfa14eb07b58e855c2234cb4130ebe9cf10fb6fd
parentcb9192a15b78d373ac802d640f4b29cac4b24633 (diff)
- some more work on libipulog compat API [almost finished]
- improt ulog_test.c from libipulog in order to test libipulog compat API
-rw-r--r--_log/src/libipulog_compat.c20
-rw-r--r--_log/utils/Makefile.am4
-rw-r--r--_log/utils/ulog_test.c87
3 files changed, 104 insertions, 7 deletions
diff --git a/_log/src/libipulog_compat.c b/_log/src/libipulog_compat.c
index d981e94..a0675ec 100644
--- a/_log/src/libipulog_compat.c
+++ b/_log/src/libipulog_compat.c
@@ -5,6 +5,7 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
+#include <libnfnetlink/libnfnetlink.h>
#include <libnfnetlink_log/libnfnetlink_log.h>
#include <libnfnetlink_log/libipulog.h>
@@ -85,6 +86,7 @@ u_int32_t ipulog_group2gmask(u_int32_t group)
struct ipulog_handle *ipulog_create_handle(u_int32_t gmask,
u_int32_t rcvbufsize)
{
+ int rv;
struct ipulog_handle *h;
unsigned int group = gmask2group(gmask);
@@ -98,7 +100,9 @@ struct ipulog_handle *ipulog_create_handle(u_int32_t gmask,
if (!h->nfulh)
goto out_free;
- if (nfulnl_bind_pf(h->nfulh, AF_INET) < 0)
+ /* bind_pf returns EEXIST if we are already registered */
+ rv = nfulnl_bind_pf(h->nfulh, AF_INET);
+ if (rv < 0 && rv != -EEXIST)
goto out_free;
h->nful_gh = nfulnl_bind_group(h->nfulh, group);
@@ -128,10 +132,11 @@ ulog_packet_msg_t *ipulog_get_packet(struct ipulog_handle *h,
struct nfattr *tb[NFULA_MAX];
struct nfulnl_msg_packet_hdr *hdr;
- if (!h->last_nlh)
+ if (!h->last_nlh) {
+ printf("first\n");
nlh = nfnl_get_msg_first(nfulnl_nfnlh(h->nfulh), buf, len);
- else {
-next_msg:
+ }else {
+next_msg: printf("next\n");
nlh = nfnl_get_msg_next(nfulnl_nfnlh(h->nfulh), buf, len);
}
h->last_nlh = nlh;
@@ -139,7 +144,8 @@ next_msg:
if (!nlh)
return NULL;
- nfnl_parse_attr(tb, NFULA_MAX, NFM_NFA(nlh), NFM_PAYLOAD(nlh));
+ nfnl_parse_attr(tb, NFULA_MAX, NFM_NFA(NLMSG_DATA(nlh)),
+ NFM_PAYLOAD(nlh));
if (!tb[NFULA_PACKET_HDR-1])
goto next_msg;
@@ -199,7 +205,9 @@ next_msg:
ssize_t ipulog_read(struct ipulog_handle *h, unsigned char *buf,
size_t len, int timeout)
{
- //return nfnl_listen();
+ /* 'timeout' was never implemented in the original libipulog,
+ * so we don't bother emulating it */
+ return nfnl_recv(nfulnl_nfnlh(h->nfulh), buf, len);
}
/* print a human readable description of the last error to stderr */
diff --git a/_log/utils/Makefile.am b/_log/utils/Makefile.am
index b0fe8a3..a62909f 100644
--- a/_log/utils/Makefile.am
+++ b/_log/utils/Makefile.am
@@ -1,8 +1,10 @@
-bin_PROGRAMS = nfulnl_test
+bin_PROGRAMS = nfulnl_test ulog_test
nfulnl_test_SOURCES = nfulnl_test.c
+ulog_test_SOURCES = ulog_test.c
INCLUDES = $(all_includes) -I$(top_srcdir)/include -I${KERNELDIR}
nfulnl_test_LDFLAGS = $(all_libraries) -lnfnetlink_log
+ulog_test_LDFLAGS = $(all_libraries) -lnfnetlink_log_libipulog -lnfnetlink_log
diff --git a/_log/utils/ulog_test.c b/_log/utils/ulog_test.c
new file mode 100644
index 0000000..f8515d3
--- /dev/null
+++ b/_log/utils/ulog_test.c
@@ -0,0 +1,87 @@
+/* ulog_test, $Revision: 1.4 $
+ *
+ * small testing program for libipulog, part of the netfilter ULOG target
+ * for the linux 2.4 netfilter subsystem.
+ *
+ * (C) 2000 by Harald Welte <laforge@gnumonks.org>
+ *
+ * this code is released under the terms of GNU GPL
+ *
+ * $Id: ulog_test.c 286 2002-06-13 12:56:53Z laforge $
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <libnfnetlink_log/libipulog.h>
+
+#define MYBUFSIZ 2048
+
+/* prints some logging about a single packet */
+void handle_packet(ulog_packet_msg_t *pkt)
+{
+ unsigned char *p;
+ int i;
+
+ printf("Hook=%u Mark=%lu len=%d ",
+ pkt->hook, pkt->mark, pkt->data_len);
+ if (strlen(pkt->prefix))
+ printf("Prefix=%s ", pkt->prefix);
+
+ if (pkt->mac_len)
+ {
+ printf("mac=");
+ p = pkt->mac;
+ for (i = 0; i < pkt->mac_len; i++, p++)
+ printf("%02x%c", *p, i==pkt->mac_len-1 ? ' ':':');
+ }
+ printf("\n");
+
+}
+
+int main(int argc, char *argv[])
+{
+ struct ipulog_handle *h;
+ unsigned char* buf;
+ int len;
+ ulog_packet_msg_t *upkt;
+ int i;
+
+ if (argc != 4) {
+ fprintf(stderr, "Usage: %s count group timeout\n", argv[0]);
+ exit(2);
+ }
+
+ /* allocate a receive buffer */
+ buf = (unsigned char *) malloc(MYBUFSIZ);
+ if (!buf)
+ exit(1);
+
+ /* create ipulog handle */
+ h = ipulog_create_handle(ipulog_group2gmask(atoi(argv[2])), 65535);
+ if (!h)
+ {
+ /* if some error occurrs, print it to stderr */
+ ipulog_perror(NULL);
+ exit(1);
+ }
+
+ alarm(atoi(argv[3]));
+
+ /* loop receiving packets and handling them over to handle_packet */
+ for (i = 0; i < atoi(argv[1]); i++) {
+ len = ipulog_read(h, buf, MYBUFSIZ, 1);
+ if (len <= 0) {
+ ipulog_perror("ulog_test: short read");
+ exit(1);
+ }
+ printf("%d bytes received\n", len);
+ while (upkt = ipulog_get_packet(h, buf, len)) {
+ handle_packet(upkt);
+ }
+ }
+
+ /* just to give it a cleaner look */
+ ipulog_destroy_handle(h);
+ return 0;
+}