mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-10-18 22:10:04 +00:00
EBPF error handling
This commit is contained in:
79
tap/tlstapper/bpf/include/log.h
Normal file
79
tap/tlstapper/bpf/include/log.h
Normal file
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
Note: This file is licenced differently from the rest of the project
|
||||
SPDX-License-Identifier: GPL-2.0
|
||||
Copyright (C) UP9 Inc.
|
||||
*/
|
||||
|
||||
#ifndef __LOG__
|
||||
#define __LOG__
|
||||
|
||||
// The same consts defined in bpf_logger.go
|
||||
//
|
||||
#define LOG_LEVEL_ERROR (0)
|
||||
#define LOG_LEVEL_INFO (1)
|
||||
#define LOG_LEVEL_DEBUG (2)
|
||||
|
||||
// The same struct can be found in bpf_logger.go
|
||||
//
|
||||
// Be careful when editing, alignment and padding should be exactly the same in go/c.
|
||||
//
|
||||
struct log_message {
|
||||
__u32 level;
|
||||
__u32 message_code;
|
||||
__u64 arg1;
|
||||
__u64 arg2;
|
||||
__u64 arg3;
|
||||
};
|
||||
|
||||
static __always_inline void log_error(void* ctx, __u16 message_code, __u64 arg1, __u64 arg2, __u64 arg3) {
|
||||
struct log_message entry = {};
|
||||
|
||||
entry.level = LOG_LEVEL_ERROR;
|
||||
entry.message_code = message_code;
|
||||
entry.arg1 = arg1;
|
||||
entry.arg2 = arg2;
|
||||
entry.arg3 = arg3;
|
||||
|
||||
long err = bpf_perf_event_output(ctx, &log_buffer, BPF_F_CURRENT_CPU, &entry, sizeof(struct log_message));
|
||||
|
||||
if (err != 0) {
|
||||
char msg[] = "Error writing log error to perf buffer - %ld";
|
||||
bpf_trace_printk(msg, sizeof(msg), err);
|
||||
}
|
||||
}
|
||||
|
||||
static __always_inline void log_info(void* ctx, __u16 message_code, __u64 arg1, __u64 arg2, __u64 arg3) {
|
||||
struct log_message entry = {};
|
||||
|
||||
entry.level = LOG_LEVEL_INFO;
|
||||
entry.message_code = message_code;
|
||||
entry.arg1 = arg1;
|
||||
entry.arg2 = arg2;
|
||||
entry.arg3 = arg3;
|
||||
|
||||
long err = bpf_perf_event_output(ctx, &log_buffer, BPF_F_CURRENT_CPU, &entry, sizeof(struct log_message));
|
||||
|
||||
if (err != 0) {
|
||||
char msg[] = "Error writing log info to perf buffer - %ld";
|
||||
bpf_trace_printk(msg, sizeof(msg), arg1, err);
|
||||
}
|
||||
}
|
||||
|
||||
static __always_inline void log_debug(void* ctx, __u16 message_code, __u64 arg1, __u64 arg2, __u64 arg3) {
|
||||
struct log_message entry = {};
|
||||
|
||||
entry.level = LOG_LEVEL_DEBUG;
|
||||
entry.message_code = message_code;
|
||||
entry.arg1 = arg1;
|
||||
entry.arg2 = arg2;
|
||||
entry.arg3 = arg3;
|
||||
|
||||
long err = bpf_perf_event_output(ctx, &log_buffer, BPF_F_CURRENT_CPU, &entry, sizeof(struct log_message));
|
||||
|
||||
if (err != 0) {
|
||||
char msg[] = "Error writing log debug to perf buffer - %ld";
|
||||
bpf_trace_printk(msg, sizeof(msg), arg1, err);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* __LOG__ */
|
42
tap/tlstapper/bpf/include/logger_messages.h
Normal file
42
tap/tlstapper/bpf/include/logger_messages.h
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
Note: This file is licenced differently from the rest of the project
|
||||
SPDX-License-Identifier: GPL-2.0
|
||||
Copyright (C) UP9 Inc.
|
||||
*/
|
||||
|
||||
#ifndef __LOG_MESSAGES__
|
||||
#define __LOG_MESSAGES__
|
||||
|
||||
// Must be synced with bpf_logger_messages.go
|
||||
//
|
||||
#define LOG_ERROR_READING_BYTES_COUNT (0)
|
||||
#define LOG_ERROR_READING_FD_ADDRESS (1)
|
||||
#define LOG_ERROR_READING_FROM_SSL_BUFFER (2)
|
||||
#define LOG_ERROR_BUFFER_TOO_BIG (3)
|
||||
#define LOG_ERROR_ALLOCATING_CHUNK (4)
|
||||
#define LOG_ERROR_READING_SSL_CONTEXT (5)
|
||||
#define LOG_ERROR_PUTTING_SSL_CONTEXT (6)
|
||||
#define LOG_ERROR_GETTING_SSL_CONTEXT (7)
|
||||
#define LOG_ERROR_MISSING_FILE_DESCRIPTOR (8)
|
||||
#define LOG_ERROR_PUTTING_FILE_DESCRIPTOR (9)
|
||||
#define LOG_ERROR_PUTTING_ACCEPT_INFO (10)
|
||||
#define LOG_ERROR_GETTING_ACCEPT_INFO (11)
|
||||
#define LOG_ERROR_READING_ACCEPT_INFO (12)
|
||||
#define LOG_ERROR_PUTTING_FD_MAPPING (13)
|
||||
#define LOG_ERROR_PUTTING_CONNECT_INFO (14)
|
||||
#define LOG_ERROR_GETTING_CONNECT_INFO (15)
|
||||
#define LOG_ERROR_READING_CONNECT_INFO (16)
|
||||
|
||||
// Sometimes we have the same error, happening from different locations.
|
||||
// in order to be able to distinct between them in the log, we add an
|
||||
// extra number that identify the location. The number can be anything,
|
||||
// but do not give the same number to different origins.
|
||||
//
|
||||
#define ORIGIN_SSL_UPROBE_CODE (0l)
|
||||
#define ORIGIN_SSL_URETPROBE_CODE (1l)
|
||||
#define ORIGIN_SYS_ENTER_READ_CODE (2l)
|
||||
#define ORIGIN_SYS_ENTER_WRITE_CODE (3l)
|
||||
#define ORIGIN_SYS_EXIT_ACCEPT4_CODE (4l)
|
||||
#define ORIGIN_SYS_EXIT_CONNECT_CODE (5l)
|
||||
|
||||
#endif /* __LOG_MESSAGES__ */
|
@@ -70,5 +70,6 @@ BPF_LRU_HASH(ssl_write_context, __u64, struct ssl_info);
|
||||
BPF_LRU_HASH(ssl_read_context, __u64, struct ssl_info);
|
||||
BPF_HASH(file_descriptor_to_ipv4, __u64, struct fd_info);
|
||||
BPF_PERF_OUTPUT(chunks_buffer);
|
||||
BPF_PERF_OUTPUT(log_buffer);
|
||||
|
||||
#endif /* __MAPS__ */
|
||||
|
Reference in New Issue
Block a user