OPNsense Forum

English Forums => Development and Code Review => Topic started by: bcjenkins on June 18, 2015, 06:32:57 pm

Title: [SUGGESTION] diag_ndp.php
Post by: bcjenkins on June 18, 2015, 06:32:57 pm
I have been looking at the diag_ndp.php code to try and improve the page load time and the data which is returned. Instead of running multiple gethostbyaddr() calls which seem to take a while to timeout, set a variable instead. Also, while technically different, if you can't find a host entry for an IP then query the arp table for a name.

Code: [Select]
function _getHostName($mac,$ip)
{                       
        if(is_ipaddr($ip)) {
                $hostname = gethostbyaddr($ip);
                list($ip, $scope) = explode("%", $ip);
                if($hostname <> "" and $hostname <> $ip) {
                        return $hostname;
                } else {
                $hostname = exec("arp -a | grep $mac | cut -f 1 -d ' '");
                if ($hostname <> '?') {
                        return $hostname;
                        } else {
                        return "";
                    }
                }
                       
        }
}
Title: Re: [SUGGESTION] diag_ndp.php
Post by: franco on June 19, 2015, 05:24:44 pm
That definitely makes sense. I'm not so sure about the arp resolve tracking MAC through IPv4 to get a host name. ndp seems to do a best-effort already, looking at the command line output. (ndp -a vs. ndp -an, but not sure how to tie that into the system). I'll be back on Monday to merge this, thanks for looking into it. :)
Title: Re: [SUGGESTION] diag_ndp.php
Post by: bcjenkins on June 19, 2015, 05:57:01 pm
In my case, I am provided IPv6 via my cable provider and it isn't doing anything about name resolution which means that I will never lookup the IPs and definitely won't match them to my inside host information. The arp command does return the hostnames based on the IP assignments locally whereas the ndp -a command does not. Another consideration is that the arp command doesn't run if the other name resolution works.
Title: Re: [SUGGESTION] diag_ndp.php
Post by: franco on June 19, 2015, 06:10:33 pm
Alright, that could work. Let's try to avoid the excess timeout load even more... How about we cache arp output once like done with ndp output and skim through that each time an IP/MAC is being queried via the function?

Have a great weekend,
Franco
Title: Re: [SUGGESTION] diag_ndp.php
Post by: bcjenkins on June 19, 2015, 06:41:27 pm
Feel free to do whatever you'd like, I appreciate the willingness to incorporate the feedback! The arp -a command doesn't take anything on my side to execute for what it is worth but I don't know if that's always the case for others.

Enjoy your weekend as well.
Title: Re: [SUGGESTION] diag_ndp.php
Post by: franco on June 24, 2015, 05:18:08 pm
Keeping this in github to not lose track: https://github.com/opnsense/core/issues/225
Title: Re: [SUGGESTION] diag_ndp.php
Post by: franco on June 30, 2015, 10:36:42 am
I've put in the code for removing the spurious gethostbyaddr() calls: https://github.com/opnsense/core/commit/38235b79b13ed6414584283f03a1c8e1767c25c0

I'm still a bit unsure if using arp to resolve IPv6 to IPv4-assigned hostnames is really the right thing to do. Adding an IPv6 mapping to /etc/hosts seems to resolve fine. Any thoughts from our IPv6 enthusiasts? :)
Title: Re: [SUGGESTION] diag_ndp.php
Post by: bcjenkins on June 30, 2015, 02:11:06 pm
Hi Franco,

How would the hosts file learn of the IP addresses and how would it update when the provider makes a change? I don't see how that is possible.

--bcj
Title: Re: [SUGGESTION] diag_ndp.php
Post by: franco on June 30, 2015, 03:31:27 pm
It sounds like the is an IPv6 DNS server missing from your setup. The biggest question is: where do the host names for these IPv6 addresses come from?

/usr/sbin/arp uses gethostaddr() to resolve the names, the only difference here being that it works on IPv4, not IPv6. So either your local config knows the host names or they are resolved via a DNS server from your upstream DNS server (likely your provider).

/usr/sbin/ndp uses getnameinfo().

PHP also use gethostaddr(), so in theory all your host names should light up given the resolvers are set up correctly for IPv6.
Title: Re: [SUGGESTION] diag_ndp.php
Post by: bcjenkins on June 30, 2015, 04:10:47 pm
If my provider provided any host name it would be in their naming convention and not mine; therefore useless to me. The IPv6 DHCP services are not handled locally. Instead, they are handled by my provider. IPv4 host names are provided locally by the inside DHCP services. These names are meaningful to me.

I do have the track interface's IPv6 address set up as a DNS provider and I am running the Unbound DNS server. This is currently managed manually and I have a request for consideration thread opened to make it automated. https://forum.opnsense.org/index.php?topic=795.0