added 2.6.29.6 aldebaran kernel
[nao-ulib.git] / kernel / 2.6.29.6-aldebaran-rt / net / netfilter / nf_conntrack_proto_sctp.c
blobf879c8007bb4a85c173887f1b53dde76439be574
1 /*
2 * Connection tracking protocol helper module for SCTP.
4 * SCTP is defined in RFC 2960. References to various sections in this code
5 * are to this RFC.
7 * 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.
12 #include <linux/types.h>
13 #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>
21 #include <linux/spinlock.h>
22 #include <linux/interrupt.h>
24 #include <net/netfilter/nf_conntrack.h>
25 #include <net/netfilter/nf_conntrack_l4proto.h>
26 #include <net/netfilter/nf_conntrack_ecache.h>
28 /* Protects ct->proto.sctp */
29 static DEFINE_RWLOCK(sctp_lock);
31 /* FIXME: Examine ipfilter's timeouts and conntrack transitions more
32 closely. They're more complex. --RR
34 And so for me for SCTP :D -Kiran */
36 static const char *const sctp_conntrack_names[] = {
37 "NONE",
38 "CLOSED",
39 "COOKIE_WAIT",
40 "COOKIE_ECHOED",
41 "ESTABLISHED",
42 "SHUTDOWN_SENT",
43 "SHUTDOWN_RECD",
44 "SHUTDOWN_ACK_SENT",
47 #define SECS * HZ
48 #define MINS * 60 SECS
49 #define HOURS * 60 MINS
50 #define DAYS * 24 HOURS
52 static unsigned int sctp_timeouts[SCTP_CONNTRACK_MAX] __read_mostly = {
53 [SCTP_CONNTRACK_CLOSED] = 10 SECS,
54 [SCTP_CONNTRACK_COOKIE_WAIT] = 3 SECS,
55 [SCTP_CONNTRACK_COOKIE_ECHOED] = 3 SECS,
56 [SCTP_CONNTRACK_ESTABLISHED] = 5 DAYS,
57 [SCTP_CONNTRACK_SHUTDOWN_SENT] = 300 SECS / 1000,
58 [SCTP_CONNTRACK_SHUTDOWN_RECD] = 300 SECS / 1000,
59 [SCTP_CONNTRACK_SHUTDOWN_ACK_SENT] = 3 SECS,
62 #define sNO SCTP_CONNTRACK_NONE
63 #define sCL SCTP_CONNTRACK_CLOSED
64 #define sCW SCTP_CONNTRACK_COOKIE_WAIT
65 #define sCE SCTP_CONNTRACK_COOKIE_ECHOED
66 #define sES SCTP_CONNTRACK_ESTABLISHED
67 #define sSS SCTP_CONNTRACK_SHUTDOWN_SENT
68 #define sSR SCTP_CONNTRACK_SHUTDOWN_RECD
69 #define sSA SCTP_CONNTRACK_SHUTDOWN_ACK_SENT
70 #define sIV SCTP_CONNTRACK_MAX
73 These are the descriptions of the states:
75 NOTE: These state names are tantalizingly similar to the states of an
76 SCTP endpoint. But the interpretation of the states is a little different,
77 considering that these are the states of the connection and not of an end
78 point. Please note the subtleties. -Kiran
80 NONE - Nothing so far.
81 COOKIE WAIT - We have seen an INIT chunk in the original direction, or also
82 an INIT_ACK chunk in the reply direction.
83 COOKIE ECHOED - We have seen a COOKIE_ECHO chunk in the original direction.
84 ESTABLISHED - We have seen a COOKIE_ACK in the reply direction.
85 SHUTDOWN_SENT - We have seen a SHUTDOWN chunk in the original direction.
86 SHUTDOWN_RECD - We have seen a SHUTDOWN chunk in the reply directoin.
87 SHUTDOWN_ACK_SENT - We have seen a SHUTDOWN_ACK chunk in the direction opposite
88 to that of the SHUTDOWN chunk.
89 CLOSED - We have seen a SHUTDOWN_COMPLETE chunk in the direction of
90 the SHUTDOWN chunk. Connection is closed.
93 /* TODO
94 - I have assumed that the first INIT is in the original direction.
95 This messes things when an INIT comes in the reply direction in CLOSED
96 state.
97 - Check the error type in the reply dir before transitioning from
98 cookie echoed to closed.
99 - Sec 5.2.4 of RFC 2960
100 - Multi Homing support.
103 /* SCTP conntrack state transitions */
104 static const u8 sctp_conntracks[2][9][SCTP_CONNTRACK_MAX] = {
106 /* ORIGINAL */
107 /* sNO, sCL, sCW, sCE, sES, sSS, sSR, sSA */
108 /* init */ {sCW, sCW, sCW, sCE, sES, sSS, sSR, sSA},
109 /* init_ack */ {sCL, sCL, sCW, sCE, sES, sSS, sSR, sSA},
110 /* abort */ {sCL, sCL, sCL, sCL, sCL, sCL, sCL, sCL},
111 /* shutdown */ {sCL, sCL, sCW, sCE, sSS, sSS, sSR, sSA},
112 /* shutdown_ack */ {sSA, sCL, sCW, sCE, sES, sSA, sSA, sSA},
113 /* error */ {sCL, sCL, sCW, sCE, sES, sSS, sSR, sSA},/* Cant have Stale cookie*/
114 /* cookie_echo */ {sCL, sCL, sCE, sCE, sES, sSS, sSR, sSA},/* 5.2.4 - Big TODO */
115 /* cookie_ack */ {sCL, sCL, sCW, sCE, sES, sSS, sSR, sSA},/* Cant come in orig dir */
116 /* shutdown_comp*/ {sCL, sCL, sCW, sCE, sES, sSS, sSR, sCL}
119 /* REPLY */
120 /* sNO, sCL, sCW, sCE, sES, sSS, sSR, sSA */
121 /* init */ {sIV, sCL, sCW, sCE, sES, sSS, sSR, sSA},/* INIT in sCL Big TODO */
122 /* init_ack */ {sIV, sCL, sCW, sCE, sES, sSS, sSR, sSA},
123 /* abort */ {sIV, sCL, sCL, sCL, sCL, sCL, sCL, sCL},
124 /* shutdown */ {sIV, sCL, sCW, sCE, sSR, sSS, sSR, sSA},
125 /* shutdown_ack */ {sIV, sCL, sCW, sCE, sES, sSA, sSA, sSA},
126 /* error */ {sIV, sCL, sCW, sCL, sES, sSS, sSR, sSA},
127 /* cookie_echo */ {sIV, sCL, sCW, sCE, sES, sSS, sSR, sSA},/* Cant come in reply dir */
128 /* cookie_ack */ {sIV, sCL, sCW, sES, sES, sSS, sSR, sSA},
129 /* shutdown_comp*/ {sIV, sCL, sCW, sCE, sES, sSS, sSR, sCL}
133 static bool sctp_pkt_to_tuple(const struct sk_buff *skb, unsigned int dataoff,
134 struct nf_conntrack_tuple *tuple)
136 const struct sctphdr *hp;
137 struct sctphdr _hdr;
139 /* Actually only need first 8 bytes. */
140 hp = skb_header_pointer(skb, dataoff, 8, &_hdr);
141 if (hp == NULL)
142 return false;
144 tuple->src.u.sctp.port = hp->source;
145 tuple->dst.u.sctp.port = hp->dest;
146 return true;
149 static bool sctp_invert_tuple(struct nf_conntrack_tuple *tuple,
150 const struct nf_conntrack_tuple *orig)
152 tuple->src.u.sctp.port = orig->dst.u.sctp.port;
153 tuple->dst.u.sctp.port = orig->src.u.sctp.port;
154 return true;
157 /* Print out the per-protocol part of the tuple. */
158 static int sctp_print_tuple(struct seq_file *s,
159 const struct nf_conntrack_tuple *tuple)
161 return seq_printf(s, "sport=%hu dport=%hu ",
162 ntohs(tuple->src.u.sctp.port),
163 ntohs(tuple->dst.u.sctp.port));
166 /* Print out the private part of the conntrack. */
167 static int sctp_print_conntrack(struct seq_file *s, const struct nf_conn *ct)
169 enum sctp_conntrack state;
171 read_lock_bh(&sctp_lock);
172 state = ct->proto.sctp.state;
173 read_unlock_bh(&sctp_lock);
175 return seq_printf(s, "%s ", sctp_conntrack_names[state]);
178 #define for_each_sctp_chunk(skb, sch, _sch, offset, dataoff, count) \
179 for ((offset) = (dataoff) + sizeof(sctp_sctphdr_t), (count) = 0; \
180 (offset) < (skb)->len && \
181 ((sch) = skb_header_pointer((skb), (offset), sizeof(_sch), &(_sch))); \
182 (offset) += (ntohs((sch)->length) + 3) & ~3, (count)++)
184 /* Some validity checks to make sure the chunks are fine */
185 static int do_basic_checks(struct nf_conn *ct,
186 const struct sk_buff *skb,
187 unsigned int dataoff,
188 unsigned long *map)
190 u_int32_t offset, count;
191 sctp_chunkhdr_t _sch, *sch;
192 int flag;
194 flag = 0;
196 for_each_sctp_chunk (skb, sch, _sch, offset, dataoff, count) {
197 pr_debug("Chunk Num: %d Type: %d\n", count, sch->type);
199 if (sch->type == SCTP_CID_INIT ||
200 sch->type == SCTP_CID_INIT_ACK ||
201 sch->type == SCTP_CID_SHUTDOWN_COMPLETE)
202 flag = 1;
205 * Cookie Ack/Echo chunks not the first OR
206 * Init / Init Ack / Shutdown compl chunks not the only chunks
207 * OR zero-length.
209 if (((sch->type == SCTP_CID_COOKIE_ACK ||
210 sch->type == SCTP_CID_COOKIE_ECHO ||
211 flag) &&
212 count != 0) || !sch->length) {
213 pr_debug("Basic checks failed\n");
214 return 1;
217 if (map)
218 set_bit(sch->type, map);
221 pr_debug("Basic checks passed\n");
222 return count == 0;
225 static int sctp_new_state(enum ip_conntrack_dir dir,
226 enum sctp_conntrack cur_state,
227 int chunk_type)
229 int i;
231 pr_debug("Chunk type: %d\n", chunk_type);
233 switch (chunk_type) {
234 case SCTP_CID_INIT:
235 pr_debug("SCTP_CID_INIT\n");
236 i = 0;
237 break;
238 case SCTP_CID_INIT_ACK:
239 pr_debug("SCTP_CID_INIT_ACK\n");
240 i = 1;
241 break;
242 case SCTP_CID_ABORT:
243 pr_debug("SCTP_CID_ABORT\n");
244 i = 2;
245 break;
246 case SCTP_CID_SHUTDOWN:
247 pr_debug("SCTP_CID_SHUTDOWN\n");
248 i = 3;
249 break;
250 case SCTP_CID_SHUTDOWN_ACK:
251 pr_debug("SCTP_CID_SHUTDOWN_ACK\n");
252 i = 4;
253 break;
254 case SCTP_CID_ERROR:
255 pr_debug("SCTP_CID_ERROR\n");
256 i = 5;
257 break;
258 case SCTP_CID_COOKIE_ECHO:
259 pr_debug("SCTP_CID_COOKIE_ECHO\n");
260 i = 6;
261 break;
262 case SCTP_CID_COOKIE_ACK:
263 pr_debug("SCTP_CID_COOKIE_ACK\n");
264 i = 7;
265 break;
266 case SCTP_CID_SHUTDOWN_COMPLETE:
267 pr_debug("SCTP_CID_SHUTDOWN_COMPLETE\n");
268 i = 8;
269 break;
270 default:
271 /* Other chunks like DATA, SACK, HEARTBEAT and
272 its ACK do not cause a change in state */
273 pr_debug("Unknown chunk type, Will stay in %s\n",
274 sctp_conntrack_names[cur_state]);
275 return cur_state;
278 pr_debug("dir: %d cur_state: %s chunk_type: %d new_state: %s\n",
279 dir, sctp_conntrack_names[cur_state], chunk_type,
280 sctp_conntrack_names[sctp_conntracks[dir][i][cur_state]]);
282 return sctp_conntracks[dir][i][cur_state];
285 /* Returns verdict for packet, or -NF_ACCEPT for invalid. */
286 static int sctp_packet(struct nf_conn *ct,
287 const struct sk_buff *skb,
288 unsigned int dataoff,
289 enum ip_conntrack_info ctinfo,
290 u_int8_t pf,
291 unsigned int hooknum)
293 enum sctp_conntrack new_state, old_state;
294 enum ip_conntrack_dir dir = CTINFO2DIR(ctinfo);
295 const struct sctphdr *sh;
296 struct sctphdr _sctph;
297 const struct sctp_chunkhdr *sch;
298 struct sctp_chunkhdr _sch;
299 u_int32_t offset, count;
300 unsigned long map[256 / sizeof(unsigned long)] = { 0 };
302 sh = skb_header_pointer(skb, dataoff, sizeof(_sctph), &_sctph);
303 if (sh == NULL)
304 goto out;
306 if (do_basic_checks(ct, skb, dataoff, map) != 0)
307 goto out;
309 /* Check the verification tag (Sec 8.5) */
310 if (!test_bit(SCTP_CID_INIT, map) &&
311 !test_bit(SCTP_CID_SHUTDOWN_COMPLETE, map) &&
312 !test_bit(SCTP_CID_COOKIE_ECHO, map) &&
313 !test_bit(SCTP_CID_ABORT, map) &&
314 !test_bit(SCTP_CID_SHUTDOWN_ACK, map) &&
315 sh->vtag != ct->proto.sctp.vtag[dir]) {
316 pr_debug("Verification tag check failed\n");
317 goto out;
320 old_state = new_state = SCTP_CONNTRACK_NONE;
321 write_lock_bh(&sctp_lock);
322 for_each_sctp_chunk (skb, sch, _sch, offset, dataoff, count) {
323 /* Special cases of Verification tag check (Sec 8.5.1) */
324 if (sch->type == SCTP_CID_INIT) {
325 /* Sec 8.5.1 (A) */
326 if (sh->vtag != 0)
327 goto out_unlock;
328 } else if (sch->type == SCTP_CID_ABORT) {
329 /* Sec 8.5.1 (B) */
330 if (sh->vtag != ct->proto.sctp.vtag[dir] &&
331 sh->vtag != ct->proto.sctp.vtag[!dir])
332 goto out_unlock;
333 } else if (sch->type == SCTP_CID_SHUTDOWN_COMPLETE) {
334 /* Sec 8.5.1 (C) */
335 if (sh->vtag != ct->proto.sctp.vtag[dir] &&
336 sh->vtag != ct->proto.sctp.vtag[!dir] &&
337 sch->flags & SCTP_CHUNK_FLAG_T)
338 goto out_unlock;
339 } else if (sch->type == SCTP_CID_COOKIE_ECHO) {
340 /* Sec 8.5.1 (D) */
341 if (sh->vtag != ct->proto.sctp.vtag[dir])
342 goto out_unlock;
345 old_state = ct->proto.sctp.state;
346 new_state = sctp_new_state(dir, old_state, sch->type);
348 /* Invalid */
349 if (new_state == SCTP_CONNTRACK_MAX) {
350 pr_debug("nf_conntrack_sctp: Invalid dir=%i ctype=%u "
351 "conntrack=%u\n",
352 dir, sch->type, old_state);
353 goto out_unlock;
356 /* If it is an INIT or an INIT ACK note down the vtag */
357 if (sch->type == SCTP_CID_INIT ||
358 sch->type == SCTP_CID_INIT_ACK) {
359 sctp_inithdr_t _inithdr, *ih;
361 ih = skb_header_pointer(skb, offset + sizeof(sctp_chunkhdr_t),
362 sizeof(_inithdr), &_inithdr);
363 if (ih == NULL)
364 goto out_unlock;
365 pr_debug("Setting vtag %x for dir %d\n",
366 ih->init_tag, !dir);
367 ct->proto.sctp.vtag[!dir] = ih->init_tag;
370 ct->proto.sctp.state = new_state;
371 if (old_state != new_state)
372 nf_conntrack_event_cache(IPCT_PROTOINFO, ct);
374 write_unlock_bh(&sctp_lock);
376 if (new_state == SCTP_CONNTRACK_MAX)
377 goto out;
379 nf_ct_refresh_acct(ct, ctinfo, skb, sctp_timeouts[new_state]);
381 if (old_state == SCTP_CONNTRACK_COOKIE_ECHOED &&
382 dir == IP_CT_DIR_REPLY &&
383 new_state == SCTP_CONNTRACK_ESTABLISHED) {
384 pr_debug("Setting assured bit\n");
385 set_bit(IPS_ASSURED_BIT, &ct->status);
386 nf_conntrack_event_cache(IPCT_STATUS, ct);
389 return NF_ACCEPT;
391 out_unlock:
392 write_unlock_bh(&sctp_lock);
393 out:
394 return -NF_ACCEPT;
397 /* Called when a new connection for this protocol found. */
398 static bool sctp_new(struct nf_conn *ct, const struct sk_buff *skb,
399 unsigned int dataoff)
401 enum sctp_conntrack new_state;
402 const struct sctphdr *sh;
403 struct sctphdr _sctph;
404 const struct sctp_chunkhdr *sch;
405 struct sctp_chunkhdr _sch;
406 u_int32_t offset, count;
407 unsigned long map[256 / sizeof(unsigned long)] = { 0 };
409 sh = skb_header_pointer(skb, dataoff, sizeof(_sctph), &_sctph);
410 if (sh == NULL)
411 return false;
413 if (do_basic_checks(ct, skb, dataoff, map) != 0)
414 return false;
416 /* If an OOTB packet has any of these chunks discard (Sec 8.4) */
417 if (test_bit(SCTP_CID_ABORT, map) ||
418 test_bit(SCTP_CID_SHUTDOWN_COMPLETE, map) ||
419 test_bit(SCTP_CID_COOKIE_ACK, map))
420 return false;
422 new_state = SCTP_CONNTRACK_MAX;
423 for_each_sctp_chunk (skb, sch, _sch, offset, dataoff, count) {
424 /* Don't need lock here: this conntrack not in circulation yet */
425 new_state = sctp_new_state(IP_CT_DIR_ORIGINAL,
426 SCTP_CONNTRACK_NONE, sch->type);
428 /* Invalid: delete conntrack */
429 if (new_state == SCTP_CONNTRACK_NONE ||
430 new_state == SCTP_CONNTRACK_MAX) {
431 pr_debug("nf_conntrack_sctp: invalid new deleting.\n");
432 return false;
435 /* Copy the vtag into the state info */
436 if (sch->type == SCTP_CID_INIT) {
437 if (sh->vtag == 0) {
438 sctp_inithdr_t _inithdr, *ih;
440 ih = skb_header_pointer(skb, offset + sizeof(sctp_chunkhdr_t),
441 sizeof(_inithdr), &_inithdr);
442 if (ih == NULL)
443 return false;
445 pr_debug("Setting vtag %x for new conn\n",
446 ih->init_tag);
448 ct->proto.sctp.vtag[IP_CT_DIR_REPLY] =
449 ih->init_tag;
450 } else {
451 /* Sec 8.5.1 (A) */
452 return false;
455 /* If it is a shutdown ack OOTB packet, we expect a return
456 shutdown complete, otherwise an ABORT Sec 8.4 (5) and (8) */
457 else {
458 pr_debug("Setting vtag %x for new conn OOTB\n",
459 sh->vtag);
460 ct->proto.sctp.vtag[IP_CT_DIR_REPLY] = sh->vtag;
463 ct->proto.sctp.state = new_state;
466 return true;
469 #if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE)
471 #include <linux/netfilter/nfnetlink.h>
472 #include <linux/netfilter/nfnetlink_conntrack.h>
474 static int sctp_to_nlattr(struct sk_buff *skb, struct nlattr *nla,
475 const struct nf_conn *ct)
477 struct nlattr *nest_parms;
479 read_lock_bh(&sctp_lock);
480 nest_parms = nla_nest_start(skb, CTA_PROTOINFO_SCTP | NLA_F_NESTED);
481 if (!nest_parms)
482 goto nla_put_failure;
484 NLA_PUT_U8(skb, CTA_PROTOINFO_SCTP_STATE, ct->proto.sctp.state);
486 NLA_PUT_BE32(skb,
487 CTA_PROTOINFO_SCTP_VTAG_ORIGINAL,
488 ct->proto.sctp.vtag[IP_CT_DIR_ORIGINAL]);
490 NLA_PUT_BE32(skb,
491 CTA_PROTOINFO_SCTP_VTAG_REPLY,
492 ct->proto.sctp.vtag[IP_CT_DIR_REPLY]);
494 read_unlock_bh(&sctp_lock);
496 nla_nest_end(skb, nest_parms);
498 return 0;
500 nla_put_failure:
501 read_unlock_bh(&sctp_lock);
502 return -1;
505 static const struct nla_policy sctp_nla_policy[CTA_PROTOINFO_SCTP_MAX+1] = {
506 [CTA_PROTOINFO_SCTP_STATE] = { .type = NLA_U8 },
507 [CTA_PROTOINFO_SCTP_VTAG_ORIGINAL] = { .type = NLA_U32 },
508 [CTA_PROTOINFO_SCTP_VTAG_REPLY] = { .type = NLA_U32 },
511 static int nlattr_to_sctp(struct nlattr *cda[], struct nf_conn *ct)
513 struct nlattr *attr = cda[CTA_PROTOINFO_SCTP];
514 struct nlattr *tb[CTA_PROTOINFO_SCTP_MAX+1];
515 int err;
517 /* updates may not contain the internal protocol info, skip parsing */
518 if (!attr)
519 return 0;
521 err = nla_parse_nested(tb,
522 CTA_PROTOINFO_SCTP_MAX,
523 attr,
524 sctp_nla_policy);
525 if (err < 0)
526 return err;
528 if (!tb[CTA_PROTOINFO_SCTP_STATE] ||
529 !tb[CTA_PROTOINFO_SCTP_VTAG_ORIGINAL] ||
530 !tb[CTA_PROTOINFO_SCTP_VTAG_REPLY])
531 return -EINVAL;
533 write_lock_bh(&sctp_lock);
534 ct->proto.sctp.state = nla_get_u8(tb[CTA_PROTOINFO_SCTP_STATE]);
535 ct->proto.sctp.vtag[IP_CT_DIR_ORIGINAL] =
536 nla_get_be32(tb[CTA_PROTOINFO_SCTP_VTAG_ORIGINAL]);
537 ct->proto.sctp.vtag[IP_CT_DIR_REPLY] =
538 nla_get_be32(tb[CTA_PROTOINFO_SCTP_VTAG_REPLY]);
539 write_unlock_bh(&sctp_lock);
541 return 0;
543 #endif
545 #ifdef CONFIG_SYSCTL
546 static unsigned int sctp_sysctl_table_users;
547 static struct ctl_table_header *sctp_sysctl_header;
548 static struct ctl_table sctp_sysctl_table[] = {
550 .procname = "nf_conntrack_sctp_timeout_closed",
551 .data = &sctp_timeouts[SCTP_CONNTRACK_CLOSED],
552 .maxlen = sizeof(unsigned int),
553 .mode = 0644,
554 .proc_handler = proc_dointvec_jiffies,
557 .procname = "nf_conntrack_sctp_timeout_cookie_wait",
558 .data = &sctp_timeouts[SCTP_CONNTRACK_COOKIE_WAIT],
559 .maxlen = sizeof(unsigned int),
560 .mode = 0644,
561 .proc_handler = proc_dointvec_jiffies,
564 .procname = "nf_conntrack_sctp_timeout_cookie_echoed",
565 .data = &sctp_timeouts[SCTP_CONNTRACK_COOKIE_ECHOED],
566 .maxlen = sizeof(unsigned int),
567 .mode = 0644,
568 .proc_handler = proc_dointvec_jiffies,
571 .procname = "nf_conntrack_sctp_timeout_established",
572 .data = &sctp_timeouts[SCTP_CONNTRACK_ESTABLISHED],
573 .maxlen = sizeof(unsigned int),
574 .mode = 0644,
575 .proc_handler = proc_dointvec_jiffies,
578 .procname = "nf_conntrack_sctp_timeout_shutdown_sent",
579 .data = &sctp_timeouts[SCTP_CONNTRACK_SHUTDOWN_SENT],
580 .maxlen = sizeof(unsigned int),
581 .mode = 0644,
582 .proc_handler = proc_dointvec_jiffies,
585 .procname = "nf_conntrack_sctp_timeout_shutdown_recd",
586 .data = &sctp_timeouts[SCTP_CONNTRACK_SHUTDOWN_RECD],
587 .maxlen = sizeof(unsigned int),
588 .mode = 0644,
589 .proc_handler = proc_dointvec_jiffies,
592 .procname = "nf_conntrack_sctp_timeout_shutdown_ack_sent",
593 .data = &sctp_timeouts[SCTP_CONNTRACK_SHUTDOWN_ACK_SENT],
594 .maxlen = sizeof(unsigned int),
595 .mode = 0644,
596 .proc_handler = proc_dointvec_jiffies,
599 .ctl_name = 0
603 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
604 static struct ctl_table sctp_compat_sysctl_table[] = {
606 .procname = "ip_conntrack_sctp_timeout_closed",
607 .data = &sctp_timeouts[SCTP_CONNTRACK_CLOSED],
608 .maxlen = sizeof(unsigned int),
609 .mode = 0644,
610 .proc_handler = proc_dointvec_jiffies,
613 .procname = "ip_conntrack_sctp_timeout_cookie_wait",
614 .data = &sctp_timeouts[SCTP_CONNTRACK_COOKIE_WAIT],
615 .maxlen = sizeof(unsigned int),
616 .mode = 0644,
617 .proc_handler = proc_dointvec_jiffies,
620 .procname = "ip_conntrack_sctp_timeout_cookie_echoed",
621 .data = &sctp_timeouts[SCTP_CONNTRACK_COOKIE_ECHOED],
622 .maxlen = sizeof(unsigned int),
623 .mode = 0644,
624 .proc_handler = proc_dointvec_jiffies,
627 .procname = "ip_conntrack_sctp_timeout_established",
628 .data = &sctp_timeouts[SCTP_CONNTRACK_ESTABLISHED],
629 .maxlen = sizeof(unsigned int),
630 .mode = 0644,
631 .proc_handler = proc_dointvec_jiffies,
634 .procname = "ip_conntrack_sctp_timeout_shutdown_sent",
635 .data = &sctp_timeouts[SCTP_CONNTRACK_SHUTDOWN_SENT],
636 .maxlen = sizeof(unsigned int),
637 .mode = 0644,
638 .proc_handler = proc_dointvec_jiffies,
641 .procname = "ip_conntrack_sctp_timeout_shutdown_recd",
642 .data = &sctp_timeouts[SCTP_CONNTRACK_SHUTDOWN_RECD],
643 .maxlen = sizeof(unsigned int),
644 .mode = 0644,
645 .proc_handler = proc_dointvec_jiffies,
648 .procname = "ip_conntrack_sctp_timeout_shutdown_ack_sent",
649 .data = &sctp_timeouts[SCTP_CONNTRACK_SHUTDOWN_ACK_SENT],
650 .maxlen = sizeof(unsigned int),
651 .mode = 0644,
652 .proc_handler = proc_dointvec_jiffies,
655 .ctl_name = 0
658 #endif /* CONFIG_NF_CONNTRACK_PROC_COMPAT */
659 #endif
661 static struct nf_conntrack_l4proto nf_conntrack_l4proto_sctp4 __read_mostly = {
662 .l3proto = PF_INET,
663 .l4proto = IPPROTO_SCTP,
664 .name = "sctp",
665 .pkt_to_tuple = sctp_pkt_to_tuple,
666 .invert_tuple = sctp_invert_tuple,
667 .print_tuple = sctp_print_tuple,
668 .print_conntrack = sctp_print_conntrack,
669 .packet = sctp_packet,
670 .new = sctp_new,
671 .me = THIS_MODULE,
672 #if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE)
673 .to_nlattr = sctp_to_nlattr,
674 .from_nlattr = nlattr_to_sctp,
675 .tuple_to_nlattr = nf_ct_port_tuple_to_nlattr,
676 .nlattr_to_tuple = nf_ct_port_nlattr_to_tuple,
677 .nla_policy = nf_ct_port_nla_policy,
678 #endif
679 #ifdef CONFIG_SYSCTL
680 .ctl_table_users = &sctp_sysctl_table_users,
681 .ctl_table_header = &sctp_sysctl_header,
682 .ctl_table = sctp_sysctl_table,
683 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
684 .ctl_compat_table = sctp_compat_sysctl_table,
685 #endif
686 #endif
689 static struct nf_conntrack_l4proto nf_conntrack_l4proto_sctp6 __read_mostly = {
690 .l3proto = PF_INET6,
691 .l4proto = IPPROTO_SCTP,
692 .name = "sctp",
693 .pkt_to_tuple = sctp_pkt_to_tuple,
694 .invert_tuple = sctp_invert_tuple,
695 .print_tuple = sctp_print_tuple,
696 .print_conntrack = sctp_print_conntrack,
697 .packet = sctp_packet,
698 .new = sctp_new,
699 .me = THIS_MODULE,
700 #if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE)
701 .to_nlattr = sctp_to_nlattr,
702 .from_nlattr = nlattr_to_sctp,
703 .tuple_to_nlattr = nf_ct_port_tuple_to_nlattr,
704 .nlattr_to_tuple = nf_ct_port_nlattr_to_tuple,
705 .nla_policy = nf_ct_port_nla_policy,
706 #endif
707 #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
714 static int __init nf_conntrack_proto_sctp_init(void)
716 int ret;
718 ret = nf_conntrack_l4proto_register(&nf_conntrack_l4proto_sctp4);
719 if (ret) {
720 printk("nf_conntrack_l4proto_sctp4: protocol register failed\n");
721 goto out;
723 ret = nf_conntrack_l4proto_register(&nf_conntrack_l4proto_sctp6);
724 if (ret) {
725 printk("nf_conntrack_l4proto_sctp6: protocol register failed\n");
726 goto cleanup_sctp4;
729 return ret;
731 cleanup_sctp4:
732 nf_conntrack_l4proto_unregister(&nf_conntrack_l4proto_sctp4);
733 out:
734 return ret;
737 static void __exit nf_conntrack_proto_sctp_fini(void)
739 nf_conntrack_l4proto_unregister(&nf_conntrack_l4proto_sctp6);
740 nf_conntrack_l4proto_unregister(&nf_conntrack_l4proto_sctp4);
743 module_init(nf_conntrack_proto_sctp_init);
744 module_exit(nf_conntrack_proto_sctp_fini);
746 MODULE_LICENSE("GPL");
747 MODULE_AUTHOR("Kiran Kumar Immidi");
748 MODULE_DESCRIPTION("Netfilter connection tracking protocol helper for SCTP");
749 MODULE_ALIAS("ip_conntrack_proto_sctp");