22
22
23
23
24
24
ngx_int_t ngx_http_modsecurity_process_connection (ngx_http_request_t * r ,
25
- ngx_http_modsecurity_ctx_t * ctx );
25
+ ngx_http_modsecurity_ctx_t * ctx ,
26
+ const char * client_addr , in_port_t client_port );
26
27
ngx_int_t ngx_http_modsecurity_process_url (ngx_http_request_t * r ,
27
28
ngx_http_modsecurity_ctx_t * ctx ,
28
29
const char * uri , const char * method , const char * http_version );
@@ -57,7 +58,7 @@ ngx_http_modsecurity_rewrite_handler(ngx_http_request_t *r)
57
58
return rc ;
58
59
}
59
60
60
- rc = ngx_http_modsecurity_process_connection (r , ctx );
61
+ rc = ngx_http_modsecurity_process_connection (r , ctx , NULL , 0 );
61
62
if (rc > 0 ) {
62
63
return rc ;
63
64
}
@@ -83,24 +84,21 @@ ngx_http_modsecurity_rewrite_handler(ngx_http_request_t *r)
83
84
84
85
ngx_int_t
85
86
ngx_http_modsecurity_process_connection (ngx_http_request_t * r ,
86
- ngx_http_modsecurity_ctx_t * ctx )
87
+ ngx_http_modsecurity_ctx_t * ctx ,
88
+ const char * client_addr , in_port_t client_port )
87
89
{
88
- in_port_t client_port , server_port ;
90
+ in_port_t server_port ;
89
91
ngx_int_t rc ;
90
- ngx_str_t client_addr , server_addr ;
92
+ ngx_str_t server_addr ;
91
93
ngx_pool_t * old_pool ;
92
94
ngx_connection_t * c ;
93
95
u_char addr [NGX_SOCKADDR_STRLEN + 1 ];
94
96
95
97
c = r -> connection ;
96
98
97
- client_addr = c -> addr_text ;
98
- client_port = ngx_inet_get_port (c -> sockaddr );
99
-
100
- if (client_addr .len < c -> listening -> addr_text_max_len ) {
101
- client_addr .data [client_addr .len ] = 0 ;
102
- } else {
103
- client_addr .data = (u_char * )ngx_str_to_char (client_addr , r -> pool );
99
+ if (client_addr == NULL ) {
100
+ client_addr = ngx_str_to_char (c -> addr_text , r -> pool );
101
+ client_port = ngx_inet_get_port (c -> sockaddr );
104
102
}
105
103
106
104
// fill c->local_sockaddr
@@ -116,7 +114,7 @@ ngx_http_modsecurity_process_connection(ngx_http_request_t *r,
116
114
117
115
old_pool = ngx_http_modsecurity_pcre_malloc_init (r -> pool );
118
116
rc = msc_process_connection (ctx -> modsec_transaction ,
119
- ( char * ) client_addr . data , client_port ,
117
+ client_addr , client_port ,
120
118
(char * )server_addr .data , server_port );
121
119
ngx_http_modsecurity_pcre_malloc_done (old_pool );
122
120
if (rc != 1 ){
0 commit comments