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