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