Merge git://oss.sgi.com:8090/xfs/xfs-2.6
[linux-drm-fsl-dcu.git] / net / ipv4 / netfilter / ip_conntrack_proto_sctp.c
1 /*
2  * Connection tracking protocol helper module for SCTP.
3  *
4  * SCTP is defined in RFC 2960. References to various sections in this code
5  * are to this RFC.
6  *
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.
10  */
11
12 /*
13  * Added support for proc manipulation of timeouts.
14  */
15
16 #include <linux/types.h>
17 #include <linux/sched.h>
18 #include <linux/timer.h>
19 #include <linux/interrupt.h>
20 #include <linux/netfilter.h>
21 #include <linux/module.h>
22 #include <linux/in.h>
23 #include <linux/ip.h>
24 #include <linux/sctp.h>
25 #include <linux/string.h>
26 #include <linux/seq_file.h>
27
28 #include <linux/netfilter_ipv4/ip_conntrack.h>
29 #include <linux/netfilter_ipv4/ip_conntrack_protocol.h>
30
31 #if 0
32 #define DEBUGP(format, ...) printk(format, ## __VA_ARGS__)
33 #else
34 #define DEBUGP(format, args...)
35 #endif
36
37 /* Protects conntrack->proto.sctp */
38 static DEFINE_RWLOCK(sctp_lock);
39
40 /* FIXME: Examine ipfilter's timeouts and conntrack transitions more
41    closely.  They're more complex. --RR
42
43    And so for me for SCTP :D -Kiran */
44
45 static const char *sctp_conntrack_names[] = {
46         "NONE",
47         "CLOSED",
48         "COOKIE_WAIT",
49         "COOKIE_ECHOED",
50         "ESTABLISHED",
51         "SHUTDOWN_SENT",
52         "SHUTDOWN_RECD",
53         "SHUTDOWN_ACK_SENT",
54 };
55
56 #define SECS  * HZ
57 #define MINS  * 60 SECS
58 #define HOURS * 60 MINS
59 #define DAYS  * 24 HOURS
60
61 static unsigned int ip_ct_sctp_timeout_closed __read_mostly           = 10 SECS;
62 static unsigned int ip_ct_sctp_timeout_cookie_wait __read_mostly      =  3 SECS;
63 static unsigned int ip_ct_sctp_timeout_cookie_echoed __read_mostly    =  3 SECS;
64 static unsigned int ip_ct_sctp_timeout_established __read_mostly      =  5 DAYS;
65 static unsigned int ip_ct_sctp_timeout_shutdown_sent __read_mostly    = 300 SECS / 1000;
66 static unsigned int ip_ct_sctp_timeout_shutdown_recd __read_mostly    = 300 SECS / 1000;
67 static unsigned int ip_ct_sctp_timeout_shutdown_ack_sent __read_mostly = 3 SECS;
68
69 static const unsigned int * sctp_timeouts[]
70 = { NULL,                                  /* SCTP_CONNTRACK_NONE  */
71     &ip_ct_sctp_timeout_closed,            /* SCTP_CONNTRACK_CLOSED */
72     &ip_ct_sctp_timeout_cookie_wait,       /* SCTP_CONNTRACK_COOKIE_WAIT */
73     &ip_ct_sctp_timeout_cookie_echoed,     /* SCTP_CONNTRACK_COOKIE_ECHOED */
74     &ip_ct_sctp_timeout_established,       /* SCTP_CONNTRACK_ESTABLISHED */
75     &ip_ct_sctp_timeout_shutdown_sent,     /* SCTP_CONNTRACK_SHUTDOWN_SENT */
76     &ip_ct_sctp_timeout_shutdown_recd,     /* SCTP_CONNTRACK_SHUTDOWN_RECD */
77     &ip_ct_sctp_timeout_shutdown_ack_sent  /* SCTP_CONNTRACK_SHUTDOWN_ACK_SENT */
78  };
79
80 #define sNO SCTP_CONNTRACK_NONE
81 #define sCL SCTP_CONNTRACK_CLOSED
82 #define sCW SCTP_CONNTRACK_COOKIE_WAIT
83 #define sCE SCTP_CONNTRACK_COOKIE_ECHOED
84 #define sES SCTP_CONNTRACK_ESTABLISHED
85 #define sSS SCTP_CONNTRACK_SHUTDOWN_SENT
86 #define sSR SCTP_CONNTRACK_SHUTDOWN_RECD
87 #define sSA SCTP_CONNTRACK_SHUTDOWN_ACK_SENT
88 #define sIV SCTP_CONNTRACK_MAX
89
90 /*
91         These are the descriptions of the states:
92
93 NOTE: These state names are tantalizingly similar to the states of an
94 SCTP endpoint. But the interpretation of the states is a little different,
95 considering that these are the states of the connection and not of an end
96 point. Please note the subtleties. -Kiran
97
98 NONE              - Nothing so far.
99 COOKIE WAIT       - We have seen an INIT chunk in the original direction, or also
100                     an INIT_ACK chunk in the reply direction.
101 COOKIE ECHOED     - We have seen a COOKIE_ECHO chunk in the original direction.
102 ESTABLISHED       - We have seen a COOKIE_ACK in the reply direction.
103 SHUTDOWN_SENT     - We have seen a SHUTDOWN chunk in the original direction.
104 SHUTDOWN_RECD     - We have seen a SHUTDOWN chunk in the reply directoin.
105 SHUTDOWN_ACK_SENT - We have seen a SHUTDOWN_ACK chunk in the direction opposite
106                     to that of the SHUTDOWN chunk.
107 CLOSED            - We have seen a SHUTDOWN_COMPLETE chunk in the direction of
108                     the SHUTDOWN chunk. Connection is closed.
109 */
110
111 /* TODO
112  - I have assumed that the first INIT is in the original direction.
113  This messes things when an INIT comes in the reply direction in CLOSED
114  state.
115  - Check the error type in the reply dir before transitioning from
116 cookie echoed to closed.
117  - Sec 5.2.4 of RFC 2960
118  - Multi Homing support.
119 */
120
121 /* SCTP conntrack state transitions */
122 static const enum sctp_conntrack sctp_conntracks[2][9][SCTP_CONNTRACK_MAX] = {
123         {
124 /*      ORIGINAL        */
125 /*                  sNO, sCL, sCW, sCE, sES, sSS, sSR, sSA */
126 /* init         */ {sCW, sCW, sCW, sCE, sES, sSS, sSR, sSA},
127 /* init_ack     */ {sCL, sCL, sCW, sCE, sES, sSS, sSR, sSA},
128 /* abort        */ {sCL, sCL, sCL, sCL, sCL, sCL, sCL, sCL},
129 /* shutdown     */ {sCL, sCL, sCW, sCE, sSS, sSS, sSR, sSA},
130 /* shutdown_ack */ {sSA, sCL, sCW, sCE, sES, sSA, sSA, sSA},
131 /* error        */ {sCL, sCL, sCW, sCE, sES, sSS, sSR, sSA},/* Cant have Stale cookie*/
132 /* cookie_echo  */ {sCL, sCL, sCE, sCE, sES, sSS, sSR, sSA},/* 5.2.4 - Big TODO */
133 /* cookie_ack   */ {sCL, sCL, sCW, sCE, sES, sSS, sSR, sSA},/* Cant come in orig dir */
134 /* shutdown_comp*/ {sCL, sCL, sCW, sCE, sES, sSS, sSR, sCL}
135         },
136         {
137 /*      REPLY   */
138 /*                  sNO, sCL, sCW, sCE, sES, sSS, sSR, sSA */
139 /* init         */ {sIV, sCL, sCW, sCE, sES, sSS, sSR, sSA},/* INIT in sCL Big TODO */
140 /* init_ack     */ {sIV, sCL, sCW, sCE, sES, sSS, sSR, sSA},
141 /* abort        */ {sIV, sCL, sCL, sCL, sCL, sCL, sCL, sCL},
142 /* shutdown     */ {sIV, sCL, sCW, sCE, sSR, sSS, sSR, sSA},
143 /* shutdown_ack */ {sIV, sCL, sCW, sCE, sES, sSA, sSA, sSA},
144 /* error        */ {sIV, sCL, sCW, sCL, sES, sSS, sSR, sSA},
145 /* cookie_echo  */ {sIV, sCL, sCW, sCE, sES, sSS, sSR, sSA},/* Cant come in reply dir */
146 /* cookie_ack   */ {sIV, sCL, sCW, sES, sES, sSS, sSR, sSA},
147 /* shutdown_comp*/ {sIV, sCL, sCW, sCE, sES, sSS, sSR, sCL}
148         }
149 };
150
151 static int sctp_pkt_to_tuple(const struct sk_buff *skb,
152                              unsigned int dataoff,
153                              struct ip_conntrack_tuple *tuple)
154 {
155         sctp_sctphdr_t _hdr, *hp;
156
157         DEBUGP(__FUNCTION__);
158         DEBUGP("\n");
159
160         /* Actually only need first 8 bytes. */
161         hp = skb_header_pointer(skb, dataoff, 8, &_hdr);
162         if (hp == NULL)
163                 return 0;
164
165         tuple->src.u.sctp.port = hp->source;
166         tuple->dst.u.sctp.port = hp->dest;
167         return 1;
168 }
169
170 static int sctp_invert_tuple(struct ip_conntrack_tuple *tuple,
171                              const struct ip_conntrack_tuple *orig)
172 {
173         DEBUGP(__FUNCTION__);
174         DEBUGP("\n");
175
176         tuple->src.u.sctp.port = orig->dst.u.sctp.port;
177         tuple->dst.u.sctp.port = orig->src.u.sctp.port;
178         return 1;
179 }
180
181 /* Print out the per-protocol part of the tuple. */
182 static int sctp_print_tuple(struct seq_file *s,
183                             const struct ip_conntrack_tuple *tuple)
184 {
185         DEBUGP(__FUNCTION__);
186         DEBUGP("\n");
187
188         return seq_printf(s, "sport=%hu dport=%hu ",
189                           ntohs(tuple->src.u.sctp.port),
190                           ntohs(tuple->dst.u.sctp.port));
191 }
192
193 /* Print out the private part of the conntrack. */
194 static int sctp_print_conntrack(struct seq_file *s,
195                                 const struct ip_conntrack *conntrack)
196 {
197         enum sctp_conntrack state;
198
199         DEBUGP(__FUNCTION__);
200         DEBUGP("\n");
201
202         read_lock_bh(&sctp_lock);
203         state = conntrack->proto.sctp.state;
204         read_unlock_bh(&sctp_lock);
205
206         return seq_printf(s, "%s ", sctp_conntrack_names[state]);
207 }
208
209 #define for_each_sctp_chunk(skb, sch, _sch, offset, count)              \
210 for (offset = skb->nh.iph->ihl * 4 + sizeof(sctp_sctphdr_t), count = 0; \
211         offset < skb->len &&                                            \
212         (sch = skb_header_pointer(skb, offset, sizeof(_sch), &_sch));   \
213         offset += (ntohs(sch->length) + 3) & ~3, count++)
214
215 /* Some validity checks to make sure the chunks are fine */
216 static int do_basic_checks(struct ip_conntrack *conntrack,
217                            const struct sk_buff *skb,
218                            char *map)
219 {
220         u_int32_t offset, count;
221         sctp_chunkhdr_t _sch, *sch;
222         int flag;
223
224         DEBUGP(__FUNCTION__);
225         DEBUGP("\n");
226
227         flag = 0;
228
229         for_each_sctp_chunk (skb, sch, _sch, offset, count) {
230                 DEBUGP("Chunk Num: %d  Type: %d\n", count, sch->type);
231
232                 if (sch->type == SCTP_CID_INIT
233                         || sch->type == SCTP_CID_INIT_ACK
234                         || sch->type == SCTP_CID_SHUTDOWN_COMPLETE) {
235                         flag = 1;
236                 }
237
238                 /*
239                  * Cookie Ack/Echo chunks not the first OR
240                  * Init / Init Ack / Shutdown compl chunks not the only chunks
241                  * OR zero-length.
242                  */
243                 if (((sch->type == SCTP_CID_COOKIE_ACK
244                         || sch->type == SCTP_CID_COOKIE_ECHO
245                         || flag)
246                       && count !=0) || !sch->length) {
247                         DEBUGP("Basic checks failed\n");
248                         return 1;
249                 }
250
251                 if (map) {
252                         set_bit(sch->type, (void *)map);
253                 }
254         }
255
256         DEBUGP("Basic checks passed\n");
257         return count == 0;
258 }
259
260 static int new_state(enum ip_conntrack_dir dir,
261                      enum sctp_conntrack cur_state,
262                      int chunk_type)
263 {
264         int i;
265
266         DEBUGP(__FUNCTION__);
267         DEBUGP("\n");
268
269         DEBUGP("Chunk type: %d\n", chunk_type);
270
271         switch (chunk_type) {
272                 case SCTP_CID_INIT:
273                         DEBUGP("SCTP_CID_INIT\n");
274                         i = 0; break;
275                 case SCTP_CID_INIT_ACK:
276                         DEBUGP("SCTP_CID_INIT_ACK\n");
277                         i = 1; break;
278                 case SCTP_CID_ABORT:
279                         DEBUGP("SCTP_CID_ABORT\n");
280                         i = 2; break;
281                 case SCTP_CID_SHUTDOWN:
282                         DEBUGP("SCTP_CID_SHUTDOWN\n");
283                         i = 3; break;
284                 case SCTP_CID_SHUTDOWN_ACK:
285                         DEBUGP("SCTP_CID_SHUTDOWN_ACK\n");
286                         i = 4; break;
287                 case SCTP_CID_ERROR:
288                         DEBUGP("SCTP_CID_ERROR\n");
289                         i = 5; break;
290                 case SCTP_CID_COOKIE_ECHO:
291                         DEBUGP("SCTP_CID_COOKIE_ECHO\n");
292                         i = 6; break;
293                 case SCTP_CID_COOKIE_ACK:
294                         DEBUGP("SCTP_CID_COOKIE_ACK\n");
295                         i = 7; break;
296                 case SCTP_CID_SHUTDOWN_COMPLETE:
297                         DEBUGP("SCTP_CID_SHUTDOWN_COMPLETE\n");
298                         i = 8; break;
299                 default:
300                         /* Other chunks like DATA, SACK, HEARTBEAT and
301                         its ACK do not cause a change in state */
302                         DEBUGP("Unknown chunk type, Will stay in %s\n",
303                                                 sctp_conntrack_names[cur_state]);
304                         return cur_state;
305         }
306
307         DEBUGP("dir: %d   cur_state: %s  chunk_type: %d  new_state: %s\n",
308                         dir, sctp_conntrack_names[cur_state], chunk_type,
309                         sctp_conntrack_names[sctp_conntracks[dir][i][cur_state]]);
310
311         return sctp_conntracks[dir][i][cur_state];
312 }
313
314 /* Returns verdict for packet, or -1 for invalid. */
315 static int sctp_packet(struct ip_conntrack *conntrack,
316                        const struct sk_buff *skb,
317                        enum ip_conntrack_info ctinfo)
318 {
319         enum sctp_conntrack newconntrack, oldsctpstate;
320         struct iphdr *iph = skb->nh.iph;
321         sctp_sctphdr_t _sctph, *sh;
322         sctp_chunkhdr_t _sch, *sch;
323         u_int32_t offset, count;
324         char map[256 / sizeof (char)] = {0};
325
326         DEBUGP(__FUNCTION__);
327         DEBUGP("\n");
328
329         sh = skb_header_pointer(skb, iph->ihl * 4, sizeof(_sctph), &_sctph);
330         if (sh == NULL)
331                 return -1;
332
333         if (do_basic_checks(conntrack, skb, map) != 0)
334                 return -1;
335
336         /* Check the verification tag (Sec 8.5) */
337         if (!test_bit(SCTP_CID_INIT, (void *)map)
338                 && !test_bit(SCTP_CID_SHUTDOWN_COMPLETE, (void *)map)
339                 && !test_bit(SCTP_CID_COOKIE_ECHO, (void *)map)
340                 && !test_bit(SCTP_CID_ABORT, (void *)map)
341                 && !test_bit(SCTP_CID_SHUTDOWN_ACK, (void *)map)
342                 && (sh->vtag != conntrack->proto.sctp.vtag[CTINFO2DIR(ctinfo)])) {
343                 DEBUGP("Verification tag check failed\n");
344                 return -1;
345         }
346
347         oldsctpstate = newconntrack = SCTP_CONNTRACK_MAX;
348         for_each_sctp_chunk (skb, sch, _sch, offset, count) {
349                 write_lock_bh(&sctp_lock);
350
351                 /* Special cases of Verification tag check (Sec 8.5.1) */
352                 if (sch->type == SCTP_CID_INIT) {
353                         /* Sec 8.5.1 (A) */
354                         if (sh->vtag != 0) {
355                                 write_unlock_bh(&sctp_lock);
356                                 return -1;
357                         }
358                 } else if (sch->type == SCTP_CID_ABORT) {
359                         /* Sec 8.5.1 (B) */
360                         if (!(sh->vtag == conntrack->proto.sctp.vtag[CTINFO2DIR(ctinfo)])
361                                 && !(sh->vtag == conntrack->proto.sctp.vtag
362                                                         [1 - CTINFO2DIR(ctinfo)])) {
363                                 write_unlock_bh(&sctp_lock);
364                                 return -1;
365                         }
366                 } else if (sch->type == SCTP_CID_SHUTDOWN_COMPLETE) {
367                         /* Sec 8.5.1 (C) */
368                         if (!(sh->vtag == conntrack->proto.sctp.vtag[CTINFO2DIR(ctinfo)])
369                                 && !(sh->vtag == conntrack->proto.sctp.vtag
370                                                         [1 - CTINFO2DIR(ctinfo)]
371                                         && (sch->flags & 1))) {
372                                 write_unlock_bh(&sctp_lock);
373                                 return -1;
374                         }
375                 } else if (sch->type == SCTP_CID_COOKIE_ECHO) {
376                         /* Sec 8.5.1 (D) */
377                         if (!(sh->vtag == conntrack->proto.sctp.vtag[CTINFO2DIR(ctinfo)])) {
378                                 write_unlock_bh(&sctp_lock);
379                                 return -1;
380                         }
381                 }
382
383                 oldsctpstate = conntrack->proto.sctp.state;
384                 newconntrack = new_state(CTINFO2DIR(ctinfo), oldsctpstate, sch->type);
385
386                 /* Invalid */
387                 if (newconntrack == SCTP_CONNTRACK_MAX) {
388                         DEBUGP("ip_conntrack_sctp: Invalid dir=%i ctype=%u conntrack=%u\n",
389                                CTINFO2DIR(ctinfo), sch->type, oldsctpstate);
390                         write_unlock_bh(&sctp_lock);
391                         return -1;
392                 }
393
394                 /* If it is an INIT or an INIT ACK note down the vtag */
395                 if (sch->type == SCTP_CID_INIT
396                         || sch->type == SCTP_CID_INIT_ACK) {
397                         sctp_inithdr_t _inithdr, *ih;
398
399                         ih = skb_header_pointer(skb, offset + sizeof(sctp_chunkhdr_t),
400                                                 sizeof(_inithdr), &_inithdr);
401                         if (ih == NULL) {
402                                         write_unlock_bh(&sctp_lock);
403                                         return -1;
404                         }
405                         DEBUGP("Setting vtag %x for dir %d\n",
406                                         ih->init_tag, !CTINFO2DIR(ctinfo));
407                         conntrack->proto.sctp.vtag[!CTINFO2DIR(ctinfo)] = ih->init_tag;
408                 }
409
410                 conntrack->proto.sctp.state = newconntrack;
411                 if (oldsctpstate != newconntrack)
412                         ip_conntrack_event_cache(IPCT_PROTOINFO, skb);
413                 write_unlock_bh(&sctp_lock);
414         }
415
416         ip_ct_refresh_acct(conntrack, ctinfo, skb, *sctp_timeouts[newconntrack]);
417
418         if (oldsctpstate == SCTP_CONNTRACK_COOKIE_ECHOED
419                 && CTINFO2DIR(ctinfo) == IP_CT_DIR_REPLY
420                 && newconntrack == SCTP_CONNTRACK_ESTABLISHED) {
421                 DEBUGP("Setting assured bit\n");
422                 set_bit(IPS_ASSURED_BIT, &conntrack->status);
423                 ip_conntrack_event_cache(IPCT_STATUS, skb);
424         }
425
426         return NF_ACCEPT;
427 }
428
429 /* Called when a new connection for this protocol found. */
430 static int sctp_new(struct ip_conntrack *conntrack,
431                     const struct sk_buff *skb)
432 {
433         enum sctp_conntrack newconntrack;
434         struct iphdr *iph = skb->nh.iph;
435         sctp_sctphdr_t _sctph, *sh;
436         sctp_chunkhdr_t _sch, *sch;
437         u_int32_t offset, count;
438         char map[256 / sizeof (char)] = {0};
439
440         DEBUGP(__FUNCTION__);
441         DEBUGP("\n");
442
443         sh = skb_header_pointer(skb, iph->ihl * 4, sizeof(_sctph), &_sctph);
444         if (sh == NULL)
445                 return 0;
446
447         if (do_basic_checks(conntrack, skb, map) != 0)
448                 return 0;
449
450         /* If an OOTB packet has any of these chunks discard (Sec 8.4) */
451         if ((test_bit (SCTP_CID_ABORT, (void *)map))
452                 || (test_bit (SCTP_CID_SHUTDOWN_COMPLETE, (void *)map))
453                 || (test_bit (SCTP_CID_COOKIE_ACK, (void *)map))) {
454                 return 0;
455         }
456
457         newconntrack = SCTP_CONNTRACK_MAX;
458         for_each_sctp_chunk (skb, sch, _sch, offset, count) {
459                 /* Don't need lock here: this conntrack not in circulation yet */
460                 newconntrack = new_state (IP_CT_DIR_ORIGINAL,
461                                                 SCTP_CONNTRACK_NONE, sch->type);
462
463                 /* Invalid: delete conntrack */
464                 if (newconntrack == SCTP_CONNTRACK_MAX) {
465                         DEBUGP("ip_conntrack_sctp: invalid new deleting.\n");
466                         return 0;
467                 }
468
469                 /* Copy the vtag into the state info */
470                 if (sch->type == SCTP_CID_INIT) {
471                         if (sh->vtag == 0) {
472                                 sctp_inithdr_t _inithdr, *ih;
473
474                                 ih = skb_header_pointer(skb, offset + sizeof(sctp_chunkhdr_t),
475                                                         sizeof(_inithdr), &_inithdr);
476                                 if (ih == NULL)
477                                         return 0;
478
479                                 DEBUGP("Setting vtag %x for new conn\n",
480                                         ih->init_tag);
481
482                                 conntrack->proto.sctp.vtag[IP_CT_DIR_REPLY] =
483                                                                 ih->init_tag;
484                         } else {
485                                 /* Sec 8.5.1 (A) */
486                                 return 0;
487                         }
488                 }
489                 /* If it is a shutdown ack OOTB packet, we expect a return
490                    shutdown complete, otherwise an ABORT Sec 8.4 (5) and (8) */
491                 else {
492                         DEBUGP("Setting vtag %x for new conn OOTB\n",
493                                 sh->vtag);
494                         conntrack->proto.sctp.vtag[IP_CT_DIR_REPLY] = sh->vtag;
495                 }
496
497                 conntrack->proto.sctp.state = newconntrack;
498         }
499
500         return 1;
501 }
502
503 static struct ip_conntrack_protocol ip_conntrack_protocol_sctp = {
504         .proto           = IPPROTO_SCTP,
505         .name            = "sctp",
506         .pkt_to_tuple    = sctp_pkt_to_tuple,
507         .invert_tuple    = sctp_invert_tuple,
508         .print_tuple     = sctp_print_tuple,
509         .print_conntrack = sctp_print_conntrack,
510         .packet          = sctp_packet,
511         .new             = sctp_new,
512         .destroy         = NULL,
513         .me              = THIS_MODULE,
514 #if defined(CONFIG_IP_NF_CONNTRACK_NETLINK) || \
515     defined(CONFIG_IP_NF_CONNTRACK_NETLINK_MODULE)
516         .tuple_to_nfattr = ip_ct_port_tuple_to_nfattr,
517         .nfattr_to_tuple = ip_ct_port_nfattr_to_tuple,
518 #endif
519 };
520
521 #ifdef CONFIG_SYSCTL
522 static ctl_table ip_ct_sysctl_table[] = {
523         {
524                 .ctl_name       = NET_IPV4_NF_CONNTRACK_SCTP_TIMEOUT_CLOSED,
525                 .procname       = "ip_conntrack_sctp_timeout_closed",
526                 .data           = &ip_ct_sctp_timeout_closed,
527                 .maxlen         = sizeof(unsigned int),
528                 .mode           = 0644,
529                 .proc_handler   = &proc_dointvec_jiffies,
530         },
531         {
532                 .ctl_name       = NET_IPV4_NF_CONNTRACK_SCTP_TIMEOUT_COOKIE_WAIT,
533                 .procname       = "ip_conntrack_sctp_timeout_cookie_wait",
534                 .data           = &ip_ct_sctp_timeout_cookie_wait,
535                 .maxlen         = sizeof(unsigned int),
536                 .mode           = 0644,
537                 .proc_handler   = &proc_dointvec_jiffies,
538         },
539         {
540                 .ctl_name       = NET_IPV4_NF_CONNTRACK_SCTP_TIMEOUT_COOKIE_ECHOED,
541                 .procname       = "ip_conntrack_sctp_timeout_cookie_echoed",
542                 .data           = &ip_ct_sctp_timeout_cookie_echoed,
543                 .maxlen         = sizeof(unsigned int),
544                 .mode           = 0644,
545                 .proc_handler   = &proc_dointvec_jiffies,
546         },
547         {
548                 .ctl_name       = NET_IPV4_NF_CONNTRACK_SCTP_TIMEOUT_ESTABLISHED,
549                 .procname       = "ip_conntrack_sctp_timeout_established",
550                 .data           = &ip_ct_sctp_timeout_established,
551                 .maxlen         = sizeof(unsigned int),
552                 .mode           = 0644,
553                 .proc_handler   = &proc_dointvec_jiffies,
554         },
555         {
556                 .ctl_name       = NET_IPV4_NF_CONNTRACK_SCTP_TIMEOUT_SHUTDOWN_SENT,
557                 .procname       = "ip_conntrack_sctp_timeout_shutdown_sent",
558                 .data           = &ip_ct_sctp_timeout_shutdown_sent,
559                 .maxlen         = sizeof(unsigned int),
560                 .mode           = 0644,
561                 .proc_handler   = &proc_dointvec_jiffies,
562         },
563         {
564                 .ctl_name       = NET_IPV4_NF_CONNTRACK_SCTP_TIMEOUT_SHUTDOWN_RECD,
565                 .procname       = "ip_conntrack_sctp_timeout_shutdown_recd",
566                 .data           = &ip_ct_sctp_timeout_shutdown_recd,
567                 .maxlen         = sizeof(unsigned int),
568                 .mode           = 0644,
569                 .proc_handler   = &proc_dointvec_jiffies,
570         },
571         {
572                 .ctl_name       = NET_IPV4_NF_CONNTRACK_SCTP_TIMEOUT_SHUTDOWN_ACK_SENT,
573                 .procname       = "ip_conntrack_sctp_timeout_shutdown_ack_sent",
574                 .data           = &ip_ct_sctp_timeout_shutdown_ack_sent,
575                 .maxlen         = sizeof(unsigned int),
576                 .mode           = 0644,
577                 .proc_handler   = &proc_dointvec_jiffies,
578         },
579         { .ctl_name = 0 }
580 };
581
582 static ctl_table ip_ct_netfilter_table[] = {
583         {
584                 .ctl_name       = NET_IPV4_NETFILTER,
585                 .procname       = "netfilter",
586                 .mode           = 0555,
587                 .child          = ip_ct_sysctl_table,
588         },
589         { .ctl_name = 0 }
590 };
591
592 static ctl_table ip_ct_ipv4_table[] = {
593         {
594                 .ctl_name       = NET_IPV4,
595                 .procname       = "ipv4",
596                 .mode           = 0555,
597                 .child          = ip_ct_netfilter_table,
598         },
599         { .ctl_name = 0 }
600 };
601
602 static ctl_table ip_ct_net_table[] = {
603         {
604                 .ctl_name       = CTL_NET,
605                 .procname       = "net",
606                 .mode           = 0555,
607                 .child          = ip_ct_ipv4_table,
608         },
609         { .ctl_name = 0 }
610 };
611
612 static struct ctl_table_header *ip_ct_sysctl_header;
613 #endif
614
615 static int __init ip_conntrack_proto_sctp_init(void)
616 {
617         int ret;
618
619         ret = ip_conntrack_protocol_register(&ip_conntrack_protocol_sctp);
620         if (ret) {
621                 printk("ip_conntrack_proto_sctp: protocol register failed\n");
622                 goto out;
623         }
624
625 #ifdef CONFIG_SYSCTL
626         ip_ct_sysctl_header = register_sysctl_table(ip_ct_net_table, 0);
627         if (ip_ct_sysctl_header == NULL) {
628                 ret = -ENOMEM;
629                 printk("ip_conntrack_proto_sctp: can't register to sysctl.\n");
630                 goto cleanup;
631         }
632 #endif
633
634         return ret;
635
636 #ifdef CONFIG_SYSCTL
637  cleanup:
638         ip_conntrack_protocol_unregister(&ip_conntrack_protocol_sctp);
639 #endif
640  out:
641         DEBUGP("SCTP conntrack module loading %s\n",
642                                         ret ? "failed": "succeeded");
643         return ret;
644 }
645
646 static void __exit ip_conntrack_proto_sctp_fini(void)
647 {
648         ip_conntrack_protocol_unregister(&ip_conntrack_protocol_sctp);
649 #ifdef CONFIG_SYSCTL
650         unregister_sysctl_table(ip_ct_sysctl_header);
651 #endif
652         DEBUGP("SCTP conntrack module unloaded\n");
653 }
654
655 module_init(ip_conntrack_proto_sctp_init);
656 module_exit(ip_conntrack_proto_sctp_fini);
657
658 MODULE_LICENSE("GPL");
659 MODULE_AUTHOR("Kiran Kumar Immidi");
660 MODULE_DESCRIPTION("Netfilter connection tracking protocol helper for SCTP");