netfilter: xt_recent: add an entry reaper
[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/udp.h>
21 #include <linux/tcp.h>
22 #include <linux/skbuff.h>
23 #include <net/route.h>
24 #include <net/ip6_route.h>
25
26 #include <net/netfilter/nf_conntrack.h>
27 #include <net/netfilter/nf_conntrack_core.h>
28 #include <net/netfilter/nf_conntrack_tuple.h>
29 #include <net/netfilter/nf_conntrack_expect.h>
30 #include <net/netfilter/nf_conntrack_ecache.h>
31 #include <net/netfilter/nf_conntrack_helper.h>
32 #include <net/netfilter/nf_conntrack_zones.h>
33 #include <linux/netfilter/nf_conntrack_h323.h>
34
35 /* Parameters */
36 static unsigned int default_rrq_ttl __read_mostly = 300;
37 module_param(default_rrq_ttl, uint, 0600);
38 MODULE_PARM_DESC(default_rrq_ttl, "use this TTL if it's missing in RRQ");
39
40 static int gkrouted_only __read_mostly = 1;
41 module_param(gkrouted_only, int, 0600);
42 MODULE_PARM_DESC(gkrouted_only, "only accept calls from gatekeeper");
43
44 static int callforward_filter __read_mostly = 1;
45 module_param(callforward_filter, bool, 0600);
46 MODULE_PARM_DESC(callforward_filter, "only create call forwarding expectations "
47                                      "if both endpoints are on different sides "
48                                      "(determined by routing information)");
49
50 /* Hooks for NAT */
51 int (*set_h245_addr_hook) (struct sk_buff *skb,
52                            unsigned char **data, int dataoff,
53                            H245_TransportAddress *taddr,
54                            union nf_inet_addr *addr, __be16 port)
55                            __read_mostly;
56 int (*set_h225_addr_hook) (struct sk_buff *skb,
57                            unsigned char **data, int dataoff,
58                            TransportAddress *taddr,
59                            union nf_inet_addr *addr, __be16 port)
60                            __read_mostly;
61 int (*set_sig_addr_hook) (struct sk_buff *skb,
62                           struct nf_conn *ct,
63                           enum ip_conntrack_info ctinfo,
64                           unsigned char **data,
65                           TransportAddress *taddr, int count) __read_mostly;
66 int (*set_ras_addr_hook) (struct sk_buff *skb,
67                           struct nf_conn *ct,
68                           enum ip_conntrack_info ctinfo,
69                           unsigned char **data,
70                           TransportAddress *taddr, int count) __read_mostly;
71 int (*nat_rtp_rtcp_hook) (struct sk_buff *skb,
72                           struct nf_conn *ct,
73                           enum ip_conntrack_info ctinfo,
74                           unsigned char **data, int dataoff,
75                           H245_TransportAddress *taddr,
76                           __be16 port, __be16 rtp_port,
77                           struct nf_conntrack_expect *rtp_exp,
78                           struct nf_conntrack_expect *rtcp_exp) __read_mostly;
79 int (*nat_t120_hook) (struct sk_buff *skb,
80                       struct nf_conn *ct,
81                       enum ip_conntrack_info ctinfo,
82                       unsigned char **data, int dataoff,
83                       H245_TransportAddress *taddr, __be16 port,
84                       struct nf_conntrack_expect *exp) __read_mostly;
85 int (*nat_h245_hook) (struct sk_buff *skb,
86                       struct nf_conn *ct,
87                       enum ip_conntrack_info ctinfo,
88                       unsigned char **data, int dataoff,
89                       TransportAddress *taddr, __be16 port,
90                       struct nf_conntrack_expect *exp) __read_mostly;
91 int (*nat_callforwarding_hook) (struct sk_buff *skb,
92                                 struct nf_conn *ct,
93                                 enum ip_conntrack_info ctinfo,
94                                 unsigned char **data, int dataoff,
95                                 TransportAddress *taddr, __be16 port,
96                                 struct nf_conntrack_expect *exp) __read_mostly;
97 int (*nat_q931_hook) (struct sk_buff *skb,
98                       struct nf_conn *ct,
99                       enum ip_conntrack_info ctinfo,
100                       unsigned char **data, TransportAddress *taddr, int idx,
101                       __be16 port, struct nf_conntrack_expect *exp)
102                       __read_mostly;
103
104 static DEFINE_SPINLOCK(nf_h323_lock);
105 static char *h323_buffer;
106
107 static struct nf_conntrack_helper nf_conntrack_helper_h245;
108 static struct nf_conntrack_helper nf_conntrack_helper_q931[];
109 static struct nf_conntrack_helper nf_conntrack_helper_ras[];
110
111 /****************************************************************************/
112 static int get_tpkt_data(struct sk_buff *skb, unsigned int protoff,
113                          struct nf_conn *ct, enum ip_conntrack_info ctinfo,
114                          unsigned char **data, int *datalen, int *dataoff)
115 {
116         struct nf_ct_h323_master *info = &nfct_help(ct)->help.ct_h323_info;
117         int dir = CTINFO2DIR(ctinfo);
118         const struct tcphdr *th;
119         struct tcphdr _tcph;
120         int tcpdatalen;
121         int tcpdataoff;
122         unsigned char *tpkt;
123         int tpktlen;
124         int tpktoff;
125
126         /* Get TCP header */
127         th = skb_header_pointer(skb, protoff, sizeof(_tcph), &_tcph);
128         if (th == NULL)
129                 return 0;
130
131         /* Get TCP data offset */
132         tcpdataoff = protoff + th->doff * 4;
133
134         /* Get TCP data length */
135         tcpdatalen = skb->len - tcpdataoff;
136         if (tcpdatalen <= 0)    /* No TCP data */
137                 goto clear_out;
138
139         if (*data == NULL) {    /* first TPKT */
140                 /* Get first TPKT pointer */
141                 tpkt = skb_header_pointer(skb, tcpdataoff, tcpdatalen,
142                                           h323_buffer);
143                 BUG_ON(tpkt == NULL);
144
145                 /* Validate TPKT identifier */
146                 if (tcpdatalen < 4 || tpkt[0] != 0x03 || tpkt[1] != 0) {
147                         /* Netmeeting sends TPKT header and data separately */
148                         if (info->tpkt_len[dir] > 0) {
149                                 pr_debug("nf_ct_h323: previous packet "
150                                          "indicated separate TPKT data of %hu "
151                                          "bytes\n", info->tpkt_len[dir]);
152                                 if (info->tpkt_len[dir] <= tcpdatalen) {
153                                         /* Yes, there was a TPKT header
154                                          * received */
155                                         *data = tpkt;
156                                         *datalen = info->tpkt_len[dir];
157                                         *dataoff = 0;
158                                         goto out;
159                                 }
160
161                                 /* Fragmented TPKT */
162                                 pr_debug("nf_ct_h323: fragmented TPKT\n");
163                                 goto clear_out;
164                         }
165
166                         /* It is not even a TPKT */
167                         return 0;
168                 }
169                 tpktoff = 0;
170         } else {                /* Next TPKT */
171                 tpktoff = *dataoff + *datalen;
172                 tcpdatalen -= tpktoff;
173                 if (tcpdatalen <= 4)    /* No more TPKT */
174                         goto clear_out;
175                 tpkt = *data + *datalen;
176
177                 /* Validate TPKT identifier */
178                 if (tpkt[0] != 0x03 || tpkt[1] != 0)
179                         goto clear_out;
180         }
181
182         /* Validate TPKT length */
183         tpktlen = tpkt[2] * 256 + tpkt[3];
184         if (tpktlen < 4)
185                 goto clear_out;
186         if (tpktlen > tcpdatalen) {
187                 if (tcpdatalen == 4) {  /* Separate TPKT header */
188                         /* Netmeeting sends TPKT header and data separately */
189                         pr_debug("nf_ct_h323: separate TPKT header indicates "
190                                  "there will be TPKT data of %hu bytes\n",
191                                  tpktlen - 4);
192                         info->tpkt_len[dir] = tpktlen - 4;
193                         return 0;
194                 }
195
196                 if (net_ratelimit())
197                         printk("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                 printk("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         struct flowi fl1, fl2;
718         int ret = 0;
719
720         /* rcu_read_lock()ed by nf_hook_slow() */
721         afinfo = nf_get_afinfo(family);
722         if (!afinfo)
723                 return 0;
724
725         memset(&fl1, 0, sizeof(fl1));
726         memset(&fl2, 0, sizeof(fl2));
727
728         switch (family) {
729         case AF_INET: {
730                 struct rtable *rt1, *rt2;
731
732                 fl1.fl4_dst = src->ip;
733                 fl2.fl4_dst = dst->ip;
734                 if (!afinfo->route((struct dst_entry **)&rt1, &fl1)) {
735                         if (!afinfo->route((struct dst_entry **)&rt2, &fl2)) {
736                                 if (rt1->rt_gateway == rt2->rt_gateway &&
737                                     rt1->u.dst.dev  == rt2->u.dst.dev)
738                                         ret = 1;
739                                 dst_release(&rt2->u.dst);
740                         }
741                         dst_release(&rt1->u.dst);
742                 }
743                 break;
744         }
745 #if defined(CONFIG_NF_CONNTRACK_IPV6) || \
746     defined(CONFIG_NF_CONNTRACK_IPV6_MODULE)
747         case AF_INET6: {
748                 struct rt6_info *rt1, *rt2;
749
750                 memcpy(&fl1.fl6_dst, src, sizeof(fl1.fl6_dst));
751                 memcpy(&fl2.fl6_dst, dst, sizeof(fl2.fl6_dst));
752                 if (!afinfo->route((struct dst_entry **)&rt1, &fl1)) {
753                         if (!afinfo->route((struct dst_entry **)&rt2, &fl2)) {
754                                 if (!memcmp(&rt1->rt6i_gateway, &rt2->rt6i_gateway,
755                                             sizeof(rt1->rt6i_gateway)) &&
756                                     rt1->u.dst.dev == rt2->u.dst.dev)
757                                         ret = 1;
758                                 dst_release(&rt2->u.dst);
759                         }
760                         dst_release(&rt1->u.dst);
761                 }
762                 break;
763         }
764 #endif
765         }
766         return ret;
767
768 }
769
770 /****************************************************************************/
771 static int expect_callforwarding(struct sk_buff *skb,
772                                  struct nf_conn *ct,
773                                  enum ip_conntrack_info ctinfo,
774                                  unsigned char **data, int dataoff,
775                                  TransportAddress *taddr)
776 {
777         int dir = CTINFO2DIR(ctinfo);
778         int ret = 0;
779         __be16 port;
780         union nf_inet_addr addr;
781         struct nf_conntrack_expect *exp;
782         typeof(nat_callforwarding_hook) nat_callforwarding;
783
784         /* Read alternativeAddress */
785         if (!get_h225_addr(ct, *data, taddr, &addr, &port) || port == 0)
786                 return 0;
787
788         /* If the calling party is on the same side of the forward-to party,
789          * we don't need to track the second call */
790         if (callforward_filter &&
791             callforward_do_filter(&addr, &ct->tuplehash[!dir].tuple.src.u3,
792                                   nf_ct_l3num(ct))) {
793                 pr_debug("nf_ct_q931: Call Forwarding not tracked\n");
794                 return 0;
795         }
796
797         /* Create expect for the second call leg */
798         if ((exp = nf_ct_expect_alloc(ct)) == NULL)
799                 return -1;
800         nf_ct_expect_init(exp, NF_CT_EXPECT_CLASS_DEFAULT, nf_ct_l3num(ct),
801                           &ct->tuplehash[!dir].tuple.src.u3, &addr,
802                           IPPROTO_TCP, NULL, &port);
803         exp->helper = nf_conntrack_helper_q931;
804
805         if (memcmp(&ct->tuplehash[dir].tuple.src.u3,
806                    &ct->tuplehash[!dir].tuple.dst.u3,
807                    sizeof(ct->tuplehash[dir].tuple.src.u3)) &&
808             (nat_callforwarding = rcu_dereference(nat_callforwarding_hook)) &&
809             ct->status & IPS_NAT_MASK) {
810                 /* Need NAT */
811                 ret = nat_callforwarding(skb, ct, ctinfo, data, dataoff,
812                                          taddr, port, exp);
813         } else {                /* Conntrack only */
814                 if (nf_ct_expect_related(exp) == 0) {
815                         pr_debug("nf_ct_q931: expect Call Forwarding ");
816                         nf_ct_dump_tuple(&exp->tuple);
817                 } else
818                         ret = -1;
819         }
820
821         nf_ct_expect_put(exp);
822
823         return ret;
824 }
825
826 /****************************************************************************/
827 static int process_setup(struct sk_buff *skb, struct nf_conn *ct,
828                          enum ip_conntrack_info ctinfo,
829                          unsigned char **data, int dataoff,
830                          Setup_UUIE *setup)
831 {
832         int dir = CTINFO2DIR(ctinfo);
833         int ret;
834         int i;
835         __be16 port;
836         union nf_inet_addr addr;
837         typeof(set_h225_addr_hook) set_h225_addr;
838
839         pr_debug("nf_ct_q931: Setup\n");
840
841         if (setup->options & eSetup_UUIE_h245Address) {
842                 ret = expect_h245(skb, ct, ctinfo, data, dataoff,
843                                   &setup->h245Address);
844                 if (ret < 0)
845                         return -1;
846         }
847
848         set_h225_addr = rcu_dereference(set_h225_addr_hook);
849         if ((setup->options & eSetup_UUIE_destCallSignalAddress) &&
850             (set_h225_addr) && ct->status & IPS_NAT_MASK &&
851             get_h225_addr(ct, *data, &setup->destCallSignalAddress,
852                           &addr, &port) &&
853             memcmp(&addr, &ct->tuplehash[!dir].tuple.src.u3, sizeof(addr))) {
854                 pr_debug("nf_ct_q931: set destCallSignalAddress %pI6:%hu->%pI6:%hu\n",
855                          &addr, ntohs(port), &ct->tuplehash[!dir].tuple.src.u3,
856                          ntohs(ct->tuplehash[!dir].tuple.src.u.tcp.port));
857                 ret = set_h225_addr(skb, data, dataoff,
858                                     &setup->destCallSignalAddress,
859                                     &ct->tuplehash[!dir].tuple.src.u3,
860                                     ct->tuplehash[!dir].tuple.src.u.tcp.port);
861                 if (ret < 0)
862                         return -1;
863         }
864
865         if ((setup->options & eSetup_UUIE_sourceCallSignalAddress) &&
866             (set_h225_addr) && ct->status & IPS_NAT_MASK &&
867             get_h225_addr(ct, *data, &setup->sourceCallSignalAddress,
868                           &addr, &port) &&
869             memcmp(&addr, &ct->tuplehash[!dir].tuple.dst.u3, sizeof(addr))) {
870                 pr_debug("nf_ct_q931: set sourceCallSignalAddress %pI6:%hu->%pI6:%hu\n",
871                          &addr, ntohs(port), &ct->tuplehash[!dir].tuple.dst.u3,
872                          ntohs(ct->tuplehash[!dir].tuple.dst.u.tcp.port));
873                 ret = set_h225_addr(skb, data, dataoff,
874                                     &setup->sourceCallSignalAddress,
875                                     &ct->tuplehash[!dir].tuple.dst.u3,
876                                     ct->tuplehash[!dir].tuple.dst.u.tcp.port);
877                 if (ret < 0)
878                         return -1;
879         }
880
881         if (setup->options & eSetup_UUIE_fastStart) {
882                 for (i = 0; i < setup->fastStart.count; i++) {
883                         ret = process_olc(skb, ct, ctinfo, data, dataoff,
884                                           &setup->fastStart.item[i]);
885                         if (ret < 0)
886                                 return -1;
887                 }
888         }
889
890         return 0;
891 }
892
893 /****************************************************************************/
894 static int process_callproceeding(struct sk_buff *skb,
895                                   struct nf_conn *ct,
896                                   enum ip_conntrack_info ctinfo,
897                                   unsigned char **data, int dataoff,
898                                   CallProceeding_UUIE *callproc)
899 {
900         int ret;
901         int i;
902
903         pr_debug("nf_ct_q931: CallProceeding\n");
904
905         if (callproc->options & eCallProceeding_UUIE_h245Address) {
906                 ret = expect_h245(skb, ct, ctinfo, data, dataoff,
907                                   &callproc->h245Address);
908                 if (ret < 0)
909                         return -1;
910         }
911
912         if (callproc->options & eCallProceeding_UUIE_fastStart) {
913                 for (i = 0; i < callproc->fastStart.count; i++) {
914                         ret = process_olc(skb, ct, ctinfo, data, dataoff,
915                                           &callproc->fastStart.item[i]);
916                         if (ret < 0)
917                                 return -1;
918                 }
919         }
920
921         return 0;
922 }
923
924 /****************************************************************************/
925 static int process_connect(struct sk_buff *skb, struct nf_conn *ct,
926                            enum ip_conntrack_info ctinfo,
927                            unsigned char **data, int dataoff,
928                            Connect_UUIE *connect)
929 {
930         int ret;
931         int i;
932
933         pr_debug("nf_ct_q931: Connect\n");
934
935         if (connect->options & eConnect_UUIE_h245Address) {
936                 ret = expect_h245(skb, ct, ctinfo, data, dataoff,
937                                   &connect->h245Address);
938                 if (ret < 0)
939                         return -1;
940         }
941
942         if (connect->options & eConnect_UUIE_fastStart) {
943                 for (i = 0; i < connect->fastStart.count; i++) {
944                         ret = process_olc(skb, ct, ctinfo, data, dataoff,
945                                           &connect->fastStart.item[i]);
946                         if (ret < 0)
947                                 return -1;
948                 }
949         }
950
951         return 0;
952 }
953
954 /****************************************************************************/
955 static int process_alerting(struct sk_buff *skb, struct nf_conn *ct,
956                             enum ip_conntrack_info ctinfo,
957                             unsigned char **data, int dataoff,
958                             Alerting_UUIE *alert)
959 {
960         int ret;
961         int i;
962
963         pr_debug("nf_ct_q931: Alerting\n");
964
965         if (alert->options & eAlerting_UUIE_h245Address) {
966                 ret = expect_h245(skb, ct, ctinfo, data, dataoff,
967                                   &alert->h245Address);
968                 if (ret < 0)
969                         return -1;
970         }
971
972         if (alert->options & eAlerting_UUIE_fastStart) {
973                 for (i = 0; i < alert->fastStart.count; i++) {
974                         ret = process_olc(skb, ct, ctinfo, data, dataoff,
975                                           &alert->fastStart.item[i]);
976                         if (ret < 0)
977                                 return -1;
978                 }
979         }
980
981         return 0;
982 }
983
984 /****************************************************************************/
985 static int process_facility(struct sk_buff *skb, struct nf_conn *ct,
986                             enum ip_conntrack_info ctinfo,
987                             unsigned char **data, int dataoff,
988                             Facility_UUIE *facility)
989 {
990         int ret;
991         int i;
992
993         pr_debug("nf_ct_q931: Facility\n");
994
995         if (facility->reason.choice == eFacilityReason_callForwarded) {
996                 if (facility->options & eFacility_UUIE_alternativeAddress)
997                         return expect_callforwarding(skb, ct, ctinfo, data,
998                                                      dataoff,
999                                                      &facility->
1000                                                      alternativeAddress);
1001                 return 0;
1002         }
1003
1004         if (facility->options & eFacility_UUIE_h245Address) {
1005                 ret = expect_h245(skb, ct, ctinfo, data, dataoff,
1006                                   &facility->h245Address);
1007                 if (ret < 0)
1008                         return -1;
1009         }
1010
1011         if (facility->options & eFacility_UUIE_fastStart) {
1012                 for (i = 0; i < facility->fastStart.count; i++) {
1013                         ret = process_olc(skb, ct, ctinfo, data, dataoff,
1014                                           &facility->fastStart.item[i]);
1015                         if (ret < 0)
1016                                 return -1;
1017                 }
1018         }
1019
1020         return 0;
1021 }
1022
1023 /****************************************************************************/
1024 static int process_progress(struct sk_buff *skb, struct nf_conn *ct,
1025                             enum ip_conntrack_info ctinfo,
1026                             unsigned char **data, int dataoff,
1027                             Progress_UUIE *progress)
1028 {
1029         int ret;
1030         int i;
1031
1032         pr_debug("nf_ct_q931: Progress\n");
1033
1034         if (progress->options & eProgress_UUIE_h245Address) {
1035                 ret = expect_h245(skb, ct, ctinfo, data, dataoff,
1036                                   &progress->h245Address);
1037                 if (ret < 0)
1038                         return -1;
1039         }
1040
1041         if (progress->options & eProgress_UUIE_fastStart) {
1042                 for (i = 0; i < progress->fastStart.count; i++) {
1043                         ret = process_olc(skb, ct, ctinfo, data, dataoff,
1044                                           &progress->fastStart.item[i]);
1045                         if (ret < 0)
1046                                 return -1;
1047                 }
1048         }
1049
1050         return 0;
1051 }
1052
1053 /****************************************************************************/
1054 static int process_q931(struct sk_buff *skb, struct nf_conn *ct,
1055                         enum ip_conntrack_info ctinfo,
1056                         unsigned char **data, int dataoff, Q931 *q931)
1057 {
1058         H323_UU_PDU *pdu = &q931->UUIE.h323_uu_pdu;
1059         int i;
1060         int ret = 0;
1061
1062         switch (pdu->h323_message_body.choice) {
1063         case eH323_UU_PDU_h323_message_body_setup:
1064                 ret = process_setup(skb, ct, ctinfo, data, dataoff,
1065                                     &pdu->h323_message_body.setup);
1066                 break;
1067         case eH323_UU_PDU_h323_message_body_callProceeding:
1068                 ret = process_callproceeding(skb, ct, ctinfo, data, dataoff,
1069                                              &pdu->h323_message_body.
1070                                              callProceeding);
1071                 break;
1072         case eH323_UU_PDU_h323_message_body_connect:
1073                 ret = process_connect(skb, ct, ctinfo, data, dataoff,
1074                                       &pdu->h323_message_body.connect);
1075                 break;
1076         case eH323_UU_PDU_h323_message_body_alerting:
1077                 ret = process_alerting(skb, ct, ctinfo, data, dataoff,
1078                                        &pdu->h323_message_body.alerting);
1079                 break;
1080         case eH323_UU_PDU_h323_message_body_facility:
1081                 ret = process_facility(skb, ct, ctinfo, data, dataoff,
1082                                        &pdu->h323_message_body.facility);
1083                 break;
1084         case eH323_UU_PDU_h323_message_body_progress:
1085                 ret = process_progress(skb, ct, ctinfo, data, dataoff,
1086                                        &pdu->h323_message_body.progress);
1087                 break;
1088         default:
1089                 pr_debug("nf_ct_q931: Q.931 signal %d\n",
1090                          pdu->h323_message_body.choice);
1091                 break;
1092         }
1093
1094         if (ret < 0)
1095                 return -1;
1096
1097         if (pdu->options & eH323_UU_PDU_h245Control) {
1098                 for (i = 0; i < pdu->h245Control.count; i++) {
1099                         ret = process_h245(skb, ct, ctinfo, data, dataoff,
1100                                            &pdu->h245Control.item[i]);
1101                         if (ret < 0)
1102                                 return -1;
1103                 }
1104         }
1105
1106         return 0;
1107 }
1108
1109 /****************************************************************************/
1110 static int q931_help(struct sk_buff *skb, unsigned int protoff,
1111                      struct nf_conn *ct, enum ip_conntrack_info ctinfo)
1112 {
1113         static Q931 q931;
1114         unsigned char *data = NULL;
1115         int datalen;
1116         int dataoff;
1117         int ret;
1118
1119         /* Until there's been traffic both ways, don't look in packets. */
1120         if (ctinfo != IP_CT_ESTABLISHED &&
1121             ctinfo != IP_CT_ESTABLISHED + IP_CT_IS_REPLY) {
1122                 return NF_ACCEPT;
1123         }
1124         pr_debug("nf_ct_q931: skblen = %u\n", skb->len);
1125
1126         spin_lock_bh(&nf_h323_lock);
1127
1128         /* Process each TPKT */
1129         while (get_tpkt_data(skb, protoff, ct, ctinfo,
1130                              &data, &datalen, &dataoff)) {
1131                 pr_debug("nf_ct_q931: TPKT len=%d ", datalen);
1132                 nf_ct_dump_tuple(&ct->tuplehash[CTINFO2DIR(ctinfo)].tuple);
1133
1134                 /* Decode Q.931 signal */
1135                 ret = DecodeQ931(data, datalen, &q931);
1136                 if (ret < 0) {
1137                         pr_debug("nf_ct_q931: decoding error: %s\n",
1138                                  ret == H323_ERROR_BOUND ?
1139                                  "out of bound" : "out of range");
1140                         /* We don't drop when decoding error */
1141                         break;
1142                 }
1143
1144                 /* Process Q.931 signal */
1145                 if (process_q931(skb, ct, ctinfo, &data, dataoff, &q931) < 0)
1146                         goto drop;
1147         }
1148
1149         spin_unlock_bh(&nf_h323_lock);
1150         return NF_ACCEPT;
1151
1152       drop:
1153         spin_unlock_bh(&nf_h323_lock);
1154         if (net_ratelimit())
1155                 printk("nf_ct_q931: packet dropped\n");
1156         return NF_DROP;
1157 }
1158
1159 /****************************************************************************/
1160 static const struct nf_conntrack_expect_policy q931_exp_policy = {
1161         /* T.120 and H.245 */
1162         .max_expected           = H323_RTP_CHANNEL_MAX * 4 + 4,
1163         .timeout                = 240,
1164 };
1165
1166 static struct nf_conntrack_helper nf_conntrack_helper_q931[] __read_mostly = {
1167         {
1168                 .name                   = "Q.931",
1169                 .me                     = THIS_MODULE,
1170                 .tuple.src.l3num        = AF_INET,
1171                 .tuple.src.u.tcp.port   = cpu_to_be16(Q931_PORT),
1172                 .tuple.dst.protonum     = IPPROTO_TCP,
1173                 .help                   = q931_help,
1174                 .expect_policy          = &q931_exp_policy,
1175         },
1176         {
1177                 .name                   = "Q.931",
1178                 .me                     = THIS_MODULE,
1179                 .tuple.src.l3num        = AF_INET6,
1180                 .tuple.src.u.tcp.port   = cpu_to_be16(Q931_PORT),
1181                 .tuple.dst.protonum     = IPPROTO_TCP,
1182                 .help                   = q931_help,
1183                 .expect_policy          = &q931_exp_policy,
1184         },
1185 };
1186
1187 /****************************************************************************/
1188 static unsigned char *get_udp_data(struct sk_buff *skb, unsigned int protoff,
1189                                    int *datalen)
1190 {
1191         const struct udphdr *uh;
1192         struct udphdr _uh;
1193         int dataoff;
1194
1195         uh = skb_header_pointer(skb, protoff, sizeof(_uh), &_uh);
1196         if (uh == NULL)
1197                 return NULL;
1198         dataoff = protoff + sizeof(_uh);
1199         if (dataoff >= skb->len)
1200                 return NULL;
1201         *datalen = skb->len - dataoff;
1202         return skb_header_pointer(skb, dataoff, *datalen, h323_buffer);
1203 }
1204
1205 /****************************************************************************/
1206 static struct nf_conntrack_expect *find_expect(struct nf_conn *ct,
1207                                                union nf_inet_addr *addr,
1208                                                __be16 port)
1209 {
1210         struct net *net = nf_ct_net(ct);
1211         struct nf_conntrack_expect *exp;
1212         struct nf_conntrack_tuple tuple;
1213
1214         memset(&tuple.src.u3, 0, sizeof(tuple.src.u3));
1215         tuple.src.u.tcp.port = 0;
1216         memcpy(&tuple.dst.u3, addr, sizeof(tuple.dst.u3));
1217         tuple.dst.u.tcp.port = port;
1218         tuple.dst.protonum = IPPROTO_TCP;
1219
1220         exp = __nf_ct_expect_find(net, nf_ct_zone(ct), &tuple);
1221         if (exp && exp->master == ct)
1222                 return exp;
1223         return NULL;
1224 }
1225
1226 /****************************************************************************/
1227 static int set_expect_timeout(struct nf_conntrack_expect *exp,
1228                               unsigned timeout)
1229 {
1230         if (!exp || !del_timer(&exp->timeout))
1231                 return 0;
1232
1233         exp->timeout.expires = jiffies + timeout * HZ;
1234         add_timer(&exp->timeout);
1235
1236         return 1;
1237 }
1238
1239 /****************************************************************************/
1240 static int expect_q931(struct sk_buff *skb, struct nf_conn *ct,
1241                        enum ip_conntrack_info ctinfo,
1242                        unsigned char **data,
1243                        TransportAddress *taddr, int count)
1244 {
1245         struct nf_ct_h323_master *info = &nfct_help(ct)->help.ct_h323_info;
1246         int dir = CTINFO2DIR(ctinfo);
1247         int ret = 0;
1248         int i;
1249         __be16 port;
1250         union nf_inet_addr addr;
1251         struct nf_conntrack_expect *exp;
1252         typeof(nat_q931_hook) nat_q931;
1253
1254         /* Look for the first related address */
1255         for (i = 0; i < count; i++) {
1256                 if (get_h225_addr(ct, *data, &taddr[i], &addr, &port) &&
1257                     memcmp(&addr, &ct->tuplehash[dir].tuple.src.u3,
1258                            sizeof(addr)) == 0 && port != 0)
1259                         break;
1260         }
1261
1262         if (i >= count)         /* Not found */
1263                 return 0;
1264
1265         /* Create expect for Q.931 */
1266         if ((exp = nf_ct_expect_alloc(ct)) == NULL)
1267                 return -1;
1268         nf_ct_expect_init(exp, NF_CT_EXPECT_CLASS_DEFAULT, nf_ct_l3num(ct),
1269                           gkrouted_only ? /* only accept calls from GK? */
1270                                 &ct->tuplehash[!dir].tuple.src.u3 : NULL,
1271                           &ct->tuplehash[!dir].tuple.dst.u3,
1272                           IPPROTO_TCP, NULL, &port);
1273         exp->helper = nf_conntrack_helper_q931;
1274         exp->flags = NF_CT_EXPECT_PERMANENT;    /* Accept multiple calls */
1275
1276         nat_q931 = rcu_dereference(nat_q931_hook);
1277         if (nat_q931 && ct->status & IPS_NAT_MASK) {    /* Need NAT */
1278                 ret = nat_q931(skb, ct, ctinfo, data, taddr, i, port, exp);
1279         } else {                /* Conntrack only */
1280                 if (nf_ct_expect_related(exp) == 0) {
1281                         pr_debug("nf_ct_ras: expect Q.931 ");
1282                         nf_ct_dump_tuple(&exp->tuple);
1283
1284                         /* Save port for looking up expect in processing RCF */
1285                         info->sig_port[dir] = port;
1286                 } else
1287                         ret = -1;
1288         }
1289
1290         nf_ct_expect_put(exp);
1291
1292         return ret;
1293 }
1294
1295 /****************************************************************************/
1296 static int process_grq(struct sk_buff *skb, struct nf_conn *ct,
1297                        enum ip_conntrack_info ctinfo,
1298                        unsigned char **data, GatekeeperRequest *grq)
1299 {
1300         typeof(set_ras_addr_hook) set_ras_addr;
1301
1302         pr_debug("nf_ct_ras: GRQ\n");
1303
1304         set_ras_addr = rcu_dereference(set_ras_addr_hook);
1305         if (set_ras_addr && ct->status & IPS_NAT_MASK)  /* NATed */
1306                 return set_ras_addr(skb, ct, ctinfo, data,
1307                                     &grq->rasAddress, 1);
1308         return 0;
1309 }
1310
1311 /****************************************************************************/
1312 static int process_gcf(struct sk_buff *skb, struct nf_conn *ct,
1313                        enum ip_conntrack_info ctinfo,
1314                        unsigned char **data, GatekeeperConfirm *gcf)
1315 {
1316         int dir = CTINFO2DIR(ctinfo);
1317         int ret = 0;
1318         __be16 port;
1319         union nf_inet_addr addr;
1320         struct nf_conntrack_expect *exp;
1321
1322         pr_debug("nf_ct_ras: GCF\n");
1323
1324         if (!get_h225_addr(ct, *data, &gcf->rasAddress, &addr, &port))
1325                 return 0;
1326
1327         /* Registration port is the same as discovery port */
1328         if (!memcmp(&addr, &ct->tuplehash[dir].tuple.src.u3, sizeof(addr)) &&
1329             port == ct->tuplehash[dir].tuple.src.u.udp.port)
1330                 return 0;
1331
1332         /* Avoid RAS expectation loops. A GCF is never expected. */
1333         if (test_bit(IPS_EXPECTED_BIT, &ct->status))
1334                 return 0;
1335
1336         /* Need new expect */
1337         if ((exp = nf_ct_expect_alloc(ct)) == NULL)
1338                 return -1;
1339         nf_ct_expect_init(exp, NF_CT_EXPECT_CLASS_DEFAULT, nf_ct_l3num(ct),
1340                           &ct->tuplehash[!dir].tuple.src.u3, &addr,
1341                           IPPROTO_UDP, NULL, &port);
1342         exp->helper = nf_conntrack_helper_ras;
1343
1344         if (nf_ct_expect_related(exp) == 0) {
1345                 pr_debug("nf_ct_ras: expect RAS ");
1346                 nf_ct_dump_tuple(&exp->tuple);
1347         } else
1348                 ret = -1;
1349
1350         nf_ct_expect_put(exp);
1351
1352         return ret;
1353 }
1354
1355 /****************************************************************************/
1356 static int process_rrq(struct sk_buff *skb, struct nf_conn *ct,
1357                        enum ip_conntrack_info ctinfo,
1358                        unsigned char **data, RegistrationRequest *rrq)
1359 {
1360         struct nf_ct_h323_master *info = &nfct_help(ct)->help.ct_h323_info;
1361         int ret;
1362         typeof(set_ras_addr_hook) set_ras_addr;
1363
1364         pr_debug("nf_ct_ras: RRQ\n");
1365
1366         ret = expect_q931(skb, ct, ctinfo, data,
1367                           rrq->callSignalAddress.item,
1368                           rrq->callSignalAddress.count);
1369         if (ret < 0)
1370                 return -1;
1371
1372         set_ras_addr = rcu_dereference(set_ras_addr_hook);
1373         if (set_ras_addr && ct->status & IPS_NAT_MASK) {
1374                 ret = set_ras_addr(skb, ct, ctinfo, data,
1375                                    rrq->rasAddress.item,
1376                                    rrq->rasAddress.count);
1377                 if (ret < 0)
1378                         return -1;
1379         }
1380
1381         if (rrq->options & eRegistrationRequest_timeToLive) {
1382                 pr_debug("nf_ct_ras: RRQ TTL = %u seconds\n", rrq->timeToLive);
1383                 info->timeout = rrq->timeToLive;
1384         } else
1385                 info->timeout = default_rrq_ttl;
1386
1387         return 0;
1388 }
1389
1390 /****************************************************************************/
1391 static int process_rcf(struct sk_buff *skb, struct nf_conn *ct,
1392                        enum ip_conntrack_info ctinfo,
1393                        unsigned char **data, RegistrationConfirm *rcf)
1394 {
1395         struct nf_ct_h323_master *info = &nfct_help(ct)->help.ct_h323_info;
1396         int dir = CTINFO2DIR(ctinfo);
1397         int ret;
1398         struct nf_conntrack_expect *exp;
1399         typeof(set_sig_addr_hook) set_sig_addr;
1400
1401         pr_debug("nf_ct_ras: RCF\n");
1402
1403         set_sig_addr = rcu_dereference(set_sig_addr_hook);
1404         if (set_sig_addr && ct->status & IPS_NAT_MASK) {
1405                 ret = set_sig_addr(skb, ct, ctinfo, data,
1406                                         rcf->callSignalAddress.item,
1407                                         rcf->callSignalAddress.count);
1408                 if (ret < 0)
1409                         return -1;
1410         }
1411
1412         if (rcf->options & eRegistrationConfirm_timeToLive) {
1413                 pr_debug("nf_ct_ras: RCF TTL = %u seconds\n", rcf->timeToLive);
1414                 info->timeout = rcf->timeToLive;
1415         }
1416
1417         if (info->timeout > 0) {
1418                 pr_debug("nf_ct_ras: set RAS connection timeout to "
1419                          "%u seconds\n", info->timeout);
1420                 nf_ct_refresh(ct, skb, info->timeout * HZ);
1421
1422                 /* Set expect timeout */
1423                 spin_lock_bh(&nf_conntrack_lock);
1424                 exp = find_expect(ct, &ct->tuplehash[dir].tuple.dst.u3,
1425                                   info->sig_port[!dir]);
1426                 if (exp) {
1427                         pr_debug("nf_ct_ras: set Q.931 expect "
1428                                  "timeout to %u seconds for",
1429                                  info->timeout);
1430                         nf_ct_dump_tuple(&exp->tuple);
1431                         set_expect_timeout(exp, info->timeout);
1432                 }
1433                 spin_unlock_bh(&nf_conntrack_lock);
1434         }
1435
1436         return 0;
1437 }
1438
1439 /****************************************************************************/
1440 static int process_urq(struct sk_buff *skb, struct nf_conn *ct,
1441                        enum ip_conntrack_info ctinfo,
1442                        unsigned char **data, UnregistrationRequest *urq)
1443 {
1444         struct nf_ct_h323_master *info = &nfct_help(ct)->help.ct_h323_info;
1445         int dir = CTINFO2DIR(ctinfo);
1446         int ret;
1447         typeof(set_sig_addr_hook) set_sig_addr;
1448
1449         pr_debug("nf_ct_ras: URQ\n");
1450
1451         set_sig_addr = rcu_dereference(set_sig_addr_hook);
1452         if (set_sig_addr && ct->status & IPS_NAT_MASK) {
1453                 ret = set_sig_addr(skb, ct, ctinfo, data,
1454                                    urq->callSignalAddress.item,
1455                                    urq->callSignalAddress.count);
1456                 if (ret < 0)
1457                         return -1;
1458         }
1459
1460         /* Clear old expect */
1461         nf_ct_remove_expectations(ct);
1462         info->sig_port[dir] = 0;
1463         info->sig_port[!dir] = 0;
1464
1465         /* Give it 30 seconds for UCF or URJ */
1466         nf_ct_refresh(ct, skb, 30 * HZ);
1467
1468         return 0;
1469 }
1470
1471 /****************************************************************************/
1472 static int process_arq(struct sk_buff *skb, struct nf_conn *ct,
1473                        enum ip_conntrack_info ctinfo,
1474                        unsigned char **data, AdmissionRequest *arq)
1475 {
1476         const struct nf_ct_h323_master *info = &nfct_help(ct)->help.ct_h323_info;
1477         int dir = CTINFO2DIR(ctinfo);
1478         __be16 port;
1479         union nf_inet_addr addr;
1480         typeof(set_h225_addr_hook) set_h225_addr;
1481
1482         pr_debug("nf_ct_ras: ARQ\n");
1483
1484         set_h225_addr = rcu_dereference(set_h225_addr_hook);
1485         if ((arq->options & eAdmissionRequest_destCallSignalAddress) &&
1486             get_h225_addr(ct, *data, &arq->destCallSignalAddress,
1487                           &addr, &port) &&
1488             !memcmp(&addr, &ct->tuplehash[dir].tuple.src.u3, sizeof(addr)) &&
1489             port == info->sig_port[dir] &&
1490             set_h225_addr && ct->status & IPS_NAT_MASK) {
1491                 /* Answering ARQ */
1492                 return set_h225_addr(skb, data, 0,
1493                                      &arq->destCallSignalAddress,
1494                                      &ct->tuplehash[!dir].tuple.dst.u3,
1495                                      info->sig_port[!dir]);
1496         }
1497
1498         if ((arq->options & eAdmissionRequest_srcCallSignalAddress) &&
1499             get_h225_addr(ct, *data, &arq->srcCallSignalAddress,
1500                           &addr, &port) &&
1501             !memcmp(&addr, &ct->tuplehash[dir].tuple.src.u3, sizeof(addr)) &&
1502             set_h225_addr && ct->status & IPS_NAT_MASK) {
1503                 /* Calling ARQ */
1504                 return set_h225_addr(skb, data, 0,
1505                                      &arq->srcCallSignalAddress,
1506                                      &ct->tuplehash[!dir].tuple.dst.u3,
1507                                      port);
1508         }
1509
1510         return 0;
1511 }
1512
1513 /****************************************************************************/
1514 static int process_acf(struct sk_buff *skb, struct nf_conn *ct,
1515                        enum ip_conntrack_info ctinfo,
1516                        unsigned char **data, AdmissionConfirm *acf)
1517 {
1518         int dir = CTINFO2DIR(ctinfo);
1519         int ret = 0;
1520         __be16 port;
1521         union nf_inet_addr addr;
1522         struct nf_conntrack_expect *exp;
1523         typeof(set_sig_addr_hook) set_sig_addr;
1524
1525         pr_debug("nf_ct_ras: ACF\n");
1526
1527         if (!get_h225_addr(ct, *data, &acf->destCallSignalAddress,
1528                            &addr, &port))
1529                 return 0;
1530
1531         if (!memcmp(&addr, &ct->tuplehash[dir].tuple.dst.u3, sizeof(addr))) {
1532                 /* Answering ACF */
1533                 set_sig_addr = rcu_dereference(set_sig_addr_hook);
1534                 if (set_sig_addr && ct->status & IPS_NAT_MASK)
1535                         return set_sig_addr(skb, ct, ctinfo, data,
1536                                             &acf->destCallSignalAddress, 1);
1537                 return 0;
1538         }
1539
1540         /* Need new expect */
1541         if ((exp = nf_ct_expect_alloc(ct)) == NULL)
1542                 return -1;
1543         nf_ct_expect_init(exp, NF_CT_EXPECT_CLASS_DEFAULT, nf_ct_l3num(ct),
1544                           &ct->tuplehash[!dir].tuple.src.u3, &addr,
1545                           IPPROTO_TCP, NULL, &port);
1546         exp->flags = NF_CT_EXPECT_PERMANENT;
1547         exp->helper = nf_conntrack_helper_q931;
1548
1549         if (nf_ct_expect_related(exp) == 0) {
1550                 pr_debug("nf_ct_ras: expect Q.931 ");
1551                 nf_ct_dump_tuple(&exp->tuple);
1552         } else
1553                 ret = -1;
1554
1555         nf_ct_expect_put(exp);
1556
1557         return ret;
1558 }
1559
1560 /****************************************************************************/
1561 static int process_lrq(struct sk_buff *skb, struct nf_conn *ct,
1562                        enum ip_conntrack_info ctinfo,
1563                        unsigned char **data, LocationRequest *lrq)
1564 {
1565         typeof(set_ras_addr_hook) set_ras_addr;
1566
1567         pr_debug("nf_ct_ras: LRQ\n");
1568
1569         set_ras_addr = rcu_dereference(set_ras_addr_hook);
1570         if (set_ras_addr && ct->status & IPS_NAT_MASK)
1571                 return set_ras_addr(skb, ct, ctinfo, data,
1572                                     &lrq->replyAddress, 1);
1573         return 0;
1574 }
1575
1576 /****************************************************************************/
1577 static int process_lcf(struct sk_buff *skb, struct nf_conn *ct,
1578                        enum ip_conntrack_info ctinfo,
1579                        unsigned char **data, LocationConfirm *lcf)
1580 {
1581         int dir = CTINFO2DIR(ctinfo);
1582         int ret = 0;
1583         __be16 port;
1584         union nf_inet_addr addr;
1585         struct nf_conntrack_expect *exp;
1586
1587         pr_debug("nf_ct_ras: LCF\n");
1588
1589         if (!get_h225_addr(ct, *data, &lcf->callSignalAddress,
1590                            &addr, &port))
1591                 return 0;
1592
1593         /* Need new expect for call signal */
1594         if ((exp = nf_ct_expect_alloc(ct)) == NULL)
1595                 return -1;
1596         nf_ct_expect_init(exp, NF_CT_EXPECT_CLASS_DEFAULT, nf_ct_l3num(ct),
1597                           &ct->tuplehash[!dir].tuple.src.u3, &addr,
1598                           IPPROTO_TCP, NULL, &port);
1599         exp->flags = NF_CT_EXPECT_PERMANENT;
1600         exp->helper = nf_conntrack_helper_q931;
1601
1602         if (nf_ct_expect_related(exp) == 0) {
1603                 pr_debug("nf_ct_ras: expect Q.931 ");
1604                 nf_ct_dump_tuple(&exp->tuple);
1605         } else
1606                 ret = -1;
1607
1608         nf_ct_expect_put(exp);
1609
1610         /* Ignore rasAddress */
1611
1612         return ret;
1613 }
1614
1615 /****************************************************************************/
1616 static int process_irr(struct sk_buff *skb, struct nf_conn *ct,
1617                        enum ip_conntrack_info ctinfo,
1618                        unsigned char **data, InfoRequestResponse *irr)
1619 {
1620         int ret;
1621         typeof(set_ras_addr_hook) set_ras_addr;
1622         typeof(set_sig_addr_hook) set_sig_addr;
1623
1624         pr_debug("nf_ct_ras: IRR\n");
1625
1626         set_ras_addr = rcu_dereference(set_ras_addr_hook);
1627         if (set_ras_addr && ct->status & IPS_NAT_MASK) {
1628                 ret = set_ras_addr(skb, ct, ctinfo, data,
1629                                    &irr->rasAddress, 1);
1630                 if (ret < 0)
1631                         return -1;
1632         }
1633
1634         set_sig_addr = rcu_dereference(set_sig_addr_hook);
1635         if (set_sig_addr && ct->status & IPS_NAT_MASK) {
1636                 ret = set_sig_addr(skb, ct, ctinfo, data,
1637                                         irr->callSignalAddress.item,
1638                                         irr->callSignalAddress.count);
1639                 if (ret < 0)
1640                         return -1;
1641         }
1642
1643         return 0;
1644 }
1645
1646 /****************************************************************************/
1647 static int process_ras(struct sk_buff *skb, struct nf_conn *ct,
1648                        enum ip_conntrack_info ctinfo,
1649                        unsigned char **data, RasMessage *ras)
1650 {
1651         switch (ras->choice) {
1652         case eRasMessage_gatekeeperRequest:
1653                 return process_grq(skb, ct, ctinfo, data,
1654                                    &ras->gatekeeperRequest);
1655         case eRasMessage_gatekeeperConfirm:
1656                 return process_gcf(skb, ct, ctinfo, data,
1657                                    &ras->gatekeeperConfirm);
1658         case eRasMessage_registrationRequest:
1659                 return process_rrq(skb, ct, ctinfo, data,
1660                                    &ras->registrationRequest);
1661         case eRasMessage_registrationConfirm:
1662                 return process_rcf(skb, ct, ctinfo, data,
1663                                    &ras->registrationConfirm);
1664         case eRasMessage_unregistrationRequest:
1665                 return process_urq(skb, ct, ctinfo, data,
1666                                    &ras->unregistrationRequest);
1667         case eRasMessage_admissionRequest:
1668                 return process_arq(skb, ct, ctinfo, data,
1669                                    &ras->admissionRequest);
1670         case eRasMessage_admissionConfirm:
1671                 return process_acf(skb, ct, ctinfo, data,
1672                                    &ras->admissionConfirm);
1673         case eRasMessage_locationRequest:
1674                 return process_lrq(skb, ct, ctinfo, data,
1675                                    &ras->locationRequest);
1676         case eRasMessage_locationConfirm:
1677                 return process_lcf(skb, ct, ctinfo, data,
1678                                    &ras->locationConfirm);
1679         case eRasMessage_infoRequestResponse:
1680                 return process_irr(skb, ct, ctinfo, data,
1681                                    &ras->infoRequestResponse);
1682         default:
1683                 pr_debug("nf_ct_ras: RAS message %d\n", ras->choice);
1684                 break;
1685         }
1686
1687         return 0;
1688 }
1689
1690 /****************************************************************************/
1691 static int ras_help(struct sk_buff *skb, unsigned int protoff,
1692                     struct nf_conn *ct, enum ip_conntrack_info ctinfo)
1693 {
1694         static RasMessage ras;
1695         unsigned char *data;
1696         int datalen = 0;
1697         int ret;
1698
1699         pr_debug("nf_ct_ras: skblen = %u\n", skb->len);
1700
1701         spin_lock_bh(&nf_h323_lock);
1702
1703         /* Get UDP data */
1704         data = get_udp_data(skb, protoff, &datalen);
1705         if (data == NULL)
1706                 goto accept;
1707         pr_debug("nf_ct_ras: RAS message len=%d ", datalen);
1708         nf_ct_dump_tuple(&ct->tuplehash[CTINFO2DIR(ctinfo)].tuple);
1709
1710         /* Decode RAS message */
1711         ret = DecodeRasMessage(data, datalen, &ras);
1712         if (ret < 0) {
1713                 pr_debug("nf_ct_ras: decoding error: %s\n",
1714                          ret == H323_ERROR_BOUND ?
1715                          "out of bound" : "out of range");
1716                 goto accept;
1717         }
1718
1719         /* Process RAS message */
1720         if (process_ras(skb, ct, ctinfo, &data, &ras) < 0)
1721                 goto drop;
1722
1723       accept:
1724         spin_unlock_bh(&nf_h323_lock);
1725         return NF_ACCEPT;
1726
1727       drop:
1728         spin_unlock_bh(&nf_h323_lock);
1729         if (net_ratelimit())
1730                 printk("nf_ct_ras: packet dropped\n");
1731         return NF_DROP;
1732 }
1733
1734 /****************************************************************************/
1735 static const struct nf_conntrack_expect_policy ras_exp_policy = {
1736         .max_expected           = 32,
1737         .timeout                = 240,
1738 };
1739
1740 static struct nf_conntrack_helper nf_conntrack_helper_ras[] __read_mostly = {
1741         {
1742                 .name                   = "RAS",
1743                 .me                     = THIS_MODULE,
1744                 .tuple.src.l3num        = AF_INET,
1745                 .tuple.src.u.udp.port   = cpu_to_be16(RAS_PORT),
1746                 .tuple.dst.protonum     = IPPROTO_UDP,
1747                 .help                   = ras_help,
1748                 .expect_policy          = &ras_exp_policy,
1749         },
1750         {
1751                 .name                   = "RAS",
1752                 .me                     = THIS_MODULE,
1753                 .tuple.src.l3num        = AF_INET6,
1754                 .tuple.src.u.udp.port   = cpu_to_be16(RAS_PORT),
1755                 .tuple.dst.protonum     = IPPROTO_UDP,
1756                 .help                   = ras_help,
1757                 .expect_policy          = &ras_exp_policy,
1758         },
1759 };
1760
1761 /****************************************************************************/
1762 static void __exit nf_conntrack_h323_fini(void)
1763 {
1764         nf_conntrack_helper_unregister(&nf_conntrack_helper_ras[1]);
1765         nf_conntrack_helper_unregister(&nf_conntrack_helper_ras[0]);
1766         nf_conntrack_helper_unregister(&nf_conntrack_helper_q931[1]);
1767         nf_conntrack_helper_unregister(&nf_conntrack_helper_q931[0]);
1768         nf_conntrack_helper_unregister(&nf_conntrack_helper_h245);
1769         kfree(h323_buffer);
1770         pr_debug("nf_ct_h323: fini\n");
1771 }
1772
1773 /****************************************************************************/
1774 static int __init nf_conntrack_h323_init(void)
1775 {
1776         int ret;
1777
1778         h323_buffer = kmalloc(65536, GFP_KERNEL);
1779         if (!h323_buffer)
1780                 return -ENOMEM;
1781         ret = nf_conntrack_helper_register(&nf_conntrack_helper_h245);
1782         if (ret < 0)
1783                 goto err1;
1784         ret = nf_conntrack_helper_register(&nf_conntrack_helper_q931[0]);
1785         if (ret < 0)
1786                 goto err2;
1787         ret = nf_conntrack_helper_register(&nf_conntrack_helper_q931[1]);
1788         if (ret < 0)
1789                 goto err3;
1790         ret = nf_conntrack_helper_register(&nf_conntrack_helper_ras[0]);
1791         if (ret < 0)
1792                 goto err4;
1793         ret = nf_conntrack_helper_register(&nf_conntrack_helper_ras[1]);
1794         if (ret < 0)
1795                 goto err5;
1796         pr_debug("nf_ct_h323: init success\n");
1797         return 0;
1798
1799 err5:
1800         nf_conntrack_helper_unregister(&nf_conntrack_helper_ras[0]);
1801 err4:
1802         nf_conntrack_helper_unregister(&nf_conntrack_helper_q931[1]);
1803 err3:
1804         nf_conntrack_helper_unregister(&nf_conntrack_helper_q931[0]);
1805 err2:
1806         nf_conntrack_helper_unregister(&nf_conntrack_helper_h245);
1807 err1:
1808         kfree(h323_buffer);
1809         return ret;
1810 }
1811
1812 /****************************************************************************/
1813 module_init(nf_conntrack_h323_init);
1814 module_exit(nf_conntrack_h323_fini);
1815
1816 EXPORT_SYMBOL_GPL(get_h225_addr);
1817 EXPORT_SYMBOL_GPL(set_h245_addr_hook);
1818 EXPORT_SYMBOL_GPL(set_h225_addr_hook);
1819 EXPORT_SYMBOL_GPL(set_sig_addr_hook);
1820 EXPORT_SYMBOL_GPL(set_ras_addr_hook);
1821 EXPORT_SYMBOL_GPL(nat_rtp_rtcp_hook);
1822 EXPORT_SYMBOL_GPL(nat_t120_hook);
1823 EXPORT_SYMBOL_GPL(nat_h245_hook);
1824 EXPORT_SYMBOL_GPL(nat_callforwarding_hook);
1825 EXPORT_SYMBOL_GPL(nat_q931_hook);
1826
1827 MODULE_AUTHOR("Jing Min Zhao <zhaojingmin@users.sourceforge.net>");
1828 MODULE_DESCRIPTION("H.323 connection tracking helper");
1829 MODULE_LICENSE("GPL");
1830 MODULE_ALIAS("ip_conntrack_h323");
1831 MODULE_ALIAS_NFCT_HELPER("h323");