diff -Naur linux-2.6.18.1/include/linux/netfilter_ipv4/ip_conntrack.h linux-2.6.18.1-new/include/linux/netfilter_ipv4/ip_conntrack.h
--- linux-2.6.18.1/include/linux/netfilter_ipv4/ip_conntrack.h	2007-11-06 21:42:38.000000000 +0530
+++ linux-2.6.18.1-new/include/linux/netfilter_ipv4/ip_conntrack.h	2007-11-06 21:36:53.000000000 +0530
@@ -120,6 +120,8 @@
 		void *sockref;
 		struct list_head related;
 	} tproxy;
+	unsigned long tproxyBit;
+        u32 tproxyFaddr;
 #endif /* CONFIG_IP_NF_TPROXY */
 
 #endif /* CONFIG_IP_NF_NAT_NEEDED */
diff -Naur linux-2.6.18.1/include/linux/netfilter_ipv4/ip_tproxy.h linux-2.6.18.1-new/include/linux/netfilter_ipv4/ip_tproxy.h
--- linux-2.6.18.1/include/linux/netfilter_ipv4/ip_tproxy.h	2007-11-06 21:42:28.000000000 +0530
+++ linux-2.6.18.1-new/include/linux/netfilter_ipv4/ip_tproxy.h	2007-11-06 21:36:53.000000000 +0530
@@ -74,5 +74,60 @@
 	} v;
 };
 
+#ifdef __KERNEL__
+struct ip_tproxy_sockref;
+
+struct ip_tproxy_hash
+{
+	struct list_head list;
+	struct ip_tproxy_sockref *sockref;
+};
+
+struct ip_tproxy_sockref
+{
+	int flags;
+	atomic_t references;
+
+	u8 proto;
+
+	/* foreign address associated with a local socket */
+	u32 faddr;
+	u16 fport;
+
+	/* local socket address */
+	u32 laddr;
+	u16 lport;
+
+	/* remote addresses, needed for datagram protocols when the peer
+	 * sends the packet triggering the NAT translation. (as there might
+	 * be multiple sockrefs on the same foreign address).
+	 */
+	u32 raddr;
+	u16 rport;
+
+	/* hash chains indexed by local and foreign addresses */
+	struct ip_tproxy_hash bylocal, byforeign;
+
+	/* lock protecting access to related list */
+	spinlock_t relatedlock;
+	/* number of related connections */
+	atomic_t related;
+	/* list of related connections */
+	struct list_head relatedct;
+
+	/* socket which we were assigned to */
+	struct sock *assigned_to;
+
+	/* How many sockets use this sockref? Used for mark-only sockrefs,
+	 * which can be shared between multiple sockets bound to the same local
+	 * address */
+	atomic_t socket_count;
+
+	/* when was this entry inserted in hash */
+	struct timespec tv_hashed;
+};
+#endif //__KERNEL__
+
+
 #endif
 
diff -Naur linux-2.6.18.1/net/ipv4/netfilter/ip_tables.c linux-2.6.18.1-new/net/ipv4/netfilter/ip_tables.c
--- linux-2.6.18.1/net/ipv4/netfilter/ip_tables.c	2006-10-14 09:04:03.000000000 +0530
+++ linux-2.6.18.1-new/net/ipv4/netfilter/ip_tables.c	2007-11-06 21:36:53.000000000 +0530
@@ -33,6 +33,9 @@
 #include <linux/netfilter/x_tables.h>
 #include <linux/netfilter_ipv4/ip_tables.h>
 
+#include <linux/netfilter_ipv4/ip_conntrack.h>
+#include <linux/netfilter_ipv4/ip_tproxy.h>
+
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>");
 MODULE_DESCRIPTION("IPv4 packet filter");
@@ -47,12 +50,16 @@
 #define dprintf(format, args...)
 #endif
 
+
+DEFINE_RWLOCK(ip_conntrack_lock);
+
 #ifdef DEBUG_IP_FIREWALL_USER
 #define duprintf(format, args...) printk(format , ## args)
 #else
 #define duprintf(format, args...)
 #endif
 
