Skip to contentSkip to conversation

conntrack-tools unknown protocol search by number

PATCH Bryan Duff 2 participants 3 messages Oct 3, 2008 – Oct 6, 2008 netfilter

lore
Share & tools
lore

Bryan Duff

author
#0 lore raw

Now instead of "conntrack -L -p tcp" you can do "conntrack -L -p 6" - useful for "unknown" proto's like gre, ah, esp.

Thanks.

-Bryan Duff

extensions/Makefile.am +3 -1
index 0eede22..8165e05 100644
@@ -1,9 +1,11 @@
 include $(top_srcdir)/Make_global.am
 
 noinst_LTLIBRARIES = libct_proto_tcp.la libct_proto_udp.la \
-		     libct_proto_icmp.la libct_proto_icmpv6.la
+		     libct_proto_icmp.la libct_proto_icmpv6.la \
+				 libct_proto_unknown.la
 
 libct_proto_tcp_la_SOURCES = libct_proto_tcp.c
 libct_proto_udp_la_SOURCES = libct_proto_udp.c
 libct_proto_icmp_la_SOURCES = libct_proto_icmp.c
 libct_proto_icmpv6_la_SOURCES = libct_proto_icmpv6.c
+libct_proto_unknown_la_SOURCES = libct_proto_unknown.c
extensions/libct_proto_unknown.c new file +65 -0

65 lines not on this page · raw message

include/conntrack.h +1 -0
index 69c2317..4787809 100644
@@ -191,5 +191,6 @@ extern void register_tcp(void);
 extern void register_udp(void);
 extern void register_icmp(void);
 extern void register_icmpv6(void);
+extern void register_unknown(void);
 
 #endif
src/Makefile.am +1 -1
index 805e50d..82f7dfe 100644
@@ -7,7 +7,7 @@ CLEANFILES = read_config_yy.c read_config_lex.c
 sbin_PROGRAMS = conntrack conntrackd
 
 conntrack_SOURCES = conntrack.c
-conntrack_LDADD = ../extensions/libct_proto_tcp.la ../extensions/libct_proto_udp.la ../extensions/libct_proto_icmp.la ../extensions/libct_proto_icmpv6.la
+conntrack_LDADD = ../extensions/libct_proto_tcp.la ../extensions/libct_proto_udp.la ../extensions/libct_proto_icmp.la ../extensions/libct_proto_icmpv6.la ../extensions/libct_proto_unknown.la
 conntrack_LDFLAGS = $(all_libraries) @LIBNETFILTER_CONNTRACK_LIBS@
 
 conntrackd_SOURCES = alarm.c main.c run.c hash.c queue.c rbtree.c \
src/conntrack.c +14 -0
index 73c102b..38d4f6d 100644
@@ -158,6 +158,7 @@ void register_proto(struct ctproto_handler *h)
 
 static struct ctproto_handler *findproto(char *name)
 {
+	uint16_t protonum;
 	struct ctproto_handler *cur;
 
 	if (!name) 
@@ -168,6 +169,18 @@ static struct ctproto_handler *findproto(char *name)
 			return cur;
 	}
 
+	protonum = atol(name);
+
+	if (protonum > 0 && protonum <= IPPROTO_MAX) {
+	//get and use "unknown" proto
+		list_for_each_entry(cur, &proto_list, head) {
+			if (strcmp(cur->name, "unknown") == 0) {
+				cur->protonum = protonum;
+				return cur;
+			}
+		}
+	}
+
 	return NULL;
 }
 
@@ -921,6 +934,7 @@ int main(int argc, char *argv[])
 	register_udp();
 	register_icmp();
 	register_icmpv6();
+	register_unknown();
 
 	/* disable explicit missing arguments error output from getopt_long */
 	opterr = 0;
#1 lore raw

Hi Bryan,

Quoted 2 lines · Bryan Duff

Now instead of "conntrack -L -p tcp" you can do "conntrack -L -p 6" - useful for "unknown" proto's like gre, ah, esp.

Thanks for the patch. I have rework it a bit, the new patch is attached. I'll push it to git if nobody complains.

BTW: udplite, dccp and sctp support are missing, in case that you want to contribute something else. You'll also have to add the missing bits into libnetfilter_conntrack.

