--- /root/netfilter/tproxy_orginal_code/patch/xt_TPROXY.c	2011-06-16 05:32:49.232116909 +0200
+++ /root/netfilter/xtables-addons-1.31/extensions/patch/xt_TPROXY.c	2011-06-16 05:32:22.070409400 +0200
@@ -17,7 +17,8 @@
 #include <net/udp.h>
 #include <net/inet_sock.h>
 #include <linux/inetdevice.h>
-#include <linux/netfilter/x_tables.h>
+//#include </TspCore/rpmbuild/BUILD/kernel-2.6.32-131.0.15.el6/linux-2.6.32-131.0.15.el6.x86_64/include/linux/netfilter/x_tables.h>
+#include  <linux/netfilter/x_tables.h>
 #include <linux/netfilter_ipv4/ip_tables.h>
 
 #include <net/netfilter/ipv4/nf_defrag_ipv4.h>
@@ -28,17 +29,28 @@
 #include <net/netfilter/ipv6/nf_defrag_ipv6.h>
 #endif
 
-#include <net/netfilter/nf_tproxy_core.h>
-#include <linux/netfilter/xt_TPROXY.h>
+#include "nf_tproxy_core.h"
+#include "xt_TPROXY.h"
+struct sctp_endpoint *__sctp_rcv_lookup_endpoint(const union sctp_addr *laddr);
+struct sctp_association *__sctp_rcv_lookup(struct sk_buff *skb,
+				      const union sctp_addr *laddr,
+				      const union sctp_addr *paddr,
+				      struct sctp_transport **transportp);
+void sctp_hash_endpoint(struct sctp_endpoint *ep);
+extern struct sock *sctp_get_ctl_sock(void);
+
 
 static inline __be32
 tproxy_laddr4(struct sk_buff *skb, __be32 user_laddr, __be32 daddr)
 {
 	struct in_device *indev;
 	__be32 laddr;
-
-	if (user_laddr)
+	pr_info("TPROXY:%s:%d:%s() - entry with (skb:%p, user_laddr:%pI4, daddr:%pI4) \n",
+				"xt_TPROXY.c",__LINE__,__func__,skb,&user_laddr,&daddr);
+	if (user_laddr){
+		pr_info("TPROXY:%s:%d:%s() - return user_laddr:%pI4 \n","xt_TPROXY.c",__LINE__,__func__,&user_laddr );
 		return user_laddr;
+	}
 
 	laddr = 0;
 	rcu_read_lock();
@@ -48,7 +60,8 @@
 		break;
 	} endfor_ifa(indev);
 	rcu_read_unlock();
-
+	pr_info("TPROXY:%s:%d:%s() - return (%s:%pI4)\n",
+				"xt_TPROXY.c",__LINE__,__func__,laddr ? "laddr" : "daddr",laddr ? &laddr : &daddr );
 	return laddr ? laddr : daddr;
 }
 
@@ -75,7 +88,8 @@
 {
 	const struct iphdr *iph = ip_hdr(skb);
 	struct tcphdr _hdr, *hp;
-
+	pr_info("TPROXY:%s:%d:%s() - entry (skb:%p,sk:%p) \n",
+				"xt_TPROXY.c",__LINE__,__func__,skb,sk);
 	hp = skb_header_pointer(skb, ip_hdrlen(skb), sizeof(_hdr), &_hdr);
 	if (hp == NULL) {
 		inet_twsk_put(inet_twsk(sk));
@@ -107,7 +121,16 @@
 {
 	const struct iphdr *iph = ip_hdr(skb);
 	struct udphdr _hdr, *hp;
-	struct sock *sk;
+	struct sock *sk = NULL;
 	hp = skb_header_pointer(skb, ip_hdrlen(skb), sizeof(_hdr), &_hdr);
 	if (hp == NULL)
@@ -123,21 +146,33 @@
 				   skb->dev, NFT_LOOKUP_ESTABLISHED);
 
 	laddr = tproxy_laddr4(skb, laddr, iph->daddr);
-	if (!lport)
+	if (!lport){
+		pr_info("TPROXY:%s:%d:%s: - lport is null  \n",
+				 		"xt_TPROXY.c",__LINE__,__func__);
 		lport = hp->dest;
+	}
 
 	/* UDP has no TCP_TIME_WAIT state, so we never enter here */
-	if (sk && sk->sk_state == TCP_TIME_WAIT)
+	if (sk && sk->sk_state == TCP_TIME_WAIT){
 		/* reopening a TIME_WAIT connection needs special handling */
 		sk = tproxy_handle_time_wait4(skb, laddr, lport, sk);
-	else if (!sk)
+	}
+	else if (!sk){
 		/* no, there's no established connection, check if
 		 * there's a listener on the redirected addr/port */
-		sk = nf_tproxy_get_sock_v4(dev_net(skb->dev), iph->protocol,
-					   iph->saddr, laddr,
-					   hp->source, lport,
-					   skb->dev, NFT_LOOKUP_LISTENER);
+		if(iph->protocol !=  IPPROTO_SCTP)
+			sk = nf_tproxy_get_sock_v4(dev_net(skb->dev), iph->protocol,	
+					iph->saddr, laddr,
+					hp->source, lport,
+					skb->dev, NFT_LOOKUP_LISTENER);
+		else
+			sk = nf_tproxy_get_sock_v4(dev_net(skb->dev), iph->protocol,	
+					iph->saddr, laddr,
+					hp->dest, lport,
+					skb->dev, NFT_LOOKUP_LISTENER);
 
+	}
+	
 	/* NOTE: assign_sock consumes our sk reference */
 	if (sk && nf_tproxy_assign_sock(skb, sk)) {
 		/* This should be in a separate target, but we don't do multiple
@@ -147,7 +182,13 @@
 		pr_debug("redirecting: proto %hhu %pI4:%hu -> %pI4:%hu, mark: %x\n",
 			 iph->protocol, &iph->daddr, ntohs(hp->dest),
 			 &laddr, ntohs(lport), skb->mark);
 		return NF_ACCEPT;
 	}
 
 	pr_debug("no socket, dropping: proto %hhu %pI4:%hu -> %pI4:%hu, mark: %x\n",
@@ -160,7 +201,6 @@
 tproxy_tg4_v0(struct sk_buff *skb, const struct xt_target_param *par)
 {
 	const struct xt_tproxy_target_info *tgi = par->targinfo;
-
 	return tproxy_tg4(skb, tgi->laddr, tgi->lport, tgi->mark_mask, tgi->mark_value);
 }
 
@@ -168,7 +208,6 @@
 tproxy_tg4_v1(struct sk_buff *skb, const struct xt_target_param *par)
 {
 	const struct xt_tproxy_target_info_v1 *tgi = par->targinfo;
-
 	return tproxy_tg4(skb, tgi->laddr.ip, tgi->lport, tgi->mark_mask, tgi->mark_value);
 }
 
@@ -343,12 +382,12 @@
 {
 	const struct ipt_ip *i = par->entryinfo;
 
-	if ((i->proto == IPPROTO_TCP || i->proto == IPPROTO_UDP)
+	if ((i->proto == IPPROTO_TCP || i->proto == IPPROTO_UDP || i->proto == IPPROTO_SCTP)
 	    && !(i->invflags & IPT_INV_PROTO))
 		return true;
 
 	pr_info("xt_TPROXY: Can be used only in combination with "
-		"either -p tcp or -p udp\n");
+		"either -p tcp or -p udp or sctp\n");
 	return false;
 }
 
