Commit Graph

4040 Commits

Author SHA1 Message Date
Glenn Strauss 9fe8fbaa72 [multiple] http_method_buf()
- http_method_buf() returns (const buffer *)
- comment out unused get_http_status_name()
- inline func for http_append_method()

config processing requires a persistent buffer for method on the
off-chance that the config performed a capturing regex match in
$HTTP["method"] condition and used it later (e.g. in mod_rewrite)
(Prior behavior using r->tmp_buf was undefined in this case)
2021-08-27 02:16:54 -04:00
Glenn Strauss 1de03a03ee [core] reduce $HTTP["host"] compare str scanning 2021-08-27 02:16:54 -04:00
Glenn Strauss 4b9da9f1e8 [core] parse $HTTP["remote-ip"] CIDR mask at start
parse $HTTP["remote-ip"] CIDR mask into structured data at startup

note: adds buffer_move() to configparser.y to reduce memory copying
for all config values, and is required for remote-ip to preserve the
structured data added after the config value string.  (Alternatively,
could have normalized the remote-ip value after copying into dc->string)
2021-08-27 02:16:54 -04:00
Glenn Strauss e34ce5f217 [core] const buffer * in config_check_cond_nocache
use (const buffer *) in config_check_cond_nocache()
2021-08-27 02:16:54 -04:00
Glenn Strauss 1ca721d479 [core] reduce excess cc inlining in http_chunk.c 2021-08-27 02:16:54 -04:00
Glenn Strauss 3a568c639c [core] http_date_time_append() convenience macro
append IMF-fixdate time string to (buffer *)
2021-08-27 02:16:54 -04:00
Glenn Strauss 9f90f33288 [core] write_all() simpler loop; better asm 2021-08-27 02:16:54 -04:00
Glenn Strauss 18e96334d6 [core] proxy_create_env() tweaks
reorder some code for better asm

proxy_set_Forwarded() sets multiple request headers, and does so prior
to walking all request headers to create request to backend.  This is
done so that specific already-existing request headers from client are
overwritten (intentionally) in proxy_set_Forwarded().

Expect header is handled, but not expected since client-sent Expect
header is handled (and unset) in connection_handle_read_post_state()
2021-08-27 02:16:54 -04:00
Glenn Strauss 9f82ba8fab [mod_proxy] proxy_response_headers load v earlier
proxy_response_headers() issue variable load slightly earlier
2021-08-27 02:16:54 -04:00
Glenn Strauss f2cdee2430 [core] order gw_host members for packing and usage 2021-08-27 02:16:54 -04:00
Glenn Strauss 50f88480a6 [core] order gw_proc members for packing and usage 2021-08-27 02:16:54 -04:00
Glenn Strauss e89d75136c [core] avoid inlining buffer_eq_icase_ssn()
(slightly better asm)
2021-08-27 02:16:54 -04:00
Glenn Strauss 2899d7f983 [core] construct file path after docroot hook
also remove some excess/duplicative trace during request processing
2021-08-27 02:16:54 -04:00
Glenn Strauss 5bc92071d7 [core] reset large path buffers from long URLs 2021-08-27 02:16:54 -04:00
Glenn Strauss f1e8a82f1a [multiple] inline struct in con->dst_addr_buf
(mod_extforward recently changed to use buffer_move() to save addr
 instead of swapping pointers)
2021-08-27 02:16:54 -04:00
Glenn Strauss e6f286ef5f [multiple] reduce use of BUFFER_INTLEN_PTR
reduce use of BUFFER_INTLEN_PTR where b->ptr known not to be NULL
2021-08-27 02:16:54 -04:00
Glenn Strauss 38a9f0ebdd [mod_access] remove excess trace
trace is still issued if access is denied
  and r->log_request_handling is set
