AF_XDP:即使每个数据包都被重定向,也没有队列ID为0的套接字的数据包 [英] AF_XDP: No packets for socket with queue-id 0 even though every packet is redirect

查看:1172
本文介绍了AF_XDP:即使每个数据包都被重定向,也没有队列ID为0的套接字的数据包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我基于本教程: https://github.com/xdp-project/xdp-tutorial/tree/master/advanced03-AF_XDP

我在用户空间中使用Queue-ID 0创建了一个套接字. 在我的内核af-xdp程序中,我过滤了UDP数据包,并通过xskmap将它们重定向到用户空间套接字.

因为我显然希望用户空间程序接收数据包,所以我将内核程序中的数据包重定向到索引0:

int index = 0;
if (bpf_map_lookup_elem(&xsks_map, &index)) {
    return bpf_redirect_map(&xsks_map, index, 0);
} else {
    bpf_printk("Didn't find connected socket for index %d!\n", index);
}

没有通过sudo cat /sys/kernel/debug/tracing/trace_pipe收到错误消息Didn't find connected socket for index 0!,但是我在用户空间中也没有收到任何数据包!

如果我继续运行该程序,并同时添加一个ethtool规则,如下所示:

sudo ethtool -N <eth> flow-type udp4 dst-ip <ip> action 0

我的用户空间程序突然开始接收数据包,并且错误消息消失了.

我认为内核程序将接收发送到该接口的每个数据包,但实际上并非如此.我做错了什么?

解决方案

因此,在IRC(#xdp,Freenode)和xdp-newbies邮件列表上对此进行了讨论.在此处报告以作记录.

答案是您没有做错任何事:使用AF_XDP,套接字可以从一个硬件队列接收数据包.您可能有多个套接字从一个队列接收数据包,但是截至撰写本文时,您不能有一个套接字在一个以上队列中接收数据包.这是设计使然.

在您的情况下,您与套接字关联的Queue-ID: 0表示它将接收来自队列0的数据包.这就是为什么在将所有流路由到队列0之前看不到NIC收到的所有数据包的原因. /p>

有关ML讨论的参考文献:链接.感谢Björn和Toke.

I am based on this tutorial: https://github.com/xdp-project/xdp-tutorial/tree/master/advanced03-AF_XDP

I create a socket with Queue-ID 0 in userspace. In my kernel af-xdp program I filter for UDP-packets and redirect them to the userspace socket via a xskmap.

Because I obviously want the userspace-program to receive packets, I redirect the packets in the kernel program to index 0:

int index = 0;
if (bpf_map_lookup_elem(&xsks_map, &index)) {
    return bpf_redirect_map(&xsks_map, index, 0);
} else {
    bpf_printk("Didn't find connected socket for index %d!\n", index);
}

I don't get the error message Didn't find connected socket for index 0! via sudo cat /sys/kernel/debug/tracing/trace_pipe but I don't receive any packets either in userspace!

If I just continue to run the program and simultaneously add an ethtool-rule like this:

sudo ethtool -N <eth> flow-type udp4 dst-ip <ip> action 0

my userspace program suddenly starts to receive packets and the error message goes away.

I thought that the kernel program would receive every packet sent to that interface but somehow that's not the case. What did I do wrong?

解决方案

So this was discussed on IRC (#xdp, Freenode) and the xdp-newbies mailing list. Reporting here for the record.

The answer is that you did nothing wrong: With AF_XDP, a socket receives the packets from one hardware queue. You could have several sockets receiving packets from one queue, but you cannot have, as of this writing, one socket receiving on more than one queue. This is by design.

In your case, the Queue-ID: 0 that you associate to your socket indicates that it will receives packet from queue 0. This is why you don't see all packets received by the NIC before routing all flows to queue 0.

Reference for the ML discussion: link. Credits to Björn and Toke.

这篇关于AF_XDP:即使每个数据包都被重定向,也没有队列ID为0的套接字的数据包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