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