summaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
author/C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org </C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org>2007-05-20 20:29:53 +0000
committer/C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org </C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org>2007-05-20 20:29:53 +0000
commit434bca2b42ad82e3d0ab56d066716410c2ae27d5 (patch)
tree27de77cd16eaf0a9c4bd300f89668e82af9f8a43 /utils
parent8ca32474125483ae58e93e2822a8e5af9f9b72ab (diff)
- delete ctnl_test.c since it contains examples of the old *deprecated* API
- fix wrong port display in the XML output (Morten Isaksen) - use ntohs instead htons in snprintf_default.c
Diffstat (limited to 'utils')
-rw-r--r--utils/Makefile.am7
-rw-r--r--utils/ctnl_test.c159
2 files changed, 1 insertions, 165 deletions
diff --git a/utils/Makefile.am b/utils/Makefile.am
index 9316368..cf406b5 100644
--- a/utils/Makefile.am
+++ b/utils/Makefile.am
@@ -1,16 +1,11 @@
include $(top_srcdir)/Make_global.am
-bin_PROGRAMS = ctnl_test \
- expect_dump expect_create expect_get expect_delete \
+bin_PROGRAMS = expect_dump expect_create expect_get expect_delete \
expect_flush expect_events \
conntrack_create conntrack_dump conntrack_update \
conntrack_delete conntrack_flush conntrack_create_nat \
conntrack_get conntrack_events
-ctnl_test_SOURCES = ctnl_test.c
-ctnl_test_LDADD = ../src/libnetfilter_conntrack.la
-ctnl_test_LDFLAGS = -dynamic -ldl
-
conntrack_create_SOURCES = conntrack_create.c
conntrack_create_LDADD = ../src/libnetfilter_conntrack.la
conntrack_create_LDFLAGS = -dynamic -ldl
diff --git a/utils/ctnl_test.c b/utils/ctnl_test.c
deleted file mode 100644
index 381f697..0000000
--- a/utils/ctnl_test.c
+++ /dev/null
@@ -1,159 +0,0 @@
-/*
- * (C) 2005 by Pablo Neira Ayuso <pablo@eurodev.net>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * libnetfilter_conntrack test file: yet incomplete
- *
- * XXX: This is the test file for the *old* libnetfilter_conntrack API.
- * Please, do not use this API for new applications since the old
- * API will be removed soon.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <signal.h>
-#include <libnetfilter_conntrack/libnetfilter_conntrack.h>
-
-static int event_counter(void *arg, unsigned int flags, int type, void *data)
-{
- static int counter = 0;
-
- fprintf(stdout, "Event number %d\n", ++counter);
- if (counter >= 10)
- return -1;
-
- return 0;
-}
-
-static struct nfct_conntrack *ct;
-static struct nfct_handle *cth;
-
-static void event_sighandler(int s)
-{
- nfct_conntrack_free(ct);
- nfct_close(cth);
-}
-
-/* I know, better with fork() as Rusty does in nfsim ;), later */
-int main(int argc, char **argv)
-{
- struct nfct_tuple orig = {
- .src = { .v4 = inet_addr("1.1.1.1") },
- .dst = { .v4 = inet_addr("2.2.2.2") },
- .l3protonum = AF_INET,
- .protonum = IPPROTO_TCP,
- .l4src = { .tcp = { .port = ntohs(10) } },
- .l4dst = { .tcp = { .port = ntohs(20) } }
- };
- struct nfct_tuple reply = {
- .src = { .v4 = inet_addr("2.2.2.2") },
- .dst = { .v4 = inet_addr("1.1.1.1") },
- .l3protonum = AF_INET,
- .protonum = IPPROTO_TCP,
- .l4src = { .tcp = { .port = ntohs(20) } },
- .l4dst = { .tcp = { .port = ntohs(10) } }
- };
- union nfct_protoinfo proto = {
- .tcp = { .state = 1 },
- };
- unsigned long status = IPS_ASSURED | IPS_CONFIRMED;
- unsigned long timeout = 100;
- unsigned long mark = 0;
- unsigned long id = NFCT_ANY_ID;
- int ret = 0, errors = 0;
-
- /* Here we go... */
- fprintf(stdout, "Test for libnetfilter_conntrack\n\n");
-
- ct = nfct_conntrack_alloc(&orig, &reply, timeout, &proto, status,
- mark, id, NULL);
- if (!ct) {
- fprintf(stderr, "Not enough memory");
- errors++;
- ret = -ENOMEM;
- goto end;
- }
-
- cth = nfct_open(CONNTRACK, 0);
- if (!cth) {
- fprintf(stderr, "Can't open handler\n");
- errors++;
- ret = -ENOENT;
- nfct_conntrack_free(ct);
- goto end;
- }
-
- ret = nfct_create_conntrack(cth, ct);
- fprintf(stdout, "TEST 1: create conntrack (%d)\n", ret);
-
- /* Skip EEXIST error, in case that the test has been called
- * twice this spot a bogus error */
- if (ret < 0 && ret != -EEXIST)
- errors++;
-
- if (ret == -EINVAL)
- fprintf(stdout, "NFNETLINK answers: -EINVAL, make sure "
- "ip_conntrack_netlink is loaded and "
- "you have NET_CAPABILITIES");
-
- nfct_register_callback(cth, nfct_default_conntrack_display, NULL);
- ret = nfct_dump_conntrack_table_reset_counters(cth, AF_INET);
- fprintf(stdout, "TEST 2: dump conntrack table and reset (%d)\n", ret);
- if (ret < 0)
- errors++;
-
- ret = nfct_dump_conntrack_table(cth, AF_INET);
- fprintf(stdout, "TEST 3: dump conntrack table (%d)\n", ret);
- if (ret < 0)
- errors++;
-
- ret = nfct_get_conntrack(cth, &orig, NFCT_DIR_ORIGINAL, NFCT_ANY_ID);
- fprintf(stdout, "TEST 4: get conntrack (%d)\n", ret);
- if (ret < 0)
- errors++;
-
- ct->status |= IPS_SEEN_REPLY;
- ct->timeout = 1000;
- ret = nfct_update_conntrack(cth, ct);
- fprintf(stdout, "TEST 5: update conntrack (%d)\n", ret);
- if (ret < 0)
- errors++;
-
- ret = nfct_delete_conntrack(cth, &orig, NFCT_DIR_ORIGINAL, NFCT_ANY_ID);
- fprintf(stdout, "TEST 6: delete conntrack (%d)\n", ret);
- if (ret < 0)
- errors++;
-
- nfct_close(cth);
-
- /* Now open a handler that is subscribed to all possible events */
- cth = nfct_open(CONNTRACK, NFCT_ALL_CT_GROUPS);
- if (!cth) {
- fprintf(stderr, "Can't open handler\n");
- errors++;
- ret = -ENOENT;
- nfct_conntrack_free(ct);
- goto end;
- }
-
- fprintf(stdout, "TEST 7: Waiting for 10 conntrack events\n");
- signal(SIGINT, event_sighandler);
- nfct_register_callback(cth, event_counter, NULL);
- ret = nfct_event_conntrack(cth);
- fprintf(stdout, "TEST 7: Received 10 conntrack events (%d)\n", ret);
-
- nfct_close(cth);
- nfct_conntrack_free(ct);
-
-end:
- if (errors)
- fprintf(stdout, "Test failed with error %d. Errors=%d\n",
- ret, errors);
- else
- fprintf(stdout, "Test OK\n");
-}