]> git.pld-linux.org Git - packages/kernel.git/blob - 2.6.5-patch-o-matic-ng-extra-20040322.patch
- obsolete
[packages/kernel.git] / 2.6.5-patch-o-matic-ng-extra-20040322.patch
1 diff -Nur --exclude '*.orig' linux-2.6.5-rc2.org/include/linux/netfilter_ipv4/ip_conntrack.h linux-2.6.5-rc2/include/linux/netfilter_ipv4/ip_conntrack.h
2 --- linux-2.6.5-rc2.org/include/linux/netfilter_ipv4/ip_conntrack.h     2004-03-22 08:57:53.000000000 +0000
3 +++ linux-2.6.5-rc2/include/linux/netfilter_ipv4/ip_conntrack.h 2004-03-22 09:08:35.000000000 +0000
4 @@ -206,6 +206,10 @@
5         } nat;
6  #endif /* CONFIG_IP_NF_NAT_NEEDED */
7  
8 +#if defined(CONFIG_IP_NF_CONNTRACK_MARK)
9 +       unsigned long mark;
10 +#endif
11 +
12  };
13  
14  /* get master conntrack via master expectation */
15 diff -Nur --exclude '*.orig' linux-2.6.5-rc2.org/include/linux/netfilter_ipv4/ipt_CONNMARK.h linux-2.6.5-rc2/include/linux/netfilter_ipv4/ipt_CONNMARK.h
16 --- linux-2.6.5-rc2.org/include/linux/netfilter_ipv4/ipt_CONNMARK.h     1970-01-01 00:00:00.000000000 +0000
17 +++ linux-2.6.5-rc2/include/linux/netfilter_ipv4/ipt_CONNMARK.h 2004-03-22 09:08:35.000000000 +0000
18 @@ -0,0 +1,25 @@
19 +#ifndef _IPT_CONNMARK_H_target
20 +#define _IPT_CONNMARK_H_target
21 +
22 +/* Copyright (C) 2002,2004 MARA Systems AB <http://www.marasystems.com>
23 + * by Henrik Nordstrom <hno@marasystems.com>
24 + *
25 + * This program is free software; you can redistribute it and/or modify
26 + * it under the terms of the GNU General Public License as published by
27 + * the Free Software Foundation; either version 2 of the License, or
28 + * (at your option) any later version.
29 + */
30 +
31 +enum {
32 +       IPT_CONNMARK_SET = 0,
33 +       IPT_CONNMARK_SAVE,
34 +       IPT_CONNMARK_RESTORE
35 +};
36 +
37 +struct ipt_connmark_target_info {
38 +       unsigned long mark;
39 +       unsigned long mask;
40 +       u_int8_t mode;
41 +};
42 +
43 +#endif /*_IPT_CONNMARK_H_target*/
44 diff -Nur --exclude '*.orig' linux-2.6.5-rc2.org/include/linux/netfilter_ipv4/ipt_IPMARK.h linux-2.6.5-rc2/include/linux/netfilter_ipv4/ipt_IPMARK.h
45 --- linux-2.6.5-rc2.org/include/linux/netfilter_ipv4/ipt_IPMARK.h       1970-01-01 00:00:00.000000000 +0000
46 +++ linux-2.6.5-rc2/include/linux/netfilter_ipv4/ipt_IPMARK.h   2004-03-22 09:00:56.000000000 +0000
47 @@ -0,0 +1,13 @@
48 +#ifndef _IPT_IPMARK_H_target
49 +#define _IPT_IPMARK_H_target
50 +
51 +struct ipt_ipmark_target_info {
52 +       unsigned long andmask;
53 +       unsigned long ormask;
54 +       unsigned int addr;
55 +};
56 +
57 +#define IPT_IPMARK_SRC    0
58 +#define IPT_IPMARK_DST    1
59 +
60 +#endif /*_IPT_IPMARK_H_target*/
61 diff -Nur --exclude '*.orig' linux-2.6.5-rc2.org/include/linux/netfilter_ipv4/ipt_XOR.h linux-2.6.5-rc2/include/linux/netfilter_ipv4/ipt_XOR.h
62 --- linux-2.6.5-rc2.org/include/linux/netfilter_ipv4/ipt_XOR.h  1970-01-01 00:00:00.000000000 +0000
63 +++ linux-2.6.5-rc2/include/linux/netfilter_ipv4/ipt_XOR.h      2004-03-22 09:01:18.000000000 +0000
64 @@ -0,0 +1,9 @@
65 +#ifndef _IPT_XOR_H
66 +#define _IPT_XOR_H
67 +
68 +struct ipt_XOR_info {
69 +       char            key[30];
70 +       u_int8_t        block_size;
71 +};
72 +
73 +#endif /* _IPT_XOR_H */
74 diff -Nur --exclude '*.orig' linux-2.6.5-rc2.org/include/linux/netfilter_ipv4/ipt_addrtype.h linux-2.6.5-rc2/include/linux/netfilter_ipv4/ipt_addrtype.h
75 --- linux-2.6.5-rc2.org/include/linux/netfilter_ipv4/ipt_addrtype.h     1970-01-01 00:00:00.000000000 +0000
76 +++ linux-2.6.5-rc2/include/linux/netfilter_ipv4/ipt_addrtype.h 2004-03-22 09:01:46.000000000 +0000
77 @@ -0,0 +1,11 @@
78 +#ifndef _IPT_ADDRTYPE_H
79 +#define _IPT_ADDRTYPE_H
80 +
81 +struct ipt_addrtype_info {
82 +       u_int16_t       source;         /* source-type mask */
83 +       u_int16_t       dest;           /* dest-type mask */
84 +       int             invert_source;
85 +       int             invert_dest;
86 +};
87 +
88 +#endif
89 diff -Nur --exclude '*.orig' linux-2.6.5-rc2.org/include/linux/netfilter_ipv4/ipt_childlevel.h linux-2.6.5-rc2/include/linux/netfilter_ipv4/ipt_childlevel.h
90 --- linux-2.6.5-rc2.org/include/linux/netfilter_ipv4/ipt_childlevel.h   1970-01-01 00:00:00.000000000 +0000
91 +++ linux-2.6.5-rc2/include/linux/netfilter_ipv4/ipt_childlevel.h       2004-03-22 09:01:53.000000000 +0000
92 @@ -0,0 +1,22 @@
93 +/* 
94 +  By Matthew Strait <quadong@users.sf.net>, Dec 2003.
95 +  http://l7-filter.sf.net
96 +
97 +  This program is free software; you can redistribute it and/or
98 +  modify it under the terms of the GNU General Public License
99 +  as published by the Free Software Foundation; either version
100 +  2 of the License, or (at your option) any later version.
101 +  http://www.gnu.org/licenses/gpl.txt
102 +*/
103 +
104 +#ifndef _IPT_CHILDLEVEL_H
105 +#define _IPT_CHILDLEVEL_H
106 +
107 +typedef char *(*proc_ipt_search) (u_int32_t, u_int8_t);
108 +
109 +struct ipt_childlevel_info {
110 +       u_int32_t childlevel; 
111 +       u_int8_t invert;
112 +};
113 +
114 +#endif /* _IPT_CHILDLEVEL_H */
115 diff -Nur --exclude '*.orig' linux-2.6.5-rc2.org/include/linux/netfilter_ipv4/ipt_connmark.h linux-2.6.5-rc2/include/linux/netfilter_ipv4/ipt_connmark.h
116 --- linux-2.6.5-rc2.org/include/linux/netfilter_ipv4/ipt_connmark.h     1970-01-01 00:00:00.000000000 +0000
117 +++ linux-2.6.5-rc2/include/linux/netfilter_ipv4/ipt_connmark.h 2004-03-22 09:08:35.000000000 +0000
118 @@ -0,0 +1,18 @@
119 +#ifndef _IPT_CONNMARK_H
120 +#define _IPT_CONNMARK_H
121 +
122 +/* Copyright (C) 2002,2004 MARA Systems AB <http://www.marasystems.com>
123 + * by Henrik Nordstrom <hno@marasystems.com>
124 + *
125 + * This program is free software; you can redistribute it and/or modify
126 + * it under the terms of the GNU General Public License as published by
127 + * the Free Software Foundation; either version 2 of the License, or
128 + * (at your option) any later version.
129 + */
130 +
131 +struct ipt_connmark_info {
132 +       unsigned long mark, mask;
133 +       u_int8_t invert;
134 +};
135 +
136 +#endif /*_IPT_CONNMARK_H*/
137 diff -Nur --exclude '*.orig' linux-2.6.5-rc2.org/include/linux/netfilter_ipv4/ipt_policy.h linux-2.6.5-rc2/include/linux/netfilter_ipv4/ipt_policy.h
138 --- linux-2.6.5-rc2.org/include/linux/netfilter_ipv4/ipt_policy.h       1970-01-01 00:00:00.000000000 +0000
139 +++ linux-2.6.5-rc2/include/linux/netfilter_ipv4/ipt_policy.h   2004-03-22 09:02:50.000000000 +0000
140 @@ -0,0 +1,52 @@
141 +#ifndef _IPT_POLICY_H
142 +#define _IPT_POLICY_H
143 +
144 +#define POLICY_MAX_ELEM        4
145 +
146 +enum ipt_policy_flags
147 +{
148 +       POLICY_MATCH_IN         = 0x1,
149 +       POLICY_MATCH_OUT        = 0x2,
150 +       POLICY_MATCH_NONE       = 0x4,
151 +       POLICY_MATCH_STRICT     = 0x8,
152 +};
153 +
154 +enum ipt_policy_modes
155 +{
156 +       POLICY_MODE_TRANSPORT,
157 +       POLICY_MODE_TUNNEL
158 +};
159 +
160 +struct ipt_policy_spec
161 +{
162 +       u_int8_t        saddr:1,
163 +                       daddr:1,
164 +                       proto:1,
165 +                       mode:1,
166 +                       spi:1,
167 +                       reqid:1;
168 +};
169 +
170 +struct ipt_policy_elem
171 +{
172 +       u_int32_t       saddr;
173 +       u_int32_t       smask;
174 +       u_int32_t       daddr;
175 +       u_int32_t       dmask;
176 +       u_int32_t       spi;
177 +       u_int32_t       reqid;
178 +       u_int8_t        proto;
179 +       u_int8_t        mode;
180 +
181 +       struct ipt_policy_spec  match;
182 +       struct ipt_policy_spec  invert;
183 +};
184 +
185 +struct ipt_policy_info
186 +{
187 +       struct ipt_policy_elem pol[POLICY_MAX_ELEM];
188 +       u_int16_t flags;
189 +       u_int16_t len;
190 +};
191 +
192 +#endif /* _IPT_POLICY_H */
193 diff -Nur --exclude '*.orig' linux-2.6.5-rc2.org/include/net/tcp.h linux-2.6.5-rc2/include/net/tcp.h
194 --- linux-2.6.5-rc2.org/include/net/tcp.h       2004-03-20 00:11:02.000000000 +0000
195 +++ linux-2.6.5-rc2/include/net/tcp.h   2004-03-22 09:02:35.000000000 +0000
196 @@ -162,6 +162,7 @@
197  extern void tcp_bucket_unlock(struct sock *sk);
198  extern int tcp_port_rover;
199  extern struct sock *tcp_v4_lookup_listener(u32 addr, unsigned short hnum, int dif);
200 +extern struct sock *tcp_v4_lookup(u32 saddr, u16 sport, u32 daddr, u16 hnum, int dif);
201  
202  /* These are AF independent. */
203  static __inline__ int tcp_bhashfn(__u16 lport)
204 diff -Nur --exclude '*.orig' linux-2.6.5-rc2.org/include/net/udp.h linux-2.6.5-rc2/include/net/udp.h
205 --- linux-2.6.5-rc2.org/include/net/udp.h       2004-03-20 00:11:34.000000000 +0000
206 +++ linux-2.6.5-rc2/include/net/udp.h   2004-03-22 09:02:35.000000000 +0000
207 @@ -74,6 +74,8 @@
208  extern int     udp_ioctl(struct sock *sk, int cmd, unsigned long arg);
209  extern int     udp_disconnect(struct sock *sk, int flags);
210  
211 +extern struct sock *udp_v4_lookup(u32 saddr, u16 sport, u32 daddr, u16 dport, int dif);
212 +
213  DECLARE_SNMP_STAT(struct udp_mib, udp_statistics);
214  #define UDP_INC_STATS(field)           SNMP_INC_STATS(udp_statistics, field)
215  #define UDP_INC_STATS_BH(field)                SNMP_INC_STATS_BH(udp_statistics, field)
216 diff -Nur --exclude '*.orig' linux-2.6.5-rc2.org/net/core/netfilter.c linux-2.6.5-rc2/net/core/netfilter.c
217 --- linux-2.6.5-rc2.org/net/core/netfilter.c    2004-03-22 08:57:53.000000000 +0000
218 +++ linux-2.6.5-rc2/net/core/netfilter.c        2004-03-22 09:02:30.000000000 +0000
219 @@ -60,6 +60,10 @@
220  } queue_handler[NPROTO];
221  static rwlock_t queue_handler_lock = RW_LOCK_UNLOCKED;
222  
223 +/**
224 + * nf_register_hook - Register with a netfilter hook
225 + * @reg: Hook operations to be registered
226 + */
227  int nf_register_hook(struct nf_hook_ops *reg)
228  {
229         struct list_head *i;
230 @@ -76,6 +80,10 @@
231         return 0;
232  }
233  
234 +/**
235 + * nf_unregister_hook - Unregister from a netfilter hook
236 + * @reg: hook operations to be unregistered
237 + */
238  void nf_unregister_hook(struct nf_hook_ops *reg)
239  {
240         spin_lock_bh(&nf_hook_lock);
241 @@ -388,6 +396,18 @@
242         return NF_ACCEPT;
243  }
244  
245 +/**
246 + * nf_register_queue_handler - Registere a queue handler with netfilter
247 + * @pf: protocol family
248 + * @outfn: function called by core to enqueue a packet
249 + * @data: opaque parameter, passed through
250 + *
251 + * This function registers a queue handler with netfilter.  There can only
252 + * be one queue handler for every protocol family.
253 + *
254 + * A queue handler _must_ reinject every packet via nf_reinject, no
255 + * matter what.
256 + */
257  int nf_register_queue_handler(int pf, nf_queue_outfn_t outfn, void *data)
258  {      
259         int ret;
260 @@ -405,7 +425,12 @@
261         return ret;
262  }
263  
264 -/* The caller must flush their queue before this */
265 +/**
266 + * nf_unregister_queue_handler - Unregister queue handler from netfilter
267 + * @pf: protocol family
268 + *
269 + * The caller must flush their queue before unregistering
270 + */
271  int nf_unregister_queue_handler(int pf)
272  {
273         write_lock_bh(&queue_handler_lock);
274 @@ -548,6 +573,15 @@
275         return ret;
276  }
277  
278 +/**
279 + * nf_reinject - Reinject a packet from a queue handler
280 + * @skb: the packet to be reinjected
281 + * @info: info which was passed to the outfn() of the queue handler
282 + * @verdict: verdict (NF_ACCEPT, ...) for this packet
283 + *
284 + * This is the function called by a queue handler to reinject a
285 + * packet.
286 + */
287  void nf_reinject(struct sk_buff *skb, struct nf_info *info,
288                  unsigned int verdict)
289  {
290 diff -Nur --exclude '*.orig' linux-2.6.5-rc2.org/net/ipv4/netfilter/Kconfig linux-2.6.5-rc2/net/ipv4/netfilter/Kconfig
291 --- linux-2.6.5-rc2.org/net/ipv4/netfilter/Kconfig      2004-03-22 08:57:53.000000000 +0000
292 +++ linux-2.6.5-rc2/net/ipv4/netfilter/Kconfig  2004-03-22 09:08:35.000000000 +0000
293 @@ -701,5 +701,41 @@
294         depends on IP_NF_IPTABLES
295           help
296  
297 +config IP_NF_TARGET_IPMARK
298 +       tristate  'IPMARK target support'
299 +       depends on IP_NF_MANGLE
300 +         help
301 +
302 +config IP_NF_TARGET_XOR
303 +       tristate  'XOR target support'
304 +       depends on IP_NF_MANGLE
305 +         help
306 +
307 +config IP_NF_MATCH_ADDRTYPE
308 +       tristate  'address type match support'
309 +       depends on IP_NF_IPTABLES
310 +         help
311 +
312 +config IP_NF_MATCH_POLICY
313 +       tristate "IPsec policy match support"
314 +       depends on IP_NF_IPTABLES && XFRM
315 +       help
316 +         Policy matching allows you to match packets based on the
317 +         IPsec policy that was used during decapsulation/will
318 +         be used during encapsulation.
319 +
320 +         To compile it as a module, choose M here.  If unsure, say N.
321 +         help
322 +
323 +config IP_NF_CONNTRACK_MARK
324 +       bool  'Connection mark tracking support'
325 +config IP_NF_TARGET_CONNMARK
326 +       tristate  'CONNMARK target support'
327 +       depends on IP_NF_MANGLE
328 +config IP_NF_MATCH_CONNMARK
329 +       tristate  ' Connection mark match support'
330 +       depends on IP_NF_IPTABLES
331 +         help
332 +
333  endmenu
334  
335 diff -Nur --exclude '*.orig' linux-2.6.5-rc2.org/net/ipv4/netfilter/Makefile linux-2.6.5-rc2/net/ipv4/netfilter/Makefile
336 --- linux-2.6.5-rc2.org/net/ipv4/netfilter/Makefile     2004-03-22 08:57:53.000000000 +0000
337 +++ linux-2.6.5-rc2/net/ipv4/netfilter/Makefile 2004-03-22 09:08:35.000000000 +0000
338 @@ -89,12 +89,15 @@
339  
340  obj-$(CONFIG_IP_NF_MATCH_TTL) += ipt_ttl.o
341  obj-$(CONFIG_IP_NF_MATCH_STATE) += ipt_state.o
342 +obj-$(CONFIG_IP_NF_MATCH_CONNMARK) += ipt_connmark.o
343  obj-$(CONFIG_IP_NF_MATCH_CONNLIMIT) += ipt_connlimit.o
344  obj-$(CONFIG_IP_NF_MATCH_CONNTRACK) += ipt_conntrack.o
345  obj-$(CONFIG_IP_NF_MATCH_TCPMSS) += ipt_tcpmss.o
346 +obj-$(CONFIG_IP_NF_MATCH_ADDRTYPE) += ipt_addrtype.o
347  obj-$(CONFIG_IP_NF_MATCH_REALM) += ipt_realm.o
348  
349  obj-$(CONFIG_IP_NF_MATCH_PHYSDEV) += ipt_physdev.o
350 +obj-$(CONFIG_IP_NF_MATCH_POLICY) += ipt_policy.o
351  
352  # targets
353  obj-$(CONFIG_IP_NF_TARGET_REJECT) += ipt_REJECT.o
354 @@ -102,6 +105,7 @@
355  obj-$(CONFIG_IP_NF_TARGET_ECN) += ipt_ECN.o
356  obj-$(CONFIG_IP_NF_TARGET_DSCP) += ipt_DSCP.o
357  obj-$(CONFIG_IP_NF_TARGET_MARK) += ipt_MARK.o
358 +obj-$(CONFIG_IP_NF_TARGET_IPMARK) += ipt_IPMARK.o
359  obj-$(CONFIG_IP_NF_TARGET_IMQ) += ipt_IMQ.o
360  obj-$(CONFIG_IP_NF_TARGET_MASQUERADE) += ipt_MASQUERADE.o
361  obj-$(CONFIG_IP_NF_TARGET_REDIRECT) += ipt_REDIRECT.o
362 @@ -110,6 +114,8 @@
363  obj-$(CONFIG_IP_NF_TARGET_CLASSIFY) += ipt_CLASSIFY.o
364  obj-$(CONFIG_IP_NF_NAT_SNMP_BASIC) += ip_nat_snmp_basic.o
365  obj-$(CONFIG_IP_NF_TARGET_LOG) += ipt_LOG.o
366 +obj-$(CONFIG_IP_NF_TARGET_CONNMARK) += ipt_CONNMARK.o
367 +obj-$(CONFIG_IP_NF_TARGET_XOR) += ipt_XOR.o
368  obj-$(CONFIG_IP_NF_TARGET_TTL) += ipt_TTL.o
369  obj-$(CONFIG_IP_NF_TARGET_IPV4OPTSSTRIP) += ipt_IPV4OPTSSTRIP.o
370  obj-$(CONFIG_IP_NF_TARGET_ULOG) += ipt_ULOG.o
371 diff -Nur --exclude '*.orig' linux-2.6.5-rc2.org/net/ipv4/netfilter/ip_conntrack_core.c linux-2.6.5-rc2/net/ipv4/netfilter/ip_conntrack_core.c
372 --- linux-2.6.5-rc2.org/net/ipv4/netfilter/ip_conntrack_core.c  2004-03-22 08:57:53.000000000 +0000
373 +++ linux-2.6.5-rc2/net/ipv4/netfilter/ip_conntrack_core.c      2004-03-22 09:08:35.000000000 +0000
374 @@ -15,6 +15,8 @@
375   * 16 Jul 2002: Harald Welte <laforge@gnumonks.org>
376   *     - add usage/reference counts to ip_conntrack_expect
377   *     - export ip_conntrack[_expect]_{find_get,put} functions
378 + * 05 Aug 2002: Harald Welte <laforge@gnumonks.org>
379 + *     - added DocBook-style comments for public API
380   * */
381  
382  #include <linux/config.h>
383 @@ -90,6 +92,10 @@
384         return p;
385  }
386  
387 +/**
388 + * ip_ct_find_proto - Find layer 4 protocol helper for given protocol number
389 + * @protocol: protocol number
390 + */
391  struct ip_conntrack_protocol *ip_ct_find_proto(u_int8_t protocol)
392  {
393         struct ip_conntrack_protocol *p;
394 @@ -113,6 +119,11 @@
395  static int ip_conntrack_hash_rnd_initted;
396  static unsigned int ip_conntrack_hash_rnd;
397  
398 +/**
399 + * hash_conntrack - Calculate the position of an entry in the connection 
400 + * tracking table.
401 + * @tuple: conntrack tuple which we want to calculate the hash position
402 + */
403  static u_int32_t
404  hash_conntrack(const struct ip_conntrack_tuple *tuple)
405  {
406 @@ -125,6 +136,19 @@
407                              ip_conntrack_hash_rnd) % ip_conntrack_htable_size);
408  }
409  
410 +/**
411 + * get_tuple - set all the fields of a tuple which is passed as parameter
412 + * given a network buffer.
413 + * @iph:pointer an IP header. 
414 + * @skb:network buffer for which we want to generate the tuple
415 + * @dataoff: FIXME: Deprecated?
416 + * @tuple: tuple which will be generate. Used as return parameter.
417 + * @protocol: structure which contains pointer to protocol specific functions.
418 + *
419 + * Note: This function doesn't allocate space for the tuple passed as 
420 + * parameter. The function pkt_to_packet which set all the protocol specific
421 + * fields of a given tuple.
422 + */
423  int
424  get_tuple(const struct iphdr *iph,
425           const struct sk_buff *skb,
426 @@ -146,6 +170,15 @@
427         return protocol->pkt_to_tuple(skb, dataoff, tuple);
428  }
429  
430 +/**
431 + * invert_tuple - Returns the inverse of a given tuple. It is used to 
432 + * calculate the tuple which represents the other sense of the flow
433 + * of a connection.
434 + * @inverse: the inverted tuple. Use as return value.
435 + * @orig: the original tuple which will be inverted.
436 + * @protocol: a pointer to the protocol structure which contains all the
437 + * specifical functions available for this tuple.
438 + */
439  static int
440  invert_tuple(struct ip_conntrack_tuple *inverse,
441              const struct ip_conntrack_tuple *orig,
442 @@ -161,7 +194,15 @@
443  
444  /* ip_conntrack_expect helper functions */
445  
446 -/* Compare tuple parts depending on mask. */
447 +/**
448 + * expect_cmp - compare a tuple with a expectation depending on a mask
449 + * @i: pointer to an expectation.
450 + * @tuple: tuple which will be compared with the expectation tuple.
451 + *
452 + * Actually the tuple field of an expectation is compared with a tuple
453 + * This function is used by LIST_FIND to find a expectation which match a te
454 + * given tuple.
455 + */
456  static inline int expect_cmp(const struct ip_conntrack_expect *i,
457                              const struct ip_conntrack_tuple *tuple)
458  {
459 @@ -169,6 +210,10 @@
460         return ip_ct_tuple_mask_cmp(tuple, &i->tuple, &i->mask);
461  }
462  
463 +/**
464 + * destroy_expect - Release all the resources allocated by an expectation.
465 + * @exp: pointer to the expectation which we want to release.
466 + */
467  static void
468  destroy_expect(struct ip_conntrack_expect *exp)
469  {
470 @@ -179,7 +224,11 @@
471         kfree(exp);
472  }
473  
474 -
475 +/**
476 + * ip_conntrack_expect_put - it decrements the counter of use related 
477 + * associated to an expectation and it calls destroy_expect.
478 + * @exp: pointer to the expectation which we want to release.
479 + */
480  inline void ip_conntrack_expect_put(struct ip_conntrack_expect *exp)
481  {
482         IP_NF_ASSERT(exp);
483 @@ -199,7 +248,14 @@
484                          struct ip_conntrack_expect *, tuple);
485  }
486  
487 -/* Find a expectation corresponding to a tuple. */
488 +/**
489 + * ip_conntrack_find_get - find conntrack according to tuple
490 + * @tuple: conntrack tuple for which we search conntrack
491 + * @ignored_conntrack: ignore this conntrack during search
492 + *
493 + * This function increments the reference count of the found
494 + * conntrack (if any).
495 + */
496  struct ip_conntrack_expect *
497  ip_conntrack_expect_find_get(const struct ip_conntrack_tuple *tuple)
498  {
499 @@ -382,7 +438,14 @@
500         return h;
501  }
502  
503 -/* Find a connection corresponding to a tuple. */
504 +/**
505 + * ip_conntrack_find_get - find conntrack according to tuple
506 + * @tuple: conntrack tuple for which we search conntrack
507 + * @ignored_conntrack: ignore this conntrack during search
508 + *
509 + * This function increments the reference count of the found
510 + * conntrack (if any).
511 + */
512  struct ip_conntrack_tuple_hash *
513  ip_conntrack_find_get(const struct ip_conntrack_tuple *tuple,
514                       const struct ip_conntrack *ignored_conntrack)
515 @@ -410,7 +473,14 @@
516         return ct;
517  }
518  
519 -/* Return conntrack and conntrack_info given skb->nfct->master */
520 +/**
521 + * ip_conntrack_get - Return conntrack and conntrack_info for given skb
522 + * @skb: skb for which we want to find conntrack and conntrack_info
523 + * @ctinfo: pointer to ctinfo, used as return value
524 + *
525 + * This function resolves the respective conntrack and conntrack_info
526 + * structures for the connection this packet (skb) is part of.
527 + */
528  struct ip_conntrack *
529  ip_conntrack_get(struct sk_buff *skb, enum ip_conntrack_info *ctinfo)
530  {
531 @@ -480,8 +550,14 @@
532         return NF_DROP;
533  }
534  
535 -/* Returns true if a connection correspondings to the tuple (required
536 -   for NAT). */
537 +/**
538 + * ip_conntrack_tuple_taken - Find out if tuple is already in use
539 + * @tuple: tuple to be used for this test
540 + * @ignored_conntrack: conntrack which is excluded from result
541 + *
542 + * This function is called by the NAT code in order to find out if
543 + * a particular tuple is already in use by some connection.
544 + */
545  int
546  ip_conntrack_tuple_taken(const struct ip_conntrack_tuple *tuple,
547                          const struct ip_conntrack *ignored_conntrack)
548 @@ -607,7 +683,13 @@
549  {
550         return ip_ct_tuple_mask_cmp(rtuple, &i->tuple, &i->mask);
551  }
552 -
553 +/**
554 + * ip_ct_find_helper - Find application helper according to tuple
555 + * @tuple: tuple for which helper needs to be found
556 + *
557 + * This function is used to determine if any registered conntrack helper
558 + * is to be used for the given tuple.
559 + */
560  struct ip_conntrack_helper *ip_ct_find_helper(const struct ip_conntrack_tuple *tuple)
561  {
562         return LIST_FIND(&helpers, helper_cmp,
563 @@ -714,12 +796,15 @@
564                         conntrack, expected);
565                  /* Welcome, Mr. Bond.  We've been expecting you... */
566                  IP_NF_ASSERT(master_ct(conntrack));
567 -                __set_bit(IPS_EXPECTED_BIT, &conntrack->status);
568 -                conntrack->master = expected;
569 -                expected->sibling = conntrack;
570 -                LIST_DELETE(&ip_conntrack_expect_list, expected);
571 -                expected->expectant->expecting--;
572 -                nf_conntrack_get(&master_ct(conntrack)->infos[0]);
573 +               __set_bit(IPS_EXPECTED_BIT, &conntrack->status);
574 +               conntrack->master = expected;
575 +               expected->sibling = conntrack;
576 +#if CONFIG_IP_NF_CONNTRACK_MARK
577 +               conntrack->mark = expected->expectant->mark;
578 +#endif
579 +               LIST_DELETE(&ip_conntrack_expect_list, expected);
580 +               expected->expectant->expecting--;
581 +               nf_conntrack_get(&master_ct(conntrack)->infos[0]);
582  
583                 /* this is a braindead... --pablo */
584                 atomic_inc(&ip_conntrack_count);
585 @@ -910,6 +995,14 @@
586         return ip_ct_tuple_mask_cmp(&i->tuple, tuple, &intersect_mask);
587  }
588  
589 +/**
590 + * ip_conntrack_unexpect_related - Unexpect a related connection
591 + * @expect: expecattin to be removed
592 + *
593 + * This function removes an existing expectation, that has not yet been
594 + * confirmed (i.e. expectation was issued, but expected connection didn't
595 + * arrive yet)
596 + */
597  inline void ip_conntrack_unexpect_related(struct ip_conntrack_expect *expect)
598  {
599         WRITE_LOCK(&ip_conntrack_lock);
600 @@ -927,7 +1020,20 @@
601         WRITE_UNLOCK(&ip_conntrack_lock);
602  }
603  
604 -/* Add a related connection. */
605 +/**
606 + * ip_conntrack_expect_related - Expect a related connection
607 + * @related_to: master conntrack
608 + * @expect: expectation with all values filled in
609 + *
610 + * This function is called by conntrack application helpers who
611 + * have detected that the control (master) connection is just about
612 + * to negotiate a related slave connection. 
613 + *
614 + * Note: This function allocates it's own struct ip_conntrack_expect,
615 + * copying the values from the 'expect' parameter.  Thus, 'expect' can
616 + * be allocated on the stack and does not need to be valid after this
617 + * function returns.
618 + */
619  int ip_conntrack_expect_related(struct ip_conntrack *related_to,
620                                 struct ip_conntrack_expect *expect)
621  {
622 @@ -1057,7 +1163,15 @@
623         return ret;
624  }
625  
626 -/* Change tuple in an existing expectation */
627 +/**
628 + * ip_conntrack_change_expect - Change tuple in existing expectation
629 + * @expect: expectation which is to be changed
630 + * @newtuple: new tuple for expect
631 + *
632 + * This function is mostly called by NAT application helpers, who want to
633 + * change an expectation issued by their respective conntrack application
634 + * helper counterpart.
635 + */
636  int ip_conntrack_change_expect(struct ip_conntrack_expect *expect,
637                                struct ip_conntrack_tuple *newtuple)
638  {
639 @@ -1098,8 +1212,15 @@
640         return ret;
641  }
642  
643 -/* Alter reply tuple (maybe alter helper).  If it's already taken,
644 -   return 0 and don't do alteration. */
645 +/**
646 + * ip_conntrack_alter_reply - Alter reply tuple of conntrack
647 + * @conntrack: conntrack whose reply tuple we want to alter
648 + * @newreply: designated reply tuple for this conntrack
649 + *
650 + * This function alters the reply tuple of a conntrack to the given
651 + * newreply tuple.  If this newreply tuple is already taken, return 0
652 + * and don't do alteration
653 + */
654  int ip_conntrack_alter_reply(struct ip_conntrack *conntrack,
655                              const struct ip_conntrack_tuple *newreply)
656  {
657 @@ -1124,6 +1245,13 @@
658         return 1;
659  }
660  
661 +/**
662 + * ip_conntrack_helper_register - Register a conntrack application helper
663 + * @me: structure describing the helper
664 + *
665 + * This function is called by conntrack application helpers to register
666 + * themselves with the conntrack core.
667 + */
668  int ip_conntrack_helper_register(struct ip_conntrack_helper *me)
669  {
670         WRITE_LOCK(&ip_conntrack_lock);
671 @@ -1145,6 +1273,13 @@
672         return 0;
673  }
674  
675 +/**
676 + * ip_conntrack_helper_unregister - Unregister a conntrack application helper
677 + * @me: structure describing the helper
678 + *
679 + * This function is called by conntrack application helpers to unregister
680 + * themselvers from the conntrack core.
681 + */
682  void ip_conntrack_helper_unregister(struct ip_conntrack_helper *me)
683  {
684         unsigned int i;
685 @@ -1163,7 +1298,14 @@
686         synchronize_net();
687  }
688  
689 -/* Refresh conntrack for this many jiffies. */
690 +/**
691 + * ip_ct_refresh - Refresh conntrack timer for given conntrack
692 + * @ct: conntrack which we want to refresh
693 + * @extra_jiffies: number of jiffies to add
694 + *
695 + * This function is called by protocol helpers and application helpers in
696 + * order to change the expiration timer of a conntrack entry.
697 + */
698  void ip_ct_refresh(struct ip_conntrack *ct, unsigned long extra_jiffies)
699  {
700         IP_NF_ASSERT(ct->timeout.data == (unsigned long)ct);
701 @@ -1182,7 +1324,16 @@
702         WRITE_UNLOCK(&ip_conntrack_lock);
703  }
704  
705 -/* Returns new sk_buff, or NULL */
706 +
707 +/**
708 + * ip_ct_gather_frags - Gather fragments of a particular skb
709 + * @skb: pointer to sk_buff of fragmented IP packet
710 + *
711 + * This code is just a wrapper around the defragmentation code in the core IPv4
712 + * stack.  It also takes care of nonlinear skb's.
713 + *
714 + * Returns new sk_buff, or NULL
715 + */
716  struct sk_buff *
717  ip_ct_gather_frags(struct sk_buff *skb)
718  {
719 @@ -1266,6 +1417,16 @@
720         return h;
721  }
722  
723 +/**
724 + * ip_ct_selective_cleanup - Selectively delete a set of conntrack entries
725 + * @kill: callback function selecting which entries to delete
726 + * @data: opaque data pointer, becomes 2nd argument for kill function
727 + *
728 + * This function can be used to selectively delete elements of the conntrack
729 + * hashtable.  The function iterates over the list of conntrack entries and
730 + * calls the 'kill' function for every entry.  If the return value is true,
731 + * the connection is deleted (death_by_timeout).
732 + */
733  void
734  ip_ct_selective_cleanup(int (*kill)(const struct ip_conntrack *i, void *data),
735                         void *data)
736 diff -Nur --exclude '*.orig' linux-2.6.5-rc2.org/net/ipv4/netfilter/ip_conntrack_standalone.c linux-2.6.5-rc2/net/ipv4/netfilter/ip_conntrack_standalone.c
737 --- linux-2.6.5-rc2.org/net/ipv4/netfilter/ip_conntrack_standalone.c    2004-03-22 08:57:53.000000000 +0000
738 +++ linux-2.6.5-rc2/net/ipv4/netfilter/ip_conntrack_standalone.c        2004-03-22 09:08:35.000000000 +0000
739 @@ -110,6 +110,9 @@
740                 len += sprintf(buffer + len, "[ASSURED] ");
741         len += sprintf(buffer + len, "use=%u ",
742                        atomic_read(&conntrack->ct_general.use));
743 +#if defined(CONFIG_IP_NF_CONNTRACK_MARK)
744 +       len += sprintf(buffer + len, "mark=%ld ", conntrack->mark);
745 +#endif
746         len += sprintf(buffer + len, "\n");
747  
748         return len;
749 @@ -569,13 +572,20 @@
750         return ret;
751  }
752  
753 -/* FIXME: Allow NULL functions and sub in pointers to generic for
754 -   them. --RR */
755 +/**
756 + * ip_conntrack_protocol_register - Register layer 4 protocol helper
757 + * @proto: structure describing this layer 4 protocol helper
758 + *
759 + * This function is called by layer 4 protocol helpers to register 
760 + * themselves with the conntrack core.
761 + */
762  int ip_conntrack_protocol_register(struct ip_conntrack_protocol *proto)
763  {
764         int ret = 0;
765         struct list_head *i;
766  
767 +       /* FIXME: Allow NULL functions and sub in pointers to generic for
768 +          them. --RR */
769         WRITE_LOCK(&ip_conntrack_lock);
770         list_for_each(i, &protocol_list) {
771                 if (((struct ip_conntrack_protocol *)i)->proto
772 @@ -592,12 +602,20 @@
773         return ret;
774  }
775  
776 +/**
777 + * ip_conntrack_protocol_unregister - Unregister layer 4 protocol helper
778 + * @proto: structure describing this layer 4 protocol helper
779 + *
780 + * This function is called byh layer 4 protocol helpers to unregister
781 + * themselvers from the conntrack core.  Please note that all conntrack
782 + * entries for this protocol are deleted from the conntrack hash table.
783 + */
784  void ip_conntrack_protocol_unregister(struct ip_conntrack_protocol *proto)
785  {
786         WRITE_LOCK(&ip_conntrack_lock);
787  
788 -       /* ip_ct_find_proto() returns proto_generic in case there is no protocol 
789 -        * helper. So this should be enough - HW */
790 +       /* ip_ct_find_proto() returns proto_generic in case there is no
791 +        * protocol helper. So this should be enough - HW */
792         LIST_DELETE(&protocol_list, proto);
793         WRITE_UNLOCK(&ip_conntrack_lock);
794         
795 diff -Nur --exclude '*.orig' linux-2.6.5-rc2.org/net/ipv4/netfilter/ip_nat_core.c linux-2.6.5-rc2/net/ipv4/netfilter/ip_nat_core.c
796 --- linux-2.6.5-rc2.org/net/ipv4/netfilter/ip_nat_core.c        2004-03-22 08:57:53.000000000 +0000
797 +++ linux-2.6.5-rc2/net/ipv4/netfilter/ip_nat_core.c    2004-03-22 09:02:30.000000000 +0000
798 @@ -96,9 +96,16 @@
799         WRITE_UNLOCK(&ip_nat_lock);
800  }
801  
802 -/* We do checksum mangling, so if they were wrong before they're still
803 - * wrong.  Also works for incomplete packets (eg. ICMP dest
804 - * unreachables.) */
805 +/**
806 + * ip_nat_cheat_check - Incremental checksum change for IP/TCP checksum
807 + * @oldvalinv: bit-inverted old value of 32bit word
808 + * @newval: new value of 32bit word
809 + * @oldcheck: old checksum value
810 + *
811 + * This function implements incremental checksum mangling, so if a checksum
812 + * was wrong it will still be wrong after mangling.  Also works for incomplete
813 + * packets (eg. ICMP dest unreachables).  Return value is the new checksum.
814 + */
815  u_int16_t
816  ip_nat_cheat_check(u_int32_t oldvalinv, u_int32_t newval, u_int16_t oldcheck)
817  {
818 @@ -124,7 +131,14 @@
819         return i;
820  }
821  
822 -/* Is this tuple already taken? (not by us) */
823 +/**
824 + * ip_nat_used_tuple - Is this tuple already in use?
825 + * @tuple: tuple to be used for this check
826 + * @ignored_conntrack: conntrack excluded from this check
827 + *
828 + * This function checks for the reply (inverted) tuple in the conntrack
829 + * hash.  This is necessarry with NAT, since there is no fixed mapping.
830 + */
831  int
832  ip_nat_used_tuple(const struct ip_conntrack_tuple *tuple,
833                   const struct ip_conntrack *ignored_conntrack)
834 @@ -515,6 +529,19 @@
835  #endif
836  };
837  
838 +/**
839 + * ip_nat_setup_info - Set up NAT mappings for NEW packet
840 + * @conntrack: conntrack on which we operate
841 + * @mr: address/port range which is valid for this NAT mapping
842 + * @hooknum: hook at which this NAT mapping applies
843 + *
844 + * This function is called by NAT targets (SNAT,DNAT,...) and by
845 + * the NAT application helper modules.  It is called for the NEW packet
846 + * of a connection in order to specify which NAT mappings shall apply to
847 + * this connection at a given hook.
848 + *
849 + * Note: The reply mappings are created automagically by this function. 
850 + */
851  unsigned int
852  ip_nat_setup_info(struct ip_conntrack *conntrack,
853                   const struct ip_nat_multi_range *mr,
854 diff -Nur --exclude '*.orig' linux-2.6.5-rc2.org/net/ipv4/netfilter/ip_nat_helper.c linux-2.6.5-rc2/net/ipv4/netfilter/ip_nat_helper.c
855 --- linux-2.6.5-rc2.org/net/ipv4/netfilter/ip_nat_helper.c      2004-03-20 00:11:02.000000000 +0000
856 +++ linux-2.6.5-rc2/net/ipv4/netfilter/ip_nat_helper.c  2004-03-22 09:02:30.000000000 +0000
857 @@ -150,9 +150,19 @@
858         return 1;
859  }
860  
861 -/* Generic function for mangling variable-length address changes inside
862 - * NATed TCP connections (like the PORT XXX,XXX,XXX,XXX,XXX,XXX
863 - * command in FTP).
864 +/**
865 + * ip_nat_mangle_tcp_packet - Mangle and potentially resize payload packet
866 + * @skb: pointer to skb of packet on which we operate
867 + * @ct: conntrack of the connection to which this packet belongs
868 + * @ctinfo: conntrack_info of the connection to which this packet belongs
869 + * @match_offset: offset in bytes where to-be-manipulated part starts
870 + * @match_len: lenght of the to-be-manipulated part
871 + * @rep_buffer: pointer to buffer containing replacement
872 + * @rep_len: length of replacement
873 + *
874 + * Generic function for mangling fixed and variable-length changes inside
875 + * NATed TCP connections (like the PORT XXX,XXX,XXX,XXX,XXX,XXX command 
876 + * in FTP).
877   *
878   * Takes care about all the nasty sequence number changes, checksumming,
879   * skb enlargement, ...
880 @@ -198,16 +208,27 @@
881         return 1;
882  }
883                         
884 -/* Generic function for mangling variable-length address changes inside
885 - * NATed UDP connections (like the CONNECT DATA XXXXX MESG XXXXX INDEX XXXXX
886 - * command in the Amanda protocol)
887 +/**
888 + * ip_nat_mangle_udp_packet - Mangle and potentially resize payload packet
889 + * @skb: pointer to skb of packet on which we operate
890 + * @ct: conntrack of the connection to which this packet belongs
891 + * @ctinfo: conntrack_info of the connection to which this packet belongs
892 + * @match_offset: offset in bytes where to-be-manipulated part starts
893 + * @match_len: lenght of the to-be-manipulated part
894 + * @rep_buffer: pointer to buffer containing replacement
895 + * @rep_len: length of replacement
896 + *
897 + * Generic function for mangling fixed and variable-length changes inside
898 + * NATed TCP connections (like the CONNECT DATA XXXXX MESG XXXXX INDEX XXXXX
899 + * commad in the Amanda protocol)
900   *
901   * Takes care about all the nasty sequence number changes, checksumming,
902   * skb enlargement, ...
903   *
904 - * XXX - This function could be merged with ip_nat_mangle_tcp_packet which
905 - *       should be fairly easy to do.
906 - */
907 + * FIXME: should be unified with ip_nat_mangle_tcp_packet!!
908 + *
909 + * */
910 +
911  int 
912  ip_nat_mangle_udp_packet(struct sk_buff **pskb,
913                          struct ip_conntrack *ct,
914 @@ -405,6 +426,13 @@
915         return ip_ct_tuple_mask_cmp(tuple, &helper->tuple, &helper->mask);
916  }
917  
918 +/**
919 + * ip_nat_helper_register - Register NAT application helper
920 + * @me: structure describing the helper
921 + *
922 + * This function is called by NAT application helpers to register
923 + * themselves with the NAT core.
924 + */
925  int ip_nat_helper_register(struct ip_nat_helper *me)
926  {
927         int ret = 0;
928 @@ -431,6 +459,13 @@
929         return ret;
930  }
931  
932 +/**
933 + * ip_nat_helper_unregister - Unregister NAT application helper
934 + * @me: structure describing the helper
935 + *
936 + * This function is called by NAT application helpers to unregister
937 + * themselves from the NAT core.
938 + */
939  void ip_nat_helper_unregister(struct ip_nat_helper *me)
940  {
941         WRITE_LOCK(&ip_nat_lock);
942 diff -Nur --exclude '*.orig' linux-2.6.5-rc2.org/net/ipv4/netfilter/ip_nat_standalone.c linux-2.6.5-rc2/net/ipv4/netfilter/ip_nat_standalone.c
943 --- linux-2.6.5-rc2.org/net/ipv4/netfilter/ip_nat_standalone.c  2004-03-20 00:11:34.000000000 +0000
944 +++ linux-2.6.5-rc2/net/ipv4/netfilter/ip_nat_standalone.c      2004-03-22 09:02:30.000000000 +0000
945 @@ -266,7 +266,13 @@
946  };
947  #endif
948  
949 -/* Protocol registration. */
950 +/**
951 + * ip_nat_protocol_register - Register a layer 4 protocol helper
952 + * @proto: structure describing this helper
953 + * 
954 + * This function is called by NAT layer 4 protocol helpers to register
955 + * themselvers with the NAT core.
956 + */
957  int ip_nat_protocol_register(struct ip_nat_protocol *proto)
958  {
959         int ret = 0;
960 @@ -287,9 +293,16 @@
961         return ret;
962  }
963  
964 -/* Noone stores the protocol anywhere; simply delete it. */
965 +/**
966 + * ip_nat_protocol_unregister - Unregister a layer 4 protocol helper
967 + * @proto: structure describing the helper
968 + *
969 + * This function is called by NAT layer 4 protocol helpers to
970 + * unregister themselves from the NAT core.
971 + */
972  void ip_nat_protocol_unregister(struct ip_nat_protocol *proto)
973  {
974 +       /* Noone stores the protocol anywhere; simply delete it. */
975         WRITE_LOCK(&ip_nat_lock);
976         LIST_DELETE(&protos, proto);
977         WRITE_UNLOCK(&ip_nat_lock);
978 diff -Nur --exclude '*.orig' linux-2.6.5-rc2.org/net/ipv4/netfilter/ip_tables.c linux-2.6.5-rc2/net/ipv4/netfilter/ip_tables.c
979 --- linux-2.6.5-rc2.org/net/ipv4/netfilter/ip_tables.c  2004-03-20 00:11:03.000000000 +0000
980 +++ linux-2.6.5-rc2/net/ipv4/netfilter/ip_tables.c      2004-03-22 09:02:27.000000000 +0000
981 @@ -8,6 +8,10 @@
982   * it under the terms of the GNU General Public License version 2 as
983   * published by the Free Software Foundation.
984   *
985 + *  6 Mar 2002 Robert Olsson <robban@robtex.com>
986 + * 17 Apr 2003 Chris  Wilson <chris@netservers.co.uk>
987 + *     - mark_source_chains speedup for complex chains
988 + *
989   * 19 Jan 2002 Harald Welte <laforge@gnumonks.org>
990   *     - increase module usage count as soon as we have rules inside
991   *       a table
992 @@ -498,6 +502,9 @@
993  {
994         unsigned int hook;
995  
996 +       /* keep track of where we have been: */
997 +       unsigned char *been = vmalloc(newinfo->size);
998 +
999         /* No recursion; use packet counter to save back ptrs (reset
1000            to 0 as we leave), and comefrom to save source hook bitmask */
1001         for (hook = 0; hook < NF_IP_NUMHOOKS; hook++) {
1002 @@ -510,6 +517,7 @@
1003  
1004                 /* Set initial back pointer. */
1005                 e->counters.pcnt = pos;
1006 +               memset(been, 0, newinfo->size);
1007  
1008                 for (;;) {
1009                         struct ipt_standard_target *t
1010 @@ -518,6 +526,7 @@
1011                         if (e->comefrom & (1 << NF_IP_NUMHOOKS)) {
1012                                 printk("iptables: loop hook %u pos %u %08X.\n",
1013                                        hook, pos, e->comefrom);
1014 +                               vfree(been);
1015                                 return 0;
1016                         }
1017                         e->comefrom
1018 @@ -565,10 +574,14 @@
1019                         } else {
1020                                 int newpos = t->verdict;
1021  
1022 -                               if (strcmp(t->target.u.user.name,
1023 +                               if ( (pos < 0 || pos >= newinfo->size
1024 +                                     || !been[pos]) 
1025 +                                   && strcmp(t->target.u.user.name,
1026                                            IPT_STANDARD_TARGET) == 0
1027                                     && newpos >= 0) {
1028                                         /* This a jump; chase it. */
1029 +                                       if (pos >= 0 && pos < newinfo->size)
1030 +                                               been[pos]++;
1031                                         duprintf("Jump rule %u -> %u\n",
1032                                                  pos, newpos);
1033                                 } else {
1034 @@ -584,6 +597,7 @@
1035                 next:
1036                 duprintf("Finished chain %u\n", hook);
1037         }
1038 +       vfree(been);
1039         return 1;
1040  }
1041  
1042 diff -Nur --exclude '*.orig' linux-2.6.5-rc2.org/net/ipv4/netfilter/ipt_CONNMARK.c linux-2.6.5-rc2/net/ipv4/netfilter/ipt_CONNMARK.c
1043 --- linux-2.6.5-rc2.org/net/ipv4/netfilter/ipt_CONNMARK.c       1970-01-01 00:00:00.000000000 +0000
1044 +++ linux-2.6.5-rc2/net/ipv4/netfilter/ipt_CONNMARK.c   2004-03-22 09:08:35.000000000 +0000
1045 @@ -0,0 +1,118 @@
1046 +/* This kernel module is used to modify the connection mark values, or
1047 + * to optionally restore the skb nfmark from the connection mark
1048 + *
1049 + * Copyright (C) 2002,2004 MARA Systems AB <http://www.marasystems.com>
1050 + * by Henrik Nordstrom <hno@marasystems.com>
1051 + *
1052 + * This program is free software; you can redistribute it and/or modify
1053 + * it under the terms of the GNU General Public License as published by
1054 + * the Free Software Foundation; either version 2 of the License, or
1055 + * (at your option) any later version.
1056 + *
1057 + * This program is distributed in the hope that it will be useful,
1058 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1059 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1060 + * GNU General Public License for more details.
1061 + *
1062 + * You should have received a copy of the GNU General Public License
1063 + * along with this program; if not, write to the Free Software
1064 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
1065 + */
1066 +#include <linux/module.h>
1067 +#include <linux/skbuff.h>
1068 +#include <linux/ip.h>
1069 +#include <net/checksum.h>
1070 +
1071 +MODULE_AUTHOR("Henrik Nordstrom <hno@marasytems.com>");
1072 +MODULE_DESCRIPTION("IP tables CONNMARK matching module");
1073 +MODULE_LICENSE("GPL");
1074 +
1075 +#include <linux/netfilter_ipv4/ip_tables.h>
1076 +#include <linux/netfilter_ipv4/ipt_CONNMARK.h>
1077 +#include <linux/netfilter_ipv4/ip_conntrack.h>
1078 +
1079 +static unsigned int
1080 +target(struct sk_buff **pskb,
1081 +       const struct net_device *in,
1082 +       const struct net_device *out,
1083 +       unsigned int hooknum,
1084 +       const void *targinfo,
1085 +       void *userinfo)
1086 +{
1087 +       const struct ipt_connmark_target_info *markinfo = targinfo;
1088 +       unsigned long diff;
1089 +       unsigned long nfmark;
1090 +       unsigned long newmark;
1091 +
1092 +       enum ip_conntrack_info ctinfo;
1093 +       struct ip_conntrack *ct = ip_conntrack_get((*pskb), &ctinfo);
1094 +       if (ct) {
1095 +           switch(markinfo->mode) {
1096 +           case IPT_CONNMARK_SET:
1097 +               newmark = (ct->mark & ~markinfo->mask) | markinfo->mark;
1098 +               if (newmark != ct->mark)
1099 +                   ct->mark = newmark;
1100 +               break;
1101 +           case IPT_CONNMARK_SAVE:
1102 +               newmark = (ct->mark & ~markinfo->mask) | ((*pskb)->nfmark & markinfo->mask);
1103 +               if (ct->mark != newmark)
1104 +                   ct->mark = newmark;
1105 +               break;
1106 +           case IPT_CONNMARK_RESTORE:
1107 +               nfmark = (*pskb)->nfmark;
1108 +               diff = (ct->mark ^ nfmark & markinfo->mask);
1109 +               if (diff != 0) {
1110 +                   (*pskb)->nfmark = nfmark ^ diff;
1111 +                   (*pskb)->nfcache |= NFC_ALTERED;
1112 +               }
1113 +               break;
1114 +           }
1115 +       }
1116 +
1117 +       return IPT_CONTINUE;
1118 +}
1119 +
1120 +static int
1121 +checkentry(const char *tablename,
1122 +          const struct ipt_entry *e,
1123 +          void *targinfo,
1124 +          unsigned int targinfosize,
1125 +          unsigned int hook_mask)
1126 +{
1127 +       struct ipt_connmark_target_info *matchinfo = targinfo;
1128 +       if (targinfosize != IPT_ALIGN(sizeof(struct ipt_connmark_target_info))) {
1129 +               printk(KERN_WARNING "CONNMARK: targinfosize %u != %Zu\n",
1130 +                      targinfosize,
1131 +                      IPT_ALIGN(sizeof(struct ipt_connmark_target_info)));
1132 +               return 0;
1133 +       }
1134 +
1135 +       if (matchinfo->mode == IPT_CONNMARK_RESTORE) {
1136 +           if (strcmp(tablename, "mangle") != 0) {
1137 +                   printk(KERN_WARNING "CONNMARK: restore can only be called from \"mangle\" table, not \"%s\"\n", tablename);
1138 +                   return 0;
1139 +           }
1140 +       }
1141 +
1142 +       return 1;
1143 +}
1144 +
1145 +static struct ipt_target ipt_connmark_reg = {
1146 +       .name = "CONNMARK",
1147 +       .target = &target,
1148 +       .checkentry = &checkentry,
1149 +       .me = THIS_MODULE
1150 +};
1151 +
1152 +static int __init init(void)
1153 +{
1154 +       return ipt_register_target(&ipt_connmark_reg);
1155 +}
1156 +
1157 +static void __exit fini(void)
1158 +{
1159 +       ipt_unregister_target(&ipt_connmark_reg);
1160 +}
1161 +
1162 +module_init(init);
1163 +module_exit(fini);
1164 diff -Nur --exclude '*.orig' linux-2.6.5-rc2.org/net/ipv4/netfilter/ipt_IPMARK.c linux-2.6.5-rc2/net/ipv4/netfilter/ipt_IPMARK.c
1165 --- linux-2.6.5-rc2.org/net/ipv4/netfilter/ipt_IPMARK.c 1970-01-01 00:00:00.000000000 +0000
1166 +++ linux-2.6.5-rc2/net/ipv4/netfilter/ipt_IPMARK.c     2004-03-22 09:00:56.000000000 +0000
1167 @@ -0,0 +1,81 @@
1168 +/* This is a module which is used for setting the NFMARK field of an skb. */
1169 +#include <linux/module.h>
1170 +#include <linux/skbuff.h>
1171 +#include <linux/ip.h>
1172 +#include <net/checksum.h>
1173 +
1174 +#include <linux/netfilter_ipv4/ip_tables.h>
1175 +#include <linux/netfilter_ipv4/ipt_IPMARK.h>
1176 +
1177 +MODULE_AUTHOR("Grzegorz Janoszka <Grzegorz.Janoszka@pro.onet.pl>");
1178 +MODULE_DESCRIPTION("IP tables IPMARK: mark based on ip address");
1179 +MODULE_LICENSE("GPL");
1180 +
1181 +static unsigned int
1182 +target(struct sk_buff **pskb,
1183 +       const struct net_device *in,
1184 +       const struct net_device *out,
1185 +       unsigned int hooknum,
1186 +       const void *targinfo,
1187 +       void *userinfo)
1188 +{
1189 +       const struct ipt_ipmark_target_info *ipmarkinfo = targinfo;
1190 +       struct iphdr *iph = (*pskb)->nh.iph;
1191 +       unsigned long mark;
1192 +
1193 +       if (ipmarkinfo->addr == IPT_IPMARK_SRC)
1194 +               mark = (unsigned long) ntohl(iph->saddr);
1195 +       else
1196 +               mark = (unsigned long) ntohl(iph->daddr);
1197 +
1198 +       mark &= ipmarkinfo->andmask;
1199 +       mark |= ipmarkinfo->ormask;
1200 +       
1201 +       if ((*pskb)->nfmark != mark) {
1202 +               (*pskb)->nfmark = mark;
1203 +               (*pskb)->nfcache |= NFC_ALTERED;
1204 +       }
1205 +       return IPT_CONTINUE;
1206 +}
1207 +
1208 +static int
1209 +checkentry(const char *tablename,
1210 +          const struct ipt_entry *e,
1211 +           void *targinfo,
1212 +           unsigned int targinfosize,
1213 +           unsigned int hook_mask)
1214 +{
1215 +       if (targinfosize != IPT_ALIGN(sizeof(struct ipt_ipmark_target_info))) {
1216 +               printk(KERN_WARNING "IPMARK: targinfosize %u != %Zu\n",
1217 +                      targinfosize,
1218 +                      IPT_ALIGN(sizeof(struct ipt_ipmark_target_info)));
1219 +               return 0;
1220 +       }
1221 +
1222 +       if (strcmp(tablename, "mangle") != 0) {
1223 +               printk(KERN_WARNING "IPMARK: can only be called from \"mangle\" table, not \"%s\"\n", tablename);
1224 +               return 0;
1225 +       }
1226 +
1227 +       return 1;
1228 +}
1229 +
1230 +static struct ipt_target ipt_ipmark_reg = { 
1231 +       .name = "IPMARK",
1232 +       .target = target,
1233 +       .checkentry = checkentry,
1234 +       .me = THIS_MODULE
1235 +};
1236 +
1237 +static int __init init(void)
1238 +{
1239 +       return ipt_register_target(&ipt_ipmark_reg);
1240 +}
1241 +
1242 +static void __exit fini(void)
1243 +{
1244 +       ipt_unregister_target(&ipt_ipmark_reg);
1245 +}
1246 +
1247 +module_init(init);
1248 +module_exit(fini);
1249 diff -Nur --exclude '*.orig' linux-2.6.5-rc2.org/net/ipv4/netfilter/ipt_XOR.c linux-2.6.5-rc2/net/ipv4/netfilter/ipt_XOR.c
1250 --- linux-2.6.5-rc2.org/net/ipv4/netfilter/ipt_XOR.c    1970-01-01 00:00:00.000000000 +0000
1251 +++ linux-2.6.5-rc2/net/ipv4/netfilter/ipt_XOR.c        2004-03-22 09:01:18.000000000 +0000
1252 @@ -0,0 +1,117 @@
1253 +/* XOR target for IP tables
1254 + * (C) 2000 by Tim Vandermeersch <Tim.Vandermeersch@pandora.be>
1255 + * Based on ipt_TTL.c
1256 + *
1257 + * Version 1.0
1258 + *
1259 + * This software is distributed under the terms of GNU GPL
1260 + */
1261 +
1262 +#include <linux/module.h>
1263 +#include <linux/skbuff.h>
1264 +#include <linux/ip.h>
1265 +#include <linux/tcp.h>
1266 +#include <linux/udp.h>
1267 +
1268 +#include <linux/netfilter_ipv4/ip_tables.h>
1269 +#include <linux/netfilter_ipv4/ipt_XOR.h>
1270 +
1271 +MODULE_AUTHOR("Tim Vandermeersch <Tim.Vandermeersch@pandora.be>");
1272 +MODULE_DESCRIPTION("IP tables XOR module");
1273 +MODULE_LICENSE("GPL");
1274 +
1275 +static unsigned int 
1276 +ipt_xor_target(struct sk_buff **pskb, 
1277 +               const struct net_device *in, const struct net_device *out, 
1278 +               unsigned int hooknum, const void *targinfo, void *userinfo)
1279 +{
1280 +       struct ipt_XOR_info *info = (void *) targinfo;
1281 +       struct iphdr *iph;
1282 +       struct tcphdr *tcph;
1283 +       struct udphdr *udph;
1284 +       int i, j, k;
1285 +
1286 +       if (!skb_ip_make_writable(pskb, (*pskb)->len))
1287 +               return NF_DROP;
1288 +
1289 +       iph = (*pskb)->nh.iph;
1290 +  
1291 +       if (iph->protocol == IPPROTO_TCP) {
1292 +               tcph = (struct tcphdr *) ((*pskb)->data + iph->ihl*4);
1293 +               for (i=0, j=0; i<(ntohs(iph->tot_len) - iph->ihl*4 - tcph->doff*4); ) {
1294 +                       for (k=0; k<=info->block_size; k++) {
1295 +                               (char) (*pskb)->data[ iph->ihl*4 + tcph->doff*4 + i ] ^= 
1296 +                                               info->key[j];
1297 +                               i++;
1298 +                       }
1299 +                       j++;
1300 +                       if (info->key[j] == 0x00)
1301 +                               j = 0;
1302 +               }
1303 +       } else if (iph->protocol == IPPROTO_UDP) {
1304 +               udph = (struct udphdr *) ((*pskb)->data + iph->ihl*4);
1305 +               for (i=0, j=0; i<(ntohs(udph->len)-8); ) {
1306 +                       for (k=0; k<=info->block_size; k++) {
1307 +                               (char) (*pskb)->data[ iph->ihl*4 + sizeof(struct udphdr) + i ] ^= 
1308 +                                               info->key[j];
1309 +                               i++;
1310 +                       }
1311 +                       j++;
1312 +                       if (info->key[j] == 0x00)
1313 +                               j = 0;
1314 +               }
1315 +       }
1316 +  
1317 +       return IPT_CONTINUE;
1318 +}
1319 +
1320 +static int ipt_xor_checkentry(const char *tablename, const struct ipt_entry *e,
1321 +               void *targinfo, unsigned int targinfosize, 
1322 +               unsigned int hook_mask)
1323 +{
1324 +       struct ipt_XOR_info *info = targinfo;
1325 +
1326 +       if (targinfosize != IPT_ALIGN(sizeof(struct ipt_XOR_info))) {
1327 +               printk(KERN_WARNING "XOR: targinfosize %u != %Zu\n", 
1328 +                               targinfosize, IPT_ALIGN(sizeof(struct ipt_XOR_info)));
1329 +               return 0;
1330 +       }       
1331 +
1332 +       if (strcmp(tablename, "mangle")) {
1333 +               printk(KERN_WARNING "XOR: can only be called from"
1334 +                               "\"mangle\" table, not \"%s\"\n", tablename);
1335 +               return 0; 
1336 +       }
1337 +
1338 +       if (!strcmp(info->key, "")) {
1339 +               printk(KERN_WARNING "XOR: You must specify a key");
1340 +               return 0;
1341 +       }
1342 +
1343 +       if (info->block_size == 0) {
1344 +               printk(KERN_WARNING "XOR: You must specify a block-size");
1345 +               return 0;
1346 +       }
1347 +
1348 +       return 1;
1349 +}
1350 +
1351 +static struct ipt_target ipt_XOR = { 
1352 +       .name = "XOR",
1353 +       .target = ipt_xor_target, 
1354 +       .checkentry = ipt_xor_checkentry,
1355 +       .me = THIS_MODULE,
1356 +};
1357 +
1358 +static int __init init(void)
1359 +{
1360 +       return ipt_register_target(&ipt_XOR);
1361 +}
1362 +
1363 +static void __exit fini(void)
1364 +{
1365 +       ipt_unregister_target(&ipt_XOR);
1366 +}
1367 +
1368 +module_init(init);
1369 +module_exit(fini);
1370 diff -Nur --exclude '*.orig' linux-2.6.5-rc2.org/net/ipv4/netfilter/ipt_addrtype.c linux-2.6.5-rc2/net/ipv4/netfilter/ipt_addrtype.c
1371 --- linux-2.6.5-rc2.org/net/ipv4/netfilter/ipt_addrtype.c       1970-01-01 00:00:00.000000000 +0000
1372 +++ linux-2.6.5-rc2/net/ipv4/netfilter/ipt_addrtype.c   2004-03-22 09:01:46.000000000 +0000
1373 @@ -0,0 +1,68 @@
1374 +/*
1375 + *  iptables module to match inet_addr_type() of an ip.
1376 + */
1377 +
1378 +#include <linux/module.h>
1379 +#include <linux/skbuff.h>
1380 +#include <linux/netdevice.h>
1381 +#include <net/route.h>
1382 +
1383 +#include <linux/netfilter_ipv4/ipt_addrtype.h>
1384 +#include <linux/netfilter_ipv4/ip_tables.h>
1385 +
1386 +MODULE_LICENSE("GPL");
1387 +
1388 +static inline int match_type(u_int32_t addr, u_int16_t mask)
1389 +{
1390 +       return !!(mask & (1 << inet_addr_type(addr)));
1391 +}
1392 +
1393 +static int match(const struct sk_buff *skb, const struct net_device *in,
1394 +                const struct net_device *out, const void *matchinfo,
1395 +                int offset, int *hotdrop)
1396 +{
1397 +       const struct ipt_addrtype_info *info = matchinfo;
1398 +       const struct iphdr *iph = skb->nh.iph;
1399 +       int ret = 1;
1400 +
1401 +       if (info->source)
1402 +               ret &= match_type(iph->saddr, info->source)^info->invert_source;
1403 +       if (info->dest)
1404 +               ret &= match_type(iph->daddr, info->dest)^info->invert_dest;
1405 +       
1406 +       return ret;
1407 +}
1408 +
1409 +static int checkentry(const char *tablename, const struct ipt_ip *ip,
1410 +                     void *matchinfo, unsigned int matchsize,
1411 +                     unsigned int hook_mask)
1412 +{
1413 +       if (matchsize != IPT_ALIGN(sizeof(struct ipt_addrtype_info))) {
1414 +               printk(KERN_ERR "ipt_addrtype: invalid size (%u != %u)\n.",
1415 +                      matchsize, IPT_ALIGN(sizeof(struct ipt_addrtype_info)));
1416 +               return 0;
1417 +       }
1418 +
1419 +       return 1;
1420 +}
1421 +
1422 +static struct ipt_match addrtype_match = { 
1423 +       .name = "addrtype",
1424 +       .match = match,
1425 +       .checkentry = checkentry,
1426 +       .me = THIS_MODULE
1427 +};
1428 +
1429 +static int __init init(void)
1430 +{
1431 +       return ipt_register_match(&addrtype_match);
1432 +}
1433 +
1434 +static void __exit fini(void)
1435 +{
1436 +       ipt_unregister_match(&addrtype_match);
1437 +
1438 +}
1439 +
1440 +module_init(init);
1441 +module_exit(fini);
1442 diff -Nur --exclude '*.orig' linux-2.6.5-rc2.org/net/ipv4/netfilter/ipt_childlevel.c linux-2.6.5-rc2/net/ipv4/netfilter/ipt_childlevel.c
1443 --- linux-2.6.5-rc2.org/net/ipv4/netfilter/ipt_childlevel.c     1970-01-01 00:00:00.000000000 +0000
1444 +++ linux-2.6.5-rc2/net/ipv4/netfilter/ipt_childlevel.c 2004-03-22 09:01:53.000000000 +0000
1445 @@ -0,0 +1,76 @@
1446 +/* 
1447 +  Kernel module to match the childlevel of a connection.
1448 +  i.e. The ftp control stream is childlevel 0.
1449 +       The ftp data stream is childlevel 1.
1450 +  
1451 +  By Matthew Strait <quadong@users.sf.net>, Dec 2003.
1452 +  http://l7-filter.sf.net
1453 +
1454 +  This program is free software; you can redistribute it and/or
1455 +  modify it under the terms of the GNU General Public License
1456 +  as published by the Free Software Foundation; either version
1457 +  2 of the License, or (at your option) any later version.
1458 +  http://www.gnu.org/licenses/gpl.txt
1459 +*/
1460 +
1461 +#include <linux/module.h>
1462 +#include <linux/skbuff.h>
1463 +#include <linux/netfilter_ipv4/ip_conntrack.h>
1464 +
1465 +#include <linux/netfilter_ipv4/ipt_childlevel.h>
1466 +#include <linux/netfilter_ipv4/ip_tables.h>
1467 +
1468 +MODULE_AUTHOR("Matthew Strait <quadong@users.sf.net>");
1469 +MODULE_LICENSE("GPL");
1470 +MODULE_DESCRIPTION("Childlevel match module");
1471 +
1472 +static int match(const struct sk_buff *skb,    const struct net_device *in,
1473 +                 const struct net_device *out, const void *matchinfo,
1474 +                 int offset,                   int *hotdrop)
1475 +{
1476 +       struct ipt_childlevel_info * info = (struct ipt_childlevel_info *)matchinfo;
1477 +        enum ip_conntrack_info ctinfo;
1478 +        struct ip_conntrack * conntrack;
1479 +       int childlevel = 0;
1480 +
1481 +        if(!(conntrack = ip_conntrack_get((struct sk_buff *)skb, &ctinfo))){
1482 +                printk(KERN_ERR "Netfilter: childlevel: error getting conntrack, giving up.\n");
1483 +               return 0;
1484 +        }
1485 +       
1486 +        while (master_ct(conntrack) != NULL){
1487 +               childlevel++;
1488 +                conntrack = master_ct(conntrack);
1489 +       }
1490 +
1491 +       return ( (childlevel == info->childlevel) ^ info->invert);
1492 +}
1493 +
1494 +static int
1495 +checkentry(const char *tablename, const struct ipt_ip *ip,
1496 +           void *matchinfo,       unsigned int matchsize,   unsigned int hook_mask)
1497 +{
1498 +       if (matchsize != IPT_ALIGN(sizeof(struct ipt_childlevel_info))) 
1499 +               return 0;
1500 +       return 1;
1501 +}
1502 +
1503 +static struct ipt_match childlevel_match = { 
1504 +       .name = "childlevel", 
1505 +       .match = &match, 
1506 +       .checkentry = &checkentry, 
1507 +       .me = THIS_MODULE 
1508 +};
1509 +
1510 +static int __init init(void)
1511 +{
1512 +       return ipt_register_match(&childlevel_match);
1513 +}
1514 +
1515 +static void __exit fini(void)
1516 +{
1517 +       ipt_unregister_match(&childlevel_match);
1518 +}
1519 +
1520 +module_init(init);
1521 +module_exit(fini);
1522 diff -Nur --exclude '*.orig' linux-2.6.5-rc2.org/net/ipv4/netfilter/ipt_connmark.c linux-2.6.5-rc2/net/ipv4/netfilter/ipt_connmark.c
1523 --- linux-2.6.5-rc2.org/net/ipv4/netfilter/ipt_connmark.c       1970-01-01 00:00:00.000000000 +0000
1524 +++ linux-2.6.5-rc2/net/ipv4/netfilter/ipt_connmark.c   2004-03-22 09:08:35.000000000 +0000
1525 @@ -0,0 +1,81 @@
1526 +/* This kernel module matches connection mark values set by the
1527 + * CONNMARK target
1528 + *
1529 + * Copyright (C) 2002,2004 MARA Systems AB <http://www.marasystems.com>
1530 + * by Henrik Nordstrom <hno@marasystems.com>
1531 + *
1532 + * This program is free software; you can redistribute it and/or modify
1533 + * it under the terms of the GNU General Public License as published by
1534 + * the Free Software Foundation; either version 2 of the License, or
1535 + * (at your option) any later version.
1536 + *
1537 + * This program is distributed in the hope that it will be useful,
1538 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1539 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1540 + * GNU General Public License for more details.
1541 + *
1542 + * You should have received a copy of the GNU General Public License
1543 + * along with this program; if not, write to the Free Software
1544 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
1545 + */
1546 +
1547 +#include <linux/module.h>
1548 +#include <linux/skbuff.h>
1549 +
1550 +MODULE_AUTHOR("Henrik Nordstrom <hno@marasytems.com>");
1551 +MODULE_DESCRIPTION("IP tables connmark match module");
1552 +MODULE_LICENSE("GPL");
1553 +
1554 +#include <linux/netfilter_ipv4/ip_tables.h>
1555 +#include <linux/netfilter_ipv4/ipt_connmark.h>
1556 +#include <linux/netfilter_ipv4/ip_conntrack.h>
1557 +
1558 +static int
1559 +match(const struct sk_buff *skb,
1560 +      const struct net_device *in,
1561 +      const struct net_device *out,
1562 +      const void *matchinfo,
1563 +      int offset,
1564 +      int *hotdrop)
1565 +{
1566 +       const struct ipt_connmark_info *info = matchinfo;
1567 +       enum ip_conntrack_info ctinfo;
1568 +       struct ip_conntrack *ct = ip_conntrack_get((struct sk_buff *)skb, &ctinfo);
1569 +       if (!ct)
1570 +               return 0;
1571 +
1572 +       return ((ct->mark & info->mask) == info->mark) ^ info->invert;
1573 +}
1574 +
1575 +static int
1576 +checkentry(const char *tablename,
1577 +          const struct ipt_ip *ip,
1578 +          void *matchinfo,
1579 +          unsigned int matchsize,
1580 +          unsigned int hook_mask)
1581 +{
1582 +       if (matchsize != IPT_ALIGN(sizeof(struct ipt_connmark_info)))
1583 +               return 0;
1584 +
1585 +       return 1;
1586 +}
1587 +
1588 +static struct ipt_match connmark_match = {
1589 +       .name = "connmark",
1590 +       .match = &match,
1591 +       .checkentry = &checkentry,
1592 +       .me = THIS_MODULE
1593 +};
1594 +
1595 +static int __init init(void)
1596 +{
1597 +       return ipt_register_match(&connmark_match);
1598 +}
1599 +
1600 +static void __exit fini(void)
1601 +{
1602 +       ipt_unregister_match(&connmark_match);
1603 +}
1604 +
1605 +module_init(init);
1606 +module_exit(fini);
1607 diff -Nur --exclude '*.orig' linux-2.6.5-rc2.org/net/ipv4/netfilter/ipt_helper.c linux-2.6.5-rc2/net/ipv4/netfilter/ipt_helper.c
1608 --- linux-2.6.5-rc2.org/net/ipv4/netfilter/ipt_helper.c 2004-03-22 08:57:53.000000000 +0000
1609 +++ linux-2.6.5-rc2/net/ipv4/netfilter/ipt_helper.c     2004-03-22 09:02:25.000000000 +0000
1610 @@ -71,8 +71,11 @@
1611         DEBUGP("master's name = %s , info->name = %s\n", 
1612                 exp->expectant->helper->name, info->name);
1613  
1614 -       ret ^= !strncmp(exp->expectant->helper->name, info->name, 
1615 -                       strlen(exp->expectant->helper->name));
1616 +       if (info->data[0] == '\0')
1617 +               ret ^= 1;
1618 +       else
1619 +               ret ^= !strncmp(exp->expectant->helper->name, info->name, 
1620 +                               strlen(exp->expectant->helper->name));
1621  out_unlock:
1622         READ_UNLOCK(&ip_conntrack_lock);
1623         return ret;
1624 @@ -92,10 +95,6 @@
1625         if (matchsize != IPT_ALIGN(sizeof(struct ipt_helper_info)))
1626                 return 0;
1627  
1628 -       /* verify that we actually should match anything */
1629 -       if ( strlen(info->name) == 0 )
1630 -               return 0;
1631 -       
1632         return 1;
1633  }
1634  
1635 diff -Nur --exclude '*.orig' linux-2.6.5-rc2.org/net/ipv4/netfilter/ipt_owner.c linux-2.6.5-rc2/net/ipv4/netfilter/ipt_owner.c
1636 --- linux-2.6.5-rc2.org/net/ipv4/netfilter/ipt_owner.c  2004-03-20 00:11:50.000000000 +0000
1637 +++ linux-2.6.5-rc2/net/ipv4/netfilter/ipt_owner.c      2004-03-22 09:02:35.000000000 +0000
1638 @@ -6,12 +6,19 @@
1639   * This program is free software; you can redistribute it and/or modify
1640   * it under the terms of the GNU General Public License version 2 as
1641   * published by the Free Software Foundation.
1642 + *
1643 + * 03/26/2003 Patrick McHardy <kaber@trash.net>        : LOCAL_IN support
1644   */
1645  
1646  #include <linux/module.h>
1647  #include <linux/skbuff.h>
1648  #include <linux/file.h>
1649 +#include <linux/ip.h>
1650 +#include <linux/tcp.h>
1651 +#include <linux/udp.h>
1652  #include <net/sock.h>
1653 +#include <net/tcp.h>
1654 +#include <net/udp.h>
1655  
1656  #include <linux/netfilter_ipv4/ipt_owner.h>
1657  #include <linux/netfilter_ipv4/ip_tables.h>
1658 @@ -21,7 +28,7 @@
1659  MODULE_DESCRIPTION("iptables owner match");
1660  
1661  static int
1662 -match_comm(const struct sk_buff *skb, const char *comm)
1663 +match_comm(const struct sock *sk, const char *comm)
1664  {
1665         struct task_struct *g, *p;
1666         struct files_struct *files;
1667 @@ -38,7 +45,7 @@
1668                         spin_lock(&files->file_lock);
1669                         for (i=0; i < files->max_fds; i++) {
1670                                 if (fcheck_files(files, i) ==
1671 -                                   skb->sk->sk_socket->file) {
1672 +                                   sk->sk_socket->file) {
1673                                         spin_unlock(&files->file_lock);
1674                                         task_unlock(p);
1675                                         read_unlock(&tasklist_lock);
1676 @@ -54,7 +61,7 @@
1677  }
1678  
1679  static int
1680 -match_pid(const struct sk_buff *skb, pid_t pid)
1681 +match_pid(const struct sock *sk, pid_t pid)
1682  {
1683         struct task_struct *p;
1684         struct files_struct *files;
1685 @@ -70,7 +77,7 @@
1686                 spin_lock(&files->file_lock);
1687                 for (i=0; i < files->max_fds; i++) {
1688                         if (fcheck_files(files, i) ==
1689 -                           skb->sk->sk_socket->file) {
1690 +                           sk->sk_socket->file) {
1691                                 spin_unlock(&files->file_lock);
1692                                 task_unlock(p);
1693                                 read_unlock(&tasklist_lock);
1694 @@ -86,10 +93,10 @@
1695  }
1696  
1697  static int
1698 -match_sid(const struct sk_buff *skb, pid_t sid)
1699 +match_sid(const struct sock *sk, pid_t sid)
1700  {
1701         struct task_struct *g, *p;
1702 -       struct file *file = skb->sk->sk_socket->file;
1703 +       struct file *file = sk->sk_socket->file;
1704         int i, found=0;
1705  
1706         read_lock(&tasklist_lock);
1707 @@ -129,41 +136,71 @@
1708        int *hotdrop)
1709  {
1710         const struct ipt_owner_info *info = matchinfo;
1711 +       struct iphdr *iph = skb->nh.iph;
1712 +       struct sock *sk = NULL;
1713 +       int ret = 0;
1714 +
1715 +       if (out) {
1716 +               sk = skb->sk;
1717 +       } else {
1718 +               if (iph->protocol == IPPROTO_TCP) {
1719 +                       struct tcphdr *tcph =
1720 +                               (struct tcphdr *)((u_int32_t *)iph + iph->ihl);
1721 +                       sk = tcp_v4_lookup(iph->saddr, tcph->source,
1722 +                                          iph->daddr, tcph->dest,
1723 +                                          skb->dev->ifindex);
1724 +                       if (sk && sk->sk_state == TCP_TIME_WAIT) {
1725 +                               tcp_tw_put((struct tcp_tw_bucket *)sk);
1726 +                               return ret;
1727 +                       }
1728 +               } else if (iph->protocol == IPPROTO_UDP) {
1729 +                       struct udphdr *udph =
1730 +                               (struct udphdr *)((u_int32_t *)iph + iph->ihl);
1731 +                       sk = udp_v4_lookup(iph->saddr, udph->source, iph->daddr,
1732 +                                          udph->dest, skb->dev->ifindex);
1733 +               }
1734 +       }
1735  
1736 -       if (!skb->sk || !skb->sk->sk_socket || !skb->sk->sk_socket->file)
1737 -               return 0;
1738 +       if (!sk || !sk->sk_socket || !sk->sk_socket->file)
1739 +               goto out;
1740  
1741         if(info->match & IPT_OWNER_UID) {
1742 -               if ((skb->sk->sk_socket->file->f_uid != info->uid) ^
1743 +               if ((sk->sk_socket->file->f_uid != info->uid) ^
1744                     !!(info->invert & IPT_OWNER_UID))
1745 -                       return 0;
1746 +                       goto out;
1747         }
1748  
1749         if(info->match & IPT_OWNER_GID) {
1750 -               if ((skb->sk->sk_socket->file->f_gid != info->gid) ^
1751 +               if ((sk->sk_socket->file->f_gid != info->gid) ^
1752                     !!(info->invert & IPT_OWNER_GID))
1753 -                       return 0;
1754 +                       goto out;
1755         }
1756  
1757         if(info->match & IPT_OWNER_PID) {
1758 -               if (!match_pid(skb, info->pid) ^
1759 +               if (!match_pid(sk, info->pid) ^
1760                     !!(info->invert & IPT_OWNER_PID))
1761 -                       return 0;
1762 +                       goto out;
1763         }
1764  
1765         if(info->match & IPT_OWNER_SID) {
1766 -               if (!match_sid(skb, info->sid) ^
1767 +               if (!match_sid(sk, info->sid) ^
1768                     !!(info->invert & IPT_OWNER_SID))
1769 -                       return 0;
1770 +                       goto out;
1771         }
1772  
1773         if(info->match & IPT_OWNER_COMM) {
1774 -               if (!match_comm(skb, info->comm) ^
1775 +               if (!match_comm(sk, info->comm) ^
1776                     !!(info->invert & IPT_OWNER_COMM))
1777 -                       return 0;
1778 +                       goto out;
1779         }
1780  
1781 -       return 1;
1782 +       ret = 1;
1783 +
1784 +out:
1785 +       if (in && sk)
1786 +               sock_put(sk);
1787 +
1788 +       return ret;
1789  }
1790  
1791  static int
1792 @@ -173,11 +210,19 @@
1793             unsigned int matchsize,
1794             unsigned int hook_mask)
1795  {
1796 -        if (hook_mask
1797 -            & ~((1 << NF_IP_LOCAL_OUT) | (1 << NF_IP_POST_ROUTING))) {
1798 -                printk("ipt_owner: only valid for LOCAL_OUT or POST_ROUTING.\n");
1799 -                return 0;
1800 -        }
1801 +       if (hook_mask
1802 +           & ~((1 << NF_IP_LOCAL_OUT) | (1 << NF_IP_POST_ROUTING) |
1803 +           (1 << NF_IP_LOCAL_IN))) {
1804 +               printk("ipt_owner: only valid for LOCAL_IN, LOCAL_OUT "
1805 +                      "or POST_ROUTING.\n");
1806 +               return 0;
1807 +       }
1808 +
1809 +       if ((hook_mask & (1 << NF_IP_LOCAL_IN))
1810 +           && ip->proto != IPPROTO_TCP && ip->proto != IPPROTO_UDP) {
1811 +               printk("ipt_owner: only TCP or UDP can be used in LOCAL_IN\n");
1812 +               return 0;
1813 +       }
1814  
1815         if (matchsize != IPT_ALIGN(sizeof(struct ipt_owner_info))) {
1816                 printk("Matchsize %u != %Zu\n", matchsize,
1817 diff -Nur --exclude '*.orig' linux-2.6.5-rc2.org/net/ipv4/netfilter/ipt_policy.c linux-2.6.5-rc2/net/ipv4/netfilter/ipt_policy.c
1818 --- linux-2.6.5-rc2.org/net/ipv4/netfilter/ipt_policy.c 1970-01-01 00:00:00.000000000 +0000
1819 +++ linux-2.6.5-rc2/net/ipv4/netfilter/ipt_policy.c     2004-03-22 09:02:50.000000000 +0000
1820 @@ -0,0 +1,176 @@
1821 +/* IP tables module for matching IPsec policy
1822 + *
1823 + * Copyright (c) 2004 Patrick McHardy, <kaber@trash.net>
1824 + *
1825 + * This program is free software; you can redistribute it and/or modify
1826 + * it under the terms of the GNU General Public License version 2 as
1827 + * published by the Free Software Foundation.
1828 + */
1829 +
1830 +#include <linux/kernel.h>
1831 +#include <linux/config.h>
1832 +#include <linux/module.h>
1833 +#include <linux/skbuff.h>
1834 +#include <linux/init.h>
1835 +#include <net/xfrm.h>
1836 +
1837 +#include <linux/netfilter_ipv4.h>
1838 +#include <linux/netfilter_ipv4/ipt_policy.h>
1839 +#include <linux/netfilter_ipv4/ip_tables.h>
1840 +
1841 +MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
1842 +MODULE_DESCRIPTION("IPtables IPsec policy matching module");
1843 +MODULE_LICENSE("GPL");
1844 +
1845 +
1846 +static inline int
1847 +match_xfrm_state(struct xfrm_state *x, const struct ipt_policy_elem *e)
1848 +{
1849 +#define MISMATCH(x,y)  (e->match.x && ((e->x != (y)) ^ e->invert.x))
1850 +
1851 +       if (MISMATCH(saddr, x->props.saddr.a4 & e->smask) ||
1852 +           MISMATCH(daddr, x->id.daddr.a4 & e->dmask) ||
1853 +           MISMATCH(proto, x->id.proto) ||
1854 +           MISMATCH(mode, x->props.mode) ||
1855 +           MISMATCH(spi, x->id.spi) ||
1856 +           MISMATCH(reqid, x->props.reqid))
1857 +               return 0;
1858 +       return 1;
1859 +}
1860 +
1861 +static int
1862 +match_policy_in(const struct sk_buff *skb, const struct ipt_policy_info *info)
1863 +{
1864 +       const struct ipt_policy_elem *e;
1865 +       struct sec_path *sp = skb->sp;
1866 +       int strict = info->flags & POLICY_MATCH_STRICT;
1867 +       int i, pos;
1868 +
1869 +       if (sp == NULL)
1870 +               return -1;
1871 +       if (strict && info->len != sp->len)
1872 +               return 0;
1873 +
1874 +       for (i = sp->len - 1; i >= 0; i--) {
1875 +               pos = strict ? i - sp->len + 1 : 0;
1876 +               if (pos >= info->len)
1877 +                       return 0;
1878 +               e = &info->pol[pos];
1879 +
1880 +               if (match_xfrm_state(sp->x[i].xvec, e)) {
1881 +                       if (!strict)
1882 +                               return 1;
1883 +               } else if (strict)
1884 +                       return 0;
1885 +       }
1886 +
1887 +       return strict ? 1 : 0;
1888 +}
1889 +
1890 +static int
1891 +match_policy_out(const struct sk_buff *skb, const struct ipt_policy_info *info)
1892 +{
1893 +       const struct ipt_policy_elem *e;
1894 +       struct dst_entry *dst = skb->dst;
1895 +       int strict = info->flags & POLICY_MATCH_STRICT;
1896 +       int i, pos;
1897 +
1898 +       if (dst->xfrm == NULL)
1899 +               return -1;
1900 +
1901 +       for (i = 0; dst && dst->xfrm; dst = dst->child, i++) {
1902 +               pos = strict ? i : 0;
1903 +               if (pos >= info->len)
1904 +                       return 0;
1905 +               e = &info->pol[pos];
1906 +
1907 +               if (match_xfrm_state(dst->xfrm, e)) {
1908 +                       if (!strict)
1909 +                               return 1;
1910 +               } else if (strict)
1911 +                       return 0;
1912 +       }
1913 +
1914 +       return strict ? 1 : 0;
1915 +}
1916 +
1917 +static int match(const struct sk_buff *skb,
1918 +                 const struct net_device *in,
1919 +                 const struct net_device *out,
1920 +                 const void *matchinfo, int offset, int *hotdrop)
1921 +{
1922 +       const struct ipt_policy_info *info = matchinfo;
1923 +       int ret;
1924 +
1925 +       if (info->flags & POLICY_MATCH_IN)
1926 +               ret = match_policy_in(skb, info);
1927 +       else
1928 +               ret = match_policy_out(skb, info);
1929 +
1930 +       if (ret < 0) {
1931 +               if (info->flags & POLICY_MATCH_NONE)
1932 +                       ret = 1;
1933 +               else
1934 +                       ret = 0;
1935 +       } else if (info->flags & POLICY_MATCH_NONE)
1936 +               ret = 0;
1937 +
1938 +       return ret;
1939 +}
1940 +
1941 +static int checkentry(const char *tablename, const struct ipt_ip *ip,
1942 +                      void *matchinfo, unsigned int matchsize,
1943 +                      unsigned int hook_mask)
1944 +{
1945 +       struct ipt_policy_info *info = matchinfo;
1946 +
1947 +       if (matchsize != IPT_ALIGN(sizeof(*info))) {
1948 +               printk(KERN_ERR "ipt_policy: matchsize %u != %u\n",
1949 +                      matchsize, IPT_ALIGN(sizeof(*info)));
1950 +               return 0;
1951 +       }
1952 +       if (!(info->flags & (POLICY_MATCH_IN|POLICY_MATCH_OUT))) {
1953 +               printk(KERN_ERR "ipt_policy: neither incoming nor "
1954 +                               "outgoing policy selected\n");
1955 +               return 0;
1956 +       }
1957 +       if (hook_mask & (1 << NF_IP_PRE_ROUTING | 1 << NF_IP_LOCAL_IN)
1958 +           && info->flags & POLICY_MATCH_OUT) {
1959 +               printk(KERN_ERR "ipt_policy: output policy not valid in "
1960 +                               "PRE_ROUTING and INPUT\n");
1961 +               return 0;
1962 +       }
1963 +       if (hook_mask & (1 << NF_IP_POST_ROUTING | 1 << NF_IP_LOCAL_OUT)
1964 +           && info->flags & POLICY_MATCH_IN) {
1965 +               printk(KERN_ERR "ipt_policy: input policy not valid in "
1966 +                               "POST_ROUTING and OUTPUT\n");
1967 +               return 0;
1968 +       }
1969 +       if (info->len > POLICY_MAX_ELEM) {
1970 +               printk(KERN_ERR "ipt_policy: too many policy elements\n");
1971 +               return 0;
1972 +       }
1973 +
1974 +       return 1;
1975 +}
1976 +
1977 +static struct ipt_match policy_match =
1978 +{
1979 +       .name           = "policy",
1980 +       .match          = match,
1981 +       .checkentry     = checkentry,
1982 +       .me             = THIS_MODULE,
1983 +};
1984 +
1985 +static int __init init(void)
1986 +{
1987 +       return ipt_register_match(&policy_match);
1988 +}
1989 +
1990 +static void __exit fini(void)
1991 +{
1992 +       ipt_unregister_match(&policy_match);
1993 +}
1994 +
1995 +module_init(init);
1996 +module_exit(fini);
1997 diff -Nur --exclude '*.orig' linux-2.6.5-rc2.org/net/ipv4/tcp_ipv4.c linux-2.6.5-rc2/net/ipv4/tcp_ipv4.c
1998 --- linux-2.6.5-rc2.org/net/ipv4/tcp_ipv4.c     2004-03-20 00:11:04.000000000 +0000
1999 +++ linux-2.6.5-rc2/net/ipv4/tcp_ipv4.c 2004-03-22 09:02:35.000000000 +0000
2000 @@ -2667,6 +2667,7 @@
2001  EXPORT_SYMBOL(tcp_v4_connect);
2002  EXPORT_SYMBOL(tcp_v4_do_rcv);
2003  EXPORT_SYMBOL(tcp_v4_lookup_listener);
2004 +EXPORT_SYMBOL(tcp_v4_lookup);
2005  EXPORT_SYMBOL(tcp_v4_rebuild_header);
2006  EXPORT_SYMBOL(tcp_v4_remember_stamp);
2007  EXPORT_SYMBOL(tcp_v4_send_check);
2008 diff -Nur --exclude '*.orig' linux-2.6.5-rc2.org/net/ipv4/udp.c linux-2.6.5-rc2/net/ipv4/udp.c
2009 --- linux-2.6.5-rc2.org/net/ipv4/udp.c  2004-03-20 00:11:02.000000000 +0000
2010 +++ linux-2.6.5-rc2/net/ipv4/udp.c      2004-03-22 09:02:35.000000000 +0000
2011 @@ -1543,6 +1543,7 @@
2012  EXPORT_SYMBOL(udp_port_rover);
2013  EXPORT_SYMBOL(udp_prot);
2014  EXPORT_SYMBOL(udp_sendmsg);
2015 +EXPORT_SYMBOL(udp_v4_lookup);
2016  
2017  #ifdef CONFIG_PROC_FS
2018  EXPORT_SYMBOL(udp_proc_register);
This page took 0.233136 seconds and 3 git commands to generate.