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