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 static int help(struct sk_buff *skb,
48 struct ip_conntrack *ct, enum ip_conntrack_info ctinfo)
50 struct ip_conntrack_expect *exp;
51 struct ip_ct_amanda_expect *exp_amanda_info;
52 char *amp, *data, *data_limit, *tmp;
53 unsigned int dataoff, i;
56 /* Only look at packets from the Amanda server */
57 if (CTINFO2DIR(ctinfo) == IP_CT_DIR_ORIGINAL)
60 /* increase the UDP timeout of the master connection as replies from
61 * Amanda clients to the server can be quite delayed */
62 ip_ct_refresh_acct(ct, ctinfo, NULL, master_timeout * HZ);
65 dataoff = skb->nh.iph->ihl*4 + sizeof(struct udphdr);
66 if (dataoff >= skb->len) {
68 printk("amanda_help: skblen = %u\n", skb->len);
72 LOCK_BH(&amanda_buffer_lock);
73 amp = skb_header_pointer(skb, dataoff,
74 skb->len - dataoff, amanda_buffer);
77 data_limit = amp + skb->len - dataoff;
80 /* Search for the CONNECT string */
81 data = strstr(data, "CONNECT ");
84 data += strlen("CONNECT ");
86 /* Only search first line. */
87 if ((tmp = strchr(data, '\n')))
90 for (i = 0; i < ARRAY_SIZE(conns); i++) {
91 char *match = strstr(data, conns[i]);
94 tmp = data = match + strlen(conns[i]);
95 port = simple_strtoul(data, &data, 10);
97 if (port == 0 || len > 5)
100 exp = ip_conntrack_expect_alloc();
104 exp->tuple.src.ip = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.ip;
105 exp->tuple.dst.ip = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.ip;
106 exp->tuple.dst.protonum = IPPROTO_TCP;
107 exp->mask.src.ip = 0xFFFFFFFF;
108 exp->mask.dst.ip = 0xFFFFFFFF;
109 exp->mask.dst.protonum = 0xFFFF;
110 exp->mask.dst.u.tcp.port = 0xFFFF;
112 exp_amanda_info = &exp->help.exp_amanda_info;
113 exp_amanda_info->offset = tmp - amp;
114 exp_amanda_info->port = port;
115 exp_amanda_info->len = len;
117 exp->tuple.dst.u.tcp.port = htons(port);
119 ip_conntrack_expect_related(exp, ct);
123 UNLOCK_BH(&amanda_buffer_lock);
127 static struct ip_conntrack_helper amanda_helper = {
128 .max_expected = ARRAY_SIZE(conns),
130 .flags = IP_CT_HELPER_F_REUSE_EXPECT,
135 .tuple = { .src = { .u = { __constant_htons(10080) } },
136 .dst = { .protonum = IPPROTO_UDP },
138 .mask = { .src = { .u = { 0xFFFF } },
139 .dst = { .protonum = 0xFFFF },
143 static void __exit fini(void)
145 ip_conntrack_helper_unregister(&amanda_helper);
148 static int __init init(void)
150 return ip_conntrack_helper_register(&amanda_helper);
153 PROVIDES_CONNTRACK(amanda);