Project

General

Profile

« Previous | Next » 

Revision 5daccf2d

Added by Reid Linnemann almost 3 years ago

Fix undefined and unused variable warnings in interfaces.inc

Notes: * interfaces_tunnel_configure() * loop continue on address type "track6" never hit, defined variable is
'$ipaddrv6' but was referred to as '$ipaddr6' * interface_bring_down() * '$old_router' was populated with the contents of a file but never used * interface_ppps_configure() * no such variables '$dhcp_gateway' and '$gway' in log_error() when
'$gateways[$pid]' is not an ip address. This looks like a copy/paste bogon,
replaced the variables with what seemed to be appropriate bits from the
pppoe configuration - the local ip for the pid and the gateway for the ppp
link * interface_wireless_configure() * Missing variables '$wpa_supplicant_crt' and '$wpa_supplicant_key' defined
to match the composed cert and key file names given file_put_contents().
Previously the chmod()s would do nothing * Missing variable '$wpa_supplicant_ca' defined according to the composed
file name given to file_put_contents(). Previously the wpa_supplicant
config would have an empty ca_cert path * run_dhcp6client_process() * parameter '$debugOption' referred to as '$debugOptions' within the function * interface_track6_configure() * Missing '$type', which should be the switched $trackcfg['ipaddrv6'] value * interface_dhcpv6_configure() * No variable $ifdescr, replaced with $interface (logical interface name) * get_configured_vip_list_with_descr * No variable $vipid, $vipid defined as the iterated index and $vip the
configured vip gotten from get_configured_vip. Previously the configured
vip list returnd would likely be empty * restart_interface_services() * No variable $realif, replaced with interface 'if' attribute from config

View differences:

