tags:

views:

774

answers:

2

I'm using a user space TCP stack based on the Linux stack running under Linux. Unfortunately it requires applications to specifically call its own modified versions of the normal sockets API functions and then just grabs incoming packets it receives in response using libpcap.

Now my question is whether there is any way to redirect packets from an application to this TCP stack without having to modify the application itself. To put it differently, I am looking for a way to intercept calls to the sockets API and redirect them to the user space equivalent.

Hope it is more or less clear what I mean.

+1  A: 

two ideas (untested, first google them to see if somebody has done it before):

  1. set a replacement stdlib which uses the TCP lib instead of syscalls. then use ld.so to override it at loadtime.

  2. set a tun net device, make the apps talk on this, and write another task that connects the other side of the tun to the userspace TCP lib.

I'd guess the first one performs better and could be less fragile. It needs some delicate stdlib knowledge, thought. Also, the tun device seems to only give you IP packets.

Your best bet is to search other users of the TCP library, it's quite possible there's already some kind of 'loader' that do exactly that.

Javier
A: 

Use tuntap as a bridge is a good idea, and tap (not tun) can give you complete ethernet packet including ehternet(mac) header. Here I have a question for you, how does your user space stack handle the incoming packets. In your post, you mentioned that it use libpcap to grab packets, but as I know, libpcap will just get a copy of the incoming packet, and then that packet will still pass into the normal kernel stack path and that may be not what you want. For example, if it's a tcp packet for your application which is running based on the user space tcp/ip stack, and kernel doesn't know it and possibly just send a rst packet out which may break your normal connection. So I think your user space tcp/ip stack may apply some special methods to prevent the incomming packet be passed into kernel, right? How does it make that?