comparison src/http/ngx_http_variables.c @ 4545:ba39af7274ed

Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and $tcpinfo_rcv_space variables. Supported on Linux and FreeBSD.
author Ruslan Ermilov <ru@nginx.com>
date Fri, 16 Mar 2012 19:15:33 +0000
parents cab9aa79256c
children 8865fd1f3aa5
comparison
equal deleted inserted replaced
4544:3a99980ac221 4545:ba39af7274ed
32 ngx_http_variable_value_t *v, uintptr_t data); 32 ngx_http_variable_value_t *v, uintptr_t data);
33 static ngx_int_t ngx_http_variable_cookie(ngx_http_request_t *r, 33 static ngx_int_t ngx_http_variable_cookie(ngx_http_request_t *r,
34 ngx_http_variable_value_t *v, uintptr_t data); 34 ngx_http_variable_value_t *v, uintptr_t data);
35 static ngx_int_t ngx_http_variable_argument(ngx_http_request_t *r, 35 static ngx_int_t ngx_http_variable_argument(ngx_http_request_t *r,
36 ngx_http_variable_value_t *v, uintptr_t data); 36 ngx_http_variable_value_t *v, uintptr_t data);
37 #if (NGX_HAVE_TCP_INFO)
38 static ngx_int_t ngx_http_variable_tcpinfo(ngx_http_request_t *r,
39 ngx_http_variable_value_t *v, uintptr_t data);
40 #endif
37 41
38 static ngx_int_t ngx_http_variable_host(ngx_http_request_t *r, 42 static ngx_int_t ngx_http_variable_host(ngx_http_request_t *r,
39 ngx_http_variable_value_t *v, uintptr_t data); 43 ngx_http_variable_value_t *v, uintptr_t data);
40 static ngx_int_t ngx_http_variable_binary_remote_addr(ngx_http_request_t *r, 44 static ngx_int_t ngx_http_variable_binary_remote_addr(ngx_http_request_t *r,
41 ngx_http_variable_value_t *v, uintptr_t data); 45 ngx_http_variable_value_t *v, uintptr_t data);
257 0, 0, 0 }, 261 0, 0, 0 },
258 262
259 { ngx_string("pid"), NULL, ngx_http_variable_pid, 263 { ngx_string("pid"), NULL, ngx_http_variable_pid,
260 0, 0, 0 }, 264 0, 0, 0 },
261 265
266 #if (NGX_HAVE_TCP_INFO)
267 { ngx_string("tcpinfo_rtt"), NULL, ngx_http_variable_tcpinfo,
268 0, NGX_HTTP_VAR_NOCACHEABLE, 0 },
269
270 { ngx_string("tcpinfo_rttvar"), NULL, ngx_http_variable_tcpinfo,
271 1, NGX_HTTP_VAR_NOCACHEABLE, 0 },
272
273 { ngx_string("tcpinfo_snd_cwnd"), NULL, ngx_http_variable_tcpinfo,
274 2, NGX_HTTP_VAR_NOCACHEABLE, 0 },
275
276 { ngx_string("tcpinfo_rcv_space"), NULL, ngx_http_variable_tcpinfo,
277 3, NGX_HTTP_VAR_NOCACHEABLE, 0 },
278 #endif
279
262 { ngx_null_string, NULL, NULL, 0, 0, 0 } 280 { ngx_null_string, NULL, NULL, 0, 0, 0 }
263 }; 281 };
264 282
265 283
266 ngx_http_variable_value_t ngx_http_variable_null_value = 284 ngx_http_variable_value_t ngx_http_variable_null_value =
880 v->no_cacheable = 0; 898 v->no_cacheable = 0;
881 v->not_found = 0; 899 v->not_found = 0;
882 900
883 return NGX_OK; 901 return NGX_OK;
884 } 902 }
903
904
905 #if (NGX_HAVE_TCP_INFO)
906
907 static ngx_int_t
908 ngx_http_variable_tcpinfo(ngx_http_request_t *r, ngx_http_variable_value_t *v,
909 uintptr_t data)
910 {
911 struct tcp_info ti;
912 socklen_t len;
913 uint32_t value;
914
915 len = sizeof(struct tcp_info);
916 if (getsockopt(r->connection->fd, IPPROTO_TCP, TCP_INFO, &ti, &len) == -1) {
917 v->not_found = 1;
918 return NGX_OK;
919 }
920
921 v->data = ngx_pnalloc(r->pool, NGX_INT32_LEN);
922 if (v->data == NULL) {
923 return NGX_ERROR;
924 }
925
926 switch (data) {
927 case 0:
928 value = ti.tcpi_rtt;
929 break;
930
931 case 1:
932 value = ti.tcpi_rttvar;
933 break;
934
935 case 2:
936 value = ti.tcpi_snd_cwnd;
937 break;
938
939 case 3:
940 value = ti.tcpi_rcv_space;
941 break;
942
943 /* suppress warning */
944 default:
945 value = 0;
946 break;
947 }
948
949 v->len = ngx_sprintf(v->data, "%uD", value) - v->data;
950 v->valid = 1;
951 v->no_cacheable = 0;
952 v->not_found = 0;
953
954 return NGX_OK;
955 }
956
957 #endif
885 958
886 959
887 static ngx_int_t 960 static ngx_int_t
888 ngx_http_variable_host(ngx_http_request_t *r, ngx_http_variable_value_t *v, 961 ngx_http_variable_host(ngx_http_request_t *r, ngx_http_variable_value_t *v,
889 uintptr_t data) 962 uintptr_t data)