Skip to content
This repository was archived by the owner on Jun 20, 2024. It is now read-only.

Refactor dns server to pass configurables to handlers in a struct. #1334

Closed
wants to merge 1 commit into from

Conversation

tomwilkie
Copy link
Contributor

Also ignore EDNS on tcp requests. Fixes #1332

@@ -286,9 +289,16 @@ func truncateResponse(response *dns.Msg, maxSize int) {
response.Truncated = true
}

func getMaxResponseSize(req *dns.Msg, defaultMaxResponseSize int) int {
func (h *handler) responseTooBig(request, response *dns.Msg) bool {
if len(response.Answer) <= 1 || h.maxResponseSize <= 0 {

This comment was marked as abuse.

@rade
Copy link
Member

rade commented Aug 20, 2015

I changed the mux to an embedded struct, so the handler is now a ServeMux. What do you think?

It's not what I would have done. Handlers don't need to know about the ServeMux. Let alone do they need to be be a ServeMux. It's unnecessary coupling.

@rade
Copy link
Member

rade commented Aug 20, 2015

i.e.

func (d *DNSServer) addHandlers(mux *dns.ServeMux, client *dns.Client, defaultMaxResponseSize int) {
    h := &handler{
        DNSServer:       d,
        maxResponseSize: defaultMaxResponseSize,
        client:          client,
    }
    mux.HandleFunc(d.domain, h.handleLocal)
    mux.HandleFunc(reverseDNSdomain, h.handleReverse)
    mux.HandleFunc(topDomain, h.handleRecursive)
}

and

mux := dns.NewServeMux()
d.addHandlers(mux, d.udpClient, minUDPSize)
udpServer := &dns.Server{PacketConn: udpListener, Handler: mux}

@rade
Copy link
Member

rade commented Aug 20, 2015

or

udpServer := &dns.Server{PacketConn: udpListener, Handler: dns.NewServeMux()}
d.addHandlers(udpServer.Handler, d.udpClient, minUDPSize)

assert_raises "exec_on $HOST1 c0 dig MX $NAME | grep -q 'status: NXDOMAIN'"

check() {
M=$(exec_on $HOST1 c0 dig +short $@ $NAME A | grep -v ';;' | wc -l)
assert_raises "test $M -eq $N"

This comment was marked as abuse.

@rade rade removed the in progress label Aug 20, 2015
return false
}
return response.Len() > h.getMaxResponseSize(request)
}

This comment was marked as abuse.

Also ignore EDNS on tcp requests. Fixes #1332

Also fixes the case where recursive dns entries would be considered
too big and compressed when using TCP.
@rade rade force-pushed the 1332-big-dns-response branch from 6824487 to 52d88a1 Compare August 20, 2015 16:49
@rade rade self-assigned this Aug 20, 2015
@rade rade mentioned this pull request Aug 20, 2015
@tomwilkie
Copy link
Contributor Author

Superseded #1344

@tomwilkie tomwilkie closed this Aug 21, 2015
@rade rade deleted the 1332-big-dns-response branch August 21, 2015 13:03
@rade rade modified the milestone: 1.1.0 Aug 29, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants