简体   繁体   English

带有 gso 的 UDP 没有收到整个消息

[英]UDP with gso doesn't receive the entire message

I am trying to use UDP with GSO (Generic Segmentation Offload) to send 50Kb sized packets.我正在尝试使用带有 GSO(通用分段卸载)的 UDP 来发送 50Kb 大小的数据包。

// sender side 
int val = 1472; // ETHERNET - udp - upv4 header
if (setsockopt(fdt, SOL_UDP, UDP_SEGMENT, &val, sizeof(val)))
    error(1, errno, "setsockopt udp segment");
int ret = sendmsg(fd, msg, flags);

and on the recv size, I do和 recv 大小,我做

// recv side 
int ret = recvmsg(fd, msg, flags);

I can see that I send 50Kb message and receiver side only received 1472 with one call.我可以看到我发送了 50Kb 的消息,而接收方只通过一次呼叫收到了 1472。 I have heard about GRO (Generic Receive Offload) but I didn't find any example online.我听说过 GRO(通用接收卸载),但我没有在网上找到任何示例。 Do I have to make multiple syscalls to get all the data, is it possible to set a socekt option or make a syscall to receive reassembled message in one go?我是否必须进行多次系统调用才能获取所有数据,是否可以设置 socekt 选项或进行系统调用以一次性接收重新组装的消息? how can it be more efficient if I have to make multiple system calls instead of just relying on IP fragmentation and sending larger than MTU packets?如果我必须进行多个系统调用,而不是仅仅依靠 IP 分片和发送大于 MTU 的数据包,如何提高效率?

Here is an interesting article you can read for deep understand GSO and GRO.这是一篇有趣的文章,您可以阅读以深入了解 GSO 和 GRO。 Ethtool may be able to enable/disable GRO on specific interfaces. Ethtool 可能能够在特定接口上启用/禁用 GRO。 Depends on the version.取决于版本。 If you can go well with it, then it's best.如果你能顺其自然,那就最好了。

If not, since the Linux network stack is realy complicated, it's hard to check which part makes the segment fail just by the result.如果没有,由于 Linux 网络堆栈确实很复杂,因此很难仅凭结果来检查哪个部分使段失败。 I think it's better to use some tools like netstat, ss, sar, tcpdump, wireshark and others to analyze each layer and then it's much easier to know where is wrong.我认为最好使用一些工具,如netstat、ss、sar、tcpdump、wireshark等来分析每一层,然后更容易知道哪里出了问题。 But don't forget to check if your hardware support this.但不要忘记检查您的硬件是否支持此功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM