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