<div>&nbsp;hello, all:<br>I have been reseach on tproxy(for kernel-2.6.24) these days. <br>And I found that Tproxy&nbsp; sets skb-&gt;mark and skb-&gt;sk first (both the TPROXY target and socket match do the same), <br>then hand packets to non-local sockets rely on policy routing. <br><br>Today I saw that Tproxy has modified ip_route_me_harder, it inserted lines of code to ip_route_me_harder like following:<br>so, what does ip_route_me_harder used for, why Tproxy modified those codes. thanks very much! <br><br>/* route_me_harder function, used by iptable_nat, iptable_mangle + ip_queue */<br>int ip_route_me_harder(struct sk_buff *skb, unsigned addr_type)<br>{<br>&nbsp;&nbsp;&nbsp; const struct iphdr *iph = ip_hdr(skb);<br>&nbsp;&nbsp;&nbsp; struct rtable *rt;<br>&nbsp;&nbsp;&nbsp; struct flowi fl = {};<br>&nbsp;&nbsp;&nbsp; struct dst_entry *odst;<br>&nbsp;&nbsp;&nbsp; unsigned int hh_len;<br>&nbsp;&nbsp;&nbsp; unsigned int type;<br><br>&nbsp;&nbsp;&nbsp; type = inet_addr_type(iph-&gt;saddr);<br>&nbsp;&nbsp;&nbsp; <u><font color="#800000"><b>if (skb-&gt;sk &amp;&amp; inet_sk(skb-&gt;sk)-&gt;transparent) //TPROXY ADDED <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; type = RTN_LOCAL;</b></font></u><br>&nbsp;&nbsp;&nbsp; if (addr_type == RTN_UNSPEC)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; addr_type = type;<br><br>&nbsp;&nbsp;&nbsp; /* some non-standard hacks like ipt_REJECT.c:send_reset() can cause<br>&nbsp;&nbsp;&nbsp; &nbsp;* packets with foreign saddr to appear on the NF_IP_LOCAL_OUT hook.<br>&nbsp;&nbsp;&nbsp; &nbsp;*/<br>&nbsp;&nbsp;&nbsp; if (addr_type == RTN_LOCAL) {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fl.nl_u.ip4_u.daddr = iph-&gt;daddr;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (type == RTN_LOCAL)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fl.nl_u.ip4_u.saddr = iph-&gt;saddr;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fl.nl_u.ip4_u.tos = RT_TOS(iph-&gt;tos);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fl.oif = skb-&gt;sk ? skb-&gt;sk-&gt;sk_bound_dev_if : 0;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fl.mark = skb-&gt;mark;<br>&nbsp;&nbsp;&nbsp; <u>&nbsp;&nbsp;&nbsp;<font color="#800000"><b> fl.flags = skb-&gt;sk ? inet_sk_flowi_flags(skb-&gt;sk) : 0;</b></font></u> //TPROXY ADDED<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (ip_route_output_key(&amp;rt, &amp;fl) != 0)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return -1;<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; /* Drop old route. */<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst_release(skb-&gt;dst);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; skb-&gt;dst = &amp;rt-&gt;u.dst;<br>&nbsp;&nbsp;&nbsp; } else {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; /* non-local src, find valid iif to satisfy<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;* rp-filter when calling ip_route_input. */<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fl.nl_u.ip4_u.daddr = iph-&gt;saddr;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (ip_route_output_key(&amp;rt, &amp;fl) != 0)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return -1;<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; odst = skb-&gt;dst;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (ip_route_input(skb, iph-&gt;daddr, iph-&gt;saddr,<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; RT_TOS(iph-&gt;tos), rt-&gt;u.dst.dev) != 0) {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst_release(&amp;rt-&gt;u.dst);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return -1;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst_release(&amp;rt-&gt;udst);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dst_release(odst);<br>&nbsp;&nbsp;&nbsp; }<br><br>&nbsp;&nbsp;&nbsp; if (skb-&gt;dst-&gt;error)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return -1;<br><br>#ifdef CONFIG_XFRM<br>&nbsp;&nbsp;&nbsp; if (!(IPCB(skb)-&gt;flags &amp; IPSKB_XFRM_TRANSFORMED) &amp;&amp;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; xfrm_decode_session(skb, &amp;fl, AF_INET) == 0)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (xfrm_lookup(&amp;skb-&gt;dst, &amp;fl, skb-&gt;sk, 0))<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return -1;<br>#endif<br><br>&nbsp;&nbsp;&nbsp; /* Change in oif may mean change in hh_len. */<br>&nbsp;&nbsp;&nbsp; hh_len = skb-&gt;dst-&gt;dev-&gt;hard_header_len;<br>&nbsp;&nbsp;&nbsp; if (skb_headroom(skb) &lt; hh_len &amp;&amp;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; pskb_expand_head(skb, hh_len - skb_headroom(skb), 0, GFP_ATOMIC))<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return -1;<br><br>&nbsp;&nbsp;&nbsp; return 0;<br>}<br><br>regards.<br></div><div>&nbsp;</div><br><!-- footer --><br> 
<hr>
<font style="font-size:12px;line-height:15px;">[广告] </font><font style="font-size:12px;line-height:15px;">购卡罗拉、花冠EX、威驰,即送价值</font><a style="font-size:12px;line-height:15px; color:blue; text-decoration:underline;" href="http://popme.163.com/link/004992_1211_6738.html">3500元专属导航仪</a>