2021-08-27 02:16:53 -04:00
Glenn Strauss 2d9bf8062d [mod_extforward] inline some more data structures 2021-08-27 02:16:53 -04:00
Glenn Strauss 4ccd86f981 [core] allocate initial request pool w/ srv->conns
allocate reusable h2 request pool when initial srv->conns pool allocated
2021-08-27 02:16:53 -04:00
Glenn Strauss 1cd73b08a6 [core] move backtrace and assert macros to ck.[ch] 2021-08-27 02:16:53 -04:00
Glenn Strauss 4e5b822b16 [mod_magnet] cache script objects at config time
always check at least mtime and size to trigger script reload
2021-08-27 02:16:53 -04:00
Glenn Strauss f490078d0f [multiple] buffer_copy_string_len_lc()
convenience wrapper combining
and making a single pass over string
2021-08-27 02:16:53 -04:00
Glenn Strauss 8c5acaae3c [core] lowercase r->http_host, r->uri.authority
always lowercase r->http_host, r->uri.authority for consistency
2021-08-27 02:16:53 -04:00
Glenn Strauss 84fa4b8d1b [core] buffer_realloc() using power-2 realloc 2021-08-27 02:16:53 -04:00
Glenn Strauss caff799ccb [build] look for port.h on Solaris, not sys/port.h 2021-08-27 02:16:53 -04:00
Glenn Strauss 0f90a9e320 [core] reduce memcmp in http_request_parse_header
extend http_header_parse_ctx to support enum http_header_h2_e
HTTP/2 pseudo-headers in hpctx->id before using memcmp()
2021-08-27 02:16:53 -04:00
Glenn Strauss 5beee8b2d4 [core] buffer_path_simplify() quick(er) path
scan to detect (potential) need for path simplification
(repeated '/' or "/.") before copying each char in string
2021-08-27 02:16:53 -04:00
Glenn Strauss 1f161bda1f [build] look for memcpy and define HAVE_MEMCPY
(HAVE_MEMCPY checked by ancient MD5 implementation in algo_md5.c)
2021-08-27 02:16:53 -04:00
Glenn Strauss 56e2881c36 [mod_auth] refactor mod_auth_check_basic()
refactor mod_auth_check_basic()
- use stack for base64-decoded username:password, and limit to 1k
2021-08-27 02:16:53 -04:00
Glenn Strauss 20c56cecc3 [mod_auth] refactor mod_auth_check_digest()
refactor mod_auth_check_digest()
- smaller functions
- collect parsed Authorization header into http_auth_digest_params_t
- use string references rather than copying and modifying Authorization
2021-08-27 02:16:53 -04:00
Glenn Strauss 60b773a6cb [mod_authn_dbi] copy strings before escaping
dbi_conn_escape_string_copy() requires '\0'-terminated string.
While that is currently the case for strings in http_auth_info_t,
that will soon change, so consumers must use ai->username with ai->ulen,
and ai->realm with ai->rlen
2021-08-27 02:16:53 -04:00
Glenn Strauss 870b0c1343 [mod_auth] mod_auth_algorithm_parse() w/ algo len
mod_auth_algorithm_parse() now takes an additional arg: algorithm strlen
2021-08-27 02:16:53 -04:00
Glenn Strauss c841ce3b0b [mod_auth] mod_auth_digest_get()
create func mod_auth_digest_get() with code pulled from
mod_auth_check_digest(), and have mod_auth_check_digest()
call mod_auth_digest_get()
2021-08-27 02:16:53 -04:00
Glenn Strauss c987bec18e [multiple] use <algo>_iov() digest funcs
reduce code duplication
make it easier to add new algos

- leverage r->tmp_buf instead of temporary allocating buffer_init()
- mod_authn_file_htpasswd_basic()
  - compare binary SHA1 (shorter) rather than base64 (longer)
  - split crypt() from mod_authn_file_htpasswd_basic() to separate func
  - apr_md5_encode() modifications for slightly better performance
2021-08-27 02:16:53 -04:00
Glenn Strauss 396a923066 [core] li_base64_dec()
(make public in base64.h, like li_base64_enc())
2021-08-27 02:16:53 -04:00
Glenn Strauss db4af125c0 [core] add iovec wrappers to sys-crypto-md.h 2021-08-27 02:16:53 -04:00
Glenn Strauss ffc7a0bfd8 [mod_auth] merge some repeated code; code reuse 2021-08-27 02:16:53 -04:00
Glenn Strauss d22e94ac88 [core] clear etag in stat_cache_get_entry_open()
clear etag in stat_cache_get_entry_open() after opening file
(in case a different caller used stat_get_get_entry() and then file
changed before being opened)
2021-08-27 02:16:53 -04:00
Glenn Strauss 2d898bf9a9 [mod_magnet] sync script load w/ stat_cache
read file and use luaL_loadbuffer()
eliminate TOC-TOU race w/ independent stat() in stat_cache_get_entry()

