aboutsummaryrefslogtreecommitdiff
path: root/lib/dns/answer.go
AgeCommit message (Collapse)Author
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-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/
2023-03-25lib/dns: fix all lint warnings suggested by revive and fieldalignmentShulhan
2023-03-22lib/dns: make sure zone origin always end with dotShulhan
In RFC 1035 there is no clear definition whether origin end with dot or not. The only explanation is on page 33. ... Domain names that end in a dot are called absolute, and are taken as complete. Domain names which do not end in a dot are called relative; the actual domain name is the concatenation of the relative part with an origin specified in a $ORIGIN, $INCLUDE, or as an argument to the master file loading routine. Also, most of examples that we found use dot for terminating origin.
2022-05-30lib/dns: split storage between internal and external cachesShulhan
Previously, the indexed caches for internal (records from hosts or zone files) and external (records from parent name servers) are stored inside single map. This changes split those internal and external caches into two maps, so any operation on one caches does not affect the other one, and vice versa.
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-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-13lib/dns: remove unnecessary string convertionShulhan
2021-01-22dns: add method to get list of non-local caches in the ServerShulhan
The CachesLRU method return the list of non-local caches ordered by the least recently used. This changes affect the answer type which must be exported, including most of its fields, so consumer can access it.
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.
2019-12-04dns: remove the use of pointer on Message fieldsShulhan
2019-05-13dns: substract the message TTL when the answer found on cacheShulhan
This fix TTL on non local answer that is never changed when requested several times by client.
2019-04-12dns: cache response with empty answer resource recordShulhan
As long as the response is OK (response code 0), we should accept response with no answer RR. One of the case is when query is AAAA and the domain does not have IPv6 address, it would response with empty answer with response code OK.
2019-04-12dns: add caches for serverShulhan
There are two type of answer: local and non-local. Local answer is a DNS record that is loaded from hosts file or master zone file. Non-local answer is a DNS record that is received from parent name servers. Server caches the DNS answers in two storages: map and list. The map caches store local and non local answers, using domain name as a key and list of answers as value, domain-name -> [{A,IN,...},{AAAA,IN,...}] The list caches store non-local answers, ordered by last accessed time, it is used to prune least frequently accessed answers. Local caches will never get pruned.