问题标签 [bpf]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
370 浏览

linux - 尝试访问“struct rq”时,bpf/bcc 报告错误

这是我用来分析内核函数的 bpf 程序pick_next_task_fiar

它报告错误如下:

我的问题是为什么 bpf 无法识别 ,struct rq因为我已经包含了# include <linux/sched.h>. 然而,它确实承认struct task_struct. 这两个结构在同一个头文件中。

内核版本:ubuntu 16.04 上的 4.4.0-141-generic

0 投票
1 回答
1030 浏览

bpf - 函数“bpf”的隐式声明

我最近一直在研究 BPF,但由于一个非常基本的问题而没有进行。

我按照 man bpf(2) 中的描述包含了 linux/bpf.h,但 GCC 找不到 bpf 函数。此代码仅用于测试以确保 GCC 可以找到 bpf 函数。

GCC 输出是这样的。

我使用的是 Archlinux,linux 内核版本是 4.20.11-arch1-1-ARCH。请帮助我如何包含 bpf 功能。

0 投票
1 回答
2876 浏览

bpf - 安装 bcc 时,找不到包 bpfcc

我正在尝试在我的 Linux 机器上安装 bcc 模块,以便编写 BPF 程序。

我一直在跟进页面

https://github.com/iovisor/bcc/blob/master/INSTALL.md#kernel-configuration

构建内核并安装 bcc 模块。

但是,每当我输入

我收到一个错误:

如果我问的基本问题太多了,我很抱歉。这是唯一一个似乎有聪明人有一些答案的地方。提前谢谢你们

0 投票
1 回答
628 浏览

c - How to get the return code of the syscall using SECCOMP_RET_DATA and PTRACE_GETEVENTMSG

I'm a little bit confused trying to obtaining syscall's return value using ptrace + seccomp.

man 4 bpf says:

man 2 ptrace says:

man 2 seccomp says:

It turns out that the BPF program can not perform something further after the BPF_RET statement. So when tracee is interrupted on SECCOMP_RET_TRACE it's in the syscall-enter-stop state and the syscall has not yet been made, therefore, the return code is definitely nowhere to take. I expect that after a subsequent call PTRACE_SYSCALL, tracee will be in the syscall-exit-stop state and tracer will be able to get the result of the syscall using PTRACE_GETEVENTMSG. But it doesn't work in my sample.

I am able to get syscall's return code inspecting registers

but I wonder how to do it in the way specified in the documentation.

0 投票
2 回答
3150 浏览

linux - 如何获取我的 Linux 内核的 bpf_helpers.h 头文件?

我正在 Ubuntu 机器上开发一个 eBPF 程序:

为此,我需要bpf.h许多定义以及bpf_helpers.h辅助函数定义。我安装了一个带有标题的新内核:

标题包括bpf.h

但不是bpf_helpers.h

如何为我的内核获取此文件,为什么它不包含在分发标头中?

我可以签出特定版本的 Linux 内核或从master获取文件,但发行版可能会对上游进行更改,这让我对此感到不舒服。

0 投票
1 回答
390 浏览

linux - sockmap 是否需要任何 BPF 程序?

我正在编写一个sockmap BPF 程序,我想知道这样一个程序的要求是什么。一个 sockmap 可能附加了一个解析器和一个判断程序,所以我的问题是在将套接字添加到映射之前是否需要任何一个程序,如果两者都不需要,那么当省略任何一个程序时会发生什么行为。

一些令人困惑的相关陈述显示了我为什么有这个问题:

0 投票
1 回答
59 浏览

linux - 如何计算 BPF 辅助函数的返回码的含义?

我正在编写一个BPF_PROG_TYPE_SOCKET_OPS程序,我看到以下内容/sys/kernel/debug/tracing/trace_pipe

当我由于以下代码段加载它时:

我怎样才能弄清楚-95是什么意思?当我查看https://elixir.bootlin.com/linux/latest/source/arch/alpha/include/uapi/asm/errno.h时,我看到:

这是找到错误含义的正确方法吗?如果是这样,描述的含义是什么?

0 投票
0 回答
182 浏览

linux-kernel - 为什么将已建立的 TCP 套接字添加到 BPF_MAP_TYPE_SOCKMAP 映射会破坏 SSL?

我有以下 BPF 程序:

它所做的只是将已建立的 TCP 套接字添加到 sock_ops sockmap。然后我将该程序作为BPF_PROG_TYPE_SOCK_OPS程序加载,将其附加到 v2 cgroup 并在该 cgroup 中运行 shell。

但是,这似乎破坏了 SSL:

HTTP 按预期工作:

为什么是这样?

uname -a: Linux ubuntu-bionic 4.18.0-16-generic #17~18.04.1-Ubuntu SMP Tue Feb 12 13:35:51 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

0 投票
1 回答
250 浏览

linux - 如何在 BPF_PROG_TYPE_SK_SKB 判断程序中确定数据包的方向?

我正在编写一个BPF_PROG_TYPE_SK_SKB判决程序来做出重定向决定。如何计算数据包的方向(入口/出口)?

我可以访问每个数据包的本地和远程端口,但我无法确定哪个是源端口或目标端口,因此无法确定方向。这应该可能吗?如果不是,那为什么不呢?

uname -a: Linux ubuntu-bionic 4.18.0-16-generic #17~18.04.1-Ubuntu SMP Tue Feb 12 13:35:51 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

0 投票
1 回答
589 浏览

linux - 为什么我的 BPF_PROG_TYPE_CGROUP_SKB 程序不能在容器中运行?

我编写了以下 eBPF 程序来计算数据包:

我还有一个用户空间组件,它将程序加载为 a ,使用 attach type将其附加BPF_PROG_TYPE_CGROUP_SKB到 v2 cgroup ( ) ,将其自己的 PID 添加到该 cgroup 并开始创建网络流量。/sys/fs/cgroup/unified/fooBPF_CGROUP_INET_EGRESS

当我在容器外运行这个用户空间组件时,它按预期工作,我看到我的程序被调用了cat /sys/kernel/debug/tracing/trace_pipe

但是,当我在容器中运行我的程序时,我看不到任何输出。

我正在按如下方式运行容器:

我正在使用主机网络和 PID 命名空间来避免它们可能导致的任何潜在问题。

为什么我的程序似乎无法在容器内运行?

uname -a: Linux ubuntu-bionic 4.18.0-16-generic #17~18.04.1-Ubuntu SMP Tue Feb 12 13:35:51 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux