gpt4 book ai didi

ebpf - 对于attach_xdp,标志是否控制模式?

转载 作者:行者123 更新时间:2023-12-02 03:12:42 25 4
gpt4 key购买 nike

当我将 xdp 与 eBPF 结合使用时,我想我可以使用 ip link 来设置模式。

例如,

ip link set dev eno1 xdpoffload obj xdp.o sec .text

我想知道 xdpoffload 或通用或 native 模式是如何在代码中实现的。

所以我在查看其他代码,发现了类似的内容:

attach_xdp(device, fn, flags)

我认为flags是设置模式标志的地方?

如果有人能告诉我这是否属实,如果属实,我可以使用哪些数字来选择该选项,那就太好了。

提前非常感谢您。

最佳答案

ip link 获取 XDP 模式并确实设置标志。您可以在 ip/iplink_xdp.c 中看到这一点:

    if (!force)
xdp.flags |= XDP_FLAGS_UPDATE_IF_NOEXIST;
if (generic)
xdp.flags |= XDP_FLAGS_SKB_MODE;
if (drv)
xdp.flags |= XDP_FLAGS_DRV_MODE;
if (offload)
xdp.flags |= XDP_FLAGS_HW_MODE;

可用值并不多,它们位于来自 Linux UAPI 的 header 中,if_link.h :

#define XDP_FLAGS_UPDATE_IF_NOEXIST (1U << 0)
#define XDP_FLAGS_SKB_MODE (1U << 1)
#define XDP_FLAGS_DRV_MODE (1U << 2)
#define XDP_FLAGS_HW_MODE (1U << 3)
#define XDP_FLAGS_MODES (XDP_FLAGS_SKB_MODE | \
XDP_FLAGS_DRV_MODE | \
XDP_FLAGS_HW_MODE)
#define XDP_FLAGS_MASK (XDP_FLAGS_UPDATE_IF_NOEXIST | \
XDP_FLAGS_MODES)

基本上,三种模式:通用/SKB (xdpgeneric)、 native /驱动程序 (xdp) 和硬件卸载 (xdpoffload) )。 ip-link(8) manual page 可以确认这一点:

xdp object | pinned | off

set (or unset) a XDP ("eXpress Data Path") BPF program to run on every packet at driver level. ip link output will indicate a xdp flag for the networking device. If the driver does not have native XDP support, the kernel will fall back to a slower, driver-independent "generic" XDP variant. The ip link output will in that case indicate xdpgeneric instead of xdp only. If the driver does have native XDP support, but the program is loaded under xdpgeneric object | pinned then the kernel will use the generic XDP variant instead of the native one. xdpdrv has the opposite effect of requestsing that the automatic fallback to the generic XDP variant be disabled and in case driver is not XDP-capable error should be returned. xdpdrv also disables hardware offloads. xdpoffload in ip link output indicates that the program has been offloaded to hardware and can also be used to request the "offload" mode, much like xdpgeneric it forces program to be installed specifically in HW/FW of the apater.

解析命令行参数后,xdp 对象将发送到内核并通过 netlink 消息附加到选定的 XDP Hook 。然后in the kernel ,程序根据从用户空间传递过来的标志进行处理。

(您可以使用 cross referencergit grepgit log -S 等来跟踪标志,例如在源存储库中。)

关于ebpf - 对于attach_xdp,标志是否控制模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57171394/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com