]> git.pld-linux.org Git - packages/kernel.git/blob - 2.6.7-pom-ng-20040608.patch
+CONFIG_IP_NF_MATCH_LAYER7=m
[packages/kernel.git] / 2.6.7-pom-ng-20040608.patch
1   Netfilter SNAP 20040608
2    included:
3    updates/01_iptables-1.2.10
4    updates/02_linux-2.6.4
5    updates/04_linux-2.6.6-helper_reassign
6    updates/05_linux-2.6.6-orphaned_expect
7    PENDING/expect-evict-order
8    PENDING/expect-slab-cache
9    PENDING/init_conntrack-optimize
10    PENDING/ipt_helper-invert-fix
11    PENDING/mangle-reroute
12    PENDING/nf-log
13    PENDING/nf_reset
14    PENDING/proc-no-internal-targets
15    PENDING/proc_net_conntrack-permissions
16    BASE/HOPLIMIT
17    BASE/IPV4OPTSSTRING
18    BASE/NETLINK                 // fix socket -> sk_socket
19    BASE/REJECT
20    BASE/TTL
21    BASE/connlimit
22    BASE/dstlimit
23    BASE/fuzzy
24    BASE/ipv4options
25    BASE/mport
26    BASE/nth
27    BASE/osf                     // fix socket -> sk_socket
28    BASE/pool                    // added EXPORT_SYMBOL(ip_pool_mod, ip_pool_match)
29    BASE/psd
30    BASE/quota
31    BASE/random
32    BASE/raw                     // removed linux-2.6.patch - included in kernel
33    BASE/realm
34    BASE/sctp
35    BASE/time
36    BASE/u32
37    EXTRA/CONNMARK
38    EXTRA/IPMARK
39    EXTRA/ROUTE
40    EXTRA/TARPIT
41    EXTRA/TRACE                  // ip_output.c fix
42    EXTRA/XOR
43    EXTRA/addrtype
44    EXTRA/eggdrop-conntrack
45    EXTRA/h323-conntrack-nat
46    EXTRA/ipsec-01-output-hooks  // fixed
47    EXTRA/ipsec-02-input-hooks
48    EXTRA/ipsec-03-policy-lookup
49    EXTRA/ipsec-04-policy-check
50    EXTRA/ipt_helper-any
51    EXTRA/mms-conntrack-nat
52    EXTRA/owner-socketlookup
53    EXTRA/ownercmd
54    EXTRA/policy
55    EXTRA/quake3-conntrack-nat
56    EXTRA/rsh
57    EXTRA/rtsp-conntrack
58    EXTRA/sctp-conntrack-nat
59    EXTRA/string                 // required unclean module - included - req fix
60    EXTRA/talk-conntrack-nat
61  
62 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/include/linux/netfilter.h linux-2.6.7-rc3/include/linux/netfilter.h
63 --- linux-2.6.7-rc3.org/include/linux/netfilter.h       2004-06-07 21:14:24.000000000 +0200
64 +++ linux-2.6.7-rc3/include/linux/netfilter.h   2004-06-08 10:38:46.000000000 +0200
65 @@ -23,6 +23,7 @@
66     <= 0x2000 is used for protocol-flags. */
67  #define NFC_UNKNOWN 0x4000
68  #define NFC_ALTERED 0x8000
69 +#define NFC_TRACE   0x10000
70  
71  #ifdef __KERNEL__
72  #include <linux/config.h>
73 @@ -137,12 +138,14 @@
74  /* This is gross, but inline doesn't cut it for avoiding the function
75     call in fast path: gcc doesn't inline (needs value tracking?). --RR */
76  #ifdef CONFIG_NETFILTER_DEBUG
77 -#define NF_HOOK(pf, hook, skb, indev, outdev, okfn)                    \
78 - nf_hook_slow((pf), (hook), (skb), (indev), (outdev), (okfn), INT_MIN)
79 +#define NF_HOOK_COND(pf, hook, skb, indev, outdev, okfn, cond)         \
80 +(!(cond)                                                               \
81 + ? (okfn)(skb)                                                                 \
82 + : nf_hook_slow((pf), (hook), (skb), (indev), (outdev), (okfn), INT_MIN))
83  #define NF_HOOK_THRESH nf_hook_slow
84  #else
85 -#define NF_HOOK(pf, hook, skb, indev, outdev, okfn)                    \
86 -(list_empty(&nf_hooks[(pf)][(hook)])                                   \
87 +#define NF_HOOK_COND(pf, hook, skb, indev, outdev, okfn, cond)         \
88 +(!(cond) || list_empty(&nf_hooks[(pf)][(hook)])                                \
89   ? (okfn)(skb)                                                         \
90   : nf_hook_slow((pf), (hook), (skb), (indev), (outdev), (okfn), INT_MIN))
91  #define NF_HOOK_THRESH(pf, hook, skb, indev, outdev, okfn, thresh)     \
92 @@ -150,6 +153,8 @@
93   ? (okfn)(skb)                                                         \
94   : nf_hook_slow((pf), (hook), (skb), (indev), (outdev), (okfn), (thresh)))
95  #endif
96 +#define NF_HOOK(pf, hook, skb, indev, outdev, okfn)                    \
97 + NF_HOOK_COND((pf), (hook), (skb), (indev), (outdev), (okfn), 1)
98  
99  int nf_hook_slow(int pf, unsigned int hook, struct sk_buff *skb,
100                  struct net_device *indev, struct net_device *outdev,
101 @@ -188,7 +193,24 @@
102  
103  #else /* !CONFIG_NETFILTER */
104  #define NF_HOOK(pf, hook, skb, indev, outdev, okfn) (okfn)(skb)
105 +#define NF_HOOK_COND(pf, hook, skb, indev, outdev, okfn, cond) (okfn)(skb)
106  #endif /*CONFIG_NETFILTER*/
107  
108 +#ifdef CONFIG_XFRM
109 +#ifdef CONFIG_IP_NF_NAT_NEEDED
110 +struct flowi;
111 +extern void nf_nat_decode_session4(struct sk_buff *skb, struct flowi *fl);
112 +
113 +static inline void
114 +nf_nat_decode_session(struct sk_buff *skb, struct flowi *fl, int family)
115 +{
116 +       if (family == AF_INET)
117 +               nf_nat_decode_session4(skb, fl);
118 +}
119 +#else /* CONFIG_IP_NF_NAT_NEEDED */
120 +#define nf_nat_decode_session(skb,fl,family)
121 +#endif /* CONFIG_IP_NF_NAT_NEEDED */
122 +#endif /* CONFIG_XFRM */
123 +
124  #endif /*__KERNEL__*/
125  #endif /*__LINUX_NETFILTER_H*/
126 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/include/linux/netfilter_helpers.h linux-2.6.7-rc3/include/linux/netfilter_helpers.h
127 --- linux-2.6.7-rc3.org/include/linux/netfilter_helpers.h       1970-01-01 01:00:00.000000000 +0100
128 +++ linux-2.6.7-rc3/include/linux/netfilter_helpers.h   2004-06-08 10:40:46.000000000 +0200
129 @@ -0,0 +1,133 @@
130 +/*
131 + * Helpers for netfiler modules.  This file provides implementations for basic
132 + * functions such as strncasecmp(), etc.
133 + *
134 + * gcc will warn for defined but unused functions, so we only include the
135 + * functions requested.  The following macros are used:
136 + *   NF_NEED_STRNCASECMP        nf_strncasecmp()
137 + *   NF_NEED_STRTOU16           nf_strtou16()
138 + *   NF_NEED_STRTOU32           nf_strtou32()
139 + */
140 +#ifndef _NETFILTER_HELPERS_H
141 +#define _NETFILTER_HELPERS_H
142 +
143 +/* Only include these functions for kernel code. */
144 +#ifdef __KERNEL__
145 +
146 +#include <linux/ctype.h>
147 +#define iseol(c) ( (c) == '\r' || (c) == '\n' )
148 +
149 +/*
150 + * The standard strncasecmp()
151 + */
152 +#ifdef NF_NEED_STRNCASECMP
153 +static int
154 +nf_strncasecmp(const char* s1, const char* s2, u_int32_t len)
155 +{
156 +    if (s1 == NULL || s2 == NULL)
157 +    {
158 +        if (s1 == NULL && s2 == NULL)
159 +        {
160 +            return 0;
161 +        }
162 +        return (s1 == NULL) ? -1 : 1;
163 +    }
164 +    while (len > 0 && tolower(*s1) == tolower(*s2))
165 +    {
166 +        len--;
167 +        s1++;
168 +        s2++;
169 +    }
170 +    return ( (len == 0) ? 0 : (tolower(*s1) - tolower(*s2)) );
171 +}
172 +#endif /* NF_NEED_STRNCASECMP */
173 +
174 +/*
175 + * Parse a string containing a 16-bit unsigned integer.
176 + * Returns the number of chars used, or zero if no number is found.
177 + */
178 +#ifdef NF_NEED_STRTOU16
179 +static int
180 +nf_strtou16(const char* pbuf, u_int16_t* pval)
181 +{
182 +    int n = 0;
183 +
184 +    *pval = 0;
185 +    while (isdigit(pbuf[n]))
186 +    {
187 +        *pval = (*pval * 10) + (pbuf[n] - '0');
188 +        n++;
189 +    }
190 +
191 +    return n;
192 +}
193 +#endif /* NF_NEED_STRTOU16 */
194 +
195 +/*
196 + * Parse a string containing a 32-bit unsigned integer.
197 + * Returns the number of chars used, or zero if no number is found.
198 + */
199 +#ifdef NF_NEED_STRTOU32
200 +static int
201 +nf_strtou32(const char* pbuf, u_int32_t* pval)
202 +{
203 +    int n = 0;
204 +
205 +    *pval = 0;
206 +    while (pbuf[n] >= '0' && pbuf[n] <= '9')
207 +    {
208 +        *pval = (*pval * 10) + (pbuf[n] - '0');
209 +        n++;
210 +    }
211 +
212 +    return n;
213 +}
214 +#endif /* NF_NEED_STRTOU32 */
215 +
216 +/*
217 + * Given a buffer and length, advance to the next line and mark the current
218 + * line.
219 + */
220 +#ifdef NF_NEED_NEXTLINE
221 +static int
222 +nf_nextline(char* p, uint len, uint* poff, uint* plineoff, uint* plinelen)
223 +{
224 +    uint    off = *poff;
225 +    uint    physlen = 0;
226 +
227 +    if (off >= len)
228 +    {
229 +        return 0;
230 +    }
231 +
232 +    while (p[off] != '\n')
233 +    {
234 +        if (len-off <= 1)
235 +        {
236 +            return 0;
237 +        }
238 +
239 +        physlen++;
240 +        off++;
241 +    }
242 +
243 +    /* if we saw a crlf, physlen needs adjusted */
244 +    if (physlen > 0 && p[off] == '\n' && p[off-1] == '\r')
245 +    {
246 +        physlen--;
247 +    }
248 +
249 +    /* advance past the newline */
250 +    off++;
251 +
252 +    *plineoff = *poff;
253 +    *plinelen = physlen;
254 +    *poff = off;
255 +
256 +    return 1;
257 +}
258 +#endif /* NF_NEED_NEXTLINE */
259 +
260 +#endif /* __KERNEL__ */
261 +
262 +#endif /* _NETFILTER_HELPERS_H */
263 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ip_conntrack.h linux-2.6.7-rc3/include/linux/netfilter_ipv4/ip_conntrack.h
264 --- linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ip_conntrack.h     2004-06-07 21:14:59.000000000 +0200
265 +++ linux-2.6.7-rc3/include/linux/netfilter_ipv4/ip_conntrack.h 2004-06-08 10:41:27.000000000 +0200
266 @@ -51,10 +51,12 @@
267  
268  #include <linux/netfilter_ipv4/ip_conntrack_tcp.h>
269  #include <linux/netfilter_ipv4/ip_conntrack_icmp.h>
270 +#include <linux/netfilter_ipv4/ip_conntrack_sctp.h>
271  
272  /* per conntrack: protocol private data */
273  union ip_conntrack_proto {
274         /* insert conntrack proto private data here */
275 +       struct ip_ct_sctp sctp;
276         struct ip_ct_tcp tcp;
277         struct ip_ct_icmp icmp;
278  };
279 @@ -64,6 +66,11 @@
280  };
281  
282  /* Add protocol helper include file here */
283 +#include <linux/netfilter_ipv4/ip_conntrack_talk.h>
284 +#include <linux/netfilter_ipv4/ip_conntrack_rtsp.h>
285 +#include <linux/netfilter_ipv4/ip_conntrack_rsh.h>
286 +#include <linux/netfilter_ipv4/ip_conntrack_mms.h>
287 +#include <linux/netfilter_ipv4/ip_conntrack_h323.h>
288  #include <linux/netfilter_ipv4/ip_conntrack_amanda.h>
289  #include <linux/netfilter_ipv4/ip_conntrack_ftp.h>
290  #include <linux/netfilter_ipv4/ip_conntrack_irc.h>
291 @@ -71,6 +78,11 @@
292  /* per expectation: application helper private data */
293  union ip_conntrack_expect_help {
294         /* insert conntrack helper private data (expect) here */
295 +       struct ip_ct_talk_expect exp_talk_info;
296 +       struct ip_ct_rtsp_expect exp_rtsp_info;
297 +       struct ip_ct_rsh_expect exp_rsh_info;
298 +       struct ip_ct_mms_expect exp_mms_info;
299 +       struct ip_ct_h225_expect exp_h225_info;
300         struct ip_ct_amanda_expect exp_amanda_info;
301         struct ip_ct_ftp_expect exp_ftp_info;
302         struct ip_ct_irc_expect exp_irc_info;
303 @@ -85,6 +97,11 @@
304  /* per conntrack: application helper private data */
305  union ip_conntrack_help {
306         /* insert conntrack helper private data (master) here */
307 +       struct ip_ct_talk_master ct_talk_info;
308 +       struct ip_ct_rtsp_master ct_rtsp_info;
309 +       struct ip_ct_rsh_master ct_rsh_info;
310 +       struct ip_ct_mms_master ct_mms_info;
311 +       struct ip_ct_h225_master ct_h225_info;
312         struct ip_ct_ftp_master ct_ftp_info;
313         struct ip_ct_irc_master ct_irc_info;
314  };
315 @@ -207,6 +224,10 @@
316         } nat;
317  #endif /* CONFIG_IP_NF_NAT_NEEDED */
318  
319 +#if defined(CONFIG_IP_NF_CONNTRACK_MARK)
320 +       unsigned long mark;
321 +#endif
322 +
323  };
324  
325  /* get master conntrack via master expectation */
326 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ip_conntrack_h323.h linux-2.6.7-rc3/include/linux/netfilter_ipv4/ip_conntrack_h323.h
327 --- linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ip_conntrack_h323.h        1970-01-01 01:00:00.000000000 +0100
328 +++ linux-2.6.7-rc3/include/linux/netfilter_ipv4/ip_conntrack_h323.h    2004-06-08 10:38:40.000000000 +0200
329 @@ -0,0 +1,31 @@
330 +#ifndef _IP_CONNTRACK_H323_H
331 +#define _IP_CONNTRACK_H323_H
332 +/* H.323 connection tracking. */
333 +
334 +#ifdef __KERNEL__
335 +/* Protects H.323 related data */
336 +#include <linux/netfilter_ipv4/lockhelp.h>
337 +DECLARE_LOCK_EXTERN(ip_h323_lock);
338 +#endif
339 +
340 +/* Default H.225 port */
341 +#define H225_PORT      1720
342 +
343 +/* This structure is per expected connection */
344 +struct ip_ct_h225_expect {
345 +       u_int16_t port;                 /* Port of the H.225 helper/RTCP/RTP channel */
346 +       enum ip_conntrack_dir dir;      /* Direction of the original connection */
347 +       unsigned int offset;            /* offset of the address in the payload */
348 +};
349 +
350 +/* This structure exists only once per master */
351 +struct ip_ct_h225_master {
352 +       int is_h225;                            /* H.225 or H.245 connection */
353 +#ifdef CONFIG_IP_NF_NAT_NEEDED
354 +       enum ip_conntrack_dir dir;              /* Direction of the original connection */
355 +       u_int32_t seq[IP_CT_DIR_MAX];           /* Exceptional packet mangling for signal addressess... */
356 +       unsigned int offset[IP_CT_DIR_MAX];     /* ...and the offset of the addresses in the payload */
357 +#endif
358 +};
359 +
360 +#endif /* _IP_CONNTRACK_H323_H */
361 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ip_conntrack_mms.h linux-2.6.7-rc3/include/linux/netfilter_ipv4/ip_conntrack_mms.h
362 --- linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ip_conntrack_mms.h 1970-01-01 01:00:00.000000000 +0100
363 +++ linux-2.6.7-rc3/include/linux/netfilter_ipv4/ip_conntrack_mms.h     2004-06-08 10:39:44.000000000 +0200
364 @@ -0,0 +1,31 @@
365 +#ifndef _IP_CONNTRACK_MMS_H
366 +#define _IP_CONNTRACK_MMS_H
367 +/* MMS tracking. */
368 +
369 +#ifdef __KERNEL__
370 +#include <linux/netfilter_ipv4/lockhelp.h>
371 +
372 +DECLARE_LOCK_EXTERN(ip_mms_lock);
373 +
374 +#define MMS_PORT                         1755
375 +#define MMS_SRV_MSG_ID                   196610
376 +
377 +#define MMS_SRV_MSG_OFFSET               36
378 +#define MMS_SRV_UNICODE_STRING_OFFSET    60
379 +#define MMS_SRV_CHUNKLENLV_OFFSET        16
380 +#define MMS_SRV_CHUNKLENLM_OFFSET        32
381 +#define MMS_SRV_MESSAGELENGTH_OFFSET     8
382 +#endif
383 +
384 +/* This structure is per expected connection */
385 +struct ip_ct_mms_expect {
386 +       u_int32_t len;
387 +       u_int32_t padding;
388 +       u_int16_t port;
389 +};
390 +
391 +/* This structure exists only once per master */
392 +struct ip_ct_mms_master {
393 +};
394 +
395 +#endif /* _IP_CONNTRACK_MMS_H */
396 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ip_conntrack_quake3.h linux-2.6.7-rc3/include/linux/netfilter_ipv4/ip_conntrack_quake3.h
397 --- linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ip_conntrack_quake3.h      1970-01-01 01:00:00.000000000 +0100
398 +++ linux-2.6.7-rc3/include/linux/netfilter_ipv4/ip_conntrack_quake3.h  2004-06-08 10:40:36.000000000 +0200
399 @@ -0,0 +1,21 @@
400 +#ifndef _IP_CT_QUAKE3
401 +#define _IP_CT_QUAKE3
402 +
403 +/* Don't confuse with 27960, often used as the Server Port */
404 +#define QUAKE3_MASTER_PORT 27950
405 +
406 +struct quake3_search {
407 +       const char marker[4]; /* always 0xff 0xff 0xff 0xff ? */
408 +       const char *pattern;
409 +       size_t plen;
410 +}; 
411 +
412 +/* This structure is per expected connection */
413 +struct ip_ct_quake3_expect {
414 +};
415 +
416 +/* This structure exists only once per master */
417 +struct ip_ct_quake3_master {
418 +};
419 +
420 +#endif /* _IP_CT_QUAKE3 */
421 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ip_conntrack_rsh.h linux-2.6.7-rc3/include/linux/netfilter_ipv4/ip_conntrack_rsh.h
422 --- linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ip_conntrack_rsh.h 1970-01-01 01:00:00.000000000 +0100
423 +++ linux-2.6.7-rc3/include/linux/netfilter_ipv4/ip_conntrack_rsh.h     2004-06-08 10:40:43.000000000 +0200
424 @@ -0,0 +1,35 @@
425 +/* RSH extension for IP connection tracking, Version 1.0
426 + * (C) 2002 by Ian (Larry) Latter <Ian.Latter@mq.edu.au>
427 + * based on HW's ip_conntrack_irc.c     
428 + *
429 + * ip_conntrack_rsh.c,v 1.0 2002/07/17 14:49:26
430 + *
431 + *      This program is free software; you can redistribute it and/or
432 + *      modify it under the terms of the GNU General Public License
433 + *      as published by the Free Software Foundation; either version
434 + *      2 of the License, or (at your option) any later version.
435 + */
436 +#ifndef _IP_CONNTRACK_RSH_H
437 +#define _IP_CONNTRACK_RSH_H
438 +
439 +#ifdef __KERNEL__
440 +#include <linux/netfilter_ipv4/lockhelp.h>
441 +
442 +DECLARE_LOCK_EXTERN(ip_rsh_lock);
443 +#endif
444 +
445 +
446 +#define RSH_PORT       514
447 +
448 +/* This structure is per expected connection */
449 +struct ip_ct_rsh_expect
450 +{
451 +       u_int16_t port;
452 +};
453 +
454 +/* This structure exists only once per master */
455 +struct ip_ct_rsh_master {
456 +};
457 +
458 +#endif /* _IP_CONNTRACK_RSH_H */
459 +
460 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ip_conntrack_rtsp.h linux-2.6.7-rc3/include/linux/netfilter_ipv4/ip_conntrack_rtsp.h
461 --- linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ip_conntrack_rtsp.h        1970-01-01 01:00:00.000000000 +0100
462 +++ linux-2.6.7-rc3/include/linux/netfilter_ipv4/ip_conntrack_rtsp.h    2004-06-08 10:40:46.000000000 +0200
463 @@ -0,0 +1,68 @@
464 +/*
465 + * RTSP extension for IP connection tracking.
466 + * (C) 2003 by Tom Marshall <tmarshall@real.com>
467 + * based on ip_conntrack_irc.h
468 + *
469 + *      This program is free software; you can redistribute it and/or
470 + *      modify it under the terms of the GNU General Public License
471 + *      as published by the Free Software Foundation; either version
472 + *      2 of the License, or (at your option) any later version.
473 + */
474 +#ifndef _IP_CONNTRACK_RTSP_H
475 +#define _IP_CONNTRACK_RTSP_H
476 +
477 +/* #define IP_NF_RTSP_DEBUG */
478 +#define IP_NF_RTSP_VERSION "0.01"
479 +
480 +/* port block types */
481 +typedef enum {
482 +    pb_single,  /* client_port=x */
483 +    pb_range,   /* client_port=x-y */
484 +    pb_discon   /* client_port=x/y (rtspbis) */
485 +} portblock_t;
486 +
487 +/* We record seq number and length of rtsp headers here, all in host order. */
488 +
489 +/*
490 + * This structure is per expected connection.  It is a member of struct
491 + * ip_conntrack_expect.  The TCP SEQ for the conntrack expect is stored
492 + * there and we are expected to only store the length of the data which
493 + * needs replaced.  If a packet contains multiple RTSP messages, we create
494 + * one expected connection per message.
495 + *
496 + * We use these variables to mark the entire header block.  This may seem
497 + * like overkill, but the nature of RTSP requires it.  A header may appear
498 + * multiple times in a message.  We must treat two Transport headers the
499 + * same as one Transport header with two entries.
500 + */
501 +struct ip_ct_rtsp_expect
502 +{
503 +    u_int32_t   len;        /* length of header block */
504 +    portblock_t pbtype;     /* Type of port block that was requested */
505 +    u_int16_t   loport;     /* Port that was requested, low or first */
506 +    u_int16_t   hiport;     /* Port that was requested, high or second */
507 +#if 0
508 +    uint        method;     /* RTSP method */
509 +    uint        cseq;       /* CSeq from request */
510 +#endif
511 +};
512 +
513 +/* This structure exists only once per master */
514 +struct ip_ct_rtsp_master
515 +{
516 +    /* Empty (?) */
517 +};
518 +
519 +
520 +#ifdef __KERNEL__
521 +
522 +#include <linux/netfilter_ipv4/lockhelp.h>
523 +
524 +#define RTSP_PORT   554
525 +
526 +/* Protects rtsp part of conntracks */
527 +DECLARE_LOCK_EXTERN(ip_rtsp_lock);
528 +
529 +#endif /* __KERNEL__ */
530 +
531 +#endif /* _IP_CONNTRACK_RTSP_H */
532 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ip_conntrack_sctp.h linux-2.6.7-rc3/include/linux/netfilter_ipv4/ip_conntrack_sctp.h
533 --- linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ip_conntrack_sctp.h        1970-01-01 01:00:00.000000000 +0100
534 +++ linux-2.6.7-rc3/include/linux/netfilter_ipv4/ip_conntrack_sctp.h    2004-06-08 10:40:55.000000000 +0200
535 @@ -0,0 +1,25 @@
536 +#ifndef _IP_CONNTRACK_SCTP_H
537 +#define _IP_CONNTRACK_SCTP_H
538 +/* SCTP tracking. */
539 +
540 +enum sctp_conntrack {
541 +       SCTP_CONNTRACK_NONE,
542 +       SCTP_CONNTRACK_CLOSED,
543 +       SCTP_CONNTRACK_COOKIE_WAIT,
544 +       SCTP_CONNTRACK_COOKIE_ECHOED,
545 +       SCTP_CONNTRACK_ESTABLISHED,
546 +       SCTP_CONNTRACK_SHUTDOWN_SENT,
547 +       SCTP_CONNTRACK_SHUTDOWN_RECD,
548 +       SCTP_CONNTRACK_SHUTDOWN_ACK_SENT,
549 +       SCTP_CONNTRACK_MAX
550 +};
551 +
552 +struct ip_ct_sctp
553 +{
554 +       enum sctp_conntrack state;
555 +
556 +       u_int32_t vtag[IP_CT_DIR_MAX];
557 +       u_int32_t ttag[IP_CT_DIR_MAX];
558 +};
559 +
560 +#endif /* _IP_CONNTRACK_SCTP_H */
561 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ip_conntrack_talk.h linux-2.6.7-rc3/include/linux/netfilter_ipv4/ip_conntrack_talk.h
562 --- linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ip_conntrack_talk.h        1970-01-01 01:00:00.000000000 +0100
563 +++ linux-2.6.7-rc3/include/linux/netfilter_ipv4/ip_conntrack_talk.h    2004-06-08 10:41:27.000000000 +0200
564 @@ -0,0 +1,152 @@
565 +#ifndef _IP_CONNTRACK_TALK_H
566 +#define _IP_CONNTRACK_TALK_H
567 +/* TALK tracking. */
568 +
569 +#ifdef __KERNEL__
570 +#include <linux/in.h>
571 +#include <linux/netfilter_ipv4/lockhelp.h>
572 +
573 +/* Protects talk part of conntracks */
574 +DECLARE_LOCK_EXTERN(ip_talk_lock);
575 +#endif
576 +
577 +
578 +#define TALK_PORT      517
579 +#define NTALK_PORT     518
580 +
581 +/* talk structures and constants from <protocols/talkd.h> */
582 +
583 +/*
584 + * 4.3BSD struct sockaddr
585 + */
586 +struct talk_addr {
587 +       u_int16_t ta_family;
588 +       u_int16_t ta_port;
589 +       u_int32_t ta_addr;
590 +       u_int32_t ta_junk1;
591 +       u_int32_t ta_junk2;
592 +};
593 +
594 +#define        TALK_OLD_NSIZE  9
595 +#define        TALK_NSIZE      12
596 +#define        TALK_TTY_NSIZE  16
597 +
598 +/*
599 + * Client->server request message formats.
600 + */
601 +struct talk_msg {
602 +       u_char  type;           /* request type, see below */
603 +       char    l_name[TALK_OLD_NSIZE];/* caller's name */
604 +       char    r_name[TALK_OLD_NSIZE];/* callee's name */
605 +       u_char  pad;
606 +       u_int32_t id_num;       /* message id */
607 +       int32_t pid;            /* caller's process id */
608 +       char    r_tty[TALK_TTY_NSIZE];/* callee's tty name */
609 +       struct  talk_addr addr;         /* old (4.3) style */
610 +       struct  talk_addr ctl_addr;     /* old (4.3) style */
611 +};
612 +
613 +struct ntalk_msg {
614 +       u_char  vers;           /* protocol version */
615 +       u_char  type;           /* request type, see below */
616 +       u_char  answer;         /* not used */
617 +       u_char  pad;
618 +       u_int32_t id_num;       /* message id */
619 +       struct  talk_addr addr;         /* old (4.3) style */
620 +       struct  talk_addr ctl_addr;     /* old (4.3) style */
621 +       int32_t pid;            /* caller's process id */
622 +       char    l_name[TALK_NSIZE];/* caller's name */
623 +       char    r_name[TALK_NSIZE];/* callee's name */
624 +       char    r_tty[TALK_TTY_NSIZE];/* callee's tty name */
625 +};
626 +
627 +struct ntalk2_msg {
628 +       u_char  vers;           /* talk protocol version    */
629 +       u_char  type;           /* request type             */
630 +       u_char  answer;         /*  */
631 +       u_char  extended;       /* !0 if additional parts   */
632 +       u_int32_t id_num;       /* message id number (dels) */
633 +       struct  talk_addr addr;         /* target address   */
634 +       struct  talk_addr ctl_addr;     /* reply to address */
635 +       int32_t pid;            /* caller's process id */
636 +       char    l_name[TALK_NSIZE];  /* caller's name */
637 +       char    r_name[TALK_NSIZE];  /* callee's name */
638 +       char    r_tty[TALK_TTY_NSIZE];    /* callee's tty */
639 +};
640 +
641 +/*
642 + * Server->client response message formats.
643 + */
644 +struct talk_response {
645 +       u_char  type;           /* type of request message, see below */
646 +       u_char  answer;         /* response to request message, see below */
647 +       u_char  pad[2];
648 +       u_int32_t id_num;       /* message id */
649 +       struct  talk_addr addr; /* address for establishing conversation */
650 +};
651 +
652 +struct ntalk_response {
653 +       u_char  vers;           /* protocol version */
654 +       u_char  type;           /* type of request message, see below */
655 +       u_char  answer;         /* response to request message, see below */
656 +       u_char  pad;
657 +       u_int32_t id_num;       /* message id */
658 +       struct  talk_addr addr; /* address for establishing conversation */
659 +};
660 +
661 +struct ntalk2_response {
662 +       u_char  vers;           /* protocol version         */
663 +       u_char  type;           /* type of request message  */
664 +       u_char  answer;         /* response to request      */
665 +       u_char  rvers;          /* Version of answering vers*/
666 +       u_int32_t id_num;       /* message id number        */
667 +       struct  talk_addr addr; /* address for connection   */
668 +       /* This is at the end to compatiblize this with NTALK version.   */
669 +       char    r_name[TALK_NSIZE]; /* callee's name            */
670 +};
671 +
672 +#define TALK_STR(data, talk_str, member) ((struct talk_str *)data)->member)
673 +#define TALK_RESP(data, ver, member) (ver ? ((struct ntalk_response *)data)->member : ((struct talk_response *)data)->member)
674 +#define TALK_MSG(data, ver, member) (ver ? ((struct ntalk_msg *)data)->member : ((struct talk_msg *)data)->member)
675 +
676 +#define        TALK_VERSION    0               /* protocol versions */
677 +#define        NTALK_VERSION   1
678 +#define        NTALK2_VERSION  2
679 +
680 +/* message type values */
681 +#define LEAVE_INVITE   0       /* leave invitation with server */
682 +#define LOOK_UP                1       /* check for invitation by callee */
683 +#define DELETE         2       /* delete invitation by caller */
684 +#define ANNOUNCE       3       /* announce invitation by caller */
685 +/* NTALK2 */
686 +#define REPLY_QUERY    4       /* request reply data from local daemon */
687 +
688 +/* answer values */
689 +#define SUCCESS                0       /* operation completed properly */
690 +#define NOT_HERE       1       /* callee not logged in */
691 +#define FAILED         2       /* operation failed for unexplained reason */
692 +#define MACHINE_UNKNOWN        3       /* caller's machine name unknown */
693 +#define PERMISSION_DENIED 4    /* callee's tty doesn't permit announce */
694 +#define UNKNOWN_REQUEST        5       /* request has invalid type value */
695 +#define        BADVERSION      6       /* request has invalid protocol version */
696 +#define        BADADDR         7       /* request has invalid addr value */
697 +#define        BADCTLADDR      8       /* request has invalid ctl_addr value */
698 +/* NTALK2 */
699 +#define NO_CALLER      9       /* no-one calling answer from REPLY   */
700 +#define TRY_HERE       10      /* Not on this machine, try this      */
701 +#define SELECTIVE_REFUSAL 11   /* User Filter refusal.               */
702 +#define MAX_RESPONSE_TYPE 11   /* Make sure this is updated          */
703 +
704 +/* We don't really need much for talk */
705 +struct ip_ct_talk_expect
706 +{
707 +       /* Port that was to be used */
708 +       u_int16_t port;
709 +};
710 +
711 +/* This structure exists only once per master */
712 +struct ip_ct_talk_master
713 +{
714 +};
715 +
716 +#endif /* _IP_CONNTRACK_TALK_H */
717 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ip_conntrack_tuple.h linux-2.6.7-rc3/include/linux/netfilter_ipv4/ip_conntrack_tuple.h
718 --- linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ip_conntrack_tuple.h       2004-06-07 21:14:55.000000000 +0200
719 +++ linux-2.6.7-rc3/include/linux/netfilter_ipv4/ip_conntrack_tuple.h   2004-06-08 10:40:55.000000000 +0200
720 @@ -25,6 +25,9 @@
721         struct {
722                 u_int16_t id;
723         } icmp;
724 +       struct {
725 +               u_int16_t port;
726 +       } sctp;
727  };
728  
729  /* The manipulable part of the tuple. */
730 @@ -55,6 +58,9 @@
731                         struct {
732                                 u_int8_t type, code;
733                         } icmp;
734 +                       struct {
735 +                               u_int16_t port;
736 +                       } sctp;
737                 } u;
738  
739                 /* The protocol. */
740 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ip_pool.h linux-2.6.7-rc3/include/linux/netfilter_ipv4/ip_pool.h
741 --- linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ip_pool.h  1970-01-01 01:00:00.000000000 +0100
742 +++ linux-2.6.7-rc3/include/linux/netfilter_ipv4/ip_pool.h      2004-06-08 10:31:45.000000000 +0200
743 @@ -0,0 +1,64 @@
744 +#ifndef _IP_POOL_H
745 +#define _IP_POOL_H
746 +
747 +/***************************************************************************/
748 +/*  This program is free software; you can redistribute it and/or modify   */
749 +/*  it under the terms of the GNU General Public License as published by   */
750 +/*  the Free Software Foundation; either version 2 of the License, or     */
751 +/*  (at your option) any later version.                                           */
752 +/*                                                                        */
753 +/*  This program is distributed in the hope that it will be useful,       */
754 +/*  but WITHOUT ANY WARRANTY; without even the implied warranty of        */
755 +/*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         */
756 +/*  GNU General Public License for more details.                          */
757 +/*                                                                        */
758 +/*  You should have received a copy of the GNU General Public License     */
759 +/*  along with this program; if not, write to the Free Software                   */
760 +/*  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*/
761 +/***************************************************************************/
762 +
763 +/* A sockopt of such quality has hardly ever been seen before on the open
764 + * market!  This little beauty, hardly ever used: above 64, so it's
765 + * traditionally used for firewalling, not touched (even once!) by the
766 + * 2.0, 2.2 and 2.4 kernels!
767 + *
768 + * Comes with its own certificate of authenticity, valid anywhere in the
769 + * Free world!
770 + *
771 + * Rusty, 19.4.2000
772 + */
773 +#define SO_IP_POOL 81
774 +
775 +typedef int ip_pool_t;                 /* pool index */
776 +#define IP_POOL_NONE   ((ip_pool_t)-1)
777 +
778 +struct ip_pool_request {
779 +       int op;
780 +       ip_pool_t index;
781 +       u_int32_t addr;
782 +       u_int32_t addr2;
783 +};
784 +
785 +/* NOTE: I deliberately break the first cut ippool utility. Nobody uses it. */
786 +
787 +#define IP_POOL_BAD001         0x00000010
788 +
789 +#define IP_POOL_FLUSH          0x00000011      /* req.index, no arguments */
790 +#define IP_POOL_INIT           0x00000012      /* from addr to addr2 incl. */
791 +#define IP_POOL_DESTROY                0x00000013      /* req.index, no arguments */
792 +#define IP_POOL_ADD_ADDR       0x00000014      /* add addr to pool */
793 +#define IP_POOL_DEL_ADDR       0x00000015      /* del addr from pool */
794 +#define IP_POOL_HIGH_NR                0x00000016      /* result in req.index */
795 +#define IP_POOL_LOOKUP         0x00000017      /* result in addr and addr2 */
796 +#define IP_POOL_USAGE          0x00000018      /* result in addr */
797 +#define IP_POOL_TEST_ADDR      0x00000019      /* result (0/1) returned */
798 +
799 +#ifdef __KERNEL__
800 +
801 +/* NOTE: ip_pool_match() and ip_pool_mod() expect ADDR to be host byte order */
802 +extern int ip_pool_match(ip_pool_t pool, u_int32_t addr);
803 +extern int ip_pool_mod(ip_pool_t pool, u_int32_t addr, int isdel);
804 +
805 +#endif
806 +
807 +#endif /*_IP_POOL_H*/
808 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ip_tables.h linux-2.6.7-rc3/include/linux/netfilter_ipv4/ip_tables.h
809 --- linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ip_tables.h        2004-06-07 21:14:25.000000000 +0200
810 +++ linux-2.6.7-rc3/include/linux/netfilter_ipv4/ip_tables.h    2004-06-08 10:37:30.000000000 +0200
811 @@ -134,6 +134,12 @@
812         /* Back pointer */
813         unsigned int comefrom;
814  
815 +       /* Name of the chain */
816 +       char *chainname;
817 +       
818 +       /* Rule number in the chain. */
819 +       u_int32_t rulenum;
820 +
821         /* Packet and byte counters. */
822         struct ipt_counters counters;
823  
824 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ipt_CONNMARK.h linux-2.6.7-rc3/include/linux/netfilter_ipv4/ipt_CONNMARK.h
825 --- linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ipt_CONNMARK.h     1970-01-01 01:00:00.000000000 +0100
826 +++ linux-2.6.7-rc3/include/linux/netfilter_ipv4/ipt_CONNMARK.h 2004-06-08 10:36:58.000000000 +0200
827 @@ -0,0 +1,25 @@
828 +#ifndef _IPT_CONNMARK_H_target
829 +#define _IPT_CONNMARK_H_target
830 +
831 +/* Copyright (C) 2002,2004 MARA Systems AB <http://www.marasystems.com>
832 + * by Henrik Nordstrom <hno@marasystems.com>
833 + *
834 + * This program is free software; you can redistribute it and/or modify
835 + * it under the terms of the GNU General Public License as published by
836 + * the Free Software Foundation; either version 2 of the License, or
837 + * (at your option) any later version.
838 + */
839 +
840 +enum {
841 +       IPT_CONNMARK_SET = 0,
842 +       IPT_CONNMARK_SAVE,
843 +       IPT_CONNMARK_RESTORE
844 +};
845 +
846 +struct ipt_connmark_target_info {
847 +       unsigned long mark;
848 +       unsigned long mask;
849 +       u_int8_t mode;
850 +};
851 +
852 +#endif /*_IPT_CONNMARK_H_target*/
853 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ipt_IPMARK.h linux-2.6.7-rc3/include/linux/netfilter_ipv4/ipt_IPMARK.h
854 --- linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ipt_IPMARK.h       1970-01-01 01:00:00.000000000 +0100
855 +++ linux-2.6.7-rc3/include/linux/netfilter_ipv4/ipt_IPMARK.h   2004-06-08 10:37:02.000000000 +0200
856 @@ -0,0 +1,13 @@
857 +#ifndef _IPT_IPMARK_H_target
858 +#define _IPT_IPMARK_H_target
859 +
860 +struct ipt_ipmark_target_info {
861 +       unsigned long andmask;
862 +       unsigned long ormask;
863 +       unsigned int addr;
864 +};
865 +
866 +#define IPT_IPMARK_SRC    0
867 +#define IPT_IPMARK_DST    1
868 +
869 +#endif /*_IPT_IPMARK_H_target*/
870 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ipt_NETLINK.h linux-2.6.7-rc3/include/linux/netfilter_ipv4/ipt_NETLINK.h
871 --- linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ipt_NETLINK.h      1970-01-01 01:00:00.000000000 +0100
872 +++ linux-2.6.7-rc3/include/linux/netfilter_ipv4/ipt_NETLINK.h  2004-06-08 10:31:09.000000000 +0200
873 @@ -0,0 +1,27 @@
874 +#ifndef _IPT_FWMON_H
875 +#define _IPT_FWMON_H
876 +
877 +/* Bitmask macros */
878 +#define MASK(x,y) (x & y)
879 +#define MASK_SET(x,y) x |= y
880 +#define MASK_UNSET(x,y) x &= ~y
881 +
882 +#define USE_MARK       0x00000001
883 +#define USE_DROP       0x00000002
884 +#define USE_SIZE       0x00000004
885 +
886 +struct ipt_nldata
887 +{      
888 +       unsigned int flags;
889 +       unsigned int mark;
890 +       unsigned int size;
891 +};
892 +
893 +/* Old header */
894 +struct netlink_t {
895 +       unsigned int len;
896 +       unsigned int mark;
897 +       char iface[IFNAMSIZ];
898 +};
899 +
900 +#endif /*_IPT_FWMON_H*/
901 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ipt_ROUTE.h linux-2.6.7-rc3/include/linux/netfilter_ipv4/ipt_ROUTE.h
902 --- linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ipt_ROUTE.h        1970-01-01 01:00:00.000000000 +0100
903 +++ linux-2.6.7-rc3/include/linux/netfilter_ipv4/ipt_ROUTE.h    2004-06-08 10:37:08.000000000 +0200
904 @@ -0,0 +1,22 @@
905 +/* Header file for iptables ipt_ROUTE target
906 + *
907 + * (C) 2002 by Cédric de Launois <delaunois@info.ucl.ac.be>
908 + *
909 + * This software is distributed under GNU GPL v2, 1991
910 + */
911 +#ifndef _IPT_ROUTE_H_target
912 +#define _IPT_ROUTE_H_target
913 +
914 +#define IPT_ROUTE_IFNAMSIZ 16
915 +
916 +struct ipt_route_target_info {
917 +       char      oif[IPT_ROUTE_IFNAMSIZ];      /* Output Interface Name */
918 +       char      iif[IPT_ROUTE_IFNAMSIZ];      /* Input Interface Name  */
919 +       u_int32_t gw;                           /* IP address of gateway */
920 +       u_int8_t  flags;
921 +};
922 +
923 +/* Values for "flags" field */
924 +#define IPT_ROUTE_CONTINUE        0x01
925 +
926 +#endif /*_IPT_ROUTE_H_target*/
927 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ipt_TTL.h linux-2.6.7-rc3/include/linux/netfilter_ipv4/ipt_TTL.h
928 --- linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ipt_TTL.h  1970-01-01 01:00:00.000000000 +0100
929 +++ linux-2.6.7-rc3/include/linux/netfilter_ipv4/ipt_TTL.h      2004-06-08 10:31:21.000000000 +0200
930 @@ -0,0 +1,21 @@
931 +/* TTL modification module for IP tables
932 + * (C) 2000 by Harald Welte <laforge@gnumonks.org> */
933 +
934 +#ifndef _IPT_TTL_H
935 +#define _IPT_TTL_H
936 +
937 +enum {
938 +       IPT_TTL_SET = 0,
939 +       IPT_TTL_INC,
940 +       IPT_TTL_DEC
941 +};
942 +
943 +#define IPT_TTL_MAXMODE        IPT_TTL_DEC
944 +
945 +struct ipt_TTL_info {
946 +       u_int8_t        mode;
947 +       u_int8_t        ttl;
948 +};
949 +
950 +
951 +#endif
952 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ipt_XOR.h linux-2.6.7-rc3/include/linux/netfilter_ipv4/ipt_XOR.h
953 --- linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ipt_XOR.h  1970-01-01 01:00:00.000000000 +0100
954 +++ linux-2.6.7-rc3/include/linux/netfilter_ipv4/ipt_XOR.h      2004-06-08 10:37:54.000000000 +0200
955 @@ -0,0 +1,9 @@
956 +#ifndef _IPT_XOR_H
957 +#define _IPT_XOR_H
958 +
959 +struct ipt_XOR_info {
960 +       char            key[30];
961 +       u_int8_t        block_size;
962 +};
963 +
964 +#endif /* _IPT_XOR_H */
965 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ipt_addrtype.h linux-2.6.7-rc3/include/linux/netfilter_ipv4/ipt_addrtype.h
966 --- linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ipt_addrtype.h     1970-01-01 01:00:00.000000000 +0100
967 +++ linux-2.6.7-rc3/include/linux/netfilter_ipv4/ipt_addrtype.h 2004-06-08 10:38:04.000000000 +0200
968 @@ -0,0 +1,11 @@
969 +#ifndef _IPT_ADDRTYPE_H
970 +#define _IPT_ADDRTYPE_H
971 +
972 +struct ipt_addrtype_info {
973 +       u_int16_t       source;         /* source-type mask */
974 +       u_int16_t       dest;           /* dest-type mask */
975 +       int             invert_source;
976 +       int             invert_dest;
977 +};
978 +
979 +#endif
980 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ipt_connlimit.h linux-2.6.7-rc3/include/linux/netfilter_ipv4/ipt_connlimit.h
981 --- linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ipt_connlimit.h    1970-01-01 01:00:00.000000000 +0100
982 +++ linux-2.6.7-rc3/include/linux/netfilter_ipv4/ipt_connlimit.h        2004-06-08 10:31:23.000000000 +0200
983 @@ -0,0 +1,12 @@
984 +#ifndef _IPT_CONNLIMIT_H
985 +#define _IPT_CONNLIMIT_H
986 +
987 +struct ipt_connlimit_data;
988 +
989 +struct ipt_connlimit_info {
990 +       int limit;
991 +       int inverse;
992 +       u_int32_t mask;
993 +       struct ipt_connlimit_data *data;
994 +};
995 +#endif /* _IPT_CONNLIMIT_H */
996 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ipt_connmark.h linux-2.6.7-rc3/include/linux/netfilter_ipv4/ipt_connmark.h
997 --- linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ipt_connmark.h     1970-01-01 01:00:00.000000000 +0100
998 +++ linux-2.6.7-rc3/include/linux/netfilter_ipv4/ipt_connmark.h 2004-06-08 10:36:58.000000000 +0200
999 @@ -0,0 +1,18 @@
1000 +#ifndef _IPT_CONNMARK_H
1001 +#define _IPT_CONNMARK_H
1002 +
1003 +/* Copyright (C) 2002,2004 MARA Systems AB <http://www.marasystems.com>
1004 + * by Henrik Nordstrom <hno@marasystems.com>
1005 + *
1006 + * This program is free software; you can redistribute it and/or modify
1007 + * it under the terms of the GNU General Public License as published by
1008 + * the Free Software Foundation; either version 2 of the License, or
1009 + * (at your option) any later version.
1010 + */
1011 +
1012 +struct ipt_connmark_info {
1013 +       unsigned long mark, mask;
1014 +       u_int8_t invert;
1015 +};
1016 +
1017 +#endif /*_IPT_CONNMARK_H*/
1018 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ipt_dstlimit.h linux-2.6.7-rc3/include/linux/netfilter_ipv4/ipt_dstlimit.h
1019 --- linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ipt_dstlimit.h     1970-01-01 01:00:00.000000000 +0100
1020 +++ linux-2.6.7-rc3/include/linux/netfilter_ipv4/ipt_dstlimit.h 2004-06-08 10:31:34.000000000 +0200
1021 @@ -0,0 +1,39 @@
1022 +#ifndef _IPT_DSTLIMIT_H
1023 +#define _IPT_DSTLIMIT_H
1024 +
1025 +/* timings are in milliseconds. */
1026 +#define IPT_DSTLIMIT_SCALE 10000
1027 +/* 1/10,000 sec period => max of 10,000/sec.  Min rate is then 429490
1028 +   seconds, or one every 59 hours. */
1029 +
1030 +/* details of this structure hidden by the implementation */
1031 +struct ipt_dstlimit_htable;
1032 +
1033 +#define IPT_DSTLIMIT_HASH_DIP  0x0001
1034 +#define IPT_DSTLIMIT_HASH_DPT  0x0002
1035 +#define IPT_DSTLIMIT_HASH_SIP  0x0004
1036 +
1037 +struct dstlimit_cfg {
1038 +       u_int32_t mode;   /* bitmask of IPT_DSTLIMIT_HASH_* */
1039 +       u_int32_t avg;    /* Average secs between packets * scale */
1040 +       u_int32_t burst;  /* Period multiplier for upper limit. */
1041 +
1042 +       /* user specified */
1043 +       u_int32_t size;         /* how many buckets */
1044 +       u_int32_t max;          /* max number of entries */
1045 +       u_int32_t gc_interval;  /* gc interval */
1046 +       u_int32_t expire;       /* when do entries expire? */
1047 +};
1048 +
1049 +struct ipt_dstlimit_info {
1050 +       char name [IFNAMSIZ];           /* name */
1051 +       struct dstlimit_cfg cfg;
1052 +       struct ipt_dstlimit_htable *hinfo;
1053 +
1054 +       /* Used internally by the kernel */
1055 +       union {
1056 +               void *ptr;
1057 +               struct ipt_dstlimit_info *master;
1058 +       } u;
1059 +};
1060 +#endif /*_IPT_DSTLIMIT_H*/
1061 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ipt_fuzzy.h linux-2.6.7-rc3/include/linux/netfilter_ipv4/ipt_fuzzy.h
1062 --- linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ipt_fuzzy.h        1970-01-01 01:00:00.000000000 +0100
1063 +++ linux-2.6.7-rc3/include/linux/netfilter_ipv4/ipt_fuzzy.h    2004-06-08 10:31:37.000000000 +0200
1064 @@ -0,0 +1,21 @@
1065 +#ifndef _IPT_FUZZY_H
1066 +#define _IPT_FUZZY_H
1067 +
1068 +#include <linux/param.h>
1069 +#include <linux/types.h>
1070 +
1071 +#define MAXFUZZYRATE 10000000
1072 +#define MINFUZZYRATE 3
1073 +
1074 +struct ipt_fuzzy_info {
1075 +       u_int32_t minimum_rate;
1076 +       u_int32_t maximum_rate;
1077 +       u_int32_t packets_total;
1078 +       u_int32_t bytes_total;
1079 +       u_int32_t previous_time;
1080 +       u_int32_t present_time;
1081 +       u_int32_t mean_rate;
1082 +       u_int8_t acceptance_rate;
1083 +};
1084 +
1085 +#endif /*_IPT_FUZZY_H*/
1086 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ipt_ipv4options.h linux-2.6.7-rc3/include/linux/netfilter_ipv4/ipt_ipv4options.h
1087 --- linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ipt_ipv4options.h  1970-01-01 01:00:00.000000000 +0100
1088 +++ linux-2.6.7-rc3/include/linux/netfilter_ipv4/ipt_ipv4options.h      2004-06-08 10:31:39.000000000 +0200
1089 @@ -0,0 +1,21 @@
1090 +#ifndef __ipt_ipv4options_h_included__
1091 +#define __ipt_ipv4options_h_included__
1092 +
1093 +#define IPT_IPV4OPTION_MATCH_SSRR              0x01  /* For strict source routing */
1094 +#define IPT_IPV4OPTION_MATCH_LSRR              0x02  /* For loose source routing */
1095 +#define IPT_IPV4OPTION_DONT_MATCH_SRR          0x04  /* any source routing */
1096 +#define IPT_IPV4OPTION_MATCH_RR                        0x08  /* For Record route */
1097 +#define IPT_IPV4OPTION_DONT_MATCH_RR           0x10
1098 +#define IPT_IPV4OPTION_MATCH_TIMESTAMP         0x20  /* For timestamp request */
1099 +#define IPT_IPV4OPTION_DONT_MATCH_TIMESTAMP    0x40
1100 +#define IPT_IPV4OPTION_MATCH_ROUTER_ALERT      0x80  /* For router-alert */
1101 +#define IPT_IPV4OPTION_DONT_MATCH_ROUTER_ALERT 0x100
1102 +#define IPT_IPV4OPTION_MATCH_ANY_OPT           0x200 /* match packet with any option */
1103 +#define IPT_IPV4OPTION_DONT_MATCH_ANY_OPT      0x400 /* match packet with no option */
1104 +
1105 +struct ipt_ipv4options_info {
1106 +       u_int16_t options;
1107 +};
1108 +
1109 +
1110 +#endif /* __ipt_ipv4options_h_included__ */
1111 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ipt_mport.h linux-2.6.7-rc3/include/linux/netfilter_ipv4/ipt_mport.h
1112 --- linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ipt_mport.h        1970-01-01 01:00:00.000000000 +0100
1113 +++ linux-2.6.7-rc3/include/linux/netfilter_ipv4/ipt_mport.h    2004-06-08 10:31:40.000000000 +0200
1114 @@ -0,0 +1,24 @@
1115 +#ifndef _IPT_MPORT_H
1116 +#define _IPT_MPORT_H
1117 +#include <linux/netfilter_ipv4/ip_tables.h>
1118 +
1119 +#define IPT_MPORT_SOURCE (1<<0)
1120 +#define IPT_MPORT_DESTINATION (1<<1)
1121 +#define IPT_MPORT_EITHER (IPT_MPORT_SOURCE|IPT_MPORT_DESTINATION)
1122 +
1123 +#define IPT_MULTI_PORTS        15
1124 +
1125 +/* Must fit inside union ipt_matchinfo: 32 bytes */
1126 +/* every entry in ports[] except for the last one has one bit in pflags
1127 + * associated with it. If this bit is set, the port is the first port of
1128 + * a portrange, with the next entry being the last.
1129 + * End of list is marked with pflags bit set and port=65535.
1130 + * If 14 ports are used (last one does not have a pflag), the last port
1131 + * is repeated to fill the last entry in ports[] */
1132 +struct ipt_mport
1133 +{
1134 +       u_int8_t flags:2;                       /* Type of comparison */
1135 +       u_int16_t pflags:14;                    /* Port flags */
1136 +       u_int16_t ports[IPT_MULTI_PORTS];       /* Ports */
1137 +};
1138 +#endif /*_IPT_MPORT_H*/
1139 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ipt_nth.h linux-2.6.7-rc3/include/linux/netfilter_ipv4/ipt_nth.h
1140 --- linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ipt_nth.h  1970-01-01 01:00:00.000000000 +0100
1141 +++ linux-2.6.7-rc3/include/linux/netfilter_ipv4/ipt_nth.h      2004-06-08 10:31:42.000000000 +0200
1142 @@ -0,0 +1,19 @@
1143 +#ifndef _IPT_NTH_H
1144 +#define _IPT_NTH_H
1145 +
1146 +#include <linux/param.h>
1147 +#include <linux/types.h>
1148 +
1149 +#ifndef IPT_NTH_NUM_COUNTERS
1150 +#define IPT_NTH_NUM_COUNTERS 16
1151 +#endif
1152 +
1153 +struct ipt_nth_info {
1154 +       u_int8_t every;
1155 +       u_int8_t not;
1156 +       u_int8_t startat;
1157 +       u_int8_t counter;
1158 +       u_int8_t packet;
1159 +};
1160 +
1161 +#endif /*_IPT_NTH_H*/
1162 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ipt_osf.h linux-2.6.7-rc3/include/linux/netfilter_ipv4/ipt_osf.h
1163 --- linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ipt_osf.h  1970-01-01 01:00:00.000000000 +0100
1164 +++ linux-2.6.7-rc3/include/linux/netfilter_ipv4/ipt_osf.h      2004-06-08 10:31:44.000000000 +0200
1165 @@ -0,0 +1,148 @@
1166 +/*
1167 + * ipt_osf.h
1168 + *
1169 + * Copyright (c) 2003 Evgeniy Polyakov <johnpol@2ka.mipt.ru>
1170 + *
1171 + *
1172 + * This program is free software; you can redistribute it and/or modify
1173 + * it under the terms of the GNU General Public License as published by
1174 + * the Free Software Foundation; either version 2 of the License, or
1175 + * (at your option) any later version.
1176 + *
1177 + * This program is distributed in the hope that it will be useful,
1178 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1179 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1180 + * GNU General Public License for more details.
1181 + *
1182 + * You should have received a copy of the GNU General Public License
1183 + * along with this program; if not, write to the Free Software
1184 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1185 + */
1186 +
1187 +#ifndef _IPT_OSF_H
1188 +#define _IPT_OSF_H
1189 +
1190 +#define MAXGENRELEN            32
1191 +#define MAXDETLEN              64
1192 +
1193 +#define IPT_OSF_GENRE          1
1194 +#define        IPT_OSF_SMART           2
1195 +#define IPT_OSF_LOG            4
1196 +#define IPT_OSF_NETLINK                8
1197 +
1198 +#define IPT_OSF_LOGLEVEL_ALL   0
1199 +#define IPT_OSF_LOGLEVEL_FIRST 1
1200 +
1201 +#include <linux/list.h>
1202 +
1203 +#ifndef __KERNEL__
1204 +#include <netinet/ip.h>
1205 +#include <netinet/tcp.h>
1206 +
1207 +struct list_head
1208 +{
1209 +       struct list_head *prev, *next;
1210 +};
1211 +#endif
1212 +
1213 +struct ipt_osf_info
1214 +{
1215 +       char                    genre[MAXGENRELEN];
1216 +       int                     len;
1217 +       unsigned long           flags;
1218 +       int                     loglevel;
1219 +       int                     invert; /* UNSUPPORTED */
1220 +};
1221 +
1222 +struct osf_wc
1223 +{
1224 +       char                    wc;
1225 +       unsigned long           val;
1226 +};
1227 +
1228 +/* This struct represents IANA options
1229 + * http://www.iana.org/assignments/tcp-parameters
1230 + */
1231 +struct osf_opt
1232 +{
1233 +       unsigned char           kind;
1234 +       unsigned char           length;
1235 +       struct osf_wc           wc;
1236 +};
1237 +
1238 +struct osf_finger
1239 +{
1240 +       struct list_head        flist;
1241 +       struct osf_wc           wss;
1242 +       unsigned char           ttl;
1243 +       unsigned char           df;
1244 +       unsigned long           ss;
1245 +       unsigned char           genre[MAXGENRELEN];
1246 +       unsigned char           version[MAXGENRELEN], subtype[MAXGENRELEN];
1247 +       
1248 +       /* Not needed, but for consistency with original table from Michal Zalewski */
1249 +       unsigned char           details[MAXDETLEN]; 
1250 +
1251 +       int                     opt_num;
1252 +       struct osf_opt          opt[MAX_IPOPTLEN]; /* In case it is all NOP or EOL */
1253 +
1254 +};
1255 +
1256 +struct ipt_osf_nlmsg
1257 +{
1258 +       struct osf_finger       f;
1259 +       struct iphdr            ip;
1260 +       struct tcphdr           tcp;
1261 +};
1262 +
1263 +#ifdef __KERNEL__
1264 +
1265 +/* Defines for IANA option kinds */
1266 +
1267 +#define OSFOPT_EOL             0       /* End of options */
1268 +#define OSFOPT_NOP             1       /* NOP */
1269 +#define OSFOPT_MSS             2       /* Maximum segment size */
1270 +#define OSFOPT_WSO             3       /* Window scale option */
1271 +#define OSFOPT_SACKP           4       /* SACK permitted */
1272 +#define OSFOPT_SACK            5       /* SACK */
1273 +#define OSFOPT_ECHO            6       
1274 +#define OSFOPT_ECHOREPLY       7
1275 +#define OSFOPT_TS              8       /* Timestamp option */
1276 +#define OSFOPT_POCP            9       /* Partial Order Connection Permitted */
1277 +#define OSFOPT_POSP            10      /* Partial Order Service Profile */
1278 +/* Others are not used in current OSF */
1279 +
1280 +static struct osf_opt IANA_opts[] = 
1281 +{
1282 +       {0, 1,},
1283 +       {1, 1,},
1284 +       {2, 4,},
1285 +       {3, 3,},
1286 +       {4, 2,},
1287 +       {5, 1 ,}, /* SACK length is not defined */
1288 +       {6, 6,},
1289 +       {7, 6,},
1290 +       {8, 10,},
1291 +       {9, 2,},
1292 +       {10, 3,},
1293 +       {11, 1,}, /* CC: Suppose 1 */
1294 +       {12, 1,}, /* the same */
1295 +       {13, 1,}, /* and here too */
1296 +       {14, 3,},
1297 +       {15, 1,}, /* TCP Alternate Checksum Data. Length is not defined */
1298 +       {16, 1,},
1299 +       {17, 1,},
1300 +       {18, 3,},
1301 +       {19, 18,},
1302 +       {20, 1,},
1303 +       {21, 1,},
1304 +       {22, 1,},
1305 +       {23, 1,},
1306 +       {24, 1,},
1307 +       {25, 1,},
1308 +       {26, 1,},
1309 +};
1310 +
1311 +#endif /* __KERNEL__ */
1312 +
1313 +#endif /* _IPT_OSF_H */
1314 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ipt_policy.h linux-2.6.7-rc3/include/linux/netfilter_ipv4/ipt_policy.h
1315 --- linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ipt_policy.h       1970-01-01 01:00:00.000000000 +0100
1316 +++ linux-2.6.7-rc3/include/linux/netfilter_ipv4/ipt_policy.h   2004-06-08 10:42:36.000000000 +0200
1317 @@ -0,0 +1,52 @@
1318 +#ifndef _IPT_POLICY_H
1319 +#define _IPT_POLICY_H
1320 +
1321 +#define POLICY_MAX_ELEM        4
1322 +
1323 +enum ipt_policy_flags
1324 +{
1325 +       POLICY_MATCH_IN         = 0x1,
1326 +       POLICY_MATCH_OUT        = 0x2,
1327 +       POLICY_MATCH_NONE       = 0x4,
1328 +       POLICY_MATCH_STRICT     = 0x8,
1329 +};
1330 +
1331 +enum ipt_policy_modes
1332 +{
1333 +       POLICY_MODE_TRANSPORT,
1334 +       POLICY_MODE_TUNNEL
1335 +};
1336 +
1337 +struct ipt_policy_spec
1338 +{
1339 +       u_int8_t        saddr:1,
1340 +                       daddr:1,
1341 +                       proto:1,
1342 +                       mode:1,
1343 +                       spi:1,
1344 +                       reqid:1;
1345 +};
1346 +
1347 +struct ipt_policy_elem
1348 +{
1349 +       u_int32_t       saddr;
1350 +       u_int32_t       smask;
1351 +       u_int32_t       daddr;
1352 +       u_int32_t       dmask;
1353 +       u_int32_t       spi;
1354 +       u_int32_t       reqid;
1355 +       u_int8_t        proto;
1356 +       u_int8_t        mode;
1357 +
1358 +       struct ipt_policy_spec  match;
1359 +       struct ipt_policy_spec  invert;
1360 +};
1361 +
1362 +struct ipt_policy_info
1363 +{
1364 +       struct ipt_policy_elem pol[POLICY_MAX_ELEM];
1365 +       u_int16_t flags;
1366 +       u_int16_t len;
1367 +};
1368 +
1369 +#endif /* _IPT_POLICY_H */
1370 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ipt_pool.h linux-2.6.7-rc3/include/linux/netfilter_ipv4/ipt_pool.h
1371 --- linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ipt_pool.h 1970-01-01 01:00:00.000000000 +0100
1372 +++ linux-2.6.7-rc3/include/linux/netfilter_ipv4/ipt_pool.h     2004-06-08 10:31:45.000000000 +0200
1373 @@ -0,0 +1,25 @@
1374 +#ifndef _IPT_POOL_H
1375 +#define _IPT_POOL_H
1376 +
1377 +#include <linux/netfilter_ipv4/ip_pool.h>
1378 +
1379 +#define IPT_POOL_INV_SRC       0x00000001
1380 +#define IPT_POOL_INV_DST       0x00000002
1381 +#define IPT_POOL_DEL_SRC       0x00000004
1382 +#define IPT_POOL_DEL_DST       0x00000008
1383 +#define IPT_POOL_INV_MOD_SRC   0x00000010
1384 +#define IPT_POOL_INV_MOD_DST   0x00000020
1385 +#define IPT_POOL_MOD_SRC_ACCEPT        0x00000040
1386 +#define IPT_POOL_MOD_DST_ACCEPT        0x00000080
1387 +#define IPT_POOL_MOD_SRC_DROP  0x00000100
1388 +#define IPT_POOL_MOD_DST_DROP  0x00000200
1389 +
1390 +/* match info */
1391 +struct ipt_pool_info
1392 +{
1393 +       ip_pool_t src;
1394 +       ip_pool_t dst;
1395 +       unsigned flags;
1396 +};
1397 +
1398 +#endif /*_IPT_POOL_H*/
1399 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ipt_psd.h linux-2.6.7-rc3/include/linux/netfilter_ipv4/ipt_psd.h
1400 --- linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ipt_psd.h  1970-01-01 01:00:00.000000000 +0100
1401 +++ linux-2.6.7-rc3/include/linux/netfilter_ipv4/ipt_psd.h      2004-06-08 10:31:53.000000000 +0200
1402 @@ -0,0 +1,40 @@
1403 +#ifndef _IPT_PSD_H
1404 +#define _IPT_PSD_H
1405 +
1406 +#include <linux/param.h>
1407 +#include <linux/types.h>
1408 +
1409 +/*
1410 + * High port numbers have a lower weight to reduce the frequency of false
1411 + * positives, such as from passive mode FTP transfers.
1412 + */
1413 +#define PORT_WEIGHT_PRIV               3
1414 +#define PORT_WEIGHT_HIGH               1
1415 +
1416 +/*
1417 + * Port scan detection thresholds: at least COUNT ports need to be scanned
1418 + * from the same source, with no longer than DELAY ticks between ports.
1419 + */
1420 +#define SCAN_MIN_COUNT                 7
1421 +#define SCAN_MAX_COUNT                 (SCAN_MIN_COUNT * PORT_WEIGHT_PRIV)
1422 +#define SCAN_WEIGHT_THRESHOLD          SCAN_MAX_COUNT
1423 +#define SCAN_DELAY_THRESHOLD           (300) /* old usage of HZ here was erroneously and broke under uml */
1424 +
1425 +/*
1426 + * Keep track of up to LIST_SIZE source addresses, using a hash table of
1427 + * HASH_SIZE entries for faster lookups, but limiting hash collisions to
1428 + * HASH_MAX source addresses per the same hash value.
1429 + */
1430 +#define LIST_SIZE                      0x100
1431 +#define HASH_LOG                       9
1432 +#define HASH_SIZE                      (1 << HASH_LOG)
1433 +#define HASH_MAX                       0x10
1434 +
1435 +struct ipt_psd_info {
1436 +       unsigned int weight_threshold;
1437 +       unsigned int delay_threshold;
1438 +       unsigned short lo_ports_weight;
1439 +       unsigned short hi_ports_weight;
1440 +};
1441 +
1442 +#endif /*_IPT_PSD_H*/
1443 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ipt_quota.h linux-2.6.7-rc3/include/linux/netfilter_ipv4/ipt_quota.h
1444 --- linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ipt_quota.h        1970-01-01 01:00:00.000000000 +0100
1445 +++ linux-2.6.7-rc3/include/linux/netfilter_ipv4/ipt_quota.h    2004-06-08 10:31:54.000000000 +0200
1446 @@ -0,0 +1,11 @@
1447 +#ifndef _IPT_QUOTA_H
1448 +#define _IPT_QUOTA_H
1449 +
1450 +/* print debug info in both kernel/netfilter module & iptable library */
1451 +//#define DEBUG_IPT_QUOTA
1452 +
1453 +struct ipt_quota_info {
1454 +        u_int64_t quota;
1455 +};
1456 +
1457 +#endif /*_IPT_QUOTA_H*/
1458 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ipt_random.h linux-2.6.7-rc3/include/linux/netfilter_ipv4/ipt_random.h
1459 --- linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ipt_random.h       1970-01-01 01:00:00.000000000 +0100
1460 +++ linux-2.6.7-rc3/include/linux/netfilter_ipv4/ipt_random.h   2004-06-08 10:31:56.000000000 +0200
1461 @@ -0,0 +1,11 @@
1462 +#ifndef _IPT_RAND_H
1463 +#define _IPT_RAND_H
1464 +
1465 +#include <linux/param.h>
1466 +#include <linux/types.h>
1467 +
1468 +struct ipt_rand_info {
1469 +       u_int8_t average;
1470 +};
1471 +
1472 +#endif /*_IPT_RAND_H*/
1473 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ipt_realm.h linux-2.6.7-rc3/include/linux/netfilter_ipv4/ipt_realm.h
1474 --- linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ipt_realm.h        1970-01-01 01:00:00.000000000 +0100
1475 +++ linux-2.6.7-rc3/include/linux/netfilter_ipv4/ipt_realm.h    2004-06-08 10:32:20.000000000 +0200
1476 @@ -0,0 +1,9 @@
1477 +#ifndef _IPT_REALM_H
1478 +#define _IPT_REALM_H
1479 +
1480 +struct ipt_realm_info {
1481 +       u_int32_t id;
1482 +       u_int32_t mask;
1483 +       u_int8_t invert;
1484 +};
1485 +#endif /*_IPT_REALM_H*/
1486 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ipt_sctp.h linux-2.6.7-rc3/include/linux/netfilter_ipv4/ipt_sctp.h
1487 --- linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ipt_sctp.h 1970-01-01 01:00:00.000000000 +0100
1488 +++ linux-2.6.7-rc3/include/linux/netfilter_ipv4/ipt_sctp.h     2004-06-08 10:32:21.000000000 +0200
1489 @@ -0,0 +1,107 @@
1490 +#ifndef _IPT_SCTP_H_
1491 +#define _IPT_SCTP_H_
1492 +
1493 +#define IPT_SCTP_SRC_PORTS             0x01
1494 +#define IPT_SCTP_DEST_PORTS            0x02
1495 +#define IPT_SCTP_CHUNK_TYPES           0x04
1496 +
1497 +#define IPT_SCTP_VALID_FLAGS           0x07
1498 +
1499 +#define ELEMCOUNT(x) (sizeof(x)/sizeof(x[0]))
1500 +
1501 +
1502 +struct ipt_sctp_flag_info {
1503 +       u_int8_t chunktype;
1504 +       u_int8_t flag;
1505 +       u_int8_t flag_mask;
1506 +};
1507 +
1508 +#define IPT_NUM_SCTP_FLAGS     4
1509 +
1510 +struct ipt_sctp_info {
1511 +       u_int16_t dpts[2];  /* Min, Max */
1512 +       u_int16_t spts[2];  /* Min, Max */
1513 +
1514 +       u_int32_t chunkmap[256 / sizeof (u_int32_t)];  /* Bit mask of chunks to be matched according to RFC 2960 */
1515 +
1516 +#define SCTP_CHUNK_MATCH_ANY   0x01  /* Match if any of the chunk types are present */
1517 +#define SCTP_CHUNK_MATCH_ALL   0x02  /* Match if all of the chunk types are present */
1518 +#define SCTP_CHUNK_MATCH_ONLY  0x04  /* Match if these are the only chunk types present */
1519 +
1520 +       u_int32_t chunk_match_type;
1521 +       struct ipt_sctp_flag_info flag_info[IPT_NUM_SCTP_FLAGS];
1522 +       int flag_count;
1523 +
1524 +       u_int32_t flags;
1525 +       u_int32_t invflags;
1526 +};
1527 +
1528 +#define bytes(type) (sizeof(type) * 8)
1529 +
1530 +#define SCTP_CHUNKMAP_SET(chunkmap, type)              \
1531 +       do {                                            \
1532 +               chunkmap[type / bytes(u_int32_t)] |=    \
1533 +                       1 << (type % bytes(u_int32_t)); \
1534 +       } while (0)
1535 +
1536 +#define SCTP_CHUNKMAP_CLEAR(chunkmap, type)                    \
1537 +       do {                                                    \
1538 +               chunkmap[type / bytes(u_int32_t)] &=            \
1539 +                       ~(1 << (type % bytes(u_int32_t)));      \
1540 +       } while (0)
1541 +
1542 +#define SCTP_CHUNKMAP_IS_SET(chunkmap, type)                   \
1543 +({                                                             \
1544 +       (chunkmap[type / bytes (u_int32_t)] &                   \
1545 +               (1 << (type % bytes (u_int32_t)))) ? 1: 0;      \
1546 +})
1547 +
1548 +#define SCTP_CHUNKMAP_RESET(chunkmap)                          \
1549 +       do {                                                    \
1550 +               int i;                                          \
1551 +               for (i = 0; i < ELEMCOUNT(chunkmap); i++)       \
1552 +                       chunkmap[i] = 0;                        \
1553 +       } while (0)
1554 +
1555 +#define SCTP_CHUNKMAP_SET_ALL(chunkmap)                        \
1556 +       do {                                                    \
1557 +               int i;                                          \
1558 +               for (i = 0; i < ELEMCOUNT(chunkmap); i++)       \
1559 +                       chunkmap[i] = ~0;                       \
1560 +       } while (0)
1561 +
1562 +#define SCTP_CHUNKMAP_COPY(destmap, srcmap)                    \
1563 +       do {                                                    \
1564 +               int i;                                          \
1565 +               for (i = 0; i < ELEMCOUNT(chunkmap); i++)       \
1566 +                       destmap[i] = srcmap[i];                 \
1567 +       } while (0)
1568 +
1569 +#define SCTP_CHUNKMAP_IS_CLEAR(chunkmap)               \
1570 +({                                                     \
1571 +       int i;                                          \
1572 +       int flag = 1;                                   \
1573 +       for (i = 0; i < ELEMCOUNT(chunkmap); i++) {     \
1574 +               if (chunkmap[i]) {                      \
1575 +                       flag = 0;                       \
1576 +                       break;                          \
1577 +               }                                       \
1578 +       }                                               \
1579 +        flag;                                          \
1580 +})
1581 +
1582 +#define SCTP_CHUNKMAP_IS_ALL_SET(chunkmap)             \
1583 +({                                                     \
1584 +       int i;                                          \
1585 +       int flag = 1;                                   \
1586 +       for (i = 0; i < ELEMCOUNT(chunkmap); i++) {     \
1587 +               if (chunkmap[i] != ~0) {                \
1588 +                       flag = 0;                       \
1589 +                               break;                  \
1590 +               }                                       \
1591 +       }                                               \
1592 +        flag;                                          \
1593 +})
1594 +
1595 +#endif /* _IPT_SCTP_H_ */
1596 +
1597 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ipt_string.h linux-2.6.7-rc3/include/linux/netfilter_ipv4/ipt_string.h
1598 --- linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ipt_string.h       1970-01-01 01:00:00.000000000 +0100
1599 +++ linux-2.6.7-rc3/include/linux/netfilter_ipv4/ipt_string.h   2004-06-08 10:41:24.000000000 +0200
1600 @@ -0,0 +1,21 @@
1601 +#ifndef _IPT_STRING_H
1602 +#define _IPT_STRING_H
1603 +
1604 +/* *** PERFORMANCE TWEAK ***
1605 + * Packet size and search string threshold,
1606 + * above which sublinear searches is used. */
1607 +#define IPT_STRING_HAYSTACK_THRESH     100
1608 +#define IPT_STRING_NEEDLE_THRESH       20
1609 +
1610 +#define BM_MAX_NLEN 256
1611 +#define BM_MAX_HLEN 1024
1612 +
1613 +typedef char *(*proc_ipt_search) (char *, char *, int, int);
1614 +
1615 +struct ipt_string_info {
1616 +    char string[BM_MAX_NLEN];
1617 +    u_int16_t invert;
1618 +    u_int16_t len;
1619 +};
1620 +
1621 +#endif /* _IPT_STRING_H */
1622 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ipt_time.h linux-2.6.7-rc3/include/linux/netfilter_ipv4/ipt_time.h
1623 --- linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ipt_time.h 1970-01-01 01:00:00.000000000 +0100
1624 +++ linux-2.6.7-rc3/include/linux/netfilter_ipv4/ipt_time.h     2004-06-08 10:32:31.000000000 +0200
1625 @@ -0,0 +1,15 @@
1626 +#ifndef __ipt_time_h_included__
1627 +#define __ipt_time_h_included__
1628 +
1629 +
1630 +struct ipt_time_info {
1631 +       u_int8_t  days_match;   /* 1 bit per day. -SMTWTFS                      */
1632 +       u_int16_t time_start;   /* 0 < time_start < 23*60+59 = 1439             */
1633 +       u_int16_t time_stop;    /* 0:0 < time_stat < 23:59                      */
1634 +       u_int8_t  kerneltime;   /* ignore skb time (and use kerneltime) or not. */
1635 +       time_t    date_start;
1636 +       time_t    date_stop;
1637 +};
1638 +
1639 +
1640 +#endif /* __ipt_time_h_included__ */
1641 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ipt_u32.h linux-2.6.7-rc3/include/linux/netfilter_ipv4/ipt_u32.h
1642 --- linux-2.6.7-rc3.org/include/linux/netfilter_ipv4/ipt_u32.h  1970-01-01 01:00:00.000000000 +0100
1643 +++ linux-2.6.7-rc3/include/linux/netfilter_ipv4/ipt_u32.h      2004-06-08 10:32:32.000000000 +0200
1644 @@ -0,0 +1,40 @@
1645 +#ifndef _IPT_U32_H
1646 +#define _IPT_U32_H
1647 +#include <linux/netfilter_ipv4/ip_tables.h>
1648 +
1649 +enum ipt_u32_ops
1650 +{
1651 +       IPT_U32_AND,
1652 +       IPT_U32_LEFTSH,
1653 +       IPT_U32_RIGHTSH,
1654 +       IPT_U32_AT
1655 +};
1656 +
1657 +struct ipt_u32_location_element
1658 +{
1659 +       u_int32_t number;
1660 +       u_int8_t nextop;
1661 +};
1662 +struct ipt_u32_value_element
1663 +{
1664 +       u_int32_t min;
1665 +       u_int32_t max;
1666 +};
1667 +/* *** any way to allow for an arbitrary number of elements?
1668 +   for now I settle for a limit of 10 of each */
1669 +#define U32MAXSIZE 10
1670 +struct ipt_u32_test
1671 +{
1672 +       u_int8_t nnums;
1673 +       struct ipt_u32_location_element location[U32MAXSIZE+1];
1674 +       u_int8_t nvalues;
1675 +       struct ipt_u32_value_element value[U32MAXSIZE+1];
1676 +};
1677 +
1678 +struct ipt_u32
1679 +{
1680 +       u_int8_t ntests;
1681 +       struct ipt_u32_test tests[U32MAXSIZE+1];
1682 +};
1683 +
1684 +#endif /*_IPT_U32_H*/
1685 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/include/linux/netfilter_ipv4.h linux-2.6.7-rc3/include/linux/netfilter_ipv4.h
1686 --- linux-2.6.7-rc3.org/include/linux/netfilter_ipv4.h  2004-06-07 21:14:57.000000000 +0200
1687 +++ linux-2.6.7-rc3/include/linux/netfilter_ipv4.h      2004-06-08 10:38:44.000000000 +0200
1688 @@ -7,6 +7,8 @@
1689  
1690  #include <linux/config.h>
1691  #include <linux/netfilter.h>
1692 +#include <linux/netdevice.h>
1693 +#include <net/protocol.h>
1694  
1695  /* IP Cache bits. */
1696  /* Src IP address. */
1697 @@ -85,6 +87,58 @@
1698     Returns true or false. */
1699  extern int skb_ip_make_writable(struct sk_buff **pskb,
1700                                 unsigned int writable_len);
1701 +
1702 +#if defined(CONFIG_XFRM) && defined(CONFIG_NETFILTER)
1703 +#include <net/route.h>
1704 +#include <net/xfrm.h>
1705 +
1706 +static inline int nf_hook_input_cond(struct sk_buff *skb)
1707 +{
1708 +       return !skb->sp || skb->sp->decap_done;
1709 +}
1710 +
1711 +static inline int
1712 +nf_xfrm_local_done(struct sk_buff *skb, struct inet_protocol *ipprot)
1713 +{
1714 +       return skb->sp && !skb->sp->decap_done
1715 +              && (!ipprot || !ipprot->xfrm_prot);
1716 +}
1717 +
1718 +static inline int nf_xfrm_nonlocal_done(struct sk_buff *skb)
1719 +{
1720 +       return skb->sp && !skb->sp->decap_done
1721 +              && !(((struct rtable *)skb->dst)->rt_flags&RTCF_LOCAL);
1722 +}
1723 +
1724 +extern int nf_rcv_postxfrm_local(struct sk_buff *skb);
1725 +extern int nf_rcv_postxfrm_nonlocal(struct sk_buff *skb);
1726 +#else /* CONFIG_XFRM */
1727 +static inline int nf_hook_input_cond(struct sk_buff *skb)
1728 +{
1729 +       return 1;
1730 +}
1731 +
1732 +static inline int
1733 +nf_xfrm_local_done(struct sk_buff *skb, struct inet_protocol *ipprot)
1734 +{
1735 +       return 0;
1736 +}
1737 +
1738 +static inline int nf_xfrm_nonlocal_done(struct sk_buff *skb)
1739 +{
1740 +       return 0;
1741 +}
1742 +
1743 +static inline int nf_rcv_postxfrm_local(struct sk_buff *skb)
1744 +{
1745 +       return 0;
1746 +}
1747 +
1748 +static inline int nf_rcv_postxfrm_nonlocal(struct sk_buff *skb)
1749 +{
1750 +       return 0; 
1751 +}
1752 +#endif /* CONFIG_XFRM */
1753  #endif /*__KERNEL__*/
1754  
1755  #endif /*__LINUX_IP_NETFILTER_H*/
1756 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/include/linux/netfilter_ipv6/ip6_tables.h linux-2.6.7-rc3/include/linux/netfilter_ipv6/ip6_tables.h
1757 --- linux-2.6.7-rc3.org/include/linux/netfilter_ipv6/ip6_tables.h       2004-06-07 21:15:11.000000000 +0200
1758 +++ linux-2.6.7-rc3/include/linux/netfilter_ipv6/ip6_tables.h   2004-06-08 10:37:30.000000000 +0200
1759 @@ -142,6 +142,12 @@
1760         /* Back pointer */
1761         unsigned int comefrom;
1762  
1763 +       /* Name of the chain */
1764 +       char *chainname;
1765 +       
1766 +       /* Rule number in the chain. */
1767 +       u_int32_t rulenum;
1768 +
1769         /* Packet and byte counters. */
1770         struct ip6t_counters counters;
1771  
1772 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/include/linux/netfilter_ipv6/ip6t_HL.h linux-2.6.7-rc3/include/linux/netfilter_ipv6/ip6t_HL.h
1773 --- linux-2.6.7-rc3.org/include/linux/netfilter_ipv6/ip6t_HL.h  1970-01-01 01:00:00.000000000 +0100
1774 +++ linux-2.6.7-rc3/include/linux/netfilter_ipv6/ip6t_HL.h      2004-06-08 10:31:03.000000000 +0200
1775 @@ -0,0 +1,22 @@
1776 +/* Hop Limit modification module for ip6tables
1777 + * Maciej Soltysiak <solt@dns.toxicfilms.tv>
1778 + * Based on HW's TTL module */
1779 +
1780 +#ifndef _IP6T_HL_H
1781 +#define _IP6T_HL_H
1782 +
1783 +enum {
1784 +       IP6T_HL_SET = 0,
1785 +       IP6T_HL_INC,
1786 +       IP6T_HL_DEC
1787 +};
1788 +
1789 +#define IP6T_HL_MAXMODE        IP6T_HL_DEC
1790 +
1791 +struct ip6t_HL_info {
1792 +       u_int8_t        mode;
1793 +       u_int8_t        hop_limit;
1794 +};
1795 +
1796 +
1797 +#endif
1798 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/include/linux/netfilter_ipv6/ip6t_REJECT.h linux-2.6.7-rc3/include/linux/netfilter_ipv6/ip6t_REJECT.h
1799 --- linux-2.6.7-rc3.org/include/linux/netfilter_ipv6/ip6t_REJECT.h      2004-06-07 21:13:34.000000000 +0200
1800 +++ linux-2.6.7-rc3/include/linux/netfilter_ipv6/ip6t_REJECT.h  2004-06-08 10:31:20.000000000 +0200
1801 @@ -2,15 +2,17 @@
1802  #define _IP6T_REJECT_H
1803  
1804  enum ip6t_reject_with {
1805 -       IP6T_ICMP_NET_UNREACHABLE,
1806 -       IP6T_ICMP_HOST_UNREACHABLE,
1807 -       IP6T_ICMP_PROT_UNREACHABLE,
1808 -       IP6T_ICMP_PORT_UNREACHABLE,
1809 -       IP6T_ICMP_ECHOREPLY
1810 +       IP6T_ICMP6_NO_ROUTE,
1811 +       IP6T_ICMP6_ADM_PROHIBITED,
1812 +       IP6T_ICMP6_NOT_NEIGHBOUR,
1813 +       IP6T_ICMP6_ADDR_UNREACH,
1814 +       IP6T_ICMP6_PORT_UNREACH,
1815 +       IP6T_ICMP6_ECHOREPLY,
1816 +       IP6T_TCP_RESET
1817  };
1818  
1819  struct ip6t_reject_info {
1820         enum ip6t_reject_with with;      /* reject type */
1821  };
1822  
1823 -#endif /*_IPT_REJECT_H*/
1824 +#endif /*_IP6T_REJECT_H*/
1825 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/include/linux/netfilter_ipv6/ip6t_ROUTE.h linux-2.6.7-rc3/include/linux/netfilter_ipv6/ip6t_ROUTE.h
1826 --- linux-2.6.7-rc3.org/include/linux/netfilter_ipv6/ip6t_ROUTE.h       1970-01-01 01:00:00.000000000 +0100
1827 +++ linux-2.6.7-rc3/include/linux/netfilter_ipv6/ip6t_ROUTE.h   2004-06-08 10:37:08.000000000 +0200
1828 @@ -0,0 +1,22 @@
1829 +/* Header file for iptables ip6t_ROUTE target
1830 + *
1831 + * (C) 2003 by Cédric de Launois <delaunois@info.ucl.ac.be>
1832 + *
1833 + * This software is distributed under GNU GPL v2, 1991
1834 + */
1835 +#ifndef _IPT_ROUTE_H_target
1836 +#define _IPT_ROUTE_H_target
1837 +
1838 +#define IP6T_ROUTE_IFNAMSIZ 16
1839 +
1840 +struct ip6t_route_target_info {
1841 +       char      oif[IP6T_ROUTE_IFNAMSIZ];     /* Output Interface Name */
1842 +       char      iif[IP6T_ROUTE_IFNAMSIZ];     /* Input Interface Name  */
1843 +       u_int32_t gw[4];                        /* IPv6 address of gateway */
1844 +       u_int8_t  flags;
1845 +};
1846 +
1847 +/* Values for "flags" field */
1848 +#define IP6T_ROUTE_CONTINUE        0x01
1849 +
1850 +#endif /*_IP6T_ROUTE_H_target*/
1851 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/include/linux/netfilter_ipv6/ip6t_fuzzy.h linux-2.6.7-rc3/include/linux/netfilter_ipv6/ip6t_fuzzy.h
1852 --- linux-2.6.7-rc3.org/include/linux/netfilter_ipv6/ip6t_fuzzy.h       1970-01-01 01:00:00.000000000 +0100
1853 +++ linux-2.6.7-rc3/include/linux/netfilter_ipv6/ip6t_fuzzy.h   2004-06-08 10:31:37.000000000 +0200
1854 @@ -0,0 +1,21 @@
1855 +#ifndef _IP6T_FUZZY_H
1856 +#define _IP6T_FUZZY_H
1857 +
1858 +#include <linux/param.h>
1859 +#include <linux/types.h>
1860 +
1861 +#define MAXFUZZYRATE 10000000
1862 +#define MINFUZZYRATE 3
1863 +
1864 +struct ip6t_fuzzy_info {
1865 +       u_int32_t minimum_rate;
1866 +       u_int32_t maximum_rate;
1867 +       u_int32_t packets_total;
1868 +       u_int32_t bytes_total;
1869 +       u_int32_t previous_time;
1870 +       u_int32_t present_time;
1871 +       u_int32_t mean_rate;
1872 +       u_int8_t acceptance_rate;
1873 +};
1874 +
1875 +#endif /*_IP6T_FUZZY_H*/
1876 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/include/linux/netfilter_ipv6/ip6t_nth.h linux-2.6.7-rc3/include/linux/netfilter_ipv6/ip6t_nth.h
1877 --- linux-2.6.7-rc3.org/include/linux/netfilter_ipv6/ip6t_nth.h 1970-01-01 01:00:00.000000000 +0100
1878 +++ linux-2.6.7-rc3/include/linux/netfilter_ipv6/ip6t_nth.h     2004-06-08 10:31:42.000000000 +0200
1879 @@ -0,0 +1,19 @@
1880 +#ifndef _IP6T_NTH_H
1881 +#define _IP6T_NTH_H
1882 +
1883 +#include <linux/param.h>
1884 +#include <linux/types.h>
1885 +
1886 +#ifndef IP6T_NTH_NUM_COUNTERS
1887 +#define IP6T_NTH_NUM_COUNTERS 16
1888 +#endif
1889 +
1890 +struct ip6t_nth_info {
1891 +       u_int8_t every;
1892 +       u_int8_t not;
1893 +       u_int8_t startat;
1894 +       u_int8_t counter;
1895 +       u_int8_t packet;
1896 +};
1897 +
1898 +#endif /*_IP6T_NTH_H*/
1899 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/include/linux/netfilter_ipv6/ip6t_owner.h linux-2.6.7-rc3/include/linux/netfilter_ipv6/ip6t_owner.h
1900 --- linux-2.6.7-rc3.org/include/linux/netfilter_ipv6/ip6t_owner.h       2004-06-07 21:14:41.000000000 +0200
1901 +++ linux-2.6.7-rc3/include/linux/netfilter_ipv6/ip6t_owner.h   2004-06-08 10:40:01.000000000 +0200
1902 @@ -6,12 +6,14 @@
1903  #define IP6T_OWNER_GID 0x02
1904  #define IP6T_OWNER_PID 0x04
1905  #define IP6T_OWNER_SID 0x08
1906 +#define IP6T_OWNER_COMM 0x10
1907  
1908  struct ip6t_owner_info {
1909      uid_t uid;
1910      gid_t gid;
1911      pid_t pid;
1912      pid_t sid;
1913 +    char comm[16];
1914      u_int8_t match, invert;    /* flags */
1915  };
1916  
1917 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/include/linux/netfilter_ipv6/ip6t_policy.h linux-2.6.7-rc3/include/linux/netfilter_ipv6/ip6t_policy.h
1918 --- linux-2.6.7-rc3.org/include/linux/netfilter_ipv6/ip6t_policy.h      1970-01-01 01:00:00.000000000 +0100
1919 +++ linux-2.6.7-rc3/include/linux/netfilter_ipv6/ip6t_policy.h  2004-06-08 10:42:36.000000000 +0200
1920 @@ -0,0 +1,52 @@
1921 +#ifndef _IP6T_POLICY_H
1922 +#define _IP6T_POLICY_H
1923 +
1924 +#define POLICY_MAX_ELEM        4
1925 +
1926 +enum ip6t_policy_flags
1927 +{
1928 +       POLICY_MATCH_IN         = 0x1,
1929 +       POLICY_MATCH_OUT        = 0x2,
1930 +       POLICY_MATCH_NONE       = 0x4,
1931 +       POLICY_MATCH_STRICT     = 0x8,
1932 +};
1933 +
1934 +enum ip6t_policy_modes
1935 +{
1936 +       POLICY_MODE_TRANSPORT,
1937 +       POLICY_MODE_TUNNEL
1938 +};
1939 +
1940 +struct ip6t_policy_spec
1941 +{
1942 +       u_int8_t        saddr:1,
1943 +                       daddr:1,
1944 +                       proto:1,
1945 +                       mode:1,
1946 +                       spi:1,
1947 +                       reqid:1;
1948 +};
1949 +
1950 +struct ip6t_policy_elem
1951 +{
1952 +       struct in6_addr saddr;
1953 +       struct in6_addr smask;
1954 +       struct in6_addr daddr;
1955 +       struct in6_addr dmask;
1956 +       u_int32_t       spi;
1957 +       u_int32_t       reqid;
1958 +       u_int8_t        proto;
1959 +       u_int8_t        mode;
1960 +
1961 +       struct ip6t_policy_spec match;
1962 +       struct ip6t_policy_spec invert;
1963 +};
1964 +
1965 +struct ip6t_policy_info
1966 +{
1967 +       struct ip6t_policy_elem pol[POLICY_MAX_ELEM];
1968 +       u_int16_t flags;
1969 +       u_int16_t len;
1970 +};
1971 +
1972 +#endif /* _IP6T_POLICY_H */
1973 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/include/linux/netfilter_ipv6/ip6t_random.h linux-2.6.7-rc3/include/linux/netfilter_ipv6/ip6t_random.h
1974 --- linux-2.6.7-rc3.org/include/linux/netfilter_ipv6/ip6t_random.h      1970-01-01 01:00:00.000000000 +0100
1975 +++ linux-2.6.7-rc3/include/linux/netfilter_ipv6/ip6t_random.h  2004-06-08 10:31:56.000000000 +0200
1976 @@ -0,0 +1,11 @@
1977 +#ifndef _IP6T_RAND_H
1978 +#define _IP6T_RAND_H
1979 +
1980 +#include <linux/param.h>
1981 +#include <linux/types.h>
1982 +
1983 +struct ip6t_rand_info {
1984 +       u_int8_t average;
1985 +};
1986 +
1987 +#endif /*_IP6T_RAND_H*/
1988 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/include/linux/netfilter_mime.h linux-2.6.7-rc3/include/linux/netfilter_mime.h
1989 --- linux-2.6.7-rc3.org/include/linux/netfilter_mime.h  1970-01-01 01:00:00.000000000 +0100
1990 +++ linux-2.6.7-rc3/include/linux/netfilter_mime.h      2004-06-08 10:40:46.000000000 +0200
1991 @@ -0,0 +1,89 @@
1992 +/*
1993 + * MIME functions for netfilter modules.  This file provides implementations
1994 + * for basic MIME parsing.  MIME headers are used in many protocols, such as
1995 + * HTTP, RTSP, SIP, etc.
1996 + *
1997 + * gcc will warn for defined but unused functions, so we only include the
1998 + * functions requested.  The following macros are used:
1999 + *   NF_NEED_MIME_NEXTLINE      nf_mime_nextline()
2000 + */
2001 +#ifndef _NETFILTER_MIME_H
2002 +#define _NETFILTER_MIME_H
2003 +
2004 +/* Only include these functions for kernel code. */
2005 +#ifdef __KERNEL__
2006 +
2007 +#include <linux/ctype.h>
2008 +
2009 +/*
2010 + * Given a buffer and length, advance to the next line and mark the current
2011 + * line.  If the current line is empty, *plinelen will be set to zero.  If
2012 + * not, it will be set to the actual line length (including CRLF).
2013 + *
2014 + * 'line' in this context means logical line (includes LWS continuations).
2015 + * Returns 1 on success, 0 on failure.
2016 + */
2017 +#ifdef NF_NEED_MIME_NEXTLINE
2018 +static int
2019 +nf_mime_nextline(char* p, uint len, uint* poff, uint* plineoff, uint* plinelen)
2020 +{
2021 +    uint    off = *poff;
2022 +    uint    physlen = 0;
2023 +    int     is_first_line = 1;
2024 +
2025 +    if (off >= len)
2026 +    {
2027 +        return 0;
2028 +    }
2029 +
2030 +    do
2031 +    {
2032 +        while (p[off] != '\n')
2033 +        {
2034 +            if (len-off <= 1)
2035 +            {
2036 +                return 0;
2037 +            }
2038 +
2039 +            physlen++;
2040 +            off++;
2041 +        }
2042 +
2043 +        /* if we saw a crlf, physlen needs adjusted */
2044 +        if (physlen > 0 && p[off] == '\n' && p[off-1] == '\r')
2045 +        {
2046 +            physlen--;
2047 +        }
2048 +
2049 +        /* advance past the newline */
2050 +        off++;
2051 +
2052 +        /* check for an empty line */
2053 +        if (physlen == 0)
2054 +        {
2055 +            break;
2056 +        }
2057 +
2058 +        /* check for colon on the first physical line */
2059 +        if (is_first_line)
2060 +        {
2061 +            is_first_line = 0;
2062 +            if (memchr(p+(*poff), ':', physlen) == NULL)
2063 +            {
2064 +                return 0;
2065 +            }
2066 +        }
2067 +    }
2068 +    while (p[off] == ' ' || p[off] == '\t');
2069 +
2070 +    *plineoff = *poff;
2071 +    *plinelen = (physlen == 0) ? 0 : (off - *poff);
2072 +    *poff = off;
2073 +
2074 +    return 1;
2075 +}
2076 +#endif /* NF_NEED_MIME_NEXTLINE */
2077 +
2078 +#endif /* __KERNEL__ */
2079 +
2080 +#endif /* _NETFILTER_MIME_H */
2081 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/include/linux/skbuff.h linux-2.6.7-rc3/include/linux/skbuff.h
2082 --- linux-2.6.7-rc3.org/include/linux/skbuff.h  2004-06-07 21:14:33.000000000 +0200
2083 +++ linux-2.6.7-rc3/include/linux/skbuff.h      2004-06-08 10:30:55.000000000 +0200
2084 @@ -1049,6 +1049,14 @@
2085         if (nfct)
2086                 atomic_inc(&nfct->master->use);
2087  }
2088 +static inline void nf_reset(struct sk_buff *skb)
2089 +{
2090 +       nf_conntrack_put(skb->nfct);
2091 +       skb->nfct = NULL;
2092 +#ifdef CONFIG_NETFILTER_DEBUG
2093 +       skb->nf_debug = 0;
2094 +#endif
2095 +}
2096  
2097  #ifdef CONFIG_BRIDGE_NETFILTER
2098  static inline void nf_bridge_put(struct nf_bridge_info *nf_bridge)
2099 @@ -1061,9 +1069,10 @@
2100         if (nf_bridge)
2101                 atomic_inc(&nf_bridge->use);
2102  }
2103 -#endif
2104 -
2105 -#endif
2106 +#endif /* CONFIG_BRIDGE_NETFILTER */
2107 +#else /* CONFIG_NETFILTER */
2108 +static inline void nf_reset(struct sk_buff *skb) {}
2109 +#endif /* CONFIG_NETFILTER */
2110  
2111  #endif /* __KERNEL__ */
2112  #endif /* _LINUX_SKBUFF_H */
2113 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/include/net/ip.h linux-2.6.7-rc3/include/net/ip.h
2114 --- linux-2.6.7-rc3.org/include/net/ip.h        2004-06-07 21:14:42.000000000 +0200
2115 +++ linux-2.6.7-rc3/include/net/ip.h    2004-06-08 10:38:43.000000000 +0200
2116 @@ -30,6 +30,8 @@
2117  #include <linux/netdevice.h>
2118  #include <linux/inetdevice.h>
2119  #include <linux/in_route.h>
2120 +#include <linux/netfilter.h>
2121 +#include <linux/netfilter_ipv4.h>
2122  #include <net/route.h>
2123  #include <net/arp.h>
2124  
2125 @@ -48,6 +50,7 @@
2126  #define IPSKB_TRANSLATED       2
2127  #define IPSKB_FORWARDED                4
2128  #define IPSKB_XFRM_TUNNEL_SIZE 8
2129 +#define IPSKB_XFRM_TRANSFORMED 16
2130  };
2131  
2132  struct ipcm_cookie
2133 @@ -212,6 +215,12 @@
2134                 __ip_select_ident(iph, dst, more);
2135  }
2136  
2137 +extern inline int ip_dst_output(struct sk_buff *skb)
2138 +{
2139 +       return NF_HOOK_COND(PF_INET, NF_IP_POST_ROUTING, skb, NULL,
2140 +                           skb->dst->dev, dst_output, skb->dst->xfrm != NULL);
2141 +}
2142 +
2143  /*
2144   *     Map a multicast IP onto multicast MAC for type ethernet.
2145   */
2146 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/include/net/protocol.h linux-2.6.7-rc3/include/net/protocol.h
2147 --- linux-2.6.7-rc3.org/include/net/protocol.h  2004-06-07 21:14:10.000000000 +0200
2148 +++ linux-2.6.7-rc3/include/net/protocol.h      2004-06-08 10:38:44.000000000 +0200
2149 @@ -39,6 +39,7 @@
2150         int                     (*handler)(struct sk_buff *skb);
2151         void                    (*err_handler)(struct sk_buff *skb, u32 info);
2152         int                     no_policy;
2153 +       int                     xfrm_prot;
2154  };
2155  
2156  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
2157 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/include/net/tcp.h linux-2.6.7-rc3/include/net/tcp.h
2158 --- linux-2.6.7-rc3.org/include/net/tcp.h       2004-06-07 21:13:39.000000000 +0200
2159 +++ linux-2.6.7-rc3/include/net/tcp.h   2004-06-08 10:39:56.000000000 +0200
2160 @@ -162,6 +162,7 @@
2161  extern void tcp_bucket_unlock(struct sock *sk);
2162  extern int tcp_port_rover;
2163  extern struct sock *tcp_v4_lookup_listener(u32 addr, unsigned short hnum, int dif);
2164 +extern struct sock *tcp_v4_lookup(u32 saddr, u16 sport, u32 daddr, u16 hnum, int dif);
2165  
2166  /* These are AF independent. */
2167  static __inline__ int tcp_bhashfn(__u16 lport)
2168 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/include/net/udp.h linux-2.6.7-rc3/include/net/udp.h
2169 --- linux-2.6.7-rc3.org/include/net/udp.h       2004-06-07 21:14:56.000000000 +0200
2170 +++ linux-2.6.7-rc3/include/net/udp.h   2004-06-08 10:39:56.000000000 +0200
2171 @@ -74,6 +74,8 @@
2172  extern int     udp_ioctl(struct sock *sk, int cmd, unsigned long arg);
2173  extern int     udp_disconnect(struct sock *sk, int flags);
2174  
2175 +extern struct sock *udp_v4_lookup(u32 saddr, u16 sport, u32 daddr, u16 dport, int dif);
2176 +
2177  DECLARE_SNMP_STAT(struct udp_mib, udp_statistics);
2178  #define UDP_INC_STATS(field)           SNMP_INC_STATS(udp_statistics, field)
2179  #define UDP_INC_STATS_BH(field)                SNMP_INC_STATS_BH(udp_statistics, field)
2180 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/include/net/xfrm.h linux-2.6.7-rc3/include/net/xfrm.h
2181 --- linux-2.6.7-rc3.org/include/net/xfrm.h      2004-06-07 21:14:56.000000000 +0200
2182 +++ linux-2.6.7-rc3/include/net/xfrm.h  2004-06-08 10:38:44.000000000 +0200
2183 @@ -540,6 +540,9 @@
2184  {
2185         atomic_t                refcnt;
2186         int                     len;
2187 +#ifdef CONFIG_NETFILTER
2188 +       int                     decap_done;
2189 +#endif
2190         struct sec_decap_state  x[XFRM_MAX_DEPTH];
2191  };
2192  
2193 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/core/netfilter.c linux-2.6.7-rc3/net/core/netfilter.c
2194 --- linux-2.6.7-rc3.org/net/core/netfilter.c    2004-06-07 21:14:11.000000000 +0200
2195 +++ linux-2.6.7-rc3/net/core/netfilter.c        2004-06-08 10:38:46.000000000 +0200
2196 @@ -27,6 +27,8 @@
2197  #include <linux/icmp.h>
2198  #include <net/sock.h>
2199  #include <net/route.h>
2200 +#include <net/xfrm.h>
2201 +#include <net/ip.h>
2202  #include <linux/ip.h>
2203  
2204  /* In this code, we can be waiting indefinitely for userspace to
2205 @@ -630,7 +632,6 @@
2206  #ifdef CONFIG_IP_ROUTE_FWMARK
2207                 fl.nl_u.ip4_u.fwmark = (*pskb)->nfmark;
2208  #endif
2209 -               fl.proto = iph->protocol;
2210                 if (ip_route_output_key(&rt, &fl) != 0)
2211                         return -1;
2212  
2213 @@ -657,6 +658,20 @@
2214         if ((*pskb)->dst->error)
2215                 return -1;
2216  
2217 +#ifdef CONFIG_XFRM
2218 +       if (!(IPCB(*pskb)->flags & IPSKB_XFRM_TRANSFORMED)) {
2219 +               struct xfrm_policy_afinfo *afinfo;
2220 +
2221 +               afinfo = xfrm_policy_get_afinfo(AF_INET);
2222 +               if (afinfo != NULL) {
2223 +                       afinfo->decode_session(*pskb, &fl);
2224 +                       xfrm_policy_put_afinfo(afinfo);
2225 +                       if (xfrm_lookup(&(*pskb)->dst, &fl, (*pskb)->sk, 0) != 0)
2226 +                               return -1;
2227 +               }
2228 +       }
2229 +#endif
2230 +
2231         /* Change in oif may mean change in hh_len. */
2232         hh_len = (*pskb)->dst->dev->hard_header_len;
2233         if (skb_headroom(*pskb) < hh_len) {
2234 @@ -674,6 +689,71 @@
2235         return 0;
2236  }
2237  
2238 +#ifdef CONFIG_XFRM
2239 +inline int nf_rcv_postxfrm_nonlocal(struct sk_buff *skb)
2240 +{
2241 +       skb->sp->decap_done = 1;
2242 +       dst_release(skb->dst);
2243 +       skb->dst = NULL;
2244 +       nf_reset(skb);
2245 +       return netif_rx(skb);
2246 +}
2247 +
2248 +int nf_rcv_postxfrm_local(struct sk_buff *skb)
2249 +{
2250 +       __skb_push(skb, skb->data - skb->nh.raw);
2251 +       /* Fix header len and checksum if last xfrm was transport mode */
2252 +       if (!skb->sp->x[skb->sp->len - 1].xvec->props.mode) {
2253 +               skb->nh.iph->tot_len = htons(skb->len);
2254 +               ip_send_check(skb->nh.iph);
2255 +       }
2256 +       return nf_rcv_postxfrm_nonlocal(skb);
2257 +}
2258 +
2259 +#ifdef CONFIG_IP_NF_NAT_NEEDED
2260 +#include <linux/netfilter_ipv4/ip_conntrack.h>
2261 +#include <linux/netfilter_ipv4/ip_nat.h>
2262 +
2263 +void nf_nat_decode_session4(struct sk_buff *skb, struct flowi *fl)
2264 +{
2265 +       struct ip_conntrack *ct;
2266 +       struct ip_conntrack_tuple *t;
2267 +       struct ip_nat_info_manip *m;
2268 +       unsigned int i;
2269 +
2270 +       if (skb->nfct == NULL)
2271 +               return;
2272 +       ct = (struct ip_conntrack *)skb->nfct->master;
2273 +
2274 +       for (i = 0; i < ct->nat.info.num_manips; i++) {
2275 +               m = &ct->nat.info.manips[i];
2276 +               t = &ct->tuplehash[m->direction].tuple;
2277 +
2278 +               switch (m->hooknum) {
2279 +               case NF_IP_PRE_ROUTING:
2280 +                       if (m->maniptype != IP_NAT_MANIP_DST)
2281 +                               break;
2282 +                       fl->fl4_dst = t->dst.ip;
2283 +                       if (t->dst.protonum == IPPROTO_TCP ||
2284 +                           t->dst.protonum == IPPROTO_UDP)
2285 +                               fl->fl_ip_dport = t->dst.u.tcp.port;
2286 +                       break;
2287 +#ifdef CONFIG_IP_NF_NAT_LOCAL
2288 +               case NF_IP_LOCAL_IN:
2289 +                       if (m->maniptype != IP_NAT_MANIP_SRC)
2290 +                               break;
2291 +                       fl->fl4_src = t->src.ip;
2292 +                       if (t->dst.protonum == IPPROTO_TCP ||
2293 +                           t->dst.protonum == IPPROTO_UDP)
2294 +                               fl->fl_ip_sport = t->src.u.tcp.port;
2295 +                       break;
2296 +#endif
2297 +               }
2298 +       }
2299 +}
2300 +#endif /* CONFIG_IP_NF_NAT_NEEDED */
2301 +#endif
2302 +
2303  int skb_ip_make_writable(struct sk_buff **pskb, unsigned int writable_len)
2304  {
2305         struct sk_buff *nskb;
2306 @@ -831,3 +911,4 @@
2307  EXPORT_SYMBOL(nf_unregister_hook);
2308  EXPORT_SYMBOL(nf_unregister_queue_handler);
2309  EXPORT_SYMBOL(nf_unregister_sockopt);
2310 +EXPORT_SYMBOL(nf_rcv_postxfrm_local);
2311 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/ah4.c linux-2.6.7-rc3/net/ipv4/ah4.c
2312 --- linux-2.6.7-rc3.org/net/ipv4/ah4.c  2004-06-07 21:14:58.000000000 +0200
2313 +++ linux-2.6.7-rc3/net/ipv4/ah4.c      2004-06-08 10:38:44.000000000 +0200
2314 @@ -146,6 +146,7 @@
2315                 err = -EHOSTUNREACH;
2316                 goto error_nolock;
2317         }
2318 +       IPCB(*pskb)->flags |= IPSKB_XFRM_TRANSFORMED;
2319         return NET_XMIT_BYPASS;
2320  
2321  error:
2322 @@ -344,6 +345,7 @@
2323         .handler        =       xfrm4_rcv,
2324         .err_handler    =       ah4_err,
2325         .no_policy      =       1,
2326 +       .xfrm_prot      =       1,
2327  };
2328  
2329  static int __init ah4_init(void)
2330 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/esp4.c linux-2.6.7-rc3/net/ipv4/esp4.c
2331 --- linux-2.6.7-rc3.org/net/ipv4/esp4.c 2004-06-07 21:14:33.000000000 +0200
2332 +++ linux-2.6.7-rc3/net/ipv4/esp4.c     2004-06-08 10:38:44.000000000 +0200
2333 @@ -216,6 +216,7 @@
2334                 err = -EHOSTUNREACH;
2335                 goto error_nolock;
2336         }
2337 +       IPCB(*pskb)->flags |= IPSKB_XFRM_TRANSFORMED;
2338         return NET_XMIT_BYPASS;
2339  
2340  error:
2341 @@ -598,6 +599,7 @@
2342         .handler        =       xfrm4_rcv,
2343         .err_handler    =       esp4_err,
2344         .no_policy      =       1,
2345 +       .xfrm_prot      =       1,
2346  };
2347  
2348  static int __init esp4_init(void)
2349 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/igmp.c linux-2.6.7-rc3/net/ipv4/igmp.c
2350 --- linux-2.6.7-rc3.org/net/ipv4/igmp.c 2004-06-07 21:15:12.000000000 +0200
2351 +++ linux-2.6.7-rc3/net/ipv4/igmp.c     2004-06-08 10:38:43.000000000 +0200
2352 @@ -343,7 +343,7 @@
2353         pig->csum = ip_compute_csum((void *)skb->h.igmph, igmplen);
2354  
2355         return NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, skb, NULL, skb->dev,
2356 -                      dst_output);
2357 +                      ip_dst_output);
2358  }
2359  
2360  static int grec_size(struct ip_mc_list *pmc, int type, int gdel, int sdel)
2361 @@ -673,7 +673,7 @@
2362         ih->csum=ip_compute_csum((void *)ih, sizeof(struct igmphdr));
2363  
2364         return NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, skb, NULL, rt->u.dst.dev,
2365 -                      dst_output);
2366 +                      ip_dst_output);
2367  }
2368  
2369  static void igmp_gq_timer_expire(unsigned long data)
2370 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/ip_forward.c linux-2.6.7-rc3/net/ipv4/ip_forward.c
2371 --- linux-2.6.7-rc3.org/net/ipv4/ip_forward.c   2004-06-07 21:13:35.000000000 +0200
2372 +++ linux-2.6.7-rc3/net/ipv4/ip_forward.c       2004-06-08 10:38:43.000000000 +0200
2373 @@ -51,7 +51,7 @@
2374         if (unlikely(opt->optlen))
2375                 ip_forward_options(skb);
2376  
2377 -       return dst_output(skb);
2378 +       return ip_dst_output(skb);
2379  }
2380  
2381  int ip_forward(struct sk_buff *skb)
2382 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/ip_gre.c linux-2.6.7-rc3/net/ipv4/ip_gre.c
2383 --- linux-2.6.7-rc3.org/net/ipv4/ip_gre.c       2004-06-07 21:14:55.000000000 +0200
2384 +++ linux-2.6.7-rc3/net/ipv4/ip_gre.c   2004-06-08 10:30:55.000000000 +0200
2385 @@ -643,13 +643,7 @@
2386                 skb->dev = tunnel->dev;
2387                 dst_release(skb->dst);
2388                 skb->dst = NULL;
2389 -#ifdef CONFIG_NETFILTER
2390 -               nf_conntrack_put(skb->nfct);
2391 -               skb->nfct = NULL;
2392 -#ifdef CONFIG_NETFILTER_DEBUG
2393 -               skb->nf_debug = 0;
2394 -#endif
2395 -#endif
2396 +               nf_reset(skb);
2397                 ipgre_ecn_decapsulate(iph, skb);
2398                 netif_rx(skb);
2399                 read_unlock(&ipgre_lock);
2400 @@ -877,13 +871,7 @@
2401                 }
2402         }
2403  
2404 -#ifdef CONFIG_NETFILTER
2405 -       nf_conntrack_put(skb->nfct);
2406 -       skb->nfct = NULL;
2407 -#ifdef CONFIG_NETFILTER_DEBUG
2408 -       skb->nf_debug = 0;
2409 -#endif
2410 -#endif
2411 +       nf_reset(skb);
2412  
2413         IPTUNNEL_XMIT();
2414         tunnel->recursion--;
2415 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/ip_input.c linux-2.6.7-rc3/net/ipv4/ip_input.c
2416 --- linux-2.6.7-rc3.org/net/ipv4/ip_input.c     2004-06-07 21:13:37.000000000 +0200
2417 +++ linux-2.6.7-rc3/net/ipv4/ip_input.c 2004-06-08 10:38:46.000000000 +0200
2418 @@ -202,18 +202,10 @@
2419  
2420  #ifdef CONFIG_NETFILTER_DEBUG
2421         nf_debug_ip_local_deliver(skb);
2422 -       skb->nf_debug = 0;
2423  #endif /*CONFIG_NETFILTER_DEBUG*/
2424  
2425         __skb_pull(skb, ihl);
2426  
2427 -#ifdef CONFIG_NETFILTER
2428 -       /* Free reference early: we don't need it any more, and it may
2429 -           hold ip_conntrack module loaded indefinitely. */
2430 -       nf_conntrack_put(skb->nfct);
2431 -       skb->nfct = NULL;
2432 -#endif /*CONFIG_NETFILTER*/
2433 -
2434          /* Point into the IP datagram, just past the header. */
2435          skb->h.raw = skb->data;
2436  
2437 @@ -228,6 +220,13 @@
2438         resubmit:
2439                 hash = protocol & (MAX_INET_PROTOS - 1);
2440                 raw_sk = sk_head(&raw_v4_htable[hash]);
2441 +               ipprot = inet_protos[hash];
2442 +               smp_read_barrier_depends();
2443 +
2444 +               if (nf_xfrm_local_done(skb, ipprot)) {
2445 +                       nf_rcv_postxfrm_local(skb);
2446 +                       goto out;
2447 +               }
2448  
2449                 /* If there maybe a raw socket we must check - if not we
2450                  * don't care less
2451 @@ -235,14 +234,15 @@
2452                 if (raw_sk)
2453                         raw_v4_input(skb, skb->nh.iph, hash);
2454  
2455 -               if ((ipprot = inet_protos[hash]) != NULL) {
2456 +               if (ipprot != NULL) {
2457                         int ret;
2458  
2459 -                       smp_read_barrier_depends();
2460 -                       if (!ipprot->no_policy &&
2461 -                           !xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb)) {
2462 -                               kfree_skb(skb);
2463 -                               goto out;
2464 +                       if (!ipprot->no_policy) {
2465 +                               if (!xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb)) {
2466 +                                       kfree_skb(skb);
2467 +                                       goto out;
2468 +                               }
2469 +                               nf_reset(skb);
2470                         }
2471                         ret = ipprot->handler(skb);
2472                         if (ret < 0) {
2473 @@ -283,8 +283,8 @@
2474                         return 0;
2475         }
2476  
2477 -       return NF_HOOK(PF_INET, NF_IP_LOCAL_IN, skb, skb->dev, NULL,
2478 -                      ip_local_deliver_finish);
2479 +       return NF_HOOK_COND(PF_INET, NF_IP_LOCAL_IN, skb, skb->dev, NULL,
2480 +                           ip_local_deliver_finish, nf_hook_input_cond(skb));
2481  }
2482  
2483  static inline int ip_rcv_finish(struct sk_buff *skb)
2484 @@ -301,6 +301,9 @@
2485                         goto drop; 
2486         }
2487  
2488 +       if (nf_xfrm_nonlocal_done(skb))
2489 +               return nf_rcv_postxfrm_nonlocal(skb);
2490 +
2491  #ifdef CONFIG_NET_CLS_ROUTE
2492         if (skb->dst->tclassid) {
2493                 struct ip_rt_acct *st = ip_rt_acct + 256*smp_processor_id();
2494 @@ -422,8 +425,8 @@
2495                 }
2496         }
2497  
2498 -       return NF_HOOK(PF_INET, NF_IP_PRE_ROUTING, skb, dev, NULL,
2499 -                      ip_rcv_finish);
2500 +       return NF_HOOK_COND(PF_INET, NF_IP_PRE_ROUTING, skb, dev, NULL,
2501 +                           ip_rcv_finish, nf_hook_input_cond(skb));
2502  
2503  inhdr_error:
2504         IP_INC_STATS_BH(InHdrErrors);
2505 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/ip_output.c linux-2.6.7-rc3/net/ipv4/ip_output.c
2506 --- linux-2.6.7-rc3.org/net/ipv4/ip_output.c    2004-06-07 21:15:12.000000000 +0200
2507 +++ linux-2.6.7-rc3/net/ipv4/ip_output.c        2004-06-08 10:38:43.000000000 +0200
2508 @@ -123,6 +124,15 @@
2509         return ttl;
2510  }
2511  
2512 +#ifdef CONFIG_NETFILTER
2513 +/* out-of-line copy is only required with netfilter */
2514 +int ip_dst_output(struct sk_buff *skb)
2515 +{
2516 +       return NF_HOOK_COND(PF_INET, NF_IP_POST_ROUTING, skb, NULL,
2517 +                           skb->dst->dev, dst_output, skb->dst->xfrm != NULL);
2518 +}
2519 +#endif
2520 +
2521  /* 
2522   *             Add an ip header to a skbuff and send it out.
2523   *
2524 @@ -165,7 +175,7 @@
2525  
2526         /* Send it out. */
2527         return NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, skb, NULL, rt->u.dst.dev,
2528 -                      dst_output);
2529 +                      ip_dst_output);
2530  }
2531  
2532  static inline int ip_finish_output2(struct sk_buff *skb)
2533 @@ -284,10 +294,8 @@
2534                 return ip_finish_output(skb);
2535  }
2536  
2537 -int ip_output(struct sk_buff **pskb)
2538 +static inline int ip_output2(struct sk_buff *skb)
2539  {
2540 -       struct sk_buff *skb = *pskb;
2541 -
2542         IP_INC_STATS(OutRequests);
2543  
2544         if ((skb->len > dst_pmtu(skb->dst) || skb_shinfo(skb)->frag_list) &&
2545 @@ -297,6 +305,18 @@
2546                 return ip_finish_output(skb);
2547  }
2548  
2549 +int ip_output(struct sk_buff **pskb)
2550 +{
2551 +       struct sk_buff *skb = *pskb;
2552 +
2553 +       int transformed = IPCB(skb)->flags & IPSKB_XFRM_TRANSFORMED;
2554 +
2555 +       if (transformed)
2556 +               nf_reset(skb);
2557 +       return NF_HOOK_COND(PF_INET, NF_IP_LOCAL_OUT, skb, NULL,
2558 +                           skb->dst->dev, ip_output2, transformed);
2559 +}
2560 +
2561  int ip_queue_xmit(struct sk_buff *skb, int ipfragok)
2562  {
2563         struct sock *sk = skb->sk;
2564 @@ -390,7 +410,7 @@
2565         skb->priority = sk->sk_priority;
2566  
2567         return NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, skb, NULL, rt->u.dst.dev,
2568 -                      dst_output);
2569 +                      ip_dst_output);
2570  
2571  no_route:
2572         IP_INC_STATS(OutNoRoutes);
2573 @@ -1180,7 +1206,7 @@
2574  
2575         /* Netfilter gets whole the not fragmented skb. */
2576         err = NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, skb, NULL, 
2577 -                     skb->dst->dev, dst_output);
2578 +                     skb->dst->dev, ip_dst_output);
2579         if (err) {
2580                 if (err > 0)
2581                         err = inet->recverr ? net_xmit_errno(err) : 0;
2582 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/ipcomp.c linux-2.6.7-rc3/net/ipv4/ipcomp.c
2583 --- linux-2.6.7-rc3.org/net/ipv4/ipcomp.c       2004-06-07 21:14:58.000000000 +0200
2584 +++ linux-2.6.7-rc3/net/ipv4/ipcomp.c   2004-06-08 10:38:44.000000000 +0200
2585 @@ -232,6 +232,7 @@
2586                 err = -EHOSTUNREACH;
2587                 goto error_nolock;
2588         }
2589 +       IPCB(*pskb)->flags |= IPSKB_XFRM_TRANSFORMED;
2590         err = NET_XMIT_BYPASS;
2591  
2592  out_exit:
2593 @@ -409,6 +410,7 @@
2594         .handler        =       xfrm4_rcv,
2595         .err_handler    =       ipcomp4_err,
2596         .no_policy      =       1,
2597 +       .xfrm_prot      =       1,
2598  };
2599  
2600  static int __init ipcomp4_init(void)
2601 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/ipip.c linux-2.6.7-rc3/net/ipv4/ipip.c
2602 --- linux-2.6.7-rc3.org/net/ipv4/ipip.c 2004-06-07 21:15:21.000000000 +0200
2603 +++ linux-2.6.7-rc3/net/ipv4/ipip.c     2004-06-08 10:38:44.000000000 +0200
2604 @@ -478,6 +478,11 @@
2605  
2606         read_lock(&ipip_lock);
2607         if ((tunnel = ipip_tunnel_lookup(iph->saddr, iph->daddr)) != NULL) {
2608 +               /* IPIP packets decapsulated by IPsec missed netfilter hooks */
2609 +               if (nf_xfrm_local_done(skb, NULL)) {
2610 +                       nf_rcv_postxfrm_local(skb);
2611 +                       return 0;
2612 +               }
2613                 if (!xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb)) {
2614                         read_unlock(&ipip_lock);
2615                         kfree_skb(skb);
2616 @@ -497,13 +502,7 @@
2617                 skb->dev = tunnel->dev;
2618                 dst_release(skb->dst);
2619                 skb->dst = NULL;
2620 -#ifdef CONFIG_NETFILTER
2621 -               nf_conntrack_put(skb->nfct);
2622 -               skb->nfct = NULL;
2623 -#ifdef CONFIG_NETFILTER_DEBUG
2624 -               skb->nf_debug = 0;
2625 -#endif
2626 -#endif
2627 +               nf_reset(skb);
2628                 ipip_ecn_decapsulate(iph, skb);
2629                 netif_rx(skb);
2630                 read_unlock(&ipip_lock);
2631 @@ -648,13 +647,7 @@
2632         if ((iph->ttl = tiph->ttl) == 0)
2633                 iph->ttl        =       old_iph->ttl;
2634  
2635 -#ifdef CONFIG_NETFILTER
2636 -       nf_conntrack_put(skb->nfct);
2637 -       skb->nfct = NULL;
2638 -#ifdef CONFIG_NETFILTER_DEBUG
2639 -       skb->nf_debug = 0;
2640 -#endif
2641 -#endif
2642 +       nf_reset(skb);
2643  
2644         IPTUNNEL_XMIT();
2645         tunnel->recursion--;
2646 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/ipmr.c linux-2.6.7-rc3/net/ipv4/ipmr.c
2647 --- linux-2.6.7-rc3.org/net/ipv4/ipmr.c 2004-06-07 21:14:12.000000000 +0200
2648 +++ linux-2.6.7-rc3/net/ipv4/ipmr.c     2004-06-08 10:38:43.000000000 +0200
2649 @@ -1105,10 +1105,7 @@
2650         skb->h.ipiph = skb->nh.iph;
2651         skb->nh.iph = iph;
2652         memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt));
2653 -#ifdef CONFIG_NETFILTER
2654 -       nf_conntrack_put(skb->nfct);
2655 -       skb->nfct = NULL;
2656 -#endif
2657 +       nf_reset(skb);
2658  }
2659  
2660  static inline int ipmr_forward_finish(struct sk_buff *skb)
2661 @@ -1120,7 +1117,7 @@
2662         if (unlikely(opt->optlen))
2663                 ip_forward_options(skb);
2664  
2665 -       return dst_output(skb);
2666 +       return ip_dst_output(skb);
2667  }
2668  
2669  /*
2670 @@ -1461,10 +1458,7 @@
2671         skb->dst = NULL;
2672         ((struct net_device_stats*)reg_dev->priv)->rx_bytes += skb->len;
2673         ((struct net_device_stats*)reg_dev->priv)->rx_packets++;
2674 -#ifdef CONFIG_NETFILTER
2675 -       nf_conntrack_put(skb->nfct);
2676 -       skb->nfct = NULL;
2677 -#endif
2678 +       nf_reset(skb);
2679         netif_rx(skb);
2680         dev_put(reg_dev);
2681         return 0;
2682 @@ -1520,10 +1514,7 @@
2683         ((struct net_device_stats*)reg_dev->priv)->rx_bytes += skb->len;
2684         ((struct net_device_stats*)reg_dev->priv)->rx_packets++;
2685         skb->dst = NULL;
2686 -#ifdef CONFIG_NETFILTER
2687 -       nf_conntrack_put(skb->nfct);
2688 -       skb->nfct = NULL;
2689 -#endif
2690 +       nf_reset(skb);
2691         netif_rx(skb);
2692         dev_put(reg_dev);
2693         return 0;
2694 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/netfilter/Kconfig linux-2.6.7-rc3/net/ipv4/netfilter/Kconfig
2695 --- linux-2.6.7-rc3.org/net/ipv4/netfilter/Kconfig      2004-06-07 21:14:56.000000000 +0200
2696 +++ linux-2.6.7-rc3/net/ipv4/netfilter/Kconfig  2004-06-08 10:42:36.000000000 +0200
2697 @@ -206,6 +206,11 @@
2698  
2699           To compile it as a module, choose M here.  If unsure, say N.
2700  
2701 +config IP_NF_MATCH_UNCLEAN
2702 +       tristate  'unclean match support (EXPERIMENTAL)'
2703 +       depends on EXPERIMENTAL && IP_NF_IPTABLES
2704 +         help
2705 +
2706  config IP_NF_MATCH_TTL
2707         tristate "TTL match support"
2708         depends on IP_NF_IPTABLES
2709 @@ -603,5 +608,492 @@
2710           <file:Documentation/modules.txt>.  If unsure, say `N'.
2711           help
2712  
2713 +config IP_NF_TARGET_IPV4OPTSSTRIP
2714 +       tristate  'IPV4OPTSSTRIP target support'
2715 +       depends on IP_NF_MANGLE
2716 +       help
2717 +         This option adds an IPV4OPTSSTRIP target.
2718 +         This target allows you to strip all IP options in a packet.
2719 +        
2720 +         If you want to compile it as a module, say M here and read
2721 +         Documentation/modules.txt.  If unsure, say `N'.
2722 +
2723 +config IP_NF_TARGET_NETLINK
2724 +       tristate  'NETLINK target support'
2725 +       depends on IP_NF_FILTER
2726 +       help
2727 +         The NETLINK target allows you to recieve packets in userspace via
2728 +         the kernel firewall netlink socket. Apps such as fwmon
2729 +         (http://firestorm.geek-ware.co.uk) can then recieve and dislpay
2730 +         these packets. This option is basically a re-implementation of the
2731 +         ipchains -o option.
2732 +
2733 +config IP_NF_TARGET_TTL
2734 +       tristate  'TTL target support'
2735 +       depends on IP_NF_MANGLE
2736 +       help
2737 +         This option adds a `TTL' target, which enables the user to set
2738 +         the TTL value or increment / decrement the TTL value by a given
2739 +         amount.
2740 +       
2741 +         If you want to compile it as a module, say M here and read
2742 +         Documentation/modules.txt.  If unsure, say `N'.
2743 +
2744 +config IP_NF_MATCH_CONNLIMIT
2745 +       tristate  'Connections/IP limit match support'
2746 +       depends on IP_NF_IPTABLES
2747 +       help
2748 +         This match allows you to restrict the number of parallel TCP
2749 +         connections to a server per client IP address (or address block).
2750 +       
2751 +         If you want to compile it as a module, say M here and read
2752 +         Documentation/modules.txt.  If unsure, say `N'.
2753 +
2754 +config IP_NF_MATCH_DSTLIMIT
2755 +       tristate  'dstlimit match support'
2756 +       depends on IP_NF_IPTABLES
2757 +
2758 +config IP_NF_MATCH_FUZZY
2759 +       tristate  'fuzzy match support'
2760 +       depends on IP_NF_IPTABLES
2761 +       help
2762 +         This option adds a `fuzzy' match, which allows you to match
2763 +         packets according to a fuzzy logic based law.
2764 +       
2765 +         If you want to compile it as a module, say M here and read
2766 +         Documentation/modules.txt.  If unsure, say `N'.
2767 +
2768 +config IP_NF_MATCH_IPV4OPTIONS
2769 +       tristate  'IPV4OPTIONS match support'
2770 +       depends on IP_NF_IPTABLES
2771 +       help
2772 +         This option adds a IPV4OPTIONS match.
2773 +         It allows you to filter options like source routing,
2774 +         record route, timestamp and router-altert.
2775 +       
2776 +         If you say Y here, try iptables -m ipv4options --help for more information.
2777 +        
2778 +         If you want to compile it as a module, say M here and read
2779 +         Documentation/modules.txt.  If unsure, say `N'.
2780 +
2781 +config IP_NF_MATCH_MPORT
2782 +       tristate  'Multiple port with ranges match support'
2783 +       depends on IP_NF_IPTABLES
2784 +       help
2785 +         This is an enhanced multiport match which supports port
2786 +         ranges as well as single ports.
2787 +       
2788 +         If you want to compile it as a module, say M here and read
2789 +         Documentation/modules.txt.  If unsure, say `N'.
2790 +
2791 +config IP_NF_MATCH_NTH
2792 +       tristate  'Nth match support'
2793 +       depends on IP_NF_IPTABLES
2794 +       help
2795 +         This option adds a `Nth' match, which allow you to make
2796 +         rules that match every Nth packet.  By default there are 
2797 +         16 different counters.
2798 +       
2799 +         [options]
2800 +          --every     Nth              Match every Nth packet
2801 +         [--counter]  num              Use counter 0-15 (default:0)
2802 +         [--start]    num              Initialize the counter at the number 'num'
2803 +                                       instead of 0. Must be between 0 and Nth-1
2804 +         [--packet]   num              Match on 'num' packet. Must be between 0
2805 +                                       and Nth-1.
2806 +       
2807 +                                       If --packet is used for a counter than
2808 +                                       there must be Nth number of --packet
2809 +                                       rules, covering all values between 0 and
2810 +                                       Nth-1 inclusively.
2811 +        
2812 +         If you want to compile it as a module, say M here and read
2813 +         Documentation/modules.txt.  If unsure, say `N'.
2814 +
2815 +config IP_NF_MATCH_OSF
2816 +       tristate  'OSF match support'
2817 +       depends on IP_NF_IPTABLES
2818 +       help
2819 +       
2820 +         The idea of passive OS fingerprint matching exists for quite a long time,
2821 +         but was created as extension fo OpenBSD pf only some weeks ago.
2822 +         Original idea was lurked in some OpenBSD mailing list (thanks
2823 +         grange@open...) and than adopted for Linux netfilter in form of this code.
2824 +       
2825 +         Original table was created by Michal Zalewski <lcamtuf@coredump.cx> for
2826 +         his excellent p0f and than changed a bit for more convenience.
2827 +       
2828 +         This module compares some data(WS, MSS, options and it's order, ttl,
2829 +         df and others) from first SYN packet (actually from packets with SYN
2830 +         bit set) with hardcoded in fingers[] table ones.
2831 +       
2832 +         If you say Y here, try iptables -m osf --help for more information.
2833 +        
2834 +         If you want to compile it as a module, say M here and read
2835 +         Documentation/modules.txt.  If unsure, say `N'.
2836 +
2837 +config IP_POOL_STATISTICS
2838 +       bool  'enable statistics on pool usage'
2839 +       depends on IP_NF_POOL!=n
2840 +       help
2841 +         This option controls whether usage gathering code is compiled into the
2842 +         ip_pool module.  Disabling statistics may be substantially faster.
2843 +
2844 +config IP_NF_POOL
2845 +       tristate  'IP address pool support'
2846 +       depends on IP_NF_IPTABLES
2847 +       help
2848 +         Pool matching lets you use bitmaps with one bit per address from some
2849 +         range of IP addresses; the match depends on whether a checked source
2850 +         or destination address has its bit set in the pool.
2851 +       
2852 +         There is also a POOL netfilter target, which can be used to set or remove
2853 +         the addresses of a packet from a pool.
2854 +       
2855 +         To define and use pools, you need userlevel utilities: a patched iptables,
2856 +         and the program ippool(8), which defines the pools and their bounds.
2857 +         The current release of pool matching is ippool-0.0.2, and can be found
2858 +         in the archives of the netfilter mailing list at
2859 +         http://lists.samba.org/netfilter/.
2860 +       
2861 +         If you want to compile it as a module, say M here and read
2862 +         Documentation/modules.txt.  If unsure, say `N'.
2863 +
2864 +config IP_NF_MATCH_PSD
2865 +       tristate  'psd match support'
2866 +       depends on IP_NF_IPTABLES
2867 +       help
2868 +         This option adds a `psd' match, which allows you to create rules in
2869 +         any iptables table wich will detect TCP and UDP port scans.
2870 +        
2871 +         If you want to compile it as a module, say M here and read
2872 +         Documentation/modules.txt.  If unsure, say `N'.
2873 +
2874 +config IP_NF_MATCH_QUOTA
2875 +       tristate  'quota match support'
2876 +       depends on IP_NF_IPTABLES
2877 +       help
2878 +         This match implements network quotas.
2879 +       
2880 +         If you want to compile it as a module, say M here and read
2881 +         Documentation/modules.txt.  If unsure, say `N'.
2882 +       
2883 +
2884 +config IP_NF_MATCH_RANDOM
2885 +       tristate  'random match support'
2886 +       depends on IP_NF_IPTABLES
2887 +       help
2888 +         This option adds a `random' match,
2889 +         which allow you to match packets randomly
2890 +         following a given probability.
2891 +        
2892 +         If you want to compile it as a module, say M here and read
2893 +         Documentation/modules.txt.  If unsure, say `N'.
2894 +
2895 +config IP_NF_MATCH_REALM
2896 +       tristate  'realm match support'
2897 +       depends on IP_NF_IPTABLES && NET_CLS_ROUTE
2898 +       help
2899 +         This option adds a `realm' match, which allows you to use the realm
2900 +         key from the routing subsytem inside iptables.
2901 +       
2902 +         This match pretty much resembles the CONFIG_NET_CLS_ROUTE4 option 
2903 +         in tc world.
2904 +       
2905 +         If you want to compile it as a module, say M here and read
2906 +         Documentation/modules.txt.  If unsure, say `N'.
2907 +
2908 +config IP_NF_MATCH_SCTP
2909 +       tristate  'SCTP protocol match support'
2910 +       depends on IP_NF_IPTABLES
2911 +
2912 +config IP_NF_MATCH_TIME
2913 +       tristate  'TIME match support'
2914 +       depends on IP_NF_IPTABLES
2915 +       help
2916 +         This option adds a `time' match, which allows you
2917 +         to match based on the packet arrival time/date
2918 +         (arrival time/date at the machine which netfilter is running on) or
2919 +         departure time/date (for locally generated packets).
2920 +       
2921 +         If you say Y here, try iptables -m time --help for more information.
2922 +        
2923 +         If you want to compile it as a module, say M here and read
2924 +         Documentation/modules.txt.  If unsure, say `N'.
2925 +
2926 +config IP_NF_MATCH_U32
2927 +       tristate  'U32 match support'
2928 +       depends on IP_NF_IPTABLES
2929 +       help
2930 +         U32 allows you to extract quantities of up to 4 bytes from a packet,
2931 +         AND them with specified masks, shift them by specified amounts and
2932 +         test whether the results are in any of a set of specified ranges.
2933 +         The specification of what to extract is general enough to skip over
2934 +         headers with lengths stored in the packet, as in IP or TCP header
2935 +         lengths.
2936 +       
2937 +         Details and examples are in the kernel module source.
2938 +
2939 +config IP_NF_CONNTRACK_MARK
2940 +       bool  'Connection mark tracking support'
2941 +       help
2942 +         This option enables support for connection marks, used by the
2943 +         `CONNMARK' target and `connmark' match. Similar to the mark value
2944 +         of packets, but this mark value is kept in the conntrack session
2945 +         instead of the individual packets.
2946 +       
2947 +config IP_NF_TARGET_CONNMARK
2948 +       tristate  'CONNMARK target support'
2949 +       depends on IP_NF_CONNTRACK_MARK && IP_NF_MANGLE
2950 +       help
2951 +         This option adds a `CONNMARK' target, which allows one to manipulate
2952 +         the connection mark value.  Similar to the MARK target, but
2953 +         affects the connection mark value rather than the packet mark value.
2954 +       
2955 +         If you want to compile it as a module, say M here and read
2956 +         Documentation/modules.txt.  The module will be called
2957 +         ipt_CONNMARK.o.  If unsure, say `N'.
2958 +       
2959 +config IP_NF_MATCH_CONNMARK
2960 +       tristate  ' Connection mark match support'
2961 +       depends on IP_NF_CONNTRACK_MARK && IP_NF_IPTABLES
2962 +       help
2963 +         This option adds a `connmark' match, which allows you to match the
2964 +         connection mark value previously set for the session by `CONNMARK'. 
2965 +       
2966 +         If you want to compile it as a module, say M here and read
2967 +         Documentation/modules.txt.  The module will be called
2968 +         ipt_connmark.o.  If unsure, say `N'.
2969 +
2970 +config IP_NF_TARGET_IPMARK
2971 +       tristate  'IPMARK target support'
2972 +       depends on IP_NF_MANGLE
2973 +       help
2974 +         This option adds a `IPMARK' target, which allows you to create rules
2975 +         in the `mangle' table which alter the netfilter mark (nfmark) field
2976 +         basing on the source or destination ip address of the packet.
2977 +         This is very useful for very fast massive mangling and marking.
2978 +       
2979 +         If you want to compile it as a module, say M here and read
2980 +         <file:Documentation/modules.txt>.  If unsure, say `N'.
2981 +
2982 +config IP_NF_TARGET_ROUTE
2983 +       tristate  'ROUTE target support'
2984 +       depends on IP_NF_MANGLE
2985 +       help
2986 +         This option adds a `ROUTE' target, which enables you to setup unusual
2987 +         routes. For example, the ROUTE lets you route a received packet through 
2988 +         an interface or towards a host, even if the regular destination of the 
2989 +         packet is the router itself. The ROUTE target is also able to change the 
2990 +         incoming interface of a packet.
2991 +       
2992 +         The target can be or not a final target. It has to be used inside the 
2993 +         mangle table.
2994 +         
2995 +         If you want to compile it as a module, say M here and read
2996 +         Documentation/modules.txt.  The module will be called ipt_ROUTE.o.
2997 +         If unsure, say `N'.
2998 +
2999 +config IP_NF_TARGET_TARPIT
3000 +       tristate 'TARPIT target support'
3001 +       depends on IP_NF_FILTER
3002 +       help
3003 +         Adds a TARPIT target to iptables, which captures and holds
3004 +         incoming TCP connections using no local per-connection resources.
3005 +         Connections are accepted, but immediately switched to the persist
3006 +         state (0 byte window), in which the remote side stops sending data
3007 +         and asks to continue every 60-240 seconds.  Attempts to close the
3008 +         connection are ignored, forcing the remote side to time out the
3009 +         connection in 12-24 minutes.
3010 +       
3011 +         This offers similar functionality to LaBrea
3012 +         <http://www.hackbusters.net/LaBrea/> but doesn't require dedicated
3013 +         hardware or IPs.  Any TCP port that you would normally DROP or REJECT
3014 +         can instead become a tarpit.
3015 +
3016 +config IP_NF_TARGET_TRACE
3017 +       tristate  'TRACE target support'
3018 +       depends on IP_NF_RAW
3019 +       help
3020 +         The TRACE target allows packets to be traced as those
3021 +         matches any subsequent rule in any table/rule. The matched
3022 +         rule and the packet is logged with the prefix
3023 +       
3024 +         TRACE: tablename/chainname/rulenum  
3025 +       
3026 +         If you want to compile it as a module, say M here and read
3027 +         <file:Documentation/modules.txt>.  If unsure, say `N'.
3028 +
3029 +config IP_NF_TARGET_XOR
3030 +       tristate  'XOR target support'
3031 +       depends on IP_NF_MANGLE
3032 +       help
3033 +         This option adds a `XOR' target, which can encrypt TCP and 
3034 +         UDP traffic using a simple XOR encryption.
3035 +       
3036 +         If you want to compile it as a module, say M here and read
3037 +         Documentation/modules.txt.  If unsure, say `N'.
3038 +
3039 +config IP_NF_MATCH_ADDRTYPE
3040 +       tristate  'address type match support'
3041 +       depends on IP_NF_IPTABLES
3042 +       help
3043 +         This option allows you to match what routing thinks of an address,
3044 +         eg. UNICAST, LOCAL, BROADCAST, ...
3045 +       
3046 +         If you want to compile it as a module, say M here and read
3047 +         Documentation/modules.txt.  If unsure, say `N'.
3048 +
3049 +config IP_NF_EGG
3050 +       tristate  'Eggdrop bot support'
3051 +       depends on IP_NF_CONNTRACK
3052 +       help
3053 +         If you are running an eggdrop hub bot on this machine, then you
3054 +         may want to enable this feature. This enables eggdrop bots to share
3055 +         their user file to other eggdrop bots.
3056 +       
3057 +         If you want to compile it as a module, say M here and read
3058 +         Documentation/modules.txt.  If unsure, say `N'.
3059 +
3060 +config IP_NF_NAT_H323
3061 +       tristate
3062 +       depends on IP_NF_CONNTRACK!=n && IP_NF_NAT!=n
3063 +       default IP_NF_NAT if IP_NF_H323=y
3064 +       default m if IP_NF_H323=m
3065 +
3066 +config IP_NF_H323
3067 +       tristate  'H.323 (netmeeting) support'
3068 +       depends on IP_NF_CONNTRACK
3069 +       help
3070 +         H.323 is a standard signalling protocol used by teleconferencing
3071 +         softwares like netmeeting. With the ip_conntrack_h323 and
3072 +         the ip_nat_h323 modules you can support the protocol on a connection
3073 +         tracking/NATing firewall.
3074 +       
3075 +         If you want to compile it as a module, say 'M' here and read
3076 +         Documentation/modules.txt.  If unsure, say 'N'.
3077 +
3078 +config IP_NF_NAT_MMS
3079 +       tristate
3080 +       depends on IP_NF_CONNTRACK!=n && IP_NF_NAT!=n
3081 +       default IP_NF_NAT if IP_NF_MMS=y
3082 +       default m if IP_NF_MMS=m
3083 +
3084 +config IP_NF_MMS
3085 +       tristate  'MMS protocol support'
3086 +       depends on IP_NF_CONNTRACK
3087 +       help
3088 +         Tracking MMS (Microsoft Windows Media Services) connections
3089 +         could be problematic if random ports are used to send the
3090 +         streaming content. This option allows users to track streaming
3091 +         connections over random UDP or TCP ports.
3092 +       
3093 +         If you want to compile it as a module, say M here and read
3094 +         <file:Documentation/modules.txt>.  If unsure, say `Y'.
3095 +
3096 +config IP_NF_NAT_QUAKE3
3097 +       tristate
3098 +       depends on IP_NF_CONNTRACK!=n && IP_NF_NAT !=n
3099 +       default IP_NF_NAT if IP_NF_QUAKE3=y
3100 +       default m if IP_NF_QUAKE3=m
3101 +
3102 +config IP_NF_QUAKE3
3103 +       tristate "Quake3 protocol support"
3104 +       depends on IP_NF_CONNTRACK
3105 +       help
3106 +         Quake III Arena  connection tracking helper. This module allows for a
3107 +         stricter firewall rulebase if one only allows traffic to a master
3108 +         server. Connections to Quake III server IP addresses and ports returned
3109 +         by the master server will be tracked automatically.
3110 +       
3111 +         If you want to compile it as a module, say M here and read
3112 +         <file:Documentation/modules.txt>.  If unsure, say `Y'.
3113 +
3114 +config IP_NF_RSH
3115 +       tristate  'RSH protocol support'
3116 +       depends on IP_NF_CONNTRACK
3117 +       help
3118 +         The RSH connection tracker is required if the dynamic
3119 +         stderr "Server to Client" connection is to occur during a
3120 +         normal RSH session.  This typically operates as follows;
3121 +       
3122 +           Client 0:1023 --> Server 514    (stream 1 - stdin/stdout)
3123 +           Client 0:1023 <-- Server 0:1023 (stream 2 - stderr)
3124 +       
3125 +         This connection tracker will identify new RSH sessions,
3126 +         extract the outbound session details, and notify netfilter
3127 +         of pending "related" sessions.
3128 +       
3129 +         Warning: This module could be dangerous. It is not "best
3130 +                  practice" to use RSH, use SSH in all instances.
3131 +                  (see rfc1244, rfc1948, rfc2179, etc ad-nauseum)
3132 +       
3133 +       
3134 +         If you want to compile it as a module, say M here and read
3135 +         <file:Documentation/modules.txt>.  If unsure, say `N'.
3136 +
3137 +config IP_NF_NAT_RTSP
3138 +       tristate
3139 +       depends on IP_NF_CONNTRACK!=n && IP_NF_NAT!=n
3140 +       default IP_NF_NAT if IP_NF_RTSP=y
3141 +       default m if IP_NF_RTSP=m
3142 +
3143 +config IP_NF_RTSP
3144 +       tristate  ' RTSP protocol support'
3145 +       depends on IP_NF_CONNTRACK
3146 +       help
3147 +         Support the RTSP protocol.  This allows UDP transports to be setup
3148 +         properly, including RTP and RDT.
3149 +       
3150 +         If you want to compile it as a module, say 'M' here and read
3151 +         Documentation/modules.txt.  If unsure, say 'Y'.
3152 +
3153 +config IP_NF_CT_PROTO_SCTP
3154 +       tristate  'SCTP protocol connection tracking support'
3155 +       depends on IP_NF_CONNTRACK
3156 +
3157 +config IP_NF_MATCH_STRING
3158 +       tristate  'String match support'
3159 +       depends on IP_NF_IPTABLES
3160 +       help
3161 +         String matching alows you to match packets which contain a
3162 +         specified string of characters.
3163 +       
3164 +         If you want to compile it as a module, say M here and read
3165 +         Documentation/modules.txt.  If unsure, say `N'.
3166 +
3167 +config IP_NF_NAT_TALK
3168 +       tristate
3169 +       depends on IP_NF_CONNTRACK!=n && IP_NF_NAT!=n
3170 +       default IP_NF_NAT if IP_NF_TALK=y
3171 +       default m if IP_NF_TALK=m
3172 +
3173 +config IP_NF_TALK
3174 +       tristate  'talk protocol support'
3175 +       depends on IP_NF_CONNTRACK
3176 +       help
3177 +         The talk protocols (both otalk/talk - or talk/ntalk, to confuse
3178 +         you by the different namings about which is old or which is new :-)
3179 +         use an additional channel to setup the talk session and a separated
3180 +         data channel for the actual conversation (like in FTP). Both the 
3181 +         initiating and the setup channels are over UDP, while the data channel 
3182 +         is over TCP, on a random port. The conntrack part of this extension
3183 +         will enable you to let in/out talk sessions easily by matching these
3184 +         connections as RELATED by the state match, while the NAT part helps
3185 +         you to let talk sessions trough a NAT machine.
3186 +       
3187 +         If you want to compile it as a module, say 'M' here and read
3188 +         Documentation/modules.txt.  If unsure, say 'N'.
3189 +
3190 +config IP_NF_MATCH_POLICY
3191 +       tristate "IPsec policy match support"
3192 +       depends on IP_NF_IPTABLES && XFRM
3193 +       help
3194 +         Policy matching allows you to match packets based on the
3195 +         IPsec policy that was used during decapsulation/will
3196 +         be used during encapsulation.
3197 +
3198 +         To compile it as a module, choose M here.  If unsure, say N.
3199 +
3200  endmenu
3201  
3202 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/netfilter/Makefile linux-2.6.7-rc3/net/ipv4/netfilter/Makefile
3203 --- linux-2.6.7-rc3.org/net/ipv4/netfilter/Makefile     2004-06-07 21:14:01.000000000 +0200
3204 +++ linux-2.6.7-rc3/net/ipv4/netfilter/Makefile 2004-06-08 10:42:36.000000000 +0200
3205 @@ -19,10 +19,34 @@
3206  # connection tracking
3207  obj-$(CONFIG_IP_NF_CONNTRACK) += ip_conntrack.o
3208  
3209 +# talk protocol support
3210 +obj-$(CONFIG_IP_NF_TALK) += ip_conntrack_talk.o
3211 +obj-$(CONFIG_IP_NF_NAT_TALK) += ip_nat_talk.o
3212 +
3213 +
3214 +# SCTP protocol connection tracking
3215 +obj-$(CONFIG_IP_NF_CT_PROTO_SCTP) += ip_conntrack_proto_sctp.o
3216
3217 +# H.323 support
3218 +obj-$(CONFIG_IP_NF_H323) += ip_conntrack_h323.o
3219 +obj-$(CONFIG_IP_NF_NAT_H323) += ip_nat_h323.o
3220 +
3221 +
3222  # connection tracking helpers
3223 +
3224 +# rtsp protocol support
3225 +obj-$(CONFIG_IP_NF_RTSP) += ip_conntrack_rtsp.o
3226 +obj-$(CONFIG_IP_NF_NAT_RTSP) += ip_nat_rtsp.o
3227 +
3228 +obj-$(CONFIG_IP_NF_QUAKE3) += ip_conntrack_quake3.o
3229 +obj-$(CONFIG_IP_NF_MMS) += ip_conntrack_mms.o
3230  obj-$(CONFIG_IP_NF_AMANDA) += ip_conntrack_amanda.o
3231  obj-$(CONFIG_IP_NF_TFTP) += ip_conntrack_tftp.o
3232  obj-$(CONFIG_IP_NF_FTP) += ip_conntrack_ftp.o
3233 +obj-$(CONFIG_IP_NF_RSH) += ip_conntrack_rsh.o
3234 +
3235 +obj-$(CONFIG_IP_NF_EGG) += ip_conntrack_egg.o
3236 +
3237  obj-$(CONFIG_IP_NF_IRC) += ip_conntrack_irc.o
3238  
3239  # NAT helpers 
3240 @@ -30,6 +69,8 @@
3241  obj-$(CONFIG_IP_NF_NAT_TFTP) += ip_nat_tftp.o
3242  obj-$(CONFIG_IP_NF_NAT_FTP) += ip_nat_ftp.o
3243  obj-$(CONFIG_IP_NF_NAT_IRC) += ip_nat_irc.o
3244 +obj-$(CONFIG_IP_NF_NAT_QUAKE3) += ip_nat_quake3.o
3245 +obj-$(CONFIG_IP_NF_NAT_MMS) += ip_nat_mms.o
3246  
3247  # generic IP tables 
3248  obj-$(CONFIG_IP_NF_IPTABLES) += ip_tables.o
3249 @@ -43,15 +84,39 @@
3250  # matches
3251  obj-$(CONFIG_IP_NF_MATCH_HELPER) += ipt_helper.o
3252  obj-$(CONFIG_IP_NF_MATCH_LIMIT) += ipt_limit.o
3253 +obj-$(CONFIG_IP_NF_MATCH_SCTP) += ipt_sctp.o
3254 +obj-$(CONFIG_IP_NF_MATCH_QUOTA) += ipt_quota.o
3255 +obj-$(CONFIG_IP_NF_MATCH_DSTLIMIT) += ipt_dstlimit.o
3256  obj-$(CONFIG_IP_NF_MATCH_MARK) += ipt_mark.o
3257 +obj-$(CONFIG_IP_NF_POOL) += ipt_pool.o ipt_POOL.o ip_pool.o
3258  obj-$(CONFIG_IP_NF_MATCH_MAC) += ipt_mac.o
3259  obj-$(CONFIG_IP_NF_MATCH_IPRANGE) += ipt_iprange.o
3260  
3261  obj-$(CONFIG_IP_NF_MATCH_PKTTYPE) += ipt_pkttype.o
3262  obj-$(CONFIG_IP_NF_MATCH_MULTIPORT) += ipt_multiport.o
3263 +
3264 +obj-$(CONFIG_IP_NF_MATCH_MPORT) += ipt_mport.o
3265 +
3266  obj-$(CONFIG_IP_NF_MATCH_OWNER) += ipt_owner.o
3267  obj-$(CONFIG_IP_NF_MATCH_TOS) += ipt_tos.o
3268  
3269 +obj-$(CONFIG_IP_NF_MATCH_TIME) += ipt_time.o
3270 +
3271 +
3272 +obj-$(CONFIG_IP_NF_MATCH_RANDOM) += ipt_random.o
3273 +
3274 +obj-$(CONFIG_IP_NF_MATCH_PSD) += ipt_psd.o
3275 +
3276 +obj-$(CONFIG_IP_NF_MATCH_OSF) += ipt_osf.o
3277 +
3278 +
3279 +obj-$(CONFIG_IP_NF_MATCH_NTH) += ipt_nth.o
3280 +
3281 +obj-$(CONFIG_IP_NF_MATCH_IPV4OPTIONS) += ipt_ipv4options.o
3282 +
3283 +
3284 +obj-$(CONFIG_IP_NF_MATCH_FUZZY) += ipt_fuzzy.o
3285 +
3286  obj-$(CONFIG_IP_NF_MATCH_RECENT) += ipt_recent.o
3287  
3288  obj-$(CONFIG_IP_NF_MATCH_ECN) += ipt_ecn.o
3289 @@ -60,28 +125,47 @@
3290  
3291  obj-$(CONFIG_IP_NF_MATCH_LENGTH) += ipt_length.o
3292  
3293 +obj-$(CONFIG_IP_NF_MATCH_U32) += ipt_u32.o
3294 +
3295 +
3296 +obj-$(CONFIG_IP_NF_MATCH_UNCLEAN) += ipt_unclean.o
3297 +obj-$(CONFIG_IP_NF_MATCH_STRING) += ipt_string.o
3298  obj-$(CONFIG_IP_NF_MATCH_TTL) += ipt_ttl.o
3299  obj-$(CONFIG_IP_NF_MATCH_STATE) += ipt_state.o
3300 +obj-$(CONFIG_IP_NF_MATCH_CONNMARK) += ipt_connmark.o
3301 +obj-$(CONFIG_IP_NF_MATCH_CONNLIMIT) += ipt_connlimit.o
3302  obj-$(CONFIG_IP_NF_MATCH_CONNTRACK) += ipt_conntrack.o
3303  obj-$(CONFIG_IP_NF_MATCH_TCPMSS) += ipt_tcpmss.o
3304 +obj-$(CONFIG_IP_NF_MATCH_ADDRTYPE) += ipt_addrtype.o
3305 +obj-$(CONFIG_IP_NF_MATCH_REALM) += ipt_realm.o
3306  
3307  obj-$(CONFIG_IP_NF_MATCH_PHYSDEV) += ipt_physdev.o
3308 +obj-$(CONFIG_IP_NF_MATCH_POLICY) += ipt_policy.o
3309  
3310  # targets
3311  obj-$(CONFIG_IP_NF_TARGET_REJECT) += ipt_REJECT.o
3312 +obj-$(CONFIG_IP_NF_TARGET_TARPIT) += ipt_TARPIT.o
3313  obj-$(CONFIG_IP_NF_TARGET_TOS) += ipt_TOS.o
3314  obj-$(CONFIG_IP_NF_TARGET_ECN) += ipt_ECN.o
3315  obj-$(CONFIG_IP_NF_TARGET_DSCP) += ipt_DSCP.o
3316  obj-$(CONFIG_IP_NF_TARGET_MARK) += ipt_MARK.o
3317 +obj-$(CONFIG_IP_NF_TARGET_IPMARK) += ipt_IPMARK.o
3318  obj-$(CONFIG_IP_NF_TARGET_MASQUERADE) += ipt_MASQUERADE.o
3319  obj-$(CONFIG_IP_NF_TARGET_REDIRECT) += ipt_REDIRECT.o
3320 +obj-$(CONFIG_IP_NF_TARGET_ROUTE) += ipt_ROUTE.o
3321  obj-$(CONFIG_IP_NF_TARGET_NETMAP) += ipt_NETMAP.o
3322  obj-$(CONFIG_IP_NF_TARGET_SAME) += ipt_SAME.o
3323  obj-$(CONFIG_IP_NF_TARGET_CLASSIFY) += ipt_CLASSIFY.o
3324  obj-$(CONFIG_IP_NF_NAT_SNMP_BASIC) += ip_nat_snmp_basic.o
3325  obj-$(CONFIG_IP_NF_TARGET_LOG) += ipt_LOG.o
3326 +obj-$(CONFIG_IP_NF_TARGET_XOR) += ipt_XOR.o
3327 +obj-$(CONFIG_IP_NF_TARGET_CONNMARK) += ipt_CONNMARK.o
3328 +obj-$(CONFIG_IP_NF_TARGET_TTL) += ipt_TTL.o
3329 +obj-$(CONFIG_IP_NF_TARGET_NETLINK) += ipt_NETLINK.o
3330 +obj-$(CONFIG_IP_NF_TARGET_IPV4OPTSSTRIP) += ipt_IPV4OPTSSTRIP.o
3331  obj-$(CONFIG_IP_NF_TARGET_ULOG) += ipt_ULOG.o
3332  obj-$(CONFIG_IP_NF_TARGET_TCPMSS) += ipt_TCPMSS.o
3333 +obj-$(CONFIG_IP_NF_TARGET_TRACE) += ipt_TRACE.o
3334  obj-$(CONFIG_IP_NF_TARGET_NOTRACK) += ipt_NOTRACK.o
3335  
3336  # generic ARP tables
3337 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/netfilter/ip_conntrack_core.c linux-2.6.7-rc3/net/ipv4/netfilter/ip_conntrack_core.c
3338 --- linux-2.6.7-rc3.org/net/ipv4/netfilter/ip_conntrack_core.c  2004-06-07 21:13:34.000000000 +0200
3339 +++ linux-2.6.7-rc3/net/ipv4/netfilter/ip_conntrack_core.c      2004-06-08 10:36:58.000000000 +0200
3340 @@ -67,6 +67,7 @@
3341  static atomic_t ip_conntrack_count = ATOMIC_INIT(0);
3342  struct list_head *ip_conntrack_hash;
3343  static kmem_cache_t *ip_conntrack_cachep;
3344 +static kmem_cache_t *ip_conntrack_expect_cachep;
3345  struct ip_conntrack ip_conntrack_untracked;
3346  
3347  extern struct ip_conntrack_protocol ip_conntrack_generic_protocol;
3348 @@ -176,7 +177,7 @@
3349         IP_NF_ASSERT(atomic_read(&exp->use));
3350         IP_NF_ASSERT(!timer_pending(&exp->timeout));
3351  
3352 -       kfree(exp);
3353 +       kmem_cache_free(ip_conntrack_expect_cachep, exp);
3354  }
3355  
3356  
3357 @@ -335,7 +337,7 @@
3358                         list_del(&ct->master->expected_list);
3359                         master = ct->master->expectant;
3360                 }
3361 -               kfree(ct->master);
3362 +               kmem_cache_free(ip_conntrack_expect_cachep, ct->master);
3363         }
3364         WRITE_UNLOCK(&ip_conntrack_lock);
3365  
3366 @@ -692,25 +694,22 @@
3367                              struct ip_conntrack_expect *, tuple);
3368         READ_UNLOCK(&ip_conntrack_expect_tuple_lock);
3369  
3370 -       /* If master is not in hash table yet (ie. packet hasn't left
3371 -          this machine yet), how can other end know about expected?
3372 -          Hence these are not the droids you are looking for (if
3373 -          master ct never got confirmed, we'd hold a reference to it
3374 -          and weird things would happen to future packets). */
3375 -       if (expected && !is_confirmed(expected->expectant))
3376 -               expected = NULL;
3377 -
3378 -       /* Look up the conntrack helper for master connections only */
3379 -       if (!expected)
3380 -               conntrack->helper = ip_ct_find_helper(&repl_tuple);
3381 +       if (expected) {
3382 +               /* If master is not in hash table yet (ie. packet hasn't left
3383 +                  this machine yet), how can other end know about expected?
3384 +                  Hence these are not the droids you are looking for (if
3385 +                  master ct never got confirmed, we'd hold a reference to it
3386 +                  and weird things would happen to future packets). */
3387 +               if (!is_confirmed(expected->expectant)) {
3388 +                       conntrack->helper = ip_ct_find_helper(&repl_tuple);
3389 +                       goto end;
3390 +               }
3391  
3392 -       /* If the expectation is dying, then this is a loser. */
3393 -       if (expected
3394 -           && expected->expectant->helper->timeout
3395 -           && ! del_timer(&expected->timeout))
3396 -               expected = NULL;
3397 +               /* Expectation is dying... */
3398 +               if (expected->expectant->helper->timeout
3399 +                   && !del_timer(&expected->timeout))
3400 +                       goto end;       
3401  
3402 -       if (expected) {
3403                 DEBUGP("conntrack: expectation arrives ct=%p exp=%p\n",
3404                         conntrack, expected);
3405                 /* Welcome, Mr. Bond.  We've been expecting you... */
3406 @@ -718,16 +717,28 @@
3407                 __set_bit(IPS_EXPECTED_BIT, &conntrack->status);
3408                 conntrack->master = expected;
3409                 expected->sibling = conntrack;
3410 +#if CONFIG_IP_NF_CONNTRACK_MARK
3411 +               conntrack->mark = expected->expectant->mark;
3412 +#endif
3413                 LIST_DELETE(&ip_conntrack_expect_list, expected);
3414                 expected->expectant->expecting--;
3415                 nf_conntrack_get(&master_ct(conntrack)->infos[0]);
3416 -       }
3417 -       atomic_inc(&ip_conntrack_count);
3418 +
3419 +               /* this is a braindead... --pablo */
3420 +               atomic_inc(&ip_conntrack_count);
3421 +               WRITE_UNLOCK(&ip_conntrack_lock);
3422 +
3423 +               if (expected->expectfn)
3424 +                       expected->expectfn(conntrack);
3425 +
3426 +               goto ret;
3427 +       } else 
3428 +               conntrack->helper = ip_ct_find_helper(&repl_tuple);
3429 +
3430 +end:   atomic_inc(&ip_conntrack_count);
3431         WRITE_UNLOCK(&ip_conntrack_lock);
3432  
3433 -       if (expected && expected->expectfn)
3434 -               expected->expectfn(conntrack);
3435 -       return &conntrack->tuplehash[IP_CT_DIR_ORIGINAL];
3436 +ret:   return &conntrack->tuplehash[IP_CT_DIR_ORIGINAL];
3437  }
3438  
3439  /* On success, returns conntrack ptr, sets skb->nfct and ctinfo */
3440 @@ -923,9 +934,8 @@
3441  ip_conntrack_expect_alloc(void)
3442  {
3443         struct ip_conntrack_expect *new;
3444 -       
3445 -       new = (struct ip_conntrack_expect *)
3446 -               kmalloc(sizeof(struct ip_conntrack_expect), GFP_ATOMIC);
3447 +
3448 +       new = kmem_cache_alloc(ip_conntrack_expect_cachep, GFP_ATOMIC);
3449         if (!new) {
3450                 DEBUGP("expect_related: OOM allocating expect\n");
3451                 return NULL;
3452 @@ -933,6 +943,7 @@
3453  
3454         /* tuple_cmp compares whole union, we have to initialized cleanly */
3455         memset(new, 0, sizeof(struct ip_conntrack_expect));
3456 +       atomic_set(&new->use, 1);
3457  
3458         return new;
3459  }
3460 @@ -944,12 +955,10 @@
3461         DEBUGP("new expectation %p of conntrack %p\n", new, related_to);
3462         new->expectant = related_to;
3463         new->sibling = NULL;
3464 -       atomic_set(&new->use, 1);
3465  
3466         /* add to expected list for this connection */
3467 -       list_add(&new->expected_list, &related_to->sibling_list);
3468 +       list_add_tail(&new->expected_list, &related_to->sibling_list);
3469         /* add to global list of expectations */
3470 -
3471         list_prepend(&ip_conntrack_expect_list, &new->list);
3472         /* add and start timer if required */
3473         if (related_to->helper->timeout) {
3474 @@ -998,12 +1007,12 @@
3475                 }
3476  
3477                 WRITE_UNLOCK(&ip_conntrack_lock);
3478 -               kfree(expect);
3479 +               /* This expectation is not inserted so no need to lock */
3480 +               kmem_cache_free(ip_conntrack_expect_cachep, expect);
3481                 return -EEXIST;
3482  
3483         } else if (related_to->helper->max_expected && 
3484                    related_to->expecting >= related_to->helper->max_expected) {
3485 -               struct list_head *cur_item;
3486                 /* old == NULL */
3487                 if (!(related_to->helper->flags & 
3488                       IP_CT_HELPER_F_REUSE_EXPECT)) {
3489 @@ -1017,7 +1026,7 @@
3490                                        related_to->helper->name,
3491                                        NIPQUAD(related_to->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.ip),
3492                                        NIPQUAD(related_to->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.ip));
3493 -                       kfree(expect);
3494 +                       kmem_cache_free(ip_conntrack_expect_cachep, expect);
3495                         return -EPERM;
3496                 }
3497                 DEBUGP("ip_conntrack: max number of expected "
3498 @@ -1029,21 +1038,14 @@
3499                        NIPQUAD(related_to->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.ip));
3500   
3501                 /* choose the the oldest expectation to evict */
3502 -               list_for_each(cur_item, &related_to->sibling_list) { 
3503 -                       struct ip_conntrack_expect *cur;
3504 -
3505 -                       cur = list_entry(cur_item, 
3506 -                                        struct ip_conntrack_expect,
3507 -                                        expected_list);
3508 -                       if (cur->sibling == NULL) {
3509 -                               old = cur;
3510 +               list_for_each_entry(old, &related_to->sibling_list, 
3511 +                                                     expected_list)
3512 +                       if (old->sibling == NULL)
3513                                 break;
3514 -                       }
3515 -               }
3516  
3517 -               /* (!old) cannot happen, since related_to->expecting is the
3518 -                * number of unconfirmed expects */
3519 -               IP_NF_ASSERT(old);
3520 +               /* We cannot fail since related_to->expecting is the number
3521 +                * of unconfirmed expectations */
3522 +               IP_NF_ASSERT(old && old->sibling == NULL);
3523  
3524                 /* newnat14 does not reuse the real allocated memory
3525                  * structures but rather unexpects the old and
3526 @@ -1058,7 +1060,7 @@
3527                 WRITE_UNLOCK(&ip_conntrack_lock);
3528                 DEBUGP("expect_related: busy!\n");
3529  
3530 -               kfree(expect);
3531 +               kmem_cache_free(ip_conntrack_expect_cachep, expect);
3532                 return -EBUSY;
3533         }
3534  
3535 @@ -1379,6 +1379,7 @@
3536         }
3537  
3538         kmem_cache_destroy(ip_conntrack_cachep);
3539 +       kmem_cache_destroy(ip_conntrack_expect_cachep);
3540         vfree(ip_conntrack_hash);
3541         nf_unregister_sockopt(&so_getorigdst);
3542  }
3543 @@ -1431,6 +1432,15 @@
3544                 printk(KERN_ERR "Unable to create ip_conntrack slab cache\n");
3545                 goto err_free_hash;
3546         }
3547 +
3548 +       ip_conntrack_expect_cachep = kmem_cache_create("ip_conntrack_expect",
3549 +                                       sizeof(struct ip_conntrack_expect),
3550 +                                       0, SLAB_HWCACHE_ALIGN, NULL, NULL);
3551 +       if (!ip_conntrack_expect_cachep) {
3552 +               printk(KERN_ERR "Unable to create ip_expect slab cache\n");
3553 +               goto err_free_conntrack_slab;
3554 +       }
3555 +
3556         /* Don't NEED lock here, but good form anyway. */
3557         WRITE_LOCK(&ip_conntrack_lock);
3558         /* Sew in builtin protocols. */
3559 @@ -1458,6 +1468,8 @@
3560  
3561         return ret;
3562  
3563 +err_free_conntrack_slab:
3564 +       kmem_cache_destroy(ip_conntrack_cachep);
3565  err_free_hash:
3566         vfree(ip_conntrack_hash);
3567  err_unreg_sockopt:
3568 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/netfilter/ip_conntrack_egg.c linux-2.6.7-rc3/net/ipv4/netfilter/ip_conntrack_egg.c
3569 --- linux-2.6.7-rc3.org/net/ipv4/netfilter/ip_conntrack_egg.c   1970-01-01 01:00:00.000000000 +0100
3570 +++ linux-2.6.7-rc3/net/ipv4/netfilter/ip_conntrack_egg.c       2004-06-08 10:38:25.000000000 +0200
3571 @@ -0,0 +1,237 @@
3572 +/* Eggdrop extension for IP connection tracking, Version 0.0.5
3573 + * based on ip_conntrack_irc.c 
3574 + *
3575 + *      This module only supports the share userfile-send command,
3576 + *      used by eggdrops to share it's userfile.
3577 + *
3578 + *      There are no support for NAT at the moment.
3579 + *
3580 + *      This program is free software; you can redistribute it and/or
3581 + *      modify it under the terms of the GNU General Public License
3582 + *      as published by the Free Software Foundation; either version
3583 + *      2 of the License, or (at your option) any later version.
3584 + *
3585 + *     Module load syntax:
3586 + *     
3587 + *     please give the ports of all Eggdrops You have running
3588 + *      on your system, the default port is 3333.
3589 + *
3590 + *      2001-04-19: Security update. IP addresses are now compared
3591 + *                  to prevent unauthorized "related" access.
3592 + *
3593 + *      2002-03-25: Harald Welte <laforge@gnumonks.org>:
3594 + *                 Port to netfilter 'newnat' API.
3595 + */
3596 +
3597 +#include <linux/module.h>
3598 +#include <linux/netfilter.h>
3599 +#include <linux/ip.h>
3600 +#include <net/checksum.h>
3601 +#include <net/tcp.h>
3602 +
3603 +#include <linux/netfilter_ipv4/lockhelp.h>
3604 +#include <linux/netfilter_ipv4/ip_conntrack_helper.h>
3605 +
3606 +#define MAX_PORTS 8
3607 +static int ports[MAX_PORTS];
3608 +static int ports_c = 0;
3609 +static unsigned int egg_timeout = 300;
3610 +
3611 +MODULE_AUTHOR("Magnus Sandin <magnus@sandin.cx>");
3612 +MODULE_DESCRIPTION("Eggdrop (userfile-sharing) connection tracking module");
3613 +MODULE_LICENSE("GPL");
3614 +#ifdef MODULE_PARM
3615 +MODULE_PARM(ports, "1-" __MODULE_STRING(MAX_PORTS) "i");
3616 +MODULE_PARM_DESC(ports, "port numbers of eggdrop servers");
3617 +#endif
3618 +
3619 +DECLARE_LOCK(ip_egg_lock);
3620 +struct module *ip_conntrack_egg = THIS_MODULE;
3621 +
3622 +#if 0
3623 +#define DEBUGP printk
3624 +#else
3625 +#define DEBUGP(format, args...)
3626 +#endif
3627 +
3628 +int parse_command(char *data, char *data_end, u_int32_t * ip, u_int16_t * port)
3629 +/* tries to get the ip_addr and port out of a eggdrop command
3630 +   return value: -1 on failure, 0 on success 
3631 +   data                pointer to first byte of DCC command data
3632 +   data_end    pointer to last byte of dcc command data
3633 +   ip          returns parsed ip of dcc command
3634 +   port                returns parsed port of dcc command */
3635 +{
3636 +       if (data > data_end)
3637 +               return -1;
3638 +       
3639 +       *ip = simple_strtoul(data, &data, 10);
3640 +
3641 +       /* skip blanks between ip and port */
3642 +       while (*data == ' ' && data < data_end)
3643 +               data++;
3644 +
3645 +       *port = simple_strtoul(data, &data, 10);
3646 +       return 0;
3647 +}
3648 +
3649 +
3650 +static int help(const struct iphdr *iph, size_t len,
3651 +               struct ip_conntrack *ct, enum ip_conntrack_info ctinfo)
3652 +{
3653 +       /* tcplen not negative guarenteed by ip_conntrack_tcp.c */
3654 +       struct tcphdr *tcph = (void *) iph + iph->ihl * 4;
3655 +       char *data = (char *) tcph + tcph->doff * 4;
3656 +       char *data_limit;
3657 +       u_int32_t tcplen = len - iph->ihl * 4;
3658 +       u_int32_t datalen = tcplen - tcph->doff * 4;
3659 +       int dir = CTINFO2DIR(ctinfo);
3660 +       int bytes_scanned = 0;
3661 +       struct ip_conntrack_expect exp;
3662 +
3663 +       u_int32_t egg_ip;
3664 +       u_int16_t egg_port;
3665 +
3666 +       DEBUGP("entered\n");
3667 +
3668 +       /* If packet is coming from IRC server */
3669 +       if (dir != IP_CT_DIR_REPLY)
3670 +               return NF_ACCEPT;
3671 +
3672 +       /* Until there's been traffic both ways, don't look in packets. */
3673 +       if (ctinfo != IP_CT_ESTABLISHED
3674 +           && ctinfo != IP_CT_ESTABLISHED + IP_CT_IS_REPLY) {
3675 +               DEBUGP("Conntrackinfo = %u\n", ctinfo);
3676 +               return NF_ACCEPT;
3677 +       }
3678 +
3679 +       /* Not whole TCP header? */
3680 +       if (tcplen < sizeof(struct tcphdr) || tcplen < tcph->doff * 4) {
3681 +               DEBUGP("tcplen = %u\n", (unsigned) tcplen);
3682 +               return NF_ACCEPT;
3683 +       }
3684 +
3685 +       /* Checksum invalid?  Ignore. */
3686 +       /* FIXME: Source route IP option packets --RR */
3687 +       if (tcp_v4_check(tcph, tcplen, iph->saddr, iph->daddr,
3688 +                        csum_partial((char *) tcph, tcplen, 0))) {
3689 +               DEBUGP("bad csum: %p %u %u.%u.%u.%u -> %u.%u.%u.%u\n",
3690 +                       tcph, tcplen, NIPQUAD(iph->saddr),
3691 +                       NIPQUAD(iph->daddr));
3692 +               return NF_ACCEPT;
3693 +       }
3694 +
3695 +       data_limit = (char *) data + datalen;
3696 +       while (datalen > 5 && bytes_scanned < 128) {
3697 +               if (memcmp(data, "s us ", 5)) {
3698 +                       data++;
3699 +                       datalen--;
3700 +                       bytes_scanned++;
3701 +                       continue;
3702 +               }
3703 +
3704 +               data += 5;
3705 +
3706 +               DEBUGP("Userfile-share found in connection "
3707 +                       "%u.%u.%u.%u -> %u.%u.%u.%u\n",
3708 +                       NIPQUAD(iph->saddr), NIPQUAD(iph->daddr));
3709 +
3710 +               if (parse_command((char *) data, data_limit, &egg_ip,
3711 +                                 &egg_port)) {
3712 +                       DEBUGP("no data in userfile-share pkt\n");
3713 +                       return NF_ACCEPT;
3714 +               }
3715 +
3716 +               memset(&exp, 0, sizeof(exp));
3717 +
3718 +               if (ct->tuplehash[dir].tuple.src.ip != htonl(egg_ip)) {
3719 +                       if (net_ratelimit())
3720 +                               printk("Forged Eggdrop command from "
3721 +                                      "%u.%u.%u.%u: %u.%u.%u.%u:%u\n",
3722 +                                      NIPQUAD(ct->tuplehash[dir].tuple.src.ip),
3723 +                                      HIPQUAD(egg_ip), egg_port);
3724 +                       return NF_ACCEPT;
3725 +               }
3726 +
3727 +               exp.tuple.src.ip = iph->daddr;
3728 +               exp.tuple.src.u.tcp.port = 0;
3729 +               exp.tuple.dst.ip = htonl(egg_ip);
3730 +               exp.tuple.dst.u.tcp.port = htons(egg_port);
3731 +               exp.tuple.dst.protonum = IPPROTO_TCP;
3732 +
3733 +               exp.mask.dst.u.tcp.port = 0xffff;
3734 +               exp.mask.dst.protonum = 0xffff;
3735 +
3736 +               DEBUGP("expect_related %u.%u.%u.%u:%u - %u.%u.%u.%u:%u\n",
3737 +                       NIPQUAD(t.src.ip), ntohs(t.src.u.tcp.port),
3738 +                       NIPQUAD(t.dst.ip), ntohs(t.dst.u.tcp.port));
3739 +
3740 +               ip_conntrack_expect_related(&exp, ct);
3741 +               break;
3742 +       }
3743 +       return NF_ACCEPT;
3744 +}
3745 +
3746 +static struct ip_conntrack_helper egg_helpers[MAX_PORTS];
3747 +static char egg_names[MAX_PORTS][14]; /* eggdrop-65535 */
3748 +
3749 +static void deregister_helpers(void) {
3750 +       int i;
3751 +       
3752 +       for (i = 0; i < ports_c; i++) {
3753 +               DEBUGP("unregistering helper for port %d\n", ports[i]);
3754 +               ip_conntrack_helper_unregister(&egg_helpers[i]);
3755 +       }
3756 +}
3757 +
3758 +static int __init init(void)
3759 +{
3760 +       int i, ret;
3761 +       char *tmpname;
3762 +
3763 +       /* If no port given, default to standard eggdrop port */
3764 +       if (ports[0] == 0)
3765 +               ports[0] = 3333;
3766 +
3767 +       for (i = 0; (i < MAX_PORTS) && ports[i]; i++) {
3768 +               memset(&egg_helpers[i], 0,
3769 +                      sizeof(struct ip_conntrack_helper));
3770 +               egg_helpers[i].tuple.src.u.tcp.port = htons(ports[i]);
3771 +               egg_helpers[i].tuple.dst.protonum = IPPROTO_TCP;
3772 +               egg_helpers[i].mask.src.u.tcp.port = 0xFFFF;
3773 +               egg_helpers[i].mask.dst.protonum = 0xFFFF;
3774 +               egg_helpers[i].max_expected = 1;
3775 +               egg_helpers[i].timeout = egg_timeout;
3776 +               egg_helpers[i].flags = IP_CT_HELPER_F_REUSE_EXPECT;
3777 +               egg_helpers[i].me = THIS_MODULE;
3778 +               egg_helpers[i].help = help;
3779 +
3780 +               tmpname = &egg_names[i][0];
3781 +               if (ports[i] == 3333)
3782 +                       sprintf(tmpname, "eggdrop");
3783 +               else
3784 +                       sprintf(tmpname, "eggdrop-%d", ports[i]);
3785 +               egg_helpers[i].name = tmpname;
3786 +
3787 +               DEBUGP("port #%d: %d\n", i, ports[i]);
3788 +
3789 +               ret = ip_conntrack_helper_register(&egg_helpers[i]);
3790 +
3791 +               if (ret) {
3792 +                       printk("ip_conntrack_egg: ERROR registering helper "
3793 +                               "for port %d\n", ports[i]);
3794 +                       deregister_helpers();
3795 +                       return 1;
3796 +               }
3797 +               ports_c++;
3798 +       }
3799 +       return 0;
3800 +}
3801 +
3802 +static void __exit fini(void)
3803 +{
3804 +       deregister_helpers();
3805 +}
3806 +
3807 +module_init(init);
3808 +module_exit(fini);
3809 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/netfilter/ip_conntrack_h323.c linux-2.6.7-rc3/net/ipv4/netfilter/ip_conntrack_h323.c
3810 --- linux-2.6.7-rc3.org/net/ipv4/netfilter/ip_conntrack_h323.c  1970-01-01 01:00:00.000000000 +0100
3811 +++ linux-2.6.7-rc3/net/ipv4/netfilter/ip_conntrack_h323.c      2004-06-08 10:38:40.000000000 +0200
3812 @@ -0,0 +1,308 @@
3813 +/* 
3814 + * H.323 'brute force' extension for H.323 connection tracking. 
3815 + * Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
3816 + *
3817 + * Based on ip_masq_h323.c for 2.2 kernels from CoRiTel, Sofia project.
3818 + * (http://www.coritel.it/projects/sofia/nat/)
3819 + * Uses Sampsa Ranta's excellent idea on using expectfn to 'bind'
3820 + * the unregistered helpers to the conntrack entries.
3821 + */
3822 +
3823 +
3824 +#include <linux/module.h>
3825 +#include <linux/netfilter.h>
3826 +#include <linux/ip.h>
3827 +#include <net/checksum.h>
3828 +#include <net/tcp.h>
3829 +
3830 +#include <linux/netfilter_ipv4/lockhelp.h>
3831 +#include <linux/netfilter_ipv4/ip_conntrack.h>
3832 +#include <linux/netfilter_ipv4/ip_conntrack_core.h>
3833 +#include <linux/netfilter_ipv4/ip_conntrack_helper.h>
3834 +#include <linux/netfilter_ipv4/ip_conntrack_tuple.h>
3835 +#include <linux/netfilter_ipv4/ip_conntrack_h323.h>
3836 +
3837 +MODULE_AUTHOR("Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>");
3838 +MODULE_DESCRIPTION("H.323 'brute force' connection tracking module");
3839 +MODULE_LICENSE("GPL");
3840 +
3841 +DECLARE_LOCK(ip_h323_lock);
3842 +struct module *ip_conntrack_h323 = THIS_MODULE;
3843 +
3844 +#if 0
3845 +#define DEBUGP printk
3846 +#else
3847 +#define DEBUGP(format, args...)
3848 +#endif
3849 +
3850 +/* FIXME: This should be in userspace.  Later. */
3851 +static int h245_help(const struct iphdr *iph, size_t len,
3852 +                    struct ip_conntrack *ct,
3853 +                    enum ip_conntrack_info ctinfo)
3854 +{
3855 +       struct tcphdr *tcph = (void *)iph + iph->ihl * 4;
3856 +       unsigned char *data = (unsigned char *) tcph + tcph->doff * 4;
3857 +       unsigned char *data_limit;
3858 +       u_int32_t tcplen = len - iph->ihl * 4;
3859 +       u_int32_t datalen = tcplen - tcph->doff * 4;
3860 +       int dir = CTINFO2DIR(ctinfo);
3861 +       struct ip_ct_h225_master *info = &ct->help.ct_h225_info;
3862 +       struct ip_conntrack_expect expect, *exp = &expect;
3863 +       struct ip_ct_h225_expect *exp_info = &exp->help.exp_h225_info;
3864 +       u_int16_t data_port;
3865 +       u_int32_t data_ip;
3866 +       unsigned int i;
3867 +
3868 +       DEBUGP("ct_h245_help: help entered %u.%u.%u.%u:%u->%u.%u.%u.%u:%u\n",
3869 +               NIPQUAD(iph->saddr), ntohs(tcph->source),
3870 +               NIPQUAD(iph->daddr), ntohs(tcph->dest));
3871 +
3872 +       /* Can't track connections formed before we registered */
3873 +       if (!info)
3874 +               return NF_ACCEPT;
3875 +               
3876 +       /* Until there's been traffic both ways, don't look in packets. */
3877 +       if (ctinfo != IP_CT_ESTABLISHED
3878 +           && ctinfo != IP_CT_ESTABLISHED + IP_CT_IS_REPLY) {
3879 +               DEBUGP("ct_h245_help: Conntrackinfo = %u\n", ctinfo);
3880 +               return NF_ACCEPT;
3881 +       }
3882 +
3883 +       /* Not whole TCP header or too short packet? */
3884 +       if (tcplen < sizeof(struct tcphdr) || tcplen < tcph->doff * 4 + 5) {
3885 +               DEBUGP("ct_h245_help: tcplen = %u\n", (unsigned)tcplen);
3886 +               return NF_ACCEPT;
3887 +       }
3888 +
3889 +       /* Checksum invalid?  Ignore. */
3890 +       /* FIXME: Source route IP option packets --RR */
3891 +       if (tcp_v4_check(tcph, tcplen, iph->saddr, iph->daddr,
3892 +                             csum_partial((char *)tcph, tcplen, 0))) {
3893 +               DEBUGP("ct_h245_help: bad csum: %p %u %u.%u.%u.%u %u.%u.%u.%u\n",
3894 +                      tcph, tcplen, NIPQUAD(iph->saddr),
3895 +                      NIPQUAD(iph->daddr));
3896 +               return NF_ACCEPT;
3897 +       }
3898 +
3899 +       data_limit = (unsigned char *) data + datalen;
3900 +       /* bytes: 0123   45
3901 +                 ipadrr port */
3902 +       for (i = 0; data < (data_limit - 5); data++, i++) {
3903 +               data_ip = *((u_int32_t *)data);
3904 +               if (data_ip == iph->saddr) {
3905 +                       data_port = *((u_int16_t *)(data + 4));
3906 +                       memset(&expect, 0, sizeof(expect));
3907 +                       /* update the H.225 info */
3908 +                       DEBUGP("ct_h245_help: new RTCP/RTP requested %u.%u.%u.%u:->%u.%u.%u.%u:%u\n",
3909 +                               NIPQUAD(ct->tuplehash[!dir].tuple.src.ip),
3910 +                               NIPQUAD(iph->saddr), ntohs(data_port));
3911 +                       LOCK_BH(&ip_h323_lock);
3912 +                       info->is_h225 = H225_PORT + 1;
3913 +                       exp_info->port = data_port;
3914 +                       exp_info->dir = dir;
3915 +                       exp_info->offset = i;
3916 +
3917 +                       exp->seq = ntohl(tcph->seq) + i;
3918 +                   
3919 +                       exp->tuple = ((struct ip_conntrack_tuple)
3920 +                               { { ct->tuplehash[!dir].tuple.src.ip,
3921 +                                   { 0 } },
3922 +                                 { data_ip,
3923 +                                   { .tcp = { data_port } },
3924 +                                   IPPROTO_UDP }});
3925 +                       exp->mask = ((struct ip_conntrack_tuple)
3926 +                               { { 0xFFFFFFFF, { 0 } },
3927 +                                 { 0xFFFFFFFF, { .tcp = { 0xFFFF } }, 0xFFFF }});
3928 +       
3929 +                       exp->expectfn = NULL;
3930 +                       
3931 +                       /* Ignore failure; should only happen with NAT */
3932 +                       ip_conntrack_expect_related(exp, ct);
3933 +
3934 +                       UNLOCK_BH(&ip_h323_lock);
3935 +               }
3936 +       }
3937 +
3938 +       return NF_ACCEPT;
3939 +
3940 +}
3941 +
3942 +/* H.245 helper is not registered! */
3943 +static struct ip_conntrack_helper h245 = 
3944 +       { { NULL, NULL },
3945 +          "H.245",                             /* name */
3946 +          IP_CT_HELPER_F_REUSE_EXPECT,         /* flags */
3947 +          NULL,                                        /* module */
3948 +          8,                                   /* max_ expected */
3949 +          240,                                 /* timeout */
3950 +          { { 0, { 0 } },                      /* tuple */
3951 +            { 0, { 0 }, IPPROTO_TCP } },
3952 +          { { 0, { 0xFFFF } },                 /* mask */
3953 +            { 0, { 0 }, 0xFFFF } },
3954 +          h245_help                            /* helper */
3955 +       };
3956 +
3957 +static int h225_expect(struct ip_conntrack *ct)
3958 +{
3959 +       WRITE_LOCK(&ip_conntrack_lock);
3960 +       ct->helper = &h245;
3961 +       DEBUGP("h225_expect: helper for %p added\n", ct);
3962 +       WRITE_UNLOCK(&ip_conntrack_lock);
3963 +       
3964 +       return NF_ACCEPT;       /* unused */
3965 +}
3966 +
3967 +/* FIXME: This should be in userspace.  Later. */
3968 +static int h225_help(const struct iphdr *iph, size_t len,
3969 +                    struct ip_conntrack *ct,
3970 +                    enum ip_conntrack_info ctinfo)
3971 +{
3972 +       struct tcphdr *tcph = (void *)iph + iph->ihl * 4;
3973 +       unsigned char *data = (unsigned char *) tcph + tcph->doff * 4;
3974 +       unsigned char *data_limit;
3975 +       u_int32_t tcplen = len - iph->ihl * 4;
3976 +       u_int32_t datalen = tcplen - tcph->doff * 4;
3977 +       int dir = CTINFO2DIR(ctinfo);
3978 +       struct ip_ct_h225_master *info = &ct->help.ct_h225_info;
3979 +       struct ip_conntrack_expect expect, *exp = &expect;
3980 +       struct ip_ct_h225_expect *exp_info = &exp->help.exp_h225_info;
3981 +       u_int16_t data_port;
3982 +       u_int32_t data_ip;
3983 +       unsigned int i;
3984 +       
3985 +       DEBUGP("ct_h225_help: help entered %u.%u.%u.%u:%u->%u.%u.%u.%u:%u\n",
3986 +               NIPQUAD(iph->saddr), ntohs(tcph->source),
3987 +               NIPQUAD(iph->daddr), ntohs(tcph->dest));
3988 +
3989 +       /* Can't track connections formed before we registered */
3990 +       if (!info)
3991 +               return NF_ACCEPT;
3992 +
3993 +       /* Until there's been traffic both ways, don't look in packets. */
3994 +       if (ctinfo != IP_CT_ESTABLISHED
3995 +           && ctinfo != IP_CT_ESTABLISHED + IP_CT_IS_REPLY) {
3996 +               DEBUGP("ct_h225_help: Conntrackinfo = %u\n", ctinfo);
3997 +               return NF_ACCEPT;
3998 +       }
3999 +
4000 +       /* Not whole TCP header or too short packet? */
4001 +       if (tcplen < sizeof(struct tcphdr) || tcplen < tcph->doff * 4 + 5) {
4002 +               DEBUGP("ct_h225_help: tcplen = %u\n", (unsigned)tcplen);
4003 +               return NF_ACCEPT;
4004 +       }
4005 +
4006 +       /* Checksum invalid?  Ignore. */
4007 +       /* FIXME: Source route IP option packets --RR */
4008 +       if (tcp_v4_check(tcph, tcplen, iph->saddr, iph->daddr,
4009 +                             csum_partial((char *)tcph, tcplen, 0))) {
4010 +               DEBUGP("ct_h225_help: bad csum: %p %u %u.%u.%u.%u %u.%u.%u.%u\n",
4011 +                      tcph, tcplen, NIPQUAD(iph->saddr),
4012 +                      NIPQUAD(iph->daddr));
4013 +               return NF_ACCEPT;
4014 +       }
4015 +       
4016 +       data_limit = (unsigned char *) data + datalen;
4017 +       /* bytes: 0123   45
4018 +                 ipadrr port */
4019 +       for (i = 0; data < (data_limit - 5); data++, i++) {
4020 +               data_ip = *((u_int32_t *)data);
4021 +               if (data_ip == iph->saddr) {
4022 +                       data_port = *((u_int16_t *)(data + 4));
4023 +                       if (data_port == tcph->source) {
4024 +                               /* Signal address */
4025 +                               DEBUGP("ct_h225_help: sourceCallSignalAddress from %u.%u.%u.%u\n",
4026 +                                       NIPQUAD(iph->saddr));
4027 +                               /* Update the H.225 info so that NAT can mangle the address/port
4028 +                                  even when we have no expected connection! */
4029 +#ifdef CONFIG_IP_NF_NAT_NEEDED
4030 +                               LOCK_BH(&ip_h323_lock);
4031 +                               info->dir = dir;
4032 +                               info->seq[IP_CT_DIR_ORIGINAL] = ntohl(tcph->seq) + i;
4033 +                               info->offset[IP_CT_DIR_ORIGINAL] = i;
4034 +                               UNLOCK_BH(&ip_h323_lock);
4035 +#endif
4036 +                       } else {
4037 +                               memset(&expect, 0, sizeof(expect));
4038 +
4039 +                               /* update the H.225 info */
4040 +                               LOCK_BH(&ip_h323_lock);
4041 +                               info->is_h225 = H225_PORT;
4042 +                               exp_info->port = data_port;
4043 +                               exp_info->dir = dir;
4044 +                               exp_info->offset = i;
4045 +
4046 +                               exp->seq = ntohl(tcph->seq) + i;
4047 +
4048 +                               exp->tuple = ((struct ip_conntrack_tuple)
4049 +                                       { { ct->tuplehash[!dir].tuple.src.ip,
4050 +                                           { 0 } },
4051 +                                         { data_ip,
4052 +                                           { .tcp = { data_port } },
4053 +                                           IPPROTO_TCP }});
4054 +                               exp->mask = ((struct ip_conntrack_tuple)
4055 +                                       { { 0xFFFFFFFF, { 0 } },
4056 +                                         { 0xFFFFFFFF, { .tcp = { 0xFFFF } }, 0xFFFF }});
4057 +       
4058 +                               exp->expectfn = h225_expect;
4059 +                               
4060 +                               /* Ignore failure */
4061 +                               ip_conntrack_expect_related(exp, ct);
4062 +
4063 +                               DEBUGP("ct_h225_help: new H.245 requested %u.%u.%u.%u->%u.%u.%u.%u:%u\n",
4064 +                                       NIPQUAD(ct->tuplehash[!dir].tuple.src.ip),
4065 +                                       NIPQUAD(iph->saddr), ntohs(data_port));
4066 +
4067 +                               UNLOCK_BH(&ip_h323_lock);
4068 +                       }  
4069 +#ifdef CONFIG_IP_NF_NAT_NEEDED
4070 +               } else if (data_ip == iph->daddr) {
4071 +                       data_port = *((u_int16_t *)(data + 4));
4072 +                       if (data_port == tcph->dest) {
4073 +                               /* Signal address */
4074 +                               DEBUGP("ct_h225_help: destCallSignalAddress %u.%u.%u.%u\n",
4075 +                                       NIPQUAD(iph->daddr));
4076 +                               /* Update the H.225 info so that NAT can mangle the address/port
4077 +                                  even when we have no expected connection! */
4078 +                               LOCK_BH(&ip_h323_lock);
4079 +                               info->dir = dir;
4080 +                               info->seq[IP_CT_DIR_REPLY] = ntohl(tcph->seq) + i;
4081 +                               info->offset[IP_CT_DIR_REPLY] = i;
4082 +                               UNLOCK_BH(&ip_h323_lock);
4083 +                       }
4084 +#endif
4085 +               }
4086 +       }
4087 +
4088 +       return NF_ACCEPT;
4089 +
4090 +}
4091 +
4092 +static struct ip_conntrack_helper h225 = 
4093 +       { { NULL, NULL },
4094 +         "H.225",                                      /* name */
4095 +         IP_CT_HELPER_F_REUSE_EXPECT,                  /* flags */
4096 +         THIS_MODULE,                                  /* module */
4097 +         2,                                            /* max_expected */
4098 +         240,                                          /* timeout */
4099 +         { { 0, { __constant_htons(H225_PORT) } },     /* tuple */
4100 +           { 0, { 0 }, IPPROTO_TCP } },
4101 +         { { 0, { 0xFFFF } },                          /* mask */
4102 +           { 0, { 0 }, 0xFFFF } },
4103 +         h225_help                                     /* helper */
4104 +       };
4105 +
4106 +static int __init init(void)
4107 +{
4108 +       return ip_conntrack_helper_register(&h225);
4109 +}
4110 +
4111 +static void __exit fini(void)
4112 +{
4113 +       /* Unregister H.225 helper */   
4114 +       ip_conntrack_helper_unregister(&h225);
4115 +}
4116 +
4117 +EXPORT_SYMBOL(ip_h323_lock);
4118 +
4119 +module_init(init);
4120 +module_exit(fini);
4121 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/netfilter/ip_conntrack_mms.c linux-2.6.7-rc3/net/ipv4/netfilter/ip_conntrack_mms.c
4122 --- linux-2.6.7-rc3.org/net/ipv4/netfilter/ip_conntrack_mms.c   1970-01-01 01:00:00.000000000 +0100
4123 +++ linux-2.6.7-rc3/net/ipv4/netfilter/ip_conntrack_mms.c       2004-06-08 10:39:44.000000000 +0200
4124 @@ -0,0 +1,308 @@
4125 +/* MMS extension for IP connection tracking
4126 + * (C) 2002 by Filip Sneppe <filip.sneppe@cronos.be>
4127 + * based on ip_conntrack_ftp.c and ip_conntrack_irc.c
4128 + *
4129 + * ip_conntrack_mms.c v0.3 2002-09-22
4130 + *
4131 + *      This program is free software; you can redistribute it and/or
4132 + *      modify it under the terms of the GNU General Public License
4133 + *      as published by the Free Software Foundation; either version
4134 + *      2 of the License, or (at your option) any later version.
4135 + *
4136 + *      Module load syntax:
4137 + *      insmod ip_conntrack_mms.o ports=port1,port2,...port<MAX_PORTS>
4138 + *
4139 + *      Please give the ports of all MMS servers You wish to connect to.
4140 + *      If you don't specify ports, the default will be TCP port 1755.
4141 + *
4142 + *      More info on MMS protocol, firewalls and NAT:
4143 + *      http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwmt/html/MMSFirewall.asp
4144 + *      http://www.microsoft.com/windows/windowsmedia/serve/firewall.asp
4145 + *
4146 + *      The SDP project people are reverse-engineering MMS:
4147 + *      http://get.to/sdp
4148 + */
4149 +
4150 +#include <linux/config.h>
4151 +#include <linux/module.h>
4152 +#include <linux/netfilter.h>
4153 +#include <linux/ip.h>
4154 +#include <linux/ctype.h>
4155 +#include <net/checksum.h>
4156 +#include <net/tcp.h>
4157 +
4158 +#include <linux/netfilter_ipv4/lockhelp.h>
4159 +#include <linux/netfilter_ipv4/ip_conntrack_helper.h>
4160 +#include <linux/netfilter_ipv4/ip_conntrack_mms.h>
4161 +
4162 +DECLARE_LOCK(ip_mms_lock);
4163 +struct module *ip_conntrack_mms = THIS_MODULE;
4164 +
4165 +#define MAX_PORTS 8
4166 +static int ports[MAX_PORTS];
4167 +static int ports_c;
4168 +#ifdef MODULE_PARM
4169 +MODULE_PARM(ports, "1-" __MODULE_STRING(MAX_PORTS) "i");
4170 +#endif
4171 +
4172 +#if 0 
4173 +#define DEBUGP printk
4174 +#else
4175 +#define DEBUGP(format, args...)
4176 +#endif
4177 +
4178 +EXPORT_SYMBOL(ip_mms_lock);
4179 +
4180 +MODULE_AUTHOR("Filip Sneppe <filip.sneppe@cronos.be>");
4181 +MODULE_DESCRIPTION("Microsoft Windows Media Services (MMS) connection tracking module");
4182 +MODULE_LICENSE("GPL");
4183 +
4184 +/* #define isdigit(c) (c >= '0' && c <= '9') */
4185 +
4186 +/* copied from drivers/usb/serial/io_edgeport.c - not perfect but will do the trick */
4187 +static void unicode_to_ascii (char *string, short *unicode, int unicode_size)
4188 +{
4189 +       int i;
4190 +       for (i = 0; i < unicode_size; ++i) {
4191 +               string[i] = (char)(unicode[i]);
4192 +       }
4193 +       string[unicode_size] = 0x00;
4194 +}
4195 +
4196 +__inline static int atoi(char *s) 
4197 +{
4198 +       int i=0;
4199 +       while (isdigit(*s)) {
4200 +               i = i*10 + *(s++) - '0';
4201 +       }
4202 +       return i;
4203 +}
4204 +
4205 +/* convert ip address string like "192.168.0.10" to unsigned int */
4206 +__inline static u_int32_t asciiiptoi(char *s)
4207 +{
4208 +       unsigned int i, j, k;
4209 +
4210 +       for(i=k=0; k<3; ++k, ++s, i<<=8) {
4211 +               i+=atoi(s);
4212 +               for(j=0; (*(++s) != '.') && (j<3); ++j)
4213 +                       ;
4214 +       }
4215 +       i+=atoi(s);
4216 +       return ntohl(i);
4217 +}
4218 +
4219 +int parse_mms(const char *data, 
4220 +             const unsigned int datalen,
4221 +             u_int32_t *mms_ip,
4222 +             u_int16_t *mms_proto,
4223 +             u_int16_t *mms_port,
4224 +             char **mms_string_b,
4225 +             char **mms_string_e,
4226 +             char **mms_padding_e)
4227 +{
4228 +       int unicode_size, i;
4229 +       char tempstring[28];       /* "\\255.255.255.255\UDP\65535" */
4230 +       char getlengthstring[28];
4231 +       
4232 +       for(unicode_size=0; 
4233 +           (char) *(data+(MMS_SRV_UNICODE_STRING_OFFSET+unicode_size*2)) != (char)0;
4234 +           unicode_size++)
4235 +               if ((unicode_size == 28) || (MMS_SRV_UNICODE_STRING_OFFSET+unicode_size*2 >= datalen)) 
4236 +                       return -1; /* out of bounds - incomplete packet */
4237 +       
4238 +       unicode_to_ascii(tempstring, (short *)(data+MMS_SRV_UNICODE_STRING_OFFSET), unicode_size);
4239 +       DEBUGP("ip_conntrack_mms: offset 60: %s\n", (const char *)(tempstring));
4240 +       
4241 +       /* IP address ? */
4242 +       *mms_ip = asciiiptoi(tempstring+2);
4243 +       
4244 +       i=sprintf(getlengthstring, "%u.%u.%u.%u", HIPQUAD(*mms_ip));
4245 +               
4246 +       /* protocol ? */
4247 +       if(strncmp(tempstring+3+i, "TCP", 3)==0)
4248 +               *mms_proto = IPPROTO_TCP;
4249 +       else if(strncmp(tempstring+3+i, "UDP", 3)==0)
4250 +               *mms_proto = IPPROTO_UDP;
4251 +
4252 +       /* port ? */
4253 +       *mms_port = atoi(tempstring+7+i);
4254 +
4255 +       /* we store a pointer to the beginning of the "\\a.b.c.d\proto\port" 
4256 +          unicode string, one to the end of the string, and one to the end 
4257 +          of the packet, since we must keep track of the number of bytes 
4258 +          between end of the unicode string and the end of packet (padding) */
4259 +       *mms_string_b  = (char *)(data + MMS_SRV_UNICODE_STRING_OFFSET);
4260 +       *mms_string_e  = (char *)(data + MMS_SRV_UNICODE_STRING_OFFSET + unicode_size * 2);
4261 +       *mms_padding_e = (char *)(data + datalen); /* looks funny, doesn't it */
4262 +       return 0;
4263 +}
4264 +
4265 +
4266 +/* FIXME: This should be in userspace.  Later. */
4267 +static int help(const struct iphdr *iph, size_t len,
4268 +               struct ip_conntrack *ct,
4269 +               enum ip_conntrack_info ctinfo)
4270 +{
4271 +       /* tcplen not negative guaranteed by ip_conntrack_tcp.c */
4272 +       struct tcphdr *tcph = (void *)iph + iph->ihl * 4;
4273 +       const char *data = (const char *)tcph + tcph->doff * 4;
4274 +       unsigned int tcplen = len - iph->ihl * 4;
4275 +       unsigned int datalen = tcplen - tcph->doff * 4;
4276 +       int dir = CTINFO2DIR(ctinfo);
4277 +       struct ip_conntrack_expect expect, *exp = &expect; 
4278 +       struct ip_ct_mms_expect *exp_mms_info = &exp->help.exp_mms_info;
4279 +       
4280 +       u_int32_t mms_ip;
4281 +       u_int16_t mms_proto;
4282 +       char mms_proto_string[8];
4283 +       u_int16_t mms_port;
4284 +       char *mms_string_b, *mms_string_e, *mms_padding_e;
4285 +            
4286 +       /* Until there's been traffic both ways, don't look in packets. */
4287 +       if (ctinfo != IP_CT_ESTABLISHED
4288 +           && ctinfo != IP_CT_ESTABLISHED+IP_CT_IS_REPLY) {
4289 +               DEBUGP("ip_conntrack_mms: Conntrackinfo = %u\n", ctinfo);
4290 +               return NF_ACCEPT;
4291 +       }
4292 +
4293 +       /* Not whole TCP header? */
4294 +       if (tcplen < sizeof(struct tcphdr) || tcplen < tcph->doff*4) {
4295 +               DEBUGP("ip_conntrack_mms: tcplen = %u\n", (unsigned)tcplen);
4296 +               return NF_ACCEPT;
4297 +       }
4298 +
4299 +       /* Checksum invalid?  Ignore. */
4300 +       /* FIXME: Source route IP option packets --RR */
4301 +       if (tcp_v4_check(tcph, tcplen, iph->saddr, iph->daddr,
4302 +           csum_partial((char *)tcph, tcplen, 0))) {
4303 +               DEBUGP("mms_help: bad csum: %p %u %u.%u.%u.%u %u.%u.%u.%u\n",
4304 +                      tcph, tcplen, NIPQUAD(iph->saddr),
4305 +                      NIPQUAD(iph->daddr));
4306 +               return NF_ACCEPT;
4307 +       }
4308 +       
4309 +       /* Only look at packets with 0x00030002/196610 on bytes 36->39 of TCP payload */
4310 +       /* FIXME: There is an issue with only looking at this packet: before this packet, 
4311 +          the client has already sent a packet to the server with the server's hostname 
4312 +          according to the client (think of it as the "Host: " header in HTTP/1.1). The 
4313 +          server will break the connection if this doesn't correspond to its own host 
4314 +          header. The client can also connect to an IP address; if it's the server's IP
4315 +          address, it will not break the connection. When doing DNAT on a connection 
4316 +          where the client uses a server's IP address, the nat module should detect
4317 +          this and change this string accordingly to the DNATed address. This should
4318 +          probably be done by checking for an IP address, then storing it as a member
4319 +          of struct ip_ct_mms_expect and checking for it in ip_nat_mms...
4320 +          */
4321 +       if( (MMS_SRV_MSG_OFFSET < datalen) && 
4322 +           ((*(u32 *)(data+MMS_SRV_MSG_OFFSET)) == MMS_SRV_MSG_ID)) {
4323 +               DEBUGP("ip_conntrack_mms: offset 37: %u %u %u %u, datalen:%u\n", 
4324 +                      (u8)*(data+36), (u8)*(data+37), 
4325 +                      (u8)*(data+38), (u8)*(data+39),
4326 +                      datalen);
4327 +               if(parse_mms(data, datalen, &mms_ip, &mms_proto, &mms_port,
4328 +                            &mms_string_b, &mms_string_e, &mms_padding_e))
4329 +                       if(net_ratelimit())
4330 +                               /* FIXME: more verbose debugging ? */
4331 +                               printk(KERN_WARNING
4332 +                                      "ip_conntrack_mms: Unable to parse data payload\n");
4333 +
4334 +               memset(&expect, 0, sizeof(expect));
4335 +
4336 +               sprintf(mms_proto_string, "(%u)", mms_proto);
4337 +               DEBUGP("ip_conntrack_mms: adding %s expectation %u.%u.%u.%u -> %u.%u.%u.%u:%u\n",
4338 +                      mms_proto == IPPROTO_TCP ? "TCP"
4339 +                      : mms_proto == IPPROTO_UDP ? "UDP":mms_proto_string,
4340 +                      NIPQUAD(ct->tuplehash[!dir].tuple.src.ip),
4341 +                      NIPQUAD(mms_ip),
4342 +                      mms_port);
4343 +               
4344 +               /* it's possible that the client will just ask the server to tunnel
4345 +                  the stream over the same TCP session (from port 1755): there's 
4346 +                  shouldn't be a need to add an expectation in that case, but it
4347 +                  makes NAT packet mangling so much easier */
4348 +               LOCK_BH(&ip_mms_lock);
4349 +
4350 +               DEBUGP("ip_conntrack_mms: tcph->seq = %u\n", tcph->seq);
4351 +               
4352 +               exp->seq = ntohl(tcph->seq) + (mms_string_b - data);
4353 +               exp_mms_info->len     = (mms_string_e  - mms_string_b);
4354 +               exp_mms_info->padding = (mms_padding_e - mms_string_e);
4355 +               exp_mms_info->port    = mms_port;
4356 +               
4357 +               DEBUGP("ip_conntrack_mms: wrote info seq=%u (ofs=%u), len=%d, padding=%u\n",
4358 +                      exp->seq, (mms_string_e - data), exp_mms_info->len, exp_mms_info->padding);
4359 +               
4360 +               exp->tuple = ((struct ip_conntrack_tuple)
4361 +                             { { ct->tuplehash[!dir].tuple.src.ip, { 0 } },
4362 +                             { mms_ip,
4363 +                               { .tcp = { (__u16) ntohs(mms_port) } },
4364 +                               mms_proto } }
4365 +                            );
4366 +               exp->mask  = ((struct ip_conntrack_tuple)
4367 +                            { { 0xFFFFFFFF, { 0 } },
4368 +                              { 0xFFFFFFFF, { .tcp = { 0xFFFF } }, 0xFFFF }});
4369 +               exp->expectfn = NULL;
4370 +               ip_conntrack_expect_related(&expect, ct);
4371 +               UNLOCK_BH(&ip_mms_lock);
4372 +       }
4373 +
4374 +       return NF_ACCEPT;
4375 +}
4376 +
4377 +static struct ip_conntrack_helper mms[MAX_PORTS];
4378 +static char mms_names[MAX_PORTS][10];
4379 +
4380 +/* Not __exit: called from init() */
4381 +static void fini(void)
4382 +{
4383 +       int i;
4384 +       for (i = 0; (i < MAX_PORTS) && ports[i]; i++) {
4385 +               DEBUGP("ip_conntrack_mms: unregistering helper for port %d\n",
4386 +                               ports[i]);
4387 +               ip_conntrack_helper_unregister(&mms[i]);
4388 +       }
4389 +}
4390 +
4391 +static int __init init(void)
4392 +{
4393 +       int i, ret;
4394 +       char *tmpname;
4395 +
4396 +       if (ports[0] == 0)
4397 +               ports[0] = MMS_PORT;
4398 +
4399 +       for (i = 0; (i < MAX_PORTS) && ports[i]; i++) {
4400 +               memset(&mms[i], 0, sizeof(struct ip_conntrack_helper));
4401 +               mms[i].tuple.src.u.tcp.port = htons(ports[i]);
4402 +               mms[i].tuple.dst.protonum = IPPROTO_TCP;
4403 +               mms[i].mask.src.u.tcp.port = 0xFFFF;
4404 +               mms[i].mask.dst.protonum = 0xFFFF;
4405 +               mms[i].max_expected = 1;
4406 +               mms[i].timeout = 0;
4407 +               mms[i].flags = IP_CT_HELPER_F_REUSE_EXPECT;
4408 +               mms[i].me = THIS_MODULE;
4409 +               mms[i].help = help;
4410 +
4411 +               tmpname = &mms_names[i][0];
4412 +               if (ports[i] == MMS_PORT)
4413 +                       sprintf(tmpname, "mms");
4414 +               else
4415 +                       sprintf(tmpname, "mms-%d", ports[i]);
4416 +               mms[i].name = tmpname;
4417 +
4418 +               DEBUGP("ip_conntrack_mms: registering helper for port %d\n", 
4419 +                               ports[i]);
4420 +               ret = ip_conntrack_helper_register(&mms[i]);
4421 +
4422 +               if (ret) {
4423 +                       fini();
4424 +                       return ret;
4425 +               }
4426 +               ports_c++;
4427 +       }
4428 +       return 0;
4429 +}
4430 +
4431 +module_init(init);
4432 +module_exit(fini);
4433 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/netfilter/ip_conntrack_proto_sctp.c linux-2.6.7-rc3/net/ipv4/netfilter/ip_conntrack_proto_sctp.c
4434 --- linux-2.6.7-rc3.org/net/ipv4/netfilter/ip_conntrack_proto_sctp.c    1970-01-01 01:00:00.000000000 +0100
4435 +++ linux-2.6.7-rc3/net/ipv4/netfilter/ip_conntrack_proto_sctp.c        2004-06-08 10:40:55.000000000 +0200
4436 @@ -0,0 +1,529 @@
4437 +/*
4438 + * Connection tracking protocol helper module for SCTP.
4439 + * 
4440 + * SCTP is defined in RFC 2960. References to various sections in this code 
4441 + * are to this RFC.
4442 + * 
4443 + * This program is free software; you can redistribute it and/or modify
4444 + * it under the terms of the GNU General Public License version 2 as
4445 + * published by the Free Software Foundation.
4446 + */
4447 +
4448 +#include <linux/types.h>
4449 +#include <linux/sched.h>
4450 +#include <linux/timer.h>
4451 +#include <linux/netfilter.h>
4452 +#include <linux/module.h>
4453 +#include <linux/in.h>
4454 +#include <linux/ip.h>
4455 +#include <linux/sctp.h>
4456 +#include <linux/string.h>
4457 +
4458 +#include <linux/netfilter_ipv4/ip_conntrack.h>
4459 +#include <linux/netfilter_ipv4/ip_conntrack_protocol.h>
4460 +#include <linux/netfilter_ipv4/lockhelp.h>
4461 +
4462 +#if 0
4463 +#define DEBUGP(format, ...) printk(format, ## __VA_ARGS__)
4464 +#else
4465 +#define DEBUGP(format, args...)
4466 +#endif
4467 +
4468 +/* Protects conntrack->proto.sctp */
4469 +static DECLARE_RWLOCK(sctp_lock);
4470 +
4471 +/* FIXME: Examine ipfilter's timeouts and conntrack transitions more
4472 +   closely.  They're more complex. --RR 
4473 +
4474 +   And so for me for SCTP :D -Kiran */
4475 +
4476 +static const char *sctp_conntrack_names[] = {
4477 +       "NONE",
4478 +       "CLOSED",
4479 +       "COOKIE_WAIT",
4480 +       "COOKIE_ECHOED",
4481 +       "ESTABLISHED",
4482 +       "SHUTDOWN_SENT",
4483 +       "SHUTDOWN_RECD",
4484 +       "SHUTDOWN_ACK_SENT",
4485 +};
4486 +
4487 +#define SECS  * HZ
4488 +#define MINS  * 60 SECS
4489 +#define HOURS * 60 MINS
4490 +#define DAYS  * 24 HOURS
4491 +
4492 +unsigned long ip_ct_sctp_timeout_closed            =  10 SECS;
4493 +unsigned long ip_ct_sctp_timeout_cookie_wait       =   3 SECS;
4494 +unsigned long ip_ct_sctp_timeout_cookie_echoed     =   3 SECS;
4495 +unsigned long ip_ct_sctp_timeout_established       =   5 DAYS;
4496 +unsigned long ip_ct_sctp_timeout_shutdown_sent     = 300 SECS / 1000;
4497 +unsigned long ip_ct_sctp_timeout_shutdown_recd     = 300 SECS / 1000;
4498 +unsigned long ip_ct_sctp_timeout_shutdown_ack_sent =   3 SECS;
4499 +
4500 +static unsigned long * sctp_timeouts[]
4501 += { 0,                                     /* SCTP_CONNTRACK_NONE  */
4502 +    &ip_ct_sctp_timeout_closed,                   /* SCTP_CONNTRACK_CLOSED */
4503 +    &ip_ct_sctp_timeout_cookie_wait,       /* SCTP_CONNTRACK_COOKIE_WAIT */
4504 +    &ip_ct_sctp_timeout_cookie_echoed,     /* SCTP_CONNTRACK_COOKIE_ECHOED */
4505 +    &ip_ct_sctp_timeout_established,       /* SCTP_CONNTRACK_ESTABLISHED */
4506 +    &ip_ct_sctp_timeout_shutdown_sent,     /* SCTP_CONNTRACK_SHUTDOWN_SENT */
4507 +    &ip_ct_sctp_timeout_shutdown_recd,     /* SCTP_CONNTRACK_SHUTDOWN_RECD */
4508 +    &ip_ct_sctp_timeout_shutdown_ack_sent  /* SCTP_CONNTRACK_SHUTDOWN_ACK_SENT */
4509 + };
4510 +
4511 +#define sNO SCTP_CONNTRACK_NONE
4512 +#define        sCL SCTP_CONNTRACK_CLOSED
4513 +#define        sCW SCTP_CONNTRACK_COOKIE_WAIT
4514 +#define        sCE SCTP_CONNTRACK_COOKIE_ECHOED
4515 +#define        sES SCTP_CONNTRACK_ESTABLISHED
4516 +#define        sSS SCTP_CONNTRACK_SHUTDOWN_SENT
4517 +#define        sSR SCTP_CONNTRACK_SHUTDOWN_RECD
4518 +#define        sSA SCTP_CONNTRACK_SHUTDOWN_ACK_SENT
4519 +#define        sIV SCTP_CONNTRACK_MAX
4520 +
4521 +/* 
4522 +       These are the descriptions of the states:
4523 +
4524 +NOTE: These state names are tantalizingly similar to the states of an 
4525 +SCTP endpoint. But the interpretation of the states is a little different,
4526 +considering that these are the states of the connection and not of an end 
4527 +point. Please note the subtleties. -Kiran
4528 +
4529 +NONE              - Nothing so far.
4530 +COOKIE WAIT       - We have seen an INIT chunk in the original direction, or also 
4531 +                    an INIT_ACK chunk in the reply direction.
4532 +COOKIE ECHOED     - We have seen a COOKIE_ECHO chunk in the original direction.
4533 +ESTABLISHED       - We have seen a COOKIE_ACK in the reply direction.
4534 +SHUTDOWN_SENT     - We have seen a SHUTDOWN chunk in the original direction.
4535 +SHUTDOWN_RECD     - We have seen a SHUTDOWN chunk in the reply directoin.
4536 +SHUTDOWN_ACK_SENT - We have seen a SHUTDOWN_ACK chunk in the direction opposite
4537 +                    to that of the SHUTDOWN chunk.
4538 +CLOSED            - We have seen a SHUTDOWN_COMPLETE chunk in the direction of 
4539 +                    the SHUTDOWN chunk. Connection is closed.
4540 +*/
4541 +
4542 +/* TODO
4543 + - I have assumed that the first INIT is in the original direction. 
4544 + This messes things when an INIT comes in the reply direction in CLOSED
4545 + state.
4546 + - Check the error type in the reply dir before transitioning from 
4547 +cookie echoed to closed.
4548 + - Sec 5.2.4 of RFC 2960
4549 + - Multi Homing support.
4550 +*/
4551 +
4552 +/* SCTP conntrack state transitions */
4553 +static enum sctp_conntrack sctp_conntracks[2][9][SCTP_CONNTRACK_MAX] = {
4554 +       {
4555 +/*     ORIGINAL        */
4556 +/*                  sNO, sCL, sCW, sCE, sES, sSS, sSR, sSA */
4557 +/* init         */ {sCW, sCW, sCW, sCE, sES, sSS, sSR, sSA},
4558 +/* init_ack     */ {sCL, sCL, sCW, sCE, sES, sSS, sSR, sSA},
4559 +/* abort        */ {sCL, sCL, sCL, sCL, sCL, sCL, sCL, sCL},
4560 +/* shutdown     */ {sCL, sCL, sCW, sCE, sSS, sSS, sSR, sSA},
4561 +/* shutdown_ack */ {sSA, sCL, sCW, sCE, sES, sSA, sSA, sSA},
4562 +/* error        */ {sCL, sCL, sCW, sCE, sES, sSS, sSR, sSA},/* Cant have Stale cookie*/
4563 +/* cookie_echo  */ {sCL, sCL, sCE, sCE, sES, sSS, sSR, sSA},/* 5.2.4 - Big TODO */
4564 +/* cookie_ack   */ {sCL, sCL, sCW, sCE, sES, sSS, sSR, sSA},/* Cant come in orig dir */
4565 +/* shutdown_comp*/ {sCL, sCL, sCW, sCE, sES, sSS, sSR, sCL}
4566 +       },
4567 +       {
4568 +/*     REPLY   */
4569 +/*                  sNO, sCL, sCW, sCE, sES, sSS, sSR, sSA */
4570 +/* init         */ {sIV, sCL, sCW, sCE, sES, sSS, sSR, sSA},/* INIT in sCL Big TODO */
4571 +/* init_ack     */ {sIV, sCL, sCW, sCE, sES, sSS, sSR, sSA},
4572 +/* abort        */ {sIV, sCL, sCL, sCL, sCL, sCL, sCL, sCL},
4573 +/* shutdown     */ {sIV, sCL, sCW, sCE, sSR, sSS, sSR, sSA},
4574 +/* shutdown_ack */ {sIV, sCL, sCW, sCE, sES, sSA, sSA, sSA},
4575 +/* error        */ {sIV, sCL, sCW, sCL, sES, sSS, sSR, sSA},
4576 +/* cookie_echo  */ {sIV, sCL, sCW, sCE, sES, sSS, sSR, sSA},/* Cant come in reply dir */
4577 +/* cookie_ack   */ {sIV, sCL, sCW, sES, sES, sSS, sSR, sSA},
4578 +/* shutdown_comp*/ {sIV, sCL, sCW, sCE, sES, sSS, sSR, sCL}
4579 +       }
4580 +};
4581 +
4582 +static int sctp_pkt_to_tuple(const struct sk_buff *skb,
4583 +                            unsigned int dataoff,
4584 +                            struct ip_conntrack_tuple *tuple)
4585 +{
4586 +       sctp_sctphdr_t hdr;
4587 +
4588 +       DEBUGP(__FUNCTION__);
4589 +       DEBUGP("\n");
4590 +
4591 +       /* Actually only need first 8 bytes. */
4592 +       if (skb_copy_bits(skb, dataoff, &hdr, 8) != 0)
4593 +               return 0;
4594 +
4595 +       tuple->src.u.sctp.port = hdr.source;
4596 +       tuple->dst.u.sctp.port = hdr.dest;
4597 +
4598 +       return 1;
4599 +}
4600 +
4601 +static int sctp_invert_tuple(struct ip_conntrack_tuple *tuple,
4602 +                            const struct ip_conntrack_tuple *orig)
4603 +{
4604 +       DEBUGP(__FUNCTION__);
4605 +       DEBUGP("\n");
4606 +
4607 +       tuple->src.u.sctp.port = orig->dst.u.sctp.port;
4608 +       tuple->dst.u.sctp.port = orig->src.u.sctp.port;
4609 +       return 1;
4610 +}
4611 +
4612 +/* Print out the per-protocol part of the tuple. */
4613 +static unsigned int sctp_print_tuple(char *buffer,
4614 +                                    const struct ip_conntrack_tuple *tuple)
4615 +{
4616 +       DEBUGP(__FUNCTION__);
4617 +       DEBUGP("\n");
4618 +
4619 +       return sprintf(buffer, "sport=%hu dport=%hu ",
4620 +                      ntohs(tuple->src.u.sctp.port),
4621 +                      ntohs(tuple->dst.u.sctp.port));
4622 +}
4623 +
4624 +/* Print out the private part of the conntrack. */
4625 +static unsigned int sctp_print_conntrack(char *buffer,
4626 +                                        const struct ip_conntrack *conntrack)
4627 +{
4628 +       enum sctp_conntrack state;
4629 +
4630 +       DEBUGP(__FUNCTION__);
4631 +       DEBUGP("\n");
4632 +
4633 +       READ_LOCK(&sctp_lock);
4634 +       state = conntrack->proto.sctp.state;
4635 +       READ_UNLOCK(&sctp_lock);
4636 +
4637 +       return sprintf(buffer, "%s ", sctp_conntrack_names[state]);
4638 +}
4639 +
4640 +#define for_each_sctp_chunk(skb, sch, offset, count)   \
4641 +for (offset = skb->nh.iph->ihl * 4 + sizeof (sctp_sctphdr_t), count = 0;       \
4642 +       offset < skb->len && !skb_copy_bits(skb, offset, &sch, sizeof(sch));    \
4643 +       offset += (htons(sch.length) + 3) & ~3, count++)
4644 +
4645 +/* Some validity checks to make sure the chunks are fine */
4646 +static int do_basic_checks(struct ip_conntrack *conntrack,
4647 +                          const struct sk_buff *skb,
4648 +                          char *map)
4649 +{
4650 +       u_int32_t offset, count;
4651 +       sctp_chunkhdr_t sch;
4652 +       int flag;
4653 +
4654 +       DEBUGP(__FUNCTION__);
4655 +       DEBUGP("\n");
4656 +
4657 +       flag = 0;
4658 +
4659 +       for_each_sctp_chunk (skb, sch, offset, count) {
4660 +               DEBUGP("Chunk Num: %d  Type: %d\n", count, sch.type);
4661 +
4662 +               if (sch.type == SCTP_CID_INIT 
4663 +                       || sch.type == SCTP_CID_INIT_ACK
4664 +                       || sch.type == SCTP_CID_SHUTDOWN_COMPLETE) {
4665 +                       flag = 1;
4666 +               }
4667 +
4668 +               /* Cookie Ack/Echo chunks not the first OR 
4669 +                  Init / Init Ack / Shutdown compl chunks not the only chunks */
4670 +               if ((sch.type == SCTP_CID_COOKIE_ACK 
4671 +                       || sch.type == SCTP_CID_COOKIE_ECHO
4672 +                       || flag)
4673 +                    && count !=0 ) {
4674 +                       DEBUGP("Basic checks failed\n");
4675 +                       return 1;
4676 +               }
4677 +
4678 +               if (map) {
4679 +                       set_bit (sch.type, (void *)map);
4680 +               }
4681 +       }
4682 +
4683 +       DEBUGP("Basic checks passed\n");
4684 +       return 0;
4685 +}
4686 +
4687 +static int new_state(enum ip_conntrack_dir dir,
4688 +                    enum sctp_conntrack cur_state,
4689 +                    int chunk_type)
4690 +{
4691 +       int i;
4692 +
4693 +       DEBUGP(__FUNCTION__);
4694 +       DEBUGP("\n");
4695 +
4696 +       DEBUGP("Chunk type: %d\n", chunk_type);
4697 +
4698 +       switch (chunk_type) {
4699 +               case SCTP_CID_INIT: 
4700 +                       DEBUGP("SCTP_CID_INIT\n");
4701 +                       i = 0; break;
4702 +               case SCTP_CID_INIT_ACK: 
4703 +                       DEBUGP("SCTP_CID_INIT_ACK\n");
4704 +                       i = 1; break;
4705 +               case SCTP_CID_ABORT: 
4706 +                       DEBUGP("SCTP_CID_ABORT\n");
4707 +                       i = 2; break;
4708 +               case SCTP_CID_SHUTDOWN: 
4709 +                       DEBUGP("SCTP_CID_SHUTDOWN\n");
4710 +                       i = 3; break;
4711 +               case SCTP_CID_SHUTDOWN_ACK: 
4712 +                       DEBUGP("SCTP_CID_SHUTDOWN_ACK\n");
4713 +                       i = 4; break;
4714 +               case SCTP_CID_ERROR: 
4715 +                       DEBUGP("SCTP_CID_ERROR\n");
4716 +                       i = 5; break;
4717 +               case SCTP_CID_COOKIE_ECHO: 
4718 +                       DEBUGP("SCTP_CID_COOKIE_ECHO\n");
4719 +                       i = 6; break;
4720 +               case SCTP_CID_COOKIE_ACK: 
4721 +                       DEBUGP("SCTP_CID_COOKIE_ACK\n");
4722 +                       i = 7; break;
4723 +               case SCTP_CID_SHUTDOWN_COMPLETE: 
4724 +                       DEBUGP("SCTP_CID_SHUTDOWN_COMPLETE\n");
4725 +                       i = 8; break;
4726 +               default:
4727 +                       /* Other chunks like DATA, SACK, HEARTBEAT and
4728 +                       its ACK do not cause a change in state */
4729 +                       DEBUGP("Unknown chunk type, Will stay in %s\n", 
4730 +                                               sctp_conntrack_names[cur_state]);
4731 +                       return cur_state;
4732 +       }
4733 +
4734 +       DEBUGP("dir: %d   cur_state: %s  chunk_type: %d  new_state: %s\n", 
4735 +                       dir, sctp_conntrack_names[cur_state], chunk_type,
4736 +                       sctp_conntrack_names[sctp_conntracks[dir][i][cur_state]]);
4737 +
4738 +       return sctp_conntracks[dir][i][cur_state];
4739 +}
4740 +
4741 +/* Returns verdict for packet, or -1 for invalid. */
4742 +static int sctp_packet(struct ip_conntrack *conntrack,
4743 +                      const struct sk_buff *skb,
4744 +                      enum ip_conntrack_info ctinfo)
4745 +{
4746 +       enum sctp_conntrack newconntrack, oldsctpstate;
4747 +       sctp_sctphdr_t sctph;
4748 +       sctp_chunkhdr_t sch;
4749 +       u_int32_t offset, count;
4750 +       char map[256 / sizeof (char)] = {0};
4751 +
4752 +       DEBUGP(__FUNCTION__);
4753 +       DEBUGP("\n");
4754 +
4755 +       if (skb_copy_bits(skb, skb->nh.iph->ihl * 4, &sctph, sizeof(sctph)) != 0)
4756 +               return -1;
4757 +
4758 +       if (do_basic_checks(conntrack, skb, map) != 0)
4759 +               return -1;
4760 +
4761 +       /* Check the verification tag (Sec 8.5) */
4762 +       if (!test_bit(SCTP_CID_INIT, (void *)map)
4763 +               && !test_bit(SCTP_CID_SHUTDOWN_COMPLETE, (void *)map)
4764 +               && !test_bit(SCTP_CID_COOKIE_ECHO, (void *)map)
4765 +               && !test_bit(SCTP_CID_ABORT, (void *)map)
4766 +               && !test_bit(SCTP_CID_SHUTDOWN_ACK, (void *)map)
4767 +               && (sctph.vtag != conntrack->proto.sctp.vtag[CTINFO2DIR(ctinfo)])) {
4768 +               DEBUGP("Verification tag check failed\n");
4769 +               return -1;
4770 +       }
4771 +
4772 +       oldsctpstate = newconntrack = SCTP_CONNTRACK_MAX;
4773 +       for_each_sctp_chunk (skb, sch, offset, count) {
4774 +               WRITE_LOCK(&sctp_lock);
4775 +
4776 +               /* Special cases of Verification tag check (Sec 8.5.1) */
4777 +               if (sch.type == SCTP_CID_INIT) {
4778 +                       /* Sec 8.5.1 (A) */
4779 +                       if (sctph.vtag != 0) {
4780 +                               WRITE_UNLOCK(&sctp_lock);
4781 +                               return -1;
4782 +                       }
4783 +               } else if (sch.type == SCTP_CID_ABORT) {
4784 +                       /* Sec 8.5.1 (B) */
4785 +                       if (!(sctph.vtag == conntrack->proto.sctp.vtag[CTINFO2DIR(ctinfo)])
4786 +                               && !(sctph.vtag == conntrack->proto.sctp.vtag
4787 +                                                       [1 - CTINFO2DIR(ctinfo)])) {
4788 +                               WRITE_UNLOCK(&sctp_lock);
4789 +                               return -1;
4790 +                       }
4791 +               } else if (sch.type == SCTP_CID_SHUTDOWN_COMPLETE) {
4792 +                       /* Sec 8.5.1 (C) */
4793 +                       if (!(sctph.vtag == conntrack->proto.sctp.vtag[CTINFO2DIR(ctinfo)])
4794 +                               && !(sctph.vtag == conntrack->proto.sctp.vtag
4795 +                                                       [1 - CTINFO2DIR(ctinfo)] 
4796 +                                       && (sch.flags & 1))) {
4797 +                               WRITE_UNLOCK(&sctp_lock);
4798 +                               return -1;
4799 +                       }
4800 +               } else if (sch.type == SCTP_CID_COOKIE_ECHO) {
4801 +                       /* Sec 8.5.1 (D) */
4802 +                       if (!(sctph.vtag == conntrack->proto.sctp.vtag[CTINFO2DIR(ctinfo)])) {
4803 +                               WRITE_UNLOCK(&sctp_lock);
4804 +                               return -1;
4805 +                       }
4806 +               }
4807 +
4808 +               oldsctpstate = conntrack->proto.sctp.state;
4809 +               newconntrack = new_state(CTINFO2DIR(ctinfo), oldsctpstate, sch.type);
4810 +
4811 +               /* Invalid */
4812 +               if (newconntrack == SCTP_CONNTRACK_MAX) {
4813 +                       DEBUGP("ip_conntrack_sctp: Invalid dir=%i ctype=%u conntrack=%u\n",
4814 +                              CTINFO2DIR(ctinfo), sch.type, oldsctpstate);
4815 +                       WRITE_UNLOCK(&sctp_lock);
4816 +                       return -1;
4817 +               }
4818 +
4819 +               /* If it is an INIT or an INIT ACK note down the vtag */
4820 +               if (sch.type == SCTP_CID_INIT 
4821 +                       || sch.type == SCTP_CID_INIT_ACK) {
4822 +                       sctp_inithdr_t inithdr;
4823 +
4824 +                       if (skb_copy_bits(skb, offset + sizeof (sctp_chunkhdr_t),
4825 +                               &inithdr, sizeof(inithdr)) != 0) {
4826 +                                       WRITE_UNLOCK(&sctp_lock);
4827 +                                       return -1;
4828 +                       }
4829 +                       DEBUGP("Setting vtag %x for dir %d\n", 
4830 +                                       inithdr.init_tag, CTINFO2DIR(ctinfo));
4831 +                       conntrack->proto.sctp.vtag[IP_CT_DIR_ORIGINAL] = inithdr.init_tag;
4832 +               }
4833 +
4834 +               conntrack->proto.sctp.state = newconntrack;
4835 +               WRITE_UNLOCK(&sctp_lock);
4836 +       }
4837 +
4838 +       ip_ct_refresh(conntrack, *sctp_timeouts[newconntrack]);
4839 +
4840 +       if (oldsctpstate == SCTP_CONNTRACK_COOKIE_ECHOED
4841 +               && CTINFO2DIR(ctinfo) == IP_CT_DIR_REPLY
4842 +               && newconntrack == SCTP_CONNTRACK_ESTABLISHED) {
4843 +               DEBUGP("Setting assured bit\n");
4844 +               set_bit(IPS_ASSURED_BIT, &conntrack->status);
4845 +       }
4846 +
4847 +       return NF_ACCEPT;
4848 +}
4849 +
4850 +/* Called when a new connection for this protocol found. */
4851 +static int sctp_new(struct ip_conntrack *conntrack, 
4852 +                   const struct sk_buff *skb)
4853 +{
4854 +       enum sctp_conntrack newconntrack;
4855 +       sctp_sctphdr_t sctph;
4856 +       sctp_chunkhdr_t sch;
4857 +       u_int32_t offset, count;
4858 +       char map[256 / sizeof (char)] = {0};
4859 +
4860 +       DEBUGP(__FUNCTION__);
4861 +       DEBUGP("\n");
4862 +
4863 +       if (skb_copy_bits(skb, skb->nh.iph->ihl * 4, &sctph, sizeof(sctph)) != 0)
4864 +               return -1;
4865 +
4866 +       if (do_basic_checks(conntrack, skb, map) != 0)
4867 +               return -1;
4868 +
4869 +       /* If an OOTB packet has any of these chunks discard (Sec 8.4) */
4870 +       if ((test_bit (SCTP_CID_ABORT, (void *)map))
4871 +               || (test_bit (SCTP_CID_SHUTDOWN_COMPLETE, (void *)map))
4872 +               || (test_bit (SCTP_CID_COOKIE_ACK, (void *)map))) {
4873 +               return -1;
4874 +       }
4875 +
4876 +       newconntrack = SCTP_CONNTRACK_MAX;
4877 +       for_each_sctp_chunk (skb, sch, offset, count) {
4878 +               /* Don't need lock here: this conntrack not in circulation yet */
4879 +               newconntrack = new_state (IP_CT_DIR_ORIGINAL, 
4880 +                                               SCTP_CONNTRACK_NONE, sch.type);
4881 +
4882 +               /* Invalid: delete conntrack */
4883 +               if (newconntrack == SCTP_CONNTRACK_MAX) {
4884 +                       DEBUGP("ip_conntrack_sctp: invalid new deleting.\n");
4885 +                       return 0;
4886 +               }
4887 +
4888 +               /* Copy the vtag into the state info */
4889 +               if (sch.type == SCTP_CID_INIT) {
4890 +                       if (sctph.vtag == 0) {
4891 +                               sctp_inithdr_t inithdr;
4892 +
4893 +                               if (skb_copy_bits(skb, offset + sizeof (sctp_chunkhdr_t), 
4894 +                                       &inithdr, sizeof(inithdr)) != 0) {
4895 +                                               return -1;
4896 +                               }
4897 +
4898 +                               DEBUGP("Setting vtag %x for new conn\n", 
4899 +                                       inithdr.init_tag);
4900 +
4901 +                               conntrack->proto.sctp.vtag[IP_CT_DIR_REPLY] = 
4902 +                                                               inithdr.init_tag;
4903 +                       } else {
4904 +                               /* Sec 8.5.1 (A) */
4905 +                               return -1;
4906 +                       }
4907 +               }
4908 +               /* If it is a shutdown ack OOTB packet, we expect a return
4909 +                  shutdown complete, otherwise an ABORT Sec 8.4 (5) and (8) */
4910 +               else {
4911 +                       DEBUGP("Setting vtag %x for new conn OOTB\n", 
4912 +                               sctph.vtag);
4913 +                       conntrack->proto.sctp.vtag[IP_CT_DIR_REPLY] = sctph.vtag;
4914 +               }
4915 +
4916 +               conntrack->proto.sctp.state = newconntrack;
4917 +       }
4918 +
4919 +       return 1;
4920 +}
4921 +
4922 +static int sctp_exp_matches_pkt(struct ip_conntrack_expect *exp,
4923 +                               const struct sk_buff *skb)
4924 +{
4925 +       /* To be implemented */
4926 +       return 0;
4927 +}
4928 +
4929 +struct ip_conntrack_protocol ip_conntrack_protocol_sctp = { 
4930 +       .list            = { NULL, NULL }, 
4931 +       .proto           = IPPROTO_SCTP, 
4932 +       .name            = "sctp",
4933 +       .pkt_to_tuple    = sctp_pkt_to_tuple, 
4934 +       .invert_tuple    = sctp_invert_tuple, 
4935 +       .print_tuple     = sctp_print_tuple, 
4936 +       .print_conntrack = sctp_print_conntrack,
4937 +       .packet          = sctp_packet, 
4938 +       .new             = sctp_new, 
4939 +       .destroy         = NULL, 
4940 +       .exp_matches_pkt = sctp_exp_matches_pkt, 
4941 +       .me              = THIS_MODULE 
4942 +};
4943 +
4944 +int __init init(void)
4945 +{
4946 +       int ret;
4947 +
4948 +       ret = ip_conntrack_protocol_register(&ip_conntrack_protocol_sctp);
4949 +       DEBUGP("SCTP conntrack module loading %s\n", 
4950 +                                       ret ? "failed": "succeeded");
4951 +       return ret;
4952 +}
4953 +
4954 +void __exit fini(void)
4955 +{
4956 +       ip_conntrack_protocol_unregister(&ip_conntrack_protocol_sctp);
4957 +       DEBUGP("SCTP conntrack module unloaded\n");
4958 +}
4959 +
4960 +module_init(init);
4961 +module_exit(fini);
4962 +
4963 +MODULE_LICENSE("GPL");
4964 +MODULE_AUTHOR("Kiran Kumar Immidi");
4965 +MODULE_DESCRIPTION("Netfilter connection tracking protocol helper for SCTP");
4966 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/netfilter/ip_conntrack_quake3.c linux-2.6.7-rc3/net/ipv4/netfilter/ip_conntrack_quake3.c
4967 --- linux-2.6.7-rc3.org/net/ipv4/netfilter/ip_conntrack_quake3.c        1970-01-01 01:00:00.000000000 +0100
4968 +++ linux-2.6.7-rc3/net/ipv4/netfilter/ip_conntrack_quake3.c    2004-06-08 10:40:36.000000000 +0200
4969 @@ -0,0 +1,156 @@
4970 +/* Quake3 extension for IP connection tracking
4971 + * (C) 2002 by Filip Sneppe <filip.sneppe@cronos.be>
4972 + * based on ip_conntrack_ftp.c and ip_conntrack_tftp.c
4973 + *
4974 + * ip_conntrack_quake3.c v0.04 2002-08-31
4975 + *
4976 + *      This program is free software; you can redistribute it and/or
4977 + *      modify it under the terms of the GNU General Public License
4978 + *      as published by the Free Software Foundation; either version
4979 + *      2 of the License, or (at your option) any later version.
4980 + *
4981 + *      Module load syntax:
4982 + *      insmod ip_conntrack_quake3.o ports=port1,port2,...port<MAX_PORTS>
4983 + *
4984 + *      please give the ports of all Quake3 master servers You wish to 
4985 + *      connect to. If you don't specify ports, the default will be UDP 
4986 + *      port 27950.
4987 + *
4988 + *      Thanks to the Ethereal folks for their analysis of the Quake3 protocol.
4989 + */
4990 +
4991 +#include <linux/module.h>
4992 +#include <linux/ip.h>
4993 +#include <linux/udp.h>
4994 +
4995 +#include <linux/netfilter.h>
4996 +#include <linux/netfilter_ipv4/ip_tables.h>
4997 +#include <linux/netfilter_ipv4/ip_conntrack_helper.h>
4998 +#include <linux/netfilter_ipv4/ip_conntrack_quake3.h>
4999 +
5000 +struct module *ip_conntrack_quake3 = THIS_MODULE;
5001 +
5002 +MODULE_AUTHOR("Filip Sneppe <filip.sneppe@cronos.be>");
5003 +MODULE_DESCRIPTION("Netfilter connection tracking module for Quake III Arena");
5004 +MODULE_LICENSE("GPL");
5005 +
5006 +#define MAX_PORTS 8
5007 +static int ports[MAX_PORTS];
5008 +static int ports_c = 0;
5009 +#ifdef MODULE_PARM
5010 +MODULE_PARM(ports, "1-" __MODULE_STRING(MAX_PORTS) "i");
5011 +MODULE_PARM_DESC(ports, "port numbers of Quake III master servers");
5012 +#endif
5013 +
5014 +/* Quake3 master server reply will add > 100 expectations per reply packet; when
5015 +   doing lots of printk's, klogd may not be able to read /proc/kmsg fast enough */
5016 +#if 0 
5017 +#define DEBUGP printk
5018 +#else
5019 +#define DEBUGP(format, args...)
5020 +#endif
5021 +
5022 +struct quake3_search quake3s_conntrack = { "****", "getserversResponse", sizeof("getserversResponse") - 1 };
5023 +
5024 +static int quake3_help(const struct iphdr *iph, size_t len,
5025 +       struct ip_conntrack *ct,
5026 +       enum ip_conntrack_info ctinfo)
5027 +{
5028 +       struct udphdr *udph = (void *)iph + iph->ihl * 4;
5029 +       int dir = CTINFO2DIR(ctinfo);
5030 +       struct ip_conntrack_expect exp;
5031 +       int i;
5032 +       
5033 +        /* Until there's been traffic both ways, don't look in packets. note: it's UDP ! */
5034 +       if (ctinfo != IP_CT_ESTABLISHED
5035 +           && ctinfo != IP_CT_IS_REPLY) {
5036 +               DEBUGP("ip_conntrack_quake3: not ok ! Conntrackinfo = %u\n", ctinfo);
5037 +               return NF_ACCEPT;
5038 +       } else { DEBUGP("ip_conntrack_quake3: it's ok ! Conntrackinfo = %u\n", ctinfo); }
5039 +       
5040 +       if (strnicmp((const char *)udph + 12, quake3s_conntrack.pattern, quake3s_conntrack.plen) == 0) {
5041 +               for(i=31;    /* 8 bytes UDP hdr, 4 bytes filler, 18 bytes "getserversResponse", 1 byte "\" */
5042 +                   i+6 < ntohs(udph->len);
5043 +                   i+=7) {
5044 +                       DEBUGP("ip_conntrack_quake3: adding server at offset %u/%u %u.%u.%u.%u:%u\n",
5045 +                              i, ntohs(udph->len),
5046 +                              NIPQUAD( (u_int32_t) *( (u_int32_t *)( (int)udph + i ) ) ), 
5047 +                              ntohs((__u16) *( (__u16 *)( (int)udph + i + 4 ) ) ) );
5048 +
5049 +                       memset(&exp, 0, sizeof(exp));
5050 +
5051 +                       exp.tuple = ((struct ip_conntrack_tuple)
5052 +                                    { { ct->tuplehash[!dir].tuple.src.ip, { 0 } },
5053 +                                      { (u_int32_t) *((u_int32_t *)((int)udph + i)), 
5054 +                                      { .udp = { (__u16) *((__u16 *)((int)udph+i+4)) } }, 
5055 +                                        IPPROTO_UDP } }
5056 +                                   );
5057 +                       exp.mask  = ((struct ip_conntrack_tuple)
5058 +                                    { { 0xFFFFFFFF, { 0 } },
5059 +                                      { 0xFFFFFFFF, { .udp = { 0xFFFF } }, 0xFFFF }});
5060 +                       exp.expectfn = NULL;
5061 +
5062 +                       ip_conntrack_expect_related(&exp, ct);
5063 +               }
5064 +
5065 +       }
5066 +       
5067 +       return(NF_ACCEPT);
5068 +}
5069 +
5070 +static struct ip_conntrack_helper quake3[MAX_PORTS];
5071 +static char quake3_names[MAX_PORTS][13];  /* quake3-65535 */
5072 +
5073 +static void fini(void)
5074 +{
5075 +       int i;
5076 +
5077 +       for(i = 0 ; (i < ports_c); i++) {
5078 +               DEBUGP("ip_conntrack_quake3: unregistering helper for port %d\n",
5079 +                                       ports[i]);
5080 +               ip_conntrack_helper_unregister(&quake3[i]);
5081 +       } 
5082 +}
5083 +
5084 +static int __init init(void)
5085 +{
5086 +       int i, ret;
5087 +       char *tmpname;
5088 +
5089 +       if(!ports[0])
5090 +               ports[0]=QUAKE3_MASTER_PORT;
5091 +
5092 +       for(i = 0 ; (i < MAX_PORTS) && ports[i] ; i++) {
5093 +               /* Create helper structure */
5094 +               memset(&quake3[i], 0, sizeof(struct ip_conntrack_helper));
5095 +
5096 +               quake3[i].tuple.dst.protonum = IPPROTO_UDP;
5097 +               quake3[i].tuple.src.u.udp.port = htons(ports[i]);
5098 +               quake3[i].mask.dst.protonum = 0xFFFF;
5099 +               quake3[i].mask.src.u.udp.port = 0xFFFF;
5100 +               quake3[i].help = quake3_help;
5101 +               quake3[i].me = THIS_MODULE;
5102 +
5103 +               tmpname = &quake3_names[i][0];
5104 +               if (ports[i] == QUAKE3_MASTER_PORT)
5105 +                       sprintf(tmpname, "quake3");
5106 +               else
5107 +                       sprintf(tmpname, "quake3-%d", i);
5108 +               quake3[i].name = tmpname;
5109 +               
5110 +               DEBUGP("ip_conntrack_quake3: registering helper for port %d\n",
5111 +                      ports[i]);
5112 +
5113 +               ret=ip_conntrack_helper_register(&quake3[i]);
5114 +               if(ret) {
5115 +                       fini();
5116 +                       return(ret);
5117 +               }
5118 +               ports_c++;
5119 +       }
5120 +
5121 +       return(0);
5122 +}
5123 +
5124 +module_init(init);
5125 +module_exit(fini);
5126 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/netfilter/ip_conntrack_rsh.c linux-2.6.7-rc3/net/ipv4/netfilter/ip_conntrack_rsh.c
5127 --- linux-2.6.7-rc3.org/net/ipv4/netfilter/ip_conntrack_rsh.c   1970-01-01 01:00:00.000000000 +0100
5128 +++ linux-2.6.7-rc3/net/ipv4/netfilter/ip_conntrack_rsh.c       2004-06-08 10:40:43.000000000 +0200
5129 @@ -0,0 +1,331 @@
5130 +/* RSH extension for IP connection tracking, Version 1.0
5131 + * (C) 2002 by Ian (Larry) Latter <Ian.Latter@mq.edu.au>
5132 + * based on HW's ip_conntrack_irc.c    
5133 + *
5134 + * ip_conntrack_rsh.c,v 1.0 2002/07/17 14:49:26
5135 + *
5136 + *      This program is free software; you can redistribute it and/or
5137 + *      modify it under the terms of the GNU General Public License
5138 + *      as published by the Free Software Foundation; either version
5139 + *      2 of the License, or (at your option) any later version.
5140 + **
5141 + *     Module load syntax:
5142 + *     insmod ip_conntrack_rsh.o ports=port1,port2,...port<MAX_PORTS>
5143 + *     
5144 + *     please give the ports of all RSH servers You wish to connect to.
5145 + *     If You don't specify ports, the default will be port 514
5146 + **
5147 + *      Note to all:
5148 + *        RSH blows ... you should use SSH (openssh.org) to replace it,
5149 + *        unfortunately I babysit some sysadmins that won't migrate
5150 + *       their legacy crap, in our second tier.
5151 + */
5152 +
5153 +
5154 +/*
5155 + *  Some docco ripped from the net to teach me all there is to know about
5156 + *  RSH, in 16.5 seconds (ie, all of the non-netfilter docco used to write
5157 + *  this module).
5158 + *
5159 + *  I have no idea what "unix rshd man pages" these guys have .. but that
5160 + *  is some pretty detailed docco!
5161 + **
5162 + *
5163 + *  4. Of the rsh protocol.
5164 + *  -----------------------
5165 + * 
5166 + *   The rshd listens on TCP port #514. The following info is from the unix
5167 + *   rshd man pages :
5168 + * 
5169 + *   "Service Request Protocol
5170 + * 
5171 + *    When the rshd daemon receives a service request, it initiates the
5172 + *    following protocol:
5173 + * 
5174 + *     1. The rshd daemon checks the source port number for the request.
5175 + *        If the port number is not in the range 0 through 1023, the rshd daemon
5176 + *        terminates the connection.
5177 + * 
5178 + *     2. The rshd daemon reads characters from the socket up to a null byte.
5179 + *        The string read is interpreted as an ASCII number (base 10). If this
5180 + *        number is nonzero, the rshd daemon interprets it as the port number
5181 + *        of a secondary stream to be used as standard error. A second connection
5182 + *        is created to the specified port on the client host. The source port
5183 + *        on the local host is in the range 0 through 1023.
5184 + * 
5185 + *     3. The rshd daemon uses the source address of the initial connection
5186 + *        request to determine the name of the client host. If the name cannot
5187 + *        be determined, the rshd daemon uses the dotted decimal representation
5188 + *        of the client host's address.
5189 + * 
5190 + *     4. The rshd daemon retrieves the following information from the initial
5191 + *        socket:
5192 + * 
5193 + *         * A null-terminated string of at most 16 bytes interpreted as
5194 + *           the user name of the user on the client host.
5195 + * 
5196 + *         * A null-terminated string of at most 16 bytes interpreted as
5197 + *           the user name to be used on the local server host.
5198 + * 
5199 + *         * Another null-terminated string interpreted as a command line
5200 + *           to be passed to a shell on the local server host.
5201 + * 
5202 + *     5. The rshd daemon attempts to validate the user using the following steps:
5203 + * 
5204 + *         a. The rshd daemon looks up the local user name in the /etc/passwd
5205 + *            file and tries to switch to the home directory (using the chdir
5206 + *            subroutine). If either the lookup or the directory change fails,
5207 + *            the rshd daemon terminates the connection.
5208 + * 
5209 + *         b. If the local user ID is a nonzero value, the rshd daemon searches
5210 + *            the /etc/hosts.equiv file to see if the name of the client
5211 + *            workstation is listed. If the client workstation is listed as an
5212 + *            equivalent host, the rshd daemon validates the user.
5213 + * 
5214 + *         c. If the $HOME/.rhosts file exists, the rshd daemon tries to
5215 + *            authenticate the user by checking the .rhosts file.
5216 + * 
5217 + *         d. If either the $HOME/.rhosts authentication fails or the
5218 + *            client host is not an equivalent host, the rshd daemon
5219 + *            terminates the connection.
5220 + * 
5221 + *     6. Once rshd validates the user, the rshd daemon returns a null byte
5222 + *        on the initial connection and passes the command line to the user's
5223 + *        local login shell. The shell then inherits the network connections
5224 + *        established by the rshd daemon."
5225 + * 
5226 + */
5227 +
5228 +
5229 +#include <linux/module.h>
5230 +#include <linux/netfilter.h>
5231 +#include <linux/ip.h>
5232 +#include <net/checksum.h>
5233 +#include <net/tcp.h>
5234 +
5235 +#include <linux/netfilter_ipv4/lockhelp.h>
5236 +#include <linux/netfilter_ipv4/ip_tables.h>
5237 +#include <linux/netfilter_ipv4/ip_conntrack_helper.h>
5238 +#include <linux/netfilter_ipv4/ip_conntrack_rsh.h>
5239 +
5240 +#define MAX_PORTS 8
5241 +static int ports[MAX_PORTS];
5242 +static int ports_n_c = 0;
5243 +
5244 +MODULE_AUTHOR("Ian (Larry) Latter <Ian.Latter@mq.edu.au>");
5245 +MODULE_DESCRIPTION("RSH connection tracking module");
5246 +MODULE_LICENSE("GPL");
5247 +#ifdef MODULE_PARM
5248 +MODULE_PARM(ports, "1-" __MODULE_STRING(MAX_PORTS) "i");
5249 +MODULE_PARM_DESC(ports, "port numbers of RSH servers");
5250 +#endif
5251 +
5252 +DECLARE_LOCK(ip_rsh_lock);
5253 +struct module *ip_conntrack_rsh = THIS_MODULE;
5254 +
5255 +#if 0
5256 +#define DEBUGP(format, args...) printk(KERN_DEBUG "ip_conntrack_rsh: " \
5257 +                                       format, ## args)
5258 +#else
5259 +#define DEBUGP(format, args...)
5260 +#endif
5261 +
5262 +
5263 +
5264 +/* FIXME: This should be in userspace.  Later. */
5265 +static int help(const struct iphdr *iph, size_t len,
5266 +               struct ip_conntrack *ct, enum ip_conntrack_info ctinfo)
5267 +{
5268 +       /* tcplen not negative guarenteed by ip_conntrack_tcp.c */
5269 +       struct tcphdr *tcph = (void *) iph + iph->ihl * 4;
5270 +       const char *data = (const char *) tcph + tcph->doff * 4;
5271 +       u_int32_t tcplen = len - iph->ihl * 4;
5272 +       int dir = CTINFO2DIR(ctinfo);
5273 +        struct ip_conntrack_expect expect, *exp = &expect;
5274 +        struct ip_ct_rsh_expect *exp_rsh_info = &exp->help.exp_rsh_info;
5275 +       u_int16_t port;
5276 +       int maxoctet;
5277 +
5278 +       /*  note that "maxoctet" is used to maintain sanity (8 was the
5279 +        *  original array size used in rshd/glibc) -- is there a
5280 +        *  vulnerability in rshd.c in the looped port *= 10?
5281 +        */
5282 +
5283 +
5284 +       DEBUGP("entered\n");
5285 +
5286 +       /* bail if packet is not from RSH client */
5287 +       if (dir == IP_CT_DIR_REPLY)
5288 +               return NF_ACCEPT;
5289 +
5290 +       /* Until there's been traffic both ways, don't look in packets. */
5291 +       if (ctinfo != IP_CT_ESTABLISHED
5292 +           && ctinfo != IP_CT_ESTABLISHED + IP_CT_IS_REPLY) {
5293 +               DEBUGP("Conntrackinfo = %u\n", ctinfo);
5294 +               return NF_ACCEPT;
5295 +       }
5296 +
5297 +       /* Not whole TCP header? */
5298 +       if (tcplen < sizeof(struct tcphdr) || tcplen < tcph->doff * 4) {
5299 +               DEBUGP("tcplen = %u\n", (unsigned) tcplen);
5300 +               return NF_ACCEPT;
5301 +       }
5302 +
5303 +       /* Checksum invalid?  Ignore. */
5304 +       /* FIXME: Source route IP option packets --RR */
5305 +       if (tcp_v4_check(tcph, tcplen, iph->saddr, iph->daddr,
5306 +                        csum_partial((char *) tcph, tcplen, 0))) {
5307 +               DEBUGP("bad csum: %p %u %u.%u.%u.%u %u.%u.%u.%u\n",
5308 +                    tcph, tcplen, NIPQUAD(iph->saddr),
5309 +                    NIPQUAD(iph->daddr));
5310 +               return NF_ACCEPT;
5311 +       }
5312 +
5313 +       /* find the rsh stderr port */
5314 +       maxoctet = 4;
5315 +       port = 0;
5316 +       for ( ; *data != 0 && maxoctet != 0; data++, maxoctet--) {
5317 +               if (*data < 0)
5318 +                       return(1);
5319 +               if (*data == 0)
5320 +                       break;
5321 +               if (*data < 48 || *data > 57) {
5322 +                       DEBUGP("these aren't the packets you're looking for ..\n");
5323 +                       return NF_ACCEPT;
5324 +               }
5325 +               port = port * 10 + ( *data - 48 );
5326 +       }
5327 +
5328 +       /* dont relate sessions that try to expose the client */
5329 +       DEBUGP("found port %u\n", port);
5330 +       if (port > 1023) {
5331 +               DEBUGP("skipping, expected port size is greater than 1023!\n");
5332 +               return NF_ACCEPT;
5333 +       }
5334 +
5335 +
5336 +       LOCK_BH(&ip_rsh_lock);
5337 +
5338 +       /*  new(,related) connection is;
5339 +        *          reply + dst (uint)port + src port (0:1023)
5340 +        */
5341 +       memset(&expect, 0, sizeof(expect));
5342 +
5343 +       /*  save some discovered data, in case someone ever wants to write
5344 +        *  a NAT module for this bastard ..
5345 +        */
5346 +       exp_rsh_info->port = port;
5347 +
5348 +       DEBUGP("wrote info port=%u\n", exp_rsh_info->port);
5349 +
5350 +
5351 +       /* Watch out, Radioactive-Man! */
5352 +       exp->tuple.src.ip = ct->tuplehash[!dir].tuple.src.ip;
5353 +       exp->tuple.dst.ip = ct->tuplehash[!dir].tuple.dst.ip;
5354 +       exp->tuple.src.u.tcp.port = 0;
5355 +       exp->tuple.dst.u.tcp.port = htons(exp_rsh_info->port);
5356 +       exp->tuple.dst.protonum = IPPROTO_TCP;
5357 +
5358 +       exp->mask.src.ip = 0xffffffff;
5359 +       exp->mask.dst.ip = 0xffffffff;
5360 +
5361 +       exp->mask.src.u.tcp.port = htons(0xfc00);
5362 +       exp->mask.dst.u.tcp.port = htons(0xfc00);
5363 +       exp->mask.dst.protonum = 0xffff;
5364 +
5365 +       exp->expectfn = NULL;
5366 +
5367 +       ip_conntrack_expect_related(&expect, ct);
5368 +
5369 +       DEBUGP("expect related ip   %u.%u.%u.%u:%u-%u.%u.%u.%u:%u\n",
5370 +               NIPQUAD(exp->tuple.src.ip),
5371 +               ntohs(exp->tuple.src.u.tcp.port),
5372 +               NIPQUAD(exp->tuple.dst.ip),
5373 +               ntohs(exp->tuple.dst.u.tcp.port));
5374 +
5375 +       DEBUGP("expect related mask %u.%u.%u.%u:%u-%u.%u.%u.%u:%u\n",
5376 +               NIPQUAD(exp->mask.src.ip),
5377 +               ntohs(exp->mask.src.u.tcp.port),
5378 +               NIPQUAD(exp->mask.dst.ip),
5379 +               ntohs(exp->mask.dst.u.tcp.port));
5380 +       UNLOCK_BH(&ip_rsh_lock);
5381 +
5382 +       return NF_ACCEPT;
5383 +}
5384 +
5385 +static struct ip_conntrack_helper rsh_helpers[MAX_PORTS];
5386 +
5387 +static void fini(void);
5388 +
5389 +static int __init init(void)
5390 +{
5391 +       int port, ret;
5392 +       static char name[10];
5393 +
5394 +
5395 +       /* If no port given, default to standard RSH port */
5396 +       if (ports[0] == 0)
5397 +               ports[0] = RSH_PORT;
5398 +
5399 +       for (port = 0; (port < MAX_PORTS) && ports[port]; port++) {
5400 +               memset(&rsh_helpers[port], 0, sizeof(struct ip_conntrack_helper));
5401 +
5402 +                if (ports[port] == RSH_PORT)
5403 +                        sprintf(name, "rsh");
5404 +                else
5405 +                        sprintf(name, "rsh-%d", port);
5406 +
5407 +               rsh_helpers[port].name = name;
5408 +               rsh_helpers[port].me = THIS_MODULE;
5409 +               rsh_helpers[port].max_expected = 1;
5410 +               rsh_helpers[port].flags = IP_CT_HELPER_F_REUSE_EXPECT;
5411 +               rsh_helpers[port].timeout = 0;
5412 +
5413 +               rsh_helpers[port].tuple.dst.protonum = IPPROTO_TCP;
5414 +               rsh_helpers[port].mask.dst.protonum = 0xffff;
5415 +
5416 +               /* RSH must come from ports 0:1023 to ports[port] (514) */
5417 +               rsh_helpers[port].tuple.src.u.tcp.port = htons(ports[port]);
5418 +               rsh_helpers[port].mask.src.u.tcp.port = htons(0xfc00);
5419 +               rsh_helpers[port].mask.dst.u.tcp.port = htons(0xfc00);
5420 +
5421 +               rsh_helpers[port].help = help;
5422 +
5423 +               DEBUGP("registering helper for port #%d: %d/TCP\n", port, ports[port]);
5424 +               DEBUGP("helper match ip   %u.%u.%u.%u:%u-%u.%u.%u.%u:%u\n",
5425 +                       NIPQUAD(rsh_helpers[port].tuple.src.ip),
5426 +                       ntohs(rsh_helpers[port].tuple.src.u.tcp.port),
5427 +                       NIPQUAD(rsh_helpers[port].tuple.dst.ip),
5428 +                       ntohs(rsh_helpers[port].tuple.dst.u.tcp.port));
5429 +               DEBUGP("helper match mask %u.%u.%u.%u:%u-%u.%u.%u.%u:%u\n",
5430 +                       NIPQUAD(rsh_helpers[port].mask.src.ip),
5431 +                       ntohs(rsh_helpers[port].mask.src.u.tcp.port),
5432 +                       NIPQUAD(rsh_helpers[port].mask.dst.ip),
5433 +                       ntohs(rsh_helpers[port].mask.dst.u.tcp.port));
5434 +
5435 +               ret = ip_conntrack_helper_register(&rsh_helpers[port]);
5436 +
5437 +               if (ret) {
5438 +                       printk("ERROR registering port %d\n",
5439 +                               ports[port]);
5440 +                       fini();
5441 +                       return -EBUSY;
5442 +               }
5443 +               ports_n_c++;
5444 +       }
5445 +       return 0;
5446 +}
5447 +
5448 +/* This function is intentionally _NOT_ defined as __exit, because 
5449 + * it is needed by the init function */
5450 +static void fini(void)
5451 +{
5452 +       int port;
5453 +       for (port = 0; (port < MAX_PORTS) && ports[port]; port++) {
5454 +               DEBUGP("unregistering port %d\n", ports[port]);
5455 +               ip_conntrack_helper_unregister(&rsh_helpers[port]);
5456 +       }
5457 +}
5458 +
5459 +module_init(init);
5460 +module_exit(fini);
5461 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/netfilter/ip_conntrack_rtsp.c linux-2.6.7-rc3/net/ipv4/netfilter/ip_conntrack_rtsp.c
5462 --- linux-2.6.7-rc3.org/net/ipv4/netfilter/ip_conntrack_rtsp.c  1970-01-01 01:00:00.000000000 +0100
5463 +++ linux-2.6.7-rc3/net/ipv4/netfilter/ip_conntrack_rtsp.c      2004-06-08 10:40:46.000000000 +0200
5464 @@ -0,0 +1,507 @@
5465 +/*
5466 + * RTSP extension for IP connection tracking
5467 + * (C) 2003 by Tom Marshall <tmarshall@real.com>
5468 + * based on ip_conntrack_irc.c
5469 + *
5470 + *      This program is free software; you can redistribute it and/or
5471 + *      modify it under the terms of the GNU General Public License
5472 + *      as published by the Free Software Foundation; either version
5473 + *      2 of the License, or (at your option) any later version.
5474 + *
5475 + * Module load syntax:
5476 + *   insmod ip_conntrack_rtsp.o ports=port1,port2,...port<MAX_PORTS>
5477 + *                              max_outstanding=n setup_timeout=secs
5478 + *
5479 + * If no ports are specified, the default will be port 554.
5480 + *
5481 + * With max_outstanding you can define the maximum number of not yet
5482 + * answered SETUP requests per RTSP session (default 8).
5483 + * With setup_timeout you can specify how long the system waits for
5484 + * an expected data channel (default 300 seconds).
5485 + */
5486 +
5487 +#include <linux/config.h>
5488 +#include <linux/module.h>
5489 +#include <linux/netfilter.h>
5490 +#include <linux/ip.h>
5491 +#include <net/checksum.h>
5492 +#include <net/tcp.h>
5493 +
5494 +#include <linux/netfilter_ipv4/lockhelp.h>
5495 +#include <linux/netfilter_ipv4/ip_conntrack_helper.h>
5496 +#include <linux/netfilter_ipv4/ip_conntrack_rtsp.h>
5497 +
5498 +#include <linux/ctype.h>
5499 +#define NF_NEED_STRNCASECMP
5500 +#define NF_NEED_STRTOU16
5501 +#define NF_NEED_STRTOU32
5502 +#define NF_NEED_NEXTLINE
5503 +#include <linux/netfilter_helpers.h>
5504 +#define NF_NEED_MIME_NEXTLINE
5505 +#include <linux/netfilter_mime.h>
5506 +
5507 +#define MAX_SIMUL_SETUP 8 /* XXX: use max_outstanding */
5508 +
5509 +#define INFOP(fmt, args...) printk(KERN_INFO "%s: %s: " fmt, __FILE__, __FUNCTION__ , ## args)
5510 +#ifdef IP_NF_RTSP_DEBUG
5511 +#define DEBUGP(fmt, args...) printk(KERN_DEBUG "%s: %s: " fmt, __FILE__, __FUNCTION__ , ## args)
5512 +#else
5513 +#define DEBUGP(fmt, args...)
5514 +#endif
5515 +
5516 +#define MAX_PORTS 8
5517 +static int ports[MAX_PORTS];
5518 +static int num_ports = 0;
5519 +static int max_outstanding = 8;
5520 +static unsigned int setup_timeout = 300;
5521 +
5522 +MODULE_AUTHOR("Tom Marshall <tmarshall@real.com>");
5523 +MODULE_DESCRIPTION("RTSP connection tracking module");
5524 +MODULE_LICENSE("GPL");
5525 +#ifdef MODULE_PARM
5526 +MODULE_PARM(ports, "1-" __MODULE_STRING(MAX_PORTS) "i");
5527 +MODULE_PARM_DESC(ports, "port numbers of RTSP servers");
5528 +MODULE_PARM(max_outstanding, "i");
5529 +MODULE_PARM_DESC(max_outstanding, "max number of outstanding SETUP requests per RTSP session");
5530 +MODULE_PARM(setup_timeout, "i");
5531 +MODULE_PARM_DESC(setup_timeout, "timeout on for unestablished data channels");
5532 +#endif
5533 +
5534 +DECLARE_LOCK(ip_rtsp_lock);
5535 +struct module* ip_conntrack_rtsp = THIS_MODULE;
5536 +
5537 +/*
5538 + * Max mappings we will allow for one RTSP connection (for RTP, the number
5539 + * of allocated ports is twice this value).  Note that SMIL burns a lot of
5540 + * ports so keep this reasonably high.  If this is too low, you will see a
5541 + * lot of "no free client map entries" messages.
5542 + */
5543 +#define MAX_PORT_MAPS 16
5544 +
5545 +/*** default port list was here in the masq code: 554, 3030, 4040 ***/
5546 +
5547 +#define SKIP_WSPACE(ptr,len,off) while(off < len && isspace(*(ptr+off))) { off++; }
5548 +
5549 +/*
5550 + * Parse an RTSP packet.
5551 + *
5552 + * Returns zero if parsing failed.
5553 + *
5554 + * Parameters:
5555 + *  IN      ptcp        tcp data pointer
5556 + *  IN      tcplen      tcp data len
5557 + *  IN/OUT  ptcpoff     points to current tcp offset
5558 + *  OUT     phdrsoff    set to offset of rtsp headers
5559 + *  OUT     phdrslen    set to length of rtsp headers
5560 + *  OUT     pcseqoff    set to offset of CSeq header
5561 + *  OUT     pcseqlen    set to length of CSeq header
5562 + */
5563 +static int
5564 +rtsp_parse_message(char* ptcp, uint tcplen, uint* ptcpoff,
5565 +                   uint* phdrsoff, uint* phdrslen,
5566 +                   uint* pcseqoff, uint* pcseqlen)
5567 +{
5568 +    uint    entitylen = 0;
5569 +    uint    lineoff;
5570 +    uint    linelen;
5571 +
5572 +    if (!nf_nextline(ptcp, tcplen, ptcpoff, &lineoff, &linelen))
5573 +    {
5574 +        return 0;
5575 +    }
5576 +
5577 +    *phdrsoff = *ptcpoff;
5578 +    while (nf_mime_nextline(ptcp, tcplen, ptcpoff, &lineoff, &linelen))
5579 +    {
5580 +        if (linelen == 0)
5581 +        {
5582 +            if (entitylen > 0)
5583 +            {
5584 +                *ptcpoff += min(entitylen, tcplen - *ptcpoff);
5585 +            }
5586 +            break;
5587 +        }
5588 +        if (lineoff+linelen > tcplen)
5589 +        {
5590 +            INFOP("!! overrun !!\n");
5591 +            break;
5592 +        }
5593 +
5594 +        if (nf_strncasecmp(ptcp+lineoff, "CSeq:", 5) == 0)
5595 +        {
5596 +            *pcseqoff = lineoff;
5597 +            *pcseqlen = linelen;
5598 +        }
5599 +        if (nf_strncasecmp(ptcp+lineoff, "Content-Length:", 15) == 0)
5600 +        {
5601 +            uint off = lineoff+15;
5602 +            SKIP_WSPACE(ptcp+lineoff, linelen, off);
5603 +            nf_strtou32(ptcp+off, &entitylen);
5604 +        }
5605 +    }
5606 +    *phdrslen = (*ptcpoff) - (*phdrsoff);
5607 +
5608 +    return 1;
5609 +}
5610 +
5611 +/*
5612 + * Find lo/hi client ports (if any) in transport header
5613 + * In:
5614 + *   ptcp, tcplen = packet
5615 + *   tranoff, tranlen = buffer to search
5616 + *
5617 + * Out:
5618 + *   pport_lo, pport_hi = lo/hi ports (host endian)
5619 + *
5620 + * Returns nonzero if any client ports found
5621 + *
5622 + * Note: it is valid (and expected) for the client to request multiple
5623 + * transports, so we need to parse the entire line.
5624 + */
5625 +static int
5626 +rtsp_parse_transport(char* ptran, uint tranlen,
5627 +                     struct ip_ct_rtsp_expect* prtspexp)
5628 +{
5629 +    int     rc = 0;
5630 +    uint    off = 0;
5631 +
5632 +    if (tranlen < 10 || !iseol(ptran[tranlen-1]) ||
5633 +        nf_strncasecmp(ptran, "Transport:", 10) != 0)
5634 +    {
5635 +        INFOP("sanity check failed\n");
5636 +        return 0;
5637 +    }
5638 +    DEBUGP("tran='%.*s'\n", (int)tranlen, ptran);
5639 +    off += 10;
5640 +    SKIP_WSPACE(ptran, tranlen, off);
5641 +
5642 +    /* Transport: tran;field;field=val,tran;field;field=val,... */
5643 +    while (off < tranlen)
5644 +    {
5645 +        const char* pparamend;
5646 +        uint        nextparamoff;
5647 +
5648 +        pparamend = memchr(ptran+off, ',', tranlen-off);
5649 +        pparamend = (pparamend == NULL) ? ptran+tranlen : pparamend+1;
5650 +        nextparamoff = pparamend-ptran;
5651 +
5652 +        while (off < nextparamoff)
5653 +        {
5654 +            const char* pfieldend;
5655 +            uint        nextfieldoff;
5656 +
5657 +            pfieldend = memchr(ptran+off, ';', nextparamoff-off);
5658 +            nextfieldoff = (pfieldend == NULL) ? nextparamoff : pfieldend-ptran+1;
5659 +
5660 +            if (strncmp(ptran+off, "client_port=", 12) == 0)
5661 +            {
5662 +                u_int16_t   port;
5663 +                uint        numlen;
5664 +
5665 +                off += 12;
5666 +                numlen = nf_strtou16(ptran+off, &port);
5667 +                off += numlen;
5668 +                if (prtspexp->loport != 0 && prtspexp->loport != port)
5669 +                {
5670 +                    DEBUGP("multiple ports found, port %hu ignored\n", port);
5671 +                }
5672 +                else
5673 +                {
5674 +                    prtspexp->loport = prtspexp->hiport = port;
5675 +                    if (ptran[off] == '-')
5676 +                    {
5677 +                        off++;
5678 +                        numlen = nf_strtou16(ptran+off, &port);
5679 +                        off += numlen;
5680 +                        prtspexp->pbtype = pb_range;
5681 +                        prtspexp->hiport = port;
5682 +
5683 +                        // If we have a range, assume rtp:
5684 +                        // loport must be even, hiport must be loport+1
5685 +                        if ((prtspexp->loport & 0x0001) != 0 ||
5686 +                            prtspexp->hiport != prtspexp->loport+1)
5687 +                        {
5688 +                            DEBUGP("incorrect range: %hu-%hu, correcting\n",
5689 +                                   prtspexp->loport, prtspexp->hiport);
5690 +                            prtspexp->loport &= 0xfffe;
5691 +                            prtspexp->hiport = prtspexp->loport+1;
5692 +                        }
5693 +                    }
5694 +                    else if (ptran[off] == '/')
5695 +                    {
5696 +                        off++;
5697 +                        numlen = nf_strtou16(ptran+off, &port);
5698 +                        off += numlen;
5699 +                        prtspexp->pbtype = pb_discon;
5700 +                        prtspexp->hiport = port;
5701 +                    }
5702 +                    rc = 1;
5703 +                }
5704 +            }
5705 +
5706 +            /*
5707 +             * Note we don't look for the destination parameter here.
5708 +             * If we are using NAT, the NAT module will handle it.  If not,
5709 +             * and the client is sending packets elsewhere, the expectation
5710 +             * will quietly time out.
5711 +             */
5712 +
5713 +            off = nextfieldoff;
5714 +        }
5715 +
5716 +        off = nextparamoff;
5717 +    }
5718 +
5719 +    return rc;
5720 +}
5721 +
5722 +/*** conntrack functions ***/
5723 +
5724 +/* outbound packet: client->server */
5725 +static int
5726 +help_out(const struct iphdr* iph, size_t pktlen,
5727 +                struct ip_conntrack* ct, enum ip_conntrack_info ctinfo)
5728 +{
5729 +    int dir = CTINFO2DIR(ctinfo);   /* = IP_CT_DIR_ORIGINAL */
5730 +    struct  tcphdr* tcph = (void*)iph + iph->ihl * 4;
5731 +    uint    tcplen = pktlen - iph->ihl * 4;
5732 +    char*   pdata = (char*)tcph + tcph->doff * 4;
5733 +    uint    datalen = tcplen - tcph->doff * 4;
5734 +    uint    dataoff = 0;
5735 +
5736 +    struct ip_conntrack_expect exp;
5737 +
5738 +    while (dataoff < datalen)
5739 +    {
5740 +        uint    cmdoff = dataoff;
5741 +        uint    hdrsoff = 0;
5742 +        uint    hdrslen = 0;
5743 +        uint    cseqoff = 0;
5744 +        uint    cseqlen = 0;
5745 +        uint    lineoff = 0;
5746 +        uint    linelen = 0;
5747 +        uint    off;
5748 +        int     rc;
5749 +
5750 +        if (!rtsp_parse_message(pdata, datalen, &dataoff,
5751 +                                &hdrsoff, &hdrslen,
5752 +                                &cseqoff, &cseqlen))
5753 +        {
5754 +            break;      /* not a valid message */
5755 +        }
5756 +
5757 +        if (strncmp(pdata+cmdoff, "SETUP ", 6) != 0)
5758 +        {
5759 +            continue;   /* not a SETUP message */
5760 +        }
5761 +        DEBUGP("found a setup message\n");
5762 +
5763 +        memset(&exp, 0, sizeof(exp));
5764 +
5765 +        off = 0;
5766 +        while (nf_mime_nextline(pdata+hdrsoff, hdrslen, &off,
5767 +                                &lineoff, &linelen))
5768 +        {
5769 +            if (linelen == 0)
5770 +            {
5771 +                break;
5772 +            }
5773 +            if (off > hdrsoff+hdrslen)
5774 +            {
5775 +                INFOP("!! overrun !!");
5776 +                break;
5777 +            }
5778 +
5779 +            if (nf_strncasecmp(pdata+hdrsoff+lineoff, "Transport:", 10) == 0)
5780 +            {
5781 +                rtsp_parse_transport(pdata+hdrsoff+lineoff, linelen,
5782 +                                     &exp.help.exp_rtsp_info);
5783 +            }
5784 +        }
5785 +
5786 +        if (exp.help.exp_rtsp_info.loport == 0)
5787 +        {
5788 +            DEBUGP("no udp transports found\n");
5789 +            continue;   /* no udp transports found */
5790 +        }
5791 +
5792 +        DEBUGP("udp transport found, ports=(%d,%hu,%hu)\n",
5793 +              (int)exp.help.exp_rtsp_info.pbtype,
5794 +              exp.help.exp_rtsp_info.loport,
5795 +              exp.help.exp_rtsp_info.hiport);
5796 +
5797 +        LOCK_BH(&ip_rtsp_lock);
5798 +        exp.seq = ntohl(tcph->seq) + hdrsoff; /* mark all the headers */
5799 +        exp.help.exp_rtsp_info.len = hdrslen;
5800 +
5801 +        exp.tuple.src.ip = ct->tuplehash[!dir].tuple.src.ip;
5802 +        exp.mask.src.ip  = 0xffffffff;
5803 +        exp.tuple.dst.ip = ct->tuplehash[dir].tuple.src.ip;
5804 +        exp.mask.dst.ip  = 0xffffffff;
5805 +        exp.tuple.dst.u.udp.port = exp.help.exp_rtsp_info.loport;
5806 +        exp.mask.dst.u.udp.port  = (exp.help.exp_rtsp_info.pbtype == pb_range) ? 0xfffe : 0xffff;
5807 +        exp.tuple.dst.protonum = IPPROTO_UDP;
5808 +        exp.mask.dst.protonum  = 0xffff;
5809 +
5810 +        DEBUGP("expect_related %u.%u.%u.%u:%u-%u.%u.%u.%u:%u\n",
5811 +                NIPQUAD(exp.tuple.src.ip),
5812 +                ntohs(exp.tuple.src.u.tcp.port),
5813 +                NIPQUAD(exp.tuple.dst.ip),
5814 +                ntohs(exp.tuple.dst.u.tcp.port));
5815 +
5816 +        /* pass the request off to the nat helper */
5817 +        rc = ip_conntrack_expect_related(&exp, ct);
5818 +        UNLOCK_BH(&ip_rtsp_lock);
5819 +        if (rc == 0)
5820 +        {
5821 +            DEBUGP("ip_conntrack_expect_related succeeded\n");
5822 +        }
5823 +        else
5824 +        {
5825 +            INFOP("ip_conntrack_expect_related failed (%d)\n", rc);
5826 +        }
5827 +    }
5828 +
5829 +    return NF_ACCEPT;
5830 +}
5831 +
5832 +/* inbound packet: server->client */
5833 +static int
5834 +help_in(const struct iphdr* iph, size_t pktlen,
5835 +                struct ip_conntrack* ct, enum ip_conntrack_info ctinfo)
5836 +{
5837 +    return NF_ACCEPT;
5838 +}
5839 +
5840 +static int
5841 +help(const struct iphdr* iph, size_t pktlen,
5842 +                struct ip_conntrack* ct, enum ip_conntrack_info ctinfo)
5843 +{
5844 +    /* tcplen not negative guarenteed by ip_conntrack_tcp.c */
5845 +    struct tcphdr* tcph = (void*)iph + iph->ihl * 4;
5846 +    u_int32_t tcplen = pktlen - iph->ihl * 4;
5847 +
5848 +    /* Until there's been traffic both ways, don't look in packets. */
5849 +    if (ctinfo != IP_CT_ESTABLISHED && ctinfo != IP_CT_ESTABLISHED + IP_CT_IS_REPLY)
5850 +    {
5851 +        DEBUGP("conntrackinfo = %u\n", ctinfo);
5852 +        return NF_ACCEPT;
5853 +    }
5854 +
5855 +    /* Not whole TCP header? */
5856 +    if (tcplen < sizeof(struct tcphdr) || tcplen < tcph->doff * 4)
5857 +    {
5858 +        DEBUGP("tcplen = %u\n", (unsigned)tcplen);
5859 +        return NF_ACCEPT;
5860 +    }
5861 +
5862 +    /* Checksum invalid?  Ignore. */
5863 +    /* FIXME: Source route IP option packets --RR */
5864 +    if (tcp_v4_check(tcph, tcplen, iph->saddr, iph->daddr,
5865 +                     csum_partial((char*)tcph, tcplen, 0)))
5866 +    {
5867 +        DEBUGP("bad csum: %p %u %u.%u.%u.%u %u.%u.%u.%u\n",
5868 +               tcph, tcplen, NIPQUAD(iph->saddr), NIPQUAD(iph->daddr));
5869 +        return NF_ACCEPT;
5870 +    }
5871 +
5872 +    switch (CTINFO2DIR(ctinfo))
5873 +    {
5874 +    case IP_CT_DIR_ORIGINAL:
5875 +        help_out(iph, pktlen, ct, ctinfo);
5876 +        break;
5877 +    case IP_CT_DIR_REPLY:
5878 +        help_in(iph, pktlen, ct, ctinfo);
5879 +        break;
5880 +    }
5881 +
5882 +    return NF_ACCEPT;
5883 +}
5884 +
5885 +static struct ip_conntrack_helper rtsp_helpers[MAX_PORTS];
5886 +static char rtsp_names[MAX_PORTS][10];
5887 +
5888 +/* This function is intentionally _NOT_ defined as __exit */
5889 +static void
5890 +fini(void)
5891 +{
5892 +    int i;
5893 +    for (i = 0; i < num_ports; i++)
5894 +    {
5895 +        DEBUGP("unregistering port %d\n", ports[i]);
5896 +        ip_conntrack_helper_unregister(&rtsp_helpers[i]);
5897 +    }
5898 +}
5899 +
5900 +static int __init
5901 +init(void)
5902 +{
5903 +    int i, ret;
5904 +    struct ip_conntrack_helper *hlpr;
5905 +    char *tmpname;
5906 +
5907 +    printk("ip_conntrack_rtsp v" IP_NF_RTSP_VERSION " loading\n");
5908 +
5909 +    if (max_outstanding < 1)
5910 +    {
5911 +        printk("ip_conntrack_rtsp: max_outstanding must be a positive integer\n");
5912 +        return -EBUSY;
5913 +    }
5914 +    if (setup_timeout < 0)
5915 +    {
5916 +        printk("ip_conntrack_rtsp: setup_timeout must be a positive integer\n");
5917 +        return -EBUSY;
5918 +    }
5919 +
5920 +    /* If no port given, default to standard rtsp port */
5921 +    if (ports[0] == 0)
5922 +    {
5923 +        ports[0] = RTSP_PORT;
5924 +    }
5925 +
5926 +    for (i = 0; (i < MAX_PORTS) && ports[i]; i++)
5927 +    {
5928 +        hlpr = &rtsp_helpers[i];
5929 +        memset(hlpr, 0, sizeof(struct ip_conntrack_helper));
5930 +        hlpr->tuple.src.u.tcp.port = htons(ports[i]);
5931 +        hlpr->tuple.dst.protonum = IPPROTO_TCP;
5932 +        hlpr->mask.src.u.tcp.port = 0xFFFF;
5933 +        hlpr->mask.dst.protonum = 0xFFFF;
5934 +        hlpr->max_expected = max_outstanding;
5935 +        hlpr->timeout = setup_timeout;
5936 +        hlpr->flags = IP_CT_HELPER_F_REUSE_EXPECT;
5937 +        hlpr->me = ip_conntrack_rtsp;
5938 +        hlpr->help = help;
5939 +
5940 +        tmpname = &rtsp_names[i][0];
5941 +        if (ports[i] == RTSP_PORT)
5942 +        {
5943 +            sprintf(tmpname, "rtsp");
5944 +        }
5945 +        else
5946 +        {
5947 +            sprintf(tmpname, "rtsp-%d", i);
5948 +        }
5949 +        hlpr->name = tmpname;
5950 +
5951 +        DEBUGP("port #%d: %d\n", i, ports[i]);
5952 +
5953 +        ret = ip_conntrack_helper_register(hlpr);
5954 +
5955 +        if (ret)
5956 +        {
5957 +            printk("ip_conntrack_rtsp: ERROR registering port %d\n", ports[i]);
5958 +            fini();
5959 +            return -EBUSY;
5960 +        }
5961 +        num_ports++;
5962 +    }
5963 +    return 0;
5964 +}
5965 +
5966 +#ifdef CONFIG_IP_NF_NAT_NEEDED
5967 +EXPORT_SYMBOL(ip_rtsp_lock);
5968 +#endif
5969 +
5970 +module_init(init);
5971 +module_exit(fini);
5972 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/netfilter/ip_conntrack_standalone.c linux-2.6.7-rc3/net/ipv4/netfilter/ip_conntrack_standalone.c
5973 --- linux-2.6.7-rc3.org/net/ipv4/netfilter/ip_conntrack_standalone.c    2004-06-07 21:14:11.000000000 +0200
5974 +++ linux-2.6.7-rc3/net/ipv4/netfilter/ip_conntrack_standalone.c        2004-06-08 10:38:45.000000000 +0200
5975 @@ -110,6 +110,9 @@
5976                 len += sprintf(buffer + len, "[ASSURED] ");
5977         len += sprintf(buffer + len, "use=%u ",
5978                        atomic_read(&conntrack->ct_general.use));
5979 +#if defined(CONFIG_IP_NF_CONNTRACK_MARK)
5980 +       len += sprintf(buffer + len, "mark=%ld ", conntrack->mark);
5981 +#endif
5982         len += sprintf(buffer + len, "\n");
5983  
5984         return len;
5985 @@ -502,7 +505,7 @@
5986         if (ret < 0)
5987                 goto cleanup_nothing;
5988  
5989 -       proc = proc_net_create("ip_conntrack",0,list_conntracks);
5990 +       proc = proc_net_create("ip_conntrack", 0440, list_conntracks);
5991         if (!proc) goto cleanup_init;
5992         proc->owner = THIS_MODULE;
5993  
5994 @@ -633,6 +636,7 @@
5995  EXPORT_SYMBOL(ip_conntrack_alter_reply);
5996  EXPORT_SYMBOL(ip_conntrack_destroyed);
5997  EXPORT_SYMBOL(ip_conntrack_get);
5998 +EXPORT_SYMBOL(__ip_conntrack_confirm);
5999  EXPORT_SYMBOL(need_ip_conntrack);
6000  EXPORT_SYMBOL(ip_conntrack_helper_register);
6001  EXPORT_SYMBOL(ip_conntrack_helper_unregister);
6002 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/netfilter/ip_conntrack_talk.c linux-2.6.7-rc3/net/ipv4/netfilter/ip_conntrack_talk.c
6003 --- linux-2.6.7-rc3.org/net/ipv4/netfilter/ip_conntrack_talk.c  1970-01-01 01:00:00.000000000 +0100
6004 +++ linux-2.6.7-rc3/net/ipv4/netfilter/ip_conntrack_talk.c      2004-06-08 10:41:27.000000000 +0200
6005 @@ -0,0 +1,360 @@
6006 +/* 
6007 + * talk extension for IP connection tracking. 
6008 + * Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
6009 + *
6010 + *      This program is free software; you can redistribute it and/or
6011 + *      modify it under the terms of the GNU General Public License
6012 + *      as published by the Free Software Foundation; either version
6013 + *      2 of the License, or (at your option) any later version.
6014 + **
6015 + *     Module load syntax:
6016 + *     insmod ip_nat_talk.o talk=[0|1] ntalk=[0|1] ntalk2=[01]
6017 + *
6018 + *             talk=[0|1]      disable|enable old talk support
6019 + *            ntalk=[0|1]      disable|enable ntalk support
6020 + *           ntalk2=[0|1]      disable|enable ntalk2 support
6021 + *
6022 + *     The default is talk=1 ntalk=1 ntalk2=1
6023 + *
6024 + *     The helper does not support simultaneous talk requests.
6025 + **
6026 + *
6027 + *             ASCII art on talk protocols
6028 + *     
6029 + *     
6030 + *     caller server               callee server
6031 + *             |     \           /
6032 + *             |       \       /
6033 + *             |         \   /
6034 + *             |           /  
6035 + *             |         /   \
6036 + *           2 |     1 /       \ 3
6037 + *     caller client  ----------- callee client
6038 + *                              4
6039 + *
6040 + *     1. caller client <-> callee server: LOOK_UP, then ANNOUNCE invitation 
6041 + *    ( 2. caller client <-> caller server: LEAVE_INVITE to server )
6042 + *     3. callee client <-> caller server: LOOK_UP invitation
6043 + *     4. callee client <-> caller client: talk data channel
6044 + *
6045 + * [1]: M. Hunter, talk: a historical protocol for interactive communication
6046 + *      draft-hunter-talk-00.txt
6047 + * [2]: D.B. Chapman, E.D. Zwicky: Building Internet Firewalls (O'Reilly)      
6048 + */
6049 +#include <linux/config.h>
6050 +#include <linux/module.h>
6051 +#include <linux/netfilter.h>
6052 +#include <linux/ip.h>
6053 +#include <net/checksum.h>
6054 +#include <net/udp.h>
6055 +
6056 +#include <linux/netfilter_ipv4/lockhelp.h>
6057 +#include <linux/netfilter_ipv4/ip_conntrack.h>
6058 +#include <linux/netfilter_ipv4/ip_conntrack_core.h>
6059 +#include <linux/netfilter_ipv4/ip_conntrack_helper.h>
6060 +#include <linux/netfilter_ipv4/ip_conntrack_talk.h>
6061 +
6062 +/* Default all talk protocols are supported */
6063 +static int talk = 1;
6064 +static int ntalk = 1;
6065 +static int ntalk2 = 1;
6066 +MODULE_AUTHOR("Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>");
6067 +MODULE_DESCRIPTION("talk connection tracking module");
6068 +MODULE_LICENSE("GPL");
6069 +#ifdef MODULE_PARM
6070 +MODULE_PARM(talk, "i");
6071 +MODULE_PARM_DESC(talk, "support (old) talk protocol");
6072 +MODULE_PARM(ntalk, "i");
6073 +MODULE_PARM_DESC(ntalk, "support ntalk protocol");
6074 +MODULE_PARM(ntalk2, "i");
6075 +MODULE_PARM_DESC(ntalk2, "support ntalk2 protocol");
6076 +#endif
6077 +
6078 +DECLARE_LOCK(ip_talk_lock);
6079 +struct module *ip_conntrack_talk = THIS_MODULE;
6080 +
6081 +#if 0
6082 +#define DEBUGP printk
6083 +#else
6084 +#define DEBUGP(format, args...)
6085 +#endif
6086 +
6087 +static int talk_expect(struct ip_conntrack *ct);
6088 +static int ntalk_expect(struct ip_conntrack *ct);
6089 +
6090 +static int (*talk_expectfn[2])(struct ip_conntrack *ct) = {talk_expect, ntalk_expect};
6091 +
6092 +static int talk_help_response(const struct iphdr *iph, size_t len,
6093 +                             struct ip_conntrack *ct,
6094 +                             enum ip_conntrack_info ctinfo,
6095 +                             int talk_port,
6096 +                             u_char mode,
6097 +                             u_char type,
6098 +                             u_char answer,
6099 +                             struct talk_addr *addr)
6100 +{
6101 +       int dir = CTINFO2DIR(ctinfo);
6102 +       struct ip_conntrack_expect expect, *exp = &expect;
6103 +       struct ip_ct_talk_expect *exp_talk_info = &exp->help.exp_talk_info;
6104 +
6105 +       DEBUGP("ip_ct_talk_help_response: %u.%u.%u.%u:%u, type %d answer %d\n",
6106 +               NIPQUAD(addr->ta_addr), ntohs(addr->ta_port),
6107 +               type, answer);
6108 +
6109 +       if (!(answer == SUCCESS && type == mode))
6110 +               return NF_ACCEPT;
6111 +       
6112 +       memset(&expect, 0, sizeof(expect));
6113 +       
6114 +       if (type == ANNOUNCE) {
6115 +
6116 +               DEBUGP("ip_ct_talk_help_response: ANNOUNCE\n");
6117 +
6118 +               /* update the talk info */
6119 +               LOCK_BH(&ip_talk_lock);
6120 +               exp_talk_info->port = htons(talk_port);
6121 +
6122 +               /* expect callee client -> caller server message */
6123 +               exp->tuple = ((struct ip_conntrack_tuple)
6124 +                       { { ct->tuplehash[dir].tuple.src.ip,
6125 +                           { 0 } },
6126 +                         { ct->tuplehash[dir].tuple.dst.ip,
6127 +                           { .tcp = { htons(talk_port) } },
6128 +                           IPPROTO_UDP }});
6129 +               exp->mask = ((struct ip_conntrack_tuple)
6130 +                       { { 0xFFFFFFFF, { 0 } },
6131 +                         { 0xFFFFFFFF, { .tcp = { 0xFFFF } }, 0xFFFF }});
6132 +               
6133 +               exp->expectfn = talk_expectfn[talk_port - TALK_PORT];
6134 +
6135 +               DEBUGP("ip_ct_talk_help_response: callee client %u.%u.%u.%u:%u -> caller daemon %u.%u.%u.%u:%u!\n",
6136 +                      NIPQUAD(exp->tuple.src.ip), ntohs(exp->tuple.src.u.udp.port),
6137 +                      NIPQUAD(exp->tuple.dst.ip), ntohs(exp->tuple.dst.u.udp.port));
6138 +
6139 +               /* Ignore failure; should only happen with NAT */
6140 +               ip_conntrack_expect_related(&expect, ct);
6141 +               UNLOCK_BH(&ip_talk_lock);
6142 +       }
6143 +       if (type == LOOK_UP) {
6144 +
6145 +               DEBUGP("ip_ct_talk_help_response: LOOK_UP\n");
6146 +
6147 +               /* update the talk info */
6148 +               LOCK_BH(&ip_talk_lock);
6149 +               exp_talk_info->port = addr->ta_port;
6150 +
6151 +               /* expect callee client -> caller client connection */
6152 +               exp->tuple = ((struct ip_conntrack_tuple)
6153 +                       { { ct->tuplehash[!dir].tuple.src.ip,
6154 +                           { 0 } },
6155 +                         { addr->ta_addr,
6156 +                           { addr->ta_port },
6157 +                           IPPROTO_TCP }});
6158 +               exp->mask = ((struct ip_conntrack_tuple)
6159 +                       { { 0xFFFFFFFF, { 0 } },
6160 +                         { 0xFFFFFFFF, { 0xFFFF }, 0xFFFF }});
6161 +               
6162 +               exp->expectfn = NULL;
6163 +               
6164 +               DEBUGP("ip_ct_talk_help_response: callee client %u.%u.%u.%u:%u -> caller client %u.%u.%u.%u:%u!\n",
6165 +                      NIPQUAD(exp->tuple.src.ip), ntohs(exp->tuple.src.u.tcp.port),
6166 +                      NIPQUAD(exp->tuple.dst.ip), ntohs(exp->tuple.dst.u.tcp.port));
6167 +
6168 +               /* Ignore failure; should only happen with NAT */
6169 +               ip_conntrack_expect_related(&expect, ct);
6170 +               UNLOCK_BH(&ip_talk_lock);
6171 +       }
6172 +                   
6173 +       return NF_ACCEPT;
6174 +}
6175 +
6176 +/* FIXME: This should be in userspace.  Later. */
6177 +static int talk_help(const struct iphdr *iph, size_t len,
6178 +                    struct ip_conntrack *ct,
6179 +                    enum ip_conntrack_info ctinfo,
6180 +                    int talk_port,
6181 +                    u_char mode)
6182 +{
6183 +       struct udphdr *udph = (void *)iph + iph->ihl * 4;
6184 +       const char *data = (const char *)udph + sizeof(struct udphdr);
6185 +       int dir = CTINFO2DIR(ctinfo);
6186 +       size_t udplen;
6187 +
6188 +       DEBUGP("ip_ct_talk_help: help entered\n");
6189 +
6190 +       /* Until there's been traffic both ways, don't look in packets. */
6191 +       if (ctinfo != IP_CT_ESTABLISHED
6192 +           && ctinfo != IP_CT_ESTABLISHED + IP_CT_IS_REPLY) {
6193 +               DEBUGP("ip_ct_talk_help: Conntrackinfo = %u\n", ctinfo);
6194 +               return NF_ACCEPT;
6195 +       }
6196 +
6197 +       /* Not whole UDP header? */
6198 +       udplen = len - iph->ihl * 4;
6199 +       if (udplen < sizeof(struct udphdr)) {
6200 +               DEBUGP("ip_ct_talk_help: too short for udph, udplen = %u\n", (unsigned)udplen);
6201 +               return NF_ACCEPT;
6202 +       }
6203 +
6204 +       /* Checksum invalid?  Ignore. */
6205 +       /* FIXME: Source route IP option packets --RR */
6206 +       if (csum_tcpudp_magic(iph->saddr, iph->daddr, udplen, IPPROTO_UDP,
6207 +                             csum_partial((char *)udph, udplen, 0))) {
6208 +               DEBUGP("ip_ct_talk_help: bad csum: %p %u %u.%u.%u.%u %u.%u.%u.%u\n",
6209 +                      udph, udplen, NIPQUAD(iph->saddr),
6210 +                      NIPQUAD(iph->daddr));
6211 +               return NF_ACCEPT;
6212 +       }
6213 +       
6214 +       DEBUGP("ip_ct_talk_help: %u.%u.%u.%u:%u->%u.%u.%u.%u:%u\n",
6215 +               NIPQUAD(iph->saddr), ntohs(udph->source), NIPQUAD(iph->daddr), ntohs(udph->dest));
6216 +
6217 +       if (dir == IP_CT_DIR_ORIGINAL)
6218 +               return NF_ACCEPT;
6219 +               
6220 +       if (talk_port == TALK_PORT
6221 +           && udplen == sizeof(struct udphdr) + sizeof(struct talk_response))
6222 +               return talk_help_response(iph, len, ct, ctinfo, talk_port, mode,
6223 +                                         ((struct talk_response *)data)->type, 
6224 +                                         ((struct talk_response *)data)->answer,
6225 +                                         &(((struct talk_response *)data)->addr));
6226 +       else if (talk_port == NTALK_PORT
6227 +                 && ntalk
6228 +                 && udplen == sizeof(struct udphdr) + sizeof(struct ntalk_response)
6229 +                 && ((struct ntalk_response *)data)->vers == NTALK_VERSION)
6230 +               return talk_help_response(iph, len, ct, ctinfo, talk_port, mode,
6231 +                                         ((struct ntalk_response *)data)->type, 
6232 +                                         ((struct ntalk_response *)data)->answer,
6233 +                                         &(((struct ntalk_response *)data)->addr));
6234 +       else if (talk_port == NTALK_PORT
6235 +                && ntalk2
6236 +                && udplen >= sizeof(struct udphdr) + sizeof(struct ntalk2_response)
6237 +                && ((struct ntalk2_response *)data)->vers == NTALK2_VERSION)
6238 +               return talk_help_response(iph, len, ct, ctinfo, talk_port, mode,
6239 +                                         ((struct ntalk2_response *)data)->type, 
6240 +                                         ((struct ntalk2_response *)data)->answer,
6241 +                                         &(((struct ntalk2_response *)data)->addr));
6242 +       else {
6243 +               DEBUGP("ip_ct_talk_help: not ntalk/ntalk2 response, datalen %u != %u or %u + max 256\n", 
6244 +                      (unsigned)udplen - sizeof(struct udphdr), 
6245 +                      sizeof(struct ntalk_response), sizeof(struct ntalk2_response));
6246 +               return NF_ACCEPT;
6247 +       }
6248 +}
6249 +
6250 +static int lookup_help(const struct iphdr *iph, size_t len,
6251 +                      struct ip_conntrack *ct, enum ip_conntrack_info ctinfo)
6252 +{
6253 +       return talk_help(iph, len, ct, ctinfo, TALK_PORT, LOOK_UP);
6254 +}
6255 +
6256 +static int lookup_nhelp(const struct iphdr *iph, size_t len,
6257 +                       struct ip_conntrack *ct, enum ip_conntrack_info ctinfo)
6258 +{
6259 +       return talk_help(iph, len, ct, ctinfo, NTALK_PORT, LOOK_UP);
6260 +}
6261 +
6262 +static struct ip_conntrack_helper lookup_helpers[2] = 
6263 +       { { { NULL, NULL },
6264 +           "talk",                                     /* name */
6265 +           0,                                          /* flags */
6266 +           NULL,                                       /* module */
6267 +           1,                                          /* max_expected */
6268 +           240,                                        /* timeout */
6269 +            { { 0, { __constant_htons(TALK_PORT) } },  /* tuple */
6270 +             { 0, { 0 }, IPPROTO_UDP } },
6271 +           { { 0, { 0xFFFF } },                        /* mask */
6272 +             { 0, { 0 }, 0xFFFF } },
6273 +           lookup_help },                              /* helper */
6274 +          { { NULL, NULL },
6275 +            "ntalk",                                   /* name */
6276 +           0,                                          /* flags */
6277 +           NULL,                                       /* module */
6278 +           1,                                          /* max_expected */
6279 +           240,                                        /* timeout */
6280 +           { { 0, { __constant_htons(NTALK_PORT) } },  /* tuple */
6281 +             { 0, { 0 }, IPPROTO_UDP } },
6282 +           { { 0, { 0xFFFF } },                        /* mask */
6283 +             { 0, { 0 }, 0xFFFF } },
6284 +           lookup_nhelp }                              /* helper */
6285 +        };
6286 +
6287 +static int talk_expect(struct ip_conntrack *ct)
6288 +{
6289 +       DEBUGP("ip_conntrack_talk: calling talk_expectfn for ct %p\n", ct);
6290 +       WRITE_LOCK(&ip_conntrack_lock);
6291 +       ct->helper = &lookup_helpers[0];
6292 +       WRITE_UNLOCK(&ip_conntrack_lock);
6293 +        
6294 +       return NF_ACCEPT;       /* unused */
6295 +}
6296 +
6297 +static int ntalk_expect(struct ip_conntrack *ct)
6298 +{
6299 +       DEBUGP("ip_conntrack_talk: calling ntalk_expectfn for ct %p\n", ct);
6300 +       WRITE_LOCK(&ip_conntrack_lock);
6301 +       ct->helper = &lookup_helpers[1];
6302 +       WRITE_UNLOCK(&ip_conntrack_lock);
6303 +        
6304 +       return NF_ACCEPT;       /* unused */
6305 +}
6306 +
6307 +static int help(const struct iphdr *iph, size_t len,
6308 +               struct ip_conntrack *ct, enum ip_conntrack_info ctinfo)
6309 +{
6310 +       return talk_help(iph, len, ct, ctinfo, TALK_PORT, ANNOUNCE);
6311 +}
6312 +
6313 +static int nhelp(const struct iphdr *iph, size_t len,
6314 +                struct ip_conntrack *ct, enum ip_conntrack_info ctinfo)
6315 +{
6316 +       return talk_help(iph, len, ct, ctinfo, NTALK_PORT, ANNOUNCE);
6317 +}
6318 +
6319 +static struct ip_conntrack_helper talk_helpers[2] = 
6320 +       { { { NULL, NULL },
6321 +           "talk",                                     /* name */
6322 +           0,                                          /* flags */
6323 +           THIS_MODULE,                                /* module */
6324 +           1,                                          /* max_expected */
6325 +           240,                                        /* timeout */
6326 +           { { 0, { __constant_htons(TALK_PORT) } },   /* tuple */
6327 +             { 0, { 0 }, IPPROTO_UDP } },
6328 +           { { 0, { 0xFFFF } },                        /* mask */
6329 +             { 0, { 0 }, 0xFFFF } },
6330 +           help },                                     /* helper */
6331 +          { { NULL, NULL },
6332 +           "ntalk",                                    /* name */
6333 +           0,                                          /* flags */
6334 +           THIS_MODULE,                                /* module */
6335 +           1,                                          /* max_expected */
6336 +           240,                                        /* timeout */
6337 +           { { 0, { __constant_htons(NTALK_PORT) } },  /* tuple */
6338 +             { 0, { 0 }, IPPROTO_UDP } },
6339 +           { { 0, { 0xFFFF } },                        /* mask */
6340 +             { 0, { 0 }, 0xFFFF } },
6341 +           nhelp }                                     /* helper */
6342 +       };
6343 +
6344 +static int __init init(void)
6345 +{
6346 +       if (talk > 0)
6347 +               ip_conntrack_helper_register(&talk_helpers[0]);
6348 +       if (ntalk > 0 || ntalk2 > 0)
6349 +               ip_conntrack_helper_register(&talk_helpers[1]);
6350 +               
6351 +       return 0;
6352 +}
6353 +
6354 +static void __exit fini(void)
6355 +{
6356 +       if (talk > 0)
6357 +               ip_conntrack_helper_unregister(&talk_helpers[0]);
6358 +       if (ntalk > 0 || ntalk2 > 0)
6359 +               ip_conntrack_helper_unregister(&talk_helpers[1]);
6360 +}
6361 +
6362 +EXPORT_SYMBOL(ip_talk_lock);
6363 +
6364 +module_init(init);
6365 +module_exit(fini);
6366 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/netfilter/ip_nat_core.c linux-2.6.7-rc3/net/ipv4/netfilter/ip_nat_core.c
6367 --- linux-2.6.7-rc3.org/net/ipv4/netfilter/ip_nat_core.c        2004-06-07 21:13:39.000000000 +0200
6368 +++ linux-2.6.7-rc3/net/ipv4/netfilter/ip_nat_core.c    2004-06-08 10:30:32.000000000 +0200
6369 @@ -816,7 +816,7 @@
6370  
6371                 /* Have to grab read lock before sibling_list traversal */
6372                 READ_LOCK(&ip_conntrack_lock);
6373 -               list_for_each(cur_item, &ct->sibling_list) { 
6374 +               list_for_each_prev(cur_item, &ct->sibling_list) { 
6375                         exp = list_entry(cur_item, struct ip_conntrack_expect, 
6376                                          expected_list);
6377                                          
6378 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/netfilter/ip_nat_h323.c linux-2.6.7-rc3/net/ipv4/netfilter/ip_nat_h323.c
6379 --- linux-2.6.7-rc3.org/net/ipv4/netfilter/ip_nat_h323.c        1970-01-01 01:00:00.000000000 +0100
6380 +++ linux-2.6.7-rc3/net/ipv4/netfilter/ip_nat_h323.c    2004-06-08 10:38:40.000000000 +0200
6381 @@ -0,0 +1,419 @@
6382 +/* 
6383 + * H.323 'brute force' extension for NAT alteration. 
6384 + * Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
6385 + *
6386 + * Based on ip_masq_h323.c for 2.2 kernels from CoRiTel, Sofia project.
6387 + * (http://www.coritel.it/projects/sofia/nat.html)
6388 + * Uses Sampsa Ranta's excellent idea on using expectfn to 'bind'
6389 + * the unregistered helpers to the conntrack entries.
6390 + */
6391 +
6392 +
6393 +#include <linux/module.h>
6394 +#include <linux/netfilter.h>
6395 +#include <linux/ip.h>
6396 +#include <net/checksum.h>
6397 +#include <net/tcp.h>
6398 +
6399 +#include <linux/netfilter_ipv4/lockhelp.h>
6400 +#include <linux/netfilter_ipv4/ip_nat.h>
6401 +#include <linux/netfilter_ipv4/ip_nat_helper.h>
6402 +#include <linux/netfilter_ipv4/ip_nat_rule.h>
6403 +#include <linux/netfilter_ipv4/ip_conntrack_tuple.h>
6404 +#include <linux/netfilter_ipv4/ip_conntrack_helper.h>
6405 +#include <linux/netfilter_ipv4/ip_conntrack_h323.h>
6406 +
6407 +MODULE_AUTHOR("Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>");
6408 +MODULE_DESCRIPTION("H.323 'brute force' connection tracking module");
6409 +MODULE_LICENSE("GPL");
6410 +
6411 +DECLARE_LOCK_EXTERN(ip_h323_lock);
6412 +struct module *ip_nat_h323 = THIS_MODULE;
6413 +
6414 +#if 0
6415 +#define DEBUGP printk
6416 +#else
6417 +#define DEBUGP(format, args...)
6418 +#endif
6419 +
6420 +/* FIXME: Time out? --RR */
6421 +
6422 +static unsigned int 
6423 +h225_nat_expected(struct sk_buff **pskb,
6424 +                 unsigned int hooknum,
6425 +                 struct ip_conntrack *ct,
6426 +                 struct ip_nat_info *info);
6427 +
6428 +static unsigned int h225_nat_help(struct ip_conntrack *ct,
6429 +                                 struct ip_conntrack_expect *exp,
6430 +                                 struct ip_nat_info *info,
6431 +                                 enum ip_conntrack_info ctinfo,
6432 +                                 unsigned int hooknum,
6433 +                                 struct sk_buff **pskb);
6434 +                 
6435 +static struct ip_nat_helper h245 = 
6436 +       { { NULL, NULL },
6437 +          "H.245",                             /* name */
6438 +         0,                                    /* flags */
6439 +         NULL,                                 /* module */
6440 +         { { 0, { 0 } },                       /* tuple */
6441 +           { 0, { 0 }, IPPROTO_TCP } },
6442 +         { { 0, { 0xFFFF } },                  /* mask */
6443 +           { 0, { 0 }, 0xFFFF } },
6444 +         h225_nat_help,                        /* helper */
6445 +         h225_nat_expected                     /* expectfn */
6446 +       };
6447 +
6448 +static unsigned int
6449 +h225_nat_expected(struct sk_buff **pskb,
6450 +                 unsigned int hooknum,
6451 +                 struct ip_conntrack *ct,
6452 +                 struct ip_nat_info *info)
6453 +{
6454 +       struct ip_nat_multi_range mr;
6455 +       u_int32_t newdstip, newsrcip, newip;
6456 +       u_int16_t port;
6457 +       struct ip_ct_h225_expect *exp_info;
6458 +       struct ip_ct_h225_master *master_info;
6459 +       struct ip_conntrack *master = master_ct(ct);
6460 +       unsigned int is_h225, ret;
6461 +       
6462 +       IP_NF_ASSERT(info);
6463 +       IP_NF_ASSERT(master);
6464 +
6465 +       IP_NF_ASSERT(!(info->initialized & (1<<HOOK2MANIP(hooknum))));
6466 +
6467 +       DEBUGP("h225_nat_expected: We have a connection!\n");
6468 +       master_info = &ct->master->expectant->help.ct_h225_info;
6469 +       exp_info = &ct->master->help.exp_h225_info;
6470 +
6471 +       LOCK_BH(&ip_h323_lock);
6472 +
6473 +       DEBUGP("master: ");
6474 +       DUMP_TUPLE(&master->tuplehash[IP_CT_DIR_ORIGINAL].tuple);
6475 +       DUMP_TUPLE(&master->tuplehash[IP_CT_DIR_REPLY].tuple);
6476 +       DEBUGP("conntrack: ");
6477 +       DUMP_TUPLE(&ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple);
6478 +       if (exp_info->dir == IP_CT_DIR_ORIGINAL) {
6479 +               /* Make connection go to the client. */
6480 +               newdstip = master->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.ip;
6481 +               newsrcip = master->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.ip;
6482 +               DEBUGP("h225_nat_expected: %u.%u.%u.%u->%u.%u.%u.%u (to client)\n",
6483 +                      NIPQUAD(newsrcip), NIPQUAD(newdstip));
6484 +       } else {
6485 +               /* Make the connection go to the server */
6486 +               newdstip = master->tuplehash[IP_CT_DIR_REPLY].tuple.src.ip;
6487 +               newsrcip = master->tuplehash[IP_CT_DIR_REPLY].tuple.dst.ip;
6488 +               DEBUGP("h225_nat_expected: %u.%u.%u.%u->%u.%u.%u.%u (to server)\n",
6489 +                      NIPQUAD(newsrcip), NIPQUAD(newdstip));
6490 +       }
6491 +       port = exp_info->port;
6492 +       is_h225 = master_info->is_h225 == H225_PORT;
6493 +       UNLOCK_BH(&ip_h323_lock);
6494 +       
6495 +       if (HOOK2MANIP(hooknum) == IP_NAT_MANIP_SRC)
6496 +               newip = newsrcip;
6497 +       else
6498 +               newip = newdstip;
6499 +
6500 +       DEBUGP("h225_nat_expected: IP to %u.%u.%u.%u\n", NIPQUAD(newip));
6501 +
6502 +       mr.rangesize = 1;
6503 +       /* We don't want to manip the per-protocol, just the IPs... */
6504 +       mr.range[0].flags = IP_NAT_RANGE_MAP_IPS;
6505 +       mr.range[0].min_ip = mr.range[0].max_ip = newip;
6506 +
6507 +       /* ... unless we're doing a MANIP_DST, in which case, make
6508 +          sure we map to the correct port */
6509 +       if (HOOK2MANIP(hooknum) == IP_NAT_MANIP_DST) {
6510 +               mr.range[0].flags |= IP_NAT_RANGE_PROTO_SPECIFIED;
6511 +               mr.range[0].min = mr.range[0].max
6512 +                       = ((union ip_conntrack_manip_proto)
6513 +                               { .tcp = { port } });
6514 +       }
6515 +
6516 +       ret = ip_nat_setup_info(ct, &mr, hooknum);
6517 +       
6518 +       if (is_h225) {
6519 +               DEBUGP("h225_nat_expected: H.225, setting NAT helper for %p\n", ct);
6520 +               /* NAT expectfn called with ip_nat_lock write-locked */
6521 +               info->helper = &h245;
6522 +       }
6523 +       return ret;
6524 +}
6525 +
6526 +static int h323_signal_address_fixup(struct ip_conntrack *ct,
6527 +                                    struct sk_buff **pskb,
6528 +                                    enum ip_conntrack_info ctinfo)
6529 +{
6530 +       struct iphdr *iph = (*pskb)->nh.iph;
6531 +       struct tcphdr *tcph = (void *)iph + iph->ihl*4;
6532 +       char *data = (char *) tcph + tcph->doff * 4;
6533 +       u_int32_t tcplen = (*pskb)->len - iph->ihl*4;
6534 +       u_int32_t datalen = tcplen - tcph->doff*4;
6535 +       struct ip_ct_h225_master *info = &ct->help.ct_h225_info; 
6536 +       u_int32_t newip;
6537 +       u_int16_t port;
6538 +       int i;
6539 +
6540 +       MUST_BE_LOCKED(&ip_h323_lock);
6541 +
6542 +       DEBUGP("h323_signal_address_fixup: %s %s\n",
6543 +               between(info->seq[IP_CT_DIR_ORIGINAL], ntohl(tcph->seq), ntohl(tcph->seq) + datalen)
6544 +                       ? "yes" : "no",
6545 +               between(info->seq[IP_CT_DIR_REPLY], ntohl(tcph->seq), ntohl(tcph->seq) + datalen)
6546 +                       ? "yes" : "no");
6547 +       if (!(between(info->seq[IP_CT_DIR_ORIGINAL], ntohl(tcph->seq), ntohl(tcph->seq) + datalen)
6548 +               || between(info->seq[IP_CT_DIR_REPLY], ntohl(tcph->seq), ntohl(tcph->seq) + datalen)))
6549 +               return 1;
6550 +
6551 +       DEBUGP("h323_signal_address_fixup: offsets %u + 6  and %u + 6 in %u\n", 
6552 +               info->offset[IP_CT_DIR_ORIGINAL], 
6553 +               info->offset[IP_CT_DIR_REPLY],
6554 +               tcplen);
6555 +       DUMP_TUPLE(&ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple);
6556 +       DUMP_TUPLE(&ct->tuplehash[IP_CT_DIR_REPLY].tuple);
6557 +
6558 +       for (i = 0; i < IP_CT_DIR_MAX; i++) {
6559 +               DEBUGP("h323_signal_address_fixup: %s %s\n",
6560 +                       info->dir == IP_CT_DIR_ORIGINAL ? "original" : "reply",
6561 +                       i == IP_CT_DIR_ORIGINAL ? "caller" : "callee");
6562 +               if (!between(info->seq[i], ntohl(tcph->seq), 
6563 +                            ntohl(tcph->seq) + datalen))
6564 +                       continue;
6565 +               if (!between(info->seq[i] + 6, ntohl(tcph->seq),
6566 +                            ntohl(tcph->seq) + datalen)) {
6567 +                       /* Partial retransmisison. It's a cracker being funky. */
6568 +                       if (net_ratelimit()) {
6569 +                               printk("H.323_NAT: partial packet %u/6 in %u/%u\n",
6570 +                                    info->seq[i],
6571 +                                    ntohl(tcph->seq),
6572 +                                    ntohl(tcph->seq) + datalen);
6573 +                       }
6574 +                       return 0;
6575 +               }
6576 +
6577 +               /* Change address inside packet to match way we're mapping
6578 +                  this connection. */
6579 +               if (i == IP_CT_DIR_ORIGINAL) {
6580 +                       newip = ct->tuplehash[!info->dir].tuple.dst.ip;
6581 +                       port = ct->tuplehash[!info->dir].tuple.dst.u.tcp.port;
6582 +               } else {
6583 +                       newip = ct->tuplehash[!info->dir].tuple.src.ip;
6584 +                       port = ct->tuplehash[!info->dir].tuple.src.u.tcp.port;
6585 +               }
6586 +
6587 +               DEBUGP("h323_signal_address_fixup: orig %s IP:port %u.%u.%u.%u:%u\n", 
6588 +                       i == IP_CT_DIR_ORIGINAL ? "source" : "dest  ", 
6589 +                       NIPQUAD(*((u_int32_t *)(data + info->offset[i]))), 
6590 +                       ntohs(*((u_int16_t *)(data + info->offset[i] + 4))));
6591 +
6592 +               /* Modify the packet */
6593 +               *(u_int32_t *)(data + info->offset[i]) = newip;
6594 +               *(u_int16_t *)(data + info->offset[i] + 4) = port;
6595 +       
6596 +               DEBUGP("h323_signal_address_fixup:  new %s IP:port %u.%u.%u.%u:%u\n", 
6597 +                       i == IP_CT_DIR_ORIGINAL ? "source" : "dest  ", 
6598 +                       NIPQUAD(*((u_int32_t *)(data + info->offset[i]))), 
6599 +                       ntohs(*((u_int16_t *)(data + info->offset[i] + 4))));
6600 +       }
6601 +
6602 +       /* fix checksum information */
6603 +
6604 +       (*pskb)->csum = csum_partial((char *)tcph + tcph->doff*4,
6605 +                                    datalen, 0);
6606 +
6607 +       tcph->check = 0;
6608 +       tcph->check = tcp_v4_check(tcph, tcplen, iph->saddr, iph->daddr,
6609 +                                  csum_partial((char *)tcph, tcph->doff*4,
6610 +                                          (*pskb)->csum));
6611 +       ip_send_check(iph);
6612 +
6613 +       return 1;
6614 +}
6615 +
6616 +static int h323_data_fixup(struct ip_ct_h225_expect *info,
6617 +                          struct ip_conntrack *ct,
6618 +                          struct sk_buff **pskb,
6619 +                          enum ip_conntrack_info ctinfo,
6620 +                          struct ip_conntrack_expect *expect)
6621 +{
6622 +       u_int32_t newip;
6623 +       u_int16_t port;
6624 +       struct ip_conntrack_tuple newtuple;
6625 +       struct iphdr *iph = (*pskb)->nh.iph;
6626 +       struct tcphdr *tcph = (void *)iph + iph->ihl*4;
6627 +       char *data = (char *) tcph + tcph->doff * 4;
6628 +       u_int32_t tcplen = (*pskb)->len - iph->ihl*4;
6629 +       struct ip_ct_h225_master *master_info = &ct->help.ct_h225_info;
6630 +       int is_h225;
6631 +
6632 +       MUST_BE_LOCKED(&ip_h323_lock);
6633 +       DEBUGP("h323_data_fixup: offset %u + 6 in %u\n", info->offset, tcplen);
6634 +       DUMP_TUPLE(&ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple);
6635 +       DUMP_TUPLE(&ct->tuplehash[IP_CT_DIR_REPLY].tuple);
6636 +
6637 +       if (!between(expect->seq + 6, ntohl(tcph->seq),
6638 +                   ntohl(tcph->seq) + tcplen - tcph->doff * 4)) {
6639 +               /* Partial retransmisison. It's a cracker being funky. */
6640 +               if (net_ratelimit()) {
6641 +                       printk("H.323_NAT: partial packet %u/6 in %u/%u\n",
6642 +                            expect->seq,
6643 +                            ntohl(tcph->seq),
6644 +                            ntohl(tcph->seq) + tcplen - tcph->doff * 4);
6645 +               }
6646 +               return 0;
6647 +       }
6648 +
6649 +       /* Change address inside packet to match way we're mapping
6650 +          this connection. */
6651 +       if (info->dir == IP_CT_DIR_REPLY) {
6652 +               /* Must be where client thinks server is */
6653 +               newip = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.ip;
6654 +               /* Expect something from client->server */
6655 +               newtuple.src.ip = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.ip;
6656 +               newtuple.dst.ip = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.ip;
6657 +       } else {
6658 +               /* Must be where server thinks client is */
6659 +               newip = ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.ip;
6660 +               /* Expect something from server->client */
6661 +               newtuple.src.ip = ct->tuplehash[IP_CT_DIR_REPLY].tuple.src.ip;
6662 +               newtuple.dst.ip = ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.ip;
6663 +       }
6664 +
6665 +       is_h225 = (master_info->is_h225 == H225_PORT);
6666 +
6667 +       if (is_h225) {
6668 +               newtuple.dst.protonum = IPPROTO_TCP;
6669 +               newtuple.src.u.tcp.port = expect->tuple.src.u.tcp.port;
6670 +       } else {
6671 +               newtuple.dst.protonum = IPPROTO_UDP;
6672 +               newtuple.src.u.udp.port = expect->tuple.src.u.udp.port;
6673 +       }
6674 +       
6675 +       /* Try to get same port: if not, try to change it. */
6676 +       for (port = ntohs(info->port); port != 0; port++) {
6677 +               if (is_h225)
6678 +                       newtuple.dst.u.tcp.port = htons(port);
6679 +               else
6680 +                       newtuple.dst.u.udp.port = htons(port);
6681 +
6682 +               if (ip_conntrack_change_expect(expect, &newtuple) == 0)
6683 +                       break;
6684 +       }
6685 +       if (port == 0) {
6686 +               DEBUGP("h323_data_fixup: no free port found!\n");
6687 +               return 0;
6688 +       }
6689 +
6690 +       port = htons(port);
6691 +
6692 +       DEBUGP("h323_data_fixup: orig IP:port %u.%u.%u.%u:%u\n", 
6693 +               NIPQUAD(*((u_int32_t *)(data + info->offset))), 
6694 +               ntohs(*((u_int16_t *)(data + info->offset + 4))));
6695 +
6696 +       /* Modify the packet */
6697 +       *(u_int32_t *)(data + info->offset) = newip;
6698 +       *(u_int16_t *)(data + info->offset + 4) = port;
6699 +       
6700 +       DEBUGP("h323_data_fixup: new IP:port %u.%u.%u.%u:%u\n", 
6701 +               NIPQUAD(*((u_int32_t *)(data + info->offset))), 
6702 +               ntohs(*((u_int16_t *)(data + info->offset + 4))));
6703 +
6704 +       /* fix checksum information  */
6705 +       /* FIXME: usually repeated multiple times in the case of H.245! */
6706 +
6707 +       (*pskb)->csum = csum_partial((char *)tcph + tcph->doff*4,
6708 +                                    tcplen - tcph->doff*4, 0);
6709 +
6710 +       tcph->check = 0;
6711 +       tcph->check = tcp_v4_check(tcph, tcplen, iph->saddr, iph->daddr,
6712 +                                  csum_partial((char *)tcph, tcph->doff*4,
6713 +                                          (*pskb)->csum));
6714 +       ip_send_check(iph);
6715 +
6716 +       return 1;
6717 +}
6718 +
6719 +static unsigned int h225_nat_help(struct ip_conntrack *ct,
6720 +                                 struct ip_conntrack_expect *exp,
6721 +                                 struct ip_nat_info *info,
6722 +                                 enum ip_conntrack_info ctinfo,
6723 +                                 unsigned int hooknum,
6724 +                                 struct sk_buff **pskb)
6725 +{
6726 +       int dir;
6727 +       struct ip_ct_h225_expect *exp_info;
6728 +       
6729 +       /* Only mangle things once: original direction in POST_ROUTING
6730 +          and reply direction on PRE_ROUTING. */
6731 +       dir = CTINFO2DIR(ctinfo);
6732 +       DEBUGP("nat_h323: dir %s at hook %s\n",
6733 +              dir == IP_CT_DIR_ORIGINAL ? "ORIG" : "REPLY",
6734 +              hooknum == NF_IP_POST_ROUTING ? "POSTROUTING"
6735 +              : hooknum == NF_IP_PRE_ROUTING ? "PREROUTING"
6736 +              : hooknum == NF_IP_LOCAL_OUT ? "OUTPUT" : "???");
6737 +       if (!((hooknum == NF_IP_POST_ROUTING && dir == IP_CT_DIR_ORIGINAL)
6738 +             || (hooknum == NF_IP_PRE_ROUTING && dir == IP_CT_DIR_REPLY))) {
6739 +               DEBUGP("nat_h323: Not touching dir %s at hook %s\n",
6740 +                      dir == IP_CT_DIR_ORIGINAL ? "ORIG" : "REPLY",
6741 +                      hooknum == NF_IP_POST_ROUTING ? "POSTROUTING"
6742 +                      : hooknum == NF_IP_PRE_ROUTING ? "PREROUTING"
6743 +                      : hooknum == NF_IP_LOCAL_OUT ? "OUTPUT" : "???");
6744 +               return NF_ACCEPT;
6745 +       }
6746 +
6747 +       if (!exp) {
6748 +               LOCK_BH(&ip_h323_lock);
6749 +               if (!h323_signal_address_fixup(ct, pskb, ctinfo)) {
6750 +                       UNLOCK_BH(&ip_h323_lock);
6751 +                       return NF_DROP;
6752 +               }
6753 +               UNLOCK_BH(&ip_h323_lock);
6754 +               return NF_ACCEPT;
6755 +       }
6756 +               
6757 +       exp_info = &exp->help.exp_h225_info;
6758 +
6759 +       LOCK_BH(&ip_h323_lock);
6760 +       if (!h323_data_fixup(exp_info, ct, pskb, ctinfo, exp)) {
6761 +               UNLOCK_BH(&ip_h323_lock);
6762 +               return NF_DROP;
6763 +       }
6764 +       UNLOCK_BH(&ip_h323_lock);
6765 +
6766 +       return NF_ACCEPT;
6767 +}
6768 +
6769 +static struct ip_nat_helper h225 = 
6770 +       { { NULL, NULL },
6771 +         "H.225",                                      /* name */
6772 +         IP_NAT_HELPER_F_ALWAYS,                       /* flags */
6773 +         THIS_MODULE,                                  /* module */
6774 +         { { 0, { .tcp = { __constant_htons(H225_PORT) } } },  /* tuple */
6775 +           { 0, { 0 }, IPPROTO_TCP } },
6776 +         { { 0, { .tcp = { 0xFFFF } } },               /* mask */
6777 +           { 0, { 0 }, 0xFFFF } },
6778 +         h225_nat_help,                                /* helper */
6779 +         h225_nat_expected                             /* expectfn */
6780 +       };
6781 +
6782 +static int __init init(void)
6783 +{
6784 +       int ret;
6785 +       
6786 +       ret = ip_nat_helper_register(&h225);
6787 +
6788 +       if (ret != 0)
6789 +               printk("ip_nat_h323: cannot initialize the module!\n");
6790 +
6791 +       return ret;
6792 +}
6793 +
6794 +static void __exit fini(void)
6795 +{
6796 +       ip_nat_helper_unregister(&h225);
6797 +}
6798 +
6799 +module_init(init);
6800 +module_exit(fini);
6801 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/netfilter/ip_nat_mms.c linux-2.6.7-rc3/net/ipv4/netfilter/ip_nat_mms.c
6802 --- linux-2.6.7-rc3.org/net/ipv4/netfilter/ip_nat_mms.c 1970-01-01 01:00:00.000000000 +0100
6803 +++ linux-2.6.7-rc3/net/ipv4/netfilter/ip_nat_mms.c     2004-06-08 10:39:44.000000000 +0200
6804 @@ -0,0 +1,350 @@
6805 +/* MMS extension for TCP NAT alteration.
6806 + * (C) 2002 by Filip Sneppe <filip.sneppe@cronos.be>
6807 + * based on ip_nat_ftp.c and ip_nat_irc.c
6808 + *
6809 + * ip_nat_mms.c v0.3 2002-09-22
6810 + *
6811 + *      This program is free software; you can redistribute it and/or
6812 + *      modify it under the terms of the GNU General Public License
6813 + *      as published by the Free Software Foundation; either version
6814 + *      2 of the License, or (at your option) any later version.
6815 + *
6816 + *      Module load syntax:
6817 + *      insmod ip_nat_mms.o ports=port1,port2,...port<MAX_PORTS>
6818 + *
6819 + *      Please give the ports of all MMS servers You wish to connect to.
6820 + *      If you don't specify ports, the default will be TCP port 1755.
6821 + *
6822 + *      More info on MMS protocol, firewalls and NAT:
6823 + *      http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwmt/html/MMSFirewall.asp
6824 + *      http://www.microsoft.com/windows/windowsmedia/serve/firewall.asp
6825 + *
6826 + *      The SDP project people are reverse-engineering MMS:
6827 + *      http://get.to/sdp
6828 + */
6829 +
6830 +/* FIXME: issue with UDP & fragmentation with this URL: 
6831 +   http://www.cnn.com/video/world/2002/01/21/jb.shoe.bomb.cafe.cnn.low.asx 
6832 +   may be related to out-of-order first packets:
6833 +   basically the expectation is set up correctly, then the server sends
6834 +   a first UDP packet which is fragmented plus arrives out-of-order.
6835 +   the MASQUERADING firewall with ip_nat_mms loaded responds with
6836 +   an ICMP unreachable back to the server */
6837 +
6838 +#include <linux/module.h>
6839 +#include <linux/netfilter_ipv4.h>
6840 +#include <linux/ip.h>
6841 +#include <linux/tcp.h>
6842 +#include <net/tcp.h>
6843 +#include <linux/netfilter_ipv4/ip_nat.h>
6844 +#include <linux/netfilter_ipv4/ip_nat_helper.h>
6845 +#include <linux/netfilter_ipv4/ip_nat_rule.h>
6846 +#include <linux/netfilter_ipv4/ip_conntrack_mms.h>
6847 +#include <linux/netfilter_ipv4/ip_conntrack_helper.h>
6848 +
6849 +#if 0 
6850 +#define DEBUGP printk
6851 +#define DUMP_BYTES(address, counter)                                \
6852 +({                                                                  \
6853 +       int temp_counter;                                           \
6854 +       for(temp_counter=0; temp_counter<counter; ++temp_counter) { \
6855 +               DEBUGP("%u ", (u8)*(address+temp_counter));         \
6856 +       };                                                          \
6857 +       DEBUGP("\n");                                               \
6858 +})
6859 +#else
6860 +#define DEBUGP(format, args...)
6861 +#define DUMP_BYTES(address, counter)
6862 +#endif
6863 +
6864 +#define MAX_PORTS 8
6865 +static int ports[MAX_PORTS];
6866 +static int ports_c = 0;
6867 +
6868 +#ifdef MODULE_PARM
6869 +MODULE_PARM(ports, "1-" __MODULE_STRING(MAX_PORTS) "i");
6870 +#endif
6871 +
6872 +MODULE_AUTHOR("Filip Sneppe <filip.sneppe@cronos.be>");
6873 +MODULE_DESCRIPTION("Microsoft Windows Media Services (MMS) NAT module");
6874 +MODULE_LICENSE("GPL");
6875 +
6876 +DECLARE_LOCK_EXTERN(ip_mms_lock);
6877 +
6878 +/* FIXME: Time out? --RR */
6879 +
6880 +static int mms_data_fixup(const struct ip_ct_mms_expect *ct_mms_info,
6881 +                          struct ip_conntrack *ct,
6882 +                          struct sk_buff **pskb,
6883 +                          enum ip_conntrack_info ctinfo,
6884 +                          struct ip_conntrack_expect *expect)
6885 +{
6886 +       u_int32_t newip;
6887 +       struct ip_conntrack_tuple t;
6888 +       struct iphdr *iph = (*pskb)->nh.iph;
6889 +       struct tcphdr *tcph = (void *) iph + iph->ihl * 4;
6890 +       char *data = (char *)tcph + tcph->doff * 4;
6891 +       int i, j, k, port;
6892 +       u_int16_t mms_proto;
6893 +
6894 +       u_int32_t *mms_chunkLenLV    = (u_int32_t *)(data + MMS_SRV_CHUNKLENLV_OFFSET);
6895 +       u_int32_t *mms_chunkLenLM    = (u_int32_t *)(data + MMS_SRV_CHUNKLENLM_OFFSET);
6896 +       u_int32_t *mms_messageLength = (u_int32_t *)(data + MMS_SRV_MESSAGELENGTH_OFFSET);
6897 +
6898 +       int zero_padding;
6899 +
6900 +       char buffer[28];         /* "\\255.255.255.255\UDP\65635" * 2 (for unicode) */
6901 +       char unicode_buffer[75]; /* 27*2 (unicode) + 20 + 1 */
6902 +       char proto_string[6];
6903 +       
6904 +       MUST_BE_LOCKED(&ip_mms_lock);
6905 +
6906 +       /* what was the protocol again ? */
6907 +       mms_proto = expect->tuple.dst.protonum;
6908 +       sprintf(proto_string, "%u", mms_proto);
6909 +       
6910 +       DEBUGP("ip_nat_mms: mms_data_fixup: info (seq %u + %u) in %u, proto %s\n",
6911 +              expect->seq, ct_mms_info->len, ntohl(tcph->seq),
6912 +              mms_proto == IPPROTO_UDP ? "UDP"
6913 +              : mms_proto == IPPROTO_TCP ? "TCP":proto_string);
6914 +       
6915 +       newip = ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.ip;
6916 +
6917 +       /* Alter conntrack's expectations. */
6918 +       t = expect->tuple;
6919 +       t.dst.ip = newip;
6920 +       for (port = ct_mms_info->port; port != 0; port++) {
6921 +               t.dst.u.tcp.port = htons(port);
6922 +               if (ip_conntrack_change_expect(expect, &t) == 0) {
6923 +                       DEBUGP("ip_nat_mms: mms_data_fixup: using port %d\n", port);
6924 +                       break;
6925 +               }
6926 +       }
6927 +       
6928 +       if(port == 0)
6929 +               return 0;
6930 +
6931 +       sprintf(buffer, "\\\\%u.%u.%u.%u\\%s\\%u",
6932 +               NIPQUAD(newip),
6933 +               expect->tuple.dst.protonum == IPPROTO_UDP ? "UDP"
6934 +               : expect->tuple.dst.protonum == IPPROTO_TCP ? "TCP":proto_string,
6935 +               port);
6936 +       DEBUGP("ip_nat_mms: new unicode string=%s\n", buffer);
6937 +       
6938 +       memset(unicode_buffer, 0, sizeof(char)*75);
6939 +
6940 +       for (i=0; i<strlen(buffer); ++i)
6941 +               *(unicode_buffer+i*2)=*(buffer+i);
6942 +       
6943 +       DEBUGP("ip_nat_mms: mms_data_fixup: padding: %u len: %u\n", ct_mms_info->padding, ct_mms_info->len);
6944 +       DEBUGP("ip_nat_mms: mms_data_fixup: offset: %u\n", MMS_SRV_UNICODE_STRING_OFFSET+ct_mms_info->len);
6945 +       DUMP_BYTES(data+MMS_SRV_UNICODE_STRING_OFFSET, 60);
6946 +       
6947 +       /* add end of packet to it */
6948 +       for (j=0; j<ct_mms_info->padding; ++j) {
6949 +               DEBUGP("ip_nat_mms: mms_data_fixup: i=%u j=%u byte=%u\n", 
6950 +                      i, j, (u8)*(data+MMS_SRV_UNICODE_STRING_OFFSET+ct_mms_info->len+j));
6951 +               *(unicode_buffer+i*2+j) = *(data+MMS_SRV_UNICODE_STRING_OFFSET+ct_mms_info->len+j);
6952 +       }
6953 +
6954 +       /* pad with zeroes at the end ? see explanation of weird math below */
6955 +       zero_padding = (8-(strlen(buffer)*2 + ct_mms_info->padding + 4)%8)%8;
6956 +       for (k=0; k<zero_padding; ++k)
6957 +               *(unicode_buffer+i*2+j+k)= (char)0;
6958 +       
6959 +       DEBUGP("ip_nat_mms: mms_data_fixup: zero_padding = %u\n", zero_padding);
6960 +       DEBUGP("ip_nat_mms: original=> chunkLenLV=%u chunkLenLM=%u messageLength=%u\n",
6961 +              *mms_chunkLenLV, *mms_chunkLenLM, *mms_messageLength);
6962 +       
6963 +       /* explanation, before I forget what I did:
6964 +          strlen(buffer)*2 + ct_mms_info->padding + 4 must be divisable by 8;
6965 +          divide by 8 and add 3 to compute the mms_chunkLenLM field,
6966 +          but note that things may have to be padded with zeroes to align by 8 
6967 +          bytes, hence we add 7 and divide by 8 to get the correct length */ 
6968 +       *mms_chunkLenLM    = (u_int32_t) (3+(strlen(buffer)*2+ct_mms_info->padding+11)/8);
6969 +       *mms_chunkLenLV    = *mms_chunkLenLM+2;
6970 +       *mms_messageLength = *mms_chunkLenLV*8;
6971 +       
6972 +       DEBUGP("ip_nat_mms: modified=> chunkLenLV=%u chunkLenLM=%u messageLength=%u\n",
6973 +              *mms_chunkLenLV, *mms_chunkLenLM, *mms_messageLength);
6974 +       
6975 +       ip_nat_mangle_tcp_packet(pskb, ct, ctinfo, 
6976 +                                expect->seq - ntohl(tcph->seq),
6977 +                                ct_mms_info->len + ct_mms_info->padding, unicode_buffer,
6978 +                                strlen(buffer)*2 + ct_mms_info->padding + zero_padding);
6979 +       DUMP_BYTES(unicode_buffer, 60);
6980 +       
6981 +       return 1;
6982 +}
6983 +
6984 +static unsigned int
6985 +mms_nat_expected(struct sk_buff **pskb,
6986 +                 unsigned int hooknum,
6987 +                 struct ip_conntrack *ct,
6988 +                 struct ip_nat_info *info)
6989 +{
6990 +       struct ip_nat_multi_range mr;
6991 +       u_int32_t newdstip, newsrcip, newip;
6992 +
6993 +       struct ip_conntrack *master = master_ct(ct);
6994 +
6995 +       IP_NF_ASSERT(info);
6996 +       IP_NF_ASSERT(master);
6997 +
6998 +       IP_NF_ASSERT(!(info->initialized & (1 << HOOK2MANIP(hooknum))));
6999 +
7000 +       DEBUGP("ip_nat_mms: mms_nat_expected: We have a connection!\n");
7001 +
7002 +       newdstip = master->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.ip;
7003 +       newsrcip = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.ip;
7004 +       DEBUGP("ip_nat_mms: mms_nat_expected: hook %s: newsrc->newdst %u.%u.%u.%u->%u.%u.%u.%u\n",
7005 +              hooknum == NF_IP_POST_ROUTING ? "POSTROUTING"
7006 +              : hooknum == NF_IP_PRE_ROUTING ? "PREROUTING"
7007 +              : hooknum == NF_IP_LOCAL_OUT ? "OUTPUT" : "???",
7008 +              NIPQUAD(newsrcip), NIPQUAD(newdstip));
7009 +
7010 +       if (HOOK2MANIP(hooknum) == IP_NAT_MANIP_SRC)
7011 +               newip = newsrcip;
7012 +       else
7013 +               newip = newdstip;
7014 +
7015 +       DEBUGP("ip_nat_mms: mms_nat_expected: IP to %u.%u.%u.%u\n", NIPQUAD(newip));
7016 +
7017 +       mr.rangesize = 1;
7018 +       /* We don't want to manip the per-protocol, just the IPs. */
7019 +       mr.range[0].flags = IP_NAT_RANGE_MAP_IPS;
7020 +       mr.range[0].min_ip = mr.range[0].max_ip = newip;
7021 +
7022 +       return ip_nat_setup_info(ct, &mr, hooknum);
7023 +}
7024 +
7025 +
7026 +static unsigned int mms_nat_help(struct ip_conntrack *ct,
7027 +                        struct ip_conntrack_expect *exp,
7028 +                        struct ip_nat_info *info,
7029 +                        enum ip_conntrack_info ctinfo,
7030 +                        unsigned int hooknum,
7031 +                        struct sk_buff **pskb)
7032 +{
7033 +       struct iphdr *iph = (*pskb)->nh.iph;
7034 +       struct tcphdr *tcph = (void *) iph + iph->ihl * 4;
7035 +       unsigned int datalen;
7036 +       int dir;
7037 +       struct ip_ct_mms_expect *ct_mms_info;
7038 +
7039 +       if (!exp)
7040 +               DEBUGP("ip_nat_mms: no exp!!");
7041 +
7042 +       ct_mms_info = &exp->help.exp_mms_info;
7043 +       
7044 +       /* Only mangle things once: original direction in POST_ROUTING
7045 +          and reply direction on PRE_ROUTING. */
7046 +       dir = CTINFO2DIR(ctinfo);
7047 +       if (!((hooknum == NF_IP_POST_ROUTING && dir == IP_CT_DIR_ORIGINAL)
7048 +           ||(hooknum == NF_IP_PRE_ROUTING && dir == IP_CT_DIR_REPLY))) {
7049 +               DEBUGP("ip_nat_mms: mms_nat_help: not touching dir %s at hook %s\n",
7050 +                      dir == IP_CT_DIR_ORIGINAL ? "ORIG" : "REPLY",
7051 +                      hooknum == NF_IP_POST_ROUTING ? "POSTROUTING"
7052 +                      : hooknum == NF_IP_PRE_ROUTING ? "PREROUTING"
7053 +                      : hooknum == NF_IP_LOCAL_OUT ? "OUTPUT" : "???");
7054 +               return NF_ACCEPT;
7055 +       }
7056 +       DEBUGP("ip_nat_mms: mms_nat_help: beyond not touching (dir %s at hook %s)\n",
7057 +              dir == IP_CT_DIR_ORIGINAL ? "ORIG" : "REPLY",
7058 +              hooknum == NF_IP_POST_ROUTING ? "POSTROUTING"
7059 +              : hooknum == NF_IP_PRE_ROUTING ? "PREROUTING"
7060 +              : hooknum == NF_IP_LOCAL_OUT ? "OUTPUT" : "???");
7061 +       
7062 +       datalen = (*pskb)->len - iph->ihl * 4 - tcph->doff * 4;
7063 +       
7064 +       DEBUGP("ip_nat_mms: mms_nat_help: %u+%u=%u %u %u\n", exp->seq, ct_mms_info->len,
7065 +              exp->seq + ct_mms_info->len,
7066 +              ntohl(tcph->seq),
7067 +              ntohl(tcph->seq) + datalen);
7068 +       
7069 +       LOCK_BH(&ip_mms_lock);
7070 +       /* Check wether the whole IP/proto/port pattern is carried in the payload */
7071 +       if (between(exp->seq + ct_mms_info->len,
7072 +           ntohl(tcph->seq),
7073 +           ntohl(tcph->seq) + datalen)) {
7074 +               if (!mms_data_fixup(ct_mms_info, ct, pskb, ctinfo, exp)) {
7075 +                       UNLOCK_BH(&ip_mms_lock);
7076 +                       return NF_DROP;
7077 +               }
7078 +       } else {
7079 +               /* Half a match?  This means a partial retransmisison.
7080 +                  It's a cracker being funky. */
7081 +               if (net_ratelimit()) {
7082 +                       printk("ip_nat_mms: partial packet %u/%u in %u/%u\n",
7083 +                              exp->seq, ct_mms_info->len,
7084 +                              ntohl(tcph->seq),
7085 +                              ntohl(tcph->seq) + datalen);
7086 +               }
7087 +               UNLOCK_BH(&ip_mms_lock);
7088 +               return NF_DROP;
7089 +       }
7090 +       UNLOCK_BH(&ip_mms_lock);
7091 +       
7092 +       return NF_ACCEPT;
7093 +}
7094 +
7095 +static struct ip_nat_helper mms[MAX_PORTS];
7096 +static char mms_names[MAX_PORTS][10];
7097 +
7098 +/* Not __exit: called from init() */
7099 +static void fini(void)
7100 +{
7101 +       int i;
7102 +
7103 +       for (i = 0; (i < MAX_PORTS) && ports[i]; i++) {
7104 +               DEBUGP("ip_nat_mms: unregistering helper for port %d\n", ports[i]);
7105 +               ip_nat_helper_unregister(&mms[i]);
7106 +       }
7107 +}
7108 +
7109 +static int __init init(void)
7110 +{
7111 +       int i, ret = 0;
7112 +       char *tmpname;
7113 +
7114 +       if (ports[0] == 0)
7115 +               ports[0] = MMS_PORT;
7116 +
7117 +       for (i = 0; (i < MAX_PORTS) && ports[i]; i++) {
7118 +
7119 +               memset(&mms[i], 0, sizeof(struct ip_nat_helper));
7120 +
7121 +               mms[i].tuple.dst.protonum = IPPROTO_TCP;
7122 +               mms[i].tuple.src.u.tcp.port = htons(ports[i]);
7123 +               mms[i].mask.dst.protonum = 0xFFFF;
7124 +               mms[i].mask.src.u.tcp.port = 0xFFFF;
7125 +               mms[i].help = mms_nat_help;
7126 +               mms[i].me = THIS_MODULE;
7127 +               mms[i].flags = 0;
7128 +               mms[i].expect = mms_nat_expected;
7129 +
7130 +               tmpname = &mms_names[i][0];
7131 +               if (ports[i] == MMS_PORT)
7132 +                       sprintf(tmpname, "mms");
7133 +               else
7134 +                       sprintf(tmpname, "mms-%d", i);
7135 +               mms[i].name = tmpname;
7136 +
7137 +               DEBUGP("ip_nat_mms: register helper for port %d\n",
7138 +                               ports[i]);
7139 +               ret = ip_nat_helper_register(&mms[i]);
7140 +
7141 +               if (ret) {
7142 +                       printk("ip_nat_mms: error registering "
7143 +                              "helper for port %d\n", ports[i]);
7144 +                       fini();
7145 +                       return ret;
7146 +               }
7147 +               ports_c++;
7148 +       }
7149 +
7150 +       return ret;
7151 +}
7152 +
7153 +module_init(init);
7154 +module_exit(fini);
7155 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/netfilter/ip_nat_quake3.c linux-2.6.7-rc3/net/ipv4/netfilter/ip_nat_quake3.c
7156 --- linux-2.6.7-rc3.org/net/ipv4/netfilter/ip_nat_quake3.c      1970-01-01 01:00:00.000000000 +0100
7157 +++ linux-2.6.7-rc3/net/ipv4/netfilter/ip_nat_quake3.c  2004-06-08 10:40:36.000000000 +0200
7158 @@ -0,0 +1,249 @@
7159 +/* Quake3 extension for UDP NAT alteration.
7160 + * (C) 2002 by Filip Sneppe <filip.sneppe@cronos.be>
7161 + * based on ip_nat_ftp.c and ip_nat_tftp.c
7162 + *
7163 + * ip_nat_quake3.c v0.0.3 2002-08-31
7164 + *
7165 + *      This program is free software; you can redistribute it and/or
7166 + *      modify it under the terms of the GNU General Public License
7167 + *      as published by the Free Software Foundation; either version
7168 + *      2 of the License, or (at your option) any later version.
7169 + *
7170 + *      Module load syntax:
7171 + *      insmod ip_nat_quake3.o ports=port1,port2,...port<MAX_PORTS>
7172 + *
7173 + *      please give the ports of all Quake3 master servers You wish to
7174 + *      connect to. If you don't specify ports, the default will be UDP
7175 + *      port 27950.
7176 + *
7177 + *      Thanks to the Ethereal folks for their analysis of the Quake3 protocol.
7178 + *
7179 + *      Notes: 
7180 + *      - If you're one of those people who would try anything to lower
7181 + *        latency while playing Quake (and who isn't :-) ), you may want to
7182 + *        consider not loading ip_nat_quake3 at all and just MASQUERADE all
7183 + *        outgoing UDP traffic.
7184 + *        This will make ip_conntrack_quake3 add the necessary expectations,
7185 + *        but there will be no overhead for client->server UDP streams. If
7186 + *        ip_nat_quake3 is loaded, quake3_nat_expected will be called per NAT
7187 + *        hook for every packet in the client->server UDP stream.
7188 + *      - Only SNAT/MASQUEARDE targets are useful for ip_nat_quake3.
7189 + *        The IP addresses in the master connection payload (=IP addresses
7190 + *        of Quake servers) have no relation with the master server so
7191 + *        DNAT'ing the master connection to a server should not change the
7192 + *        expected connections.
7193 + *      - Not tested due to lack of equipment:
7194 + *        - multiple Quake3 clients behind one MASQUERADE gateway
7195 + *        - what if Quake3 client is running on router too
7196 + */
7197 +
7198 +#include <linux/module.h>
7199 +#include <linux/netfilter_ipv4.h>
7200 +#include <linux/ip.h>
7201 +#include <linux/udp.h>
7202 +
7203 +#include <linux/netfilter.h>
7204 +#include <linux/netfilter_ipv4/ip_tables.h>
7205 +#include <linux/netfilter_ipv4/ip_conntrack_helper.h>
7206 +#include <linux/netfilter_ipv4/ip_conntrack_quake3.h>
7207 +#include <linux/netfilter_ipv4/ip_nat_helper.h>
7208 +#include <linux/netfilter_ipv4/ip_nat_rule.h>
7209 +
7210 +MODULE_AUTHOR("Filip Sneppe <filip.sneppe@cronos.be>");
7211 +MODULE_DESCRIPTION("Netfilter NAT helper for Quake III Arena");
7212 +MODULE_LICENSE("GPL");
7213 +
7214 +#define MAX_PORTS 8
7215 +
7216 +static int ports[MAX_PORTS];
7217 +static int ports_c = 0;
7218 +#ifdef MODULE_PARM
7219 +MODULE_PARM(ports,"1-" __MODULE_STRING(MAX_PORTS) "i");
7220 +MODULE_PARM_DESC(ports, "port numbers of Quake III master servers");
7221 +#endif
7222 +
7223 +/* Quake3 master server reply will add > 100 expectations per reply packet; when
7224 +   doing lots of printk's, klogd may not be able to read /proc/kmsg fast enough */
7225 +#if 0 
7226 +#define DEBUGP printk
7227 +#else
7228 +#define DEBUGP(format, args...)
7229 +#endif
7230 +
7231 +static struct quake3_search quake3s_nat = { "****", "getserversResponse", sizeof("getserversResponse") - 1 };
7232 +
7233 +static unsigned int 
7234 +quake3_nat_help(struct ip_conntrack *ct,
7235 +                struct ip_conntrack_expect *exp,
7236 +                struct ip_nat_info *info,
7237 +                enum ip_conntrack_info ctinfo,
7238 +                unsigned int hooknum,
7239 +                struct sk_buff **pskb)
7240 +{
7241 +       struct iphdr *iph = (*pskb)->nh.iph;
7242 +       struct udphdr *udph = (void *)iph + iph->ihl * 4;
7243 +       struct ip_conntrack_tuple repl;
7244 +       int dir = CTINFO2DIR(ctinfo);
7245 +       int i;
7246 +       
7247 +       DEBUGP("ip_nat_quake3: quake3_nat_help, direction: %s hook: %s\n",
7248 +              dir == IP_CT_DIR_ORIGINAL ? "ORIG" : "REPLY",
7249 +              hooknum == NF_IP_POST_ROUTING ? "POSTROUTING"
7250 +              : hooknum == NF_IP_PRE_ROUTING ? "PREROUTING"
7251 +              : hooknum == NF_IP_LOCAL_OUT ? "OUTPUT" : "???"
7252 +             );
7253 +       DUMP_TUPLE(&ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple);
7254 +       DUMP_TUPLE(&ct->tuplehash[IP_CT_DIR_REPLY].tuple);
7255 +       
7256 +       /* Only mangle things once: original direction in POST_ROUTING
7257 +          and reply direction on PRE_ROUTING. */
7258 +       if (!((hooknum == NF_IP_POST_ROUTING && dir == IP_CT_DIR_ORIGINAL)
7259 +           || (hooknum == NF_IP_PRE_ROUTING && dir == IP_CT_DIR_REPLY))) {
7260 +               DEBUGP("ip_nat_quake3: Not touching dir %s at hook %s\n",
7261 +                      dir == IP_CT_DIR_ORIGINAL ? "ORIG" : "REPLY",
7262 +                      hooknum == NF_IP_POST_ROUTING ? "POSTROUTING"
7263 +                      : hooknum == NF_IP_PRE_ROUTING ? "PREROUTING"
7264 +                      : hooknum == NF_IP_LOCAL_OUT ? "OUTPUT" : "????");
7265 +               return NF_ACCEPT;
7266 +       }
7267 +
7268 +       if (!exp) {
7269 +               DEBUGP("no conntrack expectation to modify\n");
7270 +               return NF_ACCEPT;
7271 +       }
7272 +
7273 +       if (strnicmp((const char *)udph + 12, quake3s_nat.pattern, quake3s_nat.plen) == 0) {
7274 +               for(i=31; /* 8 bytes UDP hdr, 4 bytes filler, 18 bytes "getserversResponse", 1 byte "\" */
7275 +                   i+6 < ntohs(udph->len);
7276 +                   i+=7) {
7277 +                       DEBUGP("ip_nat_quake3: adding server at offset %u/%u %u.%u.%u.%u:%u\n", 
7278 +                              i, ntohs(udph->len),
7279 +                              NIPQUAD( (u_int32_t) *( (u_int32_t *)( (int)udph + i ) ) ),
7280 +                              ntohs((__u16) *( (__u16 *)( (int)udph + i + 4 ) ) ) );
7281 +                       
7282 +                       memset(&repl, 0, sizeof(repl));
7283 +
7284 +                       repl.dst.protonum = IPPROTO_UDP;
7285 +                       repl.src.ip = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.ip;
7286 +                       repl.dst.ip = *( (u_int32_t *)( (int)udph + i ) );
7287 +                       repl.dst.u.udp.port = (__u16) *( (__u16 *)( (int)udph + i + 4 )  );
7288 +                       
7289 +                       ip_conntrack_change_expect(exp, &repl);
7290 +               }
7291 +       }
7292 +       return NF_ACCEPT;
7293 +}
7294 +
7295 +static unsigned int 
7296 +quake3_nat_expected(struct sk_buff **pskb,
7297 +                    unsigned int hooknum,
7298 +                    struct ip_conntrack *ct, 
7299 +                    struct ip_nat_info *info) 
7300 +{
7301 +       const struct ip_conntrack *master = ct->master->expectant;
7302 +       struct ip_nat_multi_range mr;
7303 +       u_int32_t newsrcip, newdstip, newip;
7304 +#if 0 
7305 +       const struct ip_conntrack_tuple *repl =
7306 +               &master->tuplehash[IP_CT_DIR_REPLY].tuple;
7307 +       struct iphdr *iph = (*pskb)->nh.iph;
7308 +       struct udphdr *udph = (void *)iph + iph->ihl*4;
7309 +#endif
7310 +
7311 +       DEBUGP("ip_nat_quake3: quake3_nat_expected: here we are\n");
7312 +       DUMP_TUPLE(&ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple);
7313 +
7314 +       IP_NF_ASSERT(info);
7315 +       IP_NF_ASSERT(master);
7316 +       IP_NF_ASSERT(!(info->initialized & (1 << HOOK2MANIP(hooknum))));
7317 +       
7318 +       newdstip = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.ip;
7319 +       newsrcip = master->tuplehash[IP_CT_DIR_REPLY].tuple.dst.ip;
7320 +       
7321 +       if (HOOK2MANIP(hooknum) == IP_NAT_MANIP_SRC) {
7322 +               newip = newsrcip;
7323 +               DEBUGP("hook: %s orig: %u.%u.%u.%u:%u <-> %u.%u.%u.%u:%u "
7324 +                      "newsrc: %u.%u.%u.%u\n",
7325 +                      hooknum == NF_IP_POST_ROUTING ? "POSTROUTING"
7326 +                      : hooknum == NF_IP_PRE_ROUTING ? "PREROUTING"
7327 +                      : hooknum == NF_IP_LOCAL_OUT ? "OUTPUT" : "????",
7328 +                      NIPQUAD((*pskb)->nh.iph->saddr), ntohs(udph->source),
7329 +                      NIPQUAD((*pskb)->nh.iph->daddr), ntohs(udph->dest),
7330 +                      NIPQUAD(newip));
7331 +               
7332 +       } else {
7333 +               newip = newdstip;
7334 +               DEBUGP("hook: %s orig: %u.%u.%u.%u:%u <-> %u.%u.%u.%u:%u "
7335 +                      "newdst: %u.%u.%u.%u\n",
7336 +                      hooknum == NF_IP_POST_ROUTING ? "POSTROUTING"
7337 +                      : hooknum == NF_IP_PRE_ROUTING ? "PREROUTING"
7338 +                      : hooknum == NF_IP_LOCAL_OUT ? "OUTPUT" : "????",
7339 +                      NIPQUAD((*pskb)->nh.iph->saddr), ntohs(udph->source),
7340 +                      NIPQUAD((*pskb)->nh.iph->daddr), ntohs(udph->dest),
7341 +                      NIPQUAD(newip));
7342 +       }
7343 +       
7344 +       mr.rangesize = 1;
7345 +       mr.range[0].flags = IP_NAT_RANGE_MAP_IPS;
7346 +       mr.range[0].min_ip = mr.range[0].max_ip = newip; 
7347 +
7348 +       return ip_nat_setup_info(ct,&mr,hooknum);
7349 +}
7350 +
7351 +static struct ip_nat_helper quake3[MAX_PORTS];
7352 +static char quake3_names[MAX_PORTS][13];  /* quake3-65535 */
7353 +
7354 +static void fini(void)
7355 +{
7356 +       int i;
7357 +       
7358 +       for (i = 0 ; i < ports_c; i++) {
7359 +               DEBUGP("ip_nat_quake3: unregistering helper for port %d\n", ports[i]);
7360 +                      ip_nat_helper_unregister(&quake3[i]);
7361 +       }
7362 +}
7363 +
7364 +static int __init init(void)
7365 +       {
7366 +               int i, ret = 0;
7367 +               char *tmpname;
7368 +
7369 +               if (!ports[0])
7370 +                       ports[0] = QUAKE3_MASTER_PORT;
7371 +               
7372 +               for (i = 0 ; (i < MAX_PORTS) && ports[i] ; i++) {
7373 +                       memset(&quake3[i], 0, sizeof(struct ip_nat_helper));
7374 +
7375 +                       quake3[i].tuple.dst.protonum = IPPROTO_UDP;
7376 +                       quake3[i].tuple.src.u.udp.port = htons(ports[i]);
7377 +                       quake3[i].mask.dst.protonum = 0xFFFF;
7378 +                       quake3[i].mask.src.u.udp.port = 0xFFFF;
7379 +                       quake3[i].help = quake3_nat_help;
7380 +                       quake3[i].flags = 0;
7381 +                       quake3[i].me = THIS_MODULE;
7382 +                       quake3[i].expect = quake3_nat_expected;
7383 +                       
7384 +                       tmpname = &quake3_names[i][0];
7385 +                       if (ports[i] == QUAKE3_MASTER_PORT)
7386 +                               sprintf(tmpname, "quake3");
7387 +                       else
7388 +                               sprintf(tmpname, "quake3-%d", i);
7389 +                       quake3[i].name = tmpname;
7390 +                       
7391 +                       DEBUGP("ip_nat_quake3: registering helper for port %d: name %s\n",
7392 +                              ports[i], quake3[i].name);
7393 +                       ret = ip_nat_helper_register(&quake3[i]);
7394 +                       
7395 +                       if (ret) {
7396 +                               printk("ip_nat_quake3: unable to register helper for port %d\n",
7397 +                                      ports[i]);
7398 +                               fini();
7399 +                               return ret;
7400 +                       }
7401 +                       ports_c++;
7402 +               }
7403 +               return ret;
7404 +       }
7405 +       
7406 +module_init(init);
7407 +module_exit(fini);
7408 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/netfilter/ip_nat_rtsp.c linux-2.6.7-rc3/net/ipv4/netfilter/ip_nat_rtsp.c
7409 --- linux-2.6.7-rc3.org/net/ipv4/netfilter/ip_nat_rtsp.c        1970-01-01 01:00:00.000000000 +0100
7410 +++ linux-2.6.7-rc3/net/ipv4/netfilter/ip_nat_rtsp.c    2004-06-08 10:40:46.000000000 +0200
7411 @@ -0,0 +1,621 @@
7412 +/*
7413 + * RTSP extension for TCP NAT alteration
7414 + * (C) 2003 by Tom Marshall <tmarshall@real.com>
7415 + * based on ip_nat_irc.c
7416 + *
7417 + *      This program is free software; you can redistribute it and/or
7418 + *      modify it under the terms of the GNU General Public License
7419 + *      as published by the Free Software Foundation; either version
7420 + *      2 of the License, or (at your option) any later version.
7421 + *
7422 + * Module load syntax:
7423 + *      insmod ip_nat_rtsp.o ports=port1,port2,...port<MAX_PORTS>
7424 + *                           stunaddr=<address>
7425 + *                           destaction=[auto|strip|none]
7426 + *
7427 + * If no ports are specified, the default will be port 554 only.
7428 + *
7429 + * stunaddr specifies the address used to detect that a client is using STUN.
7430 + * If this address is seen in the destination parameter, it is assumed that
7431 + * the client has already punched a UDP hole in the firewall, so we don't
7432 + * mangle the client_port.  If none is specified, it is autodetected.  It
7433 + * only needs to be set if you have multiple levels of NAT.  It should be
7434 + * set to the external address that the STUN clients detect.  Note that in
7435 + * this case, it will not be possible for clients to use UDP with servers
7436 + * between the NATs.
7437 + *
7438 + * If no destaction is specified, auto is used.
7439 + *   destaction=auto:  strip destination parameter if it is not stunaddr.
7440 + *   destaction=strip: always strip destination parameter (not recommended).
7441 + *   destaction=none:  do not touch destination parameter (not recommended).
7442 + */
7443 +
7444 +#include <linux/module.h>
7445 +#include <linux/netfilter_ipv4.h>
7446 +#include <linux/ip.h>
7447 +#include <linux/tcp.h>
7448 +#include <linux/kernel.h>
7449 +#include <net/tcp.h>
7450 +#include <linux/netfilter_ipv4/ip_nat.h>
7451 +#include <linux/netfilter_ipv4/ip_nat_helper.h>
7452 +#include <linux/netfilter_ipv4/ip_nat_rule.h>
7453 +#include <linux/netfilter_ipv4/ip_conntrack_rtsp.h>
7454 +#include <linux/netfilter_ipv4/ip_conntrack_helper.h>
7455 +
7456 +#include <linux/inet.h>
7457 +#include <linux/ctype.h>
7458 +#define NF_NEED_STRNCASECMP
7459 +#define NF_NEED_STRTOU16
7460 +#include <linux/netfilter_helpers.h>
7461 +#define NF_NEED_MIME_NEXTLINE
7462 +#include <linux/netfilter_mime.h>
7463 +
7464 +#define INFOP(fmt, args...) printk(KERN_INFO "%s: %s: " fmt, __FILE__, __FUNCTION__ , ## args)
7465 +#ifdef IP_NF_RTSP_DEBUG
7466 +#define DEBUGP(fmt, args...) printk(KERN_DEBUG "%s: %s: " fmt, __FILE__, __FUNCTION__ , ## args)
7467 +#else
7468 +#define DEBUGP(fmt, args...)
7469 +#endif
7470 +
7471 +#define MAX_PORTS       8
7472 +#define DSTACT_AUTO     0
7473 +#define DSTACT_STRIP    1
7474 +#define DSTACT_NONE     2
7475 +
7476 +static int      ports[MAX_PORTS];
7477 +static char*    stunaddr = NULL;
7478 +static char*    destaction = NULL;
7479 +
7480 +static int       num_ports = 0;
7481 +static u_int32_t extip = 0;
7482 +static int       dstact = 0;
7483 +
7484 +MODULE_AUTHOR("Tom Marshall <tmarshall@real.com>");
7485 +MODULE_DESCRIPTION("RTSP network address translation module");
7486 +MODULE_LICENSE("GPL");
7487 +#ifdef MODULE_PARM
7488 +MODULE_PARM(ports, "1-" __MODULE_STRING(MAX_PORTS) "i");
7489 +MODULE_PARM_DESC(ports, "port numbers of RTSP servers");
7490 +MODULE_PARM(stunaddr, "s");
7491 +MODULE_PARM_DESC(stunaddr, "Address for detecting STUN");
7492 +MODULE_PARM(destaction, "s");
7493 +MODULE_PARM_DESC(destaction, "Action for destination parameter (auto/strip/none)");
7494 +#endif
7495 +
7496 +/* protects rtsp part of conntracks */
7497 +DECLARE_LOCK_EXTERN(ip_rtsp_lock);
7498 +
7499 +#define SKIP_WSPACE(ptr,len,off) while(off < len && isspace(*(ptr+off))) { off++; }
7500 +
7501 +/*** helper functions ***/
7502 +
7503 +static void
7504 +get_skb_tcpdata(struct sk_buff* skb, char** pptcpdata, uint* ptcpdatalen)
7505 +{
7506 +    struct iphdr*   iph  = (struct iphdr*)skb->nh.iph;
7507 +    struct tcphdr*  tcph = (struct tcphdr*)((char*)iph + iph->ihl*4);
7508 +
7509 +    *pptcpdata = (char*)tcph + tcph->doff*4;
7510 +    *ptcpdatalen = ((char*)skb->h.raw + skb->len) - *pptcpdata;
7511 +}
7512 +
7513 +/*** nat functions ***/
7514 +
7515 +/*
7516 + * Mangle the "Transport:" header:
7517 + *   - Replace all occurences of "client_port=<spec>"
7518 + *   - Handle destination parameter
7519 + *
7520 + * In:
7521 + *   ct, ctinfo = conntrack context
7522 + *   pskb       = packet
7523 + *   tranoff    = Transport header offset from TCP data
7524 + *   tranlen    = Transport header length (incl. CRLF)
7525 + *   rport_lo   = replacement low  port (host endian)
7526 + *   rport_hi   = replacement high port (host endian)
7527 + *
7528 + * Returns packet size difference.
7529 + *
7530 + * Assumes that a complete transport header is present, ending with CR or LF
7531 + */
7532 +static int
7533 +rtsp_mangle_tran(struct ip_conntrack* ct, enum ip_conntrack_info ctinfo,
7534 +                 struct ip_conntrack_expect* exp,
7535 +                 struct sk_buff** pskb, uint tranoff, uint tranlen)
7536 +{
7537 +    char*       ptcp;
7538 +    uint        tcplen;
7539 +    char*       ptran;
7540 +    char        rbuf1[16];      /* Replacement buffer (one port) */
7541 +    uint        rbuf1len;       /* Replacement len (one port) */
7542 +    char        rbufa[16];      /* Replacement buffer (all ports) */
7543 +    uint        rbufalen;       /* Replacement len (all ports) */
7544 +    u_int32_t   newip;
7545 +    u_int16_t   loport, hiport;
7546 +    uint        off = 0;
7547 +    uint        diff;           /* Number of bytes we removed */
7548 +
7549 +    struct ip_ct_rtsp_expect* prtspexp = &exp->help.exp_rtsp_info;
7550 +    struct ip_conntrack_tuple t;
7551 +
7552 +    char    szextaddr[15+1];
7553 +    uint    extaddrlen;
7554 +    int     is_stun;
7555 +
7556 +    get_skb_tcpdata(*pskb, &ptcp, &tcplen);
7557 +    ptran = ptcp+tranoff;
7558 +
7559 +    if (tranoff+tranlen > tcplen || tcplen-tranoff < tranlen ||
7560 +        tranlen < 10 || !iseol(ptran[tranlen-1]) ||
7561 +        nf_strncasecmp(ptran, "Transport:", 10) != 0)
7562 +    {
7563 +        INFOP("sanity check failed\n");
7564 +        return 0;
7565 +    }
7566 +    off += 10;
7567 +    SKIP_WSPACE(ptcp+tranoff, tranlen, off);
7568 +
7569 +    newip = ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.ip;
7570 +    t = exp->tuple;
7571 +    t.dst.ip = newip;
7572 +
7573 +    extaddrlen = extip ? sprintf(szextaddr, "%u.%u.%u.%u", NIPQUAD(extip))
7574 +                       : sprintf(szextaddr, "%u.%u.%u.%u", NIPQUAD(newip));
7575 +    DEBUGP("stunaddr=%s (%s)\n", szextaddr, (extip?"forced":"auto"));
7576 +
7577 +    rbuf1len = rbufalen = 0;
7578 +    switch (prtspexp->pbtype)
7579 +    {
7580 +    case pb_single:
7581 +        for (loport = prtspexp->loport; loport != 0; loport++) /* XXX: improper wrap? */
7582 +        {
7583 +            t.dst.u.udp.port = htons(loport);
7584 +            if (ip_conntrack_change_expect(exp, &t) == 0)
7585 +            {
7586 +                DEBUGP("using port %hu\n", loport);
7587 +                break;
7588 +            }
7589 +        }
7590 +        if (loport != 0)
7591 +        {
7592 +            rbuf1len = sprintf(rbuf1, "%hu", loport);
7593 +            rbufalen = sprintf(rbufa, "%hu", loport);
7594 +        }
7595 +        break;
7596 +    case pb_range:
7597 +        for (loport = prtspexp->loport; loport != 0; loport += 2) /* XXX: improper wrap? */
7598 +        {
7599 +            t.dst.u.udp.port = htons(loport);
7600 +            if (ip_conntrack_change_expect(exp, &t) == 0)
7601 +            {
7602 +                hiport = loport + ~exp->mask.dst.u.udp.port;
7603 +                DEBUGP("using ports %hu-%hu\n", loport, hiport);
7604 +                break;
7605 +            }
7606 +        }
7607 +        if (loport != 0)
7608 +        {
7609 +            rbuf1len = sprintf(rbuf1, "%hu", loport);
7610 +            rbufalen = sprintf(rbufa, "%hu-%hu", loport, loport+1);
7611 +        }
7612 +        break;
7613 +    case pb_discon:
7614 +        for (loport = prtspexp->loport; loport != 0; loport++) /* XXX: improper wrap? */
7615 +        {
7616 +            t.dst.u.udp.port = htons(loport);
7617 +            if (ip_conntrack_change_expect(exp, &t) == 0)
7618 +            {
7619 +                DEBUGP("using port %hu (1 of 2)\n", loport);
7620 +                break;
7621 +            }
7622 +        }
7623 +        for (hiport = prtspexp->hiport; hiport != 0; hiport++) /* XXX: improper wrap? */
7624 +        {
7625 +            t.dst.u.udp.port = htons(hiport);
7626 +            if (ip_conntrack_change_expect(exp, &t) == 0)
7627 +            {
7628 +                DEBUGP("using port %hu (2 of 2)\n", hiport);
7629 +                break;
7630 +            }
7631 +        }
7632 +        if (loport != 0 && hiport != 0)
7633 +        {
7634 +            rbuf1len = sprintf(rbuf1, "%hu", loport);
7635 +            if (hiport == loport+1)
7636 +            {
7637 +                rbufalen = sprintf(rbufa, "%hu-%hu", loport, hiport);
7638 +            }
7639 +            else
7640 +            {
7641 +                rbufalen = sprintf(rbufa, "%hu/%hu", loport, hiport);
7642 +            }
7643 +        }
7644 +        break;
7645 +    }
7646 +
7647 +    if (rbuf1len == 0)
7648 +    {
7649 +        return 0;   /* cannot get replacement port(s) */
7650 +    }
7651 +
7652 +    /* Transport: tran;field;field=val,tran;field;field=val,... */
7653 +    while (off < tranlen)
7654 +    {
7655 +        uint        saveoff;
7656 +        const char* pparamend;
7657 +        uint        nextparamoff;
7658 +
7659 +        pparamend = memchr(ptran+off, ',', tranlen-off);
7660 +        pparamend = (pparamend == NULL) ? ptran+tranlen : pparamend+1;
7661 +        nextparamoff = pparamend-ptcp;
7662 +
7663 +        /*
7664 +         * We pass over each param twice.  On the first pass, we look for a
7665 +         * destination= field.  It is handled by the security policy.  If it
7666 +         * is present, allowed, and equal to our external address, we assume
7667 +         * that STUN is being used and we leave the client_port= field alone.
7668 +         */
7669 +        is_stun = 0;
7670 +        saveoff = off;
7671 +        while (off < nextparamoff)
7672 +        {
7673 +            const char* pfieldend;
7674 +            uint        nextfieldoff;
7675 +
7676 +            pfieldend = memchr(ptran+off, ';', nextparamoff-off);
7677 +            nextfieldoff = (pfieldend == NULL) ? nextparamoff : pfieldend-ptran+1;
7678 +
7679 +            if (dstact != DSTACT_NONE && strncmp(ptran+off, "destination=", 12) == 0)
7680 +            {
7681 +                if (strncmp(ptran+off+12, szextaddr, extaddrlen) == 0)
7682 +                {
7683 +                    is_stun = 1;
7684 +                }
7685 +                if (dstact == DSTACT_STRIP || (dstact == DSTACT_AUTO && !is_stun))
7686 +                {
7687 +                    diff = nextfieldoff-off;
7688 +                    if (!ip_nat_mangle_tcp_packet(pskb, ct, ctinfo,
7689 +                                                         off, diff, NULL, 0))
7690 +                    {
7691 +                        /* mangle failed, all we can do is bail */
7692 +                        return 0;
7693 +                    }
7694 +                    get_skb_tcpdata(*pskb, &ptcp, &tcplen);
7695 +                    ptran = ptcp+tranoff;
7696 +                    tranlen -= diff;
7697 +                    nextparamoff -= diff;
7698 +                    nextfieldoff -= diff;
7699 +                }
7700 +            }
7701 +
7702 +            off = nextfieldoff;
7703 +        }
7704 +        if (is_stun)
7705 +        {
7706 +            continue;
7707 +        }
7708 +        off = saveoff;
7709 +        while (off < nextparamoff)
7710 +        {
7711 +            const char* pfieldend;
7712 +            uint        nextfieldoff;
7713 +
7714 +            pfieldend = memchr(ptran+off, ';', nextparamoff-off);
7715 +            nextfieldoff = (pfieldend == NULL) ? nextparamoff : pfieldend-ptran+1;
7716 +
7717 +            if (strncmp(ptran+off, "client_port=", 12) == 0)
7718 +            {
7719 +                u_int16_t   port;
7720 +                uint        numlen;
7721 +                uint        origoff;
7722 +                uint        origlen;
7723 +                char*       rbuf    = rbuf1;
7724 +                uint        rbuflen = rbuf1len;
7725 +
7726 +                off += 12;
7727 +                origoff = (ptran-ptcp)+off;
7728 +                origlen = 0;
7729 +                numlen = nf_strtou16(ptran+off, &port);
7730 +                off += numlen;
7731 +                origlen += numlen;
7732 +                if (port != prtspexp->loport)
7733 +                {
7734 +                    DEBUGP("multiple ports found, port %hu ignored\n", port);
7735 +                }
7736 +                else
7737 +                {
7738 +                    if (ptran[off] == '-' || ptran[off] == '/')
7739 +                    {
7740 +                        off++;
7741 +                        origlen++;
7742 +                        numlen = nf_strtou16(ptran+off, &port);
7743 +                        off += numlen;
7744 +                        origlen += numlen;
7745 +                        rbuf = rbufa;
7746 +                        rbuflen = rbufalen;
7747 +                    }
7748 +
7749 +                    /*
7750 +                     * note we cannot just memcpy() if the sizes are the same.
7751 +                     * the mangle function does skb resizing, checks for a
7752 +                     * cloned skb, and updates the checksums.
7753 +                     *
7754 +                     * parameter 4 below is offset from start of tcp data.
7755 +                     */
7756 +                    diff = origlen-rbuflen;
7757 +                    if (!ip_nat_mangle_tcp_packet(pskb, ct, ctinfo,
7758 +                                              origoff, origlen, rbuf, rbuflen))
7759 +                    {
7760 +                        /* mangle failed, all we can do is bail */
7761 +                        return 0;
7762 +                    }
7763 +                    get_skb_tcpdata(*pskb, &ptcp, &tcplen);
7764 +                    ptran = ptcp+tranoff;
7765 +                    tranlen -= diff;
7766 +                    nextparamoff -= diff;
7767 +                    nextfieldoff -= diff;
7768 +                }
7769 +            }
7770 +
7771 +            off = nextfieldoff;
7772 +        }
7773 +
7774 +        off = nextparamoff;
7775 +    }
7776 +
7777 +    return 1;
7778 +}
7779 +
7780 +static unsigned int
7781 +expected(struct sk_buff **pskb, uint hooknum, struct ip_conntrack* ct, struct ip_nat_info* info)
7782 +{
7783 +    struct ip_nat_multi_range mr;
7784 +    u_int32_t newdstip, newsrcip, newip;
7785 +
7786 +    struct ip_conntrack *master = master_ct(ct);
7787 +
7788 +    IP_NF_ASSERT(info);
7789 +    IP_NF_ASSERT(master);
7790 +
7791 +    IP_NF_ASSERT(!(info->initialized & (1 << HOOK2MANIP(hooknum))));
7792 +
7793 +    newdstip = master->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.ip;
7794 +    newsrcip = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.ip;
7795 +    newip = (HOOK2MANIP(hooknum) == IP_NAT_MANIP_SRC) ? newsrcip : newdstip;
7796 +
7797 +    DEBUGP("newsrcip=%u.%u.%u.%u, newdstip=%u.%u.%u.%u, newip=%u.%u.%u.%u\n",
7798 +           NIPQUAD(newsrcip), NIPQUAD(newdstip), NIPQUAD(newip));
7799 +
7800 +    mr.rangesize = 1;
7801 +    /* We don't want to manip the per-protocol, just the IPs. */
7802 +    mr.range[0].flags = IP_NAT_RANGE_MAP_IPS;
7803 +    mr.range[0].min_ip = mr.range[0].max_ip = newip;
7804 +
7805 +    return ip_nat_setup_info(ct, &mr, hooknum);
7806 +}
7807 +
7808 +static uint
7809 +help_out(struct ip_conntrack* ct, enum ip_conntrack_info ctinfo,
7810 +         struct ip_conntrack_expect* exp, struct sk_buff** pskb)
7811 +{
7812 +    char*   ptcp;
7813 +    uint    tcplen;
7814 +    uint    hdrsoff;
7815 +    uint    hdrslen;
7816 +    uint    lineoff;
7817 +    uint    linelen;
7818 +    uint    off;
7819 +
7820 +    struct iphdr* iph = (struct iphdr*)(*pskb)->nh.iph;
7821 +    struct tcphdr* tcph = (struct tcphdr*)((void*)iph + iph->ihl*4);
7822 +
7823 +    struct ip_ct_rtsp_expect* prtspexp = &exp->help.exp_rtsp_info;
7824 +
7825 +    get_skb_tcpdata(*pskb, &ptcp, &tcplen);
7826 +
7827 +    hdrsoff = exp->seq - ntohl(tcph->seq);
7828 +    hdrslen = prtspexp->len;
7829 +    off = hdrsoff;
7830 +
7831 +    while (nf_mime_nextline(ptcp, hdrsoff+hdrslen, &off, &lineoff, &linelen))
7832 +    {
7833 +        if (linelen == 0)
7834 +        {
7835 +            break;
7836 +        }
7837 +        if (off > hdrsoff+hdrslen)
7838 +        {
7839 +            INFOP("!! overrun !!");
7840 +            break;
7841 +        }
7842 +        DEBUGP("hdr: len=%u, %.*s", linelen, (int)linelen, ptcp+lineoff);
7843 +
7844 +        if (nf_strncasecmp(ptcp+lineoff, "Transport:", 10) == 0)
7845 +        {
7846 +            uint oldtcplen = tcplen;
7847 +            if (!rtsp_mangle_tran(ct, ctinfo, exp, pskb, lineoff, linelen))
7848 +            {
7849 +                break;
7850 +            }
7851 +            get_skb_tcpdata(*pskb, &ptcp, &tcplen);
7852 +            hdrslen -= (oldtcplen-tcplen);
7853 +            off -= (oldtcplen-tcplen);
7854 +            lineoff -= (oldtcplen-tcplen);
7855 +            linelen -= (oldtcplen-tcplen);
7856 +            DEBUGP("rep: len=%u, %.*s", linelen, (int)linelen, ptcp+lineoff);
7857 +        }
7858 +    }
7859 +
7860 +    return NF_ACCEPT;
7861 +}
7862 +
7863 +static uint
7864 +help_in(struct ip_conntrack* ct, enum ip_conntrack_info ctinfo,
7865 +         struct ip_conntrack_expect* exp, struct sk_buff** pskb)
7866 +{
7867 +    /* XXX: unmangle */
7868 +    return NF_ACCEPT;
7869 +}
7870 +
7871 +static uint
7872 +help(struct ip_conntrack* ct,
7873 +     struct ip_conntrack_expect* exp,
7874 +     struct ip_nat_info* info,
7875 +     enum ip_conntrack_info ctinfo,
7876 +     unsigned int hooknum,
7877 +     struct sk_buff** pskb)
7878 +{
7879 +    struct iphdr*  iph  = (struct iphdr*)(*pskb)->nh.iph;
7880 +    struct tcphdr* tcph = (struct tcphdr*)((char*)iph + iph->ihl * 4);
7881 +    uint datalen;
7882 +    int dir;
7883 +    struct ip_ct_rtsp_expect* ct_rtsp_info;
7884 +    int rc = NF_ACCEPT;
7885 +
7886 +    if (ct == NULL || exp == NULL || info == NULL || pskb == NULL)
7887 +    {
7888 +        DEBUGP("!! null ptr (%p,%p,%p,%p) !!\n", ct, exp, info, pskb);
7889 +        return NF_ACCEPT;
7890 +    }
7891 +
7892 +    ct_rtsp_info = &exp->help.exp_rtsp_info;
7893 +
7894 +    /*
7895 +     * Only mangle things once: original direction in POST_ROUTING
7896 +     * and reply direction on PRE_ROUTING.
7897 +     */
7898 +    dir = CTINFO2DIR(ctinfo);
7899 +    if (!((hooknum == NF_IP_POST_ROUTING && dir == IP_CT_DIR_ORIGINAL)
7900 +          || (hooknum == NF_IP_PRE_ROUTING && dir == IP_CT_DIR_REPLY)))
7901 +    {
7902 +        DEBUGP("Not touching dir %s at hook %s\n",
7903 +               dir == IP_CT_DIR_ORIGINAL ? "ORIG" : "REPLY",
7904 +               hooknum == NF_IP_POST_ROUTING ? "POSTROUTING"
7905 +               : hooknum == NF_IP_PRE_ROUTING ? "PREROUTING"
7906 +               : hooknum == NF_IP_LOCAL_OUT ? "OUTPUT" : "???");
7907 +        return NF_ACCEPT;
7908 +    }
7909 +    DEBUGP("got beyond not touching\n");
7910 +
7911 +    datalen = (*pskb)->len - iph->ihl * 4 - tcph->doff * 4;
7912 +
7913 +    LOCK_BH(&ip_rtsp_lock);
7914 +    /* Ensure the packet contains all of the marked data */
7915 +    if (!between(exp->seq + ct_rtsp_info->len,
7916 +                 ntohl(tcph->seq), ntohl(tcph->seq) + datalen))
7917 +    {
7918 +        /* Partial retransmission?  Probably a hacker. */
7919 +        if (net_ratelimit())
7920 +        {
7921 +            INFOP("partial packet %u/%u in %u/%u\n",
7922 +                   exp->seq, ct_rtsp_info->len, ntohl(tcph->seq), ntohl(tcph->seq) + datalen);
7923 +        }
7924 +        UNLOCK_BH(&ip_rtsp_lock);
7925 +        return NF_DROP;
7926 +    }
7927 +
7928 +    switch (dir)
7929 +    {
7930 +    case IP_CT_DIR_ORIGINAL:
7931 +        rc = help_out(ct, ctinfo, exp, pskb);
7932 +        break;
7933 +    case IP_CT_DIR_REPLY:
7934 +        rc = help_in(ct, ctinfo, exp, pskb);
7935 +        break;
7936 +    }
7937 +    UNLOCK_BH(&ip_rtsp_lock);
7938 +
7939 +    return rc;
7940 +}
7941 +
7942 +static struct ip_nat_helper ip_nat_rtsp_helpers[MAX_PORTS];
7943 +static char rtsp_names[MAX_PORTS][10];
7944 +
7945 +/* This function is intentionally _NOT_ defined as  __exit */
7946 +static void
7947 +fini(void)
7948 +{
7949 +    int i;
7950 +
7951 +    for (i = 0; i < num_ports; i++)
7952 +    {
7953 +        DEBUGP("unregistering helper for port %d\n", ports[i]);
7954 +        ip_nat_helper_unregister(&ip_nat_rtsp_helpers[i]);
7955 +    }
7956 +}
7957 +
7958 +static int __init
7959 +init(void)
7960 +{
7961 +    int ret = 0;
7962 +    int i;
7963 +    struct ip_nat_helper* hlpr;
7964 +    char* tmpname;
7965 +
7966 +    printk("ip_nat_rtsp v" IP_NF_RTSP_VERSION " loading\n");
7967 +
7968 +    if (ports[0] == 0)
7969 +    {
7970 +        ports[0] = RTSP_PORT;
7971 +    }
7972 +
7973 +    for (i = 0; (i < MAX_PORTS) && ports[i] != 0; i++)
7974 +    {
7975 +        hlpr = &ip_nat_rtsp_helpers[i];
7976 +        memset(hlpr, 0, sizeof(struct ip_nat_helper));
7977 +
7978 +        hlpr->tuple.dst.protonum = IPPROTO_TCP;
7979 +        hlpr->tuple.src.u.tcp.port = htons(ports[i]);
7980 +        hlpr->mask.src.u.tcp.port = 0xFFFF;
7981 +        hlpr->mask.dst.protonum = 0xFFFF;
7982 +        hlpr->help = help;
7983 +        hlpr->flags = 0;
7984 +        hlpr->me = THIS_MODULE;
7985 +        hlpr->expect = expected;
7986 +
7987 +        tmpname = &rtsp_names[i][0];
7988 +        if (ports[i] == RTSP_PORT)
7989 +        {
7990 +                sprintf(tmpname, "rtsp");
7991 +        }
7992 +        else
7993 +        {
7994 +                sprintf(tmpname, "rtsp-%d", i);
7995 +        }
7996 +        hlpr->name = tmpname;
7997 +
7998 +        DEBUGP("registering helper for port %d: name %s\n", ports[i], hlpr->name);
7999 +        ret = ip_nat_helper_register(hlpr);
8000 +
8001 +        if (ret)
8002 +        {
8003 +            printk("ip_nat_rtsp: error registering helper for port %d\n", ports[i]);
8004 +            fini();
8005 +            return 1;
8006 +        }
8007 +        num_ports++;
8008 +    }
8009 +    if (stunaddr != NULL)
8010 +    {
8011 +        extip = in_aton(stunaddr);
8012 +    }
8013 +    if (destaction != NULL)
8014 +    {
8015 +        if (strcmp(destaction, "auto") == 0)
8016 +        {
8017 +            dstact = DSTACT_AUTO;
8018 +        }
8019 +        if (strcmp(destaction, "strip") == 0)
8020 +        {
8021 +            dstact = DSTACT_STRIP;
8022 +        }
8023 +        if (strcmp(destaction, "none") == 0)
8024 +        {
8025 +            dstact = DSTACT_NONE;
8026 +        }
8027 +    }
8028 +    return ret;
8029 +}
8030 +
8031 +module_init(init);
8032 +module_exit(fini);
8033 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/netfilter/ip_nat_rule.c linux-2.6.7-rc3/net/ipv4/netfilter/ip_nat_rule.c
8034 --- linux-2.6.7-rc3.org/net/ipv4/netfilter/ip_nat_rule.c        2004-06-07 21:14:10.000000000 +0200
8035 +++ linux-2.6.7-rc3/net/ipv4/netfilter/ip_nat_rule.c    2004-06-08 10:37:30.000000000 +0200
8036 @@ -75,7 +75,7 @@
8037                 0,
8038                 sizeof(struct ipt_entry),
8039                 sizeof(struct ipt_standard),
8040 -               0, { 0, 0 }, { } },
8041 +               0, NULL, 0, { 0, 0 }, { } },
8042               { { { { IPT_ALIGN(sizeof(struct ipt_standard_target)), "" } }, { } },
8043                 -NF_ACCEPT - 1 } },
8044             /* POST_ROUTING */
8045 @@ -83,7 +83,7 @@
8046                 0,
8047                 sizeof(struct ipt_entry),
8048                 sizeof(struct ipt_standard),
8049 -               0, { 0, 0 }, { } },
8050 +               0, NULL, 0, { 0, 0 }, { } },
8051               { { { { IPT_ALIGN(sizeof(struct ipt_standard_target)), "" } }, { } },
8052                 -NF_ACCEPT - 1 } },
8053             /* LOCAL_OUT */
8054 @@ -91,7 +91,7 @@
8055                 0,
8056                 sizeof(struct ipt_entry),
8057                 sizeof(struct ipt_standard),
8058 -               0, { 0, 0 }, { } },
8059 +               0, NULL, 0, { 0, 0 }, { } },
8060               { { { { IPT_ALIGN(sizeof(struct ipt_standard_target)), "" } }, { } },
8061                 -NF_ACCEPT - 1 } }
8062      },
8063 @@ -100,7 +100,7 @@
8064         0,
8065         sizeof(struct ipt_entry),
8066         sizeof(struct ipt_error),
8067 -       0, { 0, 0 }, { } },
8068 +       0, NULL, 0, { 0, 0 }, { } },
8069        { { { { IPT_ALIGN(sizeof(struct ipt_error_target)), IPT_ERROR_TARGET } },
8070           { } },
8071         "ERROR"
8072 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/netfilter/ip_nat_standalone.c linux-2.6.7-rc3/net/ipv4/netfilter/ip_nat_standalone.c
8073 --- linux-2.6.7-rc3.org/net/ipv4/netfilter/ip_nat_standalone.c  2004-06-07 21:14:56.000000000 +0200
8074 +++ linux-2.6.7-rc3/net/ipv4/netfilter/ip_nat_standalone.c      2004-06-08 10:38:45.000000000 +0200
8075 @@ -176,6 +176,45 @@
8076         return do_bindings(ct, ctinfo, info, hooknum, pskb);
8077  }
8078  
8079 +struct nat_route_key
8080 +{
8081 +       u_int32_t addr;
8082 +#ifdef CONFIG_XFRM
8083 +       u_int16_t port;
8084 +#endif
8085 +};
8086 +
8087 +static inline void
8088 +nat_route_key_get(struct sk_buff *skb, struct nat_route_key *key, int which)
8089 +{
8090 +       struct iphdr *iph = skb->nh.iph;
8091 +
8092 +       key->addr = which ? iph->daddr : iph->saddr;
8093 +#ifdef CONFIG_XFRM
8094 +       key->port = 0;
8095 +       if (iph->protocol == IPPROTO_TCP || iph->protocol == IPPROTO_UDP) {
8096 +               u_int16_t *ports = (u_int16_t *)(skb->nh.raw + iph->ihl*4);
8097 +               key->port = ports[which];
8098 +       }
8099 +#endif
8100 +}
8101 +
8102 +static inline int
8103 +nat_route_key_compare(struct sk_buff *skb, struct nat_route_key *key, int which)
8104 +{
8105 +       struct iphdr *iph = skb->nh.iph;
8106 +
8107 +       if (key->addr != (which ? iph->daddr : iph->saddr))
8108 +               return 1;
8109 +#ifdef CONFIG_XFRM
8110 +       if (iph->protocol == IPPROTO_TCP || iph->protocol == IPPROTO_UDP) {
8111 +               u_int16_t *ports = (u_int16_t *)(skb->nh.raw + iph->ihl*4);
8112 +               if (key->port != ports[which])
8113 +                       return 1;
8114 +       }
8115 +#endif
8116 +}
8117 +
8118  static unsigned int
8119  ip_nat_out(unsigned int hooknum,
8120            struct sk_buff **pskb,
8121 @@ -183,6 +222,9 @@
8122            const struct net_device *out,
8123            int (*okfn)(struct sk_buff *))
8124  {
8125 +       struct nat_route_key key;
8126 +       unsigned int ret;
8127 +
8128         /* root is playing with raw sockets. */
8129         if ((*pskb)->len < sizeof(struct iphdr)
8130             || (*pskb)->nh.iph->ihl * 4 < sizeof(struct iphdr))
8131 @@ -205,7 +247,29 @@
8132                         return NF_STOLEN;
8133         }
8134  
8135 -       return ip_nat_fn(hooknum, pskb, in, out, okfn);
8136 +       nat_route_key_get(*pskb, &key, 0);
8137 +       ret = ip_nat_fn(hooknum, pskb, in, out, okfn);
8138 +
8139 +       if (ret != NF_DROP && ret != NF_STOLEN
8140 +           && nat_route_key_compare(*pskb, &key, 0)) {
8141 +               if (ip_route_me_harder(pskb) != 0)
8142 +                       ret = NF_DROP;
8143 +#ifdef CONFIG_XFRM
8144 +               /*
8145 +                * POST_ROUTING hook is called with fixed outfn, we need
8146 +                * to manually confirm the packet and direct it to the
8147 +                * transformers if a policy matches.
8148 +                */
8149 +               else if ((*pskb)->dst->xfrm != NULL) {
8150 +                       ret = ip_conntrack_confirm(*pskb);
8151 +                       if (ret != NF_DROP) {
8152 +                               dst_output(*pskb);
8153 +                               ret = NF_STOLEN;
8154 +                       }
8155 +               }
8156 +#endif
8157 +       }
8158 +       return ret;
8159  }
8160  
8161  #ifdef CONFIG_IP_NF_NAT_LOCAL
8162 @@ -216,7 +280,7 @@
8163                 const struct net_device *out,
8164                 int (*okfn)(struct sk_buff *))
8165  {
8166 -       u_int32_t saddr, daddr;
8167 +       struct nat_route_key key;
8168         unsigned int ret;
8169  
8170         /* root is playing with raw sockets. */
8171 @@ -224,14 +288,14 @@
8172             || (*pskb)->nh.iph->ihl * 4 < sizeof(struct iphdr))
8173                 return NF_ACCEPT;
8174  
8175 -       saddr = (*pskb)->nh.iph->saddr;
8176 -       daddr = (*pskb)->nh.iph->daddr;
8177 -
8178 +       nat_route_key_get(*pskb, &key, 1);
8179         ret = ip_nat_fn(hooknum, pskb, in, out, okfn);
8180 +
8181         if (ret != NF_DROP && ret != NF_STOLEN
8182 -           && ((*pskb)->nh.iph->saddr != saddr
8183 -               || (*pskb)->nh.iph->daddr != daddr))
8184 -               return ip_route_me_harder(pskb) == 0 ? ret : NF_DROP;
8185 +           && nat_route_key_compare(*pskb, &key, 1)) {
8186 +               if (ip_route_me_harder(pskb) != 0)
8187 +                       ret = NF_DROP;
8188 +       }
8189         return ret;
8190  }
8191  #endif
8192 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/netfilter/ip_nat_talk.c linux-2.6.7-rc3/net/ipv4/netfilter/ip_nat_talk.c
8193 --- linux-2.6.7-rc3.org/net/ipv4/netfilter/ip_nat_talk.c        1970-01-01 01:00:00.000000000 +0100
8194 +++ linux-2.6.7-rc3/net/ipv4/netfilter/ip_nat_talk.c    2004-06-08 10:41:27.000000000 +0200
8195 @@ -0,0 +1,473 @@
8196 +/* 
8197 + * talk extension for UDP NAT alteration. 
8198 + * Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
8199 + *
8200 + *      This program is free software; you can redistribute it and/or
8201 + *      modify it under the terms of the GNU General Public License
8202 + *      as published by the Free Software Foundation; either version
8203 + *      2 of the License, or (at your option) any later version.
8204 + **
8205 + *     Module load syntax:
8206 + *     insmod ip_nat_talk.o talk=[0|1] ntalk=[0|1] ntalk2=[0|1]
8207 + *
8208 + *             talk=[0|1]      disable|enable old talk support
8209 + *            ntalk=[0|1]      disable|enable ntalk support
8210 + *           ntalk2=[0|1]      disable|enable ntalk2 support
8211 + *
8212 + *     The default is talk=1 ntalk=1 ntalk2=1
8213 + *
8214 + *  
8215 + */
8216 +#include <linux/module.h>
8217 +#include <linux/netfilter_ipv4.h>
8218 +#include <linux/ip.h>
8219 +#include <linux/udp.h>
8220 +#include <linux/kernel.h>
8221 +#include <net/tcp.h>
8222 +#include <net/udp.h>
8223 +
8224 +#include <linux/netfilter_ipv4/ip_nat.h>
8225 +#include <linux/netfilter_ipv4/ip_nat_helper.h>
8226 +#include <linux/netfilter_ipv4/ip_nat_rule.h>
8227 +#include <linux/netfilter_ipv4/ip_conntrack_talk.h>
8228 +#include <linux/netfilter_ipv4/ip_conntrack_helper.h>
8229 +
8230 +/* Default all talk protocols are supported */
8231 +static int talk   = 1;
8232 +static int ntalk  = 1;
8233 +static int ntalk2 = 1;
8234 +MODULE_AUTHOR("Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>");
8235 +MODULE_DESCRIPTION("talk network address translation module");
8236 +#ifdef MODULE_PARM
8237 +MODULE_PARM(talk, "i");
8238 +MODULE_PARM_DESC(talk, "support (old) talk protocol");
8239 +MODULE_PARM(ntalk, "i");
8240 +MODULE_PARM_DESC(ntalk, "support ntalk protocol");
8241 +MODULE_PARM(ntalk2, "i");
8242 +MODULE_PARM_DESC(ntalk2, "support ntalk2 protocol");
8243 +#endif
8244 +
8245 +#if 0
8246 +#define DEBUGP printk
8247 +#define IP_NAT_TALK_DEBUG
8248 +#else
8249 +#define DEBUGP(format, args...)
8250 +#endif
8251 +
8252 +/* FIXME: Time out? --RR */
8253 +
8254 +static int
8255 +mangle_packet(struct sk_buff **pskb,
8256 +             struct ip_conntrack *ct,
8257 +             u_int32_t newip,
8258 +             u_int16_t port,
8259 +             struct talk_addr *addr,
8260 +             struct talk_addr *ctl_addr)
8261 +{
8262 +       struct iphdr *iph = (*pskb)->nh.iph;
8263 +       struct udphdr *udph = (void *)iph + iph->ihl * 4;
8264 +       size_t udplen = (*pskb)->len - iph->ihl * 4;
8265 +
8266 +       /* Fortunately talk sends a structure with the address and
8267 +          port in it. The size of the packet won't change. */
8268 +
8269 +       if (ctl_addr == NULL) {
8270 +               /* response */
8271 +               if (addr->ta_addr == INADDR_ANY)
8272 +                       return 1;
8273 +               DEBUGP("ip_nat_talk_mangle_packet: response orig %u.%u.%u.%u:%u, inserting %u.%u.%u.%u:%u\n", 
8274 +                      NIPQUAD(addr->ta_addr), ntohs(addr->ta_port),
8275 +                      NIPQUAD(newip), ntohs(port));
8276 +               addr->ta_addr = newip;
8277 +               addr->ta_port = port;
8278 +       } else {
8279 +               /* message */
8280 +               if (addr->ta_addr != INADDR_ANY) {
8281 +                       /* Change address inside packet to match way we're mapping
8282 +                          this connection. */
8283 +                       DEBUGP("ip_nat_talk_mangle_packet: message orig addr %u.%u.%u.%u:%u, inserting %u.%u.%u.%u:%u\n", 
8284 +                              NIPQUAD(addr->ta_addr), ntohs(addr->ta_port),
8285 +                              NIPQUAD(ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.ip), 
8286 +                              ntohs(addr->ta_port));
8287 +                       addr->ta_addr = ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.ip;
8288 +               }
8289 +               DEBUGP("ip_nat_talk_mangle_packet: message orig ctl_addr %u.%u.%u.%u:%u, inserting %u.%u.%u.%u:%u\n", 
8290 +                      NIPQUAD(ctl_addr->ta_addr), ntohs(ctl_addr->ta_port),
8291 +                      NIPQUAD(newip), ntohs(port));
8292 +               ctl_addr->ta_addr = newip;
8293 +               ctl_addr->ta_port = port;
8294 +       }
8295 +
8296 +       /* Fix checksums */
8297 +       (*pskb)->csum = csum_partial((char *)udph + sizeof(struct udphdr), udplen - sizeof(struct udphdr), 0);
8298 +       udph->check = 0;
8299 +       udph->check = csum_tcpudp_magic(iph->saddr, iph->daddr, udplen, IPPROTO_UDP,
8300 +                                       csum_partial((char *)udph, sizeof(struct udphdr), (*pskb)->csum));
8301 +               
8302 +       ip_send_check(iph);
8303 +       return 1;
8304 +}
8305 +
8306 +static int talk_help_msg(struct ip_conntrack *ct,
8307 +                        struct sk_buff **pskb,
8308 +                        u_char type,
8309 +                        struct talk_addr *addr,
8310 +                        struct talk_addr *ctl_addr)
8311 +{
8312 +       u_int32_t newip;
8313 +       u_int16_t port;
8314 +       
8315 +       unsigned int verdict = NF_ACCEPT;
8316 +
8317 +       DEBUGP("ip_nat_talk_help_msg: addr: %u.%u.%u.%u:%u, ctl_addr: %u.%u.%u.%u:%u, type %d\n",
8318 +               NIPQUAD(addr->ta_addr), ntohs(addr->ta_port),
8319 +               NIPQUAD(ctl_addr->ta_addr), ntohs(ctl_addr->ta_port),
8320 +               type);
8321 +
8322 +       /* Change address inside packet to match way we're mapping
8323 +          this connection. */
8324 +       newip = ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.ip;
8325 +       port  = ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.u.udp.port;
8326 +       DEBUGP("ip_nat_talk_help_msg: inserting: %u.%u.%u.%u:%u\n",
8327 +               NIPQUAD(newip), ntohs(port));
8328 +
8329 +       if (!mangle_packet(pskb, ct, newip, port, addr, ctl_addr))
8330 +               verdict = NF_DROP;
8331 +
8332 +       return verdict;
8333 +}
8334 +
8335 +static int talk_help_response(struct ip_conntrack *ct,
8336 +                             struct ip_conntrack_expect *exp,
8337 +                             struct sk_buff **pskb,
8338 +                             u_char type,
8339 +                             u_char answer,
8340 +                             struct talk_addr *addr)
8341 +{
8342 +       u_int32_t newip;
8343 +       u_int16_t port;
8344 +       struct ip_conntrack_tuple t;
8345 +       struct ip_ct_talk_expect *ct_talk_info;
8346 +
8347 +       DEBUGP("ip_nat_talk_help_response: addr: %u.%u.%u.%u:%u, type %d answer %d\n",
8348 +               NIPQUAD(addr->ta_addr), ntohs(addr->ta_port),
8349 +               type, answer);
8350 +       
8351 +       LOCK_BH(&ip_talk_lock);
8352 +       ct_talk_info = &exp->help.exp_talk_info;
8353 +
8354 +       if (!(answer == SUCCESS 
8355 +             && (type == LOOK_UP || type == ANNOUNCE)
8356 +             && exp != NULL)) {
8357 +               UNLOCK_BH(&ip_talk_lock);
8358 +               return NF_ACCEPT;
8359 +       }
8360 +               
8361 +       DEBUGP("ip_nat_talk_help_response: talkinfo port %u (%s)\n", 
8362 +               ntohs(ct_talk_info->port), 
8363 +               type == LOOK_UP ? "LOOK_UP" : "ANNOUNCE");
8364 +
8365 +       /* Change address inside packet to match way we're mapping
8366 +          this connection. */
8367 +       newip = ct->tuplehash[type == LOOK_UP ? IP_CT_DIR_ORIGINAL : 
8368 +                                               IP_CT_DIR_REPLY].tuple.dst.ip;
8369 +       /* We can read expect here without conntrack lock, since it's
8370 +          only set in ip_conntrack_talk , with ip_talk_lock held
8371 +          writable */ 
8372 +       t = exp->tuple;
8373 +       t.dst.ip = newip;
8374 +
8375 +       /* Try to get same port: if not, try to change it. */
8376 +       for (port = ntohs(ct_talk_info->port); port != 0; port++) {
8377 +               if (type == LOOK_UP)
8378 +                       t.dst.u.tcp.port = htons(port);
8379 +               else
8380 +                       t.dst.u.udp.port = htons(port);
8381 +
8382 +               if (ip_conntrack_change_expect(exp, &t) == 0) {
8383 +                       DEBUGP("ip_nat_talk_help_response: using %u.%u.%u.%u:%u\n", NIPQUAD(newip), port);
8384 +                       break;
8385 +               }
8386 +       }
8387 +       UNLOCK_BH(&ip_talk_lock);
8388 +
8389 +       if (port == 0 || !mangle_packet(pskb, ct, newip, htons(port), addr, NULL))
8390 +               return NF_DROP;
8391 +       
8392 +       return NF_ACCEPT;
8393 +}
8394 +
8395 +static unsigned int talk_help(struct ip_conntrack *ct,
8396 +                             struct ip_conntrack_expect *exp,
8397 +                             struct ip_nat_info *info,
8398 +                             enum ip_conntrack_info ctinfo,
8399 +                             unsigned int hooknum,
8400 +                             struct sk_buff **pskb,
8401 +                             int talk_port)
8402 +{
8403 +       struct iphdr *iph = (*pskb)->nh.iph;
8404 +       struct udphdr *udph = (void *)iph + iph->ihl * 4;
8405 +       unsigned int udplen = (*pskb)->len - iph->ihl * 4;
8406 +       char *data = (char *)udph + sizeof(struct udphdr);
8407 +       int dir;
8408 +
8409 +       /* Only mangle things once: original direction in POST_ROUTING
8410 +          and reply direction on PRE_ROUTING. */
8411 +       dir = CTINFO2DIR(ctinfo);
8412 +       if (!((hooknum == NF_IP_POST_ROUTING && dir == IP_CT_DIR_ORIGINAL)
8413 +             || (hooknum == NF_IP_PRE_ROUTING && dir == IP_CT_DIR_REPLY))) {
8414 +               DEBUGP("ip_nat_talk_help: Not touching dir %s at hook %s\n",
8415 +                      dir == IP_CT_DIR_ORIGINAL ? "ORIG" : "REPLY",
8416 +                      hooknum == NF_IP_POST_ROUTING ? "POSTROUTING"
8417 +                      : hooknum == NF_IP_PRE_ROUTING ? "PREROUTING"
8418 +                      : hooknum == NF_IP_LOCAL_OUT ? "OUTPUT" : "???");
8419 +               return NF_ACCEPT;
8420 +       }
8421 +       DEBUGP("ip_nat_talk_help: dir %s at hook %s, %u.%u.%u.%u:%u->%u.%u.%u.%u:%u, talk port %d\n",
8422 +              dir == IP_CT_DIR_ORIGINAL ? "ORIG" : "REPLY",
8423 +              hooknum == NF_IP_POST_ROUTING ? "POSTROUTING"
8424 +              : hooknum == NF_IP_PRE_ROUTING ? "PREROUTING"
8425 +              : hooknum == NF_IP_LOCAL_OUT ? "OUTPUT" : "???",
8426 +              NIPQUAD(iph->saddr), ntohs(udph->source),
8427 +              NIPQUAD(iph->daddr), ntohs(udph->dest),
8428 +              talk_port);
8429 +
8430 +       /* Because conntrack does not drop packets, checking must be repeated here... */
8431 +       if (talk_port == TALK_PORT) {
8432 +               if (dir == IP_CT_DIR_ORIGINAL
8433 +                   && udplen == sizeof(struct udphdr) + sizeof(struct talk_msg))
8434 +                       return talk_help_msg(ct, pskb,
8435 +                                            ((struct talk_msg *)data)->type, 
8436 +                                            &(((struct talk_msg *)data)->addr),
8437 +                                            &(((struct talk_msg *)data)->ctl_addr));
8438 +               else if (dir == IP_CT_DIR_REPLY
8439 +                        && udplen == sizeof(struct udphdr) + sizeof(struct talk_response))
8440 +                       return talk_help_response(ct, exp, pskb,
8441 +                                                 ((struct talk_response *)data)->type, 
8442 +                                                 ((struct talk_response *)data)->answer,
8443 +                                                 &(((struct talk_response *)data)->addr));
8444 +               else {  
8445 +                       DEBUGP("ip_nat_talk_help: not talk %s, datalen %u != %u\n",
8446 +                              dir == IP_CT_DIR_ORIGINAL ? "message" : "response", 
8447 +                              (unsigned)udplen - sizeof(struct udphdr), 
8448 +                              dir == IP_CT_DIR_ORIGINAL ? sizeof(struct talk_msg) : sizeof(struct talk_response));
8449 +                       return NF_DROP;
8450 +               }
8451 +       } else {
8452 +               if (dir == IP_CT_DIR_ORIGINAL) {
8453 +                       if (ntalk
8454 +                           && udplen == sizeof(struct udphdr) + sizeof(struct ntalk_msg)
8455 +                           && ((struct ntalk_msg *)data)->vers == NTALK_VERSION)
8456 +                               return talk_help_msg(ct, pskb,
8457 +                                                    ((struct ntalk_msg *)data)->type, 
8458 +                                                    &(((struct ntalk_msg *)data)->addr),
8459 +                                                    &(((struct ntalk_msg *)data)->ctl_addr));
8460 +                       else if (ntalk2
8461 +                                && udplen >= sizeof(struct udphdr) + sizeof(struct ntalk2_msg)
8462 +                                && ((struct ntalk2_msg *)data)->vers == NTALK2_VERSION
8463 +                                && udplen == sizeof(struct udphdr) 
8464 +                                             + sizeof(struct ntalk2_msg) 
8465 +                                             + ((struct ntalk2_msg *)data)->extended)
8466 +                               return talk_help_msg(ct, pskb,
8467 +                                                    ((struct ntalk2_msg *)data)->type, 
8468 +                                                    &(((struct ntalk2_msg *)data)->addr),
8469 +                                                    &(((struct ntalk2_msg *)data)->ctl_addr));
8470 +                       else {
8471 +                               DEBUGP("ip_nat_talk_help: not ntalk/ntalk2 message, datalen %u != %u or %u + max 256\n", 
8472 +                                      (unsigned)udplen - sizeof(struct udphdr), 
8473 +                                      sizeof(struct ntalk_msg), sizeof(struct ntalk2_msg));
8474 +                               return NF_DROP;
8475 +                       }
8476 +               } else {
8477 +                       if (ntalk
8478 +                           && udplen == sizeof(struct udphdr) + sizeof(struct ntalk_response)
8479 +                           && ((struct ntalk_response *)data)->vers == NTALK_VERSION)
8480 +                               return talk_help_response(ct, exp, pskb,
8481 +                                                         ((struct ntalk_response *)data)->type, 
8482 +                                                         ((struct ntalk_response *)data)->answer,
8483 +                                                         &(((struct ntalk_response *)data)->addr));
8484 +                       else if (ntalk2
8485 +                                && udplen >= sizeof(struct udphdr) + sizeof(struct ntalk2_response)
8486 +                                && ((struct ntalk2_response *)data)->vers == NTALK2_VERSION)
8487 +                               return talk_help_response(ct, exp, pskb,
8488 +                                                         ((struct ntalk2_response *)data)->type, 
8489 +                                                         ((struct ntalk2_response *)data)->answer,
8490 +                                                         &(((struct ntalk2_response *)data)->addr));
8491 +                       else {
8492 +                               DEBUGP("ip_nat_talk_help: not ntalk/ntalk2 response, datalen %u != %u or %u + max 256\n", 
8493 +                                      (unsigned)udplen - sizeof(struct udphdr), 
8494 +                                      sizeof(struct ntalk_response), sizeof(struct ntalk2_response));
8495 +                               return NF_DROP;
8496 +                       }
8497 +               }
8498 +       }
8499 +}
8500 +
8501 +static unsigned int help(struct ip_conntrack *ct,
8502 +                        struct ip_conntrack_expect *exp,
8503 +                        struct ip_nat_info *info,
8504 +                        enum ip_conntrack_info ctinfo,
8505 +                        unsigned int hooknum,
8506 +                        struct sk_buff **pskb)
8507 +{
8508 +       return talk_help(ct, exp, info, ctinfo, hooknum, pskb, TALK_PORT);
8509 +}
8510 +
8511 +static unsigned int nhelp(struct ip_conntrack *ct,
8512 +                         struct ip_conntrack_expect *exp,
8513 +                         struct ip_nat_info *info,
8514 +                         enum ip_conntrack_info ctinfo,
8515 +                         unsigned int hooknum,
8516 +                         struct sk_buff **pskb)
8517 +{
8518 +       return talk_help(ct, exp, info, ctinfo, hooknum, pskb, NTALK_PORT);
8519 +}
8520 +
8521 +static unsigned int
8522 +talk_nat_expected(struct sk_buff **pskb,
8523 +                 unsigned int hooknum,
8524 +                 struct ip_conntrack *ct,
8525 +                 struct ip_nat_info *info);
8526 +
8527 +static struct ip_nat_helper talk_helpers[2] = 
8528 +       { { { NULL, NULL },
8529 +            "talk",                                    /* name */
8530 +            IP_NAT_HELPER_F_ALWAYS,                    /* flags */
8531 +            THIS_MODULE,                               /* module */
8532 +            { { 0, { .udp = { __constant_htons(TALK_PORT) } } }, /* tuple */
8533 +              { 0, { 0 }, IPPROTO_UDP } },
8534 +            { { 0, { .udp = { 0xFFFF } } },            /* mask */
8535 +              { 0, { 0 }, 0xFFFF } },
8536 +            help,                                      /* helper */
8537 +            talk_nat_expected },                       /* expectfn */
8538 +         { { NULL, NULL },
8539 +            "ntalk",                                   /* name */
8540 +            IP_NAT_HELPER_F_ALWAYS,                    /* flags */
8541 +            THIS_MODULE,                                       /* module */
8542 +            { { 0, { .udp = { __constant_htons(NTALK_PORT) } } }, /* tuple */
8543 +              { 0, { 0 }, IPPROTO_UDP } },
8544 +            { { 0, { .udp = { 0xFFFF } } },            /* mask */
8545 +              { 0, { 0 }, 0xFFFF } },
8546 +            nhelp,                                     /* helper */
8547 +            talk_nat_expected }                                /* expectfn */
8548 +       };
8549 +          
8550 +static unsigned int
8551 +talk_nat_expected(struct sk_buff **pskb,
8552 +                 unsigned int hooknum,
8553 +                 struct ip_conntrack *ct,
8554 +                 struct ip_nat_info *info)
8555 +{
8556 +       struct ip_nat_multi_range mr;
8557 +       u_int32_t newdstip, newsrcip, newip;
8558 +       u_int16_t port;
8559 +       unsigned int ret;
8560 +       
8561 +       struct ip_conntrack *master = master_ct(ct);
8562 +
8563 +       IP_NF_ASSERT(info);
8564 +       IP_NF_ASSERT(master);
8565 +
8566 +       IP_NF_ASSERT(!(info->initialized & (1<<HOOK2MANIP(hooknum))));
8567 +
8568 +       DEBUGP("ip_nat_talk_expected: We have a connection!\n");
8569 +
8570 +       LOCK_BH(&ip_talk_lock);
8571 +       port = ct->master->help.exp_talk_info.port;
8572 +       UNLOCK_BH(&ip_talk_lock);
8573 +
8574 +       DEBUGP("ip_nat_talk_expected: dir %s at hook %s, ct %p, master %p\n",
8575 +              CTINFO2DIR((*pskb)->nfct - ct->infos) == IP_CT_DIR_ORIGINAL ? "ORIG" : "REPLY",
8576 +              hooknum == NF_IP_POST_ROUTING ? "POSTROUTING"
8577 +              : hooknum == NF_IP_PRE_ROUTING ? "PREROUTING"
8578 +              : hooknum == NF_IP_LOCAL_OUT ? "OUTPUT" : "???",
8579 +              ct, master);
8580 +
8581 +       if (ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum == IPPROTO_UDP) {
8582 +               /* Callee client -> caller server */
8583 +#ifdef IP_NAT_TALK_DEBUG
8584 +               struct iphdr *iph = (*pskb)->nh.iph;
8585 +               struct udphdr *udph = (void *)iph + iph->ihl * 4;
8586 +
8587 +               DEBUGP("ip_nat_talk_expected: UDP %u.%u.%u.%u:%u->%u.%u.%u.%u:%u\n",
8588 +                      NIPQUAD(iph->saddr), ntohs(udph->source),
8589 +                      NIPQUAD(iph->daddr), ntohs(udph->dest));
8590 +#endif
8591 +               newdstip = master->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.ip;
8592 +               newsrcip = master->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.ip;
8593 +               DEBUGP("ip_nat_talk_expected: callee client -> caller server, newsrc: %u.%u.%u.%u, newdst: %u.%u.%u.%u\n",
8594 +                      NIPQUAD(newsrcip), NIPQUAD(newdstip));
8595 +       } else {
8596 +               /* Callee client -> caller client */
8597 +#ifdef IP_NAT_TALK_DEBUG
8598 +               struct iphdr *iph = (*pskb)->nh.iph;
8599 +               struct tcphdr *tcph = (void *)iph + iph->ihl * 4;
8600 +
8601 +               DEBUGP("ip_nat_talk_expected: TCP %u.%u.%u.%u:%u->%u.%u.%u.%u:%u\n",
8602 +                      NIPQUAD(iph->saddr), ntohs(tcph->source),
8603 +                      NIPQUAD(iph->daddr), ntohs(tcph->dest));
8604 +#endif
8605 +               newdstip = master->tuplehash[IP_CT_DIR_REPLY].tuple.src.ip;
8606 +               newsrcip = master->tuplehash[IP_CT_DIR_REPLY].tuple.dst.ip;
8607 +               DEBUGP("ip_nat_talk_expected: callee client -> caller client, newsrc: %u.%u.%u.%u, newdst: %u.%u.%u.%u\n",
8608 +                      NIPQUAD(newsrcip), NIPQUAD(newdstip));
8609 +       }
8610 +       if (HOOK2MANIP(hooknum) == IP_NAT_MANIP_SRC)
8611 +               newip = newsrcip;
8612 +       else
8613 +               newip = newdstip;
8614 +
8615 +       DEBUGP("ip_nat_talk_expected: IP to %u.%u.%u.%u, port %u\n", NIPQUAD(newip), ntohs(port));
8616 +
8617 +       mr.rangesize = 1;
8618 +       /* We don't want to manip the per-protocol, just the IPs... */
8619 +       mr.range[0].flags = IP_NAT_RANGE_MAP_IPS;
8620 +       mr.range[0].min_ip = mr.range[0].max_ip = newip;
8621 +       
8622 +       /* ... unless we're doing a MANIP_DST, in which case, make
8623 +          sure we map to the correct port */
8624 +       if (HOOK2MANIP(hooknum) == IP_NAT_MANIP_DST) {
8625 +               mr.range[0].flags |= IP_NAT_RANGE_PROTO_SPECIFIED;
8626 +               mr.range[0].min = mr.range[0].max
8627 +                       = ((union ip_conntrack_manip_proto)
8628 +                               { .udp = { port } });
8629 +       }
8630 +       ret = ip_nat_setup_info(ct, &mr, hooknum);
8631 +
8632 +       if (ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum == IPPROTO_UDP) {
8633 +               DEBUGP("talk_expected: setting NAT helper for %p\n", ct);
8634 +               /* NAT expectfn called with ip_nat_lock write-locked */
8635 +               info->helper = &talk_helpers[htons(port) - TALK_PORT];
8636 +       }
8637 +       return ret;
8638 +}
8639 +
8640 +static int __init init(void)
8641 +{
8642 +       int ret = 0;
8643 +
8644 +       if (talk > 0) {
8645 +               ret = ip_nat_helper_register(&talk_helpers[0]);
8646 +
8647 +               if (ret != 0)
8648 +                       return ret;
8649 +       }
8650 +       if (ntalk > 0 || ntalk2 > 0) {
8651 +               ret = ip_nat_helper_register(&talk_helpers[1]);
8652 +
8653 +               if (ret != 0 && talk > 0)
8654 +                       ip_nat_helper_unregister(&talk_helpers[0]);
8655 +       }
8656 +       return ret;
8657 +}
8658 +
8659 +static void __exit fini(void)
8660 +{
8661 +       if (talk > 0)
8662 +               ip_nat_helper_unregister(&talk_helpers[0]);
8663 +       if (ntalk > 0 || ntalk2 > 0)
8664 +               ip_nat_helper_unregister(&talk_helpers[1]);
8665 +}
8666 +
8667 +module_init(init);
8668 +module_exit(fini);
8669 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/netfilter/ip_pool.c linux-2.6.7-rc3/net/ipv4/netfilter/ip_pool.c
8670 --- linux-2.6.7-rc3.org/net/ipv4/netfilter/ip_pool.c    1970-01-01 01:00:00.000000000 +0100
8671 +++ linux-2.6.7-rc3/net/ipv4/netfilter/ip_pool.c        2004-06-08 10:31:45.000000000 +0200
8672 @@ -0,0 +1,334 @@
8673 +/* Kernel module for IP pool management */
8674 +
8675 +#include <linux/module.h>
8676 +#include <linux/ip.h>
8677 +#include <linux/skbuff.h>
8678 +#include <linux/netfilter_ipv4/ip_tables.h>
8679 +#include <linux/netfilter_ipv4/ip_pool.h>
8680 +#include <linux/errno.h>
8681 +#include <asm/uaccess.h>
8682 +#include <asm/bitops.h>
8683 +#include <linux/interrupt.h>
8684 +#include <linux/spinlock.h>
8685 +
8686 +#if 0
8687 +#define DP printk
8688 +#else
8689 +#define DP(format, args...)
8690 +#endif
8691 +
8692 +MODULE_LICENSE("GPL");
8693 +
8694 +#define NR_POOL 16
8695 +static int nr_pool = NR_POOL;/* overwrite this when loading module */
8696 +
8697 +struct ip_pool {
8698 +       u_int32_t first_ip;     /* host byte order, included in range */
8699 +       u_int32_t last_ip;      /* host byte order, included in range */
8700 +       void *members;          /* the bitmap proper */
8701 +       int nr_use;             /* total nr. of tests through this */
8702 +       int nr_match;           /* total nr. of matches through this */
8703 +       rwlock_t lock;
8704 +};
8705 +
8706 +static struct ip_pool *POOL;
8707 +
8708 +static inline struct ip_pool *lookup(ip_pool_t index)
8709 +{
8710 +       if (index < 0 || index >= nr_pool) {
8711 +               DP("ip_pool:lookup: bad index %d\n", index);
8712 +               return 0;
8713 +       }
8714 +       return POOL+index;
8715 +}
8716 +
8717 +int ip_pool_match(ip_pool_t index, u_int32_t addr)
8718 +{
8719 +        struct ip_pool *pool = lookup(index);
8720 +       int res = 0;
8721 +
8722 +       if (!pool || !pool->members)
8723 +               return 0;
8724 +       read_lock_bh(&pool->lock);
8725 +       if (pool->members) {
8726 +               if (addr >= pool->first_ip && addr <= pool->last_ip) {
8727 +                       addr -= pool->first_ip;
8728 +                       if (test_bit(addr, pool->members)) {
8729 +                               res = 1;
8730 +#ifdef CONFIG_IP_POOL_STATISTICS
8731 +                               pool->nr_match++;
8732 +#endif
8733 +                       }
8734 +               }
8735 +#ifdef CONFIG_IP_POOL_STATISTICS
8736 +               pool->nr_use++;
8737 +#endif
8738 +       }
8739 +       read_unlock_bh(&pool->lock);
8740 +       return res;
8741 +}
8742 +EXPORT_SYMBOL(ip_pool_match);
8743 +
8744 +static int pool_change(ip_pool_t index, u_int32_t addr, int isdel)
8745 +{
8746 +       struct ip_pool *pool;
8747 +       int res = -1;
8748 +
8749 +       pool = lookup(index);
8750 +       if (    !pool || !pool->members
8751 +            || addr < pool->first_ip || addr > pool->last_ip)
8752 +               return -1;
8753 +       read_lock_bh(&pool->lock);
8754 +       if (pool->members && addr >= pool->first_ip && addr <= pool->last_ip) {
8755 +               addr -= pool->first_ip;
8756 +               res = isdel
8757 +                       ? (0 != test_and_clear_bit(addr, pool->members))
8758 +                       : (0 != test_and_set_bit(addr, pool->members));
8759 +       }
8760 +       read_unlock_bh(&pool->lock);
8761 +       return res;
8762 +}
8763 +
8764 +int ip_pool_mod(ip_pool_t index, u_int32_t addr, int isdel)
8765 +{
8766 +       int res = pool_change(index,addr,isdel);
8767 +
8768 +       if (!isdel) res = !res;
8769 +       return res;
8770 +}
8771 +EXPORT_SYMBOL(ip_pool_mod);
8772 +
8773 +static inline int bitmap_bytes(u_int32_t a, u_int32_t b)
8774 +{
8775 +       return 4*((((b-a+8)/8)+3)/4);
8776 +}
8777 +
8778 +static inline int poolbytes(ip_pool_t index)
8779 +{
8780 +       struct ip_pool *pool = lookup(index);
8781 +
8782 +       return pool ? bitmap_bytes(pool->first_ip, pool->last_ip) : 0;
8783 +}
8784 +
8785 +static int setpool(
8786 +       struct sock *sk,
8787 +       int optval,
8788 +       void *user,
8789 +       unsigned int len
8790 +) {
8791 +       struct ip_pool_request req;
8792 +
8793 +       DP("ip_pool:setpool: optval=%d, user=%p, len=%d\n", optval, user, len);
8794 +       if (!capable(CAP_NET_ADMIN))
8795 +               return -EPERM;
8796 +       if (optval != SO_IP_POOL)
8797 +               return -EBADF;
8798 +       if (len != sizeof(req))
8799 +               return -EINVAL;
8800 +       if (copy_from_user(&req, user, sizeof(req)) != 0)
8801 +               return -EFAULT;
8802 +       printk("obsolete op - upgrade your ippool(8) utility.\n");
8803 +       return -EINVAL;
8804 +}
8805 +
8806 +static int getpool(
8807 +       struct sock *sk,
8808 +       int optval,
8809 +       void *user,
8810 +       int *len
8811 +) {
8812 +       struct ip_pool_request req;
8813 +       struct ip_pool *pool;
8814 +       ip_pool_t i;
8815 +       int newbytes;
8816 +       void *newmembers;
8817 +       int res;
8818 +
8819 +       DP("ip_pool:getpool: optval=%d, user=%p\n", optval, user);
8820 +       if (!capable(CAP_NET_ADMIN))
8821 +               return -EINVAL;
8822 +       if (optval != SO_IP_POOL)
8823 +               return -EINVAL;
8824 +       if (*len != sizeof(req)) {
8825 +               return -EFAULT;
8826 +       }
8827 +       if (copy_from_user(&req, user, sizeof(req)) != 0)
8828 +               return -EFAULT;
8829 +       DP("ip_pool:getpool op=%d, index=%d\n", req.op, req.index);
8830 +       if (req.op < IP_POOL_BAD001) {
8831 +               printk("obsolete op - upgrade your ippool(8) utility.\n");
8832 +               return -EFAULT;
8833 +       }
8834 +       switch(req.op) {
8835 +       case IP_POOL_HIGH_NR:
8836 +               DP("ip_pool HIGH_NR\n");
8837 +               req.index = IP_POOL_NONE;
8838 +               for (i=0; i<nr_pool; i++)
8839 +                       if (POOL[i].members)
8840 +                               req.index = i;
8841 +               return copy_to_user(user, &req, sizeof(req));
8842 +       case IP_POOL_LOOKUP:
8843 +               DP("ip_pool LOOKUP\n");
8844 +               pool = lookup(req.index);
8845 +               if (!pool)
8846 +                       return -EINVAL;
8847 +               if (!pool->members)
8848 +                       return -EBADF;
8849 +               req.addr = htonl(pool->first_ip);
8850 +               req.addr2 = htonl(pool->last_ip);
8851 +               return copy_to_user(user, &req, sizeof(req));
8852 +       case IP_POOL_USAGE:
8853 +               DP("ip_pool USE\n");
8854 +               pool = lookup(req.index);
8855 +               if (!pool)
8856 +                       return -EINVAL;
8857 +               if (!pool->members)
8858 +                       return -EBADF;
8859 +               req.addr = pool->nr_use;
8860 +               req.addr2 = pool->nr_match;
8861 +               return copy_to_user(user, &req, sizeof(req));
8862 +       case IP_POOL_TEST_ADDR:
8863 +               DP("ip_pool TEST 0x%08x\n", req.addr);
8864 +               pool = lookup(req.index);
8865 +               if (!pool)
8866 +                       return -EINVAL;
8867 +               res = 0;
8868 +               read_lock_bh(&pool->lock);
8869 +               if (!pool->members) {
8870 +                       DP("ip_pool TEST_ADDR no members in pool\n");
8871 +                       res = -EBADF;
8872 +                       goto unlock_and_return_res;
8873 +               }
8874 +               req.addr = ntohl(req.addr);
8875 +               if (req.addr < pool->first_ip) {
8876 +                       DP("ip_pool TEST_ADDR address < pool bounds\n");
8877 +                       res = -ERANGE;
8878 +                       goto unlock_and_return_res;
8879 +               }
8880 +               if (req.addr > pool->last_ip) {
8881 +                       DP("ip_pool TEST_ADDR address > pool bounds\n");
8882 +                       res = -ERANGE;
8883 +                       goto unlock_and_return_res;
8884 +               }
8885 +               req.addr = (0 != test_bit((req.addr - pool->first_ip),
8886 +                                       pool->members));
8887 +               read_unlock_bh(&pool->lock);
8888 +               return copy_to_user(user, &req, sizeof(req));
8889 +       case IP_POOL_FLUSH:
8890 +               DP("ip_pool FLUSH not yet implemented.\n");
8891 +               return -EBUSY;
8892 +       case IP_POOL_DESTROY:
8893 +               DP("ip_pool DESTROY not yet implemented.\n");
8894 +               return -EBUSY;
8895 +       case IP_POOL_INIT:
8896 +               DP("ip_pool INIT 0x%08x-0x%08x\n", req.addr, req.addr2);
8897 +               pool = lookup(req.index);
8898 +               if (!pool)
8899 +                       return -EINVAL;
8900 +               req.addr = ntohl(req.addr);
8901 +               req.addr2 = ntohl(req.addr2);
8902 +               if (req.addr > req.addr2) {
8903 +                       DP("ip_pool INIT bad ip range\n");
8904 +                       return -EINVAL;
8905 +               }
8906 +               newbytes = bitmap_bytes(req.addr, req.addr2);
8907 +               newmembers = kmalloc(newbytes, GFP_KERNEL);
8908 +               if (!newmembers) {
8909 +                       DP("ip_pool INIT out of mem for %d bytes\n", newbytes);
8910 +                       return -ENOMEM;
8911 +               }
8912 +               memset(newmembers, 0, newbytes);
8913 +               write_lock_bh(&pool->lock);
8914 +               if (pool->members) {
8915 +                       DP("ip_pool INIT pool %d exists\n", req.index);
8916 +                       kfree(newmembers);
8917 +                       res = -EBUSY;
8918 +                       goto unlock_and_return_res;
8919 +               }
8920 +               pool->first_ip = req.addr;
8921 +               pool->last_ip = req.addr2;
8922 +               pool->nr_use = 0;
8923 +               pool->nr_match = 0;
8924 +               pool->members = newmembers;
8925 +               write_unlock_bh(&pool->lock);
8926 +               return 0;
8927 +       case IP_POOL_ADD_ADDR:
8928 +               DP("ip_pool ADD_ADDR 0x%08x\n", req.addr);
8929 +               req.addr = pool_change(req.index, ntohl(req.addr), 0);
8930 +               return copy_to_user(user, &req, sizeof(req));
8931 +       case IP_POOL_DEL_ADDR:
8932 +               DP("ip_pool DEL_ADDR 0x%08x\n", req.addr);
8933 +               req.addr = pool_change(req.index, ntohl(req.addr), 1);
8934 +               return copy_to_user(user, &req, sizeof(req));
8935 +       default:
8936 +               DP("ip_pool:getpool bad op %d\n", req.op);
8937 +               return -EINVAL;
8938 +       }
8939 +       return -EINVAL;
8940 +
8941 +unlock_and_return_res:
8942 +       if (pool)
8943 +               read_unlock_bh(&pool->lock);
8944 +       return res;
8945 +}
8946 +
8947 +static struct nf_sockopt_ops so_pool
8948 += { { NULL, NULL }, PF_INET,
8949 +    SO_IP_POOL, SO_IP_POOL+1, &setpool,
8950 +    SO_IP_POOL, SO_IP_POOL+1, &getpool,
8951 +    0, NULL };
8952 +
8953 +MODULE_PARM(nr_pool, "i");
8954 +
8955 +static int __init init(void)
8956 +{
8957 +       ip_pool_t i;
8958 +       int res;
8959 +
8960 +       if (nr_pool < 1) {
8961 +               printk("ip_pool module init: bad nr_pool %d\n", nr_pool);
8962 +               return -EINVAL;
8963 +       }
8964 +       POOL = kmalloc(nr_pool * sizeof(*POOL), GFP_KERNEL);
8965 +       if (!POOL) {
8966 +               printk("ip_pool module init: out of memory for nr_pool %d\n",
8967 +                       nr_pool);
8968 +               return -ENOMEM;
8969 +       }
8970 +       for (i=0; i<nr_pool; i++) {
8971 +               POOL[i].first_ip = 0;
8972 +               POOL[i].last_ip = 0;
8973 +               POOL[i].members = 0;
8974 +               POOL[i].nr_use = 0;
8975 +               POOL[i].nr_match = 0;
8976 +               POOL[i].lock = RW_LOCK_UNLOCKED;
8977 +       }
8978 +       res = nf_register_sockopt(&so_pool);
8979 +       DP("ip_pool:init %d pools, result %d\n", nr_pool, res);
8980 +       if (res != 0) {
8981 +               kfree(POOL);
8982 +               POOL = 0;
8983 +       }
8984 +       return res;
8985 +}
8986 +
8987 +static void __exit fini(void)
8988 +{
8989 +       ip_pool_t i;
8990 +
8991 +       DP("ip_pool:fini BYEBYE\n");
8992 +       nf_unregister_sockopt(&so_pool);
8993 +       for (i=0; i<nr_pool; i++) {
8994 +               if (POOL[i].members) {
8995 +                       kfree(POOL[i].members);
8996 +                       POOL[i].members = 0;
8997 +               }
8998 +       }
8999 +       kfree(POOL);
9000 +       POOL = 0;
9001 +       DP("ip_pool:fini these are the famous last words\n");
9002 +       return;
9003 +}
9004 +
9005 +module_init(init);
9006 +module_exit(fini);
9007 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/netfilter/ip_tables.c linux-2.6.7-rc3/net/ipv4/netfilter/ip_tables.c
9008 --- linux-2.6.7-rc3.org/net/ipv4/netfilter/ip_tables.c  2004-06-07 21:14:01.000000000 +0200
9009 +++ linux-2.6.7-rc3/net/ipv4/netfilter/ip_tables.c      2004-06-08 10:37:30.000000000 +0200
9010 @@ -29,6 +29,14 @@
9011  
9012  #include <linux/netfilter_ipv4/ip_tables.h>
9013  
9014 +static const char *hooknames[] = { 
9015 +       [NF_IP_PRE_ROUTING] "PREROUTING",
9016 +       [NF_IP_LOCAL_IN] "INPUT",
9017 +       [NF_IP_FORWARD] "FORWARD",
9018 +       [NF_IP_LOCAL_OUT] "OUTPUT",
9019 +       [NF_IP_POST_ROUTING] "POSTROUTING",
9020 +};
9021 +
9022  MODULE_LICENSE("GPL");
9023  MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>");
9024  MODULE_DESCRIPTION("IPv4 packet filter");
9025 @@ -323,6 +331,12 @@
9026  
9027                         t = ipt_get_target(e);
9028                         IP_NF_ASSERT(t->u.kernel.target);
9029 +
9030 +                       /* The packet traced and the rule isn't an unconditional return/END. */
9031 +                       if (((*pskb)->nfcache & NFC_TRACE) && e->rulenum) {       
9032 +                               nf_log_packet(PF_INET, hook, *pskb, in, out, "TRACE: %s/%s/%u ",
9033 +                                             table->name, e->chainname, e->rulenum);
9034 +                       }
9035                         /* Standard target? */
9036                         if (!t->u.kernel.target->target) {
9037                                 int v;
9038 @@ -349,7 +363,6 @@
9039                                         /* set back pointer to next entry */
9040                                         back = next;
9041                                 }
9042 -
9043                                 e = get_entry(table_base, v);
9044                         } else {
9045                                 /* Targets which reenter must return
9046 @@ -475,6 +488,29 @@
9047         return find_inlist_lock(&ipt_target, name, "ipt_", error, mutex);
9048  }
9049  
9050 +static inline int
9051 +find_error_target(struct ipt_entry *s, 
9052 +                 struct ipt_entry *e,
9053 +                 char **chainname)
9054 +{
9055 +       struct ipt_entry_target *t;
9056 +       static struct ipt_entry *found = NULL;
9057 +
9058 +       if (s == e) {
9059 +               if (!found)
9060 +                       return 0;
9061 +               t = ipt_get_target(found);
9062 +               if (strcmp(t->u.user.name, 
9063 +                          IPT_ERROR_TARGET) == 0) {
9064 +                       *chainname = t->data;
9065 +                       return 1;
9066 +               }
9067 +       } else
9068 +               found = s;
9069 +       
9070 +       return 0;
9071 +}
9072 +
9073  /* All zeroes == unconditional rule. */
9074  static inline int
9075  unconditional(const struct ipt_ip *ip)
9076 @@ -494,6 +530,8 @@
9077  mark_source_chains(struct ipt_table_info *newinfo, unsigned int valid_hooks)
9078  {
9079         unsigned int hook;
9080 +       char *chainname = NULL;
9081 +       u_int32_t rulenum;
9082  
9083         /* No recursion; use packet counter to save back ptrs (reset
9084            to 0 as we leave), and comefrom to save source hook bitmask */
9085 @@ -507,6 +545,8 @@
9086  
9087                 /* Set initial back pointer. */
9088                 e->counters.pcnt = pos;
9089 +               rulenum = 1;
9090 +               chainname = (char *) hooknames[hook];
9091  
9092                 for (;;) {
9093                         struct ipt_standard_target *t
9094 @@ -519,6 +559,8 @@
9095                         }
9096                         e->comefrom
9097                                 |= ((1 << hook) | (1 << NF_IP_NUMHOOKS));
9098 +                       e->rulenum = rulenum++;
9099 +                       e->chainname = chainname;
9100  
9101                         /* Unconditional return/END. */
9102                         if (e->target_offset == sizeof(struct ipt_entry)
9103 @@ -528,6 +570,10 @@
9104                             && unconditional(&e->ip)) {
9105                                 unsigned int oldpos, size;
9106  
9107 +                               /* Set unconditional rulenum to zero. */
9108 +                               e->rulenum = 0;
9109 +                               e->counters.bcnt = 0;
9110 +
9111                                 /* Return: backtrack through the last
9112                                    big jump. */
9113                                 do {
9114 @@ -553,6 +599,11 @@
9115                                                 (newinfo->entries + pos);
9116                                 } while (oldpos == pos + e->next_offset);
9117  
9118 +                               /* Restore chainname, rulenum. */
9119 +                               chainname = e->chainname;
9120 +                               rulenum = e->counters.bcnt;
9121 +                               e->counters.bcnt = 0;
9122 +
9123                                 /* Move along one */
9124                                 size = e->next_offset;
9125                                 e = (struct ipt_entry *)
9126 @@ -568,6 +619,17 @@
9127                                         /* This a jump; chase it. */
9128                                         duprintf("Jump rule %u -> %u\n",
9129                                                  pos, newpos);
9130 +                                       e->counters.bcnt = rulenum++;
9131 +                                       rulenum = 1;
9132 +                                       e = (struct ipt_entry *)
9133 +                                               (newinfo->entries + newpos);
9134 +                                       if (IPT_ENTRY_ITERATE(newinfo->entries,
9135 +                                                             newinfo->size,
9136 +                                                             find_error_target,
9137 +                                                             e, &chainname) == 0) {
9138 +                                               printk("ip_tables: table screwed up!\n");
9139 +                                               return 0;
9140 +                                       }
9141                                 } else {
9142                                         /* ... this is a fallthru */
9143                                         newpos = pos + e->next_offset;
9144 @@ -1713,9 +1775,9 @@
9145  };
9146  
9147  #ifdef CONFIG_PROC_FS
9148 -static inline int print_name(const char *i,
9149 -                            off_t start_offset, char *buffer, int length,
9150 -                            off_t *pos, unsigned int *count)
9151 +static int print_name(const char *i,
9152 +                      off_t start_offset, char *buffer, int length,
9153 +                      off_t *pos, unsigned int *count)
9154  {
9155         if ((*count)++ >= start_offset) {
9156                 unsigned int namelen;
9157 @@ -1749,6 +1811,15 @@
9158         return pos;
9159  }
9160  
9161 +static inline int print_target(const struct ipt_target *t,
9162 +                               off_t start_offset, char *buffer, int length,
9163 +                               off_t *pos, unsigned int *count)
9164 +{
9165 +       if (t == &ipt_standard_target || t == &ipt_error_target)
9166 +               return 0;
9167 +       return print_name((char *)t, start_offset, buffer, length, pos, count);
9168 +}
9169 +
9170  static int ipt_get_targets(char *buffer, char **start, off_t offset, int length)
9171  {
9172         off_t pos = 0;
9173 @@ -1757,7 +1828,7 @@
9174         if (down_interruptible(&ipt_mutex) != 0)
9175                 return 0;
9176  
9177 -       LIST_FIND(&ipt_target, print_name, void *,
9178 +       LIST_FIND(&ipt_target, print_target, struct ipt_target *,
9179                   offset, buffer, length, &pos, &count);
9180         
9181         up(&ipt_mutex);
9182 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_CONNMARK.c linux-2.6.7-rc3/net/ipv4/netfilter/ipt_CONNMARK.c
9183 --- linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_CONNMARK.c       1970-01-01 01:00:00.000000000 +0100
9184 +++ linux-2.6.7-rc3/net/ipv4/netfilter/ipt_CONNMARK.c   2004-06-08 10:36:58.000000000 +0200
9185 @@ -0,0 +1,118 @@
9186 +/* This kernel module is used to modify the connection mark values, or
9187 + * to optionally restore the skb nfmark from the connection mark
9188 + *
9189 + * Copyright (C) 2002,2004 MARA Systems AB <http://www.marasystems.com>
9190 + * by Henrik Nordstrom <hno@marasystems.com>
9191 + *
9192 + * This program is free software; you can redistribute it and/or modify
9193 + * it under the terms of the GNU General Public License as published by
9194 + * the Free Software Foundation; either version 2 of the License, or
9195 + * (at your option) any later version.
9196 + *
9197 + * This program is distributed in the hope that it will be useful,
9198 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9199 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9200 + * GNU General Public License for more details.
9201 + *
9202 + * You should have received a copy of the GNU General Public License
9203 + * along with this program; if not, write to the Free Software
9204 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
9205 + */
9206 +#include <linux/module.h>
9207 +#include <linux/skbuff.h>
9208 +#include <linux/ip.h>
9209 +#include <net/checksum.h>
9210 +
9211 +MODULE_AUTHOR("Henrik Nordstrom <hno@marasytems.com>");
9212 +MODULE_DESCRIPTION("IP tables CONNMARK matching module");
9213 +MODULE_LICENSE("GPL");
9214 +
9215 +#include <linux/netfilter_ipv4/ip_tables.h>
9216 +#include <linux/netfilter_ipv4/ipt_CONNMARK.h>
9217 +#include <linux/netfilter_ipv4/ip_conntrack.h>
9218 +
9219 +static unsigned int
9220 +target(struct sk_buff **pskb,
9221 +       const struct net_device *in,
9222 +       const struct net_device *out,
9223 +       unsigned int hooknum,
9224 +       const void *targinfo,
9225 +       void *userinfo)
9226 +{
9227 +       const struct ipt_connmark_target_info *markinfo = targinfo;
9228 +       unsigned long diff;
9229 +       unsigned long nfmark;
9230 +       unsigned long newmark;
9231 +
9232 +       enum ip_conntrack_info ctinfo;
9233 +       struct ip_conntrack *ct = ip_conntrack_get((*pskb), &ctinfo);
9234 +       if (ct) {
9235 +           switch(markinfo->mode) {
9236 +           case IPT_CONNMARK_SET:
9237 +               newmark = (ct->mark & ~markinfo->mask) | markinfo->mark;
9238 +               if (newmark != ct->mark)
9239 +                   ct->mark = newmark;
9240 +               break;
9241 +           case IPT_CONNMARK_SAVE:
9242 +               newmark = (ct->mark & ~markinfo->mask) | ((*pskb)->nfmark & markinfo->mask);
9243 +               if (ct->mark != newmark)
9244 +                   ct->mark = newmark;
9245 +               break;
9246 +           case IPT_CONNMARK_RESTORE:
9247 +               nfmark = (*pskb)->nfmark;
9248 +               diff = (ct->mark ^ nfmark & markinfo->mask);
9249 +               if (diff != 0) {
9250 +                   (*pskb)->nfmark = nfmark ^ diff;
9251 +                   (*pskb)->nfcache |= NFC_ALTERED;
9252 +               }
9253 +               break;
9254 +           }
9255 +       }
9256 +
9257 +       return IPT_CONTINUE;
9258 +}
9259 +
9260 +static int
9261 +checkentry(const char *tablename,
9262 +          const struct ipt_entry *e,
9263 +          void *targinfo,
9264 +          unsigned int targinfosize,
9265 +          unsigned int hook_mask)
9266 +{
9267 +       struct ipt_connmark_target_info *matchinfo = targinfo;
9268 +       if (targinfosize != IPT_ALIGN(sizeof(struct ipt_connmark_target_info))) {
9269 +               printk(KERN_WARNING "CONNMARK: targinfosize %u != %Zu\n",
9270 +                      targinfosize,
9271 +                      IPT_ALIGN(sizeof(struct ipt_connmark_target_info)));
9272 +               return 0;
9273 +       }
9274 +
9275 +       if (matchinfo->mode == IPT_CONNMARK_RESTORE) {
9276 +           if (strcmp(tablename, "mangle") != 0) {
9277 +                   printk(KERN_WARNING "CONNMARK: restore can only be called from \"mangle\" table, not \"%s\"\n", tablename);
9278 +                   return 0;
9279 +           }
9280 +       }
9281 +
9282 +       return 1;
9283 +}
9284 +
9285 +static struct ipt_target ipt_connmark_reg = {
9286 +       .name = "CONNMARK",
9287 +       .target = &target,
9288 +       .checkentry = &checkentry,
9289 +       .me = THIS_MODULE
9290 +};
9291 +
9292 +static int __init init(void)
9293 +{
9294 +       return ipt_register_target(&ipt_connmark_reg);
9295 +}
9296 +
9297 +static void __exit fini(void)
9298 +{
9299 +       ipt_unregister_target(&ipt_connmark_reg);
9300 +}
9301 +
9302 +module_init(init);
9303 +module_exit(fini);
9304 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_IPMARK.c linux-2.6.7-rc3/net/ipv4/netfilter/ipt_IPMARK.c
9305 --- linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_IPMARK.c 1970-01-01 01:00:00.000000000 +0100
9306 +++ linux-2.6.7-rc3/net/ipv4/netfilter/ipt_IPMARK.c     2004-06-08 10:37:02.000000000 +0200
9307 @@ -0,0 +1,81 @@
9308 +/* This is a module which is used for setting the NFMARK field of an skb. */
9309 +#include <linux/module.h>
9310 +#include <linux/skbuff.h>
9311 +#include <linux/ip.h>
9312 +#include <net/checksum.h>
9313 +
9314 +#include <linux/netfilter_ipv4/ip_tables.h>
9315 +#include <linux/netfilter_ipv4/ipt_IPMARK.h>
9316 +
9317 +MODULE_AUTHOR("Grzegorz Janoszka <Grzegorz.Janoszka@pro.onet.pl>");
9318 +MODULE_DESCRIPTION("IP tables IPMARK: mark based on ip address");
9319 +MODULE_LICENSE("GPL");
9320 +
9321 +static unsigned int
9322 +target(struct sk_buff **pskb,
9323 +       const struct net_device *in,
9324 +       const struct net_device *out,
9325 +       unsigned int hooknum,
9326 +       const void *targinfo,
9327 +       void *userinfo)
9328 +{
9329 +       const struct ipt_ipmark_target_info *ipmarkinfo = targinfo;
9330 +       struct iphdr *iph = (*pskb)->nh.iph;
9331 +       unsigned long mark;
9332 +
9333 +       if (ipmarkinfo->addr == IPT_IPMARK_SRC)
9334 +               mark = (unsigned long) ntohl(iph->saddr);
9335 +       else
9336 +               mark = (unsigned long) ntohl(iph->daddr);
9337 +
9338 +       mark &= ipmarkinfo->andmask;
9339 +       mark |= ipmarkinfo->ormask;
9340 +       
9341 +       if ((*pskb)->nfmark != mark) {
9342 +               (*pskb)->nfmark = mark;
9343 +               (*pskb)->nfcache |= NFC_ALTERED;
9344 +       }
9345 +       return IPT_CONTINUE;
9346 +}
9347 +
9348 +static int
9349 +checkentry(const char *tablename,
9350 +          const struct ipt_entry *e,
9351 +           void *targinfo,
9352 +           unsigned int targinfosize,
9353 +           unsigned int hook_mask)
9354 +{
9355 +       if (targinfosize != IPT_ALIGN(sizeof(struct ipt_ipmark_target_info))) {
9356 +               printk(KERN_WARNING "IPMARK: targinfosize %u != %Zu\n",
9357 +                      targinfosize,
9358 +                      IPT_ALIGN(sizeof(struct ipt_ipmark_target_info)));
9359 +               return 0;
9360 +       }
9361 +
9362 +       if (strcmp(tablename, "mangle") != 0) {
9363 +               printk(KERN_WARNING "IPMARK: can only be called from \"mangle\" table, not \"%s\"\n", tablename);
9364 +               return 0;
9365 +       }
9366 +
9367 +       return 1;
9368 +}
9369 +
9370 +static struct ipt_target ipt_ipmark_reg = { 
9371 +       .name = "IPMARK",
9372 +       .target = target,
9373 +       .checkentry = checkentry,
9374 +       .me = THIS_MODULE
9375 +};
9376 +
9377 +static int __init init(void)
9378 +{
9379 +       return ipt_register_target(&ipt_ipmark_reg);
9380 +}
9381 +
9382 +static void __exit fini(void)
9383 +{
9384 +       ipt_unregister_target(&ipt_ipmark_reg);
9385 +}
9386 +
9387 +module_init(init);
9388 +module_exit(fini);
9389 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_IPV4OPTSSTRIP.c linux-2.6.7-rc3/net/ipv4/netfilter/ipt_IPV4OPTSSTRIP.c
9390 --- linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_IPV4OPTSSTRIP.c  1970-01-01 01:00:00.000000000 +0100
9391 +++ linux-2.6.7-rc3/net/ipv4/netfilter/ipt_IPV4OPTSSTRIP.c      2004-06-08 10:31:05.000000000 +0200
9392 @@ -0,0 +1,89 @@
9393 +/**
9394 + * Strip all IP options in the IP packet header.
9395 + *
9396 + * (C) 2001 by Fabrice MARIE <fabrice@netfilter.org>
9397 + * This software is distributed under GNU GPL v2, 1991
9398 + */
9399 +
9400 +#include <linux/module.h>
9401 +#include <linux/skbuff.h>
9402 +#include <net/ip.h>
9403 +#include <net/checksum.h>
9404 +
9405 +#include <linux/netfilter_ipv4/ip_tables.h>
9406 +
9407 +MODULE_AUTHOR("Fabrice MARIE <fabrice@netfilter.org>");
9408 +MODULE_DESCRIPTION("Strip all options in IPv4 packets");
9409 +MODULE_LICENSE("GPL");
9410 +
9411 +static unsigned int
9412 +target(struct sk_buff **pskb,
9413 +       const struct net_device *in,
9414 +       const struct net_device *out,
9415 +       unsigned int hooknum,
9416 +       const void *targinfo,
9417 +       void *userinfo)
9418 +{
9419 +       struct iphdr *iph;
9420 +       struct sk_buff *skb;
9421 +       struct ip_options *opt;
9422 +       unsigned char *optiph;
9423 +       int l;
9424 +       
9425 +       if (!skb_ip_make_writable(pskb, (*pskb)->len))
9426 +               return NF_DROP;
9427
9428 +       skb = (*pskb);
9429 +       iph = (*pskb)->nh.iph;
9430 +       optiph = skb->nh.raw;
9431 +       l = ((struct ip_options *)(&(IPCB(skb)->opt)))->optlen;
9432 +
9433 +       /* if no options in packet then nothing to clear. */
9434 +       if (iph->ihl * 4 == sizeof(struct iphdr))
9435 +               return IPT_CONTINUE;
9436 +
9437 +       /* else clear all options */
9438 +       memset(&(IPCB(skb)->opt), 0, sizeof(struct ip_options));
9439 +       memset(optiph+sizeof(struct iphdr), IPOPT_NOOP, l);
9440 +       opt = &(IPCB(skb)->opt);
9441 +       opt->is_data = 0;
9442 +       opt->optlen = l;
9443 +
9444 +       skb->nfcache |= NFC_ALTERED;
9445 +
9446 +        return IPT_CONTINUE;
9447 +}
9448 +
9449 +static int
9450 +checkentry(const char *tablename,
9451 +          const struct ipt_entry *e,
9452 +           void *targinfo,
9453 +           unsigned int targinfosize,
9454 +           unsigned int hook_mask)
9455 +{
9456 +       if (strcmp(tablename, "mangle")) {
9457 +               printk(KERN_WARNING "IPV4OPTSSTRIP: can only be called from \"mangle\" table, not \"%s\"\n", tablename);
9458 +               return 0;
9459 +       }
9460 +       /* nothing else to check because no parameters */
9461 +       return 1;
9462 +}
9463 +
9464 +static struct ipt_target ipt_ipv4optsstrip_reg = { 
9465 +       .name = "IPV4OPTSSTRIP",
9466 +       .target = target,
9467 +       .checkentry = checkentry,
9468 +       .me = THIS_MODULE };
9469 +
9470 +static int __init init(void)
9471 +{
9472 +       return ipt_register_target(&ipt_ipv4optsstrip_reg);
9473 +}
9474 +
9475 +static void __exit fini(void)
9476 +{
9477 +       ipt_unregister_target(&ipt_ipv4optsstrip_reg);
9478 +}
9479 +
9480 +module_init(init);
9481 +module_exit(fini);
9482 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_NETLINK.c linux-2.6.7-rc3/net/ipv4/netfilter/ipt_NETLINK.c
9483 --- linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_NETLINK.c        1970-01-01 01:00:00.000000000 +0100
9484 +++ linux-2.6.7-rc3/net/ipv4/netfilter/ipt_NETLINK.c    2004-06-08 10:31:09.000000000 +0200
9485 @@ -0,0 +1,119 @@
9486 +#include <linux/module.h>
9487 +#include <linux/version.h>
9488 +#include <linux/config.h>
9489 +#include <linux/socket.h>
9490 +#include <linux/skbuff.h>
9491 +#include <linux/kernel.h>
9492 +#include <linux/netlink.h>
9493 +#include <linux/netdevice.h>
9494 +#include <linux/mm.h>
9495 +#include <linux/socket.h>
9496 +#include <linux/netfilter_ipv4/ip_tables.h>
9497 +#include <linux/netfilter_ipv4/ipt_NETLINK.h>
9498 +#include <net/sock.h>
9499 +
9500 +MODULE_AUTHOR("Gianni Tedesco <gianni@ecsc.co.uk>");
9501 +MODULE_DESCRIPTION("Provides iptables NETLINK target similar to ipchains -o");
9502 +MODULE_LICENSE("GPL");
9503 +
9504 +#if 0
9505 +#define DEBUGP printk
9506 +#else
9507 +#define DEBUGP(format, args...)
9508 +#endif
9509 +
9510 +static struct sock *ipfwsk;
9511 +
9512 +static unsigned int ipt_netlink_target(struct sk_buff **pskb,
9513 +                                   unsigned int hooknum,
9514 +                                   const struct net_device *in,
9515 +                                   const struct net_device *out,
9516 +                                   const void *targinfo, void *userinfo)
9517 +{
9518 +       struct ipt_nldata *nld = (struct ipt_nldata *)targinfo;
9519 +       struct iphdr *ip = (*pskb)->nh.iph;
9520 +       struct sk_buff *outskb;
9521 +       struct netlink_t nlhdr;
9522 +       size_t len=0;
9523 +
9524 +       /* Allocate a socket buffer */
9525 +       if ( MASK(nld->flags, USE_SIZE) )
9526 +               len = nld->size+sizeof(nlhdr);
9527 +       else
9528 +               len = ntohs(ip->tot_len)+sizeof(nlhdr); 
9529 +
9530 +       outskb=alloc_skb(len, GFP_ATOMIC);
9531 +
9532 +       if (outskb) {
9533 +               nlhdr.len=len;
9534 +               
9535 +               if ( MASK(nld->flags, USE_MARK) )
9536 +                       nlhdr.mark=(*pskb)->nfmark=nld->mark;
9537 +               else
9538 +                       nlhdr.mark=(*pskb)->nfmark;
9539 +               
9540 +               if ( in && in->name ) {
9541 +                       strncpy((char *)&nlhdr.iface, in->name, IFNAMSIZ);
9542 +               }else if ( out && out->name ){
9543 +                       strncpy((char *)&nlhdr.iface, out->name, IFNAMSIZ);
9544 +               }
9545 +
9546 +               skb_put(outskb, len);
9547 +               memcpy(outskb->data, &nlhdr, sizeof(nlhdr));
9548 +               memcpy((outskb->data)+sizeof(nlhdr), ip, len-sizeof(nlhdr));
9549 +               netlink_broadcast(ipfwsk, outskb, 0, ~0, GFP_ATOMIC);
9550 +       }else{
9551 +               if (net_ratelimit())
9552 +                       printk(KERN_WARNING "ipt_NETLINK: packet drop due to netlink failure\n");
9553 +       }
9554 +
9555 +       if ( MASK(nld->flags, USE_DROP) )
9556 +               return NF_DROP;
9557 +
9558 +       return IPT_CONTINUE;
9559 +}
9560 +
9561 +static int ipt_netlink_checkentry(const char *tablename,
9562 +                              const struct ipt_entry *e,
9563 +                              void *targinfo,
9564 +                              unsigned int targinfosize,
9565 +                              unsigned int hookmask)
9566 +{
9567 +       //struct ipt_nldata *nld = (struct ipt_nldata *)targinfo;
9568 +
9569 +       return 1;
9570 +}
9571 +
9572 +static struct ipt_target ipt_netlink_reg = { 
9573 +       {NULL, NULL},
9574 +       "NETLINK",
9575 +       ipt_netlink_target,
9576 +       ipt_netlink_checkentry,
9577 +       NULL,
9578 +       THIS_MODULE
9579 +};
9580 +
9581 +static int __init init(void)
9582 +{
9583 +       DEBUGP("ipt_NETLINK: init module\n");   
9584 +
9585 +       if (ipt_register_target(&ipt_netlink_reg) != 0) {
9586 +               return -EINVAL;
9587 +       }
9588 +
9589 +       if ( !(ipfwsk=netlink_kernel_create(NETLINK_FIREWALL, NULL)) ){
9590 +               return -EINVAL;
9591 +       }
9592 +
9593 +       return 0;
9594 +}
9595 +
9596 +static void __exit fini(void)
9597 +{
9598 +       DEBUGP("ipt_NETLINK: cleanup_module\n");
9599 +       ipt_unregister_target(&ipt_netlink_reg);
9600 +       if(ipfwsk->sk_socket) sock_release(ipfwsk->sk_socket);
9601 +}
9602 +
9603 +module_init(init);
9604 +module_exit(fini);
9605 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_POOL.c linux-2.6.7-rc3/net/ipv4/netfilter/ipt_POOL.c
9606 --- linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_POOL.c   1970-01-01 01:00:00.000000000 +0100
9607 +++ linux-2.6.7-rc3/net/ipv4/netfilter/ipt_POOL.c       2004-06-08 10:31:45.000000000 +0200
9608 @@ -0,0 +1,116 @@
9609 +/* ipt_POOL.c - netfilter target to manipulate IP pools
9610 + *
9611 + * This target can be used almost everywhere. It acts on some specified
9612 + * IP pool, adding or deleting some IP address in the pool. The address
9613 + * can be either the source (--addsrc, --delsrc), or destination (--add/deldst)
9614 + * of the packet under inspection.
9615 + *
9616 + * The target normally returns IPT_CONTINUE.
9617 + */
9618 +
9619 +#include <linux/types.h>
9620 +#include <linux/ip.h>
9621 +#include <linux/timer.h>
9622 +#include <linux/module.h>
9623 +#include <linux/netfilter.h>
9624 +#include <linux/netdevice.h>
9625 +#include <linux/if.h>
9626 +#include <linux/inetdevice.h>
9627 +#include <net/protocol.h>
9628 +#include <net/checksum.h>
9629 +#include <linux/netfilter_ipv4.h>
9630 +#include <linux/netfilter_ipv4/ip_nat_rule.h>
9631 +#include <linux/netfilter_ipv4/ipt_pool.h>
9632 +
9633 +#if 0
9634 +#define DEBUGP printk
9635 +#else
9636 +#define DEBUGP(format, args...)
9637 +#endif
9638 +
9639 +/*** NOTE NOTE NOTE NOTE ***
9640 +**
9641 +** By sheer luck, I get away with using the "struct ipt_pool_info", as defined
9642 +** in <linux/netfilter_ipv4/ipt_pool.h>, both as the match and target info.
9643 +** Here, in the target implementation, ipt_pool_info.src, if not IP_POOL_NONE,
9644 +** is modified for the source IP address of the packet under inspection.
9645 +** The same way, the ipt_pool_info.dst pool is modified for the destination.
9646 +**
9647 +** The address is added to the pool normally. However, if IPT_POOL_DEL_dir
9648 +** flag is set in ipt_pool_info.flags, the address is deleted from the pool.
9649 +**
9650 +** If a modification was done to the pool, we possibly return ACCEPT or DROP,
9651 +** if the right IPT_POOL_MOD_dir_ACCEPT or _MOD_dir_DROP flags are set.
9652 +** The IPT_POOL_INV_MOD_dir flag inverts the sense of the check (i.e. the
9653 +** ACCEPT and DROP flags are evaluated when the pool was not modified.)
9654 +*/
9655 +
9656 +static int
9657 +do_check(const char *tablename,
9658 +              const struct ipt_entry *e,
9659 +              void *targinfo,
9660 +              unsigned int targinfosize,
9661 +              unsigned int hook_mask)
9662 +{
9663 +       const struct ipt_pool_info *ipi = targinfo;
9664 +
9665 +       if (targinfosize != IPT_ALIGN(sizeof(*ipi))) {
9666 +               DEBUGP("POOL_check: size %u.\n", targinfosize);
9667 +               return 0;
9668 +       }
9669 +       DEBUGP("ipt_POOL:do_check(%d,%d,%d)\n",ipi->src,ipi->dst,ipi->flags);
9670 +       return 1;
9671 +}
9672 +
9673 +static unsigned int
9674 +do_target(struct sk_buff **pskb,
9675 +               unsigned int hooknum,
9676 +               const struct net_device *in,
9677 +               const struct net_device *out,
9678 +               const void *targinfo,
9679 +               void *userinfo)
9680 +{
9681 +       const struct ipt_pool_info *ipi = targinfo;
9682 +       int modified;
9683 +       unsigned int verdict = IPT_CONTINUE;
9684 +
9685 +       if (ipi->src != IP_POOL_NONE) {
9686 +               modified = ip_pool_mod(ipi->src, ntohl((*pskb)->nh.iph->saddr),
9687 +                                       ipi->flags & IPT_POOL_DEL_SRC);
9688 +               if (!!modified ^ !!(ipi->flags & IPT_POOL_INV_MOD_SRC)) {
9689 +                       if (ipi->flags & IPT_POOL_MOD_SRC_ACCEPT)
9690 +                               verdict = NF_ACCEPT;
9691 +                       else if (ipi->flags & IPT_POOL_MOD_SRC_DROP)
9692 +                               verdict = NF_DROP;
9693 +               }
9694 +       }
9695 +       if (verdict == IPT_CONTINUE && ipi->dst != IP_POOL_NONE) {
9696 +               modified = ip_pool_mod(ipi->dst, ntohl((*pskb)->nh.iph->daddr),
9697 +                                       ipi->flags & IPT_POOL_DEL_DST);
9698 +               if (!!modified ^ !!(ipi->flags & IPT_POOL_INV_MOD_DST)) {
9699 +                       if (ipi->flags & IPT_POOL_MOD_DST_ACCEPT)
9700 +                               verdict = NF_ACCEPT;
9701 +                       else if (ipi->flags & IPT_POOL_MOD_DST_DROP)
9702 +                               verdict = NF_DROP;
9703 +               }
9704 +       }
9705 +       return verdict;
9706 +}
9707 +
9708 +static struct ipt_target pool_reg
9709 += { { NULL, NULL }, "POOL", do_target, do_check, NULL, THIS_MODULE };
9710 +
9711 +static int __init init(void)
9712 +{
9713 +       DEBUGP("init ipt_POOL\n");
9714 +       return ipt_register_target(&pool_reg);
9715 +}
9716 +
9717 +static void __exit fini(void)
9718 +{
9719 +       DEBUGP("fini ipt_POOL\n");
9720 +       ipt_unregister_target(&pool_reg);
9721 +}
9722 +
9723 +module_init(init);
9724 +module_exit(fini);
9725 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_REJECT.c linux-2.6.7-rc3/net/ipv4/netfilter/ipt_REJECT.c
9726 --- linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_REJECT.c 2004-06-07 21:14:56.000000000 +0200
9727 +++ linux-2.6.7-rc3/net/ipv4/netfilter/ipt_REJECT.c     2004-06-08 10:30:55.000000000 +0200
9728 @@ -142,12 +142,7 @@
9729         nskb->dst = &rt->u.dst;
9730  
9731         /* This packet will not be the same as the other: clear nf fields */
9732 -       nf_conntrack_put(nskb->nfct);
9733 -       nskb->nfct = NULL;
9734 -       nskb->nfcache = 0;
9735 -#ifdef CONFIG_NETFILTER_DEBUG
9736 -       nskb->nf_debug = 0;
9737 -#endif
9738 +       nf_reset(nskb);
9739         nskb->nfmark = 0;
9740  #ifdef CONFIG_BRIDGE_NETFILTER
9741         nf_bridge_put(nskb->nf_bridge);
9742 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_ROUTE.c linux-2.6.7-rc3/net/ipv4/netfilter/ipt_ROUTE.c
9743 --- linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_ROUTE.c  1970-01-01 01:00:00.000000000 +0100
9744 +++ linux-2.6.7-rc3/net/ipv4/netfilter/ipt_ROUTE.c      2004-06-08 10:37:08.000000000 +0200
9745 @@ -0,0 +1,393 @@
9746 +/*
9747 + * This implements the ROUTE target, which enables you to setup unusual
9748 + * routes not supported by the standard kernel routing table.
9749 + *
9750 + * Copyright (C) 2002 Cedric de Launois <delaunois@info.ucl.ac.be>
9751 + *
9752 + * v 1.9 2004/05/14
9753 + *
9754 + * This software is distributed under GNU GPL v2, 1991
9755 + */
9756 +
9757 +#include <linux/module.h>
9758 +#include <linux/skbuff.h>
9759 +#include <linux/ip.h>
9760 +#include <linux/netfilter_ipv4/ip_tables.h>
9761 +#include <linux/netfilter_ipv4/ipt_ROUTE.h>
9762 +#include <linux/netdevice.h>
9763 +#include <linux/route.h>
9764 +#include <net/ip.h>
9765 +#include <net/route.h>
9766 +#include <net/icmp.h>
9767 +#include <net/checksum.h>
9768 +
9769 +#if 0
9770 +#define DEBUGP printk
9771 +#else
9772 +#define DEBUGP(format, args...)
9773 +#endif
9774 +
9775 +MODULE_LICENSE("GPL");
9776 +MODULE_AUTHOR("Cedric de Launois <delaunois@info.ucl.ac.be>");
9777 +MODULE_DESCRIPTION("iptables ROUTE target module");
9778 +
9779 +/* Try to route the packet according to the routing keys specified in
9780 + * route_info. Keys are :
9781 + *  - ifindex : 
9782 + *      0 if no oif preferred, 
9783 + *      otherwise set to the index of the desired oif
9784 + *  - route_info->gw :
9785 + *      0 if no gateway specified,
9786 + *      otherwise set to the next host to which the pkt must be routed
9787 + * If success, skb->dev is the output device to which the packet must 
9788 + * be sent and skb->dst is not NULL
9789 + *
9790 + * RETURN: -1 if an error occured
9791 + *          1 if the packet was succesfully routed to the 
9792 + *            destination desired
9793 + *          0 if the kernel routing table could not route the packet
9794 + *            according to the keys specified
9795 + */
9796 +static int route(struct sk_buff *skb,
9797 +                unsigned int ifindex,
9798 +                const struct ipt_route_target_info *route_info)
9799 +{
9800 +       int err;
9801 +       struct rtable *rt;
9802 +       struct iphdr *iph = skb->nh.iph;
9803 +       struct flowi fl = {
9804 +               .oif = ifindex,
9805 +               .nl_u = {
9806 +                       .ip4_u = {
9807 +                               .daddr = iph->daddr,
9808 +                               .saddr = 0,
9809 +                               .tos = RT_TOS(iph->tos),
9810 +                               .scope = RT_SCOPE_UNIVERSE,
9811 +                       }
9812 +               } 
9813 +       };
9814 +       
9815 +       /* The destination address may be overloaded by the target */
9816 +       if (route_info->gw)
9817 +               fl.fld_dst = route_info->gw;
9818 +       
9819 +       /* Trying to route the packet using the standard routing table. */
9820 +       if ((err = ip_route_output_key(&rt, &fl))) {
9821 +               if (net_ratelimit()) 
9822 +                       DEBUGP("ipt_ROUTE: couldn't route pkt (err: %i)",err);
9823 +               return -1;
9824 +       }
9825 +       
9826 +       /* Drop old route. */
9827 +       dst_release(skb->dst);
9828 +       skb->dst = NULL;
9829 +
9830 +       /* Success if no oif specified or if the oif correspond to the 
9831 +        * one desired */
9832 +       if (!ifindex || rt->u.dst.dev->ifindex == ifindex) {
9833 +               skb->dst = &rt->u.dst;
9834 +               skb->dev = skb->dst->dev;
9835 +               return 1;
9836 +       }
9837 +       
9838 +       /* The interface selected by the routing table is not the one
9839 +        * specified by the user. This may happen because the dst address
9840 +        * is one of our own addresses.
9841 +        */
9842 +       if (net_ratelimit()) 
9843 +               DEBUGP("ipt_ROUTE: failed to route as desired gw=%u.%u.%u.%u oif=%i (got oif=%i)\n", 
9844 +                      NIPQUAD(route_info->gw), ifindex, rt->u.dst.dev->ifindex);
9845 +       
9846 +       return 0;
9847 +}
9848 +
9849 +
9850 +/* Stolen from ip_finish_output2
9851 + * PRE : skb->dev is set to the device we are leaving by
9852 + *       skb->dst is not NULL
9853 + * POST: the packet is sent with the link layer header pushed
9854 + *       the packet is destroyed
9855 + */
9856 +static void ip_direct_send(struct sk_buff *skb)
9857 +{
9858 +       struct dst_entry *dst = skb->dst;
9859 +       struct hh_cache *hh = dst->hh;
9860 +
9861 +       if (hh) {
9862 +               read_lock_bh(&hh->hh_lock);
9863 +               memcpy(skb->data - 16, hh->hh_data, 16);
9864 +               read_unlock_bh(&hh->hh_lock);
9865 +               skb_push(skb, hh->hh_len);
9866 +               hh->hh_output(skb);
9867 +       } else if (dst->neighbour)
9868 +               dst->neighbour->output(skb);
9869 +       else {
9870 +               if (net_ratelimit())
9871 +                       DEBUGP(KERN_DEBUG "ipt_ROUTE: no hdr & no neighbour cache!\n");
9872 +               kfree_skb(skb);
9873 +       }
9874 +}
9875 +
9876 +
9877 +/* PRE : skb->dev is set to the device we are leaving by
9878 + * POST: - the packet is directly sent to the skb->dev device, without 
9879 + *         pushing the link layer header.
9880 + *       - the packet is destroyed
9881 + */
9882 +static inline int dev_direct_send(struct sk_buff *skb)
9883 +{
9884 +       return dev_queue_xmit(skb);
9885 +}
9886 +
9887 +
9888 +static unsigned int route_oif(const struct ipt_route_target_info *route_info,
9889 +                             struct sk_buff *skb) 
9890 +{
9891 +       unsigned int ifindex = 0;
9892 +       struct net_device *dev_out = NULL;
9893 +
9894 +       /* The user set the interface name to use.
9895 +        * Getting the current interface index.
9896 +        */
9897 +       if ((dev_out = dev_get_by_name(route_info->oif))) {
9898 +               ifindex = dev_out->ifindex;
9899 +       } else {
9900 +               /* Unknown interface name : packet dropped */
9901 +               if (net_ratelimit()) 
9902 +                       DEBUGP("ipt_ROUTE: oif interface %s not found\n", route_info->oif);
9903 +               return NF_DROP;
9904 +       }
9905 +
9906 +       /* Trying the standard way of routing packets */
9907 +       switch (route(skb, ifindex, route_info)) {
9908 +       case 1:
9909 +               dev_put(dev_out);
9910 +               if (route_info->flags & IPT_ROUTE_CONTINUE)
9911 +                       return IPT_CONTINUE;
9912 +
9913 +               ip_direct_send(skb);
9914 +               return NF_STOLEN;
9915 +
9916 +       case 0:
9917 +               /* Failed to send to oif. Trying the hard way */
9918 +               if (route_info->flags & IPT_ROUTE_CONTINUE)
9919 +                       return NF_DROP;
9920 +
9921 +               if (net_ratelimit()) 
9922 +                       DEBUGP("ipt_ROUTE: forcing the use of %i\n",
9923 +                              ifindex);
9924 +
9925 +               /* We have to force the use of an interface.
9926 +                * This interface must be a tunnel interface since
9927 +                * otherwise we can't guess the hw address for
9928 +                * the packet. For a tunnel interface, no hw address
9929 +                * is needed.
9930 +                */
9931 +               if ((dev_out->type != ARPHRD_TUNNEL)
9932 +                   && (dev_out->type != ARPHRD_IPGRE)) {
9933 +                       if (net_ratelimit()) 
9934 +                               DEBUGP("ipt_ROUTE: can't guess the hw addr !\n");
9935 +                       dev_put(dev_out);
9936 +                       return NF_DROP;
9937 +               }
9938 +       
9939 +               /* Send the packet. This will also free skb
9940 +                * Do not go through the POST_ROUTING hook because 
9941 +                * skb->dst is not set and because it will probably
9942 +                * get confused by the destination IP address.
9943 +                */
9944 +               skb->dev = dev_out;
9945 +               dev_direct_send(skb);
9946 +               dev_put(dev_out);
9947 +               return NF_STOLEN;
9948 +               
9949 +       default:
9950 +               /* Unexpected error */
9951 +               dev_put(dev_out);
9952 +               return NF_DROP;
9953 +       }
9954 +}
9955 +
9956 +
9957 +static unsigned int route_iif(const struct ipt_route_target_info *route_info,
9958 +                             struct sk_buff *skb) 
9959 +{
9960 +       struct net_device *dev_in = NULL;
9961 +
9962 +       /* Getting the current interface index. */
9963 +       if (!(dev_in = dev_get_by_name(route_info->iif))) {
9964 +               if (net_ratelimit()) 
9965 +                       DEBUGP("ipt_ROUTE: iif interface %s not found\n", route_info->iif);
9966 +               return NF_DROP;
9967 +       }
9968 +
9969 +       skb->dev = dev_in;
9970 +       dst_release(skb->dst);
9971 +       skb->dst = NULL;
9972 +
9973 +       netif_rx(skb);
9974 +       dev_put(dev_in);
9975 +       return NF_STOLEN;
9976 +}
9977 +
9978 +
9979 +static unsigned int route_gw(const struct ipt_route_target_info *route_info,
9980 +                            struct sk_buff *skb) 
9981 +{
9982 +       if (route(skb, 0, route_info)!=1)
9983 +               return NF_DROP;
9984 +
9985 +       if (route_info->flags & IPT_ROUTE_CONTINUE)
9986 +               return IPT_CONTINUE;
9987 +
9988 +       ip_direct_send(skb);
9989 +       return NF_STOLEN;
9990 +}
9991 +
9992 +
9993 +static unsigned int ipt_route_target(struct sk_buff **pskb,
9994 +                                    const struct net_device *in,
9995 +                                    const struct net_device *out,
9996 +                                    unsigned int hooknum,
9997 +                                    const void *targinfo,
9998 +                                    void *userinfo)
9999 +{
10000 +       const struct ipt_route_target_info *route_info = targinfo;
10001 +       struct sk_buff *skb = *pskb;
10002 +
10003 +       /* If we are at PREROUTING or INPUT hook
10004 +        * the TTL isn't decreased by the IP stack
10005 +        */
10006 +       if (hooknum == NF_IP_PRE_ROUTING ||
10007 +           hooknum == NF_IP_LOCAL_IN) {
10008 +
10009 +               struct iphdr *iph = skb->nh.iph;
10010 +
10011 +               if (iph->ttl <= 1) {
10012 +                       struct rtable *rt;
10013 +                       struct flowi fl = {
10014 +                               .oif = 0,
10015 +                               .nl_u = {
10016 +                                       .ip4_u = {
10017 +                                               .daddr = iph->daddr,
10018 +                                               .saddr = iph->saddr,
10019 +                                               .tos = RT_TOS(iph->tos),
10020 +                                               .scope = ((iph->tos & RTO_ONLINK) ?
10021 +                                                         RT_SCOPE_LINK :
10022 +                                                         RT_SCOPE_UNIVERSE)
10023 +                                       }
10024 +                               } 
10025 +                       };
10026 +
10027 +                       if (ip_route_output_key(&rt, &fl)) {
10028 +                               return NF_DROP;
10029 +                       }
10030 +
10031 +                       if (skb->dev == rt->u.dst.dev) {
10032 +                               /* Drop old route. */
10033 +                               dst_release(skb->dst);
10034 +                               skb->dst = &rt->u.dst;
10035 +
10036 +                               /* this will traverse normal stack, and 
10037 +                                * thus call conntrack on the icmp packet */
10038 +                               icmp_send(skb, ICMP_TIME_EXCEEDED, 
10039 +                                         ICMP_EXC_TTL, 0);
10040 +                       }
10041 +
10042 +                       return NF_DROP;
10043 +               }
10044 +
10045 +               /*
10046 +                * If we are at INPUT the checksum must be recalculated since
10047 +                * the length could change as the result of a defragmentation.
10048 +                */
10049 +               if(hooknum == NF_IP_LOCAL_IN) {
10050 +                       iph->ttl = iph->ttl - 1;
10051 +                       iph->check = 0;
10052 +                       iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);
10053 +               } else {
10054 +                       ip_decrease_ttl(iph);
10055 +               }
10056 +       }
10057 +
10058 +       /* Tell conntrack to forget this packet since it may get confused 
10059 +        * when a packet is leaving with dst address == our address.
10060 +        * Good idea ? Dunno. Need advice.
10061 +        */
10062 +       if (!(route_info->flags & IPT_ROUTE_CONTINUE)) {
10063 +               nf_conntrack_put(skb->nfct);
10064 +               skb->nfct = NULL;
10065 +               skb->nfcache = 0;
10066 +#ifdef CONFIG_NETFILTER_DEBUG
10067 +               skb->nf_debug = 0;
10068 +#endif
10069 +       }
10070 +
10071 +       if (route_info->oif[0] != '\0') 
10072 +               return route_oif(route_info, *pskb);
10073 +       
10074 +       if (route_info->iif[0] != '\0') 
10075 +               return route_iif(route_info, *pskb);
10076 +
10077 +       if (route_info->gw) 
10078 +               return route_gw(route_info, *pskb);
10079 +
10080 +       if (net_ratelimit()) 
10081 +               DEBUGP(KERN_DEBUG "ipt_ROUTE: no parameter !\n");
10082 +
10083 +       return IPT_CONTINUE;
10084 +}
10085 +
10086 +
10087 +static int ipt_route_checkentry(const char *tablename,
10088 +                               const struct ipt_entry *e,
10089 +                               void *targinfo,
10090 +                               unsigned int targinfosize,
10091 +                               unsigned int hook_mask)
10092 +{
10093 +       if (strcmp(tablename, "mangle") != 0) {
10094 +               printk("ipt_ROUTE: bad table `%s', use the `mangle' table.\n",
10095 +                      tablename);
10096 +               return 0;
10097 +       }
10098 +
10099 +       if (hook_mask & ~(  (1 << NF_IP_PRE_ROUTING)
10100 +                           | (1 << NF_IP_LOCAL_IN)
10101 +                           | (1 << NF_IP_FORWARD)
10102 +                           | (1 << NF_IP_LOCAL_OUT)
10103 +                           | (1 << NF_IP_POST_ROUTING))) {
10104 +               printk("ipt_ROUTE: bad hook\n");
10105 +               return 0;
10106 +       }
10107 +
10108 +       if (targinfosize != IPT_ALIGN(sizeof(struct ipt_route_target_info))) {
10109 +               printk(KERN_WARNING "ipt_ROUTE: targinfosize %u != %Zu\n",
10110 +                      targinfosize,
10111 +                      IPT_ALIGN(sizeof(struct ipt_route_target_info)));
10112 +               return 0;
10113 +       }
10114 +
10115 +       return 1;
10116 +}
10117 +
10118 +
10119 +static struct ipt_target ipt_route_reg = { 
10120 +       .name = "ROUTE",
10121 +       .target = ipt_route_target,
10122 +       .checkentry = ipt_route_checkentry,
10123 +       .me = THIS_MODULE,
10124 +};
10125 +
10126 +static int __init init(void)
10127 +{
10128 +       return ipt_register_target(&ipt_route_reg);
10129 +}
10130 +
10131 +
10132 +static void __exit fini(void)
10133 +{
10134 +       ipt_unregister_target(&ipt_route_reg);
10135 +}
10136 +
10137 +module_init(init);
10138 +module_exit(fini);
10139 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_TARPIT.c linux-2.6.7-rc3/net/ipv4/netfilter/ipt_TARPIT.c
10140 --- linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_TARPIT.c 1970-01-01 01:00:00.000000000 +0100
10141 +++ linux-2.6.7-rc3/net/ipv4/netfilter/ipt_TARPIT.c     2004-06-08 10:37:16.000000000 +0200
10142 @@ -0,0 +1,290 @@
10143 +/* 
10144 + * Kernel module to capture and hold incoming TCP connections using 
10145 + * no local per-connection resources.
10146 + * 
10147 + * Based on ipt_REJECT.c and offering functionality similar to 
10148 + * LaBrea <http://www.hackbusters.net/LaBrea/>.
10149 + * 
10150 + * Copyright (c) 2002 Aaron Hopkins <tools@die.net>
10151 + * 
10152 + * This program is free software; you can redistribute it and/or modify
10153 + * it under the terms of the GNU General Public License as published by
10154 + * the Free Software Foundation; either version 2 of the License, or
10155 + * (at your option) any later version.
10156 + *
10157 + * This program is distributed in the hope that it will be useful,
10158 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10159 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10160 + * GNU General Public License for more details.
10161 + *
10162 + * You should have received a copy of the GNU General Public License
10163 + * along with this program; if not, write to the Free Software
10164 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
10165 + * 
10166 + * Goal:
10167 + * - Allow incoming TCP connections to be established.
10168 + * - Passing data should result in the connection being switched to the 
10169 + *   persist state (0 byte window), in which the remote side stops sending 
10170 + *   data and asks to continue every 60 seconds.
10171 + * - Attempts to shut down the connection should be ignored completely, so 
10172 + *   the remote side ends up having to time it out.
10173 + *
10174 + * This means:
10175 + * - Reply to TCP SYN,!ACK,!RST,!FIN with SYN-ACK, window 5 bytes
10176 + * - Reply to TCP SYN,ACK,!RST,!FIN with RST to prevent spoofing
10177 + * - Reply to TCP !SYN,!RST,!FIN with ACK, window 0 bytes, rate-limited
10178 + */
10179 +
10180 +#include <linux/config.h>
10181 +#include <linux/module.h>
10182 +#include <linux/skbuff.h>
10183 +#include <linux/ip.h>
10184 +#include <net/ip.h>
10185 +#include <net/tcp.h>
10186 +#include <net/icmp.h>
10187 +struct in_device;
10188 +#include <net/route.h>
10189 +#include <linux/random.h>
10190 +#include <linux/netfilter_ipv4/ip_tables.h>
10191 +
10192 +#if 0
10193 +#define DEBUGP printk
10194 +#else
10195 +#define DEBUGP(format, args...)
10196 +#endif
10197 +
10198 +MODULE_LICENSE("GPL");
10199 +MODULE_AUTHOR("Aaron Hopkins <tools@die.net>");
10200 +
10201 +/* Stolen from ip_finish_output2 */
10202 +static int ip_direct_send(struct sk_buff *skb)
10203 +{
10204 +       struct dst_entry *dst = skb->dst;
10205 +       struct hh_cache *hh = dst->hh;
10206 +
10207 +       if (hh) {    
10208 +               read_lock_bh(&hh->hh_lock);
10209 +               memcpy(skb->data - 16, hh->hh_data, 16);
10210 +                read_unlock_bh(&hh->hh_lock);
10211 +                skb_push(skb, hh->hh_len);
10212 +                return hh->hh_output(skb);
10213 +        } else if (dst->neighbour)
10214 +                return dst->neighbour->output(skb);
10215 +
10216 +       if (net_ratelimit())
10217 +               printk(KERN_DEBUG "TARPIT ip_direct_send: no header cache and no neighbor!\n");
10218 +        kfree_skb(skb);
10219 +        return -EINVAL;
10220 +}
10221 +
10222 +
10223 +/* Send reply */
10224 +static void tarpit_tcp(struct sk_buff *oskb,struct rtable *ort,int local)
10225 +{
10226 +       struct sk_buff *nskb;
10227 +       struct rtable *nrt;
10228 +       struct tcphdr *otcph, *ntcph;
10229 +       struct flowi fl = {};
10230 +       unsigned int otcplen;
10231 +       u_int16_t tmp;
10232 +
10233 +       /* A truncated TCP header isn't going to be useful */
10234 +       if (oskb->len < (oskb->nh.iph->ihl*4) + sizeof(struct tcphdr))
10235 +               return;
10236 +
10237 +       otcph = (struct tcphdr *)((u_int32_t*)oskb->nh.iph 
10238 +                                  + oskb->nh.iph->ihl);
10239 +       otcplen = oskb->len - oskb->nh.iph->ihl*4;
10240 +
10241 +       /* No replies for RST or FIN */
10242 +       if (otcph->rst || otcph->fin)
10243 +               return;
10244 +
10245 +       /* No reply to !SYN,!ACK.  Rate-limit replies to !SYN,ACKs */
10246 +       if (!otcph->syn && (!otcph->ack || !xrlim_allow(&ort->u.dst, 1*HZ)))
10247 +               return;
10248 +
10249 +       /* Check checksum. */
10250 +       if (tcp_v4_check(otcph, otcplen, oskb->nh.iph->saddr,
10251 +                        oskb->nh.iph->daddr,
10252 +                        csum_partial((char *)otcph, otcplen, 0)) != 0)
10253 +               return;
10254 +
10255 +       /* Copy skb (even if skb is about to be dropped, we can't just
10256 +           clone it because there may be other things, such as tcpdump,
10257 +           interested in it) */
10258 +       nskb = skb_copy(oskb, GFP_ATOMIC);
10259 +       if (!nskb)
10260 +               return;
10261 +
10262 +       /* This packet will not be the same as the other: clear nf fields */
10263 +       nf_conntrack_put(nskb->nfct);
10264 +       nskb->nfct = NULL;
10265 +       nskb->nfcache = 0;
10266 +#ifdef CONFIG_NETFILTER_DEBUG
10267 +       nskb->nf_debug = 0;
10268 +#endif
10269 +
10270 +       ntcph = (struct tcphdr *)((u_int32_t*)nskb->nh.iph + nskb->nh.iph->ihl);
10271 +
10272 +       /* Truncate to length (no data) */
10273 +       ntcph->doff = sizeof(struct tcphdr)/4;
10274 +       skb_trim(nskb, nskb->nh.iph->ihl*4 + sizeof(struct tcphdr));
10275 +       nskb->nh.iph->tot_len = htons(nskb->len);
10276 +
10277 +       /* Swap source and dest */
10278 +       nskb->nh.iph->daddr = xchg(&nskb->nh.iph->saddr, nskb->nh.iph->daddr);
10279 +       tmp = ntcph->source;
10280 +       ntcph->source = ntcph->dest;
10281 +       ntcph->dest = tmp;
10282 +
10283 +       /* Use supplied sequence number or make a new one */
10284 +       ntcph->seq = otcph->ack ? otcph->ack_seq 
10285 +                     : htonl(secure_tcp_sequence_number(nskb->nh.iph->saddr, 
10286 +                                                       nskb->nh.iph->daddr, 
10287 +                                                       ntcph->source, 
10288 +                                                       ntcph->dest));
10289 +
10290 +       /* Our SYN-ACKs must have a >0 window */
10291 +       ntcph->window = (otcph->syn && !otcph->ack) ? htons(5) : 0;
10292 +
10293 +       ntcph->urg_ptr = 0;
10294 +
10295 +       /* Reset flags */
10296 +       ((u_int8_t *)ntcph)[13] = 0;
10297 +
10298 +       if (otcph->syn && otcph->ack) {
10299 +               ntcph->rst = 1;
10300 +               ntcph->ack_seq = 0;
10301 +       } else {
10302 +               ntcph->syn = otcph->syn;
10303 +               ntcph->ack = 1;
10304 +               ntcph->ack_seq = htonl(ntohl(otcph->seq) + otcph->syn);
10305 +       }
10306 +
10307 +       /* Adjust TCP checksum */
10308 +       ntcph->check = 0;
10309 +       ntcph->check = tcp_v4_check(ntcph, sizeof(struct tcphdr),
10310 +                                  nskb->nh.iph->saddr,
10311 +                                  nskb->nh.iph->daddr,
10312 +                                  csum_partial((char *)ntcph,
10313 +                                               sizeof(struct tcphdr), 0));
10314 +
10315 +       /* Adjust IP TTL */
10316 +       nskb->nh.iph->ttl = sysctl_ip_default_ttl;
10317 +
10318 +       /* Set DF, id = 0 */
10319 +       nskb->nh.iph->frag_off = htons(IP_DF);
10320 +       nskb->nh.iph->id = 0;
10321 +
10322 +       /* Adjust IP checksum */
10323 +       nskb->nh.iph->check = 0;
10324 +       nskb->nh.iph->check = ip_fast_csum((unsigned char *)nskb->nh.iph, 
10325 +                                          nskb->nh.iph->ihl);
10326 +
10327 +       fl.nl_u.ip4_u.daddr = nskb->nh.iph->daddr;
10328 +       fl.nl_u.ip4_u.saddr = local ? nskb->nh.iph->saddr : 0;
10329 +       fl.nl_u.ip4_u.tos = RT_TOS(nskb->nh.iph->tos) | RTO_CONN;
10330 +       fl.oif = 0;
10331 +
10332 +       if (ip_route_output_key(&nrt, &fl))
10333 +               goto free_nskb;
10334 +
10335 +       dst_release(nskb->dst);
10336 +       nskb->dst = &nrt->u.dst;
10337 +
10338 +       /* "Never happens" */
10339 +       if (nskb->len > dst_pmtu(nskb->dst))
10340 +               goto free_nskb;
10341 +
10342 +       ip_direct_send (nskb);
10343 +
10344 +       return;
10345 +
10346 + free_nskb:
10347 +       kfree_skb(nskb);
10348 +}
10349 +
10350 +
10351 +static unsigned int tarpit(struct sk_buff **pskb,
10352 +                          const struct net_device *in,
10353 +                          const struct net_device *out,
10354 +                          unsigned int hooknum,
10355 +                          const void *targinfo,
10356 +                          void *userinfo)
10357 +{
10358 +       struct sk_buff *skb = *pskb;
10359 +       struct rtable *rt = (struct rtable*)skb->dst;
10360 +
10361 +       /* Do we have an input route cache entry? */
10362 +       if (!rt)
10363 +               return NF_DROP;
10364 +
10365 +        /* No replies to physical multicast/broadcast */
10366 +        if (skb->pkt_type != PACKET_HOST && skb->pkt_type != PACKET_OTHERHOST)
10367 +               return NF_DROP;
10368 +
10369 +        /* Now check at the protocol level */
10370 +       if (rt->rt_flags&(RTCF_BROADCAST|RTCF_MULTICAST))
10371 +                return NF_DROP;
10372 +
10373 +       /* Our naive response construction doesn't deal with IP
10374 +           options, and probably shouldn't try. */
10375 +       if (skb->nh.iph->ihl*4 != sizeof(struct iphdr))
10376 +               return NF_DROP;
10377 +
10378 +        /* We aren't interested in fragments */
10379 +       if (skb->nh.iph->frag_off & htons(IP_OFFSET))
10380 +                return NF_DROP;
10381 +
10382 +       tarpit_tcp(skb,rt,hooknum == NF_IP_LOCAL_IN);
10383 +
10384 +       return NF_DROP;
10385 +}
10386 +
10387 +
10388 +static int check(const char *tablename,
10389 +                const struct ipt_entry *e,
10390 +                void *targinfo,
10391 +                unsigned int targinfosize,
10392 +                unsigned int hook_mask)
10393 +{
10394 +       /* Only allow these for input/forward packet filtering. */
10395 +       if (strcmp(tablename, "filter") != 0) {
10396 +               DEBUGP("TARPIT: bad table %s'.\n", tablename);
10397 +               return 0;
10398 +       }
10399 +       if ((hook_mask & ~((1 << NF_IP_LOCAL_IN) 
10400 +                           | (1 << NF_IP_FORWARD))) != 0) {
10401 +               DEBUGP("TARPIT: bad hook mask %X\n", hook_mask);
10402 +               return 0;
10403 +       }
10404 +
10405 +       /* Must specify that it's a TCP packet */
10406 +       if (e->ip.proto != IPPROTO_TCP || (e->ip.invflags & IPT_INV_PROTO)) {
10407 +               DEBUGP("TARPIT: not valid for non-tcp\n");
10408 +               return 0;
10409 +       }
10410 +
10411 +       return 1;
10412 +}
10413 +
10414 +static struct ipt_target ipt_tarpit_reg = { 
10415 +       .name = "TARPIT",
10416 +       .target = tarpit,
10417 +       .checkentry = check,
10418 +       .me = THIS_MODULE
10419 +};
10420 +
10421 +static int __init init(void)
10422 +{
10423 +       return ipt_register_target(&ipt_tarpit_reg);
10424 +}
10425 +
10426 +static void __exit fini(void)
10427 +{
10428 +       ipt_unregister_target(&ipt_tarpit_reg);
10429 +}
10430 +
10431 +module_init(init);
10432 +module_exit(fini);
10433 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_TRACE.c linux-2.6.7-rc3/net/ipv4/netfilter/ipt_TRACE.c
10434 --- linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_TRACE.c  1970-01-01 01:00:00.000000000 +0100
10435 +++ linux-2.6.7-rc3/net/ipv4/netfilter/ipt_TRACE.c      2004-06-08 10:37:30.000000000 +0200
10436 @@ -0,0 +1,64 @@
10437 +/* This is a module which is used for setting 
10438 + * the NFC_TRACE flag in the nfcache field of an skb. 
10439 + */
10440 +#include <linux/module.h>
10441 +#include <linux/skbuff.h>
10442 +
10443 +#include <linux/netfilter_ipv4/ip_tables.h>
10444 +
10445 +static unsigned int
10446 +target(struct sk_buff **pskb,
10447 +       const struct net_device *in,
10448 +       const struct net_device *out,
10449 +       unsigned int hooknum,
10450 +       const void *targinfo,
10451 +       void *userinfo)
10452 +{
10453 +       (*pskb)->nfcache |= NFC_TRACE;
10454 +       return IPT_CONTINUE;
10455 +}
10456 +
10457 +static int
10458 +checkentry(const char *tablename,
10459 +          const struct ipt_entry *e,
10460 +           void *targinfo,
10461 +           unsigned int targinfosize,
10462 +           unsigned int hook_mask)
10463 +{
10464 +       if (targinfosize != 0) {
10465 +               printk(KERN_WARNING "TRACE: targinfosize %u != 0\n",
10466 +                      targinfosize);
10467 +               return 0;
10468 +       }
10469 +
10470 +       if (strcmp(tablename, "raw") != 0) {
10471 +               printk(KERN_WARNING "TRACE: can only be called from \"raw\" table, not \"%s\"\n", tablename);
10472 +               return 0;
10473 +       }
10474 +
10475 +       return 1;
10476 +}
10477 +
10478 +static struct ipt_target ipt_trace_reg = { 
10479 +       .name = "TRACE", 
10480 +       .target = target, 
10481 +       .checkentry = checkentry, 
10482 +       .me = THIS_MODULE
10483 +};
10484 +
10485 +static int __init init(void)
10486 +{
10487 +       if (ipt_register_target(&ipt_trace_reg))
10488 +               return -EINVAL;
10489 +
10490 +       return 0;
10491 +}
10492 +
10493 +static void __exit fini(void)
10494 +{
10495 +       ipt_unregister_target(&ipt_trace_reg);
10496 +}
10497 +
10498 +module_init(init);
10499 +module_exit(fini);
10500 +MODULE_LICENSE("GPL");
10501 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_TTL.c linux-2.6.7-rc3/net/ipv4/netfilter/ipt_TTL.c
10502 --- linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_TTL.c    1970-01-01 01:00:00.000000000 +0100
10503 +++ linux-2.6.7-rc3/net/ipv4/netfilter/ipt_TTL.c        2004-06-08 10:31:21.000000000 +0200
10504 @@ -0,0 +1,120 @@
10505 +/* TTL modification target for IP tables
10506 + * (C) 2000 by Harald Welte <laforge@gnumonks.org>
10507 + *
10508 + * Version: $Revision$
10509 + *
10510 + * This software is distributed under the terms of GNU GPL
10511 + */
10512 +
10513 +#include <linux/module.h>
10514 +#include <linux/skbuff.h>
10515 +#include <linux/ip.h>
10516 +#include <net/checksum.h>
10517 +
10518 +#include <linux/netfilter_ipv4/ip_tables.h>
10519 +#include <linux/netfilter_ipv4/ipt_TTL.h>
10520 +
10521 +MODULE_AUTHOR("Harald Welte <laforge@gnumonks.org>");
10522 +MODULE_DESCRIPTION("IP tables TTL modification module");
10523 +MODULE_LICENSE("GPL");
10524 +
10525 +static unsigned int 
10526 +ipt_ttl_target(struct sk_buff **pskb, const struct net_device *in, 
10527 +               const struct net_device *out, unsigned int hooknum, 
10528 +               const void *targinfo, void *userinfo)
10529 +{
10530 +       struct iphdr *iph;
10531 +       const struct ipt_TTL_info *info = targinfo;
10532 +       u_int16_t diffs[2];
10533 +       int new_ttl;
10534 +
10535 +       if (!skb_ip_make_writable(pskb, (*pskb)->len))
10536 +               return NF_DROP;
10537 +
10538 +       iph = (*pskb)->nh.iph;
10539 +                        
10540 +       switch (info->mode) {
10541 +               case IPT_TTL_SET:
10542 +                       new_ttl = info->ttl;
10543 +                       break;
10544 +               case IPT_TTL_INC:
10545 +                       new_ttl = iph->ttl + info->ttl;
10546 +                       if (new_ttl > 255)
10547 +                               new_ttl = 255;
10548 +                       break;
10549 +               case IPT_TTL_DEC:
10550 +                       new_ttl = iph->ttl + info->ttl;
10551 +                       if (new_ttl < 0)
10552 +                               new_ttl = 0;
10553 +                       break;
10554 +               default:
10555 +                       new_ttl = iph->ttl;
10556 +                       break;
10557 +       }
10558 +
10559 +       if (new_ttl != iph->ttl) {
10560 +               diffs[0] = htons(((unsigned)iph->ttl) << 8) ^ 0xFFFF;
10561 +               iph->ttl = new_ttl;
10562 +               diffs[1] = htons(((unsigned)iph->ttl) << 8);
10563 +               iph->check = csum_fold(csum_partial((char *)diffs,
10564 +                                                   sizeof(diffs),
10565 +                                                   iph->check^0xFFFF));
10566 +                                                                                               (*pskb)->nfcache |= NFC_ALTERED;
10567 +       }
10568 +
10569 +       return IPT_CONTINUE;
10570 +}
10571 +
10572 +static int ipt_ttl_checkentry(const char *tablename,
10573 +               const struct ipt_entry *e,
10574 +               void *targinfo,
10575 +               unsigned int targinfosize,
10576 +               unsigned int hook_mask)
10577 +{
10578 +       struct ipt_TTL_info *info = targinfo;
10579 +
10580 +       if (targinfosize != IPT_ALIGN(sizeof(struct ipt_TTL_info))) {
10581 +               printk(KERN_WARNING "TTL: targinfosize %u != %Zu\n",
10582 +                               targinfosize,
10583 +                               IPT_ALIGN(sizeof(struct ipt_TTL_info)));
10584 +               return 0;       
10585 +       }       
10586 +
10587 +       if (strcmp(tablename, "mangle")) {
10588 +               printk(KERN_WARNING "TTL: can only be called from \"mangle\" table, not \"%s\"\n", tablename);
10589 +               return 0;
10590 +       }
10591 +
10592 +       if (info->mode > IPT_TTL_MAXMODE) {
10593 +               printk(KERN_WARNING "TTL: invalid or unknown Mode %u\n", 
10594 +                       info->mode);
10595 +               return 0;
10596 +       }
10597 +
10598 +       if ((info->mode != IPT_TTL_SET) && (info->ttl == 0)) {
10599 +               printk(KERN_WARNING "TTL: increment/decrement doesn't make sense with value 0\n");
10600 +               return 0;
10601 +       }
10602 +       
10603 +       return 1;
10604 +}
10605 +
10606 +static struct ipt_target ipt_TTL = { 
10607 +       .name = "TTL",
10608 +       .target = ipt_ttl_target, 
10609 +       .checkentry = ipt_ttl_checkentry, 
10610 +       .me = THIS_MODULE 
10611 +};
10612 +
10613 +static int __init init(void)
10614 +{
10615 +       return ipt_register_target(&ipt_TTL);
10616 +}
10617 +
10618 +static void __exit fini(void)
10619 +{
10620 +       ipt_unregister_target(&ipt_TTL);
10621 +}
10622 +
10623 +module_init(init);
10624 +module_exit(fini);
10625 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_XOR.c linux-2.6.7-rc3/net/ipv4/netfilter/ipt_XOR.c
10626 --- linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_XOR.c    1970-01-01 01:00:00.000000000 +0100
10627 +++ linux-2.6.7-rc3/net/ipv4/netfilter/ipt_XOR.c        2004-06-08 10:37:54.000000000 +0200
10628 @@ -0,0 +1,117 @@
10629 +/* XOR target for IP tables
10630 + * (C) 2000 by Tim Vandermeersch <Tim.Vandermeersch@pandora.be>
10631 + * Based on ipt_TTL.c
10632 + *
10633 + * Version 1.0
10634 + *
10635 + * This software is distributed under the terms of GNU GPL
10636 + */
10637 +
10638 +#include <linux/module.h>
10639 +#include <linux/skbuff.h>
10640 +#include <linux/ip.h>
10641 +#include <linux/tcp.h>
10642 +#include <linux/udp.h>
10643 +
10644 +#include <linux/netfilter_ipv4/ip_tables.h>
10645 +#include <linux/netfilter_ipv4/ipt_XOR.h>
10646 +
10647 +MODULE_AUTHOR("Tim Vandermeersch <Tim.Vandermeersch@pandora.be>");
10648 +MODULE_DESCRIPTION("IP tables XOR module");
10649 +MODULE_LICENSE("GPL");
10650 +
10651 +static unsigned int 
10652 +ipt_xor_target(struct sk_buff **pskb, 
10653 +               const struct net_device *in, const struct net_device *out, 
10654 +               unsigned int hooknum, const void *targinfo, void *userinfo)
10655 +{
10656 +       struct ipt_XOR_info *info = (void *) targinfo;
10657 +       struct iphdr *iph;
10658 +       struct tcphdr *tcph;
10659 +       struct udphdr *udph;
10660 +       int i, j, k;
10661 +
10662 +       if (!skb_ip_make_writable(pskb, (*pskb)->len))
10663 +               return NF_DROP;
10664 +
10665 +       iph = (*pskb)->nh.iph;
10666 +  
10667 +       if (iph->protocol == IPPROTO_TCP) {
10668 +               tcph = (struct tcphdr *) ((*pskb)->data + iph->ihl*4);
10669 +               for (i=0, j=0; i<(ntohs(iph->tot_len) - iph->ihl*4 - tcph->doff*4); ) {
10670 +                       for (k=0; k<=info->block_size; k++) {
10671 +                               (char) (*pskb)->data[ iph->ihl*4 + tcph->doff*4 + i ] ^= 
10672 +                                               info->key[j];
10673 +                               i++;
10674 +                       }
10675 +                       j++;
10676 +                       if (info->key[j] == 0x00)
10677 +                               j = 0;
10678 +               }
10679 +       } else if (iph->protocol == IPPROTO_UDP) {
10680 +               udph = (struct udphdr *) ((*pskb)->data + iph->ihl*4);
10681 +               for (i=0, j=0; i<(ntohs(udph->len)-8); ) {
10682 +                       for (k=0; k<=info->block_size; k++) {
10683 +                               (char) (*pskb)->data[ iph->ihl*4 + sizeof(struct udphdr) + i ] ^= 
10684 +                                               info->key[j];
10685 +                               i++;
10686 +                       }
10687 +                       j++;
10688 +                       if (info->key[j] == 0x00)
10689 +                               j = 0;
10690 +               }
10691 +       }
10692 +  
10693 +       return IPT_CONTINUE;
10694 +}
10695 +
10696 +static int ipt_xor_checkentry(const char *tablename, const struct ipt_entry *e,
10697 +               void *targinfo, unsigned int targinfosize, 
10698 +               unsigned int hook_mask)
10699 +{
10700 +       struct ipt_XOR_info *info = targinfo;
10701 +
10702 +       if (targinfosize != IPT_ALIGN(sizeof(struct ipt_XOR_info))) {
10703 +               printk(KERN_WARNING "XOR: targinfosize %u != %Zu\n", 
10704 +                               targinfosize, IPT_ALIGN(sizeof(struct ipt_XOR_info)));
10705 +               return 0;
10706 +       }       
10707 +
10708 +       if (strcmp(tablename, "mangle")) {
10709 +               printk(KERN_WARNING "XOR: can only be called from"
10710 +                               "\"mangle\" table, not \"%s\"\n", tablename);
10711 +               return 0; 
10712 +       }
10713 +
10714 +       if (!strcmp(info->key, "")) {
10715 +               printk(KERN_WARNING "XOR: You must specify a key");
10716 +               return 0;
10717 +       }
10718 +
10719 +       if (info->block_size == 0) {
10720 +               printk(KERN_WARNING "XOR: You must specify a block-size");
10721 +               return 0;
10722 +       }
10723 +
10724 +       return 1;
10725 +}
10726 +
10727 +static struct ipt_target ipt_XOR = { 
10728 +       .name = "XOR",
10729 +       .target = ipt_xor_target, 
10730 +       .checkentry = ipt_xor_checkentry,
10731 +       .me = THIS_MODULE,
10732 +};
10733 +
10734 +static int __init init(void)
10735 +{
10736 +       return ipt_register_target(&ipt_XOR);
10737 +}
10738 +
10739 +static void __exit fini(void)
10740 +{
10741 +       ipt_unregister_target(&ipt_XOR);
10742 +}
10743 +
10744 +module_init(init);
10745 +module_exit(fini);
10746 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_addrtype.c linux-2.6.7-rc3/net/ipv4/netfilter/ipt_addrtype.c
10747 --- linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_addrtype.c       1970-01-01 01:00:00.000000000 +0100
10748 +++ linux-2.6.7-rc3/net/ipv4/netfilter/ipt_addrtype.c   2004-06-08 10:38:04.000000000 +0200
10749 @@ -0,0 +1,75 @@
10750 +/*
10751 + *  iptables module to match inet_addr_type() of an ip.
10752 + *
10753 + *  Copyright (c) 2004 Patrick McHardy <kaber@trash.net>
10754 + *
10755 + *  This program is free software; you can redistribute it and/or modify
10756 + *  it under the terms of the GNU General Public License version 2 as
10757 + *  published by the Free Software Foundation.
10758 + */
10759 +
10760 +#include <linux/module.h>
10761 +#include <linux/skbuff.h>
10762 +#include <linux/netdevice.h>
10763 +#include <net/route.h>
10764 +
10765 +#include <linux/netfilter_ipv4/ipt_addrtype.h>
10766 +#include <linux/netfilter_ipv4/ip_tables.h>
10767 +
10768 +MODULE_LICENSE("GPL");
10769 +MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
10770 +MODULE_DESCRIPTION("iptables addrtype match");
10771 +
10772 +static inline int match_type(u_int32_t addr, u_int16_t mask)
10773 +{
10774 +       return !!(mask & (1 << inet_addr_type(addr)));
10775 +}
10776 +
10777 +static int match(const struct sk_buff *skb, const struct net_device *in,
10778 +                const struct net_device *out, const void *matchinfo,
10779 +                int offset, int *hotdrop)
10780 +{
10781 +       const struct ipt_addrtype_info *info = matchinfo;
10782 +       const struct iphdr *iph = skb->nh.iph;
10783 +       int ret = 1;
10784 +
10785 +       if (info->source)
10786 +               ret &= match_type(iph->saddr, info->source)^info->invert_source;
10787 +       if (info->dest)
10788 +               ret &= match_type(iph->daddr, info->dest)^info->invert_dest;
10789 +       
10790 +       return ret;
10791 +}
10792 +
10793 +static int checkentry(const char *tablename, const struct ipt_ip *ip,
10794 +                     void *matchinfo, unsigned int matchsize,
10795 +                     unsigned int hook_mask)
10796 +{
10797 +       if (matchsize != IPT_ALIGN(sizeof(struct ipt_addrtype_info))) {
10798 +               printk(KERN_ERR "ipt_addrtype: invalid size (%u != %u)\n.",
10799 +                      matchsize, IPT_ALIGN(sizeof(struct ipt_addrtype_info)));
10800 +               return 0;
10801 +       }
10802 +
10803 +       return 1;
10804 +}
10805 +
10806 +static struct ipt_match addrtype_match = {
10807 +       .name           = "addrtype",
10808 +       .match          = match,
10809 +       .checkentry     = checkentry,
10810 +       .me             = THIS_MODULE
10811 +};
10812 +
10813 +static int __init init(void)
10814 +{
10815 +       return ipt_register_match(&addrtype_match);
10816 +}
10817 +
10818 +static void __exit fini(void)
10819 +{
10820 +       ipt_unregister_match(&addrtype_match);
10821 +}
10822 +
10823 +module_init(init);
10824 +module_exit(fini);
10825 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_connlimit.c linux-2.6.7-rc3/net/ipv4/netfilter/ipt_connlimit.c
10826 --- linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_connlimit.c      1970-01-01 01:00:00.000000000 +0100
10827 +++ linux-2.6.7-rc3/net/ipv4/netfilter/ipt_connlimit.c  2004-06-08 10:31:23.000000000 +0200
10828 @@ -0,0 +1,230 @@
10829 +/*
10830 + * netfilter module to limit the number of parallel tcp
10831 + * connections per IP address.
10832 + *   (c) 2000 Gerd Knorr <kraxel@bytesex.org>
10833 + *   Nov 2002: Martin Bene <martin.bene@icomedias.com>:
10834 + *             only ignore TIME_WAIT or gone connections
10835 + *
10836 + * based on ...
10837 + *
10838 + * Kernel module to match connection tracking information.
10839 + * GPL (C) 1999  Rusty Russell (rusty@rustcorp.com.au).
10840 + */
10841 +#include <linux/module.h>
10842 +#include <linux/skbuff.h>
10843 +#include <linux/list.h>
10844 +#include <linux/netfilter_ipv4/ip_conntrack.h>
10845 +#include <linux/netfilter_ipv4/ip_conntrack_core.h>
10846 +#include <linux/netfilter_ipv4/ip_conntrack_tcp.h>
10847 +#include <linux/netfilter_ipv4/ip_tables.h>
10848 +#include <linux/netfilter_ipv4/ipt_connlimit.h>
10849 +
10850 +#define DEBUG 0
10851 +
10852 +MODULE_LICENSE("GPL");
10853 +
10854 +/* we'll save the tuples of all connections we care about */
10855 +struct ipt_connlimit_conn
10856 +{
10857 +        struct list_head list;
10858 +       struct ip_conntrack_tuple tuple;
10859 +};
10860 +
10861 +struct ipt_connlimit_data {
10862 +       spinlock_t lock;
10863 +       struct list_head iphash[256];
10864 +};
10865 +
10866 +static int ipt_iphash(u_int32_t addr)
10867 +{
10868 +       int hash;
10869 +
10870 +       hash  =  addr        & 0xff;
10871 +       hash ^= (addr >>  8) & 0xff;
10872 +       hash ^= (addr >> 16) & 0xff;
10873 +       hash ^= (addr >> 24) & 0xff;
10874 +       return hash;
10875 +}
10876 +
10877 +static int count_them(struct ipt_connlimit_data *data,
10878 +                     u_int32_t addr, u_int32_t mask,
10879 +                     struct ip_conntrack *ct)
10880 +{
10881 +#if DEBUG
10882 +       const static char *tcp[] = { "none", "established", "syn_sent", "syn_recv",
10883 +                                    "fin_wait", "time_wait", "close", "close_wait",
10884 +                                    "last_ack", "listen" };
10885 +#endif
10886 +       int addit = 1, matches = 0;
10887 +       struct ip_conntrack_tuple tuple;
10888 +       struct ip_conntrack_tuple_hash *found;
10889 +       struct ipt_connlimit_conn *conn;
10890 +       struct list_head *hash,*lh;
10891 +
10892 +       spin_lock(&data->lock);
10893 +       tuple = ct->tuplehash[0].tuple;
10894 +       hash = &data->iphash[ipt_iphash(addr & mask)];
10895 +
10896 +       /* check the saved connections */
10897 +       for (lh = hash->next; lh != hash; lh = lh->next) {
10898 +               conn = list_entry(lh,struct ipt_connlimit_conn,list);
10899 +               found = ip_conntrack_find_get(&conn->tuple,ct);
10900 +               if (0 == memcmp(&conn->tuple,&tuple,sizeof(tuple)) &&
10901 +                   found != NULL &&
10902 +                   found->ctrack->proto.tcp.state != TCP_CONNTRACK_TIME_WAIT) {
10903 +                       /* Just to be sure we have it only once in the list.
10904 +                          We should'nt see tuples twice unless someone hooks this
10905 +                          into a table without "-p tcp --syn" */
10906 +                       addit = 0;
10907 +               }
10908 +#if DEBUG
10909 +               printk("ipt_connlimit [%d]: src=%u.%u.%u.%u:%d dst=%u.%u.%u.%u:%d %s\n",
10910 +                      ipt_iphash(addr & mask),
10911 +                      NIPQUAD(conn->tuple.src.ip), ntohs(conn->tuple.src.u.tcp.port),
10912 +                      NIPQUAD(conn->tuple.dst.ip), ntohs(conn->tuple.dst.u.tcp.port),
10913 +                      (NULL != found) ? tcp[found->ctrack->proto.tcp.state] : "gone");
10914 +#endif
10915 +               if (NULL == found) {
10916 +                       /* this one is gone */
10917 +                       lh = lh->prev;
10918 +                       list_del(lh->next);
10919 +                       kfree(conn);
10920 +                       continue;
10921 +               }
10922 +               if (found->ctrack->proto.tcp.state == TCP_CONNTRACK_TIME_WAIT) {
10923 +                       /* we don't care about connections which are
10924 +                          closed already -> ditch it */
10925 +                       lh = lh->prev;
10926 +                       list_del(lh->next);
10927 +                       kfree(conn);
10928 +                       nf_conntrack_put(&found->ctrack->infos[0]);
10929 +                       continue;
10930 +               }
10931 +               if ((addr & mask) == (conn->tuple.src.ip & mask)) {
10932 +                       /* same source IP address -> be counted! */
10933 +                       matches++;
10934 +               }
10935 +               nf_conntrack_put(&found->ctrack->infos[0]);
10936 +       }
10937 +       if (addit) {
10938 +               /* save the new connection in our list */
10939 +#if DEBUG
10940 +               printk("ipt_connlimit [%d]: src=%u.%u.%u.%u:%d dst=%u.%u.%u.%u:%d new\n",
10941 +                      ipt_iphash(addr & mask),
10942 +                      NIPQUAD(tuple.src.ip), ntohs(tuple.src.u.tcp.port),
10943 +                      NIPQUAD(tuple.dst.ip), ntohs(tuple.dst.u.tcp.port));
10944 +#endif
10945 +               conn = kmalloc(sizeof(*conn),GFP_ATOMIC);
10946 +               if (NULL == conn)
10947 +                       return -1;
10948 +               memset(conn,0,sizeof(*conn));
10949 +               INIT_LIST_HEAD(&conn->list);
10950 +               conn->tuple = tuple;
10951 +               list_add(&conn->list,hash);
10952 +               matches++;
10953 +       }
10954 +       spin_unlock(&data->lock);
10955 +       return matches;
10956 +}
10957 +
10958 +static int
10959 +match(const struct sk_buff *skb,
10960 +      const struct net_device *in,
10961 +      const struct net_device *out,
10962 +      const void *matchinfo,
10963 +      int offset,
10964 +      int *hotdrop)
10965 +{
10966 +       const struct ipt_connlimit_info *info = matchinfo;
10967 +       int connections, match;
10968 +       struct ip_conntrack *ct;
10969 +       enum ip_conntrack_info ctinfo;
10970 +
10971 +       ct = ip_conntrack_get((struct sk_buff *)skb, &ctinfo);
10972 +       if (NULL == ct) {
10973 +               printk("ipt_connlimit: Oops: invalid ct state ?\n");
10974 +               *hotdrop = 1;
10975 +               return 0;
10976 +       }
10977 +       connections = count_them(info->data,skb->nh.iph->saddr,info->mask,ct);
10978 +       if (-1 == connections) {
10979 +               printk("ipt_connlimit: Hmm, kmalloc failed :-(\n");
10980 +               *hotdrop = 1; /* let's free some memory :-) */
10981 +               return 0;
10982 +       }
10983 +        match = (info->inverse) ? (connections <= info->limit) : (connections > info->limit);
10984 +#if DEBUG
10985 +       printk("ipt_connlimit: src=%u.%u.%u.%u mask=%u.%u.%u.%u "
10986 +              "connections=%d limit=%d match=%s\n",
10987 +              NIPQUAD(skb->nh.iph->saddr), NIPQUAD(info->mask),
10988 +              connections, info->limit, match ? "yes" : "no");
10989 +#endif
10990 +
10991 +       return match;
10992 +}
10993 +
10994 +static int check(const char *tablename,
10995 +                const struct ipt_ip *ip,
10996 +                void *matchinfo,
10997 +                unsigned int matchsize,
10998 +                unsigned int hook_mask)
10999 +{
11000 +       struct ipt_connlimit_info *info = matchinfo;
11001 +       int i;
11002 +
11003 +       /* verify size */
11004 +       if (matchsize != IPT_ALIGN(sizeof(struct ipt_connlimit_info)))
11005 +               return 0;
11006 +
11007 +       /* refuse anything but tcp */
11008 +       if (ip->proto != IPPROTO_TCP)
11009 +               return 0;
11010 +
11011 +       /* init private data */
11012 +       info->data = kmalloc(sizeof(struct ipt_connlimit_data),GFP_KERNEL);
11013 +       spin_lock_init(&(info->data->lock));
11014 +       for (i = 0; i < 256; i++)
11015 +               INIT_LIST_HEAD(&(info->data->iphash[i]));
11016 +       
11017 +       return 1;
11018 +}
11019 +
11020 +static void destroy(void *matchinfo, unsigned int matchinfosize)
11021 +{
11022 +       struct ipt_connlimit_info *info = matchinfo;
11023 +       struct ipt_connlimit_conn *conn;
11024 +       struct list_head *hash;
11025 +       int i;
11026 +
11027 +       /* cleanup */
11028 +       for (i = 0; i < 256; i++) {
11029 +               hash = &(info->data->iphash[i]);
11030 +               while (hash != hash->next) {
11031 +                       conn = list_entry(hash->next,struct ipt_connlimit_conn,list);
11032 +                       list_del(hash->next);
11033 +                       kfree(conn);
11034 +               }
11035 +       }
11036 +       kfree(info->data);
11037 +}
11038 +
11039 +static struct ipt_match connlimit_match = { 
11040 +       .name = "connlimit",
11041 +       .match = &match,
11042 +       .checkentry = &check,
11043 +       .destroy = &destroy,
11044 +       .me = THIS_MODULE
11045 +};
11046 +
11047 +static int __init init(void)
11048 +{
11049 +       return ipt_register_match(&connlimit_match);
11050 +}
11051 +
11052 +static void __exit fini(void)
11053 +{
11054 +       ipt_unregister_match(&connlimit_match);
11055 +}
11056 +
11057 +module_init(init);
11058 +module_exit(fini);
11059 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_connmark.c linux-2.6.7-rc3/net/ipv4/netfilter/ipt_connmark.c
11060 --- linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_connmark.c       1970-01-01 01:00:00.000000000 +0100
11061 +++ linux-2.6.7-rc3/net/ipv4/netfilter/ipt_connmark.c   2004-06-08 10:36:58.000000000 +0200
11062 @@ -0,0 +1,81 @@
11063 +/* This kernel module matches connection mark values set by the
11064 + * CONNMARK target
11065 + *
11066 + * Copyright (C) 2002,2004 MARA Systems AB <http://www.marasystems.com>
11067 + * by Henrik Nordstrom <hno@marasystems.com>
11068 + *
11069 + * This program is free software; you can redistribute it and/or modify
11070 + * it under the terms of the GNU General Public License as published by
11071 + * the Free Software Foundation; either version 2 of the License, or
11072 + * (at your option) any later version.
11073 + *
11074 + * This program is distributed in the hope that it will be useful,
11075 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11076 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11077 + * GNU General Public License for more details.
11078 + *
11079 + * You should have received a copy of the GNU General Public License
11080 + * along with this program; if not, write to the Free Software
11081 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
11082 + */
11083 +
11084 +#include <linux/module.h>
11085 +#include <linux/skbuff.h>
11086 +
11087 +MODULE_AUTHOR("Henrik Nordstrom <hno@marasytems.com>");
11088 +MODULE_DESCRIPTION("IP tables connmark match module");
11089 +MODULE_LICENSE("GPL");
11090 +
11091 +#include <linux/netfilter_ipv4/ip_tables.h>
11092 +#include <linux/netfilter_ipv4/ipt_connmark.h>
11093 +#include <linux/netfilter_ipv4/ip_conntrack.h>
11094 +
11095 +static int
11096 +match(const struct sk_buff *skb,
11097 +      const struct net_device *in,
11098 +      const struct net_device *out,
11099 +      const void *matchinfo,
11100 +      int offset,
11101 +      int *hotdrop)
11102 +{
11103 +       const struct ipt_connmark_info *info = matchinfo;
11104 +       enum ip_conntrack_info ctinfo;
11105 +       struct ip_conntrack *ct = ip_conntrack_get((struct sk_buff *)skb, &ctinfo);
11106 +       if (!ct)
11107 +               return 0;
11108 +
11109 +       return ((ct->mark & info->mask) == info->mark) ^ info->invert;
11110 +}
11111 +
11112 +static int
11113 +checkentry(const char *tablename,
11114 +          const struct ipt_ip *ip,
11115 +          void *matchinfo,
11116 +          unsigned int matchsize,
11117 +          unsigned int hook_mask)
11118 +{
11119 +       if (matchsize != IPT_ALIGN(sizeof(struct ipt_connmark_info)))
11120 +               return 0;
11121 +
11122 +       return 1;
11123 +}
11124 +
11125 +static struct ipt_match connmark_match = {
11126 +       .name = "connmark",
11127 +       .match = &match,
11128 +       .checkentry = &checkentry,
11129 +       .me = THIS_MODULE
11130 +};
11131 +
11132 +static int __init init(void)
11133 +{
11134 +       return ipt_register_match(&connmark_match);
11135 +}
11136 +
11137 +static void __exit fini(void)
11138 +{
11139 +       ipt_unregister_match(&connmark_match);
11140 +}
11141 +
11142 +module_init(init);
11143 +module_exit(fini);
11144 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_dstlimit.c linux-2.6.7-rc3/net/ipv4/netfilter/ipt_dstlimit.c
11145 --- linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_dstlimit.c       1970-01-01 01:00:00.000000000 +0100
11146 +++ linux-2.6.7-rc3/net/ipv4/netfilter/ipt_dstlimit.c   2004-06-08 10:31:34.000000000 +0200
11147 @@ -0,0 +1,690 @@
11148 +/* iptables match extension to limit the number of packets per second
11149 + * seperately for each destination.
11150 + *
11151 + * (C) 2003 by Harald Welte <laforge@netfilter.org>
11152 + *
11153 + * $Id$
11154 + *
11155 + * Development of this code was funded by Astaro AG, http://www.astaro.com/
11156 + *
11157 + * based on ipt_limit.c by:
11158 + * Jérôme de Vivie     <devivie@info.enserb.u-bordeaux.fr>
11159 + * Hervé Eychenne      <eychenne@info.enserb.u-bordeaux.fr>
11160 + * Rusty Russell       <rusty@rustcorp.com.au>
11161 + *
11162 + * The general idea is to create a hash table for every dstip and have a
11163 + * seperate limit counter per tuple.  This way you can do something like 'limit
11164 + * the number of syn packets for each of my internal addresses.
11165 + *
11166 + * Ideally this would just be implemented as a general 'hash' match, which would
11167 + * allow us to attach any iptables target to it's hash buckets.  But this is
11168 + * not possible in the current iptables architecture.  As always, pkttables for
11169 + * 2.7.x will help ;)
11170 + */
11171 +#include <linux/module.h>
11172 +#include <linux/skbuff.h>
11173 +#include <linux/spinlock.h>
11174 +#include <linux/random.h>
11175 +#include <linux/jhash.h>
11176 +#include <linux/slab.h>
11177 +#include <linux/vmalloc.h>
11178 +#include <linux/tcp.h>
11179 +#include <linux/udp.h>
11180 +#include <linux/proc_fs.h>
11181 +#include <linux/seq_file.h>
11182 +
11183 +#define ASSERT_READ_LOCK(x) 
11184 +#define ASSERT_WRITE_LOCK(x) 
11185 +#include <linux/netfilter_ipv4/lockhelp.h>
11186 +#include <linux/netfilter_ipv4/listhelp.h>
11187 +
11188 +#include <linux/netfilter_ipv4/ip_tables.h>
11189 +#include <linux/netfilter_ipv4/ipt_dstlimit.h>
11190 +
11191 +/* FIXME: this is just for IP_NF_ASSERRT */
11192 +#include <linux/netfilter_ipv4/ip_conntrack.h>
11193 +
11194 +#define MS2JIFFIES(x) ((x*HZ)/1000)
11195 +
11196 +MODULE_LICENSE("GPL");
11197 +MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>");
11198 +MODULE_DESCRIPTION("iptables match for limiting per destination");
11199 +
11200 +/* need to declare this at the top */
11201 +static struct proc_dir_entry *dstlimit_procdir;
11202 +static struct file_operations dl_file_ops;
11203 +
11204 +/* hash table crap */
11205 +
11206 +struct dsthash_dst {
11207 +       u_int32_t src_ip;
11208 +       u_int32_t dst_ip;
11209 +       u_int16_t port;
11210 +};
11211 +
11212 +struct dsthash_ent {
11213 +       /* static / read-only parts in the beginning */
11214 +       struct list_head list;
11215 +       struct dsthash_dst dst;
11216 +
11217 +       /* modified structure members in the end */
11218 +       unsigned long expires;          /* precalculated expiry time */
11219 +       struct {
11220 +               unsigned long prev;     /* last modification */
11221 +               u_int32_t credit;
11222 +               u_int32_t credit_cap, cost;
11223 +       } rateinfo;
11224 +};
11225 +
11226 +struct ipt_dstlimit_htable {
11227 +       struct list_head list;          /* global list of all htables */
11228 +       atomic_t use;
11229 +
11230 +       struct dstlimit_cfg cfg;        /* config */
11231 +
11232 +       /* used internally */
11233 +       spinlock_t lock;                /* lock for list_head */
11234 +       u_int32_t rnd;                  /* random seed for hash */
11235 +       struct timer_list timer;        /* timer for gc */
11236 +       atomic_t count;                 /* number entries in table */
11237 +
11238 +       /* seq_file stuff */
11239 +       struct proc_dir_entry *pde;
11240 +
11241 +       struct list_head hash[0];       /* hashtable itself */
11242 +};
11243 +
11244 +DECLARE_RWLOCK(dstlimit_lock);         /* protects htables list */
11245 +static LIST_HEAD(dstlimit_htables);
11246 +static kmem_cache_t *dstlimit_cachep;
11247 +
11248 +static inline int dst_cmp(const struct dsthash_ent *ent, struct dsthash_dst *b)
11249 +{
11250 +       return (ent->dst.dst_ip == b->dst_ip 
11251 +               && ent->dst.port == b->port
11252 +               && ent->dst.src_ip == b->src_ip);
11253 +}
11254 +
11255 +static inline u_int32_t
11256 +hash_dst(const struct ipt_dstlimit_htable *ht, const struct dsthash_dst *dst)
11257 +{
11258 +       return (jhash_3words(dst->dst_ip, dst->port, 
11259 +                            dst->src_ip, ht->rnd) % ht->cfg.size);
11260 +}
11261 +
11262 +static inline struct dsthash_ent *
11263 +__dsthash_find(const struct ipt_dstlimit_htable *ht, struct dsthash_dst *dst)
11264 +{
11265 +       struct dsthash_ent *ent;
11266 +       u_int32_t hash = hash_dst(ht, dst);
11267 +       MUST_BE_LOCKED(&ht->lock);
11268 +       ent = LIST_FIND(&ht->hash[hash], dst_cmp, struct dsthash_ent *, dst);
11269 +       return ent;
11270 +}
11271 +
11272 +/* allocate dsthash_ent, initialize dst, put in htable and lock it */
11273 +static struct dsthash_ent *
11274 +__dsthash_alloc_init(struct ipt_dstlimit_htable *ht, struct dsthash_dst *dst)
11275 +{
11276 +       struct dsthash_ent *ent;
11277 +
11278 +       /* initialize hash with random val at the time we allocate
11279 +        * the first hashtable entry */
11280 +       if (!ht->rnd)
11281 +               get_random_bytes(&ht->rnd, 4);
11282 +
11283 +       if (ht->cfg.max &&
11284 +           atomic_read(&ht->count) >= ht->cfg.max) {
11285 +               /* FIXME: do something. question is what.. */
11286 +               if (net_ratelimit())
11287 +                       printk(KERN_WARNING 
11288 +                               "ipt_dstlimit: max count of %u reached\n", 
11289 +                               ht->cfg.max);
11290 +               return NULL;
11291 +       }
11292 +
11293 +       ent = kmem_cache_alloc(dstlimit_cachep, GFP_ATOMIC);
11294 +       if (!ent) {
11295 +               if (net_ratelimit())
11296 +                       printk(KERN_ERR 
11297 +                               "ipt_dstlimit: can't allocate dsthash_ent\n");
11298 +               return NULL;
11299 +       }
11300 +
11301 +       atomic_inc(&ht->count);
11302 +
11303 +       ent->dst.dst_ip = dst->dst_ip;
11304 +       ent->dst.port = dst->port;
11305 +       ent->dst.src_ip = dst->src_ip;
11306 +
11307 +       list_add(&ent->list, &ht->hash[hash_dst(ht, dst)]);
11308 +
11309 +       return ent;
11310 +}
11311 +
11312 +static inline void 
11313 +__dsthash_free(struct ipt_dstlimit_htable *ht, struct dsthash_ent *ent)
11314 +{
11315 +       MUST_BE_LOCKED(&ht->lock);
11316 +
11317 +       list_del(&ent->list);
11318 +       kmem_cache_free(dstlimit_cachep, ent);
11319 +       atomic_dec(&ht->count);
11320 +}
11321 +static void htable_gc(unsigned long htlong);
11322 +
11323 +static int htable_create(struct ipt_dstlimit_info *minfo)
11324 +{
11325 +       int i;
11326 +       unsigned int size;
11327 +       struct ipt_dstlimit_htable *hinfo;
11328 +
11329 +       if (minfo->cfg.size)
11330 +               size = minfo->cfg.size;
11331 +       else {
11332 +               size = (((num_physpages << PAGE_SHIFT) / 16384)
11333 +                        / sizeof(struct list_head));
11334 +               if (num_physpages > (1024 * 1024 * 1024 / PAGE_SIZE))
11335 +                       size = 8192;
11336 +               if (size < 16)
11337 +                       size = 16;
11338 +       }
11339 +       /* FIXME: don't use vmalloc() here or anywhere else -HW */
11340 +       hinfo = vmalloc(sizeof(struct ipt_dstlimit_htable)
11341 +                       + (sizeof(struct list_head) * size));
11342 +       if (!hinfo) {
11343 +               printk(KERN_ERR "ipt_dstlimit: Unable to create hashtable\n");
11344 +               return -1;
11345 +       }
11346 +       minfo->hinfo = hinfo;
11347 +
11348 +       /* copy match config into hashtable config */
11349 +       memcpy(&hinfo->cfg, &minfo->cfg, sizeof(hinfo->cfg));
11350 +       hinfo->cfg.size = size;
11351 +       if (!hinfo->cfg.max)
11352 +               hinfo->cfg.max = 8 * hinfo->cfg.size;
11353 +       else if (hinfo->cfg.max < hinfo->cfg.size)
11354 +               hinfo->cfg.max = hinfo->cfg.size;
11355 +
11356 +       for (i = 0; i < hinfo->cfg.size; i++)
11357 +               INIT_LIST_HEAD(&hinfo->hash[i]);
11358 +
11359 +       atomic_set(&hinfo->count, 0);
11360 +       atomic_set(&hinfo->use, 1);
11361 +       hinfo->rnd = 0;
11362 +       hinfo->lock = SPIN_LOCK_UNLOCKED;
11363 +       hinfo->pde = create_proc_entry(minfo->name, 0, dstlimit_procdir);
11364 +       if (!hinfo->pde) {
11365 +               vfree(hinfo);
11366 +               return -1;
11367 +       }
11368 +       hinfo->pde->proc_fops = &dl_file_ops;
11369 +       hinfo->pde->data = hinfo;
11370 +
11371 +       init_timer(&hinfo->timer);
11372 +       hinfo->timer.expires = jiffies + MS2JIFFIES(hinfo->cfg.gc_interval);
11373 +       hinfo->timer.data = (unsigned long )hinfo;
11374 +       hinfo->timer.function = htable_gc;
11375 +       add_timer(&hinfo->timer);
11376 +
11377 +       WRITE_LOCK(&dstlimit_lock);
11378 +       list_add(&hinfo->list, &dstlimit_htables);
11379 +       WRITE_UNLOCK(&dstlimit_lock);
11380 +
11381 +       return 0;
11382 +}
11383 +
11384 +static int select_all(struct ipt_dstlimit_htable *ht, struct dsthash_ent *he)
11385 +{
11386 +       return 1;
11387 +}
11388 +
11389 +static int select_gc(struct ipt_dstlimit_htable *ht, struct dsthash_ent *he)
11390 +{
11391 +       return (jiffies >= he->expires);
11392 +}
11393 +
11394 +static void htable_selective_cleanup(struct ipt_dstlimit_htable *ht,
11395 +                               int (*select)(struct ipt_dstlimit_htable *ht, 
11396 +                                             struct dsthash_ent *he))
11397 +{
11398 +       int i;
11399 +
11400 +       IP_NF_ASSERT(ht->cfg.size && ht->cfg.max);
11401 +
11402 +       /* lock hash table and iterate over it */
11403 +       LOCK_BH(&ht->lock);
11404 +       for (i = 0; i < ht->cfg.size; i++) {
11405 +               struct dsthash_ent *dh, *n;
11406 +               list_for_each_entry_safe(dh, n, &ht->hash[i], list) {
11407 +                       if ((*select)(ht, dh))
11408 +                               __dsthash_free(ht, dh);
11409 +               }
11410 +       }
11411 +       UNLOCK_BH(&ht->lock);
11412 +}
11413 +
11414 +/* hash table garbage collector, run by timer */
11415 +static void htable_gc(unsigned long htlong)
11416 +{
11417 +       struct ipt_dstlimit_htable *ht = (struct ipt_dstlimit_htable *)htlong;
11418 +
11419 +       htable_selective_cleanup(ht, select_gc);
11420 +
11421 +       /* re-add the timer accordingly */
11422 +       ht->timer.expires = jiffies + MS2JIFFIES(ht->cfg.gc_interval);
11423 +       add_timer(&ht->timer);
11424 +}
11425 +
11426 +static void htable_destroy(struct ipt_dstlimit_htable *hinfo)
11427 +{
11428 +       /* remove timer, if it is pending */
11429 +       if (timer_pending(&hinfo->timer))
11430 +               del_timer(&hinfo->timer);
11431 +
11432 +       /* remove proc entry */
11433 +       remove_proc_entry(hinfo->pde->name, dstlimit_procdir);
11434 +
11435 +       htable_selective_cleanup(hinfo, select_all);
11436 +       vfree(hinfo);
11437 +}
11438 +
11439 +static struct ipt_dstlimit_htable *htable_find_get(char *name)
11440 +{
11441 +       struct ipt_dstlimit_htable *hinfo;
11442 +
11443 +       READ_LOCK(&dstlimit_lock);
11444 +       list_for_each_entry(hinfo, &dstlimit_htables, list) {
11445 +               if (!strcmp(name, hinfo->pde->name)) {
11446 +                       atomic_inc(&hinfo->use);
11447 +                       READ_UNLOCK(&dstlimit_lock);
11448 +                       return hinfo;
11449 +               }
11450 +       }
11451 +       READ_UNLOCK(&dstlimit_lock);
11452 +
11453 +       return NULL;
11454 +}
11455 +
11456 +static void htable_put(struct ipt_dstlimit_htable *hinfo)
11457 +{
11458 +       if (atomic_dec_and_test(&hinfo->use)) {
11459 +               WRITE_LOCK(&dstlimit_lock);
11460 +               list_del(&hinfo->list);
11461 +               WRITE_UNLOCK(&dstlimit_lock);
11462 +               htable_destroy(hinfo);
11463 +       }
11464 +}
11465 +
11466 +
11467 +/* The algorithm used is the Simple Token Bucket Filter (TBF)
11468 + * see net/sched/sch_tbf.c in the linux source tree
11469 + */
11470 +
11471 +/* Rusty: This is my (non-mathematically-inclined) understanding of
11472 +   this algorithm.  The `average rate' in jiffies becomes your initial
11473 +   amount of credit `credit' and the most credit you can ever have
11474 +   `credit_cap'.  The `peak rate' becomes the cost of passing the
11475 +   test, `cost'.
11476 +
11477 +   `prev' tracks the last packet hit: you gain one credit per jiffy.
11478 +   If you get credit balance more than this, the extra credit is
11479 +   discarded.  Every time the match passes, you lose `cost' credits;
11480 +   if you don't have that many, the test fails.
11481 +
11482 +   See Alexey's formal explanation in net/sched/sch_tbf.c.
11483 +
11484 +   To get the maximum range, we multiply by this factor (ie. you get N
11485 +   credits per jiffy).  We want to allow a rate as low as 1 per day
11486 +   (slowest userspace tool allows), which means
11487 +   CREDITS_PER_JIFFY*HZ*60*60*24 < 2^32 ie.
11488 +*/
11489 +#define MAX_CPJ (0xFFFFFFFF / (HZ*60*60*24))
11490 +
11491 +/* Repeated shift and or gives us all 1s, final shift and add 1 gives
11492 + * us the power of 2 below the theoretical max, so GCC simply does a
11493 + * shift. */
11494 +#define _POW2_BELOW2(x) ((x)|((x)>>1))
11495 +#define _POW2_BELOW4(x) (_POW2_BELOW2(x)|_POW2_BELOW2((x)>>2))
11496 +#define _POW2_BELOW8(x) (_POW2_BELOW4(x)|_POW2_BELOW4((x)>>4))
11497 +#define _POW2_BELOW16(x) (_POW2_BELOW8(x)|_POW2_BELOW8((x)>>8))
11498 +#define _POW2_BELOW32(x) (_POW2_BELOW16(x)|_POW2_BELOW16((x)>>16))
11499 +#define POW2_BELOW32(x) ((_POW2_BELOW32(x)>>1) + 1)
11500 +
11501 +#define CREDITS_PER_JIFFY POW2_BELOW32(MAX_CPJ)
11502 +
11503 +/* Precision saver. */
11504 +static inline u_int32_t
11505 +user2credits(u_int32_t user)
11506 +{
11507 +       /* If multiplying would overflow... */
11508 +       if (user > 0xFFFFFFFF / (HZ*CREDITS_PER_JIFFY))
11509 +               /* Divide first. */
11510 +               return (user / IPT_DSTLIMIT_SCALE) * HZ * CREDITS_PER_JIFFY;
11511 +
11512 +       return (user * HZ * CREDITS_PER_JIFFY) / IPT_DSTLIMIT_SCALE;
11513 +}
11514 +
11515 +static inline void rateinfo_recalc(struct dsthash_ent *dh, unsigned long now)
11516 +{
11517 +       dh->rateinfo.credit += (now - xchg(&dh->rateinfo.prev, now)) 
11518 +                                       * CREDITS_PER_JIFFY;
11519 +       if (dh->rateinfo.credit > dh->rateinfo.credit_cap)
11520 +               dh->rateinfo.credit = dh->rateinfo.credit_cap;
11521 +}
11522 +
11523 +static int
11524 +dstlimit_match(const struct sk_buff *skb,
11525 +               const struct net_device *in,
11526 +               const struct net_device *out,
11527 +               const void *matchinfo,
11528 +               int offset,
11529 +               int *hotdrop)
11530 +{
11531 +       struct ipt_dstlimit_info *r = 
11532 +               ((struct ipt_dstlimit_info *)matchinfo)->u.master;
11533 +       struct ipt_dstlimit_htable *hinfo = r->hinfo;
11534 +       unsigned long now = jiffies;
11535 +       struct dsthash_ent *dh;
11536 +       struct dsthash_dst dst;
11537 +
11538 +       memset(&dst, 0, sizeof(dst));
11539 +
11540 +       /* dest ip is always in hash */
11541 +       dst.dst_ip = skb->nh.iph->daddr;
11542 +
11543 +       /* source ip only if respective hashmode, otherwise set to
11544 +        * zero */
11545 +       if (hinfo->cfg.mode & IPT_DSTLIMIT_HASH_SIP)
11546 +               dst.src_ip = skb->nh.iph->saddr;
11547 +
11548 +       /* dest port only if respective mode */
11549 +       if (hinfo->cfg.mode & IPT_DSTLIMIT_HASH_DPT) {
11550 +               u16 ports[2];
11551 +
11552 +               /* Must not be a fragment. */
11553 +               if (offset)
11554 +                       return 0;
11555 +
11556 +               /* Must be big enough to read ports (both UDP and TCP have
11557 +                  them at the start). */
11558 +               if (skb_copy_bits(skb, skb->nh.iph->ihl*4, ports, sizeof(ports)) < 0) {
11559 +                       /* We've been asked to examine this packet, and we
11560 +                          can't.  Hence, no choice but to drop. */
11561 +                       *hotdrop = 1;
11562 +                       return 0;
11563 +               }
11564 +
11565 +               switch (skb->nh.iph->protocol) {
11566 +                       struct tcphdr *th;
11567 +                       struct udphdr *uh;
11568 +               case IPPROTO_TCP:
11569 +                       th = (void *)skb->nh.iph+skb->nh.iph->ihl*4;
11570 +                       dst.port = th->dest;
11571 +                       break;
11572 +               case IPPROTO_UDP:
11573 +                       uh = (void *)skb->nh.iph+skb->nh.iph->ihl*4;
11574 +                       dst.port = uh->dest;
11575 +                       break;
11576 +               default:
11577 +                       break;
11578 +               }
11579 +       } 
11580 +
11581 +       LOCK_BH(&hinfo->lock);
11582 +       dh = __dsthash_find(hinfo, &dst);
11583 +       if (!dh) {
11584 +               dh = __dsthash_alloc_init(hinfo, &dst);
11585 +
11586 +               if (!dh) {
11587 +                       /* enomem... don't match == DROP */
11588 +                       if (net_ratelimit())
11589 +                               printk(KERN_ERR "%s: ENOMEM\n", __FUNCTION__);
11590 +                       UNLOCK_BH(&hinfo->lock);
11591 +                       return 0;
11592 +               }
11593 +
11594 +               dh->expires = jiffies + MS2JIFFIES(hinfo->cfg.expire);
11595 +
11596 +               dh->rateinfo.prev = jiffies;
11597 +               dh->rateinfo.credit = user2credits(hinfo->cfg.avg * 
11598 +                                                       hinfo->cfg.burst);
11599 +               dh->rateinfo.credit_cap = user2credits(hinfo->cfg.avg * 
11600 +                                                       hinfo->cfg.burst);
11601 +               dh->rateinfo.cost = user2credits(hinfo->cfg.avg);
11602 +
11603 +               UNLOCK_BH(&hinfo->lock);
11604 +               return 1;
11605 +       }
11606 +
11607 +       /* update expiration timeout */
11608 +       dh->expires = now + MS2JIFFIES(hinfo->cfg.expire);
11609 +
11610 +       rateinfo_recalc(dh, now);
11611 +       if (dh->rateinfo.credit >= dh->rateinfo.cost) {
11612 +               /* We're underlimit. */
11613 +               dh->rateinfo.credit -= dh->rateinfo.cost;
11614 +               UNLOCK_BH(&hinfo->lock);
11615 +               return 1;
11616 +       }
11617 +
11618 +               UNLOCK_BH(&hinfo->lock);
11619 +
11620 +       /* default case: we're overlimit, thus don't match */
11621 +       return 0;
11622 +}
11623 +
11624 +static int
11625 +dstlimit_checkentry(const char *tablename,
11626 +                    const struct ipt_ip *ip,
11627 +                    void *matchinfo,
11628 +                    unsigned int matchsize,
11629 +                    unsigned int hook_mask)
11630 +{
11631 +       struct ipt_dstlimit_info *r = matchinfo;
11632 +
11633 +       if (matchsize != IPT_ALIGN(sizeof(struct ipt_dstlimit_info)))
11634 +               return 0;
11635 +
11636 +       /* Check for overflow. */
11637 +       if (r->cfg.burst == 0
11638 +           || user2credits(r->cfg.avg * r->cfg.burst) < 
11639 +                                       user2credits(r->cfg.avg)) {
11640 +               printk(KERN_ERR "ipt_dstlimit: Overflow, try lower: %u/%u\n",
11641 +                      r->cfg.avg, r->cfg.burst);
11642 +               return 0;
11643 +       }
11644 +
11645 +       if (r->cfg.mode == 0 
11646 +           || r->cfg.mode > (IPT_DSTLIMIT_HASH_DPT
11647 +                         |IPT_DSTLIMIT_HASH_DIP
11648 +                         |IPT_DSTLIMIT_HASH_SIP))
11649 +               return 0;
11650 +
11651 +       if (!r->cfg.gc_interval)
11652 +               return 0;
11653 +       
11654 +       if (!r->cfg.expire)
11655 +               return 0;
11656 +
11657 +       r->hinfo = htable_find_get(r->name);
11658 +       if (!r->hinfo && (htable_create(r) != 0)) {
11659 +               return 0;
11660 +       }
11661 +
11662 +       /* Ugly hack: For SMP, we only want to use one set */
11663 +       r->u.master = r;
11664 +
11665 +       return 1;
11666 +}
11667 +
11668 +static void
11669 +dstlimit_destroy(void *matchinfo, unsigned int matchsize)
11670 +{
11671 +       struct ipt_dstlimit_info *r = (struct ipt_dstlimit_info *) matchinfo;
11672 +
11673 +       htable_put(r->hinfo);
11674 +}
11675 +
11676 +static struct ipt_match ipt_dstlimit = { 
11677 +       .list = { .prev = NULL, .next = NULL }, 
11678 +       .name = "dstlimit", 
11679 +       .match = dstlimit_match, 
11680 +       .checkentry = dstlimit_checkentry, 
11681 +       .destroy = dstlimit_destroy,
11682 +       .me = THIS_MODULE 
11683 +};
11684 +
11685 +/* PROC stuff */
11686 +
11687 +static void *dl_seq_start(struct seq_file *s, loff_t *pos)
11688 +{
11689 +       struct proc_dir_entry *pde = s->private;
11690 +       struct ipt_dstlimit_htable *htable = pde->data;
11691 +       unsigned int *bucket;
11692 +
11693 +       LOCK_BH(&htable->lock);
11694 +       if (*pos >= htable->cfg.size)
11695 +               return NULL;
11696 +
11697 +       bucket = kmalloc(sizeof(unsigned int), GFP_KERNEL);
11698 +       if (!bucket)
11699 +               return ERR_PTR(-ENOMEM);
11700 +
11701 +       *bucket = *pos;
11702 +       return bucket;
11703 +}
11704 +
11705 +static void *dl_seq_next(struct seq_file *s, void *v, loff_t *pos)
11706 +{
11707 +       struct proc_dir_entry *pde = s->private;
11708 +       struct ipt_dstlimit_htable *htable = pde->data;
11709 +       unsigned int *bucket = (unsigned int *)v;
11710 +
11711 +       *pos = ++(*bucket);
11712 +       if (*pos >= htable->cfg.size) {
11713 +               kfree(v);
11714 +               return NULL;
11715 +       }
11716 +       return bucket;
11717 +}
11718 +
11719 +static void dl_seq_stop(struct seq_file *s, void *v)
11720 +{
11721 +       struct proc_dir_entry *pde = s->private;
11722 +       struct ipt_dstlimit_htable *htable = pde->data;
11723 +       unsigned int *bucket = (unsigned int *)v;
11724 +
11725 +       kfree(bucket);
11726 +
11727 +       UNLOCK_BH(&htable->lock);
11728 +}
11729 +
11730 +static inline int dl_seq_real_show(struct dsthash_ent *ent, struct seq_file *s)
11731 +{
11732 +       /* recalculate to show accurate numbers */
11733 +       rateinfo_recalc(ent, jiffies);
11734 +
11735 +       return seq_printf(s, "%ld %u.%u.%u.%u->%u.%u.%u.%u:%u %u %u %u\n",
11736 +                       (ent->expires - jiffies)/HZ,
11737 +                       NIPQUAD(ent->dst.src_ip),
11738 +                       NIPQUAD(ent->dst.dst_ip), ntohs(ent->dst.port),
11739 +                       ent->rateinfo.credit, ent->rateinfo.credit_cap,
11740 +                       ent->rateinfo.cost);
11741 +}
11742 +
11743 +static int dl_seq_show(struct seq_file *s, void *v)
11744 +{
11745 +       struct proc_dir_entry *pde = s->private;
11746 +       struct ipt_dstlimit_htable *htable = pde->data;
11747 +       unsigned int *bucket = (unsigned int *)v;
11748 +
11749 +       if (LIST_FIND_W(&htable->hash[*bucket], dl_seq_real_show,
11750 +                     struct dsthash_ent *, s)) {
11751 +               /* buffer was filled and unable to print that tuple */
11752 +               return 1;
11753 +       }
11754 +       return 0;
11755 +}
11756 +
11757 +static struct seq_operations dl_seq_ops = {
11758 +       .start = dl_seq_start,
11759 +       .next  = dl_seq_next,
11760 +       .stop  = dl_seq_stop,
11761 +       .show  = dl_seq_show
11762 +};
11763 +
11764 +static int dl_proc_open(struct inode *inode, struct file *file)
11765 +{
11766 +       int ret = seq_open(file, &dl_seq_ops);
11767 +
11768 +       if (!ret) {
11769 +               struct seq_file *sf = file->private_data;
11770 +               sf->private = PDE(inode);
11771 +       }
11772 +       return ret;
11773 +}
11774 +
11775 +static struct file_operations dl_file_ops = {
11776 +       .owner   = THIS_MODULE,
11777 +       .open    = dl_proc_open,
11778 +       .read    = seq_read,
11779 +       .llseek  = seq_lseek,
11780 +       .release = seq_release
11781 +};
11782 +
11783 +static int init_or_fini(int fini)
11784 +{
11785 +       int ret = 0;
11786 +
11787 +       if (fini)
11788 +               goto cleanup;
11789 +
11790 +       if (ipt_register_match(&ipt_dstlimit)) {
11791 +               ret = -EINVAL;
11792 +               goto cleanup_nothing;
11793 +       }
11794 +
11795 +       /* FIXME: do we really want HWCACHE_ALIGN since our objects are
11796 +        * quite small ? */
11797 +       dstlimit_cachep = kmem_cache_create("ipt_dstlimit",
11798 +                                           sizeof(struct dsthash_ent), 0,
11799 +                                           SLAB_HWCACHE_ALIGN, NULL, NULL);
11800 +       if (!dstlimit_cachep) {
11801 +               printk(KERN_ERR "Unable to create ipt_dstlimit slab cache\n");
11802 +               ret = -ENOMEM;
11803 +               goto cleanup_unreg_match;
11804 +       }
11805 +
11806 +       dstlimit_procdir = proc_mkdir("ipt_dstlimit", proc_net);
11807 +       if (!dstlimit_procdir) {
11808 +               printk(KERN_ERR "Unable to create proc dir entry\n");
11809 +               ret = -ENOMEM;
11810 +               goto cleanup_free_slab;
11811 +       }
11812 +
11813 +       return ret;
11814 +
11815 +cleanup:
11816 +       remove_proc_entry("ipt_dstlimit", proc_net);
11817 +cleanup_free_slab:
11818 +       kmem_cache_destroy(dstlimit_cachep);
11819 +cleanup_unreg_match:
11820 +       ipt_unregister_match(&ipt_dstlimit);
11821 +cleanup_nothing:
11822 +       return ret;
11823 +       
11824 +}
11825 +
11826 +static int __init init(void)
11827 +{
11828 +       return init_or_fini(0);
11829 +}
11830 +
11831 +static void __exit fini(void)
11832 +{
11833 +       init_or_fini(1);
11834 +}
11835 +
11836 +module_init(init);
11837 +module_exit(fini);
11838 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_fuzzy.c linux-2.6.7-rc3/net/ipv4/netfilter/ipt_fuzzy.c
11839 --- linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_fuzzy.c  1970-01-01 01:00:00.000000000 +0100
11840 +++ linux-2.6.7-rc3/net/ipv4/netfilter/ipt_fuzzy.c      2004-06-08 10:31:37.000000000 +0200
11841 @@ -0,0 +1,185 @@
11842 +/*
11843 + *  This module implements a simple TSK FLC 
11844 + * (Takagi-Sugeno-Kang Fuzzy Logic Controller) that aims
11845 + * to limit , in an adaptive and flexible way , the packet rate crossing 
11846 + * a given stream . It serves as an initial and very simple (but effective)
11847 + * example of how Fuzzy Logic techniques can be applied to defeat DoS attacks.
11848 + *  As a matter of fact , Fuzzy Logic can help us to insert any "behavior"  
11849 + * into our code in a precise , adaptive and efficient manner. 
11850 + *  The goal is very similar to that of "limit" match , but using techniques of
11851 + * Fuzzy Control , that allow us to shape the transfer functions precisely ,
11852 + * avoiding over and undershoots - and stuff like that .
11853 + *
11854 + *
11855 + * 2002-08-10  Hime Aguiar e Oliveira Jr. <hime@engineer.com> : Initial version.
11856 + * 2002-08-17  : Changed to eliminate floating point operations .
11857 + * 2002-08-23  : Coding style changes .
11858 +*/
11859 +
11860 +#include <linux/module.h>
11861 +#include <linux/skbuff.h>
11862 +#include <linux/ip.h>
11863 +#include <linux/random.h>
11864 +#include <net/tcp.h>
11865 +#include <linux/spinlock.h>
11866 +#include <linux/netfilter_ipv4/ip_tables.h>
11867 +#include <linux/netfilter_ipv4/ipt_fuzzy.h>
11868 +
11869 +/*
11870 + Packet Acceptance Rate - LOW and Packet Acceptance Rate - HIGH
11871 + Expressed in percentage
11872 +*/
11873 +
11874 +#define PAR_LOW                1/100
11875 +#define PAR_HIGH       1
11876 +
11877 +static spinlock_t fuzzy_lock = SPIN_LOCK_UNLOCKED ;
11878 +
11879 +MODULE_AUTHOR("Hime Aguiar e Oliveira Junior <hime@engineer.com>");
11880 +MODULE_DESCRIPTION("IP tables Fuzzy Logic Controller match module");
11881 +MODULE_LICENSE("GPL");
11882 +
11883 +static  u_int8_t mf_high(u_int32_t tx,u_int32_t mini,u_int32_t maxi)
11884 +{
11885 +       if (tx >= maxi)
11886 +               return 100;
11887 +
11888 +       if (tx <= mini)
11889 +               return 0;
11890 +
11891 +       return ( (100*(tx-mini)) / (maxi-mini) );
11892 +}
11893 +
11894 +static u_int8_t mf_low(u_int32_t tx,u_int32_t mini,u_int32_t maxi)
11895 +{
11896 +       if (tx <= mini)
11897 +               return 100;
11898 +
11899 +       if (tx >= maxi)
11900 +               return 0;
11901 +
11902 +       return ( (100*( maxi - tx ))  / ( maxi - mini ) );
11903 +}
11904 +
11905 +static int
11906 +ipt_fuzzy_match(const struct sk_buff *pskb,
11907 +              const struct net_device *in,
11908 +              const struct net_device *out,
11909 +              const void *matchinfo,
11910 +              int offset,
11911 +              int *hotdrop)
11912 +{
11913 +       /* From userspace */
11914 +       
11915 +       struct ipt_fuzzy_info *info = (struct ipt_fuzzy_info *) matchinfo;
11916 +
11917 +       u_int8_t random_number;
11918 +       unsigned long amount;
11919 +       u_int8_t howhigh, howlow;
11920 +       
11921 +
11922 +       spin_lock_bh(&fuzzy_lock); /* Rise the lock */
11923 +
11924 +       info->bytes_total += pskb->len;
11925 +       info->packets_total++;
11926 +
11927 +       info->present_time = jiffies;
11928 +       
11929 +       if (info->present_time >= info->previous_time)
11930 +               amount = info->present_time - info->previous_time;
11931 +       else { 
11932 +               /* There was a transition : I choose to re-sample 
11933 +                  and keep the old acceptance rate...
11934 +               */
11935 +
11936 +               amount = 0;
11937 +               info->previous_time = info->present_time;
11938 +               info->bytes_total = info->packets_total = 0;
11939 +       };
11940 +       
11941 +       if (amount > HZ/10) /* More than 100 ms elapsed ... */
11942 +       {
11943 +
11944 +               info->mean_rate = (u_int32_t) ((HZ*info->packets_total)  \
11945 +                                       / amount );
11946 +
11947 +               info->previous_time = info->present_time;
11948 +               info->bytes_total = info->packets_total = 0;
11949 +
11950 +               howhigh = mf_high(info->mean_rate,info->minimum_rate,info->maximum_rate);
11951 +               howlow  = mf_low(info->mean_rate,info->minimum_rate,info->maximum_rate);
11952 +
11953 +               info->acceptance_rate = (u_int8_t) \
11954 +                          (howhigh*PAR_LOW + PAR_HIGH*howlow);
11955 +
11956 +               /* In fact , the above defuzzification would require a denominator
11957 +                  proportional to (howhigh+howlow) but , in this particular case ,
11958 +                  that expression is constant .
11959 +                  An imediate consequence is that it isn't necessary to call 
11960 +                  both mf_high and mf_low - but to keep things understandable ,
11961 +                  I did so .  */ 
11962 +
11963 +       }
11964 +       
11965 +       spin_unlock_bh(&fuzzy_lock); /* Release the lock */
11966 +
11967 +
11968 +       if ( info->acceptance_rate < 100 )
11969 +       {                
11970 +               get_random_bytes((void *)(&random_number), 1);
11971 +
11972 +               /*  If within the acceptance , it can pass => don't match */
11973 +               if (random_number <= (255 * info->acceptance_rate) / 100)
11974 +                       return 0;
11975 +               else
11976 +                       return 1; /* It can't pass ( It matches ) */
11977 +       } ;
11978 +
11979 +       return 0; /* acceptance_rate == 100 % => Everything passes ... */
11980 +       
11981 +}
11982 +
11983 +static int
11984 +ipt_fuzzy_checkentry(const char *tablename,
11985 +                  const struct ipt_ip *e,
11986 +                  void *matchinfo,
11987 +                  unsigned int matchsize,
11988 +                  unsigned int hook_mask)
11989 +{
11990 +       
11991 +       const struct ipt_fuzzy_info *info = matchinfo;
11992 +
11993 +       if (matchsize != IPT_ALIGN(sizeof(struct ipt_fuzzy_info))) {
11994 +               printk("ipt_fuzzy: matchsize %u != %u\n", matchsize,
11995 +                      IPT_ALIGN(sizeof(struct ipt_fuzzy_info)));
11996 +               return 0;
11997 +       }
11998 +
11999 +       if ((info->minimum_rate < MINFUZZYRATE ) || (info->maximum_rate > MAXFUZZYRATE)
12000 +           || (info->minimum_rate >= info->maximum_rate )) {
12001 +               printk("ipt_fuzzy: BAD limits , please verify !!!\n");
12002 +               return 0;
12003 +       }
12004 +
12005 +       return 1;
12006 +}
12007 +
12008 +static struct ipt_match ipt_fuzzy_reg = { 
12009 +       .name = "fuzzy",
12010 +       .match = ipt_fuzzy_match,
12011 +       .checkentry = ipt_fuzzy_checkentry,
12012 +       .me = THIS_MODULE
12013 +};
12014 +
12015 +static int __init init(void)
12016 +{
12017 +       return ipt_register_match(&ipt_fuzzy_reg);
12018 +}
12019 +
12020 +static void __exit fini(void)
12021 +{
12022 +       ipt_unregister_match(&ipt_fuzzy_reg);
12023 +}
12024 +
12025 +module_init(init);
12026 +module_exit(fini);
12027 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_helper.c linux-2.6.7-rc3/net/ipv4/netfilter/ipt_helper.c
12028 --- linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_helper.c 2004-06-07 21:14:55.000000000 +0200
12029 +++ linux-2.6.7-rc3/net/ipv4/netfilter/ipt_helper.c     2004-06-08 10:42:23.000000000 +0200
12030 @@ -41,17 +41,17 @@
12031         struct ip_conntrack_expect *exp;
12032         struct ip_conntrack *ct;
12033         enum ip_conntrack_info ctinfo;
12034 -       int ret = 0;
12035 +       int ret = info->invert;
12036         
12037         ct = ip_conntrack_get((struct sk_buff *)skb, &ctinfo);
12038         if (!ct) {
12039                 DEBUGP("ipt_helper: Eek! invalid conntrack?\n");
12040 -               return 0;
12041 +               return ret;
12042         }
12043  
12044         if (!ct->master) {
12045                 DEBUGP("ipt_helper: conntrack %p has no master\n", ct);
12046 -               return 0;
12047 +               return ret;
12048         }
12049  
12050         exp = ct->master;
12051 @@ -71,8 +71,11 @@
12052         DEBUGP("master's name = %s , info->name = %s\n", 
12053                 exp->expectant->helper->name, info->name);
12054  
12055 -       ret = !strncmp(exp->expectant->helper->name, info->name, 
12056 -                      strlen(exp->expectant->helper->name)) ^ info->invert;
12057 +       if (info->name[0] == '\0')
12058 +               ret ^= 1;
12059 +       else
12060 +               ret ^= !strncmp(exp->expectant->helper->name, info->name, 
12061 +                               strlen(exp->expectant->helper->name));
12062  out_unlock:
12063         READ_UNLOCK(&ip_conntrack_lock);
12064         return ret;
12065 @@ -92,10 +95,6 @@
12066         if (matchsize != IPT_ALIGN(sizeof(struct ipt_helper_info)))
12067                 return 0;
12068  
12069 -       /* verify that we actually should match anything */
12070 -       if ( strlen(info->name) == 0 )
12071 -               return 0;
12072 -       
12073         return 1;
12074  }
12075  
12076 @@ -108,7 +107,6 @@
12077  
12078  static int __init init(void)
12079  {
12080 -       need_ip_conntrack();
12081         return ipt_register_match(&helper_match);
12082  }
12083  
12084 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_ipv4options.c linux-2.6.7-rc3/net/ipv4/netfilter/ipt_ipv4options.c
12085 --- linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_ipv4options.c    1970-01-01 01:00:00.000000000 +0100
12086 +++ linux-2.6.7-rc3/net/ipv4/netfilter/ipt_ipv4options.c        2004-06-08 10:31:39.000000000 +0200
12087 @@ -0,0 +1,172 @@
12088 +/*
12089 +  This is a module which is used to match ipv4 options.
12090 +  This file is distributed under the terms of the GNU General Public
12091 +  License (GPL). Copies of the GPL can be obtained from:
12092 +  ftp://prep.ai.mit.edu/pub/gnu/GPL
12093 +
12094 +  11-mars-2001 Fabrice MARIE <fabrice@netfilter.org> : initial development.
12095 +  12-july-2001 Fabrice MARIE <fabrice@netfilter.org> : added router-alert otions matching. Fixed a bug with no-srr
12096 +  12-august-2001 Imran Patel <ipatel@crosswinds.net> : optimization of the match.
12097 +  18-november-2001 Fabrice MARIE <fabrice@netfilter.org> : added [!] 'any' option match.
12098 +  19-february-2004 Harald Welte <laforge@netfilter.org> : merge with 2.6.x
12099 +*/
12100 +
12101 +#include <linux/module.h>
12102 +#include <linux/skbuff.h>
12103 +#include <net/ip.h>
12104 +
12105 +#include <linux/netfilter_ipv4/ip_tables.h>
12106 +#include <linux/netfilter_ipv4/ipt_ipv4options.h>
12107 +
12108 +MODULE_LICENSE("GPL");
12109 +MODULE_AUTHOR("Fabrice Marie <fabrice@netfilter.org>");
12110 +
12111 +static int
12112 +match(const struct sk_buff *skb,
12113 +      const struct net_device *in,
12114 +      const struct net_device *out,
12115 +      const void *matchinfo,
12116 +      int offset,
12117 +      int *hotdrop)
12118 +{
12119 +       const struct ipt_ipv4options_info *info = matchinfo;   /* match info for rule */
12120 +       const struct iphdr *iph = skb->nh.iph;
12121 +       const struct ip_options *opt;
12122 +
12123 +       if (iph->ihl * 4 == sizeof(struct iphdr)) {
12124 +               /* No options, so we match only the "DONTs" and the "IGNOREs" */
12125 +
12126 +               if (((info->options & IPT_IPV4OPTION_MATCH_ANY_OPT) == IPT_IPV4OPTION_MATCH_ANY_OPT) ||
12127 +                   ((info->options & IPT_IPV4OPTION_MATCH_SSRR) == IPT_IPV4OPTION_MATCH_SSRR) ||
12128 +                   ((info->options & IPT_IPV4OPTION_MATCH_LSRR) == IPT_IPV4OPTION_MATCH_LSRR) ||
12129 +                   ((info->options & IPT_IPV4OPTION_MATCH_RR) == IPT_IPV4OPTION_MATCH_RR) ||
12130 +                   ((info->options & IPT_IPV4OPTION_MATCH_TIMESTAMP) == IPT_IPV4OPTION_MATCH_TIMESTAMP) ||
12131 +                    ((info->options & IPT_IPV4OPTION_MATCH_ROUTER_ALERT) == IPT_IPV4OPTION_MATCH_ROUTER_ALERT))
12132 +                       return 0;
12133 +               return 1;
12134 +       }
12135 +       else {
12136 +               if ((info->options & IPT_IPV4OPTION_MATCH_ANY_OPT) == IPT_IPV4OPTION_MATCH_ANY_OPT)
12137 +                       /* there are options, and we don't need to care which one */
12138 +                       return 1;
12139 +               else {
12140 +                       if ((info->options & IPT_IPV4OPTION_DONT_MATCH_ANY_OPT) == IPT_IPV4OPTION_DONT_MATCH_ANY_OPT)
12141 +                               /* there are options but we don't want any ! */
12142 +                               return 0;
12143 +               }
12144 +       }
12145 +
12146 +       opt = &(IPCB(skb)->opt);
12147 +
12148 +       /* source routing */
12149 +       if ((info->options & IPT_IPV4OPTION_MATCH_SSRR) == IPT_IPV4OPTION_MATCH_SSRR) {
12150 +               if (!((opt->srr) & (opt->is_strictroute)))
12151 +                       return 0;
12152 +       }
12153 +       else if ((info->options & IPT_IPV4OPTION_MATCH_LSRR) == IPT_IPV4OPTION_MATCH_LSRR) {
12154 +               if (!((opt->srr) & (!opt->is_strictroute)))
12155 +                       return 0;
12156 +       }
12157 +       else if ((info->options & IPT_IPV4OPTION_DONT_MATCH_SRR) == IPT_IPV4OPTION_DONT_MATCH_SRR) {
12158 +               if (opt->srr)
12159 +                       return 0;
12160 +       }
12161 +       /* record route */
12162 +       if ((info->options & IPT_IPV4OPTION_MATCH_RR) == IPT_IPV4OPTION_MATCH_RR) {
12163 +               if (!opt->rr)
12164 +                       return 0;
12165 +       }
12166 +       else if ((info->options & IPT_IPV4OPTION_DONT_MATCH_RR) == IPT_IPV4OPTION_DONT_MATCH_RR) {
12167 +               if (opt->rr)
12168 +                       return 0;
12169 +       }
12170 +       /* timestamp */
12171 +       if ((info->options & IPT_IPV4OPTION_MATCH_TIMESTAMP) == IPT_IPV4OPTION_MATCH_TIMESTAMP) {
12172 +               if (!opt->ts)
12173 +                       return 0;
12174 +       }
12175 +       else if ((info->options & IPT_IPV4OPTION_DONT_MATCH_TIMESTAMP) == IPT_IPV4OPTION_DONT_MATCH_TIMESTAMP) {
12176 +               if (opt->ts)
12177 +                       return 0;
12178 +       }
12179 +       /* router-alert option  */
12180 +       if ((info->options & IPT_IPV4OPTION_MATCH_ROUTER_ALERT) == IPT_IPV4OPTION_MATCH_ROUTER_ALERT) {
12181 +               if (!opt->router_alert)
12182 +                       return 0;
12183 +       }
12184 +       else if ((info->options & IPT_IPV4OPTION_DONT_MATCH_ROUTER_ALERT) == IPT_IPV4OPTION_DONT_MATCH_ROUTER_ALERT) {
12185 +               if (opt->router_alert)
12186 +                       return 0;
12187 +       }
12188 +
12189 +       /* we match ! */
12190 +       return 1;
12191 +}
12192 +
12193 +static int
12194 +checkentry(const char *tablename,
12195 +          const struct ipt_ip *ip,
12196 +          void *matchinfo,
12197 +          unsigned int matchsize,
12198 +          unsigned int hook_mask)
12199 +{
12200 +       const struct ipt_ipv4options_info *info = matchinfo;   /* match info for rule */
12201 +       /* Check the size */
12202 +       if (matchsize != IPT_ALIGN(sizeof(struct ipt_ipv4options_info)))
12203 +               return 0;
12204 +       /* Now check the coherence of the data ... */
12205 +       if (((info->options & IPT_IPV4OPTION_MATCH_ANY_OPT) == IPT_IPV4OPTION_MATCH_ANY_OPT) &&
12206 +           (((info->options & IPT_IPV4OPTION_DONT_MATCH_SRR) == IPT_IPV4OPTION_DONT_MATCH_SRR) ||
12207 +            ((info->options & IPT_IPV4OPTION_DONT_MATCH_RR) == IPT_IPV4OPTION_DONT_MATCH_RR) ||
12208 +            ((info->options & IPT_IPV4OPTION_DONT_MATCH_TIMESTAMP) == IPT_IPV4OPTION_DONT_MATCH_TIMESTAMP) ||
12209 +            ((info->options & IPT_IPV4OPTION_DONT_MATCH_ROUTER_ALERT) == IPT_IPV4OPTION_DONT_MATCH_ROUTER_ALERT) ||
12210 +            ((info->options & IPT_IPV4OPTION_DONT_MATCH_ANY_OPT) == IPT_IPV4OPTION_DONT_MATCH_ANY_OPT)))
12211 +               return 0; /* opposites */
12212 +       if (((info->options & IPT_IPV4OPTION_DONT_MATCH_ANY_OPT) == IPT_IPV4OPTION_DONT_MATCH_ANY_OPT) &&
12213 +           (((info->options & IPT_IPV4OPTION_MATCH_LSRR) == IPT_IPV4OPTION_MATCH_LSRR) ||
12214 +            ((info->options & IPT_IPV4OPTION_MATCH_SSRR) == IPT_IPV4OPTION_MATCH_SSRR) ||
12215 +            ((info->options & IPT_IPV4OPTION_MATCH_RR) == IPT_IPV4OPTION_MATCH_RR) ||
12216 +            ((info->options & IPT_IPV4OPTION_MATCH_TIMESTAMP) == IPT_IPV4OPTION_MATCH_TIMESTAMP) ||
12217 +            ((info->options & IPT_IPV4OPTION_MATCH_ROUTER_ALERT) == IPT_IPV4OPTION_MATCH_ROUTER_ALERT) ||
12218 +            ((info->options & IPT_IPV4OPTION_MATCH_ANY_OPT) == IPT_IPV4OPTION_MATCH_ANY_OPT)))
12219 +               return 0; /* opposites */
12220 +       if (((info->options & IPT_IPV4OPTION_MATCH_SSRR) == IPT_IPV4OPTION_MATCH_SSRR) &&
12221 +           ((info->options & IPT_IPV4OPTION_MATCH_LSRR) == IPT_IPV4OPTION_MATCH_LSRR))
12222 +               return 0; /* cannot match in the same time loose and strict source routing */
12223 +       if ((((info->options & IPT_IPV4OPTION_MATCH_SSRR) == IPT_IPV4OPTION_MATCH_SSRR) ||
12224 +            ((info->options & IPT_IPV4OPTION_MATCH_LSRR) == IPT_IPV4OPTION_MATCH_LSRR)) &&
12225 +           ((info->options & IPT_IPV4OPTION_DONT_MATCH_SRR) == IPT_IPV4OPTION_DONT_MATCH_SRR))
12226 +               return 0; /* opposites */
12227 +       if (((info->options & IPT_IPV4OPTION_MATCH_RR) == IPT_IPV4OPTION_MATCH_RR) &&
12228 +           ((info->options & IPT_IPV4OPTION_DONT_MATCH_RR) == IPT_IPV4OPTION_DONT_MATCH_RR))
12229 +               return 0; /* opposites */
12230 +       if (((info->options & IPT_IPV4OPTION_MATCH_TIMESTAMP) == IPT_IPV4OPTION_MATCH_TIMESTAMP) &&
12231 +           ((info->options & IPT_IPV4OPTION_DONT_MATCH_TIMESTAMP) == IPT_IPV4OPTION_DONT_MATCH_TIMESTAMP))
12232 +               return 0; /* opposites */
12233 +       if (((info->options & IPT_IPV4OPTION_MATCH_ROUTER_ALERT) == IPT_IPV4OPTION_MATCH_ROUTER_ALERT) &&
12234 +           ((info->options & IPT_IPV4OPTION_DONT_MATCH_ROUTER_ALERT) == IPT_IPV4OPTION_DONT_MATCH_ROUTER_ALERT))
12235 +               return 0; /* opposites */
12236 +
12237 +       /* everything looks ok. */
12238 +       return 1;
12239 +}
12240 +
12241 +static struct ipt_match ipv4options_match = { 
12242 +       .name = "ipv4options",
12243 +       .match = match,
12244 +       .checkentry = checkentry,
12245 +       .me = THIS_MODULE
12246 +};
12247 +
12248 +static int __init init(void)
12249 +{
12250 +       return ipt_register_match(&ipv4options_match);
12251 +}
12252 +
12253 +static void __exit fini(void)
12254 +{
12255 +       ipt_unregister_match(&ipv4options_match);
12256 +}
12257 +
12258 +module_init(init);
12259 +module_exit(fini);
12260 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_mport.c linux-2.6.7-rc3/net/ipv4/netfilter/ipt_mport.c
12261 --- linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_mport.c  1970-01-01 01:00:00.000000000 +0100
12262 +++ linux-2.6.7-rc3/net/ipv4/netfilter/ipt_mport.c      2004-06-08 10:31:40.000000000 +0200
12263 @@ -0,0 +1,116 @@
12264 +/* Kernel module to match one of a list of TCP/UDP ports: ports are in
12265 +   the same place so we can treat them as equal. */
12266 +#include <linux/module.h>
12267 +#include <linux/types.h>
12268 +#include <linux/udp.h>
12269 +#include <linux/skbuff.h>
12270 +
12271 +#include <linux/netfilter_ipv4/ipt_mport.h>
12272 +#include <linux/netfilter_ipv4/ip_tables.h>
12273 +
12274 +MODULE_LICENSE("GPL");
12275 +
12276 +#if 0
12277 +#define duprintf(format, args...) printk(format , ## args)
12278 +#else
12279 +#define duprintf(format, args...)
12280 +#endif
12281 +
12282 +/* Returns 1 if the port is matched by the test, 0 otherwise. */
12283 +static inline int
12284 +ports_match(const struct ipt_mport *minfo, u_int16_t src, u_int16_t dst)
12285 +{
12286 +       unsigned int i;
12287 +        unsigned int m;
12288 +        u_int16_t pflags = minfo->pflags;
12289 +       for (i=0, m=1; i<IPT_MULTI_PORTS; i++, m<<=1) {
12290 +                u_int16_t s, e;
12291 +
12292 +                if (pflags & m
12293 +                    && minfo->ports[i] == 65535)
12294 +                        return 0;
12295 +
12296 +                s = minfo->ports[i];
12297 +
12298 +                if (pflags & m) {
12299 +                        e = minfo->ports[++i];
12300 +                        m <<= 1;
12301 +                } else
12302 +                        e = s;
12303 +
12304 +                if (minfo->flags & IPT_MPORT_SOURCE
12305 +                    && src >= s && src <= e)
12306 +                        return 1;
12307 +
12308 +               if (minfo->flags & IPT_MPORT_DESTINATION
12309 +                   && dst >= s && dst <= e)
12310 +                       return 1;
12311 +       }
12312 +
12313 +       return 0;
12314 +}
12315 +
12316 +static int
12317 +match(const struct sk_buff *skb,
12318 +      const struct net_device *in,
12319 +      const struct net_device *out,
12320 +      const void *matchinfo,
12321 +      int offset,
12322 +      int *hotdrop)
12323 +{
12324 +       u16 ports[2];
12325 +       const struct ipt_mport *minfo = matchinfo;
12326 +
12327 +       if (offset)
12328 +               return 0;
12329 +
12330 +       /* Must be big enough to read ports (both UDP and TCP have
12331 +           them at the start). */
12332 +       if (skb_copy_bits(skb, skb->nh.iph->ihl*4, ports, sizeof(ports)) < 0) {
12333 +               /* We've been asked to examine this packet, and we
12334 +                  can't.  Hence, no choice but to drop. */
12335 +                       duprintf("ipt_multiport:"
12336 +                                " Dropping evil offset=0 tinygram.\n");
12337 +                       *hotdrop = 1;
12338 +                       return 0;
12339 +       }
12340 +
12341 +       return ports_match(minfo, ntohs(ports[0]), ntohs(ports[1]));
12342 +}
12343 +
12344 +/* Called when user tries to insert an entry of this type. */
12345 +static int
12346 +checkentry(const char *tablename,
12347 +          const struct ipt_ip *ip,
12348 +          void *matchinfo,
12349 +          unsigned int matchsize,
12350 +          unsigned int hook_mask)
12351 +{
12352 +       if (matchsize != IPT_ALIGN(sizeof(struct ipt_mport)))
12353 +               return 0;
12354 +
12355 +       /* Must specify proto == TCP/UDP, no unknown flags or bad count */
12356 +       return (ip->proto == IPPROTO_TCP || ip->proto == IPPROTO_UDP)
12357 +               && !(ip->invflags & IPT_INV_PROTO)
12358 +               && matchsize == IPT_ALIGN(sizeof(struct ipt_mport));
12359 +}
12360 +
12361 +static struct ipt_match mport_match = { 
12362 +       .name = "mport",
12363 +       .match = &match,
12364 +       .checkentry = &checkentry,
12365 +       .me = THIS_MODULE
12366 +};
12367 +
12368 +static int __init init(void)
12369 +{
12370 +       return ipt_register_match(&mport_match);
12371 +}
12372 +
12373 +static void __exit fini(void)
12374 +{
12375 +       ipt_unregister_match(&mport_match);
12376 +}
12377 +
12378 +module_init(init);
12379 +module_exit(fini);
12380 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_nth.c linux-2.6.7-rc3/net/ipv4/netfilter/ipt_nth.c
12381 --- linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_nth.c    1970-01-01 01:00:00.000000000 +0100
12382 +++ linux-2.6.7-rc3/net/ipv4/netfilter/ipt_nth.c        2004-06-08 10:31:42.000000000 +0200
12383 @@ -0,0 +1,166 @@
12384 +/*
12385 +  This is a module which is used for match support for every Nth packet
12386 +  This file is distributed under the terms of the GNU General Public
12387 +  License (GPL). Copies of the GPL can be obtained from:
12388 +     ftp://prep.ai.mit.edu/pub/gnu/GPL
12389 +
12390 +  2001-07-18 Fabrice MARIE <fabrice@netfilter.org> : initial implementation.
12391 +  2001-09-20 Richard Wagner (rwagner@cloudnet.com)
12392 +        * added support for multiple counters
12393 +        * added support for matching on individual packets
12394 +          in the counter cycle
12395 +  2004-02-19 Harald Welte <laforge@netfilter.org>
12396 +       * port to 2.6.x
12397 +
12398 +*/
12399 +
12400 +#include <linux/module.h>
12401 +#include <linux/skbuff.h>
12402 +#include <linux/ip.h>
12403 +#include <net/tcp.h>
12404 +#include <linux/spinlock.h>
12405 +#include <linux/netfilter_ipv4/ip_tables.h>
12406 +#include <linux/netfilter_ipv4/ipt_nth.h>
12407 +
12408 +MODULE_LICENSE("GPL");
12409 +MODULE_AUTHOR("Fabrice Marie <fabrice@netfilter.org>");
12410 +
12411 +/*
12412 + * State information.
12413 + */
12414 +struct state {
12415 +       spinlock_t lock;
12416 +       u_int16_t number;
12417 +};
12418 +
12419 +static struct state states[IPT_NTH_NUM_COUNTERS];
12420 +
12421 +static int
12422 +ipt_nth_match(const struct sk_buff *pskb,
12423 +             const struct net_device *in,
12424 +             const struct net_device *out,
12425 +             const void *matchinfo,
12426 +             int offset,
12427 +             int *hotdrop)
12428 +{
12429 +       /* Parameters from userspace */
12430 +       const struct ipt_nth_info *info = matchinfo;
12431 +        unsigned counter = info->counter;
12432 +               if((counter < 0) || (counter >= IPT_NTH_NUM_COUNTERS)) 
12433 +       {
12434 +                       printk(KERN_WARNING "nth: invalid counter %u. counter between 0 and %u\n", counter, IPT_NTH_NUM_COUNTERS-1);
12435 +               return 0;
12436 +        };
12437 +
12438 +        spin_lock(&states[counter].lock);
12439 +
12440 +        /* Are we matching every nth packet?*/
12441 +        if (info->packet == 0xFF)
12442 +        {
12443 +               /* We're matching every nth packet and only every nth packet*/
12444 +               /* Do we match or invert match? */
12445 +               if (info->not == 0)
12446 +               {
12447 +                       if (states[counter].number == 0)
12448 +                       {
12449 +                               ++states[counter].number;
12450 +                               goto match;
12451 +                       }
12452 +                       if (states[counter].number >= info->every)
12453 +                               states[counter].number = 0; /* reset the counter */
12454 +                       else
12455 +                               ++states[counter].number;
12456 +                       goto dontmatch;
12457 +               }
12458 +               else
12459 +               {
12460 +                       if (states[counter].number == 0)
12461 +                       {
12462 +                               ++states[counter].number;
12463 +                               goto dontmatch;
12464 +                       }
12465 +                       if (states[counter].number >= info->every)
12466 +                               states[counter].number = 0;
12467 +                       else
12468 +                               ++states[counter].number;
12469 +                       goto match;
12470 +               }
12471 +        }
12472 +        else
12473 +        {
12474 +               /* We're using the --packet, so there must be a rule for every value */
12475 +               if (states[counter].number == info->packet)
12476 +               {
12477 +                       /* only increment the counter when a match happens */
12478 +                       if (states[counter].number >= info->every)
12479 +                               states[counter].number = 0; /* reset the counter */
12480 +                       else
12481 +                               ++states[counter].number;
12482 +                       goto match;
12483 +               }
12484 +               else
12485 +                       goto dontmatch;
12486 +       }
12487 +
12488 + dontmatch:
12489 +       /* don't match */
12490 +       spin_unlock(&states[counter].lock);
12491 +       return 0;
12492 +
12493 + match:
12494 +       spin_unlock(&states[counter].lock);
12495 +       return 1;
12496 +}
12497 +
12498 +static int
12499 +ipt_nth_checkentry(const char *tablename,
12500 +                  const struct ipt_ip *e,
12501 +                  void *matchinfo,
12502 +                  unsigned int matchsize,
12503 +                  unsigned int hook_mask)
12504 +{
12505 +       /* Parameters from userspace */
12506 +       const struct ipt_nth_info *info = matchinfo;
12507 +        unsigned counter = info->counter;
12508 +        if((counter < 0) || (counter >= IPT_NTH_NUM_COUNTERS)) 
12509 +       {
12510 +               printk(KERN_WARNING "nth: invalid counter %u. counter between 0 and %u\n", counter, IPT_NTH_NUM_COUNTERS-1);
12511 +                       return 0;
12512 +               };
12513 +
12514 +       if (matchsize != IPT_ALIGN(sizeof(struct ipt_nth_info))) {
12515 +               printk("nth: matchsize %u != %u\n", matchsize,
12516 +                      IPT_ALIGN(sizeof(struct ipt_nth_info)));
12517 +               return 0;
12518 +       }
12519 +
12520 +       states[counter].number = info->startat;
12521 +
12522 +       return 1;
12523 +}
12524 +
12525 +static struct ipt_match ipt_nth_reg = { 
12526 +       .name = "nth",
12527 +       .match = ipt_nth_match,
12528 +       .checkentry = ipt_nth_checkentry,
12529 +       .me = THIS_MODULE
12530 +};
12531 +
12532 +static int __init init(void)
12533 +{
12534 +       unsigned counter;
12535 +
12536 +       memset(&states, 0, sizeof(states));
12537 +        for (counter = 0; counter < IPT_NTH_NUM_COUNTERS; counter++) 
12538 +               spin_lock_init(&(states[counter].lock));
12539 +
12540 +       return ipt_register_match(&ipt_nth_reg);
12541 +}
12542 +
12543 +static void __exit fini(void)
12544 +{
12545 +       ipt_unregister_match(&ipt_nth_reg);
12546 +}
12547 +
12548 +module_init(init);
12549 +module_exit(fini);
12550 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_osf.c linux-2.6.7-rc3/net/ipv4/netfilter/ipt_osf.c
12551 --- linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_osf.c    1970-01-01 01:00:00.000000000 +0100
12552 +++ linux-2.6.7-rc3/net/ipv4/netfilter/ipt_osf.c        2004-06-08 10:31:44.000000000 +0200
12553 @@ -0,0 +1,865 @@
12554 +/*
12555 + * ipt_osf.c
12556 + *
12557 + * Copyright (c) 2003 Evgeniy Polyakov <johnpol@2ka.mipt.ru>
12558 + *
12559 + *
12560 + * This program is free software; you can redistribute it and/or modify
12561 + * it under the terms of the GNU General Public License as published by
12562 + * the Free Software Foundation; either version 2 of the License, or
12563 + * (at your option) any later version.
12564 + *
12565 + * This program is distributed in the hope that it will be useful,
12566 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12567 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12568 + * GNU General Public License for more details.
12569 + *
12570 + * You should have received a copy of the GNU General Public License
12571 + * along with this program; if not, write to the Free Software
12572 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
12573 + */
12574 +
12575 +/*
12576 + * OS fingerprint matching module.
12577 + * It simply compares various parameters from SYN packet with
12578 + * some hardcoded ones.
12579 + *
12580 + * Original table was created by Michal Zalewski <lcamtuf@coredump.cx>
12581 + * for his p0f.
12582 + */
12583 +
12584 +#include <linux/config.h>
12585 +#include <linux/kernel.h>
12586 +#include <linux/types.h>
12587 +#include <linux/string.h>
12588 +#include <linux/smp.h>
12589 +#include <linux/module.h>
12590 +#include <linux/skbuff.h>
12591 +#include <linux/file.h>
12592 +#include <linux/ip.h>
12593 +#include <linux/proc_fs.h>
12594 +#include <linux/fs.h>
12595 +#include <linux/slab.h>
12596 +#include <linux/spinlock.h>
12597 +#include <linux/ctype.h>
12598 +#include <linux/list.h>
12599 +#include <linux/if.h>
12600 +
12601 +#include <net/sock.h>
12602 +#include <net/ip.h>
12603 +
12604 +#include <linux/netfilter_ipv4/ip_tables.h>
12605 +
12606 +#include <linux/netfilter_ipv4/ipt_osf.h>
12607 +
12608 +#define OSF_DEBUG
12609 +
12610 +#ifdef OSF_DEBUG
12611 +#define log(x...)              printk(KERN_INFO "ipt_osf: " x)
12612 +#define loga(x...)             printk(x)
12613 +#else
12614 +#define log(x...)              do {} while(0)
12615 +#define loga(x...)             do {} while(0)
12616 +#endif
12617 +
12618 +#define FMATCH_WRONG           0
12619 +#define FMATCH_OK              1
12620 +#define FMATCH_OPT_WRONG       2
12621 +
12622 +#define OPTDEL                 ','
12623 +#define OSFPDEL                ':'
12624 +#define MAXOPTSTRLEN           128
12625 +#define OSFFLUSH               "FLUSH"
12626 +
12627 +static rwlock_t osf_lock = RW_LOCK_UNLOCKED;
12628 +static spinlock_t ipt_osf_netlink_lock = SPIN_LOCK_UNLOCKED;
12629 +static struct list_head        finger_list;    
12630 +static int match(const struct sk_buff *, const struct net_device *, const struct net_device *,
12631 +                     const void *, int, 
12632 +                     const void *, u_int16_t, 
12633 +                     int *);
12634 +static int checkentry(const char *, const struct ipt_ip *, void *,
12635 +                          unsigned int, unsigned int);
12636 +
12637 +static unsigned long seq, ipt_osf_groups = 1;
12638 +static struct sock *nts;
12639 +
12640 +static struct ipt_match osf_match = 
12641 +{ 
12642 +       { NULL, NULL }, 
12643 +       "osf", 
12644 +       &match, 
12645 +       &checkentry, 
12646 +       NULL, 
12647 +       THIS_MODULE 
12648 +};
12649 +
12650 +static void ipt_osf_nlsend(struct osf_finger *f, const struct sk_buff *sk)
12651 +{
12652 +       unsigned int size;
12653 +       struct sk_buff *skb;
12654 +       struct ipt_osf_nlmsg *data;
12655 +       struct nlmsghdr *nlh;
12656 +
12657 +       size = NLMSG_SPACE(sizeof(struct ipt_osf_nlmsg));
12658 +
12659 +       skb = alloc_skb(size, GFP_ATOMIC);
12660 +       if (!skb)
12661 +       {
12662 +               log("skb_alloc() failed.\n");
12663 +               return;
12664 +       }
12665 +       
12666 +       nlh = NLMSG_PUT(skb, 0, seq++, NLMSG_DONE, size - sizeof(*nlh));
12667 +       
12668 +       data = (struct ipt_osf_nlmsg *)NLMSG_DATA(nlh);
12669 +
12670 +       memcpy(&data->f, f, sizeof(struct osf_finger));
12671 +       memcpy(&data->ip, sk->nh.iph, sizeof(struct iphdr));
12672 +       memcpy(&data->tcp, (struct tcphdr *)((u_int32_t *)sk->nh.iph + sk->nh.iph->ihl), sizeof(struct tcphdr));
12673 +
12674 +       NETLINK_CB(skb).dst_groups = ipt_osf_groups;
12675 +       netlink_broadcast(nts, skb, 0, ipt_osf_groups, GFP_ATOMIC);
12676 +
12677 +nlmsg_failure:
12678 +       return;
12679 +}
12680 +
12681 +static inline int smart_dec(const struct sk_buff *skb, unsigned long flags, unsigned char f_ttl)
12682 +{
12683 +       struct iphdr *ip = skb->nh.iph;
12684 +
12685 +       if (flags & IPT_OSF_SMART)
12686 +       {
12687 +               struct in_device *in_dev = in_dev_get(skb->dev);
12688 +
12689 +               for_ifa(in_dev)
12690 +               {
12691 +                       if (inet_ifa_match(ip->saddr, ifa))
12692 +                       {
12693 +                               in_dev_put(in_dev);
12694 +                               return (ip->ttl == f_ttl);
12695 +                       }
12696 +               }
12697 +               endfor_ifa(in_dev);
12698 +               
12699 +               in_dev_put(in_dev);
12700 +               return (ip->ttl <= f_ttl);
12701 +       }
12702 +       else
12703 +               return (ip->ttl == f_ttl);
12704 +}
12705 +
12706 +static int
12707 +match(const struct sk_buff *skb, const struct net_device *in, const struct net_device *out,
12708 +      const void *matchinfo, int offset,
12709 +      const void *hdr, u_int16_t datalen,
12710 +      int *hotdrop)
12711 +{
12712 +       struct ipt_osf_info *info = (struct ipt_osf_info *)matchinfo;
12713 +       struct iphdr *ip = skb->nh.iph;
12714 +       struct tcphdr *tcp;
12715 +       int fmatch = FMATCH_WRONG, fcount = 0;
12716 +       unsigned long totlen, optsize = 0, window;
12717 +       unsigned char df, *optp = NULL, *_optp = NULL;
12718 +       char check_WSS = 0;
12719 +       struct list_head *ent;
12720 +       struct osf_finger *f;
12721 +
12722 +       if (!ip || !info)
12723 +               return 0;
12724 +                               
12725 +       tcp = (struct tcphdr *)((u_int32_t *)ip + ip->ihl);
12726 +
12727 +       if (!tcp->syn)
12728 +               return 0;
12729 +       
12730 +       totlen = ntohs(ip->tot_len);
12731 +       df = ((ntohs(ip->frag_off) & IP_DF)?1:0);
12732 +       window = ntohs(tcp->window);
12733 +       
12734 +       if (tcp->doff*4 > sizeof(struct tcphdr))
12735 +       {
12736 +               _optp = optp = (char *)(tcp+1);
12737 +               optsize = tcp->doff*4 - sizeof(struct tcphdr);
12738 +       }
12739 +
12740 +       
12741 +       /* Actually we can create hash/table of all genres and search
12742 +        * only in appropriate part, but here is initial variant,
12743 +        * so will use slow path.
12744 +        */
12745 +       read_lock(&osf_lock);
12746 +       list_for_each(ent, &finger_list)
12747 +       {
12748 +               f = list_entry(ent, struct osf_finger, flist);
12749 +       
12750 +               if (!(info->flags & IPT_OSF_LOG) && strcmp(info->genre, f->genre)) 
12751 +                       continue;
12752 +
12753 +               optp = _optp;
12754 +               fmatch = FMATCH_WRONG;
12755 +
12756 +               if (totlen == f->ss && df == f->df && 
12757 +                       smart_dec(skb, info->flags, f->ttl))
12758 +               {
12759 +                       unsigned long foptsize;
12760 +                       int optnum;
12761 +                       unsigned short mss = 0;
12762 +
12763 +                       check_WSS = 0;
12764 +
12765 +                       switch (f->wss.wc)
12766 +                       {
12767 +                               case 0:   check_WSS = 0; break;
12768 +                               case 'S': check_WSS = 1; break;
12769 +                               case 'T': check_WSS = 2; break;
12770 +                               case '%': check_WSS = 3; break;
12771 +                               default: log("Wrong fingerprint wss.wc=%d, %s - %s\n", 
12772 +                                                        f->wss.wc, f->genre, f->details);
12773 +                                        check_WSS = 4;
12774 +                                        break;
12775 +                       }
12776 +                       if (check_WSS == 4)
12777 +                               continue;
12778 +
12779 +                       /* Check options */
12780 +
12781 +                       foptsize = 0;
12782 +                       for (optnum=0; optnum<f->opt_num; ++optnum)
12783 +                               foptsize += f->opt[optnum].length;
12784 +
12785 +                               
12786 +                       if (foptsize > MAX_IPOPTLEN || optsize > MAX_IPOPTLEN || optsize != foptsize)
12787 +                               continue;
12788 +
12789 +                       if (!optp)
12790 +                       {
12791 +                               fmatch = FMATCH_OK;
12792 +                               loga("\tYEP : matching without options.\n");
12793 +                               if ((info->flags & IPT_OSF_LOG) && 
12794 +                                       info->loglevel == IPT_OSF_LOGLEVEL_FIRST)
12795 +                                       break;
12796 +                               else
12797 +                                       continue;
12798 +                       }
12799 +                       
12800 +
12801 +                       for (optnum=0; optnum<f->opt_num; ++optnum)
12802 +                       {
12803 +                               if (f->opt[optnum].kind == (*optp)) 
12804 +                               {
12805 +                                       unsigned char len = f->opt[optnum].length;
12806 +                                       unsigned char *optend = optp + len;
12807 +                                       int loop_cont = 0;
12808 +
12809 +                                       fmatch = FMATCH_OK;
12810 +
12811 +
12812 +                                       switch (*optp)
12813 +                                       {
12814 +                                               case OSFOPT_MSS:
12815 +                                                       mss = ntohs(*(unsigned short *)(optp+2));
12816 +                                                       break;
12817 +                                               case OSFOPT_TS:
12818 +                                                       loop_cont = 1;
12819 +                                                       break;
12820 +                                       }
12821 +                                       
12822 +                                       if (loop_cont)
12823 +                                       {
12824 +                                               optp = optend;
12825 +                                               continue;
12826 +                                       }
12827 +                                       
12828 +                                       if (len != 1)
12829 +                                       {
12830 +                                               /* Skip kind and length fields*/
12831 +                                               optp += 2; 
12832 +
12833 +                                               if (f->opt[optnum].wc.val != 0)
12834 +                                               {
12835 +                                                       unsigned long tmp = 0;
12836 +                                                       
12837 +                                                       /* Hmmm... It looks a bit ugly. :) */
12838 +                                                       memcpy(&tmp, optp, 
12839 +                                                               (len > sizeof(unsigned long)?
12840 +                                                                       sizeof(unsigned long):len));
12841 +                                                       /* 2 + 2: optlen(2 bytes) + 
12842 +                                                        *      kind(1 byte) + length(1 byte) */
12843 +                                                       if (len == 4) 
12844 +                                                               tmp = ntohs(tmp);
12845 +                                                       else
12846 +                                                               tmp = ntohl(tmp);
12847 +
12848 +                                                       if (f->opt[optnum].wc.wc == '%')
12849 +                                                       {
12850 +                                                               if ((tmp % f->opt[optnum].wc.val) != 0)
12851 +                                                                       fmatch = FMATCH_OPT_WRONG;
12852 +                                                       }
12853 +                                                       else if (tmp != f->opt[optnum].wc.val)
12854 +                                                               fmatch = FMATCH_OPT_WRONG;
12855 +                                               }
12856 +                                       }
12857 +
12858 +                                       optp = optend;
12859 +                               }
12860 +                               else
12861 +                                       fmatch = FMATCH_OPT_WRONG;
12862 +
12863 +                               if (fmatch != FMATCH_OK)
12864 +                                       break;
12865 +                       }
12866 +
12867 +                       if (fmatch != FMATCH_OPT_WRONG)
12868 +                       {
12869 +                               fmatch = FMATCH_WRONG;
12870 +
12871 +                               switch (check_WSS)
12872 +                               {
12873 +                                       case 0:
12874 +                                               if (f->wss.val == 0 || window == f->wss.val)
12875 +                                                       fmatch = FMATCH_OK;
12876 +                                               break;
12877 +                                       case 1: /* MSS */
12878 +/* Lurked in OpenBSD */
12879 +#define SMART_MSS      1460
12880 +                                               if (window == f->wss.val*mss || 
12881 +                                                       window == f->wss.val*SMART_MSS)
12882 +                                                       fmatch = FMATCH_OK;
12883 +                                               break;
12884 +                                       case 2: /* MTU */
12885 +                                               if (window == f->wss.val*(mss+40) ||
12886 +                                                       window == f->wss.val*(SMART_MSS+40))
12887 +                                                       fmatch = FMATCH_OK;
12888 +                                               break;
12889 +                                       case 3: /* MOD */
12890 +                                               if ((window % f->wss.val) == 0)
12891 +                                                       fmatch = FMATCH_OK;
12892 +                                               break;
12893 +                               }
12894 +                       }
12895 +                                       
12896 +
12897 +                       if (fmatch == FMATCH_OK)
12898 +                       {
12899 +                               fcount++;
12900 +                               log("%s [%s:%s:%s] : %u.%u.%u.%u:%u -> %u.%u.%u.%u:%u hops=%d\n", 
12901 +                                       f->genre, f->version,
12902 +                                       f->subtype, f->details,
12903 +                                       NIPQUAD(ip->saddr), ntohs(tcp->source),
12904 +                                       NIPQUAD(ip->daddr), ntohs(tcp->dest),
12905 +                                       f->ttl - ip->ttl);
12906 +                               if (info->flags & IPT_OSF_NETLINK)
12907 +                               {
12908 +                                       spin_lock_bh(&ipt_osf_netlink_lock);
12909 +                                       ipt_osf_nlsend(f, skb);
12910 +                                       spin_unlock_bh(&ipt_osf_netlink_lock);
12911 +                               }
12912 +                               if ((info->flags & IPT_OSF_LOG) && 
12913 +                                       info->loglevel == IPT_OSF_LOGLEVEL_FIRST)
12914 +                                       break;
12915 +                       }
12916 +               }
12917 +       }
12918 +       if (!fcount && (info->flags & (IPT_OSF_LOG | IPT_OSF_NETLINK)))
12919 +       {
12920 +               unsigned char opt[4 * 15 - sizeof(struct tcphdr)];
12921 +               unsigned int i, optsize;
12922 +               struct osf_finger fg;
12923 +
12924 +               memset(&fg, 0, sizeof(fg));
12925 +
12926 +               if ((info->flags & IPT_OSF_LOG))
12927 +                       log("Unknown: %lu:%d:%d:%lu:", window, ip->ttl, df, totlen);
12928 +               if (optp)
12929 +               {
12930 +                       optsize = tcp->doff * 4 - sizeof(struct tcphdr);
12931 +                       if (skb_copy_bits(skb, ip->ihl*4 + sizeof(struct tcphdr),
12932 +                                         opt, optsize) < 0)
12933 +                       {
12934 +                               if (info->flags & IPT_OSF_LOG)
12935 +                                       loga("TRUNCATED");
12936 +                               if (info->flags & IPT_OSF_NETLINK)
12937 +                                       strcpy(fg.details, "TRUNCATED");
12938 +                       }
12939 +                       else
12940 +                       {
12941 +                               for (i = 0; i < optsize; i++)
12942 +                               {
12943 +                                       if (info->flags & IPT_OSF_LOG)
12944 +                                               loga("%02X", opt[i]);
12945 +                               }
12946 +                               if (info->flags & IPT_OSF_NETLINK)
12947 +                                       memcpy(fg.details, opt, MAXDETLEN);
12948 +                       }
12949 +               }
12950 +               if ((info->flags & IPT_OSF_LOG))
12951 +                       loga(" %u.%u.%u.%u:%u -> %u.%u.%u.%u:%u\n", 
12952 +                               NIPQUAD(ip->saddr), ntohs(tcp->source),
12953 +                               NIPQUAD(ip->daddr), ntohs(tcp->dest));
12954 +               
12955 +               if (info->flags & IPT_OSF_NETLINK)
12956 +               {
12957 +                       fg.wss.val      = window;
12958 +                       fg.ttl          = ip->ttl;
12959 +                       fg.df           = df;
12960 +                       fg.ss           = totlen;
12961 +                       strncpy(fg.genre, "Unknown", MAXGENRELEN);
12962 +
12963 +                       spin_lock_bh(&ipt_osf_netlink_lock);
12964 +                       ipt_osf_nlsend(&fg, skb);
12965 +                       spin_unlock_bh(&ipt_osf_netlink_lock);
12966 +               }
12967 +       }
12968 +
12969 +       read_unlock(&osf_lock);
12970 +
12971 +       return (fmatch == FMATCH_OK)?1:0;
12972 +}
12973 +
12974 +static int
12975 +checkentry(const char *tablename,
12976 +           const struct ipt_ip *ip,
12977 +           void *matchinfo,
12978 +           unsigned int matchsize,
12979 +           unsigned int hook_mask)
12980 +{
12981 +       if (matchsize != IPT_ALIGN(sizeof(struct ipt_osf_info)))
12982 +               return 0;
12983 +       if (ip->proto != IPPROTO_TCP)
12984 +              return 0;
12985 +
12986 +       return 1;
12987 +}
12988 +
12989 +static char * osf_strchr(char *ptr, char c)
12990 +{
12991 +       char *tmp;
12992 +
12993 +       tmp = strchr(ptr, c);
12994 +
12995 +       while (tmp && tmp+1 && isspace(*(tmp+1)))
12996 +               tmp++;
12997 +
12998 +       return tmp;
12999 +}
13000 +
13001 +static struct osf_finger * finger_alloc(void)
13002 +{
13003 +       struct osf_finger *f;
13004 +
13005 +       f = kmalloc(sizeof(struct osf_finger), GFP_KERNEL);
13006 +       if (f)
13007 +               memset(f, 0, sizeof(struct osf_finger));
13008 +       
13009 +       return f;
13010 +}
13011 +
13012 +static void finger_free(struct osf_finger *f)
13013 +{
13014 +       memset(f, 0, sizeof(struct osf_finger));
13015 +       kfree(f);
13016 +}
13017 +
13018 +
13019 +static void osf_parse_opt(struct osf_opt *opt, int *optnum, char *obuf, int olen)
13020 +{
13021 +       int i, op;
13022 +       char *ptr, wc;
13023 +       unsigned long val;
13024 +
13025 +       ptr = &obuf[0];
13026 +       i = 0;
13027 +       while (ptr != NULL && i < olen)
13028 +       {
13029 +               val = 0;
13030 +               op = 0;
13031 +               wc = 0;
13032 +               switch (obuf[i])
13033 +               {
13034 +                       case 'N': 
13035 +                               op = OSFOPT_NOP;
13036 +                               ptr = osf_strchr(&obuf[i], OPTDEL);
13037 +                               if (ptr)
13038 +                               {
13039 +                                       *ptr = '\0';
13040 +                                       ptr++;
13041 +                                       i += (int)(ptr-&obuf[i]);
13042 +
13043 +                               }
13044 +                               else
13045 +                                       i++;
13046 +                               break;
13047 +                       case 'S': 
13048 +                               op = OSFOPT_SACKP;
13049 +                               ptr = osf_strchr(&obuf[i], OPTDEL);
13050 +                               if (ptr)
13051 +                               {
13052 +                                       *ptr = '\0';
13053 +                                       ptr++;
13054 +                                       i += (int)(ptr-&obuf[i]);
13055 +
13056 +                               }
13057 +                               else
13058 +                                       i++;
13059 +                               break;
13060 +                       case 'T': 
13061 +                               op = OSFOPT_TS;
13062 +                               ptr = osf_strchr(&obuf[i], OPTDEL);
13063 +                               if (ptr)
13064 +                               {
13065 +                                       *ptr = '\0';
13066 +                                       ptr++;
13067 +                                       i += (int)(ptr-&obuf[i]);
13068 +
13069 +                               }
13070 +                               else
13071 +                                       i++;
13072 +                               break;
13073 +                       case 'W': 
13074 +                               op = OSFOPT_WSO;
13075 +                               ptr = osf_strchr(&obuf[i], OPTDEL);
13076 +                               if (ptr)
13077 +                               {
13078 +                                       switch (obuf[i+1])
13079 +                                       {
13080 +                                               case '%':       wc = '%'; break;
13081 +                                               case 'S':       wc = 'S'; break;
13082 +                                               case 'T':       wc = 'T'; break;
13083 +                                               default:        wc = 0; break;
13084 +                                       }
13085 +                                       
13086 +                                       *ptr = '\0';
13087 +                                       ptr++;
13088 +                                       if (wc)
13089 +                                               val = simple_strtoul(&obuf[i+2], NULL, 10);
13090 +                                       else
13091 +                                               val = simple_strtoul(&obuf[i+1], NULL, 10);
13092 +                                       i += (int)(ptr-&obuf[i]);
13093 +
13094 +                               }
13095 +                               else
13096 +                                       i++;
13097 +                               break;
13098 +                       case 'M': 
13099 +                               op = OSFOPT_MSS;
13100 +                               ptr = osf_strchr(&obuf[i], OPTDEL);
13101 +                               if (ptr)
13102 +                               {
13103 +                                       if (obuf[i+1] == '%')
13104 +                                               wc = '%';
13105 +                                       *ptr = '\0';
13106 +                                       ptr++;
13107 +                                       if (wc)
13108 +                                               val = simple_strtoul(&obuf[i+2], NULL, 10);
13109 +                                       else
13110 +                                               val = simple_strtoul(&obuf[i+1], NULL, 10);
13111 +                                       i += (int)(ptr-&obuf[i]);
13112 +
13113 +                               }
13114 +                               else
13115 +                                       i++;
13116 +                               break;
13117 +                       case 'E': 
13118 +                               op = OSFOPT_EOL;
13119 +                               ptr = osf_strchr(&obuf[i], OPTDEL);
13120 +                               if (ptr)
13121 +                               {
13122 +                                       *ptr = '\0';
13123 +                                       ptr++;
13124 +                                       i += (int)(ptr-&obuf[i]);
13125 +
13126 +                               }
13127 +                               else
13128 +                                       i++;
13129 +                               break;
13130 +                       default:
13131 +                               ptr = osf_strchr(&obuf[i], OPTDEL);
13132 +                               if (ptr)
13133 +                               {
13134 +                                       ptr++;
13135 +                                       i += (int)(ptr-&obuf[i]);
13136 +
13137 +                               }
13138 +                               else
13139 +                                       i++;
13140 +                               break;
13141 +               }
13142 +
13143 +               opt[*optnum].kind       = IANA_opts[op].kind;
13144 +               opt[*optnum].length     = IANA_opts[op].length;
13145 +               opt[*optnum].wc.wc      = wc;
13146 +               opt[*optnum].wc.val     = val;
13147 +
13148 +               (*optnum)++;
13149 +       }
13150 +}
13151 +
13152 +static int osf_proc_read(char *buf, char **start, off_t off, int count, int *eof, void *data)
13153 +{
13154 +       struct list_head *ent;
13155 +       struct osf_finger *f = NULL;
13156 +       int i;
13157 +       
13158 +       *eof = 1;
13159 +       count = 0;
13160 +
13161 +       read_lock_bh(&osf_lock);
13162 +       list_for_each(ent, &finger_list)
13163 +       {
13164 +               f = list_entry(ent, struct osf_finger, flist);
13165 +
13166 +               log("%s [%s]", f->genre, f->details);
13167 +               
13168 +               count += sprintf(buf+count, "%s - %s[%s] : %s", 
13169 +                                       f->genre, f->version,
13170 +                                       f->subtype, f->details);
13171 +               
13172 +               if (f->opt_num)
13173 +               {
13174 +                       loga(" OPT: ");
13175 +                       //count += sprintf(buf+count, " OPT: ");
13176 +                       for (i=0; i<f->opt_num; ++i)
13177 +                       {
13178 +                               //count += sprintf(buf+count, "%d.%c%lu; ", 
13179 +                               //      f->opt[i].kind, (f->opt[i].wc.wc)?f->opt[i].wc.wc:' ', f->opt[i].wc.val);
13180 +                               loga("%d.%c%lu; ", 
13181 +                                       f->opt[i].kind, (f->opt[i].wc.wc)?f->opt[i].wc.wc:' ', f->opt[i].wc.val);
13182 +                       }
13183 +               }
13184 +               loga("\n");
13185 +               count += sprintf(buf+count, "\n");
13186 +       }
13187 +       read_unlock_bh(&osf_lock);
13188 +
13189 +       return count;
13190 +}
13191 +
13192 +static int osf_proc_write(struct file *file, const char *buffer, unsigned long count, void *data)
13193 +{
13194 +       int cnt;
13195 +       unsigned long i;
13196 +       char obuf[MAXOPTSTRLEN];
13197 +       struct osf_finger *finger;
13198 +       struct list_head *ent, *n;
13199 +
13200 +       char *pbeg, *pend;
13201 +
13202 +       if (count == strlen(OSFFLUSH) && !strncmp(buffer, OSFFLUSH, strlen(OSFFLUSH)))
13203 +       {
13204 +               int i = 0;
13205 +               write_lock_bh(&osf_lock);
13206 +               list_for_each_safe(ent, n, &finger_list)
13207 +               {
13208 +                       i++;
13209 +                       finger = list_entry(ent, struct osf_finger, flist);
13210 +                       list_del(&finger->flist);
13211 +                       finger_free(finger);
13212 +               }
13213 +               write_unlock_bh(&osf_lock);
13214 +       
13215 +               log("Flushed %d entries.\n", i);
13216 +               
13217 +               return count;
13218 +       }
13219 +
13220 +       
13221 +       cnt = 0;
13222 +       for (i=0; i<count && buffer[i] != '\0'; ++i)
13223 +               if (buffer[i] == ':')
13224 +                       cnt++;
13225 +
13226 +       if (cnt != 8 || i != count)
13227 +       {
13228 +               log("Wrong input line cnt=%d[8], len=%lu[%lu]\n", 
13229 +                       cnt, i, count);
13230 +               return count;
13231 +       }
13232 +
13233 +       memset(obuf, 0, sizeof(obuf));
13234 +       
13235 +       finger = finger_alloc();
13236 +       if (!finger)
13237 +       {
13238 +               log("Failed to allocate new fingerprint entry.\n");
13239 +               return -ENOMEM;
13240 +       }
13241 +
13242 +       pbeg = (char *)buffer;
13243 +       pend = osf_strchr(pbeg, OSFPDEL);
13244 +       if (pend)
13245 +       {
13246 +               *pend = '\0';
13247 +               if (pbeg[0] == 'S')
13248 +               {
13249 +                       finger->wss.wc = 'S';
13250 +                       if (pbeg[1] == '%')
13251 +                               finger->wss.val = simple_strtoul(pbeg+2, NULL, 10);
13252 +                       else if (pbeg[1] == '*')
13253 +                               finger->wss.val = 0;
13254 +                       else 
13255 +                               finger->wss.val = simple_strtoul(pbeg+1, NULL, 10);
13256 +               }
13257 +               else if (pbeg[0] == 'T')
13258 +               {
13259 +                       finger->wss.wc = 'T';
13260 +                       if (pbeg[1] == '%')
13261 +                               finger->wss.val = simple_strtoul(pbeg+2, NULL, 10);
13262 +                       else if (pbeg[1] == '*')
13263 +                               finger->wss.val = 0;
13264 +                       else 
13265 +                               finger->wss.val = simple_strtoul(pbeg+1, NULL, 10);
13266 +               }
13267 +               else if (pbeg[0] == '%')
13268 +               {
13269 +                       finger->wss.wc = '%';
13270 +                       finger->wss.val = simple_strtoul(pbeg+1, NULL, 10);
13271 +               }
13272 +               else if (isdigit(pbeg[0]))
13273 +               {
13274 +                       finger->wss.wc = 0;
13275 +                       finger->wss.val = simple_strtoul(pbeg, NULL, 10);
13276 +               }
13277 +
13278 +               pbeg = pend+1;
13279 +       }
13280 +       pend = osf_strchr(pbeg, OSFPDEL);
13281 +       if (pend)
13282 +       {
13283 +               *pend = '\0';
13284 +               finger->ttl = simple_strtoul(pbeg, NULL, 10);
13285 +               pbeg = pend+1;
13286 +       }
13287 +       pend = osf_strchr(pbeg, OSFPDEL);
13288 +       if (pend)
13289 +       {
13290 +               *pend = '\0';
13291 +               finger->df = simple_strtoul(pbeg, NULL, 10);
13292 +               pbeg = pend+1;
13293 +       }
13294 +       pend = osf_strchr(pbeg, OSFPDEL);
13295 +       if (pend)
13296 +       {
13297 +               *pend = '\0';
13298 +               finger->ss = simple_strtoul(pbeg, NULL, 10);
13299 +               pbeg = pend+1;
13300 +       }
13301 +
13302 +       pend = osf_strchr(pbeg, OSFPDEL);
13303 +       if (pend)
13304 +       {
13305 +               *pend = '\0';
13306 +               cnt = snprintf(obuf, sizeof(obuf), "%s", pbeg);
13307 +               pbeg = pend+1;
13308 +       }
13309 +
13310 +       pend = osf_strchr(pbeg, OSFPDEL);
13311 +       if (pend)
13312 +       {
13313 +               *pend = '\0';
13314 +               if (pbeg[0] == '@' || pbeg[0] == '*')
13315 +                       cnt = snprintf(finger->genre, sizeof(finger->genre), "%s", pbeg+1);
13316 +               else
13317 +                       cnt = snprintf(finger->genre, sizeof(finger->genre), "%s", pbeg);
13318 +               pbeg = pend+1;
13319 +       }
13320 +       
13321 +       pend = osf_strchr(pbeg, OSFPDEL);
13322 +       if (pend)
13323 +       {
13324 +               *pend = '\0';
13325 +               cnt = snprintf(finger->version, sizeof(finger->version), "%s", pbeg);
13326 +               pbeg = pend+1;
13327 +       }
13328 +       
13329 +       pend = osf_strchr(pbeg, OSFPDEL);
13330 +       if (pend)
13331 +       {
13332 +               *pend = '\0';
13333 +               cnt = snprintf(finger->subtype, sizeof(finger->subtype), "%s", pbeg);
13334 +               pbeg = pend+1;
13335 +       }
13336 +
13337 +       cnt = snprintf(finger->details, 
13338 +                       ((count - (pbeg - buffer)+1) > MAXDETLEN)?MAXDETLEN:(count - (pbeg - buffer)+1), 
13339 +                       "%s", pbeg);
13340 +       
13341 +       log("%s - %s[%s] : %s\n", 
13342 +               finger->genre, finger->version,
13343 +               finger->subtype, finger->details);
13344 +       
13345 +       osf_parse_opt(finger->opt, &finger->opt_num, obuf, sizeof(obuf));
13346 +       
13347 +
13348 +       write_lock_bh(&osf_lock);
13349 +       list_add_tail(&finger->flist, &finger_list);
13350 +       write_unlock_bh(&osf_lock);
13351 +
13352 +       return count;
13353 +}
13354 +
13355 +static int __init osf_init(void)
13356 +{
13357 +       int err;
13358 +       struct proc_dir_entry *p;
13359 +
13360 +       log("Startng OS fingerprint matching module.\n");
13361 +
13362 +       INIT_LIST_HEAD(&finger_list);
13363 +       
13364 +       err = ipt_register_match(&osf_match);
13365 +       if (err)
13366 +       {
13367 +               log("Failed to register OS fingerprint matching module.\n");
13368 +               return -ENXIO;
13369 +       }
13370 +
13371 +       p = create_proc_entry("sys/net/ipv4/osf", S_IFREG | 0644, NULL);
13372 +       if (!p)
13373 +       {
13374 +               ipt_unregister_match(&osf_match);
13375 +               return -ENXIO;
13376 +       }
13377 +
13378 +       p->write_proc = osf_proc_write;
13379 +       p->read_proc  = osf_proc_read;
13380 +       
13381 +       nts = netlink_kernel_create(NETLINK_NFLOG, NULL);
13382 +       if (!nts)
13383 +       {
13384 +               log("netlink_kernel_create() failed\n");
13385 +               remove_proc_entry("sys/net/ipv4/osf", NULL);
13386 +               ipt_unregister_match(&osf_match);
13387 +               return -ENOMEM;
13388 +       }
13389 +
13390 +       return 0;
13391 +}
13392 +
13393 +static void __exit osf_fini(void)
13394 +{
13395 +       struct list_head *ent, *n;
13396 +       struct osf_finger *f;
13397 +       
13398 +       remove_proc_entry("sys/net/ipv4/osf", NULL);
13399 +       ipt_unregister_match(&osf_match);
13400 +       if (nts && nts->sk_socket)
13401 +               sock_release(nts->sk_socket);
13402 +
13403 +       list_for_each_safe(ent, n, &finger_list)
13404 +       {
13405 +               f = list_entry(ent, struct osf_finger, flist);
13406 +               list_del(&f->flist);
13407 +               finger_free(f);
13408 +       }
13409 +       
13410 +       log("OS fingerprint matching module finished.\n");
13411 +}
13412 +
13413 +module_init(osf_init);
13414 +module_exit(osf_fini);
13415 +
13416 +MODULE_LICENSE("GPL");
13417 +MODULE_AUTHOR("Evgeniy Polyakov <johnpol@2ka.mipt.ru>");
13418 +MODULE_DESCRIPTION("Passive OS fingerprint matching.");
13419 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_owner.c linux-2.6.7-rc3/net/ipv4/netfilter/ipt_owner.c
13420 --- linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_owner.c  2004-06-07 21:15:11.000000000 +0200
13421 +++ linux-2.6.7-rc3/net/ipv4/netfilter/ipt_owner.c      2004-06-08 10:39:56.000000000 +0200
13422 @@ -6,12 +6,19 @@
13423   * This program is free software; you can redistribute it and/or modify
13424   * it under the terms of the GNU General Public License version 2 as
13425   * published by the Free Software Foundation.
13426 + *
13427 + * 03/26/2003 Patrick McHardy <kaber@trash.net>        : LOCAL_IN support
13428   */
13429  
13430  #include <linux/module.h>
13431  #include <linux/skbuff.h>
13432  #include <linux/file.h>
13433 +#include <linux/ip.h>
13434 +#include <linux/tcp.h>
13435 +#include <linux/udp.h>
13436  #include <net/sock.h>
13437 +#include <net/tcp.h>
13438 +#include <net/udp.h>
13439  
13440  #include <linux/netfilter_ipv4/ipt_owner.h>
13441  #include <linux/netfilter_ipv4/ip_tables.h>
13442 @@ -21,7 +28,7 @@
13443  MODULE_DESCRIPTION("iptables owner match");
13444  
13445  static int
13446 -match_comm(const struct sk_buff *skb, const char *comm)
13447 +match_comm(const struct sock *sk, const char *comm)
13448  {
13449         struct task_struct *g, *p;
13450         struct files_struct *files;
13451 @@ -38,7 +45,7 @@
13452                         spin_lock(&files->file_lock);
13453                         for (i=0; i < files->max_fds; i++) {
13454                                 if (fcheck_files(files, i) ==
13455 -                                   skb->sk->sk_socket->file) {
13456 +                                   sk->sk_socket->file) {
13457                                         spin_unlock(&files->file_lock);
13458                                         task_unlock(p);
13459                                         read_unlock(&tasklist_lock);
13460 @@ -54,7 +61,7 @@
13461  }
13462  
13463  static int
13464 -match_pid(const struct sk_buff *skb, pid_t pid)
13465 +match_pid(const struct sock *sk, pid_t pid)
13466  {
13467         struct task_struct *p;
13468         struct files_struct *files;
13469 @@ -70,7 +77,7 @@
13470                 spin_lock(&files->file_lock);
13471                 for (i=0; i < files->max_fds; i++) {
13472                         if (fcheck_files(files, i) ==
13473 -                           skb->sk->sk_socket->file) {
13474 +                           sk->sk_socket->file) {
13475                                 spin_unlock(&files->file_lock);
13476                                 task_unlock(p);
13477                                 read_unlock(&tasklist_lock);
13478 @@ -86,10 +93,10 @@
13479  }
13480  
13481  static int
13482 -match_sid(const struct sk_buff *skb, pid_t sid)
13483 +match_sid(const struct sock *sk, pid_t sid)
13484  {
13485         struct task_struct *g, *p;
13486 -       struct file *file = skb->sk->sk_socket->file;
13487 +       struct file *file = sk->sk_socket->file;
13488         int i, found=0;
13489  
13490         read_lock(&tasklist_lock);
13491 @@ -129,41 +136,71 @@
13492        int *hotdrop)
13493  {
13494         const struct ipt_owner_info *info = matchinfo;
13495 +       struct iphdr *iph = skb->nh.iph;
13496 +       struct sock *sk = NULL;
13497 +       int ret = 0;
13498 +
13499 +       if (out) {
13500 +               sk = skb->sk;
13501 +       } else {
13502 +               if (iph->protocol == IPPROTO_TCP) {
13503 +                       struct tcphdr *tcph =
13504 +                               (struct tcphdr *)((u_int32_t *)iph + iph->ihl);
13505 +                       sk = tcp_v4_lookup(iph->saddr, tcph->source,
13506 +                                          iph->daddr, tcph->dest,
13507 +                                          skb->dev->ifindex);
13508 +                       if (sk && sk->sk_state == TCP_TIME_WAIT) {
13509 +                               tcp_tw_put((struct tcp_tw_bucket *)sk);
13510 +                               return ret;
13511 +                       }
13512 +               } else if (iph->protocol == IPPROTO_UDP) {
13513 +                       struct udphdr *udph =
13514 +                               (struct udphdr *)((u_int32_t *)iph + iph->ihl);
13515 +                       sk = udp_v4_lookup(iph->saddr, udph->source, iph->daddr,
13516 +                                          udph->dest, skb->dev->ifindex);
13517 +               }
13518 +       }
13519  
13520 -       if (!skb->sk || !skb->sk->sk_socket || !skb->sk->sk_socket->file)
13521 -               return 0;
13522 +       if (!sk || !sk->sk_socket || !sk->sk_socket->file)
13523 +               goto out;
13524  
13525         if(info->match & IPT_OWNER_UID) {
13526 -               if ((skb->sk->sk_socket->file->f_uid != info->uid) ^
13527 +               if ((sk->sk_socket->file->f_uid != info->uid) ^
13528                     !!(info->invert & IPT_OWNER_UID))
13529 -                       return 0;
13530 +                       goto out;
13531         }
13532  
13533         if(info->match & IPT_OWNER_GID) {
13534 -               if ((skb->sk->sk_socket->file->f_gid != info->gid) ^
13535 +               if ((sk->sk_socket->file->f_gid != info->gid) ^
13536                     !!(info->invert & IPT_OWNER_GID))
13537 -                       return 0;
13538 +                       goto out;
13539         }
13540  
13541         if(info->match & IPT_OWNER_PID) {
13542 -               if (!match_pid(skb, info->pid) ^
13543 +               if (!match_pid(sk, info->pid) ^
13544                     !!(info->invert & IPT_OWNER_PID))
13545 -                       return 0;
13546 +                       goto out;
13547         }
13548  
13549         if(info->match & IPT_OWNER_SID) {
13550 -               if (!match_sid(skb, info->sid) ^
13551 +               if (!match_sid(sk, info->sid) ^
13552                     !!(info->invert & IPT_OWNER_SID))
13553 -                       return 0;
13554 +                       goto out;
13555         }
13556  
13557         if(info->match & IPT_OWNER_COMM) {
13558 -               if (!match_comm(skb, info->comm) ^
13559 +               if (!match_comm(sk, info->comm) ^
13560                     !!(info->invert & IPT_OWNER_COMM))
13561 -                       return 0;
13562 +                       goto out;
13563         }
13564  
13565 -       return 1;
13566 +       ret = 1;
13567 +
13568 +out:
13569 +       if (in && sk)
13570 +               sock_put(sk);
13571 +
13572 +       return ret;
13573  }
13574  
13575  static int
13576 @@ -173,11 +210,19 @@
13577             unsigned int matchsize,
13578             unsigned int hook_mask)
13579  {
13580 -        if (hook_mask
13581 -            & ~((1 << NF_IP_LOCAL_OUT) | (1 << NF_IP_POST_ROUTING))) {
13582 -                printk("ipt_owner: only valid for LOCAL_OUT or POST_ROUTING.\n");
13583 -                return 0;
13584 -        }
13585 +       if (hook_mask
13586 +           & ~((1 << NF_IP_LOCAL_OUT) | (1 << NF_IP_POST_ROUTING) |
13587 +           (1 << NF_IP_LOCAL_IN))) {
13588 +               printk("ipt_owner: only valid for LOCAL_IN, LOCAL_OUT "
13589 +                      "or POST_ROUTING.\n");
13590 +               return 0;
13591 +       }
13592 +
13593 +       if ((hook_mask & (1 << NF_IP_LOCAL_IN))
13594 +           && ip->proto != IPPROTO_TCP && ip->proto != IPPROTO_UDP) {
13595 +               printk("ipt_owner: only TCP or UDP can be used in LOCAL_IN\n");
13596 +               return 0;
13597 +       }
13598  
13599         if (matchsize != IPT_ALIGN(sizeof(struct ipt_owner_info))) {
13600                 printk("Matchsize %u != %Zu\n", matchsize,
13601 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_policy.c linux-2.6.7-rc3/net/ipv4/netfilter/ipt_policy.c
13602 --- linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_policy.c 1970-01-01 01:00:00.000000000 +0100
13603 +++ linux-2.6.7-rc3/net/ipv4/netfilter/ipt_policy.c     2004-06-08 10:42:36.000000000 +0200
13604 @@ -0,0 +1,176 @@
13605 +/* IP tables module for matching IPsec policy
13606 + *
13607 + * Copyright (c) 2004 Patrick McHardy, <kaber@trash.net>
13608 + *
13609 + * This program is free software; you can redistribute it and/or modify
13610 + * it under the terms of the GNU General Public License version 2 as
13611 + * published by the Free Software Foundation.
13612 + */
13613 +
13614 +#include <linux/kernel.h>
13615 +#include <linux/config.h>
13616 +#include <linux/module.h>
13617 +#include <linux/skbuff.h>
13618 +#include <linux/init.h>
13619 +#include <net/xfrm.h>
13620 +
13621 +#include <linux/netfilter_ipv4.h>
13622 +#include <linux/netfilter_ipv4/ipt_policy.h>
13623 +#include <linux/netfilter_ipv4/ip_tables.h>
13624 +
13625 +MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
13626 +MODULE_DESCRIPTION("IPtables IPsec policy matching module");
13627 +MODULE_LICENSE("GPL");
13628 +
13629 +
13630 +static inline int
13631 +match_xfrm_state(struct xfrm_state *x, const struct ipt_policy_elem *e)
13632 +{
13633 +#define MISMATCH(x,y)  (e->match.x && ((e->x != (y)) ^ e->invert.x))
13634 +
13635 +       if (MISMATCH(saddr, x->props.saddr.a4 & e->smask) ||
13636 +           MISMATCH(daddr, x->id.daddr.a4 & e->dmask) ||
13637 +           MISMATCH(proto, x->id.proto) ||
13638 +           MISMATCH(mode, x->props.mode) ||
13639 +           MISMATCH(spi, x->id.spi) ||
13640 +           MISMATCH(reqid, x->props.reqid))
13641 +               return 0;
13642 +       return 1;
13643 +}
13644 +
13645 +static int
13646 +match_policy_in(const struct sk_buff *skb, const struct ipt_policy_info *info)
13647 +{
13648 +       const struct ipt_policy_elem *e;
13649 +       struct sec_path *sp = skb->sp;
13650 +       int strict = info->flags & POLICY_MATCH_STRICT;
13651 +       int i, pos;
13652 +
13653 +       if (sp == NULL)
13654 +               return -1;
13655 +       if (strict && info->len != sp->len)
13656 +               return 0;
13657 +
13658 +       for (i = sp->len - 1; i >= 0; i--) {
13659 +               pos = strict ? i - sp->len + 1 : 0;
13660 +               if (pos >= info->len)
13661 +                       return 0;
13662 +               e = &info->pol[pos];
13663 +
13664 +               if (match_xfrm_state(sp->x[i].xvec, e)) {
13665 +                       if (!strict)
13666 +                               return 1;
13667 +               } else if (strict)
13668 +                       return 0;
13669 +       }
13670 +
13671 +       return strict ? 1 : 0;
13672 +}
13673 +
13674 +static int
13675 +match_policy_out(const struct sk_buff *skb, const struct ipt_policy_info *info)
13676 +{
13677 +       const struct ipt_policy_elem *e;
13678 +       struct dst_entry *dst = skb->dst;
13679 +       int strict = info->flags & POLICY_MATCH_STRICT;
13680 +       int i, pos;
13681 +
13682 +       if (dst->xfrm == NULL)
13683 +               return -1;
13684 +
13685 +       for (i = 0; dst && dst->xfrm; dst = dst->child, i++) {
13686 +               pos = strict ? i : 0;
13687 +               if (pos >= info->len)
13688 +                       return 0;
13689 +               e = &info->pol[pos];
13690 +
13691 +               if (match_xfrm_state(dst->xfrm, e)) {
13692 +                       if (!strict)
13693 +                               return 1;
13694 +               } else if (strict)
13695 +                       return 0;
13696 +       }
13697 +
13698 +       return strict ? 1 : 0;
13699 +}
13700 +
13701 +static int match(const struct sk_buff *skb,
13702 +                 const struct net_device *in,
13703 +                 const struct net_device *out,
13704 +                 const void *matchinfo, int offset, int *hotdrop)
13705 +{
13706 +       const struct ipt_policy_info *info = matchinfo;
13707 +       int ret;
13708 +
13709 +       if (info->flags & POLICY_MATCH_IN)
13710 +               ret = match_policy_in(skb, info);
13711 +       else
13712 +               ret = match_policy_out(skb, info);
13713 +
13714 +       if (ret < 0) {
13715 +               if (info->flags & POLICY_MATCH_NONE)
13716 +                       ret = 1;
13717 +               else
13718 +                       ret = 0;
13719 +       } else if (info->flags & POLICY_MATCH_NONE)
13720 +               ret = 0;
13721 +
13722 +       return ret;
13723 +}
13724 +
13725 +static int checkentry(const char *tablename, const struct ipt_ip *ip,
13726 +                      void *matchinfo, unsigned int matchsize,
13727 +                      unsigned int hook_mask)
13728 +{
13729 +       struct ipt_policy_info *info = matchinfo;
13730 +
13731 +       if (matchsize != IPT_ALIGN(sizeof(*info))) {
13732 +               printk(KERN_ERR "ipt_policy: matchsize %u != %u\n",
13733 +                      matchsize, IPT_ALIGN(sizeof(*info)));
13734 +               return 0;
13735 +       }
13736 +       if (!(info->flags & (POLICY_MATCH_IN|POLICY_MATCH_OUT))) {
13737 +               printk(KERN_ERR "ipt_policy: neither incoming nor "
13738 +                               "outgoing policy selected\n");
13739 +               return 0;
13740 +       }
13741 +       if (hook_mask & (1 << NF_IP_PRE_ROUTING | 1 << NF_IP_LOCAL_IN)
13742 +           && info->flags & POLICY_MATCH_OUT) {
13743 +               printk(KERN_ERR "ipt_policy: output policy not valid in "
13744 +                               "PRE_ROUTING and INPUT\n");
13745 +               return 0;
13746 +       }
13747 +       if (hook_mask & (1 << NF_IP_POST_ROUTING | 1 << NF_IP_LOCAL_OUT)
13748 +           && info->flags & POLICY_MATCH_IN) {
13749 +               printk(KERN_ERR "ipt_policy: input policy not valid in "
13750 +                               "POST_ROUTING and OUTPUT\n");
13751 +               return 0;
13752 +       }
13753 +       if (info->len > POLICY_MAX_ELEM) {
13754 +               printk(KERN_ERR "ipt_policy: too many policy elements\n");
13755 +               return 0;
13756 +       }
13757 +
13758 +       return 1;
13759 +}
13760 +
13761 +static struct ipt_match policy_match =
13762 +{
13763 +       .name           = "policy",
13764 +       .match          = match,
13765 +       .checkentry     = checkentry,
13766 +       .me             = THIS_MODULE,
13767 +};
13768 +
13769 +static int __init init(void)
13770 +{
13771 +       return ipt_register_match(&policy_match);
13772 +}
13773 +
13774 +static void __exit fini(void)
13775 +{
13776 +       ipt_unregister_match(&policy_match);
13777 +}
13778 +
13779 +module_init(init);
13780 +module_exit(fini);
13781 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_pool.c linux-2.6.7-rc3/net/ipv4/netfilter/ipt_pool.c
13782 --- linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_pool.c   1970-01-01 01:00:00.000000000 +0100
13783 +++ linux-2.6.7-rc3/net/ipv4/netfilter/ipt_pool.c       2004-06-08 10:31:45.000000000 +0200
13784 @@ -0,0 +1,71 @@
13785 +/* Kernel module to match an IP address pool. */
13786 +
13787 +#include <linux/module.h>
13788 +#include <linux/ip.h>
13789 +#include <linux/skbuff.h>
13790 +
13791 +#include <linux/netfilter_ipv4/ip_tables.h>
13792 +#include <linux/netfilter_ipv4/ip_pool.h>
13793 +#include <linux/netfilter_ipv4/ipt_pool.h>
13794 +
13795 +static inline int match_pool(
13796 +       ip_pool_t index,
13797 +       __u32 addr,
13798 +       int inv
13799 +) {
13800 +       if (ip_pool_match(index, ntohl(addr)))
13801 +               inv = !inv;
13802 +       return inv;
13803 +}
13804 +
13805 +static int match(
13806 +       const struct sk_buff *skb,
13807 +       const struct net_device *in,
13808 +       const struct net_device *out,
13809 +       const void *matchinfo,
13810 +       int offset,
13811 +       const void *hdr,
13812 +       u_int16_t datalen,
13813 +       int *hotdrop
13814 +) {
13815 +       const struct ipt_pool_info *info = matchinfo;
13816 +       const struct iphdr *iph = skb->nh.iph;
13817 +
13818 +       if (info->src != IP_POOL_NONE && !match_pool(info->src, iph->saddr,
13819 +                                               info->flags&IPT_POOL_INV_SRC))
13820 +               return 0;
13821 +
13822 +       if (info->dst != IP_POOL_NONE && !match_pool(info->dst, iph->daddr,
13823 +                                               info->flags&IPT_POOL_INV_DST))
13824 +               return 0;
13825 +
13826 +       return 1;
13827 +}
13828 +
13829 +static int checkentry(
13830 +       const char *tablename,
13831 +       const struct ipt_ip *ip,
13832 +       void *matchinfo,
13833 +       unsigned int matchsize,
13834 +       unsigned int hook_mask
13835 +) {
13836 +       if (matchsize != IPT_ALIGN(sizeof(struct ipt_pool_info)))
13837 +               return 0;
13838 +       return 1;
13839 +}
13840 +
13841 +static struct ipt_match pool_match
13842 += { { NULL, NULL }, "pool", &match, &checkentry, NULL, THIS_MODULE };
13843 +
13844 +static int __init init(void)
13845 +{
13846 +       return ipt_register_match(&pool_match);
13847 +}
13848 +
13849 +static void __exit fini(void)
13850 +{
13851 +       ipt_unregister_match(&pool_match);
13852 +}
13853 +
13854 +module_init(init);
13855 +module_exit(fini);
13856 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_psd.c linux-2.6.7-rc3/net/ipv4/netfilter/ipt_psd.c
13857 --- linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_psd.c    1970-01-01 01:00:00.000000000 +0100
13858 +++ linux-2.6.7-rc3/net/ipv4/netfilter/ipt_psd.c        2004-06-08 10:31:53.000000000 +0200
13859 @@ -0,0 +1,358 @@
13860 +/*
13861 +  This is a module which is used for PSD (portscan detection)
13862 +  Derived from scanlogd v2.1 written by Solar Designer <solar@false.com>
13863 +  and LOG target module.
13864 +
13865 +  Copyright (C) 2000,2001 astaro AG
13866 +
13867 +  This file is distributed under the terms of the GNU General Public
13868 +  License (GPL). Copies of the GPL can be obtained from:
13869 +     ftp://prep.ai.mit.edu/pub/gnu/GPL
13870 +
13871 +  2000-05-04 Markus Hennig <hennig@astaro.de> : initial
13872 +  2000-08-18 Dennis Koslowski <koslowski@astaro.de> : first release
13873 +  2000-12-01 Dennis Koslowski <koslowski@astaro.de> : UDP scans detection added
13874 +  2001-01-02 Dennis Koslowski <koslowski@astaro.de> : output modified
13875 +  2001-02-04 Jan Rekorajski <baggins@pld.org.pl> : converted from target to match
13876 +  2004-05-05 Martijn Lievaart <m@rtij.nl> : ported to 2.6
13877 +*/
13878 +
13879 +#include <linux/module.h>
13880 +#include <linux/skbuff.h>
13881 +#include <linux/ip.h>
13882 +#include <net/tcp.h>
13883 +#include <linux/spinlock.h>
13884 +#include <linux/netfilter_ipv4/ip_tables.h>
13885 +#include <linux/netfilter_ipv4/ipt_psd.h>
13886 +
13887 +#if 0
13888 +#define DEBUGP printk
13889 +#else
13890 +#define DEBUGP(format, args...)
13891 +#endif
13892 +
13893 +MODULE_LICENSE("GPL");
13894 +MODULE_AUTHOR("Dennis Koslowski <koslowski@astaro.com>");
13895 +
13896 +#define HF_DADDR_CHANGING   0x01
13897 +#define HF_SPORT_CHANGING   0x02
13898 +#define HF_TOS_CHANGING            0x04
13899 +#define HF_TTL_CHANGING            0x08
13900 +
13901 +/*
13902 + * Information we keep per each target port
13903 + */
13904 +struct port {
13905 +       u_int16_t number;      /* port number */
13906 +       u_int8_t proto;        /* protocol number */
13907 +       u_int8_t and_flags;    /* tcp ANDed flags */
13908 +       u_int8_t or_flags;     /* tcp ORed flags */
13909 +};
13910 +
13911 +/*
13912 + * Information we keep per each source address.
13913 + */
13914 +struct host {
13915 +       struct host *next;              /* Next entry with the same hash */
13916 +       clock_t timestamp;              /* Last update time */
13917 +       struct in_addr src_addr;        /* Source address */
13918 +       struct in_addr dest_addr;       /* Destination address */
13919 +       unsigned short src_port;        /* Source port */
13920 +       int count;                      /* Number of ports in the list */
13921 +       int weight;                     /* Total weight of ports in the list */
13922 +       struct port ports[SCAN_MAX_COUNT - 1];  /* List of ports */
13923 +       unsigned char tos;              /* TOS */
13924 +       unsigned char ttl;              /* TTL */
13925 +       unsigned char flags;            /* HF_ flags bitmask */
13926 +};
13927 +
13928 +/*
13929 + * State information.
13930 + */
13931 +static struct {
13932 +       spinlock_t lock;
13933 +       struct host list[LIST_SIZE];    /* List of source addresses */
13934 +       struct host *hash[HASH_SIZE];   /* Hash: pointers into the list */
13935 +       int index;                      /* Oldest entry to be replaced */
13936 +} state;
13937 +
13938 +/*
13939 + * Convert an IP address into a hash table index.
13940 + */
13941 +static inline int hashfunc(struct in_addr addr)
13942 +{
13943 +       unsigned int value;
13944 +       int hash;
13945 +
13946 +       value = addr.s_addr;
13947 +       hash = 0;
13948 +       do {
13949 +               hash ^= value;
13950 +       } while ((value >>= HASH_LOG));
13951 +
13952 +       return hash & (HASH_SIZE - 1);
13953 +}
13954 +
13955 +static int
13956 +ipt_psd_match(const struct sk_buff *pskb,
13957 +             const struct net_device *in,
13958 +             const struct net_device *out,
13959 +             const void *matchinfo,
13960 +             int offset,
13961 +             int *hotdrop)
13962 +{
13963 +       struct iphdr *ip_hdr;
13964 +       struct tcphdr *tcp_hdr;
13965 +       struct in_addr addr;
13966 +       u_int16_t src_port,dest_port;
13967 +       u_int8_t tcp_flags, proto;
13968 +       clock_t now;
13969 +       struct host *curr, *last, **head;
13970 +       int hash, index, count;
13971 +
13972 +       /* Parameters from userspace */
13973 +       const struct ipt_psd_info *psdinfo = matchinfo;
13974 +
13975 +       /* IP header */
13976 +       ip_hdr = pskb->nh.iph;
13977 +
13978 +       /* Sanity check */
13979 +       if (ntohs(ip_hdr->frag_off) & IP_OFFSET) {
13980 +               DEBUGP("PSD: sanity check failed\n");
13981 +               return 0;
13982 +       }
13983 +
13984 +       /* TCP or UDP ? */
13985 +       proto = ip_hdr->protocol;
13986 +
13987 +       if (proto != IPPROTO_TCP && proto != IPPROTO_UDP) {
13988 +               DEBUGP("PSD: protocol not supported\n");
13989 +               return 0;
13990 +       }
13991 +
13992 +       /* Get the source address, source & destination ports, and TCP flags */
13993 +
13994 +       addr.s_addr = ip_hdr->saddr;
13995 +
13996 +       tcp_hdr = (struct tcphdr*)((u_int32_t *)ip_hdr + ip_hdr->ihl);
13997 +
13998 +       /* Yep, it´s dirty */
13999 +       src_port = tcp_hdr->source;
14000 +       dest_port = tcp_hdr->dest;
14001 +
14002 +       if (proto == IPPROTO_TCP) {
14003 +               tcp_flags = *((u_int8_t*)tcp_hdr + 13);
14004 +       }
14005 +       else {
14006 +               tcp_flags = 0x00;
14007 +       }
14008 +
14009 +       /* We're using IP address 0.0.0.0 for a special purpose here, so don't let
14010 +        * them spoof us. [DHCP needs this feature - HW] */
14011 +       if (!addr.s_addr) {
14012 +               DEBUGP("PSD: spoofed source address (0.0.0.0)\n");
14013 +               return 0;
14014 +       }
14015 +
14016 +       /* Use jiffies here not to depend on someone setting the time while we're
14017 +        * running; we need to be careful with possible return value overflows. */
14018 +       now = jiffies;
14019 +
14020 +       spin_lock(&state.lock);
14021 +
14022 +       /* Do we know this source address already? */
14023 +       count = 0;
14024 +       last = NULL;
14025 +       if ((curr = *(head = &state.hash[hash = hashfunc(addr)])))
14026 +               do {
14027 +                       if (curr->src_addr.s_addr == addr.s_addr) break;
14028 +                       count++;
14029 +                       if (curr->next) last = curr;
14030 +               } while ((curr = curr->next));
14031 +
14032 +       if (curr) {
14033 +
14034 +               /* We know this address, and the entry isn't too old. Update it. */
14035 +               if (now - curr->timestamp <= (psdinfo->delay_threshold*HZ)/100 &&
14036 +                   time_after_eq(now, curr->timestamp)) {
14037 +
14038 +                       /* Just update the appropriate list entry if we've seen this port already */
14039 +                       for (index = 0; index < curr->count; index++) {
14040 +                               if (curr->ports[index].number == dest_port) {
14041 +                                       curr->ports[index].proto = proto;
14042 +                                       curr->ports[index].and_flags &= tcp_flags;
14043 +                                       curr->ports[index].or_flags |= tcp_flags;
14044 +                                       goto out_no_match;
14045 +                               }
14046 +                       }
14047 +
14048 +                       /* TCP/ACK and/or TCP/RST to a new port? This could be an outgoing connection. */
14049 +                       if (proto == IPPROTO_TCP && (tcp_hdr->ack || tcp_hdr->rst))
14050 +                               goto out_no_match;
14051 +
14052 +                       /* Packet to a new port, and not TCP/ACK: update the timestamp */
14053 +                       curr->timestamp = now;
14054 +
14055 +                       /* Logged this scan already? Then drop the packet. */
14056 +                       if (curr->weight >= psdinfo->weight_threshold)
14057 +                               goto out_match;
14058 +
14059 +                       /* Specify if destination address, source port, TOS or TTL are not fixed */
14060 +                       if (curr->dest_addr.s_addr != ip_hdr->daddr)
14061 +                               curr->flags |= HF_DADDR_CHANGING;
14062 +                       if (curr->src_port != src_port)
14063 +                               curr->flags |= HF_SPORT_CHANGING;
14064 +                       if (curr->tos != ip_hdr->tos)
14065 +                               curr->flags |= HF_TOS_CHANGING;
14066 +                       if (curr->ttl != ip_hdr->ttl)
14067 +                               curr->flags |= HF_TTL_CHANGING;
14068 +
14069 +                       /* Update the total weight */
14070 +                       curr->weight += (ntohs(dest_port) < 1024) ?
14071 +                               psdinfo->lo_ports_weight : psdinfo->hi_ports_weight;
14072 +
14073 +                       /* Got enough destination ports to decide that this is a scan? */
14074 +                       /* Then log it and drop the packet. */
14075 +                       if (curr->weight >= psdinfo->weight_threshold)
14076 +                               goto out_match;
14077 +
14078 +                       /* Remember the new port */
14079 +                       if (curr->count < SCAN_MAX_COUNT) {
14080 +                               curr->ports[curr->count].number = dest_port;
14081 +                               curr->ports[curr->count].proto = proto;
14082 +                               curr->ports[curr->count].and_flags = tcp_flags;
14083 +                               curr->ports[curr->count].or_flags = tcp_flags;
14084 +                               curr->count++;
14085 +                       }
14086 +
14087 +                       goto out_no_match;
14088 +               }
14089 +
14090 +               /* We know this address, but the entry is outdated. Mark it unused, and
14091 +                * remove from the hash table. We'll allocate a new entry instead since
14092 +                * this one might get re-used too soon. */
14093 +               curr->src_addr.s_addr = 0;
14094 +               if (last)
14095 +                       last->next = last->next->next;
14096 +               else if (*head)
14097 +                       *head = (*head)->next;
14098 +               last = NULL;
14099 +       }
14100 +
14101 +       /* We don't need an ACK from a new source address */
14102 +       if (proto == IPPROTO_TCP && tcp_hdr->ack)
14103 +               goto out_no_match;
14104 +
14105 +       /* Got too many source addresses with the same hash value? Then remove the
14106 +        * oldest one from the hash table, so that they can't take too much of our
14107 +        * CPU time even with carefully chosen spoofed IP addresses. */
14108 +       if (count >= HASH_MAX && last) last->next = NULL;
14109 +
14110 +       /* We're going to re-use the oldest list entry, so remove it from the hash
14111 +        * table first (if it is really already in use, and isn't removed from the
14112 +        * hash table already because of the HASH_MAX check above). */
14113 +
14114 +       /* First, find it */
14115 +       if (state.list[state.index].src_addr.s_addr)
14116 +               head = &state.hash[hashfunc(state.list[state.index].src_addr)];
14117 +       else
14118 +               head = &last;
14119 +       last = NULL;
14120 +       if ((curr = *head))
14121 +       do {
14122 +               if (curr == &state.list[state.index]) break;
14123 +               last = curr;
14124 +       } while ((curr = curr->next));
14125 +
14126 +       /* Then, remove it */
14127 +       if (curr) {
14128 +               if (last)
14129 +                       last->next = last->next->next;
14130 +               else if (*head)
14131 +                       *head = (*head)->next;
14132 +       }
14133 +
14134 +       /* Get our list entry */
14135 +       curr = &state.list[state.index++];
14136 +       if (state.index >= LIST_SIZE) state.index = 0;
14137 +
14138 +       /* Link it into the hash table */
14139 +       head = &state.hash[hash];
14140 +       curr->next = *head;
14141 +       *head = curr;
14142 +
14143 +       /* And fill in the fields */
14144 +       curr->timestamp = now;
14145 +       curr->src_addr = addr;
14146 +       curr->dest_addr.s_addr = ip_hdr->daddr;
14147 +       curr->src_port = src_port;
14148 +       curr->count = 1;
14149 +       curr->weight = (ntohs(dest_port) < 1024) ?
14150 +               psdinfo->lo_ports_weight : psdinfo->hi_ports_weight;
14151 +       curr->ports[0].number = dest_port;
14152 +       curr->ports[0].proto = proto;
14153 +       curr->ports[0].and_flags = tcp_flags;
14154 +       curr->ports[0].or_flags = tcp_flags;
14155 +       curr->tos = ip_hdr->tos;
14156 +       curr->ttl = ip_hdr->ttl;
14157 +
14158 +out_no_match:
14159 +       spin_unlock(&state.lock);
14160 +       return 0;
14161 +
14162 +out_match:
14163 +       spin_unlock(&state.lock);
14164 +       return 1;
14165 +}
14166 +
14167 +static int ipt_psd_checkentry(const char *tablename,
14168 +                             const struct ipt_ip *e,
14169 +                             void *matchinfo,
14170 +                             unsigned int matchsize,
14171 +                             unsigned int hook_mask)
14172 +{
14173 +/*     const struct ipt_psd_info *psdinfo = targinfo;*/
14174 +
14175 +       /* we accept TCP only */
14176 +/*     if (e->ip.proto != IPPROTO_TCP) { */
14177 +/*             DEBUGP("PSD: specified protocol may be TCP only\n"); */
14178 +/*             return 0; */
14179 +/*     } */
14180 +
14181 +       if (matchsize != IPT_ALIGN(sizeof(struct ipt_psd_info))) {
14182 +               DEBUGP("PSD: matchsize %u != %u\n",
14183 +                      matchsize,
14184 +                      IPT_ALIGN(sizeof(struct ipt_psd_info)));
14185 +               return 0;
14186 +       }
14187 +
14188 +       return 1;
14189 +}
14190 +
14191 +static struct ipt_match ipt_psd_reg = {
14192 +       .name = "psd",
14193 +       .match = ipt_psd_match,
14194 +       .checkentry = ipt_psd_checkentry,
14195 +       .me = THIS_MODULE };
14196 +
14197 +static int __init init(void)
14198 +{
14199 +       if (ipt_register_match(&ipt_psd_reg))
14200 +               return -EINVAL;
14201 +
14202 +       memset(&state, 0, sizeof(state));
14203 +
14204 +       spin_lock_init(&(state.lock));
14205 +
14206 +       printk("netfilter PSD loaded - (c) astaro AG\n");
14207 +       return 0;
14208 +}
14209 +
14210 +static void __exit fini(void)
14211 +{
14212 +       ipt_unregister_match(&ipt_psd_reg);
14213 +       printk("netfilter PSD unloaded - (c) astaro AG\n");
14214 +}
14215 +
14216 +module_init(init);
14217 +module_exit(fini);
14218 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_quota.c linux-2.6.7-rc3/net/ipv4/netfilter/ipt_quota.c
14219 --- linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_quota.c  1970-01-01 01:00:00.000000000 +0100
14220 +++ linux-2.6.7-rc3/net/ipv4/netfilter/ipt_quota.c      2004-06-08 10:31:54.000000000 +0200
14221 @@ -0,0 +1,91 @@
14222 +/* 
14223 + * netfilter module to enforce network quotas
14224 + *
14225 + * Sam Johnston <samj@samj.net>
14226 + */
14227 +#include <linux/module.h>
14228 +#include <linux/skbuff.h>
14229 +#include <linux/spinlock.h>
14230 +#include <linux/interrupt.h>
14231 +
14232 +#include <linux/netfilter_ipv4/ip_tables.h>
14233 +#include <linux/netfilter_ipv4/ipt_quota.h>
14234 +
14235 +MODULE_LICENSE("GPL");
14236 +MODULE_AUTHOR("Sam Johnston <samj@samj.net>");
14237 +
14238 +static spinlock_t quota_lock = SPIN_LOCK_UNLOCKED;
14239 +
14240 +static int
14241 +match(const struct sk_buff *skb,
14242 +      const struct net_device *in,
14243 +      const struct net_device *out,
14244 +      const void *matchinfo,
14245 +      int offset, int *hotdrop)
14246 +{
14247 +        struct ipt_quota_info *q = (struct ipt_quota_info *) matchinfo;
14248 +       unsigned int datalen;
14249 +
14250 +       if (skb->len < sizeof(struct iphdr))
14251 +               return NF_ACCEPT;
14252 +       
14253 +       datalen = skb->len - skb->nh.iph->ihl*4;
14254 +
14255 +        spin_lock_bh(&quota_lock);
14256 +
14257 +        if (q->quota >= datalen) {
14258 +                /* we can afford this one */
14259 +                q->quota -= datalen;
14260 +                spin_unlock_bh(&quota_lock);
14261 +
14262 +#ifdef DEBUG_IPT_QUOTA
14263 +                printk("IPT Quota OK: %llu datlen %d \n", q->quota, datalen);
14264 +#endif
14265 +                return 1;
14266 +        }
14267 +
14268 +        /* so we do not allow even small packets from now on */
14269 +        q->quota = 0;
14270 +
14271 +#ifdef DEBUG_IPT_QUOTA
14272 +        printk("IPT Quota Failed: %llu datlen %d \n", q->quota, datalen);
14273 +#endif
14274 +
14275 +        spin_unlock_bh(&quota_lock);
14276 +        return 0;
14277 +}
14278 +
14279 +static int
14280 +checkentry(const char *tablename,
14281 +           const struct ipt_ip *ip,
14282 +           void *matchinfo, unsigned int matchsize, unsigned int hook_mask)
14283 +{
14284 +        /* TODO: spinlocks? sanity checks? */
14285 +        if (matchsize != IPT_ALIGN(sizeof (struct ipt_quota_info)))
14286 +                return 0;
14287 +
14288 +        return 1;
14289 +}
14290 +
14291 +static struct ipt_match quota_match = {
14292 +       .name = "quota",
14293 +       .match = match,
14294 +       .checkentry = checkentry,
14295 +       .me = THIS_MODULE
14296 +};
14297 +
14298 +static int __init
14299 +init(void)
14300 +{
14301 +        return ipt_register_match(&quota_match);
14302 +}
14303 +
14304 +static void __exit
14305 +fini(void)
14306 +{
14307 +        ipt_unregister_match(&quota_match);
14308 +}
14309 +
14310 +module_init(init);
14311 +module_exit(fini);
14312 +
14313 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_random.c linux-2.6.7-rc3/net/ipv4/netfilter/ipt_random.c
14314 --- linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_random.c 1970-01-01 01:00:00.000000000 +0100
14315 +++ linux-2.6.7-rc3/net/ipv4/netfilter/ipt_random.c     2004-06-08 10:31:56.000000000 +0200
14316 @@ -0,0 +1,96 @@
14317 +/*
14318 +  This is a module which is used for a "random" match support.
14319 +  This file is distributed under the terms of the GNU General Public
14320 +  License (GPL). Copies of the GPL can be obtained from:
14321 +     ftp://prep.ai.mit.edu/pub/gnu/GPL
14322 +
14323 +  2001-10-14 Fabrice MARIE <fabrice@netfilter.org> : initial implementation.
14324 +*/
14325 +
14326 +#include <linux/module.h>
14327 +#include <linux/skbuff.h>
14328 +#include <linux/ip.h>
14329 +#include <linux/random.h>
14330 +#include <net/tcp.h>
14331 +#include <linux/spinlock.h>
14332 +#include <linux/netfilter_ipv4/ip_tables.h>
14333 +#include <linux/netfilter_ipv4/ipt_random.h>
14334 +
14335 +MODULE_LICENSE("GPL");
14336 +
14337 +static int
14338 +ipt_rand_match(const struct sk_buff *pskb,
14339 +              const struct net_device *in,
14340 +              const struct net_device *out,
14341 +              const void *matchinfo,
14342 +              int offset,
14343 +              const void *hdr,
14344 +              u_int16_t datalen,
14345 +              int *hotdrop)
14346 +{
14347 +       /* Parameters from userspace */
14348 +       const struct ipt_rand_info *info = matchinfo;
14349 +       u_int8_t random_number;
14350 +
14351 +       /* get 1 random number from the kernel random number generation routine */
14352 +       get_random_bytes((void *)(&random_number), 1);
14353 +
14354 +       /* Do we match ? */
14355 +       if (random_number <= info->average)
14356 +               return 1;
14357 +       else
14358 +               return 0;
14359 +}
14360 +
14361 +static int
14362 +ipt_rand_checkentry(const char *tablename,
14363 +                  const struct ipt_ip *e,
14364 +                  void *matchinfo,
14365 +                  unsigned int matchsize,
14366 +                  unsigned int hook_mask)
14367 +{
14368 +       /* Parameters from userspace */
14369 +       const struct ipt_rand_info *info = matchinfo;
14370 +
14371 +       if (matchsize != IPT_ALIGN(sizeof(struct ipt_rand_info))) {
14372 +               printk("ipt_random: matchsize %u != %u\n", matchsize,
14373 +                      IPT_ALIGN(sizeof(struct ipt_rand_info)));
14374 +               return 0;
14375 +       }
14376 +
14377 +       /* must be  1 <= average % <= 99 */
14378 +       /* 1  x 2.55 = 2   */
14379 +       /* 99 x 2.55 = 252 */
14380 +       if ((info->average < 2) || (info->average > 252)) {
14381 +               printk("ipt_random:  invalid average %u\n", info->average);
14382 +               return 0;
14383 +       }
14384 +
14385 +       return 1;
14386 +}
14387 +
14388 +static struct ipt_match ipt_rand_reg = { 
14389 +       {NULL, NULL},
14390 +       "random",
14391 +       ipt_rand_match,
14392 +       ipt_rand_checkentry,
14393 +       NULL,
14394 +       THIS_MODULE };
14395 +
14396 +static int __init init(void)
14397 +{
14398 +       if (ipt_register_match(&ipt_rand_reg))
14399 +               return -EINVAL;
14400 +
14401 +       printk("ipt_random match loaded\n");
14402 +       return 0;
14403 +}
14404 +
14405 +static void __exit fini(void)
14406 +{
14407 +       ipt_unregister_match(&ipt_rand_reg);
14408 +       printk("ipt_random match unloaded\n");
14409 +}
14410 +
14411 +module_init(init);
14412 +module_exit(fini);
14413 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_realm.c linux-2.6.7-rc3/net/ipv4/netfilter/ipt_realm.c
14414 --- linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_realm.c  1970-01-01 01:00:00.000000000 +0100
14415 +++ linux-2.6.7-rc3/net/ipv4/netfilter/ipt_realm.c      2004-06-08 10:32:20.000000000 +0200
14416 @@ -0,0 +1,78 @@
14417 +/* IP tables module for matching the routing realm
14418 + *
14419 + * $Id$
14420 + *
14421 + * (C) 2003 by Sampsa Ranta <sampsa@netsonic.fi>
14422 + *
14423 + * This program is free software; you can redistribute it and/or modify
14424 + * it under the terms of the GNU General Public License version 2 as
14425 + * published by the Free Software Foundation.
14426 + */
14427 +
14428 +#include <linux/module.h>
14429 +#include <linux/skbuff.h>
14430 +#include <linux/netdevice.h>
14431 +#include <net/route.h>
14432 +
14433 +#include <linux/netfilter_ipv4/ipt_realm.h>
14434 +#include <linux/netfilter_ipv4/ip_tables.h>
14435 +
14436 +MODULE_AUTHOR("Sampsa Ranta <sampsa@netsonic.fi>");
14437 +MODULE_LICENSE("GPL");
14438 +
14439 +static int
14440 +match(const struct sk_buff *skb,
14441 +      const struct net_device *in,
14442 +      const struct net_device *out,
14443 +      const void *matchinfo,
14444 +      int offset,
14445 +      int *hotdrop)
14446 +{
14447 +       const struct ipt_realm_info *info = matchinfo;
14448 +       struct dst_entry *dst = skb->dst;
14449 +    
14450 +       if (!dst)
14451 +               return 0;
14452 +
14453 +       return (info->id == (dst->tclassid & info->mask)) ^ info->invert;
14454 +}
14455 +
14456 +static int check(const char *tablename,
14457 +                 const struct ipt_ip *ip,
14458 +                 void *matchinfo,
14459 +                 unsigned int matchsize,
14460 +                 unsigned int hook_mask)
14461 +{
14462 +       if (hook_mask
14463 +           & ~((1 << NF_IP_POST_ROUTING) | (1 << NF_IP_FORWARD) |
14464 +               (1 << NF_IP_LOCAL_OUT)| (1 << NF_IP_LOCAL_IN))) {
14465 +               printk("ipt_realm: only valid for POST_ROUTING, LOCAL_OUT, "
14466 +                      "LOCAL_IN or FORWARD.\n");
14467 +               return 0;
14468 +       }
14469 +
14470 +       if (matchsize != IPT_ALIGN(sizeof(struct ipt_realm_info)))
14471 +               return 0;
14472 +
14473 +       return 1;
14474 +}
14475 +
14476 +static struct ipt_match realm_match = {
14477 +       .name = "realm",
14478 +       .match = match, 
14479 +       .checkentry = check,
14480 +       .me = THIS_MODULE
14481 +};
14482 +
14483 +static int __init init(void)
14484 +{
14485 +       return ipt_register_match(&realm_match);
14486 +}
14487 +
14488 +static void __exit fini(void)
14489 +{
14490 +       ipt_unregister_match(&realm_match);
14491 +}
14492 +
14493 +module_init(init);
14494 +module_exit(fini);
14495 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_sctp.c linux-2.6.7-rc3/net/ipv4/netfilter/ipt_sctp.c
14496 --- linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_sctp.c   1970-01-01 01:00:00.000000000 +0100
14497 +++ linux-2.6.7-rc3/net/ipv4/netfilter/ipt_sctp.c       2004-06-08 10:32:21.000000000 +0200
14498 @@ -0,0 +1,199 @@
14499 +#include <linux/module.h>
14500 +#include <linux/skbuff.h>
14501 +#include <net/ip.h>
14502 +#include <linux/sctp.h>
14503 +
14504 +#include <linux/netfilter_ipv4/ip_tables.h>
14505 +#include <linux/netfilter_ipv4/ipt_sctp.h>
14506 +
14507 +#if 0
14508 +#define duprintf(format, args...) printk(format , ## args)
14509 +#else
14510 +#define duprintf(format, args...)
14511 +#endif
14512 +
14513 +#define SCCHECK(cond, option, flag, invflag) (!((flag) & (option)) \
14514 +                                             || (!!((invflag) & (option)) ^ (cond)))
14515 +
14516 +static int
14517 +match_flags(const struct ipt_sctp_flag_info *flag_info,
14518 +           const int flag_count,
14519 +           u_int8_t chunktype,
14520 +           u_int8_t chunkflags)
14521 +{
14522 +       int i;
14523 +
14524 +       for (i = 0; i < flag_count; i++) {
14525 +               if (flag_info[i].chunktype == chunktype) {
14526 +                       return (chunkflags & flag_info[i].flag_mask) == flag_info[i].flag;
14527 +               }
14528 +       }
14529 +
14530 +       return 1;
14531 +}
14532 +
14533 +static int
14534 +match_packet(const struct sk_buff *skb,
14535 +            const u_int32_t *chunkmap,
14536 +            int chunk_match_type,
14537 +            const struct ipt_sctp_flag_info *flag_info,
14538 +            const int flag_count,
14539 +            int *hotdrop)
14540 +{
14541 +       int offset;
14542 +       u_int32_t chunkmapcopy[256 / sizeof (u_int32_t)];
14543 +       sctp_chunkhdr_t sch;
14544 +
14545 +       int i = 0;
14546 +
14547 +       if (chunk_match_type == SCTP_CHUNK_MATCH_ALL) {
14548 +               SCTP_CHUNKMAP_COPY(chunkmapcopy, chunkmap);
14549 +       }
14550 +
14551 +       offset = skb->nh.iph->ihl * 4 + sizeof (sctp_sctphdr_t);
14552 +       do {
14553 +               if (skb_copy_bits(skb, offset, &sch, sizeof(sch)) < 0) {
14554 +                       duprintf("Dropping invalid SCTP packet.\n");
14555 +                       *hotdrop = 1;
14556 +                       return 0;
14557 +               }
14558 +
14559 +               duprintf("Chunk num: %d\toffset: %d\ttype: %d\tlength: %d\tflags: %x\n", 
14560 +                               ++i, offset, sch.type, htons(sch.length), sch.flags);
14561 +
14562 +               offset += (htons(sch.length) + 3) & ~3;
14563 +
14564 +               duprintf("skb->len: %d\toffset: %d\n", skb->len, offset);
14565 +
14566 +               if (SCTP_CHUNKMAP_IS_SET(chunkmap, sch.type)) {
14567 +                       switch (chunk_match_type) {
14568 +                       case SCTP_CHUNK_MATCH_ANY:
14569 +                               if (match_flags(flag_info, flag_count, 
14570 +                                       sch.type, sch.flags)) {
14571 +                                       return 1;
14572 +                               }
14573 +                               break;
14574 +
14575 +                       case SCTP_CHUNK_MATCH_ALL:
14576 +                               if (match_flags(flag_info, flag_count, 
14577 +                                       sch.type, sch.flags)) {
14578 +                                       SCTP_CHUNKMAP_CLEAR(chunkmapcopy, sch.type);
14579 +                               }
14580 +                               break;
14581 +
14582 +                       case SCTP_CHUNK_MATCH_ONLY:
14583 +                               if (!match_flags(flag_info, flag_count, 
14584 +                                       sch.type, sch.flags)) {
14585 +                                       return 0;
14586 +                               }
14587 +                               break;
14588 +                       }
14589 +               } else {
14590 +                       switch (chunk_match_type) {
14591 +                       case SCTP_CHUNK_MATCH_ONLY:
14592 +                               return 0;
14593 +                       }
14594 +               }
14595 +       } while (offset < skb->len);
14596 +
14597 +       switch (chunk_match_type) {
14598 +       case SCTP_CHUNK_MATCH_ALL:
14599 +               return SCTP_CHUNKMAP_IS_CLEAR(chunkmap);
14600 +       case SCTP_CHUNK_MATCH_ANY:
14601 +               return 0;
14602 +       case SCTP_CHUNK_MATCH_ONLY:
14603 +               return 1;
14604 +       }
14605 +
14606 +       /* This will never be reached, but required to stop compiler whine */
14607 +       return 0;
14608 +}
14609 +
14610 +static int
14611 +match(const struct sk_buff *skb,
14612 +      const struct net_device *in,
14613 +      const struct net_device *out,
14614 +      const void *matchinfo,
14615 +      int offset,
14616 +      int *hotdrop)
14617 +{
14618 +       const struct ipt_sctp_info *info;
14619 +       sctp_sctphdr_t sh;
14620 +
14621 +       info = (const struct ipt_sctp_info *)matchinfo;
14622 +
14623 +       if (offset) {
14624 +               duprintf("Dropping non-first fragment.. FIXME\n");
14625 +               return 0;
14626 +       }
14627 +       
14628 +       if (skb_copy_bits(skb, skb->nh.iph->ihl*4, &sh, sizeof(sh)) < 0) {
14629 +               duprintf("Dropping evil TCP offset=0 tinygram.\n");
14630 +               *hotdrop = 1;
14631 +               return 0;
14632 +               }
14633 +       duprintf("spt: %d\tdpt: %d\n", ntohs(sh.source), ntohs(sh.dest));
14634 +
14635 +       return  SCCHECK(((ntohs(sh.source) >= info->spts[0]) 
14636 +                       && (ntohs(sh.source) <= info->spts[1])), 
14637 +                       IPT_SCTP_SRC_PORTS, info->flags, info->invflags)
14638 +               && SCCHECK(((ntohs(sh.dest) >= info->dpts[0]) 
14639 +                       && (ntohs(sh.dest) <= info->dpts[1])), 
14640 +                       IPT_SCTP_DEST_PORTS, info->flags, info->invflags)
14641 +               && SCCHECK(match_packet(skb, info->chunkmap, info->chunk_match_type,
14642 +                                       info->flag_info, info->flag_count, 
14643 +                                       hotdrop),
14644 +                          IPT_SCTP_CHUNK_TYPES, info->flags, info->invflags);
14645 +}
14646 +
14647 +static int
14648 +checkentry(const char *tablename,
14649 +          const struct ipt_ip *ip,
14650 +          void *matchinfo,
14651 +          unsigned int matchsize,
14652 +          unsigned int hook_mask)
14653 +{
14654 +       const struct ipt_sctp_info *info;
14655 +
14656 +       info = (const struct ipt_sctp_info *)matchinfo;
14657 +
14658 +       return ip->proto == IPPROTO_SCTP
14659 +               && !(ip->invflags & IPT_INV_PROTO)
14660 +               && matchsize == IPT_ALIGN(sizeof(struct ipt_sctp_info))
14661 +               && !(info->flags & ~IPT_SCTP_VALID_FLAGS)
14662 +               && !(info->invflags & ~IPT_SCTP_VALID_FLAGS)
14663 +               && !(info->invflags & ~info->flags)
14664 +               && ((!(info->flags & IPT_SCTP_CHUNK_TYPES)) || 
14665 +                       (info->chunk_match_type &
14666 +                               (SCTP_CHUNK_MATCH_ALL 
14667 +                               | SCTP_CHUNK_MATCH_ANY
14668 +                               | SCTP_CHUNK_MATCH_ONLY)));
14669 +}
14670 +
14671 +static struct ipt_match sctp_match = 
14672 +{ 
14673 +       .list = { NULL, NULL},
14674 +       .name = "sctp",
14675 +       .match = &match,
14676 +       .checkentry = &checkentry,
14677 +       .destroy = NULL,
14678 +       .me = THIS_MODULE
14679 +};
14680 +
14681 +static int __init init(void)
14682 +{
14683 +       return ipt_register_match(&sctp_match);
14684 +}
14685 +
14686 +static void __exit fini(void)
14687 +{
14688 +       ipt_unregister_match(&sctp_match);
14689 +}
14690 +
14691 +module_init(init);
14692 +module_exit(fini);
14693 +
14694 +MODULE_LICENSE("GPL");
14695 +MODULE_AUTHOR("Kiran Kumar Immidi");
14696 +MODULE_DESCRIPTION("Match for SCTP protocol packets");
14697 +
14698 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_string.c linux-2.6.7-rc3/net/ipv4/netfilter/ipt_string.c
14699 --- linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_string.c 1970-01-01 01:00:00.000000000 +0100
14700 +++ linux-2.6.7-rc3/net/ipv4/netfilter/ipt_string.c     2004-06-08 10:41:24.000000000 +0200
14701 @@ -0,0 +1,183 @@
14702 +/* Kernel module to match a string into a packet.
14703 + *
14704 + * Copyright (C) 2000 Emmanuel Roger  <winfield@freegates.be>
14705 + * 
14706 + * ChangeLog
14707 + *     24.03.2004: Eric Lauriault <elauri@lacitec.on.ca>
14708 + *             Initial 2.6 port
14709 + *     19.02.2002: Gianni Tedesco <gianni@ecsc.co.uk>
14710 + *             Fixed SMP re-entrancy problem using per-cpu data areas
14711 + *             for the skip/shift tables.
14712 + *     02.05.2001: Gianni Tedesco <gianni@ecsc.co.uk>
14713 + *             Fixed kernel panic, due to overrunning boyer moore string
14714 + *             tables. Also slightly tweaked heuristic for deciding what
14715 + *             search algo to use.
14716 + *     27.01.2001: Gianni Tedesco <gianni@ecsc.co.uk>
14717 + *             Implemented Boyer Moore Sublinear search algorithm
14718 + *             alongside the existing linear search based on memcmp().
14719 + *             Also a quick check to decide which method to use on a per
14720 + *             packet basis.
14721 + */
14722 +
14723 +#include <linux/smp.h>
14724 +#include <linux/percpu.h>
14725 +#include <linux/module.h>
14726 +#include <linux/skbuff.h>
14727 +#include <linux/file.h>
14728 +#include <net/sock.h>
14729 +
14730 +#include <linux/netfilter_ipv4/ip_tables.h>
14731 +#include <linux/netfilter_ipv4/ipt_string.h>
14732 +
14733 +MODULE_LICENSE("GPL");
14734 +
14735 +struct string_per_cpu {
14736 +       int skip[BM_MAX_HLEN];
14737 +       int shift[BM_MAX_HLEN];
14738 +       int len[BM_MAX_HLEN];
14739 +};
14740 +
14741 +static DEFINE_PER_CPU(struct string_per_cpu, bm_string_data);
14742 +
14743 +
14744 +/* Boyer Moore Sublinear string search - VERY FAST */
14745 +char *search_sublinear (char *needle, char *haystack, int needle_len, int haystack_len) 
14746 +{
14747 +       int M1, right_end, sk, sh;  
14748 +       int ended, j, i;
14749 +
14750 +       int *skip, *shift, *len;
14751 +       
14752 +       /* use data suitable for this CPU */
14753 +       shift=__get_cpu_var(bm_string_data).shift;
14754 +       skip=__get_cpu_var(bm_string_data).skip;
14755 +       len=__get_cpu_var(bm_string_data).len;
14756 +       
14757 +       /* Setup skip/shift tables */
14758 +       M1 = right_end = needle_len-1;
14759 +       for (i = 0; i < BM_MAX_HLEN; i++) skip[i] = needle_len;  
14760 +       for (i = 0; needle[i]; i++) skip[(int)needle[i]] = M1 - i;
14761 +
14762 +       for (i = 1; i < needle_len; i++) {   
14763 +               for (j = 0; j < needle_len && needle[M1 - j] == needle[M1 - i - j]; j++);  
14764 +               len[i] = j;  
14765 +       }  
14766 +
14767 +       shift[0] = 1;  
14768 +       for (i = 1; i < needle_len; i++) shift[i] = needle_len;  
14769 +       for (i = M1; i > 0; i--) shift[len[i]] = i;  
14770 +       ended = 0;  
14771 +       
14772 +       for (i = 0; i < needle_len; i++) {  
14773 +               if (len[i] == M1 - i) ended = i;  
14774 +               if (ended) shift[i] = ended;  
14775 +       }  
14776 +
14777 +       /* Do the search*/  
14778 +       while (right_end < haystack_len)
14779 +       {
14780 +               for (i = 0; i < needle_len && haystack[right_end - i] == needle[M1 - i]; i++);  
14781 +               if (i == needle_len) {
14782 +                       return haystack+(right_end - M1);
14783 +               }
14784 +               
14785 +               sk = skip[(int)haystack[right_end - i]];  
14786 +               sh = shift[i];
14787 +               right_end = max(right_end - i + sk, right_end + sh);  
14788 +       }
14789 +
14790 +       return NULL;
14791 +}  
14792 +
14793 +/* Linear string search based on memcmp() */
14794 +char *search_linear (char *needle, char *haystack, int needle_len, int haystack_len) 
14795 +{
14796 +       char *k = haystack + (haystack_len-needle_len);
14797 +       char *t = haystack;
14798 +       
14799 +       while ( t <= k ) {
14800 +               if (memcmp(t, needle, needle_len) == 0)
14801 +                       return t;
14802 +               t++;
14803 +       }
14804 +
14805 +       return NULL;
14806 +}
14807 +
14808 +static int
14809 +match(const struct sk_buff *skb,
14810 +      const struct net_device *in,
14811 +      const struct net_device *out,
14812 +      const void *matchinfo,
14813 +      int offset,
14814 +      int *hotdrop)
14815 +{
14816 +       const struct ipt_string_info *info = matchinfo;
14817 +       struct iphdr *ip = skb->nh.iph;
14818 +       int hlen, nlen;
14819 +       char *needle, *haystack;
14820 +       proc_ipt_search search=search_linear;
14821 +
14822 +       if ( !ip ) return 0;
14823 +
14824 +       /* get lenghts, and validate them */
14825 +       nlen=info->len;
14826 +       hlen=ntohs(ip->tot_len)-(ip->ihl*4);
14827 +       if ( nlen > hlen ) return 0;
14828 +
14829 +       needle=(char *)&info->string;
14830 +       haystack=(char *)ip+(ip->ihl*4);
14831 +
14832 +       /* The sublinear search comes in to its own
14833 +        * on the larger packets */
14834 +       if ( (hlen>IPT_STRING_HAYSTACK_THRESH) &&
14835 +               (nlen>IPT_STRING_NEEDLE_THRESH) ) {
14836 +               if ( hlen < BM_MAX_HLEN ) {
14837 +                       search=search_sublinear;
14838 +               }else{
14839 +                       if (net_ratelimit())
14840 +                               printk(KERN_INFO "ipt_string: Packet too big "
14841 +                                       "to attempt sublinear string search "
14842 +                                       "(%d bytes)\n", hlen );
14843 +               }
14844 +       }
14845 +       
14846 +    return ((search(needle, haystack, nlen, hlen)!=NULL) ^ info->invert);
14847 +}
14848 +
14849 +static int
14850 +checkentry(const char *tablename,
14851 +           const struct ipt_ip *ip,
14852 +           void *matchinfo,
14853 +           unsigned int matchsize,
14854 +           unsigned int hook_mask)
14855 +{
14856 +
14857 +       if (matchsize != IPT_ALIGN(sizeof(struct ipt_string_info)))
14858 +               return 0;
14859 +
14860 +       return 1;
14861 +}
14862 +
14863 +static struct ipt_match string_match = {
14864 +    .name = "string",
14865 +    .match = &match,
14866 +    .checkentry = &checkentry,
14867 +    .me = THIS_MODULE
14868 +};
14869 +
14870 +
14871 +static int __init init(void)
14872 +{
14873 +       return ipt_register_match(&string_match);
14874 +}
14875 +
14876 +static void __exit fini(void)
14877 +{
14878 +       ipt_unregister_match(&string_match);
14879 +}
14880 +
14881 +module_init(init);
14882 +module_exit(fini);
14883 +
14884 +
14885 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_time.c linux-2.6.7-rc3/net/ipv4/netfilter/ipt_time.c
14886 --- linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_time.c   1970-01-01 01:00:00.000000000 +0100
14887 +++ linux-2.6.7-rc3/net/ipv4/netfilter/ipt_time.c       2004-06-08 10:32:31.000000000 +0200
14888 @@ -0,0 +1,189 @@
14889 +/*
14890 +  This is a module which is used for time matching
14891 +  It is using some modified code from dietlibc (localtime() function)
14892 +  that you can find at http://www.fefe.de/dietlibc/
14893 +  This file is distributed under the terms of the GNU General Public
14894 +  License (GPL). Copies of the GPL can be obtained from: ftp://prep.ai.mit.edu/pub/gnu/GPL
14895 +  2001-05-04 Fabrice MARIE <fabrice@netfilter.org> : initial development.
14896 +  2001-21-05 Fabrice MARIE <fabrice@netfilter.org> : bug fix in the match code,
14897 +     thanks to "Zeng Yu" <zengy@capitel.com.cn> for bug report.
14898 +  2001-26-09 Fabrice MARIE <fabrice@netfilter.org> : force the match to be in LOCAL_IN or PRE_ROUTING only.
14899 +  2001-30-11 Fabrice : added the possibility to use the match in FORWARD/OUTPUT with a little hack,
14900 +     added Nguyen Dang Phuoc Dong <dongnd@tlnet.com.vn> patch to support timezones.
14901 +  2004-05-02 Fabrice : added support for date matching, from an idea of Fabien COELHO.
14902 +*/
14903 +
14904 +#include <linux/module.h>
14905 +#include <linux/skbuff.h>
14906 +#include <linux/netfilter_ipv4/ip_tables.h>
14907 +#include <linux/netfilter_ipv4/ipt_time.h>
14908 +#include <linux/time.h>
14909 +
14910 +MODULE_AUTHOR("Fabrice MARIE <fabrice@netfilter.org>");
14911 +MODULE_DESCRIPTION("Match arrival timestamp/date");
14912 +MODULE_LICENSE("GPL");
14913 +
14914 +struct tm
14915 +{
14916 +       int tm_sec;                   /* Seconds.     [0-60] (1 leap second) */
14917 +       int tm_min;                   /* Minutes.     [0-59] */
14918 +       int tm_hour;                  /* Hours.       [0-23] */
14919 +       int tm_mday;                  /* Day.         [1-31] */
14920 +       int tm_mon;                   /* Month.       [0-11] */
14921 +       int tm_year;                  /* Year - 1900.  */
14922 +       int tm_wday;                  /* Day of week. [0-6] */
14923 +       int tm_yday;                  /* Days in year.[0-365] */
14924 +       int tm_isdst;                 /* DST.         [-1/0/1]*/
14925 +
14926 +       long int tm_gmtoff;           /* we don't care, we count from GMT */
14927 +       const char *tm_zone;          /* we don't care, we count from GMT */
14928 +};
14929 +
14930 +void
14931 +localtime(const time_t *timepr, struct tm *r);
14932 +
14933 +static int
14934 +match(const struct sk_buff *skb,
14935 +      const struct net_device *in,
14936 +      const struct net_device *out,
14937 +      const void *matchinfo,
14938 +      int offset,
14939 +      const void *hdr,
14940 +      u_int16_t datalen,
14941 +      int *hotdrop)
14942 +{
14943 +       const struct ipt_time_info *info = matchinfo;   /* match info for rule */
14944 +       struct tm currenttime;                          /* time human readable */
14945 +       u_int8_t days_of_week[7] = {64, 32, 16, 8, 4, 2, 1};
14946 +       u_int16_t packet_time;
14947 +       struct timeval kerneltimeval;
14948 +       time_t packet_local_time;
14949 +
14950 +       /* if kerneltime=1, we don't read the skb->timestamp but kernel time instead */
14951 +       if (info->kerneltime)
14952 +       {
14953 +               do_gettimeofday(&kerneltimeval);
14954 +               packet_local_time = kerneltimeval.tv_sec;
14955 +       }
14956 +       else
14957 +               packet_local_time = skb->stamp.tv_sec;
14958 +
14959 +       /* First we make sure we are in the date start-stop boundaries */
14960 +       if ((packet_local_time < info->date_start) || (packet_local_time > info->date_stop))
14961 +               return 0; /* We are outside the date boundaries */
14962 +
14963 +       /* Transform the timestamp of the packet, in a human readable form */
14964 +       localtime(&packet_local_time, &currenttime);
14965 +
14966 +       /* check if we match this timestamp, we start by the days... */
14967 +       if ((days_of_week[currenttime.tm_wday] & info->days_match) != days_of_week[currenttime.tm_wday])
14968 +               return 0; /* the day doesn't match */
14969 +
14970 +       /* ... check the time now */
14971 +       packet_time = (currenttime.tm_hour * 60) + currenttime.tm_min;
14972 +       if ((packet_time < info->time_start) || (packet_time > info->time_stop))
14973 +               return 0;
14974 +
14975 +       /* here we match ! */
14976 +       return 1;
14977 +}
14978 +
14979 +static int
14980 +checkentry(const char *tablename,
14981 +           const struct ipt_ip *ip,
14982 +           void *matchinfo,
14983 +           unsigned int matchsize,
14984 +           unsigned int hook_mask)
14985 +{
14986 +       struct ipt_time_info *info = matchinfo;   /* match info for rule */
14987 +
14988 +       /* First, check that we are in the correct hooks */
14989 +       if (hook_mask
14990 +            & ~((1 << NF_IP_PRE_ROUTING) | (1 << NF_IP_LOCAL_IN) | (1 << NF_IP_FORWARD) | (1 << NF_IP_LOCAL_OUT)))
14991 +       {
14992 +               printk("ipt_time: error, only valid for PRE_ROUTING, LOCAL_IN, FORWARD and OUTPUT)\n");
14993 +               return 0;
14994 +       }
14995 +       /* we use the kerneltime if we are in forward or output */
14996 +       info->kerneltime = 1;
14997 +       if (hook_mask & ~((1 << NF_IP_FORWARD) | (1 << NF_IP_LOCAL_OUT))) 
14998 +               /* we use the skb time */
14999 +               info->kerneltime = 0;
15000 +
15001 +       /* Check the size */
15002 +       if (matchsize != IPT_ALIGN(sizeof(struct ipt_time_info)))
15003 +               return 0;
15004 +       /* Now check the coherence of the data ... */
15005 +       if ((info->time_start > 1439) ||        /* 23*60+59 = 1439*/
15006 +           (info->time_stop  > 1439))
15007 +       {
15008 +               printk(KERN_WARNING "ipt_time: invalid argument\n");
15009 +               return 0;
15010 +       }
15011 +
15012 +       return 1;
15013 +}
15014 +
15015 +static struct ipt_match time_match
15016 += { { NULL, NULL }, "time", &match, &checkentry, NULL, THIS_MODULE };
15017 +
15018 +static int __init init(void)
15019 +{
15020 +       printk("ipt_time loading\n");
15021 +       return ipt_register_match(&time_match);
15022 +}
15023 +
15024 +static void __exit fini(void)
15025 +{
15026 +       ipt_unregister_match(&time_match);
15027 +       printk("ipt_time unloaded\n");
15028 +}
15029 +
15030 +module_init(init);
15031 +module_exit(fini);
15032 +
15033 +
15034 +/* The part below is borowed and modified from dietlibc */
15035 +
15036 +/* seconds per day */
15037 +#define SPD 24*60*60
15038 +
15039 +void
15040 +localtime(const time_t *timepr, struct tm *r) {
15041 +       time_t i;
15042 +       time_t timep;
15043 +       extern struct timezone sys_tz;
15044 +       const unsigned int __spm[12] =
15045 +               { 0,
15046 +                 (31),
15047 +                 (31+28),
15048 +                 (31+28+31),
15049 +                 (31+28+31+30),
15050 +                 (31+28+31+30+31),
15051 +                 (31+28+31+30+31+30),
15052 +                 (31+28+31+30+31+30+31),
15053 +                 (31+28+31+30+31+30+31+31),
15054 +                 (31+28+31+30+31+30+31+31+30),
15055 +                 (31+28+31+30+31+30+31+31+30+31),
15056 +                 (31+28+31+30+31+30+31+31+30+31+30),
15057 +               };
15058 +       register time_t work;
15059 +
15060 +       timep = (*timepr) - (sys_tz.tz_minuteswest * 60);
15061 +       work=timep%(SPD);
15062 +       r->tm_sec=work%60; work/=60;
15063 +       r->tm_min=work%60; r->tm_hour=work/60;
15064 +       work=timep/(SPD);
15065 +       r->tm_wday=(4+work)%7;
15066 +       for (i=1970; ; ++i) {
15067 +               register time_t k= (!(i%4) && ((i%100) || !(i%400)))?366:365;
15068 +               if (work>k)
15069 +                       work-=k;
15070 +               else
15071 +                       break;
15072 +       }
15073 +       r->tm_year=i-1900;
15074 +       for (i=11; i && __spm[i]>work; --i) ;
15075 +       r->tm_mon=i;
15076 +       r->tm_mday=work-__spm[i]+1;
15077 +}
15078 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_u32.c linux-2.6.7-rc3/net/ipv4/netfilter/ipt_u32.c
15079 --- linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_u32.c    1970-01-01 01:00:00.000000000 +0100
15080 +++ linux-2.6.7-rc3/net/ipv4/netfilter/ipt_u32.c        2004-06-08 10:32:32.000000000 +0200
15081 @@ -0,0 +1,211 @@
15082 +/* Kernel module to match u32 packet content. */
15083 +
15084 +/* 
15085 +U32 tests whether quantities of up to 4 bytes extracted from a packet 
15086 +have specified values.  The specification of what to extract is general 
15087 +enough to find data at given offsets from tcp headers or payloads.
15088 +
15089 + --u32 tests
15090 + The argument amounts to a program in a small language described below.
15091 + tests := location = value |  tests && location = value
15092 + value := range | value , range
15093 + range := number | number : number
15094 +  a single number, n, is interpreted the same as n:n
15095 +  n:m is interpreted as the range of numbers >=n and <=m
15096 + location := number | location operator number
15097 + operator := & | << | >> | @
15098 +
15099 + The operators &, <<, >>, && mean the same as in c.  The = is really a set
15100 + membership operator and the value syntax describes a set.  The @ operator
15101 + is what allows moving to the next header and is described further below.
15102 +
15103 + *** Until I can find out how to avoid it, there are some artificial limits
15104 + on the size of the tests:
15105 + - no more than 10 ='s (and 9 &&'s) in the u32 argument
15106 + - no more than 10 ranges (and 9 commas) per value
15107 + - no more than 10 numbers (and 9 operators) per location
15108 +
15109 + To describe the meaning of location, imagine the following machine that
15110 + interprets it.  There are three registers:
15111 +  A is of type char*, initially the address of the IP header
15112 +  B and C are unsigned 32 bit integers, initially zero
15113 +
15114 +  The instructions are:
15115 +   number      B = number;
15116 +               C = (*(A+B)<<24)+(*(A+B+1)<<16)+(*(A+B+2)<<8)+*(A+B+3)
15117 +   &number     C = C&number
15118 +   <<number    C = C<<number
15119 +   >>number    C = C>>number
15120 +   @number     A = A+C; then do the instruction number
15121 +  Any access of memory outside [skb->head,skb->end] causes the match to fail.
15122 +  Otherwise the result of the computation is the final value of C.
15123 +
15124 + Whitespace is allowed but not required in the tests.
15125 + However the characters that do occur there are likely to require
15126 + shell quoting, so it's a good idea to enclose the arguments in quotes.
15127 +
15128 +Example:
15129 + match IP packets with total length >= 256
15130 + The IP header contains a total length field in bytes 2-3.
15131 + --u32 "0&0xFFFF=0x100:0xFFFF" 
15132 + read bytes 0-3
15133 + AND that with FFFF (giving bytes 2-3),
15134 + and test whether that's in the range [0x100:0xFFFF]
15135 +
15136 +Example: (more realistic, hence more complicated)
15137 + match icmp packets with icmp type 0
15138 + First test that it's an icmp packet, true iff byte 9 (protocol) = 1
15139 + --u32 "6&0xFF=1 && ...
15140 + read bytes 6-9, use & to throw away bytes 6-8 and compare the result to 1
15141 + Next test that it's not a fragment.
15142 +  (If so it might be part of such a packet but we can't always tell.)
15143 +  n.b. This test is generally needed if you want to match anything
15144 +  beyond the IP header.
15145 + The last 6 bits of byte 6 and all of byte 7 are 0 iff this is a complete
15146 + packet (not a fragment).  Alternatively, you can allow first fragments
15147 + by only testing the last 5 bits of byte 6.
15148 + ... 4&0x3FFF=0 && ...
15149 + Last test: the first byte past the IP header (the type) is 0
15150 + This is where we have to use the @syntax.  The length of the IP header
15151 + (IHL) in 32 bit words is stored in the right half of byte 0 of the
15152 + IP header itself.
15153 + ... 0>>22&0x3C@0>>24=0"
15154 + The first 0 means read bytes 0-3,
15155 + >>22 means shift that 22 bits to the right.  Shifting 24 bits would give
15156 +   the first byte, so only 22 bits is four times that plus a few more bits.
15157 + &3C then eliminates the two extra bits on the right and the first four 
15158 + bits of the first byte.
15159 + For instance, if IHL=5 then the IP header is 20 (4 x 5) bytes long.
15160 + In this case bytes 0-1 are (in binary) xxxx0101 yyzzzzzz, 
15161 + >>22 gives the 10 bit value xxxx0101yy and &3C gives 010100.
15162 + @ means to use this number as a new offset into the packet, and read
15163 + four bytes starting from there.  This is the first 4 bytes of the icmp
15164 + payload, of which byte 0 is the icmp type.  Therefore we simply shift
15165 + the value 24 to the right to throw out all but the first byte and compare
15166 + the result with 0.
15167 +
15168 +Example: 
15169 + tcp payload bytes 8-12 is any of 1, 2, 5 or 8
15170 + First we test that the packet is a tcp packet (similar to icmp).
15171 + --u32 "6&0xFF=6 && ...
15172 + Next, test that it's not a fragment (same as above).
15173 + ... 0>>22&0x3C@12>>26&0x3C@8=1,2,5,8"
15174 + 0>>22&3C as above computes the number of bytes in the IP header.
15175 + @ makes this the new offset into the packet, which is the start of the
15176 + tcp header.  The length of the tcp header (again in 32 bit words) is
15177 + the left half of byte 12 of the tcp header.  The 12>>26&3C
15178 + computes this length in bytes (similar to the IP header before).
15179 + @ makes this the new offset, which is the start of the tcp payload.
15180 + Finally 8 reads bytes 8-12 of the payload and = checks whether the
15181 + result is any of 1, 2, 5 or 8
15182 +*/
15183 +
15184 +#include <linux/module.h>
15185 +#include <linux/skbuff.h>
15186 +
15187 +#include <linux/netfilter_ipv4/ipt_u32.h>
15188 +#include <linux/netfilter_ipv4/ip_tables.h>
15189 +
15190 +/* #include <asm-i386/timex.h> for timing */
15191 +
15192 +MODULE_AUTHOR("Don Cohen <don@isis.cs3-inc.com>");
15193 +MODULE_DESCRIPTION("IP tables u32 matching module");
15194 +MODULE_LICENSE("GPL");
15195 +
15196 +static int
15197 +match(const struct sk_buff *skb,
15198 +      const struct net_device *in,
15199 +      const struct net_device *out,
15200 +      const void *matchinfo,
15201 +      int offset,
15202 +      const void *hdr,
15203 +      u_int16_t datalen,
15204 +      int *hotdrop)
15205 +{
15206 +       const struct ipt_u32 *data = matchinfo;
15207 +       int testind, i;
15208 +       unsigned char* origbase = (char*)skb->nh.iph;
15209 +       unsigned char* base = origbase;
15210 +       unsigned char* head = skb->head;
15211 +       unsigned char* end = skb->end;
15212 +       int nnums, nvals;
15213 +       u_int32_t pos, val;
15214 +       /* unsigned long long cycles1, cycles2, cycles3, cycles4;
15215 +          cycles1 = get_cycles(); */
15216 +
15217 +       for (testind=0; testind < data->ntests; testind++) {
15218 +               base = origbase; /* reset for each test */
15219 +               pos = data->tests[testind].location[0].number;
15220 +               if (base+pos+3 > end || base+pos < head) 
15221 +                       return 0;
15222 +               val = (base[pos]<<24) + (base[pos+1]<<16) +
15223 +                       (base[pos+2]<<8) + base[pos+3];
15224 +               nnums = data->tests[testind].nnums;
15225 +               for (i=1; i < nnums; i++) {
15226 +                       u_int32_t number = data->tests[testind].location[i].number;
15227 +                       switch (data->tests[testind].location[i].nextop) {
15228 +                       case IPT_U32_AND: 
15229 +                               val = val & number; 
15230 +                               break;
15231 +                       case IPT_U32_LEFTSH: 
15232 +                               val = val << number;
15233 +                               break;
15234 +                       case IPT_U32_RIGHTSH: 
15235 +                               val = val >> number; 
15236 +                               break;
15237 +                       case IPT_U32_AT:
15238 +                               base = base + val;
15239 +                               pos = number;
15240 +                               if (base+pos+3 > end || base+pos < head) 
15241 +                                       return 0;
15242 +                               val = (base[pos]<<24) + (base[pos+1]<<16) +
15243 +                                       (base[pos+2]<<8) + base[pos+3];
15244 +                               break;
15245 +                       }
15246 +               }
15247 +               nvals = data->tests[testind].nvalues;
15248 +               for (i=0; i < nvals; i++) {
15249 +                       if ((data->tests[testind].value[i].min <= val) &&
15250 +                           (val <= data->tests[testind].value[i].max)) {
15251 +                               break;
15252 +                       }
15253 +               }
15254 +               if (i >= data->tests[testind].nvalues) {
15255 +                       /* cycles2 = get_cycles(); 
15256 +                          printk("failed %d in %d cycles\n", testind, 
15257 +                                 cycles2-cycles1); */
15258 +                       return 0;
15259 +               }
15260 +       }
15261 +       /* cycles2 = get_cycles();
15262 +          printk("succeeded in %d cycles\n", cycles2-cycles1); */
15263 +       return 1;
15264 +}
15265 +
15266 +static int
15267 +checkentry(const char *tablename,
15268 +           const struct ipt_ip *ip,
15269 +           void *matchinfo,
15270 +           unsigned int matchsize,
15271 +           unsigned int hook_mask)
15272 +{
15273 +       if (matchsize != IPT_ALIGN(sizeof(struct ipt_u32)))
15274 +               return 0;
15275 +       return 1;
15276 +}
15277 +
15278 +static struct ipt_match u32_match
15279 += { { NULL, NULL }, "u32", &match, &checkentry, NULL, THIS_MODULE };
15280 +
15281 +static int __init init(void)
15282 +{
15283 +       return ipt_register_match(&u32_match);
15284 +}
15285 +
15286 +static void __exit fini(void)
15287 +{
15288 +       ipt_unregister_match(&u32_match);
15289 +}
15290 +
15291 +module_init(init);
15292 +module_exit(fini);
15293 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_unclean.c linux-2.6.7-rc3/net/ipv4/netfilter/ipt_unclean.c
15294 --- linux-2.6.7-rc3.org/net/ipv4/netfilter/ipt_unclean.c        1970-01-01 01:00:00.000000000 +0100
15295 +++ linux-2.6.7-rc3/net/ipv4/netfilter/ipt_unclean.c    2004-06-08 10:41:16.000000000 +0200
15296 @@ -0,0 +1,604 @@
15297 +/* Kernel module to match suspect packets. */
15298 +#include <linux/module.h>
15299 +#include <linux/skbuff.h>
15300 +#include <net/ip.h>
15301 +#include <linux/udp.h>
15302 +#include <linux/tcp.h>
15303 +#include <linux/icmp.h>
15304 +#include <net/checksum.h>
15305 +
15306 +#include <linux/netfilter_ipv4/ip_tables.h>
15307 +
15308 +#define limpk(format, args...)                                          \
15309 +do {                                                                    \
15310 +       if (net_ratelimit())                                             \
15311 +               printk("ipt_unclean: %s" format,                         \
15312 +                      embedded ? "(embedded packet) " : "" , ## args);  \
15313 +} while(0)
15314 +
15315 +enum icmp_error_status
15316 +{
15317 +       ICMP_MAY_BE_ERROR,
15318 +       ICMP_IS_ERROR,
15319 +       ICMP_NOT_ERROR
15320 +};
15321 +
15322 +struct icmp_info
15323 +{
15324 +       size_t min_len, max_len;
15325 +       enum icmp_error_status err;
15326 +       u_int8_t min_code, max_code;
15327 +};
15328 +
15329 +static int
15330 +check_ip(struct iphdr *iph, size_t length, int embedded);
15331 +
15332 +/* ICMP-specific checks. */
15333 +static int
15334 +check_icmp(const struct icmphdr *icmph,
15335 +          u_int16_t datalen,
15336 +          unsigned int offset,
15337 +          int more_frags,
15338 +          int embedded)
15339 +{
15340 +       static struct icmp_info info[]
15341 +               = { [ICMP_ECHOREPLY]
15342 +                   = { 8, 65536, ICMP_NOT_ERROR, 0, 0 },
15343 +                   [ICMP_DEST_UNREACH]
15344 +                   = { 8 + 28, 65536, ICMP_IS_ERROR, 0, 15 },
15345 +                   [ICMP_SOURCE_QUENCH]
15346 +                   = { 8 + 28, 65536, ICMP_IS_ERROR, 0, 0 },
15347 +                   [ICMP_REDIRECT]
15348 +                   = { 8 + 28, 65536, ICMP_IS_ERROR, 0, 3 },
15349 +                   [ICMP_ECHO]
15350 +                   = { 8, 65536, ICMP_NOT_ERROR, 0, 0  },
15351 +                   /* Router advertisement. */
15352 +                   [9]
15353 +                   = { 8, 8 + 255 * 8, ICMP_NOT_ERROR, 0, 0 },
15354 +                   /* Router solicitation. */
15355 +                   [10]
15356 +                   = { 8, 8, ICMP_NOT_ERROR, 0, 0 },
15357 +                   [ICMP_TIME_EXCEEDED]
15358 +                   = { 8 + 28, 65536, ICMP_IS_ERROR, 0, 1  },
15359 +                   [ICMP_PARAMETERPROB]
15360 +                   = { 8 + 28, 65536, ICMP_IS_ERROR, 0, 1 },
15361 +                   [ICMP_TIMESTAMP]
15362 +                   = { 20, 20, ICMP_NOT_ERROR, 0, 0 },
15363 +                   [ICMP_TIMESTAMPREPLY]
15364 +                   = { 20, 20, ICMP_NOT_ERROR, 0, 0 },
15365 +                   [ICMP_INFO_REQUEST]
15366 +                   = { 8, 65536, ICMP_NOT_ERROR, 0, 0 },
15367 +                   [ICMP_INFO_REPLY]
15368 +                   = { 8, 65536, ICMP_NOT_ERROR, 0, 0 },
15369 +                   [ICMP_ADDRESS]
15370 +                   = { 12, 12, ICMP_NOT_ERROR, 0, 0 },
15371 +                   [ICMP_ADDRESSREPLY]
15372 +                   = { 12, 12, ICMP_NOT_ERROR, 0, 0 } };
15373 +
15374 +       /* Can't do anything if it's a fragment. */
15375 +       if (offset)
15376 +               return 1;
15377 +
15378 +       /* Must cover type and code. */
15379 +       if (datalen < 2) {
15380 +               limpk("ICMP len=%u too short\n", datalen);
15381 +               return 0;
15382 +       }
15383 +
15384 +       /* If not embedded. */
15385 +       if (!embedded) {
15386 +               /* Bad checksum?  Don't print, just ignore. */
15387 +               if (!more_frags
15388 +                   && ip_compute_csum((unsigned char *) icmph, datalen) != 0)
15389 +                       return 0;
15390 +
15391 +               /* CHECK: Truncated ICMP (even if first fragment). */
15392 +               if (icmph->type < sizeof(info)/sizeof(struct icmp_info)
15393 +                   && info[icmph->type].min_len != 0
15394 +                   && datalen < info[icmph->type].min_len) {
15395 +                       limpk("ICMP type %u len %u too short\n",
15396 +                             icmph->type, datalen);
15397 +                       return 0;
15398 +               }
15399 +
15400 +               /* CHECK: Check within known error ICMPs. */
15401 +               if (icmph->type < sizeof(info)/sizeof(struct icmp_info)
15402 +                   && info[icmph->type].err == ICMP_IS_ERROR) {
15403 +                       /* CHECK: Embedded packet must be at least
15404 +                          length of iph + 8 bytes. */
15405 +                       struct iphdr *inner = (void *)icmph + 8;
15406 +
15407 +                       /* datalen > 8 since all ICMP_IS_ERROR types
15408 +                           have min length > 8 */
15409 +                       if (datalen - 8 < sizeof(struct iphdr)) {
15410 +                               limpk("ICMP error internal way too short\n");
15411 +                               return 0;
15412 +                       }
15413 +                       if (datalen - 8 < inner->ihl*4 + 8) {
15414 +                               limpk("ICMP error internal too short\n");
15415 +                               return 0;
15416 +                       }
15417 +                       if (!check_ip(inner, datalen - 8, 1))
15418 +                               return 0;
15419 +               }
15420 +       } else {
15421 +               /* CHECK: Can't embed ICMP unless known non-error. */
15422 +               if (icmph->type >= sizeof(info)/sizeof(struct icmp_info)
15423 +                   || info[icmph->type].err != ICMP_NOT_ERROR) {
15424 +                       limpk("ICMP type %u not embeddable\n",
15425 +                             icmph->type);
15426 +                       return 0;
15427 +               }
15428 +       }
15429 +
15430 +       /* CHECK: Invalid ICMP codes. */
15431 +       if (icmph->type < sizeof(info)/sizeof(struct icmp_info)
15432 +           && (icmph->code < info[icmph->type].min_code
15433 +               || icmph->code > info[icmph->type].max_code)) {
15434 +               limpk("ICMP type=%u code=%u\n",
15435 +                     icmph->type, icmph->code);
15436 +               return 0;
15437 +       }
15438 +
15439 +       /* CHECK: Above maximum length. */
15440 +       if (icmph->type < sizeof(info)/sizeof(struct icmp_info)
15441 +           && info[icmph->type].max_len != 0
15442 +           && datalen > info[icmph->type].max_len) {
15443 +               limpk("ICMP type=%u too long: %u bytes\n",
15444 +                     icmph->type, datalen);
15445 +               return 0;
15446 +       }
15447 +
15448 +       switch (icmph->type) {
15449 +       case ICMP_PARAMETERPROB: {
15450 +               /* CHECK: Problem param must be within error packet's
15451 +                * IP header. */
15452 +               struct iphdr *iph = (void *)icmph + 8;
15453 +               u_int32_t arg = ntohl(icmph->un.gateway);
15454 +
15455 +               if (icmph->code == 0) {
15456 +                       /* Code 0 means that upper 8 bits is pointer
15457 +                           to problem. */
15458 +                       if ((arg >> 24) >= iph->ihl*4) {
15459 +                               limpk("ICMP PARAMETERPROB ptr = %u\n",
15460 +                                     ntohl(icmph->un.gateway) >> 24);
15461 +                               return 0;
15462 +                       }
15463 +                       arg &= 0x00FFFFFF;
15464 +               }
15465 +
15466 +               /* CHECK: Rest must be zero. */
15467 +               if (arg) {
15468 +                       limpk("ICMP PARAMETERPROB nonzero arg = %u\n",
15469 +                             arg);
15470 +                       return 0;
15471 +               }
15472 +               break;
15473 +       }
15474 +
15475 +       case ICMP_TIME_EXCEEDED:
15476 +       case ICMP_SOURCE_QUENCH:
15477 +               /* CHECK: Unused must be zero. */
15478 +               if (icmph->un.gateway != 0) {
15479 +                       limpk("ICMP type=%u unused = %u\n",
15480 +                             icmph->type, ntohl(icmph->un.gateway));
15481 +                       return 0;
15482 +               }
15483 +               break;
15484 +       }
15485 +
15486 +       return 1;
15487 +}
15488 +
15489 +/* UDP-specific checks. */
15490 +static int
15491 +check_udp(const struct iphdr *iph,
15492 +         const struct udphdr *udph,
15493 +         u_int16_t datalen,
15494 +         unsigned int offset,
15495 +         int more_frags,
15496 +         int embedded)
15497 +{
15498 +       /* Can't do anything if it's a fragment. */
15499 +       if (offset)
15500 +               return 1;
15501 +
15502 +       /* CHECK: Must cover UDP header. */
15503 +       if (datalen < sizeof(struct udphdr)) {
15504 +               limpk("UDP len=%u too short\n", datalen);
15505 +               return 0;
15506 +       }
15507 +
15508 +       /* Bad checksum?  Don't print, just say it's unclean. */
15509 +       /* FIXME: SRC ROUTE packets won't match checksum --RR */
15510 +       if (!more_frags && !embedded && udph->check
15511 +           && csum_tcpudp_magic(iph->saddr, iph->daddr, datalen, IPPROTO_UDP,
15512 +                                csum_partial((char *)udph, datalen, 0)) != 0)
15513 +               return 0;
15514 +
15515 +       /* CHECK: Destination port can't be zero. */
15516 +       if (!udph->dest) {
15517 +               limpk("UDP zero destination port\n");
15518 +               return 0;
15519 +       }
15520 +
15521 +       if (!more_frags) {
15522 +               if (!embedded) {
15523 +                       /* CHECK: UDP length must match. */
15524 +                       if (ntohs(udph->len) != datalen) {
15525 +                               limpk("UDP len too short %u vs %u\n",
15526 +                                     ntohs(udph->len), datalen);
15527 +                               return 0;
15528 +                       }
15529 +               } else {
15530 +                       /* CHECK: UDP length be >= this truncated pkt. */
15531 +                       if (ntohs(udph->len) < datalen) {
15532 +                               limpk("UDP len too long %u vs %u\n",
15533 +                                     ntohs(udph->len), datalen);
15534 +                               return 0;
15535 +                       }
15536 +               }
15537 +       } else {
15538 +               /* CHECK: UDP length must be > this frag's length. */
15539 +               if (ntohs(udph->len) <= datalen) {
15540 +                       limpk("UDP fragment len too short %u vs %u\n",
15541 +                             ntohs(udph->len), datalen);
15542 +                       return 0;
15543 +               }
15544 +       }
15545 +
15546 +       return 1;
15547 +}
15548 +
15549 +#define        TH_FIN  0x01
15550 +#define        TH_SYN  0x02
15551 +#define        TH_RST  0x04
15552 +#define        TH_PUSH 0x08
15553 +#define        TH_ACK  0x10
15554 +#define        TH_URG  0x20
15555 +#define        TH_ECE  0x40
15556 +#define        TH_CWR  0x80
15557 +
15558 +/* table of valid flag combinations - ECE and CWR are always valid */
15559 +static u8 tcp_valid_flags[(TH_FIN|TH_SYN|TH_RST|TH_PUSH|TH_ACK|TH_URG) + 1] =
15560 +{
15561 +       [TH_SYN]                        = 1,
15562 +       [TH_SYN|TH_ACK]                 = 1,
15563 +       [TH_RST]                        = 1,
15564 +       [TH_RST|TH_ACK]                 = 1,
15565 +       [TH_RST|TH_ACK|TH_PUSH]         = 1,
15566 +       [TH_FIN|TH_ACK]                 = 1,
15567 +       [TH_ACK]                        = 1,
15568 +       [TH_ACK|TH_PUSH]                = 1,
15569 +       [TH_ACK|TH_URG]                 = 1,
15570 +       [TH_ACK|TH_URG|TH_PUSH]         = 1,
15571 +       [TH_FIN|TH_ACK|TH_PUSH]         = 1,
15572 +       [TH_FIN|TH_ACK|TH_URG]          = 1,
15573 +       [TH_FIN|TH_ACK|TH_URG|TH_PUSH]  = 1
15574 +};
15575 +
15576 +/* TCP-specific checks. */
15577 +static int
15578 +check_tcp(const struct iphdr *iph,
15579 +         const struct tcphdr *tcph,
15580 +         u_int16_t datalen,
15581 +         unsigned int offset,
15582 +         int more_frags,
15583 +         int embedded)
15584 +{
15585 +       u_int8_t *opt = (u_int8_t *)tcph;
15586 +       u_int8_t *endhdr = (u_int8_t *)tcph + tcph->doff * 4;
15587 +       u_int8_t tcpflags;
15588 +       int end_of_options = 0;
15589 +       size_t i;
15590 +
15591 +       /* CHECK: Can't have offset=1: used to override TCP syn-checks. */
15592 +       /* In fact, this is caught below (offset < 516). */
15593 +
15594 +       /* Can't do anything if it's a fragment. */
15595 +       if (offset)
15596 +               return 1;
15597 +
15598 +       /* CHECK: Smaller than minimal TCP hdr. */
15599 +       if (datalen < sizeof(struct tcphdr)) {
15600 +               if (!embedded) {
15601 +                       limpk("Packet length %u < TCP header.\n", datalen);
15602 +                       return 0;
15603 +               }
15604 +               /* Must have ports available (datalen >= 8), from
15605 +                   check_icmp which set embedded = 1 */
15606 +               /* CHECK: TCP ports inside ICMP error */
15607 +               if (!tcph->source || !tcph->dest) {
15608 +                       limpk("Zero TCP ports %u/%u.\n",
15609 +                             htons(tcph->source), htons(tcph->dest));
15610 +                       return 0;
15611 +               }
15612 +               return 1;
15613 +       }
15614 +
15615 +       /* CHECK: Smaller than actual TCP hdr. */
15616 +       if (datalen < tcph->doff * 4) {
15617 +               if (!embedded) {
15618 +                       limpk("Packet length %u < actual TCP header.\n",
15619 +                             datalen);
15620 +                       return 0;
15621 +               } else
15622 +                       return 1;
15623 +       }
15624 +
15625 +       /* Bad checksum?  Don't print, just say it's unclean. */
15626 +       /* FIXME: SRC ROUTE packets won't match checksum --RR */
15627 +       if (!more_frags && !embedded
15628 +           && csum_tcpudp_magic(iph->saddr, iph->daddr, datalen, IPPROTO_TCP,
15629 +                                csum_partial((char *)tcph, datalen, 0)) != 0)
15630 +               return 0;
15631 +
15632 +       /* CHECK: TCP ports non-zero */
15633 +       if (!tcph->source || !tcph->dest) {
15634 +               limpk("Zero TCP ports %u/%u.\n",
15635 +                     htons(tcph->source), htons(tcph->dest));
15636 +               return 0;
15637 +       }
15638 +
15639 +       /* CHECK: TCP reserved bits zero. */
15640 +       if(tcp_flag_word(tcph) & TCP_RESERVED_BITS) {
15641 +               limpk("TCP reserved bits not zero\n");
15642 +               return 0;
15643 +       }
15644 +
15645 +       /* CHECK: TCP flags. */
15646 +       tcpflags = (((u_int8_t *)tcph)[13] & ~(TH_ECE|TH_CWR));
15647 +       if (!tcp_valid_flags[tcpflags]) {
15648 +               limpk("TCP flags bad: %u\n", tcpflags);
15649 +               return 0;
15650 +       }
15651 +
15652 +       for (i = sizeof(struct tcphdr); i < tcph->doff * 4; ) {
15653 +               switch (opt[i]) {
15654 +               case 0:
15655 +                       end_of_options = 1;
15656 +                       i++;
15657 +                       break;
15658 +               case 1:
15659 +                       i++;
15660 +                       break;
15661 +               default:
15662 +                       /* CHECK: options after EOO. */
15663 +                       if (end_of_options) {
15664 +                               limpk("TCP option %u after end\n",
15665 +                                     opt[i]);
15666 +                               return 0;
15667 +                       }
15668 +                       /* CHECK: options at tail. */
15669 +                       else if (i+1 >= tcph->doff * 4) {
15670 +                               limpk("TCP option %u at tail\n",
15671 +                                     opt[i]);
15672 +                               return 0;
15673 +                       }
15674 +                       /* CHECK: zero-length options. */
15675 +                       else if (opt[i+1] == 0) {
15676 +                               limpk("TCP option %u 0 len\n",
15677 +                                     opt[i]);
15678 +                               return 0;
15679 +                       }
15680 +                       /* CHECK: oversize options. */
15681 +                       else if (&opt[i] + opt[i+1] > endhdr) {
15682 +                               limpk("TCP option %u at %Zu too long\n",
15683 +                                     (unsigned int) opt[i], i);
15684 +                               return 0;
15685 +                       }
15686 +                       /* Move to next option */
15687 +                       i += opt[i+1];
15688 +               }
15689 +       }
15690 +
15691 +       return 1;
15692 +}
15693 +
15694 +/* Returns 1 if ok */
15695 +/* Standard IP checks. */
15696 +static int
15697 +check_ip(struct iphdr *iph, size_t length, int embedded)
15698 +{
15699 +       u_int8_t *opt = (u_int8_t *)iph;
15700 +       u_int8_t *endhdr = (u_int8_t *)iph + iph->ihl * 4;
15701 +       int end_of_options = 0;
15702 +       void *protoh;
15703 +       size_t datalen;
15704 +       unsigned int i;
15705 +       unsigned int offset;
15706 +
15707 +       /* Should only happen for local outgoing raw-socket packets. */
15708 +       /* CHECK: length >= ip header. */
15709 +       if (length < sizeof(struct iphdr) || length < iph->ihl * 4) {
15710 +               limpk("Packet length %Zu < IP header.\n", length);
15711 +               return 0;
15712 +       }
15713 +
15714 +       offset = ntohs(iph->frag_off) & IP_OFFSET;
15715 +       protoh = (void *)iph + iph->ihl * 4;
15716 +       datalen = length - iph->ihl * 4;
15717 +
15718 +       /* CHECK: Embedded fragment. */
15719 +       if (embedded && offset) {
15720 +               limpk("Embedded fragment.\n");
15721 +               return 0;
15722 +       }
15723 +
15724 +       for (i = sizeof(struct iphdr); i < iph->ihl * 4; ) {
15725 +               switch (opt[i]) {
15726 +               case 0:
15727 +                       end_of_options = 1;
15728 +                       i++;
15729 +                       break;
15730 +               case 1:
15731 +                       i++;
15732 +                       break;
15733 +               default:
15734 +                       /* CHECK: options after EOO. */
15735 +                       if (end_of_options) {
15736 +                               limpk("IP option %u after end\n",
15737 +                                     opt[i]);
15738 +                               return 0;
15739 +                       }
15740 +                       /* CHECK: options at tail. */
15741 +                       else if (i+1 >= iph->ihl * 4) {
15742 +                               limpk("IP option %u at tail\n",
15743 +                                     opt[i]);
15744 +                               return 0;
15745 +                       }
15746 +                       /* CHECK: zero-length or one-length options. */
15747 +                       else if (opt[i+1] < 2) {
15748 +                               limpk("IP option %u %u len\n",
15749 +                                     opt[i], opt[i+1]);
15750 +                               return 0;
15751 +                       }
15752 +                       /* CHECK: oversize options. */
15753 +                       else if (&opt[i] + opt[i+1] > endhdr) {
15754 +                               limpk("IP option %u at %u too long\n",
15755 +                                     opt[i], i);
15756 +                               return 0;
15757 +                       }
15758 +                       /* Move to next option */
15759 +                       i += opt[i+1];
15760 +               }
15761 +       }
15762 +
15763 +       /* Fragment checks. */
15764 +
15765 +       /* CHECK: More fragments, but doesn't fill 8-byte boundary. */
15766 +       if ((ntohs(iph->frag_off) & IP_MF)
15767 +           && (ntohs(iph->tot_len) % 8) != 0) {
15768 +               limpk("Truncated fragment %u long.\n", ntohs(iph->tot_len));
15769 +               return 0;
15770 +       }
15771 +
15772 +       /* CHECK: Oversize fragment a-la Ping of Death. */
15773 +       if (offset * 8 + datalen > 65535) {
15774 +               limpk("Oversize fragment to %u.\n", offset * 8);
15775 +               return 0;
15776 +       }
15777 +
15778 +       /* CHECK: DF set and offset or MF set. */
15779 +       if ((ntohs(iph->frag_off) & IP_DF)
15780 +           && (offset || (ntohs(iph->frag_off) & IP_MF))) {
15781 +               limpk("DF set and offset=%u, MF=%u.\n",
15782 +                     offset, ntohs(iph->frag_off) & IP_MF);
15783 +               return 0;
15784 +       }
15785 +
15786 +       /* CHECK: Zero-sized fragments. */
15787 +       if ((offset || (ntohs(iph->frag_off) & IP_MF))
15788 +           && datalen == 0) {
15789 +               limpk("Zero size fragment offset=%u\n", offset);
15790 +               return 0;
15791 +       }
15792 +
15793 +       /* Note: we can have even middle fragments smaller than this:
15794 +          consider a large packet passing through a 600MTU then
15795 +          576MTU link: this gives a fragment of 24 data bytes.  But
15796 +          everyone packs fragments largest first, hence a fragment
15797 +          can't START before 576 - MAX_IP_HEADER_LEN. */
15798 +
15799 +       /* Used to be min-size 576: I recall Alan Cox saying ax25 goes
15800 +          down to 128 (576 taken from RFC 791: All hosts must be
15801 +          prepared to accept datagrams of up to 576 octets).  Use 128
15802 +          here. */
15803 +#define MIN_LIKELY_MTU 128
15804 +       /* CHECK: Min size of first frag = 128. */
15805 +       if ((ntohs(iph->frag_off) & IP_MF)
15806 +           && offset == 0
15807 +           && ntohs(iph->tot_len) < MIN_LIKELY_MTU) {
15808 +               limpk("First fragment size %u < %u\n", ntohs(iph->tot_len),
15809 +                     MIN_LIKELY_MTU);
15810 +               return 0;
15811 +       }
15812 +
15813 +       /* CHECK: Min offset of frag = 128 - IP hdr len. */
15814 +       if (offset && offset * 8 < MIN_LIKELY_MTU - iph->ihl * 4) {
15815 +               limpk("Fragment starts at %u < %u\n", offset * 8,
15816 +                     MIN_LIKELY_MTU - iph->ihl * 4);
15817 +               return 0;
15818 +       }
15819 +
15820 +       /* CHECK: Protocol specification non-zero. */
15821 +       if (iph->protocol == 0) {
15822 +               limpk("Zero protocol\n");
15823 +               return 0;
15824 +       }
15825 +
15826 +       /* CHECK: Do not use what is unused.
15827 +        * First bit of fragmentation flags should be unused.
15828 +        * May be used by OS fingerprinting tools.
15829 +        * 04 Jun 2002, Maciej Soltysiak, solt@dns.toxicfilms.tv
15830 +        */
15831 +       if (ntohs(iph->frag_off)>>15) {
15832 +               limpk("IP unused bit set\n");
15833 +               return 0;
15834 +       }
15835 +
15836 +       /* Per-protocol checks. */
15837 +       switch (iph->protocol) {
15838 +       case IPPROTO_ICMP:
15839 +               return check_icmp(protoh, datalen, offset,
15840 +                                 (ntohs(iph->frag_off) & IP_MF),
15841 +                                 embedded);
15842 +
15843 +       case IPPROTO_UDP:
15844 +               return check_udp(iph, protoh, datalen, offset,
15845 +                                (ntohs(iph->frag_off) & IP_MF),
15846 +                                embedded);
15847 +
15848 +       case IPPROTO_TCP:
15849 +               return check_tcp(iph, protoh, datalen, offset,
15850 +                                (ntohs(iph->frag_off) & IP_MF),
15851 +                                embedded);
15852 +       default:
15853 +               /* Ignorance is bliss. */
15854 +               return 1;
15855 +       }
15856 +}
15857 +
15858 +static int
15859 +match(const struct sk_buff *skb,
15860 +      const struct net_device *in,
15861 +      const struct net_device *out,
15862 +      const void *matchinfo,
15863 +      int offset,
15864 +      const void *hdr,
15865 +      u_int16_t datalen,
15866 +      int *hotdrop)
15867 +{
15868 +       return !check_ip(skb->nh.iph, skb->len, 0);
15869 +}
15870 +
15871 +/* Called when user tries to insert an entry of this type. */
15872 +static int
15873 +checkentry(const char *tablename,
15874 +          const struct ipt_ip *ip,
15875 +          void *matchinfo,
15876 +          unsigned int matchsize,
15877 +          unsigned int hook_mask)
15878 +{
15879 +       if (matchsize != IPT_ALIGN(0))
15880 +               return 0;
15881 +
15882 +       return 1;
15883 +}
15884 +
15885 +static struct ipt_match unclean_match
15886 += { { NULL, NULL }, "unclean", &match, &checkentry, NULL, THIS_MODULE };
15887 +
15888 +static int __init init(void)
15889 +{
15890 +       return ipt_register_match(&unclean_match);
15891 +}
15892 +
15893 +static void __exit fini(void)
15894 +{
15895 +       ipt_unregister_match(&unclean_match);
15896 +}
15897 +
15898 +module_init(init);
15899 +module_exit(fini);
15900 +MODULE_LICENSE("GPL");
15901 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/netfilter/iptable_filter.c linux-2.6.7-rc3/net/ipv4/netfilter/iptable_filter.c
15902 --- linux-2.6.7-rc3.org/net/ipv4/netfilter/iptable_filter.c     2004-06-07 21:14:05.000000000 +0200
15903 +++ linux-2.6.7-rc3/net/ipv4/netfilter/iptable_filter.c 2004-06-08 10:37:30.000000000 +0200
15904 @@ -59,7 +59,7 @@
15905                 0,
15906                 sizeof(struct ipt_entry),
15907                 sizeof(struct ipt_standard),
15908 -               0, { 0, 0 }, { } },
15909 +               0, NULL, 0, { 0, 0 }, { } },
15910               { { { { IPT_ALIGN(sizeof(struct ipt_standard_target)), "" } }, { } },
15911                 -NF_ACCEPT - 1 } },
15912             /* FORWARD */
15913 @@ -67,7 +67,7 @@
15914                 0,
15915                 sizeof(struct ipt_entry),
15916                 sizeof(struct ipt_standard),
15917 -               0, { 0, 0 }, { } },
15918 +               0, NULL, 0, { 0, 0 }, { } },
15919               { { { { IPT_ALIGN(sizeof(struct ipt_standard_target)), "" } }, { } },
15920                 -NF_ACCEPT - 1 } },
15921             /* LOCAL_OUT */
15922 @@ -75,7 +75,7 @@
15923                 0,
15924                 sizeof(struct ipt_entry),
15925                 sizeof(struct ipt_standard),
15926 -               0, { 0, 0 }, { } },
15927 +               0, NULL, 0, { 0, 0 }, { } },
15928               { { { { IPT_ALIGN(sizeof(struct ipt_standard_target)), "" } }, { } },
15929                 -NF_ACCEPT - 1 } }
15930      },
15931 @@ -84,7 +84,7 @@
15932         0,
15933         sizeof(struct ipt_entry),
15934         sizeof(struct ipt_error),
15935 -       0, { 0, 0 }, { } },
15936 +       0, NULL, 0, { 0, 0 }, { } },
15937        { { { { IPT_ALIGN(sizeof(struct ipt_error_target)), IPT_ERROR_TARGET } },
15938           { } },
15939         "ERROR"
15940 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/netfilter/iptable_mangle.c linux-2.6.7-rc3/net/ipv4/netfilter/iptable_mangle.c
15941 --- linux-2.6.7-rc3.org/net/ipv4/netfilter/iptable_mangle.c     2004-06-07 21:14:58.000000000 +0200
15942 +++ linux-2.6.7-rc3/net/ipv4/netfilter/iptable_mangle.c 2004-06-08 10:37:30.000000000 +0200
15943 @@ -74,7 +74,7 @@
15944                 0,
15945                 sizeof(struct ipt_entry),
15946                 sizeof(struct ipt_standard),
15947 -               0, { 0, 0 }, { } },
15948 +               0, NULL, 0, { 0, 0 }, { } },
15949               { { { { IPT_ALIGN(sizeof(struct ipt_standard_target)), "" } }, { } },
15950                 -NF_ACCEPT - 1 } },
15951             /* LOCAL_IN */
15952 @@ -82,7 +82,7 @@
15953                 0,
15954                 sizeof(struct ipt_entry),
15955                 sizeof(struct ipt_standard),
15956 -               0, { 0, 0 }, { } },
15957 +               0, NULL, 0, { 0, 0 }, { } },
15958               { { { { IPT_ALIGN(sizeof(struct ipt_standard_target)), "" } }, { } },
15959                 -NF_ACCEPT - 1 } },
15960             /* FORWARD */
15961 @@ -90,7 +90,7 @@
15962                 0,
15963                 sizeof(struct ipt_entry),
15964                 sizeof(struct ipt_standard),
15965 -               0, { 0, 0 }, { } },
15966 +               0, NULL, 0, { 0, 0 }, { } },
15967               { { { { IPT_ALIGN(sizeof(struct ipt_standard_target)), "" } }, { } },
15968                 -NF_ACCEPT - 1 } },
15969             /* LOCAL_OUT */
15970 @@ -98,7 +98,7 @@
15971                 0,
15972                 sizeof(struct ipt_entry),
15973                 sizeof(struct ipt_standard),
15974 -               0, { 0, 0 }, { } },
15975 +               0, NULL, 0, { 0, 0 }, { } },
15976               { { { { IPT_ALIGN(sizeof(struct ipt_standard_target)), "" } }, { } },
15977                 -NF_ACCEPT - 1 } },
15978             /* POST_ROUTING */
15979 @@ -106,7 +106,7 @@
15980                 0,
15981                 sizeof(struct ipt_entry),
15982                 sizeof(struct ipt_standard),
15983 -               0, { 0, 0 }, { } },
15984 +               0, NULL, 0, { 0, 0 }, { } },
15985               { { { { IPT_ALIGN(sizeof(struct ipt_standard_target)), "" } }, { } },
15986                 -NF_ACCEPT - 1 } },
15987      },
15988 @@ -115,7 +115,7 @@
15989         0,
15990         sizeof(struct ipt_entry),
15991         sizeof(struct ipt_error),
15992 -       0, { 0, 0 }, { } },
15993 +       0, NULL, 0, { 0, 0 }, { } },
15994        { { { { IPT_ALIGN(sizeof(struct ipt_error_target)), IPT_ERROR_TARGET } },
15995           { } },
15996         "ERROR"
15997 @@ -173,8 +173,13 @@
15998         if (ret != NF_DROP && ret != NF_STOLEN && ret != NF_QUEUE
15999             && ((*pskb)->nh.iph->saddr != saddr
16000                 || (*pskb)->nh.iph->daddr != daddr
16001 +#ifdef CONFIG_IP_ROUTE_FWMARK
16002                 || (*pskb)->nfmark != nfmark
16003 -               || (*pskb)->nh.iph->tos != tos))
16004 +#endif
16005 +#ifdef CONFIG_IP_ROUTE_TOS
16006 +               || (*pskb)->nh.iph->tos != tos
16007 +#endif
16008 +              ))
16009                 return ip_route_me_harder(pskb) == 0 ? ret : NF_DROP;
16010  
16011         return ret;
16012 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/netfilter/iptable_raw.c linux-2.6.7-rc3/net/ipv4/netfilter/iptable_raw.c
16013 --- linux-2.6.7-rc3.org/net/ipv4/netfilter/iptable_raw.c        2004-06-07 21:14:59.000000000 +0200
16014 +++ linux-2.6.7-rc3/net/ipv4/netfilter/iptable_raw.c    2004-06-08 10:37:30.000000000 +0200
16015 @@ -46,7 +46,7 @@
16016                 0,
16017                 sizeof(struct ipt_entry),
16018                 sizeof(struct ipt_standard),
16019 -               0, { 0, 0 }, { } },
16020 +               0, NULL, 0, { 0, 0 }, { } },
16021               { { { { IPT_ALIGN(sizeof(struct ipt_standard_target)), "" } }, { } },
16022                 -NF_ACCEPT - 1 } },
16023             /* LOCAL_OUT */
16024 @@ -54,7 +54,7 @@
16025                 0,
16026                 sizeof(struct ipt_entry),
16027                 sizeof(struct ipt_standard),
16028 -               0, { 0, 0 }, { } },
16029 +               0, NULL, 0, { 0, 0 }, { } },
16030               { { { { IPT_ALIGN(sizeof(struct ipt_standard_target)), "" } }, { } },
16031                 -NF_ACCEPT - 1 } }
16032      },
16033 @@ -63,7 +63,7 @@
16034         0,
16035         sizeof(struct ipt_entry),
16036         sizeof(struct ipt_error),
16037 -       0, { 0, 0 }, { } },
16038 +       0, NULL, 0, { 0, 0 }, { } },
16039        { { { { IPT_ALIGN(sizeof(struct ipt_error_target)), IPT_ERROR_TARGET } },
16040           { } },
16041         "ERROR"
16042 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/netfilter/string.2.6.patch linux-2.6.7-rc3/net/ipv4/netfilter/string.2.6.patch
16043 --- linux-2.6.7-rc3.org/net/ipv4/netfilter/string.2.6.patch     1970-01-01 01:00:00.000000000 +0100
16044 +++ linux-2.6.7-rc3/net/ipv4/netfilter/string.2.6.patch 2004-06-08 10:41:24.000000000 +0200
16045 @@ -0,0 +1,152 @@
16046 +--- ipt_string.c.old    Mon Mar 29 06:00:23 2004
16047 ++++ ipt_string.c    Mon Mar 29 06:01:04 2004
16048 +@@ -3,6 +3,8 @@
16049 +  * Copyright (C) 2000 Emmanuel Roger  <winfield@freegates.be>
16050 +  * 
16051 +  * ChangeLog
16052 ++ *     24.03.2004: Eric Lauriault <elauri@lacitec.on.ca>
16053 ++ *             Initial 2.6 port
16054 +  *     19.02.2002: Gianni Tedesco <gianni@ecsc.co.uk>
16055 +  *             Fixed SMP re-entrancy problem using per-cpu data areas
16056 +  *             for the skip/shift tables.
16057 +@@ -18,6 +20,7 @@
16058 +  */
16059
16060 + #include <linux/smp.h>
16061 ++#include <linux/percpu.h>
16062 + #include <linux/module.h>
16063 + #include <linux/skbuff.h>
16064 + #include <linux/file.h>
16065 +@@ -29,12 +32,13 @@
16066 + MODULE_LICENSE("GPL");
16067
16068 + struct string_per_cpu {
16069 +-       int *skip;
16070 +-       int *shift;
16071 +-       int *len;
16072 ++       int skip[BM_MAX_HLEN];
16073 ++       int shift[BM_MAX_HLEN];
16074 ++       int len[BM_MAX_HLEN];
16075 + };
16076
16077 +-struct string_per_cpu *bm_string_data=NULL;
16078 ++static DEFINE_PER_CPU(struct string_per_cpu, bm_string_data);
16079 ++
16080
16081 + /* Boyer Moore Sublinear string search - VERY FAST */
16082 + char *search_sublinear (char *needle, char *haystack, int needle_len, int haystack_len) 
16083 +@@ -45,14 +49,14 @@
16084 +        int *skip, *shift, *len;
16085 +        
16086 +        /* use data suitable for this CPU */
16087 +-       shift=bm_string_data[smp_processor_id()].shift;
16088 +-       skip=bm_string_data[smp_processor_id()].skip;
16089 +-       len=bm_string_data[smp_processor_id()].len;
16090 ++       shift=__get_cpu_var(bm_string_data).shift;
16091 ++       skip=__get_cpu_var(bm_string_data).skip;
16092 ++       len=__get_cpu_var(bm_string_data).len;
16093 +        
16094 +        /* Setup skip/shift tables */
16095 +        M1 = right_end = needle_len-1;
16096 +        for (i = 0; i < BM_MAX_HLEN; i++) skip[i] = needle_len;  
16097 +-       for (i = 0; needle[i]; i++) skip[needle[i]] = M1 - i;  
16098 ++       for (i = 0; needle[i]; i++) skip[(int)needle[i]] = M1 - i;
16099
16100 +        for (i = 1; i < needle_len; i++) {   
16101 +                for (j = 0; j < needle_len && needle[M1 - j] == needle[M1 - i - j]; j++);  
16102 +@@ -77,7 +81,7 @@
16103 +                        return haystack+(right_end - M1);
16104 +                }
16105 +                
16106 +-               sk = skip[haystack[right_end - i]];  
16107 ++               sk = skip[(int)haystack[right_end - i]];  
16108 +                sh = shift[i];
16109 +                right_end = max(right_end - i + sk, right_end + sh);  
16110 +        }
16111 +@@ -100,15 +104,12 @@
16112 +        return NULL;
16113 + }
16114
16115 +-
16116 + static int
16117 + match(const struct sk_buff *skb,
16118 +       const struct net_device *in,
16119 +       const struct net_device *out,
16120 +       const void *matchinfo,
16121 +       int offset,
16122 +-      const void *hdr,
16123 +-      u_int16_t datalen,
16124 +       int *hotdrop)
16125 + {
16126 +        const struct ipt_string_info *info = matchinfo;
16127 +@@ -158,61 +159,25 @@
16128 +        return 1;
16129 + }
16130
16131 +-void string_freeup_data(void)
16132 +-{
16133 +-       int c;
16134 +-       
16135 +-       if ( bm_string_data ) {
16136 +-               for(c=0; c<smp_num_cpus; c++) {
16137 +-                       if ( bm_string_data[c].shift ) kfree(bm_string_data[c].shift);
16138 +-                       if ( bm_string_data[c].skip ) kfree(bm_string_data[c].skip);
16139 +-                       if ( bm_string_data[c].len ) kfree(bm_string_data[c].len);
16140 +-               }
16141 +-               kfree(bm_string_data);
16142 +-       }
16143 +-}
16144 ++static struct ipt_match string_match = {
16145 ++    .name = "string",
16146 ++    .match = &match,
16147 ++    .checkentry = &checkentry,
16148 ++    .me = THIS_MODULE
16149 ++};
16150
16151 +-static struct ipt_match string_match
16152 +-= { { NULL, NULL }, "string", &match, &checkentry, NULL, THIS_MODULE };
16153
16154 + static int __init init(void)
16155 + {
16156 +-       int c;
16157 +-       size_t tlen;
16158 +-       size_t alen;
16159 +-
16160 +-       tlen=sizeof(struct string_per_cpu)*smp_num_cpus;
16161 +-       alen=sizeof(int)*BM_MAX_HLEN;
16162 +-       
16163 +-       /* allocate array of structures */
16164 +-       if ( !(bm_string_data=kmalloc(tlen,GFP_KERNEL)) ) {
16165 +-               return 0;
16166 +-       }
16167 +-       
16168 +-       memset(bm_string_data, 0, tlen);
16169 +-       
16170 +-       /* allocate our skip/shift tables */
16171 +-       for(c=0; c<smp_num_cpus; c++) {
16172 +-               if ( !(bm_string_data[c].shift=kmalloc(alen, GFP_KERNEL)) )
16173 +-                       goto alloc_fail;
16174 +-               if ( !(bm_string_data[c].skip=kmalloc(alen, GFP_KERNEL)) )
16175 +-                       goto alloc_fail;
16176 +-               if ( !(bm_string_data[c].len=kmalloc(alen, GFP_KERNEL)) )
16177 +-                       goto alloc_fail;
16178 +-       }
16179 +-       
16180 +        return ipt_register_match(&string_match);
16181 +-
16182 +-alloc_fail:
16183 +-       string_freeup_data();
16184 +-       return 0;
16185 + }
16186
16187 + static void __exit fini(void)
16188 + {
16189 +        ipt_unregister_match(&string_match);
16190 +-       string_freeup_data();
16191 + }
16192
16193 + module_init(init);
16194 + module_exit(fini);
16195 ++
16196 ++
16197 +
16198 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/raw.c linux-2.6.7-rc3/net/ipv4/raw.c
16199 --- linux-2.6.7-rc3.org/net/ipv4/raw.c  2004-06-07 21:14:25.000000000 +0200
16200 +++ linux-2.6.7-rc3/net/ipv4/raw.c      2004-06-08 10:38:46.000000000 +0200
16201 @@ -249,6 +249,7 @@
16202                 kfree_skb(skb);
16203                 return NET_RX_DROP;
16204         }
16205 +       nf_reset(skb);
16206  
16207         skb_push(skb, skb->data - skb->nh.raw);
16208  
16209 @@ -307,7 +308,7 @@
16210         }
16211  
16212         err = NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, skb, NULL, rt->u.dst.dev,
16213 -                     dst_output);
16214 +                     ip_dst_output);
16215         if (err > 0)
16216                 err = inet->recverr ? net_xmit_errno(err) : 0;
16217         if (err)
16218 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/tcp_ipv4.c linux-2.6.7-rc3/net/ipv4/tcp_ipv4.c
16219 --- linux-2.6.7-rc3.org/net/ipv4/tcp_ipv4.c     2004-06-07 21:14:04.000000000 +0200
16220 +++ linux-2.6.7-rc3/net/ipv4/tcp_ipv4.c 2004-06-08 10:39:56.000000000 +0200
16221 @@ -1785,6 +1785,7 @@
16222  
16223         if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb))
16224                 goto discard_and_relse;
16225 +       nf_reset(skb);
16226  
16227         if (sk_filter(sk, skb, 0))
16228                 goto discard_and_relse;
16229 @@ -2636,6 +2637,7 @@
16230  EXPORT_SYMBOL(tcp_v4_connect);
16231  EXPORT_SYMBOL(tcp_v4_do_rcv);
16232  EXPORT_SYMBOL(tcp_v4_lookup_listener);
16233 +EXPORT_SYMBOL(tcp_v4_lookup);
16234  EXPORT_SYMBOL(tcp_v4_rebuild_header);
16235  EXPORT_SYMBOL(tcp_v4_remember_stamp);
16236  EXPORT_SYMBOL(tcp_v4_send_check);
16237 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/udp.c linux-2.6.7-rc3/net/ipv4/udp.c
16238 --- linux-2.6.7-rc3.org/net/ipv4/udp.c  2004-06-07 21:13:39.000000000 +0200
16239 +++ linux-2.6.7-rc3/net/ipv4/udp.c      2004-06-08 10:39:56.000000000 +0200
16240 @@ -1045,6 +1045,7 @@
16241                 kfree_skb(skb);
16242                 return -1;
16243         }
16244 +       nf_reset(skb);
16245  
16246         if (up->encap_type) {
16247                 /*
16248 @@ -1210,6 +1211,7 @@
16249  
16250         if (!xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb))
16251                 goto drop;
16252 +       nf_reset(skb);
16253  
16254         /* No socket. Drop packet silently, if checksum is wrong */
16255         if (udp_checksum_complete(skb))
16256 @@ -1558,6 +1560,7 @@
16257  EXPORT_SYMBOL(udp_port_rover);
16258  EXPORT_SYMBOL(udp_prot);
16259  EXPORT_SYMBOL(udp_sendmsg);
16260 +EXPORT_SYMBOL(udp_v4_lookup);
16261  
16262  #ifdef CONFIG_PROC_FS
16263  EXPORT_SYMBOL(udp_proc_register);
16264 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv4/xfrm4_tunnel.c linux-2.6.7-rc3/net/ipv4/xfrm4_tunnel.c
16265 --- linux-2.6.7-rc3.org/net/ipv4/xfrm4_tunnel.c 2004-06-07 21:13:38.000000000 +0200
16266 +++ linux-2.6.7-rc3/net/ipv4/xfrm4_tunnel.c     2004-06-08 10:38:44.000000000 +0200
16267 @@ -77,6 +77,7 @@
16268                 err = -EHOSTUNREACH;
16269                 goto error_nolock;
16270         }
16271 +       IPCB(skb)->flags |= IPSKB_XFRM_TRANSFORMED;
16272         return NET_XMIT_BYPASS;
16273  
16274  error_nolock:
16275 @@ -171,6 +172,7 @@
16276         .handler        =       ipip_rcv,
16277         .err_handler    =       ipip_err,
16278         .no_policy      =       1,
16279 +       .xfrm_prot      =       1,
16280  };
16281  
16282  static int __init ipip_init(void)
16283 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv6/ip6_tunnel.c linux-2.6.7-rc3/net/ipv6/ip6_tunnel.c
16284 --- linux-2.6.7-rc3.org/net/ipv6/ip6_tunnel.c   2004-06-07 21:13:37.000000000 +0200
16285 +++ linux-2.6.7-rc3/net/ipv6/ip6_tunnel.c       2004-06-08 10:30:55.000000000 +0200
16286 @@ -715,13 +715,7 @@
16287         ipv6h->nexthdr = proto;
16288         ipv6_addr_copy(&ipv6h->saddr, &fl.fl6_src);
16289         ipv6_addr_copy(&ipv6h->daddr, &fl.fl6_dst);
16290 -#ifdef CONFIG_NETFILTER
16291 -       nf_conntrack_put(skb->nfct);
16292 -       skb->nfct = NULL;
16293 -#ifdef CONFIG_NETFILTER_DEBUG
16294 -       skb->nf_debug = 0;
16295 -#endif
16296 -#endif
16297 +       nf_reset(skb);
16298         pkt_len = skb->len;
16299         err = NF_HOOK(PF_INET6, NF_IP6_LOCAL_OUT, skb, NULL, 
16300                       skb->dst->dev, dst_output);
16301 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv6/netfilter/Kconfig linux-2.6.7-rc3/net/ipv6/netfilter/Kconfig
16302 --- linux-2.6.7-rc3.org/net/ipv6/netfilter/Kconfig      2004-06-07 21:14:58.000000000 +0200
16303 +++ linux-2.6.7-rc3/net/ipv6/netfilter/Kconfig  2004-06-08 10:42:36.000000000 +0200
16304 @@ -230,5 +230,107 @@
16305           <file:Documentation/modules.txt>.  If unsure, say `N'.
16306           help
16307  
16308 +config IP6_NF_TARGET_HL
16309 +       tristate  'HL target support'
16310 +       depends on IP6_NF_MANGLE
16311 +       help
16312 +         This option adds a `HL' target, which allows you to modify the value of
16313 +         IPv6 Hop Limit field.
16314 +       
16315 +         If you want to compile it as a module, say M here and read
16316 +         <file:Documentation/modules.txt>.  If unsure, say `N'.
16317 +
16318 +config IP6_NF_TARGET_REJECT
16319 +       tristate  'REJECT target support'
16320 +       depends on IP6_NF_FILTER
16321 +       help
16322 +         The REJECT target allows a filtering rule to specify that an ICMPv6
16323 +         error should be issued in response to an incoming packet, rather
16324 +         than silently being dropped.
16325 +       
16326 +         If you want to compile it as a module, say M here and read
16327 +         Documentation/modules.txt.  If unsure, say `N'.
16328 +
16329 +config IP6_NF_MATCH_FUZZY
16330 +       tristate  'Fuzzy match support'
16331 +       depends on IP6_NF_FILTER
16332 +       help
16333 +         This option adds a `fuzzy' match, which allows you to match
16334 +         packets according to a fuzzy logic based law.
16335 +       
16336 +         If you want to compile it as a module, say M here and read
16337 +         Documentation/modules.txt.  If unsure, say `N'.
16338 +
16339 +config IP6_NF_MATCH_NTH
16340 +       tristate  'Nth match support'
16341 +       depends on IP6_NF_IPTABLES
16342 +       help
16343 +         This option adds a `Nth' match, which allow you to make
16344 +         rules that match every Nth packet.  By default there are 
16345 +         16 different counters.
16346 +       
16347 +         [options]
16348 +          --every     Nth              Match every Nth packet
16349 +         [--counter]  num              Use counter 0-15 (default:0)
16350 +         [--start]    num              Initialize the counter at the number 'num'
16351 +                                       instead of 0. Must be between 0 and Nth-1
16352 +         [--packet]   num              Match on 'num' packet. Must be between 0
16353 +                                       and Nth-1.
16354 +       
16355 +                                       If --packet is used for a counter than
16356 +                                       there must be Nth number of --packet
16357 +                                       rules, covering all values between 0 and
16358 +                                       Nth-1 inclusively.
16359 +        
16360 +         If you want to compile it as a module, say M here and read
16361 +         Documentation/modules.txt.  If unsure, say `N'.
16362 +
16363 +config IP6_NF_MATCH_RANDOM
16364 +       tristate  'Random match support'
16365 +       depends on IP6_NF_IPTABLES
16366 +       help
16367 +         This option adds a `random' match,
16368 +         which allow you to match packets randomly
16369 +         following a given probability.
16370 +        
16371 +         If you want to compile it as a module, say M here and read
16372 +         Documentation/modules.txt.  If unsure, say `N'.
16373 +
16374 +config IP6_NF_TARGET_ROUTE
16375 +       tristate '    ROUTE target support'
16376 +       depends on IP6_NF_MANGLE
16377 +       help
16378 +         This option adds a `ROUTE' target, which enables you to setup unusual
16379 +         routes. The ROUTE target is also able to change the incoming interface
16380 +         of a packet.
16381 +       
16382 +         The target can be or not a final target. It has to be used inside the 
16383 +         mangle table.
16384 +         
16385 +         Not working as a module.
16386 +
16387 +config IP6_NF_TARGET_TRACE
16388 +       tristate  'TRACE target support'
16389 +       depends on IP6_NF_RAW
16390 +       help
16391 +         The TRACE target allows packets to be traced as those
16392 +         matches any subsequent rule in any table/rule. The matched
16393 +         rule and the packet is logged with the prefix
16394 +       
16395 +         TRACE: tablename/chainname/rulenum  
16396 +       
16397 +         If you want to compile it as a module, say M here and read
16398 +         <file:Documentation/modules.txt>.  If unsure, say `N'.
16399 +
16400 +config IP6_NF_MATCH_POLICY
16401 +       tristate "IPsec policy match support"
16402 +       depends on IP6_NF_IPTABLES && XFRM
16403 +       help
16404 +         Policy matching allows you to match packets based on the
16405 +         IPsec policy that was used during decapsulation/will
16406 +         be used during encapsulation.
16407 +
16408 +         To compile it as a module, choose M here.  If unsure, say N.
16409 +
16410  endmenu
16411  
16412 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv6/netfilter/Makefile linux-2.6.7-rc3/net/ipv6/netfilter/Makefile
16413 --- linux-2.6.7-rc3.org/net/ipv6/netfilter/Makefile     2004-06-07 21:14:33.000000000 +0200
16414 +++ linux-2.6.7-rc3/net/ipv6/netfilter/Makefile 2004-06-08 10:42:36.000000000 +0200
16415 @@ -8,18 +8,28 @@
16416  obj-$(CONFIG_IP6_NF_MATCH_MARK) += ip6t_mark.o
16417  obj-$(CONFIG_IP6_NF_MATCH_LENGTH) += ip6t_length.o
16418  obj-$(CONFIG_IP6_NF_MATCH_MAC) += ip6t_mac.o
16419 +obj-$(CONFIG_IP6_NF_MATCH_FUZZY) += ip6t_fuzzy.o
16420  obj-$(CONFIG_IP6_NF_MATCH_RT) += ip6t_rt.o
16421  obj-$(CONFIG_IP6_NF_MATCH_OPTS) += ip6t_hbh.o ip6t_dst.o
16422  obj-$(CONFIG_IP6_NF_MATCH_IPV6HEADER) += ip6t_ipv6header.o
16423  obj-$(CONFIG_IP6_NF_MATCH_FRAG) += ip6t_frag.o
16424  obj-$(CONFIG_IP6_NF_MATCH_AHESP) += ip6t_esp.o ip6t_ah.o
16425 +obj-$(CONFIG_IP6_NF_MATCH_POLICY) += ip6t_policy.o
16426  obj-$(CONFIG_IP6_NF_MATCH_EUI64) += ip6t_eui64.o
16427  obj-$(CONFIG_IP6_NF_MATCH_MULTIPORT) += ip6t_multiport.o
16428  obj-$(CONFIG_IP6_NF_MATCH_OWNER) += ip6t_owner.o
16429  obj-$(CONFIG_IP6_NF_FILTER) += ip6table_filter.o
16430  obj-$(CONFIG_IP6_NF_MANGLE) += ip6table_mangle.o
16431  obj-$(CONFIG_IP6_NF_TARGET_MARK) += ip6t_MARK.o
16432 +obj-$(CONFIG_IP6_NF_TARGET_ROUTE) += ip6t_ROUTE.o
16433 +obj-$(CONFIG_IP6_NF_TARGET_REJECT) += ip6t_REJECT.o
16434  obj-$(CONFIG_IP6_NF_QUEUE) += ip6_queue.o
16435  obj-$(CONFIG_IP6_NF_TARGET_LOG) += ip6t_LOG.o
16436 +
16437 +obj-$(CONFIG_IP6_NF_MATCH_RANDOM) += ip6t_random.o
16438 +
16439 +obj-$(CONFIG_IP6_NF_MATCH_NTH) += ip6t_nth.o
16440 +obj-$(CONFIG_IP6_NF_TARGET_HL) += ip6t_HL.o
16441  obj-$(CONFIG_IP6_NF_RAW) += ip6table_raw.o
16442 +obj-$(CONFIG_IP6_NF_TARGET_TRACE) += ip6t_TRACE.o
16443  obj-$(CONFIG_IP6_NF_MATCH_HL) += ip6t_hl.o
16444 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv6/netfilter/ip6_tables.c linux-2.6.7-rc3/net/ipv6/netfilter/ip6_tables.c
16445 --- linux-2.6.7-rc3.org/net/ipv6/netfilter/ip6_tables.c 2004-06-07 21:14:58.000000000 +0200
16446 +++ linux-2.6.7-rc3/net/ipv6/netfilter/ip6_tables.c     2004-06-08 10:37:30.000000000 +0200
16447 @@ -38,6 +38,14 @@
16448  #define IPV6_HDR_LEN   (sizeof(struct ipv6hdr))
16449  #define IPV6_OPTHDR_LEN        (sizeof(struct ipv6_opt_hdr))
16450  
16451 +static const char *hook6names[] = { 
16452 +       [NF_IP6_PRE_ROUTING] "PREROUTING",
16453 +       [NF_IP6_LOCAL_IN] "INPUT",
16454 +       [NF_IP6_FORWARD] "FORWARD",
16455 +       [NF_IP6_LOCAL_OUT] "OUTPUT",
16456 +       [NF_IP6_POST_ROUTING] "POSTROUTING",
16457 +};
16458 +
16459  /*#define DEBUG_IP_FIREWALL*/
16460  /*#define DEBUG_ALLOW_ALL*/ /* Useful for remote debugging */
16461  /*#define DEBUG_IP_FIREWALL_USER*/
16462 @@ -406,6 +414,12 @@
16463  
16464                         t = ip6t_get_target(e);
16465                         IP_NF_ASSERT(t->u.kernel.target);
16466 +
16467 +                       /* The packet traced and the rule isn't an unconditional return/END. */
16468 +                       if (((*pskb)->nfcache & NFC_TRACE) && e->rulenum) {
16469 +                               nf_log_packet(PF_INET6, hook, *pskb, in, out, "TRACE: %s/%s/%u ",
16470 +                                             table->name, e->chainname, e->rulenum);
16471 +                       }
16472                         /* Standard target? */
16473                         if (!t->u.kernel.target->target) {
16474                                 int v;
16475 @@ -559,6 +573,29 @@
16476         return find_inlist_lock(&ip6t_target, name, "ip6t_", error, mutex);
16477  }
16478  
16479 +static inline int
16480 +find_error_target(struct ip6t_entry *s, 
16481 +                 struct ip6t_entry *e,
16482 +                 char **chainname)
16483 +{
16484 +       struct ip6t_entry_target *t;
16485 +       static struct ip6t_entry *found = NULL;
16486 +
16487 +       if (s == e) {
16488 +               if (!found)
16489 +                       return 0;
16490 +               t = ip6t_get_target(found);
16491 +               if (strcmp(t->u.user.name, 
16492 +                          IP6T_ERROR_TARGET) == 0) {
16493 +                       *chainname = t->data;
16494 +                       return 1;
16495 +               }
16496 +       } else
16497 +               found = s;
16498 +       
16499 +       return 0;
16500 +}
16501 +
16502  /* All zeroes == unconditional rule. */
16503  static inline int
16504  unconditional(const struct ip6t_ip6 *ipv6)
16505 @@ -578,6 +615,8 @@
16506  mark_source_chains(struct ip6t_table_info *newinfo, unsigned int valid_hooks)
16507  {
16508         unsigned int hook;
16509 +       char *chainname = NULL;
16510 +       u_int32_t rulenum;
16511  
16512         /* No recursion; use packet counter to save back ptrs (reset
16513            to 0 as we leave), and comefrom to save source hook bitmask */
16514 @@ -591,6 +630,8 @@
16515  
16516                 /* Set initial back pointer. */
16517                 e->counters.pcnt = pos;
16518 +               rulenum = 1;
16519 +               chainname = (char *) hook6names[hook];
16520  
16521                 for (;;) {
16522                         struct ip6t_standard_target *t
16523 @@ -603,6 +644,8 @@
16524                         }
16525                         e->comefrom
16526                                 |= ((1 << hook) | (1 << NF_IP6_NUMHOOKS));
16527 +                       e->rulenum = rulenum++;
16528 +                       e->chainname = chainname;
16529  
16530                         /* Unconditional return/END. */
16531                         if (e->target_offset == sizeof(struct ip6t_entry)
16532 @@ -612,6 +655,10 @@
16533                             && unconditional(&e->ipv6)) {
16534                                 unsigned int oldpos, size;
16535  
16536 +                               /* Set unconditional rulenum to zero. */
16537 +                               e->rulenum = 0;
16538 +                               e->counters.bcnt = 0;
16539 +
16540                                 /* Return: backtrack through the last
16541                                    big jump. */
16542                                 do {
16543 @@ -637,6 +684,11 @@
16544                                                 (newinfo->entries + pos);
16545                                 } while (oldpos == pos + e->next_offset);
16546  
16547 +                               /* Restore chainname, rulenum. */
16548 +                               chainname = e->chainname;
16549 +                               rulenum = e->counters.bcnt;
16550 +                               e->counters.bcnt = 0;
16551 +
16552                                 /* Move along one */
16553                                 size = e->next_offset;
16554                                 e = (struct ip6t_entry *)
16555 @@ -652,6 +704,17 @@
16556                                         /* This a jump; chase it. */
16557                                         duprintf("Jump rule %u -> %u\n",
16558                                                  pos, newpos);
16559 +                                       e->counters.bcnt = rulenum++;
16560 +                                       rulenum = 1;
16561 +                                       e = (struct ip6t_entry *)
16562 +                                               (newinfo->entries + newpos);
16563 +                                       if (IP6T_ENTRY_ITERATE(newinfo->entries,
16564 +                                                              newinfo->size,
16565 +                                                              find_error_target,
16566 +                                                              e, &chainname) == 0) {
16567 +                                               printk("ip6_tables: table screwed up!\n");
16568 +                                               return 0;
16569 +                                       }
16570                                 } else {
16571                                         /* ... this is a fallthru */
16572                                         newpos = pos + e->next_offset;
16573 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv6/netfilter/ip6t_HL.c linux-2.6.7-rc3/net/ipv6/netfilter/ip6t_HL.c
16574 --- linux-2.6.7-rc3.org/net/ipv6/netfilter/ip6t_HL.c    1970-01-01 01:00:00.000000000 +0100
16575 +++ linux-2.6.7-rc3/net/ipv6/netfilter/ip6t_HL.c        2004-06-08 10:31:03.000000000 +0200
16576 @@ -0,0 +1,105 @@
16577 +/* 
16578 + * Hop Limit modification target for ip6tables
16579 + * Maciej Soltysiak <solt@dns.toxicfilms.tv>
16580 + * Based on HW's TTL module
16581 + *
16582 + * This software is distributed under the terms of GNU GPL
16583 + */
16584 +
16585 +#include <linux/module.h>
16586 +#include <linux/skbuff.h>
16587 +#include <linux/ip.h>
16588 +
16589 +#include <linux/netfilter_ipv6/ip6_tables.h>
16590 +#include <linux/netfilter_ipv6/ip6t_HL.h>
16591 +
16592 +MODULE_AUTHOR("Maciej Soltysiak <solt@dns.toxicfilms.tv>");
16593 +MODULE_DESCRIPTION("IP tables Hop Limit modification module");
16594 +MODULE_LICENSE("GPL");
16595 +
16596 +static unsigned int ip6t_hl_target(struct sk_buff **pskb, unsigned int hooknum,
16597 +               const struct net_device *in, const struct net_device *out,
16598 +               const void *targinfo, void *userinfo)
16599 +{
16600 +       struct ipv6hdr *ip6h = (*pskb)->nh.ipv6h;
16601 +       const struct ip6t_HL_info *info = targinfo;
16602 +       u_int16_t diffs[2];
16603 +       int new_hl;
16604 +                        
16605 +       switch (info->mode) {
16606 +               case IP6T_HL_SET:
16607 +                       new_hl = info->hop_limit;
16608 +                       break;
16609 +               case IP6T_HL_INC:
16610 +                       new_hl = ip6h->hop_limit + info->hop_limit;
16611 +                       if (new_hl > 255)
16612 +                               new_hl = 255;
16613 +                       break;
16614 +               case IP6T_HL_DEC:
16615 +                       new_hl = ip6h->hop_limit + info->hop_limit;
16616 +                       if (new_hl < 0)
16617 +                               new_hl = 0;
16618 +                       break;
16619 +               default:
16620 +                       new_hl = ip6h->hop_limit;
16621 +                       break;
16622 +       }
16623 +
16624 +       if (new_hl != ip6h->hop_limit) {
16625 +               diffs[0] = htons(((unsigned)ip6h->hop_limit) << 8) ^ 0xFFFF;
16626 +               ip6h->hop_limit = new_hl;
16627 +               diffs[1] = htons(((unsigned)ip6h->hop_limit) << 8);
16628 +       }
16629 +
16630 +       return IP6T_CONTINUE;
16631 +}
16632 +
16633 +static int ip6t_hl_checkentry(const char *tablename,
16634 +               const struct ip6t_entry *e,
16635 +               void *targinfo,
16636 +               unsigned int targinfosize,
16637 +               unsigned int hook_mask)
16638 +{
16639 +       struct ip6t_HL_info *info = targinfo;
16640 +
16641 +       if (targinfosize != IP6T_ALIGN(sizeof(struct ip6t_HL_info))) {
16642 +               printk(KERN_WARNING "HL: targinfosize %u != %Zu\n",
16643 +                               targinfosize,
16644 +                               IP6T_ALIGN(sizeof(struct ip6t_HL_info)));
16645 +               return 0;       
16646 +       }       
16647 +
16648 +       if (strcmp(tablename, "mangle")) {
16649 +               printk(KERN_WARNING "HL: can only be called from \"mangle\" table, not \"%s\"\n", tablename);
16650 +               return 0;
16651 +       }
16652 +
16653 +       if (info->mode > IP6T_HL_MAXMODE) {
16654 +               printk(KERN_WARNING "HL: invalid or unknown Mode %u\n", 
16655 +                       info->mode);
16656 +               return 0;
16657 +       }
16658 +
16659 +       if ((info->mode != IP6T_HL_SET) && (info->hop_limit == 0)) {
16660 +               printk(KERN_WARNING "HL: increment/decrement doesn't make sense with value 0\n");
16661 +               return 0;
16662 +       }
16663 +       
16664 +       return 1;
16665 +}
16666 +
16667 +static struct ip6t_target ip6t_HL = { { NULL, NULL }, "HL", 
16668 +       ip6t_hl_target, ip6t_hl_checkentry, NULL, THIS_MODULE };
16669 +
16670 +static int __init init(void)
16671 +{
16672 +       return ip6t_register_target(&ip6t_HL);
16673 +}
16674 +
16675 +static void __exit fini(void)
16676 +{
16677 +       ip6t_unregister_target(&ip6t_HL);
16678 +}
16679 +
16680 +module_init(init);
16681 +module_exit(fini);
16682 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv6/netfilter/ip6t_REJECT.c linux-2.6.7-rc3/net/ipv6/netfilter/ip6t_REJECT.c
16683 --- linux-2.6.7-rc3.org/net/ipv6/netfilter/ip6t_REJECT.c        1970-01-01 01:00:00.000000000 +0100
16684 +++ linux-2.6.7-rc3/net/ipv6/netfilter/ip6t_REJECT.c    2004-06-08 10:31:20.000000000 +0200
16685 @@ -0,0 +1,458 @@
16686 +/*
16687 + * IP6 tables REJECT target module
16688 + * Linux INET6 implementation
16689 + *
16690 + * Copyright (C)2003 USAGI/WIDE Project
16691 + *
16692 + * Authors:
16693 + *     Yasuyuki Kozakai        <yasuyuki.kozakai@toshiba.co.jp>
16694 + *
16695 + * Based on net/ipv4/netfilter/ipt_REJECT.c
16696 + *
16697 + * This program is free software; you can redistribute it and/or
16698 + * modify it under the terms of the GNU General Public License
16699 + * as published by the Free Software Foundation; either version
16700 + * 2 of the License, or (at your option) any later version.
16701 + */
16702 +
16703 +#include <linux/config.h>
16704 +#include <linux/module.h>
16705 +#include <linux/skbuff.h>
16706 +#include <linux/icmpv6.h>
16707 +#include <net/ipv6.h>
16708 +#include <net/tcp.h>
16709 +#include <net/icmp.h>
16710 +#include <net/ip6_fib.h>
16711 +#include <net/ip6_route.h>
16712 +#include <net/flow.h>
16713 +#include <linux/netfilter_ipv6/ip6_tables.h>
16714 +#include <linux/netfilter_ipv6/ip6t_REJECT.h>
16715 +
16716 +MODULE_AUTHOR("Yasuyuki KOZAKAI <yasuyuki.kozakai@toshiba.co.jp>");
16717 +MODULE_DESCRIPTION("IP6 tables REJECT target module");
16718 +MODULE_LICENSE("GPL");
16719 +
16720 +#if 0
16721 +#define DEBUGP printk
16722 +#else
16723 +#define DEBUGP(format, args...)
16724 +#endif
16725 +
16726 +#if 0
16727 +static void connection_attach(struct sk_buff *new_skb, struct nf_ct_info *nfct)
16728 +{
16729 +       void (*attach)(struct sk_buff *, struct nf_ct_info *);
16730 +       if (nfct && (attach = ip6_ct_attach) != NULL) {
16731 +               mb();
16732 +               attach(new_skb, nfct);
16733 +       }
16734 +}
16735 +#endif
16736 +
16737 +static int maybe_reroute(struct sk_buff *skb)
16738 +{
16739 +       if (skb->nfcache & NFC_ALTERED){
16740 +               if (ip6_route_me_harder(skb) != 0){
16741 +                       kfree_skb(skb);
16742 +                       return -EINVAL;
16743 +               }
16744 +       }
16745 +
16746 +       return dst_output(skb);
16747 +}
16748 +
16749 +/* Send RST reply */
16750 +static void send_reset(struct sk_buff *oldskb)
16751 +{
16752 +       struct sk_buff *nskb;
16753 +       struct tcphdr otcph, *tcph;
16754 +       unsigned int otcplen, tcphoff, hh_len;
16755 +       int needs_ack;
16756 +       struct ipv6hdr *oip6h = oldskb->nh.ipv6h, *ip6h;
16757 +       struct dst_entry *dst = NULL;
16758 +       u8 proto;
16759 +       struct flowi fl;
16760 +       proto = oip6h->nexthdr;
16761 +       int err;
16762 +
16763 +       if ((!(ipv6_addr_type(&oip6h->saddr) & IPV6_ADDR_UNICAST)) ||
16764 +           (!(ipv6_addr_type(&oip6h->daddr) & IPV6_ADDR_UNICAST))) {
16765 +               DEBUGP("ip6t_REJECT: addr is not unicast.\n");
16766 +               return;
16767 +       }
16768 +
16769 +       tcphoff = ipv6_skip_exthdr(oldskb, ((u8*)(oip6h+1) - oldskb->data),
16770 +                                  &proto, oldskb->len - ((u8*)(oip6h+1)
16771 +                                                         - oldskb->data));
16772 +
16773 +       if ((tcphoff < 0) || (tcphoff > oldskb->len)) {
16774 +               DEBUGP("ip6t_REJECT: Can't get TCP header.\n");
16775 +               return;
16776 +       }
16777 +
16778 +       otcplen = oldskb->len - tcphoff;
16779 +
16780 +       /* IP header checks: fragment, too short. */
16781 +       if ((proto != IPPROTO_TCP) || (otcplen < sizeof(struct tcphdr))) {
16782 +               DEBUGP("ip6t_REJECT: proto(%d) != IPPROTO_TCP, or too short. otcplen = %d\n",
16783 +                       proto, otcplen);
16784 +               return;
16785 +       }
16786 +
16787 +       if (skb_copy_bits(oldskb, tcphoff, &otcph, sizeof(struct tcphdr))) {
16788 +               if (net_ratelimit())
16789 +                       printk("ip6t_REJECT: Can't copy tcp header\n");
16790 +               return;
16791 +       }
16792 +
16793 +       /* No RST for RST. */
16794 +       if (otcph.rst) {
16795 +               DEBUGP("ip6t_REJECT: RST is set\n");
16796 +               return;
16797 +       }
16798 +
16799 +       /* Check checksum. */
16800 +       if (csum_ipv6_magic(&oip6h->saddr, &oip6h->daddr, otcplen, IPPROTO_TCP,
16801 +                           skb_checksum(oldskb, tcphoff, otcplen, 0))) {
16802 +               DEBUGP("ip6t_REJECT: TCP checksum is invalid\n");
16803 +               return;
16804 +       }
16805 +
16806 +       memset(&fl, 0, sizeof(fl));
16807 +       fl.proto = IPPROTO_TCP;
16808 +       ipv6_addr_copy(&fl.fl6_src, &oip6h->daddr);
16809 +       ipv6_addr_copy(&fl.fl6_dst, &oip6h->saddr);
16810 +       fl.fl_ip_sport = otcph.dest;
16811 +       fl.fl_ip_dport = otcph.source;
16812 +       err = ip6_dst_lookup(NULL, &dst, &fl);
16813 +       if (err) {
16814 +               if (net_ratelimit())
16815 +                       printk("ip6t_REJECT: can't find dst. err = %d\n", err);
16816 +               return;
16817 +       }
16818 +
16819 +       hh_len = (dst->dev->hard_header_len + 15)&~15;
16820 +       nskb = alloc_skb(hh_len + 15 + dst->header_len + sizeof(struct ipv6hdr)
16821 +                        + sizeof(struct tcphdr) + dst->trailer_len,
16822 +                        GFP_ATOMIC);
16823 +
16824 +       if (!nskb) {
16825 +               if (net_ratelimit())
16826 +                       printk("ip6t_REJECT: Can't alloc skb\n");
16827 +               dst_release(dst);
16828 +               return;
16829 +       }
16830 +
16831 +       nskb->dst = dst;
16832 +       dst_hold(dst);
16833 +
16834 +       skb_reserve(nskb, hh_len + dst->header_len);
16835 +
16836 +       ip6h = nskb->nh.ipv6h = (struct ipv6hdr *)
16837 +                                       skb_put(nskb, sizeof(struct ipv6hdr));
16838 +       ip6h->version = 6;
16839 +       ip6h->hop_limit = dst_metric(dst, RTAX_HOPLIMIT);
16840 +       ip6h->nexthdr = IPPROTO_TCP;
16841 +       ip6h->payload_len = htons(sizeof(struct tcphdr));
16842 +       ipv6_addr_copy(&ip6h->saddr, &oip6h->daddr);
16843 +       ipv6_addr_copy(&ip6h->daddr, &oip6h->saddr);
16844 +
16845 +       tcph = (struct tcphdr *)skb_put(nskb, sizeof(struct tcphdr));
16846 +       /* Truncate to length (no data) */
16847 +       tcph->doff = sizeof(struct tcphdr)/4;
16848 +       tcph->source = otcph.dest;
16849 +       tcph->dest = otcph.source;
16850 +
16851 +       if (otcph.ack) {
16852 +               needs_ack = 0;
16853 +               tcph->seq = otcph.ack_seq;
16854 +               tcph->ack_seq = 0;
16855 +       } else {
16856 +               needs_ack = 1;
16857 +               tcph->ack_seq = htonl(ntohl(otcph.seq) + otcph.syn + otcph.fin
16858 +                                     + otcplen - (otcph.doff<<2));
16859 +               tcph->seq = 0;
16860 +       }
16861 +
16862 +       /* Reset flags */
16863 +       ((u_int8_t *)tcph)[13] = 0;
16864 +       tcph->rst = 1;
16865 +       tcph->ack = needs_ack;
16866 +       tcph->window = 0;
16867 +       tcph->urg_ptr = 0;
16868 +       tcph->check = 0;
16869 +
16870 +       /* Adjust TCP checksum */
16871 +       tcph->check = csum_ipv6_magic(&nskb->nh.ipv6h->saddr,
16872 +                                     &nskb->nh.ipv6h->daddr,
16873 +                                     sizeof(struct tcphdr), IPPROTO_TCP,
16874 +                                     csum_partial((char *)tcph,
16875 +                                                  sizeof(struct tcphdr), 0));
16876 +
16877 +#if 0
16878 +       connection_attach(nskb, oldskb->nfct);
16879 +#endif
16880 +
16881 +       NF_HOOK(PF_INET6, NF_IP6_LOCAL_OUT, nskb, NULL, nskb->dst->dev,
16882 +               maybe_reroute);
16883 +
16884 +       dst_release(dst);
16885 +}
16886 +
16887 +static void send_unreach(struct sk_buff *skb_in, unsigned char code)
16888 +{
16889 +       struct ipv6hdr *ip6h, *hdr = skb_in->nh.ipv6h;
16890 +       struct icmp6hdr *icmp6h;
16891 +       struct dst_entry *dst = NULL;
16892 +       struct rt6_info *rt;
16893 +       int tmo;
16894 +       __u32 csum;
16895 +       unsigned int len, datalen, hh_len;
16896 +       int saddr_type, daddr_type;
16897 +       unsigned int ptr, ip6off;
16898 +       u8 proto;
16899 +       struct flowi fl;
16900 +       struct sk_buff *nskb;
16901 +       char *data;
16902 +
16903 +       saddr_type = ipv6_addr_type(&hdr->saddr);
16904 +       daddr_type = ipv6_addr_type(&hdr->daddr);
16905 +
16906 +       if ((!(saddr_type & IPV6_ADDR_UNICAST)) ||
16907 +           (!(daddr_type & IPV6_ADDR_UNICAST))) {
16908 +               DEBUGP("ip6t_REJECT: addr is not unicast.\n");
16909 +               return;
16910 +       }
16911 +
16912 +       ip6off = skb_in->nh.raw - skb_in->data;
16913 +       proto = hdr->nexthdr;
16914 +       ptr = ipv6_skip_exthdr(skb_in, ip6off + sizeof(struct ipv6hdr), &proto,
16915 +                              skb_in->len - ip6off);
16916 +
16917 +       if ((ptr < 0) || (ptr > skb_in->len)) {
16918 +               ptr = ip6off + sizeof(struct ipv6hdr);
16919 +               proto = hdr->nexthdr;
16920 +       } else if (proto == IPPROTO_ICMPV6) {
16921 +                u8 type;
16922 +
16923 +                if (skb_copy_bits(skb_in, ptr + offsetof(struct icmp6hdr,
16924 +                                                     icmp6_type), &type, 1)) {
16925 +                       DEBUGP("ip6t_REJECT: Can't get ICMPv6 type\n");
16926 +                       return;
16927 +               }
16928 +
16929 +               if (!(type & ICMPV6_INFOMSG_MASK)) {
16930 +                       DEBUGP("ip6t_REJECT: no reply to icmp error\n");
16931 +                       return;
16932 +               }
16933 +        } else if (proto == IPPROTO_UDP) {
16934 +               int plen = skb_in->len - (ptr - ip6off);
16935 +               uint16_t check;
16936 +
16937 +               if (plen < sizeof(struct udphdr)) {
16938 +                       DEBUGP("ip6t_REJECT: too short\n");
16939 +                       return;
16940 +               }
16941 +
16942 +               if (skb_copy_bits(skb_in, ptr + offsetof(struct udphdr, check),
16943 +                                 &check, 2)) {
16944 +                       if (net_ratelimit())
16945 +                               printk("ip6t_REJECT: can't get copy from skb");
16946 +                       return;
16947 +               }
16948 +
16949 +               if (check &&
16950 +                   csum_ipv6_magic(&hdr->saddr, &hdr->daddr, plen,
16951 +                                   IPPROTO_UDP,
16952 +                                   skb_checksum(skb_in, ptr, plen, 0))) {
16953 +                       DEBUGP("ip6t_REJECT: UDP checksum is invalid.\n");
16954 +                       return;
16955 +               }
16956 +       }
16957 +
16958 +       memset(&fl, 0, sizeof(fl));
16959 +       fl.proto = IPPROTO_ICMPV6;
16960 +       ipv6_addr_copy(&fl.fl6_src, &hdr->daddr);
16961 +       ipv6_addr_copy(&fl.fl6_dst, &hdr->saddr);
16962 +       fl.fl_icmp_type = ICMPV6_DEST_UNREACH;
16963 +       fl.fl_icmp_code = code;
16964 +
16965 +       if (ip6_dst_lookup(NULL, &dst, &fl)) {
16966 +               return;
16967 +       }
16968 +
16969 +       rt = (struct rt6_info *)dst;
16970 +       tmo = 1*HZ;
16971 +
16972 +       if (rt->rt6i_dst.plen < 128)
16973 +               tmo >>= ((128 - rt->rt6i_dst.plen)>>5);
16974 +
16975 +       if (!xrlim_allow(dst, tmo)) {
16976 +               if (net_ratelimit())
16977 +                       printk("ip6t_REJECT: rate limitted\n");
16978 +               goto dst_release_out;
16979 +       }
16980 +
16981 +       len = skb_in->len + sizeof(struct ipv6hdr) + sizeof(struct icmp6hdr);
16982 +
16983 +       if (len > dst_pmtu(dst))
16984 +               len = dst_pmtu(dst);
16985 +       if (len > IPV6_MIN_MTU)
16986 +               len = IPV6_MIN_MTU;
16987 +
16988 +       datalen = len - sizeof(struct ipv6hdr) - sizeof(struct icmp6hdr);
16989 +       hh_len = (rt->u.dst.dev->hard_header_len + 15)&~15;
16990 +
16991 +       nskb = alloc_skb(hh_len + 15 + dst->header_len + dst->trailer_len + len,
16992 +                        GFP_ATOMIC);
16993 +
16994 +       if (!nskb) {
16995 +               if (net_ratelimit())
16996 +                       printk("ip6t_REJECT: can't alloc skb\n");
16997 +               goto dst_release_out;
16998 +       }
16999 +
17000 +       nskb->priority = 0;
17001 +       nskb->dst = dst;
17002 +       dst_hold(dst);
17003 +
17004 +       skb_reserve(nskb, hh_len + dst->header_len);
17005 +
17006 +       ip6h = nskb->nh.ipv6h = (struct ipv6hdr *)
17007 +                                       skb_put(nskb, sizeof(struct ipv6hdr));
17008 +       ip6h->version = 6;
17009 +       ip6h->hop_limit = dst_metric(dst, RTAX_HOPLIMIT);
17010 +       ip6h->nexthdr = IPPROTO_ICMPV6;
17011 +       ip6h->payload_len = htons(datalen + sizeof(struct icmp6hdr));
17012 +       ipv6_addr_copy(&ip6h->saddr, &hdr->daddr);
17013 +       ipv6_addr_copy(&ip6h->daddr, &hdr->saddr);
17014 +
17015 +       icmp6h = (struct icmp6hdr *) skb_put(nskb, sizeof(struct icmp6hdr));
17016 +       icmp6h->icmp6_type = ICMPV6_DEST_UNREACH;
17017 +       icmp6h->icmp6_code = code;
17018 +       icmp6h->icmp6_cksum = 0;
17019 +
17020 +       data = skb_put(nskb, datalen);
17021 +
17022 +       csum = csum_partial((unsigned char *)icmp6h, sizeof(struct icmp6hdr), 0);
17023 +       csum = skb_copy_and_csum_bits(skb_in, ip6off, data, datalen, csum);
17024 +       icmp6h->icmp6_cksum = csum_ipv6_magic(&hdr->saddr, &hdr->daddr,
17025 +                                            datalen + sizeof(struct icmp6hdr),
17026 +                                            IPPROTO_ICMPV6, csum);
17027 +
17028 +#if 0
17029 +       connection_attach(nskb, skb_in->nfct);
17030 +#endif
17031 +       NF_HOOK(PF_INET6, NF_IP6_LOCAL_OUT, nskb, NULL, nskb->dst->dev,
17032 +               maybe_reroute);
17033 +
17034 +dst_release_out:
17035 +       dst_release(dst);
17036 +}
17037 +
17038 +static unsigned int reject6_target(struct sk_buff **pskb,
17039 +                          unsigned int hooknum,
17040 +                          const struct net_device *in,
17041 +                          const struct net_device *out,
17042 +                          const void *targinfo,
17043 +                          void *userinfo)
17044 +{
17045 +       const struct ip6t_reject_info *reject = targinfo;
17046 +
17047 +       DEBUGP(KERN_DEBUG "%s: medium point\n", __FUNCTION__);
17048 +       /* WARNING: This code causes reentry within ip6tables.
17049 +          This means that the ip6tables jump stack is now crap.  We
17050 +          must return an absolute verdict. --RR */
17051 +       switch (reject->with) {
17052 +       case IP6T_ICMP6_NO_ROUTE:
17053 +               send_unreach(*pskb, ICMPV6_NOROUTE);
17054 +               break;
17055 +       case IP6T_ICMP6_ADM_PROHIBITED:
17056 +               send_unreach(*pskb, ICMPV6_ADM_PROHIBITED);
17057 +               break;
17058 +       case IP6T_ICMP6_NOT_NEIGHBOUR:
17059 +               send_unreach(*pskb, ICMPV6_NOT_NEIGHBOUR);
17060 +               break;
17061 +       case IP6T_ICMP6_ADDR_UNREACH:
17062 +               send_unreach(*pskb, ICMPV6_ADDR_UNREACH);
17063 +               break;
17064 +       case IP6T_ICMP6_PORT_UNREACH:
17065 +               send_unreach(*pskb, ICMPV6_PORT_UNREACH);
17066 +               break;
17067 +       case IP6T_ICMP6_ECHOREPLY:
17068 +               /* Do nothing */
17069 +               break;
17070 +       case IP6T_TCP_RESET:
17071 +               send_reset(*pskb);
17072 +               break;
17073 +       default:
17074 +               if (net_ratelimit())
17075 +                       printk(KERN_WARNING "ip6t_REJECT: case %u not handled yet\n", reject->with);
17076 +               break;
17077 +       }
17078 +
17079 +       return NF_DROP;
17080 +}
17081 +
17082 +static int check(const char *tablename,
17083 +                const struct ip6t_entry *e,
17084 +                void *targinfo,
17085 +                unsigned int targinfosize,
17086 +                unsigned int hook_mask)
17087 +{
17088 +       const struct ip6t_reject_info *rejinfo = targinfo;
17089 +
17090 +       if (targinfosize != IP6T_ALIGN(sizeof(struct ip6t_reject_info))) {
17091 +               DEBUGP("ip6t_REJECT: targinfosize %u != 0\n", targinfosize);
17092 +               return 0;
17093 +       }
17094 +
17095 +       /* Only allow these for packet filtering. */
17096 +       if (strcmp(tablename, "filter") != 0) {
17097 +               DEBUGP("ip6t_REJECT: bad table `%s'.\n", tablename);
17098 +               return 0;
17099 +       }
17100 +
17101 +       if ((hook_mask & ~((1 << NF_IP6_LOCAL_IN)
17102 +                          | (1 << NF_IP6_FORWARD)
17103 +                          | (1 << NF_IP6_LOCAL_OUT))) != 0) {
17104 +               DEBUGP("ip6t_REJECT: bad hook mask %X\n", hook_mask);
17105 +               return 0;
17106 +       }
17107 +
17108 +       if (rejinfo->with == IP6T_ICMP6_ECHOREPLY) {
17109 +               printk("ip6t_REJECT: ECHOREPLY is not supported.\n");
17110 +               return 0;
17111 +       } else if (rejinfo->with == IP6T_TCP_RESET) {
17112 +               /* Must specify that it's a TCP packet */
17113 +               if (e->ipv6.proto != IPPROTO_TCP
17114 +                   || (e->ipv6.invflags & IP6T_INV_PROTO)) {
17115 +                       DEBUGP("ip6t_REJECT: TCP_RESET illegal for non-tcp\n");
17116 +                       return 0;
17117 +               }
17118 +       }
17119 +
17120 +       return 1;
17121 +}
17122 +
17123 +static struct ip6t_target ip6t_reject_reg = {
17124 +       .name           = "REJECT",
17125 +       .target         = reject6_target,
17126 +       .checkentry     = check,
17127 +       .me             = THIS_MODULE
17128 +};
17129 +
17130 +static int __init init(void)
17131 +{
17132 +       if (ip6t_register_target(&ip6t_reject_reg))
17133 +               return -EINVAL;
17134 +       return 0;
17135 +}
17136 +
17137 +static void __exit fini(void)
17138 +{
17139 +       ip6t_unregister_target(&ip6t_reject_reg);
17140 +}
17141 +
17142 +module_init(init);
17143 +module_exit(fini);
17144 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv6/netfilter/ip6t_ROUTE.c linux-2.6.7-rc3/net/ipv6/netfilter/ip6t_ROUTE.c
17145 --- linux-2.6.7-rc3.org/net/ipv6/netfilter/ip6t_ROUTE.c 1970-01-01 01:00:00.000000000 +0100
17146 +++ linux-2.6.7-rc3/net/ipv6/netfilter/ip6t_ROUTE.c     2004-06-08 10:37:08.000000000 +0200
17147 @@ -0,0 +1,289 @@
17148 +/*
17149 + * This implements the ROUTE v6 target, which enables you to setup unusual
17150 + * routes not supported by the standard kernel routing table.
17151 + *
17152 + * Copyright (C) 2003 Cedric de Launois <delaunois@info.ucl.ac.be>
17153 + *
17154 + * v 1.0 2003/08/05
17155 + *
17156 + * This software is distributed under GNU GPL v2, 1991
17157 + */
17158 +
17159 +#include <linux/module.h>
17160 +#include <linux/skbuff.h>
17161 +#include <linux/ipv6.h>
17162 +#include <linux/netfilter_ipv6/ip6_tables.h>
17163 +#include <linux/netfilter_ipv6/ip6t_ROUTE.h>
17164 +#include <linux/netdevice.h>
17165 +#include <net/ipv6.h>
17166 +#include <net/ndisc.h>
17167 +#include <net/ip6_route.h>
17168 +#include <linux/icmpv6.h>
17169 +
17170 +#if 1
17171 +#define DEBUGP printk
17172 +#else
17173 +#define DEBUGP(format, args...)
17174 +#endif
17175 +
17176 +#define NIP6(addr) \
17177 +       ntohs((addr).s6_addr16[0]), \
17178 +       ntohs((addr).s6_addr16[1]), \
17179 +       ntohs((addr).s6_addr16[2]), \
17180 +       ntohs((addr).s6_addr16[3]), \
17181 +       ntohs((addr).s6_addr16[4]), \
17182 +       ntohs((addr).s6_addr16[5]), \
17183 +       ntohs((addr).s6_addr16[6]), \
17184 +       ntohs((addr).s6_addr16[7])
17185 +
17186 +/* Route the packet according to the routing keys specified in
17187 + * route_info. Keys are :
17188 + *  - ifindex : 
17189 + *      0 if no oif preferred, 
17190 + *      otherwise set to the index of the desired oif
17191 + *  - route_info->gw :
17192 + *      0 if no gateway specified,
17193 + *      otherwise set to the next host to which the pkt must be routed
17194 + * If success, skb->dev is the output device to which the packet must 
17195 + * be sent and skb->dst is not NULL
17196 + *
17197 + * RETURN:  1 if the packet was succesfully routed to the 
17198 + *            destination desired
17199 + *          0 if the kernel routing table could not route the packet
17200 + *            according to the keys specified
17201 + */
17202 +static int 
17203 +route6(struct sk_buff *skb,
17204 +       unsigned int ifindex,
17205 +       const struct ip6t_route_target_info *route_info)
17206 +{
17207 +       struct rt6_info *rt = NULL;
17208 +       struct ipv6hdr *ipv6h = skb->nh.ipv6h;
17209 +       struct in6_addr *gw = (struct in6_addr*)&route_info->gw;
17210 +
17211 +       DEBUGP("ip6t_ROUTE: called with: ");
17212 +       DEBUGP("DST=%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x ", NIP6(ipv6h->daddr));
17213 +       DEBUGP("GATEWAY=%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x ", NIP6(*gw));
17214 +       DEBUGP("OUT=%s\n", route_info->oif);
17215 +       
17216 +       if (ipv6_addr_any(gw))
17217 +               rt = rt6_lookup(&ipv6h->daddr, &ipv6h->saddr, ifindex, 1);
17218 +       else
17219 +               rt = rt6_lookup(gw, &ipv6h->saddr, ifindex, 1);
17220 +
17221 +       if (!rt)
17222 +               goto no_route;
17223 +
17224 +       DEBUGP("ip6t_ROUTE: routing gives: ");
17225 +       DEBUGP("DST=%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x ", NIP6(rt->rt6i_dst.addr));
17226 +       DEBUGP("GATEWAY=%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x ", NIP6(rt->rt6i_gateway));
17227 +       DEBUGP("OUT=%s\n", rt->rt6i_dev->name);
17228 +
17229 +       if (ifindex && rt->rt6i_dev->ifindex!=ifindex)
17230 +               goto wrong_route;
17231 +       
17232 +       if (!rt->rt6i_nexthop) {
17233 +               DEBUGP("ip6t_ROUTE: discovering neighbour\n");
17234 +               rt->rt6i_nexthop = ndisc_get_neigh(rt->rt6i_dev, &rt->rt6i_dst.addr);
17235 +       }
17236 +
17237 +       /* Drop old route. */
17238 +       dst_release(skb->dst);
17239 +       skb->dst = &rt->u.dst;
17240 +       skb->dev = rt->rt6i_dev;
17241 +       return 1;
17242 +
17243 + wrong_route:
17244 +       dst_release(&rt->u.dst);
17245 + no_route:
17246 +       if (!net_ratelimit())
17247 +               return 0;
17248 +
17249 +       printk("ip6t_ROUTE: no explicit route found ");
17250 +       if (ifindex)
17251 +               printk("via interface %s ", route_info->oif);
17252 +       if (!ipv6_addr_any(gw))
17253 +               printk("via gateway %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x", NIP6(*gw));
17254 +       printk("\n");
17255 +       return 0;
17256 +}
17257 +
17258 +
17259 +/* Stolen from ip6_output_finish
17260 + * PRE : skb->dev is set to the device we are leaving by
17261 + *       skb->dst is not NULL
17262 + * POST: the packet is sent with the link layer header pushed
17263 + *       the packet is destroyed
17264 + */
17265 +static void ip_direct_send(struct sk_buff *skb)
17266 +{
17267 +       struct dst_entry *dst = skb->dst;
17268 +       struct hh_cache *hh = dst->hh;
17269 +
17270 +       if (hh) {
17271 +               read_lock_bh(&hh->hh_lock);
17272 +               memcpy(skb->data - 16, hh->hh_data, 16);
17273 +               read_unlock_bh(&hh->hh_lock);
17274 +               skb_push(skb, hh->hh_len);
17275 +               hh->hh_output(skb);
17276 +       } else if (dst->neighbour)
17277 +               dst->neighbour->output(skb);
17278 +       else {
17279 +               if (net_ratelimit())
17280 +                       DEBUGP(KERN_DEBUG "ip6t_ROUTE: no hdr & no neighbour cache!\n");
17281 +               kfree_skb(skb);
17282 +       }
17283 +}
17284 +
17285 +
17286 +static unsigned int 
17287 +route6_oif(const struct ip6t_route_target_info *route_info,
17288 +          struct sk_buff *skb) 
17289 +{
17290 +       unsigned int ifindex = 0;
17291 +       struct net_device *dev_out = NULL;
17292 +
17293 +       /* The user set the interface name to use.
17294 +        * Getting the current interface index.
17295 +        */
17296 +       if ((dev_out = dev_get_by_name(route_info->oif))) {
17297 +               ifindex = dev_out->ifindex;
17298 +       } else {
17299 +               /* Unknown interface name : packet dropped */
17300 +               if (net_ratelimit()) 
17301 +                       DEBUGP("ip6t_ROUTE: oif interface %s not found\n", route_info->oif);
17302 +
17303 +               if (route_info->flags & IP6T_ROUTE_CONTINUE)
17304 +                       return IP6T_CONTINUE;
17305 +               else
17306 +                       return NF_DROP;
17307 +       }
17308 +
17309 +       /* Trying the standard way of routing packets */
17310 +       if (route6(skb, ifindex, route_info)) {
17311 +               dev_put(dev_out);
17312 +               if (route_info->flags & IP6T_ROUTE_CONTINUE)
17313 +                       return IP6T_CONTINUE;
17314 +               
17315 +               ip_direct_send(skb);
17316 +               return NF_STOLEN;
17317 +       } else 
17318 +               return NF_DROP;
17319 +}
17320 +
17321 +
17322 +static unsigned int 
17323 +route6_gw(const struct ip6t_route_target_info *route_info,
17324 +         struct sk_buff *skb) 
17325 +{
17326 +       if (route6(skb, 0, route_info)) {
17327 +               if (route_info->flags & IP6T_ROUTE_CONTINUE)
17328 +                       return IP6T_CONTINUE;
17329 +
17330 +               ip_direct_send(skb);
17331 +               return NF_STOLEN;
17332 +       } else
17333 +               return NF_DROP;
17334 +}
17335 +
17336 +
17337 +static unsigned int 
17338 +ip6t_route_target(struct sk_buff **pskb,
17339 +                 unsigned int hooknum,
17340 +                 const struct net_device *in,
17341 +                 const struct net_device *out,
17342 +                 const void *targinfo,
17343 +                 void *userinfo)
17344 +{
17345 +       const struct ip6t_route_target_info *route_info = targinfo;
17346 +       struct sk_buff *skb = *pskb;
17347 +       struct in6_addr *gw = (struct in6_addr*)&route_info->gw;
17348 +
17349 +       if (route_info->flags & IP6T_ROUTE_CONTINUE)
17350 +               goto do_it;
17351 +
17352 +       /* If we are at PREROUTING or INPUT hook
17353 +        * the TTL isn't decreased by the IP stack
17354 +        */
17355 +       if (hooknum == NF_IP6_PRE_ROUTING ||
17356 +           hooknum == NF_IP6_LOCAL_IN) {
17357 +
17358 +               struct ipv6hdr *ipv6h = skb->nh.ipv6h;
17359 +
17360 +               if (ipv6h->hop_limit <= 1) {
17361 +                       /* Force OUTPUT device used as source address */
17362 +                       skb->dev = skb->dst->dev;
17363 +
17364 +                       icmpv6_send(skb, ICMPV6_TIME_EXCEED, 
17365 +                                   ICMPV6_EXC_HOPLIMIT, 0, skb->dev);
17366 +
17367 +                       return NF_DROP;
17368 +               }
17369 +
17370 +               ipv6h->hop_limit--;
17371 +       }
17372 +
17373 +
17374 + do_it:
17375 +       if (route_info->oif[0]) 
17376 +               return route6_oif(route_info, *pskb);
17377 +       
17378 +       if (!ipv6_addr_any(gw))
17379 +               return route6_gw(route_info, *pskb);
17380 +
17381 +       if (net_ratelimit()) 
17382 +               DEBUGP(KERN_DEBUG "ip6t_ROUTE: no parameter !\n");
17383 +
17384 +       return IP6T_CONTINUE;
17385 +}
17386 +
17387 +
17388 +static int 
17389 +ip6t_route_checkentry(const char *tablename,
17390 +                     const struct ip6t_entry *e,
17391 +                     void *targinfo,
17392 +                     unsigned int targinfosize,
17393 +                     unsigned int hook_mask)
17394 +{
17395 +       if (strcmp(tablename, "mangle") != 0) {
17396 +               printk("ip6t_ROUTE: can only be called from \"mangle\" table.\n");
17397 +               return 0;
17398 +       }
17399 +
17400 +       if (targinfosize != IP6T_ALIGN(sizeof(struct ip6t_route_target_info))) {
17401 +               printk(KERN_WARNING "ip6t_ROUTE: targinfosize %u != %Zu\n",
17402 +                      targinfosize,
17403 +                      IP6T_ALIGN(sizeof(struct ip6t_route_target_info)));
17404 +               return 0;
17405 +       }
17406 +
17407 +       return 1;
17408 +}
17409 +
17410 +
17411 +static struct ip6t_target ip6t_route_reg = {
17412 +       .name       = "ROUTE",
17413 +       .target     = ip6t_route_target,
17414 +       .checkentry = ip6t_route_checkentry,
17415 +       .me         = THIS_MODULE
17416 +};
17417 +
17418 +
17419 +static int __init init(void)
17420 +{
17421 +       printk(KERN_DEBUG "registering ipv6 ROUTE target\n");
17422 +       if (ip6t_register_target(&ip6t_route_reg))
17423 +               return -EINVAL;
17424 +
17425 +       return 0;
17426 +}
17427 +
17428 +
17429 +static void __exit fini(void)
17430 +{
17431 +       ip6t_unregister_target(&ip6t_route_reg);
17432 +}
17433 +
17434 +module_init(init);
17435 +module_exit(fini);
17436 +MODULE_LICENSE("GPL");
17437 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv6/netfilter/ip6t_TRACE.c linux-2.6.7-rc3/net/ipv6/netfilter/ip6t_TRACE.c
17438 --- linux-2.6.7-rc3.org/net/ipv6/netfilter/ip6t_TRACE.c 1970-01-01 01:00:00.000000000 +0100
17439 +++ linux-2.6.7-rc3/net/ipv6/netfilter/ip6t_TRACE.c     2004-06-08 10:37:30.000000000 +0200
17440 @@ -0,0 +1,65 @@
17441 +/* This is a module which is used for setting
17442 + * the NFC_TRACE flag in the nfcache field of an skb. 
17443 + */
17444 +#include <linux/module.h>
17445 +#include <linux/skbuff.h>
17446 +
17447 +#include <linux/netfilter_ipv6/ip6_tables.h>
17448 +
17449 +MODULE_LICENSE("GPL");
17450 +
17451 +static unsigned int
17452 +target(struct sk_buff **pskb,
17453 +       unsigned int hooknum,
17454 +       const struct net_device *in,
17455 +       const struct net_device *out,
17456 +       const void *targinfo,
17457 +       void *userinfo)
17458 +{
17459 +       (*pskb)->nfcache |= NFC_TRACE;
17460 +       return IP6T_CONTINUE;
17461 +}
17462 +
17463 +static int 
17464 +checkentry(const char *tablename,
17465 +                  const struct ip6t_entry *e,
17466 +           void *targinfo,
17467 +           unsigned int targinfosize,
17468 +           unsigned int hook_mask)
17469 +{
17470 +       if (targinfosize != 0) {
17471 +               printk(KERN_WARNING "TRACE: targinfosize %u != 0\n",
17472 +                      targinfosize);
17473 +               return 0;
17474 +       }
17475 +
17476 +       if (strcmp(tablename, "raw") != 0) {
17477 +               printk(KERN_WARNING "TRACE: can only be called from \"raw\" table, not \"%s\"\n", tablename);
17478 +               return 0;
17479 +       }
17480 +
17481 +       return 1;
17482 +}
17483 +
17484 +static struct ip6t_target ip6t_trace_reg = { 
17485 +       .name = "TRACE",
17486 +       .target = target, 
17487 +       .checkentry = checkentry, 
17488 +       .me = THIS_MODULE
17489 +};
17490 +
17491 +static int __init init(void)
17492 +{
17493 +       if (ip6t_register_target(&ip6t_trace_reg))
17494 +               return -EINVAL;
17495 +
17496 +       return 0;
17497 +}
17498 +
17499 +static void __exit fini(void)
17500 +{
17501 +       ip6t_unregister_target(&ip6t_trace_reg);
17502 +}
17503 +
17504 +module_init(init);
17505 +module_exit(fini);
17506 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv6/netfilter/ip6t_fuzzy.c linux-2.6.7-rc3/net/ipv6/netfilter/ip6t_fuzzy.c
17507 --- linux-2.6.7-rc3.org/net/ipv6/netfilter/ip6t_fuzzy.c 1970-01-01 01:00:00.000000000 +0100
17508 +++ linux-2.6.7-rc3/net/ipv6/netfilter/ip6t_fuzzy.c     2004-06-08 10:31:37.000000000 +0200
17509 @@ -0,0 +1,189 @@
17510 +/*
17511 + * This module implements a simple TSK FLC
17512 + * (Takagi-Sugeno-Kang Fuzzy Logic Controller) that aims
17513 + * to limit , in an adaptive and flexible way , the packet rate crossing
17514 + * a given stream . It serves as an initial and very simple (but effective)
17515 + * example of how Fuzzy Logic techniques can be applied to defeat DoS attacks.
17516 + *  As a matter of fact , Fuzzy Logic can help us to insert any "behavior"
17517 + * into our code in a precise , adaptive and efficient manner.
17518 + *  The goal is very similar to that of "limit" match , but using techniques of
17519 + * Fuzzy Control , that allow us to shape the transfer functions precisely ,
17520 + * avoiding over and undershoots - and stuff like that .
17521 + *
17522 + *
17523 + * 2002-08-10  Hime Aguiar e Oliveira Jr. <hime@engineer.com> : Initial version.
17524 + * 2002-08-17  : Changed to eliminate floating point operations .
17525 + * 2002-08-23  : Coding style changes .
17526 + * 2003-04-08  Maciej Soltysiak <solt@dns.toxicilms.tv> : IPv6 Port
17527 + */
17528 +
17529 +#include <linux/module.h>
17530 +#include <linux/skbuff.h>
17531 +#include <linux/ipv6.h>
17532 +#include <linux/random.h>
17533 +#include <net/tcp.h>
17534 +#include <linux/spinlock.h>
17535 +#include <linux/netfilter_ipv6/ip6_tables.h>
17536 +#include <linux/netfilter_ipv6/ip6t_fuzzy.h>
17537 +
17538 +/*
17539 + Packet Acceptance Rate - LOW and Packet Acceptance Rate - HIGH
17540 + Expressed in percentage
17541 +*/
17542 +
17543 +#define PAR_LOW                1/100
17544 +#define PAR_HIGH       1
17545 +
17546 +static spinlock_t fuzzy_lock = SPIN_LOCK_UNLOCKED;
17547 +
17548 +MODULE_AUTHOR("Hime Aguiar e Oliveira Junior <hime@engineer.com>");
17549 +MODULE_DESCRIPTION("IP tables Fuzzy Logic Controller match module");
17550 +MODULE_LICENSE("GPL");
17551 +
17552 +static  u_int8_t mf_high(u_int32_t tx,u_int32_t mini,u_int32_t maxi)
17553 +{
17554 +       if (tx >= maxi) return 100;
17555 +
17556 +       if (tx <= mini) return 0;
17557 +
17558 +       return ((100 * (tx-mini)) / (maxi-mini));
17559 +}
17560 +
17561 +static u_int8_t mf_low(u_int32_t tx,u_int32_t mini,u_int32_t maxi)
17562 +{
17563 +       if (tx <= mini) return 100;
17564 +
17565 +       if (tx >= maxi) return 0;
17566 +
17567 +       return ((100 * (maxi - tx)) / (maxi - mini));
17568 +
17569 +}
17570 +
17571 +static int
17572 +ip6t_fuzzy_match(const struct sk_buff *pskb,
17573 +              const struct net_device *in,
17574 +              const struct net_device *out,
17575 +              const void *matchinfo,
17576 +              int offset,
17577 +              const void *hdr,
17578 +              u_int16_t datalen,
17579 +              int *hotdrop)
17580 +{
17581 +       /* From userspace */
17582 +
17583 +       struct ip6t_fuzzy_info *info = (struct ip6t_fuzzy_info *) matchinfo;
17584 +
17585 +       u_int8_t random_number;
17586 +       unsigned long amount;
17587 +       u_int8_t howhigh, howlow;
17588 +
17589 +
17590 +       spin_lock_bh(&fuzzy_lock); /* Rise the lock */
17591 +
17592 +       info->bytes_total += pskb->len;
17593 +       info->packets_total++;
17594 +
17595 +       info->present_time = jiffies;
17596 +
17597 +       if (info->present_time >= info->previous_time)
17598 +               amount = info->present_time - info->previous_time;
17599 +       else {
17600 +               /* There was a transition : I choose to re-sample
17601 +                  and keep the old acceptance rate...
17602 +               */
17603 +
17604 +               amount = 0;
17605 +               info->previous_time = info->present_time;
17606 +               info->bytes_total = info->packets_total = 0;
17607 +            };
17608 +
17609 +       if ( amount > HZ/10) {/* More than 100 ms elapsed ... */
17610 +
17611 +               info->mean_rate = (u_int32_t) ((HZ * info->packets_total) \
17612 +                                       / amount);
17613 +
17614 +               info->previous_time = info->present_time;
17615 +               info->bytes_total = info->packets_total = 0;
17616 +
17617 +               howhigh = mf_high(info->mean_rate,info->minimum_rate,info->maximum_rate);
17618 +               howlow  = mf_low(info->mean_rate,info->minimum_rate,info->maximum_rate);
17619 +
17620 +               info->acceptance_rate = (u_int8_t) \
17621 +                               (howhigh * PAR_LOW + PAR_HIGH * howlow);
17622 +
17623 +       /* In fact, the above defuzzification would require a denominator
17624 +        * proportional to (howhigh+howlow) but, in this particular case,
17625 +        * that expression is constant.
17626 +        * An imediate consequence is that it is not necessary to call
17627 +        * both mf_high and mf_low - but to keep things understandable,
17628 +        * I did so.
17629 +        */
17630 +
17631 +       }
17632 +
17633 +       spin_unlock_bh(&fuzzy_lock); /* Release the lock */
17634 +
17635 +
17636 +       if (info->acceptance_rate < 100)
17637 +       {
17638 +               get_random_bytes((void *)(&random_number), 1);
17639 +
17640 +               /*  If within the acceptance , it can pass => don't match */
17641 +               if (random_number <= (255 * info->acceptance_rate) / 100)
17642 +                       return 0;
17643 +               else
17644 +                       return 1; /* It can't pass (It matches) */
17645 +       };
17646 +
17647 +       return 0; /* acceptance_rate == 100 % => Everything passes ... */
17648 +
17649 +}
17650 +
17651 +static int
17652 +ip6t_fuzzy_checkentry(const char *tablename,
17653 +                  const struct ip6t_ip6 *ip,
17654 +                  void *matchinfo,
17655 +                  unsigned int matchsize,
17656 +                  unsigned int hook_mask)
17657 +{
17658 +
17659 +       const struct ip6t_fuzzy_info *info = matchinfo;
17660 +
17661 +       if (matchsize != IP6T_ALIGN(sizeof(struct ip6t_fuzzy_info))) {
17662 +               printk("ip6t_fuzzy: matchsize %u != %u\n", matchsize,
17663 +                      IP6T_ALIGN(sizeof(struct ip6t_fuzzy_info)));
17664 +               return 0;
17665 +       }
17666 +
17667 +       if ((info->minimum_rate < MINFUZZYRATE) || (info->maximum_rate > MAXFUZZYRATE)
17668 +        || (info->minimum_rate >= info->maximum_rate)) {
17669 +               printk("ip6t_fuzzy: BAD limits , please verify !!!\n");
17670 +               return 0;
17671 +       }
17672 +
17673 +       return 1;
17674 +}
17675 +
17676 +static struct ip6t_match ip6t_fuzzy_reg = {
17677 +       {NULL, NULL},
17678 +       "fuzzy",
17679 +       ip6t_fuzzy_match,
17680 +       ip6t_fuzzy_checkentry,
17681 +       NULL,
17682 +       THIS_MODULE };
17683 +
17684 +static int __init init(void)
17685 +{
17686 +       if (ip6t_register_match(&ip6t_fuzzy_reg))
17687 +               return -EINVAL;
17688 +
17689 +       return 0;
17690 +}
17691 +
17692 +static void __exit fini(void)
17693 +{
17694 +       ip6t_unregister_match(&ip6t_fuzzy_reg);
17695 +}
17696 +
17697 +module_init(init);
17698 +module_exit(fini);
17699 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv6/netfilter/ip6t_nth.c linux-2.6.7-rc3/net/ipv6/netfilter/ip6t_nth.c
17700 --- linux-2.6.7-rc3.org/net/ipv6/netfilter/ip6t_nth.c   1970-01-01 01:00:00.000000000 +0100
17701 +++ linux-2.6.7-rc3/net/ipv6/netfilter/ip6t_nth.c       2004-06-08 10:31:42.000000000 +0200
17702 @@ -0,0 +1,173 @@
17703 +/*
17704 +  This is a module which is used for match support for every Nth packet
17705 +  This file is distributed under the terms of the GNU General Public
17706 +  License (GPL). Copies of the GPL can be obtained from:
17707 +     ftp://prep.ai.mit.edu/pub/gnu/GPL
17708 +
17709 +  2001-07-18 Fabrice MARIE <fabrice@netfilter.org> : initial implementation.
17710 +  2001-09-20 Richard Wagner (rwagner@cloudnet.com)
17711 +        * added support for multiple counters
17712 +        * added support for matching on individual packets
17713 +          in the counter cycle
17714 +  2003-04-30 Maciej Soltysiak <solt@dns.toxicfilms.tv> : IPv6 Port
17715 +
17716 +*/
17717 +
17718 +#include <linux/module.h>
17719 +#include <linux/skbuff.h>
17720 +#include <linux/ip.h>
17721 +#include <net/tcp.h>
17722 +#include <linux/spinlock.h>
17723 +#include <linux/netfilter_ipv6/ip6_tables.h>
17724 +#include <linux/netfilter_ipv6/ip6t_nth.h>
17725 +
17726 +MODULE_LICENSE("GPL");
17727 +
17728 +/*
17729 + * State information.
17730 + */
17731 +struct state {
17732 +       spinlock_t lock;
17733 +       u_int16_t number;
17734 +};
17735 +
17736 +static struct state states[IP6T_NTH_NUM_COUNTERS];
17737 +
17738 +static int
17739 +ip6t_nth_match(const struct sk_buff *pskb,
17740 +             const struct net_device *in,
17741 +             const struct net_device *out,
17742 +             const void *matchinfo,
17743 +             int offset,
17744 +             const void *hdr,
17745 +             u_int16_t datalen,
17746 +             int *hotdrop)
17747 +{
17748 +       /* Parameters from userspace */
17749 +       const struct ip6t_nth_info *info = matchinfo;
17750 +        unsigned counter = info->counter;
17751 +               if((counter < 0) || (counter >= IP6T_NTH_NUM_COUNTERS)) 
17752 +       {
17753 +                       printk(KERN_WARNING "nth: invalid counter %u. counter between 0 and %u\n", counter, IP6T_NTH_NUM_COUNTERS-1);
17754 +               return 0;
17755 +        };
17756 +
17757 +        spin_lock(&states[counter].lock);
17758 +
17759 +        /* Are we matching every nth packet?*/
17760 +        if (info->packet == 0xFF)
17761 +        {
17762 +               /* We're matching every nth packet and only every nth packet*/
17763 +               /* Do we match or invert match? */
17764 +               if (info->not == 0)
17765 +               {
17766 +                       if (states[counter].number == 0)
17767 +                       {
17768 +                               ++states[counter].number;
17769 +                               goto match;
17770 +                       }
17771 +                       if (states[counter].number >= info->every)
17772 +                               states[counter].number = 0; /* reset the counter */
17773 +                       else
17774 +                               ++states[counter].number;
17775 +                       goto dontmatch;
17776 +               }
17777 +               else
17778 +               {
17779 +                       if (states[counter].number == 0)
17780 +                       {
17781 +                               ++states[counter].number;
17782 +                               goto dontmatch;
17783 +                       }
17784 +                       if (states[counter].number >= info->every)
17785 +                               states[counter].number = 0;
17786 +                       else
17787 +                               ++states[counter].number;
17788 +                       goto match;
17789 +               }
17790 +        }
17791 +        else
17792 +        {
17793 +               /* We're using the --packet, so there must be a rule for every value */
17794 +               if (states[counter].number == info->packet)
17795 +               {
17796 +                       /* only increment the counter when a match happens */
17797 +                       if (states[counter].number >= info->every)
17798 +                               states[counter].number = 0; /* reset the counter */
17799 +                       else
17800 +                               ++states[counter].number;
17801 +                       goto match;
17802 +               }
17803 +               else
17804 +                       goto dontmatch;
17805 +       }
17806 +
17807 + dontmatch:
17808 +       /* don't match */
17809 +       spin_unlock(&states[counter].lock);
17810 +       return 0;
17811 +
17812 + match:
17813 +       spin_unlock(&states[counter].lock);
17814 +       return 1;
17815 +}
17816 +
17817 +static int
17818 +ip6t_nth_checkentry(const char *tablename,
17819 +                  const struct ip6t_ip6 *e,
17820 +                  void *matchinfo,
17821 +                  unsigned int matchsize,
17822 +                  unsigned int hook_mask)
17823 +{
17824 +       /* Parameters from userspace */
17825 +       const struct ip6t_nth_info *info = matchinfo;
17826 +        unsigned counter = info->counter;
17827 +        if((counter < 0) || (counter >= IP6T_NTH_NUM_COUNTERS)) 
17828 +       {
17829 +               printk(KERN_WARNING "nth: invalid counter %u. counter between 0 and %u\n", counter, IP6T_NTH_NUM_COUNTERS-1);
17830 +                       return 0;
17831 +               };
17832 +
17833 +       if (matchsize != IP6T_ALIGN(sizeof(struct ip6t_nth_info))) {
17834 +               printk("nth: matchsize %u != %u\n", matchsize,
17835 +                      IP6T_ALIGN(sizeof(struct ip6t_nth_info)));
17836 +               return 0;
17837 +       }
17838 +
17839 +       states[counter].number = info->startat;
17840 +
17841 +       return 1;
17842 +}
17843 +
17844 +static struct ip6t_match ip6t_nth_reg = { 
17845 +       {NULL, NULL},
17846 +       "nth",
17847 +       ip6t_nth_match,
17848 +       ip6t_nth_checkentry,
17849 +       NULL,
17850 +       THIS_MODULE };
17851 +
17852 +static int __init init(void)
17853 +{
17854 +       unsigned counter;
17855 +        memset(&states, 0, sizeof(states));
17856 +       if (ip6t_register_match(&ip6t_nth_reg))
17857 +               return -EINVAL;
17858 +
17859 +        for(counter = 0; counter < IP6T_NTH_NUM_COUNTERS; counter++) 
17860 +       {
17861 +               spin_lock_init(&(states[counter].lock));
17862 +        };
17863 +
17864 +       printk("ip6t_nth match loaded\n");
17865 +       return 0;
17866 +}
17867 +
17868 +static void __exit fini(void)
17869 +{
17870 +       ip6t_unregister_match(&ip6t_nth_reg);
17871 +       printk("ip6t_nth match unloaded\n");
17872 +}
17873 +
17874 +module_init(init);
17875 +module_exit(fini);
17876 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv6/netfilter/ip6t_owner.c linux-2.6.7-rc3/net/ipv6/netfilter/ip6t_owner.c
17877 --- linux-2.6.7-rc3.org/net/ipv6/netfilter/ip6t_owner.c 2004-06-07 21:14:56.000000000 +0200
17878 +++ linux-2.6.7-rc3/net/ipv6/netfilter/ip6t_owner.c     2004-06-08 10:40:01.000000000 +0200
17879 @@ -21,6 +21,39 @@
17880  MODULE_LICENSE("GPL");
17881  
17882  static int
17883 +match_comm(const struct sk_buff *skb, const char *comm)
17884 +{
17885 +       struct task_struct *p, *g;
17886 +       struct files_struct *files;
17887 +       int i;
17888 +
17889 +       read_lock(&tasklist_lock);
17890 +       do_each_thread(g, p) {
17891 +               if(strncmp(p->comm, comm, sizeof(p->comm)))
17892 +                       continue;
17893 +
17894 +               task_lock(p);
17895 +               files = p->files;
17896 +               if(files) {
17897 +                       read_lock(&files->file_lock);
17898 +                       for (i=0; i < files->max_fds; i++) {
17899 +                               if (fcheck_files(files, i) ==
17900 +                                   skb->sk->sk_socket->file) {
17901 +                                       read_unlock(&files->file_lock);
17902 +                                       task_unlock(p);
17903 +                                       read_unlock(&tasklist_lock);
17904 +                                       return 1;
17905 +                               }
17906 +                       }
17907 +                       read_unlock(&files->file_lock);
17908 +               }
17909 +               task_unlock(p);
17910 +       } while_each_thread(g, p);
17911 +       read_unlock(&tasklist_lock);
17912 +       return 0;
17913 +}
17914 +
17915 +static int
17916  match_pid(const struct sk_buff *skb, pid_t pid)
17917  {
17918         struct task_struct *p;
17919 @@ -125,6 +158,12 @@
17920                         return 0;
17921         }
17922  
17923 +       if(info->match & IP6T_OWNER_COMM) {
17924 +               if (!match_comm(skb, info->comm) ^
17925 +                   !!(info->invert & IP6T_OWNER_COMM))
17926 +                       return 0;
17927 +       }
17928 +
17929         return 1;
17930  }
17931  
17932 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv6/netfilter/ip6t_policy.c linux-2.6.7-rc3/net/ipv6/netfilter/ip6t_policy.c
17933 --- linux-2.6.7-rc3.org/net/ipv6/netfilter/ip6t_policy.c        1970-01-01 01:00:00.000000000 +0100
17934 +++ linux-2.6.7-rc3/net/ipv6/netfilter/ip6t_policy.c    2004-06-08 10:42:36.000000000 +0200
17935 @@ -0,0 +1,201 @@
17936 +/* IP tables module for matching IPsec policy
17937 + *
17938 + * Copyright (c) 2004 Patrick McHardy, <kaber@trash.net>
17939 + *
17940 + * This program is free software; you can redistribute it and/or modify
17941 + * it under the terms of the GNU General Public License version 2 as
17942 + * published by the Free Software Foundation.
17943 + */
17944 +
17945 +#include <linux/kernel.h>
17946 +#include <linux/config.h>
17947 +#include <linux/module.h>
17948 +#include <linux/skbuff.h>
17949 +#include <linux/init.h>
17950 +#include <net/xfrm.h>
17951 +
17952 +#include <linux/netfilter_ipv6.h>
17953 +#include <linux/netfilter_ipv6/ip6t_policy.h>
17954 +#include <linux/netfilter_ipv6/ip6_tables.h>
17955 +
17956 +MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
17957 +MODULE_DESCRIPTION("IPtables IPsec policy matching module");
17958 +MODULE_LICENSE("GPL");
17959 +
17960 +
17961 +static inline int ip6_masked_addrcmp(struct in6_addr addr1,
17962 +                                     struct in6_addr mask,
17963 +                                     struct in6_addr addr2)
17964 +{
17965 +       int i;
17966 +
17967 +       for (i = 0; i < 16; i++) {
17968 +               if ((addr1.s6_addr[i] & mask.s6_addr[i]) !=
17969 +                   (addr2.s6_addr[i] & mask.s6_addr[i]))
17970 +                       return 1;
17971 +       }
17972 +       return 0;
17973 +}
17974 +
17975 +
17976 +static inline int
17977 +match_xfrm_state(struct xfrm_state *x, const struct ip6t_policy_elem *e)
17978 +{
17979 +#define MISMATCH(x,y)  (e->match.x && ((e->x != (y)) ^ e->invert.x))
17980 +       
17981 +       struct in6_addr xfrm_saddr, xfrm_daddr;
17982 +       
17983 +       if ((e->match.saddr
17984 +            && (ip6_masked_addrcmp(xfrm_saddr, e->saddr, e->smask))
17985 +               ^ e->invert.saddr ) ||
17986 +           (e->match.daddr
17987 +            && (ip6_masked_addrcmp(xfrm_daddr, e->daddr, e->dmask))
17988 +               ^ e->invert.daddr ) ||
17989 +           MISMATCH(proto, x->id.proto) ||
17990 +           MISMATCH(mode, x->props.mode) ||
17991 +           MISMATCH(spi, x->id.spi) ||
17992 +           MISMATCH(reqid, x->props.reqid))
17993 +               return 0;
17994 +       return 1;
17995 +}
17996 +
17997 +static int
17998 +match_policy_in(const struct sk_buff *skb, const struct ip6t_policy_info *info)
17999 +{
18000 +       const struct ip6t_policy_elem *e;
18001 +       struct sec_path *sp = skb->sp;
18002 +       int strict = info->flags & POLICY_MATCH_STRICT;
18003 +       int i, pos;
18004 +
18005 +       if (sp == NULL)
18006 +               return -1;
18007 +       if (strict && info->len != sp->len)
18008 +               return 0;
18009 +
18010 +       for (i = sp->len - 1; i >= 0; i--) {
18011 +               pos = strict ? i - sp->len + 1 : 0;
18012 +               if (pos >= info->len)
18013 +                       return 0;
18014 +               e = &info->pol[pos];
18015 +
18016 +               if (match_xfrm_state(sp->x[i].xvec, e)) {
18017 +                       if (!strict)
18018 +                               return 1;
18019 +               } else if (strict)
18020 +                       return 0;
18021 +       }
18022 +
18023 +       return strict ? 1 : 0;
18024 +}
18025 +
18026 +static int
18027 +match_policy_out(const struct sk_buff *skb, const struct ip6t_policy_info *info)
18028 +{
18029 +       const struct ip6t_policy_elem *e;
18030 +       struct dst_entry *dst = skb->dst;
18031 +       int strict = info->flags & POLICY_MATCH_STRICT;
18032 +       int i, pos;
18033 +
18034 +       if (dst->xfrm == NULL)
18035 +               return -1;
18036 +
18037 +       for (i = 0; dst && dst->xfrm; dst = dst->child, i++) {
18038 +               pos = strict ? i : 0;
18039 +               if (pos >= info->len)
18040 +                       return 0;
18041 +               e = &info->pol[pos];
18042 +
18043 +               if (match_xfrm_state(dst->xfrm, e)) {
18044 +                       if (!strict)
18045 +                               return 1;
18046 +               } else if (strict)
18047 +                       return 0;
18048 +       }
18049 +
18050 +       return strict ? 1 : 0;
18051 +}
18052 +
18053 +static int match(const struct sk_buff *skb,
18054 +                 const struct net_device *in,
18055 +                 const struct net_device *out,
18056 +                 const void *matchinfo,
18057 +                int offset,
18058 +                const void *hdr,
18059 +                u_int16_t datalen,
18060 +                int *hotdrop)
18061 +{
18062 +       const struct ip6t_policy_info *info = matchinfo;
18063 +       int ret;
18064 +
18065 +       if (info->flags & POLICY_MATCH_IN)
18066 +               ret = match_policy_in(skb, info);
18067 +       else
18068 +               ret = match_policy_out(skb, info);
18069 +
18070 +       if (ret < 0) {
18071 +               if (info->flags & POLICY_MATCH_NONE)
18072 +                       ret = 1;
18073 +               else
18074 +                       ret = 0;
18075 +       } else if (info->flags & POLICY_MATCH_NONE)
18076 +               ret = 0;
18077 +
18078 +       return ret;
18079 +}
18080 +
18081 +static int checkentry(const char *tablename, const struct ip6t_ip6 *ip,
18082 +                      void *matchinfo, unsigned int matchsize,
18083 +                      unsigned int hook_mask)
18084 +{
18085 +       struct ip6t_policy_info *info = matchinfo;
18086 +
18087 +       if (matchsize != IP6T_ALIGN(sizeof(*info))) {
18088 +               printk(KERN_ERR "ip6t_policy: matchsize %u != %u\n",
18089 +                      matchsize, IP6T_ALIGN(sizeof(*info)));
18090 +               return 0;
18091 +       }
18092 +       if (!(info->flags & (POLICY_MATCH_IN|POLICY_MATCH_OUT))) {
18093 +               printk(KERN_ERR "ip6t_policy: neither incoming nor "
18094 +                               "outgoing policy selected\n");
18095 +               return 0;
18096 +       }
18097 +       if (hook_mask & (1 << NF_IP6_PRE_ROUTING | 1 << NF_IP6_LOCAL_IN)
18098 +           && info->flags & POLICY_MATCH_OUT) {
18099 +               printk(KERN_ERR "ip6t_policy: output policy not valid in "
18100 +                               "PRE_ROUTING and INPUT\n");
18101 +               return 0;
18102 +       }
18103 +       if (hook_mask & (1 << NF_IP6_POST_ROUTING | 1 << NF_IP6_LOCAL_OUT)
18104 +           && info->flags & POLICY_MATCH_IN) {
18105 +               printk(KERN_ERR "ip6t_policy: input policy not valid in "
18106 +                               "POST_ROUTING and OUTPUT\n");
18107 +               return 0;
18108 +       }
18109 +       if (info->len > POLICY_MAX_ELEM) {
18110 +               printk(KERN_ERR "ip6t_policy: too many policy elements\n");
18111 +               return 0;
18112 +       }
18113 +
18114 +       return 1;
18115 +}
18116 +
18117 +static struct ip6t_match policy_match =
18118 +{
18119 +       .name           = "policy",
18120 +       .match          = match,
18121 +       .checkentry     = checkentry,
18122 +       .me             = THIS_MODULE,
18123 +};
18124 +
18125 +static int __init init(void)
18126 +{
18127 +       return ip6t_register_match(&policy_match);
18128 +}
18129 +
18130 +static void __exit fini(void)
18131 +{
18132 +       ip6t_unregister_match(&policy_match);
18133 +}
18134 +
18135 +module_init(init);
18136 +module_exit(fini);
18137 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv6/netfilter/ip6t_random.c linux-2.6.7-rc3/net/ipv6/netfilter/ip6t_random.c
18138 --- linux-2.6.7-rc3.org/net/ipv6/netfilter/ip6t_random.c        1970-01-01 01:00:00.000000000 +0100
18139 +++ linux-2.6.7-rc3/net/ipv6/netfilter/ip6t_random.c    2004-06-08 10:31:56.000000000 +0200
18140 @@ -0,0 +1,97 @@
18141 +/*
18142 +  This is a module which is used for a "random" match support.
18143 +  This file is distributed under the terms of the GNU General Public
18144 +  License (GPL). Copies of the GPL can be obtained from:
18145 +     ftp://prep.ai.mit.edu/pub/gnu/GPL
18146 +
18147 +  2001-10-14 Fabrice MARIE <fabrice@netfilter.org> : initial implementation.
18148 +  2003-04-30 Maciej Soltysiak <solt@dns.toxicfilms.tv> : IPv6 Port
18149 +*/
18150 +
18151 +#include <linux/module.h>
18152 +#include <linux/skbuff.h>
18153 +#include <linux/ip.h>
18154 +#include <linux/random.h>
18155 +#include <net/tcp.h>
18156 +#include <linux/spinlock.h>
18157 +#include <linux/netfilter_ipv6/ip6_tables.h>
18158 +#include <linux/netfilter_ipv6/ip6t_random.h>
18159 +
18160 +MODULE_LICENSE("GPL");
18161 +
18162 +static int
18163 +ip6t_rand_match(const struct sk_buff *pskb,
18164 +              const struct net_device *in,
18165 +              const struct net_device *out,
18166 +              const void *matchinfo,
18167 +              int offset,
18168 +              const void *hdr,
18169 +              u_int16_t datalen,
18170 +              int *hotdrop)
18171 +{
18172 +       /* Parameters from userspace */
18173 +       const struct ip6t_rand_info *info = matchinfo;
18174 +       u_int8_t random_number;
18175 +
18176 +       /* get 1 random number from the kernel random number generation routine */
18177 +       get_random_bytes((void *)(&random_number), 1);
18178 +
18179 +       /* Do we match ? */
18180 +       if (random_number <= info->average)
18181 +               return 1;
18182 +       else
18183 +               return 0;
18184 +}
18185 +
18186 +static int
18187 +ip6t_rand_checkentry(const char *tablename,
18188 +                  const struct ip6t_ip6 *e,
18189 +                  void *matchinfo,
18190 +                  unsigned int matchsize,
18191 +                  unsigned int hook_mask)
18192 +{
18193 +       /* Parameters from userspace */
18194 +       const struct ip6t_rand_info *info = matchinfo;
18195 +
18196 +       if (matchsize != IP6T_ALIGN(sizeof(struct ip6t_rand_info))) {
18197 +               printk("ip6t_random: matchsize %u != %u\n", matchsize,
18198 +                      IP6T_ALIGN(sizeof(struct ip6t_rand_info)));
18199 +               return 0;
18200 +       }
18201 +
18202 +       /* must be  1 <= average % <= 99 */
18203 +       /* 1  x 2.55 = 2   */
18204 +       /* 99 x 2.55 = 252 */
18205 +       if ((info->average < 2) || (info->average > 252)) {
18206 +               printk("ip6t_random:  invalid average %u\n", info->average);
18207 +               return 0;
18208 +       }
18209 +
18210 +       return 1;
18211 +}
18212 +
18213 +static struct ip6t_match ip6t_rand_reg = { 
18214 +       {NULL, NULL},
18215 +       "random",
18216 +       ip6t_rand_match,
18217 +       ip6t_rand_checkentry,
18218 +       NULL,
18219 +       THIS_MODULE };
18220 +
18221 +static int __init init(void)
18222 +{
18223 +       if (ip6t_register_match(&ip6t_rand_reg))
18224 +               return -EINVAL;
18225 +
18226 +       printk("ip6t_random match loaded\n");
18227 +       return 0;
18228 +}
18229 +
18230 +static void __exit fini(void)
18231 +{
18232 +       ip6t_unregister_match(&ip6t_rand_reg);
18233 +       printk("ip6t_random match unloaded\n");
18234 +}
18235 +
18236 +module_init(init);
18237 +module_exit(fini);
18238 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv6/netfilter/ip6table_filter.c linux-2.6.7-rc3/net/ipv6/netfilter/ip6table_filter.c
18239 --- linux-2.6.7-rc3.org/net/ipv6/netfilter/ip6table_filter.c    2004-06-07 21:13:37.000000000 +0200
18240 +++ linux-2.6.7-rc3/net/ipv6/netfilter/ip6table_filter.c        2004-06-08 10:37:30.000000000 +0200
18241 @@ -58,7 +58,7 @@
18242                 0,
18243                 sizeof(struct ip6t_entry),
18244                 sizeof(struct ip6t_standard),
18245 -               0, { 0, 0 }, { } },
18246 +               0, NULL, 0, { 0, 0 }, { } },
18247               { { { { IP6T_ALIGN(sizeof(struct ip6t_standard_target)), "" } }, { } },
18248                 -NF_ACCEPT - 1 } },
18249             /* FORWARD */
18250 @@ -66,7 +66,7 @@
18251                 0,
18252                 sizeof(struct ip6t_entry),
18253                 sizeof(struct ip6t_standard),
18254 -               0, { 0, 0 }, { } },
18255 +               0, NULL, 0, { 0, 0 }, { } },
18256               { { { { IP6T_ALIGN(sizeof(struct ip6t_standard_target)), "" } }, { } },
18257                 -NF_ACCEPT - 1 } },
18258             /* LOCAL_OUT */
18259 @@ -74,7 +74,7 @@
18260                 0,
18261                 sizeof(struct ip6t_entry),
18262                 sizeof(struct ip6t_standard),
18263 -               0, { 0, 0 }, { } },
18264 +               0, NULL, 0, { 0, 0 }, { } },
18265               { { { { IP6T_ALIGN(sizeof(struct ip6t_standard_target)), "" } }, { } },
18266                 -NF_ACCEPT - 1 } }
18267      },
18268 @@ -83,7 +83,7 @@
18269         0,
18270         sizeof(struct ip6t_entry),
18271         sizeof(struct ip6t_error),
18272 -       0, { 0, 0 }, { } },
18273 +       0, NULL, 0, { 0, 0 }, { } },
18274        { { { { IP6T_ALIGN(sizeof(struct ip6t_error_target)), IP6T_ERROR_TARGET } },
18275           { } },
18276         "ERROR"
18277 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv6/netfilter/ip6table_mangle.c linux-2.6.7-rc3/net/ipv6/netfilter/ip6table_mangle.c
18278 --- linux-2.6.7-rc3.org/net/ipv6/netfilter/ip6table_mangle.c    2004-06-07 21:14:05.000000000 +0200
18279 +++ linux-2.6.7-rc3/net/ipv6/netfilter/ip6table_mangle.c        2004-06-08 10:37:30.000000000 +0200
18280 @@ -73,7 +73,7 @@
18281                 0,
18282                 sizeof(struct ip6t_entry),
18283                 sizeof(struct ip6t_standard),
18284 -               0, { 0, 0 }, { } },
18285 +               0, NULL, 0, { 0, 0 }, { } },
18286               { { { { IP6T_ALIGN(sizeof(struct ip6t_standard_target)), "" } }, { } },
18287                 -NF_ACCEPT - 1 } },
18288             /* LOCAL_IN */
18289 @@ -81,7 +81,7 @@
18290                 0,
18291                 sizeof(struct ip6t_entry),
18292                 sizeof(struct ip6t_standard),
18293 -               0, { 0, 0 }, { } },
18294 +               0, NULL, 0, { 0, 0 }, { } },
18295               { { { { IP6T_ALIGN(sizeof(struct ip6t_standard_target)), "" } }, { } },
18296                 -NF_ACCEPT - 1 } },
18297             /* FORWARD */
18298 @@ -89,7 +89,7 @@
18299                 0,
18300                 sizeof(struct ip6t_entry),
18301                 sizeof(struct ip6t_standard),
18302 -               0, { 0, 0 }, { } },
18303 +               0, NULL, 0, { 0, 0 }, { } },
18304               { { { { IP6T_ALIGN(sizeof(struct ip6t_standard_target)), "" } }, { } },
18305                 -NF_ACCEPT - 1 } },
18306             /* LOCAL_OUT */
18307 @@ -97,7 +97,7 @@
18308                 0,
18309                 sizeof(struct ip6t_entry),
18310                 sizeof(struct ip6t_standard),
18311 -               0, { 0, 0 }, { } },
18312 +               0, NULL, 0, { 0, 0 }, { } },
18313               { { { { IP6T_ALIGN(sizeof(struct ip6t_standard_target)), "" } }, { } },
18314                 -NF_ACCEPT - 1 } },
18315             /* POST_ROUTING */
18316 @@ -105,7 +105,7 @@
18317                 0,
18318                 sizeof(struct ip6t_entry),
18319                 sizeof(struct ip6t_standard),
18320 -               0, { 0, 0 }, { } },
18321 +               0, NULL, 0, { 0, 0 }, { } },
18322               { { { { IP6T_ALIGN(sizeof(struct ip6t_standard_target)), "" } }, { } },
18323                 -NF_ACCEPT - 1 } }
18324      },
18325 @@ -114,7 +114,7 @@
18326         0,
18327         sizeof(struct ip6t_entry),
18328         sizeof(struct ip6t_error),
18329 -       0, { 0, 0 }, { } },
18330 +       0, NULL, 0, { 0, 0 }, { } },
18331        { { { { IP6T_ALIGN(sizeof(struct ip6t_error_target)), IP6T_ERROR_TARGET } },
18332           { } },
18333         "ERROR"
18334 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv6/netfilter/ip6table_raw.c linux-2.6.7-rc3/net/ipv6/netfilter/ip6table_raw.c
18335 --- linux-2.6.7-rc3.org/net/ipv6/netfilter/ip6table_raw.c       2004-06-07 21:14:43.000000000 +0200
18336 +++ linux-2.6.7-rc3/net/ipv6/netfilter/ip6table_raw.c   2004-06-08 10:37:30.000000000 +0200
18337 @@ -52,7 +52,7 @@
18338                 0,
18339                 sizeof(struct ip6t_entry),
18340                 sizeof(struct ip6t_standard),
18341 -               0, { 0, 0 }, { } },
18342 +               0, NULL, 0, { 0, 0 }, { } },
18343               { { { { IP6T_ALIGN(sizeof(struct ip6t_standard_target)), "" } }, { } },
18344                 -NF_ACCEPT - 1 } },
18345             /* LOCAL_OUT */
18346 @@ -60,7 +60,7 @@
18347                 0,
18348                 sizeof(struct ip6t_entry),
18349                 sizeof(struct ip6t_standard),
18350 -               0, { 0, 0 }, { } },
18351 +               0, NULL, 0, { 0, 0 }, { } },
18352               { { { { IP6T_ALIGN(sizeof(struct ip6t_standard_target)), "" } }, { } },
18353                 -NF_ACCEPT - 1 } },
18354      },
18355 @@ -69,7 +69,7 @@
18356         0,
18357         sizeof(struct ip6t_entry),
18358         sizeof(struct ip6t_error),
18359 -       0, { 0, 0 }, { } },
18360 +       0, NULL, 0, { 0, 0 }, { } },
18361        { { { { IP6T_ALIGN(sizeof(struct ip6t_error_target)), IP6T_ERROR_TARGET } },
18362           { } },
18363         "ERROR"
18364 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/ipv6/sit.c linux-2.6.7-rc3/net/ipv6/sit.c
18365 --- linux-2.6.7-rc3.org/net/ipv6/sit.c  2004-06-07 21:14:59.000000000 +0200
18366 +++ linux-2.6.7-rc3/net/ipv6/sit.c      2004-06-08 10:30:55.000000000 +0200
18367 @@ -388,13 +388,7 @@
18368                 skb->dev = tunnel->dev;
18369                 dst_release(skb->dst);
18370                 skb->dst = NULL;
18371 -#ifdef CONFIG_NETFILTER
18372 -               nf_conntrack_put(skb->nfct);
18373 -               skb->nfct = NULL;
18374 -#ifdef CONFIG_NETFILTER_DEBUG
18375 -               skb->nf_debug = 0;
18376 -#endif
18377 -#endif
18378 +               nf_reset(skb);
18379                 ipip6_ecn_decapsulate(iph, skb);
18380                 netif_rx(skb);
18381                 read_unlock(&ipip6_lock);
18382 @@ -580,13 +574,7 @@
18383         if ((iph->ttl = tiph->ttl) == 0)
18384                 iph->ttl        =       iph6->hop_limit;
18385  
18386 -#ifdef CONFIG_NETFILTER
18387 -       nf_conntrack_put(skb->nfct);
18388 -       skb->nfct = NULL;
18389 -#ifdef CONFIG_NETFILTER_DEBUG
18390 -       skb->nf_debug = 0;
18391 -#endif
18392 -#endif
18393 +       nf_reset(skb);
18394  
18395         IPTUNNEL_XMIT();
18396         tunnel->recursion--;
18397 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/xfrm/xfrm_input.c linux-2.6.7-rc3/net/xfrm/xfrm_input.c
18398 --- linux-2.6.7-rc3.org/net/xfrm/xfrm_input.c   2004-06-07 21:13:35.000000000 +0200
18399 +++ linux-2.6.7-rc3/net/xfrm/xfrm_input.c       2004-06-08 10:38:44.000000000 +0200
18400 @@ -29,6 +29,9 @@
18401         if (!sp)
18402                 return NULL;
18403  
18404 +#ifdef CONFIG_NETFILTER
18405 +       sp->decap_done = 0;
18406 +#endif
18407         sp->len = 0;
18408         if (src) {
18409                 int i;
18410 diff -Nur --exclude '*.orig' linux-2.6.7-rc3.org/net/xfrm/xfrm_policy.c linux-2.6.7-rc3/net/xfrm/xfrm_policy.c
18411 --- linux-2.6.7-rc3.org/net/xfrm/xfrm_policy.c  2004-06-07 21:14:24.000000000 +0200
18412 +++ linux-2.6.7-rc3/net/xfrm/xfrm_policy.c      2004-06-08 10:38:46.000000000 +0200
18413 @@ -21,6 +21,7 @@
18414  #include <linux/workqueue.h>
18415  #include <linux/notifier.h>
18416  #include <linux/netdevice.h>
18417 +#include <linux/netfilter.h>
18418  #include <net/xfrm.h>
18419  #include <net/ip.h>
18420  
18421 @@ -911,6 +912,7 @@
18422  
18423         if (_decode_session(skb, &fl, family) < 0)
18424                 return 0;
18425 +       nf_nat_decode_session(skb, &fl, family);
18426  
18427         /* First, check used SA against their selectors. */
18428         if (skb->sp) {
This page took 1.486027 seconds and 3 git commands to generate.