Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - bcjenkins

#16
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.
#17
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.

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 "";
                    }
                }
                       
        }
}
#18
15.1 Legacy Series / Re: IPv6 Dynamic DNS
June 15, 2015, 06:15:14 PM
To be honest, this is pretty specific to Cloudflare. My registrar didn't support DDNS for IPv6 and I am looking for a way to track the addresses automatically. Cloudflare's service is free to use and it might be interesting to create a mechanism which would leverage the NDP discovery to select which entries you would like to create records for.

The account email and API key is all you would need to do this. Each entry should have a MAC address, host, domain name, and TTL. If you were to store the zone ID, host ID, in the database and it will save additional calls on updates. The new API (V4) uses FQDN for host entries and domain name for zones. The FQDN can be the zone or sub-domains.

Cloudflare API - https://api.cloudflare.com/#dns-records-for-a-zone-create-dns-record

#19
15.1 Legacy Series / Re: IPv6 Dynamic DNS
June 15, 2015, 06:16:49 AM
Workable script below. Several assumptions are made

  • IPv6 address is based on MAC address. Windows does not default to this. You can fix with the code below and a reboot.
  • Domain is 2 levels like example.com and not 3 like example.co.uk

netsh interface ipv6 set global randomizeidentifiers=disabled
netsh interface ipv6 set privacy state=disabled


PHP code - This can be run as a cron job on the firewall. This works for CloudFlare using their V4 API.

<?php

/*
Copyright (C) 2015 CBA Solutions, LLC
Copyright (C) 2014 Deciso B.V.
Copyright (C) 2004-2010 Scott Ullrich <sullrich@gmail.com>
Copyright (C) 2011 Seth Mos <seth.mos@dds.nl>
Copyright (C) 2005 Paul Taylor (paultaylor@winndixie.com) and Manuel Kasper <mk@neon1.net>.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/

$hostTable = array("example.com" => "aa:bb:cc:dd:ee:f0", "server.example.com" => "aa:bb:cc:dd:ee:f1");

$cfEmail = "email@example.com";
$cfAPI = "9a7806061c88ada191ed06f989cc3dac";

//Code used from OpnSense Source
exec("/usr/sbin/ndp -na", $rawdata);
$data = array();
array_shift($rawdata);
foreach (
$rawdata as $line) {
   
$elements = preg_split('/[ ]+/', $line);
   
$ndpent = array();
   
$ndpent['ipv6'] = trim($elements[0]);
   
$ndpent['mac'] = trim($elements[1]);
   
$ndpent['interface'] = trim($elements[2]);
   
$data[] = $ndpent;
}

foreach (
$hostTable as $key => $value) {
   
$entries = array_keys(array_column($data, 'mac'), $value);
   foreach (
$entries as $entry => $number) {
       if (
substr($data[$number]['ipv6'], -4) === str_replace(':', '', substr($data[$number]['mac'],-5))) {
           
$domainArray = preg_split("/\./", $key);
           
$cfDomain = $domainArray[count($domainArray)-2] . "." . $domainArray[count($domainArray)-1];
           
$cfNewIP = $data[$number]['ipv6'];
           
$cfURL = 'https://api.cloudflare.com/client/v4/zones';

           
//Get the Zone ID
           
$curlRequest = curl_init();
           
curl_setopt($curlRequest,CURLOPT_HTTPHEADER,array("X-Auth-Email: $cfEmail","X-Auth-Key: $cfAPI","Content-Type: application/json"));
           
$cfURL .= '?' . "name=$cfDomain";
           
curl_setopt($curlRequest,CURLOPT_URL, $cfURL);
           
curl_setopt($curlRequest,CURLOPT_RETURNTRANSFER, true);
           
$result = curl_exec($curlRequest);
           
curl_close($curlRequest);
           
$cfData = json_decode($result);
           
$cfDomainID = $cfData->result[0]->id;

           
//Get the Zone Record for the FQDN
           
$cfURL = 'https://api.cloudflare.com/client/v4/zones/' . $cfDomainID . '/dns_records?type=AAAA&name=' . $key;
           
$curlRequest = curl_init();
           
curl_setopt($curlRequest,CURLOPT_HTTPHEADER,array("X-Auth-Email: $cfEmail","X-Auth-Key: $cfAPI","Content-Type: application/json"));
           
curl_setopt($curlRequest,CURLOPT_URL, $cfURL);
           
curl_setopt($curlRequest,CURLOPT_RETURNTRANSFER, true);
           
$result = curl_exec($curlRequest);
           
curl_close($curlRequest);
           
$cfData = json_decode($result);
           
$cfOldIP = $cfData->result[0]->content;
           
$cfHostID = $cfData->result[0]->id;

           if (
$cfOldIP != $cfNewIP){
               
// Build request to update current IP
               
$curlRequest = curl_init();
               
$cfUpdate = array();
               
$cfUpdate["id"] = $cfHostID;
               
$cfUpdate["type"] = "AAAA";
               
$cfUpdate["name"] = $key;
               
$cfUpdate["content"] = $cfNewIP;
               
$cfUpdate["zone_id"] = $cfDomainID;
               
$cfUpdate["zone_name"] = $cfDomain;
               
$cfUpdate["ttl"] = 300;
               
$cfURL = 'https://api.cloudflare.com/client/v4/zones/' . $cfDomainID . '/dns_records/' . $cfHostID;
               
curl_setopt($curlRequest,CURLOPT_HTTPHEADER,array("X-Auth-Email: $cfEmail","X-Auth-Key: $cfAPI","Content-Type: application/json"));
               
curl_setopt($curlRequest,CURLOPT_RETURNTRANSFER, true);
               
curl_setopt($curlRequest,CURLOPT_CUSTOMREQUEST, "PUT");
               
curl_setopt($curlRequest,CURLOPT_POSTFIELDS, json_encode($cfUpdate));
               
curl_setopt($curlRequest,CURLOPT_URL, $cfURL);
               
$result = curl_exec($curlRequest);
               
curl_close($curlRequest);
               
$cfData = json_decode($result);
           }
       }
   }
}
#20
15.1 Legacy Series / Re: IPv6 Dynamic DNS
June 13, 2015, 06:36:39 PM
I borrowed a little bit of code from the NDP diagnostics page and can execute this on the firewall to identify my desired host updates.
<?php

/*
Copyright (C) 2014 Deciso B.V.
Copyright (C) 2004-2010 Scott Ullrich <sullrich@gmail.com>
Copyright (C) 2011 Seth Mos <seth.mos@dds.nl>
Copyright (C) 2005 Paul Taylor (paultaylor@winndixie.com) and Manuel Kasper <mk@neon1.net>.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/

$hostTable = array("host1" => "aa:bb:cc:dd:ee:f0", "host2" => "aa:bb:cc:dd:ee:f1");


exec("/usr/sbin/ndp -na", $rawdata);
$data = array();
array_shift($rawdata);
foreach (
$rawdata as $line) {
   
$elements = preg_split('/[ ]+/', $line);
   
$ndpent = array();
   
$ndpent['ipv6'] = trim($elements[0]);
   
$ndpent['mac'] = trim($elements[1]);
   
$ndpent['interface'] = trim($elements[2]);
   
$data[] = $ndpent;
}

foreach (
$hostTable as $key => $value) {
   
$entries = array_keys(array_column($data, 'mac'), $value);
   foreach (
$entries as $entry => $number) {
       if (
substr($data[$number]['ipv6'], -4) === str_replace(':', '', substr($data[$number]['mac'],-5))) {
           echo
$key . " has IPv6 address of " . $data[$number]['ipv6'] . "\n";
           
/*This is where I would build out the DDNS update. I would start with a query of the DNS
           server to determine what the IP resolves to and then post an update if needed. You could
           also cache the last address locally or in a database, etc. */
       
}
   }
}


