-
Notifications
You must be signed in to change notification settings - Fork 109
add NAPTR record support #17
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
Open
sergey-lukin
wants to merge
1
commit into
openresty:master
Choose a base branch
from
sergey-lukin:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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 |
|---|---|---|
|
|
@@ -46,6 +46,7 @@ local TYPE_MX = 15 | |
| local TYPE_TXT = 16 | ||
| local TYPE_AAAA = 28 | ||
| local TYPE_SRV = 33 | ||
| local TYPE_NAPTR = 35 | ||
| local TYPE_SPF = 99 | ||
|
|
||
| local CLASS_IN = 1 | ||
|
|
@@ -65,6 +66,7 @@ local _M = { | |
| TYPE_TXT = TYPE_TXT, | ||
| TYPE_AAAA = TYPE_AAAA, | ||
| TYPE_SRV = TYPE_SRV, | ||
| TYPE_NAPTR = TYPE_NAPTR, | ||
| TYPE_SPF = TYPE_SPF, | ||
| CLASS_IN = CLASS_IN, | ||
| SECTION_AN = SECTION_AN, | ||
|
|
@@ -208,6 +210,21 @@ local function _encode_name(s) | |
| end | ||
|
|
||
|
|
||
| local function _decode_string(buf, pos) | ||
| local slen = byte(buf, pos) | ||
|
|
||
| if slen == 0 then | ||
| return "", pos + 1 | ||
| end | ||
|
|
||
| if pos + 1 + slen > #buf then | ||
| return nil, 'truncated' | ||
| end | ||
|
|
||
| return sub(buf, pos + 1, pos + slen), pos + slen + 1 | ||
| end | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto. |
||
|
|
||
| local function _decode_name(buf, pos) | ||
| local labels = {} | ||
| local nptrs = 0 | ||
|
|
@@ -481,6 +498,50 @@ local function parse_section(answers, section, buf, start_pos, size, | |
|
|
||
| pos = p | ||
|
|
||
| elseif typ == TYPE_NAPTR then | ||
| if len < 7 then | ||
| return nil, "bad NAPTR record value length: " .. len | ||
| end | ||
|
|
||
| local order_hi = byte(buf, pos) | ||
| local order_lo = byte(buf, pos + 1) | ||
| ans.order = lshift(order_hi, 8) + order_lo | ||
|
|
||
| local preference_hi = byte(buf, pos + 2) | ||
| local preference_lo = byte(buf, pos + 3) | ||
| ans.preference = lshift(preference_hi, 8) + preference_lo | ||
|
|
||
| local flags_str, p = _decode_string(buf, pos + 4) | ||
| if not flags_str then | ||
| return nil, pos | ||
| end | ||
| ans.flags = flags_str | ||
|
|
||
| local services_str, p = _decode_string(buf, p) | ||
| if not services_str then | ||
| return nil, pos | ||
| end | ||
| ans.services = services_str | ||
|
|
||
| local regexp_str, p = _decode_string(buf, p) | ||
| if not regexp_str then | ||
| return nil, pos | ||
| end | ||
| ans.regexp = regexp_str | ||
|
|
||
| local replacements_str,p = _decode_name(buf, p) | ||
| if not replacements_str then | ||
| return nil, pos | ||
| end | ||
| ans.replacements = replacements_str | ||
|
|
||
| if p - pos ~= len then | ||
| return nil, format("bad NAPTR record length: %d ~= %d", | ||
| p - pos, len) | ||
| end | ||
|
|
||
| pos = p | ||
|
|
||
| elseif typ == TYPE_NS then | ||
|
|
||
| local name, p = _decode_name(buf, pos) | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -1721,3 +1721,54 @@ GET /t | |
| records: [{"address":"127.0.0.1","section":1,"type":1,"class":1,"name":"www.google.com","ttl":123456}] | ||
| --- no_error_log | ||
| [error] | ||
|
|
||
|
|
||
| === TEST 35: NAPTR | ||
| --- http_config eval: $::HttpConfig | ||
| --- config | ||
| location /t { | ||
| content_by_lua ' | ||
| local resolver = require "resty.dns.resolver" | ||
|
|
||
| local r, err = resolver:new{ | ||
| nameservers = { {"127.0.0.1", 1953} } | ||
| } | ||
| if not r then | ||
| ngx.say("failed to instantiate resolver: ", err) | ||
| return | ||
| end | ||
|
|
||
| r._id = 125 | ||
|
|
||
| local ans, err = r:query("5.4.3.2.1.e164.arpa", { qtype = r.TYPE_NAPTR }) | ||
| if not ans then | ||
| ngx.say("failed to query: ", err) | ||
| return | ||
| end | ||
|
|
||
| local cjson = require "cjson" | ||
| ngx.say("records: ", cjson.encode(ans)) | ||
| '; | ||
| } | ||
| --- udp_listen: 1953 | ||
| --- udp_reply dns | ||
| { | ||
| id => 125, | ||
| opcode => 0, | ||
| qtype => 35, # NAPTR | ||
| qname => '5.4.3.2.1.e164.arpa', | ||
| answer => [ | ||
| { name => "5.4.3.2.1.e164.arpa", ttl => 2, order => 10, preference => 100, | ||
| flags => "u", | ||
| services => "E2U+sip", | ||
| regexp => "!^\\+123456(.*)\$!sip:\\1\@example.org!", | ||
| replacements => "" | ||
| } | ||
| ], | ||
| } | ||
| --- request | ||
| GET /t | ||
| --- response_body | ||
| records: [{"order":10,"preference":100,"class":1,"regexp":"!^\\+123456(.*)$!sip:\\[email protected]!","replacements":"","section":1,"flags":"u","type":35,"ttl":2,"name":"5.4.3.2.1.e164.arpa","services":"E2U+sip"}] | ||
| --- no_error_log | ||
| [error] | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style: we need 2 blank lines to separate function definitions.