aboutsummaryrefslogtreecommitdiff
path: root/lib/dns/server_options.go
AgeCommit message (Collapse)Author
2026-03-26lib/dns: refactoring DoT and DoH to use address instead of portShulhan
Using port makes the IP address of DoT and DoH listen on the same address with UDP. If we set ListenAddress to 0.0.0.0 and TLS termination is handled by proxy, this cause DoT and DoH will also listen on all addresses.
2026-02-02lib/dns: remove DebugLevelDNSShulhan
The DebugLevelDNS log the error on DNS level, for example empty answer, error on name, class not implemented, refused; which is now on by default.
2026-02-02lib/dns: add option to set hook on server when receiving answerShulhan
The hook function, OnAnswerReceived, will be triggered when server receive valid answer but before its put to caches.
2026-01-15all: convert license and copyright to use SPDX identifiersShulhan
With help of spdxconv tool [1], we able to bulk update all files license and copyright format to comply with SPDX formats. [1] https://kilabit.info/project/spdxconv/
2024-03-05all: comply with linter recommendations #2Shulhan
HTTP request now implicitly create request with context. Any false positive related to not closing HTTP response body has been annotated with "nolint:bodyclose". In the example code, use consistent "// Output:" comment format, by prefixing with single space. Any comment on code now also prefixing with single space. An error returned without variables now use [errors.New] instead of [fmt.Errorf]. Any error returned using [fmt.Errorf] now wrapped using "%w" instead of "%s". Also, replace error checking using [errors.Is] or [errors.As], instead of using equal/not-equal operator. Any statement like "x = x OP y" now replaced with "x OP= y". Also, swap statement is simplified using "x, y = y, x". Any switch statement with single case now replaced with if-condition. Any call to defer on function or program that call [os.Exit], now replaced by calling the deferred function directly. Any if-else condition now replaced with switch statement, if possible.
2024-03-02all: move the repository to "git.sr.ht/~shulhan/pakakeh.go"Shulhan
There are several reasons that why we move from github.com. First, related to the name of package. We accidentally name the package with "share" a common word in English that does not reflect the content of repository. By moving to other repository, we can rename it to better and unique name, in this "pakakeh.go". Pakakeh is Minang word for tools, and ".go" suffix indicate that the repository related to Go programming language. Second, supporting open source. The new repository is hosted under sourcehut.org, the founder is known to support open source, and all their services are licensed under AGPL, unlike GitHub that are closed sources. Third, regarding GitHub CoPilot. The GitHub Terms of Service [1], allow any public content that are hosted there granted them to parse the content. On one side, GitHub helps and flourish the open source, but on another side have an issues regarding scraping the copyleft license [2]. [1]: https://docs.github.com/en/site-policy/github-terms/github-terms-of-service#4-license-grant-to-us [2]: https://githubcopilotinvestigation.com
2024-02-04lib/dns: change the log mechanism by mode instead of by levelShulhan
This changes introduce three mode of debug: - DebugLevelDNS: log error on DNS level, in example empty answer, ERR_NAME (domain name is invalid or not known) and so on. - DebugLevelCache: log cache operations. - DebugLevelConnPacket: log low level connection and package, including request and response.
2023-05-20lib/dns: add option to set debug level in ServerOptionsShulhan
This options replace the global debug package.
2022-08-03lib/dns: add field SOA to the ServerOptionsShulhan
The SOA field defined the root authority for all zones and records served under the Server.
2022-05-12all: rewrite all codes to use "var" instead of ":="Shulhan
Using ":=" simplify the code but we lose the type. For example, v := F() The only way we know what the type of v is by inspecting the function F. Another disadvantages of using ":=" may cause extra variables allocation where two or more variables with same type is declared inside body of function where it could be only one. While at it, we split the struct for test case into separate type.
2022-05-09all: reformat all codes using gofmt 1.19 (the Go tip)Shulhan
2021-11-15lib/dns: realign all struct fieldsShulhan
Using the fieldalignment, we got the following output, answer.go:15:13: struct with 56 pointer bytes could be 24 = 32 bytes caches.go:27:13: struct with 24 pointer bytes could be 16 = 8 dot_client.go:20:16: struct with 16 pointer bytes could be 8 = 8 hosts_file.go:24:16: struct with 64 pointer bytes could be 48 = 16 message.go:53:14: struct of size 176 could be 168 = 8 rdata_mx.go:20:14: struct with 16 pointer bytes could be 8 = 8 rdata_opt.go:18:15: struct with 16 pointer bytes could be 8 = 8 rdata_srv.go:16:15: struct with 64 pointer bytes could be 56 = 8 rdata_wks.go:30:15: struct with 40 pointer bytes could be 32 = 8 request.go:20:14: struct with 32 pointer bytes could be 24 = 8 resource_record.go:24:21: struct with 56 pointer bytes could be 40 = 16 server.go:76:13: struct with 120 pointer bytes could be 112 = 8 server_options.go:20:20: struct of size 240 could be 224 = 16 tcp_client.go:21:16: struct with 40 pointer bytes could be 24 = 16 udp_client.go:24:16: struct with 24 pointer bytes could be 16 = 8 udp_client_pool.go:25:20: struct with 24 pointer bytes could be 16 = 8 zone_file.go:22:15: struct with 128 pointer bytes could be 120 = 8 zone_parser.go:53:17: struct with 88 pointer bytes could be 72 = 16 Turns out the struct that we frequently used, answer and resource_record, is not optimized. This changes reorder all structs field to save space in memory.
2021-11-13lib/dns: make the TCP forwarders as complementary of UDPShulhan
The TCP forwarders only active when client send the DNS request as TCP. When the server receive that request it should also forward the request as TCP not as UDP to prevent the truncated response. Another use case for TCP is when the response is truncated, the client will send the query back through TCP connection. The server should forward this request using TCP instead of UDP.
2021-11-13lib/dns: remove the fallback name servers (NS) from server optionsShulhan
The original idea of fallback NS is to send the query to the one define to original resolv.conf, instead of using the one defined by user in ServerOptions NameServers, when an error occured. But, most of error usually caused by network (disconnected, time out), so re-sending query to fallback NS does not have any effect if the network it self is not working. This changes remove the unnecessary and complex fallback NS from server.
2021-11-13lib/dns: use snake case for file namingShulhan
Using snake case make the file naming more readable.
2019-04-12dns: rename "server_options" to "serveroptions"Shulhan
Just name consistency with the type that its hold, ServerOptions (no underscore). Beside, we should use underscore on file for example and test files only.
2019-01-29lib/dns: uncapitalized the first letter of error messagesShulhan
2018-11-30all: realigned some struct to minimize the size on memoryShulhan
2018-11-29all: fix warning from lintersShulhan
2018-09-27lib/dns: add field Kind to requestShulhan
The kind value indicate from which connection the request is coming from. If Kind is UDP, Sender and UDPAddr must be non nil. If Kind is TCP, Sender must be non nil If Kind is DoH, both Sender and UDPAddr must be nil and ResponseWriter and ChanResponded must be non nil and initialized.
2018-09-25lib/dns: add type server options to configure serverShulhan
Since we have three mode for server now (UDP, TCP, DoH), more parameters were added to ListenAndServe. To simplify this we use server options with struct that can be passed directly to ListenAndServer.