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