-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: patch tcp.sock.connect to use our DNS resolver
Fix #3719 Signed-off-by: spacewander <spacewanderlzx@gmail.com>
- Loading branch information
1 parent
0a86700
commit 22ef698
Showing
8 changed files
with
125 additions
and
34 deletions.
There are no files selected for viewing
This file contains 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 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,51 @@ | ||
-- | ||
-- Licensed to the Apache Software Foundation (ASF) under one or more | ||
-- contributor license agreements. See the NOTICE file distributed with | ||
-- this work for additional information regarding copyright ownership. | ||
-- The ASF licenses this file to You under the Apache License, Version 2.0 | ||
-- (the "License"); you may not use this file except in compliance with | ||
-- the License. You may obtain a copy of the License at | ||
-- | ||
-- http://www.apache.org/licenses/LICENSE-2.0 | ||
-- | ||
-- Unless required by applicable law or agreed to in writing, software | ||
-- distributed under the License is distributed on an "AS IS" BASIS, | ||
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
-- See the License for the specific language governing permissions and | ||
-- limitations under the License. | ||
-- | ||
local json = require("apisix.core.json") | ||
local log = require("apisix.core.log") | ||
local utils = require("apisix.core.utils") | ||
|
||
|
||
local _M = {} | ||
|
||
|
||
function _M.init_resolver(args) | ||
local dns_resolver = args and args["dns_resolver"] | ||
utils.set_resolver(dns_resolver) | ||
log.info("dns resolver", json.delay_encode(dns_resolver, true)) | ||
end | ||
|
||
|
||
function _M.parse_domain(host) | ||
local ip_info, err = utils.dns_parse(host) | ||
if not ip_info then | ||
log.error("failed to parse domain: ", host, ", error: ",err) | ||
return nil, err | ||
end | ||
|
||
log.info("parse addr: ", json.delay_encode(ip_info)) | ||
log.info("resolver: ", json.delay_encode(utils.get_resolver())) | ||
log.info("host: ", host) | ||
if ip_info.address then | ||
log.info("dns resolver domain: ", host, " to ", ip_info.address) | ||
return ip_info.address | ||
end | ||
|
||
return nil, "failed to parse domain" | ||
end | ||
|
||
|
||
return _M |
This file contains 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 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 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 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 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 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