From 83eebc528950026aabebbe43b68ed25ce06b8ecd Mon Sep 17 00:00:00 2001 From: Goffredo Andreone Date: Mon, 19 Feb 2007 02:41:33 +0000 Subject: Added start of DNS forwarding code. Not functional as of yet in that recursion is not implemented. Other minor fix ups. --- packages/tinydns/tinydns.inc | 81 +++++++++++++++++++++++++++++++- packages/tinydns/tinydns.xml | 6 +++ packages/tinydns/tinydns_dhcp_filter.php | 3 ++ 3 files changed, 89 insertions(+), 1 deletion(-) (limited to 'packages/tinydns') diff --git a/packages/tinydns/tinydns.inc b/packages/tinydns/tinydns.inc index 4680d3f4..0b80da75 100644 --- a/packages/tinydns/tinydns.inc +++ b/packages/tinydns/tinydns.inc @@ -277,7 +277,16 @@ function tinydns_create_zone_file() { log_error("Could not open /service/tinydns/root/data for writing."); return; } - + + /* Load the root servers if Forwarding is enabled */ + if($config['installedpackages']['tinydns']['config'][0]['enableforwarding']) { + if($config['system']['hostname']['domain']) { + $forwardingservers = tinydns_register_forwarding_servers(); + $forwardingservers .= tinydns_register_root_servers(); + if($forwardingservers)fwrite($fd, $forwardingservers); + } + } + /* Bind TinyDNS to LAN IP and register SOA for Forward and Reverse DNS */ if($config['installedpackages']['tinydns']['config'][0]['bind2lan']) { if($config['system']['hostname']['domain']) { @@ -432,6 +441,7 @@ function tinydns_do_xmlrpc_sync($sync_to_ip, $password) { } log_error("[tinydns] tinydns_xmlrpc_sync.php is ending."); } + /* formats data as a tinydns data row item */ /* A full description of the data format is available at 'man tinydns-data' */ function tinydns_get_rowline_data($recordip, $recordtype, $ttl, $hostname, $rdns) { @@ -615,4 +625,73 @@ function tinydns_get_dns_record_type($tinydnsrecord){ } return array ($rtype, $rtype2, $rdns); } + +/* This function will be replaced by an auto detect DNS cache servers routine */ +/* At the moment ther is no tagging of DNSroute to a WAN port. It needs to be added */ +function tinydns_register_forwarding_servers() { + $fr = fopen("/var/etc/resolv.conf", "r"); + if (! $fr) { + printf("Error: cannot open resolv.conf in tinydns_register_forwarding_servers().\n"); + return 1; + } + + $lip = strlen("nameserver") + 1; + $j = 0; + $nsrecords = ""; + $arecords = ""; + while (!feof($fr)) { + $routers = fgets($fr, 4096); + $discard = ($routers[0] == "\n"); + if(!$discard){ + if ($routerip = strstr($routers,"nameserver")){ + $routerip = substr($routerip,$lip); + if($routerip){ + $j += 1; + $routerfqdn = "DNSroute-{$j}.wan{$j}"; + $routerns = "&::{$routerfqdn}"; + $routera = "={$routerfqdn}:{$routerip}"; + $nsrecords .= $routerns . "\n"; + $arecords .= $routera; + } + } + } + } + fclose($fr); + $dnsroutes ="{$nsrecords}{$arecords}"; + return $dnsroutes; +} + +function tinydns_register_root_servers() { +$rootservers =<< \ No newline at end of file diff --git a/packages/tinydns/tinydns.xml b/packages/tinydns/tinydns.xml index 983e52df..ca7c464c 100644 --- a/packages/tinydns/tinydns.xml +++ b/packages/tinydns/tinydns.xml @@ -107,6 +107,12 @@ /usr/local/pkg/tinydns.inc + + Enable DNS Forwarders + enableforwarding + Enable forwarding of unanswered DNS requests to the external DNS servers. + checkbox + Bind TinyDNS to LAN bind2lan diff --git a/packages/tinydns/tinydns_dhcp_filter.php b/packages/tinydns/tinydns_dhcp_filter.php index 28aca035..75fac7f5 100644 --- a/packages/tinydns/tinydns_dhcp_filter.php +++ b/packages/tinydns/tinydns_dhcp_filter.php @@ -91,6 +91,9 @@ while ($startofrecord < $datalen ){ $ip = substr($dnsrecord,$col1+2); else $ip = substr($dnsrecord,$col1+1); + /* For root-servers get rid of the leading colon */ + if($ip[0] == ":")$ip = substr($ip,1); + if(!$rtypes[2])$rtypes[2] = "na"; echo ""; echo "$fqdn"; echo "$rtypes[0] $rtypes[1]"; -- cgit v1.2.3