report bpf_current_task_under_cgroup() errors to userspace
authorMatteo Croce <teknoraver@meta.com>
Fri, 11 Oct 2024 16:26:58 +0000 (18:26 +0200)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 11 Oct 2024 19:47:18 +0000 (04:47 +0900)
commit75355f22db6889a0d7bf881c3b825a4818cd69e1
treed1b98fbdfa461c4da373b98139810d83ea5f337b
parentb950a8acd87d9c054e22b3f1c387cc5650e386ab
report bpf_current_task_under_cgroup() errors to userspace

bpf_current_task_under_cgroup() returns 1 if the task is under the
specified cgroup, 0 if not, negative if an error happens.

Differentiate the 1 and -1 cases, and report to userspace when we got
and error.
An error like this is mostly unlikely, the only common one is that the
userspace doesn't populate the map, and the call returns -EAGAIN.

Tested by mocking the return value of bpf_current_task_under_cgroup():
    Enumeration completed
    enp1s0f0np0: Configuring with /etc/systemd/network/20-test.network.
    Sysctl monitor BPF returned error: Link number out of range
    Sysctl monitor BPF returned error: No CSI structure available
    Sysctl monitor BPF returned error: Invalid exchange
    Sysctl monitor BPF returned error: Exchange full
    Sysctl monitor BPF returned error: Invalid request code
    Sysctl monitor BPF returned error: Unknown error 58
    Sysctl monitor BPF returned error: Device not a stream
    Sysctl monitor BPF returned error: Timer expired
    Sysctl monitor BPF returned error: Machine is not on the network
    Sysctl monitor BPF returned error: Object is remote
    Sysctl monitor BPF returned error: Advertise error
src/network/bpf/sysctl_monitor/sysctl-monitor.bpf.c