fix: allow addr:port format in stream_proxy (#3900)

Signed-off-by: spacewander <spacewanderlzx@gmail.com>
This commit is contained in:
罗泽轩 2021-03-25 09:07:05 +08:00 committed by GitHub
parent 472ea3f1db
commit baf8434034
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 48 additions and 10 deletions

View File

@ -92,11 +92,11 @@ stream {
}
server {
{% for _, port in ipairs(stream_proxy.tcp or {}) do %}
listen {*port*} {% if enable_reuseport then %} reuseport {% end %} {% if proxy_protocol and proxy_protocol.enable_tcp_pp then %} proxy_protocol {% end %};
{% for _, addr in ipairs(stream_proxy.tcp or {}) do %}
listen {*addr*} {% if enable_reuseport then %} reuseport {% end %} {% if proxy_protocol and proxy_protocol.enable_tcp_pp then %} proxy_protocol {% end %};
{% end %}
{% for _, port in ipairs(stream_proxy.udp or {}) do %}
listen {*port*} udp {% if enable_reuseport then %} reuseport {% end %};
{% for _, addr in ipairs(stream_proxy.udp or {}) do %}
listen {*addr*} udp {% if enable_reuseport then %} reuseport {% end %};
{% end %}
{% if proxy_protocol and proxy_protocol.enable_tcp_pp_to_upstream then %}

View File

@ -183,15 +183,31 @@ local config_schema = {
type = "array",
minItems = 1,
items = {
type = "integer",
}
anyOf = {
{
type = "integer",
},
{
type = "string",
},
},
},
uniqueItems = true,
},
udp = {
type = "array",
minItems = 1,
items = {
type = "integer",
}
anyOf = {
{
type = "integer",
},
{
type = "string",
},
},
},
uniqueItems = true,
},
}
},

View File

@ -101,10 +101,10 @@ apisix:
# stream_proxy: # TCP/UDP proxy
# tcp: # TCP proxy port list
# - 9100
# - 9101
# - "127.0.0.1:9101"
# udp: # UDP proxy port list
# - 9200
# - 9211
# - "127.0.0.1:9201"
# dns_resolver: # If not set, read from `/etc/resolv.conf`
# - 1.1.1.1
# - 8.8.8.8

View File

@ -45,5 +45,27 @@ if echo "$out" | grep 'no such file'; then
echo "failed: find the certificate correctly"
exit 1
fi
make stop
echo "passed: find the certificate correctly"
echo '
apisix:
node_listen: 9080
enable_admin: true
port_admin: 9180
stream_proxy:
tcp:
- "localhost:9100"
udp:
- "127.0.0.1:9101"
' > conf/config.yaml
out=$(make run 2>&1 || echo "ouch")
if echo "$out" | grep 'ouch'; then
echo "failed: allow configurating address in stream_proxy"
exit 1
fi
make stop
echo "passed: allow configurating address in stream_proxy"