From 53cd1c7183f44599cf36483bb17775d819ff07bb Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Tue, 31 Aug 2021 13:25:03 +0200 Subject: [PATCH] Squashed commit of the following: commit 9da181580631e305cf194688479eb311d74dda9d Author: Ad Schellevis Date: Tue Aug 31 13:22:39 2021 +0200 CARP: small cleanups after https://github.com/opnsense/core/pull/5184 commit 9875b53e98aeed173e1603182251b8e2165cabbb Author: vnxme <46669194+vnxme@users.noreply.github.com> Date: Sun Aug 29 22:28:03 2021 +0300 CARP: Fix fetching VIP status Implement array safeguards after e44fd48 commit 9c6ff1717741ec7f21a1b88127c57ff3d849085d Author: vnxme <46669194+vnxme@users.noreply.github.com> Date: Sun Aug 29 22:23:25 2021 +0300 CARP: Fix fetching VIP status Simplify code after e44fd48 commit 52ffd6ee3d471c09a69599a8fdd02f6e6ea6f2c6 Author: vnxme <46669194+vnxme@users.noreply.github.com> Date: Sun Aug 29 22:19:26 2021 +0300 CARP: Fix fetching VIP status Simplify code after e44fd48 commit d5ae42623e31138daa29debedc36088fa7ba4811 Author: vnxme <46669194+vnxme@users.noreply.github.com> Date: Sun Aug 29 22:13:57 2021 +0300 CARP: Fix fetching VIP status Simplify code after e44fd48 commit df99ba8106233a34732bb0cb39f6134d7697e4a4 Author: vnxme <46669194+vnxme@users.noreply.github.com> Date: Sun Aug 29 16:39:57 2021 +0300 CARP: Fix fetching VIP status Take into account translation issues commit 45eddeb399b64e631e7d81be8ac29dc2cad97bf2 Author: vnxme <46669194+vnxme@users.noreply.github.com> Date: Sun Aug 29 16:35:04 2021 +0300 CARP: Fix fetching VIP status Take into account translation issues commit a068f10cd0a4402e648a09027a6b48b90670e60a Author: vnxme <46669194+vnxme@users.noreply.github.com> Date: Sun Aug 29 15:08:51 2021 +0300 CARP: Fix fetching VIP status Whitespace cleanup commit aa958e1d04938b084a5582dd4080988aef240eaa Author: vnxme <46669194+vnxme@users.noreply.github.com> Date: Sun Aug 29 15:05:12 2021 +0300 CARP: Fix fetching VIP status Remove unnecessary require_once call Co-authored-by: Franco Fichtner commit 5966d1c834fe5c69845a675f0f829ec6efcabc2f Author: vnxme <46669194+vnxme@users.noreply.github.com> Date: Sun Aug 29 15:04:47 2021 +0300 CARP: Fix fetching VIP status Remove unnecessary require_once call Co-authored-by: Franco Fichtner commit 38d6d952084ed2db4ae2d81aa583850a38f2f7b2 Author: vnxme <46669194+vnxme@users.noreply.github.com> Date: Sun Aug 29 15:03:57 2021 +0300 CARP: Fix fetching VIP status Remove unnecessary require_once call Co-authored-by: Franco Fichtner commit 3ae8a2f960310b4f373fbae3e77e2eea2b7ced8a Author: vnxme <46669194+vnxme@users.noreply.github.com> Date: Sun Aug 29 14:49:46 2021 +0300 CARP: Fix fetching VIP status Eliminate calling get_carp_interface_status() by openvpn.inc commit bf195f3a66ad6a1ec5c62ecb589e32681eeb86dc Author: vnxme <46669194+vnxme@users.noreply.github.com> Date: Sun Aug 29 14:04:16 2021 +0300 CARP: Fix fetching VIP status Refactor the widget to call ifconfig once commit 26bfe2036a846824b9d163d9c3c8aafd2be3ac36 Author: vnxme <46669194+vnxme@users.noreply.github.com> Date: Sun Aug 29 13:58:20 2021 +0300 CARP: Fix fetching VIP status Refactor the status page to call ifconfig once commit 7cdc8eca63acfb9db8da9cf621780c30454df132 Author: vnxme <46669194+vnxme@users.noreply.github.com> Date: Sun Aug 29 10:22:05 2021 +0300 CARP: Fix fetching VIP status Add a space after vhid to make grep more precise --- src/etc/inc/interfaces.inc | 22 ------------- src/etc/inc/plugins.inc.d/openvpn.inc | 14 +++++--- src/www/carp_status.php | 21 ++++++++---- .../widgets/widgets/carp_status.widget.php | 32 +++++++++++++------ 4 files changed, 47 insertions(+), 42 deletions(-) diff --git a/src/etc/inc/interfaces.inc b/src/etc/inc/interfaces.inc index 34551e77d..d92d8c9f6 100644 --- a/src/etc/inc/interfaces.inc +++ b/src/etc/inc/interfaces.inc @@ -4482,28 +4482,6 @@ function is_ipaddr_configured($ipaddr, $ignore_if = '') } } -/* - * get_carp_interface_status($carpinterface): returns the status of a carp ip - */ -function get_carp_interface_status($carpinterface) -{ - $carp_query = []; - - /* XXX: Need to find a better way for this! */ - list ($interface, $vhid) = explode("_vip", $carpinterface); - $interface = get_real_interface($interface); - exec("/sbin/ifconfig $interface | /usr/bin/grep -v grep | /usr/bin/grep carp: | /usr/bin/grep 'vhid {$vhid}'", $carp_query); - foreach ($carp_query as $int) { - if (stristr($int, "MASTER")) { - return gettext("MASTER"); - } elseif (stristr($int, "BACKUP")) { - return gettext("BACKUP"); - } elseif (stristr($int, "INIT")) { - return gettext("INIT"); - } - } - return gettext('DISABLED'); -} function make_ipv6_64_address($prefix, $suffix) { diff --git a/src/etc/inc/plugins.inc.d/openvpn.inc b/src/etc/inc/plugins.inc.d/openvpn.inc index 88a870e78..726d612cb 100644 --- a/src/etc/inc/plugins.inc.d/openvpn.inc +++ b/src/etc/inc/plugins.inc.d/openvpn.inc @@ -898,11 +898,17 @@ function openvpn_restart($mode, $settings, $carp_event = false) } if ( - strstr($settings['interface'], '_vip') && $mode == 'client' && - get_carp_interface_status($settings['interface']) == gettext('BACKUP') + strstr($settings['interface'], '_vip') && $mode == 'client' ) { - /* do not restart a client if we are a CARP backup instance */ - return; + list ($interface, $vhid) = explode("_vip", $settings['interface']); + $interface_details = legacy_interface_details(get_real_interface($interface)); + if ( + !empty($interface_details) && !empty($interface_details['carp'][$vhid]) && + $interface_details['carp'][$vhid]['status'] == 'BACKUP' + ) { + /* do not restart a client if we are a CARP backup instance */ + return; + } } @unlink("/var/etc/openvpn/{$mode_id}.sock"); diff --git a/src/www/carp_status.php b/src/www/carp_status.php index cb4b50a4c..f51cfb99b 100644 --- a/src/www/carp_status.php +++ b/src/www/carp_status.php @@ -163,26 +163,35 @@ include("head.inc"); 0 && !$status)) { $icon = "fa fa-remove fa-fw text-danger"; - $intf_status = gettext('DISABLED'); - } elseif ($intf_status == gettext('MASTER')) { + $intf_status_i18n = gettext('DISABLED'); + } elseif ($intf_status == 'MASTER') { $icon = "fa fa-play fa-fw text-success"; - } elseif ($intf_status == gettext('BACKUP')) { + $intf_status_i18n = gettext('MASTER'); + } elseif ($intf_status == 'BACKUP') { $icon = "fa fa-play fa-fw text-muted"; - } elseif ($intf_status == gettext('INIT')) { + $intf_status_i18n = gettext('BACKUP'); + } elseif ($intf_status == 'INIT') { $icon = "fa fa-info-circle fa-fw"; + $intf_status_i18n = gettext('INIT'); }?> - + + $intf = get_real_interface($carp['interface']); + if ( + !empty($interfaces_details[$intf]) && !empty($interfaces_details[$intf]['carp'][$carp['vhid']]) + ) { + $status = $interfaces_details[$intf]['carp'][$carp['vhid']]['status']; + } else { + $status = null; + } +?>
@@ -52,18 +61,21 @@ config_read_array('virtualip', 'vip'); "; - } elseif ($status == gettext("MASTER")) { - echo ""; - } elseif ($status == gettext("BACKUP")) { - echo ""; - } elseif ($status == gettext("INIT")) { - echo ""; + $status_i18n = gettext("DISABLED"); + echo ""; + } elseif ($status == "MASTER") { + $status_i18n = gettext("MASTER"); + echo ""; + } elseif ($status == "BACKUP") { + $status_i18n = gettext("BACKUP"); + echo ""; + } elseif ($status == "INIT") { + $status_i18n = gettext("INIT"); + echo ""; } if (!empty($carp['subnet'])):?>   -   +