From 434bca2b42ad82e3d0ab56d066716410c2ae27d5 Mon Sep 17 00:00:00 2001 From: "/C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org" Date: Sun, 20 May 2007 20:29:53 +0000 Subject: - 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 --- src/conntrack/snprintf_default.c | 4 +- src/conntrack/snprintf_xml.c | 4 +- utils/Makefile.am | 7 +- utils/ctnl_test.c | 159 --------------------------------------- 4 files changed, 5 insertions(+), 169 deletions(-) delete mode 100644 utils/ctnl_test.c diff --git a/src/conntrack/snprintf_default.c b/src/conntrack/snprintf_default.c index 7f63d4c..054a4fc 100644 --- a/src/conntrack/snprintf_default.c +++ b/src/conntrack/snprintf_default.c @@ -141,8 +141,8 @@ int __snprintf_proto(char *buf, case IPPROTO_UDP: case IPPROTO_SCTP: return snprintf(buf, len, "sport=%u dport=%u ", - htons(tuple->l4src.tcp.port), - htons(tuple->l4dst.tcp.port)); + ntohs(tuple->l4src.tcp.port), + ntohs(tuple->l4dst.tcp.port)); break; case IPPROTO_ICMP: /* The ID only makes sense some ICMP messages but we want to diff --git a/src/conntrack/snprintf_xml.c b/src/conntrack/snprintf_xml.c index 6c3257f..669d3e8 100644 --- a/src/conntrack/snprintf_xml.c +++ b/src/conntrack/snprintf_xml.c @@ -182,13 +182,13 @@ static int __snprintf_proto_xml(char *buf, case IPPROTO_SCTP: if (type == __ADDR_SRC) { ret = snprintf(buf, len, "%u", - tuple->l4src.tcp.port); + ntohs(tuple->l4src.tcp.port)); if (ret == -1) return -1; buffer_size(ret, &size, &len); } else { ret = snprintf(buf, len, "%u", - tuple->l4dst.tcp.port); + ntohs(tuple->l4dst.tcp.port)); if (ret == -1) return -1; buffer_size(ret, &size, &len); 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 - * - * 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 -#include -#include -#include -#include - -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"); -} -- cgit v1.2.3