Skip to content
API Documentation
BastionGuard™
bsc::ebpf Namespace Reference

Classes

struct  ConnEvent
class  EBPFMon

Enumerations

enum  EventKind : uint8_t { EVT_TP_SET_STATE = 0 , EVT_TCP_CONNECT = 1 , EVT_UDP_SENDMSG = 2 }

Functions

bsc::model::Connection event_to_connection (const ConnEvent &ev)

Enumeration Type Documentation

◆ EventKind

enum bsc::ebpf::EventKind : uint8_t
Enumerator
EVT_TP_SET_STATE 
EVT_TCP_CONNECT 
EVT_UDP_SENDMSG 

Definition at line 45 of file EBPFMon.hpp.

45 : uint8_t {
46 EVT_TP_SET_STATE = 0, // tracepoint inet_sock_set_state
47 EVT_TCP_CONNECT = 1, // kprobe tcp_v{4,6}_connect
48 EVT_UDP_SENDMSG = 2, // kprobe udp{,v6}_sendmsg
49};
@ EVT_UDP_SENDMSG
Definition EBPFMon.hpp:48
@ EVT_TCP_CONNECT
Definition EBPFMon.hpp:47
@ EVT_TP_SET_STATE
Definition EBPFMon.hpp:46

Function Documentation

◆ event_to_connection()

bsc::model::Connection bsc::ebpf::event_to_connection ( const ConnEvent & ev)

Definition at line 34 of file EBPFMon.cpp.

35{
37
38 c.process_id = ev.pid;
39 c.user_id = ev.uid;
40 c.process_comm = std::string(ev.comm,
41 strnlen(ev.comm, sizeof(ev.comm)));
42
43 c.protocol = (ev.proto == 6) ? "tcp" : "udp";
44
45 char buf[INET6_ADDRSTRLEN]{};
46 if (ev.family == AF_INET) {
47 // src
48 inet_ntop(AF_INET, ev.src_addr, buf, sizeof(buf));
49 c.src_ip = buf;
50 // dst
51 inet_ntop(AF_INET, ev.dst_addr, buf, sizeof(buf));
52 c.dst_ip = buf;
53 } else {
54 inet_ntop(AF_INET6, ev.src_addr, buf, sizeof(buf));
55 c.src_ip = buf;
56 inet_ntop(AF_INET6, ev.dst_addr, buf, sizeof(buf));
57 c.dst_ip = buf;
58 }
59
60 c.src_port = ev.src_port;
61 c.dst_port = ev.dst_port;
62
63 // Timestamp: converte ns monotoni in system_clock (approssimato)
64 // Il daemon usa seen_at solo per ordinamento nella UI — non critico.
65 c.seen_at = std::chrono::system_clock::now();
66
67 return c;
68}
#define AF_INET
Definition bsc_ebpf.c:56
#define AF_INET6
Definition bsc_ebpf.c:57
uint8_t dst_addr[16]
Definition EBPFMon.hpp:64
uint8_t src_addr[16]
Definition EBPFMon.hpp:63
std::uint32_t process_id
std::chrono::system_clock::time_point seen_at
std::uint32_t dst_port
std::uint32_t src_port
std::uint32_t user_id

References AF_INET, AF_INET6, bsc::ebpf::ConnEvent::comm, bsc::ebpf::ConnEvent::dst_addr, bsc::model::Connection::dst_ip, bsc::ebpf::ConnEvent::dst_port, bsc::model::Connection::dst_port, event_to_connection(), bsc::ebpf::ConnEvent::family, bsc::ebpf::ConnEvent::pid, bsc::model::Connection::process_comm, bsc::model::Connection::process_id, bsc::ebpf::ConnEvent::proto, bsc::model::Connection::protocol, bsc::model::Connection::seen_at, bsc::ebpf::ConnEvent::src_addr, bsc::model::Connection::src_ip, bsc::ebpf::ConnEvent::src_port, bsc::model::Connection::src_port, bsc::ebpf::ConnEvent::uid, and bsc::model::Connection::user_id.

Referenced by event_to_connection().