blob: c6049c2d5ea8d9be54aa6f1d77accafa3b2eb920 [file] [log] [blame]
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -08001/*
2 * Connection tracking protocol helper module for SCTP.
YOSHIFUJI Hideaki601e68e2007-02-12 11:15:49 -08003 *
4 * SCTP is defined in RFC 2960. References to various sections in this code
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -08005 * are to this RFC.
YOSHIFUJI Hideaki601e68e2007-02-12 11:15:49 -08006 *
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -08007 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080010 */
11
12#include <linux/types.h>
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080013#include <linux/timer.h>
14#include <linux/netfilter.h>
15#include <linux/module.h>
16#include <linux/in.h>
17#include <linux/ip.h>
18#include <linux/sctp.h>
19#include <linux/string.h>
20#include <linux/seq_file.h>
Yasuyuki Kozakai40a839f2006-06-27 03:00:35 -070021#include <linux/spinlock.h>
22#include <linux/interrupt.h>
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080023
24#include <net/netfilter/nf_conntrack.h>
Martin Josefsson605dcad2006-11-29 02:35:06 +010025#include <net/netfilter/nf_conntrack_l4proto.h>
Martin Josefssonf6180122006-11-29 02:35:01 +010026#include <net/netfilter/nf_conntrack_ecache.h>
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080027
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080028/* FIXME: Examine ipfilter's timeouts and conntrack transitions more
YOSHIFUJI Hideaki601e68e2007-02-12 11:15:49 -080029 closely. They're more complex. --RR
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080030
31 And so for me for SCTP :D -Kiran */
32
Jan Engelhardt12c33aa2008-04-14 11:15:54 +020033static const char *const sctp_conntrack_names[] = {
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080034 "NONE",
35 "CLOSED",
36 "COOKIE_WAIT",
37 "COOKIE_ECHOED",
38 "ESTABLISHED",
39 "SHUTDOWN_SENT",
40 "SHUTDOWN_RECD",
41 "SHUTDOWN_ACK_SENT",
42};
43
44#define SECS * HZ
45#define MINS * 60 SECS
46#define HOURS * 60 MINS
47#define DAYS * 24 HOURS
48
Patrick McHardy86c0bf42008-01-14 23:48:17 -080049static unsigned int sctp_timeouts[SCTP_CONNTRACK_MAX] __read_mostly = {
50 [SCTP_CONNTRACK_CLOSED] = 10 SECS,
51 [SCTP_CONNTRACK_COOKIE_WAIT] = 3 SECS,
52 [SCTP_CONNTRACK_COOKIE_ECHOED] = 3 SECS,
53 [SCTP_CONNTRACK_ESTABLISHED] = 5 DAYS,
54 [SCTP_CONNTRACK_SHUTDOWN_SENT] = 300 SECS / 1000,
55 [SCTP_CONNTRACK_SHUTDOWN_RECD] = 300 SECS / 1000,
56 [SCTP_CONNTRACK_SHUTDOWN_ACK_SENT] = 3 SECS,
57};
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080058
59#define sNO SCTP_CONNTRACK_NONE
60#define sCL SCTP_CONNTRACK_CLOSED
61#define sCW SCTP_CONNTRACK_COOKIE_WAIT
62#define sCE SCTP_CONNTRACK_COOKIE_ECHOED
63#define sES SCTP_CONNTRACK_ESTABLISHED
64#define sSS SCTP_CONNTRACK_SHUTDOWN_SENT
65#define sSR SCTP_CONNTRACK_SHUTDOWN_RECD
66#define sSA SCTP_CONNTRACK_SHUTDOWN_ACK_SENT
67#define sIV SCTP_CONNTRACK_MAX
68
YOSHIFUJI Hideaki601e68e2007-02-12 11:15:49 -080069/*
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080070 These are the descriptions of the states:
71
YOSHIFUJI Hideaki601e68e2007-02-12 11:15:49 -080072NOTE: These state names are tantalizingly similar to the states of an
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080073SCTP endpoint. But the interpretation of the states is a little different,
YOSHIFUJI Hideaki601e68e2007-02-12 11:15:49 -080074considering that these are the states of the connection and not of an end
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080075point. Please note the subtleties. -Kiran
76
77NONE - Nothing so far.
YOSHIFUJI Hideaki601e68e2007-02-12 11:15:49 -080078COOKIE WAIT - We have seen an INIT chunk in the original direction, or also
79 an INIT_ACK chunk in the reply direction.
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080080COOKIE ECHOED - We have seen a COOKIE_ECHO chunk in the original direction.
81ESTABLISHED - We have seen a COOKIE_ACK in the reply direction.
82SHUTDOWN_SENT - We have seen a SHUTDOWN chunk in the original direction.
83SHUTDOWN_RECD - We have seen a SHUTDOWN chunk in the reply directoin.
84SHUTDOWN_ACK_SENT - We have seen a SHUTDOWN_ACK chunk in the direction opposite
YOSHIFUJI Hideaki601e68e2007-02-12 11:15:49 -080085 to that of the SHUTDOWN chunk.
86CLOSED - We have seen a SHUTDOWN_COMPLETE chunk in the direction of
87 the SHUTDOWN chunk. Connection is closed.
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080088*/
89
90/* TODO
YOSHIFUJI Hideaki601e68e2007-02-12 11:15:49 -080091 - I have assumed that the first INIT is in the original direction.
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080092 This messes things when an INIT comes in the reply direction in CLOSED
93 state.
YOSHIFUJI Hideaki601e68e2007-02-12 11:15:49 -080094 - Check the error type in the reply dir before transitioning from
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080095cookie echoed to closed.
96 - Sec 5.2.4 of RFC 2960
97 - Multi Homing support.
98*/
99
100/* SCTP conntrack state transitions */
Patrick McHardya5e73c22008-01-14 23:45:11 -0800101static const u8 sctp_conntracks[2][9][SCTP_CONNTRACK_MAX] = {
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800102 {
103/* ORIGINAL */
104/* sNO, sCL, sCW, sCE, sES, sSS, sSR, sSA */
105/* init */ {sCW, sCW, sCW, sCE, sES, sSS, sSR, sSA},
106/* init_ack */ {sCL, sCL, sCW, sCE, sES, sSS, sSR, sSA},
107/* abort */ {sCL, sCL, sCL, sCL, sCL, sCL, sCL, sCL},
108/* shutdown */ {sCL, sCL, sCW, sCE, sSS, sSS, sSR, sSA},
109/* shutdown_ack */ {sSA, sCL, sCW, sCE, sES, sSA, sSA, sSA},
110/* error */ {sCL, sCL, sCW, sCE, sES, sSS, sSR, sSA},/* Cant have Stale cookie*/
111/* cookie_echo */ {sCL, sCL, sCE, sCE, sES, sSS, sSR, sSA},/* 5.2.4 - Big TODO */
112/* cookie_ack */ {sCL, sCL, sCW, sCE, sES, sSS, sSR, sSA},/* Cant come in orig dir */
113/* shutdown_comp*/ {sCL, sCL, sCW, sCE, sES, sSS, sSR, sCL}
114 },
115 {
116/* REPLY */
117/* sNO, sCL, sCW, sCE, sES, sSS, sSR, sSA */
118/* init */ {sIV, sCL, sCW, sCE, sES, sSS, sSR, sSA},/* INIT in sCL Big TODO */
119/* init_ack */ {sIV, sCL, sCW, sCE, sES, sSS, sSR, sSA},
120/* abort */ {sIV, sCL, sCL, sCL, sCL, sCL, sCL, sCL},
121/* shutdown */ {sIV, sCL, sCW, sCE, sSR, sSS, sSR, sSA},
122/* shutdown_ack */ {sIV, sCL, sCW, sCE, sES, sSA, sSA, sSA},
123/* error */ {sIV, sCL, sCW, sCL, sES, sSS, sSR, sSA},
124/* cookie_echo */ {sIV, sCL, sCW, sCE, sES, sSS, sSR, sSA},/* Cant come in reply dir */
125/* cookie_ack */ {sIV, sCL, sCW, sES, sES, sSS, sSR, sSA},
126/* shutdown_comp*/ {sIV, sCL, sCW, sCE, sES, sSS, sSR, sCL}
127 }
128};
129
Jan Engelhardt09f263c2008-04-14 11:15:53 +0200130static bool sctp_pkt_to_tuple(const struct sk_buff *skb, unsigned int dataoff,
131 struct nf_conntrack_tuple *tuple)
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800132{
Jan Engelhardt12c33aa2008-04-14 11:15:54 +0200133 const struct sctphdr *hp;
134 struct sctphdr _hdr;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800135
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800136 /* Actually only need first 8 bytes. */
137 hp = skb_header_pointer(skb, dataoff, 8, &_hdr);
138 if (hp == NULL)
Jan Engelhardt09f263c2008-04-14 11:15:53 +0200139 return false;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800140
141 tuple->src.u.sctp.port = hp->source;
142 tuple->dst.u.sctp.port = hp->dest;
Jan Engelhardt09f263c2008-04-14 11:15:53 +0200143 return true;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800144}
145
Jan Engelhardt09f263c2008-04-14 11:15:53 +0200146static bool sctp_invert_tuple(struct nf_conntrack_tuple *tuple,
147 const struct nf_conntrack_tuple *orig)
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800148{
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800149 tuple->src.u.sctp.port = orig->dst.u.sctp.port;
150 tuple->dst.u.sctp.port = orig->src.u.sctp.port;
Jan Engelhardt09f263c2008-04-14 11:15:53 +0200151 return true;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800152}
153
154/* Print out the per-protocol part of the tuple. */
155static int sctp_print_tuple(struct seq_file *s,
156 const struct nf_conntrack_tuple *tuple)
157{
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800158 return seq_printf(s, "sport=%hu dport=%hu ",
159 ntohs(tuple->src.u.sctp.port),
160 ntohs(tuple->dst.u.sctp.port));
161}
162
163/* Print out the private part of the conntrack. */
Patrick McHardy440f0d52009-06-10 14:32:47 +0200164static int sctp_print_conntrack(struct seq_file *s, struct nf_conn *ct)
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800165{
166 enum sctp_conntrack state;
167
Patrick McHardy440f0d52009-06-10 14:32:47 +0200168 spin_lock_bh(&ct->lock);
Patrick McHardy112f35c2008-01-14 23:46:20 -0800169 state = ct->proto.sctp.state;
Patrick McHardy440f0d52009-06-10 14:32:47 +0200170 spin_unlock_bh(&ct->lock);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800171
172 return seq_printf(s, "%s ", sctp_conntrack_names[state]);
173}
174
175#define for_each_sctp_chunk(skb, sch, _sch, offset, dataoff, count) \
Jan Engelhardte79ec502007-12-17 22:44:06 -0800176for ((offset) = (dataoff) + sizeof(sctp_sctphdr_t), (count) = 0; \
177 (offset) < (skb)->len && \
178 ((sch) = skb_header_pointer((skb), (offset), sizeof(_sch), &(_sch))); \
179 (offset) += (ntohs((sch)->length) + 3) & ~3, (count)++)
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800180
181/* Some validity checks to make sure the chunks are fine */
Patrick McHardy112f35c2008-01-14 23:46:20 -0800182static int do_basic_checks(struct nf_conn *ct,
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800183 const struct sk_buff *skb,
184 unsigned int dataoff,
Patrick McHardy35c6d3c2008-01-14 23:46:05 -0800185 unsigned long *map)
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800186{
187 u_int32_t offset, count;
188 sctp_chunkhdr_t _sch, *sch;
189 int flag;
190
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800191 flag = 0;
192
193 for_each_sctp_chunk (skb, sch, _sch, offset, dataoff, count) {
Patrick McHardy0d537782007-07-07 22:39:38 -0700194 pr_debug("Chunk Num: %d Type: %d\n", count, sch->type);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800195
Patrick McHardy5447d472008-01-14 23:45:48 -0800196 if (sch->type == SCTP_CID_INIT ||
197 sch->type == SCTP_CID_INIT_ACK ||
198 sch->type == SCTP_CID_SHUTDOWN_COMPLETE)
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800199 flag = 1;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800200
Patrick McHardye17df682006-05-02 23:23:07 +0200201 /*
202 * Cookie Ack/Echo chunks not the first OR
203 * Init / Init Ack / Shutdown compl chunks not the only chunks
204 * OR zero-length.
205 */
Patrick McHardy5447d472008-01-14 23:45:48 -0800206 if (((sch->type == SCTP_CID_COOKIE_ACK ||
207 sch->type == SCTP_CID_COOKIE_ECHO ||
208 flag) &&
209 count != 0) || !sch->length) {
Patrick McHardy0d537782007-07-07 22:39:38 -0700210 pr_debug("Basic checks failed\n");
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800211 return 1;
212 }
213
Patrick McHardy5447d472008-01-14 23:45:48 -0800214 if (map)
Patrick McHardy35c6d3c2008-01-14 23:46:05 -0800215 set_bit(sch->type, map);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800216 }
217
Patrick McHardy0d537782007-07-07 22:39:38 -0700218 pr_debug("Basic checks passed\n");
Patrick McHardydd7271f2006-06-29 21:40:23 -0700219 return count == 0;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800220}
221
Patrick McHardyefe9f682008-01-14 23:47:09 -0800222static int sctp_new_state(enum ip_conntrack_dir dir,
223 enum sctp_conntrack cur_state,
224 int chunk_type)
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800225{
226 int i;
227
Patrick McHardy0d537782007-07-07 22:39:38 -0700228 pr_debug("Chunk type: %d\n", chunk_type);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800229
230 switch (chunk_type) {
Patrick McHardy5447d472008-01-14 23:45:48 -0800231 case SCTP_CID_INIT:
232 pr_debug("SCTP_CID_INIT\n");
233 i = 0;
234 break;
235 case SCTP_CID_INIT_ACK:
236 pr_debug("SCTP_CID_INIT_ACK\n");
237 i = 1;
238 break;
239 case SCTP_CID_ABORT:
240 pr_debug("SCTP_CID_ABORT\n");
241 i = 2;
242 break;
243 case SCTP_CID_SHUTDOWN:
244 pr_debug("SCTP_CID_SHUTDOWN\n");
245 i = 3;
246 break;
247 case SCTP_CID_SHUTDOWN_ACK:
248 pr_debug("SCTP_CID_SHUTDOWN_ACK\n");
249 i = 4;
250 break;
251 case SCTP_CID_ERROR:
252 pr_debug("SCTP_CID_ERROR\n");
253 i = 5;
254 break;
255 case SCTP_CID_COOKIE_ECHO:
256 pr_debug("SCTP_CID_COOKIE_ECHO\n");
257 i = 6;
258 break;
259 case SCTP_CID_COOKIE_ACK:
260 pr_debug("SCTP_CID_COOKIE_ACK\n");
261 i = 7;
262 break;
263 case SCTP_CID_SHUTDOWN_COMPLETE:
264 pr_debug("SCTP_CID_SHUTDOWN_COMPLETE\n");
265 i = 8;
266 break;
267 default:
268 /* Other chunks like DATA, SACK, HEARTBEAT and
269 its ACK do not cause a change in state */
270 pr_debug("Unknown chunk type, Will stay in %s\n",
271 sctp_conntrack_names[cur_state]);
272 return cur_state;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800273 }
274
Patrick McHardy0d537782007-07-07 22:39:38 -0700275 pr_debug("dir: %d cur_state: %s chunk_type: %d new_state: %s\n",
276 dir, sctp_conntrack_names[cur_state], chunk_type,
277 sctp_conntrack_names[sctp_conntracks[dir][i][cur_state]]);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800278
279 return sctp_conntracks[dir][i][cur_state];
280}
281
Patrick McHardyb37e9332008-01-14 23:46:52 -0800282/* Returns verdict for packet, or -NF_ACCEPT for invalid. */
Patrick McHardy112f35c2008-01-14 23:46:20 -0800283static int sctp_packet(struct nf_conn *ct,
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800284 const struct sk_buff *skb,
285 unsigned int dataoff,
286 enum ip_conntrack_info ctinfo,
Jan Engelhardt76108ce2008-10-08 11:35:00 +0200287 u_int8_t pf,
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800288 unsigned int hooknum)
289{
Patrick McHardyefe9f682008-01-14 23:47:09 -0800290 enum sctp_conntrack new_state, old_state;
Patrick McHardy85288192008-01-14 23:46:37 -0800291 enum ip_conntrack_dir dir = CTINFO2DIR(ctinfo);
Jan Engelhardt12c33aa2008-04-14 11:15:54 +0200292 const struct sctphdr *sh;
293 struct sctphdr _sctph;
294 const struct sctp_chunkhdr *sch;
295 struct sctp_chunkhdr _sch;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800296 u_int32_t offset, count;
Patrick McHardy35c6d3c2008-01-14 23:46:05 -0800297 unsigned long map[256 / sizeof(unsigned long)] = { 0 };
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800298
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800299 sh = skb_header_pointer(skb, dataoff, sizeof(_sctph), &_sctph);
300 if (sh == NULL)
Patrick McHardyb37e9332008-01-14 23:46:52 -0800301 goto out;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800302
Patrick McHardy112f35c2008-01-14 23:46:20 -0800303 if (do_basic_checks(ct, skb, dataoff, map) != 0)
Patrick McHardyb37e9332008-01-14 23:46:52 -0800304 goto out;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800305
306 /* Check the verification tag (Sec 8.5) */
Patrick McHardy35c6d3c2008-01-14 23:46:05 -0800307 if (!test_bit(SCTP_CID_INIT, map) &&
308 !test_bit(SCTP_CID_SHUTDOWN_COMPLETE, map) &&
309 !test_bit(SCTP_CID_COOKIE_ECHO, map) &&
310 !test_bit(SCTP_CID_ABORT, map) &&
311 !test_bit(SCTP_CID_SHUTDOWN_ACK, map) &&
Patrick McHardy85288192008-01-14 23:46:37 -0800312 sh->vtag != ct->proto.sctp.vtag[dir]) {
Patrick McHardy0d537782007-07-07 22:39:38 -0700313 pr_debug("Verification tag check failed\n");
Patrick McHardyb37e9332008-01-14 23:46:52 -0800314 goto out;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800315 }
316
Patrick McHardy328bd892008-11-24 13:44:55 +0100317 old_state = new_state = SCTP_CONNTRACK_NONE;
Patrick McHardy440f0d52009-06-10 14:32:47 +0200318 spin_lock_bh(&ct->lock);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800319 for_each_sctp_chunk (skb, sch, _sch, offset, dataoff, count) {
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800320 /* Special cases of Verification tag check (Sec 8.5.1) */
321 if (sch->type == SCTP_CID_INIT) {
322 /* Sec 8.5.1 (A) */
Patrick McHardyb37e9332008-01-14 23:46:52 -0800323 if (sh->vtag != 0)
324 goto out_unlock;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800325 } else if (sch->type == SCTP_CID_ABORT) {
326 /* Sec 8.5.1 (B) */
Patrick McHardy85288192008-01-14 23:46:37 -0800327 if (sh->vtag != ct->proto.sctp.vtag[dir] &&
Patrick McHardyb37e9332008-01-14 23:46:52 -0800328 sh->vtag != ct->proto.sctp.vtag[!dir])
329 goto out_unlock;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800330 } else if (sch->type == SCTP_CID_SHUTDOWN_COMPLETE) {
331 /* Sec 8.5.1 (C) */
Patrick McHardy85288192008-01-14 23:46:37 -0800332 if (sh->vtag != ct->proto.sctp.vtag[dir] &&
333 sh->vtag != ct->proto.sctp.vtag[!dir] &&
Patrick McHardy9b1c2cf2008-01-14 23:48:02 -0800334 sch->flags & SCTP_CHUNK_FLAG_T)
Patrick McHardyb37e9332008-01-14 23:46:52 -0800335 goto out_unlock;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800336 } else if (sch->type == SCTP_CID_COOKIE_ECHO) {
337 /* Sec 8.5.1 (D) */
Patrick McHardyb37e9332008-01-14 23:46:52 -0800338 if (sh->vtag != ct->proto.sctp.vtag[dir])
339 goto out_unlock;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800340 }
341
Patrick McHardyefe9f682008-01-14 23:47:09 -0800342 old_state = ct->proto.sctp.state;
343 new_state = sctp_new_state(dir, old_state, sch->type);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800344
345 /* Invalid */
Patrick McHardyefe9f682008-01-14 23:47:09 -0800346 if (new_state == SCTP_CONNTRACK_MAX) {
Patrick McHardy0d537782007-07-07 22:39:38 -0700347 pr_debug("nf_conntrack_sctp: Invalid dir=%i ctype=%u "
348 "conntrack=%u\n",
Patrick McHardyefe9f682008-01-14 23:47:09 -0800349 dir, sch->type, old_state);
Patrick McHardyb37e9332008-01-14 23:46:52 -0800350 goto out_unlock;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800351 }
352
353 /* If it is an INIT or an INIT ACK note down the vtag */
Patrick McHardy5447d472008-01-14 23:45:48 -0800354 if (sch->type == SCTP_CID_INIT ||
355 sch->type == SCTP_CID_INIT_ACK) {
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800356 sctp_inithdr_t _inithdr, *ih;
357
358 ih = skb_header_pointer(skb, offset + sizeof(sctp_chunkhdr_t),
YOSHIFUJI Hideaki601e68e2007-02-12 11:15:49 -0800359 sizeof(_inithdr), &_inithdr);
Patrick McHardyb37e9332008-01-14 23:46:52 -0800360 if (ih == NULL)
361 goto out_unlock;
Patrick McHardy0d537782007-07-07 22:39:38 -0700362 pr_debug("Setting vtag %x for dir %d\n",
Patrick McHardy85288192008-01-14 23:46:37 -0800363 ih->init_tag, !dir);
364 ct->proto.sctp.vtag[!dir] = ih->init_tag;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800365 }
366
Patrick McHardyefe9f682008-01-14 23:47:09 -0800367 ct->proto.sctp.state = new_state;
368 if (old_state != new_state)
Alexey Dobriyana71996f2008-10-08 11:35:07 +0200369 nf_conntrack_event_cache(IPCT_PROTOINFO, ct);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800370 }
Patrick McHardy440f0d52009-06-10 14:32:47 +0200371 spin_unlock_bh(&ct->lock);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800372
Patrick McHardy86c0bf42008-01-14 23:48:17 -0800373 nf_ct_refresh_acct(ct, ctinfo, skb, sctp_timeouts[new_state]);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800374
Patrick McHardyefe9f682008-01-14 23:47:09 -0800375 if (old_state == SCTP_CONNTRACK_COOKIE_ECHOED &&
Patrick McHardy85288192008-01-14 23:46:37 -0800376 dir == IP_CT_DIR_REPLY &&
Patrick McHardyefe9f682008-01-14 23:47:09 -0800377 new_state == SCTP_CONNTRACK_ESTABLISHED) {
Patrick McHardy0d537782007-07-07 22:39:38 -0700378 pr_debug("Setting assured bit\n");
Patrick McHardy112f35c2008-01-14 23:46:20 -0800379 set_bit(IPS_ASSURED_BIT, &ct->status);
Patrick McHardy858b31332010-02-03 13:48:53 +0100380 nf_conntrack_event_cache(IPCT_ASSURED, ct);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800381 }
382
383 return NF_ACCEPT;
Patrick McHardyb37e9332008-01-14 23:46:52 -0800384
385out_unlock:
Patrick McHardy440f0d52009-06-10 14:32:47 +0200386 spin_unlock_bh(&ct->lock);
Patrick McHardyb37e9332008-01-14 23:46:52 -0800387out:
388 return -NF_ACCEPT;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800389}
390
391/* Called when a new connection for this protocol found. */
Jan Engelhardt09f263c2008-04-14 11:15:53 +0200392static bool sctp_new(struct nf_conn *ct, const struct sk_buff *skb,
393 unsigned int dataoff)
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800394{
Patrick McHardyefe9f682008-01-14 23:47:09 -0800395 enum sctp_conntrack new_state;
Jan Engelhardt12c33aa2008-04-14 11:15:54 +0200396 const struct sctphdr *sh;
397 struct sctphdr _sctph;
398 const struct sctp_chunkhdr *sch;
399 struct sctp_chunkhdr _sch;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800400 u_int32_t offset, count;
Patrick McHardy35c6d3c2008-01-14 23:46:05 -0800401 unsigned long map[256 / sizeof(unsigned long)] = { 0 };
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800402
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800403 sh = skb_header_pointer(skb, dataoff, sizeof(_sctph), &_sctph);
404 if (sh == NULL)
Jan Engelhardt09f263c2008-04-14 11:15:53 +0200405 return false;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800406
Patrick McHardy112f35c2008-01-14 23:46:20 -0800407 if (do_basic_checks(ct, skb, dataoff, map) != 0)
Jan Engelhardt09f263c2008-04-14 11:15:53 +0200408 return false;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800409
410 /* If an OOTB packet has any of these chunks discard (Sec 8.4) */
Patrick McHardy35c6d3c2008-01-14 23:46:05 -0800411 if (test_bit(SCTP_CID_ABORT, map) ||
412 test_bit(SCTP_CID_SHUTDOWN_COMPLETE, map) ||
413 test_bit(SCTP_CID_COOKIE_ACK, map))
Jan Engelhardt09f263c2008-04-14 11:15:53 +0200414 return false;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800415
Patrick McHardyefe9f682008-01-14 23:47:09 -0800416 new_state = SCTP_CONNTRACK_MAX;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800417 for_each_sctp_chunk (skb, sch, _sch, offset, dataoff, count) {
418 /* Don't need lock here: this conntrack not in circulation yet */
Patrick McHardyefe9f682008-01-14 23:47:09 -0800419 new_state = sctp_new_state(IP_CT_DIR_ORIGINAL,
420 SCTP_CONNTRACK_NONE, sch->type);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800421
422 /* Invalid: delete conntrack */
Patrick McHardyefe9f682008-01-14 23:47:09 -0800423 if (new_state == SCTP_CONNTRACK_NONE ||
424 new_state == SCTP_CONNTRACK_MAX) {
Patrick McHardy0d537782007-07-07 22:39:38 -0700425 pr_debug("nf_conntrack_sctp: invalid new deleting.\n");
Jan Engelhardt09f263c2008-04-14 11:15:53 +0200426 return false;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800427 }
428
429 /* Copy the vtag into the state info */
430 if (sch->type == SCTP_CID_INIT) {
431 if (sh->vtag == 0) {
432 sctp_inithdr_t _inithdr, *ih;
433
434 ih = skb_header_pointer(skb, offset + sizeof(sctp_chunkhdr_t),
YOSHIFUJI Hideaki601e68e2007-02-12 11:15:49 -0800435 sizeof(_inithdr), &_inithdr);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800436 if (ih == NULL)
Jan Engelhardt09f263c2008-04-14 11:15:53 +0200437 return false;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800438
Patrick McHardy0d537782007-07-07 22:39:38 -0700439 pr_debug("Setting vtag %x for new conn\n",
440 ih->init_tag);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800441
Patrick McHardy112f35c2008-01-14 23:46:20 -0800442 ct->proto.sctp.vtag[IP_CT_DIR_REPLY] =
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800443 ih->init_tag;
444 } else {
445 /* Sec 8.5.1 (A) */
Jan Engelhardt09f263c2008-04-14 11:15:53 +0200446 return false;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800447 }
448 }
449 /* If it is a shutdown ack OOTB packet, we expect a return
450 shutdown complete, otherwise an ABORT Sec 8.4 (5) and (8) */
451 else {
Patrick McHardy0d537782007-07-07 22:39:38 -0700452 pr_debug("Setting vtag %x for new conn OOTB\n",
453 sh->vtag);
Patrick McHardy112f35c2008-01-14 23:46:20 -0800454 ct->proto.sctp.vtag[IP_CT_DIR_REPLY] = sh->vtag;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800455 }
456
Patrick McHardyefe9f682008-01-14 23:47:09 -0800457 ct->proto.sctp.state = new_state;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800458 }
459
Jan Engelhardt09f263c2008-04-14 11:15:53 +0200460 return true;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800461}
462
Pablo Neira Ayusoa2588602008-06-09 15:56:39 -0700463#if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE)
464
465#include <linux/netfilter/nfnetlink.h>
466#include <linux/netfilter/nfnetlink_conntrack.h>
467
468static int sctp_to_nlattr(struct sk_buff *skb, struct nlattr *nla,
Patrick McHardy440f0d52009-06-10 14:32:47 +0200469 struct nf_conn *ct)
Pablo Neira Ayusoa2588602008-06-09 15:56:39 -0700470{
471 struct nlattr *nest_parms;
472
Patrick McHardy440f0d52009-06-10 14:32:47 +0200473 spin_lock_bh(&ct->lock);
Pablo Neira Ayusoa2588602008-06-09 15:56:39 -0700474 nest_parms = nla_nest_start(skb, CTA_PROTOINFO_SCTP | NLA_F_NESTED);
475 if (!nest_parms)
476 goto nla_put_failure;
477
478 NLA_PUT_U8(skb, CTA_PROTOINFO_SCTP_STATE, ct->proto.sctp.state);
479
480 NLA_PUT_BE32(skb,
481 CTA_PROTOINFO_SCTP_VTAG_ORIGINAL,
Patrick McHardy5547cd02008-07-21 10:03:49 -0700482 ct->proto.sctp.vtag[IP_CT_DIR_ORIGINAL]);
Pablo Neira Ayusoa2588602008-06-09 15:56:39 -0700483
484 NLA_PUT_BE32(skb,
485 CTA_PROTOINFO_SCTP_VTAG_REPLY,
Patrick McHardy5547cd02008-07-21 10:03:49 -0700486 ct->proto.sctp.vtag[IP_CT_DIR_REPLY]);
Pablo Neira Ayusoa2588602008-06-09 15:56:39 -0700487
Patrick McHardy440f0d52009-06-10 14:32:47 +0200488 spin_unlock_bh(&ct->lock);
Pablo Neira Ayusoa2588602008-06-09 15:56:39 -0700489
490 nla_nest_end(skb, nest_parms);
491
492 return 0;
493
494nla_put_failure:
Patrick McHardy440f0d52009-06-10 14:32:47 +0200495 spin_unlock_bh(&ct->lock);
Pablo Neira Ayusoa2588602008-06-09 15:56:39 -0700496 return -1;
497}
498
499static const struct nla_policy sctp_nla_policy[CTA_PROTOINFO_SCTP_MAX+1] = {
500 [CTA_PROTOINFO_SCTP_STATE] = { .type = NLA_U8 },
501 [CTA_PROTOINFO_SCTP_VTAG_ORIGINAL] = { .type = NLA_U32 },
502 [CTA_PROTOINFO_SCTP_VTAG_REPLY] = { .type = NLA_U32 },
503};
504
505static int nlattr_to_sctp(struct nlattr *cda[], struct nf_conn *ct)
506{
507 struct nlattr *attr = cda[CTA_PROTOINFO_SCTP];
508 struct nlattr *tb[CTA_PROTOINFO_SCTP_MAX+1];
509 int err;
510
511 /* updates may not contain the internal protocol info, skip parsing */
512 if (!attr)
513 return 0;
514
515 err = nla_parse_nested(tb,
516 CTA_PROTOINFO_SCTP_MAX,
517 attr,
518 sctp_nla_policy);
519 if (err < 0)
520 return err;
521
522 if (!tb[CTA_PROTOINFO_SCTP_STATE] ||
523 !tb[CTA_PROTOINFO_SCTP_VTAG_ORIGINAL] ||
524 !tb[CTA_PROTOINFO_SCTP_VTAG_REPLY])
525 return -EINVAL;
526
Patrick McHardy440f0d52009-06-10 14:32:47 +0200527 spin_lock_bh(&ct->lock);
Pablo Neira Ayusoa2588602008-06-09 15:56:39 -0700528 ct->proto.sctp.state = nla_get_u8(tb[CTA_PROTOINFO_SCTP_STATE]);
529 ct->proto.sctp.vtag[IP_CT_DIR_ORIGINAL] =
Patrick McHardy5547cd02008-07-21 10:03:49 -0700530 nla_get_be32(tb[CTA_PROTOINFO_SCTP_VTAG_ORIGINAL]);
Pablo Neira Ayusoa2588602008-06-09 15:56:39 -0700531 ct->proto.sctp.vtag[IP_CT_DIR_REPLY] =
Patrick McHardy5547cd02008-07-21 10:03:49 -0700532 nla_get_be32(tb[CTA_PROTOINFO_SCTP_VTAG_REPLY]);
Patrick McHardy440f0d52009-06-10 14:32:47 +0200533 spin_unlock_bh(&ct->lock);
Pablo Neira Ayusoa2588602008-06-09 15:56:39 -0700534
535 return 0;
536}
Holger Eitzenbergera400c302009-03-25 21:53:39 +0100537
538static int sctp_nlattr_size(void)
539{
540 return nla_total_size(0) /* CTA_PROTOINFO_SCTP */
541 + nla_policy_len(sctp_nla_policy, CTA_PROTOINFO_SCTP_MAX + 1);
542}
Pablo Neira Ayusoa2588602008-06-09 15:56:39 -0700543#endif
544
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800545#ifdef CONFIG_SYSCTL
Patrick McHardy933a41e2006-11-29 02:35:18 +0100546static unsigned int sctp_sysctl_table_users;
547static struct ctl_table_header *sctp_sysctl_header;
548static struct ctl_table sctp_sysctl_table[] = {
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800549 {
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800550 .procname = "nf_conntrack_sctp_timeout_closed",
Patrick McHardy86c0bf42008-01-14 23:48:17 -0800551 .data = &sctp_timeouts[SCTP_CONNTRACK_CLOSED],
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800552 .maxlen = sizeof(unsigned int),
553 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800554 .proc_handler = proc_dointvec_jiffies,
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800555 },
556 {
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800557 .procname = "nf_conntrack_sctp_timeout_cookie_wait",
Patrick McHardy86c0bf42008-01-14 23:48:17 -0800558 .data = &sctp_timeouts[SCTP_CONNTRACK_COOKIE_WAIT],
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800559 .maxlen = sizeof(unsigned int),
560 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800561 .proc_handler = proc_dointvec_jiffies,
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800562 },
563 {
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800564 .procname = "nf_conntrack_sctp_timeout_cookie_echoed",
Patrick McHardy86c0bf42008-01-14 23:48:17 -0800565 .data = &sctp_timeouts[SCTP_CONNTRACK_COOKIE_ECHOED],
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800566 .maxlen = sizeof(unsigned int),
567 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800568 .proc_handler = proc_dointvec_jiffies,
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800569 },
570 {
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800571 .procname = "nf_conntrack_sctp_timeout_established",
Patrick McHardy86c0bf42008-01-14 23:48:17 -0800572 .data = &sctp_timeouts[SCTP_CONNTRACK_ESTABLISHED],
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800573 .maxlen = sizeof(unsigned int),
574 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800575 .proc_handler = proc_dointvec_jiffies,
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800576 },
577 {
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800578 .procname = "nf_conntrack_sctp_timeout_shutdown_sent",
Patrick McHardy86c0bf42008-01-14 23:48:17 -0800579 .data = &sctp_timeouts[SCTP_CONNTRACK_SHUTDOWN_SENT],
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800580 .maxlen = sizeof(unsigned int),
581 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800582 .proc_handler = proc_dointvec_jiffies,
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800583 },
584 {
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800585 .procname = "nf_conntrack_sctp_timeout_shutdown_recd",
Patrick McHardy86c0bf42008-01-14 23:48:17 -0800586 .data = &sctp_timeouts[SCTP_CONNTRACK_SHUTDOWN_RECD],
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800587 .maxlen = sizeof(unsigned int),
588 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800589 .proc_handler = proc_dointvec_jiffies,
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800590 },
591 {
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800592 .procname = "nf_conntrack_sctp_timeout_shutdown_ack_sent",
Patrick McHardy86c0bf42008-01-14 23:48:17 -0800593 .data = &sctp_timeouts[SCTP_CONNTRACK_SHUTDOWN_ACK_SENT],
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800594 .maxlen = sizeof(unsigned int),
595 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800596 .proc_handler = proc_dointvec_jiffies,
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800597 },
Eric W. Biedermanf8572d82009-11-05 13:32:03 -0800598 { }
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800599};
Patrick McHardya999e682006-11-29 02:35:20 +0100600
601#ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
602static struct ctl_table sctp_compat_sysctl_table[] = {
603 {
Patrick McHardya999e682006-11-29 02:35:20 +0100604 .procname = "ip_conntrack_sctp_timeout_closed",
Patrick McHardy86c0bf42008-01-14 23:48:17 -0800605 .data = &sctp_timeouts[SCTP_CONNTRACK_CLOSED],
Patrick McHardya999e682006-11-29 02:35:20 +0100606 .maxlen = sizeof(unsigned int),
607 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800608 .proc_handler = proc_dointvec_jiffies,
Patrick McHardya999e682006-11-29 02:35:20 +0100609 },
610 {
Patrick McHardya999e682006-11-29 02:35:20 +0100611 .procname = "ip_conntrack_sctp_timeout_cookie_wait",
Patrick McHardy86c0bf42008-01-14 23:48:17 -0800612 .data = &sctp_timeouts[SCTP_CONNTRACK_COOKIE_WAIT],
Patrick McHardya999e682006-11-29 02:35:20 +0100613 .maxlen = sizeof(unsigned int),
614 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800615 .proc_handler = proc_dointvec_jiffies,
Patrick McHardya999e682006-11-29 02:35:20 +0100616 },
617 {
Patrick McHardya999e682006-11-29 02:35:20 +0100618 .procname = "ip_conntrack_sctp_timeout_cookie_echoed",
Patrick McHardy86c0bf42008-01-14 23:48:17 -0800619 .data = &sctp_timeouts[SCTP_CONNTRACK_COOKIE_ECHOED],
Patrick McHardya999e682006-11-29 02:35:20 +0100620 .maxlen = sizeof(unsigned int),
621 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800622 .proc_handler = proc_dointvec_jiffies,
Patrick McHardya999e682006-11-29 02:35:20 +0100623 },
624 {
Patrick McHardya999e682006-11-29 02:35:20 +0100625 .procname = "ip_conntrack_sctp_timeout_established",
Patrick McHardy86c0bf42008-01-14 23:48:17 -0800626 .data = &sctp_timeouts[SCTP_CONNTRACK_ESTABLISHED],
Patrick McHardya999e682006-11-29 02:35:20 +0100627 .maxlen = sizeof(unsigned int),
628 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800629 .proc_handler = proc_dointvec_jiffies,
Patrick McHardya999e682006-11-29 02:35:20 +0100630 },
631 {
Patrick McHardya999e682006-11-29 02:35:20 +0100632 .procname = "ip_conntrack_sctp_timeout_shutdown_sent",
Patrick McHardy86c0bf42008-01-14 23:48:17 -0800633 .data = &sctp_timeouts[SCTP_CONNTRACK_SHUTDOWN_SENT],
Patrick McHardya999e682006-11-29 02:35:20 +0100634 .maxlen = sizeof(unsigned int),
635 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800636 .proc_handler = proc_dointvec_jiffies,
Patrick McHardya999e682006-11-29 02:35:20 +0100637 },
638 {
Patrick McHardya999e682006-11-29 02:35:20 +0100639 .procname = "ip_conntrack_sctp_timeout_shutdown_recd",
Patrick McHardy86c0bf42008-01-14 23:48:17 -0800640 .data = &sctp_timeouts[SCTP_CONNTRACK_SHUTDOWN_RECD],
Patrick McHardya999e682006-11-29 02:35:20 +0100641 .maxlen = sizeof(unsigned int),
642 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800643 .proc_handler = proc_dointvec_jiffies,
Patrick McHardya999e682006-11-29 02:35:20 +0100644 },
645 {
Patrick McHardya999e682006-11-29 02:35:20 +0100646 .procname = "ip_conntrack_sctp_timeout_shutdown_ack_sent",
Patrick McHardy86c0bf42008-01-14 23:48:17 -0800647 .data = &sctp_timeouts[SCTP_CONNTRACK_SHUTDOWN_ACK_SENT],
Patrick McHardya999e682006-11-29 02:35:20 +0100648 .maxlen = sizeof(unsigned int),
649 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800650 .proc_handler = proc_dointvec_jiffies,
Patrick McHardya999e682006-11-29 02:35:20 +0100651 },
Eric W. Biedermanf8572d82009-11-05 13:32:03 -0800652 { }
Patrick McHardya999e682006-11-29 02:35:20 +0100653};
654#endif /* CONFIG_NF_CONNTRACK_PROC_COMPAT */
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800655#endif
656
Patrick McHardy61075af2007-07-14 20:48:19 -0700657static struct nf_conntrack_l4proto nf_conntrack_l4proto_sctp4 __read_mostly = {
Patrick McHardy933a41e2006-11-29 02:35:18 +0100658 .l3proto = PF_INET,
659 .l4proto = IPPROTO_SCTP,
660 .name = "sctp",
661 .pkt_to_tuple = sctp_pkt_to_tuple,
662 .invert_tuple = sctp_invert_tuple,
663 .print_tuple = sctp_print_tuple,
664 .print_conntrack = sctp_print_conntrack,
665 .packet = sctp_packet,
666 .new = sctp_new,
667 .me = THIS_MODULE,
Pablo Neira Ayusoc7212e92007-12-17 22:29:02 -0800668#if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE)
Pablo Neira Ayusoa2588602008-06-09 15:56:39 -0700669 .to_nlattr = sctp_to_nlattr,
Holger Eitzenbergera400c302009-03-25 21:53:39 +0100670 .nlattr_size = sctp_nlattr_size,
Pablo Neira Ayusoa2588602008-06-09 15:56:39 -0700671 .from_nlattr = nlattr_to_sctp,
Pablo Neira Ayusoc7212e92007-12-17 22:29:02 -0800672 .tuple_to_nlattr = nf_ct_port_tuple_to_nlattr,
Holger Eitzenbergera400c302009-03-25 21:53:39 +0100673 .nlattr_tuple_size = nf_ct_port_nlattr_tuple_size,
Pablo Neira Ayusoc7212e92007-12-17 22:29:02 -0800674 .nlattr_to_tuple = nf_ct_port_nlattr_to_tuple,
675 .nla_policy = nf_ct_port_nla_policy,
676#endif
Patrick McHardy933a41e2006-11-29 02:35:18 +0100677#ifdef CONFIG_SYSCTL
678 .ctl_table_users = &sctp_sysctl_table_users,
679 .ctl_table_header = &sctp_sysctl_header,
680 .ctl_table = sctp_sysctl_table,
Patrick McHardya999e682006-11-29 02:35:20 +0100681#ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
682 .ctl_compat_table = sctp_compat_sysctl_table,
683#endif
Patrick McHardy933a41e2006-11-29 02:35:18 +0100684#endif
685};
686
Patrick McHardy61075af2007-07-14 20:48:19 -0700687static struct nf_conntrack_l4proto nf_conntrack_l4proto_sctp6 __read_mostly = {
Patrick McHardy933a41e2006-11-29 02:35:18 +0100688 .l3proto = PF_INET6,
689 .l4proto = IPPROTO_SCTP,
690 .name = "sctp",
691 .pkt_to_tuple = sctp_pkt_to_tuple,
692 .invert_tuple = sctp_invert_tuple,
693 .print_tuple = sctp_print_tuple,
694 .print_conntrack = sctp_print_conntrack,
695 .packet = sctp_packet,
696 .new = sctp_new,
697 .me = THIS_MODULE,
Pablo Neira Ayusoc7212e92007-12-17 22:29:02 -0800698#if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE)
Pablo Neira Ayusoa2588602008-06-09 15:56:39 -0700699 .to_nlattr = sctp_to_nlattr,
Holger Eitzenbergera400c302009-03-25 21:53:39 +0100700 .nlattr_size = sctp_nlattr_size,
Pablo Neira Ayusoa2588602008-06-09 15:56:39 -0700701 .from_nlattr = nlattr_to_sctp,
Pablo Neira Ayusoc7212e92007-12-17 22:29:02 -0800702 .tuple_to_nlattr = nf_ct_port_tuple_to_nlattr,
Holger Eitzenbergera400c302009-03-25 21:53:39 +0100703 .nlattr_tuple_size = nf_ct_port_nlattr_tuple_size,
Pablo Neira Ayusoc7212e92007-12-17 22:29:02 -0800704 .nlattr_to_tuple = nf_ct_port_nlattr_to_tuple,
705 .nla_policy = nf_ct_port_nla_policy,
706#endif
Patrick McHardy933a41e2006-11-29 02:35:18 +0100707#ifdef CONFIG_SYSCTL
708 .ctl_table_users = &sctp_sysctl_table_users,
709 .ctl_table_header = &sctp_sysctl_header,
710 .ctl_table = sctp_sysctl_table,
711#endif
712};
713
Stephen Hemminger2f0d2f12008-01-31 04:08:10 -0800714static int __init nf_conntrack_proto_sctp_init(void)
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800715{
716 int ret;
717
Martin Josefsson605dcad2006-11-29 02:35:06 +0100718 ret = nf_conntrack_l4proto_register(&nf_conntrack_l4proto_sctp4);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800719 if (ret) {
Stephen Hemminger654d0fb2010-05-13 15:02:08 +0200720 pr_err("nf_conntrack_l4proto_sctp4: protocol register failed\n");
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800721 goto out;
722 }
Martin Josefsson605dcad2006-11-29 02:35:06 +0100723 ret = nf_conntrack_l4proto_register(&nf_conntrack_l4proto_sctp6);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800724 if (ret) {
Stephen Hemminger654d0fb2010-05-13 15:02:08 +0200725 pr_err("nf_conntrack_l4proto_sctp6: protocol register failed\n");
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800726 goto cleanup_sctp4;
727 }
728
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800729 return ret;
730
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800731 cleanup_sctp4:
Martin Josefsson605dcad2006-11-29 02:35:06 +0100732 nf_conntrack_l4proto_unregister(&nf_conntrack_l4proto_sctp4);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800733 out:
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800734 return ret;
735}
736
Stephen Hemminger2f0d2f12008-01-31 04:08:10 -0800737static void __exit nf_conntrack_proto_sctp_fini(void)
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800738{
Martin Josefsson605dcad2006-11-29 02:35:06 +0100739 nf_conntrack_l4proto_unregister(&nf_conntrack_l4proto_sctp6);
740 nf_conntrack_l4proto_unregister(&nf_conntrack_l4proto_sctp4);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800741}
742
Andrew Morton65b4b4e2006-03-28 16:37:06 -0800743module_init(nf_conntrack_proto_sctp_init);
744module_exit(nf_conntrack_proto_sctp_fini);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800745
746MODULE_LICENSE("GPL");
747MODULE_AUTHOR("Kiran Kumar Immidi");
748MODULE_DESCRIPTION("Netfilter connection tracking protocol helper for SCTP");
Patrick McHardyd2483dd2006-12-02 22:06:05 -0800749MODULE_ALIAS("ip_conntrack_proto_sctp");