12 #include <linux/module.h>
13 #include <linux/tcp.h>
23 static int set_addr(
struct sk_buff *
skb,
unsigned int protoff,
24 unsigned char **
data,
int dataoff,
28 struct nf_conn *
ct = nf_ct_get(skb, &ctinfo);
41 if (!nf_nat_mangle_tcp_packet(skb, ct, ctinfo,
42 protoff, addroff,
sizeof(buf),
43 (
char *) &buf,
sizeof(buf))) {
49 th = skb_header_pointer(skb, ip_hdrlen(skb),
50 sizeof(_tcph), &_tcph);
53 *data = skb->
data + ip_hdrlen(skb) + th->doff * 4 + dataoff;
56 protoff, addroff,
sizeof(buf),
57 (
char *) &buf,
sizeof(buf))) {
64 *data = skb->
data + ip_hdrlen(skb) +
sizeof(
struct udphdr);
71 static int set_h225_addr(
struct sk_buff *skb,
unsigned int protoff,
72 unsigned char **data,
int dataoff,
76 return set_addr(skb, protoff, data, dataoff, taddr->
ipAddress.
ip,
81 static int set_h245_addr(
struct sk_buff *skb,
unsigned protoff,
82 unsigned char **data,
int dataoff,
86 return set_addr(skb, protoff, data, dataoff,
94 unsigned int protoff,
unsigned char **data,
97 const struct nf_ct_h323_master *
info = nfct_help_data(ct);
103 for (i = 0; i <
count; i++) {
106 port == info->sig_port[dir]) {
113 (
ntohl(
addr.ip) & 0xff000000) == 0x7f000000)
116 pr_debug(
"nf_nat_ras: set signal address %pI4:%hu->%pI4:%hu\n",
119 info->sig_port[!dir]);
120 return set_h225_addr(skb, protoff, data, 0,
124 info->sig_port[!dir]);
126 port == info->sig_port[dir]) {
128 pr_debug(
"nf_nat_ras: set signal address %pI4:%hu->%pI4:%hu\n",
131 info->sig_port[!dir]);
132 return set_h225_addr(skb, protoff, data, 0,
136 info->sig_port[!dir]);
147 unsigned int protoff,
unsigned char **data,
155 for (i = 0; i <
count; i++) {
158 port == ct->
tuplehash[dir].tuple.src.u.udp.port) {
159 pr_debug(
"nf_nat_ras: set rasAddress %pI4:%hu->%pI4:%hu\n",
163 return set_h225_addr(skb, protoff, data, 0, &taddr[i],
176 unsigned int protoff,
unsigned char **data,
int dataoff,
182 struct nf_ct_h323_master *info = nfct_help_data(ct);
188 rtp_exp->saved_proto.udp.port = rtp_exp->
tuple.dst.u.udp.port;
191 rtcp_exp->saved_proto.udp.port = rtcp_exp->
tuple.dst.u.udp.port;
193 rtcp_exp->dir = !dir;
196 for (i = 0; i < H323_RTP_CHANNEL_MAX; i++) {
197 if (info->rtp_port[i][dir] == rtp_port) {
202 rtp_exp->
tuple.dst.u.udp.port = info->rtp_port[
i][dir];
203 rtcp_exp->
tuple.dst.u.udp.port =
206 }
else if (info->rtp_port[i][dir] == 0) {
213 if (i >= H323_RTP_CHANNEL_MAX) {
219 for (nated_port =
ntohs(rtp_exp->
tuple.dst.u.udp.port);
220 nated_port != 0; nated_port += 2) {
223 rtp_exp->
tuple.dst.u.udp.port =
htons(nated_port);
224 ret = nf_ct_expect_related(rtp_exp);
226 rtcp_exp->
tuple.dst.u.udp.port =
227 htons(nated_port + 1);
228 ret = nf_ct_expect_related(rtcp_exp);
231 else if (ret != -
EBUSY) {
236 }
else if (ret != -
EBUSY) {
242 if (nated_port == 0) {
248 if (set_h245_addr(skb, protoff, data, dataoff, taddr,
253 info->rtp_port[
i][dir] = rtp_port;
254 info->rtp_port[
i][!dir] =
htons(nated_port);
262 pr_debug(
"nf_nat_h323: expect RTP %pI4:%hu->%pI4:%hu\n",
263 &rtp_exp->
tuple.src.u3.ip,
265 &rtp_exp->
tuple.dst.u3.ip,
267 pr_debug(
"nf_nat_h323: expect RTCP %pI4:%hu->%pI4:%hu\n",
268 &rtcp_exp->
tuple.src.u3.ip,
270 &rtcp_exp->
tuple.dst.u3.ip,
279 unsigned int protoff,
unsigned char **data,
int dataoff,
287 exp->saved_proto.tcp.port = exp->
tuple.dst.u.tcp.port;
292 for (; nated_port != 0; nated_port++) {
295 exp->
tuple.dst.u.tcp.port =
htons(nated_port);
296 ret = nf_ct_expect_related(exp);
299 else if (ret != -
EBUSY) {
305 if (nated_port == 0) {
311 if (set_h245_addr(skb, protoff, data, dataoff, taddr,
313 htons(nated_port)) < 0) {
318 pr_debug(
"nf_nat_h323: expect T.120 %pI4:%hu->%pI4:%hu\n",
319 &exp->
tuple.src.u3.ip,
321 &exp->
tuple.dst.u3.ip,
330 unsigned int protoff,
unsigned char **data,
int dataoff,
334 struct nf_ct_h323_master *info = nfct_help_data(ct);
339 exp->saved_proto.tcp.port = exp->
tuple.dst.u.tcp.port;
344 if (info->sig_port[dir] == port)
345 nated_port =
ntohs(info->sig_port[!dir]);
348 for (; nated_port != 0; nated_port++) {
351 exp->
tuple.dst.u.tcp.port =
htons(nated_port);
352 ret = nf_ct_expect_related(exp);
355 else if (ret != -
EBUSY) {
361 if (nated_port == 0) {
367 if (set_h225_addr(skb, protoff, data, dataoff, taddr,
369 htons(nated_port)) == 0) {
371 info->sig_port[dir] =
port;
372 info->sig_port[!dir] =
htons(nated_port);
378 pr_debug(
"nf_nat_q931: expect H.245 %pI4:%hu->%pI4:%hu\n",
379 &exp->
tuple.src.u3.ip,
381 &exp->
tuple.dst.u3.ip,
391 static void ip_nat_q931_expect(
struct nf_conn *
new,
396 if (this->tuple.src.u3.ip != 0) {
407 new->tuplehash[!this->dir].tuple.src.u3;
412 range.min_proto =
range.max_proto = this->saved_proto;
414 new->master->tuplehash[!this->dir].tuple.src.u3;
421 unsigned int protoff,
unsigned char **data,
425 struct nf_ct_h323_master *info = nfct_help_data(ct);
431 exp->saved_proto.tcp.port = exp->
tuple.dst.u.tcp.port;
436 if (info->sig_port[dir] == port)
437 nated_port =
ntohs(info->sig_port[!dir]);
440 for (; nated_port != 0; nated_port++) {
443 exp->
tuple.dst.u.tcp.port =
htons(nated_port);
444 ret = nf_ct_expect_related(exp);
447 else if (ret != -
EBUSY) {
453 if (nated_port == 0) {
459 if (set_h225_addr(skb, protoff, data, 0, &taddr[idx],
461 htons(nated_port)) == 0) {
463 info->sig_port[dir] =
port;
464 info->sig_port[!dir] =
htons(nated_port);
469 (
ntohl(
addr.ip) & 0xff000000) == 0x7f000000) {
470 set_h225_addr(skb, protoff, data, 0, &taddr[0],
472 info->sig_port[!dir]);
480 pr_debug(
"nf_nat_ras: expect Q.931 %pI4:%hu->%pI4:%hu\n",
481 &exp->
tuple.src.u3.ip,
483 &exp->
tuple.dst.u3.ip,
490 static void ip_nat_callforwarding_expect(
struct nf_conn *
new,
501 new->tuplehash[!this->dir].tuple.src.u3;
506 range.min_proto =
range.max_proto = this->saved_proto;
507 range.min_addr =
range.max_addr = this->saved_addr;
512 static int nat_callforwarding(
struct sk_buff *skb,
struct nf_conn *ct,
514 unsigned int protoff,
515 unsigned char **data,
int dataoff,
523 exp->saved_addr = exp->
tuple.dst.u3;
525 exp->saved_proto.tcp.port = exp->
tuple.dst.u.tcp.port;
526 exp->
expectfn = ip_nat_callforwarding_expect;
530 for (nated_port =
ntohs(port); nated_port != 0; nated_port++) {
533 exp->
tuple.dst.u.tcp.port =
htons(nated_port);
534 ret = nf_ct_expect_related(exp);
537 else if (ret != -
EBUSY) {
543 if (nated_port == 0) {
549 if (!set_h225_addr(skb, protoff, data, dataoff, taddr,
551 htons(nated_port)) == 0) {
557 pr_debug(
"nf_nat_q931: expect Call Forwarding %pI4:%hu->%pI4:%hu\n",
558 &exp->
tuple.src.u3.ip,
560 &exp->
tuple.dst.u3.ip,
568 .expectfn = ip_nat_q931_expect,
572 .name =
"callforwarding",
573 .expectfn = ip_nat_callforwarding_expect,
604 static void __exit fini(
void)