LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-24-2005, 06:16 PM   #1
sl_king
LQ Newbie
 
Registered: Aug 2005
Posts: 3

Rep: Reputation: 0
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?

Thanks!
 
Old 08-25-2005, 06:53 PM   #2
carl.waldbieser
Member
 
Registered: Jun 2005
Location: Pennsylvania
Distribution: Kubuntu
Posts: 197

Rep: Reputation: 32
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't SSH to remote machine: Connection closed by remote host Avatar Linux - Networking 35 10-23-2017 12:21 AM
setting-up an xserver connection with remote host through local firewall. qanopus Linux - Security 5 02-02-2006 10:11 AM
Resolving <www.some remote host>.... failed: Host not found. koodoo Linux - Newbie 2 06-27-2005 08:48 AM
install kernel on remote host mostart Linux - General 1 05-19-2005 10:16 AM
using linux to redirect remote vpn traffic to another remote machine brb5548 Linux - Networking 0 06-28-2003 09:07 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:05 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration