Redirecting packets to user space TCP stack without modifying application

190 篇文章 1 订阅
168 篇文章 0 订阅

http://stackoverflow.com/questions/966031/redirecting-packets-to-user-space-tcp-stack-without-modifying-application

Redirecting packets to user space TCP stack without modifying application

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.

share | improve this question
 
1  
What user space TCP stack are you using? –  chrisdew  Jul 19 '12 at 8:11

2 Answers

up vote 1 down vote accepted

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.

share | improve this answer
   

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?

share | improve this answer
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值