使用 attach_xdp,标志是否控制模式?

with attach_xdp, does flags control the mode?

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

例如,

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

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

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

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)

基本上,三种模式:generic/SKB (xdpgeneric)、native/driver (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 object 被发送到内核并通过网络链接消息附加到选定的 XDP 挂钩。然后in the kernel,程序根据用户space.

传来的flags进行处理

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