How to add a traffic-control filter for an egress eBPF programm in the eBPF Compiler Collection (bcc) with pyroute2?

169 Views Asked by At

I have an eBPF program that modifies egress/outgoing UDP packets.

I think I activate it by adding it to the egress traffic control filters. Because I use bcc I use the pyroute2 package for that.

But this fails:

import sys
import time
from pyroute2 import IPRoute, NetNS, IPDB, NSPopen
from bcc import BPF


def main():
    b = BPF(src_file="my_example.c", cflags=["-Wno-macro-redefined"])  
    fn = b.load_func("my_example", BPF.SCHED_CLS)

    ipr = IPRoute()
    ipr.tc("add", "clsact", 3) # '3' for my wifi interface as shown with "ip a"
    ipr.tc("add-filter", "bpf", 3, classid=1, fd=fn.fd, name=fn.name, direct_action=True)  # <<<


if __name__ == "__main__":
    main()

the error I get is

pyroute2.netlink.exceptions.NetlinkError: (2, 'No such file or directory')

Alas, the stack trace is inconclusive and does neither show which file or directory is missing, not what command failed exactly.

0

There are 0 best solutions below