Project

General

Profile

« Previous | Next » 

Revision be45aa79

Added by Renato Botelho over 12 years ago

Remove some trailing spaces and tabs from EOL

View differences:

etc/inc/interfaces.inc
75 75
 */
76 76
function does_interface_exist($interface) {
77 77
	global $config;
78
	
78

  
79 79
	if(!$interface)
80 80
		return false;
81 81

  
......
92 92
 */
93 93
function does_vip_exist($vip) {
94 94
	global $config;
95
	
95

  
96 96
	if(!$vip)
97 97
		return false;
98 98

  
......
172 172
					$found = true;
173 173
					break;
174 174
				}
175
*/			
175
*/
176 176
				$ports = explode(',',$ppp['ports']);
177 177
				foreach($ports as $pid => $port){
178 178
					$port = get_real_interface($port);
......
180 180
						$found = true;
181 181
						break;
182 182
					}
183
					/* Find the parent interfaces of the vlans in the MLPPP configs 
184
					* there should be only one element in the array here 
183
					/* Find the parent interfaces of the vlans in the MLPPP configs
184
					* there should be only one element in the array here
185 185
					* -- this could be better . . . */
186 186
					$parent_if = get_parent_interface($port);
187 187
					if ($realif == $parent_if[0]) {
......
192 192
			}
193 193
		}
194 194
	}
195
	
195

  
196 196
	if ($found == false) {
197 197
		$realif = get_real_interface($interface);
198 198
		pfSense_ngctl_detach("{$realif}:", $realif);
......
477 477

  
478 478
	/* Just in case anything is not working well */
479 479
	if ($smallermtu == 0)
480
		$smallermtu = 1500; 
480
		$smallermtu = 1500;
481 481

  
482 482
	$flags = 0;
483 483
	if ($commonrx === false)
......
519 519

  
520 520
	if (isset($bridge['enablestp'])) {
521 521
		/* Choose spanning tree proto */
522
		mwexec("/sbin/ifconfig {$bridgeif} proto {$bridge['proto']}");	
523
		
522
		mwexec("/sbin/ifconfig {$bridgeif} proto {$bridge['proto']}");
523

  
524 524
		if (!empty($bridge['stp'])) {
525 525
			$stpifs = explode(',', $bridge['stp']);
526 526
			foreach ($stpifs as $stpif) {
......
548 548
			}
549 549
			foreach ($ifpriority as $key => $value) {
550 550
				$realif = get_real_interface($key);
551
				mwexec("/sbin/ifconfig ${bridgeif} ifpriority {$realif} {$value}"); 
551
				mwexec("/sbin/ifconfig ${bridgeif} ifpriority {$realif} {$value}");
552 552
			}
553 553
		}
554 554
		if (!empty($bridge['ifpathcost'])) {
......
618 618
	}
619 619

  
620 620
	if($bridgeif)
621
		interfaces_bring_up($bridgeif);	
622
	else 
621
		interfaces_bring_up($bridgeif);
622
	else
623 623
		log_error(gettext("bridgeif not defined -- could not bring interface up"));
624 624

  
625 625
	return $bridgeif;
......
632 632

  
633 633
	$mtu = get_interface_mtu($bridgeif);
634 634
	$mtum = get_interface_mtu($interface);
635
	
635

  
636 636
	if ($mtu != $mtum && !(substr($interface, 0, 3) == "gif" && $mtu <= 1500))
637 637
		pfSense_interface_mtu($interface, $mtu);
638 638

  
......
650 650
	pfSense_bridge_add_member($bridgeif, $interface);
651 651
}
652 652

  
653
function interfaces_lagg_configure() 
653
function interfaces_lagg_configure()
654 654
{
655 655
        global $config, $g;
656
		if($g['booting']) 
656
		if($g['booting'])
657 657
			echo gettext("Configuring LAGG interfaces...");
658 658
        $i = 0;
659 659
		if (is_array($config['laggs']['lagg']) && count($config['laggs']['lagg'])) {
......
665 665
				$i++;
666 666
			}
667 667
		}
668
		if($g['booting']) 
668
		if($g['booting'])
669 669
			echo gettext("done.") . "\n";
670 670
}
671 671

  
......
678 678
	$members = explode(',', $lagg['members']);
679 679
	if (!count($members))
680 680
		return -1;
681
	
681

  
682 682
	if ($g['booting'] || !(empty($lagg['laggif']))) {
683 683
		pfSense_interface_destroy($lagg['laggif']);
684 684
		pfSense_interface_create($lagg['laggif']);
......
734 734
		interfaces_bring_up($member);
735 735
		mwexec("/sbin/ifconfig {$laggif} laggport {$member}");
736 736
	}
737
	
737

  
738 738
	mwexec("/sbin/ifconfig {$laggif} laggproto {$lagg['proto']}");
739 739

  
740 740
	interfaces_bring_up($laggif);
......
795 795

  
796 796
	if($greif)
797 797
		interfaces_bring_up($greif);
798
	else 
798
	else
799 799
		log_error(gettext("Could not bring greif up -- variable not defined."));
