如何通过 RAW 套接字使用 TCP 校验和卸载
(使用Linux)
使用原始套接字
创建TCP
数据包 - 事实证明,在高性能网络中,计算校验和对我来说是瓶颈。由于网卡支持校验和卸载,并且 ethtool 也表示已启用,因此我希望可以使用校验和卸载。
但当我使用原始套接字时,似乎没有计算校验和。有没有办法使用原始套接字启用 tcp 校验和卸载?
编辑:
实际上我的机器/NIC(Thinkpad x201)的行为似乎不太符合逻辑:当使用正常的tcp套接字发送数据包时,所有校验和都是错误的,在环回接口上以及在机器。有趣的是,另一台机器默默地传递数据包?
编辑2:好吧,现在我只是查看了错误机器上的数据包,卸载工作正常了。但是当我将 tcp_checksum
字段保留为 0 时,它不会被填充,它只是保持 0。
(Using Linux)
Creating TCP
packets using raw sockets
- it turns out that calculating the checksum is the bottleneck for me, in high performance networks. Since the NIC's would support checksum offloading, and ethtool
also says that it is enabled, I hoped that I could use checksum offloading.
But it seems that the checksum is not calculated, when I use raw sockets. Is there a way to enable tcp checksum offloading using raw sockets?
Edit:
Actually the behaviour of my machine/NIC (Thinkpad x201) does not seem to be too logical: when sending packets with normal tcp sockets, all checksums are wrong, on the loopback interface as well as between machines. Funnily the other machine silently delivers the packets though ?
Edit2: Ok now I just looked at the packets on the wrong machine, the offloading works. But when I leave the tcp_checksum
field 0, it does not get filled in, it simply stays 0.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在这里遇到同样的问题:在原始套接字中发送 TCP 或 UDP 数据包,但无法利用校验和卸载打开的 NIC。希望有一个setsockopt()或ioctl()类型的函数可以在原始套接字上启用校验和卸载。
对于为什么wireshark显示数据包有校验和错误但目标主机无论如何都接受所有数据包的问题,原因是wireshark(如果在Windows上通过winpcap等)在数据包从操作系统到达NIC之前捕获数据包。数据包没有由操作系统或应用程序正确填充的校验和字段——这就是 NIC 上的校验和卸载功能的用途。
问题是,如何使 NIC 在原始套接字上进行校验和卸载。
I have the same problem here: sent TCP or UDP packet in raw socket but can't take advantage the NIC whose checksuming-offloading is on. Wish there is a setsockopt() or ioctl() type of function that enable checksuming-offloading on the raw socket.
For the question why wireshark shows packets to have checksum errors but destination host accepts all the packets anyway, the reason is that wireshark (through winpcap etc if on windows) captures packets before the packets reached the NIC from OS. The packets don't have the checksum fields filled correctly by OS or application --- this is what checksum offloading feature on NIC is for.
The question is, how to enable NIC to do checksum offloading on a raw socket.