Project

General

Profile

Bug #12947 » v6address.diff

Jan-Jonas Sämann, 01/25/2025 04:31 AM

View differences:

src/etc/inc/interfaces.inc
7497 7497
	}
7498 7498

  
7499 7499
	if ($v6addrs) {
7500
		// use the first IPv6 GUA address if one exists, otherwise the first address
7500
		// use the first valid IPv6 GUA address if one exists, otherwise the first address
7501 7501
		$v6addr = $v6addrs[array_key_first($v6addrs)];
7502 7502
		foreach ($v6addrs as $addr) {
7503 7503
			if (is_v6gua($addr['addr'])) {
7504 7504
				$v6addr = $addr;
7505
				break;
7505
				if (!is_v6deprecated($addr['addr'])) {
7506
					break;
7507
				}
7506 7508
			}
7507 7509
		}
7508 7510
		$ifaddrs['ipaddr6'] = $v6addr['addr'];
src/etc/inc/util.inc
939 939
	}
940 940
}
941 941

  
942
/**
943
 * Checks if an IPv6 address is deprecated.
944
 * 
945
 * @param string $ip IPv6 address or subnet
946
 * 
947
 * @return bool
948
 */
949
function is_v6deprecated(string $ip_or_subnet): bool {
950
	if (is_subnet($ip_or_subnet) == 6) {
951
		list($ip_or_subnet) = explode('/', $ip_or_subnet);
952
	}
953
	if (!is_ipaddrv6($ip_or_subnet)) {
954
		return false;
955
	}
956
	$ip_or_subnet = Net_IPv6::Compress($ip_or_subnet);
957
	$ifconfig = [];
958
	exec("/sbin/ifconfig -au inet6", $ifconfig);
959
	return (preg_grep("/inet6 {$ip_or_subnet}.*deprecated/", $ifconfig) != false);
960
}
961

  
942 962
/* same as is_subnet() but accepts IPv4 only */
943 963
function is_subnetv4($subnet) {
944 964
	return (is_subnet($subnet) == 4);
(4-4/4)