Forwarding local traffic to remote host: kernel development
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Forwarding local traffic to remote host: kernel development
Hi All,
I need to forward all the traffic sent to "lo:127.0.0.1:2255" to "eth1:10.10.2.1:2255". The application, which is accessing localhost:2255 must not see the difference (of course, it runs locally). It should be fully confident it is talking to localhost and localhost is responding to it (which would be the altered packets from 10.10.2.1). The logic is a little more then just this, so it needs to be done on the kernel level.
iptables did not seem to help here. As a simpliest alternative, I started to take 2.4.30 kernel apart. "netif_receive_skb" and "dev_queue_xmit" seemed to be the place to mangle incoming/outgoing packets. But I cannot manage it for the local communication.
I did it the following way. When packet appeared in "netif_receive_skb", if it goes to "lo:127.0.0.1:2255", I clone the packet, change skb->dev (to "eth1"), skb->type, ip addresses, mac addresses and checksum and call dev_queue_xmit(cloned packet); then kfree_skb(old one). In case of "lo", the last call fails causing kernel BUG(): "kfree_skb passed an skb still on a list."
When I try to alter packets coming from e.g. "eth0" the same way, the whole idea works.
Anyway, I'm stuck and have no idea how to continue.
Any ideas how to do it so it works? Or, even better, how to do it right?
Re: Forwarding local traffic to remote host: kernel development
Quote:
Originally posted by sl_king Hi All,
I need to forward all the traffic sent to "lo:127.0.0.1:2255" to "eth1:10.10.2.1:2255". The application, which is accessing localhost:2255 must not see the difference (of course, it runs locally). It should be fully confident it is talking to localhost and localhost is responding to it (which would be the altered packets from 10.10.2.1). The logic is a little more then just this, so it needs to be done on the kernel level.
iptables did not seem to help here. As a simpliest alternative, I started to take 2.4.30 kernel apart. "netif_receive_skb" and "dev_queue_xmit" seemed to be the place to mangle incoming/outgoing packets. But I cannot manage it for the local communication.
I did it the following way. When packet appeared in "netif_receive_skb", if it goes to "lo:127.0.0.1:2255", I clone the packet, change skb->dev (to "eth1"), skb->type, ip addresses, mac addresses and checksum and call dev_queue_xmit(cloned packet); then kfree_skb(old one). In case of "lo", the last call fails causing kernel BUG(): "kfree_skb passed an skb still on a list."
When I try to alter packets coming from e.g. "eth0" the same way, the whole idea works.
Anyway, I'm stuck and have no idea how to continue.
Any ideas how to do it so it works? Or, even better, how to do it right?
Thanks!
I'm not sure exactly what you are doing, but if you just need to forward all the tcp traffic from a local port to a remote port, would this program work for you? http://aspn.activestate.com/ASPN/Coo.../Recipe/114642
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.