a1b95acad297471c0d65973a5a1678ebf648ceb4
[sfrench/cifs-2.6.git] / net / netfilter / nf_conntrack_h323_main.c
1 /*
2  * H.323 connection tracking helper
3  *
4  * Copyright (c) 2006 Jing Min Zhao <zhaojingmin@users.sourceforge.net>
5  *
6  * This source code is licensed under General Public License version 2.
7  *
8  * Based on the 'brute force' H.323 connection tracking module by
9  * Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
10  *
11  * For more information, please see http://nath323.sourceforge.net/
12  */
13
14 #include <linux/module.h>
15 #include <linux/moduleparam.h>
16 #include <linux/ctype.h>
17 #include <linux/inet.h>
18 #include <linux/in.h>
19 #include <linux/ip.h>
20 #include <linux/udp.h>
21 #include <linux/tcp.h>
22 #include <linux/skbuff.h>
23 #include <net/route.h>
24 #include <net/ip6_route.h>
25
26 #include <net/netfilter/nf_conntrack.h>
27 #include <net/netfilter/nf_conntrack_core.h>
28 #include <net/netfilter/nf_conntrack_tuple.h>
29 #include <net/netfilter/nf_conntrack_expect.h>
30 #include <net/netfilter/nf_conntrack_ecache.h>
31 #include <net/netfilter/nf_conntrack_helper.h>
32 #include <linux/netfilter/nf_conntrack_h323.h>
33
34 #if 0
35 #define DEBUGP printk
36 #else
37 #define DEBUGP(format, args...)
38 #endif
39
40 /* Parameters */
41 static unsigned int default_rrq_ttl __read_mostly = 300;
42 module_param(default_rrq_ttl, uint, 0600);
43 MODULE_PARM_DESC(default_rrq_ttl, "use this TTL if it's missing in RRQ");
44
45 static int gkrouted_only __read_mostly = 1;
46 module_param(gkrouted_only, int, 0600);
47 MODULE_PARM_DESC(gkrouted_only, "only accept calls from gatekeeper");
48
49 static int callforward_filter __read_mostly = 1;
50 module_param(callforward_filter, bool, 0600);
51 MODULE_PARM_DESC(callforward_filter, "only create call forwarding expectations "
52                                      "if both endpoints are on different sides "
53                                      "(determined by routing information)");
54
55 /* Hooks for NAT */
56 int (*set_h245_addr_hook) (struct sk_buff **pskb,
57                            unsigned char **data, int dataoff,
58                            H245_TransportAddress *taddr,
59                            union nf_conntrack_address *addr, __be16 port)
60                            __read_mostly;
61 int (*set_h225_addr_hook) (struct sk_buff **pskb,
62                            unsigned char **data, int dataoff,
63                            TransportAddress *taddr,
64                            union nf_conntrack_address *addr, __be16 port)
65                            __read_mostly;
66 int (*set_sig_addr_hook) (struct sk_buff **pskb,
67                           struct nf_conn *ct,
68                           enum ip_conntrack_info ctinfo,
69                           unsigned char **data,
70                           TransportAddress *taddr, int count) __read_mostly;
71 int (*set_ras_addr_hook) (struct sk_buff **pskb,
72                           struct nf_conn *ct,
73                           enum ip_conntrack_info ctinfo,
74                           unsigned char **data,
75                           TransportAddress *taddr, int count) __read_mostly;
76 int (*nat_rtp_rtcp_hook) (struct sk_buff **pskb,
77                           struct nf_conn *ct,
78                           enum ip_conntrack_info ctinfo,
79                           unsigned char **data, int dataoff,
80                           H245_TransportAddress *taddr,
81                           __be16 port, __be16 rtp_port,
82                           struct nf_conntrack_expect *rtp_exp,
83                           struct nf_conntrack_expect *rtcp_exp) __read_mostly;
84 int (*nat_t120_hook) (struct sk_buff **pskb,
85                       struct nf_conn *ct,
86                       enum ip_conntrack_info ctinfo,
87                       unsigned char **data, int dataoff,
88                       H245_TransportAddress *taddr, __be16 port,
89                       struct nf_conntrack_expect *exp) __read_mostly;
90 int (*nat_h245_hook) (struct sk_buff **pskb,
91                       struct nf_conn *ct,
92                       enum ip_conntrack_info ctinfo,
93                       unsigned char **data, int dataoff,
94                       TransportAddress *taddr, __be16 port,
95                       struct nf_conntrack_expect *exp) __read_mostly;
96 int (*nat_callforwarding_hook) (struct sk_buff **pskb,
97                                 struct nf_conn *ct,
98                                 enum ip_conntrack_info ctinfo,
99                                 unsigned char **data, int dataoff,
100                                 TransportAddress *taddr, __be16 port,
101                                 struct nf_conntrack_expect *exp) __read_mostly;
102 int (*nat_q931_hook) (struct sk_buff **pskb,
103                       struct nf_conn *ct,
104                       enum ip_conntrack_info ctinfo,
105                       unsigned char **data, TransportAddress *taddr, int idx,
106                       __be16 port, struct nf_conntrack_expect *exp)
107                       __read_mostly;
108
109 static DEFINE_SPINLOCK(nf_h323_lock);
110 static char *h323_buffer;
111
112 static struct nf_conntrack_helper nf_conntrack_helper_h245;
113 static struct nf_conntrack_helper nf_conntrack_helper_q931[];
114 static struct nf_conntrack_helper nf_conntrack_helper_ras[];
115
116 /****************************************************************************/
117 static int get_tpkt_data(struct sk_buff **pskb, unsigned int protoff,
118                          struct nf_conn *ct, enum ip_conntrack_info ctinfo,
119                          unsigned char **data, int *datalen, int *dataoff)
120 {
121         struct nf_ct_h323_master *info = &nfct_help(ct)->help.ct_h323_info;
122         int dir = CTINFO2DIR(ctinfo);
123         struct tcphdr _tcph, *th;
124         int tcpdatalen;
125         int tcpdataoff;
126         unsigned char *tpkt;
127         int tpktlen;
128         int tpktoff;
129
130         /* Get TCP header */
131         th = skb_header_pointer(*pskb, protoff, sizeof(_tcph), &_tcph);
132         if (th == NULL)
133                 return 0;
134
135         /* Get TCP data offset */
136         tcpdataoff = protoff + th->doff * 4;
137
138         /* Get TCP data length */
139         tcpdatalen = (*pskb)->len - tcpdataoff;
140         if (tcpdatalen <= 0)    /* No TCP data */
141                 goto clear_out;
142
143         if (*data == NULL) {    /* first TPKT */
144                 /* Get first TPKT pointer */
145                 tpkt = skb_header_pointer(*pskb, tcpdataoff, tcpdatalen,
146                                           h323_buffer);
147                 BUG_ON(tpkt == NULL);
148
149                 /* Validate TPKT identifier */
150                 if (tcpdatalen < 4 || tpkt[0] != 0x03 || tpkt[1] != 0) {
151                         /* Netmeeting sends TPKT header and data separately */
152                         if (info->tpkt_len[dir] > 0) {
153                                 DEBUGP("nf_ct_h323: previous packet "
154                                        "indicated separate TPKT data of %hu "
155                                        "bytes\n", info->tpkt_len[dir]);
156                                 if (info->tpkt_len[dir] <= tcpdatalen) {
157                                         /* Yes, there was a TPKT header
158                                          * received */
159                                         *data = tpkt;
160                                         *datalen = info->tpkt_len[dir];
161                                         *dataoff = 0;
162                                         goto out;
163                                 }
164
165                                 /* Fragmented TPKT */
166                                 if (net_ratelimit())
167                                         printk("nf_ct_h323: "
168                                                "fragmented TPKT\n");
169                                 goto clear_out;
170                         }
171
172                         /* It is not even a TPKT */
173                         return 0;
174                 }
175                 tpktoff = 0;
176         } else {                /* Next TPKT */
177                 tpktoff = *dataoff + *datalen;
178                 tcpdatalen -= tpktoff;
179                 if (tcpdatalen <= 4)    /* No more TPKT */
180                         goto clear_out;
181                 tpkt = *data + *datalen;
182
183                 /* Validate TPKT identifier */
184                 if (tpkt[0] != 0x03 || tpkt[1] != 0)
185                         goto clear_out;
186         }
187
188         /* Validate TPKT length */
189         tpktlen = tpkt[2] * 256 + tpkt[3];
190         if (tpktlen < 4)
191                 goto clear_out;
192         if (tpktlen > tcpdatalen) {
193                 if (tcpdatalen == 4) {  /* Separate TPKT header */
194                         /* Netmeeting sends TPKT header and data separately */
195                         DEBUGP("nf_ct_h323: separate TPKT header indicates "
196                                "there will be TPKT data of %hu bytes\n",
197                                tpktlen - 4);
198                         info->tpkt_len[dir] = tpktlen - 4;
199                         return 0;
200                 }
201
202                 if (net_ratelimit())
203                         printk("nf_ct_h323: incomplete TPKT (fragmented?)\n");
204                 goto clear_out;
205         }
206
207         /* This is the encapsulated data */
208         *data = tpkt + 4;
209         *datalen = tpktlen - 4;
210         *dataoff = tpktoff + 4;
211
212       out:
213         /* Clear TPKT length */
214         info->tpkt_len[dir] = 0;
215         return 1;
216
217       clear_out:
218         info->tpkt_len[dir] = 0;
219         return 0;
220 }
221
222 /****************************************************************************/
223 static int get_h245_addr(struct nf_conn *ct, unsigned char *data,
224                          H245_TransportAddress *taddr,
225                          union nf_conntrack_address *addr, __be16 *port)
226 {
227         unsigned char *p;
228         int family = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.l3num;
229         int len;
230
231         if (taddr->choice != eH245_TransportAddress_unicastAddress)
232                 return 0;
233
234         switch (taddr->unicastAddress.choice) {
235         case eUnicastAddress_iPAddress:
236                 if (family != AF_INET)
237                         return 0;
238                 p = data + taddr->unicastAddress.iPAddress.network;
239                 len = 4;
240                 break;
241         case eUnicastAddress_iP6Address:
242                 if (family != AF_INET6)
243                         return 0;
244                 p = data + taddr->unicastAddress.iP6Address.network;
245                 len = 16;
246                 break;
247         default:
248                 return 0;
249         }
250
251         memcpy(addr, p, len);
252         memset((void *)addr + len, 0, sizeof(*addr) - len);
253         memcpy(port, p + len, sizeof(__be16));
254
255         return 1;
256 }
257
258 /****************************************************************************/
259 static int expect_rtp_rtcp(struct sk_buff **pskb, struct nf_conn *ct,
260                            enum ip_conntrack_info ctinfo,
261                            unsigned char **data, int dataoff,
262                            H245_TransportAddress *taddr)
263 {
264         int dir = CTINFO2DIR(ctinfo);
265         int ret = 0;
266         __be16 port;
267         __be16 rtp_port, rtcp_port;
268         union nf_conntrack_address addr;
269         struct nf_conntrack_expect *rtp_exp;
270         struct nf_conntrack_expect *rtcp_exp;
271         typeof(nat_rtp_rtcp_hook) nat_rtp_rtcp;
272
273         /* Read RTP or RTCP address */
274         if (!get_h245_addr(ct, *data, taddr, &addr, &port) ||
275             memcmp(&addr, &ct->tuplehash[dir].tuple.src.u3, sizeof(addr)) ||
276             port == 0)
277                 return 0;
278
279         /* RTP port is even */
280         port &= htons(~1);
281         rtp_port = port;
282         rtcp_port = htons(ntohs(port) + 1);
283
284         /* Create expect for RTP */
285         if ((rtp_exp = nf_conntrack_expect_alloc(ct)) == NULL)
286                 return -1;
287         nf_conntrack_expect_init(rtp_exp, ct->tuplehash[!dir].tuple.src.l3num,
288                                  &ct->tuplehash[!dir].tuple.src.u3,
289                                  &ct->tuplehash[!dir].tuple.dst.u3,
290                                  IPPROTO_UDP, NULL, &rtp_port);
291
292         /* Create expect for RTCP */
293         if ((rtcp_exp = nf_conntrack_expect_alloc(ct)) == NULL) {
294                 nf_conntrack_expect_put(rtp_exp);
295                 return -1;
296         }
297         nf_conntrack_expect_init(rtcp_exp, ct->tuplehash[!dir].tuple.src.l3num,
298                                  &ct->tuplehash[!dir].tuple.src.u3,
299                                  &ct->tuplehash[!dir].tuple.dst.u3,
300                                  IPPROTO_UDP, NULL, &rtcp_port);
301
302         if (memcmp(&ct->tuplehash[dir].tuple.src.u3,
303                    &ct->tuplehash[!dir].tuple.dst.u3,
304                    sizeof(ct->tuplehash[dir].tuple.src.u3)) &&
305                    (nat_rtp_rtcp = rcu_dereference(nat_rtp_rtcp_hook)) &&
306                    ct->status & IPS_NAT_MASK) {
307                 /* NAT needed */
308                 ret = nat_rtp_rtcp(pskb, ct, ctinfo, data, dataoff,
309                                    taddr, port, rtp_port, rtp_exp, rtcp_exp);
310         } else {                /* Conntrack only */
311                 if (nf_conntrack_expect_related(rtp_exp) == 0) {
312                         if (nf_conntrack_expect_related(rtcp_exp) == 0) {
313                                 DEBUGP("nf_ct_h323: expect RTP ");
314                                 NF_CT_DUMP_TUPLE(&rtp_exp->tuple);
315                                 DEBUGP("nf_ct_h323: expect RTCP ");
316                                 NF_CT_DUMP_TUPLE(&rtcp_exp->tuple);
317                         } else {
318                                 nf_conntrack_unexpect_related(rtp_exp);
319                                 ret = -1;
320                         }
321                 } else
322                         ret = -1;
323         }
324
325         nf_conntrack_expect_put(rtp_exp);
326         nf_conntrack_expect_put(rtcp_exp);
327
328         return ret;
329 }
330
331 /****************************************************************************/
332 static int expect_t120(struct sk_buff **pskb,
333                        struct nf_conn *ct,
334                        enum ip_conntrack_info ctinfo,
335                        unsigned char **data, int dataoff,
336                        H245_TransportAddress *taddr)
337 {
338         int dir = CTINFO2DIR(ctinfo);
339         int ret = 0;
340         __be16 port;
341         union nf_conntrack_address addr;
342         struct nf_conntrack_expect *exp;
343         typeof(nat_t120_hook) nat_t120;
344
345         /* Read T.120 address */
346         if (!get_h245_addr(ct, *data, taddr, &addr, &port) ||
347             memcmp(&addr, &ct->tuplehash[dir].tuple.src.u3, sizeof(addr)) ||
348             port == 0)
349                 return 0;
350
351         /* Create expect for T.120 connections */
352         if ((exp = nf_conntrack_expect_alloc(ct)) == NULL)
353                 return -1;
354         nf_conntrack_expect_init(exp, ct->tuplehash[!dir].tuple.src.l3num,
355                                  &ct->tuplehash[!dir].tuple.src.u3,
356                                  &ct->tuplehash[!dir].tuple.dst.u3,
357                                  IPPROTO_TCP, NULL, &port);
358         exp->flags = NF_CT_EXPECT_PERMANENT;    /* Accept multiple channels */
359
360         if (memcmp(&ct->tuplehash[dir].tuple.src.u3,
361                    &ct->tuplehash[!dir].tuple.dst.u3,
362                    sizeof(ct->tuplehash[dir].tuple.src.u3)) &&
363             (nat_t120 = rcu_dereference(nat_t120_hook)) &&
364             ct->status & IPS_NAT_MASK) {
365                 /* NAT needed */
366                 ret = nat_t120(pskb, ct, ctinfo, data, dataoff, taddr,
367                                port, exp);
368         } else {                /* Conntrack only */
369                 if (nf_conntrack_expect_related(exp) == 0) {
370                         DEBUGP("nf_ct_h323: expect T.120 ");
371                         NF_CT_DUMP_TUPLE(&exp->tuple);
372                 } else
373                         ret = -1;
374         }
375
376         nf_conntrack_expect_put(exp);
377
378         return ret;
379 }
380
381 /****************************************************************************/
382 static int process_h245_channel(struct sk_buff **pskb,
383                                 struct nf_conn *ct,
384                                 enum ip_conntrack_info ctinfo,
385                                 unsigned char **data, int dataoff,
386                                 H2250LogicalChannelParameters *channel)
387 {
388         int ret;
389
390         if (channel->options & eH2250LogicalChannelParameters_mediaChannel) {
391                 /* RTP */
392                 ret = expect_rtp_rtcp(pskb, ct, ctinfo, data, dataoff,
393                                       &channel->mediaChannel);
394                 if (ret < 0)
395                         return -1;
396         }
397
398         if (channel->
399             options & eH2250LogicalChannelParameters_mediaControlChannel) {
400                 /* RTCP */
401                 ret = expect_rtp_rtcp(pskb, ct, ctinfo, data, dataoff,
402                                       &channel->mediaControlChannel);
403                 if (ret < 0)
404                         return -1;
405         }
406
407         return 0;
408 }
409
410 /****************************************************************************/
411 static int process_olc(struct sk_buff **pskb, struct nf_conn *ct,
412                        enum ip_conntrack_info ctinfo,
413                        unsigned char **data, int dataoff,
414                        OpenLogicalChannel *olc)
415 {
416         int ret;
417
418         DEBUGP("nf_ct_h323: OpenLogicalChannel\n");
419
420         if (olc->forwardLogicalChannelParameters.multiplexParameters.choice ==
421             eOpenLogicalChannel_forwardLogicalChannelParameters_multiplexParameters_h2250LogicalChannelParameters)
422         {
423                 ret = process_h245_channel(pskb, ct, ctinfo, data, dataoff,
424                                            &olc->
425                                            forwardLogicalChannelParameters.
426                                            multiplexParameters.
427                                            h2250LogicalChannelParameters);
428                 if (ret < 0)
429                         return -1;
430         }
431
432         if ((olc->options &
433              eOpenLogicalChannel_reverseLogicalChannelParameters) &&
434             (olc->reverseLogicalChannelParameters.options &
435              eOpenLogicalChannel_reverseLogicalChannelParameters_multiplexParameters)
436             && (olc->reverseLogicalChannelParameters.multiplexParameters.
437                 choice ==
438                 eOpenLogicalChannel_reverseLogicalChannelParameters_multiplexParameters_h2250LogicalChannelParameters))
439         {
440                 ret =
441                     process_h245_channel(pskb, ct, ctinfo, data, dataoff,
442                                          &olc->
443                                          reverseLogicalChannelParameters.
444                                          multiplexParameters.
445                                          h2250LogicalChannelParameters);
446                 if (ret < 0)
447                         return -1;
448         }
449
450         if ((olc->options & eOpenLogicalChannel_separateStack) &&
451             olc->forwardLogicalChannelParameters.dataType.choice ==
452             eDataType_data &&
453             olc->forwardLogicalChannelParameters.dataType.data.application.
454             choice == eDataApplicationCapability_application_t120 &&
455             olc->forwardLogicalChannelParameters.dataType.data.application.
456             t120.choice == eDataProtocolCapability_separateLANStack &&
457             olc->separateStack.networkAddress.choice ==
458             eNetworkAccessParameters_networkAddress_localAreaAddress) {
459                 ret = expect_t120(pskb, ct, ctinfo, data, dataoff,
460                                   &olc->separateStack.networkAddress.
461                                   localAreaAddress);
462                 if (ret < 0)
463                         return -1;
464         }
465
466         return 0;
467 }
468
469 /****************************************************************************/
470 static int process_olca(struct sk_buff **pskb, struct nf_conn *ct,
471                         enum ip_conntrack_info ctinfo,
472                         unsigned char **data, int dataoff,
473                         OpenLogicalChannelAck *olca)
474 {
475         H2250LogicalChannelAckParameters *ack;
476         int ret;
477
478         DEBUGP("nf_ct_h323: OpenLogicalChannelAck\n");
479
480         if ((olca->options &
481              eOpenLogicalChannelAck_reverseLogicalChannelParameters) &&
482             (olca->reverseLogicalChannelParameters.options &
483              eOpenLogicalChannelAck_reverseLogicalChannelParameters_multiplexParameters)
484             && (olca->reverseLogicalChannelParameters.multiplexParameters.
485                 choice ==
486                 eOpenLogicalChannelAck_reverseLogicalChannelParameters_multiplexParameters_h2250LogicalChannelParameters))
487         {
488                 ret = process_h245_channel(pskb, ct, ctinfo, data, dataoff,
489                                            &olca->
490                                            reverseLogicalChannelParameters.
491                                            multiplexParameters.
492                                            h2250LogicalChannelParameters);
493                 if (ret < 0)
494                         return -1;
495         }
496
497         if ((olca->options &
498              eOpenLogicalChannelAck_forwardMultiplexAckParameters) &&
499             (olca->forwardMultiplexAckParameters.choice ==
500              eOpenLogicalChannelAck_forwardMultiplexAckParameters_h2250LogicalChannelAckParameters))
501         {
502                 ack = &olca->forwardMultiplexAckParameters.
503                     h2250LogicalChannelAckParameters;
504                 if (ack->options &
505                     eH2250LogicalChannelAckParameters_mediaChannel) {
506                         /* RTP */
507                         ret = expect_rtp_rtcp(pskb, ct, ctinfo, data, dataoff,
508                                               &ack->mediaChannel);
509                         if (ret < 0)
510                                 return -1;
511                 }
512
513                 if (ack->options &
514                     eH2250LogicalChannelAckParameters_mediaControlChannel) {
515                         /* RTCP */
516                         ret = expect_rtp_rtcp(pskb, ct, ctinfo, data, dataoff,
517                                               &ack->mediaControlChannel);
518                         if (ret < 0)
519                                 return -1;
520                 }
521         }
522
523         if ((olca->options & eOpenLogicalChannelAck_separateStack) &&
524                 olca->separateStack.networkAddress.choice ==
525                 eNetworkAccessParameters_networkAddress_localAreaAddress) {
526                 ret = expect_t120(pskb, ct, ctinfo, data, dataoff,
527                                   &olca->separateStack.networkAddress.
528                                   localAreaAddress);
529                 if (ret < 0)
530                         return -1;
531         }
532
533         return 0;
534 }
535
536 /****************************************************************************/
537 static int process_h245(struct sk_buff **pskb, struct nf_conn *ct,
538                         enum ip_conntrack_info ctinfo,
539                         unsigned char **data, int dataoff,
540                         MultimediaSystemControlMessage *mscm)
541 {
542         switch (mscm->choice) {
543         case eMultimediaSystemControlMessage_request:
544                 if (mscm->request.choice ==
545                     eRequestMessage_openLogicalChannel) {
546                         return process_olc(pskb, ct, ctinfo, data, dataoff,
547                                            &mscm->request.openLogicalChannel);
548                 }
549                 DEBUGP("nf_ct_h323: H.245 Request %d\n",
550                        mscm->request.choice);
551                 break;
552         case eMultimediaSystemControlMessage_response:
553                 if (mscm->response.choice ==
554                     eResponseMessage_openLogicalChannelAck) {
555                         return process_olca(pskb, ct, ctinfo, data, dataoff,
556                                             &mscm->response.
557                                             openLogicalChannelAck);
558                 }
559                 DEBUGP("nf_ct_h323: H.245 Response %d\n",
560                        mscm->response.choice);
561                 break;
562         default:
563                 DEBUGP("nf_ct_h323: H.245 signal %d\n", mscm->choice);
564                 break;
565         }
566
567         return 0;
568 }
569
570 /****************************************************************************/
571 static int h245_help(struct sk_buff **pskb, unsigned int protoff,
572                      struct nf_conn *ct, enum ip_conntrack_info ctinfo)
573 {
574         static MultimediaSystemControlMessage mscm;
575         unsigned char *data = NULL;
576         int datalen;
577         int dataoff;
578         int ret;
579
580         /* Until there's been traffic both ways, don't look in packets. */
581         if (ctinfo != IP_CT_ESTABLISHED &&
582             ctinfo != IP_CT_ESTABLISHED + IP_CT_IS_REPLY) {
583                 return NF_ACCEPT;
584         }
585         DEBUGP("nf_ct_h245: skblen = %u\n", (*pskb)->len);
586
587         spin_lock_bh(&nf_h323_lock);
588
589         /* Process each TPKT */
590         while (get_tpkt_data(pskb, protoff, ct, ctinfo,
591                              &data, &datalen, &dataoff)) {
592                 DEBUGP("nf_ct_h245: TPKT len=%d ", datalen);
593                 NF_CT_DUMP_TUPLE(&ct->tuplehash[CTINFO2DIR(ctinfo)].tuple);
594
595                 /* Decode H.245 signal */
596                 ret = DecodeMultimediaSystemControlMessage(data, datalen,
597                                                            &mscm);
598                 if (ret < 0) {
599                         if (net_ratelimit())
600                                 printk("nf_ct_h245: decoding error: %s\n",
601                                        ret == H323_ERROR_BOUND ?
602                                        "out of bound" : "out of range");
603                         /* We don't drop when decoding error */
604                         break;
605                 }
606
607                 /* Process H.245 signal */
608                 if (process_h245(pskb, ct, ctinfo, &data, dataoff, &mscm) < 0)
609                         goto drop;
610         }
611
612         spin_unlock_bh(&nf_h323_lock);
613         return NF_ACCEPT;
614
615       drop:
616         spin_unlock_bh(&nf_h323_lock);
617         if (net_ratelimit())
618                 printk("nf_ct_h245: packet dropped\n");
619         return NF_DROP;
620 }
621
622 /****************************************************************************/
623 static struct nf_conntrack_helper nf_conntrack_helper_h245 __read_mostly = {
624         .name                   = "H.245",
625         .me                     = THIS_MODULE,
626         .max_expected           = H323_RTP_CHANNEL_MAX * 4 + 2 /* T.120 */,
627         .timeout                = 240,
628         .tuple.dst.protonum     = IPPROTO_UDP,
629         .mask.src.u.udp.port    = __constant_htons(0xFFFF),
630         .mask.dst.protonum      = 0xFF,
631         .help                   = h245_help
632 };
633
634 /****************************************************************************/
635 int get_h225_addr(struct nf_conn *ct, unsigned char *data,
636                   TransportAddress *taddr,
637                   union nf_conntrack_address *addr, __be16 *port)
638 {
639         unsigned char *p;
640         int family = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.l3num;
641         int len;
642
643         switch (taddr->choice) {
644         case eTransportAddress_ipAddress:
645                 if (family != AF_INET)
646                         return 0;
647                 p = data + taddr->ipAddress.ip;
648                 len = 4;
649                 break;
650         case eTransportAddress_ip6Address:
651                 if (family != AF_INET6)
652                         return 0;
653                 p = data + taddr->ip6Address.ip;
654                 len = 16;
655                 break;
656         default:
657                 return 0;
658         }
659
660         memcpy(addr, p, len);
661         memset((void *)addr + len, 0, sizeof(*addr) - len);
662         memcpy(port, p + len, sizeof(__be16));
663
664         return 1;
665 }
666
667 /****************************************************************************/
668 static int expect_h245(struct sk_buff **pskb, struct nf_conn *ct,
669                        enum ip_conntrack_info ctinfo,
670                        unsigned char **data, int dataoff,
671                        TransportAddress *taddr)
672 {
673         int dir = CTINFO2DIR(ctinfo);
674         int ret = 0;
675         __be16 port;
676         union nf_conntrack_address addr;
677         struct nf_conntrack_expect *exp;
678         typeof(nat_h245_hook) nat_h245;
679
680         /* Read h245Address */
681         if (!get_h225_addr(ct, *data, taddr, &addr, &port) ||
682             memcmp(&addr, &ct->tuplehash[dir].tuple.src.u3, sizeof(addr)) ||
683             port == 0)
684                 return 0;
685
686         /* Create expect for h245 connection */
687         if ((exp = nf_conntrack_expect_alloc(ct)) == NULL)
688                 return -1;
689         nf_conntrack_expect_init(exp, ct->tuplehash[!dir].tuple.src.l3num,
690                                  &ct->tuplehash[!dir].tuple.src.u3,
691                                  &ct->tuplehash[!dir].tuple.dst.u3,
692                                  IPPROTO_TCP, NULL, &port);
693         exp->helper = &nf_conntrack_helper_h245;
694
695         if (memcmp(&ct->tuplehash[dir].tuple.src.u3,
696                    &ct->tuplehash[!dir].tuple.dst.u3,
697                    sizeof(ct->tuplehash[dir].tuple.src.u3)) &&
698             (nat_h245 = rcu_dereference(nat_h245_hook)) &&
699             ct->status & IPS_NAT_MASK) {
700                 /* NAT needed */
701                 ret = nat_h245(pskb, ct, ctinfo, data, dataoff, taddr,
702                                port, exp);
703         } else {                /* Conntrack only */
704                 if (nf_conntrack_expect_related(exp) == 0) {
705                         DEBUGP("nf_ct_q931: expect H.245 ");
706                         NF_CT_DUMP_TUPLE(&exp->tuple);
707                 } else
708                         ret = -1;
709         }
710
711         nf_conntrack_expect_put(exp);
712
713         return ret;
714 }
715
716 /* If the calling party is on the same side of the forward-to party,
717  * we don't need to track the second call */
718 static int callforward_do_filter(union nf_conntrack_address *src,
719                                  union nf_conntrack_address *dst,
720                                  int family)
721 {
722         struct flowi fl1, fl2;
723         int ret = 0;
724
725         memset(&fl1, 0, sizeof(fl1));
726         memset(&fl2, 0, sizeof(fl2));
727
728         switch (family) {
729         case AF_INET: {
730                 struct rtable *rt1, *rt2;
731
732                 fl1.fl4_dst = src->ip;
733                 fl2.fl4_dst = dst->ip;
734                 if (ip_route_output_key(&rt1, &fl1) == 0) {
735                         if (ip_route_output_key(&rt2, &fl2) == 0) {
736                                 if (rt1->rt_gateway == rt2->rt_gateway &&
737                                     rt1->u.dst.dev  == rt2->u.dst.dev)
738                                         ret = 1;
739                                 dst_release(&rt2->u.dst);
740                         }
741                         dst_release(&rt1->u.dst);
742                 }
743                 break;
744         }
745 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
746         case AF_INET6: {
747                 struct rt6_info *rt1, *rt2;
748
749                 memcpy(&fl1.fl6_dst, src, sizeof(fl1.fl6_dst));
750                 memcpy(&fl2.fl6_dst, dst, sizeof(fl2.fl6_dst));
751                 rt1 = (struct rt6_info *)ip6_route_output(NULL, &fl1);
752                 if (rt1) {
753                         rt2 = (struct rt6_info *)ip6_route_output(NULL, &fl2);
754                         if (rt2) {
755                                 if (!memcmp(&rt1->rt6i_gateway, &rt2->rt6i_gateway,
756                                             sizeof(rt1->rt6i_gateway)) &&
757                                     rt1->u.dst.dev == rt2->u.dst.dev)
758                                         ret = 1;
759                                 dst_release(&rt2->u.dst);
760                         }
761                         dst_release(&rt1->u.dst);
762                 }
763                 break;
764         }
765 #endif
766         }
767         return ret;
768
769 }
770
771 /****************************************************************************/
772 static int expect_callforwarding(struct sk_buff **pskb,
773                                  struct nf_conn *ct,
774                                  enum ip_conntrack_info ctinfo,
775                                  unsigned char **data, int dataoff,
776                                  TransportAddress *taddr)
777 {
778         int dir = CTINFO2DIR(ctinfo);
779         int ret = 0;
780         __be16 port;
781         union nf_conntrack_address addr;
782         struct nf_conntrack_expect *exp;
783         typeof(nat_callforwarding_hook) nat_callforwarding;
784
785         /* Read alternativeAddress */
786         if (!get_h225_addr(ct, *data, taddr, &addr, &port) || port == 0)
787                 return 0;
788
789         /* If the calling party is on the same side of the forward-to party,
790          * we don't need to track the second call */
791         if (callforward_filter &&
792             callforward_do_filter(&addr, &ct->tuplehash[!dir].tuple.src.u3,
793                                   ct->tuplehash[!dir].tuple.src.l3num)) {
794                 DEBUGP("nf_ct_q931: Call Forwarding not tracked\n");
795                 return 0;
796         }
797
798         /* Create expect for the second call leg */
799         if ((exp = nf_conntrack_expect_alloc(ct)) == NULL)
800                 return -1;
801         nf_conntrack_expect_init(exp, ct->tuplehash[!dir].tuple.src.l3num,
802                                  &ct->tuplehash[!dir].tuple.src.u3, &addr,
803                                  IPPROTO_TCP, NULL, &port);
804         exp->helper = nf_conntrack_helper_q931;
805
806         if (memcmp(&ct->tuplehash[dir].tuple.src.u3,
807                    &ct->tuplehash[!dir].tuple.dst.u3,
808                    sizeof(ct->tuplehash[dir].tuple.src.u3)) &&
809             (nat_callforwarding = rcu_dereference(nat_callforwarding_hook)) &&
810             ct->status & IPS_NAT_MASK) {
811                 /* Need NAT */
812                 ret = nat_callforwarding(pskb, ct, ctinfo, data, dataoff,
813                                          taddr, port, exp);
814         } else {                /* Conntrack only */
815                 if (nf_conntrack_expect_related(exp) == 0) {
816                         DEBUGP("nf_ct_q931: expect Call Forwarding ");
817                         NF_CT_DUMP_TUPLE(&exp->tuple);
818                 } else
819                         ret = -1;
820         }
821
822         nf_conntrack_expect_put(exp);
823
824         return ret;
825 }
826
827 /****************************************************************************/
828 static int process_setup(struct sk_buff **pskb, struct nf_conn *ct,
829                          enum ip_conntrack_info ctinfo,
830                          unsigned char **data, int dataoff,
831                          Setup_UUIE *setup)
832 {
833         int dir = CTINFO2DIR(ctinfo);
834         int ret;
835         int i;
836         __be16 port;
837         union nf_conntrack_address addr;
838         typeof(set_h225_addr_hook) set_h225_addr;
839
840         DEBUGP("nf_ct_q931: Setup\n");
841
842         if (setup->options & eSetup_UUIE_h245Address) {
843                 ret = expect_h245(pskb, ct, ctinfo, data, dataoff,
844                                   &setup->h245Address);
845                 if (ret < 0)
846                         return -1;
847         }
848
849         set_h225_addr = rcu_dereference(set_h225_addr_hook);
850         if ((setup->options & eSetup_UUIE_destCallSignalAddress) &&
851             (set_h225_addr) && ct->status && IPS_NAT_MASK &&
852             get_h225_addr(ct, *data, &setup->destCallSignalAddress,
853                           &addr, &port) &&
854             memcmp(&addr, &ct->tuplehash[!dir].tuple.src.u3, sizeof(addr))) {
855                 DEBUGP("nf_ct_q931: set destCallSignalAddress "
856                        NIP6_FMT ":%hu->" NIP6_FMT ":%hu\n",
857                        NIP6(*(struct in6_addr *)&addr), ntohs(port),
858                        NIP6(*(struct in6_addr *)&ct->tuplehash[!dir].tuple.src.u3),
859                        ntohs(ct->tuplehash[!dir].tuple.src.u.tcp.port));
860                 ret = set_h225_addr(pskb, data, dataoff,
861                                     &setup->destCallSignalAddress,
862                                     &ct->tuplehash[!dir].tuple.src.u3,
863                                     ct->tuplehash[!dir].tuple.src.u.tcp.port);
864                 if (ret < 0)
865                         return -1;
866         }
867
868         if ((setup->options & eSetup_UUIE_sourceCallSignalAddress) &&
869             (set_h225_addr) && ct->status & IPS_NAT_MASK &&
870             get_h225_addr(ct, *data, &setup->sourceCallSignalAddress,
871                           &addr, &port) &&
872             memcmp(&addr, &ct->tuplehash[!dir].tuple.dst.u3, sizeof(addr))) {
873                 DEBUGP("nf_ct_q931: set sourceCallSignalAddress "
874                        NIP6_FMT ":%hu->" NIP6_FMT ":%hu\n",
875                        NIP6(*(struct in6_addr *)&addr), ntohs(port),
876                        NIP6(*(struct in6_addr *)&ct->tuplehash[!dir].tuple.dst.u3),
877                        ntohs(ct->tuplehash[!dir].tuple.dst.u.tcp.port));
878                 ret = set_h225_addr(pskb, data, dataoff,
879                                     &setup->sourceCallSignalAddress,
880                                     &ct->tuplehash[!dir].tuple.dst.u3,
881                                     ct->tuplehash[!dir].tuple.dst.u.tcp.port);
882                 if (ret < 0)
883                         return -1;
884         }
885
886         if (setup->options & eSetup_UUIE_fastStart) {
887                 for (i = 0; i < setup->fastStart.count; i++) {
888                         ret = process_olc(pskb, ct, ctinfo, data, dataoff,
889                                           &setup->fastStart.item[i]);
890                         if (ret < 0)
891                                 return -1;
892                 }
893         }
894
895         return 0;
896 }
897
898 /****************************************************************************/
899 static int process_callproceeding(struct sk_buff **pskb,
900                                   struct nf_conn *ct,
901                                   enum ip_conntrack_info ctinfo,
902                                   unsigned char **data, int dataoff,
903                                   CallProceeding_UUIE *callproc)
904 {
905         int ret;
906         int i;
907
908         DEBUGP("nf_ct_q931: CallProceeding\n");
909
910         if (callproc->options & eCallProceeding_UUIE_h245Address) {
911                 ret = expect_h245(pskb, ct, ctinfo, data, dataoff,
912                                   &callproc->h245Address);
913                 if (ret < 0)
914                         return -1;
915         }
916
917         if (callproc->options & eCallProceeding_UUIE_fastStart) {
918                 for (i = 0; i < callproc->fastStart.count; i++) {
919                         ret = process_olc(pskb, ct, ctinfo, data, dataoff,
920                                           &callproc->fastStart.item[i]);
921                         if (ret < 0)
922                                 return -1;
923                 }
924         }
925
926         return 0;
927 }
928
929 /****************************************************************************/
930 static int process_connect(struct sk_buff **pskb, struct nf_conn *ct,
931                            enum ip_conntrack_info ctinfo,
932                            unsigned char **data, int dataoff,
933                            Connect_UUIE *connect)
934 {
935         int ret;
936         int i;
937
938         DEBUGP("nf_ct_q931: Connect\n");
939
940         if (connect->options & eConnect_UUIE_h245Address) {
941                 ret = expect_h245(pskb, ct, ctinfo, data, dataoff,
942                                   &connect->h245Address);
943                 if (ret < 0)
944                         return -1;
945         }
946
947         if (connect->options & eConnect_UUIE_fastStart) {
948                 for (i = 0; i < connect->fastStart.count; i++) {
949                         ret = process_olc(pskb, ct, ctinfo, data, dataoff,
950                                           &connect->fastStart.item[i]);
951                         if (ret < 0)
952                                 return -1;
953                 }
954         }
955
956         return 0;
957 }
958
959 /****************************************************************************/
960 static int process_alerting(struct sk_buff **pskb, struct nf_conn *ct,
961                             enum ip_conntrack_info ctinfo,
962                             unsigned char **data, int dataoff,
963                             Alerting_UUIE *alert)
964 {
965         int ret;
966         int i;
967
968         DEBUGP("nf_ct_q931: Alerting\n");
969
970         if (alert->options & eAlerting_UUIE_h245Address) {
971                 ret = expect_h245(pskb, ct, ctinfo, data, dataoff,
972                                   &alert->h245Address);
973                 if (ret < 0)
974                         return -1;
975         }
976
977         if (alert->options & eAlerting_UUIE_fastStart) {
978                 for (i = 0; i < alert->fastStart.count; i++) {
979                         ret = process_olc(pskb, ct, ctinfo, data, dataoff,
980                                           &alert->fastStart.item[i]);
981                         if (ret < 0)
982                                 return -1;
983                 }
984         }
985
986         return 0;
987 }
988
989 /****************************************************************************/
990 static int process_facility(struct sk_buff **pskb, struct nf_conn *ct,
991                             enum ip_conntrack_info ctinfo,
992                             unsigned char **data, int dataoff,
993                             Facility_UUIE *facility)
994 {
995         int ret;
996         int i;
997
998         DEBUGP("nf_ct_q931: Facility\n");
999
1000         if (facility->reason.choice == eFacilityReason_callForwarded) {
1001                 if (facility->options & eFacility_UUIE_alternativeAddress)
1002                         return expect_callforwarding(pskb, ct, ctinfo, data,
1003                                                      dataoff,
1004                                                      &facility->
1005                                                      alternativeAddress);
1006                 return 0;
1007         }
1008
1009         if (facility->options & eFacility_UUIE_h245Address) {
1010                 ret = expect_h245(pskb, ct, ctinfo, data, dataoff,
1011                                   &facility->h245Address);
1012                 if (ret < 0)
1013                         return -1;
1014         }
1015
1016         if (facility->options & eFacility_UUIE_fastStart) {
1017                 for (i = 0; i < facility->fastStart.count; i++) {
1018                         ret = process_olc(pskb, ct, ctinfo, data, dataoff,
1019                                           &facility->fastStart.item[i]);
1020                         if (ret < 0)
1021                                 return -1;
1022                 }
1023         }
1024
1025         return 0;
1026 }
1027
1028 /****************************************************************************/
1029 static int process_progress(struct sk_buff **pskb, struct nf_conn *ct,
1030                             enum ip_conntrack_info ctinfo,
1031                             unsigned char **data, int dataoff,
1032                             Progress_UUIE *progress)
1033 {
1034         int ret;
1035         int i;
1036
1037         DEBUGP("nf_ct_q931: Progress\n");
1038
1039         if (progress->options & eProgress_UUIE_h245Address) {
1040                 ret = expect_h245(pskb, ct, ctinfo, data, dataoff,
1041                                   &progress->h245Address);
1042                 if (ret < 0)
1043                         return -1;
1044         }
1045
1046         if (progress->options & eProgress_UUIE_fastStart) {
1047                 for (i = 0; i < progress->fastStart.count; i++) {
1048                         ret = process_olc(pskb, ct, ctinfo, data, dataoff,
1049                                           &progress->fastStart.item[i]);
1050                         if (ret < 0)
1051                                 return -1;
1052                 }
1053         }
1054
1055         return 0;
1056 }
1057
1058 /****************************************************************************/
1059 static int process_q931(struct sk_buff **pskb, struct nf_conn *ct,
1060                         enum ip_conntrack_info ctinfo,
1061                         unsigned char **data, int dataoff, Q931 *q931)
1062 {
1063         H323_UU_PDU *pdu = &q931->UUIE.h323_uu_pdu;
1064         int i;
1065         int ret = 0;
1066
1067         switch (pdu->h323_message_body.choice) {
1068         case eH323_UU_PDU_h323_message_body_setup:
1069                 ret = process_setup(pskb, ct, ctinfo, data, dataoff,
1070                                     &pdu->h323_message_body.setup);
1071                 break;
1072         case eH323_UU_PDU_h323_message_body_callProceeding:
1073                 ret = process_callproceeding(pskb, ct, ctinfo, data, dataoff,
1074                                              &pdu->h323_message_body.
1075                                              callProceeding);
1076                 break;
1077         case eH323_UU_PDU_h323_message_body_connect:
1078                 ret = process_connect(pskb, ct, ctinfo, data, dataoff,
1079                                       &pdu->h323_message_body.connect);
1080                 break;
1081         case eH323_UU_PDU_h323_message_body_alerting:
1082                 ret = process_alerting(pskb, ct, ctinfo, data, dataoff,
1083                                        &pdu->h323_message_body.alerting);
1084                 break;
1085         case eH323_UU_PDU_h323_message_body_facility:
1086                 ret = process_facility(pskb, ct, ctinfo, data, dataoff,
1087                                        &pdu->h323_message_body.facility);
1088                 break;
1089         case eH323_UU_PDU_h323_message_body_progress:
1090                 ret = process_progress(pskb, ct, ctinfo, data, dataoff,
1091                                        &pdu->h323_message_body.progress);
1092                 break;
1093         default:
1094                 DEBUGP("nf_ct_q931: Q.931 signal %d\n",
1095                        pdu->h323_message_body.choice);
1096                 break;
1097         }
1098
1099         if (ret < 0)
1100                 return -1;
1101
1102         if (pdu->options & eH323_UU_PDU_h245Control) {
1103                 for (i = 0; i < pdu->h245Control.count; i++) {
1104                         ret = process_h245(pskb, ct, ctinfo, data, dataoff,
1105                                            &pdu->h245Control.item[i]);
1106                         if (ret < 0)
1107                                 return -1;
1108                 }
1109         }
1110
1111         return 0;
1112 }
1113
1114 /****************************************************************************/
1115 static int q931_help(struct sk_buff **pskb, unsigned int protoff,
1116                      struct nf_conn *ct, enum ip_conntrack_info ctinfo)
1117 {
1118         static Q931 q931;
1119         unsigned char *data = NULL;
1120         int datalen;
1121         int dataoff;
1122         int ret;
1123
1124         /* Until there's been traffic both ways, don't look in packets. */
1125         if (ctinfo != IP_CT_ESTABLISHED &&
1126             ctinfo != IP_CT_ESTABLISHED + IP_CT_IS_REPLY) {
1127                 return NF_ACCEPT;
1128         }
1129         DEBUGP("nf_ct_q931: skblen = %u\n", (*pskb)->len);
1130
1131         spin_lock_bh(&nf_h323_lock);
1132
1133         /* Process each TPKT */
1134         while (get_tpkt_data(pskb, protoff, ct, ctinfo,
1135                              &data, &datalen, &dataoff)) {
1136                 DEBUGP("nf_ct_q931: TPKT len=%d ", datalen);
1137                 NF_CT_DUMP_TUPLE(&ct->tuplehash[CTINFO2DIR(ctinfo)].tuple);
1138
1139                 /* Decode Q.931 signal */
1140                 ret = DecodeQ931(data, datalen, &q931);
1141                 if (ret < 0) {
1142                         if (net_ratelimit())
1143                                 printk("nf_ct_q931: decoding error: %s\n",
1144                                        ret == H323_ERROR_BOUND ?
1145                                        "out of bound" : "out of range");
1146                         /* We don't drop when decoding error */
1147                         break;
1148                 }
1149
1150                 /* Process Q.931 signal */
1151                 if (process_q931(pskb, ct, ctinfo, &data, dataoff, &q931) < 0)
1152                         goto drop;
1153         }
1154
1155         spin_unlock_bh(&nf_h323_lock);
1156         return NF_ACCEPT;
1157
1158       drop:
1159         spin_unlock_bh(&nf_h323_lock);
1160         if (net_ratelimit())
1161                 printk("nf_ct_q931: packet dropped\n");
1162         return NF_DROP;
1163 }
1164
1165 /****************************************************************************/
1166 static struct nf_conntrack_helper nf_conntrack_helper_q931[] __read_mostly = {
1167         {
1168                 .name                   = "Q.931",
1169                 .me                     = THIS_MODULE,
1170                                           /* T.120 and H.245 */
1171                 .max_expected           = H323_RTP_CHANNEL_MAX * 4 + 4,
1172                 .timeout                = 240,
1173                 .tuple.src.l3num        = AF_INET,
1174                 .tuple.src.u.tcp.port   = __constant_htons(Q931_PORT),
1175                 .tuple.dst.protonum     = IPPROTO_TCP,
1176                 .mask.src.l3num         = 0xFFFF,
1177                 .mask.src.u.tcp.port    = __constant_htons(0xFFFF),
1178                 .mask.dst.protonum      = 0xFF,
1179                 .help                   = q931_help
1180         },
1181         {
1182                 .name                   = "Q.931",
1183                 .me                     = THIS_MODULE,
1184                                           /* T.120 and H.245 */
1185                 .max_expected           = H323_RTP_CHANNEL_MAX * 4 + 4,
1186                 .timeout                = 240,
1187                 .tuple.src.l3num        = AF_INET6,
1188                 .tuple.src.u.tcp.port   = __constant_htons(Q931_PORT),
1189                 .tuple.dst.protonum     = IPPROTO_TCP,
1190                 .mask.src.l3num         = 0xFFFF,
1191                 .mask.src.u.tcp.port    = __constant_htons(0xFFFF),
1192                 .mask.dst.protonum      = 0xFF,
1193                 .help                   = q931_help
1194         },
1195 };
1196
1197 /****************************************************************************/
1198 static unsigned char *get_udp_data(struct sk_buff **pskb, unsigned int protoff,
1199                                    int *datalen)
1200 {
1201         struct udphdr _uh, *uh;
1202         int dataoff;
1203
1204         uh = skb_header_pointer(*pskb, protoff, sizeof(_uh), &_uh);
1205         if (uh == NULL)
1206                 return NULL;
1207         dataoff = protoff + sizeof(_uh);
1208         if (dataoff >= (*pskb)->len)
1209                 return NULL;
1210         *datalen = (*pskb)->len - dataoff;
1211         return skb_header_pointer(*pskb, dataoff, *datalen, h323_buffer);
1212 }
1213
1214 /****************************************************************************/
1215 static struct nf_conntrack_expect *find_expect(struct nf_conn *ct,
1216                                                union nf_conntrack_address *addr,
1217                                                __be16 port)
1218 {
1219         struct nf_conntrack_expect *exp;
1220         struct nf_conntrack_tuple tuple;
1221
1222         memset(&tuple.src.u3, 0, sizeof(tuple.src.u3));
1223         tuple.src.u.tcp.port = 0;
1224         memcpy(&tuple.dst.u3, addr, sizeof(tuple.dst.u3));
1225         tuple.dst.u.tcp.port = port;
1226         tuple.dst.protonum = IPPROTO_TCP;
1227
1228         exp = __nf_conntrack_expect_find(&tuple);
1229         if (exp && exp->master == ct)
1230                 return exp;
1231         return NULL;
1232 }
1233
1234 /****************************************************************************/
1235 static int set_expect_timeout(struct nf_conntrack_expect *exp,
1236                               unsigned timeout)
1237 {
1238         if (!exp || !del_timer(&exp->timeout))
1239                 return 0;
1240
1241         exp->timeout.expires = jiffies + timeout * HZ;
1242         add_timer(&exp->timeout);
1243
1244         return 1;
1245 }
1246
1247 /****************************************************************************/
1248 static int expect_q931(struct sk_buff **pskb, struct nf_conn *ct,
1249                        enum ip_conntrack_info ctinfo,
1250                        unsigned char **data,
1251                        TransportAddress *taddr, int count)
1252 {
1253         struct nf_ct_h323_master *info = &nfct_help(ct)->help.ct_h323_info;
1254         int dir = CTINFO2DIR(ctinfo);
1255         int ret = 0;
1256         int i;
1257         __be16 port;
1258         union nf_conntrack_address addr;
1259         struct nf_conntrack_expect *exp;
1260         typeof(nat_q931_hook) nat_q931;
1261
1262         /* Look for the first related address */
1263         for (i = 0; i < count; i++) {
1264                 if (get_h225_addr(ct, *data, &taddr[i], &addr, &port) &&
1265                     memcmp(&addr, &ct->tuplehash[dir].tuple.src.u3,
1266                            sizeof(addr)) == 0 && port != 0)
1267                         break;
1268         }
1269
1270         if (i >= count)         /* Not found */
1271                 return 0;
1272
1273         /* Create expect for Q.931 */
1274         if ((exp = nf_conntrack_expect_alloc(ct)) == NULL)
1275                 return -1;
1276         nf_conntrack_expect_init(exp, ct->tuplehash[!dir].tuple.src.l3num,
1277                                  gkrouted_only ? /* only accept calls from GK? */
1278                                         &ct->tuplehash[!dir].tuple.src.u3 :
1279                                         NULL,
1280                                  &ct->tuplehash[!dir].tuple.dst.u3,
1281                                  IPPROTO_TCP, NULL, &port);
1282         exp->helper = nf_conntrack_helper_q931;
1283         exp->flags = NF_CT_EXPECT_PERMANENT;    /* Accept multiple calls */
1284
1285         nat_q931 = rcu_dereference(nat_q931_hook);
1286         if (nat_q931 && ct->status & IPS_NAT_MASK) {    /* Need NAT */
1287                 ret = nat_q931(pskb, ct, ctinfo, data, taddr, i, port, exp);
1288         } else {                /* Conntrack only */
1289                 if (nf_conntrack_expect_related(exp) == 0) {
1290                         DEBUGP("nf_ct_ras: expect Q.931 ");
1291                         NF_CT_DUMP_TUPLE(&exp->tuple);
1292
1293                         /* Save port for looking up expect in processing RCF */
1294                         info->sig_port[dir] = port;
1295                 } else
1296                         ret = -1;
1297         }
1298
1299         nf_conntrack_expect_put(exp);
1300
1301         return ret;
1302 }
1303
1304 /****************************************************************************/
1305 static int process_grq(struct sk_buff **pskb, struct nf_conn *ct,
1306                        enum ip_conntrack_info ctinfo,
1307                        unsigned char **data, GatekeeperRequest *grq)
1308 {
1309         typeof(set_ras_addr_hook) set_ras_addr;
1310
1311         DEBUGP("nf_ct_ras: GRQ\n");
1312
1313         set_ras_addr = rcu_dereference(set_ras_addr_hook);
1314         if (set_ras_addr && ct->status & IPS_NAT_MASK)  /* NATed */
1315                 return set_ras_addr(pskb, ct, ctinfo, data,
1316                                     &grq->rasAddress, 1);
1317         return 0;
1318 }
1319
1320 /****************************************************************************/
1321 static int process_gcf(struct sk_buff **pskb, struct nf_conn *ct,
1322                        enum ip_conntrack_info ctinfo,
1323                        unsigned char **data, GatekeeperConfirm *gcf)
1324 {
1325         int dir = CTINFO2DIR(ctinfo);
1326         int ret = 0;
1327         __be16 port;
1328         union nf_conntrack_address addr;
1329         struct nf_conntrack_expect *exp;
1330
1331         DEBUGP("nf_ct_ras: GCF\n");
1332
1333         if (!get_h225_addr(ct, *data, &gcf->rasAddress, &addr, &port))
1334                 return 0;
1335
1336         /* Registration port is the same as discovery port */
1337         if (!memcmp(&addr, &ct->tuplehash[dir].tuple.src.u3, sizeof(addr)) &&
1338             port == ct->tuplehash[dir].tuple.src.u.udp.port)
1339                 return 0;
1340
1341         /* Avoid RAS expectation loops. A GCF is never expected. */
1342         if (test_bit(IPS_EXPECTED_BIT, &ct->status))
1343                 return 0;
1344
1345         /* Need new expect */
1346         if ((exp = nf_conntrack_expect_alloc(ct)) == NULL)
1347                 return -1;
1348         nf_conntrack_expect_init(exp, ct->tuplehash[!dir].tuple.src.l3num,
1349                                  &ct->tuplehash[!dir].tuple.src.u3, &addr,
1350                                  IPPROTO_UDP, NULL, &port);
1351         exp->helper = nf_conntrack_helper_ras;
1352
1353         if (nf_conntrack_expect_related(exp) == 0) {
1354                 DEBUGP("nf_ct_ras: expect RAS ");
1355                 NF_CT_DUMP_TUPLE(&exp->tuple);
1356         } else
1357                 ret = -1;
1358
1359         nf_conntrack_expect_put(exp);
1360
1361         return ret;
1362 }
1363
1364 /****************************************************************************/
1365 static int process_rrq(struct sk_buff **pskb, struct nf_conn *ct,
1366                        enum ip_conntrack_info ctinfo,
1367                        unsigned char **data, RegistrationRequest *rrq)
1368 {
1369         struct nf_ct_h323_master *info = &nfct_help(ct)->help.ct_h323_info;
1370         int ret;
1371         typeof(set_ras_addr_hook) set_ras_addr;
1372
1373         DEBUGP("nf_ct_ras: RRQ\n");
1374
1375         ret = expect_q931(pskb, ct, ctinfo, data,
1376                           rrq->callSignalAddress.item,
1377                           rrq->callSignalAddress.count);
1378         if (ret < 0)
1379                 return -1;
1380
1381         set_ras_addr = rcu_dereference(set_ras_addr_hook);
1382         if (set_ras_addr && ct->status & IPS_NAT_MASK) {
1383                 ret = set_ras_addr(pskb, ct, ctinfo, data,
1384                                    rrq->rasAddress.item,
1385                                    rrq->rasAddress.count);
1386                 if (ret < 0)
1387                         return -1;
1388         }
1389
1390         if (rrq->options & eRegistrationRequest_timeToLive) {
1391                 DEBUGP("nf_ct_ras: RRQ TTL = %u seconds\n", rrq->timeToLive);
1392                 info->timeout = rrq->timeToLive;
1393         } else
1394                 info->timeout = default_rrq_ttl;
1395
1396         return 0;
1397 }
1398
1399 /****************************************************************************/
1400 static int process_rcf(struct sk_buff **pskb, struct nf_conn *ct,
1401                        enum ip_conntrack_info ctinfo,
1402                        unsigned char **data, RegistrationConfirm *rcf)
1403 {
1404         struct nf_ct_h323_master *info = &nfct_help(ct)->help.ct_h323_info;
1405         int dir = CTINFO2DIR(ctinfo);
1406         int ret;
1407         struct nf_conntrack_expect *exp;
1408         typeof(set_sig_addr_hook) set_sig_addr;
1409
1410         DEBUGP("nf_ct_ras: RCF\n");
1411
1412         set_sig_addr = rcu_dereference(set_sig_addr_hook);
1413         if (set_sig_addr && ct->status & IPS_NAT_MASK) {
1414                 ret = set_sig_addr(pskb, ct, ctinfo, data,
1415                                         rcf->callSignalAddress.item,
1416                                         rcf->callSignalAddress.count);
1417                 if (ret < 0)
1418                         return -1;
1419         }
1420
1421         if (rcf->options & eRegistrationConfirm_timeToLive) {
1422                 DEBUGP("nf_ct_ras: RCF TTL = %u seconds\n", rcf->timeToLive);
1423                 info->timeout = rcf->timeToLive;
1424         }
1425
1426         if (info->timeout > 0) {
1427                 DEBUGP
1428                     ("nf_ct_ras: set RAS connection timeout to %u seconds\n",
1429                      info->timeout);
1430                 nf_ct_refresh(ct, *pskb, info->timeout * HZ);
1431
1432                 /* Set expect timeout */
1433                 read_lock_bh(&nf_conntrack_lock);
1434                 exp = find_expect(ct, &ct->tuplehash[dir].tuple.dst.u3,
1435                                   info->sig_port[!dir]);
1436                 if (exp) {
1437                         DEBUGP("nf_ct_ras: set Q.931 expect "
1438                                "timeout to %u seconds for",
1439                                info->timeout);
1440                         NF_CT_DUMP_TUPLE(&exp->tuple);
1441                         set_expect_timeout(exp, info->timeout);
1442                 }
1443                 read_unlock_bh(&nf_conntrack_lock);
1444         }
1445
1446         return 0;
1447 }
1448
1449 /****************************************************************************/
1450 static int process_urq(struct sk_buff **pskb, struct nf_conn *ct,
1451                        enum ip_conntrack_info ctinfo,
1452                        unsigned char **data, UnregistrationRequest *urq)
1453 {
1454         struct nf_ct_h323_master *info = &nfct_help(ct)->help.ct_h323_info;
1455         int dir = CTINFO2DIR(ctinfo);
1456         int ret;
1457         typeof(set_sig_addr_hook) set_sig_addr;
1458
1459         DEBUGP("nf_ct_ras: URQ\n");
1460
1461         set_sig_addr = rcu_dereference(set_sig_addr_hook);
1462         if (set_sig_addr && ct->status & IPS_NAT_MASK) {
1463                 ret = set_sig_addr(pskb, ct, ctinfo, data,
1464                                    urq->callSignalAddress.item,
1465                                    urq->callSignalAddress.count);
1466                 if (ret < 0)
1467                         return -1;
1468         }
1469
1470         /* Clear old expect */
1471         nf_ct_remove_expectations(ct);
1472         info->sig_port[dir] = 0;
1473         info->sig_port[!dir] = 0;
1474
1475         /* Give it 30 seconds for UCF or URJ */
1476         nf_ct_refresh(ct, *pskb, 30 * HZ);
1477
1478         return 0;
1479 }
1480
1481 /****************************************************************************/
1482 static int process_arq(struct sk_buff **pskb, struct nf_conn *ct,
1483                        enum ip_conntrack_info ctinfo,
1484                        unsigned char **data, AdmissionRequest *arq)
1485 {
1486         struct nf_ct_h323_master *info = &nfct_help(ct)->help.ct_h323_info;
1487         int dir = CTINFO2DIR(ctinfo);
1488         __be16 port;
1489         union nf_conntrack_address addr;
1490         typeof(set_h225_addr_hook) set_h225_addr;
1491
1492         DEBUGP("nf_ct_ras: ARQ\n");
1493
1494         set_h225_addr = rcu_dereference(set_h225_addr_hook);
1495         if ((arq->options & eAdmissionRequest_destCallSignalAddress) &&
1496             get_h225_addr(ct, *data, &arq->destCallSignalAddress,
1497                           &addr, &port) &&
1498             !memcmp(&addr, &ct->tuplehash[dir].tuple.src.u3, sizeof(addr)) &&
1499             port == info->sig_port[dir] &&
1500             set_h225_addr && ct->status & IPS_NAT_MASK) {
1501                 /* Answering ARQ */
1502                 return set_h225_addr(pskb, data, 0,
1503                                      &arq->destCallSignalAddress,
1504                                      &ct->tuplehash[!dir].tuple.dst.u3,
1505                                      info->sig_port[!dir]);
1506         }
1507
1508         if ((arq->options & eAdmissionRequest_srcCallSignalAddress) &&
1509             get_h225_addr(ct, *data, &arq->srcCallSignalAddress,
1510                           &addr, &port) &&
1511             !memcmp(&addr, &ct->tuplehash[dir].tuple.src.u3, sizeof(addr)) &&
1512             set_h225_addr && ct->status & IPS_NAT_MASK) {
1513                 /* Calling ARQ */
1514                 return set_h225_addr(pskb, data, 0,
1515                                      &arq->srcCallSignalAddress,
1516                                      &ct->tuplehash[!dir].tuple.dst.u3,
1517                                      port);
1518         }
1519
1520         return 0;
1521 }
1522
1523 /****************************************************************************/
1524 static int process_acf(struct sk_buff **pskb, struct nf_conn *ct,
1525                        enum ip_conntrack_info ctinfo,
1526                        unsigned char **data, AdmissionConfirm *acf)
1527 {
1528         int dir = CTINFO2DIR(ctinfo);
1529         int ret = 0;
1530         __be16 port;
1531         union nf_conntrack_address addr;
1532         struct nf_conntrack_expect *exp;
1533         typeof(set_sig_addr_hook) set_sig_addr;
1534
1535         DEBUGP("nf_ct_ras: ACF\n");
1536
1537         if (!get_h225_addr(ct, *data, &acf->destCallSignalAddress,
1538                            &addr, &port))
1539                 return 0;
1540
1541         if (!memcmp(&addr, &ct->tuplehash[dir].tuple.dst.u3, sizeof(addr))) {
1542                 /* Answering ACF */
1543                 set_sig_addr = rcu_dereference(set_sig_addr_hook);
1544                 if (set_sig_addr && ct->status & IPS_NAT_MASK)
1545                         return set_sig_addr(pskb, ct, ctinfo, data,
1546                                             &acf->destCallSignalAddress, 1);
1547                 return 0;
1548         }
1549
1550         /* Need new expect */
1551         if ((exp = nf_conntrack_expect_alloc(ct)) == NULL)
1552                 return -1;
1553         nf_conntrack_expect_init(exp, ct->tuplehash[!dir].tuple.src.l3num,
1554                                  &ct->tuplehash[!dir].tuple.src.u3, &addr,
1555                                  IPPROTO_TCP, NULL, &port);
1556         exp->flags = NF_CT_EXPECT_PERMANENT;
1557         exp->helper = nf_conntrack_helper_q931;
1558
1559         if (nf_conntrack_expect_related(exp) == 0) {
1560                 DEBUGP("nf_ct_ras: expect Q.931 ");
1561                 NF_CT_DUMP_TUPLE(&exp->tuple);
1562         } else
1563                 ret = -1;
1564
1565         nf_conntrack_expect_put(exp);
1566
1567         return ret;
1568 }
1569
1570 /****************************************************************************/
1571 static int process_lrq(struct sk_buff **pskb, struct nf_conn *ct,
1572                        enum ip_conntrack_info ctinfo,
1573                        unsigned char **data, LocationRequest *lrq)
1574 {
1575         typeof(set_ras_addr_hook) set_ras_addr;
1576
1577         DEBUGP("nf_ct_ras: LRQ\n");
1578
1579         set_ras_addr = rcu_dereference(set_ras_addr_hook);
1580         if (set_ras_addr && ct->status & IPS_NAT_MASK)
1581                 return set_ras_addr(pskb, ct, ctinfo, data,
1582                                     &lrq->replyAddress, 1);
1583         return 0;
1584 }
1585
1586 /****************************************************************************/
1587 static int process_lcf(struct sk_buff **pskb, struct nf_conn *ct,
1588                        enum ip_conntrack_info ctinfo,
1589                        unsigned char **data, LocationConfirm *lcf)
1590 {
1591         int dir = CTINFO2DIR(ctinfo);
1592         int ret = 0;
1593         __be16 port;
1594         union nf_conntrack_address addr;
1595         struct nf_conntrack_expect *exp;
1596
1597         DEBUGP("nf_ct_ras: LCF\n");
1598
1599         if (!get_h225_addr(ct, *data, &lcf->callSignalAddress,
1600                            &addr, &port))
1601                 return 0;
1602
1603         /* Need new expect for call signal */
1604         if ((exp = nf_conntrack_expect_alloc(ct)) == NULL)
1605                 return -1;
1606         nf_conntrack_expect_init(exp, ct->tuplehash[!dir].tuple.src.l3num,
1607                                  &ct->tuplehash[!dir].tuple.src.u3, &addr,
1608                                  IPPROTO_TCP, NULL, &port);
1609         exp->flags = NF_CT_EXPECT_PERMANENT;
1610         exp->helper = nf_conntrack_helper_q931;
1611
1612         if (nf_conntrack_expect_related(exp) == 0) {
1613                 DEBUGP("nf_ct_ras: expect Q.931 ");
1614                 NF_CT_DUMP_TUPLE(&exp->tuple);
1615         } else
1616                 ret = -1;
1617
1618         nf_conntrack_expect_put(exp);
1619
1620         /* Ignore rasAddress */
1621
1622         return ret;
1623 }
1624
1625 /****************************************************************************/
1626 static int process_irr(struct sk_buff **pskb, struct nf_conn *ct,
1627                        enum ip_conntrack_info ctinfo,
1628                        unsigned char **data, InfoRequestResponse *irr)
1629 {
1630         int ret;
1631         typeof(set_ras_addr_hook) set_ras_addr;
1632         typeof(set_sig_addr_hook) set_sig_addr;
1633
1634         DEBUGP("nf_ct_ras: IRR\n");
1635
1636         set_ras_addr = rcu_dereference(set_ras_addr_hook);
1637         if (set_ras_addr && ct->status & IPS_NAT_MASK) {
1638                 ret = set_ras_addr(pskb, ct, ctinfo, data,
1639                                    &irr->rasAddress, 1);
1640                 if (ret < 0)
1641                         return -1;
1642         }
1643
1644         set_sig_addr = rcu_dereference(set_sig_addr_hook);
1645         if (set_sig_addr && ct->status & IPS_NAT_MASK) {
1646                 ret = set_sig_addr(pskb, ct, ctinfo, data,
1647                                         irr->callSignalAddress.item,
1648                                         irr->callSignalAddress.count);
1649                 if (ret < 0)
1650                         return -1;
1651         }
1652
1653         return 0;
1654 }
1655
1656 /****************************************************************************/
1657 static int process_ras(struct sk_buff **pskb, struct nf_conn *ct,
1658                        enum ip_conntrack_info ctinfo,
1659                        unsigned char **data, RasMessage *ras)
1660 {
1661         switch (ras->choice) {
1662         case eRasMessage_gatekeeperRequest:
1663                 return process_grq(pskb, ct, ctinfo, data,
1664                                    &ras->gatekeeperRequest);
1665         case eRasMessage_gatekeeperConfirm:
1666                 return process_gcf(pskb, ct, ctinfo, data,
1667                                    &ras->gatekeeperConfirm);
1668         case eRasMessage_registrationRequest:
1669                 return process_rrq(pskb, ct, ctinfo, data,
1670                                    &ras->registrationRequest);
1671         case eRasMessage_registrationConfirm:
1672                 return process_rcf(pskb, ct, ctinfo, data,
1673                                    &ras->registrationConfirm);
1674         case eRasMessage_unregistrationRequest:
1675                 return process_urq(pskb, ct, ctinfo, data,
1676                                    &ras->unregistrationRequest);
1677         case eRasMessage_admissionRequest:
1678                 return process_arq(pskb, ct, ctinfo, data,
1679                                    &ras->admissionRequest);
1680         case eRasMessage_admissionConfirm:
1681                 return process_acf(pskb, ct, ctinfo, data,
1682                                    &ras->admissionConfirm);
1683         case eRasMessage_locationRequest:
1684                 return process_lrq(pskb, ct, ctinfo, data,
1685                                    &ras->locationRequest);
1686         case eRasMessage_locationConfirm:
1687                 return process_lcf(pskb, ct, ctinfo, data,
1688                                    &ras->locationConfirm);
1689         case eRasMessage_infoRequestResponse:
1690                 return process_irr(pskb, ct, ctinfo, data,
1691                                    &ras->infoRequestResponse);
1692         default:
1693                 DEBUGP("nf_ct_ras: RAS message %d\n", ras->choice);
1694                 break;
1695         }
1696
1697         return 0;
1698 }
1699
1700 /****************************************************************************/
1701 static int ras_help(struct sk_buff **pskb, unsigned int protoff,
1702                     struct nf_conn *ct, enum ip_conntrack_info ctinfo)
1703 {
1704         static RasMessage ras;
1705         unsigned char *data;
1706         int datalen = 0;
1707         int ret;
1708
1709         DEBUGP("nf_ct_ras: skblen = %u\n", (*pskb)->len);
1710
1711         spin_lock_bh(&nf_h323_lock);
1712
1713         /* Get UDP data */
1714         data = get_udp_data(pskb, protoff, &datalen);
1715         if (data == NULL)
1716                 goto accept;
1717         DEBUGP("nf_ct_ras: RAS message len=%d ", datalen);
1718         NF_CT_DUMP_TUPLE(&ct->tuplehash[CTINFO2DIR(ctinfo)].tuple);
1719
1720         /* Decode RAS message */
1721         ret = DecodeRasMessage(data, datalen, &ras);
1722         if (ret < 0) {
1723                 if (net_ratelimit())
1724                         printk("nf_ct_ras: decoding error: %s\n",
1725                                ret == H323_ERROR_BOUND ?
1726                                "out of bound" : "out of range");
1727                 goto accept;
1728         }
1729
1730         /* Process RAS message */
1731         if (process_ras(pskb, ct, ctinfo, &data, &ras) < 0)
1732                 goto drop;
1733
1734       accept:
1735         spin_unlock_bh(&nf_h323_lock);
1736         return NF_ACCEPT;
1737
1738       drop:
1739         spin_unlock_bh(&nf_h323_lock);
1740         if (net_ratelimit())
1741                 printk("nf_ct_ras: packet dropped\n");
1742         return NF_DROP;
1743 }
1744
1745 /****************************************************************************/
1746 static struct nf_conntrack_helper nf_conntrack_helper_ras[] __read_mostly = {
1747         {
1748                 .name                   = "RAS",
1749                 .me                     = THIS_MODULE,
1750                 .max_expected           = 32,
1751                 .timeout                = 240,
1752                 .tuple.src.l3num        = AF_INET,
1753                 .tuple.src.u.udp.port   = __constant_htons(RAS_PORT),
1754                 .tuple.dst.protonum     = IPPROTO_UDP,
1755                 .mask.src.l3num         = 0xFFFF,
1756                 .mask.src.u.udp.port    = __constant_htons(0xFFFF),
1757                 .mask.dst.protonum      = 0xFF,
1758                 .help                   = ras_help,
1759         },
1760         {
1761                 .name                   = "RAS",
1762                 .me                     = THIS_MODULE,
1763                 .max_expected           = 32,
1764                 .timeout                = 240,
1765                 .tuple.src.l3num        = AF_INET6,
1766                 .tuple.src.u.udp.port   = __constant_htons(RAS_PORT),
1767                 .tuple.dst.protonum     = IPPROTO_UDP,
1768                 .mask.src.l3num         = 0xFFFF,
1769                 .mask.src.u.udp.port    = __constant_htons(0xFFFF),
1770                 .mask.dst.protonum      = 0xFF,
1771                 .help                   = ras_help,
1772         },
1773 };
1774
1775 /****************************************************************************/
1776 static void __exit nf_conntrack_h323_fini(void)
1777 {
1778         nf_conntrack_helper_unregister(&nf_conntrack_helper_ras[1]);
1779         nf_conntrack_helper_unregister(&nf_conntrack_helper_ras[0]);
1780         nf_conntrack_helper_unregister(&nf_conntrack_helper_q931[1]);
1781         nf_conntrack_helper_unregister(&nf_conntrack_helper_q931[0]);
1782         kfree(h323_buffer);
1783         DEBUGP("nf_ct_h323: fini\n");
1784 }
1785
1786 /****************************************************************************/
1787 static int __init nf_conntrack_h323_init(void)
1788 {
1789         int ret;
1790
1791         h323_buffer = kmalloc(65536, GFP_KERNEL);
1792         if (!h323_buffer)
1793                 return -ENOMEM;
1794         ret = nf_conntrack_helper_register(&nf_conntrack_helper_q931[0]);
1795         if (ret < 0)
1796                 goto err1;
1797         ret = nf_conntrack_helper_register(&nf_conntrack_helper_q931[1]);
1798         if (ret < 0)
1799                 goto err2;
1800         ret = nf_conntrack_helper_register(&nf_conntrack_helper_ras[0]);
1801         if (ret < 0)
1802                 goto err3;
1803         ret = nf_conntrack_helper_register(&nf_conntrack_helper_ras[1]);
1804         if (ret < 0)
1805                 goto err4;
1806         DEBUGP("nf_ct_h323: init success\n");
1807         return 0;
1808
1809 err4:
1810         nf_conntrack_helper_unregister(&nf_conntrack_helper_ras[0]);
1811 err3:
1812         nf_conntrack_helper_unregister(&nf_conntrack_helper_q931[1]);
1813 err2:
1814         nf_conntrack_helper_unregister(&nf_conntrack_helper_q931[0]);
1815 err1:
1816         return ret;
1817 }
1818
1819 /****************************************************************************/
1820 module_init(nf_conntrack_h323_init);
1821 module_exit(nf_conntrack_h323_fini);
1822
1823 EXPORT_SYMBOL_GPL(get_h225_addr);
1824 EXPORT_SYMBOL_GPL(set_h245_addr_hook);
1825 EXPORT_SYMBOL_GPL(set_h225_addr_hook);
1826 EXPORT_SYMBOL_GPL(set_sig_addr_hook);
1827 EXPORT_SYMBOL_GPL(set_ras_addr_hook);
1828 EXPORT_SYMBOL_GPL(nat_rtp_rtcp_hook);
1829 EXPORT_SYMBOL_GPL(nat_t120_hook);
1830 EXPORT_SYMBOL_GPL(nat_h245_hook);
1831 EXPORT_SYMBOL_GPL(nat_callforwarding_hook);
1832 EXPORT_SYMBOL_GPL(nat_q931_hook);
1833
1834 MODULE_AUTHOR("Jing Min Zhao <zhaojingmin@users.sourceforge.net>");
1835 MODULE_DESCRIPTION("H.323 connection tracking helper");
1836 MODULE_LICENSE("GPL");
1837 MODULE_ALIAS("ip_conntrack_h323");