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