Skip to content

Commit

Permalink
changed handle command complete to handle response
Browse files Browse the repository at this point in the history
  • Loading branch information
amitslavin committed Nov 3, 2024
1 parent 69c8840 commit 3b24f9c
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 34 deletions.
2 changes: 1 addition & 1 deletion pkg/network/ebpf/c/protocols/classification/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ typedef enum {
PROG_KAFKA_TERMINATION,
PROG_GRPC,
PROG_POSTGRES,
PROG_POSTGRES_HANDLE_COMMAND_COMPLETE,
PROG_POSTGRES_HANDLE_RESPONSE,
PROG_POSTGRES_PROCESS_PARSE_MESSAGE,
PROG_POSTGRES_TERMINATION,
PROG_REDIS,
Expand Down
30 changes: 15 additions & 15 deletions pkg/network/ebpf/c/protocols/postgres/decoding.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,17 +150,17 @@ static __always_inline void postgres_handle_message(pktbuf_t pkt, conn_tuple_t *

iteration_value->iteration = 0;
iteration_value->data_off = 0;
pktbuf_tail_call_option_t handle_command_complete_tail_call_array[] = {
pktbuf_tail_call_option_t handle_response_tail_call_array[] = {
[PKTBUF_SKB] = {
.prog_array_map = &protocols_progs,
.index = PROG_POSTGRES_HANDLE_COMMAND_COMPLETE,
.index = PROG_POSTGRES_HANDLE_RESPONSE,
},
[PKTBUF_TLS] = {
.prog_array_map = &tls_process_progs,
.index = PROG_POSTGRES_HANDLE_COMMAND_COMPLETE,
.index = PROG_POSTGRES_HANDLE_RESPONSE,
},
};
pktbuf_tail_call_compact(pkt, handle_command_complete_tail_call_array);
pktbuf_tail_call_compact(pkt, handle_response_tail_call_array);
return;
}

Expand Down Expand Up @@ -199,7 +199,7 @@ static __always_inline void postgres_handle_parse_message(pktbuf_t pkt, conn_tup
// This function handles multiple messages within a single packet, processing up to POSTGRES_MAX_MESSAGES_PER_TAIL_CALL
// messages per call. When more messages exist beyond this limit, it uses tail call chaining (up to
// POSTGRES_MAX_TAIL_CALLS_FOR_MAX_MESSAGES) to continue processing.
static __always_inline bool handle_command_complete_messages(pktbuf_t pkt, conn_tuple_t conn_tuple) {
static __always_inline bool handle_response(pktbuf_t pkt, conn_tuple_t conn_tuple) {
const __u32 zero = 0;
struct pg_message_header header;
// We didn't find a new query, thus we assume we're in the middle of a transaction.
Expand Down Expand Up @@ -239,17 +239,17 @@ static __always_inline bool handle_command_complete_messages(pktbuf_t pkt, conn_

iteration_value->iteration += 1;
iteration_value->data_off = pktbuf_data_offset(pkt);
pktbuf_tail_call_option_t handle_command_complete_tail_call_array[] = {
pktbuf_tail_call_option_t handle_response_tail_call_array[] = {
[PKTBUF_SKB] = {
.prog_array_map = &protocols_progs,
.index = PROG_POSTGRES_HANDLE_COMMAND_COMPLETE,
.index = PROG_POSTGRES_HANDLE_RESPONSE,
},
[PKTBUF_TLS] = {
.prog_array_map = &tls_process_progs,
.index = PROG_POSTGRES_HANDLE_COMMAND_COMPLETE,
.index = PROG_POSTGRES_HANDLE_RESPONSE,
},
};
pktbuf_tail_call_compact(pkt, handle_command_complete_tail_call_array);
pktbuf_tail_call_compact(pkt, handle_response_tail_call_array);
return 0;
}

Expand Down Expand Up @@ -283,8 +283,8 @@ int socket__postgres_handle(struct __sk_buff* skb) {

// Handles plain text command complete messages for plaintext Postgres traffic. Pulls the connection tuple and the
// packet buffer from the map and calls the dedicated function to handle the message.
SEC("socket/postgres_handle_command_complete")
int socket__postgres_handle_command_complete(struct __sk_buff* skb) {
SEC("socket/postgres_handle_response")
int socket__postgres_handle_response(struct __sk_buff* skb) {
skb_info_t skb_info = {};
conn_tuple_t conn_tuple = {};

Expand All @@ -300,7 +300,7 @@ int socket__postgres_handle_command_complete(struct __sk_buff* skb) {
normalize_tuple(&conn_tuple);

pktbuf_t pkt = pktbuf_from_skb(skb, &skb_info);
handle_command_complete_messages(pkt, conn_tuple);
handle_response(pkt, conn_tuple);
return 0;
}

Expand Down Expand Up @@ -382,8 +382,8 @@ int uprobe__postgres_tls_termination(struct pt_regs *ctx) {
}

// Handles message parsing for a TLS Postgres traffic.
SEC("uprobe/postgres_tls_handle_command_complete")
int uprobe__postgres_tls_handle_command_complete(struct pt_regs *ctx) {
SEC("uprobe/postgres_tls_handle_response")
int uprobe__postgres_tls_handle_response(struct pt_regs *ctx) {
const __u32 zero = 0;

tls_dispatcher_arguments_t *args = bpf_map_lookup_elem(&tls_dispatcher_arguments, &zero);
Expand All @@ -394,7 +394,7 @@ int uprobe__postgres_tls_handle_command_complete(struct pt_regs *ctx) {
// Copying the tuple to the stack to handle verifier issues on kernel 4.14.
conn_tuple_t tup = args->tup;
pktbuf_t pkt = pktbuf_from_tls(ctx, args);
handle_command_complete_messages(pkt, tup);
handle_response(pkt, tup);
return 0;
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/network/protocols/ebpf_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ const (
ProgramKafkaTermination ProgramType = C.PROG_KAFKA_TERMINATION
// ProgramPostgres is the Golang representation of the C.PROG_POSTGRES enum
ProgramPostgres ProgramType = C.PROG_POSTGRES
// ProgramPostgresHandleCommandComplete is the Golang representation of the C.PROG_POSTGRES_HANDLE_COMMAND_COMPLETE enum
ProgramPostgresHandleCommandComplete ProgramType = C.PROG_POSTGRES_HANDLE_COMMAND_COMPLETE
// ProgramPostgresHandleResponse is the Golang representation of the C.PROG_POSTGRES_HANDLE_RESPONSE enum
ProgramPostgresHandleResponse ProgramType = C.PROG_POSTGRES_HANDLE_RESPONSE
// ProgramPostgresParseMessage is the Golang representation of the C.PROG_POSTGRES_PROCESS_PARSE_MESSAGE enum
ProgramPostgresParseMessage ProgramType = C.PROG_POSTGRES_PROCESS_PARSE_MESSAGE
// ProgramPostgresTermination is tail call to process Postgres termination.
Expand Down
2 changes: 1 addition & 1 deletion pkg/network/protocols/ebpf_types_linux.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 15 additions & 15 deletions pkg/network/protocols/postgres/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ import (

const (
// InFlightMap is the name of the in-flight map.
InFlightMap = "postgres_in_flight"
scratchBufferMap = "postgres_scratch_buffer"
iterationsMap = "postgres_iterations"
handleTailCall = "socket__postgres_handle"
handleCommandCompleteTailCall = "socket__postgres_handle_command_complete"
parseMessageTailCall = "socket__postgres_process_parse_message"
tlsHandleTailCall = "uprobe__postgres_tls_handle"
tlsParseMessageTailCall = "uprobe__postgres_tls_process_parse_message"
tlsTerminationTailCall = "uprobe__postgres_tls_termination"
tlsHandleCommandCompleteTailCall = "uprobe__postgres_tls_handle_command_complete"
eventStream = "postgres"
InFlightMap = "postgres_in_flight"
scratchBufferMap = "postgres_scratch_buffer"
iterationsMap = "postgres_iterations"
handleTailCall = "socket__postgres_handle"
handleResponseTailCall = "socket__postgres_handle_response"
parseMessageTailCall = "socket__postgres_process_parse_message"
tlsHandleTailCall = "uprobe__postgres_tls_handle"
tlsParseMessageTailCall = "uprobe__postgres_tls_process_parse_message"
tlsTerminationTailCall = "uprobe__postgres_tls_termination"
tlsHandleResponseTailCall = "uprobe__postgres_tls_handle_response"
eventStream = "postgres"
)

// protocol holds the state of the postgres protocol monitoring.
Expand Down Expand Up @@ -84,9 +84,9 @@ var Spec = &protocols.ProtocolSpec{
},
{
ProgArrayName: protocols.ProtocolDispatcherProgramsMap,
Key: uint32(protocols.ProgramPostgresHandleCommandComplete),
Key: uint32(protocols.ProgramPostgresHandleResponse),
ProbeIdentificationPair: manager.ProbeIdentificationPair{
EBPFFuncName: handleCommandCompleteTailCall,
EBPFFuncName: handleResponseTailCall,
},
},
{
Expand Down Expand Up @@ -119,9 +119,9 @@ var Spec = &protocols.ProtocolSpec{
},
{
ProgArrayName: protocols.TLSDispatcherProgramsMap,
Key: uint32(protocols.ProgramPostgresHandleCommandComplete),
Key: uint32(protocols.ProgramPostgresHandleResponse),
ProbeIdentificationPair: manager.ProbeIdentificationPair{
EBPFFuncName: tlsHandleCommandCompleteTailCall,
EBPFFuncName: tlsHandleResponseTailCall,
},
},
},
Expand Down

0 comments on commit 3b24f9c

Please sign in to comment.