summaryrefslogtreecommitdiff
path: root/extensions
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-04-16 13:30:56 +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-04-16 13:30:56 +0000
commitc86e48dc7d688d97a6ee4697ce01e594fa70d7db (patch)
treeb2e30ee2f32ca7f6e8f0cf602c499d97774ca8a3 /extensions
downloadconntrack-tools-c86e48dc7d688d97a6ee4697ce01e594fa70d7db.tar.gz
conntrack-tools-c86e48dc7d688d97a6ee4697ce01e594fa70d7db.zip
add pablo's conntrack tool
Diffstat (limited to 'extensions')
-rw-r--r--extensions/Makefile12
-rw-r--r--extensions/libct_proto_tcp.c67
-rw-r--r--extensions/libct_proto_udp.c67
3 files changed, 146 insertions, 0 deletions
diff --git a/extensions/Makefile b/extensions/Makefile
new file mode 100644
index 0000000..e23ed90
--- /dev/null
+++ b/extensions/Makefile
@@ -0,0 +1,12 @@
+CC=gcc
+
+all:
+ ${CC} -fPIC -Wall -g -c libct_proto_tcp.c
+ ${CC} -g -shared -Wl,-soname,libct_proto_tcp.so.0 -o libct_proto_tcp.so.0.0 libct_proto_tcp.o -lc
+ ln -sf libct_proto_tcp.so.0.0 libct_proto_tcp.so
+
+ ${CC} -fPIC -Wall -g -c libct_proto_udp.c
+ ${CC} -g -shared -Wl,-soname,libct_proto_udp.so.0 -o libct_proto_udp.so.0.0 libct_proto_udp.o -lc
+ ln -sf libct_proto_udp.so.0.0 libct_proto_udp.so
+clean:
+ rm -rf *.so *.so.* *.o
diff --git a/extensions/libct_proto_tcp.c b/extensions/libct_proto_tcp.c
new file mode 100644
index 0000000..521a170
--- /dev/null
+++ b/extensions/libct_proto_tcp.c
@@ -0,0 +1,67 @@
+#include <stdio.h>
+#include <getopt.h>
+#include <stdlib.h>
+#include <netinet/in.h> /* For htons */
+#include <linux/netfilter_ipv4/ip_conntrack_tuple.h>
+#include <linux/netfilter_ipv4/ip_conntrack.h>
+#include "../include/libct_proto.h"
+
+static struct option opts[] = {
+ {"orig-port-src", 1, 0, '1'},
+ {"orig-port-dst", 1, 0, '2'},
+ {"reply-port-src", 1, 0, '3'},
+ {"reply-port-dst", 1, 0, '4'},
+ {0, 0, 0, 0}
+};
+
+int parse(char c, char *argv[],
+ struct ip_conntrack_tuple *orig,
+ struct ip_conntrack_tuple *reply)
+{
+ switch(c) {
+ case '1':
+ if (optarg)
+ orig->src.u.tcp.port = htons(atoi(optarg));
+ break;
+ case '2':
+ if (optarg)
+ orig->dst.u.tcp.port = htons(atoi(optarg));
+ break;
+ case '3':
+ if (optarg)
+ reply->src.u.tcp.port = htons(atoi(optarg));
+ break;
+ case '4':
+ if (optarg)
+ reply->dst.u.tcp.port = htons(atoi(optarg));
+ break;
+ }
+ return 1;
+}
+
+void print(struct ip_conntrack_tuple *t)
+{
+ printf("sport=%d dport=%d ", ntohs(t->src.u.tcp.port),
+ ntohs(t->dst.u.tcp.port));
+}
+
+static struct ctproto_handler tcp = {
+ .name = "tcp",
+ .protonum = 6,
+ .parse = parse,
+ .print = print,
+ .opts = opts
+};
+
+void __attribute__ ((constructor)) init(void);
+void __attribute__ ((destructor)) fini(void);
+
+void init(void)
+{
+ register_proto(&tcp);
+}
+
+void fini(void)
+{
+ unregister_proto(&tcp);
+}
diff --git a/extensions/libct_proto_udp.c b/extensions/libct_proto_udp.c
new file mode 100644
index 0000000..8022913
--- /dev/null
+++ b/extensions/libct_proto_udp.c
@@ -0,0 +1,67 @@
+#include <stdio.h>
+#include <getopt.h>
+#include <stdlib.h>
+#include <netinet/in.h> /* For htons */
+#include <linux/netfilter_ipv4/ip_conntrack_tuple.h>
+#include <linux/netfilter_ipv4/ip_conntrack.h>
+#include "../include/libct_proto.h"
+
+static struct option opts[] = {
+ {"orig-port-src", 1, 0, '1'},
+ {"orig-port-dst", 1, 0, '2'},
+ {"reply-port-src", 1, 0, '3'},
+ {"reply-port-dst", 1, 0, '4'},
+ {0, 0, 0, 0}
+};
+
+int parse(char c, char *argv[],
+ struct ip_conntrack_tuple *orig,
+ struct ip_conntrack_tuple *reply)
+{
+ switch(c) {
+ case '1':
+ if (optarg)
+ orig->src.u.udp.port = htons(atoi(optarg));
+ break;
+ case '2':
+ if (optarg)
+ orig->dst.u.udp.port = htons(atoi(optarg));
+ break;
+ case '3':
+ if (optarg)
+ reply->src.u.udp.port = htons(atoi(optarg));
+ break;
+ case '4':
+ if (optarg)
+ reply->dst.u.udp.port = htons(atoi(optarg));
+ break;
+ }
+ return 1;
+}
+
+void print(struct ip_conntrack_tuple *t)
+{
+ printf("sport=%d dport=%d ", ntohs(t->src.u.udp.port),
+ ntohs(t->dst.u.udp.port));
+}
+
+static struct ctproto_handler udp = {
+ .name = "udp",
+ .protonum = 17,
+ .parse = parse,
+ .print = print,
+ .opts = opts
+};
+
+void __attribute__ ((constructor)) init(void);
+void __attribute__ ((destructor)) fini(void);
+
+void init(void)
+{
+ register_proto(&udp);
+}
+
+void fini(void)
+{
+ unregister_proto(&udp);
+}