Project

General

Profile

« Previous | Next » 

Revision 4fc1c68f

Added by Phil Davis over 10 years ago

Do not return disabled dynamic gateways

When a dynamic gateway is disabled (by the user through the webGUI), it was still being returned by return_gateways_array(). But when called like that, disabled gateways should not be returned. The first part of the routine was correctly skipping disabled gateways, but then the later part would effectively re-generate those dynamic gateways on-the-fly and not realise they should be skipped because they were disabled.
This code now remembers gateway details of all the gateways, including skipped ones, so the dynamic gateway code can easily realise all gateways that have been already processed, even those that were processed and skipped.
Forum: https://forum.pfsense.org/index.php?topic=86565.0
It fixes Gateway Status Widget - now if a dynamic gateway is disabled, it does not appear on the display.
This will also stop disabled dynamic gateways from being returned to other callers. So there may/will be impacts on other parts of the system when a user disables a dynamic gateway. e.g. filter.inc - a gateway that has been disabled by a user canot be used in rules any more.

View differences:

etc/inc/gwlb.inc
446 446
	global $config, $g;
447 447

  
448 448
	$gateways_arr = array();
449
	$gateways_arr_temp = array();
449 450

  
450 451
	$found_defaultv4 = 0;
451 452
	$found_defaultv6 = 0;
......
471 472
			$wancfg = $config['interfaces'][$gateway['interface']];
472 473

  
473 474
			/* skip disabled interfaces */
474
			if ($disabled === false && (!isset($wancfg['enable']) || isset($gateway['disabled'])))
475
			if ($disabled === false && (!isset($wancfg['enable'])))
475 476
				continue;
476 477

  
477 478
			/* if the gateway is dynamic and we can find the IPv4, Great! */
......
532 533
			/* include the gateway index as the attribute */
533 534
			$gateway['attribute'] = $i;
534 535

  
535
			$gateways_arr[$gateway['name']] = $gateway;
536
			/* Remember all the gateway names, even ones to be skipped because they are disabled. */
537
			/* Then we can easily know and match them later when attempting to add dynamic gateways to the list. */
538
			$gateways_arr_temp[$gateway['name']] = $gateway;
539

  
540
			/* skip disabled gateways if the caller has not asked for them to be returned. */
541
			if (!($disabled === false && isset($gateway['disabled'])))
542
				$gateways_arr[$gateway['name']] = $gateway;
536 543
		}
537 544
	}
538 545
	unset($gateway);
......
609 616
		if (!is_ipaddrv4($gateway['gateway']) && $gateway['dynamic'] == true)
610 617
			$gateway['gateway'] = "dynamic";
611 618

  
612
		/* automatically skip known static and dynamic gateways we have a array entry for */
613
		foreach($gateways_arr as $gateway_item) {
619
		/* automatically skip known static and dynamic gateways that were previously processed */
620
		foreach($gateways_arr_temp as $gateway_item) {
614 621
			if ((($ifname == $gateway_item['friendlyiface'] && $friendly == $gateway_item['name'])&& ($gateway['ipprotocol'] == $gateway_item['ipprotocol'])) ||
615 622
				($ifname == $gateway_item['friendlyiface'] && $gateway_item['dynamic'] == true) && ($gateway['ipprotocol'] == $gateway_item['ipprotocol']))
616 623
					continue 2;
......
701 708
		if (!is_ipaddrv6($gateway['gateway']) && $gateway['dynamic'] == true)
702 709
			$gateway['gateway'] = "dynamic";
703 710

  
704
		/* automatically skip known static and dynamic gateways we have a array entry for */
705
		foreach($gateways_arr as $gateway_item) {
711
		/* automatically skip known static and dynamic gateways that were previously processed */
712
		foreach($gateways_arr_temp as $gateway_item) {
706 713
			if ((($ifname == $gateway_item['friendlyiface'] && $friendly == $gateway_item['name']) && ($gateway['ipprotocol'] == $gateway_item['ipprotocol'])) ||
707 714
				($ifname == $gateway_item['friendlyiface'] && $gateway_item['dynamic'] == true) && ($gateway['ipprotocol'] == $gateway_item['ipprotocol']))
708 715
					continue 2;

Also available in: Unified diff