800 800

  
801 801
	if (isset($gre['link1']) && $gre['link1'])
......
851 851
	/* make sure the parent interface is up */
852 852
	if($realif)
853 853
		interfaces_bring_up($realif);
854
	else 
854
	else
855 855
		log_error(gettext("could not bring realif up -- variable not defined -- interface_gif_configure()"));
856 856

  
857 857
	if ($g['booting'] || !(empty($gif['gifif']))) {
......
927 927
	$iflist = get_configured_interface_with_descr();
928 928
	$delayed_list = array();
929 929
	$bridge_list = array();
930
	
930

  
931 931
	/* This is needed to speedup interfaces on bootup. */
932 932
	$reload = false;
933 933
	if (!$g['booting'])
......
935 935

  
936 936
	foreach($iflist as $if => $ifname) {
937 937
		$realif = $config['interfaces'][$if]['if'];
938
		if (strstr($realif, "bridge")) 
938
		if (strstr($realif, "bridge"))
939 939
			$bridge_list[$if] = $ifname;
940 940
		else if (strstr($realif, "gre"))
941 941
			$delayed_list[$if] = $ifname;
......
951 951
			if($g['debug'])
952 952
				log_error(sprintf(gettext("Configuring %s"), $ifname));
953 953
			interface_configure($if, $reload);
954
			if ($g['booting']) 
954
			if ($g['booting'])
955 955
				echo gettext( "done.") . "\n";
956 956
		}
957 957
	}
......
1055 1055
		break;
1056 1056
	case "carp":
1057 1057
		$vipif = "{$vip['interface']}_vip{$vip['vhid']}";
1058
		if (does_interface_exist($vipif)) 
1058
		if (does_interface_exist($vipif))
1059 1059
			pfSense_interface_destroy($vipif);
1060 1060
		break;
1061 1061
	}
......
1065 1065
	global $config, $g;
1066 1066

  
1067 1067
	if (!isset($config['interfaces'][$interface]))
1068
		return; 
1068
		return;
1069 1069
	log_error("Calling interface down for interface {$interface}, destroy is " . (($destroy) ? 'true' : 'false'));
1070 1070

  
1071 1071
	$ifcfg = $config['interfaces'][$interface];
......
1143 1143
				mwexec("/sbin/ifconfig " . escapeshellarg($realif) . " inet6 {$ip6} delete", true);
1144 1144
			if ($destroy == true)
1145 1145
				pfSense_interface_flags($realif, -IFF_UP);
1146
		}		
1146
		}
1147 1147
		break;
1148 1148
	default:
1149 1149
		if(does_interface_exist("$realif")) {
......
1173 1173
	unlink_if_exists("{$g['tmp_path']}/{$realif}_routerv6");
1174 1174
	unlink_if_exists("{$g['varetc_path']}/nameserver_{$realif}");
1175 1175
	unlink_if_exists("{$g['varetc_path']}/searchdomain_{$realif}");
1176
	
1176

  
1177 1177
	/* hostapd and wpa_supplicant do not need to be running when the interface is down.
1178 1178
	 * They will also use 100% CPU if running after the wireless clone gets deleted. */
1179 1179
	if (is_array($ifcfg['wireless'])) {
......
1184 1184
	if ($destroy == true) {
1185 1185
		if (preg_match("/^[a-z0-9]+_vip|^tun|^ovpn|^gif|^gre|^lagg|^bridge|vlan|^stf/i", $realif))
1186 1186
			pfSense_interface_destroy($realif);
1187
	}	
1187
	}
1188 1188

  
1189 1189
	return;
1190 1190
}
......
1229 1229
	$pppif = "{$post_array['type']}{$post_array['ptpid']}";
1230 1230
	$cron_cmd_file = "{$g['varetc_path']}/pppoe_restart_{$pppif}";
1231 1231

  
1232
	if (!is_array($config['cron']['item'])) 
1233
		$config['cron']['item'] = array(); 
1232
	if (!is_array($config['cron']['item']))
1233
		$config['cron']['item'] = array();
1234 1234

  
1235 1235
	$itemhash = getMPDCRONSettings($pppif);
1236
	
1236

  
1237 1237
	// reset cron items if necessary and return
1238 1238
	if (empty($post_array['pppoe-reset-type'])) {
1239 1239
		if (isset($itemhash))
......
1242 1242
		return;
1243 1243
	}
1244 1244

  
1245
	if (empty($itemhash)) 
1245
	if (empty($itemhash))
1246 1246
		$itemhash = array();
1247 1247
	$item = array();
1248 1248
	if (isset($post_array['pppoe-reset-type']) && $post_array['pppoe-reset-type'] == "custom") {
......
1295 1295
	}
1296 1296
	if (empty($item))
1297 1297
		return;
1298
	if (isset($item['ID'])) 
1298
	if (isset($item['ID']))
1299 1299
		$config['cron']['item'][$item['ID']] = $item;
1300
	else 
1300
	else
1301 1301
		$config['cron']['item'][] = $item;
1302 1302
}
1303 1303

  
......
1339 1339
		$type = "modem";
