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 support for remote target devices via BPFd #1675

Closed
wants to merge 5 commits into from
Closed
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
9 changes: 9 additions & 0 deletions SPECS/bcc+clang.spec
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ 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
Requires: libbcc = %{version}-%{release}
%description -n bpfd
Proxy daemon for remote target devices

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

Expand All @@ -99,3 +105,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
9 changes: 9 additions & 0 deletions SPECS/bcc.spec
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ 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
Requires: libbcc = %{version}-%{release}
%description -n bpfd
Proxy daemon for remote target devices

%files -n libbcc
/usr/lib64/*
/usr/include/bcc/*
Expand All @@ -117,6 +123,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
5 changes: 5 additions & 0 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,8 @@ Package: bcc-lua
Architecture: all
Depends: libbcc
Description: Standalone tool to run BCC tracers written in Lua

Package: bpfd
Architecture: all
Depends: libbcc
Description: Proxy daemon for remote target devices
1 change: 1 addition & 0 deletions debian/libbcc.install
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
usr/include/bcc/*
usr/lib/*/libbcc*
usr/lib/*/libbpf*
usr/lib/*/pkgconfig/libbcc.pc
1 change: 1 addition & 0 deletions src/cc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,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
20 changes: 18 additions & 2 deletions src/cc/bpf_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 @@ -26,7 +34,11 @@ void * bpf_module_create_b(const char *filename, const char *proto_filename, uns
return mod;
}

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

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

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

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

typedef void (*bpf_create_map_cb_t)(void *data);
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);
void * bpf_module_create_c_from_string(const char *text, unsigned flags, const char *cflags[], int ncflags);
void *bpf_module_create_c(const char *filename, unsigned flags,
const char *cflags[], int ncflags,
bpf_create_map_cb_t map_cb);
void *bpf_module_create_c_from_string(const char *text, unsigned flags,
const char *cflags[], int ncflags,
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
8 changes: 8 additions & 0 deletions src/cc/bpfd/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright (c) Jazel Canseco, 2018
# Licensed under the Apache License, Version 2.0 (the "License")

add_executable(bpfd bpfd.c base64.c remote_perf_reader.c utils.c cmd_parsers.c)
target_link_libraries(bpfd bpf-shared)
target_link_libraries(bpfd bcc-shared)

install(TARGETS bpfd RUNTIME DESTINATION bin)
Loading