Linux accept tcp,Linux TCP accept without SYN|ACK

问题

I'm trying to write a TCP transparent proxy to run on Linux.

I want to, upon receipt of an incoming connection, initiate a corresponding outgoing connection, but only accept (SYN|ACK) the incoming connection if the outgoing connection is successful.

TCP_DEFERRED_ACCEPT doesn't do what I want -- it always sends a SYN|ACK.

The question is: how do I accept TCP connections, but defer the SYN|ACK, with the Linux sockets API?

回答1:

You can do that with Linux, but not via the socket API. You would use the NFQUEUE target which allows you to redirect some packets to userspace and decide their fate from within your program.

Obiously, you'd still have to parse the packet in userspace, but searching for a few TCP flags should not be that hard and not require a complete TCP stack. And this way Linux still does the whole network job.

In your case, it would seem possible that you both use NFQUEUE and classical sockets API. The first will give you early decisions, the latter TCP stream data access. Although I never tried it.

See https://home.regit.org/netfilter-en/using-nfqueue-and-libnetfilter_queue/ for instance.

来源:https://stackoverflow.com/questions/28932015/linux-tcp-accept-without-synack

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值