iovisor / bcc

BCC - Tools for BPF-based Linux IO analysis, networking, monitoring, and more
Apache License 2.0
20.64k stars 3.89k forks source link

unknown function : bpf_setsockopt #4915

Open Engage-r opened 9 months ago

Engage-r commented 9 months ago

Hey I am new to bcc and am trying to change tcp congestion control algorithm using bcc. I wrote this simple python script:

from bcc import BPF
bpf_source = """
#include <linux/bpf.h>
#include <linux/version.h>
#include <bcc/proto.h>
#include <bcc/helpers.h>
#include <linux/tcp.h>
#define TCP_CONGESTION 13
int bpf_set_congestion_control(struct bpf_sock_ops *skops) {
    if (skops == NULL)
        return 0;
    char cong_alg[] = "reno";
    bpf_setsockopt(skops, SOL_TCP, TCP_CONGESTION, cong_alg, sizeof(cong_alg));
    return 0;
}
"""
bpf = BPF(text=bpf_source)
bpf.attach_kprobe(event="tcp_v4_connect", fn_name="bpf_set_congestion_control")

but when running it throws error:

bpf: Failed to load program: Invalid argument
10: (85) call bpf_setsockopt#49
unknown func bpf_setsockopt#49

Would be highly obliged if someone could help

ZhangYet commented 4 months ago

What version of kernel do you use?

bpf_setsockopt was introduced since v4.13.

See https://ebpf-docs.dylanreimerink.nl/linux/helper-function/bpf_setsockopt/