Skip to content

Commit

Permalink
new(sinsp-example): add gvisor support
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Terzolo <[email protected]>
  • Loading branch information
Andreagit97 committed Dec 5, 2024
1 parent 9bf9463 commit e2ae71e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
4 changes: 2 additions & 2 deletions userspace/libscap/engine/gvisor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ add_library(
scap_engine_gvisor ${scap_engine_gvisor_sources} ${scap_engine_gvisor_generated_sources}
)

add_dependencies(scap_engine_gvisor uthash jsoncpp)
add_dependencies(scap_engine_gvisor uthash jsoncpp scap_event_schema)
target_link_libraries(
scap_engine_gvisor PUBLIC scap_platform_util scap_error ${CMAKE_THREAD_LIBS_INIT}
${PROTOBUF_LIB} ${JSONCPP_LIB}
${PROTOBUF_LIB} ${JSONCPP_LIB} scap_event_schema
)

target_include_directories(scap_engine_gvisor PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
Expand Down
21 changes: 19 additions & 2 deletions userspace/libsinsp/examples/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ static string engine_string;
static string filter_string = "";
static string file_path = "";
static string bpf_path = "";
static string gvisor_config_path = "/etc/docker/runsc_falco_config.json";
static unsigned long buffer_bytes_dim = DEFAULT_DRIVER_BUFFER_BYTES_DIM;
static uint64_t max_events = UINT64_MAX;
static std::shared_ptr<sinsp_plugin> plugin;
Expand Down Expand Up @@ -110,6 +111,7 @@ Overview: Goal of sinsp-example binary is to test and debug sinsp functionality
-b <path>, --bpf <path> BPF probe.
-m, --modern_bpf modern BPF probe.
-k, --kmod Kernel module
-G <config_path>, --gvisor <config_path> Gvisor engine
-s <path>, --scap_file <path> Scap file
-p <path>, --plugin <path> Plugin. Path can follow the pattern "filepath.so|init_cfg|open_params".
-d <dim>, --buffer_dim <dim> Dimension in bytes that every per-CPU buffer will have.
Expand Down Expand Up @@ -155,13 +157,17 @@ void parse_CLI_options(sinsp& inspector, int argc, char** argv) {
{"remove-io-sc-state", no_argument, 0, 'q'},
{"enable-glogger", no_argument, 0, 'g'},
{"raw", no_argument, 0, 'r'},
{"gvisor", optional_argument, 0, 'G'},
{0, 0, 0, 0}};

bool format_set = false;
int op;
int long_index = 0;
while((op = getopt_long(argc, argv, "hf:jab:mks:p:d:o:En:zxqgr", long_options, &long_index)) !=
-1) {
while((op = getopt_long(argc,

Check warning on line 166 in userspace/libsinsp/examples/test.cpp

View check run for this annotation

Codecov / codecov/patch

userspace/libsinsp/examples/test.cpp#L166

Added line #L166 was not covered by tests
argv,
"hf:jab:mks:p:d:o:En:zxqgrG::",
long_options,
&long_index)) != -1) {
switch(op) {
case 'h':
usage();
Expand All @@ -186,6 +192,12 @@ void parse_CLI_options(sinsp& inspector, int argc, char** argv) {
select_engine(BPF_ENGINE);
bpf_path = optarg;
break;
case 'G':
engine_string = GVISOR_ENGINE;

Check warning on line 196 in userspace/libsinsp/examples/test.cpp

View check run for this annotation

Codecov / codecov/patch

userspace/libsinsp/examples/test.cpp#L195-L196

Added lines #L195 - L196 were not covered by tests
if(optarg != nullptr) {
gvisor_config_path = optarg;

Check warning on line 198 in userspace/libsinsp/examples/test.cpp

View check run for this annotation

Codecov / codecov/patch

userspace/libsinsp/examples/test.cpp#L198

Added line #L198 was not covered by tests
}
break;
case 'm':
select_engine(MODERN_BPF_ENGINE);
break;
Expand Down Expand Up @@ -349,6 +361,11 @@ void open_engine(sinsp& inspector, libsinsp::events::set<ppm_sc_code> events_sc_
plugin->id() == 0 ? sinsp_plugin_platform::SINSP_PLATFORM_FULL
: sinsp_plugin_platform::SINSP_PLATFORM_HOSTINFO);
}
#endif
#ifdef HAS_ENGINE_GVISOR
else if(!engine_string.compare(GVISOR_ENGINE)) {
inspector.open_gvisor(gvisor_config_path, "", false, -1);
}
#endif
else {
std::cerr << "Unknown engine" << std::endl;
Expand Down

0 comments on commit e2ae71e

Please sign in to comment.