// SPDX-License-Identifier: GPL-3.0-or-later
#include <sys/time.h>
#include <sys/resource.h>
#include "ebpf.h"
// callback required by eval()
int health_variable_lookup(const char *variable, uint32_t hash, struct rrdcalc *rc, calculated_number *result) {
(void)variable;
(void)hash;
(void)rc;
(void)result;
return 0;
};
void send_statistics( const char *action, const char *action_result, const char *action_data) {
(void) action;
(void) action_result;
(void) action_data;
return;
}
// callbacks required by popen()
void signals_block(void) {};
void signals_unblock(void) {};
void signals_reset(void) {};
// required by get_system_cpus()
char *netdata_configured_host_prefix = "";
// callback required by fatal()
void netdata_cleanup_and_exit(int ret) {
exit(ret);
}
// ----------------------------------------------------------------------
char *ebpf_plugin_dir = PLUGINS_DIR;
static char *ebpf_user_config_dir = CONFIG_DIR;
static char *ebpf_stock_config_dir = LIBCONFIG_DIR;
static char *ebpf_configured_log_dir = LOG_DIR;
static int update_every = 1;
static int thread_finished = 0;
int close_ebpf_plugin = 0;
struct config collector_config = { .first_section = NULL, .last_section = NULL, .mutex = NETDATA_MUTEX_INITIALIZER,
.index = { .avl_tree = { .root = NULL, .compar = appconfig_section_compare },
.rwlock = AVL_LOCK_INITIALIZER } };
int running_on_kernel = 0;
char kernel_string[64];
int ebpf_nprocs;
static int isrh;
netdata_idx_t *hash_values;
pthread_mutex_t lock;
netdata_ebpf_events_t process_probes[] = {
{ .type = 'r', .name = "vfs_write" },
{ .type = 'r', .name = "vfs_writev" },
{ .type = 'r', .name = "vfs_read" },
{ .type = 'r', .name = "vfs_readv" },
{ .type = 'r', .name = "do_sys_open" },
{ .type = 'r', .name = "vfs_unlink" },
{ .type = 'p', .name = "do_exit" },
{ .type = 'p', .name = "release_task" },
{ .type = 'r', .name = "_do_fork" },
{ .type = 'r', .name = "__close_fd" },
{ .type = 'r', .name = "__x64_sys_clone" },
{ .type = 0, .name = NULL }
};
netdata_ebpf_events_t socket_probes[] = {
{ .type = 'r', .name = "tcp_sendmsg" },
{ .type = 'p', .name = "tcp_cleanup_rbuf" },
{ .type = 'p', .name = "tcp_close" },
{ .type = 'p', .name = "udp_recvmsg" },
{ .type = 'r', .name = "udp_recvmsg" },
{ .type = 'r', .name = "udp_sendmsg" },
{ .type = 'p', .name = "do_exit" },
{ .type = 0, .name = NULL }
};
ebpf_module_t ebpf_modules[] = {
{ .thread_name = "process", .config_name = "process", .enabled = 0, .start_routine = ebpf_process_thread,
.update_time = 1, .global_charts = 1, .apps_charts = 1, .mode = MODE_ENTRY, .probes = process_probes },
{ .thread_name = "socket", .config_name = "network viewer", .enabled = 0, .start_routine = ebpf_socket_thread,
.update_time = 1, .global_charts = 1, .apps_charts = 1, .mode = MODE_ENTRY, .probes = socket_probes },
{ .thread_name = NULL, .enabled = 0, .start_routine = NULL, .update_time = 1,
.global_charts = 0, .apps_charts = 1, .mode = MODE_ENTRY, .probes = NULL },
};
/**
* Close the collector gracefully
*
* @param sig is the signal number used to close the collector
*/
static void ebpf_exit(int sig)
{