+#if 0
 #ifdef CONFIG_NETFILTER_DEBUG
 #define IP_NF_ASSERT(x)						\
 do {								\
@@ -63,6 +70,7 @@
 #else
 #define IP_NF_ASSERT(x)
 #endif
+#endif // #if 0
 
 #if 0
 /* All the better to debug you with... */
@@ -70,6 +78,7 @@
 #define inline
 #endif
 
+
 /*
    We keep a set of rules for each CPU, so we can avoid write-locking
    them in the softirq when updating the counters and therefore
@@ -85,7 +94,11 @@
 		const char *indev,
 		const char *outdev,
 		const struct ipt_ip *ipinfo,
-		int isfrag)
+		int isfrag
+#if defined(CONFIG_IP_NF_TPROXY) || defined (CONFIG_IP_NF_TPROXY_MODULE)
+                , char TproxyBitSet, u32 tproxyFaddr
+#endif /* CONFIG_IP_NF_TPROXY */
+                )
 {
 	size_t i;
 	unsigned long ret;
@@ -108,7 +121,15 @@
 			NIPQUAD(ipinfo->dmsk.s_addr),
 			NIPQUAD(ipinfo->dst.s_addr),
 			ipinfo->invflags & IPT_INV_DSTIP ? " (INV)" : "");
-		return 0;
+#if defined(CONFIG_IP_NF_TPROXY) || defined (CONFIG_IP_NF_TPROXY_MODULE)
+                if (TproxyBitSet && ((tproxyFaddr == ipinfo->src.s_addr) ||
+                                     ((tproxyFaddr & ipinfo->smsk.s_addr) == ipinfo->src.s_addr)))
+                {
+                     // Do nothing
+                }
+                else
+#endif /* CONFIG_IP_NF_TPROXY */
+                     return 0;
 	}
 
 	/* Look for ifname matches; this should unroll nicely. */
@@ -232,11 +253,52 @@
 	struct ipt_entry *e, *back;
 	struct xt_table_info *private;
 
+	struct ip_conntrack *ct;
+	enum ip_conntrack_info ctinfo;
+
+#if defined(CONFIG_IP_NF_TPROXY) || defined (CONFIG_IP_NF_TPROXY_MODULE)
+        char TproxyBitSet;
+        u32 tproxyFaddr;
+#endif /* CONFIG_IP_NF_TPROXY */
+
 	/* Initialization */
 	ip = (*pskb)->nh.iph;
 	datalen = (*pskb)->len - ip->ihl * 4;
 	indev = in ? in->name : nulldevname;
 	outdev = out ? out->name : nulldevname;
