Revision 31c43fd3
Added by Seth Mos over 13 years ago
etc/inc/interfaces.inc | ||
---|---|---|
1129 | 1129 |
pfSense_interface_flags($realif, -IFF_UP); |
1130 | 1130 |
} |
1131 | 1131 |
break; |
1132 |
case "6to4": |
|
1133 |
if(does_interface_exist("$realif")) { |
|
1134 |
mwexec("/sbin/ifconfig " . escapeshellarg($realif) . " delete", true); |
|
1135 |
if ($destroy == true) |
|
1136 |
pfSense_interface_flags($realif, -IFF_UP); |
|
1137 |
} |
|
1138 |
break; |
|
1132 | 1139 |
default: |
1133 | 1140 |
if(does_interface_exist("$realif")) { |
1134 | 1141 |
mwexec("/sbin/ifconfig " . escapeshellarg($realif) . " delete", true); |
... | ... | |
2871 | 2878 |
case '6rd': |
2872 | 2879 |
interface_6rd_configure($interface); |
2873 | 2880 |
break; |
2881 |
case '6to4': |
|
2882 |
interface_6to4_configure($interface); |
|
2883 |
break; |
|
2874 | 2884 |
default: |
2875 | 2885 |
if (is_ipaddr($wancfg['ipaddrv6']) && $wancfg['subnetv6'] <> "") { |
2876 | 2886 |
pfSense_interface_setaddress($realif, "{$wancfg['ipaddrv6']}/{$wancfg['subnetv6']}"); |
... | ... | |
3054 | 3064 |
return 0; |
3055 | 3065 |
} |
3056 | 3066 |
|
3067 |
function interface_6to4_configure($interface = "wan"){ |
|
3068 |
global $config, $g; |
|
3069 |
$iflist = get_configured_interface_with_descr(false, true); |
|
3070 |
|
|
3071 |
/* because this is a tunnel interface we can only function |
|
3072 |
* with a public IPv4 address on the interface */ |
|
3073 |
|
|
3074 |
$wancfg = $config['interfaces'][$interface]; |
|
3075 |
$wanif = $wancfg['if']; |
|
3076 |
if (empty($wancfg)) |
|
3077 |
$wancfg = array(); |
|
3078 |
|
|
3079 |
$wanif = get_real_interface($interface); |
|
3080 |
|
|
3081 |
$ip4address = find_interface_ip($wanif); |
|
3082 |
if((!is_ipaddrv4($ip4address)) || (is_private_ip($ip4address))) { |
|
3083 |
log_error("The interface IPv4 '{$ip4address}' address on interface '{$wanif}' is not public, not configuring 6RD tunnel"); |
|
3084 |
return false; |
|
3085 |
} |
|
3086 |
|
|
3087 |
/* create the long prefix notation for math, save the prefix length */ |
|
3088 |
$stfprefixlen = 16; |
|
3089 |
$stfprefix = Net_IPv6::uncompress("2002::"); |
|
3090 |
$stfarr = explode(":", $stfprefix); |
|
3091 |
$v4prefixlen = "0"; |
|
3092 |
|
|
3093 |
/* we need the hex form of the interface IPv4 address */ |
|
3094 |
$ip4arr = explode(".", $ip4address); |
|
3095 |
$hexwanv4 = ""; |
|
3096 |
foreach($ip4arr as $octet) |
|
3097 |
$hexwanv4 .= sprintf("%02x", $octet); |
|
3098 |
|
|
3099 |
/* we need the hex form of the broker IPv4 address */ |
|
3100 |
$ip4arr = explode(".", "192.88.99.1"); |
|
3101 |
$hexbrv4 = ""; |
|
3102 |
foreach($ip4arr as $octet) |
|
3103 |
$hexbrv4 .= sprintf("%02x", $octet); |
|
3104 |
|
|
3105 |
/* binary presentation of the prefix for all 128 bits. */ |
|
3106 |
$stfprefixbin = ""; |
|
3107 |
foreach($stfarr as $element) { |
|
3108 |
$stfprefixbin .= sprintf("%016b", hexdec($element)); |
|
3109 |
} |
|
3110 |
/* just save the left prefix length bits */ |
|
3111 |
$stfprefixstartbin = substr($stfprefixbin, 0, $stfprefixlen); |
|
3112 |
|
|
3113 |
/* if the prefix length is not 32 bits we need to shave bits off from the left of the v4 address. */ |
|
3114 |
$stfbrokerbin = substr(sprintf("%032b", hexdec($hexbrv4)), $v4prefixlen, 32); |
|
3115 |
$stfbrokerbin = str_pad($stfprefixstartbin . $stfbrokerbin, 128, "0", STR_PAD_RIGHT);; |
|
3116 |
|
|
3117 |
/* for the local subnet too. */ |
|
3118 |
$stflanbin = substr(sprintf("%032b", hexdec($hexwanv4)), $v4prefixlen, 32); |
|
3119 |
$stflanbin = str_pad($stfprefixstartbin . $stflanbin, 128, "0", STR_PAD_RIGHT);; |
|
3120 |
|
|
3121 |
/* convert the 128 bits for the broker address back into a valid IPv6 address */ |
|
3122 |
$stfbrarr = array(); |
|
3123 |
$stfbrbinarr = array(); |
|
3124 |
$stfbrbinarr = str_split($stfbrokerbin, 16); |
|
3125 |
foreach($stfbrbinarr as $bin) |
|
3126 |
$stfbrarr[] = dechex(bindec($bin)); |
|
3127 |
$stfbrarr[7] = 1; |
|
3128 |
$stfbrgw = Net_IPv6::compress(implode(":", $stfbrarr)); |
|
3129 |
|
|
3130 |
/* convert the 128 bits for the broker address back into a valid IPv6 address */ |
|
3131 |
$stflanarr = array(); |
|
3132 |
$stflanbinarr = array(); |
|
3133 |
$stflanbinarr = str_split($stflanbin, 16); |
|
3134 |
foreach($stflanbinarr as $bin) |
|
3135 |
$stflanarr[] = dechex(bindec($bin)); |
|
3136 |
$stflanpr = Net_IPv6::compress(implode(":", $stflanarr)); |
|
3137 |
$stflanarr[7] = 1; |
|
3138 |
$stflan = Net_IPv6::compress(implode(":", $stflanarr)); |
|
3139 |
|
|
3140 |
/* setup the stf interface */ |
|
3141 |
mwexec("/sbin/ifconfig stf0 destroy"); |
|
3142 |
mwexec("/sbin/ifconfig stf0 create"); |
|
3143 |
mwexec("/sbin/ifconfig stf0 inet6 {$stflanpr} prefixlen 16"); |
|
3144 |
|
|
3145 |
log_error("Set IPv6 address inet6 {$stflanpr} prefixlen 16 for stf0, route {$stfbrgw}"); |
|
3146 |
|
|
3147 |
/* write out a default router file */ |
|
3148 |
file_put_contents("{$g['tmp_path']}/{$wanif}_routerv6", "{$stfbrgw}"); |
|
3149 |
file_put_contents("{$g['tmp_path']}/{$wanif}_defaultgwv6", "{$stfbrgw}"); |
|
3150 |
|
|
3151 |
return 0; |
|
3152 |
} |
|
3153 |
|
|
3057 | 3154 |
function interface_dhcpv6_configure($interface = "wan") { |
3058 | 3155 |
global $config, $g; |
3059 | 3156 |
$iflist = get_configured_interface_with_descr(false, true); |
Also available in: Unified diff
Add 6to4 support for automatic tunneling.