aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
Diffstat (limited to 'net')
-rw-r--r--net/ipv4/netfilter/Kconfig5
-rw-r--r--net/ipv4/netfilter/Makefile1
-rw-r--r--net/ipv4/netfilter/nf_nat_tftp.c52
-rw-r--r--net/netfilter/Kconfig11
-rw-r--r--net/netfilter/Makefile1
-rw-r--r--net/netfilter/nf_conntrack_tftp.c159
6 files changed, 229 insertions, 0 deletions
diff --git a/net/ipv4/netfilter/Kconfig b/net/ipv4/netfilter/Kconfig
index 83e83f553ccb..1c0018b6bea4 100644
--- a/net/ipv4/netfilter/Kconfig
+++ b/net/ipv4/netfilter/Kconfig
@@ -515,6 +515,11 @@ config IP_NF_NAT_TFTP
515 default IP_NF_NAT if IP_NF_TFTP=y 515 default IP_NF_NAT if IP_NF_TFTP=y
516 default m if IP_NF_TFTP=m 516 default m if IP_NF_TFTP=m
517 517
518config NF_NAT_TFTP
519 tristate
520 depends on IP_NF_IPTABLES && NF_CONNTRACK && NF_NAT
521 default NF_NAT && NF_CONNTRACK_TFTP
522
518config IP_NF_NAT_AMANDA 523config IP_NF_NAT_AMANDA
519 tristate 524 tristate
520 depends on IP_NF_IPTABLES!=n && IP_NF_CONNTRACK!=n && IP_NF_NAT!=n 525 depends on IP_NF_IPTABLES!=n && IP_NF_CONNTRACK!=n && IP_NF_NAT!=n
diff --git a/net/ipv4/netfilter/Makefile b/net/ipv4/netfilter/Makefile
index 167b65e89aca..3ca0af0ed5f0 100644
--- a/net/ipv4/netfilter/Makefile
+++ b/net/ipv4/netfilter/Makefile
@@ -56,6 +56,7 @@ obj-$(CONFIG_NF_NAT_H323) += nf_nat_h323.o
56obj-$(CONFIG_NF_NAT_IRC) += nf_nat_irc.o 56obj-$(CONFIG_NF_NAT_IRC) += nf_nat_irc.o
57obj-$(CONFIG_NF_NAT_PPTP) += nf_nat_pptp.o 57obj-$(CONFIG_NF_NAT_PPTP) += nf_nat_pptp.o
58obj-$(CONFIG_NF_NAT_SIP) += nf_nat_sip.o 58obj-$(CONFIG_NF_NAT_SIP) += nf_nat_sip.o
59obj-$(CONFIG_NF_NAT_TFTP) += nf_nat_tftp.o
59 60
60# NAT protocols (nf_nat) 61# NAT protocols (nf_nat)
61obj-$(CONFIG_NF_NAT_PROTO_GRE) += nf_nat_proto_gre.o 62obj-$(CONFIG_NF_NAT_PROTO_GRE) += nf_nat_proto_gre.o
diff --git a/net/ipv4/netfilter/nf_nat_tftp.c b/net/ipv4/netfilter/nf_nat_tftp.c
new file mode 100644
index 000000000000..2566b79de224
--- /dev/null
+++ b/net/ipv4/netfilter/nf_nat_tftp.c
@@ -0,0 +1,52 @@
1/* (C) 2001-2002 Magnus Boden <mb@ozaba.mine.nu>
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 as
5 * published by the Free Software Foundation.
6 */
7
8#include <linux/module.h>
9#include <linux/moduleparam.h>
10#include <linux/udp.h>
11
12#include <net/netfilter/nf_nat_helper.h>
13#include <net/netfilter/nf_nat_rule.h>
14#include <net/netfilter/nf_conntrack_helper.h>
15#include <net/netfilter/nf_conntrack_expect.h>
16#include <linux/netfilter/nf_conntrack_tftp.h>
17
18MODULE_AUTHOR("Magnus Boden <mb@ozaba.mine.nu>");
19MODULE_DESCRIPTION("TFTP NAT helper");
20MODULE_LICENSE("GPL");
21MODULE_ALIAS("ip_nat_tftp");
22
23static unsigned int help(struct sk_buff **pskb,
24 enum ip_conntrack_info ctinfo,
25 struct nf_conntrack_expect *exp)
26{
27 struct nf_conn *ct = exp->master;
28
29 exp->saved_proto.udp.port
30 = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.u.udp.port;
31 exp->dir = IP_CT_DIR_REPLY;
32 exp->expectfn = nf_nat_follow_master;
33 if (nf_conntrack_expect_related(exp) != 0)
34 return NF_DROP;
35 return NF_ACCEPT;
36}
37
38static void __exit nf_nat_tftp_fini(void)
39{
40 rcu_assign_pointer(nf_nat_tftp_hook, NULL);
41 synchronize_rcu();
42}
43
44static int __init nf_nat_tftp_init(void)
45{
46 BUG_ON(rcu_dereference(nf_nat_tftp_hook));
47 rcu_assign_pointer(nf_nat_tftp_hook, help);
48 return 0;
49}
50
51module_init(nf_nat_tftp_init);
52module_exit(nf_nat_tftp_fini);
diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
index e73891194b31..e0deac17df12 100644
--- a/net/netfilter/Kconfig
+++ b/net/netfilter/Kconfig
@@ -248,6 +248,17 @@ config NF_CONNTRACK_SIP
248 248
249 To compile it as a module, choose M here. If unsure, say N. 249 To compile it as a module, choose M here. If unsure, say N.
250 250
251config NF_CONNTRACK_TFTP
252 tristate "TFTP protocol support (EXPERIMENTAL)"
253 depends on EXPERIMENTAL && NF_CONNTRACK
254 help
255 TFTP connection tracking helper, this is required depending
256 on how restrictive your ruleset is.
257 If you are using a tftp client behind -j SNAT or -j MASQUERADING
258 you will need this.
259
260 To compile it as a module, choose M here. If unsure, say N.
261
251config NF_CT_NETLINK 262config NF_CT_NETLINK
252 tristate 'Connection tracking netlink interface (EXPERIMENTAL)' 263 tristate 'Connection tracking netlink interface (EXPERIMENTAL)'
253 depends on EXPERIMENTAL && NF_CONNTRACK && NETFILTER_NETLINK 264 depends on EXPERIMENTAL && NF_CONNTRACK && NETFILTER_NETLINK
diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
index 86da21700aa3..5dc5574f7e99 100644
--- a/net/netfilter/Makefile
+++ b/net/netfilter/Makefile
@@ -30,6 +30,7 @@ obj-$(CONFIG_NF_CONNTRACK_IRC) += nf_conntrack_irc.o
30obj-$(CONFIG_NF_CONNTRACK_NETBIOS_NS) += nf_conntrack_netbios_ns.o 30obj-$(CONFIG_NF_CONNTRACK_NETBIOS_NS) += nf_conntrack_netbios_ns.o
31obj-$(CONFIG_NF_CONNTRACK_PPTP) += nf_conntrack_pptp.o 31obj-$(CONFIG_NF_CONNTRACK_PPTP) += nf_conntrack_pptp.o
32obj-$(CONFIG_NF_CONNTRACK_SIP) += nf_conntrack_sip.o 32obj-$(CONFIG_NF_CONNTRACK_SIP) += nf_conntrack_sip.o
33obj-$(CONFIG_NF_CONNTRACK_TFTP) += nf_conntrack_tftp.o
33 34
34# generic X tables 35# generic X tables
35obj-$(CONFIG_NETFILTER_XTABLES) += x_tables.o xt_tcpudp.o 36obj-$(CONFIG_NETFILTER_XTABLES) += x_tables.o xt_tcpudp.o
diff --git a/net/netfilter/nf_conntrack_tftp.c b/net/netfilter/nf_conntrack_tftp.c
new file mode 100644
index 000000000000..d46a1263fcb5
--- /dev/null
+++ b/net/netfilter/nf_conntrack_tftp.c
@@ -0,0 +1,159 @@
1/* (C) 2001-2002 Magnus Boden <mb@ozaba.mine.nu>
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 as
5 * published by the Free Software Foundation.
6 */
7
8#include <linux/module.h>
9#include <linux/moduleparam.h>
10#include <linux/in.h>
11#include <linux/udp.h>
12
13#include <net/netfilter/nf_conntrack.h>
14#include <net/netfilter/nf_conntrack_tuple.h>
15#include <net/netfilter/nf_conntrack_expect.h>
16#include <net/netfilter/nf_conntrack_ecache.h>
17#include <net/netfilter/nf_conntrack_helper.h>
18#include <linux/netfilter/nf_conntrack_tftp.h>
19
20MODULE_AUTHOR("Magnus Boden <mb@ozaba.mine.nu>");
21MODULE_DESCRIPTION("TFTP connection tracking helper");
22MODULE_LICENSE("GPL");
23MODULE_ALIAS("ip_conntrack_tftp");
24
25#define MAX_PORTS 8
26static unsigned short ports[MAX_PORTS];
27static int ports_c;
28module_param_array(ports, ushort, &ports_c, 0400);
29MODULE_PARM_DESC(ports, "Port numbers of TFTP servers");
30
31#if 0
32#define DEBUGP(format, args...) printk("%s:%s:" format, \
33 __FILE__, __FUNCTION__ , ## args)
34#else
35#define DEBUGP(format, args...)
36#endif
37
38unsigned int (*nf_nat_tftp_hook)(struct sk_buff **pskb,
39 enum ip_conntrack_info ctinfo,
40 struct nf_conntrack_expect *exp) __read_mostly;
41EXPORT_SYMBOL_GPL(nf_nat_tftp_hook);
42
43static int tftp_help(struct sk_buff **pskb,
44 unsigned int protoff,
45 struct nf_conn *ct,
46 enum ip_conntrack_info ctinfo)
47{
48 struct tftphdr _tftph, *tfh;
49 struct nf_conntrack_expect *exp;
50 struct nf_conntrack_tuple *tuple;
51 unsigned int ret = NF_ACCEPT;
52 int family = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.l3num;
53 typeof(nf_nat_tftp_hook) nf_nat_tftp;
54
55 tfh = skb_header_pointer(*pskb, protoff + sizeof(struct udphdr),
56 sizeof(_tftph), &_tftph);
57 if (tfh == NULL)
58 return NF_ACCEPT;
59
60 switch (ntohs(tfh->opcode)) {
61 case TFTP_OPCODE_READ:
62 case TFTP_OPCODE_WRITE:
63 /* RRQ and WRQ works the same way */
64 DEBUGP("");
65 NF_CT_DUMP_TUPLE(&ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple);
66 NF_CT_DUMP_TUPLE(&ct->tuplehash[IP_CT_DIR_REPLY].tuple);
67
68 exp = nf_conntrack_expect_alloc(ct);
69 if (exp == NULL)
70 return NF_DROP;
71 tuple = &ct->tuplehash[IP_CT_DIR_REPLY].tuple;
72 nf_conntrack_expect_init(exp, family,
73 &tuple->src.u3, &tuple->dst.u3,
74 IPPROTO_UDP,
75 NULL, &tuple->dst.u.udp.port);
76
77 DEBUGP("expect: ");
78 NF_CT_DUMP_TUPLE(&exp->tuple);
79 NF_CT_DUMP_TUPLE(&exp->mask);
80
81 nf_nat_tftp = rcu_dereference(nf_nat_tftp_hook);
82 if (nf_nat_tftp && ct->status & IPS_NAT_MASK)
83 ret = nf_nat_tftp(pskb, ctinfo, exp);
84 else if (nf_conntrack_expect_related(exp) != 0)
85 ret = NF_DROP;
86 nf_conntrack_expect_put(exp);
87 break;
88 case TFTP_OPCODE_DATA:
89 case TFTP_OPCODE_ACK:
90 DEBUGP("Data/ACK opcode\n");
91 break;
92 case TFTP_OPCODE_ERROR:
93 DEBUGP("Error opcode\n");
94 break;
95 default:
96 DEBUGP("Unknown opcode\n");
97 }
98 return ret;
99}
100
101static struct nf_conntrack_helper tftp[MAX_PORTS][2] __read_mostly;
102static char tftp_names[MAX_PORTS][2][sizeof("tftp-65535")] __read_mostly;
103
104static void nf_conntrack_tftp_fini(void)
105{
106 int i, j;
107
108 for (i = 0; i < ports_c; i++) {
109 for (j = 0; j < 2; j++)
110 nf_conntrack_helper_unregister(&tftp[i][j]);
111 }
112}
113
114static int __init nf_conntrack_tftp_init(void)
115{
116 int i, j, ret;
117 char *tmpname;
118
119 if (ports_c == 0)
120 ports[ports_c++] = TFTP_PORT;
121
122 for (i = 0; i < ports_c; i++) {
123 memset(&tftp[i], 0, sizeof(tftp[i]));
124
125 tftp[i][0].tuple.src.l3num = AF_INET;
126 tftp[i][1].tuple.src.l3num = AF_INET6;
127 for (j = 0; j < 2; j++) {
128 tftp[i][j].tuple.dst.protonum = IPPROTO_UDP;
129 tftp[i][j].tuple.src.u.udp.port = htons(ports[i]);
130 tftp[i][j].mask.src.l3num = 0xFFFF;
131 tftp[i][j].mask.dst.protonum = 0xFF;
132 tftp[i][j].mask.src.u.udp.port = htons(0xFFFF);
133 tftp[i][j].max_expected = 1;
134 tftp[i][j].timeout = 5 * 60; /* 5 minutes */
135 tftp[i][j].me = THIS_MODULE;
136 tftp[i][j].help = tftp_help;
137
138 tmpname = &tftp_names[i][j][0];
139 if (ports[i] == TFTP_PORT)
140 sprintf(tmpname, "tftp");
141 else
142 sprintf(tmpname, "tftp-%u", i);
143 tftp[i][j].name = tmpname;
144
145 ret = nf_conntrack_helper_register(&tftp[i][j]);
146 if (ret) {
147 printk("nf_ct_tftp: failed to register helper "
148 "for pf: %u port: %u\n",
149 tftp[i][j].tuple.src.l3num, ports[i]);
150 nf_conntrack_tftp_fini();
151 return ret;
152 }
153 }
154 }
155 return 0;
156}
157
158module_init(nf_conntrack_tftp_init);
159module_exit(nf_conntrack_tftp_fini);