mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-14 16:44:39 +00:00
ipsec: add shared function to simplify ipsec code #5201
This commit is contained in:
parent
e2ad649886
commit
82b2ede99b
@ -1861,13 +1861,11 @@ function ipsec_get_configured_vtis()
|
||||
}
|
||||
|
||||
$inet = is_ipaddrv6($phase2['tunnel_local']) ? 'inet6' : 'inet';
|
||||
$mask = $inet == 'inet6' ? find_smallest_cidr6([$phase2['tunnel_local'], $phase2['tunnel_remote']]) :
|
||||
find_smallest_cidr([$phase2['tunnel_local'], $phase2['tunnel_remote']]);
|
||||
|
||||
$configured_intf[$intfnm]['networks'][] = [
|
||||
'inet' => $inet,
|
||||
'mask' => find_smallest_cidr([$phase2['tunnel_local'], $phase2['tunnel_remote']], $inet),
|
||||
'tunnel_local' => $phase2['tunnel_local'],
|
||||
'mask' => $mask,
|
||||
'tunnel_remote' => $phase2['tunnel_remote']
|
||||
];
|
||||
}
|
||||
|
||||
@ -470,8 +470,16 @@ function ip2ulong($ip)
|
||||
return sprintf("%u", ip2long32($ip));
|
||||
}
|
||||
|
||||
/* Find the smallest possible subnet mask for given IP range */
|
||||
function find_smallest_cidr($ips, $family = 'inet')
|
||||
{
|
||||
return $family == 'inet6' ?
|
||||
find_smallest_cidr6($ips) :
|
||||
find_smallest_cidr4($ips);
|
||||
}
|
||||
|
||||
/* Find the smallest possible subnet mask for given IPv4 range */
|
||||
function find_smallest_cidr($ips)
|
||||
function find_smallest_cidr4($ips)
|
||||
{
|
||||
foreach ($ips as $id => $ip) {
|
||||
$ips[$id] = ip2long($ip);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user