The DNSMASQ source under the Spit trough
First of all, thank you, the author provides a simple design, rich functions, fully reduce the work of our ordinary programmers, but to understand it is not so desirable, there are mainly a few points. 1. Irrelevant design, code indentation problem.
Everywhere no longer space, occasionally a few lines of tab, really bad look ah, reading up very troublesome
2. The overall design of the feeling
The main architecture of the program is select to listen for the state of the socket to operate-"decided that it can only be used in a small network architecture" using the
struct DNSMASQ global structure, which contains a lot of linked lists to store the data packets and the response to bind, think very cleverly, however, Personally feel that such a structure is too bloated, look really uncomfortable, only slowly familiar with the code logic, understanding the design.
3. Modify its DNS processing logic
The main processing logic in Check_dns_listener, I only looked at the request of UDP, TCP request did not pay attention to understand, seemingly is fork process, separate processing. The maximum number of connections is limited. The
main functions are Receive_query, forward_query, reply_query, etc.
receive_query-mainly parsing datagrams to see if there is a cache, there are no timeouts, use the cache Answer_ Request processing encapsulates the corresponding, does not call Forward_query
Forward_query-The main thing is to send the data message to all DNS servers, from/tmp/resolve.conf.auto
reply _query-Accept the DNS server response, after receiving the lookup is which request, not found is discarded, found, based on SOA, etc.