Signature · 1 line
"Los honestos son inadaptados sociales" -- Les Luthiers

commit e44561766b025600e4af55a35166db46206dd42c

Author: Pablo Neira Ayuso <[email protected]>
Date:   Sat Oct 4 11:32:37 2008 +0200

conntrack: fix filtering for unsupported protocol

This patch fixes filtering for unsupported protocol. Thus, you can use -L -p 47 or -L -p gre to filter `gre' traffic.

Based on an initial patch from Bryan Duff <[email protected]>.

extensions/Makefile.am +3 -1
index 0eede22..7b48f05 100644
@@ -1,9 +1,11 @@
 include $(top_srcdir)/Make_global.am
 
 noinst_LTLIBRARIES = libct_proto_tcp.la libct_proto_udp.la \
-		     libct_proto_icmp.la libct_proto_icmpv6.la
+		     libct_proto_icmp.la libct_proto_icmpv6.la \
+		     libct_proto_unknown.la
 
 libct_proto_tcp_la_SOURCES = libct_proto_tcp.c
 libct_proto_udp_la_SOURCES = libct_proto_udp.c
 libct_proto_icmp_la_SOURCES = libct_proto_icmp.c
 libct_proto_icmpv6_la_SOURCES = libct_proto_icmpv6.c
+libct_proto_unknown_la_SOURCES = libct_proto_unknown.c
extensions/libct_proto_unknown.c new file +34 -0
new file mode 100644
index 0000000..2a47704
@@ -0,0 +1,34 @@
+/*
+ * (C) 2005-2008 by Pablo Neira Ayuso <[email protected]>
+ *
+ *      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.
+ *
+ */
+#include <stdio.h>
+#include <getopt.h>
+
+#include "conntrack.h"
+
+static struct option opts[] = {
+        {0, 0, 0, 0}
+};
+
+static void help(void)
+{
+	fprintf(stdout, "  no options (unsupported)\n");
+}
+
+struct ctproto_handler ct_proto_unknown = {
+	.name 		= "unknown",
+	.help		= help,
+	.opts		= opts,
+	.version	= VERSION,
+};
+
+void register_unknown(void)
+{
+	/* we don't actually insert this protocol in the list */
+}
include/conntrack.h +1 -0
index 69c2317..4787809 100644
@@ -191,5 +191,6 @@ extern void register_tcp(void);
 extern void register_udp(void);
 extern void register_icmp(void);
 extern void register_icmpv6(void);
+extern void register_unknown(void);
 
 #endif
src/Makefile.am +1 -1
index 805e50d..82f7dfe 100644
@@ -7,7 +7,7 @@ CLEANFILES = read_config_yy.c read_config_lex.c
 sbin_PROGRAMS = conntrack conntrackd
 
 conntrack_SOURCES = conntrack.c
-conntrack_LDADD = ../extensions/libct_proto_tcp.la ../extensions/libct_proto_udp.la ../extensions/libct_proto_icmp.la ../extensions/libct_proto_icmpv6.la
+conntrack_LDADD = ../extensions/libct_proto_tcp.la ../extensions/libct_proto_udp.la ../extensions/libct_proto_icmp.la ../extensions/libct_proto_icmpv6.la ../extensions/libct_proto_unknown.la
 conntrack_LDFLAGS = $(all_libraries) @LIBNETFILTER_CONNTRACK_LIBS@
 
 conntrackd_SOURCES = alarm.c main.c run.c hash.c queue.c rbtree.c \
src/conntrack.c +50 -16

126 lines not on this page · raw message

author
#2 lore raw

Yeah, I can add support for the other protocols.

-Bryan

Quoted 16 lines · Pablo Neira Ayuso

Hi Bryan,

Quoted 3 lines · Bryan Duff

Now instead of "conntrack -L -p tcp" you can do "conntrack -L -p 6" - useful for "unknown" proto's like gre, ah, esp.

Thanks for the patch. I have rework it a bit, the new patch is attached. I'll push it to git if nobody complains.

BTW: udplite, dccp and sctp support are missing, in case that you want to contribute something else. You'll also have to add the missing bits into libnetfilter_conntrack.