0

我正在尝试Ipv6-Srv6使用简单的 XDP-eBPF 程序跟踪数据包。我像往常一样得到 NIC 队列 1。

以下是环境细节

  1. 操作系统:来宾操作系统、Ubuntu 19.10、5.3.0-64-generic
  2. 网卡:x710:10Gbps,驱动程序=i40e,驱动程序版本=2.8.20-k,固件=7.20
  3. XDP-eBPF:我的自定义示例程序
#include <bpf.h>
#include <bpf/bpf_helpers.h>

#include <linux/if_ether.h>
#include <linux/ipv6.h>

#include <stdint.h>

#ifndef lock_xadd
#define lock_xadd(ptr, val)     ((void) __sync_fetch_and_add(ptr, val))
#endif

struct bpf_map_def SEC("maps") queue_rx_pkts = {
        .type        = BPF_MAP_TYPE_ARRAY,
        .key_size    = sizeof(__u32),
        .value_size  = sizeof(__u64),
        .max_entries = 256,
};

SEC("prog")
int xdp_select(struct xdp_md *ctx)
{
        //__u32 input_port = ctx->ingress_ifindex;
        __u32 input_queue = ctx->rx_queue_index;

        void *data_end = (void *)(long)ctx->data_end;
        void *data = (void *)(long)ctx->data;
        struct ethhdr *eth_ptr = (struct ethhdr *)data;
        struct ipv6hdr *ipv6_ptr = (struct ipv6hdr *)(data + sizeof(struct ethhdr));
        unsigned int *pkt_count = bpf_map_lookup_elem(&queue_rx_pkts, &input_queue);

        if (!pkt_count)
                return XDP_ABORTED;

        if ((data + sizeof(*eth_ptr)) > data_end)
                return XDP_DROP;


        if (eth_ptr->h_proto == 0xdd86) {
                if ((void *)(ipv6_ptr + 1) > data_end)
                        return XDP_DROP;
                *pkt_count += 1;
                return XDP_PASS;
        }

        return XDP_DROP;
}
  • 数据包生成器:使用 packEth cli 实用程序运行的主机 NIC X710packETHcli -i ens261f2 -m 2- d 0 -n 0 -f /tmp/test.pcap
  • 预期结果:入口数据包将分布在多个 RX 队列上。
  • 观察结果:RX 队列 1 只获取数据包。

在此处输入图像描述

ethtool -S [interface name]我用和验证了结果bpftool map dump id 12。两种情况 RX-Queue-1 都只会更新。

在此处输入图像描述

[EDIT-1] 根据评论的建议更新 RSS 哈希状态

$ ethtool --show-rxfh-indir ens10                                                                                                                                                                                                      [4/1785]
RX flow hash indirection table for ens10 with 8 RX ring(s):
    0:      0     1     2     3     4     5     6     7
    8:      0     1     2     3     4     5     6     7
<snipped>
  504:      0     1     2     3     4     5     6     7
RSS hash key:
9b:d2:e1:c0:f7:aa:1f:69:49:7c:55:76:48:7e:2c:fc:d5:91:47:39:df:50:52:8f:88:07:c8:63:62:27:93:17:35:75:dc:f6:85:e8:ff:c2:72:1d:de:92:d4:2b:1e:d9:f2:53:df:38
RSS hash function:
    toeplitz: on
    xor: off
    crc32: off
4

1 回答 1

0

看起来您示例中的数据包生成器一直在传输相同的数据包。是这样吗?如果是,您为什么希望数据包分布在多个队列中?比如说,设备上启用的哈希函数是“RSS-IPv6”。然后对数据包散列有贡献的数据包字段是源地址和目标地址。它们在数据包中是恒定的,因此具有相同的哈希值,因此数据包一直在同一个队列中。

根据 OP 的进一步观察,在 PackETH 中启用 IP 地址随机化(在选项上打勾Set random source IPv6 address with mask,例如,使用 的掩码值64)确实会导致生成的数据包到达接收方的不同 Rx 队列。通过ethtool -S证实这一观察获得的每队列数据包统计信息。

于 2021-02-06T11:08:03.720 回答