Browse Source

[multiple] inline struct in con->dst_addr_buf

(mod_extforward recently changed to use buffer_move() to save addr
 instead of swapping pointers)
master
Glenn Strauss 4 months ago
parent
commit
f1e8a82f1a
  1. 2
      src/base.h
  2. 2
      src/configfile-glue.c
  3. 11
      src/connections.c
  4. 2
      src/gw_backend.c
  5. 2
      src/http_cgi.c
  6. 2
      src/mod_accesslog.c
  7. 2
      src/mod_ajp13.c
  8. 6
      src/mod_auth.c
  9. 2
      src/mod_authn_gssapi.c
  10. 2
      src/mod_authn_pam.c
  11. 2
      src/mod_evasive.c
  12. 27
      src/mod_extforward.c
  13. 2
      src/mod_geoip.c
  14. 2
      src/mod_magnet.c
  15. 8
      src/mod_proxy.c
  16. 2
      src/mod_status.c
  17. 2
      src/mod_trigger_b4_dl.c

2
src/base.h

@ -49,7 +49,7 @@ struct connection {
void *config_data_base;
sock_addr dst_addr;
buffer *dst_addr_buf;
buffer dst_addr_buf;
const struct server_socket *srv_socket; /* reference to the server-socket */
/* timestamps */

2
src/configfile-glue.c

@ -570,7 +570,7 @@ static cond_result_t config_check_cond_nocache(request_st * const r, const data_
case -1: return COND_RESULT_FALSE; /*(error parsing configfile entry)*/
}
}
l = r->con->dst_addr_buf;
l = &r->con->dst_addr_buf;
break;
}
case COMP_HTTP_SCHEME:

11
src/connections.c

