From 7c833ea3d6ea78637446af5e788b06e9e6af35ce Mon Sep 17 00:00:00 2001 From: Daniil Baturin Date: Wed, 11 Jul 2018 04:13:55 +0700 Subject: [PATCH] Add a special case for /31 networks to openvpn_get_interface_ip() (another instance of #2529). --- src/etc/inc/plugins.inc.d/openvpn.inc | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/etc/inc/plugins.inc.d/openvpn.inc b/src/etc/inc/plugins.inc.d/openvpn.inc index f16b9359f..1e089d6af 100644 --- a/src/etc/inc/plugins.inc.d/openvpn.inc +++ b/src/etc/inc/plugins.inc.d/openvpn.inc @@ -1485,9 +1485,21 @@ function openvpn_create_dirs() function openvpn_get_interface_ip($ip, $mask) { - $baselong = ip2long32($ip) & ip2long($mask); - $ip1 = long2ip32($baselong + 1); - $ip2 = long2ip32($baselong + 2); + $masklong = ip2long($mask); + $baselong = ip2long32($ip) & $masklong; + + // Special case for /31 networks which lack network and broadcast addresses. + // As per RFC3021, both addresses should be treated as host addresses. + if ($masklong == 0xfffffffe) + { + $ip1 = long2ip32($baselong); + $ip2 = long2ip32($baselong + 1); + } + else + { + $ip1 = long2ip32($baselong + 1); + $ip2 = long2ip32($baselong + 2); + } return array($ip1, $ip2); }