restructure script_cache_get_script() into smaller funcs
2021-08-27 02:16:53 -04:00
Glenn Strauss e86dba5468 [mod_magnet] inline name and etag buffers in cache
also mark cache init and cache free funcs as cold
2021-08-27 02:16:53 -04:00
Glenn Strauss d5366c0aee [core] request_config_reset()
move configfile.c:config_reset_config()
  to reqpool.c:request_config_reset()
2021-08-27 02:16:53 -04:00
Glenn Strauss d38d5b4b48 [core] gw_host_get() comment out devel debugging
gw_host_get() comment out devel debugging trace
use variables within smaller scopes
2021-08-27 02:16:53 -04:00
Glenn Strauss b33d779865 [core] calculate backend host gw_hash at startup
- calculate backend host gw_hash at startup
- modify hash calculation at runtime to combine xor bits
  for hash value used in balancing selection
2021-08-27 02:16:53 -04:00
Glenn Strauss af3df29ae8 [multiple] reduce redundant NULL buffer checks
This commit is a large set of code changes and results in removal of
hundreds, perhaps thousands, of CPU instructions, a portion of which
are on hot code paths.

Most (buffer *) used by lighttpd are not NULL, especially since buffers
were inlined into numerous larger structs such as request_st and chunk.

In the small number of instances where that is not the case, a NULL
check is often performed earlier in a function where that buffer is
later used with a buffer_* func.  In the handful of cases that remained,
a NULL check was added, e.g. with r->http_host and r->conf.server_tag.

- check for empty strings at config time and set value to NULL if blank
  string will be ignored at runtime; at runtime, simple pointer check
  for NULL can be used to check for a value that has been set and is not
  blank ("")
- use buffer_is_blank() instead of buffer_string_is_empty(),
  and use buffer_is_unset() instead of buffer_is_empty(),
  where buffer is known not to be NULL so that NULL check can be skipped
- use buffer_clen() instead of buffer_string_length() when buffer is
  known not to be NULL (to avoid NULL check at runtime)
- use buffer_truncate() instead of buffer_string_set_length() to
  truncate string, and use buffer_extend() to extend

Examples where buffer known not to be NULL:
  - cpv->v.b from config_plugin_values_init is not NULL if T_CONFIG_BOOL
    (though we might set it to NULL if buffer_is_blank(cpv->v.b))
  - address of buffer is arg (&foo)
    (compiler optimizer detects this in most, but not all, cases)
  - buffer is checked for NULL earlier in func
  - buffer is accessed in same scope without a NULL check (e.g. b->ptr)

internal behavior change:
  callers must not pass a NULL buffer to some funcs.
  - buffer_init_buffer() requires non-null args
  - buffer_copy_buffer() requires non-null args
  - buffer_append_string_buffer() requires non-null args
  - buffer_string_space() requires non-null arg
2021-08-27 02:16:53 -04:00
Glenn Strauss 937d83b6cf [core] inline fam_dir_entry buffer 'name' member 2021-08-27 02:16:53 -04:00
Glenn Strauss 28804e8c80 [core] comment out unused part of http_etag_remix
note: etag buffer etag->ptr might be NULL (etag->used = etag->sze = 0)
so buffer will need to be extended, not truncated, in that case.
buffer_string_set_length() is typically used to truncate strings.
2021-08-27 02:16:53 -04:00
Glenn Strauss 7cd984c51d [core] adjust buffer use for hdr name for lshpack 2021-08-27 02:16:53 -04:00
Glenn Strauss a8b5ad2b5c [core] tweaks writing response header (better asm) 2021-08-27 02:16:53 -04:00
Glenn Strauss db853f9c05 [core] sock_addr_from_buffer_hints_numeric unused
comment out sock_addr_from_buffer_hints_numeric(); currently unused
2021-08-27 02:16:53 -04:00
Glenn Strauss 66626315ba [TLS] reset stek_rotate_ts if clock moves backward
reset stek_rotate_ts if clock moves backwards > 28800 seconds

  "Lighttpd 1.4.58 SSL connections stop working if system time of lighttpd server is changed to future one (+12h or even days)"
2021-08-27 02:16:53 -04:00