@ -546,7 +546,6 @@ static connection *connection_init(server *srv) {
con->bytes_written = 0;
con->bytes_read = 0;
con->dst_addr_buf = buffer_init();
con->srv = srv;
con->plugin_slots = srv->plugin_slots;
con->config_data_base = srv->config_data_base;
@ -578,8 +577,7 @@ void connections_free(server *srv) {
request_free_data(r);
free(con->plugin_ctx);
buffer_free(con->dst_addr_buf);
free(con->dst_addr_buf.ptr);
free(con);
}
@ -971,7 +969,8 @@ connection *connection_accepted(server *srv, const server_socket *srv_socket, so
con->connection_start = log_monotonic_secs;
con->dst_addr = *cnt_addr;
sock_addr_cache_inet_ntop_copy_buffer(con->dst_addr_buf,&con->dst_addr);
sock_addr_cache_inet_ntop_copy_buffer(&con->dst_addr_buf,
&con->dst_addr);
con->srv_socket = srv_socket;
con->is_ssl_sock = srv_socket->is_ssl;
con->proto_default_port = 80; /* "http" */
@ -1474,7 +1473,7 @@ static void connection_check_timeout (connection * const con, const time_t cur_t
"after writing %lld bytes. We waited %d seconds. "
"If this is a problem, increase "
"server.max-write-idle",
con->dst_addr_buf->ptr,
con->dst_addr_buf.ptr,
BUFFER_INTLEN_PTR(&r->target),
(long long)r->write_queue.bytes_out,
(int)r->conf.max_write_idle);
@ -1548,7 +1547,7 @@ static void connection_check_timeout (connection * const con, const time_t cur_t
"NOTE: a request from %s for %.*s timed out after writing "
"%lld bytes. We waited %d seconds. If this is a problem, "
"increase server.max-write-idle",
con->dst_addr_buf->ptr,
con->dst_addr_buf.ptr,
BUFFER_INTLEN_PTR(&r->target),
(long long)con->bytes_written, (int)r->conf.max_write_idle);
}

2
src/gw_backend.c

@ -897,7 +897,7 @@ static gw_host * gw_host_get(request_st * const r, gw_extension *extension, int
}
case GW_BALANCE_STICKY:
{ /* source sticky balancing */
const buffer * const dst_addr_buf = r->con->dst_addr_buf;
const buffer * const dst_addr_buf = &r->con->dst_addr_buf;
const uint32_t base_hash =
gw_hash(BUF_PTR_LEN(dst_addr_buf), DJBHASH_INIT);
uint32_t last_max = UINT32_MAX;

2
src/http_cgi.c

@ -306,7 +306,7 @@ http_cgi_headers (request_st * const r, http_cgi_opts * const opts, http_cgi_hea
rc |= cb(vdata, CONST_STR_LEN("SERVER_NAME"), s, n);
rc |= cb(vdata, CONST_STR_LEN("REMOTE_ADDR"),
BUF_PTR_LEN(con->dst_addr_buf));
BUF_PTR_LEN(&con->dst_addr_buf));
rc |= cb(vdata, CONST_STR_LEN("REMOTE_PORT"), buf,
li_utostrn(buf,sizeof(buf),sock_addr_get_port(&con->dst_addr)));

2
src/mod_accesslog.c

@ -914,7 +914,7 @@ static int log_access_record (const request_st * const r, buffer * const b, form
break;
case FORMAT_REMOTE_ADDR:
case FORMAT_REMOTE_HOST:
buffer_append_string_buffer(b, con->dst_addr_buf);
buffer_append_string_buffer(b, &con->dst_addr_buf);
break;
case FORMAT_REMOTE_IDENT:
/* ident */

2
src/mod_ajp13.c

@ -592,7 +592,7 @@ ajp13_create_env (handler_ctx * const hctx)
n = ajp13_enc_string(x, n, BUF_PTR_LEN(&r->uri.path));
if (0 == n) break;
/* remote_addr */
n = ajp13_enc_string(x, n, BUF_PTR_LEN(r->con->dst_addr_buf));
n = ajp13_enc_string(x, n, BUF_PTR_LEN(&r->con->dst_addr_buf));
if (0 == n) break;
/* remote_host *//*(skip DNS lookup)*/
n = ajp13_enc_string(x, n, NULL, 0);

6
src/mod_auth.c

@ -839,7 +839,7 @@ mod_auth_check_basic(request_st * const r, void *p_d, const struct http_auth_req
default:
log_error(r->conf.errh, __FILE__, __LINE__,
"password doesn't match for %s username: %s IP: %s",
r->uri.path.ptr, user, r->con->dst_addr_buf->ptr);
r->uri.path.ptr, user, r->con->dst_addr_buf.ptr);
r->keep_alive = -1; /*(disable keep-alive if bad password)*/
rc = mod_auth_send_401_unauthorized_basic(r, require->realm);
break;
@ -1305,7 +1305,7 @@ mod_auth_digest_validate_params (request_st * const r, const struct http_auth_re
log_error(r->conf.errh, __FILE__, __LINE__,
"digest: auth failed: uri mismatch (%s != %.*s), IP: %s",
r->target_orig.ptr, (int)dp->len[e_uri], dp->ptr[e_uri],
r->con->dst_addr_buf->ptr);
r->con->dst_addr_buf.ptr);
return mod_auth_send_400_bad_request(r);
}
@ -1417,7 +1417,7 @@ mod_auth_check_digest (request_st * const r, void *p_d, const struct http_auth_r
/* digest not ok */
log_error(r->conf.errh, __FILE__, __LINE__,
"digest: auth failed for %.*s: wrong password, IP: %s",
(int)ai.ulen, ai.username, r->con->dst_addr_buf->ptr);
(int)ai.ulen, ai.username, r->con->dst_addr_buf.ptr);
r->keep_alive = -1; /*(disable keep-alive if bad password)*/
return mod_auth_send_401_unauthorized_digest(r, require, 0);
}

2
src/mod_authn_gssapi.c

@ -785,7 +785,7 @@ static handler_t mod_authn_gssapi_basic(request_st * const r, void *p_d, const h
/* ret == KRB5KDC_ERR_C_PRINCIPAL_UNKNOWN or no authz rules match */
log_error(r->conf.errh, __FILE__, __LINE__,
"password doesn't match for %s username: %s IP: %s",
r->uri.path.ptr, username->ptr, r->con->dst_addr_buf->ptr);
r->uri.path.ptr, username->ptr, r->con->dst_addr_buf.ptr);
return mod_authn_gssapi_send_401_unauthorized_basic(r);
}
}

