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