mueslo / openwrt_hass_devicetracker

Simple OpenWRT package which forwards device connection changes to a HomeAssistant instance
GNU General Public License v3.0
92 stars 31 forks source link

Name resolution fails if reverse DNS zone not setup #8

Open zxdavb opened 5 years ago

zxdavb commented 5 years ago

If the nslookup fails, then maybe a warning in the log file would be a good idea?

I was getting (note host_name is a zero-length string, ""):

Mon Oct  8 17:51:20 2018 user.debug /usr/bin/hassd.sh: post {"mac":"6c:5a:b5:4e:75:c6","host_name":"","consider_home":"24:00","source_type":"router"}

instead of:

Mon Oct  8 17:51:20 2018 user.debug /usr/bin/hassd.sh: post {"mac":"6c:5a:b5:4e:75:c6","host_name":"db-desktop","consider_home":"24:00","source_type":"router"}

This happens when reverse name lookups fails in function get_host_name in functions.sh:

root@sr-router:~# nslookup 172.27.0.99
Server:         8.8.8.8
Address:        8.8.8.8#53

** server can't find 99.0.27.172.in-addr.arpa: NXDOMAIN

Say: logger -t $0 -p warning "Reverse DNS is not setup, so names cannot be resolved"

zxdavb commented 5 years ago

Having thought about this, I would expect this code not to:

   post $(build_payload "$mac" "$(get_host_name $mac)" "$timeout")

if $(get_host_name $mac) is a NULL string.

The reasoning is that: a) you could have a lot of devices on your WiFi LAN, and it will be painful to keep HA's known_devices.yaml up to date (e.g. someone visits and uses your WiFi) b) to choose which devices end up in HA, just make sure it has a lease and a reverse DNS entry (the last line, below):

uci add dhcp host
uci set dhcp.@host[-1].name=my-smartphone
uci set dhcp.@host[-1].mac='08:18:13:25:c1:87'
uci set dhcp.@host[-1].ip=192.168.0.100
uci set dhcp.@host[-1].dns=1
ttimasdf commented 4 years ago

Is nslookup by default using router's resolv.conf defined DNS server? If you point it to router itselves dnsmasq, the DNS lookup will have no problem.

mueslo commented 4 years ago

@zxdavb are you running regular dnsmasq? If so, the empty hostname is not because of not having set up the reverse DNS zone, but rather because the association event precedes assigning of a DNS name. Any subsequent events will likely have the correct DNS name, e.g. polling or disassociation events. Can you confirm that?

If so, this issue is essentially resolved by https://github.com/home-assistant/home-assistant/pull/31886

zxdavb commented 4 years ago

I am sorry, I have too much going on to help with this at the moment.