Project

General

Profile

« Previous | Next » 

Revision f016f149

Added by Marcos M almost 2 years ago

Check for routing protocol flags when removing the default route. Fix #14717

View differences:

src/etc/inc/gwlb.inc
1134 1134
	/* do not delete dynamic (frr/bgp/ospf) route
1135 1135
	 * see https://redmine.pfsense.org/issues/12536 */
1136 1136
	if ($gwdefault == "-") {
1137
		if (is_static_route('default', $ipprotocol)) {
1137
		if (!is_dynamic_route('default', $ipprotocol)) {
1138 1138
			route_del('default', $ipprotocol);
1139 1139
		}
1140 1140
		return;
src/etc/inc/util.inc
2876 2876
	return $result;
2877 2877
}
2878 2878

  
2879
/* check if route is static (not BGP/OSPF) */
2880
function is_static_route($target, $ipprotocol = '') {
2879
/**
2880
 * Checks if a route was sourced from a dynamic routing protocol like
2881
 * BGP or OSPF by looking at the route flags.
2882
 * 
2883
 * @param string $target IP address or subnet, or 'default' for the default route
2884
 * @param string $ipprotocol either 'inet' for IPv4, or 'inet6' for IPv6
2885
 * 
2886
 * @return bool true if it's a dynamic route
2887
 */
2888
function is_dynamic_route(string $target, string $ipprotocol = ''): bool {
2881 2889
	if (is_v4($target) || (($target == 'default') && ($ipprotocol == 'inet'))) {
2882 2890
		$inet = '4';
2883 2891
	} elseif (is_v6($target) || (($target == 'default') && ($ipprotocol == 'inet6'))) {
......
2886 2894
		return false;
2887 2895
	}
2888 2896

  
2889
	if (exec("/sbin/route -n{$inet} get " . escapeshellarg($target) . " 2>/dev/null | egrep 'flags: <.*STATIC.*>'")) {
2897
	/* check for the PROTO* flag instead of STATIC
2898
	 * see https://redmine.pfsense.org/issues/14717
2899
	 * mwexec() returns false if the flag exists, so invert it */
2900
	if (!mwexec("/sbin/route -n{$inet} get " . escapeshellarg($target) . " 2>/dev/null | /usr/bin/egrep 'flags: <.*PROTO.*>'")) {
2890 2901
		return true;
2891 2902
	}
2892 2903

  

Also available in: Unified diff