2
* (C) 2005 by Harald Welte <laforge@netfilter.org>
3
* 2006 by Pablo Neira Ayuso <pablo@netfilter.org>
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
15
#include <netinet/in.h> /* For htons */
16
#include "conntrack.h"
17
#include <libnetfilter_conntrack/libnetfilter_conntrack.h>
18
#include <libnetfilter_conntrack/libnetfilter_conntrack_sctp.h>
20
static struct option opts[] = {
21
{"orig-port-src", 1, 0, '1'},
22
{"orig-port-dst", 1, 0, '2'},
23
{"reply-port-src", 1, 0, '3'},
24
{"reply-port-dst", 1, 0, '4'},
26
{"tuple-port-src", 1, 0, '6'},
27
{"tuple-port-dst", 1, 0, '7'},
31
static const char *states[] = {
44
fprintf(stdout, "--orig-port-src original source port\n");
45
fprintf(stdout, "--orig-port-dst original destination port\n");
46
fprintf(stdout, "--reply-port-src reply source port\n");
47
fprintf(stdout, "--reply-port-dst reply destination port\n");
48
fprintf(stdout, "--state SCTP state, fe. ESTABLISHED\n");
49
fprintf(stdout, "--tuple-port-src expectation tuple src port\n");
50
fprintf(stdout, "--tuple-port-src expectation tuple dst port\n");
53
static int parse_options(char c, char *argv[],
54
struct nfct_tuple *orig,
55
struct nfct_tuple *reply,
56
struct nfct_tuple *exptuple,
57
struct nfct_tuple *mask,
58
union nfct_protoinfo *proto,
64
orig->l4src.sctp.port = htons(atoi(optarg));
65
*flags |= SCTP_ORIG_SPORT;
70
orig->l4dst.sctp.port = htons(atoi(optarg));
71
*flags |= SCTP_ORIG_DPORT;
76
reply->l4src.sctp.port = htons(atoi(optarg));
77
*flags |= SCTP_REPL_SPORT;
82
reply->l4dst.sctp.port = htons(atoi(optarg));
83
*flags |= SCTP_REPL_DPORT;
89
for (i=0; i<10; i++) {
90
if (strcmp(optarg, states[i]) == 0) {
91
/* FIXME: Add state to
93
proto->sctp.state = i; */
101
*flags |= SCTP_STATE;
106
exptuple->l4src.sctp.port = htons(atoi(optarg));
107
*flags |= SCTP_EXPTUPLE_SPORT;
112
exptuple->l4dst.sctp.port = htons(atoi(optarg));
113
*flags |= SCTP_EXPTUPLE_DPORT;
120
static int final_check(unsigned int flags,
121
unsigned int command,
122
struct nfct_tuple *orig,
123
struct nfct_tuple *reply)
127
if ((flags & (SCTP_ORIG_SPORT|SCTP_ORIG_DPORT))
128
&& !(flags & (SCTP_REPL_SPORT|SCTP_REPL_DPORT))) {
129
reply->l4src.sctp.port = orig->l4dst.sctp.port;
130
reply->l4dst.sctp.port = orig->l4src.sctp.port;
132
} else if (!(flags & (SCTP_ORIG_SPORT|SCTP_ORIG_DPORT))
133
&& (flags & (SCTP_REPL_SPORT|SCTP_REPL_DPORT))) {
134
orig->l4src.sctp.port = reply->l4dst.sctp.port;
135
orig->l4dst.sctp.port = reply->l4src.sctp.port;
138
if ((flags & (SCTP_ORIG_SPORT|SCTP_ORIG_DPORT))
139
&& ((flags & (SCTP_REPL_SPORT|SCTP_REPL_DPORT))))
142
/* --state is missing and we are trying to create a conntrack */
143
if (ret && (command & CT_CREATE) && (!(flags & SCTP_STATE)))
149
static struct ctproto_handler sctp = {
151
.protonum = IPPROTO_SCTP,
152
.parse_opts = parse_options,
153
.final_check = final_check,
159
static void __attribute__ ((constructor)) init(void);
161
static void init(void)
163
register_proto(&sctp);