Skip to content
Merged
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: 4 additions & 4 deletions bpf/generictracer/k_tracer.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ int BPF_KRETPROBE(obi_kretprobe_sys_accept4, s32 fd) {
// TODO: try to merge with store_accept_fd_info() above
bpf_map_update_elem(&fd_to_connection, &key, &info.p_conn.conn, BPF_ANY);

u64 accept_time = bpf_ktime_get_ns();
const u64 accept_time = bpf_ktime_get_ns();

bpf_map_update_elem(&accepted_connections, &info.p_conn.conn, &accept_time, BPF_ANY);
} else {
Expand Down Expand Up @@ -1002,7 +1002,7 @@ int obi_socket__http_filter(struct __sk_buff *skb) {
//bpf_d_printk("http buf=[%s] [%s]", buf, __FUNCTION__);
//d_print_http_connection_info(&conn);
if (packet_type == PACKET_TYPE_REQUEST) {
u64 cookie = bpf_get_socket_cookie(skb);
const u64 cookie = bpf_get_socket_cookie(skb);
//bpf_dbg_printk("cookie=%llx, len=%d, buf=[%s]", cookie, len, buf);
//dbg_print_http_connection_info(&conn);

Expand Down Expand Up @@ -1170,8 +1170,8 @@ int obi_handle_buf_with_args(void *ctx) {
(info) ? still_reading(info) : 0);

if (info && !info->submitted) {
u8 reading = still_reading(info);
u8 responding = still_responding(info);
const u8 reading = still_reading(info);
const u8 responding = still_responding(info);
// Still reading checks if we are processing buffers of a HTTP request
// that has started, but we haven't seen a response yet.
if (reading || responding) {
Expand Down
8 changes: 4 additions & 4 deletions bpf/gotracer/go_nethttp.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ int obi_uprobe_ginGetValueRet(struct pt_regs *ctx) {
bpf_map_lookup_elem(&ongoing_http_server_requests, &g_key);

off_table_t *ot = get_offsets_table();
u64 fullpath_off = go_offset_of(ot, (go_offset){.v = _gin_fullpath_pos});
const u64 fullpath_off = go_offset_of(ot, (go_offset){.v = _gin_fullpath_pos});

bpf_dbg_printk("goroutine_addr=%lx, invocation=%llx, fullpath_off=%d",
goroutine_addr,
Expand All @@ -273,7 +273,7 @@ int obi_uprobe_ginGetValueRet(struct pt_regs *ctx) {
// registers
if (fullpath_off == _gin_fullpath_off_pre_17) {
void *ptr = GO_PARAM8(ctx);
u64 len = (u64)GO_PARAM9(ctx);
const u64 len = (u64)GO_PARAM9(ctx);

if (ptr) {
bpf_dbg_printk("pre gin 1.7.0 fullPath from: %llx", ptr);
Expand All @@ -282,7 +282,7 @@ int obi_uprobe_ginGetValueRet(struct pt_regs *ctx) {
}
} else {
void *ptr = GO_PARAM6(ctx);
u64 len = (u64)GO_PARAM7(ctx);
const u64 len = (u64)GO_PARAM7(ctx);

if (ptr) {
bpf_dbg_printk("post gin 1.7.0 fullPath from: %llx", ptr);
Expand Down Expand Up @@ -950,7 +950,7 @@ int obi_uprobe_http2ResponseWriterStateWriteHeader(struct pt_regs *ctx) {
bpf_dbg_printk("=== uprobe/http2ResponseWriterStateWriteHeader ===");

void *goroutine_addr = GOROUTINE_PTR(ctx);
u64 status = (u64)GO_PARAM2(ctx);
const u64 status = (u64)GO_PARAM2(ctx);
bpf_dbg_printk("goroutine_addr=%lx, status=%d", goroutine_addr, status);
go_addr_key_t g_key = {};
go_addr_key_from_id(&g_key, goroutine_addr);
Expand Down
4 changes: 2 additions & 2 deletions bpf/gotracer/go_redis.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ int obi_uprobe_redis_with_writer(struct pt_regs *ctx) {
&conn_ptr, sizeof(conn_ptr), (void *)(tcp_conn_ptr + 8)); // find conn
bpf_dbg_printk("conn_ptr=%llx", conn_ptr);
if (conn_ptr) {
u8 ok = get_conn_info(conn_ptr, &req->conn);
const u8 ok = get_conn_info(conn_ptr, &req->conn);
if (!ok) {
__builtin_memset(&req->conn, 0, sizeof(connection_info_t));
}
Expand Down Expand Up @@ -161,7 +161,7 @@ int obi_uprobe_redis_with_writer_ret(struct pt_regs *ctx) {
if (bw) {
bpf_dbg_printk("Found bw: %llx", bw);

u64 io_writer_buf_ptr_pos =
const u64 io_writer_buf_ptr_pos =
go_offset_of(ot, (go_offset){.v = _io_writer_buf_ptr_pos});

void *buf = 0;
Expand Down
6 changes: 3 additions & 3 deletions bpf/gotracer/go_runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ enum offsets : u8 {

SEC("uprobe/runtime.mstart1")
int obi_uprobe_runtime_mstart1(struct pt_regs *ctx) {
u64 pid_tgid = bpf_get_current_pid_tgid();
const u64 pid_tgid = bpf_get_current_pid_tgid();

void *g = (void *)GOROUTINE_PTR(ctx);
void *m = NULL;
Expand Down Expand Up @@ -190,7 +190,7 @@ int obi_uprobe_runtime_mexit(struct pt_regs *ctx) {
// gp *g, oldval, newval uint32
SEC("uprobe/runtime.casgstatus")
int obi_uprobe_runtime_casgstatus(struct pt_regs *ctx) {
u64 pid_tgid = bpf_get_current_pid_tgid();
const u64 pid_tgid = bpf_get_current_pid_tgid();

void *g = (void *)GO_PARAM1(ctx);
void *m = NULL;
Expand Down Expand Up @@ -219,7 +219,7 @@ int obi_uprobe_runtime_casgstatus(struct pt_regs *ctx) {
};
grpc_srv_func_invocation_t *invocation;

u32 newval = (u32)(uintptr_t)GO_PARAM3(ctx);
const u32 newval = (u32)(uintptr_t)GO_PARAM3(ctx);
switch (newval) {
case g_running:
case g_syscall:
Expand Down
8 changes: 4 additions & 4 deletions bpf/gpuevent/cuda.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ enum {
SEC("uprobe/cudaLaunchKernel")
int BPF_KPROBE(obi_cuda_launch, u64 func_off, u64 grid_xy, u64 grid_z, u64 block_xy, u64 block_z) {
(void)ctx;
u64 id = bpf_get_current_pid_tgid();
const u64 id = bpf_get_current_pid_tgid();

if (!valid_pid(id)) {
return 0;
Expand Down Expand Up @@ -68,7 +68,7 @@ int BPF_KPROBE(obi_cuda_malloc, void **devPtr, size_t size) {
(void)ctx;
(void)devPtr;

u64 id = bpf_get_current_pid_tgid();
const u64 id = bpf_get_current_pid_tgid();

if (!valid_pid(id)) {
return 0;
Expand Down Expand Up @@ -96,7 +96,7 @@ int BPF_KPROBE(obi_cuda_memcpy, void *dst, void *src, size_t size, u8 kind) {
(void)dst;
(void)src;

u64 id = bpf_get_current_pid_tgid();
const u64 id = bpf_get_current_pid_tgid();

if (!valid_pid(id)) {
return 0;
Expand All @@ -122,7 +122,7 @@ int BPF_KPROBE(obi_cuda_memcpy, void *dst, void *src, size_t size, u8 kind) {
SEC("uprobe/cudaGraphLaunch")
int BPF_KPROBE(obi_graph_launch) {
(void)ctx;
u64 id = bpf_get_current_pid_tgid();
const u64 id = bpf_get_current_pid_tgid();

if (!valid_pid(id)) {
return 0;
Expand Down
2 changes: 1 addition & 1 deletion bpf/logenricher/logenricher.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ int BPF_KPROBE(obi_kprobe_tty_write, struct kiocb *iocb, struct iov_iter *from)
struct tty_file_private *tfp =
(struct tty_file_private *)BPF_CORE_READ(iocb, ki_filp, private_data);
struct tty_struct *tty = BPF_CORE_READ(tfp, tty);
bool is_master = tty_driver_is_pty(tty) && tty_driver_is_master(tty);
const bool is_master = tty_driver_is_pty(tty) && tty_driver_is_master(tty);

struct tty_dev master = {};
struct tty_dev slave = {};
Expand Down
6 changes: 3 additions & 3 deletions bpf/netolly/flows.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ static inline int flow_monitor(struct __sk_buff *skb) {
}
id.if_index = skb->ifindex;

u64 current_time = bpf_ktime_get_ns();
const u64 current_time = bpf_ktime_get_ns();

// TODO: we need to add spinlock here when we deprecate versions prior to 5.1, or provide
// a spinlocked alternative version and use it selectively https://lwn.net/Articles/779120/
Expand All @@ -181,7 +181,7 @@ static inline int flow_monitor(struct __sk_buff *skb) {
}
aggregate_flow->flags |= flags;

long ret = bpf_map_update_elem(&aggregated_flows, &id, aggregate_flow, BPF_ANY);
const long ret = bpf_map_update_elem(&aggregated_flows, &id, aggregate_flow, BPF_ANY);
if (trace_messages && ret != 0) {
// usually error -16 (-EBUSY) is printed here.
// In this case, the flow is dropped, as submitting it to the ringbuffer would cause
Expand Down Expand Up @@ -234,7 +234,7 @@ static inline int flow_monitor(struct __sk_buff *skb) {

// even if we know that the entry is new, another CPU might be concurrently inserting a flow
// so we need to specify BPF_ANY
long ret = bpf_map_update_elem(&aggregated_flows, &id, &new_flow, BPF_ANY);
const long ret = bpf_map_update_elem(&aggregated_flows, &id, &new_flow, BPF_ANY);
if (ret != 0) {
// usually error -16 (-EBUSY) or -7 (E2BIG) is printed here.
// In this case, we send the single-packet flow via ringbuffer as in the worst case we can have
Expand Down
2 changes: 1 addition & 1 deletion bpf/netolly/flows_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ static inline u8 get_connection_initiator(flow_id *id, u16 flags) {
conn_initiator_key initiator_key;
// from the initiator_key with sorted ip/ports, know the index of the
// endpoint that that initiated the connection, which might be the low or the high address
u8 low_is_src = fill_conn_initiator_key(id, &initiator_key);
const u8 low_is_src = fill_conn_initiator_key(id, &initiator_key);
u8 *initiator = (u8 *)bpf_map_lookup_elem(&conn_initiators, &initiator_key);
u8 initiator_index = INITIATOR_UNKNOWN;
if (initiator == NULL) {
Expand Down
6 changes: 3 additions & 3 deletions bpf/netolly/flows_sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ int obi_socket__filter(struct __sk_buff *skb) {
return TC_ACT_UNSPEC;
}

u64 current_time = bpf_ktime_get_ns();
const u64 current_time = bpf_ktime_get_ns();

// TODO: we need to add spinlock here when we deprecate versions prior to 5.1, or provide
// a spinlocked alternative version and use it selectively https://lwn.net/Articles/779120/
Expand All @@ -219,7 +219,7 @@ int obi_socket__filter(struct __sk_buff *skb) {
}
aggregate_flow->flags |= flags;

long ret = bpf_map_update_elem(&aggregated_flows, &id, aggregate_flow, BPF_ANY);
const long ret = bpf_map_update_elem(&aggregated_flows, &id, aggregate_flow, BPF_ANY);
if (trace_messages && ret != 0) {
// usually error -16 (-EBUSY) is printed here.
// In this case, the flow is dropped, as submitting it to the ringbuffer would cause
Expand Down Expand Up @@ -271,7 +271,7 @@ int obi_socket__filter(struct __sk_buff *skb) {

// even if we know that the entry is new, another CPU might be concurrently inserting a flow
// so we need to specify BPF_ANY
long ret = bpf_map_update_elem(&aggregated_flows, &id, &new_flow, BPF_ANY);
const long ret = bpf_map_update_elem(&aggregated_flows, &id, &new_flow, BPF_ANY);
if (ret != 0) {
// usually error -16 (-EBUSY) or -7 (E2BIG) is printed here.
// In this case, we send the single-packet flow via ringbuffer as in the worst case we can have
Expand Down
14 changes: 7 additions & 7 deletions bpf/pid/pid.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ enum { k_prime_hash = 192053 }; // closest prime to k_max_concurrent_pids * 64

static __always_inline u8 pid_matches(pid_data_t *p) {
// combine the namespace id and the pid into one single u64
u64 k = (((u64)p->ns) << 32) | p->pid;
const u64 k = (((u64)p->ns) << 32) | p->pid;

// divide with prime number lower than max pids * 64, modulo with primes gives good hash functions
u32 h = (u32)(k % k_prime_hash);
u32 segment = h / 64; // divide by the segment size (8 bytes) to find the segment
u32 bit = h & 63; // lowest 64 bits gives us the placement inside the segment
const u32 h = (u32)(k % k_prime_hash);
const u32 segment = h / 64; // divide by the segment size (8 bytes) to find the segment
const u32 bit = h & 63; // lowest 64 bits gives us the placement inside the segment

u64 *v = bpf_map_lookup_elem(&valid_pids, &segment);
if (!v) {
Expand All @@ -40,7 +40,7 @@ static __always_inline u8 pid_matches(pid_data_t *p) {
}

static __always_inline u32 valid_pid(u64 id) {
u32 a_pid = id >> 32;
const u32 a_pid = id >> 32;
// accept all PIDs if debugging OTEL_EBPF_BPF_PID_FILTER_OFF option is set
if (!filter_pids) {
return a_pid;
Expand All @@ -63,15 +63,15 @@ static __always_inline u32 valid_pid(u64 id) {
if (a_pid != 0) {
pid_data_t p_key = {.pid = a_pid, .ns = pid_ns_id};

u8 found_ns_pid = pid_matches(&p_key);
const u8 found_ns_pid = pid_matches(&p_key);

if (found_ns_pid) {
bpf_map_update_elem(&pid_cache, &a_pid, &a_pid, BPF_ANY);
return a_pid;
} else if (ns_ppid != 0) {
pid_data_t pp_key = {.pid = ns_ppid, .ns = pid_ns_id};

u8 found_ns_ppid = pid_matches(&pp_key);
const u8 found_ns_ppid = pid_matches(&pp_key);

if (found_ns_ppid) {
bpf_map_update_elem(&pid_cache, &a_pid, &a_pid, BPF_ANY);
Expand Down
2 changes: 1 addition & 1 deletion bpf/watcher/watcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ int obi_kprobe_sys_bind(struct pt_regs *ctx) {
return 0;
}

u16 port = get_sockaddr_port_user(addr);
const u16 port = get_sockaddr_port_user(addr);

if (!port) {
return 0;
Expand Down
Loading