1 Netfilter SNAP 20040608
3 updates/01_iptables-1.2.10
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
14 PENDING/proc-no-internal-targets
15 PENDING/proc_net_conntrack-permissions
18 BASE/NETLINK // fix socket -> sk_socket
27 BASE/osf // fix socket -> sk_socket
28 BASE/pool // added EXPORT_SYMBOL(ip_pool_mod, ip_pool_match)
32 BASE/raw // removed linux-2.6.patch - included in kernel
41 EXTRA/TRACE // ip_output.c fix
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
51 EXTRA/mms-conntrack-nat
52 EXTRA/owner-socketlookup
55 EXTRA/quake3-conntrack-nat
58 EXTRA/sctp-conntrack-nat
59 EXTRA/string // required unclean module - included - req fix
60 EXTRA/talk-conntrack-nat
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
66 <= 0x2000 is used for protocol-flags. */
67 #define NFC_UNKNOWN 0x4000
68 #define NFC_ALTERED 0x8000
69 +#define NFC_TRACE 0x10000
72 #include <linux/config.h>
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) \
82 + : nf_hook_slow((pf), (hook), (skb), (indev), (outdev), (okfn), INT_MIN))
83 #define NF_HOOK_THRESH nf_hook_slow
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)]) \
90 : nf_hook_slow((pf), (hook), (skb), (indev), (outdev), (okfn), INT_MIN))
91 #define NF_HOOK_THRESH(pf, hook, skb, indev, outdev, okfn, thresh) \
94 : nf_hook_slow((pf), (hook), (skb), (indev), (outdev), (okfn), (thresh)))
96 +#define NF_HOOK(pf, hook, skb, indev, outdev, okfn) \
97 + NF_HOOK_COND((pf), (hook), (skb), (indev), (outdev), (okfn), 1)
99 int nf_hook_slow(int pf, unsigned int hook, struct sk_buff *skb,
100 struct net_device *indev, struct net_device *outdev,
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*/
109 +#ifdef CONFIG_IP_NF_NAT_NEEDED
111 +extern void nf_nat_decode_session4(struct sk_buff *skb, struct flowi *fl);
114 +nf_nat_decode_session(struct sk_buff *skb, struct flowi *fl, int family)
116 + if (family == AF_INET)
117 + nf_nat_decode_session4(skb, fl);
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 */
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
131 + * Helpers for netfiler modules. This file provides implementations for basic
132 + * functions such as strncasecmp(), etc.
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()
140 +#ifndef _NETFILTER_HELPERS_H
141 +#define _NETFILTER_HELPERS_H
143 +/* Only include these functions for kernel code. */
146 +#include <linux/ctype.h>
147 +#define iseol(c) ( (c) == '\r' || (c) == '\n' )
150 + * The standard strncasecmp()
152 +#ifdef NF_NEED_STRNCASECMP
154 +nf_strncasecmp(const char* s1, const char* s2, u_int32_t len)
156 + if (s1 == NULL || s2 == NULL)
158 + if (s1 == NULL && s2 == NULL)
162 + return (s1 == NULL) ? -1 : 1;
164 + while (len > 0 && tolower(*s1) == tolower(*s2))
170 + return ( (len == 0) ? 0 : (tolower(*s1) - tolower(*s2)) );
172 +#endif /* NF_NEED_STRNCASECMP */
175 + * Parse a string containing a 16-bit unsigned integer.
176 + * Returns the number of chars used, or zero if no number is found.
178 +#ifdef NF_NEED_STRTOU16
180 +nf_strtou16(const char* pbuf, u_int16_t* pval)
185 + while (isdigit(pbuf[n]))
187 + *pval = (*pval * 10) + (pbuf[n] - '0');
193 +#endif /* NF_NEED_STRTOU16 */
196 + * Parse a string containing a 32-bit unsigned integer.
197 + * Returns the number of chars used, or zero if no number is found.
199 +#ifdef NF_NEED_STRTOU32
201 +nf_strtou32(const char* pbuf, u_int32_t* pval)
206 + while (pbuf[n] >= '0' && pbuf[n] <= '9')
208 + *pval = (*pval * 10) + (pbuf[n] - '0');
214 +#endif /* NF_NEED_STRTOU32 */
217 + * Given a buffer and length, advance to the next line and mark the current
220 +#ifdef NF_NEED_NEXTLINE
222 +nf_nextline(char* p, uint len, uint* poff, uint* plineoff, uint* plinelen)
232 + while (p[off] != '\n')
243 + /* if we saw a crlf, physlen needs adjusted */
244 + if (physlen > 0 && p[off] == '\n' && p[off-1] == '\r')
249 + /* advance past the newline */
253 + *plinelen = physlen;
258 +#endif /* NF_NEED_NEXTLINE */
260 +#endif /* __KERNEL__ */
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
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>
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;
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>
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;
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;
317 #endif /* CONFIG_IP_NF_NAT_NEEDED */
319 +#if defined(CONFIG_IP_NF_CONNTRACK_MARK)
320 + unsigned long mark;
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
330 +#ifndef _IP_CONNTRACK_H323_H
331 +#define _IP_CONNTRACK_H323_H
332 +/* H.323 connection tracking. */
335 +/* Protects H.323 related data */
336 +#include <linux/netfilter_ipv4/lockhelp.h>
337 +DECLARE_LOCK_EXTERN(ip_h323_lock);
340 +/* Default H.225 port */
341 +#define H225_PORT 1720
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 */
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 */
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
365 +#ifndef _IP_CONNTRACK_MMS_H
366 +#define _IP_CONNTRACK_MMS_H
370 +#include <linux/netfilter_ipv4/lockhelp.h>
372 +DECLARE_LOCK_EXTERN(ip_mms_lock);
374 +#define MMS_PORT 1755
375 +#define MMS_SRV_MSG_ID 196610
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
384 +/* This structure is per expected connection */
385 +struct ip_ct_mms_expect {
391 +/* This structure exists only once per master */
392 +struct ip_ct_mms_master {
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
400 +#ifndef _IP_CT_QUAKE3
401 +#define _IP_CT_QUAKE3
403 +/* Don't confuse with 27960, often used as the Server Port */
404 +#define QUAKE3_MASTER_PORT 27950
406 +struct quake3_search {
407 + const char marker[4]; /* always 0xff 0xff 0xff 0xff ? */
408 + const char *pattern;
412 +/* This structure is per expected connection */
413 +struct ip_ct_quake3_expect {
416 +/* This structure exists only once per master */
417 +struct ip_ct_quake3_master {
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
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
429 + * ip_conntrack_rsh.c,v 1.0 2002/07/17 14:49:26
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.
436 +#ifndef _IP_CONNTRACK_RSH_H
437 +#define _IP_CONNTRACK_RSH_H
440 +#include <linux/netfilter_ipv4/lockhelp.h>
442 +DECLARE_LOCK_EXTERN(ip_rsh_lock);
446 +#define RSH_PORT 514
448 +/* This structure is per expected connection */
449 +struct ip_ct_rsh_expect
454 +/* This structure exists only once per master */
455 +struct ip_ct_rsh_master {
458 +#endif /* _IP_CONNTRACK_RSH_H */
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
465 + * RTSP extension for IP connection tracking.
466 + * (C) 2003 by Tom Marshall <tmarshall@real.com>
467 + * based on ip_conntrack_irc.h
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.
474 +#ifndef _IP_CONNTRACK_RTSP_H
475 +#define _IP_CONNTRACK_RTSP_H
477 +/* #define IP_NF_RTSP_DEBUG */
478 +#define IP_NF_RTSP_VERSION "0.01"
480 +/* port block types */
482 + pb_single, /* client_port=x */
483 + pb_range, /* client_port=x-y */
484 + pb_discon /* client_port=x/y (rtspbis) */
487 +/* We record seq number and length of rtsp headers here, all in host order. */
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.
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.
501 +struct ip_ct_rtsp_expect
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 */
508 + uint method; /* RTSP method */
509 + uint cseq; /* CSeq from request */
513 +/* This structure exists only once per master */
514 +struct ip_ct_rtsp_master
522 +#include <linux/netfilter_ipv4/lockhelp.h>
524 +#define RTSP_PORT 554
526 +/* Protects rtsp part of conntracks */
527 +DECLARE_LOCK_EXTERN(ip_rtsp_lock);
529 +#endif /* __KERNEL__ */
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
536 +#ifndef _IP_CONNTRACK_SCTP_H
537 +#define _IP_CONNTRACK_SCTP_H
538 +/* SCTP tracking. */
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,
554 + enum sctp_conntrack state;
556 + u_int32_t vtag[IP_CT_DIR_MAX];
557 + u_int32_t ttag[IP_CT_DIR_MAX];
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
565 +#ifndef _IP_CONNTRACK_TALK_H
566 +#define _IP_CONNTRACK_TALK_H
567 +/* TALK tracking. */
570 +#include <linux/in.h>
571 +#include <linux/netfilter_ipv4/lockhelp.h>
573 +/* Protects talk part of conntracks */
574 +DECLARE_LOCK_EXTERN(ip_talk_lock);
578 +#define TALK_PORT 517
579 +#define NTALK_PORT 518
581 +/* talk structures and constants from <protocols/talkd.h> */
584 + * 4.3BSD struct sockaddr
587 + u_int16_t ta_family;
590 + u_int32_t ta_junk1;
591 + u_int32_t ta_junk2;
594 +#define TALK_OLD_NSIZE 9
595 +#define TALK_NSIZE 12
596 +#define TALK_TTY_NSIZE 16
599 + * Client->server request message formats.
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 */
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 */
614 + u_char vers; /* protocol version */
615 + u_char type; /* request type, see below */
616 + u_char answer; /* not used */
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 */
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 */
642 + * Server->client response message formats.
644 +struct talk_response {
645 + u_char type; /* type of request message, see below */
646 + u_char answer; /* response to request message, see below */
648 + u_int32_t id_num; /* message id */
649 + struct talk_addr addr; /* address for establishing conversation */
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 */
657 + u_int32_t id_num; /* message id */
658 + struct talk_addr addr; /* address for establishing conversation */
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 */
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)
676 +#define TALK_VERSION 0 /* protocol versions */
677 +#define NTALK_VERSION 1
678 +#define NTALK2_VERSION 2
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 */
686 +#define REPLY_QUERY 4 /* request reply data from local daemon */
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 */
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 */
704 +/* We don't really need much for talk */
705 +struct ip_ct_talk_expect
707 + /* Port that was to be used */
711 +/* This structure exists only once per master */
712 +struct ip_ct_talk_master
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
729 /* The manipulable part of the tuple. */
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
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. */
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. */
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 +/***************************************************************************/
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!
768 + * Comes with its own certificate of authenticity, valid anywhere in the
773 +#define SO_IP_POOL 81
775 +typedef int ip_pool_t; /* pool index */
776 +#define IP_POOL_NONE ((ip_pool_t)-1)
778 +struct ip_pool_request {
785 +/* NOTE: I deliberately break the first cut ippool utility. Nobody uses it. */
787 +#define IP_POOL_BAD001 0x00000010
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 */
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);
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
813 unsigned int comefrom;
815 + /* Name of the chain */
818 + /* Rule number in the chain. */
821 /* Packet and byte counters. */
822 struct ipt_counters counters;
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
828 +#ifndef _IPT_CONNMARK_H_target
829 +#define _IPT_CONNMARK_H_target
831 +/* Copyright (C) 2002,2004 MARA Systems AB <http://www.marasystems.com>
832 + * by Henrik Nordstrom <hno@marasystems.com>
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.
841 + IPT_CONNMARK_SET = 0,
843 + IPT_CONNMARK_RESTORE
846 +struct ipt_connmark_target_info {
847 + unsigned long mark;
848 + unsigned long mask;
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
857 +#ifndef _IPT_IPMARK_H_target
858 +#define _IPT_IPMARK_H_target
860 +struct ipt_ipmark_target_info {
861 + unsigned long andmask;
862 + unsigned long ormask;
866 +#define IPT_IPMARK_SRC 0
867 +#define IPT_IPMARK_DST 1
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
874 +#ifndef _IPT_FWMON_H
875 +#define _IPT_FWMON_H
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
882 +#define USE_MARK 0x00000001
883 +#define USE_DROP 0x00000002
884 +#define USE_SIZE 0x00000004
888 + unsigned int flags;
897 + char iface[IFNAMSIZ];
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
905 +/* Header file for iptables ipt_ROUTE target
907 + * (C) 2002 by Cédric de Launois <delaunois@info.ucl.ac.be>
909 + * This software is distributed under GNU GPL v2, 1991
911 +#ifndef _IPT_ROUTE_H_target
912 +#define _IPT_ROUTE_H_target
914 +#define IPT_ROUTE_IFNAMSIZ 16
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 */
923 +/* Values for "flags" field */
924 +#define IPT_ROUTE_CONTINUE 0x01
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
931 +/* TTL modification module for IP tables
932 + * (C) 2000 by Harald Welte <laforge@gnumonks.org> */
943 +#define IPT_TTL_MAXMODE IPT_TTL_DEC
945 +struct ipt_TTL_info {
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
959 +struct ipt_XOR_info {
961 + u_int8_t block_size;
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
969 +#ifndef _IPT_ADDRTYPE_H
970 +#define _IPT_ADDRTYPE_H
972 +struct ipt_addrtype_info {
973 + u_int16_t source; /* source-type mask */
974 + u_int16_t dest; /* dest-type mask */
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
984 +#ifndef _IPT_CONNLIMIT_H
985 +#define _IPT_CONNLIMIT_H
987 +struct ipt_connlimit_data;
989 +struct ipt_connlimit_info {
993 + struct ipt_connlimit_data *data;
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
1000 +#ifndef _IPT_CONNMARK_H
1001 +#define _IPT_CONNMARK_H
1003 +/* Copyright (C) 2002,2004 MARA Systems AB <http://www.marasystems.com>
1004 + * by Henrik Nordstrom <hno@marasystems.com>
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.
1012 +struct ipt_connmark_info {
1013 + unsigned long mark, mask;
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
1022 +#ifndef _IPT_DSTLIMIT_H
1023 +#define _IPT_DSTLIMIT_H
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. */
1030 +/* details of this structure hidden by the implementation */
1031 +struct ipt_dstlimit_htable;
1033 +#define IPT_DSTLIMIT_HASH_DIP 0x0001
1034 +#define IPT_DSTLIMIT_HASH_DPT 0x0002
1035 +#define IPT_DSTLIMIT_HASH_SIP 0x0004
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. */
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? */
1049 +struct ipt_dstlimit_info {
1050 + char name [IFNAMSIZ]; /* name */
1051 + struct dstlimit_cfg cfg;
1052 + struct ipt_dstlimit_htable *hinfo;
1054 + /* Used internally by the kernel */
1057 + struct ipt_dstlimit_info *master;
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
1065 +#ifndef _IPT_FUZZY_H
1066 +#define _IPT_FUZZY_H
1068 +#include <linux/param.h>
1069 +#include <linux/types.h>
1071 +#define MAXFUZZYRATE 10000000
1072 +#define MINFUZZYRATE 3
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;
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
1090 +#ifndef __ipt_ipv4options_h_included__
1091 +#define __ipt_ipv4options_h_included__
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 */
1105 +struct ipt_ipv4options_info {
1106 + u_int16_t options;
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
1115 +#ifndef _IPT_MPORT_H
1116 +#define _IPT_MPORT_H
1117 +#include <linux/netfilter_ipv4/ip_tables.h>
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)
1123 +#define IPT_MULTI_PORTS 15
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[] */
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 */
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
1146 +#include <linux/param.h>
1147 +#include <linux/types.h>
1149 +#ifndef IPT_NTH_NUM_COUNTERS
1150 +#define IPT_NTH_NUM_COUNTERS 16
1153 +struct ipt_nth_info {
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
1169 + * Copyright (c) 2003 Evgeniy Polyakov <johnpol@2ka.mipt.ru>
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.
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.
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
1190 +#define MAXGENRELEN 32
1191 +#define MAXDETLEN 64
1193 +#define IPT_OSF_GENRE 1
1194 +#define IPT_OSF_SMART 2
1195 +#define IPT_OSF_LOG 4
1196 +#define IPT_OSF_NETLINK 8
1198 +#define IPT_OSF_LOGLEVEL_ALL 0
1199 +#define IPT_OSF_LOGLEVEL_FIRST 1
1201 +#include <linux/list.h>
1204 +#include <netinet/ip.h>
1205 +#include <netinet/tcp.h>
1209 + struct list_head *prev, *next;
1213 +struct ipt_osf_info
1215 + char genre[MAXGENRELEN];
1217 + unsigned long flags;
1219 + int invert; /* UNSUPPORTED */
1225 + unsigned long val;
1228 +/* This struct represents IANA options
1229 + * http://www.iana.org/assignments/tcp-parameters
1233 + unsigned char kind;
1234 + unsigned char length;
1240 + struct list_head flist;
1241 + struct osf_wc wss;
1242 + unsigned char ttl;
1245 + unsigned char genre[MAXGENRELEN];
1246 + unsigned char version[MAXGENRELEN], subtype[MAXGENRELEN];
1248 + /* Not needed, but for consistency with original table from Michal Zalewski */
1249 + unsigned char details[MAXDETLEN];
1252 + struct osf_opt opt[MAX_IPOPTLEN]; /* In case it is all NOP or EOL */
1256 +struct ipt_osf_nlmsg
1258 + struct osf_finger f;
1260 + struct tcphdr tcp;
1265 +/* Defines for IANA option kinds */
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 */
1280 +static struct osf_opt IANA_opts[] =
1287 + {5, 1 ,}, /* SACK length is not defined */
1293 + {11, 1,}, /* CC: Suppose 1 */
1294 + {12, 1,}, /* the same */
1295 + {13, 1,}, /* and here too */
1297 + {15, 1,}, /* TCP Alternate Checksum Data. Length is not defined */
1311 +#endif /* __KERNEL__ */
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
1318 +#ifndef _IPT_POLICY_H
1319 +#define _IPT_POLICY_H
1321 +#define POLICY_MAX_ELEM 4
1323 +enum ipt_policy_flags
1325 + POLICY_MATCH_IN = 0x1,
1326 + POLICY_MATCH_OUT = 0x2,
1327 + POLICY_MATCH_NONE = 0x4,
1328 + POLICY_MATCH_STRICT = 0x8,
1331 +enum ipt_policy_modes
1333 + POLICY_MODE_TRANSPORT,
1334 + POLICY_MODE_TUNNEL
1337 +struct ipt_policy_spec
1347 +struct ipt_policy_elem
1358 + struct ipt_policy_spec match;
1359 + struct ipt_policy_spec invert;
1362 +struct ipt_policy_info
1364 + struct ipt_policy_elem pol[POLICY_MAX_ELEM];
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
1374 +#ifndef _IPT_POOL_H
1375 +#define _IPT_POOL_H
1377 +#include <linux/netfilter_ipv4/ip_pool.h>
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
1391 +struct ipt_pool_info
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
1406 +#include <linux/param.h>
1407 +#include <linux/types.h>
1410 + * High port numbers have a lower weight to reduce the frequency of false
1411 + * positives, such as from passive mode FTP transfers.
1413 +#define PORT_WEIGHT_PRIV 3
1414 +#define PORT_WEIGHT_HIGH 1
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.
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 */
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.
1430 +#define LIST_SIZE 0x100
1432 +#define HASH_SIZE (1 << HASH_LOG)
1433 +#define HASH_MAX 0x10
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;
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
1447 +#ifndef _IPT_QUOTA_H
1448 +#define _IPT_QUOTA_H
1450 +/* print debug info in both kernel/netfilter module & iptable library */
1451 +//#define DEBUG_IPT_QUOTA
1453 +struct ipt_quota_info {
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
1462 +#ifndef _IPT_RAND_H
1463 +#define _IPT_RAND_H
1465 +#include <linux/param.h>
1466 +#include <linux/types.h>
1468 +struct ipt_rand_info {
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
1477 +#ifndef _IPT_REALM_H
1478 +#define _IPT_REALM_H
1480 +struct ipt_realm_info {
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
1490 +#ifndef _IPT_SCTP_H_
1491 +#define _IPT_SCTP_H_
1493 +#define IPT_SCTP_SRC_PORTS 0x01
1494 +#define IPT_SCTP_DEST_PORTS 0x02
1495 +#define IPT_SCTP_CHUNK_TYPES 0x04
1497 +#define IPT_SCTP_VALID_FLAGS 0x07
1499 +#define ELEMCOUNT(x) (sizeof(x)/sizeof(x[0]))
1502 +struct ipt_sctp_flag_info {
1503 + u_int8_t chunktype;
1505 + u_int8_t flag_mask;
1508 +#define IPT_NUM_SCTP_FLAGS 4
1510 +struct ipt_sctp_info {
1511 + u_int16_t dpts[2]; /* Min, Max */
1512 + u_int16_t spts[2]; /* Min, Max */
1514 + u_int32_t chunkmap[256 / sizeof (u_int32_t)]; /* Bit mask of chunks to be matched according to RFC 2960 */
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 */
1520 + u_int32_t chunk_match_type;
1521 + struct ipt_sctp_flag_info flag_info[IPT_NUM_SCTP_FLAGS];
1525 + u_int32_t invflags;
1528 +#define bytes(type) (sizeof(type) * 8)
1530 +#define SCTP_CHUNKMAP_SET(chunkmap, type) \
1532 + chunkmap[type / bytes(u_int32_t)] |= \
1533 + 1 << (type % bytes(u_int32_t)); \
1536 +#define SCTP_CHUNKMAP_CLEAR(chunkmap, type) \
1538 + chunkmap[type / bytes(u_int32_t)] &= \
1539 + ~(1 << (type % bytes(u_int32_t))); \
1542 +#define SCTP_CHUNKMAP_IS_SET(chunkmap, type) \
1544 + (chunkmap[type / bytes (u_int32_t)] & \
1545 + (1 << (type % bytes (u_int32_t)))) ? 1: 0; \
1548 +#define SCTP_CHUNKMAP_RESET(chunkmap) \
1551 + for (i = 0; i < ELEMCOUNT(chunkmap); i++) \
1552 + chunkmap[i] = 0; \
1555 +#define SCTP_CHUNKMAP_SET_ALL(chunkmap) \
1558 + for (i = 0; i < ELEMCOUNT(chunkmap); i++) \
1559 + chunkmap[i] = ~0; \
1562 +#define SCTP_CHUNKMAP_COPY(destmap, srcmap) \
1565 + for (i = 0; i < ELEMCOUNT(chunkmap); i++) \
1566 + destmap[i] = srcmap[i]; \
1569 +#define SCTP_CHUNKMAP_IS_CLEAR(chunkmap) \
1573 + for (i = 0; i < ELEMCOUNT(chunkmap); i++) { \
1574 + if (chunkmap[i]) { \
1582 +#define SCTP_CHUNKMAP_IS_ALL_SET(chunkmap) \
1586 + for (i = 0; i < ELEMCOUNT(chunkmap); i++) { \
1587 + if (chunkmap[i] != ~0) { \
1595 +#endif /* _IPT_SCTP_H_ */
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
1601 +#ifndef _IPT_STRING_H
1602 +#define _IPT_STRING_H
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
1610 +#define BM_MAX_NLEN 256
1611 +#define BM_MAX_HLEN 1024
1613 +typedef char *(*proc_ipt_search) (char *, char *, int, int);
1615 +struct ipt_string_info {
1616 + char string[BM_MAX_NLEN];
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
1626 +#ifndef __ipt_time_h_included__
1627 +#define __ipt_time_h_included__
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;
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
1647 +#include <linux/netfilter_ipv4/ip_tables.h>
1657 +struct ipt_u32_location_element
1662 +struct ipt_u32_value_element
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
1673 + struct ipt_u32_location_element location[U32MAXSIZE+1];
1675 + struct ipt_u32_value_element value[U32MAXSIZE+1];
1681 + struct ipt_u32_test tests[U32MAXSIZE+1];
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
1690 #include <linux/config.h>
1691 #include <linux/netfilter.h>
1692 +#include <linux/netdevice.h>
1693 +#include <net/protocol.h>
1695 /* IP Cache bits. */
1696 /* Src IP address. */
1698 Returns true or false. */
1699 extern int skb_ip_make_writable(struct sk_buff **pskb,
1700 unsigned int writable_len);
1702 +#if defined(CONFIG_XFRM) && defined(CONFIG_NETFILTER)
1703 +#include <net/route.h>
1704 +#include <net/xfrm.h>
1706 +static inline int nf_hook_input_cond(struct sk_buff *skb)
1708 + return !skb->sp || skb->sp->decap_done;
1712 +nf_xfrm_local_done(struct sk_buff *skb, struct inet_protocol *ipprot)
1714 + return skb->sp && !skb->sp->decap_done
1715 + && (!ipprot || !ipprot->xfrm_prot);
1718 +static inline int nf_xfrm_nonlocal_done(struct sk_buff *skb)
1720 + return skb->sp && !skb->sp->decap_done
1721 + && !(((struct rtable *)skb->dst)->rt_flags&RTCF_LOCAL);
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)
1733 +nf_xfrm_local_done(struct sk_buff *skb, struct inet_protocol *ipprot)
1738 +static inline int nf_xfrm_nonlocal_done(struct sk_buff *skb)
1743 +static inline int nf_rcv_postxfrm_local(struct sk_buff *skb)
1748 +static inline int nf_rcv_postxfrm_nonlocal(struct sk_buff *skb)
1752 +#endif /* CONFIG_XFRM */
1753 #endif /*__KERNEL__*/
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 @@
1761 unsigned int comefrom;
1763 + /* Name of the chain */
1766 + /* Rule number in the chain. */
1767 + u_int32_t rulenum;
1769 /* Packet and byte counters. */
1770 struct ip6t_counters counters;
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
1776 +/* Hop Limit modification module for ip6tables
1777 + * Maciej Soltysiak <solt@dns.toxicfilms.tv>
1778 + * Based on HW's TTL module */
1789 +#define IP6T_HL_MAXMODE IP6T_HL_DEC
1791 +struct ip6t_HL_info {
1793 + u_int8_t hop_limit;
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
1802 #define _IP6T_REJECT_H
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,
1819 struct ip6t_reject_info {
1820 enum ip6t_reject_with with; /* reject type */
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
1829 +/* Header file for iptables ip6t_ROUTE target
1831 + * (C) 2003 by Cédric de Launois <delaunois@info.ucl.ac.be>
1833 + * This software is distributed under GNU GPL v2, 1991
1835 +#ifndef _IPT_ROUTE_H_target
1836 +#define _IPT_ROUTE_H_target
1838 +#define IP6T_ROUTE_IFNAMSIZ 16
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 */
1847 +/* Values for "flags" field */
1848 +#define IP6T_ROUTE_CONTINUE 0x01
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
1855 +#ifndef _IP6T_FUZZY_H
1856 +#define _IP6T_FUZZY_H
1858 +#include <linux/param.h>
1859 +#include <linux/types.h>
1861 +#define MAXFUZZYRATE 10000000
1862 +#define MINFUZZYRATE 3
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;
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
1880 +#ifndef _IP6T_NTH_H
1881 +#define _IP6T_NTH_H
1883 +#include <linux/param.h>
1884 +#include <linux/types.h>
1886 +#ifndef IP6T_NTH_NUM_COUNTERS
1887 +#define IP6T_NTH_NUM_COUNTERS 16
1890 +struct ip6t_nth_info {
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
1903 #define IP6T_OWNER_GID 0x02
1904 #define IP6T_OWNER_PID 0x04
1905 #define IP6T_OWNER_SID 0x08
1906 +#define IP6T_OWNER_COMM 0x10
1908 struct ip6t_owner_info {
1914 u_int8_t match, invert; /* flags */
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
1921 +#ifndef _IP6T_POLICY_H
1922 +#define _IP6T_POLICY_H
1924 +#define POLICY_MAX_ELEM 4
1926 +enum ip6t_policy_flags
1928 + POLICY_MATCH_IN = 0x1,
1929 + POLICY_MATCH_OUT = 0x2,
1930 + POLICY_MATCH_NONE = 0x4,
1931 + POLICY_MATCH_STRICT = 0x8,
1934 +enum ip6t_policy_modes
1936 + POLICY_MODE_TRANSPORT,
1937 + POLICY_MODE_TUNNEL
1940 +struct ip6t_policy_spec
1950 +struct ip6t_policy_elem
1952 + struct in6_addr saddr;
1953 + struct in6_addr smask;
1954 + struct in6_addr daddr;
1955 + struct in6_addr dmask;
1961 + struct ip6t_policy_spec match;
1962 + struct ip6t_policy_spec invert;
1965 +struct ip6t_policy_info
1967 + struct ip6t_policy_elem pol[POLICY_MAX_ELEM];
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
1977 +#ifndef _IP6T_RAND_H
1978 +#define _IP6T_RAND_H
1980 +#include <linux/param.h>
1981 +#include <linux/types.h>
1983 +struct ip6t_rand_info {
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
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.
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()
2001 +#ifndef _NETFILTER_MIME_H
2002 +#define _NETFILTER_MIME_H
2004 +/* Only include these functions for kernel code. */
2007 +#include <linux/ctype.h>
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).
2014 + * 'line' in this context means logical line (includes LWS continuations).
2015 + * Returns 1 on success, 0 on failure.
2017 +#ifdef NF_NEED_MIME_NEXTLINE
2019 +nf_mime_nextline(char* p, uint len, uint* poff, uint* plineoff, uint* plinelen)
2023 + int is_first_line = 1;
2032 + while (p[off] != '\n')
2043 + /* if we saw a crlf, physlen needs adjusted */
2044 + if (physlen > 0 && p[off] == '\n' && p[off-1] == '\r')
2049 + /* advance past the newline */
2052 + /* check for an empty line */
2058 + /* check for colon on the first physical line */
2059 + if (is_first_line)
2061 + is_first_line = 0;
2062 + if (memchr(p+(*poff), ':', physlen) == NULL)
2068 + while (p[off] == ' ' || p[off] == '\t');
2070 + *plineoff = *poff;
2071 + *plinelen = (physlen == 0) ? 0 : (off - *poff);
2076 +#endif /* NF_NEED_MIME_NEXTLINE */
2078 +#endif /* __KERNEL__ */
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 @@
2086 atomic_inc(&nfct->master->use);
2088 +static inline void nf_reset(struct sk_buff *skb)
2090 + nf_conntrack_put(skb->nfct);
2092 +#ifdef CONFIG_NETFILTER_DEBUG
2093 + skb->nf_debug = 0;
2097 #ifdef CONFIG_BRIDGE_NETFILTER
2098 static inline void nf_bridge_put(struct nf_bridge_info *nf_bridge)
2099 @@ -1061,9 +1069,10 @@
2101 atomic_inc(&nf_bridge->use);
2106 +#endif /* CONFIG_BRIDGE_NETFILTER */
2107 +#else /* CONFIG_NETFILTER */
2108 +static inline void nf_reset(struct sk_buff *skb) {}
2109 +#endif /* CONFIG_NETFILTER */
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
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>
2126 #define IPSKB_TRANSLATED 2
2127 #define IPSKB_FORWARDED 4
2128 #define IPSKB_XFRM_TUNNEL_SIZE 8
2129 +#define IPSKB_XFRM_TRANSFORMED 16
2133 @@ -212,6 +215,12 @@
2134 __ip_select_ident(iph, dst, more);
2137 +extern inline int ip_dst_output(struct sk_buff *skb)
2139 + return NF_HOOK_COND(PF_INET, NF_IP_POST_ROUTING, skb, NULL,
2140 + skb->dst->dev, dst_output, skb->dst->xfrm != NULL);
2144 * Map a multicast IP onto multicast MAC for type ethernet.
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
2150 int (*handler)(struct sk_buff *skb);
2151 void (*err_handler)(struct sk_buff *skb, u32 info);
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
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);
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
2172 extern int udp_ioctl(struct sock *sk, int cmd, unsigned long arg);
2173 extern int udp_disconnect(struct sock *sk, int flags);
2175 +extern struct sock *udp_v4_lookup(u32 saddr, u16 sport, u32 daddr, u16 dport, int dif);
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
2187 +#ifdef CONFIG_NETFILTER
2190 struct sec_decap_state x[XFRM_MAX_DEPTH];
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
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>
2204 /* In this code, we can be waiting indefinitely for userspace to
2206 #ifdef CONFIG_IP_ROUTE_FWMARK
2207 fl.nl_u.ip4_u.fwmark = (*pskb)->nfmark;
2209 - fl.proto = iph->protocol;
2210 if (ip_route_output_key(&rt, &fl) != 0)
2213 @@ -657,6 +658,20 @@
2214 if ((*pskb)->dst->error)
2218 + if (!(IPCB(*pskb)->flags & IPSKB_XFRM_TRANSFORMED)) {
2219 + struct xfrm_policy_afinfo *afinfo;
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)
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 @@
2239 +inline int nf_rcv_postxfrm_nonlocal(struct sk_buff *skb)
2241 + skb->sp->decap_done = 1;
2242 + dst_release(skb->dst);
2245 + return netif_rx(skb);
2248 +int nf_rcv_postxfrm_local(struct sk_buff *skb)
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);
2256 + return nf_rcv_postxfrm_nonlocal(skb);
2259 +#ifdef CONFIG_IP_NF_NAT_NEEDED
2260 +#include <linux/netfilter_ipv4/ip_conntrack.h>
2261 +#include <linux/netfilter_ipv4/ip_nat.h>
2263 +void nf_nat_decode_session4(struct sk_buff *skb, struct flowi *fl)
2265 + struct ip_conntrack *ct;
2266 + struct ip_conntrack_tuple *t;
2267 + struct ip_nat_info_manip *m;
2270 + if (skb->nfct == NULL)
2272 + ct = (struct ip_conntrack *)skb->nfct->master;
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;
2278 + switch (m->hooknum) {
2279 + case NF_IP_PRE_ROUTING:
2280 + if (m->maniptype != IP_NAT_MANIP_DST)
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;
2287 +#ifdef CONFIG_IP_NF_NAT_LOCAL
2288 + case NF_IP_LOCAL_IN:
2289 + if (m->maniptype != IP_NAT_MANIP_SRC)
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;
2300 +#endif /* CONFIG_IP_NF_NAT_NEEDED */
2303 int skb_ip_make_writable(struct sk_buff **pskb, unsigned int writable_len)
2305 struct sk_buff *nskb;
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
2315 err = -EHOSTUNREACH;
2318 + IPCB(*pskb)->flags |= IPSKB_XFRM_TRANSFORMED;
2319 return NET_XMIT_BYPASS;
2323 .handler = xfrm4_rcv,
2324 .err_handler = ah4_err,
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
2334 err = -EHOSTUNREACH;
2337 + IPCB(*pskb)->flags |= IPSKB_XFRM_TRANSFORMED;
2338 return NET_XMIT_BYPASS;
2342 .handler = xfrm4_rcv,
2343 .err_handler = esp4_err,
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
2353 pig->csum = ip_compute_csum((void *)skb->h.igmph, igmplen);
2355 return NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, skb, NULL, skb->dev,
2360 static int grec_size(struct ip_mc_list *pmc, int type, int gdel, int sdel)
2362 ih->csum=ip_compute_csum((void *)ih, sizeof(struct igmphdr));
2364 return NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, skb, NULL, rt->u.dst.dev,
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
2374 if (unlikely(opt->optlen))
2375 ip_forward_options(skb);
2377 - return dst_output(skb);
2378 + return ip_dst_output(skb);
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);
2389 -#ifdef CONFIG_NETFILTER
2390 - nf_conntrack_put(skb->nfct);
2392 -#ifdef CONFIG_NETFILTER_DEBUG
2393 - skb->nf_debug = 0;
2397 ipgre_ecn_decapsulate(iph, skb);
2399 read_unlock(&ipgre_lock);
2400 @@ -877,13 +871,7 @@
2404 -#ifdef CONFIG_NETFILTER
2405 - nf_conntrack_put(skb->nfct);
2407 -#ifdef CONFIG_NETFILTER_DEBUG
2408 - skb->nf_debug = 0;
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 @@
2420 #ifdef CONFIG_NETFILTER_DEBUG
2421 nf_debug_ip_local_deliver(skb);
2422 - skb->nf_debug = 0;
2423 #endif /*CONFIG_NETFILTER_DEBUG*/
2425 __skb_pull(skb, ihl);
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);
2432 -#endif /*CONFIG_NETFILTER*/
2434 /* Point into the IP datagram, just past the header. */
2435 skb->h.raw = skb->data;
2437 @@ -228,6 +220,13 @@
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();
2444 + if (nf_xfrm_local_done(skb, ipprot)) {
2445 + nf_rcv_postxfrm_local(skb);
2449 /* If there maybe a raw socket we must check - if not we
2451 @@ -235,14 +234,15 @@
2453 raw_v4_input(skb, skb->nh.iph, hash);
2455 - if ((ipprot = inet_protos[hash]) != NULL) {
2456 + if (ipprot != NULL) {
2459 - smp_read_barrier_depends();
2460 - if (!ipprot->no_policy &&
2461 - !xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb)) {
2464 + if (!ipprot->no_policy) {
2465 + if (!xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb)) {
2471 ret = ipprot->handler(skb);
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));
2483 static inline int ip_rcv_finish(struct sk_buff *skb)
2488 + if (nf_xfrm_nonlocal_done(skb))
2489 + return nf_rcv_postxfrm_nonlocal(skb);
2491 #ifdef CONFIG_NET_CLS_ROUTE
2492 if (skb->dst->tclassid) {
2493 struct ip_rt_acct *st = ip_rt_acct + 256*smp_processor_id();
2498 - return NF_HOOK(PF_INET, NF_IP_PRE_ROUTING, skb, dev, NULL,
2500 + return NF_HOOK_COND(PF_INET, NF_IP_PRE_ROUTING, skb, dev, NULL,
2501 + ip_rcv_finish, nf_hook_input_cond(skb));
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 @@
2512 +#ifdef CONFIG_NETFILTER
2513 +/* out-of-line copy is only required with netfilter */
2514 +int ip_dst_output(struct sk_buff *skb)
2516 + return NF_HOOK_COND(PF_INET, NF_IP_POST_ROUTING, skb, NULL,
2517 + skb->dst->dev, dst_output, skb->dst->xfrm != NULL);
2522 * Add an ip header to a skbuff and send it out.
2527 return NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, skb, NULL, rt->u.dst.dev,
2532 static inline int ip_finish_output2(struct sk_buff *skb)
2533 @@ -284,10 +294,8 @@
2534 return ip_finish_output(skb);
2537 -int ip_output(struct sk_buff **pskb)
2538 +static inline int ip_output2(struct sk_buff *skb)
2540 - struct sk_buff *skb = *pskb;
2542 IP_INC_STATS(OutRequests);
2544 if ((skb->len > dst_pmtu(skb->dst) || skb_shinfo(skb)->frag_list) &&
2545 @@ -297,6 +305,18 @@
2546 return ip_finish_output(skb);
2549 +int ip_output(struct sk_buff **pskb)
2551 + struct sk_buff *skb = *pskb;
2553 + int transformed = IPCB(skb)->flags & IPSKB_XFRM_TRANSFORMED;
2557 + return NF_HOOK_COND(PF_INET, NF_IP_LOCAL_OUT, skb, NULL,
2558 + skb->dst->dev, ip_output2, transformed);
2561 int ip_queue_xmit(struct sk_buff *skb, int ipfragok)
2563 struct sock *sk = skb->sk;
2565 skb->priority = sk->sk_priority;
2567 return NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, skb, NULL, rt->u.dst.dev,
2572 IP_INC_STATS(OutNoRoutes);
2573 @@ -1180,7 +1206,7 @@
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);
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
2586 err = -EHOSTUNREACH;
2589 + IPCB(*pskb)->flags |= IPSKB_XFRM_TRANSFORMED;
2590 err = NET_XMIT_BYPASS;
2594 .handler = xfrm4_rcv,
2595 .err_handler = ipcomp4_err,
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 @@
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);
2613 if (!xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb)) {
2614 read_unlock(&ipip_lock);
2616 @@ -497,13 +502,7 @@
2617 skb->dev = tunnel->dev;
2618 dst_release(skb->dst);
2620 -#ifdef CONFIG_NETFILTER
2621 - nf_conntrack_put(skb->nfct);
2623 -#ifdef CONFIG_NETFILTER_DEBUG
2624 - skb->nf_debug = 0;
2628 ipip_ecn_decapsulate(iph, skb);
2630 read_unlock(&ipip_lock);
2631 @@ -648,13 +647,7 @@
2632 if ((iph->ttl = tiph->ttl) == 0)
2633 iph->ttl = old_iph->ttl;
2635 -#ifdef CONFIG_NETFILTER
2636 - nf_conntrack_put(skb->nfct);
2638 -#ifdef CONFIG_NETFILTER_DEBUG
2639 - skb->nf_debug = 0;
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;
2652 memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt));
2653 -#ifdef CONFIG_NETFILTER
2654 - nf_conntrack_put(skb->nfct);
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);
2665 - return dst_output(skb);
2666 + return ip_dst_output(skb);
2670 @@ -1461,10 +1458,7 @@
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);
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++;
2686 -#ifdef CONFIG_NETFILTER
2687 - nf_conntrack_put(skb->nfct);
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 @@
2699 To compile it as a module, choose M here. If unsure, say N.
2701 +config IP_NF_MATCH_UNCLEAN
2702 + tristate 'unclean match support (EXPERIMENTAL)'
2703 + depends on EXPERIMENTAL && IP_NF_IPTABLES
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'.
2713 +config IP_NF_TARGET_IPV4OPTSSTRIP
2714 + tristate 'IPV4OPTSSTRIP target support'
2715 + depends on IP_NF_MANGLE
2717 + This option adds an IPV4OPTSSTRIP target.
2718 + This target allows you to strip all IP options in a packet.
2720 + If you want to compile it as a module, say M here and read
2721 + Documentation/modules.txt. If unsure, say `N'.
2723 +config IP_NF_TARGET_NETLINK
2724 + tristate 'NETLINK target support'
2725 + depends on IP_NF_FILTER
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.
2733 +config IP_NF_TARGET_TTL
2734 + tristate 'TTL target support'
2735 + depends on IP_NF_MANGLE
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
2741 + If you want to compile it as a module, say M here and read
2742 + Documentation/modules.txt. If unsure, say `N'.
2744 +config IP_NF_MATCH_CONNLIMIT
2745 + tristate 'Connections/IP limit match support'
2746 + depends on IP_NF_IPTABLES
2748 + This match allows you to restrict the number of parallel TCP
2749 + connections to a server per client IP address (or address block).
2751 + If you want to compile it as a module, say M here and read
2752 + Documentation/modules.txt. If unsure, say `N'.
2754 +config IP_NF_MATCH_DSTLIMIT
2755 + tristate 'dstlimit match support'
2756 + depends on IP_NF_IPTABLES
2758 +config IP_NF_MATCH_FUZZY
2759 + tristate 'fuzzy match support'
2760 + depends on IP_NF_IPTABLES
2762 + This option adds a `fuzzy' match, which allows you to match
2763 + packets according to a fuzzy logic based law.
2765 + If you want to compile it as a module, say M here and read
2766 + Documentation/modules.txt. If unsure, say `N'.
2768 +config IP_NF_MATCH_IPV4OPTIONS
2769 + tristate 'IPV4OPTIONS match support'
2770 + depends on IP_NF_IPTABLES
2772 + This option adds a IPV4OPTIONS match.
2773 + It allows you to filter options like source routing,
2774 + record route, timestamp and router-altert.
2776 + If you say Y here, try iptables -m ipv4options --help for more information.
2778 + If you want to compile it as a module, say M here and read
2779 + Documentation/modules.txt. If unsure, say `N'.
2781 +config IP_NF_MATCH_MPORT
2782 + tristate 'Multiple port with ranges match support'
2783 + depends on IP_NF_IPTABLES
2785 + This is an enhanced multiport match which supports port
2786 + ranges as well as single ports.
2788 + If you want to compile it as a module, say M here and read
2789 + Documentation/modules.txt. If unsure, say `N'.
2791 +config IP_NF_MATCH_NTH
2792 + tristate 'Nth match support'
2793 + depends on IP_NF_IPTABLES
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.
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
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.
2812 + If you want to compile it as a module, say M here and read
2813 + Documentation/modules.txt. If unsure, say `N'.
2815 +config IP_NF_MATCH_OSF
2816 + tristate 'OSF match support'
2817 + depends on IP_NF_IPTABLES
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.
2825 + Original table was created by Michal Zalewski <lcamtuf@coredump.cx> for
2826 + his excellent p0f and than changed a bit for more convenience.
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.
2832 + If you say Y here, try iptables -m osf --help for more information.
2834 + If you want to compile it as a module, say M here and read
2835 + Documentation/modules.txt. If unsure, say `N'.
2837 +config IP_POOL_STATISTICS
2838 + bool 'enable statistics on pool usage'
2839 + depends on IP_NF_POOL!=n
2841 + This option controls whether usage gathering code is compiled into the
2842 + ip_pool module. Disabling statistics may be substantially faster.
2845 + tristate 'IP address pool support'
2846 + depends on IP_NF_IPTABLES
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.
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.
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/.
2861 + If you want to compile it as a module, say M here and read
2862 + Documentation/modules.txt. If unsure, say `N'.
2864 +config IP_NF_MATCH_PSD
2865 + tristate 'psd match support'
2866 + depends on IP_NF_IPTABLES
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.
2871 + If you want to compile it as a module, say M here and read
2872 + Documentation/modules.txt. If unsure, say `N'.
2874 +config IP_NF_MATCH_QUOTA
2875 + tristate 'quota match support'
2876 + depends on IP_NF_IPTABLES
2878 + This match implements network quotas.
2880 + If you want to compile it as a module, say M here and read
2881 + Documentation/modules.txt. If unsure, say `N'.
2884 +config IP_NF_MATCH_RANDOM
2885 + tristate 'random match support'
2886 + depends on IP_NF_IPTABLES
2888 + This option adds a `random' match,
2889 + which allow you to match packets randomly
2890 + following a given probability.
2892 + If you want to compile it as a module, say M here and read
2893 + Documentation/modules.txt. If unsure, say `N'.
2895 +config IP_NF_MATCH_REALM
2896 + tristate 'realm match support'
2897 + depends on IP_NF_IPTABLES && NET_CLS_ROUTE
2899 + This option adds a `realm' match, which allows you to use the realm
2900 + key from the routing subsytem inside iptables.
2902 + This match pretty much resembles the CONFIG_NET_CLS_ROUTE4 option
2905 + If you want to compile it as a module, say M here and read
2906 + Documentation/modules.txt. If unsure, say `N'.
2908 +config IP_NF_MATCH_SCTP
2909 + tristate 'SCTP protocol match support'
2910 + depends on IP_NF_IPTABLES
2912 +config IP_NF_MATCH_TIME
2913 + tristate 'TIME match support'
2914 + depends on IP_NF_IPTABLES
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).
2921 + If you say Y here, try iptables -m time --help for more information.
2923 + If you want to compile it as a module, say M here and read
2924 + Documentation/modules.txt. If unsure, say `N'.
2926 +config IP_NF_MATCH_U32
2927 + tristate 'U32 match support'
2928 + depends on IP_NF_IPTABLES
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
2937 + Details and examples are in the kernel module source.
2939 +config IP_NF_CONNTRACK_MARK
2940 + bool 'Connection mark tracking support'
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.
2947 +config IP_NF_TARGET_CONNMARK
2948 + tristate 'CONNMARK target support'
2949 + depends on IP_NF_CONNTRACK_MARK && IP_NF_MANGLE
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.
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'.
2959 +config IP_NF_MATCH_CONNMARK
2960 + tristate ' Connection mark match support'
2961 + depends on IP_NF_CONNTRACK_MARK && IP_NF_IPTABLES
2963 + This option adds a `connmark' match, which allows you to match the
2964 + connection mark value previously set for the session by `CONNMARK'.
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'.
2970 +config IP_NF_TARGET_IPMARK
2971 + tristate 'IPMARK target support'
2972 + depends on IP_NF_MANGLE
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.
2979 + If you want to compile it as a module, say M here and read
2980 + <file:Documentation/modules.txt>. If unsure, say `N'.
2982 +config IP_NF_TARGET_ROUTE
2983 + tristate 'ROUTE target support'
2984 + depends on IP_NF_MANGLE
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.
2992 + The target can be or not a final target. It has to be used inside the
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'.
2999 +config IP_NF_TARGET_TARPIT
3000 + tristate 'TARPIT target support'
3001 + depends on IP_NF_FILTER
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.
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.
3016 +config IP_NF_TARGET_TRACE
3017 + tristate 'TRACE target support'
3018 + depends on IP_NF_RAW
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
3024 + TRACE: tablename/chainname/rulenum
3026 + If you want to compile it as a module, say M here and read
3027 + <file:Documentation/modules.txt>. If unsure, say `N'.
3029 +config IP_NF_TARGET_XOR
3030 + tristate 'XOR target support'
3031 + depends on IP_NF_MANGLE
3033 + This option adds a `XOR' target, which can encrypt TCP and
3034 + UDP traffic using a simple XOR encryption.
3036 + If you want to compile it as a module, say M here and read
3037 + Documentation/modules.txt. If unsure, say `N'.
3039 +config IP_NF_MATCH_ADDRTYPE
3040 + tristate 'address type match support'
3041 + depends on IP_NF_IPTABLES
3043 + This option allows you to match what routing thinks of an address,
3044 + eg. UNICAST, LOCAL, BROADCAST, ...
3046 + If you want to compile it as a module, say M here and read
3047 + Documentation/modules.txt. If unsure, say `N'.
3050 + tristate 'Eggdrop bot support'
3051 + depends on IP_NF_CONNTRACK
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.
3057 + If you want to compile it as a module, say M here and read
3058 + Documentation/modules.txt. If unsure, say `N'.
3060 +config IP_NF_NAT_H323
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
3067 + tristate 'H.323 (netmeeting) support'
3068 + depends on IP_NF_CONNTRACK
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.
3075 + If you want to compile it as a module, say 'M' here and read
3076 + Documentation/modules.txt. If unsure, say 'N'.
3078 +config IP_NF_NAT_MMS
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
3085 + tristate 'MMS protocol support'
3086 + depends on IP_NF_CONNTRACK
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.
3093 + If you want to compile it as a module, say M here and read
3094 + <file:Documentation/modules.txt>. If unsure, say `Y'.
3096 +config IP_NF_NAT_QUAKE3
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
3102 +config IP_NF_QUAKE3
3103 + tristate "Quake3 protocol support"
3104 + depends on IP_NF_CONNTRACK
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.
3111 + If you want to compile it as a module, say M here and read
3112 + <file:Documentation/modules.txt>. If unsure, say `Y'.
3115 + tristate 'RSH protocol support'
3116 + depends on IP_NF_CONNTRACK
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;
3122 + Client 0:1023 --> Server 514 (stream 1 - stdin/stdout)
3123 + Client 0:1023 <-- Server 0:1023 (stream 2 - stderr)
3125 + This connection tracker will identify new RSH sessions,
3126 + extract the outbound session details, and notify netfilter
3127 + of pending "related" sessions.
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)
3134 + If you want to compile it as a module, say M here and read
3135 + <file:Documentation/modules.txt>. If unsure, say `N'.
3137 +config IP_NF_NAT_RTSP
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
3144 + tristate ' RTSP protocol support'
3145 + depends on IP_NF_CONNTRACK
3147 + Support the RTSP protocol. This allows UDP transports to be setup
3148 + properly, including RTP and RDT.
3150 + If you want to compile it as a module, say 'M' here and read
3151 + Documentation/modules.txt. If unsure, say 'Y'.
3153 +config IP_NF_CT_PROTO_SCTP
3154 + tristate 'SCTP protocol connection tracking support'
3155 + depends on IP_NF_CONNTRACK
3157 +config IP_NF_MATCH_STRING
3158 + tristate 'String match support'
3159 + depends on IP_NF_IPTABLES
3161 + String matching alows you to match packets which contain a
3162 + specified string of characters.
3164 + If you want to compile it as a module, say M here and read
3165 + Documentation/modules.txt. If unsure, say `N'.
3167 +config IP_NF_NAT_TALK
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
3174 + tristate 'talk protocol support'
3175 + depends on IP_NF_CONNTRACK
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.
3187 + If you want to compile it as a module, say 'M' here and read
3188 + Documentation/modules.txt. If unsure, say 'N'.
3190 +config IP_NF_MATCH_POLICY
3191 + tristate "IPsec policy match support"
3192 + depends on IP_NF_IPTABLES && XFRM
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.
3198 + To compile it as a module, choose M here. If unsure, say N.
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
3206 # connection tracking
3207 obj-$(CONFIG_IP_NF_CONNTRACK) += ip_conntrack.o
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
3214 +# SCTP protocol connection tracking
3215 +obj-$(CONFIG_IP_NF_CT_PROTO_SCTP) += ip_conntrack_proto_sctp.o
3218 +obj-$(CONFIG_IP_NF_H323) += ip_conntrack_h323.o
3219 +obj-$(CONFIG_IP_NF_NAT_H323) += ip_nat_h323.o
3222 # connection tracking helpers
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
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
3235 +obj-$(CONFIG_IP_NF_EGG) += ip_conntrack_egg.o
3237 obj-$(CONFIG_IP_NF_IRC) += ip_conntrack_irc.o
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
3248 obj-$(CONFIG_IP_NF_IPTABLES) += ip_tables.o
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
3261 obj-$(CONFIG_IP_NF_MATCH_PKTTYPE) += ipt_pkttype.o
3262 obj-$(CONFIG_IP_NF_MATCH_MULTIPORT) += ipt_multiport.o
3264 +obj-$(CONFIG_IP_NF_MATCH_MPORT) += ipt_mport.o
3266 obj-$(CONFIG_IP_NF_MATCH_OWNER) += ipt_owner.o
3267 obj-$(CONFIG_IP_NF_MATCH_TOS) += ipt_tos.o
3269 +obj-$(CONFIG_IP_NF_MATCH_TIME) += ipt_time.o
3272 +obj-$(CONFIG_IP_NF_MATCH_RANDOM) += ipt_random.o
3274 +obj-$(CONFIG_IP_NF_MATCH_PSD) += ipt_psd.o
3276 +obj-$(CONFIG_IP_NF_MATCH_OSF) += ipt_osf.o
3279 +obj-$(CONFIG_IP_NF_MATCH_NTH) += ipt_nth.o
3281 +obj-$(CONFIG_IP_NF_MATCH_IPV4OPTIONS) += ipt_ipv4options.o
3284 +obj-$(CONFIG_IP_NF_MATCH_FUZZY) += ipt_fuzzy.o
3286 obj-$(CONFIG_IP_NF_MATCH_RECENT) += ipt_recent.o
3288 obj-$(CONFIG_IP_NF_MATCH_ECN) += ipt_ecn.o
3289 @@ -60,28 +125,47 @@
3291 obj-$(CONFIG_IP_NF_MATCH_LENGTH) += ipt_length.o
3293 +obj-$(CONFIG_IP_NF_MATCH_U32) += ipt_u32.o
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
3307 obj-$(CONFIG_IP_NF_MATCH_PHYSDEV) += ipt_physdev.o
3308 +obj-$(CONFIG_IP_NF_MATCH_POLICY) += ipt_policy.o
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
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
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;
3347 extern struct ip_conntrack_protocol ip_conntrack_generic_protocol;
3349 IP_NF_ASSERT(atomic_read(&exp->use));
3350 IP_NF_ASSERT(!timer_pending(&exp->timeout));
3353 + kmem_cache_free(ip_conntrack_expect_cachep, exp);
3358 list_del(&ct->master->expected_list);
3359 master = ct->master->expectant;
3361 - kfree(ct->master);
3362 + kmem_cache_free(ip_conntrack_expect_cachep, ct->master);
3364 WRITE_UNLOCK(&ip_conntrack_lock);
3366 @@ -692,25 +694,22 @@
3367 struct ip_conntrack_expect *, tuple);
3368 READ_UNLOCK(&ip_conntrack_expect_tuple_lock);
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))
3378 - /* Look up the conntrack helper for master connections only */
3380 - conntrack->helper = ip_ct_find_helper(&repl_tuple);
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);
3392 - /* If the expectation is dying, then this is a loser. */
3394 - && expected->expectant->helper->timeout
3395 - && ! del_timer(&expected->timeout))
3397 + /* Expectation is dying... */
3398 + if (expected->expectant->helper->timeout
3399 + && !del_timer(&expected->timeout))
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;
3413 LIST_DELETE(&ip_conntrack_expect_list, expected);
3414 expected->expectant->expecting--;
3415 nf_conntrack_get(&master_ct(conntrack)->infos[0]);
3417 - atomic_inc(&ip_conntrack_count);
3419 + /* this is a braindead... --pablo */
3420 + atomic_inc(&ip_conntrack_count);
3421 + WRITE_UNLOCK(&ip_conntrack_lock);
3423 + if (expected->expectfn)
3424 + expected->expectfn(conntrack);
3428 + conntrack->helper = ip_ct_find_helper(&repl_tuple);
3430 +end: atomic_inc(&ip_conntrack_count);
3431 WRITE_UNLOCK(&ip_conntrack_lock);
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];
3439 /* On success, returns conntrack ptr, sets skb->nfct and ctinfo */
3441 ip_conntrack_expect_alloc(void)
3443 struct ip_conntrack_expect *new;
3445 - new = (struct ip_conntrack_expect *)
3446 - kmalloc(sizeof(struct ip_conntrack_expect), GFP_ATOMIC);
3448 + new = kmem_cache_alloc(ip_conntrack_expect_cachep, GFP_ATOMIC);
3450 DEBUGP("expect_related: OOM allocating expect\n");
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);
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);
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 */
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 @@
3477 WRITE_UNLOCK(&ip_conntrack_lock);
3479 + /* This expectation is not inserted so no need to lock */
3480 + kmem_cache_free(ip_conntrack_expect_cachep, expect);
3483 } else if (related_to->helper->max_expected &&
3484 related_to->expecting >= related_to->helper->max_expected) {
3485 - struct list_head *cur_item;
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));
3494 + kmem_cache_free(ip_conntrack_expect_cachep, expect);
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));
3501 /* choose the the oldest expectation to evict */
3502 - list_for_each(cur_item, &related_to->sibling_list) {
3503 - struct ip_conntrack_expect *cur;
3505 - cur = list_entry(cur_item,
3506 - struct ip_conntrack_expect,
3508 - if (cur->sibling == NULL) {
3510 + list_for_each_entry(old, &related_to->sibling_list,
3512 + if (old->sibling == NULL)
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);
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");
3531 + kmem_cache_free(ip_conntrack_expect_cachep, expect);
3535 @@ -1379,6 +1379,7 @@
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);
3543 @@ -1431,6 +1432,15 @@
3544 printk(KERN_ERR "Unable to create ip_conntrack slab cache\n");
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;
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 @@
3563 +err_free_conntrack_slab:
3564 + kmem_cache_destroy(ip_conntrack_cachep);
3566 vfree(ip_conntrack_hash);
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
3572 +/* Eggdrop extension for IP connection tracking, Version 0.0.5
3573 + * based on ip_conntrack_irc.c
3575 + * This module only supports the share userfile-send command,
3576 + * used by eggdrops to share it's userfile.
3578 + * There are no support for NAT at the moment.
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.
3585 + * Module load syntax:
3587 + * please give the ports of all Eggdrops You have running
3588 + * on your system, the default port is 3333.
3590 + * 2001-04-19: Security update. IP addresses are now compared
3591 + * to prevent unauthorized "related" access.
3593 + * 2002-03-25: Harald Welte <laforge@gnumonks.org>:
3594 + * Port to netfilter 'newnat' API.
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>
3603 +#include <linux/netfilter_ipv4/lockhelp.h>
3604 +#include <linux/netfilter_ipv4/ip_conntrack_helper.h>
3606 +#define MAX_PORTS 8
3607 +static int ports[MAX_PORTS];
3608 +static int ports_c = 0;
3609 +static unsigned int egg_timeout = 300;
3611 +MODULE_AUTHOR("Magnus Sandin <magnus@sandin.cx>");
3612 +MODULE_DESCRIPTION("Eggdrop (userfile-sharing) connection tracking module");
3613 +MODULE_LICENSE("GPL");
3615 +MODULE_PARM(ports, "1-" __MODULE_STRING(MAX_PORTS) "i");
3616 +MODULE_PARM_DESC(ports, "port numbers of eggdrop servers");
3619 +DECLARE_LOCK(ip_egg_lock);
3620 +struct module *ip_conntrack_egg = THIS_MODULE;
3623 +#define DEBUGP printk
3625 +#define DEBUGP(format, args...)
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 */
3636 + if (data > data_end)
3639 + *ip = simple_strtoul(data, &data, 10);
3641 + /* skip blanks between ip and port */
3642 + while (*data == ' ' && data < data_end)
3645 + *port = simple_strtoul(data, &data, 10);
3650 +static int help(const struct iphdr *iph, size_t len,
3651 + struct ip_conntrack *ct, enum ip_conntrack_info ctinfo)
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;
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;
3664 + u_int16_t egg_port;
3666 + DEBUGP("entered\n");
3668 + /* If packet is coming from IRC server */
3669 + if (dir != IP_CT_DIR_REPLY)
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);
3679 + /* Not whole TCP header? */
3680 + if (tcplen < sizeof(struct tcphdr) || tcplen < tcph->doff * 4) {
3681 + DEBUGP("tcplen = %u\n", (unsigned) tcplen);
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));
3695 + data_limit = (char *) data + datalen;
3696 + while (datalen > 5 && bytes_scanned < 128) {
3697 + if (memcmp(data, "s us ", 5)) {
3706 + DEBUGP("Userfile-share found in connection "
3707 + "%u.%u.%u.%u -> %u.%u.%u.%u\n",
3708 + NIPQUAD(iph->saddr), NIPQUAD(iph->daddr));
3710 + if (parse_command((char *) data, data_limit, &egg_ip,
3712 + DEBUGP("no data in userfile-share pkt\n");
3716 + memset(&exp, 0, sizeof(exp));
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);
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;
3733 + exp.mask.dst.u.tcp.port = 0xffff;
3734 + exp.mask.dst.protonum = 0xffff;
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));
3740 + ip_conntrack_expect_related(&exp, ct);
3746 +static struct ip_conntrack_helper egg_helpers[MAX_PORTS];
3747 +static char egg_names[MAX_PORTS][14]; /* eggdrop-65535 */
3749 +static void deregister_helpers(void) {
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]);
3758 +static int __init init(void)
3763 + /* If no port given, default to standard eggdrop port */
3764 + if (ports[0] == 0)
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;
3780 + tmpname = &egg_names[i][0];
3781 + if (ports[i] == 3333)
3782 + sprintf(tmpname, "eggdrop");
3784 + sprintf(tmpname, "eggdrop-%d", ports[i]);
3785 + egg_helpers[i].name = tmpname;
3787 + DEBUGP("port #%d: %d\n", i, ports[i]);
3789 + ret = ip_conntrack_helper_register(&egg_helpers[i]);
3792 + printk("ip_conntrack_egg: ERROR registering helper "
3793 + "for port %d\n", ports[i]);
3794 + deregister_helpers();
3802 +static void __exit fini(void)
3804 + deregister_helpers();
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
3814 + * H.323 'brute force' extension for H.323 connection tracking.
3815 + * Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
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.
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>
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>
3837 +MODULE_AUTHOR("Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>");
3838 +MODULE_DESCRIPTION("H.323 'brute force' connection tracking module");
3839 +MODULE_LICENSE("GPL");
3841 +DECLARE_LOCK(ip_h323_lock);
3842 +struct module *ip_conntrack_h323 = THIS_MODULE;
3845 +#define DEBUGP printk
3847 +#define DEBUGP(format, args...)
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)
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;
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));
3872 + /* Can't track connections formed before we registered */
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);
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);
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));
3899 + data_limit = (unsigned char *) data + datalen;
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;
3917 + exp->seq = ntohl(tcph->seq) + i;
3919 + exp->tuple = ((struct ip_conntrack_tuple)
3920 + { { ct->tuplehash[!dir].tuple.src.ip,
3923 + { .tcp = { data_port } },
3925 + exp->mask = ((struct ip_conntrack_tuple)
3926 + { { 0xFFFFFFFF, { 0 } },
3927 + { 0xFFFFFFFF, { .tcp = { 0xFFFF } }, 0xFFFF }});
3929 + exp->expectfn = NULL;
3931 + /* Ignore failure; should only happen with NAT */
3932 + ip_conntrack_expect_related(exp, ct);
3934 + UNLOCK_BH(&ip_h323_lock);
3942 +/* H.245 helper is not registered! */
3943 +static struct ip_conntrack_helper h245 =
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 */
3957 +static int h225_expect(struct ip_conntrack *ct)
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);
3964 + return NF_ACCEPT; /* unused */
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)
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;
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));
3989 + /* Can't track connections formed before we registered */
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);
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);
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));
4016 + data_limit = (unsigned char *) data + datalen;
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);
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);
4037 + memset(&expect, 0, sizeof(expect));
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;
4046 + exp->seq = ntohl(tcph->seq) + i;
4048 + exp->tuple = ((struct ip_conntrack_tuple)
4049 + { { ct->tuplehash[!dir].tuple.src.ip,
4052 + { .tcp = { data_port } },
4054 + exp->mask = ((struct ip_conntrack_tuple)
4055 + { { 0xFFFFFFFF, { 0 } },
4056 + { 0xFFFFFFFF, { .tcp = { 0xFFFF } }, 0xFFFF }});
4058 + exp->expectfn = h225_expect;
4060 + /* Ignore failure */
4061 + ip_conntrack_expect_related(exp, ct);
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));
4067 + UNLOCK_BH(&ip_h323_lock);
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);
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);
4092 +static struct ip_conntrack_helper h225 =
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 */
4106 +static int __init init(void)
4108 + return ip_conntrack_helper_register(&h225);
4111 +static void __exit fini(void)
4113 + /* Unregister H.225 helper */
4114 + ip_conntrack_helper_unregister(&h225);
4117 +EXPORT_SYMBOL(ip_h323_lock);
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
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
4129 + * ip_conntrack_mms.c v0.3 2002-09-22
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.
4136 + * Module load syntax:
4137 + * insmod ip_conntrack_mms.o ports=port1,port2,...port<MAX_PORTS>
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.
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
4146 + * The SDP project people are reverse-engineering MMS:
4147 + * http://get.to/sdp
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>
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>
4162 +DECLARE_LOCK(ip_mms_lock);
4163 +struct module *ip_conntrack_mms = THIS_MODULE;
4165 +#define MAX_PORTS 8
4166 +static int ports[MAX_PORTS];
4167 +static int ports_c;
4169 +MODULE_PARM(ports, "1-" __MODULE_STRING(MAX_PORTS) "i");
4173 +#define DEBUGP printk
4175 +#define DEBUGP(format, args...)
4178 +EXPORT_SYMBOL(ip_mms_lock);
4180 +MODULE_AUTHOR("Filip Sneppe <filip.sneppe@cronos.be>");
4181 +MODULE_DESCRIPTION("Microsoft Windows Media Services (MMS) connection tracking module");
4182 +MODULE_LICENSE("GPL");
4184 +/* #define isdigit(c) (c >= '0' && c <= '9') */
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)
4190 + for (i = 0; i < unicode_size; ++i) {
4191 + string[i] = (char)(unicode[i]);
4193 + string[unicode_size] = 0x00;
4196 +__inline static int atoi(char *s)
4199 + while (isdigit(*s)) {
4200 + i = i*10 + *(s++) - '0';
4205 +/* convert ip address string like "192.168.0.10" to unsigned int */
4206 +__inline static u_int32_t asciiiptoi(char *s)
4208 + unsigned int i, j, k;
4210 + for(i=k=0; k<3; ++k, ++s, i<<=8) {
4212 + for(j=0; (*(++s) != '.') && (j<3); ++j)
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)
4228 + int unicode_size, i;
4229 + char tempstring[28]; /* "\\255.255.255.255\UDP\65535" */
4230 + char getlengthstring[28];
4232 + for(unicode_size=0;
4233 + (char) *(data+(MMS_SRV_UNICODE_STRING_OFFSET+unicode_size*2)) != (char)0;
4235 + if ((unicode_size == 28) || (MMS_SRV_UNICODE_STRING_OFFSET+unicode_size*2 >= datalen))
4236 + return -1; /* out of bounds - incomplete packet */
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));
4241 + /* IP address ? */
4242 + *mms_ip = asciiiptoi(tempstring+2);
4244 + i=sprintf(getlengthstring, "%u.%u.%u.%u", HIPQUAD(*mms_ip));
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;
4253 + *mms_port = atoi(tempstring+7+i);
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 */
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)
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;
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;
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);
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);
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));
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...
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),
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");
4334 + memset(&expect, 0, sizeof(expect));
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),
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);
4350 + DEBUGP("ip_conntrack_mms: tcph->seq = %u\n", tcph->seq);
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;
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);
4360 + exp->tuple = ((struct ip_conntrack_tuple)
4361 + { { ct->tuplehash[!dir].tuple.src.ip, { 0 } },
4363 + { .tcp = { (__u16) ntohs(mms_port) } },
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);
4377 +static struct ip_conntrack_helper mms[MAX_PORTS];
4378 +static char mms_names[MAX_PORTS][10];
4380 +/* Not __exit: called from init() */
4381 +static void fini(void)
4384 + for (i = 0; (i < MAX_PORTS) && ports[i]; i++) {
4385 + DEBUGP("ip_conntrack_mms: unregistering helper for port %d\n",
4387 + ip_conntrack_helper_unregister(&mms[i]);
4391 +static int __init init(void)
4396 + if (ports[0] == 0)
4397 + ports[0] = MMS_PORT;
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;
4411 + tmpname = &mms_names[i][0];
4412 + if (ports[i] == MMS_PORT)
4413 + sprintf(tmpname, "mms");
4415 + sprintf(tmpname, "mms-%d", ports[i]);
4416 + mms[i].name = tmpname;
4418 + DEBUGP("ip_conntrack_mms: registering helper for port %d\n",
4420 + ret = ip_conntrack_helper_register(&mms[i]);
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
4438 + * Connection tracking protocol helper module for SCTP.
4440 + * SCTP is defined in RFC 2960. References to various sections in this code
4441 + * are to this RFC.
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.
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>
4458 +#include <linux/netfilter_ipv4/ip_conntrack.h>
4459 +#include <linux/netfilter_ipv4/ip_conntrack_protocol.h>
4460 +#include <linux/netfilter_ipv4/lockhelp.h>
4463 +#define DEBUGP(format, ...) printk(format, ## __VA_ARGS__)
4465 +#define DEBUGP(format, args...)
4468 +/* Protects conntrack->proto.sctp */
4469 +static DECLARE_RWLOCK(sctp_lock);
4471 +/* FIXME: Examine ipfilter's timeouts and conntrack transitions more
4472 + closely. They're more complex. --RR
4474 + And so for me for SCTP :D -Kiran */
4476 +static const char *sctp_conntrack_names[] = {
4484 + "SHUTDOWN_ACK_SENT",
4488 +#define MINS * 60 SECS
4489 +#define HOURS * 60 MINS
4490 +#define DAYS * 24 HOURS
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;
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 */
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
4522 + These are the descriptions of the states:
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
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.
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
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.
4552 +/* SCTP conntrack state transitions */
4553 +static enum sctp_conntrack sctp_conntracks[2][9][SCTP_CONNTRACK_MAX] = {
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}
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}
4582 +static int sctp_pkt_to_tuple(const struct sk_buff *skb,
4583 + unsigned int dataoff,
4584 + struct ip_conntrack_tuple *tuple)
4586 + sctp_sctphdr_t hdr;
4588 + DEBUGP(__FUNCTION__);
4591 + /* Actually only need first 8 bytes. */
4592 + if (skb_copy_bits(skb, dataoff, &hdr, 8) != 0)
4595 + tuple->src.u.sctp.port = hdr.source;
4596 + tuple->dst.u.sctp.port = hdr.dest;
4601 +static int sctp_invert_tuple(struct ip_conntrack_tuple *tuple,
4602 + const struct ip_conntrack_tuple *orig)
4604 + DEBUGP(__FUNCTION__);
4607 + tuple->src.u.sctp.port = orig->dst.u.sctp.port;
4608 + tuple->dst.u.sctp.port = orig->src.u.sctp.port;
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)
4616 + DEBUGP(__FUNCTION__);
4619 + return sprintf(buffer, "sport=%hu dport=%hu ",
4620 + ntohs(tuple->src.u.sctp.port),
4621 + ntohs(tuple->dst.u.sctp.port));
4624 +/* Print out the private part of the conntrack. */
4625 +static unsigned int sctp_print_conntrack(char *buffer,
4626 + const struct ip_conntrack *conntrack)
4628 + enum sctp_conntrack state;
4630 + DEBUGP(__FUNCTION__);
4633 + READ_LOCK(&sctp_lock);
4634 + state = conntrack->proto.sctp.state;
4635 + READ_UNLOCK(&sctp_lock);
4637 + return sprintf(buffer, "%s ", sctp_conntrack_names[state]);
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++)
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,
4650 + u_int32_t offset, count;
4651 + sctp_chunkhdr_t sch;
4654 + DEBUGP(__FUNCTION__);
4659 + for_each_sctp_chunk (skb, sch, offset, count) {
4660 + DEBUGP("Chunk Num: %d Type: %d\n", count, sch.type);
4662 + if (sch.type == SCTP_CID_INIT
4663 + || sch.type == SCTP_CID_INIT_ACK
4664 + || sch.type == SCTP_CID_SHUTDOWN_COMPLETE) {
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
4674 + DEBUGP("Basic checks failed\n");
4679 + set_bit (sch.type, (void *)map);
4683 + DEBUGP("Basic checks passed\n");
4687 +static int new_state(enum ip_conntrack_dir dir,
4688 + enum sctp_conntrack cur_state,
4693 + DEBUGP(__FUNCTION__);
4696 + DEBUGP("Chunk type: %d\n", chunk_type);
4698 + switch (chunk_type) {
4699 + case SCTP_CID_INIT:
4700 + DEBUGP("SCTP_CID_INIT\n");
4702 + case SCTP_CID_INIT_ACK:
4703 + DEBUGP("SCTP_CID_INIT_ACK\n");
4705 + case SCTP_CID_ABORT:
4706 + DEBUGP("SCTP_CID_ABORT\n");
4708 + case SCTP_CID_SHUTDOWN:
4709 + DEBUGP("SCTP_CID_SHUTDOWN\n");
4711 + case SCTP_CID_SHUTDOWN_ACK:
4712 + DEBUGP("SCTP_CID_SHUTDOWN_ACK\n");
4714 + case SCTP_CID_ERROR:
4715 + DEBUGP("SCTP_CID_ERROR\n");
4717 + case SCTP_CID_COOKIE_ECHO:
4718 + DEBUGP("SCTP_CID_COOKIE_ECHO\n");
4720 + case SCTP_CID_COOKIE_ACK:
4721 + DEBUGP("SCTP_CID_COOKIE_ACK\n");
4723 + case SCTP_CID_SHUTDOWN_COMPLETE:
4724 + DEBUGP("SCTP_CID_SHUTDOWN_COMPLETE\n");
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]);
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]]);
4738 + return sctp_conntracks[dir][i][cur_state];
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)
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};
4752 + DEBUGP(__FUNCTION__);
4755 + if (skb_copy_bits(skb, skb->nh.iph->ihl * 4, &sctph, sizeof(sctph)) != 0)
4758 + if (do_basic_checks(conntrack, skb, map) != 0)
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");
4772 + oldsctpstate = newconntrack = SCTP_CONNTRACK_MAX;
4773 + for_each_sctp_chunk (skb, sch, offset, count) {
4774 + WRITE_LOCK(&sctp_lock);
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);
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);
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);
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);
4808 + oldsctpstate = conntrack->proto.sctp.state;
4809 + newconntrack = new_state(CTINFO2DIR(ctinfo), oldsctpstate, sch.type);
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);
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;
4824 + if (skb_copy_bits(skb, offset + sizeof (sctp_chunkhdr_t),
4825 + &inithdr, sizeof(inithdr)) != 0) {
4826 + WRITE_UNLOCK(&sctp_lock);
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;
4834 + conntrack->proto.sctp.state = newconntrack;
4835 + WRITE_UNLOCK(&sctp_lock);
4838 + ip_ct_refresh(conntrack, *sctp_timeouts[newconntrack]);
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);
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)
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};
4860 + DEBUGP(__FUNCTION__);
4863 + if (skb_copy_bits(skb, skb->nh.iph->ihl * 4, &sctph, sizeof(sctph)) != 0)
4866 + if (do_basic_checks(conntrack, skb, map) != 0)
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))) {
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);
4882 + /* Invalid: delete conntrack */
4883 + if (newconntrack == SCTP_CONNTRACK_MAX) {
4884 + DEBUGP("ip_conntrack_sctp: invalid new deleting.\n");
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;
4893 + if (skb_copy_bits(skb, offset + sizeof (sctp_chunkhdr_t),
4894 + &inithdr, sizeof(inithdr)) != 0) {
4898 + DEBUGP("Setting vtag %x for new conn\n",
4899 + inithdr.init_tag);
4901 + conntrack->proto.sctp.vtag[IP_CT_DIR_REPLY] =
4904 + /* Sec 8.5.1 (A) */
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) */
4911 + DEBUGP("Setting vtag %x for new conn OOTB\n",
4913 + conntrack->proto.sctp.vtag[IP_CT_DIR_REPLY] = sctph.vtag;
4916 + conntrack->proto.sctp.state = newconntrack;
4922 +static int sctp_exp_matches_pkt(struct ip_conntrack_expect *exp,
4923 + const struct sk_buff *skb)
4925 + /* To be implemented */
4929 +struct ip_conntrack_protocol ip_conntrack_protocol_sctp = {
4930 + .list = { NULL, NULL },
4931 + .proto = IPPROTO_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,
4940 + .exp_matches_pkt = sctp_exp_matches_pkt,
4944 +int __init init(void)
4948 + ret = ip_conntrack_protocol_register(&ip_conntrack_protocol_sctp);
4949 + DEBUGP("SCTP conntrack module loading %s\n",
4950 + ret ? "failed": "succeeded");
4954 +void __exit fini(void)
4956 + ip_conntrack_protocol_unregister(&ip_conntrack_protocol_sctp);
4957 + DEBUGP("SCTP conntrack module unloaded\n");
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
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
4974 + * ip_conntrack_quake3.c v0.04 2002-08-31
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.
4981 + * Module load syntax:
4982 + * insmod ip_conntrack_quake3.o ports=port1,port2,...port<MAX_PORTS>
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
4988 + * Thanks to the Ethereal folks for their analysis of the Quake3 protocol.
4991 +#include <linux/module.h>
4992 +#include <linux/ip.h>
4993 +#include <linux/udp.h>
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>
5000 +struct module *ip_conntrack_quake3 = THIS_MODULE;
5002 +MODULE_AUTHOR("Filip Sneppe <filip.sneppe@cronos.be>");
5003 +MODULE_DESCRIPTION("Netfilter connection tracking module for Quake III Arena");
5004 +MODULE_LICENSE("GPL");
5006 +#define MAX_PORTS 8
5007 +static int ports[MAX_PORTS];
5008 +static int ports_c = 0;
5010 +MODULE_PARM(ports, "1-" __MODULE_STRING(MAX_PORTS) "i");
5011 +MODULE_PARM_DESC(ports, "port numbers of Quake III master servers");
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 */
5017 +#define DEBUGP printk
5019 +#define DEBUGP(format, args...)
5022 +struct quake3_search quake3s_conntrack = { "****", "getserversResponse", sizeof("getserversResponse") - 1 };
5024 +static int quake3_help(const struct iphdr *iph, size_t len,
5025 + struct ip_conntrack *ct,
5026 + enum ip_conntrack_info ctinfo)
5028 + struct udphdr *udph = (void *)iph + iph->ihl * 4;
5029 + int dir = CTINFO2DIR(ctinfo);
5030 + struct ip_conntrack_expect exp;
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);
5038 + } else { DEBUGP("ip_conntrack_quake3: it's ok ! Conntrackinfo = %u\n", ctinfo); }
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);
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 ) ) ) );
5049 + memset(&exp, 0, sizeof(exp));
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)) } },
5057 + exp.mask = ((struct ip_conntrack_tuple)
5058 + { { 0xFFFFFFFF, { 0 } },
5059 + { 0xFFFFFFFF, { .udp = { 0xFFFF } }, 0xFFFF }});
5060 + exp.expectfn = NULL;
5062 + ip_conntrack_expect_related(&exp, ct);
5067 + return(NF_ACCEPT);
5070 +static struct ip_conntrack_helper quake3[MAX_PORTS];
5071 +static char quake3_names[MAX_PORTS][13]; /* quake3-65535 */
5073 +static void fini(void)
5077 + for(i = 0 ; (i < ports_c); i++) {
5078 + DEBUGP("ip_conntrack_quake3: unregistering helper for port %d\n",
5080 + ip_conntrack_helper_unregister(&quake3[i]);
5084 +static int __init init(void)
5090 + ports[0]=QUAKE3_MASTER_PORT;
5092 + for(i = 0 ; (i < MAX_PORTS) && ports[i] ; i++) {
5093 + /* Create helper structure */
5094 + memset(&quake3[i], 0, sizeof(struct ip_conntrack_helper));
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;
5103 + tmpname = &quake3_names[i][0];
5104 + if (ports[i] == QUAKE3_MASTER_PORT)
5105 + sprintf(tmpname, "quake3");
5107 + sprintf(tmpname, "quake3-%d", i);
5108 + quake3[i].name = tmpname;
5110 + DEBUGP("ip_conntrack_quake3: registering helper for port %d\n",
5113 + ret=ip_conntrack_helper_register(&quake3[i]);
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
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
5134 + * ip_conntrack_rsh.c,v 1.0 2002/07/17 14:49:26
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.
5141 + * Module load syntax:
5142 + * insmod ip_conntrack_rsh.o ports=port1,port2,...port<MAX_PORTS>
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
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.
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
5159 + * I have no idea what "unix rshd man pages" these guys have .. but that
5160 + * is some pretty detailed docco!
5163 + * 4. Of the rsh protocol.
5164 + * -----------------------
5166 + * The rshd listens on TCP port #514. The following info is from the unix
5167 + * rshd man pages :
5169 + * "Service Request Protocol
5171 + * When the rshd daemon receives a service request, it initiates the
5172 + * following protocol:
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.
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.
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.
5190 + * 4. The rshd daemon retrieves the following information from the initial
5193 + * * A null-terminated string of at most 16 bytes interpreted as
5194 + * the user name of the user on the client host.
5196 + * * A null-terminated string of at most 16 bytes interpreted as
5197 + * the user name to be used on the local server host.
5199 + * * Another null-terminated string interpreted as a command line
5200 + * to be passed to a shell on the local server host.
5202 + * 5. The rshd daemon attempts to validate the user using the following steps:
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.
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.
5214 + * c. If the $HOME/.rhosts file exists, the rshd daemon tries to
5215 + * authenticate the user by checking the .rhosts file.
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.
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."
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>
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>
5240 +#define MAX_PORTS 8
5241 +static int ports[MAX_PORTS];
5242 +static int ports_n_c = 0;
5244 +MODULE_AUTHOR("Ian (Larry) Latter <Ian.Latter@mq.edu.au>");
5245 +MODULE_DESCRIPTION("RSH connection tracking module");
5246 +MODULE_LICENSE("GPL");
5248 +MODULE_PARM(ports, "1-" __MODULE_STRING(MAX_PORTS) "i");
5249 +MODULE_PARM_DESC(ports, "port numbers of RSH servers");
5252 +DECLARE_LOCK(ip_rsh_lock);
5253 +struct module *ip_conntrack_rsh = THIS_MODULE;
5256 +#define DEBUGP(format, args...) printk(KERN_DEBUG "ip_conntrack_rsh: " \
5259 +#define DEBUGP(format, args...)
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)
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;
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?
5284 + DEBUGP("entered\n");
5286 + /* bail if packet is not from RSH client */
5287 + if (dir == IP_CT_DIR_REPLY)
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);
5297 + /* Not whole TCP header? */
5298 + if (tcplen < sizeof(struct tcphdr) || tcplen < tcph->doff * 4) {
5299 + DEBUGP("tcplen = %u\n", (unsigned) tcplen);
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));
5313 + /* find the rsh stderr port */
5316 + for ( ; *data != 0 && maxoctet != 0; data++, maxoctet--) {
5321 + if (*data < 48 || *data > 57) {
5322 + DEBUGP("these aren't the packets you're looking for ..\n");
5325 + port = port * 10 + ( *data - 48 );
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");
5336 + LOCK_BH(&ip_rsh_lock);
5338 + /* new(,related) connection is;
5339 + * reply + dst (uint)port + src port (0:1023)
5341 + memset(&expect, 0, sizeof(expect));
5343 + /* save some discovered data, in case someone ever wants to write
5344 + * a NAT module for this bastard ..
5346 + exp_rsh_info->port = port;
5348 + DEBUGP("wrote info port=%u\n", exp_rsh_info->port);
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;
5358 + exp->mask.src.ip = 0xffffffff;
5359 + exp->mask.dst.ip = 0xffffffff;
5361 + exp->mask.src.u.tcp.port = htons(0xfc00);
5362 + exp->mask.dst.u.tcp.port = htons(0xfc00);
5363 + exp->mask.dst.protonum = 0xffff;
5365 + exp->expectfn = NULL;
5367 + ip_conntrack_expect_related(&expect, ct);
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));
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);
5385 +static struct ip_conntrack_helper rsh_helpers[MAX_PORTS];
5387 +static void fini(void);
5389 +static int __init init(void)
5392 + static char name[10];
5395 + /* If no port given, default to standard RSH port */
5396 + if (ports[0] == 0)
5397 + ports[0] = RSH_PORT;
5399 + for (port = 0; (port < MAX_PORTS) && ports[port]; port++) {
5400 + memset(&rsh_helpers[port], 0, sizeof(struct ip_conntrack_helper));
5402 + if (ports[port] == RSH_PORT)
5403 + sprintf(name, "rsh");
5405 + sprintf(name, "rsh-%d", port);
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;
5413 + rsh_helpers[port].tuple.dst.protonum = IPPROTO_TCP;
5414 + rsh_helpers[port].mask.dst.protonum = 0xffff;
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);
5421 + rsh_helpers[port].help = help;
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));
5435 + ret = ip_conntrack_helper_register(&rsh_helpers[port]);
5438 + printk("ERROR registering port %d\n",
5448 +/* This function is intentionally _NOT_ defined as __exit, because
5449 + * it is needed by the init function */
5450 +static void fini(void)
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]);
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
5466 + * RTSP extension for IP connection tracking
5467 + * (C) 2003 by Tom Marshall <tmarshall@real.com>
5468 + * based on ip_conntrack_irc.c
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.
5475 + * Module load syntax:
5476 + * insmod ip_conntrack_rtsp.o ports=port1,port2,...port<MAX_PORTS>
5477 + * max_outstanding=n setup_timeout=secs
5479 + * If no ports are specified, the default will be port 554.
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).
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>
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>
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>
5507 +#define MAX_SIMUL_SETUP 8 /* XXX: use max_outstanding */
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)
5513 +#define DEBUGP(fmt, args...)
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;
5522 +MODULE_AUTHOR("Tom Marshall <tmarshall@real.com>");
5523 +MODULE_DESCRIPTION("RTSP connection tracking module");
5524 +MODULE_LICENSE("GPL");
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");
5534 +DECLARE_LOCK(ip_rtsp_lock);
5535 +struct module* ip_conntrack_rtsp = THIS_MODULE;
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.
5543 +#define MAX_PORT_MAPS 16
5545 +/*** default port list was here in the masq code: 554, 3030, 4040 ***/
5547 +#define SKIP_WSPACE(ptr,len,off) while(off < len && isspace(*(ptr+off))) { off++; }
5550 + * Parse an RTSP packet.
5552 + * Returns zero if parsing failed.
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
5564 +rtsp_parse_message(char* ptcp, uint tcplen, uint* ptcpoff,
5565 + uint* phdrsoff, uint* phdrslen,
5566 + uint* pcseqoff, uint* pcseqlen)
5568 + uint entitylen = 0;
5572 + if (!nf_nextline(ptcp, tcplen, ptcpoff, &lineoff, &linelen))
5577 + *phdrsoff = *ptcpoff;
5578 + while (nf_mime_nextline(ptcp, tcplen, ptcpoff, &lineoff, &linelen))
5582 + if (entitylen > 0)
5584 + *ptcpoff += min(entitylen, tcplen - *ptcpoff);
5588 + if (lineoff+linelen > tcplen)
5590 + INFOP("!! overrun !!\n");
5594 + if (nf_strncasecmp(ptcp+lineoff, "CSeq:", 5) == 0)
5596 + *pcseqoff = lineoff;
5597 + *pcseqlen = linelen;
5599 + if (nf_strncasecmp(ptcp+lineoff, "Content-Length:", 15) == 0)
5601 + uint off = lineoff+15;
5602 + SKIP_WSPACE(ptcp+lineoff, linelen, off);
5603 + nf_strtou32(ptcp+off, &entitylen);
5606 + *phdrslen = (*ptcpoff) - (*phdrsoff);
5612 + * Find lo/hi client ports (if any) in transport header
5614 + * ptcp, tcplen = packet
5615 + * tranoff, tranlen = buffer to search
5618 + * pport_lo, pport_hi = lo/hi ports (host endian)
5620 + * Returns nonzero if any client ports found
5622 + * Note: it is valid (and expected) for the client to request multiple
5623 + * transports, so we need to parse the entire line.
5626 +rtsp_parse_transport(char* ptran, uint tranlen,
5627 + struct ip_ct_rtsp_expect* prtspexp)
5632 + if (tranlen < 10 || !iseol(ptran[tranlen-1]) ||
5633 + nf_strncasecmp(ptran, "Transport:", 10) != 0)
5635 + INFOP("sanity check failed\n");
5638 + DEBUGP("tran='%.*s'\n", (int)tranlen, ptran);
5640 + SKIP_WSPACE(ptran, tranlen, off);
5642 + /* Transport: tran;field;field=val,tran;field;field=val,... */
5643 + while (off < tranlen)
5645 + const char* pparamend;
5646 + uint nextparamoff;
5648 + pparamend = memchr(ptran+off, ',', tranlen-off);
5649 + pparamend = (pparamend == NULL) ? ptran+tranlen : pparamend+1;
5650 + nextparamoff = pparamend-ptran;
5652 + while (off < nextparamoff)
5654 + const char* pfieldend;
5655 + uint nextfieldoff;
5657 + pfieldend = memchr(ptran+off, ';', nextparamoff-off);
5658 + nextfieldoff = (pfieldend == NULL) ? nextparamoff : pfieldend-ptran+1;
5660 + if (strncmp(ptran+off, "client_port=", 12) == 0)
5666 + numlen = nf_strtou16(ptran+off, &port);
5668 + if (prtspexp->loport != 0 && prtspexp->loport != port)
5670 + DEBUGP("multiple ports found, port %hu ignored\n", port);
5674 + prtspexp->loport = prtspexp->hiport = port;
5675 + if (ptran[off] == '-')
5678 + numlen = nf_strtou16(ptran+off, &port);
5680 + prtspexp->pbtype = pb_range;
5681 + prtspexp->hiport = port;
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)
5688 + DEBUGP("incorrect range: %hu-%hu, correcting\n",
5689 + prtspexp->loport, prtspexp->hiport);
5690 + prtspexp->loport &= 0xfffe;
5691 + prtspexp->hiport = prtspexp->loport+1;
5694 + else if (ptran[off] == '/')
5697 + numlen = nf_strtou16(ptran+off, &port);
5699 + prtspexp->pbtype = pb_discon;
5700 + prtspexp->hiport = port;
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.
5713 + off = nextfieldoff;
5716 + off = nextparamoff;
5722 +/*** conntrack functions ***/
5724 +/* outbound packet: client->server */
5726 +help_out(const struct iphdr* iph, size_t pktlen,
5727 + struct ip_conntrack* ct, enum ip_conntrack_info ctinfo)
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;
5736 + struct ip_conntrack_expect exp;
5738 + while (dataoff < datalen)
5740 + uint cmdoff = dataoff;
5750 + if (!rtsp_parse_message(pdata, datalen, &dataoff,
5751 + &hdrsoff, &hdrslen,
5752 + &cseqoff, &cseqlen))
5754 + break; /* not a valid message */
5757 + if (strncmp(pdata+cmdoff, "SETUP ", 6) != 0)
5759 + continue; /* not a SETUP message */
5761 + DEBUGP("found a setup message\n");
5763 + memset(&exp, 0, sizeof(exp));
5766 + while (nf_mime_nextline(pdata+hdrsoff, hdrslen, &off,
5767 + &lineoff, &linelen))
5773 + if (off > hdrsoff+hdrslen)
5775 + INFOP("!! overrun !!");
5779 + if (nf_strncasecmp(pdata+hdrsoff+lineoff, "Transport:", 10) == 0)
5781 + rtsp_parse_transport(pdata+hdrsoff+lineoff, linelen,
5782 + &exp.help.exp_rtsp_info);
5786 + if (exp.help.exp_rtsp_info.loport == 0)
5788 + DEBUGP("no udp transports found\n");
5789 + continue; /* no udp transports found */
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);
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;
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;
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));
5816 + /* pass the request off to the nat helper */
5817 + rc = ip_conntrack_expect_related(&exp, ct);
5818 + UNLOCK_BH(&ip_rtsp_lock);
5821 + DEBUGP("ip_conntrack_expect_related succeeded\n");
5825 + INFOP("ip_conntrack_expect_related failed (%d)\n", rc);
5832 +/* inbound packet: server->client */
5834 +help_in(const struct iphdr* iph, size_t pktlen,
5835 + struct ip_conntrack* ct, enum ip_conntrack_info ctinfo)
5841 +help(const struct iphdr* iph, size_t pktlen,
5842 + struct ip_conntrack* ct, enum ip_conntrack_info ctinfo)
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;
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)
5851 + DEBUGP("conntrackinfo = %u\n", ctinfo);
5855 + /* Not whole TCP header? */
5856 + if (tcplen < sizeof(struct tcphdr) || tcplen < tcph->doff * 4)
5858 + DEBUGP("tcplen = %u\n", (unsigned)tcplen);
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)))
5867 + DEBUGP("bad csum: %p %u %u.%u.%u.%u %u.%u.%u.%u\n",
5868 + tcph, tcplen, NIPQUAD(iph->saddr), NIPQUAD(iph->daddr));
5872 + switch (CTINFO2DIR(ctinfo))
5874 + case IP_CT_DIR_ORIGINAL:
5875 + help_out(iph, pktlen, ct, ctinfo);
5877 + case IP_CT_DIR_REPLY:
5878 + help_in(iph, pktlen, ct, ctinfo);
5885 +static struct ip_conntrack_helper rtsp_helpers[MAX_PORTS];
5886 +static char rtsp_names[MAX_PORTS][10];
5888 +/* This function is intentionally _NOT_ defined as __exit */
5893 + for (i = 0; i < num_ports; i++)
5895 + DEBUGP("unregistering port %d\n", ports[i]);
5896 + ip_conntrack_helper_unregister(&rtsp_helpers[i]);
5904 + struct ip_conntrack_helper *hlpr;
5907 + printk("ip_conntrack_rtsp v" IP_NF_RTSP_VERSION " loading\n");
5909 + if (max_outstanding < 1)
5911 + printk("ip_conntrack_rtsp: max_outstanding must be a positive integer\n");
5914 + if (setup_timeout < 0)
5916 + printk("ip_conntrack_rtsp: setup_timeout must be a positive integer\n");
5920 + /* If no port given, default to standard rtsp port */
5921 + if (ports[0] == 0)
5923 + ports[0] = RTSP_PORT;
5926 + for (i = 0; (i < MAX_PORTS) && ports[i]; i++)
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;
5940 + tmpname = &rtsp_names[i][0];
5941 + if (ports[i] == RTSP_PORT)
5943 + sprintf(tmpname, "rtsp");
5947 + sprintf(tmpname, "rtsp-%d", i);
5949 + hlpr->name = tmpname;
5951 + DEBUGP("port #%d: %d\n", i, ports[i]);
5953 + ret = ip_conntrack_helper_register(hlpr);
5957 + printk("ip_conntrack_rtsp: ERROR registering port %d\n", ports[i]);
5966 +#ifdef CONFIG_IP_NF_NAT_NEEDED
5967 +EXPORT_SYMBOL(ip_rtsp_lock);
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
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);
5982 len += sprintf(buffer + len, "\n");
5987 goto cleanup_nothing;
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;
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
6007 + * talk extension for IP connection tracking.
6008 + * Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
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.
6015 + * Module load syntax:
6016 + * insmod ip_nat_talk.o talk=[0|1] ntalk=[0|1] ntalk2=[01]
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
6022 + * The default is talk=1 ntalk=1 ntalk2=1
6024 + * The helper does not support simultaneous talk requests.
6027 + * ASCII art on talk protocols
6030 + * caller server callee server
6037 + * caller client ----------- callee client
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
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)
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>
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>
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");
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");
6078 +DECLARE_LOCK(ip_talk_lock);
6079 +struct module *ip_conntrack_talk = THIS_MODULE;
6082 +#define DEBUGP printk
6084 +#define DEBUGP(format, args...)
6087 +static int talk_expect(struct ip_conntrack *ct);
6088 +static int ntalk_expect(struct ip_conntrack *ct);
6090 +static int (*talk_expectfn[2])(struct ip_conntrack *ct) = {talk_expect, ntalk_expect};
6092 +static int talk_help_response(const struct iphdr *iph, size_t len,
6093 + struct ip_conntrack *ct,
6094 + enum ip_conntrack_info ctinfo,
6099 + struct talk_addr *addr)
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;
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),
6109 + if (!(answer == SUCCESS && type == mode))
6112 + memset(&expect, 0, sizeof(expect));
6114 + if (type == ANNOUNCE) {
6116 + DEBUGP("ip_ct_talk_help_response: ANNOUNCE\n");
6118 + /* update the talk info */
6119 + LOCK_BH(&ip_talk_lock);
6120 + exp_talk_info->port = htons(talk_port);
6122 + /* expect callee client -> caller server message */
6123 + exp->tuple = ((struct ip_conntrack_tuple)
6124 + { { ct->tuplehash[dir].tuple.src.ip,
6126 + { ct->tuplehash[dir].tuple.dst.ip,
6127 + { .tcp = { htons(talk_port) } },
6129 + exp->mask = ((struct ip_conntrack_tuple)
6130 + { { 0xFFFFFFFF, { 0 } },
6131 + { 0xFFFFFFFF, { .tcp = { 0xFFFF } }, 0xFFFF }});
6133 + exp->expectfn = talk_expectfn[talk_port - TALK_PORT];
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));
6139 + /* Ignore failure; should only happen with NAT */
6140 + ip_conntrack_expect_related(&expect, ct);
6141 + UNLOCK_BH(&ip_talk_lock);
6143 + if (type == LOOK_UP) {
6145 + DEBUGP("ip_ct_talk_help_response: LOOK_UP\n");
6147 + /* update the talk info */
6148 + LOCK_BH(&ip_talk_lock);
6149 + exp_talk_info->port = addr->ta_port;
6151 + /* expect callee client -> caller client connection */
6152 + exp->tuple = ((struct ip_conntrack_tuple)
6153 + { { ct->tuplehash[!dir].tuple.src.ip,
6156 + { addr->ta_port },
6158 + exp->mask = ((struct ip_conntrack_tuple)
6159 + { { 0xFFFFFFFF, { 0 } },
6160 + { 0xFFFFFFFF, { 0xFFFF }, 0xFFFF }});
6162 + exp->expectfn = NULL;
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));
6168 + /* Ignore failure; should only happen with NAT */
6169 + ip_conntrack_expect_related(&expect, ct);
6170 + UNLOCK_BH(&ip_talk_lock);
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,
6183 + struct udphdr *udph = (void *)iph + iph->ihl * 4;
6184 + const char *data = (const char *)udph + sizeof(struct udphdr);
6185 + int dir = CTINFO2DIR(ctinfo);
6188 + DEBUGP("ip_ct_talk_help: help entered\n");
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);
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);
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));
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));
6217 + if (dir == IP_CT_DIR_ORIGINAL)
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
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
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));
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));
6250 +static int lookup_help(const struct iphdr *iph, size_t len,
6251 + struct ip_conntrack *ct, enum ip_conntrack_info ctinfo)
6253 + return talk_help(iph, len, ct, ctinfo, TALK_PORT, LOOK_UP);
6256 +static int lookup_nhelp(const struct iphdr *iph, size_t len,
6257 + struct ip_conntrack *ct, enum ip_conntrack_info ctinfo)
6259 + return talk_help(iph, len, ct, ctinfo, NTALK_PORT, LOOK_UP);
6262 +static struct ip_conntrack_helper lookup_helpers[2] =
6263 + { { { NULL, NULL },
6264 + "talk", /* name */
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 */
6275 + "ntalk", /* name */
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 */
6287 +static int talk_expect(struct ip_conntrack *ct)
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);
6294 + return NF_ACCEPT; /* unused */
6297 +static int ntalk_expect(struct ip_conntrack *ct)
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);
6304 + return NF_ACCEPT; /* unused */
6307 +static int help(const struct iphdr *iph, size_t len,
6308 + struct ip_conntrack *ct, enum ip_conntrack_info ctinfo)
6310 + return talk_help(iph, len, ct, ctinfo, TALK_PORT, ANNOUNCE);
6313 +static int nhelp(const struct iphdr *iph, size_t len,
6314 + struct ip_conntrack *ct, enum ip_conntrack_info ctinfo)
6316 + return talk_help(iph, len, ct, ctinfo, NTALK_PORT, ANNOUNCE);
6319 +static struct ip_conntrack_helper talk_helpers[2] =
6320 + { { { NULL, NULL },
6321 + "talk", /* name */
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 */
6332 + "ntalk", /* name */
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 */
6344 +static int __init init(void)
6347 + ip_conntrack_helper_register(&talk_helpers[0]);
6348 + if (ntalk > 0 || ntalk2 > 0)
6349 + ip_conntrack_helper_register(&talk_helpers[1]);
6354 +static void __exit fini(void)
6357 + ip_conntrack_helper_unregister(&talk_helpers[0]);
6358 + if (ntalk > 0 || ntalk2 > 0)
6359 + ip_conntrack_helper_unregister(&talk_helpers[1]);
6362 +EXPORT_SYMBOL(ip_talk_lock);
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
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,
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
6383 + * H.323 'brute force' extension for NAT alteration.
6384 + * Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
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.
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>
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>
6407 +MODULE_AUTHOR("Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>");
6408 +MODULE_DESCRIPTION("H.323 'brute force' connection tracking module");
6409 +MODULE_LICENSE("GPL");
6411 +DECLARE_LOCK_EXTERN(ip_h323_lock);
6412 +struct module *ip_nat_h323 = THIS_MODULE;
6415 +#define DEBUGP printk
6417 +#define DEBUGP(format, args...)
6420 +/* FIXME: Time out? --RR */
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);
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);
6435 +static struct ip_nat_helper h245 =
6437 + "H.245", /* name */
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 */
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)
6454 + struct ip_nat_multi_range mr;
6455 + u_int32_t newdstip, newsrcip, newip;
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;
6462 + IP_NF_ASSERT(info);
6463 + IP_NF_ASSERT(master);
6465 + IP_NF_ASSERT(!(info->initialized & (1<<HOOK2MANIP(hooknum))));
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;
6471 + LOCK_BH(&ip_h323_lock);
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));
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));
6491 + port = exp_info->port;
6492 + is_h225 = master_info->is_h225 == H225_PORT;
6493 + UNLOCK_BH(&ip_h323_lock);
6495 + if (HOOK2MANIP(hooknum) == IP_NAT_MANIP_SRC)
6500 + DEBUGP("h225_nat_expected: IP to %u.%u.%u.%u\n", NIPQUAD(newip));
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;
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 } });
6516 + ret = ip_nat_setup_info(ct, &mr, hooknum);
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;
6526 +static int h323_signal_address_fixup(struct ip_conntrack *ct,
6527 + struct sk_buff **pskb,
6528 + enum ip_conntrack_info ctinfo)
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;
6540 + MUST_BE_LOCKED(&ip_h323_lock);
6542 + DEBUGP("h323_signal_address_fixup: %s %s\n",
6543 + between(info->seq[IP_CT_DIR_ORIGINAL], ntohl(tcph->seq), ntohl(tcph->seq) + datalen)
6545 + between(info->seq[IP_CT_DIR_REPLY], ntohl(tcph->seq), ntohl(tcph->seq) + datalen)
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)))
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],
6555 + DUMP_TUPLE(&ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple);
6556 + DUMP_TUPLE(&ct->tuplehash[IP_CT_DIR_REPLY].tuple);
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))
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",
6572 + ntohl(tcph->seq) + datalen);
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;
6583 + newip = ct->tuplehash[!info->dir].tuple.src.ip;
6584 + port = ct->tuplehash[!info->dir].tuple.src.u.tcp.port;
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))));
6592 + /* Modify the packet */
6593 + *(u_int32_t *)(data + info->offset[i]) = newip;
6594 + *(u_int16_t *)(data + info->offset[i] + 4) = port;
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))));
6602 + /* fix checksum information */
6604 + (*pskb)->csum = csum_partial((char *)tcph + tcph->doff*4,
6608 + tcph->check = tcp_v4_check(tcph, tcplen, iph->saddr, iph->daddr,
6609 + csum_partial((char *)tcph, tcph->doff*4,
6611 + ip_send_check(iph);
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)
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;
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);
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",
6644 + ntohl(tcph->seq) + tcplen - tcph->doff * 4);
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;
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;
6665 + is_h225 = (master_info->is_h225 == H225_PORT);
6668 + newtuple.dst.protonum = IPPROTO_TCP;
6669 + newtuple.src.u.tcp.port = expect->tuple.src.u.tcp.port;
6671 + newtuple.dst.protonum = IPPROTO_UDP;
6672 + newtuple.src.u.udp.port = expect->tuple.src.u.udp.port;
6675 + /* Try to get same port: if not, try to change it. */
6676 + for (port = ntohs(info->port); port != 0; port++) {
6678 + newtuple.dst.u.tcp.port = htons(port);
6680 + newtuple.dst.u.udp.port = htons(port);
6682 + if (ip_conntrack_change_expect(expect, &newtuple) == 0)
6686 + DEBUGP("h323_data_fixup: no free port found!\n");
6690 + port = htons(port);
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))));
6696 + /* Modify the packet */
6697 + *(u_int32_t *)(data + info->offset) = newip;
6698 + *(u_int16_t *)(data + info->offset + 4) = port;
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))));
6704 + /* fix checksum information */
6705 + /* FIXME: usually repeated multiple times in the case of H.245! */
6707 + (*pskb)->csum = csum_partial((char *)tcph + tcph->doff*4,
6708 + tcplen - tcph->doff*4, 0);
6711 + tcph->check = tcp_v4_check(tcph, tcplen, iph->saddr, iph->daddr,
6712 + csum_partial((char *)tcph, tcph->doff*4,
6714 + ip_send_check(iph);
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)
6727 + struct ip_ct_h225_expect *exp_info;
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" : "???");
6748 + LOCK_BH(&ip_h323_lock);
6749 + if (!h323_signal_address_fixup(ct, pskb, ctinfo)) {
6750 + UNLOCK_BH(&ip_h323_lock);
6753 + UNLOCK_BH(&ip_h323_lock);
6757 + exp_info = &exp->help.exp_h225_info;
6759 + LOCK_BH(&ip_h323_lock);
6760 + if (!h323_data_fixup(exp_info, ct, pskb, ctinfo, exp)) {
6761 + UNLOCK_BH(&ip_h323_lock);
6764 + UNLOCK_BH(&ip_h323_lock);
6769 +static struct ip_nat_helper h225 =
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 */
6782 +static int __init init(void)
6786 + ret = ip_nat_helper_register(&h225);
6789 + printk("ip_nat_h323: cannot initialize the module!\n");
6794 +static void __exit fini(void)
6796 + ip_nat_helper_unregister(&h225);
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
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
6809 + * ip_nat_mms.c v0.3 2002-09-22
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.
6816 + * Module load syntax:
6817 + * insmod ip_nat_mms.o ports=port1,port2,...port<MAX_PORTS>
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.
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
6826 + * The SDP project people are reverse-engineering MMS:
6827 + * http://get.to/sdp
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 */
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>
6850 +#define DEBUGP printk
6851 +#define DUMP_BYTES(address, counter) \
6853 + int temp_counter; \
6854 + for(temp_counter=0; temp_counter<counter; ++temp_counter) { \
6855 + DEBUGP("%u ", (u8)*(address+temp_counter)); \
6860 +#define DEBUGP(format, args...)
6861 +#define DUMP_BYTES(address, counter)
6864 +#define MAX_PORTS 8
6865 +static int ports[MAX_PORTS];
6866 +static int ports_c = 0;
6869 +MODULE_PARM(ports, "1-" __MODULE_STRING(MAX_PORTS) "i");
6872 +MODULE_AUTHOR("Filip Sneppe <filip.sneppe@cronos.be>");
6873 +MODULE_DESCRIPTION("Microsoft Windows Media Services (MMS) NAT module");
6874 +MODULE_LICENSE("GPL");
6876 +DECLARE_LOCK_EXTERN(ip_mms_lock);
6878 +/* FIXME: Time out? --RR */
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)
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;
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);
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];
6904 + MUST_BE_LOCKED(&ip_mms_lock);
6906 + /* what was the protocol again ? */
6907 + mms_proto = expect->tuple.dst.protonum;
6908 + sprintf(proto_string, "%u", mms_proto);
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);
6915 + newip = ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.ip;
6917 + /* Alter conntrack's expectations. */
6918 + t = expect->tuple;
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);
6931 + sprintf(buffer, "\\\\%u.%u.%u.%u\\%s\\%u",
6933 + expect->tuple.dst.protonum == IPPROTO_UDP ? "UDP"
6934 + : expect->tuple.dst.protonum == IPPROTO_TCP ? "TCP":proto_string,
6936 + DEBUGP("ip_nat_mms: new unicode string=%s\n", buffer);
6938 + memset(unicode_buffer, 0, sizeof(char)*75);
6940 + for (i=0; i<strlen(buffer); ++i)
6941 + *(unicode_buffer+i*2)=*(buffer+i);
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);
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);
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;
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);
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;
6972 + DEBUGP("ip_nat_mms: modified=> chunkLenLV=%u chunkLenLM=%u messageLength=%u\n",
6973 + *mms_chunkLenLV, *mms_chunkLenLM, *mms_messageLength);
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);
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)
6990 + struct ip_nat_multi_range mr;
6991 + u_int32_t newdstip, newsrcip, newip;
6993 + struct ip_conntrack *master = master_ct(ct);
6995 + IP_NF_ASSERT(info);
6996 + IP_NF_ASSERT(master);
6998 + IP_NF_ASSERT(!(info->initialized & (1 << HOOK2MANIP(hooknum))));
7000 + DEBUGP("ip_nat_mms: mms_nat_expected: We have a connection!\n");
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));
7010 + if (HOOK2MANIP(hooknum) == IP_NAT_MANIP_SRC)
7015 + DEBUGP("ip_nat_mms: mms_nat_expected: IP to %u.%u.%u.%u\n", NIPQUAD(newip));
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;
7022 + return ip_nat_setup_info(ct, &mr, hooknum);
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)
7033 + struct iphdr *iph = (*pskb)->nh.iph;
7034 + struct tcphdr *tcph = (void *) iph + iph->ihl * 4;
7035 + unsigned int datalen;
7037 + struct ip_ct_mms_expect *ct_mms_info;
7040 + DEBUGP("ip_nat_mms: no exp!!");
7042 + ct_mms_info = &exp->help.exp_mms_info;
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" : "???");
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" : "???");
7062 + datalen = (*pskb)->len - iph->ihl * 4 - tcph->doff * 4;
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,
7067 + ntohl(tcph->seq) + datalen);
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,
7073 + ntohl(tcph->seq) + datalen)) {
7074 + if (!mms_data_fixup(ct_mms_info, ct, pskb, ctinfo, exp)) {
7075 + UNLOCK_BH(&ip_mms_lock);
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,
7085 + ntohl(tcph->seq) + datalen);
7087 + UNLOCK_BH(&ip_mms_lock);
7090 + UNLOCK_BH(&ip_mms_lock);
7095 +static struct ip_nat_helper mms[MAX_PORTS];
7096 +static char mms_names[MAX_PORTS][10];
7098 +/* Not __exit: called from init() */
7099 +static void fini(void)
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]);
7109 +static int __init init(void)
7114 + if (ports[0] == 0)
7115 + ports[0] = MMS_PORT;
7117 + for (i = 0; (i < MAX_PORTS) && ports[i]; i++) {
7119 + memset(&mms[i], 0, sizeof(struct ip_nat_helper));
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;
7128 + mms[i].expect = mms_nat_expected;
7130 + tmpname = &mms_names[i][0];
7131 + if (ports[i] == MMS_PORT)
7132 + sprintf(tmpname, "mms");
7134 + sprintf(tmpname, "mms-%d", i);
7135 + mms[i].name = tmpname;
7137 + DEBUGP("ip_nat_mms: register helper for port %d\n",
7139 + ret = ip_nat_helper_register(&mms[i]);
7142 + printk("ip_nat_mms: error registering "
7143 + "helper for port %d\n", ports[i]);
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
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
7163 + * ip_nat_quake3.c v0.0.3 2002-08-31
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.
7170 + * Module load syntax:
7171 + * insmod ip_nat_quake3.o ports=port1,port2,...port<MAX_PORTS>
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
7177 + * Thanks to the Ethereal folks for their analysis of the Quake3 protocol.
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
7198 +#include <linux/module.h>
7199 +#include <linux/netfilter_ipv4.h>
7200 +#include <linux/ip.h>
7201 +#include <linux/udp.h>
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>
7210 +MODULE_AUTHOR("Filip Sneppe <filip.sneppe@cronos.be>");
7211 +MODULE_DESCRIPTION("Netfilter NAT helper for Quake III Arena");
7212 +MODULE_LICENSE("GPL");
7214 +#define MAX_PORTS 8
7216 +static int ports[MAX_PORTS];
7217 +static int ports_c = 0;
7219 +MODULE_PARM(ports,"1-" __MODULE_STRING(MAX_PORTS) "i");
7220 +MODULE_PARM_DESC(ports, "port numbers of Quake III master servers");
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 */
7226 +#define DEBUGP printk
7228 +#define DEBUGP(format, args...)
7231 +static struct quake3_search quake3s_nat = { "****", "getserversResponse", sizeof("getserversResponse") - 1 };
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)
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);
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" : "???"
7253 + DUMP_TUPLE(&ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple);
7254 + DUMP_TUPLE(&ct->tuplehash[IP_CT_DIR_REPLY].tuple);
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" : "????");
7269 + DEBUGP("no conntrack expectation to modify\n");
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);
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 ) ) ) );
7282 + memset(&repl, 0, sizeof(repl));
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 ) );
7289 + ip_conntrack_change_expect(exp, &repl);
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)
7301 + const struct ip_conntrack *master = ct->master->expectant;
7302 + struct ip_nat_multi_range mr;
7303 + u_int32_t newsrcip, newdstip, newip;
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;
7311 + DEBUGP("ip_nat_quake3: quake3_nat_expected: here we are\n");
7312 + DUMP_TUPLE(&ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple);
7314 + IP_NF_ASSERT(info);
7315 + IP_NF_ASSERT(master);
7316 + IP_NF_ASSERT(!(info->initialized & (1 << HOOK2MANIP(hooknum))));
7318 + newdstip = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.ip;
7319 + newsrcip = master->tuplehash[IP_CT_DIR_REPLY].tuple.dst.ip;
7321 + if (HOOK2MANIP(hooknum) == IP_NAT_MANIP_SRC) {
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),
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),
7345 + mr.range[0].flags = IP_NAT_RANGE_MAP_IPS;
7346 + mr.range[0].min_ip = mr.range[0].max_ip = newip;
7348 + return ip_nat_setup_info(ct,&mr,hooknum);
7351 +static struct ip_nat_helper quake3[MAX_PORTS];
7352 +static char quake3_names[MAX_PORTS][13]; /* quake3-65535 */
7354 +static void fini(void)
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]);
7364 +static int __init init(void)
7370 + ports[0] = QUAKE3_MASTER_PORT;
7372 + for (i = 0 ; (i < MAX_PORTS) && ports[i] ; i++) {
7373 + memset(&quake3[i], 0, sizeof(struct ip_nat_helper));
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;
7384 + tmpname = &quake3_names[i][0];
7385 + if (ports[i] == QUAKE3_MASTER_PORT)
7386 + sprintf(tmpname, "quake3");
7388 + sprintf(tmpname, "quake3-%d", i);
7389 + quake3[i].name = tmpname;
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]);
7396 + printk("ip_nat_quake3: unable to register helper for port %d\n",
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
7413 + * RTSP extension for TCP NAT alteration
7414 + * (C) 2003 by Tom Marshall <tmarshall@real.com>
7415 + * based on ip_nat_irc.c
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.
7422 + * Module load syntax:
7423 + * insmod ip_nat_rtsp.o ports=port1,port2,...port<MAX_PORTS>
7424 + * stunaddr=<address>
7425 + * destaction=[auto|strip|none]
7427 + * If no ports are specified, the default will be port 554 only.
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.
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).
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>
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>
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)
7468 +#define DEBUGP(fmt, args...)
7471 +#define MAX_PORTS 8
7472 +#define DSTACT_AUTO 0
7473 +#define DSTACT_STRIP 1
7474 +#define DSTACT_NONE 2
7476 +static int ports[MAX_PORTS];
7477 +static char* stunaddr = NULL;
7478 +static char* destaction = NULL;
7480 +static int num_ports = 0;
7481 +static u_int32_t extip = 0;
7482 +static int dstact = 0;
7484 +MODULE_AUTHOR("Tom Marshall <tmarshall@real.com>");
7485 +MODULE_DESCRIPTION("RTSP network address translation module");
7486 +MODULE_LICENSE("GPL");
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)");
7496 +/* protects rtsp part of conntracks */
7497 +DECLARE_LOCK_EXTERN(ip_rtsp_lock);
7499 +#define SKIP_WSPACE(ptr,len,off) while(off < len && isspace(*(ptr+off))) { off++; }
7501 +/*** helper functions ***/
7504 +get_skb_tcpdata(struct sk_buff* skb, char** pptcpdata, uint* ptcpdatalen)
7506 + struct iphdr* iph = (struct iphdr*)skb->nh.iph;
7507 + struct tcphdr* tcph = (struct tcphdr*)((char*)iph + iph->ihl*4);
7509 + *pptcpdata = (char*)tcph + tcph->doff*4;
7510 + *ptcpdatalen = ((char*)skb->h.raw + skb->len) - *pptcpdata;
7513 +/*** nat functions ***/
7516 + * Mangle the "Transport:" header:
7517 + * - Replace all occurences of "client_port=<spec>"
7518 + * - Handle destination parameter
7521 + * ct, ctinfo = conntrack context
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)
7528 + * Returns packet size difference.
7530 + * Assumes that a complete transport header is present, ending with CR or LF
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)
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) */
7545 + u_int16_t loport, hiport;
7547 + uint diff; /* Number of bytes we removed */
7549 + struct ip_ct_rtsp_expect* prtspexp = &exp->help.exp_rtsp_info;
7550 + struct ip_conntrack_tuple t;
7552 + char szextaddr[15+1];
7556 + get_skb_tcpdata(*pskb, &ptcp, &tcplen);
7557 + ptran = ptcp+tranoff;
7559 + if (tranoff+tranlen > tcplen || tcplen-tranoff < tranlen ||
7560 + tranlen < 10 || !iseol(ptran[tranlen-1]) ||
7561 + nf_strncasecmp(ptran, "Transport:", 10) != 0)
7563 + INFOP("sanity check failed\n");
7567 + SKIP_WSPACE(ptcp+tranoff, tranlen, off);
7569 + newip = ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.ip;
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"));
7577 + rbuf1len = rbufalen = 0;
7578 + switch (prtspexp->pbtype)
7581 + for (loport = prtspexp->loport; loport != 0; loport++) /* XXX: improper wrap? */
7583 + t.dst.u.udp.port = htons(loport);
7584 + if (ip_conntrack_change_expect(exp, &t) == 0)
7586 + DEBUGP("using port %hu\n", loport);
7592 + rbuf1len = sprintf(rbuf1, "%hu", loport);
7593 + rbufalen = sprintf(rbufa, "%hu", loport);
7597 + for (loport = prtspexp->loport; loport != 0; loport += 2) /* XXX: improper wrap? */
7599 + t.dst.u.udp.port = htons(loport);
7600 + if (ip_conntrack_change_expect(exp, &t) == 0)
7602 + hiport = loport + ~exp->mask.dst.u.udp.port;
7603 + DEBUGP("using ports %hu-%hu\n", loport, hiport);
7609 + rbuf1len = sprintf(rbuf1, "%hu", loport);
7610 + rbufalen = sprintf(rbufa, "%hu-%hu", loport, loport+1);
7614 + for (loport = prtspexp->loport; loport != 0; loport++) /* XXX: improper wrap? */
7616 + t.dst.u.udp.port = htons(loport);
7617 + if (ip_conntrack_change_expect(exp, &t) == 0)
7619 + DEBUGP("using port %hu (1 of 2)\n", loport);
7623 + for (hiport = prtspexp->hiport; hiport != 0; hiport++) /* XXX: improper wrap? */
7625 + t.dst.u.udp.port = htons(hiport);
7626 + if (ip_conntrack_change_expect(exp, &t) == 0)
7628 + DEBUGP("using port %hu (2 of 2)\n", hiport);
7632 + if (loport != 0 && hiport != 0)
7634 + rbuf1len = sprintf(rbuf1, "%hu", loport);
7635 + if (hiport == loport+1)
7637 + rbufalen = sprintf(rbufa, "%hu-%hu", loport, hiport);
7641 + rbufalen = sprintf(rbufa, "%hu/%hu", loport, hiport);
7647 + if (rbuf1len == 0)
7649 + return 0; /* cannot get replacement port(s) */
7652 + /* Transport: tran;field;field=val,tran;field;field=val,... */
7653 + while (off < tranlen)
7656 + const char* pparamend;
7657 + uint nextparamoff;
7659 + pparamend = memchr(ptran+off, ',', tranlen-off);
7660 + pparamend = (pparamend == NULL) ? ptran+tranlen : pparamend+1;
7661 + nextparamoff = pparamend-ptcp;
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.
7671 + while (off < nextparamoff)
7673 + const char* pfieldend;
7674 + uint nextfieldoff;
7676 + pfieldend = memchr(ptran+off, ';', nextparamoff-off);
7677 + nextfieldoff = (pfieldend == NULL) ? nextparamoff : pfieldend-ptran+1;
7679 + if (dstact != DSTACT_NONE && strncmp(ptran+off, "destination=", 12) == 0)
7681 + if (strncmp(ptran+off+12, szextaddr, extaddrlen) == 0)
7685 + if (dstact == DSTACT_STRIP || (dstact == DSTACT_AUTO && !is_stun))
7687 + diff = nextfieldoff-off;
7688 + if (!ip_nat_mangle_tcp_packet(pskb, ct, ctinfo,
7689 + off, diff, NULL, 0))
7691 + /* mangle failed, all we can do is bail */
7694 + get_skb_tcpdata(*pskb, &ptcp, &tcplen);
7695 + ptran = ptcp+tranoff;
7697 + nextparamoff -= diff;
7698 + nextfieldoff -= diff;
7702 + off = nextfieldoff;
7709 + while (off < nextparamoff)
7711 + const char* pfieldend;
7712 + uint nextfieldoff;
7714 + pfieldend = memchr(ptran+off, ';', nextparamoff-off);
7715 + nextfieldoff = (pfieldend == NULL) ? nextparamoff : pfieldend-ptran+1;
7717 + if (strncmp(ptran+off, "client_port=", 12) == 0)
7723 + char* rbuf = rbuf1;
7724 + uint rbuflen = rbuf1len;
7727 + origoff = (ptran-ptcp)+off;
7729 + numlen = nf_strtou16(ptran+off, &port);
7731 + origlen += numlen;
7732 + if (port != prtspexp->loport)
7734 + DEBUGP("multiple ports found, port %hu ignored\n", port);
7738 + if (ptran[off] == '-' || ptran[off] == '/')
7742 + numlen = nf_strtou16(ptran+off, &port);
7744 + origlen += numlen;
7746 + rbuflen = rbufalen;
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.
7754 + * parameter 4 below is offset from start of tcp data.
7756 + diff = origlen-rbuflen;
7757 + if (!ip_nat_mangle_tcp_packet(pskb, ct, ctinfo,
7758 + origoff, origlen, rbuf, rbuflen))
7760 + /* mangle failed, all we can do is bail */
7763 + get_skb_tcpdata(*pskb, &ptcp, &tcplen);
7764 + ptran = ptcp+tranoff;
7766 + nextparamoff -= diff;
7767 + nextfieldoff -= diff;
7771 + off = nextfieldoff;
7774 + off = nextparamoff;
7780 +static unsigned int
7781 +expected(struct sk_buff **pskb, uint hooknum, struct ip_conntrack* ct, struct ip_nat_info* info)
7783 + struct ip_nat_multi_range mr;
7784 + u_int32_t newdstip, newsrcip, newip;
7786 + struct ip_conntrack *master = master_ct(ct);
7788 + IP_NF_ASSERT(info);
7789 + IP_NF_ASSERT(master);
7791 + IP_NF_ASSERT(!(info->initialized & (1 << HOOK2MANIP(hooknum))));
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;
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));
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;
7805 + return ip_nat_setup_info(ct, &mr, hooknum);
7809 +help_out(struct ip_conntrack* ct, enum ip_conntrack_info ctinfo,
7810 + struct ip_conntrack_expect* exp, struct sk_buff** pskb)
7820 + struct iphdr* iph = (struct iphdr*)(*pskb)->nh.iph;
7821 + struct tcphdr* tcph = (struct tcphdr*)((void*)iph + iph->ihl*4);
7823 + struct ip_ct_rtsp_expect* prtspexp = &exp->help.exp_rtsp_info;
7825 + get_skb_tcpdata(*pskb, &ptcp, &tcplen);
7827 + hdrsoff = exp->seq - ntohl(tcph->seq);
7828 + hdrslen = prtspexp->len;
7831 + while (nf_mime_nextline(ptcp, hdrsoff+hdrslen, &off, &lineoff, &linelen))
7837 + if (off > hdrsoff+hdrslen)
7839 + INFOP("!! overrun !!");
7842 + DEBUGP("hdr: len=%u, %.*s", linelen, (int)linelen, ptcp+lineoff);
7844 + if (nf_strncasecmp(ptcp+lineoff, "Transport:", 10) == 0)
7846 + uint oldtcplen = tcplen;
7847 + if (!rtsp_mangle_tran(ct, ctinfo, exp, pskb, lineoff, linelen))
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);
7864 +help_in(struct ip_conntrack* ct, enum ip_conntrack_info ctinfo,
7865 + struct ip_conntrack_expect* exp, struct sk_buff** pskb)
7867 + /* XXX: unmangle */
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)
7879 + struct iphdr* iph = (struct iphdr*)(*pskb)->nh.iph;
7880 + struct tcphdr* tcph = (struct tcphdr*)((char*)iph + iph->ihl * 4);
7883 + struct ip_ct_rtsp_expect* ct_rtsp_info;
7884 + int rc = NF_ACCEPT;
7886 + if (ct == NULL || exp == NULL || info == NULL || pskb == NULL)
7888 + DEBUGP("!! null ptr (%p,%p,%p,%p) !!\n", ct, exp, info, pskb);
7892 + ct_rtsp_info = &exp->help.exp_rtsp_info;
7895 + * Only mangle things once: original direction in POST_ROUTING
7896 + * and reply direction on PRE_ROUTING.
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)))
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" : "???");
7909 + DEBUGP("got beyond not touching\n");
7911 + datalen = (*pskb)->len - iph->ihl * 4 - tcph->doff * 4;
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))
7918 + /* Partial retransmission? Probably a hacker. */
7919 + if (net_ratelimit())
7921 + INFOP("partial packet %u/%u in %u/%u\n",
7922 + exp->seq, ct_rtsp_info->len, ntohl(tcph->seq), ntohl(tcph->seq) + datalen);
7924 + UNLOCK_BH(&ip_rtsp_lock);
7930 + case IP_CT_DIR_ORIGINAL:
7931 + rc = help_out(ct, ctinfo, exp, pskb);
7933 + case IP_CT_DIR_REPLY:
7934 + rc = help_in(ct, ctinfo, exp, pskb);
7937 + UNLOCK_BH(&ip_rtsp_lock);
7942 +static struct ip_nat_helper ip_nat_rtsp_helpers[MAX_PORTS];
7943 +static char rtsp_names[MAX_PORTS][10];
7945 +/* This function is intentionally _NOT_ defined as __exit */
7951 + for (i = 0; i < num_ports; i++)
7953 + DEBUGP("unregistering helper for port %d\n", ports[i]);
7954 + ip_nat_helper_unregister(&ip_nat_rtsp_helpers[i]);
7963 + struct ip_nat_helper* hlpr;
7966 + printk("ip_nat_rtsp v" IP_NF_RTSP_VERSION " loading\n");
7968 + if (ports[0] == 0)
7970 + ports[0] = RTSP_PORT;
7973 + for (i = 0; (i < MAX_PORTS) && ports[i] != 0; i++)
7975 + hlpr = &ip_nat_rtsp_helpers[i];
7976 + memset(hlpr, 0, sizeof(struct ip_nat_helper));
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;
7984 + hlpr->me = THIS_MODULE;
7985 + hlpr->expect = expected;
7987 + tmpname = &rtsp_names[i][0];
7988 + if (ports[i] == RTSP_PORT)
7990 + sprintf(tmpname, "rtsp");
7994 + sprintf(tmpname, "rtsp-%d", i);
7996 + hlpr->name = tmpname;
7998 + DEBUGP("registering helper for port %d: name %s\n", ports[i], hlpr->name);
7999 + ret = ip_nat_helper_register(hlpr);
8003 + printk("ip_nat_rtsp: error registering helper for port %d\n", ports[i]);
8009 + if (stunaddr != NULL)
8011 + extip = in_aton(stunaddr);
8013 + if (destaction != NULL)
8015 + if (strcmp(destaction, "auto") == 0)
8017 + dstact = DSTACT_AUTO;
8019 + if (strcmp(destaction, "strip") == 0)
8021 + dstact = DSTACT_STRIP;
8023 + if (strcmp(destaction, "none") == 0)
8025 + dstact = DSTACT_NONE;
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
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)), "" } }, { } },
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)), "" } }, { } },
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)), "" } }, { } },
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 } },
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);
8079 +struct nat_route_key
8088 +nat_route_key_get(struct sk_buff *skb, struct nat_route_key *key, int which)
8090 + struct iphdr *iph = skb->nh.iph;
8092 + key->addr = which ? iph->daddr : iph->saddr;
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];
8103 +nat_route_key_compare(struct sk_buff *skb, struct nat_route_key *key, int which)
8105 + struct iphdr *iph = skb->nh.iph;
8107 + if (key->addr != (which ? iph->daddr : iph->saddr))
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])
8119 ip_nat_out(unsigned int hooknum,
8120 struct sk_buff **pskb,
8122 const struct net_device *out,
8123 int (*okfn)(struct sk_buff *))
8125 + struct nat_route_key key;
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 @@
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);
8139 + if (ret != NF_DROP && ret != NF_STOLEN
8140 + && nat_route_key_compare(*pskb, &key, 0)) {
8141 + if (ip_route_me_harder(pskb) != 0)
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.
8149 + else if ((*pskb)->dst->xfrm != NULL) {
8150 + ret = ip_conntrack_confirm(*pskb);
8151 + if (ret != NF_DROP) {
8152 + dst_output(*pskb);
8161 #ifdef CONFIG_IP_NF_NAT_LOCAL
8163 const struct net_device *out,
8164 int (*okfn)(struct sk_buff *))
8166 - u_int32_t saddr, daddr;
8167 + struct nat_route_key key;
8170 /* root is playing with raw sockets. */
8171 @@ -224,14 +288,14 @@
8172 || (*pskb)->nh.iph->ihl * 4 < sizeof(struct iphdr))
8175 - saddr = (*pskb)->nh.iph->saddr;
8176 - daddr = (*pskb)->nh.iph->daddr;
8178 + nat_route_key_get(*pskb, &key, 1);
8179 ret = ip_nat_fn(hooknum, pskb, in, out, okfn);
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)
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
8197 + * talk extension for UDP NAT alteration.
8198 + * Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
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.
8205 + * Module load syntax:
8206 + * insmod ip_nat_talk.o talk=[0|1] ntalk=[0|1] ntalk2=[0|1]
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
8212 + * The default is talk=1 ntalk=1 ntalk2=1
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>
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>
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");
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");
8246 +#define DEBUGP printk
8247 +#define IP_NAT_TALK_DEBUG
8249 +#define DEBUGP(format, args...)
8252 +/* FIXME: Time out? --RR */
8255 +mangle_packet(struct sk_buff **pskb,
8256 + struct ip_conntrack *ct,
8259 + struct talk_addr *addr,
8260 + struct talk_addr *ctl_addr)
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;
8266 + /* Fortunately talk sends a structure with the address and
8267 + port in it. The size of the packet won't change. */
8269 + if (ctl_addr == NULL) {
8271 + if (addr->ta_addr == INADDR_ANY)
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;
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;
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;
8296 + /* Fix checksums */
8297 + (*pskb)->csum = csum_partial((char *)udph + sizeof(struct udphdr), udplen - sizeof(struct udphdr), 0);
8299 + udph->check = csum_tcpudp_magic(iph->saddr, iph->daddr, udplen, IPPROTO_UDP,
8300 + csum_partial((char *)udph, sizeof(struct udphdr), (*pskb)->csum));
8302 + ip_send_check(iph);
8306 +static int talk_help_msg(struct ip_conntrack *ct,
8307 + struct sk_buff **pskb,
8309 + struct talk_addr *addr,
8310 + struct talk_addr *ctl_addr)
8315 + unsigned int verdict = NF_ACCEPT;
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),
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));
8329 + if (!mangle_packet(pskb, ct, newip, port, addr, ctl_addr))
8330 + verdict = NF_DROP;
8335 +static int talk_help_response(struct ip_conntrack *ct,
8336 + struct ip_conntrack_expect *exp,
8337 + struct sk_buff **pskb,
8340 + struct talk_addr *addr)
8344 + struct ip_conntrack_tuple t;
8345 + struct ip_ct_talk_expect *ct_talk_info;
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),
8351 + LOCK_BH(&ip_talk_lock);
8352 + ct_talk_info = &exp->help.exp_talk_info;
8354 + if (!(answer == SUCCESS
8355 + && (type == LOOK_UP || type == ANNOUNCE)
8356 + && exp != NULL)) {
8357 + UNLOCK_BH(&ip_talk_lock);
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");
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
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);
8380 + t.dst.u.udp.port = htons(port);
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);
8387 + UNLOCK_BH(&ip_talk_lock);
8389 + if (port == 0 || !mangle_packet(pskb, ct, newip, htons(port), addr, NULL))
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,
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);
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" : "???");
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),
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));
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));
8452 + if (dir == IP_CT_DIR_ORIGINAL) {
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));
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));
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));
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));
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));
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));
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)
8508 + return talk_help(ct, exp, info, ctinfo, hooknum, pskb, TALK_PORT);
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)
8518 + return talk_help(ct, exp, info, ctinfo, hooknum, pskb, NTALK_PORT);
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);
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 */
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 */
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)
8556 + struct ip_nat_multi_range mr;
8557 + u_int32_t newdstip, newsrcip, newip;
8561 + struct ip_conntrack *master = master_ct(ct);
8563 + IP_NF_ASSERT(info);
8564 + IP_NF_ASSERT(master);
8566 + IP_NF_ASSERT(!(info->initialized & (1<<HOOK2MANIP(hooknum))));
8568 + DEBUGP("ip_nat_talk_expected: We have a connection!\n");
8570 + LOCK_BH(&ip_talk_lock);
8571 + port = ct->master->help.exp_talk_info.port;
8572 + UNLOCK_BH(&ip_talk_lock);
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" : "???",
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;
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));
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));
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;
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));
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));
8610 + if (HOOK2MANIP(hooknum) == IP_NAT_MANIP_SRC)
8615 + DEBUGP("ip_nat_talk_expected: IP to %u.%u.%u.%u, port %u\n", NIPQUAD(newip), ntohs(port));
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;
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 } });
8630 + ret = ip_nat_setup_info(ct, &mr, hooknum);
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];
8640 +static int __init init(void)
8645 + ret = ip_nat_helper_register(&talk_helpers[0]);
8650 + if (ntalk > 0 || ntalk2 > 0) {
8651 + ret = ip_nat_helper_register(&talk_helpers[1]);
8653 + if (ret != 0 && talk > 0)
8654 + ip_nat_helper_unregister(&talk_helpers[0]);
8659 +static void __exit fini(void)
8662 + ip_nat_helper_unregister(&talk_helpers[0]);
8663 + if (ntalk > 0 || ntalk2 > 0)
8664 + ip_nat_helper_unregister(&talk_helpers[1]);
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
8673 +/* Kernel module for IP pool management */
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>
8689 +#define DP(format, args...)
8692 +MODULE_LICENSE("GPL");
8695 +static int nr_pool = NR_POOL;/* overwrite this when loading module */
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 */
8706 +static struct ip_pool *POOL;
8708 +static inline struct ip_pool *lookup(ip_pool_t index)
8710 + if (index < 0 || index >= nr_pool) {
8711 + DP("ip_pool:lookup: bad index %d\n", index);
8714 + return POOL+index;
8717 +int ip_pool_match(ip_pool_t index, u_int32_t addr)
8719 + struct ip_pool *pool = lookup(index);
8722 + if (!pool || !pool->members)
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)) {
8730 +#ifdef CONFIG_IP_POOL_STATISTICS
8735 +#ifdef CONFIG_IP_POOL_STATISTICS
8739 + read_unlock_bh(&pool->lock);
8742 +EXPORT_SYMBOL(ip_pool_match);
8744 +static int pool_change(ip_pool_t index, u_int32_t addr, int isdel)
8746 + struct ip_pool *pool;
8749 + pool = lookup(index);
8750 + if ( !pool || !pool->members
8751 + || addr < pool->first_ip || addr > pool->last_ip)
8753 + read_lock_bh(&pool->lock);
8754 + if (pool->members && addr >= pool->first_ip && addr <= pool->last_ip) {
8755 + addr -= pool->first_ip;
8757 + ? (0 != test_and_clear_bit(addr, pool->members))
8758 + : (0 != test_and_set_bit(addr, pool->members));
8760 + read_unlock_bh(&pool->lock);
8764 +int ip_pool_mod(ip_pool_t index, u_int32_t addr, int isdel)
8766 + int res = pool_change(index,addr,isdel);
8768 + if (!isdel) res = !res;
8771 +EXPORT_SYMBOL(ip_pool_mod);
8773 +static inline int bitmap_bytes(u_int32_t a, u_int32_t b)
8775 + return 4*((((b-a+8)/8)+3)/4);
8778 +static inline int poolbytes(ip_pool_t index)
8780 + struct ip_pool *pool = lookup(index);
8782 + return pool ? bitmap_bytes(pool->first_ip, pool->last_ip) : 0;
8785 +static int setpool(
8791 + struct ip_pool_request req;
8793 + DP("ip_pool:setpool: optval=%d, user=%p, len=%d\n", optval, user, len);
8794 + if (!capable(CAP_NET_ADMIN))
8796 + if (optval != SO_IP_POOL)
8798 + if (len != sizeof(req))
8800 + if (copy_from_user(&req, user, sizeof(req)) != 0)
8802 + printk("obsolete op - upgrade your ippool(8) utility.\n");
8806 +static int getpool(
8812 + struct ip_pool_request req;
8813 + struct ip_pool *pool;
8819 + DP("ip_pool:getpool: optval=%d, user=%p\n", optval, user);
8820 + if (!capable(CAP_NET_ADMIN))
8822 + if (optval != SO_IP_POOL)
8824 + if (*len != sizeof(req)) {
8827 + if (copy_from_user(&req, user, sizeof(req)) != 0)
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");
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)
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);
8847 + if (!pool->members)
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);
8857 + if (!pool->members)
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);
8868 + read_lock_bh(&pool->lock);
8869 + if (!pool->members) {
8870 + DP("ip_pool TEST_ADDR no members in pool\n");
8872 + goto unlock_and_return_res;
8874 + req.addr = ntohl(req.addr);
8875 + if (req.addr < pool->first_ip) {
8876 + DP("ip_pool TEST_ADDR address < pool bounds\n");
8878 + goto unlock_and_return_res;
8880 + if (req.addr > pool->last_ip) {
8881 + DP("ip_pool TEST_ADDR address > pool bounds\n");
8883 + goto unlock_and_return_res;
8885 + req.addr = (0 != test_bit((req.addr - pool->first_ip),
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");
8892 + case IP_POOL_DESTROY:
8893 + DP("ip_pool DESTROY not yet implemented.\n");
8895 + case IP_POOL_INIT:
8896 + DP("ip_pool INIT 0x%08x-0x%08x\n", req.addr, req.addr2);
8897 + pool = lookup(req.index);
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");
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);
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);
8918 + goto unlock_and_return_res;
8920 + pool->first_ip = req.addr;
8921 + pool->last_ip = req.addr2;
8923 + pool->nr_match = 0;
8924 + pool->members = newmembers;
8925 + write_unlock_bh(&pool->lock);
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));
8936 + DP("ip_pool:getpool bad op %d\n", req.op);
8941 +unlock_and_return_res:
8943 + read_unlock_bh(&pool->lock);
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,
8953 +MODULE_PARM(nr_pool, "i");
8955 +static int __init init(void)
8960 + if (nr_pool < 1) {
8961 + printk("ip_pool module init: bad nr_pool %d\n", nr_pool);
8964 + POOL = kmalloc(nr_pool * sizeof(*POOL), GFP_KERNEL);
8966 + printk("ip_pool module init: out of memory for nr_pool %d\n",
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;
8978 + res = nf_register_sockopt(&so_pool);
8979 + DP("ip_pool:init %d pools, result %d\n", nr_pool, res);
8987 +static void __exit fini(void)
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;
9001 + DP("ip_pool:fini these are the famous last words\n");
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
9012 #include <linux/netfilter_ipv4/ip_tables.h>
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",
9022 MODULE_LICENSE("GPL");
9023 MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>");
9024 MODULE_DESCRIPTION("IPv4 packet filter");
9025 @@ -323,6 +331,12 @@
9027 t = ipt_get_target(e);
9028 IP_NF_ASSERT(t->u.kernel.target);
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);
9035 /* Standard target? */
9036 if (!t->u.kernel.target->target) {
9039 /* set back pointer to next entry */
9043 e = get_entry(table_base, v);
9045 /* Targets which reenter must return
9046 @@ -475,6 +488,29 @@
9047 return find_inlist_lock(&ipt_target, name, "ipt_", error, mutex);
9051 +find_error_target(struct ipt_entry *s,
9052 + struct ipt_entry *e,
9055 + struct ipt_entry_target *t;
9056 + static struct ipt_entry *found = NULL;
9061 + t = ipt_get_target(found);
9062 + if (strcmp(t->u.user.name,
9063 + IPT_ERROR_TARGET) == 0) {
9064 + *chainname = t->data;
9073 /* All zeroes == unconditional rule. */
9075 unconditional(const struct ipt_ip *ip)
9077 mark_source_chains(struct ipt_table_info *newinfo, unsigned int valid_hooks)
9080 + char *chainname = NULL;
9081 + u_int32_t rulenum;
9083 /* No recursion; use packet counter to save back ptrs (reset
9084 to 0 as we leave), and comefrom to save source hook bitmask */
9087 /* Set initial back pointer. */
9088 e->counters.pcnt = pos;
9090 + chainname = (char *) hooknames[hook];
9093 struct ipt_standard_target *t
9097 |= ((1 << hook) | (1 << NF_IP_NUMHOOKS));
9098 + e->rulenum = rulenum++;
9099 + e->chainname = chainname;
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;
9107 + /* Set unconditional rulenum to zero. */
9109 + e->counters.bcnt = 0;
9111 /* Return: backtrack through the last
9114 @@ -553,6 +599,11 @@
9115 (newinfo->entries + pos);
9116 } while (oldpos == pos + e->next_offset);
9118 + /* Restore chainname, rulenum. */
9119 + chainname = e->chainname;
9120 + rulenum = e->counters.bcnt;
9121 + e->counters.bcnt = 0;
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",
9130 + e->counters.bcnt = rulenum++;
9132 + e = (struct ipt_entry *)
9133 + (newinfo->entries + newpos);
9134 + if (IPT_ENTRY_ITERATE(newinfo->entries,
9136 + find_error_target,
9137 + e, &chainname) == 0) {
9138 + printk("ip_tables: table screwed up!\n");
9142 /* ... this is a fallthru */
9143 newpos = pos + e->next_offset;
9144 @@ -1713,9 +1775,9 @@
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)
9155 if ((*count)++ >= start_offset) {
9156 unsigned int namelen;
9157 @@ -1749,6 +1811,15 @@
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)
9165 + if (t == &ipt_standard_target || t == &ipt_error_target)
9167 + return print_name((char *)t, start_offset, buffer, length, pos, count);
9170 static int ipt_get_targets(char *buffer, char **start, off_t offset, int length)
9173 @@ -1757,7 +1828,7 @@
9174 if (down_interruptible(&ipt_mutex) != 0)
9177 - LIST_FIND(&ipt_target, print_name, void *,
9178 + LIST_FIND(&ipt_target, print_target, struct ipt_target *,
9179 offset, buffer, length, &pos, &count);
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
9186 +/* This kernel module is used to modify the connection mark values, or
9187 + * to optionally restore the skb nfmark from the connection mark
9189 + * Copyright (C) 2002,2004 MARA Systems AB <http://www.marasystems.com>
9190 + * by Henrik Nordstrom <hno@marasystems.com>
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.
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.
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
9206 +#include <linux/module.h>
9207 +#include <linux/skbuff.h>
9208 +#include <linux/ip.h>
9209 +#include <net/checksum.h>
9211 +MODULE_AUTHOR("Henrik Nordstrom <hno@marasytems.com>");
9212 +MODULE_DESCRIPTION("IP tables CONNMARK matching module");
9213 +MODULE_LICENSE("GPL");
9215 +#include <linux/netfilter_ipv4/ip_tables.h>
9216 +#include <linux/netfilter_ipv4/ipt_CONNMARK.h>
9217 +#include <linux/netfilter_ipv4/ip_conntrack.h>
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,
9227 + const struct ipt_connmark_target_info *markinfo = targinfo;
9228 + unsigned long diff;
9229 + unsigned long nfmark;
9230 + unsigned long newmark;
9232 + enum ip_conntrack_info ctinfo;
9233 + struct ip_conntrack *ct = ip_conntrack_get((*pskb), &ctinfo);
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;
9241 + case IPT_CONNMARK_SAVE:
9242 + newmark = (ct->mark & ~markinfo->mask) | ((*pskb)->nfmark & markinfo->mask);
9243 + if (ct->mark != newmark)
9244 + ct->mark = newmark;
9246 + case IPT_CONNMARK_RESTORE:
9247 + nfmark = (*pskb)->nfmark;
9248 + diff = (ct->mark ^ nfmark & markinfo->mask);
9250 + (*pskb)->nfmark = nfmark ^ diff;
9251 + (*pskb)->nfcache |= NFC_ALTERED;
9257 + return IPT_CONTINUE;
9261 +checkentry(const char *tablename,
9262 + const struct ipt_entry *e,
9264 + unsigned int targinfosize,
9265 + unsigned int hook_mask)
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",
9271 + IPT_ALIGN(sizeof(struct ipt_connmark_target_info)));
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);
9285 +static struct ipt_target ipt_connmark_reg = {
9286 + .name = "CONNMARK",
9287 + .target = &target,
9288 + .checkentry = &checkentry,
9292 +static int __init init(void)
9294 + return ipt_register_target(&ipt_connmark_reg);
9297 +static void __exit fini(void)
9299 + ipt_unregister_target(&ipt_connmark_reg);
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
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>
9314 +#include <linux/netfilter_ipv4/ip_tables.h>
9315 +#include <linux/netfilter_ipv4/ipt_IPMARK.h>
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");
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,
9329 + const struct ipt_ipmark_target_info *ipmarkinfo = targinfo;
9330 + struct iphdr *iph = (*pskb)->nh.iph;
9331 + unsigned long mark;
9333 + if (ipmarkinfo->addr == IPT_IPMARK_SRC)
9334 + mark = (unsigned long) ntohl(iph->saddr);
9336 + mark = (unsigned long) ntohl(iph->daddr);
9338 + mark &= ipmarkinfo->andmask;
9339 + mark |= ipmarkinfo->ormask;
9341 + if ((*pskb)->nfmark != mark) {
9342 + (*pskb)->nfmark = mark;
9343 + (*pskb)->nfcache |= NFC_ALTERED;
9345 + return IPT_CONTINUE;
9349 +checkentry(const char *tablename,
9350 + const struct ipt_entry *e,
9352 + unsigned int targinfosize,
9353 + unsigned int hook_mask)
9355 + if (targinfosize != IPT_ALIGN(sizeof(struct ipt_ipmark_target_info))) {
9356 + printk(KERN_WARNING "IPMARK: targinfosize %u != %Zu\n",
9358 + IPT_ALIGN(sizeof(struct ipt_ipmark_target_info)));
9362 + if (strcmp(tablename, "mangle") != 0) {
9363 + printk(KERN_WARNING "IPMARK: can only be called from \"mangle\" table, not \"%s\"\n", tablename);
9370 +static struct ipt_target ipt_ipmark_reg = {
9373 + .checkentry = checkentry,
9377 +static int __init init(void)
9379 + return ipt_register_target(&ipt_ipmark_reg);
9382 +static void __exit fini(void)
9384 + ipt_unregister_target(&ipt_ipmark_reg);
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
9394 + * Strip all IP options in the IP packet header.
9396 + * (C) 2001 by Fabrice MARIE <fabrice@netfilter.org>
9397 + * This software is distributed under GNU GPL v2, 1991
9400 +#include <linux/module.h>
9401 +#include <linux/skbuff.h>
9402 +#include <net/ip.h>
9403 +#include <net/checksum.h>
9405 +#include <linux/netfilter_ipv4/ip_tables.h>
9407 +MODULE_AUTHOR("Fabrice MARIE <fabrice@netfilter.org>");
9408 +MODULE_DESCRIPTION("Strip all options in IPv4 packets");
9409 +MODULE_LICENSE("GPL");
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,
9419 + struct iphdr *iph;
9420 + struct sk_buff *skb;
9421 + struct ip_options *opt;
9422 + unsigned char *optiph;
9425 + if (!skb_ip_make_writable(pskb, (*pskb)->len))
9429 + iph = (*pskb)->nh.iph;
9430 + optiph = skb->nh.raw;
9431 + l = ((struct ip_options *)(&(IPCB(skb)->opt)))->optlen;
9433 + /* if no options in packet then nothing to clear. */
9434 + if (iph->ihl * 4 == sizeof(struct iphdr))
9435 + return IPT_CONTINUE;
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);
9444 + skb->nfcache |= NFC_ALTERED;
9446 + return IPT_CONTINUE;
9450 +checkentry(const char *tablename,
9451 + const struct ipt_entry *e,
9453 + unsigned int targinfosize,
9454 + unsigned int hook_mask)
9456 + if (strcmp(tablename, "mangle")) {
9457 + printk(KERN_WARNING "IPV4OPTSSTRIP: can only be called from \"mangle\" table, not \"%s\"\n", tablename);
9460 + /* nothing else to check because no parameters */
9464 +static struct ipt_target ipt_ipv4optsstrip_reg = {
9465 + .name = "IPV4OPTSSTRIP",
9467 + .checkentry = checkentry,
9468 + .me = THIS_MODULE };
9470 +static int __init init(void)
9472 + return ipt_register_target(&ipt_ipv4optsstrip_reg);
9475 +static void __exit fini(void)
9477 + ipt_unregister_target(&ipt_ipv4optsstrip_reg);
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
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>
9500 +MODULE_AUTHOR("Gianni Tedesco <gianni@ecsc.co.uk>");
9501 +MODULE_DESCRIPTION("Provides iptables NETLINK target similar to ipchains -o");
9502 +MODULE_LICENSE("GPL");
9505 +#define DEBUGP printk
9507 +#define DEBUGP(format, args...)
9510 +static struct sock *ipfwsk;
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)
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;
9524 + /* Allocate a socket buffer */
9525 + if ( MASK(nld->flags, USE_SIZE) )
9526 + len = nld->size+sizeof(nlhdr);
9528 + len = ntohs(ip->tot_len)+sizeof(nlhdr);
9530 + outskb=alloc_skb(len, GFP_ATOMIC);
9535 + if ( MASK(nld->flags, USE_MARK) )
9536 + nlhdr.mark=(*pskb)->nfmark=nld->mark;
9538 + nlhdr.mark=(*pskb)->nfmark;
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);
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);
9551 + if (net_ratelimit())
9552 + printk(KERN_WARNING "ipt_NETLINK: packet drop due to netlink failure\n");
9555 + if ( MASK(nld->flags, USE_DROP) )
9558 + return IPT_CONTINUE;
9561 +static int ipt_netlink_checkentry(const char *tablename,
9562 + const struct ipt_entry *e,
9564 + unsigned int targinfosize,
9565 + unsigned int hookmask)
9567 + //struct ipt_nldata *nld = (struct ipt_nldata *)targinfo;
9572 +static struct ipt_target ipt_netlink_reg = {
9575 + ipt_netlink_target,
9576 + ipt_netlink_checkentry,
9581 +static int __init init(void)
9583 + DEBUGP("ipt_NETLINK: init module\n");
9585 + if (ipt_register_target(&ipt_netlink_reg) != 0) {
9589 + if ( !(ipfwsk=netlink_kernel_create(NETLINK_FIREWALL, NULL)) ){
9596 +static void __exit fini(void)
9598 + DEBUGP("ipt_NETLINK: cleanup_module\n");
9599 + ipt_unregister_target(&ipt_netlink_reg);
9600 + if(ipfwsk->sk_socket) sock_release(ipfwsk->sk_socket);
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
9609 +/* ipt_POOL.c - netfilter target to manipulate IP pools
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.
9616 + * The target normally returns IPT_CONTINUE.
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>
9634 +#define DEBUGP printk
9636 +#define DEBUGP(format, args...)
9639 +/*** NOTE NOTE NOTE NOTE ***
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.
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.
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.)
9657 +do_check(const char *tablename,
9658 + const struct ipt_entry *e,
9660 + unsigned int targinfosize,
9661 + unsigned int hook_mask)
9663 + const struct ipt_pool_info *ipi = targinfo;
9665 + if (targinfosize != IPT_ALIGN(sizeof(*ipi))) {
9666 + DEBUGP("POOL_check: size %u.\n", targinfosize);
9669 + DEBUGP("ipt_POOL:do_check(%d,%d,%d)\n",ipi->src,ipi->dst,ipi->flags);
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,
9681 + const struct ipt_pool_info *ipi = targinfo;
9683 + unsigned int verdict = IPT_CONTINUE;
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;
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;
9708 +static struct ipt_target pool_reg
9709 += { { NULL, NULL }, "POOL", do_target, do_check, NULL, THIS_MODULE };
9711 +static int __init init(void)
9713 + DEBUGP("init ipt_POOL\n");
9714 + return ipt_register_target(&pool_reg);
9717 +static void __exit fini(void)
9719 + DEBUGP("fini ipt_POOL\n");
9720 + ipt_unregister_target(&pool_reg);
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;
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;
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
9747 + * This implements the ROUTE target, which enables you to setup unusual
9748 + * routes not supported by the standard kernel routing table.
9750 + * Copyright (C) 2002 Cedric de Launois <delaunois@info.ucl.ac.be>
9752 + * v 1.9 2004/05/14
9754 + * This software is distributed under GNU GPL v2, 1991
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>
9770 +#define DEBUGP printk
9772 +#define DEBUGP(format, args...)
9775 +MODULE_LICENSE("GPL");
9776 +MODULE_AUTHOR("Cedric de Launois <delaunois@info.ucl.ac.be>");
9777 +MODULE_DESCRIPTION("iptables ROUTE target module");
9779 +/* Try to route the packet according to the routing keys specified in
9780 + * route_info. Keys are :
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
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
9796 +static int route(struct sk_buff *skb,
9797 + unsigned int ifindex,
9798 + const struct ipt_route_target_info *route_info)
9801 + struct rtable *rt;
9802 + struct iphdr *iph = skb->nh.iph;
9803 + struct flowi fl = {
9807 + .daddr = iph->daddr,
9809 + .tos = RT_TOS(iph->tos),
9810 + .scope = RT_SCOPE_UNIVERSE,
9815 + /* The destination address may be overloaded by the target */
9816 + if (route_info->gw)
9817 + fl.fld_dst = route_info->gw;
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);
9826 + /* Drop old route. */
9827 + dst_release(skb->dst);
9830 + /* Success if no oif specified or if the oif correspond to the
9832 + if (!ifindex || rt->u.dst.dev->ifindex == ifindex) {
9833 + skb->dst = &rt->u.dst;
9834 + skb->dev = skb->dst->dev;
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.
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);
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
9856 +static void ip_direct_send(struct sk_buff *skb)
9858 + struct dst_entry *dst = skb->dst;
9859 + struct hh_cache *hh = dst->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);
9870 + if (net_ratelimit())
9871 + DEBUGP(KERN_DEBUG "ipt_ROUTE: no hdr & no neighbour cache!\n");
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
9882 +static inline int dev_direct_send(struct sk_buff *skb)
9884 + return dev_queue_xmit(skb);
9888 +static unsigned int route_oif(const struct ipt_route_target_info *route_info,
9889 + struct sk_buff *skb)
9891 + unsigned int ifindex = 0;
9892 + struct net_device *dev_out = NULL;
9894 + /* The user set the interface name to use.
9895 + * Getting the current interface index.
9897 + if ((dev_out = dev_get_by_name(route_info->oif))) {
9898 + ifindex = dev_out->ifindex;
9900 + /* Unknown interface name : packet dropped */
9901 + if (net_ratelimit())
9902 + DEBUGP("ipt_ROUTE: oif interface %s not found\n", route_info->oif);
9906 + /* Trying the standard way of routing packets */
9907 + switch (route(skb, ifindex, route_info)) {
9910 + if (route_info->flags & IPT_ROUTE_CONTINUE)
9911 + return IPT_CONTINUE;
9913 + ip_direct_send(skb);
9917 + /* Failed to send to oif. Trying the hard way */
9918 + if (route_info->flags & IPT_ROUTE_CONTINUE)
9921 + if (net_ratelimit())
9922 + DEBUGP("ipt_ROUTE: forcing the use of %i\n",
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
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");
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.
9944 + skb->dev = dev_out;
9945 + dev_direct_send(skb);
9950 + /* Unexpected error */
9957 +static unsigned int route_iif(const struct ipt_route_target_info *route_info,
9958 + struct sk_buff *skb)
9960 + struct net_device *dev_in = NULL;
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);
9969 + skb->dev = dev_in;
9970 + dst_release(skb->dst);
9979 +static unsigned int route_gw(const struct ipt_route_target_info *route_info,
9980 + struct sk_buff *skb)
9982 + if (route(skb, 0, route_info)!=1)
9985 + if (route_info->flags & IPT_ROUTE_CONTINUE)
9986 + return IPT_CONTINUE;
9988 + ip_direct_send(skb);
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,
10000 + const struct ipt_route_target_info *route_info = targinfo;
10001 + struct sk_buff *skb = *pskb;
10003 + /* If we are at PREROUTING or INPUT hook
10004 + * the TTL isn't decreased by the IP stack
10006 + if (hooknum == NF_IP_PRE_ROUTING ||
10007 + hooknum == NF_IP_LOCAL_IN) {
10009 + struct iphdr *iph = skb->nh.iph;
10011 + if (iph->ttl <= 1) {
10012 + struct rtable *rt;
10013 + struct flowi fl = {
10017 + .daddr = iph->daddr,
10018 + .saddr = iph->saddr,
10019 + .tos = RT_TOS(iph->tos),
10020 + .scope = ((iph->tos & RTO_ONLINK) ?
10022 + RT_SCOPE_UNIVERSE)
10027 + if (ip_route_output_key(&rt, &fl)) {
10031 + if (skb->dev == rt->u.dst.dev) {
10032 + /* Drop old route. */
10033 + dst_release(skb->dst);
10034 + skb->dst = &rt->u.dst;
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);
10046 + * If we are at INPUT the checksum must be recalculated since
10047 + * the length could change as the result of a defragmentation.
10049 + if(hooknum == NF_IP_LOCAL_IN) {
10050 + iph->ttl = iph->ttl - 1;
10052 + iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);
10054 + ip_decrease_ttl(iph);
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.
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;
10071 + if (route_info->oif[0] != '\0')
10072 + return route_oif(route_info, *pskb);
10074 + if (route_info->iif[0] != '\0')
10075 + return route_iif(route_info, *pskb);
10077 + if (route_info->gw)
10078 + return route_gw(route_info, *pskb);
10080 + if (net_ratelimit())
10081 + DEBUGP(KERN_DEBUG "ipt_ROUTE: no parameter !\n");
10083 + return IPT_CONTINUE;
10087 +static int ipt_route_checkentry(const char *tablename,
10088 + const struct ipt_entry *e,
10090 + unsigned int targinfosize,
10091 + unsigned int hook_mask)
10093 + if (strcmp(tablename, "mangle") != 0) {
10094 + printk("ipt_ROUTE: bad table `%s', use the `mangle' table.\n",
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");
10108 + if (targinfosize != IPT_ALIGN(sizeof(struct ipt_route_target_info))) {
10109 + printk(KERN_WARNING "ipt_ROUTE: targinfosize %u != %Zu\n",
10111 + IPT_ALIGN(sizeof(struct ipt_route_target_info)));
10119 +static struct ipt_target ipt_route_reg = {
10121 + .target = ipt_route_target,
10122 + .checkentry = ipt_route_checkentry,
10123 + .me = THIS_MODULE,
10126 +static int __init init(void)
10128 + return ipt_register_target(&ipt_route_reg);
10132 +static void __exit fini(void)
10134 + ipt_unregister_target(&ipt_route_reg);
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
10144 + * Kernel module to capture and hold incoming TCP connections using
10145 + * no local per-connection resources.
10147 + * Based on ipt_REJECT.c and offering functionality similar to
10148 + * LaBrea <http://www.hackbusters.net/LaBrea/>.
10150 + * Copyright (c) 2002 Aaron Hopkins <tools@die.net>
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.
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.
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.
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.
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
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>
10188 +#include <net/route.h>
10189 +#include <linux/random.h>
10190 +#include <linux/netfilter_ipv4/ip_tables.h>
10193 +#define DEBUGP printk
10195 +#define DEBUGP(format, args...)
10198 +MODULE_LICENSE("GPL");
10199 +MODULE_AUTHOR("Aaron Hopkins <tools@die.net>");
10201 +/* Stolen from ip_finish_output2 */
10202 +static int ip_direct_send(struct sk_buff *skb)
10204 + struct dst_entry *dst = skb->dst;
10205 + struct hh_cache *hh = dst->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);
10216 + if (net_ratelimit())
10217 + printk(KERN_DEBUG "TARPIT ip_direct_send: no header cache and no neighbor!\n");
10224 +static void tarpit_tcp(struct sk_buff *oskb,struct rtable *ort,int local)
10226 + struct sk_buff *nskb;
10227 + struct rtable *nrt;
10228 + struct tcphdr *otcph, *ntcph;
10229 + struct flowi fl = {};
10230 + unsigned int otcplen;
10233 + /* A truncated TCP header isn't going to be useful */
10234 + if (oskb->len < (oskb->nh.iph->ihl*4) + sizeof(struct tcphdr))
10237 + otcph = (struct tcphdr *)((u_int32_t*)oskb->nh.iph
10238 + + oskb->nh.iph->ihl);
10239 + otcplen = oskb->len - oskb->nh.iph->ihl*4;
10241 + /* No replies for RST or FIN */
10242 + if (otcph->rst || otcph->fin)
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)))
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)
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);
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;
10270 + ntcph = (struct tcphdr *)((u_int32_t*)nskb->nh.iph + nskb->nh.iph->ihl);
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);
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;
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,
10290 + /* Our SYN-ACKs must have a >0 window */
10291 + ntcph->window = (otcph->syn && !otcph->ack) ? htons(5) : 0;
10293 + ntcph->urg_ptr = 0;
10295 + /* Reset flags */
10296 + ((u_int8_t *)ntcph)[13] = 0;
10298 + if (otcph->syn && otcph->ack) {
10300 + ntcph->ack_seq = 0;
10302 + ntcph->syn = otcph->syn;
10304 + ntcph->ack_seq = htonl(ntohl(otcph->seq) + otcph->syn);
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));
10315 + /* Adjust IP TTL */
10316 + nskb->nh.iph->ttl = sysctl_ip_default_ttl;
10318 + /* Set DF, id = 0 */
10319 + nskb->nh.iph->frag_off = htons(IP_DF);
10320 + nskb->nh.iph->id = 0;
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);
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;
10332 + if (ip_route_output_key(&nrt, &fl))
10335 + dst_release(nskb->dst);
10336 + nskb->dst = &nrt->u.dst;
10338 + /* "Never happens" */
10339 + if (nskb->len > dst_pmtu(nskb->dst))
10342 + ip_direct_send (nskb);
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,
10358 + struct sk_buff *skb = *pskb;
10359 + struct rtable *rt = (struct rtable*)skb->dst;
10361 + /* Do we have an input route cache entry? */
10365 + /* No replies to physical multicast/broadcast */
10366 + if (skb->pkt_type != PACKET_HOST && skb->pkt_type != PACKET_OTHERHOST)
10369 + /* Now check at the protocol level */
10370 + if (rt->rt_flags&(RTCF_BROADCAST|RTCF_MULTICAST))
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))
10378 + /* We aren't interested in fragments */
10379 + if (skb->nh.iph->frag_off & htons(IP_OFFSET))
10382 + tarpit_tcp(skb,rt,hooknum == NF_IP_LOCAL_IN);
10388 +static int check(const char *tablename,
10389 + const struct ipt_entry *e,
10391 + unsigned int targinfosize,
10392 + unsigned int hook_mask)
10394 + /* Only allow these for input/forward packet filtering. */
10395 + if (strcmp(tablename, "filter") != 0) {
10396 + DEBUGP("TARPIT: bad table %s'.\n", tablename);
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);
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");
10414 +static struct ipt_target ipt_tarpit_reg = {
10415 + .name = "TARPIT",
10416 + .target = tarpit,
10417 + .checkentry = check,
10418 + .me = THIS_MODULE
10421 +static int __init init(void)
10423 + return ipt_register_target(&ipt_tarpit_reg);
10426 +static void __exit fini(void)
10428 + ipt_unregister_target(&ipt_tarpit_reg);
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
10437 +/* This is a module which is used for setting
10438 + * the NFC_TRACE flag in the nfcache field of an skb.
10440 +#include <linux/module.h>
10441 +#include <linux/skbuff.h>
10443 +#include <linux/netfilter_ipv4/ip_tables.h>
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,
10453 + (*pskb)->nfcache |= NFC_TRACE;
10454 + return IPT_CONTINUE;
10458 +checkentry(const char *tablename,
10459 + const struct ipt_entry *e,
10461 + unsigned int targinfosize,
10462 + unsigned int hook_mask)
10464 + if (targinfosize != 0) {
10465 + printk(KERN_WARNING "TRACE: targinfosize %u != 0\n",
10470 + if (strcmp(tablename, "raw") != 0) {
10471 + printk(KERN_WARNING "TRACE: can only be called from \"raw\" table, not \"%s\"\n", tablename);
10478 +static struct ipt_target ipt_trace_reg = {
10480 + .target = target,
10481 + .checkentry = checkentry,
10482 + .me = THIS_MODULE
10485 +static int __init init(void)
10487 + if (ipt_register_target(&ipt_trace_reg))
10493 +static void __exit fini(void)
10495 + ipt_unregister_target(&ipt_trace_reg);
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
10505 +/* TTL modification target for IP tables
10506 + * (C) 2000 by Harald Welte <laforge@gnumonks.org>
10508 + * Version: $Revision$
10510 + * This software is distributed under the terms of GNU GPL
10513 +#include <linux/module.h>
10514 +#include <linux/skbuff.h>
10515 +#include <linux/ip.h>
10516 +#include <net/checksum.h>
10518 +#include <linux/netfilter_ipv4/ip_tables.h>
10519 +#include <linux/netfilter_ipv4/ipt_TTL.h>
10521 +MODULE_AUTHOR("Harald Welte <laforge@gnumonks.org>");
10522 +MODULE_DESCRIPTION("IP tables TTL modification module");
10523 +MODULE_LICENSE("GPL");
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)
10530 + struct iphdr *iph;
10531 + const struct ipt_TTL_info *info = targinfo;
10532 + u_int16_t diffs[2];
10535 + if (!skb_ip_make_writable(pskb, (*pskb)->len))
10538 + iph = (*pskb)->nh.iph;
10540 + switch (info->mode) {
10541 + case IPT_TTL_SET:
10542 + new_ttl = info->ttl;
10544 + case IPT_TTL_INC:
10545 + new_ttl = iph->ttl + info->ttl;
10546 + if (new_ttl > 255)
10549 + case IPT_TTL_DEC:
10550 + new_ttl = iph->ttl + info->ttl;
10555 + new_ttl = iph->ttl;
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,
10565 + iph->check^0xFFFF));
10566 + (*pskb)->nfcache |= NFC_ALTERED;
10569 + return IPT_CONTINUE;
10572 +static int ipt_ttl_checkentry(const char *tablename,
10573 + const struct ipt_entry *e,
10575 + unsigned int targinfosize,
10576 + unsigned int hook_mask)
10578 + struct ipt_TTL_info *info = targinfo;
10580 + if (targinfosize != IPT_ALIGN(sizeof(struct ipt_TTL_info))) {
10581 + printk(KERN_WARNING "TTL: targinfosize %u != %Zu\n",
10583 + IPT_ALIGN(sizeof(struct ipt_TTL_info)));
10587 + if (strcmp(tablename, "mangle")) {
10588 + printk(KERN_WARNING "TTL: can only be called from \"mangle\" table, not \"%s\"\n", tablename);
10592 + if (info->mode > IPT_TTL_MAXMODE) {
10593 + printk(KERN_WARNING "TTL: invalid or unknown Mode %u\n",
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");
10606 +static struct ipt_target ipt_TTL = {
10608 + .target = ipt_ttl_target,
10609 + .checkentry = ipt_ttl_checkentry,
10610 + .me = THIS_MODULE
10613 +static int __init init(void)
10615 + return ipt_register_target(&ipt_TTL);
10618 +static void __exit fini(void)
10620 + ipt_unregister_target(&ipt_TTL);
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
10629 +/* XOR target for IP tables
10630 + * (C) 2000 by Tim Vandermeersch <Tim.Vandermeersch@pandora.be>
10631 + * Based on ipt_TTL.c
10635 + * This software is distributed under the terms of GNU GPL
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>
10644 +#include <linux/netfilter_ipv4/ip_tables.h>
10645 +#include <linux/netfilter_ipv4/ipt_XOR.h>
10647 +MODULE_AUTHOR("Tim Vandermeersch <Tim.Vandermeersch@pandora.be>");
10648 +MODULE_DESCRIPTION("IP tables XOR module");
10649 +MODULE_LICENSE("GPL");
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)
10656 + struct ipt_XOR_info *info = (void *) targinfo;
10657 + struct iphdr *iph;
10658 + struct tcphdr *tcph;
10659 + struct udphdr *udph;
10662 + if (!skb_ip_make_writable(pskb, (*pskb)->len))
10665 + iph = (*pskb)->nh.iph;
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 ] ^=
10676 + if (info->key[j] == 0x00)
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 ] ^=
10688 + if (info->key[j] == 0x00)
10693 + return IPT_CONTINUE;
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)
10700 + struct ipt_XOR_info *info = targinfo;
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)));
10708 + if (strcmp(tablename, "mangle")) {
10709 + printk(KERN_WARNING "XOR: can only be called from"
10710 + "\"mangle\" table, not \"%s\"\n", tablename);
10714 + if (!strcmp(info->key, "")) {
10715 + printk(KERN_WARNING "XOR: You must specify a key");
10719 + if (info->block_size == 0) {
10720 + printk(KERN_WARNING "XOR: You must specify a block-size");
10727 +static struct ipt_target ipt_XOR = {
10729 + .target = ipt_xor_target,
10730 + .checkentry = ipt_xor_checkentry,
10731 + .me = THIS_MODULE,
10734 +static int __init init(void)
10736 + return ipt_register_target(&ipt_XOR);
10739 +static void __exit fini(void)
10741 + ipt_unregister_target(&ipt_XOR);
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
10751 + * iptables module to match inet_addr_type() of an ip.
10753 + * Copyright (c) 2004 Patrick McHardy <kaber@trash.net>
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.
10760 +#include <linux/module.h>
10761 +#include <linux/skbuff.h>
10762 +#include <linux/netdevice.h>
10763 +#include <net/route.h>
10765 +#include <linux/netfilter_ipv4/ipt_addrtype.h>
10766 +#include <linux/netfilter_ipv4/ip_tables.h>
10768 +MODULE_LICENSE("GPL");
10769 +MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
10770 +MODULE_DESCRIPTION("iptables addrtype match");
10772 +static inline int match_type(u_int32_t addr, u_int16_t mask)
10774 + return !!(mask & (1 << inet_addr_type(addr)));
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)
10781 + const struct ipt_addrtype_info *info = matchinfo;
10782 + const struct iphdr *iph = skb->nh.iph;
10785 + if (info->source)
10786 + ret &= match_type(iph->saddr, info->source)^info->invert_source;
10788 + ret &= match_type(iph->daddr, info->dest)^info->invert_dest;
10793 +static int checkentry(const char *tablename, const struct ipt_ip *ip,
10794 + void *matchinfo, unsigned int matchsize,
10795 + unsigned int hook_mask)
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)));
10806 +static struct ipt_match addrtype_match = {
10807 + .name = "addrtype",
10809 + .checkentry = checkentry,
10810 + .me = THIS_MODULE
10813 +static int __init init(void)
10815 + return ipt_register_match(&addrtype_match);
10818 +static void __exit fini(void)
10820 + ipt_unregister_match(&addrtype_match);
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
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
10838 + * Kernel module to match connection tracking information.
10839 + * GPL (C) 1999 Rusty Russell (rusty@rustcorp.com.au).
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>
10852 +MODULE_LICENSE("GPL");
10854 +/* we'll save the tuples of all connections we care about */
10855 +struct ipt_connlimit_conn
10857 + struct list_head list;
10858 + struct ip_conntrack_tuple tuple;
10861 +struct ipt_connlimit_data {
10863 + struct list_head iphash[256];
10866 +static int ipt_iphash(u_int32_t addr)
10870 + hash = addr & 0xff;
10871 + hash ^= (addr >> 8) & 0xff;
10872 + hash ^= (addr >> 16) & 0xff;
10873 + hash ^= (addr >> 24) & 0xff;
10877 +static int count_them(struct ipt_connlimit_data *data,
10878 + u_int32_t addr, u_int32_t mask,
10879 + struct ip_conntrack *ct)
10882 + const static char *tcp[] = { "none", "established", "syn_sent", "syn_recv",
10883 + "fin_wait", "time_wait", "close", "close_wait",
10884 + "last_ack", "listen" };
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;
10892 + spin_lock(&data->lock);
10893 + tuple = ct->tuplehash[0].tuple;
10894 + hash = &data->iphash[ipt_iphash(addr & mask)];
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)) &&
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" */
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");
10915 + if (NULL == found) {
10916 + /* this one is gone */
10918 + list_del(lh->next);
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 */
10926 + list_del(lh->next);
10928 + nf_conntrack_put(&found->ctrack->infos[0]);
10931 + if ((addr & mask) == (conn->tuple.src.ip & mask)) {
10932 + /* same source IP address -> be counted! */
10935 + nf_conntrack_put(&found->ctrack->infos[0]);
10938 + /* save the new connection in our list */
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));
10945 + conn = kmalloc(sizeof(*conn),GFP_ATOMIC);
10946 + if (NULL == conn)
10948 + memset(conn,0,sizeof(*conn));
10949 + INIT_LIST_HEAD(&conn->list);
10950 + conn->tuple = tuple;
10951 + list_add(&conn->list,hash);
10954 + spin_unlock(&data->lock);
10959 +match(const struct sk_buff *skb,
10960 + const struct net_device *in,
10961 + const struct net_device *out,
10962 + const void *matchinfo,
10966 + const struct ipt_connlimit_info *info = matchinfo;
10967 + int connections, match;
10968 + struct ip_conntrack *ct;
10969 + enum ip_conntrack_info ctinfo;
10971 + ct = ip_conntrack_get((struct sk_buff *)skb, &ctinfo);
10972 + if (NULL == ct) {
10973 + printk("ipt_connlimit: Oops: invalid ct state ?\n");
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 :-) */
10983 + match = (info->inverse) ? (connections <= info->limit) : (connections > info->limit);
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");
10994 +static int check(const char *tablename,
10995 + const struct ipt_ip *ip,
10997 + unsigned int matchsize,
10998 + unsigned int hook_mask)
11000 + struct ipt_connlimit_info *info = matchinfo;
11003 + /* verify size */
11004 + if (matchsize != IPT_ALIGN(sizeof(struct ipt_connlimit_info)))
11007 + /* refuse anything but tcp */
11008 + if (ip->proto != IPPROTO_TCP)
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]));
11020 +static void destroy(void *matchinfo, unsigned int matchinfosize)
11022 + struct ipt_connlimit_info *info = matchinfo;
11023 + struct ipt_connlimit_conn *conn;
11024 + struct list_head *hash;
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);
11036 + kfree(info->data);
11039 +static struct ipt_match connlimit_match = {
11040 + .name = "connlimit",
11042 + .checkentry = &check,
11043 + .destroy = &destroy,
11044 + .me = THIS_MODULE
11047 +static int __init init(void)
11049 + return ipt_register_match(&connlimit_match);
11052 +static void __exit fini(void)
11054 + ipt_unregister_match(&connlimit_match);
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
11063 +/* This kernel module matches connection mark values set by the
11064 + * CONNMARK target
11066 + * Copyright (C) 2002,2004 MARA Systems AB <http://www.marasystems.com>
11067 + * by Henrik Nordstrom <hno@marasystems.com>
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.
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.
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
11084 +#include <linux/module.h>
11085 +#include <linux/skbuff.h>
11087 +MODULE_AUTHOR("Henrik Nordstrom <hno@marasytems.com>");
11088 +MODULE_DESCRIPTION("IP tables connmark match module");
11089 +MODULE_LICENSE("GPL");
11091 +#include <linux/netfilter_ipv4/ip_tables.h>
11092 +#include <linux/netfilter_ipv4/ipt_connmark.h>
11093 +#include <linux/netfilter_ipv4/ip_conntrack.h>
11096 +match(const struct sk_buff *skb,
11097 + const struct net_device *in,
11098 + const struct net_device *out,
11099 + const void *matchinfo,
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);
11109 + return ((ct->mark & info->mask) == info->mark) ^ info->invert;
11113 +checkentry(const char *tablename,
11114 + const struct ipt_ip *ip,
11116 + unsigned int matchsize,
11117 + unsigned int hook_mask)
11119 + if (matchsize != IPT_ALIGN(sizeof(struct ipt_connmark_info)))
11125 +static struct ipt_match connmark_match = {
11126 + .name = "connmark",
11128 + .checkentry = &checkentry,
11129 + .me = THIS_MODULE
11132 +static int __init init(void)
11134 + return ipt_register_match(&connmark_match);
11137 +static void __exit fini(void)
11139 + ipt_unregister_match(&connmark_match);
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
11148 +/* iptables match extension to limit the number of packets per second
11149 + * seperately for each destination.
11151 + * (C) 2003 by Harald Welte <laforge@netfilter.org>
11155 + * Development of this code was funded by Astaro AG, http://www.astaro.com/
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>
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.
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 ;)
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>
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>
11188 +#include <linux/netfilter_ipv4/ip_tables.h>
11189 +#include <linux/netfilter_ipv4/ipt_dstlimit.h>
11191 +/* FIXME: this is just for IP_NF_ASSERRT */
11192 +#include <linux/netfilter_ipv4/ip_conntrack.h>
11194 +#define MS2JIFFIES(x) ((x*HZ)/1000)
11196 +MODULE_LICENSE("GPL");
11197 +MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>");
11198 +MODULE_DESCRIPTION("iptables match for limiting per destination");
11200 +/* need to declare this at the top */
11201 +static struct proc_dir_entry *dstlimit_procdir;
11202 +static struct file_operations dl_file_ops;
11204 +/* hash table crap */
11206 +struct dsthash_dst {
11207 + u_int32_t src_ip;
11208 + u_int32_t dst_ip;
11212 +struct dsthash_ent {
11213 + /* static / read-only parts in the beginning */
11214 + struct list_head list;
11215 + struct dsthash_dst dst;
11217 + /* modified structure members in the end */
11218 + unsigned long expires; /* precalculated expiry time */
11220 + unsigned long prev; /* last modification */
11221 + u_int32_t credit;
11222 + u_int32_t credit_cap, cost;
11226 +struct ipt_dstlimit_htable {
11227 + struct list_head list; /* global list of all htables */
11230 + struct dstlimit_cfg cfg; /* config */
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 */
11238 + /* seq_file stuff */
11239 + struct proc_dir_entry *pde;
11241 + struct list_head hash[0]; /* hashtable itself */
11244 +DECLARE_RWLOCK(dstlimit_lock); /* protects htables list */
11245 +static LIST_HEAD(dstlimit_htables);
11246 +static kmem_cache_t *dstlimit_cachep;
11248 +static inline int dst_cmp(const struct dsthash_ent *ent, struct dsthash_dst *b)
11250 + return (ent->dst.dst_ip == b->dst_ip
11251 + && ent->dst.port == b->port
11252 + && ent->dst.src_ip == b->src_ip);
11255 +static inline u_int32_t
11256 +hash_dst(const struct ipt_dstlimit_htable *ht, const struct dsthash_dst *dst)
11258 + return (jhash_3words(dst->dst_ip, dst->port,
11259 + dst->src_ip, ht->rnd) % ht->cfg.size);
11262 +static inline struct dsthash_ent *
11263 +__dsthash_find(const struct ipt_dstlimit_htable *ht, struct dsthash_dst *dst)
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);
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)
11276 + struct dsthash_ent *ent;
11278 + /* initialize hash with random val at the time we allocate
11279 + * the first hashtable entry */
11281 + get_random_bytes(&ht->rnd, 4);
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",
11293 + ent = kmem_cache_alloc(dstlimit_cachep, GFP_ATOMIC);
11295 + if (net_ratelimit())
11297 + "ipt_dstlimit: can't allocate dsthash_ent\n");
11301 + atomic_inc(&ht->count);
11303 + ent->dst.dst_ip = dst->dst_ip;
11304 + ent->dst.port = dst->port;
11305 + ent->dst.src_ip = dst->src_ip;
11307 + list_add(&ent->list, &ht->hash[hash_dst(ht, dst)]);
11312 +static inline void
11313 +__dsthash_free(struct ipt_dstlimit_htable *ht, struct dsthash_ent *ent)
11315 + MUST_BE_LOCKED(&ht->lock);
11317 + list_del(&ent->list);
11318 + kmem_cache_free(dstlimit_cachep, ent);
11319 + atomic_dec(&ht->count);
11321 +static void htable_gc(unsigned long htlong);
11323 +static int htable_create(struct ipt_dstlimit_info *minfo)
11326 + unsigned int size;
11327 + struct ipt_dstlimit_htable *hinfo;
11329 + if (minfo->cfg.size)
11330 + size = minfo->cfg.size;
11332 + size = (((num_physpages << PAGE_SHIFT) / 16384)
11333 + / sizeof(struct list_head));
11334 + if (num_physpages > (1024 * 1024 * 1024 / PAGE_SIZE))
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));
11343 + printk(KERN_ERR "ipt_dstlimit: Unable to create hashtable\n");
11346 + minfo->hinfo = hinfo;
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;
11356 + for (i = 0; i < hinfo->cfg.size; i++)
11357 + INIT_LIST_HEAD(&hinfo->hash[i]);
11359 + atomic_set(&hinfo->count, 0);
11360 + atomic_set(&hinfo->use, 1);
11362 + hinfo->lock = SPIN_LOCK_UNLOCKED;
11363 + hinfo->pde = create_proc_entry(minfo->name, 0, dstlimit_procdir);
11364 + if (!hinfo->pde) {
11368 + hinfo->pde->proc_fops = &dl_file_ops;
11369 + hinfo->pde->data = hinfo;
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);
11377 + WRITE_LOCK(&dstlimit_lock);
11378 + list_add(&hinfo->list, &dstlimit_htables);
11379 + WRITE_UNLOCK(&dstlimit_lock);
11384 +static int select_all(struct ipt_dstlimit_htable *ht, struct dsthash_ent *he)
11389 +static int select_gc(struct ipt_dstlimit_htable *ht, struct dsthash_ent *he)
11391 + return (jiffies >= he->expires);
11394 +static void htable_selective_cleanup(struct ipt_dstlimit_htable *ht,
11395 + int (*select)(struct ipt_dstlimit_htable *ht,
11396 + struct dsthash_ent *he))
11400 + IP_NF_ASSERT(ht->cfg.size && ht->cfg.max);
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);
11411 + UNLOCK_BH(&ht->lock);
11414 +/* hash table garbage collector, run by timer */
11415 +static void htable_gc(unsigned long htlong)
11417 + struct ipt_dstlimit_htable *ht = (struct ipt_dstlimit_htable *)htlong;
11419 + htable_selective_cleanup(ht, select_gc);
11421 + /* re-add the timer accordingly */
11422 + ht->timer.expires = jiffies + MS2JIFFIES(ht->cfg.gc_interval);
11423 + add_timer(&ht->timer);
11426 +static void htable_destroy(struct ipt_dstlimit_htable *hinfo)
11428 + /* remove timer, if it is pending */
11429 + if (timer_pending(&hinfo->timer))
11430 + del_timer(&hinfo->timer);
11432 + /* remove proc entry */
11433 + remove_proc_entry(hinfo->pde->name, dstlimit_procdir);
11435 + htable_selective_cleanup(hinfo, select_all);
11439 +static struct ipt_dstlimit_htable *htable_find_get(char *name)
11441 + struct ipt_dstlimit_htable *hinfo;
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);
11451 + READ_UNLOCK(&dstlimit_lock);
11456 +static void htable_put(struct ipt_dstlimit_htable *hinfo)
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);
11467 +/* The algorithm used is the Simple Token Bucket Filter (TBF)
11468 + * see net/sched/sch_tbf.c in the linux source tree
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
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.
11482 + See Alexey's formal explanation in net/sched/sch_tbf.c.
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.
11489 +#define MAX_CPJ (0xFFFFFFFF / (HZ*60*60*24))
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
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)
11501 +#define CREDITS_PER_JIFFY POW2_BELOW32(MAX_CPJ)
11503 +/* Precision saver. */
11504 +static inline u_int32_t
11505 +user2credits(u_int32_t user)
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;
11512 + return (user * HZ * CREDITS_PER_JIFFY) / IPT_DSTLIMIT_SCALE;
11515 +static inline void rateinfo_recalc(struct dsthash_ent *dh, unsigned long now)
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;
11524 +dstlimit_match(const struct sk_buff *skb,
11525 + const struct net_device *in,
11526 + const struct net_device *out,
11527 + const void *matchinfo,
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;
11538 + memset(&dst, 0, sizeof(dst));
11540 + /* dest ip is always in hash */
11541 + dst.dst_ip = skb->nh.iph->daddr;
11543 + /* source ip only if respective hashmode, otherwise set to
11545 + if (hinfo->cfg.mode & IPT_DSTLIMIT_HASH_SIP)
11546 + dst.src_ip = skb->nh.iph->saddr;
11548 + /* dest port only if respective mode */
11549 + if (hinfo->cfg.mode & IPT_DSTLIMIT_HASH_DPT) {
11552 + /* Must not be a fragment. */
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. */
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;
11572 + case IPPROTO_UDP:
11573 + uh = (void *)skb->nh.iph+skb->nh.iph->ihl*4;
11574 + dst.port = uh->dest;
11581 + LOCK_BH(&hinfo->lock);
11582 + dh = __dsthash_find(hinfo, &dst);
11584 + dh = __dsthash_alloc_init(hinfo, &dst);
11587 + /* enomem... don't match == DROP */
11588 + if (net_ratelimit())
11589 + printk(KERN_ERR "%s: ENOMEM\n", __FUNCTION__);
11590 + UNLOCK_BH(&hinfo->lock);
11594 + dh->expires = jiffies + MS2JIFFIES(hinfo->cfg.expire);
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);
11603 + UNLOCK_BH(&hinfo->lock);
11607 + /* update expiration timeout */
11608 + dh->expires = now + MS2JIFFIES(hinfo->cfg.expire);
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);
11618 + UNLOCK_BH(&hinfo->lock);
11620 + /* default case: we're overlimit, thus don't match */
11625 +dstlimit_checkentry(const char *tablename,
11626 + const struct ipt_ip *ip,
11628 + unsigned int matchsize,
11629 + unsigned int hook_mask)
11631 + struct ipt_dstlimit_info *r = matchinfo;
11633 + if (matchsize != IPT_ALIGN(sizeof(struct ipt_dstlimit_info)))
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);
11645 + if (r->cfg.mode == 0
11646 + || r->cfg.mode > (IPT_DSTLIMIT_HASH_DPT
11647 + |IPT_DSTLIMIT_HASH_DIP
11648 + |IPT_DSTLIMIT_HASH_SIP))
11651 + if (!r->cfg.gc_interval)
11654 + if (!r->cfg.expire)
11657 + r->hinfo = htable_find_get(r->name);
11658 + if (!r->hinfo && (htable_create(r) != 0)) {
11662 + /* Ugly hack: For SMP, we only want to use one set */
11669 +dstlimit_destroy(void *matchinfo, unsigned int matchsize)
11671 + struct ipt_dstlimit_info *r = (struct ipt_dstlimit_info *) matchinfo;
11673 + htable_put(r->hinfo);
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
11687 +static void *dl_seq_start(struct seq_file *s, loff_t *pos)
11689 + struct proc_dir_entry *pde = s->private;
11690 + struct ipt_dstlimit_htable *htable = pde->data;
11691 + unsigned int *bucket;
11693 + LOCK_BH(&htable->lock);
11694 + if (*pos >= htable->cfg.size)
11697 + bucket = kmalloc(sizeof(unsigned int), GFP_KERNEL);
11699 + return ERR_PTR(-ENOMEM);
11705 +static void *dl_seq_next(struct seq_file *s, void *v, loff_t *pos)
11707 + struct proc_dir_entry *pde = s->private;
11708 + struct ipt_dstlimit_htable *htable = pde->data;
11709 + unsigned int *bucket = (unsigned int *)v;
11711 + *pos = ++(*bucket);
11712 + if (*pos >= htable->cfg.size) {
11719 +static void dl_seq_stop(struct seq_file *s, void *v)
11721 + struct proc_dir_entry *pde = s->private;
11722 + struct ipt_dstlimit_htable *htable = pde->data;
11723 + unsigned int *bucket = (unsigned int *)v;
11727 + UNLOCK_BH(&htable->lock);
11730 +static inline int dl_seq_real_show(struct dsthash_ent *ent, struct seq_file *s)
11732 + /* recalculate to show accurate numbers */
11733 + rateinfo_recalc(ent, jiffies);
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);
11743 +static int dl_seq_show(struct seq_file *s, void *v)
11745 + struct proc_dir_entry *pde = s->private;
11746 + struct ipt_dstlimit_htable *htable = pde->data;
11747 + unsigned int *bucket = (unsigned int *)v;
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 */
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
11764 +static int dl_proc_open(struct inode *inode, struct file *file)
11766 + int ret = seq_open(file, &dl_seq_ops);
11769 + struct seq_file *sf = file->private_data;
11770 + sf->private = PDE(inode);
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
11783 +static int init_or_fini(int fini)
11790 + if (ipt_register_match(&ipt_dstlimit)) {
11792 + goto cleanup_nothing;
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");
11803 + goto cleanup_unreg_match;
11806 + dstlimit_procdir = proc_mkdir("ipt_dstlimit", proc_net);
11807 + if (!dstlimit_procdir) {
11808 + printk(KERN_ERR "Unable to create proc dir entry\n");
11810 + goto cleanup_free_slab;
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);
11826 +static int __init init(void)
11828 + return init_or_fini(0);
11831 +static void __exit fini(void)
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
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 .
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 .
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>
11870 + Packet Acceptance Rate - LOW and Packet Acceptance Rate - HIGH
11871 + Expressed in percentage
11874 +#define PAR_LOW 1/100
11875 +#define PAR_HIGH 1
11877 +static spinlock_t fuzzy_lock = SPIN_LOCK_UNLOCKED ;
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");
11883 +static u_int8_t mf_high(u_int32_t tx,u_int32_t mini,u_int32_t maxi)
11891 + return ( (100*(tx-mini)) / (maxi-mini) );
11894 +static u_int8_t mf_low(u_int32_t tx,u_int32_t mini,u_int32_t maxi)
11902 + return ( (100*( maxi - tx )) / ( maxi - mini ) );
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,
11913 + /* From userspace */
11915 + struct ipt_fuzzy_info *info = (struct ipt_fuzzy_info *) matchinfo;
11917 + u_int8_t random_number;
11918 + unsigned long amount;
11919 + u_int8_t howhigh, howlow;
11922 + spin_lock_bh(&fuzzy_lock); /* Rise the lock */
11924 + info->bytes_total += pskb->len;
11925 + info->packets_total++;
11927 + info->present_time = jiffies;
11929 + if (info->present_time >= info->previous_time)
11930 + amount = info->present_time - info->previous_time;
11932 + /* There was a transition : I choose to re-sample
11933 + and keep the old acceptance rate...
11937 + info->previous_time = info->present_time;
11938 + info->bytes_total = info->packets_total = 0;
11941 + if (amount > HZ/10) /* More than 100 ms elapsed ... */
11944 + info->mean_rate = (u_int32_t) ((HZ*info->packets_total) \
11947 + info->previous_time = info->present_time;
11948 + info->bytes_total = info->packets_total = 0;
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);
11953 + info->acceptance_rate = (u_int8_t) \
11954 + (howhigh*PAR_LOW + PAR_HIGH*howlow);
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 ,
11965 + spin_unlock_bh(&fuzzy_lock); /* Release the lock */
11968 + if ( info->acceptance_rate < 100 )
11970 + get_random_bytes((void *)(&random_number), 1);
11972 + /* If within the acceptance , it can pass => don't match */
11973 + if (random_number <= (255 * info->acceptance_rate) / 100)
11976 + return 1; /* It can't pass ( It matches ) */
11979 + return 0; /* acceptance_rate == 100 % => Everything passes ... */
11984 +ipt_fuzzy_checkentry(const char *tablename,
11985 + const struct ipt_ip *e,
11987 + unsigned int matchsize,
11988 + unsigned int hook_mask)
11991 + const struct ipt_fuzzy_info *info = matchinfo;
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)));
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");
12008 +static struct ipt_match ipt_fuzzy_reg = {
12010 + .match = ipt_fuzzy_match,
12011 + .checkentry = ipt_fuzzy_checkentry,
12012 + .me = THIS_MODULE
12015 +static int __init init(void)
12017 + return ipt_register_match(&ipt_fuzzy_reg);
12020 +static void __exit fini(void)
12022 + ipt_unregister_match(&ipt_fuzzy_reg);
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;
12035 + int ret = info->invert;
12037 ct = ip_conntrack_get((struct sk_buff *)skb, &ctinfo);
12039 DEBUGP("ipt_helper: Eek! invalid conntrack?\n");
12045 DEBUGP("ipt_helper: conntrack %p has no master\n", ct);
12052 DEBUGP("master's name = %s , info->name = %s\n",
12053 exp->expectant->helper->name, info->name);
12055 - ret = !strncmp(exp->expectant->helper->name, info->name,
12056 - strlen(exp->expectant->helper->name)) ^ info->invert;
12057 + if (info->name[0] == '\0')
12060 + ret ^= !strncmp(exp->expectant->helper->name, info->name,
12061 + strlen(exp->expectant->helper->name));
12063 READ_UNLOCK(&ip_conntrack_lock);
12066 if (matchsize != IPT_ALIGN(sizeof(struct ipt_helper_info)))
12069 - /* verify that we actually should match anything */
12070 - if ( strlen(info->name) == 0 )
12076 @@ -108,7 +107,6 @@
12078 static int __init init(void)
12080 - need_ip_conntrack();
12081 return ipt_register_match(&helper_match);
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
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
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
12101 +#include <linux/module.h>
12102 +#include <linux/skbuff.h>
12103 +#include <net/ip.h>
12105 +#include <linux/netfilter_ipv4/ip_tables.h>
12106 +#include <linux/netfilter_ipv4/ipt_ipv4options.h>
12108 +MODULE_LICENSE("GPL");
12109 +MODULE_AUTHOR("Fabrice Marie <fabrice@netfilter.org>");
12112 +match(const struct sk_buff *skb,
12113 + const struct net_device *in,
12114 + const struct net_device *out,
12115 + const void *matchinfo,
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;
12123 + if (iph->ihl * 4 == sizeof(struct iphdr)) {
12124 + /* No options, so we match only the "DONTs" and the "IGNOREs" */
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))
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 */
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 ! */
12146 + opt = &(IPCB(skb)->opt);
12148 + /* source routing */
12149 + if ((info->options & IPT_IPV4OPTION_MATCH_SSRR) == IPT_IPV4OPTION_MATCH_SSRR) {
12150 + if (!((opt->srr) & (opt->is_strictroute)))
12153 + else if ((info->options & IPT_IPV4OPTION_MATCH_LSRR) == IPT_IPV4OPTION_MATCH_LSRR) {
12154 + if (!((opt->srr) & (!opt->is_strictroute)))
12157 + else if ((info->options & IPT_IPV4OPTION_DONT_MATCH_SRR) == IPT_IPV4OPTION_DONT_MATCH_SRR) {
12161 + /* record route */
12162 + if ((info->options & IPT_IPV4OPTION_MATCH_RR) == IPT_IPV4OPTION_MATCH_RR) {
12166 + else if ((info->options & IPT_IPV4OPTION_DONT_MATCH_RR) == IPT_IPV4OPTION_DONT_MATCH_RR) {
12171 + if ((info->options & IPT_IPV4OPTION_MATCH_TIMESTAMP) == IPT_IPV4OPTION_MATCH_TIMESTAMP) {
12175 + else if ((info->options & IPT_IPV4OPTION_DONT_MATCH_TIMESTAMP) == IPT_IPV4OPTION_DONT_MATCH_TIMESTAMP) {
12179 + /* router-alert option */
12180 + if ((info->options & IPT_IPV4OPTION_MATCH_ROUTER_ALERT) == IPT_IPV4OPTION_MATCH_ROUTER_ALERT) {
12181 + if (!opt->router_alert)
12184 + else if ((info->options & IPT_IPV4OPTION_DONT_MATCH_ROUTER_ALERT) == IPT_IPV4OPTION_DONT_MATCH_ROUTER_ALERT) {
12185 + if (opt->router_alert)
12194 +checkentry(const char *tablename,
12195 + const struct ipt_ip *ip,
12197 + unsigned int matchsize,
12198 + unsigned int hook_mask)
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)))
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 */
12237 + /* everything looks ok. */
12241 +static struct ipt_match ipv4options_match = {
12242 + .name = "ipv4options",
12244 + .checkentry = checkentry,
12245 + .me = THIS_MODULE
12248 +static int __init init(void)
12250 + return ipt_register_match(&ipv4options_match);
12253 +static void __exit fini(void)
12255 + ipt_unregister_match(&ipv4options_match);
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
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>
12271 +#include <linux/netfilter_ipv4/ipt_mport.h>
12272 +#include <linux/netfilter_ipv4/ip_tables.h>
12274 +MODULE_LICENSE("GPL");
12277 +#define duprintf(format, args...) printk(format , ## args)
12279 +#define duprintf(format, args...)
12282 +/* Returns 1 if the port is matched by the test, 0 otherwise. */
12284 +ports_match(const struct ipt_mport *minfo, u_int16_t src, u_int16_t dst)
12288 + u_int16_t pflags = minfo->pflags;
12289 + for (i=0, m=1; i<IPT_MULTI_PORTS; i++, m<<=1) {
12293 + && minfo->ports[i] == 65535)
12296 + s = minfo->ports[i];
12298 + if (pflags & m) {
12299 + e = minfo->ports[++i];
12304 + if (minfo->flags & IPT_MPORT_SOURCE
12305 + && src >= s && src <= e)
12308 + if (minfo->flags & IPT_MPORT_DESTINATION
12309 + && dst >= s && dst <= e)
12317 +match(const struct sk_buff *skb,
12318 + const struct net_device *in,
12319 + const struct net_device *out,
12320 + const void *matchinfo,
12325 + const struct ipt_mport *minfo = matchinfo;
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");
12341 + return ports_match(minfo, ntohs(ports[0]), ntohs(ports[1]));
12344 +/* Called when user tries to insert an entry of this type. */
12346 +checkentry(const char *tablename,
12347 + const struct ipt_ip *ip,
12349 + unsigned int matchsize,
12350 + unsigned int hook_mask)
12352 + if (matchsize != IPT_ALIGN(sizeof(struct ipt_mport)))
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));
12361 +static struct ipt_match mport_match = {
12364 + .checkentry = &checkentry,
12365 + .me = THIS_MODULE
12368 +static int __init init(void)
12370 + return ipt_register_match(&mport_match);
12373 +static void __exit fini(void)
12375 + ipt_unregister_match(&mport_match);
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
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
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>
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>
12408 +MODULE_LICENSE("GPL");
12409 +MODULE_AUTHOR("Fabrice Marie <fabrice@netfilter.org>");
12412 + * State information.
12416 + u_int16_t number;
12419 +static struct state states[IPT_NTH_NUM_COUNTERS];
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,
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))
12434 + printk(KERN_WARNING "nth: invalid counter %u. counter between 0 and %u\n", counter, IPT_NTH_NUM_COUNTERS-1);
12438 + spin_lock(&states[counter].lock);
12440 + /* Are we matching every nth packet?*/
12441 + if (info->packet == 0xFF)
12443 + /* We're matching every nth packet and only every nth packet*/
12444 + /* Do we match or invert match? */
12445 + if (info->not == 0)
12447 + if (states[counter].number == 0)
12449 + ++states[counter].number;
12452 + if (states[counter].number >= info->every)
12453 + states[counter].number = 0; /* reset the counter */
12455 + ++states[counter].number;
12460 + if (states[counter].number == 0)
12462 + ++states[counter].number;
12465 + if (states[counter].number >= info->every)
12466 + states[counter].number = 0;
12468 + ++states[counter].number;
12474 + /* We're using the --packet, so there must be a rule for every value */
12475 + if (states[counter].number == info->packet)
12477 + /* only increment the counter when a match happens */
12478 + if (states[counter].number >= info->every)
12479 + states[counter].number = 0; /* reset the counter */
12481 + ++states[counter].number;
12489 + /* don't match */
12490 + spin_unlock(&states[counter].lock);
12494 + spin_unlock(&states[counter].lock);
12499 +ipt_nth_checkentry(const char *tablename,
12500 + const struct ipt_ip *e,
12502 + unsigned int matchsize,
12503 + unsigned int hook_mask)
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))
12510 + printk(KERN_WARNING "nth: invalid counter %u. counter between 0 and %u\n", counter, IPT_NTH_NUM_COUNTERS-1);
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)));
12520 + states[counter].number = info->startat;
12525 +static struct ipt_match ipt_nth_reg = {
12527 + .match = ipt_nth_match,
12528 + .checkentry = ipt_nth_checkentry,
12529 + .me = THIS_MODULE
12532 +static int __init init(void)
12534 + unsigned counter;
12536 + memset(&states, 0, sizeof(states));
12537 + for (counter = 0; counter < IPT_NTH_NUM_COUNTERS; counter++)
12538 + spin_lock_init(&(states[counter].lock));
12540 + return ipt_register_match(&ipt_nth_reg);
12543 +static void __exit fini(void)
12545 + ipt_unregister_match(&ipt_nth_reg);
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
12557 + * Copyright (c) 2003 Evgeniy Polyakov <johnpol@2ka.mipt.ru>
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.
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.
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
12576 + * OS fingerprint matching module.
12577 + * It simply compares various parameters from SYN packet with
12578 + * some hardcoded ones.
12580 + * Original table was created by Michal Zalewski <lcamtuf@coredump.cx>
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>
12601 +#include <net/sock.h>
12602 +#include <net/ip.h>
12604 +#include <linux/netfilter_ipv4/ip_tables.h>
12606 +#include <linux/netfilter_ipv4/ipt_osf.h>
12611 +#define log(x...) printk(KERN_INFO "ipt_osf: " x)
12612 +#define loga(x...) printk(x)
12614 +#define log(x...) do {} while(0)
12615 +#define loga(x...) do {} while(0)
12618 +#define FMATCH_WRONG 0
12619 +#define FMATCH_OK 1
12620 +#define FMATCH_OPT_WRONG 2
12622 +#define OPTDEL ','
12623 +#define OSFPDEL ':'
12624 +#define MAXOPTSTRLEN 128
12625 +#define OSFFLUSH "FLUSH"
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,
12634 +static int checkentry(const char *, const struct ipt_ip *, void *,
12635 + unsigned int, unsigned int);
12637 +static unsigned long seq, ipt_osf_groups = 1;
12638 +static struct sock *nts;
12640 +static struct ipt_match osf_match =
12650 +static void ipt_osf_nlsend(struct osf_finger *f, const struct sk_buff *sk)
12652 + unsigned int size;
12653 + struct sk_buff *skb;
12654 + struct ipt_osf_nlmsg *data;
12655 + struct nlmsghdr *nlh;
12657 + size = NLMSG_SPACE(sizeof(struct ipt_osf_nlmsg));
12659 + skb = alloc_skb(size, GFP_ATOMIC);
12662 + log("skb_alloc() failed.\n");
12666 + nlh = NLMSG_PUT(skb, 0, seq++, NLMSG_DONE, size - sizeof(*nlh));
12668 + data = (struct ipt_osf_nlmsg *)NLMSG_DATA(nlh);
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));
12674 + NETLINK_CB(skb).dst_groups = ipt_osf_groups;
12675 + netlink_broadcast(nts, skb, 0, ipt_osf_groups, GFP_ATOMIC);
12681 +static inline int smart_dec(const struct sk_buff *skb, unsigned long flags, unsigned char f_ttl)
12683 + struct iphdr *ip = skb->nh.iph;
12685 + if (flags & IPT_OSF_SMART)
12687 + struct in_device *in_dev = in_dev_get(skb->dev);
12691 + if (inet_ifa_match(ip->saddr, ifa))
12693 + in_dev_put(in_dev);
12694 + return (ip->ttl == f_ttl);
12697 + endfor_ifa(in_dev);
12699 + in_dev_put(in_dev);
12700 + return (ip->ttl <= f_ttl);
12703 + return (ip->ttl == f_ttl);
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,
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;
12722 + if (!ip || !info)
12725 + tcp = (struct tcphdr *)((u_int32_t *)ip + ip->ihl);
12730 + totlen = ntohs(ip->tot_len);
12731 + df = ((ntohs(ip->frag_off) & IP_DF)?1:0);
12732 + window = ntohs(tcp->window);
12734 + if (tcp->doff*4 > sizeof(struct tcphdr))
12736 + _optp = optp = (char *)(tcp+1);
12737 + optsize = tcp->doff*4 - sizeof(struct tcphdr);
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.
12745 + read_lock(&osf_lock);
12746 + list_for_each(ent, &finger_list)
12748 + f = list_entry(ent, struct osf_finger, flist);
12750 + if (!(info->flags & IPT_OSF_LOG) && strcmp(info->genre, f->genre))
12754 + fmatch = FMATCH_WRONG;
12756 + if (totlen == f->ss && df == f->df &&
12757 + smart_dec(skb, info->flags, f->ttl))
12759 + unsigned long foptsize;
12761 + unsigned short mss = 0;
12765 + switch (f->wss.wc)
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);
12776 + if (check_WSS == 4)
12779 + /* Check options */
12782 + for (optnum=0; optnum<f->opt_num; ++optnum)
12783 + foptsize += f->opt[optnum].length;
12786 + if (foptsize > MAX_IPOPTLEN || optsize > MAX_IPOPTLEN || optsize != foptsize)
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)
12801 + for (optnum=0; optnum<f->opt_num; ++optnum)
12803 + if (f->opt[optnum].kind == (*optp))
12805 + unsigned char len = f->opt[optnum].length;
12806 + unsigned char *optend = optp + len;
12807 + int loop_cont = 0;
12809 + fmatch = FMATCH_OK;
12815 + mss = ntohs(*(unsigned short *)(optp+2));
12830 + /* Skip kind and length fields*/
12833 + if (f->opt[optnum].wc.val != 0)
12835 + unsigned long tmp = 0;
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) */
12844 + tmp = ntohs(tmp);
12846 + tmp = ntohl(tmp);
12848 + if (f->opt[optnum].wc.wc == '%')
12850 + if ((tmp % f->opt[optnum].wc.val) != 0)
12851 + fmatch = FMATCH_OPT_WRONG;
12853 + else if (tmp != f->opt[optnum].wc.val)
12854 + fmatch = FMATCH_OPT_WRONG;
12861 + fmatch = FMATCH_OPT_WRONG;
12863 + if (fmatch != FMATCH_OK)
12867 + if (fmatch != FMATCH_OPT_WRONG)
12869 + fmatch = FMATCH_WRONG;
12871 + switch (check_WSS)
12874 + if (f->wss.val == 0 || window == f->wss.val)
12875 + fmatch = FMATCH_OK;
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;
12884 + case 2: /* MTU */
12885 + if (window == f->wss.val*(mss+40) ||
12886 + window == f->wss.val*(SMART_MSS+40))
12887 + fmatch = FMATCH_OK;
12889 + case 3: /* MOD */
12890 + if ((window % f->wss.val) == 0)
12891 + fmatch = FMATCH_OK;
12897 + if (fmatch == FMATCH_OK)
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)
12908 + spin_lock_bh(&ipt_osf_netlink_lock);
12909 + ipt_osf_nlsend(f, skb);
12910 + spin_unlock_bh(&ipt_osf_netlink_lock);
12912 + if ((info->flags & IPT_OSF_LOG) &&
12913 + info->loglevel == IPT_OSF_LOGLEVEL_FIRST)
12918 + if (!fcount && (info->flags & (IPT_OSF_LOG | IPT_OSF_NETLINK)))
12920 + unsigned char opt[4 * 15 - sizeof(struct tcphdr)];
12921 + unsigned int i, optsize;
12922 + struct osf_finger fg;
12924 + memset(&fg, 0, sizeof(fg));
12926 + if ((info->flags & IPT_OSF_LOG))
12927 + log("Unknown: %lu:%d:%d:%lu:", window, ip->ttl, df, totlen);
12930 + optsize = tcp->doff * 4 - sizeof(struct tcphdr);
12931 + if (skb_copy_bits(skb, ip->ihl*4 + sizeof(struct tcphdr),
12932 + opt, optsize) < 0)
12934 + if (info->flags & IPT_OSF_LOG)
12935 + loga("TRUNCATED");
12936 + if (info->flags & IPT_OSF_NETLINK)
12937 + strcpy(fg.details, "TRUNCATED");
12941 + for (i = 0; i < optsize; i++)
12943 + if (info->flags & IPT_OSF_LOG)
12944 + loga("%02X", opt[i]);
12946 + if (info->flags & IPT_OSF_NETLINK)
12947 + memcpy(fg.details, opt, MAXDETLEN);
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));
12955 + if (info->flags & IPT_OSF_NETLINK)
12957 + fg.wss.val = window;
12958 + fg.ttl = ip->ttl;
12961 + strncpy(fg.genre, "Unknown", MAXGENRELEN);
12963 + spin_lock_bh(&ipt_osf_netlink_lock);
12964 + ipt_osf_nlsend(&fg, skb);
12965 + spin_unlock_bh(&ipt_osf_netlink_lock);
12969 + read_unlock(&osf_lock);
12971 + return (fmatch == FMATCH_OK)?1:0;
12975 +checkentry(const char *tablename,
12976 + const struct ipt_ip *ip,
12978 + unsigned int matchsize,
12979 + unsigned int hook_mask)
12981 + if (matchsize != IPT_ALIGN(sizeof(struct ipt_osf_info)))
12983 + if (ip->proto != IPPROTO_TCP)
12989 +static char * osf_strchr(char *ptr, char c)
12993 + tmp = strchr(ptr, c);
12995 + while (tmp && tmp+1 && isspace(*(tmp+1)))
13001 +static struct osf_finger * finger_alloc(void)
13003 + struct osf_finger *f;
13005 + f = kmalloc(sizeof(struct osf_finger), GFP_KERNEL);
13007 + memset(f, 0, sizeof(struct osf_finger));
13012 +static void finger_free(struct osf_finger *f)
13014 + memset(f, 0, sizeof(struct osf_finger));
13019 +static void osf_parse_opt(struct osf_opt *opt, int *optnum, char *obuf, int olen)
13023 + unsigned long val;
13027 + while (ptr != NULL && i < olen)
13036 + ptr = osf_strchr(&obuf[i], OPTDEL);
13041 + i += (int)(ptr-&obuf[i]);
13048 + op = OSFOPT_SACKP;
13049 + ptr = osf_strchr(&obuf[i], OPTDEL);
13054 + i += (int)(ptr-&obuf[i]);
13062 + ptr = osf_strchr(&obuf[i], OPTDEL);
13067 + i += (int)(ptr-&obuf[i]);
13075 + ptr = osf_strchr(&obuf[i], OPTDEL);
13078 + switch (obuf[i+1])
13080 + case '%': wc = '%'; break;
13081 + case 'S': wc = 'S'; break;
13082 + case 'T': wc = 'T'; break;
13083 + default: wc = 0; break;
13089 + val = simple_strtoul(&obuf[i+2], NULL, 10);
13091 + val = simple_strtoul(&obuf[i+1], NULL, 10);
13092 + i += (int)(ptr-&obuf[i]);
13100 + ptr = osf_strchr(&obuf[i], OPTDEL);
13103 + if (obuf[i+1] == '%')
13108 + val = simple_strtoul(&obuf[i+2], NULL, 10);
13110 + val = simple_strtoul(&obuf[i+1], NULL, 10);
13111 + i += (int)(ptr-&obuf[i]);
13119 + ptr = osf_strchr(&obuf[i], OPTDEL);
13124 + i += (int)(ptr-&obuf[i]);
13131 + ptr = osf_strchr(&obuf[i], OPTDEL);
13135 + i += (int)(ptr-&obuf[i]);
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;
13152 +static int osf_proc_read(char *buf, char **start, off_t off, int count, int *eof, void *data)
13154 + struct list_head *ent;
13155 + struct osf_finger *f = NULL;
13161 + read_lock_bh(&osf_lock);
13162 + list_for_each(ent, &finger_list)
13164 + f = list_entry(ent, struct osf_finger, flist);
13166 + log("%s [%s]", f->genre, f->details);
13168 + count += sprintf(buf+count, "%s - %s[%s] : %s",
13169 + f->genre, f->version,
13170 + f->subtype, f->details);
13175 + //count += sprintf(buf+count, " OPT: ");
13176 + for (i=0; i<f->opt_num; ++i)
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);
13185 + count += sprintf(buf+count, "\n");
13187 + read_unlock_bh(&osf_lock);
13192 +static int osf_proc_write(struct file *file, const char *buffer, unsigned long count, void *data)
13196 + char obuf[MAXOPTSTRLEN];
13197 + struct osf_finger *finger;
13198 + struct list_head *ent, *n;
13200 + char *pbeg, *pend;
13202 + if (count == strlen(OSFFLUSH) && !strncmp(buffer, OSFFLUSH, strlen(OSFFLUSH)))
13205 + write_lock_bh(&osf_lock);
13206 + list_for_each_safe(ent, n, &finger_list)
13209 + finger = list_entry(ent, struct osf_finger, flist);
13210 + list_del(&finger->flist);
13211 + finger_free(finger);
13213 + write_unlock_bh(&osf_lock);
13215 + log("Flushed %d entries.\n", i);
13222 + for (i=0; i<count && buffer[i] != '\0'; ++i)
13223 + if (buffer[i] == ':')
13226 + if (cnt != 8 || i != count)
13228 + log("Wrong input line cnt=%d[8], len=%lu[%lu]\n",
13233 + memset(obuf, 0, sizeof(obuf));
13235 + finger = finger_alloc();
13238 + log("Failed to allocate new fingerprint entry.\n");
13242 + pbeg = (char *)buffer;
13243 + pend = osf_strchr(pbeg, OSFPDEL);
13247 + if (pbeg[0] == 'S')
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;
13255 + finger->wss.val = simple_strtoul(pbeg+1, NULL, 10);
13257 + else if (pbeg[0] == 'T')
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;
13265 + finger->wss.val = simple_strtoul(pbeg+1, NULL, 10);
13267 + else if (pbeg[0] == '%')
13269 + finger->wss.wc = '%';
13270 + finger->wss.val = simple_strtoul(pbeg+1, NULL, 10);
13272 + else if (isdigit(pbeg[0]))
13274 + finger->wss.wc = 0;
13275 + finger->wss.val = simple_strtoul(pbeg, NULL, 10);
13280 + pend = osf_strchr(pbeg, OSFPDEL);
13284 + finger->ttl = simple_strtoul(pbeg, NULL, 10);
13287 + pend = osf_strchr(pbeg, OSFPDEL);
13291 + finger->df = simple_strtoul(pbeg, NULL, 10);
13294 + pend = osf_strchr(pbeg, OSFPDEL);
13298 + finger->ss = simple_strtoul(pbeg, NULL, 10);
13302 + pend = osf_strchr(pbeg, OSFPDEL);
13306 + cnt = snprintf(obuf, sizeof(obuf), "%s", pbeg);
13310 + pend = osf_strchr(pbeg, OSFPDEL);
13314 + if (pbeg[0] == '@' || pbeg[0] == '*')
13315 + cnt = snprintf(finger->genre, sizeof(finger->genre), "%s", pbeg+1);
13317 + cnt = snprintf(finger->genre, sizeof(finger->genre), "%s", pbeg);
13321 + pend = osf_strchr(pbeg, OSFPDEL);
13325 + cnt = snprintf(finger->version, sizeof(finger->version), "%s", pbeg);
13329 + pend = osf_strchr(pbeg, OSFPDEL);
13333 + cnt = snprintf(finger->subtype, sizeof(finger->subtype), "%s", pbeg);
13337 + cnt = snprintf(finger->details,
13338 + ((count - (pbeg - buffer)+1) > MAXDETLEN)?MAXDETLEN:(count - (pbeg - buffer)+1),
13341 + log("%s - %s[%s] : %s\n",
13342 + finger->genre, finger->version,
13343 + finger->subtype, finger->details);
13345 + osf_parse_opt(finger->opt, &finger->opt_num, obuf, sizeof(obuf));
13348 + write_lock_bh(&osf_lock);
13349 + list_add_tail(&finger->flist, &finger_list);
13350 + write_unlock_bh(&osf_lock);
13355 +static int __init osf_init(void)
13358 + struct proc_dir_entry *p;
13360 + log("Startng OS fingerprint matching module.\n");
13362 + INIT_LIST_HEAD(&finger_list);
13364 + err = ipt_register_match(&osf_match);
13367 + log("Failed to register OS fingerprint matching module.\n");
13371 + p = create_proc_entry("sys/net/ipv4/osf", S_IFREG | 0644, NULL);
13374 + ipt_unregister_match(&osf_match);
13378 + p->write_proc = osf_proc_write;
13379 + p->read_proc = osf_proc_read;
13381 + nts = netlink_kernel_create(NETLINK_NFLOG, NULL);
13384 + log("netlink_kernel_create() failed\n");
13385 + remove_proc_entry("sys/net/ipv4/osf", NULL);
13386 + ipt_unregister_match(&osf_match);
13393 +static void __exit osf_fini(void)
13395 + struct list_head *ent, *n;
13396 + struct osf_finger *f;
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);
13403 + list_for_each_safe(ent, n, &finger_list)
13405 + f = list_entry(ent, struct osf_finger, flist);
13406 + list_del(&f->flist);
13410 + log("OS fingerprint matching module finished.\n");
13413 +module_init(osf_init);
13414 +module_exit(osf_fini);
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
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.
13427 + * 03/26/2003 Patrick McHardy <kaber@trash.net> : LOCAL_IN support
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>
13440 #include <linux/netfilter_ipv4/ipt_owner.h>
13441 #include <linux/netfilter_ipv4/ip_tables.h>
13443 MODULE_DESCRIPTION("iptables owner match");
13446 -match_comm(const struct sk_buff *skb, const char *comm)
13447 +match_comm(const struct sock *sk, const char *comm)
13449 struct task_struct *g, *p;
13450 struct files_struct *files;
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);
13459 read_unlock(&tasklist_lock);
13464 -match_pid(const struct sk_buff *skb, pid_t pid)
13465 +match_pid(const struct sock *sk, pid_t pid)
13467 struct task_struct *p;
13468 struct files_struct *files;
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);
13477 read_unlock(&tasklist_lock);
13478 @@ -86,10 +93,10 @@
13482 -match_sid(const struct sk_buff *skb, pid_t sid)
13483 +match_sid(const struct sock *sk, pid_t sid)
13485 struct task_struct *g, *p;
13486 - struct file *file = skb->sk->sk_socket->file;
13487 + struct file *file = sk->sk_socket->file;
13490 read_lock(&tasklist_lock);
13491 @@ -129,41 +136,71 @@
13494 const struct ipt_owner_info *info = matchinfo;
13495 + struct iphdr *iph = skb->nh.iph;
13496 + struct sock *sk = NULL;
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);
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);
13520 - if (!skb->sk || !skb->sk->sk_socket || !skb->sk->sk_socket->file)
13522 + if (!sk || !sk->sk_socket || !sk->sk_socket->file)
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))
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))
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))
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))
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))
13576 @@ -173,11 +210,19 @@
13577 unsigned int matchsize,
13578 unsigned int 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");
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");
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");
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
13605 +/* IP tables module for matching IPsec policy
13607 + * Copyright (c) 2004 Patrick McHardy, <kaber@trash.net>
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.
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>
13621 +#include <linux/netfilter_ipv4.h>
13622 +#include <linux/netfilter_ipv4/ipt_policy.h>
13623 +#include <linux/netfilter_ipv4/ip_tables.h>
13625 +MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
13626 +MODULE_DESCRIPTION("IPtables IPsec policy matching module");
13627 +MODULE_LICENSE("GPL");
13631 +match_xfrm_state(struct xfrm_state *x, const struct ipt_policy_elem *e)
13633 +#define MISMATCH(x,y) (e->match.x && ((e->x != (y)) ^ e->invert.x))
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))
13646 +match_policy_in(const struct sk_buff *skb, const struct ipt_policy_info *info)
13648 + const struct ipt_policy_elem *e;
13649 + struct sec_path *sp = skb->sp;
13650 + int strict = info->flags & POLICY_MATCH_STRICT;
13655 + if (strict && info->len != sp->len)
13658 + for (i = sp->len - 1; i >= 0; i--) {
13659 + pos = strict ? i - sp->len + 1 : 0;
13660 + if (pos >= info->len)
13662 + e = &info->pol[pos];
13664 + if (match_xfrm_state(sp->x[i].xvec, e)) {
13667 + } else if (strict)
13671 + return strict ? 1 : 0;
13675 +match_policy_out(const struct sk_buff *skb, const struct ipt_policy_info *info)
13677 + const struct ipt_policy_elem *e;
13678 + struct dst_entry *dst = skb->dst;
13679 + int strict = info->flags & POLICY_MATCH_STRICT;
13682 + if (dst->xfrm == NULL)
13685 + for (i = 0; dst && dst->xfrm; dst = dst->child, i++) {
13686 + pos = strict ? i : 0;
13687 + if (pos >= info->len)
13689 + e = &info->pol[pos];
13691 + if (match_xfrm_state(dst->xfrm, e)) {
13694 + } else if (strict)
13698 + return strict ? 1 : 0;
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)
13706 + const struct ipt_policy_info *info = matchinfo;
13709 + if (info->flags & POLICY_MATCH_IN)
13710 + ret = match_policy_in(skb, info);
13712 + ret = match_policy_out(skb, info);
13715 + if (info->flags & POLICY_MATCH_NONE)
13719 + } else if (info->flags & POLICY_MATCH_NONE)
13725 +static int checkentry(const char *tablename, const struct ipt_ip *ip,
13726 + void *matchinfo, unsigned int matchsize,
13727 + unsigned int hook_mask)
13729 + struct ipt_policy_info *info = matchinfo;
13731 + if (matchsize != IPT_ALIGN(sizeof(*info))) {
13732 + printk(KERN_ERR "ipt_policy: matchsize %u != %u\n",
13733 + matchsize, IPT_ALIGN(sizeof(*info)));
13736 + if (!(info->flags & (POLICY_MATCH_IN|POLICY_MATCH_OUT))) {
13737 + printk(KERN_ERR "ipt_policy: neither incoming nor "
13738 + "outgoing policy selected\n");
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");
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");
13753 + if (info->len > POLICY_MAX_ELEM) {
13754 + printk(KERN_ERR "ipt_policy: too many policy elements\n");
13761 +static struct ipt_match policy_match =
13763 + .name = "policy",
13765 + .checkentry = checkentry,
13766 + .me = THIS_MODULE,
13769 +static int __init init(void)
13771 + return ipt_register_match(&policy_match);
13774 +static void __exit fini(void)
13776 + ipt_unregister_match(&policy_match);
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
13785 +/* Kernel module to match an IP address pool. */
13787 +#include <linux/module.h>
13788 +#include <linux/ip.h>
13789 +#include <linux/skbuff.h>
13791 +#include <linux/netfilter_ipv4/ip_tables.h>
13792 +#include <linux/netfilter_ipv4/ip_pool.h>
13793 +#include <linux/netfilter_ipv4/ipt_pool.h>
13795 +static inline int match_pool(
13800 + if (ip_pool_match(index, ntohl(addr)))
13806 + const struct sk_buff *skb,
13807 + const struct net_device *in,
13808 + const struct net_device *out,
13809 + const void *matchinfo,
13812 + u_int16_t datalen,
13815 + const struct ipt_pool_info *info = matchinfo;
13816 + const struct iphdr *iph = skb->nh.iph;
13818 + if (info->src != IP_POOL_NONE && !match_pool(info->src, iph->saddr,
13819 + info->flags&IPT_POOL_INV_SRC))
13822 + if (info->dst != IP_POOL_NONE && !match_pool(info->dst, iph->daddr,
13823 + info->flags&IPT_POOL_INV_DST))
13829 +static int checkentry(
13830 + const char *tablename,
13831 + const struct ipt_ip *ip,
13833 + unsigned int matchsize,
13834 + unsigned int hook_mask
13836 + if (matchsize != IPT_ALIGN(sizeof(struct ipt_pool_info)))
13841 +static struct ipt_match pool_match
13842 += { { NULL, NULL }, "pool", &match, &checkentry, NULL, THIS_MODULE };
13844 +static int __init init(void)
13846 + return ipt_register_match(&pool_match);
13849 +static void __exit fini(void)
13851 + ipt_unregister_match(&pool_match);
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
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.
13865 + Copyright (C) 2000,2001 astaro AG
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
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
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>
13888 +#define DEBUGP printk
13890 +#define DEBUGP(format, args...)
13893 +MODULE_LICENSE("GPL");
13894 +MODULE_AUTHOR("Dennis Koslowski <koslowski@astaro.com>");
13896 +#define HF_DADDR_CHANGING 0x01
13897 +#define HF_SPORT_CHANGING 0x02
13898 +#define HF_TOS_CHANGING 0x04
13899 +#define HF_TTL_CHANGING 0x08
13902 + * Information we keep per each target 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 */
13912 + * Information we keep per each source address.
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 */
13929 + * State information.
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 */
13939 + * Convert an IP address into a hash table index.
13941 +static inline int hashfunc(struct in_addr addr)
13943 + unsigned int value;
13946 + value = addr.s_addr;
13950 + } while ((value >>= HASH_LOG));
13952 + return hash & (HASH_SIZE - 1);
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,
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;
13969 + struct host *curr, *last, **head;
13970 + int hash, index, count;
13972 + /* Parameters from userspace */
13973 + const struct ipt_psd_info *psdinfo = matchinfo;
13976 + ip_hdr = pskb->nh.iph;
13978 + /* Sanity check */
13979 + if (ntohs(ip_hdr->frag_off) & IP_OFFSET) {
13980 + DEBUGP("PSD: sanity check failed\n");
13984 + /* TCP or UDP ? */
13985 + proto = ip_hdr->protocol;
13987 + if (proto != IPPROTO_TCP && proto != IPPROTO_UDP) {
13988 + DEBUGP("PSD: protocol not supported\n");
13992 + /* Get the source address, source & destination ports, and TCP flags */
13994 + addr.s_addr = ip_hdr->saddr;
13996 + tcp_hdr = (struct tcphdr*)((u_int32_t *)ip_hdr + ip_hdr->ihl);
13998 + /* Yep, it´s dirty */
13999 + src_port = tcp_hdr->source;
14000 + dest_port = tcp_hdr->dest;
14002 + if (proto == IPPROTO_TCP) {
14003 + tcp_flags = *((u_int8_t*)tcp_hdr + 13);
14006 + tcp_flags = 0x00;
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");
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. */
14020 + spin_lock(&state.lock);
14022 + /* Do we know this source address already? */
14025 + if ((curr = *(head = &state.hash[hash = hashfunc(addr)])))
14027 + if (curr->src_addr.s_addr == addr.s_addr) break;
14029 + if (curr->next) last = curr;
14030 + } while ((curr = curr->next));
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)) {
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;
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;
14052 + /* Packet to a new port, and not TCP/ACK: update the timestamp */
14053 + curr->timestamp = now;
14055 + /* Logged this scan already? Then drop the packet. */
14056 + if (curr->weight >= psdinfo->weight_threshold)
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;
14069 + /* Update the total weight */
14070 + curr->weight += (ntohs(dest_port) < 1024) ?
14071 + psdinfo->lo_ports_weight : psdinfo->hi_ports_weight;
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)
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;
14087 + goto out_no_match;
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;
14095 + last->next = last->next->next;
14097 + *head = (*head)->next;
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;
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;
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). */
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)];
14120 + if ((curr = *head))
14122 + if (curr == &state.list[state.index]) break;
14124 + } while ((curr = curr->next));
14126 + /* Then, remove it */
14129 + last->next = last->next->next;
14131 + *head = (*head)->next;
14134 + /* Get our list entry */
14135 + curr = &state.list[state.index++];
14136 + if (state.index >= LIST_SIZE) state.index = 0;
14138 + /* Link it into the hash table */
14139 + head = &state.hash[hash];
14140 + curr->next = *head;
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;
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;
14159 + spin_unlock(&state.lock);
14163 + spin_unlock(&state.lock);
14167 +static int ipt_psd_checkentry(const char *tablename,
14168 + const struct ipt_ip *e,
14170 + unsigned int matchsize,
14171 + unsigned int hook_mask)
14173 +/* const struct ipt_psd_info *psdinfo = targinfo;*/
14175 + /* we accept TCP only */
14176 +/* if (e->ip.proto != IPPROTO_TCP) { */
14177 +/* DEBUGP("PSD: specified protocol may be TCP only\n"); */
14181 + if (matchsize != IPT_ALIGN(sizeof(struct ipt_psd_info))) {
14182 + DEBUGP("PSD: matchsize %u != %u\n",
14184 + IPT_ALIGN(sizeof(struct ipt_psd_info)));
14191 +static struct ipt_match ipt_psd_reg = {
14193 + .match = ipt_psd_match,
14194 + .checkentry = ipt_psd_checkentry,
14195 + .me = THIS_MODULE };
14197 +static int __init init(void)
14199 + if (ipt_register_match(&ipt_psd_reg))
14202 + memset(&state, 0, sizeof(state));
14204 + spin_lock_init(&(state.lock));
14206 + printk("netfilter PSD loaded - (c) astaro AG\n");
14210 +static void __exit fini(void)
14212 + ipt_unregister_match(&ipt_psd_reg);
14213 + printk("netfilter PSD unloaded - (c) astaro AG\n");
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
14223 + * netfilter module to enforce network quotas
14225 + * Sam Johnston <samj@samj.net>
14227 +#include <linux/module.h>
14228 +#include <linux/skbuff.h>
14229 +#include <linux/spinlock.h>
14230 +#include <linux/interrupt.h>
14232 +#include <linux/netfilter_ipv4/ip_tables.h>
14233 +#include <linux/netfilter_ipv4/ipt_quota.h>
14235 +MODULE_LICENSE("GPL");
14236 +MODULE_AUTHOR("Sam Johnston <samj@samj.net>");
14238 +static spinlock_t quota_lock = SPIN_LOCK_UNLOCKED;
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)
14247 + struct ipt_quota_info *q = (struct ipt_quota_info *) matchinfo;
14248 + unsigned int datalen;
14250 + if (skb->len < sizeof(struct iphdr))
14251 + return NF_ACCEPT;
14253 + datalen = skb->len - skb->nh.iph->ihl*4;
14255 + spin_lock_bh("a_lock);
14257 + if (q->quota >= datalen) {
14258 + /* we can afford this one */
14259 + q->quota -= datalen;
14260 + spin_unlock_bh("a_lock);
14262 +#ifdef DEBUG_IPT_QUOTA
14263 + printk("IPT Quota OK: %llu datlen %d \n", q->quota, datalen);
14268 + /* so we do not allow even small packets from now on */
14271 +#ifdef DEBUG_IPT_QUOTA
14272 + printk("IPT Quota Failed: %llu datlen %d \n", q->quota, datalen);
14275 + spin_unlock_bh("a_lock);
14280 +checkentry(const char *tablename,
14281 + const struct ipt_ip *ip,
14282 + void *matchinfo, unsigned int matchsize, unsigned int hook_mask)
14284 + /* TODO: spinlocks? sanity checks? */
14285 + if (matchsize != IPT_ALIGN(sizeof (struct ipt_quota_info)))
14291 +static struct ipt_match quota_match = {
14294 + .checkentry = checkentry,
14295 + .me = THIS_MODULE
14301 + return ipt_register_match("a_match);
14304 +static void __exit
14307 + ipt_unregister_match("a_match);
14310 +module_init(init);
14311 +module_exit(fini);
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
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
14323 + 2001-10-14 Fabrice MARIE <fabrice@netfilter.org> : initial implementation.
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>
14335 +MODULE_LICENSE("GPL");
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,
14344 + u_int16_t datalen,
14347 + /* Parameters from userspace */
14348 + const struct ipt_rand_info *info = matchinfo;
14349 + u_int8_t random_number;
14351 + /* get 1 random number from the kernel random number generation routine */
14352 + get_random_bytes((void *)(&random_number), 1);
14354 + /* Do we match ? */
14355 + if (random_number <= info->average)
14362 +ipt_rand_checkentry(const char *tablename,
14363 + const struct ipt_ip *e,
14365 + unsigned int matchsize,
14366 + unsigned int hook_mask)
14368 + /* Parameters from userspace */
14369 + const struct ipt_rand_info *info = matchinfo;
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)));
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);
14388 +static struct ipt_match ipt_rand_reg = {
14392 + ipt_rand_checkentry,
14396 +static int __init init(void)
14398 + if (ipt_register_match(&ipt_rand_reg))
14401 + printk("ipt_random match loaded\n");
14405 +static void __exit fini(void)
14407 + ipt_unregister_match(&ipt_rand_reg);
14408 + printk("ipt_random match unloaded\n");
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
14417 +/* IP tables module for matching the routing realm
14421 + * (C) 2003 by Sampsa Ranta <sampsa@netsonic.fi>
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.
14428 +#include <linux/module.h>
14429 +#include <linux/skbuff.h>
14430 +#include <linux/netdevice.h>
14431 +#include <net/route.h>
14433 +#include <linux/netfilter_ipv4/ipt_realm.h>
14434 +#include <linux/netfilter_ipv4/ip_tables.h>
14436 +MODULE_AUTHOR("Sampsa Ranta <sampsa@netsonic.fi>");
14437 +MODULE_LICENSE("GPL");
14440 +match(const struct sk_buff *skb,
14441 + const struct net_device *in,
14442 + const struct net_device *out,
14443 + const void *matchinfo,
14447 + const struct ipt_realm_info *info = matchinfo;
14448 + struct dst_entry *dst = skb->dst;
14453 + return (info->id == (dst->tclassid & info->mask)) ^ info->invert;
14456 +static int check(const char *tablename,
14457 + const struct ipt_ip *ip,
14459 + unsigned int matchsize,
14460 + unsigned int 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");
14470 + if (matchsize != IPT_ALIGN(sizeof(struct ipt_realm_info)))
14476 +static struct ipt_match realm_match = {
14479 + .checkentry = check,
14480 + .me = THIS_MODULE
14483 +static int __init init(void)
14485 + return ipt_register_match(&realm_match);
14488 +static void __exit fini(void)
14490 + ipt_unregister_match(&realm_match);
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
14499 +#include <linux/module.h>
14500 +#include <linux/skbuff.h>
14501 +#include <net/ip.h>
14502 +#include <linux/sctp.h>
14504 +#include <linux/netfilter_ipv4/ip_tables.h>
14505 +#include <linux/netfilter_ipv4/ipt_sctp.h>
14508 +#define duprintf(format, args...) printk(format , ## args)
14510 +#define duprintf(format, args...)
14513 +#define SCCHECK(cond, option, flag, invflag) (!((flag) & (option)) \
14514 + || (!!((invflag) & (option)) ^ (cond)))
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)
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;
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,
14542 + u_int32_t chunkmapcopy[256 / sizeof (u_int32_t)];
14543 + sctp_chunkhdr_t sch;
14547 + if (chunk_match_type == SCTP_CHUNK_MATCH_ALL) {
14548 + SCTP_CHUNKMAP_COPY(chunkmapcopy, chunkmap);
14551 + offset = skb->nh.iph->ihl * 4 + sizeof (sctp_sctphdr_t);
14553 + if (skb_copy_bits(skb, offset, &sch, sizeof(sch)) < 0) {
14554 + duprintf("Dropping invalid SCTP packet.\n");
14559 + duprintf("Chunk num: %d\toffset: %d\ttype: %d\tlength: %d\tflags: %x\n",
14560 + ++i, offset, sch.type, htons(sch.length), sch.flags);
14562 + offset += (htons(sch.length) + 3) & ~3;
14564 + duprintf("skb->len: %d\toffset: %d\n", skb->len, offset);
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)) {
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);
14582 + case SCTP_CHUNK_MATCH_ONLY:
14583 + if (!match_flags(flag_info, flag_count,
14584 + sch.type, sch.flags)) {
14590 + switch (chunk_match_type) {
14591 + case SCTP_CHUNK_MATCH_ONLY:
14595 + } while (offset < skb->len);
14597 + switch (chunk_match_type) {
14598 + case SCTP_CHUNK_MATCH_ALL:
14599 + return SCTP_CHUNKMAP_IS_CLEAR(chunkmap);
14600 + case SCTP_CHUNK_MATCH_ANY:
14602 + case SCTP_CHUNK_MATCH_ONLY:
14606 + /* This will never be reached, but required to stop compiler whine */
14611 +match(const struct sk_buff *skb,
14612 + const struct net_device *in,
14613 + const struct net_device *out,
14614 + const void *matchinfo,
14618 + const struct ipt_sctp_info *info;
14619 + sctp_sctphdr_t sh;
14621 + info = (const struct ipt_sctp_info *)matchinfo;
14624 + duprintf("Dropping non-first fragment.. FIXME\n");
14628 + if (skb_copy_bits(skb, skb->nh.iph->ihl*4, &sh, sizeof(sh)) < 0) {
14629 + duprintf("Dropping evil TCP offset=0 tinygram.\n");
14633 + duprintf("spt: %d\tdpt: %d\n", ntohs(sh.source), ntohs(sh.dest));
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,
14644 + IPT_SCTP_CHUNK_TYPES, info->flags, info->invflags);
14648 +checkentry(const char *tablename,
14649 + const struct ipt_ip *ip,
14651 + unsigned int matchsize,
14652 + unsigned int hook_mask)
14654 + const struct ipt_sctp_info *info;
14656 + info = (const struct ipt_sctp_info *)matchinfo;
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)));
14671 +static struct ipt_match sctp_match =
14673 + .list = { NULL, NULL},
14676 + .checkentry = &checkentry,
14678 + .me = THIS_MODULE
14681 +static int __init init(void)
14683 + return ipt_register_match(&sctp_match);
14686 +static void __exit fini(void)
14688 + ipt_unregister_match(&sctp_match);
14691 +module_init(init);
14692 +module_exit(fini);
14694 +MODULE_LICENSE("GPL");
14695 +MODULE_AUTHOR("Kiran Kumar Immidi");
14696 +MODULE_DESCRIPTION("Match for SCTP protocol packets");
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
14702 +/* Kernel module to match a string into a packet.
14704 + * Copyright (C) 2000 Emmanuel Roger <winfield@freegates.be>
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
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>
14730 +#include <linux/netfilter_ipv4/ip_tables.h>
14731 +#include <linux/netfilter_ipv4/ipt_string.h>
14733 +MODULE_LICENSE("GPL");
14735 +struct string_per_cpu {
14736 + int skip[BM_MAX_HLEN];
14737 + int shift[BM_MAX_HLEN];
14738 + int len[BM_MAX_HLEN];
14741 +static DEFINE_PER_CPU(struct string_per_cpu, bm_string_data);
14744 +/* Boyer Moore Sublinear string search - VERY FAST */
14745 +char *search_sublinear (char *needle, char *haystack, int needle_len, int haystack_len)
14747 + int M1, right_end, sk, sh;
14750 + int *skip, *shift, *len;
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;
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;
14762 + for (i = 1; i < needle_len; i++) {
14763 + for (j = 0; j < needle_len && needle[M1 - j] == needle[M1 - i - j]; j++);
14768 + for (i = 1; i < needle_len; i++) shift[i] = needle_len;
14769 + for (i = M1; i > 0; i--) shift[len[i]] = i;
14772 + for (i = 0; i < needle_len; i++) {
14773 + if (len[i] == M1 - i) ended = i;
14774 + if (ended) shift[i] = ended;
14777 + /* Do the search*/
14778 + while (right_end < haystack_len)
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);
14785 + sk = skip[(int)haystack[right_end - i]];
14787 + right_end = max(right_end - i + sk, right_end + sh);
14793 +/* Linear string search based on memcmp() */
14794 +char *search_linear (char *needle, char *haystack, int needle_len, int haystack_len)
14796 + char *k = haystack + (haystack_len-needle_len);
14797 + char *t = haystack;
14799 + while ( t <= k ) {
14800 + if (memcmp(t, needle, needle_len) == 0)
14809 +match(const struct sk_buff *skb,
14810 + const struct net_device *in,
14811 + const struct net_device *out,
14812 + const void *matchinfo,
14816 + const struct ipt_string_info *info = matchinfo;
14817 + struct iphdr *ip = skb->nh.iph;
14819 + char *needle, *haystack;
14820 + proc_ipt_search search=search_linear;
14822 + if ( !ip ) return 0;
14824 + /* get lenghts, and validate them */
14826 + hlen=ntohs(ip->tot_len)-(ip->ihl*4);
14827 + if ( nlen > hlen ) return 0;
14829 + needle=(char *)&info->string;
14830 + haystack=(char *)ip+(ip->ihl*4);
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;
14839 + if (net_ratelimit())
14840 + printk(KERN_INFO "ipt_string: Packet too big "
14841 + "to attempt sublinear string search "
14842 + "(%d bytes)\n", hlen );
14846 + return ((search(needle, haystack, nlen, hlen)!=NULL) ^ info->invert);
14850 +checkentry(const char *tablename,
14851 + const struct ipt_ip *ip,
14853 + unsigned int matchsize,
14854 + unsigned int hook_mask)
14857 + if (matchsize != IPT_ALIGN(sizeof(struct ipt_string_info)))
14863 +static struct ipt_match string_match = {
14864 + .name = "string",
14866 + .checkentry = &checkentry,
14867 + .me = THIS_MODULE
14871 +static int __init init(void)
14873 + return ipt_register_match(&string_match);
14876 +static void __exit fini(void)
14878 + ipt_unregister_match(&string_match);
14881 +module_init(init);
14882 +module_exit(fini);
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
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.
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>
14910 +MODULE_AUTHOR("Fabrice MARIE <fabrice@netfilter.org>");
14911 +MODULE_DESCRIPTION("Match arrival timestamp/date");
14912 +MODULE_LICENSE("GPL");
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]*/
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 */
14931 +localtime(const time_t *timepr, struct tm *r);
14934 +match(const struct sk_buff *skb,
14935 + const struct net_device *in,
14936 + const struct net_device *out,
14937 + const void *matchinfo,
14940 + u_int16_t datalen,
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;
14950 + /* if kerneltime=1, we don't read the skb->timestamp but kernel time instead */
14951 + if (info->kerneltime)
14953 + do_gettimeofday(&kerneltimeval);
14954 + packet_local_time = kerneltimeval.tv_sec;
14957 + packet_local_time = skb->stamp.tv_sec;
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 */
14963 + /* Transform the timestamp of the packet, in a human readable form */
14964 + localtime(&packet_local_time, ¤ttime);
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 */
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))
14975 + /* here we match ! */
14980 +checkentry(const char *tablename,
14981 + const struct ipt_ip *ip,
14983 + unsigned int matchsize,
14984 + unsigned int hook_mask)
14986 + struct ipt_time_info *info = matchinfo; /* match info for rule */
14988 + /* First, check that we are in the correct hooks */
14990 + & ~((1 << NF_IP_PRE_ROUTING) | (1 << NF_IP_LOCAL_IN) | (1 << NF_IP_FORWARD) | (1 << NF_IP_LOCAL_OUT)))
14992 + printk("ipt_time: error, only valid for PRE_ROUTING, LOCAL_IN, FORWARD and OUTPUT)\n");
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;
15001 + /* Check the size */
15002 + if (matchsize != IPT_ALIGN(sizeof(struct ipt_time_info)))
15004 + /* Now check the coherence of the data ... */
15005 + if ((info->time_start > 1439) || /* 23*60+59 = 1439*/
15006 + (info->time_stop > 1439))
15008 + printk(KERN_WARNING "ipt_time: invalid argument\n");
15015 +static struct ipt_match time_match
15016 += { { NULL, NULL }, "time", &match, &checkentry, NULL, THIS_MODULE };
15018 +static int __init init(void)
15020 + printk("ipt_time loading\n");
15021 + return ipt_register_match(&time_match);
15024 +static void __exit fini(void)
15026 + ipt_unregister_match(&time_match);
15027 + printk("ipt_time unloaded\n");
15030 +module_init(init);
15031 +module_exit(fini);
15034 +/* The part below is borowed and modified from dietlibc */
15036 +/* seconds per day */
15037 +#define SPD 24*60*60
15040 +localtime(const time_t *timepr, struct tm *r) {
15043 + extern struct timezone sys_tz;
15044 + const unsigned int __spm[12] =
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),
15058 + register time_t work;
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;
15073 + r->tm_year=i-1900;
15074 + for (i=11; i && __spm[i]>work; --i) ;
15076 + r->tm_mday=work-__spm[i]+1;
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
15082 +/* Kernel module to match u32 packet content. */
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.
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 := & | << | >> | @
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.
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
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
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.
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.
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"
15133 + AND that with FFFF (giving bytes 2-3),
15134 + and test whether that's in the range [0x100:0xFFFF]
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.
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
15184 +#include <linux/module.h>
15185 +#include <linux/skbuff.h>
15187 +#include <linux/netfilter_ipv4/ipt_u32.h>
15188 +#include <linux/netfilter_ipv4/ip_tables.h>
15190 +/* #include <asm-i386/timex.h> for timing */
15192 +MODULE_AUTHOR("Don Cohen <don@isis.cs3-inc.com>");
15193 +MODULE_DESCRIPTION("IP tables u32 matching module");
15194 +MODULE_LICENSE("GPL");
15197 +match(const struct sk_buff *skb,
15198 + const struct net_device *in,
15199 + const struct net_device *out,
15200 + const void *matchinfo,
15203 + u_int16_t datalen,
15206 + const struct ipt_u32 *data = matchinfo;
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(); */
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)
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;
15231 + case IPT_U32_LEFTSH:
15232 + val = val << number;
15234 + case IPT_U32_RIGHTSH:
15235 + val = val >> number;
15238 + base = base + val;
15240 + if (base+pos+3 > end || base+pos < head)
15242 + val = (base[pos]<<24) + (base[pos+1]<<16) +
15243 + (base[pos+2]<<8) + base[pos+3];
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)) {
15254 + if (i >= data->tests[testind].nvalues) {
15255 + /* cycles2 = get_cycles();
15256 + printk("failed %d in %d cycles\n", testind,
15257 + cycles2-cycles1); */
15261 + /* cycles2 = get_cycles();
15262 + printk("succeeded in %d cycles\n", cycles2-cycles1); */
15267 +checkentry(const char *tablename,
15268 + const struct ipt_ip *ip,
15270 + unsigned int matchsize,
15271 + unsigned int hook_mask)
15273 + if (matchsize != IPT_ALIGN(sizeof(struct ipt_u32)))
15278 +static struct ipt_match u32_match
15279 += { { NULL, NULL }, "u32", &match, &checkentry, NULL, THIS_MODULE };
15281 +static int __init init(void)
15283 + return ipt_register_match(&u32_match);
15286 +static void __exit fini(void)
15288 + ipt_unregister_match(&u32_match);
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
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>
15306 +#include <linux/netfilter_ipv4/ip_tables.h>
15308 +#define limpk(format, args...) \
15310 + if (net_ratelimit()) \
15311 + printk("ipt_unclean: %s" format, \
15312 + embedded ? "(embedded packet) " : "" , ## args); \
15315 +enum icmp_error_status
15317 + ICMP_MAY_BE_ERROR,
15324 + size_t min_len, max_len;
15325 + enum icmp_error_status err;
15326 + u_int8_t min_code, max_code;
15330 +check_ip(struct iphdr *iph, size_t length, int embedded);
15332 +/* ICMP-specific checks. */
15334 +check_icmp(const struct icmphdr *icmph,
15335 + u_int16_t datalen,
15336 + unsigned int offset,
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 },
15348 + = { 8 + 28, 65536, ICMP_IS_ERROR, 0, 3 },
15350 + = { 8, 65536, ICMP_NOT_ERROR, 0, 0 },
15351 + /* Router advertisement. */
15353 + = { 8, 8 + 255 * 8, ICMP_NOT_ERROR, 0, 0 },
15354 + /* Router solicitation. */
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 },
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 },
15370 + = { 12, 12, ICMP_NOT_ERROR, 0, 0 },
15371 + [ICMP_ADDRESSREPLY]
15372 + = { 12, 12, ICMP_NOT_ERROR, 0, 0 } };
15374 + /* Can't do anything if it's a fragment. */
15378 + /* Must cover type and code. */
15379 + if (datalen < 2) {
15380 + limpk("ICMP len=%u too short\n", datalen);
15384 + /* If not embedded. */
15386 + /* Bad checksum? Don't print, just ignore. */
15388 + && ip_compute_csum((unsigned char *) icmph, datalen) != 0)
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);
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;
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");
15413 + if (datalen - 8 < inner->ihl*4 + 8) {
15414 + limpk("ICMP error internal too short\n");
15417 + if (!check_ip(inner, datalen - 8, 1))
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",
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);
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);
15448 + switch (icmph->type) {
15449 + case ICMP_PARAMETERPROB: {
15450 + /* CHECK: Problem param must be within error packet's
15452 + struct iphdr *iph = (void *)icmph + 8;
15453 + u_int32_t arg = ntohl(icmph->un.gateway);
15455 + if (icmph->code == 0) {
15456 + /* Code 0 means that upper 8 bits is pointer
15458 + if ((arg >> 24) >= iph->ihl*4) {
15459 + limpk("ICMP PARAMETERPROB ptr = %u\n",
15460 + ntohl(icmph->un.gateway) >> 24);
15463 + arg &= 0x00FFFFFF;
15466 + /* CHECK: Rest must be zero. */
15468 + limpk("ICMP PARAMETERPROB nonzero arg = %u\n",
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));
15489 +/* UDP-specific checks. */
15491 +check_udp(const struct iphdr *iph,
15492 + const struct udphdr *udph,
15493 + u_int16_t datalen,
15494 + unsigned int offset,
15498 + /* Can't do anything if it's a fragment. */
15502 + /* CHECK: Must cover UDP header. */
15503 + if (datalen < sizeof(struct udphdr)) {
15504 + limpk("UDP len=%u too short\n", datalen);
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)
15515 + /* CHECK: Destination port can't be zero. */
15516 + if (!udph->dest) {
15517 + limpk("UDP zero destination port\n");
15521 + if (!more_frags) {
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);
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);
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);
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
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] =
15562 + [TH_SYN|TH_ACK] = 1,
15564 + [TH_RST|TH_ACK] = 1,
15565 + [TH_RST|TH_ACK|TH_PUSH] = 1,
15566 + [TH_FIN|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
15576 +/* TCP-specific checks. */
15578 +check_tcp(const struct iphdr *iph,
15579 + const struct tcphdr *tcph,
15580 + u_int16_t datalen,
15581 + unsigned int offset,
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;
15591 + /* CHECK: Can't have offset=1: used to override TCP syn-checks. */
15592 + /* In fact, this is caught below (offset < 516). */
15594 + /* Can't do anything if it's a fragment. */
15598 + /* CHECK: Smaller than minimal TCP hdr. */
15599 + if (datalen < sizeof(struct tcphdr)) {
15601 + limpk("Packet length %u < TCP header.\n", datalen);
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));
15615 + /* CHECK: Smaller than actual TCP hdr. */
15616 + if (datalen < tcph->doff * 4) {
15618 + limpk("Packet length %u < actual TCP header.\n",
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)
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));
15639 + /* CHECK: TCP reserved bits zero. */
15640 + if(tcp_flag_word(tcph) & TCP_RESERVED_BITS) {
15641 + limpk("TCP reserved bits not zero\n");
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);
15652 + for (i = sizeof(struct tcphdr); i < tcph->doff * 4; ) {
15653 + switch (opt[i]) {
15655 + end_of_options = 1;
15662 + /* CHECK: options after EOO. */
15663 + if (end_of_options) {
15664 + limpk("TCP option %u after end\n",
15668 + /* CHECK: options at tail. */
15669 + else if (i+1 >= tcph->doff * 4) {
15670 + limpk("TCP option %u at tail\n",
15674 + /* CHECK: zero-length options. */
15675 + else if (opt[i+1] == 0) {
15676 + limpk("TCP option %u 0 len\n",
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);
15686 + /* Move to next option */
15694 +/* Returns 1 if ok */
15695 +/* Standard IP checks. */
15697 +check_ip(struct iphdr *iph, size_t length, int embedded)
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;
15705 + unsigned int offset;
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);
15714 + offset = ntohs(iph->frag_off) & IP_OFFSET;
15715 + protoh = (void *)iph + iph->ihl * 4;
15716 + datalen = length - iph->ihl * 4;
15718 + /* CHECK: Embedded fragment. */
15719 + if (embedded && offset) {
15720 + limpk("Embedded fragment.\n");
15724 + for (i = sizeof(struct iphdr); i < iph->ihl * 4; ) {
15725 + switch (opt[i]) {
15727 + end_of_options = 1;
15734 + /* CHECK: options after EOO. */
15735 + if (end_of_options) {
15736 + limpk("IP option %u after end\n",
15740 + /* CHECK: options at tail. */
15741 + else if (i+1 >= iph->ihl * 4) {
15742 + limpk("IP option %u at tail\n",
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]);
15752 + /* CHECK: oversize options. */
15753 + else if (&opt[i] + opt[i+1] > endhdr) {
15754 + limpk("IP option %u at %u too long\n",
15758 + /* Move to next option */
15763 + /* Fragment checks. */
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));
15772 + /* CHECK: Oversize fragment a-la Ping of Death. */
15773 + if (offset * 8 + datalen > 65535) {
15774 + limpk("Oversize fragment to %u.\n", offset * 8);
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);
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);
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. */
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
15803 +#define MIN_LIKELY_MTU 128
15804 + /* CHECK: Min size of first frag = 128. */
15805 + if ((ntohs(iph->frag_off) & IP_MF)
15807 + && ntohs(iph->tot_len) < MIN_LIKELY_MTU) {
15808 + limpk("First fragment size %u < %u\n", ntohs(iph->tot_len),
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);
15820 + /* CHECK: Protocol specification non-zero. */
15821 + if (iph->protocol == 0) {
15822 + limpk("Zero protocol\n");
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
15831 + if (ntohs(iph->frag_off)>>15) {
15832 + limpk("IP unused bit set\n");
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),
15843 + case IPPROTO_UDP:
15844 + return check_udp(iph, protoh, datalen, offset,
15845 + (ntohs(iph->frag_off) & IP_MF),
15848 + case IPPROTO_TCP:
15849 + return check_tcp(iph, protoh, datalen, offset,
15850 + (ntohs(iph->frag_off) & IP_MF),
15853 + /* Ignorance is bliss. */
15859 +match(const struct sk_buff *skb,
15860 + const struct net_device *in,
15861 + const struct net_device *out,
15862 + const void *matchinfo,
15865 + u_int16_t datalen,
15868 + return !check_ip(skb->nh.iph, skb->len, 0);
15871 +/* Called when user tries to insert an entry of this type. */
15873 +checkentry(const char *tablename,
15874 + const struct ipt_ip *ip,
15876 + unsigned int matchsize,
15877 + unsigned int hook_mask)
15879 + if (matchsize != IPT_ALIGN(0))
15885 +static struct ipt_match unclean_match
15886 += { { NULL, NULL }, "unclean", &match, &checkentry, NULL, THIS_MODULE };
15888 +static int __init init(void)
15890 + return ipt_register_match(&unclean_match);
15893 +static void __exit fini(void)
15895 + ipt_unregister_match(&unclean_match);
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
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 } },
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 } },
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)), "" } }, { } },
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 } },
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
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 } },
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 } },
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 } },
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 } },
15979 @@ -106,7 +106,7 @@
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 } },
15988 @@ -115,7 +115,7 @@
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 } },
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))
16005 +#ifdef CONFIG_IP_ROUTE_TOS
16006 + || (*pskb)->nh.iph->tos != tos
16009 return ip_route_me_harder(pskb) == 0 ? ret : NF_DROP;
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
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 } },
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)), "" } }, { } },
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 } },
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
16046 +--- ipt_string.c.old Mon Mar 29 06:00:23 2004
16047 ++++ ipt_string.c Mon Mar 29 06:01:04 2004
16049 + * Copyright (C) 2000 Emmanuel Roger <winfield@freegates.be>
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.
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");
16068 + struct string_per_cpu {
16072 ++ int skip[BM_MAX_HLEN];
16073 ++ int shift[BM_MAX_HLEN];
16074 ++ int len[BM_MAX_HLEN];
16077 +-struct string_per_cpu *bm_string_data=NULL;
16078 ++static DEFINE_PER_CPU(struct string_per_cpu, bm_string_data);
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;
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;
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;
16100 + for (i = 1; i < needle_len; i++) {
16101 + for (j = 0; j < needle_len && needle[M1 - j] == needle[M1 - i - j]; j++);
16103 + return haystack+(right_end - M1);
16106 +- sk = skip[haystack[right_end - i]];
16107 ++ sk = skip[(int)haystack[right_end - i]];
16109 + right_end = max(right_end - i + sk, right_end + sh);
16111 +@@ -100,15 +104,12 @@
16117 + match(const struct sk_buff *skb,
16118 + const struct net_device *in,
16119 + const struct net_device *out,
16120 + const void *matchinfo,
16122 +- const void *hdr,
16123 +- u_int16_t datalen,
16126 + const struct ipt_string_info *info = matchinfo;
16127 +@@ -158,61 +159,25 @@
16131 +-void string_freeup_data(void)
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);
16141 +- kfree(bm_string_data);
16144 ++static struct ipt_match string_match = {
16145 ++ .name = "string",
16146 ++ .match = &match,
16147 ++ .checkentry = &checkentry,
16148 ++ .me = THIS_MODULE
16151 +-static struct ipt_match string_match
16152 +-= { { NULL, NULL }, "string", &match, &checkentry, NULL, THIS_MODULE };
16154 + static int __init init(void)
16160 +- tlen=sizeof(struct string_per_cpu)*smp_num_cpus;
16161 +- alen=sizeof(int)*BM_MAX_HLEN;
16163 +- /* allocate array of structures */
16164 +- if ( !(bm_string_data=kmalloc(tlen,GFP_KERNEL)) ) {
16168 +- memset(bm_string_data, 0, tlen);
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;
16180 + return ipt_register_match(&string_match);
16183 +- string_freeup_data();
16187 + static void __exit fini(void)
16189 + ipt_unregister_match(&string_match);
16190 +- string_freeup_data();
16193 + module_init(init);
16194 + module_exit(fini);
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 @@
16203 return NET_RX_DROP;
16207 skb_push(skb, skb->data - skb->nh.raw);
16209 @@ -307,7 +308,7 @@
16212 err = NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, skb, NULL, rt->u.dst.dev,
16216 err = inet->recverr ? net_xmit_errno(err) : 0;
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 @@
16223 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb))
16224 goto discard_and_relse;
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 @@
16246 if (up->encap_type) {
16248 @@ -1210,6 +1211,7 @@
16250 if (!xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb))
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);
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
16268 err = -EHOSTUNREACH;
16271 + IPCB(skb)->flags |= IPSKB_XFRM_TRANSFORMED;
16272 return NET_XMIT_BYPASS;
16275 @@ -171,6 +172,7 @@
16276 .handler = ipip_rcv,
16277 .err_handler = ipip_err,
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;
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'.
16308 +config IP6_NF_TARGET_HL
16309 + tristate 'HL target support'
16310 + depends on IP6_NF_MANGLE
16312 + This option adds a `HL' target, which allows you to modify the value of
16313 + IPv6 Hop Limit field.
16315 + If you want to compile it as a module, say M here and read
16316 + <file:Documentation/modules.txt>. If unsure, say `N'.
16318 +config IP6_NF_TARGET_REJECT
16319 + tristate 'REJECT target support'
16320 + depends on IP6_NF_FILTER
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.
16326 + If you want to compile it as a module, say M here and read
16327 + Documentation/modules.txt. If unsure, say `N'.
16329 +config IP6_NF_MATCH_FUZZY
16330 + tristate 'Fuzzy match support'
16331 + depends on IP6_NF_FILTER
16333 + This option adds a `fuzzy' match, which allows you to match
16334 + packets according to a fuzzy logic based law.
16336 + If you want to compile it as a module, say M here and read
16337 + Documentation/modules.txt. If unsure, say `N'.
16339 +config IP6_NF_MATCH_NTH
16340 + tristate 'Nth match support'
16341 + depends on IP6_NF_IPTABLES
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.
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
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.
16360 + If you want to compile it as a module, say M here and read
16361 + Documentation/modules.txt. If unsure, say `N'.
16363 +config IP6_NF_MATCH_RANDOM
16364 + tristate 'Random match support'
16365 + depends on IP6_NF_IPTABLES
16367 + This option adds a `random' match,
16368 + which allow you to match packets randomly
16369 + following a given probability.
16371 + If you want to compile it as a module, say M here and read
16372 + Documentation/modules.txt. If unsure, say `N'.
16374 +config IP6_NF_TARGET_ROUTE
16375 + tristate ' ROUTE target support'
16376 + depends on IP6_NF_MANGLE
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
16382 + The target can be or not a final target. It has to be used inside the
16385 + Not working as a module.
16387 +config IP6_NF_TARGET_TRACE
16388 + tristate 'TRACE target support'
16389 + depends on IP6_NF_RAW
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
16395 + TRACE: tablename/chainname/rulenum
16397 + If you want to compile it as a module, say M here and read
16398 + <file:Documentation/modules.txt>. If unsure, say `N'.
16400 +config IP6_NF_MATCH_POLICY
16401 + tristate "IPsec policy match support"
16402 + depends on IP6_NF_IPTABLES && XFRM
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.
16408 + To compile it as a module, choose M here. If unsure, say N.
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
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
16437 +obj-$(CONFIG_IP6_NF_MATCH_RANDOM) += ip6t_random.o
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
16448 #define IPV6_HDR_LEN (sizeof(struct ipv6hdr))
16449 #define IPV6_OPTHDR_LEN (sizeof(struct ipv6_opt_hdr))
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",
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 @@
16464 t = ip6t_get_target(e);
16465 IP_NF_ASSERT(t->u.kernel.target);
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);
16472 /* Standard target? */
16473 if (!t->u.kernel.target->target) {
16475 @@ -559,6 +573,29 @@
16476 return find_inlist_lock(&ip6t_target, name, "ip6t_", error, mutex);
16480 +find_error_target(struct ip6t_entry *s,
16481 + struct ip6t_entry *e,
16482 + char **chainname)
16484 + struct ip6t_entry_target *t;
16485 + static struct ip6t_entry *found = NULL;
16490 + t = ip6t_get_target(found);
16491 + if (strcmp(t->u.user.name,
16492 + IP6T_ERROR_TARGET) == 0) {
16493 + *chainname = t->data;
16502 /* All zeroes == unconditional rule. */
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)
16509 + char *chainname = NULL;
16510 + u_int32_t rulenum;
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 @@
16516 /* Set initial back pointer. */
16517 e->counters.pcnt = pos;
16519 + chainname = (char *) hook6names[hook];
16522 struct ip6t_standard_target *t
16523 @@ -603,6 +644,8 @@
16526 |= ((1 << hook) | (1 << NF_IP6_NUMHOOKS));
16527 + e->rulenum = rulenum++;
16528 + e->chainname = chainname;
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;
16536 + /* Set unconditional rulenum to zero. */
16538 + e->counters.bcnt = 0;
16540 /* Return: backtrack through the last
16543 @@ -637,6 +684,11 @@
16544 (newinfo->entries + pos);
16545 } while (oldpos == pos + e->next_offset);
16547 + /* Restore chainname, rulenum. */
16548 + chainname = e->chainname;
16549 + rulenum = e->counters.bcnt;
16550 + e->counters.bcnt = 0;
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",
16559 + e->counters.bcnt = rulenum++;
16561 + e = (struct ip6t_entry *)
16562 + (newinfo->entries + newpos);
16563 + if (IP6T_ENTRY_ITERATE(newinfo->entries,
16565 + find_error_target,
16566 + e, &chainname) == 0) {
16567 + printk("ip6_tables: table screwed up!\n");
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
16578 + * Hop Limit modification target for ip6tables
16579 + * Maciej Soltysiak <solt@dns.toxicfilms.tv>
16580 + * Based on HW's TTL module
16582 + * This software is distributed under the terms of GNU GPL
16585 +#include <linux/module.h>
16586 +#include <linux/skbuff.h>
16587 +#include <linux/ip.h>
16589 +#include <linux/netfilter_ipv6/ip6_tables.h>
16590 +#include <linux/netfilter_ipv6/ip6t_HL.h>
16592 +MODULE_AUTHOR("Maciej Soltysiak <solt@dns.toxicfilms.tv>");
16593 +MODULE_DESCRIPTION("IP tables Hop Limit modification module");
16594 +MODULE_LICENSE("GPL");
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)
16600 + struct ipv6hdr *ip6h = (*pskb)->nh.ipv6h;
16601 + const struct ip6t_HL_info *info = targinfo;
16602 + u_int16_t diffs[2];
16605 + switch (info->mode) {
16606 + case IP6T_HL_SET:
16607 + new_hl = info->hop_limit;
16609 + case IP6T_HL_INC:
16610 + new_hl = ip6h->hop_limit + info->hop_limit;
16611 + if (new_hl > 255)
16614 + case IP6T_HL_DEC:
16615 + new_hl = ip6h->hop_limit + info->hop_limit;
16620 + new_hl = ip6h->hop_limit;
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);
16630 + return IP6T_CONTINUE;
16633 +static int ip6t_hl_checkentry(const char *tablename,
16634 + const struct ip6t_entry *e,
16636 + unsigned int targinfosize,
16637 + unsigned int hook_mask)
16639 + struct ip6t_HL_info *info = targinfo;
16641 + if (targinfosize != IP6T_ALIGN(sizeof(struct ip6t_HL_info))) {
16642 + printk(KERN_WARNING "HL: targinfosize %u != %Zu\n",
16644 + IP6T_ALIGN(sizeof(struct ip6t_HL_info)));
16648 + if (strcmp(tablename, "mangle")) {
16649 + printk(KERN_WARNING "HL: can only be called from \"mangle\" table, not \"%s\"\n", tablename);
16653 + if (info->mode > IP6T_HL_MAXMODE) {
16654 + printk(KERN_WARNING "HL: invalid or unknown Mode %u\n",
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");
16667 +static struct ip6t_target ip6t_HL = { { NULL, NULL }, "HL",
16668 + ip6t_hl_target, ip6t_hl_checkentry, NULL, THIS_MODULE };
16670 +static int __init init(void)
16672 + return ip6t_register_target(&ip6t_HL);
16675 +static void __exit fini(void)
16677 + ip6t_unregister_target(&ip6t_HL);
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
16687 + * IP6 tables REJECT target module
16688 + * Linux INET6 implementation
16690 + * Copyright (C)2003 USAGI/WIDE Project
16693 + * Yasuyuki Kozakai <yasuyuki.kozakai@toshiba.co.jp>
16695 + * Based on net/ipv4/netfilter/ipt_REJECT.c
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.
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>
16716 +MODULE_AUTHOR("Yasuyuki KOZAKAI <yasuyuki.kozakai@toshiba.co.jp>");
16717 +MODULE_DESCRIPTION("IP6 tables REJECT target module");
16718 +MODULE_LICENSE("GPL");
16721 +#define DEBUGP printk
16723 +#define DEBUGP(format, args...)
16727 +static void connection_attach(struct sk_buff *new_skb, struct nf_ct_info *nfct)
16729 + void (*attach)(struct sk_buff *, struct nf_ct_info *);
16730 + if (nfct && (attach = ip6_ct_attach) != NULL) {
16732 + attach(new_skb, nfct);
16737 +static int maybe_reroute(struct sk_buff *skb)
16739 + if (skb->nfcache & NFC_ALTERED){
16740 + if (ip6_route_me_harder(skb) != 0){
16746 + return dst_output(skb);
16749 +/* Send RST reply */
16750 +static void send_reset(struct sk_buff *oldskb)
16752 + struct sk_buff *nskb;
16753 + struct tcphdr otcph, *tcph;
16754 + unsigned int otcplen, tcphoff, hh_len;
16756 + struct ipv6hdr *oip6h = oldskb->nh.ipv6h, *ip6h;
16757 + struct dst_entry *dst = NULL;
16760 + proto = oip6h->nexthdr;
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");
16769 + tcphoff = ipv6_skip_exthdr(oldskb, ((u8*)(oip6h+1) - oldskb->data),
16770 + &proto, oldskb->len - ((u8*)(oip6h+1)
16771 + - oldskb->data));
16773 + if ((tcphoff < 0) || (tcphoff > oldskb->len)) {
16774 + DEBUGP("ip6t_REJECT: Can't get TCP header.\n");
16778 + otcplen = oldskb->len - tcphoff;
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",
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");
16793 + /* No RST for RST. */
16795 + DEBUGP("ip6t_REJECT: RST is set\n");
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");
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);
16814 + if (net_ratelimit())
16815 + printk("ip6t_REJECT: can't find dst. err = %d\n", err);
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,
16825 + if (net_ratelimit())
16826 + printk("ip6t_REJECT: Can't alloc skb\n");
16827 + dst_release(dst);
16834 + skb_reserve(nskb, hh_len + dst->header_len);
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);
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;
16853 + tcph->seq = otcph.ack_seq;
16854 + tcph->ack_seq = 0;
16857 + tcph->ack_seq = htonl(ntohl(otcph.seq) + otcph.syn + otcph.fin
16858 + + otcplen - (otcph.doff<<2));
16862 + /* Reset flags */
16863 + ((u_int8_t *)tcph)[13] = 0;
16865 + tcph->ack = needs_ack;
16866 + tcph->window = 0;
16867 + tcph->urg_ptr = 0;
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));
16878 + connection_attach(nskb, oldskb->nfct);
16881 + NF_HOOK(PF_INET6, NF_IP6_LOCAL_OUT, nskb, NULL, nskb->dst->dev,
16884 + dst_release(dst);
16887 +static void send_unreach(struct sk_buff *skb_in, unsigned char code)
16889 + struct ipv6hdr *ip6h, *hdr = skb_in->nh.ipv6h;
16890 + struct icmp6hdr *icmp6h;
16891 + struct dst_entry *dst = NULL;
16892 + struct rt6_info *rt;
16895 + unsigned int len, datalen, hh_len;
16896 + int saddr_type, daddr_type;
16897 + unsigned int ptr, ip6off;
16900 + struct sk_buff *nskb;
16903 + saddr_type = ipv6_addr_type(&hdr->saddr);
16904 + daddr_type = ipv6_addr_type(&hdr->daddr);
16906 + if ((!(saddr_type & IPV6_ADDR_UNICAST)) ||
16907 + (!(daddr_type & IPV6_ADDR_UNICAST))) {
16908 + DEBUGP("ip6t_REJECT: addr is not unicast.\n");
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);
16917 + if ((ptr < 0) || (ptr > skb_in->len)) {
16918 + ptr = ip6off + sizeof(struct ipv6hdr);
16919 + proto = hdr->nexthdr;
16920 + } else if (proto == IPPROTO_ICMPV6) {
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");
16929 + if (!(type & ICMPV6_INFOMSG_MASK)) {
16930 + DEBUGP("ip6t_REJECT: no reply to icmp error\n");
16933 + } else if (proto == IPPROTO_UDP) {
16934 + int plen = skb_in->len - (ptr - ip6off);
16937 + if (plen < sizeof(struct udphdr)) {
16938 + DEBUGP("ip6t_REJECT: too short\n");
16942 + if (skb_copy_bits(skb_in, ptr + offsetof(struct udphdr, check),
16944 + if (net_ratelimit())
16945 + printk("ip6t_REJECT: can't get copy from skb");
16950 + csum_ipv6_magic(&hdr->saddr, &hdr->daddr, plen,
16952 + skb_checksum(skb_in, ptr, plen, 0))) {
16953 + DEBUGP("ip6t_REJECT: UDP checksum is invalid.\n");
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;
16965 + if (ip6_dst_lookup(NULL, &dst, &fl)) {
16969 + rt = (struct rt6_info *)dst;
16972 + if (rt->rt6i_dst.plen < 128)
16973 + tmo >>= ((128 - rt->rt6i_dst.plen)>>5);
16975 + if (!xrlim_allow(dst, tmo)) {
16976 + if (net_ratelimit())
16977 + printk("ip6t_REJECT: rate limitted\n");
16978 + goto dst_release_out;
16981 + len = skb_in->len + sizeof(struct ipv6hdr) + sizeof(struct icmp6hdr);
16983 + if (len > dst_pmtu(dst))
16984 + len = dst_pmtu(dst);
16985 + if (len > IPV6_MIN_MTU)
16986 + len = IPV6_MIN_MTU;
16988 + datalen = len - sizeof(struct ipv6hdr) - sizeof(struct icmp6hdr);
16989 + hh_len = (rt->u.dst.dev->hard_header_len + 15)&~15;
16991 + nskb = alloc_skb(hh_len + 15 + dst->header_len + dst->trailer_len + len,
16995 + if (net_ratelimit())
16996 + printk("ip6t_REJECT: can't alloc skb\n");
16997 + goto dst_release_out;
17000 + nskb->priority = 0;
17004 + skb_reserve(nskb, hh_len + dst->header_len);
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);
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;
17020 + data = skb_put(nskb, datalen);
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);
17029 + connection_attach(nskb, skb_in->nfct);
17031 + NF_HOOK(PF_INET6, NF_IP6_LOCAL_OUT, nskb, NULL, nskb->dst->dev,
17035 + dst_release(dst);
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,
17045 + const struct ip6t_reject_info *reject = targinfo;
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);
17055 + case IP6T_ICMP6_ADM_PROHIBITED:
17056 + send_unreach(*pskb, ICMPV6_ADM_PROHIBITED);
17058 + case IP6T_ICMP6_NOT_NEIGHBOUR:
17059 + send_unreach(*pskb, ICMPV6_NOT_NEIGHBOUR);
17061 + case IP6T_ICMP6_ADDR_UNREACH:
17062 + send_unreach(*pskb, ICMPV6_ADDR_UNREACH);
17064 + case IP6T_ICMP6_PORT_UNREACH:
17065 + send_unreach(*pskb, ICMPV6_PORT_UNREACH);
17067 + case IP6T_ICMP6_ECHOREPLY:
17070 + case IP6T_TCP_RESET:
17071 + send_reset(*pskb);
17074 + if (net_ratelimit())
17075 + printk(KERN_WARNING "ip6t_REJECT: case %u not handled yet\n", reject->with);
17082 +static int check(const char *tablename,
17083 + const struct ip6t_entry *e,
17085 + unsigned int targinfosize,
17086 + unsigned int hook_mask)
17088 + const struct ip6t_reject_info *rejinfo = targinfo;
17090 + if (targinfosize != IP6T_ALIGN(sizeof(struct ip6t_reject_info))) {
17091 + DEBUGP("ip6t_REJECT: targinfosize %u != 0\n", targinfosize);
17095 + /* Only allow these for packet filtering. */
17096 + if (strcmp(tablename, "filter") != 0) {
17097 + DEBUGP("ip6t_REJECT: bad table `%s'.\n", tablename);
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);
17108 + if (rejinfo->with == IP6T_ICMP6_ECHOREPLY) {
17109 + printk("ip6t_REJECT: ECHOREPLY is not supported.\n");
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");
17123 +static struct ip6t_target ip6t_reject_reg = {
17124 + .name = "REJECT",
17125 + .target = reject6_target,
17126 + .checkentry = check,
17127 + .me = THIS_MODULE
17130 +static int __init init(void)
17132 + if (ip6t_register_target(&ip6t_reject_reg))
17137 +static void __exit fini(void)
17139 + ip6t_unregister_target(&ip6t_reject_reg);
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
17149 + * This implements the ROUTE v6 target, which enables you to setup unusual
17150 + * routes not supported by the standard kernel routing table.
17152 + * Copyright (C) 2003 Cedric de Launois <delaunois@info.ucl.ac.be>
17154 + * v 1.0 2003/08/05
17156 + * This software is distributed under GNU GPL v2, 1991
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>
17171 +#define DEBUGP printk
17173 +#define DEBUGP(format, args...)
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])
17186 +/* Route the packet according to the routing keys specified in
17187 + * route_info. Keys are :
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
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
17203 +route6(struct sk_buff *skb,
17204 + unsigned int ifindex,
17205 + const struct ip6t_route_target_info *route_info)
17207 + struct rt6_info *rt = NULL;
17208 + struct ipv6hdr *ipv6h = skb->nh.ipv6h;
17209 + struct in6_addr *gw = (struct in6_addr*)&route_info->gw;
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);
17216 + if (ipv6_addr_any(gw))
17217 + rt = rt6_lookup(&ipv6h->daddr, &ipv6h->saddr, ifindex, 1);
17219 + rt = rt6_lookup(gw, &ipv6h->saddr, ifindex, 1);
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);
17229 + if (ifindex && rt->rt6i_dev->ifindex!=ifindex)
17230 + goto wrong_route;
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);
17237 + /* Drop old route. */
17238 + dst_release(skb->dst);
17239 + skb->dst = &rt->u.dst;
17240 + skb->dev = rt->rt6i_dev;
17244 + dst_release(&rt->u.dst);
17246 + if (!net_ratelimit())
17249 + printk("ip6t_ROUTE: no explicit route found ");
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));
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
17265 +static void ip_direct_send(struct sk_buff *skb)
17267 + struct dst_entry *dst = skb->dst;
17268 + struct hh_cache *hh = dst->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);
17279 + if (net_ratelimit())
17280 + DEBUGP(KERN_DEBUG "ip6t_ROUTE: no hdr & no neighbour cache!\n");
17286 +static unsigned int
17287 +route6_oif(const struct ip6t_route_target_info *route_info,
17288 + struct sk_buff *skb)
17290 + unsigned int ifindex = 0;
17291 + struct net_device *dev_out = NULL;
17293 + /* The user set the interface name to use.
17294 + * Getting the current interface index.
17296 + if ((dev_out = dev_get_by_name(route_info->oif))) {
17297 + ifindex = dev_out->ifindex;
17299 + /* Unknown interface name : packet dropped */
17300 + if (net_ratelimit())
17301 + DEBUGP("ip6t_ROUTE: oif interface %s not found\n", route_info->oif);
17303 + if (route_info->flags & IP6T_ROUTE_CONTINUE)
17304 + return IP6T_CONTINUE;
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;
17315 + ip_direct_send(skb);
17316 + return NF_STOLEN;
17322 +static unsigned int
17323 +route6_gw(const struct ip6t_route_target_info *route_info,
17324 + struct sk_buff *skb)
17326 + if (route6(skb, 0, route_info)) {
17327 + if (route_info->flags & IP6T_ROUTE_CONTINUE)
17328 + return IP6T_CONTINUE;
17330 + ip_direct_send(skb);
17331 + return NF_STOLEN;
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,
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;
17349 + if (route_info->flags & IP6T_ROUTE_CONTINUE)
17352 + /* If we are at PREROUTING or INPUT hook
17353 + * the TTL isn't decreased by the IP stack
17355 + if (hooknum == NF_IP6_PRE_ROUTING ||
17356 + hooknum == NF_IP6_LOCAL_IN) {
17358 + struct ipv6hdr *ipv6h = skb->nh.ipv6h;
17360 + if (ipv6h->hop_limit <= 1) {
17361 + /* Force OUTPUT device used as source address */
17362 + skb->dev = skb->dst->dev;
17364 + icmpv6_send(skb, ICMPV6_TIME_EXCEED,
17365 + ICMPV6_EXC_HOPLIMIT, 0, skb->dev);
17370 + ipv6h->hop_limit--;
17375 + if (route_info->oif[0])
17376 + return route6_oif(route_info, *pskb);
17378 + if (!ipv6_addr_any(gw))
17379 + return route6_gw(route_info, *pskb);
17381 + if (net_ratelimit())
17382 + DEBUGP(KERN_DEBUG "ip6t_ROUTE: no parameter !\n");
17384 + return IP6T_CONTINUE;
17389 +ip6t_route_checkentry(const char *tablename,
17390 + const struct ip6t_entry *e,
17392 + unsigned int targinfosize,
17393 + unsigned int hook_mask)
17395 + if (strcmp(tablename, "mangle") != 0) {
17396 + printk("ip6t_ROUTE: can only be called from \"mangle\" table.\n");
17400 + if (targinfosize != IP6T_ALIGN(sizeof(struct ip6t_route_target_info))) {
17401 + printk(KERN_WARNING "ip6t_ROUTE: targinfosize %u != %Zu\n",
17403 + IP6T_ALIGN(sizeof(struct ip6t_route_target_info)));
17411 +static struct ip6t_target ip6t_route_reg = {
17413 + .target = ip6t_route_target,
17414 + .checkentry = ip6t_route_checkentry,
17415 + .me = THIS_MODULE
17419 +static int __init init(void)
17421 + printk(KERN_DEBUG "registering ipv6 ROUTE target\n");
17422 + if (ip6t_register_target(&ip6t_route_reg))
17429 +static void __exit fini(void)
17431 + ip6t_unregister_target(&ip6t_route_reg);
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
17441 +/* This is a module which is used for setting
17442 + * the NFC_TRACE flag in the nfcache field of an skb.
17444 +#include <linux/module.h>
17445 +#include <linux/skbuff.h>
17447 +#include <linux/netfilter_ipv6/ip6_tables.h>
17449 +MODULE_LICENSE("GPL");
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,
17459 + (*pskb)->nfcache |= NFC_TRACE;
17460 + return IP6T_CONTINUE;
17464 +checkentry(const char *tablename,
17465 + const struct ip6t_entry *e,
17467 + unsigned int targinfosize,
17468 + unsigned int hook_mask)
17470 + if (targinfosize != 0) {
17471 + printk(KERN_WARNING "TRACE: targinfosize %u != 0\n",
17476 + if (strcmp(tablename, "raw") != 0) {
17477 + printk(KERN_WARNING "TRACE: can only be called from \"raw\" table, not \"%s\"\n", tablename);
17484 +static struct ip6t_target ip6t_trace_reg = {
17486 + .target = target,
17487 + .checkentry = checkentry,
17488 + .me = THIS_MODULE
17491 +static int __init init(void)
17493 + if (ip6t_register_target(&ip6t_trace_reg))
17499 +static void __exit fini(void)
17501 + ip6t_unregister_target(&ip6t_trace_reg);
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
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 .
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
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>
17539 + Packet Acceptance Rate - LOW and Packet Acceptance Rate - HIGH
17540 + Expressed in percentage
17543 +#define PAR_LOW 1/100
17544 +#define PAR_HIGH 1
17546 +static spinlock_t fuzzy_lock = SPIN_LOCK_UNLOCKED;
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");
17552 +static u_int8_t mf_high(u_int32_t tx,u_int32_t mini,u_int32_t maxi)
17554 + if (tx >= maxi) return 100;
17556 + if (tx <= mini) return 0;
17558 + return ((100 * (tx-mini)) / (maxi-mini));
17561 +static u_int8_t mf_low(u_int32_t tx,u_int32_t mini,u_int32_t maxi)
17563 + if (tx <= mini) return 100;
17565 + if (tx >= maxi) return 0;
17567 + return ((100 * (maxi - tx)) / (maxi - mini));
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,
17578 + u_int16_t datalen,
17581 + /* From userspace */
17583 + struct ip6t_fuzzy_info *info = (struct ip6t_fuzzy_info *) matchinfo;
17585 + u_int8_t random_number;
17586 + unsigned long amount;
17587 + u_int8_t howhigh, howlow;
17590 + spin_lock_bh(&fuzzy_lock); /* Rise the lock */
17592 + info->bytes_total += pskb->len;
17593 + info->packets_total++;
17595 + info->present_time = jiffies;
17597 + if (info->present_time >= info->previous_time)
17598 + amount = info->present_time - info->previous_time;
17600 + /* There was a transition : I choose to re-sample
17601 + and keep the old acceptance rate...
17605 + info->previous_time = info->present_time;
17606 + info->bytes_total = info->packets_total = 0;
17609 + if ( amount > HZ/10) {/* More than 100 ms elapsed ... */
17611 + info->mean_rate = (u_int32_t) ((HZ * info->packets_total) \
17614 + info->previous_time = info->present_time;
17615 + info->bytes_total = info->packets_total = 0;
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);
17620 + info->acceptance_rate = (u_int8_t) \
17621 + (howhigh * PAR_LOW + PAR_HIGH * howlow);
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,
17633 + spin_unlock_bh(&fuzzy_lock); /* Release the lock */
17636 + if (info->acceptance_rate < 100)
17638 + get_random_bytes((void *)(&random_number), 1);
17640 + /* If within the acceptance , it can pass => don't match */
17641 + if (random_number <= (255 * info->acceptance_rate) / 100)
17644 + return 1; /* It can't pass (It matches) */
17647 + return 0; /* acceptance_rate == 100 % => Everything passes ... */
17652 +ip6t_fuzzy_checkentry(const char *tablename,
17653 + const struct ip6t_ip6 *ip,
17655 + unsigned int matchsize,
17656 + unsigned int hook_mask)
17659 + const struct ip6t_fuzzy_info *info = matchinfo;
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)));
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");
17676 +static struct ip6t_match ip6t_fuzzy_reg = {
17679 + ip6t_fuzzy_match,
17680 + ip6t_fuzzy_checkentry,
17684 +static int __init init(void)
17686 + if (ip6t_register_match(&ip6t_fuzzy_reg))
17692 +static void __exit fini(void)
17694 + ip6t_unregister_match(&ip6t_fuzzy_reg);
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
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
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
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>
17726 +MODULE_LICENSE("GPL");
17729 + * State information.
17733 + u_int16_t number;
17736 +static struct state states[IP6T_NTH_NUM_COUNTERS];
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,
17745 + u_int16_t datalen,
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))
17753 + printk(KERN_WARNING "nth: invalid counter %u. counter between 0 and %u\n", counter, IP6T_NTH_NUM_COUNTERS-1);
17757 + spin_lock(&states[counter].lock);
17759 + /* Are we matching every nth packet?*/
17760 + if (info->packet == 0xFF)
17762 + /* We're matching every nth packet and only every nth packet*/
17763 + /* Do we match or invert match? */
17764 + if (info->not == 0)
17766 + if (states[counter].number == 0)
17768 + ++states[counter].number;
17771 + if (states[counter].number >= info->every)
17772 + states[counter].number = 0; /* reset the counter */
17774 + ++states[counter].number;
17779 + if (states[counter].number == 0)
17781 + ++states[counter].number;
17784 + if (states[counter].number >= info->every)
17785 + states[counter].number = 0;
17787 + ++states[counter].number;
17793 + /* We're using the --packet, so there must be a rule for every value */
17794 + if (states[counter].number == info->packet)
17796 + /* only increment the counter when a match happens */
17797 + if (states[counter].number >= info->every)
17798 + states[counter].number = 0; /* reset the counter */
17800 + ++states[counter].number;
17808 + /* don't match */
17809 + spin_unlock(&states[counter].lock);
17813 + spin_unlock(&states[counter].lock);
17818 +ip6t_nth_checkentry(const char *tablename,
17819 + const struct ip6t_ip6 *e,
17821 + unsigned int matchsize,
17822 + unsigned int hook_mask)
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))
17829 + printk(KERN_WARNING "nth: invalid counter %u. counter between 0 and %u\n", counter, IP6T_NTH_NUM_COUNTERS-1);
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)));
17839 + states[counter].number = info->startat;
17844 +static struct ip6t_match ip6t_nth_reg = {
17848 + ip6t_nth_checkentry,
17852 +static int __init init(void)
17854 + unsigned counter;
17855 + memset(&states, 0, sizeof(states));
17856 + if (ip6t_register_match(&ip6t_nth_reg))
17859 + for(counter = 0; counter < IP6T_NTH_NUM_COUNTERS; counter++)
17861 + spin_lock_init(&(states[counter].lock));
17864 + printk("ip6t_nth match loaded\n");
17868 +static void __exit fini(void)
17870 + ip6t_unregister_match(&ip6t_nth_reg);
17871 + printk("ip6t_nth match unloaded\n");
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
17880 MODULE_LICENSE("GPL");
17883 +match_comm(const struct sk_buff *skb, const char *comm)
17885 + struct task_struct *p, *g;
17886 + struct files_struct *files;
17889 + read_lock(&tasklist_lock);
17890 + do_each_thread(g, p) {
17891 + if(strncmp(p->comm, comm, sizeof(p->comm)))
17895 + files = p->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);
17903 + read_unlock(&tasklist_lock);
17907 + read_unlock(&files->file_lock);
17910 + } while_each_thread(g, p);
17911 + read_unlock(&tasklist_lock);
17916 match_pid(const struct sk_buff *skb, pid_t pid)
17918 struct task_struct *p;
17919 @@ -125,6 +158,12 @@
17923 + if(info->match & IP6T_OWNER_COMM) {
17924 + if (!match_comm(skb, info->comm) ^
17925 + !!(info->invert & IP6T_OWNER_COMM))
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
17936 +/* IP tables module for matching IPsec policy
17938 + * Copyright (c) 2004 Patrick McHardy, <kaber@trash.net>
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.
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>
17952 +#include <linux/netfilter_ipv6.h>
17953 +#include <linux/netfilter_ipv6/ip6t_policy.h>
17954 +#include <linux/netfilter_ipv6/ip6_tables.h>
17956 +MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
17957 +MODULE_DESCRIPTION("IPtables IPsec policy matching module");
17958 +MODULE_LICENSE("GPL");
17961 +static inline int ip6_masked_addrcmp(struct in6_addr addr1,
17962 + struct in6_addr mask,
17963 + struct in6_addr addr2)
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]))
17977 +match_xfrm_state(struct xfrm_state *x, const struct ip6t_policy_elem *e)
17979 +#define MISMATCH(x,y) (e->match.x && ((e->x != (y)) ^ e->invert.x))
17981 + struct in6_addr xfrm_saddr, xfrm_daddr;
17983 + if ((e->match.saddr
17984 + && (ip6_masked_addrcmp(xfrm_saddr, e->saddr, e->smask))
17985 + ^ e->invert.saddr ) ||
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))
17998 +match_policy_in(const struct sk_buff *skb, const struct ip6t_policy_info *info)
18000 + const struct ip6t_policy_elem *e;
18001 + struct sec_path *sp = skb->sp;
18002 + int strict = info->flags & POLICY_MATCH_STRICT;
18007 + if (strict && info->len != sp->len)
18010 + for (i = sp->len - 1; i >= 0; i--) {
18011 + pos = strict ? i - sp->len + 1 : 0;
18012 + if (pos >= info->len)
18014 + e = &info->pol[pos];
18016 + if (match_xfrm_state(sp->x[i].xvec, e)) {
18019 + } else if (strict)
18023 + return strict ? 1 : 0;
18027 +match_policy_out(const struct sk_buff *skb, const struct ip6t_policy_info *info)
18029 + const struct ip6t_policy_elem *e;
18030 + struct dst_entry *dst = skb->dst;
18031 + int strict = info->flags & POLICY_MATCH_STRICT;
18034 + if (dst->xfrm == NULL)
18037 + for (i = 0; dst && dst->xfrm; dst = dst->child, i++) {
18038 + pos = strict ? i : 0;
18039 + if (pos >= info->len)
18041 + e = &info->pol[pos];
18043 + if (match_xfrm_state(dst->xfrm, e)) {
18046 + } else if (strict)
18050 + return strict ? 1 : 0;
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,
18059 + u_int16_t datalen,
18062 + const struct ip6t_policy_info *info = matchinfo;
18065 + if (info->flags & POLICY_MATCH_IN)
18066 + ret = match_policy_in(skb, info);
18068 + ret = match_policy_out(skb, info);
18071 + if (info->flags & POLICY_MATCH_NONE)
18075 + } else if (info->flags & POLICY_MATCH_NONE)
18081 +static int checkentry(const char *tablename, const struct ip6t_ip6 *ip,
18082 + void *matchinfo, unsigned int matchsize,
18083 + unsigned int hook_mask)
18085 + struct ip6t_policy_info *info = matchinfo;
18087 + if (matchsize != IP6T_ALIGN(sizeof(*info))) {
18088 + printk(KERN_ERR "ip6t_policy: matchsize %u != %u\n",
18089 + matchsize, IP6T_ALIGN(sizeof(*info)));
18092 + if (!(info->flags & (POLICY_MATCH_IN|POLICY_MATCH_OUT))) {
18093 + printk(KERN_ERR "ip6t_policy: neither incoming nor "
18094 + "outgoing policy selected\n");
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");
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");
18109 + if (info->len > POLICY_MAX_ELEM) {
18110 + printk(KERN_ERR "ip6t_policy: too many policy elements\n");
18117 +static struct ip6t_match policy_match =
18119 + .name = "policy",
18121 + .checkentry = checkentry,
18122 + .me = THIS_MODULE,
18125 +static int __init init(void)
18127 + return ip6t_register_match(&policy_match);
18130 +static void __exit fini(void)
18132 + ip6t_unregister_match(&policy_match);
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
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
18147 + 2001-10-14 Fabrice MARIE <fabrice@netfilter.org> : initial implementation.
18148 + 2003-04-30 Maciej Soltysiak <solt@dns.toxicfilms.tv> : IPv6 Port
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>
18160 +MODULE_LICENSE("GPL");
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,
18169 + u_int16_t datalen,
18172 + /* Parameters from userspace */
18173 + const struct ip6t_rand_info *info = matchinfo;
18174 + u_int8_t random_number;
18176 + /* get 1 random number from the kernel random number generation routine */
18177 + get_random_bytes((void *)(&random_number), 1);
18179 + /* Do we match ? */
18180 + if (random_number <= info->average)
18187 +ip6t_rand_checkentry(const char *tablename,
18188 + const struct ip6t_ip6 *e,
18190 + unsigned int matchsize,
18191 + unsigned int hook_mask)
18193 + /* Parameters from userspace */
18194 + const struct ip6t_rand_info *info = matchinfo;
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)));
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);
18213 +static struct ip6t_match ip6t_rand_reg = {
18217 + ip6t_rand_checkentry,
18221 +static int __init init(void)
18223 + if (ip6t_register_match(&ip6t_rand_reg))
18226 + printk("ip6t_random match loaded\n");
18230 +static void __exit fini(void)
18232 + ip6t_unregister_match(&ip6t_rand_reg);
18233 + printk("ip6t_random match unloaded\n");
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
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 } },
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 } },
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)), "" } }, { } },
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 } },
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
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 } },
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 } },
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 } },
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 } },
18316 @@ -105,7 +105,7 @@
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)), "" } }, { } },
18325 @@ -114,7 +114,7 @@
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 } },
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
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 } },
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 } },
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 } },
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);
18371 -#ifdef CONFIG_NETFILTER
18372 - nf_conntrack_put(skb->nfct);
18373 - skb->nfct = NULL;
18374 -#ifdef CONFIG_NETFILTER_DEBUG
18375 - skb->nf_debug = 0;
18379 ipip6_ecn_decapsulate(iph, skb);
18381 read_unlock(&ipip6_lock);
18382 @@ -580,13 +574,7 @@
18383 if ((iph->ttl = tiph->ttl) == 0)
18384 iph->ttl = iph6->hop_limit;
18386 -#ifdef CONFIG_NETFILTER
18387 - nf_conntrack_put(skb->nfct);
18388 - skb->nfct = NULL;
18389 -#ifdef CONFIG_NETFILTER_DEBUG
18390 - skb->nf_debug = 0;
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
18404 +#ifdef CONFIG_NETFILTER
18405 + sp->decap_done = 0;
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
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>
18421 @@ -911,6 +912,7 @@
18423 if (_decode_session(skb, &fl, family) < 0)
18425 + nf_nat_decode_session(skb, &fl, family);
18427 /* First, check used SA against their selectors. */