1340 1340
	else
1341 1341
		$type = $ppp['type'];
1342
	$upper_type = strtoupper($ppp['type']);	
1342
	$upper_type = strtoupper($ppp['type']);
1343 1343

  
1344 1344
	if($g['booting']) {
1345 1345
		$descr = isset($ifcfg['descr']) ? $ifcfg['descr'] : strtoupper($interface);
......
1366 1366
	 */
1367 1367
	foreach($ports as $pid => $port){
1368 1368
		switch ($ppp['type']) {
1369
			case "pppoe": 
1369
			case "pppoe":
1370 1370
				/* Bring the parent interface up */
1371 1371
				interfaces_bring_up($port);
1372 1372
				pfSense_ngctl_attach(".", $port);
......
1380 1380
					interfaces_bring_up($port);
1381 1381
				} else if (empty($localips[$pid]))
1382 1382
					$localips[$pid] = get_interface_ip($port); // try to get the interface IP from the port
1383
				
1383

  
1384 1384
				if(!is_ipaddr($localips[$pid])){
1385 1385
					log_error("Could not get a Local IP address for PPTP/L2TP link on {$port} in interfaces_ppps_configure. Using 0.0.0.0 ip!");
1386 1386
					$localips[$pid] = "0.0.0.0";
......
1388 1388
				/* XXX: This needs to go away soon! [It's commented out!] */
1389 1389
				/* Configure the gateway (remote IP ) */
1390 1390
				if (!$g['booting'] && !is_ipaddr($gateways[$pid]) && is_hostname($gateways[$pid])) {
1391
					/* XXX: Fix later 
1391
					/* XXX: Fix later
1392 1392
					$gateways[$pid] = gethostbyname($gateways[$pid]);
1393 1393
					if(!is_ipaddr($gateways[$pid])) {
1394 1394
						log_error("Could not get a valid Gateway IP from {$port} via DNS in interfaces_ppps_configure.");
......
1413 1413
				break;
1414 1414
		}
1415 1415
	}
1416
	
1416

  
1417 1417
	if (is_array($ports) && count($ports) > 1)
1418 1418
		$multilink = "enable";
1419 1419
	else
1420 1420
		$multilink = "disable";
1421
	
1421

  
1422 1422
	if ($type == "modem"){
1423 1423
		if (is_ipaddr($ppp['localip']))
1424 1424
			$localip = $ppp['localip'];
......
1430 1430
		else
1431 1431
			$gateway = "10.64.64.{$pppid}";
1432 1432
		$ranges = "{$localip}/0 {$gateway}/0";
1433
		
1434
		if (empty($ppp['apnum']))	
1433

  
1434
		if (empty($ppp['apnum']))
1435 1435
			$ppp['apnum'] = 1;
1436 1436
	} else
1437 1437
		$ranges = "0.0.0.0/0 0.0.0.0/0";
1438 1438

  
1439
	if (isset($ppp['ondemand'])) 
1439
	if (isset($ppp['ondemand']))
1440 1440
		$ondemand = "enable";
1441 1441
	else
1442 1442
		$ondemand = "disable";
......
1490 1490
			}
1491 1491
		}
1492 1492
	}
1493
	
1493

  
1494 1494
	if (($interface == "wan" && $founddefaultgw == false) || $setdefaultgw == true){
1495 1495
		$setdefaultgw = true;
1496 1496
		$mpdconf .= <<<EOD
......
1509 1509
	set iface addrs 10.10.1.1 10.10.1.2
1510 1510

  
1511 1511
EOD;
1512
	
1512

  
1513 1513
	if (isset($ppp['tcpmssfix']))
1514 1514
		$tcpmss = "disable";
1515 1515
	else
......
1670 1670

  
1671 1671
EOD;
1672 1672
		}
1673
		
1673

  
1674 1674
		$mpdconf .= "\topen\n";
1675 1675
	} //end foreach($port)
1676 1676

  
......
1714 1714
	/* fire up mpd */
1715 1715
	mwexec("/usr/local/sbin/mpd5 -b -k -d {$g['varetc_path']} -f mpd_{$interface}.conf -p {$g['varrun_path']}/{$ppp['type']}_{$interface}.pid -s ppp {$ppp['type']}client");
1716 1716

  
1717
	// Check for PPPoE periodic reset request 
1717
	// Check for PPPoE periodic reset request
1718 1718
	if ($type == "pppoe") {
1719 1719
		if (!empty($ppp['pppoe-reset-type']))
1720 1720
			interface_setup_pppoe_reset_file($ppp['if'], $interface);
......
1781 1781
		mwexec("/sbin/sysctl net.inet.carp.arpbalance=1", true);
1782 1782
		mwexec("/sbin/sysctl net.inet.carp.preempt=0", true);
1783 1783
	} else
1784
		mwexec("/sbin/sysctl net.inet.carp.preempt=1", true);		
1784
		mwexec("/sbin/sysctl net.inet.carp.preempt=1", true);
1785 1785

  
1786 1786
	mwexec("sbin/sysctl net.inet.carp.log=1", true);
1787 1787
	if (!empty($pfsyncinterface))
......
1792 1792
	/* setup pfsync interface */
1793 1793
	if ($carp_sync_int and $pfsyncenabled) {
1794 1794
		if (is_ipaddr($pfsyncpeerip))
1795
			mwexec("/sbin/ifconfig pfsync0 syncdev {$carp_sync_int} syncpeer {$pfsyncpeerip} up", false);						
1795
			mwexec("/sbin/ifconfig pfsync0 syncdev {$carp_sync_int} syncpeer {$pfsyncpeerip} up", false);
1796 1796
		else
1797
			mwexec("/sbin/ifconfig pfsync0 syncdev {$carp_sync_int} up", false);			
1797
			mwexec("/sbin/ifconfig pfsync0 syncdev {$carp_sync_int} up", false);
1798 1798

  
1799 1799
		sleep(1);
1800 1800

  
......
1812 1812
	}
1813 1813

  
1814 1814
	if($config['virtualip']['vip'])
1815
		mwexec("/sbin/sysctl net.inet.carp.allow=1", true);				
1815
		mwexec("/sbin/sysctl net.inet.carp.allow=1", true);
1816 1816
	else
1817
		mwexec("/sbin/sysctl net.inet.carp.allow=0", true);		
1818
	
1817
		mwexec("/sbin/sysctl net.inet.carp.allow=0", true);
1818

  
1819 1819
	if ($g['booting']) {
1820 1820
		unmute_kernel_msgs();
1821 1821
		echo gettext("done.") . "\n";
......
1848 1848
					$proxyif = $vipent['interface'];
1849 1849
				else
1850 1850
					$proxyif = "wan";
1851
				
1851

  
1852 1852
				if (!empty($interface) && $interface != $proxyif)
1853 1853
					continue;
1854 1854

  
......
1872 1872
                                else if (isset($paent['range']))
1873 1873
                                        $args .= " " . escapeshellarg($paent['range']['from'] . "-" . $paent['range']['to']);
1874 1874
                        }
1875
                        mwexec_bg("/usr/local/sbin/choparp " . $args);	
1875
                        mwexec_bg("/usr/local/sbin/choparp " . $args);
1876 1876
		}
1877 1877
	} else if (count($paa) > 0) {
1878 1878
		foreach ($paa as $paif => $paents)  {
......
2049 2049

  
2050 2050
function interface_wireless_clone($realif, $wlcfg) {
2051 2051
	global $config, $g;
2052
	/*   Check to see if interface has been cloned as of yet.  
2052
	/*   Check to see if interface has been cloned as of yet.
2053 2053
	 *   If it has not been cloned then go ahead and clone it.
2054 2054
	 */
2055 2055
	$needs_clone = false;
......
2376 2376
			}
2377 2377
			break;
2378 2378
		case 'hostap':
2379
			if($wlcfg['wpa']['passphrase']) 
2379
			if($wlcfg['wpa']['passphrase'])
2380 2380
				$wpa_passphrase = "wpa_passphrase={$wlcfg['wpa']['passphrase']}\n";
2381
			else 
2381
			else
2382 2382
				$wpa_passphrase = "";
2383 2383
			if (isset($wlcfg['wpa']['enable'])) {
2384 2384
				$wpa .= <<<EOD
......
2418 2418
}
2419 2419
				if($wlcfg['auth_server_addr'] && $wlcfg['auth_server_shared_secret']) {
2420 2420
					$auth_server_port = "1812";
2421
					if($wlcfg['auth_server_port']) 
2421
					if($wlcfg['auth_server_port'])
2422 2422
						$auth_server_port = $wlcfg['auth_server_port'];
2423 2423
					$auth_server_port2 = "1812";
2424
					if($wlcfg['auth_server_port2']) 
2424
					if($wlcfg['auth_server_port2'])
2425 2425
						$auth_server_port2 = $wlcfg['auth_server_port2'];
2426 2426
					$wpa .= <<<EOD
2427 2427

  
......
2586 2586
	$wlcmd_args = implode(" ", $wlcmd);
2587 2587
	mwexec("/sbin/ifconfig {$if} $wlcmd_args", false);
2588 2588

  
2589
	
2589

  
2590 2590
	sleep(1);
2591 2591
	/* execute hostapd and wpa_supplicant if required in shell */
2592 2592
	mwexec("/bin/sh {$g['tmp_path']}/{$if}_setup.sh");
......
2639 2639
	/* Disable Accepting router advertisements unless specifically requested */
2640 2640
	log_error("Deny router advertisements for interface {$interface}");
2641 2641
	mwexec("/sbin/ifconfig " . escapeshellarg($realif) . " inet6 -accept_rtadv");
2642
			
2642

  
2643 2643
	if (!$g['booting'] && !(substr($realif, 0, 4) == "ovpn")) {
2644 2644
		/* remove all IPv4 and IPv6 addresses */
2645 2645
		while (mwexec("/sbin/ifconfig " . escapeshellarg($realif) . " -alias", true) == 0);
......
2657 2657

  
2658 2658
	$mac = get_interface_mac($realhwif);
2659 2659
	/*	Don't try to reapply the spoofed MAC if it's already applied.
2660
		When ifconfig link is used, it cycles the interface down/up, which triggers 
2661
		the interface config again, which attempts to spoof the MAC again, 
2660
		When ifconfig link is used, it cycles the interface down/up, which triggers
2661
		the interface config again, which attempts to spoof the MAC again,
2662 2662
		which cycles the link again... */
2663 2663
	if ($wancfg['spoofmac'] && ($wancfg['spoofmac'] != $mac)) {
2664 2664
		mwexec("/sbin/ifconfig " . escapeshellarg($realhwif) .
......
2823 2823
		interfaces_bring_up($wancfg['if']);
2824 2824

  
2825 2825
	interface_netgraph_needed($interface);
2826
 	
2826

  
2827 2827
	if (!$g['booting']) {
2828 2828
		link_interface_to_vips($interface, "update");
2829 2829

  
......
2884 2884
		$wancfg = array();
2885 2885

  
2886 2886
	$wanif = get_real_interface($interface);
2887
	
2887

  
2888 2888
	/* If the interface is not configured via another, exit */
2889 2889
	if(!$wancfg['track6-interface'] <> "") {
2890 2890
		return(false);
......
2926 2926
		$lancfg = array();
2927 2927

  
2928 2928
	$lanif = get_real_interface($interface);
2929
	
2929

  
2930 2930
	/* If the interface is not configured via another, exit */
2931 2931
	if(!$lancfg['track6-interface'] <> "") {
2932 2932
		return(false);
2933 2933
	}
2934 2934
	if(!is_numeric($lancfg['track6-prefix-id']))
2935 2935
		$lancfg['track6-prefix-id'] = 0;
2936
	
2936

  
2937 2937
	$wancfg = $config['interfaces'][$lancfg['track6-interface']];
2938 2938
	$wanif = $wancfg['if'];
2939 2939
	if (empty($wancfg))
2940 2940
		$wancfg = array();
2941
	
2941

  
2942 2942
	$ip4address = find_interface_ip($wanif);
2943 2943
	if((!is_ipaddrv4($ip4address)) || (is_private_ip($ip4address))) {
2944 2944
		log_error("The interface IPv4 '{$ip4address}' address on interface '{$wanif}' is not public, not configuring 6RD tunnel");
2945 2945
		return false;
2946 2946
	}
2947 2947
	$hexwanv4 = return_hex_ipv4($ip4address);
2948
	
2948

  
2949 2949
	/* create the long prefix notation for math, save the prefix length */
2950 2950
	$rd6prefix = explode("/", $wancfg['prefix-6rd']);
2951 2951
	$rd6prefixlen = $rd6prefix[1];
......
2953 2953

  
2954 2954
	/* binary presentation of the prefix for all 128 bits. */
2955 2955
	$rd6lanbin = convert_ipv6_to_128bit($rd6prefix);
2956
	
2956

  
2957 2957
	/* just save the left prefix length bits */
2958 2958
	$rd6lanbin = substr($rd6lanbin, 0, $rd6prefixlen);
2959 2959
	/* add the v4 address, offset n bits from the left */
......
2967 2967
	/* fill the rest out with zeros */
2968 2968
	$rd6lanbin = str_pad($rd6lanbin, 128, "0", STR_PAD_RIGHT);;
2969 2969

  
2970
	/* convert the 128 bits for the lan address back into a valid IPv6 address */ 
2970
	/* convert the 128 bits for the lan address back into a valid IPv6 address */
2971 2971
	$rd6lan = convert_128bit_to_ipv6($rd6lanbin) ."1";
2972
	
2972

  
2973 2973
	log_error("rd6 {$interface} with ipv6 address {$rd6lan} based on {$lancfg['track6-interface']} ipv4 {$ip4address}");
2974 2974
	mwexec("/sbin/ifconfig {$lanif} inet6 {$rd6lan} prefixlen 64");
2975 2975
	return 0;
......
2985 2985
		$lancfg = array();
2986 2986

  
2987 2987
	$lanif = get_real_interface($interface);
2988
	
2988

  
2989 2989
	/* If the interface is not configured via another, exit */
2990 2990
	if(!$lancfg['track6-interface'] <> "") {
2991 2991
		return(false);
2992 2992
	}
2993 2993
	if(!is_numeric($lancfg['track6-prefix-id']))
2994 2994
		$lancfg['track6-prefix-id'] = 0;
2995
	
2995

  
2996 2996
	$wancfg = $config['interfaces'][$lancfg['track6-interface']];
2997 2997
	$wanif = $wancfg['if'];
2998 2998
	if (empty($wancfg))
2999 2999
		$wancfg = array();
3000
	
3000

  
3001 3001
	$ip4address = find_interface_ip($wanif);
3002 3002
	if((!is_ipaddrv4($ip4address)) || (is_private_ip($ip4address))) {
3003 3003
		log_error("The interface IPv4 '{$ip4address}' address on interface '{$wanif}' is not public, not configuring 6RD tunnel");
3004 3004
		return false;
3005 3005
	}
3006 3006
	$hexwanv4 = return_hex_ipv4($ip4address);
3007
	
3007

  
3008 3008
	/* create the long prefix notation for math, save the prefix length */
3009 3009
	$sixto4prefix = "2002::";
3010 3010
	$sixto4prefixlen = 16;
......
3012 3012

  
3013 3013
	/* binary presentation of the prefix for all 128 bits. */
3014 3014
	$sixto4lanbin = convert_ipv6_to_128bit($sixto4prefix);
3015
	
3015

  
3016 3016
	/* just save the left prefix length bits */
3017 3017
	$sixto4lanbin = substr($sixto4lanbin, 0, $sixto4prefixlen);
3018 3018
	/* add the v4 address */
......
3021 3021
	$sixto4lanbin .= sprintf("%016b", $lancfg['track6-prefix-id']);
3022 3022
	/* fill the rest out with zeros */
3023 3023
	$sixto4lanbin = str_pad($sixto4lanbin, 128, "0", STR_PAD_RIGHT);;
3024
	
3025
	/* convert the 128 bits for the lan address back into a valid IPv6 address */ 
3024

  
3025
	/* convert the 128 bits for the lan address back into a valid IPv6 address */
3026 3026
	$sixto4lan = convert_128bit_to_ipv6($sixto4lanbin) ."1";
3027
	
3027

  
3028 3028
	log_error("sixto4 {$interface} with ipv6 address {$sixto4lan} based on {$lancfg['track6-interface']} ipv4 {$ip4address}");
3029 3029
	mwexec("/sbin/ifconfig {$lanif} inet6 {$sixto4lan} prefixlen 64");
3030 3030
	return 0;
......
3040 3040
		$lancfg = array();
3041 3041

  
3042 3042
	$lanif = get_real_interface($interface);
3043
	
3043

  
3044 3044
	/* If the interface is not configured via another, exit */
3045 3045
	if(!$lancfg['track6-interface'] <> "") {
3046 3046
		return(false);
3047 3047
	}
3048 3048
	if(!is_numeric($lancfg['track6-prefix-id']))
3049 3049
		$lancfg['track6-prefix-id'] = 0;
3050
	
3050

  
3051 3051
	$wancfg = $config['interfaces'][$lancfg['track6-interface']];
3052 3052
	$wanif = $wancfg['if'];
3053 3053
	if (empty($wancfg))
3054 3054
		$wancfg = array();
3055
	
3056
	
3055

  
3056

  
3057 3057
	$ifcfgipv6 = find_interface_ipv6($lanif);
3058 3058
	if(is_ipaddrv6($ifcfgipv6)) {
3059 3059
		$dhcp6lanarr = explode(":", Net_IPv6::uncompress($ifcfgipv6));
......
3072 3072
	global $config, $g;
3073 3073
	$iflist = get_configured_interface_with_descr(false, true);
3074 3074

  
3075
	/* because this is a tunnel interface we can only function 
3075
	/* because this is a tunnel interface we can only function
3076 3076
	 *	with a public IPv4 address on the interface */
3077 3077

  
3078 3078
	$wancfg = $config['interfaces'][$interface];
......
3081 3081
		$wancfg = array();
3082 3082

  
3083 3083
	$wanif = get_real_interface($interface);
3084
	
3084

  
3085 3085
	$ip4address = find_interface_ip($wanif);
3086 3086
	$ip4gateway = get_interface_gateway($wanif);
3087 3087
	if((!is_ipaddrv4($ip4address)) || (is_private_ip($ip4address))) {
......
3089 3089
		return false;
3090 3090
	}
3091 3091
	$hexwanv4 = return_hex_ipv4($ip4address);
3092
	
3092

  
3093 3093
	if(!is_numeric($wancfg['prefix-6rd-v4plen']))
3094 3094
		$wancfg['prefix-6rd-v4plen'] = 0;
3095 3095

  
......
3100 3100

  
3101 3101
	/* we need the hex form of the broker IPv4 address */
3102 3102
	$hexbrv4 = return_hex_ipv4($wancfg['gateway-6rd']);
3103
	
3103

  
3104 3104
	/* binary presentation of the prefix for all 128 bits. */
3105 3105
	$rd6prefixbin = convert_ipv6_to_128bit($rd6prefix);
3106
		
3106

  
3107 3107
	/* just save the left prefix length bits */
3108 3108
	$rd6brprefixbin = substr($rd6prefixbin, 0, $rd6prefixlen);
3109 3109
	/* if the prefix length is not 32 bits we need to shave bits off from the left of the v4 address. */
......
3111 3111
	/* fill out the rest with 0's */
3112 3112
	$rd6brprefixbin = str_pad($rd6brprefixbin, 128, "0", STR_PAD_RIGHT);;
3113 3113

  
3114
	/* convert the 128 bits for the broker address back into a valid IPv6 address */ 
3114
	/* convert the 128 bits for the broker address back into a valid IPv6 address */
3115 3115
	$rd6brgw = convert_128bit_to_ipv6($rd6brprefixbin);
3116 3116

  
3117 3117
	/* just save the left prefix length bits */
......
3121 3121
	/* fill out the rest with 0's */
3122 3122
	$rd6prefixbin = str_pad($rd6prefixbin, 128, "0", STR_PAD_RIGHT);;
3123 3123

  
3124
	/* convert the 128 bits for the broker address back into a valid IPv6 address */ 
3124
	/* convert the 128 bits for the broker address back into a valid IPv6 address */
3125 3125
	$rd6prefix = convert_128bit_to_ipv6($rd6prefixbin);
3126 3126

  
3127 3127
	/* stf approach only works when embedding the entire 32 bits of the v4 */
......
3150 3150
	global $config, $g;
3151 3151
	$iflist = get_configured_interface_with_descr(false, true);
3152 3152

  
3153
	/* because this is a tunnel interface we can only function 
3153
	/* because this is a tunnel interface we can only function
3154 3154
	 *	with a public IPv4 address on the interface */
3155 3155

  
3156 3156
	$wancfg = $config['interfaces'][$interface];
......
3159 3159
		$wancfg = array();
3160 3160

  
3161 3161
	$wanif = get_real_interface($interface);
3162
	
3162

  
3163 3163
	$ip4address = find_interface_ip($wanif);
3164 3164
	$ip4gateway = get_interface_gateway($wanif);
3165 3165
	if((!is_ipaddrv4($ip4address)) || (is_private_ip($ip4address))) {
3166 3166
		log_error("The interface IPv4 '{$ip4address}' address on interface '{$wanif}' is not public, not configuring 6RD tunnel");
3167 3167
		return false;
3168 3168
	}
3169
	
3169

  
3170 3170
	/* create the long prefix notation for math, save the prefix length */
3171 3171
	$stfprefixlen = 16;
3172 3172
	$stfprefix = Net_IPv6::uncompress("2002::");
3173 3173
	$stfarr = explode(":", $stfprefix);
3174 3174
	$v4prefixlen = "0";
3175
	
3175

  
3176 3176
	/* we need the hex form of the interface IPv4 address */
3177 3177
	$ip4arr = explode(".", $ip4address);
3178 3178
	$hexwanv4 = "";
......
3184 3184
	$hexbrv4 = "";
3185 3185
	foreach($ip4arr as $octet)
3186 3186
		$hexbrv4 .= sprintf("%02x", $octet);
3187
	
3187

  
3188 3188
	/* binary presentation of the prefix for all 128 bits. */
3189 3189
	$stfprefixbin = "";
3190 3190
	foreach($stfarr as $element) {
......
3201 3201
	$stflanbin = substr(sprintf("%032b", hexdec($hexwanv4)), $v4prefixlen, 32);
3202 3202
	$stflanbin = str_pad($stfprefixstartbin . $stflanbin, 128, "0", STR_PAD_RIGHT);;
3203 3203

  
3204
	/* convert the 128 bits for the broker address back into a valid IPv6 address */ 
3204
	/* convert the 128 bits for the broker address back into a valid IPv6 address */
3205 3205
	$stfbrarr = array();
3206 3206
	$stfbrbinarr = array();
3207 3207
	$stfbrbinarr = str_split($stfbrokerbin, 16);
......
3209 3209
		$stfbrarr[] = dechex(bindec($bin));
3210 3210
	$stfbrgw = Net_IPv6::compress(implode(":", $stfbrarr));
3211 3211

  
3212
	/* convert the 128 bits for the broker address back into a valid IPv6 address */ 
3212
	/* convert the 128 bits for the broker address back into a valid IPv6 address */
3213 3213
	$stflanarr = array();
3214 3214
	$stflanbinarr = array();
3215 3215
	$stflanbinarr = str_split($stflanbin, 16);
......
3226 3226
	mwexec("/sbin/ifconfig stf0 inet6 {$stflanpr} prefixlen 16");
3227 3227

  
3228 3228
	log_error("Set IPv6 address inet6 {$stflanpr} prefixlen 16 for stf0, route {$stfbrgw}");
3229
	
3229

  
3230 3230
	/* write out a default router file */
3231 3231
	file_put_contents("{$g['tmp_path']}/{$wanif}_routerv6", "{$stfbrgw}");
3232 3232
	file_put_contents("{$g['tmp_path']}/{$wanif}_defaultgwv6", "{$stfbrgw}");
......
3240 3240
		if($config['interfaces'][$if]['track6-interface'] == $interface)
3241 3241
			interface_track6_configure($if);
3242 3242
	}
3243
	
3243

  
3244 3244
	return 0;
3245 3245
}
3246 3246

  
......
3273 3273
		$dhcp6cconf .= "	script \"{$g['varetc_path']}/dhcp6c_{$interface}_script.sh\"; # we'd like some nameservers please\n";
3274 3274
		$dhcp6cconf .= "};\n";
3275 3275
	} else {
3276
	
3276

  
3277 3277
		$dhcp6cconf .= " 	send ia-na 0;	# request stateful address\n";
3278 3278
		if(is_numeric($wancfg['dhcp6-ia-pd-len'])) {
3279 3279
			$dhcp6cconf .= "	send ia-pd 0;	# request prefix delegation\n";
......
3385 3385
		return 0;
3386 3386
	}
3387 3387
 	$dhclientconf = "";
3388
	
3388

  
3389 3389
	$dhclientconf .= <<<EOD
3390 3390
interface "{$wanif}" {
3391 3391
timeout 60;
......
3415 3415
	/* bring wan interface up before starting dhclient */
3416 3416
	if($wanif)
3417 3417
		interfaces_bring_up($wanif);
3418
	else 
3418
	else
3419 3419
		log_error(printf(gettext("Could not bring up %s interface in interface_dhcp_configure()"), $wanif));
3420 3420

  
3421 3421
	/* fire up dhclient */
......
3455 3455
	$interface = get_real_interface($interface);
3456 3456
	mwexec("/sbin/ifconfig {$interface} group {$groupname}", true);
3457 3457
}
3458
 
3458

  
3459 3459
/* COMPAT Function */
3460 3460
function convert_friendly_interface_to_real_interface_name($interface) {
3461 3461
	return get_real_interface($interface);
......
3592 3592

  
3593 3593
	// If we got a real interface, find it's friendly assigned name
3594 3594
	$interface = convert_real_interface_to_friendly_interface_name($interface);
3595
		
3595

  
3596 3596
	if (!empty($interface) && isset($config['interfaces'][$interface])) {
3597 3597
		$ifcfg = $config['interfaces'][$interface];
3598 3598
		switch ($ifcfg['ipaddr']) {
......
3605 3605
						foreach ($config['ppps']['ppp'] as $pppidx => $ppp) {
3606 3606
							if ($ifcfg['if'] == $ppp['if']) {
3607 3607
								$ports = explode(',', $ppp['ports']);
3608
								foreach ($ports as $pid => $parent_if) 
3608
								foreach ($ports as $pid => $parent_if)
3609 3609
									$parents[$pid] = get_real_interface($parent_if);
3610 3610
								break;
3611 3611
							}
......
3616 3616
			default:
3617 3617
				// Handle _vlans
3618 3618
				if (strstr($realif,"_vlan"))
3619
					if (is_array($config['vlans']['vlan'])) 
3619
					if (is_array($config['vlans']['vlan']))
3620 3620
						foreach ($config['vlans']['vlan'] as $vlanidx => $vlan)
3621 3621
							if ($ifcfg['if'] == $vlan['vlanif']){
3622 3622
								$parents[0] = $vlan['if'];
......
3625 3625
				break;
3626 3626
		}
3627 3627
	}
3628
	
3628

  
3629 3629
	if (empty($parents))
3630 3630
		$parents[0] = $realif;
3631
	
3631

  
3632 3632
	return $parents;
3633 3633
}
3634 3634

  
......
3711 3711
		*/
3712 3712

  
3713 3713
		switch ($cfg['ipaddr']) {
3714
			case "pppoe": 
3715
			case "pptp": 
3716
			case "l2tp": 
3714
			case "pppoe":
3715
			case "pptp":
3716
			case "l2tp":
3717 3717
			case "ppp":
3718 3718
				$wanif = $cfg['if'];
3719 3719
				break;
......
3772 3772
{
3773 3773
	/* if list */
3774 3774
	$ifdescrs = get_configured_interface_list();
3775
		
3775

  
3776 3776
	foreach ($ifdescrs as $ifdescr => $ifname) {
3777 3777
		if ($bits === null) {
3778 3778
			if ($ip == get_interface_ip($ifname)) {
......
4035 4035
	global $interface_sn_arr_cache;
4036 4036

  
4037 4037
	$interface = str_replace("\n", "", $interface);
4038
	
4038

  
4039 4039
	if (!does_interface_exist($interface))
4040 4040
		return;
4041 4041

  
......
4057 4057
	global $interface_ipv6_arr_cache;
4058 4058
	global $interface_snv6_arr_cache;
4059 4059
	global $config;
4060
	
4060

  
4061 4061
	$interface = trim($interface);
4062 4062
	$interface = get_real_interface($interface);
4063
	
4063

  
4064 4064
	if (!does_interface_exist($interface))
4065 4065
		return;
4066 4066

  
......
4097 4097
{
4098 4098
	global $interface_llv6_arr_cache;
4099 4099
	global $config;
4100
	
4100

  
4101 4101
	$interface = str_replace("\n", "", $interface);
4102
	
4102

  
4103 4103
	if (!does_interface_exist($interface))
4104 4104
		return;
4105 4105

  
......
4666 4666
			$wanif = $a_groups[$interface][0]['vip'];
4667 4667
		else
4668 4668
			$wanif = $a_groups[$interface][0]['int'];
4669
		
4669

  
4670 4670
		return $wanif;
4671 4671
	}
4672 4672
	/* fall through to get_real_interface */

Also available in: Unified diff