Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add remote device support via bpfd #2298

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions SPECS/bcc+clang.spec
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ Requires: python-bcc
%description -n bcc-tools
Command line tools for BPF Compiler Collection (BCC)

%package -n bpfd
Summary: Proxy daemon for remote target devices
%description -n bpfd
Proxy daemon for remote target devices

%files -n python-bcc
%{python_sitelib}/bcc*

Expand All @@ -99,3 +104,6 @@ Command line tools for BPF Compiler Collection (BCC)
/usr/share/bcc/introspection/*
/usr/share/bcc/tools/*
/usr/share/bcc/man/*

%files -n bpfd
/usr/bin/bpfd
8 changes: 8 additions & 0 deletions SPECS/bcc.spec
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ Requires: %{python_bcc} = %{version}-%{release}
%description -n bcc-tools
Command line tools for BPF Compiler Collection (BCC)

%package -n bpfd
Summary: Proxy daemon for remote target devices
%description -n bpfd
Proxy daemon for remote target devices

%files -n libbcc
/usr/lib64/*
/usr/include/bcc/*
Expand Down Expand Up @@ -169,6 +174,9 @@ Command line tools for BPF Compiler Collection (BCC)
/usr/share/bcc/tools/*
/usr/share/bcc/man/*

%files -n bpfd
/usr/bin/bpfd

%post -n libbcc -p /sbin/ldconfig

%postun -n libbcc -p /sbin/ldconfig
Expand Down
1 change: 1 addition & 0 deletions debian/bpfd.install
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
usr/bin/bpfd
4 changes: 4 additions & 0 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,7 @@ Provides: bpfcc-lua
Conflicts: bpfcc-lua
Depends: libbcc (= ${binary:Version})
Description: Standalone tool to run BCC tracers written in Lua

Package: bpfd
Architecture: all
Description: Proxy daemon for remote target devices
1 change: 1 addition & 0 deletions src/cc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ if(ENABLE_USDT)
endif()

add_subdirectory(frontends)
add_subdirectory(bpfd)

# Link against LLVM libraries
target_link_libraries(bcc-shared ${bcc_common_libs_for_s})
Expand Down
16 changes: 14 additions & 2 deletions src/cc/bcc_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@
#include "bpf_module.h"

extern "C" {

// This stores the appropriate callback function to invoke when there is a
// need to create a map. This is done so that the Python interface can pass
// custom callbacks to create maps for situations wherein the map creation
// functions provided by libbbc are not sufficient (e.g. when there is a need
// to create maps on remote target devices).
bpf_create_map_cb_t bpf_create_map_cb;

void * bpf_module_create_b(const char *filename, const char *proto_filename, unsigned flags) {
auto mod = new ebpf::BPFModule(flags);
if (mod->load_b(filename, proto_filename) != 0) {
Expand All @@ -27,7 +35,9 @@ void * bpf_module_create_b(const char *filename, const char *proto_filename, uns
}

void * bpf_module_create_c(const char *filename, unsigned flags, const char *cflags[],
int ncflags, bool allow_rlimit) {
int ncflags, bool allow_rlimit, bpf_create_map_cb_t map_cb) {
bpf_create_map_cb = map_cb;

auto mod = new ebpf::BPFModule(flags, nullptr, true, "", allow_rlimit);
if (mod->load_c(filename, cflags, ncflags) != 0) {
delete mod;
Expand All @@ -37,7 +47,9 @@ void * bpf_module_create_c(const char *filename, unsigned flags, const char *cfl
}

void * bpf_module_create_c_from_string(const char *text, unsigned flags, const char *cflags[],
int ncflags, bool allow_rlimit) {
int ncflags, bool allow_rlimit, bpf_create_map_cb_t map_cb) {
bpf_create_map_cb = map_cb;

auto mod = new ebpf::BPFModule(flags, nullptr, true, "", allow_rlimit);
if (mod->load_string(text, cflags, ncflags) != 0) {
delete mod;
Expand Down
7 changes: 5 additions & 2 deletions src/cc/bcc_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@
extern "C" {
#endif

typedef int (*bpf_create_map_cb_t)(void *data, bool allow_rlimit);
extern bpf_create_map_cb_t bpf_create_map_cb;

void * bpf_module_create_b(const char *filename, const char *proto_filename, unsigned flags);
void * bpf_module_create_c(const char *filename, unsigned flags, const char *cflags[], int ncflags,
bool allow_rlimit);
bool allow_rlimit, bpf_create_map_cb_t map_cb);
void * bpf_module_create_c_from_string(const char *text, unsigned flags, const char *cflags[],
int ncflags, bool allow_rlimit);
int ncflags, bool allow_rlimit, bpf_create_map_cb_t map_cb);
void bpf_module_destroy(void *program);
char * bpf_module_license(void *program);
unsigned bpf_module_kern_version(void *program);
Expand Down
6 changes: 5 additions & 1 deletion src/cc/bpf_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "exported_files.h"
#include "libbpf.h"
#include "bcc_btf.h"
#include "bcc_common.h"
#include "libbpf/src/bpf.h"

namespace ebpf {
Expand Down Expand Up @@ -340,7 +341,10 @@ int BPFModule::load_maps(sec_map_def &sections) {
attr.btf_value_type_id = map_tids[map_name].second;
}

fd = bcc_create_map_xattr(&attr, allow_rlimit_);
if (bpf_create_map_cb)
fd = bpf_create_map_cb(&attr, allow_rlimit_);
else
fd = bcc_create_map_xattr(&attr, allow_rlimit_);
if (fd < 0) {
fprintf(stderr, "could not open bpf map: %s, error: %s\n",
map_name, strerror(errno));
Expand Down
30 changes: 30 additions & 0 deletions src/cc/bpfd/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright (c) Jazel Canseco, 2018
# Copyright (c) Adrian Ratiu, 2019
# Licensed under the Apache License, Version 2.0 (the "License")

cmake_minimum_required(VERSION 2.8.7)

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake)

find_package(LibElf REQUIRED)
find_package(ZLIB REQUIRED)

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..
${CMAKE_CURRENT_SOURCE_DIR}/../libbpf/include
${CMAKE_CURRENT_SOURCE_DIR}/../libbpf/include/uapi)

add_library(bcc-bpfd-static STATIC ../common.cc ../bcc_syms.cc ../ns_guard.cc ../bcc_proc.c
../libbpf.c ../perf_reader.c ../bcc_elf.c ../bcc_perf_map.c)

file(GLOB libbpf_sources "../libbpf/src/*.c")
add_library(bpf-bpfd-static STATIC ../libbpf.c ${libbpf_sources})

add_executable(bpfd bpfd.c base64.c remote_perf_reader.c utils.c cmd_parsers.c)
target_link_libraries(bpfd bpf-bpfd-static bcc-bpfd-static)
target_link_libraries(bpfd ${LIBELF_LIBRARIES} ${ZLIB_LIBRARIES})

install(TARGETS bpfd RUNTIME DESTINATION bin)
Loading