I'm trying to implement my own DNS server from scratch. However, I'm having difficulty understanding how RFC 1035 recommends truncation to be performed.
Section 6.2 says:
When a response is so long that truncation is required, the truncation should start at the end of the response and work forward in the datagram. Thus if there is any data for the authority section, the answer section is guaranteed to be unique.
I can't really understand what this means. I assume "forward" means away from the header. But what does that have to do with the authority section? And it says "end of the response" which I assume means end of answer section? What if the whole answer section doesn't fit in the message?
Could somebody explain this algorithm better?
I also found Section 9 of RFC 2181 which says:
The TC bit should be set in responses only when an RRSet is required as a part of the response, but could not be included in its entirety. The TC bit should not be set merely because some extra information could have been included, but there was insufficient room. This includes the results of additional section processing. In such cases the entire RRSet that will not fit in the response should be omitted, and the reply sent as is, with the TC bit clear. If the recipient of the reply needs the omitted data, it can construct a query for that data and send that separately.
Where TC is set, the partial RRSet that would not completely fit may be left in the response. When a DNS client receives a reply with TC set, it should ignore that response, and query again, using a mechanism, such as a TCP connection, that will permit larger replies.