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