net/frr: watchfrr service handling (#4712)

This commit is contained in:
Andy Binder
2025-12-17 10:00:22 +01:00
committed by GitHub
parent ea438ed72c
commit 8015cbf4bd
5 changed files with 94 additions and 14 deletions
+36 -3
View File
@@ -1,4 +1,37 @@
#!/bin/sh
#!/usr/local/bin/php
<?php
# XXX this should not be strictly needed
/usr/local/etc/rc.d/frr start
/*
* Copyright (C) 2018 Franco Fichtner <franco@opnsense.org>
* Copyright (C) 2004 Scott Ullrich <sullrich@gmail.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
require_once('config.inc');
require_once('util.inc');
require_once('plugins.inc.d/frr.inc');
if (frr_enabled()) {
shell_exec('/usr/local/opnsense/scripts/frr/carp_event_handler');
}
+55
View File
@@ -0,0 +1,55 @@
#!/bin/sh
# Copyright (c) 2025 Andy Binder <AndyBinder@gmx.de>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
# Service wrapper for starting/restarting frr service
# This wrapper is needed to react on specific service interactions through watchfrr.
# Startup details with watchfrr enabled (default):
# 1. "service frr start" calls "service frr start watchfrr"
# 2. watchfrr once started calls "service frr restart all"
# 3. "restart all" need to loop the list of $frr_daemons to start each
# of then
# 4. vtysh -b is executed to load boot startup configuration
ACTION="$1"
COMMAND="$2"
/usr/sbin/service frr "$ACTION" "$COMMAND"
SERVICE_EXIT_CODE=$?
# If frr starts/restarts ospfd, e.g. on process error (parameter: start/restart ospfd)
if [ "$2" = "ospfd" ]; then
logger -t frr_wrapper "WATCHFRR - OSPFD - Starting CARP event handler now"
/usr/local/opnsense/scripts/frr/carp_event_handler
fi
# If frr starts up (parameter: restart all)
if [ "$2" = "all" ]; then
(
/usr/bin/logger -t frr_wrapper "WATCHFRR - STARTUP - Starting CARP event handler now"
/usr/local/opnsense/scripts/frr/carp_event_handler
) &
fi
exit $SERVICE_EXIT_CODE
@@ -18,7 +18,7 @@ message:restarting frr
description:Restart FRR
[reload]
command:service frr reload
command:service frr reload; /usr/local/opnsense/scripts/frr/carp_event_handler
parameters:
type:script
message:reloading frr
@@ -18,15 +18,7 @@ frr_carp_demote="{%
if not helpers.empty('OPNsense.quagga.ospf.carp_demote') %} ospfd{% endif %}{%
if not helpers.empty('OPNsense.quagga.ospf6.carp_demote') %} ospf6d{% endif
%}"
start_postcmd='
# XXX rc.d/frr declares its own post command we need to hook first
start_postcmd
# XXX rc.d/frr iterates through daemons so we need to hook last one
if [ "${frr_daemons}" != "${frr_daemons% ${name}}" ]; then
echo "Starting CARP event handler now"
/usr/local/opnsense/scripts/frr/carp_event_handler
fi
'
watchfrr_flags="-r /usr/local/opnsense/scripts/frr/frr_wrapper.shbBrestartbB%s -s /usr/local/opnsense/scripts/frr/frr_wrapper.shbBstartbB%s -k /usr/sbin/servicebBfrrbBstopbB%s -b bB -t 30"
{% if OPNsense.quagga.general.enablesnmp == '1' %}
zebra_flags="${zebra_flags} -M snmp"
bgpd_flags="${bgpd_flags} -M snmp"
@@ -2,5 +2,5 @@
# Local syslog-ng configuration filter definition [FRR].
###################################################################
filter f_local_routing_frr {
program("bgpd") or program("ospfd") or program("ospf6d") or program("ripd") or program("zebra") or program("frr_carp");
program("bgpd") or program("ospfd") or program("ospf6d") or program("ripd") or program("zebra") or program("frr_carp") or program("frr_wrapper");
};