2
src/mod_authn_pam.c

@ -150,7 +150,7 @@ static handler_t mod_authn_pam_query(request_st * const r, void *p_d, const buff
mod_authn_pam_patch_config(r, p);
const char * const addrstr = r->con->dst_addr_buf->ptr;
const char * const addrstr = r->con->dst_addr_buf.ptr;
rc = pam_start(p->conf.service, username->ptr, &conv, &pamh);
if (PAM_SUCCESS != rc
|| PAM_SUCCESS !=(rc = pam_set_item(pamh, PAM_RHOST, addrstr))

2
src/mod_evasive.c

@ -147,7 +147,7 @@ URIHANDLER_FUNC(mod_evasive_uri_handler) {
if (!p->conf.silent) {
log_error(r->conf.errh, __FILE__, __LINE__,
"%s turned away. Too many connections.",
r->con->dst_addr_buf->ptr);
r->con->dst_addr_buf.ptr);
}
if (p->conf.location) {

27
src/mod_extforward.c

@ -522,7 +522,7 @@ static int is_proxy_trusted(plugin_data *p, const char * const ip, size_t iplen)
static int is_connection_trusted(connection * const con, plugin_data *p)
{
if (p->conf.forward_all) return (1 == p->conf.forward_all);
return is_proxy_trusted(p, BUF_PTR_LEN(con->dst_addr_buf));
return is_proxy_trusted(p, BUF_PTR_LEN(&con->dst_addr_buf));
}
/*
@ -573,21 +573,22 @@ static int mod_extforward_set_addr(request_st * const r, plugin_data *p, const c
"-- mod_extforward_uri_handler already patched this connection, resetting state");
}
con->dst_addr = hctx->saved_remote_addr;
buffer_move(con->dst_addr_buf, &hctx->saved_remote_addr_buf);
buffer_move(&con->dst_addr_buf, &hctx->saved_remote_addr_buf);
}
} else {
con->plugin_ctx[p->id] = hctx = handler_ctx_init();
}
/* save old address */
if (extforward_check_proxy) {
http_header_env_set(r, CONST_STR_LEN("_L_EXTFORWARD_ACTUAL_FOR"), BUF_PTR_LEN(con->dst_addr_buf));
http_header_env_set(r, CONST_STR_LEN("_L_EXTFORWARD_ACTUAL_FOR"),
BUF_PTR_LEN(&con->dst_addr_buf));
}
hctx->request_count = con->request_count;
hctx->saved_remote_addr = con->dst_addr;
buffer_move(&hctx->saved_remote_addr_buf, con->dst_addr_buf);
buffer_move(&hctx->saved_remote_addr_buf, &con->dst_addr_buf);
/* patch connection address */
con->dst_addr = sock;
buffer_copy_string_len(con->dst_addr_buf, addr, addrlen);
buffer_copy_string_len(&con->dst_addr_buf, addr, addrlen);
/* Now, clean the conf_cond cache, because we may have changed the results of tests */
config_cond_cache_reset_item(r, COMP_HTTP_REMOTE_IP);
@ -1109,7 +1110,7 @@ URIHANDLER_FUNC(mod_extforward_uri_handler) {
log_error(r->conf.errh, __FILE__, __LINE__,
"no forward header found or "
"remote address %s is NOT a trusted proxy, skipping",
r->con->dst_addr_buf->ptr);
r->con->dst_addr_buf.ptr);
}
return HANDLER_GO_ON;
}
@ -1145,7 +1146,7 @@ REQUEST_FUNC(mod_extforward_restore) {
if (!buffer_is_unset(&hctx->saved_remote_addr_buf)) {
con->dst_addr = hctx->saved_remote_addr;
buffer_move(con->dst_addr_buf, &hctx->saved_remote_addr_buf);
buffer_move(&con->dst_addr_buf, &hctx->saved_remote_addr_buf);
/* Now, clean the conf_cond cache, because we may have changed the results of tests */
config_cond_cache_reset_item(r, COMP_HTTP_REMOTE_IP);
}
@ -1169,7 +1170,7 @@ CONNECTION_FUNC(mod_extforward_handle_con_close)
}
if (!buffer_is_unset(&hctx->saved_remote_addr_buf)) {
con->dst_addr = hctx->saved_remote_addr;
buffer_move(con->dst_addr_buf, &hctx->saved_remote_addr_buf);
buffer_move(&con->dst_addr_buf, &hctx->saved_remote_addr_buf);
}
if (NULL != hctx->env) {
array_free(hctx->env);
@ -1201,7 +1202,7 @@ CONNECTION_FUNC(mod_extforward_handle_con_accept)
if (r->conf.log_request_handling) {
log_error(r->conf.errh, __FILE__, __LINE__,
"remote address %s is NOT a trusted proxy, skipping",
con->dst_addr_buf->ptr);
con->dst_addr_buf.ptr);
}
}
return HANDLER_GO_ON;
@ -1485,7 +1486,7 @@ static int mod_extforward_hap_PROXY_v1 (connection * const con,
/* re-parse addr to string to normalize
* (instead of trusting PROXY to provide canonicalized src_addr string)
* (should prefer PROXY v2 protocol if concerned about performance) */
sock_addr_inet_ntop_copy_buffer(con->dst_addr_buf, &con->dst_addr);
sock_addr_inet_ntop_copy_buffer(&con->dst_addr_buf, &con->dst_addr);
return 0;
}
@ -1545,7 +1546,7 @@ static int mod_extforward_hap_PROXY_v2 (connection * const con,
case 0x11: /* TCPv4 */
sock_addr_assign(&con->dst_addr, AF_INET, hdr->v2.addr.ip4.src_port,
&hdr->v2.addr.ip4.src_addr);
sock_addr_inet_ntop_copy_buffer(con->dst_addr_buf, &con->dst_addr);
sock_addr_inet_ntop_copy_buffer(&con->dst_addr_buf, &con->dst_addr);
#if 0
((struct sockaddr_in *)&by)->sin_family = AF_INET;
((struct sockaddr_in *)&by)->sin_addr.s_addr =
@ -1559,7 +1560,7 @@ static int mod_extforward_hap_PROXY_v2 (connection * const con,
case 0x21: /* TCPv6 */
sock_addr_assign(&con->dst_addr, AF_INET6, hdr->v2.addr.ip6.src_port,
&hdr->v2.addr.ip6.src_addr);
sock_addr_inet_ntop_copy_buffer(con->dst_addr_buf, &con->dst_addr);
sock_addr_inet_ntop_copy_buffer(&con->dst_addr_buf, &con->dst_addr);
#if 0
((struct sockaddr_in6 *)&by)->sin6_family = AF_INET6;
memcpy(&((struct sockaddr_in6 *)&by)->sin6_addr,
@ -1578,7 +1579,7 @@ static int mod_extforward_hap_PROXY_v2 (connection * const con,
if (NULL == z) return -1; /* invalid addr; too long */
len = (uint32_t)(z - src_addr + 1); /*(+1 for '\0')*/
sock_addr_assign(&con->dst_addr, AF_UNIX, 0, src_addr);
buffer_copy_string_len(con->dst_addr_buf, src_addr, len);
buffer_copy_string_len(&con->dst_addr_buf, src_addr, len);
}
#if 0 /*(dst_addr should be identical to src_addr for AF_UNIX)*/
((struct sockaddr_un *)&by)->sun_family = AF_UNIX;

2
src/mod_geoip.c

@ -208,7 +208,7 @@ SETDEFAULTS_FUNC(mod_geoip_set_defaults) {
static handler_t mod_geoip_query (request_st * const r, plugin_data * const p) {
GeoIPRecord *gir;
const char *remote_ip = r->con->dst_addr_buf->ptr;
const char *remote_ip = r->con->dst_addr_buf.ptr;
if (NULL != http_header_env_get(r, CONST_STR_LEN("GEOIP_COUNTRY_CODE"))) {
return HANDLER_GO_ON;

2
src/mod_magnet.c

@ -541,7 +541,7 @@ static buffer *magnet_env_get_buffer_by_id(request_st * const r, int id) {
case MAGNET_ENV_REQUEST_URI: dest = &r->target; break;
case MAGNET_ENV_REQUEST_ORIG_URI: dest = &r->target_orig; break;
case MAGNET_ENV_REQUEST_PATH_INFO: dest = &r->pathinfo; break;
case MAGNET_ENV_REQUEST_REMOTE_IP: dest = r->con->dst_addr_buf; break;
case MAGNET_ENV_REQUEST_REMOTE_IP: dest = &r->con->dst_addr_buf; break;
case MAGNET_ENV_REQUEST_SERVER_ADDR: /* local IP without port */
{
const server_socket * const srv_socket = r->con->srv_socket;

8
src/mod_proxy.c

@ -687,15 +687,15 @@ static void proxy_set_Forwarded(connection * const con, request_st * const r, co
} else if (family == AF_INET) {
/*(Note: if :port is added, then must be quoted-string:
* e.g. for="...:port")*/
buffer_append_string_buffer(b, con->dst_addr_buf);
buffer_append_string_buffer(b, &con->dst_addr_buf);
} else if (family == AF_INET6) {
buffer_append_str3(b, CONST_STR_LEN("\"["),
BUF_PTR_LEN(con->dst_addr_buf),
BUF_PTR_LEN(&con->dst_addr_buf),
CONST_STR_LEN("]\""));
} else {
buffer_append_string_len(b, CONST_STR_LEN("\""));
buffer_append_string_backslash_escaped(
b, BUF_PTR_LEN(con->dst_addr_buf));
b, BUF_PTR_LEN(&con->dst_addr_buf));
buffer_append_string_len(b, CONST_STR_LEN("\""));
}
semicolon = 1;
@ -780,7 +780,7 @@ static void proxy_set_Forwarded(connection * const con, request_st * const r, co
/* legacy X-* headers, including X-Forwarded-For */
b = (NULL != efor) ? efor : con->dst_addr_buf;
b = (NULL != efor) ? efor : &con->dst_addr_buf;
http_header_request_set(r, HTTP_HEADER_X_FORWARDED_FOR,
CONST_STR_LEN("X-Forwarded-For"),
BUF_PTR_LEN(b));

2
src/mod_status.c

@ -234,7 +234,7 @@ static void mod_status_get_multiplier(buffer *b, double avg, int size) {
static void mod_status_html_rtable_r (buffer * const b, const request_st * const r, const connection * const con, const time_t cur_ts) {
buffer_append_str3(b, CONST_STR_LEN("<tr><td class=\"string\">"),
BUF_PTR_LEN(con->dst_addr_buf),
BUF_PTR_LEN(&con->dst_addr_buf),
CONST_STR_LEN("</td><td class=\"int\">"));
if (r->reqbody_length) {

2
src/mod_trigger_b4_dl.c

@ -397,7 +397,7 @@ URIHANDLER_FUNC(mod_trigger_b4_dl_uri_handler) {
http_header_request_get(r, HTTP_HEADER_X_FORWARDED_FOR,
CONST_STR_LEN("X-Forwarded-For"));
if (NULL == remote_ip) {
remote_ip = r->con->dst_addr_buf;
remote_ip = &r->con->dst_addr_buf;
}
if (p->conf.debug) {

Loading…
Cancel
Save