[ARM] 3335/1: Old-abi Thumb sys_syscall broken
[linux-2.6/linux-loongson.git] / net / ipv4 / netfilter / ip_nat_amanda.c
blob3a888715bbf3b536e880bfa7de1975fd1ab5757c
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.
10 * Module load syntax:
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>
18 #include <linux/ip.h>
19 #include <linux/udp.h>
20 #include <net/tcp.h>
21 #include <net/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")];
41 u_int16_t port;
42 unsigned int ret;
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)
56 break;
59 if (port == 0)
60 return NF_DROP;
62 sprintf(buffer, "%u", port);
63 ret = ip_nat_mangle_udp_packet(pskb, exp->master, ctinfo,
64 matchoff, matchlen,
65 buffer, strlen(buffer));
66 if (ret != NF_ACCEPT)
67 ip_conntrack_unexpect_related(exp);
68 return ret;
71 static void __exit ip_nat_amanda_fini(void)
73 ip_nat_amanda_hook = NULL;
74 /* Make sure noone calls it, meanwhile. */
75 synchronize_net();
78 static int __init ip_nat_amanda_init(void)
80 BUG_ON(ip_nat_amanda_hook);
81 ip_nat_amanda_hook = help;
82 return 0;
85 module_init(ip_nat_amanda_init);
86 module_exit(ip_nat_amanda_fini);