summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsmos <seth.mos@dds.nl>2012-02-01 12:36:38 +0100
committersmos <seth.mos@dds.nl>2012-02-01 12:36:38 +0100
commitf87ccbed8357f0f6648d8704760b5b5732e73b0c (patch)
treebc1327c7927ba71c9c8a38921deac8bde0c1a89a
parenta11df336d4492c6846d6362a7fe88d0eefe36f11 (diff)
downloadpfsense-f87ccbed8357f0f6648d8704760b5b5732e73b0c.zip
pfsense-f87ccbed8357f0f6648d8704760b5b5732e73b0c.tar.gz
Add more backend code to calculate the 6RD broker IPv6 address from the IPv4 broker address.
Adds to ticket #2117
-rw-r--r--etc/inc/interfaces.inc40
1 files changed, 39 insertions, 1 deletions
diff --git a/etc/inc/interfaces.inc b/etc/inc/interfaces.inc
index 3c34d0a..c7b080d 100644
--- a/etc/inc/interfaces.inc
+++ b/etc/inc/interfaces.inc
@@ -2956,11 +2956,49 @@ function interface_6rd_configure($interface = "wan"){
return false;
}
+ /* calculate the IPv6 prefix from the public IPv4 address */
+ $ip4arr = explode(".", $ip4address);
+ $rd6prefix = explode("/", $wancfg['prefix-6rd']);
+ $rd6prefixlen = $rd6prefix[1];
+ $rd6prefix = Net_IPv6::uncompress($rd6prefix[0]);
+
+ $rd6arr = explode(":", $rd6prefix);
+ $rd6wanarr = array();
+ $length = $rd6prefixlen;
+ foreach($rd6arr as $element) {
+ if(($length < 0) && (empty($ip4arr))) {
+ $rd6wanarr[] = 0;
+ continue;
+ }
+ /* more then 16 bits left, just add element */
+ if($length >= 16)
+ $rd6wanarr[] = $element;
+ /* less then 16 bits, add ip4 octet */
+ if(($length <= 16) && ($length >= 8) && (count($ip4arr) > 0)) {
+ $rd6wanarr[] = dechex(hexdec($element) + $ip4arr[0]);
+ array_shift($ip4arr);
+ }
+ if(($length < 0) && (count($ip4arr) > 0)) {
+ $rd6el = array();
+ $rd6el[] = dechex($ip4arr[0]);
+ $rd6el[] = dechex($ip4arr[1]);
+
+ $rd6wanarr[] = $rd6el[0] . $rd6el[1];
+ array_shift($ip4arr);
+ array_shift($ip4arr);
+ }
+ $length = $length - 16;
+ }
+
+ $rd6wanprefix = implode(":", $rd6wanarr);
+
/* setup the stf interface */
mwexec("/sbin/ifconfig stf0 destroy");
mwexec("/sbin/ifconfig stf0 create");
- mwexec("/sbin/ifconfig stf0 inet6 {$wancfg['prefix-6rd']}");
+ mwexec("/sbin/ifconfig stf0 inet6 {$rd6wanprefix}/{$rd6prefixlen}");
+ /* FIXME, do we want to automagically inject a route here? */
+
/* Example 6RD setup steps
# ifconfig fxp0 inet6 2001:db8:c000:0202::1/64
# ifconfig fxp1 inet 192.0.2.2/24
OpenPOWER on IntegriCloud