Skip to content
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

feat(router): enable flavor expressions in stream subsystem #11071

Merged
merged 87 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
f4a7ac1
schema for stream
chronolaw Jun 14, 2023
8ae9a3a
c:add_value
chronolaw Jun 14, 2023
c3b7a68
_M:exec for stream
chronolaw Jun 14, 2023
2b7f28e
select for stream
chronolaw Jun 14, 2023
7d671e0
improve select
chronolaw Jun 14, 2023
af03e7e
style lint
chronolaw Jun 14, 2023
80bac69
cidr
chronolaw Jun 14, 2023
75a3d9c
no cidr
chronolaw Jun 14, 2023
fd0cd2d
stream select
chronolaw Jun 14, 2023
6eb7838
compat_stream.lua
chronolaw Jun 14, 2023
c3d4634
compat_stream.lua
chronolaw Jun 15, 2023
01c47d1
clean
chronolaw Jun 15, 2023
3b3dcb9
get_priority
chronolaw Jun 15, 2023
6ddaee0
compat_stream.lua
chronolaw Jun 15, 2023
4b73143
kong spec
chronolaw Jun 15, 2023
598332c
enable compat_stream
chronolaw Jun 15, 2023
a19ca93
debug unit-test
chronolaw Jun 15, 2023
4477f9a
debug unit-test
chronolaw Jun 15, 2023
8cf8e72
src.ip/dst.ip
chronolaw Jun 15, 2023
5e5c31d
fix uint tests
chronolaw Jun 15, 2023
11363d7
select
chronolaw Jun 15, 2023
9b12408
init.lua
chronolaw Jun 15, 2023
058093e
remove compat_stream.lua
chronolaw Jun 15, 2023
315288a
compat.lua
chronolaw Jun 15, 2023
f88c3b1
compat.lua
chronolaw Jun 15, 2023
f31b9f1
stream compat expr check
chronolaw Jun 15, 2023
c343b4d
test clean
chronolaw Jun 15, 2023
b0c7cf5
parse ip addr
chronolaw Jun 16, 2023
47ddbcc
parse_ip_addr
chronolaw Jun 18, 2023
6b060be
fix router_spec
chronolaw Jun 18, 2023
23b87b7
luacheck: ignore
chronolaw Jun 19, 2023
6ec02b1
remove #only
chronolaw Jun 19, 2023
cfedc5f
code clean
chronolaw Jun 19, 2023
4147f23
fix router ip cidr tests
chronolaw Jun 19, 2023
6bb34e9
unified schema for http/stream
chronolaw Jun 20, 2023
e8caf65
style fix
chronolaw Jun 20, 2023
3d5128f
08-router_spec.lua
chronolaw Jun 20, 2023
01e42ba
remove only
chronolaw Jun 20, 2023
a977a74
CHANGELOG.md
chronolaw Jun 20, 2023
8df289e
changelog
chronolaw Jun 21, 2023
94896c5
tls snis
chronolaw Jun 22, 2023
7fb5ea3
dont use ipairs
chronolaw Jun 26, 2023
61f98be
stream expression test
chronolaw Jul 6, 2023
b2f87b6
stream priority
chronolaw Jul 6, 2023
97ec945
stream priority
chronolaw Jul 6, 2023
c01c705
stream priority
chronolaw Jul 6, 2023
c32ee45
sni check
chronolaw Jul 6, 2023
fb2dc7b
get_expression
chronolaw Jul 6, 2023
176b542
clean
chronolaw Jul 6, 2023
61ddada
stream priority
chronolaw Jul 6, 2023
e603a0a
it_trad_only snis
chronolaw Jul 6, 2023
1dc3ce1
check empty route fields
chronolaw Jul 7, 2023
974a678
deps
chronolaw Jul 7, 2023
f7ee84b
clean
chronolaw Jul 7, 2023
0f130b6
clean
chronolaw Jul 7, 2023
18d4ccb
stream_get_priority
chronolaw Jul 7, 2023
622b235
08-router_spec.lua
chronolaw Jul 7, 2023
2f22c32
test expressions
chronolaw Jul 7, 2023
056585f
fix regex tests
chronolaw Jul 7, 2023
8b1b537
style clean
chronolaw Jul 7, 2023
6a633dd
deps
chronolaw Jul 7, 2023
6e23af2
26-udp_spec.lua
chronolaw Jul 7, 2023
488e3fd
26-udp_spec.lua
chronolaw Jul 7, 2023
069d7cc
28-stream_plugins_triggering_spec.lua
chronolaw Jul 7, 2023
c4d7540
fix spec 28
chronolaw Jul 7, 2023
2eb79a3
01-proxy_spec.lua
chronolaw Jul 7, 2023
64c4023
style clean
chronolaw Jul 7, 2023
dd3c3a7
06-ssl_spec.lua
chronolaw Jul 7, 2023
b147c18
23-context_spec.lua
chronolaw Jul 10, 2023
416d9cb
lshift_uint64
chronolaw Jul 10, 2023
33dd171
bump atc-router to 1.2.0
chronolaw Jul 10, 2023
fe2070b
changelog
chronolaw Jul 10, 2023
0a8a768
small style fix
chronolaw Jul 10, 2023
44bc1f5
18-upstream_tls_spec.lua
chronolaw Jul 10, 2023
72fa5ff
ip op in compat
chronolaw Jul 10, 2023
1834c1d
10-balancer/06-stream_spec.lua
chronolaw Jul 10, 2023
8329de0
calc weight clean
chronolaw Jul 12, 2023
90cfcf6
some comments
chronolaw Jul 12, 2023
8cd2497
06-ssl_spec.lua
chronolaw Jul 12, 2023
a74d7db
style lint
chronolaw Jul 12, 2023
681969e
08-router_spec.lua
chronolaw Jul 17, 2023
b559edd
nets_buf
chronolaw Jul 24, 2023
c07988a
gen net.protocol
chronolaw Jul 24, 2023
9b4ec44
fixme ipv6
chronolaw Jul 24, 2023
45de53b
fix 08-router_spec.lua
chronolaw Jul 24, 2023
e2efc7f
revert nets_buf change
chronolaw Jul 24, 2023
fd9bf99
add cache for stream router
chronolaw Jul 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .requirements
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ LUA_KONG_NGINX_MODULE=4d19e8d19c6dbc07eba5cf6f5ebacad95266f928 # 0.6.0
LUA_RESTY_LMDB=951926f20b674a0622236a0e331b359df1c02d9b # 1.3.0
LUA_RESTY_EVENTS=8448a92cec36ac04ea522e78f6496ba03c9b1fd8 # 0.2.0
LUA_RESTY_WEBSOCKET=60eafc3d7153bceb16e6327074e0afc3d94b1316 # 0.4.0
ATC_ROUTER=72cc8fddeac024c54c9c1fa5a25c28a72d79080e # 1.1.0
ATC_ROUTER=b0d5e7e2a2ca59bb051959385d3e42d96c93bb98 # 1.2.0
StarlightIbuki marked this conversation as resolved.
Show resolved Hide resolved

