@@ -63,6 +63,29 @@ static __always_inline void classify_decrypted_payload(protocol_stack_t *stack,
63
63
set_protocol (stack , proto );
64
64
}
65
65
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
+ */
66
89
static __always_inline void tls_process (struct pt_regs * ctx , conn_tuple_t * t , void * buffer_ptr , size_t len , __u64 tags ) {
67
90
conn_tuple_t final_tuple = {0 };
68
91
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
92
115
protocol = get_protocol_from_stack (stack , LAYER_APPLICATION );
93
116
// Could have a maybe_is_kafka() function to do an initial check here based on the
94
117
// 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
+ */
95
127
if (is_kafka_monitoring_enabled () && protocol == PROTOCOL_UNKNOWN ) {
96
128
tls_dispatcher_arguments_t * args = bpf_map_lookup_elem (& tls_dispatcher_arguments , & zero );
97
129
if (args == NULL ) {
@@ -125,6 +157,10 @@ static __always_inline void tls_process(struct pt_regs *ctx, conn_tuple_t *t, vo
125
157
prog = PROG_POSTGRES ;
126
158
final_tuple = normalized_tuple ;
127
159
break ;
160
+ case PROTOCOL_REDIS :
161
+ prog = PROG_REDIS ;
162
+ final_tuple = normalized_tuple ;
163
+ break ;
128
164
default :
129
165
return ;
130
166
}
@@ -213,6 +249,10 @@ static __always_inline void tls_finish(struct pt_regs *ctx, conn_tuple_t *t, boo
213
249
prog = PROG_POSTGRES_TERMINATION ;
214
250
final_tuple = normalized_tuple ;
215
251
break ;
252
+ case PROTOCOL_REDIS :
253
+ prog = PROG_REDIS_TERMINATION ;
254
+ final_tuple = normalized_tuple ;
255
+ break ;
216
256
default :
217
257
return ;
218
258
}
0 commit comments