aboutsummaryrefslogtreecommitdiff
path: root/lib/dns
AgeCommit message (Collapse)Author
10 daysall: apply go fixShulhan
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 unnessary log prefix on forwarderShulhan
The "tag" prefix already indicate the forwarder type.
2026-02-02lib/dns: minimize use of appendShulhan
In handleDoHRequest, we did not need to call append, just copy it as is. In DoTClient and TCPClient, since we already do make, use direct copy instead of another append.
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: skip caching empty answer only for query type AShulhan
Previously, we did not store response with empty RR answer for all record types. Meanwhile, some domains still does not have AAAA(28) and HTTPS(65) records set, but browser will requesting them. So, to minimize traffic for those query we skip caching only for query type A and cache the rest of types.
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: changes the request's kind field to stringShulhan
This is to minimize lookup on map each time we need the string representation.
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-26lib/dns: add method to set TTL on MessageShulhan
The SetTTL method set all RRs answer time to live.
2026-01-26lib/dns: print the answer TTL in DebugLevelCacheShulhan
The log level cache changed to the following format, ... {MSG_ID QNAME TYPE TTL} ... where MSG_ID is the message ID, QNAME is the question name, TYPE is the type of question, and TTL is the time-to-live of the answer. This changes require adding field TTL to Answer and exporting the field Message.
2026-01-26lib/dns: simplify log message for DebugLevelCacheShulhan
For each logged request, there should be one line of response logged, success or fail. This changes remove redundant log "^" (request forwarded) and "~" (answer is expired). The final log would be only "+" (new answer cached), or "#" (answer updated), or "!" (error).
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/
2025-02-04all: remove the nolint tagsShulhan
The "nolint" tag is used to ignore lines from being processed by golangci-lint. Since we are not using golangci-lint anymore, now and in the future, those lines can be removed.
2025-01-23all: use for-range with numericShulhan
Go 1.22 now support for-range on numeric value.
2025-01-23all: replace "interface{}" with "any"Shulhan
2025-01-23all: replace [lib/bytes.WriteXxx] with standard libraryShulhan
The "encoding/binary.BigEndian" in standard library provides method PutXxx that do the same thing.
2025-01-23all: replace "lib/bytes.ReadXxx" with standard libraryShulhan
Package "encoding/binary" from standard library support reading integer from bytes using BigEndian, LittleEndian variables.
2025-01-23all: replace "lib/bytes.AppendXxx" with standard libraryShulhan
Since Go 1.19, package "encoding/binary.BigEndian" support appending byte order.
2025-01-22lib/bytes: replace Copy and Concat with standard libraryShulhan
Since Go 1.20, the standard bytes package have the Copy function. Since Go 1.22, the standard slices package have the Concat function.
2025-01-17lib/dns: improve the logging prefix on serveTCPClientShulhan
The serveTCPClient is used to serve TCP and DoT clients. Previously, the error returned from this method is prefixed based on the kind, for example serveTCPClient TCP: ... serveTCPClient DoT: ... This changes pass the log prefix to the method so now it become serveTCPClient: ... serveDoTClient: ...
2025-01-17lib/dns: detect invalid header earlierShulhan
Previously, we unpack the header and then question without detecting whether the header itself is valid or not, for example the op-code, the response code. This cause the unpacking question return an error like label length overflow at index xxx One of the case is when someone sent random or HTTP request to DoT port.
2025-01-15lib/dns: fix unpacking resource data on HTTPS recordShulhan
Instead of passing the whole packet, pass the packet for unpacking target name only and rdata for unpacking the SVCB HTTPS record.
2024-12-28lib/bytes: split the hexdump related functions to separate packageShulhan
Package hexdump implements reading and writing bytes from and into hexadecimal number. It support parsing output from hexdump(1) tool.
2024-09-30all: simplify some statementsShulhan
2024-05-04lib: comply with linter recommendationsShulhan
2024-04-13lib/dns: make server accept record type ANYShulhan
The record type ANY contains multiple A, AAAA or any known resource records that we already support.
2024-04-12lib/dns: return errInvalidMessage when received message cannot be parsedShulhan
By returning error errInvalidMessage, the caller can check whether the issue is in connection or in the message itself. If the issue is not in the message, the caller needs to re-create the connection.
2024-04-12lib/dns: fix packing and unpacking OPT recordShulhan
The RDATA in OPT records can contains zero or _more_ options. Previously, we only handle unpacking and packing one option, now we handle multiple options.
2024-04-04lib/dns: check for possible packet misformat in SVCB RR and TCP clientShulhan
If the length of packet is not as expected, return immendiately with an error. This is to prevent panic when unpacking the response message.
2024-04-03lib/dns: fix unpacking ipv4hint on SVCB recordShulhan
Somehow the test passed on my main machine, but failed on my laptop. Weird.
2024-03-27lib/dns: refactor [Message.Unpack] to [UnpackMessage]Shulhan
The previous API for Message is a little bit weird. Its provides creating Message manually, but expose the method [UnpackHeaderQuestion], meanwhile the field packet itself is unexported. In order to make it more clear we refactor [Message.Unpack] to function [UnpackMessage] that accept raw DNS packet.
2024-03-26lib/dns: implements RFC 9460 for SVCB RR and HTTPS RRShulhan
2024-03-26lib/dns: use ParseUint to parse escaped octet in "\NNN" formatShulhan
Previously, we use ParseInt to parse escaped octet "\NNN", but using this method only allow decimal from 0 to 127, while the specification allow 0 to 255.
2024-03-22lib/dns: add test flag to skip running DNS serverShulhan
When we want to test a function or methods that does not interact with DNS server, there is no need to run dummy DNS server.
2024-03-05all: comply with linter recommendations #3Shulhan
For HTTP server that use TLS, set the minimum TLS version and ReadHeaderTimeout to mitigate slowloris attack. For HTTP client or server that parameterize the use of InsecureSkipVerify, annotate the line with "nolint:gosec" to allow the code pass the check. Library that still use sha1, in example in DKIM and TOTP, skip the warnings by annotating the line with "nolint:gosec". A pointer variable now allocated their address before assigning its value. Any error that returned now wrapped using "%w". Also, replace error checking using [errors.Is] or [errors.As] instead of using equal or not-equal operators. In "lib/http", replace any usage of "math/rand" with "crypto/rand". Any call of [math/big.Rat.SetString] now annotated with "nolint:gosec" since its false positive, the issue has been fixed in Go >= 1.17.7. Any switch case that does not cover the rest of the possible values now handled by adding the cases or by replacing the "default" case with the rest of values.
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-05all: comply with linter recommendations #1Shulhan
Instead of annotating the lines that caught by linters, fix it to comply with the recommendations. This causes several breaking changes, especially related to naming, * api/slack: [Message.IconUrl] become [Message.IconURL] * lib/dns: DefaultSoaMinumumTtl become DefaultSoaMinimumTTL * lib/email: [Message.SetBodyHtml] become [Message.SetBodyHTML] * lib/http: [Client.GenerateHttpRequest] become [Client.GenerateHTTPRequest] * lib/http: [ClientOptions.ServerUrl] become [ClientOptions.ServerURL] * lib/http: [EndpointRequest.HttpWriter] become [EndpointRequest.HTTPWriter] * lib/http: [EndpointRequest.HttpRequest] become [EndpointRequest.HTTPRequest] * lib/http: [ServerOptions.EnableIndexHtml] become [ServerOptions.EnableIndexHTML] * lib/http: [SSEConn.HttpRequest] become [SSEConn.HTTPRequest] * lib/smtp: [ClientOptions.ServerUrl] become [ClientOptions.ServerURL] * lib/ssh/sftp: [FileAttrs.SetUid] become [FileAttrs.SetUID] * lib/ssh/sftp: [FileAttrs.Uid] become [FileAttrs.UID]
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-25lib/dns: prefix the error message with method namesShulhan
By prefixing the error message it allow us to better track the error message written by application.
2024-02-25lib/dns: ignore invalid messageShulhan
If Query return a message but the failed to unpack due to invalid format, for example unpackOPT: data length is out of range ignore it instead of disconnect the client connection.
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-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-09-11lib: fix method signature for WriteToShulhan
The WriteTo should return int64 not int.
2023-09-11lib/dns: realign struct in test CachesQueryShulhan
The realign reduce the struct cost from 200 to 176 bytes (-24 bytes).
2023-08-06lib/dns: fix leaking internal zoneShulhan
Previously, if the server have internal zone "my.internal" and the client query "sub.my.internal" that does not exist in the zone, the server then forward the query to parent name server. This cause the internal zone and its domains leaked to parent name server. This changes fix this issue by checking if the query is subset of internal zone Origin if domain does not exist, and response with error code 3 (ERR_NAME) with the Zone SOA in Authority.
2023-08-06lib/dns: add method to populate internal caches by ZoneShulhan
The InternalPopulateZone populate the internal caches from Zone's messages.
2023-08-06lib/dns: changes the return key on LoadZoneDirShulhan
Previously, the LoadZoneDir return the key as file name of zone. This changes return the key as Zone Origin to prevent same zones defined in different files.
2023-08-06lib/dns: use Zone as single source of truth when parsingShulhan
Previously, the zoneParser store its own origin and TTL, which make it duplicates and confuse with the zone field that stored and returned by parser. To make things simple, use the zone field value as single source of truth for origin (using zone.Origin) and TTL (using zone.SOA.Minimum).