src/etc/inc/interfaces.inc
31 31
require_once("gwlb.inc");
32 32
require_once("ipsec.inc");
33 33
require_once("vpn.inc");
34
require_once("Net/IPv6.php");
34 35

  
35 36
function interfaces_bring_up($interface) {
36 37
	if (!$interface) {
......
81 82
 * detected.
82 83
 */
83 84
function does_interface_exist($interface, $flush = false) {
84
	global $config;
85

  
86 85
	if (!$interface) {
87 86
		return false;
88 87
	}
......
100 99
 * configured.
101 100
 */
102 101
function does_vip_exist($vip) {
103
	global $config;
104

  
105 102
	if (!$vip) {
106 103
		return false;
107 104
	}
......
144 141
}
145 142

  
146 143
function interfaces_loopback_configure() {
147
	global $g;
148

  
149 144
	if (platform_booting()) {
150 145
		echo gettext("Configuring loopback interface...");
151 146
		mute_kernel_msgs();
......
197 192
}
198 193

  
199 194
function interface_is_qinq($if = NULL) {
200
	global $config;
201

  
202
	if ($if == NULL || empty($if) || !is_array($config['qinqs']['qinqentry'])) {
195
	if (!$if) {
203 196
		return (NULL);
204 197
	}
205 198

  
......
210 203
		return (NULL);
211 204
	}
212 205

  
213
	foreach ($config['qinqs']['qinqentry'] as $qinqidx => $qinq) {
206
	foreach (config_get_path('qinqs/qinqentry', []) as $qinq) {
214 207
		if ("{$qinqif}.{$vlantag}" != $qinq['vlanif']) {
215 208
			continue;
216 209
		}
......
245 238
}
246 239

  
247 240
function interface_is_vlan($if = NULL) {
248
	global $config;
249

  
250 241
	if ($if == NULL || empty($if) || is_array($if)) {
251 242
		return (NULL);
252 243
	}
......
260 251
	}
261 252

  
262 253
	/* Find the VLAN interface. */
263
	if (isset($config['vlans']['vlan']) && is_array($config['vlans']['vlan'])) {
264
		foreach ($config['vlans']['vlan'] as $vlanidx => $vlan) {
265
			if ($if == $vlan['vlanif']) {
266
				return ($vlan);
267
			}
254
	foreach (config_get_path('vlans/vlan', []) as $vlan) {
255
		if ($if == $vlan['vlanif']) {
256
			return ($vlan);
268 257
		}
269 258
	}
270 259

  
271 260
	/* Check for the first level tag in QinQ interfaces. */
272
	if (isset($config['qinqs']['qinqentry']) && is_array($config['qinqs']['qinqentry'])) {
273
		foreach ($config['qinqs']['qinqentry'] as $qinqidx => $qinq) {
274
			if ($if == $qinq['vlanif']) {
275
				return ($qinq);
276
			}
261
	foreach (config_get_path('qinqs/qinqentry', []) as $qinq) {
262
		if ($if == $qinq['vlanif']) {
263
			return ($qinq);
277 264
		}
278 265
	}
279 266

  
......
368 355
}
369 356

  
370 357
function interfaces_vlan_configure($parentif = "") {
371
	global $config, $g;
372 358
	$dhcp6c_list = array();
373 359

  
374 360
	$vlans = config_get_path('vlans/vlan');
......
386 372
			/* configure dhcp6 enabled VLAN interfaces later
387 373
			 * see https://redmine.pfsense.org/issues/3965 */
388 374
			$if = convert_real_interface_to_friendly_interface_name($vlan['vlanif']);
389
			$ipaddvr6 = config_get_path("interfaces/{$if}/ipaddrv6");
390
			if (!empty($ipaddrv6) && $ipaddrv6 == "dhcp6") {
375
			if (config_get_path("interfaces/{$if}/ipaddrv6", "") == "dhcp6") {
391 376
				$dhcp6c_list[$if] = $vlan;
392 377
				continue;
393 378
			}
......
407 392
}
408 393

  
409 394
function interface_vlan_configure(&$vlan, $flush = true) {
410
	global $config, $g;
411

  
412 395
	if (!is_array($vlan)) {
413 396
		log_error(gettext("VLAN: called with wrong options. Problems with config!"));
414 397
		return(NULL);
......
492 475
			continue;
493 476
		}
494 477
		// PPP interfaces must be restarted to adjust MTU changes
495
		foreach ($config['ppps']['ppp'] as $pppid => $ppp) {
478
		foreach (config_get_path('ppps/ppp') as $ppp) {
496 479
			$ports = explode(',', $ppp['ports']);
497
			foreach ($ports as $pid => $port) {
480
			foreach ($ports as $port) {
498 481
				if ($port != $vlan['vlanif']) {
499 482
					continue;
500 483
				}
......
506 489
}
507 490

  
508 491
function interface_qinq_configure(&$qinq, $fd = NULL, $flush = true) {
509
	global $config, $g;
492
	global $g;
510 493

  
511 494
	if (!is_array($qinq)) {
512 495
		log_error(sprintf(gettext("QinQ compat VLAN: called with wrong options. Problems with config!%s"), "\n"));
......
514 497
	}
515 498

  
516 499
	$qinqif = $qinq['if'];
517
	$tag = $qinq['tag'];
518 500
	if (empty($qinqif)) {
519 501
		log_error(sprintf(gettext("interface_qinq_configure called with if undefined.%s"), "\n"));
520 502
		return;
......
597 579
}
598 580

  
599 581
function interfaces_qinq_configure($ovpn=false) {
600
	global $config, $g;
601

  
602 582
	$qinqentry = config_get_path('qinqs/qinqentry');
603 583
	if (is_array($qinqentry) && count($qinqentry)) {
604 584
		if (platform_booting() && $ovpn) {
......
621 601
}
622 602

  
623 603
function interface_qinq2_configure(&$qinq, &$cmdbuf, $macaddr, $flush = true) {
624
	global $config, $g;
625

  
626 604
	if (!is_array($qinq)) {
627 605
		log_error(sprintf(gettext("QinQ compat VLAN: called with wrong options. Problems with config!%s"), "\n"));
628 606
		return;
......
658 636
}
659 637

  
660 638
function interfaces_create_wireless_clones() {
661
	global $config, $g;
639
	global $config;
662 640

  
663 641
	$iflist = get_configured_interface_list();
664 642

  
......
738 716
}
739 717

  
740 718
function interface_bridge_configure(&$bridge, $checkmember = 0, $flush = true) {
741
	global $config, $g;
742

  
743 719
	if (!is_array($bridge)) {
744 720
		return;
745 721
	}
......
1118 1094

  
1119 1095
/* NOTE: $grekey is not used but useful for passing this function to array_walk. */
1120 1096
function interface_gre_configure(&$gre, $grekey = "", $flush = true) {
1121
	global $config, $g;
1097
	global $g;
1122 1098

  
1123 1099
	if (!is_array($gre)) {
1124 1100
		return -1;
......
1416 1392
				continue;
1417 1393
			}
1418 1394

  
1419
			if ($ipaddr6 == "track6") {
1395
			if ($ipaddrv6 == "track6") {
1420 1396
				continue;
1421 1397
			}
1422 1398
		} elseif ($checkparent == 2) {
......
1439 1415

  
1440 1416
/* Build a list of IPsec interfaces */
1441 1417
function interface_ipsec_vti_list_p1($ph1ent) {
1442
	global $config;
1443 1418
	$iface_list = array();
1444 1419

  
1445 1420
	if (empty($ph1ent) || !is_array($ph1ent) || !is_array(config_get_path('ipsec/phase2'))) {
......
1484 1459
	if (($vtisubnet_spec && is_array($vtisubnet_spec))) {
1485 1460
		/* With IKEv1 or v2+Split, each P2 gets its own conn/reqid/interface */
1486 1461
		if (!isset($phase1['mobile']) && ($phase1['iketype'] == 'ikev1' || isset($phase1['splitconn']))) {
1487
			foreach ($vtisubnet_spec as $idx => $vtisub) {
1462
			foreach ($vtisubnet_spec as $vtisub) {
1488 1463
				/* Is this for this P2? */
1489 1464
				if (($vtisub['left'] == ipsec_idinfo_to_cidr($phase2['localid'], true, $phase2['mode'])) &&
1490 1465
				    ($vtisub['right'] == ipsec_idinfo_to_cidr($phase2['remoteid'], false, $phase2['mode']))) {
......
1525 1500
	/* With IKEv1 or v2+Split, each P2 gets its own conn/reqid/interface */
1526 1501
	if (!isset($ph1ent['mobile']) && ($ph1ent['iketype'] == 'ikev1' || isset($ph1ent['splitconn']))) {
1527 1502
		/* Form a single interface for each P2 entry */
1528
		foreach ($vtisubnet_spec as $idx => $vtisub) {
1503
		foreach ($vtisubnet_spec as $vtisub) {
1529 1504
			$ipsecif = ipsec_get_ifname($ph1ent, $vtisub['reqid']);
1530 1505
			if (!is_array($iface_addrs[$ipsecif])) {
1531 1506
				$iface_addrs[$ipsecif] = array();
......
1618 1593

  
1619 1594
function interfaces_ipsec_vti_configure($gateways_status = false) {
1620 1595
	global $config;
1596
	$bootmsg = false;
1621 1597

  
1622 1598
	/* Fetch gateway status if not passed */
1623 1599
	if (!is_array($gateways_status)) {
......
1924 1900
		case "pptp":
1925 1901
		case "l2tp":
1926 1902
			if (is_array($ppps) && count($ppps)) {
1927
				foreach ($ppps as $pppid => $ppp) {
1903
				foreach ($ppps as  $ppp) {
1928 1904
					if ($realif == $ppp['if']) {
1929 1905
						if (isset($ppp['ondemand']) && !$destroy) {
1930 1906
							send_event("interface reconfigure {$interface}");
......
2031 2007
		services_dhcpd_configure('inet6', $track6);
2032 2008
	}
2033 2009

  
2034
	$old_router = '';
2035
	if (file_exists("{$g['tmp_path']}/{$realif}_router")) {
2036
		$old_router = trim(file_get_contents("{$g['tmp_path']}/{$realif}_router"));
2037
	}
2038

  
2039 2010
	/* remove interface up file if it exists */
2040 2011
	unlink_if_exists("{$g['tmp_path']}/{$realif}up");
2041 2012
	unlink_if_exists("{$g['vardb_path']}/{$interface}ip");
......
2119 2090
}
2120 2091

  
2121 2092
function interface_isppp_type($interface) {
2122
	global $config;
2123

  
2124 2093
	$iface = config_get_path("interfaces/{$interface}");
2125 2094
	if (!is_array($iface)) {
2126 2095
		return false;
......
2140 2109
}
2141 2110

  
2142 2111
function interfaces_ptpid_used($ptpid) {
2143
	global $config;
2144

  
2145 2112
	$ppps = config_get_path('ppps/ppp');
2146 2113
	if (is_array($ppps)) {
2147 2114
		foreach ($ppps as $settings) {
......
2155 2122
}
2156 2123

  
2157 2124
function interfaces_ptpid_next() {
2158

  
2159 2125
	$ptpid = 0;
2160 2126
	while (interfaces_ptpid_used($ptpid)) {
2161 2127
		$ptpid++;
......
2165 2131
}
2166 2132

  
2167 2133
function getMPDCRONSettings($pppif) {
2168
	global $config, $g;
2134
	global $g;
2169 2135

  
2170 2136
	$cron_cmd_file = "{$g['varetc_path']}/pppoe_restart_{$pppif}";
2171
	$items = config_get_path('cron/item');
2172
	if (is_array($items)) {
2173
		foreach ($item as $i => $item) {
2174
			if (stripos($item['command'], $cron_cmd_file) !== false) {
2175
				return array("ID" => $i, "ITEM" => $item);
2176
			}
2137
	foreach (config_get_path('cron/item', []) as $i => $item) {
2138
		if (stripos($item['command'], $cron_cmd_file) !== false) {
2139
			return array("ID" => $i, "ITEM" => $item);
2177 2140
		}
2178 2141
	}
2179 2142

  
......
2266 2229
}
2267 2230

  
2268 2231
function restart_ppp_interfaces_using_interfaces($triggerinterfaces) {
2269
	global $config;
2270 2232
	$ppp_list = array();
2271
	$ppps = config_get_path('ppps/ppp');
2272
	if (is_array($ppps) && count($ppps)) {
2273
		foreach ($ppps as $pppid => $ppp) {
2274
			$ports = explode(",", $ppp['ports']);
2275
			foreach($ports as $port) {
2276
				foreach($triggerinterfaces as $vip) {
2277
					if ($port == "_vip{$vip['uniqid']}") {
2278
						$if = convert_real_interface_to_friendly_interface_name($ppp['if']);
2279
						$ppp_list[$if] = 1;
2280
					}
2233
	foreach (config_get_path('ppps/ppp', []) as $ppp) {
2234
		$ports = explode(",", $ppp['ports']);
2235
		foreach($ports as $port) {
2236
			foreach($triggerinterfaces as $vip) {
2237
				if ($port == "_vip{$vip['uniqid']}") {
2238
					$if = convert_real_interface_to_friendly_interface_name($ppp['if']);
2239
					$ppp_list[$if] = 1;
2281 2240
				}
2282 2241
			}
2283 2242
		}
2284 2243
	}
2285
	foreach($ppp_list as $pppif => $dummy) {
2244
	foreach(array_keys($ppp_list) as $pppif) {
2286 2245
		interface_ppps_configure($pppif);
2287 2246
	}
2288 2247
}
......
2313 2272
		@symlink("/usr/local/sbin/mpd.script", "{$g['varetc_path']}/mpd.script");
2314 2273
	}
2315 2274

  
2275
	$pppid = "";
2276
	$ppp = array();
2316 2277
	$ppps = config_get_path('ppps/ppp');
2317 2278
	if (is_array($ppps) && count($ppps)) {
2318 2279
		foreach ($ppps as $pppid => $ppp) {
......
2331 2292
	} else {
2332 2293
		$type = $ppp['type'];
2333 2294
	}
2334
	$upper_type = strtoupper($ppp['type']);
2335 2295

  
2336 2296
	$confports = explode(',', $ppp['ports']);
2337 2297
	if ($type == "modem") {
......
2385 2345
					$gateways[$pid] = gethostbyname($gateways[$pid]);
2386 2346
				}
2387 2347
				if (!is_ipaddr($gateways[$pid])) {
2388
					log_error(sprintf(gettext('Could not get a PPTP/L2TP Remote IP address from %1$s for %2$s in interfaces_ppps_configure.'), $dhcp_gateway, $gway));
2348
					log_error(sprintf(gettext('Could not get a PPTP/L2TP Remote IP address from %1$s for %2$s in interfaces_ppps_configure.'), $localips[$pid], $ppp['gateway']));
2389 2349
					return 0;
2390 2350
				}
2391 2351
				break;
......
2873 2833
}
2874 2834

  
2875 2835
function interfaces_sync_setup() {
2876
	global $g, $config;
2836
	global $config;
2877 2837

  
2878 2838
	if (config_get_path('system/developerspew')) {
2879 2839
		$mt = microtime();
......
2923 2883
		$i = 0;
2924 2884
		do {
2925 2885
			sleep(1);
2926
			$_gb = exec('/sbin/ifconfig pfsync0 | ' .
2927
			    '/usr/bin/grep -q "syncok: 0" 2>/dev/null', $output,
2928
			    $rc);
2886
			exec('/sbin/ifconfig pfsync0 | ' .
2887
				 '/usr/bin/grep -q "syncok: 0" 2>/dev/null', $output,
2888
				 $rc);
2929 2889
			$i++;
2930 2890
		} while ($rc != 0 && $i <= 30);
2931 2891

  
......
2949 2909
}
2950 2910

  
2951 2911
function interface_proxyarp_configure($interface = "") {
2952
	global $config, $g;
2912
	global $g;
2953 2913
	if (config_get_path('system/developerspew')) {
2954 2914
		$mt = microtime();
2955 2915
		echo "interface_proxyarp_configure() being called $mt\n";
......
3031 2991
}
3032 2992

  
3033 2993
function interface_vip_cleanup($interface, $inet = "all", $type = VIP_ALL) {
3034
	global $g, $config;
3035

  
3036 2994
	$vips = config_get_path('virtualip/vip');
3037 2995
	if (is_array($vips)) {
3038 2996
		foreach ($vips as $vip) {
......
3064 3022
}
3065 3023

  
3066 3024
function interfaces_vips_configure($interface = "") {
3067
	global $g, $config;
3068 3025
	if (config_get_path('system/developerspew')) {
3069 3026
		$mt = microtime();
3070 3027
		echo "interfaces_vips_configure() being called $mt\n";
......
3110 3067
}
3111 3068

  
3112 3069
function interface_ipalias_configure(&$vip) {
3113
	global $config;
3114

  
3115 3070
	$gateway = '';
3116 3071
	if ($vip['mode'] != 'ipalias') {
3117 3072
		return;
......
3148 3103
}
3149 3104

  
3150 3105
function interface_carp_configure(&$vip, $maintenancemode_only = false, $ipalias_reload = false) {
3151
	global $config, $g;
3106
	global $config;
3152 3107
	if (config_get_path('system/developerspew')) {
3153 3108
		$mt = microtime();
3154 3109
		echo "interface_carp_configure() being called $mt\n";
......
3225 3180
}
3226 3181

  
3227 3182
function interface_wireless_clone($realif, $wlcfg) {
3228
	global $config, $g;
3183
	global $g;
3229 3184
	/*   Check to see if interface has been cloned as of yet.
3230 3185
	 *   If it has not been cloned then go ahead and clone it.
3231 3186
	 */
......
3292 3247
}
3293 3248

  
3294 3249
function interface_sync_wireless_clones(&$ifcfg, $sync_changes = false) {
3295
	global $config, $g;
3250
	global $config;
3296 3251

  
3297 3252
	$shared_settings = array('standard', 'turbo', 'protmode', 'txpower', 'channel',
3298 3253
				 'diversity', 'txantenna', 'rxantenna', 'distance',
......
3405 3360
	$ifconfig = "/sbin/ifconfig";
3406 3361
	$sysctl = "/sbin/sysctl";
3407 3362
	$sysctl_args = "-q";
3408
	$killall = "/usr/bin/killall";
3409 3363

  
3410 3364
	/* Set all wireless ifconfig variables (split up to get rid of needed checking) */
3411 3365

  
......
3548 3502
	unlink_if_exists($hostapd_conf);
3549 3503

  
3550 3504
	/* generate wpa_supplicant/hostap config if wpa is enabled */
3551

  
3505
	$wpa = "";
3552 3506
	switch ($wlcfg['mode']) {
3553 3507
		case 'bss':
3554 3508
			if (isset($wlcfg['wpa']['enable'])) {
......
3579 3533
					}
3580 3534
					if (strstr($wlcfg['wpa']['wpa_eap_client_mode'], 'TLS')) { 
3581 3535
						$cert = lookup_cert($wlcfg['wpa']['wpa_eap_cert']);
3582
						@file_put_contents($wpa_supplicant_file . "crt", base64_decode($cert['crt']) . "\n" .
3536
						$wpa_supplicant_crt = $wpa_supplicant_file . "crt";
3537
						$wpa_supplicant_key = $wpa_supplicant_file . "key";
3538
						@file_put_contents($wpa_supplicant_crt, base64_decode($cert['crt']) . "\n" .
3583 3539
						    ca_chain($cert)); 
3584
						@file_put_contents($wpa_supplicant_file . "key", base64_decode($cert['prv'])); 
3540
						@file_put_contents($wpa_supplicant_key, base64_decode($cert['prv'])); 
3585 3541
						@chmod($wpa_supplicant_crt, 0600);
3586 3542
						@chmod($wpa_supplicant_key, 0600);
3587 3543
						$wpa .= "client_cert=\"{$wpa_supplicant_crt}\"\n";
3588 3544
						$wpa .= "private_key=\"{$wpa_supplicant_key}\"\n";
3589 3545
					}
3590 3546
					$ca = lookup_ca($wlcfg['wpa']['wpa_eap_ca']);
3591
					@file_put_contents($wpa_supplicant_file . "ca", base64_decode($ca['crt']) . "\n" .
3547
					$wpa_supplicant_ca = $wpa_supplicant_file . "ca";
3548
					@file_put_contents($wpa_supplicant_ca, base64_decode($ca['crt']) . "\n" .
3592 3549
					    ca_chain($ca)); 
3593 3550
					$wpa .= "ca_cert=\"{$wpa_supplicant_ca}\"\n";
3594 3551
					$wpa .= "eap={$wlcfg['wpa']['wpa_eap_client_mode']}\n";
......
3960 3917
	}
3961 3918
}
3962 3919

  
3963
function run_dhcp6client_process($interfaces, $debugOption, $noreleaseOption) {
3920
function run_dhcp6client_process($interfaces, $debugOptions, $noreleaseOption) {
3964 3921
	global $g;
3965 3922

  
3966 3923
	/*
......
4491 4448
		return;
4492 4449
	}
4493 4450

  
4494
	switch ($trackcfg['ipaddrv6']) {
4451
	$type = $trackcfg['ipaddrv6'];
4452
	switch ($type) {
4495 4453
		case "6to4":
4496 4454
			if ($g['debug']) {
4497 4455
				log_error(sprintf(gettext('Interface %1$s configured via %2$s type %3$s'), $interface, $wancfg['track6-interface'], $type));
......
4541 4499
}
4542 4500

  
4543 4501
function interface_track6_6rd_configure($interface, $lancfg) {
4544
	global $config, $g;
4502
	global $config;
4545 4503
	global $interface_ipv6_arr_cache;
4546 4504
	global $interface_snv6_arr_cache;
4547 4505

  
......
4605 4563
}
4606 4564

  
4607 4565
function interface_track6_6to4_configure($interface, $lancfg) {
4608
	global $config, $g;
4566
	global $config;
4609 4567
	global $interface_ipv6_arr_cache;
4610 4568
	global $interface_snv6_arr_cache;
4611 4569

  
......
4665 4623
}
4666 4624

  
4667 4625
function interface_6rd_configure($interface, $wancfg) {
4668
	global $config, $g;
4626
	global $g;
4669 4627

  
4670 4628
	/* because this is a tunnel interface we can only function
4671 4629
	 *	with a public IPv4 address on the interface */
......
4759 4717
}
4760 4718

  
4761 4719
function interface_6to4_configure($interface, $wancfg) {
4762
	global $config, $g;
4720
	global $g;
4763 4721

  
4764 4722
	/* because this is a tunnel interface we can only function
4765 4723
	 *	with a public IPv4 address on the interface */
......
4829 4787
	}
4830 4788
	$stflanpr = text_to_compressed_ip6(implode(":", $stflanarr));
4831 4789
	$stflanarr[7] = 1;
4832
	$stflan = text_to_compressed_ip6(implode(":", $stflanarr));
4833 4790

  
4834 4791
	/* setup the stf interface */
4835 4792
	if (!is_module_loaded("if_stf")) {
......
4981 4938
					}
4982 4939
					foreach ($trackiflist as $friendly => $ifcfg) {
4983 4940
						if ($g['debug']) {
4984
							log_error("setting up $ifdescr - {$ifcfg['track6-prefix-id']}");
4941
							log_error("setting up $interface - {$ifcfg['track6-prefix-id']}");
4985 4942
						}
4986 4943
						$realif = get_real_interface($friendly);
4987 4944
						$dhcp6cconf .= "\tprefix-interface {$realif} {\n";
......
5213 5170
				$track6 = link_interface_to_track6($ifconf);
5214 5171
				if (is_array($track6) && !empty($track6)) {
5215 5172
					/* remove stale track interfaces IP */
5216
					foreach ($track6 as $tr6ifname => $tr6cfg) {
5173
					foreach (array_keys($track6) as $tr6if) {
5217 5174
						interface_reconfigure($tr6if, true);
5218 5175
					}
5219 5176
				}
......
5448 5405

  
5449 5406

  
5450 5407
function interface_dhcp_configure($interface) {
5451
	global $config, $g, $vlanprio_values;
5408
	global $g, $vlanprio_values;
5452 5409

  
5453 5410
	$ifcfg = config_get_path("interfaces/{$interface}");
5454 5411
	if (empty($ifcfg)) {
......
5507 5464

  
5508 5465
	// DHCP Config File Advanced
5509 5466
	if ($ifcfg['adv_dhcp_config_advanced']) {
5510
		$dhclientconf = DHCP_Config_File_Advanced($interface, $ifcfg, $realif);
5467
		$dhclientconf = DHCP_Config_File_Advanced($ifcfg, $realif);
5511 5468
	}
5512 5469

  
5513 5470
	if (is_ipaddr($ifcfg['alias-address'])) {
......
5544 5501
	return 0;
5545 5502
}
5546 5503

  
5547
function DHCP_Config_File_Advanced($interface, $ifcfg, $realif) {
5504
function DHCP_Config_File_Advanced($ifcfg, $realif) {
5548 5505

  
5549 5506
	$hostname = "";
5550 5507
	if ($ifcfg['dhcphostname'] != '') {
......
5705 5662
}
5706 5663

  
5707 5664
function interface_group_setup(&$groupname /* The parameter is an array */) {
5708
	global $config;
5709

  
5710 5665
	if (!is_array($groupname)) {
5711 5666
		return;
5712 5667
	}
......
5831 5786
				}
5832 5787
				break;
5833 5788
			} elseif (substr($interface, 0, 4) == '_vip') {
5834
				foreach (config_get_path('virtualip/vip', []) as $counter => $vip) {
5789
				foreach (config_get_path('virtualip/vip', []) as $vip) {
5835 5790
					if (($vip['mode'] == "carp") || ($vip['mode'] == "ipalias")) {
5836 5791
						if ($interface == "_vip{$vip['uniqid']}") {
5837 5792
							$descr = $vip['subnet'];
......
5891 5846
 *	(Only handles ppps and vlans now.)
5892 5847
 */
5893 5848
function get_parent_interface($interface, $avoidrecurse = false) {
5894
	global $config;
5895

  
5896 5849
	$parents = array();
5897 5850
	//Check that we got a valid interface passed
5898 5851
	$realif = get_real_interface($interface);
......
5914 5867
			case "pptp":
5915 5868
			case "l2tp":
5916 5869
				if (empty($parents)) {
5917
					if (is_array($config['ppps']['ppp'])) {
5918
						foreach ($config['ppps']['ppp'] as $pppidx => $ppp) {
5919
							if ($ifcfg['if'] == $ppp['if']) {
5920
								$ports = explode(',', $ppp['ports']);
5921
								foreach ($ports as $pid => $parent_if) {
5922
									$parents[$pid] = get_real_interface($parent_if);
5923
								}
5924
								break;
5870
					foreach (config_get_path('ppps/ppp') as $ppp) {
5871
						if ($ifcfg['if'] == $ppp['if']) {
5872
							$ports = explode(',', $ppp['ports']);
5873
							foreach ($ports as $pid => $parent_if) {
5874
								$parents[$pid] = get_real_interface($parent_if);
5925 5875
							}
5876
							break;
5926 5877
						}
5927 5878
					}
5928 5879
				}
......
6029 5980
}
6030 5981

  
6031 5982
function get_real_interface($interface = "wan", $family = "all", $realv6iface = false, $flush = false) {
6032
	global $config, $g;
5983
	global $g;
6033 5984

  
6034 5985
	$wanif = NULL;
6035 5986

  
......
6173 6124
	/* if list */
6174 6125
	$ifdescrs = get_configured_interface_list();
6175 6126

  
6176
	foreach ($ifdescrs as $ifdescr => $ifname) {
6127
	foreach ($ifdescrs as $ifname) {
6177 6128
		$ifip = ($isv6ip) ? get_interface_ipv6($ifname) : get_interface_ip($ifname);
6178 6129
		if (is_null($ifip)) {
6179 6130
			continue;
......
6256 6207
}
6257 6208

  
6258 6209
function interface_find_child_cfgmtu($realiface) {
6259
	global $config;
6260

  
6261 6210
	$interface = convert_real_interface_to_friendly_interface_name($realiface);
6262 6211
	$vlans = link_interface_to_vlans($realiface);
6263 6212
	$qinqs = link_interface_to_qinqs($realiface);
......
6514 6463
function find_interface_ipv6($interface, $flush = false) {
6515 6464
	global $interface_ipv6_arr_cache;
6516 6465
	global $interface_snv6_arr_cache;
6517
	global $config;
6518 6466

  
6519 6467
	$interface = trim($interface);
6520 6468
	$interface = get_real_interface($interface);
......
6538 6486
 */
6539 6487
function find_interface_ipv6_ll($interface, $flush = false) {
6540 6488
	global $interface_llv6_arr_cache;
6541
	global $config;
6542 6489

  
6543 6490
	$interface = str_replace("\n", "", $interface);
6544 6491

  
......
6650 6597
function get_possible_traffic_source_addresses($include_ipv6_link_local=false) {
6651 6598
	$sourceips = get_possible_listen_ips($include_ipv6_link_local);
6652 6599
	foreach (array('server', 'client') as $mode) {
6653
		foreach (config_get_path("openvpn/openvpn-{$mode}", []) as $id => $setting) {
6600
		foreach (config_get_path("openvpn/openvpn-{$mode}", []) as $setting) {
6654 6601
			if (!isset($setting['disable'])) {
6655 6602
				$sourceips_key = 'ovpn' . substr($mode, 0, 1) . $setting['vpnid'];
6656 6603
				$sourceips[$sourceips_key] = gettext("OpenVPN") . " " . $mode . ": " . htmlspecialchars($setting['description']);
......
6674 6621
}
6675 6622

  
6676 6623
function get_interface_ip($interface = "wan", $gateways_status = false) {
6677
	global $config;
6678

  
6679 6624
	if (substr($interface, 0, 4) == '_vip') {
6680 6625
		return get_configured_vip_ipv4($interface);
6681 6626
	} elseif (substr($interface, 0, 5) == '_lloc') {
......
6825 6770
}
6826 6771

  
6827 6772
function get_interface_subnet($interface = "wan") {
6828
	global $config;
6829

  
6830 6773
	if (substr($interface, 0, 4) == '_vip') {
6831 6774
		return (get_configured_vip_subnetv4($interface));
6832 6775
	}
......
6850 6793
}
6851 6794

  
6852 6795
function get_interface_subnetv6($interface = "wan") {
6853
	global $config;
6854

  
6855 6796
	if (substr($interface, 0, 4) == '_vip') {
6856 6797
		return (get_configured_vip_subnetv6($interface));
6857 6798
	} elseif (substr($interface, 0, 5) == '_lloc') {
......
7226 7167
}
7227 7168

  
7228 7169
function get_interface_vendor_mac($interface) {
7229
	global $config, $g;
7170
	global $g;
7230 7171

  
7231 7172
	$macinfo = get_interface_addresses($interface);
7232 7173
	if (isset($macinfo["hwaddr"]) && $macinfo["hwaddr"] !=
......
7318 7259
}
7319 7260

  
7320 7261
function interfaces_staticarp_configure($if) {
7321
	global $config, $g;
7322 7262
	if (config_get_path('system/developerspew')) {
7323 7263
		$mt = microtime();
7324 7264
		echo "interfaces_staticarp_configure($if) being called $mt\n";
......
7363 7303
}
7364 7304

  
7365 7305
function get_failover_interface($interface, $family = "all", $gateways_status = false) {
7366
	global $config;
7367

  
7368 7306
	/* shortcut to get_real_interface if we find it in the config */
7369 7307
	if (is_array(config_get_path("interfaces/{$interface}"))) {
7370 7308
		return get_real_interface($interface, $family);
......
7396 7334
 *   false - otherwise (DHCP/DHCP6 not in use, or the name is not an interface or gateway group)
7397 7335
 ******/
7398 7336
function interface_has_dhcp($interface, $family = 4) {
7399
	global $config;
7400

  
7401 7337
	$iface = config_get_path("interfaces/{$interface}");
7402 7338
	if ($iface) {
7403 7339
		if (($family == 4) && ($iface['ipaddr'] == "dhcp")) {
......
7438 7374
	$interfaces = array();	// In case there are no VIPs defined
7439 7375

  
7440 7376
	$viplist = get_configured_vip_list($family, $type);
7441
	foreach ($viplist as $vip => $address) {
7442
		$interfaces[$vip] = $address;
7377
	foreach ($viplist as $vipid => $address) {
7378
		$interfaces[$vipid] = $address;
7443 7379
		if ($type = VIP_CARP) {
7444 7380
			$vip = get_configured_vip($vipid);
7445 7381
			if (isset($vip) && is_array($vip) ) {
......
7447 7383
			}
7448 7384
		}
7449 7385
		if (get_vip_descr($address)) {
7450
			$interfaces[$vip] .= " (" . get_vip_descr($address) . ")";
7386
			$interfaces[$vipid] .= " (" . get_vip_descr($address) . ")";
7451 7387
		}
7452 7388
	}
7453 7389
	return $interfaces;
......
7456 7392
function return_gateway_groups_array_with_descr() {
7457 7393
	$interfaces = array();
7458 7394
	$grouplist = return_gateway_groups_array();
7459
	foreach ($grouplist as $name => $group) {
7460
		if ($group[0]['vip'] != "") {
7461
			$vipif = $group[0]['vip'];
7462
		} else {
7463
			$vipif = $group[0]['int'];
7464
		}
7465

  
7395
	foreach (array_keys($grouplist) as $name) {
7466 7396
		$interfaces[$name] = "GW Group {$name}";
7467 7397
	}
7468 7398
	return $interfaces;
......
7544 7474

  
7545 7475
		// The members of a LAGG cannot be assigned, used in VLANs, QinQ, or PPP.
7546 7476
		$lagglist = get_lagg_interface_list();
7547
		foreach ($lagglist as $laggif => $lagg) {
7477
		foreach ($lagglist as $lagg) {
7548 7478
			/* LAGG members cannot be assigned */
7549 7479
			$laggmembers = explode(',', $lagg['members']);
7550 7480
			foreach ($laggmembers as $lagm) {
......
7651 7581
	services_snmpd_configure($interface);
7652 7582
	vpn_l2tp_configure($interface);
7653 7583

  
7654
	if (substr($realif, 0, 4) != "ovpn") {
7584
	if (substr(config_get_path("interfaces/{$interface}/if",""), 0, 4) != "ovpn") {
7655 7585
		openvpn_resync_all($interface);
7656 7586
	}
7657 7587
	ipsec_force_reload($interface);

Also available in: Unified diff