Skip to content

Commit 5948810

Browse files
committed
Add redis to tls_process
1 parent b3d34f5 commit 5948810

File tree

1 file changed

+40
-0
lines changed
  • pkg/network/ebpf/c/protocols/tls

1 file changed

+40
-0
lines changed

pkg/network/ebpf/c/protocols/tls/https.h

+40
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,29 @@ static __always_inline void classify_decrypted_payload(protocol_stack_t *stack,
6363
set_protocol(stack, proto);
6464
}
6565

66+
/*
67+
* Processes decrypted TLS traffic and dispatches it to appropriate protocol handlers.
68+
*
69+
* This function is called by various TLS hookpoints (OpenSSL, GnuTLS, GoTLS, JavaTLS)
70+
* to process decrypted TLS payloads. It manages the protocol stack for each connection,
71+
* classifies the decrypted payload if the application protocol is not yet known, and
72+
* dispatches the traffic to the appropriate protocol handler via tail calls.
73+
*
74+
* The function first creates or retrieves a protocol stack for the connection. If the
75+
* application protocol is unknown, it attempts to classify the payload. For Kafka traffic,
76+
* an additional classification step may be performed via a tail call if Kafka monitoring
77+
* is enabled.
78+
*
79+
* For each supported protocol, the function performs a tail call to a dedicated handler:
80+
* - HTTP: PROG_HTTP
81+
* - HTTP2: PROG_HTTP2_HANDLE_FIRST_FRAME
82+
* - Kafka: PROG_KAFKA
83+
* - PostgreSQL: PROG_POSTGRES
84+
* - Redis: PROG_REDIS
85+
*
86+
* The function takes the BPF program context, connection metadata (tuple), a pointer to
87+
* the decrypted payload and its length, and connection metadata tags as input.
88+
*/
6689
static __always_inline void tls_process(struct pt_regs *ctx, conn_tuple_t *t, void *buffer_ptr, size_t len, __u64 tags) {
6790
conn_tuple_t final_tuple = {0};
6891
conn_tuple_t normalized_tuple = *t;
@@ -92,6 +115,15 @@ static __always_inline void tls_process(struct pt_regs *ctx, conn_tuple_t *t, vo
92115
protocol = get_protocol_from_stack(stack, LAYER_APPLICATION);
93116
// Could have a maybe_is_kafka() function to do an initial check here based on the
94117
// fragment buffer without the tail call.
118+
119+
/*
120+
* Special handling for Kafka:
121+
* Unlike other protocols that can be classified directly, Kafka requires additional context
122+
* and more complex pattern matching that can't be done in the main classifier. We use a
123+
* tail call to a dedicated Kafka classifier that can perform the full protocol analysis.
124+
* This is only done if Kafka monitoring is enabled and the protocol is still unknown after
125+
* the initial classification attempt.
126+
*/
95127
if (is_kafka_monitoring_enabled() && protocol == PROTOCOL_UNKNOWN) {
96128
tls_dispatcher_arguments_t *args = bpf_map_lookup_elem(&tls_dispatcher_arguments, &zero);
97129
if (args == NULL) {
@@ -125,6 +157,10 @@ static __always_inline void tls_process(struct pt_regs *ctx, conn_tuple_t *t, vo
125157
prog = PROG_POSTGRES;
126158
final_tuple = normalized_tuple;
127159
break;
160+
case PROTOCOL_REDIS:
161+
prog = PROG_REDIS;
162+
final_tuple = normalized_tuple;
163+
break;
128164
default:
129165
return;
130166
}
@@ -213,6 +249,10 @@ static __always_inline void tls_finish(struct pt_regs *ctx, conn_tuple_t *t, boo
213249
prog = PROG_POSTGRES_TERMINATION;
214250
final_tuple = normalized_tuple;
215251
break;
252+
case PROTOCOL_REDIS:
253+
prog = PROG_REDIS_TERMINATION;
254+
final_tuple = normalized_tuple;
255+
break;
216256
default:
217257
return;
218258
}

0 commit comments

Comments
 (0)