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