d2b590533452e201d48c8b1bc172a0661828b917
1 /* (C) 2001-2002 Magnus Boden <mb@ozaba.mine.nu>
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.
9 * Thu 21 Mar 2002 Harald Welte <laforge@gnumonks.org>
10 * - port to newnat API
14 #include <linux/module.h>
16 #include <linux/udp.h>
18 #include <linux/netfilter.h>
19 #include <linux/netfilter_ipv4/ip_tables.h>
20 #include <linux/netfilter_ipv4/ip_conntrack_helper.h>
21 #include <linux/netfilter_ipv4/ip_conntrack_tftp.h>
22 #include <linux/moduleparam.h>
24 MODULE_AUTHOR("Magnus Boden <mb@ozaba.mine.nu>");
25 MODULE_DESCRIPTION("tftp connection tracking helper");
26 MODULE_LICENSE("GPL");
29 static int ports
[MAX_PORTS
];
31 module_param_array(ports
, int, &ports_c
, 0400);
32 MODULE_PARM_DESC(ports
, "port numbers of tftp servers");
35 #define DEBUGP(format, args...) printk("%s:%s:" format, \
36 __FILE__, __FUNCTION__ , ## args)
38 #define DEBUGP(format, args...)
41 unsigned int (*ip_nat_tftp_hook
)(struct sk_buff
**pskb
,
42 enum ip_conntrack_info ctinfo
,
43 struct ip_conntrack_expect
*exp
);
44 EXPORT_SYMBOL_GPL(ip_nat_tftp_hook
);
46 static int tftp_help(struct sk_buff
**pskb
,
47 struct ip_conntrack
*ct
,
48 enum ip_conntrack_info ctinfo
)
50 struct tftphdr _tftph
, *tfh
;
51 struct ip_conntrack_expect
*exp
;
52 unsigned int ret
= NF_ACCEPT
;
54 tfh
= skb_header_pointer(*pskb
,
55 (*pskb
)->nh
.iph
->ihl
*4+sizeof(struct udphdr
),
56 sizeof(_tftph
), &_tftph
);
60 switch (ntohs(tfh
->opcode
)) {
61 /* RRQ and WRQ works the same way */
62 case TFTP_OPCODE_READ
:
63 case TFTP_OPCODE_WRITE
:
65 DUMP_TUPLE(&ct
->tuplehash
[IP_CT_DIR_ORIGINAL
].tuple
);
66 DUMP_TUPLE(&ct
->tuplehash
[IP_CT_DIR_REPLY
].tuple
);
68 exp
= ip_conntrack_expect_alloc(ct
);
72 exp
->tuple
= ct
->tuplehash
[IP_CT_DIR_REPLY
].tuple
;
73 exp
->mask
.src
.ip
= 0xffffffff;
74 exp
->mask
.dst
.ip
= 0xffffffff;
75 exp
->mask
.dst
.u
.udp
.port
= 0xffff;
76 exp
->mask
.dst
.protonum
= 0xff;
81 DUMP_TUPLE(&exp
->tuple
);
82 DUMP_TUPLE(&exp
->mask
);
84 ret
= ip_nat_tftp_hook(pskb
, ctinfo
, exp
);
85 else if (ip_conntrack_expect_related(exp
) != 0)
87 ip_conntrack_expect_put(exp
);
89 case TFTP_OPCODE_DATA
:
91 DEBUGP("Data/ACK opcode\n");
93 case TFTP_OPCODE_ERROR
:
94 DEBUGP("Error opcode\n");
97 DEBUGP("Unknown opcode\n");
102 static struct ip_conntrack_helper tftp
[MAX_PORTS
];
103 static char tftp_names
[MAX_PORTS
][10];
105 static void fini(void)
109 for (i
= 0 ; i
< ports_c
; i
++) {
110 DEBUGP("unregistering helper for port %d\n",
112 ip_conntrack_helper_unregister(&tftp
[i
]);
116 static int __init
init(void)
122 ports
[ports_c
++] = TFTP_PORT
;
124 for (i
= 0; i
< ports_c
; i
++) {
125 /* Create helper structure */
126 memset(&tftp
[i
], 0, sizeof(struct ip_conntrack_helper
));
128 tftp
[i
].tuple
.dst
.protonum
= IPPROTO_UDP
;
129 tftp
[i
].tuple
.src
.u
.udp
.port
= htons(ports
[i
]);
130 tftp
[i
].mask
.dst
.protonum
= 0xFF;
131 tftp
[i
].mask
.src
.u
.udp
.port
= 0xFFFF;
132 tftp
[i
].max_expected
= 1;
133 tftp
[i
].timeout
= 5 * 60; /* 5 minutes */
134 tftp
[i
].me
= THIS_MODULE
;
135 tftp
[i
].help
= tftp_help
;
137 tmpname
= &tftp_names
[i
][0];
138 if (ports
[i
] == TFTP_PORT
)
139 sprintf(tmpname
, "tftp");
141 sprintf(tmpname
, "tftp-%d", i
);
142 tftp
[i
].name
= tmpname
;
144 DEBUGP("port #%d: %d\n", i
, ports
[i
]);
146 ret
=ip_conntrack_helper_register(&tftp
[i
]);
148 printk("ERROR registering helper for port %d\n",
This page took 0.046086 seconds and 4 git commands to generate.