1
1
mirror of https://github.com/eblot/pybootd.git synced 2024-09-11 14:06:57 +03:00

Allow to advertise serveral DNS servers.

Multiple DNS servers can be specified, separated with ';'. Most
clients will consider only the 1st one listed. The special 'auto'
keyword is updated to advertise all nameservers used by the DHCP
server.
This commit is contained in:
David Decotigny 2013-03-05 18:07:08 -08:00
parent ee5543ba97
commit 8162ce912d
2 changed files with 17 additions and 9 deletions

View File

@ -179,7 +179,10 @@ client requests at least an IP address twice:
Domain part of the client FQDN, that is the network's domain name.
``dns``
IP address of the DNS server. The server only accepts a single address.
IP addresses of DNS servers. Multiple addresses are separated with
semicolon. Specify ``auto`` to re-use DNS addresses used by the
server. Note that most DHCP clients will only consider the first
DNS address if multiple are provided.
``lease_time``
Validity in seconds of a DHCP lease. Please note that the BOOTP daemon does

View File

@ -559,9 +559,12 @@ class BootpServer:
'dns', None)
if dns:
if dns.lower() == 'auto':
dns = self.get_dns_server() or socket.inet_ntoa(server)
dns = socket.inet_aton(dns)
pkt += struct.pack('!BB4s', DHCP_IP_DNS, 4, dns)
dns_list = self.get_dns_servers() or [socket.inet_ntoa(server)]
else:
dns_list = dns.split(';')
for dns_str in dns_list:
dns_ip = socket.inet_aton(dns_str)
pkt += struct.pack('!BB4s', DHCP_IP_DNS, 4, dns_ip)
pkt += struct.pack('!BBI', DHCP_LEASE_TIME, 4,
int(self.config.get(self.bootp_section, 'lease_time',
str(24*3600))))
@ -589,20 +592,22 @@ class BootpServer:
(currentstate, newstate))
self.states[mac_str] = newstate
def get_dns_server(self):
def get_dns_servers(self):
nscre = re.compile('nameserver\s+(\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3})\s')
result = []
try:
with open('/etc/resolv.conf', 'r') as resolv:
for line in resolv:
mo = nscre.match(line)
if mo:
dns = mo.group(1)
self.log.info('Found primary nameserver: %s' % dns)
return dns
self.log.info('Found nameserver: %s' % dns)
result.append(dns)
except Exception, e:
pass
self.log.info('No nameserver found')
return None
if not result:
self.log.info('No nameserver found')
return result
def get_filename(self, ip):
"""Returns the filename defined for a host"""