1 /* Amanda extension for TCP NAT alteration.
2 * (C) 2002 by Brian J. Murrell <netfilter@interlinx.bc.ca>
3 * based on a copy of HW's ip_nat_irc.c as well as other modules
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version
8 * 2 of the License, or (at your option) any later version.
11 * insmod ip_nat_amanda.o
14 #include <linux/kernel.h>
15 #include <linux/module.h>
16 #include <linux/netfilter.h>
17 #include <linux/skbuff.h>
19 #include <linux/udp.h>
23 #include <linux/netfilter_ipv4.h>
24 #include <linux/netfilter_ipv4/ip_nat.h>
25 #include <linux/netfilter_ipv4/ip_nat_helper.h>
26 #include <linux/netfilter_ipv4/ip_conntrack_helper.h>
27 #include <linux/netfilter_ipv4/ip_conntrack_amanda.h>
30 MODULE_AUTHOR("Brian J. Murrell <netfilter@interlinx.bc.ca>");
31 MODULE_DESCRIPTION("Amanda NAT helper");
32 MODULE_LICENSE("GPL");
34 static unsigned int help(struct sk_buff
**pskb
,
35 enum ip_conntrack_info ctinfo
,
36 unsigned int matchoff
,
37 unsigned int matchlen
,
38 struct ip_conntrack_expect
*exp
)
40 char buffer
[sizeof("65535")];
44 /* Connection comes from client. */
45 exp
->saved_proto
.tcp
.port
= exp
->tuple
.dst
.u
.tcp
.port
;
46 exp
->dir
= IP_CT_DIR_ORIGINAL
;
48 /* When you see the packet, we need to NAT it the same as the
49 * this one (ie. same IP: it will be TCP and master is UDP). */
50 exp
->expectfn
= ip_nat_follow_master
;
52 /* Try to get same port: if not, try to change it. */
53 for (port
= ntohs(exp
->saved_proto
.tcp
.port
); port
!= 0; port
++) {
54 exp
->tuple
.dst
.u
.tcp
.port
= htons(port
);
55 if (ip_conntrack_expect_related(exp
) == 0)
62 sprintf(buffer
, "%u", port
);
63 ret
= ip_nat_mangle_udp_packet(pskb
, exp
->master
, ctinfo
,
65 buffer
, strlen(buffer
));
67 ip_conntrack_unexpect_related(exp
);
71 static void __exit
fini(void)
73 ip_nat_amanda_hook
= NULL
;
74 /* Make sure noone calls it, meanwhile. */
78 static int __init
init(void)
80 BUG_ON(ip_nat_amanda_hook
);
81 ip_nat_amanda_hook
= help
;