From 370746178e50d71d2683e3ed32dcb56cea6cbc40 Mon Sep 17 00:00:00 2001 From: Andy Binder Date: Sat, 24 May 2025 13:07:21 +0200 Subject: [PATCH] net/frr: watchfrr service handling --- net/frr/src/etc/rc.syshook.d/start/50-frr | 39 ++++++++++++- .../src/opnsense/scripts/frr/frr_wrapper.sh | 55 +++++++++++++++++++ .../conf/actions.d/actions_quagga.conf | 2 +- .../service/templates/OPNsense/Quagga/frr | 10 +--- .../OPNsense/Syslog/local/routing_frr.conf | 2 +- 5 files changed, 94 insertions(+), 14 deletions(-) create mode 100755 net/frr/src/opnsense/scripts/frr/frr_wrapper.sh diff --git a/net/frr/src/etc/rc.syshook.d/start/50-frr b/net/frr/src/etc/rc.syshook.d/start/50-frr index efded3c94a..dd4254a89b 100755 --- a/net/frr/src/etc/rc.syshook.d/start/50-frr +++ b/net/frr/src/etc/rc.syshook.d/start/50-frr @@ -1,4 +1,37 @@ -#!/bin/sh +#!/usr/local/bin/php + + * Copyright (C) 2004 Scott Ullrich + * 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'); +} \ No newline at end of file diff --git a/net/frr/src/opnsense/scripts/frr/frr_wrapper.sh b/net/frr/src/opnsense/scripts/frr/frr_wrapper.sh new file mode 100755 index 0000000000..5b3a812991 --- /dev/null +++ b/net/frr/src/opnsense/scripts/frr/frr_wrapper.sh @@ -0,0 +1,55 @@ +#!/bin/sh + +# Copyright (c) 2025 Andy Binder +# +# 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 diff --git a/net/frr/src/opnsense/service/conf/actions.d/actions_quagga.conf b/net/frr/src/opnsense/service/conf/actions.d/actions_quagga.conf index aa2e0b70bd..32b7e533c0 100644 --- a/net/frr/src/opnsense/service/conf/actions.d/actions_quagga.conf +++ b/net/frr/src/opnsense/service/conf/actions.d/actions_quagga.conf @@ -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 diff --git a/net/frr/src/opnsense/service/templates/OPNsense/Quagga/frr b/net/frr/src/opnsense/service/templates/OPNsense/Quagga/frr index 7235af5106..66c05df4c6 100644 --- a/net/frr/src/opnsense/service/templates/OPNsense/Quagga/frr +++ b/net/frr/src/opnsense/service/templates/OPNsense/Quagga/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" diff --git a/net/frr/src/opnsense/service/templates/OPNsense/Syslog/local/routing_frr.conf b/net/frr/src/opnsense/service/templates/OPNsense/Syslog/local/routing_frr.conf index ad0869d3c7..61a95d16ac 100644 --- a/net/frr/src/opnsense/service/templates/OPNsense/Syslog/local/routing_frr.conf +++ b/net/frr/src/opnsense/service/templates/OPNsense/Syslog/local/routing_frr.conf @@ -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"); };