]> err.no Git - linux-2.6/blob - net/netfilter/nf_conntrack_h323_main.c
[NETFILTER]: nf_conntrack_h323: remove unnecessary process of Information signal
[linux-2.6] / 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         return 0;
524 }
525
526 /****************************************************************************/
527 static int process_h245(struct sk_buff **pskb, struct nf_conn *ct,
528                         enum ip_conntrack_info ctinfo,
529                         unsigned char **data, int dataoff,
530                         MultimediaSystemControlMessage *mscm)
531 {
532         switch (mscm->choice) {
533         case eMultimediaSystemControlMessage_request:
534                 if (mscm->request.choice ==
535                     eRequestMessage_openLogicalChannel) {
536                         return process_olc(pskb, ct, ctinfo, data, dataoff,
537                                            &mscm->request.openLogicalChannel);
538                 }
539                 DEBUGP("nf_ct_h323: H.245 Request %d\n",
540                        mscm->request.choice);
541                 break;
542         case eMultimediaSystemControlMessage_response:
543                 if (mscm->response.choice ==
544                     eResponseMessage_openLogicalChannelAck) {
545                         return process_olca(pskb, ct, ctinfo, data, dataoff,
546                                             &mscm->response.
547                                             openLogicalChannelAck);
548                 }
549                 DEBUGP("nf_ct_h323: H.245 Response %d\n",
550                        mscm->response.choice);
551                 break;
552         default:
553                 DEBUGP("nf_ct_h323: H.245 signal %d\n", mscm->choice);
554                 break;
555         }
556
557         return 0;
558 }
559
560 /****************************************************************************/
561 static int h245_help(struct sk_buff **pskb, unsigned int protoff,
562                      struct nf_conn *ct, enum ip_conntrack_info ctinfo)
563 {
564         static MultimediaSystemControlMessage mscm;
565         unsigned char *data = NULL;
566         int datalen;
567         int dataoff;
568         int ret;
569
570         /* Until there's been traffic both ways, don't look in packets. */
571         if (ctinfo != IP_CT_ESTABLISHED &&
572             ctinfo != IP_CT_ESTABLISHED + IP_CT_IS_REPLY) {
573                 return NF_ACCEPT;
574         }
575         DEBUGP("nf_ct_h245: skblen = %u\n", (*pskb)->len);
576
577         spin_lock_bh(&nf_h323_lock);
578
579         /* Process each TPKT */
580         while (get_tpkt_data(pskb, protoff, ct, ctinfo,
581                              &data, &datalen, &dataoff)) {
582                 DEBUGP("nf_ct_h245: TPKT len=%d ", datalen);
583                 NF_CT_DUMP_TUPLE(&ct->tuplehash[CTINFO2DIR(ctinfo)].tuple);
584
585                 /* Decode H.245 signal */
586                 ret = DecodeMultimediaSystemControlMessage(data, datalen,
587                                                            &mscm);
588                 if (ret < 0) {
589                         if (net_ratelimit())
590                                 printk("nf_ct_h245: decoding error: %s\n",
591                                        ret == H323_ERROR_BOUND ?
592                                        "out of bound" : "out of range");
593                         /* We don't drop when decoding error */
594                         break;
595                 }
596
597                 /* Process H.245 signal */
598                 if (process_h245(pskb, ct, ctinfo, &data, dataoff, &mscm) < 0)
599                         goto drop;
600         }
601
602         spin_unlock_bh(&nf_h323_lock);
603         return NF_ACCEPT;
604
605       drop:
606         spin_unlock_bh(&nf_h323_lock);
607         if (net_ratelimit())
608                 printk("nf_ct_h245: packet dropped\n");
609         return NF_DROP;
610 }
611
612 /****************************************************************************/
613 static struct nf_conntrack_helper nf_conntrack_helper_h245 __read_mostly = {
614         .name                   = "H.245",
615         .me                     = THIS_MODULE,
616         .max_expected           = H323_RTP_CHANNEL_MAX * 4 + 2 /* T.120 */,
617         .timeout                = 240,
618         .tuple.dst.protonum     = IPPROTO_UDP,
619         .mask.src.u.udp.port    = __constant_htons(0xFFFF),
620         .mask.dst.protonum      = 0xFF,
621         .help                   = h245_help
622 };
623
624 /****************************************************************************/
625 int get_h225_addr(struct nf_conn *ct, unsigned char *data,
626                   TransportAddress *taddr,
627                   union nf_conntrack_address *addr, __be16 *port)
628 {
629         unsigned char *p;
630         int family = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.l3num;
631         int len;
632
633         switch (taddr->choice) {
634         case eTransportAddress_ipAddress:
635                 if (family != AF_INET)
636                         return 0;
637                 p = data + taddr->ipAddress.ip;
638                 len = 4;
639                 break;
640         case eTransportAddress_ip6Address:
641                 if (family != AF_INET6)
642                         return 0;
643                 p = data + taddr->ip6Address.ip;
644                 len = 16;
645                 break;
646         default:
647                 return 0;
648         }
649
650         memcpy(addr, p, len);
651         memset((void *)addr + len, 0, sizeof(*addr) - len);
652         memcpy(port, p + len, sizeof(__be16));
653
654         return 1;
655 }
656
657 /****************************************************************************/
658 static int expect_h245(struct sk_buff **pskb, struct nf_conn *ct,
659                        enum ip_conntrack_info ctinfo,
660                        unsigned char **data, int dataoff,
661                        TransportAddress *taddr)
662 {
663         int dir = CTINFO2DIR(ctinfo);
664         int ret = 0;
665         __be16 port;
666         union nf_conntrack_address addr;
667         struct nf_conntrack_expect *exp;
668         typeof(nat_h245_hook) nat_h245;
669
670         /* Read h245Address */
671         if (!get_h225_addr(ct, *data, taddr, &addr, &port) ||
672             memcmp(&addr, &ct->tuplehash[dir].tuple.src.u3, sizeof(addr)) ||
673             port == 0)
674                 return 0;
675
676         /* Create expect for h245 connection */
677         if ((exp = nf_conntrack_expect_alloc(ct)) == NULL)
678                 return -1;
679         nf_conntrack_expect_init(exp, ct->tuplehash[!dir].tuple.src.l3num,
680                                  &ct->tuplehash[!dir].tuple.src.u3,
681                                  &ct->tuplehash[!dir].tuple.dst.u3,
682                                  IPPROTO_TCP, NULL, &port);
683         exp->helper = &nf_conntrack_helper_h245;
684
685         if (memcmp(&ct->tuplehash[dir].tuple.src.u3,
686                    &ct->tuplehash[!dir].tuple.dst.u3,
687                    sizeof(ct->tuplehash[dir].tuple.src.u3)) &&
688             (nat_h245 = rcu_dereference(nat_h245_hook)) &&
689             ct->status & IPS_NAT_MASK) {
690                 /* NAT needed */
691                 ret = nat_h245(pskb, ct, ctinfo, data, dataoff, taddr,
692                                port, exp);
693         } else {                /* Conntrack only */
694                 if (nf_conntrack_expect_related(exp) == 0) {
695                         DEBUGP("nf_ct_q931: expect H.245 ");
696                         NF_CT_DUMP_TUPLE(&exp->tuple);
697                 } else
698                         ret = -1;
699         }
700
701         nf_conntrack_expect_put(exp);
702
703         return ret;
704 }
705
706 /* If the calling party is on the same side of the forward-to party,
707  * we don't need to track the second call */
708 static int callforward_do_filter(union nf_conntrack_address *src,
709                                  union nf_conntrack_address *dst,
710                                  int family)
711 {
712         struct flowi fl1, fl2;
713         int ret = 0;
714
715         memset(&fl1, 0, sizeof(fl1));
716         memset(&fl2, 0, sizeof(fl2));
717
718         switch (family) {
719         case AF_INET: {
720                 struct rtable *rt1, *rt2;
721
722                 fl1.fl4_dst = src->ip;
723                 fl2.fl4_dst = dst->ip;
724                 if (ip_route_output_key(&rt1, &fl1) == 0) {
725                         if (ip_route_output_key(&rt2, &fl2) == 0) {
726                                 if (rt1->rt_gateway == rt2->rt_gateway &&
727                                     rt1->u.dst.dev  == rt2->u.dst.dev)
728                                         ret = 1;
729                                 dst_release(&rt2->u.dst);
730                         }
731                         dst_release(&rt1->u.dst);
732                 }
733                 break;
734         }
735 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
736         case AF_INET6: {
737                 struct rt6_info *rt1, *rt2;
738
739                 memcpy(&fl1.fl6_dst, src, sizeof(fl1.fl6_dst));
740                 memcpy(&fl2.fl6_dst, dst, sizeof(fl2.fl6_dst));
741                 rt1 = (struct rt6_info *)ip6_route_output(NULL, &fl1);
742                 if (rt1) {
743                         rt2 = (struct rt6_info *)ip6_route_output(NULL, &fl2);
744                         if (rt2) {
745                                 if (!memcmp(&rt1->rt6i_gateway, &rt2->rt6i_gateway,
746                                             sizeof(rt1->rt6i_gateway)) &&
747                                     rt1->u.dst.dev == rt2->u.dst.dev)
748                                         ret = 1;
749                                 dst_release(&rt2->u.dst);
750                         }
751                         dst_release(&rt1->u.dst);
752                 }
753                 break;
754         }
755 #endif
756         }
757         return ret;
758
759 }
760
761 /****************************************************************************/
762 static int expect_callforwarding(struct sk_buff **pskb,
763                                  struct nf_conn *ct,
764                                  enum ip_conntrack_info ctinfo,
765                                  unsigned char **data, int dataoff,
766                                  TransportAddress *taddr)
767 {
768         int dir = CTINFO2DIR(ctinfo);
769         int ret = 0;
770         __be16 port;
771         union nf_conntrack_address addr;
772         struct nf_conntrack_expect *exp;
773         typeof(nat_callforwarding_hook) nat_callforwarding;
774
775         /* Read alternativeAddress */
776         if (!get_h225_addr(ct, *data, taddr, &addr, &port) || port == 0)
777                 return 0;
778
779         /* If the calling party is on the same side of the forward-to party,
780          * we don't need to track the second call */
781         if (callforward_filter &&
782             callforward_do_filter(&addr, &ct->tuplehash[!dir].tuple.src.u3,
783                                   ct->tuplehash[!dir].tuple.src.l3num)) {
784                 DEBUGP("nf_ct_q931: Call Forwarding not tracked\n");
785                 return 0;
786         }
787
788         /* Create expect for the second call leg */
789         if ((exp = nf_conntrack_expect_alloc(ct)) == NULL)
790                 return -1;
791         nf_conntrack_expect_init(exp, ct->tuplehash[!dir].tuple.src.l3num,
792                                  &ct->tuplehash[!dir].tuple.src.u3, &addr,
793                                  IPPROTO_TCP, NULL, &port);
794         exp->helper = nf_conntrack_helper_q931;
795
796         if (memcmp(&ct->tuplehash[dir].tuple.src.u3,
797                    &ct->tuplehash[!dir].tuple.dst.u3,
798                    sizeof(ct->tuplehash[dir].tuple.src.u3)) &&
799             (nat_callforwarding = rcu_dereference(nat_callforwarding_hook)) &&
800             ct->status & IPS_NAT_MASK) {
801                 /* Need NAT */
802                 ret = nat_callforwarding(pskb, ct, ctinfo, data, dataoff,
803                                          taddr, port, exp);
804         } else {                /* Conntrack only */
805                 if (nf_conntrack_expect_related(exp) == 0) {
806                         DEBUGP("nf_ct_q931: expect Call Forwarding ");
807                         NF_CT_DUMP_TUPLE(&exp->tuple);
808                 } else
809                         ret = -1;
810         }
811
812         nf_conntrack_expect_put(exp);
813
814         return ret;
815 }
816
817 /****************************************************************************/
818 static int process_setup(struct sk_buff **pskb, struct nf_conn *ct,
819                          enum ip_conntrack_info ctinfo,
820                          unsigned char **data, int dataoff,
821                          Setup_UUIE *setup)
822 {
823         int dir = CTINFO2DIR(ctinfo);
824         int ret;
825         int i;
826         __be16 port;
827         union nf_conntrack_address addr;
828         typeof(set_h225_addr_hook) set_h225_addr;
829
830         DEBUGP("nf_ct_q931: Setup\n");
831
832         if (setup->options & eSetup_UUIE_h245Address) {
833                 ret = expect_h245(pskb, ct, ctinfo, data, dataoff,
834                                   &setup->h245Address);
835                 if (ret < 0)
836                         return -1;
837         }
838
839         set_h225_addr = rcu_dereference(set_h225_addr_hook);
840         if ((setup->options & eSetup_UUIE_destCallSignalAddress) &&
841             (set_h225_addr) && ct->status && IPS_NAT_MASK &&
842             get_h225_addr(ct, *data, &setup->destCallSignalAddress,
843                           &addr, &port) &&
844             memcmp(&addr, &ct->tuplehash[!dir].tuple.src.u3, sizeof(addr))) {
845                 DEBUGP("nf_ct_q931: set destCallSignalAddress "
846                        NIP6_FMT ":%hu->" NIP6_FMT ":%hu\n",
847                        NIP6(*(struct in6_addr *)&addr), ntohs(port),
848                        NIP6(*(struct in6_addr *)&ct->tuplehash[!dir].tuple.src.u3),
849                        ntohs(ct->tuplehash[!dir].tuple.src.u.tcp.port));
850                 ret = set_h225_addr(pskb, data, dataoff,
851                                     &setup->destCallSignalAddress,
852                                     &ct->tuplehash[!dir].tuple.src.u3,
853                                     ct->tuplehash[!dir].tuple.src.u.tcp.port);
854                 if (ret < 0)
855                         return -1;
856         }
857
858         if ((setup->options & eSetup_UUIE_sourceCallSignalAddress) &&
859             (set_h225_addr) && ct->status & IPS_NAT_MASK &&
860             get_h225_addr(ct, *data, &setup->sourceCallSignalAddress,
861                           &addr, &port) &&
862             memcmp(&addr, &ct->tuplehash[!dir].tuple.dst.u3, sizeof(addr))) {
863                 DEBUGP("nf_ct_q931: set sourceCallSignalAddress "
864                        NIP6_FMT ":%hu->" NIP6_FMT ":%hu\n",
865                        NIP6(*(struct in6_addr *)&addr), ntohs(port),
866                        NIP6(*(struct in6_addr *)&ct->tuplehash[!dir].tuple.dst.u3),
867                        ntohs(ct->tuplehash[!dir].tuple.dst.u.tcp.port));
868                 ret = set_h225_addr(pskb, data, dataoff,
869                                     &setup->sourceCallSignalAddress,
870                                     &ct->tuplehash[!dir].tuple.dst.u3,
871                                     ct->tuplehash[!dir].tuple.dst.u.tcp.port);
872                 if (ret < 0)
873                         return -1;
874         }
875
876         if (setup->options & eSetup_UUIE_fastStart) {
877                 for (i = 0; i < setup->fastStart.count; i++) {
878                         ret = process_olc(pskb, ct, ctinfo, data, dataoff,
879                                           &setup->fastStart.item[i]);
880                         if (ret < 0)
881                                 return -1;
882                 }
883         }
884
885         return 0;
886 }
887
888 /****************************************************************************/
889 static int process_callproceeding(struct sk_buff **pskb,
890                                   struct nf_conn *ct,
891                                   enum ip_conntrack_info ctinfo,
892                                   unsigned char **data, int dataoff,
893                                   CallProceeding_UUIE *callproc)
894 {
895         int ret;
896         int i;
897
898         DEBUGP("nf_ct_q931: CallProceeding\n");
899
900         if (callproc->options & eCallProceeding_UUIE_h245Address) {
901                 ret = expect_h245(pskb, ct, ctinfo, data, dataoff,
902                                   &callproc->h245Address);
903                 if (ret < 0)
904                         return -1;
905         }
906
907         if (callproc->options & eCallProceeding_UUIE_fastStart) {
908                 for (i = 0; i < callproc->fastStart.count; i++) {
909                         ret = process_olc(pskb, ct, ctinfo, data, dataoff,
910                                           &callproc->fastStart.item[i]);
911                         if (ret < 0)
912                                 return -1;
913                 }
914         }
915
916         return 0;
917 }
918
919 /****************************************************************************/
920 static int process_connect(struct sk_buff **pskb, struct nf_conn *ct,
921                            enum ip_conntrack_info ctinfo,
922                            unsigned char **data, int dataoff,
923                            Connect_UUIE *connect)
924 {
925         int ret;
926         int i;
927
928         DEBUGP("nf_ct_q931: Connect\n");
929
930         if (connect->options & eConnect_UUIE_h245Address) {
931                 ret = expect_h245(pskb, ct, ctinfo, data, dataoff,
932                                   &connect->h245Address);
933                 if (ret < 0)
934                         return -1;
935         }
936
937         if (connect->options & eConnect_UUIE_fastStart) {
938                 for (i = 0; i < connect->fastStart.count; i++) {
939                         ret = process_olc(pskb, ct, ctinfo, data, dataoff,
940                                           &connect->fastStart.item[i]);
941                         if (ret < 0)
942                                 return -1;
943                 }
944         }
945
946         return 0;
947 }
948
949 /****************************************************************************/
950 static int process_alerting(struct sk_buff **pskb, struct nf_conn *ct,
951                             enum ip_conntrack_info ctinfo,
952                             unsigned char **data, int dataoff,
953                             Alerting_UUIE *alert)
954 {
955         int ret;
956         int i;
957
958         DEBUGP("nf_ct_q931: Alerting\n");
959
960         if (alert->options & eAlerting_UUIE_h245Address) {
961                 ret = expect_h245(pskb, ct, ctinfo, data, dataoff,
962                                   &alert->h245Address);
963                 if (ret < 0)
964                         return -1;
965         }
966
967         if (alert->options & eAlerting_UUIE_fastStart) {
968                 for (i = 0; i < alert->fastStart.count; i++) {
969                         ret = process_olc(pskb, ct, ctinfo, data, dataoff,
970                                           &alert->fastStart.item[i]);
971                         if (ret < 0)
972                                 return -1;
973                 }
974         }
975
976         return 0;
977 }
978
979 /****************************************************************************/
980 static int process_facility(struct sk_buff **pskb, struct nf_conn *ct,
981                             enum ip_conntrack_info ctinfo,
982                             unsigned char **data, int dataoff,
983                             Facility_UUIE *facility)
984 {
985         int ret;
986         int i;
987
988         DEBUGP("nf_ct_q931: Facility\n");
989
990         if (facility->reason.choice == eFacilityReason_callForwarded) {
991                 if (facility->options & eFacility_UUIE_alternativeAddress)
992                         return expect_callforwarding(pskb, ct, ctinfo, data,
993                                                      dataoff,
994                                                      &facility->
995                                                      alternativeAddress);
996                 return 0;
997         }
998
999         if (facility->options & eFacility_UUIE_h245Address) {
1000                 ret = expect_h245(pskb, ct, ctinfo, data, dataoff,
1001                                   &facility->h245Address);
1002                 if (ret < 0)
1003                         return -1;
1004         }
1005
1006         if (facility->options & eFacility_UUIE_fastStart) {
1007                 for (i = 0; i < facility->fastStart.count; i++) {
1008                         ret = process_olc(pskb, ct, ctinfo, data, dataoff,
1009                                           &facility->fastStart.item[i]);
1010                         if (ret < 0)
1011                                 return -1;
1012                 }
1013         }
1014
1015         return 0;
1016 }
1017
1018 /****************************************************************************/
1019 static int process_progress(struct sk_buff **pskb, struct nf_conn *ct,
1020                             enum ip_conntrack_info ctinfo,
1021                             unsigned char **data, int dataoff,
1022                             Progress_UUIE *progress)
1023 {
1024         int ret;
1025         int i;
1026
1027         DEBUGP("nf_ct_q931: Progress\n");
1028
1029         if (progress->options & eProgress_UUIE_h245Address) {
1030                 ret = expect_h245(pskb, ct, ctinfo, data, dataoff,
1031                                   &progress->h245Address);
1032                 if (ret < 0)
1033                         return -1;
1034         }
1035
1036         if (progress->options & eProgress_UUIE_fastStart) {
1037                 for (i = 0; i < progress->fastStart.count; i++) {
1038                         ret = process_olc(pskb, ct, ctinfo, data, dataoff,
1039                                           &progress->fastStart.item[i]);
1040                         if (ret < 0)
1041                                 return -1;
1042                 }
1043         }
1044
1045         return 0;
1046 }
1047
1048 /****************************************************************************/
1049 static int process_q931(struct sk_buff **pskb, struct nf_conn *ct,
1050                         enum ip_conntrack_info ctinfo,
1051                         unsigned char **data, int dataoff, Q931 *q931)
1052 {
1053         H323_UU_PDU *pdu = &q931->UUIE.h323_uu_pdu;
1054         int i;
1055         int ret = 0;
1056
1057         switch (pdu->h323_message_body.choice) {
1058         case eH323_UU_PDU_h323_message_body_setup:
1059                 ret = process_setup(pskb, ct, ctinfo, data, dataoff,
1060                                     &pdu->h323_message_body.setup);
1061                 break;
1062         case eH323_UU_PDU_h323_message_body_callProceeding:
1063                 ret = process_callproceeding(pskb, ct, ctinfo, data, dataoff,
1064                                              &pdu->h323_message_body.
1065                                              callProceeding);
1066                 break;
1067         case eH323_UU_PDU_h323_message_body_connect:
1068                 ret = process_connect(pskb, ct, ctinfo, data, dataoff,
1069                                       &pdu->h323_message_body.connect);
1070                 break;
1071         case eH323_UU_PDU_h323_message_body_alerting:
1072                 ret = process_alerting(pskb, ct, ctinfo, data, dataoff,
1073                                        &pdu->h323_message_body.alerting);
1074                 break;
1075         case eH323_UU_PDU_h323_message_body_facility:
1076                 ret = process_facility(pskb, ct, ctinfo, data, dataoff,
1077                                        &pdu->h323_message_body.facility);
1078                 break;
1079         case eH323_UU_PDU_h323_message_body_progress:
1080                 ret = process_progress(pskb, ct, ctinfo, data, dataoff,
1081                                        &pdu->h323_message_body.progress);
1082                 break;
1083         default:
1084                 DEBUGP("nf_ct_q931: Q.931 signal %d\n",
1085                        pdu->h323_message_body.choice);
1086                 break;
1087         }
1088
1089         if (ret < 0)
1090                 return -1;
1091
1092         if (pdu->options & eH323_UU_PDU_h245Control) {
1093                 for (i = 0; i < pdu->h245Control.count; i++) {
1094                         ret = process_h245(pskb, ct, ctinfo, data, dataoff,
1095                                            &pdu->h245Control.item[i]);
1096                         if (ret < 0)
1097                                 return -1;
1098                 }
1099         }
1100
1101         return 0;
1102 }
1103
1104 /****************************************************************************/
1105 static int q931_help(struct sk_buff **pskb, unsigned int protoff,
1106                      struct nf_conn *ct, enum ip_conntrack_info ctinfo)
1107 {
1108         static Q931 q931;
1109         unsigned char *data = NULL;
1110         int datalen;
1111         int dataoff;
1112         int ret;
1113
1114         /* Until there's been traffic both ways, don't look in packets. */
1115         if (ctinfo != IP_CT_ESTABLISHED &&
1116             ctinfo != IP_CT_ESTABLISHED + IP_CT_IS_REPLY) {
1117                 return NF_ACCEPT;
1118         }
1119         DEBUGP("nf_ct_q931: skblen = %u\n", (*pskb)->len);
1120
1121         spin_lock_bh(&nf_h323_lock);
1122
1123         /* Process each TPKT */
1124         while (get_tpkt_data(pskb, protoff, ct, ctinfo,
1125                              &data, &datalen, &dataoff)) {
1126                 DEBUGP("nf_ct_q931: TPKT len=%d ", datalen);
1127                 NF_CT_DUMP_TUPLE(&ct->tuplehash[CTINFO2DIR(ctinfo)].tuple);
1128
1129                 /* Decode Q.931 signal */
1130                 ret = DecodeQ931(data, datalen, &q931);
1131                 if (ret < 0) {
1132                         if (net_ratelimit())
1133                                 printk("nf_ct_q931: decoding error: %s\n",
1134                                        ret == H323_ERROR_BOUND ?
1135                                        "out of bound" : "out of range");
1136                         /* We don't drop when decoding error */
1137                         break;
1138                 }
1139
1140                 /* Process Q.931 signal */
1141                 if (process_q931(pskb, ct, ctinfo, &data, dataoff, &q931) < 0)
1142                         goto drop;
1143         }
1144
1145         spin_unlock_bh(&nf_h323_lock);
1146         return NF_ACCEPT;
1147
1148       drop:
1149         spin_unlock_bh(&nf_h323_lock);
1150         if (net_ratelimit())
1151                 printk("nf_ct_q931: packet dropped\n");
1152         return NF_DROP;
1153 }
1154
1155 /****************************************************************************/
1156 static struct nf_conntrack_helper nf_conntrack_helper_q931[] __read_mostly = {
1157         {
1158                 .name                   = "Q.931",
1159                 .me                     = THIS_MODULE,
1160                                           /* T.120 and H.245 */
1161                 .max_expected           = H323_RTP_CHANNEL_MAX * 4 + 4,
1162                 .timeout                = 240,
1163                 .tuple.src.l3num        = AF_INET,
1164                 .tuple.src.u.tcp.port   = __constant_htons(Q931_PORT),
1165                 .tuple.dst.protonum     = IPPROTO_TCP,
1166                 .mask.src.l3num         = 0xFFFF,
1167                 .mask.src.u.tcp.port    = __constant_htons(0xFFFF),
1168                 .mask.dst.protonum      = 0xFF,
1169                 .help                   = q931_help
1170         },
1171         {
1172                 .name                   = "Q.931",
1173                 .me                     = THIS_MODULE,
1174                                           /* T.120 and H.245 */
1175                 .max_expected           = H323_RTP_CHANNEL_MAX * 4 + 4,
1176                 .timeout                = 240,
1177                 .tuple.src.l3num        = AF_INET6,
1178                 .tuple.src.u.tcp.port   = __constant_htons(Q931_PORT),
1179                 .tuple.dst.protonum     = IPPROTO_TCP,
1180                 .mask.src.l3num         = 0xFFFF,
1181                 .mask.src.u.tcp.port    = __constant_htons(0xFFFF),
1182                 .mask.dst.protonum      = 0xFF,
1183                 .help                   = q931_help
1184         },
1185 };
1186
1187 /****************************************************************************/
1188 static unsigned char *get_udp_data(struct sk_buff **pskb, unsigned int protoff,
1189                                    int *datalen)
1190 {
1191         struct udphdr _uh, *uh;
1192         int dataoff;
1193
1194         uh = skb_header_pointer(*pskb, protoff, sizeof(_uh), &_uh);
1195         if (uh == NULL)
1196                 return NULL;
1197         dataoff = protoff + sizeof(_uh);
1198         if (dataoff >= (*pskb)->len)
1199                 return NULL;
1200         *datalen = (*pskb)->len - dataoff;
1201         return skb_header_pointer(*pskb, dataoff, *datalen, h323_buffer);
1202 }
1203
1204 /****************************************************************************/
1205 static struct nf_conntrack_expect *find_expect(struct nf_conn *ct,
1206                                                union nf_conntrack_address *addr,
1207                                                __be16 port)
1208 {
1209         struct nf_conntrack_expect *exp;
1210         struct nf_conntrack_tuple tuple;
1211
1212         memset(&tuple.src.u3, 0, sizeof(tuple.src.u3));
1213         tuple.src.u.tcp.port = 0;
1214         memcpy(&tuple.dst.u3, addr, sizeof(tuple.dst.u3));
1215         tuple.dst.u.tcp.port = port;
1216         tuple.dst.protonum = IPPROTO_TCP;
1217
1218         exp = __nf_conntrack_expect_find(&tuple);
1219         if (exp && exp->master == ct)
1220                 return exp;
1221         return NULL;
1222 }
1223
1224 /****************************************************************************/
1225 static int set_expect_timeout(struct nf_conntrack_expect *exp,
1226                               unsigned timeout)
1227 {
1228         if (!exp || !del_timer(&exp->timeout))
1229                 return 0;
1230
1231         exp->timeout.expires = jiffies + timeout * HZ;
1232         add_timer(&exp->timeout);
1233
1234         return 1;
1235 }
1236
1237 /****************************************************************************/
1238 static int expect_q931(struct sk_buff **pskb, struct nf_conn *ct,
1239                        enum ip_conntrack_info ctinfo,
1240                        unsigned char **data,
1241                        TransportAddress *taddr, int count)
1242 {
1243         struct nf_ct_h323_master *info = &nfct_help(ct)->help.ct_h323_info;
1244         int dir = CTINFO2DIR(ctinfo);
1245         int ret = 0;
1246         int i;
1247         __be16 port;
1248         union nf_conntrack_address addr;
1249         struct nf_conntrack_expect *exp;
1250         typeof(nat_q931_hook) nat_q931;
1251
1252         /* Look for the first related address */
1253         for (i = 0; i < count; i++) {
1254                 if (get_h225_addr(ct, *data, &taddr[i], &addr, &port) &&
1255                     memcmp(&addr, &ct->tuplehash[dir].tuple.src.u3,
1256                            sizeof(addr)) == 0 && port != 0)
1257                         break;
1258         }
1259
1260         if (i >= count)         /* Not found */
1261                 return 0;
1262
1263         /* Create expect for Q.931 */
1264         if ((exp = nf_conntrack_expect_alloc(ct)) == NULL)
1265                 return -1;
1266         nf_conntrack_expect_init(exp, ct->tuplehash[!dir].tuple.src.l3num,
1267                                  gkrouted_only ? /* only accept calls from GK? */
1268                                         &ct->tuplehash[!dir].tuple.src.u3 :
1269                                         NULL,
1270                                  &ct->tuplehash[!dir].tuple.dst.u3,
1271                                  IPPROTO_TCP, NULL, &port);
1272         exp->helper = nf_conntrack_helper_q931;
1273         exp->flags = NF_CT_EXPECT_PERMANENT;    /* Accept multiple calls */
1274
1275         nat_q931 = rcu_dereference(nat_q931_hook);
1276         if (nat_q931 && ct->status & IPS_NAT_MASK) {    /* Need NAT */
1277                 ret = nat_q931(pskb, ct, ctinfo, data, taddr, i, port, exp);
1278         } else {                /* Conntrack only */
1279                 if (nf_conntrack_expect_related(exp) == 0) {
1280                         DEBUGP("nf_ct_ras: expect Q.931 ");
1281                         NF_CT_DUMP_TUPLE(&exp->tuple);
1282
1283                         /* Save port for looking up expect in processing RCF */
1284                         info->sig_port[dir] = port;
1285                 } else
1286                         ret = -1;
1287         }
1288
1289         nf_conntrack_expect_put(exp);
1290
1291         return ret;
1292 }
1293
1294 /****************************************************************************/
1295 static int process_grq(struct sk_buff **pskb, struct nf_conn *ct,
1296                        enum ip_conntrack_info ctinfo,
1297                        unsigned char **data, GatekeeperRequest *grq)
1298 {
1299         typeof(set_ras_addr_hook) set_ras_addr;
1300
1301         DEBUGP("nf_ct_ras: GRQ\n");
1302
1303         set_ras_addr = rcu_dereference(set_ras_addr_hook);
1304         if (set_ras_addr && ct->status & IPS_NAT_MASK)  /* NATed */
1305                 return set_ras_addr(pskb, ct, ctinfo, data,
1306                                     &grq->rasAddress, 1);
1307         return 0;
1308 }
1309
1310 /****************************************************************************/
1311 static int process_gcf(struct sk_buff **pskb, struct nf_conn *ct,
1312                        enum ip_conntrack_info ctinfo,
1313                        unsigned char **data, GatekeeperConfirm *gcf)
1314 {
1315         int dir = CTINFO2DIR(ctinfo);
1316         int ret = 0;
1317         __be16 port;
1318         union nf_conntrack_address addr;
1319         struct nf_conntrack_expect *exp;
1320
1321         DEBUGP("nf_ct_ras: GCF\n");
1322
1323         if (!get_h225_addr(ct, *data, &gcf->rasAddress, &addr, &port))
1324                 return 0;
1325
1326         /* Registration port is the same as discovery port */
1327         if (!memcmp(&addr, &ct->tuplehash[dir].tuple.src.u3, sizeof(addr)) &&
1328             port == ct->tuplehash[dir].tuple.src.u.udp.port)
1329                 return 0;
1330
1331         /* Avoid RAS expectation loops. A GCF is never expected. */
1332         if (test_bit(IPS_EXPECTED_BIT, &ct->status))
1333                 return 0;
1334
1335         /* Need new expect */
1336         if ((exp = nf_conntrack_expect_alloc(ct)) == NULL)
1337                 return -1;
1338         nf_conntrack_expect_init(exp, ct->tuplehash[!dir].tuple.src.l3num,
1339                                  &ct->tuplehash[!dir].tuple.src.u3, &addr,
1340                                  IPPROTO_UDP, NULL, &port);
1341         exp->helper = nf_conntrack_helper_ras;
1342
1343         if (nf_conntrack_expect_related(exp) == 0) {
1344                 DEBUGP("nf_ct_ras: expect RAS ");
1345                 NF_CT_DUMP_TUPLE(&exp->tuple);
1346         } else
1347                 ret = -1;
1348
1349         nf_conntrack_expect_put(exp);
1350
1351         return ret;
1352 }
1353
1354 /****************************************************************************/
1355 static int process_rrq(struct sk_buff **pskb, struct nf_conn *ct,
1356                        enum ip_conntrack_info ctinfo,
1357                        unsigned char **data, RegistrationRequest *rrq)
1358 {
1359         struct nf_ct_h323_master *info = &nfct_help(ct)->help.ct_h323_info;
1360         int ret;
1361         typeof(set_ras_addr_hook) set_ras_addr;
1362
1363         DEBUGP("nf_ct_ras: RRQ\n");
1364
1365         ret = expect_q931(pskb, ct, ctinfo, data,
1366                           rrq->callSignalAddress.item,
1367                           rrq->callSignalAddress.count);
1368         if (ret < 0)
1369                 return -1;
1370
1371         set_ras_addr = rcu_dereference(set_ras_addr_hook);
1372         if (set_ras_addr && ct->status & IPS_NAT_MASK) {
1373                 ret = set_ras_addr(pskb, ct, ctinfo, data,
1374                                    rrq->rasAddress.item,
1375                                    rrq->rasAddress.count);
1376                 if (ret < 0)
1377                         return -1;
1378         }
1379
1380         if (rrq->options & eRegistrationRequest_timeToLive) {
1381                 DEBUGP("nf_ct_ras: RRQ TTL = %u seconds\n", rrq->timeToLive);
1382                 info->timeout = rrq->timeToLive;
1383         } else
1384                 info->timeout = default_rrq_ttl;
1385
1386         return 0;
1387 }
1388
1389 /****************************************************************************/
1390 static int process_rcf(struct sk_buff **pskb, struct nf_conn *ct,
1391                        enum ip_conntrack_info ctinfo,
1392                        unsigned char **data, RegistrationConfirm *rcf)
1393 {
1394         struct nf_ct_h323_master *info = &nfct_help(ct)->help.ct_h323_info;
1395         int dir = CTINFO2DIR(ctinfo);
1396         int ret;
1397         struct nf_conntrack_expect *exp;
1398         typeof(set_sig_addr_hook) set_sig_addr;
1399
1400         DEBUGP("nf_ct_ras: RCF\n");
1401
1402         set_sig_addr = rcu_dereference(set_sig_addr_hook);
1403         if (set_sig_addr && ct->status & IPS_NAT_MASK) {
1404                 ret = set_sig_addr(pskb, ct, ctinfo, data,
1405                                         rcf->callSignalAddress.item,
1406                                         rcf->callSignalAddress.count);
1407                 if (ret < 0)
1408                         return -1;
1409         }
1410
1411         if (rcf->options & eRegistrationConfirm_timeToLive) {
1412                 DEBUGP("nf_ct_ras: RCF TTL = %u seconds\n", rcf->timeToLive);
1413                 info->timeout = rcf->timeToLive;
1414         }
1415
1416         if (info->timeout > 0) {
1417                 DEBUGP
1418                     ("nf_ct_ras: set RAS connection timeout to %u seconds\n",
1419                      info->timeout);
1420                 nf_ct_refresh(ct, *pskb, info->timeout * HZ);
1421
1422                 /* Set expect timeout */
1423                 read_lock_bh(&nf_conntrack_lock);
1424                 exp = find_expect(ct, &ct->tuplehash[dir].tuple.dst.u3,
1425                                   info->sig_port[!dir]);
1426                 if (exp) {
1427                         DEBUGP("nf_ct_ras: set Q.931 expect "
1428                                "timeout to %u seconds for",
1429                                info->timeout);
1430                         NF_CT_DUMP_TUPLE(&exp->tuple);
1431                         set_expect_timeout(exp, info->timeout);
1432                 }
1433                 read_unlock_bh(&nf_conntrack_lock);
1434         }
1435
1436         return 0;
1437 }
1438
1439 /****************************************************************************/
1440 static int process_urq(struct sk_buff **pskb, struct nf_conn *ct,
1441                        enum ip_conntrack_info ctinfo,
1442                        unsigned char **data, UnregistrationRequest *urq)
1443 {
1444         struct nf_ct_h323_master *info = &nfct_help(ct)->help.ct_h323_info;
1445         int dir = CTINFO2DIR(ctinfo);
1446         int ret;
1447         typeof(set_sig_addr_hook) set_sig_addr;
1448
1449         DEBUGP("nf_ct_ras: URQ\n");
1450
1451         set_sig_addr = rcu_dereference(set_sig_addr_hook);
1452         if (set_sig_addr && ct->status & IPS_NAT_MASK) {
1453                 ret = set_sig_addr(pskb, ct, ctinfo, data,
1454                                    urq->callSignalAddress.item,
1455                                    urq->callSignalAddress.count);
1456                 if (ret < 0)
1457                         return -1;
1458         }
1459
1460         /* Clear old expect */
1461         nf_ct_remove_expectations(ct);
1462         info->sig_port[dir] = 0;
1463         info->sig_port[!dir] = 0;
1464
1465         /* Give it 30 seconds for UCF or URJ */
1466         nf_ct_refresh(ct, *pskb, 30 * HZ);
1467
1468         return 0;
1469 }
1470
1471 /****************************************************************************/
1472 static int process_arq(struct sk_buff **pskb, struct nf_conn *ct,
1473                        enum ip_conntrack_info ctinfo,
1474                        unsigned char **data, AdmissionRequest *arq)
1475 {
1476         struct nf_ct_h323_master *info = &nfct_help(ct)->help.ct_h323_info;
1477         int dir = CTINFO2DIR(ctinfo);
1478         __be16 port;
1479         union nf_conntrack_address addr;
1480         typeof(set_h225_addr_hook) set_h225_addr;
1481
1482         DEBUGP("nf_ct_ras: ARQ\n");
1483
1484         set_h225_addr = rcu_dereference(set_h225_addr_hook);
1485         if ((arq->options & eAdmissionRequest_destCallSignalAddress) &&
1486             get_h225_addr(ct, *data, &arq->destCallSignalAddress,
1487                           &addr, &port) &&
1488             !memcmp(&addr, &ct->tuplehash[dir].tuple.src.u3, sizeof(addr)) &&
1489             port == info->sig_port[dir] &&
1490             set_h225_addr && ct->status & IPS_NAT_MASK) {
1491                 /* Answering ARQ */
1492                 return set_h225_addr(pskb, data, 0,
1493                                      &arq->destCallSignalAddress,
1494                                      &ct->tuplehash[!dir].tuple.dst.u3,
1495                                      info->sig_port[!dir]);
1496         }
1497
1498         if ((arq->options & eAdmissionRequest_srcCallSignalAddress) &&
1499             get_h225_addr(ct, *data, &arq->srcCallSignalAddress,
1500                           &addr, &port) &&
1501             !memcmp(&addr, &ct->tuplehash[dir].tuple.src.u3, sizeof(addr)) &&
1502             set_h225_addr && ct->status & IPS_NAT_MASK) {
1503                 /* Calling ARQ */
1504                 return set_h225_addr(pskb, data, 0,
1505                                      &arq->srcCallSignalAddress,
1506                                      &ct->tuplehash[!dir].tuple.dst.u3,
1507                                      port);
1508         }
1509
1510         return 0;
1511 }
1512
1513 /****************************************************************************/
1514 static int process_acf(struct sk_buff **pskb, struct nf_conn *ct,
1515                        enum ip_conntrack_info ctinfo,
1516                        unsigned char **data, AdmissionConfirm *acf)
1517 {
1518         int dir = CTINFO2DIR(ctinfo);
1519         int ret = 0;
1520         __be16 port;
1521         union nf_conntrack_address addr;
1522         struct nf_conntrack_expect *exp;
1523         typeof(set_sig_addr_hook) set_sig_addr;
1524
1525         DEBUGP("nf_ct_ras: ACF\n");
1526
1527         if (!get_h225_addr(ct, *data, &acf->destCallSignalAddress,
1528                            &addr, &port))
1529                 return 0;
1530
1531         if (!memcmp(&addr, &ct->tuplehash[dir].tuple.dst.u3, sizeof(addr))) {
1532                 /* Answering ACF */
1533                 set_sig_addr = rcu_dereference(set_sig_addr_hook);
1534                 if (set_sig_addr && ct->status & IPS_NAT_MASK)
1535                         return set_sig_addr(pskb, ct, ctinfo, data,
1536                                             &acf->destCallSignalAddress, 1);
1537                 return 0;
1538         }
1539
1540         /* Need new expect */
1541         if ((exp = nf_conntrack_expect_alloc(ct)) == NULL)
1542                 return -1;
1543         nf_conntrack_expect_init(exp, ct->tuplehash[!dir].tuple.src.l3num,
1544                                  &ct->tuplehash[!dir].tuple.src.u3, &addr,
1545                                  IPPROTO_TCP, NULL, &port);
1546         exp->flags = NF_CT_EXPECT_PERMANENT;
1547         exp->helper = nf_conntrack_helper_q931;
1548
1549         if (nf_conntrack_expect_related(exp) == 0) {
1550                 DEBUGP("nf_ct_ras: expect Q.931 ");
1551                 NF_CT_DUMP_TUPLE(&exp->tuple);
1552         } else
1553                 ret = -1;
1554
1555         nf_conntrack_expect_put(exp);
1556
1557         return ret;
1558 }
1559
1560 /****************************************************************************/
1561 static int process_lrq(struct sk_buff **pskb, struct nf_conn *ct,
1562                        enum ip_conntrack_info ctinfo,
1563                        unsigned char **data, LocationRequest *lrq)
1564 {
1565         typeof(set_ras_addr_hook) set_ras_addr;
1566
1567         DEBUGP("nf_ct_ras: LRQ\n");
1568
1569         set_ras_addr = rcu_dereference(set_ras_addr_hook);
1570         if (set_ras_addr && ct->status & IPS_NAT_MASK)
1571                 return set_ras_addr(pskb, ct, ctinfo, data,
1572                                     &lrq->replyAddress, 1);
1573         return 0;
1574 }
1575
1576 /****************************************************************************/
1577 static int process_lcf(struct sk_buff **pskb, struct nf_conn *ct,
1578                        enum ip_conntrack_info ctinfo,
1579                        unsigned char **data, LocationConfirm *lcf)
1580 {
1581         int dir = CTINFO2DIR(ctinfo);
1582         int ret = 0;
1583         __be16 port;
1584         union nf_conntrack_address addr;
1585         struct nf_conntrack_expect *exp;
1586
1587         DEBUGP("nf_ct_ras: LCF\n");
1588
1589         if (!get_h225_addr(ct, *data, &lcf->callSignalAddress,
1590                            &addr, &port))
1591                 return 0;
1592
1593         /* Need new expect for call signal */
1594         if ((exp = nf_conntrack_expect_alloc(ct)) == NULL)
1595                 return -1;
1596         nf_conntrack_expect_init(exp, ct->tuplehash[!dir].tuple.src.l3num,
1597                                  &ct->tuplehash[!dir].tuple.src.u3, &addr,
1598                                  IPPROTO_TCP, NULL, &port);
1599         exp->flags = NF_CT_EXPECT_PERMANENT;
1600         exp->helper = nf_conntrack_helper_q931;
1601
1602         if (nf_conntrack_expect_related(exp) == 0) {
1603                 DEBUGP("nf_ct_ras: expect Q.931 ");
1604                 NF_CT_DUMP_TUPLE(&exp->tuple);
1605         } else
1606                 ret = -1;
1607
1608         nf_conntrack_expect_put(exp);
1609
1610         /* Ignore rasAddress */
1611
1612         return ret;
1613 }
1614
1615 /****************************************************************************/
1616 static int process_irr(struct sk_buff **pskb, struct nf_conn *ct,
1617                        enum ip_conntrack_info ctinfo,
1618                        unsigned char **data, InfoRequestResponse *irr)
1619 {
1620         int ret;
1621         typeof(set_ras_addr_hook) set_ras_addr;
1622         typeof(set_sig_addr_hook) set_sig_addr;
1623
1624         DEBUGP("nf_ct_ras: IRR\n");
1625
1626         set_ras_addr = rcu_dereference(set_ras_addr_hook);
1627         if (set_ras_addr && ct->status & IPS_NAT_MASK) {
1628                 ret = set_ras_addr(pskb, ct, ctinfo, data,
1629                                    &irr->rasAddress, 1);
1630                 if (ret < 0)
1631                         return -1;
1632         }
1633
1634         set_sig_addr = rcu_dereference(set_sig_addr_hook);
1635         if (set_sig_addr && ct->status & IPS_NAT_MASK) {
1636                 ret = set_sig_addr(pskb, ct, ctinfo, data,
1637                                         irr->callSignalAddress.item,
1638                                         irr->callSignalAddress.count);
1639                 if (ret < 0)
1640                         return -1;
1641         }
1642
1643         return 0;
1644 }
1645
1646 /****************************************************************************/
1647 static int process_ras(struct sk_buff **pskb, struct nf_conn *ct,
1648                        enum ip_conntrack_info ctinfo,
1649                        unsigned char **data, RasMessage *ras)
1650 {
1651         switch (ras->choice) {
1652         case eRasMessage_gatekeeperRequest:
1653                 return process_grq(pskb, ct, ctinfo, data,
1654                                    &ras->gatekeeperRequest);
1655         case eRasMessage_gatekeeperConfirm:
1656                 return process_gcf(pskb, ct, ctinfo, data,
1657                                    &ras->gatekeeperConfirm);
1658         case eRasMessage_registrationRequest:
1659                 return process_rrq(pskb, ct, ctinfo, data,
1660                                    &ras->registrationRequest);
1661         case eRasMessage_registrationConfirm:
1662                 return process_rcf(pskb, ct, ctinfo, data,
1663                                    &ras->registrationConfirm);
1664         case eRasMessage_unregistrationRequest:
1665                 return process_urq(pskb, ct, ctinfo, data,
1666                                    &ras->unregistrationRequest);
1667         case eRasMessage_admissionRequest:
1668                 return process_arq(pskb, ct, ctinfo, data,
1669                                    &ras->admissionRequest);
1670         case eRasMessage_admissionConfirm:
1671                 return process_acf(pskb, ct, ctinfo, data,
1672                                    &ras->admissionConfirm);
1673         case eRasMessage_locationRequest:
1674                 return process_lrq(pskb, ct, ctinfo, data,
1675                                    &ras->locationRequest);
1676         case eRasMessage_locationConfirm:
1677                 return process_lcf(pskb, ct, ctinfo, data,
1678                                    &ras->locationConfirm);
1679         case eRasMessage_infoRequestResponse:
1680                 return process_irr(pskb, ct, ctinfo, data,
1681                                    &ras->infoRequestResponse);
1682         default:
1683                 DEBUGP("nf_ct_ras: RAS message %d\n", ras->choice);
1684                 break;
1685         }
1686
1687         return 0;
1688 }
1689
1690 /****************************************************************************/
1691 static int ras_help(struct sk_buff **pskb, unsigned int protoff,
1692                     struct nf_conn *ct, enum ip_conntrack_info ctinfo)
1693 {
1694         static RasMessage ras;
1695         unsigned char *data;
1696         int datalen = 0;
1697         int ret;
1698
1699         DEBUGP("nf_ct_ras: skblen = %u\n", (*pskb)->len);
1700
1701         spin_lock_bh(&nf_h323_lock);
1702
1703         /* Get UDP data */
1704         data = get_udp_data(pskb, protoff, &datalen);
1705         if (data == NULL)
1706                 goto accept;
1707         DEBUGP("nf_ct_ras: RAS message len=%d ", datalen);
1708         NF_CT_DUMP_TUPLE(&ct->tuplehash[CTINFO2DIR(ctinfo)].tuple);
1709
1710         /* Decode RAS message */
1711         ret = DecodeRasMessage(data, datalen, &ras);
1712         if (ret < 0) {
1713                 if (net_ratelimit())
1714                         printk("nf_ct_ras: decoding error: %s\n",
1715                                ret == H323_ERROR_BOUND ?
1716                                "out of bound" : "out of range");
1717                 goto accept;
1718         }
1719
1720         /* Process RAS message */
1721         if (process_ras(pskb, ct, ctinfo, &data, &ras) < 0)
1722                 goto drop;
1723
1724       accept:
1725         spin_unlock_bh(&nf_h323_lock);
1726         return NF_ACCEPT;
1727
1728       drop:
1729         spin_unlock_bh(&nf_h323_lock);
1730         if (net_ratelimit())
1731                 printk("nf_ct_ras: packet dropped\n");
1732         return NF_DROP;
1733 }
1734
1735 /****************************************************************************/
1736 static struct nf_conntrack_helper nf_conntrack_helper_ras[] __read_mostly = {
1737         {
1738                 .name                   = "RAS",
1739                 .me                     = THIS_MODULE,
1740                 .max_expected           = 32,
1741                 .timeout                = 240,
1742                 .tuple.src.l3num        = AF_INET,
1743                 .tuple.src.u.udp.port   = __constant_htons(RAS_PORT),
1744                 .tuple.dst.protonum     = IPPROTO_UDP,
1745                 .mask.src.l3num         = 0xFFFF,
1746                 .mask.src.u.udp.port    = __constant_htons(0xFFFF),
1747                 .mask.dst.protonum      = 0xFF,
1748                 .help                   = ras_help,
1749         },
1750         {
1751                 .name                   = "RAS",
1752                 .me                     = THIS_MODULE,
1753                 .max_expected           = 32,
1754                 .timeout                = 240,
1755                 .tuple.src.l3num        = AF_INET6,
1756                 .tuple.src.u.udp.port   = __constant_htons(RAS_PORT),
1757                 .tuple.dst.protonum     = IPPROTO_UDP,
1758                 .mask.src.l3num         = 0xFFFF,
1759                 .mask.src.u.udp.port    = __constant_htons(0xFFFF),
1760                 .mask.dst.protonum      = 0xFF,
1761                 .help                   = ras_help,
1762         },
1763 };
1764
1765 /****************************************************************************/
1766 static void __exit nf_conntrack_h323_fini(void)
1767 {
1768         nf_conntrack_helper_unregister(&nf_conntrack_helper_ras[1]);
1769         nf_conntrack_helper_unregister(&nf_conntrack_helper_ras[0]);
1770         nf_conntrack_helper_unregister(&nf_conntrack_helper_q931[1]);
1771         nf_conntrack_helper_unregister(&nf_conntrack_helper_q931[0]);
1772         kfree(h323_buffer);
1773         DEBUGP("nf_ct_h323: fini\n");
1774 }
1775
1776 /****************************************************************************/
1777 static int __init nf_conntrack_h323_init(void)
1778 {
1779         int ret;
1780
1781         h323_buffer = kmalloc(65536, GFP_KERNEL);
1782         if (!h323_buffer)
1783                 return -ENOMEM;
1784         ret = nf_conntrack_helper_register(&nf_conntrack_helper_q931[0]);
1785         if (ret < 0)
1786                 goto err1;
1787         ret = nf_conntrack_helper_register(&nf_conntrack_helper_q931[1]);
1788         if (ret < 0)
1789                 goto err2;
1790         ret = nf_conntrack_helper_register(&nf_conntrack_helper_ras[0]);
1791         if (ret < 0)
1792                 goto err3;
1793         ret = nf_conntrack_helper_register(&nf_conntrack_helper_ras[1]);
1794         if (ret < 0)
1795                 goto err4;
1796         DEBUGP("nf_ct_h323: init success\n");
1797         return 0;
1798
1799 err4:
1800         nf_conntrack_helper_unregister(&nf_conntrack_helper_ras[0]);
1801 err3:
1802         nf_conntrack_helper_unregister(&nf_conntrack_helper_q931[1]);
1803 err2:
1804         nf_conntrack_helper_unregister(&nf_conntrack_helper_q931[0]);
1805 err1:
1806         return ret;
1807 }
1808
1809 /****************************************************************************/
1810 module_init(nf_conntrack_h323_init);
1811 module_exit(nf_conntrack_h323_fini);
1812
1813 EXPORT_SYMBOL_GPL(get_h225_addr);
1814 EXPORT_SYMBOL_GPL(set_h245_addr_hook);
1815 EXPORT_SYMBOL_GPL(set_h225_addr_hook);
1816 EXPORT_SYMBOL_GPL(set_sig_addr_hook);
1817 EXPORT_SYMBOL_GPL(set_ras_addr_hook);
1818 EXPORT_SYMBOL_GPL(nat_rtp_rtcp_hook);
1819 EXPORT_SYMBOL_GPL(nat_t120_hook);
1820 EXPORT_SYMBOL_GPL(nat_h245_hook);
1821 EXPORT_SYMBOL_GPL(nat_callforwarding_hook);
1822 EXPORT_SYMBOL_GPL(nat_q931_hook);
1823
1824 MODULE_AUTHOR("Jing Min Zhao <zhaojingmin@users.sourceforge.net>");
1825 MODULE_DESCRIPTION("H.323 connection tracking helper");
1826 MODULE_LICENSE("GPL");
1827 MODULE_ALIAS("ip_conntrack_h323");