diff -urN iptables-1.3.8.orig/extensions/libip6t_tproxy.man iptables-1.3.8/extensions/libip6t_tproxy.man
--- iptables-1.3.8.orig/extensions/libip6t_tproxy.man	1970-01-01 01:00:00.000000000 +0100
+++ iptables-1.3.8/extensions/libip6t_tproxy.man	2007-09-04 09:16:31.000000000 +0200
@@ -0,0 +1 @@
+This module matches the mark set by TPROXY target.
diff -urN iptables-1.3.8.orig/extensions/libipt_tproxy.c iptables-1.3.8/extensions/libipt_tproxy.c
--- iptables-1.3.8.orig/extensions/libipt_tproxy.c	1970-01-01 01:00:00.000000000 +0100
+++ iptables-1.3.8/extensions/libipt_tproxy.c	2007-09-04 09:47:57.000000000 +0200
@@ -0,0 +1,77 @@
+/* Shared library add-on to iptables to add tproxy matching support. */
+#include <stdio.h>
+#include <netdb.h>
+#include <string.h>
+#include <stdlib.h>
+#include <getopt.h>
+#include <iptables.h>
+
+/* Function which prints out usage message. */
+static void
+help(void)
+{
+	printf(
+"tproxy match v%s:\n"
+"\tmatched if a packet is marked by the TPROXY target.\n\n",
+IPTABLES_VERSION);
+}
+
+static struct option opts[] = {
+	{0}
+};
+
+/* Initialize the match. */
+static void
+init(struct ipt_entry_match *m, unsigned int *nfcache)
+{
+	/* Can't cache this */
+	*nfcache |= NFC_UNKNOWN;
+}
+
+/* Function which parses command options; returns true if it
+   ate an option */
+static int
+parse(int c, char **argv, int invert, unsigned int *flags,
+      const struct ipt_entry *entry,
+      unsigned int *nfcache,
+      struct ipt_entry_match **match)
+{
+	return 0;
+}
+
+static void 
+final_check(unsigned int flags)
+{
+}
+
+static void
+print(const struct ipt_ip *ip,
+      const struct ipt_entry_match *match,
+      int numeric)
+{
+	printf("tproxy ");
+}
+
+static void 
+save(const struct ipt_ip *ip, const struct ipt_entry_match *match)
+{
+}
+
+static struct iptables_match tproxy = {
+	.name          = "tproxy",
+	.version       = IPTABLES_VERSION,
+	.size          = 0, 
+	.userspacesize = 0, 
+	.help          = &help,
+	.init          = &init,
+	.parse         = &parse,
+	.final_check   = &final_check,
+	.print         = &print,
+	.save          = &save,
+	.extra_opts    = &opts,
+};
+
+void _init(void)
+{
+	register_match(&tproxy);
+}
diff -urN iptables-1.3.8.orig/extensions/libipt_TPROXY.c iptables-1.3.8/extensions/libipt_TPROXY.c
--- iptables-1.3.8.orig/extensions/libipt_TPROXY.c	1970-01-01 01:00:00.000000000 +0100
+++ iptables-1.3.8/extensions/libipt_TPROXY.c	2007-09-04 09:40:37.000000000 +0200
@@ -0,0 +1,112 @@
+/* Shared library add-on to iptables to add TPROXY target support.
+ *
+ * Copyright (C) 2002-2007 BalaBit IT Ltd.
+ */
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <getopt.h>
+
+#include <iptables.h>
+#include <linux/netfilter_ipv4/ip_tables.h>
+#include <linux/netfilter/xt_TPROXY.h>
+
+static const struct option tproxy_opts[] = {
+	{"on-port", 1, NULL, '1'},
+	{"on-ip",   1, NULL, '2'},
+	{NULL},
+};
+
+static void tproxy_help(void)
+{
+	printf(
+"TPROXY target v%s options:\n"
+"  --on-port port                   Redirect connection to port, or the original port if 0\n"
+"  --on-ip ip                       Optionally redirect to the given IP\n",
+IPTABLES_VERSION);
+}
+
+static void parse_tproxy_lport(const char *s, struct xt_tproxy_target_info *info)
+{
+	unsigned int lport;
+
+	if (string_to_number(s, 0, 65535, &lport) != -1)
+	        info->lport = htons(lport);
+	else
+	        exit_error(PARAMETER_PROBLEM, "bad --on-proxy `%s'", s);
+}
+
+static void parse_tproxy_laddr(const char *s, struct xt_tproxy_target_info *info)
+{
+	struct in_addr *laddr;
+
+	if ((laddr = dotted_to_addr(s)) == NULL)
+	        exit_error(PARAMETER_PROBLEM, "bad --on-ip `%s'", s);
+ 	info->laddr = laddr->s_addr;
+}
+
+static int tproxy_parse(int c, char **argv, int invert, unsigned int *flags,
+                        const void *entry, struct ipt_entry_target **target)
+{
+	struct xt_tproxy_target_info *tproxyinfo = (void *)(*target)->data;
+
+	switch (c) {
+	case '1':
+		if (*flags != 0)
+			exit_error(PARAMETER_PROBLEM,
+				"TPROXY target: Can't specify --to-port twice");
+		parse_tproxy_lport(optarg, tproxyinfo);
+		*flags = 1;
+		break;
+	case '2':
+		parse_tproxy_laddr(optarg, tproxyinfo);
+		break;
+	default:
+		return 0;
+	}
+
+	return 1;
+}
+
+static void tproxy_check(unsigned int flags)
+{
+	if (flags == 0)
+		exit_error(PARAMETER_PROBLEM,
+		           "TPROXY target: Parameter --on-port is required");
+}
+
+static void tproxy_print(const void *ip, const struct ipt_entry_target *target,
+                         int numeric)
+{
+	const struct xt_tproxy_target_info *tproxyinfo = (const void *)target->data;
+	printf("TPROXY redirect %s:%d",
+	       addr_to_dotted((const struct in_addr *)&tproxyinfo->laddr),
+	       ntohs(tproxyinfo->lport));
+}
+
+static void tproxy_save(const void *ip, const struct ipt_entry_target *target)
+{
+	const struct xt_tproxy_target_info *tproxyinfo = (const void *)target->data;
+
+	printf("--on-port %d ", ntohs(tproxyinfo->lport));
+	printf("--on-ip %s ",
+	       addr_to_dotted((const struct in_addr *)&tproxyinfo->laddr));
+}
+
+static struct iptables_target tproxy_reg = {
+	.name          = "TPROXY",
+	.version       = IPTABLES_VERSION,
+	.size          = IPT_ALIGN(sizeof(struct xt_tproxy_target_info)),
+	.userspacesize = IPT_ALIGN(sizeof(struct xt_tproxy_target_info)),
+	.help          = &tproxy_help,
+	.parse         = &tproxy_parse,
+	.final_check   = &tproxy_check,
+	.print         = &tproxy_print,
+	.save          = &tproxy_save,
+	.extra_opts    = &tproxy_opts,
+};
+											
+void _init(void)
+{
+	register_target(&tproxy_reg);
+}
diff -urN iptables-1.3.8.orig/extensions/libipt_tproxy.man iptables-1.3.8/extensions/libipt_tproxy.man
--- iptables-1.3.8.orig/extensions/libipt_tproxy.man	1970-01-01 01:00:00.000000000 +0100
+++ iptables-1.3.8/extensions/libipt_tproxy.man	2007-09-04 09:16:31.000000000 +0200
@@ -0,0 +1 @@
+This module matches the mark set by TPROXY target.
diff -urN iptables-1.3.8.orig/extensions/libipt_TPROXY.man iptables-1.3.8/extensions/libipt_TPROXY.man
--- iptables-1.3.8.orig/extensions/libipt_TPROXY.man	1970-01-01 01:00:00.000000000 +0100
+++ iptables-1.3.8/extensions/libipt_TPROXY.man	2007-09-04 09:16:31.000000000 +0200
@@ -0,0 +1,26 @@
+This target is only valid in the
+.B nat
+table, in the
+.B PREROUTING
+chain, and user-defined chains which are only called from that
+chain.  It redirects the packet to the machine itself by changing its
+routing but without changing the packets themselves. It marks the
+packets for the tproxy match. It takes two options:
+.TP
+.BR "--on-port " "\fIport\fP"
+This specifies a destination port to use. It is a required option, 0
+means the new destination port is the same as the original. This is
+only valid if the rule also specifies
+.B "-p tcp"
+or
+.BR "-p udp" .
+.TP
+.BR "--on-ip " "\fIaddress\fP"
+This specifies a destination address to use. By default the address is
+the IP address of the incoming interface. This is only valid if the
+rule also specifies
+.B "-p tcp"
+or
+.BR "-p udp" .
+.RS
+.PP
diff -urN iptables-1.3.8.orig/extensions/.tproxy-test iptables-1.3.8/extensions/.tproxy-test
--- iptables-1.3.8.orig/extensions/.tproxy-test	1970-01-01 01:00:00.000000000 +0100
+++ iptables-1.3.8/extensions/.tproxy-test	2007-09-03 15:20:41.000000000 +0200
@@ -0,0 +1,3 @@
+#!/bin/sh
+[ -f $KERNEL_DIR/include/linux/netfilter/xt_TPROXY.h ] && 
+    echo TPROXY && echo tproxy
