]> git.pld-linux.org Git - packages/kernel.git/blob - 2.6.6-pom-ng-20040518.patch
- minor fix. it builds but linking needs fix.
[packages/kernel.git] / 2.6.6-pom-ng-20040518.patch
1   Netfilter SNAP 20040518
2    included:
3    PENDING/expect-evict-order
4    PENDING/init_conntrack-optimize
5    PENDING/ipt_helper-invert-fix
6    PENDING/nf-log
7    PENDING/nf_reset
8    PENDING/orphaned-expect-fix
9    PENDING/proc-no-internal-targets
10    BASE/HOPLIMIT
11    BASE/IPV4OPTSSTRING
12    BASE/NETLINK                 // fix socket -> sk_socket
13    BASE/REJECT
14    BASE/TTL
15    BASE/connlimit
16    BASE/dstlimit
17    BASE/fuzzy
18    BASE/ipv4options
19    BASE/mport
20    BASE/nth
21    BASE/osf                     // fix socket -> sk_socket
22    BASE/pool                    // added EXPORT_SYMBOL(ip_pool_mod, ip_pool_match)
23    BASE/psd
24    BASE/quota
25    BASE/random
26    BASE/realm
27    BASE/sctp
28    BASE/time
29    BASE/u32
30    EXTRA/CONNMARK
31    EXTRA/IPMARK
32    EXTRA/ROUTE
33    EXTRA/TARPIT                 // fix Makefile.ladd and req patch for 2.6
34    EXTRA/TRACE
35    EXTRA/XOR
36    EXTRA/addrtype
37    EXTRA/eggdrop-conntrack
38    EXTRA/h323-conntrack-nat
39    EXTRA/ipsec-01-output-hooks
40    EXTRA/ipsec-02-input-hooks
41    EXTRA/ipsec-03-policy-lookup
42    EXTRA/ipsec-04-policy-check
43    EXTRA/ipt_helper-any
44    EXTRA/mms-conntrack-nat
45    EXTRA/owner-socketlookup
46    EXTRA/ownercmd
47    EXTRA/policy
48    EXTRA/quake3-conntrack-nat
49    EXTRA/rsh
50    EXTRA/rtsp-conntrack
51    EXTRA/sctp-conntrack-nat
52    EXTRA/string                 // required unclean module - included - req fix
53    EXTRA/talk-conntrack-nat
54    
55 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter.h linux-2.6.6/include/linux/netfilter.h
56 --- linux-2.6.6.org/include/linux/netfilter.h   2004-05-10 04:32:37.000000000 +0200
57 +++ linux-2.6.6/include/linux/netfilter.h       2004-05-18 14:28:50.000000000 +0200
58 @@ -23,6 +23,7 @@
59     <= 0x2000 is used for protocol-flags. */
60  #define NFC_UNKNOWN 0x4000
61  #define NFC_ALTERED 0x8000
62 +#define NFC_TRACE   0x10000
63  
64  #ifdef __KERNEL__
65  #include <linux/config.h>
66 @@ -137,12 +138,14 @@
67  /* This is gross, but inline doesn't cut it for avoiding the function
68     call in fast path: gcc doesn't inline (needs value tracking?). --RR */
69  #ifdef CONFIG_NETFILTER_DEBUG
70 -#define NF_HOOK(pf, hook, skb, indev, outdev, okfn)                    \
71 - nf_hook_slow((pf), (hook), (skb), (indev), (outdev), (okfn), INT_MIN)
72 +#define NF_HOOK_COND(pf, hook, skb, indev, outdev, okfn, cond)         \
73 +(!(cond)                                                               \
74 + ? (okfn)(skb)                                                                 \
75 + : nf_hook_slow((pf), (hook), (skb), (indev), (outdev), (okfn), INT_MIN))
76  #define NF_HOOK_THRESH nf_hook_slow
77  #else
78 -#define NF_HOOK(pf, hook, skb, indev, outdev, okfn)                    \
79 -(list_empty(&nf_hooks[(pf)][(hook)])                                   \
80 +#define NF_HOOK_COND(pf, hook, skb, indev, outdev, okfn, cond)         \
81 +(!(cond) || list_empty(&nf_hooks[(pf)][(hook)])                                \
82   ? (okfn)(skb)                                                         \
83   : nf_hook_slow((pf), (hook), (skb), (indev), (outdev), (okfn), INT_MIN))
84  #define NF_HOOK_THRESH(pf, hook, skb, indev, outdev, okfn, thresh)     \
85 @@ -150,6 +153,8 @@
86   ? (okfn)(skb)                                                         \
87   : nf_hook_slow((pf), (hook), (skb), (indev), (outdev), (okfn), (thresh)))
88  #endif
89 +#define NF_HOOK(pf, hook, skb, indev, outdev, okfn)                    \
90 + NF_HOOK_COND((pf), (hook), (skb), (indev), (outdev), (okfn), 1)
91  
92  int nf_hook_slow(int pf, unsigned int hook, struct sk_buff *skb,
93                  struct net_device *indev, struct net_device *outdev,
94 @@ -182,7 +187,24 @@
95  
96  #else /* !CONFIG_NETFILTER */
97  #define NF_HOOK(pf, hook, skb, indev, outdev, okfn) (okfn)(skb)
98 +#define NF_HOOK_COND(pf, hook, skb, indev, outdev, okfn, cond) (okfn)(skb)
99  #endif /*CONFIG_NETFILTER*/
100  
101 +#ifdef CONFIG_XFRM
102 +#ifdef CONFIG_IP_NF_NAT_NEEDED
103 +struct flowi;
104 +extern void nf_nat_decode_session4(struct sk_buff *skb, struct flowi *fl);
105 +
106 +static inline void
107 +nf_nat_decode_session(struct sk_buff *skb, struct flowi *fl, int family)
108 +{
109 +       if (family == AF_INET)
110 +               nf_nat_decode_session4(skb, fl);
111 +}
112 +#else /* CONFIG_IP_NF_NAT_NEEDED */
113 +#define nf_nat_decode_session(skb,fl,family)
114 +#endif /* CONFIG_IP_NF_NAT_NEEDED */
115 +#endif /* CONFIG_XFRM */
116 +
117  #endif /*__KERNEL__*/
118  #endif /*__LINUX_NETFILTER_H*/
119 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_helpers.h linux-2.6.6/include/linux/netfilter_helpers.h
120 --- linux-2.6.6.org/include/linux/netfilter_helpers.h   1970-01-01 01:00:00.000000000 +0100
121 +++ linux-2.6.6/include/linux/netfilter_helpers.h       2004-05-18 14:28:50.000000000 +0200
122 @@ -0,0 +1,133 @@
123 +/*
124 + * Helpers for netfiler modules.  This file provides implementations for basic
125 + * functions such as strncasecmp(), etc.
126 + *
127 + * gcc will warn for defined but unused functions, so we only include the
128 + * functions requested.  The following macros are used:
129 + *   NF_NEED_STRNCASECMP        nf_strncasecmp()
130 + *   NF_NEED_STRTOU16           nf_strtou16()
131 + *   NF_NEED_STRTOU32           nf_strtou32()
132 + */
133 +#ifndef _NETFILTER_HELPERS_H
134 +#define _NETFILTER_HELPERS_H
135 +
136 +/* Only include these functions for kernel code. */
137 +#ifdef __KERNEL__
138 +
139 +#include <linux/ctype.h>
140 +#define iseol(c) ( (c) == '\r' || (c) == '\n' )
141 +
142 +/*
143 + * The standard strncasecmp()
144 + */
145 +#ifdef NF_NEED_STRNCASECMP
146 +static int
147 +nf_strncasecmp(const char* s1, const char* s2, u_int32_t len)
148 +{
149 +    if (s1 == NULL || s2 == NULL)
150 +    {
151 +        if (s1 == NULL && s2 == NULL)
152 +        {
153 +            return 0;
154 +        }
155 +        return (s1 == NULL) ? -1 : 1;
156 +    }
157 +    while (len > 0 && tolower(*s1) == tolower(*s2))
158 +    {
159 +        len--;
160 +        s1++;
161 +        s2++;
162 +    }
163 +    return ( (len == 0) ? 0 : (tolower(*s1) - tolower(*s2)) );
164 +}
165 +#endif /* NF_NEED_STRNCASECMP */
166 +
167 +/*
168 + * Parse a string containing a 16-bit unsigned integer.
169 + * Returns the number of chars used, or zero if no number is found.
170 + */
171 +#ifdef NF_NEED_STRTOU16
172 +static int
173 +nf_strtou16(const char* pbuf, u_int16_t* pval)
174 +{
175 +    int n = 0;
176 +
177 +    *pval = 0;
178 +    while (isdigit(pbuf[n]))
179 +    {
180 +        *pval = (*pval * 10) + (pbuf[n] - '0');
181 +        n++;
182 +    }
183 +
184 +    return n;
185 +}
186 +#endif /* NF_NEED_STRTOU16 */
187 +
188 +/*
189 + * Parse a string containing a 32-bit unsigned integer.
190 + * Returns the number of chars used, or zero if no number is found.
191 + */
192 +#ifdef NF_NEED_STRTOU32
193 +static int
194 +nf_strtou32(const char* pbuf, u_int32_t* pval)
195 +{
196 +    int n = 0;
197 +
198 +    *pval = 0;
199 +    while (pbuf[n] >= '0' && pbuf[n] <= '9')
200 +    {
201 +        *pval = (*pval * 10) + (pbuf[n] - '0');
202 +        n++;
203 +    }
204 +
205 +    return n;
206 +}
207 +#endif /* NF_NEED_STRTOU32 */
208 +
209 +/*
210 + * Given a buffer and length, advance to the next line and mark the current
211 + * line.
212 + */
213 +#ifdef NF_NEED_NEXTLINE
214 +static int
215 +nf_nextline(char* p, uint len, uint* poff, uint* plineoff, uint* plinelen)
216 +{
217 +    uint    off = *poff;
218 +    uint    physlen = 0;
219 +
220 +    if (off >= len)
221 +    {
222 +        return 0;
223 +    }
224 +
225 +    while (p[off] != '\n')
226 +    {
227 +        if (len-off <= 1)
228 +        {
229 +            return 0;
230 +        }
231 +
232 +        physlen++;
233 +        off++;
234 +    }
235 +
236 +    /* if we saw a crlf, physlen needs adjusted */
237 +    if (physlen > 0 && p[off] == '\n' && p[off-1] == '\r')
238 +    {
239 +        physlen--;
240 +    }
241 +
242 +    /* advance past the newline */
243 +    off++;
244 +
245 +    *plineoff = *poff;
246 +    *plinelen = physlen;
247 +    *poff = off;
248 +
249 +    return 1;
250 +}
251 +#endif /* NF_NEED_NEXTLINE */
252 +
253 +#endif /* __KERNEL__ */
254 +
255 +#endif /* _NETFILTER_HELPERS_H */
256 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ip_conntrack.h linux-2.6.6/include/linux/netfilter_ipv4/ip_conntrack.h
257 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ip_conntrack.h 2004-05-10 04:33:20.000000000 +0200
258 +++ linux-2.6.6/include/linux/netfilter_ipv4/ip_conntrack.h     2004-05-18 14:28:50.000000000 +0200
259 @@ -51,10 +51,12 @@
260  
261  #include <linux/netfilter_ipv4/ip_conntrack_tcp.h>
262  #include <linux/netfilter_ipv4/ip_conntrack_icmp.h>
263 +#include <linux/netfilter_ipv4/ip_conntrack_sctp.h>
264  
265  /* per conntrack: protocol private data */
266  union ip_conntrack_proto {
267         /* insert conntrack proto private data here */
268 +       struct ip_ct_sctp sctp;
269         struct ip_ct_tcp tcp;
270         struct ip_ct_icmp icmp;
271  };
272 @@ -64,6 +66,11 @@
273  };
274  
275  /* Add protocol helper include file here */
276 +#include <linux/netfilter_ipv4/ip_conntrack_talk.h>
277 +#include <linux/netfilter_ipv4/ip_conntrack_rtsp.h>
278 +#include <linux/netfilter_ipv4/ip_conntrack_rsh.h>
279 +#include <linux/netfilter_ipv4/ip_conntrack_mms.h>
280 +#include <linux/netfilter_ipv4/ip_conntrack_h323.h>
281  #include <linux/netfilter_ipv4/ip_conntrack_amanda.h>
282  #include <linux/netfilter_ipv4/ip_conntrack_ftp.h>
283  #include <linux/netfilter_ipv4/ip_conntrack_irc.h>
284 @@ -71,6 +78,11 @@
285  /* per expectation: application helper private data */
286  union ip_conntrack_expect_help {
287         /* insert conntrack helper private data (expect) here */
288 +       struct ip_ct_talk_expect exp_talk_info;
289 +       struct ip_ct_rtsp_expect exp_rtsp_info;
290 +       struct ip_ct_rsh_expect exp_rsh_info;
291 +       struct ip_ct_mms_expect exp_mms_info;
292 +       struct ip_ct_h225_expect exp_h225_info;
293         struct ip_ct_amanda_expect exp_amanda_info;
294         struct ip_ct_ftp_expect exp_ftp_info;
295         struct ip_ct_irc_expect exp_irc_info;
296 @@ -85,6 +97,11 @@
297  /* per conntrack: application helper private data */
298  union ip_conntrack_help {
299         /* insert conntrack helper private data (master) here */
300 +       struct ip_ct_talk_master ct_talk_info;
301 +       struct ip_ct_rtsp_master ct_rtsp_info;
302 +       struct ip_ct_rsh_master ct_rsh_info;
303 +       struct ip_ct_mms_master ct_mms_info;
304 +       struct ip_ct_h225_master ct_h225_info;
305         struct ip_ct_ftp_master ct_ftp_info;
306         struct ip_ct_irc_master ct_irc_info;
307  };
308 @@ -207,6 +224,10 @@
309         } nat;
310  #endif /* CONFIG_IP_NF_NAT_NEEDED */
311  
312 +#if defined(CONFIG_IP_NF_CONNTRACK_MARK)
313 +       unsigned long mark;
314 +#endif
315 +
316  };
317  
318  /* get master conntrack via master expectation */
319 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ip_conntrack_h323.h linux-2.6.6/include/linux/netfilter_ipv4/ip_conntrack_h323.h
320 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ip_conntrack_h323.h    1970-01-01 01:00:00.000000000 +0100
321 +++ linux-2.6.6/include/linux/netfilter_ipv4/ip_conntrack_h323.h        2004-05-18 14:28:50.000000000 +0200
322 @@ -0,0 +1,31 @@
323 +#ifndef _IP_CONNTRACK_H323_H
324 +#define _IP_CONNTRACK_H323_H
325 +/* H.323 connection tracking. */
326 +
327 +#ifdef __KERNEL__
328 +/* Protects H.323 related data */
329 +#include <linux/netfilter_ipv4/lockhelp.h>
330 +DECLARE_LOCK_EXTERN(ip_h323_lock);
331 +#endif
332 +
333 +/* Default H.225 port */
334 +#define H225_PORT      1720
335 +
336 +/* This structure is per expected connection */
337 +struct ip_ct_h225_expect {
338 +       u_int16_t port;                 /* Port of the H.225 helper/RTCP/RTP channel */
339 +       enum ip_conntrack_dir dir;      /* Direction of the original connection */
340 +       unsigned int offset;            /* offset of the address in the payload */
341 +};
342 +
343 +/* This structure exists only once per master */
344 +struct ip_ct_h225_master {
345 +       int is_h225;                            /* H.225 or H.245 connection */
346 +#ifdef CONFIG_IP_NF_NAT_NEEDED
347 +       enum ip_conntrack_dir dir;              /* Direction of the original connection */
348 +       u_int32_t seq[IP_CT_DIR_MAX];           /* Exceptional packet mangling for signal addressess... */
349 +       unsigned int offset[IP_CT_DIR_MAX];     /* ...and the offset of the addresses in the payload */
350 +#endif
351 +};
352 +
353 +#endif /* _IP_CONNTRACK_H323_H */
354 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ip_conntrack_mms.h linux-2.6.6/include/linux/netfilter_ipv4/ip_conntrack_mms.h
355 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ip_conntrack_mms.h     1970-01-01 01:00:00.000000000 +0100
356 +++ linux-2.6.6/include/linux/netfilter_ipv4/ip_conntrack_mms.h 2004-05-18 14:28:50.000000000 +0200
357 @@ -0,0 +1,31 @@
358 +#ifndef _IP_CONNTRACK_MMS_H
359 +#define _IP_CONNTRACK_MMS_H
360 +/* MMS tracking. */
361 +
362 +#ifdef __KERNEL__
363 +#include <linux/netfilter_ipv4/lockhelp.h>
364 +
365 +DECLARE_LOCK_EXTERN(ip_mms_lock);
366 +
367 +#define MMS_PORT                         1755
368 +#define MMS_SRV_MSG_ID                   196610
369 +
370 +#define MMS_SRV_MSG_OFFSET               36
371 +#define MMS_SRV_UNICODE_STRING_OFFSET    60
372 +#define MMS_SRV_CHUNKLENLV_OFFSET        16
373 +#define MMS_SRV_CHUNKLENLM_OFFSET        32
374 +#define MMS_SRV_MESSAGELENGTH_OFFSET     8
375 +#endif
376 +
377 +/* This structure is per expected connection */
378 +struct ip_ct_mms_expect {
379 +       u_int32_t len;
380 +       u_int32_t padding;
381 +       u_int16_t port;
382 +};
383 +
384 +/* This structure exists only once per master */
385 +struct ip_ct_mms_master {
386 +};
387 +
388 +#endif /* _IP_CONNTRACK_MMS_H */
389 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ip_conntrack_quake3.h linux-2.6.6/include/linux/netfilter_ipv4/ip_conntrack_quake3.h
390 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ip_conntrack_quake3.h  1970-01-01 01:00:00.000000000 +0100
391 +++ linux-2.6.6/include/linux/netfilter_ipv4/ip_conntrack_quake3.h      2004-05-18 14:28:50.000000000 +0200
392 @@ -0,0 +1,21 @@
393 +#ifndef _IP_CT_QUAKE3
394 +#define _IP_CT_QUAKE3
395 +
396 +/* Don't confuse with 27960, often used as the Server Port */
397 +#define QUAKE3_MASTER_PORT 27950
398 +
399 +struct quake3_search {
400 +       const char marker[4]; /* always 0xff 0xff 0xff 0xff ? */
401 +       const char *pattern;
402 +       size_t plen;
403 +}; 
404 +
405 +/* This structure is per expected connection */
406 +struct ip_ct_quake3_expect {
407 +};
408 +
409 +/* This structure exists only once per master */
410 +struct ip_ct_quake3_master {
411 +};
412 +
413 +#endif /* _IP_CT_QUAKE3 */
414 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ip_conntrack_rsh.h linux-2.6.6/include/linux/netfilter_ipv4/ip_conntrack_rsh.h
415 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ip_conntrack_rsh.h     1970-01-01 01:00:00.000000000 +0100
416 +++ linux-2.6.6/include/linux/netfilter_ipv4/ip_conntrack_rsh.h 2004-05-18 14:28:50.000000000 +0200
417 @@ -0,0 +1,35 @@
418 +/* RSH extension for IP connection tracking, Version 1.0
419 + * (C) 2002 by Ian (Larry) Latter <Ian.Latter@mq.edu.au>
420 + * based on HW's ip_conntrack_irc.c     
421 + *
422 + * ip_conntrack_rsh.c,v 1.0 2002/07/17 14:49:26
423 + *
424 + *      This program is free software; you can redistribute it and/or
425 + *      modify it under the terms of the GNU General Public License
426 + *      as published by the Free Software Foundation; either version
427 + *      2 of the License, or (at your option) any later version.
428 + */
429 +#ifndef _IP_CONNTRACK_RSH_H
430 +#define _IP_CONNTRACK_RSH_H
431 +
432 +#ifdef __KERNEL__
433 +#include <linux/netfilter_ipv4/lockhelp.h>
434 +
435 +DECLARE_LOCK_EXTERN(ip_rsh_lock);
436 +#endif
437 +
438 +
439 +#define RSH_PORT       514
440 +
441 +/* This structure is per expected connection */
442 +struct ip_ct_rsh_expect
443 +{
444 +       u_int16_t port;
445 +};
446 +
447 +/* This structure exists only once per master */
448 +struct ip_ct_rsh_master {
449 +};
450 +
451 +#endif /* _IP_CONNTRACK_RSH_H */
452 +
453 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ip_conntrack_rtsp.h linux-2.6.6/include/linux/netfilter_ipv4/ip_conntrack_rtsp.h
454 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ip_conntrack_rtsp.h    1970-01-01 01:00:00.000000000 +0100
455 +++ linux-2.6.6/include/linux/netfilter_ipv4/ip_conntrack_rtsp.h        2004-05-18 14:28:50.000000000 +0200
456 @@ -0,0 +1,68 @@
457 +/*
458 + * RTSP extension for IP connection tracking.
459 + * (C) 2003 by Tom Marshall <tmarshall@real.com>
460 + * based on ip_conntrack_irc.h
461 + *
462 + *      This program is free software; you can redistribute it and/or
463 + *      modify it under the terms of the GNU General Public License
464 + *      as published by the Free Software Foundation; either version
465 + *      2 of the License, or (at your option) any later version.
466 + */
467 +#ifndef _IP_CONNTRACK_RTSP_H
468 +#define _IP_CONNTRACK_RTSP_H
469 +
470 +/* #define IP_NF_RTSP_DEBUG */
471 +#define IP_NF_RTSP_VERSION "0.01"
472 +
473 +/* port block types */
474 +typedef enum {
475 +    pb_single,  /* client_port=x */
476 +    pb_range,   /* client_port=x-y */
477 +    pb_discon   /* client_port=x/y (rtspbis) */
478 +} portblock_t;
479 +
480 +/* We record seq number and length of rtsp headers here, all in host order. */
481 +
482 +/*
483 + * This structure is per expected connection.  It is a member of struct
484 + * ip_conntrack_expect.  The TCP SEQ for the conntrack expect is stored
485 + * there and we are expected to only store the length of the data which
486 + * needs replaced.  If a packet contains multiple RTSP messages, we create
487 + * one expected connection per message.
488 + *
489 + * We use these variables to mark the entire header block.  This may seem
490 + * like overkill, but the nature of RTSP requires it.  A header may appear
491 + * multiple times in a message.  We must treat two Transport headers the
492 + * same as one Transport header with two entries.
493 + */
494 +struct ip_ct_rtsp_expect
495 +{
496 +    u_int32_t   len;        /* length of header block */
497 +    portblock_t pbtype;     /* Type of port block that was requested */
498 +    u_int16_t   loport;     /* Port that was requested, low or first */
499 +    u_int16_t   hiport;     /* Port that was requested, high or second */
500 +#if 0
501 +    uint        method;     /* RTSP method */
502 +    uint        cseq;       /* CSeq from request */
503 +#endif
504 +};
505 +
506 +/* This structure exists only once per master */
507 +struct ip_ct_rtsp_master
508 +{
509 +    /* Empty (?) */
510 +};
511 +
512 +
513 +#ifdef __KERNEL__
514 +
515 +#include <linux/netfilter_ipv4/lockhelp.h>
516 +
517 +#define RTSP_PORT   554
518 +
519 +/* Protects rtsp part of conntracks */
520 +DECLARE_LOCK_EXTERN(ip_rtsp_lock);
521 +
522 +#endif /* __KERNEL__ */
523 +
524 +#endif /* _IP_CONNTRACK_RTSP_H */
525 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ip_conntrack_sctp.h linux-2.6.6/include/linux/netfilter_ipv4/ip_conntrack_sctp.h
526 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ip_conntrack_sctp.h    1970-01-01 01:00:00.000000000 +0100
527 +++ linux-2.6.6/include/linux/netfilter_ipv4/ip_conntrack_sctp.h        2004-05-18 14:28:50.000000000 +0200
528 @@ -0,0 +1,25 @@
529 +#ifndef _IP_CONNTRACK_SCTP_H
530 +#define _IP_CONNTRACK_SCTP_H
531 +/* SCTP tracking. */
532 +
533 +enum sctp_conntrack {
534 +       SCTP_CONNTRACK_NONE,
535 +       SCTP_CONNTRACK_CLOSED,
536 +       SCTP_CONNTRACK_COOKIE_WAIT,
537 +       SCTP_CONNTRACK_COOKIE_ECHOED,
538 +       SCTP_CONNTRACK_ESTABLISHED,
539 +       SCTP_CONNTRACK_SHUTDOWN_SENT,
540 +       SCTP_CONNTRACK_SHUTDOWN_RECD,
541 +       SCTP_CONNTRACK_SHUTDOWN_ACK_SENT,
542 +       SCTP_CONNTRACK_MAX
543 +};
544 +
545 +struct ip_ct_sctp
546 +{
547 +       enum sctp_conntrack state;
548 +
549 +       u_int32_t vtag[IP_CT_DIR_MAX];
550 +       u_int32_t ttag[IP_CT_DIR_MAX];
551 +};
552 +
553 +#endif /* _IP_CONNTRACK_SCTP_H */
554 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ip_conntrack_talk.h linux-2.6.6/include/linux/netfilter_ipv4/ip_conntrack_talk.h
555 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ip_conntrack_talk.h    1970-01-01 01:00:00.000000000 +0100
556 +++ linux-2.6.6/include/linux/netfilter_ipv4/ip_conntrack_talk.h        2004-05-18 14:28:50.000000000 +0200
557 @@ -0,0 +1,152 @@
558 +#ifndef _IP_CONNTRACK_TALK_H
559 +#define _IP_CONNTRACK_TALK_H
560 +/* TALK tracking. */
561 +
562 +#ifdef __KERNEL__
563 +#include <linux/in.h>
564 +#include <linux/netfilter_ipv4/lockhelp.h>
565 +
566 +/* Protects talk part of conntracks */
567 +DECLARE_LOCK_EXTERN(ip_talk_lock);
568 +#endif
569 +
570 +
571 +#define TALK_PORT      517
572 +#define NTALK_PORT     518
573 +
574 +/* talk structures and constants from <protocols/talkd.h> */
575 +
576 +/*
577 + * 4.3BSD struct sockaddr
578 + */
579 +struct talk_addr {
580 +       u_int16_t ta_family;
581 +       u_int16_t ta_port;
582 +       u_int32_t ta_addr;
583 +       u_int32_t ta_junk1;
584 +       u_int32_t ta_junk2;
585 +};
586 +
587 +#define        TALK_OLD_NSIZE  9
588 +#define        TALK_NSIZE      12
589 +#define        TALK_TTY_NSIZE  16
590 +
591 +/*
592 + * Client->server request message formats.
593 + */
594 +struct talk_msg {
595 +       u_char  type;           /* request type, see below */
596 +       char    l_name[TALK_OLD_NSIZE];/* caller's name */
597 +       char    r_name[TALK_OLD_NSIZE];/* callee's name */
598 +       u_char  pad;
599 +       u_int32_t id_num;       /* message id */
600 +       int32_t pid;            /* caller's process id */
601 +       char    r_tty[TALK_TTY_NSIZE];/* callee's tty name */
602 +       struct  talk_addr addr;         /* old (4.3) style */
603 +       struct  talk_addr ctl_addr;     /* old (4.3) style */
604 +};
605 +
606 +struct ntalk_msg {
607 +       u_char  vers;           /* protocol version */
608 +       u_char  type;           /* request type, see below */
609 +       u_char  answer;         /* not used */
610 +       u_char  pad;
611 +       u_int32_t id_num;       /* message id */
612 +       struct  talk_addr addr;         /* old (4.3) style */
613 +       struct  talk_addr ctl_addr;     /* old (4.3) style */
614 +       int32_t pid;            /* caller's process id */
615 +       char    l_name[TALK_NSIZE];/* caller's name */
616 +       char    r_name[TALK_NSIZE];/* callee's name */
617 +       char    r_tty[TALK_TTY_NSIZE];/* callee's tty name */
618 +};
619 +
620 +struct ntalk2_msg {
621 +       u_char  vers;           /* talk protocol version    */
622 +       u_char  type;           /* request type             */
623 +       u_char  answer;         /*  */
624 +       u_char  extended;       /* !0 if additional parts   */
625 +       u_int32_t id_num;       /* message id number (dels) */
626 +       struct  talk_addr addr;         /* target address   */
627 +       struct  talk_addr ctl_addr;     /* reply to address */
628 +       int32_t pid;            /* caller's process id */
629 +       char    l_name[TALK_NSIZE];  /* caller's name */
630 +       char    r_name[TALK_NSIZE];  /* callee's name */
631 +       char    r_tty[TALK_TTY_NSIZE];    /* callee's tty */
632 +};
633 +
634 +/*
635 + * Server->client response message formats.
636 + */
637 +struct talk_response {
638 +       u_char  type;           /* type of request message, see below */
639 +       u_char  answer;         /* response to request message, see below */
640 +       u_char  pad[2];
641 +       u_int32_t id_num;       /* message id */
642 +       struct  talk_addr addr; /* address for establishing conversation */
643 +};
644 +
645 +struct ntalk_response {
646 +       u_char  vers;           /* protocol version */
647 +       u_char  type;           /* type of request message, see below */
648 +       u_char  answer;         /* response to request message, see below */
649 +       u_char  pad;
650 +       u_int32_t id_num;       /* message id */
651 +       struct  talk_addr addr; /* address for establishing conversation */
652 +};
653 +
654 +struct ntalk2_response {
655 +       u_char  vers;           /* protocol version         */
656 +       u_char  type;           /* type of request message  */
657 +       u_char  answer;         /* response to request      */
658 +       u_char  rvers;          /* Version of answering vers*/
659 +       u_int32_t id_num;       /* message id number        */
660 +       struct  talk_addr addr; /* address for connection   */
661 +       /* This is at the end to compatiblize this with NTALK version.   */
662 +       char    r_name[TALK_NSIZE]; /* callee's name            */
663 +};
664 +
665 +#define TALK_STR(data, talk_str, member) ((struct talk_str *)data)->member)
666 +#define TALK_RESP(data, ver, member) (ver ? ((struct ntalk_response *)data)->member : ((struct talk_response *)data)->member)
667 +#define TALK_MSG(data, ver, member) (ver ? ((struct ntalk_msg *)data)->member : ((struct talk_msg *)data)->member)
668 +
669 +#define        TALK_VERSION    0               /* protocol versions */
670 +#define        NTALK_VERSION   1
671 +#define        NTALK2_VERSION  2
672 +
673 +/* message type values */
674 +#define LEAVE_INVITE   0       /* leave invitation with server */
675 +#define LOOK_UP                1       /* check for invitation by callee */
676 +#define DELETE         2       /* delete invitation by caller */
677 +#define ANNOUNCE       3       /* announce invitation by caller */
678 +/* NTALK2 */
679 +#define REPLY_QUERY    4       /* request reply data from local daemon */
680 +
681 +/* answer values */
682 +#define SUCCESS                0       /* operation completed properly */
683 +#define NOT_HERE       1       /* callee not logged in */
684 +#define FAILED         2       /* operation failed for unexplained reason */
685 +#define MACHINE_UNKNOWN        3       /* caller's machine name unknown */
686 +#define PERMISSION_DENIED 4    /* callee's tty doesn't permit announce */
687 +#define UNKNOWN_REQUEST        5       /* request has invalid type value */
688 +#define        BADVERSION      6       /* request has invalid protocol version */
689 +#define        BADADDR         7       /* request has invalid addr value */
690 +#define        BADCTLADDR      8       /* request has invalid ctl_addr value */
691 +/* NTALK2 */
692 +#define NO_CALLER      9       /* no-one calling answer from REPLY   */
693 +#define TRY_HERE       10      /* Not on this machine, try this      */
694 +#define SELECTIVE_REFUSAL 11   /* User Filter refusal.               */
695 +#define MAX_RESPONSE_TYPE 11   /* Make sure this is updated          */
696 +
697 +/* We don't really need much for talk */
698 +struct ip_ct_talk_expect
699 +{
700 +       /* Port that was to be used */
701 +       u_int16_t port;
702 +};
703 +
704 +/* This structure exists only once per master */
705 +struct ip_ct_talk_master
706 +{
707 +};
708 +
709 +#endif /* _IP_CONNTRACK_TALK_H */
710 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ip_conntrack_tuple.h linux-2.6.6/include/linux/netfilter_ipv4/ip_conntrack_tuple.h
711 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ip_conntrack_tuple.h   2004-05-10 04:32:54.000000000 +0200
712 +++ linux-2.6.6/include/linux/netfilter_ipv4/ip_conntrack_tuple.h       2004-05-18 14:28:50.000000000 +0200
713 @@ -25,6 +25,9 @@
714         struct {
715                 u_int16_t id;
716         } icmp;
717 +       struct {
718 +               u_int16_t port;
719 +       } sctp;
720  };
721  
722  /* The manipulable part of the tuple. */
723 @@ -55,6 +58,9 @@
724                         struct {
725                                 u_int8_t type, code;
726                         } icmp;
727 +                       struct {
728 +                               u_int16_t port;
729 +                       } sctp;
730                 } u;
731  
732                 /* The protocol. */
733 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ip_pool.h linux-2.6.6/include/linux/netfilter_ipv4/ip_pool.h
734 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ip_pool.h      1970-01-01 01:00:00.000000000 +0100
735 +++ linux-2.6.6/include/linux/netfilter_ipv4/ip_pool.h  2004-05-18 14:28:50.000000000 +0200
736 @@ -0,0 +1,64 @@
737 +#ifndef _IP_POOL_H
738 +#define _IP_POOL_H
739 +
740 +/***************************************************************************/
741 +/*  This program is free software; you can redistribute it and/or modify   */
742 +/*  it under the terms of the GNU General Public License as published by   */
743 +/*  the Free Software Foundation; either version 2 of the License, or     */
744 +/*  (at your option) any later version.                                           */
745 +/*                                                                        */
746 +/*  This program is distributed in the hope that it will be useful,       */
747 +/*  but WITHOUT ANY WARRANTY; without even the implied warranty of        */
748 +/*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         */
749 +/*  GNU General Public License for more details.                          */
750 +/*                                                                        */
751 +/*  You should have received a copy of the GNU General Public License     */
752 +/*  along with this program; if not, write to the Free Software                   */
753 +/*  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*/
754 +/***************************************************************************/
755 +
756 +/* A sockopt of such quality has hardly ever been seen before on the open
757 + * market!  This little beauty, hardly ever used: above 64, so it's
758 + * traditionally used for firewalling, not touched (even once!) by the
759 + * 2.0, 2.2 and 2.4 kernels!
760 + *
761 + * Comes with its own certificate of authenticity, valid anywhere in the
762 + * Free world!
763 + *
764 + * Rusty, 19.4.2000
765 + */
766 +#define SO_IP_POOL 81
767 +
768 +typedef int ip_pool_t;                 /* pool index */
769 +#define IP_POOL_NONE   ((ip_pool_t)-1)
770 +
771 +struct ip_pool_request {
772 +       int op;
773 +       ip_pool_t index;
774 +       u_int32_t addr;
775 +       u_int32_t addr2;
776 +};
777 +
778 +/* NOTE: I deliberately break the first cut ippool utility. Nobody uses it. */
779 +
780 +#define IP_POOL_BAD001         0x00000010
781 +
782 +#define IP_POOL_FLUSH          0x00000011      /* req.index, no arguments */
783 +#define IP_POOL_INIT           0x00000012      /* from addr to addr2 incl. */
784 +#define IP_POOL_DESTROY                0x00000013      /* req.index, no arguments */
785 +#define IP_POOL_ADD_ADDR       0x00000014      /* add addr to pool */
786 +#define IP_POOL_DEL_ADDR       0x00000015      /* del addr from pool */
787 +#define IP_POOL_HIGH_NR                0x00000016      /* result in req.index */
788 +#define IP_POOL_LOOKUP         0x00000017      /* result in addr and addr2 */
789 +#define IP_POOL_USAGE          0x00000018      /* result in addr */
790 +#define IP_POOL_TEST_ADDR      0x00000019      /* result (0/1) returned */
791 +
792 +#ifdef __KERNEL__
793 +
794 +/* NOTE: ip_pool_match() and ip_pool_mod() expect ADDR to be host byte order */
795 +extern int ip_pool_match(ip_pool_t pool, u_int32_t addr);
796 +extern int ip_pool_mod(ip_pool_t pool, u_int32_t addr, int isdel);
797 +
798 +#endif
799 +
800 +#endif /*_IP_POOL_H*/
801 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ip_tables.h linux-2.6.6/include/linux/netfilter_ipv4/ip_tables.h
802 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ip_tables.h    2004-05-10 04:32:37.000000000 +0200
803 +++ linux-2.6.6/include/linux/netfilter_ipv4/ip_tables.h        2004-05-18 14:28:50.000000000 +0200
804 @@ -104,7 +104,8 @@
805  
806  /* Values for "flag" field in struct ipt_ip (general ip structure). */
807  #define IPT_F_FRAG             0x01    /* Set if rule is a fragment rule */
808 -#define IPT_F_MASK             0x01    /* All possible flag bits mask. */
809 +#define IPT_F_GOTO             0x02    /* Set if jump is a goto */
810 +#define IPT_F_MASK             0x03    /* All possible flag bits mask. */
811  
812  /* Values for "inv" field in struct ipt_ip. */
813  #define IPT_INV_VIA_IN         0x01    /* Invert the sense of IN IFACE. */
814 @@ -134,6 +135,12 @@
815         /* Back pointer */
816         unsigned int comefrom;
817  
818 +       /* Name of the chain */
819 +       char *chainname;
820 +       
821 +       /* Rule number in the chain. */
822 +       u_int32_t rulenum;
823 +
824         /* Packet and byte counters. */
825         struct ipt_counters counters;
826  
827 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_CONNMARK.h linux-2.6.6/include/linux/netfilter_ipv4/ipt_CONNMARK.h
828 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_CONNMARK.h 1970-01-01 01:00:00.000000000 +0100
829 +++ linux-2.6.6/include/linux/netfilter_ipv4/ipt_CONNMARK.h     2004-05-18 14:28:50.000000000 +0200
830 @@ -0,0 +1,25 @@
831 +#ifndef _IPT_CONNMARK_H_target
832 +#define _IPT_CONNMARK_H_target
833 +
834 +/* Copyright (C) 2002,2004 MARA Systems AB <http://www.marasystems.com>
835 + * by Henrik Nordstrom <hno@marasystems.com>
836 + *
837 + * This program is free software; you can redistribute it and/or modify
838 + * it under the terms of the GNU General Public License as published by
839 + * the Free Software Foundation; either version 2 of the License, or
840 + * (at your option) any later version.
841 + */
842 +
843 +enum {
844 +       IPT_CONNMARK_SET = 0,
845 +       IPT_CONNMARK_SAVE,
846 +       IPT_CONNMARK_RESTORE
847 +};
848 +
849 +struct ipt_connmark_target_info {
850 +       unsigned long mark;
851 +       unsigned long mask;
852 +       u_int8_t mode;
853 +};
854 +
855 +#endif /*_IPT_CONNMARK_H_target*/
856 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_IPMARK.h linux-2.6.6/include/linux/netfilter_ipv4/ipt_IPMARK.h
857 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_IPMARK.h   1970-01-01 01:00:00.000000000 +0100
858 +++ linux-2.6.6/include/linux/netfilter_ipv4/ipt_IPMARK.h       2004-05-18 14:28:50.000000000 +0200
859 @@ -0,0 +1,13 @@
860 +#ifndef _IPT_IPMARK_H_target
861 +#define _IPT_IPMARK_H_target
862 +
863 +struct ipt_ipmark_target_info {
864 +       unsigned long andmask;
865 +       unsigned long ormask;
866 +       unsigned int addr;
867 +};
868 +
869 +#define IPT_IPMARK_SRC    0
870 +#define IPT_IPMARK_DST    1
871 +
872 +#endif /*_IPT_IPMARK_H_target*/
873 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_MARK.h linux-2.6.6/include/linux/netfilter_ipv4/ipt_MARK.h
874 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_MARK.h     2004-05-10 04:32:26.000000000 +0200
875 +++ linux-2.6.6/include/linux/netfilter_ipv4/ipt_MARK.h 2004-05-18 14:28:50.000000000 +0200
876 @@ -1,8 +1,15 @@
877  #ifndef _IPT_MARK_H_target
878  #define _IPT_MARK_H_target
879  
880 +enum {
881 +        IPT_MARK_SET,
882 +        IPT_MARK_AND,
883 +        IPT_MARK_OR
884 +};
885 +
886  struct ipt_mark_target_info {
887         unsigned long mark;
888 +       u_int8_t mode;
889  };
890  
891  #endif /*_IPT_MARK_H_target*/
892 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_NETLINK.h linux-2.6.6/include/linux/netfilter_ipv4/ipt_NETLINK.h
893 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_NETLINK.h  1970-01-01 01:00:00.000000000 +0100
894 +++ linux-2.6.6/include/linux/netfilter_ipv4/ipt_NETLINK.h      2004-05-18 14:28:50.000000000 +0200
895 @@ -0,0 +1,27 @@
896 +#ifndef _IPT_FWMON_H
897 +#define _IPT_FWMON_H
898 +
899 +/* Bitmask macros */
900 +#define MASK(x,y) (x & y)
901 +#define MASK_SET(x,y) x |= y
902 +#define MASK_UNSET(x,y) x &= ~y
903 +
904 +#define USE_MARK       0x00000001
905 +#define USE_DROP       0x00000002
906 +#define USE_SIZE       0x00000004
907 +
908 +struct ipt_nldata
909 +{      
910 +       unsigned int flags;
911 +       unsigned int mark;
912 +       unsigned int size;
913 +};
914 +
915 +/* Old header */
916 +struct netlink_t {
917 +       unsigned int len;
918 +       unsigned int mark;
919 +       char iface[IFNAMSIZ];
920 +};
921 +
922 +#endif /*_IPT_FWMON_H*/
923 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_ROUTE.h linux-2.6.6/include/linux/netfilter_ipv4/ipt_ROUTE.h
924 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_ROUTE.h    1970-01-01 01:00:00.000000000 +0100
925 +++ linux-2.6.6/include/linux/netfilter_ipv4/ipt_ROUTE.h        2004-05-18 14:28:50.000000000 +0200
926 @@ -0,0 +1,22 @@
927 +/* Header file for iptables ipt_ROUTE target
928 + *
929 + * (C) 2002 by Cédric de Launois <delaunois@info.ucl.ac.be>
930 + *
931 + * This software is distributed under GNU GPL v2, 1991
932 + */
933 +#ifndef _IPT_ROUTE_H_target
934 +#define _IPT_ROUTE_H_target
935 +
936 +#define IPT_ROUTE_IFNAMSIZ 16
937 +
938 +struct ipt_route_target_info {
939 +       char      oif[IPT_ROUTE_IFNAMSIZ];      /* Output Interface Name */
940 +       char      iif[IPT_ROUTE_IFNAMSIZ];      /* Input Interface Name  */
941 +       u_int32_t gw;                           /* IP address of gateway */
942 +       u_int8_t  flags;
943 +};
944 +
945 +/* Values for "flags" field */
946 +#define IPT_ROUTE_CONTINUE        0x01
947 +
948 +#endif /*_IPT_ROUTE_H_target*/
949 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_TCPLAG.h linux-2.6.6/include/linux/netfilter_ipv4/ipt_TCPLAG.h
950 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_TCPLAG.h   1970-01-01 01:00:00.000000000 +0100
951 +++ linux-2.6.6/include/linux/netfilter_ipv4/ipt_TCPLAG.h       2004-05-18 14:28:50.000000000 +0200
952 @@ -0,0 +1,10 @@
953 +#ifndef _IPT_TCPLAG_H
954 +#define _IPT_TCPLAG_H
955 +
956 +struct ipt_tcplag
957 +{
958 +       unsigned char level;
959 +       unsigned char prefix[ 15 ];
960 +};
961 +
962 +#endif
963 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_TTL.h linux-2.6.6/include/linux/netfilter_ipv4/ipt_TTL.h
964 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_TTL.h      1970-01-01 01:00:00.000000000 +0100
965 +++ linux-2.6.6/include/linux/netfilter_ipv4/ipt_TTL.h  2004-05-18 14:28:50.000000000 +0200
966 @@ -0,0 +1,21 @@
967 +/* TTL modification module for IP tables
968 + * (C) 2000 by Harald Welte <laforge@gnumonks.org> */
969 +
970 +#ifndef _IPT_TTL_H
971 +#define _IPT_TTL_H
972 +
973 +enum {
974 +       IPT_TTL_SET = 0,
975 +       IPT_TTL_INC,
976 +       IPT_TTL_DEC
977 +};
978 +
979 +#define IPT_TTL_MAXMODE        IPT_TTL_DEC
980 +
981 +struct ipt_TTL_info {
982 +       u_int8_t        mode;
983 +       u_int8_t        ttl;
984 +};
985 +
986 +
987 +#endif
988 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_XOR.h linux-2.6.6/include/linux/netfilter_ipv4/ipt_XOR.h
989 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_XOR.h      1970-01-01 01:00:00.000000000 +0100
990 +++ linux-2.6.6/include/linux/netfilter_ipv4/ipt_XOR.h  2004-05-18 14:28:50.000000000 +0200
991 @@ -0,0 +1,9 @@
992 +#ifndef _IPT_XOR_H
993 +#define _IPT_XOR_H
994 +
995 +struct ipt_XOR_info {
996 +       char            key[30];
997 +       u_int8_t        block_size;
998 +};
999 +
1000 +#endif /* _IPT_XOR_H */
1001 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_addrtype.h linux-2.6.6/include/linux/netfilter_ipv4/ipt_addrtype.h
1002 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_addrtype.h 1970-01-01 01:00:00.000000000 +0100
1003 +++ linux-2.6.6/include/linux/netfilter_ipv4/ipt_addrtype.h     2004-05-18 14:28:50.000000000 +0200
1004 @@ -0,0 +1,11 @@
1005 +#ifndef _IPT_ADDRTYPE_H
1006 +#define _IPT_ADDRTYPE_H
1007 +
1008 +struct ipt_addrtype_info {
1009 +       u_int16_t       source;         /* source-type mask */
1010 +       u_int16_t       dest;           /* dest-type mask */
1011 +       int             invert_source;
1012 +       int             invert_dest;
1013 +};
1014 +
1015 +#endif
1016 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_connlimit.h linux-2.6.6/include/linux/netfilter_ipv4/ipt_connlimit.h
1017 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_connlimit.h        1970-01-01 01:00:00.000000000 +0100
1018 +++ linux-2.6.6/include/linux/netfilter_ipv4/ipt_connlimit.h    2004-05-18 14:28:50.000000000 +0200
1019 @@ -0,0 +1,12 @@
1020 +#ifndef _IPT_CONNLIMIT_H
1021 +#define _IPT_CONNLIMIT_H
1022 +
1023 +struct ipt_connlimit_data;
1024 +
1025 +struct ipt_connlimit_info {
1026 +       int limit;
1027 +       int inverse;
1028 +       u_int32_t mask;
1029 +       struct ipt_connlimit_data *data;
1030 +};
1031 +#endif /* _IPT_CONNLIMIT_H */
1032 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_connmark.h linux-2.6.6/include/linux/netfilter_ipv4/ipt_connmark.h
1033 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_connmark.h 1970-01-01 01:00:00.000000000 +0100
1034 +++ linux-2.6.6/include/linux/netfilter_ipv4/ipt_connmark.h     2004-05-18 14:28:50.000000000 +0200
1035 @@ -0,0 +1,18 @@
1036 +#ifndef _IPT_CONNMARK_H
1037 +#define _IPT_CONNMARK_H
1038 +
1039 +/* Copyright (C) 2002,2004 MARA Systems AB <http://www.marasystems.com>
1040 + * by Henrik Nordstrom <hno@marasystems.com>
1041 + *
1042 + * This program is free software; you can redistribute it and/or modify
1043 + * it under the terms of the GNU General Public License as published by
1044 + * the Free Software Foundation; either version 2 of the License, or
1045 + * (at your option) any later version.
1046 + */
1047 +
1048 +struct ipt_connmark_info {
1049 +       unsigned long mark, mask;
1050 +       u_int8_t invert;
1051 +};
1052 +
1053 +#endif /*_IPT_CONNMARK_H*/
1054 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_dstlimit.h linux-2.6.6/include/linux/netfilter_ipv4/ipt_dstlimit.h
1055 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_dstlimit.h 1970-01-01 01:00:00.000000000 +0100
1056 +++ linux-2.6.6/include/linux/netfilter_ipv4/ipt_dstlimit.h     2004-05-18 14:28:50.000000000 +0200
1057 @@ -0,0 +1,39 @@
1058 +#ifndef _IPT_DSTLIMIT_H
1059 +#define _IPT_DSTLIMIT_H
1060 +
1061 +/* timings are in milliseconds. */
1062 +#define IPT_DSTLIMIT_SCALE 10000
1063 +/* 1/10,000 sec period => max of 10,000/sec.  Min rate is then 429490
1064 +   seconds, or one every 59 hours. */
1065 +
1066 +/* details of this structure hidden by the implementation */
1067 +struct ipt_dstlimit_htable;
1068 +
1069 +#define IPT_DSTLIMIT_HASH_DIP  0x0001
1070 +#define IPT_DSTLIMIT_HASH_DPT  0x0002
1071 +#define IPT_DSTLIMIT_HASH_SIP  0x0004
1072 +
1073 +struct dstlimit_cfg {
1074 +       u_int32_t mode;   /* bitmask of IPT_DSTLIMIT_HASH_* */
1075 +       u_int32_t avg;    /* Average secs between packets * scale */
1076 +       u_int32_t burst;  /* Period multiplier for upper limit. */
1077 +
1078 +       /* user specified */
1079 +       u_int32_t size;         /* how many buckets */
1080 +       u_int32_t max;          /* max number of entries */
1081 +       u_int32_t gc_interval;  /* gc interval */
1082 +       u_int32_t expire;       /* when do entries expire? */
1083 +};
1084 +
1085 +struct ipt_dstlimit_info {
1086 +       char name [IFNAMSIZ];           /* name */
1087 +       struct dstlimit_cfg cfg;
1088 +       struct ipt_dstlimit_htable *hinfo;
1089 +
1090 +       /* Used internally by the kernel */
1091 +       union {
1092 +               void *ptr;
1093 +               struct ipt_dstlimit_info *master;
1094 +       } u;
1095 +};
1096 +#endif /*_IPT_DSTLIMIT_H*/
1097 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_fuzzy.h linux-2.6.6/include/linux/netfilter_ipv4/ipt_fuzzy.h
1098 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_fuzzy.h    1970-01-01 01:00:00.000000000 +0100
1099 +++ linux-2.6.6/include/linux/netfilter_ipv4/ipt_fuzzy.h        2004-05-18 14:28:50.000000000 +0200
1100 @@ -0,0 +1,21 @@
1101 +#ifndef _IPT_FUZZY_H
1102 +#define _IPT_FUZZY_H
1103 +
1104 +#include <linux/param.h>
1105 +#include <linux/types.h>
1106 +
1107 +#define MAXFUZZYRATE 10000000
1108 +#define MINFUZZYRATE 3
1109 +
1110 +struct ipt_fuzzy_info {
1111 +       u_int32_t minimum_rate;
1112 +       u_int32_t maximum_rate;
1113 +       u_int32_t packets_total;
1114 +       u_int32_t bytes_total;
1115 +       u_int32_t previous_time;
1116 +       u_int32_t present_time;
1117 +       u_int32_t mean_rate;
1118 +       u_int8_t acceptance_rate;
1119 +};
1120 +
1121 +#endif /*_IPT_FUZZY_H*/
1122 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_ipv4options.h linux-2.6.6/include/linux/netfilter_ipv4/ipt_ipv4options.h
1123 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_ipv4options.h      1970-01-01 01:00:00.000000000 +0100
1124 +++ linux-2.6.6/include/linux/netfilter_ipv4/ipt_ipv4options.h  2004-05-18 14:28:50.000000000 +0200
1125 @@ -0,0 +1,21 @@
1126 +#ifndef __ipt_ipv4options_h_included__
1127 +#define __ipt_ipv4options_h_included__
1128 +
1129 +#define IPT_IPV4OPTION_MATCH_SSRR              0x01  /* For strict source routing */
1130 +#define IPT_IPV4OPTION_MATCH_LSRR              0x02  /* For loose source routing */
1131 +#define IPT_IPV4OPTION_DONT_MATCH_SRR          0x04  /* any source routing */
1132 +#define IPT_IPV4OPTION_MATCH_RR                        0x08  /* For Record route */
1133 +#define IPT_IPV4OPTION_DONT_MATCH_RR           0x10
1134 +#define IPT_IPV4OPTION_MATCH_TIMESTAMP         0x20  /* For timestamp request */
1135 +#define IPT_IPV4OPTION_DONT_MATCH_TIMESTAMP    0x40
1136 +#define IPT_IPV4OPTION_MATCH_ROUTER_ALERT      0x80  /* For router-alert */
1137 +#define IPT_IPV4OPTION_DONT_MATCH_ROUTER_ALERT 0x100
1138 +#define IPT_IPV4OPTION_MATCH_ANY_OPT           0x200 /* match packet with any option */
1139 +#define IPT_IPV4OPTION_DONT_MATCH_ANY_OPT      0x400 /* match packet with no option */
1140 +
1141 +struct ipt_ipv4options_info {
1142 +       u_int16_t options;
1143 +};
1144 +
1145 +
1146 +#endif /* __ipt_ipv4options_h_included__ */
1147 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_mport.h linux-2.6.6/include/linux/netfilter_ipv4/ipt_mport.h
1148 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_mport.h    1970-01-01 01:00:00.000000000 +0100
1149 +++ linux-2.6.6/include/linux/netfilter_ipv4/ipt_mport.h        2004-05-18 14:28:50.000000000 +0200
1150 @@ -0,0 +1,24 @@
1151 +#ifndef _IPT_MPORT_H
1152 +#define _IPT_MPORT_H
1153 +#include <linux/netfilter_ipv4/ip_tables.h>
1154 +
1155 +#define IPT_MPORT_SOURCE (1<<0)
1156 +#define IPT_MPORT_DESTINATION (1<<1)
1157 +#define IPT_MPORT_EITHER (IPT_MPORT_SOURCE|IPT_MPORT_DESTINATION)
1158 +
1159 +#define IPT_MULTI_PORTS        15
1160 +
1161 +/* Must fit inside union ipt_matchinfo: 32 bytes */
1162 +/* every entry in ports[] except for the last one has one bit in pflags
1163 + * associated with it. If this bit is set, the port is the first port of
1164 + * a portrange, with the next entry being the last.
1165 + * End of list is marked with pflags bit set and port=65535.
1166 + * If 14 ports are used (last one does not have a pflag), the last port
1167 + * is repeated to fill the last entry in ports[] */
1168 +struct ipt_mport
1169 +{
1170 +       u_int8_t flags:2;                       /* Type of comparison */
1171 +       u_int16_t pflags:14;                    /* Port flags */
1172 +       u_int16_t ports[IPT_MULTI_PORTS];       /* Ports */
1173 +};
1174 +#endif /*_IPT_MPORT_H*/
1175 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_nth.h linux-2.6.6/include/linux/netfilter_ipv4/ipt_nth.h
1176 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_nth.h      1970-01-01 01:00:00.000000000 +0100
1177 +++ linux-2.6.6/include/linux/netfilter_ipv4/ipt_nth.h  2004-05-18 14:28:50.000000000 +0200
1178 @@ -0,0 +1,19 @@
1179 +#ifndef _IPT_NTH_H
1180 +#define _IPT_NTH_H
1181 +
1182 +#include <linux/param.h>
1183 +#include <linux/types.h>
1184 +
1185 +#ifndef IPT_NTH_NUM_COUNTERS
1186 +#define IPT_NTH_NUM_COUNTERS 16
1187 +#endif
1188 +
1189 +struct ipt_nth_info {
1190 +       u_int8_t every;
1191 +       u_int8_t not;
1192 +       u_int8_t startat;
1193 +       u_int8_t counter;
1194 +       u_int8_t packet;
1195 +};
1196 +
1197 +#endif /*_IPT_NTH_H*/
1198 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_osf.h linux-2.6.6/include/linux/netfilter_ipv4/ipt_osf.h
1199 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_osf.h      1970-01-01 01:00:00.000000000 +0100
1200 +++ linux-2.6.6/include/linux/netfilter_ipv4/ipt_osf.h  2004-05-18 14:28:50.000000000 +0200
1201 @@ -0,0 +1,148 @@
1202 +/*
1203 + * ipt_osf.h
1204 + *
1205 + * Copyright (c) 2003 Evgeniy Polyakov <johnpol@2ka.mipt.ru>
1206 + *
1207 + *
1208 + * This program is free software; you can redistribute it and/or modify
1209 + * it under the terms of the GNU General Public License as published by
1210 + * the Free Software Foundation; either version 2 of the License, or
1211 + * (at your option) any later version.
1212 + *
1213 + * This program is distributed in the hope that it will be useful,
1214 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1215 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1216 + * GNU General Public License for more details.
1217 + *
1218 + * You should have received a copy of the GNU General Public License
1219 + * along with this program; if not, write to the Free Software
1220 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1221 + */
1222 +
1223 +#ifndef _IPT_OSF_H
1224 +#define _IPT_OSF_H
1225 +
1226 +#define MAXGENRELEN            32
1227 +#define MAXDETLEN              64
1228 +
1229 +#define IPT_OSF_GENRE          1
1230 +#define        IPT_OSF_SMART           2
1231 +#define IPT_OSF_LOG            4
1232 +#define IPT_OSF_NETLINK                8
1233 +
1234 +#define IPT_OSF_LOGLEVEL_ALL   0
1235 +#define IPT_OSF_LOGLEVEL_FIRST 1
1236 +
1237 +#include <linux/list.h>
1238 +
1239 +#ifndef __KERNEL__
1240 +#include <netinet/ip.h>
1241 +#include <netinet/tcp.h>
1242 +
1243 +struct list_head
1244 +{
1245 +       struct list_head *prev, *next;
1246 +};
1247 +#endif
1248 +
1249 +struct ipt_osf_info
1250 +{
1251 +       char                    genre[MAXGENRELEN];
1252 +       int                     len;
1253 +       unsigned long           flags;
1254 +       int                     loglevel;
1255 +       int                     invert; /* UNSUPPORTED */
1256 +};
1257 +
1258 +struct osf_wc
1259 +{
1260 +       char                    wc;
1261 +       unsigned long           val;
1262 +};
1263 +
1264 +/* This struct represents IANA options
1265 + * http://www.iana.org/assignments/tcp-parameters
1266 + */
1267 +struct osf_opt
1268 +{
1269 +       unsigned char           kind;
1270 +       unsigned char           length;
1271 +       struct osf_wc           wc;
1272 +};
1273 +
1274 +struct osf_finger
1275 +{
1276 +       struct list_head        flist;
1277 +       struct osf_wc           wss;
1278 +       unsigned char           ttl;
1279 +       unsigned char           df;
1280 +       unsigned long           ss;
1281 +       unsigned char           genre[MAXGENRELEN];
1282 +       unsigned char           version[MAXGENRELEN], subtype[MAXGENRELEN];
1283 +       
1284 +       /* Not needed, but for consistency with original table from Michal Zalewski */
1285 +       unsigned char           details[MAXDETLEN]; 
1286 +
1287 +       int                     opt_num;
1288 +       struct osf_opt          opt[MAX_IPOPTLEN]; /* In case it is all NOP or EOL */
1289 +
1290 +};
1291 +
1292 +struct ipt_osf_nlmsg
1293 +{
1294 +       struct osf_finger       f;
1295 +       struct iphdr            ip;
1296 +       struct tcphdr           tcp;
1297 +};
1298 +
1299 +#ifdef __KERNEL__
1300 +
1301 +/* Defines for IANA option kinds */
1302 +
1303 +#define OSFOPT_EOL             0       /* End of options */
1304 +#define OSFOPT_NOP             1       /* NOP */
1305 +#define OSFOPT_MSS             2       /* Maximum segment size */
1306 +#define OSFOPT_WSO             3       /* Window scale option */
1307 +#define OSFOPT_SACKP           4       /* SACK permitted */
1308 +#define OSFOPT_SACK            5       /* SACK */
1309 +#define OSFOPT_ECHO            6       
1310 +#define OSFOPT_ECHOREPLY       7
1311 +#define OSFOPT_TS              8       /* Timestamp option */
1312 +#define OSFOPT_POCP            9       /* Partial Order Connection Permitted */
1313 +#define OSFOPT_POSP            10      /* Partial Order Service Profile */
1314 +/* Others are not used in current OSF */
1315 +
1316 +static struct osf_opt IANA_opts[] = 
1317 +{
1318 +       {0, 1,},
1319 +       {1, 1,},
1320 +       {2, 4,},
1321 +       {3, 3,},
1322 +       {4, 2,},
1323 +       {5, 1 ,}, /* SACK length is not defined */
1324 +       {6, 6,},
1325 +       {7, 6,},
1326 +       {8, 10,},
1327 +       {9, 2,},
1328 +       {10, 3,},
1329 +       {11, 1,}, /* CC: Suppose 1 */
1330 +       {12, 1,}, /* the same */
1331 +       {13, 1,}, /* and here too */
1332 +       {14, 3,},
1333 +       {15, 1,}, /* TCP Alternate Checksum Data. Length is not defined */
1334 +       {16, 1,},
1335 +       {17, 1,},
1336 +       {18, 3,},
1337 +       {19, 18,},
1338 +       {20, 1,},
1339 +       {21, 1,},
1340 +       {22, 1,},
1341 +       {23, 1,},
1342 +       {24, 1,},
1343 +       {25, 1,},
1344 +       {26, 1,},
1345 +};
1346 +
1347 +#endif /* __KERNEL__ */
1348 +
1349 +#endif /* _IPT_OSF_H */
1350 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_policy.h linux-2.6.6/include/linux/netfilter_ipv4/ipt_policy.h
1351 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_policy.h   1970-01-01 01:00:00.000000000 +0100
1352 +++ linux-2.6.6/include/linux/netfilter_ipv4/ipt_policy.h       2004-05-18 14:28:50.000000000 +0200
1353 @@ -0,0 +1,52 @@
1354 +#ifndef _IPT_POLICY_H
1355 +#define _IPT_POLICY_H
1356 +
1357 +#define POLICY_MAX_ELEM        4
1358 +
1359 +enum ipt_policy_flags
1360 +{
1361 +       POLICY_MATCH_IN         = 0x1,
1362 +       POLICY_MATCH_OUT        = 0x2,
1363 +       POLICY_MATCH_NONE       = 0x4,
1364 +       POLICY_MATCH_STRICT     = 0x8,
1365 +};
1366 +
1367 +enum ipt_policy_modes
1368 +{
1369 +       POLICY_MODE_TRANSPORT,
1370 +       POLICY_MODE_TUNNEL
1371 +};
1372 +
1373 +struct ipt_policy_spec
1374 +{
1375 +       u_int8_t        saddr:1,
1376 +                       daddr:1,
1377 +                       proto:1,
1378 +                       mode:1,
1379 +                       spi:1,
1380 +                       reqid:1;
1381 +};
1382 +
1383 +struct ipt_policy_elem
1384 +{
1385 +       u_int32_t       saddr;
1386 +       u_int32_t       smask;
1387 +       u_int32_t       daddr;
1388 +       u_int32_t       dmask;
1389 +       u_int32_t       spi;
1390 +       u_int32_t       reqid;
1391 +       u_int8_t        proto;
1392 +       u_int8_t        mode;
1393 +
1394 +       struct ipt_policy_spec  match;
1395 +       struct ipt_policy_spec  invert;
1396 +};
1397 +
1398 +struct ipt_policy_info
1399 +{
1400 +       struct ipt_policy_elem pol[POLICY_MAX_ELEM];
1401 +       u_int16_t flags;
1402 +       u_int16_t len;
1403 +};
1404 +
1405 +#endif /* _IPT_POLICY_H */
1406 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_pool.h linux-2.6.6/include/linux/netfilter_ipv4/ipt_pool.h
1407 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_pool.h     1970-01-01 01:00:00.000000000 +0100
1408 +++ linux-2.6.6/include/linux/netfilter_ipv4/ipt_pool.h 2004-05-18 14:28:50.000000000 +0200
1409 @@ -0,0 +1,25 @@
1410 +#ifndef _IPT_POOL_H
1411 +#define _IPT_POOL_H
1412 +
1413 +#include <linux/netfilter_ipv4/ip_pool.h>
1414 +
1415 +#define IPT_POOL_INV_SRC       0x00000001
1416 +#define IPT_POOL_INV_DST       0x00000002
1417 +#define IPT_POOL_DEL_SRC       0x00000004
1418 +#define IPT_POOL_DEL_DST       0x00000008
1419 +#define IPT_POOL_INV_MOD_SRC   0x00000010
1420 +#define IPT_POOL_INV_MOD_DST   0x00000020
1421 +#define IPT_POOL_MOD_SRC_ACCEPT        0x00000040
1422 +#define IPT_POOL_MOD_DST_ACCEPT        0x00000080
1423 +#define IPT_POOL_MOD_SRC_DROP  0x00000100
1424 +#define IPT_POOL_MOD_DST_DROP  0x00000200
1425 +
1426 +/* match info */
1427 +struct ipt_pool_info
1428 +{
1429 +       ip_pool_t src;
1430 +       ip_pool_t dst;
1431 +       unsigned flags;
1432 +};
1433 +
1434 +#endif /*_IPT_POOL_H*/
1435 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_psd.h linux-2.6.6/include/linux/netfilter_ipv4/ipt_psd.h
1436 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_psd.h      1970-01-01 01:00:00.000000000 +0100
1437 +++ linux-2.6.6/include/linux/netfilter_ipv4/ipt_psd.h  2004-05-18 14:28:50.000000000 +0200
1438 @@ -0,0 +1,40 @@
1439 +#ifndef _IPT_PSD_H
1440 +#define _IPT_PSD_H
1441 +
1442 +#include <linux/param.h>
1443 +#include <linux/types.h>
1444 +
1445 +/*
1446 + * High port numbers have a lower weight to reduce the frequency of false
1447 + * positives, such as from passive mode FTP transfers.
1448 + */
1449 +#define PORT_WEIGHT_PRIV               3
1450 +#define PORT_WEIGHT_HIGH               1
1451 +
1452 +/*
1453 + * Port scan detection thresholds: at least COUNT ports need to be scanned
1454 + * from the same source, with no longer than DELAY ticks between ports.
1455 + */
1456 +#define SCAN_MIN_COUNT                 7
1457 +#define SCAN_MAX_COUNT                 (SCAN_MIN_COUNT * PORT_WEIGHT_PRIV)
1458 +#define SCAN_WEIGHT_THRESHOLD          SCAN_MAX_COUNT
1459 +#define SCAN_DELAY_THRESHOLD           (300) /* old usage of HZ here was erroneously and broke under uml */
1460 +
1461 +/*
1462 + * Keep track of up to LIST_SIZE source addresses, using a hash table of
1463 + * HASH_SIZE entries for faster lookups, but limiting hash collisions to
1464 + * HASH_MAX source addresses per the same hash value.
1465 + */
1466 +#define LIST_SIZE                      0x100
1467 +#define HASH_LOG                       9
1468 +#define HASH_SIZE                      (1 << HASH_LOG)
1469 +#define HASH_MAX                       0x10
1470 +
1471 +struct ipt_psd_info {
1472 +       unsigned int weight_threshold;
1473 +       unsigned int delay_threshold;
1474 +       unsigned short lo_ports_weight;
1475 +       unsigned short hi_ports_weight;
1476 +};
1477 +
1478 +#endif /*_IPT_PSD_H*/
1479 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_quota.h linux-2.6.6/include/linux/netfilter_ipv4/ipt_quota.h
1480 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_quota.h    1970-01-01 01:00:00.000000000 +0100
1481 +++ linux-2.6.6/include/linux/netfilter_ipv4/ipt_quota.h        2004-05-18 14:28:50.000000000 +0200
1482 @@ -0,0 +1,11 @@
1483 +#ifndef _IPT_QUOTA_H
1484 +#define _IPT_QUOTA_H
1485 +
1486 +/* print debug info in both kernel/netfilter module & iptable library */
1487 +//#define DEBUG_IPT_QUOTA
1488 +
1489 +struct ipt_quota_info {
1490 +        u_int64_t quota;
1491 +};
1492 +
1493 +#endif /*_IPT_QUOTA_H*/
1494 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_random.h linux-2.6.6/include/linux/netfilter_ipv4/ipt_random.h
1495 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_random.h   1970-01-01 01:00:00.000000000 +0100
1496 +++ linux-2.6.6/include/linux/netfilter_ipv4/ipt_random.h       2004-05-18 14:28:50.000000000 +0200
1497 @@ -0,0 +1,11 @@
1498 +#ifndef _IPT_RAND_H
1499 +#define _IPT_RAND_H
1500 +
1501 +#include <linux/param.h>
1502 +#include <linux/types.h>
1503 +
1504 +struct ipt_rand_info {
1505 +       u_int8_t average;
1506 +};
1507 +
1508 +#endif /*_IPT_RAND_H*/
1509 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_realm.h linux-2.6.6/include/linux/netfilter_ipv4/ipt_realm.h
1510 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_realm.h    1970-01-01 01:00:00.000000000 +0100
1511 +++ linux-2.6.6/include/linux/netfilter_ipv4/ipt_realm.h        2004-05-18 14:28:50.000000000 +0200
1512 @@ -0,0 +1,9 @@
1513 +#ifndef _IPT_REALM_H
1514 +#define _IPT_REALM_H
1515 +
1516 +struct ipt_realm_info {
1517 +       u_int32_t id;
1518 +       u_int32_t mask;
1519 +       u_int8_t invert;
1520 +};
1521 +#endif /*_IPT_REALM_H*/
1522 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_sctp.h linux-2.6.6/include/linux/netfilter_ipv4/ipt_sctp.h
1523 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_sctp.h     1970-01-01 01:00:00.000000000 +0100
1524 +++ linux-2.6.6/include/linux/netfilter_ipv4/ipt_sctp.h 2004-05-18 14:28:50.000000000 +0200
1525 @@ -0,0 +1,107 @@
1526 +#ifndef _IPT_SCTP_H_
1527 +#define _IPT_SCTP_H_
1528 +
1529 +#define IPT_SCTP_SRC_PORTS             0x01
1530 +#define IPT_SCTP_DEST_PORTS            0x02
1531 +#define IPT_SCTP_CHUNK_TYPES           0x04
1532 +
1533 +#define IPT_SCTP_VALID_FLAGS           0x07
1534 +
1535 +#define ELEMCOUNT(x) (sizeof(x)/sizeof(x[0]))
1536 +
1537 +
1538 +struct ipt_sctp_flag_info {
1539 +       u_int8_t chunktype;
1540 +       u_int8_t flag;
1541 +       u_int8_t flag_mask;
1542 +};
1543 +
1544 +#define IPT_NUM_SCTP_FLAGS     4
1545 +
1546 +struct ipt_sctp_info {
1547 +       u_int16_t dpts[2];  /* Min, Max */
1548 +       u_int16_t spts[2];  /* Min, Max */
1549 +
1550 +       u_int32_t chunkmap[256 / sizeof (u_int32_t)];  /* Bit mask of chunks to be matched according to RFC 2960 */
1551 +
1552 +#define SCTP_CHUNK_MATCH_ANY   0x01  /* Match if any of the chunk types are present */
1553 +#define SCTP_CHUNK_MATCH_ALL   0x02  /* Match if all of the chunk types are present */
1554 +#define SCTP_CHUNK_MATCH_ONLY  0x04  /* Match if these are the only chunk types present */
1555 +
1556 +       u_int32_t chunk_match_type;
1557 +       struct ipt_sctp_flag_info flag_info[IPT_NUM_SCTP_FLAGS];
1558 +       int flag_count;
1559 +
1560 +       u_int32_t flags;
1561 +       u_int32_t invflags;
1562 +};
1563 +
1564 +#define bytes(type) (sizeof(type) * 8)
1565 +
1566 +#define SCTP_CHUNKMAP_SET(chunkmap, type)              \
1567 +       do {                                            \
1568 +               chunkmap[type / bytes(u_int32_t)] |=    \
1569 +                       1 << (type % bytes(u_int32_t)); \
1570 +       } while (0)
1571 +
1572 +#define SCTP_CHUNKMAP_CLEAR(chunkmap, type)                    \
1573 +       do {                                                    \
1574 +               chunkmap[type / bytes(u_int32_t)] &=            \
1575 +                       ~(1 << (type % bytes(u_int32_t)));      \
1576 +       } while (0)
1577 +
1578 +#define SCTP_CHUNKMAP_IS_SET(chunkmap, type)                   \
1579 +({                                                             \
1580 +       (chunkmap[type / bytes (u_int32_t)] &                   \
1581 +               (1 << (type % bytes (u_int32_t)))) ? 1: 0;      \
1582 +})
1583 +
1584 +#define SCTP_CHUNKMAP_RESET(chunkmap)                          \
1585 +       do {                                                    \
1586 +               int i;                                          \
1587 +               for (i = 0; i < ELEMCOUNT(chunkmap); i++)       \
1588 +                       chunkmap[i] = 0;                        \
1589 +       } while (0)
1590 +
1591 +#define SCTP_CHUNKMAP_SET_ALL(chunkmap)                        \
1592 +       do {                                                    \
1593 +               int i;                                          \
1594 +               for (i = 0; i < ELEMCOUNT(chunkmap); i++)       \
1595 +                       chunkmap[i] = ~0;                       \
1596 +       } while (0)
1597 +
1598 +#define SCTP_CHUNKMAP_COPY(destmap, srcmap)                    \
1599 +       do {                                                    \
1600 +               int i;                                          \
1601 +               for (i = 0; i < ELEMCOUNT(chunkmap); i++)       \
1602 +                       destmap[i] = srcmap[i];                 \
1603 +       } while (0)
1604 +
1605 +#define SCTP_CHUNKMAP_IS_CLEAR(chunkmap)               \
1606 +({                                                     \
1607 +       int i;                                          \
1608 +       int flag = 1;                                   \
1609 +       for (i = 0; i < ELEMCOUNT(chunkmap); i++) {     \
1610 +               if (chunkmap[i]) {                      \
1611 +                       flag = 0;                       \
1612 +                       break;                          \
1613 +               }                                       \
1614 +       }                                               \
1615 +        flag;                                          \
1616 +})
1617 +
1618 +#define SCTP_CHUNKMAP_IS_ALL_SET(chunkmap)             \
1619 +({                                                     \
1620 +       int i;                                          \
1621 +       int flag = 1;                                   \
1622 +       for (i = 0; i < ELEMCOUNT(chunkmap); i++) {     \
1623 +               if (chunkmap[i] != ~0) {                \
1624 +                       flag = 0;                       \
1625 +                               break;                  \
1626 +               }                                       \
1627 +       }                                               \
1628 +        flag;                                          \
1629 +})
1630 +
1631 +#endif /* _IPT_SCTP_H_ */
1632 +
1633 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_string.h linux-2.6.6/include/linux/netfilter_ipv4/ipt_string.h
1634 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_string.h   1970-01-01 01:00:00.000000000 +0100
1635 +++ linux-2.6.6/include/linux/netfilter_ipv4/ipt_string.h       2004-05-18 14:28:50.000000000 +0200
1636 @@ -0,0 +1,21 @@
1637 +#ifndef _IPT_STRING_H
1638 +#define _IPT_STRING_H
1639 +
1640 +/* *** PERFORMANCE TWEAK ***
1641 + * Packet size and search string threshold,
1642 + * above which sublinear searches is used. */
1643 +#define IPT_STRING_HAYSTACK_THRESH     100
1644 +#define IPT_STRING_NEEDLE_THRESH       20
1645 +
1646 +#define BM_MAX_NLEN 256
1647 +#define BM_MAX_HLEN 1024
1648 +
1649 +typedef char *(*proc_ipt_search) (char *, char *, int, int);
1650 +
1651 +struct ipt_string_info {
1652 +    char string[BM_MAX_NLEN];
1653 +    u_int16_t invert;
1654 +    u_int16_t len;
1655 +};
1656 +
1657 +#endif /* _IPT_STRING_H */
1658 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_time.h linux-2.6.6/include/linux/netfilter_ipv4/ipt_time.h
1659 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_time.h     1970-01-01 01:00:00.000000000 +0100
1660 +++ linux-2.6.6/include/linux/netfilter_ipv4/ipt_time.h 2004-05-18 14:28:50.000000000 +0200
1661 @@ -0,0 +1,15 @@
1662 +#ifndef __ipt_time_h_included__
1663 +#define __ipt_time_h_included__
1664 +
1665 +
1666 +struct ipt_time_info {
1667 +       u_int8_t  days_match;   /* 1 bit per day. -SMTWTFS                      */
1668 +       u_int16_t time_start;   /* 0 < time_start < 23*60+59 = 1439             */
1669 +       u_int16_t time_stop;    /* 0:0 < time_stat < 23:59                      */
1670 +       u_int8_t  kerneltime;   /* ignore skb time (and use kerneltime) or not. */
1671 +       time_t    date_start;
1672 +       time_t    date_stop;
1673 +};
1674 +
1675 +
1676 +#endif /* __ipt_time_h_included__ */
1677 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_u32.h linux-2.6.6/include/linux/netfilter_ipv4/ipt_u32.h
1678 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_u32.h      1970-01-01 01:00:00.000000000 +0100
1679 +++ linux-2.6.6/include/linux/netfilter_ipv4/ipt_u32.h  2004-05-18 14:28:50.000000000 +0200
1680 @@ -0,0 +1,40 @@
1681 +#ifndef _IPT_U32_H
1682 +#define _IPT_U32_H
1683 +#include <linux/netfilter_ipv4/ip_tables.h>
1684 +
1685 +enum ipt_u32_ops
1686 +{
1687 +       IPT_U32_AND,
1688 +       IPT_U32_LEFTSH,
1689 +       IPT_U32_RIGHTSH,
1690 +       IPT_U32_AT
1691 +};
1692 +
1693 +struct ipt_u32_location_element
1694 +{
1695 +       u_int32_t number;
1696 +       u_int8_t nextop;
1697 +};
1698 +struct ipt_u32_value_element
1699 +{
1700 +       u_int32_t min;
1701 +       u_int32_t max;
1702 +};
1703 +/* *** any way to allow for an arbitrary number of elements?
1704 +   for now I settle for a limit of 10 of each */
1705 +#define U32MAXSIZE 10
1706 +struct ipt_u32_test
1707 +{
1708 +       u_int8_t nnums;
1709 +       struct ipt_u32_location_element location[U32MAXSIZE+1];
1710 +       u_int8_t nvalues;
1711 +       struct ipt_u32_value_element value[U32MAXSIZE+1];
1712 +};
1713 +
1714 +struct ipt_u32
1715 +{
1716 +       u_int8_t ntests;
1717 +       struct ipt_u32_test tests[U32MAXSIZE+1];
1718 +};
1719 +
1720 +#endif /*_IPT_U32_H*/
1721 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4.h linux-2.6.6/include/linux/netfilter_ipv4.h
1722 --- linux-2.6.6.org/include/linux/netfilter_ipv4.h      2004-05-10 04:33:13.000000000 +0200
1723 +++ linux-2.6.6/include/linux/netfilter_ipv4.h  2004-05-18 14:28:50.000000000 +0200
1724 @@ -7,6 +7,8 @@
1725  
1726  #include <linux/config.h>
1727  #include <linux/netfilter.h>
1728 +#include <linux/netdevice.h>
1729 +#include <net/protocol.h>
1730  
1731  /* IP Cache bits. */
1732  /* Src IP address. */
1733 @@ -85,6 +87,58 @@
1734     Returns true or false. */
1735  extern int skb_ip_make_writable(struct sk_buff **pskb,
1736                                 unsigned int writable_len);
1737 +
1738 +#if defined(CONFIG_XFRM) && defined(CONFIG_NETFILTER)
1739 +#include <net/route.h>
1740 +#include <net/xfrm.h>
1741 +
1742 +static inline int nf_hook_input_cond(struct sk_buff *skb)
1743 +{
1744 +       return !skb->sp || skb->sp->decap_done;
1745 +}
1746 +
1747 +static inline int
1748 +nf_xfrm_local_done(struct sk_buff *skb, struct inet_protocol *ipprot)
1749 +{
1750 +       return skb->sp && !skb->sp->decap_done
1751 +              && (!ipprot || !ipprot->xfrm_prot);
1752 +}
1753 +
1754 +static inline int nf_xfrm_nonlocal_done(struct sk_buff *skb)
1755 +{
1756 +       return skb->sp && !skb->sp->decap_done
1757 +              && !(((struct rtable *)skb->dst)->rt_flags&RTCF_LOCAL);
1758 +}
1759 +
1760 +extern int nf_rcv_postxfrm_local(struct sk_buff *skb);
1761 +extern int nf_rcv_postxfrm_nonlocal(struct sk_buff *skb);
1762 +#else /* CONFIG_XFRM */
1763 +static inline int nf_hook_input_cond(struct sk_buff *skb)
1764 +{
1765 +       return 1;
1766 +}
1767 +
1768 +static inline int
1769 +nf_xfrm_local_done(struct sk_buff *skb, struct inet_protocol *ipprot)
1770 +{
1771 +       return 0;
1772 +}
1773 +
1774 +static inline int nf_xfrm_nonlocal_done(struct sk_buff *skb)
1775 +{
1776 +       return 0;
1777 +}
1778 +
1779 +static inline int nf_rcv_postxfrm_local(struct sk_buff *skb)
1780 +{
1781 +       return 0;
1782 +}
1783 +
1784 +static inline int nf_rcv_postxfrm_nonlocal(struct sk_buff *skb)
1785 +{
1786 +       return 0; 
1787 +}
1788 +#endif /* CONFIG_XFRM */
1789  #endif /*__KERNEL__*/
1790  
1791  #endif /*__LINUX_IP_NETFILTER_H*/
1792 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv6/ip6_tables.h linux-2.6.6/include/linux/netfilter_ipv6/ip6_tables.h
1793 --- linux-2.6.6.org/include/linux/netfilter_ipv6/ip6_tables.h   2004-05-10 04:33:20.000000000 +0200
1794 +++ linux-2.6.6/include/linux/netfilter_ipv6/ip6_tables.h       2004-05-18 14:28:50.000000000 +0200
1795 @@ -140,6 +140,12 @@
1796         /* Back pointer */
1797         unsigned int comefrom;
1798  
1799 +       /* Name of the chain */
1800 +       char *chainname;
1801 +       
1802 +       /* Rule number in the chain. */
1803 +       u_int32_t rulenum;
1804 +
1805         /* Packet and byte counters. */
1806         struct ip6t_counters counters;
1807  
1808 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv6/ip6t_HL.h linux-2.6.6/include/linux/netfilter_ipv6/ip6t_HL.h
1809 --- linux-2.6.6.org/include/linux/netfilter_ipv6/ip6t_HL.h      1970-01-01 01:00:00.000000000 +0100
1810 +++ linux-2.6.6/include/linux/netfilter_ipv6/ip6t_HL.h  2004-05-18 14:28:50.000000000 +0200
1811 @@ -0,0 +1,22 @@
1812 +/* Hop Limit modification module for ip6tables
1813 + * Maciej Soltysiak <solt@dns.toxicfilms.tv>
1814 + * Based on HW's TTL module */
1815 +
1816 +#ifndef _IP6T_HL_H
1817 +#define _IP6T_HL_H
1818 +
1819 +enum {
1820 +       IP6T_HL_SET = 0,
1821 +       IP6T_HL_INC,
1822 +       IP6T_HL_DEC
1823 +};
1824 +
1825 +#define IP6T_HL_MAXMODE        IP6T_HL_DEC
1826 +
1827 +struct ip6t_HL_info {
1828 +       u_int8_t        mode;
1829 +       u_int8_t        hop_limit;
1830 +};
1831 +
1832 +
1833 +#endif
1834 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv6/ip6t_REJECT.h linux-2.6.6/include/linux/netfilter_ipv6/ip6t_REJECT.h
1835 --- linux-2.6.6.org/include/linux/netfilter_ipv6/ip6t_REJECT.h  2004-05-10 04:31:58.000000000 +0200
1836 +++ linux-2.6.6/include/linux/netfilter_ipv6/ip6t_REJECT.h      2004-05-18 14:28:50.000000000 +0200
1837 @@ -2,15 +2,17 @@
1838  #define _IP6T_REJECT_H
1839  
1840  enum ip6t_reject_with {
1841 -       IP6T_ICMP_NET_UNREACHABLE,
1842 -       IP6T_ICMP_HOST_UNREACHABLE,
1843 -       IP6T_ICMP_PROT_UNREACHABLE,
1844 -       IP6T_ICMP_PORT_UNREACHABLE,
1845 -       IP6T_ICMP_ECHOREPLY
1846 +       IP6T_ICMP6_NO_ROUTE,
1847 +       IP6T_ICMP6_ADM_PROHIBITED,
1848 +       IP6T_ICMP6_NOT_NEIGHBOUR,
1849 +       IP6T_ICMP6_ADDR_UNREACH,
1850 +       IP6T_ICMP6_PORT_UNREACH,
1851 +       IP6T_ICMP6_ECHOREPLY,
1852 +       IP6T_TCP_RESET
1853  };
1854  
1855  struct ip6t_reject_info {
1856         enum ip6t_reject_with with;      /* reject type */
1857  };
1858  
1859 -#endif /*_IPT_REJECT_H*/
1860 +#endif /*_IP6T_REJECT_H*/
1861 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv6/ip6t_ROUTE.h linux-2.6.6/include/linux/netfilter_ipv6/ip6t_ROUTE.h
1862 --- linux-2.6.6.org/include/linux/netfilter_ipv6/ip6t_ROUTE.h   1970-01-01 01:00:00.000000000 +0100
1863 +++ linux-2.6.6/include/linux/netfilter_ipv6/ip6t_ROUTE.h       2004-05-18 14:28:50.000000000 +0200
1864 @@ -0,0 +1,22 @@
1865 +/* Header file for iptables ip6t_ROUTE target
1866 + *
1867 + * (C) 2003 by Cédric de Launois <delaunois@info.ucl.ac.be>
1868 + *
1869 + * This software is distributed under GNU GPL v2, 1991
1870 + */
1871 +#ifndef _IPT_ROUTE_H_target
1872 +#define _IPT_ROUTE_H_target
1873 +
1874 +#define IP6T_ROUTE_IFNAMSIZ 16
1875 +
1876 +struct ip6t_route_target_info {
1877 +       char      oif[IP6T_ROUTE_IFNAMSIZ];     /* Output Interface Name */
1878 +       char      iif[IP6T_ROUTE_IFNAMSIZ];     /* Input Interface Name  */
1879 +       u_int32_t gw[4];                        /* IPv6 address of gateway */
1880 +       u_int8_t  flags;
1881 +};
1882 +
1883 +/* Values for "flags" field */
1884 +#define IP6T_ROUTE_CONTINUE        0x01
1885 +
1886 +#endif /*_IP6T_ROUTE_H_target*/
1887 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv6/ip6t_fuzzy.h linux-2.6.6/include/linux/netfilter_ipv6/ip6t_fuzzy.h
1888 --- linux-2.6.6.org/include/linux/netfilter_ipv6/ip6t_fuzzy.h   1970-01-01 01:00:00.000000000 +0100
1889 +++ linux-2.6.6/include/linux/netfilter_ipv6/ip6t_fuzzy.h       2004-05-18 14:28:50.000000000 +0200
1890 @@ -0,0 +1,21 @@
1891 +#ifndef _IP6T_FUZZY_H
1892 +#define _IP6T_FUZZY_H
1893 +
1894 +#include <linux/param.h>
1895 +#include <linux/types.h>
1896 +
1897 +#define MAXFUZZYRATE 10000000
1898 +#define MINFUZZYRATE 3
1899 +
1900 +struct ip6t_fuzzy_info {
1901 +       u_int32_t minimum_rate;
1902 +       u_int32_t maximum_rate;
1903 +       u_int32_t packets_total;
1904 +       u_int32_t bytes_total;
1905 +       u_int32_t previous_time;
1906 +       u_int32_t present_time;
1907 +       u_int32_t mean_rate;
1908 +       u_int8_t acceptance_rate;
1909 +};
1910 +
1911 +#endif /*_IP6T_FUZZY_H*/
1912 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv6/ip6t_nth.h linux-2.6.6/include/linux/netfilter_ipv6/ip6t_nth.h
1913 --- linux-2.6.6.org/include/linux/netfilter_ipv6/ip6t_nth.h     1970-01-01 01:00:00.000000000 +0100
1914 +++ linux-2.6.6/include/linux/netfilter_ipv6/ip6t_nth.h 2004-05-18 14:28:50.000000000 +0200
1915 @@ -0,0 +1,19 @@
1916 +#ifndef _IP6T_NTH_H
1917 +#define _IP6T_NTH_H
1918 +
1919 +#include <linux/param.h>
1920 +#include <linux/types.h>
1921 +
1922 +#ifndef IP6T_NTH_NUM_COUNTERS
1923 +#define IP6T_NTH_NUM_COUNTERS 16
1924 +#endif
1925 +
1926 +struct ip6t_nth_info {
1927 +       u_int8_t every;
1928 +       u_int8_t not;
1929 +       u_int8_t startat;
1930 +       u_int8_t counter;
1931 +       u_int8_t packet;
1932 +};
1933 +
1934 +#endif /*_IP6T_NTH_H*/
1935 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv6/ip6t_owner.h linux-2.6.6/include/linux/netfilter_ipv6/ip6t_owner.h
1936 --- linux-2.6.6.org/include/linux/netfilter_ipv6/ip6t_owner.h   2004-05-10 04:32:52.000000000 +0200
1937 +++ linux-2.6.6/include/linux/netfilter_ipv6/ip6t_owner.h       2004-05-18 14:28:50.000000000 +0200
1938 @@ -6,12 +6,14 @@
1939  #define IP6T_OWNER_GID 0x02
1940  #define IP6T_OWNER_PID 0x04
1941  #define IP6T_OWNER_SID 0x08
1942 +#define IP6T_OWNER_COMM 0x10
1943  
1944  struct ip6t_owner_info {
1945      uid_t uid;
1946      gid_t gid;
1947      pid_t pid;
1948      pid_t sid;
1949 +    char comm[16];
1950      u_int8_t match, invert;    /* flags */
1951  };
1952  
1953 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv6/ip6t_policy.h linux-2.6.6/include/linux/netfilter_ipv6/ip6t_policy.h
1954 --- linux-2.6.6.org/include/linux/netfilter_ipv6/ip6t_policy.h  1970-01-01 01:00:00.000000000 +0100
1955 +++ linux-2.6.6/include/linux/netfilter_ipv6/ip6t_policy.h      2004-05-18 14:28:50.000000000 +0200
1956 @@ -0,0 +1,52 @@
1957 +#ifndef _IP6T_POLICY_H
1958 +#define _IP6T_POLICY_H
1959 +
1960 +#define POLICY_MAX_ELEM        4
1961 +
1962 +enum ip6t_policy_flags
1963 +{
1964 +       POLICY_MATCH_IN         = 0x1,
1965 +       POLICY_MATCH_OUT        = 0x2,
1966 +       POLICY_MATCH_NONE       = 0x4,
1967 +       POLICY_MATCH_STRICT     = 0x8,
1968 +};
1969 +
1970 +enum ip6t_policy_modes
1971 +{
1972 +       POLICY_MODE_TRANSPORT,
1973 +       POLICY_MODE_TUNNEL
1974 +};
1975 +
1976 +struct ip6t_policy_spec
1977 +{
1978 +       u_int8_t        saddr:1,
1979 +                       daddr:1,
1980 +                       proto:1,
1981 +                       mode:1,
1982 +                       spi:1,
1983 +                       reqid:1;
1984 +};
1985 +
1986 +struct ip6t_policy_elem
1987 +{
1988 +       struct in6_addr saddr;
1989 +       struct in6_addr smask;
1990 +       struct in6_addr daddr;
1991 +       struct in6_addr dmask;
1992 +       u_int32_t       spi;
1993 +       u_int32_t       reqid;
1994 +       u_int8_t        proto;
1995 +       u_int8_t        mode;
1996 +
1997 +       struct ip6t_policy_spec match;
1998 +       struct ip6t_policy_spec invert;
1999 +};
2000 +
2001 +struct ip6t_policy_info
2002 +{
2003 +       struct ip6t_policy_elem pol[POLICY_MAX_ELEM];
2004 +       u_int16_t flags;
2005 +       u_int16_t len;
2006 +};
2007 +
2008 +#endif /* _IP6T_POLICY_H */
2009 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv6/ip6t_random.h linux-2.6.6/include/linux/netfilter_ipv6/ip6t_random.h
2010 --- linux-2.6.6.org/include/linux/netfilter_ipv6/ip6t_random.h  1970-01-01 01:00:00.000000000 +0100
2011 +++ linux-2.6.6/include/linux/netfilter_ipv6/ip6t_random.h      2004-05-18 14:28:50.000000000 +0200
2012 @@ -0,0 +1,11 @@
2013 +#ifndef _IP6T_RAND_H
2014 +#define _IP6T_RAND_H
2015 +
2016 +#include <linux/param.h>
2017 +#include <linux/types.h>
2018 +
2019 +struct ip6t_rand_info {
2020 +       u_int8_t average;
2021 +};
2022 +
2023 +#endif /*_IP6T_RAND_H*/
2024 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_mime.h linux-2.6.6/include/linux/netfilter_mime.h
2025 --- linux-2.6.6.org/include/linux/netfilter_mime.h      1970-01-01 01:00:00.000000000 +0100
2026 +++ linux-2.6.6/include/linux/netfilter_mime.h  2004-05-18 14:28:50.000000000 +0200
2027 @@ -0,0 +1,89 @@
2028 +/*
2029 + * MIME functions for netfilter modules.  This file provides implementations
2030 + * for basic MIME parsing.  MIME headers are used in many protocols, such as
2031 + * HTTP, RTSP, SIP, etc.
2032 + *
2033 + * gcc will warn for defined but unused functions, so we only include the
2034 + * functions requested.  The following macros are used:
2035 + *   NF_NEED_MIME_NEXTLINE      nf_mime_nextline()
2036 + */
2037 +#ifndef _NETFILTER_MIME_H
2038 +#define _NETFILTER_MIME_H
2039 +
2040 +/* Only include these functions for kernel code. */
2041 +#ifdef __KERNEL__
2042 +
2043 +#include <linux/ctype.h>
2044 +
2045 +/*
2046 + * Given a buffer and length, advance to the next line and mark the current
2047 + * line.  If the current line is empty, *plinelen will be set to zero.  If
2048 + * not, it will be set to the actual line length (including CRLF).
2049 + *
2050 + * 'line' in this context means logical line (includes LWS continuations).
2051 + * Returns 1 on success, 0 on failure.
2052 + */
2053 +#ifdef NF_NEED_MIME_NEXTLINE
2054 +static int
2055 +nf_mime_nextline(char* p, uint len, uint* poff, uint* plineoff, uint* plinelen)
2056 +{
2057 +    uint    off = *poff;
2058 +    uint    physlen = 0;
2059 +    int     is_first_line = 1;
2060 +
2061 +    if (off >= len)
2062 +    {
2063 +        return 0;
2064 +    }
2065 +
2066 +    do
2067 +    {
2068 +        while (p[off] != '\n')
2069 +        {
2070 +            if (len-off <= 1)
2071 +            {
2072 +                return 0;
2073 +            }
2074 +
2075 +            physlen++;
2076 +            off++;
2077 +        }
2078 +
2079 +        /* if we saw a crlf, physlen needs adjusted */
2080 +        if (physlen > 0 && p[off] == '\n' && p[off-1] == '\r')
2081 +        {
2082 +            physlen--;
2083 +        }
2084 +
2085 +        /* advance past the newline */
2086 +        off++;
2087 +
2088 +        /* check for an empty line */
2089 +        if (physlen == 0)
2090 +        {
2091 +            break;
2092 +        }
2093 +
2094 +        /* check for colon on the first physical line */
2095 +        if (is_first_line)
2096 +        {
2097 +            is_first_line = 0;
2098 +            if (memchr(p+(*poff), ':', physlen) == NULL)
2099 +            {
2100 +                return 0;
2101 +            }
2102 +        }
2103 +    }
2104 +    while (p[off] == ' ' || p[off] == '\t');
2105 +
2106 +    *plineoff = *poff;
2107 +    *plinelen = (physlen == 0) ? 0 : (off - *poff);
2108 +    *poff = off;
2109 +
2110 +    return 1;
2111 +}
2112 +#endif /* NF_NEED_MIME_NEXTLINE */
2113 +
2114 +#endif /* __KERNEL__ */
2115 +
2116 +#endif /* _NETFILTER_MIME_H */
2117 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/skbuff.h linux-2.6.6/include/linux/skbuff.h
2118 --- linux-2.6.6.org/include/linux/skbuff.h      2004-05-10 04:32:39.000000000 +0200
2119 +++ linux-2.6.6/include/linux/skbuff.h  2004-05-18 14:28:50.000000000 +0200
2120 @@ -1049,6 +1049,14 @@
2121         if (nfct)
2122                 atomic_inc(&nfct->master->use);
2123  }
2124 +static inline void nf_reset(struct sk_buff *skb)
2125 +{
2126 +       nf_conntrack_put(skb->nfct);
2127 +       skb->nfct = NULL;
2128 +#ifdef CONFIG_NETFILTER_DEBUG
2129 +       skb->nf_debug = 0;
2130 +#endif
2131 +}
2132  
2133  #ifdef CONFIG_BRIDGE_NETFILTER
2134  static inline void nf_bridge_put(struct nf_bridge_info *nf_bridge)
2135 @@ -1061,9 +1069,10 @@
2136         if (nf_bridge)
2137                 atomic_inc(&nf_bridge->use);
2138  }
2139 -#endif
2140 -
2141 -#endif
2142 +#endif /* CONFIG_BRIDGE_NETFILTER */
2143 +#else /* CONFIG_NETFILTER */
2144 +static inline void nf_reset(struct sk_buff *skb) {}
2145 +#endif /* CONFIG_NETFILTER */
2146  
2147  #endif /* __KERNEL__ */
2148  #endif /* _LINUX_SKBUFF_H */
2149 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/net/ip.h linux-2.6.6/include/net/ip.h
2150 --- linux-2.6.6.org/include/net/ip.h    2004-05-10 04:32:53.000000000 +0200
2151 +++ linux-2.6.6/include/net/ip.h        2004-05-18 14:28:50.000000000 +0200
2152 @@ -30,6 +30,8 @@
2153  #include <linux/netdevice.h>
2154  #include <linux/inetdevice.h>
2155  #include <linux/in_route.h>
2156 +#include <linux/netfilter.h>
2157 +#include <linux/netfilter_ipv4.h>
2158  #include <net/route.h>
2159  #include <net/arp.h>
2160  
2161 @@ -48,6 +50,7 @@
2162  #define IPSKB_TRANSLATED       2
2163  #define IPSKB_FORWARDED                4
2164  #define IPSKB_XFRM_TUNNEL_SIZE 8
2165 +#define IPSKB_XFRM_TRANSFORMED 16
2166  };
2167  
2168  struct ipcm_cookie
2169 @@ -212,6 +215,12 @@
2170                 __ip_select_ident(iph, dst, more);
2171  }
2172  
2173 +extern inline int ip_dst_output(struct sk_buff *skb)
2174 +{
2175 +       return NF_HOOK_COND(PF_INET, NF_IP_POST_ROUTING, skb, NULL,
2176 +                           skb->dst->dev, dst_output, skb->dst->xfrm != NULL);
2177 +}
2178 +
2179  /*
2180   *     Map a multicast IP onto multicast MAC for type ethernet.
2181   */
2182 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/net/protocol.h linux-2.6.6/include/net/protocol.h
2183 --- linux-2.6.6.org/include/net/protocol.h      2004-05-10 04:32:28.000000000 +0200
2184 +++ linux-2.6.6/include/net/protocol.h  2004-05-18 14:28:50.000000000 +0200
2185 @@ -39,6 +39,7 @@
2186         int                     (*handler)(struct sk_buff *skb);
2187         void                    (*err_handler)(struct sk_buff *skb, u32 info);
2188         int                     no_policy;
2189 +       int                     xfrm_prot;
2190  };
2191  
2192  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
2193 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/net/tcp.h linux-2.6.6/include/net/tcp.h
2194 --- linux-2.6.6.org/include/net/tcp.h   2004-05-10 04:32:01.000000000 +0200
2195 +++ linux-2.6.6/include/net/tcp.h       2004-05-18 14:28:50.000000000 +0200
2196 @@ -162,6 +162,7 @@
2197  extern void tcp_bucket_unlock(struct sock *sk);
2198  extern int tcp_port_rover;
2199  extern struct sock *tcp_v4_lookup_listener(u32 addr, unsigned short hnum, int dif);
2200 +extern struct sock *tcp_v4_lookup(u32 saddr, u16 sport, u32 daddr, u16 hnum, int dif);
2201  
2202  /* These are AF independent. */
2203  static __inline__ int tcp_bhashfn(__u16 lport)
2204 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/net/udp.h linux-2.6.6/include/net/udp.h
2205 --- linux-2.6.6.org/include/net/udp.h   2004-05-10 04:33:13.000000000 +0200
2206 +++ linux-2.6.6/include/net/udp.h       2004-05-18 14:28:50.000000000 +0200
2207 @@ -74,6 +74,8 @@
2208  extern int     udp_ioctl(struct sock *sk, int cmd, unsigned long arg);
2209  extern int     udp_disconnect(struct sock *sk, int flags);
2210  
2211 +extern struct sock *udp_v4_lookup(u32 saddr, u16 sport, u32 daddr, u16 dport, int dif);
2212 +
2213  DECLARE_SNMP_STAT(struct udp_mib, udp_statistics);
2214  #define UDP_INC_STATS(field)           SNMP_INC_STATS(udp_statistics, field)
2215  #define UDP_INC_STATS_BH(field)                SNMP_INC_STATS_BH(udp_statistics, field)
2216 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/net/xfrm.h linux-2.6.6/include/net/xfrm.h
2217 --- linux-2.6.6.org/include/net/xfrm.h  2004-05-10 04:33:13.000000000 +0200
2218 +++ linux-2.6.6/include/net/xfrm.h      2004-05-18 14:28:50.000000000 +0200
2219 @@ -540,6 +540,9 @@
2220  {
2221         atomic_t                refcnt;
2222         int                     len;
2223 +#ifdef CONFIG_NETFILTER
2224 +       int                     decap_done;
2225 +#endif
2226         struct sec_decap_state  x[XFRM_MAX_DEPTH];
2227  };
2228  
2229 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/core/netfilter.c linux-2.6.6/net/core/netfilter.c
2230 --- linux-2.6.6.org/net/core/netfilter.c        2004-05-10 04:32:29.000000000 +0200
2231 +++ linux-2.6.6/net/core/netfilter.c    2004-05-18 14:28:50.000000000 +0200
2232 @@ -27,6 +27,8 @@
2233  #include <linux/icmp.h>
2234  #include <net/sock.h>
2235  #include <net/route.h>
2236 +#include <net/xfrm.h>
2237 +#include <net/ip.h>
2238  #include <linux/ip.h>
2239  
2240  /* In this code, we can be waiting indefinitely for userspace to
2241 @@ -638,7 +640,6 @@
2242  #ifdef CONFIG_IP_ROUTE_FWMARK
2243                 fl.nl_u.ip4_u.fwmark = (*pskb)->nfmark;
2244  #endif
2245 -               fl.proto = iph->protocol;
2246                 if (ip_route_output_key(&rt, &fl) != 0)
2247                         return -1;
2248  
2249 @@ -665,6 +666,20 @@
2250         if ((*pskb)->dst->error)
2251                 return -1;
2252  
2253 +#ifdef CONFIG_XFRM
2254 +       if (!(IPCB(*pskb)->flags & IPSKB_XFRM_TRANSFORMED)) {
2255 +               struct xfrm_policy_afinfo *afinfo;
2256 +
2257 +               afinfo = xfrm_policy_get_afinfo(AF_INET);
2258 +               if (afinfo != NULL) {
2259 +                       afinfo->decode_session(*pskb, &fl);
2260 +                       xfrm_policy_put_afinfo(afinfo);
2261 +                       if (xfrm_lookup(&(*pskb)->dst, &fl, (*pskb)->sk, 0) != 0)
2262 +                               return -1;
2263 +               }
2264 +       }
2265 +#endif
2266 +
2267         /* Change in oif may mean change in hh_len. */
2268         hh_len = (*pskb)->dst->dev->hard_header_len;
2269         if (skb_headroom(*pskb) < hh_len) {
2270 @@ -682,6 +697,71 @@
2271         return 0;
2272  }
2273  
2274 +#ifdef CONFIG_XFRM
2275 +inline int nf_rcv_postxfrm_nonlocal(struct sk_buff *skb)
2276 +{
2277 +       skb->sp->decap_done = 1;
2278 +       dst_release(skb->dst);
2279 +       skb->dst = NULL;
2280 +       nf_reset(skb);
2281 +       return netif_rx(skb);
2282 +}
2283 +
2284 +int nf_rcv_postxfrm_local(struct sk_buff *skb)
2285 +{
2286 +       __skb_push(skb, skb->data - skb->nh.raw);
2287 +       /* Fix header len and checksum if last xfrm was transport mode */
2288 +       if (!skb->sp->x[skb->sp->len - 1].xvec->props.mode) {
2289 +               skb->nh.iph->tot_len = htons(skb->len);
2290 +               ip_send_check(skb->nh.iph);
2291 +       }
2292 +       return nf_rcv_postxfrm_nonlocal(skb);
2293 +}
2294 +
2295 +#ifdef CONFIG_IP_NF_NAT_NEEDED
2296 +#include <linux/netfilter_ipv4/ip_conntrack.h>
2297 +#include <linux/netfilter_ipv4/ip_nat.h>
2298 +
2299 +void nf_nat_decode_session4(struct sk_buff *skb, struct flowi *fl)
2300 +{
2301 +       struct ip_conntrack *ct;
2302 +       struct ip_conntrack_tuple *t;
2303 +       struct ip_nat_info_manip *m;
2304 +       unsigned int i;
2305 +
2306 +       if (skb->nfct == NULL)
2307 +               return;
2308 +       ct = (struct ip_conntrack *)skb->nfct->master;
2309 +
2310 +       for (i = 0; i < ct->nat.info.num_manips; i++) {
2311 +               m = &ct->nat.info.manips[i];
2312 +               t = &ct->tuplehash[m->direction].tuple;
2313 +
2314 +               switch (m->hooknum) {
2315 +               case NF_IP_PRE_ROUTING:
2316 +                       if (m->maniptype != IP_NAT_MANIP_DST)
2317 +                               break;
2318 +                       fl->fl4_dst = t->dst.ip;
2319 +                       if (t->dst.protonum == IPPROTO_TCP ||
2320 +                           t->dst.protonum == IPPROTO_UDP)
2321 +                               fl->fl_ip_dport = t->dst.u.tcp.port;
2322 +                       break;
2323 +#ifdef CONFIG_IP_NF_NAT_LOCAL
2324 +               case NF_IP_LOCAL_IN:
2325 +                       if (m->maniptype != IP_NAT_MANIP_SRC)
2326 +                               break;
2327 +                       fl->fl4_src = t->src.ip;
2328 +                       if (t->dst.protonum == IPPROTO_TCP ||
2329 +                           t->dst.protonum == IPPROTO_UDP)
2330 +                               fl->fl_ip_sport = t->src.u.tcp.port;
2331 +                       break;
2332 +#endif
2333 +               }
2334 +       }
2335 +}
2336 +#endif /* CONFIG_IP_NF_NAT_NEEDED */
2337 +#endif
2338 +
2339  int skb_ip_make_writable(struct sk_buff **pskb, unsigned int writable_len)
2340  {
2341         struct sk_buff *nskb;
2342 @@ -839,3 +919,4 @@
2343  EXPORT_SYMBOL(nf_unregister_hook);
2344  EXPORT_SYMBOL(nf_unregister_queue_handler);
2345  EXPORT_SYMBOL(nf_unregister_sockopt);
2346 +EXPORT_SYMBOL(nf_rcv_postxfrm_local);
2347 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/ah4.c linux-2.6.6/net/ipv4/ah4.c
2348 --- linux-2.6.6.org/net/ipv4/ah4.c      2004-05-10 04:33:19.000000000 +0200
2349 +++ linux-2.6.6/net/ipv4/ah4.c  2004-05-18 14:28:50.000000000 +0200
2350 @@ -145,6 +145,7 @@
2351                 err = -EHOSTUNREACH;
2352                 goto error_nolock;
2353         }
2354 +       IPCB(skb)->flags |= IPSKB_XFRM_TRANSFORMED;
2355         return NET_XMIT_BYPASS;
2356  
2357  error:
2358 @@ -343,6 +344,7 @@
2359         .handler        =       xfrm4_rcv,
2360         .err_handler    =       ah4_err,
2361         .no_policy      =       1,
2362 +       .xfrm_prot      =       1,
2363  };
2364  
2365  static int __init ah4_init(void)
2366 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/esp4.c linux-2.6.6/net/ipv4/esp4.c
2367 --- linux-2.6.6.org/net/ipv4/esp4.c     2004-05-10 04:32:39.000000000 +0200
2368 +++ linux-2.6.6/net/ipv4/esp4.c 2004-05-18 14:28:50.000000000 +0200
2369 @@ -216,6 +216,7 @@
2370                 err = -EHOSTUNREACH;
2371                 goto error_nolock;
2372         }
2373 +       IPCB(skb)->flags |= IPSKB_XFRM_TRANSFORMED;
2374         return NET_XMIT_BYPASS;
2375  
2376  error:
2377 @@ -598,6 +599,7 @@
2378         .handler        =       xfrm4_rcv,
2379         .err_handler    =       esp4_err,
2380         .no_policy      =       1,
2381 +       .xfrm_prot      =       1,
2382  };
2383  
2384  static int __init esp4_init(void)
2385 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/igmp.c linux-2.6.6/net/ipv4/igmp.c
2386 --- linux-2.6.6.org/net/ipv4/igmp.c     2004-05-10 04:33:21.000000000 +0200
2387 +++ linux-2.6.6/net/ipv4/igmp.c 2004-05-18 14:28:50.000000000 +0200
2388 @@ -342,7 +342,7 @@
2389         pig->csum = ip_compute_csum((void *)skb->h.igmph, igmplen);
2390  
2391         return NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, skb, NULL, skb->dev,
2392 -                      dst_output);
2393 +                      ip_dst_output);
2394  }
2395  
2396  static int grec_size(struct ip_mc_list *pmc, int type, int gdel, int sdel)
2397 @@ -672,7 +672,7 @@
2398         ih->csum=ip_compute_csum((void *)ih, sizeof(struct igmphdr));
2399  
2400         return NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, skb, NULL, rt->u.dst.dev,
2401 -                      dst_output);
2402 +                      ip_dst_output);
2403  }
2404  
2405  static void igmp_gq_timer_expire(unsigned long data)
2406 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/ip_forward.c linux-2.6.6/net/ipv4/ip_forward.c
2407 --- linux-2.6.6.org/net/ipv4/ip_forward.c       2004-05-10 04:31:58.000000000 +0200
2408 +++ linux-2.6.6/net/ipv4/ip_forward.c   2004-05-18 14:28:50.000000000 +0200
2409 @@ -51,7 +51,7 @@
2410         if (unlikely(opt->optlen))
2411                 ip_forward_options(skb);
2412  
2413 -       return dst_output(skb);
2414 +       return ip_dst_output(skb);
2415  }
2416  
2417  int ip_forward(struct sk_buff *skb)
2418 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/ip_gre.c linux-2.6.6/net/ipv4/ip_gre.c
2419 --- linux-2.6.6.org/net/ipv4/ip_gre.c   2004-05-10 04:32:54.000000000 +0200
2420 +++ linux-2.6.6/net/ipv4/ip_gre.c       2004-05-18 14:28:50.000000000 +0200
2421 @@ -643,13 +643,7 @@
2422                 skb->dev = tunnel->dev;
2423                 dst_release(skb->dst);
2424                 skb->dst = NULL;
2425 -#ifdef CONFIG_NETFILTER
2426 -               nf_conntrack_put(skb->nfct);
2427 -               skb->nfct = NULL;
2428 -#ifdef CONFIG_NETFILTER_DEBUG
2429 -               skb->nf_debug = 0;
2430 -#endif
2431 -#endif
2432 +               nf_reset(skb);
2433                 ipgre_ecn_decapsulate(iph, skb);
2434                 netif_rx(skb);
2435                 read_unlock(&ipgre_lock);
2436 @@ -877,13 +871,7 @@
2437                 }
2438         }
2439  
2440 -#ifdef CONFIG_NETFILTER
2441 -       nf_conntrack_put(skb->nfct);
2442 -       skb->nfct = NULL;
2443 -#ifdef CONFIG_NETFILTER_DEBUG
2444 -       skb->nf_debug = 0;
2445 -#endif
2446 -#endif
2447 +       nf_reset(skb);
2448  
2449         IPTUNNEL_XMIT();
2450         tunnel->recursion--;
2451 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/ip_input.c linux-2.6.6/net/ipv4/ip_input.c
2452 --- linux-2.6.6.org/net/ipv4/ip_input.c 2004-05-10 04:31:59.000000000 +0200
2453 +++ linux-2.6.6/net/ipv4/ip_input.c     2004-05-18 14:28:50.000000000 +0200
2454 @@ -202,18 +202,10 @@
2455  
2456  #ifdef CONFIG_NETFILTER_DEBUG
2457         nf_debug_ip_local_deliver(skb);
2458 -       skb->nf_debug = 0;
2459  #endif /*CONFIG_NETFILTER_DEBUG*/
2460  
2461         __skb_pull(skb, ihl);
2462  
2463 -#ifdef CONFIG_NETFILTER
2464 -       /* Free reference early: we don't need it any more, and it may
2465 -           hold ip_conntrack module loaded indefinitely. */
2466 -       nf_conntrack_put(skb->nfct);
2467 -       skb->nfct = NULL;
2468 -#endif /*CONFIG_NETFILTER*/
2469 -
2470          /* Point into the IP datagram, just past the header. */
2471          skb->h.raw = skb->data;
2472  
2473 @@ -228,6 +220,13 @@
2474         resubmit:
2475                 hash = protocol & (MAX_INET_PROTOS - 1);
2476                 raw_sk = sk_head(&raw_v4_htable[hash]);
2477 +               ipprot = inet_protos[hash];
2478 +               smp_read_barrier_depends();
2479 +
2480 +               if (nf_xfrm_local_done(skb, ipprot)) {
2481 +                       nf_rcv_postxfrm_local(skb);
2482 +                       goto out;
2483 +               }
2484  
2485                 /* If there maybe a raw socket we must check - if not we
2486                  * don't care less
2487 @@ -235,14 +234,15 @@
2488                 if (raw_sk)
2489                         raw_v4_input(skb, skb->nh.iph, hash);
2490  
2491 -               if ((ipprot = inet_protos[hash]) != NULL) {
2492 +               if (ipprot != NULL) {
2493                         int ret;
2494  
2495 -                       smp_read_barrier_depends();
2496 -                       if (!ipprot->no_policy &&
2497 -                           !xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb)) {
2498 -                               kfree_skb(skb);
2499 -                               goto out;
2500 +                       if (!ipprot->no_policy) {
2501 +                               if (!xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb)) {
2502 +                                       kfree_skb(skb);
2503 +                                       goto out;
2504 +                               }
2505 +                               nf_reset(skb);
2506                         }
2507                         ret = ipprot->handler(skb);
2508                         if (ret < 0) {
2509 @@ -283,8 +283,8 @@
2510                         return 0;
2511         }
2512  
2513 -       return NF_HOOK(PF_INET, NF_IP_LOCAL_IN, skb, skb->dev, NULL,
2514 -                      ip_local_deliver_finish);
2515 +       return NF_HOOK_COND(PF_INET, NF_IP_LOCAL_IN, skb, skb->dev, NULL,
2516 +                           ip_local_deliver_finish, nf_hook_input_cond(skb));
2517  }
2518  
2519  static inline int ip_rcv_finish(struct sk_buff *skb)
2520 @@ -301,6 +301,9 @@
2521                         goto drop; 
2522         }
2523  
2524 +       if (nf_xfrm_nonlocal_done(skb))
2525 +               return nf_rcv_postxfrm_nonlocal(skb);
2526 +
2527  #ifdef CONFIG_NET_CLS_ROUTE
2528         if (skb->dst->tclassid) {
2529                 struct ip_rt_acct *st = ip_rt_acct + 256*smp_processor_id();
2530 @@ -422,8 +425,8 @@
2531                 }
2532         }
2533  
2534 -       return NF_HOOK(PF_INET, NF_IP_PRE_ROUTING, skb, dev, NULL,
2535 -                      ip_rcv_finish);
2536 +       return NF_HOOK_COND(PF_INET, NF_IP_PRE_ROUTING, skb, dev, NULL,
2537 +                           ip_rcv_finish, nf_hook_input_cond(skb));
2538  
2539  inhdr_error:
2540         IP_INC_STATS_BH(IpInHdrErrors);
2541 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/ip_output.c linux-2.6.6/net/ipv4/ip_output.c
2542 --- linux-2.6.6.org/net/ipv4/ip_output.c        2004-05-10 04:33:21.000000000 +0200
2543 +++ linux-2.6.6/net/ipv4/ip_output.c    2004-05-18 14:28:50.000000000 +0200
2544 @@ -123,6 +123,15 @@
2545         return ttl;
2546  }
2547  
2548 +#ifdef CONFIG_NETFILTER
2549 +/* out-of-line copy is only required with netfilter */
2550 +int ip_dst_output(struct sk_buff *skb)
2551 +{
2552 +       return NF_HOOK_COND(PF_INET, NF_IP_POST_ROUTING, skb, NULL,
2553 +                           skb->dst->dev, dst_output, skb->dst->xfrm != NULL);
2554 +}
2555 +#endif
2556 +
2557  /* 
2558   *             Add an ip header to a skbuff and send it out.
2559   *
2560 @@ -165,7 +174,7 @@
2561  
2562         /* Send it out. */
2563         return NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, skb, NULL, rt->u.dst.dev,
2564 -                      dst_output);
2565 +                      ip_dst_output);
2566  }
2567  
2568  static inline int ip_finish_output2(struct sk_buff *skb)
2569 @@ -283,7 +292,7 @@
2570                 return ip_finish_output(skb);
2571  }
2572  
2573 -int ip_output(struct sk_buff *skb)
2574 +static inline int ip_output2(struct sk_buff *skb)
2575  {
2576         IP_INC_STATS(IpOutRequests);
2577  
2578 @@ -294,6 +303,16 @@
2579                 return ip_finish_output(skb);
2580  }
2581  
2582 +int ip_output(struct sk_buff *skb)
2583 +{
2584 +       int transformed = IPCB(skb)->flags & IPSKB_XFRM_TRANSFORMED;
2585 +
2586 +       if (transformed)
2587 +               nf_reset(skb);
2588 +       return NF_HOOK_COND(PF_INET, NF_IP_LOCAL_OUT, skb, NULL,
2589 +                           skb->dst->dev, ip_output2, transformed);
2590 +}
2591 +
2592  int ip_queue_xmit(struct sk_buff *skb, int ipfragok)
2593  {
2594         struct sock *sk = skb->sk;
2595 @@ -387,7 +406,7 @@
2596         skb->priority = sk->sk_priority;
2597  
2598         return NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, skb, NULL, rt->u.dst.dev,
2599 -                      dst_output);
2600 +                      ip_dst_output);
2601  
2602  no_route:
2603         IP_INC_STATS(IpOutNoRoutes);
2604 @@ -1177,7 +1196,7 @@
2605  
2606         /* Netfilter gets whole the not fragmented skb. */
2607         err = NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, skb, NULL, 
2608 -                     skb->dst->dev, dst_output);
2609 +                     skb->dst->dev, ip_dst_output);
2610         if (err) {
2611                 if (err > 0)
2612                         err = inet->recverr ? net_xmit_errno(err) : 0;
2613 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/ipcomp.c linux-2.6.6/net/ipv4/ipcomp.c
2614 --- linux-2.6.6.org/net/ipv4/ipcomp.c   2004-05-10 04:33:13.000000000 +0200
2615 +++ linux-2.6.6/net/ipv4/ipcomp.c       2004-05-18 14:28:50.000000000 +0200
2616 @@ -231,6 +231,7 @@
2617                 err = -EHOSTUNREACH;
2618                 goto error_nolock;
2619         }
2620 +       IPCB(skb)->flags |= IPSKB_XFRM_TRANSFORMED;
2621         err = NET_XMIT_BYPASS;
2622  
2623  out_exit:
2624 @@ -407,6 +408,7 @@
2625         .handler        =       xfrm4_rcv,
2626         .err_handler    =       ipcomp4_err,
2627         .no_policy      =       1,
2628 +       .xfrm_prot      =       1,
2629  };
2630  
2631  static int __init ipcomp4_init(void)
2632 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/ipip.c linux-2.6.6/net/ipv4/ipip.c
2633 --- linux-2.6.6.org/net/ipv4/ipip.c     2004-05-10 04:33:22.000000000 +0200
2634 +++ linux-2.6.6/net/ipv4/ipip.c 2004-05-18 14:28:50.000000000 +0200
2635 @@ -478,6 +478,11 @@
2636  
2637         read_lock(&ipip_lock);
2638         if ((tunnel = ipip_tunnel_lookup(iph->saddr, iph->daddr)) != NULL) {
2639 +               /* IPIP packets decapsulated by IPsec missed netfilter hooks */
2640 +               if (nf_xfrm_local_done(skb, NULL)) {
2641 +                       nf_rcv_postxfrm_local(skb);
2642 +                       return 0;
2643 +               }
2644                 if (!xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb)) {
2645                         kfree_skb(skb);
2646                         return 0;
2647 @@ -496,13 +501,7 @@
2648                 skb->dev = tunnel->dev;
2649                 dst_release(skb->dst);
2650                 skb->dst = NULL;
2651 -#ifdef CONFIG_NETFILTER
2652 -               nf_conntrack_put(skb->nfct);
2653 -               skb->nfct = NULL;
2654 -#ifdef CONFIG_NETFILTER_DEBUG
2655 -               skb->nf_debug = 0;
2656 -#endif
2657 -#endif
2658 +               nf_reset(skb);
2659                 ipip_ecn_decapsulate(iph, skb);
2660                 netif_rx(skb);
2661                 read_unlock(&ipip_lock);
2662 @@ -647,13 +646,7 @@
2663         if ((iph->ttl = tiph->ttl) == 0)
2664                 iph->ttl        =       old_iph->ttl;
2665  
2666 -#ifdef CONFIG_NETFILTER
2667 -       nf_conntrack_put(skb->nfct);
2668 -       skb->nfct = NULL;
2669 -#ifdef CONFIG_NETFILTER_DEBUG
2670 -       skb->nf_debug = 0;
2671 -#endif
2672 -#endif
2673 +       nf_reset(skb);
2674  
2675         IPTUNNEL_XMIT();
2676         tunnel->recursion--;
2677 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/ipmr.c linux-2.6.6/net/ipv4/ipmr.c
2678 --- linux-2.6.6.org/net/ipv4/ipmr.c     2004-05-10 04:32:30.000000000 +0200
2679 +++ linux-2.6.6/net/ipv4/ipmr.c 2004-05-18 14:28:50.000000000 +0200
2680 @@ -1120,7 +1120,7 @@
2681         if (unlikely(opt->optlen))
2682                 ip_forward_options(skb);
2683  
2684 -       return dst_output(skb);
2685 +       return ip_dst_output(skb);
2686  }
2687  
2688  /*
2689 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/Kconfig linux-2.6.6/net/ipv4/netfilter/Kconfig
2690 --- linux-2.6.6.org/net/ipv4/netfilter/Kconfig  2004-05-10 04:33:13.000000000 +0200
2691 +++ linux-2.6.6/net/ipv4/netfilter/Kconfig      2004-05-18 14:28:50.000000000 +0200
2692 @@ -206,6 +206,11 @@
2693  
2694           To compile it as a module, choose M here.  If unsure, say N.
2695  
2696 +config IP_NF_MATCH_UNCLEAN
2697 +       tristate  'unclean match support (EXPERIMENTAL)'
2698 +       depends on EXPERIMENTAL && IP_NF_IPTABLES
2699 +         help
2700 +
2701  config IP_NF_MATCH_TTL
2702         tristate "TTL match support"
2703         depends on IP_NF_IPTABLES
2704 @@ -603,5 +608,509 @@
2705           <file:Documentation/modules.txt>.  If unsure, say `N'.
2706           help
2707  
2708 +config IP_NF_TARGET_IPV4OPTSSTRIP
2709 +       tristate  'IPV4OPTSSTRIP target support'
2710 +       depends on IP_NF_MANGLE
2711 +       help
2712 +         This option adds an IPV4OPTSSTRIP target.
2713 +         This target allows you to strip all IP options in a packet.
2714 +        
2715 +         If you want to compile it as a module, say M here and read
2716 +         Documentation/modules.txt.  If unsure, say `N'.
2717 +
2718 +config IP_NF_TARGET_NETLINK
2719 +       tristate  'NETLINK target support'
2720 +       depends on IP_NF_FILTER
2721 +       help
2722 +         The NETLINK target allows you to recieve packets in userspace via
2723 +         the kernel firewall netlink socket. Apps such as fwmon
2724 +         (http://firestorm.geek-ware.co.uk) can then recieve and dislpay
2725 +         these packets. This option is basically a re-implementation of the
2726 +         ipchains -o option.
2727 +
2728 +config IP_NF_TARGET_TTL
2729 +       tristate  'TTL target support'
2730 +       depends on IP_NF_MANGLE
2731 +       help
2732 +         This option adds a `TTL' target, which enables the user to set
2733 +         the TTL value or increment / decrement the TTL value by a given
2734 +         amount.
2735 +       
2736 +         If you want to compile it as a module, say M here and read
2737 +         Documentation/modules.txt.  If unsure, say `N'.
2738 +
2739 +config IP_NF_MATCH_CONNLIMIT
2740 +       tristate  'Connections/IP limit match support'
2741 +       depends on IP_NF_IPTABLES
2742 +       help
2743 +         This match allows you to restrict the number of parallel TCP
2744 +         connections to a server per client IP address (or address block).
2745 +       
2746 +         If you want to compile it as a module, say M here and read
2747 +         Documentation/modules.txt.  If unsure, say `N'.
2748 +
2749 +config IP_NF_MATCH_DSTLIMIT
2750 +       tristate  'dstlimit match support'
2751 +       depends on IP_NF_IPTABLES
2752 +
2753 +config IP_NF_MATCH_FUZZY
2754 +       tristate  'fuzzy match support'
2755 +       depends on IP_NF_IPTABLES
2756 +       help
2757 +         This option adds a `fuzzy' match, which allows you to match
2758 +         packets according to a fuzzy logic based law.
2759 +       
2760 +         If you want to compile it as a module, say M here and read
2761 +         Documentation/modules.txt.  If unsure, say `N'.
2762 +
2763 +config IP_NF_MATCH_IPV4OPTIONS
2764 +       tristate  'IPV4OPTIONS match support'
2765 +       depends on IP_NF_IPTABLES
2766 +       help
2767 +         This option adds a IPV4OPTIONS match.
2768 +         It allows you to filter options like source routing,
2769 +         record route, timestamp and router-altert.
2770 +       
2771 +         If you say Y here, try iptables -m ipv4options --help for more information.
2772 +        
2773 +         If you want to compile it as a module, say M here and read
2774 +         Documentation/modules.txt.  If unsure, say `N'.
2775 +
2776 +config IP_NF_MATCH_MPORT
2777 +       tristate  'Multiple port with ranges match support'
2778 +       depends on IP_NF_IPTABLES
2779 +       help
2780 +         This is an enhanced multiport match which supports port
2781 +         ranges as well as single ports.
2782 +       
2783 +         If you want to compile it as a module, say M here and read
2784 +         Documentation/modules.txt.  If unsure, say `N'.
2785 +
2786 +config IP_NF_MATCH_NTH
2787 +       tristate  'Nth match support'
2788 +       depends on IP_NF_IPTABLES
2789 +       help
2790 +         This option adds a `Nth' match, which allow you to make
2791 +         rules that match every Nth packet.  By default there are 
2792 +         16 different counters.
2793 +       
2794 +         [options]
2795 +          --every     Nth              Match every Nth packet
2796 +         [--counter]  num              Use counter 0-15 (default:0)
2797 +         [--start]    num              Initialize the counter at the number 'num'
2798 +                                       instead of 0. Must be between 0 and Nth-1
2799 +         [--packet]   num              Match on 'num' packet. Must be between 0
2800 +                                       and Nth-1.
2801 +       
2802 +                                       If --packet is used for a counter than
2803 +                                       there must be Nth number of --packet
2804 +                                       rules, covering all values between 0 and
2805 +                                       Nth-1 inclusively.
2806 +        
2807 +         If you want to compile it as a module, say M here and read
2808 +         Documentation/modules.txt.  If unsure, say `N'.
2809 +
2810 +config IP_NF_MATCH_OSF
2811 +       tristate  'OSF match support'
2812 +       depends on IP_NF_IPTABLES
2813 +       help
2814 +       
2815 +         The idea of passive OS fingerprint matching exists for quite a long time,
2816 +         but was created as extension fo OpenBSD pf only some weeks ago.
2817 +         Original idea was lurked in some OpenBSD mailing list (thanks
2818 +         grange@open...) and than adopted for Linux netfilter in form of this code.
2819 +       
2820 +         Original table was created by Michal Zalewski <lcamtuf@coredump.cx> for
2821 +         his excellent p0f and than changed a bit for more convenience.
2822 +       
2823 +         This module compares some data(WS, MSS, options and it's order, ttl,
2824 +         df and others) from first SYN packet (actually from packets with SYN
2825 +         bit set) with hardcoded in fingers[] table ones.
2826 +       
2827 +         If you say Y here, try iptables -m osf --help for more information.
2828 +        
2829 +         If you want to compile it as a module, say M here and read
2830 +         Documentation/modules.txt.  If unsure, say `N'.
2831 +
2832 +config IP_POOL_STATISTICS
2833 +       bool  'enable statistics on pool usage'
2834 +       depends on IP_NF_POOL!=n
2835 +       help
2836 +         This option controls whether usage gathering code is compiled into the
2837 +         ip_pool module.  Disabling statistics may be substantially faster.
2838 +
2839 +config IP_NF_POOL
2840 +       tristate  'IP address pool support'
2841 +       depends on IP_NF_IPTABLES
2842 +       help
2843 +         Pool matching lets you use bitmaps with one bit per address from some
2844 +         range of IP addresses; the match depends on whether a checked source
2845 +         or destination address has its bit set in the pool.
2846 +       
2847 +         There is also a POOL netfilter target, which can be used to set or remove
2848 +         the addresses of a packet from a pool.
2849 +       
2850 +         To define and use pools, you need userlevel utilities: a patched iptables,
2851 +         and the program ippool(8), which defines the pools and their bounds.
2852 +         The current release of pool matching is ippool-0.0.2, and can be found
2853 +         in the archives of the netfilter mailing list at
2854 +         http://lists.samba.org/netfilter/.
2855 +       
2856 +         If you want to compile it as a module, say M here and read
2857 +         Documentation/modules.txt.  If unsure, say `N'.
2858 +
2859 +config IP_NF_MATCH_PSD
2860 +       tristate  'psd match support'
2861 +       depends on IP_NF_IPTABLES
2862 +       help
2863 +         This option adds a `psd' match, which allows you to create rules in
2864 +         any iptables table wich will detect TCP and UDP port scans.
2865 +        
2866 +         If you want to compile it as a module, say M here and read
2867 +         Documentation/modules.txt.  If unsure, say `N'.
2868 +
2869 +config IP_NF_MATCH_QUOTA
2870 +       tristate  'quota match support'
2871 +       depends on IP_NF_IPTABLES
2872 +       help
2873 +         This match implements network quotas.
2874 +       
2875 +         If you want to compile it as a module, say M here and read
2876 +         Documentation/modules.txt.  If unsure, say `N'.
2877 +       
2878 +
2879 +config IP_NF_MATCH_RANDOM
2880 +       tristate  'random match support'
2881 +       depends on IP_NF_IPTABLES
2882 +       help
2883 +         This option adds a `random' match,
2884 +         which allow you to match packets randomly
2885 +         following a given probability.
2886 +        
2887 +         If you want to compile it as a module, say M here and read
2888 +         Documentation/modules.txt.  If unsure, say `N'.
2889 +
2890 +config IP_NF_MATCH_REALM
2891 +       tristate  'realm match support'
2892 +       depends on IP_NF_IPTABLES && NET_CLS_ROUTE
2893 +       help
2894 +         This option adds a `realm' match, which allows you to use the realm
2895 +         key from the routing subsytem inside iptables.
2896 +       
2897 +         This match pretty much resembles the CONFIG_NET_CLS_ROUTE4 option 
2898 +         in tc world.
2899 +       
2900 +         If you want to compile it as a module, say M here and read
2901 +         Documentation/modules.txt.  If unsure, say `N'.
2902 +
2903 +config IP_NF_MATCH_SCTP
2904 +       tristate  'SCTP protocol match support'
2905 +       depends on IP_NF_IPTABLES
2906 +
2907 +config IP_NF_MATCH_TIME
2908 +       tristate  'TIME match support'
2909 +       depends on IP_NF_IPTABLES
2910 +       help
2911 +         This option adds a `time' match, which allows you
2912 +         to match based on the packet arrival time/date
2913 +         (arrival time/date at the machine which netfilter is running on) or
2914 +         departure time/date (for locally generated packets).
2915 +       
2916 +         If you say Y here, try iptables -m time --help for more information.
2917 +        
2918 +         If you want to compile it as a module, say M here and read
2919 +         Documentation/modules.txt.  If unsure, say `N'.
2920 +
2921 +config IP_NF_MATCH_U32
2922 +       tristate  'U32 match support'
2923 +       depends on IP_NF_IPTABLES
2924 +       help
2925 +         U32 allows you to extract quantities of up to 4 bytes from a packet,
2926 +         AND them with specified masks, shift them by specified amounts and
2927 +         test whether the results are in any of a set of specified ranges.
2928 +         The specification of what to extract is general enough to skip over
2929 +         headers with lengths stored in the packet, as in IP or TCP header
2930 +         lengths.
2931 +       
2932 +         Details and examples are in the kernel module source.
2933 +
2934 +config IP_NF_CONNTRACK_MARK
2935 +       bool  'Connection mark tracking support'
2936 +       help
2937 +         This option enables support for connection marks, used by the
2938 +         `CONNMARK' target and `connmark' match. Similar to the mark value
2939 +         of packets, but this mark value is kept in the conntrack session
2940 +         instead of the individual packets.
2941 +       
2942 +config IP_NF_TARGET_CONNMARK
2943 +       tristate  'CONNMARK target support'
2944 +       depends on IP_NF_CONNTRACK_MARK && IP_NF_MANGLE
2945 +       help
2946 +         This option adds a `CONNMARK' target, which allows one to manipulate
2947 +         the connection mark value.  Similar to the MARK target, but
2948 +         affects the connection mark value rather than the packet mark value.
2949 +       
2950 +         If you want to compile it as a module, say M here and read
2951 +         Documentation/modules.txt.  The module will be called
2952 +         ipt_CONNMARK.o.  If unsure, say `N'.
2953 +       
2954 +config IP_NF_MATCH_CONNMARK
2955 +       tristate  ' Connection mark match support'
2956 +       depends on IP_NF_CONNTRACK_MARK && IP_NF_IPTABLES
2957 +       help
2958 +         This option adds a `connmark' match, which allows you to match the
2959 +         connection mark value previously set for the session by `CONNMARK'. 
2960 +       
2961 +         If you want to compile it as a module, say M here and read
2962 +         Documentation/modules.txt.  The module will be called
2963 +         ipt_connmark.o.  If unsure, say `N'.
2964 +
2965 +config IP_NF_TARGET_IPMARK
2966 +       tristate  'IPMARK target support'
2967 +       depends on IP_NF_MANGLE
2968 +       help
2969 +         This option adds a `IPMARK' target, which allows you to create rules
2970 +         in the `mangle' table which alter the netfilter mark (nfmark) field
2971 +         basing on the source or destination ip address of the packet.
2972 +         This is very useful for very fast massive mangling and marking.
2973 +       
2974 +         If you want to compile it as a module, say M here and read
2975 +         <file:Documentation/modules.txt>.  If unsure, say `N'.
2976 +
2977 +config IP_NF_TARGET_ROUTE
2978 +       tristate  'ROUTE target support'
2979 +       depends on IP_NF_MANGLE
2980 +       help
2981 +         This option adds a `ROUTE' target, which enables you to setup unusual
2982 +         routes. For example, the ROUTE lets you route a received packet through 
2983 +         an interface or towards a host, even if the regular destination of the 
2984 +         packet is the router itself. The ROUTE target is also able to change the 
2985 +         incoming interface of a packet.
2986 +       
2987 +         The target can be or not a final target. It has to be used inside the 
2988 +         mangle table.
2989 +         
2990 +         If you want to compile it as a module, say M here and read
2991 +         Documentation/modules.txt.  The module will be called ipt_ROUTE.o.
2992 +         If unsure, say `N'.
2993 +
2994 +config IP_NF_TARGET_TARPIT
2995 +       tristate 'TARPIT target support'
2996 +       depends on IP_NF_FILTER
2997 +       help
2998 +         Adds a TARPIT target to iptables, which captures and holds
2999 +         incoming TCP connections using no local per-connection resources.
3000 +         Connections are accepted, but immediately switched to the persist
3001 +         state (0 byte window), in which the remote side stops sending data
3002 +         and asks to continue every 60-240 seconds.  Attempts to close the
3003 +         connection are ignored, forcing the remote side to time out the
3004 +         connection in 12-24 minutes.
3005 +       
3006 +         This offers similar functionality to LaBrea
3007 +         <http://www.hackbusters.net/LaBrea/> but doesn't require dedicated
3008 +         hardware or IPs.  Any TCP port that you would normally DROP or REJECT
3009 +         can instead become a tarpit.
3010 +
3011 +config IP_NF_TARGET_TCPLAG
3012 +       tristate  'TCPLAG target support'
3013 +       depends on IP_NF_IPTABLES
3014 +       help
3015 +         This option adds a `TCPLAG' target, intended for INPUT, OUTPUT and
3016 +         FORWARD chains.
3017 +       
3018 +         This target has no effect on packets but will passively monitor TCP/IP
3019 +         connections and send lag estimates to syslog. Lag estimates are
3020 +         generated by considering the time delay between SEQ and matching ACK,
3021 +         which does not map precisely to any particular network property.
3022 +         We can say that a fast network will typically give smaller lag values
3023 +         than a slow network.
3024 +       
3025 +         Safest option is to choose `M' here and compile as a module,
3026 +         the module will do nothing until activated using the `iptables' utility.
3027 +
3028 +config IP_NF_TARGET_TRACE
3029 +       tristate  'TRACE target support'
3030 +       depends on IP_NF_RAW
3031 +       help
3032 +         The TRACE target allows packets to be traced as those
3033 +         matches any subsequent rule in any table/rule. The matched
3034 +         rule and the packet is logged with the prefix
3035 +       
3036 +         TRACE: tablename/chainname/rulenum  
3037 +       
3038 +         If you want to compile it as a module, say M here and read
3039 +         <file:Documentation/modules.txt>.  If unsure, say `N'.
3040 +
3041 +config IP_NF_TARGET_XOR
3042 +       tristate  'XOR target support'
3043 +       depends on IP_NF_MANGLE
3044 +       help
3045 +         This option adds a `XOR' target, which can encrypt TCP and 
3046 +         UDP traffic using a simple XOR encryption.
3047 +       
3048 +         If you want to compile it as a module, say M here and read
3049 +         Documentation/modules.txt.  If unsure, say `N'.
3050 +
3051 +config IP_NF_MATCH_ADDRTYPE
3052 +       tristate  'address type match support'
3053 +       depends on IP_NF_IPTABLES
3054 +       help
3055 +         This option allows you to match what routing thinks of an address,
3056 +         eg. UNICAST, LOCAL, BROADCAST, ...
3057 +       
3058 +         If you want to compile it as a module, say M here and read
3059 +         Documentation/modules.txt.  If unsure, say `N'.
3060 +
3061 +config IP_NF_EGG
3062 +       tristate  'Eggdrop bot support'
3063 +       depends on IP_NF_CONNTRACK
3064 +       help
3065 +         If you are running an eggdrop hub bot on this machine, then you
3066 +         may want to enable this feature. This enables eggdrop bots to share
3067 +         their user file to other eggdrop bots.
3068 +       
3069 +         If you want to compile it as a module, say M here and read
3070 +         Documentation/modules.txt.  If unsure, say `N'.
3071 +
3072 +config IP_NF_NAT_H323
3073 +       tristate
3074 +       depends on IP_NF_CONNTRACK!=n && IP_NF_NAT!=n
3075 +       default IP_NF_NAT if IP_NF_H323=y
3076 +       default m if IP_NF_H323=m
3077 +
3078 +config IP_NF_H323
3079 +       tristate  'H.323 (netmeeting) support'
3080 +       depends on IP_NF_CONNTRACK
3081 +       help
3082 +         H.323 is a standard signalling protocol used by teleconferencing
3083 +         softwares like netmeeting. With the ip_conntrack_h323 and
3084 +         the ip_nat_h323 modules you can support the protocol on a connection
3085 +         tracking/NATing firewall.
3086 +       
3087 +         If you want to compile it as a module, say 'M' here and read
3088 +         Documentation/modules.txt.  If unsure, say 'N'.
3089 +
3090 +config IP_NF_NAT_MMS
3091 +       tristate
3092 +       depends on IP_NF_CONNTRACK!=n && IP_NF_NAT!=n
3093 +       default IP_NF_NAT if IP_NF_MMS=y
3094 +       default m if IP_NF_MMS=m
3095 +
3096 +config IP_NF_MMS
3097 +       tristate  'MMS protocol support'
3098 +       depends on IP_NF_CONNTRACK
3099 +       help
3100 +         Tracking MMS (Microsoft Windows Media Services) connections
3101 +         could be problematic if random ports are used to send the
3102 +         streaming content. This option allows users to track streaming
3103 +         connections over random UDP or TCP ports.
3104 +       
3105 +         If you want to compile it as a module, say M here and read
3106 +         <file:Documentation/modules.txt>.  If unsure, say `Y'.
3107 +
3108 +config IP_NF_MATCH_POLICY
3109 +       tristate "IPsec policy match support"
3110 +       depends on IP_NF_IPTABLES && XFRM
3111 +       help
3112 +         Policy matching allows you to match packets based on the
3113 +         IPsec policy that was used during decapsulation/will
3114 +         be used during encapsulation.
3115 +
3116 +         To compile it as a module, choose M here.  If unsure, say N.
3117 +
3118 +config IP_NF_NAT_QUAKE3
3119 +       tristate
3120 +       depends on IP_NF_CONNTRACK!=n && IP_NF_NAT !=n
3121 +       default IP_NF_NAT if IP_NF_QUAKE3=y
3122 +       default m if IP_NF_QUAKE3=m
3123 +
3124 +config IP_NF_QUAKE3
3125 +       tristate "Quake3 protocol support"
3126 +       depends on IP_NF_CONNTRACK
3127 +       help
3128 +         Quake III Arena  connection tracking helper. This module allows for a
3129 +         stricter firewall rulebase if one only allows traffic to a master
3130 +         server. Connections to Quake III server IP addresses and ports returned
3131 +         by the master server will be tracked automatically.
3132 +       
3133 +         If you want to compile it as a module, say M here and read
3134 +         <file:Documentation/modules.txt>.  If unsure, say `Y'.
3135 +
3136 +config IP_NF_RSH
3137 +       tristate  'RSH protocol support'
3138 +       depends on IP_NF_CONNTRACK
3139 +       help
3140 +         The RSH connection tracker is required if the dynamic
3141 +         stderr "Server to Client" connection is to occur during a
3142 +         normal RSH session.  This typically operates as follows;
3143 +       
3144 +           Client 0:1023 --> Server 514    (stream 1 - stdin/stdout)
3145 +           Client 0:1023 <-- Server 0:1023 (stream 2 - stderr)
3146 +       
3147 +         This connection tracker will identify new RSH sessions,
3148 +         extract the outbound session details, and notify netfilter
3149 +         of pending "related" sessions.
3150 +       
3151 +         Warning: This module could be dangerous. It is not "best
3152 +                  practice" to use RSH, use SSH in all instances.
3153 +                  (see rfc1244, rfc1948, rfc2179, etc ad-nauseum)
3154 +       
3155 +       
3156 +         If you want to compile it as a module, say M here and read
3157 +         <file:Documentation/modules.txt>.  If unsure, say `N'.
3158 +
3159 +config IP_NF_NAT_RTSP
3160 +       tristate
3161 +       depends on IP_NF_CONNTRACK!=n && IP_NF_NAT!=n
3162 +       default IP_NF_NAT if IP_NF_RTSP=y
3163 +       default m if IP_NF_RTSP=m
3164 +
3165 +config IP_NF_RTSP
3166 +       tristate  ' RTSP protocol support'
3167 +       depends on IP_NF_CONNTRACK
3168 +       help
3169 +         Support the RTSP protocol.  This allows UDP transports to be setup
3170 +         properly, including RTP and RDT.
3171 +       
3172 +         If you want to compile it as a module, say 'M' here and read
3173 +         Documentation/modules.txt.  If unsure, say 'Y'.
3174 +
3175 +config IP_NF_CT_PROTO_SCTP
3176 +       tristate  'SCTP protocol connection tracking support'
3177 +       depends on IP_NF_CONNTRACK
3178 +
3179 +config IP_NF_MATCH_STRING
3180 +       tristate  'String match support'
3181 +       depends on IP_NF_IPTABLES
3182 +       help
3183 +         String matching alows you to match packets which contain a
3184 +         specified string of characters.
3185 +       
3186 +         If you want to compile it as a module, say M here and read
3187 +         Documentation/modules.txt.  If unsure, say `N'.
3188 +
3189 +config IP_NF_NAT_TALK
3190 +       tristate
3191 +       depends on IP_NF_CONNTRACK!=n && IP_NF_NAT!=n
3192 +       default IP_NF_NAT if IP_NF_TALK=y
3193 +       default m if IP_NF_TALK=m
3194 +
3195 +config IP_NF_TALK
3196 +       tristate  'talk protocol support'
3197 +       depends on IP_NF_CONNTRACK
3198 +       help
3199 +         The talk protocols (both otalk/talk - or talk/ntalk, to confuse
3200 +         you by the different namings about which is old or which is new :-)
3201 +         use an additional channel to setup the talk session and a separated
3202 +         data channel for the actual conversation (like in FTP). Both the 
3203 +         initiating and the setup channels are over UDP, while the data channel 
3204 +         is over TCP, on a random port. The conntrack part of this extension
3205 +         will enable you to let in/out talk sessions easily by matching these
3206 +         connections as RELATED by the state match, while the NAT part helps
3207 +         you to let talk sessions trough a NAT machine.
3208 +       
3209 +         If you want to compile it as a module, say 'M' here and read
3210 +         Documentation/modules.txt.  If unsure, say 'N'.
3211 +
3212  endmenu
3213  
3214 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/Makefile linux-2.6.6/net/ipv4/netfilter/Makefile
3215 --- linux-2.6.6.org/net/ipv4/netfilter/Makefile 2004-05-10 04:32:26.000000000 +0200
3216 +++ linux-2.6.6/net/ipv4/netfilter/Makefile     2004-05-18 14:28:50.000000000 +0200
3217 @@ -19,10 +19,34 @@
3218  # connection tracking
3219  obj-$(CONFIG_IP_NF_CONNTRACK) += ip_conntrack.o
3220  
3221 +# talk protocol support
3222 +obj-$(CONFIG_IP_NF_TALK) += ip_conntrack_talk.o
3223 +obj-$(CONFIG_IP_NF_NAT_TALK) += ip_nat_talk.o
3224 +
3225 +
3226 +# SCTP protocol connection tracking
3227 +obj-$(CONFIG_IP_NF_CT_PROTO_SCTP) += ip_conntrack_proto_sctp.o
3228
3229 +# H.323 support
3230 +obj-$(CONFIG_IP_NF_H323) += ip_conntrack_h323.o
3231 +obj-$(CONFIG_IP_NF_NAT_H323) += ip_nat_h323.o
3232 +
3233 +
3234  # connection tracking helpers
3235 +
3236 +# rtsp protocol support
3237 +obj-$(CONFIG_IP_NF_RTSP) += ip_conntrack_rtsp.o
3238 +obj-$(CONFIG_IP_NF_NAT_RTSP) += ip_nat_rtsp.o
3239 +
3240 +obj-$(CONFIG_IP_NF_QUAKE3) += ip_conntrack_quake3.o
3241 +obj-$(CONFIG_IP_NF_MMS) += ip_conntrack_mms.o
3242  obj-$(CONFIG_IP_NF_AMANDA) += ip_conntrack_amanda.o
3243  obj-$(CONFIG_IP_NF_TFTP) += ip_conntrack_tftp.o
3244  obj-$(CONFIG_IP_NF_FTP) += ip_conntrack_ftp.o
3245 +obj-$(CONFIG_IP_NF_RSH) += ip_conntrack_rsh.o
3246 +
3247 +obj-$(CONFIG_IP_NF_EGG) += ip_conntrack_egg.o
3248 +
3249  obj-$(CONFIG_IP_NF_IRC) += ip_conntrack_irc.o
3250  
3251  # NAT helpers 
3252 @@ -30,6 +69,8 @@
3253  obj-$(CONFIG_IP_NF_NAT_TFTP) += ip_nat_tftp.o
3254  obj-$(CONFIG_IP_NF_NAT_FTP) += ip_nat_ftp.o
3255  obj-$(CONFIG_IP_NF_NAT_IRC) += ip_nat_irc.o
3256 +obj-$(CONFIG_IP_NF_NAT_QUAKE3) += ip_nat_quake3.o
3257 +obj-$(CONFIG_IP_NF_NAT_MMS) += ip_nat_mms.o
3258  
3259  # generic IP tables 
3260  obj-$(CONFIG_IP_NF_IPTABLES) += ip_tables.o
3261 @@ -43,15 +84,39 @@
3262  # matches
3263  obj-$(CONFIG_IP_NF_MATCH_HELPER) += ipt_helper.o
3264  obj-$(CONFIG_IP_NF_MATCH_LIMIT) += ipt_limit.o
3265 +obj-$(CONFIG_IP_NF_MATCH_SCTP) += ipt_sctp.o
3266 +obj-$(CONFIG_IP_NF_MATCH_QUOTA) += ipt_quota.o
3267 +obj-$(CONFIG_IP_NF_MATCH_DSTLIMIT) += ipt_dstlimit.o
3268  obj-$(CONFIG_IP_NF_MATCH_MARK) += ipt_mark.o
3269 +obj-$(CONFIG_IP_NF_POOL) += ipt_pool.o ipt_POOL.o ip_pool.o
3270  obj-$(CONFIG_IP_NF_MATCH_MAC) += ipt_mac.o
3271  obj-$(CONFIG_IP_NF_MATCH_IPRANGE) += ipt_iprange.o
3272  
3273  obj-$(CONFIG_IP_NF_MATCH_PKTTYPE) += ipt_pkttype.o
3274  obj-$(CONFIG_IP_NF_MATCH_MULTIPORT) += ipt_multiport.o
3275 +
3276 +obj-$(CONFIG_IP_NF_MATCH_MPORT) += ipt_mport.o
3277 +
3278  obj-$(CONFIG_IP_NF_MATCH_OWNER) += ipt_owner.o
3279  obj-$(CONFIG_IP_NF_MATCH_TOS) += ipt_tos.o
3280  
3281 +obj-$(CONFIG_IP_NF_MATCH_TIME) += ipt_time.o
3282 +
3283 +
3284 +obj-$(CONFIG_IP_NF_MATCH_RANDOM) += ipt_random.o
3285 +
3286 +obj-$(CONFIG_IP_NF_MATCH_PSD) += ipt_psd.o
3287 +
3288 +obj-$(CONFIG_IP_NF_MATCH_OSF) += ipt_osf.o
3289 +
3290 +
3291 +obj-$(CONFIG_IP_NF_MATCH_NTH) += ipt_nth.o
3292 +
3293 +obj-$(CONFIG_IP_NF_MATCH_IPV4OPTIONS) += ipt_ipv4options.o
3294 +
3295 +
3296 +obj-$(CONFIG_IP_NF_MATCH_FUZZY) += ipt_fuzzy.o
3297 +
3298  obj-$(CONFIG_IP_NF_MATCH_RECENT) += ipt_recent.o
3299  
3300  obj-$(CONFIG_IP_NF_MATCH_ECN) += ipt_ecn.o
3301 @@ -60,28 +125,48 @@
3302  
3303  obj-$(CONFIG_IP_NF_MATCH_LENGTH) += ipt_length.o
3304  
3305 +obj-$(CONFIG_IP_NF_MATCH_U32) += ipt_u32.o
3306 +
3307 +
3308 +obj-$(CONFIG_IP_NF_MATCH_UNCLEAN) += ipt_unclean.o
3309 +obj-$(CONFIG_IP_NF_MATCH_STRING) += ipt_string.o
3310  obj-$(CONFIG_IP_NF_MATCH_TTL) += ipt_ttl.o
3311  obj-$(CONFIG_IP_NF_MATCH_STATE) += ipt_state.o
3312 +obj-$(CONFIG_IP_NF_MATCH_CONNMARK) += ipt_connmark.o
3313 +obj-$(CONFIG_IP_NF_MATCH_CONNLIMIT) += ipt_connlimit.o
3314  obj-$(CONFIG_IP_NF_MATCH_CONNTRACK) += ipt_conntrack.o
3315  obj-$(CONFIG_IP_NF_MATCH_TCPMSS) += ipt_tcpmss.o
3316 +obj-$(CONFIG_IP_NF_MATCH_ADDRTYPE) += ipt_addrtype.o
3317 +obj-$(CONFIG_IP_NF_MATCH_REALM) += ipt_realm.o
3318  
3319  obj-$(CONFIG_IP_NF_MATCH_PHYSDEV) += ipt_physdev.o
3320 +obj-$(CONFIG_IP_NF_MATCH_POLICY) += ipt_policy.o
3321  
3322  # targets
3323  obj-$(CONFIG_IP_NF_TARGET_REJECT) += ipt_REJECT.o
3324 +obj-$(CONFIG_IP_NF_TARGET_TARPIT) += ipt_TARPIT.o
3325  obj-$(CONFIG_IP_NF_TARGET_TOS) += ipt_TOS.o
3326  obj-$(CONFIG_IP_NF_TARGET_ECN) += ipt_ECN.o
3327  obj-$(CONFIG_IP_NF_TARGET_DSCP) += ipt_DSCP.o
3328  obj-$(CONFIG_IP_NF_TARGET_MARK) += ipt_MARK.o
3329 +obj-$(CONFIG_IP_NF_TARGET_IPMARK) += ipt_IPMARK.o
3330  obj-$(CONFIG_IP_NF_TARGET_MASQUERADE) += ipt_MASQUERADE.o
3331  obj-$(CONFIG_IP_NF_TARGET_REDIRECT) += ipt_REDIRECT.o
3332 +obj-$(CONFIG_IP_NF_TARGET_ROUTE) += ipt_ROUTE.o
3333  obj-$(CONFIG_IP_NF_TARGET_NETMAP) += ipt_NETMAP.o
3334  obj-$(CONFIG_IP_NF_TARGET_SAME) += ipt_SAME.o
3335  obj-$(CONFIG_IP_NF_TARGET_CLASSIFY) += ipt_CLASSIFY.o
3336  obj-$(CONFIG_IP_NF_NAT_SNMP_BASIC) += ip_nat_snmp_basic.o
3337  obj-$(CONFIG_IP_NF_TARGET_LOG) += ipt_LOG.o
3338 +obj-$(CONFIG_IP_NF_TARGET_XOR) += ipt_XOR.o
3339 +obj-$(CONFIG_IP_NF_TARGET_TCPLAG) += ipt_TCPLAG.o
3340 +obj-$(CONFIG_IP_NF_TARGET_CONNMARK) += ipt_CONNMARK.o
3341 +obj-$(CONFIG_IP_NF_TARGET_TTL) += ipt_TTL.o
3342 +obj-$(CONFIG_IP_NF_TARGET_NETLINK) += ipt_NETLINK.o
3343 +obj-$(CONFIG_IP_NF_TARGET_IPV4OPTSSTRIP) += ipt_IPV4OPTSSTRIP.o
3344  obj-$(CONFIG_IP_NF_TARGET_ULOG) += ipt_ULOG.o
3345  obj-$(CONFIG_IP_NF_TARGET_TCPMSS) += ipt_TCPMSS.o
3346 +obj-$(CONFIG_IP_NF_TARGET_TRACE) += ipt_TRACE.o
3347  obj-$(CONFIG_IP_NF_TARGET_NOTRACK) += ipt_NOTRACK.o
3348  
3349  # generic ARP tables
3350 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ip_conntrack_core.c linux-2.6.6/net/ipv4/netfilter/ip_conntrack_core.c
3351 --- linux-2.6.6.org/net/ipv4/netfilter/ip_conntrack_core.c      2004-05-10 04:31:55.000000000 +0200
3352 +++ linux-2.6.6/net/ipv4/netfilter/ip_conntrack_core.c  2004-05-18 14:28:50.000000000 +0200
3353 @@ -324,8 +324,9 @@
3354                 ip_conntrack_destroyed(ct);
3355  
3356         WRITE_LOCK(&ip_conntrack_lock);
3357 -       /* Delete us from our own list to prevent corruption later */
3358 -       list_del(&ct->sibling_list);
3359 +       /* Make sure don't leave any orphaned expectations lying around */
3360 +       if (ct->expecting)
3361 +               remove_expectations(ct, 1);
3362  
3363         /* Delete our master expectation */
3364         if (ct->master) {
3365 @@ -692,25 +693,22 @@
3366                              struct ip_conntrack_expect *, tuple);
3367         READ_UNLOCK(&ip_conntrack_expect_tuple_lock);
3368  
3369 -       /* If master is not in hash table yet (ie. packet hasn't left
3370 -          this machine yet), how can other end know about expected?
3371 -          Hence these are not the droids you are looking for (if
3372 -          master ct never got confirmed, we'd hold a reference to it
3373 -          and weird things would happen to future packets). */
3374 -       if (expected && !is_confirmed(expected->expectant))
3375 -               expected = NULL;
3376 -
3377 -       /* Look up the conntrack helper for master connections only */
3378 -       if (!expected)
3379 -               conntrack->helper = ip_ct_find_helper(&repl_tuple);
3380 +       if (expected) {
3381 +               /* If master is not in hash table yet (ie. packet hasn't left
3382 +                  this machine yet), how can other end know about expected?
3383 +                  Hence these are not the droids you are looking for (if
3384 +                  master ct never got confirmed, we'd hold a reference to it
3385 +                  and weird things would happen to future packets). */
3386 +               if (!is_confirmed(expected->expectant)) {
3387 +                       conntrack->helper = ip_ct_find_helper(&repl_tuple);
3388 +                       goto end;
3389 +               }
3390  
3391 -       /* If the expectation is dying, then this is a loser. */
3392 -       if (expected
3393 -           && expected->expectant->helper->timeout
3394 -           && ! del_timer(&expected->timeout))
3395 -               expected = NULL;
3396 +               /* Expectation is dying... */
3397 +               if (expected->expectant->helper->timeout
3398 +                   && !del_timer(&expected->timeout))
3399 +                       goto end;       
3400  
3401 -       if (expected) {
3402                 DEBUGP("conntrack: expectation arrives ct=%p exp=%p\n",
3403                         conntrack, expected);
3404                 /* Welcome, Mr. Bond.  We've been expecting you... */
3405 @@ -718,16 +716,28 @@
3406                 __set_bit(IPS_EXPECTED_BIT, &conntrack->status);
3407                 conntrack->master = expected;
3408                 expected->sibling = conntrack;
3409 +#if CONFIG_IP_NF_CONNTRACK_MARK
3410 +               conntrack->mark = expected->expectant->mark;
3411 +#endif
3412                 LIST_DELETE(&ip_conntrack_expect_list, expected);
3413                 expected->expectant->expecting--;
3414                 nf_conntrack_get(&master_ct(conntrack)->infos[0]);
3415 -       }
3416 -       atomic_inc(&ip_conntrack_count);
3417 +
3418 +               /* this is a braindead... --pablo */
3419 +               atomic_inc(&ip_conntrack_count);
3420 +               WRITE_UNLOCK(&ip_conntrack_lock);
3421 +
3422 +               if (expected->expectfn)
3423 +                       expected->expectfn(conntrack);
3424 +
3425 +               goto ret;
3426 +       } else 
3427 +               conntrack->helper = ip_ct_find_helper(&repl_tuple);
3428 +
3429 +end:   atomic_inc(&ip_conntrack_count);
3430         WRITE_UNLOCK(&ip_conntrack_lock);
3431  
3432 -       if (expected && expected->expectfn)
3433 -               expected->expectfn(conntrack);
3434 -       return &conntrack->tuplehash[IP_CT_DIR_ORIGINAL];
3435 +ret:   return &conntrack->tuplehash[IP_CT_DIR_ORIGINAL];
3436  }
3437  
3438  /* On success, returns conntrack ptr, sets skb->nfct and ctinfo */
3439 @@ -947,9 +957,8 @@
3440         atomic_set(&new->use, 1);
3441  
3442         /* add to expected list for this connection */
3443 -       list_add(&new->expected_list, &related_to->sibling_list);
3444 +       list_add_tail(&new->expected_list, &related_to->sibling_list);
3445         /* add to global list of expectations */
3446 -
3447         list_prepend(&ip_conntrack_expect_list, &new->list);
3448         /* add and start timer if required */
3449         if (related_to->helper->timeout) {
3450 @@ -1003,7 +1012,6 @@
3451  
3452         } else if (related_to->helper->max_expected && 
3453                    related_to->expecting >= related_to->helper->max_expected) {
3454 -               struct list_head *cur_item;
3455                 /* old == NULL */
3456                 if (!(related_to->helper->flags & 
3457                       IP_CT_HELPER_F_REUSE_EXPECT)) {
3458 @@ -1029,21 +1037,14 @@
3459                        NIPQUAD(related_to->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.ip));
3460   
3461                 /* choose the the oldest expectation to evict */
3462 -               list_for_each(cur_item, &related_to->sibling_list) { 
3463 -                       struct ip_conntrack_expect *cur;
3464 -
3465 -                       cur = list_entry(cur_item, 
3466 -                                        struct ip_conntrack_expect,
3467 -                                        expected_list);
3468 -                       if (cur->sibling == NULL) {
3469 -                               old = cur;
3470 +               list_for_each_entry(old, &related_to->sibling_list, 
3471 +                                                     expected_list)
3472 +                       if (old->sibling == NULL)
3473                                 break;
3474 -                       }
3475 -               }
3476  
3477 -               /* (!old) cannot happen, since related_to->expecting is the
3478 -                * number of unconfirmed expects */
3479 -               IP_NF_ASSERT(old);
3480 +               /* We cannot fail since related_to->expecting is the number
3481 +                * of unconfirmed expectations */
3482 +               IP_NF_ASSERT(old && old->sibling == NULL);
3483  
3484                 /* newnat14 does not reuse the real allocated memory
3485                  * structures but rather unexpects the old and
3486 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ip_conntrack_egg.c linux-2.6.6/net/ipv4/netfilter/ip_conntrack_egg.c
3487 --- linux-2.6.6.org/net/ipv4/netfilter/ip_conntrack_egg.c       1970-01-01 01:00:00.000000000 +0100
3488 +++ linux-2.6.6/net/ipv4/netfilter/ip_conntrack_egg.c   2004-05-18 14:28:50.000000000 +0200
3489 @@ -0,0 +1,237 @@
3490 +/* Eggdrop extension for IP connection tracking, Version 0.0.5
3491 + * based on ip_conntrack_irc.c 
3492 + *
3493 + *      This module only supports the share userfile-send command,
3494 + *      used by eggdrops to share it's userfile.
3495 + *
3496 + *      There are no support for NAT at the moment.
3497 + *
3498 + *      This program is free software; you can redistribute it and/or
3499 + *      modify it under the terms of the GNU General Public License
3500 + *      as published by the Free Software Foundation; either version
3501 + *      2 of the License, or (at your option) any later version.
3502 + *
3503 + *     Module load syntax:
3504 + *     
3505 + *     please give the ports of all Eggdrops You have running
3506 + *      on your system, the default port is 3333.
3507 + *
3508 + *      2001-04-19: Security update. IP addresses are now compared
3509 + *                  to prevent unauthorized "related" access.
3510 + *
3511 + *      2002-03-25: Harald Welte <laforge@gnumonks.org>:
3512 + *                 Port to netfilter 'newnat' API.
3513 + */
3514 +
3515 +#include <linux/module.h>
3516 +#include <linux/netfilter.h>
3517 +#include <linux/ip.h>
3518 +#include <net/checksum.h>
3519 +#include <net/tcp.h>
3520 +
3521 +#include <linux/netfilter_ipv4/lockhelp.h>
3522 +#include <linux/netfilter_ipv4/ip_conntrack_helper.h>
3523 +
3524 +#define MAX_PORTS 8
3525 +static int ports[MAX_PORTS];
3526 +static int ports_c = 0;
3527 +static unsigned int egg_timeout = 300;
3528 +
3529 +MODULE_AUTHOR("Magnus Sandin <magnus@sandin.cx>");
3530 +MODULE_DESCRIPTION("Eggdrop (userfile-sharing) connection tracking module");
3531 +MODULE_LICENSE("GPL");
3532 +#ifdef MODULE_PARM
3533 +MODULE_PARM(ports, "1-" __MODULE_STRING(MAX_PORTS) "i");
3534 +MODULE_PARM_DESC(ports, "port numbers of eggdrop servers");
3535 +#endif
3536 +
3537 +DECLARE_LOCK(ip_egg_lock);
3538 +struct module *ip_conntrack_egg = THIS_MODULE;
3539 +
3540 +#if 0
3541 +#define DEBUGP printk
3542 +#else
3543 +#define DEBUGP(format, args...)
3544 +#endif
3545 +
3546 +int parse_command(char *data, char *data_end, u_int32_t * ip, u_int16_t * port)
3547 +/* tries to get the ip_addr and port out of a eggdrop command
3548 +   return value: -1 on failure, 0 on success 
3549 +   data                pointer to first byte of DCC command data
3550 +   data_end    pointer to last byte of dcc command data
3551 +   ip          returns parsed ip of dcc command
3552 +   port                returns parsed port of dcc command */
3553 +{
3554 +       if (data > data_end)
3555 +               return -1;
3556 +       
3557 +       *ip = simple_strtoul(data, &data, 10);
3558 +
3559 +       /* skip blanks between ip and port */
3560 +       while (*data == ' ' && data < data_end)
3561 +               data++;
3562 +
3563 +       *port = simple_strtoul(data, &data, 10);
3564 +       return 0;
3565 +}
3566 +
3567 +
3568 +static int help(const struct iphdr *iph, size_t len,
3569 +               struct ip_conntrack *ct, enum ip_conntrack_info ctinfo)
3570 +{
3571 +       /* tcplen not negative guarenteed by ip_conntrack_tcp.c */
3572 +       struct tcphdr *tcph = (void *) iph + iph->ihl * 4;
3573 +       char *data = (char *) tcph + tcph->doff * 4;
3574 +       char *data_limit;
3575 +       u_int32_t tcplen = len - iph->ihl * 4;
3576 +       u_int32_t datalen = tcplen - tcph->doff * 4;
3577 +       int dir = CTINFO2DIR(ctinfo);
3578 +       int bytes_scanned = 0;
3579 +       struct ip_conntrack_expect exp;
3580 +
3581 +       u_int32_t egg_ip;
3582 +       u_int16_t egg_port;
3583 +
3584 +       DEBUGP("entered\n");
3585 +
3586 +       /* If packet is coming from IRC server */
3587 +       if (dir != IP_CT_DIR_REPLY)
3588 +               return NF_ACCEPT;
3589 +
3590 +       /* Until there's been traffic both ways, don't look in packets. */
3591 +       if (ctinfo != IP_CT_ESTABLISHED
3592 +           && ctinfo != IP_CT_ESTABLISHED + IP_CT_IS_REPLY) {
3593 +               DEBUGP("Conntrackinfo = %u\n", ctinfo);
3594 +               return NF_ACCEPT;
3595 +       }
3596 +
3597 +       /* Not whole TCP header? */
3598 +       if (tcplen < sizeof(struct tcphdr) || tcplen < tcph->doff * 4) {
3599 +               DEBUGP("tcplen = %u\n", (unsigned) tcplen);
3600 +               return NF_ACCEPT;
3601 +       }
3602 +
3603 +       /* Checksum invalid?  Ignore. */
3604 +       /* FIXME: Source route IP option packets --RR */
3605 +       if (tcp_v4_check(tcph, tcplen, iph->saddr, iph->daddr,
3606 +                        csum_partial((char *) tcph, tcplen, 0))) {
3607 +               DEBUGP("bad csum: %p %u %u.%u.%u.%u -> %u.%u.%u.%u\n",
3608 +                       tcph, tcplen, NIPQUAD(iph->saddr),
3609 +                       NIPQUAD(iph->daddr));
3610 +               return NF_ACCEPT;
3611 +       }
3612 +
3613 +       data_limit = (char *) data + datalen;
3614 +       while (datalen > 5 && bytes_scanned < 128) {
3615 +               if (memcmp(data, "s us ", 5)) {
3616 +                       data++;
3617 +                       datalen--;
3618 +                       bytes_scanned++;
3619 +                       continue;
3620 +               }
3621 +
3622 +               data += 5;
3623 +
3624 +               DEBUGP("Userfile-share found in connection "
3625 +                       "%u.%u.%u.%u -> %u.%u.%u.%u\n",
3626 +                       NIPQUAD(iph->saddr), NIPQUAD(iph->daddr));
3627 +
3628 +               if (parse_command((char *) data, data_limit, &egg_ip,
3629 +                                 &egg_port)) {
3630 +                       DEBUGP("no data in userfile-share pkt\n");
3631 +                       return NF_ACCEPT;
3632 +               }
3633 +
3634 +               memset(&exp, 0, sizeof(exp));
3635 +
3636 +               if (ct->tuplehash[dir].tuple.src.ip != htonl(egg_ip)) {
3637 +                       if (net_ratelimit())
3638 +                               printk("Forged Eggdrop command from "
3639 +                                      "%u.%u.%u.%u: %u.%u.%u.%u:%u\n",
3640 +                                      NIPQUAD(ct->tuplehash[dir].tuple.src.ip),
3641 +                                      HIPQUAD(egg_ip), egg_port);
3642 +                       return NF_ACCEPT;
3643 +               }
3644 +
3645 +               exp.tuple.src.ip = iph->daddr;
3646 +               exp.tuple.src.u.tcp.port = 0;
3647 +               exp.tuple.dst.ip = htonl(egg_ip);
3648 +               exp.tuple.dst.u.tcp.port = htons(egg_port);
3649 +               exp.tuple.dst.protonum = IPPROTO_TCP;
3650 +
3651 +               exp.mask.dst.u.tcp.port = 0xffff;
3652 +               exp.mask.dst.protonum = 0xffff;
3653 +
3654 +               DEBUGP("expect_related %u.%u.%u.%u:%u - %u.%u.%u.%u:%u\n",
3655 +                       NIPQUAD(t.src.ip), ntohs(t.src.u.tcp.port),
3656 +                       NIPQUAD(t.dst.ip), ntohs(t.dst.u.tcp.port));
3657 +
3658 +               ip_conntrack_expect_related(ct, &exp);
3659 +               break;
3660 +       }
3661 +       return NF_ACCEPT;
3662 +}
3663 +
3664 +static struct ip_conntrack_helper egg_helpers[MAX_PORTS];
3665 +static char egg_names[MAX_PORTS][14]; /* eggdrop-65535 */
3666 +
3667 +static void deregister_helpers(void) {
3668 +       int i;
3669 +       
3670 +       for (i = 0; i < ports_c; i++) {
3671 +               DEBUGP("unregistering helper for port %d\n", ports[i]);
3672 +               ip_conntrack_helper_unregister(&egg_helpers[i]);
3673 +       }
3674 +}
3675 +
3676 +static int __init init(void)
3677 +{
3678 +       int i, ret;
3679 +       char *tmpname;
3680 +
3681 +       /* If no port given, default to standard eggdrop port */
3682 +       if (ports[0] == 0)
3683 +               ports[0] = 3333;
3684 +
3685 +       for (i = 0; (i < MAX_PORTS) && ports[i]; i++) {
3686 +               memset(&egg_helpers[i], 0,
3687 +                      sizeof(struct ip_conntrack_helper));
3688 +               egg_helpers[i].tuple.src.u.tcp.port = htons(ports[i]);
3689 +               egg_helpers[i].tuple.dst.protonum = IPPROTO_TCP;
3690 +               egg_helpers[i].mask.src.u.tcp.port = 0xFFFF;
3691 +               egg_helpers[i].mask.dst.protonum = 0xFFFF;
3692 +               egg_helpers[i].max_expected = 1;
3693 +               egg_helpers[i].timeout = egg_timeout;
3694 +               egg_helpers[i].flags = IP_CT_HELPER_F_REUSE_EXPECT;
3695 +               egg_helpers[i].me = THIS_MODULE;
3696 +               egg_helpers[i].help = help;
3697 +
3698 +               tmpname = &egg_names[i][0];
3699 +               if (ports[i] == 3333)
3700 +                       sprintf(tmpname, "eggdrop");
3701 +               else
3702 +                       sprintf(tmpname, "eggdrop-%d", ports[i]);
3703 +               egg_helpers[i].name = tmpname;
3704 +
3705 +               DEBUGP("port #%d: %d\n", i, ports[i]);
3706 +
3707 +               ret = ip_conntrack_helper_register(&egg_helpers[i]);
3708 +
3709 +               if (ret) {
3710 +                       printk("ip_conntrack_egg: ERROR registering helper "
3711 +                               "for port %d\n", ports[i]);
3712 +                       deregister_helpers();
3713 +                       return 1;
3714 +               }
3715 +               ports_c++;
3716 +       }
3717 +       return 0;
3718 +}
3719 +
3720 +static void __exit fini(void)
3721 +{
3722 +       deregister_helpers();
3723 +}
3724 +
3725 +module_init(init);
3726 +module_exit(fini);
3727 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ip_conntrack_h323.c linux-2.6.6/net/ipv4/netfilter/ip_conntrack_h323.c
3728 --- linux-2.6.6.org/net/ipv4/netfilter/ip_conntrack_h323.c      1970-01-01 01:00:00.000000000 +0100
3729 +++ linux-2.6.6/net/ipv4/netfilter/ip_conntrack_h323.c  2004-05-18 14:28:50.000000000 +0200
3730 @@ -0,0 +1,308 @@
3731 +/* 
3732 + * H.323 'brute force' extension for H.323 connection tracking. 
3733 + * Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
3734 + *
3735 + * Based on ip_masq_h323.c for 2.2 kernels from CoRiTel, Sofia project.
3736 + * (http://www.coritel.it/projects/sofia/nat/)
3737 + * Uses Sampsa Ranta's excellent idea on using expectfn to 'bind'
3738 + * the unregistered helpers to the conntrack entries.
3739 + */
3740 +
3741 +
3742 +#include <linux/module.h>
3743 +#include <linux/netfilter.h>
3744 +#include <linux/ip.h>
3745 +#include <net/checksum.h>
3746 +#include <net/tcp.h>
3747 +
3748 +#include <linux/netfilter_ipv4/lockhelp.h>
3749 +#include <linux/netfilter_ipv4/ip_conntrack.h>
3750 +#include <linux/netfilter_ipv4/ip_conntrack_core.h>
3751 +#include <linux/netfilter_ipv4/ip_conntrack_helper.h>
3752 +#include <linux/netfilter_ipv4/ip_conntrack_tuple.h>
3753 +#include <linux/netfilter_ipv4/ip_conntrack_h323.h>
3754 +
3755 +MODULE_AUTHOR("Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>");
3756 +MODULE_DESCRIPTION("H.323 'brute force' connection tracking module");
3757 +MODULE_LICENSE("GPL");
3758 +
3759 +DECLARE_LOCK(ip_h323_lock);
3760 +struct module *ip_conntrack_h323 = THIS_MODULE;
3761 +
3762 +#if 0
3763 +#define DEBUGP printk
3764 +#else
3765 +#define DEBUGP(format, args...)
3766 +#endif
3767 +
3768 +/* FIXME: This should be in userspace.  Later. */
3769 +static int h245_help(const struct iphdr *iph, size_t len,
3770 +                    struct ip_conntrack *ct,
3771 +                    enum ip_conntrack_info ctinfo)
3772 +{
3773 +       struct tcphdr *tcph = (void *)iph + iph->ihl * 4;
3774 +       unsigned char *data = (unsigned char *) tcph + tcph->doff * 4;
3775 +       unsigned char *data_limit;
3776 +       u_int32_t tcplen = len - iph->ihl * 4;
3777 +       u_int32_t datalen = tcplen - tcph->doff * 4;
3778 +       int dir = CTINFO2DIR(ctinfo);
3779 +       struct ip_ct_h225_master *info = &ct->help.ct_h225_info;
3780 +       struct ip_conntrack_expect expect, *exp = &expect;
3781 +       struct ip_ct_h225_expect *exp_info = &exp->help.exp_h225_info;
3782 +       u_int16_t data_port;
3783 +       u_int32_t data_ip;
3784 +       unsigned int i;
3785 +
3786 +       DEBUGP("ct_h245_help: help entered %u.%u.%u.%u:%u->%u.%u.%u.%u:%u\n",
3787 +               NIPQUAD(iph->saddr), ntohs(tcph->source),
3788 +               NIPQUAD(iph->daddr), ntohs(tcph->dest));
3789 +
3790 +       /* Can't track connections formed before we registered */
3791 +       if (!info)
3792 +               return NF_ACCEPT;
3793 +               
3794 +       /* Until there's been traffic both ways, don't look in packets. */
3795 +       if (ctinfo != IP_CT_ESTABLISHED
3796 +           && ctinfo != IP_CT_ESTABLISHED + IP_CT_IS_REPLY) {
3797 +               DEBUGP("ct_h245_help: Conntrackinfo = %u\n", ctinfo);
3798 +               return NF_ACCEPT;
3799 +       }
3800 +
3801 +       /* Not whole TCP header or too short packet? */
3802 +       if (tcplen < sizeof(struct tcphdr) || tcplen < tcph->doff * 4 + 5) {
3803 +               DEBUGP("ct_h245_help: tcplen = %u\n", (unsigned)tcplen);
3804 +               return NF_ACCEPT;
3805 +       }
3806 +
3807 +       /* Checksum invalid?  Ignore. */
3808 +       /* FIXME: Source route IP option packets --RR */
3809 +       if (tcp_v4_check(tcph, tcplen, iph->saddr, iph->daddr,
3810 +                             csum_partial((char *)tcph, tcplen, 0))) {
3811 +               DEBUGP("ct_h245_help: bad csum: %p %u %u.%u.%u.%u %u.%u.%u.%u\n",
3812 +                      tcph, tcplen, NIPQUAD(iph->saddr),
3813 +                      NIPQUAD(iph->daddr));
3814 +               return NF_ACCEPT;
3815 +       }
3816 +
3817 +       data_limit = (unsigned char *) data + datalen;
3818 +       /* bytes: 0123   45
3819 +                 ipadrr port */
3820 +       for (i = 0; data < (data_limit - 5); data++, i++) {
3821 +               data_ip = *((u_int32_t *)data);
3822 +               if (data_ip == iph->saddr) {
3823 +                       data_port = *((u_int16_t *)(data + 4));
3824 +                       memset(&expect, 0, sizeof(expect));
3825 +                       /* update the H.225 info */
3826 +                       DEBUGP("ct_h245_help: new RTCP/RTP requested %u.%u.%u.%u:->%u.%u.%u.%u:%u\n",
3827 +                               NIPQUAD(ct->tuplehash[!dir].tuple.src.ip),
3828 +                               NIPQUAD(iph->saddr), ntohs(data_port));
3829 +                       LOCK_BH(&ip_h323_lock);
3830 +                       info->is_h225 = H225_PORT + 1;
3831 +                       exp_info->port = data_port;
3832 +                       exp_info->dir = dir;
3833 +                       exp_info->offset = i;
3834 +
3835 +                       exp->seq = ntohl(tcph->seq) + i;
3836 +                   
3837 +                       exp->tuple = ((struct ip_conntrack_tuple)
3838 +                               { { ct->tuplehash[!dir].tuple.src.ip,
3839 +                                   { 0 } },
3840 +                                 { data_ip,
3841 +                                   { .tcp = { data_port } },
3842 +                                   IPPROTO_UDP }});
3843 +                       exp->mask = ((struct ip_conntrack_tuple)
3844 +                               { { 0xFFFFFFFF, { 0 } },
3845 +                                 { 0xFFFFFFFF, { .tcp = { 0xFFFF } }, 0xFFFF }});
3846 +       
3847 +                       exp->expectfn = NULL;
3848 +                       
3849 +                       /* Ignore failure; should only happen with NAT */
3850 +                       ip_conntrack_expect_related(ct, exp);
3851 +
3852 +                       UNLOCK_BH(&ip_h323_lock);
3853 +               }
3854 +       }
3855 +
3856 +       return NF_ACCEPT;
3857 +
3858 +}
3859 +
3860 +/* H.245 helper is not registered! */
3861 +static struct ip_conntrack_helper h245 = 
3862 +       { { NULL, NULL },
3863 +          "H.245",                             /* name */
3864 +          IP_CT_HELPER_F_REUSE_EXPECT,         /* flags */
3865 +          NULL,                                        /* module */
3866 +          8,                                   /* max_ expected */
3867 +          240,                                 /* timeout */
3868 +          { { 0, { 0 } },                      /* tuple */
3869 +            { 0, { 0 }, IPPROTO_TCP } },
3870 +          { { 0, { 0xFFFF } },                 /* mask */
3871 +            { 0, { 0 }, 0xFFFF } },
3872 +          h245_help                            /* helper */
3873 +       };
3874 +
3875 +static int h225_expect(struct ip_conntrack *ct)
3876 +{
3877 +       WRITE_LOCK(&ip_conntrack_lock);
3878 +       ct->helper = &h245;
3879 +       DEBUGP("h225_expect: helper for %p added\n", ct);
3880 +       WRITE_UNLOCK(&ip_conntrack_lock);
3881 +       
3882 +       return NF_ACCEPT;       /* unused */
3883 +}
3884 +
3885 +/* FIXME: This should be in userspace.  Later. */
3886 +static int h225_help(const struct iphdr *iph, size_t len,
3887 +                    struct ip_conntrack *ct,
3888 +                    enum ip_conntrack_info ctinfo)
3889 +{
3890 +       struct tcphdr *tcph = (void *)iph + iph->ihl * 4;
3891 +       unsigned char *data = (unsigned char *) tcph + tcph->doff * 4;
3892 +       unsigned char *data_limit;
3893 +       u_int32_t tcplen = len - iph->ihl * 4;
3894 +       u_int32_t datalen = tcplen - tcph->doff * 4;
3895 +       int dir = CTINFO2DIR(ctinfo);
3896 +       struct ip_ct_h225_master *info = &ct->help.ct_h225_info;
3897 +       struct ip_conntrack_expect expect, *exp = &expect;
3898 +       struct ip_ct_h225_expect *exp_info = &exp->help.exp_h225_info;
3899 +       u_int16_t data_port;
3900 +       u_int32_t data_ip;
3901 +       unsigned int i;
3902 +       
3903 +       DEBUGP("ct_h225_help: help entered %u.%u.%u.%u:%u->%u.%u.%u.%u:%u\n",
3904 +               NIPQUAD(iph->saddr), ntohs(tcph->source),
3905 +               NIPQUAD(iph->daddr), ntohs(tcph->dest));
3906 +
3907 +       /* Can't track connections formed before we registered */
3908 +       if (!info)
3909 +               return NF_ACCEPT;
3910 +
3911 +       /* Until there's been traffic both ways, don't look in packets. */
3912 +       if (ctinfo != IP_CT_ESTABLISHED
3913 +           && ctinfo != IP_CT_ESTABLISHED + IP_CT_IS_REPLY) {
3914 +               DEBUGP("ct_h225_help: Conntrackinfo = %u\n", ctinfo);
3915 +               return NF_ACCEPT;
3916 +       }
3917 +
3918 +       /* Not whole TCP header or too short packet? */
3919 +       if (tcplen < sizeof(struct tcphdr) || tcplen < tcph->doff * 4 + 5) {
3920 +               DEBUGP("ct_h225_help: tcplen = %u\n", (unsigned)tcplen);
3921 +               return NF_ACCEPT;
3922 +       }
3923 +
3924 +       /* Checksum invalid?  Ignore. */
3925 +       /* FIXME: Source route IP option packets --RR */
3926 +       if (tcp_v4_check(tcph, tcplen, iph->saddr, iph->daddr,
3927 +                             csum_partial((char *)tcph, tcplen, 0))) {
3928 +               DEBUGP("ct_h225_help: bad csum: %p %u %u.%u.%u.%u %u.%u.%u.%u\n",
3929 +                      tcph, tcplen, NIPQUAD(iph->saddr),
3930 +                      NIPQUAD(iph->daddr));
3931 +               return NF_ACCEPT;
3932 +       }
3933 +       
3934 +       data_limit = (unsigned char *) data + datalen;
3935 +       /* bytes: 0123   45
3936 +                 ipadrr port */
3937 +       for (i = 0; data < (data_limit - 5); data++, i++) {
3938 +               data_ip = *((u_int32_t *)data);
3939 +               if (data_ip == iph->saddr) {
3940 +                       data_port = *((u_int16_t *)(data + 4));
3941 +                       if (data_port == tcph->source) {
3942 +                               /* Signal address */
3943 +                               DEBUGP("ct_h225_help: sourceCallSignalAddress from %u.%u.%u.%u\n",
3944 +                                       NIPQUAD(iph->saddr));
3945 +                               /* Update the H.225 info so that NAT can mangle the address/port
3946 +                                  even when we have no expected connection! */
3947 +#ifdef CONFIG_IP_NF_NAT_NEEDED
3948 +                               LOCK_BH(&ip_h323_lock);
3949 +                               info->dir = dir;
3950 +                               info->seq[IP_CT_DIR_ORIGINAL] = ntohl(tcph->seq) + i;
3951 +                               info->offset[IP_CT_DIR_ORIGINAL] = i;
3952 +                               UNLOCK_BH(&ip_h323_lock);
3953 +#endif
3954 +                       } else {
3955 +                               memset(&expect, 0, sizeof(expect));
3956 +
3957 +                               /* update the H.225 info */
3958 +                               LOCK_BH(&ip_h323_lock);
3959 +                               info->is_h225 = H225_PORT;
3960 +                               exp_info->port = data_port;
3961 +                               exp_info->dir = dir;
3962 +                               exp_info->offset = i;
3963 +
3964 +                               exp->seq = ntohl(tcph->seq) + i;
3965 +
3966 +                               exp->tuple = ((struct ip_conntrack_tuple)
3967 +                                       { { ct->tuplehash[!dir].tuple.src.ip,
3968 +                                           { 0 } },
3969 +                                         { data_ip,
3970 +                                           { .tcp = { data_port } },
3971 +                                           IPPROTO_TCP }});
3972 +                               exp->mask = ((struct ip_conntrack_tuple)
3973 +                                       { { 0xFFFFFFFF, { 0 } },
3974 +                                         { 0xFFFFFFFF, { .tcp = { 0xFFFF } }, 0xFFFF }});
3975 +       
3976 +                               exp->expectfn = h225_expect;
3977 +                               
3978 +                               /* Ignore failure */
3979 +                               ip_conntrack_expect_related(ct, exp);
3980 +
3981 +                               DEBUGP("ct_h225_help: new H.245 requested %u.%u.%u.%u->%u.%u.%u.%u:%u\n",
3982 +                                       NIPQUAD(ct->tuplehash[!dir].tuple.src.ip),
3983 +                                       NIPQUAD(iph->saddr), ntohs(data_port));
3984 +
3985 +                               UNLOCK_BH(&ip_h323_lock);
3986 +                       }  
3987 +#ifdef CONFIG_IP_NF_NAT_NEEDED
3988 +               } else if (data_ip == iph->daddr) {
3989 +                       data_port = *((u_int16_t *)(data + 4));
3990 +                       if (data_port == tcph->dest) {
3991 +                               /* Signal address */
3992 +                               DEBUGP("ct_h225_help: destCallSignalAddress %u.%u.%u.%u\n",
3993 +                                       NIPQUAD(iph->daddr));
3994 +                               /* Update the H.225 info so that NAT can mangle the address/port
3995 +                                  even when we have no expected connection! */
3996 +                               LOCK_BH(&ip_h323_lock);
3997 +                               info->dir = dir;
3998 +                               info->seq[IP_CT_DIR_REPLY] = ntohl(tcph->seq) + i;
3999 +                               info->offset[IP_CT_DIR_REPLY] = i;
4000 +                               UNLOCK_BH(&ip_h323_lock);
4001 +                       }
4002 +#endif
4003 +               }
4004 +       }
4005 +
4006 +       return NF_ACCEPT;
4007 +
4008 +}
4009 +
4010 +static struct ip_conntrack_helper h225 = 
4011 +       { { NULL, NULL },
4012 +         "H.225",                                      /* name */
4013 +         IP_CT_HELPER_F_REUSE_EXPECT,                  /* flags */
4014 +         THIS_MODULE,                                  /* module */
4015 +         2,                                            /* max_expected */
4016 +         240,                                          /* timeout */
4017 +         { { 0, { __constant_htons(H225_PORT) } },     /* tuple */
4018 +           { 0, { 0 }, IPPROTO_TCP } },
4019 +         { { 0, { 0xFFFF } },                          /* mask */
4020 +           { 0, { 0 }, 0xFFFF } },
4021 +         h225_help                                     /* helper */
4022 +       };
4023 +
4024 +static int __init init(void)
4025 +{
4026 +       return ip_conntrack_helper_register(&h225);
4027 +}
4028 +
4029 +static void __exit fini(void)
4030 +{
4031 +       /* Unregister H.225 helper */   
4032 +       ip_conntrack_helper_unregister(&h225);
4033 +}
4034 +
4035 +EXPORT_SYMBOL(ip_h323_lock);
4036 +
4037 +module_init(init);
4038 +module_exit(fini);
4039 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ip_conntrack_mms.c linux-2.6.6/net/ipv4/netfilter/ip_conntrack_mms.c
4040 --- linux-2.6.6.org/net/ipv4/netfilter/ip_conntrack_mms.c       1970-01-01 01:00:00.000000000 +0100
4041 +++ linux-2.6.6/net/ipv4/netfilter/ip_conntrack_mms.c   2004-05-18 14:28:50.000000000 +0200
4042 @@ -0,0 +1,308 @@
4043 +/* MMS extension for IP connection tracking
4044 + * (C) 2002 by Filip Sneppe <filip.sneppe@cronos.be>
4045 + * based on ip_conntrack_ftp.c and ip_conntrack_irc.c
4046 + *
4047 + * ip_conntrack_mms.c v0.3 2002-09-22
4048 + *
4049 + *      This program is free software; you can redistribute it and/or
4050 + *      modify it under the terms of the GNU General Public License
4051 + *      as published by the Free Software Foundation; either version
4052 + *      2 of the License, or (at your option) any later version.
4053 + *
4054 + *      Module load syntax:
4055 + *      insmod ip_conntrack_mms.o ports=port1,port2,...port<MAX_PORTS>
4056 + *
4057 + *      Please give the ports of all MMS servers You wish to connect to.
4058 + *      If you don't specify ports, the default will be TCP port 1755.
4059 + *
4060 + *      More info on MMS protocol, firewalls and NAT:
4061 + *      http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwmt/html/MMSFirewall.asp
4062 + *      http://www.microsoft.com/windows/windowsmedia/serve/firewall.asp
4063 + *
4064 + *      The SDP project people are reverse-engineering MMS:
4065 + *      http://get.to/sdp
4066 + */
4067 +
4068 +#include <linux/config.h>
4069 +#include <linux/module.h>
4070 +#include <linux/netfilter.h>
4071 +#include <linux/ip.h>
4072 +#include <linux/ctype.h>
4073 +#include <net/checksum.h>
4074 +#include <net/tcp.h>
4075 +
4076 +#include <linux/netfilter_ipv4/lockhelp.h>
4077 +#include <linux/netfilter_ipv4/ip_conntrack_helper.h>
4078 +#include <linux/netfilter_ipv4/ip_conntrack_mms.h>
4079 +
4080 +DECLARE_LOCK(ip_mms_lock);
4081 +struct module *ip_conntrack_mms = THIS_MODULE;
4082 +
4083 +#define MAX_PORTS 8
4084 +static int ports[MAX_PORTS];
4085 +static int ports_c;
4086 +#ifdef MODULE_PARM
4087 +MODULE_PARM(ports, "1-" __MODULE_STRING(MAX_PORTS) "i");
4088 +#endif
4089 +
4090 +#if 0 
4091 +#define DEBUGP printk
4092 +#else
4093 +#define DEBUGP(format, args...)
4094 +#endif
4095 +
4096 +EXPORT_SYMBOL(ip_mms_lock);
4097 +
4098 +MODULE_AUTHOR("Filip Sneppe <filip.sneppe@cronos.be>");
4099 +MODULE_DESCRIPTION("Microsoft Windows Media Services (MMS) connection tracking module");
4100 +MODULE_LICENSE("GPL");
4101 +
4102 +/* #define isdigit(c) (c >= '0' && c <= '9') */
4103 +
4104 +/* copied from drivers/usb/serial/io_edgeport.c - not perfect but will do the trick */
4105 +static void unicode_to_ascii (char *string, short *unicode, int unicode_size)
4106 +{
4107 +       int i;
4108 +       for (i = 0; i < unicode_size; ++i) {
4109 +               string[i] = (char)(unicode[i]);
4110 +       }
4111 +       string[unicode_size] = 0x00;
4112 +}
4113 +
4114 +__inline static int atoi(char *s) 
4115 +{
4116 +       int i=0;
4117 +       while (isdigit(*s)) {
4118 +               i = i*10 + *(s++) - '0';
4119 +       }
4120 +       return i;
4121 +}
4122 +
4123 +/* convert ip address string like "192.168.0.10" to unsigned int */
4124 +__inline static u_int32_t asciiiptoi(char *s)
4125 +{
4126 +       unsigned int i, j, k;
4127 +
4128 +       for(i=k=0; k<3; ++k, ++s, i<<=8) {
4129 +               i+=atoi(s);
4130 +               for(j=0; (*(++s) != '.') && (j<3); ++j)
4131 +                       ;
4132 +       }
4133 +       i+=atoi(s);
4134 +       return ntohl(i);
4135 +}
4136 +
4137 +int parse_mms(const char *data, 
4138 +             const unsigned int datalen,
4139 +             u_int32_t *mms_ip,
4140 +             u_int16_t *mms_proto,
4141 +             u_int16_t *mms_port,
4142 +             char **mms_string_b,
4143 +             char **mms_string_e,
4144 +             char **mms_padding_e)
4145 +{
4146 +       int unicode_size, i;
4147 +       char tempstring[28];       /* "\\255.255.255.255\UDP\65535" */
4148 +       char getlengthstring[28];
4149 +       
4150 +       for(unicode_size=0; 
4151 +           (char) *(data+(MMS_SRV_UNICODE_STRING_OFFSET+unicode_size*2)) != (char)0;
4152 +           unicode_size++)
4153 +               if ((unicode_size == 28) || (MMS_SRV_UNICODE_STRING_OFFSET+unicode_size*2 >= datalen)) 
4154 +                       return -1; /* out of bounds - incomplete packet */
4155 +       
4156 +       unicode_to_ascii(tempstring, (short *)(data+MMS_SRV_UNICODE_STRING_OFFSET), unicode_size);
4157 +       DEBUGP("ip_conntrack_mms: offset 60: %s\n", (const char *)(tempstring));
4158 +       
4159 +       /* IP address ? */
4160 +       *mms_ip = asciiiptoi(tempstring+2);
4161 +       
4162 +       i=sprintf(getlengthstring, "%u.%u.%u.%u", HIPQUAD(*mms_ip));
4163 +               
4164 +       /* protocol ? */
4165 +       if(strncmp(tempstring+3+i, "TCP", 3)==0)
4166 +               *mms_proto = IPPROTO_TCP;
4167 +       else if(strncmp(tempstring+3+i, "UDP", 3)==0)
4168 +               *mms_proto = IPPROTO_UDP;
4169 +
4170 +       /* port ? */
4171 +       *mms_port = atoi(tempstring+7+i);
4172 +
4173 +       /* we store a pointer to the beginning of the "\\a.b.c.d\proto\port" 
4174 +          unicode string, one to the end of the string, and one to the end 
4175 +          of the packet, since we must keep track of the number of bytes 
4176 +          between end of the unicode string and the end of packet (padding) */
4177 +       *mms_string_b  = (char *)(data + MMS_SRV_UNICODE_STRING_OFFSET);
4178 +       *mms_string_e  = (char *)(data + MMS_SRV_UNICODE_STRING_OFFSET + unicode_size * 2);
4179 +       *mms_padding_e = (char *)(data + datalen); /* looks funny, doesn't it */
4180 +       return 0;
4181 +}
4182 +
4183 +
4184 +/* FIXME: This should be in userspace.  Later. */
4185 +static int help(const struct iphdr *iph, size_t len,
4186 +               struct ip_conntrack *ct,
4187 +               enum ip_conntrack_info ctinfo)
4188 +{
4189 +       /* tcplen not negative guaranteed by ip_conntrack_tcp.c */
4190 +       struct tcphdr *tcph = (void *)iph + iph->ihl * 4;
4191 +       const char *data = (const char *)tcph + tcph->doff * 4;
4192 +       unsigned int tcplen = len - iph->ihl * 4;
4193 +       unsigned int datalen = tcplen - tcph->doff * 4;
4194 +       int dir = CTINFO2DIR(ctinfo);
4195 +       struct ip_conntrack_expect expect, *exp = &expect; 
4196 +       struct ip_ct_mms_expect *exp_mms_info = &exp->help.exp_mms_info;
4197 +       
4198 +       u_int32_t mms_ip;
4199 +       u_int16_t mms_proto;
4200 +       char mms_proto_string[8];
4201 +       u_int16_t mms_port;
4202 +       char *mms_string_b, *mms_string_e, *mms_padding_e;
4203 +            
4204 +       /* Until there's been traffic both ways, don't look in packets. */
4205 +       if (ctinfo != IP_CT_ESTABLISHED
4206 +           && ctinfo != IP_CT_ESTABLISHED+IP_CT_IS_REPLY) {
4207 +               DEBUGP("ip_conntrack_mms: Conntrackinfo = %u\n", ctinfo);
4208 +               return NF_ACCEPT;
4209 +       }
4210 +
4211 +       /* Not whole TCP header? */
4212 +       if (tcplen < sizeof(struct tcphdr) || tcplen < tcph->doff*4) {
4213 +               DEBUGP("ip_conntrack_mms: tcplen = %u\n", (unsigned)tcplen);
4214 +               return NF_ACCEPT;
4215 +       }
4216 +
4217 +       /* Checksum invalid?  Ignore. */
4218 +       /* FIXME: Source route IP option packets --RR */
4219 +       if (tcp_v4_check(tcph, tcplen, iph->saddr, iph->daddr,
4220 +           csum_partial((char *)tcph, tcplen, 0))) {
4221 +               DEBUGP("mms_help: bad csum: %p %u %u.%u.%u.%u %u.%u.%u.%u\n",
4222 +                      tcph, tcplen, NIPQUAD(iph->saddr),
4223 +                      NIPQUAD(iph->daddr));
4224 +               return NF_ACCEPT;
4225 +       }
4226 +       
4227 +       /* Only look at packets with 0x00030002/196610 on bytes 36->39 of TCP payload */
4228 +       /* FIXME: There is an issue with only looking at this packet: before this packet, 
4229 +          the client has already sent a packet to the server with the server's hostname 
4230 +          according to the client (think of it as the "Host: " header in HTTP/1.1). The 
4231 +          server will break the connection if this doesn't correspond to its own host 
4232 +          header. The client can also connect to an IP address; if it's the server's IP
4233 +          address, it will not break the connection. When doing DNAT on a connection 
4234 +          where the client uses a server's IP address, the nat module should detect
4235 +          this and change this string accordingly to the DNATed address. This should
4236 +          probably be done by checking for an IP address, then storing it as a member
4237 +          of struct ip_ct_mms_expect and checking for it in ip_nat_mms...
4238 +          */
4239 +       if( (MMS_SRV_MSG_OFFSET < datalen) && 
4240 +           ((*(u32 *)(data+MMS_SRV_MSG_OFFSET)) == MMS_SRV_MSG_ID)) {
4241 +               DEBUGP("ip_conntrack_mms: offset 37: %u %u %u %u, datalen:%u\n", 
4242 +                      (u8)*(data+36), (u8)*(data+37), 
4243 +                      (u8)*(data+38), (u8)*(data+39),
4244 +                      datalen);
4245 +               if(parse_mms(data, datalen, &mms_ip, &mms_proto, &mms_port,
4246 +                            &mms_string_b, &mms_string_e, &mms_padding_e))
4247 +                       if(net_ratelimit())
4248 +                               /* FIXME: more verbose debugging ? */
4249 +                               printk(KERN_WARNING
4250 +                                      "ip_conntrack_mms: Unable to parse data payload\n");
4251 +
4252 +               memset(&expect, 0, sizeof(expect));
4253 +
4254 +               sprintf(mms_proto_string, "(%u)", mms_proto);
4255 +               DEBUGP("ip_conntrack_mms: adding %s expectation %u.%u.%u.%u -> %u.%u.%u.%u:%u\n",
4256 +                      mms_proto == IPPROTO_TCP ? "TCP"
4257 +                      : mms_proto == IPPROTO_UDP ? "UDP":mms_proto_string,
4258 +                      NIPQUAD(ct->tuplehash[!dir].tuple.src.ip),
4259 +                      NIPQUAD(mms_ip),
4260 +                      mms_port);
4261 +               
4262 +               /* it's possible that the client will just ask the server to tunnel
4263 +                  the stream over the same TCP session (from port 1755): there's 
4264 +                  shouldn't be a need to add an expectation in that case, but it
4265 +                  makes NAT packet mangling so much easier */
4266 +               LOCK_BH(&ip_mms_lock);
4267 +
4268 +               DEBUGP("ip_conntrack_mms: tcph->seq = %u\n", tcph->seq);
4269 +               
4270 +               exp->seq = ntohl(tcph->seq) + (mms_string_b - data);
4271 +               exp_mms_info->len     = (mms_string_e  - mms_string_b);
4272 +               exp_mms_info->padding = (mms_padding_e - mms_string_e);
4273 +               exp_mms_info->port    = mms_port;
4274 +               
4275 +               DEBUGP("ip_conntrack_mms: wrote info seq=%u (ofs=%u), len=%d, padding=%u\n",
4276 +                      exp->seq, (mms_string_e - data), exp_mms_info->len, exp_mms_info->padding);
4277 +               
4278 +               exp->tuple = ((struct ip_conntrack_tuple)
4279 +                             { { ct->tuplehash[!dir].tuple.src.ip, { 0 } },
4280 +                             { mms_ip,
4281 +                               { .tcp = { (__u16) ntohs(mms_port) } },
4282 +                               mms_proto } }
4283 +                            );
4284 +               exp->mask  = ((struct ip_conntrack_tuple)
4285 +                            { { 0xFFFFFFFF, { 0 } },
4286 +                              { 0xFFFFFFFF, { .tcp = { 0xFFFF } }, 0xFFFF }});
4287 +               exp->expectfn = NULL;
4288 +               ip_conntrack_expect_related(ct, &expect);
4289 +               UNLOCK_BH(&ip_mms_lock);
4290 +       }
4291 +
4292 +       return NF_ACCEPT;
4293 +}
4294 +
4295 +static struct ip_conntrack_helper mms[MAX_PORTS];
4296 +static char mms_names[MAX_PORTS][10];
4297 +
4298 +/* Not __exit: called from init() */
4299 +static void fini(void)
4300 +{
4301 +       int i;
4302 +       for (i = 0; (i < MAX_PORTS) && ports[i]; i++) {
4303 +               DEBUGP("ip_conntrack_mms: unregistering helper for port %d\n",
4304 +                               ports[i]);
4305 +               ip_conntrack_helper_unregister(&mms[i]);
4306 +       }
4307 +}
4308 +
4309 +static int __init init(void)
4310 +{
4311 +       int i, ret;
4312 +       char *tmpname;
4313 +
4314 +       if (ports[0] == 0)
4315 +               ports[0] = MMS_PORT;
4316 +
4317 +       for (i = 0; (i < MAX_PORTS) && ports[i]; i++) {
4318 +               memset(&mms[i], 0, sizeof(struct ip_conntrack_helper));
4319 +               mms[i].tuple.src.u.tcp.port = htons(ports[i]);
4320 +               mms[i].tuple.dst.protonum = IPPROTO_TCP;
4321 +               mms[i].mask.src.u.tcp.port = 0xFFFF;
4322 +               mms[i].mask.dst.protonum = 0xFFFF;
4323 +               mms[i].max_expected = 1;
4324 +               mms[i].timeout = 0;
4325 +               mms[i].flags = IP_CT_HELPER_F_REUSE_EXPECT;
4326 +               mms[i].me = THIS_MODULE;
4327 +               mms[i].help = help;
4328 +
4329 +               tmpname = &mms_names[i][0];
4330 +               if (ports[i] == MMS_PORT)
4331 +                       sprintf(tmpname, "mms");
4332 +               else
4333 +                       sprintf(tmpname, "mms-%d", ports[i]);
4334 +               mms[i].name = tmpname;
4335 +
4336 +               DEBUGP("ip_conntrack_mms: registering helper for port %d\n", 
4337 +                               ports[i]);
4338 +               ret = ip_conntrack_helper_register(&mms[i]);
4339 +
4340 +               if (ret) {
4341 +                       fini();
4342 +                       return ret;
4343 +               }
4344 +               ports_c++;
4345 +       }
4346 +       return 0;
4347 +}
4348 +
4349 +module_init(init);
4350 +module_exit(fini);
4351 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ip_conntrack_proto_sctp.c linux-2.6.6/net/ipv4/netfilter/ip_conntrack_proto_sctp.c
4352 --- linux-2.6.6.org/net/ipv4/netfilter/ip_conntrack_proto_sctp.c        1970-01-01 01:00:00.000000000 +0100
4353 +++ linux-2.6.6/net/ipv4/netfilter/ip_conntrack_proto_sctp.c    2004-05-18 14:28:50.000000000 +0200
4354 @@ -0,0 +1,529 @@
4355 +/*
4356 + * Connection tracking protocol helper module for SCTP.
4357 + * 
4358 + * SCTP is defined in RFC 2960. References to various sections in this code 
4359 + * are to this RFC.
4360 + * 
4361 + * This program is free software; you can redistribute it and/or modify
4362 + * it under the terms of the GNU General Public License version 2 as
4363 + * published by the Free Software Foundation.
4364 + */
4365 +
4366 +#include <linux/types.h>
4367 +#include <linux/sched.h>
4368 +#include <linux/timer.h>
4369 +#include <linux/netfilter.h>
4370 +#include <linux/module.h>
4371 +#include <linux/in.h>
4372 +#include <linux/ip.h>
4373 +#include <linux/sctp.h>
4374 +#include <linux/string.h>
4375 +
4376 +#include <linux/netfilter_ipv4/ip_conntrack.h>
4377 +#include <linux/netfilter_ipv4/ip_conntrack_protocol.h>
4378 +#include <linux/netfilter_ipv4/lockhelp.h>
4379 +
4380 +#if 0
4381 +#define DEBUGP(format, ...) printk(format, ## __VA_ARGS__)
4382 +#else
4383 +#define DEBUGP(format, args...)
4384 +#endif
4385 +
4386 +/* Protects conntrack->proto.sctp */
4387 +static DECLARE_RWLOCK(sctp_lock);
4388 +
4389 +/* FIXME: Examine ipfilter's timeouts and conntrack transitions more
4390 +   closely.  They're more complex. --RR 
4391 +
4392 +   And so for me for SCTP :D -Kiran */
4393 +
4394 +static const char *sctp_conntrack_names[] = {
4395 +       "NONE",
4396 +       "CLOSED",
4397 +       "COOKIE_WAIT",
4398 +       "COOKIE_ECHOED",
4399 +       "ESTABLISHED",
4400 +       "SHUTDOWN_SENT",
4401 +       "SHUTDOWN_RECD",
4402 +       "SHUTDOWN_ACK_SENT",
4403 +};
4404 +
4405 +#define SECS  * HZ
4406 +#define MINS  * 60 SECS
4407 +#define HOURS * 60 MINS
4408 +#define DAYS  * 24 HOURS
4409 +
4410 +unsigned long ip_ct_sctp_timeout_closed            =  10 SECS;
4411 +unsigned long ip_ct_sctp_timeout_cookie_wait       =   3 SECS;
4412 +unsigned long ip_ct_sctp_timeout_cookie_echoed     =   3 SECS;
4413 +unsigned long ip_ct_sctp_timeout_established       =   5 DAYS;
4414 +unsigned long ip_ct_sctp_timeout_shutdown_sent     = 300 SECS / 1000;
4415 +unsigned long ip_ct_sctp_timeout_shutdown_recd     = 300 SECS / 1000;
4416 +unsigned long ip_ct_sctp_timeout_shutdown_ack_sent =   3 SECS;
4417 +
4418 +static unsigned long * sctp_timeouts[]
4419 += { 0,                                     /* SCTP_CONNTRACK_NONE  */
4420 +    &ip_ct_sctp_timeout_closed,                   /* SCTP_CONNTRACK_CLOSED */
4421 +    &ip_ct_sctp_timeout_cookie_wait,       /* SCTP_CONNTRACK_COOKIE_WAIT */
4422 +    &ip_ct_sctp_timeout_cookie_echoed,     /* SCTP_CONNTRACK_COOKIE_ECHOED */
4423 +    &ip_ct_sctp_timeout_established,       /* SCTP_CONNTRACK_ESTABLISHED */
4424 +    &ip_ct_sctp_timeout_shutdown_sent,     /* SCTP_CONNTRACK_SHUTDOWN_SENT */
4425 +    &ip_ct_sctp_timeout_shutdown_recd,     /* SCTP_CONNTRACK_SHUTDOWN_RECD */
4426 +    &ip_ct_sctp_timeout_shutdown_ack_sent  /* SCTP_CONNTRACK_SHUTDOWN_ACK_SENT */
4427 + };
4428 +
4429 +#define sNO SCTP_CONNTRACK_NONE
4430 +#define        sCL SCTP_CONNTRACK_CLOSED
4431 +#define        sCW SCTP_CONNTRACK_COOKIE_WAIT
4432 +#define        sCE SCTP_CONNTRACK_COOKIE_ECHOED
4433 +#define        sES SCTP_CONNTRACK_ESTABLISHED
4434 +#define        sSS SCTP_CONNTRACK_SHUTDOWN_SENT
4435 +#define        sSR SCTP_CONNTRACK_SHUTDOWN_RECD
4436 +#define        sSA SCTP_CONNTRACK_SHUTDOWN_ACK_SENT
4437 +#define        sIV SCTP_CONNTRACK_MAX
4438 +
4439 +/* 
4440 +       These are the descriptions of the states:
4441 +
4442 +NOTE: These state names are tantalizingly similar to the states of an 
4443 +SCTP endpoint. But the interpretation of the states is a little different,
4444 +considering that these are the states of the connection and not of an end 
4445 +point. Please note the subtleties. -Kiran
4446 +
4447 +NONE              - Nothing so far.
4448 +COOKIE WAIT       - We have seen an INIT chunk in the original direction, or also 
4449 +                    an INIT_ACK chunk in the reply direction.
4450 +COOKIE ECHOED     - We have seen a COOKIE_ECHO chunk in the original direction.
4451 +ESTABLISHED       - We have seen a COOKIE_ACK in the reply direction.
4452 +SHUTDOWN_SENT     - We have seen a SHUTDOWN chunk in the original direction.
4453 +SHUTDOWN_RECD     - We have seen a SHUTDOWN chunk in the reply directoin.
4454 +SHUTDOWN_ACK_SENT - We have seen a SHUTDOWN_ACK chunk in the direction opposite
4455 +                    to that of the SHUTDOWN chunk.
4456 +CLOSED            - We have seen a SHUTDOWN_COMPLETE chunk in the direction of 
4457 +                    the SHUTDOWN chunk. Connection is closed.
4458 +*/
4459 +
4460 +/* TODO
4461 + - I have assumed that the first INIT is in the original direction. 
4462 + This messes things when an INIT comes in the reply direction in CLOSED
4463 + state.
4464 + - Check the error type in the reply dir before transitioning from 
4465 +cookie echoed to closed.
4466 + - Sec 5.2.4 of RFC 2960
4467 + - Multi Homing support.
4468 +*/
4469 +
4470 +/* SCTP conntrack state transitions */
4471 +static enum sctp_conntrack sctp_conntracks[2][9][SCTP_CONNTRACK_MAX] = {
4472 +       {
4473 +/*     ORIGINAL        */
4474 +/*                  sNO, sCL, sCW, sCE, sES, sSS, sSR, sSA */
4475 +/* init         */ {sCW, sCW, sCW, sCE, sES, sSS, sSR, sSA},
4476 +/* init_ack     */ {sCL, sCL, sCW, sCE, sES, sSS, sSR, sSA},
4477 +/* abort        */ {sCL, sCL, sCL, sCL, sCL, sCL, sCL, sCL},
4478 +/* shutdown     */ {sCL, sCL, sCW, sCE, sSS, sSS, sSR, sSA},
4479 +/* shutdown_ack */ {sSA, sCL, sCW, sCE, sES, sSA, sSA, sSA},
4480 +/* error        */ {sCL, sCL, sCW, sCE, sES, sSS, sSR, sSA},/* Cant have Stale cookie*/
4481 +/* cookie_echo  */ {sCL, sCL, sCE, sCE, sES, sSS, sSR, sSA},/* 5.2.4 - Big TODO */
4482 +/* cookie_ack   */ {sCL, sCL, sCW, sCE, sES, sSS, sSR, sSA},/* Cant come in orig dir */
4483 +/* shutdown_comp*/ {sCL, sCL, sCW, sCE, sES, sSS, sSR, sCL}
4484 +       },
4485 +       {
4486 +/*     REPLY   */
4487 +/*                  sNO, sCL, sCW, sCE, sES, sSS, sSR, sSA */
4488 +/* init         */ {sIV, sCL, sCW, sCE, sES, sSS, sSR, sSA},/* INIT in sCL Big TODO */
4489 +/* init_ack     */ {sIV, sCL, sCW, sCE, sES, sSS, sSR, sSA},
4490 +/* abort        */ {sIV, sCL, sCL, sCL, sCL, sCL, sCL, sCL},
4491 +/* shutdown     */ {sIV, sCL, sCW, sCE, sSR, sSS, sSR, sSA},
4492 +/* shutdown_ack */ {sIV, sCL, sCW, sCE, sES, sSA, sSA, sSA},
4493 +/* error        */ {sIV, sCL, sCW, sCL, sES, sSS, sSR, sSA},
4494 +/* cookie_echo  */ {sIV, sCL, sCW, sCE, sES, sSS, sSR, sSA},/* Cant come in reply dir */
4495 +/* cookie_ack   */ {sIV, sCL, sCW, sES, sES, sSS, sSR, sSA},
4496 +/* shutdown_comp*/ {sIV, sCL, sCW, sCE, sES, sSS, sSR, sCL}
4497 +       }
4498 +};
4499 +
4500 +static int sctp_pkt_to_tuple(const struct sk_buff *skb,
4501 +                            unsigned int dataoff,
4502 +                            struct ip_conntrack_tuple *tuple)
4503 +{
4504 +       sctp_sctphdr_t hdr;
4505 +
4506 +       DEBUGP(__FUNCTION__);
4507 +       DEBUGP("\n");
4508 +
4509 +       /* Actually only need first 8 bytes. */
4510 +       if (skb_copy_bits(skb, dataoff, &hdr, 8) != 0)
4511 +               return 0;
4512 +
4513 +       tuple->src.u.sctp.port = hdr.source;
4514 +       tuple->dst.u.sctp.port = hdr.dest;
4515 +
4516 +       return 1;
4517 +}
4518 +
4519 +static int sctp_invert_tuple(struct ip_conntrack_tuple *tuple,
4520 +                            const struct ip_conntrack_tuple *orig)
4521 +{
4522 +       DEBUGP(__FUNCTION__);
4523 +       DEBUGP("\n");
4524 +
4525 +       tuple->src.u.sctp.port = orig->dst.u.sctp.port;
4526 +       tuple->dst.u.sctp.port = orig->src.u.sctp.port;
4527 +       return 1;
4528 +}
4529 +
4530 +/* Print out the per-protocol part of the tuple. */
4531 +static unsigned int sctp_print_tuple(char *buffer,
4532 +                                    const struct ip_conntrack_tuple *tuple)
4533 +{
4534 +       DEBUGP(__FUNCTION__);
4535 +       DEBUGP("\n");
4536 +
4537 +       return sprintf(buffer, "sport=%hu dport=%hu ",
4538 +                      ntohs(tuple->src.u.sctp.port),
4539 +                      ntohs(tuple->dst.u.sctp.port));
4540 +}
4541 +
4542 +/* Print out the private part of the conntrack. */
4543 +static unsigned int sctp_print_conntrack(char *buffer,
4544 +                                        const struct ip_conntrack *conntrack)
4545 +{
4546 +       enum sctp_conntrack state;
4547 +
4548 +       DEBUGP(__FUNCTION__);
4549 +       DEBUGP("\n");
4550 +
4551 +       READ_LOCK(&sctp_lock);
4552 +       state = conntrack->proto.sctp.state;
4553 +       READ_UNLOCK(&sctp_lock);
4554 +
4555 +       return sprintf(buffer, "%s ", sctp_conntrack_names[state]);
4556 +}
4557 +
4558 +#define for_each_sctp_chunk(skb, sch, offset, count)   \
4559 +for (offset = skb->nh.iph->ihl * 4 + sizeof (sctp_sctphdr_t), count = 0;       \
4560 +       offset < skb->len && !skb_copy_bits(skb, offset, &sch, sizeof(sch));    \
4561 +       offset += (htons(sch.length) + 3) & ~3, count++)
4562 +
4563 +/* Some validity checks to make sure the chunks are fine */
4564 +static int do_basic_checks(struct ip_conntrack *conntrack,
4565 +                          const struct sk_buff *skb,
4566 +                          char *map)
4567 +{
4568 +       u_int32_t offset, count;
4569 +       sctp_chunkhdr_t sch;
4570 +       int flag;
4571 +
4572 +       DEBUGP(__FUNCTION__);
4573 +       DEBUGP("\n");
4574 +
4575 +       flag = 0;
4576 +
4577 +       for_each_sctp_chunk (skb, sch, offset, count) {
4578 +               DEBUGP("Chunk Num: %d  Type: %d\n", count, sch.type);
4579 +
4580 +               if (sch.type == SCTP_CID_INIT 
4581 +                       || sch.type == SCTP_CID_INIT_ACK
4582 +                       || sch.type == SCTP_CID_SHUTDOWN_COMPLETE) {
4583 +                       flag = 1;
4584 +               }
4585 +
4586 +               /* Cookie Ack/Echo chunks not the first OR 
4587 +                  Init / Init Ack / Shutdown compl chunks not the only chunks */
4588 +               if ((sch.type == SCTP_CID_COOKIE_ACK 
4589 +                       || sch.type == SCTP_CID_COOKIE_ECHO
4590 +                       || flag)
4591 +                    && count !=0 ) {
4592 +                       DEBUGP("Basic checks failed\n");
4593 +                       return 1;
4594 +               }
4595 +
4596 +               if (map) {
4597 +                       set_bit (sch.type, (void *)map);
4598 +               }
4599 +       }
4600 +
4601 +       DEBUGP("Basic checks passed\n");
4602 +       return 0;
4603 +}
4604 +
4605 +static int new_state(enum ip_conntrack_dir dir,
4606 +                    enum sctp_conntrack cur_state,
4607 +                    int chunk_type)
4608 +{
4609 +       int i;
4610 +
4611 +       DEBUGP(__FUNCTION__);
4612 +       DEBUGP("\n");
4613 +
4614 +       DEBUGP("Chunk type: %d\n", chunk_type);
4615 +
4616 +       switch (chunk_type) {
4617 +               case SCTP_CID_INIT: 
4618 +                       DEBUGP("SCTP_CID_INIT\n");
4619 +                       i = 0; break;
4620 +               case SCTP_CID_INIT_ACK: 
4621 +                       DEBUGP("SCTP_CID_INIT_ACK\n");
4622 +                       i = 1; break;
4623 +               case SCTP_CID_ABORT: 
4624 +                       DEBUGP("SCTP_CID_ABORT\n");
4625 +                       i = 2; break;
4626 +               case SCTP_CID_SHUTDOWN: 
4627 +                       DEBUGP("SCTP_CID_SHUTDOWN\n");
4628 +                       i = 3; break;
4629 +               case SCTP_CID_SHUTDOWN_ACK: 
4630 +                       DEBUGP("SCTP_CID_SHUTDOWN_ACK\n");
4631 +                       i = 4; break;
4632 +               case SCTP_CID_ERROR: 
4633 +                       DEBUGP("SCTP_CID_ERROR\n");
4634 +                       i = 5; break;
4635 +               case SCTP_CID_COOKIE_ECHO: 
4636 +                       DEBUGP("SCTP_CID_COOKIE_ECHO\n");
4637 +                       i = 6; break;
4638 +               case SCTP_CID_COOKIE_ACK: 
4639 +                       DEBUGP("SCTP_CID_COOKIE_ACK\n");
4640 +                       i = 7; break;
4641 +               case SCTP_CID_SHUTDOWN_COMPLETE: 
4642 +                       DEBUGP("SCTP_CID_SHUTDOWN_COMPLETE\n");
4643 +                       i = 8; break;
4644 +               default:
4645 +                       /* Other chunks like DATA, SACK, HEARTBEAT and
4646 +                       its ACK do not cause a change in state */
4647 +                       DEBUGP("Unknown chunk type, Will stay in %s\n", 
4648 +                                               sctp_conntrack_names[cur_state]);
4649 +                       return cur_state;
4650 +       }
4651 +
4652 +       DEBUGP("dir: %d   cur_state: %s  chunk_type: %d  new_state: %s\n", 
4653 +                       dir, sctp_conntrack_names[cur_state], chunk_type,
4654 +                       sctp_conntrack_names[sctp_conntracks[dir][i][cur_state]]);
4655 +
4656 +       return sctp_conntracks[dir][i][cur_state];
4657 +}
4658 +
4659 +/* Returns verdict for packet, or -1 for invalid. */
4660 +static int sctp_packet(struct ip_conntrack *conntrack,
4661 +                      const struct sk_buff *skb,
4662 +                      enum ip_conntrack_info ctinfo)
4663 +{
4664 +       enum sctp_conntrack newconntrack, oldsctpstate;
4665 +       sctp_sctphdr_t sctph;
4666 +       sctp_chunkhdr_t sch;
4667 +       u_int32_t offset, count;
4668 +       char map[256 / sizeof (char)] = {0};
4669 +
4670 +       DEBUGP(__FUNCTION__);
4671 +       DEBUGP("\n");
4672 +
4673 +       if (skb_copy_bits(skb, skb->nh.iph->ihl * 4, &sctph, sizeof(sctph)) != 0)
4674 +               return -1;
4675 +
4676 +       if (do_basic_checks(conntrack, skb, map) != 0)
4677 +               return -1;
4678 +
4679 +       /* Check the verification tag (Sec 8.5) */
4680 +       if (!test_bit(SCTP_CID_INIT, (void *)map)
4681 +               && !test_bit(SCTP_CID_SHUTDOWN_COMPLETE, (void *)map)
4682 +               && !test_bit(SCTP_CID_COOKIE_ECHO, (void *)map)
4683 +               && !test_bit(SCTP_CID_ABORT, (void *)map)
4684 +               && !test_bit(SCTP_CID_SHUTDOWN_ACK, (void *)map)
4685 +               && (sctph.vtag != conntrack->proto.sctp.vtag[CTINFO2DIR(ctinfo)])) {
4686 +               DEBUGP("Verification tag check failed\n");
4687 +               return -1;
4688 +       }
4689 +
4690 +       oldsctpstate = newconntrack = SCTP_CONNTRACK_MAX;
4691 +       for_each_sctp_chunk (skb, sch, offset, count) {
4692 +               WRITE_LOCK(&sctp_lock);
4693 +
4694 +               /* Special cases of Verification tag check (Sec 8.5.1) */
4695 +               if (sch.type == SCTP_CID_INIT) {
4696 +                       /* Sec 8.5.1 (A) */
4697 +                       if (sctph.vtag != 0) {
4698 +                               WRITE_UNLOCK(&sctp_lock);
4699 +                               return -1;
4700 +                       }
4701 +               } else if (sch.type == SCTP_CID_ABORT) {
4702 +                       /* Sec 8.5.1 (B) */
4703 +                       if (!(sctph.vtag == conntrack->proto.sctp.vtag[CTINFO2DIR(ctinfo)])
4704 +                               && !(sctph.vtag == conntrack->proto.sctp.vtag
4705 +                                                       [1 - CTINFO2DIR(ctinfo)])) {
4706 +                               WRITE_UNLOCK(&sctp_lock);
4707 +                               return -1;
4708 +                       }
4709 +               } else if (sch.type == SCTP_CID_SHUTDOWN_COMPLETE) {
4710 +                       /* Sec 8.5.1 (C) */
4711 +                       if (!(sctph.vtag == conntrack->proto.sctp.vtag[CTINFO2DIR(ctinfo)])
4712 +                               && !(sctph.vtag == conntrack->proto.sctp.vtag
4713 +                                                       [1 - CTINFO2DIR(ctinfo)] 
4714 +                                       && (sch.flags & 1))) {
4715 +                               WRITE_UNLOCK(&sctp_lock);
4716 +                               return -1;
4717 +                       }
4718 +               } else if (sch.type == SCTP_CID_COOKIE_ECHO) {
4719 +                       /* Sec 8.5.1 (D) */
4720 +                       if (!(sctph.vtag == conntrack->proto.sctp.vtag[CTINFO2DIR(ctinfo)])) {
4721 +                               WRITE_UNLOCK(&sctp_lock);
4722 +                               return -1;
4723 +                       }
4724 +               }
4725 +
4726 +               oldsctpstate = conntrack->proto.sctp.state;
4727 +               newconntrack = new_state(CTINFO2DIR(ctinfo), oldsctpstate, sch.type);
4728 +
4729 +               /* Invalid */
4730 +               if (newconntrack == SCTP_CONNTRACK_MAX) {
4731 +                       DEBUGP("ip_conntrack_sctp: Invalid dir=%i ctype=%u conntrack=%u\n",
4732 +                              CTINFO2DIR(ctinfo), sch.type, oldsctpstate);
4733 +                       WRITE_UNLOCK(&sctp_lock);
4734 +                       return -1;
4735 +               }
4736 +
4737 +               /* If it is an INIT or an INIT ACK note down the vtag */
4738 +               if (sch.type == SCTP_CID_INIT 
4739 +                       || sch.type == SCTP_CID_INIT_ACK) {
4740 +                       sctp_inithdr_t inithdr;
4741 +
4742 +                       if (skb_copy_bits(skb, offset + sizeof (sctp_chunkhdr_t),
4743 +                               &inithdr, sizeof(inithdr)) != 0) {
4744 +                                       WRITE_UNLOCK(&sctp_lock);
4745 +                                       return -1;
4746 +                       }
4747 +                       DEBUGP("Setting vtag %x for dir %d\n", 
4748 +                                       inithdr.init_tag, CTINFO2DIR(ctinfo));
4749 +                       conntrack->proto.sctp.vtag[IP_CT_DIR_ORIGINAL] = inithdr.init_tag;
4750 +               }
4751 +
4752 +               conntrack->proto.sctp.state = newconntrack;
4753 +               WRITE_UNLOCK(&sctp_lock);
4754 +       }
4755 +
4756 +       ip_ct_refresh(conntrack, *sctp_timeouts[newconntrack]);
4757 +
4758 +       if (oldsctpstate == SCTP_CONNTRACK_COOKIE_ECHOED
4759 +               && CTINFO2DIR(ctinfo) == IP_CT_DIR_REPLY
4760 +               && newconntrack == SCTP_CONNTRACK_ESTABLISHED) {
4761 +               DEBUGP("Setting assured bit\n");
4762 +               set_bit(IPS_ASSURED_BIT, &conntrack->status);
4763 +       }
4764 +
4765 +       return NF_ACCEPT;
4766 +}
4767 +
4768 +/* Called when a new connection for this protocol found. */
4769 +static int sctp_new(struct ip_conntrack *conntrack, 
4770 +                   const struct sk_buff *skb)
4771 +{
4772 +       enum sctp_conntrack newconntrack;
4773 +       sctp_sctphdr_t sctph;
4774 +       sctp_chunkhdr_t sch;
4775 +       u_int32_t offset, count;
4776 +       char map[256 / sizeof (char)] = {0};
4777 +
4778 +       DEBUGP(__FUNCTION__);
4779 +       DEBUGP("\n");
4780 +
4781 +       if (skb_copy_bits(skb, skb->nh.iph->ihl * 4, &sctph, sizeof(sctph)) != 0)
4782 +               return -1;
4783 +
4784 +       if (do_basic_checks(conntrack, skb, map) != 0)
4785 +               return -1;
4786 +
4787 +       /* If an OOTB packet has any of these chunks discard (Sec 8.4) */
4788 +       if ((test_bit (SCTP_CID_ABORT, (void *)map))
4789 +               || (test_bit (SCTP_CID_SHUTDOWN_COMPLETE, (void *)map))
4790 +               || (test_bit (SCTP_CID_COOKIE_ACK, (void *)map))) {
4791 +               return -1;
4792 +       }
4793 +
4794 +       newconntrack = SCTP_CONNTRACK_MAX;
4795 +       for_each_sctp_chunk (skb, sch, offset, count) {
4796 +               /* Don't need lock here: this conntrack not in circulation yet */
4797 +               newconntrack = new_state (IP_CT_DIR_ORIGINAL, 
4798 +                                               SCTP_CONNTRACK_NONE, sch.type);
4799 +
4800 +               /* Invalid: delete conntrack */
4801 +               if (newconntrack == SCTP_CONNTRACK_MAX) {
4802 +                       DEBUGP("ip_conntrack_sctp: invalid new deleting.\n");
4803 +                       return 0;
4804 +               }
4805 +
4806 +               /* Copy the vtag into the state info */
4807 +               if (sch.type == SCTP_CID_INIT) {
4808 +                       if (sctph.vtag == 0) {
4809 +                               sctp_inithdr_t inithdr;
4810 +
4811 +                               if (skb_copy_bits(skb, offset + sizeof (sctp_chunkhdr_t), 
4812 +                                       &inithdr, sizeof(inithdr)) != 0) {
4813 +                                               return -1;
4814 +                               }
4815 +
4816 +                               DEBUGP("Setting vtag %x for new conn\n", 
4817 +                                       inithdr.init_tag);
4818 +
4819 +                               conntrack->proto.sctp.vtag[IP_CT_DIR_REPLY] = 
4820 +                                                               inithdr.init_tag;
4821 +                       } else {
4822 +                               /* Sec 8.5.1 (A) */
4823 +                               return -1;
4824 +                       }
4825 +               }
4826 +               /* If it is a shutdown ack OOTB packet, we expect a return
4827 +                  shutdown complete, otherwise an ABORT Sec 8.4 (5) and (8) */
4828 +               else {
4829 +                       DEBUGP("Setting vtag %x for new conn OOTB\n", 
4830 +                               sctph.vtag);
4831 +                       conntrack->proto.sctp.vtag[IP_CT_DIR_REPLY] = sctph.vtag;
4832 +               }
4833 +
4834 +               conntrack->proto.sctp.state = newconntrack;
4835 +       }
4836 +
4837 +       return 1;
4838 +}
4839 +
4840 +static int sctp_exp_matches_pkt(struct ip_conntrack_expect *exp,
4841 +                               const struct sk_buff *skb)
4842 +{
4843 +       /* To be implemented */
4844 +       return 0;
4845 +}
4846 +
4847 +struct ip_conntrack_protocol ip_conntrack_protocol_sctp = { 
4848 +       .list            = { NULL, NULL }, 
4849 +       .proto           = IPPROTO_SCTP, 
4850 +       .name            = "sctp",
4851 +       .pkt_to_tuple    = sctp_pkt_to_tuple, 
4852 +       .invert_tuple    = sctp_invert_tuple, 
4853 +       .print_tuple     = sctp_print_tuple, 
4854 +       .print_conntrack = sctp_print_conntrack,
4855 +       .packet          = sctp_packet, 
4856 +       .new             = sctp_new, 
4857 +       .destroy         = NULL, 
4858 +       .exp_matches_pkt = sctp_exp_matches_pkt, 
4859 +       .me              = THIS_MODULE 
4860 +};
4861 +
4862 +int __init init(void)
4863 +{
4864 +       int ret;
4865 +
4866 +       ret = ip_conntrack_protocol_register(&ip_conntrack_protocol_sctp);
4867 +       DEBUGP("SCTP conntrack module loading %s\n", 
4868 +                                       ret ? "failed": "succeeded");
4869 +       return ret;
4870 +}
4871 +
4872 +void __exit fini(void)
4873 +{
4874 +       ip_conntrack_protocol_unregister(&ip_conntrack_protocol_sctp);
4875 +       DEBUGP("SCTP conntrack module unloaded\n");
4876 +}
4877 +
4878 +module_init(init);
4879 +module_exit(fini);
4880 +
4881 +MODULE_LICENSE("GPL");
4882 +MODULE_AUTHOR("Kiran Kumar Immidi");
4883 +MODULE_DESCRIPTION("Netfilter connection tracking protocol helper for SCTP");
4884 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ip_conntrack_quake3.c linux-2.6.6/net/ipv4/netfilter/ip_conntrack_quake3.c
4885 --- linux-2.6.6.org/net/ipv4/netfilter/ip_conntrack_quake3.c    1970-01-01 01:00:00.000000000 +0100
4886 +++ linux-2.6.6/net/ipv4/netfilter/ip_conntrack_quake3.c        2004-05-18 14:28:50.000000000 +0200
4887 @@ -0,0 +1,156 @@
4888 +/* Quake3 extension for IP connection tracking
4889 + * (C) 2002 by Filip Sneppe <filip.sneppe@cronos.be>
4890 + * based on ip_conntrack_ftp.c and ip_conntrack_tftp.c
4891 + *
4892 + * ip_conntrack_quake3.c v0.04 2002-08-31
4893 + *
4894 + *      This program is free software; you can redistribute it and/or
4895 + *      modify it under the terms of the GNU General Public License
4896 + *      as published by the Free Software Foundation; either version
4897 + *      2 of the License, or (at your option) any later version.
4898 + *
4899 + *      Module load syntax:
4900 + *      insmod ip_conntrack_quake3.o ports=port1,port2,...port<MAX_PORTS>
4901 + *
4902 + *      please give the ports of all Quake3 master servers You wish to 
4903 + *      connect to. If you don't specify ports, the default will be UDP 
4904 + *      port 27950.
4905 + *
4906 + *      Thanks to the Ethereal folks for their analysis of the Quake3 protocol.
4907 + */
4908 +
4909 +#include <linux/module.h>
4910 +#include <linux/ip.h>
4911 +#include <linux/udp.h>
4912 +
4913 +#include <linux/netfilter.h>
4914 +#include <linux/netfilter_ipv4/ip_tables.h>
4915 +#include <linux/netfilter_ipv4/ip_conntrack_helper.h>
4916 +#include <linux/netfilter_ipv4/ip_conntrack_quake3.h>
4917 +
4918 +struct module *ip_conntrack_quake3 = THIS_MODULE;
4919 +
4920 +MODULE_AUTHOR("Filip Sneppe <filip.sneppe@cronos.be>");
4921 +MODULE_DESCRIPTION("Netfilter connection tracking module for Quake III Arena");
4922 +MODULE_LICENSE("GPL");
4923 +
4924 +#define MAX_PORTS 8
4925 +static int ports[MAX_PORTS];
4926 +static int ports_c = 0;
4927 +#ifdef MODULE_PARM
4928 +MODULE_PARM(ports, "1-" __MODULE_STRING(MAX_PORTS) "i");
4929 +MODULE_PARM_DESC(ports, "port numbers of Quake III master servers");
4930 +#endif
4931 +
4932 +/* Quake3 master server reply will add > 100 expectations per reply packet; when
4933 +   doing lots of printk's, klogd may not be able to read /proc/kmsg fast enough */
4934 +#if 0 
4935 +#define DEBUGP printk
4936 +#else
4937 +#define DEBUGP(format, args...)
4938 +#endif
4939 +
4940 +struct quake3_search quake3s_conntrack = { "****", "getserversResponse", sizeof("getserversResponse") - 1 };
4941 +
4942 +static int quake3_help(const struct iphdr *iph, size_t len,
4943 +       struct ip_conntrack *ct,
4944 +       enum ip_conntrack_info ctinfo)
4945 +{
4946 +       struct udphdr *udph = (void *)iph + iph->ihl * 4;
4947 +       int dir = CTINFO2DIR(ctinfo);
4948 +       struct ip_conntrack_expect exp;
4949 +       int i;
4950 +       
4951 +        /* Until there's been traffic both ways, don't look in packets. note: it's UDP ! */
4952 +       if (ctinfo != IP_CT_ESTABLISHED
4953 +           && ctinfo != IP_CT_IS_REPLY) {
4954 +               DEBUGP("ip_conntrack_quake3: not ok ! Conntrackinfo = %u\n", ctinfo);
4955 +               return NF_ACCEPT;
4956 +       } else { DEBUGP("ip_conntrack_quake3: it's ok ! Conntrackinfo = %u\n", ctinfo); }
4957 +       
4958 +       if (strnicmp((const char *)udph + 12, quake3s_conntrack.pattern, quake3s_conntrack.plen) == 0) {
4959 +               for(i=31;    /* 8 bytes UDP hdr, 4 bytes filler, 18 bytes "getserversResponse", 1 byte "\" */
4960 +                   i+6 < ntohs(udph->len);
4961 +                   i+=7) {
4962 +                       DEBUGP("ip_conntrack_quake3: adding server at offset %u/%u %u.%u.%u.%u:%u\n",
4963 +                              i, ntohs(udph->len),
4964 +                              NIPQUAD( (u_int32_t) *( (u_int32_t *)( (int)udph + i ) ) ), 
4965 +                              ntohs((__u16) *( (__u16 *)( (int)udph + i + 4 ) ) ) );
4966 +
4967 +                       memset(&exp, 0, sizeof(exp));
4968 +
4969 +                       exp.tuple = ((struct ip_conntrack_tuple)
4970 +                                    { { ct->tuplehash[!dir].tuple.src.ip, { 0 } },
4971 +                                      { (u_int32_t) *((u_int32_t *)((int)udph + i)), 
4972 +                                      { .udp = { (__u16) *((__u16 *)((int)udph+i+4)) } }, 
4973 +                                        IPPROTO_UDP } }
4974 +                                   );
4975 +                       exp.mask  = ((struct ip_conntrack_tuple)
4976 +                                    { { 0xFFFFFFFF, { 0 } },
4977 +                                      { 0xFFFFFFFF, { .udp = { 0xFFFF } }, 0xFFFF }});
4978 +                       exp.expectfn = NULL;
4979 +
4980 +                       ip_conntrack_expect_related(ct, &exp);
4981 +               }
4982 +
4983 +       }
4984 +       
4985 +       return(NF_ACCEPT);
4986 +}
4987 +
4988 +static struct ip_conntrack_helper quake3[MAX_PORTS];
4989 +static char quake3_names[MAX_PORTS][13];  /* quake3-65535 */
4990 +
4991 +static void fini(void)
4992 +{
4993 +       int i;
4994 +
4995 +       for(i = 0 ; (i < ports_c); i++) {
4996 +               DEBUGP("ip_conntrack_quake3: unregistering helper for port %d\n",
4997 +                                       ports[i]);
4998 +               ip_conntrack_helper_unregister(&quake3[i]);
4999 +       } 
5000 +}
5001 +
5002 +static int __init init(void)
5003 +{
5004 +       int i, ret;
5005 +       char *tmpname;
5006 +
5007 +       if(!ports[0])
5008 +               ports[0]=QUAKE3_MASTER_PORT;
5009 +
5010 +       for(i = 0 ; (i < MAX_PORTS) && ports[i] ; i++) {
5011 +               /* Create helper structure */
5012 +               memset(&quake3[i], 0, sizeof(struct ip_conntrack_helper));
5013 +
5014 +               quake3[i].tuple.dst.protonum = IPPROTO_UDP;
5015 +               quake3[i].tuple.src.u.udp.port = htons(ports[i]);
5016 +               quake3[i].mask.dst.protonum = 0xFFFF;
5017 +               quake3[i].mask.src.u.udp.port = 0xFFFF;
5018 +               quake3[i].help = quake3_help;
5019 +               quake3[i].me = THIS_MODULE;
5020 +
5021 +               tmpname = &quake3_names[i][0];
5022 +               if (ports[i] == QUAKE3_MASTER_PORT)
5023 +                       sprintf(tmpname, "quake3");
5024 +               else
5025 +                       sprintf(tmpname, "quake3-%d", i);
5026 +               quake3[i].name = tmpname;
5027 +               
5028 +               DEBUGP("ip_conntrack_quake3: registering helper for port %d\n",
5029 +                      ports[i]);
5030 +
5031 +               ret=ip_conntrack_helper_register(&quake3[i]);
5032 +               if(ret) {
5033 +                       fini();
5034 +                       return(ret);
5035 +               }
5036 +               ports_c++;
5037 +       }
5038 +
5039 +       return(0);
5040 +}
5041 +
5042 +module_init(init);
5043 +module_exit(fini);
5044 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ip_conntrack_rsh.c linux-2.6.6/net/ipv4/netfilter/ip_conntrack_rsh.c
5045 --- linux-2.6.6.org/net/ipv4/netfilter/ip_conntrack_rsh.c       1970-01-01 01:00:00.000000000 +0100
5046 +++ linux-2.6.6/net/ipv4/netfilter/ip_conntrack_rsh.c   2004-05-18 14:28:50.000000000 +0200
5047 @@ -0,0 +1,331 @@
5048 +/* RSH extension for IP connection tracking, Version 1.0
5049 + * (C) 2002 by Ian (Larry) Latter <Ian.Latter@mq.edu.au>
5050 + * based on HW's ip_conntrack_irc.c    
5051 + *
5052 + * ip_conntrack_rsh.c,v 1.0 2002/07/17 14:49:26
5053 + *
5054 + *      This program is free software; you can redistribute it and/or
5055 + *      modify it under the terms of the GNU General Public License
5056 + *      as published by the Free Software Foundation; either version
5057 + *      2 of the License, or (at your option) any later version.
5058 + **
5059 + *     Module load syntax:
5060 + *     insmod ip_conntrack_rsh.o ports=port1,port2,...port<MAX_PORTS>
5061 + *     
5062 + *     please give the ports of all RSH servers You wish to connect to.
5063 + *     If You don't specify ports, the default will be port 514
5064 + **
5065 + *      Note to all:
5066 + *        RSH blows ... you should use SSH (openssh.org) to replace it,
5067 + *        unfortunately I babysit some sysadmins that won't migrate
5068 + *       their legacy crap, in our second tier.
5069 + */
5070 +
5071 +
5072 +/*
5073 + *  Some docco ripped from the net to teach me all there is to know about
5074 + *  RSH, in 16.5 seconds (ie, all of the non-netfilter docco used to write
5075 + *  this module).
5076 + *
5077 + *  I have no idea what "unix rshd man pages" these guys have .. but that
5078 + *  is some pretty detailed docco!
5079 + **
5080 + *
5081 + *  4. Of the rsh protocol.
5082 + *  -----------------------
5083 + * 
5084 + *   The rshd listens on TCP port #514. The following info is from the unix
5085 + *   rshd man pages :
5086 + * 
5087 + *   "Service Request Protocol
5088 + * 
5089 + *    When the rshd daemon receives a service request, it initiates the
5090 + *    following protocol:
5091 + * 
5092 + *     1. The rshd daemon checks the source port number for the request.
5093 + *        If the port number is not in the range 0 through 1023, the rshd daemon
5094 + *        terminates the connection.
5095 + * 
5096 + *     2. The rshd daemon reads characters from the socket up to a null byte.
5097 + *        The string read is interpreted as an ASCII number (base 10). If this
5098 + *        number is nonzero, the rshd daemon interprets it as the port number
5099 + *        of a secondary stream to be used as standard error. A second connection
5100 + *        is created to the specified port on the client host. The source port
5101 + *        on the local host is in the range 0 through 1023.
5102 + * 
5103 + *     3. The rshd daemon uses the source address of the initial connection
5104 + *        request to determine the name of the client host. If the name cannot
5105 + *        be determined, the rshd daemon uses the dotted decimal representation
5106 + *        of the client host's address.
5107 + * 
5108 + *     4. The rshd daemon retrieves the following information from the initial
5109 + *        socket:
5110 + * 
5111 + *         * A null-terminated string of at most 16 bytes interpreted as
5112 + *           the user name of the user on the client host.
5113 + * 
5114 + *         * A null-terminated string of at most 16 bytes interpreted as
5115 + *           the user name to be used on the local server host.
5116 + * 
5117 + *         * Another null-terminated string interpreted as a command line
5118 + *           to be passed to a shell on the local server host.
5119 + * 
5120 + *     5. The rshd daemon attempts to validate the user using the following steps:
5121 + * 
5122 + *         a. The rshd daemon looks up the local user name in the /etc/passwd
5123 + *            file and tries to switch to the home directory (using the chdir
5124 + *            subroutine). If either the lookup or the directory change fails,
5125 + *            the rshd daemon terminates the connection.
5126 + * 
5127 + *         b. If the local user ID is a nonzero value, the rshd daemon searches
5128 + *            the /etc/hosts.equiv file to see if the name of the client
5129 + *            workstation is listed. If the client workstation is listed as an
5130 + *            equivalent host, the rshd daemon validates the user.
5131 + * 
5132 + *         c. If the $HOME/.rhosts file exists, the rshd daemon tries to
5133 + *            authenticate the user by checking the .rhosts file.
5134 + * 
5135 + *         d. If either the $HOME/.rhosts authentication fails or the
5136 + *            client host is not an equivalent host, the rshd daemon
5137 + *            terminates the connection.
5138 + * 
5139 + *     6. Once rshd validates the user, the rshd daemon returns a null byte
5140 + *        on the initial connection and passes the command line to the user's
5141 + *        local login shell. The shell then inherits the network connections
5142 + *        established by the rshd daemon."
5143 + * 
5144 + */
5145 +
5146 +
5147 +#include <linux/module.h>
5148 +#include <linux/netfilter.h>
5149 +#include <linux/ip.h>
5150 +#include <net/checksum.h>
5151 +#include <net/tcp.h>
5152 +
5153 +#include <linux/netfilter_ipv4/lockhelp.h>
5154 +#include <linux/netfilter_ipv4/ip_tables.h>
5155 +#include <linux/netfilter_ipv4/ip_conntrack_helper.h>
5156 +#include <linux/netfilter_ipv4/ip_conntrack_rsh.h>
5157 +
5158 +#define MAX_PORTS 8
5159 +static int ports[MAX_PORTS];
5160 +static int ports_n_c = 0;
5161 +
5162 +MODULE_AUTHOR("Ian (Larry) Latter <Ian.Latter@mq.edu.au>");
5163 +MODULE_DESCRIPTION("RSH connection tracking module");
5164 +MODULE_LICENSE("GPL");
5165 +#ifdef MODULE_PARM
5166 +MODULE_PARM(ports, "1-" __MODULE_STRING(MAX_PORTS) "i");
5167 +MODULE_PARM_DESC(ports, "port numbers of RSH servers");
5168 +#endif
5169 +
5170 +DECLARE_LOCK(ip_rsh_lock);
5171 +struct module *ip_conntrack_rsh = THIS_MODULE;
5172 +
5173 +#if 0
5174 +#define DEBUGP(format, args...) printk(KERN_DEBUG "ip_conntrack_rsh: " \
5175 +                                       format, ## args)
5176 +#else
5177 +#define DEBUGP(format, args...)
5178 +#endif
5179 +
5180 +
5181 +
5182 +/* FIXME: This should be in userspace.  Later. */
5183 +static int help(const struct iphdr *iph, size_t len,
5184 +               struct ip_conntrack *ct, enum ip_conntrack_info ctinfo)
5185 +{
5186 +       /* tcplen not negative guarenteed by ip_conntrack_tcp.c */
5187 +       struct tcphdr *tcph = (void *) iph + iph->ihl * 4;
5188 +       const char *data = (const char *) tcph + tcph->doff * 4;
5189 +       u_int32_t tcplen = len - iph->ihl * 4;
5190 +       int dir = CTINFO2DIR(ctinfo);
5191 +        struct ip_conntrack_expect expect, *exp = &expect;
5192 +        struct ip_ct_rsh_expect *exp_rsh_info = &exp->help.exp_rsh_info;
5193 +       u_int16_t port;
5194 +       int maxoctet;
5195 +
5196 +       /*  note that "maxoctet" is used to maintain sanity (8 was the
5197 +        *  original array size used in rshd/glibc) -- is there a
5198 +        *  vulnerability in rshd.c in the looped port *= 10?
5199 +        */
5200 +
5201 +
5202 +       DEBUGP("entered\n");
5203 +
5204 +       /* bail if packet is not from RSH client */
5205 +       if (dir == IP_CT_DIR_REPLY)
5206 +               return NF_ACCEPT;
5207 +
5208 +       /* Until there's been traffic both ways, don't look in packets. */
5209 +       if (ctinfo != IP_CT_ESTABLISHED
5210 +           && ctinfo != IP_CT_ESTABLISHED + IP_CT_IS_REPLY) {
5211 +               DEBUGP("Conntrackinfo = %u\n", ctinfo);
5212 +               return NF_ACCEPT;
5213 +       }
5214 +
5215 +       /* Not whole TCP header? */
5216 +       if (tcplen < sizeof(struct tcphdr) || tcplen < tcph->doff * 4) {
5217 +               DEBUGP("tcplen = %u\n", (unsigned) tcplen);
5218 +               return NF_ACCEPT;
5219 +       }
5220 +
5221 +       /* Checksum invalid?  Ignore. */
5222 +       /* FIXME: Source route IP option packets --RR */
5223 +       if (tcp_v4_check(tcph, tcplen, iph->saddr, iph->daddr,
5224 +                        csum_partial((char *) tcph, tcplen, 0))) {
5225 +               DEBUGP("bad csum: %p %u %u.%u.%u.%u %u.%u.%u.%u\n",
5226 +                    tcph, tcplen, NIPQUAD(iph->saddr),
5227 +                    NIPQUAD(iph->daddr));
5228 +               return NF_ACCEPT;
5229 +       }
5230 +
5231 +       /* find the rsh stderr port */
5232 +       maxoctet = 4;
5233 +       port = 0;
5234 +       for ( ; *data != 0 && maxoctet != 0; data++, maxoctet--) {
5235 +               if (*data < 0)
5236 +                       return(1);
5237 +               if (*data == 0)
5238 +                       break;
5239 +               if (*data < 48 || *data > 57) {
5240 +                       DEBUGP("these aren't the packets you're looking for ..\n");
5241 +                       return NF_ACCEPT;
5242 +               }
5243 +               port = port * 10 + ( *data - 48 );
5244 +       }
5245 +
5246 +       /* dont relate sessions that try to expose the client */
5247 +       DEBUGP("found port %u\n", port);
5248 +       if (port > 1023) {
5249 +               DEBUGP("skipping, expected port size is greater than 1023!\n");
5250 +               return NF_ACCEPT;
5251 +       }
5252 +
5253 +
5254 +       LOCK_BH(&ip_rsh_lock);
5255 +
5256 +       /*  new(,related) connection is;
5257 +        *          reply + dst (uint)port + src port (0:1023)
5258 +        */
5259 +       memset(&expect, 0, sizeof(expect));
5260 +
5261 +       /*  save some discovered data, in case someone ever wants to write
5262 +        *  a NAT module for this bastard ..
5263 +        */
5264 +       exp_rsh_info->port = port;
5265 +
5266 +       DEBUGP("wrote info port=%u\n", exp_rsh_info->port);
5267 +
5268 +
5269 +       /* Watch out, Radioactive-Man! */
5270 +       exp->tuple.src.ip = ct->tuplehash[!dir].tuple.src.ip;
5271 +       exp->tuple.dst.ip = ct->tuplehash[!dir].tuple.dst.ip;
5272 +       exp->tuple.src.u.tcp.port = 0;
5273 +       exp->tuple.dst.u.tcp.port = htons(exp_rsh_info->port);
5274 +       exp->tuple.dst.protonum = IPPROTO_TCP;
5275 +
5276 +       exp->mask.src.ip = 0xffffffff;
5277 +       exp->mask.dst.ip = 0xffffffff;
5278 +
5279 +       exp->mask.src.u.tcp.port = htons(0xfc00);
5280 +       exp->mask.dst.u.tcp.port = htons(0xfc00);
5281 +       exp->mask.dst.protonum = 0xffff;
5282 +
5283 +       exp->expectfn = NULL;
5284 +
5285 +       ip_conntrack_expect_related(ct, &expect);
5286 +
5287 +       DEBUGP("expect related ip   %u.%u.%u.%u:%u-%u.%u.%u.%u:%u\n",
5288 +               NIPQUAD(exp->tuple.src.ip),
5289 +               ntohs(exp->tuple.src.u.tcp.port),
5290 +               NIPQUAD(exp->tuple.dst.ip),
5291 +               ntohs(exp->tuple.dst.u.tcp.port));
5292 +
5293 +       DEBUGP("expect related mask %u.%u.%u.%u:%u-%u.%u.%u.%u:%u\n",
5294 +               NIPQUAD(exp->mask.src.ip),
5295 +               ntohs(exp->mask.src.u.tcp.port),
5296 +               NIPQUAD(exp->mask.dst.ip),
5297 +               ntohs(exp->mask.dst.u.tcp.port));
5298 +       UNLOCK_BH(&ip_rsh_lock);
5299 +
5300 +       return NF_ACCEPT;
5301 +}
5302 +
5303 +static struct ip_conntrack_helper rsh_helpers[MAX_PORTS];
5304 +
5305 +static void fini(void);
5306 +
5307 +static int __init init(void)
5308 +{
5309 +       int port, ret;
5310 +       static char name[10];
5311 +
5312 +
5313 +       /* If no port given, default to standard RSH port */
5314 +       if (ports[0] == 0)
5315 +               ports[0] = RSH_PORT;
5316 +
5317 +       for (port = 0; (port < MAX_PORTS) && ports[port]; port++) {
5318 +               memset(&rsh_helpers[port], 0, sizeof(struct ip_conntrack_helper));
5319 +
5320 +                if (ports[port] == RSH_PORT)
5321 +                        sprintf(name, "rsh");
5322 +                else
5323 +                        sprintf(name, "rsh-%d", port);
5324 +
5325 +               rsh_helpers[port].name = name;
5326 +               rsh_helpers[port].me = THIS_MODULE;
5327 +               rsh_helpers[port].max_expected = 1;
5328 +               rsh_helpers[port].flags = IP_CT_HELPER_F_REUSE_EXPECT;
5329 +               rsh_helpers[port].timeout = 0;
5330 +
5331 +               rsh_helpers[port].tuple.dst.protonum = IPPROTO_TCP;
5332 +               rsh_helpers[port].mask.dst.protonum = 0xffff;
5333 +
5334 +               /* RSH must come from ports 0:1023 to ports[port] (514) */
5335 +               rsh_helpers[port].tuple.src.u.tcp.port = htons(ports[port]);
5336 +               rsh_helpers[port].mask.src.u.tcp.port = htons(0xfc00);
5337 +               rsh_helpers[port].mask.dst.u.tcp.port = htons(0xfc00);
5338 +
5339 +               rsh_helpers[port].help = help;
5340 +
5341 +               DEBUGP("registering helper for port #%d: %d/TCP\n", port, ports[port]);
5342 +               DEBUGP("helper match ip   %u.%u.%u.%u:%u-%u.%u.%u.%u:%u\n",
5343 +                       NIPQUAD(rsh_helpers[port].tuple.src.ip),
5344 +                       ntohs(rsh_helpers[port].tuple.src.u.tcp.port),
5345 +                       NIPQUAD(rsh_helpers[port].tuple.dst.ip),
5346 +                       ntohs(rsh_helpers[port].tuple.dst.u.tcp.port));
5347 +               DEBUGP("helper match mask %u.%u.%u.%u:%u-%u.%u.%u.%u:%u\n",
5348 +                       NIPQUAD(rsh_helpers[port].mask.src.ip),
5349 +                       ntohs(rsh_helpers[port].mask.src.u.tcp.port),
5350 +                       NIPQUAD(rsh_helpers[port].mask.dst.ip),
5351 +                       ntohs(rsh_helpers[port].mask.dst.u.tcp.port));
5352 +
5353 +               ret = ip_conntrack_helper_register(&rsh_helpers[port]);
5354 +
5355 +               if (ret) {
5356 +                       printk("ERROR registering port %d\n",
5357 +                               ports[port]);
5358 +                       fini();
5359 +                       return -EBUSY;
5360 +               }
5361 +               ports_n_c++;
5362 +       }
5363 +       return 0;
5364 +}
5365 +
5366 +/* This function is intentionally _NOT_ defined as __exit, because 
5367 + * it is needed by the init function */
5368 +static void fini(void)
5369 +{
5370 +       int port;
5371 +       for (port = 0; (port < MAX_PORTS) && ports[port]; port++) {
5372 +               DEBUGP("unregistering port %d\n", ports[port]);
5373 +               ip_conntrack_helper_unregister(&rsh_helpers[port]);
5374 +       }
5375 +}
5376 +
5377 +module_init(init);
5378 +module_exit(fini);
5379 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ip_conntrack_rtsp.c linux-2.6.6/net/ipv4/netfilter/ip_conntrack_rtsp.c
5380 --- linux-2.6.6.org/net/ipv4/netfilter/ip_conntrack_rtsp.c      1970-01-01 01:00:00.000000000 +0100
5381 +++ linux-2.6.6/net/ipv4/netfilter/ip_conntrack_rtsp.c  2004-05-18 14:28:50.000000000 +0200
5382 @@ -0,0 +1,507 @@
5383 +/*
5384 + * RTSP extension for IP connection tracking
5385 + * (C) 2003 by Tom Marshall <tmarshall@real.com>
5386 + * based on ip_conntrack_irc.c
5387 + *
5388 + *      This program is free software; you can redistribute it and/or
5389 + *      modify it under the terms of the GNU General Public License
5390 + *      as published by the Free Software Foundation; either version
5391 + *      2 of the License, or (at your option) any later version.
5392 + *
5393 + * Module load syntax:
5394 + *   insmod ip_conntrack_rtsp.o ports=port1,port2,...port<MAX_PORTS>
5395 + *                              max_outstanding=n setup_timeout=secs
5396 + *
5397 + * If no ports are specified, the default will be port 554.
5398 + *
5399 + * With max_outstanding you can define the maximum number of not yet
5400 + * answered SETUP requests per RTSP session (default 8).
5401 + * With setup_timeout you can specify how long the system waits for
5402 + * an expected data channel (default 300 seconds).
5403 + */
5404 +
5405 +#include <linux/config.h>
5406 +#include <linux/module.h>
5407 +#include <linux/netfilter.h>
5408 +#include <linux/ip.h>
5409 +#include <net/checksum.h>
5410 +#include <net/tcp.h>
5411 +
5412 +#include <linux/netfilter_ipv4/lockhelp.h>
5413 +#include <linux/netfilter_ipv4/ip_conntrack_helper.h>
5414 +#include <linux/netfilter_ipv4/ip_conntrack_rtsp.h>
5415 +
5416 +#include <linux/ctype.h>
5417 +#define NF_NEED_STRNCASECMP
5418 +#define NF_NEED_STRTOU16
5419 +#define NF_NEED_STRTOU32
5420 +#define NF_NEED_NEXTLINE
5421 +#include <linux/netfilter_helpers.h>
5422 +#define NF_NEED_MIME_NEXTLINE
5423 +#include <linux/netfilter_mime.h>
5424 +
5425 +#define MAX_SIMUL_SETUP 8 /* XXX: use max_outstanding */
5426 +
5427 +#define INFOP(fmt, args...) printk(KERN_INFO "%s: %s: " fmt, __FILE__, __FUNCTION__ , ## args)
5428 +#ifdef IP_NF_RTSP_DEBUG
5429 +#define DEBUGP(fmt, args...) printk(KERN_DEBUG "%s: %s: " fmt, __FILE__, __FUNCTION__ , ## args)
5430 +#else
5431 +#define DEBUGP(fmt, args...)
5432 +#endif
5433 +
5434 +#define MAX_PORTS 8
5435 +static int ports[MAX_PORTS];
5436 +static int num_ports = 0;
5437 +static int max_outstanding = 8;
5438 +static unsigned int setup_timeout = 300;
5439 +
5440 +MODULE_AUTHOR("Tom Marshall <tmarshall@real.com>");
5441 +MODULE_DESCRIPTION("RTSP connection tracking module");
5442 +MODULE_LICENSE("GPL");
5443 +#ifdef MODULE_PARM
5444 +MODULE_PARM(ports, "1-" __MODULE_STRING(MAX_PORTS) "i");
5445 +MODULE_PARM_DESC(ports, "port numbers of RTSP servers");
5446 +MODULE_PARM(max_outstanding, "i");
5447 +MODULE_PARM_DESC(max_outstanding, "max number of outstanding SETUP requests per RTSP session");
5448 +MODULE_PARM(setup_timeout, "i");
5449 +MODULE_PARM_DESC(setup_timeout, "timeout on for unestablished data channels");
5450 +#endif
5451 +
5452 +DECLARE_LOCK(ip_rtsp_lock);
5453 +struct module* ip_conntrack_rtsp = THIS_MODULE;
5454 +
5455 +/*
5456 + * Max mappings we will allow for one RTSP connection (for RTP, the number
5457 + * of allocated ports is twice this value).  Note that SMIL burns a lot of
5458 + * ports so keep this reasonably high.  If this is too low, you will see a
5459 + * lot of "no free client map entries" messages.
5460 + */
5461 +#define MAX_PORT_MAPS 16
5462 +
5463 +/*** default port list was here in the masq code: 554, 3030, 4040 ***/
5464 +
5465 +#define SKIP_WSPACE(ptr,len,off) while(off < len && isspace(*(ptr+off))) { off++; }
5466 +
5467 +/*
5468 + * Parse an RTSP packet.
5469 + *
5470 + * Returns zero if parsing failed.
5471 + *
5472 + * Parameters:
5473 + *  IN      ptcp        tcp data pointer
5474 + *  IN      tcplen      tcp data len
5475 + *  IN/OUT  ptcpoff     points to current tcp offset
5476 + *  OUT     phdrsoff    set to offset of rtsp headers
5477 + *  OUT     phdrslen    set to length of rtsp headers
5478 + *  OUT     pcseqoff    set to offset of CSeq header
5479 + *  OUT     pcseqlen    set to length of CSeq header
5480 + */
5481 +static int
5482 +rtsp_parse_message(char* ptcp, uint tcplen, uint* ptcpoff,
5483 +                   uint* phdrsoff, uint* phdrslen,
5484 +                   uint* pcseqoff, uint* pcseqlen)
5485 +{
5486 +    uint    entitylen = 0;
5487 +    uint    lineoff;
5488 +    uint    linelen;
5489 +
5490 +    if (!nf_nextline(ptcp, tcplen, ptcpoff, &lineoff, &linelen))
5491 +    {
5492 +        return 0;
5493 +    }
5494 +
5495 +    *phdrsoff = *ptcpoff;
5496 +    while (nf_mime_nextline(ptcp, tcplen, ptcpoff, &lineoff, &linelen))
5497 +    {
5498 +        if (linelen == 0)
5499 +        {
5500 +            if (entitylen > 0)
5501 +            {
5502 +                *ptcpoff += min(entitylen, tcplen - *ptcpoff);
5503 +            }
5504 +            break;
5505 +        }
5506 +        if (lineoff+linelen > tcplen)
5507 +        {
5508 +            INFOP("!! overrun !!\n");
5509 +            break;
5510 +        }
5511 +
5512 +        if (nf_strncasecmp(ptcp+lineoff, "CSeq:", 5) == 0)
5513 +        {
5514 +            *pcseqoff = lineoff;
5515 +            *pcseqlen = linelen;
5516 +        }
5517 +        if (nf_strncasecmp(ptcp+lineoff, "Content-Length:", 15) == 0)
5518 +        {
5519 +            uint off = lineoff+15;
5520 +            SKIP_WSPACE(ptcp+lineoff, linelen, off);
5521 +            nf_strtou32(ptcp+off, &entitylen);
5522 +        }
5523 +    }
5524 +    *phdrslen = (*ptcpoff) - (*phdrsoff);
5525 +
5526 +    return 1;
5527 +}
5528 +
5529 +/*
5530 + * Find lo/hi client ports (if any) in transport header
5531 + * In:
5532 + *   ptcp, tcplen = packet
5533 + *   tranoff, tranlen = buffer to search
5534 + *
5535 + * Out:
5536 + *   pport_lo, pport_hi = lo/hi ports (host endian)
5537 + *
5538 + * Returns nonzero if any client ports found
5539 + *
5540 + * Note: it is valid (and expected) for the client to request multiple
5541 + * transports, so we need to parse the entire line.
5542 + */
5543 +static int
5544 +rtsp_parse_transport(char* ptran, uint tranlen,
5545 +                     struct ip_ct_rtsp_expect* prtspexp)
5546 +{
5547 +    int     rc = 0;
5548 +    uint    off = 0;
5549 +
5550 +    if (tranlen < 10 || !iseol(ptran[tranlen-1]) ||
5551 +        nf_strncasecmp(ptran, "Transport:", 10) != 0)
5552 +    {
5553 +        INFOP("sanity check failed\n");
5554 +        return 0;
5555 +    }
5556 +    DEBUGP("tran='%.*s'\n", (int)tranlen, ptran);
5557 +    off += 10;
5558 +    SKIP_WSPACE(ptran, tranlen, off);
5559 +
5560 +    /* Transport: tran;field;field=val,tran;field;field=val,... */
5561 +    while (off < tranlen)
5562 +    {
5563 +        const char* pparamend;
5564 +        uint        nextparamoff;
5565 +
5566 +        pparamend = memchr(ptran+off, ',', tranlen-off);
5567 +        pparamend = (pparamend == NULL) ? ptran+tranlen : pparamend+1;
5568 +        nextparamoff = pparamend-ptran;
5569 +
5570 +        while (off < nextparamoff)
5571 +        {
5572 +            const char* pfieldend;
5573 +            uint        nextfieldoff;
5574 +
5575 +            pfieldend = memchr(ptran+off, ';', nextparamoff-off);
5576 +            nextfieldoff = (pfieldend == NULL) ? nextparamoff : pfieldend-ptran+1;
5577 +
5578 +            if (strncmp(ptran+off, "client_port=", 12) == 0)
5579 +            {
5580 +                u_int16_t   port;
5581 +                uint        numlen;
5582 +
5583 +                off += 12;
5584 +                numlen = nf_strtou16(ptran+off, &port);
5585 +                off += numlen;
5586 +                if (prtspexp->loport != 0 && prtspexp->loport != port)
5587 +                {
5588 +                    DEBUGP("multiple ports found, port %hu ignored\n", port);
5589 +                }
5590 +                else
5591 +                {
5592 +                    prtspexp->loport = prtspexp->hiport = port;
5593 +                    if (ptran[off] == '-')
5594 +                    {
5595 +                        off++;
5596 +                        numlen = nf_strtou16(ptran+off, &port);
5597 +                        off += numlen;
5598 +                        prtspexp->pbtype = pb_range;
5599 +                        prtspexp->hiport = port;
5600 +
5601 +                        // If we have a range, assume rtp:
5602 +                        // loport must be even, hiport must be loport+1
5603 +                        if ((prtspexp->loport & 0x0001) != 0 ||
5604 +                            prtspexp->hiport != prtspexp->loport+1)
5605 +                        {
5606 +                            DEBUGP("incorrect range: %hu-%hu, correcting\n",
5607 +                                   prtspexp->loport, prtspexp->hiport);
5608 +                            prtspexp->loport &= 0xfffe;
5609 +                            prtspexp->hiport = prtspexp->loport+1;
5610 +                        }
5611 +                    }
5612 +                    else if (ptran[off] == '/')
5613 +                    {
5614 +                        off++;
5615 +                        numlen = nf_strtou16(ptran+off, &port);
5616 +                        off += numlen;
5617 +                        prtspexp->pbtype = pb_discon;
5618 +                        prtspexp->hiport = port;
5619 +                    }
5620 +                    rc = 1;
5621 +                }
5622 +            }
5623 +
5624 +            /*
5625 +             * Note we don't look for the destination parameter here.
5626 +             * If we are using NAT, the NAT module will handle it.  If not,
5627 +             * and the client is sending packets elsewhere, the expectation
5628 +             * will quietly time out.
5629 +             */
5630 +
5631 +            off = nextfieldoff;
5632 +        }
5633 +
5634 +        off = nextparamoff;
5635 +    }
5636 +
5637 +    return rc;
5638 +}
5639 +
5640 +/*** conntrack functions ***/
5641 +
5642 +/* outbound packet: client->server */
5643 +static int
5644 +help_out(const struct iphdr* iph, size_t pktlen,
5645 +                struct ip_conntrack* ct, enum ip_conntrack_info ctinfo)
5646 +{
5647 +    int dir = CTINFO2DIR(ctinfo);   /* = IP_CT_DIR_ORIGINAL */
5648 +    struct  tcphdr* tcph = (void*)iph + iph->ihl * 4;
5649 +    uint    tcplen = pktlen - iph->ihl * 4;
5650 +    char*   pdata = (char*)tcph + tcph->doff * 4;
5651 +    uint    datalen = tcplen - tcph->doff * 4;
5652 +    uint    dataoff = 0;
5653 +
5654 +    struct ip_conntrack_expect exp;
5655 +
5656 +    while (dataoff < datalen)
5657 +    {
5658 +        uint    cmdoff = dataoff;
5659 +        uint    hdrsoff = 0;
5660 +        uint    hdrslen = 0;
5661 +        uint    cseqoff = 0;
5662 +        uint    cseqlen = 0;
5663 +        uint    lineoff = 0;
5664 +        uint    linelen = 0;
5665 +        uint    off;
5666 +        int     rc;
5667 +
5668 +        if (!rtsp_parse_message(pdata, datalen, &dataoff,
5669 +                                &hdrsoff, &hdrslen,
5670 +                                &cseqoff, &cseqlen))
5671 +        {
5672 +            break;      /* not a valid message */
5673 +        }
5674 +
5675 +        if (strncmp(pdata+cmdoff, "SETUP ", 6) != 0)
5676 +        {
5677 +            continue;   /* not a SETUP message */
5678 +        }
5679 +        DEBUGP("found a setup message\n");
5680 +
5681 +        memset(&exp, 0, sizeof(exp));
5682 +
5683 +        off = 0;
5684 +        while (nf_mime_nextline(pdata+hdrsoff, hdrslen, &off,
5685 +                                &lineoff, &linelen))
5686 +        {
5687 +            if (linelen == 0)
5688 +            {
5689 +                break;
5690 +            }
5691 +            if (off > hdrsoff+hdrslen)
5692 +            {
5693 +                INFOP("!! overrun !!");
5694 +                break;
5695 +            }
5696 +
5697 +            if (nf_strncasecmp(pdata+hdrsoff+lineoff, "Transport:", 10) == 0)
5698 +            {
5699 +                rtsp_parse_transport(pdata+hdrsoff+lineoff, linelen,
5700 +                                     &exp.help.exp_rtsp_info);
5701 +            }
5702 +        }
5703 +
5704 +        if (exp.help.exp_rtsp_info.loport == 0)
5705 +        {
5706 +            DEBUGP("no udp transports found\n");
5707 +            continue;   /* no udp transports found */
5708 +        }
5709 +
5710 +        DEBUGP("udp transport found, ports=(%d,%hu,%hu)\n",
5711 +              (int)exp.help.exp_rtsp_info.pbtype,
5712 +              exp.help.exp_rtsp_info.loport,
5713 +              exp.help.exp_rtsp_info.hiport);
5714 +
5715 +        LOCK_BH(&ip_rtsp_lock);
5716 +        exp.seq = ntohl(tcph->seq) + hdrsoff; /* mark all the headers */
5717 +        exp.help.exp_rtsp_info.len = hdrslen;
5718 +
5719 +        exp.tuple.src.ip = ct->tuplehash[!dir].tuple.src.ip;
5720 +        exp.mask.src.ip  = 0xffffffff;
5721 +        exp.tuple.dst.ip = ct->tuplehash[dir].tuple.src.ip;
5722 +        exp.mask.dst.ip  = 0xffffffff;
5723 +        exp.tuple.dst.u.udp.port = exp.help.exp_rtsp_info.loport;
5724 +        exp.mask.dst.u.udp.port  = (exp.help.exp_rtsp_info.pbtype == pb_range) ? 0xfffe : 0xffff;
5725 +        exp.tuple.dst.protonum = IPPROTO_UDP;
5726 +        exp.mask.dst.protonum  = 0xffff;
5727 +
5728 +        DEBUGP("expect_related %u.%u.%u.%u:%u-%u.%u.%u.%u:%u\n",
5729 +                NIPQUAD(exp.tuple.src.ip),
5730 +                ntohs(exp.tuple.src.u.tcp.port),
5731 +                NIPQUAD(exp.tuple.dst.ip),
5732 +                ntohs(exp.tuple.dst.u.tcp.port));
5733 +
5734 +        /* pass the request off to the nat helper */
5735 +        rc = ip_conntrack_expect_related(ct, &exp);
5736 +        UNLOCK_BH(&ip_rtsp_lock);
5737 +        if (rc == 0)
5738 +        {
5739 +            DEBUGP("ip_conntrack_expect_related succeeded\n");
5740 +        }
5741 +        else
5742 +        {
5743 +            INFOP("ip_conntrack_expect_related failed (%d)\n", rc);
5744 +        }
5745 +    }
5746 +
5747 +    return NF_ACCEPT;
5748 +}
5749 +
5750 +/* inbound packet: server->client */
5751 +static int
5752 +help_in(const struct iphdr* iph, size_t pktlen,
5753 +                struct ip_conntrack* ct, enum ip_conntrack_info ctinfo)
5754 +{
5755 +    return NF_ACCEPT;
5756 +}
5757 +
5758 +static int
5759 +help(const struct iphdr* iph, size_t pktlen,
5760 +                struct ip_conntrack* ct, enum ip_conntrack_info ctinfo)
5761 +{
5762 +    /* tcplen not negative guarenteed by ip_conntrack_tcp.c */
5763 +    struct tcphdr* tcph = (void*)iph + iph->ihl * 4;
5764 +    u_int32_t tcplen = pktlen - iph->ihl * 4;
5765 +
5766 +    /* Until there's been traffic both ways, don't look in packets. */
5767 +    if (ctinfo != IP_CT_ESTABLISHED && ctinfo != IP_CT_ESTABLISHED + IP_CT_IS_REPLY)
5768 +    {
5769 +        DEBUGP("conntrackinfo = %u\n", ctinfo);
5770 +        return NF_ACCEPT;
5771 +    }
5772 +
5773 +    /* Not whole TCP header? */
5774 +    if (tcplen < sizeof(struct tcphdr) || tcplen < tcph->doff * 4)
5775 +    {
5776 +        DEBUGP("tcplen = %u\n", (unsigned)tcplen);
5777 +        return NF_ACCEPT;
5778 +    }
5779 +
5780 +    /* Checksum invalid?  Ignore. */
5781 +    /* FIXME: Source route IP option packets --RR */
5782 +    if (tcp_v4_check(tcph, tcplen, iph->saddr, iph->daddr,
5783 +                     csum_partial((char*)tcph, tcplen, 0)))
5784 +    {
5785 +        DEBUGP("bad csum: %p %u %u.%u.%u.%u %u.%u.%u.%u\n",
5786 +               tcph, tcplen, NIPQUAD(iph->saddr), NIPQUAD(iph->daddr));
5787 +        return NF_ACCEPT;
5788 +    }
5789 +
5790 +    switch (CTINFO2DIR(ctinfo))
5791 +    {
5792 +    case IP_CT_DIR_ORIGINAL:
5793 +        help_out(iph, pktlen, ct, ctinfo);
5794 +        break;
5795 +    case IP_CT_DIR_REPLY:
5796 +        help_in(iph, pktlen, ct, ctinfo);
5797 +        break;
5798 +    }
5799 +
5800 +    return NF_ACCEPT;
5801 +}
5802 +
5803 +static struct ip_conntrack_helper rtsp_helpers[MAX_PORTS];
5804 +static char rtsp_names[MAX_PORTS][10];
5805 +
5806 +/* This function is intentionally _NOT_ defined as __exit */
5807 +static void
5808 +fini(void)
5809 +{
5810 +    int i;
5811 +    for (i = 0; i < num_ports; i++)
5812 +    {
5813 +        DEBUGP("unregistering port %d\n", ports[i]);
5814 +        ip_conntrack_helper_unregister(&rtsp_helpers[i]);
5815 +    }
5816 +}
5817 +
5818 +static int __init
5819 +init(void)
5820 +{
5821 +    int i, ret;
5822 +    struct ip_conntrack_helper *hlpr;
5823 +    char *tmpname;
5824 +
5825 +    printk("ip_conntrack_rtsp v" IP_NF_RTSP_VERSION " loading\n");
5826 +
5827 +    if (max_outstanding < 1)
5828 +    {
5829 +        printk("ip_conntrack_rtsp: max_outstanding must be a positive integer\n");
5830 +        return -EBUSY;
5831 +    }
5832 +    if (setup_timeout < 0)
5833 +    {
5834 +        printk("ip_conntrack_rtsp: setup_timeout must be a positive integer\n");
5835 +        return -EBUSY;
5836 +    }
5837 +
5838 +    /* If no port given, default to standard rtsp port */
5839 +    if (ports[0] == 0)
5840 +    {
5841 +        ports[0] = RTSP_PORT;
5842 +    }
5843 +
5844 +    for (i = 0; (i < MAX_PORTS) && ports[i]; i++)
5845 +    {
5846 +        hlpr = &rtsp_helpers[i];
5847 +        memset(hlpr, 0, sizeof(struct ip_conntrack_helper));
5848 +        hlpr->tuple.src.u.tcp.port = htons(ports[i]);
5849 +        hlpr->tuple.dst.protonum = IPPROTO_TCP;
5850 +        hlpr->mask.src.u.tcp.port = 0xFFFF;
5851 +        hlpr->mask.dst.protonum = 0xFFFF;
5852 +        hlpr->max_expected = max_outstanding;
5853 +        hlpr->timeout = setup_timeout;
5854 +        hlpr->flags = IP_CT_HELPER_F_REUSE_EXPECT;
5855 +        hlpr->me = ip_conntrack_rtsp;
5856 +        hlpr->help = help;
5857 +
5858 +        tmpname = &rtsp_names[i][0];
5859 +        if (ports[i] == RTSP_PORT)
5860 +        {
5861 +            sprintf(tmpname, "rtsp");
5862 +        }
5863 +        else
5864 +        {
5865 +            sprintf(tmpname, "rtsp-%d", i);
5866 +        }
5867 +        hlpr->name = tmpname;
5868 +
5869 +        DEBUGP("port #%d: %d\n", i, ports[i]);
5870 +
5871 +        ret = ip_conntrack_helper_register(hlpr);
5872 +
5873 +        if (ret)
5874 +        {
5875 +            printk("ip_conntrack_rtsp: ERROR registering port %d\n", ports[i]);
5876 +            fini();
5877 +            return -EBUSY;
5878 +        }
5879 +        num_ports++;
5880 +    }
5881 +    return 0;
5882 +}
5883 +
5884 +#ifdef CONFIG_IP_NF_NAT_NEEDED
5885 +EXPORT_SYMBOL(ip_rtsp_lock);
5886 +#endif
5887 +
5888 +module_init(init);
5889 +module_exit(fini);
5890 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ip_conntrack_standalone.c linux-2.6.6/net/ipv4/netfilter/ip_conntrack_standalone.c
5891 --- linux-2.6.6.org/net/ipv4/netfilter/ip_conntrack_standalone.c        2004-05-10 04:32:29.000000000 +0200
5892 +++ linux-2.6.6/net/ipv4/netfilter/ip_conntrack_standalone.c    2004-05-18 14:28:50.000000000 +0200
5893 @@ -110,6 +110,9 @@
5894                 len += sprintf(buffer + len, "[ASSURED] ");
5895         len += sprintf(buffer + len, "use=%u ",
5896                        atomic_read(&conntrack->ct_general.use));
5897 +#if defined(CONFIG_IP_NF_CONNTRACK_MARK)
5898 +       len += sprintf(buffer + len, "mark=%ld ", conntrack->mark);
5899 +#endif
5900         len += sprintf(buffer + len, "\n");
5901  
5902         return len;
5903 @@ -633,6 +636,7 @@
5904  EXPORT_SYMBOL(ip_conntrack_alter_reply);
5905  EXPORT_SYMBOL(ip_conntrack_destroyed);
5906  EXPORT_SYMBOL(ip_conntrack_get);
5907 +EXPORT_SYMBOL(__ip_conntrack_confirm);
5908  EXPORT_SYMBOL(need_ip_conntrack);
5909  EXPORT_SYMBOL(ip_conntrack_helper_register);
5910  EXPORT_SYMBOL(ip_conntrack_helper_unregister);
5911 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ip_conntrack_talk.c linux-2.6.6/net/ipv4/netfilter/ip_conntrack_talk.c
5912 --- linux-2.6.6.org/net/ipv4/netfilter/ip_conntrack_talk.c      1970-01-01 01:00:00.000000000 +0100
5913 +++ linux-2.6.6/net/ipv4/netfilter/ip_conntrack_talk.c  2004-05-18 14:28:50.000000000 +0200
5914 @@ -0,0 +1,360 @@
5915 +/* 
5916 + * talk extension for IP connection tracking. 
5917 + * Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
5918 + *
5919 + *      This program is free software; you can redistribute it and/or
5920 + *      modify it under the terms of the GNU General Public License
5921 + *      as published by the Free Software Foundation; either version
5922 + *      2 of the License, or (at your option) any later version.
5923 + **
5924 + *     Module load syntax:
5925 + *     insmod ip_nat_talk.o talk=[0|1] ntalk=[0|1] ntalk2=[01]
5926 + *
5927 + *             talk=[0|1]      disable|enable old talk support
5928 + *            ntalk=[0|1]      disable|enable ntalk support
5929 + *           ntalk2=[0|1]      disable|enable ntalk2 support
5930 + *
5931 + *     The default is talk=1 ntalk=1 ntalk2=1
5932 + *
5933 + *     The helper does not support simultaneous talk requests.
5934 + **
5935 + *
5936 + *             ASCII art on talk protocols
5937 + *     
5938 + *     
5939 + *     caller server               callee server
5940 + *             |     \           /
5941 + *             |       \       /
5942 + *             |         \   /
5943 + *             |           /  
5944 + *             |         /   \
5945 + *           2 |     1 /       \ 3
5946 + *     caller client  ----------- callee client
5947 + *                              4
5948 + *
5949 + *     1. caller client <-> callee server: LOOK_UP, then ANNOUNCE invitation 
5950 + *    ( 2. caller client <-> caller server: LEAVE_INVITE to server )
5951 + *     3. callee client <-> caller server: LOOK_UP invitation
5952 + *     4. callee client <-> caller client: talk data channel
5953 + *
5954 + * [1]: M. Hunter, talk: a historical protocol for interactive communication
5955 + *      draft-hunter-talk-00.txt
5956 + * [2]: D.B. Chapman, E.D. Zwicky: Building Internet Firewalls (O'Reilly)      
5957 + */
5958 +#include <linux/config.h>
5959 +#include <linux/module.h>
5960 +#include <linux/netfilter.h>
5961 +#include <linux/ip.h>
5962 +#include <net/checksum.h>
5963 +#include <net/udp.h>
5964 +
5965 +#include <linux/netfilter_ipv4/lockhelp.h>
5966 +#include <linux/netfilter_ipv4/ip_conntrack.h>
5967 +#include <linux/netfilter_ipv4/ip_conntrack_core.h>
5968 +#include <linux/netfilter_ipv4/ip_conntrack_helper.h>
5969 +#include <linux/netfilter_ipv4/ip_conntrack_talk.h>
5970 +
5971 +/* Default all talk protocols are supported */
5972 +static int talk = 1;
5973 +static int ntalk = 1;
5974 +static int ntalk2 = 1;
5975 +MODULE_AUTHOR("Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>");
5976 +MODULE_DESCRIPTION("talk connection tracking module");
5977 +MODULE_LICENSE("GPL");
5978 +#ifdef MODULE_PARM
5979 +MODULE_PARM(talk, "i");
5980 +MODULE_PARM_DESC(talk, "support (old) talk protocol");
5981 +MODULE_PARM(ntalk, "i");
5982 +MODULE_PARM_DESC(ntalk, "support ntalk protocol");
5983 +MODULE_PARM(ntalk2, "i");
5984 +MODULE_PARM_DESC(ntalk2, "support ntalk2 protocol");
5985 +#endif
5986 +
5987 +DECLARE_LOCK(ip_talk_lock);
5988 +struct module *ip_conntrack_talk = THIS_MODULE;
5989 +
5990 +#if 0
5991 +#define DEBUGP printk
5992 +#else
5993 +#define DEBUGP(format, args...)
5994 +#endif
5995 +
5996 +static int talk_expect(struct ip_conntrack *ct);
5997 +static int ntalk_expect(struct ip_conntrack *ct);
5998 +
5999 +static int (*talk_expectfn[2])(struct ip_conntrack *ct) = {talk_expect, ntalk_expect};
6000 +
6001 +static int talk_help_response(const struct iphdr *iph, size_t len,
6002 +                             struct ip_conntrack *ct,
6003 +                             enum ip_conntrack_info ctinfo,
6004 +                             int talk_port,
6005 +                             u_char mode,
6006 +                             u_char type,
6007 +                             u_char answer,
6008 +                             struct talk_addr *addr)
6009 +{
6010 +       int dir = CTINFO2DIR(ctinfo);
6011 +       struct ip_conntrack_expect expect, *exp = &expect;
6012 +       struct ip_ct_talk_expect *exp_talk_info = &exp->help.exp_talk_info;
6013 +
6014 +       DEBUGP("ip_ct_talk_help_response: %u.%u.%u.%u:%u, type %d answer %d\n",
6015 +               NIPQUAD(addr->ta_addr), ntohs(addr->ta_port),
6016 +               type, answer);
6017 +
6018 +       if (!(answer == SUCCESS && type == mode))
6019 +               return NF_ACCEPT;
6020 +       
6021 +       memset(&expect, 0, sizeof(expect));
6022 +       
6023 +       if (type == ANNOUNCE) {
6024 +
6025 +               DEBUGP("ip_ct_talk_help_response: ANNOUNCE\n");
6026 +
6027 +               /* update the talk info */
6028 +               LOCK_BH(&ip_talk_lock);
6029 +               exp_talk_info->port = htons(talk_port);
6030 +
6031 +               /* expect callee client -> caller server message */
6032 +               exp->tuple = ((struct ip_conntrack_tuple)
6033 +                       { { ct->tuplehash[dir].tuple.src.ip,
6034 +                           { 0 } },
6035 +                         { ct->tuplehash[dir].tuple.dst.ip,
6036 +                           { .tcp = { htons(talk_port) } },
6037 +                           IPPROTO_UDP }});
6038 +               exp->mask = ((struct ip_conntrack_tuple)
6039 +                       { { 0xFFFFFFFF, { 0 } },
6040 +                         { 0xFFFFFFFF, { .tcp = { 0xFFFF } }, 0xFFFF }});
6041 +               
6042 +               exp->expectfn = talk_expectfn[talk_port - TALK_PORT];
6043 +
6044 +               DEBUGP("ip_ct_talk_help_response: callee client %u.%u.%u.%u:%u -> caller daemon %u.%u.%u.%u:%u!\n",
6045 +                      NIPQUAD(exp->tuple.src.ip), ntohs(exp->tuple.src.u.udp.port),
6046 +                      NIPQUAD(exp->tuple.dst.ip), ntohs(exp->tuple.dst.u.udp.port));
6047 +
6048 +               /* Ignore failure; should only happen with NAT */
6049 +               ip_conntrack_expect_related(ct, &expect);
6050 +               UNLOCK_BH(&ip_talk_lock);
6051 +       }
6052 +       if (type == LOOK_UP) {
6053 +
6054 +               DEBUGP("ip_ct_talk_help_response: LOOK_UP\n");
6055 +
6056 +               /* update the talk info */
6057 +               LOCK_BH(&ip_talk_lock);
6058 +               exp_talk_info->port = addr->ta_port;
6059 +
6060 +               /* expect callee client -> caller client connection */
6061 +               exp->tuple = ((struct ip_conntrack_tuple)
6062 +                       { { ct->tuplehash[!dir].tuple.src.ip,
6063 +                           { 0 } },
6064 +                         { addr->ta_addr,
6065 +                           { addr->ta_port },
6066 +                           IPPROTO_TCP }});
6067 +               exp->mask = ((struct ip_conntrack_tuple)
6068 +                       { { 0xFFFFFFFF, { 0 } },
6069 +                         { 0xFFFFFFFF, { 0xFFFF }, 0xFFFF }});
6070 +               
6071 +               exp->expectfn = NULL;
6072 +               
6073 +               DEBUGP("ip_ct_talk_help_response: callee client %u.%u.%u.%u:%u -> caller client %u.%u.%u.%u:%u!\n",
6074 +                      NIPQUAD(exp->tuple.src.ip), ntohs(exp->tuple.src.u.tcp.port),
6075 +                      NIPQUAD(exp->tuple.dst.ip), ntohs(exp->tuple.dst.u.tcp.port));
6076 +
6077 +               /* Ignore failure; should only happen with NAT */
6078 +               ip_conntrack_expect_related(ct, &expect);
6079 +               UNLOCK_BH(&ip_talk_lock);
6080 +       }
6081 +                   
6082 +       return NF_ACCEPT;
6083 +}
6084 +
6085 +/* FIXME: This should be in userspace.  Later. */
6086 +static int talk_help(const struct iphdr *iph, size_t len,
6087 +                    struct ip_conntrack *ct,
6088 +                    enum ip_conntrack_info ctinfo,
6089 +                    int talk_port,
6090 +                    u_char mode)
6091 +{
6092 +       struct udphdr *udph = (void *)iph + iph->ihl * 4;
6093 +       const char *data = (const char *)udph + sizeof(struct udphdr);
6094 +       int dir = CTINFO2DIR(ctinfo);
6095 +       size_t udplen;
6096 +
6097 +       DEBUGP("ip_ct_talk_help: help entered\n");
6098 +
6099 +       /* Until there's been traffic both ways, don't look in packets. */
6100 +       if (ctinfo != IP_CT_ESTABLISHED
6101 +           && ctinfo != IP_CT_ESTABLISHED + IP_CT_IS_REPLY) {
6102 +               DEBUGP("ip_ct_talk_help: Conntrackinfo = %u\n", ctinfo);
6103 +               return NF_ACCEPT;
6104 +       }
6105 +
6106 +       /* Not whole UDP header? */
6107 +       udplen = len - iph->ihl * 4;
6108 +       if (udplen < sizeof(struct udphdr)) {
6109 +               DEBUGP("ip_ct_talk_help: too short for udph, udplen = %u\n", (unsigned)udplen);
6110 +               return NF_ACCEPT;
6111 +       }
6112 +
6113 +       /* Checksum invalid?  Ignore. */
6114 +       /* FIXME: Source route IP option packets --RR */
6115 +       if (csum_tcpudp_magic(iph->saddr, iph->daddr, udplen, IPPROTO_UDP,
6116 +                             csum_partial((char *)udph, udplen, 0))) {
6117 +               DEBUGP("ip_ct_talk_help: bad csum: %p %u %u.%u.%u.%u %u.%u.%u.%u\n",
6118 +                      udph, udplen, NIPQUAD(iph->saddr),
6119 +                      NIPQUAD(iph->daddr));
6120 +               return NF_ACCEPT;
6121 +       }
6122 +       
6123 +       DEBUGP("ip_ct_talk_help: %u.%u.%u.%u:%u->%u.%u.%u.%u:%u\n",
6124 +               NIPQUAD(iph->saddr), ntohs(udph->source), NIPQUAD(iph->daddr), ntohs(udph->dest));
6125 +
6126 +       if (dir == IP_CT_DIR_ORIGINAL)
6127 +               return NF_ACCEPT;
6128 +               
6129 +       if (talk_port == TALK_PORT
6130 +           && udplen == sizeof(struct udphdr) + sizeof(struct talk_response))
6131 +               return talk_help_response(iph, len, ct, ctinfo, talk_port, mode,
6132 +                                         ((struct talk_response *)data)->type, 
6133 +                                         ((struct talk_response *)data)->answer,
6134 +                                         &(((struct talk_response *)data)->addr));
6135 +       else if (talk_port == NTALK_PORT
6136 +                 && ntalk
6137 +                 && udplen == sizeof(struct udphdr) + sizeof(struct ntalk_response)
6138 +                 && ((struct ntalk_response *)data)->vers == NTALK_VERSION)
6139 +               return talk_help_response(iph, len, ct, ctinfo, talk_port, mode,
6140 +                                         ((struct ntalk_response *)data)->type, 
6141 +                                         ((struct ntalk_response *)data)->answer,
6142 +                                         &(((struct ntalk_response *)data)->addr));
6143 +       else if (talk_port == NTALK_PORT
6144 +                && ntalk2
6145 +                && udplen >= sizeof(struct udphdr) + sizeof(struct ntalk2_response)
6146 +                && ((struct ntalk2_response *)data)->vers == NTALK2_VERSION)
6147 +               return talk_help_response(iph, len, ct, ctinfo, talk_port, mode,
6148 +                                         ((struct ntalk2_response *)data)->type, 
6149 +                                         ((struct ntalk2_response *)data)->answer,
6150 +                                         &(((struct ntalk2_response *)data)->addr));
6151 +       else {
6152 +               DEBUGP("ip_ct_talk_help: not ntalk/ntalk2 response, datalen %u != %u or %u + max 256\n", 
6153 +                      (unsigned)udplen - sizeof(struct udphdr), 
6154 +                      sizeof(struct ntalk_response), sizeof(struct ntalk2_response));
6155 +               return NF_ACCEPT;
6156 +       }
6157 +}
6158 +
6159 +static int lookup_help(const struct iphdr *iph, size_t len,
6160 +                      struct ip_conntrack *ct, enum ip_conntrack_info ctinfo)
6161 +{
6162 +       return talk_help(iph, len, ct, ctinfo, TALK_PORT, LOOK_UP);
6163 +}
6164 +
6165 +static int lookup_nhelp(const struct iphdr *iph, size_t len,
6166 +                       struct ip_conntrack *ct, enum ip_conntrack_info ctinfo)
6167 +{
6168 +       return talk_help(iph, len, ct, ctinfo, NTALK_PORT, LOOK_UP);
6169 +}
6170 +
6171 +static struct ip_conntrack_helper lookup_helpers[2] = 
6172 +       { { { NULL, NULL },
6173 +           "talk",                                     /* name */
6174 +           0,                                          /* flags */
6175 +           NULL,                                       /* module */
6176 +           1,                                          /* max_expected */
6177 +           240,                                        /* timeout */
6178 +            { { 0, { __constant_htons(TALK_PORT) } },  /* tuple */
6179 +             { 0, { 0 }, IPPROTO_UDP } },
6180 +           { { 0, { 0xFFFF } },                        /* mask */
6181 +             { 0, { 0 }, 0xFFFF } },
6182 +           lookup_help },                              /* helper */
6183 +          { { NULL, NULL },
6184 +            "ntalk",                                   /* name */
6185 +           0,                                          /* flags */
6186 +           NULL,                                       /* module */
6187 +           1,                                          /* max_expected */
6188 +           240,                                        /* timeout */
6189 +           { { 0, { __constant_htons(NTALK_PORT) } },  /* tuple */
6190 +             { 0, { 0 }, IPPROTO_UDP } },
6191 +           { { 0, { 0xFFFF } },                        /* mask */
6192 +             { 0, { 0 }, 0xFFFF } },
6193 +           lookup_nhelp }                              /* helper */
6194 +        };
6195 +
6196 +static int talk_expect(struct ip_conntrack *ct)
6197 +{
6198 +       DEBUGP("ip_conntrack_talk: calling talk_expectfn for ct %p\n", ct);
6199 +       WRITE_LOCK(&ip_conntrack_lock);
6200 +       ct->helper = &lookup_helpers[0];
6201 +       WRITE_UNLOCK(&ip_conntrack_lock);
6202 +        
6203 +       return NF_ACCEPT;       /* unused */
6204 +}
6205 +
6206 +static int ntalk_expect(struct ip_conntrack *ct)
6207 +{
6208 +       DEBUGP("ip_conntrack_talk: calling ntalk_expectfn for ct %p\n", ct);
6209 +       WRITE_LOCK(&ip_conntrack_lock);
6210 +       ct->helper = &lookup_helpers[1];
6211 +       WRITE_UNLOCK(&ip_conntrack_lock);
6212 +        
6213 +       return NF_ACCEPT;       /* unused */
6214 +}
6215 +
6216 +static int help(const struct iphdr *iph, size_t len,
6217 +               struct ip_conntrack *ct, enum ip_conntrack_info ctinfo)
6218 +{
6219 +       return talk_help(iph, len, ct, ctinfo, TALK_PORT, ANNOUNCE);
6220 +}
6221 +
6222 +static int nhelp(const struct iphdr *iph, size_t len,
6223 +                struct ip_conntrack *ct, enum ip_conntrack_info ctinfo)
6224 +{
6225 +       return talk_help(iph, len, ct, ctinfo, NTALK_PORT, ANNOUNCE);
6226 +}
6227 +
6228 +static struct ip_conntrack_helper talk_helpers[2] = 
6229 +       { { { NULL, NULL },
6230 +           "talk",                                     /* name */
6231 +           0,                                          /* flags */
6232 +           THIS_MODULE,                                /* module */
6233 +           1,                                          /* max_expected */
6234 +           240,                                        /* timeout */
6235 +           { { 0, { __constant_htons(TALK_PORT) } },   /* tuple */
6236 +             { 0, { 0 }, IPPROTO_UDP } },
6237 +           { { 0, { 0xFFFF } },                        /* mask */
6238 +             { 0, { 0 }, 0xFFFF } },
6239 +           help },                                     /* helper */
6240 +          { { NULL, NULL },
6241 +           "ntalk",                                    /* name */
6242 +           0,                                          /* flags */
6243 +           THIS_MODULE,                                /* module */
6244 +           1,                                          /* max_expected */
6245 +           240,                                        /* timeout */
6246 +           { { 0, { __constant_htons(NTALK_PORT) } },  /* tuple */
6247 +             { 0, { 0 }, IPPROTO_UDP } },
6248 +           { { 0, { 0xFFFF } },                        /* mask */
6249 +             { 0, { 0 }, 0xFFFF } },
6250 +           nhelp }                                     /* helper */
6251 +       };
6252 +
6253 +static int __init init(void)
6254 +{
6255 +       if (talk > 0)
6256 +               ip_conntrack_helper_register(&talk_helpers[0]);
6257 +       if (ntalk > 0 || ntalk2 > 0)
6258 +               ip_conntrack_helper_register(&talk_helpers[1]);
6259 +               
6260 +       return 0;
6261 +}
6262 +
6263 +static void __exit fini(void)
6264 +{
6265 +       if (talk > 0)
6266 +               ip_conntrack_helper_unregister(&talk_helpers[0]);
6267 +       if (ntalk > 0 || ntalk2 > 0)
6268 +               ip_conntrack_helper_unregister(&talk_helpers[1]);
6269 +}
6270 +
6271 +EXPORT_SYMBOL(ip_talk_lock);
6272 +
6273 +module_init(init);
6274 +module_exit(fini);
6275 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ip_nat_core.c linux-2.6.6/net/ipv4/netfilter/ip_nat_core.c
6276 --- linux-2.6.6.org/net/ipv4/netfilter/ip_nat_core.c    2004-05-10 04:32:01.000000000 +0200
6277 +++ linux-2.6.6/net/ipv4/netfilter/ip_nat_core.c        2004-05-18 14:28:50.000000000 +0200
6278 @@ -816,7 +816,7 @@
6279  
6280                 /* Have to grab read lock before sibling_list traversal */
6281                 READ_LOCK(&ip_conntrack_lock);
6282 -               list_for_each(cur_item, &ct->sibling_list) { 
6283 +               list_for_each_prev(cur_item, &ct->sibling_list) { 
6284                         exp = list_entry(cur_item, struct ip_conntrack_expect, 
6285                                          expected_list);
6286                                          
6287 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ip_nat_h323.c linux-2.6.6/net/ipv4/netfilter/ip_nat_h323.c
6288 --- linux-2.6.6.org/net/ipv4/netfilter/ip_nat_h323.c    1970-01-01 01:00:00.000000000 +0100
6289 +++ linux-2.6.6/net/ipv4/netfilter/ip_nat_h323.c        2004-05-18 14:28:50.000000000 +0200
6290 @@ -0,0 +1,419 @@
6291 +/* 
6292 + * H.323 'brute force' extension for NAT alteration. 
6293 + * Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
6294 + *
6295 + * Based on ip_masq_h323.c for 2.2 kernels from CoRiTel, Sofia project.
6296 + * (http://www.coritel.it/projects/sofia/nat.html)
6297 + * Uses Sampsa Ranta's excellent idea on using expectfn to 'bind'
6298 + * the unregistered helpers to the conntrack entries.
6299 + */
6300 +
6301 +
6302 +#include <linux/module.h>
6303 +#include <linux/netfilter.h>
6304 +#include <linux/ip.h>
6305 +#include <net/checksum.h>
6306 +#include <net/tcp.h>
6307 +
6308 +#include <linux/netfilter_ipv4/lockhelp.h>
6309 +#include <linux/netfilter_ipv4/ip_nat.h>
6310 +#include <linux/netfilter_ipv4/ip_nat_helper.h>
6311 +#include <linux/netfilter_ipv4/ip_nat_rule.h>
6312 +#include <linux/netfilter_ipv4/ip_conntrack_tuple.h>
6313 +#include <linux/netfilter_ipv4/ip_conntrack_helper.h>
6314 +#include <linux/netfilter_ipv4/ip_conntrack_h323.h>
6315 +
6316 +MODULE_AUTHOR("Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>");
6317 +MODULE_DESCRIPTION("H.323 'brute force' connection tracking module");
6318 +MODULE_LICENSE("GPL");
6319 +
6320 +DECLARE_LOCK_EXTERN(ip_h323_lock);
6321 +struct module *ip_nat_h323 = THIS_MODULE;
6322 +
6323 +#if 0
6324 +#define DEBUGP printk
6325 +#else
6326 +#define DEBUGP(format, args...)
6327 +#endif
6328 +
6329 +/* FIXME: Time out? --RR */
6330 +
6331 +static unsigned int 
6332 +h225_nat_expected(struct sk_buff **pskb,
6333 +                 unsigned int hooknum,
6334 +                 struct ip_conntrack *ct,
6335 +                 struct ip_nat_info *info);
6336 +
6337 +static unsigned int h225_nat_help(struct ip_conntrack *ct,
6338 +                                 struct ip_conntrack_expect *exp,
6339 +                                 struct ip_nat_info *info,
6340 +                                 enum ip_conntrack_info ctinfo,
6341 +                                 unsigned int hooknum,
6342 +                                 struct sk_buff **pskb);
6343 +                 
6344 +static struct ip_nat_helper h245 = 
6345 +       { { NULL, NULL },
6346 +          "H.245",                             /* name */
6347 +         0,                                    /* flags */
6348 +         NULL,                                 /* module */
6349 +         { { 0, { 0 } },                       /* tuple */
6350 +           { 0, { 0 }, IPPROTO_TCP } },
6351 +         { { 0, { 0xFFFF } },                  /* mask */
6352 +           { 0, { 0 }, 0xFFFF } },
6353 +         h225_nat_help,                        /* helper */
6354 +         h225_nat_expected                     /* expectfn */
6355 +       };
6356 +
6357 +static unsigned int
6358 +h225_nat_expected(struct sk_buff **pskb,
6359 +                 unsigned int hooknum,
6360 +                 struct ip_conntrack *ct,
6361 +                 struct ip_nat_info *info)
6362 +{
6363 +       struct ip_nat_multi_range mr;
6364 +       u_int32_t newdstip, newsrcip, newip;
6365 +       u_int16_t port;
6366 +       struct ip_ct_h225_expect *exp_info;
6367 +       struct ip_ct_h225_master *master_info;
6368 +       struct ip_conntrack *master = master_ct(ct);
6369 +       unsigned int is_h225, ret;
6370 +       
6371 +       IP_NF_ASSERT(info);
6372 +       IP_NF_ASSERT(master);
6373 +
6374 +       IP_NF_ASSERT(!(info->initialized & (1<<HOOK2MANIP(hooknum))));
6375 +
6376 +       DEBUGP("h225_nat_expected: We have a connection!\n");
6377 +       master_info = &ct->master->expectant->help.ct_h225_info;
6378 +       exp_info = &ct->master->help.exp_h225_info;
6379 +
6380 +       LOCK_BH(&ip_h323_lock);
6381 +
6382 +       DEBUGP("master: ");
6383 +       DUMP_TUPLE(&master->tuplehash[IP_CT_DIR_ORIGINAL].tuple);
6384 +       DUMP_TUPLE(&master->tuplehash[IP_CT_DIR_REPLY].tuple);
6385 +       DEBUGP("conntrack: ");
6386 +       DUMP_TUPLE(&ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple);
6387 +       if (exp_info->dir == IP_CT_DIR_ORIGINAL) {
6388 +               /* Make connection go to the client. */
6389 +               newdstip = master->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.ip;
6390 +               newsrcip = master->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.ip;
6391 +               DEBUGP("h225_nat_expected: %u.%u.%u.%u->%u.%u.%u.%u (to client)\n",
6392 +                      NIPQUAD(newsrcip), NIPQUAD(newdstip));
6393 +       } else {
6394 +               /* Make the connection go to the server */
6395 +               newdstip = master->tuplehash[IP_CT_DIR_REPLY].tuple.src.ip;
6396 +               newsrcip = master->tuplehash[IP_CT_DIR_REPLY].tuple.dst.ip;
6397 +               DEBUGP("h225_nat_expected: %u.%u.%u.%u->%u.%u.%u.%u (to server)\n",
6398 +                      NIPQUAD(newsrcip), NIPQUAD(newdstip));
6399 +       }
6400 +       port = exp_info->port;
6401 +       is_h225 = master_info->is_h225 == H225_PORT;
6402 +       UNLOCK_BH(&ip_h323_lock);
6403 +       
6404 +       if (HOOK2MANIP(hooknum) == IP_NAT_MANIP_SRC)
6405 +               newip = newsrcip;
6406 +       else
6407 +               newip = newdstip;
6408 +
6409 +       DEBUGP("h225_nat_expected: IP to %u.%u.%u.%u\n", NIPQUAD(newip));
6410 +
6411 +       mr.rangesize = 1;
6412 +       /* We don't want to manip the per-protocol, just the IPs... */
6413 +       mr.range[0].flags = IP_NAT_RANGE_MAP_IPS;
6414 +       mr.range[0].min_ip = mr.range[0].max_ip = newip;
6415 +
6416 +       /* ... unless we're doing a MANIP_DST, in which case, make
6417 +          sure we map to the correct port */
6418 +       if (HOOK2MANIP(hooknum) == IP_NAT_MANIP_DST) {
6419 +               mr.range[0].flags |= IP_NAT_RANGE_PROTO_SPECIFIED;
6420 +               mr.range[0].min = mr.range[0].max
6421 +                       = ((union ip_conntrack_manip_proto)
6422 +                               { .tcp = { port } });
6423 +       }
6424 +
6425 +       ret = ip_nat_setup_info(ct, &mr, hooknum);
6426 +       
6427 +       if (is_h225) {
6428 +               DEBUGP("h225_nat_expected: H.225, setting NAT helper for %p\n", ct);
6429 +               /* NAT expectfn called with ip_nat_lock write-locked */
6430 +               info->helper = &h245;
6431 +       }
6432 +       return ret;
6433 +}
6434 +
6435 +static int h323_signal_address_fixup(struct ip_conntrack *ct,
6436 +                                    struct sk_buff **pskb,
6437 +                                    enum ip_conntrack_info ctinfo)
6438 +{
6439 +       struct iphdr *iph = (*pskb)->nh.iph;
6440 +       struct tcphdr *tcph = (void *)iph + iph->ihl*4;
6441 +       char *data = (char *) tcph + tcph->doff * 4;
6442 +       u_int32_t tcplen = (*pskb)->len - iph->ihl*4;
6443 +       u_int32_t datalen = tcplen - tcph->doff*4;
6444 +       struct ip_ct_h225_master *info = &ct->help.ct_h225_info; 
6445 +       u_int32_t newip;
6446 +       u_int16_t port;
6447 +       int i;
6448 +
6449 +       MUST_BE_LOCKED(&ip_h323_lock);
6450 +
6451 +       DEBUGP("h323_signal_address_fixup: %s %s\n",
6452 +               between(info->seq[IP_CT_DIR_ORIGINAL], ntohl(tcph->seq), ntohl(tcph->seq) + datalen)
6453 +                       ? "yes" : "no",
6454 +               between(info->seq[IP_CT_DIR_REPLY], ntohl(tcph->seq), ntohl(tcph->seq) + datalen)
6455 +                       ? "yes" : "no");
6456 +       if (!(between(info->seq[IP_CT_DIR_ORIGINAL], ntohl(tcph->seq), ntohl(tcph->seq) + datalen)
6457 +               || between(info->seq[IP_CT_DIR_REPLY], ntohl(tcph->seq), ntohl(tcph->seq) + datalen)))
6458 +               return 1;
6459 +
6460 +       DEBUGP("h323_signal_address_fixup: offsets %u + 6  and %u + 6 in %u\n", 
6461 +               info->offset[IP_CT_DIR_ORIGINAL], 
6462 +               info->offset[IP_CT_DIR_REPLY],
6463 +               tcplen);
6464 +       DUMP_TUPLE(&ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple);
6465 +       DUMP_TUPLE(&ct->tuplehash[IP_CT_DIR_REPLY].tuple);
6466 +
6467 +       for (i = 0; i < IP_CT_DIR_MAX; i++) {
6468 +               DEBUGP("h323_signal_address_fixup: %s %s\n",
6469 +                       info->dir == IP_CT_DIR_ORIGINAL ? "original" : "reply",
6470 +                       i == IP_CT_DIR_ORIGINAL ? "caller" : "callee");
6471 +               if (!between(info->seq[i], ntohl(tcph->seq), 
6472 +                            ntohl(tcph->seq) + datalen))
6473 +                       continue;
6474 +               if (!between(info->seq[i] + 6, ntohl(tcph->seq),
6475 +                            ntohl(tcph->seq) + datalen)) {
6476 +                       /* Partial retransmisison. It's a cracker being funky. */
6477 +                       if (net_ratelimit()) {
6478 +                               printk("H.323_NAT: partial packet %u/6 in %u/%u\n",
6479 +                                    info->seq[i],
6480 +                                    ntohl(tcph->seq),
6481 +                                    ntohl(tcph->seq) + datalen);
6482 +                       }
6483 +                       return 0;
6484 +               }
6485 +
6486 +               /* Change address inside packet to match way we're mapping
6487 +                  this connection. */
6488 +               if (i == IP_CT_DIR_ORIGINAL) {
6489 +                       newip = ct->tuplehash[!info->dir].tuple.dst.ip;
6490 +                       port = ct->tuplehash[!info->dir].tuple.dst.u.tcp.port;
6491 +               } else {
6492 +                       newip = ct->tuplehash[!info->dir].tuple.src.ip;
6493 +                       port = ct->tuplehash[!info->dir].tuple.src.u.tcp.port;
6494 +               }
6495 +
6496 +               DEBUGP("h323_signal_address_fixup: orig %s IP:port %u.%u.%u.%u:%u\n", 
6497 +                       i == IP_CT_DIR_ORIGINAL ? "source" : "dest  ", 
6498 +                       NIPQUAD(*((u_int32_t *)(data + info->offset[i]))), 
6499 +                       ntohs(*((u_int16_t *)(data + info->offset[i] + 4))));
6500 +
6501 +               /* Modify the packet */
6502 +               *(u_int32_t *)(data + info->offset[i]) = newip;
6503 +               *(u_int16_t *)(data + info->offset[i] + 4) = port;
6504 +       
6505 +               DEBUGP("h323_signal_address_fixup:  new %s IP:port %u.%u.%u.%u:%u\n", 
6506 +                       i == IP_CT_DIR_ORIGINAL ? "source" : "dest  ", 
6507 +                       NIPQUAD(*((u_int32_t *)(data + info->offset[i]))), 
6508 +                       ntohs(*((u_int16_t *)(data + info->offset[i] + 4))));
6509 +       }
6510 +
6511 +       /* fix checksum information */
6512 +
6513 +       (*pskb)->csum = csum_partial((char *)tcph + tcph->doff*4,
6514 +                                    datalen, 0);
6515 +
6516 +       tcph->check = 0;
6517 +       tcph->check = tcp_v4_check(tcph, tcplen, iph->saddr, iph->daddr,
6518 +                                  csum_partial((char *)tcph, tcph->doff*4,
6519 +                                          (*pskb)->csum));
6520 +       ip_send_check(iph);
6521 +
6522 +       return 1;
6523 +}
6524 +
6525 +static int h323_data_fixup(struct ip_ct_h225_expect *info,
6526 +                          struct ip_conntrack *ct,
6527 +                          struct sk_buff **pskb,
6528 +                          enum ip_conntrack_info ctinfo,
6529 +                          struct ip_conntrack_expect *expect)
6530 +{
6531 +       u_int32_t newip;
6532 +       u_int16_t port;
6533 +       struct ip_conntrack_tuple newtuple;
6534 +       struct iphdr *iph = (*pskb)->nh.iph;
6535 +       struct tcphdr *tcph = (void *)iph + iph->ihl*4;
6536 +       char *data = (char *) tcph + tcph->doff * 4;
6537 +       u_int32_t tcplen = (*pskb)->len - iph->ihl*4;
6538 +       struct ip_ct_h225_master *master_info = &ct->help.ct_h225_info;
6539 +       int is_h225;
6540 +
6541 +       MUST_BE_LOCKED(&ip_h323_lock);
6542 +       DEBUGP("h323_data_fixup: offset %u + 6 in %u\n", info->offset, tcplen);
6543 +       DUMP_TUPLE(&ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple);
6544 +       DUMP_TUPLE(&ct->tuplehash[IP_CT_DIR_REPLY].tuple);
6545 +
6546 +       if (!between(expect->seq + 6, ntohl(tcph->seq),
6547 +                   ntohl(tcph->seq) + tcplen - tcph->doff * 4)) {
6548 +               /* Partial retransmisison. It's a cracker being funky. */
6549 +               if (net_ratelimit()) {
6550 +                       printk("H.323_NAT: partial packet %u/6 in %u/%u\n",
6551 +                            expect->seq,
6552 +                            ntohl(tcph->seq),
6553 +                            ntohl(tcph->seq) + tcplen - tcph->doff * 4);
6554 +               }
6555 +               return 0;
6556 +       }
6557 +
6558 +       /* Change address inside packet to match way we're mapping
6559 +          this connection. */
6560 +       if (info->dir == IP_CT_DIR_REPLY) {
6561 +               /* Must be where client thinks server is */
6562 +               newip = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.ip;
6563 +               /* Expect something from client->server */
6564 +               newtuple.src.ip = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.ip;
6565 +               newtuple.dst.ip = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.ip;
6566 +       } else {
6567 +               /* Must be where server thinks client is */
6568 +               newip = ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.ip;
6569 +               /* Expect something from server->client */
6570 +               newtuple.src.ip = ct->tuplehash[IP_CT_DIR_REPLY].tuple.src.ip;
6571 +               newtuple.dst.ip = ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.ip;
6572 +       }
6573 +
6574 +       is_h225 = (master_info->is_h225 == H225_PORT);
6575 +
6576 +       if (is_h225) {
6577 +               newtuple.dst.protonum = IPPROTO_TCP;
6578 +               newtuple.src.u.tcp.port = expect->tuple.src.u.tcp.port;
6579 +       } else {
6580 +               newtuple.dst.protonum = IPPROTO_UDP;
6581 +               newtuple.src.u.udp.port = expect->tuple.src.u.udp.port;
6582 +       }
6583 +       
6584 +       /* Try to get same port: if not, try to change it. */
6585 +       for (port = ntohs(info->port); port != 0; port++) {
6586 +               if (is_h225)
6587 +                       newtuple.dst.u.tcp.port = htons(port);
6588 +               else
6589 +                       newtuple.dst.u.udp.port = htons(port);
6590 +
6591 +               if (ip_conntrack_change_expect(expect, &newtuple) == 0)
6592 +                       break;
6593 +       }
6594 +       if (port == 0) {
6595 +               DEBUGP("h323_data_fixup: no free port found!\n");
6596 +               return 0;
6597 +       }
6598 +
6599 +       port = htons(port);
6600 +
6601 +       DEBUGP("h323_data_fixup: orig IP:port %u.%u.%u.%u:%u\n", 
6602 +               NIPQUAD(*((u_int32_t *)(data + info->offset))), 
6603 +               ntohs(*((u_int16_t *)(data + info->offset + 4))));
6604 +
6605 +       /* Modify the packet */
6606 +       *(u_int32_t *)(data + info->offset) = newip;
6607 +       *(u_int16_t *)(data + info->offset + 4) = port;
6608 +       
6609 +       DEBUGP("h323_data_fixup: new IP:port %u.%u.%u.%u:%u\n", 
6610 +               NIPQUAD(*((u_int32_t *)(data + info->offset))), 
6611 +               ntohs(*((u_int16_t *)(data + info->offset + 4))));
6612 +
6613 +       /* fix checksum information  */
6614 +       /* FIXME: usually repeated multiple times in the case of H.245! */
6615 +
6616 +       (*pskb)->csum = csum_partial((char *)tcph + tcph->doff*4,
6617 +                                    tcplen - tcph->doff*4, 0);
6618 +
6619 +       tcph->check = 0;
6620 +       tcph->check = tcp_v4_check(tcph, tcplen, iph->saddr, iph->daddr,
6621 +                                  csum_partial((char *)tcph, tcph->doff*4,
6622 +                                          (*pskb)->csum));
6623 +       ip_send_check(iph);
6624 +
6625 +       return 1;
6626 +}
6627 +
6628 +static unsigned int h225_nat_help(struct ip_conntrack *ct,
6629 +                                 struct ip_conntrack_expect *exp,
6630 +                                 struct ip_nat_info *info,
6631 +                                 enum ip_conntrack_info ctinfo,
6632 +                                 unsigned int hooknum,
6633 +                                 struct sk_buff **pskb)
6634 +{
6635 +       int dir;
6636 +       struct ip_ct_h225_expect *exp_info;
6637 +       
6638 +       /* Only mangle things once: original direction in POST_ROUTING
6639 +          and reply direction on PRE_ROUTING. */
6640 +       dir = CTINFO2DIR(ctinfo);
6641 +       DEBUGP("nat_h323: dir %s at hook %s\n",
6642 +              dir == IP_CT_DIR_ORIGINAL ? "ORIG" : "REPLY",
6643 +              hooknum == NF_IP_POST_ROUTING ? "POSTROUTING"
6644 +              : hooknum == NF_IP_PRE_ROUTING ? "PREROUTING"
6645 +              : hooknum == NF_IP_LOCAL_OUT ? "OUTPUT" : "???");
6646 +       if (!((hooknum == NF_IP_POST_ROUTING && dir == IP_CT_DIR_ORIGINAL)
6647 +             || (hooknum == NF_IP_PRE_ROUTING && dir == IP_CT_DIR_REPLY))) {
6648 +               DEBUGP("nat_h323: Not touching dir %s at hook %s\n",
6649 +                      dir == IP_CT_DIR_ORIGINAL ? "ORIG" : "REPLY",
6650 +                      hooknum == NF_IP_POST_ROUTING ? "POSTROUTING"
6651 +                      : hooknum == NF_IP_PRE_ROUTING ? "PREROUTING"
6652 +                      : hooknum == NF_IP_LOCAL_OUT ? "OUTPUT" : "???");
6653 +               return NF_ACCEPT;
6654 +       }
6655 +
6656 +       if (!exp) {
6657 +               LOCK_BH(&ip_h323_lock);
6658 +               if (!h323_signal_address_fixup(ct, pskb, ctinfo)) {
6659 +                       UNLOCK_BH(&ip_h323_lock);
6660 +                       return NF_DROP;
6661 +               }
6662 +               UNLOCK_BH(&ip_h323_lock);
6663 +               return NF_ACCEPT;
6664 +       }
6665 +               
6666 +       exp_info = &exp->help.exp_h225_info;
6667 +
6668 +       LOCK_BH(&ip_h323_lock);
6669 +       if (!h323_data_fixup(exp_info, ct, pskb, ctinfo, exp)) {
6670 +               UNLOCK_BH(&ip_h323_lock);
6671 +               return NF_DROP;
6672 +       }
6673 +       UNLOCK_BH(&ip_h323_lock);
6674 +
6675 +       return NF_ACCEPT;
6676 +}
6677 +
6678 +static struct ip_nat_helper h225 = 
6679 +       { { NULL, NULL },
6680 +         "H.225",                                      /* name */
6681 +         IP_NAT_HELPER_F_ALWAYS,                       /* flags */
6682 +         THIS_MODULE,                                  /* module */
6683 +         { { 0, { .tcp = { __constant_htons(H225_PORT) } } },  /* tuple */
6684 +           { 0, { 0 }, IPPROTO_TCP } },
6685 +         { { 0, { .tcp = { 0xFFFF } } },               /* mask */
6686 +           { 0, { 0 }, 0xFFFF } },
6687 +         h225_nat_help,                                /* helper */
6688 +         h225_nat_expected                             /* expectfn */
6689 +       };
6690 +
6691 +static int __init init(void)
6692 +{
6693 +       int ret;
6694 +       
6695 +       ret = ip_nat_helper_register(&h225);
6696 +
6697 +       if (ret != 0)
6698 +               printk("ip_nat_h323: cannot initialize the module!\n");
6699 +
6700 +       return ret;
6701 +}
6702 +
6703 +static void __exit fini(void)
6704 +{
6705 +       ip_nat_helper_unregister(&h225);
6706 +}
6707 +
6708 +module_init(init);
6709 +module_exit(fini);
6710 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ip_nat_mms.c linux-2.6.6/net/ipv4/netfilter/ip_nat_mms.c
6711 --- linux-2.6.6.org/net/ipv4/netfilter/ip_nat_mms.c     1970-01-01 01:00:00.000000000 +0100
6712 +++ linux-2.6.6/net/ipv4/netfilter/ip_nat_mms.c 2004-05-18 14:28:50.000000000 +0200
6713 @@ -0,0 +1,350 @@
6714 +/* MMS extension for TCP NAT alteration.
6715 + * (C) 2002 by Filip Sneppe <filip.sneppe@cronos.be>
6716 + * based on ip_nat_ftp.c and ip_nat_irc.c
6717 + *
6718 + * ip_nat_mms.c v0.3 2002-09-22
6719 + *
6720 + *      This program is free software; you can redistribute it and/or
6721 + *      modify it under the terms of the GNU General Public License
6722 + *      as published by the Free Software Foundation; either version
6723 + *      2 of the License, or (at your option) any later version.
6724 + *
6725 + *      Module load syntax:
6726 + *      insmod ip_nat_mms.o ports=port1,port2,...port<MAX_PORTS>
6727 + *
6728 + *      Please give the ports of all MMS servers You wish to connect to.
6729 + *      If you don't specify ports, the default will be TCP port 1755.
6730 + *
6731 + *      More info on MMS protocol, firewalls and NAT:
6732 + *      http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwmt/html/MMSFirewall.asp
6733 + *      http://www.microsoft.com/windows/windowsmedia/serve/firewall.asp
6734 + *
6735 + *      The SDP project people are reverse-engineering MMS:
6736 + *      http://get.to/sdp
6737 + */
6738 +
6739 +/* FIXME: issue with UDP & fragmentation with this URL: 
6740 +   http://www.cnn.com/video/world/2002/01/21/jb.shoe.bomb.cafe.cnn.low.asx 
6741 +   may be related to out-of-order first packets:
6742 +   basically the expectation is set up correctly, then the server sends
6743 +   a first UDP packet which is fragmented plus arrives out-of-order.
6744 +   the MASQUERADING firewall with ip_nat_mms loaded responds with
6745 +   an ICMP unreachable back to the server */
6746 +
6747 +#include <linux/module.h>
6748 +#include <linux/netfilter_ipv4.h>
6749 +#include <linux/ip.h>
6750 +#include <linux/tcp.h>
6751 +#include <net/tcp.h>
6752 +#include <linux/netfilter_ipv4/ip_nat.h>
6753 +#include <linux/netfilter_ipv4/ip_nat_helper.h>
6754 +#include <linux/netfilter_ipv4/ip_nat_rule.h>
6755 +#include <linux/netfilter_ipv4/ip_conntrack_mms.h>
6756 +#include <linux/netfilter_ipv4/ip_conntrack_helper.h>
6757 +
6758 +#if 0 
6759 +#define DEBUGP printk
6760 +#define DUMP_BYTES(address, counter)                                \
6761 +({                                                                  \
6762 +       int temp_counter;                                           \
6763 +       for(temp_counter=0; temp_counter<counter; ++temp_counter) { \
6764 +               DEBUGP("%u ", (u8)*(address+temp_counter));         \
6765 +       };                                                          \
6766 +       DEBUGP("\n");                                               \
6767 +})
6768 +#else
6769 +#define DEBUGP(format, args...)
6770 +#define DUMP_BYTES(address, counter)
6771 +#endif
6772 +
6773 +#define MAX_PORTS 8
6774 +static int ports[MAX_PORTS];
6775 +static int ports_c = 0;
6776 +
6777 +#ifdef MODULE_PARM
6778 +MODULE_PARM(ports, "1-" __MODULE_STRING(MAX_PORTS) "i");
6779 +#endif
6780 +
6781 +MODULE_AUTHOR("Filip Sneppe <filip.sneppe@cronos.be>");
6782 +MODULE_DESCRIPTION("Microsoft Windows Media Services (MMS) NAT module");
6783 +MODULE_LICENSE("GPL");
6784 +
6785 +DECLARE_LOCK_EXTERN(ip_mms_lock);
6786 +
6787 +/* FIXME: Time out? --RR */
6788 +
6789 +static int mms_data_fixup(const struct ip_ct_mms_expect *ct_mms_info,
6790 +                          struct ip_conntrack *ct,
6791 +                          struct sk_buff **pskb,
6792 +                          enum ip_conntrack_info ctinfo,
6793 +                          struct ip_conntrack_expect *expect)
6794 +{
6795 +       u_int32_t newip;
6796 +       struct ip_conntrack_tuple t;
6797 +       struct iphdr *iph = (*pskb)->nh.iph;
6798 +       struct tcphdr *tcph = (void *) iph + iph->ihl * 4;
6799 +       char *data = (char *)tcph + tcph->doff * 4;
6800 +       int i, j, k, port;
6801 +       u_int16_t mms_proto;
6802 +
6803 +       u_int32_t *mms_chunkLenLV    = (u_int32_t *)(data + MMS_SRV_CHUNKLENLV_OFFSET);
6804 +       u_int32_t *mms_chunkLenLM    = (u_int32_t *)(data + MMS_SRV_CHUNKLENLM_OFFSET);
6805 +       u_int32_t *mms_messageLength = (u_int32_t *)(data + MMS_SRV_MESSAGELENGTH_OFFSET);
6806 +
6807 +       int zero_padding;
6808 +
6809 +       char buffer[28];         /* "\\255.255.255.255\UDP\65635" * 2 (for unicode) */
6810 +       char unicode_buffer[75]; /* 27*2 (unicode) + 20 + 1 */
6811 +       char proto_string[6];
6812 +       
6813 +       MUST_BE_LOCKED(&ip_mms_lock);
6814 +
6815 +       /* what was the protocol again ? */
6816 +       mms_proto = expect->tuple.dst.protonum;
6817 +       sprintf(proto_string, "%u", mms_proto);
6818 +       
6819 +       DEBUGP("ip_nat_mms: mms_data_fixup: info (seq %u + %u) in %u, proto %s\n",
6820 +              expect->seq, ct_mms_info->len, ntohl(tcph->seq),
6821 +              mms_proto == IPPROTO_UDP ? "UDP"
6822 +              : mms_proto == IPPROTO_TCP ? "TCP":proto_string);
6823 +       
6824 +       newip = ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.ip;
6825 +
6826 +       /* Alter conntrack's expectations. */
6827 +       t = expect->tuple;
6828 +       t.dst.ip = newip;
6829 +       for (port = ct_mms_info->port; port != 0; port++) {
6830 +               t.dst.u.tcp.port = htons(port);
6831 +               if (ip_conntrack_change_expect(expect, &t) == 0) {
6832 +                       DEBUGP("ip_nat_mms: mms_data_fixup: using port %d\n", port);
6833 +                       break;
6834 +               }
6835 +       }
6836 +       
6837 +       if(port == 0)
6838 +               return 0;
6839 +
6840 +       sprintf(buffer, "\\\\%u.%u.%u.%u\\%s\\%u",
6841 +               NIPQUAD(newip),
6842 +               expect->tuple.dst.protonum == IPPROTO_UDP ? "UDP"
6843 +               : expect->tuple.dst.protonum == IPPROTO_TCP ? "TCP":proto_string,
6844 +               port);
6845 +       DEBUGP("ip_nat_mms: new unicode string=%s\n", buffer);
6846 +       
6847 +       memset(unicode_buffer, 0, sizeof(char)*75);
6848 +
6849 +       for (i=0; i<strlen(buffer); ++i)
6850 +               *(unicode_buffer+i*2)=*(buffer+i);
6851 +       
6852 +       DEBUGP("ip_nat_mms: mms_data_fixup: padding: %u len: %u\n", ct_mms_info->padding, ct_mms_info->len);
6853 +       DEBUGP("ip_nat_mms: mms_data_fixup: offset: %u\n", MMS_SRV_UNICODE_STRING_OFFSET+ct_mms_info->len);
6854 +       DUMP_BYTES(data+MMS_SRV_UNICODE_STRING_OFFSET, 60);
6855 +       
6856 +       /* add end of packet to it */
6857 +       for (j=0; j<ct_mms_info->padding; ++j) {
6858 +               DEBUGP("ip_nat_mms: mms_data_fixup: i=%u j=%u byte=%u\n", 
6859 +                      i, j, (u8)*(data+MMS_SRV_UNICODE_STRING_OFFSET+ct_mms_info->len+j));
6860 +               *(unicode_buffer+i*2+j) = *(data+MMS_SRV_UNICODE_STRING_OFFSET+ct_mms_info->len+j);
6861 +       }
6862 +
6863 +       /* pad with zeroes at the end ? see explanation of weird math below */
6864 +       zero_padding = (8-(strlen(buffer)*2 + ct_mms_info->padding + 4)%8)%8;
6865 +       for (k=0; k<zero_padding; ++k)
6866 +               *(unicode_buffer+i*2+j+k)= (char)0;
6867 +       
6868 +       DEBUGP("ip_nat_mms: mms_data_fixup: zero_padding = %u\n", zero_padding);
6869 +       DEBUGP("ip_nat_mms: original=> chunkLenLV=%u chunkLenLM=%u messageLength=%u\n",
6870 +              *mms_chunkLenLV, *mms_chunkLenLM, *mms_messageLength);
6871 +       
6872 +       /* explanation, before I forget what I did:
6873 +          strlen(buffer)*2 + ct_mms_info->padding + 4 must be divisable by 8;
6874 +          divide by 8 and add 3 to compute the mms_chunkLenLM field,
6875 +          but note that things may have to be padded with zeroes to align by 8 
6876 +          bytes, hence we add 7 and divide by 8 to get the correct length */ 
6877 +       *mms_chunkLenLM    = (u_int32_t) (3+(strlen(buffer)*2+ct_mms_info->padding+11)/8);
6878 +       *mms_chunkLenLV    = *mms_chunkLenLM+2;
6879 +       *mms_messageLength = *mms_chunkLenLV*8;
6880 +       
6881 +       DEBUGP("ip_nat_mms: modified=> chunkLenLV=%u chunkLenLM=%u messageLength=%u\n",
6882 +              *mms_chunkLenLV, *mms_chunkLenLM, *mms_messageLength);
6883 +       
6884 +       ip_nat_mangle_tcp_packet(pskb, ct, ctinfo, 
6885 +                                expect->seq - ntohl(tcph->seq),
6886 +                                ct_mms_info->len + ct_mms_info->padding, unicode_buffer,
6887 +                                strlen(buffer)*2 + ct_mms_info->padding + zero_padding);
6888 +       DUMP_BYTES(unicode_buffer, 60);
6889 +       
6890 +       return 1;
6891 +}
6892 +
6893 +static unsigned int
6894 +mms_nat_expected(struct sk_buff **pskb,
6895 +                 unsigned int hooknum,
6896 +                 struct ip_conntrack *ct,
6897 +                 struct ip_nat_info *info)
6898 +{
6899 +       struct ip_nat_multi_range mr;
6900 +       u_int32_t newdstip, newsrcip, newip;
6901 +
6902 +       struct ip_conntrack *master = master_ct(ct);
6903 +
6904 +       IP_NF_ASSERT(info);
6905 +       IP_NF_ASSERT(master);
6906 +
6907 +       IP_NF_ASSERT(!(info->initialized & (1 << HOOK2MANIP(hooknum))));
6908 +
6909 +       DEBUGP("ip_nat_mms: mms_nat_expected: We have a connection!\n");
6910 +
6911 +       newdstip = master->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.ip;
6912 +       newsrcip = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.ip;
6913 +       DEBUGP("ip_nat_mms: mms_nat_expected: hook %s: newsrc->newdst %u.%u.%u.%u->%u.%u.%u.%u\n",
6914 +              hooknum == NF_IP_POST_ROUTING ? "POSTROUTING"
6915 +              : hooknum == NF_IP_PRE_ROUTING ? "PREROUTING"
6916 +              : hooknum == NF_IP_LOCAL_OUT ? "OUTPUT" : "???",
6917 +              NIPQUAD(newsrcip), NIPQUAD(newdstip));
6918 +
6919 +       if (HOOK2MANIP(hooknum) == IP_NAT_MANIP_SRC)
6920 +               newip = newsrcip;
6921 +       else
6922 +               newip = newdstip;
6923 +
6924 +       DEBUGP("ip_nat_mms: mms_nat_expected: IP to %u.%u.%u.%u\n", NIPQUAD(newip));
6925 +
6926 +       mr.rangesize = 1;
6927 +       /* We don't want to manip the per-protocol, just the IPs. */
6928 +       mr.range[0].flags = IP_NAT_RANGE_MAP_IPS;
6929 +       mr.range[0].min_ip = mr.range[0].max_ip = newip;
6930 +
6931 +       return ip_nat_setup_info(ct, &mr, hooknum);
6932 +}
6933 +
6934 +
6935 +static unsigned int mms_nat_help(struct ip_conntrack *ct,
6936 +                        struct ip_conntrack_expect *exp,
6937 +                        struct ip_nat_info *info,
6938 +                        enum ip_conntrack_info ctinfo,
6939 +                        unsigned int hooknum,
6940 +                        struct sk_buff **pskb)
6941 +{
6942 +       struct iphdr *iph = (*pskb)->nh.iph;
6943 +       struct tcphdr *tcph = (void *) iph + iph->ihl * 4;
6944 +       unsigned int datalen;
6945 +       int dir;
6946 +       struct ip_ct_mms_expect *ct_mms_info;
6947 +
6948 +       if (!exp)
6949 +               DEBUGP("ip_nat_mms: no exp!!");
6950 +
6951 +       ct_mms_info = &exp->help.exp_mms_info;
6952 +       
6953 +       /* Only mangle things once: original direction in POST_ROUTING
6954 +          and reply direction on PRE_ROUTING. */
6955 +       dir = CTINFO2DIR(ctinfo);
6956 +       if (!((hooknum == NF_IP_POST_ROUTING && dir == IP_CT_DIR_ORIGINAL)
6957 +           ||(hooknum == NF_IP_PRE_ROUTING && dir == IP_CT_DIR_REPLY))) {
6958 +               DEBUGP("ip_nat_mms: mms_nat_help: not touching dir %s at hook %s\n",
6959 +                      dir == IP_CT_DIR_ORIGINAL ? "ORIG" : "REPLY",
6960 +                      hooknum == NF_IP_POST_ROUTING ? "POSTROUTING"
6961 +                      : hooknum == NF_IP_PRE_ROUTING ? "PREROUTING"
6962 +                      : hooknum == NF_IP_LOCAL_OUT ? "OUTPUT" : "???");
6963 +               return NF_ACCEPT;
6964 +       }
6965 +       DEBUGP("ip_nat_mms: mms_nat_help: beyond not touching (dir %s at hook %s)\n",
6966 +              dir == IP_CT_DIR_ORIGINAL ? "ORIG" : "REPLY",
6967 +              hooknum == NF_IP_POST_ROUTING ? "POSTROUTING"
6968 +              : hooknum == NF_IP_PRE_ROUTING ? "PREROUTING"
6969 +              : hooknum == NF_IP_LOCAL_OUT ? "OUTPUT" : "???");
6970 +       
6971 +       datalen = (*pskb)->len - iph->ihl * 4 - tcph->doff * 4;
6972 +       
6973 +       DEBUGP("ip_nat_mms: mms_nat_help: %u+%u=%u %u %u\n", exp->seq, ct_mms_info->len,
6974 +              exp->seq + ct_mms_info->len,
6975 +              ntohl(tcph->seq),
6976 +              ntohl(tcph->seq) + datalen);
6977 +       
6978 +       LOCK_BH(&ip_mms_lock);
6979 +       /* Check wether the whole IP/proto/port pattern is carried in the payload */
6980 +       if (between(exp->seq + ct_mms_info->len,
6981 +           ntohl(tcph->seq),
6982 +           ntohl(tcph->seq) + datalen)) {
6983 +               if (!mms_data_fixup(ct_mms_info, ct, pskb, ctinfo, exp)) {
6984 +                       UNLOCK_BH(&ip_mms_lock);
6985 +                       return NF_DROP;
6986 +               }
6987 +       } else {
6988 +               /* Half a match?  This means a partial retransmisison.
6989 +                  It's a cracker being funky. */
6990 +               if (net_ratelimit()) {
6991 +                       printk("ip_nat_mms: partial packet %u/%u in %u/%u\n",
6992 +                              exp->seq, ct_mms_info->len,
6993 +                              ntohl(tcph->seq),
6994 +                              ntohl(tcph->seq) + datalen);
6995 +               }
6996 +               UNLOCK_BH(&ip_mms_lock);
6997 +               return NF_DROP;
6998 +       }
6999 +       UNLOCK_BH(&ip_mms_lock);
7000 +       
7001 +       return NF_ACCEPT;
7002 +}
7003 +
7004 +static struct ip_nat_helper mms[MAX_PORTS];
7005 +static char mms_names[MAX_PORTS][10];
7006 +
7007 +/* Not __exit: called from init() */
7008 +static void fini(void)
7009 +{
7010 +       int i;
7011 +
7012 +       for (i = 0; (i < MAX_PORTS) && ports[i]; i++) {
7013 +               DEBUGP("ip_nat_mms: unregistering helper for port %d\n", ports[i]);
7014 +               ip_nat_helper_unregister(&mms[i]);
7015 +       }
7016 +}
7017 +
7018 +static int __init init(void)
7019 +{
7020 +       int i, ret = 0;
7021 +       char *tmpname;
7022 +
7023 +       if (ports[0] == 0)
7024 +               ports[0] = MMS_PORT;
7025 +
7026 +       for (i = 0; (i < MAX_PORTS) && ports[i]; i++) {
7027 +
7028 +               memset(&mms[i], 0, sizeof(struct ip_nat_helper));
7029 +
7030 +               mms[i].tuple.dst.protonum = IPPROTO_TCP;
7031 +               mms[i].tuple.src.u.tcp.port = htons(ports[i]);
7032 +               mms[i].mask.dst.protonum = 0xFFFF;
7033 +               mms[i].mask.src.u.tcp.port = 0xFFFF;
7034 +               mms[i].help = mms_nat_help;
7035 +               mms[i].me = THIS_MODULE;
7036 +               mms[i].flags = 0;
7037 +               mms[i].expect = mms_nat_expected;
7038 +
7039 +               tmpname = &mms_names[i][0];
7040 +               if (ports[i] == MMS_PORT)
7041 +                       sprintf(tmpname, "mms");
7042 +               else
7043 +                       sprintf(tmpname, "mms-%d", i);
7044 +               mms[i].name = tmpname;
7045 +
7046 +               DEBUGP("ip_nat_mms: register helper for port %d\n",
7047 +                               ports[i]);
7048 +               ret = ip_nat_helper_register(&mms[i]);
7049 +
7050 +               if (ret) {
7051 +                       printk("ip_nat_mms: error registering "
7052 +                              "helper for port %d\n", ports[i]);
7053 +                       fini();
7054 +                       return ret;
7055 +               }
7056 +               ports_c++;
7057 +       }
7058 +
7059 +       return ret;
7060 +}
7061 +
7062 +module_init(init);
7063 +module_exit(fini);
7064 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ip_nat_quake3.c linux-2.6.6/net/ipv4/netfilter/ip_nat_quake3.c
7065 --- linux-2.6.6.org/net/ipv4/netfilter/ip_nat_quake3.c  1970-01-01 01:00:00.000000000 +0100
7066 +++ linux-2.6.6/net/ipv4/netfilter/ip_nat_quake3.c      2004-05-18 14:28:50.000000000 +0200
7067 @@ -0,0 +1,249 @@
7068 +/* Quake3 extension for UDP NAT alteration.
7069 + * (C) 2002 by Filip Sneppe <filip.sneppe@cronos.be>
7070 + * based on ip_nat_ftp.c and ip_nat_tftp.c
7071 + *
7072 + * ip_nat_quake3.c v0.0.3 2002-08-31
7073 + *
7074 + *      This program is free software; you can redistribute it and/or
7075 + *      modify it under the terms of the GNU General Public License
7076 + *      as published by the Free Software Foundation; either version
7077 + *      2 of the License, or (at your option) any later version.
7078 + *
7079 + *      Module load syntax:
7080 + *      insmod ip_nat_quake3.o ports=port1,port2,...port<MAX_PORTS>
7081 + *
7082 + *      please give the ports of all Quake3 master servers You wish to
7083 + *      connect to. If you don't specify ports, the default will be UDP
7084 + *      port 27950.
7085 + *
7086 + *      Thanks to the Ethereal folks for their analysis of the Quake3 protocol.
7087 + *
7088 + *      Notes: 
7089 + *      - If you're one of those people who would try anything to lower
7090 + *        latency while playing Quake (and who isn't :-) ), you may want to
7091 + *        consider not loading ip_nat_quake3 at all and just MASQUERADE all
7092 + *        outgoing UDP traffic.
7093 + *        This will make ip_conntrack_quake3 add the necessary expectations,
7094 + *        but there will be no overhead for client->server UDP streams. If
7095 + *        ip_nat_quake3 is loaded, quake3_nat_expected will be called per NAT
7096 + *        hook for every packet in the client->server UDP stream.
7097 + *      - Only SNAT/MASQUEARDE targets are useful for ip_nat_quake3.
7098 + *        The IP addresses in the master connection payload (=IP addresses
7099 + *        of Quake servers) have no relation with the master server so
7100 + *        DNAT'ing the master connection to a server should not change the
7101 + *        expected connections.
7102 + *      - Not tested due to lack of equipment:
7103 + *        - multiple Quake3 clients behind one MASQUERADE gateway
7104 + *        - what if Quake3 client is running on router too
7105 + */
7106 +
7107 +#include <linux/module.h>
7108 +#include <linux/netfilter_ipv4.h>
7109 +#include <linux/ip.h>
7110 +#include <linux/udp.h>
7111 +
7112 +#include <linux/netfilter.h>
7113 +#include <linux/netfilter_ipv4/ip_tables.h>
7114 +#include <linux/netfilter_ipv4/ip_conntrack_helper.h>
7115 +#include <linux/netfilter_ipv4/ip_conntrack_quake3.h>
7116 +#include <linux/netfilter_ipv4/ip_nat_helper.h>
7117 +#include <linux/netfilter_ipv4/ip_nat_rule.h>
7118 +
7119 +MODULE_AUTHOR("Filip Sneppe <filip.sneppe@cronos.be>");
7120 +MODULE_DESCRIPTION("Netfilter NAT helper for Quake III Arena");
7121 +MODULE_LICENSE("GPL");
7122 +
7123 +#define MAX_PORTS 8
7124 +
7125 +static int ports[MAX_PORTS];
7126 +static int ports_c = 0;
7127 +#ifdef MODULE_PARM
7128 +MODULE_PARM(ports,"1-" __MODULE_STRING(MAX_PORTS) "i");
7129 +MODULE_PARM_DESC(ports, "port numbers of Quake III master servers");
7130 +#endif
7131 +
7132 +/* Quake3 master server reply will add > 100 expectations per reply packet; when
7133 +   doing lots of printk's, klogd may not be able to read /proc/kmsg fast enough */
7134 +#if 0 
7135 +#define DEBUGP printk
7136 +#else
7137 +#define DEBUGP(format, args...)
7138 +#endif
7139 +
7140 +static struct quake3_search quake3s_nat = { "****", "getserversResponse", sizeof("getserversResponse") - 1 };
7141 +
7142 +static unsigned int 
7143 +quake3_nat_help(struct ip_conntrack *ct,
7144 +                struct ip_conntrack_expect *exp,
7145 +                struct ip_nat_info *info,
7146 +                enum ip_conntrack_info ctinfo,
7147 +                unsigned int hooknum,
7148 +                struct sk_buff **pskb)
7149 +{
7150 +       struct iphdr *iph = (*pskb)->nh.iph;
7151 +       struct udphdr *udph = (void *)iph + iph->ihl * 4;
7152 +       struct ip_conntrack_tuple repl;
7153 +       int dir = CTINFO2DIR(ctinfo);
7154 +       int i;
7155 +       
7156 +       DEBUGP("ip_nat_quake3: quake3_nat_help, direction: %s hook: %s\n",
7157 +              dir == IP_CT_DIR_ORIGINAL ? "ORIG" : "REPLY",
7158 +              hooknum == NF_IP_POST_ROUTING ? "POSTROUTING"
7159 +              : hooknum == NF_IP_PRE_ROUTING ? "PREROUTING"
7160 +              : hooknum == NF_IP_LOCAL_OUT ? "OUTPUT" : "???"
7161 +             );
7162 +       DUMP_TUPLE(&ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple);
7163 +       DUMP_TUPLE(&ct->tuplehash[IP_CT_DIR_REPLY].tuple);
7164 +       
7165 +       /* Only mangle things once: original direction in POST_ROUTING
7166 +          and reply direction on PRE_ROUTING. */
7167 +       if (!((hooknum == NF_IP_POST_ROUTING && dir == IP_CT_DIR_ORIGINAL)
7168 +           || (hooknum == NF_IP_PRE_ROUTING && dir == IP_CT_DIR_REPLY))) {
7169 +               DEBUGP("ip_nat_quake3: Not touching dir %s at hook %s\n",
7170 +                      dir == IP_CT_DIR_ORIGINAL ? "ORIG" : "REPLY",
7171 +                      hooknum == NF_IP_POST_ROUTING ? "POSTROUTING"
7172 +                      : hooknum == NF_IP_PRE_ROUTING ? "PREROUTING"
7173 +                      : hooknum == NF_IP_LOCAL_OUT ? "OUTPUT" : "????");
7174 +               return NF_ACCEPT;
7175 +       }
7176 +
7177 +       if (!exp) {
7178 +               DEBUGP("no conntrack expectation to modify\n");
7179 +               return NF_ACCEPT;
7180 +       }
7181 +
7182 +       if (strnicmp((const char *)udph + 12, quake3s_nat.pattern, quake3s_nat.plen) == 0) {
7183 +               for(i=31; /* 8 bytes UDP hdr, 4 bytes filler, 18 bytes "getserversResponse", 1 byte "\" */
7184 +                   i+6 < ntohs(udph->len);
7185 +                   i+=7) {
7186 +                       DEBUGP("ip_nat_quake3: adding server at offset %u/%u %u.%u.%u.%u:%u\n", 
7187 +                              i, ntohs(udph->len),
7188 +                              NIPQUAD( (u_int32_t) *( (u_int32_t *)( (int)udph + i ) ) ),
7189 +                              ntohs((__u16) *( (__u16 *)( (int)udph + i + 4 ) ) ) );
7190 +                       
7191 +                       memset(&repl, 0, sizeof(repl));
7192 +
7193 +                       repl.dst.protonum = IPPROTO_UDP;
7194 +                       repl.src.ip = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.ip;
7195 +                       repl.dst.ip = *( (u_int32_t *)( (int)udph + i ) );
7196 +                       repl.dst.u.udp.port = (__u16) *( (__u16 *)( (int)udph + i + 4 )  );
7197 +                       
7198 +                       ip_conntrack_change_expect(exp, &repl);
7199 +               }
7200 +       }
7201 +       return NF_ACCEPT;
7202 +}
7203 +
7204 +static unsigned int 
7205 +quake3_nat_expected(struct sk_buff **pskb,
7206 +                    unsigned int hooknum,
7207 +                    struct ip_conntrack *ct, 
7208 +                    struct ip_nat_info *info) 
7209 +{
7210 +       const struct ip_conntrack *master = ct->master->expectant;
7211 +       struct ip_nat_multi_range mr;
7212 +       u_int32_t newsrcip, newdstip, newip;
7213 +#if 0 
7214 +       const struct ip_conntrack_tuple *repl =
7215 +               &master->tuplehash[IP_CT_DIR_REPLY].tuple;
7216 +       struct iphdr *iph = (*pskb)->nh.iph;
7217 +       struct udphdr *udph = (void *)iph + iph->ihl*4;
7218 +#endif
7219 +
7220 +       DEBUGP("ip_nat_quake3: quake3_nat_expected: here we are\n");
7221 +       DUMP_TUPLE(&ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple);
7222 +
7223 +       IP_NF_ASSERT(info);
7224 +       IP_NF_ASSERT(master);
7225 +       IP_NF_ASSERT(!(info->initialized & (1 << HOOK2MANIP(hooknum))));
7226 +       
7227 +       newdstip = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.ip;
7228 +       newsrcip = master->tuplehash[IP_CT_DIR_REPLY].tuple.dst.ip;
7229 +       
7230 +       if (HOOK2MANIP(hooknum) == IP_NAT_MANIP_SRC) {
7231 +               newip = newsrcip;
7232 +               DEBUGP("hook: %s orig: %u.%u.%u.%u:%u <-> %u.%u.%u.%u:%u "
7233 +                      "newsrc: %u.%u.%u.%u\n",
7234 +                      hooknum == NF_IP_POST_ROUTING ? "POSTROUTING"
7235 +                      : hooknum == NF_IP_PRE_ROUTING ? "PREROUTING"
7236 +                      : hooknum == NF_IP_LOCAL_OUT ? "OUTPUT" : "????",
7237 +                      NIPQUAD((*pskb)->nh.iph->saddr), ntohs(udph->source),
7238 +                      NIPQUAD((*pskb)->nh.iph->daddr), ntohs(udph->dest),
7239 +                      NIPQUAD(newip));
7240 +               
7241 +       } else {
7242 +               newip = newdstip;
7243 +               DEBUGP("hook: %s orig: %u.%u.%u.%u:%u <-> %u.%u.%u.%u:%u "
7244 +                      "newdst: %u.%u.%u.%u\n",
7245 +                      hooknum == NF_IP_POST_ROUTING ? "POSTROUTING"
7246 +                      : hooknum == NF_IP_PRE_ROUTING ? "PREROUTING"
7247 +                      : hooknum == NF_IP_LOCAL_OUT ? "OUTPUT" : "????",
7248 +                      NIPQUAD((*pskb)->nh.iph->saddr), ntohs(udph->source),
7249 +                      NIPQUAD((*pskb)->nh.iph->daddr), ntohs(udph->dest),
7250 +                      NIPQUAD(newip));
7251 +       }
7252 +       
7253 +       mr.rangesize = 1;
7254 +       mr.range[0].flags = IP_NAT_RANGE_MAP_IPS;
7255 +       mr.range[0].min_ip = mr.range[0].max_ip = newip; 
7256 +
7257 +       return ip_nat_setup_info(ct,&mr,hooknum);
7258 +}
7259 +
7260 +static struct ip_nat_helper quake3[MAX_PORTS];
7261 +static char quake3_names[MAX_PORTS][13];  /* quake3-65535 */
7262 +
7263 +static void fini(void)
7264 +{
7265 +       int i;
7266 +       
7267 +       for (i = 0 ; i < ports_c; i++) {
7268 +               DEBUGP("ip_nat_quake3: unregistering helper for port %d\n", ports[i]);
7269 +                      ip_nat_helper_unregister(&quake3[i]);
7270 +       }
7271 +}
7272 +
7273 +static int __init init(void)
7274 +       {
7275 +               int i, ret = 0;
7276 +               char *tmpname;
7277 +
7278 +               if (!ports[0])
7279 +                       ports[0] = QUAKE3_MASTER_PORT;
7280 +               
7281 +               for (i = 0 ; (i < MAX_PORTS) && ports[i] ; i++) {
7282 +                       memset(&quake3[i], 0, sizeof(struct ip_nat_helper));
7283 +
7284 +                       quake3[i].tuple.dst.protonum = IPPROTO_UDP;
7285 +                       quake3[i].tuple.src.u.udp.port = htons(ports[i]);
7286 +                       quake3[i].mask.dst.protonum = 0xFFFF;
7287 +                       quake3[i].mask.src.u.udp.port = 0xFFFF;
7288 +                       quake3[i].help = quake3_nat_help;
7289 +                       quake3[i].flags = 0;
7290 +                       quake3[i].me = THIS_MODULE;
7291 +                       quake3[i].expect = quake3_nat_expected;
7292 +                       
7293 +                       tmpname = &quake3_names[i][0];
7294 +                       if (ports[i] == QUAKE3_MASTER_PORT)
7295 +                               sprintf(tmpname, "quake3");
7296 +                       else
7297 +                               sprintf(tmpname, "quake3-%d", i);
7298 +                       quake3[i].name = tmpname;
7299 +                       
7300 +                       DEBUGP("ip_nat_quake3: registering helper for port %d: name %s\n",
7301 +                              ports[i], quake3[i].name);
7302 +                       ret = ip_nat_helper_register(&quake3[i]);
7303 +                       
7304 +                       if (ret) {
7305 +                               printk("ip_nat_quake3: unable to register helper for port %d\n",
7306 +                                      ports[i]);
7307 +                               fini();
7308 +                               return ret;
7309 +                       }
7310 +                       ports_c++;
7311 +               }
7312 +               return ret;
7313 +       }
7314 +       
7315 +module_init(init);
7316 +module_exit(fini);
7317 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ip_nat_rtsp.c linux-2.6.6/net/ipv4/netfilter/ip_nat_rtsp.c
7318 --- linux-2.6.6.org/net/ipv4/netfilter/ip_nat_rtsp.c    1970-01-01 01:00:00.000000000 +0100
7319 +++ linux-2.6.6/net/ipv4/netfilter/ip_nat_rtsp.c        2004-05-18 14:28:50.000000000 +0200
7320 @@ -0,0 +1,621 @@
7321 +/*
7322 + * RTSP extension for TCP NAT alteration
7323 + * (C) 2003 by Tom Marshall <tmarshall@real.com>
7324 + * based on ip_nat_irc.c
7325 + *
7326 + *      This program is free software; you can redistribute it and/or
7327 + *      modify it under the terms of the GNU General Public License
7328 + *      as published by the Free Software Foundation; either version
7329 + *      2 of the License, or (at your option) any later version.
7330 + *
7331 + * Module load syntax:
7332 + *      insmod ip_nat_rtsp.o ports=port1,port2,...port<MAX_PORTS>
7333 + *                           stunaddr=<address>
7334 + *                           destaction=[auto|strip|none]
7335 + *
7336 + * If no ports are specified, the default will be port 554 only.
7337 + *
7338 + * stunaddr specifies the address used to detect that a client is using STUN.
7339 + * If this address is seen in the destination parameter, it is assumed that
7340 + * the client has already punched a UDP hole in the firewall, so we don't
7341 + * mangle the client_port.  If none is specified, it is autodetected.  It
7342 + * only needs to be set if you have multiple levels of NAT.  It should be
7343 + * set to the external address that the STUN clients detect.  Note that in
7344 + * this case, it will not be possible for clients to use UDP with servers
7345 + * between the NATs.
7346 + *
7347 + * If no destaction is specified, auto is used.
7348 + *   destaction=auto:  strip destination parameter if it is not stunaddr.
7349 + *   destaction=strip: always strip destination parameter (not recommended).
7350 + *   destaction=none:  do not touch destination parameter (not recommended).
7351 + */
7352 +
7353 +#include <linux/module.h>
7354 +#include <linux/netfilter_ipv4.h>
7355 +#include <linux/ip.h>
7356 +#include <linux/tcp.h>
7357 +#include <linux/kernel.h>
7358 +#include <net/tcp.h>
7359 +#include <linux/netfilter_ipv4/ip_nat.h>
7360 +#include <linux/netfilter_ipv4/ip_nat_helper.h>
7361 +#include <linux/netfilter_ipv4/ip_nat_rule.h>
7362 +#include <linux/netfilter_ipv4/ip_conntrack_rtsp.h>
7363 +#include <linux/netfilter_ipv4/ip_conntrack_helper.h>
7364 +
7365 +#include <linux/inet.h>
7366 +#include <linux/ctype.h>
7367 +#define NF_NEED_STRNCASECMP
7368 +#define NF_NEED_STRTOU16
7369 +#include <linux/netfilter_helpers.h>
7370 +#define NF_NEED_MIME_NEXTLINE
7371 +#include <linux/netfilter_mime.h>
7372 +
7373 +#define INFOP(fmt, args...) printk(KERN_INFO "%s: %s: " fmt, __FILE__, __FUNCTION__ , ## args)
7374 +#ifdef IP_NF_RTSP_DEBUG
7375 +#define DEBUGP(fmt, args...) printk(KERN_DEBUG "%s: %s: " fmt, __FILE__, __FUNCTION__ , ## args)
7376 +#else
7377 +#define DEBUGP(fmt, args...)
7378 +#endif
7379 +
7380 +#define MAX_PORTS       8
7381 +#define DSTACT_AUTO     0
7382 +#define DSTACT_STRIP    1
7383 +#define DSTACT_NONE     2
7384 +
7385 +static int      ports[MAX_PORTS];
7386 +static char*    stunaddr = NULL;
7387 +static char*    destaction = NULL;
7388 +
7389 +static int       num_ports = 0;
7390 +static u_int32_t extip = 0;
7391 +static int       dstact = 0;
7392 +
7393 +MODULE_AUTHOR("Tom Marshall <tmarshall@real.com>");
7394 +MODULE_DESCRIPTION("RTSP network address translation module");
7395 +MODULE_LICENSE("GPL");
7396 +#ifdef MODULE_PARM
7397 +MODULE_PARM(ports, "1-" __MODULE_STRING(MAX_PORTS) "i");
7398 +MODULE_PARM_DESC(ports, "port numbers of RTSP servers");
7399 +MODULE_PARM(stunaddr, "s");
7400 +MODULE_PARM_DESC(stunaddr, "Address for detecting STUN");
7401 +MODULE_PARM(destaction, "s");
7402 +MODULE_PARM_DESC(destaction, "Action for destination parameter (auto/strip/none)");
7403 +#endif
7404 +
7405 +/* protects rtsp part of conntracks */
7406 +DECLARE_LOCK_EXTERN(ip_rtsp_lock);
7407 +
7408 +#define SKIP_WSPACE(ptr,len,off) while(off < len && isspace(*(ptr+off))) { off++; }
7409 +
7410 +/*** helper functions ***/
7411 +
7412 +static void
7413 +get_skb_tcpdata(struct sk_buff* skb, char** pptcpdata, uint* ptcpdatalen)
7414 +{
7415 +    struct iphdr*   iph  = (struct iphdr*)skb->nh.iph;
7416 +    struct tcphdr*  tcph = (struct tcphdr*)((char*)iph + iph->ihl*4);
7417 +
7418 +    *pptcpdata = (char*)tcph + tcph->doff*4;
7419 +    *ptcpdatalen = ((char*)skb->h.raw + skb->len) - *pptcpdata;
7420 +}
7421 +
7422 +/*** nat functions ***/
7423 +
7424 +/*
7425 + * Mangle the "Transport:" header:
7426 + *   - Replace all occurences of "client_port=<spec>"
7427 + *   - Handle destination parameter
7428 + *
7429 + * In:
7430 + *   ct, ctinfo = conntrack context
7431 + *   pskb       = packet
7432 + *   tranoff    = Transport header offset from TCP data
7433 + *   tranlen    = Transport header length (incl. CRLF)
7434 + *   rport_lo   = replacement low  port (host endian)
7435 + *   rport_hi   = replacement high port (host endian)
7436 + *
7437 + * Returns packet size difference.
7438 + *
7439 + * Assumes that a complete transport header is present, ending with CR or LF
7440 + */
7441 +static int
7442 +rtsp_mangle_tran(struct ip_conntrack* ct, enum ip_conntrack_info ctinfo,
7443 +                 struct ip_conntrack_expect* exp,
7444 +                 struct sk_buff** pskb, uint tranoff, uint tranlen)
7445 +{
7446 +    char*       ptcp;
7447 +    uint        tcplen;
7448 +    char*       ptran;
7449 +    char        rbuf1[16];      /* Replacement buffer (one port) */
7450 +    uint        rbuf1len;       /* Replacement len (one port) */
7451 +    char        rbufa[16];      /* Replacement buffer (all ports) */
7452 +    uint        rbufalen;       /* Replacement len (all ports) */
7453 +    u_int32_t   newip;
7454 +    u_int16_t   loport, hiport;
7455 +    uint        off = 0;
7456 +    uint        diff;           /* Number of bytes we removed */
7457 +
7458 +    struct ip_ct_rtsp_expect* prtspexp = &exp->help.exp_rtsp_info;
7459 +    struct ip_conntrack_tuple t;
7460 +
7461 +    char    szextaddr[15+1];
7462 +    uint    extaddrlen;
7463 +    int     is_stun;
7464 +
7465 +    get_skb_tcpdata(*pskb, &ptcp, &tcplen);
7466 +    ptran = ptcp+tranoff;
7467 +
7468 +    if (tranoff+tranlen > tcplen || tcplen-tranoff < tranlen ||
7469 +        tranlen < 10 || !iseol(ptran[tranlen-1]) ||
7470 +        nf_strncasecmp(ptran, "Transport:", 10) != 0)
7471 +    {
7472 +        INFOP("sanity check failed\n");
7473 +        return 0;
7474 +    }
7475 +    off += 10;
7476 +    SKIP_WSPACE(ptcp+tranoff, tranlen, off);
7477 +
7478 +    newip = ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.ip;
7479 +    t = exp->tuple;
7480 +    t.dst.ip = newip;
7481 +
7482 +    extaddrlen = extip ? sprintf(szextaddr, "%u.%u.%u.%u", NIPQUAD(extip))
7483 +                       : sprintf(szextaddr, "%u.%u.%u.%u", NIPQUAD(newip));
7484 +    DEBUGP("stunaddr=%s (%s)\n", szextaddr, (extip?"forced":"auto"));
7485 +
7486 +    rbuf1len = rbufalen = 0;
7487 +    switch (prtspexp->pbtype)
7488 +    {
7489 +    case pb_single:
7490 +        for (loport = prtspexp->loport; loport != 0; loport++) /* XXX: improper wrap? */
7491 +        {
7492 +            t.dst.u.udp.port = htons(loport);
7493 +            if (ip_conntrack_change_expect(exp, &t) == 0)
7494 +            {
7495 +                DEBUGP("using port %hu\n", loport);
7496 +                break;
7497 +            }
7498 +        }
7499 +        if (loport != 0)
7500 +        {
7501 +            rbuf1len = sprintf(rbuf1, "%hu", loport);
7502 +            rbufalen = sprintf(rbufa, "%hu", loport);
7503 +        }
7504 +        break;
7505 +    case pb_range:
7506 +        for (loport = prtspexp->loport; loport != 0; loport += 2) /* XXX: improper wrap? */
7507 +        {
7508 +            t.dst.u.udp.port = htons(loport);
7509 +            if (ip_conntrack_change_expect(exp, &t) == 0)
7510 +            {
7511 +                hiport = loport + ~exp->mask.dst.u.udp.port;
7512 +                DEBUGP("using ports %hu-%hu\n", loport, hiport);
7513 +                break;
7514 +            }
7515 +        }
7516 +        if (loport != 0)
7517 +        {
7518 +            rbuf1len = sprintf(rbuf1, "%hu", loport);
7519 +            rbufalen = sprintf(rbufa, "%hu-%hu", loport, loport+1);
7520 +        }
7521 +        break;
7522 +    case pb_discon:
7523 +        for (loport = prtspexp->loport; loport != 0; loport++) /* XXX: improper wrap? */
7524 +        {
7525 +            t.dst.u.udp.port = htons(loport);
7526 +            if (ip_conntrack_change_expect(exp, &t) == 0)
7527 +            {
7528 +                DEBUGP("using port %hu (1 of 2)\n", loport);
7529 +                break;
7530 +            }
7531 +        }
7532 +        for (hiport = prtspexp->hiport; hiport != 0; hiport++) /* XXX: improper wrap? */
7533 +        {
7534 +            t.dst.u.udp.port = htons(hiport);
7535 +            if (ip_conntrack_change_expect(exp, &t) == 0)
7536 +            {
7537 +                DEBUGP("using port %hu (2 of 2)\n", hiport);
7538 +                break;
7539 +            }
7540 +        }
7541 +        if (loport != 0 && hiport != 0)
7542 +        {
7543 +            rbuf1len = sprintf(rbuf1, "%hu", loport);
7544 +            if (hiport == loport+1)
7545 +            {
7546 +                rbufalen = sprintf(rbufa, "%hu-%hu", loport, hiport);
7547 +            }
7548 +            else
7549 +            {
7550 +                rbufalen = sprintf(rbufa, "%hu/%hu", loport, hiport);
7551 +            }
7552 +        }
7553 +        break;
7554 +    }
7555 +
7556 +    if (rbuf1len == 0)
7557 +    {
7558 +        return 0;   /* cannot get replacement port(s) */
7559 +    }
7560 +
7561 +    /* Transport: tran;field;field=val,tran;field;field=val,... */
7562 +    while (off < tranlen)
7563 +    {
7564 +        uint        saveoff;
7565 +        const char* pparamend;
7566 +        uint        nextparamoff;
7567 +
7568 +        pparamend = memchr(ptran+off, ',', tranlen-off);
7569 +        pparamend = (pparamend == NULL) ? ptran+tranlen : pparamend+1;
7570 +        nextparamoff = pparamend-ptcp;
7571 +
7572 +        /*
7573 +         * We pass over each param twice.  On the first pass, we look for a
7574 +         * destination= field.  It is handled by the security policy.  If it
7575 +         * is present, allowed, and equal to our external address, we assume
7576 +         * that STUN is being used and we leave the client_port= field alone.
7577 +         */
7578 +        is_stun = 0;
7579 +        saveoff = off;
7580 +        while (off < nextparamoff)
7581 +        {
7582 +            const char* pfieldend;
7583 +            uint        nextfieldoff;
7584 +
7585 +            pfieldend = memchr(ptran+off, ';', nextparamoff-off);
7586 +            nextfieldoff = (pfieldend == NULL) ? nextparamoff : pfieldend-ptran+1;
7587 +
7588 +            if (dstact != DSTACT_NONE && strncmp(ptran+off, "destination=", 12) == 0)
7589 +            {
7590 +                if (strncmp(ptran+off+12, szextaddr, extaddrlen) == 0)
7591 +                {
7592 +                    is_stun = 1;
7593 +                }
7594 +                if (dstact == DSTACT_STRIP || (dstact == DSTACT_AUTO && !is_stun))
7595 +                {
7596 +                    diff = nextfieldoff-off;
7597 +                    if (!ip_nat_mangle_tcp_packet(pskb, ct, ctinfo,
7598 +                                                         off, diff, NULL, 0))
7599 +                    {
7600 +                        /* mangle failed, all we can do is bail */
7601 +                        return 0;
7602 +                    }
7603 +                    get_skb_tcpdata(*pskb, &ptcp, &tcplen);
7604 +                    ptran = ptcp+tranoff;
7605 +                    tranlen -= diff;
7606 +                    nextparamoff -= diff;
7607 +                    nextfieldoff -= diff;
7608 +                }
7609 +            }
7610 +
7611 +            off = nextfieldoff;
7612 +        }
7613 +        if (is_stun)
7614 +        {
7615 +            continue;
7616 +        }
7617 +        off = saveoff;
7618 +        while (off < nextparamoff)
7619 +        {
7620 +            const char* pfieldend;
7621 +            uint        nextfieldoff;
7622 +
7623 +            pfieldend = memchr(ptran+off, ';', nextparamoff-off);
7624 +            nextfieldoff = (pfieldend == NULL) ? nextparamoff : pfieldend-ptran+1;
7625 +
7626 +            if (strncmp(ptran+off, "client_port=", 12) == 0)
7627 +            {
7628 +                u_int16_t   port;
7629 +                uint        numlen;
7630 +                uint        origoff;
7631 +                uint        origlen;
7632 +                char*       rbuf    = rbuf1;
7633 +                uint        rbuflen = rbuf1len;
7634 +
7635 +                off += 12;
7636 +                origoff = (ptran-ptcp)+off;
7637 +                origlen = 0;
7638 +                numlen = nf_strtou16(ptran+off, &port);
7639 +                off += numlen;
7640 +                origlen += numlen;
7641 +                if (port != prtspexp->loport)
7642 +                {
7643 +                    DEBUGP("multiple ports found, port %hu ignored\n", port);
7644 +                }
7645 +                else
7646 +                {
7647 +                    if (ptran[off] == '-' || ptran[off] == '/')
7648 +                    {
7649 +                        off++;
7650 +                        origlen++;
7651 +                        numlen = nf_strtou16(ptran+off, &port);
7652 +                        off += numlen;
7653 +                        origlen += numlen;
7654 +                        rbuf = rbufa;
7655 +                        rbuflen = rbufalen;
7656 +                    }
7657 +
7658 +                    /*
7659 +                     * note we cannot just memcpy() if the sizes are the same.
7660 +                     * the mangle function does skb resizing, checks for a
7661 +                     * cloned skb, and updates the checksums.
7662 +                     *
7663 +                     * parameter 4 below is offset from start of tcp data.
7664 +                     */
7665 +                    diff = origlen-rbuflen;
7666 +                    if (!ip_nat_mangle_tcp_packet(pskb, ct, ctinfo,
7667 +                                              origoff, origlen, rbuf, rbuflen))
7668 +                    {
7669 +                        /* mangle failed, all we can do is bail */
7670 +                        return 0;
7671 +                    }
7672 +                    get_skb_tcpdata(*pskb, &ptcp, &tcplen);
7673 +                    ptran = ptcp+tranoff;
7674 +                    tranlen -= diff;
7675 +                    nextparamoff -= diff;
7676 +                    nextfieldoff -= diff;
7677 +                }
7678 +            }
7679 +
7680 +            off = nextfieldoff;
7681 +        }
7682 +
7683 +        off = nextparamoff;
7684 +    }
7685 +
7686 +    return 1;
7687 +}
7688 +
7689 +static unsigned int
7690 +expected(struct sk_buff **pskb, uint hooknum, struct ip_conntrack* ct, struct ip_nat_info* info)
7691 +{
7692 +    struct ip_nat_multi_range mr;
7693 +    u_int32_t newdstip, newsrcip, newip;
7694 +
7695 +    struct ip_conntrack *master = master_ct(ct);
7696 +
7697 +    IP_NF_ASSERT(info);
7698 +    IP_NF_ASSERT(master);
7699 +
7700 +    IP_NF_ASSERT(!(info->initialized & (1 << HOOK2MANIP(hooknum))));
7701 +
7702 +    newdstip = master->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.ip;
7703 +    newsrcip = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.ip;
7704 +    newip = (HOOK2MANIP(hooknum) == IP_NAT_MANIP_SRC) ? newsrcip : newdstip;
7705 +
7706 +    DEBUGP("newsrcip=%u.%u.%u.%u, newdstip=%u.%u.%u.%u, newip=%u.%u.%u.%u\n",
7707 +           NIPQUAD(newsrcip), NIPQUAD(newdstip), NIPQUAD(newip));
7708 +
7709 +    mr.rangesize = 1;
7710 +    /* We don't want to manip the per-protocol, just the IPs. */
7711 +    mr.range[0].flags = IP_NAT_RANGE_MAP_IPS;
7712 +    mr.range[0].min_ip = mr.range[0].max_ip = newip;
7713 +
7714 +    return ip_nat_setup_info(ct, &mr, hooknum);
7715 +}
7716 +
7717 +static uint
7718 +help_out(struct ip_conntrack* ct, enum ip_conntrack_info ctinfo,
7719 +         struct ip_conntrack_expect* exp, struct sk_buff** pskb)
7720 +{
7721 +    char*   ptcp;
7722 +    uint    tcplen;
7723 +    uint    hdrsoff;
7724 +    uint    hdrslen;
7725 +    uint    lineoff;
7726 +    uint    linelen;
7727 +    uint    off;
7728 +
7729 +    struct iphdr* iph = (struct iphdr*)(*pskb)->nh.iph;
7730 +    struct tcphdr* tcph = (struct tcphdr*)((void*)iph + iph->ihl*4);
7731 +
7732 +    struct ip_ct_rtsp_expect* prtspexp = &exp->help.exp_rtsp_info;
7733 +
7734 +    get_skb_tcpdata(*pskb, &ptcp, &tcplen);
7735 +
7736 +    hdrsoff = exp->seq - ntohl(tcph->seq);
7737 +    hdrslen = prtspexp->len;
7738 +    off = hdrsoff;
7739 +
7740 +    while (nf_mime_nextline(ptcp, hdrsoff+hdrslen, &off, &lineoff, &linelen))
7741 +    {
7742 +        if (linelen == 0)
7743 +        {
7744 +            break;
7745 +        }
7746 +        if (off > hdrsoff+hdrslen)
7747 +        {
7748 +            INFOP("!! overrun !!");
7749 +            break;
7750 +        }
7751 +        DEBUGP("hdr: len=%u, %.*s", linelen, (int)linelen, ptcp+lineoff);
7752 +
7753 +        if (nf_strncasecmp(ptcp+lineoff, "Transport:", 10) == 0)
7754 +        {
7755 +            uint oldtcplen = tcplen;
7756 +            if (!rtsp_mangle_tran(ct, ctinfo, exp, pskb, lineoff, linelen))
7757 +            {
7758 +                break;
7759 +            }
7760 +            get_skb_tcpdata(*pskb, &ptcp, &tcplen);
7761 +            hdrslen -= (oldtcplen-tcplen);
7762 +            off -= (oldtcplen-tcplen);
7763 +            lineoff -= (oldtcplen-tcplen);
7764 +            linelen -= (oldtcplen-tcplen);
7765 +            DEBUGP("rep: len=%u, %.*s", linelen, (int)linelen, ptcp+lineoff);
7766 +        }
7767 +    }
7768 +
7769 +    return NF_ACCEPT;
7770 +}
7771 +
7772 +static uint
7773 +help_in(struct ip_conntrack* ct, enum ip_conntrack_info ctinfo,
7774 +         struct ip_conntrack_expect* exp, struct sk_buff** pskb)
7775 +{
7776 +    /* XXX: unmangle */
7777 +    return NF_ACCEPT;
7778 +}
7779 +
7780 +static uint
7781 +help(struct ip_conntrack* ct,
7782 +     struct ip_conntrack_expect* exp,
7783 +     struct ip_nat_info* info,
7784 +     enum ip_conntrack_info ctinfo,
7785 +     unsigned int hooknum,
7786 +     struct sk_buff** pskb)
7787 +{
7788 +    struct iphdr*  iph  = (struct iphdr*)(*pskb)->nh.iph;
7789 +    struct tcphdr* tcph = (struct tcphdr*)((char*)iph + iph->ihl * 4);
7790 +    uint datalen;
7791 +    int dir;
7792 +    struct ip_ct_rtsp_expect* ct_rtsp_info;
7793 +    int rc = NF_ACCEPT;
7794 +
7795 +    if (ct == NULL || exp == NULL || info == NULL || pskb == NULL)
7796 +    {
7797 +        DEBUGP("!! null ptr (%p,%p,%p,%p) !!\n", ct, exp, info, pskb);
7798 +        return NF_ACCEPT;
7799 +    }
7800 +
7801 +    ct_rtsp_info = &exp->help.exp_rtsp_info;
7802 +
7803 +    /*
7804 +     * Only mangle things once: original direction in POST_ROUTING
7805 +     * and reply direction on PRE_ROUTING.
7806 +     */
7807 +    dir = CTINFO2DIR(ctinfo);
7808 +    if (!((hooknum == NF_IP_POST_ROUTING && dir == IP_CT_DIR_ORIGINAL)
7809 +          || (hooknum == NF_IP_PRE_ROUTING && dir == IP_CT_DIR_REPLY)))
7810 +    {
7811 +        DEBUGP("Not touching dir %s at hook %s\n",
7812 +               dir == IP_CT_DIR_ORIGINAL ? "ORIG" : "REPLY",
7813 +               hooknum == NF_IP_POST_ROUTING ? "POSTROUTING"
7814 +               : hooknum == NF_IP_PRE_ROUTING ? "PREROUTING"
7815 +               : hooknum == NF_IP_LOCAL_OUT ? "OUTPUT" : "???");
7816 +        return NF_ACCEPT;
7817 +    }
7818 +    DEBUGP("got beyond not touching\n");
7819 +
7820 +    datalen = (*pskb)->len - iph->ihl * 4 - tcph->doff * 4;
7821 +
7822 +    LOCK_BH(&ip_rtsp_lock);
7823 +    /* Ensure the packet contains all of the marked data */
7824 +    if (!between(exp->seq + ct_rtsp_info->len,
7825 +                 ntohl(tcph->seq), ntohl(tcph->seq) + datalen))
7826 +    {
7827 +        /* Partial retransmission?  Probably a hacker. */
7828 +        if (net_ratelimit())
7829 +        {
7830 +            INFOP("partial packet %u/%u in %u/%u\n",
7831 +                   exp->seq, ct_rtsp_info->len, ntohl(tcph->seq), ntohl(tcph->seq) + datalen);
7832 +        }
7833 +        UNLOCK_BH(&ip_rtsp_lock);
7834 +        return NF_DROP;
7835 +    }
7836 +
7837 +    switch (dir)
7838 +    {
7839 +    case IP_CT_DIR_ORIGINAL:
7840 +        rc = help_out(ct, ctinfo, exp, pskb);
7841 +        break;
7842 +    case IP_CT_DIR_REPLY:
7843 +        rc = help_in(ct, ctinfo, exp, pskb);
7844 +        break;
7845 +    }
7846 +    UNLOCK_BH(&ip_rtsp_lock);
7847 +
7848 +    return rc;
7849 +}
7850 +
7851 +static struct ip_nat_helper ip_nat_rtsp_helpers[MAX_PORTS];
7852 +static char rtsp_names[MAX_PORTS][10];
7853 +
7854 +/* This function is intentionally _NOT_ defined as  __exit */
7855 +static void
7856 +fini(void)
7857 +{
7858 +    int i;
7859 +
7860 +    for (i = 0; i < num_ports; i++)
7861 +    {
7862 +        DEBUGP("unregistering helper for port %d\n", ports[i]);
7863 +        ip_nat_helper_unregister(&ip_nat_rtsp_helpers[i]);
7864 +    }
7865 +}
7866 +
7867 +static int __init
7868 +init(void)
7869 +{
7870 +    int ret = 0;
7871 +    int i;
7872 +    struct ip_nat_helper* hlpr;
7873 +    char* tmpname;
7874 +
7875 +    printk("ip_nat_rtsp v" IP_NF_RTSP_VERSION " loading\n");
7876 +
7877 +    if (ports[0] == 0)
7878 +    {
7879 +        ports[0] = RTSP_PORT;
7880 +    }
7881 +
7882 +    for (i = 0; (i < MAX_PORTS) && ports[i] != 0; i++)
7883 +    {
7884 +        hlpr = &ip_nat_rtsp_helpers[i];
7885 +        memset(hlpr, 0, sizeof(struct ip_nat_helper));
7886 +
7887 +        hlpr->tuple.dst.protonum = IPPROTO_TCP;
7888 +        hlpr->tuple.src.u.tcp.port = htons(ports[i]);
7889 +        hlpr->mask.src.u.tcp.port = 0xFFFF;
7890 +        hlpr->mask.dst.protonum = 0xFFFF;
7891 +        hlpr->help = help;
7892 +        hlpr->flags = 0;
7893 +        hlpr->me = THIS_MODULE;
7894 +        hlpr->expect = expected;
7895 +
7896 +        tmpname = &rtsp_names[i][0];
7897 +        if (ports[i] == RTSP_PORT)
7898 +        {
7899 +                sprintf(tmpname, "rtsp");
7900 +        }
7901 +        else
7902 +        {
7903 +                sprintf(tmpname, "rtsp-%d", i);
7904 +        }
7905 +        hlpr->name = tmpname;
7906 +
7907 +        DEBUGP("registering helper for port %d: name %s\n", ports[i], hlpr->name);
7908 +        ret = ip_nat_helper_register(hlpr);
7909 +
7910 +        if (ret)
7911 +        {
7912 +            printk("ip_nat_rtsp: error registering helper for port %d\n", ports[i]);
7913 +            fini();
7914 +            return 1;
7915 +        }
7916 +        num_ports++;
7917 +    }
7918 +    if (stunaddr != NULL)
7919 +    {
7920 +        extip = in_aton(stunaddr);
7921 +    }
7922 +    if (destaction != NULL)
7923 +    {
7924 +        if (strcmp(destaction, "auto") == 0)
7925 +        {
7926 +            dstact = DSTACT_AUTO;
7927 +        }
7928 +        if (strcmp(destaction, "strip") == 0)
7929 +        {
7930 +            dstact = DSTACT_STRIP;
7931 +        }
7932 +        if (strcmp(destaction, "none") == 0)
7933 +        {
7934 +            dstact = DSTACT_NONE;
7935 +        }
7936 +    }
7937 +    return ret;
7938 +}
7939 +
7940 +module_init(init);
7941 +module_exit(fini);
7942 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ip_nat_rule.c linux-2.6.6/net/ipv4/netfilter/ip_nat_rule.c
7943 --- linux-2.6.6.org/net/ipv4/netfilter/ip_nat_rule.c    2004-05-10 04:32:28.000000000 +0200
7944 +++ linux-2.6.6/net/ipv4/netfilter/ip_nat_rule.c        2004-05-18 14:28:50.000000000 +0200
7945 @@ -75,7 +75,7 @@
7946                 0,
7947                 sizeof(struct ipt_entry),
7948                 sizeof(struct ipt_standard),
7949 -               0, { 0, 0 }, { } },
7950 +               0, NULL, 0, { 0, 0 }, { } },
7951               { { { { IPT_ALIGN(sizeof(struct ipt_standard_target)), "" } }, { } },
7952                 -NF_ACCEPT - 1 } },
7953             /* POST_ROUTING */
7954 @@ -83,7 +83,7 @@
7955                 0,
7956                 sizeof(struct ipt_entry),
7957                 sizeof(struct ipt_standard),
7958 -               0, { 0, 0 }, { } },
7959 +               0, NULL, 0, { 0, 0 }, { } },
7960               { { { { IPT_ALIGN(sizeof(struct ipt_standard_target)), "" } }, { } },
7961                 -NF_ACCEPT - 1 } },
7962             /* LOCAL_OUT */
7963 @@ -91,7 +91,7 @@
7964                 0,
7965                 sizeof(struct ipt_entry),
7966                 sizeof(struct ipt_standard),
7967 -               0, { 0, 0 }, { } },
7968 +               0, NULL, 0, { 0, 0 }, { } },
7969               { { { { IPT_ALIGN(sizeof(struct ipt_standard_target)), "" } }, { } },
7970                 -NF_ACCEPT - 1 } }
7971      },
7972 @@ -100,7 +100,7 @@
7973         0,
7974         sizeof(struct ipt_entry),
7975         sizeof(struct ipt_error),
7976 -       0, { 0, 0 }, { } },
7977 +       0, NULL, 0, { 0, 0 }, { } },
7978        { { { { IPT_ALIGN(sizeof(struct ipt_error_target)), IPT_ERROR_TARGET } },
7979           { } },
7980         "ERROR"
7981 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ip_nat_standalone.c linux-2.6.6/net/ipv4/netfilter/ip_nat_standalone.c
7982 --- linux-2.6.6.org/net/ipv4/netfilter/ip_nat_standalone.c      2004-05-10 04:33:12.000000000 +0200
7983 +++ linux-2.6.6/net/ipv4/netfilter/ip_nat_standalone.c  2004-05-18 14:28:50.000000000 +0200
7984 @@ -175,6 +175,45 @@
7985         return do_bindings(ct, ctinfo, info, hooknum, pskb);
7986  }
7987  
7988 +struct nat_route_key
7989 +{
7990 +       u_int32_t addr;
7991 +#ifdef CONFIG_XFRM
7992 +       u_int16_t port;
7993 +#endif
7994 +};
7995 +
7996 +static inline void
7997 +nat_route_key_get(struct sk_buff *skb, struct nat_route_key *key, int which)
7998 +{
7999 +       struct iphdr *iph = skb->nh.iph;
8000 +
8001 +       key->addr = which ? iph->daddr : iph->saddr;
8002 +#ifdef CONFIG_XFRM
8003 +       key->port = 0;
8004 +       if (iph->protocol == IPPROTO_TCP || iph->protocol == IPPROTO_UDP) {
8005 +               u_int16_t *ports = (u_int16_t *)(skb->nh.raw + iph->ihl*4);
8006 +               key->port = ports[which];
8007 +       }
8008 +#endif
8009 +}
8010 +
8011 +static inline int
8012 +nat_route_key_compare(struct sk_buff *skb, struct nat_route_key *key, int which)
8013 +{
8014 +       struct iphdr *iph = skb->nh.iph;
8015 +
8016 +       if (key->addr != (which ? iph->daddr : iph->saddr))
8017 +               return 1;
8018 +#ifdef CONFIG_XFRM
8019 +       if (iph->protocol == IPPROTO_TCP || iph->protocol == IPPROTO_UDP) {
8020 +               u_int16_t *ports = (u_int16_t *)(skb->nh.raw + iph->ihl*4);
8021 +               if (key->port != ports[which])
8022 +                       return 1;
8023 +       }
8024 +#endif
8025 +}
8026 +
8027  static unsigned int
8028  ip_nat_out(unsigned int hooknum,
8029            struct sk_buff **pskb,
8030 @@ -182,6 +221,9 @@
8031            const struct net_device *out,
8032            int (*okfn)(struct sk_buff *))
8033  {
8034 +       struct nat_route_key key;
8035 +       unsigned int ret;
8036 +
8037         /* root is playing with raw sockets. */
8038         if ((*pskb)->len < sizeof(struct iphdr)
8039             || (*pskb)->nh.iph->ihl * 4 < sizeof(struct iphdr))
8040 @@ -204,7 +246,29 @@
8041                         return NF_STOLEN;
8042         }
8043  
8044 -       return ip_nat_fn(hooknum, pskb, in, out, okfn);
8045 +       nat_route_key_get(*pskb, &key, 0);
8046 +       ret = ip_nat_fn(hooknum, pskb, in, out, okfn);
8047 +
8048 +       if (ret != NF_DROP && ret != NF_STOLEN
8049 +           && nat_route_key_compare(*pskb, &key, 0)) {
8050 +               if (ip_route_me_harder(pskb) != 0)
8051 +                       ret = NF_DROP;
8052 +#ifdef CONFIG_XFRM
8053 +               /*
8054 +                * POST_ROUTING hook is called with fixed outfn, we need
8055 +                * to manually confirm the packet and direct it to the
8056 +                * transformers if a policy matches.
8057 +                */
8058 +               else if ((*pskb)->dst->xfrm != NULL) {
8059 +                       ret = ip_conntrack_confirm(*pskb);
8060 +                       if (ret != NF_DROP) {
8061 +                               dst_output(*pskb);
8062 +                               ret = NF_STOLEN;
8063 +                       }
8064 +               }
8065 +#endif
8066 +       }
8067 +       return ret;
8068  }
8069  
8070  #ifdef CONFIG_IP_NF_NAT_LOCAL
8071 @@ -215,7 +279,7 @@
8072                 const struct net_device *out,
8073                 int (*okfn)(struct sk_buff *))
8074  {
8075 -       u_int32_t saddr, daddr;
8076 +       struct nat_route_key key;
8077         unsigned int ret;
8078  
8079         /* root is playing with raw sockets. */
8080 @@ -223,14 +287,14 @@
8081             || (*pskb)->nh.iph->ihl * 4 < sizeof(struct iphdr))
8082                 return NF_ACCEPT;
8083  
8084 -       saddr = (*pskb)->nh.iph->saddr;
8085 -       daddr = (*pskb)->nh.iph->daddr;
8086 -
8087 +       nat_route_key_get(*pskb, &key, 1);
8088         ret = ip_nat_fn(hooknum, pskb, in, out, okfn);
8089 +
8090         if (ret != NF_DROP && ret != NF_STOLEN
8091 -           && ((*pskb)->nh.iph->saddr != saddr
8092 -               || (*pskb)->nh.iph->daddr != daddr))
8093 -               return ip_route_me_harder(pskb) == 0 ? ret : NF_DROP;
8094 +           && nat_route_key_compare(*pskb, &key, 1)) {
8095 +               if (ip_route_me_harder(pskb) != 0)
8096 +                       ret = NF_DROP;
8097 +       }
8098         return ret;
8099  }
8100  #endif
8101 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ip_nat_talk.c linux-2.6.6/net/ipv4/netfilter/ip_nat_talk.c
8102 --- linux-2.6.6.org/net/ipv4/netfilter/ip_nat_talk.c    1970-01-01 01:00:00.000000000 +0100
8103 +++ linux-2.6.6/net/ipv4/netfilter/ip_nat_talk.c        2004-05-18 14:28:50.000000000 +0200
8104 @@ -0,0 +1,473 @@
8105 +/* 
8106 + * talk extension for UDP NAT alteration. 
8107 + * Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
8108 + *
8109 + *      This program is free software; you can redistribute it and/or
8110 + *      modify it under the terms of the GNU General Public License
8111 + *      as published by the Free Software Foundation; either version
8112 + *      2 of the License, or (at your option) any later version.
8113 + **
8114 + *     Module load syntax:
8115 + *     insmod ip_nat_talk.o talk=[0|1] ntalk=[0|1] ntalk2=[0|1]
8116 + *
8117 + *             talk=[0|1]      disable|enable old talk support
8118 + *            ntalk=[0|1]      disable|enable ntalk support
8119 + *           ntalk2=[0|1]      disable|enable ntalk2 support
8120 + *
8121 + *     The default is talk=1 ntalk=1 ntalk2=1
8122 + *
8123 + *  
8124 + */
8125 +#include <linux/module.h>
8126 +#include <linux/netfilter_ipv4.h>
8127 +#include <linux/ip.h>
8128 +#include <linux/udp.h>
8129 +#include <linux/kernel.h>
8130 +#include <net/tcp.h>
8131 +#include <net/udp.h>
8132 +
8133 +#include <linux/netfilter_ipv4/ip_nat.h>
8134 +#include <linux/netfilter_ipv4/ip_nat_helper.h>
8135 +#include <linux/netfilter_ipv4/ip_nat_rule.h>
8136 +#include <linux/netfilter_ipv4/ip_conntrack_talk.h>
8137 +#include <linux/netfilter_ipv4/ip_conntrack_helper.h>
8138 +
8139 +/* Default all talk protocols are supported */
8140 +static int talk   = 1;
8141 +static int ntalk  = 1;
8142 +static int ntalk2 = 1;
8143 +MODULE_AUTHOR("Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>");
8144 +MODULE_DESCRIPTION("talk network address translation module");
8145 +#ifdef MODULE_PARM
8146 +MODULE_PARM(talk, "i");
8147 +MODULE_PARM_DESC(talk, "support (old) talk protocol");
8148 +MODULE_PARM(ntalk, "i");
8149 +MODULE_PARM_DESC(ntalk, "support ntalk protocol");
8150 +MODULE_PARM(ntalk2, "i");
8151 +MODULE_PARM_DESC(ntalk2, "support ntalk2 protocol");
8152 +#endif
8153 +
8154 +#if 0
8155 +#define DEBUGP printk
8156 +#define IP_NAT_TALK_DEBUG
8157 +#else
8158 +#define DEBUGP(format, args...)
8159 +#endif
8160 +
8161 +/* FIXME: Time out? --RR */
8162 +
8163 +static int
8164 +mangle_packet(struct sk_buff **pskb,
8165 +             struct ip_conntrack *ct,
8166 +             u_int32_t newip,
8167 +             u_int16_t port,
8168 +             struct talk_addr *addr,
8169 +             struct talk_addr *ctl_addr)
8170 +{
8171 +       struct iphdr *iph = (*pskb)->nh.iph;
8172 +       struct udphdr *udph = (void *)iph + iph->ihl * 4;
8173 +       size_t udplen = (*pskb)->len - iph->ihl * 4;
8174 +
8175 +       /* Fortunately talk sends a structure with the address and
8176 +          port in it. The size of the packet won't change. */
8177 +
8178 +       if (ctl_addr == NULL) {
8179 +               /* response */
8180 +               if (addr->ta_addr == INADDR_ANY)
8181 +                       return 1;
8182 +               DEBUGP("ip_nat_talk_mangle_packet: response orig %u.%u.%u.%u:%u, inserting %u.%u.%u.%u:%u\n", 
8183 +                      NIPQUAD(addr->ta_addr), ntohs(addr->ta_port),
8184 +                      NIPQUAD(newip), ntohs(port));
8185 +               addr->ta_addr = newip;
8186 +               addr->ta_port = port;
8187 +       } else {
8188 +               /* message */
8189 +               if (addr->ta_addr != INADDR_ANY) {
8190 +                       /* Change address inside packet to match way we're mapping
8191 +                          this connection. */
8192 +                       DEBUGP("ip_nat_talk_mangle_packet: message orig addr %u.%u.%u.%u:%u, inserting %u.%u.%u.%u:%u\n", 
8193 +                              NIPQUAD(addr->ta_addr), ntohs(addr->ta_port),
8194 +                              NIPQUAD(ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.ip), 
8195 +                              ntohs(addr->ta_port));
8196 +                       addr->ta_addr = ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.ip;
8197 +               }
8198 +               DEBUGP("ip_nat_talk_mangle_packet: message orig ctl_addr %u.%u.%u.%u:%u, inserting %u.%u.%u.%u:%u\n", 
8199 +                      NIPQUAD(ctl_addr->ta_addr), ntohs(ctl_addr->ta_port),
8200 +                      NIPQUAD(newip), ntohs(port));
8201 +               ctl_addr->ta_addr = newip;
8202 +               ctl_addr->ta_port = port;
8203 +       }
8204 +
8205 +       /* Fix checksums */
8206 +       (*pskb)->csum = csum_partial((char *)udph + sizeof(struct udphdr), udplen - sizeof(struct udphdr), 0);
8207 +       udph->check = 0;
8208 +       udph->check = csum_tcpudp_magic(iph->saddr, iph->daddr, udplen, IPPROTO_UDP,
8209 +                                       csum_partial((char *)udph, sizeof(struct udphdr), (*pskb)->csum));
8210 +               
8211 +       ip_send_check(iph);
8212 +       return 1;
8213 +}
8214 +
8215 +static int talk_help_msg(struct ip_conntrack *ct,
8216 +                        struct sk_buff **pskb,
8217 +                        u_char type,
8218 +                        struct talk_addr *addr,
8219 +                        struct talk_addr *ctl_addr)
8220 +{
8221 +       u_int32_t newip;
8222 +       u_int16_t port;
8223 +       
8224 +       unsigned int verdict = NF_ACCEPT;
8225 +
8226 +       DEBUGP("ip_nat_talk_help_msg: addr: %u.%u.%u.%u:%u, ctl_addr: %u.%u.%u.%u:%u, type %d\n",
8227 +               NIPQUAD(addr->ta_addr), ntohs(addr->ta_port),
8228 +               NIPQUAD(ctl_addr->ta_addr), ntohs(ctl_addr->ta_port),
8229 +               type);
8230 +
8231 +       /* Change address inside packet to match way we're mapping
8232 +          this connection. */
8233 +       newip = ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.ip;
8234 +       port  = ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.u.udp.port;
8235 +       DEBUGP("ip_nat_talk_help_msg: inserting: %u.%u.%u.%u:%u\n",
8236 +               NIPQUAD(newip), ntohs(port));
8237 +
8238 +       if (!mangle_packet(pskb, ct, newip, port, addr, ctl_addr))
8239 +               verdict = NF_DROP;
8240 +
8241 +       return verdict;
8242 +}
8243 +
8244 +static int talk_help_response(struct ip_conntrack *ct,
8245 +                             struct ip_conntrack_expect *exp,
8246 +                             struct sk_buff **pskb,
8247 +                             u_char type,
8248 +                             u_char answer,
8249 +                             struct talk_addr *addr)
8250 +{
8251 +       u_int32_t newip;
8252 +       u_int16_t port;
8253 +       struct ip_conntrack_tuple t;
8254 +       struct ip_ct_talk_expect *ct_talk_info;
8255 +
8256 +       DEBUGP("ip_nat_talk_help_response: addr: %u.%u.%u.%u:%u, type %d answer %d\n",
8257 +               NIPQUAD(addr->ta_addr), ntohs(addr->ta_port),
8258 +               type, answer);
8259 +       
8260 +       LOCK_BH(&ip_talk_lock);
8261 +       ct_talk_info = &exp->help.exp_talk_info;
8262 +
8263 +       if (!(answer == SUCCESS 
8264 +             && (type == LOOK_UP || type == ANNOUNCE)
8265 +             && exp != NULL)) {
8266 +               UNLOCK_BH(&ip_talk_lock);
8267 +               return NF_ACCEPT;
8268 +       }
8269 +               
8270 +       DEBUGP("ip_nat_talk_help_response: talkinfo port %u (%s)\n", 
8271 +               ntohs(ct_talk_info->port), 
8272 +               type == LOOK_UP ? "LOOK_UP" : "ANNOUNCE");
8273 +
8274 +       /* Change address inside packet to match way we're mapping
8275 +          this connection. */
8276 +       newip = ct->tuplehash[type == LOOK_UP ? IP_CT_DIR_ORIGINAL : 
8277 +                                               IP_CT_DIR_REPLY].tuple.dst.ip;
8278 +       /* We can read expect here without conntrack lock, since it's
8279 +          only set in ip_conntrack_talk , with ip_talk_lock held
8280 +          writable */ 
8281 +       t = exp->tuple;
8282 +       t.dst.ip = newip;
8283 +
8284 +       /* Try to get same port: if not, try to change it. */
8285 +       for (port = ntohs(ct_talk_info->port); port != 0; port++) {
8286 +               if (type == LOOK_UP)
8287 +                       t.dst.u.tcp.port = htons(port);
8288 +               else
8289 +                       t.dst.u.udp.port = htons(port);
8290 +
8291 +               if (ip_conntrack_change_expect(exp, &t) == 0) {
8292 +                       DEBUGP("ip_nat_talk_help_response: using %u.%u.%u.%u:%u\n", NIPQUAD(newip), port);
8293 +                       break;
8294 +               }
8295 +       }
8296 +       UNLOCK_BH(&ip_talk_lock);
8297 +
8298 +       if (port == 0 || !mangle_packet(pskb, ct, newip, htons(port), addr, NULL))
8299 +               return NF_DROP;
8300 +       
8301 +       return NF_ACCEPT;
8302 +}
8303 +
8304 +static unsigned int talk_help(struct ip_conntrack *ct,
8305 +                             struct ip_conntrack_expect *exp,
8306 +                             struct ip_nat_info *info,
8307 +                             enum ip_conntrack_info ctinfo,
8308 +                             unsigned int hooknum,
8309 +                             struct sk_buff **pskb,
8310 +                             int talk_port)
8311 +{
8312 +       struct iphdr *iph = (*pskb)->nh.iph;
8313 +       struct udphdr *udph = (void *)iph + iph->ihl * 4;
8314 +       unsigned int udplen = (*pskb)->len - iph->ihl * 4;
8315 +       char *data = (char *)udph + sizeof(struct udphdr);
8316 +       int dir;
8317 +
8318 +       /* Only mangle things once: original direction in POST_ROUTING
8319 +          and reply direction on PRE_ROUTING. */
8320 +       dir = CTINFO2DIR(ctinfo);
8321 +       if (!((hooknum == NF_IP_POST_ROUTING && dir == IP_CT_DIR_ORIGINAL)
8322 +             || (hooknum == NF_IP_PRE_ROUTING && dir == IP_CT_DIR_REPLY))) {
8323 +               DEBUGP("ip_nat_talk_help: Not touching dir %s at hook %s\n",
8324 +                      dir == IP_CT_DIR_ORIGINAL ? "ORIG" : "REPLY",
8325 +                      hooknum == NF_IP_POST_ROUTING ? "POSTROUTING"
8326 +                      : hooknum == NF_IP_PRE_ROUTING ? "PREROUTING"
8327 +                      : hooknum == NF_IP_LOCAL_OUT ? "OUTPUT" : "???");
8328 +               return NF_ACCEPT;
8329 +       }
8330 +       DEBUGP("ip_nat_talk_help: dir %s at hook %s, %u.%u.%u.%u:%u->%u.%u.%u.%u:%u, talk port %d\n",
8331 +              dir == IP_CT_DIR_ORIGINAL ? "ORIG" : "REPLY",
8332 +              hooknum == NF_IP_POST_ROUTING ? "POSTROUTING"
8333 +              : hooknum == NF_IP_PRE_ROUTING ? "PREROUTING"
8334 +              : hooknum == NF_IP_LOCAL_OUT ? "OUTPUT" : "???",
8335 +              NIPQUAD(iph->saddr), ntohs(udph->source),
8336 +              NIPQUAD(iph->daddr), ntohs(udph->dest),
8337 +              talk_port);
8338 +
8339 +       /* Because conntrack does not drop packets, checking must be repeated here... */
8340 +       if (talk_port == TALK_PORT) {
8341 +               if (dir == IP_CT_DIR_ORIGINAL
8342 +                   && udplen == sizeof(struct udphdr) + sizeof(struct talk_msg))
8343 +                       return talk_help_msg(ct, pskb,
8344 +                                            ((struct talk_msg *)data)->type, 
8345 +                                            &(((struct talk_msg *)data)->addr),
8346 +                                            &(((struct talk_msg *)data)->ctl_addr));
8347 +               else if (dir == IP_CT_DIR_REPLY
8348 +                        && udplen == sizeof(struct udphdr) + sizeof(struct talk_response))
8349 +                       return talk_help_response(ct, exp, pskb,
8350 +                                                 ((struct talk_response *)data)->type, 
8351 +                                                 ((struct talk_response *)data)->answer,
8352 +                                                 &(((struct talk_response *)data)->addr));
8353 +               else {  
8354 +                       DEBUGP("ip_nat_talk_help: not talk %s, datalen %u != %u\n",
8355 +                              dir == IP_CT_DIR_ORIGINAL ? "message" : "response", 
8356 +                              (unsigned)udplen - sizeof(struct udphdr), 
8357 +                              dir == IP_CT_DIR_ORIGINAL ? sizeof(struct talk_msg) : sizeof(struct talk_response));
8358 +                       return NF_DROP;
8359 +               }
8360 +       } else {
8361 +               if (dir == IP_CT_DIR_ORIGINAL) {
8362 +                       if (ntalk
8363 +                           && udplen == sizeof(struct udphdr) + sizeof(struct ntalk_msg)
8364 +                           && ((struct ntalk_msg *)data)->vers == NTALK_VERSION)
8365 +                               return talk_help_msg(ct, pskb,
8366 +                                                    ((struct ntalk_msg *)data)->type, 
8367 +                                                    &(((struct ntalk_msg *)data)->addr),
8368 +                                                    &(((struct ntalk_msg *)data)->ctl_addr));
8369 +                       else if (ntalk2
8370 +                                && udplen >= sizeof(struct udphdr) + sizeof(struct ntalk2_msg)
8371 +                                && ((struct ntalk2_msg *)data)->vers == NTALK2_VERSION
8372 +                                && udplen == sizeof(struct udphdr) 
8373 +                                             + sizeof(struct ntalk2_msg) 
8374 +                                             + ((struct ntalk2_msg *)data)->extended)
8375 +                               return talk_help_msg(ct, pskb,
8376 +                                                    ((struct ntalk2_msg *)data)->type, 
8377 +                                                    &(((struct ntalk2_msg *)data)->addr),
8378 +                                                    &(((struct ntalk2_msg *)data)->ctl_addr));
8379 +                       else {
8380 +                               DEBUGP("ip_nat_talk_help: not ntalk/ntalk2 message, datalen %u != %u or %u + max 256\n", 
8381 +                                      (unsigned)udplen - sizeof(struct udphdr), 
8382 +                                      sizeof(struct ntalk_msg), sizeof(struct ntalk2_msg));
8383 +                               return NF_DROP;
8384 +                       }
8385 +               } else {
8386 +                       if (ntalk
8387 +                           && udplen == sizeof(struct udphdr) + sizeof(struct ntalk_response)
8388 +                           && ((struct ntalk_response *)data)->vers == NTALK_VERSION)
8389 +                               return talk_help_response(ct, exp, pskb,
8390 +                                                         ((struct ntalk_response *)data)->type, 
8391 +                                                         ((struct ntalk_response *)data)->answer,
8392 +                                                         &(((struct ntalk_response *)data)->addr));
8393 +                       else if (ntalk2
8394 +                                && udplen >= sizeof(struct udphdr) + sizeof(struct ntalk2_response)
8395 +                                && ((struct ntalk2_response *)data)->vers == NTALK2_VERSION)
8396 +                               return talk_help_response(ct, exp, pskb,
8397 +                                                         ((struct ntalk2_response *)data)->type, 
8398 +                                                         ((struct ntalk2_response *)data)->answer,
8399 +                                                         &(((struct ntalk2_response *)data)->addr));
8400 +                       else {
8401 +                               DEBUGP("ip_nat_talk_help: not ntalk/ntalk2 response, datalen %u != %u or %u + max 256\n", 
8402 +                                      (unsigned)udplen - sizeof(struct udphdr), 
8403 +                                      sizeof(struct ntalk_response), sizeof(struct ntalk2_response));
8404 +                               return NF_DROP;
8405 +                       }
8406 +               }
8407 +       }
8408 +}
8409 +
8410 +static unsigned int help(struct ip_conntrack *ct,
8411 +                        struct ip_conntrack_expect *exp,
8412 +                        struct ip_nat_info *info,
8413 +                        enum ip_conntrack_info ctinfo,
8414 +                        unsigned int hooknum,
8415 +                        struct sk_buff **pskb)
8416 +{
8417 +       return talk_help(ct, exp, info, ctinfo, hooknum, pskb, TALK_PORT);
8418 +}
8419 +
8420 +static unsigned int nhelp(struct ip_conntrack *ct,
8421 +                         struct ip_conntrack_expect *exp,
8422 +                         struct ip_nat_info *info,
8423 +                         enum ip_conntrack_info ctinfo,
8424 +                         unsigned int hooknum,
8425 +                         struct sk_buff **pskb)
8426 +{
8427 +       return talk_help(ct, exp, info, ctinfo, hooknum, pskb, NTALK_PORT);
8428 +}
8429 +
8430 +static unsigned int
8431 +talk_nat_expected(struct sk_buff **pskb,
8432 +                 unsigned int hooknum,
8433 +                 struct ip_conntrack *ct,
8434 +                 struct ip_nat_info *info);
8435 +
8436 +static struct ip_nat_helper talk_helpers[2] = 
8437 +       { { { NULL, NULL },
8438 +            "talk",                                    /* name */
8439 +            IP_NAT_HELPER_F_ALWAYS,                    /* flags */
8440 +            THIS_MODULE,                               /* module */
8441 +            { { 0, { .udp = { __constant_htons(TALK_PORT) } } }, /* tuple */
8442 +              { 0, { 0 }, IPPROTO_UDP } },
8443 +            { { 0, { .udp = { 0xFFFF } } },            /* mask */
8444 +              { 0, { 0 }, 0xFFFF } },
8445 +            help,                                      /* helper */
8446 +            talk_nat_expected },                       /* expectfn */
8447 +         { { NULL, NULL },
8448 +            "ntalk",                                   /* name */
8449 +            IP_NAT_HELPER_F_ALWAYS,                    /* flags */
8450 +            THIS_MODULE,                                       /* module */
8451 +            { { 0, { .udp = { __constant_htons(NTALK_PORT) } } }, /* tuple */
8452 +              { 0, { 0 }, IPPROTO_UDP } },
8453 +            { { 0, { .udp = { 0xFFFF } } },            /* mask */
8454 +              { 0, { 0 }, 0xFFFF } },
8455 +            nhelp,                                     /* helper */
8456 +            talk_nat_expected }                                /* expectfn */
8457 +       };
8458 +          
8459 +static unsigned int
8460 +talk_nat_expected(struct sk_buff **pskb,
8461 +                 unsigned int hooknum,
8462 +                 struct ip_conntrack *ct,
8463 +                 struct ip_nat_info *info)
8464 +{
8465 +       struct ip_nat_multi_range mr;
8466 +       u_int32_t newdstip, newsrcip, newip;
8467 +       u_int16_t port;
8468 +       unsigned int ret;
8469 +       
8470 +       struct ip_conntrack *master = master_ct(ct);
8471 +
8472 +       IP_NF_ASSERT(info);
8473 +       IP_NF_ASSERT(master);
8474 +
8475 +       IP_NF_ASSERT(!(info->initialized & (1<<HOOK2MANIP(hooknum))));
8476 +
8477 +       DEBUGP("ip_nat_talk_expected: We have a connection!\n");
8478 +
8479 +       LOCK_BH(&ip_talk_lock);
8480 +       port = ct->master->help.exp_talk_info.port;
8481 +       UNLOCK_BH(&ip_talk_lock);
8482 +
8483 +       DEBUGP("ip_nat_talk_expected: dir %s at hook %s, ct %p, master %p\n",
8484 +              CTINFO2DIR((*pskb)->nfct - ct->infos) == IP_CT_DIR_ORIGINAL ? "ORIG" : "REPLY",
8485 +              hooknum == NF_IP_POST_ROUTING ? "POSTROUTING"
8486 +              : hooknum == NF_IP_PRE_ROUTING ? "PREROUTING"
8487 +              : hooknum == NF_IP_LOCAL_OUT ? "OUTPUT" : "???",
8488 +              ct, master);
8489 +
8490 +       if (ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum == IPPROTO_UDP) {
8491 +               /* Callee client -> caller server */
8492 +#ifdef IP_NAT_TALK_DEBUG
8493 +               struct iphdr *iph = (*pskb)->nh.iph;
8494 +               struct udphdr *udph = (void *)iph + iph->ihl * 4;
8495 +
8496 +               DEBUGP("ip_nat_talk_expected: UDP %u.%u.%u.%u:%u->%u.%u.%u.%u:%u\n",
8497 +                      NIPQUAD(iph->saddr), ntohs(udph->source),
8498 +                      NIPQUAD(iph->daddr), ntohs(udph->dest));
8499 +#endif
8500 +               newdstip = master->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.ip;
8501 +               newsrcip = master->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.ip;
8502 +               DEBUGP("ip_nat_talk_expected: callee client -> caller server, newsrc: %u.%u.%u.%u, newdst: %u.%u.%u.%u\n",
8503 +                      NIPQUAD(newsrcip), NIPQUAD(newdstip));
8504 +       } else {
8505 +               /* Callee client -> caller client */
8506 +#ifdef IP_NAT_TALK_DEBUG
8507 +               struct iphdr *iph = (*pskb)->nh.iph;
8508 +               struct tcphdr *tcph = (void *)iph + iph->ihl * 4;
8509 +
8510 +               DEBUGP("ip_nat_talk_expected: TCP %u.%u.%u.%u:%u->%u.%u.%u.%u:%u\n",
8511 +                      NIPQUAD(iph->saddr), ntohs(tcph->source),
8512 +                      NIPQUAD(iph->daddr), ntohs(tcph->dest));
8513 +#endif
8514 +               newdstip = master->tuplehash[IP_CT_DIR_REPLY].tuple.src.ip;
8515 +               newsrcip = master->tuplehash[IP_CT_DIR_REPLY].tuple.dst.ip;
8516 +               DEBUGP("ip_nat_talk_expected: callee client -> caller client, newsrc: %u.%u.%u.%u, newdst: %u.%u.%u.%u\n",
8517 +                      NIPQUAD(newsrcip), NIPQUAD(newdstip));
8518 +       }
8519 +       if (HOOK2MANIP(hooknum) == IP_NAT_MANIP_SRC)
8520 +               newip = newsrcip;
8521 +       else
8522 +               newip = newdstip;
8523 +
8524 +       DEBUGP("ip_nat_talk_expected: IP to %u.%u.%u.%u, port %u\n", NIPQUAD(newip), ntohs(port));
8525 +
8526 +       mr.rangesize = 1;
8527 +       /* We don't want to manip the per-protocol, just the IPs... */
8528 +       mr.range[0].flags = IP_NAT_RANGE_MAP_IPS;
8529 +       mr.range[0].min_ip = mr.range[0].max_ip = newip;
8530 +       
8531 +       /* ... unless we're doing a MANIP_DST, in which case, make
8532 +          sure we map to the correct port */
8533 +       if (HOOK2MANIP(hooknum) == IP_NAT_MANIP_DST) {
8534 +               mr.range[0].flags |= IP_NAT_RANGE_PROTO_SPECIFIED;
8535 +               mr.range[0].min = mr.range[0].max
8536 +                       = ((union ip_conntrack_manip_proto)
8537 +                               { .udp = { port } });
8538 +       }
8539 +       ret = ip_nat_setup_info(ct, &mr, hooknum);
8540 +
8541 +       if (ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum == IPPROTO_UDP) {
8542 +               DEBUGP("talk_expected: setting NAT helper for %p\n", ct);
8543 +               /* NAT expectfn called with ip_nat_lock write-locked */
8544 +               info->helper = &talk_helpers[htons(port) - TALK_PORT];
8545 +       }
8546 +       return ret;
8547 +}
8548 +
8549 +static int __init init(void)
8550 +{
8551 +       int ret = 0;
8552 +
8553 +       if (talk > 0) {
8554 +               ret = ip_nat_helper_register(&talk_helpers[0]);
8555 +
8556 +               if (ret != 0)
8557 +                       return ret;
8558 +       }
8559 +       if (ntalk > 0 || ntalk2 > 0) {
8560 +               ret = ip_nat_helper_register(&talk_helpers[1]);
8561 +
8562 +               if (ret != 0 && talk > 0)
8563 +                       ip_nat_helper_unregister(&talk_helpers[0]);
8564 +       }
8565 +       return ret;
8566 +}
8567 +
8568 +static void __exit fini(void)
8569 +{
8570 +       if (talk > 0)
8571 +               ip_nat_helper_unregister(&talk_helpers[0]);
8572 +       if (ntalk > 0 || ntalk2 > 0)
8573 +               ip_nat_helper_unregister(&talk_helpers[1]);
8574 +}
8575 +
8576 +module_init(init);
8577 +module_exit(fini);
8578 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ip_pool.c linux-2.6.6/net/ipv4/netfilter/ip_pool.c
8579 --- linux-2.6.6.org/net/ipv4/netfilter/ip_pool.c        1970-01-01 01:00:00.000000000 +0100
8580 +++ linux-2.6.6/net/ipv4/netfilter/ip_pool.c    2004-05-18 14:28:50.000000000 +0200
8581 @@ -0,0 +1,334 @@
8582 +/* Kernel module for IP pool management */
8583 +
8584 +#include <linux/module.h>
8585 +#include <linux/ip.h>
8586 +#include <linux/skbuff.h>
8587 +#include <linux/netfilter_ipv4/ip_tables.h>
8588 +#include <linux/netfilter_ipv4/ip_pool.h>
8589 +#include <linux/errno.h>
8590 +#include <asm/uaccess.h>
8591 +#include <asm/bitops.h>
8592 +#include <linux/interrupt.h>
8593 +#include <linux/spinlock.h>
8594 +
8595 +#if 0
8596 +#define DP printk
8597 +#else
8598 +#define DP(format, args...)
8599 +#endif
8600 +
8601 +MODULE_LICENSE("GPL");
8602 +
8603 +#define NR_POOL 16
8604 +static int nr_pool = NR_POOL;/* overwrite this when loading module */
8605 +
8606 +struct ip_pool {
8607 +       u_int32_t first_ip;     /* host byte order, included in range */
8608 +       u_int32_t last_ip;      /* host byte order, included in range */
8609 +       void *members;          /* the bitmap proper */
8610 +       int nr_use;             /* total nr. of tests through this */
8611 +       int nr_match;           /* total nr. of matches through this */
8612 +       rwlock_t lock;
8613 +};
8614 +
8615 +static struct ip_pool *POOL;
8616 +
8617 +static inline struct ip_pool *lookup(ip_pool_t index)
8618 +{
8619 +       if (index < 0 || index >= nr_pool) {
8620 +               DP("ip_pool:lookup: bad index %d\n", index);
8621 +               return 0;
8622 +       }
8623 +       return POOL+index;
8624 +}
8625 +
8626 +int ip_pool_match(ip_pool_t index, u_int32_t addr)
8627 +{
8628 +        struct ip_pool *pool = lookup(index);
8629 +       int res = 0;
8630 +
8631 +       if (!pool || !pool->members)
8632 +               return 0;
8633 +       read_lock_bh(&pool->lock);
8634 +       if (pool->members) {
8635 +               if (addr >= pool->first_ip && addr <= pool->last_ip) {
8636 +                       addr -= pool->first_ip;
8637 +                       if (test_bit(addr, pool->members)) {
8638 +                               res = 1;
8639 +#ifdef CONFIG_IP_POOL_STATISTICS
8640 +                               pool->nr_match++;
8641 +#endif
8642 +                       }
8643 +               }
8644 +#ifdef CONFIG_IP_POOL_STATISTICS
8645 +               pool->nr_use++;
8646 +#endif
8647 +       }
8648 +       read_unlock_bh(&pool->lock);
8649 +       return res;
8650 +}
8651 +EXPORT_SYMBOL(ip_pool_match);
8652 +
8653 +static int pool_change(ip_pool_t index, u_int32_t addr, int isdel)
8654 +{
8655 +       struct ip_pool *pool;
8656 +       int res = -1;
8657 +
8658 +       pool = lookup(index);
8659 +       if (    !pool || !pool->members
8660 +            || addr < pool->first_ip || addr > pool->last_ip)
8661 +               return -1;
8662 +       read_lock_bh(&pool->lock);
8663 +       if (pool->members && addr >= pool->first_ip && addr <= pool->last_ip) {
8664 +               addr -= pool->first_ip;
8665 +               res = isdel
8666 +                       ? (0 != test_and_clear_bit(addr, pool->members))
8667 +                       : (0 != test_and_set_bit(addr, pool->members));
8668 +       }
8669 +       read_unlock_bh(&pool->lock);
8670 +       return res;
8671 +}
8672 +
8673 +int ip_pool_mod(ip_pool_t index, u_int32_t addr, int isdel)
8674 +{
8675 +       int res = pool_change(index,addr,isdel);
8676 +
8677 +       if (!isdel) res = !res;
8678 +       return res;
8679 +}
8680 +EXPORT_SYMBOL(ip_pool_mod);
8681 +
8682 +static inline int bitmap_bytes(u_int32_t a, u_int32_t b)
8683 +{
8684 +       return 4*((((b-a+8)/8)+3)/4);
8685 +}
8686 +
8687 +static inline int poolbytes(ip_pool_t index)
8688 +{
8689 +       struct ip_pool *pool = lookup(index);
8690 +
8691 +       return pool ? bitmap_bytes(pool->first_ip, pool->last_ip) : 0;
8692 +}
8693 +
8694 +static int setpool(
8695 +       struct sock *sk,
8696 +       int optval,
8697 +       void *user,
8698 +       unsigned int len
8699 +) {
8700 +       struct ip_pool_request req;
8701 +
8702 +       DP("ip_pool:setpool: optval=%d, user=%p, len=%d\n", optval, user, len);
8703 +       if (!capable(CAP_NET_ADMIN))
8704 +               return -EPERM;
8705 +       if (optval != SO_IP_POOL)
8706 +               return -EBADF;
8707 +       if (len != sizeof(req))
8708 +               return -EINVAL;
8709 +       if (copy_from_user(&req, user, sizeof(req)) != 0)
8710 +               return -EFAULT;
8711 +       printk("obsolete op - upgrade your ippool(8) utility.\n");
8712 +       return -EINVAL;
8713 +}
8714 +
8715 +static int getpool(
8716 +       struct sock *sk,
8717 +       int optval,
8718 +       void *user,
8719 +       int *len
8720 +) {
8721 +       struct ip_pool_request req;
8722 +       struct ip_pool *pool;
8723 +       ip_pool_t i;
8724 +       int newbytes;
8725 +       void *newmembers;
8726 +       int res;
8727 +
8728 +       DP("ip_pool:getpool: optval=%d, user=%p\n", optval, user);
8729 +       if (!capable(CAP_NET_ADMIN))
8730 +               return -EINVAL;
8731 +       if (optval != SO_IP_POOL)
8732 +               return -EINVAL;
8733 +       if (*len != sizeof(req)) {
8734 +               return -EFAULT;
8735 +       }
8736 +       if (copy_from_user(&req, user, sizeof(req)) != 0)
8737 +               return -EFAULT;
8738 +       DP("ip_pool:getpool op=%d, index=%d\n", req.op, req.index);
8739 +       if (req.op < IP_POOL_BAD001) {
8740 +               printk("obsolete op - upgrade your ippool(8) utility.\n");
8741 +               return -EFAULT;
8742 +       }
8743 +       switch(req.op) {
8744 +       case IP_POOL_HIGH_NR:
8745 +               DP("ip_pool HIGH_NR\n");
8746 +               req.index = IP_POOL_NONE;
8747 +               for (i=0; i<nr_pool; i++)
8748 +                       if (POOL[i].members)
8749 +                               req.index = i;
8750 +               return copy_to_user(user, &req, sizeof(req));
8751 +       case IP_POOL_LOOKUP:
8752 +               DP("ip_pool LOOKUP\n");
8753 +               pool = lookup(req.index);
8754 +               if (!pool)
8755 +                       return -EINVAL;
8756 +               if (!pool->members)
8757 +                       return -EBADF;
8758 +               req.addr = htonl(pool->first_ip);
8759 +               req.addr2 = htonl(pool->last_ip);
8760 +               return copy_to_user(user, &req, sizeof(req));
8761 +       case IP_POOL_USAGE:
8762 +               DP("ip_pool USE\n");
8763 +               pool = lookup(req.index);
8764 +               if (!pool)
8765 +                       return -EINVAL;
8766 +               if (!pool->members)
8767 +                       return -EBADF;
8768 +               req.addr = pool->nr_use;
8769 +               req.addr2 = pool->nr_match;
8770 +               return copy_to_user(user, &req, sizeof(req));
8771 +       case IP_POOL_TEST_ADDR:
8772 +               DP("ip_pool TEST 0x%08x\n", req.addr);
8773 +               pool = lookup(req.index);
8774 +               if (!pool)
8775 +                       return -EINVAL;
8776 +               res = 0;
8777 +               read_lock_bh(&pool->lock);
8778 +               if (!pool->members) {
8779 +                       DP("ip_pool TEST_ADDR no members in pool\n");
8780 +                       res = -EBADF;
8781 +                       goto unlock_and_return_res;
8782 +               }
8783 +               req.addr = ntohl(req.addr);
8784 +               if (req.addr < pool->first_ip) {
8785 +                       DP("ip_pool TEST_ADDR address < pool bounds\n");
8786 +                       res = -ERANGE;
8787 +                       goto unlock_and_return_res;
8788 +               }
8789 +               if (req.addr > pool->last_ip) {
8790 +                       DP("ip_pool TEST_ADDR address > pool bounds\n");
8791 +                       res = -ERANGE;
8792 +                       goto unlock_and_return_res;
8793 +               }
8794 +               req.addr = (0 != test_bit((req.addr - pool->first_ip),
8795 +                                       pool->members));
8796 +               read_unlock_bh(&pool->lock);
8797 +               return copy_to_user(user, &req, sizeof(req));
8798 +       case IP_POOL_FLUSH:
8799 +               DP("ip_pool FLUSH not yet implemented.\n");
8800 +               return -EBUSY;
8801 +       case IP_POOL_DESTROY:
8802 +               DP("ip_pool DESTROY not yet implemented.\n");
8803 +               return -EBUSY;
8804 +       case IP_POOL_INIT:
8805 +               DP("ip_pool INIT 0x%08x-0x%08x\n", req.addr, req.addr2);
8806 +               pool = lookup(req.index);
8807 +               if (!pool)
8808 +                       return -EINVAL;
8809 +               req.addr = ntohl(req.addr);
8810 +               req.addr2 = ntohl(req.addr2);
8811 +               if (req.addr > req.addr2) {
8812 +                       DP("ip_pool INIT bad ip range\n");
8813 +                       return -EINVAL;
8814 +               }
8815 +               newbytes = bitmap_bytes(req.addr, req.addr2);
8816 +               newmembers = kmalloc(newbytes, GFP_KERNEL);
8817 +               if (!newmembers) {
8818 +                       DP("ip_pool INIT out of mem for %d bytes\n", newbytes);
8819 +                       return -ENOMEM;
8820 +               }
8821 +               memset(newmembers, 0, newbytes);
8822 +               write_lock_bh(&pool->lock);
8823 +               if (pool->members) {
8824 +                       DP("ip_pool INIT pool %d exists\n", req.index);
8825 +                       kfree(newmembers);
8826 +                       res = -EBUSY;
8827 +                       goto unlock_and_return_res;
8828 +               }
8829 +               pool->first_ip = req.addr;
8830 +               pool->last_ip = req.addr2;
8831 +               pool->nr_use = 0;
8832 +               pool->nr_match = 0;
8833 +               pool->members = newmembers;
8834 +               write_unlock_bh(&pool->lock);
8835 +               return 0;
8836 +       case IP_POOL_ADD_ADDR:
8837 +               DP("ip_pool ADD_ADDR 0x%08x\n", req.addr);
8838 +               req.addr = pool_change(req.index, ntohl(req.addr), 0);
8839 +               return copy_to_user(user, &req, sizeof(req));
8840 +       case IP_POOL_DEL_ADDR:
8841 +               DP("ip_pool DEL_ADDR 0x%08x\n", req.addr);
8842 +               req.addr = pool_change(req.index, ntohl(req.addr), 1);
8843 +               return copy_to_user(user, &req, sizeof(req));
8844 +       default:
8845 +               DP("ip_pool:getpool bad op %d\n", req.op);
8846 +               return -EINVAL;
8847 +       }
8848 +       return -EINVAL;
8849 +
8850 +unlock_and_return_res:
8851 +       if (pool)
8852 +               read_unlock_bh(&pool->lock);
8853 +       return res;
8854 +}
8855 +
8856 +static struct nf_sockopt_ops so_pool
8857 += { { NULL, NULL }, PF_INET,
8858 +    SO_IP_POOL, SO_IP_POOL+1, &setpool,
8859 +    SO_IP_POOL, SO_IP_POOL+1, &getpool,
8860 +    0, NULL };
8861 +
8862 +MODULE_PARM(nr_pool, "i");
8863 +
8864 +static int __init init(void)
8865 +{
8866 +       ip_pool_t i;
8867 +       int res;
8868 +
8869 +       if (nr_pool < 1) {
8870 +               printk("ip_pool module init: bad nr_pool %d\n", nr_pool);
8871 +               return -EINVAL;
8872 +       }
8873 +       POOL = kmalloc(nr_pool * sizeof(*POOL), GFP_KERNEL);
8874 +       if (!POOL) {
8875 +               printk("ip_pool module init: out of memory for nr_pool %d\n",
8876 +                       nr_pool);
8877 +               return -ENOMEM;
8878 +       }
8879 +       for (i=0; i<nr_pool; i++) {
8880 +               POOL[i].first_ip = 0;
8881 +               POOL[i].last_ip = 0;
8882 +               POOL[i].members = 0;
8883 +               POOL[i].nr_use = 0;
8884 +               POOL[i].nr_match = 0;
8885 +               POOL[i].lock = RW_LOCK_UNLOCKED;
8886 +       }
8887 +       res = nf_register_sockopt(&so_pool);
8888 +       DP("ip_pool:init %d pools, result %d\n", nr_pool, res);
8889 +       if (res != 0) {
8890 +               kfree(POOL);
8891 +               POOL = 0;
8892 +       }
8893 +       return res;
8894 +}
8895 +
8896 +static void __exit fini(void)
8897 +{
8898 +       ip_pool_t i;
8899 +
8900 +       DP("ip_pool:fini BYEBYE\n");
8901 +       nf_unregister_sockopt(&so_pool);
8902 +       for (i=0; i<nr_pool; i++) {
8903 +               if (POOL[i].members) {
8904 +                       kfree(POOL[i].members);
8905 +                       POOL[i].members = 0;
8906 +               }
8907 +       }
8908 +       kfree(POOL);
8909 +       POOL = 0;
8910 +       DP("ip_pool:fini these are the famous last words\n");
8911 +       return;
8912 +}
8913 +
8914 +module_init(init);
8915 +module_exit(fini);
8916 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ip_tables.c linux-2.6.6/net/ipv4/netfilter/ip_tables.c
8917 --- linux-2.6.6.org/net/ipv4/netfilter/ip_tables.c      2004-05-10 04:32:26.000000000 +0200
8918 +++ linux-2.6.6/net/ipv4/netfilter/ip_tables.c  2004-05-18 14:28:50.000000000 +0200
8919 @@ -29,6 +29,14 @@
8920  
8921  #include <linux/netfilter_ipv4/ip_tables.h>
8922  
8923 +static const char *hooknames[] = { 
8924 +       [NF_IP_PRE_ROUTING] "PREROUTING",
8925 +       [NF_IP_LOCAL_IN] "INPUT",
8926 +       [NF_IP_FORWARD] "FORWARD",
8927 +       [NF_IP_LOCAL_OUT] "OUTPUT",
8928 +       [NF_IP_POST_ROUTING] "POSTROUTING",
8929 +};
8930 +
8931  MODULE_LICENSE("GPL");
8932  MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>");
8933  MODULE_DESCRIPTION("IPv4 packet filter");
8934 @@ -326,6 +334,12 @@
8935  
8936                         t = ipt_get_target(e);
8937                         IP_NF_ASSERT(t->u.kernel.target);
8938 +
8939 +                       /* The packet traced and the rule isn't an unconditional return/END. */
8940 +                       if (((*pskb)->nfcache & NFC_TRACE) && e->rulenum) {       
8941 +                               nf_log_packet(PF_INET, hook, *pskb, in, out, "TRACE: %s/%s/%u ",
8942 +                                             table->name, e->chainname, e->rulenum);
8943 +                       }
8944                         /* Standard target? */
8945                         if (!t->u.kernel.target->target) {
8946                                 int v;
8947 @@ -343,7 +357,7 @@
8948                                         continue;
8949                                 }
8950                                 if (table_base + v
8951 -                                   != (void *)e + e->next_offset) {
8952 +                                   != (void *)e + e->next_offset && !(e->ip.flags & IPT_F_GOTO)) {
8953                                         /* Save old back ptr in next entry */
8954                                         struct ipt_entry *next
8955                                                 = (void *)e + e->next_offset;
8956 @@ -352,7 +366,6 @@
8957                                         /* set back pointer to next entry */
8958                                         back = next;
8959                                 }
8960 -
8961                                 e = get_entry(table_base, v);
8962                         } else {
8963                                 /* Targets which reenter must return
8964 @@ -478,6 +491,29 @@
8965         return find_inlist_lock(&ipt_target, name, "ipt_", error, mutex);
8966  }
8967  
8968 +static inline int
8969 +find_error_target(struct ipt_entry *s, 
8970 +                 struct ipt_entry *e,
8971 +                 char **chainname)
8972 +{
8973 +       struct ipt_entry_target *t;
8974 +       static struct ipt_entry *found = NULL;
8975 +
8976 +       if (s == e) {
8977 +               if (!found)
8978 +                       return 0;
8979 +               t = ipt_get_target(found);
8980 +               if (strcmp(t->u.user.name, 
8981 +                          IPT_ERROR_TARGET) == 0) {
8982 +                       *chainname = t->data;
8983 +                       return 1;
8984 +               }
8985 +       } else
8986 +               found = s;
8987 +       
8988 +       return 0;
8989 +}
8990 +
8991  /* All zeroes == unconditional rule. */
8992  static inline int
8993  unconditional(const struct ipt_ip *ip)
8994 @@ -497,6 +533,8 @@
8995  mark_source_chains(struct ipt_table_info *newinfo, unsigned int valid_hooks)
8996  {
8997         unsigned int hook;
8998 +       char *chainname = NULL;
8999 +       u_int32_t rulenum;
9000  
9001         /* No recursion; use packet counter to save back ptrs (reset
9002            to 0 as we leave), and comefrom to save source hook bitmask */
9003 @@ -510,6 +548,8 @@
9004  
9005                 /* Set initial back pointer. */
9006                 e->counters.pcnt = pos;
9007 +               rulenum = 1;
9008 +               chainname = (char *) hooknames[hook];
9009  
9010                 for (;;) {
9011                         struct ipt_standard_target *t
9012 @@ -522,6 +562,8 @@
9013                         }
9014                         e->comefrom
9015                                 |= ((1 << hook) | (1 << NF_IP_NUMHOOKS));
9016 +                       e->rulenum = rulenum++;
9017 +                       e->chainname = chainname;
9018  
9019                         /* Unconditional return/END. */
9020                         if (e->target_offset == sizeof(struct ipt_entry)
9021 @@ -531,6 +573,10 @@
9022                             && unconditional(&e->ip)) {
9023                                 unsigned int oldpos, size;
9024  
9025 +                               /* Set unconditional rulenum to zero. */
9026 +                               e->rulenum = 0;
9027 +                               e->counters.bcnt = 0;
9028 +
9029                                 /* Return: backtrack through the last
9030                                    big jump. */
9031                                 do {
9032 @@ -556,6 +602,11 @@
9033                                                 (newinfo->entries + pos);
9034                                 } while (oldpos == pos + e->next_offset);
9035  
9036 +                               /* Restore chainname, rulenum. */
9037 +                               chainname = e->chainname;
9038 +                               rulenum = e->counters.bcnt;
9039 +                               e->counters.bcnt = 0;
9040 +
9041                                 /* Move along one */
9042                                 size = e->next_offset;
9043                                 e = (struct ipt_entry *)
9044 @@ -571,6 +622,17 @@
9045                                         /* This a jump; chase it. */
9046                                         duprintf("Jump rule %u -> %u\n",
9047                                                  pos, newpos);
9048 +                                       e->counters.bcnt = rulenum++;
9049 +                                       rulenum = 1;
9050 +                                       e = (struct ipt_entry *)
9051 +                                               (newinfo->entries + newpos);
9052 +                                       if (IPT_ENTRY_ITERATE(newinfo->entries,
9053 +                                                             newinfo->size,
9054 +                                                             find_error_target,
9055 +                                                             e, &chainname) == 0) {
9056 +                                               printk("ip_tables: table screwed up!\n");
9057 +                                               return 0;
9058 +                                       }
9059                                 } else {
9060                                         /* ... this is a fallthru */
9061                                         newpos = pos + e->next_offset;
9062 @@ -1716,9 +1778,9 @@
9063  };
9064  
9065  #ifdef CONFIG_PROC_FS
9066 -static inline int print_name(const char *i,
9067 -                            off_t start_offset, char *buffer, int length,
9068 -                            off_t *pos, unsigned int *count)
9069 +static int print_name(const char *i,
9070 +                      off_t start_offset, char *buffer, int length,
9071 +                      off_t *pos, unsigned int *count)
9072  {
9073         if ((*count)++ >= start_offset) {
9074                 unsigned int namelen;
9075 @@ -1752,6 +1814,15 @@
9076         return pos;
9077  }
9078  
9079 +static inline int print_target(const struct ipt_target *t,
9080 +                               off_t start_offset, char *buffer, int length,
9081 +                               off_t *pos, unsigned int *count)
9082 +{
9083 +       if (t == &ipt_standard_target || t == &ipt_error_target)
9084 +               return 0;
9085 +       return print_name((char *)t, start_offset, buffer, length, pos, count);
9086 +}
9087 +
9088  static int ipt_get_targets(char *buffer, char **start, off_t offset, int length)
9089  {
9090         off_t pos = 0;
9091 @@ -1760,7 +1831,7 @@
9092         if (down_interruptible(&ipt_mutex) != 0)
9093                 return 0;
9094  
9095 -       LIST_FIND(&ipt_target, print_name, void *,
9096 +       LIST_FIND(&ipt_target, print_target, struct ipt_target *,
9097                   offset, buffer, length, &pos, &count);
9098         
9099         up(&ipt_mutex);
9100 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_CONNMARK.c linux-2.6.6/net/ipv4/netfilter/ipt_CONNMARK.c
9101 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_CONNMARK.c   1970-01-01 01:00:00.000000000 +0100
9102 +++ linux-2.6.6/net/ipv4/netfilter/ipt_CONNMARK.c       2004-05-18 14:28:50.000000000 +0200
9103 @@ -0,0 +1,118 @@
9104 +/* This kernel module is used to modify the connection mark values, or
9105 + * to optionally restore the skb nfmark from the connection mark
9106 + *
9107 + * Copyright (C) 2002,2004 MARA Systems AB <http://www.marasystems.com>
9108 + * by Henrik Nordstrom <hno@marasystems.com>
9109 + *
9110 + * This program is free software; you can redistribute it and/or modify
9111 + * it under the terms of the GNU General Public License as published by
9112 + * the Free Software Foundation; either version 2 of the License, or
9113 + * (at your option) any later version.
9114 + *
9115 + * This program is distributed in the hope that it will be useful,
9116 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9117 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9118 + * GNU General Public License for more details.
9119 + *
9120 + * You should have received a copy of the GNU General Public License
9121 + * along with this program; if not, write to the Free Software
9122 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
9123 + */
9124 +#include <linux/module.h>
9125 +#include <linux/skbuff.h>
9126 +#include <linux/ip.h>
9127 +#include <net/checksum.h>
9128 +
9129 +MODULE_AUTHOR("Henrik Nordstrom <hno@marasytems.com>");
9130 +MODULE_DESCRIPTION("IP tables CONNMARK matching module");
9131 +MODULE_LICENSE("GPL");
9132 +
9133 +#include <linux/netfilter_ipv4/ip_tables.h>
9134 +#include <linux/netfilter_ipv4/ipt_CONNMARK.h>
9135 +#include <linux/netfilter_ipv4/ip_conntrack.h>
9136 +
9137 +static unsigned int
9138 +target(struct sk_buff **pskb,
9139 +       const struct net_device *in,
9140 +       const struct net_device *out,
9141 +       unsigned int hooknum,
9142 +       const void *targinfo,
9143 +       void *userinfo)
9144 +{
9145 +       const struct ipt_connmark_target_info *markinfo = targinfo;
9146 +       unsigned long diff;
9147 +       unsigned long nfmark;
9148 +       unsigned long newmark;
9149 +
9150 +       enum ip_conntrack_info ctinfo;
9151 +       struct ip_conntrack *ct = ip_conntrack_get((*pskb), &ctinfo);
9152 +       if (ct) {
9153 +           switch(markinfo->mode) {
9154 +           case IPT_CONNMARK_SET:
9155 +               newmark = (ct->mark & ~markinfo->mask) | markinfo->mark;
9156 +               if (newmark != ct->mark)
9157 +                   ct->mark = newmark;
9158 +               break;
9159 +           case IPT_CONNMARK_SAVE:
9160 +               newmark = (ct->mark & ~markinfo->mask) | ((*pskb)->nfmark & markinfo->mask);
9161 +               if (ct->mark != newmark)
9162 +                   ct->mark = newmark;
9163 +               break;
9164 +           case IPT_CONNMARK_RESTORE:
9165 +               nfmark = (*pskb)->nfmark;
9166 +               diff = (ct->mark ^ nfmark & markinfo->mask);
9167 +               if (diff != 0) {
9168 +                   (*pskb)->nfmark = nfmark ^ diff;
9169 +                   (*pskb)->nfcache |= NFC_ALTERED;
9170 +               }
9171 +               break;
9172 +           }
9173 +       }
9174 +
9175 +       return IPT_CONTINUE;
9176 +}
9177 +
9178 +static int
9179 +checkentry(const char *tablename,
9180 +          const struct ipt_entry *e,
9181 +          void *targinfo,
9182 +          unsigned int targinfosize,
9183 +          unsigned int hook_mask)
9184 +{
9185 +       struct ipt_connmark_target_info *matchinfo = targinfo;
9186 +       if (targinfosize != IPT_ALIGN(sizeof(struct ipt_connmark_target_info))) {
9187 +               printk(KERN_WARNING "CONNMARK: targinfosize %u != %Zu\n",
9188 +                      targinfosize,
9189 +                      IPT_ALIGN(sizeof(struct ipt_connmark_target_info)));
9190 +               return 0;
9191 +       }
9192 +
9193 +       if (matchinfo->mode == IPT_CONNMARK_RESTORE) {
9194 +           if (strcmp(tablename, "mangle") != 0) {
9195 +                   printk(KERN_WARNING "CONNMARK: restore can only be called from \"mangle\" table, not \"%s\"\n", tablename);
9196 +                   return 0;
9197 +           }
9198 +       }
9199 +
9200 +       return 1;
9201 +}
9202 +
9203 +static struct ipt_target ipt_connmark_reg = {
9204 +       .name = "CONNMARK",
9205 +       .target = &target,
9206 +       .checkentry = &checkentry,
9207 +       .me = THIS_MODULE
9208 +};
9209 +
9210 +static int __init init(void)
9211 +{
9212 +       return ipt_register_target(&ipt_connmark_reg);
9213 +}
9214 +
9215 +static void __exit fini(void)
9216 +{
9217 +       ipt_unregister_target(&ipt_connmark_reg);
9218 +}
9219 +
9220 +module_init(init);
9221 +module_exit(fini);
9222 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_IPMARK.c linux-2.6.6/net/ipv4/netfilter/ipt_IPMARK.c
9223 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_IPMARK.c     1970-01-01 01:00:00.000000000 +0100
9224 +++ linux-2.6.6/net/ipv4/netfilter/ipt_IPMARK.c 2004-05-18 14:28:50.000000000 +0200
9225 @@ -0,0 +1,81 @@
9226 +/* This is a module which is used for setting the NFMARK field of an skb. */
9227 +#include <linux/module.h>
9228 +#include <linux/skbuff.h>
9229 +#include <linux/ip.h>
9230 +#include <net/checksum.h>
9231 +
9232 +#include <linux/netfilter_ipv4/ip_tables.h>
9233 +#include <linux/netfilter_ipv4/ipt_IPMARK.h>
9234 +
9235 +MODULE_AUTHOR("Grzegorz Janoszka <Grzegorz.Janoszka@pro.onet.pl>");
9236 +MODULE_DESCRIPTION("IP tables IPMARK: mark based on ip address");
9237 +MODULE_LICENSE("GPL");
9238 +
9239 +static unsigned int
9240 +target(struct sk_buff **pskb,
9241 +       const struct net_device *in,
9242 +       const struct net_device *out,
9243 +       unsigned int hooknum,
9244 +       const void *targinfo,
9245 +       void *userinfo)
9246 +{
9247 +       const struct ipt_ipmark_target_info *ipmarkinfo = targinfo;
9248 +       struct iphdr *iph = (*pskb)->nh.iph;
9249 +       unsigned long mark;
9250 +
9251 +       if (ipmarkinfo->addr == IPT_IPMARK_SRC)
9252 +               mark = (unsigned long) ntohl(iph->saddr);
9253 +       else
9254 +               mark = (unsigned long) ntohl(iph->daddr);
9255 +
9256 +       mark &= ipmarkinfo->andmask;
9257 +       mark |= ipmarkinfo->ormask;
9258 +       
9259 +       if ((*pskb)->nfmark != mark) {
9260 +               (*pskb)->nfmark = mark;
9261 +               (*pskb)->nfcache |= NFC_ALTERED;
9262 +       }
9263 +       return IPT_CONTINUE;
9264 +}
9265 +
9266 +static int
9267 +checkentry(const char *tablename,
9268 +          const struct ipt_entry *e,
9269 +           void *targinfo,
9270 +           unsigned int targinfosize,
9271 +           unsigned int hook_mask)
9272 +{
9273 +       if (targinfosize != IPT_ALIGN(sizeof(struct ipt_ipmark_target_info))) {
9274 +               printk(KERN_WARNING "IPMARK: targinfosize %u != %Zu\n",
9275 +                      targinfosize,
9276 +                      IPT_ALIGN(sizeof(struct ipt_ipmark_target_info)));
9277 +               return 0;
9278 +       }
9279 +
9280 +       if (strcmp(tablename, "mangle") != 0) {
9281 +               printk(KERN_WARNING "IPMARK: can only be called from \"mangle\" table, not \"%s\"\n", tablename);
9282 +               return 0;
9283 +       }
9284 +
9285 +       return 1;
9286 +}
9287 +
9288 +static struct ipt_target ipt_ipmark_reg = { 
9289 +       .name = "IPMARK",
9290 +       .target = target,
9291 +       .checkentry = checkentry,
9292 +       .me = THIS_MODULE
9293 +};
9294 +
9295 +static int __init init(void)
9296 +{
9297 +       return ipt_register_target(&ipt_ipmark_reg);
9298 +}
9299 +
9300 +static void __exit fini(void)
9301 +{
9302 +       ipt_unregister_target(&ipt_ipmark_reg);
9303 +}
9304 +
9305 +module_init(init);
9306 +module_exit(fini);
9307 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_IPV4OPTSSTRIP.c linux-2.6.6/net/ipv4/netfilter/ipt_IPV4OPTSSTRIP.c
9308 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_IPV4OPTSSTRIP.c      1970-01-01 01:00:00.000000000 +0100
9309 +++ linux-2.6.6/net/ipv4/netfilter/ipt_IPV4OPTSSTRIP.c  2004-05-18 14:28:50.000000000 +0200
9310 @@ -0,0 +1,89 @@
9311 +/**
9312 + * Strip all IP options in the IP packet header.
9313 + *
9314 + * (C) 2001 by Fabrice MARIE <fabrice@netfilter.org>
9315 + * This software is distributed under GNU GPL v2, 1991
9316 + */
9317 +
9318 +#include <linux/module.h>
9319 +#include <linux/skbuff.h>
9320 +#include <linux/ip.h>
9321 +#include <net/checksum.h>
9322 +
9323 +#include <linux/netfilter_ipv4/ip_tables.h>
9324 +
9325 +MODULE_AUTHOR("Fabrice MARIE <fabrice@netfilter.org>");
9326 +MODULE_DESCRIPTION("Strip all options in IPv4 packets");
9327 +MODULE_LICENSE("GPL");
9328 +
9329 +static unsigned int
9330 +target(struct sk_buff **pskb,
9331 +       const struct net_device *in,
9332 +       const struct net_device *out,
9333 +       unsigned int hooknum,
9334 +       const void *targinfo,
9335 +       void *userinfo)
9336 +{
9337 +       struct iphdr *iph;
9338 +       struct sk_buff *skb;
9339 +       struct ip_options *opt;
9340 +       unsigned char *optiph;
9341 +       int l;
9342 +       
9343 +       if (!skb_ip_make_writable(pskb, (*pskb)->len))
9344 +               return NF_DROP;
9345
9346 +       skb = (*pskb);
9347 +       iph = (*pskb)->nh.iph;
9348 +       optiph = skb->nh.raw;
9349 +       l = ((struct ip_options *)(&(IPCB(skb)->opt)))->optlen;
9350 +
9351 +       /* if no options in packet then nothing to clear. */
9352 +       if (iph->ihl * 4 == sizeof(struct iphdr))
9353 +               return IPT_CONTINUE;
9354 +
9355 +       /* else clear all options */
9356 +       memset(&(IPCB(skb)->opt), 0, sizeof(struct ip_options));
9357 +       memset(optiph+sizeof(struct iphdr), IPOPT_NOOP, l);
9358 +       opt = &(IPCB(skb)->opt);
9359 +       opt->is_data = 0;
9360 +       opt->optlen = l;
9361 +
9362 +       skb->nfcache |= NFC_ALTERED;
9363 +
9364 +        return IPT_CONTINUE;
9365 +}
9366 +
9367 +static int
9368 +checkentry(const char *tablename,
9369 +          const struct ipt_entry *e,
9370 +           void *targinfo,
9371 +           unsigned int targinfosize,
9372 +           unsigned int hook_mask)
9373 +{
9374 +       if (strcmp(tablename, "mangle")) {
9375 +               printk(KERN_WARNING "IPV4OPTSSTRIP: can only be called from \"mangle\" table, not \"%s\"\n", tablename);
9376 +               return 0;
9377 +       }
9378 +       /* nothing else to check because no parameters */
9379 +       return 1;
9380 +}
9381 +
9382 +static struct ipt_target ipt_ipv4optsstrip_reg = { 
9383 +       .name = "IPV4OPTSSTRIP",
9384 +       .target = target,
9385 +       .checkentry = checkentry,
9386 +       .me = THIS_MODULE };
9387 +
9388 +static int __init init(void)
9389 +{
9390 +       return ipt_register_target(&ipt_ipv4optsstrip_reg);
9391 +}
9392 +
9393 +static void __exit fini(void)
9394 +{
9395 +       ipt_unregister_target(&ipt_ipv4optsstrip_reg);
9396 +}
9397 +
9398 +module_init(init);
9399 +module_exit(fini);
9400 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_MARK.c linux-2.6.6/net/ipv4/netfilter/ipt_MARK.c
9401 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_MARK.c       2004-05-10 04:32:37.000000000 +0200
9402 +++ linux-2.6.6/net/ipv4/netfilter/ipt_MARK.c   2004-05-18 14:28:50.000000000 +0200
9403 @@ -29,10 +29,20 @@
9404  {
9405         const struct ipt_mark_target_info *markinfo = targinfo;
9406  
9407 -       if((*pskb)->nfmark != markinfo->mark) {
9408 +       switch (markinfo->mode) {
9409 +       case IPT_MARK_SET:
9410                 (*pskb)->nfmark = markinfo->mark;
9411 -               (*pskb)->nfcache |= NFC_ALTERED;
9412 +               break;
9413 +               
9414 +       case IPT_MARK_AND:
9415 +               (*pskb)->nfmark &= markinfo->mark;
9416 +               break;
9417 +               
9418 +       case IPT_MARK_OR:
9419 +               (*pskb)->nfmark |= markinfo->mark;
9420 +               break;
9421         }
9422 +        (*pskb)->nfcache |= NFC_ALTERED;
9423         return IPT_CONTINUE;
9424  }
9425  
9426 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_NETLINK.c linux-2.6.6/net/ipv4/netfilter/ipt_NETLINK.c
9427 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_NETLINK.c    1970-01-01 01:00:00.000000000 +0100
9428 +++ linux-2.6.6/net/ipv4/netfilter/ipt_NETLINK.c        2004-05-18 14:28:50.000000000 +0200
9429 @@ -0,0 +1,119 @@
9430 +#include <linux/module.h>
9431 +#include <linux/version.h>
9432 +#include <linux/config.h>
9433 +#include <linux/socket.h>
9434 +#include <linux/skbuff.h>
9435 +#include <linux/kernel.h>
9436 +#include <linux/netlink.h>
9437 +#include <linux/netdevice.h>
9438 +#include <linux/mm.h>
9439 +#include <linux/socket.h>
9440 +#include <linux/netfilter_ipv4/ip_tables.h>
9441 +#include <linux/netfilter_ipv4/ipt_NETLINK.h>
9442 +#include <net/sock.h>
9443 +
9444 +MODULE_AUTHOR("Gianni Tedesco <gianni@ecsc.co.uk>");
9445 +MODULE_DESCRIPTION("Provides iptables NETLINK target similar to ipchains -o");
9446 +MODULE_LICENSE("GPL");
9447 +
9448 +#if 0
9449 +#define DEBUGP printk
9450 +#else
9451 +#define DEBUGP(format, args...)
9452 +#endif
9453 +
9454 +static struct sock *ipfwsk;
9455 +
9456 +static unsigned int ipt_netlink_target(struct sk_buff **pskb,
9457 +                                   unsigned int hooknum,
9458 +                                   const struct net_device *in,
9459 +                                   const struct net_device *out,
9460 +                                   const void *targinfo, void *userinfo)
9461 +{
9462 +       struct ipt_nldata *nld = (struct ipt_nldata *)targinfo;
9463 +       struct iphdr *ip = (*pskb)->nh.iph;
9464 +       struct sk_buff *outskb;
9465 +       struct netlink_t nlhdr;
9466 +       size_t len=0;
9467 +
9468 +       /* Allocate a socket buffer */
9469 +       if ( MASK(nld->flags, USE_SIZE) )
9470 +               len = nld->size+sizeof(nlhdr);
9471 +       else
9472 +               len = ntohs(ip->tot_len)+sizeof(nlhdr); 
9473 +
9474 +       outskb=alloc_skb(len, GFP_ATOMIC);
9475 +
9476 +       if (outskb) {
9477 +               nlhdr.len=len;
9478 +               
9479 +               if ( MASK(nld->flags, USE_MARK) )
9480 +                       nlhdr.mark=(*pskb)->nfmark=nld->mark;
9481 +               else
9482 +                       nlhdr.mark=(*pskb)->nfmark;
9483 +               
9484 +               if ( in && in->name ) {
9485 +                       strncpy((char *)&nlhdr.iface, in->name, IFNAMSIZ);
9486 +               }else if ( out && out->name ){
9487 +                       strncpy((char *)&nlhdr.iface, out->name, IFNAMSIZ);
9488 +               }
9489 +
9490 +               skb_put(outskb, len);
9491 +               memcpy(outskb->data, &nlhdr, sizeof(nlhdr));
9492 +               memcpy((outskb->data)+sizeof(nlhdr), ip, len-sizeof(nlhdr));
9493 +               netlink_broadcast(ipfwsk, outskb, 0, ~0, GFP_ATOMIC);
9494 +       }else{
9495 +               if (net_ratelimit())
9496 +                       printk(KERN_WARNING "ipt_NETLINK: packet drop due to netlink failure\n");
9497 +       }
9498 +
9499 +       if ( MASK(nld->flags, USE_DROP) )
9500 +               return NF_DROP;
9501 +
9502 +       return IPT_CONTINUE;
9503 +}
9504 +
9505 +static int ipt_netlink_checkentry(const char *tablename,
9506 +                              const struct ipt_entry *e,
9507 +                              void *targinfo,
9508 +                              unsigned int targinfosize,
9509 +                              unsigned int hookmask)
9510 +{
9511 +       //struct ipt_nldata *nld = (struct ipt_nldata *)targinfo;
9512 +
9513 +       return 1;
9514 +}
9515 +
9516 +static struct ipt_target ipt_netlink_reg = { 
9517 +       {NULL, NULL},
9518 +       "NETLINK",
9519 +       ipt_netlink_target,
9520 +       ipt_netlink_checkentry,
9521 +       NULL,
9522 +       THIS_MODULE
9523 +};
9524 +
9525 +static int __init init(void)
9526 +{
9527 +       DEBUGP("ipt_NETLINK: init module\n");   
9528 +
9529 +       if (ipt_register_target(&ipt_netlink_reg) != 0) {
9530 +               return -EINVAL;
9531 +       }
9532 +
9533 +       if ( !(ipfwsk=netlink_kernel_create(NETLINK_FIREWALL, NULL)) ){
9534 +               return -EINVAL;
9535 +       }
9536 +
9537 +       return 0;
9538 +}
9539 +
9540 +static void __exit fini(void)
9541 +{
9542 +       DEBUGP("ipt_NETLINK: cleanup_module\n");
9543 +       ipt_unregister_target(&ipt_netlink_reg);
9544 +       if(ipfwsk->sk_socket) sock_release(ipfwsk->sk_socket);
9545 +}
9546 +
9547 +module_init(init);
9548 +module_exit(fini);
9549 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_POOL.c linux-2.6.6/net/ipv4/netfilter/ipt_POOL.c
9550 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_POOL.c       1970-01-01 01:00:00.000000000 +0100
9551 +++ linux-2.6.6/net/ipv4/netfilter/ipt_POOL.c   2004-05-18 14:28:50.000000000 +0200
9552 @@ -0,0 +1,116 @@
9553 +/* ipt_POOL.c - netfilter target to manipulate IP pools
9554 + *
9555 + * This target can be used almost everywhere. It acts on some specified
9556 + * IP pool, adding or deleting some IP address in the pool. The address
9557 + * can be either the source (--addsrc, --delsrc), or destination (--add/deldst)
9558 + * of the packet under inspection.
9559 + *
9560 + * The target normally returns IPT_CONTINUE.
9561 + */
9562 +
9563 +#include <linux/types.h>
9564 +#include <linux/ip.h>
9565 +#include <linux/timer.h>
9566 +#include <linux/module.h>
9567 +#include <linux/netfilter.h>
9568 +#include <linux/netdevice.h>
9569 +#include <linux/if.h>
9570 +#include <linux/inetdevice.h>
9571 +#include <net/protocol.h>
9572 +#include <net/checksum.h>
9573 +#include <linux/netfilter_ipv4.h>
9574 +#include <linux/netfilter_ipv4/ip_nat_rule.h>
9575 +#include <linux/netfilter_ipv4/ipt_pool.h>
9576 +
9577 +#if 0
9578 +#define DEBUGP printk
9579 +#else
9580 +#define DEBUGP(format, args...)
9581 +#endif
9582 +
9583 +/*** NOTE NOTE NOTE NOTE ***
9584 +**
9585 +** By sheer luck, I get away with using the "struct ipt_pool_info", as defined
9586 +** in <linux/netfilter_ipv4/ipt_pool.h>, both as the match and target info.
9587 +** Here, in the target implementation, ipt_pool_info.src, if not IP_POOL_NONE,
9588 +** is modified for the source IP address of the packet under inspection.
9589 +** The same way, the ipt_pool_info.dst pool is modified for the destination.
9590 +**
9591 +** The address is added to the pool normally. However, if IPT_POOL_DEL_dir
9592 +** flag is set in ipt_pool_info.flags, the address is deleted from the pool.
9593 +**
9594 +** If a modification was done to the pool, we possibly return ACCEPT or DROP,
9595 +** if the right IPT_POOL_MOD_dir_ACCEPT or _MOD_dir_DROP flags are set.
9596 +** The IPT_POOL_INV_MOD_dir flag inverts the sense of the check (i.e. the
9597 +** ACCEPT and DROP flags are evaluated when the pool was not modified.)
9598 +*/
9599 +
9600 +static int
9601 +do_check(const char *tablename,
9602 +              const struct ipt_entry *e,
9603 +              void *targinfo,
9604 +              unsigned int targinfosize,
9605 +              unsigned int hook_mask)
9606 +{
9607 +       const struct ipt_pool_info *ipi = targinfo;
9608 +
9609 +       if (targinfosize != IPT_ALIGN(sizeof(*ipi))) {
9610 +               DEBUGP("POOL_check: size %u.\n", targinfosize);
9611 +               return 0;
9612 +       }
9613 +       DEBUGP("ipt_POOL:do_check(%d,%d,%d)\n",ipi->src,ipi->dst,ipi->flags);
9614 +       return 1;
9615 +}
9616 +
9617 +static unsigned int
9618 +do_target(struct sk_buff **pskb,
9619 +               unsigned int hooknum,
9620 +               const struct net_device *in,
9621 +               const struct net_device *out,
9622 +               const void *targinfo,
9623 +               void *userinfo)
9624 +{
9625 +       const struct ipt_pool_info *ipi = targinfo;
9626 +       int modified;
9627 +       unsigned int verdict = IPT_CONTINUE;
9628 +
9629 +       if (ipi->src != IP_POOL_NONE) {
9630 +               modified = ip_pool_mod(ipi->src, ntohl((*pskb)->nh.iph->saddr),
9631 +                                       ipi->flags & IPT_POOL_DEL_SRC);
9632 +               if (!!modified ^ !!(ipi->flags & IPT_POOL_INV_MOD_SRC)) {
9633 +                       if (ipi->flags & IPT_POOL_MOD_SRC_ACCEPT)
9634 +                               verdict = NF_ACCEPT;
9635 +                       else if (ipi->flags & IPT_POOL_MOD_SRC_DROP)
9636 +                               verdict = NF_DROP;
9637 +               }
9638 +       }
9639 +       if (verdict == IPT_CONTINUE && ipi->dst != IP_POOL_NONE) {
9640 +               modified = ip_pool_mod(ipi->dst, ntohl((*pskb)->nh.iph->daddr),
9641 +                                       ipi->flags & IPT_POOL_DEL_DST);
9642 +               if (!!modified ^ !!(ipi->flags & IPT_POOL_INV_MOD_DST)) {
9643 +                       if (ipi->flags & IPT_POOL_MOD_DST_ACCEPT)
9644 +                               verdict = NF_ACCEPT;
9645 +                       else if (ipi->flags & IPT_POOL_MOD_DST_DROP)
9646 +                               verdict = NF_DROP;
9647 +               }
9648 +       }
9649 +       return verdict;
9650 +}
9651 +
9652 +static struct ipt_target pool_reg
9653 += { { NULL, NULL }, "POOL", do_target, do_check, NULL, THIS_MODULE };
9654 +
9655 +static int __init init(void)
9656 +{
9657 +       DEBUGP("init ipt_POOL\n");
9658 +       return ipt_register_target(&pool_reg);
9659 +}
9660 +
9661 +static void __exit fini(void)
9662 +{
9663 +       DEBUGP("fini ipt_POOL\n");
9664 +       ipt_unregister_target(&pool_reg);
9665 +}
9666 +
9667 +module_init(init);
9668 +module_exit(fini);
9669 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_ROUTE.c linux-2.6.6/net/ipv4/netfilter/ipt_ROUTE.c
9670 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_ROUTE.c      1970-01-01 01:00:00.000000000 +0100
9671 +++ linux-2.6.6/net/ipv4/netfilter/ipt_ROUTE.c  2004-05-18 14:28:50.000000000 +0200
9672 @@ -0,0 +1,393 @@
9673 +/*
9674 + * This implements the ROUTE target, which enables you to setup unusual
9675 + * routes not supported by the standard kernel routing table.
9676 + *
9677 + * Copyright (C) 2002 Cedric de Launois <delaunois@info.ucl.ac.be>
9678 + *
9679 + * v 1.9 2004/05/14
9680 + *
9681 + * This software is distributed under GNU GPL v2, 1991
9682 + */
9683 +
9684 +#include <linux/module.h>
9685 +#include <linux/skbuff.h>
9686 +#include <linux/ip.h>
9687 +#include <linux/netfilter_ipv4/ip_tables.h>
9688 +#include <linux/netfilter_ipv4/ipt_ROUTE.h>
9689 +#include <linux/netdevice.h>
9690 +#include <linux/route.h>
9691 +#include <net/ip.h>
9692 +#include <net/route.h>
9693 +#include <net/icmp.h>
9694 +#include <net/checksum.h>
9695 +
9696 +#if 0
9697 +#define DEBUGP printk
9698 +#else
9699 +#define DEBUGP(format, args...)
9700 +#endif
9701 +
9702 +MODULE_LICENSE("GPL");
9703 +MODULE_AUTHOR("Cedric de Launois <delaunois@info.ucl.ac.be>");
9704 +MODULE_DESCRIPTION("iptables ROUTE target module");
9705 +
9706 +/* Try to route the packet according to the routing keys specified in
9707 + * route_info. Keys are :
9708 + *  - ifindex : 
9709 + *      0 if no oif preferred, 
9710 + *      otherwise set to the index of the desired oif
9711 + *  - route_info->gw :
9712 + *      0 if no gateway specified,
9713 + *      otherwise set to the next host to which the pkt must be routed
9714 + * If success, skb->dev is the output device to which the packet must 
9715 + * be sent and skb->dst is not NULL
9716 + *
9717 + * RETURN: -1 if an error occured
9718 + *          1 if the packet was succesfully routed to the 
9719 + *            destination desired
9720 + *          0 if the kernel routing table could not route the packet
9721 + *            according to the keys specified
9722 + */
9723 +static int route(struct sk_buff *skb,
9724 +                unsigned int ifindex,
9725 +                const struct ipt_route_target_info *route_info)
9726 +{
9727 +       int err;
9728 +       struct rtable *rt;
9729 +       struct iphdr *iph = skb->nh.iph;
9730 +       struct flowi fl = {
9731 +               .oif = ifindex,
9732 +               .nl_u = {
9733 +                       .ip4_u = {
9734 +                               .daddr = iph->daddr,
9735 +                               .saddr = 0,
9736 +                               .tos = RT_TOS(iph->tos),
9737 +                               .scope = RT_SCOPE_UNIVERSE,
9738 +                       }
9739 +               } 
9740 +       };
9741 +       
9742 +       /* The destination address may be overloaded by the target */
9743 +       if (route_info->gw)
9744 +               fl.fld_dst = route_info->gw;
9745 +       
9746 +       /* Trying to route the packet using the standard routing table. */
9747 +       if ((err = ip_route_output_key(&rt, &fl))) {
9748 +               if (net_ratelimit()) 
9749 +                       DEBUGP("ipt_ROUTE: couldn't route pkt (err: %i)",err);
9750 +               return -1;
9751 +       }
9752 +       
9753 +       /* Drop old route. */
9754 +       dst_release(skb->dst);
9755 +       skb->dst = NULL;
9756 +
9757 +       /* Success if no oif specified or if the oif correspond to the 
9758 +        * one desired */
9759 +       if (!ifindex || rt->u.dst.dev->ifindex == ifindex) {
9760 +               skb->dst = &rt->u.dst;
9761 +               skb->dev = skb->dst->dev;
9762 +               return 1;
9763 +       }
9764 +       
9765 +       /* The interface selected by the routing table is not the one
9766 +        * specified by the user. This may happen because the dst address
9767 +        * is one of our own addresses.
9768 +        */
9769 +       if (net_ratelimit()) 
9770 +               DEBUGP("ipt_ROUTE: failed to route as desired gw=%u.%u.%u.%u oif=%i (got oif=%i)\n", 
9771 +                      NIPQUAD(route_info->gw), ifindex, rt->u.dst.dev->ifindex);
9772 +       
9773 +       return 0;
9774 +}
9775 +
9776 +
9777 +/* Stolen from ip_finish_output2
9778 + * PRE : skb->dev is set to the device we are leaving by
9779 + *       skb->dst is not NULL
9780 + * POST: the packet is sent with the link layer header pushed
9781 + *       the packet is destroyed
9782 + */
9783 +static void ip_direct_send(struct sk_buff *skb)
9784 +{
9785 +       struct dst_entry *dst = skb->dst;
9786 +       struct hh_cache *hh = dst->hh;
9787 +
9788 +       if (hh) {
9789 +               read_lock_bh(&hh->hh_lock);
9790 +               memcpy(skb->data - 16, hh->hh_data, 16);
9791 +               read_unlock_bh(&hh->hh_lock);
9792 +               skb_push(skb, hh->hh_len);
9793 +               hh->hh_output(skb);
9794 +       } else if (dst->neighbour)
9795 +               dst->neighbour->output(skb);
9796 +       else {
9797 +               if (net_ratelimit())
9798 +                       DEBUGP(KERN_DEBUG "ipt_ROUTE: no hdr & no neighbour cache!\n");
9799 +               kfree_skb(skb);
9800 +       }
9801 +}
9802 +
9803 +
9804 +/* PRE : skb->dev is set to the device we are leaving by
9805 + * POST: - the packet is directly sent to the skb->dev device, without 
9806 + *         pushing the link layer header.
9807 + *       - the packet is destroyed
9808 + */
9809 +static inline int dev_direct_send(struct sk_buff *skb)
9810 +{
9811 +       return dev_queue_xmit(skb);
9812 +}
9813 +
9814 +
9815 +static unsigned int route_oif(const struct ipt_route_target_info *route_info,
9816 +                             struct sk_buff *skb) 
9817 +{
9818 +       unsigned int ifindex = 0;
9819 +       struct net_device *dev_out = NULL;
9820 +
9821 +       /* The user set the interface name to use.
9822 +        * Getting the current interface index.
9823 +        */
9824 +       if ((dev_out = dev_get_by_name(route_info->oif))) {
9825 +               ifindex = dev_out->ifindex;
9826 +       } else {
9827 +               /* Unknown interface name : packet dropped */
9828 +               if (net_ratelimit()) 
9829 +                       DEBUGP("ipt_ROUTE: oif interface %s not found\n", route_info->oif);
9830 +               return NF_DROP;
9831 +       }
9832 +
9833 +       /* Trying the standard way of routing packets */
9834 +       switch (route(skb, ifindex, route_info)) {
9835 +       case 1:
9836 +               dev_put(dev_out);
9837 +               if (route_info->flags & IPT_ROUTE_CONTINUE)
9838 +                       return IPT_CONTINUE;
9839 +
9840 +               ip_direct_send(skb);
9841 +               return NF_STOLEN;
9842 +
9843 +       case 0:
9844 +               /* Failed to send to oif. Trying the hard way */
9845 +               if (route_info->flags & IPT_ROUTE_CONTINUE)
9846 +                       return NF_DROP;
9847 +
9848 +               if (net_ratelimit()) 
9849 +                       DEBUGP("ipt_ROUTE: forcing the use of %i\n",
9850 +                              ifindex);
9851 +
9852 +               /* We have to force the use of an interface.
9853 +                * This interface must be a tunnel interface since
9854 +                * otherwise we can't guess the hw address for
9855 +                * the packet. For a tunnel interface, no hw address
9856 +                * is needed.
9857 +                */
9858 +               if ((dev_out->type != ARPHRD_TUNNEL)
9859 +                   && (dev_out->type != ARPHRD_IPGRE)) {
9860 +                       if (net_ratelimit()) 
9861 +                               DEBUGP("ipt_ROUTE: can't guess the hw addr !\n");
9862 +                       dev_put(dev_out);
9863 +                       return NF_DROP;
9864 +               }
9865 +       
9866 +               /* Send the packet. This will also free skb
9867 +                * Do not go through the POST_ROUTING hook because 
9868 +                * skb->dst is not set and because it will probably
9869 +                * get confused by the destination IP address.
9870 +                */
9871 +               skb->dev = dev_out;
9872 +               dev_direct_send(skb);
9873 +               dev_put(dev_out);
9874 +               return NF_STOLEN;
9875 +               
9876 +       default:
9877 +               /* Unexpected error */
9878 +               dev_put(dev_out);
9879 +               return NF_DROP;
9880 +       }
9881 +}
9882 +
9883 +
9884 +static unsigned int route_iif(const struct ipt_route_target_info *route_info,
9885 +                             struct sk_buff *skb) 
9886 +{
9887 +       struct net_device *dev_in = NULL;
9888 +
9889 +       /* Getting the current interface index. */
9890 +       if (!(dev_in = dev_get_by_name(route_info->iif))) {
9891 +               if (net_ratelimit()) 
9892 +                       DEBUGP("ipt_ROUTE: iif interface %s not found\n", route_info->iif);
9893 +               return NF_DROP;
9894 +       }
9895 +
9896 +       skb->dev = dev_in;
9897 +       dst_release(skb->dst);
9898 +       skb->dst = NULL;
9899 +
9900 +       netif_rx(skb);
9901 +       dev_put(dev_in);
9902 +       return NF_STOLEN;
9903 +}
9904 +
9905 +
9906 +static unsigned int route_gw(const struct ipt_route_target_info *route_info,
9907 +                            struct sk_buff *skb) 
9908 +{
9909 +       if (route(skb, 0, route_info)!=1)
9910 +               return NF_DROP;
9911 +
9912 +       if (route_info->flags & IPT_ROUTE_CONTINUE)
9913 +               return IPT_CONTINUE;
9914 +
9915 +       ip_direct_send(skb);
9916 +       return NF_STOLEN;
9917 +}
9918 +
9919 +
9920 +static unsigned int ipt_route_target(struct sk_buff **pskb,
9921 +                                    const struct net_device *in,
9922 +                                    const struct net_device *out,
9923 +                                    unsigned int hooknum,
9924 +                                    const void *targinfo,
9925 +                                    void *userinfo)
9926 +{
9927 +       const struct ipt_route_target_info *route_info = targinfo;
9928 +       struct sk_buff *skb = *pskb;
9929 +
9930 +       /* If we are at PREROUTING or INPUT hook
9931 +        * the TTL isn't decreased by the IP stack
9932 +        */
9933 +       if (hooknum == NF_IP_PRE_ROUTING ||
9934 +           hooknum == NF_IP_LOCAL_IN) {
9935 +
9936 +               struct iphdr *iph = skb->nh.iph;
9937 +
9938 +               if (iph->ttl <= 1) {
9939 +                       struct rtable *rt;
9940 +                       struct flowi fl = {
9941 +                               .oif = 0,
9942 +                               .nl_u = {
9943 +                                       .ip4_u = {
9944 +                                               .daddr = iph->daddr,
9945 +                                               .saddr = iph->saddr,
9946 +                                               .tos = RT_TOS(iph->tos),
9947 +                                               .scope = ((iph->tos & RTO_ONLINK) ?
9948 +                                                         RT_SCOPE_LINK :
9949 +                                                         RT_SCOPE_UNIVERSE)
9950 +                                       }
9951 +                               } 
9952 +                       };
9953 +
9954 +                       if (ip_route_output_key(&rt, &fl)) {
9955 +                               return NF_DROP;
9956 +                       }
9957 +
9958 +                       if (skb->dev == rt->u.dst.dev) {
9959 +                               /* Drop old route. */
9960 +                               dst_release(skb->dst);
9961 +                               skb->dst = &rt->u.dst;
9962 +
9963 +                               /* this will traverse normal stack, and 
9964 +                                * thus call conntrack on the icmp packet */
9965 +                               icmp_send(skb, ICMP_TIME_EXCEEDED, 
9966 +                                         ICMP_EXC_TTL, 0);
9967 +                       }
9968 +
9969 +                       return NF_DROP;
9970 +               }
9971 +
9972 +               /*
9973 +                * If we are at INPUT the checksum must be recalculated since
9974 +                * the length could change as the result of a defragmentation.
9975 +                */
9976 +               if(hooknum == NF_IP_LOCAL_IN) {
9977 +                       iph->ttl = iph->ttl - 1;
9978 +                       iph->check = 0;
9979 +                       iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);
9980 +               } else {
9981 +                       ip_decrease_ttl(iph);
9982 +               }
9983 +       }
9984 +
9985 +       /* Tell conntrack to forget this packet since it may get confused 
9986 +        * when a packet is leaving with dst address == our address.
9987 +        * Good idea ? Dunno. Need advice.
9988 +        */
9989 +       if (!(route_info->flags & IPT_ROUTE_CONTINUE)) {
9990 +               nf_conntrack_put(skb->nfct);
9991 +               skb->nfct = NULL;
9992 +               skb->nfcache = 0;
9993 +#ifdef CONFIG_NETFILTER_DEBUG
9994 +               skb->nf_debug = 0;
9995 +#endif
9996 +       }
9997 +
9998 +       if (route_info->oif[0] != '\0') 
9999 +               return route_oif(route_info, *pskb);
10000 +       
10001 +       if (route_info->iif[0] != '\0') 
10002 +               return route_iif(route_info, *pskb);
10003 +
10004 +       if (route_info->gw) 
10005 +               return route_gw(route_info, *pskb);
10006 +
10007 +       if (net_ratelimit()) 
10008 +               DEBUGP(KERN_DEBUG "ipt_ROUTE: no parameter !\n");
10009 +
10010 +       return IPT_CONTINUE;
10011 +}
10012 +
10013 +
10014 +static int ipt_route_checkentry(const char *tablename,
10015 +                               const struct ipt_entry *e,
10016 +                               void *targinfo,
10017 +                               unsigned int targinfosize,
10018 +                               unsigned int hook_mask)
10019 +{
10020 +       if (strcmp(tablename, "mangle") != 0) {
10021 +               printk("ipt_ROUTE: bad table `%s', use the `mangle' table.\n",
10022 +                      tablename);
10023 +               return 0;
10024 +       }
10025 +
10026 +       if (hook_mask & ~(  (1 << NF_IP_PRE_ROUTING)
10027 +                           | (1 << NF_IP_LOCAL_IN)
10028 +                           | (1 << NF_IP_FORWARD)
10029 +                           | (1 << NF_IP_LOCAL_OUT)
10030 +                           | (1 << NF_IP_POST_ROUTING))) {
10031 +               printk("ipt_ROUTE: bad hook\n");
10032 +               return 0;
10033 +       }
10034 +
10035 +       if (targinfosize != IPT_ALIGN(sizeof(struct ipt_route_target_info))) {
10036 +               printk(KERN_WARNING "ipt_ROUTE: targinfosize %u != %Zu\n",
10037 +                      targinfosize,
10038 +                      IPT_ALIGN(sizeof(struct ipt_route_target_info)));
10039 +               return 0;
10040 +       }
10041 +
10042 +       return 1;
10043 +}
10044 +
10045 +
10046 +static struct ipt_target ipt_route_reg = { 
10047 +       .name = "ROUTE",
10048 +       .target = ipt_route_target,
10049 +       .checkentry = ipt_route_checkentry,
10050 +       .me = THIS_MODULE,
10051 +};
10052 +
10053 +static int __init init(void)
10054 +{
10055 +       return ipt_register_target(&ipt_route_reg);
10056 +}
10057 +
10058 +
10059 +static void __exit fini(void)
10060 +{
10061 +       ipt_unregister_target(&ipt_route_reg);
10062 +}
10063 +
10064 +module_init(init);
10065 +module_exit(fini);
10066 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_TARPIT.c linux-2.6.6/net/ipv4/netfilter/ipt_TARPIT.c
10067 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_TARPIT.c     1970-01-01 01:00:00.000000000 +0100
10068 +++ linux-2.6.6/net/ipv4/netfilter/ipt_TARPIT.c 2004-05-18 14:28:50.000000000 +0200
10069 @@ -0,0 +1,290 @@
10070 +/* 
10071 + * Kernel module to capture and hold incoming TCP connections using 
10072 + * no local per-connection resources.
10073 + * 
10074 + * Based on ipt_REJECT.c and offering functionality similar to 
10075 + * LaBrea <http://www.hackbusters.net/LaBrea/>.
10076 + * 
10077 + * Copyright (c) 2002 Aaron Hopkins <tools@die.net>
10078 + * 
10079 + * This program is free software; you can redistribute it and/or modify
10080 + * it under the terms of the GNU General Public License as published by
10081 + * the Free Software Foundation; either version 2 of the License, or
10082 + * (at your option) any later version.
10083 + *
10084 + * This program is distributed in the hope that it will be useful,
10085 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10086 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10087 + * GNU General Public License for more details.
10088 + *
10089 + * You should have received a copy of the GNU General Public License
10090 + * along with this program; if not, write to the Free Software
10091 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
10092 + * 
10093 + * Goal:
10094 + * - Allow incoming TCP connections to be established.
10095 + * - Passing data should result in the connection being switched to the 
10096 + *   persist state (0 byte window), in which the remote side stops sending 
10097 + *   data and asks to continue every 60 seconds.
10098 + * - Attempts to shut down the connection should be ignored completely, so 
10099 + *   the remote side ends up having to time it out.
10100 + *
10101 + * This means:
10102 + * - Reply to TCP SYN,!ACK,!RST,!FIN with SYN-ACK, window 5 bytes
10103 + * - Reply to TCP SYN,ACK,!RST,!FIN with RST to prevent spoofing
10104 + * - Reply to TCP !SYN,!RST,!FIN with ACK, window 0 bytes, rate-limited
10105 + */
10106 +
10107 +#include <linux/config.h>
10108 +#include <linux/module.h>
10109 +#include <linux/skbuff.h>
10110 +#include <linux/ip.h>
10111 +#include <net/ip.h>
10112 +#include <net/tcp.h>
10113 +#include <net/icmp.h>
10114 +struct in_device;
10115 +#include <net/route.h>
10116 +#include <linux/random.h>
10117 +#include <linux/netfilter_ipv4/ip_tables.h>
10118 +
10119 +#if 0
10120 +#define DEBUGP printk
10121 +#else
10122 +#define DEBUGP(format, args...)
10123 +#endif
10124 +
10125 +MODULE_LICENSE("GPL");
10126 +MODULE_AUTHOR("Aaron Hopkins <tools@die.net>");
10127 +
10128 +/* Stolen from ip_finish_output2 */
10129 +static int ip_direct_send(struct sk_buff *skb)
10130 +{
10131 +       struct dst_entry *dst = skb->dst;
10132 +       struct hh_cache *hh = dst->hh;
10133 +
10134 +       if (hh) {    
10135 +               read_lock_bh(&hh->hh_lock);
10136 +               memcpy(skb->data - 16, hh->hh_data, 16);
10137 +                read_unlock_bh(&hh->hh_lock);
10138 +                skb_push(skb, hh->hh_len);
10139 +                return hh->hh_output(skb);
10140 +        } else if (dst->neighbour)
10141 +                return dst->neighbour->output(skb);
10142 +
10143 +       if (net_ratelimit())
10144 +               printk(KERN_DEBUG "TARPIT ip_direct_send: no header cache and no neighbor!\n");
10145 +        kfree_skb(skb);
10146 +        return -EINVAL;
10147 +}
10148 +
10149 +
10150 +/* Send reply */
10151 +static void tarpit_tcp(struct sk_buff *oskb,struct rtable *ort,int local)
10152 +{
10153 +       struct sk_buff *nskb;
10154 +       struct rtable *nrt;
10155 +       struct tcphdr *otcph, *ntcph;
10156 +       struct flowi fl = {};
10157 +       unsigned int otcplen;
10158 +       u_int16_t tmp;
10159 +
10160 +       /* A truncated TCP header isn't going to be useful */
10161 +       if (oskb->len < (oskb->nh.iph->ihl*4) + sizeof(struct tcphdr))
10162 +               return;
10163 +
10164 +       otcph = (struct tcphdr *)((u_int32_t*)oskb->nh.iph 
10165 +                                  + oskb->nh.iph->ihl);
10166 +       otcplen = oskb->len - oskb->nh.iph->ihl*4;
10167 +
10168 +       /* No replies for RST or FIN */
10169 +       if (otcph->rst || otcph->fin)
10170 +               return;
10171 +
10172 +       /* No reply to !SYN,!ACK.  Rate-limit replies to !SYN,ACKs */
10173 +       if (!otcph->syn && (!otcph->ack || !xrlim_allow(&ort->u.dst, 1*HZ)))
10174 +               return;
10175 +
10176 +       /* Check checksum. */
10177 +       if (tcp_v4_check(otcph, otcplen, oskb->nh.iph->saddr,
10178 +                        oskb->nh.iph->daddr,
10179 +                        csum_partial((char *)otcph, otcplen, 0)) != 0)
10180 +               return;
10181 +
10182 +       /* Copy skb (even if skb is about to be dropped, we can't just
10183 +           clone it because there may be other things, such as tcpdump,
10184 +           interested in it) */
10185 +       nskb = skb_copy(oskb, GFP_ATOMIC);
10186 +       if (!nskb)
10187 +               return;
10188 +
10189 +       /* This packet will not be the same as the other: clear nf fields */
10190 +       nf_conntrack_put(nskb->nfct);
10191 +       nskb->nfct = NULL;
10192 +       nskb->nfcache = 0;
10193 +#ifdef CONFIG_NETFILTER_DEBUG
10194 +       nskb->nf_debug = 0;
10195 +#endif
10196 +
10197 +       ntcph = (struct tcphdr *)((u_int32_t*)nskb->nh.iph + nskb->nh.iph->ihl);
10198 +
10199 +       /* Truncate to length (no data) */
10200 +       ntcph->doff = sizeof(struct tcphdr)/4;
10201 +       skb_trim(nskb, nskb->nh.iph->ihl*4 + sizeof(struct tcphdr));
10202 +       nskb->nh.iph->tot_len = htons(nskb->len);
10203 +
10204 +       /* Swap source and dest */
10205 +       nskb->nh.iph->daddr = xchg(&nskb->nh.iph->saddr, nskb->nh.iph->daddr);
10206 +       tmp = ntcph->source;
10207 +       ntcph->source = ntcph->dest;
10208 +       ntcph->dest = tmp;
10209 +
10210 +       /* Use supplied sequence number or make a new one */
10211 +       ntcph->seq = otcph->ack ? otcph->ack_seq 
10212 +                     : htonl(secure_tcp_sequence_number(nskb->nh.iph->saddr, 
10213 +                                                       nskb->nh.iph->daddr, 
10214 +                                                       ntcph->source, 
10215 +                                                       ntcph->dest));
10216 +
10217 +       /* Our SYN-ACKs must have a >0 window */
10218 +       ntcph->window = (otcph->syn && !otcph->ack) ? htons(5) : 0;
10219 +
10220 +       ntcph->urg_ptr = 0;
10221 +
10222 +       /* Reset flags */
10223 +       ((u_int8_t *)ntcph)[13] = 0;
10224 +
10225 +       if (otcph->syn && otcph->ack) {
10226 +               ntcph->rst = 1;
10227 +               ntcph->ack_seq = 0;
10228 +       } else {
10229 +               ntcph->syn = otcph->syn;
10230 +               ntcph->ack = 1;
10231 +               ntcph->ack_seq = htonl(ntohl(otcph->seq) + otcph->syn);
10232 +       }
10233 +
10234 +       /* Adjust TCP checksum */
10235 +       ntcph->check = 0;
10236 +       ntcph->check = tcp_v4_check(ntcph, sizeof(struct tcphdr),
10237 +                                  nskb->nh.iph->saddr,
10238 +                                  nskb->nh.iph->daddr,
10239 +                                  csum_partial((char *)ntcph,
10240 +                                               sizeof(struct tcphdr), 0));
10241 +
10242 +       /* Adjust IP TTL */
10243 +       nskb->nh.iph->ttl = sysctl_ip_default_ttl;
10244 +
10245 +       /* Set DF, id = 0 */
10246 +       nskb->nh.iph->frag_off = htons(IP_DF);
10247 +       nskb->nh.iph->id = 0;
10248 +
10249 +       /* Adjust IP checksum */
10250 +       nskb->nh.iph->check = 0;
10251 +       nskb->nh.iph->check = ip_fast_csum((unsigned char *)nskb->nh.iph, 
10252 +                                          nskb->nh.iph->ihl);
10253 +
10254 +       fl.nl_u.ip4_u.daddr = nskb->nh.iph->daddr;
10255 +       fl.nl_u.ip4_u.saddr = local ? nskb->nh.iph->saddr : 0;
10256 +       fl.nl_u.ip4_u.tos = RT_TOS(nskb->nh.iph->tos) | RTO_CONN;
10257 +       fl.oif = 0;
10258 +
10259 +       if (ip_route_output_key(&nrt, &fl))
10260 +               goto free_nskb;
10261 +
10262 +       dst_release(nskb->dst);
10263 +       nskb->dst = &nrt->u.dst;
10264 +
10265 +       /* "Never happens" */
10266 +       if (nskb->len > dst_pmtu(nskb->dst))
10267 +               goto free_nskb;
10268 +
10269 +       ip_direct_send (nskb);
10270 +
10271 +       return;
10272 +
10273 + free_nskb:
10274 +       kfree_skb(nskb);
10275 +}
10276 +
10277 +
10278 +static unsigned int tarpit(struct sk_buff **pskb,
10279 +                          const struct net_device *in,
10280 +                          const struct net_device *out,
10281 +                          unsigned int hooknum,
10282 +                          const void *targinfo,
10283 +                          void *userinfo)
10284 +{
10285 +       struct sk_buff *skb = *pskb;
10286 +       struct rtable *rt = (struct rtable*)skb->dst;
10287 +
10288 +       /* Do we have an input route cache entry? */
10289 +       if (!rt)
10290 +               return NF_DROP;
10291 +
10292 +        /* No replies to physical multicast/broadcast */
10293 +        if (skb->pkt_type != PACKET_HOST && skb->pkt_type != PACKET_OTHERHOST)
10294 +               return NF_DROP;
10295 +
10296 +        /* Now check at the protocol level */
10297 +       if (rt->rt_flags&(RTCF_BROADCAST|RTCF_MULTICAST))
10298 +                return NF_DROP;
10299 +
10300 +       /* Our naive response construction doesn't deal with IP
10301 +           options, and probably shouldn't try. */
10302 +       if (skb->nh.iph->ihl*4 != sizeof(struct iphdr))
10303 +               return NF_DROP;
10304 +
10305 +        /* We aren't interested in fragments */
10306 +       if (skb->nh.iph->frag_off & htons(IP_OFFSET))
10307 +                return NF_DROP;
10308 +
10309 +       tarpit_tcp(skb,rt,hooknum == NF_IP_LOCAL_IN);
10310 +
10311 +       return NF_DROP;
10312 +}
10313 +
10314 +
10315 +static int check(const char *tablename,
10316 +                const struct ipt_entry *e,
10317 +                void *targinfo,
10318 +                unsigned int targinfosize,
10319 +                unsigned int hook_mask)
10320 +{
10321 +       /* Only allow these for input/forward packet filtering. */
10322 +       if (strcmp(tablename, "filter") != 0) {
10323 +               DEBUGP("TARPIT: bad table %s'.\n", tablename);
10324 +               return 0;
10325 +       }
10326 +       if ((hook_mask & ~((1 << NF_IP_LOCAL_IN) 
10327 +                           | (1 << NF_IP_FORWARD))) != 0) {
10328 +               DEBUGP("TARPIT: bad hook mask %X\n", hook_mask);
10329 +               return 0;
10330 +       }
10331 +
10332 +       /* Must specify that it's a TCP packet */
10333 +       if (e->ip.proto != IPPROTO_TCP || (e->ip.invflags & IPT_INV_PROTO)) {
10334 +               DEBUGP("TARPIT: not valid for non-tcp\n");
10335 +               return 0;
10336 +       }
10337 +
10338 +       return 1;
10339 +}
10340 +
10341 +static struct ipt_target ipt_tarpit_reg = { 
10342 +       .name = "TARPIT",
10343 +       .target = tarpit,
10344 +       .checkentry = check,
10345 +       .me = THIS_MODULE
10346 +};
10347 +
10348 +static int __init init(void)
10349 +{
10350 +       return ipt_register_target(&ipt_tarpit_reg);
10351 +}
10352 +
10353 +static void __exit fini(void)
10354 +{
10355 +       ipt_unregister_target(&ipt_tarpit_reg);
10356 +}
10357 +
10358 +module_init(init);
10359 +module_exit(fini);
10360 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_TCPLAG.c linux-2.6.6/net/ipv4/netfilter/ipt_TCPLAG.c
10361 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_TCPLAG.c     1970-01-01 01:00:00.000000000 +0100
10362 +++ linux-2.6.6/net/ipv4/netfilter/ipt_TCPLAG.c 2004-05-18 14:28:50.000000000 +0200
10363 @@ -0,0 +1,697 @@
10364 +/* ipt_TCPLAG.c -- kernel module to implement TCPLAG target into netfilter
10365 + * Copyright (C) 2002 Telford Tendys <telford@triode.net.au>
10366 + *
10367 + * This program is free software; you can redistribute it and/or modify
10368 + * it under the terms of the GNU General Public License as published by
10369 + * the Free Software Foundation; either version 2 of the License, or
10370 + * (at your option) any later version.
10371 + *
10372 + * This program is distributed in the hope that it will be useful,
10373 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10374 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10375 + * GNU General Public License for more details.
10376 + *
10377 + * You should have received a copy of the GNU General Public License
10378 + * along with this program; if not, write to the Free Software
10379 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
10380 + */
10381 +
10382 +/*
10383 + * This collects packets and attempts to make them into pairs
10384 + * based on its own knowledge of how typical network conversations
10385 + * operate. Once it has a pair, it logs the time between them.
10386 + */
10387 +#include <linux/module.h>
10388 +#include <linux/skbuff.h>
10389 +#include <linux/ip.h>
10390 +#include <linux/spinlock.h>
10391 +#include <net/icmp.h>
10392 +#include <net/udp.h>
10393 +#include <net/tcp.h>
10394 +#include <linux/netfilter_ipv4/ip_tables.h>
10395 +
10396 +#include <net/route.h>
10397 +#include <linux/netfilter_ipv4/ipt_TCPLAG.h>
10398 +
10399 +#if 0
10400 +#define DEBUGP printk
10401 +#else
10402 +#define DEBUGP(format, args...)
10403 +#endif
10404 +
10405 +/*
10406 + * We need one spinlock for the hash table.
10407 + */
10408 +static spinlock_t hash_lock = SPIN_LOCK_UNLOCKED;
10409 +
10410 +typedef struct timeval timeval_T;
10411 +
10412 +/*
10413 + * Linked lists of events in the connection,
10414 + * these store the SEQ numbers and the newest is always
10415 + * at the start of the linked list, then they get older
10416 + * down to the end of the linked list (this is not perfect
10417 + * if packets get out of order but we don't worry about fine
10418 + * details like that).
10419 + *
10420 + * Matching any event wipes out that event and also all other
10421 + * events down the chain (i.e. all older events).
10422 + * This keeps the linked list as short as possible.
10423 + */
10424 +typedef struct tcplag_event_S
10425 +{
10426 +       struct tcplag_event_S *next;
10427 +       u16 source_port;
10428 +       u16 dest_port;
10429 +       u32 expected_ACK;
10430 +       struct timeval stamp;
10431 +} tcplag_event_T;
10432 +
10433 +/*
10434 + * This stores the connection statistics
10435 + * We define connections more loosely than TCP/IP does,
10436 + * because we only consider the two hosts, not the ports
10437 + * Also, we list the host-pairs in low,high order which
10438 + * means that we don't care who originated the connection.
10439 + */
10440 +typedef struct tcplag_hash_S
10441 +{
10442 +       u32 low_ip;
10443 +       u32 high_ip;
10444 +       struct timeval lag_l_SEQ_h_ACK; /* l sends some data and h acknowledges that (sum of lag times) */
10445 +       struct timeval lag_h_SEQ_l_ACK; /* h sends some data and l acknowledges that (sum of lag times) */
10446 +       tcplag_event_T *h_ACK_list;     /* Try to match ACK packets coming from h in this list */
10447 +       tcplag_event_T *l_ACK_list;     /* Try to match ACK packets coming from l in this list */
10448 +       time_t stamp;                   /* When this bucket got added to the table */
10449 +       u16 count_l_SEQ_h_ACK;          /* Increment for each event */
10450 +       u16 count_h_SEQ_l_ACK;          /* Increment for each event */
10451 +} tcplag_hash_T;
10452 +
10453 +static tcplag_hash_T **hashtab = 0;
10454 +static u32 hashsize = 0;
10455 +static u16 max_seconds = 30; /* Empty a hash bucket after this time */
10456 +static u32 reaper_ix = 0;
10457 +
10458 +static void divide_down( timeval_T *T, int c )
10459 +{
10460 +       int remainder;
10461 +
10462 +       T->tv_usec /= c;
10463 +       remainder = T->tv_sec % c; /* Only works properly with positive numbers */
10464 +       remainder *= 1000000;
10465 +       T->tv_usec == remainder;
10466 +       T->tv_sec /= c;
10467 +}
10468 +
10469 +int diff_timeval( timeval_T *tv1, timeval_T *tv2 )
10470 +{
10471 +       register long x;
10472 +
10473 +       x = tv1->tv_sec - tv2->tv_sec;
10474 +       if( x ) return( x );
10475 +       x = tv1->tv_usec - tv2->tv_usec;
10476 +       return( x );
10477 +}
10478 +
10479 +void sprint_timeval( char *buf, timeval_T *tv )
10480 +{
10481 +       if( tv->tv_sec )
10482 +               sprintf( buf, "%lu%06lu", tv->tv_sec, tv->tv_usec );
10483 +       else
10484 +               sprintf( buf, "%lu", tv->tv_usec );
10485 +}
10486 +
10487 +/*
10488 + * This generates the log messages through printk()
10489 + *
10490 + * There is really no particular interest in the port numbers at this stage,
10491 + * they are only useful for matching up the request with the reply.
10492 + * The IP numbers are useful because some sites may be slower than others
10493 + * or may travel different routes, etc (OK, in theory changing the port number
10494 + * could also change the route but I don't like that sort of theory).
10495 + *
10496 + * The tags are:
10497 + *
10498 + * LIP=          The IP number of the side with the lowest lag
10499 + * RIP=          The IP number of the side with the highest lag
10500 + * LLAG=         The average time (in us) between RIP->LIP SEQ and LIP->RIP ACK
10501 + * RLAG=         The average time (in us) between LIP->RIP SEQ and RIP->LIP ACK
10502 + */
10503 +static void output( tcplag_hash_T *H, int level, const char *prefix )
10504 +{
10505 +       struct timeval ltm, rtm;
10506 +       u32 local_ip, remote_ip;
10507 +       char r_buf[ 20 ], l_buf[ 20 ];
10508 +/*
10509 + * We can't make sense of a connection that only passes data one way,
10510 + * In principle, at least the SYN and FIN should go both ways so we
10511 + * should get a few hits for every connection.
10512 + */
10513 +       if( 0 == H->count_l_SEQ_h_ACK || 0 == H->count_h_SEQ_l_ACK ) return;
10514 +/*
10515 + * Calculate average times by dividing down
10516 + */
10517 +       divide_down( &H->lag_l_SEQ_h_ACK, H->count_l_SEQ_h_ACK );
10518 +       divide_down( &H->lag_h_SEQ_l_ACK, H->count_h_SEQ_l_ACK );
10519 +/*
10520 + * Sort these two by the lag so the the local is always the short lag
10521 + */
10522 +       if( diff_timeval( &H->lag_l_SEQ_h_ACK, &H->lag_h_SEQ_l_ACK ) > 0 )
10523 +       {
10524 +               local_ip    = H->low_ip;
10525 +               remote_ip   = H->high_ip;
10526 +               rtm.tv_sec  = H->lag_l_SEQ_h_ACK.tv_sec;
10527 +               rtm.tv_usec = H->lag_l_SEQ_h_ACK.tv_usec;
10528 +               ltm.tv_sec  = H->lag_h_SEQ_l_ACK.tv_sec;
10529 +               ltm.tv_usec = H->lag_h_SEQ_l_ACK.tv_usec;
10530 +       }
10531 +       else
10532 +       {
10533 +               local_ip    = H->high_ip;
10534 +               remote_ip   = H->low_ip;
10535 +               ltm.tv_sec  = H->lag_l_SEQ_h_ACK.tv_sec;
10536 +               ltm.tv_usec = H->lag_l_SEQ_h_ACK.tv_usec;
10537 +               rtm.tv_sec  = H->lag_h_SEQ_l_ACK.tv_sec;
10538 +               rtm.tv_usec = H->lag_h_SEQ_l_ACK.tv_usec;
10539 +       }
10540 +/*
10541 + * Don't use a spinlock on the output,
10542 + * it is not guaranteed safe because some OTHER printk could
10543 + * split our log message so we want only one single printk.
10544 + *
10545 + * We use sprintf() to partially pre-digest the output
10546 + *
10547 + * Actually, neither this not the main netfilter LOG target is
10548 + * really safe from printk() overlap, basically syslog cannot
10549 + * be regarded as a guaranteed data output channel. It is good
10550 + * enough for most purposes.
10551 + */
10552 +       sprint_timeval( l_buf, &ltm );
10553 +       sprint_timeval( r_buf, &rtm );
10554 +       printk( "<%d>%sLIP=%u.%u.%u.%u RIP=%u.%u.%u.%u LLAG=%s RLAG=%s\n",
10555 +                       level & 7, prefix,
10556 +                       NIPQUAD( local_ip ), NIPQUAD( remote_ip ),
10557 +                       l_buf, r_buf );
10558 +}
10559 +
10560 +/*
10561 + * The reaper rolls through the hash table looking for old.
10562 + * Log entries are only generated at the reaping time
10563 + * (which means all log entries are out-of-date)
10564 + */
10565 +static void reaper( time_t now, int level, const char *prefix )
10566 +{
10567 +       int i;
10568 +
10569 +       now -= max_seconds;
10570 +       if( !hashsize ) return;
10571 +       if( !hashtab ) return;
10572 +       for( i = 0; i < 10; i++ )
10573 +       {
10574 +               if( ++reaper_ix >= hashsize ) reaper_ix = 0; 
10575 +
10576 +//             DEBUGP( KERN_WARNING "reaper checking %u\n", reaper_ix );
10577 +
10578 +               if( hashtab[ reaper_ix ])
10579 +               {
10580 +                       tcplag_hash_T *found = 0;
10581 +
10582 +                       spin_lock_bh( &hash_lock );
10583 +                       if( hashtab[ reaper_ix ])
10584 +                       {
10585 +                               if( now > hashtab[ reaper_ix ]->stamp )
10586 +                               {
10587 +                                       DEBUGP( KERN_WARNING "reaper found expired entry\n" );
10588 +                                       found = hashtab[ reaper_ix ];
10589 +                                       hashtab[ reaper_ix ] = 0;
10590 +                               }
10591 +                       }
10592 +                       spin_unlock_bh( &hash_lock );
10593 +
10594 +                       if( found )
10595 +                       {
10596 +                               output( found, level, prefix );
10597 +                               kfree( found );
10598 +                       }
10599 +               }
10600 +       }
10601 +}
10602 +
10603 +/*
10604 + * Convert the connection characteristics into a number
10605 + * (not including the timestamp) FIXME: this is a sucky hash function
10606 + */
10607 +static u32 make_hash( tcplag_hash_T *connection )
10608 +{
10609 +       register u32 r;
10610 +
10611 +       r = connection->low_ip;
10612 +       r += connection->high_ip;
10613 +       return( r );
10614 +}
10615 +
10616 +static int compare_connections( tcplag_hash_T *con1, tcplag_hash_T *con2 )
10617 +{
10618 +       int x;
10619 +
10620 +       x = con1->low_ip - con2->low_ip; if( x ) return( x );
10621 +       x = con1->high_ip - con2->high_ip;
10622 +       return( x );
10623 +}
10624 +
10625 +static int compare_events( tcplag_event_T *ev1, tcplag_event_T *ev2 )
10626 +{
10627 +       int x;
10628 +
10629 +       DEBUGP( "Comparing sequence %u to %u\n", ev1->expected_ACK, ev2->expected_ACK );
10630 +       x = ev1->expected_ACK - ev2->expected_ACK;
10631 +       if( x ) return( x );
10632 +       DEBUGP( "Comparing source port %u to %u\n", ev1->source_port, ev2->source_port );
10633 +       x = ev1->source_port - ev2->source_port;
10634 +       if( x ) return( x );
10635 +       DEBUGP( "Comparing destination port %u to %u\n", ev1->dest_port, ev2->dest_port );
10636 +       x = ev1->dest_port - ev2->dest_port;
10637 +       return( x );
10638 +}
10639 +
10640 +/*
10641 + * Go to the hash table and either find an existing connection that
10642 + * matches correctly or inject a new connection into the table.
10643 + * Once the connection is OK, chain the event onto the linked list.
10644 + */
10645 +static void hash_insert( tcplag_hash_T *connection, tcplag_event_T *event, int direction )
10646 +{
10647 +       u32 h, i;
10648 +
10649 +       if( !event ) return; /* Just to be safe */
10650 +       if( !hashsize ) return;
10651 +       if( !hashtab ) return;
10652 +
10653 +       h = make_hash( connection );
10654 +       h %= hashsize;
10655 +
10656 +       DEBUGP( KERN_WARNING "hash_insert( %u )\n", h );
10657 +
10658 +       spin_lock_bh( &hash_lock );
10659 +       for( i = 0; i < hashsize; i++, ({ if( ++h >= hashsize ) { h = 0; }}))
10660 +       {
10661 +               tcplag_hash_T *co_new = 0;
10662 +/*
10663 + * Consider existing entry
10664 + */
10665 +               if( hashtab[ h ])
10666 +               {
10667 +                       if( compare_connections( hashtab[ h ], connection )) continue;
10668 +                       co_new = hashtab[ h ];
10669 +                       DEBUGP( KERN_WARNING "Existing connection at %u\n", h );
10670 +                       goto add_link;
10671 +               }
10672 +/*
10673 + * Use empty slot for new entry
10674 + */
10675 +               if( !hashtab[ h ])
10676 +               {
10677 +                       co_new = kmalloc( sizeof( tcplag_hash_T ), GFP_ATOMIC );
10678 +                       memset( co_new, 0, sizeof( tcplag_hash_T ));
10679 +                       co_new->low_ip = connection->low_ip;
10680 +                       co_new->high_ip = connection->high_ip;
10681 +                       co_new->stamp = event->stamp.tv_sec;
10682 +                       hashtab[ h ] = co_new;
10683 +                       DEBUGP( KERN_WARNING "Added connection to table at %u\n", h );
10684 + add_link:
10685 +                       {
10686 +                               tcplag_event_T *ev_new;
10687 +
10688 +                               ev_new = kmalloc( sizeof( tcplag_event_T ), GFP_ATOMIC );
10689 +                               memcpy( ev_new, event, sizeof( tcplag_event_T ));
10690 +                               if( direction )
10691 +                               {
10692 +                                       ev_new->next = co_new->h_ACK_list;
10693 +                                       co_new->h_ACK_list = ev_new;
10694 +                                       DEBUGP( KERN_WARNING "Connection at %u, direction is h_ACK_list\n", h );
10695 +                               }
10696 +                               else
10697 +                               {
10698 +                                       ev_new->next = co_new->l_ACK_list;
10699 +                                       co_new->l_ACK_list = ev_new;
10700 +                                       DEBUGP( KERN_WARNING "Connection at %u, direction is l_ACK_list\n", h );
10701 +                               }
10702 +                       }
10703 +                       goto done;
10704 +               }
10705 +       }
10706 + done:
10707 +       spin_unlock_bh( &hash_lock );
10708 +}
10709 +
10710 +/*
10711 + * Search the hash table for a matching connection,
10712 + * if we can't find one of those then we are stuffed.
10713 + *
10714 + * Once a connection has been found, scan along the list for
10715 + * a matching SEQ number and if that is found then calculate
10716 + * the lag, update the counters and cut the chain at the
10717 + * point where the matching SEQ is found.
10718 + */
10719 +static int request_complete( tcplag_hash_T *connection, tcplag_event_T *event, int direction )
10720 +{
10721 +       u32 h, i;
10722 +
10723 +       if( !event ) return( 0 );
10724 +       if( !hashsize ) return( 0 );
10725 +       if( !hashtab ) return( 0 );
10726 +       h = make_hash( connection );
10727 +       h %= hashsize;
10728 +
10729 +       DEBUGP( KERN_WARNING "request_complete( %u )\n", h );
10730 +
10731 +       for( i = 0; i < hashsize; i++ )
10732 +       {
10733 +               tcplag_hash_T *found = 0;
10734 +
10735 +               if( !hashtab[ h ]) return( 0 );
10736 +
10737 +               spin_lock_bh( &hash_lock );
10738 +               if( hashtab[ h ])
10739 +               {
10740 +                       if( !compare_connections( hashtab[ h ], connection ))
10741 +                       {
10742 +                               tcplag_event_T *ev, **evroot;
10743 +                               timeval_T *tv;
10744 +                               u16 *cn;
10745 +
10746 +                               found = hashtab[ h ];
10747 +                               if( direction )
10748 +                               {
10749 +                                       evroot = &found->h_ACK_list;
10750 +                                       tv = &found->lag_l_SEQ_h_ACK;
10751 +                                       cn = &found->count_l_SEQ_h_ACK;
10752 +                                       DEBUGP( KERN_WARNING "Connection at %u, direction is h_ACK_list\n", h );
10753 +                               }
10754 +                               else
10755 +                               {
10756 +                                       evroot = &found->l_ACK_list;
10757 +                                       tv = &found->lag_h_SEQ_l_ACK;
10758 +                                       cn = &found->count_h_SEQ_l_ACK;
10759 +                                       DEBUGP( KERN_WARNING "Connection at %u, direction is l_ACK_list\n", h );
10760 +                               }
10761 +                               for( ev = *evroot; ev; ev = ev->next )
10762 +                               {
10763 +                                       if( !compare_events( ev, event ))
10764 +                                       {
10765 +/*
10766 + * Calculate the lag (in two parts) and add that to the collection
10767 + */
10768 +                                               event->stamp.tv_sec -= ev->stamp.tv_sec;
10769 +                                               event->stamp.tv_usec -= ev->stamp.tv_usec;
10770 +                                               if( event->stamp.tv_usec < 0 )
10771 +                                               {
10772 +                                                       event->stamp.tv_usec += 1000000;
10773 +                                                       event->stamp.tv_sec++;
10774 +                                               }
10775 +                                               if( event->stamp.tv_sec < 0 )
10776 +                                               {
10777 +                                                       DEBUGP( KERN_WARNING "Negative lag detected\n" );
10778 +                                               }
10779 +                                               else
10780 +                                               {
10781 +                                                       tv->tv_sec += event->stamp.tv_sec;
10782 +                                                       tv->tv_usec += event->stamp.tv_usec;
10783 +                                                       ++*cn;
10784 +                                                       DEBUGP( KERN_WARNING "Found a match, added %lu.%06lu"
10785 +                                                                       " (accumulator is up to %lu.%06lu, %u events)\n",
10786 +                                                                       event->stamp.tv_sec,
10787 +                                                                       event->stamp.tv_usec,
10788 +                                                                       tv->tv_sec, tv->tv_usec, *cn );
10789 +                                               }
10790 +/*
10791 + * Truncate the linked list.
10792 + *
10793 + * Visit each event in the list and return the memory to the pool.
10794 + *
10795 + * If a host is making multiple connections to the same remote host
10796 + * then this truncation will result in some requests not being
10797 + * monitored. Statistically we will still get some reasonable number
10798 + * of measurements and multiple simultaneous connections between host
10799 + * pairs don't happen all that often.
10800 + */
10801 +                                               *evroot = 0;
10802 +                                               while( ev )
10803 +                                               {
10804 +                                                       tcplag_event_T *ev_next = ev->next;
10805 +                                                       DEBUGP( KERN_WARNING "Shitcan %u\n", ev->expected_ACK );
10806 +                                                       kfree( ev );
10807 +                                                       ev = ev_next;
10808 +                                               }
10809 +/*
10810 + * TODO: overflow limit for *cn, force premature output() if necessary
10811 + * (and drop this connection from the hash table)
10812 + */
10813 +                                               break;
10814 +                                       }
10815 +                               }
10816 +                               goto done;
10817 +                       }
10818 +               }
10819 + done:
10820 +               spin_unlock_bh( &hash_lock );
10821 +
10822 +               if( found ) return( 1 );
10823 +               if( ++h >= hashsize ) h = 0;
10824 +       }       
10825 +       return( 0 );
10826 +}
10827 +
10828 +/*
10829 + * Here is our target data:
10830 + *
10831 + * pskb      --  The packet itself (see linux/skbuff.h for breakdown)
10832 + *
10833 + * hooknum   --
10834 + *
10835 + * in        --  The device that this packet came in on
10836 + *               (depending on the chain this may or may not exist)
10837 + *
10838 + * out       --  The device that this packet is just about to go
10839 + *               out onto (again existance depends on the chain)
10840 + *
10841 + * targinfo  --  Our private data (handed through from iptables command util)
10842 + *
10843 + * userinfo  --  Some more data
10844 + *
10845 + */
10846 +
10847 +static unsigned int target( struct sk_buff **pskb,
10848 +                                                       unsigned int hooknum,
10849 +                                                       const struct net_device *in,
10850 +                                                       const struct net_device *out,
10851 +                                                       const void *targinfo,
10852 +                                                       void *userinfo )
10853 +{
10854 +       struct iphdr *iph = ( *pskb )->nh.iph;
10855 +       const struct ipt_tcplag *el = targinfo;
10856 +       tcplag_hash_T connection;
10857 +       tcplag_event_T event;
10858 +       int direction;
10859 +/*
10860 + * We know we are dealing with IP here
10861 + * Fill in all the obvious fields
10862 + */
10863 +       if( iph->saddr > iph->daddr )
10864 +       {
10865 +               direction = 0;
10866 +               connection.high_ip = iph->saddr;
10867 +               connection.low_ip = iph->daddr;
10868 +       }
10869 +       else
10870 +       {
10871 +               direction = 1;
10872 +               connection.low_ip = iph->saddr;
10873 +               connection.high_ip = iph->daddr;
10874 +       }
10875 +       do_gettimeofday( &event.stamp );
10876 +/*
10877 + * Do a bit of cleaning
10878 + */
10879 +       reaper( event.stamp.tv_sec, el->level, el->prefix );
10880 +
10881 +       DEBUGP( KERN_WARNING "got packet %lu %lu %s %s\n",
10882 +                       event.stamp.tv_sec,
10883 +                       event.stamp.tv_usec,
10884 +                       in ? in->name : "none", out ? out->name : "none" );
10885 +/*
10886 + * Now start looking at the details
10887 + *
10888 + * First step is to identify this packet to see if it is 
10889 + * the sort of packet that we are interested in.
10890 + * Don't hold any locks while we are doing this because often
10891 + * we will just let the packet go without any further consideration.
10892 + */
10893 +       switch( iph->protocol )
10894 +       {
10895 +               case IPPROTO_TCP:
10896 +               {
10897 +                       struct tcphdr *tcp;
10898 +
10899 +                       if( ntohs( iph->frag_off ) & IP_OFFSET )
10900 +                       {
10901 +                               DEBUGP( KERN_WARNING "ignoring fragment\n" );
10902 +                               break;
10903 +                       }
10904 +                       tcp = (struct tcphdr *)((u32 *)iph + iph->ihl );
10905 +                       event.source_port = ntohs( tcp->source );
10906 +                       event.dest_port = ntohs( tcp->dest );
10907 +/*
10908 + * Every packet should have a valid SEQ number so use this to
10909 + * generate an ACK number. This works along the formula:
10910 + * -- Start with the SEQ number
10911 + * -- For SYN or FIN add 1 to that number
10912 + * -- For data packet, add the data length to that number
10913 + */
10914 +
10915 +/*
10916 + * Data length requires a bit of fiddling around
10917 + */
10918 +                       {
10919 +                               unsigned int data_len;
10920 +                               if( tcp->syn || tcp->fin )
10921 +                               {
10922 +                                       data_len = 1; /* Not real data, the SEQ clicks forward by 1 */
10923 +                               }
10924 +                               else
10925 +                               {
10926 +                                       data_len = ntohs( iph->tot_len );
10927 +                                       data_len -= 4 * iph->ihl;  /* Subtract away IP header & options */
10928 +                                       data_len -= 4 * tcp->doff; /* Subtract away TCP header & options */
10929 +                               }
10930 +                               
10931 +                               DEBUGP( KERN_WARNING "Data length calculated at %u\n", data_len );
10932 +
10933 +                               if( data_len ) /* Only track events that demand an ACK */
10934 +                               {
10935 +                                       event.expected_ACK = ntohl( tcp->seq ) + data_len;
10936 +                                       hash_insert( &connection, &event, direction );
10937 +                               }
10938 +                               else
10939 +                               {
10940 +                                       DEBUGP( "Don't bother to insert this, ACK not required\n" );
10941 +                               }
10942 +                       }
10943 +
10944 +                       if( tcp->ack )
10945 +                       {
10946 +/*
10947 + * Now we consider the matching of an existing event.
10948 + * Reverse the port numbers and change the ACK number to the actual ACK number
10949 + * Note that the direction is reversed because the reply will be going
10950 + * the opposite way to the request.
10951 + */
10952 +                               event.expected_ACK = ntohl( tcp->ack_seq );
10953 +                               event.dest_port = ntohs( tcp->source );
10954 +                               event.source_port = ntohs( tcp->dest );
10955 +                               request_complete( &connection, &event, !direction );
10956 +                       }
10957 +                       else
10958 +                       {
10959 +                               DEBUGP( "Don't bother to check this, ACK not valid\n" );
10960 +                       }
10961 +               }
10962 +       }
10963 +       return( IPT_CONTINUE );
10964 +}
10965 +
10966 +/*
10967 + * return( 0 ) if there is a problem with this entry (i.e. kick it out of the kernel)
10968 + * return( 1 ) if the entry is suitable
10969 + *
10970 + * tablename     --  
10971 + *
10972 + * e             --  
10973 + *
10974 + * targinfo      --  Our private data block (handed to us from iptables plug-in)
10975 + *
10976 + * targinfosize  --  The size of our private data block
10977 + *
10978 + * hook_mask     --  
10979 + *
10980 + *
10981 + * Not much can go wrong for us, any illegal flags are harmlessly ignored,
10982 + * all possible flag combos make sense. All we check for is correct data size.
10983 + */
10984 +static int checkentry( const char *tablename,
10985 +                                          const struct ipt_entry *e,
10986 +                                          void *targinfo,
10987 +                                          unsigned int targinfosize,
10988 +                                          unsigned int hook_mask )
10989 +{
10990 +       const struct ipt_tcplag *el = targinfo;
10991 +
10992 +       if( targinfosize != IPT_ALIGN( sizeof( struct ipt_tcplag )))
10993 +       {
10994 +               DEBUGP( "TCPLAG: targinfosize %u != %u\n", targinfosize,
10995 +                               IPT_ALIGN( sizeof( struct ipt_tcplag )));
10996 +               return( 0 );
10997 +       }
10998 +       if( el->prefix[ 14 ]) return( 0 ); /* Be sure to have terminated string */
10999 +       return( 1 );
11000 +}
11001 +
11002 +static struct ipt_target reg =
11003 +{
11004 +       { 0, 0 },
11005 +       "TCPLAG",
11006 +       &target,
11007 +       &checkentry,
11008 +       0,
11009 +    THIS_MODULE
11010 +};
11011 +
11012 +static int __init init( void )
11013 +{
11014 +       if( ipt_register_target( &reg )) return( -EINVAL );
11015 +       hashsize = 123; /* should be configurable */
11016 +       hashtab = kmalloc( sizeof( void * ) * hashsize, GFP_ATOMIC );
11017 +       memset( hashtab, 0, sizeof( void * ) * hashsize );
11018 +       return( 0 );
11019 +}
11020 +
11021 +/*
11022 + * This should not need locks (in theory)
11023 + * because it can only get punted after it is no longer
11024 + * chained into any of the netfilter lists.
11025 + */
11026 +static void __exit fini( void )
11027 +{
11028 +       int i;
11029 +
11030 +       ipt_unregister_target( &reg );
11031 +/*
11032 + * Put back kernel memory
11033 + */
11034 +       for( i = 0; i < hashsize; i++ )
11035 +       {
11036 +               tcplag_hash_T *p;
11037 +
11038 +               if(( p = hashtab[ i ]))
11039 +               {
11040 +                       tcplag_event_T *ev, *evn;
11041 +
11042 +                       hashtab[ i ] = 0;
11043 +                       for( ev = p->h_ACK_list; ev; ev = evn )
11044 +                       {
11045 +                               evn = ev->next;
11046 +                               kfree( ev );
11047 +                       }
11048 +                       for( ev = p->l_ACK_list; ev; ev = evn )
11049 +                       {
11050 +                               evn = ev->next;
11051 +                               kfree( ev );
11052 +                       }
11053 +                       kfree( p );
11054 +               }
11055 +       }
11056 +       kfree( hashtab );
11057 +}
11058 +
11059 +module_init(init);
11060 +module_exit(fini);
11061 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_TRACE.c linux-2.6.6/net/ipv4/netfilter/ipt_TRACE.c
11062 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_TRACE.c      1970-01-01 01:00:00.000000000 +0100
11063 +++ linux-2.6.6/net/ipv4/netfilter/ipt_TRACE.c  2004-05-18 14:28:50.000000000 +0200
11064 @@ -0,0 +1,64 @@
11065 +/* This is a module which is used for setting 
11066 + * the NFC_TRACE flag in the nfcache field of an skb. 
11067 + */
11068 +#include <linux/module.h>
11069 +#include <linux/skbuff.h>
11070 +
11071 +#include <linux/netfilter_ipv4/ip_tables.h>
11072 +
11073 +static unsigned int
11074 +target(struct sk_buff **pskb,
11075 +       const struct net_device *in,
11076 +       const struct net_device *out,
11077 +       unsigned int hooknum,
11078 +       const void *targinfo,
11079 +       void *userinfo)
11080 +{
11081 +       (*pskb)->nfcache |= NFC_TRACE;
11082 +       return IPT_CONTINUE;
11083 +}
11084 +
11085 +static int
11086 +checkentry(const char *tablename,
11087 +          const struct ipt_entry *e,
11088 +           void *targinfo,
11089 +           unsigned int targinfosize,
11090 +           unsigned int hook_mask)
11091 +{
11092 +       if (targinfosize != 0) {
11093 +               printk(KERN_WARNING "TRACE: targinfosize %u != 0\n",
11094 +                      targinfosize);
11095 +               return 0;
11096 +       }
11097 +
11098 +       if (strcmp(tablename, "raw") != 0) {
11099 +               printk(KERN_WARNING "TRACE: can only be called from \"raw\" table, not \"%s\"\n", tablename);
11100 +               return 0;
11101 +       }
11102 +
11103 +       return 1;
11104 +}
11105 +
11106 +static struct ipt_target ipt_trace_reg = { 
11107 +       .name = "TRACE", 
11108 +       .target = target, 
11109 +       .checkentry = checkentry, 
11110 +       .me = THIS_MODULE
11111 +};
11112 +
11113 +static int __init init(void)
11114 +{
11115 +       if (ipt_register_target(&ipt_trace_reg))
11116 +               return -EINVAL;
11117 +
11118 +       return 0;
11119 +}
11120 +
11121 +static void __exit fini(void)
11122 +{
11123 +       ipt_unregister_target(&ipt_trace_reg);
11124 +}
11125 +
11126 +module_init(init);
11127 +module_exit(fini);
11128 +MODULE_LICENSE("GPL");
11129 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_TTL.c linux-2.6.6/net/ipv4/netfilter/ipt_TTL.c
11130 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_TTL.c        1970-01-01 01:00:00.000000000 +0100
11131 +++ linux-2.6.6/net/ipv4/netfilter/ipt_TTL.c    2004-05-18 14:28:50.000000000 +0200
11132 @@ -0,0 +1,120 @@
11133 +/* TTL modification target for IP tables
11134 + * (C) 2000 by Harald Welte <laforge@gnumonks.org>
11135 + *
11136 + * Version: $Revision$
11137 + *
11138 + * This software is distributed under the terms of GNU GPL
11139 + */
11140 +
11141 +#include <linux/module.h>
11142 +#include <linux/skbuff.h>
11143 +#include <linux/ip.h>
11144 +#include <net/checksum.h>
11145 +
11146 +#include <linux/netfilter_ipv4/ip_tables.h>
11147 +#include <linux/netfilter_ipv4/ipt_TTL.h>
11148 +
11149 +MODULE_AUTHOR("Harald Welte <laforge@gnumonks.org>");
11150 +MODULE_DESCRIPTION("IP tables TTL modification module");
11151 +MODULE_LICENSE("GPL");
11152 +
11153 +static unsigned int 
11154 +ipt_ttl_target(struct sk_buff **pskb, const struct net_device *in, 
11155 +               const struct net_device *out, unsigned int hooknum, 
11156 +               const void *targinfo, void *userinfo)
11157 +{
11158 +       struct iphdr *iph;
11159 +       const struct ipt_TTL_info *info = targinfo;
11160 +       u_int16_t diffs[2];
11161 +       int new_ttl;
11162 +
11163 +       if (!skb_ip_make_writable(pskb, (*pskb)->len))
11164 +               return NF_DROP;
11165 +
11166 +       iph = (*pskb)->nh.iph;
11167 +                        
11168 +       switch (info->mode) {
11169 +               case IPT_TTL_SET:
11170 +                       new_ttl = info->ttl;
11171 +                       break;
11172 +               case IPT_TTL_INC:
11173 +                       new_ttl = iph->ttl + info->ttl;
11174 +                       if (new_ttl > 255)
11175 +                               new_ttl = 255;
11176 +                       break;
11177 +               case IPT_TTL_DEC:
11178 +                       new_ttl = iph->ttl + info->ttl;
11179 +                       if (new_ttl < 0)
11180 +                               new_ttl = 0;
11181 +                       break;
11182 +               default:
11183 +                       new_ttl = iph->ttl;
11184 +                       break;
11185 +       }
11186 +
11187 +       if (new_ttl != iph->ttl) {
11188 +               diffs[0] = htons(((unsigned)iph->ttl) << 8) ^ 0xFFFF;
11189 +               iph->ttl = new_ttl;
11190 +               diffs[1] = htons(((unsigned)iph->ttl) << 8);
11191 +               iph->check = csum_fold(csum_partial((char *)diffs,
11192 +                                                   sizeof(diffs),
11193 +                                                   iph->check^0xFFFF));
11194 +                                                                                               (*pskb)->nfcache |= NFC_ALTERED;
11195 +       }
11196 +
11197 +       return IPT_CONTINUE;
11198 +}
11199 +
11200 +static int ipt_ttl_checkentry(const char *tablename,
11201 +               const struct ipt_entry *e,
11202 +               void *targinfo,
11203 +               unsigned int targinfosize,
11204 +               unsigned int hook_mask)
11205 +{
11206 +       struct ipt_TTL_info *info = targinfo;
11207 +
11208 +       if (targinfosize != IPT_ALIGN(sizeof(struct ipt_TTL_info))) {
11209 +               printk(KERN_WARNING "TTL: targinfosize %u != %Zu\n",
11210 +                               targinfosize,
11211 +                               IPT_ALIGN(sizeof(struct ipt_TTL_info)));
11212 +               return 0;       
11213 +       }       
11214 +
11215 +       if (strcmp(tablename, "mangle")) {
11216 +               printk(KERN_WARNING "TTL: can only be called from \"mangle\" table, not \"%s\"\n", tablename);
11217 +               return 0;
11218 +       }
11219 +
11220 +       if (info->mode > IPT_TTL_MAXMODE) {
11221 +               printk(KERN_WARNING "TTL: invalid or unknown Mode %u\n", 
11222 +                       info->mode);
11223 +               return 0;
11224 +       }
11225 +
11226 +       if ((info->mode != IPT_TTL_SET) && (info->ttl == 0)) {
11227 +               printk(KERN_WARNING "TTL: increment/decrement doesn't make sense with value 0\n");
11228 +               return 0;
11229 +       }
11230 +       
11231 +       return 1;
11232 +}
11233 +
11234 +static struct ipt_target ipt_TTL = { 
11235 +       .name = "TTL",
11236 +       .target = ipt_ttl_target, 
11237 +       .checkentry = ipt_ttl_checkentry, 
11238 +       .me = THIS_MODULE 
11239 +};
11240 +
11241 +static int __init init(void)
11242 +{
11243 +       return ipt_register_target(&ipt_TTL);
11244 +}
11245 +
11246 +static void __exit fini(void)
11247 +{
11248 +       ipt_unregister_target(&ipt_TTL);
11249 +}
11250 +
11251 +module_init(init);
11252 +module_exit(fini);
11253 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_XOR.c linux-2.6.6/net/ipv4/netfilter/ipt_XOR.c
11254 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_XOR.c        1970-01-01 01:00:00.000000000 +0100
11255 +++ linux-2.6.6/net/ipv4/netfilter/ipt_XOR.c    2004-05-18 14:28:50.000000000 +0200
11256 @@ -0,0 +1,117 @@
11257 +/* XOR target for IP tables
11258 + * (C) 2000 by Tim Vandermeersch <Tim.Vandermeersch@pandora.be>
11259 + * Based on ipt_TTL.c
11260 + *
11261 + * Version 1.0
11262 + *
11263 + * This software is distributed under the terms of GNU GPL
11264 + */
11265 +
11266 +#include <linux/module.h>
11267 +#include <linux/skbuff.h>
11268 +#include <linux/ip.h>
11269 +#include <linux/tcp.h>
11270 +#include <linux/udp.h>
11271 +
11272 +#include <linux/netfilter_ipv4/ip_tables.h>
11273 +#include <linux/netfilter_ipv4/ipt_XOR.h>
11274 +
11275 +MODULE_AUTHOR("Tim Vandermeersch <Tim.Vandermeersch@pandora.be>");
11276 +MODULE_DESCRIPTION("IP tables XOR module");
11277 +MODULE_LICENSE("GPL");
11278 +
11279 +static unsigned int 
11280 +ipt_xor_target(struct sk_buff **pskb, 
11281 +               const struct net_device *in, const struct net_device *out, 
11282 +               unsigned int hooknum, const void *targinfo, void *userinfo)
11283 +{
11284 +       struct ipt_XOR_info *info = (void *) targinfo;
11285 +       struct iphdr *iph;
11286 +       struct tcphdr *tcph;
11287 +       struct udphdr *udph;
11288 +       int i, j, k;
11289 +
11290 +       if (!skb_ip_make_writable(pskb, (*pskb)->len))
11291 +               return NF_DROP;
11292 +
11293 +       iph = (*pskb)->nh.iph;
11294 +  
11295 +       if (iph->protocol == IPPROTO_TCP) {
11296 +               tcph = (struct tcphdr *) ((*pskb)->data + iph->ihl*4);
11297 +               for (i=0, j=0; i<(ntohs(iph->tot_len) - iph->ihl*4 - tcph->doff*4); ) {
11298 +                       for (k=0; k<=info->block_size; k++) {
11299 +                               (char) (*pskb)->data[ iph->ihl*4 + tcph->doff*4 + i ] ^= 
11300 +                                               info->key[j];
11301 +                               i++;
11302 +                       }
11303 +                       j++;
11304 +                       if (info->key[j] == 0x00)
11305 +                               j = 0;
11306 +               }
11307 +       } else if (iph->protocol == IPPROTO_UDP) {
11308 +               udph = (struct udphdr *) ((*pskb)->data + iph->ihl*4);
11309 +               for (i=0, j=0; i<(ntohs(udph->len)-8); ) {
11310 +                       for (k=0; k<=info->block_size; k++) {
11311 +                               (char) (*pskb)->data[ iph->ihl*4 + sizeof(struct udphdr) + i ] ^= 
11312 +                                               info->key[j];
11313 +                               i++;
11314 +                       }
11315 +                       j++;
11316 +                       if (info->key[j] == 0x00)
11317 +                               j = 0;
11318 +               }
11319 +       }
11320 +  
11321 +       return IPT_CONTINUE;
11322 +}
11323 +
11324 +static int ipt_xor_checkentry(const char *tablename, const struct ipt_entry *e,
11325 +               void *targinfo, unsigned int targinfosize, 
11326 +               unsigned int hook_mask)
11327 +{
11328 +       struct ipt_XOR_info *info = targinfo;
11329 +
11330 +       if (targinfosize != IPT_ALIGN(sizeof(struct ipt_XOR_info))) {
11331 +               printk(KERN_WARNING "XOR: targinfosize %u != %Zu\n", 
11332 +                               targinfosize, IPT_ALIGN(sizeof(struct ipt_XOR_info)));
11333 +               return 0;
11334 +       }       
11335 +
11336 +       if (strcmp(tablename, "mangle")) {
11337 +               printk(KERN_WARNING "XOR: can only be called from"
11338 +                               "\"mangle\" table, not \"%s\"\n", tablename);
11339 +               return 0; 
11340 +       }
11341 +
11342 +       if (!strcmp(info->key, "")) {
11343 +               printk(KERN_WARNING "XOR: You must specify a key");
11344 +               return 0;
11345 +       }
11346 +
11347 +       if (info->block_size == 0) {
11348 +               printk(KERN_WARNING "XOR: You must specify a block-size");
11349 +               return 0;
11350 +       }
11351 +
11352 +       return 1;
11353 +}
11354 +
11355 +static struct ipt_target ipt_XOR = { 
11356 +       .name = "XOR",
11357 +       .target = ipt_xor_target, 
11358 +       .checkentry = ipt_xor_checkentry,
11359 +       .me = THIS_MODULE,
11360 +};
11361 +
11362 +static int __init init(void)
11363 +{
11364 +       return ipt_register_target(&ipt_XOR);
11365 +}
11366 +
11367 +static void __exit fini(void)
11368 +{
11369 +       ipt_unregister_target(&ipt_XOR);
11370 +}
11371 +
11372 +module_init(init);
11373 +module_exit(fini);
11374 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_addrtype.c linux-2.6.6/net/ipv4/netfilter/ipt_addrtype.c
11375 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_addrtype.c   1970-01-01 01:00:00.000000000 +0100
11376 +++ linux-2.6.6/net/ipv4/netfilter/ipt_addrtype.c       2004-05-18 14:28:50.000000000 +0200
11377 @@ -0,0 +1,68 @@
11378 +/*
11379 + *  iptables module to match inet_addr_type() of an ip.
11380 + */
11381 +
11382 +#include <linux/module.h>
11383 +#include <linux/skbuff.h>
11384 +#include <linux/netdevice.h>
11385 +#include <net/route.h>
11386 +
11387 +#include <linux/netfilter_ipv4/ipt_addrtype.h>
11388 +#include <linux/netfilter_ipv4/ip_tables.h>
11389 +
11390 +MODULE_LICENSE("GPL");
11391 +
11392 +static inline int match_type(u_int32_t addr, u_int16_t mask)
11393 +{
11394 +       return !!(mask & (1 << inet_addr_type(addr)));
11395 +}
11396 +
11397 +static int match(const struct sk_buff *skb, const struct net_device *in,
11398 +                const struct net_device *out, const void *matchinfo,
11399 +                int offset, int *hotdrop)
11400 +{
11401 +       const struct ipt_addrtype_info *info = matchinfo;
11402 +       const struct iphdr *iph = skb->nh.iph;
11403 +       int ret = 1;
11404 +
11405 +       if (info->source)
11406 +               ret &= match_type(iph->saddr, info->source)^info->invert_source;
11407 +       if (info->dest)
11408 +               ret &= match_type(iph->daddr, info->dest)^info->invert_dest;
11409 +       
11410 +       return ret;
11411 +}
11412 +
11413 +static int checkentry(const char *tablename, const struct ipt_ip *ip,
11414 +                     void *matchinfo, unsigned int matchsize,
11415 +                     unsigned int hook_mask)
11416 +{
11417 +       if (matchsize != IPT_ALIGN(sizeof(struct ipt_addrtype_info))) {
11418 +               printk(KERN_ERR "ipt_addrtype: invalid size (%u != %u)\n.",
11419 +                      matchsize, IPT_ALIGN(sizeof(struct ipt_addrtype_info)));
11420 +               return 0;
11421 +       }
11422 +
11423 +       return 1;
11424 +}
11425 +
11426 +static struct ipt_match addrtype_match = { 
11427 +       .name = "addrtype",
11428 +       .match = match,
11429 +       .checkentry = checkentry,
11430 +       .me = THIS_MODULE
11431 +};
11432 +
11433 +static int __init init(void)
11434 +{
11435 +       return ipt_register_match(&addrtype_match);
11436 +}
11437 +
11438 +static void __exit fini(void)
11439 +{
11440 +       ipt_unregister_match(&addrtype_match);
11441 +
11442 +}
11443 +
11444 +module_init(init);
11445 +module_exit(fini);
11446 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_connlimit.c linux-2.6.6/net/ipv4/netfilter/ipt_connlimit.c
11447 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_connlimit.c  1970-01-01 01:00:00.000000000 +0100
11448 +++ linux-2.6.6/net/ipv4/netfilter/ipt_connlimit.c      2004-05-18 14:28:50.000000000 +0200
11449 @@ -0,0 +1,230 @@
11450 +/*
11451 + * netfilter module to limit the number of parallel tcp
11452 + * connections per IP address.
11453 + *   (c) 2000 Gerd Knorr <kraxel@bytesex.org>
11454 + *   Nov 2002: Martin Bene <martin.bene@icomedias.com>:
11455 + *             only ignore TIME_WAIT or gone connections
11456 + *
11457 + * based on ...
11458 + *
11459 + * Kernel module to match connection tracking information.
11460 + * GPL (C) 1999  Rusty Russell (rusty@rustcorp.com.au).
11461 + */
11462 +#include <linux/module.h>
11463 +#include <linux/skbuff.h>
11464 +#include <linux/list.h>
11465 +#include <linux/netfilter_ipv4/ip_conntrack.h>
11466 +#include <linux/netfilter_ipv4/ip_conntrack_core.h>
11467 +#include <linux/netfilter_ipv4/ip_conntrack_tcp.h>
11468 +#include <linux/netfilter_ipv4/ip_tables.h>
11469 +#include <linux/netfilter_ipv4/ipt_connlimit.h>
11470 +
11471 +#define DEBUG 0
11472 +
11473 +MODULE_LICENSE("GPL");
11474 +
11475 +/* we'll save the tuples of all connections we care about */
11476 +struct ipt_connlimit_conn
11477 +{
11478 +        struct list_head list;
11479 +       struct ip_conntrack_tuple tuple;
11480 +};
11481 +
11482 +struct ipt_connlimit_data {
11483 +       spinlock_t lock;
11484 +       struct list_head iphash[256];
11485 +};
11486 +
11487 +static int ipt_iphash(u_int32_t addr)
11488 +{
11489 +       int hash;
11490 +
11491 +       hash  =  addr        & 0xff;
11492 +       hash ^= (addr >>  8) & 0xff;
11493 +       hash ^= (addr >> 16) & 0xff;
11494 +       hash ^= (addr >> 24) & 0xff;
11495 +       return hash;
11496 +}
11497 +
11498 +static int count_them(struct ipt_connlimit_data *data,
11499 +                     u_int32_t addr, u_int32_t mask,
11500 +                     struct ip_conntrack *ct)
11501 +{
11502 +#if DEBUG
11503 +       const static char *tcp[] = { "none", "established", "syn_sent", "syn_recv",
11504 +                                    "fin_wait", "time_wait", "close", "close_wait",
11505 +                                    "last_ack", "listen" };
11506 +#endif
11507 +       int addit = 1, matches = 0;
11508 +       struct ip_conntrack_tuple tuple;
11509 +       struct ip_conntrack_tuple_hash *found;
11510 +       struct ipt_connlimit_conn *conn;
11511 +       struct list_head *hash,*lh;
11512 +
11513 +       spin_lock(&data->lock);
11514 +       tuple = ct->tuplehash[0].tuple;
11515 +       hash = &data->iphash[ipt_iphash(addr & mask)];
11516 +
11517 +       /* check the saved connections */
11518 +       for (lh = hash->next; lh != hash; lh = lh->next) {
11519 +               conn = list_entry(lh,struct ipt_connlimit_conn,list);
11520 +               found = ip_conntrack_find_get(&conn->tuple,ct);
11521 +               if (0 == memcmp(&conn->tuple,&tuple,sizeof(tuple)) &&
11522 +                   found != NULL &&
11523 +                   found->ctrack->proto.tcp.state != TCP_CONNTRACK_TIME_WAIT) {
11524 +                       /* Just to be sure we have it only once in the list.
11525 +                          We should'nt see tuples twice unless someone hooks this
11526 +                          into a table without "-p tcp --syn" */
11527 +                       addit = 0;
11528 +               }
11529 +#if DEBUG
11530 +               printk("ipt_connlimit [%d]: src=%u.%u.%u.%u:%d dst=%u.%u.%u.%u:%d %s\n",
11531 +                      ipt_iphash(addr & mask),
11532 +                      NIPQUAD(conn->tuple.src.ip), ntohs(conn->tuple.src.u.tcp.port),
11533 +                      NIPQUAD(conn->tuple.dst.ip), ntohs(conn->tuple.dst.u.tcp.port),
11534 +                      (NULL != found) ? tcp[found->ctrack->proto.tcp.state] : "gone");
11535 +#endif
11536 +               if (NULL == found) {
11537 +                       /* this one is gone */
11538 +                       lh = lh->prev;
11539 +                       list_del(lh->next);
11540 +                       kfree(conn);
11541 +                       continue;
11542 +               }
11543 +               if (found->ctrack->proto.tcp.state == TCP_CONNTRACK_TIME_WAIT) {
11544 +                       /* we don't care about connections which are
11545 +                          closed already -> ditch it */
11546 +                       lh = lh->prev;
11547 +                       list_del(lh->next);
11548 +                       kfree(conn);
11549 +                       nf_conntrack_put(&found->ctrack->infos[0]);
11550 +                       continue;
11551 +               }
11552 +               if ((addr & mask) == (conn->tuple.src.ip & mask)) {
11553 +                       /* same source IP address -> be counted! */
11554 +                       matches++;
11555 +               }
11556 +               nf_conntrack_put(&found->ctrack->infos[0]);
11557 +       }
11558 +       if (addit) {
11559 +               /* save the new connection in our list */
11560 +#if DEBUG
11561 +               printk("ipt_connlimit [%d]: src=%u.%u.%u.%u:%d dst=%u.%u.%u.%u:%d new\n",
11562 +                      ipt_iphash(addr & mask),
11563 +                      NIPQUAD(tuple.src.ip), ntohs(tuple.src.u.tcp.port),
11564 +                      NIPQUAD(tuple.dst.ip), ntohs(tuple.dst.u.tcp.port));
11565 +#endif
11566 +               conn = kmalloc(sizeof(*conn),GFP_ATOMIC);
11567 +               if (NULL == conn)
11568 +                       return -1;
11569 +               memset(conn,0,sizeof(*conn));
11570 +               INIT_LIST_HEAD(&conn->list);
11571 +               conn->tuple = tuple;
11572 +               list_add(&conn->list,hash);
11573 +               matches++;
11574 +       }
11575 +       spin_unlock(&data->lock);
11576 +       return matches;
11577 +}
11578 +
11579 +static int
11580 +match(const struct sk_buff *skb,
11581 +      const struct net_device *in,
11582 +      const struct net_device *out,
11583 +      const void *matchinfo,
11584 +      int offset,
11585 +      int *hotdrop)
11586 +{
11587 +       const struct ipt_connlimit_info *info = matchinfo;
11588 +       int connections, match;
11589 +       struct ip_conntrack *ct;
11590 +       enum ip_conntrack_info ctinfo;
11591 +
11592 +       ct = ip_conntrack_get((struct sk_buff *)skb, &ctinfo);
11593 +       if (NULL == ct) {
11594 +               printk("ipt_connlimit: Oops: invalid ct state ?\n");
11595 +               *hotdrop = 1;
11596 +               return 0;
11597 +       }
11598 +       connections = count_them(info->data,skb->nh.iph->saddr,info->mask,ct);
11599 +       if (-1 == connections) {
11600 +               printk("ipt_connlimit: Hmm, kmalloc failed :-(\n");
11601 +               *hotdrop = 1; /* let's free some memory :-) */
11602 +               return 0;
11603 +       }
11604 +        match = (info->inverse) ? (connections <= info->limit) : (connections > info->limit);
11605 +#if DEBUG
11606 +       printk("ipt_connlimit: src=%u.%u.%u.%u mask=%u.%u.%u.%u "
11607 +              "connections=%d limit=%d match=%s\n",
11608 +              NIPQUAD(skb->nh.iph->saddr), NIPQUAD(info->mask),
11609 +              connections, info->limit, match ? "yes" : "no");
11610 +#endif
11611 +
11612 +       return match;
11613 +}
11614 +
11615 +static int check(const char *tablename,
11616 +                const struct ipt_ip *ip,
11617 +                void *matchinfo,
11618 +                unsigned int matchsize,
11619 +                unsigned int hook_mask)
11620 +{
11621 +       struct ipt_connlimit_info *info = matchinfo;
11622 +       int i;
11623 +
11624 +       /* verify size */
11625 +       if (matchsize != IPT_ALIGN(sizeof(struct ipt_connlimit_info)))
11626 +               return 0;
11627 +
11628 +       /* refuse anything but tcp */
11629 +       if (ip->proto != IPPROTO_TCP)
11630 +               return 0;
11631 +
11632 +       /* init private data */
11633 +       info->data = kmalloc(sizeof(struct ipt_connlimit_data),GFP_KERNEL);
11634 +       spin_lock_init(&(info->data->lock));
11635 +       for (i = 0; i < 256; i++)
11636 +               INIT_LIST_HEAD(&(info->data->iphash[i]));
11637 +       
11638 +       return 1;
11639 +}
11640 +
11641 +static void destroy(void *matchinfo, unsigned int matchinfosize)
11642 +{
11643 +       struct ipt_connlimit_info *info = matchinfo;
11644 +       struct ipt_connlimit_conn *conn;
11645 +       struct list_head *hash;
11646 +       int i;
11647 +
11648 +       /* cleanup */
11649 +       for (i = 0; i < 256; i++) {
11650 +               hash = &(info->data->iphash[i]);
11651 +               while (hash != hash->next) {
11652 +                       conn = list_entry(hash->next,struct ipt_connlimit_conn,list);
11653 +                       list_del(hash->next);
11654 +                       kfree(conn);
11655 +               }
11656 +       }
11657 +       kfree(info->data);
11658 +}
11659 +
11660 +static struct ipt_match connlimit_match = { 
11661 +       .name = "connlimit",
11662 +       .match = &match,
11663 +       .checkentry = &check,
11664 +       .destroy = &destroy,
11665 +       .me = THIS_MODULE
11666 +};
11667 +
11668 +static int __init init(void)
11669 +{
11670 +       return ipt_register_match(&connlimit_match);
11671 +}
11672 +
11673 +static void __exit fini(void)
11674 +{
11675 +       ipt_unregister_match(&connlimit_match);
11676 +}
11677 +
11678 +module_init(init);
11679 +module_exit(fini);
11680 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_connmark.c linux-2.6.6/net/ipv4/netfilter/ipt_connmark.c
11681 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_connmark.c   1970-01-01 01:00:00.000000000 +0100
11682 +++ linux-2.6.6/net/ipv4/netfilter/ipt_connmark.c       2004-05-18 14:28:50.000000000 +0200
11683 @@ -0,0 +1,81 @@
11684 +/* This kernel module matches connection mark values set by the
11685 + * CONNMARK target
11686 + *
11687 + * Copyright (C) 2002,2004 MARA Systems AB <http://www.marasystems.com>
11688 + * by Henrik Nordstrom <hno@marasystems.com>
11689 + *
11690 + * This program is free software; you can redistribute it and/or modify
11691 + * it under the terms of the GNU General Public License as published by
11692 + * the Free Software Foundation; either version 2 of the License, or
11693 + * (at your option) any later version.
11694 + *
11695 + * This program is distributed in the hope that it will be useful,
11696 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11697 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11698 + * GNU General Public License for more details.
11699 + *
11700 + * You should have received a copy of the GNU General Public License
11701 + * along with this program; if not, write to the Free Software
11702 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
11703 + */
11704 +
11705 +#include <linux/module.h>
11706 +#include <linux/skbuff.h>
11707 +
11708 +MODULE_AUTHOR("Henrik Nordstrom <hno@marasytems.com>");
11709 +MODULE_DESCRIPTION("IP tables connmark match module");
11710 +MODULE_LICENSE("GPL");
11711 +
11712 +#include <linux/netfilter_ipv4/ip_tables.h>
11713 +#include <linux/netfilter_ipv4/ipt_connmark.h>
11714 +#include <linux/netfilter_ipv4/ip_conntrack.h>
11715 +
11716 +static int
11717 +match(const struct sk_buff *skb,
11718 +      const struct net_device *in,
11719 +      const struct net_device *out,
11720 +      const void *matchinfo,
11721 +      int offset,
11722 +      int *hotdrop)
11723 +{
11724 +       const struct ipt_connmark_info *info = matchinfo;
11725 +       enum ip_conntrack_info ctinfo;
11726 +       struct ip_conntrack *ct = ip_conntrack_get((struct sk_buff *)skb, &ctinfo);
11727 +       if (!ct)
11728 +               return 0;
11729 +
11730 +       return ((ct->mark & info->mask) == info->mark) ^ info->invert;
11731 +}
11732 +
11733 +static int
11734 +checkentry(const char *tablename,
11735 +          const struct ipt_ip *ip,
11736 +          void *matchinfo,
11737 +          unsigned int matchsize,
11738 +          unsigned int hook_mask)
11739 +{
11740 +       if (matchsize != IPT_ALIGN(sizeof(struct ipt_connmark_info)))
11741 +               return 0;
11742 +
11743 +       return 1;
11744 +}
11745 +
11746 +static struct ipt_match connmark_match = {
11747 +       .name = "connmark",
11748 +       .match = &match,
11749 +       .checkentry = &checkentry,
11750 +       .me = THIS_MODULE
11751 +};
11752 +
11753 +static int __init init(void)
11754 +{
11755 +       return ipt_register_match(&connmark_match);
11756 +}
11757 +
11758 +static void __exit fini(void)
11759 +{
11760 +       ipt_unregister_match(&connmark_match);
11761 +}
11762 +
11763 +module_init(init);
11764 +module_exit(fini);
11765 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_dstlimit.c linux-2.6.6/net/ipv4/netfilter/ipt_dstlimit.c
11766 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_dstlimit.c   1970-01-01 01:00:00.000000000 +0100
11767 +++ linux-2.6.6/net/ipv4/netfilter/ipt_dstlimit.c       2004-05-18 14:28:50.000000000 +0200
11768 @@ -0,0 +1,690 @@
11769 +/* iptables match extension to limit the number of packets per second
11770 + * seperately for each destination.
11771 + *
11772 + * (C) 2003 by Harald Welte <laforge@netfilter.org>
11773 + *
11774 + * $Id$
11775 + *
11776 + * Development of this code was funded by Astaro AG, http://www.astaro.com/
11777 + *
11778 + * based on ipt_limit.c by:
11779 + * Jérôme de Vivie     <devivie@info.enserb.u-bordeaux.fr>
11780 + * Hervé Eychenne      <eychenne@info.enserb.u-bordeaux.fr>
11781 + * Rusty Russell       <rusty@rustcorp.com.au>
11782 + *
11783 + * The general idea is to create a hash table for every dstip and have a
11784 + * seperate limit counter per tuple.  This way you can do something like 'limit
11785 + * the number of syn packets for each of my internal addresses.
11786 + *
11787 + * Ideally this would just be implemented as a general 'hash' match, which would
11788 + * allow us to attach any iptables target to it's hash buckets.  But this is
11789 + * not possible in the current iptables architecture.  As always, pkttables for
11790 + * 2.7.x will help ;)
11791 + */
11792 +#include <linux/module.h>
11793 +#include <linux/skbuff.h>
11794 +#include <linux/spinlock.h>
11795 +#include <linux/random.h>
11796 +#include <linux/jhash.h>
11797 +#include <linux/slab.h>
11798 +#include <linux/vmalloc.h>
11799 +#include <linux/tcp.h>
11800 +#include <linux/udp.h>
11801 +#include <linux/proc_fs.h>
11802 +#include <linux/seq_file.h>
11803 +
11804 +#define ASSERT_READ_LOCK(x) 
11805 +#define ASSERT_WRITE_LOCK(x) 
11806 +#include <linux/netfilter_ipv4/lockhelp.h>
11807 +#include <linux/netfilter_ipv4/listhelp.h>
11808 +
11809 +#include <linux/netfilter_ipv4/ip_tables.h>
11810 +#include <linux/netfilter_ipv4/ipt_dstlimit.h>
11811 +
11812 +/* FIXME: this is just for IP_NF_ASSERRT */
11813 +#include <linux/netfilter_ipv4/ip_conntrack.h>
11814 +
11815 +#define MS2JIFFIES(x) ((x*HZ)/1000)
11816 +
11817 +MODULE_LICENSE("GPL");
11818 +MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>");
11819 +MODULE_DESCRIPTION("iptables match for limiting per destination");
11820 +
11821 +/* need to declare this at the top */
11822 +static struct proc_dir_entry *dstlimit_procdir;
11823 +static struct file_operations dl_file_ops;
11824 +
11825 +/* hash table crap */
11826 +
11827 +struct dsthash_dst {
11828 +       u_int32_t src_ip;
11829 +       u_int32_t dst_ip;
11830 +       u_int16_t port;
11831 +};
11832 +
11833 +struct dsthash_ent {
11834 +       /* static / read-only parts in the beginning */
11835 +       struct list_head list;
11836 +       struct dsthash_dst dst;
11837 +
11838 +       /* modified structure members in the end */
11839 +       unsigned long expires;          /* precalculated expiry time */
11840 +       struct {
11841 +               unsigned long prev;     /* last modification */
11842 +               u_int32_t credit;
11843 +               u_int32_t credit_cap, cost;
11844 +       } rateinfo;
11845 +};
11846 +
11847 +struct ipt_dstlimit_htable {
11848 +       struct list_head list;          /* global list of all htables */
11849 +       atomic_t use;
11850 +
11851 +       struct dstlimit_cfg cfg;        /* config */
11852 +
11853 +       /* used internally */
11854 +       spinlock_t lock;                /* lock for list_head */
11855 +       u_int32_t rnd;                  /* random seed for hash */
11856 +       struct timer_list timer;        /* timer for gc */
11857 +       atomic_t count;                 /* number entries in table */
11858 +
11859 +       /* seq_file stuff */
11860 +       struct proc_dir_entry *pde;
11861 +
11862 +       struct list_head hash[0];       /* hashtable itself */
11863 +};
11864 +
11865 +DECLARE_RWLOCK(dstlimit_lock);         /* protects htables list */
11866 +static LIST_HEAD(dstlimit_htables);
11867 +static kmem_cache_t *dstlimit_cachep;
11868 +
11869 +static inline int dst_cmp(const struct dsthash_ent *ent, struct dsthash_dst *b)
11870 +{
11871 +       return (ent->dst.dst_ip == b->dst_ip 
11872 +               && ent->dst.port == b->port
11873 +               && ent->dst.src_ip == b->src_ip);
11874 +}
11875 +
11876 +static inline u_int32_t
11877 +hash_dst(const struct ipt_dstlimit_htable *ht, const struct dsthash_dst *dst)
11878 +{
11879 +       return (jhash_3words(dst->dst_ip, dst->port, 
11880 +                            dst->src_ip, ht->rnd) % ht->cfg.size);
11881 +}
11882 +
11883 +static inline struct dsthash_ent *
11884 +__dsthash_find(const struct ipt_dstlimit_htable *ht, struct dsthash_dst *dst)
11885 +{
11886 +       struct dsthash_ent *ent;
11887 +       u_int32_t hash = hash_dst(ht, dst);
11888 +       MUST_BE_LOCKED(&ht->lock);
11889 +       ent = LIST_FIND(&ht->hash[hash], dst_cmp, struct dsthash_ent *, dst);
11890 +       return ent;
11891 +}
11892 +
11893 +/* allocate dsthash_ent, initialize dst, put in htable and lock it */
11894 +static struct dsthash_ent *
11895 +__dsthash_alloc_init(struct ipt_dstlimit_htable *ht, struct dsthash_dst *dst)
11896 +{
11897 +       struct dsthash_ent *ent;
11898 +
11899 +       /* initialize hash with random val at the time we allocate
11900 +        * the first hashtable entry */
11901 +       if (!ht->rnd)
11902 +               get_random_bytes(&ht->rnd, 4);
11903 +
11904 +       if (ht->cfg.max &&
11905 +           atomic_read(&ht->count) >= ht->cfg.max) {
11906 +               /* FIXME: do something. question is what.. */
11907 +               if (net_ratelimit())
11908 +                       printk(KERN_WARNING 
11909 +                               "ipt_dstlimit: max count of %u reached\n", 
11910 +                               ht->cfg.max);
11911 +               return NULL;
11912 +       }
11913 +
11914 +       ent = kmem_cache_alloc(dstlimit_cachep, GFP_ATOMIC);
11915 +       if (!ent) {
11916 +               if (net_ratelimit())
11917 +                       printk(KERN_ERR 
11918 +                               "ipt_dstlimit: can't allocate dsthash_ent\n");
11919 +               return NULL;
11920 +       }
11921 +
11922 +       atomic_inc(&ht->count);
11923 +
11924 +       ent->dst.dst_ip = dst->dst_ip;
11925 +       ent->dst.port = dst->port;
11926 +       ent->dst.src_ip = dst->src_ip;
11927 +
11928 +       list_add(&ent->list, &ht->hash[hash_dst(ht, dst)]);
11929 +
11930 +       return ent;
11931 +}
11932 +
11933 +static inline void 
11934 +__dsthash_free(struct ipt_dstlimit_htable *ht, struct dsthash_ent *ent)
11935 +{
11936 +       MUST_BE_LOCKED(&ht->lock);
11937 +
11938 +       list_del(&ent->list);
11939 +       kmem_cache_free(dstlimit_cachep, ent);
11940 +       atomic_dec(&ht->count);
11941 +}
11942 +static void htable_gc(unsigned long htlong);
11943 +
11944 +static int htable_create(struct ipt_dstlimit_info *minfo)
11945 +{
11946 +       int i;
11947 +       unsigned int size;
11948 +       struct ipt_dstlimit_htable *hinfo;
11949 +
11950 +       if (minfo->cfg.size)
11951 +               size = minfo->cfg.size;
11952 +       else {
11953 +               size = (((num_physpages << PAGE_SHIFT) / 16384)
11954 +                        / sizeof(struct list_head));
11955 +               if (num_physpages > (1024 * 1024 * 1024 / PAGE_SIZE))
11956 +                       size = 8192;
11957 +               if (size < 16)
11958 +                       size = 16;
11959 +       }
11960 +       /* FIXME: don't use vmalloc() here or anywhere else -HW */
11961 +       hinfo = vmalloc(sizeof(struct ipt_dstlimit_htable)
11962 +                       + (sizeof(struct list_head) * size));
11963 +       if (!hinfo) {
11964 +               printk(KERN_ERR "ipt_dstlimit: Unable to create hashtable\n");
11965 +               return -1;
11966 +       }
11967 +       minfo->hinfo = hinfo;
11968 +
11969 +       /* copy match config into hashtable config */
11970 +       memcpy(&hinfo->cfg, &minfo->cfg, sizeof(hinfo->cfg));
11971 +       hinfo->cfg.size = size;
11972 +       if (!hinfo->cfg.max)
11973 +               hinfo->cfg.max = 8 * hinfo->cfg.size;
11974 +       else if (hinfo->cfg.max < hinfo->cfg.size)
11975 +               hinfo->cfg.max = hinfo->cfg.size;
11976 +
11977 +       for (i = 0; i < hinfo->cfg.size; i++)
11978 +               INIT_LIST_HEAD(&hinfo->hash[i]);
11979 +
11980 +       atomic_set(&hinfo->count, 0);
11981 +       atomic_set(&hinfo->use, 1);
11982 +       hinfo->rnd = 0;
11983 +       hinfo->lock = SPIN_LOCK_UNLOCKED;
11984 +       hinfo->pde = create_proc_entry(minfo->name, 0, dstlimit_procdir);
11985 +       if (!hinfo->pde) {
11986 +               vfree(hinfo);
11987 +               return -1;
11988 +       }
11989 +       hinfo->pde->proc_fops = &dl_file_ops;
11990 +       hinfo->pde->data = hinfo;
11991 +
11992 +       init_timer(&hinfo->timer);
11993 +       hinfo->timer.expires = jiffies + MS2JIFFIES(hinfo->cfg.gc_interval);
11994 +       hinfo->timer.data = (unsigned long )hinfo;
11995 +       hinfo->timer.function = htable_gc;
11996 +       add_timer(&hinfo->timer);
11997 +
11998 +       WRITE_LOCK(&dstlimit_lock);
11999 +       list_add(&hinfo->list, &dstlimit_htables);
12000 +       WRITE_UNLOCK(&dstlimit_lock);
12001 +
12002 +       return 0;
12003 +}
12004 +
12005 +static int select_all(struct ipt_dstlimit_htable *ht, struct dsthash_ent *he)
12006 +{
12007 +       return 1;
12008 +}
12009 +
12010 +static int select_gc(struct ipt_dstlimit_htable *ht, struct dsthash_ent *he)
12011 +{
12012 +       return (jiffies >= he->expires);
12013 +}
12014 +
12015 +static void htable_selective_cleanup(struct ipt_dstlimit_htable *ht,
12016 +                               int (*select)(struct ipt_dstlimit_htable *ht, 
12017 +                                             struct dsthash_ent *he))
12018 +{
12019 +       int i;
12020 +
12021 +       IP_NF_ASSERT(ht->cfg.size && ht->cfg.max);
12022 +
12023 +       /* lock hash table and iterate over it */
12024 +       LOCK_BH(&ht->lock);
12025 +       for (i = 0; i < ht->cfg.size; i++) {
12026 +               struct dsthash_ent *dh, *n;
12027 +               list_for_each_entry_safe(dh, n, &ht->hash[i], list) {
12028 +                       if ((*select)(ht, dh))
12029 +                               __dsthash_free(ht, dh);
12030 +               }
12031 +       }
12032 +       UNLOCK_BH(&ht->lock);
12033 +}
12034 +
12035 +/* hash table garbage collector, run by timer */
12036 +static void htable_gc(unsigned long htlong)
12037 +{
12038 +       struct ipt_dstlimit_htable *ht = (struct ipt_dstlimit_htable *)htlong;
12039 +
12040 +       htable_selective_cleanup(ht, select_gc);
12041 +
12042 +       /* re-add the timer accordingly */
12043 +       ht->timer.expires = jiffies + MS2JIFFIES(ht->cfg.gc_interval);
12044 +       add_timer(&ht->timer);
12045 +}
12046 +
12047 +static void htable_destroy(struct ipt_dstlimit_htable *hinfo)
12048 +{
12049 +       /* remove timer, if it is pending */
12050 +       if (timer_pending(&hinfo->timer))
12051 +               del_timer(&hinfo->timer);
12052 +
12053 +       /* remove proc entry */
12054 +       remove_proc_entry(hinfo->pde->name, dstlimit_procdir);
12055 +
12056 +       htable_selective_cleanup(hinfo, select_all);
12057 +       vfree(hinfo);
12058 +}
12059 +
12060 +static struct ipt_dstlimit_htable *htable_find_get(char *name)
12061 +{
12062 +       struct ipt_dstlimit_htable *hinfo;
12063 +
12064 +       READ_LOCK(&dstlimit_lock);
12065 +       list_for_each_entry(hinfo, &dstlimit_htables, list) {
12066 +               if (!strcmp(name, hinfo->pde->name)) {
12067 +                       atomic_inc(&hinfo->use);
12068 +                       READ_UNLOCK(&dstlimit_lock);
12069 +                       return hinfo;
12070 +               }
12071 +       }
12072 +       READ_UNLOCK(&dstlimit_lock);
12073 +
12074 +       return NULL;
12075 +}
12076 +
12077 +static void htable_put(struct ipt_dstlimit_htable *hinfo)
12078 +{
12079 +       if (atomic_dec_and_test(&hinfo->use)) {
12080 +               WRITE_LOCK(&dstlimit_lock);
12081 +               list_del(&hinfo->list);
12082 +               WRITE_UNLOCK(&dstlimit_lock);
12083 +               htable_destroy(hinfo);
12084 +       }
12085 +}
12086 +
12087 +
12088 +/* The algorithm used is the Simple Token Bucket Filter (TBF)
12089 + * see net/sched/sch_tbf.c in the linux source tree
12090 + */
12091 +
12092 +/* Rusty: This is my (non-mathematically-inclined) understanding of
12093 +   this algorithm.  The `average rate' in jiffies becomes your initial
12094 +   amount of credit `credit' and the most credit you can ever have
12095 +   `credit_cap'.  The `peak rate' becomes the cost of passing the
12096 +   test, `cost'.
12097 +
12098 +   `prev' tracks the last packet hit: you gain one credit per jiffy.
12099 +   If you get credit balance more than this, the extra credit is
12100 +   discarded.  Every time the match passes, you lose `cost' credits;
12101 +   if you don't have that many, the test fails.
12102 +
12103 +   See Alexey's formal explanation in net/sched/sch_tbf.c.
12104 +
12105 +   To get the maximum range, we multiply by this factor (ie. you get N
12106 +   credits per jiffy).  We want to allow a rate as low as 1 per day
12107 +   (slowest userspace tool allows), which means
12108 +   CREDITS_PER_JIFFY*HZ*60*60*24 < 2^32 ie.
12109 +*/
12110 +#define MAX_CPJ (0xFFFFFFFF / (HZ*60*60*24))
12111 +
12112 +/* Repeated shift and or gives us all 1s, final shift and add 1 gives
12113 + * us the power of 2 below the theoretical max, so GCC simply does a
12114 + * shift. */
12115 +#define _POW2_BELOW2(x) ((x)|((x)>>1))
12116 +#define _POW2_BELOW4(x) (_POW2_BELOW2(x)|_POW2_BELOW2((x)>>2))
12117 +#define _POW2_BELOW8(x) (_POW2_BELOW4(x)|_POW2_BELOW4((x)>>4))
12118 +#define _POW2_BELOW16(x) (_POW2_BELOW8(x)|_POW2_BELOW8((x)>>8))
12119 +#define _POW2_BELOW32(x) (_POW2_BELOW16(x)|_POW2_BELOW16((x)>>16))
12120 +#define POW2_BELOW32(x) ((_POW2_BELOW32(x)>>1) + 1)
12121 +
12122 +#define CREDITS_PER_JIFFY POW2_BELOW32(MAX_CPJ)
12123 +
12124 +/* Precision saver. */
12125 +static inline u_int32_t
12126 +user2credits(u_int32_t user)
12127 +{
12128 +       /* If multiplying would overflow... */
12129 +       if (user > 0xFFFFFFFF / (HZ*CREDITS_PER_JIFFY))
12130 +               /* Divide first. */
12131 +               return (user / IPT_DSTLIMIT_SCALE) * HZ * CREDITS_PER_JIFFY;
12132 +
12133 +       return (user * HZ * CREDITS_PER_JIFFY) / IPT_DSTLIMIT_SCALE;
12134 +}
12135 +
12136 +static inline void rateinfo_recalc(struct dsthash_ent *dh, unsigned long now)
12137 +{
12138 +       dh->rateinfo.credit += (now - xchg(&dh->rateinfo.prev, now)) 
12139 +                                       * CREDITS_PER_JIFFY;
12140 +       if (dh->rateinfo.credit > dh->rateinfo.credit_cap)
12141 +               dh->rateinfo.credit = dh->rateinfo.credit_cap;
12142 +}
12143 +
12144 +static int
12145 +dstlimit_match(const struct sk_buff *skb,
12146 +               const struct net_device *in,
12147 +               const struct net_device *out,
12148 +               const void *matchinfo,
12149 +               int offset,
12150 +               int *hotdrop)
12151 +{
12152 +       struct ipt_dstlimit_info *r = 
12153 +               ((struct ipt_dstlimit_info *)matchinfo)->u.master;
12154 +       struct ipt_dstlimit_htable *hinfo = r->hinfo;
12155 +       unsigned long now = jiffies;
12156 +       struct dsthash_ent *dh;
12157 +       struct dsthash_dst dst;
12158 +
12159 +       memset(&dst, 0, sizeof(dst));
12160 +
12161 +       /* dest ip is always in hash */
12162 +       dst.dst_ip = skb->nh.iph->daddr;
12163 +
12164 +       /* source ip only if respective hashmode, otherwise set to
12165 +        * zero */
12166 +       if (hinfo->cfg.mode & IPT_DSTLIMIT_HASH_SIP)
12167 +               dst.src_ip = skb->nh.iph->saddr;
12168 +
12169 +       /* dest port only if respective mode */
12170 +       if (hinfo->cfg.mode & IPT_DSTLIMIT_HASH_DPT) {
12171 +               u16 ports[2];
12172 +
12173 +               /* Must not be a fragment. */
12174 +               if (offset)
12175 +                       return 0;
12176 +
12177 +               /* Must be big enough to read ports (both UDP and TCP have
12178 +                  them at the start). */
12179 +               if (skb_copy_bits(skb, skb->nh.iph->ihl*4, ports, sizeof(ports)) < 0) {
12180 +                       /* We've been asked to examine this packet, and we
12181 +                          can't.  Hence, no choice but to drop. */
12182 +                       *hotdrop = 1;
12183 +                       return 0;
12184 +               }
12185 +
12186 +               switch (skb->nh.iph->protocol) {
12187 +                       struct tcphdr *th;
12188 +                       struct udphdr *uh;
12189 +               case IPPROTO_TCP:
12190 +                       th = (void *)skb->nh.iph+skb->nh.iph->ihl*4;
12191 +                       dst.port = th->dest;
12192 +                       break;
12193 +               case IPPROTO_UDP:
12194 +                       uh = (void *)skb->nh.iph+skb->nh.iph->ihl*4;
12195 +                       dst.port = uh->dest;
12196 +                       break;
12197 +               default:
12198 +                       break;
12199 +               }
12200 +       } 
12201 +
12202 +       LOCK_BH(&hinfo->lock);
12203 +       dh = __dsthash_find(hinfo, &dst);
12204 +       if (!dh) {
12205 +               dh = __dsthash_alloc_init(hinfo, &dst);
12206 +
12207 +               if (!dh) {
12208 +                       /* enomem... don't match == DROP */
12209 +                       if (net_ratelimit())
12210 +                               printk(KERN_ERR "%s: ENOMEM\n", __FUNCTION__);
12211 +                       UNLOCK_BH(&hinfo->lock);
12212 +                       return 0;
12213 +               }
12214 +
12215 +               dh->expires = jiffies + MS2JIFFIES(hinfo->cfg.expire);
12216 +
12217 +               dh->rateinfo.prev = jiffies;
12218 +               dh->rateinfo.credit = user2credits(hinfo->cfg.avg * 
12219 +                                                       hinfo->cfg.burst);
12220 +               dh->rateinfo.credit_cap = user2credits(hinfo->cfg.avg * 
12221 +                                                       hinfo->cfg.burst);
12222 +               dh->rateinfo.cost = user2credits(hinfo->cfg.avg);
12223 +
12224 +               UNLOCK_BH(&hinfo->lock);
12225 +               return 1;
12226 +       }
12227 +
12228 +       /* update expiration timeout */
12229 +       dh->expires = now + MS2JIFFIES(hinfo->cfg.expire);
12230 +
12231 +       rateinfo_recalc(dh, now);
12232 +       if (dh->rateinfo.credit >= dh->rateinfo.cost) {
12233 +               /* We're underlimit. */
12234 +               dh->rateinfo.credit -= dh->rateinfo.cost;
12235 +               UNLOCK_BH(&hinfo->lock);
12236 +               return 1;
12237 +       }
12238 +
12239 +               UNLOCK_BH(&hinfo->lock);
12240 +
12241 +       /* default case: we're overlimit, thus don't match */
12242 +       return 0;
12243 +}
12244 +
12245 +static int
12246 +dstlimit_checkentry(const char *tablename,
12247 +                    const struct ipt_ip *ip,
12248 +                    void *matchinfo,
12249 +                    unsigned int matchsize,
12250 +                    unsigned int hook_mask)
12251 +{
12252 +       struct ipt_dstlimit_info *r = matchinfo;
12253 +
12254 +       if (matchsize != IPT_ALIGN(sizeof(struct ipt_dstlimit_info)))
12255 +               return 0;
12256 +
12257 +       /* Check for overflow. */
12258 +       if (r->cfg.burst == 0
12259 +           || user2credits(r->cfg.avg * r->cfg.burst) < 
12260 +                                       user2credits(r->cfg.avg)) {
12261 +               printk(KERN_ERR "ipt_dstlimit: Overflow, try lower: %u/%u\n",
12262 +                      r->cfg.avg, r->cfg.burst);
12263 +               return 0;
12264 +       }
12265 +
12266 +       if (r->cfg.mode == 0 
12267 +           || r->cfg.mode > (IPT_DSTLIMIT_HASH_DPT
12268 +                         |IPT_DSTLIMIT_HASH_DIP
12269 +                         |IPT_DSTLIMIT_HASH_SIP))
12270 +               return 0;
12271 +
12272 +       if (!r->cfg.gc_interval)
12273 +               return 0;
12274 +       
12275 +       if (!r->cfg.expire)
12276 +               return 0;
12277 +
12278 +       r->hinfo = htable_find_get(r->name);
12279 +       if (!r->hinfo && (htable_create(r) != 0)) {
12280 +               return 0;
12281 +       }
12282 +
12283 +       /* Ugly hack: For SMP, we only want to use one set */
12284 +       r->u.master = r;
12285 +
12286 +       return 1;
12287 +}
12288 +
12289 +static void
12290 +dstlimit_destroy(void *matchinfo, unsigned int matchsize)
12291 +{
12292 +       struct ipt_dstlimit_info *r = (struct ipt_dstlimit_info *) matchinfo;
12293 +
12294 +       htable_put(r->hinfo);
12295 +}
12296 +
12297 +static struct ipt_match ipt_dstlimit = { 
12298 +       .list = { .prev = NULL, .next = NULL }, 
12299 +       .name = "dstlimit", 
12300 +       .match = dstlimit_match, 
12301 +       .checkentry = dstlimit_checkentry, 
12302 +       .destroy = dstlimit_destroy,
12303 +       .me = THIS_MODULE 
12304 +};
12305 +
12306 +/* PROC stuff */
12307 +
12308 +static void *dl_seq_start(struct seq_file *s, loff_t *pos)
12309 +{
12310 +       struct proc_dir_entry *pde = s->private;
12311 +       struct ipt_dstlimit_htable *htable = pde->data;
12312 +       unsigned int *bucket;
12313 +
12314 +       LOCK_BH(&htable->lock);
12315 +       if (*pos >= htable->cfg.size)
12316 +               return NULL;
12317 +
12318 +       bucket = kmalloc(sizeof(unsigned int), GFP_KERNEL);
12319 +       if (!bucket)
12320 +               return ERR_PTR(-ENOMEM);
12321 +
12322 +       *bucket = *pos;
12323 +       return bucket;
12324 +}
12325 +
12326 +static void *dl_seq_next(struct seq_file *s, void *v, loff_t *pos)
12327 +{
12328 +       struct proc_dir_entry *pde = s->private;
12329 +       struct ipt_dstlimit_htable *htable = pde->data;
12330 +       unsigned int *bucket = (unsigned int *)v;
12331 +
12332 +       *pos = ++(*bucket);
12333 +       if (*pos >= htable->cfg.size) {
12334 +               kfree(v);
12335 +               return NULL;
12336 +       }
12337 +       return bucket;
12338 +}
12339 +
12340 +static void dl_seq_stop(struct seq_file *s, void *v)
12341 +{
12342 +       struct proc_dir_entry *pde = s->private;
12343 +       struct ipt_dstlimit_htable *htable = pde->data;
12344 +       unsigned int *bucket = (unsigned int *)v;
12345 +
12346 +       kfree(bucket);
12347 +
12348 +       UNLOCK_BH(&htable->lock);
12349 +}
12350 +
12351 +static inline int dl_seq_real_show(struct dsthash_ent *ent, struct seq_file *s)
12352 +{
12353 +       /* recalculate to show accurate numbers */
12354 +       rateinfo_recalc(ent, jiffies);
12355 +
12356 +       return seq_printf(s, "%ld %u.%u.%u.%u->%u.%u.%u.%u:%u %u %u %u\n",
12357 +                       (ent->expires - jiffies)/HZ,
12358 +                       NIPQUAD(ent->dst.src_ip),
12359 +                       NIPQUAD(ent->dst.dst_ip), ntohs(ent->dst.port),
12360 +                       ent->rateinfo.credit, ent->rateinfo.credit_cap,
12361 +                       ent->rateinfo.cost);
12362 +}
12363 +
12364 +static int dl_seq_show(struct seq_file *s, void *v)
12365 +{
12366 +       struct proc_dir_entry *pde = s->private;
12367 +       struct ipt_dstlimit_htable *htable = pde->data;
12368 +       unsigned int *bucket = (unsigned int *)v;
12369 +
12370 +       if (LIST_FIND_W(&htable->hash[*bucket], dl_seq_real_show,
12371 +                     struct dsthash_ent *, s)) {
12372 +               /* buffer was filled and unable to print that tuple */
12373 +               return 1;
12374 +       }
12375 +       return 0;
12376 +}
12377 +
12378 +static struct seq_operations dl_seq_ops = {
12379 +       .start = dl_seq_start,
12380 +       .next  = dl_seq_next,
12381 +       .stop  = dl_seq_stop,
12382 +       .show  = dl_seq_show
12383 +};
12384 +
12385 +static int dl_proc_open(struct inode *inode, struct file *file)
12386 +{
12387 +       int ret = seq_open(file, &dl_seq_ops);
12388 +
12389 +       if (!ret) {
12390 +               struct seq_file *sf = file->private_data;
12391 +               sf->private = PDE(inode);
12392 +       }
12393 +       return ret;
12394 +}
12395 +
12396 +static struct file_operations dl_file_ops = {
12397 +       .owner   = THIS_MODULE,
12398 +       .open    = dl_proc_open,
12399 +       .read    = seq_read,
12400 +       .llseek  = seq_lseek,
12401 +       .release = seq_release
12402 +};
12403 +
12404 +static int init_or_fini(int fini)
12405 +{
12406 +       int ret = 0;
12407 +
12408 +       if (fini)
12409 +               goto cleanup;
12410 +
12411 +       if (ipt_register_match(&ipt_dstlimit)) {
12412 +               ret = -EINVAL;
12413 +               goto cleanup_nothing;
12414 +       }
12415 +
12416 +       /* FIXME: do we really want HWCACHE_ALIGN since our objects are
12417 +        * quite small ? */
12418 +       dstlimit_cachep = kmem_cache_create("ipt_dstlimit",
12419 +                                           sizeof(struct dsthash_ent), 0,
12420 +                                           SLAB_HWCACHE_ALIGN, NULL, NULL);
12421 +       if (!dstlimit_cachep) {
12422 +               printk(KERN_ERR "Unable to create ipt_dstlimit slab cache\n");
12423 +               ret = -ENOMEM;
12424 +               goto cleanup_unreg_match;
12425 +       }
12426 +
12427 +       dstlimit_procdir = proc_mkdir("ipt_dstlimit", proc_net);
12428 +       if (!dstlimit_procdir) {
12429 +               printk(KERN_ERR "Unable to create proc dir entry\n");
12430 +               ret = -ENOMEM;
12431 +               goto cleanup_free_slab;
12432 +       }
12433 +
12434 +       return ret;
12435 +
12436 +cleanup:
12437 +       remove_proc_entry("ipt_dstlimit", proc_net);
12438 +cleanup_free_slab:
12439 +       kmem_cache_destroy(dstlimit_cachep);
12440 +cleanup_unreg_match:
12441 +       ipt_unregister_match(&ipt_dstlimit);
12442 +cleanup_nothing:
12443 +       return ret;
12444 +       
12445 +}
12446 +
12447 +static int __init init(void)
12448 +{
12449 +       return init_or_fini(0);
12450 +}
12451 +
12452 +static void __exit fini(void)
12453 +{
12454 +       init_or_fini(1);
12455 +}
12456 +
12457 +module_init(init);
12458 +module_exit(fini);
12459 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_fuzzy.c linux-2.6.6/net/ipv4/netfilter/ipt_fuzzy.c
12460 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_fuzzy.c      1970-01-01 01:00:00.000000000 +0100
12461 +++ linux-2.6.6/net/ipv4/netfilter/ipt_fuzzy.c  2004-05-18 14:28:50.000000000 +0200
12462 @@ -0,0 +1,185 @@
12463 +/*
12464 + *  This module implements a simple TSK FLC 
12465 + * (Takagi-Sugeno-Kang Fuzzy Logic Controller) that aims
12466 + * to limit , in an adaptive and flexible way , the packet rate crossing 
12467 + * a given stream . It serves as an initial and very simple (but effective)
12468 + * example of how Fuzzy Logic techniques can be applied to defeat DoS attacks.
12469 + *  As a matter of fact , Fuzzy Logic can help us to insert any "behavior"  
12470 + * into our code in a precise , adaptive and efficient manner. 
12471 + *  The goal is very similar to that of "limit" match , but using techniques of
12472 + * Fuzzy Control , that allow us to shape the transfer functions precisely ,
12473 + * avoiding over and undershoots - and stuff like that .
12474 + *
12475 + *
12476 + * 2002-08-10  Hime Aguiar e Oliveira Jr. <hime@engineer.com> : Initial version.
12477 + * 2002-08-17  : Changed to eliminate floating point operations .
12478 + * 2002-08-23  : Coding style changes .
12479 +*/
12480 +
12481 +#include <linux/module.h>
12482 +#include <linux/skbuff.h>
12483 +#include <linux/ip.h>
12484 +#include <linux/random.h>
12485 +#include <net/tcp.h>
12486 +#include <linux/spinlock.h>
12487 +#include <linux/netfilter_ipv4/ip_tables.h>
12488 +#include <linux/netfilter_ipv4/ipt_fuzzy.h>
12489 +
12490 +/*
12491 + Packet Acceptance Rate - LOW and Packet Acceptance Rate - HIGH
12492 + Expressed in percentage
12493 +*/
12494 +
12495 +#define PAR_LOW                1/100
12496 +#define PAR_HIGH       1
12497 +
12498 +static spinlock_t fuzzy_lock = SPIN_LOCK_UNLOCKED ;
12499 +
12500 +MODULE_AUTHOR("Hime Aguiar e Oliveira Junior <hime@engineer.com>");
12501 +MODULE_DESCRIPTION("IP tables Fuzzy Logic Controller match module");
12502 +MODULE_LICENSE("GPL");
12503 +
12504 +static  u_int8_t mf_high(u_int32_t tx,u_int32_t mini,u_int32_t maxi)
12505 +{
12506 +       if (tx >= maxi)
12507 +               return 100;
12508 +
12509 +       if (tx <= mini)
12510 +               return 0;
12511 +
12512 +       return ( (100*(tx-mini)) / (maxi-mini) );
12513 +}
12514 +
12515 +static u_int8_t mf_low(u_int32_t tx,u_int32_t mini,u_int32_t maxi)
12516 +{
12517 +       if (tx <= mini)
12518 +               return 100;
12519 +
12520 +       if (tx >= maxi)
12521 +               return 0;
12522 +
12523 +       return ( (100*( maxi - tx ))  / ( maxi - mini ) );
12524 +}
12525 +
12526 +static int
12527 +ipt_fuzzy_match(const struct sk_buff *pskb,
12528 +              const struct net_device *in,
12529 +              const struct net_device *out,
12530 +              const void *matchinfo,
12531 +              int offset,
12532 +              int *hotdrop)
12533 +{
12534 +       /* From userspace */
12535 +       
12536 +       struct ipt_fuzzy_info *info = (struct ipt_fuzzy_info *) matchinfo;
12537 +
12538 +       u_int8_t random_number;
12539 +       unsigned long amount;
12540 +       u_int8_t howhigh, howlow;
12541 +       
12542 +
12543 +       spin_lock_bh(&fuzzy_lock); /* Rise the lock */
12544 +
12545 +       info->bytes_total += pskb->len;
12546 +       info->packets_total++;
12547 +
12548 +       info->present_time = jiffies;
12549 +       
12550 +       if (info->present_time >= info->previous_time)
12551 +               amount = info->present_time - info->previous_time;
12552 +       else { 
12553 +               /* There was a transition : I choose to re-sample 
12554 +                  and keep the old acceptance rate...
12555 +               */
12556 +
12557 +               amount = 0;
12558 +               info->previous_time = info->present_time;
12559 +               info->bytes_total = info->packets_total = 0;
12560 +       };
12561 +       
12562 +       if (amount > HZ/10) /* More than 100 ms elapsed ... */
12563 +       {
12564 +
12565 +               info->mean_rate = (u_int32_t) ((HZ*info->packets_total)  \
12566 +                                       / amount );
12567 +
12568 +               info->previous_time = info->present_time;
12569 +               info->bytes_total = info->packets_total = 0;
12570 +
12571 +               howhigh = mf_high(info->mean_rate,info->minimum_rate,info->maximum_rate);
12572 +               howlow  = mf_low(info->mean_rate,info->minimum_rate,info->maximum_rate);
12573 +
12574 +               info->acceptance_rate = (u_int8_t) \
12575 +                          (howhigh*PAR_LOW + PAR_HIGH*howlow);
12576 +
12577 +               /* In fact , the above defuzzification would require a denominator
12578 +                  proportional to (howhigh+howlow) but , in this particular case ,
12579 +                  that expression is constant .
12580 +                  An imediate consequence is that it isn't necessary to call 
12581 +                  both mf_high and mf_low - but to keep things understandable ,
12582 +                  I did so .  */ 
12583 +
12584 +       }
12585 +       
12586 +       spin_unlock_bh(&fuzzy_lock); /* Release the lock */
12587 +
12588 +
12589 +       if ( info->acceptance_rate < 100 )
12590 +       {                
12591 +               get_random_bytes((void *)(&random_number), 1);
12592 +
12593 +               /*  If within the acceptance , it can pass => don't match */
12594 +               if (random_number <= (255 * info->acceptance_rate) / 100)
12595 +                       return 0;
12596 +               else
12597 +                       return 1; /* It can't pass ( It matches ) */
12598 +       } ;
12599 +
12600 +       return 0; /* acceptance_rate == 100 % => Everything passes ... */
12601 +       
12602 +}
12603 +
12604 +static int
12605 +ipt_fuzzy_checkentry(const char *tablename,
12606 +                  const struct ipt_ip *e,
12607 +                  void *matchinfo,
12608 +                  unsigned int matchsize,
12609 +                  unsigned int hook_mask)
12610 +{
12611 +       
12612 +       const struct ipt_fuzzy_info *info = matchinfo;
12613 +
12614 +       if (matchsize != IPT_ALIGN(sizeof(struct ipt_fuzzy_info))) {
12615 +               printk("ipt_fuzzy: matchsize %u != %u\n", matchsize,
12616 +                      IPT_ALIGN(sizeof(struct ipt_fuzzy_info)));
12617 +               return 0;
12618 +       }
12619 +
12620 +       if ((info->minimum_rate < MINFUZZYRATE ) || (info->maximum_rate > MAXFUZZYRATE)
12621 +           || (info->minimum_rate >= info->maximum_rate )) {
12622 +               printk("ipt_fuzzy: BAD limits , please verify !!!\n");
12623 +               return 0;
12624 +       }
12625 +
12626 +       return 1;
12627 +}
12628 +
12629 +static struct ipt_match ipt_fuzzy_reg = { 
12630 +       .name = "fuzzy",
12631 +       .match = ipt_fuzzy_match,
12632 +       .checkentry = ipt_fuzzy_checkentry,
12633 +       .me = THIS_MODULE
12634 +};
12635 +
12636 +static int __init init(void)
12637 +{
12638 +       return ipt_register_match(&ipt_fuzzy_reg);
12639 +}
12640 +
12641 +static void __exit fini(void)
12642 +{
12643 +       ipt_unregister_match(&ipt_fuzzy_reg);
12644 +}
12645 +
12646 +module_init(init);
12647 +module_exit(fini);
12648 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_helper.c linux-2.6.6/net/ipv4/netfilter/ipt_helper.c
12649 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_helper.c     2004-05-10 04:32:54.000000000 +0200
12650 +++ linux-2.6.6/net/ipv4/netfilter/ipt_helper.c 2004-05-18 14:28:50.000000000 +0200
12651 @@ -41,17 +41,17 @@
12652         struct ip_conntrack_expect *exp;
12653         struct ip_conntrack *ct;
12654         enum ip_conntrack_info ctinfo;
12655 -       int ret = 0;
12656 +       int ret = info->invert;
12657         
12658         ct = ip_conntrack_get((struct sk_buff *)skb, &ctinfo);
12659         if (!ct) {
12660                 DEBUGP("ipt_helper: Eek! invalid conntrack?\n");
12661 -               return 0;
12662 +               return ret;
12663         }
12664  
12665         if (!ct->master) {
12666                 DEBUGP("ipt_helper: conntrack %p has no master\n", ct);
12667 -               return 0;
12668 +               return ret;
12669         }
12670  
12671         exp = ct->master;
12672 @@ -71,8 +71,11 @@
12673         DEBUGP("master's name = %s , info->name = %s\n", 
12674                 exp->expectant->helper->name, info->name);
12675  
12676 -       ret = !strncmp(exp->expectant->helper->name, info->name, 
12677 -                      strlen(exp->expectant->helper->name)) ^ info->invert;
12678 +       if (info->name[0] == '\0')
12679 +               ret ^= 1;
12680 +       else
12681 +               ret ^= !strncmp(exp->expectant->helper->name, info->name, 
12682 +                               strlen(exp->expectant->helper->name));
12683  out_unlock:
12684         READ_UNLOCK(&ip_conntrack_lock);
12685         return ret;
12686 @@ -92,10 +95,6 @@
12687         if (matchsize != IPT_ALIGN(sizeof(struct ipt_helper_info)))
12688                 return 0;
12689  
12690 -       /* verify that we actually should match anything */
12691 -       if ( strlen(info->name) == 0 )
12692 -               return 0;
12693 -       
12694         return 1;
12695  }
12696  
12697 @@ -108,7 +107,6 @@
12698  
12699  static int __init init(void)
12700  {
12701 -       need_ip_conntrack();
12702         return ipt_register_match(&helper_match);
12703  }
12704  
12705 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_ipv4options.c linux-2.6.6/net/ipv4/netfilter/ipt_ipv4options.c
12706 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_ipv4options.c        1970-01-01 01:00:00.000000000 +0100
12707 +++ linux-2.6.6/net/ipv4/netfilter/ipt_ipv4options.c    2004-05-18 14:28:50.000000000 +0200
12708 @@ -0,0 +1,172 @@
12709 +/*
12710 +  This is a module which is used to match ipv4 options.
12711 +  This file is distributed under the terms of the GNU General Public
12712 +  License (GPL). Copies of the GPL can be obtained from:
12713 +  ftp://prep.ai.mit.edu/pub/gnu/GPL
12714 +
12715 +  11-mars-2001 Fabrice MARIE <fabrice@netfilter.org> : initial development.
12716 +  12-july-2001 Fabrice MARIE <fabrice@netfilter.org> : added router-alert otions matching. Fixed a bug with no-srr
12717 +  12-august-2001 Imran Patel <ipatel@crosswinds.net> : optimization of the match.
12718 +  18-november-2001 Fabrice MARIE <fabrice@netfilter.org> : added [!] 'any' option match.
12719 +  19-february-2004 Harald Welte <laforge@netfilter.org> : merge with 2.6.x
12720 +*/
12721 +
12722 +#include <linux/module.h>
12723 +#include <linux/skbuff.h>
12724 +#include <net/ip.h>
12725 +
12726 +#include <linux/netfilter_ipv4/ip_tables.h>
12727 +#include <linux/netfilter_ipv4/ipt_ipv4options.h>
12728 +
12729 +MODULE_LICENSE("GPL");
12730 +MODULE_AUTHOR("Fabrice Marie <fabrice@netfilter.org>");
12731 +
12732 +static int
12733 +match(const struct sk_buff *skb,
12734 +      const struct net_device *in,
12735 +      const struct net_device *out,
12736 +      const void *matchinfo,
12737 +      int offset,
12738 +      int *hotdrop)
12739 +{
12740 +       const struct ipt_ipv4options_info *info = matchinfo;   /* match info for rule */
12741 +       const struct iphdr *iph = skb->nh.iph;
12742 +       const struct ip_options *opt;
12743 +
12744 +       if (iph->ihl * 4 == sizeof(struct iphdr)) {
12745 +               /* No options, so we match only the "DONTs" and the "IGNOREs" */
12746 +
12747 +               if (((info->options & IPT_IPV4OPTION_MATCH_ANY_OPT) == IPT_IPV4OPTION_MATCH_ANY_OPT) ||
12748 +                   ((info->options & IPT_IPV4OPTION_MATCH_SSRR) == IPT_IPV4OPTION_MATCH_SSRR) ||
12749 +                   ((info->options & IPT_IPV4OPTION_MATCH_LSRR) == IPT_IPV4OPTION_MATCH_LSRR) ||
12750 +                   ((info->options & IPT_IPV4OPTION_MATCH_RR) == IPT_IPV4OPTION_MATCH_RR) ||
12751 +                   ((info->options & IPT_IPV4OPTION_MATCH_TIMESTAMP) == IPT_IPV4OPTION_MATCH_TIMESTAMP) ||
12752 +                    ((info->options & IPT_IPV4OPTION_MATCH_ROUTER_ALERT) == IPT_IPV4OPTION_MATCH_ROUTER_ALERT))
12753 +                       return 0;
12754 +               return 1;
12755 +       }
12756 +       else {
12757 +               if ((info->options & IPT_IPV4OPTION_MATCH_ANY_OPT) == IPT_IPV4OPTION_MATCH_ANY_OPT)
12758 +                       /* there are options, and we don't need to care which one */
12759 +                       return 1;
12760 +               else {
12761 +                       if ((info->options & IPT_IPV4OPTION_DONT_MATCH_ANY_OPT) == IPT_IPV4OPTION_DONT_MATCH_ANY_OPT)
12762 +                               /* there are options but we don't want any ! */
12763 +                               return 0;
12764 +               }
12765 +       }
12766 +
12767 +       opt = &(IPCB(skb)->opt);
12768 +
12769 +       /* source routing */
12770 +       if ((info->options & IPT_IPV4OPTION_MATCH_SSRR) == IPT_IPV4OPTION_MATCH_SSRR) {
12771 +               if (!((opt->srr) & (opt->is_strictroute)))
12772 +                       return 0;
12773 +       }
12774 +       else if ((info->options & IPT_IPV4OPTION_MATCH_LSRR) == IPT_IPV4OPTION_MATCH_LSRR) {
12775 +               if (!((opt->srr) & (!opt->is_strictroute)))
12776 +                       return 0;
12777 +       }
12778 +       else if ((info->options & IPT_IPV4OPTION_DONT_MATCH_SRR) == IPT_IPV4OPTION_DONT_MATCH_SRR) {
12779 +               if (opt->srr)
12780 +                       return 0;
12781 +       }
12782 +       /* record route */
12783 +       if ((info->options & IPT_IPV4OPTION_MATCH_RR) == IPT_IPV4OPTION_MATCH_RR) {
12784 +               if (!opt->rr)
12785 +                       return 0;
12786 +       }
12787 +       else if ((info->options & IPT_IPV4OPTION_DONT_MATCH_RR) == IPT_IPV4OPTION_DONT_MATCH_RR) {
12788 +               if (opt->rr)
12789 +                       return 0;
12790 +       }
12791 +       /* timestamp */
12792 +       if ((info->options & IPT_IPV4OPTION_MATCH_TIMESTAMP) == IPT_IPV4OPTION_MATCH_TIMESTAMP) {
12793 +               if (!opt->ts)
12794 +                       return 0;
12795 +       }
12796 +       else if ((info->options & IPT_IPV4OPTION_DONT_MATCH_TIMESTAMP) == IPT_IPV4OPTION_DONT_MATCH_TIMESTAMP) {
12797 +               if (opt->ts)
12798 +                       return 0;
12799 +       }
12800 +       /* router-alert option  */
12801 +       if ((info->options & IPT_IPV4OPTION_MATCH_ROUTER_ALERT) == IPT_IPV4OPTION_MATCH_ROUTER_ALERT) {
12802 +               if (!opt->router_alert)
12803 +                       return 0;
12804 +       }
12805 +       else if ((info->options & IPT_IPV4OPTION_DONT_MATCH_ROUTER_ALERT) == IPT_IPV4OPTION_DONT_MATCH_ROUTER_ALERT) {
12806 +               if (opt->router_alert)
12807 +                       return 0;
12808 +       }
12809 +
12810 +       /* we match ! */
12811 +       return 1;
12812 +}
12813 +
12814 +static int
12815 +checkentry(const char *tablename,
12816 +          const struct ipt_ip *ip,
12817 +          void *matchinfo,
12818 +          unsigned int matchsize,
12819 +          unsigned int hook_mask)
12820 +{
12821 +       const struct ipt_ipv4options_info *info = matchinfo;   /* match info for rule */
12822 +       /* Check the size */
12823 +       if (matchsize != IPT_ALIGN(sizeof(struct ipt_ipv4options_info)))
12824 +               return 0;
12825 +       /* Now check the coherence of the data ... */
12826 +       if (((info->options & IPT_IPV4OPTION_MATCH_ANY_OPT) == IPT_IPV4OPTION_MATCH_ANY_OPT) &&
12827 +           (((info->options & IPT_IPV4OPTION_DONT_MATCH_SRR) == IPT_IPV4OPTION_DONT_MATCH_SRR) ||
12828 +            ((info->options & IPT_IPV4OPTION_DONT_MATCH_RR) == IPT_IPV4OPTION_DONT_MATCH_RR) ||
12829 +            ((info->options & IPT_IPV4OPTION_DONT_MATCH_TIMESTAMP) == IPT_IPV4OPTION_DONT_MATCH_TIMESTAMP) ||
12830 +            ((info->options & IPT_IPV4OPTION_DONT_MATCH_ROUTER_ALERT) == IPT_IPV4OPTION_DONT_MATCH_ROUTER_ALERT) ||
12831 +            ((info->options & IPT_IPV4OPTION_DONT_MATCH_ANY_OPT) == IPT_IPV4OPTION_DONT_MATCH_ANY_OPT)))
12832 +               return 0; /* opposites */
12833 +       if (((info->options & IPT_IPV4OPTION_DONT_MATCH_ANY_OPT) == IPT_IPV4OPTION_DONT_MATCH_ANY_OPT) &&
12834 +           (((info->options & IPT_IPV4OPTION_MATCH_LSRR) == IPT_IPV4OPTION_MATCH_LSRR) ||
12835 +            ((info->options & IPT_IPV4OPTION_MATCH_SSRR) == IPT_IPV4OPTION_MATCH_SSRR) ||
12836 +            ((info->options & IPT_IPV4OPTION_MATCH_RR) == IPT_IPV4OPTION_MATCH_RR) ||
12837 +            ((info->options & IPT_IPV4OPTION_MATCH_TIMESTAMP) == IPT_IPV4OPTION_MATCH_TIMESTAMP) ||
12838 +            ((info->options & IPT_IPV4OPTION_MATCH_ROUTER_ALERT) == IPT_IPV4OPTION_MATCH_ROUTER_ALERT) ||
12839 +            ((info->options & IPT_IPV4OPTION_MATCH_ANY_OPT) == IPT_IPV4OPTION_MATCH_ANY_OPT)))
12840 +               return 0; /* opposites */
12841 +       if (((info->options & IPT_IPV4OPTION_MATCH_SSRR) == IPT_IPV4OPTION_MATCH_SSRR) &&
12842 +           ((info->options & IPT_IPV4OPTION_MATCH_LSRR) == IPT_IPV4OPTION_MATCH_LSRR))
12843 +               return 0; /* cannot match in the same time loose and strict source routing */
12844 +       if ((((info->options & IPT_IPV4OPTION_MATCH_SSRR) == IPT_IPV4OPTION_MATCH_SSRR) ||
12845 +            ((info->options & IPT_IPV4OPTION_MATCH_LSRR) == IPT_IPV4OPTION_MATCH_LSRR)) &&
12846 +           ((info->options & IPT_IPV4OPTION_DONT_MATCH_SRR) == IPT_IPV4OPTION_DONT_MATCH_SRR))
12847 +               return 0; /* opposites */
12848 +       if (((info->options & IPT_IPV4OPTION_MATCH_RR) == IPT_IPV4OPTION_MATCH_RR) &&
12849 +           ((info->options & IPT_IPV4OPTION_DONT_MATCH_RR) == IPT_IPV4OPTION_DONT_MATCH_RR))
12850 +               return 0; /* opposites */
12851 +       if (((info->options & IPT_IPV4OPTION_MATCH_TIMESTAMP) == IPT_IPV4OPTION_MATCH_TIMESTAMP) &&
12852 +           ((info->options & IPT_IPV4OPTION_DONT_MATCH_TIMESTAMP) == IPT_IPV4OPTION_DONT_MATCH_TIMESTAMP))
12853 +               return 0; /* opposites */
12854 +       if (((info->options & IPT_IPV4OPTION_MATCH_ROUTER_ALERT) == IPT_IPV4OPTION_MATCH_ROUTER_ALERT) &&
12855 +           ((info->options & IPT_IPV4OPTION_DONT_MATCH_ROUTER_ALERT) == IPT_IPV4OPTION_DONT_MATCH_ROUTER_ALERT))
12856 +               return 0; /* opposites */
12857 +
12858 +       /* everything looks ok. */
12859 +       return 1;
12860 +}
12861 +
12862 +static struct ipt_match ipv4options_match = { 
12863 +       .name = "ipv4options",
12864 +       .match = match,
12865 +       .checkentry = checkentry,
12866 +       .me = THIS_MODULE
12867 +};
12868 +
12869 +static int __init init(void)
12870 +{
12871 +       return ipt_register_match(&ipv4options_match);
12872 +}
12873 +
12874 +static void __exit fini(void)
12875 +{
12876 +       ipt_unregister_match(&ipv4options_match);
12877 +}
12878 +
12879 +module_init(init);
12880 +module_exit(fini);
12881 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_mport.c linux-2.6.6/net/ipv4/netfilter/ipt_mport.c
12882 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_mport.c      1970-01-01 01:00:00.000000000 +0100
12883 +++ linux-2.6.6/net/ipv4/netfilter/ipt_mport.c  2004-05-18 14:28:50.000000000 +0200
12884 @@ -0,0 +1,116 @@
12885 +/* Kernel module to match one of a list of TCP/UDP ports: ports are in
12886 +   the same place so we can treat them as equal. */
12887 +#include <linux/module.h>
12888 +#include <linux/types.h>
12889 +#include <linux/udp.h>
12890 +#include <linux/skbuff.h>
12891 +
12892 +#include <linux/netfilter_ipv4/ipt_mport.h>
12893 +#include <linux/netfilter_ipv4/ip_tables.h>
12894 +
12895 +MODULE_LICENSE("GPL");
12896 +
12897 +#if 0
12898 +#define duprintf(format, args...) printk(format , ## args)
12899 +#else
12900 +#define duprintf(format, args...)
12901 +#endif
12902 +
12903 +/* Returns 1 if the port is matched by the test, 0 otherwise. */
12904 +static inline int
12905 +ports_match(const struct ipt_mport *minfo, u_int16_t src, u_int16_t dst)
12906 +{
12907 +       unsigned int i;
12908 +        unsigned int m;
12909 +        u_int16_t pflags = minfo->pflags;
12910 +       for (i=0, m=1; i<IPT_MULTI_PORTS; i++, m<<=1) {
12911 +                u_int16_t s, e;
12912 +
12913 +                if (pflags & m
12914 +                    && minfo->ports[i] == 65535)
12915 +                        return 0;
12916 +
12917 +                s = minfo->ports[i];
12918 +
12919 +                if (pflags & m) {
12920 +                        e = minfo->ports[++i];
12921 +                        m <<= 1;
12922 +                } else
12923 +                        e = s;
12924 +
12925 +                if (minfo->flags & IPT_MPORT_SOURCE
12926 +                    && src >= s && src <= e)
12927 +                        return 1;
12928 +
12929 +               if (minfo->flags & IPT_MPORT_DESTINATION
12930 +                   && dst >= s && dst <= e)
12931 +                       return 1;
12932 +       }
12933 +
12934 +       return 0;
12935 +}
12936 +
12937 +static int
12938 +match(const struct sk_buff *skb,
12939 +      const struct net_device *in,
12940 +      const struct net_device *out,
12941 +      const void *matchinfo,
12942 +      int offset,
12943 +      int *hotdrop)
12944 +{
12945 +       u16 ports[2];
12946 +       const struct ipt_mport *minfo = matchinfo;
12947 +
12948 +       if (offset)
12949 +               return 0;
12950 +
12951 +       /* Must be big enough to read ports (both UDP and TCP have
12952 +           them at the start). */
12953 +       if (skb_copy_bits(skb, skb->nh.iph->ihl*4, ports, sizeof(ports)) < 0) {
12954 +               /* We've been asked to examine this packet, and we
12955 +                  can't.  Hence, no choice but to drop. */
12956 +                       duprintf("ipt_multiport:"
12957 +                                " Dropping evil offset=0 tinygram.\n");
12958 +                       *hotdrop = 1;
12959 +                       return 0;
12960 +       }
12961 +
12962 +       return ports_match(minfo, ntohs(ports[0]), ntohs(ports[1]));
12963 +}
12964 +
12965 +/* Called when user tries to insert an entry of this type. */
12966 +static int
12967 +checkentry(const char *tablename,
12968 +          const struct ipt_ip *ip,
12969 +          void *matchinfo,
12970 +          unsigned int matchsize,
12971 +          unsigned int hook_mask)
12972 +{
12973 +       if (matchsize != IPT_ALIGN(sizeof(struct ipt_mport)))
12974 +               return 0;
12975 +
12976 +       /* Must specify proto == TCP/UDP, no unknown flags or bad count */
12977 +       return (ip->proto == IPPROTO_TCP || ip->proto == IPPROTO_UDP)
12978 +               && !(ip->invflags & IPT_INV_PROTO)
12979 +               && matchsize == IPT_ALIGN(sizeof(struct ipt_mport));
12980 +}
12981 +
12982 +static struct ipt_match mport_match = { 
12983 +       .name = "mport",
12984 +       .match = &match,
12985 +       .checkentry = &checkentry,
12986 +       .me = THIS_MODULE
12987 +};
12988 +
12989 +static int __init init(void)
12990 +{
12991 +       return ipt_register_match(&mport_match);
12992 +}
12993 +
12994 +static void __exit fini(void)
12995 +{
12996 +       ipt_unregister_match(&mport_match);
12997 +}
12998 +
12999 +module_init(init);
13000 +module_exit(fini);
13001 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_nth.c linux-2.6.6/net/ipv4/netfilter/ipt_nth.c
13002 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_nth.c        1970-01-01 01:00:00.000000000 +0100
13003 +++ linux-2.6.6/net/ipv4/netfilter/ipt_nth.c    2004-05-18 14:28:50.000000000 +0200
13004 @@ -0,0 +1,166 @@
13005 +/*
13006 +  This is a module which is used for match support for every Nth packet
13007 +  This file is distributed under the terms of the GNU General Public
13008 +  License (GPL). Copies of the GPL can be obtained from:
13009 +     ftp://prep.ai.mit.edu/pub/gnu/GPL
13010 +
13011 +  2001-07-18 Fabrice MARIE <fabrice@netfilter.org> : initial implementation.
13012 +  2001-09-20 Richard Wagner (rwagner@cloudnet.com)
13013 +        * added support for multiple counters
13014 +        * added support for matching on individual packets
13015 +          in the counter cycle
13016 +  2004-02-19 Harald Welte <laforge@netfilter.org>
13017 +       * port to 2.6.x
13018 +
13019 +*/
13020 +
13021 +#include <linux/module.h>
13022 +#include <linux/skbuff.h>
13023 +#include <linux/ip.h>
13024 +#include <net/tcp.h>
13025 +#include <linux/spinlock.h>
13026 +#include <linux/netfilter_ipv4/ip_tables.h>
13027 +#include <linux/netfilter_ipv4/ipt_nth.h>
13028 +
13029 +MODULE_LICENSE("GPL");
13030 +MODULE_AUTHOR("Fabrice Marie <fabrice@netfilter.org>");
13031 +
13032 +/*
13033 + * State information.
13034 + */
13035 +struct state {
13036 +       spinlock_t lock;
13037 +       u_int16_t number;
13038 +};
13039 +
13040 +static struct state states[IPT_NTH_NUM_COUNTERS];
13041 +
13042 +static int
13043 +ipt_nth_match(const struct sk_buff *pskb,
13044 +             const struct net_device *in,
13045 +             const struct net_device *out,
13046 +             const void *matchinfo,
13047 +             int offset,
13048 +             int *hotdrop)
13049 +{
13050 +       /* Parameters from userspace */
13051 +       const struct ipt_nth_info *info = matchinfo;
13052 +        unsigned counter = info->counter;
13053 +               if((counter < 0) || (counter >= IPT_NTH_NUM_COUNTERS)) 
13054 +       {
13055 +                       printk(KERN_WARNING "nth: invalid counter %u. counter between 0 and %u\n", counter, IPT_NTH_NUM_COUNTERS-1);
13056 +               return 0;
13057 +        };
13058 +
13059 +        spin_lock(&states[counter].lock);
13060 +
13061 +        /* Are we matching every nth packet?*/
13062 +        if (info->packet == 0xFF)
13063 +        {
13064 +               /* We're matching every nth packet and only every nth packet*/
13065 +               /* Do we match or invert match? */
13066 +               if (info->not == 0)
13067 +               {
13068 +                       if (states[counter].number == 0)
13069 +                       {
13070 +                               ++states[counter].number;
13071 +                               goto match;
13072 +                       }
13073 +                       if (states[counter].number >= info->every)
13074 +                               states[counter].number = 0; /* reset the counter */
13075 +                       else
13076 +                               ++states[counter].number;
13077 +                       goto dontmatch;
13078 +               }
13079 +               else
13080 +               {
13081 +                       if (states[counter].number == 0)
13082 +                       {
13083 +                               ++states[counter].number;
13084 +                               goto dontmatch;
13085 +                       }
13086 +                       if (states[counter].number >= info->every)
13087 +                               states[counter].number = 0;
13088 +                       else
13089 +                               ++states[counter].number;
13090 +                       goto match;
13091 +               }
13092 +        }
13093 +        else
13094 +        {
13095 +               /* We're using the --packet, so there must be a rule for every value */
13096 +               if (states[counter].number == info->packet)
13097 +               {
13098 +                       /* only increment the counter when a match happens */
13099 +                       if (states[counter].number >= info->every)
13100 +                               states[counter].number = 0; /* reset the counter */
13101 +                       else
13102 +                               ++states[counter].number;
13103 +                       goto match;
13104 +               }
13105 +               else
13106 +                       goto dontmatch;
13107 +       }
13108 +
13109 + dontmatch:
13110 +       /* don't match */
13111 +       spin_unlock(&states[counter].lock);
13112 +       return 0;
13113 +
13114 + match:
13115 +       spin_unlock(&states[counter].lock);
13116 +       return 1;
13117 +}
13118 +
13119 +static int
13120 +ipt_nth_checkentry(const char *tablename,
13121 +                  const struct ipt_ip *e,
13122 +                  void *matchinfo,
13123 +                  unsigned int matchsize,
13124 +                  unsigned int hook_mask)
13125 +{
13126 +       /* Parameters from userspace */
13127 +       const struct ipt_nth_info *info = matchinfo;
13128 +        unsigned counter = info->counter;
13129 +        if((counter < 0) || (counter >= IPT_NTH_NUM_COUNTERS)) 
13130 +       {
13131 +               printk(KERN_WARNING "nth: invalid counter %u. counter between 0 and %u\n", counter, IPT_NTH_NUM_COUNTERS-1);
13132 +                       return 0;
13133 +               };
13134 +
13135 +       if (matchsize != IPT_ALIGN(sizeof(struct ipt_nth_info))) {
13136 +               printk("nth: matchsize %u != %u\n", matchsize,
13137 +                      IPT_ALIGN(sizeof(struct ipt_nth_info)));
13138 +               return 0;
13139 +       }
13140 +
13141 +       states[counter].number = info->startat;
13142 +
13143 +       return 1;
13144 +}
13145 +
13146 +static struct ipt_match ipt_nth_reg = { 
13147 +       .name = "nth",
13148 +       .match = ipt_nth_match,
13149 +       .checkentry = ipt_nth_checkentry,
13150 +       .me = THIS_MODULE
13151 +};
13152 +
13153 +static int __init init(void)
13154 +{
13155 +       unsigned counter;
13156 +
13157 +       memset(&states, 0, sizeof(states));
13158 +        for (counter = 0; counter < IPT_NTH_NUM_COUNTERS; counter++) 
13159 +               spin_lock_init(&(states[counter].lock));
13160 +
13161 +       return ipt_register_match(&ipt_nth_reg);
13162 +}
13163 +
13164 +static void __exit fini(void)
13165 +{
13166 +       ipt_unregister_match(&ipt_nth_reg);
13167 +}
13168 +
13169 +module_init(init);
13170 +module_exit(fini);
13171 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_osf.c linux-2.6.6/net/ipv4/netfilter/ipt_osf.c
13172 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_osf.c        1970-01-01 01:00:00.000000000 +0100
13173 +++ linux-2.6.6/net/ipv4/netfilter/ipt_osf.c    2004-05-18 14:28:50.000000000 +0200
13174 @@ -0,0 +1,865 @@
13175 +/*
13176 + * ipt_osf.c
13177 + *
13178 + * Copyright (c) 2003 Evgeniy Polyakov <johnpol@2ka.mipt.ru>
13179 + *
13180 + *
13181 + * This program is free software; you can redistribute it and/or modify
13182 + * it under the terms of the GNU General Public License as published by
13183 + * the Free Software Foundation; either version 2 of the License, or
13184 + * (at your option) any later version.
13185 + *
13186 + * This program is distributed in the hope that it will be useful,
13187 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13188 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13189 + * GNU General Public License for more details.
13190 + *
13191 + * You should have received a copy of the GNU General Public License
13192 + * along with this program; if not, write to the Free Software
13193 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
13194 + */
13195 +
13196 +/*
13197 + * OS fingerprint matching module.
13198 + * It simply compares various parameters from SYN packet with
13199 + * some hardcoded ones.
13200 + *
13201 + * Original table was created by Michal Zalewski <lcamtuf@coredump.cx>
13202 + * for his p0f.
13203 + */
13204 +
13205 +#include <linux/config.h>
13206 +#include <linux/kernel.h>
13207 +#include <linux/types.h>
13208 +#include <linux/string.h>
13209 +#include <linux/smp.h>
13210 +#include <linux/module.h>
13211 +#include <linux/skbuff.h>
13212 +#include <linux/file.h>
13213 +#include <linux/ip.h>
13214 +#include <linux/proc_fs.h>
13215 +#include <linux/fs.h>
13216 +#include <linux/slab.h>
13217 +#include <linux/spinlock.h>
13218 +#include <linux/ctype.h>
13219 +#include <linux/list.h>
13220 +#include <linux/if.h>
13221 +
13222 +#include <net/sock.h>
13223 +#include <net/ip.h>
13224 +
13225 +#include <linux/netfilter_ipv4/ip_tables.h>
13226 +
13227 +#include <linux/netfilter_ipv4/ipt_osf.h>
13228 +
13229 +#define OSF_DEBUG
13230 +
13231 +#ifdef OSF_DEBUG
13232 +#define log(x...)              printk(KERN_INFO "ipt_osf: " x)
13233 +#define loga(x...)             printk(x)
13234 +#else
13235 +#define log(x...)              do {} while(0)
13236 +#define loga(x...)             do {} while(0)
13237 +#endif
13238 +
13239 +#define FMATCH_WRONG           0
13240 +#define FMATCH_OK              1
13241 +#define FMATCH_OPT_WRONG       2
13242 +
13243 +#define OPTDEL                 ','
13244 +#define OSFPDEL                ':'
13245 +#define MAXOPTSTRLEN           128
13246 +#define OSFFLUSH               "FLUSH"
13247 +
13248 +static rwlock_t osf_lock = RW_LOCK_UNLOCKED;
13249 +static spinlock_t ipt_osf_netlink_lock = SPIN_LOCK_UNLOCKED;
13250 +static struct list_head        finger_list;    
13251 +static int match(const struct sk_buff *, const struct net_device *, const struct net_device *,
13252 +                     const void *, int, 
13253 +                     const void *, u_int16_t, 
13254 +                     int *);
13255 +static int checkentry(const char *, const struct ipt_ip *, void *,
13256 +                          unsigned int, unsigned int);
13257 +
13258 +static unsigned long seq, ipt_osf_groups = 1;
13259 +static struct sock *nts;
13260 +
13261 +static struct ipt_match osf_match = 
13262 +{ 
13263 +       { NULL, NULL }, 
13264 +       "osf", 
13265 +       &match, 
13266 +       &checkentry, 
13267 +       NULL, 
13268 +       THIS_MODULE 
13269 +};
13270 +
13271 +static void ipt_osf_nlsend(struct osf_finger *f, const struct sk_buff *sk)
13272 +{
13273 +       unsigned int size;
13274 +       struct sk_buff *skb;
13275 +       struct ipt_osf_nlmsg *data;
13276 +       struct nlmsghdr *nlh;
13277 +
13278 +       size = NLMSG_SPACE(sizeof(struct ipt_osf_nlmsg));
13279 +
13280 +       skb = alloc_skb(size, GFP_ATOMIC);
13281 +       if (!skb)
13282 +       {
13283 +               log("skb_alloc() failed.\n");
13284 +               return;
13285 +       }
13286 +       
13287 +       nlh = NLMSG_PUT(skb, 0, seq++, NLMSG_DONE, size - sizeof(*nlh));
13288 +       
13289 +       data = (struct ipt_osf_nlmsg *)NLMSG_DATA(nlh);
13290 +
13291 +       memcpy(&data->f, f, sizeof(struct osf_finger));
13292 +       memcpy(&data->ip, sk->nh.iph, sizeof(struct iphdr));
13293 +       memcpy(&data->tcp, (struct tcphdr *)((u_int32_t *)sk->nh.iph + sk->nh.iph->ihl), sizeof(struct tcphdr));
13294 +
13295 +       NETLINK_CB(skb).dst_groups = ipt_osf_groups;
13296 +       netlink_broadcast(nts, skb, 0, ipt_osf_groups, GFP_ATOMIC);
13297 +
13298 +nlmsg_failure:
13299 +       return;
13300 +}
13301 +
13302 +static inline int smart_dec(const struct sk_buff *skb, unsigned long flags, unsigned char f_ttl)
13303 +{
13304 +       struct iphdr *ip = skb->nh.iph;
13305 +
13306 +       if (flags & IPT_OSF_SMART)
13307 +       {
13308 +               struct in_device *in_dev = in_dev_get(skb->dev);
13309 +
13310 +               for_ifa(in_dev)
13311 +               {
13312 +                       if (inet_ifa_match(ip->saddr, ifa))
13313 +                       {
13314 +                               in_dev_put(in_dev);
13315 +                               return (ip->ttl == f_ttl);
13316 +                       }
13317 +               }
13318 +               endfor_ifa(in_dev);
13319 +               
13320 +               in_dev_put(in_dev);
13321 +               return (ip->ttl <= f_ttl);
13322 +       }
13323 +       else
13324 +               return (ip->ttl == f_ttl);
13325 +}
13326 +
13327 +static int
13328 +match(const struct sk_buff *skb, const struct net_device *in, const struct net_device *out,
13329 +      const void *matchinfo, int offset,
13330 +      const void *hdr, u_int16_t datalen,
13331 +      int *hotdrop)
13332 +{
13333 +       struct ipt_osf_info *info = (struct ipt_osf_info *)matchinfo;
13334 +       struct iphdr *ip = skb->nh.iph;
13335 +       struct tcphdr *tcp;
13336 +       int fmatch = FMATCH_WRONG, fcount = 0;
13337 +       unsigned long totlen, optsize = 0, window;
13338 +       unsigned char df, *optp = NULL, *_optp = NULL;
13339 +       char check_WSS = 0;
13340 +       struct list_head *ent;
13341 +       struct osf_finger *f;
13342 +
13343 +       if (!ip || !info)
13344 +               return 0;
13345 +                               
13346 +       tcp = (struct tcphdr *)((u_int32_t *)ip + ip->ihl);
13347 +
13348 +       if (!tcp->syn)
13349 +               return 0;
13350 +       
13351 +       totlen = ntohs(ip->tot_len);
13352 +       df = ((ntohs(ip->frag_off) & IP_DF)?1:0);
13353 +       window = ntohs(tcp->window);
13354 +       
13355 +       if (tcp->doff*4 > sizeof(struct tcphdr))
13356 +       {
13357 +               _optp = optp = (char *)(tcp+1);
13358 +               optsize = tcp->doff*4 - sizeof(struct tcphdr);
13359 +       }
13360 +
13361 +       
13362 +       /* Actually we can create hash/table of all genres and search
13363 +        * only in appropriate part, but here is initial variant,
13364 +        * so will use slow path.
13365 +        */
13366 +       read_lock(&osf_lock);
13367 +       list_for_each(ent, &finger_list)
13368 +       {
13369 +               f = list_entry(ent, struct osf_finger, flist);
13370 +       
13371 +               if (!(info->flags & IPT_OSF_LOG) && strcmp(info->genre, f->genre)) 
13372 +                       continue;
13373 +
13374 +               optp = _optp;
13375 +               fmatch = FMATCH_WRONG;
13376 +
13377 +               if (totlen == f->ss && df == f->df && 
13378 +                       smart_dec(skb, info->flags, f->ttl))
13379 +               {
13380 +                       unsigned long foptsize;
13381 +                       int optnum;
13382 +                       unsigned short mss = 0;
13383 +
13384 +                       check_WSS = 0;
13385 +
13386 +                       switch (f->wss.wc)
13387 +                       {
13388 +                               case 0:   check_WSS = 0; break;
13389 +                               case 'S': check_WSS = 1; break;
13390 +                               case 'T': check_WSS = 2; break;
13391 +                               case '%': check_WSS = 3; break;
13392 +                               default: log("Wrong fingerprint wss.wc=%d, %s - %s\n", 
13393 +                                                        f->wss.wc, f->genre, f->details);
13394 +                                        check_WSS = 4;
13395 +                                        break;
13396 +                       }
13397 +                       if (check_WSS == 4)
13398 +                               continue;
13399 +
13400 +                       /* Check options */
13401 +
13402 +                       foptsize = 0;
13403 +                       for (optnum=0; optnum<f->opt_num; ++optnum)
13404 +                               foptsize += f->opt[optnum].length;
13405 +
13406 +                               
13407 +                       if (foptsize > MAX_IPOPTLEN || optsize > MAX_IPOPTLEN || optsize != foptsize)
13408 +                               continue;
13409 +
13410 +                       if (!optp)
13411 +                       {
13412 +                               fmatch = FMATCH_OK;
13413 +                               loga("\tYEP : matching without options.\n");
13414 +                               if ((info->flags & IPT_OSF_LOG) && 
13415 +                                       info->loglevel == IPT_OSF_LOGLEVEL_FIRST)
13416 +                                       break;
13417 +                               else
13418 +                                       continue;
13419 +                       }
13420 +                       
13421 +
13422 +                       for (optnum=0; optnum<f->opt_num; ++optnum)
13423 +                       {
13424 +                               if (f->opt[optnum].kind == (*optp)) 
13425 +                               {
13426 +                                       unsigned char len = f->opt[optnum].length;
13427 +                                       unsigned char *optend = optp + len;
13428 +                                       int loop_cont = 0;
13429 +
13430 +                                       fmatch = FMATCH_OK;
13431 +
13432 +
13433 +                                       switch (*optp)
13434 +                                       {
13435 +                                               case OSFOPT_MSS:
13436 +                                                       mss = ntohs(*(unsigned short *)(optp+2));
13437 +                                                       break;
13438 +                                               case OSFOPT_TS:
13439 +                                                       loop_cont = 1;
13440 +                                                       break;
13441 +                                       }
13442 +                                       
13443 +                                       if (loop_cont)
13444 +                                       {
13445 +                                               optp = optend;
13446 +                                               continue;
13447 +                                       }
13448 +                                       
13449 +                                       if (len != 1)
13450 +                                       {
13451 +                                               /* Skip kind and length fields*/
13452 +                                               optp += 2; 
13453 +
13454 +                                               if (f->opt[optnum].wc.val != 0)
13455 +                                               {
13456 +                                                       unsigned long tmp = 0;
13457 +                                                       
13458 +                                                       /* Hmmm... It looks a bit ugly. :) */
13459 +                                                       memcpy(&tmp, optp, 
13460 +                                                               (len > sizeof(unsigned long)?
13461 +                                                                       sizeof(unsigned long):len));
13462 +                                                       /* 2 + 2: optlen(2 bytes) + 
13463 +                                                        *      kind(1 byte) + length(1 byte) */
13464 +                                                       if (len == 4) 
13465 +                                                               tmp = ntohs(tmp);
13466 +                                                       else
13467 +                                                               tmp = ntohl(tmp);
13468 +
13469 +                                                       if (f->opt[optnum].wc.wc == '%')
13470 +                                                       {
13471 +                                                               if ((tmp % f->opt[optnum].wc.val) != 0)
13472 +                                                                       fmatch = FMATCH_OPT_WRONG;
13473 +                                                       }
13474 +                                                       else if (tmp != f->opt[optnum].wc.val)
13475 +                                                               fmatch = FMATCH_OPT_WRONG;
13476 +                                               }
13477 +                                       }
13478 +
13479 +                                       optp = optend;
13480 +                               }
13481 +                               else
13482 +                                       fmatch = FMATCH_OPT_WRONG;
13483 +
13484 +                               if (fmatch != FMATCH_OK)
13485 +                                       break;
13486 +                       }
13487 +
13488 +                       if (fmatch != FMATCH_OPT_WRONG)
13489 +                       {
13490 +                               fmatch = FMATCH_WRONG;
13491 +
13492 +                               switch (check_WSS)
13493 +                               {
13494 +                                       case 0:
13495 +                                               if (f->wss.val == 0 || window == f->wss.val)
13496 +                                                       fmatch = FMATCH_OK;
13497 +                                               break;
13498 +                                       case 1: /* MSS */
13499 +/* Lurked in OpenBSD */
13500 +#define SMART_MSS      1460
13501 +                                               if (window == f->wss.val*mss || 
13502 +                                                       window == f->wss.val*SMART_MSS)
13503 +                                                       fmatch = FMATCH_OK;
13504 +                                               break;
13505 +                                       case 2: /* MTU */
13506 +                                               if (window == f->wss.val*(mss+40) ||
13507 +                                                       window == f->wss.val*(SMART_MSS+40))
13508 +                                                       fmatch = FMATCH_OK;
13509 +                                               break;
13510 +                                       case 3: /* MOD */
13511 +                                               if ((window % f->wss.val) == 0)
13512 +                                                       fmatch = FMATCH_OK;
13513 +                                               break;
13514 +                               }
13515 +                       }
13516 +                                       
13517 +
13518 +                       if (fmatch == FMATCH_OK)
13519 +                       {
13520 +                               fcount++;
13521 +                               log("%s [%s:%s:%s] : %u.%u.%u.%u:%u -> %u.%u.%u.%u:%u hops=%d\n", 
13522 +                                       f->genre, f->version,
13523 +                                       f->subtype, f->details,
13524 +                                       NIPQUAD(ip->saddr), ntohs(tcp->source),
13525 +                                       NIPQUAD(ip->daddr), ntohs(tcp->dest),
13526 +                                       f->ttl - ip->ttl);
13527 +                               if (info->flags & IPT_OSF_NETLINK)
13528 +                               {
13529 +                                       spin_lock_bh(&ipt_osf_netlink_lock);
13530 +                                       ipt_osf_nlsend(f, skb);
13531 +                                       spin_unlock_bh(&ipt_osf_netlink_lock);
13532 +                               }
13533 +                               if ((info->flags & IPT_OSF_LOG) && 
13534 +                                       info->loglevel == IPT_OSF_LOGLEVEL_FIRST)
13535 +                                       break;
13536 +                       }
13537 +               }
13538 +       }
13539 +       if (!fcount && (info->flags & (IPT_OSF_LOG | IPT_OSF_NETLINK)))
13540 +       {
13541 +               unsigned char opt[4 * 15 - sizeof(struct tcphdr)];
13542 +               unsigned int i, optsize;
13543 +               struct osf_finger fg;
13544 +
13545 +               memset(&fg, 0, sizeof(fg));
13546 +
13547 +               if ((info->flags & IPT_OSF_LOG))
13548 +                       log("Unknown: %lu:%d:%d:%lu:", window, ip->ttl, df, totlen);
13549 +               if (optp)
13550 +               {
13551 +                       optsize = tcp->doff * 4 - sizeof(struct tcphdr);
13552 +                       if (skb_copy_bits(skb, ip->ihl*4 + sizeof(struct tcphdr),
13553 +                                         opt, optsize) < 0)
13554 +                       {
13555 +                               if (info->flags & IPT_OSF_LOG)
13556 +                                       loga("TRUNCATED");
13557 +                               if (info->flags & IPT_OSF_NETLINK)
13558 +                                       strcpy(fg.details, "TRUNCATED");
13559 +                       }
13560 +                       else
13561 +                       {
13562 +                               for (i = 0; i < optsize; i++)
13563 +                               {
13564 +                                       if (info->flags & IPT_OSF_LOG)
13565 +                                               loga("%02X", opt[i]);
13566 +                               }
13567 +                               if (info->flags & IPT_OSF_NETLINK)
13568 +                                       memcpy(fg.details, opt, MAXDETLEN);
13569 +                       }
13570 +               }
13571 +               if ((info->flags & IPT_OSF_LOG))
13572 +                       loga(" %u.%u.%u.%u:%u -> %u.%u.%u.%u:%u\n", 
13573 +                               NIPQUAD(ip->saddr), ntohs(tcp->source),
13574 +                               NIPQUAD(ip->daddr), ntohs(tcp->dest));
13575 +               
13576 +               if (info->flags & IPT_OSF_NETLINK)
13577 +               {
13578 +                       fg.wss.val      = window;
13579 +                       fg.ttl          = ip->ttl;
13580 +                       fg.df           = df;
13581 +                       fg.ss           = totlen;
13582 +                       strncpy(fg.genre, "Unknown", MAXGENRELEN);
13583 +
13584 +                       spin_lock_bh(&ipt_osf_netlink_lock);
13585 +                       ipt_osf_nlsend(&fg, skb);
13586 +                       spin_unlock_bh(&ipt_osf_netlink_lock);
13587 +               }
13588 +       }
13589 +
13590 +       read_unlock(&osf_lock);
13591 +
13592 +       return (fmatch == FMATCH_OK)?1:0;
13593 +}
13594 +
13595 +static int
13596 +checkentry(const char *tablename,
13597 +           const struct ipt_ip *ip,
13598 +           void *matchinfo,
13599 +           unsigned int matchsize,
13600 +           unsigned int hook_mask)
13601 +{
13602 +       if (matchsize != IPT_ALIGN(sizeof(struct ipt_osf_info)))
13603 +               return 0;
13604 +       if (ip->proto != IPPROTO_TCP)
13605 +              return 0;
13606 +
13607 +       return 1;
13608 +}
13609 +
13610 +static char * osf_strchr(char *ptr, char c)
13611 +{
13612 +       char *tmp;
13613 +
13614 +       tmp = strchr(ptr, c);
13615 +
13616 +       while (tmp && tmp+1 && isspace(*(tmp+1)))
13617 +               tmp++;
13618 +
13619 +       return tmp;
13620 +}
13621 +
13622 +static struct osf_finger * finger_alloc(void)
13623 +{
13624 +       struct osf_finger *f;
13625 +
13626 +       f = kmalloc(sizeof(struct osf_finger), GFP_KERNEL);
13627 +       if (f)
13628 +               memset(f, 0, sizeof(struct osf_finger));
13629 +       
13630 +       return f;
13631 +}
13632 +
13633 +static void finger_free(struct osf_finger *f)
13634 +{
13635 +       memset(f, 0, sizeof(struct osf_finger));
13636 +       kfree(f);
13637 +}
13638 +
13639 +
13640 +static void osf_parse_opt(struct osf_opt *opt, int *optnum, char *obuf, int olen)
13641 +{
13642 +       int i, op;
13643 +       char *ptr, wc;
13644 +       unsigned long val;
13645 +
13646 +       ptr = &obuf[0];
13647 +       i = 0;
13648 +       while (ptr != NULL && i < olen)
13649 +       {
13650 +               val = 0;
13651 +               op = 0;
13652 +               wc = 0;
13653 +               switch (obuf[i])
13654 +               {
13655 +                       case 'N': 
13656 +                               op = OSFOPT_NOP;
13657 +                               ptr = osf_strchr(&obuf[i], OPTDEL);
13658 +                               if (ptr)
13659 +                               {
13660 +                                       *ptr = '\0';
13661 +                                       ptr++;
13662 +                                       i += (int)(ptr-&obuf[i]);
13663 +
13664 +                               }
13665 +                               else
13666 +                                       i++;
13667 +                               break;
13668 +                       case 'S': 
13669 +                               op = OSFOPT_SACKP;
13670 +                               ptr = osf_strchr(&obuf[i], OPTDEL);
13671 +                               if (ptr)
13672 +                               {
13673 +                                       *ptr = '\0';
13674 +                                       ptr++;
13675 +                                       i += (int)(ptr-&obuf[i]);
13676 +
13677 +                               }
13678 +                               else
13679 +                                       i++;
13680 +                               break;
13681 +                       case 'T': 
13682 +                               op = OSFOPT_TS;
13683 +                               ptr = osf_strchr(&obuf[i], OPTDEL);
13684 +                               if (ptr)
13685 +                               {
13686 +                                       *ptr = '\0';
13687 +                                       ptr++;
13688 +                                       i += (int)(ptr-&obuf[i]);
13689 +
13690 +                               }
13691 +                               else
13692 +                                       i++;
13693 +                               break;
13694 +                       case 'W': 
13695 +                               op = OSFOPT_WSO;
13696 +                               ptr = osf_strchr(&obuf[i], OPTDEL);
13697 +                               if (ptr)
13698 +                               {
13699 +                                       switch (obuf[i+1])
13700 +                                       {
13701 +                                               case '%':       wc = '%'; break;
13702 +                                               case 'S':       wc = 'S'; break;
13703 +                                               case 'T':       wc = 'T'; break;
13704 +                                               default:        wc = 0; break;
13705 +                                       }
13706 +                                       
13707 +                                       *ptr = '\0';
13708 +                                       ptr++;
13709 +                                       if (wc)
13710 +                                               val = simple_strtoul(&obuf[i+2], NULL, 10);
13711 +                                       else
13712 +                                               val = simple_strtoul(&obuf[i+1], NULL, 10);
13713 +                                       i += (int)(ptr-&obuf[i]);
13714 +
13715 +                               }
13716 +                               else
13717 +                                       i++;
13718 +                               break;
13719 +                       case 'M': 
13720 +                               op = OSFOPT_MSS;
13721 +                               ptr = osf_strchr(&obuf[i], OPTDEL);
13722 +                               if (ptr)
13723 +                               {
13724 +                                       if (obuf[i+1] == '%')
13725 +                                               wc = '%';
13726 +                                       *ptr = '\0';
13727 +                                       ptr++;
13728 +                                       if (wc)
13729 +                                               val = simple_strtoul(&obuf[i+2], NULL, 10);
13730 +                                       else
13731 +                                               val = simple_strtoul(&obuf[i+1], NULL, 10);
13732 +                                       i += (int)(ptr-&obuf[i]);
13733 +
13734 +                               }
13735 +                               else
13736 +                                       i++;
13737 +                               break;
13738 +                       case 'E': 
13739 +                               op = OSFOPT_EOL;
13740 +                               ptr = osf_strchr(&obuf[i], OPTDEL);
13741 +                               if (ptr)
13742 +                               {
13743 +                                       *ptr = '\0';
13744 +                                       ptr++;
13745 +                                       i += (int)(ptr-&obuf[i]);
13746 +
13747 +                               }
13748 +                               else
13749 +                                       i++;
13750 +                               break;
13751 +                       default:
13752 +                               ptr = osf_strchr(&obuf[i], OPTDEL);
13753 +                               if (ptr)
13754 +                               {
13755 +                                       ptr++;
13756 +                                       i += (int)(ptr-&obuf[i]);
13757 +
13758 +                               }
13759 +                               else
13760 +                                       i++;
13761 +                               break;
13762 +               }
13763 +
13764 +               opt[*optnum].kind       = IANA_opts[op].kind;
13765 +               opt[*optnum].length     = IANA_opts[op].length;
13766 +               opt[*optnum].wc.wc      = wc;
13767 +               opt[*optnum].wc.val     = val;
13768 +
13769 +               (*optnum)++;
13770 +       }
13771 +}
13772 +
13773 +static int osf_proc_read(char *buf, char **start, off_t off, int count, int *eof, void *data)
13774 +{
13775 +       struct list_head *ent;
13776 +       struct osf_finger *f = NULL;
13777 +       int i;
13778 +       
13779 +       *eof = 1;
13780 +       count = 0;
13781 +
13782 +       read_lock_bh(&osf_lock);
13783 +       list_for_each(ent, &finger_list)
13784 +       {
13785 +               f = list_entry(ent, struct osf_finger, flist);
13786 +
13787 +               log("%s [%s]", f->genre, f->details);
13788 +               
13789 +               count += sprintf(buf+count, "%s - %s[%s] : %s", 
13790 +                                       f->genre, f->version,
13791 +                                       f->subtype, f->details);
13792 +               
13793 +               if (f->opt_num)
13794 +               {
13795 +                       loga(" OPT: ");
13796 +                       //count += sprintf(buf+count, " OPT: ");
13797 +                       for (i=0; i<f->opt_num; ++i)
13798 +                       {
13799 +                               //count += sprintf(buf+count, "%d.%c%lu; ", 
13800 +                               //      f->opt[i].kind, (f->opt[i].wc.wc)?f->opt[i].wc.wc:' ', f->opt[i].wc.val);
13801 +                               loga("%d.%c%lu; ", 
13802 +                                       f->opt[i].kind, (f->opt[i].wc.wc)?f->opt[i].wc.wc:' ', f->opt[i].wc.val);
13803 +                       }
13804 +               }
13805 +               loga("\n");
13806 +               count += sprintf(buf+count, "\n");
13807 +       }
13808 +       read_unlock_bh(&osf_lock);
13809 +
13810 +       return count;
13811 +}
13812 +
13813 +static int osf_proc_write(struct file *file, const char *buffer, unsigned long count, void *data)
13814 +{
13815 +       int cnt;
13816 +       unsigned long i;
13817 +       char obuf[MAXOPTSTRLEN];
13818 +       struct osf_finger *finger;
13819 +       struct list_head *ent, *n;
13820 +
13821 +       char *pbeg, *pend;
13822 +
13823 +       if (count == strlen(OSFFLUSH) && !strncmp(buffer, OSFFLUSH, strlen(OSFFLUSH)))
13824 +       {
13825 +               int i = 0;
13826 +               write_lock_bh(&osf_lock);
13827 +               list_for_each_safe(ent, n, &finger_list)
13828 +               {
13829 +                       i++;
13830 +                       finger = list_entry(ent, struct osf_finger, flist);
13831 +                       list_del(&finger->flist);
13832 +                       finger_free(finger);
13833 +               }
13834 +               write_unlock_bh(&osf_lock);
13835 +       
13836 +               log("Flushed %d entries.\n", i);
13837 +               
13838 +               return count;
13839 +       }
13840 +
13841 +       
13842 +       cnt = 0;
13843 +       for (i=0; i<count && buffer[i] != '\0'; ++i)
13844 +               if (buffer[i] == ':')
13845 +                       cnt++;
13846 +
13847 +       if (cnt != 8 || i != count)
13848 +       {
13849 +               log("Wrong input line cnt=%d[8], len=%lu[%lu]\n", 
13850 +                       cnt, i, count);
13851 +               return count;
13852 +       }
13853 +
13854 +       memset(obuf, 0, sizeof(obuf));
13855 +       
13856 +       finger = finger_alloc();
13857 +       if (!finger)
13858 +       {
13859 +               log("Failed to allocate new fingerprint entry.\n");
13860 +               return -ENOMEM;
13861 +       }
13862 +
13863 +       pbeg = (char *)buffer;
13864 +       pend = osf_strchr(pbeg, OSFPDEL);
13865 +       if (pend)
13866 +       {
13867 +               *pend = '\0';
13868 +               if (pbeg[0] == 'S')
13869 +               {
13870 +                       finger->wss.wc = 'S';
13871 +                       if (pbeg[1] == '%')
13872 +                               finger->wss.val = simple_strtoul(pbeg+2, NULL, 10);
13873 +                       else if (pbeg[1] == '*')
13874 +                               finger->wss.val = 0;
13875 +                       else 
13876 +                               finger->wss.val = simple_strtoul(pbeg+1, NULL, 10);
13877 +               }
13878 +               else if (pbeg[0] == 'T')
13879 +               {
13880 +                       finger->wss.wc = 'T';
13881 +                       if (pbeg[1] == '%')
13882 +                               finger->wss.val = simple_strtoul(pbeg+2, NULL, 10);
13883 +                       else if (pbeg[1] == '*')
13884 +                               finger->wss.val = 0;
13885 +                       else 
13886 +                               finger->wss.val = simple_strtoul(pbeg+1, NULL, 10);
13887 +               }
13888 +               else if (pbeg[0] == '%')
13889 +               {
13890 +                       finger->wss.wc = '%';
13891 +                       finger->wss.val = simple_strtoul(pbeg+1, NULL, 10);
13892 +               }
13893 +               else if (isdigit(pbeg[0]))
13894 +               {
13895 +                       finger->wss.wc = 0;
13896 +                       finger->wss.val = simple_strtoul(pbeg, NULL, 10);
13897 +               }
13898 +
13899 +               pbeg = pend+1;
13900 +       }
13901 +       pend = osf_strchr(pbeg, OSFPDEL);
13902 +       if (pend)
13903 +       {
13904 +               *pend = '\0';
13905 +               finger->ttl = simple_strtoul(pbeg, NULL, 10);
13906 +               pbeg = pend+1;
13907 +       }
13908 +       pend = osf_strchr(pbeg, OSFPDEL);
13909 +       if (pend)
13910 +       {
13911 +               *pend = '\0';
13912 +               finger->df = simple_strtoul(pbeg, NULL, 10);
13913 +               pbeg = pend+1;
13914 +       }
13915 +       pend = osf_strchr(pbeg, OSFPDEL);
13916 +       if (pend)
13917 +       {
13918 +               *pend = '\0';
13919 +               finger->ss = simple_strtoul(pbeg, NULL, 10);
13920 +               pbeg = pend+1;
13921 +       }
13922 +
13923 +       pend = osf_strchr(pbeg, OSFPDEL);
13924 +       if (pend)
13925 +       {
13926 +               *pend = '\0';
13927 +               cnt = snprintf(obuf, sizeof(obuf), "%s", pbeg);
13928 +               pbeg = pend+1;
13929 +       }
13930 +
13931 +       pend = osf_strchr(pbeg, OSFPDEL);
13932 +       if (pend)
13933 +       {
13934 +               *pend = '\0';
13935 +               if (pbeg[0] == '@' || pbeg[0] == '*')
13936 +                       cnt = snprintf(finger->genre, sizeof(finger->genre), "%s", pbeg+1);
13937 +               else
13938 +                       cnt = snprintf(finger->genre, sizeof(finger->genre), "%s", pbeg);
13939 +               pbeg = pend+1;
13940 +       }
13941 +       
13942 +       pend = osf_strchr(pbeg, OSFPDEL);
13943 +       if (pend)
13944 +       {
13945 +               *pend = '\0';
13946 +               cnt = snprintf(finger->version, sizeof(finger->version), "%s", pbeg);
13947 +               pbeg = pend+1;
13948 +       }
13949 +       
13950 +       pend = osf_strchr(pbeg, OSFPDEL);
13951 +       if (pend)
13952 +       {
13953 +               *pend = '\0';
13954 +               cnt = snprintf(finger->subtype, sizeof(finger->subtype), "%s", pbeg);
13955 +               pbeg = pend+1;
13956 +       }
13957 +
13958 +       cnt = snprintf(finger->details, 
13959 +                       ((count - (pbeg - buffer)+1) > MAXDETLEN)?MAXDETLEN:(count - (pbeg - buffer)+1), 
13960 +                       "%s", pbeg);
13961 +       
13962 +       log("%s - %s[%s] : %s\n", 
13963 +               finger->genre, finger->version,
13964 +               finger->subtype, finger->details);
13965 +       
13966 +       osf_parse_opt(finger->opt, &finger->opt_num, obuf, sizeof(obuf));
13967 +       
13968 +
13969 +       write_lock_bh(&osf_lock);
13970 +       list_add_tail(&finger->flist, &finger_list);
13971 +       write_unlock_bh(&osf_lock);
13972 +
13973 +       return count;
13974 +}
13975 +
13976 +static int __init osf_init(void)
13977 +{
13978 +       int err;
13979 +       struct proc_dir_entry *p;
13980 +
13981 +       log("Startng OS fingerprint matching module.\n");
13982 +
13983 +       INIT_LIST_HEAD(&finger_list);
13984 +       
13985 +       err = ipt_register_match(&osf_match);
13986 +       if (err)
13987 +       {
13988 +               log("Failed to register OS fingerprint matching module.\n");
13989 +               return -ENXIO;
13990 +       }
13991 +
13992 +       p = create_proc_entry("sys/net/ipv4/osf", S_IFREG | 0644, NULL);
13993 +       if (!p)
13994 +       {
13995 +               ipt_unregister_match(&osf_match);
13996 +               return -ENXIO;
13997 +       }
13998 +
13999 +       p->write_proc = osf_proc_write;
14000 +       p->read_proc  = osf_proc_read;
14001 +       
14002 +       nts = netlink_kernel_create(NETLINK_NFLOG, NULL);
14003 +       if (!nts)
14004 +       {
14005 +               log("netlink_kernel_create() failed\n");
14006 +               remove_proc_entry("sys/net/ipv4/osf", NULL);
14007 +               ipt_unregister_match(&osf_match);
14008 +               return -ENOMEM;
14009 +       }
14010 +
14011 +       return 0;
14012 +}
14013 +
14014 +static void __exit osf_fini(void)
14015 +{
14016 +       struct list_head *ent, *n;
14017 +       struct osf_finger *f;
14018 +       
14019 +       remove_proc_entry("sys/net/ipv4/osf", NULL);
14020 +       ipt_unregister_match(&osf_match);
14021 +       if (nts && nts->sk_socket)
14022 +               sock_release(nts->sk_socket);
14023 +
14024 +       list_for_each_safe(ent, n, &finger_list)
14025 +       {
14026 +               f = list_entry(ent, struct osf_finger, flist);
14027 +               list_del(&f->flist);
14028 +               finger_free(f);
14029 +       }
14030 +       
14031 +       log("OS fingerprint matching module finished.\n");
14032 +}
14033 +
14034 +module_init(osf_init);
14035 +module_exit(osf_fini);
14036 +
14037 +MODULE_LICENSE("GPL");
14038 +MODULE_AUTHOR("Evgeniy Polyakov <johnpol@2ka.mipt.ru>");
14039 +MODULE_DESCRIPTION("Passive OS fingerprint matching.");
14040 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_owner.c linux-2.6.6/net/ipv4/netfilter/ipt_owner.c
14041 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_owner.c      2004-05-10 04:33:20.000000000 +0200
14042 +++ linux-2.6.6/net/ipv4/netfilter/ipt_owner.c  2004-05-18 14:28:50.000000000 +0200
14043 @@ -6,12 +6,19 @@
14044   * This program is free software; you can redistribute it and/or modify
14045   * it under the terms of the GNU General Public License version 2 as
14046   * published by the Free Software Foundation.
14047 + *
14048 + * 03/26/2003 Patrick McHardy <kaber@trash.net>        : LOCAL_IN support
14049   */
14050  
14051  #include <linux/module.h>
14052  #include <linux/skbuff.h>
14053  #include <linux/file.h>
14054 +#include <linux/ip.h>
14055 +#include <linux/tcp.h>
14056 +#include <linux/udp.h>
14057  #include <net/sock.h>
14058 +#include <net/tcp.h>
14059 +#include <net/udp.h>
14060  
14061  #include <linux/netfilter_ipv4/ipt_owner.h>
14062  #include <linux/netfilter_ipv4/ip_tables.h>
14063 @@ -21,7 +28,7 @@
14064  MODULE_DESCRIPTION("iptables owner match");
14065  
14066  static int
14067 -match_comm(const struct sk_buff *skb, const char *comm)
14068 +match_comm(const struct sock *sk, const char *comm)
14069  {
14070         struct task_struct *g, *p;
14071         struct files_struct *files;
14072 @@ -38,7 +45,7 @@
14073                         spin_lock(&files->file_lock);
14074                         for (i=0; i < files->max_fds; i++) {
14075                                 if (fcheck_files(files, i) ==
14076 -                                   skb->sk->sk_socket->file) {
14077 +                                   sk->sk_socket->file) {
14078                                         spin_unlock(&files->file_lock);
14079                                         task_unlock(p);
14080                                         read_unlock(&tasklist_lock);
14081 @@ -54,7 +61,7 @@
14082  }
14083  
14084  static int
14085 -match_pid(const struct sk_buff *skb, pid_t pid)
14086 +match_pid(const struct sock *sk, pid_t pid)
14087  {
14088         struct task_struct *p;
14089         struct files_struct *files;
14090 @@ -70,7 +77,7 @@
14091                 spin_lock(&files->file_lock);
14092                 for (i=0; i < files->max_fds; i++) {
14093                         if (fcheck_files(files, i) ==
14094 -                           skb->sk->sk_socket->file) {
14095 +                           sk->sk_socket->file) {
14096                                 spin_unlock(&files->file_lock);
14097                                 task_unlock(p);
14098                                 read_unlock(&tasklist_lock);
14099 @@ -86,10 +93,10 @@
14100  }
14101  
14102  static int
14103 -match_sid(const struct sk_buff *skb, pid_t sid)
14104 +match_sid(const struct sock *sk, pid_t sid)
14105  {
14106         struct task_struct *g, *p;
14107 -       struct file *file = skb->sk->sk_socket->file;
14108 +       struct file *file = sk->sk_socket->file;
14109         int i, found=0;
14110  
14111         read_lock(&tasklist_lock);
14112 @@ -129,41 +136,71 @@
14113        int *hotdrop)
14114  {
14115         const struct ipt_owner_info *info = matchinfo;
14116 +       struct iphdr *iph = skb->nh.iph;
14117 +       struct sock *sk = NULL;
14118 +       int ret = 0;
14119 +
14120 +       if (out) {
14121 +               sk = skb->sk;
14122 +       } else {
14123 +               if (iph->protocol == IPPROTO_TCP) {
14124 +                       struct tcphdr *tcph =
14125 +                               (struct tcphdr *)((u_int32_t *)iph + iph->ihl);
14126 +                       sk = tcp_v4_lookup(iph->saddr, tcph->source,
14127 +                                          iph->daddr, tcph->dest,
14128 +                                          skb->dev->ifindex);
14129 +                       if (sk && sk->sk_state == TCP_TIME_WAIT) {
14130 +                               tcp_tw_put((struct tcp_tw_bucket *)sk);
14131 +                               return ret;
14132 +                       }
14133 +               } else if (iph->protocol == IPPROTO_UDP) {
14134 +                       struct udphdr *udph =
14135 +                               (struct udphdr *)((u_int32_t *)iph + iph->ihl);
14136 +                       sk = udp_v4_lookup(iph->saddr, udph->source, iph->daddr,
14137 +                                          udph->dest, skb->dev->ifindex);
14138 +               }
14139 +       }
14140  
14141 -       if (!skb->sk || !skb->sk->sk_socket || !skb->sk->sk_socket->file)
14142 -               return 0;
14143 +       if (!sk || !sk->sk_socket || !sk->sk_socket->file)
14144 +               goto out;
14145  
14146         if(info->match & IPT_OWNER_UID) {
14147 -               if ((skb->sk->sk_socket->file->f_uid != info->uid) ^
14148 +               if ((sk->sk_socket->file->f_uid != info->uid) ^
14149                     !!(info->invert & IPT_OWNER_UID))
14150 -                       return 0;
14151 +                       goto out;
14152         }
14153  
14154         if(info->match & IPT_OWNER_GID) {
14155 -               if ((skb->sk->sk_socket->file->f_gid != info->gid) ^
14156 +               if ((sk->sk_socket->file->f_gid != info->gid) ^
14157                     !!(info->invert & IPT_OWNER_GID))
14158 -                       return 0;
14159 +                       goto out;
14160         }
14161  
14162         if(info->match & IPT_OWNER_PID) {
14163 -               if (!match_pid(skb, info->pid) ^
14164 +               if (!match_pid(sk, info->pid) ^
14165                     !!(info->invert & IPT_OWNER_PID))
14166 -                       return 0;
14167 +                       goto out;
14168         }
14169  
14170         if(info->match & IPT_OWNER_SID) {
14171 -               if (!match_sid(skb, info->sid) ^
14172 +               if (!match_sid(sk, info->sid) ^
14173                     !!(info->invert & IPT_OWNER_SID))
14174 -                       return 0;
14175 +                       goto out;
14176         }
14177  
14178         if(info->match & IPT_OWNER_COMM) {
14179 -               if (!match_comm(skb, info->comm) ^
14180 +               if (!match_comm(sk, info->comm) ^
14181                     !!(info->invert & IPT_OWNER_COMM))
14182 -                       return 0;
14183 +                       goto out;
14184         }
14185  
14186 -       return 1;
14187 +       ret = 1;
14188 +
14189 +out:
14190 +       if (in && sk)
14191 +               sock_put(sk);
14192 +
14193 +       return ret;
14194  }
14195  
14196  static int
14197 @@ -173,11 +210,19 @@
14198             unsigned int matchsize,
14199             unsigned int hook_mask)
14200  {
14201 -        if (hook_mask
14202 -            & ~((1 << NF_IP_LOCAL_OUT) | (1 << NF_IP_POST_ROUTING))) {
14203 -                printk("ipt_owner: only valid for LOCAL_OUT or POST_ROUTING.\n");
14204 -                return 0;
14205 -        }
14206 +       if (hook_mask
14207 +           & ~((1 << NF_IP_LOCAL_OUT) | (1 << NF_IP_POST_ROUTING) |
14208 +           (1 << NF_IP_LOCAL_IN))) {
14209 +               printk("ipt_owner: only valid for LOCAL_IN, LOCAL_OUT "
14210 +                      "or POST_ROUTING.\n");
14211 +               return 0;
14212 +       }
14213 +
14214 +       if ((hook_mask & (1 << NF_IP_LOCAL_IN))
14215 +           && ip->proto != IPPROTO_TCP && ip->proto != IPPROTO_UDP) {
14216 +               printk("ipt_owner: only TCP or UDP can be used in LOCAL_IN\n");
14217 +               return 0;
14218 +       }
14219  
14220         if (matchsize != IPT_ALIGN(sizeof(struct ipt_owner_info))) {
14221                 printk("Matchsize %u != %Zu\n", matchsize,
14222 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_policy.c linux-2.6.6/net/ipv4/netfilter/ipt_policy.c
14223 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_policy.c     1970-01-01 01:00:00.000000000 +0100
14224 +++ linux-2.6.6/net/ipv4/netfilter/ipt_policy.c 2004-05-18 14:28:50.000000000 +0200
14225 @@ -0,0 +1,176 @@
14226 +/* IP tables module for matching IPsec policy
14227 + *
14228 + * Copyright (c) 2004 Patrick McHardy, <kaber@trash.net>
14229 + *
14230 + * This program is free software; you can redistribute it and/or modify
14231 + * it under the terms of the GNU General Public License version 2 as
14232 + * published by the Free Software Foundation.
14233 + */
14234 +
14235 +#include <linux/kernel.h>
14236 +#include <linux/config.h>
14237 +#include <linux/module.h>
14238 +#include <linux/skbuff.h>
14239 +#include <linux/init.h>
14240 +#include <net/xfrm.h>
14241 +
14242 +#include <linux/netfilter_ipv4.h>
14243 +#include <linux/netfilter_ipv4/ipt_policy.h>
14244 +#include <linux/netfilter_ipv4/ip_tables.h>
14245 +
14246 +MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
14247 +MODULE_DESCRIPTION("IPtables IPsec policy matching module");
14248 +MODULE_LICENSE("GPL");
14249 +
14250 +
14251 +static inline int
14252 +match_xfrm_state(struct xfrm_state *x, const struct ipt_policy_elem *e)
14253 +{
14254 +#define MISMATCH(x,y)  (e->match.x && ((e->x != (y)) ^ e->invert.x))
14255 +
14256 +       if (MISMATCH(saddr, x->props.saddr.a4 & e->smask) ||
14257 +           MISMATCH(daddr, x->id.daddr.a4 & e->dmask) ||
14258 +           MISMATCH(proto, x->id.proto) ||
14259 +           MISMATCH(mode, x->props.mode) ||
14260 +           MISMATCH(spi, x->id.spi) ||
14261 +           MISMATCH(reqid, x->props.reqid))
14262 +               return 0;
14263 +       return 1;
14264 +}
14265 +
14266 +static int
14267 +match_policy_in(const struct sk_buff *skb, const struct ipt_policy_info *info)
14268 +{
14269 +       const struct ipt_policy_elem *e;
14270 +       struct sec_path *sp = skb->sp;
14271 +       int strict = info->flags & POLICY_MATCH_STRICT;
14272 +       int i, pos;
14273 +
14274 +       if (sp == NULL)
14275 +               return -1;
14276 +       if (strict && info->len != sp->len)
14277 +               return 0;
14278 +
14279 +       for (i = sp->len - 1; i >= 0; i--) {
14280 +               pos = strict ? i - sp->len + 1 : 0;
14281 +               if (pos >= info->len)
14282 +                       return 0;
14283 +               e = &info->pol[pos];
14284 +
14285 +               if (match_xfrm_state(sp->x[i].xvec, e)) {
14286 +                       if (!strict)
14287 +                               return 1;
14288 +               } else if (strict)
14289 +                       return 0;
14290 +       }
14291 +
14292 +       return strict ? 1 : 0;
14293 +}
14294 +
14295 +static int
14296 +match_policy_out(const struct sk_buff *skb, const struct ipt_policy_info *info)
14297 +{
14298 +       const struct ipt_policy_elem *e;
14299 +       struct dst_entry *dst = skb->dst;
14300 +       int strict = info->flags & POLICY_MATCH_STRICT;
14301 +       int i, pos;
14302 +
14303 +       if (dst->xfrm == NULL)
14304 +               return -1;
14305 +
14306 +       for (i = 0; dst && dst->xfrm; dst = dst->child, i++) {
14307 +               pos = strict ? i : 0;
14308 +               if (pos >= info->len)
14309 +                       return 0;
14310 +               e = &info->pol[pos];
14311 +
14312 +               if (match_xfrm_state(dst->xfrm, e)) {
14313 +                       if (!strict)
14314 +                               return 1;
14315 +               } else if (strict)
14316 +                       return 0;
14317 +       }
14318 +
14319 +       return strict ? 1 : 0;
14320 +}
14321 +
14322 +static int match(const struct sk_buff *skb,
14323 +                 const struct net_device *in,
14324 +                 const struct net_device *out,
14325 +                 const void *matchinfo, int offset, int *hotdrop)
14326 +{
14327 +       const struct ipt_policy_info *info = matchinfo;
14328 +       int ret;
14329 +
14330 +       if (info->flags & POLICY_MATCH_IN)
14331 +               ret = match_policy_in(skb, info);
14332 +       else
14333 +               ret = match_policy_out(skb, info);
14334 +
14335 +       if (ret < 0) {
14336 +               if (info->flags & POLICY_MATCH_NONE)
14337 +                       ret = 1;
14338 +               else
14339 +                       ret = 0;
14340 +       } else if (info->flags & POLICY_MATCH_NONE)
14341 +               ret = 0;
14342 +
14343 +       return ret;
14344 +}
14345 +
14346 +static int checkentry(const char *tablename, const struct ipt_ip *ip,
14347 +                      void *matchinfo, unsigned int matchsize,
14348 +                      unsigned int hook_mask)
14349 +{
14350 +       struct ipt_policy_info *info = matchinfo;
14351 +
14352 +       if (matchsize != IPT_ALIGN(sizeof(*info))) {
14353 +               printk(KERN_ERR "ipt_policy: matchsize %u != %u\n",
14354 +                      matchsize, IPT_ALIGN(sizeof(*info)));
14355 +               return 0;
14356 +       }
14357 +       if (!(info->flags & (POLICY_MATCH_IN|POLICY_MATCH_OUT))) {
14358 +               printk(KERN_ERR "ipt_policy: neither incoming nor "
14359 +                               "outgoing policy selected\n");
14360 +               return 0;
14361 +       }
14362 +       if (hook_mask & (1 << NF_IP_PRE_ROUTING | 1 << NF_IP_LOCAL_IN)
14363 +           && info->flags & POLICY_MATCH_OUT) {
14364 +               printk(KERN_ERR "ipt_policy: output policy not valid in "
14365 +                               "PRE_ROUTING and INPUT\n");
14366 +               return 0;
14367 +       }
14368 +       if (hook_mask & (1 << NF_IP_POST_ROUTING | 1 << NF_IP_LOCAL_OUT)
14369 +           && info->flags & POLICY_MATCH_IN) {
14370 +               printk(KERN_ERR "ipt_policy: input policy not valid in "
14371 +                               "POST_ROUTING and OUTPUT\n");
14372 +               return 0;
14373 +       }
14374 +       if (info->len > POLICY_MAX_ELEM) {
14375 +               printk(KERN_ERR "ipt_policy: too many policy elements\n");
14376 +               return 0;
14377 +       }
14378 +
14379 +       return 1;
14380 +}
14381 +
14382 +static struct ipt_match policy_match =
14383 +{
14384 +       .name           = "policy",
14385 +       .match          = match,
14386 +       .checkentry     = checkentry,
14387 +       .me             = THIS_MODULE,
14388 +};
14389 +
14390 +static int __init init(void)
14391 +{
14392 +       return ipt_register_match(&policy_match);
14393 +}
14394 +
14395 +static void __exit fini(void)
14396 +{
14397 +       ipt_unregister_match(&policy_match);
14398 +}
14399 +
14400 +module_init(init);
14401 +module_exit(fini);
14402 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_pool.c linux-2.6.6/net/ipv4/netfilter/ipt_pool.c
14403 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_pool.c       1970-01-01 01:00:00.000000000 +0100
14404 +++ linux-2.6.6/net/ipv4/netfilter/ipt_pool.c   2004-05-18 14:28:50.000000000 +0200
14405 @@ -0,0 +1,71 @@
14406 +/* Kernel module to match an IP address pool. */
14407 +
14408 +#include <linux/module.h>
14409 +#include <linux/ip.h>
14410 +#include <linux/skbuff.h>
14411 +
14412 +#include <linux/netfilter_ipv4/ip_tables.h>
14413 +#include <linux/netfilter_ipv4/ip_pool.h>
14414 +#include <linux/netfilter_ipv4/ipt_pool.h>
14415 +
14416 +static inline int match_pool(
14417 +       ip_pool_t index,
14418 +       __u32 addr,
14419 +       int inv
14420 +) {
14421 +       if (ip_pool_match(index, ntohl(addr)))
14422 +               inv = !inv;
14423 +       return inv;
14424 +}
14425 +
14426 +static int match(
14427 +       const struct sk_buff *skb,
14428 +       const struct net_device *in,
14429 +       const struct net_device *out,
14430 +       const void *matchinfo,
14431 +       int offset,
14432 +       const void *hdr,
14433 +       u_int16_t datalen,
14434 +       int *hotdrop
14435 +) {
14436 +       const struct ipt_pool_info *info = matchinfo;
14437 +       const struct iphdr *iph = skb->nh.iph;
14438 +
14439 +       if (info->src != IP_POOL_NONE && !match_pool(info->src, iph->saddr,
14440 +                                               info->flags&IPT_POOL_INV_SRC))
14441 +               return 0;
14442 +
14443 +       if (info->dst != IP_POOL_NONE && !match_pool(info->dst, iph->daddr,
14444 +                                               info->flags&IPT_POOL_INV_DST))
14445 +               return 0;
14446 +
14447 +       return 1;
14448 +}
14449 +
14450 +static int checkentry(
14451 +       const char *tablename,
14452 +       const struct ipt_ip *ip,
14453 +       void *matchinfo,
14454 +       unsigned int matchsize,
14455 +       unsigned int hook_mask
14456 +) {
14457 +       if (matchsize != IPT_ALIGN(sizeof(struct ipt_pool_info)))
14458 +               return 0;
14459 +       return 1;
14460 +}
14461 +
14462 +static struct ipt_match pool_match
14463 += { { NULL, NULL }, "pool", &match, &checkentry, NULL, THIS_MODULE };
14464 +
14465 +static int __init init(void)
14466 +{
14467 +       return ipt_register_match(&pool_match);
14468 +}
14469 +
14470 +static void __exit fini(void)
14471 +{
14472 +       ipt_unregister_match(&pool_match);
14473 +}
14474 +
14475 +module_init(init);
14476 +module_exit(fini);
14477 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_psd.c linux-2.6.6/net/ipv4/netfilter/ipt_psd.c
14478 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_psd.c        1970-01-01 01:00:00.000000000 +0100
14479 +++ linux-2.6.6/net/ipv4/netfilter/ipt_psd.c    2004-05-18 14:28:50.000000000 +0200
14480 @@ -0,0 +1,358 @@
14481 +/*
14482 +  This is a module which is used for PSD (portscan detection)
14483 +  Derived from scanlogd v2.1 written by Solar Designer <solar@false.com>
14484 +  and LOG target module.
14485 +
14486 +  Copyright (C) 2000,2001 astaro AG
14487 +
14488 +  This file is distributed under the terms of the GNU General Public
14489 +  License (GPL). Copies of the GPL can be obtained from:
14490 +     ftp://prep.ai.mit.edu/pub/gnu/GPL
14491 +
14492 +  2000-05-04 Markus Hennig <hennig@astaro.de> : initial
14493 +  2000-08-18 Dennis Koslowski <koslowski@astaro.de> : first release
14494 +  2000-12-01 Dennis Koslowski <koslowski@astaro.de> : UDP scans detection added
14495 +  2001-01-02 Dennis Koslowski <koslowski@astaro.de> : output modified
14496 +  2001-02-04 Jan Rekorajski <baggins@pld.org.pl> : converted from target to match
14497 +  2004-05-05 Martijn Lievaart <m@rtij.nl> : ported to 2.6
14498 +*/
14499 +
14500 +#include <linux/module.h>
14501 +#include <linux/skbuff.h>
14502 +#include <linux/ip.h>
14503 +#include <net/tcp.h>
14504 +#include <linux/spinlock.h>
14505 +#include <linux/netfilter_ipv4/ip_tables.h>
14506 +#include <linux/netfilter_ipv4/ipt_psd.h>
14507 +
14508 +#if 0
14509 +#define DEBUGP printk
14510 +#else
14511 +#define DEBUGP(format, args...)
14512 +#endif
14513 +
14514 +MODULE_LICENSE("GPL");
14515 +MODULE_AUTHOR("Dennis Koslowski <koslowski@astaro.com>");
14516 +
14517 +#define HF_DADDR_CHANGING   0x01
14518 +#define HF_SPORT_CHANGING   0x02
14519 +#define HF_TOS_CHANGING            0x04
14520 +#define HF_TTL_CHANGING            0x08
14521 +
14522 +/*
14523 + * Information we keep per each target port
14524 + */
14525 +struct port {
14526 +       u_int16_t number;      /* port number */
14527 +       u_int8_t proto;        /* protocol number */
14528 +       u_int8_t and_flags;    /* tcp ANDed flags */
14529 +       u_int8_t or_flags;     /* tcp ORed flags */
14530 +};
14531 +
14532 +/*
14533 + * Information we keep per each source address.
14534 + */
14535 +struct host {
14536 +       struct host *next;              /* Next entry with the same hash */
14537 +       clock_t timestamp;              /* Last update time */
14538 +       struct in_addr src_addr;        /* Source address */
14539 +       struct in_addr dest_addr;       /* Destination address */
14540 +       unsigned short src_port;        /* Source port */
14541 +       int count;                      /* Number of ports in the list */
14542 +       int weight;                     /* Total weight of ports in the list */
14543 +       struct port ports[SCAN_MAX_COUNT - 1];  /* List of ports */
14544 +       unsigned char tos;              /* TOS */
14545 +       unsigned char ttl;              /* TTL */
14546 +       unsigned char flags;            /* HF_ flags bitmask */
14547 +};
14548 +
14549 +/*
14550 + * State information.
14551 + */
14552 +static struct {
14553 +       spinlock_t lock;
14554 +       struct host list[LIST_SIZE];    /* List of source addresses */
14555 +       struct host *hash[HASH_SIZE];   /* Hash: pointers into the list */
14556 +       int index;                      /* Oldest entry to be replaced */
14557 +} state;
14558 +
14559 +/*
14560 + * Convert an IP address into a hash table index.
14561 + */
14562 +static inline int hashfunc(struct in_addr addr)
14563 +{
14564 +       unsigned int value;
14565 +       int hash;
14566 +
14567 +       value = addr.s_addr;
14568 +       hash = 0;
14569 +       do {
14570 +               hash ^= value;
14571 +       } while ((value >>= HASH_LOG));
14572 +
14573 +       return hash & (HASH_SIZE - 1);
14574 +}
14575 +
14576 +static int
14577 +ipt_psd_match(const struct sk_buff *pskb,
14578 +             const struct net_device *in,
14579 +             const struct net_device *out,
14580 +             const void *matchinfo,
14581 +             int offset,
14582 +             int *hotdrop)
14583 +{
14584 +       struct iphdr *ip_hdr;
14585 +       struct tcphdr *tcp_hdr;
14586 +       struct in_addr addr;
14587 +       u_int16_t src_port,dest_port;
14588 +       u_int8_t tcp_flags, proto;
14589 +       clock_t now;
14590 +       struct host *curr, *last, **head;
14591 +       int hash, index, count;
14592 +
14593 +       /* Parameters from userspace */
14594 +       const struct ipt_psd_info *psdinfo = matchinfo;
14595 +
14596 +       /* IP header */
14597 +       ip_hdr = pskb->nh.iph;
14598 +
14599 +       /* Sanity check */
14600 +       if (ntohs(ip_hdr->frag_off) & IP_OFFSET) {
14601 +               DEBUGP("PSD: sanity check failed\n");
14602 +               return 0;
14603 +       }
14604 +
14605 +       /* TCP or UDP ? */
14606 +       proto = ip_hdr->protocol;
14607 +
14608 +       if (proto != IPPROTO_TCP && proto != IPPROTO_UDP) {
14609 +               DEBUGP("PSD: protocol not supported\n");
14610 +               return 0;
14611 +       }
14612 +
14613 +       /* Get the source address, source & destination ports, and TCP flags */
14614 +
14615 +       addr.s_addr = ip_hdr->saddr;
14616 +
14617 +       tcp_hdr = (struct tcphdr*)((u_int32_t *)ip_hdr + ip_hdr->ihl);
14618 +
14619 +       /* Yep, it´s dirty */
14620 +       src_port = tcp_hdr->source;
14621 +       dest_port = tcp_hdr->dest;
14622 +
14623 +       if (proto == IPPROTO_TCP) {
14624 +               tcp_flags = *((u_int8_t*)tcp_hdr + 13);
14625 +       }
14626 +       else {
14627 +               tcp_flags = 0x00;
14628 +       }
14629 +
14630 +       /* We're using IP address 0.0.0.0 for a special purpose here, so don't let
14631 +        * them spoof us. [DHCP needs this feature - HW] */
14632 +       if (!addr.s_addr) {
14633 +               DEBUGP("PSD: spoofed source address (0.0.0.0)\n");
14634 +               return 0;
14635 +       }
14636 +
14637 +       /* Use jiffies here not to depend on someone setting the time while we're
14638 +        * running; we need to be careful with possible return value overflows. */
14639 +       now = jiffies;
14640 +
14641 +       spin_lock(&state.lock);
14642 +
14643 +       /* Do we know this source address already? */
14644 +       count = 0;
14645 +       last = NULL;
14646 +       if ((curr = *(head = &state.hash[hash = hashfunc(addr)])))
14647 +               do {
14648 +                       if (curr->src_addr.s_addr == addr.s_addr) break;
14649 +                       count++;
14650 +                       if (curr->next) last = curr;
14651 +               } while ((curr = curr->next));
14652 +
14653 +       if (curr) {
14654 +
14655 +               /* We know this address, and the entry isn't too old. Update it. */
14656 +               if (now - curr->timestamp <= (psdinfo->delay_threshold*HZ)/100 &&
14657 +                   time_after_eq(now, curr->timestamp)) {
14658 +
14659 +                       /* Just update the appropriate list entry if we've seen this port already */
14660 +                       for (index = 0; index < curr->count; index++) {
14661 +                               if (curr->ports[index].number == dest_port) {
14662 +                                       curr->ports[index].proto = proto;
14663 +                                       curr->ports[index].and_flags &= tcp_flags;
14664 +                                       curr->ports[index].or_flags |= tcp_flags;
14665 +                                       goto out_no_match;
14666 +                               }
14667 +                       }
14668 +
14669 +                       /* TCP/ACK and/or TCP/RST to a new port? This could be an outgoing connection. */
14670 +                       if (proto == IPPROTO_TCP && (tcp_hdr->ack || tcp_hdr->rst))
14671 +                               goto out_no_match;
14672 +
14673 +                       /* Packet to a new port, and not TCP/ACK: update the timestamp */
14674 +                       curr->timestamp = now;
14675 +
14676 +                       /* Logged this scan already? Then drop the packet. */
14677 +                       if (curr->weight >= psdinfo->weight_threshold)
14678 +                               goto out_match;
14679 +
14680 +                       /* Specify if destination address, source port, TOS or TTL are not fixed */
14681 +                       if (curr->dest_addr.s_addr != ip_hdr->daddr)
14682 +                               curr->flags |= HF_DADDR_CHANGING;
14683 +                       if (curr->src_port != src_port)
14684 +                               curr->flags |= HF_SPORT_CHANGING;
14685 +                       if (curr->tos != ip_hdr->tos)
14686 +                               curr->flags |= HF_TOS_CHANGING;
14687 +                       if (curr->ttl != ip_hdr->ttl)
14688 +                               curr->flags |= HF_TTL_CHANGING;
14689 +
14690 +                       /* Update the total weight */
14691 +                       curr->weight += (ntohs(dest_port) < 1024) ?
14692 +                               psdinfo->lo_ports_weight : psdinfo->hi_ports_weight;
14693 +
14694 +                       /* Got enough destination ports to decide that this is a scan? */
14695 +                       /* Then log it and drop the packet. */
14696 +                       if (curr->weight >= psdinfo->weight_threshold)
14697 +                               goto out_match;
14698 +
14699 +                       /* Remember the new port */
14700 +                       if (curr->count < SCAN_MAX_COUNT) {
14701 +                               curr->ports[curr->count].number = dest_port;
14702 +                               curr->ports[curr->count].proto = proto;
14703 +                               curr->ports[curr->count].and_flags = tcp_flags;
14704 +                               curr->ports[curr->count].or_flags = tcp_flags;
14705 +                               curr->count++;
14706 +                       }
14707 +
14708 +                       goto out_no_match;
14709 +               }
14710 +
14711 +               /* We know this address, but the entry is outdated. Mark it unused, and
14712 +                * remove from the hash table. We'll allocate a new entry instead since
14713 +                * this one might get re-used too soon. */
14714 +               curr->src_addr.s_addr = 0;
14715 +               if (last)
14716 +                       last->next = last->next->next;
14717 +               else if (*head)
14718 +                       *head = (*head)->next;
14719 +               last = NULL;
14720 +       }
14721 +
14722 +       /* We don't need an ACK from a new source address */
14723 +       if (proto == IPPROTO_TCP && tcp_hdr->ack)
14724 +               goto out_no_match;
14725 +
14726 +       /* Got too many source addresses with the same hash value? Then remove the
14727 +        * oldest one from the hash table, so that they can't take too much of our
14728 +        * CPU time even with carefully chosen spoofed IP addresses. */
14729 +       if (count >= HASH_MAX && last) last->next = NULL;
14730 +
14731 +       /* We're going to re-use the oldest list entry, so remove it from the hash
14732 +        * table first (if it is really already in use, and isn't removed from the
14733 +        * hash table already because of the HASH_MAX check above). */
14734 +
14735 +       /* First, find it */
14736 +       if (state.list[state.index].src_addr.s_addr)
14737 +               head = &state.hash[hashfunc(state.list[state.index].src_addr)];
14738 +       else
14739 +               head = &last;
14740 +       last = NULL;
14741 +       if ((curr = *head))
14742 +       do {
14743 +               if (curr == &state.list[state.index]) break;
14744 +               last = curr;
14745 +       } while ((curr = curr->next));
14746 +
14747 +       /* Then, remove it */
14748 +       if (curr) {
14749 +               if (last)
14750 +                       last->next = last->next->next;
14751 +               else if (*head)
14752 +                       *head = (*head)->next;
14753 +       }
14754 +
14755 +       /* Get our list entry */
14756 +       curr = &state.list[state.index++];
14757 +       if (state.index >= LIST_SIZE) state.index = 0;
14758 +
14759 +       /* Link it into the hash table */
14760 +       head = &state.hash[hash];
14761 +       curr->next = *head;
14762 +       *head = curr;
14763 +
14764 +       /* And fill in the fields */
14765 +       curr->timestamp = now;
14766 +       curr->src_addr = addr;
14767 +       curr->dest_addr.s_addr = ip_hdr->daddr;
14768 +       curr->src_port = src_port;
14769 +       curr->count = 1;
14770 +       curr->weight = (ntohs(dest_port) < 1024) ?
14771 +               psdinfo->lo_ports_weight : psdinfo->hi_ports_weight;
14772 +       curr->ports[0].number = dest_port;
14773 +       curr->ports[0].proto = proto;
14774 +       curr->ports[0].and_flags = tcp_flags;
14775 +       curr->ports[0].or_flags = tcp_flags;
14776 +       curr->tos = ip_hdr->tos;
14777 +       curr->ttl = ip_hdr->ttl;
14778 +
14779 +out_no_match:
14780 +       spin_unlock(&state.lock);
14781 +       return 0;
14782 +
14783 +out_match:
14784 +       spin_unlock(&state.lock);
14785 +       return 1;
14786 +}
14787 +
14788 +static int ipt_psd_checkentry(const char *tablename,
14789 +                             const struct ipt_ip *e,
14790 +                             void *matchinfo,
14791 +                             unsigned int matchsize,
14792 +                             unsigned int hook_mask)
14793 +{
14794 +/*     const struct ipt_psd_info *psdinfo = targinfo;*/
14795 +
14796 +       /* we accept TCP only */
14797 +/*     if (e->ip.proto != IPPROTO_TCP) { */
14798 +/*             DEBUGP("PSD: specified protocol may be TCP only\n"); */
14799 +/*             return 0; */
14800 +/*     } */
14801 +
14802 +       if (matchsize != IPT_ALIGN(sizeof(struct ipt_psd_info))) {
14803 +               DEBUGP("PSD: matchsize %u != %u\n",
14804 +                      matchsize,
14805 +                      IPT_ALIGN(sizeof(struct ipt_psd_info)));
14806 +               return 0;
14807 +       }
14808 +
14809 +       return 1;
14810 +}
14811 +
14812 +static struct ipt_match ipt_psd_reg = {
14813 +       .name = "psd",
14814 +       .match = ipt_psd_match,
14815 +       .checkentry = ipt_psd_checkentry,
14816 +       .me = THIS_MODULE };
14817 +
14818 +static int __init init(void)
14819 +{
14820 +       if (ipt_register_match(&ipt_psd_reg))
14821 +               return -EINVAL;
14822 +
14823 +       memset(&state, 0, sizeof(state));
14824 +
14825 +       spin_lock_init(&(state.lock));
14826 +
14827 +       printk("netfilter PSD loaded - (c) astaro AG\n");
14828 +       return 0;
14829 +}
14830 +
14831 +static void __exit fini(void)
14832 +{
14833 +       ipt_unregister_match(&ipt_psd_reg);
14834 +       printk("netfilter PSD unloaded - (c) astaro AG\n");
14835 +}
14836 +
14837 +module_init(init);
14838 +module_exit(fini);
14839 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_quota.c linux-2.6.6/net/ipv4/netfilter/ipt_quota.c
14840 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_quota.c      1970-01-01 01:00:00.000000000 +0100
14841 +++ linux-2.6.6/net/ipv4/netfilter/ipt_quota.c  2004-05-18 14:28:50.000000000 +0200
14842 @@ -0,0 +1,91 @@
14843 +/* 
14844 + * netfilter module to enforce network quotas
14845 + *
14846 + * Sam Johnston <samj@samj.net>
14847 + */
14848 +#include <linux/module.h>
14849 +#include <linux/skbuff.h>
14850 +#include <linux/spinlock.h>
14851 +#include <linux/interrupt.h>
14852 +
14853 +#include <linux/netfilter_ipv4/ip_tables.h>
14854 +#include <linux/netfilter_ipv4/ipt_quota.h>
14855 +
14856 +MODULE_LICENSE("GPL");
14857 +MODULE_AUTHOR("Sam Johnston <samj@samj.net>");
14858 +
14859 +static spinlock_t quota_lock = SPIN_LOCK_UNLOCKED;
14860 +
14861 +static int
14862 +match(const struct sk_buff *skb,
14863 +      const struct net_device *in,
14864 +      const struct net_device *out,
14865 +      const void *matchinfo,
14866 +      int offset, int *hotdrop)
14867 +{
14868 +        struct ipt_quota_info *q = (struct ipt_quota_info *) matchinfo;
14869 +       unsigned int datalen;
14870 +
14871 +       if (skb->len < sizeof(struct iphdr))
14872 +               return NF_ACCEPT;
14873 +       
14874 +       datalen = skb->len - skb->nh.iph->ihl*4;
14875 +
14876 +        spin_lock_bh(&quota_lock);
14877 +
14878 +        if (q->quota >= datalen) {
14879 +                /* we can afford this one */
14880 +                q->quota -= datalen;
14881 +                spin_unlock_bh(&quota_lock);
14882 +
14883 +#ifdef DEBUG_IPT_QUOTA
14884 +                printk("IPT Quota OK: %llu datlen %d \n", q->quota, datalen);
14885 +#endif
14886 +                return 1;
14887 +        }
14888 +
14889 +        /* so we do not allow even small packets from now on */
14890 +        q->quota = 0;
14891 +
14892 +#ifdef DEBUG_IPT_QUOTA
14893 +        printk("IPT Quota Failed: %llu datlen %d \n", q->quota, datalen);
14894 +#endif
14895 +
14896 +        spin_unlock_bh(&quota_lock);
14897 +        return 0;
14898 +}
14899 +
14900 +static int
14901 +checkentry(const char *tablename,
14902 +           const struct ipt_ip *ip,
14903 +           void *matchinfo, unsigned int matchsize, unsigned int hook_mask)
14904 +{
14905 +        /* TODO: spinlocks? sanity checks? */
14906 +        if (matchsize != IPT_ALIGN(sizeof (struct ipt_quota_info)))
14907 +                return 0;
14908 +
14909 +        return 1;
14910 +}
14911 +
14912 +static struct ipt_match quota_match = {
14913 +       .name = "quota",
14914 +       .match = match,
14915 +       .checkentry = checkentry,
14916 +       .me = THIS_MODULE
14917 +};
14918 +
14919 +static int __init
14920 +init(void)
14921 +{
14922 +        return ipt_register_match(&quota_match);
14923 +}
14924 +
14925 +static void __exit
14926 +fini(void)
14927 +{
14928 +        ipt_unregister_match(&quota_match);
14929 +}
14930 +
14931 +module_init(init);
14932 +module_exit(fini);
14933 +
14934 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_random.c linux-2.6.6/net/ipv4/netfilter/ipt_random.c
14935 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_random.c     1970-01-01 01:00:00.000000000 +0100
14936 +++ linux-2.6.6/net/ipv4/netfilter/ipt_random.c 2004-05-18 14:28:50.000000000 +0200
14937 @@ -0,0 +1,96 @@
14938 +/*
14939 +  This is a module which is used for a "random" match support.
14940 +  This file is distributed under the terms of the GNU General Public
14941 +  License (GPL). Copies of the GPL can be obtained from:
14942 +     ftp://prep.ai.mit.edu/pub/gnu/GPL
14943 +
14944 +  2001-10-14 Fabrice MARIE <fabrice@netfilter.org> : initial implementation.
14945 +*/
14946 +
14947 +#include <linux/module.h>
14948 +#include <linux/skbuff.h>
14949 +#include <linux/ip.h>
14950 +#include <linux/random.h>
14951 +#include <net/tcp.h>
14952 +#include <linux/spinlock.h>
14953 +#include <linux/netfilter_ipv4/ip_tables.h>
14954 +#include <linux/netfilter_ipv4/ipt_random.h>
14955 +
14956 +MODULE_LICENSE("GPL");
14957 +
14958 +static int
14959 +ipt_rand_match(const struct sk_buff *pskb,
14960 +              const struct net_device *in,
14961 +              const struct net_device *out,
14962 +              const void *matchinfo,
14963 +              int offset,
14964 +              const void *hdr,
14965 +              u_int16_t datalen,
14966 +              int *hotdrop)
14967 +{
14968 +       /* Parameters from userspace */
14969 +       const struct ipt_rand_info *info = matchinfo;
14970 +       u_int8_t random_number;
14971 +
14972 +       /* get 1 random number from the kernel random number generation routine */
14973 +       get_random_bytes((void *)(&random_number), 1);
14974 +
14975 +       /* Do we match ? */
14976 +       if (random_number <= info->average)
14977 +               return 1;
14978 +       else
14979 +               return 0;
14980 +}
14981 +
14982 +static int
14983 +ipt_rand_checkentry(const char *tablename,
14984 +                  const struct ipt_ip *e,
14985 +                  void *matchinfo,
14986 +                  unsigned int matchsize,
14987 +                  unsigned int hook_mask)
14988 +{
14989 +       /* Parameters from userspace */
14990 +       const struct ipt_rand_info *info = matchinfo;
14991 +
14992 +       if (matchsize != IPT_ALIGN(sizeof(struct ipt_rand_info))) {
14993 +               printk("ipt_random: matchsize %u != %u\n", matchsize,
14994 +                      IPT_ALIGN(sizeof(struct ipt_rand_info)));
14995 +               return 0;
14996 +       }
14997 +
14998 +       /* must be  1 <= average % <= 99 */
14999 +       /* 1  x 2.55 = 2   */
15000 +       /* 99 x 2.55 = 252 */
15001 +       if ((info->average < 2) || (info->average > 252)) {
15002 +               printk("ipt_random:  invalid average %u\n", info->average);
15003 +               return 0;
15004 +       }
15005 +
15006 +       return 1;
15007 +}
15008 +
15009 +static struct ipt_match ipt_rand_reg = { 
15010 +       {NULL, NULL},
15011 +       "random",
15012 +       ipt_rand_match,
15013 +       ipt_rand_checkentry,
15014 +       NULL,
15015 +       THIS_MODULE };
15016 +
15017 +static int __init init(void)
15018 +{
15019 +       if (ipt_register_match(&ipt_rand_reg))
15020 +               return -EINVAL;
15021 +
15022 +       printk("ipt_random match loaded\n");
15023 +       return 0;
15024 +}
15025 +
15026 +static void __exit fini(void)
15027 +{
15028 +       ipt_unregister_match(&ipt_rand_reg);
15029 +       printk("ipt_random match unloaded\n");
15030 +}
15031 +
15032 +module_init(init);
15033 +module_exit(fini);
15034 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_realm.c linux-2.6.6/net/ipv4/netfilter/ipt_realm.c
15035 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_realm.c      1970-01-01 01:00:00.000000000 +0100
15036 +++ linux-2.6.6/net/ipv4/netfilter/ipt_realm.c  2004-05-18 14:28:50.000000000 +0200
15037 @@ -0,0 +1,78 @@
15038 +/* IP tables module for matching the routing realm
15039 + *
15040 + * $Id$
15041 + *
15042 + * (C) 2003 by Sampsa Ranta <sampsa@netsonic.fi>
15043 + *
15044 + * This program is free software; you can redistribute it and/or modify
15045 + * it under the terms of the GNU General Public License version 2 as
15046 + * published by the Free Software Foundation.
15047 + */
15048 +
15049 +#include <linux/module.h>
15050 +#include <linux/skbuff.h>
15051 +#include <linux/netdevice.h>
15052 +#include <net/route.h>
15053 +
15054 +#include <linux/netfilter_ipv4/ipt_realm.h>
15055 +#include <linux/netfilter_ipv4/ip_tables.h>
15056 +
15057 +MODULE_AUTHOR("Sampsa Ranta <sampsa@netsonic.fi>");
15058 +MODULE_LICENSE("GPL");
15059 +
15060 +static int
15061 +match(const struct sk_buff *skb,
15062 +      const struct net_device *in,
15063 +      const struct net_device *out,
15064 +      const void *matchinfo,
15065 +      int offset,
15066 +      int *hotdrop)
15067 +{
15068 +       const struct ipt_realm_info *info = matchinfo;
15069 +       struct dst_entry *dst = skb->dst;
15070 +    
15071 +       if (!dst)
15072 +               return 0;
15073 +
15074 +       return (info->id == (dst->tclassid & info->mask)) ^ info->invert;
15075 +}
15076 +
15077 +static int check(const char *tablename,
15078 +                 const struct ipt_ip *ip,
15079 +                 void *matchinfo,
15080 +                 unsigned int matchsize,
15081 +                 unsigned int hook_mask)
15082 +{
15083 +       if (hook_mask
15084 +           & ~((1 << NF_IP_POST_ROUTING) | (1 << NF_IP_FORWARD) |
15085 +               (1 << NF_IP_LOCAL_OUT)| (1 << NF_IP_LOCAL_IN))) {
15086 +               printk("ipt_realm: only valid for POST_ROUTING, LOCAL_OUT, "
15087 +                      "LOCAL_IN or FORWARD.\n");
15088 +               return 0;
15089 +       }
15090 +
15091 +       if (matchsize != IPT_ALIGN(sizeof(struct ipt_realm_info)))
15092 +               return 0;
15093 +
15094 +       return 1;
15095 +}
15096 +
15097 +static struct ipt_match realm_match = {
15098 +       .name = "realm",
15099 +       .match = match, 
15100 +       .checkentry = check,
15101 +       .me = THIS_MODULE
15102 +};
15103 +
15104 +static int __init init(void)
15105 +{
15106 +       return ipt_register_match(&realm_match);
15107 +}
15108 +
15109 +static void __exit fini(void)
15110 +{
15111 +       ipt_unregister_match(&realm_match);
15112 +}
15113 +
15114 +module_init(init);
15115 +module_exit(fini);
15116 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_sctp.c linux-2.6.6/net/ipv4/netfilter/ipt_sctp.c
15117 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_sctp.c       1970-01-01 01:00:00.000000000 +0100
15118 +++ linux-2.6.6/net/ipv4/netfilter/ipt_sctp.c   2004-05-18 14:28:50.000000000 +0200
15119 @@ -0,0 +1,199 @@
15120 +#include <linux/module.h>
15121 +#include <linux/skbuff.h>
15122 +#include <net/ip.h>
15123 +#include <linux/sctp.h>
15124 +
15125 +#include <linux/netfilter_ipv4/ip_tables.h>
15126 +#include <linux/netfilter_ipv4/ipt_sctp.h>
15127 +
15128 +#if 0
15129 +#define duprintf(format, args...) printk(format , ## args)
15130 +#else
15131 +#define duprintf(format, args...)
15132 +#endif
15133 +
15134 +#define SCCHECK(cond, option, flag, invflag) (!((flag) & (option)) \
15135 +                                             || (!!((invflag) & (option)) ^ (cond)))
15136 +
15137 +static int
15138 +match_flags(const struct ipt_sctp_flag_info *flag_info,
15139 +           const int flag_count,
15140 +           u_int8_t chunktype,
15141 +           u_int8_t chunkflags)
15142 +{
15143 +       int i;
15144 +
15145 +       for (i = 0; i < flag_count; i++) {
15146 +               if (flag_info[i].chunktype == chunktype) {
15147 +                       return (chunkflags & flag_info[i].flag_mask) == flag_info[i].flag;
15148 +               }
15149 +       }
15150 +
15151 +       return 1;
15152 +}
15153 +
15154 +static int
15155 +match_packet(const struct sk_buff *skb,
15156 +            const u_int32_t *chunkmap,
15157 +            int chunk_match_type,
15158 +            const struct ipt_sctp_flag_info *flag_info,
15159 +            const int flag_count,
15160 +            int *hotdrop)
15161 +{
15162 +       int offset;
15163 +       u_int32_t chunkmapcopy[256 / sizeof (u_int32_t)];
15164 +       sctp_chunkhdr_t sch;
15165 +
15166 +       int i = 0;
15167 +
15168 +       if (chunk_match_type == SCTP_CHUNK_MATCH_ALL) {
15169 +               SCTP_CHUNKMAP_COPY(chunkmapcopy, chunkmap);
15170 +       }
15171 +
15172 +       offset = skb->nh.iph->ihl * 4 + sizeof (sctp_sctphdr_t);
15173 +       do {
15174 +               if (skb_copy_bits(skb, offset, &sch, sizeof(sch)) < 0) {
15175 +                       duprintf("Dropping invalid SCTP packet.\n");
15176 +                       *hotdrop = 1;
15177 +                       return 0;
15178 +               }
15179 +
15180 +               duprintf("Chunk num: %d\toffset: %d\ttype: %d\tlength: %d\tflags: %x\n", 
15181 +                               ++i, offset, sch.type, htons(sch.length), sch.flags);
15182 +
15183 +               offset += (htons(sch.length) + 3) & ~3;
15184 +
15185 +               duprintf("skb->len: %d\toffset: %d\n", skb->len, offset);
15186 +
15187 +               if (SCTP_CHUNKMAP_IS_SET(chunkmap, sch.type)) {
15188 +                       switch (chunk_match_type) {
15189 +                       case SCTP_CHUNK_MATCH_ANY:
15190 +                               if (match_flags(flag_info, flag_count, 
15191 +                                       sch.type, sch.flags)) {
15192 +                                       return 1;
15193 +                               }
15194 +                               break;
15195 +
15196 +                       case SCTP_CHUNK_MATCH_ALL:
15197 +                               if (match_flags(flag_info, flag_count, 
15198 +                                       sch.type, sch.flags)) {
15199 +                                       SCTP_CHUNKMAP_CLEAR(chunkmapcopy, sch.type);
15200 +                               }
15201 +                               break;
15202 +
15203 +                       case SCTP_CHUNK_MATCH_ONLY:
15204 +                               if (!match_flags(flag_info, flag_count, 
15205 +                                       sch.type, sch.flags)) {
15206 +                                       return 0;
15207 +                               }
15208 +                               break;
15209 +                       }
15210 +               } else {
15211 +                       switch (chunk_match_type) {
15212 +                       case SCTP_CHUNK_MATCH_ONLY:
15213 +                               return 0;
15214 +                       }
15215 +               }
15216 +       } while (offset < skb->len);
15217 +
15218 +       switch (chunk_match_type) {
15219 +       case SCTP_CHUNK_MATCH_ALL:
15220 +               return SCTP_CHUNKMAP_IS_CLEAR(chunkmap);
15221 +       case SCTP_CHUNK_MATCH_ANY:
15222 +               return 0;
15223 +       case SCTP_CHUNK_MATCH_ONLY:
15224 +               return 1;
15225 +       }
15226 +
15227 +       /* This will never be reached, but required to stop compiler whine */
15228 +       return 0;
15229 +}
15230 +
15231 +static int
15232 +match(const struct sk_buff *skb,
15233 +      const struct net_device *in,
15234 +      const struct net_device *out,
15235 +      const void *matchinfo,
15236 +      int offset,
15237 +      int *hotdrop)
15238 +{
15239 +       const struct ipt_sctp_info *info;
15240 +       sctp_sctphdr_t sh;
15241 +
15242 +       info = (const struct ipt_sctp_info *)matchinfo;
15243 +
15244 +       if (offset) {
15245 +               duprintf("Dropping non-first fragment.. FIXME\n");
15246 +               return 0;
15247 +       }
15248 +       
15249 +       if (skb_copy_bits(skb, skb->nh.iph->ihl*4, &sh, sizeof(sh)) < 0) {
15250 +               duprintf("Dropping evil TCP offset=0 tinygram.\n");
15251 +               *hotdrop = 1;
15252 +               return 0;
15253 +               }
15254 +       duprintf("spt: %d\tdpt: %d\n", ntohs(sh.source), ntohs(sh.dest));
15255 +
15256 +       return  SCCHECK(((ntohs(sh.source) >= info->spts[0]) 
15257 +                       && (ntohs(sh.source) <= info->spts[1])), 
15258 +                       IPT_SCTP_SRC_PORTS, info->flags, info->invflags)
15259 +               && SCCHECK(((ntohs(sh.dest) >= info->dpts[0]) 
15260 +                       && (ntohs(sh.dest) <= info->dpts[1])), 
15261 +                       IPT_SCTP_DEST_PORTS, info->flags, info->invflags)
15262 +               && SCCHECK(match_packet(skb, info->chunkmap, info->chunk_match_type,
15263 +                                       info->flag_info, info->flag_count, 
15264 +                                       hotdrop),
15265 +                          IPT_SCTP_CHUNK_TYPES, info->flags, info->invflags);
15266 +}
15267 +
15268 +static int
15269 +checkentry(const char *tablename,
15270 +          const struct ipt_ip *ip,
15271 +          void *matchinfo,
15272 +          unsigned int matchsize,
15273 +          unsigned int hook_mask)
15274 +{
15275 +       const struct ipt_sctp_info *info;
15276 +
15277 +       info = (const struct ipt_sctp_info *)matchinfo;
15278 +
15279 +       return ip->proto == IPPROTO_SCTP
15280 +               && !(ip->invflags & IPT_INV_PROTO)
15281 +               && matchsize == IPT_ALIGN(sizeof(struct ipt_sctp_info))
15282 +               && !(info->flags & ~IPT_SCTP_VALID_FLAGS)
15283 +               && !(info->invflags & ~IPT_SCTP_VALID_FLAGS)
15284 +               && !(info->invflags & ~info->flags)
15285 +               && ((!(info->flags & IPT_SCTP_CHUNK_TYPES)) || 
15286 +                       (info->chunk_match_type &
15287 +                               (SCTP_CHUNK_MATCH_ALL 
15288 +                               | SCTP_CHUNK_MATCH_ANY
15289 +                               | SCTP_CHUNK_MATCH_ONLY)));
15290 +}
15291 +
15292 +static struct ipt_match sctp_match = 
15293 +{ 
15294 +       .list = { NULL, NULL},
15295 +       .name = "sctp",
15296 +       .match = &match,
15297 +       .checkentry = &checkentry,
15298 +       .destroy = NULL,
15299 +       .me = THIS_MODULE
15300 +};
15301 +
15302 +static int __init init(void)
15303 +{
15304 +       return ipt_register_match(&sctp_match);
15305 +}
15306 +
15307 +static void __exit fini(void)
15308 +{
15309 +       ipt_unregister_match(&sctp_match);
15310 +}
15311 +
15312 +module_init(init);
15313 +module_exit(fini);
15314 +
15315 +MODULE_LICENSE("GPL");
15316 +MODULE_AUTHOR("Kiran Kumar Immidi");
15317 +MODULE_DESCRIPTION("Match for SCTP protocol packets");
15318 +
15319 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_string.c linux-2.6.6/net/ipv4/netfilter/ipt_string.c
15320 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_string.c     1970-01-01 01:00:00.000000000 +0100
15321 +++ linux-2.6.6/net/ipv4/netfilter/ipt_string.c 2004-05-18 14:28:58.000000000 +0200
15322 @@ -0,0 +1,183 @@
15323 +/* Kernel module to match a string into a packet.
15324 + *
15325 + * Copyright (C) 2000 Emmanuel Roger  <winfield@freegates.be>
15326 + * 
15327 + * ChangeLog
15328 + *     24.03.2004: Eric Lauriault <elauri@lacitec.on.ca>
15329 + *             Initial 2.6 port
15330 + *     19.02.2002: Gianni Tedesco <gianni@ecsc.co.uk>
15331 + *             Fixed SMP re-entrancy problem using per-cpu data areas
15332 + *             for the skip/shift tables.
15333 + *     02.05.2001: Gianni Tedesco <gianni@ecsc.co.uk>
15334 + *             Fixed kernel panic, due to overrunning boyer moore string
15335 + *             tables. Also slightly tweaked heuristic for deciding what
15336 + *             search algo to use.
15337 + *     27.01.2001: Gianni Tedesco <gianni@ecsc.co.uk>
15338 + *             Implemented Boyer Moore Sublinear search algorithm
15339 + *             alongside the existing linear search based on memcmp().
15340 + *             Also a quick check to decide which method to use on a per
15341 + *             packet basis.
15342 + */
15343 +
15344 +#include <linux/smp.h>
15345 +#include <linux/percpu.h>
15346 +#include <linux/module.h>
15347 +#include <linux/skbuff.h>
15348 +#include <linux/file.h>
15349 +#include <net/sock.h>
15350 +
15351 +#include <linux/netfilter_ipv4/ip_tables.h>
15352 +#include <linux/netfilter_ipv4/ipt_string.h>
15353 +
15354 +MODULE_LICENSE("GPL");
15355 +
15356 +struct string_per_cpu {
15357 +       int skip[BM_MAX_HLEN];
15358 +       int shift[BM_MAX_HLEN];
15359 +       int len[BM_MAX_HLEN];
15360 +};
15361 +
15362 +static DEFINE_PER_CPU(struct string_per_cpu, bm_string_data);
15363 +
15364 +
15365 +/* Boyer Moore Sublinear string search - VERY FAST */
15366 +char *search_sublinear (char *needle, char *haystack, int needle_len, int haystack_len) 
15367 +{
15368 +       int M1, right_end, sk, sh;  
15369 +       int ended, j, i;
15370 +
15371 +       int *skip, *shift, *len;
15372 +       
15373 +       /* use data suitable for this CPU */
15374 +       shift=__get_cpu_var(bm_string_data).shift;
15375 +       skip=__get_cpu_var(bm_string_data).skip;
15376 +       len=__get_cpu_var(bm_string_data).len;
15377 +       
15378 +       /* Setup skip/shift tables */
15379 +       M1 = right_end = needle_len-1;
15380 +       for (i = 0; i < BM_MAX_HLEN; i++) skip[i] = needle_len;  
15381 +       for (i = 0; needle[i]; i++) skip[(int)needle[i]] = M1 - i;
15382 +
15383 +       for (i = 1; i < needle_len; i++) {   
15384 +               for (j = 0; j < needle_len && needle[M1 - j] == needle[M1 - i - j]; j++);  
15385 +               len[i] = j;  
15386 +       }  
15387 +
15388 +       shift[0] = 1;  
15389 +       for (i = 1; i < needle_len; i++) shift[i] = needle_len;  
15390 +       for (i = M1; i > 0; i--) shift[len[i]] = i;  
15391 +       ended = 0;  
15392 +       
15393 +       for (i = 0; i < needle_len; i++) {  
15394 +               if (len[i] == M1 - i) ended = i;  
15395 +               if (ended) shift[i] = ended;  
15396 +       }  
15397 +
15398 +       /* Do the search*/  
15399 +       while (right_end < haystack_len)
15400 +       {
15401 +               for (i = 0; i < needle_len && haystack[right_end - i] == needle[M1 - i]; i++);  
15402 +               if (i == needle_len) {
15403 +                       return haystack+(right_end - M1);
15404 +               }
15405 +               
15406 +               sk = skip[(int)haystack[right_end - i]];  
15407 +               sh = shift[i];
15408 +               right_end = max(right_end - i + sk, right_end + sh);  
15409 +       }
15410 +
15411 +       return NULL;
15412 +}  
15413 +
15414 +/* Linear string search based on memcmp() */
15415 +char *search_linear (char *needle, char *haystack, int needle_len, int haystack_len) 
15416 +{
15417 +       char *k = haystack + (haystack_len-needle_len);
15418 +       char *t = haystack;
15419 +       
15420 +       while ( t <= k ) {
15421 +               if (memcmp(t, needle, needle_len) == 0)
15422 +                       return t;
15423 +               t++;
15424 +       }
15425 +
15426 +       return NULL;
15427 +}
15428 +
15429 +static int
15430 +match(const struct sk_buff *skb,
15431 +      const struct net_device *in,
15432 +      const struct net_device *out,
15433 +      const void *matchinfo,
15434 +      int offset,
15435 +      int *hotdrop)
15436 +{
15437 +       const struct ipt_string_info *info = matchinfo;
15438 +       struct iphdr *ip = skb->nh.iph;
15439 +       int hlen, nlen;
15440 +       char *needle, *haystack;
15441 +       proc_ipt_search search=search_linear;
15442 +
15443 +       if ( !ip ) return 0;
15444 +
15445 +       /* get lenghts, and validate them */
15446 +       nlen=info->len;
15447 +       hlen=ntohs(ip->tot_len)-(ip->ihl*4);
15448 +       if ( nlen > hlen ) return 0;
15449 +
15450 +       needle=(char *)&info->string;
15451 +       haystack=(char *)ip+(ip->ihl*4);
15452 +
15453 +       /* The sublinear search comes in to its own
15454 +        * on the larger packets */
15455 +       if ( (hlen>IPT_STRING_HAYSTACK_THRESH) &&
15456 +               (nlen>IPT_STRING_NEEDLE_THRESH) ) {
15457 +               if ( hlen < BM_MAX_HLEN ) {
15458 +                       search=search_sublinear;
15459 +               }else{
15460 +                       if (net_ratelimit())
15461 +                               printk(KERN_INFO "ipt_string: Packet too big "
15462 +                                       "to attempt sublinear string search "
15463 +                                       "(%d bytes)\n", hlen );
15464 +               }
15465 +       }
15466 +       
15467 +    return ((search(needle, haystack, nlen, hlen)!=NULL) ^ info->invert);
15468 +}
15469 +
15470 +static int
15471 +checkentry(const char *tablename,
15472 +           const struct ipt_ip *ip,
15473 +           void *matchinfo,
15474 +           unsigned int matchsize,
15475 +           unsigned int hook_mask)
15476 +{
15477 +
15478 +       if (matchsize != IPT_ALIGN(sizeof(struct ipt_string_info)))
15479 +               return 0;
15480 +
15481 +       return 1;
15482 +}
15483 +
15484 +static struct ipt_match string_match = {
15485 +    .name = "string",
15486 +    .match = &match,
15487 +    .checkentry = &checkentry,
15488 +    .me = THIS_MODULE
15489 +};
15490 +
15491 +
15492 +static int __init init(void)
15493 +{
15494 +       return ipt_register_match(&string_match);
15495 +}
15496 +
15497 +static void __exit fini(void)
15498 +{
15499 +       ipt_unregister_match(&string_match);
15500 +}
15501 +
15502 +module_init(init);
15503 +module_exit(fini);
15504 +
15505 +
15506 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_time.c linux-2.6.6/net/ipv4/netfilter/ipt_time.c
15507 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_time.c       1970-01-01 01:00:00.000000000 +0100
15508 +++ linux-2.6.6/net/ipv4/netfilter/ipt_time.c   2004-05-18 14:28:50.000000000 +0200
15509 @@ -0,0 +1,189 @@
15510 +/*
15511 +  This is a module which is used for time matching
15512 +  It is using some modified code from dietlibc (localtime() function)
15513 +  that you can find at http://www.fefe.de/dietlibc/
15514 +  This file is distributed under the terms of the GNU General Public
15515 +  License (GPL). Copies of the GPL can be obtained from: ftp://prep.ai.mit.edu/pub/gnu/GPL
15516 +  2001-05-04 Fabrice MARIE <fabrice@netfilter.org> : initial development.
15517 +  2001-21-05 Fabrice MARIE <fabrice@netfilter.org> : bug fix in the match code,
15518 +     thanks to "Zeng Yu" <zengy@capitel.com.cn> for bug report.
15519 +  2001-26-09 Fabrice MARIE <fabrice@netfilter.org> : force the match to be in LOCAL_IN or PRE_ROUTING only.
15520 +  2001-30-11 Fabrice : added the possibility to use the match in FORWARD/OUTPUT with a little hack,
15521 +     added Nguyen Dang Phuoc Dong <dongnd@tlnet.com.vn> patch to support timezones.
15522 +  2004-05-02 Fabrice : added support for date matching, from an idea of Fabien COELHO.
15523 +*/
15524 +
15525 +#include <linux/module.h>
15526 +#include <linux/skbuff.h>
15527 +#include <linux/netfilter_ipv4/ip_tables.h>
15528 +#include <linux/netfilter_ipv4/ipt_time.h>
15529 +#include <linux/time.h>
15530 +
15531 +MODULE_AUTHOR("Fabrice MARIE <fabrice@netfilter.org>");
15532 +MODULE_DESCRIPTION("Match arrival timestamp/date");
15533 +MODULE_LICENSE("GPL");
15534 +
15535 +struct tm
15536 +{
15537 +       int tm_sec;                   /* Seconds.     [0-60] (1 leap second) */
15538 +       int tm_min;                   /* Minutes.     [0-59] */
15539 +       int tm_hour;                  /* Hours.       [0-23] */
15540 +       int tm_mday;                  /* Day.         [1-31] */
15541 +       int tm_mon;                   /* Month.       [0-11] */
15542 +       int tm_year;                  /* Year - 1900.  */
15543 +       int tm_wday;                  /* Day of week. [0-6] */
15544 +       int tm_yday;                  /* Days in year.[0-365] */
15545 +       int tm_isdst;                 /* DST.         [-1/0/1]*/
15546 +
15547 +       long int tm_gmtoff;           /* we don't care, we count from GMT */
15548 +       const char *tm_zone;          /* we don't care, we count from GMT */
15549 +};
15550 +
15551 +void
15552 +localtime(const time_t *timepr, struct tm *r);
15553 +
15554 +static int
15555 +match(const struct sk_buff *skb,
15556 +      const struct net_device *in,
15557 +      const struct net_device *out,
15558 +      const void *matchinfo,
15559 +      int offset,
15560 +      const void *hdr,
15561 +      u_int16_t datalen,
15562 +      int *hotdrop)
15563 +{
15564 +       const struct ipt_time_info *info = matchinfo;   /* match info for rule */
15565 +       struct tm currenttime;                          /* time human readable */
15566 +       u_int8_t days_of_week[7] = {64, 32, 16, 8, 4, 2, 1};
15567 +       u_int16_t packet_time;
15568 +       struct timeval kerneltimeval;
15569 +       time_t packet_local_time;
15570 +
15571 +       /* if kerneltime=1, we don't read the skb->timestamp but kernel time instead */
15572 +       if (info->kerneltime)
15573 +       {
15574 +               do_gettimeofday(&kerneltimeval);
15575 +               packet_local_time = kerneltimeval.tv_sec;
15576 +       }
15577 +       else
15578 +               packet_local_time = skb->stamp.tv_sec;
15579 +
15580 +       /* First we make sure we are in the date start-stop boundaries */
15581 +       if ((packet_local_time < info->date_start) || (packet_local_time > info->date_stop))
15582 +               return 0; /* We are outside the date boundaries */
15583 +
15584 +       /* Transform the timestamp of the packet, in a human readable form */
15585 +       localtime(&packet_local_time, &currenttime);
15586 +
15587 +       /* check if we match this timestamp, we start by the days... */
15588 +       if ((days_of_week[currenttime.tm_wday] & info->days_match) != days_of_week[currenttime.tm_wday])
15589 +               return 0; /* the day doesn't match */
15590 +
15591 +       /* ... check the time now */
15592 +       packet_time = (currenttime.tm_hour * 60) + currenttime.tm_min;
15593 +       if ((packet_time < info->time_start) || (packet_time > info->time_stop))
15594 +               return 0;
15595 +
15596 +       /* here we match ! */
15597 +       return 1;
15598 +}
15599 +
15600 +static int
15601 +checkentry(const char *tablename,
15602 +           const struct ipt_ip *ip,
15603 +           void *matchinfo,
15604 +           unsigned int matchsize,
15605 +           unsigned int hook_mask)
15606 +{
15607 +       struct ipt_time_info *info = matchinfo;   /* match info for rule */
15608 +
15609 +       /* First, check that we are in the correct hooks */
15610 +       if (hook_mask
15611 +            & ~((1 << NF_IP_PRE_ROUTING) | (1 << NF_IP_LOCAL_IN) | (1 << NF_IP_FORWARD) | (1 << NF_IP_LOCAL_OUT)))
15612 +       {
15613 +               printk("ipt_time: error, only valid for PRE_ROUTING, LOCAL_IN, FORWARD and OUTPUT)\n");
15614 +               return 0;
15615 +       }
15616 +       /* we use the kerneltime if we are in forward or output */
15617 +       info->kerneltime = 1;
15618 +       if (hook_mask & ~((1 << NF_IP_FORWARD) | (1 << NF_IP_LOCAL_OUT))) 
15619 +               /* we use the skb time */
15620 +               info->kerneltime = 0;
15621 +
15622 +       /* Check the size */
15623 +       if (matchsize != IPT_ALIGN(sizeof(struct ipt_time_info)))
15624 +               return 0;
15625 +       /* Now check the coherence of the data ... */
15626 +       if ((info->time_start > 1439) ||        /* 23*60+59 = 1439*/
15627 +           (info->time_stop  > 1439))
15628 +       {
15629 +               printk(KERN_WARNING "ipt_time: invalid argument\n");
15630 +               return 0;
15631 +       }
15632 +
15633 +       return 1;
15634 +}
15635 +
15636 +static struct ipt_match time_match
15637 += { { NULL, NULL }, "time", &match, &checkentry, NULL, THIS_MODULE };
15638 +
15639 +static int __init init(void)
15640 +{
15641 +       printk("ipt_time loading\n");
15642 +       return ipt_register_match(&time_match);
15643 +}
15644 +
15645 +static void __exit fini(void)
15646 +{
15647 +       ipt_unregister_match(&time_match);
15648 +       printk("ipt_time unloaded\n");
15649 +}
15650 +
15651 +module_init(init);
15652 +module_exit(fini);
15653 +
15654 +
15655 +/* The part below is borowed and modified from dietlibc */
15656 +
15657 +/* seconds per day */
15658 +#define SPD 24*60*60
15659 +
15660 +void
15661 +localtime(const time_t *timepr, struct tm *r) {
15662 +       time_t i;
15663 +       time_t timep;
15664 +       extern struct timezone sys_tz;
15665 +       const unsigned int __spm[12] =
15666 +               { 0,
15667 +                 (31),
15668 +                 (31+28),
15669 +                 (31+28+31),
15670 +                 (31+28+31+30),
15671 +                 (31+28+31+30+31),
15672 +                 (31+28+31+30+31+30),
15673 +                 (31+28+31+30+31+30+31),
15674 +                 (31+28+31+30+31+30+31+31),
15675 +                 (31+28+31+30+31+30+31+31+30),
15676 +                 (31+28+31+30+31+30+31+31+30+31),
15677 +                 (31+28+31+30+31+30+31+31+30+31+30),
15678 +               };
15679 +       register time_t work;
15680 +
15681 +       timep = (*timepr) - (sys_tz.tz_minuteswest * 60);
15682 +       work=timep%(SPD);
15683 +       r->tm_sec=work%60; work/=60;
15684 +       r->tm_min=work%60; r->tm_hour=work/60;
15685 +       work=timep/(SPD);
15686 +       r->tm_wday=(4+work)%7;
15687 +       for (i=1970; ; ++i) {
15688 +               register time_t k= (!(i%4) && ((i%100) || !(i%400)))?366:365;
15689 +               if (work>k)
15690 +                       work-=k;
15691 +               else
15692 +                       break;
15693 +       }
15694 +       r->tm_year=i-1900;
15695 +       for (i=11; i && __spm[i]>work; --i) ;
15696 +       r->tm_mon=i;
15697 +       r->tm_mday=work-__spm[i]+1;
15698 +}
15699 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_u32.c linux-2.6.6/net/ipv4/netfilter/ipt_u32.c
15700 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_u32.c        1970-01-01 01:00:00.000000000 +0100
15701 +++ linux-2.6.6/net/ipv4/netfilter/ipt_u32.c    2004-05-18 14:28:50.000000000 +0200
15702 @@ -0,0 +1,211 @@
15703 +/* Kernel module to match u32 packet content. */
15704 +
15705 +/* 
15706 +U32 tests whether quantities of up to 4 bytes extracted from a packet 
15707 +have specified values.  The specification of what to extract is general 
15708 +enough to find data at given offsets from tcp headers or payloads.
15709 +
15710 + --u32 tests
15711 + The argument amounts to a program in a small language described below.
15712 + tests := location = value |  tests && location = value
15713 + value := range | value , range
15714 + range := number | number : number
15715 +  a single number, n, is interpreted the same as n:n
15716 +  n:m is interpreted as the range of numbers >=n and <=m
15717 + location := number | location operator number
15718 + operator := & | << | >> | @
15719 +
15720 + The operators &, <<, >>, && mean the same as in c.  The = is really a set
15721 + membership operator and the value syntax describes a set.  The @ operator
15722 + is what allows moving to the next header and is described further below.
15723 +
15724 + *** Until I can find out how to avoid it, there are some artificial limits
15725 + on the size of the tests:
15726 + - no more than 10 ='s (and 9 &&'s) in the u32 argument
15727 + - no more than 10 ranges (and 9 commas) per value
15728 + - no more than 10 numbers (and 9 operators) per location
15729 +
15730 + To describe the meaning of location, imagine the following machine that
15731 + interprets it.  There are three registers:
15732 +  A is of type char*, initially the address of the IP header
15733 +  B and C are unsigned 32 bit integers, initially zero
15734 +
15735 +  The instructions are:
15736 +   number      B = number;
15737 +               C = (*(A+B)<<24)+(*(A+B+1)<<16)+(*(A+B+2)<<8)+*(A+B+3)
15738 +   &number     C = C&number
15739 +   <<number    C = C<<number
15740 +   >>number    C = C>>number
15741 +   @number     A = A+C; then do the instruction number
15742 +  Any access of memory outside [skb->head,skb->end] causes the match to fail.
15743 +  Otherwise the result of the computation is the final value of C.
15744 +
15745 + Whitespace is allowed but not required in the tests.
15746 + However the characters that do occur there are likely to require
15747 + shell quoting, so it's a good idea to enclose the arguments in quotes.
15748 +
15749 +Example:
15750 + match IP packets with total length >= 256
15751 + The IP header contains a total length field in bytes 2-3.
15752 + --u32 "0&0xFFFF=0x100:0xFFFF" 
15753 + read bytes 0-3
15754 + AND that with FFFF (giving bytes 2-3),
15755 + and test whether that's in the range [0x100:0xFFFF]
15756 +
15757 +Example: (more realistic, hence more complicated)
15758 + match icmp packets with icmp type 0
15759 + First test that it's an icmp packet, true iff byte 9 (protocol) = 1
15760 + --u32 "6&0xFF=1 && ...
15761 + read bytes 6-9, use & to throw away bytes 6-8 and compare the result to 1
15762 + Next test that it's not a fragment.
15763 +  (If so it might be part of such a packet but we can't always tell.)
15764 +  n.b. This test is generally needed if you want to match anything
15765 +  beyond the IP header.
15766 + The last 6 bits of byte 6 and all of byte 7 are 0 iff this is a complete
15767 + packet (not a fragment).  Alternatively, you can allow first fragments
15768 + by only testing the last 5 bits of byte 6.
15769 + ... 4&0x3FFF=0 && ...
15770 + Last test: the first byte past the IP header (the type) is 0
15771 + This is where we have to use the @syntax.  The length of the IP header
15772 + (IHL) in 32 bit words is stored in the right half of byte 0 of the
15773 + IP header itself.
15774 + ... 0>>22&0x3C@0>>24=0"
15775 + The first 0 means read bytes 0-3,
15776 + >>22 means shift that 22 bits to the right.  Shifting 24 bits would give
15777 +   the first byte, so only 22 bits is four times that plus a few more bits.
15778 + &3C then eliminates the two extra bits on the right and the first four 
15779 + bits of the first byte.
15780 + For instance, if IHL=5 then the IP header is 20 (4 x 5) bytes long.
15781 + In this case bytes 0-1 are (in binary) xxxx0101 yyzzzzzz, 
15782 + >>22 gives the 10 bit value xxxx0101yy and &3C gives 010100.
15783 + @ means to use this number as a new offset into the packet, and read
15784 + four bytes starting from there.  This is the first 4 bytes of the icmp
15785 + payload, of which byte 0 is the icmp type.  Therefore we simply shift
15786 + the value 24 to the right to throw out all but the first byte and compare
15787 + the result with 0.
15788 +
15789 +Example: 
15790 + tcp payload bytes 8-12 is any of 1, 2, 5 or 8
15791 + First we test that the packet is a tcp packet (similar to icmp).
15792 + --u32 "6&0xFF=6 && ...
15793 + Next, test that it's not a fragment (same as above).
15794 + ... 0>>22&0x3C@12>>26&0x3C@8=1,2,5,8"
15795 + 0>>22&3C as above computes the number of bytes in the IP header.
15796 + @ makes this the new offset into the packet, which is the start of the
15797 + tcp header.  The length of the tcp header (again in 32 bit words) is
15798 + the left half of byte 12 of the tcp header.  The 12>>26&3C
15799 + computes this length in bytes (similar to the IP header before).
15800 + @ makes this the new offset, which is the start of the tcp payload.
15801 + Finally 8 reads bytes 8-12 of the payload and = checks whether the
15802 + result is any of 1, 2, 5 or 8
15803 +*/
15804 +
15805 +#include <linux/module.h>
15806 +#include <linux/skbuff.h>
15807 +
15808 +#include <linux/netfilter_ipv4/ipt_u32.h>
15809 +#include <linux/netfilter_ipv4/ip_tables.h>
15810 +
15811 +/* #include <asm-i386/timex.h> for timing */
15812 +
15813 +MODULE_AUTHOR("Don Cohen <don@isis.cs3-inc.com>");
15814 +MODULE_DESCRIPTION("IP tables u32 matching module");
15815 +MODULE_LICENSE("GPL");
15816 +
15817 +static int
15818 +match(const struct sk_buff *skb,
15819 +      const struct net_device *in,
15820 +      const struct net_device *out,
15821 +      const void *matchinfo,
15822 +      int offset,
15823 +      const void *hdr,
15824 +      u_int16_t datalen,
15825 +      int *hotdrop)
15826 +{
15827 +       const struct ipt_u32 *data = matchinfo;
15828 +       int testind, i;
15829 +       unsigned char* origbase = (char*)skb->nh.iph;
15830 +       unsigned char* base = origbase;
15831 +       unsigned char* head = skb->head;
15832 +       unsigned char* end = skb->end;
15833 +       int nnums, nvals;
15834 +       u_int32_t pos, val;
15835 +       /* unsigned long long cycles1, cycles2, cycles3, cycles4;
15836 +          cycles1 = get_cycles(); */
15837 +
15838 +       for (testind=0; testind < data->ntests; testind++) {
15839 +               base = origbase; /* reset for each test */
15840 +               pos = data->tests[testind].location[0].number;
15841 +               if (base+pos+3 > end || base+pos < head) 
15842 +                       return 0;
15843 +               val = (base[pos]<<24) + (base[pos+1]<<16) +
15844 +                       (base[pos+2]<<8) + base[pos+3];
15845 +               nnums = data->tests[testind].nnums;
15846 +               for (i=1; i < nnums; i++) {
15847 +                       u_int32_t number = data->tests[testind].location[i].number;
15848 +                       switch (data->tests[testind].location[i].nextop) {
15849 +                       case IPT_U32_AND: 
15850 +                               val = val & number; 
15851 +                               break;
15852 +                       case IPT_U32_LEFTSH: 
15853 +                               val = val << number;
15854 +                               break;
15855 +                       case IPT_U32_RIGHTSH: 
15856 +                               val = val >> number; 
15857 +                               break;
15858 +                       case IPT_U32_AT:
15859 +                               base = base + val;
15860 +                               pos = number;
15861 +                               if (base+pos+3 > end || base+pos < head) 
15862 +                                       return 0;
15863 +                               val = (base[pos]<<24) + (base[pos+1]<<16) +
15864 +                                       (base[pos+2]<<8) + base[pos+3];
15865 +                               break;
15866 +                       }
15867 +               }
15868 +               nvals = data->tests[testind].nvalues;
15869 +               for (i=0; i < nvals; i++) {
15870 +                       if ((data->tests[testind].value[i].min <= val) &&
15871 +                           (val <= data->tests[testind].value[i].max)) {
15872 +                               break;
15873 +                       }
15874 +               }
15875 +               if (i >= data->tests[testind].nvalues) {
15876 +                       /* cycles2 = get_cycles(); 
15877 +                          printk("failed %d in %d cycles\n", testind, 
15878 +                                 cycles2-cycles1); */
15879 +                       return 0;
15880 +               }
15881 +       }
15882 +       /* cycles2 = get_cycles();
15883 +          printk("succeeded in %d cycles\n", cycles2-cycles1); */
15884 +       return 1;
15885 +}
15886 +
15887 +static int
15888 +checkentry(const char *tablename,
15889 +           const struct ipt_ip *ip,
15890 +           void *matchinfo,
15891 +           unsigned int matchsize,
15892 +           unsigned int hook_mask)
15893 +{
15894 +       if (matchsize != IPT_ALIGN(sizeof(struct ipt_u32)))
15895 +               return 0;
15896 +       return 1;
15897 +}
15898 +
15899 +static struct ipt_match u32_match
15900 += { { NULL, NULL }, "u32", &match, &checkentry, NULL, THIS_MODULE };
15901 +
15902 +static int __init init(void)
15903 +{
15904 +       return ipt_register_match(&u32_match);
15905 +}
15906 +
15907 +static void __exit fini(void)
15908 +{
15909 +       ipt_unregister_match(&u32_match);
15910 +}
15911 +
15912 +module_init(init);
15913 +module_exit(fini);
15914 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_unclean.c linux-2.6.6/net/ipv4/netfilter/ipt_unclean.c
15915 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_unclean.c    1970-01-01 01:00:00.000000000 +0100
15916 +++ linux-2.6.6/net/ipv4/netfilter/ipt_unclean.c        2004-05-18 14:28:50.000000000 +0200
15917 @@ -0,0 +1,604 @@
15918 +/* Kernel module to match suspect packets. */
15919 +#include <linux/module.h>
15920 +#include <linux/skbuff.h>
15921 +#include <linux/ip.h>
15922 +#include <linux/udp.h>
15923 +#include <linux/tcp.h>
15924 +#include <linux/icmp.h>
15925 +#include <net/checksum.h>
15926 +
15927 +#include <linux/netfilter_ipv4/ip_tables.h>
15928 +
15929 +#define limpk(format, args...)                                          \
15930 +do {                                                                    \
15931 +       if (net_ratelimit())                                             \
15932 +               printk("ipt_unclean: %s" format,                         \
15933 +                      embedded ? "(embedded packet) " : "" , ## args);  \
15934 +} while(0)
15935 +
15936 +enum icmp_error_status
15937 +{
15938 +       ICMP_MAY_BE_ERROR,
15939 +       ICMP_IS_ERROR,
15940 +       ICMP_NOT_ERROR
15941 +};
15942 +
15943 +struct icmp_info
15944 +{
15945 +       size_t min_len, max_len;
15946 +       enum icmp_error_status err;
15947 +       u_int8_t min_code, max_code;
15948 +};
15949 +
15950 +static int
15951 +check_ip(struct iphdr *iph, size_t length, int embedded);
15952 +
15953 +/* ICMP-specific checks. */
15954 +static int
15955 +check_icmp(const struct icmphdr *icmph,
15956 +          u_int16_t datalen,
15957 +          unsigned int offset,
15958 +          int more_frags,
15959 +          int embedded)
15960 +{
15961 +       static struct icmp_info info[]
15962 +               = { [ICMP_ECHOREPLY]
15963 +                   = { 8, 65536, ICMP_NOT_ERROR, 0, 0 },
15964 +                   [ICMP_DEST_UNREACH]
15965 +                   = { 8 + 28, 65536, ICMP_IS_ERROR, 0, 15 },
15966 +                   [ICMP_SOURCE_QUENCH]
15967 +                   = { 8 + 28, 65536, ICMP_IS_ERROR, 0, 0 },
15968 +                   [ICMP_REDIRECT]
15969 +                   = { 8 + 28, 65536, ICMP_IS_ERROR, 0, 3 },
15970 +                   [ICMP_ECHO]
15971 +                   = { 8, 65536, ICMP_NOT_ERROR, 0, 0  },
15972 +                   /* Router advertisement. */
15973 +                   [9]
15974 +                   = { 8, 8 + 255 * 8, ICMP_NOT_ERROR, 0, 0 },
15975 +                   /* Router solicitation. */
15976 +                   [10]
15977 +                   = { 8, 8, ICMP_NOT_ERROR, 0, 0 },
15978 +                   [ICMP_TIME_EXCEEDED]
15979 +                   = { 8 + 28, 65536, ICMP_IS_ERROR, 0, 1  },
15980 +                   [ICMP_PARAMETERPROB]
15981 +                   = { 8 + 28, 65536, ICMP_IS_ERROR, 0, 1 },
15982 +                   [ICMP_TIMESTAMP]
15983 +                   = { 20, 20, ICMP_NOT_ERROR, 0, 0 },
15984 +                   [ICMP_TIMESTAMPREPLY]
15985 +                   = { 20, 20, ICMP_NOT_ERROR, 0, 0 },
15986 +                   [ICMP_INFO_REQUEST]
15987 +                   = { 8, 65536, ICMP_NOT_ERROR, 0, 0 },
15988 +                   [ICMP_INFO_REPLY]
15989 +                   = { 8, 65536, ICMP_NOT_ERROR, 0, 0 },
15990 +                   [ICMP_ADDRESS]
15991 +                   = { 12, 12, ICMP_NOT_ERROR, 0, 0 },
15992 +                   [ICMP_ADDRESSREPLY]
15993 +                   = { 12, 12, ICMP_NOT_ERROR, 0, 0 } };
15994 +
15995 +       /* Can't do anything if it's a fragment. */
15996 +       if (offset)
15997 +               return 1;
15998 +
15999 +       /* Must cover type and code. */
16000 +       if (datalen < 2) {
16001 +               limpk("ICMP len=%u too short\n", datalen);
16002 +               return 0;
16003 +       }
16004 +
16005 +       /* If not embedded. */
16006 +       if (!embedded) {
16007 +               /* Bad checksum?  Don't print, just ignore. */
16008 +               if (!more_frags
16009 +                   && ip_compute_csum((unsigned char *) icmph, datalen) != 0)
16010 +                       return 0;
16011 +
16012 +               /* CHECK: Truncated ICMP (even if first fragment). */
16013 +               if (icmph->type < sizeof(info)/sizeof(struct icmp_info)
16014 +                   && info[icmph->type].min_len != 0
16015 +                   && datalen < info[icmph->type].min_len) {
16016 +                       limpk("ICMP type %u len %u too short\n",
16017 +                             icmph->type, datalen);
16018 +                       return 0;
16019 +               }
16020 +
16021 +               /* CHECK: Check within known error ICMPs. */
16022 +               if (icmph->type < sizeof(info)/sizeof(struct icmp_info)
16023 +                   && info[icmph->type].err == ICMP_IS_ERROR) {
16024 +                       /* CHECK: Embedded packet must be at least
16025 +                          length of iph + 8 bytes. */
16026 +                       struct iphdr *inner = (void *)icmph + 8;
16027 +
16028 +                       /* datalen > 8 since all ICMP_IS_ERROR types
16029 +                           have min length > 8 */
16030 +                       if (datalen - 8 < sizeof(struct iphdr)) {
16031 +                               limpk("ICMP error internal way too short\n");
16032 +                               return 0;
16033 +                       }
16034 +                       if (datalen - 8 < inner->ihl*4 + 8) {
16035 +                               limpk("ICMP error internal too short\n");
16036 +                               return 0;
16037 +                       }
16038 +                       if (!check_ip(inner, datalen - 8, 1))
16039 +                               return 0;
16040 +               }
16041 +       } else {
16042 +               /* CHECK: Can't embed ICMP unless known non-error. */
16043 +               if (icmph->type >= sizeof(info)/sizeof(struct icmp_info)
16044 +                   || info[icmph->type].err != ICMP_NOT_ERROR) {
16045 +                       limpk("ICMP type %u not embeddable\n",
16046 +                             icmph->type);
16047 +                       return 0;
16048 +               }
16049 +       }
16050 +
16051 +       /* CHECK: Invalid ICMP codes. */
16052 +       if (icmph->type < sizeof(info)/sizeof(struct icmp_info)
16053 +           && (icmph->code < info[icmph->type].min_code
16054 +               || icmph->code > info[icmph->type].max_code)) {
16055 +               limpk("ICMP type=%u code=%u\n",
16056 +                     icmph->type, icmph->code);
16057 +               return 0;
16058 +       }
16059 +
16060 +       /* CHECK: Above maximum length. */
16061 +       if (icmph->type < sizeof(info)/sizeof(struct icmp_info)
16062 +           && info[icmph->type].max_len != 0
16063 +           && datalen > info[icmph->type].max_len) {
16064 +               limpk("ICMP type=%u too long: %u bytes\n",
16065 +                     icmph->type, datalen);
16066 +               return 0;
16067 +       }
16068 +
16069 +       switch (icmph->type) {
16070 +       case ICMP_PARAMETERPROB: {
16071 +               /* CHECK: Problem param must be within error packet's
16072 +                * IP header. */
16073 +               struct iphdr *iph = (void *)icmph + 8;
16074 +               u_int32_t arg = ntohl(icmph->un.gateway);
16075 +
16076 +               if (icmph->code == 0) {
16077 +                       /* Code 0 means that upper 8 bits is pointer
16078 +                           to problem. */
16079 +                       if ((arg >> 24) >= iph->ihl*4) {
16080 +                               limpk("ICMP PARAMETERPROB ptr = %u\n",
16081 +                                     ntohl(icmph->un.gateway) >> 24);
16082 +                               return 0;
16083 +                       }
16084 +                       arg &= 0x00FFFFFF;
16085 +               }
16086 +
16087 +               /* CHECK: Rest must be zero. */
16088 +               if (arg) {
16089 +                       limpk("ICMP PARAMETERPROB nonzero arg = %u\n",
16090 +                             arg);
16091 +                       return 0;
16092 +               }
16093 +               break;
16094 +       }
16095 +
16096 +       case ICMP_TIME_EXCEEDED:
16097 +       case ICMP_SOURCE_QUENCH:
16098 +               /* CHECK: Unused must be zero. */
16099 +               if (icmph->un.gateway != 0) {
16100 +                       limpk("ICMP type=%u unused = %u\n",
16101 +                             icmph->type, ntohl(icmph->un.gateway));
16102 +                       return 0;
16103 +               }
16104 +               break;
16105 +       }
16106 +
16107 +       return 1;
16108 +}
16109 +
16110 +/* UDP-specific checks. */
16111 +static int
16112 +check_udp(const struct iphdr *iph,
16113 +         const struct udphdr *udph,
16114 +         u_int16_t datalen,
16115 +         unsigned int offset,
16116 +         int more_frags,
16117 +         int embedded)
16118 +{
16119 +       /* Can't do anything if it's a fragment. */
16120 +       if (offset)
16121 +               return 1;
16122 +
16123 +       /* CHECK: Must cover UDP header. */
16124 +       if (datalen < sizeof(struct udphdr)) {
16125 +               limpk("UDP len=%u too short\n", datalen);
16126 +               return 0;
16127 +       }
16128 +
16129 +       /* Bad checksum?  Don't print, just say it's unclean. */
16130 +       /* FIXME: SRC ROUTE packets won't match checksum --RR */
16131 +       if (!more_frags && !embedded && udph->check
16132 +           && csum_tcpudp_magic(iph->saddr, iph->daddr, datalen, IPPROTO_UDP,
16133 +                                csum_partial((char *)udph, datalen, 0)) != 0)
16134 +               return 0;
16135 +
16136 +       /* CHECK: Destination port can't be zero. */
16137 +       if (!udph->dest) {
16138 +               limpk("UDP zero destination port\n");
16139 +               return 0;
16140 +       }
16141 +
16142 +       if (!more_frags) {
16143 +               if (!embedded) {
16144 +                       /* CHECK: UDP length must match. */
16145 +                       if (ntohs(udph->len) != datalen) {
16146 +                               limpk("UDP len too short %u vs %u\n",
16147 +                                     ntohs(udph->len), datalen);
16148 +                               return 0;
16149 +                       }
16150 +               } else {
16151 +                       /* CHECK: UDP length be >= this truncated pkt. */
16152 +                       if (ntohs(udph->len) < datalen) {
16153 +                               limpk("UDP len too long %u vs %u\n",
16154 +                                     ntohs(udph->len), datalen);
16155 +                               return 0;
16156 +                       }
16157 +               }
16158 +       } else {
16159 +               /* CHECK: UDP length must be > this frag's length. */
16160 +               if (ntohs(udph->len) <= datalen) {
16161 +                       limpk("UDP fragment len too short %u vs %u\n",
16162 +                             ntohs(udph->len), datalen);
16163 +                       return 0;
16164 +               }
16165 +       }
16166 +
16167 +       return 1;
16168 +}
16169 +
16170 +#define        TH_FIN  0x01
16171 +#define        TH_SYN  0x02
16172 +#define        TH_RST  0x04
16173 +#define        TH_PUSH 0x08
16174 +#define        TH_ACK  0x10
16175 +#define        TH_URG  0x20
16176 +#define        TH_ECE  0x40
16177 +#define        TH_CWR  0x80
16178 +
16179 +/* table of valid flag combinations - ECE and CWR are always valid */
16180 +static u8 tcp_valid_flags[(TH_FIN|TH_SYN|TH_RST|TH_PUSH|TH_ACK|TH_URG) + 1] =
16181 +{
16182 +       [TH_SYN]                        = 1,
16183 +       [TH_SYN|TH_ACK]                 = 1,
16184 +       [TH_RST]                        = 1,
16185 +       [TH_RST|TH_ACK]                 = 1,
16186 +       [TH_RST|TH_ACK|TH_PUSH]         = 1,
16187 +       [TH_FIN|TH_ACK]                 = 1,
16188 +       [TH_ACK]                        = 1,
16189 +       [TH_ACK|TH_PUSH]                = 1,
16190 +       [TH_ACK|TH_URG]                 = 1,
16191 +       [TH_ACK|TH_URG|TH_PUSH]         = 1,
16192 +       [TH_FIN|TH_ACK|TH_PUSH]         = 1,
16193 +       [TH_FIN|TH_ACK|TH_URG]          = 1,
16194 +       [TH_FIN|TH_ACK|TH_URG|TH_PUSH]  = 1
16195 +};
16196 +
16197 +/* TCP-specific checks. */
16198 +static int
16199 +check_tcp(const struct iphdr *iph,
16200 +         const struct tcphdr *tcph,
16201 +         u_int16_t datalen,
16202 +         unsigned int offset,
16203 +         int more_frags,
16204 +         int embedded)
16205 +{
16206 +       u_int8_t *opt = (u_int8_t *)tcph;
16207 +       u_int8_t *endhdr = (u_int8_t *)tcph + tcph->doff * 4;
16208 +       u_int8_t tcpflags;
16209 +       int end_of_options = 0;
16210 +       size_t i;
16211 +
16212 +       /* CHECK: Can't have offset=1: used to override TCP syn-checks. */
16213 +       /* In fact, this is caught below (offset < 516). */
16214 +
16215 +       /* Can't do anything if it's a fragment. */
16216 +       if (offset)
16217 +               return 1;
16218 +
16219 +       /* CHECK: Smaller than minimal TCP hdr. */
16220 +       if (datalen < sizeof(struct tcphdr)) {
16221 +               if (!embedded) {
16222 +                       limpk("Packet length %u < TCP header.\n", datalen);
16223 +                       return 0;
16224 +               }
16225 +               /* Must have ports available (datalen >= 8), from
16226 +                   check_icmp which set embedded = 1 */
16227 +               /* CHECK: TCP ports inside ICMP error */
16228 +               if (!tcph->source || !tcph->dest) {
16229 +                       limpk("Zero TCP ports %u/%u.\n",
16230 +                             htons(tcph->source), htons(tcph->dest));
16231 +                       return 0;
16232 +               }
16233 +               return 1;
16234 +       }
16235 +
16236 +       /* CHECK: Smaller than actual TCP hdr. */
16237 +       if (datalen < tcph->doff * 4) {
16238 +               if (!embedded) {
16239 +                       limpk("Packet length %u < actual TCP header.\n",
16240 +                             datalen);
16241 +                       return 0;
16242 +               } else
16243 +                       return 1;
16244 +       }
16245 +
16246 +       /* Bad checksum?  Don't print, just say it's unclean. */
16247 +       /* FIXME: SRC ROUTE packets won't match checksum --RR */
16248 +       if (!more_frags && !embedded
16249 +           && csum_tcpudp_magic(iph->saddr, iph->daddr, datalen, IPPROTO_TCP,
16250 +                                csum_partial((char *)tcph, datalen, 0)) != 0)
16251 +               return 0;
16252 +
16253 +       /* CHECK: TCP ports non-zero */
16254 +       if (!tcph->source || !tcph->dest) {
16255 +               limpk("Zero TCP ports %u/%u.\n",
16256 +                     htons(tcph->source), htons(tcph->dest));
16257 +               return 0;
16258 +       }
16259 +
16260 +       /* CHECK: TCP reserved bits zero. */
16261 +       if(tcp_flag_word(tcph) & TCP_RESERVED_BITS) {
16262 +               limpk("TCP reserved bits not zero\n");
16263 +               return 0;
16264 +       }
16265 +
16266 +       /* CHECK: TCP flags. */
16267 +       tcpflags = (((u_int8_t *)tcph)[13] & ~(TH_ECE|TH_CWR));
16268 +       if (!tcp_valid_flags[tcpflags]) {
16269 +               limpk("TCP flags bad: %u\n", tcpflags);
16270 +               return 0;
16271 +       }
16272 +
16273 +       for (i = sizeof(struct tcphdr); i < tcph->doff * 4; ) {
16274 +               switch (opt[i]) {
16275 +               case 0:
16276 +                       end_of_options = 1;
16277 +                       i++;
16278 +                       break;
16279 +               case 1:
16280 +                       i++;
16281 +                       break;
16282 +               default:
16283 +                       /* CHECK: options after EOO. */
16284 +                       if (end_of_options) {
16285 +                               limpk("TCP option %u after end\n",
16286 +                                     opt[i]);
16287 +                               return 0;
16288 +                       }
16289 +                       /* CHECK: options at tail. */
16290 +                       else if (i+1 >= tcph->doff * 4) {
16291 +                               limpk("TCP option %u at tail\n",
16292 +                                     opt[i]);
16293 +                               return 0;
16294 +                       }
16295 +                       /* CHECK: zero-length options. */
16296 +                       else if (opt[i+1] == 0) {
16297 +                               limpk("TCP option %u 0 len\n",
16298 +                                     opt[i]);
16299 +                               return 0;
16300 +                       }
16301 +                       /* CHECK: oversize options. */
16302 +                       else if (&opt[i] + opt[i+1] > endhdr) {
16303 +                               limpk("TCP option %u at %Zu too long\n",
16304 +                                     (unsigned int) opt[i], i);
16305 +                               return 0;
16306 +                       }
16307 +                       /* Move to next option */
16308 +                       i += opt[i+1];
16309 +               }
16310 +       }
16311 +
16312 +       return 1;
16313 +}
16314 +
16315 +/* Returns 1 if ok */
16316 +/* Standard IP checks. */
16317 +static int
16318 +check_ip(struct iphdr *iph, size_t length, int embedded)
16319 +{
16320 +       u_int8_t *opt = (u_int8_t *)iph;
16321 +       u_int8_t *endhdr = (u_int8_t *)iph + iph->ihl * 4;
16322 +       int end_of_options = 0;
16323 +       void *protoh;
16324 +       size_t datalen;
16325 +       unsigned int i;
16326 +       unsigned int offset;
16327 +
16328 +       /* Should only happen for local outgoing raw-socket packets. */
16329 +       /* CHECK: length >= ip header. */
16330 +       if (length < sizeof(struct iphdr) || length < iph->ihl * 4) {
16331 +               limpk("Packet length %Zu < IP header.\n", length);
16332 +               return 0;
16333 +       }
16334 +
16335 +       offset = ntohs(iph->frag_off) & IP_OFFSET;
16336 +       protoh = (void *)iph + iph->ihl * 4;
16337 +       datalen = length - iph->ihl * 4;
16338 +
16339 +       /* CHECK: Embedded fragment. */
16340 +       if (embedded && offset) {
16341 +               limpk("Embedded fragment.\n");
16342 +               return 0;
16343 +       }
16344 +
16345 +       for (i = sizeof(struct iphdr); i < iph->ihl * 4; ) {
16346 +               switch (opt[i]) {
16347 +               case 0:
16348 +                       end_of_options = 1;
16349 +                       i++;
16350 +                       break;
16351 +               case 1:
16352 +                       i++;
16353 +                       break;
16354 +               default:
16355 +                       /* CHECK: options after EOO. */
16356 +                       if (end_of_options) {
16357 +                               limpk("IP option %u after end\n",
16358 +                                     opt[i]);
16359 +                               return 0;
16360 +                       }
16361 +                       /* CHECK: options at tail. */
16362 +                       else if (i+1 >= iph->ihl * 4) {
16363 +                               limpk("IP option %u at tail\n",
16364 +                                     opt[i]);
16365 +                               return 0;
16366 +                       }
16367 +                       /* CHECK: zero-length or one-length options. */
16368 +                       else if (opt[i+1] < 2) {
16369 +                               limpk("IP option %u %u len\n",
16370 +                                     opt[i], opt[i+1]);
16371 +                               return 0;
16372 +                       }
16373 +                       /* CHECK: oversize options. */
16374 +                       else if (&opt[i] + opt[i+1] > endhdr) {
16375 +                               limpk("IP option %u at %u too long\n",
16376 +                                     opt[i], i);
16377 +                               return 0;
16378 +                       }
16379 +                       /* Move to next option */
16380 +                       i += opt[i+1];
16381 +               }
16382 +       }
16383 +
16384 +       /* Fragment checks. */
16385 +
16386 +       /* CHECK: More fragments, but doesn't fill 8-byte boundary. */
16387 +       if ((ntohs(iph->frag_off) & IP_MF)
16388 +           && (ntohs(iph->tot_len) % 8) != 0) {
16389 +               limpk("Truncated fragment %u long.\n", ntohs(iph->tot_len));
16390 +               return 0;
16391 +       }
16392 +
16393 +       /* CHECK: Oversize fragment a-la Ping of Death. */
16394 +       if (offset * 8 + datalen > 65535) {
16395 +               limpk("Oversize fragment to %u.\n", offset * 8);
16396 +               return 0;
16397 +       }
16398 +
16399 +       /* CHECK: DF set and offset or MF set. */
16400 +       if ((ntohs(iph->frag_off) & IP_DF)
16401 +           && (offset || (ntohs(iph->frag_off) & IP_MF))) {
16402 +               limpk("DF set and offset=%u, MF=%u.\n",
16403 +                     offset, ntohs(iph->frag_off) & IP_MF);
16404 +               return 0;
16405 +       }
16406 +
16407 +       /* CHECK: Zero-sized fragments. */
16408 +       if ((offset || (ntohs(iph->frag_off) & IP_MF))
16409 +           && datalen == 0) {
16410 +               limpk("Zero size fragment offset=%u\n", offset);
16411 +               return 0;
16412 +       }
16413 +
16414 +       /* Note: we can have even middle fragments smaller than this:
16415 +          consider a large packet passing through a 600MTU then
16416 +          576MTU link: this gives a fragment of 24 data bytes.  But
16417 +          everyone packs fragments largest first, hence a fragment
16418 +          can't START before 576 - MAX_IP_HEADER_LEN. */
16419 +
16420 +       /* Used to be min-size 576: I recall Alan Cox saying ax25 goes
16421 +          down to 128 (576 taken from RFC 791: All hosts must be
16422 +          prepared to accept datagrams of up to 576 octets).  Use 128
16423 +          here. */
16424 +#define MIN_LIKELY_MTU 128
16425 +       /* CHECK: Min size of first frag = 128. */
16426 +       if ((ntohs(iph->frag_off) & IP_MF)
16427 +           && offset == 0
16428 +           && ntohs(iph->tot_len) < MIN_LIKELY_MTU) {
16429 +               limpk("First fragment size %u < %u\n", ntohs(iph->tot_len),
16430 +                     MIN_LIKELY_MTU);
16431 +               return 0;
16432 +       }
16433 +
16434 +       /* CHECK: Min offset of frag = 128 - IP hdr len. */
16435 +       if (offset && offset * 8 < MIN_LIKELY_MTU - iph->ihl * 4) {
16436 +               limpk("Fragment starts at %u < %u\n", offset * 8,
16437 +                     MIN_LIKELY_MTU - iph->ihl * 4);
16438 +               return 0;
16439 +       }
16440 +
16441 +       /* CHECK: Protocol specification non-zero. */
16442 +       if (iph->protocol == 0) {
16443 +               limpk("Zero protocol\n");
16444 +               return 0;
16445 +       }
16446 +
16447 +       /* CHECK: Do not use what is unused.
16448 +        * First bit of fragmentation flags should be unused.
16449 +        * May be used by OS fingerprinting tools.
16450 +        * 04 Jun 2002, Maciej Soltysiak, solt@dns.toxicfilms.tv
16451 +        */
16452 +       if (ntohs(iph->frag_off)>>15) {
16453 +               limpk("IP unused bit set\n");
16454 +               return 0;
16455 +       }
16456 +
16457 +       /* Per-protocol checks. */
16458 +       switch (iph->protocol) {
16459 +       case IPPROTO_ICMP:
16460 +               return check_icmp(protoh, datalen, offset,
16461 +                                 (ntohs(iph->frag_off) & IP_MF),
16462 +                                 embedded);
16463 +
16464 +       case IPPROTO_UDP:
16465 +               return check_udp(iph, protoh, datalen, offset,
16466 +                                (ntohs(iph->frag_off) & IP_MF),
16467 +                                embedded);
16468 +
16469 +       case IPPROTO_TCP:
16470 +               return check_tcp(iph, protoh, datalen, offset,
16471 +                                (ntohs(iph->frag_off) & IP_MF),
16472 +                                embedded);
16473 +       default:
16474 +               /* Ignorance is bliss. */
16475 +               return 1;
16476 +       }
16477 +}
16478 +
16479 +static int
16480 +match(const struct sk_buff *skb,
16481 +      const struct net_device *in,
16482 +      const struct net_device *out,
16483 +      const void *matchinfo,
16484 +      int offset,
16485 +      const void *hdr,
16486 +      u_int16_t datalen,
16487 +      int *hotdrop)
16488 +{
16489 +       return !check_ip(skb->nh.iph, skb->len, 0);
16490 +}
16491 +
16492 +/* Called when user tries to insert an entry of this type. */
16493 +static int
16494 +checkentry(const char *tablename,
16495 +          const struct ipt_ip *ip,
16496 +          void *matchinfo,
16497 +          unsigned int matchsize,
16498 +          unsigned int hook_mask)
16499 +{
16500 +       if (matchsize != IPT_ALIGN(0))
16501 +               return 0;
16502 +
16503 +       return 1;
16504 +}
16505 +
16506 +static struct ipt_match unclean_match
16507 += { { NULL, NULL }, "unclean", &match, &checkentry, NULL, THIS_MODULE };
16508 +
16509 +static int __init init(void)
16510 +{
16511 +       return ipt_register_match(&unclean_match);
16512 +}
16513 +
16514 +static void __exit fini(void)
16515 +{
16516 +       ipt_unregister_match(&unclean_match);
16517 +}
16518 +
16519 +module_init(init);
16520 +module_exit(fini);
16521 +MODULE_LICENSE("GPL");
16522 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/iptable_filter.c linux-2.6.6/net/ipv4/netfilter/iptable_filter.c
16523 --- linux-2.6.6.org/net/ipv4/netfilter/iptable_filter.c 2004-05-10 04:32:28.000000000 +0200
16524 +++ linux-2.6.6/net/ipv4/netfilter/iptable_filter.c     2004-05-18 14:28:50.000000000 +0200
16525 @@ -59,7 +59,7 @@
16526                 0,
16527                 sizeof(struct ipt_entry),
16528                 sizeof(struct ipt_standard),
16529 -               0, { 0, 0 }, { } },
16530 +               0, NULL, 0, { 0, 0 }, { } },
16531               { { { { IPT_ALIGN(sizeof(struct ipt_standard_target)), "" } }, { } },
16532                 -NF_ACCEPT - 1 } },
16533             /* FORWARD */
16534 @@ -67,7 +67,7 @@
16535                 0,
16536                 sizeof(struct ipt_entry),
16537                 sizeof(struct ipt_standard),
16538 -               0, { 0, 0 }, { } },
16539 +               0, NULL, 0, { 0, 0 }, { } },
16540               { { { { IPT_ALIGN(sizeof(struct ipt_standard_target)), "" } }, { } },
16541                 -NF_ACCEPT - 1 } },
16542             /* LOCAL_OUT */
16543 @@ -75,7 +75,7 @@
16544                 0,
16545                 sizeof(struct ipt_entry),
16546                 sizeof(struct ipt_standard),
16547 -               0, { 0, 0 }, { } },
16548 +               0, NULL, 0, { 0, 0 }, { } },
16549               { { { { IPT_ALIGN(sizeof(struct ipt_standard_target)), "" } }, { } },
16550                 -NF_ACCEPT - 1 } }
16551      },
16552 @@ -84,7 +84,7 @@
16553         0,
16554         sizeof(struct ipt_entry),
16555         sizeof(struct ipt_error),
16556 -       0, { 0, 0 }, { } },
16557 +       0, NULL, 0, { 0, 0 }, { } },
16558        { { { { IPT_ALIGN(sizeof(struct ipt_error_target)), IPT_ERROR_TARGET } },
16559           { } },
16560         "ERROR"
16561 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/iptable_mangle.c linux-2.6.6/net/ipv4/netfilter/iptable_mangle.c
16562 --- linux-2.6.6.org/net/ipv4/netfilter/iptable_mangle.c 2004-05-10 04:33:14.000000000 +0200
16563 +++ linux-2.6.6/net/ipv4/netfilter/iptable_mangle.c     2004-05-18 14:28:50.000000000 +0200
16564 @@ -74,7 +74,7 @@
16565                 0,
16566                 sizeof(struct ipt_entry),
16567                 sizeof(struct ipt_standard),
16568 -               0, { 0, 0 }, { } },
16569 +               0, NULL, 0, { 0, 0 }, { } },
16570               { { { { IPT_ALIGN(sizeof(struct ipt_standard_target)), "" } }, { } },
16571                 -NF_ACCEPT - 1 } },
16572             /* LOCAL_IN */
16573 @@ -82,7 +82,7 @@
16574                 0,
16575                 sizeof(struct ipt_entry),
16576                 sizeof(struct ipt_standard),
16577 -               0, { 0, 0 }, { } },
16578 +               0, NULL, 0, { 0, 0 }, { } },
16579               { { { { IPT_ALIGN(sizeof(struct ipt_standard_target)), "" } }, { } },
16580                 -NF_ACCEPT - 1 } },
16581             /* FORWARD */
16582 @@ -90,7 +90,7 @@
16583                 0,
16584                 sizeof(struct ipt_entry),
16585                 sizeof(struct ipt_standard),
16586 -               0, { 0, 0 }, { } },
16587 +               0, NULL, 0, { 0, 0 }, { } },
16588               { { { { IPT_ALIGN(sizeof(struct ipt_standard_target)), "" } }, { } },
16589                 -NF_ACCEPT - 1 } },
16590             /* LOCAL_OUT */
16591 @@ -98,7 +98,7 @@
16592                 0,
16593                 sizeof(struct ipt_entry),
16594                 sizeof(struct ipt_standard),
16595 -               0, { 0, 0 }, { } },
16596 +               0, NULL, 0, { 0, 0 }, { } },
16597               { { { { IPT_ALIGN(sizeof(struct ipt_standard_target)), "" } }, { } },
16598                 -NF_ACCEPT - 1 } },
16599             /* POST_ROUTING */
16600 @@ -106,7 +106,7 @@
16601                 0,
16602                 sizeof(struct ipt_entry),
16603                 sizeof(struct ipt_standard),
16604 -               0, { 0, 0 }, { } },
16605 +               0, NULL, 0, { 0, 0 }, { } },
16606               { { { { IPT_ALIGN(sizeof(struct ipt_standard_target)), "" } }, { } },
16607                 -NF_ACCEPT - 1 } },
16608      },
16609 @@ -115,7 +115,7 @@
16610         0,
16611         sizeof(struct ipt_entry),
16612         sizeof(struct ipt_error),
16613 -       0, { 0, 0 }, { } },
16614 +       0, NULL, 0, { 0, 0 }, { } },
16615        { { { { IPT_ALIGN(sizeof(struct ipt_error_target)), IPT_ERROR_TARGET } },
16616           { } },
16617         "ERROR"
16618 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/iptable_raw.c linux-2.6.6/net/ipv4/netfilter/iptable_raw.c
16619 --- linux-2.6.6.org/net/ipv4/netfilter/iptable_raw.c    2004-05-10 04:33:19.000000000 +0200
16620 +++ linux-2.6.6/net/ipv4/netfilter/iptable_raw.c        2004-05-18 14:28:50.000000000 +0200
16621 @@ -46,7 +46,7 @@
16622                 0,
16623                 sizeof(struct ipt_entry),
16624                 sizeof(struct ipt_standard),
16625 -               0, { 0, 0 }, { } },
16626 +               0, NULL, 0, { 0, 0 }, { } },
16627               { { { { IPT_ALIGN(sizeof(struct ipt_standard_target)), "" } }, { } },
16628                 -NF_ACCEPT - 1 } },
16629             /* LOCAL_OUT */
16630 @@ -54,7 +54,7 @@
16631                 0,
16632                 sizeof(struct ipt_entry),
16633                 sizeof(struct ipt_standard),
16634 -               0, { 0, 0 }, { } },
16635 +               0, NULL, 0, { 0, 0 }, { } },
16636               { { { { IPT_ALIGN(sizeof(struct ipt_standard_target)), "" } }, { } },
16637                 -NF_ACCEPT - 1 } }
16638      },
16639 @@ -63,7 +63,7 @@
16640         0,
16641         sizeof(struct ipt_entry),
16642         sizeof(struct ipt_error),
16643 -       0, { 0, 0 }, { } },
16644 +       0, NULL, 0, { 0, 0 }, { } },
16645        { { { { IPT_ALIGN(sizeof(struct ipt_error_target)), IPT_ERROR_TARGET } },
16646           { } },
16647         "ERROR"
16648 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/raw.c linux-2.6.6/net/ipv4/raw.c
16649 --- linux-2.6.6.org/net/ipv4/raw.c      2004-05-10 04:32:38.000000000 +0200
16650 +++ linux-2.6.6/net/ipv4/raw.c  2004-05-18 14:28:50.000000000 +0200
16651 @@ -249,6 +249,7 @@
16652                 kfree_skb(skb);
16653                 return NET_RX_DROP;
16654         }
16655 +       nf_reset(skb);
16656  
16657         skb_push(skb, skb->data - skb->nh.raw);
16658  
16659 @@ -307,7 +308,7 @@
16660         }
16661  
16662         err = NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, skb, NULL, rt->u.dst.dev,
16663 -                     dst_output);
16664 +                     ip_dst_output);
16665         if (err > 0)
16666                 err = inet->recverr ? net_xmit_errno(err) : 0;
16667         if (err)
16668 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/tcp_ipv4.c linux-2.6.6/net/ipv4/tcp_ipv4.c
16669 --- linux-2.6.6.org/net/ipv4/tcp_ipv4.c 2004-05-18 14:08:55.000000000 +0200
16670 +++ linux-2.6.6/net/ipv4/tcp_ipv4.c     2004-05-18 14:28:50.000000000 +0200
16671 @@ -1785,6 +1785,7 @@
16672  
16673         if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb))
16674                 goto discard_and_relse;
16675 +       nf_reset(skb);
16676  
16677         if (sk_filter(sk, skb, 0))
16678                 goto discard_and_relse;
16679 @@ -2636,6 +2637,7 @@
16680  EXPORT_SYMBOL(tcp_v4_connect);
16681  EXPORT_SYMBOL(tcp_v4_do_rcv);
16682  EXPORT_SYMBOL(tcp_v4_lookup_listener);
16683 +EXPORT_SYMBOL(tcp_v4_lookup);
16684  EXPORT_SYMBOL(tcp_v4_rebuild_header);
16685  EXPORT_SYMBOL(tcp_v4_remember_stamp);
16686  EXPORT_SYMBOL(tcp_v4_send_check);
16687 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/udp.c linux-2.6.6/net/ipv4/udp.c
16688 --- linux-2.6.6.org/net/ipv4/udp.c      2004-05-10 04:32:01.000000000 +0200
16689 +++ linux-2.6.6/net/ipv4/udp.c  2004-05-18 14:28:50.000000000 +0200
16690 @@ -1045,6 +1045,7 @@
16691                 kfree_skb(skb);
16692                 return -1;
16693         }
16694 +       nf_reset(skb);
16695  
16696         if (up->encap_type) {
16697                 /*
16698 @@ -1210,6 +1211,7 @@
16699  
16700         if (!xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb))
16701                 goto drop;
16702 +       nf_reset(skb);
16703  
16704         /* No socket. Drop packet silently, if checksum is wrong */
16705         if (udp_checksum_complete(skb))
16706 @@ -1558,6 +1560,7 @@
16707  EXPORT_SYMBOL(udp_port_rover);
16708  EXPORT_SYMBOL(udp_prot);
16709  EXPORT_SYMBOL(udp_sendmsg);
16710 +EXPORT_SYMBOL(udp_v4_lookup);
16711  
16712  #ifdef CONFIG_PROC_FS
16713  EXPORT_SYMBOL(udp_proc_register);
16714 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/xfrm4_tunnel.c linux-2.6.6/net/ipv4/xfrm4_tunnel.c
16715 --- linux-2.6.6.org/net/ipv4/xfrm4_tunnel.c     2004-05-10 04:32:00.000000000 +0200
16716 +++ linux-2.6.6/net/ipv4/xfrm4_tunnel.c 2004-05-18 14:28:50.000000000 +0200
16717 @@ -76,6 +76,7 @@
16718                 err = -EHOSTUNREACH;
16719                 goto error_nolock;
16720         }
16721 +       IPCB(skb)->flags |= IPSKB_XFRM_TRANSFORMED;
16722         return NET_XMIT_BYPASS;
16723  
16724  error_nolock:
16725 @@ -170,6 +171,7 @@
16726         .handler        =       ipip_rcv,
16727         .err_handler    =       ipip_err,
16728         .no_policy      =       1,
16729 +       .xfrm_prot      =       1,
16730  };
16731  
16732  static int __init ipip_init(void)
16733 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv6/ip6_output.c linux-2.6.6/net/ipv6/ip6_output.c
16734 --- linux-2.6.6.org/net/ipv6/ip6_output.c       2004-05-10 04:31:59.000000000 +0200
16735 +++ linux-2.6.6/net/ipv6/ip6_output.c   2004-05-18 14:28:50.000000000 +0200
16736 @@ -805,6 +805,7 @@
16737         *dst = NULL;
16738         return err;
16739  }
16740 +EXPORT_SYMBOL(ip6_dst_lookup);
16741  
16742  int ip6_append_data(struct sock *sk, int getfrag(void *from, char *to, int offset, int len, int odd, struct sk_buff *skb),
16743                     void *from, int length, int transhdrlen,
16744 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv6/ip6_tunnel.c linux-2.6.6/net/ipv6/ip6_tunnel.c
16745 --- linux-2.6.6.org/net/ipv6/ip6_tunnel.c       2004-05-10 04:31:59.000000000 +0200
16746 +++ linux-2.6.6/net/ipv6/ip6_tunnel.c   2004-05-18 14:28:50.000000000 +0200
16747 @@ -715,13 +715,7 @@
16748         ipv6h->nexthdr = proto;
16749         ipv6_addr_copy(&ipv6h->saddr, &fl.fl6_src);
16750         ipv6_addr_copy(&ipv6h->daddr, &fl.fl6_dst);
16751 -#ifdef CONFIG_NETFILTER
16752 -       nf_conntrack_put(skb->nfct);
16753 -       skb->nfct = NULL;
16754 -#ifdef CONFIG_NETFILTER_DEBUG
16755 -       skb->nf_debug = 0;
16756 -#endif
16757 -#endif
16758 +       nf_reset(skb);
16759         pkt_len = skb->len;
16760         err = NF_HOOK(PF_INET6, NF_IP6_LOCAL_OUT, skb, NULL, 
16761                       skb->dst->dev, dst_output);
16762 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv6/netfilter/Kconfig linux-2.6.6/net/ipv6/netfilter/Kconfig
16763 --- linux-2.6.6.org/net/ipv6/netfilter/Kconfig  2004-05-10 04:33:13.000000000 +0200
16764 +++ linux-2.6.6/net/ipv6/netfilter/Kconfig      2004-05-18 14:28:50.000000000 +0200
16765 @@ -230,5 +230,107 @@
16766           <file:Documentation/modules.txt>.  If unsure, say `N'.
16767           help
16768  
16769 +config IP6_NF_TARGET_HL
16770 +       tristate  'HL target support'
16771 +       depends on IP6_NF_MANGLE
16772 +       help
16773 +         This option adds a `HL' target, which allows you to modify the value of
16774 +         IPv6 Hop Limit field.
16775 +       
16776 +         If you want to compile it as a module, say M here and read
16777 +         <file:Documentation/modules.txt>.  If unsure, say `N'.
16778 +
16779 +config IP6_NF_TARGET_REJECT
16780 +       tristate  'REJECT target support'
16781 +       depends on IP6_NF_FILTER
16782 +       help
16783 +         The REJECT target allows a filtering rule to specify that an ICMPv6
16784 +         error should be issued in response to an incoming packet, rather
16785 +         than silently being dropped.
16786 +       
16787 +         If you want to compile it as a module, say M here and read
16788 +         Documentation/modules.txt.  If unsure, say `N'.
16789 +
16790 +config IP6_NF_MATCH_FUZZY
16791 +       tristate  'Fuzzy match support'
16792 +       depends on IP6_NF_FILTER
16793 +       help
16794 +         This option adds a `fuzzy' match, which allows you to match
16795 +         packets according to a fuzzy logic based law.
16796 +       
16797 +         If you want to compile it as a module, say M here and read
16798 +         Documentation/modules.txt.  If unsure, say `N'.
16799 +
16800 +config IP6_NF_MATCH_NTH
16801 +       tristate  'Nth match support'
16802 +       depends on IP6_NF_IPTABLES
16803 +       help
16804 +         This option adds a `Nth' match, which allow you to make
16805 +         rules that match every Nth packet.  By default there are 
16806 +         16 different counters.
16807 +       
16808 +         [options]
16809 +          --every     Nth              Match every Nth packet
16810 +         [--counter]  num              Use counter 0-15 (default:0)
16811 +         [--start]    num              Initialize the counter at the number 'num'
16812 +                                       instead of 0. Must be between 0 and Nth-1
16813 +         [--packet]   num              Match on 'num' packet. Must be between 0
16814 +                                       and Nth-1.
16815 +       
16816 +                                       If --packet is used for a counter than
16817 +                                       there must be Nth number of --packet
16818 +                                       rules, covering all values between 0 and
16819 +                                       Nth-1 inclusively.
16820 +        
16821 +         If you want to compile it as a module, say M here and read
16822 +         Documentation/modules.txt.  If unsure, say `N'.
16823 +
16824 +config IP6_NF_MATCH_RANDOM
16825 +       tristate  'Random match support'
16826 +       depends on IP6_NF_IPTABLES
16827 +       help
16828 +         This option adds a `random' match,
16829 +         which allow you to match packets randomly
16830 +         following a given probability.
16831 +        
16832 +         If you want to compile it as a module, say M here and read
16833 +         Documentation/modules.txt.  If unsure, say `N'.
16834 +
16835 +config IP6_NF_TARGET_ROUTE
16836 +       tristate '    ROUTE target support'
16837 +       depends on IP6_NF_MANGLE
16838 +       help
16839 +         This option adds a `ROUTE' target, which enables you to setup unusual
16840 +         routes. The ROUTE target is also able to change the incoming interface
16841 +         of a packet.
16842 +       
16843 +         The target can be or not a final target. It has to be used inside the 
16844 +         mangle table.
16845 +         
16846 +         Not working as a module.
16847 +
16848 +config IP6_NF_TARGET_TRACE
16849 +       tristate  'TRACE target support'
16850 +       depends on IP6_NF_RAW
16851 +       help
16852 +         The TRACE target allows packets to be traced as those
16853 +         matches any subsequent rule in any table/rule. The matched
16854 +         rule and the packet is logged with the prefix
16855 +       
16856 +         TRACE: tablename/chainname/rulenum  
16857 +       
16858 +         If you want to compile it as a module, say M here and read
16859 +         <file:Documentation/modules.txt>.  If unsure, say `N'.
16860 +
16861 +config IP6_NF_MATCH_POLICY
16862 +       tristate "IPsec policy match support"
16863 +       depends on IP6_NF_IPTABLES && XFRM
16864 +       help
16865 +         Policy matching allows you to match packets based on the
16866 +         IPsec policy that was used during decapsulation/will
16867 +         be used during encapsulation.
16868 +
16869 +         To compile it as a module, choose M here.  If unsure, say N.
16870 +
16871  endmenu
16872  
16873 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv6/netfilter/Makefile linux-2.6.6/net/ipv6/netfilter/Makefile
16874 --- linux-2.6.6.org/net/ipv6/netfilter/Makefile 2004-05-10 04:32:39.000000000 +0200
16875 +++ linux-2.6.6/net/ipv6/netfilter/Makefile     2004-05-18 14:28:50.000000000 +0200
16876 @@ -8,18 +8,28 @@
16877  obj-$(CONFIG_IP6_NF_MATCH_MARK) += ip6t_mark.o
16878  obj-$(CONFIG_IP6_NF_MATCH_LENGTH) += ip6t_length.o
16879  obj-$(CONFIG_IP6_NF_MATCH_MAC) += ip6t_mac.o
16880 +obj-$(CONFIG_IP6_NF_MATCH_FUZZY) += ip6t_fuzzy.o
16881  obj-$(CONFIG_IP6_NF_MATCH_RT) += ip6t_rt.o
16882  obj-$(CONFIG_IP6_NF_MATCH_OPTS) += ip6t_hbh.o ip6t_dst.o
16883  obj-$(CONFIG_IP6_NF_MATCH_IPV6HEADER) += ip6t_ipv6header.o
16884  obj-$(CONFIG_IP6_NF_MATCH_FRAG) += ip6t_frag.o
16885  obj-$(CONFIG_IP6_NF_MATCH_AHESP) += ip6t_esp.o ip6t_ah.o
16886 +obj-$(CONFIG_IP6_NF_MATCH_POLICY) += ip6t_policy.o
16887  obj-$(CONFIG_IP6_NF_MATCH_EUI64) += ip6t_eui64.o
16888  obj-$(CONFIG_IP6_NF_MATCH_MULTIPORT) += ip6t_multiport.o
16889  obj-$(CONFIG_IP6_NF_MATCH_OWNER) += ip6t_owner.o
16890  obj-$(CONFIG_IP6_NF_FILTER) += ip6table_filter.o
16891  obj-$(CONFIG_IP6_NF_MANGLE) += ip6table_mangle.o
16892  obj-$(CONFIG_IP6_NF_TARGET_MARK) += ip6t_MARK.o
16893 +obj-$(CONFIG_IP6_NF_TARGET_ROUTE) += ip6t_ROUTE.o
16894 +obj-$(CONFIG_IP6_NF_TARGET_REJECT) += ip6t_REJECT.o
16895  obj-$(CONFIG_IP6_NF_QUEUE) += ip6_queue.o
16896  obj-$(CONFIG_IP6_NF_TARGET_LOG) += ip6t_LOG.o
16897 +
16898 +obj-$(CONFIG_IP6_NF_MATCH_RANDOM) += ip6t_random.o
16899 +
16900 +obj-$(CONFIG_IP6_NF_MATCH_NTH) += ip6t_nth.o
16901 +obj-$(CONFIG_IP6_NF_TARGET_HL) += ip6t_HL.o
16902  obj-$(CONFIG_IP6_NF_RAW) += ip6table_raw.o
16903 +obj-$(CONFIG_IP6_NF_TARGET_TRACE) += ip6t_TRACE.o
16904  obj-$(CONFIG_IP6_NF_MATCH_HL) += ip6t_hl.o
16905 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv6/netfilter/ip6_tables.c linux-2.6.6/net/ipv6/netfilter/ip6_tables.c
16906 --- linux-2.6.6.org/net/ipv6/netfilter/ip6_tables.c     2004-05-10 04:33:19.000000000 +0200
16907 +++ linux-2.6.6/net/ipv6/netfilter/ip6_tables.c 2004-05-18 14:28:50.000000000 +0200
16908 @@ -38,6 +38,14 @@
16909  #define IPV6_HDR_LEN   (sizeof(struct ipv6hdr))
16910  #define IPV6_OPTHDR_LEN        (sizeof(struct ipv6_opt_hdr))
16911  
16912 +static const char *hook6names[] = { 
16913 +       [NF_IP6_PRE_ROUTING] "PREROUTING",
16914 +       [NF_IP6_LOCAL_IN] "INPUT",
16915 +       [NF_IP6_FORWARD] "FORWARD",
16916 +       [NF_IP6_LOCAL_OUT] "OUTPUT",
16917 +       [NF_IP6_POST_ROUTING] "POSTROUTING",
16918 +};
16919 +
16920  /*#define DEBUG_IP_FIREWALL*/
16921  /*#define DEBUG_ALLOW_ALL*/ /* Useful for remote debugging */
16922  /*#define DEBUG_IP_FIREWALL_USER*/
16923 @@ -408,6 +416,12 @@
16924  
16925                         t = ip6t_get_target(e);
16926                         IP_NF_ASSERT(t->u.kernel.target);
16927 +
16928 +                       /* The packet traced and the rule isn't an unconditional return/END. */
16929 +                       if (((*pskb)->nfcache & NFC_TRACE) && e->rulenum) {
16930 +                               nf_log_packet(PF_INET6, hook, *pskb, in, out, "TRACE: %s/%s/%u ",
16931 +                                             table->name, e->chainname, e->rulenum);
16932 +                       }
16933                         /* Standard target? */
16934                         if (!t->u.kernel.target->target) {
16935                                 int v;
16936 @@ -561,6 +575,29 @@
16937         return find_inlist_lock(&ip6t_target, name, "ip6t_", error, mutex);
16938  }
16939  
16940 +static inline int
16941 +find_error_target(struct ip6t_entry *s, 
16942 +                 struct ip6t_entry *e,
16943 +                 char **chainname)
16944 +{
16945 +       struct ip6t_entry_target *t;
16946 +       static struct ip6t_entry *found = NULL;
16947 +
16948 +       if (s == e) {
16949 +               if (!found)
16950 +                       return 0;
16951 +               t = ip6t_get_target(found);
16952 +               if (strcmp(t->u.user.name, 
16953 +                          IP6T_ERROR_TARGET) == 0) {
16954 +                       *chainname = t->data;
16955 +                       return 1;
16956 +               }
16957 +       } else
16958 +               found = s;
16959 +       
16960 +       return 0;
16961 +}
16962 +
16963  /* All zeroes == unconditional rule. */
16964  static inline int
16965  unconditional(const struct ip6t_ip6 *ipv6)
16966 @@ -580,6 +617,8 @@
16967  mark_source_chains(struct ip6t_table_info *newinfo, unsigned int valid_hooks)
16968  {
16969         unsigned int hook;
16970 +       char *chainname = NULL;
16971 +       u_int32_t rulenum;
16972  
16973         /* No recursion; use packet counter to save back ptrs (reset
16974            to 0 as we leave), and comefrom to save source hook bitmask */
16975 @@ -593,6 +632,8 @@
16976  
16977                 /* Set initial back pointer. */
16978                 e->counters.pcnt = pos;
16979 +               rulenum = 1;
16980 +               chainname = (char *) hook6names[hook];
16981  
16982                 for (;;) {
16983                         struct ip6t_standard_target *t
16984 @@ -605,6 +646,8 @@
16985                         }
16986                         e->comefrom
16987                                 |= ((1 << hook) | (1 << NF_IP6_NUMHOOKS));
16988 +                       e->rulenum = rulenum++;
16989 +                       e->chainname = chainname;
16990  
16991                         /* Unconditional return/END. */
16992                         if (e->target_offset == sizeof(struct ip6t_entry)
16993 @@ -614,6 +657,10 @@
16994                             && unconditional(&e->ipv6)) {
16995                                 unsigned int oldpos, size;
16996  
16997 +                               /* Set unconditional rulenum to zero. */
16998 +                               e->rulenum = 0;
16999 +                               e->counters.bcnt = 0;
17000 +
17001                                 /* Return: backtrack through the last
17002                                    big jump. */
17003                                 do {
17004 @@ -639,6 +686,11 @@
17005                                                 (newinfo->entries + pos);
17006                                 } while (oldpos == pos + e->next_offset);
17007  
17008 +                               /* Restore chainname, rulenum. */
17009 +                               chainname = e->chainname;
17010 +                               rulenum = e->counters.bcnt;
17011 +                               e->counters.bcnt = 0;
17012 +
17013                                 /* Move along one */
17014                                 size = e->next_offset;
17015                                 e = (struct ip6t_entry *)
17016 @@ -654,6 +706,17 @@
17017                                         /* This a jump; chase it. */
17018                                         duprintf("Jump rule %u -> %u\n",
17019                                                  pos, newpos);
17020 +                                       e->counters.bcnt = rulenum++;
17021 +                                       rulenum = 1;
17022 +                                       e = (struct ip6t_entry *)
17023 +                                               (newinfo->entries + newpos);
17024 +                                       if (IP6T_ENTRY_ITERATE(newinfo->entries,
17025 +                                                              newinfo->size,
17026 +                                                              find_error_target,
17027 +                                                              e, &chainname) == 0) {
17028 +                                               printk("ip6_tables: table screwed up!\n");
17029 +                                               return 0;
17030 +                                       }
17031                                 } else {
17032                                         /* ... this is a fallthru */
17033                                         newpos = pos + e->next_offset;
17034 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv6/netfilter/ip6t_HL.c linux-2.6.6/net/ipv6/netfilter/ip6t_HL.c
17035 --- linux-2.6.6.org/net/ipv6/netfilter/ip6t_HL.c        1970-01-01 01:00:00.000000000 +0100
17036 +++ linux-2.6.6/net/ipv6/netfilter/ip6t_HL.c    2004-05-18 14:28:50.000000000 +0200
17037 @@ -0,0 +1,105 @@
17038 +/* 
17039 + * Hop Limit modification target for ip6tables
17040 + * Maciej Soltysiak <solt@dns.toxicfilms.tv>
17041 + * Based on HW's TTL module
17042 + *
17043 + * This software is distributed under the terms of GNU GPL
17044 + */
17045 +
17046 +#include <linux/module.h>
17047 +#include <linux/skbuff.h>
17048 +#include <linux/ip.h>
17049 +
17050 +#include <linux/netfilter_ipv6/ip6_tables.h>
17051 +#include <linux/netfilter_ipv6/ip6t_HL.h>
17052 +
17053 +MODULE_AUTHOR("Maciej Soltysiak <solt@dns.toxicfilms.tv>");
17054 +MODULE_DESCRIPTION("IP tables Hop Limit modification module");
17055 +MODULE_LICENSE("GPL");
17056 +
17057 +static unsigned int ip6t_hl_target(struct sk_buff **pskb, unsigned int hooknum,
17058 +               const struct net_device *in, const struct net_device *out,
17059 +               const void *targinfo, void *userinfo)
17060 +{
17061 +       struct ipv6hdr *ip6h = (*pskb)->nh.ipv6h;
17062 +       const struct ip6t_HL_info *info = targinfo;
17063 +       u_int16_t diffs[2];
17064 +       int new_hl;
17065 +                        
17066 +       switch (info->mode) {
17067 +               case IP6T_HL_SET:
17068 +                       new_hl = info->hop_limit;
17069 +                       break;
17070 +               case IP6T_HL_INC:
17071 +                       new_hl = ip6h->hop_limit + info->hop_limit;
17072 +                       if (new_hl > 255)
17073 +                               new_hl = 255;
17074 +                       break;
17075 +               case IP6T_HL_DEC:
17076 +                       new_hl = ip6h->hop_limit + info->hop_limit;
17077 +                       if (new_hl < 0)
17078 +                               new_hl = 0;
17079 +                       break;
17080 +               default:
17081 +                       new_hl = ip6h->hop_limit;
17082 +                       break;
17083 +       }
17084 +
17085 +       if (new_hl != ip6h->hop_limit) {
17086 +               diffs[0] = htons(((unsigned)ip6h->hop_limit) << 8) ^ 0xFFFF;
17087 +               ip6h->hop_limit = new_hl;
17088 +               diffs[1] = htons(((unsigned)ip6h->hop_limit) << 8);
17089 +       }
17090 +
17091 +       return IP6T_CONTINUE;
17092 +}
17093 +
17094 +static int ip6t_hl_checkentry(const char *tablename,
17095 +               const struct ip6t_entry *e,
17096 +               void *targinfo,
17097 +               unsigned int targinfosize,
17098 +               unsigned int hook_mask)
17099 +{
17100 +       struct ip6t_HL_info *info = targinfo;
17101 +
17102 +       if (targinfosize != IP6T_ALIGN(sizeof(struct ip6t_HL_info))) {
17103 +               printk(KERN_WARNING "HL: targinfosize %u != %Zu\n",
17104 +                               targinfosize,
17105 +                               IP6T_ALIGN(sizeof(struct ip6t_HL_info)));
17106 +               return 0;       
17107 +       }       
17108 +
17109 +       if (strcmp(tablename, "mangle")) {
17110 +               printk(KERN_WARNING "HL: can only be called from \"mangle\" table, not \"%s\"\n", tablename);
17111 +               return 0;
17112 +       }
17113 +
17114 +       if (info->mode > IP6T_HL_MAXMODE) {
17115 +               printk(KERN_WARNING "HL: invalid or unknown Mode %u\n", 
17116 +                       info->mode);
17117 +               return 0;
17118 +       }
17119 +
17120 +       if ((info->mode != IP6T_HL_SET) && (info->hop_limit == 0)) {
17121 +               printk(KERN_WARNING "HL: increment/decrement doesn't make sense with value 0\n");
17122 +               return 0;
17123 +       }
17124 +       
17125 +       return 1;
17126 +}
17127 +
17128 +static struct ip6t_target ip6t_HL = { { NULL, NULL }, "HL", 
17129 +       ip6t_hl_target, ip6t_hl_checkentry, NULL, THIS_MODULE };
17130 +
17131 +static int __init init(void)
17132 +{
17133 +       return ip6t_register_target(&ip6t_HL);
17134 +}
17135 +
17136 +static void __exit fini(void)
17137 +{
17138 +       ip6t_unregister_target(&ip6t_HL);
17139 +}
17140 +
17141 +module_init(init);
17142 +module_exit(fini);
17143 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv6/netfilter/ip6t_REJECT.c linux-2.6.6/net/ipv6/netfilter/ip6t_REJECT.c
17144 --- linux-2.6.6.org/net/ipv6/netfilter/ip6t_REJECT.c    1970-01-01 01:00:00.000000000 +0100
17145 +++ linux-2.6.6/net/ipv6/netfilter/ip6t_REJECT.c        2004-05-18 14:28:50.000000000 +0200
17146 @@ -0,0 +1,458 @@
17147 +/*
17148 + * IP6 tables REJECT target module
17149 + * Linux INET6 implementation
17150 + *
17151 + * Copyright (C)2003 USAGI/WIDE Project
17152 + *
17153 + * Authors:
17154 + *     Yasuyuki Kozakai        <yasuyuki.kozakai@toshiba.co.jp>
17155 + *
17156 + * Based on net/ipv4/netfilter/ipt_REJECT.c
17157 + *
17158 + * This program is free software; you can redistribute it and/or
17159 + * modify it under the terms of the GNU General Public License
17160 + * as published by the Free Software Foundation; either version
17161 + * 2 of the License, or (at your option) any later version.
17162 + */
17163 +
17164 +#include <linux/config.h>
17165 +#include <linux/module.h>
17166 +#include <linux/skbuff.h>
17167 +#include <linux/icmpv6.h>
17168 +#include <net/ipv6.h>
17169 +#include <net/tcp.h>
17170 +#include <net/icmp.h>
17171 +#include <net/ip6_fib.h>
17172 +#include <net/ip6_route.h>
17173 +#include <net/flow.h>
17174 +#include <linux/netfilter_ipv6/ip6_tables.h>
17175 +#include <linux/netfilter_ipv6/ip6t_REJECT.h>
17176 +
17177 +MODULE_AUTHOR("Yasuyuki KOZAKAI <yasuyuki.kozakai@toshiba.co.jp>");
17178 +MODULE_DESCRIPTION("IP6 tables REJECT target module");
17179 +MODULE_LICENSE("GPL");
17180 +
17181 +#if 0
17182 +#define DEBUGP printk
17183 +#else
17184 +#define DEBUGP(format, args...)
17185 +#endif
17186 +
17187 +#if 0
17188 +static void connection_attach(struct sk_buff *new_skb, struct nf_ct_info *nfct)
17189 +{
17190 +       void (*attach)(struct sk_buff *, struct nf_ct_info *);
17191 +       if (nfct && (attach = ip6_ct_attach) != NULL) {
17192 +               mb();
17193 +               attach(new_skb, nfct);
17194 +       }
17195 +}
17196 +#endif
17197 +
17198 +static int maybe_reroute(struct sk_buff *skb)
17199 +{
17200 +       if (skb->nfcache & NFC_ALTERED){
17201 +               if (ip6_route_me_harder(skb) != 0){
17202 +                       kfree_skb(skb);
17203 +                       return -EINVAL;
17204 +               }
17205 +       }
17206 +
17207 +       return dst_output(skb);
17208 +}
17209 +
17210 +/* Send RST reply */
17211 +static void send_reset(struct sk_buff *oldskb)
17212 +{
17213 +       struct sk_buff *nskb;
17214 +       struct tcphdr otcph, *tcph;
17215 +       unsigned int otcplen, tcphoff, hh_len;
17216 +       int needs_ack;
17217 +       struct ipv6hdr *oip6h = oldskb->nh.ipv6h, *ip6h;
17218 +       struct dst_entry *dst = NULL;
17219 +       u8 proto;
17220 +       struct flowi fl;
17221 +       proto = oip6h->nexthdr;
17222 +       int err;
17223 +
17224 +       if ((!(ipv6_addr_type(&oip6h->saddr) & IPV6_ADDR_UNICAST)) ||
17225 +           (!(ipv6_addr_type(&oip6h->daddr) & IPV6_ADDR_UNICAST))) {
17226 +               DEBUGP("ip6t_REJECT: addr is not unicast.\n");
17227 +               return;
17228 +       }
17229 +
17230 +       tcphoff = ipv6_skip_exthdr(oldskb, ((u8*)(oip6h+1) - oldskb->data),
17231 +                                  &proto, oldskb->len - ((u8*)(oip6h+1)
17232 +                                                         - oldskb->data));
17233 +
17234 +       if ((tcphoff < 0) || (tcphoff > oldskb->len)) {
17235 +               DEBUGP("ip6t_REJECT: Can't get TCP header.\n");
17236 +               return;
17237 +       }
17238 +
17239 +       otcplen = oldskb->len - tcphoff;
17240 +
17241 +       /* IP header checks: fragment, too short. */
17242 +       if ((proto != IPPROTO_TCP) || (otcplen < sizeof(struct tcphdr))) {
17243 +               DEBUGP("ip6t_REJECT: proto(%d) != IPPROTO_TCP, or too short. otcplen = %d\n",
17244 +                       proto, otcplen);
17245 +               return;
17246 +       }
17247 +
17248 +       if (skb_copy_bits(oldskb, tcphoff, &otcph, sizeof(struct tcphdr))) {
17249 +               if (net_ratelimit())
17250 +                       printk("ip6t_REJECT: Can't copy tcp header\n");
17251 +               return;
17252 +       }
17253 +
17254 +       /* No RST for RST. */
17255 +       if (otcph.rst) {
17256 +               DEBUGP("ip6t_REJECT: RST is set\n");
17257 +               return;
17258 +       }
17259 +
17260 +       /* Check checksum. */
17261 +       if (csum_ipv6_magic(&oip6h->saddr, &oip6h->daddr, otcplen, IPPROTO_TCP,
17262 +                           skb_checksum(oldskb, tcphoff, otcplen, 0))) {
17263 +               DEBUGP("ip6t_REJECT: TCP checksum is invalid\n");
17264 +               return;
17265 +       }
17266 +
17267 +       memset(&fl, 0, sizeof(fl));
17268 +       fl.proto = IPPROTO_TCP;
17269 +       ipv6_addr_copy(&fl.fl6_src, &oip6h->daddr);
17270 +       ipv6_addr_copy(&fl.fl6_dst, &oip6h->saddr);
17271 +       fl.fl_ip_sport = otcph.dest;
17272 +       fl.fl_ip_dport = otcph.source;
17273 +       err = ip6_dst_lookup(NULL, &dst, &fl);
17274 +       if (err) {
17275 +               if (net_ratelimit())
17276 +                       printk("ip6t_REJECT: can't find dst. err = %d\n", err);
17277 +               return;
17278 +       }
17279 +
17280 +       hh_len = (dst->dev->hard_header_len + 15)&~15;
17281 +       nskb = alloc_skb(hh_len + 15 + dst->header_len + sizeof(struct ipv6hdr)
17282 +                        + sizeof(struct tcphdr) + dst->trailer_len,
17283 +                        GFP_ATOMIC);
17284 +
17285 +       if (!nskb) {
17286 +               if (net_ratelimit())
17287 +                       printk("ip6t_REJECT: Can't alloc skb\n");
17288 +               dst_release(dst);
17289 +               return;
17290 +       }
17291 +
17292 +       nskb->dst = dst;
17293 +       dst_hold(dst);
17294 +
17295 +       skb_reserve(nskb, hh_len + dst->header_len);
17296 +
17297 +       ip6h = nskb->nh.ipv6h = (struct ipv6hdr *)
17298 +                                       skb_put(nskb, sizeof(struct ipv6hdr));
17299 +       ip6h->version = 6;
17300 +       ip6h->hop_limit = dst_metric(dst, RTAX_HOPLIMIT);
17301 +       ip6h->nexthdr = IPPROTO_TCP;
17302 +       ip6h->payload_len = htons(sizeof(struct tcphdr));
17303 +       ipv6_addr_copy(&ip6h->saddr, &oip6h->daddr);
17304 +       ipv6_addr_copy(&ip6h->daddr, &oip6h->saddr);
17305 +
17306 +       tcph = (struct tcphdr *)skb_put(nskb, sizeof(struct tcphdr));
17307 +       /* Truncate to length (no data) */
17308 +       tcph->doff = sizeof(struct tcphdr)/4;
17309 +       tcph->source = otcph.dest;
17310 +       tcph->dest = otcph.source;
17311 +
17312 +       if (otcph.ack) {
17313 +               needs_ack = 0;
17314 +               tcph->seq = otcph.ack_seq;
17315 +               tcph->ack_seq = 0;
17316 +       } else {
17317 +               needs_ack = 1;
17318 +               tcph->ack_seq = htonl(ntohl(otcph.seq) + otcph.syn + otcph.fin
17319 +                                     + otcplen - (otcph.doff<<2));
17320 +               tcph->seq = 0;
17321 +       }
17322 +
17323 +       /* Reset flags */
17324 +       ((u_int8_t *)tcph)[13] = 0;
17325 +       tcph->rst = 1;
17326 +       tcph->ack = needs_ack;
17327 +       tcph->window = 0;
17328 +       tcph->urg_ptr = 0;
17329 +       tcph->check = 0;
17330 +
17331 +       /* Adjust TCP checksum */
17332 +       tcph->check = csum_ipv6_magic(&nskb->nh.ipv6h->saddr,
17333 +                                     &nskb->nh.ipv6h->daddr,
17334 +                                     sizeof(struct tcphdr), IPPROTO_TCP,
17335 +                                     csum_partial((char *)tcph,
17336 +                                                  sizeof(struct tcphdr), 0));
17337 +
17338 +#if 0
17339 +       connection_attach(nskb, oldskb->nfct);
17340 +#endif
17341 +
17342 +       NF_HOOK(PF_INET6, NF_IP6_LOCAL_OUT, nskb, NULL, nskb->dst->dev,
17343 +               maybe_reroute);
17344 +
17345 +       dst_release(dst);
17346 +}
17347 +
17348 +static void send_unreach(struct sk_buff *skb_in, unsigned char code)
17349 +{
17350 +       struct ipv6hdr *ip6h, *hdr = skb_in->nh.ipv6h;
17351 +       struct icmp6hdr *icmp6h;
17352 +       struct dst_entry *dst = NULL;
17353 +       struct rt6_info *rt;
17354 +       int tmo;
17355 +       __u32 csum;
17356 +       unsigned int len, datalen, hh_len;
17357 +       int saddr_type, daddr_type;
17358 +       unsigned int ptr, ip6off;
17359 +       u8 proto;
17360 +       struct flowi fl;
17361 +       struct sk_buff *nskb;
17362 +       char *data;
17363 +
17364 +       saddr_type = ipv6_addr_type(&hdr->saddr);
17365 +       daddr_type = ipv6_addr_type(&hdr->daddr);
17366 +
17367 +       if ((!(saddr_type & IPV6_ADDR_UNICAST)) ||
17368 +           (!(daddr_type & IPV6_ADDR_UNICAST))) {
17369 +               DEBUGP("ip6t_REJECT: addr is not unicast.\n");
17370 +               return;
17371 +       }
17372 +
17373 +       ip6off = skb_in->nh.raw - skb_in->data;
17374 +       proto = hdr->nexthdr;
17375 +       ptr = ipv6_skip_exthdr(skb_in, ip6off + sizeof(struct ipv6hdr), &proto,
17376 +                              skb_in->len - ip6off);
17377 +
17378 +       if ((ptr < 0) || (ptr > skb_in->len)) {
17379 +               ptr = ip6off + sizeof(struct ipv6hdr);
17380 +               proto = hdr->nexthdr;
17381 +       } else if (proto == IPPROTO_ICMPV6) {
17382 +                u8 type;
17383 +
17384 +                if (skb_copy_bits(skb_in, ptr + offsetof(struct icmp6hdr,
17385 +                                                     icmp6_type), &type, 1)) {
17386 +                       DEBUGP("ip6t_REJECT: Can't get ICMPv6 type\n");
17387 +                       return;
17388 +               }
17389 +
17390 +               if (!(type & ICMPV6_INFOMSG_MASK)) {
17391 +                       DEBUGP("ip6t_REJECT: no reply to icmp error\n");
17392 +                       return;
17393 +               }
17394 +        } else if (proto == IPPROTO_UDP) {
17395 +               int plen = skb_in->len - (ptr - ip6off);
17396 +               uint16_t check;
17397 +
17398 +               if (plen < sizeof(struct udphdr)) {
17399 +                       DEBUGP("ip6t_REJECT: too short\n");
17400 +                       return;
17401 +               }
17402 +
17403 +               if (skb_copy_bits(skb_in, ptr + offsetof(struct udphdr, check),
17404 +                                 &check, 2)) {
17405 +                       if (net_ratelimit())
17406 +                               printk("ip6t_REJECT: can't get copy from skb");
17407 +                       return;
17408 +               }
17409 +
17410 +               if (check &&
17411 +                   csum_ipv6_magic(&hdr->saddr, &hdr->daddr, plen,
17412 +                                   IPPROTO_UDP,
17413 +                                   skb_checksum(skb_in, ptr, plen, 0))) {
17414 +                       DEBUGP("ip6t_REJECT: UDP checksum is invalid.\n");
17415 +                       return;
17416 +               }
17417 +       }
17418 +
17419 +       memset(&fl, 0, sizeof(fl));
17420 +       fl.proto = IPPROTO_ICMPV6;
17421 +       ipv6_addr_copy(&fl.fl6_src, &hdr->daddr);
17422 +       ipv6_addr_copy(&fl.fl6_dst, &hdr->saddr);
17423 +       fl.fl_icmp_type = ICMPV6_DEST_UNREACH;
17424 +       fl.fl_icmp_code = code;
17425 +
17426 +       if (ip6_dst_lookup(NULL, &dst, &fl)) {
17427 +               return;
17428 +       }
17429 +
17430 +       rt = (struct rt6_info *)dst;
17431 +       tmo = 1*HZ;
17432 +
17433 +       if (rt->rt6i_dst.plen < 128)
17434 +               tmo >>= ((128 - rt->rt6i_dst.plen)>>5);
17435 +
17436 +       if (!xrlim_allow(dst, tmo)) {
17437 +               if (net_ratelimit())
17438 +                       printk("ip6t_REJECT: rate limitted\n");
17439 +               goto dst_release_out;
17440 +       }
17441 +
17442 +       len = skb_in->len + sizeof(struct ipv6hdr) + sizeof(struct icmp6hdr);
17443 +
17444 +       if (len > dst_pmtu(dst))
17445 +               len = dst_pmtu(dst);
17446 +       if (len > IPV6_MIN_MTU)
17447 +               len = IPV6_MIN_MTU;
17448 +
17449 +       datalen = len - sizeof(struct ipv6hdr) - sizeof(struct icmp6hdr);
17450 +       hh_len = (rt->u.dst.dev->hard_header_len + 15)&~15;
17451 +
17452 +       nskb = alloc_skb(hh_len + 15 + dst->header_len + dst->trailer_len + len,
17453 +                        GFP_ATOMIC);
17454 +
17455 +       if (!nskb) {
17456 +               if (net_ratelimit())
17457 +                       printk("ip6t_REJECT: can't alloc skb\n");
17458 +               goto dst_release_out;
17459 +       }
17460 +
17461 +       nskb->priority = 0;
17462 +       nskb->dst = dst;
17463 +       dst_hold(dst);
17464 +
17465 +       skb_reserve(nskb, hh_len + dst->header_len);
17466 +
17467 +       ip6h = nskb->nh.ipv6h = (struct ipv6hdr *)
17468 +                                       skb_put(nskb, sizeof(struct ipv6hdr));
17469 +       ip6h->version = 6;
17470 +       ip6h->hop_limit = dst_metric(dst, RTAX_HOPLIMIT);
17471 +       ip6h->nexthdr = IPPROTO_ICMPV6;
17472 +       ip6h->payload_len = htons(datalen + sizeof(struct icmp6hdr));
17473 +       ipv6_addr_copy(&ip6h->saddr, &hdr->daddr);
17474 +       ipv6_addr_copy(&ip6h->daddr, &hdr->saddr);
17475 +
17476 +       icmp6h = (struct icmp6hdr *) skb_put(nskb, sizeof(struct icmp6hdr));
17477 +       icmp6h->icmp6_type = ICMPV6_DEST_UNREACH;
17478 +       icmp6h->icmp6_code = code;
17479 +       icmp6h->icmp6_cksum = 0;
17480 +
17481 +       data = skb_put(nskb, datalen);
17482 +
17483 +       csum = csum_partial((unsigned char *)icmp6h, sizeof(struct icmp6hdr), 0);
17484 +       csum = skb_copy_and_csum_bits(skb_in, ip6off, data, datalen, csum);
17485 +       icmp6h->icmp6_cksum = csum_ipv6_magic(&hdr->saddr, &hdr->daddr,
17486 +                                            datalen + sizeof(struct icmp6hdr),
17487 +                                            IPPROTO_ICMPV6, csum);
17488 +
17489 +#if 0
17490 +       connection_attach(nskb, skb_in->nfct);
17491 +#endif
17492 +       NF_HOOK(PF_INET6, NF_IP6_LOCAL_OUT, nskb, NULL, nskb->dst->dev,
17493 +               maybe_reroute);
17494 +
17495 +dst_release_out:
17496 +       dst_release(dst);
17497 +}
17498 +
17499 +static unsigned int reject6_target(struct sk_buff **pskb,
17500 +                          unsigned int hooknum,
17501 +                          const struct net_device *in,
17502 +                          const struct net_device *out,
17503 +                          const void *targinfo,
17504 +                          void *userinfo)
17505 +{
17506 +       const struct ip6t_reject_info *reject = targinfo;
17507 +
17508 +       DEBUGP(KERN_DEBUG "%s: medium point\n", __FUNCTION__);
17509 +       /* WARNING: This code causes reentry within ip6tables.
17510 +          This means that the ip6tables jump stack is now crap.  We
17511 +          must return an absolute verdict. --RR */
17512 +       switch (reject->with) {
17513 +       case IP6T_ICMP6_NO_ROUTE:
17514 +               send_unreach(*pskb, ICMPV6_NOROUTE);
17515 +               break;
17516 +       case IP6T_ICMP6_ADM_PROHIBITED:
17517 +               send_unreach(*pskb, ICMPV6_ADM_PROHIBITED);
17518 +               break;
17519 +       case IP6T_ICMP6_NOT_NEIGHBOUR:
17520 +               send_unreach(*pskb, ICMPV6_NOT_NEIGHBOUR);
17521 +               break;
17522 +       case IP6T_ICMP6_ADDR_UNREACH:
17523 +               send_unreach(*pskb, ICMPV6_ADDR_UNREACH);
17524 +               break;
17525 +       case IP6T_ICMP6_PORT_UNREACH:
17526 +               send_unreach(*pskb, ICMPV6_PORT_UNREACH);
17527 +               break;
17528 +       case IP6T_ICMP6_ECHOREPLY:
17529 +               /* Do nothing */
17530 +               break;
17531 +       case IP6T_TCP_RESET:
17532 +               send_reset(*pskb);
17533 +               break;
17534 +       default:
17535 +               if (net_ratelimit())
17536 +                       printk(KERN_WARNING "ip6t_REJECT: case %u not handled yet\n", reject->with);
17537 +               break;
17538 +       }
17539 +
17540 +       return NF_DROP;
17541 +}
17542 +
17543 +static int check(const char *tablename,
17544 +                const struct ip6t_entry *e,
17545 +                void *targinfo,
17546 +                unsigned int targinfosize,
17547 +                unsigned int hook_mask)
17548 +{
17549 +       const struct ip6t_reject_info *rejinfo = targinfo;
17550 +
17551 +       if (targinfosize != IP6T_ALIGN(sizeof(struct ip6t_reject_info))) {
17552 +               DEBUGP("ip6t_REJECT: targinfosize %u != 0\n", targinfosize);
17553 +               return 0;
17554 +       }
17555 +
17556 +       /* Only allow these for packet filtering. */
17557 +       if (strcmp(tablename, "filter") != 0) {
17558 +               DEBUGP("ip6t_REJECT: bad table `%s'.\n", tablename);
17559 +               return 0;
17560 +       }
17561 +
17562 +       if ((hook_mask & ~((1 << NF_IP6_LOCAL_IN)
17563 +                          | (1 << NF_IP6_FORWARD)
17564 +                          | (1 << NF_IP6_LOCAL_OUT))) != 0) {
17565 +               DEBUGP("ip6t_REJECT: bad hook mask %X\n", hook_mask);
17566 +               return 0;
17567 +       }
17568 +
17569 +       if (rejinfo->with == IP6T_ICMP6_ECHOREPLY) {
17570 +               printk("ip6t_REJECT: ECHOREPLY is not supported.\n");
17571 +               return 0;
17572 +       } else if (rejinfo->with == IP6T_TCP_RESET) {
17573 +               /* Must specify that it's a TCP packet */
17574 +               if (e->ipv6.proto != IPPROTO_TCP
17575 +                   || (e->ipv6.invflags & IP6T_INV_PROTO)) {
17576 +                       DEBUGP("ip6t_REJECT: TCP_RESET illegal for non-tcp\n");
17577 +                       return 0;
17578 +               }
17579 +       }
17580 +
17581 +       return 1;
17582 +}
17583 +
17584 +static struct ip6t_target ip6t_reject_reg = {
17585 +       .name           = "REJECT",
17586 +       .target         = reject6_target,
17587 +       .checkentry     = check,
17588 +       .me             = THIS_MODULE
17589 +};
17590 +
17591 +static int __init init(void)
17592 +{
17593 +       if (ip6t_register_target(&ip6t_reject_reg))
17594 +               return -EINVAL;
17595 +       return 0;
17596 +}
17597 +
17598 +static void __exit fini(void)
17599 +{
17600 +       ip6t_unregister_target(&ip6t_reject_reg);
17601 +}
17602 +
17603 +module_init(init);
17604 +module_exit(fini);
17605 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv6/netfilter/ip6t_ROUTE.c linux-2.6.6/net/ipv6/netfilter/ip6t_ROUTE.c
17606 --- linux-2.6.6.org/net/ipv6/netfilter/ip6t_ROUTE.c     1970-01-01 01:00:00.000000000 +0100
17607 +++ linux-2.6.6/net/ipv6/netfilter/ip6t_ROUTE.c 2004-05-18 14:28:50.000000000 +0200
17608 @@ -0,0 +1,289 @@
17609 +/*
17610 + * This implements the ROUTE v6 target, which enables you to setup unusual
17611 + * routes not supported by the standard kernel routing table.
17612 + *
17613 + * Copyright (C) 2003 Cedric de Launois <delaunois@info.ucl.ac.be>
17614 + *
17615 + * v 1.0 2003/08/05
17616 + *
17617 + * This software is distributed under GNU GPL v2, 1991
17618 + */
17619 +
17620 +#include <linux/module.h>
17621 +#include <linux/skbuff.h>
17622 +#include <linux/ipv6.h>
17623 +#include <linux/netfilter_ipv6/ip6_tables.h>
17624 +#include <linux/netfilter_ipv6/ip6t_ROUTE.h>
17625 +#include <linux/netdevice.h>
17626 +#include <net/ipv6.h>
17627 +#include <net/ndisc.h>
17628 +#include <net/ip6_route.h>
17629 +#include <linux/icmpv6.h>
17630 +
17631 +#if 1
17632 +#define DEBUGP printk
17633 +#else
17634 +#define DEBUGP(format, args...)
17635 +#endif
17636 +
17637 +#define NIP6(addr) \
17638 +       ntohs((addr).s6_addr16[0]), \
17639 +       ntohs((addr).s6_addr16[1]), \
17640 +       ntohs((addr).s6_addr16[2]), \
17641 +       ntohs((addr).s6_addr16[3]), \
17642 +       ntohs((addr).s6_addr16[4]), \
17643 +       ntohs((addr).s6_addr16[5]), \
17644 +       ntohs((addr).s6_addr16[6]), \
17645 +       ntohs((addr).s6_addr16[7])
17646 +
17647 +/* Route the packet according to the routing keys specified in
17648 + * route_info. Keys are :
17649 + *  - ifindex : 
17650 + *      0 if no oif preferred, 
17651 + *      otherwise set to the index of the desired oif
17652 + *  - route_info->gw :
17653 + *      0 if no gateway specified,
17654 + *      otherwise set to the next host to which the pkt must be routed
17655 + * If success, skb->dev is the output device to which the packet must 
17656 + * be sent and skb->dst is not NULL
17657 + *
17658 + * RETURN:  1 if the packet was succesfully routed to the 
17659 + *            destination desired
17660 + *          0 if the kernel routing table could not route the packet
17661 + *            according to the keys specified
17662 + */
17663 +static int 
17664 +route6(struct sk_buff *skb,
17665 +       unsigned int ifindex,
17666 +       const struct ip6t_route_target_info *route_info)
17667 +{
17668 +       struct rt6_info *rt = NULL;
17669 +       struct ipv6hdr *ipv6h = skb->nh.ipv6h;
17670 +       struct in6_addr *gw = (struct in6_addr*)&route_info->gw;
17671 +
17672 +       DEBUGP("ip6t_ROUTE: called with: ");
17673 +       DEBUGP("DST=%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x ", NIP6(ipv6h->daddr));
17674 +       DEBUGP("GATEWAY=%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x ", NIP6(*gw));
17675 +       DEBUGP("OUT=%s\n", route_info->oif);
17676 +       
17677 +       if (ipv6_addr_any(gw))
17678 +               rt = rt6_lookup(&ipv6h->daddr, &ipv6h->saddr, ifindex, 1);
17679 +       else
17680 +               rt = rt6_lookup(gw, &ipv6h->saddr, ifindex, 1);
17681 +
17682 +       if (!rt)
17683 +               goto no_route;
17684 +
17685 +       DEBUGP("ip6t_ROUTE: routing gives: ");
17686 +       DEBUGP("DST=%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x ", NIP6(rt->rt6i_dst.addr));
17687 +       DEBUGP("GATEWAY=%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x ", NIP6(rt->rt6i_gateway));
17688 +       DEBUGP("OUT=%s\n", rt->rt6i_dev->name);
17689 +
17690 +       if (ifindex && rt->rt6i_dev->ifindex!=ifindex)
17691 +               goto wrong_route;
17692 +       
17693 +       if (!rt->rt6i_nexthop) {
17694 +               DEBUGP("ip6t_ROUTE: discovering neighbour\n");
17695 +               rt->rt6i_nexthop = ndisc_get_neigh(rt->rt6i_dev, &rt->rt6i_dst.addr);
17696 +       }
17697 +
17698 +       /* Drop old route. */
17699 +       dst_release(skb->dst);
17700 +       skb->dst = &rt->u.dst;
17701 +       skb->dev = rt->rt6i_dev;
17702 +       return 1;
17703 +
17704 + wrong_route:
17705 +       dst_release(&rt->u.dst);
17706 + no_route:
17707 +       if (!net_ratelimit())
17708 +               return 0;
17709 +
17710 +       printk("ip6t_ROUTE: no explicit route found ");
17711 +       if (ifindex)
17712 +               printk("via interface %s ", route_info->oif);
17713 +       if (!ipv6_addr_any(gw))
17714 +               printk("via gateway %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x", NIP6(*gw));
17715 +       printk("\n");
17716 +       return 0;
17717 +}
17718 +
17719 +
17720 +/* Stolen from ip6_output_finish
17721 + * PRE : skb->dev is set to the device we are leaving by
17722 + *       skb->dst is not NULL
17723 + * POST: the packet is sent with the link layer header pushed
17724 + *       the packet is destroyed
17725 + */
17726 +static void ip_direct_send(struct sk_buff *skb)
17727 +{
17728 +       struct dst_entry *dst = skb->dst;
17729 +       struct hh_cache *hh = dst->hh;
17730 +
17731 +       if (hh) {
17732 +               read_lock_bh(&hh->hh_lock);
17733 +               memcpy(skb->data - 16, hh->hh_data, 16);
17734 +               read_unlock_bh(&hh->hh_lock);
17735 +               skb_push(skb, hh->hh_len);
17736 +               hh->hh_output(skb);
17737 +       } else if (dst->neighbour)
17738 +               dst->neighbour->output(skb);
17739 +       else {
17740 +               if (net_ratelimit())
17741 +                       DEBUGP(KERN_DEBUG "ip6t_ROUTE: no hdr & no neighbour cache!\n");
17742 +               kfree_skb(skb);
17743 +       }
17744 +}
17745 +
17746 +
17747 +static unsigned int 
17748 +route6_oif(const struct ip6t_route_target_info *route_info,
17749 +          struct sk_buff *skb) 
17750 +{
17751 +       unsigned int ifindex = 0;
17752 +       struct net_device *dev_out = NULL;
17753 +
17754 +       /* The user set the interface name to use.
17755 +        * Getting the current interface index.
17756 +        */
17757 +       if ((dev_out = dev_get_by_name(route_info->oif))) {
17758 +               ifindex = dev_out->ifindex;
17759 +       } else {
17760 +               /* Unknown interface name : packet dropped */
17761 +               if (net_ratelimit()) 
17762 +                       DEBUGP("ip6t_ROUTE: oif interface %s not found\n", route_info->oif);
17763 +
17764 +               if (route_info->flags & IP6T_ROUTE_CONTINUE)
17765 +                       return IP6T_CONTINUE;
17766 +               else
17767 +                       return NF_DROP;
17768 +       }
17769 +
17770 +       /* Trying the standard way of routing packets */
17771 +       if (route6(skb, ifindex, route_info)) {
17772 +               dev_put(dev_out);
17773 +               if (route_info->flags & IP6T_ROUTE_CONTINUE)
17774 +                       return IP6T_CONTINUE;
17775 +               
17776 +               ip_direct_send(skb);
17777 +               return NF_STOLEN;
17778 +       } else 
17779 +               return NF_DROP;
17780 +}
17781 +
17782 +
17783 +static unsigned int 
17784 +route6_gw(const struct ip6t_route_target_info *route_info,
17785 +         struct sk_buff *skb) 
17786 +{
17787 +       if (route6(skb, 0, route_info)) {
17788 +               if (route_info->flags & IP6T_ROUTE_CONTINUE)
17789 +                       return IP6T_CONTINUE;
17790 +
17791 +               ip_direct_send(skb);
17792 +               return NF_STOLEN;
17793 +       } else
17794 +               return NF_DROP;
17795 +}
17796 +
17797 +
17798 +static unsigned int 
17799 +ip6t_route_target(struct sk_buff **pskb,
17800 +                 unsigned int hooknum,
17801 +                 const struct net_device *in,
17802 +                 const struct net_device *out,
17803 +                 const void *targinfo,
17804 +                 void *userinfo)
17805 +{
17806 +       const struct ip6t_route_target_info *route_info = targinfo;
17807 +       struct sk_buff *skb = *pskb;
17808 +       struct in6_addr *gw = (struct in6_addr*)&route_info->gw;
17809 +
17810 +       if (route_info->flags & IP6T_ROUTE_CONTINUE)
17811 +               goto do_it;
17812 +
17813 +       /* If we are at PREROUTING or INPUT hook
17814 +        * the TTL isn't decreased by the IP stack
17815 +        */
17816 +       if (hooknum == NF_IP6_PRE_ROUTING ||
17817 +           hooknum == NF_IP6_LOCAL_IN) {
17818 +
17819 +               struct ipv6hdr *ipv6h = skb->nh.ipv6h;
17820 +
17821 +               if (ipv6h->hop_limit <= 1) {
17822 +                       /* Force OUTPUT device used as source address */
17823 +                       skb->dev = skb->dst->dev;
17824 +
17825 +                       icmpv6_send(skb, ICMPV6_TIME_EXCEED, 
17826 +                                   ICMPV6_EXC_HOPLIMIT, 0, skb->dev);
17827 +
17828 +                       return NF_DROP;
17829 +               }
17830 +
17831 +               ipv6h->hop_limit--;
17832 +       }
17833 +
17834 +
17835 + do_it:
17836 +       if (route_info->oif[0]) 
17837 +               return route6_oif(route_info, *pskb);
17838 +       
17839 +       if (!ipv6_addr_any(gw))
17840 +               return route6_gw(route_info, *pskb);
17841 +
17842 +       if (net_ratelimit()) 
17843 +               DEBUGP(KERN_DEBUG "ip6t_ROUTE: no parameter !\n");
17844 +
17845 +       return IP6T_CONTINUE;
17846 +}
17847 +
17848 +
17849 +static int 
17850 +ip6t_route_checkentry(const char *tablename,
17851 +                     const struct ip6t_entry *e,
17852 +                     void *targinfo,
17853 +                     unsigned int targinfosize,
17854 +                     unsigned int hook_mask)
17855 +{
17856 +       if (strcmp(tablename, "mangle") != 0) {
17857 +               printk("ip6t_ROUTE: can only be called from \"mangle\" table.\n");
17858 +               return 0;
17859 +       }
17860 +
17861 +       if (targinfosize != IP6T_ALIGN(sizeof(struct ip6t_route_target_info))) {
17862 +               printk(KERN_WARNING "ip6t_ROUTE: targinfosize %u != %Zu\n",
17863 +                      targinfosize,
17864 +                      IP6T_ALIGN(sizeof(struct ip6t_route_target_info)));
17865 +               return 0;
17866 +       }
17867 +
17868 +       return 1;
17869 +}
17870 +
17871 +
17872 +static struct ip6t_target ip6t_route_reg = {
17873 +       .name       = "ROUTE",
17874 +       .target     = ip6t_route_target,
17875 +       .checkentry = ip6t_route_checkentry,
17876 +       .me         = THIS_MODULE
17877 +};
17878 +
17879 +
17880 +static int __init init(void)
17881 +{
17882 +       printk(KERN_DEBUG "registering ipv6 ROUTE target\n");
17883 +       if (ip6t_register_target(&ip6t_route_reg))
17884 +               return -EINVAL;
17885 +
17886 +       return 0;
17887 +}
17888 +
17889 +
17890 +static void __exit fini(void)
17891 +{
17892 +       ip6t_unregister_target(&ip6t_route_reg);
17893 +}
17894 +
17895 +module_init(init);
17896 +module_exit(fini);
17897 +MODULE_LICENSE("GPL");
17898 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv6/netfilter/ip6t_TRACE.c linux-2.6.6/net/ipv6/netfilter/ip6t_TRACE.c
17899 --- linux-2.6.6.org/net/ipv6/netfilter/ip6t_TRACE.c     1970-01-01 01:00:00.000000000 +0100
17900 +++ linux-2.6.6/net/ipv6/netfilter/ip6t_TRACE.c 2004-05-18 14:28:50.000000000 +0200
17901 @@ -0,0 +1,65 @@
17902 +/* This is a module which is used for setting
17903 + * the NFC_TRACE flag in the nfcache field of an skb. 
17904 + */
17905 +#include <linux/module.h>
17906 +#include <linux/skbuff.h>
17907 +
17908 +#include <linux/netfilter_ipv6/ip6_tables.h>
17909 +
17910 +MODULE_LICENSE("GPL");
17911 +
17912 +static unsigned int
17913 +target(struct sk_buff **pskb,
17914 +       unsigned int hooknum,
17915 +       const struct net_device *in,
17916 +       const struct net_device *out,
17917 +       const void *targinfo,
17918 +       void *userinfo)
17919 +{
17920 +       (*pskb)->nfcache |= NFC_TRACE;
17921 +       return IP6T_CONTINUE;
17922 +}
17923 +
17924 +static int 
17925 +checkentry(const char *tablename,
17926 +                  const struct ip6t_entry *e,
17927 +           void *targinfo,
17928 +           unsigned int targinfosize,
17929 +           unsigned int hook_mask)
17930 +{
17931 +       if (targinfosize != 0) {
17932 +               printk(KERN_WARNING "TRACE: targinfosize %u != 0\n",
17933 +                      targinfosize);
17934 +               return 0;
17935 +       }
17936 +
17937 +       if (strcmp(tablename, "raw") != 0) {
17938 +               printk(KERN_WARNING "TRACE: can only be called from \"raw\" table, not \"%s\"\n", tablename);
17939 +               return 0;
17940 +       }
17941 +
17942 +       return 1;
17943 +}
17944 +
17945 +static struct ip6t_target ip6t_trace_reg = { 
17946 +       .name = "TRACE",
17947 +       .target = target, 
17948 +       .checkentry = checkentry, 
17949 +       .me = THIS_MODULE
17950 +};
17951 +
17952 +static int __init init(void)
17953 +{
17954 +       if (ip6t_register_target(&ip6t_trace_reg))
17955 +               return -EINVAL;
17956 +
17957 +       return 0;
17958 +}
17959 +
17960 +static void __exit fini(void)
17961 +{
17962 +       ip6t_unregister_target(&ip6t_trace_reg);
17963 +}
17964 +
17965 +module_init(init);
17966 +module_exit(fini);
17967 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv6/netfilter/ip6t_fuzzy.c linux-2.6.6/net/ipv6/netfilter/ip6t_fuzzy.c
17968 --- linux-2.6.6.org/net/ipv6/netfilter/ip6t_fuzzy.c     1970-01-01 01:00:00.000000000 +0100
17969 +++ linux-2.6.6/net/ipv6/netfilter/ip6t_fuzzy.c 2004-05-18 14:28:50.000000000 +0200
17970 @@ -0,0 +1,189 @@
17971 +/*
17972 + * This module implements a simple TSK FLC
17973 + * (Takagi-Sugeno-Kang Fuzzy Logic Controller) that aims
17974 + * to limit , in an adaptive and flexible way , the packet rate crossing
17975 + * a given stream . It serves as an initial and very simple (but effective)
17976 + * example of how Fuzzy Logic techniques can be applied to defeat DoS attacks.
17977 + *  As a matter of fact , Fuzzy Logic can help us to insert any "behavior"
17978 + * into our code in a precise , adaptive and efficient manner.
17979 + *  The goal is very similar to that of "limit" match , but using techniques of
17980 + * Fuzzy Control , that allow us to shape the transfer functions precisely ,
17981 + * avoiding over and undershoots - and stuff like that .
17982 + *
17983 + *
17984 + * 2002-08-10  Hime Aguiar e Oliveira Jr. <hime@engineer.com> : Initial version.
17985 + * 2002-08-17  : Changed to eliminate floating point operations .
17986 + * 2002-08-23  : Coding style changes .
17987 + * 2003-04-08  Maciej Soltysiak <solt@dns.toxicilms.tv> : IPv6 Port
17988 + */
17989 +
17990 +#include <linux/module.h>
17991 +#include <linux/skbuff.h>
17992 +#include <linux/ipv6.h>
17993 +#include <linux/random.h>
17994 +#include <net/tcp.h>
17995 +#include <linux/spinlock.h>
17996 +#include <linux/netfilter_ipv6/ip6_tables.h>
17997 +#include <linux/netfilter_ipv6/ip6t_fuzzy.h>
17998 +
17999 +/*
18000 + Packet Acceptance Rate - LOW and Packet Acceptance Rate - HIGH
18001 + Expressed in percentage
18002 +*/
18003 +
18004 +#define PAR_LOW                1/100
18005 +#define PAR_HIGH       1
18006 +
18007 +static spinlock_t fuzzy_lock = SPIN_LOCK_UNLOCKED;
18008 +
18009 +MODULE_AUTHOR("Hime Aguiar e Oliveira Junior <hime@engineer.com>");
18010 +MODULE_DESCRIPTION("IP tables Fuzzy Logic Controller match module");
18011 +MODULE_LICENSE("GPL");
18012 +
18013 +static  u_int8_t mf_high(u_int32_t tx,u_int32_t mini,u_int32_t maxi)
18014 +{
18015 +       if (tx >= maxi) return 100;
18016 +
18017 +       if (tx <= mini) return 0;
18018 +
18019 +       return ((100 * (tx-mini)) / (maxi-mini));
18020 +}
18021 +
18022 +static u_int8_t mf_low(u_int32_t tx,u_int32_t mini,u_int32_t maxi)
18023 +{
18024 +       if (tx <= mini) return 100;
18025 +
18026 +       if (tx >= maxi) return 0;
18027 +
18028 +       return ((100 * (maxi - tx)) / (maxi - mini));
18029 +
18030 +}
18031 +
18032 +static int
18033 +ip6t_fuzzy_match(const struct sk_buff *pskb,
18034 +              const struct net_device *in,
18035 +              const struct net_device *out,
18036 +              const void *matchinfo,
18037 +              int offset,
18038 +              const void *hdr,
18039 +              u_int16_t datalen,
18040 +              int *hotdrop)
18041 +{
18042 +       /* From userspace */
18043 +
18044 +       struct ip6t_fuzzy_info *info = (struct ip6t_fuzzy_info *) matchinfo;
18045 +
18046 +       u_int8_t random_number;
18047 +       unsigned long amount;
18048 +       u_int8_t howhigh, howlow;
18049 +
18050 +
18051 +       spin_lock_bh(&fuzzy_lock); /* Rise the lock */
18052 +
18053 +       info->bytes_total += pskb->len;
18054 +       info->packets_total++;
18055 +
18056 +       info->present_time = jiffies;
18057 +
18058 +       if (info->present_time >= info->previous_time)
18059 +               amount = info->present_time - info->previous_time;
18060 +       else {
18061 +               /* There was a transition : I choose to re-sample
18062 +                  and keep the old acceptance rate...
18063 +               */
18064 +
18065 +               amount = 0;
18066 +               info->previous_time = info->present_time;
18067 +               info->bytes_total = info->packets_total = 0;
18068 +            };
18069 +
18070 +       if ( amount > HZ/10) {/* More than 100 ms elapsed ... */
18071 +
18072 +               info->mean_rate = (u_int32_t) ((HZ * info->packets_total) \
18073 +                                       / amount);
18074 +
18075 +               info->previous_time = info->present_time;
18076 +               info->bytes_total = info->packets_total = 0;
18077 +
18078 +               howhigh = mf_high(info->mean_rate,info->minimum_rate,info->maximum_rate);
18079 +               howlow  = mf_low(info->mean_rate,info->minimum_rate,info->maximum_rate);
18080 +
18081 +               info->acceptance_rate = (u_int8_t) \
18082 +                               (howhigh * PAR_LOW + PAR_HIGH * howlow);
18083 +
18084 +       /* In fact, the above defuzzification would require a denominator
18085 +        * proportional to (howhigh+howlow) but, in this particular case,
18086 +        * that expression is constant.
18087 +        * An imediate consequence is that it is not necessary to call
18088 +        * both mf_high and mf_low - but to keep things understandable,
18089 +        * I did so.
18090 +        */
18091 +
18092 +       }
18093 +
18094 +       spin_unlock_bh(&fuzzy_lock); /* Release the lock */
18095 +
18096 +
18097 +       if (info->acceptance_rate < 100)
18098 +       {
18099 +               get_random_bytes((void *)(&random_number), 1);
18100 +
18101 +               /*  If within the acceptance , it can pass => don't match */
18102 +               if (random_number <= (255 * info->acceptance_rate) / 100)
18103 +                       return 0;
18104 +               else
18105 +                       return 1; /* It can't pass (It matches) */
18106 +       };
18107 +
18108 +       return 0; /* acceptance_rate == 100 % => Everything passes ... */
18109 +
18110 +}
18111 +
18112 +static int
18113 +ip6t_fuzzy_checkentry(const char *tablename,
18114 +                  const struct ip6t_ip6 *ip,
18115 +                  void *matchinfo,
18116 +                  unsigned int matchsize,
18117 +                  unsigned int hook_mask)
18118 +{
18119 +
18120 +       const struct ip6t_fuzzy_info *info = matchinfo;
18121 +
18122 +       if (matchsize != IP6T_ALIGN(sizeof(struct ip6t_fuzzy_info))) {
18123 +               printk("ip6t_fuzzy: matchsize %u != %u\n", matchsize,
18124 +                      IP6T_ALIGN(sizeof(struct ip6t_fuzzy_info)));
18125 +               return 0;
18126 +       }
18127 +
18128 +       if ((info->minimum_rate < MINFUZZYRATE) || (info->maximum_rate > MAXFUZZYRATE)
18129 +        || (info->minimum_rate >= info->maximum_rate)) {
18130 +               printk("ip6t_fuzzy: BAD limits , please verify !!!\n");
18131 +               return 0;
18132 +       }
18133 +
18134 +       return 1;
18135 +}
18136 +
18137 +static struct ip6t_match ip6t_fuzzy_reg = {
18138 +       {NULL, NULL},
18139 +       "fuzzy",
18140 +       ip6t_fuzzy_match,
18141 +       ip6t_fuzzy_checkentry,
18142 +       NULL,
18143 +       THIS_MODULE };
18144 +
18145 +static int __init init(void)
18146 +{
18147 +       if (ip6t_register_match(&ip6t_fuzzy_reg))
18148 +               return -EINVAL;
18149 +
18150 +       return 0;
18151 +}
18152 +
18153 +static void __exit fini(void)
18154 +{
18155 +       ip6t_unregister_match(&ip6t_fuzzy_reg);
18156 +}
18157 +
18158 +module_init(init);
18159 +module_exit(fini);
18160 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv6/netfilter/ip6t_nth.c linux-2.6.6/net/ipv6/netfilter/ip6t_nth.c
18161 --- linux-2.6.6.org/net/ipv6/netfilter/ip6t_nth.c       1970-01-01 01:00:00.000000000 +0100
18162 +++ linux-2.6.6/net/ipv6/netfilter/ip6t_nth.c   2004-05-18 14:28:50.000000000 +0200
18163 @@ -0,0 +1,173 @@
18164 +/*
18165 +  This is a module which is used for match support for every Nth packet
18166 +  This file is distributed under the terms of the GNU General Public
18167 +  License (GPL). Copies of the GPL can be obtained from:
18168 +     ftp://prep.ai.mit.edu/pub/gnu/GPL
18169 +
18170 +  2001-07-18 Fabrice MARIE <fabrice@netfilter.org> : initial implementation.
18171 +  2001-09-20 Richard Wagner (rwagner@cloudnet.com)
18172 +        * added support for multiple counters
18173 +        * added support for matching on individual packets
18174 +          in the counter cycle
18175 +  2003-04-30 Maciej Soltysiak <solt@dns.toxicfilms.tv> : IPv6 Port
18176 +
18177 +*/
18178 +
18179 +#include <linux/module.h>
18180 +#include <linux/skbuff.h>
18181 +#include <linux/ip.h>
18182 +#include <net/tcp.h>
18183 +#include <linux/spinlock.h>
18184 +#include <linux/netfilter_ipv6/ip6_tables.h>
18185 +#include <linux/netfilter_ipv6/ip6t_nth.h>
18186 +
18187 +MODULE_LICENSE("GPL");
18188 +
18189 +/*
18190 + * State information.
18191 + */
18192 +struct state {
18193 +       spinlock_t lock;
18194 +       u_int16_t number;
18195 +};
18196 +
18197 +static struct state states[IP6T_NTH_NUM_COUNTERS];
18198 +
18199 +static int
18200 +ip6t_nth_match(const struct sk_buff *pskb,
18201 +             const struct net_device *in,
18202 +             const struct net_device *out,
18203 +             const void *matchinfo,
18204 +             int offset,
18205 +             const void *hdr,
18206 +             u_int16_t datalen,
18207 +             int *hotdrop)
18208 +{
18209 +       /* Parameters from userspace */
18210 +       const struct ip6t_nth_info *info = matchinfo;
18211 +        unsigned counter = info->counter;
18212 +               if((counter < 0) || (counter >= IP6T_NTH_NUM_COUNTERS)) 
18213 +       {
18214 +                       printk(KERN_WARNING "nth: invalid counter %u. counter between 0 and %u\n", counter, IP6T_NTH_NUM_COUNTERS-1);
18215 +               return 0;
18216 +        };
18217 +
18218 +        spin_lock(&states[counter].lock);
18219 +
18220 +        /* Are we matching every nth packet?*/
18221 +        if (info->packet == 0xFF)
18222 +        {
18223 +               /* We're matching every nth packet and only every nth packet*/
18224 +               /* Do we match or invert match? */
18225 +               if (info->not == 0)
18226 +               {
18227 +                       if (states[counter].number == 0)
18228 +                       {
18229 +                               ++states[counter].number;
18230 +                               goto match;
18231 +                       }
18232 +                       if (states[counter].number >= info->every)
18233 +                               states[counter].number = 0; /* reset the counter */
18234 +                       else
18235 +                               ++states[counter].number;
18236 +                       goto dontmatch;
18237 +               }
18238 +               else
18239 +               {
18240 +                       if (states[counter].number == 0)
18241 +                       {
18242 +                               ++states[counter].number;
18243 +                               goto dontmatch;
18244 +                       }
18245 +                       if (states[counter].number >= info->every)
18246 +                               states[counter].number = 0;
18247 +                       else
18248 +                               ++states[counter].number;
18249 +                       goto match;
18250 +               }
18251 +        }
18252 +        else
18253 +        {
18254 +               /* We're using the --packet, so there must be a rule for every value */
18255 +               if (states[counter].number == info->packet)
18256 +               {
18257 +                       /* only increment the counter when a match happens */
18258 +                       if (states[counter].number >= info->every)
18259 +                               states[counter].number = 0; /* reset the counter */
18260 +                       else
18261 +                               ++states[counter].number;
18262 +                       goto match;
18263 +               }
18264 +               else
18265 +                       goto dontmatch;
18266 +       }
18267 +
18268 + dontmatch:
18269 +       /* don't match */
18270 +       spin_unlock(&states[counter].lock);
18271 +       return 0;
18272 +
18273 + match:
18274 +       spin_unlock(&states[counter].lock);
18275 +       return 1;
18276 +}
18277 +
18278 +static int
18279 +ip6t_nth_checkentry(const char *tablename,
18280 +                  const struct ip6t_ip6 *e,
18281 +                  void *matchinfo,
18282 +                  unsigned int matchsize,
18283 +                  unsigned int hook_mask)
18284 +{
18285 +       /* Parameters from userspace */
18286 +       const struct ip6t_nth_info *info = matchinfo;
18287 +        unsigned counter = info->counter;
18288 +        if((counter < 0) || (counter >= IP6T_NTH_NUM_COUNTERS)) 
18289 +       {
18290 +               printk(KERN_WARNING "nth: invalid counter %u. counter between 0 and %u\n", counter, IP6T_NTH_NUM_COUNTERS-1);
18291 +                       return 0;
18292 +               };
18293 +
18294 +       if (matchsize != IP6T_ALIGN(sizeof(struct ip6t_nth_info))) {
18295 +               printk("nth: matchsize %u != %u\n", matchsize,
18296 +                      IP6T_ALIGN(sizeof(struct ip6t_nth_info)));
18297 +               return 0;
18298 +       }
18299 +
18300 +       states[counter].number = info->startat;
18301 +
18302 +       return 1;
18303 +}
18304 +
18305 +static struct ip6t_match ip6t_nth_reg = { 
18306 +       {NULL, NULL},
18307 +       "nth",
18308 +       ip6t_nth_match,
18309 +       ip6t_nth_checkentry,
18310 +       NULL,
18311 +       THIS_MODULE };
18312 +
18313 +static int __init init(void)
18314 +{
18315 +       unsigned counter;
18316 +        memset(&states, 0, sizeof(states));
18317 +       if (ip6t_register_match(&ip6t_nth_reg))
18318 +               return -EINVAL;
18319 +
18320 +        for(counter = 0; counter < IP6T_NTH_NUM_COUNTERS; counter++) 
18321 +       {
18322 +               spin_lock_init(&(states[counter].lock));
18323 +        };
18324 +
18325 +       printk("ip6t_nth match loaded\n");
18326 +       return 0;
18327 +}
18328 +
18329 +static void __exit fini(void)
18330 +{
18331 +       ip6t_unregister_match(&ip6t_nth_reg);
18332 +       printk("ip6t_nth match unloaded\n");
18333 +}
18334 +
18335 +module_init(init);
18336 +module_exit(fini);
18337 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv6/netfilter/ip6t_owner.c linux-2.6.6/net/ipv6/netfilter/ip6t_owner.c
18338 --- linux-2.6.6.org/net/ipv6/netfilter/ip6t_owner.c     2004-05-10 04:33:13.000000000 +0200
18339 +++ linux-2.6.6/net/ipv6/netfilter/ip6t_owner.c 2004-05-18 14:28:50.000000000 +0200
18340 @@ -21,6 +21,39 @@
18341  MODULE_LICENSE("GPL");
18342  
18343  static int
18344 +match_comm(const struct sk_buff *skb, const char *comm)
18345 +{
18346 +       struct task_struct *p, *g;
18347 +       struct files_struct *files;
18348 +       int i;
18349 +
18350 +       read_lock(&tasklist_lock);
18351 +       do_each_thread(g, p) {
18352 +               if(strncmp(p->comm, comm, sizeof(p->comm)))
18353 +                       continue;
18354 +
18355 +               task_lock(p);
18356 +               files = p->files;
18357 +               if(files) {
18358 +                       read_lock(&files->file_lock);
18359 +                       for (i=0; i < files->max_fds; i++) {
18360 +                               if (fcheck_files(files, i) ==
18361 +                                   skb->sk->sk_socket->file) {
18362 +                                       read_unlock(&files->file_lock);
18363 +                                       task_unlock(p);
18364 +                                       read_unlock(&tasklist_lock);
18365 +                                       return 1;
18366 +                               }
18367 +                       }
18368 +                       read_unlock(&files->file_lock);
18369 +               }
18370 +               task_unlock(p);
18371 +       } while_each_thread(g, p);
18372 +       read_unlock(&tasklist_lock);
18373 +       return 0;
18374 +}
18375 +
18376 +static int
18377  match_pid(const struct sk_buff *skb, pid_t pid)
18378  {
18379         struct task_struct *p;
18380 @@ -125,6 +158,12 @@
18381                         return 0;
18382         }
18383  
18384 +       if(info->match & IP6T_OWNER_COMM) {
18385 +               if (!match_comm(skb, info->comm) ^
18386 +                   !!(info->invert & IP6T_OWNER_COMM))
18387 +                       return 0;
18388 +       }
18389 +
18390         return 1;
18391  }
18392  
18393 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv6/netfilter/ip6t_policy.c linux-2.6.6/net/ipv6/netfilter/ip6t_policy.c
18394 --- linux-2.6.6.org/net/ipv6/netfilter/ip6t_policy.c    1970-01-01 01:00:00.000000000 +0100
18395 +++ linux-2.6.6/net/ipv6/netfilter/ip6t_policy.c        2004-05-18 14:28:50.000000000 +0200
18396 @@ -0,0 +1,201 @@
18397 +/* IP tables module for matching IPsec policy
18398 + *
18399 + * Copyright (c) 2004 Patrick McHardy, <kaber@trash.net>
18400 + *
18401 + * This program is free software; you can redistribute it and/or modify
18402 + * it under the terms of the GNU General Public License version 2 as
18403 + * published by the Free Software Foundation.
18404 + */
18405 +
18406 +#include <linux/kernel.h>
18407 +#include <linux/config.h>
18408 +#include <linux/module.h>
18409 +#include <linux/skbuff.h>
18410 +#include <linux/init.h>
18411 +#include <net/xfrm.h>
18412 +
18413 +#include <linux/netfilter_ipv6.h>
18414 +#include <linux/netfilter_ipv6/ip6t_policy.h>
18415 +#include <linux/netfilter_ipv6/ip6_tables.h>
18416 +
18417 +MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
18418 +MODULE_DESCRIPTION("IPtables IPsec policy matching module");
18419 +MODULE_LICENSE("GPL");
18420 +
18421 +
18422 +static inline int ip6_masked_addrcmp(struct in6_addr addr1,
18423 +                                     struct in6_addr mask,
18424 +                                     struct in6_addr addr2)
18425 +{
18426 +       int i;
18427 +
18428 +       for (i = 0; i < 16; i++) {
18429 +               if ((addr1.s6_addr[i] & mask.s6_addr[i]) !=
18430 +                   (addr2.s6_addr[i] & mask.s6_addr[i]))
18431 +                       return 1;
18432 +       }
18433 +       return 0;
18434 +}
18435 +
18436 +
18437 +static inline int
18438 +match_xfrm_state(struct xfrm_state *x, const struct ip6t_policy_elem *e)
18439 +{
18440 +#define MISMATCH(x,y)  (e->match.x && ((e->x != (y)) ^ e->invert.x))
18441 +       
18442 +       struct in6_addr xfrm_saddr, xfrm_daddr;
18443 +       
18444 +       if ((e->match.saddr
18445 +            && (ip6_masked_addrcmp(xfrm_saddr, e->saddr, e->smask))
18446 +               ^ e->invert.saddr ) ||
18447 +           (e->match.daddr
18448 +            && (ip6_masked_addrcmp(xfrm_daddr, e->daddr, e->dmask))
18449 +               ^ e->invert.daddr ) ||
18450 +           MISMATCH(proto, x->id.proto) ||
18451 +           MISMATCH(mode, x->props.mode) ||
18452 +           MISMATCH(spi, x->id.spi) ||
18453 +           MISMATCH(reqid, x->props.reqid))
18454 +               return 0;
18455 +       return 1;
18456 +}
18457 +
18458 +static int
18459 +match_policy_in(const struct sk_buff *skb, const struct ip6t_policy_info *info)
18460 +{
18461 +       const struct ip6t_policy_elem *e;
18462 +       struct sec_path *sp = skb->sp;
18463 +       int strict = info->flags & POLICY_MATCH_STRICT;
18464 +       int i, pos;
18465 +
18466 +       if (sp == NULL)
18467 +               return -1;
18468 +       if (strict && info->len != sp->len)
18469 +               return 0;
18470 +
18471 +       for (i = sp->len - 1; i >= 0; i--) {
18472 +               pos = strict ? i - sp->len + 1 : 0;
18473 +               if (pos >= info->len)
18474 +                       return 0;
18475 +               e = &info->pol[pos];
18476 +
18477 +               if (match_xfrm_state(sp->x[i].xvec, e)) {
18478 +                       if (!strict)
18479 +                               return 1;
18480 +               } else if (strict)
18481 +                       return 0;
18482 +       }
18483 +
18484 +       return strict ? 1 : 0;
18485 +}
18486 +
18487 +static int
18488 +match_policy_out(const struct sk_buff *skb, const struct ip6t_policy_info *info)
18489 +{
18490 +       const struct ip6t_policy_elem *e;
18491 +       struct dst_entry *dst = skb->dst;
18492 +       int strict = info->flags & POLICY_MATCH_STRICT;
18493 +       int i, pos;
18494 +
18495 +       if (dst->xfrm == NULL)
18496 +               return -1;
18497 +
18498 +       for (i = 0; dst && dst->xfrm; dst = dst->child, i++) {
18499 +               pos = strict ? i : 0;
18500 +               if (pos >= info->len)
18501 +                       return 0;
18502 +               e = &info->pol[pos];
18503 +
18504 +               if (match_xfrm_state(dst->xfrm, e)) {
18505 +                       if (!strict)
18506 +                               return 1;
18507 +               } else if (strict)
18508 +                       return 0;
18509 +       }
18510 +
18511 +       return strict ? 1 : 0;
18512 +}
18513 +
18514 +static int match(const struct sk_buff *skb,
18515 +                 const struct net_device *in,
18516 +                 const struct net_device *out,
18517 +                 const void *matchinfo,
18518 +                int offset,
18519 +                const void *hdr,
18520 +                u_int16_t datalen,
18521 +                int *hotdrop)
18522 +{
18523 +       const struct ip6t_policy_info *info = matchinfo;
18524 +       int ret;
18525 +
18526 +       if (info->flags & POLICY_MATCH_IN)
18527 +               ret = match_policy_in(skb, info);
18528 +       else
18529 +               ret = match_policy_out(skb, info);
18530 +
18531 +       if (ret < 0) {
18532 +               if (info->flags & POLICY_MATCH_NONE)
18533 +                       ret = 1;
18534 +               else
18535 +                       ret = 0;
18536 +       } else if (info->flags & POLICY_MATCH_NONE)
18537 +               ret = 0;
18538 +
18539 +       return ret;
18540 +}
18541 +
18542 +static int checkentry(const char *tablename, const struct ip6t_ip6 *ip,
18543 +                      void *matchinfo, unsigned int matchsize,
18544 +                      unsigned int hook_mask)
18545 +{
18546 +       struct ip6t_policy_info *info = matchinfo;
18547 +
18548 +       if (matchsize != IP6T_ALIGN(sizeof(*info))) {
18549 +               printk(KERN_ERR "ip6t_policy: matchsize %u != %u\n",
18550 +                      matchsize, IP6T_ALIGN(sizeof(*info)));
18551 +               return 0;
18552 +       }
18553 +       if (!(info->flags & (POLICY_MATCH_IN|POLICY_MATCH_OUT))) {
18554 +               printk(KERN_ERR "ip6t_policy: neither incoming nor "
18555 +                               "outgoing policy selected\n");
18556 +               return 0;
18557 +       }
18558 +       if (hook_mask & (1 << NF_IP6_PRE_ROUTING | 1 << NF_IP6_LOCAL_IN)
18559 +           && info->flags & POLICY_MATCH_OUT) {
18560 +               printk(KERN_ERR "ip6t_policy: output policy not valid in "
18561 +                               "PRE_ROUTING and INPUT\n");
18562 +               return 0;
18563 +       }
18564 +       if (hook_mask & (1 << NF_IP6_POST_ROUTING | 1 << NF_IP6_LOCAL_OUT)
18565 +           && info->flags & POLICY_MATCH_IN) {
18566 +               printk(KERN_ERR "ip6t_policy: input policy not valid in "
18567 +                               "POST_ROUTING and OUTPUT\n");
18568 +               return 0;
18569 +       }
18570 +       if (info->len > POLICY_MAX_ELEM) {
18571 +               printk(KERN_ERR "ip6t_policy: too many policy elements\n");
18572 +               return 0;
18573 +       }
18574 +
18575 +       return 1;
18576 +}
18577 +
18578 +static struct ip6t_match policy_match =
18579 +{
18580 +       .name           = "policy",
18581 +       .match          = match,
18582 +       .checkentry     = checkentry,
18583 +       .me             = THIS_MODULE,
18584 +};
18585 +
18586 +static int __init init(void)
18587 +{
18588 +       return ip6t_register_match(&policy_match);
18589 +}
18590 +
18591 +static void __exit fini(void)
18592 +{
18593 +       ip6t_unregister_match(&policy_match);
18594 +}
18595 +
18596 +module_init(init);
18597 +module_exit(fini);
18598 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv6/netfilter/ip6t_random.c linux-2.6.6/net/ipv6/netfilter/ip6t_random.c
18599 --- linux-2.6.6.org/net/ipv6/netfilter/ip6t_random.c    1970-01-01 01:00:00.000000000 +0100
18600 +++ linux-2.6.6/net/ipv6/netfilter/ip6t_random.c        2004-05-18 14:28:50.000000000 +0200
18601 @@ -0,0 +1,97 @@
18602 +/*
18603 +  This is a module which is used for a "random" match support.
18604 +  This file is distributed under the terms of the GNU General Public
18605 +  License (GPL). Copies of the GPL can be obtained from:
18606 +     ftp://prep.ai.mit.edu/pub/gnu/GPL
18607 +
18608 +  2001-10-14 Fabrice MARIE <fabrice@netfilter.org> : initial implementation.
18609 +  2003-04-30 Maciej Soltysiak <solt@dns.toxicfilms.tv> : IPv6 Port
18610 +*/
18611 +
18612 +#include <linux/module.h>
18613 +#include <linux/skbuff.h>
18614 +#include <linux/ip.h>
18615 +#include <linux/random.h>
18616 +#include <net/tcp.h>
18617 +#include <linux/spinlock.h>
18618 +#include <linux/netfilter_ipv6/ip6_tables.h>
18619 +#include <linux/netfilter_ipv6/ip6t_random.h>
18620 +
18621 +MODULE_LICENSE("GPL");
18622 +
18623 +static int
18624 +ip6t_rand_match(const struct sk_buff *pskb,
18625 +              const struct net_device *in,
18626 +              const struct net_device *out,
18627 +              const void *matchinfo,
18628 +              int offset,
18629 +              const void *hdr,
18630 +              u_int16_t datalen,
18631 +              int *hotdrop)
18632 +{
18633 +       /* Parameters from userspace */
18634 +       const struct ip6t_rand_info *info = matchinfo;
18635 +       u_int8_t random_number;
18636 +
18637 +       /* get 1 random number from the kernel random number generation routine */
18638 +       get_random_bytes((void *)(&random_number), 1);
18639 +
18640 +       /* Do we match ? */
18641 +       if (random_number <= info->average)
18642 +               return 1;
18643 +       else
18644 +               return 0;
18645 +}
18646 +
18647 +static int
18648 +ip6t_rand_checkentry(const char *tablename,
18649 +                  const struct ip6t_ip6 *e,
18650 +                  void *matchinfo,
18651 +                  unsigned int matchsize,
18652 +                  unsigned int hook_mask)
18653 +{
18654 +       /* Parameters from userspace */
18655 +       const struct ip6t_rand_info *info = matchinfo;
18656 +
18657 +       if (matchsize != IP6T_ALIGN(sizeof(struct ip6t_rand_info))) {
18658 +               printk("ip6t_random: matchsize %u != %u\n", matchsize,
18659 +                      IP6T_ALIGN(sizeof(struct ip6t_rand_info)));
18660 +               return 0;
18661 +       }
18662 +
18663 +       /* must be  1 <= average % <= 99 */
18664 +       /* 1  x 2.55 = 2   */
18665 +       /* 99 x 2.55 = 252 */
18666 +       if ((info->average < 2) || (info->average > 252)) {
18667 +               printk("ip6t_random:  invalid average %u\n", info->average);
18668 +               return 0;
18669 +       }
18670 +
18671 +       return 1;
18672 +}
18673 +
18674 +static struct ip6t_match ip6t_rand_reg = { 
18675 +       {NULL, NULL},
18676 +       "random",
18677 +       ip6t_rand_match,
18678 +       ip6t_rand_checkentry,
18679 +       NULL,
18680 +       THIS_MODULE };
18681 +
18682 +static int __init init(void)
18683 +{
18684 +       if (ip6t_register_match(&ip6t_rand_reg))
18685 +               return -EINVAL;
18686 +
18687 +       printk("ip6t_random match loaded\n");
18688 +       return 0;
18689 +}
18690 +
18691 +static void __exit fini(void)
18692 +{
18693 +       ip6t_unregister_match(&ip6t_rand_reg);
18694 +       printk("ip6t_random match unloaded\n");
18695 +}
18696 +
18697 +module_init(init);
18698 +module_exit(fini);
18699 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv6/netfilter/ip6table_filter.c linux-2.6.6/net/ipv6/netfilter/ip6table_filter.c
18700 --- linux-2.6.6.org/net/ipv6/netfilter/ip6table_filter.c        2004-05-10 04:32:00.000000000 +0200
18701 +++ linux-2.6.6/net/ipv6/netfilter/ip6table_filter.c    2004-05-18 14:28:50.000000000 +0200
18702 @@ -58,7 +58,7 @@
18703                 0,
18704                 sizeof(struct ip6t_entry),
18705                 sizeof(struct ip6t_standard),
18706 -               0, { 0, 0 }, { } },
18707 +               0, NULL, 0, { 0, 0 }, { } },
18708               { { { { IP6T_ALIGN(sizeof(struct ip6t_standard_target)), "" } }, { } },
18709                 -NF_ACCEPT - 1 } },
18710             /* FORWARD */
18711 @@ -66,7 +66,7 @@
18712                 0,
18713                 sizeof(struct ip6t_entry),
18714                 sizeof(struct ip6t_standard),
18715 -               0, { 0, 0 }, { } },
18716 +               0, NULL, 0, { 0, 0 }, { } },
18717               { { { { IP6T_ALIGN(sizeof(struct ip6t_standard_target)), "" } }, { } },
18718                 -NF_ACCEPT - 1 } },
18719             /* LOCAL_OUT */
18720 @@ -74,7 +74,7 @@
18721                 0,
18722                 sizeof(struct ip6t_entry),
18723                 sizeof(struct ip6t_standard),
18724 -               0, { 0, 0 }, { } },
18725 +               0, NULL, 0, { 0, 0 }, { } },
18726               { { { { IP6T_ALIGN(sizeof(struct ip6t_standard_target)), "" } }, { } },
18727                 -NF_ACCEPT - 1 } }
18728      },
18729 @@ -83,7 +83,7 @@
18730         0,
18731         sizeof(struct ip6t_entry),
18732         sizeof(struct ip6t_error),
18733 -       0, { 0, 0 }, { } },
18734 +       0, NULL, 0, { 0, 0 }, { } },
18735        { { { { IP6T_ALIGN(sizeof(struct ip6t_error_target)), IP6T_ERROR_TARGET } },
18736           { } },
18737         "ERROR"
18738 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv6/netfilter/ip6table_mangle.c linux-2.6.6/net/ipv6/netfilter/ip6table_mangle.c
18739 --- linux-2.6.6.org/net/ipv6/netfilter/ip6table_mangle.c        2004-05-10 04:32:28.000000000 +0200
18740 +++ linux-2.6.6/net/ipv6/netfilter/ip6table_mangle.c    2004-05-18 14:28:50.000000000 +0200
18741 @@ -73,7 +73,7 @@
18742                 0,
18743                 sizeof(struct ip6t_entry),
18744                 sizeof(struct ip6t_standard),
18745 -               0, { 0, 0 }, { } },
18746 +               0, NULL, 0, { 0, 0 }, { } },
18747               { { { { IP6T_ALIGN(sizeof(struct ip6t_standard_target)), "" } }, { } },
18748                 -NF_ACCEPT - 1 } },
18749             /* LOCAL_IN */
18750 @@ -81,7 +81,7 @@
18751                 0,
18752                 sizeof(struct ip6t_entry),
18753                 sizeof(struct ip6t_standard),
18754 -               0, { 0, 0 }, { } },
18755 +               0, NULL, 0, { 0, 0 }, { } },
18756               { { { { IP6T_ALIGN(sizeof(struct ip6t_standard_target)), "" } }, { } },
18757                 -NF_ACCEPT - 1 } },
18758             /* FORWARD */
18759 @@ -89,7 +89,7 @@
18760                 0,
18761                 sizeof(struct ip6t_entry),
18762                 sizeof(struct ip6t_standard),
18763 -               0, { 0, 0 }, { } },
18764 +               0, NULL, 0, { 0, 0 }, { } },
18765               { { { { IP6T_ALIGN(sizeof(struct ip6t_standard_target)), "" } }, { } },
18766                 -NF_ACCEPT - 1 } },
18767             /* LOCAL_OUT */
18768 @@ -97,7 +97,7 @@
18769                 0,
18770                 sizeof(struct ip6t_entry),
18771                 sizeof(struct ip6t_standard),
18772 -               0, { 0, 0 }, { } },
18773 +               0, NULL, 0, { 0, 0 }, { } },
18774               { { { { IP6T_ALIGN(sizeof(struct ip6t_standard_target)), "" } }, { } },
18775                 -NF_ACCEPT - 1 } },
18776             /* POST_ROUTING */
18777 @@ -105,7 +105,7 @@
18778                 0,
18779                 sizeof(struct ip6t_entry),
18780                 sizeof(struct ip6t_standard),
18781 -               0, { 0, 0 }, { } },
18782 +               0, NULL, 0, { 0, 0 }, { } },
18783               { { { { IP6T_ALIGN(sizeof(struct ip6t_standard_target)), "" } }, { } },
18784                 -NF_ACCEPT - 1 } }
18785      },
18786 @@ -114,7 +114,7 @@
18787         0,
18788         sizeof(struct ip6t_entry),
18789         sizeof(struct ip6t_error),
18790 -       0, { 0, 0 }, { } },
18791 +       0, NULL, 0, { 0, 0 }, { } },
18792        { { { { IP6T_ALIGN(sizeof(struct ip6t_error_target)), IP6T_ERROR_TARGET } },
18793           { } },
18794         "ERROR"
18795 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv6/netfilter/ip6table_raw.c linux-2.6.6/net/ipv6/netfilter/ip6table_raw.c
18796 --- linux-2.6.6.org/net/ipv6/netfilter/ip6table_raw.c   2004-05-10 04:32:53.000000000 +0200
18797 +++ linux-2.6.6/net/ipv6/netfilter/ip6table_raw.c       2004-05-18 14:28:50.000000000 +0200
18798 @@ -52,7 +52,7 @@
18799                 0,
18800                 sizeof(struct ip6t_entry),
18801                 sizeof(struct ip6t_standard),
18802 -               0, { 0, 0 }, { } },
18803 +               0, NULL, 0, { 0, 0 }, { } },
18804               { { { { IP6T_ALIGN(sizeof(struct ip6t_standard_target)), "" } }, { } },
18805                 -NF_ACCEPT - 1 } },
18806             /* LOCAL_OUT */
18807 @@ -60,7 +60,7 @@
18808                 0,
18809                 sizeof(struct ip6t_entry),
18810                 sizeof(struct ip6t_standard),
18811 -               0, { 0, 0 }, { } },
18812 +               0, NULL, 0, { 0, 0 }, { } },
18813               { { { { IP6T_ALIGN(sizeof(struct ip6t_standard_target)), "" } }, { } },
18814                 -NF_ACCEPT - 1 } },
18815      },
18816 @@ -69,7 +69,7 @@
18817         0,
18818         sizeof(struct ip6t_entry),
18819         sizeof(struct ip6t_error),
18820 -       0, { 0, 0 }, { } },
18821 +       0, NULL, 0, { 0, 0 }, { } },
18822        { { { { IP6T_ALIGN(sizeof(struct ip6t_error_target)), IP6T_ERROR_TARGET } },
18823           { } },
18824         "ERROR"
18825 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv6/sit.c linux-2.6.6/net/ipv6/sit.c
18826 --- linux-2.6.6.org/net/ipv6/sit.c      2004-05-10 04:33:20.000000000 +0200
18827 +++ linux-2.6.6/net/ipv6/sit.c  2004-05-18 14:28:50.000000000 +0200
18828 @@ -388,13 +388,7 @@
18829                 skb->dev = tunnel->dev;
18830                 dst_release(skb->dst);
18831                 skb->dst = NULL;
18832 -#ifdef CONFIG_NETFILTER
18833 -               nf_conntrack_put(skb->nfct);
18834 -               skb->nfct = NULL;
18835 -#ifdef CONFIG_NETFILTER_DEBUG
18836 -               skb->nf_debug = 0;
18837 -#endif
18838 -#endif
18839 +               nf_reset(skb);
18840                 ipip6_ecn_decapsulate(iph, skb);
18841                 netif_rx(skb);
18842                 read_unlock(&ipip6_lock);
18843 @@ -580,13 +574,7 @@
18844         if ((iph->ttl = tiph->ttl) == 0)
18845                 iph->ttl        =       iph6->hop_limit;
18846  
18847 -#ifdef CONFIG_NETFILTER
18848 -       nf_conntrack_put(skb->nfct);
18849 -       skb->nfct = NULL;
18850 -#ifdef CONFIG_NETFILTER_DEBUG
18851 -       skb->nf_debug = 0;
18852 -#endif
18853 -#endif
18854 +       nf_reset(skb);
18855  
18856         IPTUNNEL_XMIT();
18857         tunnel->recursion--;
18858 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/xfrm/xfrm_input.c linux-2.6.6/net/xfrm/xfrm_input.c
18859 --- linux-2.6.6.org/net/xfrm/xfrm_input.c       2004-05-10 04:31:59.000000000 +0200
18860 +++ linux-2.6.6/net/xfrm/xfrm_input.c   2004-05-18 14:28:50.000000000 +0200
18861 @@ -29,6 +29,9 @@
18862         if (!sp)
18863                 return NULL;
18864  
18865 +#ifdef CONFIG_NETFILTER
18866 +       sp->decap_done = 0;
18867 +#endif
18868         sp->len = 0;
18869         if (src) {
18870                 int i;
18871 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/xfrm/xfrm_policy.c linux-2.6.6/net/xfrm/xfrm_policy.c
18872 --- linux-2.6.6.org/net/xfrm/xfrm_policy.c      2004-05-10 04:32:37.000000000 +0200
18873 +++ linux-2.6.6/net/xfrm/xfrm_policy.c  2004-05-18 14:28:50.000000000 +0200
18874 @@ -21,6 +21,7 @@
18875  #include <linux/workqueue.h>
18876  #include <linux/notifier.h>
18877  #include <linux/netdevice.h>
18878 +#include <linux/netfilter.h>
18879  #include <net/xfrm.h>
18880  #include <net/ip.h>
18881  
18882 @@ -908,6 +909,7 @@
18883  
18884         if (_decode_session(skb, &fl, family) < 0)
18885                 return 0;
18886 +       nf_nat_decode_session(skb, &fl, family);
18887  
18888         /* First, check used SA against their selectors. */
18889         if (skb->sp) {
This page took 1.555272 seconds and 3 git commands to generate.