Commit graph

51 commits

Author SHA1 Message Date
Nguyen Phuong An
e78d9a7893 Remove some duplicate worlds (#2582)
Signed-off-by: Nguyen Phuong An <AnNP@vn.fujitsu.com>
2019-02-20 07:12:21 -05:00
Nguyen Quang Huy
8d09cb243f Fix some typos (#2560)
* Fix some typos

Corect some words for reading more easily

* Update NOERROR response code

NOERROR is a response code so I revert the typo checking for it
2019-02-17 08:31:12 +00:00
Miek Gieben
e47d881461
pkg/replace: make it more efficient. (#2544)
* pkg/replace: make it more efficient.

Remove the map that is allocated on every write and make it more static,
but just defining a function that gets called for a label and returns
its value.

Remove the interface definition and just implement what is needed in our
case. Add benchmark test for replace as well.

Extend metadata test to test multiple values (pretty sure this didn't
work, but there wasn't a test for it, so can't be sure).

Update all callers to use it - concurrent use should be fine as we pass
everything by value.

Benchmarks in replacer:

new: BenchmarkReplacer-4   300000      4717 ns/op     240 B/op       8 allocs/op
old: BenchmarkReplacer-4   300000      4368 ns/op     384 B/op      11 allocs/op

Added benchmark function to the old code to test it.

~~~
func BenchmarkReplacer(b *testing.B) {
	w := dnstest.NewRecorder(&test.ResponseWriter{})
	r := new(dns.Msg)
	r.SetQuestion("example.org.", dns.TypeHINFO)
	r.MsgHdr.AuthenticatedData = true
	b.ResetTimer()
	b.ReportAllocs()
	repl := New(context.TODO(), r, w, "")
	for i := 0; i < b.N; i++ {
		repl.Replace("{type} {name} {size}")
	}
}
~~~

New code contains (of course a different one). The amount of ops is
more, which might be good to look at some more. For all the allocations
is seems it was quite performant.

This looks to be 50% faster, and there is less allocations in log
plugin:

old: BenchmarkLogged-4   	   20000	     70526 ns/op
new: BenchmarkLogged-4   	   30000	     57558 ns/op

Signed-off-by: Miek Gieben <miek@miek.nl>

* Stickler bot

Signed-off-by: Miek Gieben <miek@miek.nl>

* Improve test coverage

Signed-off-by: Miek Gieben <miek@miek.nl>

* typo

Signed-off-by: Miek Gieben <miek@miek.nl>

* Add test for malformed log lines

Signed-off-by: Miek Gieben <miek@miek.nl>
2019-02-12 07:38:49 +00:00
Daniel Garcia
4a3f5cc41e Use Trim(Prefix/Suffix) instead of Trim(Left/Right) in rewrite prefix plugin (#2364) (#2372) 2018-12-06 22:10:46 +00:00
Miek Gieben
fc667b98e0
Fix EDNS0 compliance (#2357)
* Fix EDNS0 compliance

Do SizeAndDo in the server (ScrubWriter) and remove all uses of this
from the plugins. Also *always* do it. This is to get into compliance
for https://dnsflagday.net/.

The pkg/edns0 now exports the EDNS0 options we understand; this is
exported to allow plugins add things there. The *rewrite* plugin used
this to add custom EDNS0 option codes that the server needs to
understand.

This also needs a new release of miekg/dns because it triggered a
race-condition that was basicly there forever.

See:
* https://github.com/miekg/dns/issues/857
* https://github.com/miekg/dns/pull/859

Running a test instance and pointing the https://ednscomp.isc.org/ednscomp
to it shows the tests are now fixed:

~~~
EDNS Compliance Tester
Checking: 'miek.nl' as at 2018-12-01T17:53:15Z

miek.nl. @147.75.204.203 (drone.coredns.io.): dns=ok edns=ok edns1=ok edns@512=ok ednsopt=ok edns1opt=ok do=ok ednsflags=ok docookie=ok edns512tcp=ok optlist=ok
miek.nl. @2604:1380:2002:a000::1 (drone.coredns.io.): dns=ok edns=ok edns1=ok edns@512=ok ednsopt=ok edns1opt=ok do=ok ednsflags=ok docookie=ok edns512tcp=ok optlist=ok

All Ok
Codes
ok - test passed.
~~~

Signed-off-by: Miek Gieben <miek@miek.nl>

Signed-off-by: Miek Gieben <miek@miek.nl>

* typos in comments

Signed-off-by: Miek Gieben <miek@miek.nl>
2018-12-06 21:18:11 +00:00
Daniel Garcia
f51c110511 Use TrimPrefix instead of TrimLeft in rewrite prefix plugin (#2364) (#2370) 2018-12-06 21:02:07 +00:00
Francois Tur
94c9aae323 plugin/log - Support for Metadata (#2251)
* - add metadata support to Log

* - adapt ctx after rebase
2018-11-13 11:20:49 -08:00
Miek Gieben
1ef0a02b46
Revert "log/forward plugins: Extend dns query logging (#2240)" (#2256)
This reverts commit 8045aa279b.
2018-10-31 21:03:46 +00:00
Dzmitry Razhanski
8045aa279b log/forward plugins: Extend dns query logging (#2240)
Automatically submitted.
2018-10-29 18:50:31 +00:00
Paul G
a9ce35ae4e
plugin/rewrite: add closing dot for suffix rewrite rule (#2070)
* add closing dot for suffix rewrite rule
* improve rule syntax checks

Resolves: #1881
2018-10-23 16:59:59 -04:00
Miek Gieben
7b078a885f
plugin/rewrite: silence these tests (#2120)
* plugin/rewrite: silence these tests

The old Unix saying: no news, is good news.

Signed-off-by: Miek Gieben <miek@miek.nl>

* Fix da tests

Signed-off-by: Miek Gieben <miek@miek.nl>
2018-09-22 15:28:13 +01:00
Chris O'Haver
2f1223c36a
Move suffix example out of EDNS0 section (#2102) 2018-09-17 16:41:38 -04:00
Paul G
38051b9089
plugin/rewrite: add handling of TTL field rewrites (#2048)
Resolves: #1981

Signed-off-by: Paul Greenberg <greenpau@outlook.com>
2018-08-29 10:41:03 -04:00
Chris O'Haver
610bdc091d
Add suffix example to docs (#2049) 2018-08-23 15:27:09 -04:00
Karsten Weiss
6d8a078704 Typo fixes (#2031) 2018-08-14 08:55:55 -07:00
Miek Gieben
f3134da45e
Clean up tests logging (#1979)
* Clean up tests logging

This cleans up the travis logs so you can see the failures better.

Older tests in tests/ would call log.SetOutput(ioutil.Discard) in
a haphazard way. This add log.Discard and put an `init` function in each
package's dir (no way to do this globally). The cleanup in tests/ is
clear.

All plugins also got this init function to have some uniformity and kill
any (future) logging there in the tests as well.

There is a one-off in pkg/healthcheck because that does log.

Signed-off-by: Miek Gieben <miek@miek.nl>

* bring back original log_test.go

Signed-off-by: Miek Gieben <miek@miek.nl>

* suppress logging here as well

Signed-off-by: Miek Gieben <miek@miek.nl>
2018-07-19 16:23:06 +01:00
Miek Gieben
d9b9a955ba plugin/rewrite: prevent illegal names (#1972)
Log and returns an error when the name rewrite creates a name that is
illegal. Add test in name_test.go to see if an error is returned.

Possible followup could be the only check this if a name-rewrite is
done.

Fixes: #1638

Signed-off-by: Miek Gieben <miek@miek.nl>
2018-07-13 09:32:07 -04:00
Miek Gieben
4083852b70 Remove trailing whitespace (#1955)
Prevent future; "remove trailing whitespace" PR, but adding a simple
presubmit that checks for this.

This presubmit flagged quite some offenders, remove all trailing
whitespace from. Apart from that there aren't any other changes.

Signed-off-by: Miek Gieben <miek@miek.nl>
2018-07-09 08:08:02 -04:00
Francois Tur
b3a92f1622 - compliance with metadata contract. If metadata value is empty, ignore rewrite - like if metadata does not exist. (#1953) 2018-07-08 17:38:46 -04:00
Francois Tur
7745462430 plugin/rewrite - extend edns0 local variable support with metadata (#1928)
* - add support of metadata values for edns0 local variables

* - comments from review.

* - simplify label check. Add UT

* - enhance check for Labels, add UT
- remove IsMetadataSet

* - edns0 variable - if variable is not found just ignore the rewrite.
2018-07-08 08:18:01 +01:00
Miek Gieben
6dd2cf8c4b plugin/rewrite: use request.Request and other cleanups (#1920)
This was done anyway, but only deep in the functions, just do this
everywhere; allows for shorter code and request.Request allows for
caching as well.

Cleanups, make it more Go like.
* remove unneeded switches
* remove testdir (why was this there??)
* simplify the logic
* remove unneeded variables
* put short functions on a single line
* fix documentation.
* spin off wire funcs in wire.go, make them functions.

Signed-off-by: Miek Gieben <miek@miek.nl>
2018-07-02 07:39:50 -07:00
Miek Gieben
99800a687c
plugin/metadata: metadata is just label=value (#1914)
This revert 17d807f0 and re-adds the metadata plugin as a plugin that
just sets a label to a value function.

Add package documentation on how to use the metadata package. Make it
clear that any caching is up to the Func implemented.

There are now - no in tree users. We could add the request metadata by
default under names that copy request.Request, i.e

request/ip - remote IP
request/port - remote port

Variables.go has been deleted.

Signed-off-by: Miek Gieben <miek@miek.nl>
2018-07-01 20:01:17 +01:00
Miek Gieben
0a43306871
plugin/rewrite: cleanup (#1916)
delete unused tests and fix import lines.

Signed-off-by: Miek Gieben <miek@miek.nl>
2018-06-30 21:55:38 +01:00
Miek Gieben
2fd31cd3e0
plugin/metadata: some cleanups (#1906)
* plugin/metadata: some cleanups

Name to provider.go as that's what being defined right now in the file.
Use request.Request because that's done in variables.go anyway. Name the
main storage M, because there is no further meaning behind.

Remove superfluous methods

Signed-off-by: Miek Gieben <miek@miek.nl>

* Fix test

Signed-off-by: Miek Gieben <miek@miek.nl>
2018-06-29 15:03:25 +01:00
Eugen Kleiner
17d807f05f plugin/metadata: add metadata plugin (#1894)
* plugin/metadata: add metadata plugin

* plugin/metadata: Add MD struct, refactor code, fix doc

* plugin/metadata: simplify metadata key

* plugin/metadata: improve setup_test

* Support of metadata by rewrite plugin. Move calculated variables to metadata.

* Move variables from metadata to pkg, add UTs, READMEs change, metadata small fixes

* Add client port validation to variables_test

* plugin/metadata: improve README

* plugin/metadata: rename methods

* plugin/metadata: Update Metadataer interface, update doc, cosmetic code changes

* plugin/metadata: move colllisions check to OnStartup(). Fix default variables metadataer.

* plugin/metadata: Fix comment for method setValue

* plugin/metadata: change variables order to fix linter warning

* plugin/metadata: rename Metadataer to Provider
2018-06-29 10:44:16 +01:00
Francois Tur
6fbc1f8990 Plugin/Rewrite - review documentation of "append" (#1877)
* - ensure description of 'append' match what is encoded.

* - fix description based on review comments
2018-06-18 10:02:05 +01:00
Miek Gieben
c0fbef0714
generate doc for 1.1.3 (#1832) 2018-05-24 07:51:59 +01:00
Chris O'Haver
2c04e72bdc
Try to clarify rewrite docs (#1795)
making response rewrites more prominent
2018-05-11 13:50:59 -04:00
Chris O'Haver
47b2b10209 plugin/rewrite: handle continue in response rewrite (#1740)
* handle continue in response rewrite

* add test
2018-04-27 07:05:44 +01:00
Chris O'Haver
5e06687ee5 plugin/rewrite: tweak parse error messaging, add tests (#1737)
* tweak parse error messaging, add tests

* looser err msg checking
2018-04-25 20:48:32 +01:00
Miek Gieben
0930eb8beb
all: fix plugin import ordering (#1717)
Got a bit messed up with stb lib "context" usage.
2018-04-22 08:34:35 +01:00
Miek Gieben
8722336fff
global: move to context (#1699)
* global: move to context

Move from golang.org/x/net/context to std lib's context.

Change done with:

for i in $(grep -l '/context' **/*.go); do sed -e 's|golang.org/x/net/context|context|' -i $i; echo $i; done
for i in **/*.go; do goimports -w $i; done

* drop from dns.pb.go as well
2018-04-20 11:01:06 +01:00
Sandeep Rajan
a0834b1dd5 check DO bit is maintaining status (#1526) 2018-02-14 20:18:02 +01:00
Yong Tang
4e63d0be35 Enable goimports check, and fixes several imports format (#1525)
This fix enables goimports check and fixes several imports format
so that the import sections are prettier, e.g.:
```
 import (
-       "github.com/miekg/dns"
        "regexp"
        "strconv"
        "strings"
+
+       "github.com/miekg/dns"
 )
```

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
2018-02-14 10:00:04 -05:00
Miek Gieben
fd7abd9849
Add OWNERS file (#1486)
This should have everyone, but the process was quite manual. The rename
from middleware -> plugin also meant I had to do some extra digging on
who actually submitted the PR. I also double checked the current list of
people with commit access.

Every plugin now has an OWNERS, except *reverse*. I'll file a bug for
that.
2018-02-08 10:55:51 +00:00
Sandeep Rajan
a4e0f6452d plugin/rewrite: remove do set in edns0 (#1500)
* remove setdo

* gofmt
2018-02-07 13:53:23 -05:00
Paul Greenberg
f636930c5c plugin/rewrite: rewrite responses for all record types (#1460) (#1463) 2018-02-06 18:40:46 +00:00
Paul Greenberg
7d371edb2d plugin/rewrite: add response rewrite docs (#1414) 2018-01-22 22:01:13 -05:00
Paul Greenberg
258c163bb0 feature: plugin/rewrite: rewrite ANSWER SECTION (#1318)
Resolves: #1313
2018-01-18 10:41:14 -05:00
Miek Gieben
58221f55db
Manual pages (#1346)
* Add manual pages

Generate manual pages from the README and extend README with Name and
Description sections.

The generation requires 'ronn' which may not be available. Just check in
all generated manual pages.
2018-01-04 12:53:07 +00:00
Paul Greenberg
3125381f2d plugin/rewrite: fix flow control logic for all rule types (#1308)
Resolves: #1307
2017-12-14 13:25:36 -05:00
Paul Greenberg
d35f2c73ec plugin/rewrite: regular expression and substring match/replace (#1296) (#1297) 2017-12-13 11:31:19 -05:00
Miek Gieben
e9699c42b7
plugin/rewrite: don't set or use ecs.DraftOption (#1262)
* plugin/rewrite: don't set or use ecs.DraftOption

Don't know why we are accessing this and explicitally setting it to
False (the default).
Any kill with fire - makes the build, build again.

* remove this
2017-11-28 14:03:20 +00:00
Miek Gieben
42504332ae plugin/rewrite: lowercase error
super small cleanup; smaller case return errors.
2017-11-13 16:08:06 +00:00
Miek Gieben
0186aadfcf
fuzz: put fuzzing stuff in own build tag (#1215)
No need to have this build all the time.
2017-11-10 13:59:42 +00:00
Miek Gieben
427aed6f5b doc update (#1140)
* doc update

Go through all README and fix mistakes, extend example and let more
corefile snippets be test for validity.

* Cant use spefic addr in test
2017-10-10 09:39:35 +02:00
Miek Gieben
4276d29b81 Add fuzzing infrastructure (#1118)
Fix file/fuzz.go build and docs in Makefile.fuzz
Each plugin can add a fuzz.go to join the fuzzing craze.
pkg/fuzz/do.go could be made a lot smarter, but is probably good enough
for starters.

$ make -f Makefile.fuzz <plugin>

will build with go-fuzz-build and then execute a go-fuzz run. Each
plugin's fuzz run uses a per-plugin directory to store the fuzz data.
2017-09-29 22:28:13 +01:00
Yong Tang
387ceb480b go lint/vet/misspell cleanup (#1105)
This fix address several issues related to golint/vet/misspell.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
2017-09-22 16:13:04 -07:00
Miek Gieben
284061eee7 pkg: add dnstest (#1098)
Add a full test server impl in this new package + tests. Move
dnsrecorder into this package as well and finish up the commented out
tests that were left in the old dnsrecorder package.

Update all callers and tests.
2017-09-21 15:15:47 +01:00
Thong Huynh
ec21f83425 Modify the rewrite plugin to write multiple EDNS0 options (#936) (#1096)
* Add processing mode

* Add processing mode

* Update UTs

* Update README.md

* Change to use the constant Stop

* Fix README per review comments
2017-09-20 16:06:53 -04:00