How can ebpf programs be attached to TC classes/qdiscs? #769
-
Hi, Open this to preserve some background knowledge about why cilium/ebpf missing TC loader, anyone with insight could share the knowledge here. |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 2 replies
-
from what I understand, there are two options: 1 netlink based TC loader according to https://lore.kernel.org/bpf/[email protected]/, bpf_link based TC is still missing in kernel. |
Beta Was this translation helpful? Give feedback.
-
here are examples of netlink based: https://pkg.go.dev/github.com/florianl/go-tc https://github.com/cilium/cilium/blob/master/pkg/datapath/loader/netlink.go#L155-L192 |
Beta Was this translation helpful? Give feedback.
-
seems not going to be true anymore https://github.com/cilium/linux/commits/pr/meta5 |
Beta Was this translation helpful? Give feedback.
-
Long story short: use https://pkg.go.dev/github.com/florianl/go-tc#example-package-EBPF. TC is a completely separate kernel subsystem from eBPF that can currently only be interacted with using netlink sockets and its corresponding protocol. As a comparison, on older versions of the Linux kernel, attaching XDP programs also required netlink. However, due to its simplicity (XDP associates a prog FD with an ifindex, which can be retrieved by name using the Go stdlib), XDP has since received a bpf_link interface, and TC, however, is significantly more complex in both its design and its implementation. Assuming the user sets up a class/qdisc hierarchy using the While this is relatively trivial nowadays due to the availability of decent Go libraries, it does require us to add either Then there's also the question of API design. At minimum, the caller would have to specify the qdisc to attach the program to, and configure some fields in the created tc filter. Assuming we're using In conclusion, until tc bpf_link comes around, a dedicated tc library is always going to be the best tool for the job. 🙂 Perhaps we can highlight this more prominently by pointing to external examples for this? |
Beta Was this translation helpful? Give feedback.
-
@vincentmli as i was searching i came across libbpfgo library , They have not yet released their first version, but they have presented bpf_link tc hook in their APIs. this is an example : https://github.com/aquasecurity/libbpfgo/blob/main/selftest/tc/main.go I guess for the sake of TC one can use that side by side but anyway it worth a try for the time being until |
Beta Was this translation helpful? Give feedback.
Long story short: use https://pkg.go.dev/github.com/florianl/go-tc#example-package-EBPF.
TC is a completely separate kernel subsystem from eBPF that can currently only be interacted with using netlink sockets and its corresponding protocol. As a comparison, on older versions of the Linux kernel, attaching XDP programs also required netlink. However, due to its simplicity (XDP associates a prog FD with an ifindex, which can be retrieved by name using the Go stdlib), XDP has since received a bpf_link interface, and
cilium/ebpf
was easily extended to support it.TC, however, is significantly more complex in both its design and its implementation. Assuming the user sets up a class/qdisc hiera…