I added a static route.<br><br>I found the reason.<br>One of my tp-link device has a bug which quietly ignored my static route configuration.<br><br><br><br><div class="gmail_quote">2011/5/4 Balazs Scheidler <span dir="ltr"><<a href="mailto:bazsi@balabit.hu" target="_blank">bazsi@balabit.hu</a>></span><br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div><div></div><div>On Mon, 2011-05-02 at 19:42 +0800, 文剑 wrote:<br>
> Hi,<br>
><br>
> I want to write a full transparency proxy too.<br>
><br>
> Squid and haproxy are so complicated that i can't quickly understand<br>
> how tproxy works.<br>
> And I am new to iptables.<br>
> If there is a sample peace of code which is simple, I think it would<br>
> be helpful.<br>
><br>
> I wrote some code which failed at initiating connections with a<br>
> foreign address as a source.<br>
> The reason is timeout while attempting connection.<br>
> Where am I wrong?<br>
><br>
> Thanks.<br>
><br>
><br>
> My code:<br>
><br>
> #define NON_LOCAL_IP "192.168.111.23"<br>
> #define NON_LOCAL_PORT 2000<br>
><br>
> int sockfd = socket(AF_INET, SOCK_STREAM, 0);<br>
><br>
> memset (&non_local_addr, 0, sizeof(non_local_addr));<br>
> non_local_addr.sin_family = AF_INET;<br>
> dst_addr.sin_addr.s_addr = inet_addr(NON_LOCAL_IP);<br>
> inet_pton(AF_INET, NON_LOCAL_IP, &non_local_addr.sin_addr);<br>
> non_local_addr.sin_port = htons(NON_LOCAL_PORT);<br>
><br>
> setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &optvalue,<br>
> sizeof(optvalue));<br>
> setsockopt(sockfd, SOL_IP, IP_TRANSPARENT, &optvalue,<br>
> sizeof(optvalue));<br>
> bind(sockfd, (struct sockaddr *)&non_local_addr,<br>
> sizeof(non_local_addr));<br>
><br>
> memset(&dst_addr, 0, sizeof(dst_addr));<br>
> dst_addr.sin_family = AF_INET;<br>
> dst_addr.sin_addr.s_addr = inet_addr("192.168.1.1");<br>
> dst_addr.sin_port = htons(80);<br>
><br>
> connect(sockfd, (struct sockaddr *) &dst_addr, sizeof(dst_addr)); //<br>
> ETIMEOUT<br>
<br>
</div></div>are you sure the reverse direction is routed back through your box? that<br>
is needed for tproxy to pick up packets.<br>
<br>
e.g. the server should route client destined packets using your box as a<br>
gateway.<br>
<font color="#888888"><br>
--<br>
Bazsi<br>
<br>
<br>
</font></blockquote></div><br><br clear="all"><br><br>