The DNS directive calls either the dns-config built-in function or a DNS function that you specify.
Syntax
DNS fn=dns-config local-domain-levels=<n>
local-domain-levels specifies the number of levels of subdomains that the local network has. The default is 1.
Web Proxy Server optimizes DNS lookups by reducing the times of trying to resolve hosts that are apparently fully qualified domain names but which DNS would otherwise by default still try to resolve relative to the local domain.
For example, suppose you’re in the netscape.com domain, and you try to access the host www.xyzzy.com. At first, DNS will try to resolve:
www.xyzzy.com.netscape.com
and only after that the real fully-qualified domain name:
www.xyzzy.com
If the local domain has subdomains, such as corp.netscape.com, it would do the two additional lookups:
www.xyzzy.com.corp.netscape.com www.xyzzy.com.netscape.com
To avoid these extra DNS lookups, you can suggest to the proxy that it treat host names that are apparently not local as remote, and it should tell DNS immediately not to try to resolve the name relative to the current domain.
If the local network has no subdomains, you set the value to 0. This means that only if the host name has no domain part at all (no dots in the host name) will it be resolved relative to the local domain. Otherwise, DNS should always resolve it as an absolute, fully qualified domain name.
If the local network has one level of subdomains, you set the value to 1. This means that host names that include two or more dots will be treated as fully qualified domain names, and so on.
An example of one level of subdomains would be the netscape.com domain, with subdomains:
corp.netscape.com engr.netscape.com mktg.netscape.com
This means that hosts without a dot, such as step would be resolved with respect to the current domain, such as engr.netscape.com, and so the dns-config function would try this:
step.engr.netscape.com
If you are on corp.netscape.com but the destination host step is on the engr subdomain, you could say just:
step.engr
instead of having to specify the fully qualified domain name:
step.engr.netscape.com
This is a DNS-class function that you define.
Syntax
DNS fn=your-dns-function
Only the first applicable DNS function is called, starting from the most restrictive object. In the rare case that it is desirable to call multiple DNS functions, the function can return REQ_NOACTION.
The DNS function must have this prototype:
int your_dns_function(pblock *pb, Session *sn, Request *rq);
To get the host name use
pblock_findval("dns-host", rq->vars)
and set the host entry using the new NSAPI function
dns_set_hostent
The struct hostent * will not be freed by the caller but will be treated as a pointer to a static area, as with the gethostbyname call. It is a good idea to keep a pointer in a static variable in the custom DNS function and on the next call either use the same struct hostent or free it before allocating a new one.
The DNS function returns REQ_PROCEED if it is successful, and REQ_NOACTION if the next DNS function (or gethostbyname, if no other applicable DNS class functions exist) should be called instead. Any other return value is treated as failure to resolve the host name.
This example uses the normal gethostbyname call to resolve the host name:
#include <nsapi.h> int my_dns_func(pblock *pb, Session *sn, Request *rq) { char *host = pblock_findval("dns-host", rq->vars); struct hostent *hostent; hostent = gethostbyname(host); // replace with custom DNS implementation dns_set_hostent(hostent, sn, rq); return REQ_PROCEED; } |