+
+#if defined(CONFIG_IP_NF_TPROXY) || defined (CONFIG_IP_NF_TPROXY_MODULE)
+	read_lock_bh(&ip_conntrack_lock);
+	TproxyBitSet = 0;
+	tproxyFaddr = 0;
+        if (NF_IP_POST_ROUTING == hook)
+        {
+             ct = ip_conntrack_get (*pskb, &ctinfo);
+
+             if (ct)
+             {
+                  if (IPS_TPROXY_BIT & ct->tproxyBit)
+                  {
+                       tproxyFaddr = ct->tproxyFaddr;
+                       TproxyBitSet = 1;
+
+                  }
+                  else
+                  {
+                       TproxyBitSet = 0;
+                       tproxyFaddr = 0;
+                  }
+             }
+             else
+             {
+                  TproxyBitSet = 0;
+                  tproxyFaddr = 0;
+             }
+	}
+	read_unlock_bh(&ip_conntrack_lock);
+#endif /* CONFIG_IP_NF_TPROXY */
+	
+
 	/* We handle fragments by dealing with the first fragment as
 	 * if it was a normal packet.  All other fragments are treated
 	 * normally, except that they will NEVER match rules that ask
@@ -257,7 +319,12 @@
 	do {
 		IP_NF_ASSERT(e);
 		IP_NF_ASSERT(back);
-		if (ip_packet_match(ip, indev, outdev, &e->ip, offset)) {
+		if (ip_packet_match(ip, indev, outdev, &e->ip, offset
+#if defined(CONFIG_IP_NF_TPROXY) || defined (CONFIG_IP_NF_TPROXY_MODULE)
+                                    ,TproxyBitSet, tproxyFaddr
+#endif /* CONFIG_IP_NF_TPROXY */
+                                   ))
+                {
 			struct ipt_entry_target *t;
 
 			if (IPT_MATCH_ITERATE(e, do_match,
diff -Naur linux-2.6.18.1/net/ipv4/netfilter/iptable_tproxy.c linux-2.6.18.1-new/net/ipv4/netfilter/iptable_tproxy.c
--- linux-2.6.18.1/net/ipv4/netfilter/iptable_tproxy.c	2007-11-06 21:42:38.000000000 +0530
+++ linux-2.6.18.1-new/net/ipv4/netfilter/iptable_tproxy.c	2007-11-06 21:41:00.000000000 +0530
@@ -45,7 +45,7 @@
 
 #include <linux/netfilter_ipv4/listhelp.h>
 
-#define TPROXY_VALID_HOOKS ((1 << NF_IP_PRE_ROUTING) | (1 << NF_IP_LOCAL_OUT))
+#define TPROXY_VALID_HOOKS ((1 << NF_IP_PRE_ROUTING) | (1 << NF_IP_LOCAL_OUT)) 
 
 #if 0
 #define DEBUGP printk
@@ -147,6 +147,7 @@
 
 #define TF_STATE_MASK	  0xffff0000
 
+#if 0
 struct ip_tproxy_sockref;
 
 struct ip_tproxy_hash
@@ -198,6 +199,7 @@
 	/* when was this entry inserted in hash */
 	struct timespec tv_hashed;
 };
+#endif
 
 static int hashsize = 0;
 module_param(hashsize, uint, 0600);
@@ -724,6 +726,13 @@
 		       hooknum, sr->laddr, sr->lport, newip, newport);
 	}
 	else {
+		if (test_bit(IPS_SRC_NAT_DONE_BIT, &ct->status))
+		{
+			test_and_clear_bit(IPS_SRC_NAT_DONE_BIT, &ct->status);
+                        ct->tproxyBit = IPS_TPROXY_BIT;
+                        ct->tproxyFaddr = newip;
+		}
+
 		/* we store a reference to the sockref in the conntrack */
 		if (!test_and_set_bit(IPS_TPROXY_BIT, &ct->status)) {
 			if (flags & TN_STOREREF) {
@@ -828,6 +837,7 @@
 	enum ip_conntrack_info ctinfo;
 	unsigned int verdict = NF_ACCEPT;
 
+
 	ct = ip_conntrack_get(*pskb, &ctinfo);
 
 	if (ct && ctinfo == IP_CT_NEW) {
@@ -851,6 +861,7 @@
 		read_lock_bh(&ip_tproxy_lock);
 		if (hooknum == NF_IP_PRE_ROUTING || hooknum == NF_IP_LOCAL_OUT) {
 
+
 			/*
 			 * We either received a connection from the network (PREROUTING case)
 			 * or a local process generated one (LOCAL_OUT case).
@@ -869,6 +880,7 @@
 			sr = ip_tproxy_sockref_find_foreign(iph->daddr, tports[1],
 						iph->protocol, iph->saddr, tports[0]);
 
+
 			if (sr && sr->flags & TF_ORPHAN) {
 				/* This sockref is orphaned, the listening socket is already unassigned,
 				 * so it should not be used for setting up NAT for a new connection. */
@@ -891,6 +903,7 @@
 				if ((sr->flags & TF_MARK_ONLY) == 0)
 					sr = NULL;
 			}
+
 		}
 		else if (hooknum == NF_IP_POST_ROUTING) {
 
@@ -906,6 +919,7 @@
 
 			/* source address is interesting */
 
+			
 			sr = ip_tproxy_sockref_find_local(iph->saddr, tports[0], iph->protocol,
 					1, iph->daddr, tports[1]);
 			if (sr && (sr->flags & (TF_CONNECT|TF_MARK_ONLY)) == 0) {
@@ -984,9 +998,9 @@
 			/* there was no matching sockref, so we consult the
 			 * TPROXY table
 			 */
-
 			ui.changed = 0;
 			verdict = ipt_do_table(pskb, hooknum, in, out, &tproxy_table, &ui);
+
 			if (ui.changed && verdict == NF_ACCEPT) {
 				struct ip_tproxy_sockref sr;
 				u32 laddr;
@@ -1014,9 +1028,17 @@
 				if (!ip_tproxy_setup_nat(pskb, hooknum, &sr, 0))
 					verdict = NF_DROP;
 			}
+                        else
+                        {
+                             // 
+                             // Letz make these values zero so that no junk values are
+                             // present.
+                             //
+                                ct->tproxyBit = 0;
+                                ct->tproxyFaddr = 0;
+                        }
 		}
 	}
-
 	return verdict;
 }
 
@@ -1826,7 +1848,8 @@
 	.owner		= THIS_MODULE,
 	.pf		= PF_INET,
 	.hooknum	= NF_IP_POST_ROUTING,
-	.priority	= -130
+        //.priority	= -130
+	.priority	= -155
 };
 
 static struct nf_hook_ops ip_tproxy_local_out_ops = {
