* conntrack-tools unknown protocol search by number
@ 2008-10-03 21:56 Bryan Duff
2008-10-04 9:37 ` Pablo Neira Ayuso
0 siblings, 1 reply; 3+ messages in thread
From: Bryan Duff @ 2008-10-03 21:56 UTC (permalink / raw)
To: netfilter-devel
[-- Attachment #1: Type: text/plain, Size: 141 bytes --]
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
[-- Attachment #2: conntrack-tools-unknown_proto.patch --]
[-- Type: text/plain, Size: 4307 bytes --]
diff --git a/extensions/Makefile.am b/extensions/Makefile.am
index 0eede22..8165e05 100644
--- a/extensions/Makefile.am
+++ b/extensions/Makefile.am
@@ -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
diff --git a/extensions/libct_proto_unknown.c b/extensions/libct_proto_unknown.c
new file mode 100644
index 0000000..cbb5b2b
--- /dev/null
+++ b/extensions/libct_proto_unknown.c
@@ -0,0 +1,65 @@
+/*
+ * (C) 2005-2007 by Pablo Neira Ayuso <pablo@netfilter.org>
+ * 2005 by Harald Welte <laforge@netfilter.org>
+ *
+ * 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 "conntrack.h"
+
+#include <stdio.h>
+#include <getopt.h>
+#include <stdlib.h>
+#include <netinet/in.h> /* For htons */
+#include <libnetfilter_conntrack/libnetfilter_conntrack.h>
+
+static struct option opts[] = {
+ {0, 0, 0, 0}
+};
+
+#define UNKNOWN_NUMBER_OF_OPT 1
+
+static void help(void)
+{
+ fprintf(stdout, " no options\n");
+}
+
+static int parse(char c,
+ struct nf_conntrack *ct,
+ struct nf_conntrack *exptuple,
+ struct nf_conntrack *mask,
+ unsigned int *flags)
+{
+ return 1;
+}
+
+static void final_check(unsigned int flags,
+ unsigned int cmd,
+ struct nf_conntrack *ct)
+{
+#if 0
+ generic_opt_check(flags,
+ UNKNOWN_NUMBER_OF_OPT,
+ unknown_commands_v_options[cmd],
+ unknown_optflags);
+#endif
+}
+
+static struct ctproto_handler unknown = {
+ .name = "unknown",
+ .protonum = IPPROTO_ICMP, //default
+ .parse_opts = parse,
+ .final_check = final_check,
+ .help = help,
+ .opts = opts,
+ .version = VERSION,
+};
+
+void register_unknown(void)
+{
+ register_proto(&unknown);
+}
diff --git a/include/conntrack.h b/include/conntrack.h
index 69c2317..4787809 100644
--- a/include/conntrack.h
+++ b/include/conntrack.h
@@ -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
diff --git a/src/Makefile.am b/src/Makefile.am
index 805e50d..82f7dfe 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -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 \
diff --git a/src/conntrack.c b/src/conntrack.c
index 73c102b..38d4f6d 100644
--- a/src/conntrack.c
+++ b/src/conntrack.c
@@ -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;
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: conntrack-tools unknown protocol search by number
2008-10-03 21:56 conntrack-tools unknown protocol search by number Bryan Duff
@ 2008-10-04 9:37 ` Pablo Neira Ayuso
2008-10-06 20:46 ` Bryan Duff
0 siblings, 1 reply; 3+ messages in thread
From: Pablo Neira Ayuso @ 2008-10-04 9:37 UTC (permalink / raw)
To: Bryan Duff; +Cc: netfilter-devel
[-- Attachment #1: Type: text/plain, Size: 499 bytes --]
Hi Bryan,
Bryan Duff wrote:
> 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.
--
"Los honestos son inadaptados sociales" -- Les Luthiers
[-- Attachment #2: y.patch --]
[-- Type: text/x-diff, Size: 6869 bytes --]
commit e44561766b025600e4af55a35166db46206dd42c
Author: Pablo Neira Ayuso <pablo@netfilter.org>
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 <bduff@astrocorp.com>.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
diff --git a/extensions/Makefile.am b/extensions/Makefile.am
index 0eede22..7b48f05 100644
--- a/extensions/Makefile.am
+++ b/extensions/Makefile.am
@@ -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
diff --git a/extensions/libct_proto_unknown.c b/extensions/libct_proto_unknown.c
new file mode 100644
index 0000000..2a47704
--- /dev/null
+++ b/extensions/libct_proto_unknown.c
@@ -0,0 +1,34 @@
+/*
+ * (C) 2005-2008 by Pablo Neira Ayuso <pablo@netfilter.org>
+ *
+ * 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 */
+}
diff --git a/include/conntrack.h b/include/conntrack.h
index 69c2317..4787809 100644
--- a/include/conntrack.h
+++ b/include/conntrack.h
@@ -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
diff --git a/src/Makefile.am b/src/Makefile.am
index 805e50d..82f7dfe 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -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 \
diff --git a/src/conntrack.c b/src/conntrack.c
index 73c102b..eccaa7b 100644
--- a/src/conntrack.c
+++ b/src/conntrack.c
@@ -53,6 +53,7 @@
#endif
#include <signal.h>
#include <string.h>
+#include <netdb.h>
#include <libnetfilter_conntrack/libnetfilter_conntrack.h>
static const char cmdflags[NUMBER_OF_CMD]
@@ -156,26 +157,61 @@ void register_proto(struct ctproto_handler *h)
list_add(&h->head, &proto_list);
}
-static struct ctproto_handler *findproto(char *name)
+extern struct ctproto_handler ct_proto_unknown;
+
+static struct ctproto_handler *findproto(char *name, int *pnum)
{
struct ctproto_handler *cur;
+ struct protoent *pent;
+ int protonum;
- if (!name)
- return NULL;
-
+ /* is it in the list of supported protocol? */
list_for_each_entry(cur, &proto_list, head) {
- if (strcmp(cur->name, name) == 0)
+ if (strcmp(cur->name, name) == 0) {
+ *pnum = cur->protonum;
return cur;
+ }
+ }
+ /* using the protocol name for an unsupported protocol? */
+ if ((pent = getprotobyname(name))) {
+ *pnum = pent->p_proto;
+ return &ct_proto_unknown;
+ }
+ /* using a protocol number? */
+ protonum = atoi(name);
+ if (protonum > 0 && protonum <= IPPROTO_MAX) {
+ /* try lookup by number, perhaps this protocol is supported */
+ list_for_each_entry(cur, &proto_list, head) {
+ if (cur->protonum == protonum) {
+ *pnum = protonum;
+ return cur;
+ }
+ }
+ *pnum = protonum;
+ return &ct_proto_unknown;
}
return NULL;
}
static void
-extension_help(struct ctproto_handler *h)
+extension_help(struct ctproto_handler *h, int protonum)
{
- fprintf(stdout, "\n");
- fprintf(stdout, "Proto `%s' help:\n", h->name);
+ const char *name;
+
+ if (h == &ct_proto_unknown) {
+ struct protoent *pent;
+
+ pent = getprotobynumber(protonum);
+ if (!pent)
+ name = h->name;
+ else
+ name = pent->p_name;
+ } else {
+ name = h->name;
+ }
+
+ fprintf(stdout, "Proto `%s' help:\n", name);
h->help();
}
@@ -908,7 +944,7 @@ int main(int argc, char *argv[])
struct nf_conntrack *mask = (struct nf_conntrack *)(void*) __mask;
char __exp[nfexp_maxsize()];
struct nf_expect *exp = (struct nf_expect *)(void*) __exp;
- int l3protonum;
+ int l3protonum, protonum = 0;
union ct_address ad;
unsigned int command = 0;
@@ -921,6 +957,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;
@@ -990,7 +1027,7 @@ int main(int argc, char *argv[])
break;
case 'p':
options |= CT_OPT_PROTO;
- h = findproto(optarg);
+ h = findproto(optarg, &protonum);
if (!h)
exit_error(PARAMETER_PROBLEM,
"`%s' unsupported protocol",
@@ -999,6 +1036,8 @@ int main(int argc, char *argv[])
opts = merge_options(opts, h->opts, &h->option_offset);
if (opts == NULL)
exit_error(OTHER_PROBLEM, "out of memory");
+
+ nfct_set_attr_u8(obj, ATTR_L4PROTO, protonum);
break;
case 't':
options |= CT_OPT_TIMEOUT;
@@ -1090,11 +1129,6 @@ int main(int argc, char *argv[])
if (family == AF_UNSPEC)
family = AF_INET;
- /* set the protocol number if we have seen -p with no parameters */
- if (h && !nfct_attr_is_set(obj, ATTR_ORIG_L4PROTO) &&
- !nfct_attr_is_set(obj, ATTR_REPL_L4PROTO))
- nfct_set_attr_u8(obj, ATTR_L4PROTO, h->protonum);
-
cmd = bit2cmd(command);
generic_cmd_check(cmd, options);
generic_opt_check(options,
@@ -1304,7 +1338,7 @@ int main(int argc, char *argv[])
case CT_HELP:
usage(argv[0]);
if (options & CT_OPT_PROTO)
- extension_help(h);
+ extension_help(h, protonum);
break;
default:
usage(argv[0]);
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: conntrack-tools unknown protocol search by number
2008-10-04 9:37 ` Pablo Neira Ayuso
@ 2008-10-06 20:46 ` Bryan Duff
0 siblings, 0 replies; 3+ messages in thread
From: Bryan Duff @ 2008-10-06 20:46 UTC (permalink / raw)
To: Pablo Neira Ayuso; +Cc: netfilter-devel
Yeah, I can add support for the other protocols.
-Bryan
Pablo Neira Ayuso wrote:
> Hi Bryan,
>
> Bryan Duff wrote:
>
>> 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.
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-10-06 20:43 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-10-03 21:56 conntrack-tools unknown protocol search by number Bryan Duff
2008-10-04 9:37 ` Pablo Neira Ayuso
2008-10-06 20:46 ` Bryan Duff
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.