aboutsummaryrefslogtreecommitdiff
path: root/lib/dns/dns.go
AgeCommit message (Collapse)Author
2026-02-02lib/dns: use separate ServeMux for handling DoHShulhan
Using the [http.DefaultServeMux] will cause panic when the server restarted automatically.
2026-02-02lib/dns: changes the request's kind field to stringShulhan
This is to minimize lookup on map each time we need the string representation.
2026-01-25lib/dns: increase the client default timeout from 6 to 60 secondsShulhan
The 6 seconds timeout will works only on fast, stable connection. On some environment with bad network connection, it will cause I/O timeout during recv and this affect the whole internet connections, like browsing. Since the browser wait for domain to be resolved but it does not get the response, it send another query. The next query also got timeout again. Increasing to 10-30 seconds also does not help on that environment. After some tests, 60 seconds is the lower timeout limit that reduce the I/O timeout. It is better that we receive the response and store it to caches, so the next query can be handled quickly, rather than timeout and retrying with the same error.
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-26lib/dns: implements RFC 9460 for SVCB RR and HTTPS RRShulhan
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.
2023-12-13all: fix linter warnings reported by reviveShulhan
There are some reports that I disagree with revive, in example, code should not declare the type after variables. In my opinion, on some cases, declaring the type make the code more readable and explicit. Since I did not want to add new configuration file, we changes it and follow revive for now.
2023-08-05lib/dns: always initialize the Zone SOA record to default valuesShulhan
Previously, if we parse, create, or remove the SOA record from zone, we assume the SOA records are valid and not touch their values. In this changes, we set the SOA fields to default values if its not set, to make the SOA record consistent and valid, in perspective of client. This changes also export the default OS values for documentation and add new method NewRDataSOA to simplify creating new SOA record.
2022-05-09all: reformat all codes using gofmt 1.19 (the Go tip)Shulhan
2022-03-03lib/dns: increase the default UDP packet size to 1232Shulhan
The value is based on recommendation by https://dnsflagday.net/2020/ to prevent IP fragmentation when supporting EDNS message.
2021-11-14lib/dns: refactoring the section headerShulhan
This changes rename the SectionHeader into MessageHeader. The pack() method is optimized with the following results, benchmark old ns/op new ns/op delta BenchmarkMessageHeader_pack-8 66.2 21.7 -67.31% benchmark old allocs new allocs delta BenchmarkMessageHeader_pack-8 3 1 -66.67% benchmark old bytes new bytes delta BenchmarkMessageHeader_pack-8 32 16 -50.00% The unpack() method is simplified by minimizing the if-condition. This changes also fix the pack and unpack OpCode for value other then 0, due to wrong shift value, 2 instead of 3.
2021-11-14lib/dns: refactoring, introduce new type RecordClassShulhan
Previously, the record class is represented by uint16 using prefix QueryClassXxx. This changes make the record class to be an independent type, to make code more strict (prevent passing invalid value), and readable.
2021-11-14lib/dns: refactoring, create type RecordType to represent type of RRShulhan
Previously, we use uint16 to represent type for ResourceRecord Type or Question type. To make the code more strict, where parameter or return value, must be expected as record type, we add new type to represent the RR type: RecordType. This changes also rename any variable name of QType or qtype to RType or rtype because QType is misleading. The type defined the ResourceRecord to be queried not only question.
2021-11-11lib/dns: use different packet between UDP and TCP messagesShulhan
Previously, all packet size for reading and sending the message is fixed to 4096, even on UDP. This changes set the UDP packet size maximum to 512 bytes and others to 4096 bytes. While at it, minimize copying packet if its not reusable inside a method.
2020-09-06dns: export function to get query type by address valueShulhan
2020-08-17dns: add method to save the master records to fileShulhan
2020-06-06all: use default linter optionsShulhan
2019-10-21all: fix and add missing commentsShulhan
2019-10-17dns: allow DoT traffic to be logged as "DoT" not "TCP"Shulhan
2019-10-17dns: implement client for DNS over TLSShulhan
There is nothing special with this implementation. Basically, its TCP connection on top of TLS.
2019-10-16dns: mention that this package support DNS over HTTP (client and server)Shulhan
2019-10-16dns: refactoring server optionsShulhan
The fields in ServerOptions is refactored to have generic name. * The IPAddress field is renamed to ListenAddress, its value is both IP address and port. * The Port field is removed, merged to ListenAddress. * The DoHPort field renamed to HTTPPort. * The DoHCertificate field is renamed to TLSCertificate. * The DoHAllowInsecure field is renamed to TLSAllowInsecure. All the fields now have ini tag so it can be filled by using ini.Unmarshal().
2019-06-14all: fix nolint formatShulhan
The valid syntax to suppress linter warnings is "//nolint:<name>" with no space between comment and "nolint" and between ":". Also, we move the placement of nolint directive to the top of statements for multiple nolint in the same scope. While at it, fix and supress some linter warnings.
2019-05-07dns: suppress linter warning on global variable "rcodeNames"Shulhan
2019-04-12dns: unexport connection typeShulhan
Since the caches and forwarding now is handled internally, and Request has been unexported, there is no need for exporting the connection type anymore.
2019-04-12dns: add mapping of response code to human readable namesShulhan
This mapping can be used to print an error message based on error code on response.
2019-04-12dns: move the ParseNameServers function to file funcsShulhan
This will make the dns.go only contains global variables and constants.
2019-03-01all: fix warnings from linterShulhan
Most of the warnings caused by update to linter which cause global variables declared with grouping "( ... )" and that has been suppressed, are become false-positive again.
2019-02-28dns: add mapping of connection types and its namesShulhan
This mapping can be used to print connection type for logging.
2019-02-23dns: print the section question type by stringShulhan
Previously, the question type is printed using the decimal value, for example 1 for question type address (A). This commit add the mapping between query types and their string representation and use it for printing query type.
2019-02-05lib/dns: prefix the query type comment with number for easy referenceShulhan
2019-01-29lib/dns: uncapitalized the first letter of error messagesShulhan
2019-01-28lib/dns: add type of connectionShulhan
This is to limit implementation to assign value of connection type to known values only.
2018-11-30all: minimize and suppress linter warnings for global variablesShulhan
2018-11-29all: fixes warning from lintersShulhan
2018-09-26lib/dns: use debug packageShulhan
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.
2018-09-25lib/dns: implement client and server for DNS over HTTPSShulhan
The implementation is based on latest draft [1]. [1] https://tools.ietf.org/html/draft-ietf-doh-dns-over-https-14
2018-09-10lib/dns: add function to parse list of name server into UDP addressesShulhan
2018-09-03lib/dns: implement parsing master files (RFC1035 section 5)Shulhan
Master files are text files that contain RRs in text form. Since the contents of a zone can be expressed in the form of a list of RRs a master file is most often used to define a zone, though it can be used to list a cache's contents.
2018-09-01[chore] Update documentationsShulhan
2018-08-30lib/dns: increase maximum UDP packet size from 1280 to 4096 to handle EDNSShulhan
2018-08-26lib/dns: use package lib/net to parse IP and portShulhan
2018-08-23lib/dns: Implement DNS server with handlerShulhan
2018-08-22lib/dns: Implement client with TCP connectionShulhan
2018-08-19lib/dns: handle SRV RR (RFC 2782)Shulhan
2018-08-18lib/dns: replace QueryType with uint16Shulhan
This will allow to detect unknown query type for further development.
2018-08-18lib/dns: increase timeout (read/write) to six secondsShulhan
2018-08-18lib/dns: increase maximum UDP packet size from 512 to 1280Shulhan
2018-08-17lib/dns: rename rdataAddrXXX to rdataIPv4XXXShulhan