Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AYA tc classifier does not support using tc_classid #886

Open
danielconnor opened this issue Feb 19, 2024 · 0 comments
Open

AYA tc classifier does not support using tc_classid #886

danielconnor opened this issue Feb 19, 2024 · 0 comments

Comments

@danielconnor
Copy link

danielconnor commented Feb 19, 2024

A tc classifier eBPF program can set the tc_classid field to specify the class that should be used to handle the packet. A direct-action eBPF program only supports setting the minor 16 bits of the classid, meaning the classid/flowid attribute needs to be set on the eBPF configuration for it to work. AYA currently doesn't support setting the classid/flowid attribute(via TCA_BPF_CLASSID) on a classifier program.

Explaination

An aya tc classifier program is always direct-action
https://github.com/aya-rs/aya/blob/main/aya/src/sys/netlink.rs#L161-L162

direct-action means exts_integrated
https://github.com/torvalds/linux/blob/master/net/sched/cls_bpf.c#L480

If exts_integrated, the classid is prog->res.classid (a 32bit integer) ORed with qdisc_skb_cb(skb)->tc_classid, which is a 16bit integer - meaning the bpf program can only set the minor 16 bits.
https://github.com/torvalds/linux/blob/master/net/sched/cls_bpf.c#L110-L119

Since the program can only set the minor 16 bits and the major 16 bits need to be set, setting the tc_classid field from bpf has no effect unless the program classid/flowid is set.

Note: calling the property classid/flowid because that's what tc accepts and outputs as flowid (parsing classid/flowid
https://github.com/iproute2/iproute2/blob/d9b886d745ada3b8481e041ceca579c6f3acbea3/tc/f_bpf.c#L123-L132C26)

I've verified it works with the following change:

diff --git a/aya/src/sys/netlink.rs b/aya/src/sys/netlink.rs
index f10c283..46a2e73 100644
--- a/aya/src/sys/netlink.rs
+++ b/aya/src/sys/netlink.rs
@@ -19,6 +19,7 @@ use crate::{
     generated::{
         ifinfomsg, tcmsg, IFLA_XDP_EXPECTED_FD, IFLA_XDP_FD, IFLA_XDP_FLAGS, NLMSG_ALIGNTO,
         TCA_BPF_FD, TCA_BPF_FLAGS, TCA_BPF_FLAG_ACT_DIRECT, TCA_BPF_NAME, TCA_KIND, TCA_OPTIONS,
+        TCA_BPF_CLASSID,
         TC_H_CLSACT, TC_H_INGRESS, TC_H_MAJ_MASK, TC_H_UNSPEC, XDP_FLAGS_REPLACE,
     },
     programs::TcAttachType,
@@ -160,6 +161,8 @@ pub(crate) unsafe fn netlink_qdisc_attach(
     options.write_attr_bytes(TCA_BPF_NAME as u16, prog_name.to_bytes_with_nul())?;
     let flags: u32 = TCA_BPF_FLAG_ACT_DIRECT;
     options.write_attr(TCA_BPF_FLAGS as u16, flags)?;
+    options.write_attr(TCA_BPF_CLASSID as u16, 1 << 16)?;
+
     let options_len = options.finish()?;

     req.header.nlmsg_len += align_to(kind_len + options_len, NLA_ALIGNTO as usize) as u32;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant