nxt_router.c (2131:aea375f03b0b) nxt_router.c (2132:34d63ed988dc)
1
2/*
3 * Copyright (C) Igor Sysoev
4 * Copyright (C) Valentin V. Bartenev
5 * Copyright (C) NGINX, Inc.
6 */
7
8#include <nxt_router.h>

--- 95 unchanged lines hidden (view full) ---

104static void nxt_router_conf_send(nxt_task_t *task,
105 nxt_router_temp_conf_t *tmcf, nxt_port_msg_type_t type);
106
107static nxt_int_t nxt_router_conf_create(nxt_task_t *task,
108 nxt_router_temp_conf_t *tmcf, u_char *start, u_char *end);
109static nxt_int_t nxt_router_conf_process_static(nxt_task_t *task,
110 nxt_router_conf_t *rtcf, nxt_conf_value_t *conf);
111static nxt_int_t nxt_router_conf_process_client_ip(nxt_task_t *task,
1
2/*
3 * Copyright (C) Igor Sysoev
4 * Copyright (C) Valentin V. Bartenev
5 * Copyright (C) NGINX, Inc.
6 */
7
8#include <nxt_router.h>

--- 95 unchanged lines hidden (view full) ---

104static void nxt_router_conf_send(nxt_task_t *task,
105 nxt_router_temp_conf_t *tmcf, nxt_port_msg_type_t type);
106
107static nxt_int_t nxt_router_conf_create(nxt_task_t *task,
108 nxt_router_temp_conf_t *tmcf, u_char *start, u_char *end);
109static nxt_int_t nxt_router_conf_process_static(nxt_task_t *task,
110 nxt_router_conf_t *rtcf, nxt_conf_value_t *conf);
111static nxt_int_t nxt_router_conf_process_client_ip(nxt_task_t *task,
112 nxt_router_temp_conf_t *tmcf, nxt_socket_conf_t *skcf,
113 nxt_conf_value_t *conf);
112 nxt_mp_t *mp, nxt_socket_conf_t *skcf, nxt_conf_value_t *conf);
114
115static nxt_app_t *nxt_router_app_find(nxt_queue_t *queue, nxt_str_t *name);
116static nxt_int_t nxt_router_apps_hash_test(nxt_lvlhsh_query_t *lhq, void *data);
117static nxt_int_t nxt_router_apps_hash_add(nxt_router_conf_t *rtcf,
118 nxt_app_t *app);
119static nxt_app_t *nxt_router_apps_hash_get(nxt_router_conf_t *rtcf,
120 nxt_str_t *name);
121static void nxt_router_apps_hash_use(nxt_task_t *task, nxt_router_conf_t *rtcf,

--- 1758 unchanged lines hidden (view full) ---

1880 t = &skcf->body_temp_path;
1881
1882 if (t->length == 0) {
1883 t->start = (u_char *) task->thread->runtime->tmp;
1884 t->length = nxt_strlen(t->start);
1885 }
1886
1887 conf = nxt_conf_get_path(listener, &client_ip_path);
113
114static nxt_app_t *nxt_router_app_find(nxt_queue_t *queue, nxt_str_t *name);
115static nxt_int_t nxt_router_apps_hash_test(nxt_lvlhsh_query_t *lhq, void *data);
116static nxt_int_t nxt_router_apps_hash_add(nxt_router_conf_t *rtcf,
117 nxt_app_t *app);
118static nxt_app_t *nxt_router_apps_hash_get(nxt_router_conf_t *rtcf,
119 nxt_str_t *name);
120static void nxt_router_apps_hash_use(nxt_task_t *task, nxt_router_conf_t *rtcf,

--- 1758 unchanged lines hidden (view full) ---

1879 t = &skcf->body_temp_path;
1880
1881 if (t->length == 0) {
1882 t->start = (u_char *) task->thread->runtime->tmp;
1883 t->length = nxt_strlen(t->start);
1884 }
1885
1886 conf = nxt_conf_get_path(listener, &client_ip_path);
1888 ret = nxt_router_conf_process_client_ip(task, tmcf, skcf,
1889 conf);
1890 if (nxt_slow_path(ret != NXT_OK)) {
1891 return NXT_ERROR;
1887
1888 if (conf != NULL) {
1889 ret = nxt_router_conf_process_client_ip(task, mp, skcf, conf);
1890 if (nxt_slow_path(ret != NXT_OK)) {
1891 return NXT_ERROR;
1892 }
1892 }
1893
1894#if (NXT_TLS)
1895 certificate = nxt_conf_get_path(listener, &certificate_path);
1896
1897 if (certificate != NULL) {
1898 tls_init = nxt_mp_get(tmcf->mem_pool, sizeof(nxt_tls_init_t));
1899 if (nxt_slow_path(tls_init == NULL)) {

--- 219 unchanged lines hidden (view full) ---

2119 }
2120 }
2121
2122 return NXT_OK;
2123}
2124
2125
2126static nxt_int_t
1893 }
1894
1895#if (NXT_TLS)
1896 certificate = nxt_conf_get_path(listener, &certificate_path);
1897
1898 if (certificate != NULL) {
1899 tls_init = nxt_mp_get(tmcf->mem_pool, sizeof(nxt_tls_init_t));
1900 if (nxt_slow_path(tls_init == NULL)) {

--- 219 unchanged lines hidden (view full) ---

2120 }
2121 }
2122
2123 return NXT_OK;
2124}
2125
2126
2127static nxt_int_t
2127nxt_router_conf_process_client_ip(nxt_task_t *task, nxt_router_temp_conf_t *tmcf,
2128nxt_router_conf_process_client_ip(nxt_task_t *task, nxt_mp_t *mp,
2128 nxt_socket_conf_t *skcf, nxt_conf_value_t *conf)
2129{
2130 char c;
2131 size_t i;
2129 nxt_socket_conf_t *skcf, nxt_conf_value_t *conf)
2130{
2131 char c;
2132 size_t i;
2132 nxt_mp_t *mp;
2133 uint32_t hash;
2134 nxt_str_t header;
2135 nxt_conf_value_t *source_conf, *header_conf, *recursive_conf;
2133 uint32_t hash;
2134 nxt_str_t header;
2135 nxt_conf_value_t *source_conf, *header_conf, *recursive_conf;
2136 nxt_http_client_ip_t *client_ip;
2136 nxt_http_forward_t *forward;
2137 nxt_http_forward_header_t *client_ip;
2137 nxt_http_route_addr_rule_t *source;
2138
2139 static nxt_str_t header_path = nxt_string("/header");
2140 static nxt_str_t source_path = nxt_string("/source");
2141 static nxt_str_t recursive_path = nxt_string("/recursive");
2142
2138 nxt_http_route_addr_rule_t *source;
2139
2140 static nxt_str_t header_path = nxt_string("/header");
2141 static nxt_str_t source_path = nxt_string("/source");
2142 static nxt_str_t recursive_path = nxt_string("/recursive");
2143
2143 if (conf == NULL) {
2144 skcf->client_ip = NULL;
2145
2146 return NXT_OK;
2147 }
2148
2149 mp = tmcf->router_conf->mem_pool;
2150
2151 source_conf = nxt_conf_get_path(conf, &source_path);
2152 header_conf = nxt_conf_get_path(conf, &header_path);
2153 recursive_conf = nxt_conf_get_path(conf, &recursive_path);
2154
2155 if (source_conf == NULL || header_conf == NULL) {
2156 return NXT_ERROR;
2157 }
2158
2144 source_conf = nxt_conf_get_path(conf, &source_path);
2145 header_conf = nxt_conf_get_path(conf, &header_path);
2146 recursive_conf = nxt_conf_get_path(conf, &recursive_path);
2147
2148 if (source_conf == NULL || header_conf == NULL) {
2149 return NXT_ERROR;
2150 }
2151
2159 client_ip = nxt_mp_zget(mp, sizeof(nxt_http_client_ip_t));
2160 if (nxt_slow_path(client_ip == NULL)) {
2152 forward = nxt_mp_zget(mp, sizeof(nxt_http_forward_t));
2153 if (nxt_slow_path(forward == NULL)) {
2161 return NXT_ERROR;
2162 }
2163
2164 source = nxt_http_route_addr_rule_create(task, mp, source_conf);
2165 if (nxt_slow_path(source == NULL)) {
2166 return NXT_ERROR;
2167 }
2168
2154 return NXT_ERROR;
2155 }
2156
2157 source = nxt_http_route_addr_rule_create(task, mp, source_conf);
2158 if (nxt_slow_path(source == NULL)) {
2159 return NXT_ERROR;
2160 }
2161
2169 client_ip->source = source;
2162 forward->source = source;
2170
2163
2164 client_ip = &forward->client_ip;
2165
2171 nxt_conf_get_string(header_conf, &header);
2172
2173 if (recursive_conf != NULL) {
2166 nxt_conf_get_string(header_conf, &header);
2167
2168 if (recursive_conf != NULL) {
2174 client_ip->recursive = nxt_conf_get_boolean(recursive_conf);
2169 forward->recursive = nxt_conf_get_boolean(recursive_conf);
2175 }
2176
2177 client_ip->header = nxt_str_dup(mp, NULL, &header);
2178 if (nxt_slow_path(client_ip->header == NULL)) {
2179 return NXT_ERROR;
2180 }
2181
2182 hash = NXT_HTTP_FIELD_HASH_INIT;
2183
2184 for (i = 0; i < client_ip->header->length; i++) {
2185 c = client_ip->header->start[i];
2186 hash = nxt_http_field_hash_char(hash, nxt_lowcase(c));
2187 }
2188
2189 hash = nxt_http_field_hash_end(hash) & 0xFFFF;
2190
2191 client_ip->header_hash = hash;
2192
2170 }
2171
2172 client_ip->header = nxt_str_dup(mp, NULL, &header);
2173 if (nxt_slow_path(client_ip->header == NULL)) {
2174 return NXT_ERROR;
2175 }
2176
2177 hash = NXT_HTTP_FIELD_HASH_INIT;
2178
2179 for (i = 0; i < client_ip->header->length; i++) {
2180 c = client_ip->header->start[i];
2181 hash = nxt_http_field_hash_char(hash, nxt_lowcase(c));
2182 }
2183
2184 hash = nxt_http_field_hash_end(hash) & 0xFFFF;
2185
2186 client_ip->header_hash = hash;
2187
2193 skcf->client_ip = client_ip;
2188 skcf->client_ip = forward;
2194
2195 return NXT_OK;
2196}
2197
2198
2199static nxt_app_t *
2200nxt_router_app_find(nxt_queue_t *queue, nxt_str_t *name)
2201{

--- 3759 unchanged lines hidden ---
2189
2190 return NXT_OK;
2191}
2192
2193
2194static nxt_app_t *
2195nxt_router_app_find(nxt_queue_t *queue, nxt_str_t *name)
2196{

--- 3759 unchanged lines hidden ---