1 diff -NurpP --minimal linux-2.6.19-pom-ng/include/linux/netfilter_ipv4/ip_conntrack_quake3.h linux-2.6.19/include/linux/netfilter_ipv4/ip_conntrack_quake3.h
2 --- linux-2.6.19-pom-ng/include/linux/netfilter_ipv4/ip_conntrack_quake3.h 1970-01-01 01:00:00.000000000 +0100
3 +++ linux-2.6.19/include/linux/netfilter_ipv4/ip_conntrack_quake3.h 2006-12-14 11:21:52.000000000 +0100
8 +/* Don't confuse with 27960, often used as the Server Port */
9 +#define QUAKE3_MASTER_PORT 27950
11 +struct quake3_search {
12 + const char marker[4]; /* always 0xff 0xff 0xff 0xff ? */
13 + const char *pattern;
17 +/* This structure is per expected connection */
18 +struct ip_ct_quake3_expect {
21 +/* This structure exists only once per master */
22 +struct ip_ct_quake3_master {
25 +extern unsigned int (*ip_nat_quake3_hook)(struct ip_conntrack_expect *exp);
26 +#endif /* _IP_CT_QUAKE3 */
27 diff -NurpP --minimal linux-2.6.19-pom-ng/net/ipv4/netfilter/Kconfig linux-2.6.19/net/ipv4/netfilter/Kconfig
28 --- linux-2.6.19-pom-ng/net/ipv4/netfilter/Kconfig 2006-12-14 11:13:22.000000000 +0100
29 +++ linux-2.6.19/net/ipv4/netfilter/Kconfig 2006-12-14 11:21:52.000000000 +0100
30 @@ -820,5 +820,23 @@ config IP_NF_MMS
31 If you want to compile it as a module, say M here and read
32 <file:Documentation/modules.txt>. If unsure, say `Y'.
34 +config IP_NF_NAT_QUAKE3
36 + depends on IP_NF_CONNTRACK!=n && IP_NF_NAT !=n
37 + default IP_NF_NAT if IP_NF_QUAKE3=y
38 + default m if IP_NF_QUAKE3=m
41 + tristate "Quake3 protocol support"
42 + depends on IP_NF_CONNTRACK
44 + Quake III Arena connection tracking helper. This module allows for a
45 + stricter firewall rulebase if one only allows traffic to a master
46 + server. Connections to Quake III server IP addresses and ports returned
47 + by the master server will be tracked automatically.
49 + If you want to compile it as a module, say M here and read
50 + <file:Documentation/modules.txt>. If unsure, say `Y'.
54 diff -NurpP --minimal linux-2.6.19-pom-ng/net/ipv4/netfilter/Makefile linux-2.6.19/net/ipv4/netfilter/Makefile
55 --- linux-2.6.19-pom-ng/net/ipv4/netfilter/Makefile 2006-12-14 11:13:22.000000000 +0100
56 +++ linux-2.6.19/net/ipv4/netfilter/Makefile 2006-12-14 11:21:52.000000000 +0100
57 @@ -25,6 +25,7 @@ obj-$(CONFIG_IP_NF_CONNTRACK_NETLINK) +=
58 obj-$(CONFIG_IP_NF_CT_PROTO_SCTP) += ip_conntrack_proto_sctp.o
60 # connection tracking helpers
61 +obj-$(CONFIG_IP_NF_QUAKE3) += ip_conntrack_quake3.o
62 obj-$(CONFIG_IP_NF_MMS) += ip_conntrack_mms.o
63 obj-$(CONFIG_IP_NF_H323) += ip_conntrack_h323.o
64 obj-$(CONFIG_IP_NF_PPTP) += ip_conntrack_pptp.o
65 @@ -43,6 +44,7 @@ obj-$(CONFIG_IP_NF_NAT_AMANDA) += ip_nat
66 obj-$(CONFIG_IP_NF_NAT_TFTP) += ip_nat_tftp.o
67 obj-$(CONFIG_IP_NF_NAT_FTP) += ip_nat_ftp.o
68 obj-$(CONFIG_IP_NF_NAT_IRC) += ip_nat_irc.o
69 +obj-$(CONFIG_IP_NF_NAT_QUAKE3) += ip_nat_quake3.o
70 obj-$(CONFIG_IP_NF_NAT_SIP) += ip_nat_sip.o
73 diff -NurpP --minimal linux-2.6.19-pom-ng/net/ipv4/netfilter/ip_conntrack_quake3.c linux-2.6.19/net/ipv4/netfilter/ip_conntrack_quake3.c
74 --- linux-2.6.19-pom-ng/net/ipv4/netfilter/ip_conntrack_quake3.c 1970-01-01 01:00:00.000000000 +0100
75 +++ linux-2.6.19/net/ipv4/netfilter/ip_conntrack_quake3.c 2006-12-14 11:21:52.000000000 +0100
77 +/* Quake3 extension for IP connection tracking
78 + * (C) 2002 by Filip Sneppe <filip.sneppe@cronos.be>
79 + * (C) 2005 by Harald Welte <laforge@netfilter.org>
80 + * based on ip_conntrack_ftp.c and ip_conntrack_tftp.c
82 + * ip_conntrack_quake3.c v0.04 2002-08-31
84 + * This program is free software; you can redistribute it and/or
85 + * modify it under the terms of the GNU General Public License
86 + * as published by the Free Software Foundation; either version
87 + * 2 of the License, or (at your option) any later version.
89 + * Module load syntax:
90 + * insmod ip_conntrack_quake3.o ports=port1,port2,...port<MAX_PORTS>
92 + * please give the ports of all Quake3 master servers You wish to
93 + * connect to. If you don't specify ports, the default will be UDP
96 + * Thanks to the Ethereal folks for their analysis of the Quake3 protocol.
99 +#include <linux/module.h>
100 +#include <linux/ip.h>
101 +#include <linux/udp.h>
103 +#include <linux/netfilter.h>
104 +#include <linux/netfilter_ipv4/ip_tables.h>
105 +#include <linux/netfilter_ipv4/ip_conntrack_helper.h>
106 +#include <linux/netfilter_ipv4/ip_conntrack_quake3.h>
108 +MODULE_AUTHOR("Filip Sneppe <filip.sneppe@cronos.be>");
109 +MODULE_DESCRIPTION("Netfilter connection tracking module for Quake III Arena");
110 +MODULE_LICENSE("GPL");
113 +static int ports[MAX_PORTS];
114 +static int ports_c = 0;
115 +module_param_array(ports, int, &ports_c, 0400);
116 +MODULE_PARM_DESC(ports, "port numbers of Quake III master servers");
118 +static char quake3_buffer[65536];
119 +static DECLARE_LOCK(quake3_buffer_lock);
121 +static unsigned int (*ip_nat_quake3_hook)(struct ip_conntrack_expect *exp);
123 +/* Quake3 master server reply will add > 100 expectations per reply packet; when
124 + doing lots of printk's, klogd may not be able to read /proc/kmsg fast enough */
126 +#define DEBUGP printk
128 +#define DEBUGP(format, args...)
131 +struct quake3_search quake3s_conntrack = { "****", "getserversResponse", sizeof("getserversResponse") - 1 };
133 +static int quake3_help(struct sk_buff **pskb,
134 + struct ip_conntrack *ct,
135 + enum ip_conntrack_info ctinfo)
137 + struct udphdr _udph, *uh;
138 + struct ip_conntrack_expect *exp;
139 + void *data, *qb_ptr;
140 + int dir = CTINFO2DIR(ctinfo);
142 + int ret = NF_ACCEPT;
145 + /* Until there's been traffic both ways, don't look in packets. note:
147 + if (ctinfo != IP_CT_ESTABLISHED
148 + && ctinfo != IP_CT_IS_REPLY) {
149 + DEBUGP("ip_conntrack_quake3: not ok ! Conntrackinfo = %u\n",
153 + DEBUGP("ip_conntrack_quake3: it's ok ! Conntrackinfo = %u\n",
157 + /* Valid UDP header? */
158 + uh = skb_header_pointer(*pskb, (*pskb)->nh.iph->ihl*4,
159 + sizeof(_udph), &_udph);
164 + dataoff = (*pskb)->nh.iph->ihl*4 + sizeof(struct udphdr);
165 + if (dataoff >= (*pskb)->len)
168 + LOCK_BH(&quake3_buffer_lock);
169 + qb_ptr = skb_header_pointer(*pskb, dataoff,
170 + (*pskb)->len - dataoff, quake3_buffer);
171 + BUG_ON(qb_ptr == NULL);
175 + if (strnicmp(data + 4, quake3s_conntrack.pattern,
176 + quake3s_conntrack.plen) == 0) {
177 + for(i=23; /* 4 bytes filler, 18 bytes "getserversResponse",
179 + i+6 < ntohs(uh->len);
181 + u_int32_t *ip = data+i;
182 + u_int16_t *port = data+i+4;
184 + DEBUGP("ip_conntrack_quake3: adding server at offset "
185 + "%u/%u %u.%u.%u.%u:%u\n", i, ntohs(uh->len),
186 + NIPQUAD(*ip), ntohs(*port));
189 + exp = ip_conntrack_expect_alloc();
195 + memset(exp, 0, sizeof(*exp));
197 + exp->tuple.src.ip = ct->tuplehash[!dir].tuple.src.ip;
198 + exp->tuple.dst.ip = *ip;
199 + exp->tuple.dst.u.udp.port = *port;
200 + exp->tuple.dst.protonum = IPPROTO_UDP;
202 + exp->mask.src.ip = 0xffffffff;
203 + exp->mask.dst.ip = 0xffffffff;
204 + exp->mask.dst.u.udp.port = 0xffff;
205 + exp->mask.dst.protonum = 0xff;
207 + if (ip_nat_quake3_hook)
208 + ret = ip_nat_quake3_hook(exp);
209 + else if (ip_conntrack_expect_related(exp) != 0) {
210 + ip_conntrack_expect_free(exp);
221 +static struct ip_conntrack_helper quake3[MAX_PORTS];
222 +static char quake3_names[MAX_PORTS][13]; /* quake3-65535 */
224 +static void fini(void)
228 + for(i = 0 ; (i < ports_c); i++) {
229 + DEBUGP("ip_conntrack_quake3: unregistering helper for port %d\n",
231 + ip_conntrack_helper_unregister(&quake3[i]);
235 +static int __init init(void)
241 + ports[0]=QUAKE3_MASTER_PORT;
243 + for(i = 0 ; (i < MAX_PORTS) && ports[i] ; i++) {
244 + /* Create helper structure */
245 + memset(&quake3[i], 0, sizeof(struct ip_conntrack_helper));
247 + quake3[i].tuple.dst.protonum = IPPROTO_UDP;
248 + quake3[i].tuple.src.u.udp.port = htons(ports[i]);
249 + quake3[i].mask.dst.protonum = 0xFF;
250 + quake3[i].mask.src.u.udp.port = 0xFFFF;
251 + quake3[i].help = quake3_help;
252 + quake3[i].me = THIS_MODULE;
253 + quake3[i].timeout = 120;
255 + tmpname = &quake3_names[i][0];
256 + if (ports[i] == QUAKE3_MASTER_PORT)
257 + sprintf(tmpname, "quake3");
259 + sprintf(tmpname, "quake3-%d", i);
260 + quake3[i].name = tmpname;
262 + DEBUGP("ip_conntrack_quake3: registering helper for port %d\n",
265 + ret=ip_conntrack_helper_register(&quake3[i]);
278 diff -NurpP --minimal linux-2.6.19-pom-ng/net/ipv4/netfilter/ip_nat_quake3.c linux-2.6.19/net/ipv4/netfilter/ip_nat_quake3.c
279 --- linux-2.6.19-pom-ng/net/ipv4/netfilter/ip_nat_quake3.c 1970-01-01 01:00:00.000000000 +0100
280 +++ linux-2.6.19/net/ipv4/netfilter/ip_nat_quake3.c 2006-12-14 11:21:52.000000000 +0100
282 +/* Quake3 extension for UDP NAT alteration.
283 + * (C) 2002 by Filip Sneppe <filip.sneppe@cronos.be>
284 + * (C) 2005 by Harald Welte <laforge@netfilter.org>
285 + * based on ip_nat_ftp.c and ip_nat_tftp.c
287 + * ip_nat_quake3.c v0.0.3 2002-08-31
289 + * This program is free software; you can redistribute it and/or
290 + * modify it under the terms of the GNU General Public License
291 + * as published by the Free Software Foundation; either version
292 + * 2 of the License, or (at your option) any later version.
294 + * Module load syntax:
295 + * insmod ip_nat_quake3.o ports=port1,port2,...port<MAX_PORTS>
297 + * please give the ports of all Quake3 master servers You wish to
298 + * connect to. If you don't specify ports, the default will be UDP
301 + * Thanks to the Ethereal folks for their analysis of the Quake3 protocol.
304 + * - If you're one of those people who would try anything to lower
305 + * latency while playing Quake (and who isn't :-) ), you may want to
306 + * consider not loading ip_nat_quake3 at all and just MASQUERADE all
307 + * outgoing UDP traffic.
308 + * This will make ip_conntrack_quake3 add the necessary expectations,
309 + * but there will be no overhead for client->server UDP streams. If
310 + * ip_nat_quake3 is loaded, quake3_nat_expected will be called per NAT
311 + * hook for every packet in the client->server UDP stream.
312 + * - Only SNAT/MASQUEARDE targets are useful for ip_nat_quake3.
313 + * The IP addresses in the master connection payload (=IP addresses
314 + * of Quake servers) have no relation with the master server so
315 + * DNAT'ing the master connection to a server should not change the
316 + * expected connections.
317 + * - Not tested due to lack of equipment:
318 + * - multiple Quake3 clients behind one MASQUERADE gateway
319 + * - what if Quake3 client is running on router too
322 +#include <linux/module.h>
323 +#include <linux/netfilter_ipv4.h>
324 +#include <linux/ip.h>
325 +#include <linux/udp.h>
327 +#include <linux/netfilter.h>
328 +#include <linux/netfilter_ipv4/ip_tables.h>
329 +#include <linux/netfilter_ipv4/ip_conntrack_helper.h>
330 +#include <linux/netfilter_ipv4/ip_conntrack_quake3.h>
331 +#include <linux/netfilter_ipv4/ip_nat_helper.h>
333 +MODULE_AUTHOR("Filip Sneppe <filip.sneppe@cronos.be>");
334 +MODULE_DESCRIPTION("Netfilter NAT helper for Quake III Arena");
335 +MODULE_LICENSE("GPL");
337 +/* Quake3 master server reply will add > 100 expectations per reply packet; when
338 + doing lots of printk's, klogd may not be able to read /proc/kmsg fast enough */
340 +#define DEBUGP printk
342 +#define DEBUGP(format, args...)
346 +quake3_nat_help(struct ip_conntrack_expect *exp)
348 + struct ip_conntrack *ct = exp->master;
350 + /* What is this? Why don't we try to alter the port? -HW */
351 + exp->tuple.src.ip = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.ip;
352 + exp->saved_proto.udp.port = exp->tuple.dst.u.udp.port;
353 + exp->expectfn = ip_nat_follow_master;
356 + if (ip_conntrack_expect_related(exp) != 0) {
357 + ip_conntrack_expect_free(exp);
364 +static void fini(void)
366 + ip_nat_quake3_hook = NULL;
370 +static int __init init(void)
372 + BUG_ON(ip_nat_quake3_hook);
373 + ip_nat_quake3_hook = quake3_nat_help;