Skip to content

Commit

Permalink
* DNS: resolve host names from DHCP: improve
Browse files Browse the repository at this point in the history
. Require a valid host name from DHCP lease
. Use lower-case names
  • Loading branch information
szolin committed Aug 18, 2020
1 parent 8d0c8ad commit efeacd9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
22 changes: 19 additions & 3 deletions AGHTechDoc.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ Contents:
* Update client
* Delete client
* API: Find clients by IP
* Enable DHCP server
* DHCP server
* DHCP server in DNS
* "Show DHCP status" command
* "Check DHCP" command
* "Enable DHCP" command
Expand Down Expand Up @@ -375,9 +376,9 @@ Error response:
UI shows error message "Auto-update has failed"


## Enable DHCP server
## DHCP server

Algorithm:
Enable DHCP server algorithm:

* UI shows DHCP configuration screen with "Enabled DHCP" button disabled, and "Check DHCP" button enabled
* User clicks on "Check DHCP"; UI sends request to server
Expand All @@ -389,6 +390,21 @@ Algorithm:
* UI shows the status


### DHCP server in DNS

DHCP leases are used in several ways by DNS module.

* For "A" DNS reqeust we reply with an IP address leased by our DHCP server.

< A bills-notebook.lan.
> A bills-notebook.lan. = 192.168.1.100

* For "PTR" DNS request we reply with a hostname from an active DHCP lease.

< PTR 100.1.168.192.in-addr.arpa.
> PTR 100.1.168.192.in-addr.arpa. = bills-notebook.


### "Show DHCP status" command

Request:
Expand Down
22 changes: 19 additions & 3 deletions dnsforward/handle_dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,20 @@ func processInitial(ctx *dnsContext) int {
return resultDone
}

// Return TRUE if host names doesn't contain disallowed characters
func isHostnameOK(hostname string) bool {
for _, c := range hostname {
if !((c >= 'a' && c <= 'z') ||
(c >= 'A' && c <= 'Z') ||
(c >= '0' && c <= '9') ||
c == '.' || c == '-') {
log.Debug("DNS: skipping invalid hostname %s from DHCP", hostname)
return false
}
}
return true
}

func (s *Server) onDHCPLeaseChanged(flags int) {
switch flags {
case dhcpd.LeaseChangedAdded,
Expand All @@ -110,15 +124,17 @@ func (s *Server) onDHCPLeaseChanged(flags int) {
ll := s.dhcpServer.Leases(dhcpd.LeasesAll)

for _, l := range ll {
if len(l.Hostname) == 0 {
if len(l.Hostname) == 0 || !isHostnameOK(l.Hostname) {
continue
}

m[l.IP.String()] = l.Hostname
lowhost := strings.ToLower(l.Hostname)

m[l.IP.String()] = lowhost

ip := make(net.IP, 4)
copy(ip, l.IP.To4())
hostToIP[l.Hostname] = ip
hostToIP[lowhost] = ip
}

log.Debug("DNS: added %d A/PTR entries from DHCP", len(m))
Expand Down

0 comments on commit efeacd9

Please sign in to comment.