@@ -33,15 +33,7 @@ static char *ngx_http_modsecurity_merge_conf(ngx_conf_t *cf, void *parent, void
33
33
static void ngx_http_modsecurity_cleanup_instance (void * data );
34
34
static void ngx_http_modsecurity_cleanup_rules (void * data );
35
35
36
- static ngx_int_t ngx_http_modsecurity_req_headers_phase_time (ngx_http_request_t * r ,
37
- ngx_http_variable_value_t * v , uintptr_t data );
38
- static ngx_int_t ngx_http_modsecurity_req_body_phase_time (ngx_http_request_t * r ,
39
- ngx_http_variable_value_t * v , uintptr_t data );
40
- static ngx_int_t ngx_http_modsecurity_resp_headers_phase_time (ngx_http_request_t * r ,
41
- ngx_http_variable_value_t * v , uintptr_t data );
42
- static ngx_int_t ngx_http_modsecurity_resp_body_phase_time (ngx_http_request_t * r ,
43
- ngx_http_variable_value_t * v , uintptr_t data );
44
- static ngx_int_t ngx_http_modsecurity_logging_phase_time (ngx_http_request_t * r ,
36
+ static ngx_int_t ngx_http_modsecurity_phase_time (ngx_http_request_t * r ,
45
37
ngx_http_variable_value_t * v , uintptr_t data );
46
38
static ngx_int_t ngx_http_modsecurity_time_variable (ngx_http_request_t * r ,
47
39
ngx_http_variable_value_t * v , uintptr_t data , ngx_msec_int_t usec );
@@ -541,26 +533,26 @@ ngx_module_t ngx_http_modsecurity_module = {
541
533
542
534
static ngx_http_variable_t ngx_http_modsecurity_vars [] = {
543
535
{ ngx_string ("modsecurity_req_headers_phase_time" ), NULL ,
544
- ngx_http_modsecurity_req_headers_phase_time , 0 ,
545
- NGX_HTTP_VAR_NOCACHEABLE , 0 },
536
+ ngx_http_modsecurity_phase_time , 0 ,
537
+ NGX_HTTP_VAR_NOCACHEABLE | NGX_HTTP_VAR_NOHASH , 0 },
546
538
547
539
{ ngx_string ("modsecurity_req_body_phase_time" ), NULL ,
548
- ngx_http_modsecurity_req_body_phase_time , 0 ,
549
- NGX_HTTP_VAR_NOCACHEABLE , 0 },
540
+ ngx_http_modsecurity_phase_time , 1 ,
541
+ NGX_HTTP_VAR_NOCACHEABLE | NGX_HTTP_VAR_NOHASH , 0 },
550
542
551
543
{ ngx_string ("modsecurity_resp_headers_phase_time" ), NULL ,
552
- ngx_http_modsecurity_resp_headers_phase_time , 0 ,
553
- NGX_HTTP_VAR_NOCACHEABLE , 0 },
544
+ ngx_http_modsecurity_phase_time , 2 ,
545
+ NGX_HTTP_VAR_NOCACHEABLE | NGX_HTTP_VAR_NOHASH , 0 },
554
546
555
547
{ ngx_string ("modsecurity_resp_body_phase_time" ), NULL ,
556
- ngx_http_modsecurity_resp_body_phase_time , 0 ,
557
- NGX_HTTP_VAR_NOCACHEABLE , 0 },
548
+ ngx_http_modsecurity_phase_time , 3 ,
549
+ NGX_HTTP_VAR_NOCACHEABLE | NGX_HTTP_VAR_NOHASH , 0 },
558
550
559
551
{ ngx_string ("modsecurity_logging_phase_time" ), NULL ,
560
- ngx_http_modsecurity_logging_phase_time , 0 ,
561
- NGX_HTTP_VAR_NOCACHEABLE , 0 },
552
+ ngx_http_modsecurity_phase_time , 4 ,
553
+ NGX_HTTP_VAR_NOCACHEABLE | NGX_HTTP_VAR_NOHASH , 0 },
562
554
563
- ngx_http_null_variable
555
+ { ngx_null_string , NULL , NULL , 0 , 0 , 0 }
564
556
};
565
557
566
558
@@ -850,21 +842,7 @@ ngx_http_modsecurity_cleanup_rules(void *data)
850
842
851
843
852
844
static ngx_int_t
853
- ngx_http_modsecurity_req_headers_phase_time (ngx_http_request_t * r ,
854
- ngx_http_variable_value_t * v , uintptr_t data )
855
- {
856
- ngx_http_modsecurity_ctx_t * ctx ;
857
-
858
- ctx = ngx_http_get_module_ctx (r , ngx_http_modsecurity_module );
859
- if (ctx == NULL ) {
860
- return NGX_ERROR ;
861
- }
862
- return ngx_http_modsecurity_time_variable (r , v , data , ctx -> req_headers_phase_time );
863
- }
864
-
865
-
866
- static ngx_int_t
867
- ngx_http_modsecurity_req_body_phase_time (ngx_http_request_t * r ,
845
+ ngx_http_modsecurity_phase_time (ngx_http_request_t * r ,
868
846
ngx_http_variable_value_t * v , uintptr_t data )
869
847
{
870
848
ngx_http_modsecurity_ctx_t * ctx ;
@@ -873,49 +851,21 @@ ngx_http_modsecurity_req_body_phase_time(ngx_http_request_t *r,
873
851
if (ctx == NULL ) {
874
852
return NGX_ERROR ;
875
853
}
876
- return ngx_http_modsecurity_time_variable (r , v , data , ctx -> req_body_phase_time );
877
- }
878
854
879
-
880
- static ngx_int_t
881
- ngx_http_modsecurity_resp_headers_phase_time (ngx_http_request_t * r ,
882
- ngx_http_variable_value_t * v , uintptr_t data )
883
- {
884
- ngx_http_modsecurity_ctx_t * ctx ;
885
-
886
- ctx = ngx_http_get_module_ctx (r , ngx_http_modsecurity_module );
887
- if (ctx == NULL ) {
888
- return NGX_ERROR ;
889
- }
890
- return ngx_http_modsecurity_time_variable (r , v , data , ctx -> resp_headers_phase_time );
891
- }
892
-
893
-
894
- static ngx_int_t
895
- ngx_http_modsecurity_resp_body_phase_time (ngx_http_request_t * r ,
896
- ngx_http_variable_value_t * v , uintptr_t data )
897
- {
898
- ngx_http_modsecurity_ctx_t * ctx ;
899
-
900
- ctx = ngx_http_get_module_ctx (r , ngx_http_modsecurity_module );
901
- if (ctx == NULL ) {
902
- return NGX_ERROR ;
903
- }
904
- return ngx_http_modsecurity_time_variable (r , v , data , ctx -> resp_body_phase_time );
905
- }
906
-
907
-
908
- static ngx_int_t
909
- ngx_http_modsecurity_logging_phase_time (ngx_http_request_t * r ,
910
- ngx_http_variable_value_t * v , uintptr_t data )
911
- {
912
- ngx_http_modsecurity_ctx_t * ctx ;
913
-
914
- ctx = ngx_http_get_module_ctx (r , ngx_http_modsecurity_module );
915
- if (ctx == NULL ) {
916
- return NGX_ERROR ;
855
+ switch (data ) {
856
+ case 0 :
857
+ return ngx_http_modsecurity_time_variable (r , v , data , ctx -> req_headers_phase_time );
858
+ case 1 :
859
+ return ngx_http_modsecurity_time_variable (r , v , data , ctx -> req_body_phase_time );
860
+ case 2 :
861
+ return ngx_http_modsecurity_time_variable (r , v , data , ctx -> resp_headers_phase_time );
862
+ case 3 :
863
+ return ngx_http_modsecurity_time_variable (r , v , data , ctx -> resp_body_phase_time );
864
+ case 4 :
865
+ return ngx_http_modsecurity_time_variable (r , v , data , ctx -> logging_phase_time );
866
+ default :
867
+ return -1 ;
917
868
}
918
- return ngx_http_modsecurity_time_variable (r , v , data , ctx -> logging_phase_time );
919
869
}
920
870
921
871
@@ -946,10 +896,10 @@ ngx_http_modsecurity_time_variable(ngx_http_request_t *r,
946
896
947
897
948
898
ngx_msec_int_t
949
- ngx_http_modsecurity_compute_processing_time (struct timeval tv ) {
950
- struct timeval current_tv ;
951
- ngx_gettimeofday ( & current_tv );
952
- return (ngx_msec_int_t ) ((current_tv .tv_sec - tv .tv_sec ) * 1000000 + (current_tv .tv_usec - tv .tv_usec ) );
899
+ ngx_http_modsecurity_compute_processing_time (struct timespec tv ) {
900
+ struct timespec current_tv ;
901
+ ( void ) clock_gettime ( CLOCK_MONOTONIC , & current_tv );
902
+ return (ngx_msec_int_t ) ((current_tv .tv_sec - tv .tv_sec ) * 1000000 + (current_tv .tv_nsec - tv .tv_nsec ) / 1000 );
953
903
};
954
904
955
905
/* vi:set ft=c ts=4 sw=4 et fdm=marker: */
0 commit comments