【问题标题】:Printing Hello World using uBPF?使用 uBPF 打印 Hello World?
【发布时间】:2021-08-13 21:54:11
【问题描述】:

我最近在搞乱 uBPF,并注意到我似乎无法在 uBPF 中实现任何打印功能。我尝试将我的代码直接添加到 VM 文件夹中的 test.c,但将其作为注册函数,但我留下了重定位错误,让我没有解决方案。我已经看到了 OKO 的实现,但这似乎也不能解决我的问题。

这是我的注册码:

static void
register_functions(struct ubpf_vm *vm)
{
    ubpf_register(vm, 0, "gather_bytes", gather_bytes);
    ubpf_register(vm, 1, "memfrob", memfrob);
    ubpf_register(vm, 2, "trash_registers", trash_registers);
    ubpf_register(vm, 3, "ubpf_printf", ubpf_printf);
}

这里是打印函数本身:

static void
ubpf_printf(const char *fmt, ...)
{
    va_list args;
    va_start(args, fmt);
    char str[MAX_PRINTF_LENGTH];
    if (vsnprintf(str, MAX_PRINTF_LENGTH, fmt, args) >= 0)
        VLOG_ERR("%s", str);
    va_end(args);
}

我的问题是如何实现可以打印任何我想要的打印功能?

编辑:在 test.c 中实现我的测试功能后,添加错误本身。 vlog.h 文件在那里,但我似乎仍然收到错误。

make -C vm
make: Entering directory '/home/pi/Desktop/ubpfModified/vm'
cc -Wall -Werror -Iinc -O2 -g -Wunused-parameter   -c -o test.o test.c
test.c:32:10: fatal error: /home/pi/Desktop/ubpf/vm/vlog.h: No such file or directory
   32 | #include "/home/pi/Desktop/ubpf/vm/vlog.h"
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make: *** [<builtin>: test.o] Error 1
make: Leaving directory '/home/pi/Desktop/ubpfModified/vm'

【问题讨论】:

  • 你能分享你遇到的错误吗?
  • 抱歉刚刚编辑了错误:make -C vm make: Entering directory '/home/pi/Desktop/ubpfModified/vm' cc -Wall -Werror -Iinc -O2 -g -Wunused-parameter -c -o test.o test.c test.c:32:10: fatal error: /home/pi/Desktop/ubpf/vm/vlog.h: No such file or directory 32 | #include "/home/pi/Desktop/ubpf/vm/vlog.h" | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ compilation terminated. make: *** [&lt;builtin&gt;: test.o] Error 1 make: Leaving directory '/home/pi/Desktop/ubpfModified/vm' 有没有办法为我写的函数调用 test.c?因为我似乎不能悲伤地打电话给他们。

标签: bpf ebpf


【解决方案1】:

错误消息告诉您所需的一切。这与您的实现无关,而是与您尝试包含但编译器找不到的标头有关。

您显然从 Oko 复制了一些代码,例如 VLOG_ERR() 似乎在 oko/include/openvswitch/vlog.h 中定义。您可能添加了 #include "vlog.h",但没有将相关文件添加到您的 repo 中?

【讨论】:

    猜你喜欢
    • 2018-03-11
    • 2014-01-10
    • 2017-09-29
    • 2015-05-04
    • 1970-01-01
    • 1970-01-01
    • 2012-10-06
    • 2013-08-23
    • 1970-01-01
    相关资源
    最近更新 更多