gpt4 book ai didi

c - BPF : mark in structure __skbuff is not writeable?

转载 作者:太空宇宙 更新时间:2023-11-04 04:11:21 25 4
gpt4 key购买 nike

我有一个 BPF 代码(“classifier”部分)。我使用它加载到使用 tc(流量 Controller )实用程序的界面。我的代码更改了 __skbuff 中的标记。后来当我尝试使用 iptables 捕获这个标记时,我发现我编辑的标记已经消失了。

代码:

__section("classifier")
int function(struct __sk_buff *skb)
{
skb->mark = 0x123;

我使用 iptable mangle 表的以下规则来查看标记是否写入正确。

# iptables -t mangle -A PREROUTING -i <my_interface> \
-m mark --mark 0x123 \
-j LOG --log-prefix "MY_PRINTS" --log-level 7

以下是我用来加载 bpf 程序的 TC 命令;

# tc qdisc add dev <myInterface> root handle 1: prio
# tc filter add dev <myInterface> parent 1: bpf obj bpf.o flowid 1:1 direct-action

最佳答案

问题出在您的 tc 命令中。您正在将过滤器连接到导出侧。

root parent 指的是导出侧,用于流量整形。相反,如果您想在入口侧附加过滤器,则应使用类似这样的东西(不需要句柄):

# tc qdisc add dev <myInterface> ingress
# tc filter add dev <myInterface> ingress bpf obj bpf.o direct-action

或者,更好的做法是,使用 BPF 特定的 qdisc clsact,它可用于为入口和导出附加过滤器(关于它的文档不多,除了它的 commit logCilium's BPF documentation(搜索clsact)):

# tc qdisc add dev <myInterface> clsact
# tc filter add dev <myInterface> ingress bpf obj bpf.o direct-action

关于c - BPF : mark in structure __skbuff is not writeable?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57055240/

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