It would be awesome if something like this could wind up in the UI to set up. I'll continue to hack out my script for my purposes. If anyone is interested in the finished product please shout out.

--bcj
#21
15.1 Legacy Series / Re: IPv6 Dynamic DNS
June 09, 2015, 03:18:02 PM
No, I believe you're correct. You could build an application on the router to harvest the IPv6 assignments and correlate them with a MAC -> host table. Sending an update to the IPv6 DDNS platform when a change is detected.

Log on to your router and look at the current discovery information:

ndp -an

If your discovery seems light, then you can ping the multicast address to update the neighbor discovery:

ping6 -I em0 -c 3 ff02::1 Where em0 is your LAN interface.

As an example, my LAN interface knows about my LAN client and I could write a script to do this very coarsely. I would much rather it be baked in to the GUI and supported by the project. I would be willing to contribute to this effort, too, but I couldn't fund the entirety.
#22
15.1 Legacy Series / IPv6 Dynamic DNS
June 07, 2015, 03:58:15 AM
Is there a way for the firewall to track IPv6 clients behind it and update dynamic DNS entries on a service like Cloudflare?
#23
Thank you both for the comments. The issue as it turns out was unrelated to my OpnSense router and was instead related to my Aruba IAP-225 WAP at the house. The Aruba needs to have broadcast-filtering set to "None" for the SSID. (Source) I was able to isolate when I tested on a wire.

The settings I am using are below. The DNS is being provided by OpenDNS.

WAN Configuration:
IPv6 Configuration Type: DHCP6
DHCPv6 Prefix Delegation size: 56
Send IPv6 prefix hint: Checked

LAN Configuration:
IPv6 Configuration Type: Track Interface
Track IPv6 Interface -> IPv6 Interface: WAN

System -> Settings -> DNS Servers
208.67.222.222 - Set to WAN IPv4
208.67.220.220 - Set to WAN IPv4
2620:0:ccc::2 - Set to WAN IPv6
2620:0:ccd::2 - Set to WAN IPv6

Firewall -> Rules
Add WAN rule to allow IPv6 ICMP echoreq
#24
Greetings,

I have an IPv6 address on my WAN (/64) adapter, and managed to get one assigned to my LAN (/128) adapter. My PCs and Mac are NOT receiving an IPv6 address and when executing a ping6 from the LAN interface, I receive a "No route to host" error.

I didn't see anything in the forums on a simple IPv6 setup, is there one?

Provider is TWC in the US.

--bcj