@@ -121,6 +121,8 @@ static enum state __parse_request_startline(
121121 }
122122
123123failed :
124+ if (current_state != ST_FIELD_NAME_START )
125+ LOG (KERN_ERR , "__parse_request_startline failed, current_state:%d, char: %c\n" , current_state , ch );
124126 return current_state ;
125127}
126128
@@ -131,8 +133,10 @@ static bool parse_request_startline(const struct bpf_mem_ptr *msg, struct bpf_me
131133 struct kmesh_data_node * URI = new_kmesh_data_node (URI_STRING_LENGTH );
132134 struct kmesh_data_node * http_version = new_kmesh_data_node (VERSION_STRING_LENGTH );
133135
134- if (IS_ERR (method ) || IS_ERR (URI ) || IS_ERR (http_version ))
136+ if (IS_ERR (method ) || IS_ERR (URI ) || IS_ERR (http_version )) {
137+ LOG (KERN_ERR , "parse_request new kmesh_data_node failed\n" );
135138 goto failed ;
139+ }
136140
137141 current_state = __parse_request_startline (msg , context , method , URI , http_version );
138142 if (current_state != ST_FIELD_NAME_START )
@@ -232,6 +236,8 @@ static enum state __parse_respose_startline(
232236 }
233237 }
234238failed :
239+ if (current_state != ST_FIELD_NAME_START )
240+ LOG (KERN_ERR , "__parse_respose_startline failed, current_state:%d, char: %c\n" , current_state , ch );
235241 return current_state ;
236242}
237243
@@ -242,8 +248,10 @@ static bool parse_respose_startline(const struct bpf_mem_ptr *msg, struct bpf_me
242248 struct kmesh_data_node * status_code = new_kmesh_data_node (STATUS_STRING_LENGTH );
243249 struct kmesh_data_node * reason = new_kmesh_data_node (REASON_STRING_LENGTH );
244250
245- if (IS_ERR (http_version ) || IS_ERR (status_code ) || IS_ERR (reason ))
251+ if (IS_ERR (http_version ) || IS_ERR (status_code ) || IS_ERR (reason )) {
252+ LOG (KERN_ERR , "parse_respose new kmesh_data_node failed\n" );
246253 goto failed ;
254+ }
247255
248256 current_state = __parse_respose_startline (msg , context , http_version , status_code , reason );
249257 if (current_state != ST_FIELD_NAME_START )
@@ -279,8 +287,10 @@ static bool parse_header(struct bpf_mem_ptr *context)
279287 ch = ((char * )context -> ptr )[i ];
280288 switch (current_state ) {
281289 case ST_FIELD_NAME_START :
282- if (ch == FIELD_SPLIT )
290+ if (ch == FIELD_SPLIT ) {
291+ LOG (KERN_ERR , "Invalid field split detected, char:%c, current_state:%d\n" , ch , current_state );
283292 return false;
293+ }
284294 if (ch == CR ) {
285295 current_state = ST_HEAD_END ;
286296 break ;
@@ -315,15 +325,20 @@ static bool parse_header(struct bpf_mem_ptr *context)
315325 current_state = ST_NEW_LINE ;
316326 break ;
317327 case ST_NEW_LINE :
318- if (unlikely (ch != LF ))
328+ if (unlikely (ch != LF )) {
329+ LOG (KERN_ERR , "Expected LF but got another character:%c, current_state:%d\n" , ch , current_state );
319330 return false;
320- if (field_name_end_position < field_name_begin_position )
321- return false;
322- if (field_value_end_position < field_value_begin_position )
331+ }
332+ if (field_name_end_position < field_name_begin_position
333+ || field_value_end_position < field_value_begin_position ) {
334+ LOG (KERN_ERR , "Invalid field name or value positions, char:%c, current_state:%d\n" , ch , current_state );
323335 return false;
336+ }
324337 new_field = new_kmesh_data_node (field_name_end_position - field_name_begin_position + 2 );
325- if (IS_ERR (new_field ))
338+ if (IS_ERR (new_field )) {
339+ LOG (KERN_ERR , "Failed to create new field node, char:%c, current_state:%d\n" , ch , current_state );
326340 return false;
341+ }
327342 (void )strncpy (
328343 new_field -> keystring ,
329344 ((char * )context -> ptr ) + field_name_begin_position ,
@@ -347,18 +362,21 @@ static bool parse_header(struct bpf_mem_ptr *context)
347362 current_state = ST_FIELD_NAME_START ;
348363 break ;
349364 case ST_HEAD_END :
350- if (ch != LF )
365+ if (ch != LF ) {
366+ LOG (KERN_ERR , "Expected LF but got another character:%c, current_state:%d\n" , ch , current_state );
351367 return false;
368+ }
352369 head_end = true;
353370 break ;
354371 default :
355372 // It's not going to get here
356373 break ;
357374 }
358375 }
359- if (current_state != ST_HEAD_END )
376+ if (current_state != ST_HEAD_END ) {
377+ LOG (KERN_ERR , "parse_header failed, current_state:%d\n" , current_state );
360378 return false;
361-
379+ }
362380 return true;
363381}
364382
0 commit comments