11 #include <linux/module.h>
16 #include <linux/tcp.h>
17 #include <linux/netfilter.h>
18 #include <linux/slab.h>
27 static unsigned int ports_c;
28 static unsigned int max_dcc_channels = 8;
31 static char *irc_buffer;
37 unsigned int matchoff,
38 unsigned int matchlen,
51 MODULE_PARM_DESC(max_dcc_channels,
"max number of expected DCC channels per "
56 static const char *
const dccprotos[] = {
57 "SEND ",
"CHAT ",
"MOVE ",
"TSEND ",
"SCHAT "
71 static int parse_dcc(
char *
data,
const char *data_end,
__be32 *
ip,
77 while (*data++ !=
' ')
78 if (data > data_end - 12)
83 for (tmp = data; tmp <= data_end; tmp++)
86 if (tmp > data_end || *tmp !=
'\n')
93 while (*data ==
' ') {
105 static int help(
struct sk_buff *skb,
unsigned int protoff,
108 unsigned int dataoff;
109 const struct iphdr *iph;
112 const char *data_limit;
121 char *addr_beg_p, *addr_end_p;
133 th = skb_header_pointer(skb, protoff,
sizeof(_tcph), &_tcph);
138 dataoff = protoff + th->doff*4;
139 if (dataoff >= skb->len)
142 spin_lock_bh(&irc_buffer_lock);
143 ib_ptr = skb_header_pointer(skb, dataoff, skb->len - dataoff,
148 data_limit = ib_ptr + skb->len - dataoff;
153 if (
memcmp(data,
"\1DCC ", 5)) {
161 pr_debug(
"DCC found in master %pI4:%u %pI4:%u\n",
170 data +=
strlen(dccprotos[i]);
171 pr_debug(
"DCC %s detected\n", dccprotos[i]);
176 if (parse_dcc(data, data_limit, &dcc_ip,
177 &dcc_port, &addr_beg_p, &addr_end_p)) {
178 pr_debug(
"unable to parse dcc command\n");
182 pr_debug(
"DCC bound ip/port: %pI4:%u\n",
187 if (tuple->
src.u3.ip != dcc_ip &&
188 tuple->
dst.u3.ip != dcc_ip) {
201 port =
htons(dcc_port);
204 NULL, &tuple->
dst.u3,
209 ret = nf_nat_irc(skb, ctinfo, protoff,
211 addr_end_p - addr_beg_p,
213 else if (nf_ct_expect_related(exp) != 0)
220 spin_unlock_bh(&irc_buffer_lock);
227 static void nf_conntrack_irc_fini(
void);
229 static int __init nf_conntrack_irc_init(
void)
233 if (max_dcc_channels < 1) {
234 printk(
KERN_ERR "nf_ct_irc: max_dcc_channels must not be zero\n");
238 irc_exp_policy.max_expected = max_dcc_channels;
239 irc_exp_policy.timeout = dcc_timeout;
247 ports[ports_c++] = IRC_PORT;
249 for (i = 0; i < ports_c; i++) {
251 irc[
i].tuple.src.u.tcp.port =
htons(ports[i]);
253 irc[
i].expect_policy = &irc_exp_policy;
257 if (ports[i] == IRC_PORT)
265 "for pf: %u port: %u\n",
266 irc[i].tuple.
src.l3num, ports[i]);
267 nf_conntrack_irc_fini();
276 static void nf_conntrack_irc_fini(
void)
280 for (i = 0; i < ports_c; i++)