From 21ed4ac1f957f1e4d7be195a98fb235de13ede21 Mon Sep 17 00:00:00 2001 From: "/C=DE/ST=Berlin/L=Berlin/O=Netfilter Project/OU=Development/CN=pablo/emailAddress=pablo@netfilter.org" Date: Mon, 25 Apr 2005 10:01:10 +0000 Subject: Major resync --- extensions/libct_proto_tcp.c | 64 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 59 insertions(+), 5 deletions(-) (limited to 'extensions/libct_proto_tcp.c') diff --git a/extensions/libct_proto_tcp.c b/extensions/libct_proto_tcp.c index 521a170..3366da4 100644 --- a/extensions/libct_proto_tcp.c +++ b/extensions/libct_proto_tcp.c @@ -11,29 +11,83 @@ static struct option opts[] = { {"orig-port-dst", 1, 0, '2'}, {"reply-port-src", 1, 0, '3'}, {"reply-port-dst", 1, 0, '4'}, + {"state", 1, 0, '5'}, {0, 0, 0, 0} }; +enum tcp_param_flags { + ORIG_SPORT_BIT = 0, + ORIG_SPORT = (1 << ORIG_SPORT_BIT), + + ORIG_DPORT_BIT = 1, + ORIG_DPORT = (1 << ORIG_DPORT_BIT), + + REPL_SPORT_BIT = 2, + REPL_SPORT = (1 << REPL_SPORT_BIT), + + REPL_DPORT_BIT = 3, + REPL_DPORT = (1 << REPL_DPORT_BIT), + + STATE_BIT = 4, + STATE = (1 << STATE_BIT) +}; + +static const char *states[] = { + "NONE", + "SYN_SENT", + "SYN_RECV", + "ESTABLISHED", + "FIN_WAIT", + "CLOSE_WAIT", + "LAST_ACK", + "TIME_WAIT", + "CLOSE", + "LISTEN" +}; + int parse(char c, char *argv[], struct ip_conntrack_tuple *orig, - struct ip_conntrack_tuple *reply) + struct ip_conntrack_tuple *reply, + union ip_conntrack_proto *proto, + unsigned int *flags) { switch(c) { case '1': - if (optarg) + if (optarg) { orig->src.u.tcp.port = htons(atoi(optarg)); + *flags |= ORIG_SPORT; + } break; case '2': - if (optarg) + if (optarg) { orig->dst.u.tcp.port = htons(atoi(optarg)); + *flags |= ORIG_DPORT; + } break; case '3': - if (optarg) + if (optarg) { reply->src.u.tcp.port = htons(atoi(optarg)); + *flags |= REPL_SPORT; + } break; case '4': - if (optarg) + if (optarg) { reply->dst.u.tcp.port = htons(atoi(optarg)); + *flags |= REPL_DPORT; + } + break; + case '5': + if (optarg) { + int i; + for (i=0; i<10; i++) { + if (strcmp(optarg, states[i]) == 0) { + proto->tcp.state = i; + break; + } + } + if (i == 10) + printf("doh?\n"); + } break; } return 1; -- cgit v1.2.3