Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
C
Coredns
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Railgun
Coredns
Commits
b813706b
Commit
b813706b
authored
Mar 15, 2018
by
Miek Gieben
Committed by
GitHub
Mar 15, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
request: add match function (#1615)
parent
3e6489ef
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
0 deletions
+38
-0
request/request.go
request/request.go
+18
-0
request/request_test.go
request/request_test.go
+20
-0
No files found.
request/request.go
View file @
b813706b
...
...
@@ -361,6 +361,24 @@ func (r *Request) Clear() {
r
.
name
=
""
}
// Match checks if the reply matches the qname and qtype from the request, it returns
// false when they don't match.
func
(
r
*
Request
)
Match
(
reply
*
dns
.
Msg
)
bool
{
if
len
(
reply
.
Question
)
!=
1
{
return
false
}
if
strings
.
ToLower
(
reply
.
Question
[
0
]
.
Name
)
!=
r
.
Name
()
{
return
false
}
if
reply
.
Question
[
0
]
.
Qtype
!=
r
.
QType
()
{
return
false
}
return
true
}
const
(
// TODO(miek): make this less awkward.
doTrue
=
1
...
...
request/request_test.go
View file @
b813706b
...
...
@@ -109,6 +109,26 @@ func TestRequestScrubExtra(t *testing.T) {
}
}
func
TestRequestMatch
(
t
*
testing
.
T
)
{
st
:=
testRequest
()
reply
:=
new
(
dns
.
Msg
)
reply
.
SetQuestion
(
"example.com."
,
dns
.
TypeMX
)
if
b
:=
st
.
Match
(
reply
);
b
{
t
.
Errorf
(
"failed to match %s %d, got %t, expected %t"
,
"example.com."
,
dns
.
TypeMX
,
b
,
false
)
}
reply
.
SetQuestion
(
"example.com."
,
dns
.
TypeA
)
if
b
:=
st
.
Match
(
reply
);
!
b
{
t
.
Errorf
(
"failed to match %s %d, got %t, expected %t"
,
"example.com."
,
dns
.
TypeA
,
b
,
true
)
}
reply
.
SetQuestion
(
"example.org."
,
dns
.
TypeA
)
if
b
:=
st
.
Match
(
reply
);
b
{
t
.
Errorf
(
"failed to match %s %d, got %t, expected %t"
,
"example.org."
,
dns
.
TypeA
,
b
,
false
)
}
}
func
BenchmarkRequestDo
(
b
*
testing
.
B
)
{
st
:=
testRequest
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment