1 /* Amanda extension for IP connection tracking, Version 0.2
2 * (C) 2002 by Brian J. Murrell <netfilter@interlinx.bc.ca>
3 * based on HW's ip_conntrack_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_conntrack_amanda.o [master_timeout=n]
13 * Where master_timeout is the timeout (in seconds) of the master
14 * connection (port 10080). This defaults to 5 minutes but if
15 * your clients take longer than 5 minutes to do their work
16 * before getting back to the Amanda server, you can increase
21 #include <linux/kernel.h>
22 #include <linux/module.h>
23 #include <linux/netfilter.h>
25 #include <linux/moduleparam.h>
26 #include <net/checksum.h>
29 #include <linux/netfilter_ipv4/lockhelp.h>
30 #include <linux/netfilter_ipv4/ip_conntrack_helper.h>
31 #include <linux/netfilter_ipv4/ip_conntrack_amanda.h>
33 static unsigned int master_timeout
= 300;
35 MODULE_AUTHOR("Brian J. Murrell <netfilter@interlinx.bc.ca>");
36 MODULE_DESCRIPTION("Amanda connection tracking module");
37 MODULE_LICENSE("GPL");
38 module_param(master_timeout
, int, 0600);
39 MODULE_PARM_DESC(master_timeout
, "timeout for the master connection");
41 static char *conns
[] = { "DATA ", "MESG ", "INDEX " };
43 /* This is slow, but it's simple. --RR */
44 static char amanda_buffer
[65536];
45 static DECLARE_LOCK(amanda_buffer_lock
);
47 unsigned int (*ip_nat_amanda_hook
)(struct sk_buff
**pskb
,
48 enum ip_conntrack_info ctinfo
,
49 unsigned int matchoff
,
50 unsigned int matchlen
,
51 struct ip_conntrack_expect
*exp
);
52 EXPORT_SYMBOL_GPL(ip_nat_amanda_hook
);
54 static int help(struct sk_buff
**pskb
,
55 struct ip_conntrack
*ct
, enum ip_conntrack_info ctinfo
)
57 struct ip_conntrack_expect
*exp
;
58 char *data
, *data_limit
, *tmp
;
59 unsigned int dataoff
, i
;
63 /* Only look at packets from the Amanda server */
64 if (CTINFO2DIR(ctinfo
) == IP_CT_DIR_ORIGINAL
)
67 /* increase the UDP timeout of the master connection as replies from
68 * Amanda clients to the server can be quite delayed */
69 ip_ct_refresh_acct(ct
, ctinfo
, NULL
, master_timeout
* HZ
);
72 dataoff
= (*pskb
)->nh
.iph
->ihl
*4 + sizeof(struct udphdr
);
73 if (dataoff
>= (*pskb
)->len
) {
75 printk("amanda_help: skblen = %u\n", (*pskb
)->len
);
79 LOCK_BH(&amanda_buffer_lock
);
80 skb_copy_bits(*pskb
, dataoff
, amanda_buffer
, (*pskb
)->len
- dataoff
);
82 data_limit
= amanda_buffer
+ (*pskb
)->len
- dataoff
;
85 /* Search for the CONNECT string */
86 data
= strstr(data
, "CONNECT ");
89 data
+= strlen("CONNECT ");
91 /* Only search first line. */
92 if ((tmp
= strchr(data
, '\n')))
95 for (i
= 0; i
< ARRAY_SIZE(conns
); i
++) {
96 char *match
= strstr(data
, conns
[i
]);
99 tmp
= data
= match
+ strlen(conns
[i
]);
100 port
= simple_strtoul(data
, &data
, 10);
102 if (port
== 0 || len
> 5)
105 exp
= ip_conntrack_expect_alloc();
111 exp
->expectfn
= NULL
;
114 exp
->tuple
.src
.ip
= ct
->tuplehash
[IP_CT_DIR_ORIGINAL
].tuple
.src
.ip
;
115 exp
->tuple
.src
.u
.tcp
.port
= 0;
116 exp
->tuple
.dst
.ip
= ct
->tuplehash
[IP_CT_DIR_ORIGINAL
].tuple
.dst
.ip
;
117 exp
->tuple
.dst
.protonum
= IPPROTO_TCP
;
118 exp
->tuple
.dst
.u
.tcp
.port
= htons(port
);
120 exp
->mask
.src
.ip
= 0xFFFFFFFF;
121 exp
->mask
.src
.u
.tcp
.port
= 0;
122 exp
->mask
.dst
.ip
= 0xFFFFFFFF;
123 exp
->mask
.dst
.protonum
= 0xFF;
124 exp
->mask
.dst
.u
.tcp
.port
= 0xFFFF;
126 if (ip_nat_amanda_hook
)
127 ret
= ip_nat_amanda_hook(pskb
, ctinfo
,
130 else if (ip_conntrack_expect_related(exp
) != 0) {
131 ip_conntrack_expect_free(exp
);
137 UNLOCK_BH(&amanda_buffer_lock
);
141 static struct ip_conntrack_helper amanda_helper
= {
142 .max_expected
= ARRAY_SIZE(conns
),
148 .tuple
= { .src
= { .u
= { __constant_htons(10080) } },
149 .dst
= { .protonum
= IPPROTO_UDP
},
151 .mask
= { .src
= { .u
= { 0xFFFF } },
152 .dst
= { .protonum
= 0xFF },
156 static void __exit
fini(void)
158 ip_conntrack_helper_unregister(&amanda_helper
);
161 static int __init
init(void)
163 return ip_conntrack_helper_register(&amanda_helper
);