Skip to content
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

Ednsopt #91

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Ednsopt #91

wants to merge 2 commits into from

Conversation

klyr
Copy link

@klyr klyr commented Jul 20, 2020

Add a new --ednsopt option to add arbitrary EDNS options.

@codecov-commenter
Copy link

codecov-commenter commented Jul 20, 2020

Codecov Report

Merging #91 into master will decrease coverage by 0.65%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #91      +/-   ##
==========================================
- Coverage   71.20%   70.54%   -0.66%     
==========================================
  Files          30       30              
  Lines        2035     2054      +19     
==========================================
  Hits         1449     1449              
- Misses        415      433      +18     
- Partials      171      172       +1     
Impacted Files Coverage Δ
proxy/config.go 41.66% <ø> (ø)
proxy/proxy.go 60.97% <0.00%> (-7.99%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7b79d1c...6b435f3. Read the comment docs.

To add a new edns option with code 4242:

$ echo -n "This is a binary string" | base64
VGhpcyBpcyBhIGJpbmFyeSBzdHJpbmc=

./dnsproxy -u 1.1.1.1 --ednsopt "4242:VGhpcyBpcyBhIGJpbmFyeSBzdHJpbmc="
Copy link
Member

@ameshkov ameshkov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@klyr first of all, thank you for the contribution! This feature does make sense to me.

Could you please add a unit-test for this?

I'd suggest this as a setup:

  1. Add a "fake" upstream (Upstream implementation that records request and responds immediately with anything)
  2. Create a proxy with EDNSOpt configured
  3. Call Resolve method
  4. Check that EDNS was received by the fake upstream

@@ -218,6 +224,27 @@ func createProxyConfig(options Options) proxy.Config {
}
}

if len(options.EDNSOpt) > 0 {
config.EDNSOpts = make(map[uint16][]byte)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please move this code to a separate function and also add a unit-test for it?


// Set EDNSOpts
func (p *Proxy) processEDNSOpts(d *DNSContext) {
var o (*dns.OPT) = nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var o *dns.OPT is a better looking variant

kv := strings.Split(s, ":")
if len(kv) != 2 {
log.Fatalf("parse error for '%s', --ednsopt must be of the form: option-code:base64encodeddata (ex: --ednsopt 8:SGVsbG8gd29ybGQK)", s)
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

else branch is not needed here, just put the code below without it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants