aboutsummaryrefslogtreecommitdiff
path: root/lib/dns/message_test.go
AgeCommit message (Collapse)Author
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-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-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-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
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-06lib/dns: add method AddAuthority to MessageShulhan
The AddAuthority add the rr to list of Authority. Calling this method mark the message as answer, instead of query. If the rr is SOA, it will replace the existing record if exist and set the flag authoritative answer (IsAA) in header to true. If the rr is NS, it will be added only if its not exist. It will return an error if the rr type is not SOA or NS or the size of records in Authority is full, maximum four records.
2023-03-22lib/dns: remove unnecessary statements on test MessageShulhan
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.
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-15lib/dns: refactoring message questionShulhan
Previously the type for message question section SectionQuestion. This changes, rename the type to MessageQuestion.
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.
2021-03-14all: refactoring the test.Assert and test.AssertBench signatureShulhan
Previously, the test.Assert and test.AssertBench functions has the boolean parameter to print the stack trace of test in case its not equal. Since this parameter is not mandatory and its usually always set to "true", we remove them from function signature to simplify the call to Assert and AssertBench.
2020-09-06dns: unexport the Messsage's Packet fieldShulhan
This field is used for storing the actual DNS packet after Message.Pack has been called.
2020-08-15dns: refactoring the ResourceRecord values from []byte to stringShulhan
There are two reasons for this changes. First, to allow JSON encoded of ResourceRecord.Value without encoded to base64. Second, to minimize unreleased packet due to the backing storage is still used when assigned to Value (or any []byte field in RDataXXX).
2020-08-03dns: refactoring resource record fieldsShulhan
Previously, each record data is represented b¥ its own type, except for A, NS, CNAME, MB, MG, NULL, PTR, and TXT; represented b¥ slice of byte. This changes replace all record data with an interface{}.
2020-06-06all: use default linter optionsShulhan
2020-06-06dns: replace RDataText with plain []byteShulhan
2020-06-06dns: change unpackDomainName from recursive to loopShulhan
2019-12-04dns: remove the use of pointer on Message fieldsShulhan
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 warnings on duplicate statementsShulhan
2019-04-12dns/message: remove elapsed parameter on message IsExpired()Shulhan
Since this function is called after the TTL has been subtracted, there is no need to compare them with elapsed time; we only need to check if TTL is zero or not.
2019-04-12dns/client: add parameter to set recursion on Lookup()Shulhan
Previously, the recursion flags is on by default when we doing a Lookup. This may leak the DNS query to parent nameserver if client actually only want the local services. This commit add parameter to allow or disallow recursion when doing lookup.
2019-04-12dns/message: add method to set response codeShulhan
The method will set the response code in header and directly on the raw packet if its exist.
2019-04-12dns/message: add methods to set AA, Query, RD flagsShulhan
This methods allow converting a query message into a response message without generating new message.
2019-03-02all: suppress "dupl" linter warnings on test filesShulhan
2018-09-09lib/dns: fix test due to change on default new messageShulhan
2018-09-05lib/dns: export RDataText valueShulhan
2018-09-05Remove message pool, let the client handle how to pool the messageShulhan
2018-09-03lib/dns: rename method for marshal/unmarshal to Pack/UnpackShulhan
We try to follow Go encoding package conventions, but the BinaryUnmarshaler interface notation does not make sense in our case, where packet is already existed in message itself.
2018-09-03lib/dns: check for escaped character and octet in domain namesShulhan
From RFC 1035, section "5.1 Format", page 35, Because these files are text files several special encodings are necessary to allow arbitrary data to be loaded. In particular: ... \X where X is any character other than a digit (0-9), is used to quote that character so that its special meaning does not apply. For example, "\." can be used to place a dot character in a label. \DDD where each D is a digit is the octet corresponding to the decimal number described by DDD. The resulting octet is assumed to be text and is not checked for special meaning. ...
2018-08-22lib/dns: Implement client with TCP connectionShulhan
2018-08-22[test] lib/dns: Fix test input dataShulhan
2018-08-21lib/dns: marshal/unmarshal IP address from/to string representationShulhan
2018-08-19lib/dns: handle SRV RR (RFC 2782)Shulhan
2018-08-19lib/dns: convert all domain names to lower cases on marshaling or unmarshalingShulhan
2018-08-19lib/dns: add method to check if message is expiredShulhan
2018-08-17lib/dns: add support for IPv6 (RFC 3596)Shulhan
2018-08-17[test] lib/dns: test marshaling/unmarshaling A, NS, CNAME, and MX RDATAShulhan
2018-08-17lib/dns: remove type QueryClass, change it to uin16Shulhan
This to allow OPT RR with class represent requestor's UDP payload size.
2018-08-17lib/dns: implement marshaling message to binary (DNS message)Shulhan
2018-08-16dns: library that implement DNS client as in RFC 1035Shulhan
Additional implementation including RFC 6891 - Extension Mechanisms for DNS (EDNS(0)).