-
Notifications
You must be signed in to change notification settings - Fork 257
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pull request 332: AGDNS-1982 Improve code vol.2
Squashed commit of the following: commit 7ee49cd Merge: c9e3f2c feea26e Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 28 13:50:57 2024 +0300 Merge branch 'master' into imp-code-vol.2 commit c9e3f2c Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Wed Mar 27 13:13:01 2024 +0300 proxy: imp code, docs commit 1ecf288 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Mar 25 16:06:08 2024 +0300 proxy: add recursion detector, imp code commit e4f41d4 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Mar 25 13:45:17 2024 +0300 proxy: imp code
- Loading branch information
1 parent
feea26e
commit 076a1de
Showing
9 changed files
with
428 additions
and
172 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package proxy | ||
|
||
import "github.com/miekg/dns" | ||
|
||
// MessageConstructor creates DNS messages. | ||
type MessageConstructor interface { | ||
// NewMsgNXDOMAIN creates a new response message replying to req with the | ||
// NXDOMAIN code. | ||
NewMsgNXDOMAIN(req *dns.Msg) (resp *dns.Msg) | ||
|
||
// NewMsgSERVFAIL creates a new response message replying to req with the | ||
// SERVFAIL code. | ||
NewMsgSERVFAIL(req *dns.Msg) (resp *dns.Msg) | ||
|
||
// NewMsgNOTIMPLEMENTED creates a new response message replying to req with | ||
// the NOTIMPLEMENTED code. | ||
NewMsgNOTIMPLEMENTED(req *dns.Msg) (resp *dns.Msg) | ||
} | ||
|
||
// defaultMessageConstructor is a default implementation of MessageConstructor. | ||
type defaultMessageConstructor struct{} | ||
|
||
// type check | ||
var _ MessageConstructor = defaultMessageConstructor{} | ||
|
||
// NewMsgNXDOMAIN implements the [MessageConstructor] interface for | ||
// defaultMessageConstructor. | ||
func (defaultMessageConstructor) NewMsgNXDOMAIN(req *dns.Msg) (resp *dns.Msg) { | ||
return reply(req, dns.RcodeNameError) | ||
} | ||
|
||
// NewMsgSERVFAIL implements the [MessageConstructor] interface for | ||
// defaultMessageConstructor. | ||
func (defaultMessageConstructor) NewMsgSERVFAIL(req *dns.Msg) (resp *dns.Msg) { | ||
return reply(req, dns.RcodeServerFailure) | ||
} | ||
|
||
// NewMsgNOTIMPLEMENTED implements the [MessageConstructor] interface for | ||
// defaultMessageConstructor. | ||
func (defaultMessageConstructor) NewMsgNOTIMPLEMENTED(req *dns.Msg) (resp *dns.Msg) { | ||
resp = reply(req, dns.RcodeNotImplemented) | ||
|
||
// Most of the Internet and especially the inner core has an MTU of at least | ||
// 1500 octets. Maximum DNS/UDP payload size for IPv6 on MTU 1500 ethernet | ||
// is 1452 (1500 minus 40 (IPv6 header size) minus 8 (UDP header size)). | ||
// | ||
// See appendix A of https://datatracker.ietf.org/doc/draft-ietf-dnsop-avoid-fragmentation/17. | ||
const maxUDPPayload = 1452 | ||
|
||
// NOTIMPLEMENTED without EDNS is treated as 'we don't support EDNS', so | ||
// explicitly set it. | ||
resp.SetEdns0(maxUDPPayload, false) | ||
|
||
return resp | ||
} | ||
|
||
// reply creates a new response message replying to req with the given code. | ||
func reply(req *dns.Msg, code int) (resp *dns.Msg) { | ||
resp = (&dns.Msg{}).SetRcode(req, code) | ||
resp.RecursionAvailable = true | ||
|
||
return resp | ||
} |
This file contains 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
Oops, something went wrong.