-
Notifications
You must be signed in to change notification settings - Fork 23
feat: support OpenResty 1.29.2.4 patches #113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c074652
feat: support OpenResty 1.29.2.4 patches
jarvis9443 b3dfda5
fix: address OpenResty 1.29.2.4 patch review
jarvis9443 e7eff2a
fix: address runtime patch review
jarvis9443 36c6de7
fix: address OpenResty 1.29.2 patch review comments
jarvis9443 40492bc
fix: export stream TLS session free FFI
jarvis9443 3a4ee4d
fix: address OpenResty 1.29.2 patch review
jarvis9443 f2d6704
fix: avoid crc32 sentinel for keepalive pools
jarvis9443 c4b38ec
fix: address OpenResty patch review feedback
jarvis9443 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| diff --git lib/ngx/balancer.lua lib/ngx/balancer.lua | ||
| index 18bdc2c..3a98f53 100644 | ||
| --- lib/ngx/balancer.lua | ||
| +++ lib/ngx/balancer.lua | ||
| @@ -3,7 +3,7 @@ | ||
|
|
||
| local base = require "resty.core.base" | ||
| base.allows_subsystem('http', 'stream') | ||
| - | ||
| +require "resty.core.hash" | ||
|
|
||
| local ffi = require "ffi" | ||
| local C = ffi.C | ||
| @@ -20,6 +20,7 @@ local error = error | ||
| local type = type | ||
| local tonumber = tonumber | ||
| local max = math.max | ||
| +local ngx_crc32_long = ngx.crc32_long | ||
|
|
||
| local subsystem = ngx.config.subsystem | ||
| local ngx_lua_ffi_balancer_set_current_peer | ||
| @@ -35,8 +36,8 @@ if subsystem == 'http' then | ||
| ffi.cdef[[ | ||
| int ngx_http_lua_ffi_balancer_set_current_peer(ngx_http_request_t *r, | ||
| const unsigned char *addr, size_t addr_len, int port, | ||
| - const unsigned char *host, ssize_t host_len, | ||
| - char **err); | ||
| + unsigned int cpool_crc32, int cpool_set, unsigned int cpool_size, | ||
| + char **err); | ||
|
|
||
| int ngx_http_lua_ffi_balancer_enable_keepalive(ngx_http_request_t *r, | ||
| unsigned long timeout, unsigned int max_requests, char **err); | ||
| @@ -130,6 +130,7 @@ else | ||
| error("unknown subsystem: " .. subsystem) | ||
| end | ||
|
|
||
| +local DEFAULT_KEEPALIVE_POOL_SIZE = 30 | ||
| local DEFAULT_KEEPALIVE_IDLE_TIMEOUT = 60000 | ||
| local DEFAULT_KEEPALIVE_MAX_REQUESTS = 100 | ||
|
|
||
| @@ -143,27 +144,67 @@ local peer_state_names = { | ||
| local _M = { version = base.version } | ||
|
|
||
| if subsystem == "http" then | ||
| - function _M.set_current_peer(addr, port, host) | ||
| + function _M.set_current_peer(addr, port, opts) | ||
| local r = get_request() | ||
| if not r then | ||
| error("no request found") | ||
| end | ||
|
|
||
| + local pool_crc32 | ||
| + local pool_set = 0 | ||
| + local pool_size | ||
| + if opts then | ||
| + if type(opts) ~= "table" then | ||
| + error("bad argument #3 to 'set_current_peer' " .. | ||
| + "(table expected, got " .. type(opts) .. ")", 2) | ||
| + end | ||
| + | ||
| + local pool = opts.pool | ||
| + pool_size = opts.pool_size | ||
| + | ||
| + if pool then | ||
| + if type(pool) ~= "string" then | ||
| + error("bad option 'pool' to 'set_current_peer' " .. | ||
| + "(string expected, got " .. type(pool) .. ")", 2) | ||
| + elseif pool == "" then | ||
| + error("bad option 'pool' to 'set_current_peer' " .. | ||
| + "(non-empty string expected)", 2) | ||
| + end | ||
| + | ||
| + pool_crc32 = ngx_crc32_long(pool) | ||
| + pool_set = 1 | ||
| + end | ||
| + | ||
| + if pool_size then | ||
| + if type(pool_size) ~= "number" then | ||
| + error("bad option 'pool_size' to 'set_current_peer' " .. | ||
| + "(number expected, got " .. type(pool_size) .. ")", 2) | ||
| + | ||
| + elseif pool_size < 1 then | ||
| + error("bad option 'pool_size' to 'set_current_peer' " .. | ||
| + "(expected > 0)", 2) | ||
| + end | ||
| + end | ||
| + end | ||
| + | ||
| if not port then | ||
| port = 0 | ||
| + | ||
| elseif type(port) ~= "number" then | ||
| port = tonumber(port) | ||
| end | ||
|
|
||
| - if host ~= nil and type(host) ~= "string" then | ||
| - error("bad argument #3 to 'set_current_peer' " | ||
| - .. "(string expected, got " .. type(host) .. ")") | ||
| + if not pool_crc32 then | ||
| + pool_crc32 = 0 | ||
| end | ||
|
|
||
| - local rc = ngx_lua_ffi_balancer_set_current_peer(r, addr, #addr, | ||
| - port, | ||
| - host, | ||
| - host and #host or 0, | ||
| + if not pool_size then | ||
| + pool_size = DEFAULT_KEEPALIVE_POOL_SIZE | ||
| + end | ||
| + | ||
| + local rc = ngx_lua_ffi_balancer_set_current_peer(r, addr, #addr, port, | ||
| + pool_crc32, pool_set, | ||
| + pool_size, | ||
| errmsg) | ||
| if rc == FFI_OK then | ||
| return true | ||
| @@ -172,26 +207,26 @@ if subsystem == "http" then | ||
| return nil, ffi_str(errmsg[0]) | ||
| end | ||
| else | ||
| - function _M.set_current_peer(addr, port, host) | ||
| + function _M.set_current_peer(addr, port, opts) | ||
| local r = get_request() | ||
| if not r then | ||
| error("no request found") | ||
| end | ||
|
|
||
| + if opts then | ||
| + error("bad argument #3 to 'set_current_peer' ('opts' not yet " .. | ||
| + "implemented in " .. subsystem .. " subsystem)", 2) | ||
| + end | ||
| + | ||
| if not port then | ||
| port = 0 | ||
| + | ||
| elseif type(port) ~= "number" then | ||
| port = tonumber(port) | ||
| end | ||
|
|
||
| - if host ~= nil then | ||
| - error("bad argument #3 to 'set_current_peer' ('host' not yet " .. | ||
| - "implemented in " .. subsystem .. " subsystem)", 2) | ||
| - end | ||
| - | ||
| local rc = ngx_lua_ffi_balancer_set_current_peer(r, addr, #addr, | ||
| - port, | ||
| - errmsg) | ||
| + port, errmsg) | ||
| if rc == FFI_OK then | ||
| return true | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| diff --git lib/resty/core/coroutine.lua lib/resty/core/coroutine.lua | ||
| index 42cf0d8..a468147 100644 | ||
| --- lib/resty/core/coroutine.lua | ||
| +++ lib/resty/core/coroutine.lua | ||
| @@ -13,7 +13,7 @@ do | ||
| local r = get_request() | ||
| if r ~= nil then | ||
| local ctx = get_raw_phase(r) | ||
| - if ctx ~= 0x020 and ctx ~= 0x040 then | ||
| + if ctx ~= 0x020 and ctx ~= 0x040 and ctx ~= 0x100 then | ||
| return ours(...) | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| diff --git lib/ngx/ssl.lua lib/ngx/ssl.lua | ||
| index b696bea..f3b20e0 100644 | ||
| --- lib/ngx/ssl.lua | ||
| +++ lib/ngx/ssl.lua | ||
| @@ -100,7 +100,7 @@ if subsystem == 'http' then | ||
| void ngx_http_lua_ffi_free_priv_key(void *cdata); | ||
|
|
||
| int ngx_http_lua_ffi_ssl_verify_client(void *r, | ||
| - void *client_certs, void *trusted_certs, int depth, char **err); | ||
| + void *client_certs, void *trusted_certs, int depth, int reject_in_handshake, char **err); | ||
|
|
||
| int ngx_http_lua_ffi_ssl_client_random(ngx_http_request_t *r, | ||
| const unsigned char *out, size_t *outlen, char **err); | ||
| @@ -198,7 +198,7 @@ elseif subsystem == 'stream' then | ||
| void ngx_stream_lua_ffi_free_priv_key(void *cdata); | ||
|
|
||
| int ngx_stream_lua_ffi_ssl_verify_client(void *r, | ||
| - void *client_certs, void *trusted_certs, int depth, char **err); | ||
| + void *client_certs, void *trusted_certs, int depth, int reject_in_handshake, char **err); | ||
|
|
||
| int ngx_stream_lua_ffi_ssl_client_random(ngx_stream_lua_request_t *r, | ||
| unsigned char *out, size_t *outlen, char **err); | ||
| @@ -484,7 +484,7 @@ function _M.set_priv_key(priv_key) | ||
| end | ||
|
|
||
|
|
||
| -function _M.verify_client(client_certs, depth, trusted_certs) | ||
| +function _M.verify_client(client_certs, depth, trusted_certs, reject_in_handshake) | ||
| local r = get_request() | ||
| if not r then | ||
| error("no request found") | ||
| @@ -494,8 +494,15 @@ function _M.verify_client(client_certs, depth, trusted_certs) | ||
| depth = -1 | ||
| end | ||
|
|
||
| + if reject_in_handshake == nil then | ||
| + -- reject by default so we can migrate to the new behavior | ||
| + -- without modifying Lua code | ||
| + reject_in_handshake = true | ||
| + end | ||
| + | ||
| + local reject_in_handshake_int = reject_in_handshake and 1 or 0 | ||
| local rc = ngx_lua_ffi_ssl_verify_client(r, client_certs, trusted_certs, | ||
| - depth, errmsg) | ||
| + depth, reject_in_handshake_int, errmsg) | ||
| if rc == FFI_OK then | ||
| return true | ||
| end |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.