KONG_MANAGER=nightly
NGX_WASM_MODULE_BRANCH=main
Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@

#### Core

- Enable `expressions` and `traditional_compatible` router flavor in stream subsystem.
[#11071](https://github.com/Kong/kong/pull/11071)

#### Admin API

#### Kong Manager
Expand Down Expand Up @@ -165,8 +168,9 @@
- Bumped pgmoon from 1.16.0 to 1.16.2 (Kong's fork)
[#11181](https://github.com/Kong/kong/pull/11181)
[#11229](https://github.com/Kong/kong/pull/11229)
- Bumped atc-router from 1.0.5 to 1.1.0
- Bumped atc-router from 1.0.5 to 1.2.0
[#10100](https://github.com/Kong/kong/pull/10100)
[#11071](https://github.com/Kong/kong/pull/11071)
- Bumped lua-resty-lmdb from 1.1.0 to 1.3.0
[#11227](https://github.com/Kong/kong/pull/11227)

Expand Down
144 changes: 143 additions & 1 deletion kong/router/atc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ local assert = assert
local setmetatable = setmetatable
local pairs = pairs
local ipairs = ipairs
local tonumber = tonumber


local max = math.max
Expand Down Expand Up @@ -49,6 +50,9 @@ local LOGICAL_OR = " || "
local LOGICAL_AND = " && "


local is_http = ngx.config.subsystem == "http"


-- reuse buffer object
local values_buf = buffer.new(64)

Expand All @@ -64,8 +68,11 @@ do
},

["Int"] = {"net.port",
"net.src.port", "net.dst.port",
},

["IpAddr"] = {"net.src.ip", "net.dst.ip",
},
}

CACHED_SCHEMA = schema.new()
Expand Down Expand Up @@ -343,7 +350,6 @@ end
-- example.*:123 => example.*, 123
local split_host_port
do
local tonumber = tonumber
local DEFAULT_HOSTS_LRUCACHE_SIZE = DEFAULT_MATCH_LRUCACHE_SIZE

local memo_hp = lrucache.new(DEFAULT_HOSTS_LRUCACHE_SIZE)
Expand Down Expand Up @@ -381,6 +387,8 @@ do
end


if is_http then
randmonkey marked this conversation as resolved.
Show resolved Hide resolved

function _M:select(req_method, req_uri, req_host, req_scheme,
src_ip, src_port,
dst_ip, dst_port,
Expand Down Expand Up @@ -588,6 +596,140 @@ function _M:exec(ctx)
return match_t
end

else -- is stream subsystem

function _M:select(_, _, _, scheme,
StarlightIbuki marked this conversation as resolved.
Show resolved Hide resolved
src_ip, src_port,
dst_ip, dst_port,
sni)

check_select_params(nil, nil, nil, scheme,
src_ip, src_port,
dst_ip, dst_port,
sni)

local c = context.new(self.schema)

for _, field in ipairs(self.fields) do
if field == "net.protocol" then
assert(c:add_value(field, scheme))

elseif field == "tls.sni" then
local res, err = c:add_value(field, sni)
if not res then
return nil, err
end

elseif field == "net.src.ip" then
assert(c:add_value(field, src_ip))

elseif field == "net.src.port" then
assert(c:add_value(field, src_port))

elseif field == "net.dst.ip" then
assert(c:add_value(field, dst_ip))

elseif field == "net.dst.port" then
assert(c:add_value(field, dst_port))

end -- if
end -- for

local matched = self.router:execute(c)
if not matched then
return nil
end

local uuid = c:get_result()

local service = self.services[uuid]
local matched_route = self.routes[uuid]
StarlightIbuki marked this conversation as resolved.
Show resolved Hide resolved

local service_protocol, _, --service_type
service_host, service_port,
service_hostname_type = get_service_info(service)

return {
route = matched_route,
service = service,
upstream_url_t = {
type = service_hostname_type,
host = service_host,
port = service_port,
},
upstream_scheme = service_protocol,
StarlightIbuki marked this conversation as resolved.
Show resolved Hide resolved
}
end


function _M:exec(ctx)
StarlightIbuki marked this conversation as resolved.
Show resolved Hide resolved
local src_ip = var.remote_addr
local dst_ip = var.server_addr

local src_port = tonumber(var.remote_port, 10)
local dst_port = tonumber((ctx or ngx.ctx).host_port, 10) or
tonumber(var.server_port, 10)

-- error value for non-TLS connections ignored intentionally
local sni = server_name()

-- fallback to preread SNI if current connection doesn't terminate TLS
if not sni then
sni = var.ssl_preread_server_name
end

local scheme
if var.protocol == "UDP" then
scheme = "udp"
else
scheme = sni and "tls" or "tcp"
end

-- when proxying TLS request in second layer or doing TLS passthrough
-- rewrite the dst_ip, port back to what specified in proxy_protocol
if var.kong_tls_passthrough_block == "1" or var.ssl_protocol then
dst_ip = var.proxy_protocol_server_addr
dst_port = tonumber(var.proxy_protocol_server_port)
end

local cache_key = (src_ip or "") .. "|" ..
(src_port or "") .. "|" ..
(dst_ip or "") .. "|" ..
(dst_port or "") .. "|" ..
(sni or "")

local match_t = self.cache:get(cache_key)
if not match_t then
if self.cache_neg:get(cache_key) then
route_match_stat(ctx, "neg")
return nil
end

local err
match_t, err = self:select(nil, nil, nil, scheme,
src_ip, src_port,
dst_ip, dst_port,
sni)
if not match_t then
if err then
ngx_log(ngx_ERR, "router returned an error: ", err)
end

self.cache_neg:set(cache_key, true)
return nil
end

self.cache:set(cache_key, match_t)

else
route_match_stat(ctx, "pos")
end

return match_t
end

end -- if is_http


function _M._set_ngx(mock_ngx)
if type(mock_ngx) ~= "table" then
Expand Down
Loading