1

I am working on a user space tcp stack (mostly just for fun) and I am having some trouble testing it against the unix tcp stack. Currently the only form of testing is done via unit tests. However, I want to test my tcp stack against a real kernel tcp stack. I tried the following setups without much success.

  • using raw sockets: I wrote a simple echo tcp server that accepts connection using the kernel tcp socket. The tcp server listens to port 8080 on localhost. My tcp client uses the user space tcp stack. However, the kernel sends a tcp rst whenever the client sends a syn to the server. It kind of work after I modified iptable to drop all tcp rst packets. However, even though the 3 way syn, syn+ack, ack handshake is established, the server cannot recv any packet that my client sends. I eventually gave up on raw sockets.

  • using tun/tap: Similarly the echo server uses kernel tcp socket and listens on localhost port 8080. The client opens a tap device. The tap device has an ip of 10.0.0.1 and my client assumes an ip of 10.0.0.2. I am able to ping 10.0.0.2 from my computer. However, when my client sends a syn to the tcp server over the tap device, the server does not respond.

Note: I am using ubuntu 12.04.

4

1 回答 1

1

您可以使用 conntrack 工具尝试获取更多信息,了解为什么它不能使用原始套接字。如果由于某种原因内核对 tcp 连接的状态感到困惑,它可能正在决定重置它。您可以尝试通过在原始表中设置 notrack 规则来告诉内核不要跟踪连接以排除这种情况。就像是

iptables -t raw -A PREROUTING -p tcp --port 8080 -j NOTRACK

尝试tcpdumptun/tap 设备上使用并iptables计数以查看数据包被丢弃的位置。我也会尝试 tun 设备,所以你只需要担心第 3 层。

于 2014-12-11T04:11:02.697 回答