2 * H.323 connection tracking helper
4 * Copyright (c) 2006 Jing Min Zhao <zhaojingmin@users.sourceforge.net>
6 * This source code is licensed under General Public License version 2.
8 * Based on the 'brute force' H.323 connection tracking module by
9 * Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
11 * For more information, please see http://nath323.sourceforge.net/
14 #include <linux/module.h>
15 #include <linux/moduleparam.h>
16 #include <linux/ctype.h>
17 #include <linux/inet.h>
20 #include <linux/udp.h>
21 #include <linux/tcp.h>
22 #include <linux/skbuff.h>
23 #include <net/route.h>
24 #include <net/ip6_route.h>
26 #include <net/netfilter/nf_conntrack.h>
27 #include <net/netfilter/nf_conntrack_core.h>
28 #include <net/netfilter/nf_conntrack_tuple.h>
29 #include <net/netfilter/nf_conntrack_expect.h>
30 #include <net/netfilter/nf_conntrack_ecache.h>
31 #include <net/netfilter/nf_conntrack_helper.h>
32 #include <linux/netfilter/nf_conntrack_h323.h>
35 static unsigned int default_rrq_ttl __read_mostly
= 300;
36 module_param(default_rrq_ttl
, uint
, 0600);
37 MODULE_PARM_DESC(default_rrq_ttl
, "use this TTL if it's missing in RRQ");
39 static int gkrouted_only __read_mostly
= 1;
40 module_param(gkrouted_only
, int, 0600);
41 MODULE_PARM_DESC(gkrouted_only
, "only accept calls from gatekeeper");
43 static int callforward_filter __read_mostly
= 1;
44 module_param(callforward_filter
, bool, 0600);
45 MODULE_PARM_DESC(callforward_filter
, "only create call forwarding expectations "
46 "if both endpoints are on different sides "
47 "(determined by routing information)");
50 int (*set_h245_addr_hook
) (struct sk_buff
*skb
,
51 unsigned char **data
, int dataoff
,
52 H245_TransportAddress
*taddr
,
53 union nf_inet_addr
*addr
, __be16 port
)
55 int (*set_h225_addr_hook
) (struct sk_buff
*skb
,
56 unsigned char **data
, int dataoff
,
57 TransportAddress
*taddr
,
58 union nf_inet_addr
*addr
, __be16 port
)
60 int (*set_sig_addr_hook
) (struct sk_buff
*skb
,
62 enum ip_conntrack_info ctinfo
,
64 TransportAddress
*taddr
, int count
) __read_mostly
;
65 int (*set_ras_addr_hook
) (struct sk_buff
*skb
,
67 enum ip_conntrack_info ctinfo
,
69 TransportAddress
*taddr
, int count
) __read_mostly
;
70 int (*nat_rtp_rtcp_hook
) (struct sk_buff
*skb
,
72 enum ip_conntrack_info ctinfo
,
73 unsigned char **data
, int dataoff
,
74 H245_TransportAddress
*taddr
,
75 __be16 port
, __be16 rtp_port
,
76 struct nf_conntrack_expect
*rtp_exp
,
77 struct nf_conntrack_expect
*rtcp_exp
) __read_mostly
;
78 int (*nat_t120_hook
) (struct sk_buff
*skb
,
80 enum ip_conntrack_info ctinfo
,
81 unsigned char **data
, int dataoff
,
82 H245_TransportAddress
*taddr
, __be16 port
,
83 struct nf_conntrack_expect
*exp
) __read_mostly
;
84 int (*nat_h245_hook
) (struct sk_buff
*skb
,
86 enum ip_conntrack_info ctinfo
,
87 unsigned char **data
, int dataoff
,
88 TransportAddress
*taddr
, __be16 port
,
89 struct nf_conntrack_expect
*exp
) __read_mostly
;
90 int (*nat_callforwarding_hook
) (struct sk_buff
*skb
,
92 enum ip_conntrack_info ctinfo
,
93 unsigned char **data
, int dataoff
,
94 TransportAddress
*taddr
, __be16 port
,
95 struct nf_conntrack_expect
*exp
) __read_mostly
;
96 int (*nat_q931_hook
) (struct sk_buff
*skb
,
98 enum ip_conntrack_info ctinfo
,
99 unsigned char **data
, TransportAddress
*taddr
, int idx
,
100 __be16 port
, struct nf_conntrack_expect
*exp
)
103 static DEFINE_SPINLOCK(nf_h323_lock
);
104 static char *h323_buffer
;
106 static struct nf_conntrack_helper nf_conntrack_helper_h245
;
107 static struct nf_conntrack_helper nf_conntrack_helper_q931
[];
108 static struct nf_conntrack_helper nf_conntrack_helper_ras
[];
110 /****************************************************************************/
111 static int get_tpkt_data(struct sk_buff
*skb
, unsigned int protoff
,
112 struct nf_conn
*ct
, enum ip_conntrack_info ctinfo
,
113 unsigned char **data
, int *datalen
, int *dataoff
)
115 struct nf_ct_h323_master
*info
= &nfct_help(ct
)->help
.ct_h323_info
;
116 int dir
= CTINFO2DIR(ctinfo
);
117 const struct tcphdr
*th
;
126 th
= skb_header_pointer(skb
, protoff
, sizeof(_tcph
), &_tcph
);
130 /* Get TCP data offset */
131 tcpdataoff
= protoff
+ th
->doff
* 4;
133 /* Get TCP data length */
134 tcpdatalen
= skb
->len
- tcpdataoff
;
135 if (tcpdatalen
<= 0) /* No TCP data */
138 if (*data
== NULL
) { /* first TPKT */
139 /* Get first TPKT pointer */
140 tpkt
= skb_header_pointer(skb
, tcpdataoff
, tcpdatalen
,
142 BUG_ON(tpkt
== NULL
);
144 /* Validate TPKT identifier */
145 if (tcpdatalen
< 4 || tpkt
[0] != 0x03 || tpkt
[1] != 0) {
146 /* Netmeeting sends TPKT header and data separately */
147 if (info
->tpkt_len
[dir
] > 0) {
148 pr_debug("nf_ct_h323: previous packet "
149 "indicated separate TPKT data of %hu "
150 "bytes\n", info
->tpkt_len
[dir
]);
151 if (info
->tpkt_len
[dir
] <= tcpdatalen
) {
152 /* Yes, there was a TPKT header
155 *datalen
= info
->tpkt_len
[dir
];
160 /* Fragmented TPKT */
161 pr_debug("nf_ct_h323: fragmented TPKT\n");
165 /* It is not even a TPKT */
169 } else { /* Next TPKT */
170 tpktoff
= *dataoff
+ *datalen
;
171 tcpdatalen
-= tpktoff
;
172 if (tcpdatalen
<= 4) /* No more TPKT */
174 tpkt
= *data
+ *datalen
;
176 /* Validate TPKT identifier */
177 if (tpkt
[0] != 0x03 || tpkt
[1] != 0)
181 /* Validate TPKT length */
182 tpktlen
= tpkt
[2] * 256 + tpkt
[3];
185 if (tpktlen
> tcpdatalen
) {
186 if (tcpdatalen
== 4) { /* Separate TPKT header */
187 /* Netmeeting sends TPKT header and data separately */
188 pr_debug("nf_ct_h323: separate TPKT header indicates "
189 "there will be TPKT data of %hu bytes\n",
191 info
->tpkt_len
[dir
] = tpktlen
- 4;
196 printk("nf_ct_h323: incomplete TPKT (fragmented?)\n");
200 /* This is the encapsulated data */
202 *datalen
= tpktlen
- 4;
203 *dataoff
= tpktoff
+ 4;
206 /* Clear TPKT length */
207 info
->tpkt_len
[dir
] = 0;
211 info
->tpkt_len
[dir
] = 0;
215 /****************************************************************************/
216 static int get_h245_addr(struct nf_conn
*ct
, const unsigned char *data
,
217 H245_TransportAddress
*taddr
,
218 union nf_inet_addr
*addr
, __be16
*port
)
220 const unsigned char *p
;
223 if (taddr
->choice
!= eH245_TransportAddress_unicastAddress
)
226 switch (taddr
->unicastAddress
.choice
) {
227 case eUnicastAddress_iPAddress
:
228 if (nf_ct_l3num(ct
) != AF_INET
)
230 p
= data
+ taddr
->unicastAddress
.iPAddress
.network
;
233 case eUnicastAddress_iP6Address
:
234 if (nf_ct_l3num(ct
) != AF_INET6
)
236 p
= data
+ taddr
->unicastAddress
.iP6Address
.network
;
243 memcpy(addr
, p
, len
);
244 memset((void *)addr
+ len
, 0, sizeof(*addr
) - len
);
245 memcpy(port
, p
+ len
, sizeof(__be16
));
250 /****************************************************************************/
251 static int expect_rtp_rtcp(struct sk_buff
*skb
, struct nf_conn
*ct
,
252 enum ip_conntrack_info ctinfo
,
253 unsigned char **data
, int dataoff
,
254 H245_TransportAddress
*taddr
)
256 int dir
= CTINFO2DIR(ctinfo
);
259 __be16 rtp_port
, rtcp_port
;
260 union nf_inet_addr addr
;
261 struct nf_conntrack_expect
*rtp_exp
;
262 struct nf_conntrack_expect
*rtcp_exp
;
263 typeof(nat_rtp_rtcp_hook
) nat_rtp_rtcp
;
265 /* Read RTP or RTCP address */
266 if (!get_h245_addr(ct
, *data
, taddr
, &addr
, &port
) ||
267 memcmp(&addr
, &ct
->tuplehash
[dir
].tuple
.src
.u3
, sizeof(addr
)) ||
271 /* RTP port is even */
274 rtcp_port
= htons(ntohs(port
) + 1);
276 /* Create expect for RTP */
277 if ((rtp_exp
= nf_ct_expect_alloc(ct
)) == NULL
)
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
);
284 /* Create expect for RTCP */
285 if ((rtcp_exp
= nf_ct_expect_alloc(ct
)) == NULL
) {
286 nf_ct_expect_put(rtp_exp
);
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
);
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
) {
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
);
310 nf_ct_unexpect_related(rtp_exp
);
317 nf_ct_expect_put(rtp_exp
);
318 nf_ct_expect_put(rtcp_exp
);
323 /****************************************************************************/
324 static int expect_t120(struct sk_buff
*skb
,
326 enum ip_conntrack_info ctinfo
,
327 unsigned char **data
, int dataoff
,
328 H245_TransportAddress
*taddr
)
330 int dir
= CTINFO2DIR(ctinfo
);
333 union nf_inet_addr addr
;
334 struct nf_conntrack_expect
*exp
;
335 typeof(nat_t120_hook
) nat_t120
;
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
)) ||
343 /* Create expect for T.120 connections */
344 if ((exp
= nf_ct_expect_alloc(ct
)) == NULL
)
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 */
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
) {
358 ret
= nat_t120(skb
, ct
, ctinfo
, data
, dataoff
, taddr
,
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
);
368 nf_ct_expect_put(exp
);
373 /****************************************************************************/
374 static int process_h245_channel(struct sk_buff
*skb
,
376 enum ip_conntrack_info ctinfo
,
377 unsigned char **data
, int dataoff
,
378 H2250LogicalChannelParameters
*channel
)
382 if (channel
->options
& eH2250LogicalChannelParameters_mediaChannel
) {
384 ret
= expect_rtp_rtcp(skb
, ct
, ctinfo
, data
, dataoff
,
385 &channel
->mediaChannel
);
391 options
& eH2250LogicalChannelParameters_mediaControlChannel
) {
393 ret
= expect_rtp_rtcp(skb
, ct
, ctinfo
, data
, dataoff
,
394 &channel
->mediaControlChannel
);
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
)
410 pr_debug("nf_ct_h323: OpenLogicalChannel\n");
412 if (olc
->forwardLogicalChannelParameters
.multiplexParameters
.choice
==
413 eOpenLogicalChannel_forwardLogicalChannelParameters_multiplexParameters_h2250LogicalChannelParameters
)
415 ret
= process_h245_channel(skb
, ct
, ctinfo
, data
, dataoff
,
417 forwardLogicalChannelParameters
.
419 h2250LogicalChannelParameters
);
425 eOpenLogicalChannel_reverseLogicalChannelParameters
) &&
426 (olc
->reverseLogicalChannelParameters
.options
&
427 eOpenLogicalChannel_reverseLogicalChannelParameters_multiplexParameters
)
428 && (olc
->reverseLogicalChannelParameters
.multiplexParameters
.
430 eOpenLogicalChannel_reverseLogicalChannelParameters_multiplexParameters_h2250LogicalChannelParameters
))
433 process_h245_channel(skb
, ct
, ctinfo
, data
, dataoff
,
435 reverseLogicalChannelParameters
.
437 h2250LogicalChannelParameters
);
442 if ((olc
->options
& eOpenLogicalChannel_separateStack
) &&
443 olc
->forwardLogicalChannelParameters
.dataType
.choice
==
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
.
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
)
467 H2250LogicalChannelAckParameters
*ack
;
470 pr_debug("nf_ct_h323: OpenLogicalChannelAck\n");
473 eOpenLogicalChannelAck_reverseLogicalChannelParameters
) &&
474 (olca
->reverseLogicalChannelParameters
.options
&
475 eOpenLogicalChannelAck_reverseLogicalChannelParameters_multiplexParameters
)
476 && (olca
->reverseLogicalChannelParameters
.multiplexParameters
.
478 eOpenLogicalChannelAck_reverseLogicalChannelParameters_multiplexParameters_h2250LogicalChannelParameters
))
480 ret
= process_h245_channel(skb
, ct
, ctinfo
, data
, dataoff
,
482 reverseLogicalChannelParameters
.
484 h2250LogicalChannelParameters
);
490 eOpenLogicalChannelAck_forwardMultiplexAckParameters
) &&
491 (olca
->forwardMultiplexAckParameters
.choice
==
492 eOpenLogicalChannelAck_forwardMultiplexAckParameters_h2250LogicalChannelAckParameters
))
494 ack
= &olca
->forwardMultiplexAckParameters
.
495 h2250LogicalChannelAckParameters
;
497 eH2250LogicalChannelAckParameters_mediaChannel
) {
499 ret
= expect_rtp_rtcp(skb
, ct
, ctinfo
, data
, dataoff
,
506 eH2250LogicalChannelAckParameters_mediaControlChannel
) {
508 ret
= expect_rtp_rtcp(skb
, ct
, ctinfo
, data
, dataoff
,
509 &ack
->mediaControlChannel
);
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
.
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
)
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
);
541 pr_debug("nf_ct_h323: H.245 Request %d\n",
542 mscm
->request
.choice
);
544 case eMultimediaSystemControlMessage_response
:
545 if (mscm
->response
.choice
==
546 eResponseMessage_openLogicalChannelAck
) {
547 return process_olca(skb
, ct
, ctinfo
, data
, dataoff
,
549 openLogicalChannelAck
);
551 pr_debug("nf_ct_h323: H.245 Response %d\n",
552 mscm
->response
.choice
);
555 pr_debug("nf_ct_h323: H.245 signal %d\n", mscm
->choice
);
562 /****************************************************************************/
563 static int h245_help(struct sk_buff
*skb
, unsigned int protoff
,
564 struct nf_conn
*ct
, enum ip_conntrack_info ctinfo
)
566 static MultimediaSystemControlMessage mscm
;
567 unsigned char *data
= NULL
;
572 /* Until there's been traffic both ways, don't look in packets. */
573 if (ctinfo
!= IP_CT_ESTABLISHED
&&
574 ctinfo
!= IP_CT_ESTABLISHED
+ IP_CT_IS_REPLY
) {
577 pr_debug("nf_ct_h245: skblen = %u\n", skb
->len
);
579 spin_lock_bh(&nf_h323_lock
);
581 /* Process each TPKT */
582 while (get_tpkt_data(skb
, protoff
, ct
, ctinfo
,
583 &data
, &datalen
, &dataoff
)) {
584 pr_debug("nf_ct_h245: TPKT len=%d ", datalen
);
585 nf_ct_dump_tuple(&ct
->tuplehash
[CTINFO2DIR(ctinfo
)].tuple
);
587 /* Decode H.245 signal */
588 ret
= DecodeMultimediaSystemControlMessage(data
, datalen
,
591 pr_debug("nf_ct_h245: decoding error: %s\n",
592 ret
== H323_ERROR_BOUND
?
593 "out of bound" : "out of range");
594 /* We don't drop when decoding error */
598 /* Process H.245 signal */
599 if (process_h245(skb
, ct
, ctinfo
, &data
, dataoff
, &mscm
) < 0)
603 spin_unlock_bh(&nf_h323_lock
);
607 spin_unlock_bh(&nf_h323_lock
);
609 printk("nf_ct_h245: packet dropped\n");
613 /****************************************************************************/
614 static const struct nf_conntrack_expect_policy h245_exp_policy
= {
615 .max_expected
= H323_RTP_CHANNEL_MAX
* 4 + 2 /* T.120 */,
619 static struct nf_conntrack_helper nf_conntrack_helper_h245 __read_mostly
= {
622 .tuple
.dst
.protonum
= IPPROTO_UDP
,
624 .expect_policy
= &h245_exp_policy
,
627 /****************************************************************************/
628 int get_h225_addr(struct nf_conn
*ct
, unsigned char *data
,
629 TransportAddress
*taddr
,
630 union nf_inet_addr
*addr
, __be16
*port
)
632 const unsigned char *p
;
635 switch (taddr
->choice
) {
636 case eTransportAddress_ipAddress
:
637 if (nf_ct_l3num(ct
) != AF_INET
)
639 p
= data
+ taddr
->ipAddress
.ip
;
642 case eTransportAddress_ip6Address
:
643 if (nf_ct_l3num(ct
) != AF_INET6
)
645 p
= data
+ taddr
->ip6Address
.ip
;
652 memcpy(addr
, p
, len
);
653 memset((void *)addr
+ len
, 0, sizeof(*addr
) - len
);
654 memcpy(port
, p
+ len
, sizeof(__be16
));
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
)
665 int dir
= CTINFO2DIR(ctinfo
);
668 union nf_inet_addr addr
;
669 struct nf_conntrack_expect
*exp
;
670 typeof(nat_h245_hook
) nat_h245
;
672 /* Read h245Address */
673 if (!get_h225_addr(ct
, *data
, taddr
, &addr
, &port
) ||
674 memcmp(&addr
, &ct
->tuplehash
[dir
].tuple
.src
.u3
, sizeof(addr
)) ||
678 /* Create expect for h245 connection */
679 if ((exp
= nf_ct_expect_alloc(ct
)) == NULL
)
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
;
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
) {
693 ret
= nat_h245(skb
, ct
, ctinfo
, data
, dataoff
, taddr
,
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
);
703 nf_ct_expect_put(exp
);
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
, int family
)
713 const struct nf_afinfo
*afinfo
;
714 struct flowi fl1
, fl2
;
717 /* rcu_read_lock()ed by nf_hook_slow() */
718 afinfo
= nf_get_afinfo(family
);
722 memset(&fl1
, 0, sizeof(fl1
));
723 memset(&fl2
, 0, sizeof(fl2
));
727 struct rtable
*rt1
, *rt2
;
729 fl1
.fl4_dst
= src
->ip
;
730 fl2
.fl4_dst
= dst
->ip
;
731 if (!afinfo
->route((struct dst_entry
**)&rt1
, &fl1
)) {
732 if (!afinfo
->route((struct dst_entry
**)&rt2
, &fl2
)) {
733 if (rt1
->rt_gateway
== rt2
->rt_gateway
&&
734 rt1
->u
.dst
.dev
== rt2
->u
.dst
.dev
)
736 dst_release(&rt2
->u
.dst
);
738 dst_release(&rt1
->u
.dst
);
742 #if defined(CONFIG_NF_CONNTRACK_IPV6) || \
743 defined(CONFIG_NF_CONNTRACK_IPV6_MODULE)
745 struct rt6_info
*rt1
, *rt2
;
747 memcpy(&fl1
.fl6_dst
, src
, sizeof(fl1
.fl6_dst
));
748 memcpy(&fl2
.fl6_dst
, dst
, sizeof(fl2
.fl6_dst
));
749 if (!afinfo
->route((struct dst_entry
**)&rt1
, &fl1
)) {
750 if (!afinfo
->route((struct dst_entry
**)&rt2
, &fl2
)) {
751 if (!memcmp(&rt1
->rt6i_gateway
, &rt2
->rt6i_gateway
,
752 sizeof(rt1
->rt6i_gateway
)) &&
753 rt1
->u
.dst
.dev
== rt2
->u
.dst
.dev
)
755 dst_release(&rt2
->u
.dst
);
757 dst_release(&rt1
->u
.dst
);
767 /****************************************************************************/
768 static int expect_callforwarding(struct sk_buff
*skb
,
770 enum ip_conntrack_info ctinfo
,
771 unsigned char **data
, int dataoff
,
772 TransportAddress
*taddr
)
774 int dir
= CTINFO2DIR(ctinfo
);
777 union nf_inet_addr addr
;
778 struct nf_conntrack_expect
*exp
;
779 typeof(nat_callforwarding_hook
) nat_callforwarding
;
781 /* Read alternativeAddress */
782 if (!get_h225_addr(ct
, *data
, taddr
, &addr
, &port
) || port
== 0)
785 /* If the calling party is on the same side of the forward-to party,
786 * we don't need to track the second call */
787 if (callforward_filter
&&
788 callforward_do_filter(&addr
, &ct
->tuplehash
[!dir
].tuple
.src
.u3
,
790 pr_debug("nf_ct_q931: Call Forwarding not tracked\n");
794 /* Create expect for the second call leg */
795 if ((exp
= nf_ct_expect_alloc(ct
)) == NULL
)
797 nf_ct_expect_init(exp
, NF_CT_EXPECT_CLASS_DEFAULT
, nf_ct_l3num(ct
),
798 &ct
->tuplehash
[!dir
].tuple
.src
.u3
, &addr
,
799 IPPROTO_TCP
, NULL
, &port
);
800 exp
->helper
= nf_conntrack_helper_q931
;
802 if (memcmp(&ct
->tuplehash
[dir
].tuple
.src
.u3
,
803 &ct
->tuplehash
[!dir
].tuple
.dst
.u3
,
804 sizeof(ct
->tuplehash
[dir
].tuple
.src
.u3
)) &&
805 (nat_callforwarding
= rcu_dereference(nat_callforwarding_hook
)) &&
806 ct
->status
& IPS_NAT_MASK
) {
808 ret
= nat_callforwarding(skb
, ct
, ctinfo
, data
, dataoff
,
810 } else { /* Conntrack only */
811 if (nf_ct_expect_related(exp
) == 0) {
812 pr_debug("nf_ct_q931: expect Call Forwarding ");
813 nf_ct_dump_tuple(&exp
->tuple
);
818 nf_ct_expect_put(exp
);
823 /****************************************************************************/
824 static int process_setup(struct sk_buff
*skb
, struct nf_conn
*ct
,
825 enum ip_conntrack_info ctinfo
,
826 unsigned char **data
, int dataoff
,
829 int dir
= CTINFO2DIR(ctinfo
);
833 union nf_inet_addr addr
;
834 typeof(set_h225_addr_hook
) set_h225_addr
;
836 pr_debug("nf_ct_q931: Setup\n");
838 if (setup
->options
& eSetup_UUIE_h245Address
) {
839 ret
= expect_h245(skb
, ct
, ctinfo
, data
, dataoff
,
840 &setup
->h245Address
);
845 set_h225_addr
= rcu_dereference(set_h225_addr_hook
);
846 if ((setup
->options
& eSetup_UUIE_destCallSignalAddress
) &&
847 (set_h225_addr
) && ct
->status
& IPS_NAT_MASK
&&
848 get_h225_addr(ct
, *data
, &setup
->destCallSignalAddress
,
850 memcmp(&addr
, &ct
->tuplehash
[!dir
].tuple
.src
.u3
, sizeof(addr
))) {
851 pr_debug("nf_ct_q931: set destCallSignalAddress "
852 NIP6_FMT
":%hu->" NIP6_FMT
":%hu\n",
853 NIP6(*(struct in6_addr
*)&addr
), ntohs(port
),
854 NIP6(*(struct in6_addr
*)&ct
->tuplehash
[!dir
].tuple
.src
.u3
),
855 ntohs(ct
->tuplehash
[!dir
].tuple
.src
.u
.tcp
.port
));
856 ret
= set_h225_addr(skb
, data
, dataoff
,
857 &setup
->destCallSignalAddress
,
858 &ct
->tuplehash
[!dir
].tuple
.src
.u3
,
859 ct
->tuplehash
[!dir
].tuple
.src
.u
.tcp
.port
);
864 if ((setup
->options
& eSetup_UUIE_sourceCallSignalAddress
) &&
865 (set_h225_addr
) && ct
->status
& IPS_NAT_MASK
&&
866 get_h225_addr(ct
, *data
, &setup
->sourceCallSignalAddress
,
868 memcmp(&addr
, &ct
->tuplehash
[!dir
].tuple
.dst
.u3
, sizeof(addr
))) {
869 pr_debug("nf_ct_q931: set sourceCallSignalAddress "
870 NIP6_FMT
":%hu->" NIP6_FMT
":%hu\n",
871 NIP6(*(struct in6_addr
*)&addr
), ntohs(port
),
872 NIP6(*(struct in6_addr
*)&ct
->tuplehash
[!dir
].tuple
.dst
.u3
),
873 ntohs(ct
->tuplehash
[!dir
].tuple
.dst
.u
.tcp
.port
));
874 ret
= set_h225_addr(skb
, data
, dataoff
,
875 &setup
->sourceCallSignalAddress
,
876 &ct
->tuplehash
[!dir
].tuple
.dst
.u3
,
877 ct
->tuplehash
[!dir
].tuple
.dst
.u
.tcp
.port
);
882 if (setup
->options
& eSetup_UUIE_fastStart
) {
883 for (i
= 0; i
< setup
->fastStart
.count
; i
++) {
884 ret
= process_olc(skb
, ct
, ctinfo
, data
, dataoff
,
885 &setup
->fastStart
.item
[i
]);
894 /****************************************************************************/
895 static int process_callproceeding(struct sk_buff
*skb
,
897 enum ip_conntrack_info ctinfo
,
898 unsigned char **data
, int dataoff
,
899 CallProceeding_UUIE
*callproc
)
904 pr_debug("nf_ct_q931: CallProceeding\n");
906 if (callproc
->options
& eCallProceeding_UUIE_h245Address
) {
907 ret
= expect_h245(skb
, ct
, ctinfo
, data
, dataoff
,
908 &callproc
->h245Address
);
913 if (callproc
->options
& eCallProceeding_UUIE_fastStart
) {
914 for (i
= 0; i
< callproc
->fastStart
.count
; i
++) {
915 ret
= process_olc(skb
, ct
, ctinfo
, data
, dataoff
,
916 &callproc
->fastStart
.item
[i
]);
925 /****************************************************************************/
926 static int process_connect(struct sk_buff
*skb
, struct nf_conn
*ct
,
927 enum ip_conntrack_info ctinfo
,
928 unsigned char **data
, int dataoff
,
929 Connect_UUIE
*connect
)
934 pr_debug("nf_ct_q931: Connect\n");
936 if (connect
->options
& eConnect_UUIE_h245Address
) {
937 ret
= expect_h245(skb
, ct
, ctinfo
, data
, dataoff
,
938 &connect
->h245Address
);
943 if (connect
->options
& eConnect_UUIE_fastStart
) {
944 for (i
= 0; i
< connect
->fastStart
.count
; i
++) {
945 ret
= process_olc(skb
, ct
, ctinfo
, data
, dataoff
,
946 &connect
->fastStart
.item
[i
]);
955 /****************************************************************************/
956 static int process_alerting(struct sk_buff
*skb
, struct nf_conn
*ct
,
957 enum ip_conntrack_info ctinfo
,
958 unsigned char **data
, int dataoff
,
959 Alerting_UUIE
*alert
)
964 pr_debug("nf_ct_q931: Alerting\n");
966 if (alert
->options
& eAlerting_UUIE_h245Address
) {
967 ret
= expect_h245(skb
, ct
, ctinfo
, data
, dataoff
,
968 &alert
->h245Address
);
973 if (alert
->options
& eAlerting_UUIE_fastStart
) {
974 for (i
= 0; i
< alert
->fastStart
.count
; i
++) {
975 ret
= process_olc(skb
, ct
, ctinfo
, data
, dataoff
,
976 &alert
->fastStart
.item
[i
]);
985 /****************************************************************************/
986 static int process_facility(struct sk_buff
*skb
, struct nf_conn
*ct
,
987 enum ip_conntrack_info ctinfo
,
988 unsigned char **data
, int dataoff
,
989 Facility_UUIE
*facility
)
994 pr_debug("nf_ct_q931: Facility\n");
996 if (facility
->reason
.choice
== eFacilityReason_callForwarded
) {
997 if (facility
->options
& eFacility_UUIE_alternativeAddress
)
998 return expect_callforwarding(skb
, ct
, ctinfo
, data
,
1001 alternativeAddress
);
1005 if (facility
->options
& eFacility_UUIE_h245Address
) {
1006 ret
= expect_h245(skb
, ct
, ctinfo
, data
, dataoff
,
1007 &facility
->h245Address
);
1012 if (facility
->options
& eFacility_UUIE_fastStart
) {
1013 for (i
= 0; i
< facility
->fastStart
.count
; i
++) {
1014 ret
= process_olc(skb
, ct
, ctinfo
, data
, dataoff
,
1015 &facility
->fastStart
.item
[i
]);
1024 /****************************************************************************/
1025 static int process_progress(struct sk_buff
*skb
, struct nf_conn
*ct
,
1026 enum ip_conntrack_info ctinfo
,
1027 unsigned char **data
, int dataoff
,
1028 Progress_UUIE
*progress
)
1033 pr_debug("nf_ct_q931: Progress\n");
1035 if (progress
->options
& eProgress_UUIE_h245Address
) {
1036 ret
= expect_h245(skb
, ct
, ctinfo
, data
, dataoff
,
1037 &progress
->h245Address
);
1042 if (progress
->options
& eProgress_UUIE_fastStart
) {
1043 for (i
= 0; i
< progress
->fastStart
.count
; i
++) {
1044 ret
= process_olc(skb
, ct
, ctinfo
, data
, dataoff
,
1045 &progress
->fastStart
.item
[i
]);
1054 /****************************************************************************/
1055 static int process_q931(struct sk_buff
*skb
, struct nf_conn
*ct
,
1056 enum ip_conntrack_info ctinfo
,
1057 unsigned char **data
, int dataoff
, Q931
*q931
)
1059 H323_UU_PDU
*pdu
= &q931
->UUIE
.h323_uu_pdu
;
1063 switch (pdu
->h323_message_body
.choice
) {
1064 case eH323_UU_PDU_h323_message_body_setup
:
1065 ret
= process_setup(skb
, ct
, ctinfo
, data
, dataoff
,
1066 &pdu
->h323_message_body
.setup
);
1068 case eH323_UU_PDU_h323_message_body_callProceeding
:
1069 ret
= process_callproceeding(skb
, ct
, ctinfo
, data
, dataoff
,
1070 &pdu
->h323_message_body
.
1073 case eH323_UU_PDU_h323_message_body_connect
:
1074 ret
= process_connect(skb
, ct
, ctinfo
, data
, dataoff
,
1075 &pdu
->h323_message_body
.connect
);
1077 case eH323_UU_PDU_h323_message_body_alerting
:
1078 ret
= process_alerting(skb
, ct
, ctinfo
, data
, dataoff
,
1079 &pdu
->h323_message_body
.alerting
);
1081 case eH323_UU_PDU_h323_message_body_facility
:
1082 ret
= process_facility(skb
, ct
, ctinfo
, data
, dataoff
,
1083 &pdu
->h323_message_body
.facility
);
1085 case eH323_UU_PDU_h323_message_body_progress
:
1086 ret
= process_progress(skb
, ct
, ctinfo
, data
, dataoff
,
1087 &pdu
->h323_message_body
.progress
);
1090 pr_debug("nf_ct_q931: Q.931 signal %d\n",
1091 pdu
->h323_message_body
.choice
);
1098 if (pdu
->options
& eH323_UU_PDU_h245Control
) {
1099 for (i
= 0; i
< pdu
->h245Control
.count
; i
++) {
1100 ret
= process_h245(skb
, ct
, ctinfo
, data
, dataoff
,
1101 &pdu
->h245Control
.item
[i
]);
1110 /****************************************************************************/
1111 static int q931_help(struct sk_buff
*skb
, unsigned int protoff
,
1112 struct nf_conn
*ct
, enum ip_conntrack_info ctinfo
)
1115 unsigned char *data
= NULL
;
1120 /* Until there's been traffic both ways, don't look in packets. */
1121 if (ctinfo
!= IP_CT_ESTABLISHED
&&
1122 ctinfo
!= IP_CT_ESTABLISHED
+ IP_CT_IS_REPLY
) {
1125 pr_debug("nf_ct_q931: skblen = %u\n", skb
->len
);
1127 spin_lock_bh(&nf_h323_lock
);
1129 /* Process each TPKT */
1130 while (get_tpkt_data(skb
, protoff
, ct
, ctinfo
,
1131 &data
, &datalen
, &dataoff
)) {
1132 pr_debug("nf_ct_q931: TPKT len=%d ", datalen
);
1133 nf_ct_dump_tuple(&ct
->tuplehash
[CTINFO2DIR(ctinfo
)].tuple
);
1135 /* Decode Q.931 signal */
1136 ret
= DecodeQ931(data
, datalen
, &q931
);
1138 pr_debug("nf_ct_q931: decoding error: %s\n",
1139 ret
== H323_ERROR_BOUND
?
1140 "out of bound" : "out of range");
1141 /* We don't drop when decoding error */
1145 /* Process Q.931 signal */
1146 if (process_q931(skb
, ct
, ctinfo
, &data
, dataoff
, &q931
) < 0)
1150 spin_unlock_bh(&nf_h323_lock
);
1154 spin_unlock_bh(&nf_h323_lock
);
1155 if (net_ratelimit())
1156 printk("nf_ct_q931: packet dropped\n");
1160 /****************************************************************************/
1161 static const struct nf_conntrack_expect_policy q931_exp_policy
= {
1162 /* T.120 and H.245 */
1163 .max_expected
= H323_RTP_CHANNEL_MAX
* 4 + 4,
1167 static struct nf_conntrack_helper nf_conntrack_helper_q931
[] __read_mostly
= {
1171 .tuple
.src
.l3num
= AF_INET
,
1172 .tuple
.src
.u
.tcp
.port
= __constant_htons(Q931_PORT
),
1173 .tuple
.dst
.protonum
= IPPROTO_TCP
,
1175 .expect_policy
= &q931_exp_policy
,
1180 .tuple
.src
.l3num
= AF_INET6
,
1181 .tuple
.src
.u
.tcp
.port
= __constant_htons(Q931_PORT
),
1182 .tuple
.dst
.protonum
= IPPROTO_TCP
,
1184 .expect_policy
= &q931_exp_policy
,
1188 /****************************************************************************/
1189 static unsigned char *get_udp_data(struct sk_buff
*skb
, unsigned int protoff
,
1192 const struct udphdr
*uh
;
1196 uh
= skb_header_pointer(skb
, protoff
, sizeof(_uh
), &_uh
);
1199 dataoff
= protoff
+ sizeof(_uh
);
1200 if (dataoff
>= skb
->len
)
1202 *datalen
= skb
->len
- dataoff
;
1203 return skb_header_pointer(skb
, dataoff
, *datalen
, h323_buffer
);
1206 /****************************************************************************/
1207 static struct nf_conntrack_expect
*find_expect(struct nf_conn
*ct
,
1208 union nf_inet_addr
*addr
,
1211 struct nf_conntrack_expect
*exp
;
1212 struct nf_conntrack_tuple tuple
;
1214 memset(&tuple
.src
.u3
, 0, sizeof(tuple
.src
.u3
));
1215 tuple
.src
.u
.tcp
.port
= 0;
1216 memcpy(&tuple
.dst
.u3
, addr
, sizeof(tuple
.dst
.u3
));
1217 tuple
.dst
.u
.tcp
.port
= port
;
1218 tuple
.dst
.protonum
= IPPROTO_TCP
;
1220 exp
= __nf_ct_expect_find(&tuple
);
1221 if (exp
&& exp
->master
== ct
)
1226 /****************************************************************************/
1227 static int set_expect_timeout(struct nf_conntrack_expect
*exp
,
1230 if (!exp
|| !del_timer(&exp
->timeout
))
1233 exp
->timeout
.expires
= jiffies
+ timeout
* HZ
;
1234 add_timer(&exp
->timeout
);
1239 /****************************************************************************/
1240 static int expect_q931(struct sk_buff
*skb
, struct nf_conn
*ct
,
1241 enum ip_conntrack_info ctinfo
,
1242 unsigned char **data
,
1243 TransportAddress
*taddr
, int count
)
1245 struct nf_ct_h323_master
*info
= &nfct_help(ct
)->help
.ct_h323_info
;
1246 int dir
= CTINFO2DIR(ctinfo
);
1250 union nf_inet_addr addr
;
1251 struct nf_conntrack_expect
*exp
;
1252 typeof(nat_q931_hook
) nat_q931
;
1254 /* Look for the first related address */
1255 for (i
= 0; i
< count
; i
++) {
1256 if (get_h225_addr(ct
, *data
, &taddr
[i
], &addr
, &port
) &&
1257 memcmp(&addr
, &ct
->tuplehash
[dir
].tuple
.src
.u3
,
1258 sizeof(addr
)) == 0 && port
!= 0)
1262 if (i
>= count
) /* Not found */
1265 /* Create expect for Q.931 */
1266 if ((exp
= nf_ct_expect_alloc(ct
)) == NULL
)
1268 nf_ct_expect_init(exp
, NF_CT_EXPECT_CLASS_DEFAULT
, nf_ct_l3num(ct
),
1269 gkrouted_only
? /* only accept calls from GK? */
1270 &ct
->tuplehash
[!dir
].tuple
.src
.u3
: NULL
,
1271 &ct
->tuplehash
[!dir
].tuple
.dst
.u3
,
1272 IPPROTO_TCP
, NULL
, &port
);
1273 exp
->helper
= nf_conntrack_helper_q931
;
1274 exp
->flags
= NF_CT_EXPECT_PERMANENT
; /* Accept multiple calls */
1276 nat_q931
= rcu_dereference(nat_q931_hook
);
1277 if (nat_q931
&& ct
->status
& IPS_NAT_MASK
) { /* Need NAT */
1278 ret
= nat_q931(skb
, ct
, ctinfo
, data
, taddr
, i
, port
, exp
);
1279 } else { /* Conntrack only */
1280 if (nf_ct_expect_related(exp
) == 0) {
1281 pr_debug("nf_ct_ras: expect Q.931 ");
1282 nf_ct_dump_tuple(&exp
->tuple
);
1284 /* Save port for looking up expect in processing RCF */
1285 info
->sig_port
[dir
] = port
;
1290 nf_ct_expect_put(exp
);
1295 /****************************************************************************/
1296 static int process_grq(struct sk_buff
*skb
, struct nf_conn
*ct
,
1297 enum ip_conntrack_info ctinfo
,
1298 unsigned char **data
, GatekeeperRequest
*grq
)
1300 typeof(set_ras_addr_hook
) set_ras_addr
;
1302 pr_debug("nf_ct_ras: GRQ\n");
1304 set_ras_addr
= rcu_dereference(set_ras_addr_hook
);
1305 if (set_ras_addr
&& ct
->status
& IPS_NAT_MASK
) /* NATed */
1306 return set_ras_addr(skb
, ct
, ctinfo
, data
,
1307 &grq
->rasAddress
, 1);
1311 /****************************************************************************/
1312 static int process_gcf(struct sk_buff
*skb
, struct nf_conn
*ct
,
1313 enum ip_conntrack_info ctinfo
,
1314 unsigned char **data
, GatekeeperConfirm
*gcf
)
1316 int dir
= CTINFO2DIR(ctinfo
);
1319 union nf_inet_addr addr
;
1320 struct nf_conntrack_expect
*exp
;
1322 pr_debug("nf_ct_ras: GCF\n");
1324 if (!get_h225_addr(ct
, *data
, &gcf
->rasAddress
, &addr
, &port
))
1327 /* Registration port is the same as discovery port */
1328 if (!memcmp(&addr
, &ct
->tuplehash
[dir
].tuple
.src
.u3
, sizeof(addr
)) &&
1329 port
== ct
->tuplehash
[dir
].tuple
.src
.u
.udp
.port
)
1332 /* Avoid RAS expectation loops. A GCF is never expected. */
1333 if (test_bit(IPS_EXPECTED_BIT
, &ct
->status
))
1336 /* Need new expect */
1337 if ((exp
= nf_ct_expect_alloc(ct
)) == NULL
)
1339 nf_ct_expect_init(exp
, NF_CT_EXPECT_CLASS_DEFAULT
, nf_ct_l3num(ct
),
1340 &ct
->tuplehash
[!dir
].tuple
.src
.u3
, &addr
,
1341 IPPROTO_UDP
, NULL
, &port
);
1342 exp
->helper
= nf_conntrack_helper_ras
;
1344 if (nf_ct_expect_related(exp
) == 0) {
1345 pr_debug("nf_ct_ras: expect RAS ");
1346 nf_ct_dump_tuple(&exp
->tuple
);
1350 nf_ct_expect_put(exp
);
1355 /****************************************************************************/
1356 static int process_rrq(struct sk_buff
*skb
, struct nf_conn
*ct
,
1357 enum ip_conntrack_info ctinfo
,
1358 unsigned char **data
, RegistrationRequest
*rrq
)
1360 struct nf_ct_h323_master
*info
= &nfct_help(ct
)->help
.ct_h323_info
;
1362 typeof(set_ras_addr_hook
) set_ras_addr
;
1364 pr_debug("nf_ct_ras: RRQ\n");
1366 ret
= expect_q931(skb
, ct
, ctinfo
, data
,
1367 rrq
->callSignalAddress
.item
,
1368 rrq
->callSignalAddress
.count
);
1372 set_ras_addr
= rcu_dereference(set_ras_addr_hook
);
1373 if (set_ras_addr
&& ct
->status
& IPS_NAT_MASK
) {
1374 ret
= set_ras_addr(skb
, ct
, ctinfo
, data
,
1375 rrq
->rasAddress
.item
,
1376 rrq
->rasAddress
.count
);
1381 if (rrq
->options
& eRegistrationRequest_timeToLive
) {
1382 pr_debug("nf_ct_ras: RRQ TTL = %u seconds\n", rrq
->timeToLive
);
1383 info
->timeout
= rrq
->timeToLive
;
1385 info
->timeout
= default_rrq_ttl
;
1390 /****************************************************************************/
1391 static int process_rcf(struct sk_buff
*skb
, struct nf_conn
*ct
,
1392 enum ip_conntrack_info ctinfo
,
1393 unsigned char **data
, RegistrationConfirm
*rcf
)
1395 struct nf_ct_h323_master
*info
= &nfct_help(ct
)->help
.ct_h323_info
;
1396 int dir
= CTINFO2DIR(ctinfo
);
1398 struct nf_conntrack_expect
*exp
;
1399 typeof(set_sig_addr_hook
) set_sig_addr
;
1401 pr_debug("nf_ct_ras: RCF\n");
1403 set_sig_addr
= rcu_dereference(set_sig_addr_hook
);
1404 if (set_sig_addr
&& ct
->status
& IPS_NAT_MASK
) {
1405 ret
= set_sig_addr(skb
, ct
, ctinfo
, data
,
1406 rcf
->callSignalAddress
.item
,
1407 rcf
->callSignalAddress
.count
);
1412 if (rcf
->options
& eRegistrationConfirm_timeToLive
) {
1413 pr_debug("nf_ct_ras: RCF TTL = %u seconds\n", rcf
->timeToLive
);
1414 info
->timeout
= rcf
->timeToLive
;
1417 if (info
->timeout
> 0) {
1418 pr_debug("nf_ct_ras: set RAS connection timeout to "
1419 "%u seconds\n", info
->timeout
);
1420 nf_ct_refresh(ct
, skb
, info
->timeout
* HZ
);
1422 /* Set expect timeout */
1423 spin_lock_bh(&nf_conntrack_lock
);
1424 exp
= find_expect(ct
, &ct
->tuplehash
[dir
].tuple
.dst
.u3
,
1425 info
->sig_port
[!dir
]);
1427 pr_debug("nf_ct_ras: set Q.931 expect "
1428 "timeout to %u seconds for",
1430 nf_ct_dump_tuple(&exp
->tuple
);
1431 set_expect_timeout(exp
, info
->timeout
);
1433 spin_unlock_bh(&nf_conntrack_lock
);
1439 /****************************************************************************/
1440 static int process_urq(struct sk_buff
*skb
, struct nf_conn
*ct
,
1441 enum ip_conntrack_info ctinfo
,
1442 unsigned char **data
, UnregistrationRequest
*urq
)
1444 struct nf_ct_h323_master
*info
= &nfct_help(ct
)->help
.ct_h323_info
;
1445 int dir
= CTINFO2DIR(ctinfo
);
1447 typeof(set_sig_addr_hook
) set_sig_addr
;
1449 pr_debug("nf_ct_ras: URQ\n");
1451 set_sig_addr
= rcu_dereference(set_sig_addr_hook
);
1452 if (set_sig_addr
&& ct
->status
& IPS_NAT_MASK
) {
1453 ret
= set_sig_addr(skb
, ct
, ctinfo
, data
,
1454 urq
->callSignalAddress
.item
,
1455 urq
->callSignalAddress
.count
);
1460 /* Clear old expect */
1461 nf_ct_remove_expectations(ct
);
1462 info
->sig_port
[dir
] = 0;
1463 info
->sig_port
[!dir
] = 0;
1465 /* Give it 30 seconds for UCF or URJ */
1466 nf_ct_refresh(ct
, skb
, 30 * HZ
);
1471 /****************************************************************************/
1472 static int process_arq(struct sk_buff
*skb
, struct nf_conn
*ct
,
1473 enum ip_conntrack_info ctinfo
,
1474 unsigned char **data
, AdmissionRequest
*arq
)
1476 const struct nf_ct_h323_master
*info
= &nfct_help(ct
)->help
.ct_h323_info
;
1477 int dir
= CTINFO2DIR(ctinfo
);
1479 union nf_inet_addr addr
;
1480 typeof(set_h225_addr_hook
) set_h225_addr
;
1482 pr_debug("nf_ct_ras: ARQ\n");
1484 set_h225_addr
= rcu_dereference(set_h225_addr_hook
);
1485 if ((arq
->options
& eAdmissionRequest_destCallSignalAddress
) &&
1486 get_h225_addr(ct
, *data
, &arq
->destCallSignalAddress
,
1488 !memcmp(&addr
, &ct
->tuplehash
[dir
].tuple
.src
.u3
, sizeof(addr
)) &&
1489 port
== info
->sig_port
[dir
] &&
1490 set_h225_addr
&& ct
->status
& IPS_NAT_MASK
) {
1492 return set_h225_addr(skb
, data
, 0,
1493 &arq
->destCallSignalAddress
,
1494 &ct
->tuplehash
[!dir
].tuple
.dst
.u3
,
1495 info
->sig_port
[!dir
]);
1498 if ((arq
->options
& eAdmissionRequest_srcCallSignalAddress
) &&
1499 get_h225_addr(ct
, *data
, &arq
->srcCallSignalAddress
,
1501 !memcmp(&addr
, &ct
->tuplehash
[dir
].tuple
.src
.u3
, sizeof(addr
)) &&
1502 set_h225_addr
&& ct
->status
& IPS_NAT_MASK
) {
1504 return set_h225_addr(skb
, data
, 0,
1505 &arq
->srcCallSignalAddress
,
1506 &ct
->tuplehash
[!dir
].tuple
.dst
.u3
,
1513 /****************************************************************************/
1514 static int process_acf(struct sk_buff
*skb
, struct nf_conn
*ct
,
1515 enum ip_conntrack_info ctinfo
,
1516 unsigned char **data
, AdmissionConfirm
*acf
)
1518 int dir
= CTINFO2DIR(ctinfo
);
1521 union nf_inet_addr addr
;
1522 struct nf_conntrack_expect
*exp
;
1523 typeof(set_sig_addr_hook
) set_sig_addr
;
1525 pr_debug("nf_ct_ras: ACF\n");
1527 if (!get_h225_addr(ct
, *data
, &acf
->destCallSignalAddress
,
1531 if (!memcmp(&addr
, &ct
->tuplehash
[dir
].tuple
.dst
.u3
, sizeof(addr
))) {
1533 set_sig_addr
= rcu_dereference(set_sig_addr_hook
);
1534 if (set_sig_addr
&& ct
->status
& IPS_NAT_MASK
)
1535 return set_sig_addr(skb
, ct
, ctinfo
, data
,
1536 &acf
->destCallSignalAddress
, 1);
1540 /* Need new expect */
1541 if ((exp
= nf_ct_expect_alloc(ct
)) == NULL
)
1543 nf_ct_expect_init(exp
, NF_CT_EXPECT_CLASS_DEFAULT
, nf_ct_l3num(ct
),
1544 &ct
->tuplehash
[!dir
].tuple
.src
.u3
, &addr
,
1545 IPPROTO_TCP
, NULL
, &port
);
1546 exp
->flags
= NF_CT_EXPECT_PERMANENT
;
1547 exp
->helper
= nf_conntrack_helper_q931
;
1549 if (nf_ct_expect_related(exp
) == 0) {
1550 pr_debug("nf_ct_ras: expect Q.931 ");
1551 nf_ct_dump_tuple(&exp
->tuple
);
1555 nf_ct_expect_put(exp
);
1560 /****************************************************************************/
1561 static int process_lrq(struct sk_buff
*skb
, struct nf_conn
*ct
,
1562 enum ip_conntrack_info ctinfo
,
1563 unsigned char **data
, LocationRequest
*lrq
)
1565 typeof(set_ras_addr_hook
) set_ras_addr
;
1567 pr_debug("nf_ct_ras: LRQ\n");
1569 set_ras_addr
= rcu_dereference(set_ras_addr_hook
);
1570 if (set_ras_addr
&& ct
->status
& IPS_NAT_MASK
)
1571 return set_ras_addr(skb
, ct
, ctinfo
, data
,
1572 &lrq
->replyAddress
, 1);
1576 /****************************************************************************/
1577 static int process_lcf(struct sk_buff
*skb
, struct nf_conn
*ct
,
1578 enum ip_conntrack_info ctinfo
,
1579 unsigned char **data
, LocationConfirm
*lcf
)
1581 int dir
= CTINFO2DIR(ctinfo
);
1584 union nf_inet_addr addr
;
1585 struct nf_conntrack_expect
*exp
;
1587 pr_debug("nf_ct_ras: LCF\n");
1589 if (!get_h225_addr(ct
, *data
, &lcf
->callSignalAddress
,
1593 /* Need new expect for call signal */
1594 if ((exp
= nf_ct_expect_alloc(ct
)) == NULL
)
1596 nf_ct_expect_init(exp
, NF_CT_EXPECT_CLASS_DEFAULT
, nf_ct_l3num(ct
),
1597 &ct
->tuplehash
[!dir
].tuple
.src
.u3
, &addr
,
1598 IPPROTO_TCP
, NULL
, &port
);
1599 exp
->flags
= NF_CT_EXPECT_PERMANENT
;
1600 exp
->helper
= nf_conntrack_helper_q931
;
1602 if (nf_ct_expect_related(exp
) == 0) {
1603 pr_debug("nf_ct_ras: expect Q.931 ");
1604 nf_ct_dump_tuple(&exp
->tuple
);
1608 nf_ct_expect_put(exp
);
1610 /* Ignore rasAddress */
1615 /****************************************************************************/
1616 static int process_irr(struct sk_buff
*skb
, struct nf_conn
*ct
,
1617 enum ip_conntrack_info ctinfo
,
1618 unsigned char **data
, InfoRequestResponse
*irr
)
1621 typeof(set_ras_addr_hook
) set_ras_addr
;
1622 typeof(set_sig_addr_hook
) set_sig_addr
;
1624 pr_debug("nf_ct_ras: IRR\n");
1626 set_ras_addr
= rcu_dereference(set_ras_addr_hook
);
1627 if (set_ras_addr
&& ct
->status
& IPS_NAT_MASK
) {
1628 ret
= set_ras_addr(skb
, ct
, ctinfo
, data
,
1629 &irr
->rasAddress
, 1);
1634 set_sig_addr
= rcu_dereference(set_sig_addr_hook
);
1635 if (set_sig_addr
&& ct
->status
& IPS_NAT_MASK
) {
1636 ret
= set_sig_addr(skb
, ct
, ctinfo
, data
,
1637 irr
->callSignalAddress
.item
,
1638 irr
->callSignalAddress
.count
);
1646 /****************************************************************************/
1647 static int process_ras(struct sk_buff
*skb
, struct nf_conn
*ct
,
1648 enum ip_conntrack_info ctinfo
,
1649 unsigned char **data
, RasMessage
*ras
)
1651 switch (ras
->choice
) {
1652 case eRasMessage_gatekeeperRequest
:
1653 return process_grq(skb
, ct
, ctinfo
, data
,
1654 &ras
->gatekeeperRequest
);
1655 case eRasMessage_gatekeeperConfirm
:
1656 return process_gcf(skb
, ct
, ctinfo
, data
,
1657 &ras
->gatekeeperConfirm
);
1658 case eRasMessage_registrationRequest
:
1659 return process_rrq(skb
, ct
, ctinfo
, data
,
1660 &ras
->registrationRequest
);
1661 case eRasMessage_registrationConfirm
:
1662 return process_rcf(skb
, ct
, ctinfo
, data
,
1663 &ras
->registrationConfirm
);
1664 case eRasMessage_unregistrationRequest
:
1665 return process_urq(skb
, ct
, ctinfo
, data
,
1666 &ras
->unregistrationRequest
);
1667 case eRasMessage_admissionRequest
:
1668 return process_arq(skb
, ct
, ctinfo
, data
,
1669 &ras
->admissionRequest
);
1670 case eRasMessage_admissionConfirm
:
1671 return process_acf(skb
, ct
, ctinfo
, data
,
1672 &ras
->admissionConfirm
);
1673 case eRasMessage_locationRequest
:
1674 return process_lrq(skb
, ct
, ctinfo
, data
,
1675 &ras
->locationRequest
);
1676 case eRasMessage_locationConfirm
:
1677 return process_lcf(skb
, ct
, ctinfo
, data
,
1678 &ras
->locationConfirm
);
1679 case eRasMessage_infoRequestResponse
:
1680 return process_irr(skb
, ct
, ctinfo
, data
,
1681 &ras
->infoRequestResponse
);
1683 pr_debug("nf_ct_ras: RAS message %d\n", ras
->choice
);
1690 /****************************************************************************/
1691 static int ras_help(struct sk_buff
*skb
, unsigned int protoff
,
1692 struct nf_conn
*ct
, enum ip_conntrack_info ctinfo
)
1694 static RasMessage ras
;
1695 unsigned char *data
;
1699 pr_debug("nf_ct_ras: skblen = %u\n", skb
->len
);
1701 spin_lock_bh(&nf_h323_lock
);
1704 data
= get_udp_data(skb
, protoff
, &datalen
);
1707 pr_debug("nf_ct_ras: RAS message len=%d ", datalen
);
1708 nf_ct_dump_tuple(&ct
->tuplehash
[CTINFO2DIR(ctinfo
)].tuple
);
1710 /* Decode RAS message */
1711 ret
= DecodeRasMessage(data
, datalen
, &ras
);
1713 pr_debug("nf_ct_ras: decoding error: %s\n",
1714 ret
== H323_ERROR_BOUND
?
1715 "out of bound" : "out of range");
1719 /* Process RAS message */
1720 if (process_ras(skb
, ct
, ctinfo
, &data
, &ras
) < 0)
1724 spin_unlock_bh(&nf_h323_lock
);
1728 spin_unlock_bh(&nf_h323_lock
);
1729 if (net_ratelimit())
1730 printk("nf_ct_ras: packet dropped\n");
1734 /****************************************************************************/
1735 static const struct nf_conntrack_expect_policy ras_exp_policy
= {
1740 static struct nf_conntrack_helper nf_conntrack_helper_ras
[] __read_mostly
= {
1744 .tuple
.src
.l3num
= AF_INET
,
1745 .tuple
.src
.u
.udp
.port
= __constant_htons(RAS_PORT
),
1746 .tuple
.dst
.protonum
= IPPROTO_UDP
,
1748 .expect_policy
= &ras_exp_policy
,
1753 .tuple
.src
.l3num
= AF_INET6
,
1754 .tuple
.src
.u
.udp
.port
= __constant_htons(RAS_PORT
),
1755 .tuple
.dst
.protonum
= IPPROTO_UDP
,
1757 .expect_policy
= &ras_exp_policy
,
1761 /****************************************************************************/
1762 static void __exit
nf_conntrack_h323_fini(void)
1764 nf_conntrack_helper_unregister(&nf_conntrack_helper_ras
[1]);
1765 nf_conntrack_helper_unregister(&nf_conntrack_helper_ras
[0]);
1766 nf_conntrack_helper_unregister(&nf_conntrack_helper_q931
[1]);
1767 nf_conntrack_helper_unregister(&nf_conntrack_helper_q931
[0]);
1769 pr_debug("nf_ct_h323: fini\n");
1772 /****************************************************************************/
1773 static int __init
nf_conntrack_h323_init(void)
1777 h323_buffer
= kmalloc(65536, GFP_KERNEL
);
1780 ret
= nf_conntrack_helper_register(&nf_conntrack_helper_q931
[0]);
1783 ret
= nf_conntrack_helper_register(&nf_conntrack_helper_q931
[1]);
1786 ret
= nf_conntrack_helper_register(&nf_conntrack_helper_ras
[0]);
1789 ret
= nf_conntrack_helper_register(&nf_conntrack_helper_ras
[1]);
1792 pr_debug("nf_ct_h323: init success\n");
1796 nf_conntrack_helper_unregister(&nf_conntrack_helper_ras
[0]);
1798 nf_conntrack_helper_unregister(&nf_conntrack_helper_q931
[1]);
1800 nf_conntrack_helper_unregister(&nf_conntrack_helper_q931
[0]);
1805 /****************************************************************************/
1806 module_init(nf_conntrack_h323_init
);
1807 module_exit(nf_conntrack_h323_fini
);
1809 EXPORT_SYMBOL_GPL(get_h225_addr
);
1810 EXPORT_SYMBOL_GPL(set_h245_addr_hook
);
1811 EXPORT_SYMBOL_GPL(set_h225_addr_hook
);
1812 EXPORT_SYMBOL_GPL(set_sig_addr_hook
);
1813 EXPORT_SYMBOL_GPL(set_ras_addr_hook
);
1814 EXPORT_SYMBOL_GPL(nat_rtp_rtcp_hook
);
1815 EXPORT_SYMBOL_GPL(nat_t120_hook
);
1816 EXPORT_SYMBOL_GPL(nat_h245_hook
);
1817 EXPORT_SYMBOL_GPL(nat_callforwarding_hook
);
1818 EXPORT_SYMBOL_GPL(nat_q931_hook
);
1820 MODULE_AUTHOR("Jing Min Zhao <zhaojingmin@users.sourceforge.net>");
1821 MODULE_DESCRIPTION("H.323 connection tracking helper");
1822 MODULE_LICENSE("GPL");
1823 MODULE_ALIAS("ip_conntrack_h323");