1 Netfilter SNAP 20040518
3 PENDING/expect-evict-order
4 PENDING/init_conntrack-optimize
5 PENDING/ipt_helper-invert-fix
8 PENDING/orphaned-expect-fix
9 PENDING/proc-no-internal-targets
12 BASE/NETLINK // fix socket -> sk_socket
21 BASE/osf // fix socket -> sk_socket
22 BASE/pool // added EXPORT_SYMBOL(ip_pool_mod, ip_pool_match)
33 EXTRA/TARPIT // fix Makefile.ladd and req patch for 2.6
37 EXTRA/eggdrop-conntrack
38 EXTRA/h323-conntrack-nat
39 EXTRA/ipsec-01-output-hooks
40 EXTRA/ipsec-02-input-hooks
41 EXTRA/ipsec-03-policy-lookup
42 EXTRA/ipsec-04-policy-check
44 EXTRA/mms-conntrack-nat
45 EXTRA/owner-socketlookup
48 EXTRA/quake3-conntrack-nat
51 EXTRA/sctp-conntrack-nat
52 EXTRA/string // required unclean module - included - req fix
53 EXTRA/talk-conntrack-nat
55 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter.h linux-2.6.6/include/linux/netfilter.h
56 --- linux-2.6.6.org/include/linux/netfilter.h 2004-05-10 04:32:37.000000000 +0200
57 +++ linux-2.6.6/include/linux/netfilter.h 2004-05-18 14:28:50.000000000 +0200
59 <= 0x2000 is used for protocol-flags. */
60 #define NFC_UNKNOWN 0x4000
61 #define NFC_ALTERED 0x8000
62 +#define NFC_TRACE 0x10000
65 #include <linux/config.h>
67 /* This is gross, but inline doesn't cut it for avoiding the function
68 call in fast path: gcc doesn't inline (needs value tracking?). --RR */
69 #ifdef CONFIG_NETFILTER_DEBUG
70 -#define NF_HOOK(pf, hook, skb, indev, outdev, okfn) \
71 - nf_hook_slow((pf), (hook), (skb), (indev), (outdev), (okfn), INT_MIN)
72 +#define NF_HOOK_COND(pf, hook, skb, indev, outdev, okfn, cond) \
75 + : nf_hook_slow((pf), (hook), (skb), (indev), (outdev), (okfn), INT_MIN))
76 #define NF_HOOK_THRESH nf_hook_slow
78 -#define NF_HOOK(pf, hook, skb, indev, outdev, okfn) \
79 -(list_empty(&nf_hooks[(pf)][(hook)]) \
80 +#define NF_HOOK_COND(pf, hook, skb, indev, outdev, okfn, cond) \
81 +(!(cond) || list_empty(&nf_hooks[(pf)][(hook)]) \
83 : nf_hook_slow((pf), (hook), (skb), (indev), (outdev), (okfn), INT_MIN))
84 #define NF_HOOK_THRESH(pf, hook, skb, indev, outdev, okfn, thresh) \
87 : nf_hook_slow((pf), (hook), (skb), (indev), (outdev), (okfn), (thresh)))
89 +#define NF_HOOK(pf, hook, skb, indev, outdev, okfn) \
90 + NF_HOOK_COND((pf), (hook), (skb), (indev), (outdev), (okfn), 1)
92 int nf_hook_slow(int pf, unsigned int hook, struct sk_buff *skb,
93 struct net_device *indev, struct net_device *outdev,
96 #else /* !CONFIG_NETFILTER */
97 #define NF_HOOK(pf, hook, skb, indev, outdev, okfn) (okfn)(skb)
98 +#define NF_HOOK_COND(pf, hook, skb, indev, outdev, okfn, cond) (okfn)(skb)
99 #endif /*CONFIG_NETFILTER*/
102 +#ifdef CONFIG_IP_NF_NAT_NEEDED
104 +extern void nf_nat_decode_session4(struct sk_buff *skb, struct flowi *fl);
107 +nf_nat_decode_session(struct sk_buff *skb, struct flowi *fl, int family)
109 + if (family == AF_INET)
110 + nf_nat_decode_session4(skb, fl);
112 +#else /* CONFIG_IP_NF_NAT_NEEDED */
113 +#define nf_nat_decode_session(skb,fl,family)
114 +#endif /* CONFIG_IP_NF_NAT_NEEDED */
115 +#endif /* CONFIG_XFRM */
117 #endif /*__KERNEL__*/
118 #endif /*__LINUX_NETFILTER_H*/
119 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_helpers.h linux-2.6.6/include/linux/netfilter_helpers.h
120 --- linux-2.6.6.org/include/linux/netfilter_helpers.h 1970-01-01 01:00:00.000000000 +0100
121 +++ linux-2.6.6/include/linux/netfilter_helpers.h 2004-05-18 14:28:50.000000000 +0200
124 + * Helpers for netfiler modules. This file provides implementations for basic
125 + * functions such as strncasecmp(), etc.
127 + * gcc will warn for defined but unused functions, so we only include the
128 + * functions requested. The following macros are used:
129 + * NF_NEED_STRNCASECMP nf_strncasecmp()
130 + * NF_NEED_STRTOU16 nf_strtou16()
131 + * NF_NEED_STRTOU32 nf_strtou32()
133 +#ifndef _NETFILTER_HELPERS_H
134 +#define _NETFILTER_HELPERS_H
136 +/* Only include these functions for kernel code. */
139 +#include <linux/ctype.h>
140 +#define iseol(c) ( (c) == '\r' || (c) == '\n' )
143 + * The standard strncasecmp()
145 +#ifdef NF_NEED_STRNCASECMP
147 +nf_strncasecmp(const char* s1, const char* s2, u_int32_t len)
149 + if (s1 == NULL || s2 == NULL)
151 + if (s1 == NULL && s2 == NULL)
155 + return (s1 == NULL) ? -1 : 1;
157 + while (len > 0 && tolower(*s1) == tolower(*s2))
163 + return ( (len == 0) ? 0 : (tolower(*s1) - tolower(*s2)) );
165 +#endif /* NF_NEED_STRNCASECMP */
168 + * Parse a string containing a 16-bit unsigned integer.
169 + * Returns the number of chars used, or zero if no number is found.
171 +#ifdef NF_NEED_STRTOU16
173 +nf_strtou16(const char* pbuf, u_int16_t* pval)
178 + while (isdigit(pbuf[n]))
180 + *pval = (*pval * 10) + (pbuf[n] - '0');
186 +#endif /* NF_NEED_STRTOU16 */
189 + * Parse a string containing a 32-bit unsigned integer.
190 + * Returns the number of chars used, or zero if no number is found.
192 +#ifdef NF_NEED_STRTOU32
194 +nf_strtou32(const char* pbuf, u_int32_t* pval)
199 + while (pbuf[n] >= '0' && pbuf[n] <= '9')
201 + *pval = (*pval * 10) + (pbuf[n] - '0');
207 +#endif /* NF_NEED_STRTOU32 */
210 + * Given a buffer and length, advance to the next line and mark the current
213 +#ifdef NF_NEED_NEXTLINE
215 +nf_nextline(char* p, uint len, uint* poff, uint* plineoff, uint* plinelen)
225 + while (p[off] != '\n')
236 + /* if we saw a crlf, physlen needs adjusted */
237 + if (physlen > 0 && p[off] == '\n' && p[off-1] == '\r')
242 + /* advance past the newline */
246 + *plinelen = physlen;
251 +#endif /* NF_NEED_NEXTLINE */
253 +#endif /* __KERNEL__ */
255 +#endif /* _NETFILTER_HELPERS_H */
256 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ip_conntrack.h linux-2.6.6/include/linux/netfilter_ipv4/ip_conntrack.h
257 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ip_conntrack.h 2004-05-10 04:33:20.000000000 +0200
258 +++ linux-2.6.6/include/linux/netfilter_ipv4/ip_conntrack.h 2004-05-18 14:28:50.000000000 +0200
261 #include <linux/netfilter_ipv4/ip_conntrack_tcp.h>
262 #include <linux/netfilter_ipv4/ip_conntrack_icmp.h>
263 +#include <linux/netfilter_ipv4/ip_conntrack_sctp.h>
265 /* per conntrack: protocol private data */
266 union ip_conntrack_proto {
267 /* insert conntrack proto private data here */
268 + struct ip_ct_sctp sctp;
269 struct ip_ct_tcp tcp;
270 struct ip_ct_icmp icmp;
275 /* Add protocol helper include file here */
276 +#include <linux/netfilter_ipv4/ip_conntrack_talk.h>
277 +#include <linux/netfilter_ipv4/ip_conntrack_rtsp.h>
278 +#include <linux/netfilter_ipv4/ip_conntrack_rsh.h>
279 +#include <linux/netfilter_ipv4/ip_conntrack_mms.h>
280 +#include <linux/netfilter_ipv4/ip_conntrack_h323.h>
281 #include <linux/netfilter_ipv4/ip_conntrack_amanda.h>
282 #include <linux/netfilter_ipv4/ip_conntrack_ftp.h>
283 #include <linux/netfilter_ipv4/ip_conntrack_irc.h>
285 /* per expectation: application helper private data */
286 union ip_conntrack_expect_help {
287 /* insert conntrack helper private data (expect) here */
288 + struct ip_ct_talk_expect exp_talk_info;
289 + struct ip_ct_rtsp_expect exp_rtsp_info;
290 + struct ip_ct_rsh_expect exp_rsh_info;
291 + struct ip_ct_mms_expect exp_mms_info;
292 + struct ip_ct_h225_expect exp_h225_info;
293 struct ip_ct_amanda_expect exp_amanda_info;
294 struct ip_ct_ftp_expect exp_ftp_info;
295 struct ip_ct_irc_expect exp_irc_info;
297 /* per conntrack: application helper private data */
298 union ip_conntrack_help {
299 /* insert conntrack helper private data (master) here */
300 + struct ip_ct_talk_master ct_talk_info;
301 + struct ip_ct_rtsp_master ct_rtsp_info;
302 + struct ip_ct_rsh_master ct_rsh_info;
303 + struct ip_ct_mms_master ct_mms_info;
304 + struct ip_ct_h225_master ct_h225_info;
305 struct ip_ct_ftp_master ct_ftp_info;
306 struct ip_ct_irc_master ct_irc_info;
310 #endif /* CONFIG_IP_NF_NAT_NEEDED */
312 +#if defined(CONFIG_IP_NF_CONNTRACK_MARK)
313 + unsigned long mark;
318 /* get master conntrack via master expectation */
319 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ip_conntrack_h323.h linux-2.6.6/include/linux/netfilter_ipv4/ip_conntrack_h323.h
320 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ip_conntrack_h323.h 1970-01-01 01:00:00.000000000 +0100
321 +++ linux-2.6.6/include/linux/netfilter_ipv4/ip_conntrack_h323.h 2004-05-18 14:28:50.000000000 +0200
323 +#ifndef _IP_CONNTRACK_H323_H
324 +#define _IP_CONNTRACK_H323_H
325 +/* H.323 connection tracking. */
328 +/* Protects H.323 related data */
329 +#include <linux/netfilter_ipv4/lockhelp.h>
330 +DECLARE_LOCK_EXTERN(ip_h323_lock);
333 +/* Default H.225 port */
334 +#define H225_PORT 1720
336 +/* This structure is per expected connection */
337 +struct ip_ct_h225_expect {
338 + u_int16_t port; /* Port of the H.225 helper/RTCP/RTP channel */
339 + enum ip_conntrack_dir dir; /* Direction of the original connection */
340 + unsigned int offset; /* offset of the address in the payload */
343 +/* This structure exists only once per master */
344 +struct ip_ct_h225_master {
345 + int is_h225; /* H.225 or H.245 connection */
346 +#ifdef CONFIG_IP_NF_NAT_NEEDED
347 + enum ip_conntrack_dir dir; /* Direction of the original connection */
348 + u_int32_t seq[IP_CT_DIR_MAX]; /* Exceptional packet mangling for signal addressess... */
349 + unsigned int offset[IP_CT_DIR_MAX]; /* ...and the offset of the addresses in the payload */
353 +#endif /* _IP_CONNTRACK_H323_H */
354 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ip_conntrack_mms.h linux-2.6.6/include/linux/netfilter_ipv4/ip_conntrack_mms.h
355 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ip_conntrack_mms.h 1970-01-01 01:00:00.000000000 +0100
356 +++ linux-2.6.6/include/linux/netfilter_ipv4/ip_conntrack_mms.h 2004-05-18 14:28:50.000000000 +0200
358 +#ifndef _IP_CONNTRACK_MMS_H
359 +#define _IP_CONNTRACK_MMS_H
363 +#include <linux/netfilter_ipv4/lockhelp.h>
365 +DECLARE_LOCK_EXTERN(ip_mms_lock);
367 +#define MMS_PORT 1755
368 +#define MMS_SRV_MSG_ID 196610
370 +#define MMS_SRV_MSG_OFFSET 36
371 +#define MMS_SRV_UNICODE_STRING_OFFSET 60
372 +#define MMS_SRV_CHUNKLENLV_OFFSET 16
373 +#define MMS_SRV_CHUNKLENLM_OFFSET 32
374 +#define MMS_SRV_MESSAGELENGTH_OFFSET 8
377 +/* This structure is per expected connection */
378 +struct ip_ct_mms_expect {
384 +/* This structure exists only once per master */
385 +struct ip_ct_mms_master {
388 +#endif /* _IP_CONNTRACK_MMS_H */
389 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ip_conntrack_quake3.h linux-2.6.6/include/linux/netfilter_ipv4/ip_conntrack_quake3.h
390 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ip_conntrack_quake3.h 1970-01-01 01:00:00.000000000 +0100
391 +++ linux-2.6.6/include/linux/netfilter_ipv4/ip_conntrack_quake3.h 2004-05-18 14:28:50.000000000 +0200
393 +#ifndef _IP_CT_QUAKE3
394 +#define _IP_CT_QUAKE3
396 +/* Don't confuse with 27960, often used as the Server Port */
397 +#define QUAKE3_MASTER_PORT 27950
399 +struct quake3_search {
400 + const char marker[4]; /* always 0xff 0xff 0xff 0xff ? */
401 + const char *pattern;
405 +/* This structure is per expected connection */
406 +struct ip_ct_quake3_expect {
409 +/* This structure exists only once per master */
410 +struct ip_ct_quake3_master {
413 +#endif /* _IP_CT_QUAKE3 */
414 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ip_conntrack_rsh.h linux-2.6.6/include/linux/netfilter_ipv4/ip_conntrack_rsh.h
415 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ip_conntrack_rsh.h 1970-01-01 01:00:00.000000000 +0100
416 +++ linux-2.6.6/include/linux/netfilter_ipv4/ip_conntrack_rsh.h 2004-05-18 14:28:50.000000000 +0200
418 +/* RSH extension for IP connection tracking, Version 1.0
419 + * (C) 2002 by Ian (Larry) Latter <Ian.Latter@mq.edu.au>
420 + * based on HW's ip_conntrack_irc.c
422 + * ip_conntrack_rsh.c,v 1.0 2002/07/17 14:49:26
424 + * This program is free software; you can redistribute it and/or
425 + * modify it under the terms of the GNU General Public License
426 + * as published by the Free Software Foundation; either version
427 + * 2 of the License, or (at your option) any later version.
429 +#ifndef _IP_CONNTRACK_RSH_H
430 +#define _IP_CONNTRACK_RSH_H
433 +#include <linux/netfilter_ipv4/lockhelp.h>
435 +DECLARE_LOCK_EXTERN(ip_rsh_lock);
439 +#define RSH_PORT 514
441 +/* This structure is per expected connection */
442 +struct ip_ct_rsh_expect
447 +/* This structure exists only once per master */
448 +struct ip_ct_rsh_master {
451 +#endif /* _IP_CONNTRACK_RSH_H */
453 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ip_conntrack_rtsp.h linux-2.6.6/include/linux/netfilter_ipv4/ip_conntrack_rtsp.h
454 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ip_conntrack_rtsp.h 1970-01-01 01:00:00.000000000 +0100
455 +++ linux-2.6.6/include/linux/netfilter_ipv4/ip_conntrack_rtsp.h 2004-05-18 14:28:50.000000000 +0200
458 + * RTSP extension for IP connection tracking.
459 + * (C) 2003 by Tom Marshall <tmarshall@real.com>
460 + * based on ip_conntrack_irc.h
462 + * This program is free software; you can redistribute it and/or
463 + * modify it under the terms of the GNU General Public License
464 + * as published by the Free Software Foundation; either version
465 + * 2 of the License, or (at your option) any later version.
467 +#ifndef _IP_CONNTRACK_RTSP_H
468 +#define _IP_CONNTRACK_RTSP_H
470 +/* #define IP_NF_RTSP_DEBUG */
471 +#define IP_NF_RTSP_VERSION "0.01"
473 +/* port block types */
475 + pb_single, /* client_port=x */
476 + pb_range, /* client_port=x-y */
477 + pb_discon /* client_port=x/y (rtspbis) */
480 +/* We record seq number and length of rtsp headers here, all in host order. */
483 + * This structure is per expected connection. It is a member of struct
484 + * ip_conntrack_expect. The TCP SEQ for the conntrack expect is stored
485 + * there and we are expected to only store the length of the data which
486 + * needs replaced. If a packet contains multiple RTSP messages, we create
487 + * one expected connection per message.
489 + * We use these variables to mark the entire header block. This may seem
490 + * like overkill, but the nature of RTSP requires it. A header may appear
491 + * multiple times in a message. We must treat two Transport headers the
492 + * same as one Transport header with two entries.
494 +struct ip_ct_rtsp_expect
496 + u_int32_t len; /* length of header block */
497 + portblock_t pbtype; /* Type of port block that was requested */
498 + u_int16_t loport; /* Port that was requested, low or first */
499 + u_int16_t hiport; /* Port that was requested, high or second */
501 + uint method; /* RTSP method */
502 + uint cseq; /* CSeq from request */
506 +/* This structure exists only once per master */
507 +struct ip_ct_rtsp_master
515 +#include <linux/netfilter_ipv4/lockhelp.h>
517 +#define RTSP_PORT 554
519 +/* Protects rtsp part of conntracks */
520 +DECLARE_LOCK_EXTERN(ip_rtsp_lock);
522 +#endif /* __KERNEL__ */
524 +#endif /* _IP_CONNTRACK_RTSP_H */
525 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ip_conntrack_sctp.h linux-2.6.6/include/linux/netfilter_ipv4/ip_conntrack_sctp.h
526 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ip_conntrack_sctp.h 1970-01-01 01:00:00.000000000 +0100
527 +++ linux-2.6.6/include/linux/netfilter_ipv4/ip_conntrack_sctp.h 2004-05-18 14:28:50.000000000 +0200
529 +#ifndef _IP_CONNTRACK_SCTP_H
530 +#define _IP_CONNTRACK_SCTP_H
531 +/* SCTP tracking. */
533 +enum sctp_conntrack {
534 + SCTP_CONNTRACK_NONE,
535 + SCTP_CONNTRACK_CLOSED,
536 + SCTP_CONNTRACK_COOKIE_WAIT,
537 + SCTP_CONNTRACK_COOKIE_ECHOED,
538 + SCTP_CONNTRACK_ESTABLISHED,
539 + SCTP_CONNTRACK_SHUTDOWN_SENT,
540 + SCTP_CONNTRACK_SHUTDOWN_RECD,
541 + SCTP_CONNTRACK_SHUTDOWN_ACK_SENT,
547 + enum sctp_conntrack state;
549 + u_int32_t vtag[IP_CT_DIR_MAX];
550 + u_int32_t ttag[IP_CT_DIR_MAX];
553 +#endif /* _IP_CONNTRACK_SCTP_H */
554 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ip_conntrack_talk.h linux-2.6.6/include/linux/netfilter_ipv4/ip_conntrack_talk.h
555 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ip_conntrack_talk.h 1970-01-01 01:00:00.000000000 +0100
556 +++ linux-2.6.6/include/linux/netfilter_ipv4/ip_conntrack_talk.h 2004-05-18 14:28:50.000000000 +0200
558 +#ifndef _IP_CONNTRACK_TALK_H
559 +#define _IP_CONNTRACK_TALK_H
560 +/* TALK tracking. */
563 +#include <linux/in.h>
564 +#include <linux/netfilter_ipv4/lockhelp.h>
566 +/* Protects talk part of conntracks */
567 +DECLARE_LOCK_EXTERN(ip_talk_lock);
571 +#define TALK_PORT 517
572 +#define NTALK_PORT 518
574 +/* talk structures and constants from <protocols/talkd.h> */
577 + * 4.3BSD struct sockaddr
580 + u_int16_t ta_family;
583 + u_int32_t ta_junk1;
584 + u_int32_t ta_junk2;
587 +#define TALK_OLD_NSIZE 9
588 +#define TALK_NSIZE 12
589 +#define TALK_TTY_NSIZE 16
592 + * Client->server request message formats.
595 + u_char type; /* request type, see below */
596 + char l_name[TALK_OLD_NSIZE];/* caller's name */
597 + char r_name[TALK_OLD_NSIZE];/* callee's name */
599 + u_int32_t id_num; /* message id */
600 + int32_t pid; /* caller's process id */
601 + char r_tty[TALK_TTY_NSIZE];/* callee's tty name */
602 + struct talk_addr addr; /* old (4.3) style */
603 + struct talk_addr ctl_addr; /* old (4.3) style */
607 + u_char vers; /* protocol version */
608 + u_char type; /* request type, see below */
609 + u_char answer; /* not used */
611 + u_int32_t id_num; /* message id */
612 + struct talk_addr addr; /* old (4.3) style */
613 + struct talk_addr ctl_addr; /* old (4.3) style */
614 + int32_t pid; /* caller's process id */
615 + char l_name[TALK_NSIZE];/* caller's name */
616 + char r_name[TALK_NSIZE];/* callee's name */
617 + char r_tty[TALK_TTY_NSIZE];/* callee's tty name */
621 + u_char vers; /* talk protocol version */
622 + u_char type; /* request type */
623 + u_char answer; /* */
624 + u_char extended; /* !0 if additional parts */
625 + u_int32_t id_num; /* message id number (dels) */
626 + struct talk_addr addr; /* target address */
627 + struct talk_addr ctl_addr; /* reply to address */
628 + int32_t pid; /* caller's process id */
629 + char l_name[TALK_NSIZE]; /* caller's name */
630 + char r_name[TALK_NSIZE]; /* callee's name */
631 + char r_tty[TALK_TTY_NSIZE]; /* callee's tty */
635 + * Server->client response message formats.
637 +struct talk_response {
638 + u_char type; /* type of request message, see below */
639 + u_char answer; /* response to request message, see below */
641 + u_int32_t id_num; /* message id */
642 + struct talk_addr addr; /* address for establishing conversation */
645 +struct ntalk_response {
646 + u_char vers; /* protocol version */
647 + u_char type; /* type of request message, see below */
648 + u_char answer; /* response to request message, see below */
650 + u_int32_t id_num; /* message id */
651 + struct talk_addr addr; /* address for establishing conversation */
654 +struct ntalk2_response {
655 + u_char vers; /* protocol version */
656 + u_char type; /* type of request message */
657 + u_char answer; /* response to request */
658 + u_char rvers; /* Version of answering vers*/
659 + u_int32_t id_num; /* message id number */
660 + struct talk_addr addr; /* address for connection */
661 + /* This is at the end to compatiblize this with NTALK version. */
662 + char r_name[TALK_NSIZE]; /* callee's name */
665 +#define TALK_STR(data, talk_str, member) ((struct talk_str *)data)->member)
666 +#define TALK_RESP(data, ver, member) (ver ? ((struct ntalk_response *)data)->member : ((struct talk_response *)data)->member)
667 +#define TALK_MSG(data, ver, member) (ver ? ((struct ntalk_msg *)data)->member : ((struct talk_msg *)data)->member)
669 +#define TALK_VERSION 0 /* protocol versions */
670 +#define NTALK_VERSION 1
671 +#define NTALK2_VERSION 2
673 +/* message type values */
674 +#define LEAVE_INVITE 0 /* leave invitation with server */
675 +#define LOOK_UP 1 /* check for invitation by callee */
676 +#define DELETE 2 /* delete invitation by caller */
677 +#define ANNOUNCE 3 /* announce invitation by caller */
679 +#define REPLY_QUERY 4 /* request reply data from local daemon */
682 +#define SUCCESS 0 /* operation completed properly */
683 +#define NOT_HERE 1 /* callee not logged in */
684 +#define FAILED 2 /* operation failed for unexplained reason */
685 +#define MACHINE_UNKNOWN 3 /* caller's machine name unknown */
686 +#define PERMISSION_DENIED 4 /* callee's tty doesn't permit announce */
687 +#define UNKNOWN_REQUEST 5 /* request has invalid type value */
688 +#define BADVERSION 6 /* request has invalid protocol version */
689 +#define BADADDR 7 /* request has invalid addr value */
690 +#define BADCTLADDR 8 /* request has invalid ctl_addr value */
692 +#define NO_CALLER 9 /* no-one calling answer from REPLY */
693 +#define TRY_HERE 10 /* Not on this machine, try this */
694 +#define SELECTIVE_REFUSAL 11 /* User Filter refusal. */
695 +#define MAX_RESPONSE_TYPE 11 /* Make sure this is updated */
697 +/* We don't really need much for talk */
698 +struct ip_ct_talk_expect
700 + /* Port that was to be used */
704 +/* This structure exists only once per master */
705 +struct ip_ct_talk_master
709 +#endif /* _IP_CONNTRACK_TALK_H */
710 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ip_conntrack_tuple.h linux-2.6.6/include/linux/netfilter_ipv4/ip_conntrack_tuple.h
711 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ip_conntrack_tuple.h 2004-05-10 04:32:54.000000000 +0200
712 +++ linux-2.6.6/include/linux/netfilter_ipv4/ip_conntrack_tuple.h 2004-05-18 14:28:50.000000000 +0200
722 /* The manipulable part of the tuple. */
733 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ip_pool.h linux-2.6.6/include/linux/netfilter_ipv4/ip_pool.h
734 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ip_pool.h 1970-01-01 01:00:00.000000000 +0100
735 +++ linux-2.6.6/include/linux/netfilter_ipv4/ip_pool.h 2004-05-18 14:28:50.000000000 +0200
740 +/***************************************************************************/
741 +/* This program is free software; you can redistribute it and/or modify */
742 +/* it under the terms of the GNU General Public License as published by */
743 +/* the Free Software Foundation; either version 2 of the License, or */
744 +/* (at your option) any later version. */
746 +/* This program is distributed in the hope that it will be useful, */
747 +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
748 +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
749 +/* GNU General Public License for more details. */
751 +/* You should have received a copy of the GNU General Public License */
752 +/* along with this program; if not, write to the Free Software */
753 +/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*/
754 +/***************************************************************************/
756 +/* A sockopt of such quality has hardly ever been seen before on the open
757 + * market! This little beauty, hardly ever used: above 64, so it's
758 + * traditionally used for firewalling, not touched (even once!) by the
759 + * 2.0, 2.2 and 2.4 kernels!
761 + * Comes with its own certificate of authenticity, valid anywhere in the
766 +#define SO_IP_POOL 81
768 +typedef int ip_pool_t; /* pool index */
769 +#define IP_POOL_NONE ((ip_pool_t)-1)
771 +struct ip_pool_request {
778 +/* NOTE: I deliberately break the first cut ippool utility. Nobody uses it. */
780 +#define IP_POOL_BAD001 0x00000010
782 +#define IP_POOL_FLUSH 0x00000011 /* req.index, no arguments */
783 +#define IP_POOL_INIT 0x00000012 /* from addr to addr2 incl. */
784 +#define IP_POOL_DESTROY 0x00000013 /* req.index, no arguments */
785 +#define IP_POOL_ADD_ADDR 0x00000014 /* add addr to pool */
786 +#define IP_POOL_DEL_ADDR 0x00000015 /* del addr from pool */
787 +#define IP_POOL_HIGH_NR 0x00000016 /* result in req.index */
788 +#define IP_POOL_LOOKUP 0x00000017 /* result in addr and addr2 */
789 +#define IP_POOL_USAGE 0x00000018 /* result in addr */
790 +#define IP_POOL_TEST_ADDR 0x00000019 /* result (0/1) returned */
794 +/* NOTE: ip_pool_match() and ip_pool_mod() expect ADDR to be host byte order */
795 +extern int ip_pool_match(ip_pool_t pool, u_int32_t addr);
796 +extern int ip_pool_mod(ip_pool_t pool, u_int32_t addr, int isdel);
800 +#endif /*_IP_POOL_H*/
801 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ip_tables.h linux-2.6.6/include/linux/netfilter_ipv4/ip_tables.h
802 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ip_tables.h 2004-05-10 04:32:37.000000000 +0200
803 +++ linux-2.6.6/include/linux/netfilter_ipv4/ip_tables.h 2004-05-18 14:28:50.000000000 +0200
806 /* Values for "flag" field in struct ipt_ip (general ip structure). */
807 #define IPT_F_FRAG 0x01 /* Set if rule is a fragment rule */
808 -#define IPT_F_MASK 0x01 /* All possible flag bits mask. */
809 +#define IPT_F_GOTO 0x02 /* Set if jump is a goto */
810 +#define IPT_F_MASK 0x03 /* All possible flag bits mask. */
812 /* Values for "inv" field in struct ipt_ip. */
813 #define IPT_INV_VIA_IN 0x01 /* Invert the sense of IN IFACE. */
816 unsigned int comefrom;
818 + /* Name of the chain */
821 + /* Rule number in the chain. */
824 /* Packet and byte counters. */
825 struct ipt_counters counters;
827 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_CONNMARK.h linux-2.6.6/include/linux/netfilter_ipv4/ipt_CONNMARK.h
828 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_CONNMARK.h 1970-01-01 01:00:00.000000000 +0100
829 +++ linux-2.6.6/include/linux/netfilter_ipv4/ipt_CONNMARK.h 2004-05-18 14:28:50.000000000 +0200
831 +#ifndef _IPT_CONNMARK_H_target
832 +#define _IPT_CONNMARK_H_target
834 +/* Copyright (C) 2002,2004 MARA Systems AB <http://www.marasystems.com>
835 + * by Henrik Nordstrom <hno@marasystems.com>
837 + * This program is free software; you can redistribute it and/or modify
838 + * it under the terms of the GNU General Public License as published by
839 + * the Free Software Foundation; either version 2 of the License, or
840 + * (at your option) any later version.
844 + IPT_CONNMARK_SET = 0,
846 + IPT_CONNMARK_RESTORE
849 +struct ipt_connmark_target_info {
850 + unsigned long mark;
851 + unsigned long mask;
855 +#endif /*_IPT_CONNMARK_H_target*/
856 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_IPMARK.h linux-2.6.6/include/linux/netfilter_ipv4/ipt_IPMARK.h
857 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_IPMARK.h 1970-01-01 01:00:00.000000000 +0100
858 +++ linux-2.6.6/include/linux/netfilter_ipv4/ipt_IPMARK.h 2004-05-18 14:28:50.000000000 +0200
860 +#ifndef _IPT_IPMARK_H_target
861 +#define _IPT_IPMARK_H_target
863 +struct ipt_ipmark_target_info {
864 + unsigned long andmask;
865 + unsigned long ormask;
869 +#define IPT_IPMARK_SRC 0
870 +#define IPT_IPMARK_DST 1
872 +#endif /*_IPT_IPMARK_H_target*/
873 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_MARK.h linux-2.6.6/include/linux/netfilter_ipv4/ipt_MARK.h
874 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_MARK.h 2004-05-10 04:32:26.000000000 +0200
875 +++ linux-2.6.6/include/linux/netfilter_ipv4/ipt_MARK.h 2004-05-18 14:28:50.000000000 +0200
877 #ifndef _IPT_MARK_H_target
878 #define _IPT_MARK_H_target
886 struct ipt_mark_target_info {
891 #endif /*_IPT_MARK_H_target*/
892 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_NETLINK.h linux-2.6.6/include/linux/netfilter_ipv4/ipt_NETLINK.h
893 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_NETLINK.h 1970-01-01 01:00:00.000000000 +0100
894 +++ linux-2.6.6/include/linux/netfilter_ipv4/ipt_NETLINK.h 2004-05-18 14:28:50.000000000 +0200
896 +#ifndef _IPT_FWMON_H
897 +#define _IPT_FWMON_H
899 +/* Bitmask macros */
900 +#define MASK(x,y) (x & y)
901 +#define MASK_SET(x,y) x |= y
902 +#define MASK_UNSET(x,y) x &= ~y
904 +#define USE_MARK 0x00000001
905 +#define USE_DROP 0x00000002
906 +#define USE_SIZE 0x00000004
910 + unsigned int flags;
919 + char iface[IFNAMSIZ];
922 +#endif /*_IPT_FWMON_H*/
923 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_ROUTE.h linux-2.6.6/include/linux/netfilter_ipv4/ipt_ROUTE.h
924 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_ROUTE.h 1970-01-01 01:00:00.000000000 +0100
925 +++ linux-2.6.6/include/linux/netfilter_ipv4/ipt_ROUTE.h 2004-05-18 14:28:50.000000000 +0200
927 +/* Header file for iptables ipt_ROUTE target
929 + * (C) 2002 by Cédric de Launois <delaunois@info.ucl.ac.be>
931 + * This software is distributed under GNU GPL v2, 1991
933 +#ifndef _IPT_ROUTE_H_target
934 +#define _IPT_ROUTE_H_target
936 +#define IPT_ROUTE_IFNAMSIZ 16
938 +struct ipt_route_target_info {
939 + char oif[IPT_ROUTE_IFNAMSIZ]; /* Output Interface Name */
940 + char iif[IPT_ROUTE_IFNAMSIZ]; /* Input Interface Name */
941 + u_int32_t gw; /* IP address of gateway */
945 +/* Values for "flags" field */
946 +#define IPT_ROUTE_CONTINUE 0x01
948 +#endif /*_IPT_ROUTE_H_target*/
949 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_TCPLAG.h linux-2.6.6/include/linux/netfilter_ipv4/ipt_TCPLAG.h
950 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_TCPLAG.h 1970-01-01 01:00:00.000000000 +0100
951 +++ linux-2.6.6/include/linux/netfilter_ipv4/ipt_TCPLAG.h 2004-05-18 14:28:50.000000000 +0200
953 +#ifndef _IPT_TCPLAG_H
954 +#define _IPT_TCPLAG_H
958 + unsigned char level;
959 + unsigned char prefix[ 15 ];
963 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_TTL.h linux-2.6.6/include/linux/netfilter_ipv4/ipt_TTL.h
964 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_TTL.h 1970-01-01 01:00:00.000000000 +0100
965 +++ linux-2.6.6/include/linux/netfilter_ipv4/ipt_TTL.h 2004-05-18 14:28:50.000000000 +0200
967 +/* TTL modification module for IP tables
968 + * (C) 2000 by Harald Welte <laforge@gnumonks.org> */
979 +#define IPT_TTL_MAXMODE IPT_TTL_DEC
981 +struct ipt_TTL_info {
988 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_XOR.h linux-2.6.6/include/linux/netfilter_ipv4/ipt_XOR.h
989 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_XOR.h 1970-01-01 01:00:00.000000000 +0100
990 +++ linux-2.6.6/include/linux/netfilter_ipv4/ipt_XOR.h 2004-05-18 14:28:50.000000000 +0200
995 +struct ipt_XOR_info {
997 + u_int8_t block_size;
1000 +#endif /* _IPT_XOR_H */
1001 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_addrtype.h linux-2.6.6/include/linux/netfilter_ipv4/ipt_addrtype.h
1002 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_addrtype.h 1970-01-01 01:00:00.000000000 +0100
1003 +++ linux-2.6.6/include/linux/netfilter_ipv4/ipt_addrtype.h 2004-05-18 14:28:50.000000000 +0200
1005 +#ifndef _IPT_ADDRTYPE_H
1006 +#define _IPT_ADDRTYPE_H
1008 +struct ipt_addrtype_info {
1009 + u_int16_t source; /* source-type mask */
1010 + u_int16_t dest; /* dest-type mask */
1011 + int invert_source;
1016 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_connlimit.h linux-2.6.6/include/linux/netfilter_ipv4/ipt_connlimit.h
1017 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_connlimit.h 1970-01-01 01:00:00.000000000 +0100
1018 +++ linux-2.6.6/include/linux/netfilter_ipv4/ipt_connlimit.h 2004-05-18 14:28:50.000000000 +0200
1020 +#ifndef _IPT_CONNLIMIT_H
1021 +#define _IPT_CONNLIMIT_H
1023 +struct ipt_connlimit_data;
1025 +struct ipt_connlimit_info {
1029 + struct ipt_connlimit_data *data;
1031 +#endif /* _IPT_CONNLIMIT_H */
1032 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_connmark.h linux-2.6.6/include/linux/netfilter_ipv4/ipt_connmark.h
1033 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_connmark.h 1970-01-01 01:00:00.000000000 +0100
1034 +++ linux-2.6.6/include/linux/netfilter_ipv4/ipt_connmark.h 2004-05-18 14:28:50.000000000 +0200
1036 +#ifndef _IPT_CONNMARK_H
1037 +#define _IPT_CONNMARK_H
1039 +/* Copyright (C) 2002,2004 MARA Systems AB <http://www.marasystems.com>
1040 + * by Henrik Nordstrom <hno@marasystems.com>
1042 + * This program is free software; you can redistribute it and/or modify
1043 + * it under the terms of the GNU General Public License as published by
1044 + * the Free Software Foundation; either version 2 of the License, or
1045 + * (at your option) any later version.
1048 +struct ipt_connmark_info {
1049 + unsigned long mark, mask;
1053 +#endif /*_IPT_CONNMARK_H*/
1054 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_dstlimit.h linux-2.6.6/include/linux/netfilter_ipv4/ipt_dstlimit.h
1055 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_dstlimit.h 1970-01-01 01:00:00.000000000 +0100
1056 +++ linux-2.6.6/include/linux/netfilter_ipv4/ipt_dstlimit.h 2004-05-18 14:28:50.000000000 +0200
1058 +#ifndef _IPT_DSTLIMIT_H
1059 +#define _IPT_DSTLIMIT_H
1061 +/* timings are in milliseconds. */
1062 +#define IPT_DSTLIMIT_SCALE 10000
1063 +/* 1/10,000 sec period => max of 10,000/sec. Min rate is then 429490
1064 + seconds, or one every 59 hours. */
1066 +/* details of this structure hidden by the implementation */
1067 +struct ipt_dstlimit_htable;
1069 +#define IPT_DSTLIMIT_HASH_DIP 0x0001
1070 +#define IPT_DSTLIMIT_HASH_DPT 0x0002
1071 +#define IPT_DSTLIMIT_HASH_SIP 0x0004
1073 +struct dstlimit_cfg {
1074 + u_int32_t mode; /* bitmask of IPT_DSTLIMIT_HASH_* */
1075 + u_int32_t avg; /* Average secs between packets * scale */
1076 + u_int32_t burst; /* Period multiplier for upper limit. */
1078 + /* user specified */
1079 + u_int32_t size; /* how many buckets */
1080 + u_int32_t max; /* max number of entries */
1081 + u_int32_t gc_interval; /* gc interval */
1082 + u_int32_t expire; /* when do entries expire? */
1085 +struct ipt_dstlimit_info {
1086 + char name [IFNAMSIZ]; /* name */
1087 + struct dstlimit_cfg cfg;
1088 + struct ipt_dstlimit_htable *hinfo;
1090 + /* Used internally by the kernel */
1093 + struct ipt_dstlimit_info *master;
1096 +#endif /*_IPT_DSTLIMIT_H*/
1097 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_fuzzy.h linux-2.6.6/include/linux/netfilter_ipv4/ipt_fuzzy.h
1098 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_fuzzy.h 1970-01-01 01:00:00.000000000 +0100
1099 +++ linux-2.6.6/include/linux/netfilter_ipv4/ipt_fuzzy.h 2004-05-18 14:28:50.000000000 +0200
1101 +#ifndef _IPT_FUZZY_H
1102 +#define _IPT_FUZZY_H
1104 +#include <linux/param.h>
1105 +#include <linux/types.h>
1107 +#define MAXFUZZYRATE 10000000
1108 +#define MINFUZZYRATE 3
1110 +struct ipt_fuzzy_info {
1111 + u_int32_t minimum_rate;
1112 + u_int32_t maximum_rate;
1113 + u_int32_t packets_total;
1114 + u_int32_t bytes_total;
1115 + u_int32_t previous_time;
1116 + u_int32_t present_time;
1117 + u_int32_t mean_rate;
1118 + u_int8_t acceptance_rate;
1121 +#endif /*_IPT_FUZZY_H*/
1122 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_ipv4options.h linux-2.6.6/include/linux/netfilter_ipv4/ipt_ipv4options.h
1123 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_ipv4options.h 1970-01-01 01:00:00.000000000 +0100
1124 +++ linux-2.6.6/include/linux/netfilter_ipv4/ipt_ipv4options.h 2004-05-18 14:28:50.000000000 +0200
1126 +#ifndef __ipt_ipv4options_h_included__
1127 +#define __ipt_ipv4options_h_included__
1129 +#define IPT_IPV4OPTION_MATCH_SSRR 0x01 /* For strict source routing */
1130 +#define IPT_IPV4OPTION_MATCH_LSRR 0x02 /* For loose source routing */
1131 +#define IPT_IPV4OPTION_DONT_MATCH_SRR 0x04 /* any source routing */
1132 +#define IPT_IPV4OPTION_MATCH_RR 0x08 /* For Record route */
1133 +#define IPT_IPV4OPTION_DONT_MATCH_RR 0x10
1134 +#define IPT_IPV4OPTION_MATCH_TIMESTAMP 0x20 /* For timestamp request */
1135 +#define IPT_IPV4OPTION_DONT_MATCH_TIMESTAMP 0x40
1136 +#define IPT_IPV4OPTION_MATCH_ROUTER_ALERT 0x80 /* For router-alert */
1137 +#define IPT_IPV4OPTION_DONT_MATCH_ROUTER_ALERT 0x100
1138 +#define IPT_IPV4OPTION_MATCH_ANY_OPT 0x200 /* match packet with any option */
1139 +#define IPT_IPV4OPTION_DONT_MATCH_ANY_OPT 0x400 /* match packet with no option */
1141 +struct ipt_ipv4options_info {
1142 + u_int16_t options;
1146 +#endif /* __ipt_ipv4options_h_included__ */
1147 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_mport.h linux-2.6.6/include/linux/netfilter_ipv4/ipt_mport.h
1148 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_mport.h 1970-01-01 01:00:00.000000000 +0100
1149 +++ linux-2.6.6/include/linux/netfilter_ipv4/ipt_mport.h 2004-05-18 14:28:50.000000000 +0200
1151 +#ifndef _IPT_MPORT_H
1152 +#define _IPT_MPORT_H
1153 +#include <linux/netfilter_ipv4/ip_tables.h>
1155 +#define IPT_MPORT_SOURCE (1<<0)
1156 +#define IPT_MPORT_DESTINATION (1<<1)
1157 +#define IPT_MPORT_EITHER (IPT_MPORT_SOURCE|IPT_MPORT_DESTINATION)
1159 +#define IPT_MULTI_PORTS 15
1161 +/* Must fit inside union ipt_matchinfo: 32 bytes */
1162 +/* every entry in ports[] except for the last one has one bit in pflags
1163 + * associated with it. If this bit is set, the port is the first port of
1164 + * a portrange, with the next entry being the last.
1165 + * End of list is marked with pflags bit set and port=65535.
1166 + * If 14 ports are used (last one does not have a pflag), the last port
1167 + * is repeated to fill the last entry in ports[] */
1170 + u_int8_t flags:2; /* Type of comparison */
1171 + u_int16_t pflags:14; /* Port flags */
1172 + u_int16_t ports[IPT_MULTI_PORTS]; /* Ports */
1174 +#endif /*_IPT_MPORT_H*/
1175 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_nth.h linux-2.6.6/include/linux/netfilter_ipv4/ipt_nth.h
1176 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_nth.h 1970-01-01 01:00:00.000000000 +0100
1177 +++ linux-2.6.6/include/linux/netfilter_ipv4/ipt_nth.h 2004-05-18 14:28:50.000000000 +0200
1182 +#include <linux/param.h>
1183 +#include <linux/types.h>
1185 +#ifndef IPT_NTH_NUM_COUNTERS
1186 +#define IPT_NTH_NUM_COUNTERS 16
1189 +struct ipt_nth_info {
1197 +#endif /*_IPT_NTH_H*/
1198 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_osf.h linux-2.6.6/include/linux/netfilter_ipv4/ipt_osf.h
1199 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_osf.h 1970-01-01 01:00:00.000000000 +0100
1200 +++ linux-2.6.6/include/linux/netfilter_ipv4/ipt_osf.h 2004-05-18 14:28:50.000000000 +0200
1205 + * Copyright (c) 2003 Evgeniy Polyakov <johnpol@2ka.mipt.ru>
1208 + * This program is free software; you can redistribute it and/or modify
1209 + * it under the terms of the GNU General Public License as published by
1210 + * the Free Software Foundation; either version 2 of the License, or
1211 + * (at your option) any later version.
1213 + * This program is distributed in the hope that it will be useful,
1214 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1215 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1216 + * GNU General Public License for more details.
1218 + * You should have received a copy of the GNU General Public License
1219 + * along with this program; if not, write to the Free Software
1220 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1226 +#define MAXGENRELEN 32
1227 +#define MAXDETLEN 64
1229 +#define IPT_OSF_GENRE 1
1230 +#define IPT_OSF_SMART 2
1231 +#define IPT_OSF_LOG 4
1232 +#define IPT_OSF_NETLINK 8
1234 +#define IPT_OSF_LOGLEVEL_ALL 0
1235 +#define IPT_OSF_LOGLEVEL_FIRST 1
1237 +#include <linux/list.h>
1240 +#include <netinet/ip.h>
1241 +#include <netinet/tcp.h>
1245 + struct list_head *prev, *next;
1249 +struct ipt_osf_info
1251 + char genre[MAXGENRELEN];
1253 + unsigned long flags;
1255 + int invert; /* UNSUPPORTED */
1261 + unsigned long val;
1264 +/* This struct represents IANA options
1265 + * http://www.iana.org/assignments/tcp-parameters
1269 + unsigned char kind;
1270 + unsigned char length;
1276 + struct list_head flist;
1277 + struct osf_wc wss;
1278 + unsigned char ttl;
1281 + unsigned char genre[MAXGENRELEN];
1282 + unsigned char version[MAXGENRELEN], subtype[MAXGENRELEN];
1284 + /* Not needed, but for consistency with original table from Michal Zalewski */
1285 + unsigned char details[MAXDETLEN];
1288 + struct osf_opt opt[MAX_IPOPTLEN]; /* In case it is all NOP or EOL */
1292 +struct ipt_osf_nlmsg
1294 + struct osf_finger f;
1296 + struct tcphdr tcp;
1301 +/* Defines for IANA option kinds */
1303 +#define OSFOPT_EOL 0 /* End of options */
1304 +#define OSFOPT_NOP 1 /* NOP */
1305 +#define OSFOPT_MSS 2 /* Maximum segment size */
1306 +#define OSFOPT_WSO 3 /* Window scale option */
1307 +#define OSFOPT_SACKP 4 /* SACK permitted */
1308 +#define OSFOPT_SACK 5 /* SACK */
1309 +#define OSFOPT_ECHO 6
1310 +#define OSFOPT_ECHOREPLY 7
1311 +#define OSFOPT_TS 8 /* Timestamp option */
1312 +#define OSFOPT_POCP 9 /* Partial Order Connection Permitted */
1313 +#define OSFOPT_POSP 10 /* Partial Order Service Profile */
1314 +/* Others are not used in current OSF */
1316 +static struct osf_opt IANA_opts[] =
1323 + {5, 1 ,}, /* SACK length is not defined */
1329 + {11, 1,}, /* CC: Suppose 1 */
1330 + {12, 1,}, /* the same */
1331 + {13, 1,}, /* and here too */
1333 + {15, 1,}, /* TCP Alternate Checksum Data. Length is not defined */
1347 +#endif /* __KERNEL__ */
1349 +#endif /* _IPT_OSF_H */
1350 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_policy.h linux-2.6.6/include/linux/netfilter_ipv4/ipt_policy.h
1351 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_policy.h 1970-01-01 01:00:00.000000000 +0100
1352 +++ linux-2.6.6/include/linux/netfilter_ipv4/ipt_policy.h 2004-05-18 14:28:50.000000000 +0200
1354 +#ifndef _IPT_POLICY_H
1355 +#define _IPT_POLICY_H
1357 +#define POLICY_MAX_ELEM 4
1359 +enum ipt_policy_flags
1361 + POLICY_MATCH_IN = 0x1,
1362 + POLICY_MATCH_OUT = 0x2,
1363 + POLICY_MATCH_NONE = 0x4,
1364 + POLICY_MATCH_STRICT = 0x8,
1367 +enum ipt_policy_modes
1369 + POLICY_MODE_TRANSPORT,
1370 + POLICY_MODE_TUNNEL
1373 +struct ipt_policy_spec
1383 +struct ipt_policy_elem
1394 + struct ipt_policy_spec match;
1395 + struct ipt_policy_spec invert;
1398 +struct ipt_policy_info
1400 + struct ipt_policy_elem pol[POLICY_MAX_ELEM];
1405 +#endif /* _IPT_POLICY_H */
1406 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_pool.h linux-2.6.6/include/linux/netfilter_ipv4/ipt_pool.h
1407 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_pool.h 1970-01-01 01:00:00.000000000 +0100
1408 +++ linux-2.6.6/include/linux/netfilter_ipv4/ipt_pool.h 2004-05-18 14:28:50.000000000 +0200
1410 +#ifndef _IPT_POOL_H
1411 +#define _IPT_POOL_H
1413 +#include <linux/netfilter_ipv4/ip_pool.h>
1415 +#define IPT_POOL_INV_SRC 0x00000001
1416 +#define IPT_POOL_INV_DST 0x00000002
1417 +#define IPT_POOL_DEL_SRC 0x00000004
1418 +#define IPT_POOL_DEL_DST 0x00000008
1419 +#define IPT_POOL_INV_MOD_SRC 0x00000010
1420 +#define IPT_POOL_INV_MOD_DST 0x00000020
1421 +#define IPT_POOL_MOD_SRC_ACCEPT 0x00000040
1422 +#define IPT_POOL_MOD_DST_ACCEPT 0x00000080
1423 +#define IPT_POOL_MOD_SRC_DROP 0x00000100
1424 +#define IPT_POOL_MOD_DST_DROP 0x00000200
1427 +struct ipt_pool_info
1434 +#endif /*_IPT_POOL_H*/
1435 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_psd.h linux-2.6.6/include/linux/netfilter_ipv4/ipt_psd.h
1436 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_psd.h 1970-01-01 01:00:00.000000000 +0100
1437 +++ linux-2.6.6/include/linux/netfilter_ipv4/ipt_psd.h 2004-05-18 14:28:50.000000000 +0200
1442 +#include <linux/param.h>
1443 +#include <linux/types.h>
1446 + * High port numbers have a lower weight to reduce the frequency of false
1447 + * positives, such as from passive mode FTP transfers.
1449 +#define PORT_WEIGHT_PRIV 3
1450 +#define PORT_WEIGHT_HIGH 1
1453 + * Port scan detection thresholds: at least COUNT ports need to be scanned
1454 + * from the same source, with no longer than DELAY ticks between ports.
1456 +#define SCAN_MIN_COUNT 7
1457 +#define SCAN_MAX_COUNT (SCAN_MIN_COUNT * PORT_WEIGHT_PRIV)
1458 +#define SCAN_WEIGHT_THRESHOLD SCAN_MAX_COUNT
1459 +#define SCAN_DELAY_THRESHOLD (300) /* old usage of HZ here was erroneously and broke under uml */
1462 + * Keep track of up to LIST_SIZE source addresses, using a hash table of
1463 + * HASH_SIZE entries for faster lookups, but limiting hash collisions to
1464 + * HASH_MAX source addresses per the same hash value.
1466 +#define LIST_SIZE 0x100
1468 +#define HASH_SIZE (1 << HASH_LOG)
1469 +#define HASH_MAX 0x10
1471 +struct ipt_psd_info {
1472 + unsigned int weight_threshold;
1473 + unsigned int delay_threshold;
1474 + unsigned short lo_ports_weight;
1475 + unsigned short hi_ports_weight;
1478 +#endif /*_IPT_PSD_H*/
1479 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_quota.h linux-2.6.6/include/linux/netfilter_ipv4/ipt_quota.h
1480 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_quota.h 1970-01-01 01:00:00.000000000 +0100
1481 +++ linux-2.6.6/include/linux/netfilter_ipv4/ipt_quota.h 2004-05-18 14:28:50.000000000 +0200
1483 +#ifndef _IPT_QUOTA_H
1484 +#define _IPT_QUOTA_H
1486 +/* print debug info in both kernel/netfilter module & iptable library */
1487 +//#define DEBUG_IPT_QUOTA
1489 +struct ipt_quota_info {
1493 +#endif /*_IPT_QUOTA_H*/
1494 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_random.h linux-2.6.6/include/linux/netfilter_ipv4/ipt_random.h
1495 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_random.h 1970-01-01 01:00:00.000000000 +0100
1496 +++ linux-2.6.6/include/linux/netfilter_ipv4/ipt_random.h 2004-05-18 14:28:50.000000000 +0200
1498 +#ifndef _IPT_RAND_H
1499 +#define _IPT_RAND_H
1501 +#include <linux/param.h>
1502 +#include <linux/types.h>
1504 +struct ipt_rand_info {
1508 +#endif /*_IPT_RAND_H*/
1509 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_realm.h linux-2.6.6/include/linux/netfilter_ipv4/ipt_realm.h
1510 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_realm.h 1970-01-01 01:00:00.000000000 +0100
1511 +++ linux-2.6.6/include/linux/netfilter_ipv4/ipt_realm.h 2004-05-18 14:28:50.000000000 +0200
1513 +#ifndef _IPT_REALM_H
1514 +#define _IPT_REALM_H
1516 +struct ipt_realm_info {
1521 +#endif /*_IPT_REALM_H*/
1522 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_sctp.h linux-2.6.6/include/linux/netfilter_ipv4/ipt_sctp.h
1523 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_sctp.h 1970-01-01 01:00:00.000000000 +0100
1524 +++ linux-2.6.6/include/linux/netfilter_ipv4/ipt_sctp.h 2004-05-18 14:28:50.000000000 +0200
1526 +#ifndef _IPT_SCTP_H_
1527 +#define _IPT_SCTP_H_
1529 +#define IPT_SCTP_SRC_PORTS 0x01
1530 +#define IPT_SCTP_DEST_PORTS 0x02
1531 +#define IPT_SCTP_CHUNK_TYPES 0x04
1533 +#define IPT_SCTP_VALID_FLAGS 0x07
1535 +#define ELEMCOUNT(x) (sizeof(x)/sizeof(x[0]))
1538 +struct ipt_sctp_flag_info {
1539 + u_int8_t chunktype;
1541 + u_int8_t flag_mask;
1544 +#define IPT_NUM_SCTP_FLAGS 4
1546 +struct ipt_sctp_info {
1547 + u_int16_t dpts[2]; /* Min, Max */
1548 + u_int16_t spts[2]; /* Min, Max */
1550 + u_int32_t chunkmap[256 / sizeof (u_int32_t)]; /* Bit mask of chunks to be matched according to RFC 2960 */
1552 +#define SCTP_CHUNK_MATCH_ANY 0x01 /* Match if any of the chunk types are present */
1553 +#define SCTP_CHUNK_MATCH_ALL 0x02 /* Match if all of the chunk types are present */
1554 +#define SCTP_CHUNK_MATCH_ONLY 0x04 /* Match if these are the only chunk types present */
1556 + u_int32_t chunk_match_type;
1557 + struct ipt_sctp_flag_info flag_info[IPT_NUM_SCTP_FLAGS];
1561 + u_int32_t invflags;
1564 +#define bytes(type) (sizeof(type) * 8)
1566 +#define SCTP_CHUNKMAP_SET(chunkmap, type) \
1568 + chunkmap[type / bytes(u_int32_t)] |= \
1569 + 1 << (type % bytes(u_int32_t)); \
1572 +#define SCTP_CHUNKMAP_CLEAR(chunkmap, type) \
1574 + chunkmap[type / bytes(u_int32_t)] &= \
1575 + ~(1 << (type % bytes(u_int32_t))); \
1578 +#define SCTP_CHUNKMAP_IS_SET(chunkmap, type) \
1580 + (chunkmap[type / bytes (u_int32_t)] & \
1581 + (1 << (type % bytes (u_int32_t)))) ? 1: 0; \
1584 +#define SCTP_CHUNKMAP_RESET(chunkmap) \
1587 + for (i = 0; i < ELEMCOUNT(chunkmap); i++) \
1588 + chunkmap[i] = 0; \
1591 +#define SCTP_CHUNKMAP_SET_ALL(chunkmap) \
1594 + for (i = 0; i < ELEMCOUNT(chunkmap); i++) \
1595 + chunkmap[i] = ~0; \
1598 +#define SCTP_CHUNKMAP_COPY(destmap, srcmap) \
1601 + for (i = 0; i < ELEMCOUNT(chunkmap); i++) \
1602 + destmap[i] = srcmap[i]; \
1605 +#define SCTP_CHUNKMAP_IS_CLEAR(chunkmap) \
1609 + for (i = 0; i < ELEMCOUNT(chunkmap); i++) { \
1610 + if (chunkmap[i]) { \
1618 +#define SCTP_CHUNKMAP_IS_ALL_SET(chunkmap) \
1622 + for (i = 0; i < ELEMCOUNT(chunkmap); i++) { \
1623 + if (chunkmap[i] != ~0) { \
1631 +#endif /* _IPT_SCTP_H_ */
1633 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_string.h linux-2.6.6/include/linux/netfilter_ipv4/ipt_string.h
1634 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_string.h 1970-01-01 01:00:00.000000000 +0100
1635 +++ linux-2.6.6/include/linux/netfilter_ipv4/ipt_string.h 2004-05-18 14:28:50.000000000 +0200
1637 +#ifndef _IPT_STRING_H
1638 +#define _IPT_STRING_H
1640 +/* *** PERFORMANCE TWEAK ***
1641 + * Packet size and search string threshold,
1642 + * above which sublinear searches is used. */
1643 +#define IPT_STRING_HAYSTACK_THRESH 100
1644 +#define IPT_STRING_NEEDLE_THRESH 20
1646 +#define BM_MAX_NLEN 256
1647 +#define BM_MAX_HLEN 1024
1649 +typedef char *(*proc_ipt_search) (char *, char *, int, int);
1651 +struct ipt_string_info {
1652 + char string[BM_MAX_NLEN];
1657 +#endif /* _IPT_STRING_H */
1658 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_time.h linux-2.6.6/include/linux/netfilter_ipv4/ipt_time.h
1659 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_time.h 1970-01-01 01:00:00.000000000 +0100
1660 +++ linux-2.6.6/include/linux/netfilter_ipv4/ipt_time.h 2004-05-18 14:28:50.000000000 +0200
1662 +#ifndef __ipt_time_h_included__
1663 +#define __ipt_time_h_included__
1666 +struct ipt_time_info {
1667 + u_int8_t days_match; /* 1 bit per day. -SMTWTFS */
1668 + u_int16_t time_start; /* 0 < time_start < 23*60+59 = 1439 */
1669 + u_int16_t time_stop; /* 0:0 < time_stat < 23:59 */
1670 + u_int8_t kerneltime; /* ignore skb time (and use kerneltime) or not. */
1671 + time_t date_start;
1676 +#endif /* __ipt_time_h_included__ */
1677 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_u32.h linux-2.6.6/include/linux/netfilter_ipv4/ipt_u32.h
1678 --- linux-2.6.6.org/include/linux/netfilter_ipv4/ipt_u32.h 1970-01-01 01:00:00.000000000 +0100
1679 +++ linux-2.6.6/include/linux/netfilter_ipv4/ipt_u32.h 2004-05-18 14:28:50.000000000 +0200
1683 +#include <linux/netfilter_ipv4/ip_tables.h>
1693 +struct ipt_u32_location_element
1698 +struct ipt_u32_value_element
1703 +/* *** any way to allow for an arbitrary number of elements?
1704 + for now I settle for a limit of 10 of each */
1705 +#define U32MAXSIZE 10
1706 +struct ipt_u32_test
1709 + struct ipt_u32_location_element location[U32MAXSIZE+1];
1711 + struct ipt_u32_value_element value[U32MAXSIZE+1];
1717 + struct ipt_u32_test tests[U32MAXSIZE+1];
1720 +#endif /*_IPT_U32_H*/
1721 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv4.h linux-2.6.6/include/linux/netfilter_ipv4.h
1722 --- linux-2.6.6.org/include/linux/netfilter_ipv4.h 2004-05-10 04:33:13.000000000 +0200
1723 +++ linux-2.6.6/include/linux/netfilter_ipv4.h 2004-05-18 14:28:50.000000000 +0200
1726 #include <linux/config.h>
1727 #include <linux/netfilter.h>
1728 +#include <linux/netdevice.h>
1729 +#include <net/protocol.h>
1731 /* IP Cache bits. */
1732 /* Src IP address. */
1734 Returns true or false. */
1735 extern int skb_ip_make_writable(struct sk_buff **pskb,
1736 unsigned int writable_len);
1738 +#if defined(CONFIG_XFRM) && defined(CONFIG_NETFILTER)
1739 +#include <net/route.h>
1740 +#include <net/xfrm.h>
1742 +static inline int nf_hook_input_cond(struct sk_buff *skb)
1744 + return !skb->sp || skb->sp->decap_done;
1748 +nf_xfrm_local_done(struct sk_buff *skb, struct inet_protocol *ipprot)
1750 + return skb->sp && !skb->sp->decap_done
1751 + && (!ipprot || !ipprot->xfrm_prot);
1754 +static inline int nf_xfrm_nonlocal_done(struct sk_buff *skb)
1756 + return skb->sp && !skb->sp->decap_done
1757 + && !(((struct rtable *)skb->dst)->rt_flags&RTCF_LOCAL);
1760 +extern int nf_rcv_postxfrm_local(struct sk_buff *skb);
1761 +extern int nf_rcv_postxfrm_nonlocal(struct sk_buff *skb);
1762 +#else /* CONFIG_XFRM */
1763 +static inline int nf_hook_input_cond(struct sk_buff *skb)
1769 +nf_xfrm_local_done(struct sk_buff *skb, struct inet_protocol *ipprot)
1774 +static inline int nf_xfrm_nonlocal_done(struct sk_buff *skb)
1779 +static inline int nf_rcv_postxfrm_local(struct sk_buff *skb)
1784 +static inline int nf_rcv_postxfrm_nonlocal(struct sk_buff *skb)
1788 +#endif /* CONFIG_XFRM */
1789 #endif /*__KERNEL__*/
1791 #endif /*__LINUX_IP_NETFILTER_H*/
1792 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv6/ip6_tables.h linux-2.6.6/include/linux/netfilter_ipv6/ip6_tables.h
1793 --- linux-2.6.6.org/include/linux/netfilter_ipv6/ip6_tables.h 2004-05-10 04:33:20.000000000 +0200
1794 +++ linux-2.6.6/include/linux/netfilter_ipv6/ip6_tables.h 2004-05-18 14:28:50.000000000 +0200
1795 @@ -140,6 +140,12 @@
1797 unsigned int comefrom;
1799 + /* Name of the chain */
1802 + /* Rule number in the chain. */
1803 + u_int32_t rulenum;
1805 /* Packet and byte counters. */
1806 struct ip6t_counters counters;
1808 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv6/ip6t_HL.h linux-2.6.6/include/linux/netfilter_ipv6/ip6t_HL.h
1809 --- linux-2.6.6.org/include/linux/netfilter_ipv6/ip6t_HL.h 1970-01-01 01:00:00.000000000 +0100
1810 +++ linux-2.6.6/include/linux/netfilter_ipv6/ip6t_HL.h 2004-05-18 14:28:50.000000000 +0200
1812 +/* Hop Limit modification module for ip6tables
1813 + * Maciej Soltysiak <solt@dns.toxicfilms.tv>
1814 + * Based on HW's TTL module */
1825 +#define IP6T_HL_MAXMODE IP6T_HL_DEC
1827 +struct ip6t_HL_info {
1829 + u_int8_t hop_limit;
1834 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv6/ip6t_REJECT.h linux-2.6.6/include/linux/netfilter_ipv6/ip6t_REJECT.h
1835 --- linux-2.6.6.org/include/linux/netfilter_ipv6/ip6t_REJECT.h 2004-05-10 04:31:58.000000000 +0200
1836 +++ linux-2.6.6/include/linux/netfilter_ipv6/ip6t_REJECT.h 2004-05-18 14:28:50.000000000 +0200
1838 #define _IP6T_REJECT_H
1840 enum ip6t_reject_with {
1841 - IP6T_ICMP_NET_UNREACHABLE,
1842 - IP6T_ICMP_HOST_UNREACHABLE,
1843 - IP6T_ICMP_PROT_UNREACHABLE,
1844 - IP6T_ICMP_PORT_UNREACHABLE,
1845 - IP6T_ICMP_ECHOREPLY
1846 + IP6T_ICMP6_NO_ROUTE,
1847 + IP6T_ICMP6_ADM_PROHIBITED,
1848 + IP6T_ICMP6_NOT_NEIGHBOUR,
1849 + IP6T_ICMP6_ADDR_UNREACH,
1850 + IP6T_ICMP6_PORT_UNREACH,
1851 + IP6T_ICMP6_ECHOREPLY,
1855 struct ip6t_reject_info {
1856 enum ip6t_reject_with with; /* reject type */
1859 -#endif /*_IPT_REJECT_H*/
1860 +#endif /*_IP6T_REJECT_H*/
1861 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv6/ip6t_ROUTE.h linux-2.6.6/include/linux/netfilter_ipv6/ip6t_ROUTE.h
1862 --- linux-2.6.6.org/include/linux/netfilter_ipv6/ip6t_ROUTE.h 1970-01-01 01:00:00.000000000 +0100
1863 +++ linux-2.6.6/include/linux/netfilter_ipv6/ip6t_ROUTE.h 2004-05-18 14:28:50.000000000 +0200
1865 +/* Header file for iptables ip6t_ROUTE target
1867 + * (C) 2003 by Cédric de Launois <delaunois@info.ucl.ac.be>
1869 + * This software is distributed under GNU GPL v2, 1991
1871 +#ifndef _IPT_ROUTE_H_target
1872 +#define _IPT_ROUTE_H_target
1874 +#define IP6T_ROUTE_IFNAMSIZ 16
1876 +struct ip6t_route_target_info {
1877 + char oif[IP6T_ROUTE_IFNAMSIZ]; /* Output Interface Name */
1878 + char iif[IP6T_ROUTE_IFNAMSIZ]; /* Input Interface Name */
1879 + u_int32_t gw[4]; /* IPv6 address of gateway */
1883 +/* Values for "flags" field */
1884 +#define IP6T_ROUTE_CONTINUE 0x01
1886 +#endif /*_IP6T_ROUTE_H_target*/
1887 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv6/ip6t_fuzzy.h linux-2.6.6/include/linux/netfilter_ipv6/ip6t_fuzzy.h
1888 --- linux-2.6.6.org/include/linux/netfilter_ipv6/ip6t_fuzzy.h 1970-01-01 01:00:00.000000000 +0100
1889 +++ linux-2.6.6/include/linux/netfilter_ipv6/ip6t_fuzzy.h 2004-05-18 14:28:50.000000000 +0200
1891 +#ifndef _IP6T_FUZZY_H
1892 +#define _IP6T_FUZZY_H
1894 +#include <linux/param.h>
1895 +#include <linux/types.h>
1897 +#define MAXFUZZYRATE 10000000
1898 +#define MINFUZZYRATE 3
1900 +struct ip6t_fuzzy_info {
1901 + u_int32_t minimum_rate;
1902 + u_int32_t maximum_rate;
1903 + u_int32_t packets_total;
1904 + u_int32_t bytes_total;
1905 + u_int32_t previous_time;
1906 + u_int32_t present_time;
1907 + u_int32_t mean_rate;
1908 + u_int8_t acceptance_rate;
1911 +#endif /*_IP6T_FUZZY_H*/
1912 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv6/ip6t_nth.h linux-2.6.6/include/linux/netfilter_ipv6/ip6t_nth.h
1913 --- linux-2.6.6.org/include/linux/netfilter_ipv6/ip6t_nth.h 1970-01-01 01:00:00.000000000 +0100
1914 +++ linux-2.6.6/include/linux/netfilter_ipv6/ip6t_nth.h 2004-05-18 14:28:50.000000000 +0200
1916 +#ifndef _IP6T_NTH_H
1917 +#define _IP6T_NTH_H
1919 +#include <linux/param.h>
1920 +#include <linux/types.h>
1922 +#ifndef IP6T_NTH_NUM_COUNTERS
1923 +#define IP6T_NTH_NUM_COUNTERS 16
1926 +struct ip6t_nth_info {
1934 +#endif /*_IP6T_NTH_H*/
1935 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv6/ip6t_owner.h linux-2.6.6/include/linux/netfilter_ipv6/ip6t_owner.h
1936 --- linux-2.6.6.org/include/linux/netfilter_ipv6/ip6t_owner.h 2004-05-10 04:32:52.000000000 +0200
1937 +++ linux-2.6.6/include/linux/netfilter_ipv6/ip6t_owner.h 2004-05-18 14:28:50.000000000 +0200
1939 #define IP6T_OWNER_GID 0x02
1940 #define IP6T_OWNER_PID 0x04
1941 #define IP6T_OWNER_SID 0x08
1942 +#define IP6T_OWNER_COMM 0x10
1944 struct ip6t_owner_info {
1950 u_int8_t match, invert; /* flags */
1953 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv6/ip6t_policy.h linux-2.6.6/include/linux/netfilter_ipv6/ip6t_policy.h
1954 --- linux-2.6.6.org/include/linux/netfilter_ipv6/ip6t_policy.h 1970-01-01 01:00:00.000000000 +0100
1955 +++ linux-2.6.6/include/linux/netfilter_ipv6/ip6t_policy.h 2004-05-18 14:28:50.000000000 +0200
1957 +#ifndef _IP6T_POLICY_H
1958 +#define _IP6T_POLICY_H
1960 +#define POLICY_MAX_ELEM 4
1962 +enum ip6t_policy_flags
1964 + POLICY_MATCH_IN = 0x1,
1965 + POLICY_MATCH_OUT = 0x2,
1966 + POLICY_MATCH_NONE = 0x4,
1967 + POLICY_MATCH_STRICT = 0x8,
1970 +enum ip6t_policy_modes
1972 + POLICY_MODE_TRANSPORT,
1973 + POLICY_MODE_TUNNEL
1976 +struct ip6t_policy_spec
1986 +struct ip6t_policy_elem
1988 + struct in6_addr saddr;
1989 + struct in6_addr smask;
1990 + struct in6_addr daddr;
1991 + struct in6_addr dmask;
1997 + struct ip6t_policy_spec match;
1998 + struct ip6t_policy_spec invert;
2001 +struct ip6t_policy_info
2003 + struct ip6t_policy_elem pol[POLICY_MAX_ELEM];
2008 +#endif /* _IP6T_POLICY_H */
2009 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_ipv6/ip6t_random.h linux-2.6.6/include/linux/netfilter_ipv6/ip6t_random.h
2010 --- linux-2.6.6.org/include/linux/netfilter_ipv6/ip6t_random.h 1970-01-01 01:00:00.000000000 +0100
2011 +++ linux-2.6.6/include/linux/netfilter_ipv6/ip6t_random.h 2004-05-18 14:28:50.000000000 +0200
2013 +#ifndef _IP6T_RAND_H
2014 +#define _IP6T_RAND_H
2016 +#include <linux/param.h>
2017 +#include <linux/types.h>
2019 +struct ip6t_rand_info {
2023 +#endif /*_IP6T_RAND_H*/
2024 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/netfilter_mime.h linux-2.6.6/include/linux/netfilter_mime.h
2025 --- linux-2.6.6.org/include/linux/netfilter_mime.h 1970-01-01 01:00:00.000000000 +0100
2026 +++ linux-2.6.6/include/linux/netfilter_mime.h 2004-05-18 14:28:50.000000000 +0200
2029 + * MIME functions for netfilter modules. This file provides implementations
2030 + * for basic MIME parsing. MIME headers are used in many protocols, such as
2031 + * HTTP, RTSP, SIP, etc.
2033 + * gcc will warn for defined but unused functions, so we only include the
2034 + * functions requested. The following macros are used:
2035 + * NF_NEED_MIME_NEXTLINE nf_mime_nextline()
2037 +#ifndef _NETFILTER_MIME_H
2038 +#define _NETFILTER_MIME_H
2040 +/* Only include these functions for kernel code. */
2043 +#include <linux/ctype.h>
2046 + * Given a buffer and length, advance to the next line and mark the current
2047 + * line. If the current line is empty, *plinelen will be set to zero. If
2048 + * not, it will be set to the actual line length (including CRLF).
2050 + * 'line' in this context means logical line (includes LWS continuations).
2051 + * Returns 1 on success, 0 on failure.
2053 +#ifdef NF_NEED_MIME_NEXTLINE
2055 +nf_mime_nextline(char* p, uint len, uint* poff, uint* plineoff, uint* plinelen)
2059 + int is_first_line = 1;
2068 + while (p[off] != '\n')
2079 + /* if we saw a crlf, physlen needs adjusted */
2080 + if (physlen > 0 && p[off] == '\n' && p[off-1] == '\r')
2085 + /* advance past the newline */
2088 + /* check for an empty line */
2094 + /* check for colon on the first physical line */
2095 + if (is_first_line)
2097 + is_first_line = 0;
2098 + if (memchr(p+(*poff), ':', physlen) == NULL)
2104 + while (p[off] == ' ' || p[off] == '\t');
2106 + *plineoff = *poff;
2107 + *plinelen = (physlen == 0) ? 0 : (off - *poff);
2112 +#endif /* NF_NEED_MIME_NEXTLINE */
2114 +#endif /* __KERNEL__ */
2116 +#endif /* _NETFILTER_MIME_H */
2117 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/linux/skbuff.h linux-2.6.6/include/linux/skbuff.h
2118 --- linux-2.6.6.org/include/linux/skbuff.h 2004-05-10 04:32:39.000000000 +0200
2119 +++ linux-2.6.6/include/linux/skbuff.h 2004-05-18 14:28:50.000000000 +0200
2120 @@ -1049,6 +1049,14 @@
2122 atomic_inc(&nfct->master->use);
2124 +static inline void nf_reset(struct sk_buff *skb)
2126 + nf_conntrack_put(skb->nfct);
2128 +#ifdef CONFIG_NETFILTER_DEBUG
2129 + skb->nf_debug = 0;
2133 #ifdef CONFIG_BRIDGE_NETFILTER
2134 static inline void nf_bridge_put(struct nf_bridge_info *nf_bridge)
2135 @@ -1061,9 +1069,10 @@
2137 atomic_inc(&nf_bridge->use);
2142 +#endif /* CONFIG_BRIDGE_NETFILTER */
2143 +#else /* CONFIG_NETFILTER */
2144 +static inline void nf_reset(struct sk_buff *skb) {}
2145 +#endif /* CONFIG_NETFILTER */
2147 #endif /* __KERNEL__ */
2148 #endif /* _LINUX_SKBUFF_H */
2149 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/net/ip.h linux-2.6.6/include/net/ip.h
2150 --- linux-2.6.6.org/include/net/ip.h 2004-05-10 04:32:53.000000000 +0200
2151 +++ linux-2.6.6/include/net/ip.h 2004-05-18 14:28:50.000000000 +0200
2153 #include <linux/netdevice.h>
2154 #include <linux/inetdevice.h>
2155 #include <linux/in_route.h>
2156 +#include <linux/netfilter.h>
2157 +#include <linux/netfilter_ipv4.h>
2158 #include <net/route.h>
2159 #include <net/arp.h>
2162 #define IPSKB_TRANSLATED 2
2163 #define IPSKB_FORWARDED 4
2164 #define IPSKB_XFRM_TUNNEL_SIZE 8
2165 +#define IPSKB_XFRM_TRANSFORMED 16
2169 @@ -212,6 +215,12 @@
2170 __ip_select_ident(iph, dst, more);
2173 +extern inline int ip_dst_output(struct sk_buff *skb)
2175 + return NF_HOOK_COND(PF_INET, NF_IP_POST_ROUTING, skb, NULL,
2176 + skb->dst->dev, dst_output, skb->dst->xfrm != NULL);
2180 * Map a multicast IP onto multicast MAC for type ethernet.
2182 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/net/protocol.h linux-2.6.6/include/net/protocol.h
2183 --- linux-2.6.6.org/include/net/protocol.h 2004-05-10 04:32:28.000000000 +0200
2184 +++ linux-2.6.6/include/net/protocol.h 2004-05-18 14:28:50.000000000 +0200
2186 int (*handler)(struct sk_buff *skb);
2187 void (*err_handler)(struct sk_buff *skb, u32 info);
2192 #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
2193 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/net/tcp.h linux-2.6.6/include/net/tcp.h
2194 --- linux-2.6.6.org/include/net/tcp.h 2004-05-10 04:32:01.000000000 +0200
2195 +++ linux-2.6.6/include/net/tcp.h 2004-05-18 14:28:50.000000000 +0200
2197 extern void tcp_bucket_unlock(struct sock *sk);
2198 extern int tcp_port_rover;
2199 extern struct sock *tcp_v4_lookup_listener(u32 addr, unsigned short hnum, int dif);
2200 +extern struct sock *tcp_v4_lookup(u32 saddr, u16 sport, u32 daddr, u16 hnum, int dif);
2202 /* These are AF independent. */
2203 static __inline__ int tcp_bhashfn(__u16 lport)
2204 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/net/udp.h linux-2.6.6/include/net/udp.h
2205 --- linux-2.6.6.org/include/net/udp.h 2004-05-10 04:33:13.000000000 +0200
2206 +++ linux-2.6.6/include/net/udp.h 2004-05-18 14:28:50.000000000 +0200
2208 extern int udp_ioctl(struct sock *sk, int cmd, unsigned long arg);
2209 extern int udp_disconnect(struct sock *sk, int flags);
2211 +extern struct sock *udp_v4_lookup(u32 saddr, u16 sport, u32 daddr, u16 dport, int dif);
2213 DECLARE_SNMP_STAT(struct udp_mib, udp_statistics);
2214 #define UDP_INC_STATS(field) SNMP_INC_STATS(udp_statistics, field)
2215 #define UDP_INC_STATS_BH(field) SNMP_INC_STATS_BH(udp_statistics, field)
2216 diff -Nur --exclude '*.orig' linux-2.6.6.org/include/net/xfrm.h linux-2.6.6/include/net/xfrm.h
2217 --- linux-2.6.6.org/include/net/xfrm.h 2004-05-10 04:33:13.000000000 +0200
2218 +++ linux-2.6.6/include/net/xfrm.h 2004-05-18 14:28:50.000000000 +0200
2223 +#ifdef CONFIG_NETFILTER
2226 struct sec_decap_state x[XFRM_MAX_DEPTH];
2229 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/core/netfilter.c linux-2.6.6/net/core/netfilter.c
2230 --- linux-2.6.6.org/net/core/netfilter.c 2004-05-10 04:32:29.000000000 +0200
2231 +++ linux-2.6.6/net/core/netfilter.c 2004-05-18 14:28:50.000000000 +0200
2233 #include <linux/icmp.h>
2234 #include <net/sock.h>
2235 #include <net/route.h>
2236 +#include <net/xfrm.h>
2237 +#include <net/ip.h>
2238 #include <linux/ip.h>
2240 /* In this code, we can be waiting indefinitely for userspace to
2242 #ifdef CONFIG_IP_ROUTE_FWMARK
2243 fl.nl_u.ip4_u.fwmark = (*pskb)->nfmark;
2245 - fl.proto = iph->protocol;
2246 if (ip_route_output_key(&rt, &fl) != 0)
2249 @@ -665,6 +666,20 @@
2250 if ((*pskb)->dst->error)
2254 + if (!(IPCB(*pskb)->flags & IPSKB_XFRM_TRANSFORMED)) {
2255 + struct xfrm_policy_afinfo *afinfo;
2257 + afinfo = xfrm_policy_get_afinfo(AF_INET);
2258 + if (afinfo != NULL) {
2259 + afinfo->decode_session(*pskb, &fl);
2260 + xfrm_policy_put_afinfo(afinfo);
2261 + if (xfrm_lookup(&(*pskb)->dst, &fl, (*pskb)->sk, 0) != 0)
2267 /* Change in oif may mean change in hh_len. */
2268 hh_len = (*pskb)->dst->dev->hard_header_len;
2269 if (skb_headroom(*pskb) < hh_len) {
2270 @@ -682,6 +697,71 @@
2275 +inline int nf_rcv_postxfrm_nonlocal(struct sk_buff *skb)
2277 + skb->sp->decap_done = 1;
2278 + dst_release(skb->dst);
2281 + return netif_rx(skb);
2284 +int nf_rcv_postxfrm_local(struct sk_buff *skb)
2286 + __skb_push(skb, skb->data - skb->nh.raw);
2287 + /* Fix header len and checksum if last xfrm was transport mode */
2288 + if (!skb->sp->x[skb->sp->len - 1].xvec->props.mode) {
2289 + skb->nh.iph->tot_len = htons(skb->len);
2290 + ip_send_check(skb->nh.iph);
2292 + return nf_rcv_postxfrm_nonlocal(skb);
2295 +#ifdef CONFIG_IP_NF_NAT_NEEDED
2296 +#include <linux/netfilter_ipv4/ip_conntrack.h>
2297 +#include <linux/netfilter_ipv4/ip_nat.h>
2299 +void nf_nat_decode_session4(struct sk_buff *skb, struct flowi *fl)
2301 + struct ip_conntrack *ct;
2302 + struct ip_conntrack_tuple *t;
2303 + struct ip_nat_info_manip *m;
2306 + if (skb->nfct == NULL)
2308 + ct = (struct ip_conntrack *)skb->nfct->master;
2310 + for (i = 0; i < ct->nat.info.num_manips; i++) {
2311 + m = &ct->nat.info.manips[i];
2312 + t = &ct->tuplehash[m->direction].tuple;
2314 + switch (m->hooknum) {
2315 + case NF_IP_PRE_ROUTING:
2316 + if (m->maniptype != IP_NAT_MANIP_DST)
2318 + fl->fl4_dst = t->dst.ip;
2319 + if (t->dst.protonum == IPPROTO_TCP ||
2320 + t->dst.protonum == IPPROTO_UDP)
2321 + fl->fl_ip_dport = t->dst.u.tcp.port;
2323 +#ifdef CONFIG_IP_NF_NAT_LOCAL
2324 + case NF_IP_LOCAL_IN:
2325 + if (m->maniptype != IP_NAT_MANIP_SRC)
2327 + fl->fl4_src = t->src.ip;
2328 + if (t->dst.protonum == IPPROTO_TCP ||
2329 + t->dst.protonum == IPPROTO_UDP)
2330 + fl->fl_ip_sport = t->src.u.tcp.port;
2336 +#endif /* CONFIG_IP_NF_NAT_NEEDED */
2339 int skb_ip_make_writable(struct sk_buff **pskb, unsigned int writable_len)
2341 struct sk_buff *nskb;
2343 EXPORT_SYMBOL(nf_unregister_hook);
2344 EXPORT_SYMBOL(nf_unregister_queue_handler);
2345 EXPORT_SYMBOL(nf_unregister_sockopt);
2346 +EXPORT_SYMBOL(nf_rcv_postxfrm_local);
2347 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/ah4.c linux-2.6.6/net/ipv4/ah4.c
2348 --- linux-2.6.6.org/net/ipv4/ah4.c 2004-05-10 04:33:19.000000000 +0200
2349 +++ linux-2.6.6/net/ipv4/ah4.c 2004-05-18 14:28:50.000000000 +0200
2351 err = -EHOSTUNREACH;
2354 + IPCB(skb)->flags |= IPSKB_XFRM_TRANSFORMED;
2355 return NET_XMIT_BYPASS;
2359 .handler = xfrm4_rcv,
2360 .err_handler = ah4_err,
2365 static int __init ah4_init(void)
2366 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/esp4.c linux-2.6.6/net/ipv4/esp4.c
2367 --- linux-2.6.6.org/net/ipv4/esp4.c 2004-05-10 04:32:39.000000000 +0200
2368 +++ linux-2.6.6/net/ipv4/esp4.c 2004-05-18 14:28:50.000000000 +0200
2370 err = -EHOSTUNREACH;
2373 + IPCB(skb)->flags |= IPSKB_XFRM_TRANSFORMED;
2374 return NET_XMIT_BYPASS;
2378 .handler = xfrm4_rcv,
2379 .err_handler = esp4_err,
2384 static int __init esp4_init(void)
2385 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/igmp.c linux-2.6.6/net/ipv4/igmp.c
2386 --- linux-2.6.6.org/net/ipv4/igmp.c 2004-05-10 04:33:21.000000000 +0200
2387 +++ linux-2.6.6/net/ipv4/igmp.c 2004-05-18 14:28:50.000000000 +0200
2389 pig->csum = ip_compute_csum((void *)skb->h.igmph, igmplen);
2391 return NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, skb, NULL, skb->dev,
2396 static int grec_size(struct ip_mc_list *pmc, int type, int gdel, int sdel)
2398 ih->csum=ip_compute_csum((void *)ih, sizeof(struct igmphdr));
2400 return NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, skb, NULL, rt->u.dst.dev,
2405 static void igmp_gq_timer_expire(unsigned long data)
2406 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/ip_forward.c linux-2.6.6/net/ipv4/ip_forward.c
2407 --- linux-2.6.6.org/net/ipv4/ip_forward.c 2004-05-10 04:31:58.000000000 +0200
2408 +++ linux-2.6.6/net/ipv4/ip_forward.c 2004-05-18 14:28:50.000000000 +0200
2410 if (unlikely(opt->optlen))
2411 ip_forward_options(skb);
2413 - return dst_output(skb);
2414 + return ip_dst_output(skb);
2417 int ip_forward(struct sk_buff *skb)
2418 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/ip_gre.c linux-2.6.6/net/ipv4/ip_gre.c
2419 --- linux-2.6.6.org/net/ipv4/ip_gre.c 2004-05-10 04:32:54.000000000 +0200
2420 +++ linux-2.6.6/net/ipv4/ip_gre.c 2004-05-18 14:28:50.000000000 +0200
2421 @@ -643,13 +643,7 @@
2422 skb->dev = tunnel->dev;
2423 dst_release(skb->dst);
2425 -#ifdef CONFIG_NETFILTER
2426 - nf_conntrack_put(skb->nfct);
2428 -#ifdef CONFIG_NETFILTER_DEBUG
2429 - skb->nf_debug = 0;
2433 ipgre_ecn_decapsulate(iph, skb);
2435 read_unlock(&ipgre_lock);
2436 @@ -877,13 +871,7 @@
2440 -#ifdef CONFIG_NETFILTER
2441 - nf_conntrack_put(skb->nfct);
2443 -#ifdef CONFIG_NETFILTER_DEBUG
2444 - skb->nf_debug = 0;
2450 tunnel->recursion--;
2451 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/ip_input.c linux-2.6.6/net/ipv4/ip_input.c
2452 --- linux-2.6.6.org/net/ipv4/ip_input.c 2004-05-10 04:31:59.000000000 +0200
2453 +++ linux-2.6.6/net/ipv4/ip_input.c 2004-05-18 14:28:50.000000000 +0200
2454 @@ -202,18 +202,10 @@
2456 #ifdef CONFIG_NETFILTER_DEBUG
2457 nf_debug_ip_local_deliver(skb);
2458 - skb->nf_debug = 0;
2459 #endif /*CONFIG_NETFILTER_DEBUG*/
2461 __skb_pull(skb, ihl);
2463 -#ifdef CONFIG_NETFILTER
2464 - /* Free reference early: we don't need it any more, and it may
2465 - hold ip_conntrack module loaded indefinitely. */
2466 - nf_conntrack_put(skb->nfct);
2468 -#endif /*CONFIG_NETFILTER*/
2470 /* Point into the IP datagram, just past the header. */
2471 skb->h.raw = skb->data;
2473 @@ -228,6 +220,13 @@
2475 hash = protocol & (MAX_INET_PROTOS - 1);
2476 raw_sk = sk_head(&raw_v4_htable[hash]);
2477 + ipprot = inet_protos[hash];
2478 + smp_read_barrier_depends();
2480 + if (nf_xfrm_local_done(skb, ipprot)) {
2481 + nf_rcv_postxfrm_local(skb);
2485 /* If there maybe a raw socket we must check - if not we
2487 @@ -235,14 +234,15 @@
2489 raw_v4_input(skb, skb->nh.iph, hash);
2491 - if ((ipprot = inet_protos[hash]) != NULL) {
2492 + if (ipprot != NULL) {
2495 - smp_read_barrier_depends();
2496 - if (!ipprot->no_policy &&
2497 - !xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb)) {
2500 + if (!ipprot->no_policy) {
2501 + if (!xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb)) {
2507 ret = ipprot->handler(skb);
2513 - return NF_HOOK(PF_INET, NF_IP_LOCAL_IN, skb, skb->dev, NULL,
2514 - ip_local_deliver_finish);
2515 + return NF_HOOK_COND(PF_INET, NF_IP_LOCAL_IN, skb, skb->dev, NULL,
2516 + ip_local_deliver_finish, nf_hook_input_cond(skb));
2519 static inline int ip_rcv_finish(struct sk_buff *skb)
2524 + if (nf_xfrm_nonlocal_done(skb))
2525 + return nf_rcv_postxfrm_nonlocal(skb);
2527 #ifdef CONFIG_NET_CLS_ROUTE
2528 if (skb->dst->tclassid) {
2529 struct ip_rt_acct *st = ip_rt_acct + 256*smp_processor_id();
2534 - return NF_HOOK(PF_INET, NF_IP_PRE_ROUTING, skb, dev, NULL,
2536 + return NF_HOOK_COND(PF_INET, NF_IP_PRE_ROUTING, skb, dev, NULL,
2537 + ip_rcv_finish, nf_hook_input_cond(skb));
2540 IP_INC_STATS_BH(IpInHdrErrors);
2541 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/ip_output.c linux-2.6.6/net/ipv4/ip_output.c
2542 --- linux-2.6.6.org/net/ipv4/ip_output.c 2004-05-10 04:33:21.000000000 +0200
2543 +++ linux-2.6.6/net/ipv4/ip_output.c 2004-05-18 14:28:50.000000000 +0200
2544 @@ -123,6 +123,15 @@
2548 +#ifdef CONFIG_NETFILTER
2549 +/* out-of-line copy is only required with netfilter */
2550 +int ip_dst_output(struct sk_buff *skb)
2552 + return NF_HOOK_COND(PF_INET, NF_IP_POST_ROUTING, skb, NULL,
2553 + skb->dst->dev, dst_output, skb->dst->xfrm != NULL);
2558 * Add an ip header to a skbuff and send it out.
2563 return NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, skb, NULL, rt->u.dst.dev,
2568 static inline int ip_finish_output2(struct sk_buff *skb)
2570 return ip_finish_output(skb);
2573 -int ip_output(struct sk_buff *skb)
2574 +static inline int ip_output2(struct sk_buff *skb)
2576 IP_INC_STATS(IpOutRequests);
2578 @@ -294,6 +303,16 @@
2579 return ip_finish_output(skb);
2582 +int ip_output(struct sk_buff *skb)
2584 + int transformed = IPCB(skb)->flags & IPSKB_XFRM_TRANSFORMED;
2588 + return NF_HOOK_COND(PF_INET, NF_IP_LOCAL_OUT, skb, NULL,
2589 + skb->dst->dev, ip_output2, transformed);
2592 int ip_queue_xmit(struct sk_buff *skb, int ipfragok)
2594 struct sock *sk = skb->sk;
2596 skb->priority = sk->sk_priority;
2598 return NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, skb, NULL, rt->u.dst.dev,
2603 IP_INC_STATS(IpOutNoRoutes);
2604 @@ -1177,7 +1196,7 @@
2606 /* Netfilter gets whole the not fragmented skb. */
2607 err = NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, skb, NULL,
2608 - skb->dst->dev, dst_output);
2609 + skb->dst->dev, ip_dst_output);
2612 err = inet->recverr ? net_xmit_errno(err) : 0;
2613 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/ipcomp.c linux-2.6.6/net/ipv4/ipcomp.c
2614 --- linux-2.6.6.org/net/ipv4/ipcomp.c 2004-05-10 04:33:13.000000000 +0200
2615 +++ linux-2.6.6/net/ipv4/ipcomp.c 2004-05-18 14:28:50.000000000 +0200
2617 err = -EHOSTUNREACH;
2620 + IPCB(skb)->flags |= IPSKB_XFRM_TRANSFORMED;
2621 err = NET_XMIT_BYPASS;
2625 .handler = xfrm4_rcv,
2626 .err_handler = ipcomp4_err,
2631 static int __init ipcomp4_init(void)
2632 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/ipip.c linux-2.6.6/net/ipv4/ipip.c
2633 --- linux-2.6.6.org/net/ipv4/ipip.c 2004-05-10 04:33:22.000000000 +0200
2634 +++ linux-2.6.6/net/ipv4/ipip.c 2004-05-18 14:28:50.000000000 +0200
2635 @@ -478,6 +478,11 @@
2637 read_lock(&ipip_lock);
2638 if ((tunnel = ipip_tunnel_lookup(iph->saddr, iph->daddr)) != NULL) {
2639 + /* IPIP packets decapsulated by IPsec missed netfilter hooks */
2640 + if (nf_xfrm_local_done(skb, NULL)) {
2641 + nf_rcv_postxfrm_local(skb);
2644 if (!xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb)) {
2647 @@ -496,13 +501,7 @@
2648 skb->dev = tunnel->dev;
2649 dst_release(skb->dst);
2651 -#ifdef CONFIG_NETFILTER
2652 - nf_conntrack_put(skb->nfct);
2654 -#ifdef CONFIG_NETFILTER_DEBUG
2655 - skb->nf_debug = 0;
2659 ipip_ecn_decapsulate(iph, skb);
2661 read_unlock(&ipip_lock);
2662 @@ -647,13 +646,7 @@
2663 if ((iph->ttl = tiph->ttl) == 0)
2664 iph->ttl = old_iph->ttl;
2666 -#ifdef CONFIG_NETFILTER
2667 - nf_conntrack_put(skb->nfct);
2669 -#ifdef CONFIG_NETFILTER_DEBUG
2670 - skb->nf_debug = 0;
2676 tunnel->recursion--;
2677 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/ipmr.c linux-2.6.6/net/ipv4/ipmr.c
2678 --- linux-2.6.6.org/net/ipv4/ipmr.c 2004-05-10 04:32:30.000000000 +0200
2679 +++ linux-2.6.6/net/ipv4/ipmr.c 2004-05-18 14:28:50.000000000 +0200
2680 @@ -1120,7 +1120,7 @@
2681 if (unlikely(opt->optlen))
2682 ip_forward_options(skb);
2684 - return dst_output(skb);
2685 + return ip_dst_output(skb);
2689 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/Kconfig linux-2.6.6/net/ipv4/netfilter/Kconfig
2690 --- linux-2.6.6.org/net/ipv4/netfilter/Kconfig 2004-05-10 04:33:13.000000000 +0200
2691 +++ linux-2.6.6/net/ipv4/netfilter/Kconfig 2004-05-18 14:28:50.000000000 +0200
2692 @@ -206,6 +206,11 @@
2694 To compile it as a module, choose M here. If unsure, say N.
2696 +config IP_NF_MATCH_UNCLEAN
2697 + tristate 'unclean match support (EXPERIMENTAL)'
2698 + depends on EXPERIMENTAL && IP_NF_IPTABLES
2701 config IP_NF_MATCH_TTL
2702 tristate "TTL match support"
2703 depends on IP_NF_IPTABLES
2704 @@ -603,5 +608,509 @@
2705 <file:Documentation/modules.txt>. If unsure, say `N'.
2708 +config IP_NF_TARGET_IPV4OPTSSTRIP
2709 + tristate 'IPV4OPTSSTRIP target support'
2710 + depends on IP_NF_MANGLE
2712 + This option adds an IPV4OPTSSTRIP target.
2713 + This target allows you to strip all IP options in a packet.
2715 + If you want to compile it as a module, say M here and read
2716 + Documentation/modules.txt. If unsure, say `N'.
2718 +config IP_NF_TARGET_NETLINK
2719 + tristate 'NETLINK target support'
2720 + depends on IP_NF_FILTER
2722 + The NETLINK target allows you to recieve packets in userspace via
2723 + the kernel firewall netlink socket. Apps such as fwmon
2724 + (http://firestorm.geek-ware.co.uk) can then recieve and dislpay
2725 + these packets. This option is basically a re-implementation of the
2726 + ipchains -o option.
2728 +config IP_NF_TARGET_TTL
2729 + tristate 'TTL target support'
2730 + depends on IP_NF_MANGLE
2732 + This option adds a `TTL' target, which enables the user to set
2733 + the TTL value or increment / decrement the TTL value by a given
2736 + If you want to compile it as a module, say M here and read
2737 + Documentation/modules.txt. If unsure, say `N'.
2739 +config IP_NF_MATCH_CONNLIMIT
2740 + tristate 'Connections/IP limit match support'
2741 + depends on IP_NF_IPTABLES
2743 + This match allows you to restrict the number of parallel TCP
2744 + connections to a server per client IP address (or address block).
2746 + If you want to compile it as a module, say M here and read
2747 + Documentation/modules.txt. If unsure, say `N'.
2749 +config IP_NF_MATCH_DSTLIMIT
2750 + tristate 'dstlimit match support'
2751 + depends on IP_NF_IPTABLES
2753 +config IP_NF_MATCH_FUZZY
2754 + tristate 'fuzzy match support'
2755 + depends on IP_NF_IPTABLES
2757 + This option adds a `fuzzy' match, which allows you to match
2758 + packets according to a fuzzy logic based law.
2760 + If you want to compile it as a module, say M here and read
2761 + Documentation/modules.txt. If unsure, say `N'.
2763 +config IP_NF_MATCH_IPV4OPTIONS
2764 + tristate 'IPV4OPTIONS match support'
2765 + depends on IP_NF_IPTABLES
2767 + This option adds a IPV4OPTIONS match.
2768 + It allows you to filter options like source routing,
2769 + record route, timestamp and router-altert.
2771 + If you say Y here, try iptables -m ipv4options --help for more information.
2773 + If you want to compile it as a module, say M here and read
2774 + Documentation/modules.txt. If unsure, say `N'.
2776 +config IP_NF_MATCH_MPORT
2777 + tristate 'Multiple port with ranges match support'
2778 + depends on IP_NF_IPTABLES
2780 + This is an enhanced multiport match which supports port
2781 + ranges as well as single ports.
2783 + If you want to compile it as a module, say M here and read
2784 + Documentation/modules.txt. If unsure, say `N'.
2786 +config IP_NF_MATCH_NTH
2787 + tristate 'Nth match support'
2788 + depends on IP_NF_IPTABLES
2790 + This option adds a `Nth' match, which allow you to make
2791 + rules that match every Nth packet. By default there are
2792 + 16 different counters.
2795 + --every Nth Match every Nth packet
2796 + [--counter] num Use counter 0-15 (default:0)
2797 + [--start] num Initialize the counter at the number 'num'
2798 + instead of 0. Must be between 0 and Nth-1
2799 + [--packet] num Match on 'num' packet. Must be between 0
2802 + If --packet is used for a counter than
2803 + there must be Nth number of --packet
2804 + rules, covering all values between 0 and
2805 + Nth-1 inclusively.
2807 + If you want to compile it as a module, say M here and read
2808 + Documentation/modules.txt. If unsure, say `N'.
2810 +config IP_NF_MATCH_OSF
2811 + tristate 'OSF match support'
2812 + depends on IP_NF_IPTABLES
2815 + The idea of passive OS fingerprint matching exists for quite a long time,
2816 + but was created as extension fo OpenBSD pf only some weeks ago.
2817 + Original idea was lurked in some OpenBSD mailing list (thanks
2818 + grange@open...) and than adopted for Linux netfilter in form of this code.
2820 + Original table was created by Michal Zalewski <lcamtuf@coredump.cx> for
2821 + his excellent p0f and than changed a bit for more convenience.
2823 + This module compares some data(WS, MSS, options and it's order, ttl,
2824 + df and others) from first SYN packet (actually from packets with SYN
2825 + bit set) with hardcoded in fingers[] table ones.
2827 + If you say Y here, try iptables -m osf --help for more information.
2829 + If you want to compile it as a module, say M here and read
2830 + Documentation/modules.txt. If unsure, say `N'.
2832 +config IP_POOL_STATISTICS
2833 + bool 'enable statistics on pool usage'
2834 + depends on IP_NF_POOL!=n
2836 + This option controls whether usage gathering code is compiled into the
2837 + ip_pool module. Disabling statistics may be substantially faster.
2840 + tristate 'IP address pool support'
2841 + depends on IP_NF_IPTABLES
2843 + Pool matching lets you use bitmaps with one bit per address from some
2844 + range of IP addresses; the match depends on whether a checked source
2845 + or destination address has its bit set in the pool.
2847 + There is also a POOL netfilter target, which can be used to set or remove
2848 + the addresses of a packet from a pool.
2850 + To define and use pools, you need userlevel utilities: a patched iptables,
2851 + and the program ippool(8), which defines the pools and their bounds.
2852 + The current release of pool matching is ippool-0.0.2, and can be found
2853 + in the archives of the netfilter mailing list at
2854 + http://lists.samba.org/netfilter/.
2856 + If you want to compile it as a module, say M here and read
2857 + Documentation/modules.txt. If unsure, say `N'.
2859 +config IP_NF_MATCH_PSD
2860 + tristate 'psd match support'
2861 + depends on IP_NF_IPTABLES
2863 + This option adds a `psd' match, which allows you to create rules in
2864 + any iptables table wich will detect TCP and UDP port scans.
2866 + If you want to compile it as a module, say M here and read
2867 + Documentation/modules.txt. If unsure, say `N'.
2869 +config IP_NF_MATCH_QUOTA
2870 + tristate 'quota match support'
2871 + depends on IP_NF_IPTABLES
2873 + This match implements network quotas.
2875 + If you want to compile it as a module, say M here and read
2876 + Documentation/modules.txt. If unsure, say `N'.
2879 +config IP_NF_MATCH_RANDOM
2880 + tristate 'random match support'
2881 + depends on IP_NF_IPTABLES
2883 + This option adds a `random' match,
2884 + which allow you to match packets randomly
2885 + following a given probability.
2887 + If you want to compile it as a module, say M here and read
2888 + Documentation/modules.txt. If unsure, say `N'.
2890 +config IP_NF_MATCH_REALM
2891 + tristate 'realm match support'
2892 + depends on IP_NF_IPTABLES && NET_CLS_ROUTE
2894 + This option adds a `realm' match, which allows you to use the realm
2895 + key from the routing subsytem inside iptables.
2897 + This match pretty much resembles the CONFIG_NET_CLS_ROUTE4 option
2900 + If you want to compile it as a module, say M here and read
2901 + Documentation/modules.txt. If unsure, say `N'.
2903 +config IP_NF_MATCH_SCTP
2904 + tristate 'SCTP protocol match support'
2905 + depends on IP_NF_IPTABLES
2907 +config IP_NF_MATCH_TIME
2908 + tristate 'TIME match support'
2909 + depends on IP_NF_IPTABLES
2911 + This option adds a `time' match, which allows you
2912 + to match based on the packet arrival time/date
2913 + (arrival time/date at the machine which netfilter is running on) or
2914 + departure time/date (for locally generated packets).
2916 + If you say Y here, try iptables -m time --help for more information.
2918 + If you want to compile it as a module, say M here and read
2919 + Documentation/modules.txt. If unsure, say `N'.
2921 +config IP_NF_MATCH_U32
2922 + tristate 'U32 match support'
2923 + depends on IP_NF_IPTABLES
2925 + U32 allows you to extract quantities of up to 4 bytes from a packet,
2926 + AND them with specified masks, shift them by specified amounts and
2927 + test whether the results are in any of a set of specified ranges.
2928 + The specification of what to extract is general enough to skip over
2929 + headers with lengths stored in the packet, as in IP or TCP header
2932 + Details and examples are in the kernel module source.
2934 +config IP_NF_CONNTRACK_MARK
2935 + bool 'Connection mark tracking support'
2937 + This option enables support for connection marks, used by the
2938 + `CONNMARK' target and `connmark' match. Similar to the mark value
2939 + of packets, but this mark value is kept in the conntrack session
2940 + instead of the individual packets.
2942 +config IP_NF_TARGET_CONNMARK
2943 + tristate 'CONNMARK target support'
2944 + depends on IP_NF_CONNTRACK_MARK && IP_NF_MANGLE
2946 + This option adds a `CONNMARK' target, which allows one to manipulate
2947 + the connection mark value. Similar to the MARK target, but
2948 + affects the connection mark value rather than the packet mark value.
2950 + If you want to compile it as a module, say M here and read
2951 + Documentation/modules.txt. The module will be called
2952 + ipt_CONNMARK.o. If unsure, say `N'.
2954 +config IP_NF_MATCH_CONNMARK
2955 + tristate ' Connection mark match support'
2956 + depends on IP_NF_CONNTRACK_MARK && IP_NF_IPTABLES
2958 + This option adds a `connmark' match, which allows you to match the
2959 + connection mark value previously set for the session by `CONNMARK'.
2961 + If you want to compile it as a module, say M here and read
2962 + Documentation/modules.txt. The module will be called
2963 + ipt_connmark.o. If unsure, say `N'.
2965 +config IP_NF_TARGET_IPMARK
2966 + tristate 'IPMARK target support'
2967 + depends on IP_NF_MANGLE
2969 + This option adds a `IPMARK' target, which allows you to create rules
2970 + in the `mangle' table which alter the netfilter mark (nfmark) field
2971 + basing on the source or destination ip address of the packet.
2972 + This is very useful for very fast massive mangling and marking.
2974 + If you want to compile it as a module, say M here and read
2975 + <file:Documentation/modules.txt>. If unsure, say `N'.
2977 +config IP_NF_TARGET_ROUTE
2978 + tristate 'ROUTE target support'
2979 + depends on IP_NF_MANGLE
2981 + This option adds a `ROUTE' target, which enables you to setup unusual
2982 + routes. For example, the ROUTE lets you route a received packet through
2983 + an interface or towards a host, even if the regular destination of the
2984 + packet is the router itself. The ROUTE target is also able to change the
2985 + incoming interface of a packet.
2987 + The target can be or not a final target. It has to be used inside the
2990 + If you want to compile it as a module, say M here and read
2991 + Documentation/modules.txt. The module will be called ipt_ROUTE.o.
2992 + If unsure, say `N'.
2994 +config IP_NF_TARGET_TARPIT
2995 + tristate 'TARPIT target support'
2996 + depends on IP_NF_FILTER
2998 + Adds a TARPIT target to iptables, which captures and holds
2999 + incoming TCP connections using no local per-connection resources.
3000 + Connections are accepted, but immediately switched to the persist
3001 + state (0 byte window), in which the remote side stops sending data
3002 + and asks to continue every 60-240 seconds. Attempts to close the
3003 + connection are ignored, forcing the remote side to time out the
3004 + connection in 12-24 minutes.
3006 + This offers similar functionality to LaBrea
3007 + <http://www.hackbusters.net/LaBrea/> but doesn't require dedicated
3008 + hardware or IPs. Any TCP port that you would normally DROP or REJECT
3009 + can instead become a tarpit.
3011 +config IP_NF_TARGET_TCPLAG
3012 + tristate 'TCPLAG target support'
3013 + depends on IP_NF_IPTABLES
3015 + This option adds a `TCPLAG' target, intended for INPUT, OUTPUT and
3018 + This target has no effect on packets but will passively monitor TCP/IP
3019 + connections and send lag estimates to syslog. Lag estimates are
3020 + generated by considering the time delay between SEQ and matching ACK,
3021 + which does not map precisely to any particular network property.
3022 + We can say that a fast network will typically give smaller lag values
3023 + than a slow network.
3025 + Safest option is to choose `M' here and compile as a module,
3026 + the module will do nothing until activated using the `iptables' utility.
3028 +config IP_NF_TARGET_TRACE
3029 + tristate 'TRACE target support'
3030 + depends on IP_NF_RAW
3032 + The TRACE target allows packets to be traced as those
3033 + matches any subsequent rule in any table/rule. The matched
3034 + rule and the packet is logged with the prefix
3036 + TRACE: tablename/chainname/rulenum
3038 + If you want to compile it as a module, say M here and read
3039 + <file:Documentation/modules.txt>. If unsure, say `N'.
3041 +config IP_NF_TARGET_XOR
3042 + tristate 'XOR target support'
3043 + depends on IP_NF_MANGLE
3045 + This option adds a `XOR' target, which can encrypt TCP and
3046 + UDP traffic using a simple XOR encryption.
3048 + If you want to compile it as a module, say M here and read
3049 + Documentation/modules.txt. If unsure, say `N'.
3051 +config IP_NF_MATCH_ADDRTYPE
3052 + tristate 'address type match support'
3053 + depends on IP_NF_IPTABLES
3055 + This option allows you to match what routing thinks of an address,
3056 + eg. UNICAST, LOCAL, BROADCAST, ...
3058 + If you want to compile it as a module, say M here and read
3059 + Documentation/modules.txt. If unsure, say `N'.
3062 + tristate 'Eggdrop bot support'
3063 + depends on IP_NF_CONNTRACK
3065 + If you are running an eggdrop hub bot on this machine, then you
3066 + may want to enable this feature. This enables eggdrop bots to share
3067 + their user file to other eggdrop bots.
3069 + If you want to compile it as a module, say M here and read
3070 + Documentation/modules.txt. If unsure, say `N'.
3072 +config IP_NF_NAT_H323
3074 + depends on IP_NF_CONNTRACK!=n && IP_NF_NAT!=n
3075 + default IP_NF_NAT if IP_NF_H323=y
3076 + default m if IP_NF_H323=m
3079 + tristate 'H.323 (netmeeting) support'
3080 + depends on IP_NF_CONNTRACK
3082 + H.323 is a standard signalling protocol used by teleconferencing
3083 + softwares like netmeeting. With the ip_conntrack_h323 and
3084 + the ip_nat_h323 modules you can support the protocol on a connection
3085 + tracking/NATing firewall.
3087 + If you want to compile it as a module, say 'M' here and read
3088 + Documentation/modules.txt. If unsure, say 'N'.
3090 +config IP_NF_NAT_MMS
3092 + depends on IP_NF_CONNTRACK!=n && IP_NF_NAT!=n
3093 + default IP_NF_NAT if IP_NF_MMS=y
3094 + default m if IP_NF_MMS=m
3097 + tristate 'MMS protocol support'
3098 + depends on IP_NF_CONNTRACK
3100 + Tracking MMS (Microsoft Windows Media Services) connections
3101 + could be problematic if random ports are used to send the
3102 + streaming content. This option allows users to track streaming
3103 + connections over random UDP or TCP ports.
3105 + If you want to compile it as a module, say M here and read
3106 + <file:Documentation/modules.txt>. If unsure, say `Y'.
3108 +config IP_NF_MATCH_POLICY
3109 + tristate "IPsec policy match support"
3110 + depends on IP_NF_IPTABLES && XFRM
3112 + Policy matching allows you to match packets based on the
3113 + IPsec policy that was used during decapsulation/will
3114 + be used during encapsulation.
3116 + To compile it as a module, choose M here. If unsure, say N.
3118 +config IP_NF_NAT_QUAKE3
3120 + depends on IP_NF_CONNTRACK!=n && IP_NF_NAT !=n
3121 + default IP_NF_NAT if IP_NF_QUAKE3=y
3122 + default m if IP_NF_QUAKE3=m
3124 +config IP_NF_QUAKE3
3125 + tristate "Quake3 protocol support"
3126 + depends on IP_NF_CONNTRACK
3128 + Quake III Arena connection tracking helper. This module allows for a
3129 + stricter firewall rulebase if one only allows traffic to a master
3130 + server. Connections to Quake III server IP addresses and ports returned
3131 + by the master server will be tracked automatically.
3133 + If you want to compile it as a module, say M here and read
3134 + <file:Documentation/modules.txt>. If unsure, say `Y'.
3137 + tristate 'RSH protocol support'
3138 + depends on IP_NF_CONNTRACK
3140 + The RSH connection tracker is required if the dynamic
3141 + stderr "Server to Client" connection is to occur during a
3142 + normal RSH session. This typically operates as follows;
3144 + Client 0:1023 --> Server 514 (stream 1 - stdin/stdout)
3145 + Client 0:1023 <-- Server 0:1023 (stream 2 - stderr)
3147 + This connection tracker will identify new RSH sessions,
3148 + extract the outbound session details, and notify netfilter
3149 + of pending "related" sessions.
3151 + Warning: This module could be dangerous. It is not "best
3152 + practice" to use RSH, use SSH in all instances.
3153 + (see rfc1244, rfc1948, rfc2179, etc ad-nauseum)
3156 + If you want to compile it as a module, say M here and read
3157 + <file:Documentation/modules.txt>. If unsure, say `N'.
3159 +config IP_NF_NAT_RTSP
3161 + depends on IP_NF_CONNTRACK!=n && IP_NF_NAT!=n
3162 + default IP_NF_NAT if IP_NF_RTSP=y
3163 + default m if IP_NF_RTSP=m
3166 + tristate ' RTSP protocol support'
3167 + depends on IP_NF_CONNTRACK
3169 + Support the RTSP protocol. This allows UDP transports to be setup
3170 + properly, including RTP and RDT.
3172 + If you want to compile it as a module, say 'M' here and read
3173 + Documentation/modules.txt. If unsure, say 'Y'.
3175 +config IP_NF_CT_PROTO_SCTP
3176 + tristate 'SCTP protocol connection tracking support'
3177 + depends on IP_NF_CONNTRACK
3179 +config IP_NF_MATCH_STRING
3180 + tristate 'String match support'
3181 + depends on IP_NF_IPTABLES
3183 + String matching alows you to match packets which contain a
3184 + specified string of characters.
3186 + If you want to compile it as a module, say M here and read
3187 + Documentation/modules.txt. If unsure, say `N'.
3189 +config IP_NF_NAT_TALK
3191 + depends on IP_NF_CONNTRACK!=n && IP_NF_NAT!=n
3192 + default IP_NF_NAT if IP_NF_TALK=y
3193 + default m if IP_NF_TALK=m
3196 + tristate 'talk protocol support'
3197 + depends on IP_NF_CONNTRACK
3199 + The talk protocols (both otalk/talk - or talk/ntalk, to confuse
3200 + you by the different namings about which is old or which is new :-)
3201 + use an additional channel to setup the talk session and a separated
3202 + data channel for the actual conversation (like in FTP). Both the
3203 + initiating and the setup channels are over UDP, while the data channel
3204 + is over TCP, on a random port. The conntrack part of this extension
3205 + will enable you to let in/out talk sessions easily by matching these
3206 + connections as RELATED by the state match, while the NAT part helps
3207 + you to let talk sessions trough a NAT machine.
3209 + If you want to compile it as a module, say 'M' here and read
3210 + Documentation/modules.txt. If unsure, say 'N'.
3214 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/Makefile linux-2.6.6/net/ipv4/netfilter/Makefile
3215 --- linux-2.6.6.org/net/ipv4/netfilter/Makefile 2004-05-10 04:32:26.000000000 +0200
3216 +++ linux-2.6.6/net/ipv4/netfilter/Makefile 2004-05-18 14:28:50.000000000 +0200
3218 # connection tracking
3219 obj-$(CONFIG_IP_NF_CONNTRACK) += ip_conntrack.o
3221 +# talk protocol support
3222 +obj-$(CONFIG_IP_NF_TALK) += ip_conntrack_talk.o
3223 +obj-$(CONFIG_IP_NF_NAT_TALK) += ip_nat_talk.o
3226 +# SCTP protocol connection tracking
3227 +obj-$(CONFIG_IP_NF_CT_PROTO_SCTP) += ip_conntrack_proto_sctp.o
3230 +obj-$(CONFIG_IP_NF_H323) += ip_conntrack_h323.o
3231 +obj-$(CONFIG_IP_NF_NAT_H323) += ip_nat_h323.o
3234 # connection tracking helpers
3236 +# rtsp protocol support
3237 +obj-$(CONFIG_IP_NF_RTSP) += ip_conntrack_rtsp.o
3238 +obj-$(CONFIG_IP_NF_NAT_RTSP) += ip_nat_rtsp.o
3240 +obj-$(CONFIG_IP_NF_QUAKE3) += ip_conntrack_quake3.o
3241 +obj-$(CONFIG_IP_NF_MMS) += ip_conntrack_mms.o
3242 obj-$(CONFIG_IP_NF_AMANDA) += ip_conntrack_amanda.o
3243 obj-$(CONFIG_IP_NF_TFTP) += ip_conntrack_tftp.o
3244 obj-$(CONFIG_IP_NF_FTP) += ip_conntrack_ftp.o
3245 +obj-$(CONFIG_IP_NF_RSH) += ip_conntrack_rsh.o
3247 +obj-$(CONFIG_IP_NF_EGG) += ip_conntrack_egg.o
3249 obj-$(CONFIG_IP_NF_IRC) += ip_conntrack_irc.o
3253 obj-$(CONFIG_IP_NF_NAT_TFTP) += ip_nat_tftp.o
3254 obj-$(CONFIG_IP_NF_NAT_FTP) += ip_nat_ftp.o
3255 obj-$(CONFIG_IP_NF_NAT_IRC) += ip_nat_irc.o
3256 +obj-$(CONFIG_IP_NF_NAT_QUAKE3) += ip_nat_quake3.o
3257 +obj-$(CONFIG_IP_NF_NAT_MMS) += ip_nat_mms.o
3260 obj-$(CONFIG_IP_NF_IPTABLES) += ip_tables.o
3263 obj-$(CONFIG_IP_NF_MATCH_HELPER) += ipt_helper.o
3264 obj-$(CONFIG_IP_NF_MATCH_LIMIT) += ipt_limit.o
3265 +obj-$(CONFIG_IP_NF_MATCH_SCTP) += ipt_sctp.o
3266 +obj-$(CONFIG_IP_NF_MATCH_QUOTA) += ipt_quota.o
3267 +obj-$(CONFIG_IP_NF_MATCH_DSTLIMIT) += ipt_dstlimit.o
3268 obj-$(CONFIG_IP_NF_MATCH_MARK) += ipt_mark.o
3269 +obj-$(CONFIG_IP_NF_POOL) += ipt_pool.o ipt_POOL.o ip_pool.o
3270 obj-$(CONFIG_IP_NF_MATCH_MAC) += ipt_mac.o
3271 obj-$(CONFIG_IP_NF_MATCH_IPRANGE) += ipt_iprange.o
3273 obj-$(CONFIG_IP_NF_MATCH_PKTTYPE) += ipt_pkttype.o
3274 obj-$(CONFIG_IP_NF_MATCH_MULTIPORT) += ipt_multiport.o
3276 +obj-$(CONFIG_IP_NF_MATCH_MPORT) += ipt_mport.o
3278 obj-$(CONFIG_IP_NF_MATCH_OWNER) += ipt_owner.o
3279 obj-$(CONFIG_IP_NF_MATCH_TOS) += ipt_tos.o
3281 +obj-$(CONFIG_IP_NF_MATCH_TIME) += ipt_time.o
3284 +obj-$(CONFIG_IP_NF_MATCH_RANDOM) += ipt_random.o
3286 +obj-$(CONFIG_IP_NF_MATCH_PSD) += ipt_psd.o
3288 +obj-$(CONFIG_IP_NF_MATCH_OSF) += ipt_osf.o
3291 +obj-$(CONFIG_IP_NF_MATCH_NTH) += ipt_nth.o
3293 +obj-$(CONFIG_IP_NF_MATCH_IPV4OPTIONS) += ipt_ipv4options.o
3296 +obj-$(CONFIG_IP_NF_MATCH_FUZZY) += ipt_fuzzy.o
3298 obj-$(CONFIG_IP_NF_MATCH_RECENT) += ipt_recent.o
3300 obj-$(CONFIG_IP_NF_MATCH_ECN) += ipt_ecn.o
3301 @@ -60,28 +125,48 @@
3303 obj-$(CONFIG_IP_NF_MATCH_LENGTH) += ipt_length.o
3305 +obj-$(CONFIG_IP_NF_MATCH_U32) += ipt_u32.o
3308 +obj-$(CONFIG_IP_NF_MATCH_UNCLEAN) += ipt_unclean.o
3309 +obj-$(CONFIG_IP_NF_MATCH_STRING) += ipt_string.o
3310 obj-$(CONFIG_IP_NF_MATCH_TTL) += ipt_ttl.o
3311 obj-$(CONFIG_IP_NF_MATCH_STATE) += ipt_state.o
3312 +obj-$(CONFIG_IP_NF_MATCH_CONNMARK) += ipt_connmark.o
3313 +obj-$(CONFIG_IP_NF_MATCH_CONNLIMIT) += ipt_connlimit.o
3314 obj-$(CONFIG_IP_NF_MATCH_CONNTRACK) += ipt_conntrack.o
3315 obj-$(CONFIG_IP_NF_MATCH_TCPMSS) += ipt_tcpmss.o
3316 +obj-$(CONFIG_IP_NF_MATCH_ADDRTYPE) += ipt_addrtype.o
3317 +obj-$(CONFIG_IP_NF_MATCH_REALM) += ipt_realm.o
3319 obj-$(CONFIG_IP_NF_MATCH_PHYSDEV) += ipt_physdev.o
3320 +obj-$(CONFIG_IP_NF_MATCH_POLICY) += ipt_policy.o
3323 obj-$(CONFIG_IP_NF_TARGET_REJECT) += ipt_REJECT.o
3324 +obj-$(CONFIG_IP_NF_TARGET_TARPIT) += ipt_TARPIT.o
3325 obj-$(CONFIG_IP_NF_TARGET_TOS) += ipt_TOS.o
3326 obj-$(CONFIG_IP_NF_TARGET_ECN) += ipt_ECN.o
3327 obj-$(CONFIG_IP_NF_TARGET_DSCP) += ipt_DSCP.o
3328 obj-$(CONFIG_IP_NF_TARGET_MARK) += ipt_MARK.o
3329 +obj-$(CONFIG_IP_NF_TARGET_IPMARK) += ipt_IPMARK.o
3330 obj-$(CONFIG_IP_NF_TARGET_MASQUERADE) += ipt_MASQUERADE.o
3331 obj-$(CONFIG_IP_NF_TARGET_REDIRECT) += ipt_REDIRECT.o
3332 +obj-$(CONFIG_IP_NF_TARGET_ROUTE) += ipt_ROUTE.o
3333 obj-$(CONFIG_IP_NF_TARGET_NETMAP) += ipt_NETMAP.o
3334 obj-$(CONFIG_IP_NF_TARGET_SAME) += ipt_SAME.o
3335 obj-$(CONFIG_IP_NF_TARGET_CLASSIFY) += ipt_CLASSIFY.o
3336 obj-$(CONFIG_IP_NF_NAT_SNMP_BASIC) += ip_nat_snmp_basic.o
3337 obj-$(CONFIG_IP_NF_TARGET_LOG) += ipt_LOG.o
3338 +obj-$(CONFIG_IP_NF_TARGET_XOR) += ipt_XOR.o
3339 +obj-$(CONFIG_IP_NF_TARGET_TCPLAG) += ipt_TCPLAG.o
3340 +obj-$(CONFIG_IP_NF_TARGET_CONNMARK) += ipt_CONNMARK.o
3341 +obj-$(CONFIG_IP_NF_TARGET_TTL) += ipt_TTL.o
3342 +obj-$(CONFIG_IP_NF_TARGET_NETLINK) += ipt_NETLINK.o
3343 +obj-$(CONFIG_IP_NF_TARGET_IPV4OPTSSTRIP) += ipt_IPV4OPTSSTRIP.o
3344 obj-$(CONFIG_IP_NF_TARGET_ULOG) += ipt_ULOG.o
3345 obj-$(CONFIG_IP_NF_TARGET_TCPMSS) += ipt_TCPMSS.o
3346 +obj-$(CONFIG_IP_NF_TARGET_TRACE) += ipt_TRACE.o
3347 obj-$(CONFIG_IP_NF_TARGET_NOTRACK) += ipt_NOTRACK.o
3349 # generic ARP tables
3350 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ip_conntrack_core.c linux-2.6.6/net/ipv4/netfilter/ip_conntrack_core.c
3351 --- linux-2.6.6.org/net/ipv4/netfilter/ip_conntrack_core.c 2004-05-10 04:31:55.000000000 +0200
3352 +++ linux-2.6.6/net/ipv4/netfilter/ip_conntrack_core.c 2004-05-18 14:28:50.000000000 +0200
3354 ip_conntrack_destroyed(ct);
3356 WRITE_LOCK(&ip_conntrack_lock);
3357 - /* Delete us from our own list to prevent corruption later */
3358 - list_del(&ct->sibling_list);
3359 + /* Make sure don't leave any orphaned expectations lying around */
3360 + if (ct->expecting)
3361 + remove_expectations(ct, 1);
3363 /* Delete our master expectation */
3365 @@ -692,25 +693,22 @@
3366 struct ip_conntrack_expect *, tuple);
3367 READ_UNLOCK(&ip_conntrack_expect_tuple_lock);
3369 - /* If master is not in hash table yet (ie. packet hasn't left
3370 - this machine yet), how can other end know about expected?
3371 - Hence these are not the droids you are looking for (if
3372 - master ct never got confirmed, we'd hold a reference to it
3373 - and weird things would happen to future packets). */
3374 - if (expected && !is_confirmed(expected->expectant))
3377 - /* Look up the conntrack helper for master connections only */
3379 - conntrack->helper = ip_ct_find_helper(&repl_tuple);
3381 + /* If master is not in hash table yet (ie. packet hasn't left
3382 + this machine yet), how can other end know about expected?
3383 + Hence these are not the droids you are looking for (if
3384 + master ct never got confirmed, we'd hold a reference to it
3385 + and weird things would happen to future packets). */
3386 + if (!is_confirmed(expected->expectant)) {
3387 + conntrack->helper = ip_ct_find_helper(&repl_tuple);
3391 - /* If the expectation is dying, then this is a loser. */
3393 - && expected->expectant->helper->timeout
3394 - && ! del_timer(&expected->timeout))
3396 + /* Expectation is dying... */
3397 + if (expected->expectant->helper->timeout
3398 + && !del_timer(&expected->timeout))
3402 DEBUGP("conntrack: expectation arrives ct=%p exp=%p\n",
3403 conntrack, expected);
3404 /* Welcome, Mr. Bond. We've been expecting you... */
3405 @@ -718,16 +716,28 @@
3406 __set_bit(IPS_EXPECTED_BIT, &conntrack->status);
3407 conntrack->master = expected;
3408 expected->sibling = conntrack;
3409 +#if CONFIG_IP_NF_CONNTRACK_MARK
3410 + conntrack->mark = expected->expectant->mark;
3412 LIST_DELETE(&ip_conntrack_expect_list, expected);
3413 expected->expectant->expecting--;
3414 nf_conntrack_get(&master_ct(conntrack)->infos[0]);
3416 - atomic_inc(&ip_conntrack_count);
3418 + /* this is a braindead... --pablo */
3419 + atomic_inc(&ip_conntrack_count);
3420 + WRITE_UNLOCK(&ip_conntrack_lock);
3422 + if (expected->expectfn)
3423 + expected->expectfn(conntrack);
3427 + conntrack->helper = ip_ct_find_helper(&repl_tuple);
3429 +end: atomic_inc(&ip_conntrack_count);
3430 WRITE_UNLOCK(&ip_conntrack_lock);
3432 - if (expected && expected->expectfn)
3433 - expected->expectfn(conntrack);
3434 - return &conntrack->tuplehash[IP_CT_DIR_ORIGINAL];
3435 +ret: return &conntrack->tuplehash[IP_CT_DIR_ORIGINAL];
3438 /* On success, returns conntrack ptr, sets skb->nfct and ctinfo */
3440 atomic_set(&new->use, 1);
3442 /* add to expected list for this connection */
3443 - list_add(&new->expected_list, &related_to->sibling_list);
3444 + list_add_tail(&new->expected_list, &related_to->sibling_list);
3445 /* add to global list of expectations */
3447 list_prepend(&ip_conntrack_expect_list, &new->list);
3448 /* add and start timer if required */
3449 if (related_to->helper->timeout) {
3450 @@ -1003,7 +1012,6 @@
3452 } else if (related_to->helper->max_expected &&
3453 related_to->expecting >= related_to->helper->max_expected) {
3454 - struct list_head *cur_item;
3456 if (!(related_to->helper->flags &
3457 IP_CT_HELPER_F_REUSE_EXPECT)) {
3458 @@ -1029,21 +1037,14 @@
3459 NIPQUAD(related_to->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.ip));
3461 /* choose the the oldest expectation to evict */
3462 - list_for_each(cur_item, &related_to->sibling_list) {
3463 - struct ip_conntrack_expect *cur;
3465 - cur = list_entry(cur_item,
3466 - struct ip_conntrack_expect,
3468 - if (cur->sibling == NULL) {
3470 + list_for_each_entry(old, &related_to->sibling_list,
3472 + if (old->sibling == NULL)
3477 - /* (!old) cannot happen, since related_to->expecting is the
3478 - * number of unconfirmed expects */
3479 - IP_NF_ASSERT(old);
3480 + /* We cannot fail since related_to->expecting is the number
3481 + * of unconfirmed expectations */
3482 + IP_NF_ASSERT(old && old->sibling == NULL);
3484 /* newnat14 does not reuse the real allocated memory
3485 * structures but rather unexpects the old and
3486 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ip_conntrack_egg.c linux-2.6.6/net/ipv4/netfilter/ip_conntrack_egg.c
3487 --- linux-2.6.6.org/net/ipv4/netfilter/ip_conntrack_egg.c 1970-01-01 01:00:00.000000000 +0100
3488 +++ linux-2.6.6/net/ipv4/netfilter/ip_conntrack_egg.c 2004-05-18 14:28:50.000000000 +0200
3490 +/* Eggdrop extension for IP connection tracking, Version 0.0.5
3491 + * based on ip_conntrack_irc.c
3493 + * This module only supports the share userfile-send command,
3494 + * used by eggdrops to share it's userfile.
3496 + * There are no support for NAT at the moment.
3498 + * This program is free software; you can redistribute it and/or
3499 + * modify it under the terms of the GNU General Public License
3500 + * as published by the Free Software Foundation; either version
3501 + * 2 of the License, or (at your option) any later version.
3503 + * Module load syntax:
3505 + * please give the ports of all Eggdrops You have running
3506 + * on your system, the default port is 3333.
3508 + * 2001-04-19: Security update. IP addresses are now compared
3509 + * to prevent unauthorized "related" access.
3511 + * 2002-03-25: Harald Welte <laforge@gnumonks.org>:
3512 + * Port to netfilter 'newnat' API.
3515 +#include <linux/module.h>
3516 +#include <linux/netfilter.h>
3517 +#include <linux/ip.h>
3518 +#include <net/checksum.h>
3519 +#include <net/tcp.h>
3521 +#include <linux/netfilter_ipv4/lockhelp.h>
3522 +#include <linux/netfilter_ipv4/ip_conntrack_helper.h>
3524 +#define MAX_PORTS 8
3525 +static int ports[MAX_PORTS];
3526 +static int ports_c = 0;
3527 +static unsigned int egg_timeout = 300;
3529 +MODULE_AUTHOR("Magnus Sandin <magnus@sandin.cx>");
3530 +MODULE_DESCRIPTION("Eggdrop (userfile-sharing) connection tracking module");
3531 +MODULE_LICENSE("GPL");
3533 +MODULE_PARM(ports, "1-" __MODULE_STRING(MAX_PORTS) "i");
3534 +MODULE_PARM_DESC(ports, "port numbers of eggdrop servers");
3537 +DECLARE_LOCK(ip_egg_lock);
3538 +struct module *ip_conntrack_egg = THIS_MODULE;
3541 +#define DEBUGP printk
3543 +#define DEBUGP(format, args...)
3546 +int parse_command(char *data, char *data_end, u_int32_t * ip, u_int16_t * port)
3547 +/* tries to get the ip_addr and port out of a eggdrop command
3548 + return value: -1 on failure, 0 on success
3549 + data pointer to first byte of DCC command data
3550 + data_end pointer to last byte of dcc command data
3551 + ip returns parsed ip of dcc command
3552 + port returns parsed port of dcc command */
3554 + if (data > data_end)
3557 + *ip = simple_strtoul(data, &data, 10);
3559 + /* skip blanks between ip and port */
3560 + while (*data == ' ' && data < data_end)
3563 + *port = simple_strtoul(data, &data, 10);
3568 +static int help(const struct iphdr *iph, size_t len,
3569 + struct ip_conntrack *ct, enum ip_conntrack_info ctinfo)
3571 + /* tcplen not negative guarenteed by ip_conntrack_tcp.c */
3572 + struct tcphdr *tcph = (void *) iph + iph->ihl * 4;
3573 + char *data = (char *) tcph + tcph->doff * 4;
3575 + u_int32_t tcplen = len - iph->ihl * 4;
3576 + u_int32_t datalen = tcplen - tcph->doff * 4;
3577 + int dir = CTINFO2DIR(ctinfo);
3578 + int bytes_scanned = 0;
3579 + struct ip_conntrack_expect exp;
3582 + u_int16_t egg_port;
3584 + DEBUGP("entered\n");
3586 + /* If packet is coming from IRC server */
3587 + if (dir != IP_CT_DIR_REPLY)
3590 + /* Until there's been traffic both ways, don't look in packets. */
3591 + if (ctinfo != IP_CT_ESTABLISHED
3592 + && ctinfo != IP_CT_ESTABLISHED + IP_CT_IS_REPLY) {
3593 + DEBUGP("Conntrackinfo = %u\n", ctinfo);
3597 + /* Not whole TCP header? */
3598 + if (tcplen < sizeof(struct tcphdr) || tcplen < tcph->doff * 4) {
3599 + DEBUGP("tcplen = %u\n", (unsigned) tcplen);
3603 + /* Checksum invalid? Ignore. */
3604 + /* FIXME: Source route IP option packets --RR */
3605 + if (tcp_v4_check(tcph, tcplen, iph->saddr, iph->daddr,
3606 + csum_partial((char *) tcph, tcplen, 0))) {
3607 + DEBUGP("bad csum: %p %u %u.%u.%u.%u -> %u.%u.%u.%u\n",
3608 + tcph, tcplen, NIPQUAD(iph->saddr),
3609 + NIPQUAD(iph->daddr));
3613 + data_limit = (char *) data + datalen;
3614 + while (datalen > 5 && bytes_scanned < 128) {
3615 + if (memcmp(data, "s us ", 5)) {
3624 + DEBUGP("Userfile-share found in connection "
3625 + "%u.%u.%u.%u -> %u.%u.%u.%u\n",
3626 + NIPQUAD(iph->saddr), NIPQUAD(iph->daddr));
3628 + if (parse_command((char *) data, data_limit, &egg_ip,
3630 + DEBUGP("no data in userfile-share pkt\n");
3634 + memset(&exp, 0, sizeof(exp));
3636 + if (ct->tuplehash[dir].tuple.src.ip != htonl(egg_ip)) {
3637 + if (net_ratelimit())
3638 + printk("Forged Eggdrop command from "
3639 + "%u.%u.%u.%u: %u.%u.%u.%u:%u\n",
3640 + NIPQUAD(ct->tuplehash[dir].tuple.src.ip),
3641 + HIPQUAD(egg_ip), egg_port);
3645 + exp.tuple.src.ip = iph->daddr;
3646 + exp.tuple.src.u.tcp.port = 0;
3647 + exp.tuple.dst.ip = htonl(egg_ip);
3648 + exp.tuple.dst.u.tcp.port = htons(egg_port);
3649 + exp.tuple.dst.protonum = IPPROTO_TCP;
3651 + exp.mask.dst.u.tcp.port = 0xffff;
3652 + exp.mask.dst.protonum = 0xffff;
3654 + DEBUGP("expect_related %u.%u.%u.%u:%u - %u.%u.%u.%u:%u\n",
3655 + NIPQUAD(t.src.ip), ntohs(t.src.u.tcp.port),
3656 + NIPQUAD(t.dst.ip), ntohs(t.dst.u.tcp.port));
3658 + ip_conntrack_expect_related(ct, &exp);
3664 +static struct ip_conntrack_helper egg_helpers[MAX_PORTS];
3665 +static char egg_names[MAX_PORTS][14]; /* eggdrop-65535 */
3667 +static void deregister_helpers(void) {
3670 + for (i = 0; i < ports_c; i++) {
3671 + DEBUGP("unregistering helper for port %d\n", ports[i]);
3672 + ip_conntrack_helper_unregister(&egg_helpers[i]);
3676 +static int __init init(void)
3681 + /* If no port given, default to standard eggdrop port */
3682 + if (ports[0] == 0)
3685 + for (i = 0; (i < MAX_PORTS) && ports[i]; i++) {
3686 + memset(&egg_helpers[i], 0,
3687 + sizeof(struct ip_conntrack_helper));
3688 + egg_helpers[i].tuple.src.u.tcp.port = htons(ports[i]);
3689 + egg_helpers[i].tuple.dst.protonum = IPPROTO_TCP;
3690 + egg_helpers[i].mask.src.u.tcp.port = 0xFFFF;
3691 + egg_helpers[i].mask.dst.protonum = 0xFFFF;
3692 + egg_helpers[i].max_expected = 1;
3693 + egg_helpers[i].timeout = egg_timeout;
3694 + egg_helpers[i].flags = IP_CT_HELPER_F_REUSE_EXPECT;
3695 + egg_helpers[i].me = THIS_MODULE;
3696 + egg_helpers[i].help = help;
3698 + tmpname = &egg_names[i][0];
3699 + if (ports[i] == 3333)
3700 + sprintf(tmpname, "eggdrop");
3702 + sprintf(tmpname, "eggdrop-%d", ports[i]);
3703 + egg_helpers[i].name = tmpname;
3705 + DEBUGP("port #%d: %d\n", i, ports[i]);
3707 + ret = ip_conntrack_helper_register(&egg_helpers[i]);
3710 + printk("ip_conntrack_egg: ERROR registering helper "
3711 + "for port %d\n", ports[i]);
3712 + deregister_helpers();
3720 +static void __exit fini(void)
3722 + deregister_helpers();
3727 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ip_conntrack_h323.c linux-2.6.6/net/ipv4/netfilter/ip_conntrack_h323.c
3728 --- linux-2.6.6.org/net/ipv4/netfilter/ip_conntrack_h323.c 1970-01-01 01:00:00.000000000 +0100
3729 +++ linux-2.6.6/net/ipv4/netfilter/ip_conntrack_h323.c 2004-05-18 14:28:50.000000000 +0200
3732 + * H.323 'brute force' extension for H.323 connection tracking.
3733 + * Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
3735 + * Based on ip_masq_h323.c for 2.2 kernels from CoRiTel, Sofia project.
3736 + * (http://www.coritel.it/projects/sofia/nat/)
3737 + * Uses Sampsa Ranta's excellent idea on using expectfn to 'bind'
3738 + * the unregistered helpers to the conntrack entries.
3742 +#include <linux/module.h>
3743 +#include <linux/netfilter.h>
3744 +#include <linux/ip.h>
3745 +#include <net/checksum.h>
3746 +#include <net/tcp.h>
3748 +#include <linux/netfilter_ipv4/lockhelp.h>
3749 +#include <linux/netfilter_ipv4/ip_conntrack.h>
3750 +#include <linux/netfilter_ipv4/ip_conntrack_core.h>
3751 +#include <linux/netfilter_ipv4/ip_conntrack_helper.h>
3752 +#include <linux/netfilter_ipv4/ip_conntrack_tuple.h>
3753 +#include <linux/netfilter_ipv4/ip_conntrack_h323.h>
3755 +MODULE_AUTHOR("Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>");
3756 +MODULE_DESCRIPTION("H.323 'brute force' connection tracking module");
3757 +MODULE_LICENSE("GPL");
3759 +DECLARE_LOCK(ip_h323_lock);
3760 +struct module *ip_conntrack_h323 = THIS_MODULE;
3763 +#define DEBUGP printk
3765 +#define DEBUGP(format, args...)
3768 +/* FIXME: This should be in userspace. Later. */
3769 +static int h245_help(const struct iphdr *iph, size_t len,
3770 + struct ip_conntrack *ct,
3771 + enum ip_conntrack_info ctinfo)
3773 + struct tcphdr *tcph = (void *)iph + iph->ihl * 4;
3774 + unsigned char *data = (unsigned char *) tcph + tcph->doff * 4;
3775 + unsigned char *data_limit;
3776 + u_int32_t tcplen = len - iph->ihl * 4;
3777 + u_int32_t datalen = tcplen - tcph->doff * 4;
3778 + int dir = CTINFO2DIR(ctinfo);
3779 + struct ip_ct_h225_master *info = &ct->help.ct_h225_info;
3780 + struct ip_conntrack_expect expect, *exp = &expect;
3781 + struct ip_ct_h225_expect *exp_info = &exp->help.exp_h225_info;
3782 + u_int16_t data_port;
3783 + u_int32_t data_ip;
3786 + DEBUGP("ct_h245_help: help entered %u.%u.%u.%u:%u->%u.%u.%u.%u:%u\n",
3787 + NIPQUAD(iph->saddr), ntohs(tcph->source),
3788 + NIPQUAD(iph->daddr), ntohs(tcph->dest));
3790 + /* Can't track connections formed before we registered */
3794 + /* Until there's been traffic both ways, don't look in packets. */
3795 + if (ctinfo != IP_CT_ESTABLISHED
3796 + && ctinfo != IP_CT_ESTABLISHED + IP_CT_IS_REPLY) {
3797 + DEBUGP("ct_h245_help: Conntrackinfo = %u\n", ctinfo);
3801 + /* Not whole TCP header or too short packet? */
3802 + if (tcplen < sizeof(struct tcphdr) || tcplen < tcph->doff * 4 + 5) {
3803 + DEBUGP("ct_h245_help: tcplen = %u\n", (unsigned)tcplen);
3807 + /* Checksum invalid? Ignore. */
3808 + /* FIXME: Source route IP option packets --RR */
3809 + if (tcp_v4_check(tcph, tcplen, iph->saddr, iph->daddr,
3810 + csum_partial((char *)tcph, tcplen, 0))) {
3811 + DEBUGP("ct_h245_help: bad csum: %p %u %u.%u.%u.%u %u.%u.%u.%u\n",
3812 + tcph, tcplen, NIPQUAD(iph->saddr),
3813 + NIPQUAD(iph->daddr));
3817 + data_limit = (unsigned char *) data + datalen;
3820 + for (i = 0; data < (data_limit - 5); data++, i++) {
3821 + data_ip = *((u_int32_t *)data);
3822 + if (data_ip == iph->saddr) {
3823 + data_port = *((u_int16_t *)(data + 4));
3824 + memset(&expect, 0, sizeof(expect));
3825 + /* update the H.225 info */
3826 + DEBUGP("ct_h245_help: new RTCP/RTP requested %u.%u.%u.%u:->%u.%u.%u.%u:%u\n",
3827 + NIPQUAD(ct->tuplehash[!dir].tuple.src.ip),
3828 + NIPQUAD(iph->saddr), ntohs(data_port));
3829 + LOCK_BH(&ip_h323_lock);
3830 + info->is_h225 = H225_PORT + 1;
3831 + exp_info->port = data_port;
3832 + exp_info->dir = dir;
3833 + exp_info->offset = i;
3835 + exp->seq = ntohl(tcph->seq) + i;
3837 + exp->tuple = ((struct ip_conntrack_tuple)
3838 + { { ct->tuplehash[!dir].tuple.src.ip,
3841 + { .tcp = { data_port } },
3843 + exp->mask = ((struct ip_conntrack_tuple)
3844 + { { 0xFFFFFFFF, { 0 } },
3845 + { 0xFFFFFFFF, { .tcp = { 0xFFFF } }, 0xFFFF }});
3847 + exp->expectfn = NULL;
3849 + /* Ignore failure; should only happen with NAT */
3850 + ip_conntrack_expect_related(ct, exp);
3852 + UNLOCK_BH(&ip_h323_lock);
3860 +/* H.245 helper is not registered! */
3861 +static struct ip_conntrack_helper h245 =
3863 + "H.245", /* name */
3864 + IP_CT_HELPER_F_REUSE_EXPECT, /* flags */
3865 + NULL, /* module */
3866 + 8, /* max_ expected */
3867 + 240, /* timeout */
3868 + { { 0, { 0 } }, /* tuple */
3869 + { 0, { 0 }, IPPROTO_TCP } },
3870 + { { 0, { 0xFFFF } }, /* mask */
3871 + { 0, { 0 }, 0xFFFF } },
3872 + h245_help /* helper */
3875 +static int h225_expect(struct ip_conntrack *ct)
3877 + WRITE_LOCK(&ip_conntrack_lock);
3878 + ct->helper = &h245;
3879 + DEBUGP("h225_expect: helper for %p added\n", ct);
3880 + WRITE_UNLOCK(&ip_conntrack_lock);
3882 + return NF_ACCEPT; /* unused */
3885 +/* FIXME: This should be in userspace. Later. */
3886 +static int h225_help(const struct iphdr *iph, size_t len,
3887 + struct ip_conntrack *ct,
3888 + enum ip_conntrack_info ctinfo)
3890 + struct tcphdr *tcph = (void *)iph + iph->ihl * 4;
3891 + unsigned char *data = (unsigned char *) tcph + tcph->doff * 4;
3892 + unsigned char *data_limit;
3893 + u_int32_t tcplen = len - iph->ihl * 4;
3894 + u_int32_t datalen = tcplen - tcph->doff * 4;
3895 + int dir = CTINFO2DIR(ctinfo);
3896 + struct ip_ct_h225_master *info = &ct->help.ct_h225_info;
3897 + struct ip_conntrack_expect expect, *exp = &expect;
3898 + struct ip_ct_h225_expect *exp_info = &exp->help.exp_h225_info;
3899 + u_int16_t data_port;
3900 + u_int32_t data_ip;
3903 + DEBUGP("ct_h225_help: help entered %u.%u.%u.%u:%u->%u.%u.%u.%u:%u\n",
3904 + NIPQUAD(iph->saddr), ntohs(tcph->source),
3905 + NIPQUAD(iph->daddr), ntohs(tcph->dest));
3907 + /* Can't track connections formed before we registered */
3911 + /* Until there's been traffic both ways, don't look in packets. */
3912 + if (ctinfo != IP_CT_ESTABLISHED
3913 + && ctinfo != IP_CT_ESTABLISHED + IP_CT_IS_REPLY) {
3914 + DEBUGP("ct_h225_help: Conntrackinfo = %u\n", ctinfo);
3918 + /* Not whole TCP header or too short packet? */
3919 + if (tcplen < sizeof(struct tcphdr) || tcplen < tcph->doff * 4 + 5) {
3920 + DEBUGP("ct_h225_help: tcplen = %u\n", (unsigned)tcplen);
3924 + /* Checksum invalid? Ignore. */
3925 + /* FIXME: Source route IP option packets --RR */
3926 + if (tcp_v4_check(tcph, tcplen, iph->saddr, iph->daddr,
3927 + csum_partial((char *)tcph, tcplen, 0))) {
3928 + DEBUGP("ct_h225_help: bad csum: %p %u %u.%u.%u.%u %u.%u.%u.%u\n",
3929 + tcph, tcplen, NIPQUAD(iph->saddr),
3930 + NIPQUAD(iph->daddr));
3934 + data_limit = (unsigned char *) data + datalen;
3937 + for (i = 0; data < (data_limit - 5); data++, i++) {
3938 + data_ip = *((u_int32_t *)data);
3939 + if (data_ip == iph->saddr) {
3940 + data_port = *((u_int16_t *)(data + 4));
3941 + if (data_port == tcph->source) {
3942 + /* Signal address */
3943 + DEBUGP("ct_h225_help: sourceCallSignalAddress from %u.%u.%u.%u\n",
3944 + NIPQUAD(iph->saddr));
3945 + /* Update the H.225 info so that NAT can mangle the address/port
3946 + even when we have no expected connection! */
3947 +#ifdef CONFIG_IP_NF_NAT_NEEDED
3948 + LOCK_BH(&ip_h323_lock);
3950 + info->seq[IP_CT_DIR_ORIGINAL] = ntohl(tcph->seq) + i;
3951 + info->offset[IP_CT_DIR_ORIGINAL] = i;
3952 + UNLOCK_BH(&ip_h323_lock);
3955 + memset(&expect, 0, sizeof(expect));
3957 + /* update the H.225 info */
3958 + LOCK_BH(&ip_h323_lock);
3959 + info->is_h225 = H225_PORT;
3960 + exp_info->port = data_port;
3961 + exp_info->dir = dir;
3962 + exp_info->offset = i;
3964 + exp->seq = ntohl(tcph->seq) + i;
3966 + exp->tuple = ((struct ip_conntrack_tuple)
3967 + { { ct->tuplehash[!dir].tuple.src.ip,
3970 + { .tcp = { data_port } },
3972 + exp->mask = ((struct ip_conntrack_tuple)
3973 + { { 0xFFFFFFFF, { 0 } },
3974 + { 0xFFFFFFFF, { .tcp = { 0xFFFF } }, 0xFFFF }});
3976 + exp->expectfn = h225_expect;
3978 + /* Ignore failure */
3979 + ip_conntrack_expect_related(ct, exp);
3981 + DEBUGP("ct_h225_help: new H.245 requested %u.%u.%u.%u->%u.%u.%u.%u:%u\n",
3982 + NIPQUAD(ct->tuplehash[!dir].tuple.src.ip),
3983 + NIPQUAD(iph->saddr), ntohs(data_port));
3985 + UNLOCK_BH(&ip_h323_lock);
3987 +#ifdef CONFIG_IP_NF_NAT_NEEDED
3988 + } else if (data_ip == iph->daddr) {
3989 + data_port = *((u_int16_t *)(data + 4));
3990 + if (data_port == tcph->dest) {
3991 + /* Signal address */
3992 + DEBUGP("ct_h225_help: destCallSignalAddress %u.%u.%u.%u\n",
3993 + NIPQUAD(iph->daddr));
3994 + /* Update the H.225 info so that NAT can mangle the address/port
3995 + even when we have no expected connection! */
3996 + LOCK_BH(&ip_h323_lock);
3998 + info->seq[IP_CT_DIR_REPLY] = ntohl(tcph->seq) + i;
3999 + info->offset[IP_CT_DIR_REPLY] = i;
4000 + UNLOCK_BH(&ip_h323_lock);
4010 +static struct ip_conntrack_helper h225 =
4012 + "H.225", /* name */
4013 + IP_CT_HELPER_F_REUSE_EXPECT, /* flags */
4014 + THIS_MODULE, /* module */
4015 + 2, /* max_expected */
4016 + 240, /* timeout */
4017 + { { 0, { __constant_htons(H225_PORT) } }, /* tuple */
4018 + { 0, { 0 }, IPPROTO_TCP } },
4019 + { { 0, { 0xFFFF } }, /* mask */
4020 + { 0, { 0 }, 0xFFFF } },
4021 + h225_help /* helper */
4024 +static int __init init(void)
4026 + return ip_conntrack_helper_register(&h225);
4029 +static void __exit fini(void)
4031 + /* Unregister H.225 helper */
4032 + ip_conntrack_helper_unregister(&h225);
4035 +EXPORT_SYMBOL(ip_h323_lock);
4039 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ip_conntrack_mms.c linux-2.6.6/net/ipv4/netfilter/ip_conntrack_mms.c
4040 --- linux-2.6.6.org/net/ipv4/netfilter/ip_conntrack_mms.c 1970-01-01 01:00:00.000000000 +0100
4041 +++ linux-2.6.6/net/ipv4/netfilter/ip_conntrack_mms.c 2004-05-18 14:28:50.000000000 +0200
4043 +/* MMS extension for IP connection tracking
4044 + * (C) 2002 by Filip Sneppe <filip.sneppe@cronos.be>
4045 + * based on ip_conntrack_ftp.c and ip_conntrack_irc.c
4047 + * ip_conntrack_mms.c v0.3 2002-09-22
4049 + * This program is free software; you can redistribute it and/or
4050 + * modify it under the terms of the GNU General Public License
4051 + * as published by the Free Software Foundation; either version
4052 + * 2 of the License, or (at your option) any later version.
4054 + * Module load syntax:
4055 + * insmod ip_conntrack_mms.o ports=port1,port2,...port<MAX_PORTS>
4057 + * Please give the ports of all MMS servers You wish to connect to.
4058 + * If you don't specify ports, the default will be TCP port 1755.
4060 + * More info on MMS protocol, firewalls and NAT:
4061 + * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwmt/html/MMSFirewall.asp
4062 + * http://www.microsoft.com/windows/windowsmedia/serve/firewall.asp
4064 + * The SDP project people are reverse-engineering MMS:
4065 + * http://get.to/sdp
4068 +#include <linux/config.h>
4069 +#include <linux/module.h>
4070 +#include <linux/netfilter.h>
4071 +#include <linux/ip.h>
4072 +#include <linux/ctype.h>
4073 +#include <net/checksum.h>
4074 +#include <net/tcp.h>
4076 +#include <linux/netfilter_ipv4/lockhelp.h>
4077 +#include <linux/netfilter_ipv4/ip_conntrack_helper.h>
4078 +#include <linux/netfilter_ipv4/ip_conntrack_mms.h>
4080 +DECLARE_LOCK(ip_mms_lock);
4081 +struct module *ip_conntrack_mms = THIS_MODULE;
4083 +#define MAX_PORTS 8
4084 +static int ports[MAX_PORTS];
4085 +static int ports_c;
4087 +MODULE_PARM(ports, "1-" __MODULE_STRING(MAX_PORTS) "i");
4091 +#define DEBUGP printk
4093 +#define DEBUGP(format, args...)
4096 +EXPORT_SYMBOL(ip_mms_lock);
4098 +MODULE_AUTHOR("Filip Sneppe <filip.sneppe@cronos.be>");
4099 +MODULE_DESCRIPTION("Microsoft Windows Media Services (MMS) connection tracking module");
4100 +MODULE_LICENSE("GPL");
4102 +/* #define isdigit(c) (c >= '0' && c <= '9') */
4104 +/* copied from drivers/usb/serial/io_edgeport.c - not perfect but will do the trick */
4105 +static void unicode_to_ascii (char *string, short *unicode, int unicode_size)
4108 + for (i = 0; i < unicode_size; ++i) {
4109 + string[i] = (char)(unicode[i]);
4111 + string[unicode_size] = 0x00;
4114 +__inline static int atoi(char *s)
4117 + while (isdigit(*s)) {
4118 + i = i*10 + *(s++) - '0';
4123 +/* convert ip address string like "192.168.0.10" to unsigned int */
4124 +__inline static u_int32_t asciiiptoi(char *s)
4126 + unsigned int i, j, k;
4128 + for(i=k=0; k<3; ++k, ++s, i<<=8) {
4130 + for(j=0; (*(++s) != '.') && (j<3); ++j)
4137 +int parse_mms(const char *data,
4138 + const unsigned int datalen,
4139 + u_int32_t *mms_ip,
4140 + u_int16_t *mms_proto,
4141 + u_int16_t *mms_port,
4142 + char **mms_string_b,
4143 + char **mms_string_e,
4144 + char **mms_padding_e)
4146 + int unicode_size, i;
4147 + char tempstring[28]; /* "\\255.255.255.255\UDP\65535" */
4148 + char getlengthstring[28];
4150 + for(unicode_size=0;
4151 + (char) *(data+(MMS_SRV_UNICODE_STRING_OFFSET+unicode_size*2)) != (char)0;
4153 + if ((unicode_size == 28) || (MMS_SRV_UNICODE_STRING_OFFSET+unicode_size*2 >= datalen))
4154 + return -1; /* out of bounds - incomplete packet */
4156 + unicode_to_ascii(tempstring, (short *)(data+MMS_SRV_UNICODE_STRING_OFFSET), unicode_size);
4157 + DEBUGP("ip_conntrack_mms: offset 60: %s\n", (const char *)(tempstring));
4159 + /* IP address ? */
4160 + *mms_ip = asciiiptoi(tempstring+2);
4162 + i=sprintf(getlengthstring, "%u.%u.%u.%u", HIPQUAD(*mms_ip));
4165 + if(strncmp(tempstring+3+i, "TCP", 3)==0)
4166 + *mms_proto = IPPROTO_TCP;
4167 + else if(strncmp(tempstring+3+i, "UDP", 3)==0)
4168 + *mms_proto = IPPROTO_UDP;
4171 + *mms_port = atoi(tempstring+7+i);
4173 + /* we store a pointer to the beginning of the "\\a.b.c.d\proto\port"
4174 + unicode string, one to the end of the string, and one to the end
4175 + of the packet, since we must keep track of the number of bytes
4176 + between end of the unicode string and the end of packet (padding) */
4177 + *mms_string_b = (char *)(data + MMS_SRV_UNICODE_STRING_OFFSET);
4178 + *mms_string_e = (char *)(data + MMS_SRV_UNICODE_STRING_OFFSET + unicode_size * 2);
4179 + *mms_padding_e = (char *)(data + datalen); /* looks funny, doesn't it */
4184 +/* FIXME: This should be in userspace. Later. */
4185 +static int help(const struct iphdr *iph, size_t len,
4186 + struct ip_conntrack *ct,
4187 + enum ip_conntrack_info ctinfo)
4189 + /* tcplen not negative guaranteed by ip_conntrack_tcp.c */
4190 + struct tcphdr *tcph = (void *)iph + iph->ihl * 4;
4191 + const char *data = (const char *)tcph + tcph->doff * 4;
4192 + unsigned int tcplen = len - iph->ihl * 4;
4193 + unsigned int datalen = tcplen - tcph->doff * 4;
4194 + int dir = CTINFO2DIR(ctinfo);
4195 + struct ip_conntrack_expect expect, *exp = &expect;
4196 + struct ip_ct_mms_expect *exp_mms_info = &exp->help.exp_mms_info;
4199 + u_int16_t mms_proto;
4200 + char mms_proto_string[8];
4201 + u_int16_t mms_port;
4202 + char *mms_string_b, *mms_string_e, *mms_padding_e;
4204 + /* Until there's been traffic both ways, don't look in packets. */
4205 + if (ctinfo != IP_CT_ESTABLISHED
4206 + && ctinfo != IP_CT_ESTABLISHED+IP_CT_IS_REPLY) {
4207 + DEBUGP("ip_conntrack_mms: Conntrackinfo = %u\n", ctinfo);
4211 + /* Not whole TCP header? */
4212 + if (tcplen < sizeof(struct tcphdr) || tcplen < tcph->doff*4) {
4213 + DEBUGP("ip_conntrack_mms: tcplen = %u\n", (unsigned)tcplen);
4217 + /* Checksum invalid? Ignore. */
4218 + /* FIXME: Source route IP option packets --RR */
4219 + if (tcp_v4_check(tcph, tcplen, iph->saddr, iph->daddr,
4220 + csum_partial((char *)tcph, tcplen, 0))) {
4221 + DEBUGP("mms_help: bad csum: %p %u %u.%u.%u.%u %u.%u.%u.%u\n",
4222 + tcph, tcplen, NIPQUAD(iph->saddr),
4223 + NIPQUAD(iph->daddr));
4227 + /* Only look at packets with 0x00030002/196610 on bytes 36->39 of TCP payload */
4228 + /* FIXME: There is an issue with only looking at this packet: before this packet,
4229 + the client has already sent a packet to the server with the server's hostname
4230 + according to the client (think of it as the "Host: " header in HTTP/1.1). The
4231 + server will break the connection if this doesn't correspond to its own host
4232 + header. The client can also connect to an IP address; if it's the server's IP
4233 + address, it will not break the connection. When doing DNAT on a connection
4234 + where the client uses a server's IP address, the nat module should detect
4235 + this and change this string accordingly to the DNATed address. This should
4236 + probably be done by checking for an IP address, then storing it as a member
4237 + of struct ip_ct_mms_expect and checking for it in ip_nat_mms...
4239 + if( (MMS_SRV_MSG_OFFSET < datalen) &&
4240 + ((*(u32 *)(data+MMS_SRV_MSG_OFFSET)) == MMS_SRV_MSG_ID)) {
4241 + DEBUGP("ip_conntrack_mms: offset 37: %u %u %u %u, datalen:%u\n",
4242 + (u8)*(data+36), (u8)*(data+37),
4243 + (u8)*(data+38), (u8)*(data+39),
4245 + if(parse_mms(data, datalen, &mms_ip, &mms_proto, &mms_port,
4246 + &mms_string_b, &mms_string_e, &mms_padding_e))
4247 + if(net_ratelimit())
4248 + /* FIXME: more verbose debugging ? */
4249 + printk(KERN_WARNING
4250 + "ip_conntrack_mms: Unable to parse data payload\n");
4252 + memset(&expect, 0, sizeof(expect));
4254 + sprintf(mms_proto_string, "(%u)", mms_proto);
4255 + DEBUGP("ip_conntrack_mms: adding %s expectation %u.%u.%u.%u -> %u.%u.%u.%u:%u\n",
4256 + mms_proto == IPPROTO_TCP ? "TCP"
4257 + : mms_proto == IPPROTO_UDP ? "UDP":mms_proto_string,
4258 + NIPQUAD(ct->tuplehash[!dir].tuple.src.ip),
4262 + /* it's possible that the client will just ask the server to tunnel
4263 + the stream over the same TCP session (from port 1755): there's
4264 + shouldn't be a need to add an expectation in that case, but it
4265 + makes NAT packet mangling so much easier */
4266 + LOCK_BH(&ip_mms_lock);
4268 + DEBUGP("ip_conntrack_mms: tcph->seq = %u\n", tcph->seq);
4270 + exp->seq = ntohl(tcph->seq) + (mms_string_b - data);
4271 + exp_mms_info->len = (mms_string_e - mms_string_b);
4272 + exp_mms_info->padding = (mms_padding_e - mms_string_e);
4273 + exp_mms_info->port = mms_port;
4275 + DEBUGP("ip_conntrack_mms: wrote info seq=%u (ofs=%u), len=%d, padding=%u\n",
4276 + exp->seq, (mms_string_e - data), exp_mms_info->len, exp_mms_info->padding);
4278 + exp->tuple = ((struct ip_conntrack_tuple)
4279 + { { ct->tuplehash[!dir].tuple.src.ip, { 0 } },
4281 + { .tcp = { (__u16) ntohs(mms_port) } },
4284 + exp->mask = ((struct ip_conntrack_tuple)
4285 + { { 0xFFFFFFFF, { 0 } },
4286 + { 0xFFFFFFFF, { .tcp = { 0xFFFF } }, 0xFFFF }});
4287 + exp->expectfn = NULL;
4288 + ip_conntrack_expect_related(ct, &expect);
4289 + UNLOCK_BH(&ip_mms_lock);
4295 +static struct ip_conntrack_helper mms[MAX_PORTS];
4296 +static char mms_names[MAX_PORTS][10];
4298 +/* Not __exit: called from init() */
4299 +static void fini(void)
4302 + for (i = 0; (i < MAX_PORTS) && ports[i]; i++) {
4303 + DEBUGP("ip_conntrack_mms: unregistering helper for port %d\n",
4305 + ip_conntrack_helper_unregister(&mms[i]);
4309 +static int __init init(void)
4314 + if (ports[0] == 0)
4315 + ports[0] = MMS_PORT;
4317 + for (i = 0; (i < MAX_PORTS) && ports[i]; i++) {
4318 + memset(&mms[i], 0, sizeof(struct ip_conntrack_helper));
4319 + mms[i].tuple.src.u.tcp.port = htons(ports[i]);
4320 + mms[i].tuple.dst.protonum = IPPROTO_TCP;
4321 + mms[i].mask.src.u.tcp.port = 0xFFFF;
4322 + mms[i].mask.dst.protonum = 0xFFFF;
4323 + mms[i].max_expected = 1;
4324 + mms[i].timeout = 0;
4325 + mms[i].flags = IP_CT_HELPER_F_REUSE_EXPECT;
4326 + mms[i].me = THIS_MODULE;
4327 + mms[i].help = help;
4329 + tmpname = &mms_names[i][0];
4330 + if (ports[i] == MMS_PORT)
4331 + sprintf(tmpname, "mms");
4333 + sprintf(tmpname, "mms-%d", ports[i]);
4334 + mms[i].name = tmpname;
4336 + DEBUGP("ip_conntrack_mms: registering helper for port %d\n",
4338 + ret = ip_conntrack_helper_register(&mms[i]);
4351 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ip_conntrack_proto_sctp.c linux-2.6.6/net/ipv4/netfilter/ip_conntrack_proto_sctp.c
4352 --- linux-2.6.6.org/net/ipv4/netfilter/ip_conntrack_proto_sctp.c 1970-01-01 01:00:00.000000000 +0100
4353 +++ linux-2.6.6/net/ipv4/netfilter/ip_conntrack_proto_sctp.c 2004-05-18 14:28:50.000000000 +0200
4356 + * Connection tracking protocol helper module for SCTP.
4358 + * SCTP is defined in RFC 2960. References to various sections in this code
4359 + * are to this RFC.
4361 + * This program is free software; you can redistribute it and/or modify
4362 + * it under the terms of the GNU General Public License version 2 as
4363 + * published by the Free Software Foundation.
4366 +#include <linux/types.h>
4367 +#include <linux/sched.h>
4368 +#include <linux/timer.h>
4369 +#include <linux/netfilter.h>
4370 +#include <linux/module.h>
4371 +#include <linux/in.h>
4372 +#include <linux/ip.h>
4373 +#include <linux/sctp.h>
4374 +#include <linux/string.h>
4376 +#include <linux/netfilter_ipv4/ip_conntrack.h>
4377 +#include <linux/netfilter_ipv4/ip_conntrack_protocol.h>
4378 +#include <linux/netfilter_ipv4/lockhelp.h>
4381 +#define DEBUGP(format, ...) printk(format, ## __VA_ARGS__)
4383 +#define DEBUGP(format, args...)
4386 +/* Protects conntrack->proto.sctp */
4387 +static DECLARE_RWLOCK(sctp_lock);
4389 +/* FIXME: Examine ipfilter's timeouts and conntrack transitions more
4390 + closely. They're more complex. --RR
4392 + And so for me for SCTP :D -Kiran */
4394 +static const char *sctp_conntrack_names[] = {
4402 + "SHUTDOWN_ACK_SENT",
4406 +#define MINS * 60 SECS
4407 +#define HOURS * 60 MINS
4408 +#define DAYS * 24 HOURS
4410 +unsigned long ip_ct_sctp_timeout_closed = 10 SECS;
4411 +unsigned long ip_ct_sctp_timeout_cookie_wait = 3 SECS;
4412 +unsigned long ip_ct_sctp_timeout_cookie_echoed = 3 SECS;
4413 +unsigned long ip_ct_sctp_timeout_established = 5 DAYS;
4414 +unsigned long ip_ct_sctp_timeout_shutdown_sent = 300 SECS / 1000;
4415 +unsigned long ip_ct_sctp_timeout_shutdown_recd = 300 SECS / 1000;
4416 +unsigned long ip_ct_sctp_timeout_shutdown_ack_sent = 3 SECS;
4418 +static unsigned long * sctp_timeouts[]
4419 += { 0, /* SCTP_CONNTRACK_NONE */
4420 + &ip_ct_sctp_timeout_closed, /* SCTP_CONNTRACK_CLOSED */
4421 + &ip_ct_sctp_timeout_cookie_wait, /* SCTP_CONNTRACK_COOKIE_WAIT */
4422 + &ip_ct_sctp_timeout_cookie_echoed, /* SCTP_CONNTRACK_COOKIE_ECHOED */
4423 + &ip_ct_sctp_timeout_established, /* SCTP_CONNTRACK_ESTABLISHED */
4424 + &ip_ct_sctp_timeout_shutdown_sent, /* SCTP_CONNTRACK_SHUTDOWN_SENT */
4425 + &ip_ct_sctp_timeout_shutdown_recd, /* SCTP_CONNTRACK_SHUTDOWN_RECD */
4426 + &ip_ct_sctp_timeout_shutdown_ack_sent /* SCTP_CONNTRACK_SHUTDOWN_ACK_SENT */
4429 +#define sNO SCTP_CONNTRACK_NONE
4430 +#define sCL SCTP_CONNTRACK_CLOSED
4431 +#define sCW SCTP_CONNTRACK_COOKIE_WAIT
4432 +#define sCE SCTP_CONNTRACK_COOKIE_ECHOED
4433 +#define sES SCTP_CONNTRACK_ESTABLISHED
4434 +#define sSS SCTP_CONNTRACK_SHUTDOWN_SENT
4435 +#define sSR SCTP_CONNTRACK_SHUTDOWN_RECD
4436 +#define sSA SCTP_CONNTRACK_SHUTDOWN_ACK_SENT
4437 +#define sIV SCTP_CONNTRACK_MAX
4440 + These are the descriptions of the states:
4442 +NOTE: These state names are tantalizingly similar to the states of an
4443 +SCTP endpoint. But the interpretation of the states is a little different,
4444 +considering that these are the states of the connection and not of an end
4445 +point. Please note the subtleties. -Kiran
4447 +NONE - Nothing so far.
4448 +COOKIE WAIT - We have seen an INIT chunk in the original direction, or also
4449 + an INIT_ACK chunk in the reply direction.
4450 +COOKIE ECHOED - We have seen a COOKIE_ECHO chunk in the original direction.
4451 +ESTABLISHED - We have seen a COOKIE_ACK in the reply direction.
4452 +SHUTDOWN_SENT - We have seen a SHUTDOWN chunk in the original direction.
4453 +SHUTDOWN_RECD - We have seen a SHUTDOWN chunk in the reply directoin.
4454 +SHUTDOWN_ACK_SENT - We have seen a SHUTDOWN_ACK chunk in the direction opposite
4455 + to that of the SHUTDOWN chunk.
4456 +CLOSED - We have seen a SHUTDOWN_COMPLETE chunk in the direction of
4457 + the SHUTDOWN chunk. Connection is closed.
4461 + - I have assumed that the first INIT is in the original direction.
4462 + This messes things when an INIT comes in the reply direction in CLOSED
4464 + - Check the error type in the reply dir before transitioning from
4465 +cookie echoed to closed.
4466 + - Sec 5.2.4 of RFC 2960
4467 + - Multi Homing support.
4470 +/* SCTP conntrack state transitions */
4471 +static enum sctp_conntrack sctp_conntracks[2][9][SCTP_CONNTRACK_MAX] = {
4474 +/* sNO, sCL, sCW, sCE, sES, sSS, sSR, sSA */
4475 +/* init */ {sCW, sCW, sCW, sCE, sES, sSS, sSR, sSA},
4476 +/* init_ack */ {sCL, sCL, sCW, sCE, sES, sSS, sSR, sSA},
4477 +/* abort */ {sCL, sCL, sCL, sCL, sCL, sCL, sCL, sCL},
4478 +/* shutdown */ {sCL, sCL, sCW, sCE, sSS, sSS, sSR, sSA},
4479 +/* shutdown_ack */ {sSA, sCL, sCW, sCE, sES, sSA, sSA, sSA},
4480 +/* error */ {sCL, sCL, sCW, sCE, sES, sSS, sSR, sSA},/* Cant have Stale cookie*/
4481 +/* cookie_echo */ {sCL, sCL, sCE, sCE, sES, sSS, sSR, sSA},/* 5.2.4 - Big TODO */
4482 +/* cookie_ack */ {sCL, sCL, sCW, sCE, sES, sSS, sSR, sSA},/* Cant come in orig dir */
4483 +/* shutdown_comp*/ {sCL, sCL, sCW, sCE, sES, sSS, sSR, sCL}
4487 +/* sNO, sCL, sCW, sCE, sES, sSS, sSR, sSA */
4488 +/* init */ {sIV, sCL, sCW, sCE, sES, sSS, sSR, sSA},/* INIT in sCL Big TODO */
4489 +/* init_ack */ {sIV, sCL, sCW, sCE, sES, sSS, sSR, sSA},
4490 +/* abort */ {sIV, sCL, sCL, sCL, sCL, sCL, sCL, sCL},
4491 +/* shutdown */ {sIV, sCL, sCW, sCE, sSR, sSS, sSR, sSA},
4492 +/* shutdown_ack */ {sIV, sCL, sCW, sCE, sES, sSA, sSA, sSA},
4493 +/* error */ {sIV, sCL, sCW, sCL, sES, sSS, sSR, sSA},
4494 +/* cookie_echo */ {sIV, sCL, sCW, sCE, sES, sSS, sSR, sSA},/* Cant come in reply dir */
4495 +/* cookie_ack */ {sIV, sCL, sCW, sES, sES, sSS, sSR, sSA},
4496 +/* shutdown_comp*/ {sIV, sCL, sCW, sCE, sES, sSS, sSR, sCL}
4500 +static int sctp_pkt_to_tuple(const struct sk_buff *skb,
4501 + unsigned int dataoff,
4502 + struct ip_conntrack_tuple *tuple)
4504 + sctp_sctphdr_t hdr;
4506 + DEBUGP(__FUNCTION__);
4509 + /* Actually only need first 8 bytes. */
4510 + if (skb_copy_bits(skb, dataoff, &hdr, 8) != 0)
4513 + tuple->src.u.sctp.port = hdr.source;
4514 + tuple->dst.u.sctp.port = hdr.dest;
4519 +static int sctp_invert_tuple(struct ip_conntrack_tuple *tuple,
4520 + const struct ip_conntrack_tuple *orig)
4522 + DEBUGP(__FUNCTION__);
4525 + tuple->src.u.sctp.port = orig->dst.u.sctp.port;
4526 + tuple->dst.u.sctp.port = orig->src.u.sctp.port;
4530 +/* Print out the per-protocol part of the tuple. */
4531 +static unsigned int sctp_print_tuple(char *buffer,
4532 + const struct ip_conntrack_tuple *tuple)
4534 + DEBUGP(__FUNCTION__);
4537 + return sprintf(buffer, "sport=%hu dport=%hu ",
4538 + ntohs(tuple->src.u.sctp.port),
4539 + ntohs(tuple->dst.u.sctp.port));
4542 +/* Print out the private part of the conntrack. */
4543 +static unsigned int sctp_print_conntrack(char *buffer,
4544 + const struct ip_conntrack *conntrack)
4546 + enum sctp_conntrack state;
4548 + DEBUGP(__FUNCTION__);
4551 + READ_LOCK(&sctp_lock);
4552 + state = conntrack->proto.sctp.state;
4553 + READ_UNLOCK(&sctp_lock);
4555 + return sprintf(buffer, "%s ", sctp_conntrack_names[state]);
4558 +#define for_each_sctp_chunk(skb, sch, offset, count) \
4559 +for (offset = skb->nh.iph->ihl * 4 + sizeof (sctp_sctphdr_t), count = 0; \
4560 + offset < skb->len && !skb_copy_bits(skb, offset, &sch, sizeof(sch)); \
4561 + offset += (htons(sch.length) + 3) & ~3, count++)
4563 +/* Some validity checks to make sure the chunks are fine */
4564 +static int do_basic_checks(struct ip_conntrack *conntrack,
4565 + const struct sk_buff *skb,
4568 + u_int32_t offset, count;
4569 + sctp_chunkhdr_t sch;
4572 + DEBUGP(__FUNCTION__);
4577 + for_each_sctp_chunk (skb, sch, offset, count) {
4578 + DEBUGP("Chunk Num: %d Type: %d\n", count, sch.type);
4580 + if (sch.type == SCTP_CID_INIT
4581 + || sch.type == SCTP_CID_INIT_ACK
4582 + || sch.type == SCTP_CID_SHUTDOWN_COMPLETE) {
4586 + /* Cookie Ack/Echo chunks not the first OR
4587 + Init / Init Ack / Shutdown compl chunks not the only chunks */
4588 + if ((sch.type == SCTP_CID_COOKIE_ACK
4589 + || sch.type == SCTP_CID_COOKIE_ECHO
4592 + DEBUGP("Basic checks failed\n");
4597 + set_bit (sch.type, (void *)map);
4601 + DEBUGP("Basic checks passed\n");
4605 +static int new_state(enum ip_conntrack_dir dir,
4606 + enum sctp_conntrack cur_state,
4611 + DEBUGP(__FUNCTION__);
4614 + DEBUGP("Chunk type: %d\n", chunk_type);
4616 + switch (chunk_type) {
4617 + case SCTP_CID_INIT:
4618 + DEBUGP("SCTP_CID_INIT\n");
4620 + case SCTP_CID_INIT_ACK:
4621 + DEBUGP("SCTP_CID_INIT_ACK\n");
4623 + case SCTP_CID_ABORT:
4624 + DEBUGP("SCTP_CID_ABORT\n");
4626 + case SCTP_CID_SHUTDOWN:
4627 + DEBUGP("SCTP_CID_SHUTDOWN\n");
4629 + case SCTP_CID_SHUTDOWN_ACK:
4630 + DEBUGP("SCTP_CID_SHUTDOWN_ACK\n");
4632 + case SCTP_CID_ERROR:
4633 + DEBUGP("SCTP_CID_ERROR\n");
4635 + case SCTP_CID_COOKIE_ECHO:
4636 + DEBUGP("SCTP_CID_COOKIE_ECHO\n");
4638 + case SCTP_CID_COOKIE_ACK:
4639 + DEBUGP("SCTP_CID_COOKIE_ACK\n");
4641 + case SCTP_CID_SHUTDOWN_COMPLETE:
4642 + DEBUGP("SCTP_CID_SHUTDOWN_COMPLETE\n");
4645 + /* Other chunks like DATA, SACK, HEARTBEAT and
4646 + its ACK do not cause a change in state */
4647 + DEBUGP("Unknown chunk type, Will stay in %s\n",
4648 + sctp_conntrack_names[cur_state]);
4652 + DEBUGP("dir: %d cur_state: %s chunk_type: %d new_state: %s\n",
4653 + dir, sctp_conntrack_names[cur_state], chunk_type,
4654 + sctp_conntrack_names[sctp_conntracks[dir][i][cur_state]]);
4656 + return sctp_conntracks[dir][i][cur_state];
4659 +/* Returns verdict for packet, or -1 for invalid. */
4660 +static int sctp_packet(struct ip_conntrack *conntrack,
4661 + const struct sk_buff *skb,
4662 + enum ip_conntrack_info ctinfo)
4664 + enum sctp_conntrack newconntrack, oldsctpstate;
4665 + sctp_sctphdr_t sctph;
4666 + sctp_chunkhdr_t sch;
4667 + u_int32_t offset, count;
4668 + char map[256 / sizeof (char)] = {0};
4670 + DEBUGP(__FUNCTION__);
4673 + if (skb_copy_bits(skb, skb->nh.iph->ihl * 4, &sctph, sizeof(sctph)) != 0)
4676 + if (do_basic_checks(conntrack, skb, map) != 0)
4679 + /* Check the verification tag (Sec 8.5) */
4680 + if (!test_bit(SCTP_CID_INIT, (void *)map)
4681 + && !test_bit(SCTP_CID_SHUTDOWN_COMPLETE, (void *)map)
4682 + && !test_bit(SCTP_CID_COOKIE_ECHO, (void *)map)
4683 + && !test_bit(SCTP_CID_ABORT, (void *)map)
4684 + && !test_bit(SCTP_CID_SHUTDOWN_ACK, (void *)map)
4685 + && (sctph.vtag != conntrack->proto.sctp.vtag[CTINFO2DIR(ctinfo)])) {
4686 + DEBUGP("Verification tag check failed\n");
4690 + oldsctpstate = newconntrack = SCTP_CONNTRACK_MAX;
4691 + for_each_sctp_chunk (skb, sch, offset, count) {
4692 + WRITE_LOCK(&sctp_lock);
4694 + /* Special cases of Verification tag check (Sec 8.5.1) */
4695 + if (sch.type == SCTP_CID_INIT) {
4696 + /* Sec 8.5.1 (A) */
4697 + if (sctph.vtag != 0) {
4698 + WRITE_UNLOCK(&sctp_lock);
4701 + } else if (sch.type == SCTP_CID_ABORT) {
4702 + /* Sec 8.5.1 (B) */
4703 + if (!(sctph.vtag == conntrack->proto.sctp.vtag[CTINFO2DIR(ctinfo)])
4704 + && !(sctph.vtag == conntrack->proto.sctp.vtag
4705 + [1 - CTINFO2DIR(ctinfo)])) {
4706 + WRITE_UNLOCK(&sctp_lock);
4709 + } else if (sch.type == SCTP_CID_SHUTDOWN_COMPLETE) {
4710 + /* Sec 8.5.1 (C) */
4711 + if (!(sctph.vtag == conntrack->proto.sctp.vtag[CTINFO2DIR(ctinfo)])
4712 + && !(sctph.vtag == conntrack->proto.sctp.vtag
4713 + [1 - CTINFO2DIR(ctinfo)]
4714 + && (sch.flags & 1))) {
4715 + WRITE_UNLOCK(&sctp_lock);
4718 + } else if (sch.type == SCTP_CID_COOKIE_ECHO) {
4719 + /* Sec 8.5.1 (D) */
4720 + if (!(sctph.vtag == conntrack->proto.sctp.vtag[CTINFO2DIR(ctinfo)])) {
4721 + WRITE_UNLOCK(&sctp_lock);
4726 + oldsctpstate = conntrack->proto.sctp.state;
4727 + newconntrack = new_state(CTINFO2DIR(ctinfo), oldsctpstate, sch.type);
4730 + if (newconntrack == SCTP_CONNTRACK_MAX) {
4731 + DEBUGP("ip_conntrack_sctp: Invalid dir=%i ctype=%u conntrack=%u\n",
4732 + CTINFO2DIR(ctinfo), sch.type, oldsctpstate);
4733 + WRITE_UNLOCK(&sctp_lock);
4737 + /* If it is an INIT or an INIT ACK note down the vtag */
4738 + if (sch.type == SCTP_CID_INIT
4739 + || sch.type == SCTP_CID_INIT_ACK) {
4740 + sctp_inithdr_t inithdr;
4742 + if (skb_copy_bits(skb, offset + sizeof (sctp_chunkhdr_t),
4743 + &inithdr, sizeof(inithdr)) != 0) {
4744 + WRITE_UNLOCK(&sctp_lock);
4747 + DEBUGP("Setting vtag %x for dir %d\n",
4748 + inithdr.init_tag, CTINFO2DIR(ctinfo));
4749 + conntrack->proto.sctp.vtag[IP_CT_DIR_ORIGINAL] = inithdr.init_tag;
4752 + conntrack->proto.sctp.state = newconntrack;
4753 + WRITE_UNLOCK(&sctp_lock);
4756 + ip_ct_refresh(conntrack, *sctp_timeouts[newconntrack]);
4758 + if (oldsctpstate == SCTP_CONNTRACK_COOKIE_ECHOED
4759 + && CTINFO2DIR(ctinfo) == IP_CT_DIR_REPLY
4760 + && newconntrack == SCTP_CONNTRACK_ESTABLISHED) {
4761 + DEBUGP("Setting assured bit\n");
4762 + set_bit(IPS_ASSURED_BIT, &conntrack->status);
4768 +/* Called when a new connection for this protocol found. */
4769 +static int sctp_new(struct ip_conntrack *conntrack,
4770 + const struct sk_buff *skb)
4772 + enum sctp_conntrack newconntrack;
4773 + sctp_sctphdr_t sctph;
4774 + sctp_chunkhdr_t sch;
4775 + u_int32_t offset, count;
4776 + char map[256 / sizeof (char)] = {0};
4778 + DEBUGP(__FUNCTION__);
4781 + if (skb_copy_bits(skb, skb->nh.iph->ihl * 4, &sctph, sizeof(sctph)) != 0)
4784 + if (do_basic_checks(conntrack, skb, map) != 0)
4787 + /* If an OOTB packet has any of these chunks discard (Sec 8.4) */
4788 + if ((test_bit (SCTP_CID_ABORT, (void *)map))
4789 + || (test_bit (SCTP_CID_SHUTDOWN_COMPLETE, (void *)map))
4790 + || (test_bit (SCTP_CID_COOKIE_ACK, (void *)map))) {
4794 + newconntrack = SCTP_CONNTRACK_MAX;
4795 + for_each_sctp_chunk (skb, sch, offset, count) {
4796 + /* Don't need lock here: this conntrack not in circulation yet */
4797 + newconntrack = new_state (IP_CT_DIR_ORIGINAL,
4798 + SCTP_CONNTRACK_NONE, sch.type);
4800 + /* Invalid: delete conntrack */
4801 + if (newconntrack == SCTP_CONNTRACK_MAX) {
4802 + DEBUGP("ip_conntrack_sctp: invalid new deleting.\n");
4806 + /* Copy the vtag into the state info */
4807 + if (sch.type == SCTP_CID_INIT) {
4808 + if (sctph.vtag == 0) {
4809 + sctp_inithdr_t inithdr;
4811 + if (skb_copy_bits(skb, offset + sizeof (sctp_chunkhdr_t),
4812 + &inithdr, sizeof(inithdr)) != 0) {
4816 + DEBUGP("Setting vtag %x for new conn\n",
4817 + inithdr.init_tag);
4819 + conntrack->proto.sctp.vtag[IP_CT_DIR_REPLY] =
4822 + /* Sec 8.5.1 (A) */
4826 + /* If it is a shutdown ack OOTB packet, we expect a return
4827 + shutdown complete, otherwise an ABORT Sec 8.4 (5) and (8) */
4829 + DEBUGP("Setting vtag %x for new conn OOTB\n",
4831 + conntrack->proto.sctp.vtag[IP_CT_DIR_REPLY] = sctph.vtag;
4834 + conntrack->proto.sctp.state = newconntrack;
4840 +static int sctp_exp_matches_pkt(struct ip_conntrack_expect *exp,
4841 + const struct sk_buff *skb)
4843 + /* To be implemented */
4847 +struct ip_conntrack_protocol ip_conntrack_protocol_sctp = {
4848 + .list = { NULL, NULL },
4849 + .proto = IPPROTO_SCTP,
4851 + .pkt_to_tuple = sctp_pkt_to_tuple,
4852 + .invert_tuple = sctp_invert_tuple,
4853 + .print_tuple = sctp_print_tuple,
4854 + .print_conntrack = sctp_print_conntrack,
4855 + .packet = sctp_packet,
4858 + .exp_matches_pkt = sctp_exp_matches_pkt,
4862 +int __init init(void)
4866 + ret = ip_conntrack_protocol_register(&ip_conntrack_protocol_sctp);
4867 + DEBUGP("SCTP conntrack module loading %s\n",
4868 + ret ? "failed": "succeeded");
4872 +void __exit fini(void)
4874 + ip_conntrack_protocol_unregister(&ip_conntrack_protocol_sctp);
4875 + DEBUGP("SCTP conntrack module unloaded\n");
4881 +MODULE_LICENSE("GPL");
4882 +MODULE_AUTHOR("Kiran Kumar Immidi");
4883 +MODULE_DESCRIPTION("Netfilter connection tracking protocol helper for SCTP");
4884 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ip_conntrack_quake3.c linux-2.6.6/net/ipv4/netfilter/ip_conntrack_quake3.c
4885 --- linux-2.6.6.org/net/ipv4/netfilter/ip_conntrack_quake3.c 1970-01-01 01:00:00.000000000 +0100
4886 +++ linux-2.6.6/net/ipv4/netfilter/ip_conntrack_quake3.c 2004-05-18 14:28:50.000000000 +0200
4888 +/* Quake3 extension for IP connection tracking
4889 + * (C) 2002 by Filip Sneppe <filip.sneppe@cronos.be>
4890 + * based on ip_conntrack_ftp.c and ip_conntrack_tftp.c
4892 + * ip_conntrack_quake3.c v0.04 2002-08-31
4894 + * This program is free software; you can redistribute it and/or
4895 + * modify it under the terms of the GNU General Public License
4896 + * as published by the Free Software Foundation; either version
4897 + * 2 of the License, or (at your option) any later version.
4899 + * Module load syntax:
4900 + * insmod ip_conntrack_quake3.o ports=port1,port2,...port<MAX_PORTS>
4902 + * please give the ports of all Quake3 master servers You wish to
4903 + * connect to. If you don't specify ports, the default will be UDP
4906 + * Thanks to the Ethereal folks for their analysis of the Quake3 protocol.
4909 +#include <linux/module.h>
4910 +#include <linux/ip.h>
4911 +#include <linux/udp.h>
4913 +#include <linux/netfilter.h>
4914 +#include <linux/netfilter_ipv4/ip_tables.h>
4915 +#include <linux/netfilter_ipv4/ip_conntrack_helper.h>
4916 +#include <linux/netfilter_ipv4/ip_conntrack_quake3.h>
4918 +struct module *ip_conntrack_quake3 = THIS_MODULE;
4920 +MODULE_AUTHOR("Filip Sneppe <filip.sneppe@cronos.be>");
4921 +MODULE_DESCRIPTION("Netfilter connection tracking module for Quake III Arena");
4922 +MODULE_LICENSE("GPL");
4924 +#define MAX_PORTS 8
4925 +static int ports[MAX_PORTS];
4926 +static int ports_c = 0;
4928 +MODULE_PARM(ports, "1-" __MODULE_STRING(MAX_PORTS) "i");
4929 +MODULE_PARM_DESC(ports, "port numbers of Quake III master servers");
4932 +/* Quake3 master server reply will add > 100 expectations per reply packet; when
4933 + doing lots of printk's, klogd may not be able to read /proc/kmsg fast enough */
4935 +#define DEBUGP printk
4937 +#define DEBUGP(format, args...)
4940 +struct quake3_search quake3s_conntrack = { "****", "getserversResponse", sizeof("getserversResponse") - 1 };
4942 +static int quake3_help(const struct iphdr *iph, size_t len,
4943 + struct ip_conntrack *ct,
4944 + enum ip_conntrack_info ctinfo)
4946 + struct udphdr *udph = (void *)iph + iph->ihl * 4;
4947 + int dir = CTINFO2DIR(ctinfo);
4948 + struct ip_conntrack_expect exp;
4951 + /* Until there's been traffic both ways, don't look in packets. note: it's UDP ! */
4952 + if (ctinfo != IP_CT_ESTABLISHED
4953 + && ctinfo != IP_CT_IS_REPLY) {
4954 + DEBUGP("ip_conntrack_quake3: not ok ! Conntrackinfo = %u\n", ctinfo);
4956 + } else { DEBUGP("ip_conntrack_quake3: it's ok ! Conntrackinfo = %u\n", ctinfo); }
4958 + if (strnicmp((const char *)udph + 12, quake3s_conntrack.pattern, quake3s_conntrack.plen) == 0) {
4959 + for(i=31; /* 8 bytes UDP hdr, 4 bytes filler, 18 bytes "getserversResponse", 1 byte "\" */
4960 + i+6 < ntohs(udph->len);
4962 + DEBUGP("ip_conntrack_quake3: adding server at offset %u/%u %u.%u.%u.%u:%u\n",
4963 + i, ntohs(udph->len),
4964 + NIPQUAD( (u_int32_t) *( (u_int32_t *)( (int)udph + i ) ) ),
4965 + ntohs((__u16) *( (__u16 *)( (int)udph + i + 4 ) ) ) );
4967 + memset(&exp, 0, sizeof(exp));
4969 + exp.tuple = ((struct ip_conntrack_tuple)
4970 + { { ct->tuplehash[!dir].tuple.src.ip, { 0 } },
4971 + { (u_int32_t) *((u_int32_t *)((int)udph + i)),
4972 + { .udp = { (__u16) *((__u16 *)((int)udph+i+4)) } },
4975 + exp.mask = ((struct ip_conntrack_tuple)
4976 + { { 0xFFFFFFFF, { 0 } },
4977 + { 0xFFFFFFFF, { .udp = { 0xFFFF } }, 0xFFFF }});
4978 + exp.expectfn = NULL;
4980 + ip_conntrack_expect_related(ct, &exp);
4985 + return(NF_ACCEPT);
4988 +static struct ip_conntrack_helper quake3[MAX_PORTS];
4989 +static char quake3_names[MAX_PORTS][13]; /* quake3-65535 */
4991 +static void fini(void)
4995 + for(i = 0 ; (i < ports_c); i++) {
4996 + DEBUGP("ip_conntrack_quake3: unregistering helper for port %d\n",
4998 + ip_conntrack_helper_unregister(&quake3[i]);
5002 +static int __init init(void)
5008 + ports[0]=QUAKE3_MASTER_PORT;
5010 + for(i = 0 ; (i < MAX_PORTS) && ports[i] ; i++) {
5011 + /* Create helper structure */
5012 + memset(&quake3[i], 0, sizeof(struct ip_conntrack_helper));
5014 + quake3[i].tuple.dst.protonum = IPPROTO_UDP;
5015 + quake3[i].tuple.src.u.udp.port = htons(ports[i]);
5016 + quake3[i].mask.dst.protonum = 0xFFFF;
5017 + quake3[i].mask.src.u.udp.port = 0xFFFF;
5018 + quake3[i].help = quake3_help;
5019 + quake3[i].me = THIS_MODULE;
5021 + tmpname = &quake3_names[i][0];
5022 + if (ports[i] == QUAKE3_MASTER_PORT)
5023 + sprintf(tmpname, "quake3");
5025 + sprintf(tmpname, "quake3-%d", i);
5026 + quake3[i].name = tmpname;
5028 + DEBUGP("ip_conntrack_quake3: registering helper for port %d\n",
5031 + ret=ip_conntrack_helper_register(&quake3[i]);
5044 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ip_conntrack_rsh.c linux-2.6.6/net/ipv4/netfilter/ip_conntrack_rsh.c
5045 --- linux-2.6.6.org/net/ipv4/netfilter/ip_conntrack_rsh.c 1970-01-01 01:00:00.000000000 +0100
5046 +++ linux-2.6.6/net/ipv4/netfilter/ip_conntrack_rsh.c 2004-05-18 14:28:50.000000000 +0200
5048 +/* RSH extension for IP connection tracking, Version 1.0
5049 + * (C) 2002 by Ian (Larry) Latter <Ian.Latter@mq.edu.au>
5050 + * based on HW's ip_conntrack_irc.c
5052 + * ip_conntrack_rsh.c,v 1.0 2002/07/17 14:49:26
5054 + * This program is free software; you can redistribute it and/or
5055 + * modify it under the terms of the GNU General Public License
5056 + * as published by the Free Software Foundation; either version
5057 + * 2 of the License, or (at your option) any later version.
5059 + * Module load syntax:
5060 + * insmod ip_conntrack_rsh.o ports=port1,port2,...port<MAX_PORTS>
5062 + * please give the ports of all RSH servers You wish to connect to.
5063 + * If You don't specify ports, the default will be port 514
5066 + * RSH blows ... you should use SSH (openssh.org) to replace it,
5067 + * unfortunately I babysit some sysadmins that won't migrate
5068 + * their legacy crap, in our second tier.
5073 + * Some docco ripped from the net to teach me all there is to know about
5074 + * RSH, in 16.5 seconds (ie, all of the non-netfilter docco used to write
5077 + * I have no idea what "unix rshd man pages" these guys have .. but that
5078 + * is some pretty detailed docco!
5081 + * 4. Of the rsh protocol.
5082 + * -----------------------
5084 + * The rshd listens on TCP port #514. The following info is from the unix
5085 + * rshd man pages :
5087 + * "Service Request Protocol
5089 + * When the rshd daemon receives a service request, it initiates the
5090 + * following protocol:
5092 + * 1. The rshd daemon checks the source port number for the request.
5093 + * If the port number is not in the range 0 through 1023, the rshd daemon
5094 + * terminates the connection.
5096 + * 2. The rshd daemon reads characters from the socket up to a null byte.
5097 + * The string read is interpreted as an ASCII number (base 10). If this
5098 + * number is nonzero, the rshd daemon interprets it as the port number
5099 + * of a secondary stream to be used as standard error. A second connection
5100 + * is created to the specified port on the client host. The source port
5101 + * on the local host is in the range 0 through 1023.
5103 + * 3. The rshd daemon uses the source address of the initial connection
5104 + * request to determine the name of the client host. If the name cannot
5105 + * be determined, the rshd daemon uses the dotted decimal representation
5106 + * of the client host's address.
5108 + * 4. The rshd daemon retrieves the following information from the initial
5111 + * * A null-terminated string of at most 16 bytes interpreted as
5112 + * the user name of the user on the client host.
5114 + * * A null-terminated string of at most 16 bytes interpreted as
5115 + * the user name to be used on the local server host.
5117 + * * Another null-terminated string interpreted as a command line
5118 + * to be passed to a shell on the local server host.
5120 + * 5. The rshd daemon attempts to validate the user using the following steps:
5122 + * a. The rshd daemon looks up the local user name in the /etc/passwd
5123 + * file and tries to switch to the home directory (using the chdir
5124 + * subroutine). If either the lookup or the directory change fails,
5125 + * the rshd daemon terminates the connection.
5127 + * b. If the local user ID is a nonzero value, the rshd daemon searches
5128 + * the /etc/hosts.equiv file to see if the name of the client
5129 + * workstation is listed. If the client workstation is listed as an
5130 + * equivalent host, the rshd daemon validates the user.
5132 + * c. If the $HOME/.rhosts file exists, the rshd daemon tries to
5133 + * authenticate the user by checking the .rhosts file.
5135 + * d. If either the $HOME/.rhosts authentication fails or the
5136 + * client host is not an equivalent host, the rshd daemon
5137 + * terminates the connection.
5139 + * 6. Once rshd validates the user, the rshd daemon returns a null byte
5140 + * on the initial connection and passes the command line to the user's
5141 + * local login shell. The shell then inherits the network connections
5142 + * established by the rshd daemon."
5147 +#include <linux/module.h>
5148 +#include <linux/netfilter.h>
5149 +#include <linux/ip.h>
5150 +#include <net/checksum.h>
5151 +#include <net/tcp.h>
5153 +#include <linux/netfilter_ipv4/lockhelp.h>
5154 +#include <linux/netfilter_ipv4/ip_tables.h>
5155 +#include <linux/netfilter_ipv4/ip_conntrack_helper.h>
5156 +#include <linux/netfilter_ipv4/ip_conntrack_rsh.h>
5158 +#define MAX_PORTS 8
5159 +static int ports[MAX_PORTS];
5160 +static int ports_n_c = 0;
5162 +MODULE_AUTHOR("Ian (Larry) Latter <Ian.Latter@mq.edu.au>");
5163 +MODULE_DESCRIPTION("RSH connection tracking module");
5164 +MODULE_LICENSE("GPL");
5166 +MODULE_PARM(ports, "1-" __MODULE_STRING(MAX_PORTS) "i");
5167 +MODULE_PARM_DESC(ports, "port numbers of RSH servers");
5170 +DECLARE_LOCK(ip_rsh_lock);
5171 +struct module *ip_conntrack_rsh = THIS_MODULE;
5174 +#define DEBUGP(format, args...) printk(KERN_DEBUG "ip_conntrack_rsh: " \
5177 +#define DEBUGP(format, args...)
5182 +/* FIXME: This should be in userspace. Later. */
5183 +static int help(const struct iphdr *iph, size_t len,
5184 + struct ip_conntrack *ct, enum ip_conntrack_info ctinfo)
5186 + /* tcplen not negative guarenteed by ip_conntrack_tcp.c */
5187 + struct tcphdr *tcph = (void *) iph + iph->ihl * 4;
5188 + const char *data = (const char *) tcph + tcph->doff * 4;
5189 + u_int32_t tcplen = len - iph->ihl * 4;
5190 + int dir = CTINFO2DIR(ctinfo);
5191 + struct ip_conntrack_expect expect, *exp = &expect;
5192 + struct ip_ct_rsh_expect *exp_rsh_info = &exp->help.exp_rsh_info;
5196 + /* note that "maxoctet" is used to maintain sanity (8 was the
5197 + * original array size used in rshd/glibc) -- is there a
5198 + * vulnerability in rshd.c in the looped port *= 10?
5202 + DEBUGP("entered\n");
5204 + /* bail if packet is not from RSH client */
5205 + if (dir == IP_CT_DIR_REPLY)
5208 + /* Until there's been traffic both ways, don't look in packets. */
5209 + if (ctinfo != IP_CT_ESTABLISHED
5210 + && ctinfo != IP_CT_ESTABLISHED + IP_CT_IS_REPLY) {
5211 + DEBUGP("Conntrackinfo = %u\n", ctinfo);
5215 + /* Not whole TCP header? */
5216 + if (tcplen < sizeof(struct tcphdr) || tcplen < tcph->doff * 4) {
5217 + DEBUGP("tcplen = %u\n", (unsigned) tcplen);
5221 + /* Checksum invalid? Ignore. */
5222 + /* FIXME: Source route IP option packets --RR */
5223 + if (tcp_v4_check(tcph, tcplen, iph->saddr, iph->daddr,
5224 + csum_partial((char *) tcph, tcplen, 0))) {
5225 + DEBUGP("bad csum: %p %u %u.%u.%u.%u %u.%u.%u.%u\n",
5226 + tcph, tcplen, NIPQUAD(iph->saddr),
5227 + NIPQUAD(iph->daddr));
5231 + /* find the rsh stderr port */
5234 + for ( ; *data != 0 && maxoctet != 0; data++, maxoctet--) {
5239 + if (*data < 48 || *data > 57) {
5240 + DEBUGP("these aren't the packets you're looking for ..\n");
5243 + port = port * 10 + ( *data - 48 );
5246 + /* dont relate sessions that try to expose the client */
5247 + DEBUGP("found port %u\n", port);
5248 + if (port > 1023) {
5249 + DEBUGP("skipping, expected port size is greater than 1023!\n");
5254 + LOCK_BH(&ip_rsh_lock);
5256 + /* new(,related) connection is;
5257 + * reply + dst (uint)port + src port (0:1023)
5259 + memset(&expect, 0, sizeof(expect));
5261 + /* save some discovered data, in case someone ever wants to write
5262 + * a NAT module for this bastard ..
5264 + exp_rsh_info->port = port;
5266 + DEBUGP("wrote info port=%u\n", exp_rsh_info->port);
5269 + /* Watch out, Radioactive-Man! */
5270 + exp->tuple.src.ip = ct->tuplehash[!dir].tuple.src.ip;
5271 + exp->tuple.dst.ip = ct->tuplehash[!dir].tuple.dst.ip;
5272 + exp->tuple.src.u.tcp.port = 0;
5273 + exp->tuple.dst.u.tcp.port = htons(exp_rsh_info->port);
5274 + exp->tuple.dst.protonum = IPPROTO_TCP;
5276 + exp->mask.src.ip = 0xffffffff;
5277 + exp->mask.dst.ip = 0xffffffff;
5279 + exp->mask.src.u.tcp.port = htons(0xfc00);
5280 + exp->mask.dst.u.tcp.port = htons(0xfc00);
5281 + exp->mask.dst.protonum = 0xffff;
5283 + exp->expectfn = NULL;
5285 + ip_conntrack_expect_related(ct, &expect);
5287 + DEBUGP("expect related ip %u.%u.%u.%u:%u-%u.%u.%u.%u:%u\n",
5288 + NIPQUAD(exp->tuple.src.ip),
5289 + ntohs(exp->tuple.src.u.tcp.port),
5290 + NIPQUAD(exp->tuple.dst.ip),
5291 + ntohs(exp->tuple.dst.u.tcp.port));
5293 + DEBUGP("expect related mask %u.%u.%u.%u:%u-%u.%u.%u.%u:%u\n",
5294 + NIPQUAD(exp->mask.src.ip),
5295 + ntohs(exp->mask.src.u.tcp.port),
5296 + NIPQUAD(exp->mask.dst.ip),
5297 + ntohs(exp->mask.dst.u.tcp.port));
5298 + UNLOCK_BH(&ip_rsh_lock);
5303 +static struct ip_conntrack_helper rsh_helpers[MAX_PORTS];
5305 +static void fini(void);
5307 +static int __init init(void)
5310 + static char name[10];
5313 + /* If no port given, default to standard RSH port */
5314 + if (ports[0] == 0)
5315 + ports[0] = RSH_PORT;
5317 + for (port = 0; (port < MAX_PORTS) && ports[port]; port++) {
5318 + memset(&rsh_helpers[port], 0, sizeof(struct ip_conntrack_helper));
5320 + if (ports[port] == RSH_PORT)
5321 + sprintf(name, "rsh");
5323 + sprintf(name, "rsh-%d", port);
5325 + rsh_helpers[port].name = name;
5326 + rsh_helpers[port].me = THIS_MODULE;
5327 + rsh_helpers[port].max_expected = 1;
5328 + rsh_helpers[port].flags = IP_CT_HELPER_F_REUSE_EXPECT;
5329 + rsh_helpers[port].timeout = 0;
5331 + rsh_helpers[port].tuple.dst.protonum = IPPROTO_TCP;
5332 + rsh_helpers[port].mask.dst.protonum = 0xffff;
5334 + /* RSH must come from ports 0:1023 to ports[port] (514) */
5335 + rsh_helpers[port].tuple.src.u.tcp.port = htons(ports[port]);
5336 + rsh_helpers[port].mask.src.u.tcp.port = htons(0xfc00);
5337 + rsh_helpers[port].mask.dst.u.tcp.port = htons(0xfc00);
5339 + rsh_helpers[port].help = help;
5341 + DEBUGP("registering helper for port #%d: %d/TCP\n", port, ports[port]);
5342 + DEBUGP("helper match ip %u.%u.%u.%u:%u-%u.%u.%u.%u:%u\n",
5343 + NIPQUAD(rsh_helpers[port].tuple.src.ip),
5344 + ntohs(rsh_helpers[port].tuple.src.u.tcp.port),
5345 + NIPQUAD(rsh_helpers[port].tuple.dst.ip),
5346 + ntohs(rsh_helpers[port].tuple.dst.u.tcp.port));
5347 + DEBUGP("helper match mask %u.%u.%u.%u:%u-%u.%u.%u.%u:%u\n",
5348 + NIPQUAD(rsh_helpers[port].mask.src.ip),
5349 + ntohs(rsh_helpers[port].mask.src.u.tcp.port),
5350 + NIPQUAD(rsh_helpers[port].mask.dst.ip),
5351 + ntohs(rsh_helpers[port].mask.dst.u.tcp.port));
5353 + ret = ip_conntrack_helper_register(&rsh_helpers[port]);
5356 + printk("ERROR registering port %d\n",
5366 +/* This function is intentionally _NOT_ defined as __exit, because
5367 + * it is needed by the init function */
5368 +static void fini(void)
5371 + for (port = 0; (port < MAX_PORTS) && ports[port]; port++) {
5372 + DEBUGP("unregistering port %d\n", ports[port]);
5373 + ip_conntrack_helper_unregister(&rsh_helpers[port]);
5379 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ip_conntrack_rtsp.c linux-2.6.6/net/ipv4/netfilter/ip_conntrack_rtsp.c
5380 --- linux-2.6.6.org/net/ipv4/netfilter/ip_conntrack_rtsp.c 1970-01-01 01:00:00.000000000 +0100
5381 +++ linux-2.6.6/net/ipv4/netfilter/ip_conntrack_rtsp.c 2004-05-18 14:28:50.000000000 +0200
5384 + * RTSP extension for IP connection tracking
5385 + * (C) 2003 by Tom Marshall <tmarshall@real.com>
5386 + * based on ip_conntrack_irc.c
5388 + * This program is free software; you can redistribute it and/or
5389 + * modify it under the terms of the GNU General Public License
5390 + * as published by the Free Software Foundation; either version
5391 + * 2 of the License, or (at your option) any later version.
5393 + * Module load syntax:
5394 + * insmod ip_conntrack_rtsp.o ports=port1,port2,...port<MAX_PORTS>
5395 + * max_outstanding=n setup_timeout=secs
5397 + * If no ports are specified, the default will be port 554.
5399 + * With max_outstanding you can define the maximum number of not yet
5400 + * answered SETUP requests per RTSP session (default 8).
5401 + * With setup_timeout you can specify how long the system waits for
5402 + * an expected data channel (default 300 seconds).
5405 +#include <linux/config.h>
5406 +#include <linux/module.h>
5407 +#include <linux/netfilter.h>
5408 +#include <linux/ip.h>
5409 +#include <net/checksum.h>
5410 +#include <net/tcp.h>
5412 +#include <linux/netfilter_ipv4/lockhelp.h>
5413 +#include <linux/netfilter_ipv4/ip_conntrack_helper.h>
5414 +#include <linux/netfilter_ipv4/ip_conntrack_rtsp.h>
5416 +#include <linux/ctype.h>
5417 +#define NF_NEED_STRNCASECMP
5418 +#define NF_NEED_STRTOU16
5419 +#define NF_NEED_STRTOU32
5420 +#define NF_NEED_NEXTLINE
5421 +#include <linux/netfilter_helpers.h>
5422 +#define NF_NEED_MIME_NEXTLINE
5423 +#include <linux/netfilter_mime.h>
5425 +#define MAX_SIMUL_SETUP 8 /* XXX: use max_outstanding */
5427 +#define INFOP(fmt, args...) printk(KERN_INFO "%s: %s: " fmt, __FILE__, __FUNCTION__ , ## args)
5428 +#ifdef IP_NF_RTSP_DEBUG
5429 +#define DEBUGP(fmt, args...) printk(KERN_DEBUG "%s: %s: " fmt, __FILE__, __FUNCTION__ , ## args)
5431 +#define DEBUGP(fmt, args...)
5434 +#define MAX_PORTS 8
5435 +static int ports[MAX_PORTS];
5436 +static int num_ports = 0;
5437 +static int max_outstanding = 8;
5438 +static unsigned int setup_timeout = 300;
5440 +MODULE_AUTHOR("Tom Marshall <tmarshall@real.com>");
5441 +MODULE_DESCRIPTION("RTSP connection tracking module");
5442 +MODULE_LICENSE("GPL");
5444 +MODULE_PARM(ports, "1-" __MODULE_STRING(MAX_PORTS) "i");
5445 +MODULE_PARM_DESC(ports, "port numbers of RTSP servers");
5446 +MODULE_PARM(max_outstanding, "i");
5447 +MODULE_PARM_DESC(max_outstanding, "max number of outstanding SETUP requests per RTSP session");
5448 +MODULE_PARM(setup_timeout, "i");
5449 +MODULE_PARM_DESC(setup_timeout, "timeout on for unestablished data channels");
5452 +DECLARE_LOCK(ip_rtsp_lock);
5453 +struct module* ip_conntrack_rtsp = THIS_MODULE;
5456 + * Max mappings we will allow for one RTSP connection (for RTP, the number
5457 + * of allocated ports is twice this value). Note that SMIL burns a lot of
5458 + * ports so keep this reasonably high. If this is too low, you will see a
5459 + * lot of "no free client map entries" messages.
5461 +#define MAX_PORT_MAPS 16
5463 +/*** default port list was here in the masq code: 554, 3030, 4040 ***/
5465 +#define SKIP_WSPACE(ptr,len,off) while(off < len && isspace(*(ptr+off))) { off++; }
5468 + * Parse an RTSP packet.
5470 + * Returns zero if parsing failed.
5473 + * IN ptcp tcp data pointer
5474 + * IN tcplen tcp data len
5475 + * IN/OUT ptcpoff points to current tcp offset
5476 + * OUT phdrsoff set to offset of rtsp headers
5477 + * OUT phdrslen set to length of rtsp headers
5478 + * OUT pcseqoff set to offset of CSeq header
5479 + * OUT pcseqlen set to length of CSeq header
5482 +rtsp_parse_message(char* ptcp, uint tcplen, uint* ptcpoff,
5483 + uint* phdrsoff, uint* phdrslen,
5484 + uint* pcseqoff, uint* pcseqlen)
5486 + uint entitylen = 0;
5490 + if (!nf_nextline(ptcp, tcplen, ptcpoff, &lineoff, &linelen))
5495 + *phdrsoff = *ptcpoff;
5496 + while (nf_mime_nextline(ptcp, tcplen, ptcpoff, &lineoff, &linelen))
5500 + if (entitylen > 0)
5502 + *ptcpoff += min(entitylen, tcplen - *ptcpoff);
5506 + if (lineoff+linelen > tcplen)
5508 + INFOP("!! overrun !!\n");
5512 + if (nf_strncasecmp(ptcp+lineoff, "CSeq:", 5) == 0)
5514 + *pcseqoff = lineoff;
5515 + *pcseqlen = linelen;
5517 + if (nf_strncasecmp(ptcp+lineoff, "Content-Length:", 15) == 0)
5519 + uint off = lineoff+15;
5520 + SKIP_WSPACE(ptcp+lineoff, linelen, off);
5521 + nf_strtou32(ptcp+off, &entitylen);
5524 + *phdrslen = (*ptcpoff) - (*phdrsoff);
5530 + * Find lo/hi client ports (if any) in transport header
5532 + * ptcp, tcplen = packet
5533 + * tranoff, tranlen = buffer to search
5536 + * pport_lo, pport_hi = lo/hi ports (host endian)
5538 + * Returns nonzero if any client ports found
5540 + * Note: it is valid (and expected) for the client to request multiple
5541 + * transports, so we need to parse the entire line.
5544 +rtsp_parse_transport(char* ptran, uint tranlen,
5545 + struct ip_ct_rtsp_expect* prtspexp)
5550 + if (tranlen < 10 || !iseol(ptran[tranlen-1]) ||
5551 + nf_strncasecmp(ptran, "Transport:", 10) != 0)
5553 + INFOP("sanity check failed\n");
5556 + DEBUGP("tran='%.*s'\n", (int)tranlen, ptran);
5558 + SKIP_WSPACE(ptran, tranlen, off);
5560 + /* Transport: tran;field;field=val,tran;field;field=val,... */
5561 + while (off < tranlen)
5563 + const char* pparamend;
5564 + uint nextparamoff;
5566 + pparamend = memchr(ptran+off, ',', tranlen-off);
5567 + pparamend = (pparamend == NULL) ? ptran+tranlen : pparamend+1;
5568 + nextparamoff = pparamend-ptran;
5570 + while (off < nextparamoff)
5572 + const char* pfieldend;
5573 + uint nextfieldoff;
5575 + pfieldend = memchr(ptran+off, ';', nextparamoff-off);
5576 + nextfieldoff = (pfieldend == NULL) ? nextparamoff : pfieldend-ptran+1;
5578 + if (strncmp(ptran+off, "client_port=", 12) == 0)
5584 + numlen = nf_strtou16(ptran+off, &port);
5586 + if (prtspexp->loport != 0 && prtspexp->loport != port)
5588 + DEBUGP("multiple ports found, port %hu ignored\n", port);
5592 + prtspexp->loport = prtspexp->hiport = port;
5593 + if (ptran[off] == '-')
5596 + numlen = nf_strtou16(ptran+off, &port);
5598 + prtspexp->pbtype = pb_range;
5599 + prtspexp->hiport = port;
5601 + // If we have a range, assume rtp:
5602 + // loport must be even, hiport must be loport+1
5603 + if ((prtspexp->loport & 0x0001) != 0 ||
5604 + prtspexp->hiport != prtspexp->loport+1)
5606 + DEBUGP("incorrect range: %hu-%hu, correcting\n",
5607 + prtspexp->loport, prtspexp->hiport);
5608 + prtspexp->loport &= 0xfffe;
5609 + prtspexp->hiport = prtspexp->loport+1;
5612 + else if (ptran[off] == '/')
5615 + numlen = nf_strtou16(ptran+off, &port);
5617 + prtspexp->pbtype = pb_discon;
5618 + prtspexp->hiport = port;
5625 + * Note we don't look for the destination parameter here.
5626 + * If we are using NAT, the NAT module will handle it. If not,
5627 + * and the client is sending packets elsewhere, the expectation
5628 + * will quietly time out.
5631 + off = nextfieldoff;
5634 + off = nextparamoff;
5640 +/*** conntrack functions ***/
5642 +/* outbound packet: client->server */
5644 +help_out(const struct iphdr* iph, size_t pktlen,
5645 + struct ip_conntrack* ct, enum ip_conntrack_info ctinfo)
5647 + int dir = CTINFO2DIR(ctinfo); /* = IP_CT_DIR_ORIGINAL */
5648 + struct tcphdr* tcph = (void*)iph + iph->ihl * 4;
5649 + uint tcplen = pktlen - iph->ihl * 4;
5650 + char* pdata = (char*)tcph + tcph->doff * 4;
5651 + uint datalen = tcplen - tcph->doff * 4;
5654 + struct ip_conntrack_expect exp;
5656 + while (dataoff < datalen)
5658 + uint cmdoff = dataoff;
5668 + if (!rtsp_parse_message(pdata, datalen, &dataoff,
5669 + &hdrsoff, &hdrslen,
5670 + &cseqoff, &cseqlen))
5672 + break; /* not a valid message */
5675 + if (strncmp(pdata+cmdoff, "SETUP ", 6) != 0)
5677 + continue; /* not a SETUP message */
5679 + DEBUGP("found a setup message\n");
5681 + memset(&exp, 0, sizeof(exp));
5684 + while (nf_mime_nextline(pdata+hdrsoff, hdrslen, &off,
5685 + &lineoff, &linelen))
5691 + if (off > hdrsoff+hdrslen)
5693 + INFOP("!! overrun !!");
5697 + if (nf_strncasecmp(pdata+hdrsoff+lineoff, "Transport:", 10) == 0)
5699 + rtsp_parse_transport(pdata+hdrsoff+lineoff, linelen,
5700 + &exp.help.exp_rtsp_info);
5704 + if (exp.help.exp_rtsp_info.loport == 0)
5706 + DEBUGP("no udp transports found\n");
5707 + continue; /* no udp transports found */
5710 + DEBUGP("udp transport found, ports=(%d,%hu,%hu)\n",
5711 + (int)exp.help.exp_rtsp_info.pbtype,
5712 + exp.help.exp_rtsp_info.loport,
5713 + exp.help.exp_rtsp_info.hiport);
5715 + LOCK_BH(&ip_rtsp_lock);
5716 + exp.seq = ntohl(tcph->seq) + hdrsoff; /* mark all the headers */
5717 + exp.help.exp_rtsp_info.len = hdrslen;
5719 + exp.tuple.src.ip = ct->tuplehash[!dir].tuple.src.ip;
5720 + exp.mask.src.ip = 0xffffffff;
5721 + exp.tuple.dst.ip = ct->tuplehash[dir].tuple.src.ip;
5722 + exp.mask.dst.ip = 0xffffffff;
5723 + exp.tuple.dst.u.udp.port = exp.help.exp_rtsp_info.loport;
5724 + exp.mask.dst.u.udp.port = (exp.help.exp_rtsp_info.pbtype == pb_range) ? 0xfffe : 0xffff;
5725 + exp.tuple.dst.protonum = IPPROTO_UDP;
5726 + exp.mask.dst.protonum = 0xffff;
5728 + DEBUGP("expect_related %u.%u.%u.%u:%u-%u.%u.%u.%u:%u\n",
5729 + NIPQUAD(exp.tuple.src.ip),
5730 + ntohs(exp.tuple.src.u.tcp.port),
5731 + NIPQUAD(exp.tuple.dst.ip),
5732 + ntohs(exp.tuple.dst.u.tcp.port));
5734 + /* pass the request off to the nat helper */
5735 + rc = ip_conntrack_expect_related(ct, &exp);
5736 + UNLOCK_BH(&ip_rtsp_lock);
5739 + DEBUGP("ip_conntrack_expect_related succeeded\n");
5743 + INFOP("ip_conntrack_expect_related failed (%d)\n", rc);
5750 +/* inbound packet: server->client */
5752 +help_in(const struct iphdr* iph, size_t pktlen,
5753 + struct ip_conntrack* ct, enum ip_conntrack_info ctinfo)
5759 +help(const struct iphdr* iph, size_t pktlen,
5760 + struct ip_conntrack* ct, enum ip_conntrack_info ctinfo)
5762 + /* tcplen not negative guarenteed by ip_conntrack_tcp.c */
5763 + struct tcphdr* tcph = (void*)iph + iph->ihl * 4;
5764 + u_int32_t tcplen = pktlen - iph->ihl * 4;
5766 + /* Until there's been traffic both ways, don't look in packets. */
5767 + if (ctinfo != IP_CT_ESTABLISHED && ctinfo != IP_CT_ESTABLISHED + IP_CT_IS_REPLY)
5769 + DEBUGP("conntrackinfo = %u\n", ctinfo);
5773 + /* Not whole TCP header? */
5774 + if (tcplen < sizeof(struct tcphdr) || tcplen < tcph->doff * 4)
5776 + DEBUGP("tcplen = %u\n", (unsigned)tcplen);
5780 + /* Checksum invalid? Ignore. */
5781 + /* FIXME: Source route IP option packets --RR */
5782 + if (tcp_v4_check(tcph, tcplen, iph->saddr, iph->daddr,
5783 + csum_partial((char*)tcph, tcplen, 0)))
5785 + DEBUGP("bad csum: %p %u %u.%u.%u.%u %u.%u.%u.%u\n",
5786 + tcph, tcplen, NIPQUAD(iph->saddr), NIPQUAD(iph->daddr));
5790 + switch (CTINFO2DIR(ctinfo))
5792 + case IP_CT_DIR_ORIGINAL:
5793 + help_out(iph, pktlen, ct, ctinfo);
5795 + case IP_CT_DIR_REPLY:
5796 + help_in(iph, pktlen, ct, ctinfo);
5803 +static struct ip_conntrack_helper rtsp_helpers[MAX_PORTS];
5804 +static char rtsp_names[MAX_PORTS][10];
5806 +/* This function is intentionally _NOT_ defined as __exit */
5811 + for (i = 0; i < num_ports; i++)
5813 + DEBUGP("unregistering port %d\n", ports[i]);
5814 + ip_conntrack_helper_unregister(&rtsp_helpers[i]);
5822 + struct ip_conntrack_helper *hlpr;
5825 + printk("ip_conntrack_rtsp v" IP_NF_RTSP_VERSION " loading\n");
5827 + if (max_outstanding < 1)
5829 + printk("ip_conntrack_rtsp: max_outstanding must be a positive integer\n");
5832 + if (setup_timeout < 0)
5834 + printk("ip_conntrack_rtsp: setup_timeout must be a positive integer\n");
5838 + /* If no port given, default to standard rtsp port */
5839 + if (ports[0] == 0)
5841 + ports[0] = RTSP_PORT;
5844 + for (i = 0; (i < MAX_PORTS) && ports[i]; i++)
5846 + hlpr = &rtsp_helpers[i];
5847 + memset(hlpr, 0, sizeof(struct ip_conntrack_helper));
5848 + hlpr->tuple.src.u.tcp.port = htons(ports[i]);
5849 + hlpr->tuple.dst.protonum = IPPROTO_TCP;
5850 + hlpr->mask.src.u.tcp.port = 0xFFFF;
5851 + hlpr->mask.dst.protonum = 0xFFFF;
5852 + hlpr->max_expected = max_outstanding;
5853 + hlpr->timeout = setup_timeout;
5854 + hlpr->flags = IP_CT_HELPER_F_REUSE_EXPECT;
5855 + hlpr->me = ip_conntrack_rtsp;
5856 + hlpr->help = help;
5858 + tmpname = &rtsp_names[i][0];
5859 + if (ports[i] == RTSP_PORT)
5861 + sprintf(tmpname, "rtsp");
5865 + sprintf(tmpname, "rtsp-%d", i);
5867 + hlpr->name = tmpname;
5869 + DEBUGP("port #%d: %d\n", i, ports[i]);
5871 + ret = ip_conntrack_helper_register(hlpr);
5875 + printk("ip_conntrack_rtsp: ERROR registering port %d\n", ports[i]);
5884 +#ifdef CONFIG_IP_NF_NAT_NEEDED
5885 +EXPORT_SYMBOL(ip_rtsp_lock);
5890 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ip_conntrack_standalone.c linux-2.6.6/net/ipv4/netfilter/ip_conntrack_standalone.c
5891 --- linux-2.6.6.org/net/ipv4/netfilter/ip_conntrack_standalone.c 2004-05-10 04:32:29.000000000 +0200
5892 +++ linux-2.6.6/net/ipv4/netfilter/ip_conntrack_standalone.c 2004-05-18 14:28:50.000000000 +0200
5894 len += sprintf(buffer + len, "[ASSURED] ");
5895 len += sprintf(buffer + len, "use=%u ",
5896 atomic_read(&conntrack->ct_general.use));
5897 +#if defined(CONFIG_IP_NF_CONNTRACK_MARK)
5898 + len += sprintf(buffer + len, "mark=%ld ", conntrack->mark);
5900 len += sprintf(buffer + len, "\n");
5904 EXPORT_SYMBOL(ip_conntrack_alter_reply);
5905 EXPORT_SYMBOL(ip_conntrack_destroyed);
5906 EXPORT_SYMBOL(ip_conntrack_get);
5907 +EXPORT_SYMBOL(__ip_conntrack_confirm);
5908 EXPORT_SYMBOL(need_ip_conntrack);
5909 EXPORT_SYMBOL(ip_conntrack_helper_register);
5910 EXPORT_SYMBOL(ip_conntrack_helper_unregister);
5911 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ip_conntrack_talk.c linux-2.6.6/net/ipv4/netfilter/ip_conntrack_talk.c
5912 --- linux-2.6.6.org/net/ipv4/netfilter/ip_conntrack_talk.c 1970-01-01 01:00:00.000000000 +0100
5913 +++ linux-2.6.6/net/ipv4/netfilter/ip_conntrack_talk.c 2004-05-18 14:28:50.000000000 +0200
5916 + * talk extension for IP connection tracking.
5917 + * Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
5919 + * This program is free software; you can redistribute it and/or
5920 + * modify it under the terms of the GNU General Public License
5921 + * as published by the Free Software Foundation; either version
5922 + * 2 of the License, or (at your option) any later version.
5924 + * Module load syntax:
5925 + * insmod ip_nat_talk.o talk=[0|1] ntalk=[0|1] ntalk2=[01]
5927 + * talk=[0|1] disable|enable old talk support
5928 + * ntalk=[0|1] disable|enable ntalk support
5929 + * ntalk2=[0|1] disable|enable ntalk2 support
5931 + * The default is talk=1 ntalk=1 ntalk2=1
5933 + * The helper does not support simultaneous talk requests.
5936 + * ASCII art on talk protocols
5939 + * caller server callee server
5946 + * caller client ----------- callee client
5949 + * 1. caller client <-> callee server: LOOK_UP, then ANNOUNCE invitation
5950 + * ( 2. caller client <-> caller server: LEAVE_INVITE to server )
5951 + * 3. callee client <-> caller server: LOOK_UP invitation
5952 + * 4. callee client <-> caller client: talk data channel
5954 + * [1]: M. Hunter, talk: a historical protocol for interactive communication
5955 + * draft-hunter-talk-00.txt
5956 + * [2]: D.B. Chapman, E.D. Zwicky: Building Internet Firewalls (O'Reilly)
5958 +#include <linux/config.h>
5959 +#include <linux/module.h>
5960 +#include <linux/netfilter.h>
5961 +#include <linux/ip.h>
5962 +#include <net/checksum.h>
5963 +#include <net/udp.h>
5965 +#include <linux/netfilter_ipv4/lockhelp.h>
5966 +#include <linux/netfilter_ipv4/ip_conntrack.h>
5967 +#include <linux/netfilter_ipv4/ip_conntrack_core.h>
5968 +#include <linux/netfilter_ipv4/ip_conntrack_helper.h>
5969 +#include <linux/netfilter_ipv4/ip_conntrack_talk.h>
5971 +/* Default all talk protocols are supported */
5972 +static int talk = 1;
5973 +static int ntalk = 1;
5974 +static int ntalk2 = 1;
5975 +MODULE_AUTHOR("Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>");
5976 +MODULE_DESCRIPTION("talk connection tracking module");
5977 +MODULE_LICENSE("GPL");
5979 +MODULE_PARM(talk, "i");
5980 +MODULE_PARM_DESC(talk, "support (old) talk protocol");
5981 +MODULE_PARM(ntalk, "i");
5982 +MODULE_PARM_DESC(ntalk, "support ntalk protocol");
5983 +MODULE_PARM(ntalk2, "i");
5984 +MODULE_PARM_DESC(ntalk2, "support ntalk2 protocol");
5987 +DECLARE_LOCK(ip_talk_lock);
5988 +struct module *ip_conntrack_talk = THIS_MODULE;
5991 +#define DEBUGP printk
5993 +#define DEBUGP(format, args...)
5996 +static int talk_expect(struct ip_conntrack *ct);
5997 +static int ntalk_expect(struct ip_conntrack *ct);
5999 +static int (*talk_expectfn[2])(struct ip_conntrack *ct) = {talk_expect, ntalk_expect};
6001 +static int talk_help_response(const struct iphdr *iph, size_t len,
6002 + struct ip_conntrack *ct,
6003 + enum ip_conntrack_info ctinfo,
6008 + struct talk_addr *addr)
6010 + int dir = CTINFO2DIR(ctinfo);
6011 + struct ip_conntrack_expect expect, *exp = &expect;
6012 + struct ip_ct_talk_expect *exp_talk_info = &exp->help.exp_talk_info;
6014 + DEBUGP("ip_ct_talk_help_response: %u.%u.%u.%u:%u, type %d answer %d\n",
6015 + NIPQUAD(addr->ta_addr), ntohs(addr->ta_port),
6018 + if (!(answer == SUCCESS && type == mode))
6021 + memset(&expect, 0, sizeof(expect));
6023 + if (type == ANNOUNCE) {
6025 + DEBUGP("ip_ct_talk_help_response: ANNOUNCE\n");
6027 + /* update the talk info */
6028 + LOCK_BH(&ip_talk_lock);
6029 + exp_talk_info->port = htons(talk_port);
6031 + /* expect callee client -> caller server message */
6032 + exp->tuple = ((struct ip_conntrack_tuple)
6033 + { { ct->tuplehash[dir].tuple.src.ip,
6035 + { ct->tuplehash[dir].tuple.dst.ip,
6036 + { .tcp = { htons(talk_port) } },
6038 + exp->mask = ((struct ip_conntrack_tuple)
6039 + { { 0xFFFFFFFF, { 0 } },
6040 + { 0xFFFFFFFF, { .tcp = { 0xFFFF } }, 0xFFFF }});
6042 + exp->expectfn = talk_expectfn[talk_port - TALK_PORT];
6044 + DEBUGP("ip_ct_talk_help_response: callee client %u.%u.%u.%u:%u -> caller daemon %u.%u.%u.%u:%u!\n",
6045 + NIPQUAD(exp->tuple.src.ip), ntohs(exp->tuple.src.u.udp.port),
6046 + NIPQUAD(exp->tuple.dst.ip), ntohs(exp->tuple.dst.u.udp.port));
6048 + /* Ignore failure; should only happen with NAT */
6049 + ip_conntrack_expect_related(ct, &expect);
6050 + UNLOCK_BH(&ip_talk_lock);
6052 + if (type == LOOK_UP) {
6054 + DEBUGP("ip_ct_talk_help_response: LOOK_UP\n");
6056 + /* update the talk info */
6057 + LOCK_BH(&ip_talk_lock);
6058 + exp_talk_info->port = addr->ta_port;
6060 + /* expect callee client -> caller client connection */
6061 + exp->tuple = ((struct ip_conntrack_tuple)
6062 + { { ct->tuplehash[!dir].tuple.src.ip,
6065 + { addr->ta_port },
6067 + exp->mask = ((struct ip_conntrack_tuple)
6068 + { { 0xFFFFFFFF, { 0 } },
6069 + { 0xFFFFFFFF, { 0xFFFF }, 0xFFFF }});
6071 + exp->expectfn = NULL;
6073 + DEBUGP("ip_ct_talk_help_response: callee client %u.%u.%u.%u:%u -> caller client %u.%u.%u.%u:%u!\n",
6074 + NIPQUAD(exp->tuple.src.ip), ntohs(exp->tuple.src.u.tcp.port),
6075 + NIPQUAD(exp->tuple.dst.ip), ntohs(exp->tuple.dst.u.tcp.port));
6077 + /* Ignore failure; should only happen with NAT */
6078 + ip_conntrack_expect_related(ct, &expect);
6079 + UNLOCK_BH(&ip_talk_lock);
6085 +/* FIXME: This should be in userspace. Later. */
6086 +static int talk_help(const struct iphdr *iph, size_t len,
6087 + struct ip_conntrack *ct,
6088 + enum ip_conntrack_info ctinfo,
6092 + struct udphdr *udph = (void *)iph + iph->ihl * 4;
6093 + const char *data = (const char *)udph + sizeof(struct udphdr);
6094 + int dir = CTINFO2DIR(ctinfo);
6097 + DEBUGP("ip_ct_talk_help: help entered\n");
6099 + /* Until there's been traffic both ways, don't look in packets. */
6100 + if (ctinfo != IP_CT_ESTABLISHED
6101 + && ctinfo != IP_CT_ESTABLISHED + IP_CT_IS_REPLY) {
6102 + DEBUGP("ip_ct_talk_help: Conntrackinfo = %u\n", ctinfo);
6106 + /* Not whole UDP header? */
6107 + udplen = len - iph->ihl * 4;
6108 + if (udplen < sizeof(struct udphdr)) {
6109 + DEBUGP("ip_ct_talk_help: too short for udph, udplen = %u\n", (unsigned)udplen);
6113 + /* Checksum invalid? Ignore. */
6114 + /* FIXME: Source route IP option packets --RR */
6115 + if (csum_tcpudp_magic(iph->saddr, iph->daddr, udplen, IPPROTO_UDP,
6116 + csum_partial((char *)udph, udplen, 0))) {
6117 + DEBUGP("ip_ct_talk_help: bad csum: %p %u %u.%u.%u.%u %u.%u.%u.%u\n",
6118 + udph, udplen, NIPQUAD(iph->saddr),
6119 + NIPQUAD(iph->daddr));
6123 + DEBUGP("ip_ct_talk_help: %u.%u.%u.%u:%u->%u.%u.%u.%u:%u\n",
6124 + NIPQUAD(iph->saddr), ntohs(udph->source), NIPQUAD(iph->daddr), ntohs(udph->dest));
6126 + if (dir == IP_CT_DIR_ORIGINAL)
6129 + if (talk_port == TALK_PORT
6130 + && udplen == sizeof(struct udphdr) + sizeof(struct talk_response))
6131 + return talk_help_response(iph, len, ct, ctinfo, talk_port, mode,
6132 + ((struct talk_response *)data)->type,
6133 + ((struct talk_response *)data)->answer,
6134 + &(((struct talk_response *)data)->addr));
6135 + else if (talk_port == NTALK_PORT
6137 + && udplen == sizeof(struct udphdr) + sizeof(struct ntalk_response)
6138 + && ((struct ntalk_response *)data)->vers == NTALK_VERSION)
6139 + return talk_help_response(iph, len, ct, ctinfo, talk_port, mode,
6140 + ((struct ntalk_response *)data)->type,
6141 + ((struct ntalk_response *)data)->answer,
6142 + &(((struct ntalk_response *)data)->addr));
6143 + else if (talk_port == NTALK_PORT
6145 + && udplen >= sizeof(struct udphdr) + sizeof(struct ntalk2_response)
6146 + && ((struct ntalk2_response *)data)->vers == NTALK2_VERSION)
6147 + return talk_help_response(iph, len, ct, ctinfo, talk_port, mode,
6148 + ((struct ntalk2_response *)data)->type,
6149 + ((struct ntalk2_response *)data)->answer,
6150 + &(((struct ntalk2_response *)data)->addr));
6152 + DEBUGP("ip_ct_talk_help: not ntalk/ntalk2 response, datalen %u != %u or %u + max 256\n",
6153 + (unsigned)udplen - sizeof(struct udphdr),
6154 + sizeof(struct ntalk_response), sizeof(struct ntalk2_response));
6159 +static int lookup_help(const struct iphdr *iph, size_t len,
6160 + struct ip_conntrack *ct, enum ip_conntrack_info ctinfo)
6162 + return talk_help(iph, len, ct, ctinfo, TALK_PORT, LOOK_UP);
6165 +static int lookup_nhelp(const struct iphdr *iph, size_t len,
6166 + struct ip_conntrack *ct, enum ip_conntrack_info ctinfo)
6168 + return talk_help(iph, len, ct, ctinfo, NTALK_PORT, LOOK_UP);
6171 +static struct ip_conntrack_helper lookup_helpers[2] =
6172 + { { { NULL, NULL },
6173 + "talk", /* name */
6175 + NULL, /* module */
6176 + 1, /* max_expected */
6177 + 240, /* timeout */
6178 + { { 0, { __constant_htons(TALK_PORT) } }, /* tuple */
6179 + { 0, { 0 }, IPPROTO_UDP } },
6180 + { { 0, { 0xFFFF } }, /* mask */
6181 + { 0, { 0 }, 0xFFFF } },
6182 + lookup_help }, /* helper */
6184 + "ntalk", /* name */
6186 + NULL, /* module */
6187 + 1, /* max_expected */
6188 + 240, /* timeout */
6189 + { { 0, { __constant_htons(NTALK_PORT) } }, /* tuple */
6190 + { 0, { 0 }, IPPROTO_UDP } },
6191 + { { 0, { 0xFFFF } }, /* mask */
6192 + { 0, { 0 }, 0xFFFF } },
6193 + lookup_nhelp } /* helper */
6196 +static int talk_expect(struct ip_conntrack *ct)
6198 + DEBUGP("ip_conntrack_talk: calling talk_expectfn for ct %p\n", ct);
6199 + WRITE_LOCK(&ip_conntrack_lock);
6200 + ct->helper = &lookup_helpers[0];
6201 + WRITE_UNLOCK(&ip_conntrack_lock);
6203 + return NF_ACCEPT; /* unused */
6206 +static int ntalk_expect(struct ip_conntrack *ct)
6208 + DEBUGP("ip_conntrack_talk: calling ntalk_expectfn for ct %p\n", ct);
6209 + WRITE_LOCK(&ip_conntrack_lock);
6210 + ct->helper = &lookup_helpers[1];
6211 + WRITE_UNLOCK(&ip_conntrack_lock);
6213 + return NF_ACCEPT; /* unused */
6216 +static int help(const struct iphdr *iph, size_t len,
6217 + struct ip_conntrack *ct, enum ip_conntrack_info ctinfo)
6219 + return talk_help(iph, len, ct, ctinfo, TALK_PORT, ANNOUNCE);
6222 +static int nhelp(const struct iphdr *iph, size_t len,
6223 + struct ip_conntrack *ct, enum ip_conntrack_info ctinfo)
6225 + return talk_help(iph, len, ct, ctinfo, NTALK_PORT, ANNOUNCE);
6228 +static struct ip_conntrack_helper talk_helpers[2] =
6229 + { { { NULL, NULL },
6230 + "talk", /* name */
6232 + THIS_MODULE, /* module */
6233 + 1, /* max_expected */
6234 + 240, /* timeout */
6235 + { { 0, { __constant_htons(TALK_PORT) } }, /* tuple */
6236 + { 0, { 0 }, IPPROTO_UDP } },
6237 + { { 0, { 0xFFFF } }, /* mask */
6238 + { 0, { 0 }, 0xFFFF } },
6239 + help }, /* helper */
6241 + "ntalk", /* name */
6243 + THIS_MODULE, /* module */
6244 + 1, /* max_expected */
6245 + 240, /* timeout */
6246 + { { 0, { __constant_htons(NTALK_PORT) } }, /* tuple */
6247 + { 0, { 0 }, IPPROTO_UDP } },
6248 + { { 0, { 0xFFFF } }, /* mask */
6249 + { 0, { 0 }, 0xFFFF } },
6250 + nhelp } /* helper */
6253 +static int __init init(void)
6256 + ip_conntrack_helper_register(&talk_helpers[0]);
6257 + if (ntalk > 0 || ntalk2 > 0)
6258 + ip_conntrack_helper_register(&talk_helpers[1]);
6263 +static void __exit fini(void)
6266 + ip_conntrack_helper_unregister(&talk_helpers[0]);
6267 + if (ntalk > 0 || ntalk2 > 0)
6268 + ip_conntrack_helper_unregister(&talk_helpers[1]);
6271 +EXPORT_SYMBOL(ip_talk_lock);
6275 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ip_nat_core.c linux-2.6.6/net/ipv4/netfilter/ip_nat_core.c
6276 --- linux-2.6.6.org/net/ipv4/netfilter/ip_nat_core.c 2004-05-10 04:32:01.000000000 +0200
6277 +++ linux-2.6.6/net/ipv4/netfilter/ip_nat_core.c 2004-05-18 14:28:50.000000000 +0200
6280 /* Have to grab read lock before sibling_list traversal */
6281 READ_LOCK(&ip_conntrack_lock);
6282 - list_for_each(cur_item, &ct->sibling_list) {
6283 + list_for_each_prev(cur_item, &ct->sibling_list) {
6284 exp = list_entry(cur_item, struct ip_conntrack_expect,
6287 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ip_nat_h323.c linux-2.6.6/net/ipv4/netfilter/ip_nat_h323.c
6288 --- linux-2.6.6.org/net/ipv4/netfilter/ip_nat_h323.c 1970-01-01 01:00:00.000000000 +0100
6289 +++ linux-2.6.6/net/ipv4/netfilter/ip_nat_h323.c 2004-05-18 14:28:50.000000000 +0200
6292 + * H.323 'brute force' extension for NAT alteration.
6293 + * Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
6295 + * Based on ip_masq_h323.c for 2.2 kernels from CoRiTel, Sofia project.
6296 + * (http://www.coritel.it/projects/sofia/nat.html)
6297 + * Uses Sampsa Ranta's excellent idea on using expectfn to 'bind'
6298 + * the unregistered helpers to the conntrack entries.
6302 +#include <linux/module.h>
6303 +#include <linux/netfilter.h>
6304 +#include <linux/ip.h>
6305 +#include <net/checksum.h>
6306 +#include <net/tcp.h>
6308 +#include <linux/netfilter_ipv4/lockhelp.h>
6309 +#include <linux/netfilter_ipv4/ip_nat.h>
6310 +#include <linux/netfilter_ipv4/ip_nat_helper.h>
6311 +#include <linux/netfilter_ipv4/ip_nat_rule.h>
6312 +#include <linux/netfilter_ipv4/ip_conntrack_tuple.h>
6313 +#include <linux/netfilter_ipv4/ip_conntrack_helper.h>
6314 +#include <linux/netfilter_ipv4/ip_conntrack_h323.h>
6316 +MODULE_AUTHOR("Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>");
6317 +MODULE_DESCRIPTION("H.323 'brute force' connection tracking module");
6318 +MODULE_LICENSE("GPL");
6320 +DECLARE_LOCK_EXTERN(ip_h323_lock);
6321 +struct module *ip_nat_h323 = THIS_MODULE;
6324 +#define DEBUGP printk
6326 +#define DEBUGP(format, args...)
6329 +/* FIXME: Time out? --RR */
6331 +static unsigned int
6332 +h225_nat_expected(struct sk_buff **pskb,
6333 + unsigned int hooknum,
6334 + struct ip_conntrack *ct,
6335 + struct ip_nat_info *info);
6337 +static unsigned int h225_nat_help(struct ip_conntrack *ct,
6338 + struct ip_conntrack_expect *exp,
6339 + struct ip_nat_info *info,
6340 + enum ip_conntrack_info ctinfo,
6341 + unsigned int hooknum,
6342 + struct sk_buff **pskb);
6344 +static struct ip_nat_helper h245 =
6346 + "H.245", /* name */
6348 + NULL, /* module */
6349 + { { 0, { 0 } }, /* tuple */
6350 + { 0, { 0 }, IPPROTO_TCP } },
6351 + { { 0, { 0xFFFF } }, /* mask */
6352 + { 0, { 0 }, 0xFFFF } },
6353 + h225_nat_help, /* helper */
6354 + h225_nat_expected /* expectfn */
6357 +static unsigned int
6358 +h225_nat_expected(struct sk_buff **pskb,
6359 + unsigned int hooknum,
6360 + struct ip_conntrack *ct,
6361 + struct ip_nat_info *info)
6363 + struct ip_nat_multi_range mr;
6364 + u_int32_t newdstip, newsrcip, newip;
6366 + struct ip_ct_h225_expect *exp_info;
6367 + struct ip_ct_h225_master *master_info;
6368 + struct ip_conntrack *master = master_ct(ct);
6369 + unsigned int is_h225, ret;
6371 + IP_NF_ASSERT(info);
6372 + IP_NF_ASSERT(master);
6374 + IP_NF_ASSERT(!(info->initialized & (1<<HOOK2MANIP(hooknum))));
6376 + DEBUGP("h225_nat_expected: We have a connection!\n");
6377 + master_info = &ct->master->expectant->help.ct_h225_info;
6378 + exp_info = &ct->master->help.exp_h225_info;
6380 + LOCK_BH(&ip_h323_lock);
6382 + DEBUGP("master: ");
6383 + DUMP_TUPLE(&master->tuplehash[IP_CT_DIR_ORIGINAL].tuple);
6384 + DUMP_TUPLE(&master->tuplehash[IP_CT_DIR_REPLY].tuple);
6385 + DEBUGP("conntrack: ");
6386 + DUMP_TUPLE(&ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple);
6387 + if (exp_info->dir == IP_CT_DIR_ORIGINAL) {
6388 + /* Make connection go to the client. */
6389 + newdstip = master->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.ip;
6390 + newsrcip = master->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.ip;
6391 + DEBUGP("h225_nat_expected: %u.%u.%u.%u->%u.%u.%u.%u (to client)\n",
6392 + NIPQUAD(newsrcip), NIPQUAD(newdstip));
6394 + /* Make the connection go to the server */
6395 + newdstip = master->tuplehash[IP_CT_DIR_REPLY].tuple.src.ip;
6396 + newsrcip = master->tuplehash[IP_CT_DIR_REPLY].tuple.dst.ip;
6397 + DEBUGP("h225_nat_expected: %u.%u.%u.%u->%u.%u.%u.%u (to server)\n",
6398 + NIPQUAD(newsrcip), NIPQUAD(newdstip));
6400 + port = exp_info->port;
6401 + is_h225 = master_info->is_h225 == H225_PORT;
6402 + UNLOCK_BH(&ip_h323_lock);
6404 + if (HOOK2MANIP(hooknum) == IP_NAT_MANIP_SRC)
6409 + DEBUGP("h225_nat_expected: IP to %u.%u.%u.%u\n", NIPQUAD(newip));
6412 + /* We don't want to manip the per-protocol, just the IPs... */
6413 + mr.range[0].flags = IP_NAT_RANGE_MAP_IPS;
6414 + mr.range[0].min_ip = mr.range[0].max_ip = newip;
6416 + /* ... unless we're doing a MANIP_DST, in which case, make
6417 + sure we map to the correct port */
6418 + if (HOOK2MANIP(hooknum) == IP_NAT_MANIP_DST) {
6419 + mr.range[0].flags |= IP_NAT_RANGE_PROTO_SPECIFIED;
6420 + mr.range[0].min = mr.range[0].max
6421 + = ((union ip_conntrack_manip_proto)
6422 + { .tcp = { port } });
6425 + ret = ip_nat_setup_info(ct, &mr, hooknum);
6428 + DEBUGP("h225_nat_expected: H.225, setting NAT helper for %p\n", ct);
6429 + /* NAT expectfn called with ip_nat_lock write-locked */
6430 + info->helper = &h245;
6435 +static int h323_signal_address_fixup(struct ip_conntrack *ct,
6436 + struct sk_buff **pskb,
6437 + enum ip_conntrack_info ctinfo)
6439 + struct iphdr *iph = (*pskb)->nh.iph;
6440 + struct tcphdr *tcph = (void *)iph + iph->ihl*4;
6441 + char *data = (char *) tcph + tcph->doff * 4;
6442 + u_int32_t tcplen = (*pskb)->len - iph->ihl*4;
6443 + u_int32_t datalen = tcplen - tcph->doff*4;
6444 + struct ip_ct_h225_master *info = &ct->help.ct_h225_info;
6449 + MUST_BE_LOCKED(&ip_h323_lock);
6451 + DEBUGP("h323_signal_address_fixup: %s %s\n",
6452 + between(info->seq[IP_CT_DIR_ORIGINAL], ntohl(tcph->seq), ntohl(tcph->seq) + datalen)
6454 + between(info->seq[IP_CT_DIR_REPLY], ntohl(tcph->seq), ntohl(tcph->seq) + datalen)
6456 + if (!(between(info->seq[IP_CT_DIR_ORIGINAL], ntohl(tcph->seq), ntohl(tcph->seq) + datalen)
6457 + || between(info->seq[IP_CT_DIR_REPLY], ntohl(tcph->seq), ntohl(tcph->seq) + datalen)))
6460 + DEBUGP("h323_signal_address_fixup: offsets %u + 6 and %u + 6 in %u\n",
6461 + info->offset[IP_CT_DIR_ORIGINAL],
6462 + info->offset[IP_CT_DIR_REPLY],
6464 + DUMP_TUPLE(&ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple);
6465 + DUMP_TUPLE(&ct->tuplehash[IP_CT_DIR_REPLY].tuple);
6467 + for (i = 0; i < IP_CT_DIR_MAX; i++) {
6468 + DEBUGP("h323_signal_address_fixup: %s %s\n",
6469 + info->dir == IP_CT_DIR_ORIGINAL ? "original" : "reply",
6470 + i == IP_CT_DIR_ORIGINAL ? "caller" : "callee");
6471 + if (!between(info->seq[i], ntohl(tcph->seq),
6472 + ntohl(tcph->seq) + datalen))
6474 + if (!between(info->seq[i] + 6, ntohl(tcph->seq),
6475 + ntohl(tcph->seq) + datalen)) {
6476 + /* Partial retransmisison. It's a cracker being funky. */
6477 + if (net_ratelimit()) {
6478 + printk("H.323_NAT: partial packet %u/6 in %u/%u\n",
6481 + ntohl(tcph->seq) + datalen);
6486 + /* Change address inside packet to match way we're mapping
6487 + this connection. */
6488 + if (i == IP_CT_DIR_ORIGINAL) {
6489 + newip = ct->tuplehash[!info->dir].tuple.dst.ip;
6490 + port = ct->tuplehash[!info->dir].tuple.dst.u.tcp.port;
6492 + newip = ct->tuplehash[!info->dir].tuple.src.ip;
6493 + port = ct->tuplehash[!info->dir].tuple.src.u.tcp.port;
6496 + DEBUGP("h323_signal_address_fixup: orig %s IP:port %u.%u.%u.%u:%u\n",
6497 + i == IP_CT_DIR_ORIGINAL ? "source" : "dest ",
6498 + NIPQUAD(*((u_int32_t *)(data + info->offset[i]))),
6499 + ntohs(*((u_int16_t *)(data + info->offset[i] + 4))));
6501 + /* Modify the packet */
6502 + *(u_int32_t *)(data + info->offset[i]) = newip;
6503 + *(u_int16_t *)(data + info->offset[i] + 4) = port;
6505 + DEBUGP("h323_signal_address_fixup: new %s IP:port %u.%u.%u.%u:%u\n",
6506 + i == IP_CT_DIR_ORIGINAL ? "source" : "dest ",
6507 + NIPQUAD(*((u_int32_t *)(data + info->offset[i]))),
6508 + ntohs(*((u_int16_t *)(data + info->offset[i] + 4))));
6511 + /* fix checksum information */
6513 + (*pskb)->csum = csum_partial((char *)tcph + tcph->doff*4,
6517 + tcph->check = tcp_v4_check(tcph, tcplen, iph->saddr, iph->daddr,
6518 + csum_partial((char *)tcph, tcph->doff*4,
6520 + ip_send_check(iph);
6525 +static int h323_data_fixup(struct ip_ct_h225_expect *info,
6526 + struct ip_conntrack *ct,
6527 + struct sk_buff **pskb,
6528 + enum ip_conntrack_info ctinfo,
6529 + struct ip_conntrack_expect *expect)
6533 + struct ip_conntrack_tuple newtuple;
6534 + struct iphdr *iph = (*pskb)->nh.iph;
6535 + struct tcphdr *tcph = (void *)iph + iph->ihl*4;
6536 + char *data = (char *) tcph + tcph->doff * 4;
6537 + u_int32_t tcplen = (*pskb)->len - iph->ihl*4;
6538 + struct ip_ct_h225_master *master_info = &ct->help.ct_h225_info;
6541 + MUST_BE_LOCKED(&ip_h323_lock);
6542 + DEBUGP("h323_data_fixup: offset %u + 6 in %u\n", info->offset, tcplen);
6543 + DUMP_TUPLE(&ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple);
6544 + DUMP_TUPLE(&ct->tuplehash[IP_CT_DIR_REPLY].tuple);
6546 + if (!between(expect->seq + 6, ntohl(tcph->seq),
6547 + ntohl(tcph->seq) + tcplen - tcph->doff * 4)) {
6548 + /* Partial retransmisison. It's a cracker being funky. */
6549 + if (net_ratelimit()) {
6550 + printk("H.323_NAT: partial packet %u/6 in %u/%u\n",
6553 + ntohl(tcph->seq) + tcplen - tcph->doff * 4);
6558 + /* Change address inside packet to match way we're mapping
6559 + this connection. */
6560 + if (info->dir == IP_CT_DIR_REPLY) {
6561 + /* Must be where client thinks server is */
6562 + newip = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.ip;
6563 + /* Expect something from client->server */
6564 + newtuple.src.ip = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.ip;
6565 + newtuple.dst.ip = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.ip;
6567 + /* Must be where server thinks client is */
6568 + newip = ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.ip;
6569 + /* Expect something from server->client */
6570 + newtuple.src.ip = ct->tuplehash[IP_CT_DIR_REPLY].tuple.src.ip;
6571 + newtuple.dst.ip = ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.ip;
6574 + is_h225 = (master_info->is_h225 == H225_PORT);
6577 + newtuple.dst.protonum = IPPROTO_TCP;
6578 + newtuple.src.u.tcp.port = expect->tuple.src.u.tcp.port;
6580 + newtuple.dst.protonum = IPPROTO_UDP;
6581 + newtuple.src.u.udp.port = expect->tuple.src.u.udp.port;
6584 + /* Try to get same port: if not, try to change it. */
6585 + for (port = ntohs(info->port); port != 0; port++) {
6587 + newtuple.dst.u.tcp.port = htons(port);
6589 + newtuple.dst.u.udp.port = htons(port);
6591 + if (ip_conntrack_change_expect(expect, &newtuple) == 0)
6595 + DEBUGP("h323_data_fixup: no free port found!\n");
6599 + port = htons(port);
6601 + DEBUGP("h323_data_fixup: orig IP:port %u.%u.%u.%u:%u\n",
6602 + NIPQUAD(*((u_int32_t *)(data + info->offset))),
6603 + ntohs(*((u_int16_t *)(data + info->offset + 4))));
6605 + /* Modify the packet */
6606 + *(u_int32_t *)(data + info->offset) = newip;
6607 + *(u_int16_t *)(data + info->offset + 4) = port;
6609 + DEBUGP("h323_data_fixup: new IP:port %u.%u.%u.%u:%u\n",
6610 + NIPQUAD(*((u_int32_t *)(data + info->offset))),
6611 + ntohs(*((u_int16_t *)(data + info->offset + 4))));
6613 + /* fix checksum information */
6614 + /* FIXME: usually repeated multiple times in the case of H.245! */
6616 + (*pskb)->csum = csum_partial((char *)tcph + tcph->doff*4,
6617 + tcplen - tcph->doff*4, 0);
6620 + tcph->check = tcp_v4_check(tcph, tcplen, iph->saddr, iph->daddr,
6621 + csum_partial((char *)tcph, tcph->doff*4,
6623 + ip_send_check(iph);
6628 +static unsigned int h225_nat_help(struct ip_conntrack *ct,
6629 + struct ip_conntrack_expect *exp,
6630 + struct ip_nat_info *info,
6631 + enum ip_conntrack_info ctinfo,
6632 + unsigned int hooknum,
6633 + struct sk_buff **pskb)
6636 + struct ip_ct_h225_expect *exp_info;
6638 + /* Only mangle things once: original direction in POST_ROUTING
6639 + and reply direction on PRE_ROUTING. */
6640 + dir = CTINFO2DIR(ctinfo);
6641 + DEBUGP("nat_h323: dir %s at hook %s\n",
6642 + dir == IP_CT_DIR_ORIGINAL ? "ORIG" : "REPLY",
6643 + hooknum == NF_IP_POST_ROUTING ? "POSTROUTING"
6644 + : hooknum == NF_IP_PRE_ROUTING ? "PREROUTING"
6645 + : hooknum == NF_IP_LOCAL_OUT ? "OUTPUT" : "???");
6646 + if (!((hooknum == NF_IP_POST_ROUTING && dir == IP_CT_DIR_ORIGINAL)
6647 + || (hooknum == NF_IP_PRE_ROUTING && dir == IP_CT_DIR_REPLY))) {
6648 + DEBUGP("nat_h323: Not touching dir %s at hook %s\n",
6649 + dir == IP_CT_DIR_ORIGINAL ? "ORIG" : "REPLY",
6650 + hooknum == NF_IP_POST_ROUTING ? "POSTROUTING"
6651 + : hooknum == NF_IP_PRE_ROUTING ? "PREROUTING"
6652 + : hooknum == NF_IP_LOCAL_OUT ? "OUTPUT" : "???");
6657 + LOCK_BH(&ip_h323_lock);
6658 + if (!h323_signal_address_fixup(ct, pskb, ctinfo)) {
6659 + UNLOCK_BH(&ip_h323_lock);
6662 + UNLOCK_BH(&ip_h323_lock);
6666 + exp_info = &exp->help.exp_h225_info;
6668 + LOCK_BH(&ip_h323_lock);
6669 + if (!h323_data_fixup(exp_info, ct, pskb, ctinfo, exp)) {
6670 + UNLOCK_BH(&ip_h323_lock);
6673 + UNLOCK_BH(&ip_h323_lock);
6678 +static struct ip_nat_helper h225 =
6680 + "H.225", /* name */
6681 + IP_NAT_HELPER_F_ALWAYS, /* flags */
6682 + THIS_MODULE, /* module */
6683 + { { 0, { .tcp = { __constant_htons(H225_PORT) } } }, /* tuple */
6684 + { 0, { 0 }, IPPROTO_TCP } },
6685 + { { 0, { .tcp = { 0xFFFF } } }, /* mask */
6686 + { 0, { 0 }, 0xFFFF } },
6687 + h225_nat_help, /* helper */
6688 + h225_nat_expected /* expectfn */
6691 +static int __init init(void)
6695 + ret = ip_nat_helper_register(&h225);
6698 + printk("ip_nat_h323: cannot initialize the module!\n");
6703 +static void __exit fini(void)
6705 + ip_nat_helper_unregister(&h225);
6710 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ip_nat_mms.c linux-2.6.6/net/ipv4/netfilter/ip_nat_mms.c
6711 --- linux-2.6.6.org/net/ipv4/netfilter/ip_nat_mms.c 1970-01-01 01:00:00.000000000 +0100
6712 +++ linux-2.6.6/net/ipv4/netfilter/ip_nat_mms.c 2004-05-18 14:28:50.000000000 +0200
6714 +/* MMS extension for TCP NAT alteration.
6715 + * (C) 2002 by Filip Sneppe <filip.sneppe@cronos.be>
6716 + * based on ip_nat_ftp.c and ip_nat_irc.c
6718 + * ip_nat_mms.c v0.3 2002-09-22
6720 + * This program is free software; you can redistribute it and/or
6721 + * modify it under the terms of the GNU General Public License
6722 + * as published by the Free Software Foundation; either version
6723 + * 2 of the License, or (at your option) any later version.
6725 + * Module load syntax:
6726 + * insmod ip_nat_mms.o ports=port1,port2,...port<MAX_PORTS>
6728 + * Please give the ports of all MMS servers You wish to connect to.
6729 + * If you don't specify ports, the default will be TCP port 1755.
6731 + * More info on MMS protocol, firewalls and NAT:
6732 + * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwmt/html/MMSFirewall.asp
6733 + * http://www.microsoft.com/windows/windowsmedia/serve/firewall.asp
6735 + * The SDP project people are reverse-engineering MMS:
6736 + * http://get.to/sdp
6739 +/* FIXME: issue with UDP & fragmentation with this URL:
6740 + http://www.cnn.com/video/world/2002/01/21/jb.shoe.bomb.cafe.cnn.low.asx
6741 + may be related to out-of-order first packets:
6742 + basically the expectation is set up correctly, then the server sends
6743 + a first UDP packet which is fragmented plus arrives out-of-order.
6744 + the MASQUERADING firewall with ip_nat_mms loaded responds with
6745 + an ICMP unreachable back to the server */
6747 +#include <linux/module.h>
6748 +#include <linux/netfilter_ipv4.h>
6749 +#include <linux/ip.h>
6750 +#include <linux/tcp.h>
6751 +#include <net/tcp.h>
6752 +#include <linux/netfilter_ipv4/ip_nat.h>
6753 +#include <linux/netfilter_ipv4/ip_nat_helper.h>
6754 +#include <linux/netfilter_ipv4/ip_nat_rule.h>
6755 +#include <linux/netfilter_ipv4/ip_conntrack_mms.h>
6756 +#include <linux/netfilter_ipv4/ip_conntrack_helper.h>
6759 +#define DEBUGP printk
6760 +#define DUMP_BYTES(address, counter) \
6762 + int temp_counter; \
6763 + for(temp_counter=0; temp_counter<counter; ++temp_counter) { \
6764 + DEBUGP("%u ", (u8)*(address+temp_counter)); \
6769 +#define DEBUGP(format, args...)
6770 +#define DUMP_BYTES(address, counter)
6773 +#define MAX_PORTS 8
6774 +static int ports[MAX_PORTS];
6775 +static int ports_c = 0;
6778 +MODULE_PARM(ports, "1-" __MODULE_STRING(MAX_PORTS) "i");
6781 +MODULE_AUTHOR("Filip Sneppe <filip.sneppe@cronos.be>");
6782 +MODULE_DESCRIPTION("Microsoft Windows Media Services (MMS) NAT module");
6783 +MODULE_LICENSE("GPL");
6785 +DECLARE_LOCK_EXTERN(ip_mms_lock);
6787 +/* FIXME: Time out? --RR */
6789 +static int mms_data_fixup(const struct ip_ct_mms_expect *ct_mms_info,
6790 + struct ip_conntrack *ct,
6791 + struct sk_buff **pskb,
6792 + enum ip_conntrack_info ctinfo,
6793 + struct ip_conntrack_expect *expect)
6796 + struct ip_conntrack_tuple t;
6797 + struct iphdr *iph = (*pskb)->nh.iph;
6798 + struct tcphdr *tcph = (void *) iph + iph->ihl * 4;
6799 + char *data = (char *)tcph + tcph->doff * 4;
6800 + int i, j, k, port;
6801 + u_int16_t mms_proto;
6803 + u_int32_t *mms_chunkLenLV = (u_int32_t *)(data + MMS_SRV_CHUNKLENLV_OFFSET);
6804 + u_int32_t *mms_chunkLenLM = (u_int32_t *)(data + MMS_SRV_CHUNKLENLM_OFFSET);
6805 + u_int32_t *mms_messageLength = (u_int32_t *)(data + MMS_SRV_MESSAGELENGTH_OFFSET);
6809 + char buffer[28]; /* "\\255.255.255.255\UDP\65635" * 2 (for unicode) */
6810 + char unicode_buffer[75]; /* 27*2 (unicode) + 20 + 1 */
6811 + char proto_string[6];
6813 + MUST_BE_LOCKED(&ip_mms_lock);
6815 + /* what was the protocol again ? */
6816 + mms_proto = expect->tuple.dst.protonum;
6817 + sprintf(proto_string, "%u", mms_proto);
6819 + DEBUGP("ip_nat_mms: mms_data_fixup: info (seq %u + %u) in %u, proto %s\n",
6820 + expect->seq, ct_mms_info->len, ntohl(tcph->seq),
6821 + mms_proto == IPPROTO_UDP ? "UDP"
6822 + : mms_proto == IPPROTO_TCP ? "TCP":proto_string);
6824 + newip = ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.ip;
6826 + /* Alter conntrack's expectations. */
6827 + t = expect->tuple;
6829 + for (port = ct_mms_info->port; port != 0; port++) {
6830 + t.dst.u.tcp.port = htons(port);
6831 + if (ip_conntrack_change_expect(expect, &t) == 0) {
6832 + DEBUGP("ip_nat_mms: mms_data_fixup: using port %d\n", port);
6840 + sprintf(buffer, "\\\\%u.%u.%u.%u\\%s\\%u",
6842 + expect->tuple.dst.protonum == IPPROTO_UDP ? "UDP"
6843 + : expect->tuple.dst.protonum == IPPROTO_TCP ? "TCP":proto_string,
6845 + DEBUGP("ip_nat_mms: new unicode string=%s\n", buffer);
6847 + memset(unicode_buffer, 0, sizeof(char)*75);
6849 + for (i=0; i<strlen(buffer); ++i)
6850 + *(unicode_buffer+i*2)=*(buffer+i);
6852 + DEBUGP("ip_nat_mms: mms_data_fixup: padding: %u len: %u\n", ct_mms_info->padding, ct_mms_info->len);
6853 + DEBUGP("ip_nat_mms: mms_data_fixup: offset: %u\n", MMS_SRV_UNICODE_STRING_OFFSET+ct_mms_info->len);
6854 + DUMP_BYTES(data+MMS_SRV_UNICODE_STRING_OFFSET, 60);
6856 + /* add end of packet to it */
6857 + for (j=0; j<ct_mms_info->padding; ++j) {
6858 + DEBUGP("ip_nat_mms: mms_data_fixup: i=%u j=%u byte=%u\n",
6859 + i, j, (u8)*(data+MMS_SRV_UNICODE_STRING_OFFSET+ct_mms_info->len+j));
6860 + *(unicode_buffer+i*2+j) = *(data+MMS_SRV_UNICODE_STRING_OFFSET+ct_mms_info->len+j);
6863 + /* pad with zeroes at the end ? see explanation of weird math below */
6864 + zero_padding = (8-(strlen(buffer)*2 + ct_mms_info->padding + 4)%8)%8;
6865 + for (k=0; k<zero_padding; ++k)
6866 + *(unicode_buffer+i*2+j+k)= (char)0;
6868 + DEBUGP("ip_nat_mms: mms_data_fixup: zero_padding = %u\n", zero_padding);
6869 + DEBUGP("ip_nat_mms: original=> chunkLenLV=%u chunkLenLM=%u messageLength=%u\n",
6870 + *mms_chunkLenLV, *mms_chunkLenLM, *mms_messageLength);
6872 + /* explanation, before I forget what I did:
6873 + strlen(buffer)*2 + ct_mms_info->padding + 4 must be divisable by 8;
6874 + divide by 8 and add 3 to compute the mms_chunkLenLM field,
6875 + but note that things may have to be padded with zeroes to align by 8
6876 + bytes, hence we add 7 and divide by 8 to get the correct length */
6877 + *mms_chunkLenLM = (u_int32_t) (3+(strlen(buffer)*2+ct_mms_info->padding+11)/8);
6878 + *mms_chunkLenLV = *mms_chunkLenLM+2;
6879 + *mms_messageLength = *mms_chunkLenLV*8;
6881 + DEBUGP("ip_nat_mms: modified=> chunkLenLV=%u chunkLenLM=%u messageLength=%u\n",
6882 + *mms_chunkLenLV, *mms_chunkLenLM, *mms_messageLength);
6884 + ip_nat_mangle_tcp_packet(pskb, ct, ctinfo,
6885 + expect->seq - ntohl(tcph->seq),
6886 + ct_mms_info->len + ct_mms_info->padding, unicode_buffer,
6887 + strlen(buffer)*2 + ct_mms_info->padding + zero_padding);
6888 + DUMP_BYTES(unicode_buffer, 60);
6893 +static unsigned int
6894 +mms_nat_expected(struct sk_buff **pskb,
6895 + unsigned int hooknum,
6896 + struct ip_conntrack *ct,
6897 + struct ip_nat_info *info)
6899 + struct ip_nat_multi_range mr;
6900 + u_int32_t newdstip, newsrcip, newip;
6902 + struct ip_conntrack *master = master_ct(ct);
6904 + IP_NF_ASSERT(info);
6905 + IP_NF_ASSERT(master);
6907 + IP_NF_ASSERT(!(info->initialized & (1 << HOOK2MANIP(hooknum))));
6909 + DEBUGP("ip_nat_mms: mms_nat_expected: We have a connection!\n");
6911 + newdstip = master->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.ip;
6912 + newsrcip = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.ip;
6913 + DEBUGP("ip_nat_mms: mms_nat_expected: hook %s: newsrc->newdst %u.%u.%u.%u->%u.%u.%u.%u\n",
6914 + hooknum == NF_IP_POST_ROUTING ? "POSTROUTING"
6915 + : hooknum == NF_IP_PRE_ROUTING ? "PREROUTING"
6916 + : hooknum == NF_IP_LOCAL_OUT ? "OUTPUT" : "???",
6917 + NIPQUAD(newsrcip), NIPQUAD(newdstip));
6919 + if (HOOK2MANIP(hooknum) == IP_NAT_MANIP_SRC)
6924 + DEBUGP("ip_nat_mms: mms_nat_expected: IP to %u.%u.%u.%u\n", NIPQUAD(newip));
6927 + /* We don't want to manip the per-protocol, just the IPs. */
6928 + mr.range[0].flags = IP_NAT_RANGE_MAP_IPS;
6929 + mr.range[0].min_ip = mr.range[0].max_ip = newip;
6931 + return ip_nat_setup_info(ct, &mr, hooknum);
6935 +static unsigned int mms_nat_help(struct ip_conntrack *ct,
6936 + struct ip_conntrack_expect *exp,
6937 + struct ip_nat_info *info,
6938 + enum ip_conntrack_info ctinfo,
6939 + unsigned int hooknum,
6940 + struct sk_buff **pskb)
6942 + struct iphdr *iph = (*pskb)->nh.iph;
6943 + struct tcphdr *tcph = (void *) iph + iph->ihl * 4;
6944 + unsigned int datalen;
6946 + struct ip_ct_mms_expect *ct_mms_info;
6949 + DEBUGP("ip_nat_mms: no exp!!");
6951 + ct_mms_info = &exp->help.exp_mms_info;
6953 + /* Only mangle things once: original direction in POST_ROUTING
6954 + and reply direction on PRE_ROUTING. */
6955 + dir = CTINFO2DIR(ctinfo);
6956 + if (!((hooknum == NF_IP_POST_ROUTING && dir == IP_CT_DIR_ORIGINAL)
6957 + ||(hooknum == NF_IP_PRE_ROUTING && dir == IP_CT_DIR_REPLY))) {
6958 + DEBUGP("ip_nat_mms: mms_nat_help: not touching dir %s at hook %s\n",
6959 + dir == IP_CT_DIR_ORIGINAL ? "ORIG" : "REPLY",
6960 + hooknum == NF_IP_POST_ROUTING ? "POSTROUTING"
6961 + : hooknum == NF_IP_PRE_ROUTING ? "PREROUTING"
6962 + : hooknum == NF_IP_LOCAL_OUT ? "OUTPUT" : "???");
6965 + DEBUGP("ip_nat_mms: mms_nat_help: beyond not touching (dir %s at hook %s)\n",
6966 + dir == IP_CT_DIR_ORIGINAL ? "ORIG" : "REPLY",
6967 + hooknum == NF_IP_POST_ROUTING ? "POSTROUTING"
6968 + : hooknum == NF_IP_PRE_ROUTING ? "PREROUTING"
6969 + : hooknum == NF_IP_LOCAL_OUT ? "OUTPUT" : "???");
6971 + datalen = (*pskb)->len - iph->ihl * 4 - tcph->doff * 4;
6973 + DEBUGP("ip_nat_mms: mms_nat_help: %u+%u=%u %u %u\n", exp->seq, ct_mms_info->len,
6974 + exp->seq + ct_mms_info->len,
6976 + ntohl(tcph->seq) + datalen);
6978 + LOCK_BH(&ip_mms_lock);
6979 + /* Check wether the whole IP/proto/port pattern is carried in the payload */
6980 + if (between(exp->seq + ct_mms_info->len,
6982 + ntohl(tcph->seq) + datalen)) {
6983 + if (!mms_data_fixup(ct_mms_info, ct, pskb, ctinfo, exp)) {
6984 + UNLOCK_BH(&ip_mms_lock);
6988 + /* Half a match? This means a partial retransmisison.
6989 + It's a cracker being funky. */
6990 + if (net_ratelimit()) {
6991 + printk("ip_nat_mms: partial packet %u/%u in %u/%u\n",
6992 + exp->seq, ct_mms_info->len,
6994 + ntohl(tcph->seq) + datalen);
6996 + UNLOCK_BH(&ip_mms_lock);
6999 + UNLOCK_BH(&ip_mms_lock);
7004 +static struct ip_nat_helper mms[MAX_PORTS];
7005 +static char mms_names[MAX_PORTS][10];
7007 +/* Not __exit: called from init() */
7008 +static void fini(void)
7012 + for (i = 0; (i < MAX_PORTS) && ports[i]; i++) {
7013 + DEBUGP("ip_nat_mms: unregistering helper for port %d\n", ports[i]);
7014 + ip_nat_helper_unregister(&mms[i]);
7018 +static int __init init(void)
7023 + if (ports[0] == 0)
7024 + ports[0] = MMS_PORT;
7026 + for (i = 0; (i < MAX_PORTS) && ports[i]; i++) {
7028 + memset(&mms[i], 0, sizeof(struct ip_nat_helper));
7030 + mms[i].tuple.dst.protonum = IPPROTO_TCP;
7031 + mms[i].tuple.src.u.tcp.port = htons(ports[i]);
7032 + mms[i].mask.dst.protonum = 0xFFFF;
7033 + mms[i].mask.src.u.tcp.port = 0xFFFF;
7034 + mms[i].help = mms_nat_help;
7035 + mms[i].me = THIS_MODULE;
7037 + mms[i].expect = mms_nat_expected;
7039 + tmpname = &mms_names[i][0];
7040 + if (ports[i] == MMS_PORT)
7041 + sprintf(tmpname, "mms");
7043 + sprintf(tmpname, "mms-%d", i);
7044 + mms[i].name = tmpname;
7046 + DEBUGP("ip_nat_mms: register helper for port %d\n",
7048 + ret = ip_nat_helper_register(&mms[i]);
7051 + printk("ip_nat_mms: error registering "
7052 + "helper for port %d\n", ports[i]);
7064 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ip_nat_quake3.c linux-2.6.6/net/ipv4/netfilter/ip_nat_quake3.c
7065 --- linux-2.6.6.org/net/ipv4/netfilter/ip_nat_quake3.c 1970-01-01 01:00:00.000000000 +0100
7066 +++ linux-2.6.6/net/ipv4/netfilter/ip_nat_quake3.c 2004-05-18 14:28:50.000000000 +0200
7068 +/* Quake3 extension for UDP NAT alteration.
7069 + * (C) 2002 by Filip Sneppe <filip.sneppe@cronos.be>
7070 + * based on ip_nat_ftp.c and ip_nat_tftp.c
7072 + * ip_nat_quake3.c v0.0.3 2002-08-31
7074 + * This program is free software; you can redistribute it and/or
7075 + * modify it under the terms of the GNU General Public License
7076 + * as published by the Free Software Foundation; either version
7077 + * 2 of the License, or (at your option) any later version.
7079 + * Module load syntax:
7080 + * insmod ip_nat_quake3.o ports=port1,port2,...port<MAX_PORTS>
7082 + * please give the ports of all Quake3 master servers You wish to
7083 + * connect to. If you don't specify ports, the default will be UDP
7086 + * Thanks to the Ethereal folks for their analysis of the Quake3 protocol.
7089 + * - If you're one of those people who would try anything to lower
7090 + * latency while playing Quake (and who isn't :-) ), you may want to
7091 + * consider not loading ip_nat_quake3 at all and just MASQUERADE all
7092 + * outgoing UDP traffic.
7093 + * This will make ip_conntrack_quake3 add the necessary expectations,
7094 + * but there will be no overhead for client->server UDP streams. If
7095 + * ip_nat_quake3 is loaded, quake3_nat_expected will be called per NAT
7096 + * hook for every packet in the client->server UDP stream.
7097 + * - Only SNAT/MASQUEARDE targets are useful for ip_nat_quake3.
7098 + * The IP addresses in the master connection payload (=IP addresses
7099 + * of Quake servers) have no relation with the master server so
7100 + * DNAT'ing the master connection to a server should not change the
7101 + * expected connections.
7102 + * - Not tested due to lack of equipment:
7103 + * - multiple Quake3 clients behind one MASQUERADE gateway
7104 + * - what if Quake3 client is running on router too
7107 +#include <linux/module.h>
7108 +#include <linux/netfilter_ipv4.h>
7109 +#include <linux/ip.h>
7110 +#include <linux/udp.h>
7112 +#include <linux/netfilter.h>
7113 +#include <linux/netfilter_ipv4/ip_tables.h>
7114 +#include <linux/netfilter_ipv4/ip_conntrack_helper.h>
7115 +#include <linux/netfilter_ipv4/ip_conntrack_quake3.h>
7116 +#include <linux/netfilter_ipv4/ip_nat_helper.h>
7117 +#include <linux/netfilter_ipv4/ip_nat_rule.h>
7119 +MODULE_AUTHOR("Filip Sneppe <filip.sneppe@cronos.be>");
7120 +MODULE_DESCRIPTION("Netfilter NAT helper for Quake III Arena");
7121 +MODULE_LICENSE("GPL");
7123 +#define MAX_PORTS 8
7125 +static int ports[MAX_PORTS];
7126 +static int ports_c = 0;
7128 +MODULE_PARM(ports,"1-" __MODULE_STRING(MAX_PORTS) "i");
7129 +MODULE_PARM_DESC(ports, "port numbers of Quake III master servers");
7132 +/* Quake3 master server reply will add > 100 expectations per reply packet; when
7133 + doing lots of printk's, klogd may not be able to read /proc/kmsg fast enough */
7135 +#define DEBUGP printk
7137 +#define DEBUGP(format, args...)
7140 +static struct quake3_search quake3s_nat = { "****", "getserversResponse", sizeof("getserversResponse") - 1 };
7142 +static unsigned int
7143 +quake3_nat_help(struct ip_conntrack *ct,
7144 + struct ip_conntrack_expect *exp,
7145 + struct ip_nat_info *info,
7146 + enum ip_conntrack_info ctinfo,
7147 + unsigned int hooknum,
7148 + struct sk_buff **pskb)
7150 + struct iphdr *iph = (*pskb)->nh.iph;
7151 + struct udphdr *udph = (void *)iph + iph->ihl * 4;
7152 + struct ip_conntrack_tuple repl;
7153 + int dir = CTINFO2DIR(ctinfo);
7156 + DEBUGP("ip_nat_quake3: quake3_nat_help, direction: %s hook: %s\n",
7157 + dir == IP_CT_DIR_ORIGINAL ? "ORIG" : "REPLY",
7158 + hooknum == NF_IP_POST_ROUTING ? "POSTROUTING"
7159 + : hooknum == NF_IP_PRE_ROUTING ? "PREROUTING"
7160 + : hooknum == NF_IP_LOCAL_OUT ? "OUTPUT" : "???"
7162 + DUMP_TUPLE(&ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple);
7163 + DUMP_TUPLE(&ct->tuplehash[IP_CT_DIR_REPLY].tuple);
7165 + /* Only mangle things once: original direction in POST_ROUTING
7166 + and reply direction on PRE_ROUTING. */
7167 + if (!((hooknum == NF_IP_POST_ROUTING && dir == IP_CT_DIR_ORIGINAL)
7168 + || (hooknum == NF_IP_PRE_ROUTING && dir == IP_CT_DIR_REPLY))) {
7169 + DEBUGP("ip_nat_quake3: Not touching dir %s at hook %s\n",
7170 + dir == IP_CT_DIR_ORIGINAL ? "ORIG" : "REPLY",
7171 + hooknum == NF_IP_POST_ROUTING ? "POSTROUTING"
7172 + : hooknum == NF_IP_PRE_ROUTING ? "PREROUTING"
7173 + : hooknum == NF_IP_LOCAL_OUT ? "OUTPUT" : "????");
7178 + DEBUGP("no conntrack expectation to modify\n");
7182 + if (strnicmp((const char *)udph + 12, quake3s_nat.pattern, quake3s_nat.plen) == 0) {
7183 + for(i=31; /* 8 bytes UDP hdr, 4 bytes filler, 18 bytes "getserversResponse", 1 byte "\" */
7184 + i+6 < ntohs(udph->len);
7186 + DEBUGP("ip_nat_quake3: adding server at offset %u/%u %u.%u.%u.%u:%u\n",
7187 + i, ntohs(udph->len),
7188 + NIPQUAD( (u_int32_t) *( (u_int32_t *)( (int)udph + i ) ) ),
7189 + ntohs((__u16) *( (__u16 *)( (int)udph + i + 4 ) ) ) );
7191 + memset(&repl, 0, sizeof(repl));
7193 + repl.dst.protonum = IPPROTO_UDP;
7194 + repl.src.ip = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.ip;
7195 + repl.dst.ip = *( (u_int32_t *)( (int)udph + i ) );
7196 + repl.dst.u.udp.port = (__u16) *( (__u16 *)( (int)udph + i + 4 ) );
7198 + ip_conntrack_change_expect(exp, &repl);
7204 +static unsigned int
7205 +quake3_nat_expected(struct sk_buff **pskb,
7206 + unsigned int hooknum,
7207 + struct ip_conntrack *ct,
7208 + struct ip_nat_info *info)
7210 + const struct ip_conntrack *master = ct->master->expectant;
7211 + struct ip_nat_multi_range mr;
7212 + u_int32_t newsrcip, newdstip, newip;
7214 + const struct ip_conntrack_tuple *repl =
7215 + &master->tuplehash[IP_CT_DIR_REPLY].tuple;
7216 + struct iphdr *iph = (*pskb)->nh.iph;
7217 + struct udphdr *udph = (void *)iph + iph->ihl*4;
7220 + DEBUGP("ip_nat_quake3: quake3_nat_expected: here we are\n");
7221 + DUMP_TUPLE(&ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple);
7223 + IP_NF_ASSERT(info);
7224 + IP_NF_ASSERT(master);
7225 + IP_NF_ASSERT(!(info->initialized & (1 << HOOK2MANIP(hooknum))));
7227 + newdstip = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.ip;
7228 + newsrcip = master->tuplehash[IP_CT_DIR_REPLY].tuple.dst.ip;
7230 + if (HOOK2MANIP(hooknum) == IP_NAT_MANIP_SRC) {
7232 + DEBUGP("hook: %s orig: %u.%u.%u.%u:%u <-> %u.%u.%u.%u:%u "
7233 + "newsrc: %u.%u.%u.%u\n",
7234 + hooknum == NF_IP_POST_ROUTING ? "POSTROUTING"
7235 + : hooknum == NF_IP_PRE_ROUTING ? "PREROUTING"
7236 + : hooknum == NF_IP_LOCAL_OUT ? "OUTPUT" : "????",
7237 + NIPQUAD((*pskb)->nh.iph->saddr), ntohs(udph->source),
7238 + NIPQUAD((*pskb)->nh.iph->daddr), ntohs(udph->dest),
7243 + DEBUGP("hook: %s orig: %u.%u.%u.%u:%u <-> %u.%u.%u.%u:%u "
7244 + "newdst: %u.%u.%u.%u\n",
7245 + hooknum == NF_IP_POST_ROUTING ? "POSTROUTING"
7246 + : hooknum == NF_IP_PRE_ROUTING ? "PREROUTING"
7247 + : hooknum == NF_IP_LOCAL_OUT ? "OUTPUT" : "????",
7248 + NIPQUAD((*pskb)->nh.iph->saddr), ntohs(udph->source),
7249 + NIPQUAD((*pskb)->nh.iph->daddr), ntohs(udph->dest),
7254 + mr.range[0].flags = IP_NAT_RANGE_MAP_IPS;
7255 + mr.range[0].min_ip = mr.range[0].max_ip = newip;
7257 + return ip_nat_setup_info(ct,&mr,hooknum);
7260 +static struct ip_nat_helper quake3[MAX_PORTS];
7261 +static char quake3_names[MAX_PORTS][13]; /* quake3-65535 */
7263 +static void fini(void)
7267 + for (i = 0 ; i < ports_c; i++) {
7268 + DEBUGP("ip_nat_quake3: unregistering helper for port %d\n", ports[i]);
7269 + ip_nat_helper_unregister(&quake3[i]);
7273 +static int __init init(void)
7279 + ports[0] = QUAKE3_MASTER_PORT;
7281 + for (i = 0 ; (i < MAX_PORTS) && ports[i] ; i++) {
7282 + memset(&quake3[i], 0, sizeof(struct ip_nat_helper));
7284 + quake3[i].tuple.dst.protonum = IPPROTO_UDP;
7285 + quake3[i].tuple.src.u.udp.port = htons(ports[i]);
7286 + quake3[i].mask.dst.protonum = 0xFFFF;
7287 + quake3[i].mask.src.u.udp.port = 0xFFFF;
7288 + quake3[i].help = quake3_nat_help;
7289 + quake3[i].flags = 0;
7290 + quake3[i].me = THIS_MODULE;
7291 + quake3[i].expect = quake3_nat_expected;
7293 + tmpname = &quake3_names[i][0];
7294 + if (ports[i] == QUAKE3_MASTER_PORT)
7295 + sprintf(tmpname, "quake3");
7297 + sprintf(tmpname, "quake3-%d", i);
7298 + quake3[i].name = tmpname;
7300 + DEBUGP("ip_nat_quake3: registering helper for port %d: name %s\n",
7301 + ports[i], quake3[i].name);
7302 + ret = ip_nat_helper_register(&quake3[i]);
7305 + printk("ip_nat_quake3: unable to register helper for port %d\n",
7317 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ip_nat_rtsp.c linux-2.6.6/net/ipv4/netfilter/ip_nat_rtsp.c
7318 --- linux-2.6.6.org/net/ipv4/netfilter/ip_nat_rtsp.c 1970-01-01 01:00:00.000000000 +0100
7319 +++ linux-2.6.6/net/ipv4/netfilter/ip_nat_rtsp.c 2004-05-18 14:28:50.000000000 +0200
7322 + * RTSP extension for TCP NAT alteration
7323 + * (C) 2003 by Tom Marshall <tmarshall@real.com>
7324 + * based on ip_nat_irc.c
7326 + * This program is free software; you can redistribute it and/or
7327 + * modify it under the terms of the GNU General Public License
7328 + * as published by the Free Software Foundation; either version
7329 + * 2 of the License, or (at your option) any later version.
7331 + * Module load syntax:
7332 + * insmod ip_nat_rtsp.o ports=port1,port2,...port<MAX_PORTS>
7333 + * stunaddr=<address>
7334 + * destaction=[auto|strip|none]
7336 + * If no ports are specified, the default will be port 554 only.
7338 + * stunaddr specifies the address used to detect that a client is using STUN.
7339 + * If this address is seen in the destination parameter, it is assumed that
7340 + * the client has already punched a UDP hole in the firewall, so we don't
7341 + * mangle the client_port. If none is specified, it is autodetected. It
7342 + * only needs to be set if you have multiple levels of NAT. It should be
7343 + * set to the external address that the STUN clients detect. Note that in
7344 + * this case, it will not be possible for clients to use UDP with servers
7345 + * between the NATs.
7347 + * If no destaction is specified, auto is used.
7348 + * destaction=auto: strip destination parameter if it is not stunaddr.
7349 + * destaction=strip: always strip destination parameter (not recommended).
7350 + * destaction=none: do not touch destination parameter (not recommended).
7353 +#include <linux/module.h>
7354 +#include <linux/netfilter_ipv4.h>
7355 +#include <linux/ip.h>
7356 +#include <linux/tcp.h>
7357 +#include <linux/kernel.h>
7358 +#include <net/tcp.h>
7359 +#include <linux/netfilter_ipv4/ip_nat.h>
7360 +#include <linux/netfilter_ipv4/ip_nat_helper.h>
7361 +#include <linux/netfilter_ipv4/ip_nat_rule.h>
7362 +#include <linux/netfilter_ipv4/ip_conntrack_rtsp.h>
7363 +#include <linux/netfilter_ipv4/ip_conntrack_helper.h>
7365 +#include <linux/inet.h>
7366 +#include <linux/ctype.h>
7367 +#define NF_NEED_STRNCASECMP
7368 +#define NF_NEED_STRTOU16
7369 +#include <linux/netfilter_helpers.h>
7370 +#define NF_NEED_MIME_NEXTLINE
7371 +#include <linux/netfilter_mime.h>
7373 +#define INFOP(fmt, args...) printk(KERN_INFO "%s: %s: " fmt, __FILE__, __FUNCTION__ , ## args)
7374 +#ifdef IP_NF_RTSP_DEBUG
7375 +#define DEBUGP(fmt, args...) printk(KERN_DEBUG "%s: %s: " fmt, __FILE__, __FUNCTION__ , ## args)
7377 +#define DEBUGP(fmt, args...)
7380 +#define MAX_PORTS 8
7381 +#define DSTACT_AUTO 0
7382 +#define DSTACT_STRIP 1
7383 +#define DSTACT_NONE 2
7385 +static int ports[MAX_PORTS];
7386 +static char* stunaddr = NULL;
7387 +static char* destaction = NULL;
7389 +static int num_ports = 0;
7390 +static u_int32_t extip = 0;
7391 +static int dstact = 0;
7393 +MODULE_AUTHOR("Tom Marshall <tmarshall@real.com>");
7394 +MODULE_DESCRIPTION("RTSP network address translation module");
7395 +MODULE_LICENSE("GPL");
7397 +MODULE_PARM(ports, "1-" __MODULE_STRING(MAX_PORTS) "i");
7398 +MODULE_PARM_DESC(ports, "port numbers of RTSP servers");
7399 +MODULE_PARM(stunaddr, "s");
7400 +MODULE_PARM_DESC(stunaddr, "Address for detecting STUN");
7401 +MODULE_PARM(destaction, "s");
7402 +MODULE_PARM_DESC(destaction, "Action for destination parameter (auto/strip/none)");
7405 +/* protects rtsp part of conntracks */
7406 +DECLARE_LOCK_EXTERN(ip_rtsp_lock);
7408 +#define SKIP_WSPACE(ptr,len,off) while(off < len && isspace(*(ptr+off))) { off++; }
7410 +/*** helper functions ***/
7413 +get_skb_tcpdata(struct sk_buff* skb, char** pptcpdata, uint* ptcpdatalen)
7415 + struct iphdr* iph = (struct iphdr*)skb->nh.iph;
7416 + struct tcphdr* tcph = (struct tcphdr*)((char*)iph + iph->ihl*4);
7418 + *pptcpdata = (char*)tcph + tcph->doff*4;
7419 + *ptcpdatalen = ((char*)skb->h.raw + skb->len) - *pptcpdata;
7422 +/*** nat functions ***/
7425 + * Mangle the "Transport:" header:
7426 + * - Replace all occurences of "client_port=<spec>"
7427 + * - Handle destination parameter
7430 + * ct, ctinfo = conntrack context
7432 + * tranoff = Transport header offset from TCP data
7433 + * tranlen = Transport header length (incl. CRLF)
7434 + * rport_lo = replacement low port (host endian)
7435 + * rport_hi = replacement high port (host endian)
7437 + * Returns packet size difference.
7439 + * Assumes that a complete transport header is present, ending with CR or LF
7442 +rtsp_mangle_tran(struct ip_conntrack* ct, enum ip_conntrack_info ctinfo,
7443 + struct ip_conntrack_expect* exp,
7444 + struct sk_buff** pskb, uint tranoff, uint tranlen)
7449 + char rbuf1[16]; /* Replacement buffer (one port) */
7450 + uint rbuf1len; /* Replacement len (one port) */
7451 + char rbufa[16]; /* Replacement buffer (all ports) */
7452 + uint rbufalen; /* Replacement len (all ports) */
7454 + u_int16_t loport, hiport;
7456 + uint diff; /* Number of bytes we removed */
7458 + struct ip_ct_rtsp_expect* prtspexp = &exp->help.exp_rtsp_info;
7459 + struct ip_conntrack_tuple t;
7461 + char szextaddr[15+1];
7465 + get_skb_tcpdata(*pskb, &ptcp, &tcplen);
7466 + ptran = ptcp+tranoff;
7468 + if (tranoff+tranlen > tcplen || tcplen-tranoff < tranlen ||
7469 + tranlen < 10 || !iseol(ptran[tranlen-1]) ||
7470 + nf_strncasecmp(ptran, "Transport:", 10) != 0)
7472 + INFOP("sanity check failed\n");
7476 + SKIP_WSPACE(ptcp+tranoff, tranlen, off);
7478 + newip = ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.ip;
7482 + extaddrlen = extip ? sprintf(szextaddr, "%u.%u.%u.%u", NIPQUAD(extip))
7483 + : sprintf(szextaddr, "%u.%u.%u.%u", NIPQUAD(newip));
7484 + DEBUGP("stunaddr=%s (%s)\n", szextaddr, (extip?"forced":"auto"));
7486 + rbuf1len = rbufalen = 0;
7487 + switch (prtspexp->pbtype)
7490 + for (loport = prtspexp->loport; loport != 0; loport++) /* XXX: improper wrap? */
7492 + t.dst.u.udp.port = htons(loport);
7493 + if (ip_conntrack_change_expect(exp, &t) == 0)
7495 + DEBUGP("using port %hu\n", loport);
7501 + rbuf1len = sprintf(rbuf1, "%hu", loport);
7502 + rbufalen = sprintf(rbufa, "%hu", loport);
7506 + for (loport = prtspexp->loport; loport != 0; loport += 2) /* XXX: improper wrap? */
7508 + t.dst.u.udp.port = htons(loport);
7509 + if (ip_conntrack_change_expect(exp, &t) == 0)
7511 + hiport = loport + ~exp->mask.dst.u.udp.port;
7512 + DEBUGP("using ports %hu-%hu\n", loport, hiport);
7518 + rbuf1len = sprintf(rbuf1, "%hu", loport);
7519 + rbufalen = sprintf(rbufa, "%hu-%hu", loport, loport+1);
7523 + for (loport = prtspexp->loport; loport != 0; loport++) /* XXX: improper wrap? */
7525 + t.dst.u.udp.port = htons(loport);
7526 + if (ip_conntrack_change_expect(exp, &t) == 0)
7528 + DEBUGP("using port %hu (1 of 2)\n", loport);
7532 + for (hiport = prtspexp->hiport; hiport != 0; hiport++) /* XXX: improper wrap? */
7534 + t.dst.u.udp.port = htons(hiport);
7535 + if (ip_conntrack_change_expect(exp, &t) == 0)
7537 + DEBUGP("using port %hu (2 of 2)\n", hiport);
7541 + if (loport != 0 && hiport != 0)
7543 + rbuf1len = sprintf(rbuf1, "%hu", loport);
7544 + if (hiport == loport+1)
7546 + rbufalen = sprintf(rbufa, "%hu-%hu", loport, hiport);
7550 + rbufalen = sprintf(rbufa, "%hu/%hu", loport, hiport);
7556 + if (rbuf1len == 0)
7558 + return 0; /* cannot get replacement port(s) */
7561 + /* Transport: tran;field;field=val,tran;field;field=val,... */
7562 + while (off < tranlen)
7565 + const char* pparamend;
7566 + uint nextparamoff;
7568 + pparamend = memchr(ptran+off, ',', tranlen-off);
7569 + pparamend = (pparamend == NULL) ? ptran+tranlen : pparamend+1;
7570 + nextparamoff = pparamend-ptcp;
7573 + * We pass over each param twice. On the first pass, we look for a
7574 + * destination= field. It is handled by the security policy. If it
7575 + * is present, allowed, and equal to our external address, we assume
7576 + * that STUN is being used and we leave the client_port= field alone.
7580 + while (off < nextparamoff)
7582 + const char* pfieldend;
7583 + uint nextfieldoff;
7585 + pfieldend = memchr(ptran+off, ';', nextparamoff-off);
7586 + nextfieldoff = (pfieldend == NULL) ? nextparamoff : pfieldend-ptran+1;
7588 + if (dstact != DSTACT_NONE && strncmp(ptran+off, "destination=", 12) == 0)
7590 + if (strncmp(ptran+off+12, szextaddr, extaddrlen) == 0)
7594 + if (dstact == DSTACT_STRIP || (dstact == DSTACT_AUTO && !is_stun))
7596 + diff = nextfieldoff-off;
7597 + if (!ip_nat_mangle_tcp_packet(pskb, ct, ctinfo,
7598 + off, diff, NULL, 0))
7600 + /* mangle failed, all we can do is bail */
7603 + get_skb_tcpdata(*pskb, &ptcp, &tcplen);
7604 + ptran = ptcp+tranoff;
7606 + nextparamoff -= diff;
7607 + nextfieldoff -= diff;
7611 + off = nextfieldoff;
7618 + while (off < nextparamoff)
7620 + const char* pfieldend;
7621 + uint nextfieldoff;
7623 + pfieldend = memchr(ptran+off, ';', nextparamoff-off);
7624 + nextfieldoff = (pfieldend == NULL) ? nextparamoff : pfieldend-ptran+1;
7626 + if (strncmp(ptran+off, "client_port=", 12) == 0)
7632 + char* rbuf = rbuf1;
7633 + uint rbuflen = rbuf1len;
7636 + origoff = (ptran-ptcp)+off;
7638 + numlen = nf_strtou16(ptran+off, &port);
7640 + origlen += numlen;
7641 + if (port != prtspexp->loport)
7643 + DEBUGP("multiple ports found, port %hu ignored\n", port);
7647 + if (ptran[off] == '-' || ptran[off] == '/')
7651 + numlen = nf_strtou16(ptran+off, &port);
7653 + origlen += numlen;
7655 + rbuflen = rbufalen;
7659 + * note we cannot just memcpy() if the sizes are the same.
7660 + * the mangle function does skb resizing, checks for a
7661 + * cloned skb, and updates the checksums.
7663 + * parameter 4 below is offset from start of tcp data.
7665 + diff = origlen-rbuflen;
7666 + if (!ip_nat_mangle_tcp_packet(pskb, ct, ctinfo,
7667 + origoff, origlen, rbuf, rbuflen))
7669 + /* mangle failed, all we can do is bail */
7672 + get_skb_tcpdata(*pskb, &ptcp, &tcplen);
7673 + ptran = ptcp+tranoff;
7675 + nextparamoff -= diff;
7676 + nextfieldoff -= diff;
7680 + off = nextfieldoff;
7683 + off = nextparamoff;
7689 +static unsigned int
7690 +expected(struct sk_buff **pskb, uint hooknum, struct ip_conntrack* ct, struct ip_nat_info* info)
7692 + struct ip_nat_multi_range mr;
7693 + u_int32_t newdstip, newsrcip, newip;
7695 + struct ip_conntrack *master = master_ct(ct);
7697 + IP_NF_ASSERT(info);
7698 + IP_NF_ASSERT(master);
7700 + IP_NF_ASSERT(!(info->initialized & (1 << HOOK2MANIP(hooknum))));
7702 + newdstip = master->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.ip;
7703 + newsrcip = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.ip;
7704 + newip = (HOOK2MANIP(hooknum) == IP_NAT_MANIP_SRC) ? newsrcip : newdstip;
7706 + DEBUGP("newsrcip=%u.%u.%u.%u, newdstip=%u.%u.%u.%u, newip=%u.%u.%u.%u\n",
7707 + NIPQUAD(newsrcip), NIPQUAD(newdstip), NIPQUAD(newip));
7710 + /* We don't want to manip the per-protocol, just the IPs. */
7711 + mr.range[0].flags = IP_NAT_RANGE_MAP_IPS;
7712 + mr.range[0].min_ip = mr.range[0].max_ip = newip;
7714 + return ip_nat_setup_info(ct, &mr, hooknum);
7718 +help_out(struct ip_conntrack* ct, enum ip_conntrack_info ctinfo,
7719 + struct ip_conntrack_expect* exp, struct sk_buff** pskb)
7729 + struct iphdr* iph = (struct iphdr*)(*pskb)->nh.iph;
7730 + struct tcphdr* tcph = (struct tcphdr*)((void*)iph + iph->ihl*4);
7732 + struct ip_ct_rtsp_expect* prtspexp = &exp->help.exp_rtsp_info;
7734 + get_skb_tcpdata(*pskb, &ptcp, &tcplen);
7736 + hdrsoff = exp->seq - ntohl(tcph->seq);
7737 + hdrslen = prtspexp->len;
7740 + while (nf_mime_nextline(ptcp, hdrsoff+hdrslen, &off, &lineoff, &linelen))
7746 + if (off > hdrsoff+hdrslen)
7748 + INFOP("!! overrun !!");
7751 + DEBUGP("hdr: len=%u, %.*s", linelen, (int)linelen, ptcp+lineoff);
7753 + if (nf_strncasecmp(ptcp+lineoff, "Transport:", 10) == 0)
7755 + uint oldtcplen = tcplen;
7756 + if (!rtsp_mangle_tran(ct, ctinfo, exp, pskb, lineoff, linelen))
7760 + get_skb_tcpdata(*pskb, &ptcp, &tcplen);
7761 + hdrslen -= (oldtcplen-tcplen);
7762 + off -= (oldtcplen-tcplen);
7763 + lineoff -= (oldtcplen-tcplen);
7764 + linelen -= (oldtcplen-tcplen);
7765 + DEBUGP("rep: len=%u, %.*s", linelen, (int)linelen, ptcp+lineoff);
7773 +help_in(struct ip_conntrack* ct, enum ip_conntrack_info ctinfo,
7774 + struct ip_conntrack_expect* exp, struct sk_buff** pskb)
7776 + /* XXX: unmangle */
7781 +help(struct ip_conntrack* ct,
7782 + struct ip_conntrack_expect* exp,
7783 + struct ip_nat_info* info,
7784 + enum ip_conntrack_info ctinfo,
7785 + unsigned int hooknum,
7786 + struct sk_buff** pskb)
7788 + struct iphdr* iph = (struct iphdr*)(*pskb)->nh.iph;
7789 + struct tcphdr* tcph = (struct tcphdr*)((char*)iph + iph->ihl * 4);
7792 + struct ip_ct_rtsp_expect* ct_rtsp_info;
7793 + int rc = NF_ACCEPT;
7795 + if (ct == NULL || exp == NULL || info == NULL || pskb == NULL)
7797 + DEBUGP("!! null ptr (%p,%p,%p,%p) !!\n", ct, exp, info, pskb);
7801 + ct_rtsp_info = &exp->help.exp_rtsp_info;
7804 + * Only mangle things once: original direction in POST_ROUTING
7805 + * and reply direction on PRE_ROUTING.
7807 + dir = CTINFO2DIR(ctinfo);
7808 + if (!((hooknum == NF_IP_POST_ROUTING && dir == IP_CT_DIR_ORIGINAL)
7809 + || (hooknum == NF_IP_PRE_ROUTING && dir == IP_CT_DIR_REPLY)))
7811 + DEBUGP("Not touching dir %s at hook %s\n",
7812 + dir == IP_CT_DIR_ORIGINAL ? "ORIG" : "REPLY",
7813 + hooknum == NF_IP_POST_ROUTING ? "POSTROUTING"
7814 + : hooknum == NF_IP_PRE_ROUTING ? "PREROUTING"
7815 + : hooknum == NF_IP_LOCAL_OUT ? "OUTPUT" : "???");
7818 + DEBUGP("got beyond not touching\n");
7820 + datalen = (*pskb)->len - iph->ihl * 4 - tcph->doff * 4;
7822 + LOCK_BH(&ip_rtsp_lock);
7823 + /* Ensure the packet contains all of the marked data */
7824 + if (!between(exp->seq + ct_rtsp_info->len,
7825 + ntohl(tcph->seq), ntohl(tcph->seq) + datalen))
7827 + /* Partial retransmission? Probably a hacker. */
7828 + if (net_ratelimit())
7830 + INFOP("partial packet %u/%u in %u/%u\n",
7831 + exp->seq, ct_rtsp_info->len, ntohl(tcph->seq), ntohl(tcph->seq) + datalen);
7833 + UNLOCK_BH(&ip_rtsp_lock);
7839 + case IP_CT_DIR_ORIGINAL:
7840 + rc = help_out(ct, ctinfo, exp, pskb);
7842 + case IP_CT_DIR_REPLY:
7843 + rc = help_in(ct, ctinfo, exp, pskb);
7846 + UNLOCK_BH(&ip_rtsp_lock);
7851 +static struct ip_nat_helper ip_nat_rtsp_helpers[MAX_PORTS];
7852 +static char rtsp_names[MAX_PORTS][10];
7854 +/* This function is intentionally _NOT_ defined as __exit */
7860 + for (i = 0; i < num_ports; i++)
7862 + DEBUGP("unregistering helper for port %d\n", ports[i]);
7863 + ip_nat_helper_unregister(&ip_nat_rtsp_helpers[i]);
7872 + struct ip_nat_helper* hlpr;
7875 + printk("ip_nat_rtsp v" IP_NF_RTSP_VERSION " loading\n");
7877 + if (ports[0] == 0)
7879 + ports[0] = RTSP_PORT;
7882 + for (i = 0; (i < MAX_PORTS) && ports[i] != 0; i++)
7884 + hlpr = &ip_nat_rtsp_helpers[i];
7885 + memset(hlpr, 0, sizeof(struct ip_nat_helper));
7887 + hlpr->tuple.dst.protonum = IPPROTO_TCP;
7888 + hlpr->tuple.src.u.tcp.port = htons(ports[i]);
7889 + hlpr->mask.src.u.tcp.port = 0xFFFF;
7890 + hlpr->mask.dst.protonum = 0xFFFF;
7891 + hlpr->help = help;
7893 + hlpr->me = THIS_MODULE;
7894 + hlpr->expect = expected;
7896 + tmpname = &rtsp_names[i][0];
7897 + if (ports[i] == RTSP_PORT)
7899 + sprintf(tmpname, "rtsp");
7903 + sprintf(tmpname, "rtsp-%d", i);
7905 + hlpr->name = tmpname;
7907 + DEBUGP("registering helper for port %d: name %s\n", ports[i], hlpr->name);
7908 + ret = ip_nat_helper_register(hlpr);
7912 + printk("ip_nat_rtsp: error registering helper for port %d\n", ports[i]);
7918 + if (stunaddr != NULL)
7920 + extip = in_aton(stunaddr);
7922 + if (destaction != NULL)
7924 + if (strcmp(destaction, "auto") == 0)
7926 + dstact = DSTACT_AUTO;
7928 + if (strcmp(destaction, "strip") == 0)
7930 + dstact = DSTACT_STRIP;
7932 + if (strcmp(destaction, "none") == 0)
7934 + dstact = DSTACT_NONE;
7942 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ip_nat_rule.c linux-2.6.6/net/ipv4/netfilter/ip_nat_rule.c
7943 --- linux-2.6.6.org/net/ipv4/netfilter/ip_nat_rule.c 2004-05-10 04:32:28.000000000 +0200
7944 +++ linux-2.6.6/net/ipv4/netfilter/ip_nat_rule.c 2004-05-18 14:28:50.000000000 +0200
7947 sizeof(struct ipt_entry),
7948 sizeof(struct ipt_standard),
7949 - 0, { 0, 0 }, { } },
7950 + 0, NULL, 0, { 0, 0 }, { } },
7951 { { { { IPT_ALIGN(sizeof(struct ipt_standard_target)), "" } }, { } },
7956 sizeof(struct ipt_entry),
7957 sizeof(struct ipt_standard),
7958 - 0, { 0, 0 }, { } },
7959 + 0, NULL, 0, { 0, 0 }, { } },
7960 { { { { IPT_ALIGN(sizeof(struct ipt_standard_target)), "" } }, { } },
7965 sizeof(struct ipt_entry),
7966 sizeof(struct ipt_standard),
7967 - 0, { 0, 0 }, { } },
7968 + 0, NULL, 0, { 0, 0 }, { } },
7969 { { { { IPT_ALIGN(sizeof(struct ipt_standard_target)), "" } }, { } },
7974 sizeof(struct ipt_entry),
7975 sizeof(struct ipt_error),
7976 - 0, { 0, 0 }, { } },
7977 + 0, NULL, 0, { 0, 0 }, { } },
7978 { { { { IPT_ALIGN(sizeof(struct ipt_error_target)), IPT_ERROR_TARGET } },
7981 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ip_nat_standalone.c linux-2.6.6/net/ipv4/netfilter/ip_nat_standalone.c
7982 --- linux-2.6.6.org/net/ipv4/netfilter/ip_nat_standalone.c 2004-05-10 04:33:12.000000000 +0200
7983 +++ linux-2.6.6/net/ipv4/netfilter/ip_nat_standalone.c 2004-05-18 14:28:50.000000000 +0200
7984 @@ -175,6 +175,45 @@
7985 return do_bindings(ct, ctinfo, info, hooknum, pskb);
7988 +struct nat_route_key
7997 +nat_route_key_get(struct sk_buff *skb, struct nat_route_key *key, int which)
7999 + struct iphdr *iph = skb->nh.iph;
8001 + key->addr = which ? iph->daddr : iph->saddr;
8004 + if (iph->protocol == IPPROTO_TCP || iph->protocol == IPPROTO_UDP) {
8005 + u_int16_t *ports = (u_int16_t *)(skb->nh.raw + iph->ihl*4);
8006 + key->port = ports[which];
8012 +nat_route_key_compare(struct sk_buff *skb, struct nat_route_key *key, int which)
8014 + struct iphdr *iph = skb->nh.iph;
8016 + if (key->addr != (which ? iph->daddr : iph->saddr))
8019 + if (iph->protocol == IPPROTO_TCP || iph->protocol == IPPROTO_UDP) {
8020 + u_int16_t *ports = (u_int16_t *)(skb->nh.raw + iph->ihl*4);
8021 + if (key->port != ports[which])
8028 ip_nat_out(unsigned int hooknum,
8029 struct sk_buff **pskb,
8031 const struct net_device *out,
8032 int (*okfn)(struct sk_buff *))
8034 + struct nat_route_key key;
8037 /* root is playing with raw sockets. */
8038 if ((*pskb)->len < sizeof(struct iphdr)
8039 || (*pskb)->nh.iph->ihl * 4 < sizeof(struct iphdr))
8040 @@ -204,7 +246,29 @@
8044 - return ip_nat_fn(hooknum, pskb, in, out, okfn);
8045 + nat_route_key_get(*pskb, &key, 0);
8046 + ret = ip_nat_fn(hooknum, pskb, in, out, okfn);
8048 + if (ret != NF_DROP && ret != NF_STOLEN
8049 + && nat_route_key_compare(*pskb, &key, 0)) {
8050 + if (ip_route_me_harder(pskb) != 0)
8054 + * POST_ROUTING hook is called with fixed outfn, we need
8055 + * to manually confirm the packet and direct it to the
8056 + * transformers if a policy matches.
8058 + else if ((*pskb)->dst->xfrm != NULL) {
8059 + ret = ip_conntrack_confirm(*pskb);
8060 + if (ret != NF_DROP) {
8061 + dst_output(*pskb);
8070 #ifdef CONFIG_IP_NF_NAT_LOCAL
8072 const struct net_device *out,
8073 int (*okfn)(struct sk_buff *))
8075 - u_int32_t saddr, daddr;
8076 + struct nat_route_key key;
8079 /* root is playing with raw sockets. */
8080 @@ -223,14 +287,14 @@
8081 || (*pskb)->nh.iph->ihl * 4 < sizeof(struct iphdr))
8084 - saddr = (*pskb)->nh.iph->saddr;
8085 - daddr = (*pskb)->nh.iph->daddr;
8087 + nat_route_key_get(*pskb, &key, 1);
8088 ret = ip_nat_fn(hooknum, pskb, in, out, okfn);
8090 if (ret != NF_DROP && ret != NF_STOLEN
8091 - && ((*pskb)->nh.iph->saddr != saddr
8092 - || (*pskb)->nh.iph->daddr != daddr))
8093 - return ip_route_me_harder(pskb) == 0 ? ret : NF_DROP;
8094 + && nat_route_key_compare(*pskb, &key, 1)) {
8095 + if (ip_route_me_harder(pskb) != 0)
8101 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ip_nat_talk.c linux-2.6.6/net/ipv4/netfilter/ip_nat_talk.c
8102 --- linux-2.6.6.org/net/ipv4/netfilter/ip_nat_talk.c 1970-01-01 01:00:00.000000000 +0100
8103 +++ linux-2.6.6/net/ipv4/netfilter/ip_nat_talk.c 2004-05-18 14:28:50.000000000 +0200
8106 + * talk extension for UDP NAT alteration.
8107 + * Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
8109 + * This program is free software; you can redistribute it and/or
8110 + * modify it under the terms of the GNU General Public License
8111 + * as published by the Free Software Foundation; either version
8112 + * 2 of the License, or (at your option) any later version.
8114 + * Module load syntax:
8115 + * insmod ip_nat_talk.o talk=[0|1] ntalk=[0|1] ntalk2=[0|1]
8117 + * talk=[0|1] disable|enable old talk support
8118 + * ntalk=[0|1] disable|enable ntalk support
8119 + * ntalk2=[0|1] disable|enable ntalk2 support
8121 + * The default is talk=1 ntalk=1 ntalk2=1
8125 +#include <linux/module.h>
8126 +#include <linux/netfilter_ipv4.h>
8127 +#include <linux/ip.h>
8128 +#include <linux/udp.h>
8129 +#include <linux/kernel.h>
8130 +#include <net/tcp.h>
8131 +#include <net/udp.h>
8133 +#include <linux/netfilter_ipv4/ip_nat.h>
8134 +#include <linux/netfilter_ipv4/ip_nat_helper.h>
8135 +#include <linux/netfilter_ipv4/ip_nat_rule.h>
8136 +#include <linux/netfilter_ipv4/ip_conntrack_talk.h>
8137 +#include <linux/netfilter_ipv4/ip_conntrack_helper.h>
8139 +/* Default all talk protocols are supported */
8140 +static int talk = 1;
8141 +static int ntalk = 1;
8142 +static int ntalk2 = 1;
8143 +MODULE_AUTHOR("Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>");
8144 +MODULE_DESCRIPTION("talk network address translation module");
8146 +MODULE_PARM(talk, "i");
8147 +MODULE_PARM_DESC(talk, "support (old) talk protocol");
8148 +MODULE_PARM(ntalk, "i");
8149 +MODULE_PARM_DESC(ntalk, "support ntalk protocol");
8150 +MODULE_PARM(ntalk2, "i");
8151 +MODULE_PARM_DESC(ntalk2, "support ntalk2 protocol");
8155 +#define DEBUGP printk
8156 +#define IP_NAT_TALK_DEBUG
8158 +#define DEBUGP(format, args...)
8161 +/* FIXME: Time out? --RR */
8164 +mangle_packet(struct sk_buff **pskb,
8165 + struct ip_conntrack *ct,
8168 + struct talk_addr *addr,
8169 + struct talk_addr *ctl_addr)
8171 + struct iphdr *iph = (*pskb)->nh.iph;
8172 + struct udphdr *udph = (void *)iph + iph->ihl * 4;
8173 + size_t udplen = (*pskb)->len - iph->ihl * 4;
8175 + /* Fortunately talk sends a structure with the address and
8176 + port in it. The size of the packet won't change. */
8178 + if (ctl_addr == NULL) {
8180 + if (addr->ta_addr == INADDR_ANY)
8182 + DEBUGP("ip_nat_talk_mangle_packet: response orig %u.%u.%u.%u:%u, inserting %u.%u.%u.%u:%u\n",
8183 + NIPQUAD(addr->ta_addr), ntohs(addr->ta_port),
8184 + NIPQUAD(newip), ntohs(port));
8185 + addr->ta_addr = newip;
8186 + addr->ta_port = port;
8189 + if (addr->ta_addr != INADDR_ANY) {
8190 + /* Change address inside packet to match way we're mapping
8191 + this connection. */
8192 + DEBUGP("ip_nat_talk_mangle_packet: message orig addr %u.%u.%u.%u:%u, inserting %u.%u.%u.%u:%u\n",
8193 + NIPQUAD(addr->ta_addr), ntohs(addr->ta_port),
8194 + NIPQUAD(ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.ip),
8195 + ntohs(addr->ta_port));
8196 + addr->ta_addr = ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.ip;
8198 + DEBUGP("ip_nat_talk_mangle_packet: message orig ctl_addr %u.%u.%u.%u:%u, inserting %u.%u.%u.%u:%u\n",
8199 + NIPQUAD(ctl_addr->ta_addr), ntohs(ctl_addr->ta_port),
8200 + NIPQUAD(newip), ntohs(port));
8201 + ctl_addr->ta_addr = newip;
8202 + ctl_addr->ta_port = port;
8205 + /* Fix checksums */
8206 + (*pskb)->csum = csum_partial((char *)udph + sizeof(struct udphdr), udplen - sizeof(struct udphdr), 0);
8208 + udph->check = csum_tcpudp_magic(iph->saddr, iph->daddr, udplen, IPPROTO_UDP,
8209 + csum_partial((char *)udph, sizeof(struct udphdr), (*pskb)->csum));
8211 + ip_send_check(iph);
8215 +static int talk_help_msg(struct ip_conntrack *ct,
8216 + struct sk_buff **pskb,
8218 + struct talk_addr *addr,
8219 + struct talk_addr *ctl_addr)
8224 + unsigned int verdict = NF_ACCEPT;
8226 + DEBUGP("ip_nat_talk_help_msg: addr: %u.%u.%u.%u:%u, ctl_addr: %u.%u.%u.%u:%u, type %d\n",
8227 + NIPQUAD(addr->ta_addr), ntohs(addr->ta_port),
8228 + NIPQUAD(ctl_addr->ta_addr), ntohs(ctl_addr->ta_port),
8231 + /* Change address inside packet to match way we're mapping
8232 + this connection. */
8233 + newip = ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.ip;
8234 + port = ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.u.udp.port;
8235 + DEBUGP("ip_nat_talk_help_msg: inserting: %u.%u.%u.%u:%u\n",
8236 + NIPQUAD(newip), ntohs(port));
8238 + if (!mangle_packet(pskb, ct, newip, port, addr, ctl_addr))
8239 + verdict = NF_DROP;
8244 +static int talk_help_response(struct ip_conntrack *ct,
8245 + struct ip_conntrack_expect *exp,
8246 + struct sk_buff **pskb,
8249 + struct talk_addr *addr)
8253 + struct ip_conntrack_tuple t;
8254 + struct ip_ct_talk_expect *ct_talk_info;
8256 + DEBUGP("ip_nat_talk_help_response: addr: %u.%u.%u.%u:%u, type %d answer %d\n",
8257 + NIPQUAD(addr->ta_addr), ntohs(addr->ta_port),
8260 + LOCK_BH(&ip_talk_lock);
8261 + ct_talk_info = &exp->help.exp_talk_info;
8263 + if (!(answer == SUCCESS
8264 + && (type == LOOK_UP || type == ANNOUNCE)
8265 + && exp != NULL)) {
8266 + UNLOCK_BH(&ip_talk_lock);
8270 + DEBUGP("ip_nat_talk_help_response: talkinfo port %u (%s)\n",
8271 + ntohs(ct_talk_info->port),
8272 + type == LOOK_UP ? "LOOK_UP" : "ANNOUNCE");
8274 + /* Change address inside packet to match way we're mapping
8275 + this connection. */
8276 + newip = ct->tuplehash[type == LOOK_UP ? IP_CT_DIR_ORIGINAL :
8277 + IP_CT_DIR_REPLY].tuple.dst.ip;
8278 + /* We can read expect here without conntrack lock, since it's
8279 + only set in ip_conntrack_talk , with ip_talk_lock held
8284 + /* Try to get same port: if not, try to change it. */
8285 + for (port = ntohs(ct_talk_info->port); port != 0; port++) {
8286 + if (type == LOOK_UP)
8287 + t.dst.u.tcp.port = htons(port);
8289 + t.dst.u.udp.port = htons(port);
8291 + if (ip_conntrack_change_expect(exp, &t) == 0) {
8292 + DEBUGP("ip_nat_talk_help_response: using %u.%u.%u.%u:%u\n", NIPQUAD(newip), port);
8296 + UNLOCK_BH(&ip_talk_lock);
8298 + if (port == 0 || !mangle_packet(pskb, ct, newip, htons(port), addr, NULL))
8304 +static unsigned int talk_help(struct ip_conntrack *ct,
8305 + struct ip_conntrack_expect *exp,
8306 + struct ip_nat_info *info,
8307 + enum ip_conntrack_info ctinfo,
8308 + unsigned int hooknum,
8309 + struct sk_buff **pskb,
8312 + struct iphdr *iph = (*pskb)->nh.iph;
8313 + struct udphdr *udph = (void *)iph + iph->ihl * 4;
8314 + unsigned int udplen = (*pskb)->len - iph->ihl * 4;
8315 + char *data = (char *)udph + sizeof(struct udphdr);
8318 + /* Only mangle things once: original direction in POST_ROUTING
8319 + and reply direction on PRE_ROUTING. */
8320 + dir = CTINFO2DIR(ctinfo);
8321 + if (!((hooknum == NF_IP_POST_ROUTING && dir == IP_CT_DIR_ORIGINAL)
8322 + || (hooknum == NF_IP_PRE_ROUTING && dir == IP_CT_DIR_REPLY))) {
8323 + DEBUGP("ip_nat_talk_help: Not touching dir %s at hook %s\n",
8324 + dir == IP_CT_DIR_ORIGINAL ? "ORIG" : "REPLY",
8325 + hooknum == NF_IP_POST_ROUTING ? "POSTROUTING"
8326 + : hooknum == NF_IP_PRE_ROUTING ? "PREROUTING"
8327 + : hooknum == NF_IP_LOCAL_OUT ? "OUTPUT" : "???");
8330 + DEBUGP("ip_nat_talk_help: dir %s at hook %s, %u.%u.%u.%u:%u->%u.%u.%u.%u:%u, talk port %d\n",
8331 + dir == IP_CT_DIR_ORIGINAL ? "ORIG" : "REPLY",
8332 + hooknum == NF_IP_POST_ROUTING ? "POSTROUTING"
8333 + : hooknum == NF_IP_PRE_ROUTING ? "PREROUTING"
8334 + : hooknum == NF_IP_LOCAL_OUT ? "OUTPUT" : "???",
8335 + NIPQUAD(iph->saddr), ntohs(udph->source),
8336 + NIPQUAD(iph->daddr), ntohs(udph->dest),
8339 + /* Because conntrack does not drop packets, checking must be repeated here... */
8340 + if (talk_port == TALK_PORT) {
8341 + if (dir == IP_CT_DIR_ORIGINAL
8342 + && udplen == sizeof(struct udphdr) + sizeof(struct talk_msg))
8343 + return talk_help_msg(ct, pskb,
8344 + ((struct talk_msg *)data)->type,
8345 + &(((struct talk_msg *)data)->addr),
8346 + &(((struct talk_msg *)data)->ctl_addr));
8347 + else if (dir == IP_CT_DIR_REPLY
8348 + && udplen == sizeof(struct udphdr) + sizeof(struct talk_response))
8349 + return talk_help_response(ct, exp, pskb,
8350 + ((struct talk_response *)data)->type,
8351 + ((struct talk_response *)data)->answer,
8352 + &(((struct talk_response *)data)->addr));
8354 + DEBUGP("ip_nat_talk_help: not talk %s, datalen %u != %u\n",
8355 + dir == IP_CT_DIR_ORIGINAL ? "message" : "response",
8356 + (unsigned)udplen - sizeof(struct udphdr),
8357 + dir == IP_CT_DIR_ORIGINAL ? sizeof(struct talk_msg) : sizeof(struct talk_response));
8361 + if (dir == IP_CT_DIR_ORIGINAL) {
8363 + && udplen == sizeof(struct udphdr) + sizeof(struct ntalk_msg)
8364 + && ((struct ntalk_msg *)data)->vers == NTALK_VERSION)
8365 + return talk_help_msg(ct, pskb,
8366 + ((struct ntalk_msg *)data)->type,
8367 + &(((struct ntalk_msg *)data)->addr),
8368 + &(((struct ntalk_msg *)data)->ctl_addr));
8370 + && udplen >= sizeof(struct udphdr) + sizeof(struct ntalk2_msg)
8371 + && ((struct ntalk2_msg *)data)->vers == NTALK2_VERSION
8372 + && udplen == sizeof(struct udphdr)
8373 + + sizeof(struct ntalk2_msg)
8374 + + ((struct ntalk2_msg *)data)->extended)
8375 + return talk_help_msg(ct, pskb,
8376 + ((struct ntalk2_msg *)data)->type,
8377 + &(((struct ntalk2_msg *)data)->addr),
8378 + &(((struct ntalk2_msg *)data)->ctl_addr));
8380 + DEBUGP("ip_nat_talk_help: not ntalk/ntalk2 message, datalen %u != %u or %u + max 256\n",
8381 + (unsigned)udplen - sizeof(struct udphdr),
8382 + sizeof(struct ntalk_msg), sizeof(struct ntalk2_msg));
8387 + && udplen == sizeof(struct udphdr) + sizeof(struct ntalk_response)
8388 + && ((struct ntalk_response *)data)->vers == NTALK_VERSION)
8389 + return talk_help_response(ct, exp, pskb,
8390 + ((struct ntalk_response *)data)->type,
8391 + ((struct ntalk_response *)data)->answer,
8392 + &(((struct ntalk_response *)data)->addr));
8394 + && udplen >= sizeof(struct udphdr) + sizeof(struct ntalk2_response)
8395 + && ((struct ntalk2_response *)data)->vers == NTALK2_VERSION)
8396 + return talk_help_response(ct, exp, pskb,
8397 + ((struct ntalk2_response *)data)->type,
8398 + ((struct ntalk2_response *)data)->answer,
8399 + &(((struct ntalk2_response *)data)->addr));
8401 + DEBUGP("ip_nat_talk_help: not ntalk/ntalk2 response, datalen %u != %u or %u + max 256\n",
8402 + (unsigned)udplen - sizeof(struct udphdr),
8403 + sizeof(struct ntalk_response), sizeof(struct ntalk2_response));
8410 +static unsigned int help(struct ip_conntrack *ct,
8411 + struct ip_conntrack_expect *exp,
8412 + struct ip_nat_info *info,
8413 + enum ip_conntrack_info ctinfo,
8414 + unsigned int hooknum,
8415 + struct sk_buff **pskb)
8417 + return talk_help(ct, exp, info, ctinfo, hooknum, pskb, TALK_PORT);
8420 +static unsigned int nhelp(struct ip_conntrack *ct,
8421 + struct ip_conntrack_expect *exp,
8422 + struct ip_nat_info *info,
8423 + enum ip_conntrack_info ctinfo,
8424 + unsigned int hooknum,
8425 + struct sk_buff **pskb)
8427 + return talk_help(ct, exp, info, ctinfo, hooknum, pskb, NTALK_PORT);
8430 +static unsigned int
8431 +talk_nat_expected(struct sk_buff **pskb,
8432 + unsigned int hooknum,
8433 + struct ip_conntrack *ct,
8434 + struct ip_nat_info *info);
8436 +static struct ip_nat_helper talk_helpers[2] =
8437 + { { { NULL, NULL },
8438 + "talk", /* name */
8439 + IP_NAT_HELPER_F_ALWAYS, /* flags */
8440 + THIS_MODULE, /* module */
8441 + { { 0, { .udp = { __constant_htons(TALK_PORT) } } }, /* tuple */
8442 + { 0, { 0 }, IPPROTO_UDP } },
8443 + { { 0, { .udp = { 0xFFFF } } }, /* mask */
8444 + { 0, { 0 }, 0xFFFF } },
8445 + help, /* helper */
8446 + talk_nat_expected }, /* expectfn */
8448 + "ntalk", /* name */
8449 + IP_NAT_HELPER_F_ALWAYS, /* flags */
8450 + THIS_MODULE, /* module */
8451 + { { 0, { .udp = { __constant_htons(NTALK_PORT) } } }, /* tuple */
8452 + { 0, { 0 }, IPPROTO_UDP } },
8453 + { { 0, { .udp = { 0xFFFF } } }, /* mask */
8454 + { 0, { 0 }, 0xFFFF } },
8455 + nhelp, /* helper */
8456 + talk_nat_expected } /* expectfn */
8459 +static unsigned int
8460 +talk_nat_expected(struct sk_buff **pskb,
8461 + unsigned int hooknum,
8462 + struct ip_conntrack *ct,
8463 + struct ip_nat_info *info)
8465 + struct ip_nat_multi_range mr;
8466 + u_int32_t newdstip, newsrcip, newip;
8470 + struct ip_conntrack *master = master_ct(ct);
8472 + IP_NF_ASSERT(info);
8473 + IP_NF_ASSERT(master);
8475 + IP_NF_ASSERT(!(info->initialized & (1<<HOOK2MANIP(hooknum))));
8477 + DEBUGP("ip_nat_talk_expected: We have a connection!\n");
8479 + LOCK_BH(&ip_talk_lock);
8480 + port = ct->master->help.exp_talk_info.port;
8481 + UNLOCK_BH(&ip_talk_lock);
8483 + DEBUGP("ip_nat_talk_expected: dir %s at hook %s, ct %p, master %p\n",
8484 + CTINFO2DIR((*pskb)->nfct - ct->infos) == IP_CT_DIR_ORIGINAL ? "ORIG" : "REPLY",
8485 + hooknum == NF_IP_POST_ROUTING ? "POSTROUTING"
8486 + : hooknum == NF_IP_PRE_ROUTING ? "PREROUTING"
8487 + : hooknum == NF_IP_LOCAL_OUT ? "OUTPUT" : "???",
8490 + if (ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum == IPPROTO_UDP) {
8491 + /* Callee client -> caller server */
8492 +#ifdef IP_NAT_TALK_DEBUG
8493 + struct iphdr *iph = (*pskb)->nh.iph;
8494 + struct udphdr *udph = (void *)iph + iph->ihl * 4;
8496 + DEBUGP("ip_nat_talk_expected: UDP %u.%u.%u.%u:%u->%u.%u.%u.%u:%u\n",
8497 + NIPQUAD(iph->saddr), ntohs(udph->source),
8498 + NIPQUAD(iph->daddr), ntohs(udph->dest));
8500 + newdstip = master->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.ip;
8501 + newsrcip = master->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.ip;
8502 + DEBUGP("ip_nat_talk_expected: callee client -> caller server, newsrc: %u.%u.%u.%u, newdst: %u.%u.%u.%u\n",
8503 + NIPQUAD(newsrcip), NIPQUAD(newdstip));
8505 + /* Callee client -> caller client */
8506 +#ifdef IP_NAT_TALK_DEBUG
8507 + struct iphdr *iph = (*pskb)->nh.iph;
8508 + struct tcphdr *tcph = (void *)iph + iph->ihl * 4;
8510 + DEBUGP("ip_nat_talk_expected: TCP %u.%u.%u.%u:%u->%u.%u.%u.%u:%u\n",
8511 + NIPQUAD(iph->saddr), ntohs(tcph->source),
8512 + NIPQUAD(iph->daddr), ntohs(tcph->dest));
8514 + newdstip = master->tuplehash[IP_CT_DIR_REPLY].tuple.src.ip;
8515 + newsrcip = master->tuplehash[IP_CT_DIR_REPLY].tuple.dst.ip;
8516 + DEBUGP("ip_nat_talk_expected: callee client -> caller client, newsrc: %u.%u.%u.%u, newdst: %u.%u.%u.%u\n",
8517 + NIPQUAD(newsrcip), NIPQUAD(newdstip));
8519 + if (HOOK2MANIP(hooknum) == IP_NAT_MANIP_SRC)
8524 + DEBUGP("ip_nat_talk_expected: IP to %u.%u.%u.%u, port %u\n", NIPQUAD(newip), ntohs(port));
8527 + /* We don't want to manip the per-protocol, just the IPs... */
8528 + mr.range[0].flags = IP_NAT_RANGE_MAP_IPS;
8529 + mr.range[0].min_ip = mr.range[0].max_ip = newip;
8531 + /* ... unless we're doing a MANIP_DST, in which case, make
8532 + sure we map to the correct port */
8533 + if (HOOK2MANIP(hooknum) == IP_NAT_MANIP_DST) {
8534 + mr.range[0].flags |= IP_NAT_RANGE_PROTO_SPECIFIED;
8535 + mr.range[0].min = mr.range[0].max
8536 + = ((union ip_conntrack_manip_proto)
8537 + { .udp = { port } });
8539 + ret = ip_nat_setup_info(ct, &mr, hooknum);
8541 + if (ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum == IPPROTO_UDP) {
8542 + DEBUGP("talk_expected: setting NAT helper for %p\n", ct);
8543 + /* NAT expectfn called with ip_nat_lock write-locked */
8544 + info->helper = &talk_helpers[htons(port) - TALK_PORT];
8549 +static int __init init(void)
8554 + ret = ip_nat_helper_register(&talk_helpers[0]);
8559 + if (ntalk > 0 || ntalk2 > 0) {
8560 + ret = ip_nat_helper_register(&talk_helpers[1]);
8562 + if (ret != 0 && talk > 0)
8563 + ip_nat_helper_unregister(&talk_helpers[0]);
8568 +static void __exit fini(void)
8571 + ip_nat_helper_unregister(&talk_helpers[0]);
8572 + if (ntalk > 0 || ntalk2 > 0)
8573 + ip_nat_helper_unregister(&talk_helpers[1]);
8578 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ip_pool.c linux-2.6.6/net/ipv4/netfilter/ip_pool.c
8579 --- linux-2.6.6.org/net/ipv4/netfilter/ip_pool.c 1970-01-01 01:00:00.000000000 +0100
8580 +++ linux-2.6.6/net/ipv4/netfilter/ip_pool.c 2004-05-18 14:28:50.000000000 +0200
8582 +/* Kernel module for IP pool management */
8584 +#include <linux/module.h>
8585 +#include <linux/ip.h>
8586 +#include <linux/skbuff.h>
8587 +#include <linux/netfilter_ipv4/ip_tables.h>
8588 +#include <linux/netfilter_ipv4/ip_pool.h>
8589 +#include <linux/errno.h>
8590 +#include <asm/uaccess.h>
8591 +#include <asm/bitops.h>
8592 +#include <linux/interrupt.h>
8593 +#include <linux/spinlock.h>
8598 +#define DP(format, args...)
8601 +MODULE_LICENSE("GPL");
8604 +static int nr_pool = NR_POOL;/* overwrite this when loading module */
8607 + u_int32_t first_ip; /* host byte order, included in range */
8608 + u_int32_t last_ip; /* host byte order, included in range */
8609 + void *members; /* the bitmap proper */
8610 + int nr_use; /* total nr. of tests through this */
8611 + int nr_match; /* total nr. of matches through this */
8615 +static struct ip_pool *POOL;
8617 +static inline struct ip_pool *lookup(ip_pool_t index)
8619 + if (index < 0 || index >= nr_pool) {
8620 + DP("ip_pool:lookup: bad index %d\n", index);
8623 + return POOL+index;
8626 +int ip_pool_match(ip_pool_t index, u_int32_t addr)
8628 + struct ip_pool *pool = lookup(index);
8631 + if (!pool || !pool->members)
8633 + read_lock_bh(&pool->lock);
8634 + if (pool->members) {
8635 + if (addr >= pool->first_ip && addr <= pool->last_ip) {
8636 + addr -= pool->first_ip;
8637 + if (test_bit(addr, pool->members)) {
8639 +#ifdef CONFIG_IP_POOL_STATISTICS
8644 +#ifdef CONFIG_IP_POOL_STATISTICS
8648 + read_unlock_bh(&pool->lock);
8651 +EXPORT_SYMBOL(ip_pool_match);
8653 +static int pool_change(ip_pool_t index, u_int32_t addr, int isdel)
8655 + struct ip_pool *pool;
8658 + pool = lookup(index);
8659 + if ( !pool || !pool->members
8660 + || addr < pool->first_ip || addr > pool->last_ip)
8662 + read_lock_bh(&pool->lock);
8663 + if (pool->members && addr >= pool->first_ip && addr <= pool->last_ip) {
8664 + addr -= pool->first_ip;
8666 + ? (0 != test_and_clear_bit(addr, pool->members))
8667 + : (0 != test_and_set_bit(addr, pool->members));
8669 + read_unlock_bh(&pool->lock);
8673 +int ip_pool_mod(ip_pool_t index, u_int32_t addr, int isdel)
8675 + int res = pool_change(index,addr,isdel);
8677 + if (!isdel) res = !res;
8680 +EXPORT_SYMBOL(ip_pool_mod);
8682 +static inline int bitmap_bytes(u_int32_t a, u_int32_t b)
8684 + return 4*((((b-a+8)/8)+3)/4);
8687 +static inline int poolbytes(ip_pool_t index)
8689 + struct ip_pool *pool = lookup(index);
8691 + return pool ? bitmap_bytes(pool->first_ip, pool->last_ip) : 0;
8694 +static int setpool(
8700 + struct ip_pool_request req;
8702 + DP("ip_pool:setpool: optval=%d, user=%p, len=%d\n", optval, user, len);
8703 + if (!capable(CAP_NET_ADMIN))
8705 + if (optval != SO_IP_POOL)
8707 + if (len != sizeof(req))
8709 + if (copy_from_user(&req, user, sizeof(req)) != 0)
8711 + printk("obsolete op - upgrade your ippool(8) utility.\n");
8715 +static int getpool(
8721 + struct ip_pool_request req;
8722 + struct ip_pool *pool;
8728 + DP("ip_pool:getpool: optval=%d, user=%p\n", optval, user);
8729 + if (!capable(CAP_NET_ADMIN))
8731 + if (optval != SO_IP_POOL)
8733 + if (*len != sizeof(req)) {
8736 + if (copy_from_user(&req, user, sizeof(req)) != 0)
8738 + DP("ip_pool:getpool op=%d, index=%d\n", req.op, req.index);
8739 + if (req.op < IP_POOL_BAD001) {
8740 + printk("obsolete op - upgrade your ippool(8) utility.\n");
8744 + case IP_POOL_HIGH_NR:
8745 + DP("ip_pool HIGH_NR\n");
8746 + req.index = IP_POOL_NONE;
8747 + for (i=0; i<nr_pool; i++)
8748 + if (POOL[i].members)
8750 + return copy_to_user(user, &req, sizeof(req));
8751 + case IP_POOL_LOOKUP:
8752 + DP("ip_pool LOOKUP\n");
8753 + pool = lookup(req.index);
8756 + if (!pool->members)
8758 + req.addr = htonl(pool->first_ip);
8759 + req.addr2 = htonl(pool->last_ip);
8760 + return copy_to_user(user, &req, sizeof(req));
8761 + case IP_POOL_USAGE:
8762 + DP("ip_pool USE\n");
8763 + pool = lookup(req.index);
8766 + if (!pool->members)
8768 + req.addr = pool->nr_use;
8769 + req.addr2 = pool->nr_match;
8770 + return copy_to_user(user, &req, sizeof(req));
8771 + case IP_POOL_TEST_ADDR:
8772 + DP("ip_pool TEST 0x%08x\n", req.addr);
8773 + pool = lookup(req.index);
8777 + read_lock_bh(&pool->lock);
8778 + if (!pool->members) {
8779 + DP("ip_pool TEST_ADDR no members in pool\n");
8781 + goto unlock_and_return_res;
8783 + req.addr = ntohl(req.addr);
8784 + if (req.addr < pool->first_ip) {
8785 + DP("ip_pool TEST_ADDR address < pool bounds\n");
8787 + goto unlock_and_return_res;
8789 + if (req.addr > pool->last_ip) {
8790 + DP("ip_pool TEST_ADDR address > pool bounds\n");
8792 + goto unlock_and_return_res;
8794 + req.addr = (0 != test_bit((req.addr - pool->first_ip),
8796 + read_unlock_bh(&pool->lock);
8797 + return copy_to_user(user, &req, sizeof(req));
8798 + case IP_POOL_FLUSH:
8799 + DP("ip_pool FLUSH not yet implemented.\n");
8801 + case IP_POOL_DESTROY:
8802 + DP("ip_pool DESTROY not yet implemented.\n");
8804 + case IP_POOL_INIT:
8805 + DP("ip_pool INIT 0x%08x-0x%08x\n", req.addr, req.addr2);
8806 + pool = lookup(req.index);
8809 + req.addr = ntohl(req.addr);
8810 + req.addr2 = ntohl(req.addr2);
8811 + if (req.addr > req.addr2) {
8812 + DP("ip_pool INIT bad ip range\n");
8815 + newbytes = bitmap_bytes(req.addr, req.addr2);
8816 + newmembers = kmalloc(newbytes, GFP_KERNEL);
8817 + if (!newmembers) {
8818 + DP("ip_pool INIT out of mem for %d bytes\n", newbytes);
8821 + memset(newmembers, 0, newbytes);
8822 + write_lock_bh(&pool->lock);
8823 + if (pool->members) {
8824 + DP("ip_pool INIT pool %d exists\n", req.index);
8825 + kfree(newmembers);
8827 + goto unlock_and_return_res;
8829 + pool->first_ip = req.addr;
8830 + pool->last_ip = req.addr2;
8832 + pool->nr_match = 0;
8833 + pool->members = newmembers;
8834 + write_unlock_bh(&pool->lock);
8836 + case IP_POOL_ADD_ADDR:
8837 + DP("ip_pool ADD_ADDR 0x%08x\n", req.addr);
8838 + req.addr = pool_change(req.index, ntohl(req.addr), 0);
8839 + return copy_to_user(user, &req, sizeof(req));
8840 + case IP_POOL_DEL_ADDR:
8841 + DP("ip_pool DEL_ADDR 0x%08x\n", req.addr);
8842 + req.addr = pool_change(req.index, ntohl(req.addr), 1);
8843 + return copy_to_user(user, &req, sizeof(req));
8845 + DP("ip_pool:getpool bad op %d\n", req.op);
8850 +unlock_and_return_res:
8852 + read_unlock_bh(&pool->lock);
8856 +static struct nf_sockopt_ops so_pool
8857 += { { NULL, NULL }, PF_INET,
8858 + SO_IP_POOL, SO_IP_POOL+1, &setpool,
8859 + SO_IP_POOL, SO_IP_POOL+1, &getpool,
8862 +MODULE_PARM(nr_pool, "i");
8864 +static int __init init(void)
8869 + if (nr_pool < 1) {
8870 + printk("ip_pool module init: bad nr_pool %d\n", nr_pool);
8873 + POOL = kmalloc(nr_pool * sizeof(*POOL), GFP_KERNEL);
8875 + printk("ip_pool module init: out of memory for nr_pool %d\n",
8879 + for (i=0; i<nr_pool; i++) {
8880 + POOL[i].first_ip = 0;
8881 + POOL[i].last_ip = 0;
8882 + POOL[i].members = 0;
8883 + POOL[i].nr_use = 0;
8884 + POOL[i].nr_match = 0;
8885 + POOL[i].lock = RW_LOCK_UNLOCKED;
8887 + res = nf_register_sockopt(&so_pool);
8888 + DP("ip_pool:init %d pools, result %d\n", nr_pool, res);
8896 +static void __exit fini(void)
8900 + DP("ip_pool:fini BYEBYE\n");
8901 + nf_unregister_sockopt(&so_pool);
8902 + for (i=0; i<nr_pool; i++) {
8903 + if (POOL[i].members) {
8904 + kfree(POOL[i].members);
8905 + POOL[i].members = 0;
8910 + DP("ip_pool:fini these are the famous last words\n");
8916 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ip_tables.c linux-2.6.6/net/ipv4/netfilter/ip_tables.c
8917 --- linux-2.6.6.org/net/ipv4/netfilter/ip_tables.c 2004-05-10 04:32:26.000000000 +0200
8918 +++ linux-2.6.6/net/ipv4/netfilter/ip_tables.c 2004-05-18 14:28:50.000000000 +0200
8921 #include <linux/netfilter_ipv4/ip_tables.h>
8923 +static const char *hooknames[] = {
8924 + [NF_IP_PRE_ROUTING] "PREROUTING",
8925 + [NF_IP_LOCAL_IN] "INPUT",
8926 + [NF_IP_FORWARD] "FORWARD",
8927 + [NF_IP_LOCAL_OUT] "OUTPUT",
8928 + [NF_IP_POST_ROUTING] "POSTROUTING",
8931 MODULE_LICENSE("GPL");
8932 MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>");
8933 MODULE_DESCRIPTION("IPv4 packet filter");
8934 @@ -326,6 +334,12 @@
8936 t = ipt_get_target(e);
8937 IP_NF_ASSERT(t->u.kernel.target);
8939 + /* The packet traced and the rule isn't an unconditional return/END. */
8940 + if (((*pskb)->nfcache & NFC_TRACE) && e->rulenum) {
8941 + nf_log_packet(PF_INET, hook, *pskb, in, out, "TRACE: %s/%s/%u ",
8942 + table->name, e->chainname, e->rulenum);
8944 /* Standard target? */
8945 if (!t->u.kernel.target->target) {
8951 - != (void *)e + e->next_offset) {
8952 + != (void *)e + e->next_offset && !(e->ip.flags & IPT_F_GOTO)) {
8953 /* Save old back ptr in next entry */
8954 struct ipt_entry *next
8955 = (void *)e + e->next_offset;
8957 /* set back pointer to next entry */
8961 e = get_entry(table_base, v);
8963 /* Targets which reenter must return
8964 @@ -478,6 +491,29 @@
8965 return find_inlist_lock(&ipt_target, name, "ipt_", error, mutex);
8969 +find_error_target(struct ipt_entry *s,
8970 + struct ipt_entry *e,
8973 + struct ipt_entry_target *t;
8974 + static struct ipt_entry *found = NULL;
8979 + t = ipt_get_target(found);
8980 + if (strcmp(t->u.user.name,
8981 + IPT_ERROR_TARGET) == 0) {
8982 + *chainname = t->data;
8991 /* All zeroes == unconditional rule. */
8993 unconditional(const struct ipt_ip *ip)
8995 mark_source_chains(struct ipt_table_info *newinfo, unsigned int valid_hooks)
8998 + char *chainname = NULL;
8999 + u_int32_t rulenum;
9001 /* No recursion; use packet counter to save back ptrs (reset
9002 to 0 as we leave), and comefrom to save source hook bitmask */
9005 /* Set initial back pointer. */
9006 e->counters.pcnt = pos;
9008 + chainname = (char *) hooknames[hook];
9011 struct ipt_standard_target *t
9015 |= ((1 << hook) | (1 << NF_IP_NUMHOOKS));
9016 + e->rulenum = rulenum++;
9017 + e->chainname = chainname;
9019 /* Unconditional return/END. */
9020 if (e->target_offset == sizeof(struct ipt_entry)
9021 @@ -531,6 +573,10 @@
9022 && unconditional(&e->ip)) {
9023 unsigned int oldpos, size;
9025 + /* Set unconditional rulenum to zero. */
9027 + e->counters.bcnt = 0;
9029 /* Return: backtrack through the last
9032 @@ -556,6 +602,11 @@
9033 (newinfo->entries + pos);
9034 } while (oldpos == pos + e->next_offset);
9036 + /* Restore chainname, rulenum. */
9037 + chainname = e->chainname;
9038 + rulenum = e->counters.bcnt;
9039 + e->counters.bcnt = 0;
9041 /* Move along one */
9042 size = e->next_offset;
9043 e = (struct ipt_entry *)
9044 @@ -571,6 +622,17 @@
9045 /* This a jump; chase it. */
9046 duprintf("Jump rule %u -> %u\n",
9048 + e->counters.bcnt = rulenum++;
9050 + e = (struct ipt_entry *)
9051 + (newinfo->entries + newpos);
9052 + if (IPT_ENTRY_ITERATE(newinfo->entries,
9054 + find_error_target,
9055 + e, &chainname) == 0) {
9056 + printk("ip_tables: table screwed up!\n");
9060 /* ... this is a fallthru */
9061 newpos = pos + e->next_offset;
9062 @@ -1716,9 +1778,9 @@
9065 #ifdef CONFIG_PROC_FS
9066 -static inline int print_name(const char *i,
9067 - off_t start_offset, char *buffer, int length,
9068 - off_t *pos, unsigned int *count)
9069 +static int print_name(const char *i,
9070 + off_t start_offset, char *buffer, int length,
9071 + off_t *pos, unsigned int *count)
9073 if ((*count)++ >= start_offset) {
9074 unsigned int namelen;
9075 @@ -1752,6 +1814,15 @@
9079 +static inline int print_target(const struct ipt_target *t,
9080 + off_t start_offset, char *buffer, int length,
9081 + off_t *pos, unsigned int *count)
9083 + if (t == &ipt_standard_target || t == &ipt_error_target)
9085 + return print_name((char *)t, start_offset, buffer, length, pos, count);
9088 static int ipt_get_targets(char *buffer, char **start, off_t offset, int length)
9091 @@ -1760,7 +1831,7 @@
9092 if (down_interruptible(&ipt_mutex) != 0)
9095 - LIST_FIND(&ipt_target, print_name, void *,
9096 + LIST_FIND(&ipt_target, print_target, struct ipt_target *,
9097 offset, buffer, length, &pos, &count);
9100 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_CONNMARK.c linux-2.6.6/net/ipv4/netfilter/ipt_CONNMARK.c
9101 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_CONNMARK.c 1970-01-01 01:00:00.000000000 +0100
9102 +++ linux-2.6.6/net/ipv4/netfilter/ipt_CONNMARK.c 2004-05-18 14:28:50.000000000 +0200
9104 +/* This kernel module is used to modify the connection mark values, or
9105 + * to optionally restore the skb nfmark from the connection mark
9107 + * Copyright (C) 2002,2004 MARA Systems AB <http://www.marasystems.com>
9108 + * by Henrik Nordstrom <hno@marasystems.com>
9110 + * This program is free software; you can redistribute it and/or modify
9111 + * it under the terms of the GNU General Public License as published by
9112 + * the Free Software Foundation; either version 2 of the License, or
9113 + * (at your option) any later version.
9115 + * This program is distributed in the hope that it will be useful,
9116 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9117 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9118 + * GNU General Public License for more details.
9120 + * You should have received a copy of the GNU General Public License
9121 + * along with this program; if not, write to the Free Software
9122 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
9124 +#include <linux/module.h>
9125 +#include <linux/skbuff.h>
9126 +#include <linux/ip.h>
9127 +#include <net/checksum.h>
9129 +MODULE_AUTHOR("Henrik Nordstrom <hno@marasytems.com>");
9130 +MODULE_DESCRIPTION("IP tables CONNMARK matching module");
9131 +MODULE_LICENSE("GPL");
9133 +#include <linux/netfilter_ipv4/ip_tables.h>
9134 +#include <linux/netfilter_ipv4/ipt_CONNMARK.h>
9135 +#include <linux/netfilter_ipv4/ip_conntrack.h>
9137 +static unsigned int
9138 +target(struct sk_buff **pskb,
9139 + const struct net_device *in,
9140 + const struct net_device *out,
9141 + unsigned int hooknum,
9142 + const void *targinfo,
9145 + const struct ipt_connmark_target_info *markinfo = targinfo;
9146 + unsigned long diff;
9147 + unsigned long nfmark;
9148 + unsigned long newmark;
9150 + enum ip_conntrack_info ctinfo;
9151 + struct ip_conntrack *ct = ip_conntrack_get((*pskb), &ctinfo);
9153 + switch(markinfo->mode) {
9154 + case IPT_CONNMARK_SET:
9155 + newmark = (ct->mark & ~markinfo->mask) | markinfo->mark;
9156 + if (newmark != ct->mark)
9157 + ct->mark = newmark;
9159 + case IPT_CONNMARK_SAVE:
9160 + newmark = (ct->mark & ~markinfo->mask) | ((*pskb)->nfmark & markinfo->mask);
9161 + if (ct->mark != newmark)
9162 + ct->mark = newmark;
9164 + case IPT_CONNMARK_RESTORE:
9165 + nfmark = (*pskb)->nfmark;
9166 + diff = (ct->mark ^ nfmark & markinfo->mask);
9168 + (*pskb)->nfmark = nfmark ^ diff;
9169 + (*pskb)->nfcache |= NFC_ALTERED;
9175 + return IPT_CONTINUE;
9179 +checkentry(const char *tablename,
9180 + const struct ipt_entry *e,
9182 + unsigned int targinfosize,
9183 + unsigned int hook_mask)
9185 + struct ipt_connmark_target_info *matchinfo = targinfo;
9186 + if (targinfosize != IPT_ALIGN(sizeof(struct ipt_connmark_target_info))) {
9187 + printk(KERN_WARNING "CONNMARK: targinfosize %u != %Zu\n",
9189 + IPT_ALIGN(sizeof(struct ipt_connmark_target_info)));
9193 + if (matchinfo->mode == IPT_CONNMARK_RESTORE) {
9194 + if (strcmp(tablename, "mangle") != 0) {
9195 + printk(KERN_WARNING "CONNMARK: restore can only be called from \"mangle\" table, not \"%s\"\n", tablename);
9203 +static struct ipt_target ipt_connmark_reg = {
9204 + .name = "CONNMARK",
9205 + .target = &target,
9206 + .checkentry = &checkentry,
9210 +static int __init init(void)
9212 + return ipt_register_target(&ipt_connmark_reg);
9215 +static void __exit fini(void)
9217 + ipt_unregister_target(&ipt_connmark_reg);
9222 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_IPMARK.c linux-2.6.6/net/ipv4/netfilter/ipt_IPMARK.c
9223 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_IPMARK.c 1970-01-01 01:00:00.000000000 +0100
9224 +++ linux-2.6.6/net/ipv4/netfilter/ipt_IPMARK.c 2004-05-18 14:28:50.000000000 +0200
9226 +/* This is a module which is used for setting the NFMARK field of an skb. */
9227 +#include <linux/module.h>
9228 +#include <linux/skbuff.h>
9229 +#include <linux/ip.h>
9230 +#include <net/checksum.h>
9232 +#include <linux/netfilter_ipv4/ip_tables.h>
9233 +#include <linux/netfilter_ipv4/ipt_IPMARK.h>
9235 +MODULE_AUTHOR("Grzegorz Janoszka <Grzegorz.Janoszka@pro.onet.pl>");
9236 +MODULE_DESCRIPTION("IP tables IPMARK: mark based on ip address");
9237 +MODULE_LICENSE("GPL");
9239 +static unsigned int
9240 +target(struct sk_buff **pskb,
9241 + const struct net_device *in,
9242 + const struct net_device *out,
9243 + unsigned int hooknum,
9244 + const void *targinfo,
9247 + const struct ipt_ipmark_target_info *ipmarkinfo = targinfo;
9248 + struct iphdr *iph = (*pskb)->nh.iph;
9249 + unsigned long mark;
9251 + if (ipmarkinfo->addr == IPT_IPMARK_SRC)
9252 + mark = (unsigned long) ntohl(iph->saddr);
9254 + mark = (unsigned long) ntohl(iph->daddr);
9256 + mark &= ipmarkinfo->andmask;
9257 + mark |= ipmarkinfo->ormask;
9259 + if ((*pskb)->nfmark != mark) {
9260 + (*pskb)->nfmark = mark;
9261 + (*pskb)->nfcache |= NFC_ALTERED;
9263 + return IPT_CONTINUE;
9267 +checkentry(const char *tablename,
9268 + const struct ipt_entry *e,
9270 + unsigned int targinfosize,
9271 + unsigned int hook_mask)
9273 + if (targinfosize != IPT_ALIGN(sizeof(struct ipt_ipmark_target_info))) {
9274 + printk(KERN_WARNING "IPMARK: targinfosize %u != %Zu\n",
9276 + IPT_ALIGN(sizeof(struct ipt_ipmark_target_info)));
9280 + if (strcmp(tablename, "mangle") != 0) {
9281 + printk(KERN_WARNING "IPMARK: can only be called from \"mangle\" table, not \"%s\"\n", tablename);
9288 +static struct ipt_target ipt_ipmark_reg = {
9291 + .checkentry = checkentry,
9295 +static int __init init(void)
9297 + return ipt_register_target(&ipt_ipmark_reg);
9300 +static void __exit fini(void)
9302 + ipt_unregister_target(&ipt_ipmark_reg);
9307 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_IPV4OPTSSTRIP.c linux-2.6.6/net/ipv4/netfilter/ipt_IPV4OPTSSTRIP.c
9308 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_IPV4OPTSSTRIP.c 1970-01-01 01:00:00.000000000 +0100
9309 +++ linux-2.6.6/net/ipv4/netfilter/ipt_IPV4OPTSSTRIP.c 2004-05-18 14:28:50.000000000 +0200
9312 + * Strip all IP options in the IP packet header.
9314 + * (C) 2001 by Fabrice MARIE <fabrice@netfilter.org>
9315 + * This software is distributed under GNU GPL v2, 1991
9318 +#include <linux/module.h>
9319 +#include <linux/skbuff.h>
9320 +#include <linux/ip.h>
9321 +#include <net/checksum.h>
9323 +#include <linux/netfilter_ipv4/ip_tables.h>
9325 +MODULE_AUTHOR("Fabrice MARIE <fabrice@netfilter.org>");
9326 +MODULE_DESCRIPTION("Strip all options in IPv4 packets");
9327 +MODULE_LICENSE("GPL");
9329 +static unsigned int
9330 +target(struct sk_buff **pskb,
9331 + const struct net_device *in,
9332 + const struct net_device *out,
9333 + unsigned int hooknum,
9334 + const void *targinfo,
9337 + struct iphdr *iph;
9338 + struct sk_buff *skb;
9339 + struct ip_options *opt;
9340 + unsigned char *optiph;
9343 + if (!skb_ip_make_writable(pskb, (*pskb)->len))
9347 + iph = (*pskb)->nh.iph;
9348 + optiph = skb->nh.raw;
9349 + l = ((struct ip_options *)(&(IPCB(skb)->opt)))->optlen;
9351 + /* if no options in packet then nothing to clear. */
9352 + if (iph->ihl * 4 == sizeof(struct iphdr))
9353 + return IPT_CONTINUE;
9355 + /* else clear all options */
9356 + memset(&(IPCB(skb)->opt), 0, sizeof(struct ip_options));
9357 + memset(optiph+sizeof(struct iphdr), IPOPT_NOOP, l);
9358 + opt = &(IPCB(skb)->opt);
9362 + skb->nfcache |= NFC_ALTERED;
9364 + return IPT_CONTINUE;
9368 +checkentry(const char *tablename,
9369 + const struct ipt_entry *e,
9371 + unsigned int targinfosize,
9372 + unsigned int hook_mask)
9374 + if (strcmp(tablename, "mangle")) {
9375 + printk(KERN_WARNING "IPV4OPTSSTRIP: can only be called from \"mangle\" table, not \"%s\"\n", tablename);
9378 + /* nothing else to check because no parameters */
9382 +static struct ipt_target ipt_ipv4optsstrip_reg = {
9383 + .name = "IPV4OPTSSTRIP",
9385 + .checkentry = checkentry,
9386 + .me = THIS_MODULE };
9388 +static int __init init(void)
9390 + return ipt_register_target(&ipt_ipv4optsstrip_reg);
9393 +static void __exit fini(void)
9395 + ipt_unregister_target(&ipt_ipv4optsstrip_reg);
9400 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_MARK.c linux-2.6.6/net/ipv4/netfilter/ipt_MARK.c
9401 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_MARK.c 2004-05-10 04:32:37.000000000 +0200
9402 +++ linux-2.6.6/net/ipv4/netfilter/ipt_MARK.c 2004-05-18 14:28:50.000000000 +0200
9405 const struct ipt_mark_target_info *markinfo = targinfo;
9407 - if((*pskb)->nfmark != markinfo->mark) {
9408 + switch (markinfo->mode) {
9409 + case IPT_MARK_SET:
9410 (*pskb)->nfmark = markinfo->mark;
9411 - (*pskb)->nfcache |= NFC_ALTERED;
9414 + case IPT_MARK_AND:
9415 + (*pskb)->nfmark &= markinfo->mark;
9419 + (*pskb)->nfmark |= markinfo->mark;
9422 + (*pskb)->nfcache |= NFC_ALTERED;
9423 return IPT_CONTINUE;
9426 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_NETLINK.c linux-2.6.6/net/ipv4/netfilter/ipt_NETLINK.c
9427 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_NETLINK.c 1970-01-01 01:00:00.000000000 +0100
9428 +++ linux-2.6.6/net/ipv4/netfilter/ipt_NETLINK.c 2004-05-18 14:28:50.000000000 +0200
9430 +#include <linux/module.h>
9431 +#include <linux/version.h>
9432 +#include <linux/config.h>
9433 +#include <linux/socket.h>
9434 +#include <linux/skbuff.h>
9435 +#include <linux/kernel.h>
9436 +#include <linux/netlink.h>
9437 +#include <linux/netdevice.h>
9438 +#include <linux/mm.h>
9439 +#include <linux/socket.h>
9440 +#include <linux/netfilter_ipv4/ip_tables.h>
9441 +#include <linux/netfilter_ipv4/ipt_NETLINK.h>
9442 +#include <net/sock.h>
9444 +MODULE_AUTHOR("Gianni Tedesco <gianni@ecsc.co.uk>");
9445 +MODULE_DESCRIPTION("Provides iptables NETLINK target similar to ipchains -o");
9446 +MODULE_LICENSE("GPL");
9449 +#define DEBUGP printk
9451 +#define DEBUGP(format, args...)
9454 +static struct sock *ipfwsk;
9456 +static unsigned int ipt_netlink_target(struct sk_buff **pskb,
9457 + unsigned int hooknum,
9458 + const struct net_device *in,
9459 + const struct net_device *out,
9460 + const void *targinfo, void *userinfo)
9462 + struct ipt_nldata *nld = (struct ipt_nldata *)targinfo;
9463 + struct iphdr *ip = (*pskb)->nh.iph;
9464 + struct sk_buff *outskb;
9465 + struct netlink_t nlhdr;
9468 + /* Allocate a socket buffer */
9469 + if ( MASK(nld->flags, USE_SIZE) )
9470 + len = nld->size+sizeof(nlhdr);
9472 + len = ntohs(ip->tot_len)+sizeof(nlhdr);
9474 + outskb=alloc_skb(len, GFP_ATOMIC);
9479 + if ( MASK(nld->flags, USE_MARK) )
9480 + nlhdr.mark=(*pskb)->nfmark=nld->mark;
9482 + nlhdr.mark=(*pskb)->nfmark;
9484 + if ( in && in->name ) {
9485 + strncpy((char *)&nlhdr.iface, in->name, IFNAMSIZ);
9486 + }else if ( out && out->name ){
9487 + strncpy((char *)&nlhdr.iface, out->name, IFNAMSIZ);
9490 + skb_put(outskb, len);
9491 + memcpy(outskb->data, &nlhdr, sizeof(nlhdr));
9492 + memcpy((outskb->data)+sizeof(nlhdr), ip, len-sizeof(nlhdr));
9493 + netlink_broadcast(ipfwsk, outskb, 0, ~0, GFP_ATOMIC);
9495 + if (net_ratelimit())
9496 + printk(KERN_WARNING "ipt_NETLINK: packet drop due to netlink failure\n");
9499 + if ( MASK(nld->flags, USE_DROP) )
9502 + return IPT_CONTINUE;
9505 +static int ipt_netlink_checkentry(const char *tablename,
9506 + const struct ipt_entry *e,
9508 + unsigned int targinfosize,
9509 + unsigned int hookmask)
9511 + //struct ipt_nldata *nld = (struct ipt_nldata *)targinfo;
9516 +static struct ipt_target ipt_netlink_reg = {
9519 + ipt_netlink_target,
9520 + ipt_netlink_checkentry,
9525 +static int __init init(void)
9527 + DEBUGP("ipt_NETLINK: init module\n");
9529 + if (ipt_register_target(&ipt_netlink_reg) != 0) {
9533 + if ( !(ipfwsk=netlink_kernel_create(NETLINK_FIREWALL, NULL)) ){
9540 +static void __exit fini(void)
9542 + DEBUGP("ipt_NETLINK: cleanup_module\n");
9543 + ipt_unregister_target(&ipt_netlink_reg);
9544 + if(ipfwsk->sk_socket) sock_release(ipfwsk->sk_socket);
9549 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_POOL.c linux-2.6.6/net/ipv4/netfilter/ipt_POOL.c
9550 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_POOL.c 1970-01-01 01:00:00.000000000 +0100
9551 +++ linux-2.6.6/net/ipv4/netfilter/ipt_POOL.c 2004-05-18 14:28:50.000000000 +0200
9553 +/* ipt_POOL.c - netfilter target to manipulate IP pools
9555 + * This target can be used almost everywhere. It acts on some specified
9556 + * IP pool, adding or deleting some IP address in the pool. The address
9557 + * can be either the source (--addsrc, --delsrc), or destination (--add/deldst)
9558 + * of the packet under inspection.
9560 + * The target normally returns IPT_CONTINUE.
9563 +#include <linux/types.h>
9564 +#include <linux/ip.h>
9565 +#include <linux/timer.h>
9566 +#include <linux/module.h>
9567 +#include <linux/netfilter.h>
9568 +#include <linux/netdevice.h>
9569 +#include <linux/if.h>
9570 +#include <linux/inetdevice.h>
9571 +#include <net/protocol.h>
9572 +#include <net/checksum.h>
9573 +#include <linux/netfilter_ipv4.h>
9574 +#include <linux/netfilter_ipv4/ip_nat_rule.h>
9575 +#include <linux/netfilter_ipv4/ipt_pool.h>
9578 +#define DEBUGP printk
9580 +#define DEBUGP(format, args...)
9583 +/*** NOTE NOTE NOTE NOTE ***
9585 +** By sheer luck, I get away with using the "struct ipt_pool_info", as defined
9586 +** in <linux/netfilter_ipv4/ipt_pool.h>, both as the match and target info.
9587 +** Here, in the target implementation, ipt_pool_info.src, if not IP_POOL_NONE,
9588 +** is modified for the source IP address of the packet under inspection.
9589 +** The same way, the ipt_pool_info.dst pool is modified for the destination.
9591 +** The address is added to the pool normally. However, if IPT_POOL_DEL_dir
9592 +** flag is set in ipt_pool_info.flags, the address is deleted from the pool.
9594 +** If a modification was done to the pool, we possibly return ACCEPT or DROP,
9595 +** if the right IPT_POOL_MOD_dir_ACCEPT or _MOD_dir_DROP flags are set.
9596 +** The IPT_POOL_INV_MOD_dir flag inverts the sense of the check (i.e. the
9597 +** ACCEPT and DROP flags are evaluated when the pool was not modified.)
9601 +do_check(const char *tablename,
9602 + const struct ipt_entry *e,
9604 + unsigned int targinfosize,
9605 + unsigned int hook_mask)
9607 + const struct ipt_pool_info *ipi = targinfo;
9609 + if (targinfosize != IPT_ALIGN(sizeof(*ipi))) {
9610 + DEBUGP("POOL_check: size %u.\n", targinfosize);
9613 + DEBUGP("ipt_POOL:do_check(%d,%d,%d)\n",ipi->src,ipi->dst,ipi->flags);
9617 +static unsigned int
9618 +do_target(struct sk_buff **pskb,
9619 + unsigned int hooknum,
9620 + const struct net_device *in,
9621 + const struct net_device *out,
9622 + const void *targinfo,
9625 + const struct ipt_pool_info *ipi = targinfo;
9627 + unsigned int verdict = IPT_CONTINUE;
9629 + if (ipi->src != IP_POOL_NONE) {
9630 + modified = ip_pool_mod(ipi->src, ntohl((*pskb)->nh.iph->saddr),
9631 + ipi->flags & IPT_POOL_DEL_SRC);
9632 + if (!!modified ^ !!(ipi->flags & IPT_POOL_INV_MOD_SRC)) {
9633 + if (ipi->flags & IPT_POOL_MOD_SRC_ACCEPT)
9634 + verdict = NF_ACCEPT;
9635 + else if (ipi->flags & IPT_POOL_MOD_SRC_DROP)
9636 + verdict = NF_DROP;
9639 + if (verdict == IPT_CONTINUE && ipi->dst != IP_POOL_NONE) {
9640 + modified = ip_pool_mod(ipi->dst, ntohl((*pskb)->nh.iph->daddr),
9641 + ipi->flags & IPT_POOL_DEL_DST);
9642 + if (!!modified ^ !!(ipi->flags & IPT_POOL_INV_MOD_DST)) {
9643 + if (ipi->flags & IPT_POOL_MOD_DST_ACCEPT)
9644 + verdict = NF_ACCEPT;
9645 + else if (ipi->flags & IPT_POOL_MOD_DST_DROP)
9646 + verdict = NF_DROP;
9652 +static struct ipt_target pool_reg
9653 += { { NULL, NULL }, "POOL", do_target, do_check, NULL, THIS_MODULE };
9655 +static int __init init(void)
9657 + DEBUGP("init ipt_POOL\n");
9658 + return ipt_register_target(&pool_reg);
9661 +static void __exit fini(void)
9663 + DEBUGP("fini ipt_POOL\n");
9664 + ipt_unregister_target(&pool_reg);
9669 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_ROUTE.c linux-2.6.6/net/ipv4/netfilter/ipt_ROUTE.c
9670 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_ROUTE.c 1970-01-01 01:00:00.000000000 +0100
9671 +++ linux-2.6.6/net/ipv4/netfilter/ipt_ROUTE.c 2004-05-18 14:28:50.000000000 +0200
9674 + * This implements the ROUTE target, which enables you to setup unusual
9675 + * routes not supported by the standard kernel routing table.
9677 + * Copyright (C) 2002 Cedric de Launois <delaunois@info.ucl.ac.be>
9679 + * v 1.9 2004/05/14
9681 + * This software is distributed under GNU GPL v2, 1991
9684 +#include <linux/module.h>
9685 +#include <linux/skbuff.h>
9686 +#include <linux/ip.h>
9687 +#include <linux/netfilter_ipv4/ip_tables.h>
9688 +#include <linux/netfilter_ipv4/ipt_ROUTE.h>
9689 +#include <linux/netdevice.h>
9690 +#include <linux/route.h>
9691 +#include <net/ip.h>
9692 +#include <net/route.h>
9693 +#include <net/icmp.h>
9694 +#include <net/checksum.h>
9697 +#define DEBUGP printk
9699 +#define DEBUGP(format, args...)
9702 +MODULE_LICENSE("GPL");
9703 +MODULE_AUTHOR("Cedric de Launois <delaunois@info.ucl.ac.be>");
9704 +MODULE_DESCRIPTION("iptables ROUTE target module");
9706 +/* Try to route the packet according to the routing keys specified in
9707 + * route_info. Keys are :
9709 + * 0 if no oif preferred,
9710 + * otherwise set to the index of the desired oif
9711 + * - route_info->gw :
9712 + * 0 if no gateway specified,
9713 + * otherwise set to the next host to which the pkt must be routed
9714 + * If success, skb->dev is the output device to which the packet must
9715 + * be sent and skb->dst is not NULL
9717 + * RETURN: -1 if an error occured
9718 + * 1 if the packet was succesfully routed to the
9719 + * destination desired
9720 + * 0 if the kernel routing table could not route the packet
9721 + * according to the keys specified
9723 +static int route(struct sk_buff *skb,
9724 + unsigned int ifindex,
9725 + const struct ipt_route_target_info *route_info)
9728 + struct rtable *rt;
9729 + struct iphdr *iph = skb->nh.iph;
9730 + struct flowi fl = {
9734 + .daddr = iph->daddr,
9736 + .tos = RT_TOS(iph->tos),
9737 + .scope = RT_SCOPE_UNIVERSE,
9742 + /* The destination address may be overloaded by the target */
9743 + if (route_info->gw)
9744 + fl.fld_dst = route_info->gw;
9746 + /* Trying to route the packet using the standard routing table. */
9747 + if ((err = ip_route_output_key(&rt, &fl))) {
9748 + if (net_ratelimit())
9749 + DEBUGP("ipt_ROUTE: couldn't route pkt (err: %i)",err);
9753 + /* Drop old route. */
9754 + dst_release(skb->dst);
9757 + /* Success if no oif specified or if the oif correspond to the
9759 + if (!ifindex || rt->u.dst.dev->ifindex == ifindex) {
9760 + skb->dst = &rt->u.dst;
9761 + skb->dev = skb->dst->dev;
9765 + /* The interface selected by the routing table is not the one
9766 + * specified by the user. This may happen because the dst address
9767 + * is one of our own addresses.
9769 + if (net_ratelimit())
9770 + DEBUGP("ipt_ROUTE: failed to route as desired gw=%u.%u.%u.%u oif=%i (got oif=%i)\n",
9771 + NIPQUAD(route_info->gw), ifindex, rt->u.dst.dev->ifindex);
9777 +/* Stolen from ip_finish_output2
9778 + * PRE : skb->dev is set to the device we are leaving by
9779 + * skb->dst is not NULL
9780 + * POST: the packet is sent with the link layer header pushed
9781 + * the packet is destroyed
9783 +static void ip_direct_send(struct sk_buff *skb)
9785 + struct dst_entry *dst = skb->dst;
9786 + struct hh_cache *hh = dst->hh;
9789 + read_lock_bh(&hh->hh_lock);
9790 + memcpy(skb->data - 16, hh->hh_data, 16);
9791 + read_unlock_bh(&hh->hh_lock);
9792 + skb_push(skb, hh->hh_len);
9793 + hh->hh_output(skb);
9794 + } else if (dst->neighbour)
9795 + dst->neighbour->output(skb);
9797 + if (net_ratelimit())
9798 + DEBUGP(KERN_DEBUG "ipt_ROUTE: no hdr & no neighbour cache!\n");
9804 +/* PRE : skb->dev is set to the device we are leaving by
9805 + * POST: - the packet is directly sent to the skb->dev device, without
9806 + * pushing the link layer header.
9807 + * - the packet is destroyed
9809 +static inline int dev_direct_send(struct sk_buff *skb)
9811 + return dev_queue_xmit(skb);
9815 +static unsigned int route_oif(const struct ipt_route_target_info *route_info,
9816 + struct sk_buff *skb)
9818 + unsigned int ifindex = 0;
9819 + struct net_device *dev_out = NULL;
9821 + /* The user set the interface name to use.
9822 + * Getting the current interface index.
9824 + if ((dev_out = dev_get_by_name(route_info->oif))) {
9825 + ifindex = dev_out->ifindex;
9827 + /* Unknown interface name : packet dropped */
9828 + if (net_ratelimit())
9829 + DEBUGP("ipt_ROUTE: oif interface %s not found\n", route_info->oif);
9833 + /* Trying the standard way of routing packets */
9834 + switch (route(skb, ifindex, route_info)) {
9837 + if (route_info->flags & IPT_ROUTE_CONTINUE)
9838 + return IPT_CONTINUE;
9840 + ip_direct_send(skb);
9844 + /* Failed to send to oif. Trying the hard way */
9845 + if (route_info->flags & IPT_ROUTE_CONTINUE)
9848 + if (net_ratelimit())
9849 + DEBUGP("ipt_ROUTE: forcing the use of %i\n",
9852 + /* We have to force the use of an interface.
9853 + * This interface must be a tunnel interface since
9854 + * otherwise we can't guess the hw address for
9855 + * the packet. For a tunnel interface, no hw address
9858 + if ((dev_out->type != ARPHRD_TUNNEL)
9859 + && (dev_out->type != ARPHRD_IPGRE)) {
9860 + if (net_ratelimit())
9861 + DEBUGP("ipt_ROUTE: can't guess the hw addr !\n");
9866 + /* Send the packet. This will also free skb
9867 + * Do not go through the POST_ROUTING hook because
9868 + * skb->dst is not set and because it will probably
9869 + * get confused by the destination IP address.
9871 + skb->dev = dev_out;
9872 + dev_direct_send(skb);
9877 + /* Unexpected error */
9884 +static unsigned int route_iif(const struct ipt_route_target_info *route_info,
9885 + struct sk_buff *skb)
9887 + struct net_device *dev_in = NULL;
9889 + /* Getting the current interface index. */
9890 + if (!(dev_in = dev_get_by_name(route_info->iif))) {
9891 + if (net_ratelimit())
9892 + DEBUGP("ipt_ROUTE: iif interface %s not found\n", route_info->iif);
9896 + skb->dev = dev_in;
9897 + dst_release(skb->dst);
9906 +static unsigned int route_gw(const struct ipt_route_target_info *route_info,
9907 + struct sk_buff *skb)
9909 + if (route(skb, 0, route_info)!=1)
9912 + if (route_info->flags & IPT_ROUTE_CONTINUE)
9913 + return IPT_CONTINUE;
9915 + ip_direct_send(skb);
9920 +static unsigned int ipt_route_target(struct sk_buff **pskb,
9921 + const struct net_device *in,
9922 + const struct net_device *out,
9923 + unsigned int hooknum,
9924 + const void *targinfo,
9927 + const struct ipt_route_target_info *route_info = targinfo;
9928 + struct sk_buff *skb = *pskb;
9930 + /* If we are at PREROUTING or INPUT hook
9931 + * the TTL isn't decreased by the IP stack
9933 + if (hooknum == NF_IP_PRE_ROUTING ||
9934 + hooknum == NF_IP_LOCAL_IN) {
9936 + struct iphdr *iph = skb->nh.iph;
9938 + if (iph->ttl <= 1) {
9939 + struct rtable *rt;
9940 + struct flowi fl = {
9944 + .daddr = iph->daddr,
9945 + .saddr = iph->saddr,
9946 + .tos = RT_TOS(iph->tos),
9947 + .scope = ((iph->tos & RTO_ONLINK) ?
9949 + RT_SCOPE_UNIVERSE)
9954 + if (ip_route_output_key(&rt, &fl)) {
9958 + if (skb->dev == rt->u.dst.dev) {
9959 + /* Drop old route. */
9960 + dst_release(skb->dst);
9961 + skb->dst = &rt->u.dst;
9963 + /* this will traverse normal stack, and
9964 + * thus call conntrack on the icmp packet */
9965 + icmp_send(skb, ICMP_TIME_EXCEEDED,
9973 + * If we are at INPUT the checksum must be recalculated since
9974 + * the length could change as the result of a defragmentation.
9976 + if(hooknum == NF_IP_LOCAL_IN) {
9977 + iph->ttl = iph->ttl - 1;
9979 + iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);
9981 + ip_decrease_ttl(iph);
9985 + /* Tell conntrack to forget this packet since it may get confused
9986 + * when a packet is leaving with dst address == our address.
9987 + * Good idea ? Dunno. Need advice.
9989 + if (!(route_info->flags & IPT_ROUTE_CONTINUE)) {
9990 + nf_conntrack_put(skb->nfct);
9993 +#ifdef CONFIG_NETFILTER_DEBUG
9994 + skb->nf_debug = 0;
9998 + if (route_info->oif[0] != '\0')
9999 + return route_oif(route_info, *pskb);
10001 + if (route_info->iif[0] != '\0')
10002 + return route_iif(route_info, *pskb);
10004 + if (route_info->gw)
10005 + return route_gw(route_info, *pskb);
10007 + if (net_ratelimit())
10008 + DEBUGP(KERN_DEBUG "ipt_ROUTE: no parameter !\n");
10010 + return IPT_CONTINUE;
10014 +static int ipt_route_checkentry(const char *tablename,
10015 + const struct ipt_entry *e,
10017 + unsigned int targinfosize,
10018 + unsigned int hook_mask)
10020 + if (strcmp(tablename, "mangle") != 0) {
10021 + printk("ipt_ROUTE: bad table `%s', use the `mangle' table.\n",
10026 + if (hook_mask & ~( (1 << NF_IP_PRE_ROUTING)
10027 + | (1 << NF_IP_LOCAL_IN)
10028 + | (1 << NF_IP_FORWARD)
10029 + | (1 << NF_IP_LOCAL_OUT)
10030 + | (1 << NF_IP_POST_ROUTING))) {
10031 + printk("ipt_ROUTE: bad hook\n");
10035 + if (targinfosize != IPT_ALIGN(sizeof(struct ipt_route_target_info))) {
10036 + printk(KERN_WARNING "ipt_ROUTE: targinfosize %u != %Zu\n",
10038 + IPT_ALIGN(sizeof(struct ipt_route_target_info)));
10046 +static struct ipt_target ipt_route_reg = {
10048 + .target = ipt_route_target,
10049 + .checkentry = ipt_route_checkentry,
10050 + .me = THIS_MODULE,
10053 +static int __init init(void)
10055 + return ipt_register_target(&ipt_route_reg);
10059 +static void __exit fini(void)
10061 + ipt_unregister_target(&ipt_route_reg);
10064 +module_init(init);
10065 +module_exit(fini);
10066 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_TARPIT.c linux-2.6.6/net/ipv4/netfilter/ipt_TARPIT.c
10067 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_TARPIT.c 1970-01-01 01:00:00.000000000 +0100
10068 +++ linux-2.6.6/net/ipv4/netfilter/ipt_TARPIT.c 2004-05-18 14:28:50.000000000 +0200
10071 + * Kernel module to capture and hold incoming TCP connections using
10072 + * no local per-connection resources.
10074 + * Based on ipt_REJECT.c and offering functionality similar to
10075 + * LaBrea <http://www.hackbusters.net/LaBrea/>.
10077 + * Copyright (c) 2002 Aaron Hopkins <tools@die.net>
10079 + * This program is free software; you can redistribute it and/or modify
10080 + * it under the terms of the GNU General Public License as published by
10081 + * the Free Software Foundation; either version 2 of the License, or
10082 + * (at your option) any later version.
10084 + * This program is distributed in the hope that it will be useful,
10085 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10086 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10087 + * GNU General Public License for more details.
10089 + * You should have received a copy of the GNU General Public License
10090 + * along with this program; if not, write to the Free Software
10091 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
10094 + * - Allow incoming TCP connections to be established.
10095 + * - Passing data should result in the connection being switched to the
10096 + * persist state (0 byte window), in which the remote side stops sending
10097 + * data and asks to continue every 60 seconds.
10098 + * - Attempts to shut down the connection should be ignored completely, so
10099 + * the remote side ends up having to time it out.
10102 + * - Reply to TCP SYN,!ACK,!RST,!FIN with SYN-ACK, window 5 bytes
10103 + * - Reply to TCP SYN,ACK,!RST,!FIN with RST to prevent spoofing
10104 + * - Reply to TCP !SYN,!RST,!FIN with ACK, window 0 bytes, rate-limited
10107 +#include <linux/config.h>
10108 +#include <linux/module.h>
10109 +#include <linux/skbuff.h>
10110 +#include <linux/ip.h>
10111 +#include <net/ip.h>
10112 +#include <net/tcp.h>
10113 +#include <net/icmp.h>
10115 +#include <net/route.h>
10116 +#include <linux/random.h>
10117 +#include <linux/netfilter_ipv4/ip_tables.h>
10120 +#define DEBUGP printk
10122 +#define DEBUGP(format, args...)
10125 +MODULE_LICENSE("GPL");
10126 +MODULE_AUTHOR("Aaron Hopkins <tools@die.net>");
10128 +/* Stolen from ip_finish_output2 */
10129 +static int ip_direct_send(struct sk_buff *skb)
10131 + struct dst_entry *dst = skb->dst;
10132 + struct hh_cache *hh = dst->hh;
10135 + read_lock_bh(&hh->hh_lock);
10136 + memcpy(skb->data - 16, hh->hh_data, 16);
10137 + read_unlock_bh(&hh->hh_lock);
10138 + skb_push(skb, hh->hh_len);
10139 + return hh->hh_output(skb);
10140 + } else if (dst->neighbour)
10141 + return dst->neighbour->output(skb);
10143 + if (net_ratelimit())
10144 + printk(KERN_DEBUG "TARPIT ip_direct_send: no header cache and no neighbor!\n");
10151 +static void tarpit_tcp(struct sk_buff *oskb,struct rtable *ort,int local)
10153 + struct sk_buff *nskb;
10154 + struct rtable *nrt;
10155 + struct tcphdr *otcph, *ntcph;
10156 + struct flowi fl = {};
10157 + unsigned int otcplen;
10160 + /* A truncated TCP header isn't going to be useful */
10161 + if (oskb->len < (oskb->nh.iph->ihl*4) + sizeof(struct tcphdr))
10164 + otcph = (struct tcphdr *)((u_int32_t*)oskb->nh.iph
10165 + + oskb->nh.iph->ihl);
10166 + otcplen = oskb->len - oskb->nh.iph->ihl*4;
10168 + /* No replies for RST or FIN */
10169 + if (otcph->rst || otcph->fin)
10172 + /* No reply to !SYN,!ACK. Rate-limit replies to !SYN,ACKs */
10173 + if (!otcph->syn && (!otcph->ack || !xrlim_allow(&ort->u.dst, 1*HZ)))
10176 + /* Check checksum. */
10177 + if (tcp_v4_check(otcph, otcplen, oskb->nh.iph->saddr,
10178 + oskb->nh.iph->daddr,
10179 + csum_partial((char *)otcph, otcplen, 0)) != 0)
10182 + /* Copy skb (even if skb is about to be dropped, we can't just
10183 + clone it because there may be other things, such as tcpdump,
10184 + interested in it) */
10185 + nskb = skb_copy(oskb, GFP_ATOMIC);
10189 + /* This packet will not be the same as the other: clear nf fields */
10190 + nf_conntrack_put(nskb->nfct);
10191 + nskb->nfct = NULL;
10192 + nskb->nfcache = 0;
10193 +#ifdef CONFIG_NETFILTER_DEBUG
10194 + nskb->nf_debug = 0;
10197 + ntcph = (struct tcphdr *)((u_int32_t*)nskb->nh.iph + nskb->nh.iph->ihl);
10199 + /* Truncate to length (no data) */
10200 + ntcph->doff = sizeof(struct tcphdr)/4;
10201 + skb_trim(nskb, nskb->nh.iph->ihl*4 + sizeof(struct tcphdr));
10202 + nskb->nh.iph->tot_len = htons(nskb->len);
10204 + /* Swap source and dest */
10205 + nskb->nh.iph->daddr = xchg(&nskb->nh.iph->saddr, nskb->nh.iph->daddr);
10206 + tmp = ntcph->source;
10207 + ntcph->source = ntcph->dest;
10208 + ntcph->dest = tmp;
10210 + /* Use supplied sequence number or make a new one */
10211 + ntcph->seq = otcph->ack ? otcph->ack_seq
10212 + : htonl(secure_tcp_sequence_number(nskb->nh.iph->saddr,
10213 + nskb->nh.iph->daddr,
10217 + /* Our SYN-ACKs must have a >0 window */
10218 + ntcph->window = (otcph->syn && !otcph->ack) ? htons(5) : 0;
10220 + ntcph->urg_ptr = 0;
10222 + /* Reset flags */
10223 + ((u_int8_t *)ntcph)[13] = 0;
10225 + if (otcph->syn && otcph->ack) {
10227 + ntcph->ack_seq = 0;
10229 + ntcph->syn = otcph->syn;
10231 + ntcph->ack_seq = htonl(ntohl(otcph->seq) + otcph->syn);
10234 + /* Adjust TCP checksum */
10235 + ntcph->check = 0;
10236 + ntcph->check = tcp_v4_check(ntcph, sizeof(struct tcphdr),
10237 + nskb->nh.iph->saddr,
10238 + nskb->nh.iph->daddr,
10239 + csum_partial((char *)ntcph,
10240 + sizeof(struct tcphdr), 0));
10242 + /* Adjust IP TTL */
10243 + nskb->nh.iph->ttl = sysctl_ip_default_ttl;
10245 + /* Set DF, id = 0 */
10246 + nskb->nh.iph->frag_off = htons(IP_DF);
10247 + nskb->nh.iph->id = 0;
10249 + /* Adjust IP checksum */
10250 + nskb->nh.iph->check = 0;
10251 + nskb->nh.iph->check = ip_fast_csum((unsigned char *)nskb->nh.iph,
10252 + nskb->nh.iph->ihl);
10254 + fl.nl_u.ip4_u.daddr = nskb->nh.iph->daddr;
10255 + fl.nl_u.ip4_u.saddr = local ? nskb->nh.iph->saddr : 0;
10256 + fl.nl_u.ip4_u.tos = RT_TOS(nskb->nh.iph->tos) | RTO_CONN;
10259 + if (ip_route_output_key(&nrt, &fl))
10262 + dst_release(nskb->dst);
10263 + nskb->dst = &nrt->u.dst;
10265 + /* "Never happens" */
10266 + if (nskb->len > dst_pmtu(nskb->dst))
10269 + ip_direct_send (nskb);
10278 +static unsigned int tarpit(struct sk_buff **pskb,
10279 + const struct net_device *in,
10280 + const struct net_device *out,
10281 + unsigned int hooknum,
10282 + const void *targinfo,
10285 + struct sk_buff *skb = *pskb;
10286 + struct rtable *rt = (struct rtable*)skb->dst;
10288 + /* Do we have an input route cache entry? */
10292 + /* No replies to physical multicast/broadcast */
10293 + if (skb->pkt_type != PACKET_HOST && skb->pkt_type != PACKET_OTHERHOST)
10296 + /* Now check at the protocol level */
10297 + if (rt->rt_flags&(RTCF_BROADCAST|RTCF_MULTICAST))
10300 + /* Our naive response construction doesn't deal with IP
10301 + options, and probably shouldn't try. */
10302 + if (skb->nh.iph->ihl*4 != sizeof(struct iphdr))
10305 + /* We aren't interested in fragments */
10306 + if (skb->nh.iph->frag_off & htons(IP_OFFSET))
10309 + tarpit_tcp(skb,rt,hooknum == NF_IP_LOCAL_IN);
10315 +static int check(const char *tablename,
10316 + const struct ipt_entry *e,
10318 + unsigned int targinfosize,
10319 + unsigned int hook_mask)
10321 + /* Only allow these for input/forward packet filtering. */
10322 + if (strcmp(tablename, "filter") != 0) {
10323 + DEBUGP("TARPIT: bad table %s'.\n", tablename);
10326 + if ((hook_mask & ~((1 << NF_IP_LOCAL_IN)
10327 + | (1 << NF_IP_FORWARD))) != 0) {
10328 + DEBUGP("TARPIT: bad hook mask %X\n", hook_mask);
10332 + /* Must specify that it's a TCP packet */
10333 + if (e->ip.proto != IPPROTO_TCP || (e->ip.invflags & IPT_INV_PROTO)) {
10334 + DEBUGP("TARPIT: not valid for non-tcp\n");
10341 +static struct ipt_target ipt_tarpit_reg = {
10342 + .name = "TARPIT",
10343 + .target = tarpit,
10344 + .checkentry = check,
10345 + .me = THIS_MODULE
10348 +static int __init init(void)
10350 + return ipt_register_target(&ipt_tarpit_reg);
10353 +static void __exit fini(void)
10355 + ipt_unregister_target(&ipt_tarpit_reg);
10358 +module_init(init);
10359 +module_exit(fini);
10360 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_TCPLAG.c linux-2.6.6/net/ipv4/netfilter/ipt_TCPLAG.c
10361 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_TCPLAG.c 1970-01-01 01:00:00.000000000 +0100
10362 +++ linux-2.6.6/net/ipv4/netfilter/ipt_TCPLAG.c 2004-05-18 14:28:50.000000000 +0200
10364 +/* ipt_TCPLAG.c -- kernel module to implement TCPLAG target into netfilter
10365 + * Copyright (C) 2002 Telford Tendys <telford@triode.net.au>
10367 + * This program is free software; you can redistribute it and/or modify
10368 + * it under the terms of the GNU General Public License as published by
10369 + * the Free Software Foundation; either version 2 of the License, or
10370 + * (at your option) any later version.
10372 + * This program is distributed in the hope that it will be useful,
10373 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10374 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10375 + * GNU General Public License for more details.
10377 + * You should have received a copy of the GNU General Public License
10378 + * along with this program; if not, write to the Free Software
10379 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
10383 + * This collects packets and attempts to make them into pairs
10384 + * based on its own knowledge of how typical network conversations
10385 + * operate. Once it has a pair, it logs the time between them.
10387 +#include <linux/module.h>
10388 +#include <linux/skbuff.h>
10389 +#include <linux/ip.h>
10390 +#include <linux/spinlock.h>
10391 +#include <net/icmp.h>
10392 +#include <net/udp.h>
10393 +#include <net/tcp.h>
10394 +#include <linux/netfilter_ipv4/ip_tables.h>
10396 +#include <net/route.h>
10397 +#include <linux/netfilter_ipv4/ipt_TCPLAG.h>
10400 +#define DEBUGP printk
10402 +#define DEBUGP(format, args...)
10406 + * We need one spinlock for the hash table.
10408 +static spinlock_t hash_lock = SPIN_LOCK_UNLOCKED;
10410 +typedef struct timeval timeval_T;
10413 + * Linked lists of events in the connection,
10414 + * these store the SEQ numbers and the newest is always
10415 + * at the start of the linked list, then they get older
10416 + * down to the end of the linked list (this is not perfect
10417 + * if packets get out of order but we don't worry about fine
10418 + * details like that).
10420 + * Matching any event wipes out that event and also all other
10421 + * events down the chain (i.e. all older events).
10422 + * This keeps the linked list as short as possible.
10424 +typedef struct tcplag_event_S
10426 + struct tcplag_event_S *next;
10429 + u32 expected_ACK;
10430 + struct timeval stamp;
10434 + * This stores the connection statistics
10435 + * We define connections more loosely than TCP/IP does,
10436 + * because we only consider the two hosts, not the ports
10437 + * Also, we list the host-pairs in low,high order which
10438 + * means that we don't care who originated the connection.
10440 +typedef struct tcplag_hash_S
10444 + struct timeval lag_l_SEQ_h_ACK; /* l sends some data and h acknowledges that (sum of lag times) */
10445 + struct timeval lag_h_SEQ_l_ACK; /* h sends some data and l acknowledges that (sum of lag times) */
10446 + tcplag_event_T *h_ACK_list; /* Try to match ACK packets coming from h in this list */
10447 + tcplag_event_T *l_ACK_list; /* Try to match ACK packets coming from l in this list */
10448 + time_t stamp; /* When this bucket got added to the table */
10449 + u16 count_l_SEQ_h_ACK; /* Increment for each event */
10450 + u16 count_h_SEQ_l_ACK; /* Increment for each event */
10453 +static tcplag_hash_T **hashtab = 0;
10454 +static u32 hashsize = 0;
10455 +static u16 max_seconds = 30; /* Empty a hash bucket after this time */
10456 +static u32 reaper_ix = 0;
10458 +static void divide_down( timeval_T *T, int c )
10463 + remainder = T->tv_sec % c; /* Only works properly with positive numbers */
10464 + remainder *= 1000000;
10465 + T->tv_usec == remainder;
10469 +int diff_timeval( timeval_T *tv1, timeval_T *tv2 )
10473 + x = tv1->tv_sec - tv2->tv_sec;
10474 + if( x ) return( x );
10475 + x = tv1->tv_usec - tv2->tv_usec;
10479 +void sprint_timeval( char *buf, timeval_T *tv )
10482 + sprintf( buf, "%lu%06lu", tv->tv_sec, tv->tv_usec );
10484 + sprintf( buf, "%lu", tv->tv_usec );
10488 + * This generates the log messages through printk()
10490 + * There is really no particular interest in the port numbers at this stage,
10491 + * they are only useful for matching up the request with the reply.
10492 + * The IP numbers are useful because some sites may be slower than others
10493 + * or may travel different routes, etc (OK, in theory changing the port number
10494 + * could also change the route but I don't like that sort of theory).
10498 + * LIP= The IP number of the side with the lowest lag
10499 + * RIP= The IP number of the side with the highest lag
10500 + * LLAG= The average time (in us) between RIP->LIP SEQ and LIP->RIP ACK
10501 + * RLAG= The average time (in us) between LIP->RIP SEQ and RIP->LIP ACK
10503 +static void output( tcplag_hash_T *H, int level, const char *prefix )
10505 + struct timeval ltm, rtm;
10506 + u32 local_ip, remote_ip;
10507 + char r_buf[ 20 ], l_buf[ 20 ];
10509 + * We can't make sense of a connection that only passes data one way,
10510 + * In principle, at least the SYN and FIN should go both ways so we
10511 + * should get a few hits for every connection.
10513 + if( 0 == H->count_l_SEQ_h_ACK || 0 == H->count_h_SEQ_l_ACK ) return;
10515 + * Calculate average times by dividing down
10517 + divide_down( &H->lag_l_SEQ_h_ACK, H->count_l_SEQ_h_ACK );
10518 + divide_down( &H->lag_h_SEQ_l_ACK, H->count_h_SEQ_l_ACK );
10520 + * Sort these two by the lag so the the local is always the short lag
10522 + if( diff_timeval( &H->lag_l_SEQ_h_ACK, &H->lag_h_SEQ_l_ACK ) > 0 )
10524 + local_ip = H->low_ip;
10525 + remote_ip = H->high_ip;
10526 + rtm.tv_sec = H->lag_l_SEQ_h_ACK.tv_sec;
10527 + rtm.tv_usec = H->lag_l_SEQ_h_ACK.tv_usec;
10528 + ltm.tv_sec = H->lag_h_SEQ_l_ACK.tv_sec;
10529 + ltm.tv_usec = H->lag_h_SEQ_l_ACK.tv_usec;
10533 + local_ip = H->high_ip;
10534 + remote_ip = H->low_ip;
10535 + ltm.tv_sec = H->lag_l_SEQ_h_ACK.tv_sec;
10536 + ltm.tv_usec = H->lag_l_SEQ_h_ACK.tv_usec;
10537 + rtm.tv_sec = H->lag_h_SEQ_l_ACK.tv_sec;
10538 + rtm.tv_usec = H->lag_h_SEQ_l_ACK.tv_usec;
10541 + * Don't use a spinlock on the output,
10542 + * it is not guaranteed safe because some OTHER printk could
10543 + * split our log message so we want only one single printk.
10545 + * We use sprintf() to partially pre-digest the output
10547 + * Actually, neither this not the main netfilter LOG target is
10548 + * really safe from printk() overlap, basically syslog cannot
10549 + * be regarded as a guaranteed data output channel. It is good
10550 + * enough for most purposes.
10552 + sprint_timeval( l_buf, <m );
10553 + sprint_timeval( r_buf, &rtm );
10554 + printk( "<%d>%sLIP=%u.%u.%u.%u RIP=%u.%u.%u.%u LLAG=%s RLAG=%s\n",
10555 + level & 7, prefix,
10556 + NIPQUAD( local_ip ), NIPQUAD( remote_ip ),
10561 + * The reaper rolls through the hash table looking for old.
10562 + * Log entries are only generated at the reaping time
10563 + * (which means all log entries are out-of-date)
10565 +static void reaper( time_t now, int level, const char *prefix )
10569 + now -= max_seconds;
10570 + if( !hashsize ) return;
10571 + if( !hashtab ) return;
10572 + for( i = 0; i < 10; i++ )
10574 + if( ++reaper_ix >= hashsize ) reaper_ix = 0;
10576 +// DEBUGP( KERN_WARNING "reaper checking %u\n", reaper_ix );
10578 + if( hashtab[ reaper_ix ])
10580 + tcplag_hash_T *found = 0;
10582 + spin_lock_bh( &hash_lock );
10583 + if( hashtab[ reaper_ix ])
10585 + if( now > hashtab[ reaper_ix ]->stamp )
10587 + DEBUGP( KERN_WARNING "reaper found expired entry\n" );
10588 + found = hashtab[ reaper_ix ];
10589 + hashtab[ reaper_ix ] = 0;
10592 + spin_unlock_bh( &hash_lock );
10596 + output( found, level, prefix );
10604 + * Convert the connection characteristics into a number
10605 + * (not including the timestamp) FIXME: this is a sucky hash function
10607 +static u32 make_hash( tcplag_hash_T *connection )
10611 + r = connection->low_ip;
10612 + r += connection->high_ip;
10616 +static int compare_connections( tcplag_hash_T *con1, tcplag_hash_T *con2 )
10620 + x = con1->low_ip - con2->low_ip; if( x ) return( x );
10621 + x = con1->high_ip - con2->high_ip;
10625 +static int compare_events( tcplag_event_T *ev1, tcplag_event_T *ev2 )
10629 + DEBUGP( "Comparing sequence %u to %u\n", ev1->expected_ACK, ev2->expected_ACK );
10630 + x = ev1->expected_ACK - ev2->expected_ACK;
10631 + if( x ) return( x );
10632 + DEBUGP( "Comparing source port %u to %u\n", ev1->source_port, ev2->source_port );
10633 + x = ev1->source_port - ev2->source_port;
10634 + if( x ) return( x );
10635 + DEBUGP( "Comparing destination port %u to %u\n", ev1->dest_port, ev2->dest_port );
10636 + x = ev1->dest_port - ev2->dest_port;
10641 + * Go to the hash table and either find an existing connection that
10642 + * matches correctly or inject a new connection into the table.
10643 + * Once the connection is OK, chain the event onto the linked list.
10645 +static void hash_insert( tcplag_hash_T *connection, tcplag_event_T *event, int direction )
10649 + if( !event ) return; /* Just to be safe */
10650 + if( !hashsize ) return;
10651 + if( !hashtab ) return;
10653 + h = make_hash( connection );
10656 + DEBUGP( KERN_WARNING "hash_insert( %u )\n", h );
10658 + spin_lock_bh( &hash_lock );
10659 + for( i = 0; i < hashsize; i++, ({ if( ++h >= hashsize ) { h = 0; }}))
10661 + tcplag_hash_T *co_new = 0;
10663 + * Consider existing entry
10665 + if( hashtab[ h ])
10667 + if( compare_connections( hashtab[ h ], connection )) continue;
10668 + co_new = hashtab[ h ];
10669 + DEBUGP( KERN_WARNING "Existing connection at %u\n", h );
10673 + * Use empty slot for new entry
10675 + if( !hashtab[ h ])
10677 + co_new = kmalloc( sizeof( tcplag_hash_T ), GFP_ATOMIC );
10678 + memset( co_new, 0, sizeof( tcplag_hash_T ));
10679 + co_new->low_ip = connection->low_ip;
10680 + co_new->high_ip = connection->high_ip;
10681 + co_new->stamp = event->stamp.tv_sec;
10682 + hashtab[ h ] = co_new;
10683 + DEBUGP( KERN_WARNING "Added connection to table at %u\n", h );
10686 + tcplag_event_T *ev_new;
10688 + ev_new = kmalloc( sizeof( tcplag_event_T ), GFP_ATOMIC );
10689 + memcpy( ev_new, event, sizeof( tcplag_event_T ));
10692 + ev_new->next = co_new->h_ACK_list;
10693 + co_new->h_ACK_list = ev_new;
10694 + DEBUGP( KERN_WARNING "Connection at %u, direction is h_ACK_list\n", h );
10698 + ev_new->next = co_new->l_ACK_list;
10699 + co_new->l_ACK_list = ev_new;
10700 + DEBUGP( KERN_WARNING "Connection at %u, direction is l_ACK_list\n", h );
10707 + spin_unlock_bh( &hash_lock );
10711 + * Search the hash table for a matching connection,
10712 + * if we can't find one of those then we are stuffed.
10714 + * Once a connection has been found, scan along the list for
10715 + * a matching SEQ number and if that is found then calculate
10716 + * the lag, update the counters and cut the chain at the
10717 + * point where the matching SEQ is found.
10719 +static int request_complete( tcplag_hash_T *connection, tcplag_event_T *event, int direction )
10723 + if( !event ) return( 0 );
10724 + if( !hashsize ) return( 0 );
10725 + if( !hashtab ) return( 0 );
10726 + h = make_hash( connection );
10729 + DEBUGP( KERN_WARNING "request_complete( %u )\n", h );
10731 + for( i = 0; i < hashsize; i++ )
10733 + tcplag_hash_T *found = 0;
10735 + if( !hashtab[ h ]) return( 0 );
10737 + spin_lock_bh( &hash_lock );
10738 + if( hashtab[ h ])
10740 + if( !compare_connections( hashtab[ h ], connection ))
10742 + tcplag_event_T *ev, **evroot;
10746 + found = hashtab[ h ];
10749 + evroot = &found->h_ACK_list;
10750 + tv = &found->lag_l_SEQ_h_ACK;
10751 + cn = &found->count_l_SEQ_h_ACK;
10752 + DEBUGP( KERN_WARNING "Connection at %u, direction is h_ACK_list\n", h );
10756 + evroot = &found->l_ACK_list;
10757 + tv = &found->lag_h_SEQ_l_ACK;
10758 + cn = &found->count_h_SEQ_l_ACK;
10759 + DEBUGP( KERN_WARNING "Connection at %u, direction is l_ACK_list\n", h );
10761 + for( ev = *evroot; ev; ev = ev->next )
10763 + if( !compare_events( ev, event ))
10766 + * Calculate the lag (in two parts) and add that to the collection
10768 + event->stamp.tv_sec -= ev->stamp.tv_sec;
10769 + event->stamp.tv_usec -= ev->stamp.tv_usec;
10770 + if( event->stamp.tv_usec < 0 )
10772 + event->stamp.tv_usec += 1000000;
10773 + event->stamp.tv_sec++;
10775 + if( event->stamp.tv_sec < 0 )
10777 + DEBUGP( KERN_WARNING "Negative lag detected\n" );
10781 + tv->tv_sec += event->stamp.tv_sec;
10782 + tv->tv_usec += event->stamp.tv_usec;
10784 + DEBUGP( KERN_WARNING "Found a match, added %lu.%06lu"
10785 + " (accumulator is up to %lu.%06lu, %u events)\n",
10786 + event->stamp.tv_sec,
10787 + event->stamp.tv_usec,
10788 + tv->tv_sec, tv->tv_usec, *cn );
10791 + * Truncate the linked list.
10793 + * Visit each event in the list and return the memory to the pool.
10795 + * If a host is making multiple connections to the same remote host
10796 + * then this truncation will result in some requests not being
10797 + * monitored. Statistically we will still get some reasonable number
10798 + * of measurements and multiple simultaneous connections between host
10799 + * pairs don't happen all that often.
10804 + tcplag_event_T *ev_next = ev->next;
10805 + DEBUGP( KERN_WARNING "Shitcan %u\n", ev->expected_ACK );
10810 + * TODO: overflow limit for *cn, force premature output() if necessary
10811 + * (and drop this connection from the hash table)
10820 + spin_unlock_bh( &hash_lock );
10822 + if( found ) return( 1 );
10823 + if( ++h >= hashsize ) h = 0;
10829 + * Here is our target data:
10831 + * pskb -- The packet itself (see linux/skbuff.h for breakdown)
10835 + * in -- The device that this packet came in on
10836 + * (depending on the chain this may or may not exist)
10838 + * out -- The device that this packet is just about to go
10839 + * out onto (again existance depends on the chain)
10841 + * targinfo -- Our private data (handed through from iptables command util)
10843 + * userinfo -- Some more data
10847 +static unsigned int target( struct sk_buff **pskb,
10848 + unsigned int hooknum,
10849 + const struct net_device *in,
10850 + const struct net_device *out,
10851 + const void *targinfo,
10854 + struct iphdr *iph = ( *pskb )->nh.iph;
10855 + const struct ipt_tcplag *el = targinfo;
10856 + tcplag_hash_T connection;
10857 + tcplag_event_T event;
10860 + * We know we are dealing with IP here
10861 + * Fill in all the obvious fields
10863 + if( iph->saddr > iph->daddr )
10866 + connection.high_ip = iph->saddr;
10867 + connection.low_ip = iph->daddr;
10872 + connection.low_ip = iph->saddr;
10873 + connection.high_ip = iph->daddr;
10875 + do_gettimeofday( &event.stamp );
10877 + * Do a bit of cleaning
10879 + reaper( event.stamp.tv_sec, el->level, el->prefix );
10881 + DEBUGP( KERN_WARNING "got packet %lu %lu %s %s\n",
10882 + event.stamp.tv_sec,
10883 + event.stamp.tv_usec,
10884 + in ? in->name : "none", out ? out->name : "none" );
10886 + * Now start looking at the details
10888 + * First step is to identify this packet to see if it is
10889 + * the sort of packet that we are interested in.
10890 + * Don't hold any locks while we are doing this because often
10891 + * we will just let the packet go without any further consideration.
10893 + switch( iph->protocol )
10895 + case IPPROTO_TCP:
10897 + struct tcphdr *tcp;
10899 + if( ntohs( iph->frag_off ) & IP_OFFSET )
10901 + DEBUGP( KERN_WARNING "ignoring fragment\n" );
10904 + tcp = (struct tcphdr *)((u32 *)iph + iph->ihl );
10905 + event.source_port = ntohs( tcp->source );
10906 + event.dest_port = ntohs( tcp->dest );
10908 + * Every packet should have a valid SEQ number so use this to
10909 + * generate an ACK number. This works along the formula:
10910 + * -- Start with the SEQ number
10911 + * -- For SYN or FIN add 1 to that number
10912 + * -- For data packet, add the data length to that number
10916 + * Data length requires a bit of fiddling around
10919 + unsigned int data_len;
10920 + if( tcp->syn || tcp->fin )
10922 + data_len = 1; /* Not real data, the SEQ clicks forward by 1 */
10926 + data_len = ntohs( iph->tot_len );
10927 + data_len -= 4 * iph->ihl; /* Subtract away IP header & options */
10928 + data_len -= 4 * tcp->doff; /* Subtract away TCP header & options */
10931 + DEBUGP( KERN_WARNING "Data length calculated at %u\n", data_len );
10933 + if( data_len ) /* Only track events that demand an ACK */
10935 + event.expected_ACK = ntohl( tcp->seq ) + data_len;
10936 + hash_insert( &connection, &event, direction );
10940 + DEBUGP( "Don't bother to insert this, ACK not required\n" );
10947 + * Now we consider the matching of an existing event.
10948 + * Reverse the port numbers and change the ACK number to the actual ACK number
10949 + * Note that the direction is reversed because the reply will be going
10950 + * the opposite way to the request.
10952 + event.expected_ACK = ntohl( tcp->ack_seq );
10953 + event.dest_port = ntohs( tcp->source );
10954 + event.source_port = ntohs( tcp->dest );
10955 + request_complete( &connection, &event, !direction );
10959 + DEBUGP( "Don't bother to check this, ACK not valid\n" );
10963 + return( IPT_CONTINUE );
10967 + * return( 0 ) if there is a problem with this entry (i.e. kick it out of the kernel)
10968 + * return( 1 ) if the entry is suitable
10974 + * targinfo -- Our private data block (handed to us from iptables plug-in)
10976 + * targinfosize -- The size of our private data block
10981 + * Not much can go wrong for us, any illegal flags are harmlessly ignored,
10982 + * all possible flag combos make sense. All we check for is correct data size.
10984 +static int checkentry( const char *tablename,
10985 + const struct ipt_entry *e,
10987 + unsigned int targinfosize,
10988 + unsigned int hook_mask )
10990 + const struct ipt_tcplag *el = targinfo;
10992 + if( targinfosize != IPT_ALIGN( sizeof( struct ipt_tcplag )))
10994 + DEBUGP( "TCPLAG: targinfosize %u != %u\n", targinfosize,
10995 + IPT_ALIGN( sizeof( struct ipt_tcplag )));
10998 + if( el->prefix[ 14 ]) return( 0 ); /* Be sure to have terminated string */
11002 +static struct ipt_target reg =
11012 +static int __init init( void )
11014 + if( ipt_register_target( ® )) return( -EINVAL );
11015 + hashsize = 123; /* should be configurable */
11016 + hashtab = kmalloc( sizeof( void * ) * hashsize, GFP_ATOMIC );
11017 + memset( hashtab, 0, sizeof( void * ) * hashsize );
11022 + * This should not need locks (in theory)
11023 + * because it can only get punted after it is no longer
11024 + * chained into any of the netfilter lists.
11026 +static void __exit fini( void )
11030 + ipt_unregister_target( ® );
11032 + * Put back kernel memory
11034 + for( i = 0; i < hashsize; i++ )
11036 + tcplag_hash_T *p;
11038 + if(( p = hashtab[ i ]))
11040 + tcplag_event_T *ev, *evn;
11042 + hashtab[ i ] = 0;
11043 + for( ev = p->h_ACK_list; ev; ev = evn )
11048 + for( ev = p->l_ACK_list; ev; ev = evn )
11056 + kfree( hashtab );
11059 +module_init(init);
11060 +module_exit(fini);
11061 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_TRACE.c linux-2.6.6/net/ipv4/netfilter/ipt_TRACE.c
11062 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_TRACE.c 1970-01-01 01:00:00.000000000 +0100
11063 +++ linux-2.6.6/net/ipv4/netfilter/ipt_TRACE.c 2004-05-18 14:28:50.000000000 +0200
11065 +/* This is a module which is used for setting
11066 + * the NFC_TRACE flag in the nfcache field of an skb.
11068 +#include <linux/module.h>
11069 +#include <linux/skbuff.h>
11071 +#include <linux/netfilter_ipv4/ip_tables.h>
11073 +static unsigned int
11074 +target(struct sk_buff **pskb,
11075 + const struct net_device *in,
11076 + const struct net_device *out,
11077 + unsigned int hooknum,
11078 + const void *targinfo,
11081 + (*pskb)->nfcache |= NFC_TRACE;
11082 + return IPT_CONTINUE;
11086 +checkentry(const char *tablename,
11087 + const struct ipt_entry *e,
11089 + unsigned int targinfosize,
11090 + unsigned int hook_mask)
11092 + if (targinfosize != 0) {
11093 + printk(KERN_WARNING "TRACE: targinfosize %u != 0\n",
11098 + if (strcmp(tablename, "raw") != 0) {
11099 + printk(KERN_WARNING "TRACE: can only be called from \"raw\" table, not \"%s\"\n", tablename);
11106 +static struct ipt_target ipt_trace_reg = {
11108 + .target = target,
11109 + .checkentry = checkentry,
11110 + .me = THIS_MODULE
11113 +static int __init init(void)
11115 + if (ipt_register_target(&ipt_trace_reg))
11121 +static void __exit fini(void)
11123 + ipt_unregister_target(&ipt_trace_reg);
11126 +module_init(init);
11127 +module_exit(fini);
11128 +MODULE_LICENSE("GPL");
11129 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_TTL.c linux-2.6.6/net/ipv4/netfilter/ipt_TTL.c
11130 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_TTL.c 1970-01-01 01:00:00.000000000 +0100
11131 +++ linux-2.6.6/net/ipv4/netfilter/ipt_TTL.c 2004-05-18 14:28:50.000000000 +0200
11133 +/* TTL modification target for IP tables
11134 + * (C) 2000 by Harald Welte <laforge@gnumonks.org>
11136 + * Version: $Revision$
11138 + * This software is distributed under the terms of GNU GPL
11141 +#include <linux/module.h>
11142 +#include <linux/skbuff.h>
11143 +#include <linux/ip.h>
11144 +#include <net/checksum.h>
11146 +#include <linux/netfilter_ipv4/ip_tables.h>
11147 +#include <linux/netfilter_ipv4/ipt_TTL.h>
11149 +MODULE_AUTHOR("Harald Welte <laforge@gnumonks.org>");
11150 +MODULE_DESCRIPTION("IP tables TTL modification module");
11151 +MODULE_LICENSE("GPL");
11153 +static unsigned int
11154 +ipt_ttl_target(struct sk_buff **pskb, const struct net_device *in,
11155 + const struct net_device *out, unsigned int hooknum,
11156 + const void *targinfo, void *userinfo)
11158 + struct iphdr *iph;
11159 + const struct ipt_TTL_info *info = targinfo;
11160 + u_int16_t diffs[2];
11163 + if (!skb_ip_make_writable(pskb, (*pskb)->len))
11166 + iph = (*pskb)->nh.iph;
11168 + switch (info->mode) {
11169 + case IPT_TTL_SET:
11170 + new_ttl = info->ttl;
11172 + case IPT_TTL_INC:
11173 + new_ttl = iph->ttl + info->ttl;
11174 + if (new_ttl > 255)
11177 + case IPT_TTL_DEC:
11178 + new_ttl = iph->ttl + info->ttl;
11183 + new_ttl = iph->ttl;
11187 + if (new_ttl != iph->ttl) {
11188 + diffs[0] = htons(((unsigned)iph->ttl) << 8) ^ 0xFFFF;
11189 + iph->ttl = new_ttl;
11190 + diffs[1] = htons(((unsigned)iph->ttl) << 8);
11191 + iph->check = csum_fold(csum_partial((char *)diffs,
11193 + iph->check^0xFFFF));
11194 + (*pskb)->nfcache |= NFC_ALTERED;
11197 + return IPT_CONTINUE;
11200 +static int ipt_ttl_checkentry(const char *tablename,
11201 + const struct ipt_entry *e,
11203 + unsigned int targinfosize,
11204 + unsigned int hook_mask)
11206 + struct ipt_TTL_info *info = targinfo;
11208 + if (targinfosize != IPT_ALIGN(sizeof(struct ipt_TTL_info))) {
11209 + printk(KERN_WARNING "TTL: targinfosize %u != %Zu\n",
11211 + IPT_ALIGN(sizeof(struct ipt_TTL_info)));
11215 + if (strcmp(tablename, "mangle")) {
11216 + printk(KERN_WARNING "TTL: can only be called from \"mangle\" table, not \"%s\"\n", tablename);
11220 + if (info->mode > IPT_TTL_MAXMODE) {
11221 + printk(KERN_WARNING "TTL: invalid or unknown Mode %u\n",
11226 + if ((info->mode != IPT_TTL_SET) && (info->ttl == 0)) {
11227 + printk(KERN_WARNING "TTL: increment/decrement doesn't make sense with value 0\n");
11234 +static struct ipt_target ipt_TTL = {
11236 + .target = ipt_ttl_target,
11237 + .checkentry = ipt_ttl_checkentry,
11238 + .me = THIS_MODULE
11241 +static int __init init(void)
11243 + return ipt_register_target(&ipt_TTL);
11246 +static void __exit fini(void)
11248 + ipt_unregister_target(&ipt_TTL);
11251 +module_init(init);
11252 +module_exit(fini);
11253 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_XOR.c linux-2.6.6/net/ipv4/netfilter/ipt_XOR.c
11254 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_XOR.c 1970-01-01 01:00:00.000000000 +0100
11255 +++ linux-2.6.6/net/ipv4/netfilter/ipt_XOR.c 2004-05-18 14:28:50.000000000 +0200
11257 +/* XOR target for IP tables
11258 + * (C) 2000 by Tim Vandermeersch <Tim.Vandermeersch@pandora.be>
11259 + * Based on ipt_TTL.c
11263 + * This software is distributed under the terms of GNU GPL
11266 +#include <linux/module.h>
11267 +#include <linux/skbuff.h>
11268 +#include <linux/ip.h>
11269 +#include <linux/tcp.h>
11270 +#include <linux/udp.h>
11272 +#include <linux/netfilter_ipv4/ip_tables.h>
11273 +#include <linux/netfilter_ipv4/ipt_XOR.h>
11275 +MODULE_AUTHOR("Tim Vandermeersch <Tim.Vandermeersch@pandora.be>");
11276 +MODULE_DESCRIPTION("IP tables XOR module");
11277 +MODULE_LICENSE("GPL");
11279 +static unsigned int
11280 +ipt_xor_target(struct sk_buff **pskb,
11281 + const struct net_device *in, const struct net_device *out,
11282 + unsigned int hooknum, const void *targinfo, void *userinfo)
11284 + struct ipt_XOR_info *info = (void *) targinfo;
11285 + struct iphdr *iph;
11286 + struct tcphdr *tcph;
11287 + struct udphdr *udph;
11290 + if (!skb_ip_make_writable(pskb, (*pskb)->len))
11293 + iph = (*pskb)->nh.iph;
11295 + if (iph->protocol == IPPROTO_TCP) {
11296 + tcph = (struct tcphdr *) ((*pskb)->data + iph->ihl*4);
11297 + for (i=0, j=0; i<(ntohs(iph->tot_len) - iph->ihl*4 - tcph->doff*4); ) {
11298 + for (k=0; k<=info->block_size; k++) {
11299 + (char) (*pskb)->data[ iph->ihl*4 + tcph->doff*4 + i ] ^=
11304 + if (info->key[j] == 0x00)
11307 + } else if (iph->protocol == IPPROTO_UDP) {
11308 + udph = (struct udphdr *) ((*pskb)->data + iph->ihl*4);
11309 + for (i=0, j=0; i<(ntohs(udph->len)-8); ) {
11310 + for (k=0; k<=info->block_size; k++) {
11311 + (char) (*pskb)->data[ iph->ihl*4 + sizeof(struct udphdr) + i ] ^=
11316 + if (info->key[j] == 0x00)
11321 + return IPT_CONTINUE;
11324 +static int ipt_xor_checkentry(const char *tablename, const struct ipt_entry *e,
11325 + void *targinfo, unsigned int targinfosize,
11326 + unsigned int hook_mask)
11328 + struct ipt_XOR_info *info = targinfo;
11330 + if (targinfosize != IPT_ALIGN(sizeof(struct ipt_XOR_info))) {
11331 + printk(KERN_WARNING "XOR: targinfosize %u != %Zu\n",
11332 + targinfosize, IPT_ALIGN(sizeof(struct ipt_XOR_info)));
11336 + if (strcmp(tablename, "mangle")) {
11337 + printk(KERN_WARNING "XOR: can only be called from"
11338 + "\"mangle\" table, not \"%s\"\n", tablename);
11342 + if (!strcmp(info->key, "")) {
11343 + printk(KERN_WARNING "XOR: You must specify a key");
11347 + if (info->block_size == 0) {
11348 + printk(KERN_WARNING "XOR: You must specify a block-size");
11355 +static struct ipt_target ipt_XOR = {
11357 + .target = ipt_xor_target,
11358 + .checkentry = ipt_xor_checkentry,
11359 + .me = THIS_MODULE,
11362 +static int __init init(void)
11364 + return ipt_register_target(&ipt_XOR);
11367 +static void __exit fini(void)
11369 + ipt_unregister_target(&ipt_XOR);
11372 +module_init(init);
11373 +module_exit(fini);
11374 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_addrtype.c linux-2.6.6/net/ipv4/netfilter/ipt_addrtype.c
11375 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_addrtype.c 1970-01-01 01:00:00.000000000 +0100
11376 +++ linux-2.6.6/net/ipv4/netfilter/ipt_addrtype.c 2004-05-18 14:28:50.000000000 +0200
11379 + * iptables module to match inet_addr_type() of an ip.
11382 +#include <linux/module.h>
11383 +#include <linux/skbuff.h>
11384 +#include <linux/netdevice.h>
11385 +#include <net/route.h>
11387 +#include <linux/netfilter_ipv4/ipt_addrtype.h>
11388 +#include <linux/netfilter_ipv4/ip_tables.h>
11390 +MODULE_LICENSE("GPL");
11392 +static inline int match_type(u_int32_t addr, u_int16_t mask)
11394 + return !!(mask & (1 << inet_addr_type(addr)));
11397 +static int match(const struct sk_buff *skb, const struct net_device *in,
11398 + const struct net_device *out, const void *matchinfo,
11399 + int offset, int *hotdrop)
11401 + const struct ipt_addrtype_info *info = matchinfo;
11402 + const struct iphdr *iph = skb->nh.iph;
11405 + if (info->source)
11406 + ret &= match_type(iph->saddr, info->source)^info->invert_source;
11408 + ret &= match_type(iph->daddr, info->dest)^info->invert_dest;
11413 +static int checkentry(const char *tablename, const struct ipt_ip *ip,
11414 + void *matchinfo, unsigned int matchsize,
11415 + unsigned int hook_mask)
11417 + if (matchsize != IPT_ALIGN(sizeof(struct ipt_addrtype_info))) {
11418 + printk(KERN_ERR "ipt_addrtype: invalid size (%u != %u)\n.",
11419 + matchsize, IPT_ALIGN(sizeof(struct ipt_addrtype_info)));
11426 +static struct ipt_match addrtype_match = {
11427 + .name = "addrtype",
11429 + .checkentry = checkentry,
11430 + .me = THIS_MODULE
11433 +static int __init init(void)
11435 + return ipt_register_match(&addrtype_match);
11438 +static void __exit fini(void)
11440 + ipt_unregister_match(&addrtype_match);
11444 +module_init(init);
11445 +module_exit(fini);
11446 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_connlimit.c linux-2.6.6/net/ipv4/netfilter/ipt_connlimit.c
11447 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_connlimit.c 1970-01-01 01:00:00.000000000 +0100
11448 +++ linux-2.6.6/net/ipv4/netfilter/ipt_connlimit.c 2004-05-18 14:28:50.000000000 +0200
11451 + * netfilter module to limit the number of parallel tcp
11452 + * connections per IP address.
11453 + * (c) 2000 Gerd Knorr <kraxel@bytesex.org>
11454 + * Nov 2002: Martin Bene <martin.bene@icomedias.com>:
11455 + * only ignore TIME_WAIT or gone connections
11459 + * Kernel module to match connection tracking information.
11460 + * GPL (C) 1999 Rusty Russell (rusty@rustcorp.com.au).
11462 +#include <linux/module.h>
11463 +#include <linux/skbuff.h>
11464 +#include <linux/list.h>
11465 +#include <linux/netfilter_ipv4/ip_conntrack.h>
11466 +#include <linux/netfilter_ipv4/ip_conntrack_core.h>
11467 +#include <linux/netfilter_ipv4/ip_conntrack_tcp.h>
11468 +#include <linux/netfilter_ipv4/ip_tables.h>
11469 +#include <linux/netfilter_ipv4/ipt_connlimit.h>
11473 +MODULE_LICENSE("GPL");
11475 +/* we'll save the tuples of all connections we care about */
11476 +struct ipt_connlimit_conn
11478 + struct list_head list;
11479 + struct ip_conntrack_tuple tuple;
11482 +struct ipt_connlimit_data {
11484 + struct list_head iphash[256];
11487 +static int ipt_iphash(u_int32_t addr)
11491 + hash = addr & 0xff;
11492 + hash ^= (addr >> 8) & 0xff;
11493 + hash ^= (addr >> 16) & 0xff;
11494 + hash ^= (addr >> 24) & 0xff;
11498 +static int count_them(struct ipt_connlimit_data *data,
11499 + u_int32_t addr, u_int32_t mask,
11500 + struct ip_conntrack *ct)
11503 + const static char *tcp[] = { "none", "established", "syn_sent", "syn_recv",
11504 + "fin_wait", "time_wait", "close", "close_wait",
11505 + "last_ack", "listen" };
11507 + int addit = 1, matches = 0;
11508 + struct ip_conntrack_tuple tuple;
11509 + struct ip_conntrack_tuple_hash *found;
11510 + struct ipt_connlimit_conn *conn;
11511 + struct list_head *hash,*lh;
11513 + spin_lock(&data->lock);
11514 + tuple = ct->tuplehash[0].tuple;
11515 + hash = &data->iphash[ipt_iphash(addr & mask)];
11517 + /* check the saved connections */
11518 + for (lh = hash->next; lh != hash; lh = lh->next) {
11519 + conn = list_entry(lh,struct ipt_connlimit_conn,list);
11520 + found = ip_conntrack_find_get(&conn->tuple,ct);
11521 + if (0 == memcmp(&conn->tuple,&tuple,sizeof(tuple)) &&
11523 + found->ctrack->proto.tcp.state != TCP_CONNTRACK_TIME_WAIT) {
11524 + /* Just to be sure we have it only once in the list.
11525 + We should'nt see tuples twice unless someone hooks this
11526 + into a table without "-p tcp --syn" */
11530 + printk("ipt_connlimit [%d]: src=%u.%u.%u.%u:%d dst=%u.%u.%u.%u:%d %s\n",
11531 + ipt_iphash(addr & mask),
11532 + NIPQUAD(conn->tuple.src.ip), ntohs(conn->tuple.src.u.tcp.port),
11533 + NIPQUAD(conn->tuple.dst.ip), ntohs(conn->tuple.dst.u.tcp.port),
11534 + (NULL != found) ? tcp[found->ctrack->proto.tcp.state] : "gone");
11536 + if (NULL == found) {
11537 + /* this one is gone */
11539 + list_del(lh->next);
11543 + if (found->ctrack->proto.tcp.state == TCP_CONNTRACK_TIME_WAIT) {
11544 + /* we don't care about connections which are
11545 + closed already -> ditch it */
11547 + list_del(lh->next);
11549 + nf_conntrack_put(&found->ctrack->infos[0]);
11552 + if ((addr & mask) == (conn->tuple.src.ip & mask)) {
11553 + /* same source IP address -> be counted! */
11556 + nf_conntrack_put(&found->ctrack->infos[0]);
11559 + /* save the new connection in our list */
11561 + printk("ipt_connlimit [%d]: src=%u.%u.%u.%u:%d dst=%u.%u.%u.%u:%d new\n",
11562 + ipt_iphash(addr & mask),
11563 + NIPQUAD(tuple.src.ip), ntohs(tuple.src.u.tcp.port),
11564 + NIPQUAD(tuple.dst.ip), ntohs(tuple.dst.u.tcp.port));
11566 + conn = kmalloc(sizeof(*conn),GFP_ATOMIC);
11567 + if (NULL == conn)
11569 + memset(conn,0,sizeof(*conn));
11570 + INIT_LIST_HEAD(&conn->list);
11571 + conn->tuple = tuple;
11572 + list_add(&conn->list,hash);
11575 + spin_unlock(&data->lock);
11580 +match(const struct sk_buff *skb,
11581 + const struct net_device *in,
11582 + const struct net_device *out,
11583 + const void *matchinfo,
11587 + const struct ipt_connlimit_info *info = matchinfo;
11588 + int connections, match;
11589 + struct ip_conntrack *ct;
11590 + enum ip_conntrack_info ctinfo;
11592 + ct = ip_conntrack_get((struct sk_buff *)skb, &ctinfo);
11593 + if (NULL == ct) {
11594 + printk("ipt_connlimit: Oops: invalid ct state ?\n");
11598 + connections = count_them(info->data,skb->nh.iph->saddr,info->mask,ct);
11599 + if (-1 == connections) {
11600 + printk("ipt_connlimit: Hmm, kmalloc failed :-(\n");
11601 + *hotdrop = 1; /* let's free some memory :-) */
11604 + match = (info->inverse) ? (connections <= info->limit) : (connections > info->limit);
11606 + printk("ipt_connlimit: src=%u.%u.%u.%u mask=%u.%u.%u.%u "
11607 + "connections=%d limit=%d match=%s\n",
11608 + NIPQUAD(skb->nh.iph->saddr), NIPQUAD(info->mask),
11609 + connections, info->limit, match ? "yes" : "no");
11615 +static int check(const char *tablename,
11616 + const struct ipt_ip *ip,
11618 + unsigned int matchsize,
11619 + unsigned int hook_mask)
11621 + struct ipt_connlimit_info *info = matchinfo;
11624 + /* verify size */
11625 + if (matchsize != IPT_ALIGN(sizeof(struct ipt_connlimit_info)))
11628 + /* refuse anything but tcp */
11629 + if (ip->proto != IPPROTO_TCP)
11632 + /* init private data */
11633 + info->data = kmalloc(sizeof(struct ipt_connlimit_data),GFP_KERNEL);
11634 + spin_lock_init(&(info->data->lock));
11635 + for (i = 0; i < 256; i++)
11636 + INIT_LIST_HEAD(&(info->data->iphash[i]));
11641 +static void destroy(void *matchinfo, unsigned int matchinfosize)
11643 + struct ipt_connlimit_info *info = matchinfo;
11644 + struct ipt_connlimit_conn *conn;
11645 + struct list_head *hash;
11649 + for (i = 0; i < 256; i++) {
11650 + hash = &(info->data->iphash[i]);
11651 + while (hash != hash->next) {
11652 + conn = list_entry(hash->next,struct ipt_connlimit_conn,list);
11653 + list_del(hash->next);
11657 + kfree(info->data);
11660 +static struct ipt_match connlimit_match = {
11661 + .name = "connlimit",
11663 + .checkentry = &check,
11664 + .destroy = &destroy,
11665 + .me = THIS_MODULE
11668 +static int __init init(void)
11670 + return ipt_register_match(&connlimit_match);
11673 +static void __exit fini(void)
11675 + ipt_unregister_match(&connlimit_match);
11678 +module_init(init);
11679 +module_exit(fini);
11680 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_connmark.c linux-2.6.6/net/ipv4/netfilter/ipt_connmark.c
11681 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_connmark.c 1970-01-01 01:00:00.000000000 +0100
11682 +++ linux-2.6.6/net/ipv4/netfilter/ipt_connmark.c 2004-05-18 14:28:50.000000000 +0200
11684 +/* This kernel module matches connection mark values set by the
11685 + * CONNMARK target
11687 + * Copyright (C) 2002,2004 MARA Systems AB <http://www.marasystems.com>
11688 + * by Henrik Nordstrom <hno@marasystems.com>
11690 + * This program is free software; you can redistribute it and/or modify
11691 + * it under the terms of the GNU General Public License as published by
11692 + * the Free Software Foundation; either version 2 of the License, or
11693 + * (at your option) any later version.
11695 + * This program is distributed in the hope that it will be useful,
11696 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11697 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11698 + * GNU General Public License for more details.
11700 + * You should have received a copy of the GNU General Public License
11701 + * along with this program; if not, write to the Free Software
11702 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
11705 +#include <linux/module.h>
11706 +#include <linux/skbuff.h>
11708 +MODULE_AUTHOR("Henrik Nordstrom <hno@marasytems.com>");
11709 +MODULE_DESCRIPTION("IP tables connmark match module");
11710 +MODULE_LICENSE("GPL");
11712 +#include <linux/netfilter_ipv4/ip_tables.h>
11713 +#include <linux/netfilter_ipv4/ipt_connmark.h>
11714 +#include <linux/netfilter_ipv4/ip_conntrack.h>
11717 +match(const struct sk_buff *skb,
11718 + const struct net_device *in,
11719 + const struct net_device *out,
11720 + const void *matchinfo,
11724 + const struct ipt_connmark_info *info = matchinfo;
11725 + enum ip_conntrack_info ctinfo;
11726 + struct ip_conntrack *ct = ip_conntrack_get((struct sk_buff *)skb, &ctinfo);
11730 + return ((ct->mark & info->mask) == info->mark) ^ info->invert;
11734 +checkentry(const char *tablename,
11735 + const struct ipt_ip *ip,
11737 + unsigned int matchsize,
11738 + unsigned int hook_mask)
11740 + if (matchsize != IPT_ALIGN(sizeof(struct ipt_connmark_info)))
11746 +static struct ipt_match connmark_match = {
11747 + .name = "connmark",
11749 + .checkentry = &checkentry,
11750 + .me = THIS_MODULE
11753 +static int __init init(void)
11755 + return ipt_register_match(&connmark_match);
11758 +static void __exit fini(void)
11760 + ipt_unregister_match(&connmark_match);
11763 +module_init(init);
11764 +module_exit(fini);
11765 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_dstlimit.c linux-2.6.6/net/ipv4/netfilter/ipt_dstlimit.c
11766 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_dstlimit.c 1970-01-01 01:00:00.000000000 +0100
11767 +++ linux-2.6.6/net/ipv4/netfilter/ipt_dstlimit.c 2004-05-18 14:28:50.000000000 +0200
11769 +/* iptables match extension to limit the number of packets per second
11770 + * seperately for each destination.
11772 + * (C) 2003 by Harald Welte <laforge@netfilter.org>
11776 + * Development of this code was funded by Astaro AG, http://www.astaro.com/
11778 + * based on ipt_limit.c by:
11779 + * Jérôme de Vivie <devivie@info.enserb.u-bordeaux.fr>
11780 + * Hervé Eychenne <eychenne@info.enserb.u-bordeaux.fr>
11781 + * Rusty Russell <rusty@rustcorp.com.au>
11783 + * The general idea is to create a hash table for every dstip and have a
11784 + * seperate limit counter per tuple. This way you can do something like 'limit
11785 + * the number of syn packets for each of my internal addresses.
11787 + * Ideally this would just be implemented as a general 'hash' match, which would
11788 + * allow us to attach any iptables target to it's hash buckets. But this is
11789 + * not possible in the current iptables architecture. As always, pkttables for
11790 + * 2.7.x will help ;)
11792 +#include <linux/module.h>
11793 +#include <linux/skbuff.h>
11794 +#include <linux/spinlock.h>
11795 +#include <linux/random.h>
11796 +#include <linux/jhash.h>
11797 +#include <linux/slab.h>
11798 +#include <linux/vmalloc.h>
11799 +#include <linux/tcp.h>
11800 +#include <linux/udp.h>
11801 +#include <linux/proc_fs.h>
11802 +#include <linux/seq_file.h>
11804 +#define ASSERT_READ_LOCK(x)
11805 +#define ASSERT_WRITE_LOCK(x)
11806 +#include <linux/netfilter_ipv4/lockhelp.h>
11807 +#include <linux/netfilter_ipv4/listhelp.h>
11809 +#include <linux/netfilter_ipv4/ip_tables.h>
11810 +#include <linux/netfilter_ipv4/ipt_dstlimit.h>
11812 +/* FIXME: this is just for IP_NF_ASSERRT */
11813 +#include <linux/netfilter_ipv4/ip_conntrack.h>
11815 +#define MS2JIFFIES(x) ((x*HZ)/1000)
11817 +MODULE_LICENSE("GPL");
11818 +MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>");
11819 +MODULE_DESCRIPTION("iptables match for limiting per destination");
11821 +/* need to declare this at the top */
11822 +static struct proc_dir_entry *dstlimit_procdir;
11823 +static struct file_operations dl_file_ops;
11825 +/* hash table crap */
11827 +struct dsthash_dst {
11828 + u_int32_t src_ip;
11829 + u_int32_t dst_ip;
11833 +struct dsthash_ent {
11834 + /* static / read-only parts in the beginning */
11835 + struct list_head list;
11836 + struct dsthash_dst dst;
11838 + /* modified structure members in the end */
11839 + unsigned long expires; /* precalculated expiry time */
11841 + unsigned long prev; /* last modification */
11842 + u_int32_t credit;
11843 + u_int32_t credit_cap, cost;
11847 +struct ipt_dstlimit_htable {
11848 + struct list_head list; /* global list of all htables */
11851 + struct dstlimit_cfg cfg; /* config */
11853 + /* used internally */
11854 + spinlock_t lock; /* lock for list_head */
11855 + u_int32_t rnd; /* random seed for hash */
11856 + struct timer_list timer; /* timer for gc */
11857 + atomic_t count; /* number entries in table */
11859 + /* seq_file stuff */
11860 + struct proc_dir_entry *pde;
11862 + struct list_head hash[0]; /* hashtable itself */
11865 +DECLARE_RWLOCK(dstlimit_lock); /* protects htables list */
11866 +static LIST_HEAD(dstlimit_htables);
11867 +static kmem_cache_t *dstlimit_cachep;
11869 +static inline int dst_cmp(const struct dsthash_ent *ent, struct dsthash_dst *b)
11871 + return (ent->dst.dst_ip == b->dst_ip
11872 + && ent->dst.port == b->port
11873 + && ent->dst.src_ip == b->src_ip);
11876 +static inline u_int32_t
11877 +hash_dst(const struct ipt_dstlimit_htable *ht, const struct dsthash_dst *dst)
11879 + return (jhash_3words(dst->dst_ip, dst->port,
11880 + dst->src_ip, ht->rnd) % ht->cfg.size);
11883 +static inline struct dsthash_ent *
11884 +__dsthash_find(const struct ipt_dstlimit_htable *ht, struct dsthash_dst *dst)
11886 + struct dsthash_ent *ent;
11887 + u_int32_t hash = hash_dst(ht, dst);
11888 + MUST_BE_LOCKED(&ht->lock);
11889 + ent = LIST_FIND(&ht->hash[hash], dst_cmp, struct dsthash_ent *, dst);
11893 +/* allocate dsthash_ent, initialize dst, put in htable and lock it */
11894 +static struct dsthash_ent *
11895 +__dsthash_alloc_init(struct ipt_dstlimit_htable *ht, struct dsthash_dst *dst)
11897 + struct dsthash_ent *ent;
11899 + /* initialize hash with random val at the time we allocate
11900 + * the first hashtable entry */
11902 + get_random_bytes(&ht->rnd, 4);
11904 + if (ht->cfg.max &&
11905 + atomic_read(&ht->count) >= ht->cfg.max) {
11906 + /* FIXME: do something. question is what.. */
11907 + if (net_ratelimit())
11908 + printk(KERN_WARNING
11909 + "ipt_dstlimit: max count of %u reached\n",
11914 + ent = kmem_cache_alloc(dstlimit_cachep, GFP_ATOMIC);
11916 + if (net_ratelimit())
11918 + "ipt_dstlimit: can't allocate dsthash_ent\n");
11922 + atomic_inc(&ht->count);
11924 + ent->dst.dst_ip = dst->dst_ip;
11925 + ent->dst.port = dst->port;
11926 + ent->dst.src_ip = dst->src_ip;
11928 + list_add(&ent->list, &ht->hash[hash_dst(ht, dst)]);
11933 +static inline void
11934 +__dsthash_free(struct ipt_dstlimit_htable *ht, struct dsthash_ent *ent)
11936 + MUST_BE_LOCKED(&ht->lock);
11938 + list_del(&ent->list);
11939 + kmem_cache_free(dstlimit_cachep, ent);
11940 + atomic_dec(&ht->count);
11942 +static void htable_gc(unsigned long htlong);
11944 +static int htable_create(struct ipt_dstlimit_info *minfo)
11947 + unsigned int size;
11948 + struct ipt_dstlimit_htable *hinfo;
11950 + if (minfo->cfg.size)
11951 + size = minfo->cfg.size;
11953 + size = (((num_physpages << PAGE_SHIFT) / 16384)
11954 + / sizeof(struct list_head));
11955 + if (num_physpages > (1024 * 1024 * 1024 / PAGE_SIZE))
11960 + /* FIXME: don't use vmalloc() here or anywhere else -HW */
11961 + hinfo = vmalloc(sizeof(struct ipt_dstlimit_htable)
11962 + + (sizeof(struct list_head) * size));
11964 + printk(KERN_ERR "ipt_dstlimit: Unable to create hashtable\n");
11967 + minfo->hinfo = hinfo;
11969 + /* copy match config into hashtable config */
11970 + memcpy(&hinfo->cfg, &minfo->cfg, sizeof(hinfo->cfg));
11971 + hinfo->cfg.size = size;
11972 + if (!hinfo->cfg.max)
11973 + hinfo->cfg.max = 8 * hinfo->cfg.size;
11974 + else if (hinfo->cfg.max < hinfo->cfg.size)
11975 + hinfo->cfg.max = hinfo->cfg.size;
11977 + for (i = 0; i < hinfo->cfg.size; i++)
11978 + INIT_LIST_HEAD(&hinfo->hash[i]);
11980 + atomic_set(&hinfo->count, 0);
11981 + atomic_set(&hinfo->use, 1);
11983 + hinfo->lock = SPIN_LOCK_UNLOCKED;
11984 + hinfo->pde = create_proc_entry(minfo->name, 0, dstlimit_procdir);
11985 + if (!hinfo->pde) {
11989 + hinfo->pde->proc_fops = &dl_file_ops;
11990 + hinfo->pde->data = hinfo;
11992 + init_timer(&hinfo->timer);
11993 + hinfo->timer.expires = jiffies + MS2JIFFIES(hinfo->cfg.gc_interval);
11994 + hinfo->timer.data = (unsigned long )hinfo;
11995 + hinfo->timer.function = htable_gc;
11996 + add_timer(&hinfo->timer);
11998 + WRITE_LOCK(&dstlimit_lock);
11999 + list_add(&hinfo->list, &dstlimit_htables);
12000 + WRITE_UNLOCK(&dstlimit_lock);
12005 +static int select_all(struct ipt_dstlimit_htable *ht, struct dsthash_ent *he)
12010 +static int select_gc(struct ipt_dstlimit_htable *ht, struct dsthash_ent *he)
12012 + return (jiffies >= he->expires);
12015 +static void htable_selective_cleanup(struct ipt_dstlimit_htable *ht,
12016 + int (*select)(struct ipt_dstlimit_htable *ht,
12017 + struct dsthash_ent *he))
12021 + IP_NF_ASSERT(ht->cfg.size && ht->cfg.max);
12023 + /* lock hash table and iterate over it */
12024 + LOCK_BH(&ht->lock);
12025 + for (i = 0; i < ht->cfg.size; i++) {
12026 + struct dsthash_ent *dh, *n;
12027 + list_for_each_entry_safe(dh, n, &ht->hash[i], list) {
12028 + if ((*select)(ht, dh))
12029 + __dsthash_free(ht, dh);
12032 + UNLOCK_BH(&ht->lock);
12035 +/* hash table garbage collector, run by timer */
12036 +static void htable_gc(unsigned long htlong)
12038 + struct ipt_dstlimit_htable *ht = (struct ipt_dstlimit_htable *)htlong;
12040 + htable_selective_cleanup(ht, select_gc);
12042 + /* re-add the timer accordingly */
12043 + ht->timer.expires = jiffies + MS2JIFFIES(ht->cfg.gc_interval);
12044 + add_timer(&ht->timer);
12047 +static void htable_destroy(struct ipt_dstlimit_htable *hinfo)
12049 + /* remove timer, if it is pending */
12050 + if (timer_pending(&hinfo->timer))
12051 + del_timer(&hinfo->timer);
12053 + /* remove proc entry */
12054 + remove_proc_entry(hinfo->pde->name, dstlimit_procdir);
12056 + htable_selective_cleanup(hinfo, select_all);
12060 +static struct ipt_dstlimit_htable *htable_find_get(char *name)
12062 + struct ipt_dstlimit_htable *hinfo;
12064 + READ_LOCK(&dstlimit_lock);
12065 + list_for_each_entry(hinfo, &dstlimit_htables, list) {
12066 + if (!strcmp(name, hinfo->pde->name)) {
12067 + atomic_inc(&hinfo->use);
12068 + READ_UNLOCK(&dstlimit_lock);
12072 + READ_UNLOCK(&dstlimit_lock);
12077 +static void htable_put(struct ipt_dstlimit_htable *hinfo)
12079 + if (atomic_dec_and_test(&hinfo->use)) {
12080 + WRITE_LOCK(&dstlimit_lock);
12081 + list_del(&hinfo->list);
12082 + WRITE_UNLOCK(&dstlimit_lock);
12083 + htable_destroy(hinfo);
12088 +/* The algorithm used is the Simple Token Bucket Filter (TBF)
12089 + * see net/sched/sch_tbf.c in the linux source tree
12092 +/* Rusty: This is my (non-mathematically-inclined) understanding of
12093 + this algorithm. The `average rate' in jiffies becomes your initial
12094 + amount of credit `credit' and the most credit you can ever have
12095 + `credit_cap'. The `peak rate' becomes the cost of passing the
12098 + `prev' tracks the last packet hit: you gain one credit per jiffy.
12099 + If you get credit balance more than this, the extra credit is
12100 + discarded. Every time the match passes, you lose `cost' credits;
12101 + if you don't have that many, the test fails.
12103 + See Alexey's formal explanation in net/sched/sch_tbf.c.
12105 + To get the maximum range, we multiply by this factor (ie. you get N
12106 + credits per jiffy). We want to allow a rate as low as 1 per day
12107 + (slowest userspace tool allows), which means
12108 + CREDITS_PER_JIFFY*HZ*60*60*24 < 2^32 ie.
12110 +#define MAX_CPJ (0xFFFFFFFF / (HZ*60*60*24))
12112 +/* Repeated shift and or gives us all 1s, final shift and add 1 gives
12113 + * us the power of 2 below the theoretical max, so GCC simply does a
12115 +#define _POW2_BELOW2(x) ((x)|((x)>>1))
12116 +#define _POW2_BELOW4(x) (_POW2_BELOW2(x)|_POW2_BELOW2((x)>>2))
12117 +#define _POW2_BELOW8(x) (_POW2_BELOW4(x)|_POW2_BELOW4((x)>>4))
12118 +#define _POW2_BELOW16(x) (_POW2_BELOW8(x)|_POW2_BELOW8((x)>>8))
12119 +#define _POW2_BELOW32(x) (_POW2_BELOW16(x)|_POW2_BELOW16((x)>>16))
12120 +#define POW2_BELOW32(x) ((_POW2_BELOW32(x)>>1) + 1)
12122 +#define CREDITS_PER_JIFFY POW2_BELOW32(MAX_CPJ)
12124 +/* Precision saver. */
12125 +static inline u_int32_t
12126 +user2credits(u_int32_t user)
12128 + /* If multiplying would overflow... */
12129 + if (user > 0xFFFFFFFF / (HZ*CREDITS_PER_JIFFY))
12130 + /* Divide first. */
12131 + return (user / IPT_DSTLIMIT_SCALE) * HZ * CREDITS_PER_JIFFY;
12133 + return (user * HZ * CREDITS_PER_JIFFY) / IPT_DSTLIMIT_SCALE;
12136 +static inline void rateinfo_recalc(struct dsthash_ent *dh, unsigned long now)
12138 + dh->rateinfo.credit += (now - xchg(&dh->rateinfo.prev, now))
12139 + * CREDITS_PER_JIFFY;
12140 + if (dh->rateinfo.credit > dh->rateinfo.credit_cap)
12141 + dh->rateinfo.credit = dh->rateinfo.credit_cap;
12145 +dstlimit_match(const struct sk_buff *skb,
12146 + const struct net_device *in,
12147 + const struct net_device *out,
12148 + const void *matchinfo,
12152 + struct ipt_dstlimit_info *r =
12153 + ((struct ipt_dstlimit_info *)matchinfo)->u.master;
12154 + struct ipt_dstlimit_htable *hinfo = r->hinfo;
12155 + unsigned long now = jiffies;
12156 + struct dsthash_ent *dh;
12157 + struct dsthash_dst dst;
12159 + memset(&dst, 0, sizeof(dst));
12161 + /* dest ip is always in hash */
12162 + dst.dst_ip = skb->nh.iph->daddr;
12164 + /* source ip only if respective hashmode, otherwise set to
12166 + if (hinfo->cfg.mode & IPT_DSTLIMIT_HASH_SIP)
12167 + dst.src_ip = skb->nh.iph->saddr;
12169 + /* dest port only if respective mode */
12170 + if (hinfo->cfg.mode & IPT_DSTLIMIT_HASH_DPT) {
12173 + /* Must not be a fragment. */
12177 + /* Must be big enough to read ports (both UDP and TCP have
12178 + them at the start). */
12179 + if (skb_copy_bits(skb, skb->nh.iph->ihl*4, ports, sizeof(ports)) < 0) {
12180 + /* We've been asked to examine this packet, and we
12181 + can't. Hence, no choice but to drop. */
12186 + switch (skb->nh.iph->protocol) {
12187 + struct tcphdr *th;
12188 + struct udphdr *uh;
12189 + case IPPROTO_TCP:
12190 + th = (void *)skb->nh.iph+skb->nh.iph->ihl*4;
12191 + dst.port = th->dest;
12193 + case IPPROTO_UDP:
12194 + uh = (void *)skb->nh.iph+skb->nh.iph->ihl*4;
12195 + dst.port = uh->dest;
12202 + LOCK_BH(&hinfo->lock);
12203 + dh = __dsthash_find(hinfo, &dst);
12205 + dh = __dsthash_alloc_init(hinfo, &dst);
12208 + /* enomem... don't match == DROP */
12209 + if (net_ratelimit())
12210 + printk(KERN_ERR "%s: ENOMEM\n", __FUNCTION__);
12211 + UNLOCK_BH(&hinfo->lock);
12215 + dh->expires = jiffies + MS2JIFFIES(hinfo->cfg.expire);
12217 + dh->rateinfo.prev = jiffies;
12218 + dh->rateinfo.credit = user2credits(hinfo->cfg.avg *
12219 + hinfo->cfg.burst);
12220 + dh->rateinfo.credit_cap = user2credits(hinfo->cfg.avg *
12221 + hinfo->cfg.burst);
12222 + dh->rateinfo.cost = user2credits(hinfo->cfg.avg);
12224 + UNLOCK_BH(&hinfo->lock);
12228 + /* update expiration timeout */
12229 + dh->expires = now + MS2JIFFIES(hinfo->cfg.expire);
12231 + rateinfo_recalc(dh, now);
12232 + if (dh->rateinfo.credit >= dh->rateinfo.cost) {
12233 + /* We're underlimit. */
12234 + dh->rateinfo.credit -= dh->rateinfo.cost;
12235 + UNLOCK_BH(&hinfo->lock);
12239 + UNLOCK_BH(&hinfo->lock);
12241 + /* default case: we're overlimit, thus don't match */
12246 +dstlimit_checkentry(const char *tablename,
12247 + const struct ipt_ip *ip,
12249 + unsigned int matchsize,
12250 + unsigned int hook_mask)
12252 + struct ipt_dstlimit_info *r = matchinfo;
12254 + if (matchsize != IPT_ALIGN(sizeof(struct ipt_dstlimit_info)))
12257 + /* Check for overflow. */
12258 + if (r->cfg.burst == 0
12259 + || user2credits(r->cfg.avg * r->cfg.burst) <
12260 + user2credits(r->cfg.avg)) {
12261 + printk(KERN_ERR "ipt_dstlimit: Overflow, try lower: %u/%u\n",
12262 + r->cfg.avg, r->cfg.burst);
12266 + if (r->cfg.mode == 0
12267 + || r->cfg.mode > (IPT_DSTLIMIT_HASH_DPT
12268 + |IPT_DSTLIMIT_HASH_DIP
12269 + |IPT_DSTLIMIT_HASH_SIP))
12272 + if (!r->cfg.gc_interval)
12275 + if (!r->cfg.expire)
12278 + r->hinfo = htable_find_get(r->name);
12279 + if (!r->hinfo && (htable_create(r) != 0)) {
12283 + /* Ugly hack: For SMP, we only want to use one set */
12290 +dstlimit_destroy(void *matchinfo, unsigned int matchsize)
12292 + struct ipt_dstlimit_info *r = (struct ipt_dstlimit_info *) matchinfo;
12294 + htable_put(r->hinfo);
12297 +static struct ipt_match ipt_dstlimit = {
12298 + .list = { .prev = NULL, .next = NULL },
12299 + .name = "dstlimit",
12300 + .match = dstlimit_match,
12301 + .checkentry = dstlimit_checkentry,
12302 + .destroy = dstlimit_destroy,
12303 + .me = THIS_MODULE
12308 +static void *dl_seq_start(struct seq_file *s, loff_t *pos)
12310 + struct proc_dir_entry *pde = s->private;
12311 + struct ipt_dstlimit_htable *htable = pde->data;
12312 + unsigned int *bucket;
12314 + LOCK_BH(&htable->lock);
12315 + if (*pos >= htable->cfg.size)
12318 + bucket = kmalloc(sizeof(unsigned int), GFP_KERNEL);
12320 + return ERR_PTR(-ENOMEM);
12326 +static void *dl_seq_next(struct seq_file *s, void *v, loff_t *pos)
12328 + struct proc_dir_entry *pde = s->private;
12329 + struct ipt_dstlimit_htable *htable = pde->data;
12330 + unsigned int *bucket = (unsigned int *)v;
12332 + *pos = ++(*bucket);
12333 + if (*pos >= htable->cfg.size) {
12340 +static void dl_seq_stop(struct seq_file *s, void *v)
12342 + struct proc_dir_entry *pde = s->private;
12343 + struct ipt_dstlimit_htable *htable = pde->data;
12344 + unsigned int *bucket = (unsigned int *)v;
12348 + UNLOCK_BH(&htable->lock);
12351 +static inline int dl_seq_real_show(struct dsthash_ent *ent, struct seq_file *s)
12353 + /* recalculate to show accurate numbers */
12354 + rateinfo_recalc(ent, jiffies);
12356 + return seq_printf(s, "%ld %u.%u.%u.%u->%u.%u.%u.%u:%u %u %u %u\n",
12357 + (ent->expires - jiffies)/HZ,
12358 + NIPQUAD(ent->dst.src_ip),
12359 + NIPQUAD(ent->dst.dst_ip), ntohs(ent->dst.port),
12360 + ent->rateinfo.credit, ent->rateinfo.credit_cap,
12361 + ent->rateinfo.cost);
12364 +static int dl_seq_show(struct seq_file *s, void *v)
12366 + struct proc_dir_entry *pde = s->private;
12367 + struct ipt_dstlimit_htable *htable = pde->data;
12368 + unsigned int *bucket = (unsigned int *)v;
12370 + if (LIST_FIND_W(&htable->hash[*bucket], dl_seq_real_show,
12371 + struct dsthash_ent *, s)) {
12372 + /* buffer was filled and unable to print that tuple */
12378 +static struct seq_operations dl_seq_ops = {
12379 + .start = dl_seq_start,
12380 + .next = dl_seq_next,
12381 + .stop = dl_seq_stop,
12382 + .show = dl_seq_show
12385 +static int dl_proc_open(struct inode *inode, struct file *file)
12387 + int ret = seq_open(file, &dl_seq_ops);
12390 + struct seq_file *sf = file->private_data;
12391 + sf->private = PDE(inode);
12396 +static struct file_operations dl_file_ops = {
12397 + .owner = THIS_MODULE,
12398 + .open = dl_proc_open,
12399 + .read = seq_read,
12400 + .llseek = seq_lseek,
12401 + .release = seq_release
12404 +static int init_or_fini(int fini)
12411 + if (ipt_register_match(&ipt_dstlimit)) {
12413 + goto cleanup_nothing;
12416 + /* FIXME: do we really want HWCACHE_ALIGN since our objects are
12417 + * quite small ? */
12418 + dstlimit_cachep = kmem_cache_create("ipt_dstlimit",
12419 + sizeof(struct dsthash_ent), 0,
12420 + SLAB_HWCACHE_ALIGN, NULL, NULL);
12421 + if (!dstlimit_cachep) {
12422 + printk(KERN_ERR "Unable to create ipt_dstlimit slab cache\n");
12424 + goto cleanup_unreg_match;
12427 + dstlimit_procdir = proc_mkdir("ipt_dstlimit", proc_net);
12428 + if (!dstlimit_procdir) {
12429 + printk(KERN_ERR "Unable to create proc dir entry\n");
12431 + goto cleanup_free_slab;
12437 + remove_proc_entry("ipt_dstlimit", proc_net);
12438 +cleanup_free_slab:
12439 + kmem_cache_destroy(dstlimit_cachep);
12440 +cleanup_unreg_match:
12441 + ipt_unregister_match(&ipt_dstlimit);
12447 +static int __init init(void)
12449 + return init_or_fini(0);
12452 +static void __exit fini(void)
12457 +module_init(init);
12458 +module_exit(fini);
12459 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_fuzzy.c linux-2.6.6/net/ipv4/netfilter/ipt_fuzzy.c
12460 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_fuzzy.c 1970-01-01 01:00:00.000000000 +0100
12461 +++ linux-2.6.6/net/ipv4/netfilter/ipt_fuzzy.c 2004-05-18 14:28:50.000000000 +0200
12464 + * This module implements a simple TSK FLC
12465 + * (Takagi-Sugeno-Kang Fuzzy Logic Controller) that aims
12466 + * to limit , in an adaptive and flexible way , the packet rate crossing
12467 + * a given stream . It serves as an initial and very simple (but effective)
12468 + * example of how Fuzzy Logic techniques can be applied to defeat DoS attacks.
12469 + * As a matter of fact , Fuzzy Logic can help us to insert any "behavior"
12470 + * into our code in a precise , adaptive and efficient manner.
12471 + * The goal is very similar to that of "limit" match , but using techniques of
12472 + * Fuzzy Control , that allow us to shape the transfer functions precisely ,
12473 + * avoiding over and undershoots - and stuff like that .
12476 + * 2002-08-10 Hime Aguiar e Oliveira Jr. <hime@engineer.com> : Initial version.
12477 + * 2002-08-17 : Changed to eliminate floating point operations .
12478 + * 2002-08-23 : Coding style changes .
12481 +#include <linux/module.h>
12482 +#include <linux/skbuff.h>
12483 +#include <linux/ip.h>
12484 +#include <linux/random.h>
12485 +#include <net/tcp.h>
12486 +#include <linux/spinlock.h>
12487 +#include <linux/netfilter_ipv4/ip_tables.h>
12488 +#include <linux/netfilter_ipv4/ipt_fuzzy.h>
12491 + Packet Acceptance Rate - LOW and Packet Acceptance Rate - HIGH
12492 + Expressed in percentage
12495 +#define PAR_LOW 1/100
12496 +#define PAR_HIGH 1
12498 +static spinlock_t fuzzy_lock = SPIN_LOCK_UNLOCKED ;
12500 +MODULE_AUTHOR("Hime Aguiar e Oliveira Junior <hime@engineer.com>");
12501 +MODULE_DESCRIPTION("IP tables Fuzzy Logic Controller match module");
12502 +MODULE_LICENSE("GPL");
12504 +static u_int8_t mf_high(u_int32_t tx,u_int32_t mini,u_int32_t maxi)
12512 + return ( (100*(tx-mini)) / (maxi-mini) );
12515 +static u_int8_t mf_low(u_int32_t tx,u_int32_t mini,u_int32_t maxi)
12523 + return ( (100*( maxi - tx )) / ( maxi - mini ) );
12527 +ipt_fuzzy_match(const struct sk_buff *pskb,
12528 + const struct net_device *in,
12529 + const struct net_device *out,
12530 + const void *matchinfo,
12534 + /* From userspace */
12536 + struct ipt_fuzzy_info *info = (struct ipt_fuzzy_info *) matchinfo;
12538 + u_int8_t random_number;
12539 + unsigned long amount;
12540 + u_int8_t howhigh, howlow;
12543 + spin_lock_bh(&fuzzy_lock); /* Rise the lock */
12545 + info->bytes_total += pskb->len;
12546 + info->packets_total++;
12548 + info->present_time = jiffies;
12550 + if (info->present_time >= info->previous_time)
12551 + amount = info->present_time - info->previous_time;
12553 + /* There was a transition : I choose to re-sample
12554 + and keep the old acceptance rate...
12558 + info->previous_time = info->present_time;
12559 + info->bytes_total = info->packets_total = 0;
12562 + if (amount > HZ/10) /* More than 100 ms elapsed ... */
12565 + info->mean_rate = (u_int32_t) ((HZ*info->packets_total) \
12568 + info->previous_time = info->present_time;
12569 + info->bytes_total = info->packets_total = 0;
12571 + howhigh = mf_high(info->mean_rate,info->minimum_rate,info->maximum_rate);
12572 + howlow = mf_low(info->mean_rate,info->minimum_rate,info->maximum_rate);
12574 + info->acceptance_rate = (u_int8_t) \
12575 + (howhigh*PAR_LOW + PAR_HIGH*howlow);
12577 + /* In fact , the above defuzzification would require a denominator
12578 + proportional to (howhigh+howlow) but , in this particular case ,
12579 + that expression is constant .
12580 + An imediate consequence is that it isn't necessary to call
12581 + both mf_high and mf_low - but to keep things understandable ,
12586 + spin_unlock_bh(&fuzzy_lock); /* Release the lock */
12589 + if ( info->acceptance_rate < 100 )
12591 + get_random_bytes((void *)(&random_number), 1);
12593 + /* If within the acceptance , it can pass => don't match */
12594 + if (random_number <= (255 * info->acceptance_rate) / 100)
12597 + return 1; /* It can't pass ( It matches ) */
12600 + return 0; /* acceptance_rate == 100 % => Everything passes ... */
12605 +ipt_fuzzy_checkentry(const char *tablename,
12606 + const struct ipt_ip *e,
12608 + unsigned int matchsize,
12609 + unsigned int hook_mask)
12612 + const struct ipt_fuzzy_info *info = matchinfo;
12614 + if (matchsize != IPT_ALIGN(sizeof(struct ipt_fuzzy_info))) {
12615 + printk("ipt_fuzzy: matchsize %u != %u\n", matchsize,
12616 + IPT_ALIGN(sizeof(struct ipt_fuzzy_info)));
12620 + if ((info->minimum_rate < MINFUZZYRATE ) || (info->maximum_rate > MAXFUZZYRATE)
12621 + || (info->minimum_rate >= info->maximum_rate )) {
12622 + printk("ipt_fuzzy: BAD limits , please verify !!!\n");
12629 +static struct ipt_match ipt_fuzzy_reg = {
12631 + .match = ipt_fuzzy_match,
12632 + .checkentry = ipt_fuzzy_checkentry,
12633 + .me = THIS_MODULE
12636 +static int __init init(void)
12638 + return ipt_register_match(&ipt_fuzzy_reg);
12641 +static void __exit fini(void)
12643 + ipt_unregister_match(&ipt_fuzzy_reg);
12646 +module_init(init);
12647 +module_exit(fini);
12648 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_helper.c linux-2.6.6/net/ipv4/netfilter/ipt_helper.c
12649 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_helper.c 2004-05-10 04:32:54.000000000 +0200
12650 +++ linux-2.6.6/net/ipv4/netfilter/ipt_helper.c 2004-05-18 14:28:50.000000000 +0200
12651 @@ -41,17 +41,17 @@
12652 struct ip_conntrack_expect *exp;
12653 struct ip_conntrack *ct;
12654 enum ip_conntrack_info ctinfo;
12656 + int ret = info->invert;
12658 ct = ip_conntrack_get((struct sk_buff *)skb, &ctinfo);
12660 DEBUGP("ipt_helper: Eek! invalid conntrack?\n");
12666 DEBUGP("ipt_helper: conntrack %p has no master\n", ct);
12673 DEBUGP("master's name = %s , info->name = %s\n",
12674 exp->expectant->helper->name, info->name);
12676 - ret = !strncmp(exp->expectant->helper->name, info->name,
12677 - strlen(exp->expectant->helper->name)) ^ info->invert;
12678 + if (info->name[0] == '\0')
12681 + ret ^= !strncmp(exp->expectant->helper->name, info->name,
12682 + strlen(exp->expectant->helper->name));
12684 READ_UNLOCK(&ip_conntrack_lock);
12687 if (matchsize != IPT_ALIGN(sizeof(struct ipt_helper_info)))
12690 - /* verify that we actually should match anything */
12691 - if ( strlen(info->name) == 0 )
12697 @@ -108,7 +107,6 @@
12699 static int __init init(void)
12701 - need_ip_conntrack();
12702 return ipt_register_match(&helper_match);
12705 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_ipv4options.c linux-2.6.6/net/ipv4/netfilter/ipt_ipv4options.c
12706 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_ipv4options.c 1970-01-01 01:00:00.000000000 +0100
12707 +++ linux-2.6.6/net/ipv4/netfilter/ipt_ipv4options.c 2004-05-18 14:28:50.000000000 +0200
12710 + This is a module which is used to match ipv4 options.
12711 + This file is distributed under the terms of the GNU General Public
12712 + License (GPL). Copies of the GPL can be obtained from:
12713 + ftp://prep.ai.mit.edu/pub/gnu/GPL
12715 + 11-mars-2001 Fabrice MARIE <fabrice@netfilter.org> : initial development.
12716 + 12-july-2001 Fabrice MARIE <fabrice@netfilter.org> : added router-alert otions matching. Fixed a bug with no-srr
12717 + 12-august-2001 Imran Patel <ipatel@crosswinds.net> : optimization of the match.
12718 + 18-november-2001 Fabrice MARIE <fabrice@netfilter.org> : added [!] 'any' option match.
12719 + 19-february-2004 Harald Welte <laforge@netfilter.org> : merge with 2.6.x
12722 +#include <linux/module.h>
12723 +#include <linux/skbuff.h>
12724 +#include <net/ip.h>
12726 +#include <linux/netfilter_ipv4/ip_tables.h>
12727 +#include <linux/netfilter_ipv4/ipt_ipv4options.h>
12729 +MODULE_LICENSE("GPL");
12730 +MODULE_AUTHOR("Fabrice Marie <fabrice@netfilter.org>");
12733 +match(const struct sk_buff *skb,
12734 + const struct net_device *in,
12735 + const struct net_device *out,
12736 + const void *matchinfo,
12740 + const struct ipt_ipv4options_info *info = matchinfo; /* match info for rule */
12741 + const struct iphdr *iph = skb->nh.iph;
12742 + const struct ip_options *opt;
12744 + if (iph->ihl * 4 == sizeof(struct iphdr)) {
12745 + /* No options, so we match only the "DONTs" and the "IGNOREs" */
12747 + if (((info->options & IPT_IPV4OPTION_MATCH_ANY_OPT) == IPT_IPV4OPTION_MATCH_ANY_OPT) ||
12748 + ((info->options & IPT_IPV4OPTION_MATCH_SSRR) == IPT_IPV4OPTION_MATCH_SSRR) ||
12749 + ((info->options & IPT_IPV4OPTION_MATCH_LSRR) == IPT_IPV4OPTION_MATCH_LSRR) ||
12750 + ((info->options & IPT_IPV4OPTION_MATCH_RR) == IPT_IPV4OPTION_MATCH_RR) ||
12751 + ((info->options & IPT_IPV4OPTION_MATCH_TIMESTAMP) == IPT_IPV4OPTION_MATCH_TIMESTAMP) ||
12752 + ((info->options & IPT_IPV4OPTION_MATCH_ROUTER_ALERT) == IPT_IPV4OPTION_MATCH_ROUTER_ALERT))
12757 + if ((info->options & IPT_IPV4OPTION_MATCH_ANY_OPT) == IPT_IPV4OPTION_MATCH_ANY_OPT)
12758 + /* there are options, and we don't need to care which one */
12761 + if ((info->options & IPT_IPV4OPTION_DONT_MATCH_ANY_OPT) == IPT_IPV4OPTION_DONT_MATCH_ANY_OPT)
12762 + /* there are options but we don't want any ! */
12767 + opt = &(IPCB(skb)->opt);
12769 + /* source routing */
12770 + if ((info->options & IPT_IPV4OPTION_MATCH_SSRR) == IPT_IPV4OPTION_MATCH_SSRR) {
12771 + if (!((opt->srr) & (opt->is_strictroute)))
12774 + else if ((info->options & IPT_IPV4OPTION_MATCH_LSRR) == IPT_IPV4OPTION_MATCH_LSRR) {
12775 + if (!((opt->srr) & (!opt->is_strictroute)))
12778 + else if ((info->options & IPT_IPV4OPTION_DONT_MATCH_SRR) == IPT_IPV4OPTION_DONT_MATCH_SRR) {
12782 + /* record route */
12783 + if ((info->options & IPT_IPV4OPTION_MATCH_RR) == IPT_IPV4OPTION_MATCH_RR) {
12787 + else if ((info->options & IPT_IPV4OPTION_DONT_MATCH_RR) == IPT_IPV4OPTION_DONT_MATCH_RR) {
12792 + if ((info->options & IPT_IPV4OPTION_MATCH_TIMESTAMP) == IPT_IPV4OPTION_MATCH_TIMESTAMP) {
12796 + else if ((info->options & IPT_IPV4OPTION_DONT_MATCH_TIMESTAMP) == IPT_IPV4OPTION_DONT_MATCH_TIMESTAMP) {
12800 + /* router-alert option */
12801 + if ((info->options & IPT_IPV4OPTION_MATCH_ROUTER_ALERT) == IPT_IPV4OPTION_MATCH_ROUTER_ALERT) {
12802 + if (!opt->router_alert)
12805 + else if ((info->options & IPT_IPV4OPTION_DONT_MATCH_ROUTER_ALERT) == IPT_IPV4OPTION_DONT_MATCH_ROUTER_ALERT) {
12806 + if (opt->router_alert)
12815 +checkentry(const char *tablename,
12816 + const struct ipt_ip *ip,
12818 + unsigned int matchsize,
12819 + unsigned int hook_mask)
12821 + const struct ipt_ipv4options_info *info = matchinfo; /* match info for rule */
12822 + /* Check the size */
12823 + if (matchsize != IPT_ALIGN(sizeof(struct ipt_ipv4options_info)))
12825 + /* Now check the coherence of the data ... */
12826 + if (((info->options & IPT_IPV4OPTION_MATCH_ANY_OPT) == IPT_IPV4OPTION_MATCH_ANY_OPT) &&
12827 + (((info->options & IPT_IPV4OPTION_DONT_MATCH_SRR) == IPT_IPV4OPTION_DONT_MATCH_SRR) ||
12828 + ((info->options & IPT_IPV4OPTION_DONT_MATCH_RR) == IPT_IPV4OPTION_DONT_MATCH_RR) ||
12829 + ((info->options & IPT_IPV4OPTION_DONT_MATCH_TIMESTAMP) == IPT_IPV4OPTION_DONT_MATCH_TIMESTAMP) ||
12830 + ((info->options & IPT_IPV4OPTION_DONT_MATCH_ROUTER_ALERT) == IPT_IPV4OPTION_DONT_MATCH_ROUTER_ALERT) ||
12831 + ((info->options & IPT_IPV4OPTION_DONT_MATCH_ANY_OPT) == IPT_IPV4OPTION_DONT_MATCH_ANY_OPT)))
12832 + return 0; /* opposites */
12833 + if (((info->options & IPT_IPV4OPTION_DONT_MATCH_ANY_OPT) == IPT_IPV4OPTION_DONT_MATCH_ANY_OPT) &&
12834 + (((info->options & IPT_IPV4OPTION_MATCH_LSRR) == IPT_IPV4OPTION_MATCH_LSRR) ||
12835 + ((info->options & IPT_IPV4OPTION_MATCH_SSRR) == IPT_IPV4OPTION_MATCH_SSRR) ||
12836 + ((info->options & IPT_IPV4OPTION_MATCH_RR) == IPT_IPV4OPTION_MATCH_RR) ||
12837 + ((info->options & IPT_IPV4OPTION_MATCH_TIMESTAMP) == IPT_IPV4OPTION_MATCH_TIMESTAMP) ||
12838 + ((info->options & IPT_IPV4OPTION_MATCH_ROUTER_ALERT) == IPT_IPV4OPTION_MATCH_ROUTER_ALERT) ||
12839 + ((info->options & IPT_IPV4OPTION_MATCH_ANY_OPT) == IPT_IPV4OPTION_MATCH_ANY_OPT)))
12840 + return 0; /* opposites */
12841 + if (((info->options & IPT_IPV4OPTION_MATCH_SSRR) == IPT_IPV4OPTION_MATCH_SSRR) &&
12842 + ((info->options & IPT_IPV4OPTION_MATCH_LSRR) == IPT_IPV4OPTION_MATCH_LSRR))
12843 + return 0; /* cannot match in the same time loose and strict source routing */
12844 + if ((((info->options & IPT_IPV4OPTION_MATCH_SSRR) == IPT_IPV4OPTION_MATCH_SSRR) ||
12845 + ((info->options & IPT_IPV4OPTION_MATCH_LSRR) == IPT_IPV4OPTION_MATCH_LSRR)) &&
12846 + ((info->options & IPT_IPV4OPTION_DONT_MATCH_SRR) == IPT_IPV4OPTION_DONT_MATCH_SRR))
12847 + return 0; /* opposites */
12848 + if (((info->options & IPT_IPV4OPTION_MATCH_RR) == IPT_IPV4OPTION_MATCH_RR) &&
12849 + ((info->options & IPT_IPV4OPTION_DONT_MATCH_RR) == IPT_IPV4OPTION_DONT_MATCH_RR))
12850 + return 0; /* opposites */
12851 + if (((info->options & IPT_IPV4OPTION_MATCH_TIMESTAMP) == IPT_IPV4OPTION_MATCH_TIMESTAMP) &&
12852 + ((info->options & IPT_IPV4OPTION_DONT_MATCH_TIMESTAMP) == IPT_IPV4OPTION_DONT_MATCH_TIMESTAMP))
12853 + return 0; /* opposites */
12854 + if (((info->options & IPT_IPV4OPTION_MATCH_ROUTER_ALERT) == IPT_IPV4OPTION_MATCH_ROUTER_ALERT) &&
12855 + ((info->options & IPT_IPV4OPTION_DONT_MATCH_ROUTER_ALERT) == IPT_IPV4OPTION_DONT_MATCH_ROUTER_ALERT))
12856 + return 0; /* opposites */
12858 + /* everything looks ok. */
12862 +static struct ipt_match ipv4options_match = {
12863 + .name = "ipv4options",
12865 + .checkentry = checkentry,
12866 + .me = THIS_MODULE
12869 +static int __init init(void)
12871 + return ipt_register_match(&ipv4options_match);
12874 +static void __exit fini(void)
12876 + ipt_unregister_match(&ipv4options_match);
12879 +module_init(init);
12880 +module_exit(fini);
12881 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_mport.c linux-2.6.6/net/ipv4/netfilter/ipt_mport.c
12882 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_mport.c 1970-01-01 01:00:00.000000000 +0100
12883 +++ linux-2.6.6/net/ipv4/netfilter/ipt_mport.c 2004-05-18 14:28:50.000000000 +0200
12885 +/* Kernel module to match one of a list of TCP/UDP ports: ports are in
12886 + the same place so we can treat them as equal. */
12887 +#include <linux/module.h>
12888 +#include <linux/types.h>
12889 +#include <linux/udp.h>
12890 +#include <linux/skbuff.h>
12892 +#include <linux/netfilter_ipv4/ipt_mport.h>
12893 +#include <linux/netfilter_ipv4/ip_tables.h>
12895 +MODULE_LICENSE("GPL");
12898 +#define duprintf(format, args...) printk(format , ## args)
12900 +#define duprintf(format, args...)
12903 +/* Returns 1 if the port is matched by the test, 0 otherwise. */
12905 +ports_match(const struct ipt_mport *minfo, u_int16_t src, u_int16_t dst)
12909 + u_int16_t pflags = minfo->pflags;
12910 + for (i=0, m=1; i<IPT_MULTI_PORTS; i++, m<<=1) {
12914 + && minfo->ports[i] == 65535)
12917 + s = minfo->ports[i];
12919 + if (pflags & m) {
12920 + e = minfo->ports[++i];
12925 + if (minfo->flags & IPT_MPORT_SOURCE
12926 + && src >= s && src <= e)
12929 + if (minfo->flags & IPT_MPORT_DESTINATION
12930 + && dst >= s && dst <= e)
12938 +match(const struct sk_buff *skb,
12939 + const struct net_device *in,
12940 + const struct net_device *out,
12941 + const void *matchinfo,
12946 + const struct ipt_mport *minfo = matchinfo;
12951 + /* Must be big enough to read ports (both UDP and TCP have
12952 + them at the start). */
12953 + if (skb_copy_bits(skb, skb->nh.iph->ihl*4, ports, sizeof(ports)) < 0) {
12954 + /* We've been asked to examine this packet, and we
12955 + can't. Hence, no choice but to drop. */
12956 + duprintf("ipt_multiport:"
12957 + " Dropping evil offset=0 tinygram.\n");
12962 + return ports_match(minfo, ntohs(ports[0]), ntohs(ports[1]));
12965 +/* Called when user tries to insert an entry of this type. */
12967 +checkentry(const char *tablename,
12968 + const struct ipt_ip *ip,
12970 + unsigned int matchsize,
12971 + unsigned int hook_mask)
12973 + if (matchsize != IPT_ALIGN(sizeof(struct ipt_mport)))
12976 + /* Must specify proto == TCP/UDP, no unknown flags or bad count */
12977 + return (ip->proto == IPPROTO_TCP || ip->proto == IPPROTO_UDP)
12978 + && !(ip->invflags & IPT_INV_PROTO)
12979 + && matchsize == IPT_ALIGN(sizeof(struct ipt_mport));
12982 +static struct ipt_match mport_match = {
12985 + .checkentry = &checkentry,
12986 + .me = THIS_MODULE
12989 +static int __init init(void)
12991 + return ipt_register_match(&mport_match);
12994 +static void __exit fini(void)
12996 + ipt_unregister_match(&mport_match);
12999 +module_init(init);
13000 +module_exit(fini);
13001 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_nth.c linux-2.6.6/net/ipv4/netfilter/ipt_nth.c
13002 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_nth.c 1970-01-01 01:00:00.000000000 +0100
13003 +++ linux-2.6.6/net/ipv4/netfilter/ipt_nth.c 2004-05-18 14:28:50.000000000 +0200
13006 + This is a module which is used for match support for every Nth packet
13007 + This file is distributed under the terms of the GNU General Public
13008 + License (GPL). Copies of the GPL can be obtained from:
13009 + ftp://prep.ai.mit.edu/pub/gnu/GPL
13011 + 2001-07-18 Fabrice MARIE <fabrice@netfilter.org> : initial implementation.
13012 + 2001-09-20 Richard Wagner (rwagner@cloudnet.com)
13013 + * added support for multiple counters
13014 + * added support for matching on individual packets
13015 + in the counter cycle
13016 + 2004-02-19 Harald Welte <laforge@netfilter.org>
13021 +#include <linux/module.h>
13022 +#include <linux/skbuff.h>
13023 +#include <linux/ip.h>
13024 +#include <net/tcp.h>
13025 +#include <linux/spinlock.h>
13026 +#include <linux/netfilter_ipv4/ip_tables.h>
13027 +#include <linux/netfilter_ipv4/ipt_nth.h>
13029 +MODULE_LICENSE("GPL");
13030 +MODULE_AUTHOR("Fabrice Marie <fabrice@netfilter.org>");
13033 + * State information.
13037 + u_int16_t number;
13040 +static struct state states[IPT_NTH_NUM_COUNTERS];
13043 +ipt_nth_match(const struct sk_buff *pskb,
13044 + const struct net_device *in,
13045 + const struct net_device *out,
13046 + const void *matchinfo,
13050 + /* Parameters from userspace */
13051 + const struct ipt_nth_info *info = matchinfo;
13052 + unsigned counter = info->counter;
13053 + if((counter < 0) || (counter >= IPT_NTH_NUM_COUNTERS))
13055 + printk(KERN_WARNING "nth: invalid counter %u. counter between 0 and %u\n", counter, IPT_NTH_NUM_COUNTERS-1);
13059 + spin_lock(&states[counter].lock);
13061 + /* Are we matching every nth packet?*/
13062 + if (info->packet == 0xFF)
13064 + /* We're matching every nth packet and only every nth packet*/
13065 + /* Do we match or invert match? */
13066 + if (info->not == 0)
13068 + if (states[counter].number == 0)
13070 + ++states[counter].number;
13073 + if (states[counter].number >= info->every)
13074 + states[counter].number = 0; /* reset the counter */
13076 + ++states[counter].number;
13081 + if (states[counter].number == 0)
13083 + ++states[counter].number;
13086 + if (states[counter].number >= info->every)
13087 + states[counter].number = 0;
13089 + ++states[counter].number;
13095 + /* We're using the --packet, so there must be a rule for every value */
13096 + if (states[counter].number == info->packet)
13098 + /* only increment the counter when a match happens */
13099 + if (states[counter].number >= info->every)
13100 + states[counter].number = 0; /* reset the counter */
13102 + ++states[counter].number;
13110 + /* don't match */
13111 + spin_unlock(&states[counter].lock);
13115 + spin_unlock(&states[counter].lock);
13120 +ipt_nth_checkentry(const char *tablename,
13121 + const struct ipt_ip *e,
13123 + unsigned int matchsize,
13124 + unsigned int hook_mask)
13126 + /* Parameters from userspace */
13127 + const struct ipt_nth_info *info = matchinfo;
13128 + unsigned counter = info->counter;
13129 + if((counter < 0) || (counter >= IPT_NTH_NUM_COUNTERS))
13131 + printk(KERN_WARNING "nth: invalid counter %u. counter between 0 and %u\n", counter, IPT_NTH_NUM_COUNTERS-1);
13135 + if (matchsize != IPT_ALIGN(sizeof(struct ipt_nth_info))) {
13136 + printk("nth: matchsize %u != %u\n", matchsize,
13137 + IPT_ALIGN(sizeof(struct ipt_nth_info)));
13141 + states[counter].number = info->startat;
13146 +static struct ipt_match ipt_nth_reg = {
13148 + .match = ipt_nth_match,
13149 + .checkentry = ipt_nth_checkentry,
13150 + .me = THIS_MODULE
13153 +static int __init init(void)
13155 + unsigned counter;
13157 + memset(&states, 0, sizeof(states));
13158 + for (counter = 0; counter < IPT_NTH_NUM_COUNTERS; counter++)
13159 + spin_lock_init(&(states[counter].lock));
13161 + return ipt_register_match(&ipt_nth_reg);
13164 +static void __exit fini(void)
13166 + ipt_unregister_match(&ipt_nth_reg);
13169 +module_init(init);
13170 +module_exit(fini);
13171 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_osf.c linux-2.6.6/net/ipv4/netfilter/ipt_osf.c
13172 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_osf.c 1970-01-01 01:00:00.000000000 +0100
13173 +++ linux-2.6.6/net/ipv4/netfilter/ipt_osf.c 2004-05-18 14:28:50.000000000 +0200
13178 + * Copyright (c) 2003 Evgeniy Polyakov <johnpol@2ka.mipt.ru>
13181 + * This program is free software; you can redistribute it and/or modify
13182 + * it under the terms of the GNU General Public License as published by
13183 + * the Free Software Foundation; either version 2 of the License, or
13184 + * (at your option) any later version.
13186 + * This program is distributed in the hope that it will be useful,
13187 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13188 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13189 + * GNU General Public License for more details.
13191 + * You should have received a copy of the GNU General Public License
13192 + * along with this program; if not, write to the Free Software
13193 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
13197 + * OS fingerprint matching module.
13198 + * It simply compares various parameters from SYN packet with
13199 + * some hardcoded ones.
13201 + * Original table was created by Michal Zalewski <lcamtuf@coredump.cx>
13205 +#include <linux/config.h>
13206 +#include <linux/kernel.h>
13207 +#include <linux/types.h>
13208 +#include <linux/string.h>
13209 +#include <linux/smp.h>
13210 +#include <linux/module.h>
13211 +#include <linux/skbuff.h>
13212 +#include <linux/file.h>
13213 +#include <linux/ip.h>
13214 +#include <linux/proc_fs.h>
13215 +#include <linux/fs.h>
13216 +#include <linux/slab.h>
13217 +#include <linux/spinlock.h>
13218 +#include <linux/ctype.h>
13219 +#include <linux/list.h>
13220 +#include <linux/if.h>
13222 +#include <net/sock.h>
13223 +#include <net/ip.h>
13225 +#include <linux/netfilter_ipv4/ip_tables.h>
13227 +#include <linux/netfilter_ipv4/ipt_osf.h>
13232 +#define log(x...) printk(KERN_INFO "ipt_osf: " x)
13233 +#define loga(x...) printk(x)
13235 +#define log(x...) do {} while(0)
13236 +#define loga(x...) do {} while(0)
13239 +#define FMATCH_WRONG 0
13240 +#define FMATCH_OK 1
13241 +#define FMATCH_OPT_WRONG 2
13243 +#define OPTDEL ','
13244 +#define OSFPDEL ':'
13245 +#define MAXOPTSTRLEN 128
13246 +#define OSFFLUSH "FLUSH"
13248 +static rwlock_t osf_lock = RW_LOCK_UNLOCKED;
13249 +static spinlock_t ipt_osf_netlink_lock = SPIN_LOCK_UNLOCKED;
13250 +static struct list_head finger_list;
13251 +static int match(const struct sk_buff *, const struct net_device *, const struct net_device *,
13252 + const void *, int,
13253 + const void *, u_int16_t,
13255 +static int checkentry(const char *, const struct ipt_ip *, void *,
13256 + unsigned int, unsigned int);
13258 +static unsigned long seq, ipt_osf_groups = 1;
13259 +static struct sock *nts;
13261 +static struct ipt_match osf_match =
13271 +static void ipt_osf_nlsend(struct osf_finger *f, const struct sk_buff *sk)
13273 + unsigned int size;
13274 + struct sk_buff *skb;
13275 + struct ipt_osf_nlmsg *data;
13276 + struct nlmsghdr *nlh;
13278 + size = NLMSG_SPACE(sizeof(struct ipt_osf_nlmsg));
13280 + skb = alloc_skb(size, GFP_ATOMIC);
13283 + log("skb_alloc() failed.\n");
13287 + nlh = NLMSG_PUT(skb, 0, seq++, NLMSG_DONE, size - sizeof(*nlh));
13289 + data = (struct ipt_osf_nlmsg *)NLMSG_DATA(nlh);
13291 + memcpy(&data->f, f, sizeof(struct osf_finger));
13292 + memcpy(&data->ip, sk->nh.iph, sizeof(struct iphdr));
13293 + memcpy(&data->tcp, (struct tcphdr *)((u_int32_t *)sk->nh.iph + sk->nh.iph->ihl), sizeof(struct tcphdr));
13295 + NETLINK_CB(skb).dst_groups = ipt_osf_groups;
13296 + netlink_broadcast(nts, skb, 0, ipt_osf_groups, GFP_ATOMIC);
13302 +static inline int smart_dec(const struct sk_buff *skb, unsigned long flags, unsigned char f_ttl)
13304 + struct iphdr *ip = skb->nh.iph;
13306 + if (flags & IPT_OSF_SMART)
13308 + struct in_device *in_dev = in_dev_get(skb->dev);
13312 + if (inet_ifa_match(ip->saddr, ifa))
13314 + in_dev_put(in_dev);
13315 + return (ip->ttl == f_ttl);
13318 + endfor_ifa(in_dev);
13320 + in_dev_put(in_dev);
13321 + return (ip->ttl <= f_ttl);
13324 + return (ip->ttl == f_ttl);
13328 +match(const struct sk_buff *skb, const struct net_device *in, const struct net_device *out,
13329 + const void *matchinfo, int offset,
13330 + const void *hdr, u_int16_t datalen,
13333 + struct ipt_osf_info *info = (struct ipt_osf_info *)matchinfo;
13334 + struct iphdr *ip = skb->nh.iph;
13335 + struct tcphdr *tcp;
13336 + int fmatch = FMATCH_WRONG, fcount = 0;
13337 + unsigned long totlen, optsize = 0, window;
13338 + unsigned char df, *optp = NULL, *_optp = NULL;
13339 + char check_WSS = 0;
13340 + struct list_head *ent;
13341 + struct osf_finger *f;
13343 + if (!ip || !info)
13346 + tcp = (struct tcphdr *)((u_int32_t *)ip + ip->ihl);
13351 + totlen = ntohs(ip->tot_len);
13352 + df = ((ntohs(ip->frag_off) & IP_DF)?1:0);
13353 + window = ntohs(tcp->window);
13355 + if (tcp->doff*4 > sizeof(struct tcphdr))
13357 + _optp = optp = (char *)(tcp+1);
13358 + optsize = tcp->doff*4 - sizeof(struct tcphdr);
13362 + /* Actually we can create hash/table of all genres and search
13363 + * only in appropriate part, but here is initial variant,
13364 + * so will use slow path.
13366 + read_lock(&osf_lock);
13367 + list_for_each(ent, &finger_list)
13369 + f = list_entry(ent, struct osf_finger, flist);
13371 + if (!(info->flags & IPT_OSF_LOG) && strcmp(info->genre, f->genre))
13375 + fmatch = FMATCH_WRONG;
13377 + if (totlen == f->ss && df == f->df &&
13378 + smart_dec(skb, info->flags, f->ttl))
13380 + unsigned long foptsize;
13382 + unsigned short mss = 0;
13386 + switch (f->wss.wc)
13388 + case 0: check_WSS = 0; break;
13389 + case 'S': check_WSS = 1; break;
13390 + case 'T': check_WSS = 2; break;
13391 + case '%': check_WSS = 3; break;
13392 + default: log("Wrong fingerprint wss.wc=%d, %s - %s\n",
13393 + f->wss.wc, f->genre, f->details);
13397 + if (check_WSS == 4)
13400 + /* Check options */
13403 + for (optnum=0; optnum<f->opt_num; ++optnum)
13404 + foptsize += f->opt[optnum].length;
13407 + if (foptsize > MAX_IPOPTLEN || optsize > MAX_IPOPTLEN || optsize != foptsize)
13412 + fmatch = FMATCH_OK;
13413 + loga("\tYEP : matching without options.\n");
13414 + if ((info->flags & IPT_OSF_LOG) &&
13415 + info->loglevel == IPT_OSF_LOGLEVEL_FIRST)
13422 + for (optnum=0; optnum<f->opt_num; ++optnum)
13424 + if (f->opt[optnum].kind == (*optp))
13426 + unsigned char len = f->opt[optnum].length;
13427 + unsigned char *optend = optp + len;
13428 + int loop_cont = 0;
13430 + fmatch = FMATCH_OK;
13436 + mss = ntohs(*(unsigned short *)(optp+2));
13451 + /* Skip kind and length fields*/
13454 + if (f->opt[optnum].wc.val != 0)
13456 + unsigned long tmp = 0;
13458 + /* Hmmm... It looks a bit ugly. :) */
13459 + memcpy(&tmp, optp,
13460 + (len > sizeof(unsigned long)?
13461 + sizeof(unsigned long):len));
13462 + /* 2 + 2: optlen(2 bytes) +
13463 + * kind(1 byte) + length(1 byte) */
13465 + tmp = ntohs(tmp);
13467 + tmp = ntohl(tmp);
13469 + if (f->opt[optnum].wc.wc == '%')
13471 + if ((tmp % f->opt[optnum].wc.val) != 0)
13472 + fmatch = FMATCH_OPT_WRONG;
13474 + else if (tmp != f->opt[optnum].wc.val)
13475 + fmatch = FMATCH_OPT_WRONG;
13482 + fmatch = FMATCH_OPT_WRONG;
13484 + if (fmatch != FMATCH_OK)
13488 + if (fmatch != FMATCH_OPT_WRONG)
13490 + fmatch = FMATCH_WRONG;
13492 + switch (check_WSS)
13495 + if (f->wss.val == 0 || window == f->wss.val)
13496 + fmatch = FMATCH_OK;
13498 + case 1: /* MSS */
13499 +/* Lurked in OpenBSD */
13500 +#define SMART_MSS 1460
13501 + if (window == f->wss.val*mss ||
13502 + window == f->wss.val*SMART_MSS)
13503 + fmatch = FMATCH_OK;
13505 + case 2: /* MTU */
13506 + if (window == f->wss.val*(mss+40) ||
13507 + window == f->wss.val*(SMART_MSS+40))
13508 + fmatch = FMATCH_OK;
13510 + case 3: /* MOD */
13511 + if ((window % f->wss.val) == 0)
13512 + fmatch = FMATCH_OK;
13518 + if (fmatch == FMATCH_OK)
13521 + log("%s [%s:%s:%s] : %u.%u.%u.%u:%u -> %u.%u.%u.%u:%u hops=%d\n",
13522 + f->genre, f->version,
13523 + f->subtype, f->details,
13524 + NIPQUAD(ip->saddr), ntohs(tcp->source),
13525 + NIPQUAD(ip->daddr), ntohs(tcp->dest),
13526 + f->ttl - ip->ttl);
13527 + if (info->flags & IPT_OSF_NETLINK)
13529 + spin_lock_bh(&ipt_osf_netlink_lock);
13530 + ipt_osf_nlsend(f, skb);
13531 + spin_unlock_bh(&ipt_osf_netlink_lock);
13533 + if ((info->flags & IPT_OSF_LOG) &&
13534 + info->loglevel == IPT_OSF_LOGLEVEL_FIRST)
13539 + if (!fcount && (info->flags & (IPT_OSF_LOG | IPT_OSF_NETLINK)))
13541 + unsigned char opt[4 * 15 - sizeof(struct tcphdr)];
13542 + unsigned int i, optsize;
13543 + struct osf_finger fg;
13545 + memset(&fg, 0, sizeof(fg));
13547 + if ((info->flags & IPT_OSF_LOG))
13548 + log("Unknown: %lu:%d:%d:%lu:", window, ip->ttl, df, totlen);
13551 + optsize = tcp->doff * 4 - sizeof(struct tcphdr);
13552 + if (skb_copy_bits(skb, ip->ihl*4 + sizeof(struct tcphdr),
13553 + opt, optsize) < 0)
13555 + if (info->flags & IPT_OSF_LOG)
13556 + loga("TRUNCATED");
13557 + if (info->flags & IPT_OSF_NETLINK)
13558 + strcpy(fg.details, "TRUNCATED");
13562 + for (i = 0; i < optsize; i++)
13564 + if (info->flags & IPT_OSF_LOG)
13565 + loga("%02X", opt[i]);
13567 + if (info->flags & IPT_OSF_NETLINK)
13568 + memcpy(fg.details, opt, MAXDETLEN);
13571 + if ((info->flags & IPT_OSF_LOG))
13572 + loga(" %u.%u.%u.%u:%u -> %u.%u.%u.%u:%u\n",
13573 + NIPQUAD(ip->saddr), ntohs(tcp->source),
13574 + NIPQUAD(ip->daddr), ntohs(tcp->dest));
13576 + if (info->flags & IPT_OSF_NETLINK)
13578 + fg.wss.val = window;
13579 + fg.ttl = ip->ttl;
13582 + strncpy(fg.genre, "Unknown", MAXGENRELEN);
13584 + spin_lock_bh(&ipt_osf_netlink_lock);
13585 + ipt_osf_nlsend(&fg, skb);
13586 + spin_unlock_bh(&ipt_osf_netlink_lock);
13590 + read_unlock(&osf_lock);
13592 + return (fmatch == FMATCH_OK)?1:0;
13596 +checkentry(const char *tablename,
13597 + const struct ipt_ip *ip,
13599 + unsigned int matchsize,
13600 + unsigned int hook_mask)
13602 + if (matchsize != IPT_ALIGN(sizeof(struct ipt_osf_info)))
13604 + if (ip->proto != IPPROTO_TCP)
13610 +static char * osf_strchr(char *ptr, char c)
13614 + tmp = strchr(ptr, c);
13616 + while (tmp && tmp+1 && isspace(*(tmp+1)))
13622 +static struct osf_finger * finger_alloc(void)
13624 + struct osf_finger *f;
13626 + f = kmalloc(sizeof(struct osf_finger), GFP_KERNEL);
13628 + memset(f, 0, sizeof(struct osf_finger));
13633 +static void finger_free(struct osf_finger *f)
13635 + memset(f, 0, sizeof(struct osf_finger));
13640 +static void osf_parse_opt(struct osf_opt *opt, int *optnum, char *obuf, int olen)
13644 + unsigned long val;
13648 + while (ptr != NULL && i < olen)
13657 + ptr = osf_strchr(&obuf[i], OPTDEL);
13662 + i += (int)(ptr-&obuf[i]);
13669 + op = OSFOPT_SACKP;
13670 + ptr = osf_strchr(&obuf[i], OPTDEL);
13675 + i += (int)(ptr-&obuf[i]);
13683 + ptr = osf_strchr(&obuf[i], OPTDEL);
13688 + i += (int)(ptr-&obuf[i]);
13696 + ptr = osf_strchr(&obuf[i], OPTDEL);
13699 + switch (obuf[i+1])
13701 + case '%': wc = '%'; break;
13702 + case 'S': wc = 'S'; break;
13703 + case 'T': wc = 'T'; break;
13704 + default: wc = 0; break;
13710 + val = simple_strtoul(&obuf[i+2], NULL, 10);
13712 + val = simple_strtoul(&obuf[i+1], NULL, 10);
13713 + i += (int)(ptr-&obuf[i]);
13721 + ptr = osf_strchr(&obuf[i], OPTDEL);
13724 + if (obuf[i+1] == '%')
13729 + val = simple_strtoul(&obuf[i+2], NULL, 10);
13731 + val = simple_strtoul(&obuf[i+1], NULL, 10);
13732 + i += (int)(ptr-&obuf[i]);
13740 + ptr = osf_strchr(&obuf[i], OPTDEL);
13745 + i += (int)(ptr-&obuf[i]);
13752 + ptr = osf_strchr(&obuf[i], OPTDEL);
13756 + i += (int)(ptr-&obuf[i]);
13764 + opt[*optnum].kind = IANA_opts[op].kind;
13765 + opt[*optnum].length = IANA_opts[op].length;
13766 + opt[*optnum].wc.wc = wc;
13767 + opt[*optnum].wc.val = val;
13773 +static int osf_proc_read(char *buf, char **start, off_t off, int count, int *eof, void *data)
13775 + struct list_head *ent;
13776 + struct osf_finger *f = NULL;
13782 + read_lock_bh(&osf_lock);
13783 + list_for_each(ent, &finger_list)
13785 + f = list_entry(ent, struct osf_finger, flist);
13787 + log("%s [%s]", f->genre, f->details);
13789 + count += sprintf(buf+count, "%s - %s[%s] : %s",
13790 + f->genre, f->version,
13791 + f->subtype, f->details);
13796 + //count += sprintf(buf+count, " OPT: ");
13797 + for (i=0; i<f->opt_num; ++i)
13799 + //count += sprintf(buf+count, "%d.%c%lu; ",
13800 + // f->opt[i].kind, (f->opt[i].wc.wc)?f->opt[i].wc.wc:' ', f->opt[i].wc.val);
13801 + loga("%d.%c%lu; ",
13802 + f->opt[i].kind, (f->opt[i].wc.wc)?f->opt[i].wc.wc:' ', f->opt[i].wc.val);
13806 + count += sprintf(buf+count, "\n");
13808 + read_unlock_bh(&osf_lock);
13813 +static int osf_proc_write(struct file *file, const char *buffer, unsigned long count, void *data)
13817 + char obuf[MAXOPTSTRLEN];
13818 + struct osf_finger *finger;
13819 + struct list_head *ent, *n;
13821 + char *pbeg, *pend;
13823 + if (count == strlen(OSFFLUSH) && !strncmp(buffer, OSFFLUSH, strlen(OSFFLUSH)))
13826 + write_lock_bh(&osf_lock);
13827 + list_for_each_safe(ent, n, &finger_list)
13830 + finger = list_entry(ent, struct osf_finger, flist);
13831 + list_del(&finger->flist);
13832 + finger_free(finger);
13834 + write_unlock_bh(&osf_lock);
13836 + log("Flushed %d entries.\n", i);
13843 + for (i=0; i<count && buffer[i] != '\0'; ++i)
13844 + if (buffer[i] == ':')
13847 + if (cnt != 8 || i != count)
13849 + log("Wrong input line cnt=%d[8], len=%lu[%lu]\n",
13854 + memset(obuf, 0, sizeof(obuf));
13856 + finger = finger_alloc();
13859 + log("Failed to allocate new fingerprint entry.\n");
13863 + pbeg = (char *)buffer;
13864 + pend = osf_strchr(pbeg, OSFPDEL);
13868 + if (pbeg[0] == 'S')
13870 + finger->wss.wc = 'S';
13871 + if (pbeg[1] == '%')
13872 + finger->wss.val = simple_strtoul(pbeg+2, NULL, 10);
13873 + else if (pbeg[1] == '*')
13874 + finger->wss.val = 0;
13876 + finger->wss.val = simple_strtoul(pbeg+1, NULL, 10);
13878 + else if (pbeg[0] == 'T')
13880 + finger->wss.wc = 'T';
13881 + if (pbeg[1] == '%')
13882 + finger->wss.val = simple_strtoul(pbeg+2, NULL, 10);
13883 + else if (pbeg[1] == '*')
13884 + finger->wss.val = 0;
13886 + finger->wss.val = simple_strtoul(pbeg+1, NULL, 10);
13888 + else if (pbeg[0] == '%')
13890 + finger->wss.wc = '%';
13891 + finger->wss.val = simple_strtoul(pbeg+1, NULL, 10);
13893 + else if (isdigit(pbeg[0]))
13895 + finger->wss.wc = 0;
13896 + finger->wss.val = simple_strtoul(pbeg, NULL, 10);
13901 + pend = osf_strchr(pbeg, OSFPDEL);
13905 + finger->ttl = simple_strtoul(pbeg, NULL, 10);
13908 + pend = osf_strchr(pbeg, OSFPDEL);
13912 + finger->df = simple_strtoul(pbeg, NULL, 10);
13915 + pend = osf_strchr(pbeg, OSFPDEL);
13919 + finger->ss = simple_strtoul(pbeg, NULL, 10);
13923 + pend = osf_strchr(pbeg, OSFPDEL);
13927 + cnt = snprintf(obuf, sizeof(obuf), "%s", pbeg);
13931 + pend = osf_strchr(pbeg, OSFPDEL);
13935 + if (pbeg[0] == '@' || pbeg[0] == '*')
13936 + cnt = snprintf(finger->genre, sizeof(finger->genre), "%s", pbeg+1);
13938 + cnt = snprintf(finger->genre, sizeof(finger->genre), "%s", pbeg);
13942 + pend = osf_strchr(pbeg, OSFPDEL);
13946 + cnt = snprintf(finger->version, sizeof(finger->version), "%s", pbeg);
13950 + pend = osf_strchr(pbeg, OSFPDEL);
13954 + cnt = snprintf(finger->subtype, sizeof(finger->subtype), "%s", pbeg);
13958 + cnt = snprintf(finger->details,
13959 + ((count - (pbeg - buffer)+1) > MAXDETLEN)?MAXDETLEN:(count - (pbeg - buffer)+1),
13962 + log("%s - %s[%s] : %s\n",
13963 + finger->genre, finger->version,
13964 + finger->subtype, finger->details);
13966 + osf_parse_opt(finger->opt, &finger->opt_num, obuf, sizeof(obuf));
13969 + write_lock_bh(&osf_lock);
13970 + list_add_tail(&finger->flist, &finger_list);
13971 + write_unlock_bh(&osf_lock);
13976 +static int __init osf_init(void)
13979 + struct proc_dir_entry *p;
13981 + log("Startng OS fingerprint matching module.\n");
13983 + INIT_LIST_HEAD(&finger_list);
13985 + err = ipt_register_match(&osf_match);
13988 + log("Failed to register OS fingerprint matching module.\n");
13992 + p = create_proc_entry("sys/net/ipv4/osf", S_IFREG | 0644, NULL);
13995 + ipt_unregister_match(&osf_match);
13999 + p->write_proc = osf_proc_write;
14000 + p->read_proc = osf_proc_read;
14002 + nts = netlink_kernel_create(NETLINK_NFLOG, NULL);
14005 + log("netlink_kernel_create() failed\n");
14006 + remove_proc_entry("sys/net/ipv4/osf", NULL);
14007 + ipt_unregister_match(&osf_match);
14014 +static void __exit osf_fini(void)
14016 + struct list_head *ent, *n;
14017 + struct osf_finger *f;
14019 + remove_proc_entry("sys/net/ipv4/osf", NULL);
14020 + ipt_unregister_match(&osf_match);
14021 + if (nts && nts->sk_socket)
14022 + sock_release(nts->sk_socket);
14024 + list_for_each_safe(ent, n, &finger_list)
14026 + f = list_entry(ent, struct osf_finger, flist);
14027 + list_del(&f->flist);
14031 + log("OS fingerprint matching module finished.\n");
14034 +module_init(osf_init);
14035 +module_exit(osf_fini);
14037 +MODULE_LICENSE("GPL");
14038 +MODULE_AUTHOR("Evgeniy Polyakov <johnpol@2ka.mipt.ru>");
14039 +MODULE_DESCRIPTION("Passive OS fingerprint matching.");
14040 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_owner.c linux-2.6.6/net/ipv4/netfilter/ipt_owner.c
14041 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_owner.c 2004-05-10 04:33:20.000000000 +0200
14042 +++ linux-2.6.6/net/ipv4/netfilter/ipt_owner.c 2004-05-18 14:28:50.000000000 +0200
14044 * This program is free software; you can redistribute it and/or modify
14045 * it under the terms of the GNU General Public License version 2 as
14046 * published by the Free Software Foundation.
14048 + * 03/26/2003 Patrick McHardy <kaber@trash.net> : LOCAL_IN support
14051 #include <linux/module.h>
14052 #include <linux/skbuff.h>
14053 #include <linux/file.h>
14054 +#include <linux/ip.h>
14055 +#include <linux/tcp.h>
14056 +#include <linux/udp.h>
14057 #include <net/sock.h>
14058 +#include <net/tcp.h>
14059 +#include <net/udp.h>
14061 #include <linux/netfilter_ipv4/ipt_owner.h>
14062 #include <linux/netfilter_ipv4/ip_tables.h>
14064 MODULE_DESCRIPTION("iptables owner match");
14067 -match_comm(const struct sk_buff *skb, const char *comm)
14068 +match_comm(const struct sock *sk, const char *comm)
14070 struct task_struct *g, *p;
14071 struct files_struct *files;
14073 spin_lock(&files->file_lock);
14074 for (i=0; i < files->max_fds; i++) {
14075 if (fcheck_files(files, i) ==
14076 - skb->sk->sk_socket->file) {
14077 + sk->sk_socket->file) {
14078 spin_unlock(&files->file_lock);
14080 read_unlock(&tasklist_lock);
14085 -match_pid(const struct sk_buff *skb, pid_t pid)
14086 +match_pid(const struct sock *sk, pid_t pid)
14088 struct task_struct *p;
14089 struct files_struct *files;
14091 spin_lock(&files->file_lock);
14092 for (i=0; i < files->max_fds; i++) {
14093 if (fcheck_files(files, i) ==
14094 - skb->sk->sk_socket->file) {
14095 + sk->sk_socket->file) {
14096 spin_unlock(&files->file_lock);
14098 read_unlock(&tasklist_lock);
14099 @@ -86,10 +93,10 @@
14103 -match_sid(const struct sk_buff *skb, pid_t sid)
14104 +match_sid(const struct sock *sk, pid_t sid)
14106 struct task_struct *g, *p;
14107 - struct file *file = skb->sk->sk_socket->file;
14108 + struct file *file = sk->sk_socket->file;
14111 read_lock(&tasklist_lock);
14112 @@ -129,41 +136,71 @@
14115 const struct ipt_owner_info *info = matchinfo;
14116 + struct iphdr *iph = skb->nh.iph;
14117 + struct sock *sk = NULL;
14123 + if (iph->protocol == IPPROTO_TCP) {
14124 + struct tcphdr *tcph =
14125 + (struct tcphdr *)((u_int32_t *)iph + iph->ihl);
14126 + sk = tcp_v4_lookup(iph->saddr, tcph->source,
14127 + iph->daddr, tcph->dest,
14128 + skb->dev->ifindex);
14129 + if (sk && sk->sk_state == TCP_TIME_WAIT) {
14130 + tcp_tw_put((struct tcp_tw_bucket *)sk);
14133 + } else if (iph->protocol == IPPROTO_UDP) {
14134 + struct udphdr *udph =
14135 + (struct udphdr *)((u_int32_t *)iph + iph->ihl);
14136 + sk = udp_v4_lookup(iph->saddr, udph->source, iph->daddr,
14137 + udph->dest, skb->dev->ifindex);
14141 - if (!skb->sk || !skb->sk->sk_socket || !skb->sk->sk_socket->file)
14143 + if (!sk || !sk->sk_socket || !sk->sk_socket->file)
14146 if(info->match & IPT_OWNER_UID) {
14147 - if ((skb->sk->sk_socket->file->f_uid != info->uid) ^
14148 + if ((sk->sk_socket->file->f_uid != info->uid) ^
14149 !!(info->invert & IPT_OWNER_UID))
14154 if(info->match & IPT_OWNER_GID) {
14155 - if ((skb->sk->sk_socket->file->f_gid != info->gid) ^
14156 + if ((sk->sk_socket->file->f_gid != info->gid) ^
14157 !!(info->invert & IPT_OWNER_GID))
14162 if(info->match & IPT_OWNER_PID) {
14163 - if (!match_pid(skb, info->pid) ^
14164 + if (!match_pid(sk, info->pid) ^
14165 !!(info->invert & IPT_OWNER_PID))
14170 if(info->match & IPT_OWNER_SID) {
14171 - if (!match_sid(skb, info->sid) ^
14172 + if (!match_sid(sk, info->sid) ^
14173 !!(info->invert & IPT_OWNER_SID))
14178 if(info->match & IPT_OWNER_COMM) {
14179 - if (!match_comm(skb, info->comm) ^
14180 + if (!match_comm(sk, info->comm) ^
14181 !!(info->invert & IPT_OWNER_COMM))
14197 @@ -173,11 +210,19 @@
14198 unsigned int matchsize,
14199 unsigned int hook_mask)
14202 - & ~((1 << NF_IP_LOCAL_OUT) | (1 << NF_IP_POST_ROUTING))) {
14203 - printk("ipt_owner: only valid for LOCAL_OUT or POST_ROUTING.\n");
14207 + & ~((1 << NF_IP_LOCAL_OUT) | (1 << NF_IP_POST_ROUTING) |
14208 + (1 << NF_IP_LOCAL_IN))) {
14209 + printk("ipt_owner: only valid for LOCAL_IN, LOCAL_OUT "
14210 + "or POST_ROUTING.\n");
14214 + if ((hook_mask & (1 << NF_IP_LOCAL_IN))
14215 + && ip->proto != IPPROTO_TCP && ip->proto != IPPROTO_UDP) {
14216 + printk("ipt_owner: only TCP or UDP can be used in LOCAL_IN\n");
14220 if (matchsize != IPT_ALIGN(sizeof(struct ipt_owner_info))) {
14221 printk("Matchsize %u != %Zu\n", matchsize,
14222 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_policy.c linux-2.6.6/net/ipv4/netfilter/ipt_policy.c
14223 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_policy.c 1970-01-01 01:00:00.000000000 +0100
14224 +++ linux-2.6.6/net/ipv4/netfilter/ipt_policy.c 2004-05-18 14:28:50.000000000 +0200
14226 +/* IP tables module for matching IPsec policy
14228 + * Copyright (c) 2004 Patrick McHardy, <kaber@trash.net>
14230 + * This program is free software; you can redistribute it and/or modify
14231 + * it under the terms of the GNU General Public License version 2 as
14232 + * published by the Free Software Foundation.
14235 +#include <linux/kernel.h>
14236 +#include <linux/config.h>
14237 +#include <linux/module.h>
14238 +#include <linux/skbuff.h>
14239 +#include <linux/init.h>
14240 +#include <net/xfrm.h>
14242 +#include <linux/netfilter_ipv4.h>
14243 +#include <linux/netfilter_ipv4/ipt_policy.h>
14244 +#include <linux/netfilter_ipv4/ip_tables.h>
14246 +MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
14247 +MODULE_DESCRIPTION("IPtables IPsec policy matching module");
14248 +MODULE_LICENSE("GPL");
14252 +match_xfrm_state(struct xfrm_state *x, const struct ipt_policy_elem *e)
14254 +#define MISMATCH(x,y) (e->match.x && ((e->x != (y)) ^ e->invert.x))
14256 + if (MISMATCH(saddr, x->props.saddr.a4 & e->smask) ||
14257 + MISMATCH(daddr, x->id.daddr.a4 & e->dmask) ||
14258 + MISMATCH(proto, x->id.proto) ||
14259 + MISMATCH(mode, x->props.mode) ||
14260 + MISMATCH(spi, x->id.spi) ||
14261 + MISMATCH(reqid, x->props.reqid))
14267 +match_policy_in(const struct sk_buff *skb, const struct ipt_policy_info *info)
14269 + const struct ipt_policy_elem *e;
14270 + struct sec_path *sp = skb->sp;
14271 + int strict = info->flags & POLICY_MATCH_STRICT;
14276 + if (strict && info->len != sp->len)
14279 + for (i = sp->len - 1; i >= 0; i--) {
14280 + pos = strict ? i - sp->len + 1 : 0;
14281 + if (pos >= info->len)
14283 + e = &info->pol[pos];
14285 + if (match_xfrm_state(sp->x[i].xvec, e)) {
14288 + } else if (strict)
14292 + return strict ? 1 : 0;
14296 +match_policy_out(const struct sk_buff *skb, const struct ipt_policy_info *info)
14298 + const struct ipt_policy_elem *e;
14299 + struct dst_entry *dst = skb->dst;
14300 + int strict = info->flags & POLICY_MATCH_STRICT;
14303 + if (dst->xfrm == NULL)
14306 + for (i = 0; dst && dst->xfrm; dst = dst->child, i++) {
14307 + pos = strict ? i : 0;
14308 + if (pos >= info->len)
14310 + e = &info->pol[pos];
14312 + if (match_xfrm_state(dst->xfrm, e)) {
14315 + } else if (strict)
14319 + return strict ? 1 : 0;
14322 +static int match(const struct sk_buff *skb,
14323 + const struct net_device *in,
14324 + const struct net_device *out,
14325 + const void *matchinfo, int offset, int *hotdrop)
14327 + const struct ipt_policy_info *info = matchinfo;
14330 + if (info->flags & POLICY_MATCH_IN)
14331 + ret = match_policy_in(skb, info);
14333 + ret = match_policy_out(skb, info);
14336 + if (info->flags & POLICY_MATCH_NONE)
14340 + } else if (info->flags & POLICY_MATCH_NONE)
14346 +static int checkentry(const char *tablename, const struct ipt_ip *ip,
14347 + void *matchinfo, unsigned int matchsize,
14348 + unsigned int hook_mask)
14350 + struct ipt_policy_info *info = matchinfo;
14352 + if (matchsize != IPT_ALIGN(sizeof(*info))) {
14353 + printk(KERN_ERR "ipt_policy: matchsize %u != %u\n",
14354 + matchsize, IPT_ALIGN(sizeof(*info)));
14357 + if (!(info->flags & (POLICY_MATCH_IN|POLICY_MATCH_OUT))) {
14358 + printk(KERN_ERR "ipt_policy: neither incoming nor "
14359 + "outgoing policy selected\n");
14362 + if (hook_mask & (1 << NF_IP_PRE_ROUTING | 1 << NF_IP_LOCAL_IN)
14363 + && info->flags & POLICY_MATCH_OUT) {
14364 + printk(KERN_ERR "ipt_policy: output policy not valid in "
14365 + "PRE_ROUTING and INPUT\n");
14368 + if (hook_mask & (1 << NF_IP_POST_ROUTING | 1 << NF_IP_LOCAL_OUT)
14369 + && info->flags & POLICY_MATCH_IN) {
14370 + printk(KERN_ERR "ipt_policy: input policy not valid in "
14371 + "POST_ROUTING and OUTPUT\n");
14374 + if (info->len > POLICY_MAX_ELEM) {
14375 + printk(KERN_ERR "ipt_policy: too many policy elements\n");
14382 +static struct ipt_match policy_match =
14384 + .name = "policy",
14386 + .checkentry = checkentry,
14387 + .me = THIS_MODULE,
14390 +static int __init init(void)
14392 + return ipt_register_match(&policy_match);
14395 +static void __exit fini(void)
14397 + ipt_unregister_match(&policy_match);
14400 +module_init(init);
14401 +module_exit(fini);
14402 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_pool.c linux-2.6.6/net/ipv4/netfilter/ipt_pool.c
14403 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_pool.c 1970-01-01 01:00:00.000000000 +0100
14404 +++ linux-2.6.6/net/ipv4/netfilter/ipt_pool.c 2004-05-18 14:28:50.000000000 +0200
14406 +/* Kernel module to match an IP address pool. */
14408 +#include <linux/module.h>
14409 +#include <linux/ip.h>
14410 +#include <linux/skbuff.h>
14412 +#include <linux/netfilter_ipv4/ip_tables.h>
14413 +#include <linux/netfilter_ipv4/ip_pool.h>
14414 +#include <linux/netfilter_ipv4/ipt_pool.h>
14416 +static inline int match_pool(
14421 + if (ip_pool_match(index, ntohl(addr)))
14427 + const struct sk_buff *skb,
14428 + const struct net_device *in,
14429 + const struct net_device *out,
14430 + const void *matchinfo,
14433 + u_int16_t datalen,
14436 + const struct ipt_pool_info *info = matchinfo;
14437 + const struct iphdr *iph = skb->nh.iph;
14439 + if (info->src != IP_POOL_NONE && !match_pool(info->src, iph->saddr,
14440 + info->flags&IPT_POOL_INV_SRC))
14443 + if (info->dst != IP_POOL_NONE && !match_pool(info->dst, iph->daddr,
14444 + info->flags&IPT_POOL_INV_DST))
14450 +static int checkentry(
14451 + const char *tablename,
14452 + const struct ipt_ip *ip,
14454 + unsigned int matchsize,
14455 + unsigned int hook_mask
14457 + if (matchsize != IPT_ALIGN(sizeof(struct ipt_pool_info)))
14462 +static struct ipt_match pool_match
14463 += { { NULL, NULL }, "pool", &match, &checkentry, NULL, THIS_MODULE };
14465 +static int __init init(void)
14467 + return ipt_register_match(&pool_match);
14470 +static void __exit fini(void)
14472 + ipt_unregister_match(&pool_match);
14475 +module_init(init);
14476 +module_exit(fini);
14477 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_psd.c linux-2.6.6/net/ipv4/netfilter/ipt_psd.c
14478 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_psd.c 1970-01-01 01:00:00.000000000 +0100
14479 +++ linux-2.6.6/net/ipv4/netfilter/ipt_psd.c 2004-05-18 14:28:50.000000000 +0200
14482 + This is a module which is used for PSD (portscan detection)
14483 + Derived from scanlogd v2.1 written by Solar Designer <solar@false.com>
14484 + and LOG target module.
14486 + Copyright (C) 2000,2001 astaro AG
14488 + This file is distributed under the terms of the GNU General Public
14489 + License (GPL). Copies of the GPL can be obtained from:
14490 + ftp://prep.ai.mit.edu/pub/gnu/GPL
14492 + 2000-05-04 Markus Hennig <hennig@astaro.de> : initial
14493 + 2000-08-18 Dennis Koslowski <koslowski@astaro.de> : first release
14494 + 2000-12-01 Dennis Koslowski <koslowski@astaro.de> : UDP scans detection added
14495 + 2001-01-02 Dennis Koslowski <koslowski@astaro.de> : output modified
14496 + 2001-02-04 Jan Rekorajski <baggins@pld.org.pl> : converted from target to match
14497 + 2004-05-05 Martijn Lievaart <m@rtij.nl> : ported to 2.6
14500 +#include <linux/module.h>
14501 +#include <linux/skbuff.h>
14502 +#include <linux/ip.h>
14503 +#include <net/tcp.h>
14504 +#include <linux/spinlock.h>
14505 +#include <linux/netfilter_ipv4/ip_tables.h>
14506 +#include <linux/netfilter_ipv4/ipt_psd.h>
14509 +#define DEBUGP printk
14511 +#define DEBUGP(format, args...)
14514 +MODULE_LICENSE("GPL");
14515 +MODULE_AUTHOR("Dennis Koslowski <koslowski@astaro.com>");
14517 +#define HF_DADDR_CHANGING 0x01
14518 +#define HF_SPORT_CHANGING 0x02
14519 +#define HF_TOS_CHANGING 0x04
14520 +#define HF_TTL_CHANGING 0x08
14523 + * Information we keep per each target port
14526 + u_int16_t number; /* port number */
14527 + u_int8_t proto; /* protocol number */
14528 + u_int8_t and_flags; /* tcp ANDed flags */
14529 + u_int8_t or_flags; /* tcp ORed flags */
14533 + * Information we keep per each source address.
14536 + struct host *next; /* Next entry with the same hash */
14537 + clock_t timestamp; /* Last update time */
14538 + struct in_addr src_addr; /* Source address */
14539 + struct in_addr dest_addr; /* Destination address */
14540 + unsigned short src_port; /* Source port */
14541 + int count; /* Number of ports in the list */
14542 + int weight; /* Total weight of ports in the list */
14543 + struct port ports[SCAN_MAX_COUNT - 1]; /* List of ports */
14544 + unsigned char tos; /* TOS */
14545 + unsigned char ttl; /* TTL */
14546 + unsigned char flags; /* HF_ flags bitmask */
14550 + * State information.
14554 + struct host list[LIST_SIZE]; /* List of source addresses */
14555 + struct host *hash[HASH_SIZE]; /* Hash: pointers into the list */
14556 + int index; /* Oldest entry to be replaced */
14560 + * Convert an IP address into a hash table index.
14562 +static inline int hashfunc(struct in_addr addr)
14564 + unsigned int value;
14567 + value = addr.s_addr;
14571 + } while ((value >>= HASH_LOG));
14573 + return hash & (HASH_SIZE - 1);
14577 +ipt_psd_match(const struct sk_buff *pskb,
14578 + const struct net_device *in,
14579 + const struct net_device *out,
14580 + const void *matchinfo,
14584 + struct iphdr *ip_hdr;
14585 + struct tcphdr *tcp_hdr;
14586 + struct in_addr addr;
14587 + u_int16_t src_port,dest_port;
14588 + u_int8_t tcp_flags, proto;
14590 + struct host *curr, *last, **head;
14591 + int hash, index, count;
14593 + /* Parameters from userspace */
14594 + const struct ipt_psd_info *psdinfo = matchinfo;
14597 + ip_hdr = pskb->nh.iph;
14599 + /* Sanity check */
14600 + if (ntohs(ip_hdr->frag_off) & IP_OFFSET) {
14601 + DEBUGP("PSD: sanity check failed\n");
14605 + /* TCP or UDP ? */
14606 + proto = ip_hdr->protocol;
14608 + if (proto != IPPROTO_TCP && proto != IPPROTO_UDP) {
14609 + DEBUGP("PSD: protocol not supported\n");
14613 + /* Get the source address, source & destination ports, and TCP flags */
14615 + addr.s_addr = ip_hdr->saddr;
14617 + tcp_hdr = (struct tcphdr*)((u_int32_t *)ip_hdr + ip_hdr->ihl);
14619 + /* Yep, it´s dirty */
14620 + src_port = tcp_hdr->source;
14621 + dest_port = tcp_hdr->dest;
14623 + if (proto == IPPROTO_TCP) {
14624 + tcp_flags = *((u_int8_t*)tcp_hdr + 13);
14627 + tcp_flags = 0x00;
14630 + /* We're using IP address 0.0.0.0 for a special purpose here, so don't let
14631 + * them spoof us. [DHCP needs this feature - HW] */
14632 + if (!addr.s_addr) {
14633 + DEBUGP("PSD: spoofed source address (0.0.0.0)\n");
14637 + /* Use jiffies here not to depend on someone setting the time while we're
14638 + * running; we need to be careful with possible return value overflows. */
14641 + spin_lock(&state.lock);
14643 + /* Do we know this source address already? */
14646 + if ((curr = *(head = &state.hash[hash = hashfunc(addr)])))
14648 + if (curr->src_addr.s_addr == addr.s_addr) break;
14650 + if (curr->next) last = curr;
14651 + } while ((curr = curr->next));
14655 + /* We know this address, and the entry isn't too old. Update it. */
14656 + if (now - curr->timestamp <= (psdinfo->delay_threshold*HZ)/100 &&
14657 + time_after_eq(now, curr->timestamp)) {
14659 + /* Just update the appropriate list entry if we've seen this port already */
14660 + for (index = 0; index < curr->count; index++) {
14661 + if (curr->ports[index].number == dest_port) {
14662 + curr->ports[index].proto = proto;
14663 + curr->ports[index].and_flags &= tcp_flags;
14664 + curr->ports[index].or_flags |= tcp_flags;
14665 + goto out_no_match;
14669 + /* TCP/ACK and/or TCP/RST to a new port? This could be an outgoing connection. */
14670 + if (proto == IPPROTO_TCP && (tcp_hdr->ack || tcp_hdr->rst))
14671 + goto out_no_match;
14673 + /* Packet to a new port, and not TCP/ACK: update the timestamp */
14674 + curr->timestamp = now;
14676 + /* Logged this scan already? Then drop the packet. */
14677 + if (curr->weight >= psdinfo->weight_threshold)
14680 + /* Specify if destination address, source port, TOS or TTL are not fixed */
14681 + if (curr->dest_addr.s_addr != ip_hdr->daddr)
14682 + curr->flags |= HF_DADDR_CHANGING;
14683 + if (curr->src_port != src_port)
14684 + curr->flags |= HF_SPORT_CHANGING;
14685 + if (curr->tos != ip_hdr->tos)
14686 + curr->flags |= HF_TOS_CHANGING;
14687 + if (curr->ttl != ip_hdr->ttl)
14688 + curr->flags |= HF_TTL_CHANGING;
14690 + /* Update the total weight */
14691 + curr->weight += (ntohs(dest_port) < 1024) ?
14692 + psdinfo->lo_ports_weight : psdinfo->hi_ports_weight;
14694 + /* Got enough destination ports to decide that this is a scan? */
14695 + /* Then log it and drop the packet. */
14696 + if (curr->weight >= psdinfo->weight_threshold)
14699 + /* Remember the new port */
14700 + if (curr->count < SCAN_MAX_COUNT) {
14701 + curr->ports[curr->count].number = dest_port;
14702 + curr->ports[curr->count].proto = proto;
14703 + curr->ports[curr->count].and_flags = tcp_flags;
14704 + curr->ports[curr->count].or_flags = tcp_flags;
14708 + goto out_no_match;
14711 + /* We know this address, but the entry is outdated. Mark it unused, and
14712 + * remove from the hash table. We'll allocate a new entry instead since
14713 + * this one might get re-used too soon. */
14714 + curr->src_addr.s_addr = 0;
14716 + last->next = last->next->next;
14718 + *head = (*head)->next;
14722 + /* We don't need an ACK from a new source address */
14723 + if (proto == IPPROTO_TCP && tcp_hdr->ack)
14724 + goto out_no_match;
14726 + /* Got too many source addresses with the same hash value? Then remove the
14727 + * oldest one from the hash table, so that they can't take too much of our
14728 + * CPU time even with carefully chosen spoofed IP addresses. */
14729 + if (count >= HASH_MAX && last) last->next = NULL;
14731 + /* We're going to re-use the oldest list entry, so remove it from the hash
14732 + * table first (if it is really already in use, and isn't removed from the
14733 + * hash table already because of the HASH_MAX check above). */
14735 + /* First, find it */
14736 + if (state.list[state.index].src_addr.s_addr)
14737 + head = &state.hash[hashfunc(state.list[state.index].src_addr)];
14741 + if ((curr = *head))
14743 + if (curr == &state.list[state.index]) break;
14745 + } while ((curr = curr->next));
14747 + /* Then, remove it */
14750 + last->next = last->next->next;
14752 + *head = (*head)->next;
14755 + /* Get our list entry */
14756 + curr = &state.list[state.index++];
14757 + if (state.index >= LIST_SIZE) state.index = 0;
14759 + /* Link it into the hash table */
14760 + head = &state.hash[hash];
14761 + curr->next = *head;
14764 + /* And fill in the fields */
14765 + curr->timestamp = now;
14766 + curr->src_addr = addr;
14767 + curr->dest_addr.s_addr = ip_hdr->daddr;
14768 + curr->src_port = src_port;
14770 + curr->weight = (ntohs(dest_port) < 1024) ?
14771 + psdinfo->lo_ports_weight : psdinfo->hi_ports_weight;
14772 + curr->ports[0].number = dest_port;
14773 + curr->ports[0].proto = proto;
14774 + curr->ports[0].and_flags = tcp_flags;
14775 + curr->ports[0].or_flags = tcp_flags;
14776 + curr->tos = ip_hdr->tos;
14777 + curr->ttl = ip_hdr->ttl;
14780 + spin_unlock(&state.lock);
14784 + spin_unlock(&state.lock);
14788 +static int ipt_psd_checkentry(const char *tablename,
14789 + const struct ipt_ip *e,
14791 + unsigned int matchsize,
14792 + unsigned int hook_mask)
14794 +/* const struct ipt_psd_info *psdinfo = targinfo;*/
14796 + /* we accept TCP only */
14797 +/* if (e->ip.proto != IPPROTO_TCP) { */
14798 +/* DEBUGP("PSD: specified protocol may be TCP only\n"); */
14802 + if (matchsize != IPT_ALIGN(sizeof(struct ipt_psd_info))) {
14803 + DEBUGP("PSD: matchsize %u != %u\n",
14805 + IPT_ALIGN(sizeof(struct ipt_psd_info)));
14812 +static struct ipt_match ipt_psd_reg = {
14814 + .match = ipt_psd_match,
14815 + .checkentry = ipt_psd_checkentry,
14816 + .me = THIS_MODULE };
14818 +static int __init init(void)
14820 + if (ipt_register_match(&ipt_psd_reg))
14823 + memset(&state, 0, sizeof(state));
14825 + spin_lock_init(&(state.lock));
14827 + printk("netfilter PSD loaded - (c) astaro AG\n");
14831 +static void __exit fini(void)
14833 + ipt_unregister_match(&ipt_psd_reg);
14834 + printk("netfilter PSD unloaded - (c) astaro AG\n");
14837 +module_init(init);
14838 +module_exit(fini);
14839 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_quota.c linux-2.6.6/net/ipv4/netfilter/ipt_quota.c
14840 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_quota.c 1970-01-01 01:00:00.000000000 +0100
14841 +++ linux-2.6.6/net/ipv4/netfilter/ipt_quota.c 2004-05-18 14:28:50.000000000 +0200
14844 + * netfilter module to enforce network quotas
14846 + * Sam Johnston <samj@samj.net>
14848 +#include <linux/module.h>
14849 +#include <linux/skbuff.h>
14850 +#include <linux/spinlock.h>
14851 +#include <linux/interrupt.h>
14853 +#include <linux/netfilter_ipv4/ip_tables.h>
14854 +#include <linux/netfilter_ipv4/ipt_quota.h>
14856 +MODULE_LICENSE("GPL");
14857 +MODULE_AUTHOR("Sam Johnston <samj@samj.net>");
14859 +static spinlock_t quota_lock = SPIN_LOCK_UNLOCKED;
14862 +match(const struct sk_buff *skb,
14863 + const struct net_device *in,
14864 + const struct net_device *out,
14865 + const void *matchinfo,
14866 + int offset, int *hotdrop)
14868 + struct ipt_quota_info *q = (struct ipt_quota_info *) matchinfo;
14869 + unsigned int datalen;
14871 + if (skb->len < sizeof(struct iphdr))
14872 + return NF_ACCEPT;
14874 + datalen = skb->len - skb->nh.iph->ihl*4;
14876 + spin_lock_bh("a_lock);
14878 + if (q->quota >= datalen) {
14879 + /* we can afford this one */
14880 + q->quota -= datalen;
14881 + spin_unlock_bh("a_lock);
14883 +#ifdef DEBUG_IPT_QUOTA
14884 + printk("IPT Quota OK: %llu datlen %d \n", q->quota, datalen);
14889 + /* so we do not allow even small packets from now on */
14892 +#ifdef DEBUG_IPT_QUOTA
14893 + printk("IPT Quota Failed: %llu datlen %d \n", q->quota, datalen);
14896 + spin_unlock_bh("a_lock);
14901 +checkentry(const char *tablename,
14902 + const struct ipt_ip *ip,
14903 + void *matchinfo, unsigned int matchsize, unsigned int hook_mask)
14905 + /* TODO: spinlocks? sanity checks? */
14906 + if (matchsize != IPT_ALIGN(sizeof (struct ipt_quota_info)))
14912 +static struct ipt_match quota_match = {
14915 + .checkentry = checkentry,
14916 + .me = THIS_MODULE
14922 + return ipt_register_match("a_match);
14925 +static void __exit
14928 + ipt_unregister_match("a_match);
14931 +module_init(init);
14932 +module_exit(fini);
14934 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_random.c linux-2.6.6/net/ipv4/netfilter/ipt_random.c
14935 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_random.c 1970-01-01 01:00:00.000000000 +0100
14936 +++ linux-2.6.6/net/ipv4/netfilter/ipt_random.c 2004-05-18 14:28:50.000000000 +0200
14939 + This is a module which is used for a "random" match support.
14940 + This file is distributed under the terms of the GNU General Public
14941 + License (GPL). Copies of the GPL can be obtained from:
14942 + ftp://prep.ai.mit.edu/pub/gnu/GPL
14944 + 2001-10-14 Fabrice MARIE <fabrice@netfilter.org> : initial implementation.
14947 +#include <linux/module.h>
14948 +#include <linux/skbuff.h>
14949 +#include <linux/ip.h>
14950 +#include <linux/random.h>
14951 +#include <net/tcp.h>
14952 +#include <linux/spinlock.h>
14953 +#include <linux/netfilter_ipv4/ip_tables.h>
14954 +#include <linux/netfilter_ipv4/ipt_random.h>
14956 +MODULE_LICENSE("GPL");
14959 +ipt_rand_match(const struct sk_buff *pskb,
14960 + const struct net_device *in,
14961 + const struct net_device *out,
14962 + const void *matchinfo,
14965 + u_int16_t datalen,
14968 + /* Parameters from userspace */
14969 + const struct ipt_rand_info *info = matchinfo;
14970 + u_int8_t random_number;
14972 + /* get 1 random number from the kernel random number generation routine */
14973 + get_random_bytes((void *)(&random_number), 1);
14975 + /* Do we match ? */
14976 + if (random_number <= info->average)
14983 +ipt_rand_checkentry(const char *tablename,
14984 + const struct ipt_ip *e,
14986 + unsigned int matchsize,
14987 + unsigned int hook_mask)
14989 + /* Parameters from userspace */
14990 + const struct ipt_rand_info *info = matchinfo;
14992 + if (matchsize != IPT_ALIGN(sizeof(struct ipt_rand_info))) {
14993 + printk("ipt_random: matchsize %u != %u\n", matchsize,
14994 + IPT_ALIGN(sizeof(struct ipt_rand_info)));
14998 + /* must be 1 <= average % <= 99 */
14999 + /* 1 x 2.55 = 2 */
15000 + /* 99 x 2.55 = 252 */
15001 + if ((info->average < 2) || (info->average > 252)) {
15002 + printk("ipt_random: invalid average %u\n", info->average);
15009 +static struct ipt_match ipt_rand_reg = {
15013 + ipt_rand_checkentry,
15017 +static int __init init(void)
15019 + if (ipt_register_match(&ipt_rand_reg))
15022 + printk("ipt_random match loaded\n");
15026 +static void __exit fini(void)
15028 + ipt_unregister_match(&ipt_rand_reg);
15029 + printk("ipt_random match unloaded\n");
15032 +module_init(init);
15033 +module_exit(fini);
15034 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_realm.c linux-2.6.6/net/ipv4/netfilter/ipt_realm.c
15035 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_realm.c 1970-01-01 01:00:00.000000000 +0100
15036 +++ linux-2.6.6/net/ipv4/netfilter/ipt_realm.c 2004-05-18 14:28:50.000000000 +0200
15038 +/* IP tables module for matching the routing realm
15042 + * (C) 2003 by Sampsa Ranta <sampsa@netsonic.fi>
15044 + * This program is free software; you can redistribute it and/or modify
15045 + * it under the terms of the GNU General Public License version 2 as
15046 + * published by the Free Software Foundation.
15049 +#include <linux/module.h>
15050 +#include <linux/skbuff.h>
15051 +#include <linux/netdevice.h>
15052 +#include <net/route.h>
15054 +#include <linux/netfilter_ipv4/ipt_realm.h>
15055 +#include <linux/netfilter_ipv4/ip_tables.h>
15057 +MODULE_AUTHOR("Sampsa Ranta <sampsa@netsonic.fi>");
15058 +MODULE_LICENSE("GPL");
15061 +match(const struct sk_buff *skb,
15062 + const struct net_device *in,
15063 + const struct net_device *out,
15064 + const void *matchinfo,
15068 + const struct ipt_realm_info *info = matchinfo;
15069 + struct dst_entry *dst = skb->dst;
15074 + return (info->id == (dst->tclassid & info->mask)) ^ info->invert;
15077 +static int check(const char *tablename,
15078 + const struct ipt_ip *ip,
15080 + unsigned int matchsize,
15081 + unsigned int hook_mask)
15084 + & ~((1 << NF_IP_POST_ROUTING) | (1 << NF_IP_FORWARD) |
15085 + (1 << NF_IP_LOCAL_OUT)| (1 << NF_IP_LOCAL_IN))) {
15086 + printk("ipt_realm: only valid for POST_ROUTING, LOCAL_OUT, "
15087 + "LOCAL_IN or FORWARD.\n");
15091 + if (matchsize != IPT_ALIGN(sizeof(struct ipt_realm_info)))
15097 +static struct ipt_match realm_match = {
15100 + .checkentry = check,
15101 + .me = THIS_MODULE
15104 +static int __init init(void)
15106 + return ipt_register_match(&realm_match);
15109 +static void __exit fini(void)
15111 + ipt_unregister_match(&realm_match);
15114 +module_init(init);
15115 +module_exit(fini);
15116 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_sctp.c linux-2.6.6/net/ipv4/netfilter/ipt_sctp.c
15117 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_sctp.c 1970-01-01 01:00:00.000000000 +0100
15118 +++ linux-2.6.6/net/ipv4/netfilter/ipt_sctp.c 2004-05-18 14:28:50.000000000 +0200
15120 +#include <linux/module.h>
15121 +#include <linux/skbuff.h>
15122 +#include <net/ip.h>
15123 +#include <linux/sctp.h>
15125 +#include <linux/netfilter_ipv4/ip_tables.h>
15126 +#include <linux/netfilter_ipv4/ipt_sctp.h>
15129 +#define duprintf(format, args...) printk(format , ## args)
15131 +#define duprintf(format, args...)
15134 +#define SCCHECK(cond, option, flag, invflag) (!((flag) & (option)) \
15135 + || (!!((invflag) & (option)) ^ (cond)))
15138 +match_flags(const struct ipt_sctp_flag_info *flag_info,
15139 + const int flag_count,
15140 + u_int8_t chunktype,
15141 + u_int8_t chunkflags)
15145 + for (i = 0; i < flag_count; i++) {
15146 + if (flag_info[i].chunktype == chunktype) {
15147 + return (chunkflags & flag_info[i].flag_mask) == flag_info[i].flag;
15155 +match_packet(const struct sk_buff *skb,
15156 + const u_int32_t *chunkmap,
15157 + int chunk_match_type,
15158 + const struct ipt_sctp_flag_info *flag_info,
15159 + const int flag_count,
15163 + u_int32_t chunkmapcopy[256 / sizeof (u_int32_t)];
15164 + sctp_chunkhdr_t sch;
15168 + if (chunk_match_type == SCTP_CHUNK_MATCH_ALL) {
15169 + SCTP_CHUNKMAP_COPY(chunkmapcopy, chunkmap);
15172 + offset = skb->nh.iph->ihl * 4 + sizeof (sctp_sctphdr_t);
15174 + if (skb_copy_bits(skb, offset, &sch, sizeof(sch)) < 0) {
15175 + duprintf("Dropping invalid SCTP packet.\n");
15180 + duprintf("Chunk num: %d\toffset: %d\ttype: %d\tlength: %d\tflags: %x\n",
15181 + ++i, offset, sch.type, htons(sch.length), sch.flags);
15183 + offset += (htons(sch.length) + 3) & ~3;
15185 + duprintf("skb->len: %d\toffset: %d\n", skb->len, offset);
15187 + if (SCTP_CHUNKMAP_IS_SET(chunkmap, sch.type)) {
15188 + switch (chunk_match_type) {
15189 + case SCTP_CHUNK_MATCH_ANY:
15190 + if (match_flags(flag_info, flag_count,
15191 + sch.type, sch.flags)) {
15196 + case SCTP_CHUNK_MATCH_ALL:
15197 + if (match_flags(flag_info, flag_count,
15198 + sch.type, sch.flags)) {
15199 + SCTP_CHUNKMAP_CLEAR(chunkmapcopy, sch.type);
15203 + case SCTP_CHUNK_MATCH_ONLY:
15204 + if (!match_flags(flag_info, flag_count,
15205 + sch.type, sch.flags)) {
15211 + switch (chunk_match_type) {
15212 + case SCTP_CHUNK_MATCH_ONLY:
15216 + } while (offset < skb->len);
15218 + switch (chunk_match_type) {
15219 + case SCTP_CHUNK_MATCH_ALL:
15220 + return SCTP_CHUNKMAP_IS_CLEAR(chunkmap);
15221 + case SCTP_CHUNK_MATCH_ANY:
15223 + case SCTP_CHUNK_MATCH_ONLY:
15227 + /* This will never be reached, but required to stop compiler whine */
15232 +match(const struct sk_buff *skb,
15233 + const struct net_device *in,
15234 + const struct net_device *out,
15235 + const void *matchinfo,
15239 + const struct ipt_sctp_info *info;
15240 + sctp_sctphdr_t sh;
15242 + info = (const struct ipt_sctp_info *)matchinfo;
15245 + duprintf("Dropping non-first fragment.. FIXME\n");
15249 + if (skb_copy_bits(skb, skb->nh.iph->ihl*4, &sh, sizeof(sh)) < 0) {
15250 + duprintf("Dropping evil TCP offset=0 tinygram.\n");
15254 + duprintf("spt: %d\tdpt: %d\n", ntohs(sh.source), ntohs(sh.dest));
15256 + return SCCHECK(((ntohs(sh.source) >= info->spts[0])
15257 + && (ntohs(sh.source) <= info->spts[1])),
15258 + IPT_SCTP_SRC_PORTS, info->flags, info->invflags)
15259 + && SCCHECK(((ntohs(sh.dest) >= info->dpts[0])
15260 + && (ntohs(sh.dest) <= info->dpts[1])),
15261 + IPT_SCTP_DEST_PORTS, info->flags, info->invflags)
15262 + && SCCHECK(match_packet(skb, info->chunkmap, info->chunk_match_type,
15263 + info->flag_info, info->flag_count,
15265 + IPT_SCTP_CHUNK_TYPES, info->flags, info->invflags);
15269 +checkentry(const char *tablename,
15270 + const struct ipt_ip *ip,
15272 + unsigned int matchsize,
15273 + unsigned int hook_mask)
15275 + const struct ipt_sctp_info *info;
15277 + info = (const struct ipt_sctp_info *)matchinfo;
15279 + return ip->proto == IPPROTO_SCTP
15280 + && !(ip->invflags & IPT_INV_PROTO)
15281 + && matchsize == IPT_ALIGN(sizeof(struct ipt_sctp_info))
15282 + && !(info->flags & ~IPT_SCTP_VALID_FLAGS)
15283 + && !(info->invflags & ~IPT_SCTP_VALID_FLAGS)
15284 + && !(info->invflags & ~info->flags)
15285 + && ((!(info->flags & IPT_SCTP_CHUNK_TYPES)) ||
15286 + (info->chunk_match_type &
15287 + (SCTP_CHUNK_MATCH_ALL
15288 + | SCTP_CHUNK_MATCH_ANY
15289 + | SCTP_CHUNK_MATCH_ONLY)));
15292 +static struct ipt_match sctp_match =
15294 + .list = { NULL, NULL},
15297 + .checkentry = &checkentry,
15299 + .me = THIS_MODULE
15302 +static int __init init(void)
15304 + return ipt_register_match(&sctp_match);
15307 +static void __exit fini(void)
15309 + ipt_unregister_match(&sctp_match);
15312 +module_init(init);
15313 +module_exit(fini);
15315 +MODULE_LICENSE("GPL");
15316 +MODULE_AUTHOR("Kiran Kumar Immidi");
15317 +MODULE_DESCRIPTION("Match for SCTP protocol packets");
15319 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_string.c linux-2.6.6/net/ipv4/netfilter/ipt_string.c
15320 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_string.c 1970-01-01 01:00:00.000000000 +0100
15321 +++ linux-2.6.6/net/ipv4/netfilter/ipt_string.c 2004-05-18 14:28:58.000000000 +0200
15323 +/* Kernel module to match a string into a packet.
15325 + * Copyright (C) 2000 Emmanuel Roger <winfield@freegates.be>
15328 + * 24.03.2004: Eric Lauriault <elauri@lacitec.on.ca>
15329 + * Initial 2.6 port
15330 + * 19.02.2002: Gianni Tedesco <gianni@ecsc.co.uk>
15331 + * Fixed SMP re-entrancy problem using per-cpu data areas
15332 + * for the skip/shift tables.
15333 + * 02.05.2001: Gianni Tedesco <gianni@ecsc.co.uk>
15334 + * Fixed kernel panic, due to overrunning boyer moore string
15335 + * tables. Also slightly tweaked heuristic for deciding what
15336 + * search algo to use.
15337 + * 27.01.2001: Gianni Tedesco <gianni@ecsc.co.uk>
15338 + * Implemented Boyer Moore Sublinear search algorithm
15339 + * alongside the existing linear search based on memcmp().
15340 + * Also a quick check to decide which method to use on a per
15344 +#include <linux/smp.h>
15345 +#include <linux/percpu.h>
15346 +#include <linux/module.h>
15347 +#include <linux/skbuff.h>
15348 +#include <linux/file.h>
15349 +#include <net/sock.h>
15351 +#include <linux/netfilter_ipv4/ip_tables.h>
15352 +#include <linux/netfilter_ipv4/ipt_string.h>
15354 +MODULE_LICENSE("GPL");
15356 +struct string_per_cpu {
15357 + int skip[BM_MAX_HLEN];
15358 + int shift[BM_MAX_HLEN];
15359 + int len[BM_MAX_HLEN];
15362 +static DEFINE_PER_CPU(struct string_per_cpu, bm_string_data);
15365 +/* Boyer Moore Sublinear string search - VERY FAST */
15366 +char *search_sublinear (char *needle, char *haystack, int needle_len, int haystack_len)
15368 + int M1, right_end, sk, sh;
15371 + int *skip, *shift, *len;
15373 + /* use data suitable for this CPU */
15374 + shift=__get_cpu_var(bm_string_data).shift;
15375 + skip=__get_cpu_var(bm_string_data).skip;
15376 + len=__get_cpu_var(bm_string_data).len;
15378 + /* Setup skip/shift tables */
15379 + M1 = right_end = needle_len-1;
15380 + for (i = 0; i < BM_MAX_HLEN; i++) skip[i] = needle_len;
15381 + for (i = 0; needle[i]; i++) skip[(int)needle[i]] = M1 - i;
15383 + for (i = 1; i < needle_len; i++) {
15384 + for (j = 0; j < needle_len && needle[M1 - j] == needle[M1 - i - j]; j++);
15389 + for (i = 1; i < needle_len; i++) shift[i] = needle_len;
15390 + for (i = M1; i > 0; i--) shift[len[i]] = i;
15393 + for (i = 0; i < needle_len; i++) {
15394 + if (len[i] == M1 - i) ended = i;
15395 + if (ended) shift[i] = ended;
15398 + /* Do the search*/
15399 + while (right_end < haystack_len)
15401 + for (i = 0; i < needle_len && haystack[right_end - i] == needle[M1 - i]; i++);
15402 + if (i == needle_len) {
15403 + return haystack+(right_end - M1);
15406 + sk = skip[(int)haystack[right_end - i]];
15408 + right_end = max(right_end - i + sk, right_end + sh);
15414 +/* Linear string search based on memcmp() */
15415 +char *search_linear (char *needle, char *haystack, int needle_len, int haystack_len)
15417 + char *k = haystack + (haystack_len-needle_len);
15418 + char *t = haystack;
15420 + while ( t <= k ) {
15421 + if (memcmp(t, needle, needle_len) == 0)
15430 +match(const struct sk_buff *skb,
15431 + const struct net_device *in,
15432 + const struct net_device *out,
15433 + const void *matchinfo,
15437 + const struct ipt_string_info *info = matchinfo;
15438 + struct iphdr *ip = skb->nh.iph;
15440 + char *needle, *haystack;
15441 + proc_ipt_search search=search_linear;
15443 + if ( !ip ) return 0;
15445 + /* get lenghts, and validate them */
15447 + hlen=ntohs(ip->tot_len)-(ip->ihl*4);
15448 + if ( nlen > hlen ) return 0;
15450 + needle=(char *)&info->string;
15451 + haystack=(char *)ip+(ip->ihl*4);
15453 + /* The sublinear search comes in to its own
15454 + * on the larger packets */
15455 + if ( (hlen>IPT_STRING_HAYSTACK_THRESH) &&
15456 + (nlen>IPT_STRING_NEEDLE_THRESH) ) {
15457 + if ( hlen < BM_MAX_HLEN ) {
15458 + search=search_sublinear;
15460 + if (net_ratelimit())
15461 + printk(KERN_INFO "ipt_string: Packet too big "
15462 + "to attempt sublinear string search "
15463 + "(%d bytes)\n", hlen );
15467 + return ((search(needle, haystack, nlen, hlen)!=NULL) ^ info->invert);
15471 +checkentry(const char *tablename,
15472 + const struct ipt_ip *ip,
15474 + unsigned int matchsize,
15475 + unsigned int hook_mask)
15478 + if (matchsize != IPT_ALIGN(sizeof(struct ipt_string_info)))
15484 +static struct ipt_match string_match = {
15485 + .name = "string",
15487 + .checkentry = &checkentry,
15488 + .me = THIS_MODULE
15492 +static int __init init(void)
15494 + return ipt_register_match(&string_match);
15497 +static void __exit fini(void)
15499 + ipt_unregister_match(&string_match);
15502 +module_init(init);
15503 +module_exit(fini);
15506 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_time.c linux-2.6.6/net/ipv4/netfilter/ipt_time.c
15507 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_time.c 1970-01-01 01:00:00.000000000 +0100
15508 +++ linux-2.6.6/net/ipv4/netfilter/ipt_time.c 2004-05-18 14:28:50.000000000 +0200
15511 + This is a module which is used for time matching
15512 + It is using some modified code from dietlibc (localtime() function)
15513 + that you can find at http://www.fefe.de/dietlibc/
15514 + This file is distributed under the terms of the GNU General Public
15515 + License (GPL). Copies of the GPL can be obtained from: ftp://prep.ai.mit.edu/pub/gnu/GPL
15516 + 2001-05-04 Fabrice MARIE <fabrice@netfilter.org> : initial development.
15517 + 2001-21-05 Fabrice MARIE <fabrice@netfilter.org> : bug fix in the match code,
15518 + thanks to "Zeng Yu" <zengy@capitel.com.cn> for bug report.
15519 + 2001-26-09 Fabrice MARIE <fabrice@netfilter.org> : force the match to be in LOCAL_IN or PRE_ROUTING only.
15520 + 2001-30-11 Fabrice : added the possibility to use the match in FORWARD/OUTPUT with a little hack,
15521 + added Nguyen Dang Phuoc Dong <dongnd@tlnet.com.vn> patch to support timezones.
15522 + 2004-05-02 Fabrice : added support for date matching, from an idea of Fabien COELHO.
15525 +#include <linux/module.h>
15526 +#include <linux/skbuff.h>
15527 +#include <linux/netfilter_ipv4/ip_tables.h>
15528 +#include <linux/netfilter_ipv4/ipt_time.h>
15529 +#include <linux/time.h>
15531 +MODULE_AUTHOR("Fabrice MARIE <fabrice@netfilter.org>");
15532 +MODULE_DESCRIPTION("Match arrival timestamp/date");
15533 +MODULE_LICENSE("GPL");
15537 + int tm_sec; /* Seconds. [0-60] (1 leap second) */
15538 + int tm_min; /* Minutes. [0-59] */
15539 + int tm_hour; /* Hours. [0-23] */
15540 + int tm_mday; /* Day. [1-31] */
15541 + int tm_mon; /* Month. [0-11] */
15542 + int tm_year; /* Year - 1900. */
15543 + int tm_wday; /* Day of week. [0-6] */
15544 + int tm_yday; /* Days in year.[0-365] */
15545 + int tm_isdst; /* DST. [-1/0/1]*/
15547 + long int tm_gmtoff; /* we don't care, we count from GMT */
15548 + const char *tm_zone; /* we don't care, we count from GMT */
15552 +localtime(const time_t *timepr, struct tm *r);
15555 +match(const struct sk_buff *skb,
15556 + const struct net_device *in,
15557 + const struct net_device *out,
15558 + const void *matchinfo,
15561 + u_int16_t datalen,
15564 + const struct ipt_time_info *info = matchinfo; /* match info for rule */
15565 + struct tm currenttime; /* time human readable */
15566 + u_int8_t days_of_week[7] = {64, 32, 16, 8, 4, 2, 1};
15567 + u_int16_t packet_time;
15568 + struct timeval kerneltimeval;
15569 + time_t packet_local_time;
15571 + /* if kerneltime=1, we don't read the skb->timestamp but kernel time instead */
15572 + if (info->kerneltime)
15574 + do_gettimeofday(&kerneltimeval);
15575 + packet_local_time = kerneltimeval.tv_sec;
15578 + packet_local_time = skb->stamp.tv_sec;
15580 + /* First we make sure we are in the date start-stop boundaries */
15581 + if ((packet_local_time < info->date_start) || (packet_local_time > info->date_stop))
15582 + return 0; /* We are outside the date boundaries */
15584 + /* Transform the timestamp of the packet, in a human readable form */
15585 + localtime(&packet_local_time, ¤ttime);
15587 + /* check if we match this timestamp, we start by the days... */
15588 + if ((days_of_week[currenttime.tm_wday] & info->days_match) != days_of_week[currenttime.tm_wday])
15589 + return 0; /* the day doesn't match */
15591 + /* ... check the time now */
15592 + packet_time = (currenttime.tm_hour * 60) + currenttime.tm_min;
15593 + if ((packet_time < info->time_start) || (packet_time > info->time_stop))
15596 + /* here we match ! */
15601 +checkentry(const char *tablename,
15602 + const struct ipt_ip *ip,
15604 + unsigned int matchsize,
15605 + unsigned int hook_mask)
15607 + struct ipt_time_info *info = matchinfo; /* match info for rule */
15609 + /* First, check that we are in the correct hooks */
15611 + & ~((1 << NF_IP_PRE_ROUTING) | (1 << NF_IP_LOCAL_IN) | (1 << NF_IP_FORWARD) | (1 << NF_IP_LOCAL_OUT)))
15613 + printk("ipt_time: error, only valid for PRE_ROUTING, LOCAL_IN, FORWARD and OUTPUT)\n");
15616 + /* we use the kerneltime if we are in forward or output */
15617 + info->kerneltime = 1;
15618 + if (hook_mask & ~((1 << NF_IP_FORWARD) | (1 << NF_IP_LOCAL_OUT)))
15619 + /* we use the skb time */
15620 + info->kerneltime = 0;
15622 + /* Check the size */
15623 + if (matchsize != IPT_ALIGN(sizeof(struct ipt_time_info)))
15625 + /* Now check the coherence of the data ... */
15626 + if ((info->time_start > 1439) || /* 23*60+59 = 1439*/
15627 + (info->time_stop > 1439))
15629 + printk(KERN_WARNING "ipt_time: invalid argument\n");
15636 +static struct ipt_match time_match
15637 += { { NULL, NULL }, "time", &match, &checkentry, NULL, THIS_MODULE };
15639 +static int __init init(void)
15641 + printk("ipt_time loading\n");
15642 + return ipt_register_match(&time_match);
15645 +static void __exit fini(void)
15647 + ipt_unregister_match(&time_match);
15648 + printk("ipt_time unloaded\n");
15651 +module_init(init);
15652 +module_exit(fini);
15655 +/* The part below is borowed and modified from dietlibc */
15657 +/* seconds per day */
15658 +#define SPD 24*60*60
15661 +localtime(const time_t *timepr, struct tm *r) {
15664 + extern struct timezone sys_tz;
15665 + const unsigned int __spm[12] =
15671 + (31+28+31+30+31),
15672 + (31+28+31+30+31+30),
15673 + (31+28+31+30+31+30+31),
15674 + (31+28+31+30+31+30+31+31),
15675 + (31+28+31+30+31+30+31+31+30),
15676 + (31+28+31+30+31+30+31+31+30+31),
15677 + (31+28+31+30+31+30+31+31+30+31+30),
15679 + register time_t work;
15681 + timep = (*timepr) - (sys_tz.tz_minuteswest * 60);
15682 + work=timep%(SPD);
15683 + r->tm_sec=work%60; work/=60;
15684 + r->tm_min=work%60; r->tm_hour=work/60;
15685 + work=timep/(SPD);
15686 + r->tm_wday=(4+work)%7;
15687 + for (i=1970; ; ++i) {
15688 + register time_t k= (!(i%4) && ((i%100) || !(i%400)))?366:365;
15694 + r->tm_year=i-1900;
15695 + for (i=11; i && __spm[i]>work; --i) ;
15697 + r->tm_mday=work-__spm[i]+1;
15699 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_u32.c linux-2.6.6/net/ipv4/netfilter/ipt_u32.c
15700 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_u32.c 1970-01-01 01:00:00.000000000 +0100
15701 +++ linux-2.6.6/net/ipv4/netfilter/ipt_u32.c 2004-05-18 14:28:50.000000000 +0200
15703 +/* Kernel module to match u32 packet content. */
15706 +U32 tests whether quantities of up to 4 bytes extracted from a packet
15707 +have specified values. The specification of what to extract is general
15708 +enough to find data at given offsets from tcp headers or payloads.
15711 + The argument amounts to a program in a small language described below.
15712 + tests := location = value | tests && location = value
15713 + value := range | value , range
15714 + range := number | number : number
15715 + a single number, n, is interpreted the same as n:n
15716 + n:m is interpreted as the range of numbers >=n and <=m
15717 + location := number | location operator number
15718 + operator := & | << | >> | @
15720 + The operators &, <<, >>, && mean the same as in c. The = is really a set
15721 + membership operator and the value syntax describes a set. The @ operator
15722 + is what allows moving to the next header and is described further below.
15724 + *** Until I can find out how to avoid it, there are some artificial limits
15725 + on the size of the tests:
15726 + - no more than 10 ='s (and 9 &&'s) in the u32 argument
15727 + - no more than 10 ranges (and 9 commas) per value
15728 + - no more than 10 numbers (and 9 operators) per location
15730 + To describe the meaning of location, imagine the following machine that
15731 + interprets it. There are three registers:
15732 + A is of type char*, initially the address of the IP header
15733 + B and C are unsigned 32 bit integers, initially zero
15735 + The instructions are:
15736 + number B = number;
15737 + C = (*(A+B)<<24)+(*(A+B+1)<<16)+(*(A+B+2)<<8)+*(A+B+3)
15738 + &number C = C&number
15739 + <<number C = C<<number
15740 + >>number C = C>>number
15741 + @number A = A+C; then do the instruction number
15742 + Any access of memory outside [skb->head,skb->end] causes the match to fail.
15743 + Otherwise the result of the computation is the final value of C.
15745 + Whitespace is allowed but not required in the tests.
15746 + However the characters that do occur there are likely to require
15747 + shell quoting, so it's a good idea to enclose the arguments in quotes.
15750 + match IP packets with total length >= 256
15751 + The IP header contains a total length field in bytes 2-3.
15752 + --u32 "0&0xFFFF=0x100:0xFFFF"
15754 + AND that with FFFF (giving bytes 2-3),
15755 + and test whether that's in the range [0x100:0xFFFF]
15757 +Example: (more realistic, hence more complicated)
15758 + match icmp packets with icmp type 0
15759 + First test that it's an icmp packet, true iff byte 9 (protocol) = 1
15760 + --u32 "6&0xFF=1 && ...
15761 + read bytes 6-9, use & to throw away bytes 6-8 and compare the result to 1
15762 + Next test that it's not a fragment.
15763 + (If so it might be part of such a packet but we can't always tell.)
15764 + n.b. This test is generally needed if you want to match anything
15765 + beyond the IP header.
15766 + The last 6 bits of byte 6 and all of byte 7 are 0 iff this is a complete
15767 + packet (not a fragment). Alternatively, you can allow first fragments
15768 + by only testing the last 5 bits of byte 6.
15769 + ... 4&0x3FFF=0 && ...
15770 + Last test: the first byte past the IP header (the type) is 0
15771 + This is where we have to use the @syntax. The length of the IP header
15772 + (IHL) in 32 bit words is stored in the right half of byte 0 of the
15773 + IP header itself.
15774 + ... 0>>22&0x3C@0>>24=0"
15775 + The first 0 means read bytes 0-3,
15776 + >>22 means shift that 22 bits to the right. Shifting 24 bits would give
15777 + the first byte, so only 22 bits is four times that plus a few more bits.
15778 + &3C then eliminates the two extra bits on the right and the first four
15779 + bits of the first byte.
15780 + For instance, if IHL=5 then the IP header is 20 (4 x 5) bytes long.
15781 + In this case bytes 0-1 are (in binary) xxxx0101 yyzzzzzz,
15782 + >>22 gives the 10 bit value xxxx0101yy and &3C gives 010100.
15783 + @ means to use this number as a new offset into the packet, and read
15784 + four bytes starting from there. This is the first 4 bytes of the icmp
15785 + payload, of which byte 0 is the icmp type. Therefore we simply shift
15786 + the value 24 to the right to throw out all but the first byte and compare
15787 + the result with 0.
15790 + tcp payload bytes 8-12 is any of 1, 2, 5 or 8
15791 + First we test that the packet is a tcp packet (similar to icmp).
15792 + --u32 "6&0xFF=6 && ...
15793 + Next, test that it's not a fragment (same as above).
15794 + ... 0>>22&0x3C@12>>26&0x3C@8=1,2,5,8"
15795 + 0>>22&3C as above computes the number of bytes in the IP header.
15796 + @ makes this the new offset into the packet, which is the start of the
15797 + tcp header. The length of the tcp header (again in 32 bit words) is
15798 + the left half of byte 12 of the tcp header. The 12>>26&3C
15799 + computes this length in bytes (similar to the IP header before).
15800 + @ makes this the new offset, which is the start of the tcp payload.
15801 + Finally 8 reads bytes 8-12 of the payload and = checks whether the
15802 + result is any of 1, 2, 5 or 8
15805 +#include <linux/module.h>
15806 +#include <linux/skbuff.h>
15808 +#include <linux/netfilter_ipv4/ipt_u32.h>
15809 +#include <linux/netfilter_ipv4/ip_tables.h>
15811 +/* #include <asm-i386/timex.h> for timing */
15813 +MODULE_AUTHOR("Don Cohen <don@isis.cs3-inc.com>");
15814 +MODULE_DESCRIPTION("IP tables u32 matching module");
15815 +MODULE_LICENSE("GPL");
15818 +match(const struct sk_buff *skb,
15819 + const struct net_device *in,
15820 + const struct net_device *out,
15821 + const void *matchinfo,
15824 + u_int16_t datalen,
15827 + const struct ipt_u32 *data = matchinfo;
15829 + unsigned char* origbase = (char*)skb->nh.iph;
15830 + unsigned char* base = origbase;
15831 + unsigned char* head = skb->head;
15832 + unsigned char* end = skb->end;
15833 + int nnums, nvals;
15834 + u_int32_t pos, val;
15835 + /* unsigned long long cycles1, cycles2, cycles3, cycles4;
15836 + cycles1 = get_cycles(); */
15838 + for (testind=0; testind < data->ntests; testind++) {
15839 + base = origbase; /* reset for each test */
15840 + pos = data->tests[testind].location[0].number;
15841 + if (base+pos+3 > end || base+pos < head)
15843 + val = (base[pos]<<24) + (base[pos+1]<<16) +
15844 + (base[pos+2]<<8) + base[pos+3];
15845 + nnums = data->tests[testind].nnums;
15846 + for (i=1; i < nnums; i++) {
15847 + u_int32_t number = data->tests[testind].location[i].number;
15848 + switch (data->tests[testind].location[i].nextop) {
15849 + case IPT_U32_AND:
15850 + val = val & number;
15852 + case IPT_U32_LEFTSH:
15853 + val = val << number;
15855 + case IPT_U32_RIGHTSH:
15856 + val = val >> number;
15859 + base = base + val;
15861 + if (base+pos+3 > end || base+pos < head)
15863 + val = (base[pos]<<24) + (base[pos+1]<<16) +
15864 + (base[pos+2]<<8) + base[pos+3];
15868 + nvals = data->tests[testind].nvalues;
15869 + for (i=0; i < nvals; i++) {
15870 + if ((data->tests[testind].value[i].min <= val) &&
15871 + (val <= data->tests[testind].value[i].max)) {
15875 + if (i >= data->tests[testind].nvalues) {
15876 + /* cycles2 = get_cycles();
15877 + printk("failed %d in %d cycles\n", testind,
15878 + cycles2-cycles1); */
15882 + /* cycles2 = get_cycles();
15883 + printk("succeeded in %d cycles\n", cycles2-cycles1); */
15888 +checkentry(const char *tablename,
15889 + const struct ipt_ip *ip,
15891 + unsigned int matchsize,
15892 + unsigned int hook_mask)
15894 + if (matchsize != IPT_ALIGN(sizeof(struct ipt_u32)))
15899 +static struct ipt_match u32_match
15900 += { { NULL, NULL }, "u32", &match, &checkentry, NULL, THIS_MODULE };
15902 +static int __init init(void)
15904 + return ipt_register_match(&u32_match);
15907 +static void __exit fini(void)
15909 + ipt_unregister_match(&u32_match);
15912 +module_init(init);
15913 +module_exit(fini);
15914 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/ipt_unclean.c linux-2.6.6/net/ipv4/netfilter/ipt_unclean.c
15915 --- linux-2.6.6.org/net/ipv4/netfilter/ipt_unclean.c 1970-01-01 01:00:00.000000000 +0100
15916 +++ linux-2.6.6/net/ipv4/netfilter/ipt_unclean.c 2004-05-18 14:28:50.000000000 +0200
15918 +/* Kernel module to match suspect packets. */
15919 +#include <linux/module.h>
15920 +#include <linux/skbuff.h>
15921 +#include <linux/ip.h>
15922 +#include <linux/udp.h>
15923 +#include <linux/tcp.h>
15924 +#include <linux/icmp.h>
15925 +#include <net/checksum.h>
15927 +#include <linux/netfilter_ipv4/ip_tables.h>
15929 +#define limpk(format, args...) \
15931 + if (net_ratelimit()) \
15932 + printk("ipt_unclean: %s" format, \
15933 + embedded ? "(embedded packet) " : "" , ## args); \
15936 +enum icmp_error_status
15938 + ICMP_MAY_BE_ERROR,
15945 + size_t min_len, max_len;
15946 + enum icmp_error_status err;
15947 + u_int8_t min_code, max_code;
15951 +check_ip(struct iphdr *iph, size_t length, int embedded);
15953 +/* ICMP-specific checks. */
15955 +check_icmp(const struct icmphdr *icmph,
15956 + u_int16_t datalen,
15957 + unsigned int offset,
15961 + static struct icmp_info info[]
15962 + = { [ICMP_ECHOREPLY]
15963 + = { 8, 65536, ICMP_NOT_ERROR, 0, 0 },
15964 + [ICMP_DEST_UNREACH]
15965 + = { 8 + 28, 65536, ICMP_IS_ERROR, 0, 15 },
15966 + [ICMP_SOURCE_QUENCH]
15967 + = { 8 + 28, 65536, ICMP_IS_ERROR, 0, 0 },
15969 + = { 8 + 28, 65536, ICMP_IS_ERROR, 0, 3 },
15971 + = { 8, 65536, ICMP_NOT_ERROR, 0, 0 },
15972 + /* Router advertisement. */
15974 + = { 8, 8 + 255 * 8, ICMP_NOT_ERROR, 0, 0 },
15975 + /* Router solicitation. */
15977 + = { 8, 8, ICMP_NOT_ERROR, 0, 0 },
15978 + [ICMP_TIME_EXCEEDED]
15979 + = { 8 + 28, 65536, ICMP_IS_ERROR, 0, 1 },
15980 + [ICMP_PARAMETERPROB]
15981 + = { 8 + 28, 65536, ICMP_IS_ERROR, 0, 1 },
15983 + = { 20, 20, ICMP_NOT_ERROR, 0, 0 },
15984 + [ICMP_TIMESTAMPREPLY]
15985 + = { 20, 20, ICMP_NOT_ERROR, 0, 0 },
15986 + [ICMP_INFO_REQUEST]
15987 + = { 8, 65536, ICMP_NOT_ERROR, 0, 0 },
15988 + [ICMP_INFO_REPLY]
15989 + = { 8, 65536, ICMP_NOT_ERROR, 0, 0 },
15991 + = { 12, 12, ICMP_NOT_ERROR, 0, 0 },
15992 + [ICMP_ADDRESSREPLY]
15993 + = { 12, 12, ICMP_NOT_ERROR, 0, 0 } };
15995 + /* Can't do anything if it's a fragment. */
15999 + /* Must cover type and code. */
16000 + if (datalen < 2) {
16001 + limpk("ICMP len=%u too short\n", datalen);
16005 + /* If not embedded. */
16007 + /* Bad checksum? Don't print, just ignore. */
16009 + && ip_compute_csum((unsigned char *) icmph, datalen) != 0)
16012 + /* CHECK: Truncated ICMP (even if first fragment). */
16013 + if (icmph->type < sizeof(info)/sizeof(struct icmp_info)
16014 + && info[icmph->type].min_len != 0
16015 + && datalen < info[icmph->type].min_len) {
16016 + limpk("ICMP type %u len %u too short\n",
16017 + icmph->type, datalen);
16021 + /* CHECK: Check within known error ICMPs. */
16022 + if (icmph->type < sizeof(info)/sizeof(struct icmp_info)
16023 + && info[icmph->type].err == ICMP_IS_ERROR) {
16024 + /* CHECK: Embedded packet must be at least
16025 + length of iph + 8 bytes. */
16026 + struct iphdr *inner = (void *)icmph + 8;
16028 + /* datalen > 8 since all ICMP_IS_ERROR types
16029 + have min length > 8 */
16030 + if (datalen - 8 < sizeof(struct iphdr)) {
16031 + limpk("ICMP error internal way too short\n");
16034 + if (datalen - 8 < inner->ihl*4 + 8) {
16035 + limpk("ICMP error internal too short\n");
16038 + if (!check_ip(inner, datalen - 8, 1))
16042 + /* CHECK: Can't embed ICMP unless known non-error. */
16043 + if (icmph->type >= sizeof(info)/sizeof(struct icmp_info)
16044 + || info[icmph->type].err != ICMP_NOT_ERROR) {
16045 + limpk("ICMP type %u not embeddable\n",
16051 + /* CHECK: Invalid ICMP codes. */
16052 + if (icmph->type < sizeof(info)/sizeof(struct icmp_info)
16053 + && (icmph->code < info[icmph->type].min_code
16054 + || icmph->code > info[icmph->type].max_code)) {
16055 + limpk("ICMP type=%u code=%u\n",
16056 + icmph->type, icmph->code);
16060 + /* CHECK: Above maximum length. */
16061 + if (icmph->type < sizeof(info)/sizeof(struct icmp_info)
16062 + && info[icmph->type].max_len != 0
16063 + && datalen > info[icmph->type].max_len) {
16064 + limpk("ICMP type=%u too long: %u bytes\n",
16065 + icmph->type, datalen);
16069 + switch (icmph->type) {
16070 + case ICMP_PARAMETERPROB: {
16071 + /* CHECK: Problem param must be within error packet's
16073 + struct iphdr *iph = (void *)icmph + 8;
16074 + u_int32_t arg = ntohl(icmph->un.gateway);
16076 + if (icmph->code == 0) {
16077 + /* Code 0 means that upper 8 bits is pointer
16079 + if ((arg >> 24) >= iph->ihl*4) {
16080 + limpk("ICMP PARAMETERPROB ptr = %u\n",
16081 + ntohl(icmph->un.gateway) >> 24);
16084 + arg &= 0x00FFFFFF;
16087 + /* CHECK: Rest must be zero. */
16089 + limpk("ICMP PARAMETERPROB nonzero arg = %u\n",
16096 + case ICMP_TIME_EXCEEDED:
16097 + case ICMP_SOURCE_QUENCH:
16098 + /* CHECK: Unused must be zero. */
16099 + if (icmph->un.gateway != 0) {
16100 + limpk("ICMP type=%u unused = %u\n",
16101 + icmph->type, ntohl(icmph->un.gateway));
16110 +/* UDP-specific checks. */
16112 +check_udp(const struct iphdr *iph,
16113 + const struct udphdr *udph,
16114 + u_int16_t datalen,
16115 + unsigned int offset,
16119 + /* Can't do anything if it's a fragment. */
16123 + /* CHECK: Must cover UDP header. */
16124 + if (datalen < sizeof(struct udphdr)) {
16125 + limpk("UDP len=%u too short\n", datalen);
16129 + /* Bad checksum? Don't print, just say it's unclean. */
16130 + /* FIXME: SRC ROUTE packets won't match checksum --RR */
16131 + if (!more_frags && !embedded && udph->check
16132 + && csum_tcpudp_magic(iph->saddr, iph->daddr, datalen, IPPROTO_UDP,
16133 + csum_partial((char *)udph, datalen, 0)) != 0)
16136 + /* CHECK: Destination port can't be zero. */
16137 + if (!udph->dest) {
16138 + limpk("UDP zero destination port\n");
16142 + if (!more_frags) {
16144 + /* CHECK: UDP length must match. */
16145 + if (ntohs(udph->len) != datalen) {
16146 + limpk("UDP len too short %u vs %u\n",
16147 + ntohs(udph->len), datalen);
16151 + /* CHECK: UDP length be >= this truncated pkt. */
16152 + if (ntohs(udph->len) < datalen) {
16153 + limpk("UDP len too long %u vs %u\n",
16154 + ntohs(udph->len), datalen);
16159 + /* CHECK: UDP length must be > this frag's length. */
16160 + if (ntohs(udph->len) <= datalen) {
16161 + limpk("UDP fragment len too short %u vs %u\n",
16162 + ntohs(udph->len), datalen);
16170 +#define TH_FIN 0x01
16171 +#define TH_SYN 0x02
16172 +#define TH_RST 0x04
16173 +#define TH_PUSH 0x08
16174 +#define TH_ACK 0x10
16175 +#define TH_URG 0x20
16176 +#define TH_ECE 0x40
16177 +#define TH_CWR 0x80
16179 +/* table of valid flag combinations - ECE and CWR are always valid */
16180 +static u8 tcp_valid_flags[(TH_FIN|TH_SYN|TH_RST|TH_PUSH|TH_ACK|TH_URG) + 1] =
16183 + [TH_SYN|TH_ACK] = 1,
16185 + [TH_RST|TH_ACK] = 1,
16186 + [TH_RST|TH_ACK|TH_PUSH] = 1,
16187 + [TH_FIN|TH_ACK] = 1,
16189 + [TH_ACK|TH_PUSH] = 1,
16190 + [TH_ACK|TH_URG] = 1,
16191 + [TH_ACK|TH_URG|TH_PUSH] = 1,
16192 + [TH_FIN|TH_ACK|TH_PUSH] = 1,
16193 + [TH_FIN|TH_ACK|TH_URG] = 1,
16194 + [TH_FIN|TH_ACK|TH_URG|TH_PUSH] = 1
16197 +/* TCP-specific checks. */
16199 +check_tcp(const struct iphdr *iph,
16200 + const struct tcphdr *tcph,
16201 + u_int16_t datalen,
16202 + unsigned int offset,
16206 + u_int8_t *opt = (u_int8_t *)tcph;
16207 + u_int8_t *endhdr = (u_int8_t *)tcph + tcph->doff * 4;
16208 + u_int8_t tcpflags;
16209 + int end_of_options = 0;
16212 + /* CHECK: Can't have offset=1: used to override TCP syn-checks. */
16213 + /* In fact, this is caught below (offset < 516). */
16215 + /* Can't do anything if it's a fragment. */
16219 + /* CHECK: Smaller than minimal TCP hdr. */
16220 + if (datalen < sizeof(struct tcphdr)) {
16222 + limpk("Packet length %u < TCP header.\n", datalen);
16225 + /* Must have ports available (datalen >= 8), from
16226 + check_icmp which set embedded = 1 */
16227 + /* CHECK: TCP ports inside ICMP error */
16228 + if (!tcph->source || !tcph->dest) {
16229 + limpk("Zero TCP ports %u/%u.\n",
16230 + htons(tcph->source), htons(tcph->dest));
16236 + /* CHECK: Smaller than actual TCP hdr. */
16237 + if (datalen < tcph->doff * 4) {
16239 + limpk("Packet length %u < actual TCP header.\n",
16246 + /* Bad checksum? Don't print, just say it's unclean. */
16247 + /* FIXME: SRC ROUTE packets won't match checksum --RR */
16248 + if (!more_frags && !embedded
16249 + && csum_tcpudp_magic(iph->saddr, iph->daddr, datalen, IPPROTO_TCP,
16250 + csum_partial((char *)tcph, datalen, 0)) != 0)
16253 + /* CHECK: TCP ports non-zero */
16254 + if (!tcph->source || !tcph->dest) {
16255 + limpk("Zero TCP ports %u/%u.\n",
16256 + htons(tcph->source), htons(tcph->dest));
16260 + /* CHECK: TCP reserved bits zero. */
16261 + if(tcp_flag_word(tcph) & TCP_RESERVED_BITS) {
16262 + limpk("TCP reserved bits not zero\n");
16266 + /* CHECK: TCP flags. */
16267 + tcpflags = (((u_int8_t *)tcph)[13] & ~(TH_ECE|TH_CWR));
16268 + if (!tcp_valid_flags[tcpflags]) {
16269 + limpk("TCP flags bad: %u\n", tcpflags);
16273 + for (i = sizeof(struct tcphdr); i < tcph->doff * 4; ) {
16274 + switch (opt[i]) {
16276 + end_of_options = 1;
16283 + /* CHECK: options after EOO. */
16284 + if (end_of_options) {
16285 + limpk("TCP option %u after end\n",
16289 + /* CHECK: options at tail. */
16290 + else if (i+1 >= tcph->doff * 4) {
16291 + limpk("TCP option %u at tail\n",
16295 + /* CHECK: zero-length options. */
16296 + else if (opt[i+1] == 0) {
16297 + limpk("TCP option %u 0 len\n",
16301 + /* CHECK: oversize options. */
16302 + else if (&opt[i] + opt[i+1] > endhdr) {
16303 + limpk("TCP option %u at %Zu too long\n",
16304 + (unsigned int) opt[i], i);
16307 + /* Move to next option */
16315 +/* Returns 1 if ok */
16316 +/* Standard IP checks. */
16318 +check_ip(struct iphdr *iph, size_t length, int embedded)
16320 + u_int8_t *opt = (u_int8_t *)iph;
16321 + u_int8_t *endhdr = (u_int8_t *)iph + iph->ihl * 4;
16322 + int end_of_options = 0;
16326 + unsigned int offset;
16328 + /* Should only happen for local outgoing raw-socket packets. */
16329 + /* CHECK: length >= ip header. */
16330 + if (length < sizeof(struct iphdr) || length < iph->ihl * 4) {
16331 + limpk("Packet length %Zu < IP header.\n", length);
16335 + offset = ntohs(iph->frag_off) & IP_OFFSET;
16336 + protoh = (void *)iph + iph->ihl * 4;
16337 + datalen = length - iph->ihl * 4;
16339 + /* CHECK: Embedded fragment. */
16340 + if (embedded && offset) {
16341 + limpk("Embedded fragment.\n");
16345 + for (i = sizeof(struct iphdr); i < iph->ihl * 4; ) {
16346 + switch (opt[i]) {
16348 + end_of_options = 1;
16355 + /* CHECK: options after EOO. */
16356 + if (end_of_options) {
16357 + limpk("IP option %u after end\n",
16361 + /* CHECK: options at tail. */
16362 + else if (i+1 >= iph->ihl * 4) {
16363 + limpk("IP option %u at tail\n",
16367 + /* CHECK: zero-length or one-length options. */
16368 + else if (opt[i+1] < 2) {
16369 + limpk("IP option %u %u len\n",
16370 + opt[i], opt[i+1]);
16373 + /* CHECK: oversize options. */
16374 + else if (&opt[i] + opt[i+1] > endhdr) {
16375 + limpk("IP option %u at %u too long\n",
16379 + /* Move to next option */
16384 + /* Fragment checks. */
16386 + /* CHECK: More fragments, but doesn't fill 8-byte boundary. */
16387 + if ((ntohs(iph->frag_off) & IP_MF)
16388 + && (ntohs(iph->tot_len) % 8) != 0) {
16389 + limpk("Truncated fragment %u long.\n", ntohs(iph->tot_len));
16393 + /* CHECK: Oversize fragment a-la Ping of Death. */
16394 + if (offset * 8 + datalen > 65535) {
16395 + limpk("Oversize fragment to %u.\n", offset * 8);
16399 + /* CHECK: DF set and offset or MF set. */
16400 + if ((ntohs(iph->frag_off) & IP_DF)
16401 + && (offset || (ntohs(iph->frag_off) & IP_MF))) {
16402 + limpk("DF set and offset=%u, MF=%u.\n",
16403 + offset, ntohs(iph->frag_off) & IP_MF);
16407 + /* CHECK: Zero-sized fragments. */
16408 + if ((offset || (ntohs(iph->frag_off) & IP_MF))
16409 + && datalen == 0) {
16410 + limpk("Zero size fragment offset=%u\n", offset);
16414 + /* Note: we can have even middle fragments smaller than this:
16415 + consider a large packet passing through a 600MTU then
16416 + 576MTU link: this gives a fragment of 24 data bytes. But
16417 + everyone packs fragments largest first, hence a fragment
16418 + can't START before 576 - MAX_IP_HEADER_LEN. */
16420 + /* Used to be min-size 576: I recall Alan Cox saying ax25 goes
16421 + down to 128 (576 taken from RFC 791: All hosts must be
16422 + prepared to accept datagrams of up to 576 octets). Use 128
16424 +#define MIN_LIKELY_MTU 128
16425 + /* CHECK: Min size of first frag = 128. */
16426 + if ((ntohs(iph->frag_off) & IP_MF)
16428 + && ntohs(iph->tot_len) < MIN_LIKELY_MTU) {
16429 + limpk("First fragment size %u < %u\n", ntohs(iph->tot_len),
16434 + /* CHECK: Min offset of frag = 128 - IP hdr len. */
16435 + if (offset && offset * 8 < MIN_LIKELY_MTU - iph->ihl * 4) {
16436 + limpk("Fragment starts at %u < %u\n", offset * 8,
16437 + MIN_LIKELY_MTU - iph->ihl * 4);
16441 + /* CHECK: Protocol specification non-zero. */
16442 + if (iph->protocol == 0) {
16443 + limpk("Zero protocol\n");
16447 + /* CHECK: Do not use what is unused.
16448 + * First bit of fragmentation flags should be unused.
16449 + * May be used by OS fingerprinting tools.
16450 + * 04 Jun 2002, Maciej Soltysiak, solt@dns.toxicfilms.tv
16452 + if (ntohs(iph->frag_off)>>15) {
16453 + limpk("IP unused bit set\n");
16457 + /* Per-protocol checks. */
16458 + switch (iph->protocol) {
16459 + case IPPROTO_ICMP:
16460 + return check_icmp(protoh, datalen, offset,
16461 + (ntohs(iph->frag_off) & IP_MF),
16464 + case IPPROTO_UDP:
16465 + return check_udp(iph, protoh, datalen, offset,
16466 + (ntohs(iph->frag_off) & IP_MF),
16469 + case IPPROTO_TCP:
16470 + return check_tcp(iph, protoh, datalen, offset,
16471 + (ntohs(iph->frag_off) & IP_MF),
16474 + /* Ignorance is bliss. */
16480 +match(const struct sk_buff *skb,
16481 + const struct net_device *in,
16482 + const struct net_device *out,
16483 + const void *matchinfo,
16486 + u_int16_t datalen,
16489 + return !check_ip(skb->nh.iph, skb->len, 0);
16492 +/* Called when user tries to insert an entry of this type. */
16494 +checkentry(const char *tablename,
16495 + const struct ipt_ip *ip,
16497 + unsigned int matchsize,
16498 + unsigned int hook_mask)
16500 + if (matchsize != IPT_ALIGN(0))
16506 +static struct ipt_match unclean_match
16507 += { { NULL, NULL }, "unclean", &match, &checkentry, NULL, THIS_MODULE };
16509 +static int __init init(void)
16511 + return ipt_register_match(&unclean_match);
16514 +static void __exit fini(void)
16516 + ipt_unregister_match(&unclean_match);
16519 +module_init(init);
16520 +module_exit(fini);
16521 +MODULE_LICENSE("GPL");
16522 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/iptable_filter.c linux-2.6.6/net/ipv4/netfilter/iptable_filter.c
16523 --- linux-2.6.6.org/net/ipv4/netfilter/iptable_filter.c 2004-05-10 04:32:28.000000000 +0200
16524 +++ linux-2.6.6/net/ipv4/netfilter/iptable_filter.c 2004-05-18 14:28:50.000000000 +0200
16527 sizeof(struct ipt_entry),
16528 sizeof(struct ipt_standard),
16529 - 0, { 0, 0 }, { } },
16530 + 0, NULL, 0, { 0, 0 }, { } },
16531 { { { { IPT_ALIGN(sizeof(struct ipt_standard_target)), "" } }, { } },
16532 -NF_ACCEPT - 1 } },
16536 sizeof(struct ipt_entry),
16537 sizeof(struct ipt_standard),
16538 - 0, { 0, 0 }, { } },
16539 + 0, NULL, 0, { 0, 0 }, { } },
16540 { { { { IPT_ALIGN(sizeof(struct ipt_standard_target)), "" } }, { } },
16541 -NF_ACCEPT - 1 } },
16545 sizeof(struct ipt_entry),
16546 sizeof(struct ipt_standard),
16547 - 0, { 0, 0 }, { } },
16548 + 0, NULL, 0, { 0, 0 }, { } },
16549 { { { { IPT_ALIGN(sizeof(struct ipt_standard_target)), "" } }, { } },
16554 sizeof(struct ipt_entry),
16555 sizeof(struct ipt_error),
16556 - 0, { 0, 0 }, { } },
16557 + 0, NULL, 0, { 0, 0 }, { } },
16558 { { { { IPT_ALIGN(sizeof(struct ipt_error_target)), IPT_ERROR_TARGET } },
16561 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/iptable_mangle.c linux-2.6.6/net/ipv4/netfilter/iptable_mangle.c
16562 --- linux-2.6.6.org/net/ipv4/netfilter/iptable_mangle.c 2004-05-10 04:33:14.000000000 +0200
16563 +++ linux-2.6.6/net/ipv4/netfilter/iptable_mangle.c 2004-05-18 14:28:50.000000000 +0200
16566 sizeof(struct ipt_entry),
16567 sizeof(struct ipt_standard),
16568 - 0, { 0, 0 }, { } },
16569 + 0, NULL, 0, { 0, 0 }, { } },
16570 { { { { IPT_ALIGN(sizeof(struct ipt_standard_target)), "" } }, { } },
16571 -NF_ACCEPT - 1 } },
16575 sizeof(struct ipt_entry),
16576 sizeof(struct ipt_standard),
16577 - 0, { 0, 0 }, { } },
16578 + 0, NULL, 0, { 0, 0 }, { } },
16579 { { { { IPT_ALIGN(sizeof(struct ipt_standard_target)), "" } }, { } },
16580 -NF_ACCEPT - 1 } },
16584 sizeof(struct ipt_entry),
16585 sizeof(struct ipt_standard),
16586 - 0, { 0, 0 }, { } },
16587 + 0, NULL, 0, { 0, 0 }, { } },
16588 { { { { IPT_ALIGN(sizeof(struct ipt_standard_target)), "" } }, { } },
16589 -NF_ACCEPT - 1 } },
16593 sizeof(struct ipt_entry),
16594 sizeof(struct ipt_standard),
16595 - 0, { 0, 0 }, { } },
16596 + 0, NULL, 0, { 0, 0 }, { } },
16597 { { { { IPT_ALIGN(sizeof(struct ipt_standard_target)), "" } }, { } },
16598 -NF_ACCEPT - 1 } },
16600 @@ -106,7 +106,7 @@
16602 sizeof(struct ipt_entry),
16603 sizeof(struct ipt_standard),
16604 - 0, { 0, 0 }, { } },
16605 + 0, NULL, 0, { 0, 0 }, { } },
16606 { { { { IPT_ALIGN(sizeof(struct ipt_standard_target)), "" } }, { } },
16607 -NF_ACCEPT - 1 } },
16609 @@ -115,7 +115,7 @@
16611 sizeof(struct ipt_entry),
16612 sizeof(struct ipt_error),
16613 - 0, { 0, 0 }, { } },
16614 + 0, NULL, 0, { 0, 0 }, { } },
16615 { { { { IPT_ALIGN(sizeof(struct ipt_error_target)), IPT_ERROR_TARGET } },
16618 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/netfilter/iptable_raw.c linux-2.6.6/net/ipv4/netfilter/iptable_raw.c
16619 --- linux-2.6.6.org/net/ipv4/netfilter/iptable_raw.c 2004-05-10 04:33:19.000000000 +0200
16620 +++ linux-2.6.6/net/ipv4/netfilter/iptable_raw.c 2004-05-18 14:28:50.000000000 +0200
16623 sizeof(struct ipt_entry),
16624 sizeof(struct ipt_standard),
16625 - 0, { 0, 0 }, { } },
16626 + 0, NULL, 0, { 0, 0 }, { } },
16627 { { { { IPT_ALIGN(sizeof(struct ipt_standard_target)), "" } }, { } },
16628 -NF_ACCEPT - 1 } },
16632 sizeof(struct ipt_entry),
16633 sizeof(struct ipt_standard),
16634 - 0, { 0, 0 }, { } },
16635 + 0, NULL, 0, { 0, 0 }, { } },
16636 { { { { IPT_ALIGN(sizeof(struct ipt_standard_target)), "" } }, { } },
16641 sizeof(struct ipt_entry),
16642 sizeof(struct ipt_error),
16643 - 0, { 0, 0 }, { } },
16644 + 0, NULL, 0, { 0, 0 }, { } },
16645 { { { { IPT_ALIGN(sizeof(struct ipt_error_target)), IPT_ERROR_TARGET } },
16648 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/raw.c linux-2.6.6/net/ipv4/raw.c
16649 --- linux-2.6.6.org/net/ipv4/raw.c 2004-05-10 04:32:38.000000000 +0200
16650 +++ linux-2.6.6/net/ipv4/raw.c 2004-05-18 14:28:50.000000000 +0200
16651 @@ -249,6 +249,7 @@
16653 return NET_RX_DROP;
16657 skb_push(skb, skb->data - skb->nh.raw);
16659 @@ -307,7 +308,7 @@
16662 err = NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, skb, NULL, rt->u.dst.dev,
16666 err = inet->recverr ? net_xmit_errno(err) : 0;
16668 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/tcp_ipv4.c linux-2.6.6/net/ipv4/tcp_ipv4.c
16669 --- linux-2.6.6.org/net/ipv4/tcp_ipv4.c 2004-05-18 14:08:55.000000000 +0200
16670 +++ linux-2.6.6/net/ipv4/tcp_ipv4.c 2004-05-18 14:28:50.000000000 +0200
16671 @@ -1785,6 +1785,7 @@
16673 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb))
16674 goto discard_and_relse;
16677 if (sk_filter(sk, skb, 0))
16678 goto discard_and_relse;
16679 @@ -2636,6 +2637,7 @@
16680 EXPORT_SYMBOL(tcp_v4_connect);
16681 EXPORT_SYMBOL(tcp_v4_do_rcv);
16682 EXPORT_SYMBOL(tcp_v4_lookup_listener);
16683 +EXPORT_SYMBOL(tcp_v4_lookup);
16684 EXPORT_SYMBOL(tcp_v4_rebuild_header);
16685 EXPORT_SYMBOL(tcp_v4_remember_stamp);
16686 EXPORT_SYMBOL(tcp_v4_send_check);
16687 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/udp.c linux-2.6.6/net/ipv4/udp.c
16688 --- linux-2.6.6.org/net/ipv4/udp.c 2004-05-10 04:32:01.000000000 +0200
16689 +++ linux-2.6.6/net/ipv4/udp.c 2004-05-18 14:28:50.000000000 +0200
16690 @@ -1045,6 +1045,7 @@
16696 if (up->encap_type) {
16698 @@ -1210,6 +1211,7 @@
16700 if (!xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb))
16704 /* No socket. Drop packet silently, if checksum is wrong */
16705 if (udp_checksum_complete(skb))
16706 @@ -1558,6 +1560,7 @@
16707 EXPORT_SYMBOL(udp_port_rover);
16708 EXPORT_SYMBOL(udp_prot);
16709 EXPORT_SYMBOL(udp_sendmsg);
16710 +EXPORT_SYMBOL(udp_v4_lookup);
16712 #ifdef CONFIG_PROC_FS
16713 EXPORT_SYMBOL(udp_proc_register);
16714 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv4/xfrm4_tunnel.c linux-2.6.6/net/ipv4/xfrm4_tunnel.c
16715 --- linux-2.6.6.org/net/ipv4/xfrm4_tunnel.c 2004-05-10 04:32:00.000000000 +0200
16716 +++ linux-2.6.6/net/ipv4/xfrm4_tunnel.c 2004-05-18 14:28:50.000000000 +0200
16718 err = -EHOSTUNREACH;
16721 + IPCB(skb)->flags |= IPSKB_XFRM_TRANSFORMED;
16722 return NET_XMIT_BYPASS;
16725 @@ -170,6 +171,7 @@
16726 .handler = ipip_rcv,
16727 .err_handler = ipip_err,
16732 static int __init ipip_init(void)
16733 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv6/ip6_output.c linux-2.6.6/net/ipv6/ip6_output.c
16734 --- linux-2.6.6.org/net/ipv6/ip6_output.c 2004-05-10 04:31:59.000000000 +0200
16735 +++ linux-2.6.6/net/ipv6/ip6_output.c 2004-05-18 14:28:50.000000000 +0200
16736 @@ -805,6 +805,7 @@
16740 +EXPORT_SYMBOL(ip6_dst_lookup);
16742 int ip6_append_data(struct sock *sk, int getfrag(void *from, char *to, int offset, int len, int odd, struct sk_buff *skb),
16743 void *from, int length, int transhdrlen,
16744 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv6/ip6_tunnel.c linux-2.6.6/net/ipv6/ip6_tunnel.c
16745 --- linux-2.6.6.org/net/ipv6/ip6_tunnel.c 2004-05-10 04:31:59.000000000 +0200
16746 +++ linux-2.6.6/net/ipv6/ip6_tunnel.c 2004-05-18 14:28:50.000000000 +0200
16747 @@ -715,13 +715,7 @@
16748 ipv6h->nexthdr = proto;
16749 ipv6_addr_copy(&ipv6h->saddr, &fl.fl6_src);
16750 ipv6_addr_copy(&ipv6h->daddr, &fl.fl6_dst);
16751 -#ifdef CONFIG_NETFILTER
16752 - nf_conntrack_put(skb->nfct);
16753 - skb->nfct = NULL;
16754 -#ifdef CONFIG_NETFILTER_DEBUG
16755 - skb->nf_debug = 0;
16759 pkt_len = skb->len;
16760 err = NF_HOOK(PF_INET6, NF_IP6_LOCAL_OUT, skb, NULL,
16761 skb->dst->dev, dst_output);
16762 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv6/netfilter/Kconfig linux-2.6.6/net/ipv6/netfilter/Kconfig
16763 --- linux-2.6.6.org/net/ipv6/netfilter/Kconfig 2004-05-10 04:33:13.000000000 +0200
16764 +++ linux-2.6.6/net/ipv6/netfilter/Kconfig 2004-05-18 14:28:50.000000000 +0200
16765 @@ -230,5 +230,107 @@
16766 <file:Documentation/modules.txt>. If unsure, say `N'.
16769 +config IP6_NF_TARGET_HL
16770 + tristate 'HL target support'
16771 + depends on IP6_NF_MANGLE
16773 + This option adds a `HL' target, which allows you to modify the value of
16774 + IPv6 Hop Limit field.
16776 + If you want to compile it as a module, say M here and read
16777 + <file:Documentation/modules.txt>. If unsure, say `N'.
16779 +config IP6_NF_TARGET_REJECT
16780 + tristate 'REJECT target support'
16781 + depends on IP6_NF_FILTER
16783 + The REJECT target allows a filtering rule to specify that an ICMPv6
16784 + error should be issued in response to an incoming packet, rather
16785 + than silently being dropped.
16787 + If you want to compile it as a module, say M here and read
16788 + Documentation/modules.txt. If unsure, say `N'.
16790 +config IP6_NF_MATCH_FUZZY
16791 + tristate 'Fuzzy match support'
16792 + depends on IP6_NF_FILTER
16794 + This option adds a `fuzzy' match, which allows you to match
16795 + packets according to a fuzzy logic based law.
16797 + If you want to compile it as a module, say M here and read
16798 + Documentation/modules.txt. If unsure, say `N'.
16800 +config IP6_NF_MATCH_NTH
16801 + tristate 'Nth match support'
16802 + depends on IP6_NF_IPTABLES
16804 + This option adds a `Nth' match, which allow you to make
16805 + rules that match every Nth packet. By default there are
16806 + 16 different counters.
16809 + --every Nth Match every Nth packet
16810 + [--counter] num Use counter 0-15 (default:0)
16811 + [--start] num Initialize the counter at the number 'num'
16812 + instead of 0. Must be between 0 and Nth-1
16813 + [--packet] num Match on 'num' packet. Must be between 0
16816 + If --packet is used for a counter than
16817 + there must be Nth number of --packet
16818 + rules, covering all values between 0 and
16819 + Nth-1 inclusively.
16821 + If you want to compile it as a module, say M here and read
16822 + Documentation/modules.txt. If unsure, say `N'.
16824 +config IP6_NF_MATCH_RANDOM
16825 + tristate 'Random match support'
16826 + depends on IP6_NF_IPTABLES
16828 + This option adds a `random' match,
16829 + which allow you to match packets randomly
16830 + following a given probability.
16832 + If you want to compile it as a module, say M here and read
16833 + Documentation/modules.txt. If unsure, say `N'.
16835 +config IP6_NF_TARGET_ROUTE
16836 + tristate ' ROUTE target support'
16837 + depends on IP6_NF_MANGLE
16839 + This option adds a `ROUTE' target, which enables you to setup unusual
16840 + routes. The ROUTE target is also able to change the incoming interface
16843 + The target can be or not a final target. It has to be used inside the
16846 + Not working as a module.
16848 +config IP6_NF_TARGET_TRACE
16849 + tristate 'TRACE target support'
16850 + depends on IP6_NF_RAW
16852 + The TRACE target allows packets to be traced as those
16853 + matches any subsequent rule in any table/rule. The matched
16854 + rule and the packet is logged with the prefix
16856 + TRACE: tablename/chainname/rulenum
16858 + If you want to compile it as a module, say M here and read
16859 + <file:Documentation/modules.txt>. If unsure, say `N'.
16861 +config IP6_NF_MATCH_POLICY
16862 + tristate "IPsec policy match support"
16863 + depends on IP6_NF_IPTABLES && XFRM
16865 + Policy matching allows you to match packets based on the
16866 + IPsec policy that was used during decapsulation/will
16867 + be used during encapsulation.
16869 + To compile it as a module, choose M here. If unsure, say N.
16873 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv6/netfilter/Makefile linux-2.6.6/net/ipv6/netfilter/Makefile
16874 --- linux-2.6.6.org/net/ipv6/netfilter/Makefile 2004-05-10 04:32:39.000000000 +0200
16875 +++ linux-2.6.6/net/ipv6/netfilter/Makefile 2004-05-18 14:28:50.000000000 +0200
16877 obj-$(CONFIG_IP6_NF_MATCH_MARK) += ip6t_mark.o
16878 obj-$(CONFIG_IP6_NF_MATCH_LENGTH) += ip6t_length.o
16879 obj-$(CONFIG_IP6_NF_MATCH_MAC) += ip6t_mac.o
16880 +obj-$(CONFIG_IP6_NF_MATCH_FUZZY) += ip6t_fuzzy.o
16881 obj-$(CONFIG_IP6_NF_MATCH_RT) += ip6t_rt.o
16882 obj-$(CONFIG_IP6_NF_MATCH_OPTS) += ip6t_hbh.o ip6t_dst.o
16883 obj-$(CONFIG_IP6_NF_MATCH_IPV6HEADER) += ip6t_ipv6header.o
16884 obj-$(CONFIG_IP6_NF_MATCH_FRAG) += ip6t_frag.o
16885 obj-$(CONFIG_IP6_NF_MATCH_AHESP) += ip6t_esp.o ip6t_ah.o
16886 +obj-$(CONFIG_IP6_NF_MATCH_POLICY) += ip6t_policy.o
16887 obj-$(CONFIG_IP6_NF_MATCH_EUI64) += ip6t_eui64.o
16888 obj-$(CONFIG_IP6_NF_MATCH_MULTIPORT) += ip6t_multiport.o
16889 obj-$(CONFIG_IP6_NF_MATCH_OWNER) += ip6t_owner.o
16890 obj-$(CONFIG_IP6_NF_FILTER) += ip6table_filter.o
16891 obj-$(CONFIG_IP6_NF_MANGLE) += ip6table_mangle.o
16892 obj-$(CONFIG_IP6_NF_TARGET_MARK) += ip6t_MARK.o
16893 +obj-$(CONFIG_IP6_NF_TARGET_ROUTE) += ip6t_ROUTE.o
16894 +obj-$(CONFIG_IP6_NF_TARGET_REJECT) += ip6t_REJECT.o
16895 obj-$(CONFIG_IP6_NF_QUEUE) += ip6_queue.o
16896 obj-$(CONFIG_IP6_NF_TARGET_LOG) += ip6t_LOG.o
16898 +obj-$(CONFIG_IP6_NF_MATCH_RANDOM) += ip6t_random.o
16900 +obj-$(CONFIG_IP6_NF_MATCH_NTH) += ip6t_nth.o
16901 +obj-$(CONFIG_IP6_NF_TARGET_HL) += ip6t_HL.o
16902 obj-$(CONFIG_IP6_NF_RAW) += ip6table_raw.o
16903 +obj-$(CONFIG_IP6_NF_TARGET_TRACE) += ip6t_TRACE.o
16904 obj-$(CONFIG_IP6_NF_MATCH_HL) += ip6t_hl.o
16905 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv6/netfilter/ip6_tables.c linux-2.6.6/net/ipv6/netfilter/ip6_tables.c
16906 --- linux-2.6.6.org/net/ipv6/netfilter/ip6_tables.c 2004-05-10 04:33:19.000000000 +0200
16907 +++ linux-2.6.6/net/ipv6/netfilter/ip6_tables.c 2004-05-18 14:28:50.000000000 +0200
16909 #define IPV6_HDR_LEN (sizeof(struct ipv6hdr))
16910 #define IPV6_OPTHDR_LEN (sizeof(struct ipv6_opt_hdr))
16912 +static const char *hook6names[] = {
16913 + [NF_IP6_PRE_ROUTING] "PREROUTING",
16914 + [NF_IP6_LOCAL_IN] "INPUT",
16915 + [NF_IP6_FORWARD] "FORWARD",
16916 + [NF_IP6_LOCAL_OUT] "OUTPUT",
16917 + [NF_IP6_POST_ROUTING] "POSTROUTING",
16920 /*#define DEBUG_IP_FIREWALL*/
16921 /*#define DEBUG_ALLOW_ALL*/ /* Useful for remote debugging */
16922 /*#define DEBUG_IP_FIREWALL_USER*/
16923 @@ -408,6 +416,12 @@
16925 t = ip6t_get_target(e);
16926 IP_NF_ASSERT(t->u.kernel.target);
16928 + /* The packet traced and the rule isn't an unconditional return/END. */
16929 + if (((*pskb)->nfcache & NFC_TRACE) && e->rulenum) {
16930 + nf_log_packet(PF_INET6, hook, *pskb, in, out, "TRACE: %s/%s/%u ",
16931 + table->name, e->chainname, e->rulenum);
16933 /* Standard target? */
16934 if (!t->u.kernel.target->target) {
16936 @@ -561,6 +575,29 @@
16937 return find_inlist_lock(&ip6t_target, name, "ip6t_", error, mutex);
16941 +find_error_target(struct ip6t_entry *s,
16942 + struct ip6t_entry *e,
16943 + char **chainname)
16945 + struct ip6t_entry_target *t;
16946 + static struct ip6t_entry *found = NULL;
16951 + t = ip6t_get_target(found);
16952 + if (strcmp(t->u.user.name,
16953 + IP6T_ERROR_TARGET) == 0) {
16954 + *chainname = t->data;
16963 /* All zeroes == unconditional rule. */
16965 unconditional(const struct ip6t_ip6 *ipv6)
16966 @@ -580,6 +617,8 @@
16967 mark_source_chains(struct ip6t_table_info *newinfo, unsigned int valid_hooks)
16970 + char *chainname = NULL;
16971 + u_int32_t rulenum;
16973 /* No recursion; use packet counter to save back ptrs (reset
16974 to 0 as we leave), and comefrom to save source hook bitmask */
16975 @@ -593,6 +632,8 @@
16977 /* Set initial back pointer. */
16978 e->counters.pcnt = pos;
16980 + chainname = (char *) hook6names[hook];
16983 struct ip6t_standard_target *t
16984 @@ -605,6 +646,8 @@
16987 |= ((1 << hook) | (1 << NF_IP6_NUMHOOKS));
16988 + e->rulenum = rulenum++;
16989 + e->chainname = chainname;
16991 /* Unconditional return/END. */
16992 if (e->target_offset == sizeof(struct ip6t_entry)
16993 @@ -614,6 +657,10 @@
16994 && unconditional(&e->ipv6)) {
16995 unsigned int oldpos, size;
16997 + /* Set unconditional rulenum to zero. */
16999 + e->counters.bcnt = 0;
17001 /* Return: backtrack through the last
17004 @@ -639,6 +686,11 @@
17005 (newinfo->entries + pos);
17006 } while (oldpos == pos + e->next_offset);
17008 + /* Restore chainname, rulenum. */
17009 + chainname = e->chainname;
17010 + rulenum = e->counters.bcnt;
17011 + e->counters.bcnt = 0;
17013 /* Move along one */
17014 size = e->next_offset;
17015 e = (struct ip6t_entry *)
17016 @@ -654,6 +706,17 @@
17017 /* This a jump; chase it. */
17018 duprintf("Jump rule %u -> %u\n",
17020 + e->counters.bcnt = rulenum++;
17022 + e = (struct ip6t_entry *)
17023 + (newinfo->entries + newpos);
17024 + if (IP6T_ENTRY_ITERATE(newinfo->entries,
17026 + find_error_target,
17027 + e, &chainname) == 0) {
17028 + printk("ip6_tables: table screwed up!\n");
17032 /* ... this is a fallthru */
17033 newpos = pos + e->next_offset;
17034 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv6/netfilter/ip6t_HL.c linux-2.6.6/net/ipv6/netfilter/ip6t_HL.c
17035 --- linux-2.6.6.org/net/ipv6/netfilter/ip6t_HL.c 1970-01-01 01:00:00.000000000 +0100
17036 +++ linux-2.6.6/net/ipv6/netfilter/ip6t_HL.c 2004-05-18 14:28:50.000000000 +0200
17039 + * Hop Limit modification target for ip6tables
17040 + * Maciej Soltysiak <solt@dns.toxicfilms.tv>
17041 + * Based on HW's TTL module
17043 + * This software is distributed under the terms of GNU GPL
17046 +#include <linux/module.h>
17047 +#include <linux/skbuff.h>
17048 +#include <linux/ip.h>
17050 +#include <linux/netfilter_ipv6/ip6_tables.h>
17051 +#include <linux/netfilter_ipv6/ip6t_HL.h>
17053 +MODULE_AUTHOR("Maciej Soltysiak <solt@dns.toxicfilms.tv>");
17054 +MODULE_DESCRIPTION("IP tables Hop Limit modification module");
17055 +MODULE_LICENSE("GPL");
17057 +static unsigned int ip6t_hl_target(struct sk_buff **pskb, unsigned int hooknum,
17058 + const struct net_device *in, const struct net_device *out,
17059 + const void *targinfo, void *userinfo)
17061 + struct ipv6hdr *ip6h = (*pskb)->nh.ipv6h;
17062 + const struct ip6t_HL_info *info = targinfo;
17063 + u_int16_t diffs[2];
17066 + switch (info->mode) {
17067 + case IP6T_HL_SET:
17068 + new_hl = info->hop_limit;
17070 + case IP6T_HL_INC:
17071 + new_hl = ip6h->hop_limit + info->hop_limit;
17072 + if (new_hl > 255)
17075 + case IP6T_HL_DEC:
17076 + new_hl = ip6h->hop_limit + info->hop_limit;
17081 + new_hl = ip6h->hop_limit;
17085 + if (new_hl != ip6h->hop_limit) {
17086 + diffs[0] = htons(((unsigned)ip6h->hop_limit) << 8) ^ 0xFFFF;
17087 + ip6h->hop_limit = new_hl;
17088 + diffs[1] = htons(((unsigned)ip6h->hop_limit) << 8);
17091 + return IP6T_CONTINUE;
17094 +static int ip6t_hl_checkentry(const char *tablename,
17095 + const struct ip6t_entry *e,
17097 + unsigned int targinfosize,
17098 + unsigned int hook_mask)
17100 + struct ip6t_HL_info *info = targinfo;
17102 + if (targinfosize != IP6T_ALIGN(sizeof(struct ip6t_HL_info))) {
17103 + printk(KERN_WARNING "HL: targinfosize %u != %Zu\n",
17105 + IP6T_ALIGN(sizeof(struct ip6t_HL_info)));
17109 + if (strcmp(tablename, "mangle")) {
17110 + printk(KERN_WARNING "HL: can only be called from \"mangle\" table, not \"%s\"\n", tablename);
17114 + if (info->mode > IP6T_HL_MAXMODE) {
17115 + printk(KERN_WARNING "HL: invalid or unknown Mode %u\n",
17120 + if ((info->mode != IP6T_HL_SET) && (info->hop_limit == 0)) {
17121 + printk(KERN_WARNING "HL: increment/decrement doesn't make sense with value 0\n");
17128 +static struct ip6t_target ip6t_HL = { { NULL, NULL }, "HL",
17129 + ip6t_hl_target, ip6t_hl_checkentry, NULL, THIS_MODULE };
17131 +static int __init init(void)
17133 + return ip6t_register_target(&ip6t_HL);
17136 +static void __exit fini(void)
17138 + ip6t_unregister_target(&ip6t_HL);
17141 +module_init(init);
17142 +module_exit(fini);
17143 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv6/netfilter/ip6t_REJECT.c linux-2.6.6/net/ipv6/netfilter/ip6t_REJECT.c
17144 --- linux-2.6.6.org/net/ipv6/netfilter/ip6t_REJECT.c 1970-01-01 01:00:00.000000000 +0100
17145 +++ linux-2.6.6/net/ipv6/netfilter/ip6t_REJECT.c 2004-05-18 14:28:50.000000000 +0200
17148 + * IP6 tables REJECT target module
17149 + * Linux INET6 implementation
17151 + * Copyright (C)2003 USAGI/WIDE Project
17154 + * Yasuyuki Kozakai <yasuyuki.kozakai@toshiba.co.jp>
17156 + * Based on net/ipv4/netfilter/ipt_REJECT.c
17158 + * This program is free software; you can redistribute it and/or
17159 + * modify it under the terms of the GNU General Public License
17160 + * as published by the Free Software Foundation; either version
17161 + * 2 of the License, or (at your option) any later version.
17164 +#include <linux/config.h>
17165 +#include <linux/module.h>
17166 +#include <linux/skbuff.h>
17167 +#include <linux/icmpv6.h>
17168 +#include <net/ipv6.h>
17169 +#include <net/tcp.h>
17170 +#include <net/icmp.h>
17171 +#include <net/ip6_fib.h>
17172 +#include <net/ip6_route.h>
17173 +#include <net/flow.h>
17174 +#include <linux/netfilter_ipv6/ip6_tables.h>
17175 +#include <linux/netfilter_ipv6/ip6t_REJECT.h>
17177 +MODULE_AUTHOR("Yasuyuki KOZAKAI <yasuyuki.kozakai@toshiba.co.jp>");
17178 +MODULE_DESCRIPTION("IP6 tables REJECT target module");
17179 +MODULE_LICENSE("GPL");
17182 +#define DEBUGP printk
17184 +#define DEBUGP(format, args...)
17188 +static void connection_attach(struct sk_buff *new_skb, struct nf_ct_info *nfct)
17190 + void (*attach)(struct sk_buff *, struct nf_ct_info *);
17191 + if (nfct && (attach = ip6_ct_attach) != NULL) {
17193 + attach(new_skb, nfct);
17198 +static int maybe_reroute(struct sk_buff *skb)
17200 + if (skb->nfcache & NFC_ALTERED){
17201 + if (ip6_route_me_harder(skb) != 0){
17207 + return dst_output(skb);
17210 +/* Send RST reply */
17211 +static void send_reset(struct sk_buff *oldskb)
17213 + struct sk_buff *nskb;
17214 + struct tcphdr otcph, *tcph;
17215 + unsigned int otcplen, tcphoff, hh_len;
17217 + struct ipv6hdr *oip6h = oldskb->nh.ipv6h, *ip6h;
17218 + struct dst_entry *dst = NULL;
17221 + proto = oip6h->nexthdr;
17224 + if ((!(ipv6_addr_type(&oip6h->saddr) & IPV6_ADDR_UNICAST)) ||
17225 + (!(ipv6_addr_type(&oip6h->daddr) & IPV6_ADDR_UNICAST))) {
17226 + DEBUGP("ip6t_REJECT: addr is not unicast.\n");
17230 + tcphoff = ipv6_skip_exthdr(oldskb, ((u8*)(oip6h+1) - oldskb->data),
17231 + &proto, oldskb->len - ((u8*)(oip6h+1)
17232 + - oldskb->data));
17234 + if ((tcphoff < 0) || (tcphoff > oldskb->len)) {
17235 + DEBUGP("ip6t_REJECT: Can't get TCP header.\n");
17239 + otcplen = oldskb->len - tcphoff;
17241 + /* IP header checks: fragment, too short. */
17242 + if ((proto != IPPROTO_TCP) || (otcplen < sizeof(struct tcphdr))) {
17243 + DEBUGP("ip6t_REJECT: proto(%d) != IPPROTO_TCP, or too short. otcplen = %d\n",
17248 + if (skb_copy_bits(oldskb, tcphoff, &otcph, sizeof(struct tcphdr))) {
17249 + if (net_ratelimit())
17250 + printk("ip6t_REJECT: Can't copy tcp header\n");
17254 + /* No RST for RST. */
17256 + DEBUGP("ip6t_REJECT: RST is set\n");
17260 + /* Check checksum. */
17261 + if (csum_ipv6_magic(&oip6h->saddr, &oip6h->daddr, otcplen, IPPROTO_TCP,
17262 + skb_checksum(oldskb, tcphoff, otcplen, 0))) {
17263 + DEBUGP("ip6t_REJECT: TCP checksum is invalid\n");
17267 + memset(&fl, 0, sizeof(fl));
17268 + fl.proto = IPPROTO_TCP;
17269 + ipv6_addr_copy(&fl.fl6_src, &oip6h->daddr);
17270 + ipv6_addr_copy(&fl.fl6_dst, &oip6h->saddr);
17271 + fl.fl_ip_sport = otcph.dest;
17272 + fl.fl_ip_dport = otcph.source;
17273 + err = ip6_dst_lookup(NULL, &dst, &fl);
17275 + if (net_ratelimit())
17276 + printk("ip6t_REJECT: can't find dst. err = %d\n", err);
17280 + hh_len = (dst->dev->hard_header_len + 15)&~15;
17281 + nskb = alloc_skb(hh_len + 15 + dst->header_len + sizeof(struct ipv6hdr)
17282 + + sizeof(struct tcphdr) + dst->trailer_len,
17286 + if (net_ratelimit())
17287 + printk("ip6t_REJECT: Can't alloc skb\n");
17288 + dst_release(dst);
17295 + skb_reserve(nskb, hh_len + dst->header_len);
17297 + ip6h = nskb->nh.ipv6h = (struct ipv6hdr *)
17298 + skb_put(nskb, sizeof(struct ipv6hdr));
17299 + ip6h->version = 6;
17300 + ip6h->hop_limit = dst_metric(dst, RTAX_HOPLIMIT);
17301 + ip6h->nexthdr = IPPROTO_TCP;
17302 + ip6h->payload_len = htons(sizeof(struct tcphdr));
17303 + ipv6_addr_copy(&ip6h->saddr, &oip6h->daddr);
17304 + ipv6_addr_copy(&ip6h->daddr, &oip6h->saddr);
17306 + tcph = (struct tcphdr *)skb_put(nskb, sizeof(struct tcphdr));
17307 + /* Truncate to length (no data) */
17308 + tcph->doff = sizeof(struct tcphdr)/4;
17309 + tcph->source = otcph.dest;
17310 + tcph->dest = otcph.source;
17314 + tcph->seq = otcph.ack_seq;
17315 + tcph->ack_seq = 0;
17318 + tcph->ack_seq = htonl(ntohl(otcph.seq) + otcph.syn + otcph.fin
17319 + + otcplen - (otcph.doff<<2));
17323 + /* Reset flags */
17324 + ((u_int8_t *)tcph)[13] = 0;
17326 + tcph->ack = needs_ack;
17327 + tcph->window = 0;
17328 + tcph->urg_ptr = 0;
17331 + /* Adjust TCP checksum */
17332 + tcph->check = csum_ipv6_magic(&nskb->nh.ipv6h->saddr,
17333 + &nskb->nh.ipv6h->daddr,
17334 + sizeof(struct tcphdr), IPPROTO_TCP,
17335 + csum_partial((char *)tcph,
17336 + sizeof(struct tcphdr), 0));
17339 + connection_attach(nskb, oldskb->nfct);
17342 + NF_HOOK(PF_INET6, NF_IP6_LOCAL_OUT, nskb, NULL, nskb->dst->dev,
17345 + dst_release(dst);
17348 +static void send_unreach(struct sk_buff *skb_in, unsigned char code)
17350 + struct ipv6hdr *ip6h, *hdr = skb_in->nh.ipv6h;
17351 + struct icmp6hdr *icmp6h;
17352 + struct dst_entry *dst = NULL;
17353 + struct rt6_info *rt;
17356 + unsigned int len, datalen, hh_len;
17357 + int saddr_type, daddr_type;
17358 + unsigned int ptr, ip6off;
17361 + struct sk_buff *nskb;
17364 + saddr_type = ipv6_addr_type(&hdr->saddr);
17365 + daddr_type = ipv6_addr_type(&hdr->daddr);
17367 + if ((!(saddr_type & IPV6_ADDR_UNICAST)) ||
17368 + (!(daddr_type & IPV6_ADDR_UNICAST))) {
17369 + DEBUGP("ip6t_REJECT: addr is not unicast.\n");
17373 + ip6off = skb_in->nh.raw - skb_in->data;
17374 + proto = hdr->nexthdr;
17375 + ptr = ipv6_skip_exthdr(skb_in, ip6off + sizeof(struct ipv6hdr), &proto,
17376 + skb_in->len - ip6off);
17378 + if ((ptr < 0) || (ptr > skb_in->len)) {
17379 + ptr = ip6off + sizeof(struct ipv6hdr);
17380 + proto = hdr->nexthdr;
17381 + } else if (proto == IPPROTO_ICMPV6) {
17384 + if (skb_copy_bits(skb_in, ptr + offsetof(struct icmp6hdr,
17385 + icmp6_type), &type, 1)) {
17386 + DEBUGP("ip6t_REJECT: Can't get ICMPv6 type\n");
17390 + if (!(type & ICMPV6_INFOMSG_MASK)) {
17391 + DEBUGP("ip6t_REJECT: no reply to icmp error\n");
17394 + } else if (proto == IPPROTO_UDP) {
17395 + int plen = skb_in->len - (ptr - ip6off);
17398 + if (plen < sizeof(struct udphdr)) {
17399 + DEBUGP("ip6t_REJECT: too short\n");
17403 + if (skb_copy_bits(skb_in, ptr + offsetof(struct udphdr, check),
17405 + if (net_ratelimit())
17406 + printk("ip6t_REJECT: can't get copy from skb");
17411 + csum_ipv6_magic(&hdr->saddr, &hdr->daddr, plen,
17413 + skb_checksum(skb_in, ptr, plen, 0))) {
17414 + DEBUGP("ip6t_REJECT: UDP checksum is invalid.\n");
17419 + memset(&fl, 0, sizeof(fl));
17420 + fl.proto = IPPROTO_ICMPV6;
17421 + ipv6_addr_copy(&fl.fl6_src, &hdr->daddr);
17422 + ipv6_addr_copy(&fl.fl6_dst, &hdr->saddr);
17423 + fl.fl_icmp_type = ICMPV6_DEST_UNREACH;
17424 + fl.fl_icmp_code = code;
17426 + if (ip6_dst_lookup(NULL, &dst, &fl)) {
17430 + rt = (struct rt6_info *)dst;
17433 + if (rt->rt6i_dst.plen < 128)
17434 + tmo >>= ((128 - rt->rt6i_dst.plen)>>5);
17436 + if (!xrlim_allow(dst, tmo)) {
17437 + if (net_ratelimit())
17438 + printk("ip6t_REJECT: rate limitted\n");
17439 + goto dst_release_out;
17442 + len = skb_in->len + sizeof(struct ipv6hdr) + sizeof(struct icmp6hdr);
17444 + if (len > dst_pmtu(dst))
17445 + len = dst_pmtu(dst);
17446 + if (len > IPV6_MIN_MTU)
17447 + len = IPV6_MIN_MTU;
17449 + datalen = len - sizeof(struct ipv6hdr) - sizeof(struct icmp6hdr);
17450 + hh_len = (rt->u.dst.dev->hard_header_len + 15)&~15;
17452 + nskb = alloc_skb(hh_len + 15 + dst->header_len + dst->trailer_len + len,
17456 + if (net_ratelimit())
17457 + printk("ip6t_REJECT: can't alloc skb\n");
17458 + goto dst_release_out;
17461 + nskb->priority = 0;
17465 + skb_reserve(nskb, hh_len + dst->header_len);
17467 + ip6h = nskb->nh.ipv6h = (struct ipv6hdr *)
17468 + skb_put(nskb, sizeof(struct ipv6hdr));
17469 + ip6h->version = 6;
17470 + ip6h->hop_limit = dst_metric(dst, RTAX_HOPLIMIT);
17471 + ip6h->nexthdr = IPPROTO_ICMPV6;
17472 + ip6h->payload_len = htons(datalen + sizeof(struct icmp6hdr));
17473 + ipv6_addr_copy(&ip6h->saddr, &hdr->daddr);
17474 + ipv6_addr_copy(&ip6h->daddr, &hdr->saddr);
17476 + icmp6h = (struct icmp6hdr *) skb_put(nskb, sizeof(struct icmp6hdr));
17477 + icmp6h->icmp6_type = ICMPV6_DEST_UNREACH;
17478 + icmp6h->icmp6_code = code;
17479 + icmp6h->icmp6_cksum = 0;
17481 + data = skb_put(nskb, datalen);
17483 + csum = csum_partial((unsigned char *)icmp6h, sizeof(struct icmp6hdr), 0);
17484 + csum = skb_copy_and_csum_bits(skb_in, ip6off, data, datalen, csum);
17485 + icmp6h->icmp6_cksum = csum_ipv6_magic(&hdr->saddr, &hdr->daddr,
17486 + datalen + sizeof(struct icmp6hdr),
17487 + IPPROTO_ICMPV6, csum);
17490 + connection_attach(nskb, skb_in->nfct);
17492 + NF_HOOK(PF_INET6, NF_IP6_LOCAL_OUT, nskb, NULL, nskb->dst->dev,
17496 + dst_release(dst);
17499 +static unsigned int reject6_target(struct sk_buff **pskb,
17500 + unsigned int hooknum,
17501 + const struct net_device *in,
17502 + const struct net_device *out,
17503 + const void *targinfo,
17506 + const struct ip6t_reject_info *reject = targinfo;
17508 + DEBUGP(KERN_DEBUG "%s: medium point\n", __FUNCTION__);
17509 + /* WARNING: This code causes reentry within ip6tables.
17510 + This means that the ip6tables jump stack is now crap. We
17511 + must return an absolute verdict. --RR */
17512 + switch (reject->with) {
17513 + case IP6T_ICMP6_NO_ROUTE:
17514 + send_unreach(*pskb, ICMPV6_NOROUTE);
17516 + case IP6T_ICMP6_ADM_PROHIBITED:
17517 + send_unreach(*pskb, ICMPV6_ADM_PROHIBITED);
17519 + case IP6T_ICMP6_NOT_NEIGHBOUR:
17520 + send_unreach(*pskb, ICMPV6_NOT_NEIGHBOUR);
17522 + case IP6T_ICMP6_ADDR_UNREACH:
17523 + send_unreach(*pskb, ICMPV6_ADDR_UNREACH);
17525 + case IP6T_ICMP6_PORT_UNREACH:
17526 + send_unreach(*pskb, ICMPV6_PORT_UNREACH);
17528 + case IP6T_ICMP6_ECHOREPLY:
17531 + case IP6T_TCP_RESET:
17532 + send_reset(*pskb);
17535 + if (net_ratelimit())
17536 + printk(KERN_WARNING "ip6t_REJECT: case %u not handled yet\n", reject->with);
17543 +static int check(const char *tablename,
17544 + const struct ip6t_entry *e,
17546 + unsigned int targinfosize,
17547 + unsigned int hook_mask)
17549 + const struct ip6t_reject_info *rejinfo = targinfo;
17551 + if (targinfosize != IP6T_ALIGN(sizeof(struct ip6t_reject_info))) {
17552 + DEBUGP("ip6t_REJECT: targinfosize %u != 0\n", targinfosize);
17556 + /* Only allow these for packet filtering. */
17557 + if (strcmp(tablename, "filter") != 0) {
17558 + DEBUGP("ip6t_REJECT: bad table `%s'.\n", tablename);
17562 + if ((hook_mask & ~((1 << NF_IP6_LOCAL_IN)
17563 + | (1 << NF_IP6_FORWARD)
17564 + | (1 << NF_IP6_LOCAL_OUT))) != 0) {
17565 + DEBUGP("ip6t_REJECT: bad hook mask %X\n", hook_mask);
17569 + if (rejinfo->with == IP6T_ICMP6_ECHOREPLY) {
17570 + printk("ip6t_REJECT: ECHOREPLY is not supported.\n");
17572 + } else if (rejinfo->with == IP6T_TCP_RESET) {
17573 + /* Must specify that it's a TCP packet */
17574 + if (e->ipv6.proto != IPPROTO_TCP
17575 + || (e->ipv6.invflags & IP6T_INV_PROTO)) {
17576 + DEBUGP("ip6t_REJECT: TCP_RESET illegal for non-tcp\n");
17584 +static struct ip6t_target ip6t_reject_reg = {
17585 + .name = "REJECT",
17586 + .target = reject6_target,
17587 + .checkentry = check,
17588 + .me = THIS_MODULE
17591 +static int __init init(void)
17593 + if (ip6t_register_target(&ip6t_reject_reg))
17598 +static void __exit fini(void)
17600 + ip6t_unregister_target(&ip6t_reject_reg);
17603 +module_init(init);
17604 +module_exit(fini);
17605 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv6/netfilter/ip6t_ROUTE.c linux-2.6.6/net/ipv6/netfilter/ip6t_ROUTE.c
17606 --- linux-2.6.6.org/net/ipv6/netfilter/ip6t_ROUTE.c 1970-01-01 01:00:00.000000000 +0100
17607 +++ linux-2.6.6/net/ipv6/netfilter/ip6t_ROUTE.c 2004-05-18 14:28:50.000000000 +0200
17610 + * This implements the ROUTE v6 target, which enables you to setup unusual
17611 + * routes not supported by the standard kernel routing table.
17613 + * Copyright (C) 2003 Cedric de Launois <delaunois@info.ucl.ac.be>
17615 + * v 1.0 2003/08/05
17617 + * This software is distributed under GNU GPL v2, 1991
17620 +#include <linux/module.h>
17621 +#include <linux/skbuff.h>
17622 +#include <linux/ipv6.h>
17623 +#include <linux/netfilter_ipv6/ip6_tables.h>
17624 +#include <linux/netfilter_ipv6/ip6t_ROUTE.h>
17625 +#include <linux/netdevice.h>
17626 +#include <net/ipv6.h>
17627 +#include <net/ndisc.h>
17628 +#include <net/ip6_route.h>
17629 +#include <linux/icmpv6.h>
17632 +#define DEBUGP printk
17634 +#define DEBUGP(format, args...)
17637 +#define NIP6(addr) \
17638 + ntohs((addr).s6_addr16[0]), \
17639 + ntohs((addr).s6_addr16[1]), \
17640 + ntohs((addr).s6_addr16[2]), \
17641 + ntohs((addr).s6_addr16[3]), \
17642 + ntohs((addr).s6_addr16[4]), \
17643 + ntohs((addr).s6_addr16[5]), \
17644 + ntohs((addr).s6_addr16[6]), \
17645 + ntohs((addr).s6_addr16[7])
17647 +/* Route the packet according to the routing keys specified in
17648 + * route_info. Keys are :
17650 + * 0 if no oif preferred,
17651 + * otherwise set to the index of the desired oif
17652 + * - route_info->gw :
17653 + * 0 if no gateway specified,
17654 + * otherwise set to the next host to which the pkt must be routed
17655 + * If success, skb->dev is the output device to which the packet must
17656 + * be sent and skb->dst is not NULL
17658 + * RETURN: 1 if the packet was succesfully routed to the
17659 + * destination desired
17660 + * 0 if the kernel routing table could not route the packet
17661 + * according to the keys specified
17664 +route6(struct sk_buff *skb,
17665 + unsigned int ifindex,
17666 + const struct ip6t_route_target_info *route_info)
17668 + struct rt6_info *rt = NULL;
17669 + struct ipv6hdr *ipv6h = skb->nh.ipv6h;
17670 + struct in6_addr *gw = (struct in6_addr*)&route_info->gw;
17672 + DEBUGP("ip6t_ROUTE: called with: ");
17673 + DEBUGP("DST=%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x ", NIP6(ipv6h->daddr));
17674 + DEBUGP("GATEWAY=%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x ", NIP6(*gw));
17675 + DEBUGP("OUT=%s\n", route_info->oif);
17677 + if (ipv6_addr_any(gw))
17678 + rt = rt6_lookup(&ipv6h->daddr, &ipv6h->saddr, ifindex, 1);
17680 + rt = rt6_lookup(gw, &ipv6h->saddr, ifindex, 1);
17685 + DEBUGP("ip6t_ROUTE: routing gives: ");
17686 + DEBUGP("DST=%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x ", NIP6(rt->rt6i_dst.addr));
17687 + DEBUGP("GATEWAY=%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x ", NIP6(rt->rt6i_gateway));
17688 + DEBUGP("OUT=%s\n", rt->rt6i_dev->name);
17690 + if (ifindex && rt->rt6i_dev->ifindex!=ifindex)
17691 + goto wrong_route;
17693 + if (!rt->rt6i_nexthop) {
17694 + DEBUGP("ip6t_ROUTE: discovering neighbour\n");
17695 + rt->rt6i_nexthop = ndisc_get_neigh(rt->rt6i_dev, &rt->rt6i_dst.addr);
17698 + /* Drop old route. */
17699 + dst_release(skb->dst);
17700 + skb->dst = &rt->u.dst;
17701 + skb->dev = rt->rt6i_dev;
17705 + dst_release(&rt->u.dst);
17707 + if (!net_ratelimit())
17710 + printk("ip6t_ROUTE: no explicit route found ");
17712 + printk("via interface %s ", route_info->oif);
17713 + if (!ipv6_addr_any(gw))
17714 + printk("via gateway %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x", NIP6(*gw));
17720 +/* Stolen from ip6_output_finish
17721 + * PRE : skb->dev is set to the device we are leaving by
17722 + * skb->dst is not NULL
17723 + * POST: the packet is sent with the link layer header pushed
17724 + * the packet is destroyed
17726 +static void ip_direct_send(struct sk_buff *skb)
17728 + struct dst_entry *dst = skb->dst;
17729 + struct hh_cache *hh = dst->hh;
17732 + read_lock_bh(&hh->hh_lock);
17733 + memcpy(skb->data - 16, hh->hh_data, 16);
17734 + read_unlock_bh(&hh->hh_lock);
17735 + skb_push(skb, hh->hh_len);
17736 + hh->hh_output(skb);
17737 + } else if (dst->neighbour)
17738 + dst->neighbour->output(skb);
17740 + if (net_ratelimit())
17741 + DEBUGP(KERN_DEBUG "ip6t_ROUTE: no hdr & no neighbour cache!\n");
17747 +static unsigned int
17748 +route6_oif(const struct ip6t_route_target_info *route_info,
17749 + struct sk_buff *skb)
17751 + unsigned int ifindex = 0;
17752 + struct net_device *dev_out = NULL;
17754 + /* The user set the interface name to use.
17755 + * Getting the current interface index.
17757 + if ((dev_out = dev_get_by_name(route_info->oif))) {
17758 + ifindex = dev_out->ifindex;
17760 + /* Unknown interface name : packet dropped */
17761 + if (net_ratelimit())
17762 + DEBUGP("ip6t_ROUTE: oif interface %s not found\n", route_info->oif);
17764 + if (route_info->flags & IP6T_ROUTE_CONTINUE)
17765 + return IP6T_CONTINUE;
17770 + /* Trying the standard way of routing packets */
17771 + if (route6(skb, ifindex, route_info)) {
17772 + dev_put(dev_out);
17773 + if (route_info->flags & IP6T_ROUTE_CONTINUE)
17774 + return IP6T_CONTINUE;
17776 + ip_direct_send(skb);
17777 + return NF_STOLEN;
17783 +static unsigned int
17784 +route6_gw(const struct ip6t_route_target_info *route_info,
17785 + struct sk_buff *skb)
17787 + if (route6(skb, 0, route_info)) {
17788 + if (route_info->flags & IP6T_ROUTE_CONTINUE)
17789 + return IP6T_CONTINUE;
17791 + ip_direct_send(skb);
17792 + return NF_STOLEN;
17798 +static unsigned int
17799 +ip6t_route_target(struct sk_buff **pskb,
17800 + unsigned int hooknum,
17801 + const struct net_device *in,
17802 + const struct net_device *out,
17803 + const void *targinfo,
17806 + const struct ip6t_route_target_info *route_info = targinfo;
17807 + struct sk_buff *skb = *pskb;
17808 + struct in6_addr *gw = (struct in6_addr*)&route_info->gw;
17810 + if (route_info->flags & IP6T_ROUTE_CONTINUE)
17813 + /* If we are at PREROUTING or INPUT hook
17814 + * the TTL isn't decreased by the IP stack
17816 + if (hooknum == NF_IP6_PRE_ROUTING ||
17817 + hooknum == NF_IP6_LOCAL_IN) {
17819 + struct ipv6hdr *ipv6h = skb->nh.ipv6h;
17821 + if (ipv6h->hop_limit <= 1) {
17822 + /* Force OUTPUT device used as source address */
17823 + skb->dev = skb->dst->dev;
17825 + icmpv6_send(skb, ICMPV6_TIME_EXCEED,
17826 + ICMPV6_EXC_HOPLIMIT, 0, skb->dev);
17831 + ipv6h->hop_limit--;
17836 + if (route_info->oif[0])
17837 + return route6_oif(route_info, *pskb);
17839 + if (!ipv6_addr_any(gw))
17840 + return route6_gw(route_info, *pskb);
17842 + if (net_ratelimit())
17843 + DEBUGP(KERN_DEBUG "ip6t_ROUTE: no parameter !\n");
17845 + return IP6T_CONTINUE;
17850 +ip6t_route_checkentry(const char *tablename,
17851 + const struct ip6t_entry *e,
17853 + unsigned int targinfosize,
17854 + unsigned int hook_mask)
17856 + if (strcmp(tablename, "mangle") != 0) {
17857 + printk("ip6t_ROUTE: can only be called from \"mangle\" table.\n");
17861 + if (targinfosize != IP6T_ALIGN(sizeof(struct ip6t_route_target_info))) {
17862 + printk(KERN_WARNING "ip6t_ROUTE: targinfosize %u != %Zu\n",
17864 + IP6T_ALIGN(sizeof(struct ip6t_route_target_info)));
17872 +static struct ip6t_target ip6t_route_reg = {
17874 + .target = ip6t_route_target,
17875 + .checkentry = ip6t_route_checkentry,
17876 + .me = THIS_MODULE
17880 +static int __init init(void)
17882 + printk(KERN_DEBUG "registering ipv6 ROUTE target\n");
17883 + if (ip6t_register_target(&ip6t_route_reg))
17890 +static void __exit fini(void)
17892 + ip6t_unregister_target(&ip6t_route_reg);
17895 +module_init(init);
17896 +module_exit(fini);
17897 +MODULE_LICENSE("GPL");
17898 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv6/netfilter/ip6t_TRACE.c linux-2.6.6/net/ipv6/netfilter/ip6t_TRACE.c
17899 --- linux-2.6.6.org/net/ipv6/netfilter/ip6t_TRACE.c 1970-01-01 01:00:00.000000000 +0100
17900 +++ linux-2.6.6/net/ipv6/netfilter/ip6t_TRACE.c 2004-05-18 14:28:50.000000000 +0200
17902 +/* This is a module which is used for setting
17903 + * the NFC_TRACE flag in the nfcache field of an skb.
17905 +#include <linux/module.h>
17906 +#include <linux/skbuff.h>
17908 +#include <linux/netfilter_ipv6/ip6_tables.h>
17910 +MODULE_LICENSE("GPL");
17912 +static unsigned int
17913 +target(struct sk_buff **pskb,
17914 + unsigned int hooknum,
17915 + const struct net_device *in,
17916 + const struct net_device *out,
17917 + const void *targinfo,
17920 + (*pskb)->nfcache |= NFC_TRACE;
17921 + return IP6T_CONTINUE;
17925 +checkentry(const char *tablename,
17926 + const struct ip6t_entry *e,
17928 + unsigned int targinfosize,
17929 + unsigned int hook_mask)
17931 + if (targinfosize != 0) {
17932 + printk(KERN_WARNING "TRACE: targinfosize %u != 0\n",
17937 + if (strcmp(tablename, "raw") != 0) {
17938 + printk(KERN_WARNING "TRACE: can only be called from \"raw\" table, not \"%s\"\n", tablename);
17945 +static struct ip6t_target ip6t_trace_reg = {
17947 + .target = target,
17948 + .checkentry = checkentry,
17949 + .me = THIS_MODULE
17952 +static int __init init(void)
17954 + if (ip6t_register_target(&ip6t_trace_reg))
17960 +static void __exit fini(void)
17962 + ip6t_unregister_target(&ip6t_trace_reg);
17965 +module_init(init);
17966 +module_exit(fini);
17967 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv6/netfilter/ip6t_fuzzy.c linux-2.6.6/net/ipv6/netfilter/ip6t_fuzzy.c
17968 --- linux-2.6.6.org/net/ipv6/netfilter/ip6t_fuzzy.c 1970-01-01 01:00:00.000000000 +0100
17969 +++ linux-2.6.6/net/ipv6/netfilter/ip6t_fuzzy.c 2004-05-18 14:28:50.000000000 +0200
17972 + * This module implements a simple TSK FLC
17973 + * (Takagi-Sugeno-Kang Fuzzy Logic Controller) that aims
17974 + * to limit , in an adaptive and flexible way , the packet rate crossing
17975 + * a given stream . It serves as an initial and very simple (but effective)
17976 + * example of how Fuzzy Logic techniques can be applied to defeat DoS attacks.
17977 + * As a matter of fact , Fuzzy Logic can help us to insert any "behavior"
17978 + * into our code in a precise , adaptive and efficient manner.
17979 + * The goal is very similar to that of "limit" match , but using techniques of
17980 + * Fuzzy Control , that allow us to shape the transfer functions precisely ,
17981 + * avoiding over and undershoots - and stuff like that .
17984 + * 2002-08-10 Hime Aguiar e Oliveira Jr. <hime@engineer.com> : Initial version.
17985 + * 2002-08-17 : Changed to eliminate floating point operations .
17986 + * 2002-08-23 : Coding style changes .
17987 + * 2003-04-08 Maciej Soltysiak <solt@dns.toxicilms.tv> : IPv6 Port
17990 +#include <linux/module.h>
17991 +#include <linux/skbuff.h>
17992 +#include <linux/ipv6.h>
17993 +#include <linux/random.h>
17994 +#include <net/tcp.h>
17995 +#include <linux/spinlock.h>
17996 +#include <linux/netfilter_ipv6/ip6_tables.h>
17997 +#include <linux/netfilter_ipv6/ip6t_fuzzy.h>
18000 + Packet Acceptance Rate - LOW and Packet Acceptance Rate - HIGH
18001 + Expressed in percentage
18004 +#define PAR_LOW 1/100
18005 +#define PAR_HIGH 1
18007 +static spinlock_t fuzzy_lock = SPIN_LOCK_UNLOCKED;
18009 +MODULE_AUTHOR("Hime Aguiar e Oliveira Junior <hime@engineer.com>");
18010 +MODULE_DESCRIPTION("IP tables Fuzzy Logic Controller match module");
18011 +MODULE_LICENSE("GPL");
18013 +static u_int8_t mf_high(u_int32_t tx,u_int32_t mini,u_int32_t maxi)
18015 + if (tx >= maxi) return 100;
18017 + if (tx <= mini) return 0;
18019 + return ((100 * (tx-mini)) / (maxi-mini));
18022 +static u_int8_t mf_low(u_int32_t tx,u_int32_t mini,u_int32_t maxi)
18024 + if (tx <= mini) return 100;
18026 + if (tx >= maxi) return 0;
18028 + return ((100 * (maxi - tx)) / (maxi - mini));
18033 +ip6t_fuzzy_match(const struct sk_buff *pskb,
18034 + const struct net_device *in,
18035 + const struct net_device *out,
18036 + const void *matchinfo,
18039 + u_int16_t datalen,
18042 + /* From userspace */
18044 + struct ip6t_fuzzy_info *info = (struct ip6t_fuzzy_info *) matchinfo;
18046 + u_int8_t random_number;
18047 + unsigned long amount;
18048 + u_int8_t howhigh, howlow;
18051 + spin_lock_bh(&fuzzy_lock); /* Rise the lock */
18053 + info->bytes_total += pskb->len;
18054 + info->packets_total++;
18056 + info->present_time = jiffies;
18058 + if (info->present_time >= info->previous_time)
18059 + amount = info->present_time - info->previous_time;
18061 + /* There was a transition : I choose to re-sample
18062 + and keep the old acceptance rate...
18066 + info->previous_time = info->present_time;
18067 + info->bytes_total = info->packets_total = 0;
18070 + if ( amount > HZ/10) {/* More than 100 ms elapsed ... */
18072 + info->mean_rate = (u_int32_t) ((HZ * info->packets_total) \
18075 + info->previous_time = info->present_time;
18076 + info->bytes_total = info->packets_total = 0;
18078 + howhigh = mf_high(info->mean_rate,info->minimum_rate,info->maximum_rate);
18079 + howlow = mf_low(info->mean_rate,info->minimum_rate,info->maximum_rate);
18081 + info->acceptance_rate = (u_int8_t) \
18082 + (howhigh * PAR_LOW + PAR_HIGH * howlow);
18084 + /* In fact, the above defuzzification would require a denominator
18085 + * proportional to (howhigh+howlow) but, in this particular case,
18086 + * that expression is constant.
18087 + * An imediate consequence is that it is not necessary to call
18088 + * both mf_high and mf_low - but to keep things understandable,
18094 + spin_unlock_bh(&fuzzy_lock); /* Release the lock */
18097 + if (info->acceptance_rate < 100)
18099 + get_random_bytes((void *)(&random_number), 1);
18101 + /* If within the acceptance , it can pass => don't match */
18102 + if (random_number <= (255 * info->acceptance_rate) / 100)
18105 + return 1; /* It can't pass (It matches) */
18108 + return 0; /* acceptance_rate == 100 % => Everything passes ... */
18113 +ip6t_fuzzy_checkentry(const char *tablename,
18114 + const struct ip6t_ip6 *ip,
18116 + unsigned int matchsize,
18117 + unsigned int hook_mask)
18120 + const struct ip6t_fuzzy_info *info = matchinfo;
18122 + if (matchsize != IP6T_ALIGN(sizeof(struct ip6t_fuzzy_info))) {
18123 + printk("ip6t_fuzzy: matchsize %u != %u\n", matchsize,
18124 + IP6T_ALIGN(sizeof(struct ip6t_fuzzy_info)));
18128 + if ((info->minimum_rate < MINFUZZYRATE) || (info->maximum_rate > MAXFUZZYRATE)
18129 + || (info->minimum_rate >= info->maximum_rate)) {
18130 + printk("ip6t_fuzzy: BAD limits , please verify !!!\n");
18137 +static struct ip6t_match ip6t_fuzzy_reg = {
18140 + ip6t_fuzzy_match,
18141 + ip6t_fuzzy_checkentry,
18145 +static int __init init(void)
18147 + if (ip6t_register_match(&ip6t_fuzzy_reg))
18153 +static void __exit fini(void)
18155 + ip6t_unregister_match(&ip6t_fuzzy_reg);
18158 +module_init(init);
18159 +module_exit(fini);
18160 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv6/netfilter/ip6t_nth.c linux-2.6.6/net/ipv6/netfilter/ip6t_nth.c
18161 --- linux-2.6.6.org/net/ipv6/netfilter/ip6t_nth.c 1970-01-01 01:00:00.000000000 +0100
18162 +++ linux-2.6.6/net/ipv6/netfilter/ip6t_nth.c 2004-05-18 14:28:50.000000000 +0200
18165 + This is a module which is used for match support for every Nth packet
18166 + This file is distributed under the terms of the GNU General Public
18167 + License (GPL). Copies of the GPL can be obtained from:
18168 + ftp://prep.ai.mit.edu/pub/gnu/GPL
18170 + 2001-07-18 Fabrice MARIE <fabrice@netfilter.org> : initial implementation.
18171 + 2001-09-20 Richard Wagner (rwagner@cloudnet.com)
18172 + * added support for multiple counters
18173 + * added support for matching on individual packets
18174 + in the counter cycle
18175 + 2003-04-30 Maciej Soltysiak <solt@dns.toxicfilms.tv> : IPv6 Port
18179 +#include <linux/module.h>
18180 +#include <linux/skbuff.h>
18181 +#include <linux/ip.h>
18182 +#include <net/tcp.h>
18183 +#include <linux/spinlock.h>
18184 +#include <linux/netfilter_ipv6/ip6_tables.h>
18185 +#include <linux/netfilter_ipv6/ip6t_nth.h>
18187 +MODULE_LICENSE("GPL");
18190 + * State information.
18194 + u_int16_t number;
18197 +static struct state states[IP6T_NTH_NUM_COUNTERS];
18200 +ip6t_nth_match(const struct sk_buff *pskb,
18201 + const struct net_device *in,
18202 + const struct net_device *out,
18203 + const void *matchinfo,
18206 + u_int16_t datalen,
18209 + /* Parameters from userspace */
18210 + const struct ip6t_nth_info *info = matchinfo;
18211 + unsigned counter = info->counter;
18212 + if((counter < 0) || (counter >= IP6T_NTH_NUM_COUNTERS))
18214 + printk(KERN_WARNING "nth: invalid counter %u. counter between 0 and %u\n", counter, IP6T_NTH_NUM_COUNTERS-1);
18218 + spin_lock(&states[counter].lock);
18220 + /* Are we matching every nth packet?*/
18221 + if (info->packet == 0xFF)
18223 + /* We're matching every nth packet and only every nth packet*/
18224 + /* Do we match or invert match? */
18225 + if (info->not == 0)
18227 + if (states[counter].number == 0)
18229 + ++states[counter].number;
18232 + if (states[counter].number >= info->every)
18233 + states[counter].number = 0; /* reset the counter */
18235 + ++states[counter].number;
18240 + if (states[counter].number == 0)
18242 + ++states[counter].number;
18245 + if (states[counter].number >= info->every)
18246 + states[counter].number = 0;
18248 + ++states[counter].number;
18254 + /* We're using the --packet, so there must be a rule for every value */
18255 + if (states[counter].number == info->packet)
18257 + /* only increment the counter when a match happens */
18258 + if (states[counter].number >= info->every)
18259 + states[counter].number = 0; /* reset the counter */
18261 + ++states[counter].number;
18269 + /* don't match */
18270 + spin_unlock(&states[counter].lock);
18274 + spin_unlock(&states[counter].lock);
18279 +ip6t_nth_checkentry(const char *tablename,
18280 + const struct ip6t_ip6 *e,
18282 + unsigned int matchsize,
18283 + unsigned int hook_mask)
18285 + /* Parameters from userspace */
18286 + const struct ip6t_nth_info *info = matchinfo;
18287 + unsigned counter = info->counter;
18288 + if((counter < 0) || (counter >= IP6T_NTH_NUM_COUNTERS))
18290 + printk(KERN_WARNING "nth: invalid counter %u. counter between 0 and %u\n", counter, IP6T_NTH_NUM_COUNTERS-1);
18294 + if (matchsize != IP6T_ALIGN(sizeof(struct ip6t_nth_info))) {
18295 + printk("nth: matchsize %u != %u\n", matchsize,
18296 + IP6T_ALIGN(sizeof(struct ip6t_nth_info)));
18300 + states[counter].number = info->startat;
18305 +static struct ip6t_match ip6t_nth_reg = {
18309 + ip6t_nth_checkentry,
18313 +static int __init init(void)
18315 + unsigned counter;
18316 + memset(&states, 0, sizeof(states));
18317 + if (ip6t_register_match(&ip6t_nth_reg))
18320 + for(counter = 0; counter < IP6T_NTH_NUM_COUNTERS; counter++)
18322 + spin_lock_init(&(states[counter].lock));
18325 + printk("ip6t_nth match loaded\n");
18329 +static void __exit fini(void)
18331 + ip6t_unregister_match(&ip6t_nth_reg);
18332 + printk("ip6t_nth match unloaded\n");
18335 +module_init(init);
18336 +module_exit(fini);
18337 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv6/netfilter/ip6t_owner.c linux-2.6.6/net/ipv6/netfilter/ip6t_owner.c
18338 --- linux-2.6.6.org/net/ipv6/netfilter/ip6t_owner.c 2004-05-10 04:33:13.000000000 +0200
18339 +++ linux-2.6.6/net/ipv6/netfilter/ip6t_owner.c 2004-05-18 14:28:50.000000000 +0200
18341 MODULE_LICENSE("GPL");
18344 +match_comm(const struct sk_buff *skb, const char *comm)
18346 + struct task_struct *p, *g;
18347 + struct files_struct *files;
18350 + read_lock(&tasklist_lock);
18351 + do_each_thread(g, p) {
18352 + if(strncmp(p->comm, comm, sizeof(p->comm)))
18356 + files = p->files;
18358 + read_lock(&files->file_lock);
18359 + for (i=0; i < files->max_fds; i++) {
18360 + if (fcheck_files(files, i) ==
18361 + skb->sk->sk_socket->file) {
18362 + read_unlock(&files->file_lock);
18364 + read_unlock(&tasklist_lock);
18368 + read_unlock(&files->file_lock);
18371 + } while_each_thread(g, p);
18372 + read_unlock(&tasklist_lock);
18377 match_pid(const struct sk_buff *skb, pid_t pid)
18379 struct task_struct *p;
18380 @@ -125,6 +158,12 @@
18384 + if(info->match & IP6T_OWNER_COMM) {
18385 + if (!match_comm(skb, info->comm) ^
18386 + !!(info->invert & IP6T_OWNER_COMM))
18393 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv6/netfilter/ip6t_policy.c linux-2.6.6/net/ipv6/netfilter/ip6t_policy.c
18394 --- linux-2.6.6.org/net/ipv6/netfilter/ip6t_policy.c 1970-01-01 01:00:00.000000000 +0100
18395 +++ linux-2.6.6/net/ipv6/netfilter/ip6t_policy.c 2004-05-18 14:28:50.000000000 +0200
18397 +/* IP tables module for matching IPsec policy
18399 + * Copyright (c) 2004 Patrick McHardy, <kaber@trash.net>
18401 + * This program is free software; you can redistribute it and/or modify
18402 + * it under the terms of the GNU General Public License version 2 as
18403 + * published by the Free Software Foundation.
18406 +#include <linux/kernel.h>
18407 +#include <linux/config.h>
18408 +#include <linux/module.h>
18409 +#include <linux/skbuff.h>
18410 +#include <linux/init.h>
18411 +#include <net/xfrm.h>
18413 +#include <linux/netfilter_ipv6.h>
18414 +#include <linux/netfilter_ipv6/ip6t_policy.h>
18415 +#include <linux/netfilter_ipv6/ip6_tables.h>
18417 +MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
18418 +MODULE_DESCRIPTION("IPtables IPsec policy matching module");
18419 +MODULE_LICENSE("GPL");
18422 +static inline int ip6_masked_addrcmp(struct in6_addr addr1,
18423 + struct in6_addr mask,
18424 + struct in6_addr addr2)
18428 + for (i = 0; i < 16; i++) {
18429 + if ((addr1.s6_addr[i] & mask.s6_addr[i]) !=
18430 + (addr2.s6_addr[i] & mask.s6_addr[i]))
18438 +match_xfrm_state(struct xfrm_state *x, const struct ip6t_policy_elem *e)
18440 +#define MISMATCH(x,y) (e->match.x && ((e->x != (y)) ^ e->invert.x))
18442 + struct in6_addr xfrm_saddr, xfrm_daddr;
18444 + if ((e->match.saddr
18445 + && (ip6_masked_addrcmp(xfrm_saddr, e->saddr, e->smask))
18446 + ^ e->invert.saddr ) ||
18448 + && (ip6_masked_addrcmp(xfrm_daddr, e->daddr, e->dmask))
18449 + ^ e->invert.daddr ) ||
18450 + MISMATCH(proto, x->id.proto) ||
18451 + MISMATCH(mode, x->props.mode) ||
18452 + MISMATCH(spi, x->id.spi) ||
18453 + MISMATCH(reqid, x->props.reqid))
18459 +match_policy_in(const struct sk_buff *skb, const struct ip6t_policy_info *info)
18461 + const struct ip6t_policy_elem *e;
18462 + struct sec_path *sp = skb->sp;
18463 + int strict = info->flags & POLICY_MATCH_STRICT;
18468 + if (strict && info->len != sp->len)
18471 + for (i = sp->len - 1; i >= 0; i--) {
18472 + pos = strict ? i - sp->len + 1 : 0;
18473 + if (pos >= info->len)
18475 + e = &info->pol[pos];
18477 + if (match_xfrm_state(sp->x[i].xvec, e)) {
18480 + } else if (strict)
18484 + return strict ? 1 : 0;
18488 +match_policy_out(const struct sk_buff *skb, const struct ip6t_policy_info *info)
18490 + const struct ip6t_policy_elem *e;
18491 + struct dst_entry *dst = skb->dst;
18492 + int strict = info->flags & POLICY_MATCH_STRICT;
18495 + if (dst->xfrm == NULL)
18498 + for (i = 0; dst && dst->xfrm; dst = dst->child, i++) {
18499 + pos = strict ? i : 0;
18500 + if (pos >= info->len)
18502 + e = &info->pol[pos];
18504 + if (match_xfrm_state(dst->xfrm, e)) {
18507 + } else if (strict)
18511 + return strict ? 1 : 0;
18514 +static int match(const struct sk_buff *skb,
18515 + const struct net_device *in,
18516 + const struct net_device *out,
18517 + const void *matchinfo,
18520 + u_int16_t datalen,
18523 + const struct ip6t_policy_info *info = matchinfo;
18526 + if (info->flags & POLICY_MATCH_IN)
18527 + ret = match_policy_in(skb, info);
18529 + ret = match_policy_out(skb, info);
18532 + if (info->flags & POLICY_MATCH_NONE)
18536 + } else if (info->flags & POLICY_MATCH_NONE)
18542 +static int checkentry(const char *tablename, const struct ip6t_ip6 *ip,
18543 + void *matchinfo, unsigned int matchsize,
18544 + unsigned int hook_mask)
18546 + struct ip6t_policy_info *info = matchinfo;
18548 + if (matchsize != IP6T_ALIGN(sizeof(*info))) {
18549 + printk(KERN_ERR "ip6t_policy: matchsize %u != %u\n",
18550 + matchsize, IP6T_ALIGN(sizeof(*info)));
18553 + if (!(info->flags & (POLICY_MATCH_IN|POLICY_MATCH_OUT))) {
18554 + printk(KERN_ERR "ip6t_policy: neither incoming nor "
18555 + "outgoing policy selected\n");
18558 + if (hook_mask & (1 << NF_IP6_PRE_ROUTING | 1 << NF_IP6_LOCAL_IN)
18559 + && info->flags & POLICY_MATCH_OUT) {
18560 + printk(KERN_ERR "ip6t_policy: output policy not valid in "
18561 + "PRE_ROUTING and INPUT\n");
18564 + if (hook_mask & (1 << NF_IP6_POST_ROUTING | 1 << NF_IP6_LOCAL_OUT)
18565 + && info->flags & POLICY_MATCH_IN) {
18566 + printk(KERN_ERR "ip6t_policy: input policy not valid in "
18567 + "POST_ROUTING and OUTPUT\n");
18570 + if (info->len > POLICY_MAX_ELEM) {
18571 + printk(KERN_ERR "ip6t_policy: too many policy elements\n");
18578 +static struct ip6t_match policy_match =
18580 + .name = "policy",
18582 + .checkentry = checkentry,
18583 + .me = THIS_MODULE,
18586 +static int __init init(void)
18588 + return ip6t_register_match(&policy_match);
18591 +static void __exit fini(void)
18593 + ip6t_unregister_match(&policy_match);
18596 +module_init(init);
18597 +module_exit(fini);
18598 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv6/netfilter/ip6t_random.c linux-2.6.6/net/ipv6/netfilter/ip6t_random.c
18599 --- linux-2.6.6.org/net/ipv6/netfilter/ip6t_random.c 1970-01-01 01:00:00.000000000 +0100
18600 +++ linux-2.6.6/net/ipv6/netfilter/ip6t_random.c 2004-05-18 14:28:50.000000000 +0200
18603 + This is a module which is used for a "random" match support.
18604 + This file is distributed under the terms of the GNU General Public
18605 + License (GPL). Copies of the GPL can be obtained from:
18606 + ftp://prep.ai.mit.edu/pub/gnu/GPL
18608 + 2001-10-14 Fabrice MARIE <fabrice@netfilter.org> : initial implementation.
18609 + 2003-04-30 Maciej Soltysiak <solt@dns.toxicfilms.tv> : IPv6 Port
18612 +#include <linux/module.h>
18613 +#include <linux/skbuff.h>
18614 +#include <linux/ip.h>
18615 +#include <linux/random.h>
18616 +#include <net/tcp.h>
18617 +#include <linux/spinlock.h>
18618 +#include <linux/netfilter_ipv6/ip6_tables.h>
18619 +#include <linux/netfilter_ipv6/ip6t_random.h>
18621 +MODULE_LICENSE("GPL");
18624 +ip6t_rand_match(const struct sk_buff *pskb,
18625 + const struct net_device *in,
18626 + const struct net_device *out,
18627 + const void *matchinfo,
18630 + u_int16_t datalen,
18633 + /* Parameters from userspace */
18634 + const struct ip6t_rand_info *info = matchinfo;
18635 + u_int8_t random_number;
18637 + /* get 1 random number from the kernel random number generation routine */
18638 + get_random_bytes((void *)(&random_number), 1);
18640 + /* Do we match ? */
18641 + if (random_number <= info->average)
18648 +ip6t_rand_checkentry(const char *tablename,
18649 + const struct ip6t_ip6 *e,
18651 + unsigned int matchsize,
18652 + unsigned int hook_mask)
18654 + /* Parameters from userspace */
18655 + const struct ip6t_rand_info *info = matchinfo;
18657 + if (matchsize != IP6T_ALIGN(sizeof(struct ip6t_rand_info))) {
18658 + printk("ip6t_random: matchsize %u != %u\n", matchsize,
18659 + IP6T_ALIGN(sizeof(struct ip6t_rand_info)));
18663 + /* must be 1 <= average % <= 99 */
18664 + /* 1 x 2.55 = 2 */
18665 + /* 99 x 2.55 = 252 */
18666 + if ((info->average < 2) || (info->average > 252)) {
18667 + printk("ip6t_random: invalid average %u\n", info->average);
18674 +static struct ip6t_match ip6t_rand_reg = {
18678 + ip6t_rand_checkentry,
18682 +static int __init init(void)
18684 + if (ip6t_register_match(&ip6t_rand_reg))
18687 + printk("ip6t_random match loaded\n");
18691 +static void __exit fini(void)
18693 + ip6t_unregister_match(&ip6t_rand_reg);
18694 + printk("ip6t_random match unloaded\n");
18697 +module_init(init);
18698 +module_exit(fini);
18699 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv6/netfilter/ip6table_filter.c linux-2.6.6/net/ipv6/netfilter/ip6table_filter.c
18700 --- linux-2.6.6.org/net/ipv6/netfilter/ip6table_filter.c 2004-05-10 04:32:00.000000000 +0200
18701 +++ linux-2.6.6/net/ipv6/netfilter/ip6table_filter.c 2004-05-18 14:28:50.000000000 +0200
18704 sizeof(struct ip6t_entry),
18705 sizeof(struct ip6t_standard),
18706 - 0, { 0, 0 }, { } },
18707 + 0, NULL, 0, { 0, 0 }, { } },
18708 { { { { IP6T_ALIGN(sizeof(struct ip6t_standard_target)), "" } }, { } },
18709 -NF_ACCEPT - 1 } },
18713 sizeof(struct ip6t_entry),
18714 sizeof(struct ip6t_standard),
18715 - 0, { 0, 0 }, { } },
18716 + 0, NULL, 0, { 0, 0 }, { } },
18717 { { { { IP6T_ALIGN(sizeof(struct ip6t_standard_target)), "" } }, { } },
18718 -NF_ACCEPT - 1 } },
18722 sizeof(struct ip6t_entry),
18723 sizeof(struct ip6t_standard),
18724 - 0, { 0, 0 }, { } },
18725 + 0, NULL, 0, { 0, 0 }, { } },
18726 { { { { IP6T_ALIGN(sizeof(struct ip6t_standard_target)), "" } }, { } },
18731 sizeof(struct ip6t_entry),
18732 sizeof(struct ip6t_error),
18733 - 0, { 0, 0 }, { } },
18734 + 0, NULL, 0, { 0, 0 }, { } },
18735 { { { { IP6T_ALIGN(sizeof(struct ip6t_error_target)), IP6T_ERROR_TARGET } },
18738 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv6/netfilter/ip6table_mangle.c linux-2.6.6/net/ipv6/netfilter/ip6table_mangle.c
18739 --- linux-2.6.6.org/net/ipv6/netfilter/ip6table_mangle.c 2004-05-10 04:32:28.000000000 +0200
18740 +++ linux-2.6.6/net/ipv6/netfilter/ip6table_mangle.c 2004-05-18 14:28:50.000000000 +0200
18743 sizeof(struct ip6t_entry),
18744 sizeof(struct ip6t_standard),
18745 - 0, { 0, 0 }, { } },
18746 + 0, NULL, 0, { 0, 0 }, { } },
18747 { { { { IP6T_ALIGN(sizeof(struct ip6t_standard_target)), "" } }, { } },
18748 -NF_ACCEPT - 1 } },
18752 sizeof(struct ip6t_entry),
18753 sizeof(struct ip6t_standard),
18754 - 0, { 0, 0 }, { } },
18755 + 0, NULL, 0, { 0, 0 }, { } },
18756 { { { { IP6T_ALIGN(sizeof(struct ip6t_standard_target)), "" } }, { } },
18757 -NF_ACCEPT - 1 } },
18761 sizeof(struct ip6t_entry),
18762 sizeof(struct ip6t_standard),
18763 - 0, { 0, 0 }, { } },
18764 + 0, NULL, 0, { 0, 0 }, { } },
18765 { { { { IP6T_ALIGN(sizeof(struct ip6t_standard_target)), "" } }, { } },
18766 -NF_ACCEPT - 1 } },
18770 sizeof(struct ip6t_entry),
18771 sizeof(struct ip6t_standard),
18772 - 0, { 0, 0 }, { } },
18773 + 0, NULL, 0, { 0, 0 }, { } },
18774 { { { { IP6T_ALIGN(sizeof(struct ip6t_standard_target)), "" } }, { } },
18775 -NF_ACCEPT - 1 } },
18777 @@ -105,7 +105,7 @@
18779 sizeof(struct ip6t_entry),
18780 sizeof(struct ip6t_standard),
18781 - 0, { 0, 0 }, { } },
18782 + 0, NULL, 0, { 0, 0 }, { } },
18783 { { { { IP6T_ALIGN(sizeof(struct ip6t_standard_target)), "" } }, { } },
18786 @@ -114,7 +114,7 @@
18788 sizeof(struct ip6t_entry),
18789 sizeof(struct ip6t_error),
18790 - 0, { 0, 0 }, { } },
18791 + 0, NULL, 0, { 0, 0 }, { } },
18792 { { { { IP6T_ALIGN(sizeof(struct ip6t_error_target)), IP6T_ERROR_TARGET } },
18795 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv6/netfilter/ip6table_raw.c linux-2.6.6/net/ipv6/netfilter/ip6table_raw.c
18796 --- linux-2.6.6.org/net/ipv6/netfilter/ip6table_raw.c 2004-05-10 04:32:53.000000000 +0200
18797 +++ linux-2.6.6/net/ipv6/netfilter/ip6table_raw.c 2004-05-18 14:28:50.000000000 +0200
18800 sizeof(struct ip6t_entry),
18801 sizeof(struct ip6t_standard),
18802 - 0, { 0, 0 }, { } },
18803 + 0, NULL, 0, { 0, 0 }, { } },
18804 { { { { IP6T_ALIGN(sizeof(struct ip6t_standard_target)), "" } }, { } },
18805 -NF_ACCEPT - 1 } },
18809 sizeof(struct ip6t_entry),
18810 sizeof(struct ip6t_standard),
18811 - 0, { 0, 0 }, { } },
18812 + 0, NULL, 0, { 0, 0 }, { } },
18813 { { { { IP6T_ALIGN(sizeof(struct ip6t_standard_target)), "" } }, { } },
18814 -NF_ACCEPT - 1 } },
18818 sizeof(struct ip6t_entry),
18819 sizeof(struct ip6t_error),
18820 - 0, { 0, 0 }, { } },
18821 + 0, NULL, 0, { 0, 0 }, { } },
18822 { { { { IP6T_ALIGN(sizeof(struct ip6t_error_target)), IP6T_ERROR_TARGET } },
18825 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/ipv6/sit.c linux-2.6.6/net/ipv6/sit.c
18826 --- linux-2.6.6.org/net/ipv6/sit.c 2004-05-10 04:33:20.000000000 +0200
18827 +++ linux-2.6.6/net/ipv6/sit.c 2004-05-18 14:28:50.000000000 +0200
18828 @@ -388,13 +388,7 @@
18829 skb->dev = tunnel->dev;
18830 dst_release(skb->dst);
18832 -#ifdef CONFIG_NETFILTER
18833 - nf_conntrack_put(skb->nfct);
18834 - skb->nfct = NULL;
18835 -#ifdef CONFIG_NETFILTER_DEBUG
18836 - skb->nf_debug = 0;
18840 ipip6_ecn_decapsulate(iph, skb);
18842 read_unlock(&ipip6_lock);
18843 @@ -580,13 +574,7 @@
18844 if ((iph->ttl = tiph->ttl) == 0)
18845 iph->ttl = iph6->hop_limit;
18847 -#ifdef CONFIG_NETFILTER
18848 - nf_conntrack_put(skb->nfct);
18849 - skb->nfct = NULL;
18850 -#ifdef CONFIG_NETFILTER_DEBUG
18851 - skb->nf_debug = 0;
18857 tunnel->recursion--;
18858 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/xfrm/xfrm_input.c linux-2.6.6/net/xfrm/xfrm_input.c
18859 --- linux-2.6.6.org/net/xfrm/xfrm_input.c 2004-05-10 04:31:59.000000000 +0200
18860 +++ linux-2.6.6/net/xfrm/xfrm_input.c 2004-05-18 14:28:50.000000000 +0200
18865 +#ifdef CONFIG_NETFILTER
18866 + sp->decap_done = 0;
18871 diff -Nur --exclude '*.orig' linux-2.6.6.org/net/xfrm/xfrm_policy.c linux-2.6.6/net/xfrm/xfrm_policy.c
18872 --- linux-2.6.6.org/net/xfrm/xfrm_policy.c 2004-05-10 04:32:37.000000000 +0200
18873 +++ linux-2.6.6/net/xfrm/xfrm_policy.c 2004-05-18 14:28:50.000000000 +0200
18875 #include <linux/workqueue.h>
18876 #include <linux/notifier.h>
18877 #include <linux/netdevice.h>
18878 +#include <linux/netfilter.h>
18879 #include <net/xfrm.h>
18880 #include <net/ip.h>
18882 @@ -908,6 +909,7 @@
18884 if (_decode_session(skb, &fl, family) < 0)
18886 + nf_nat_decode_session(skb, &fl, family);
18888 /* First, check used SA against their selectors. */