Skip to content

Commit 2bcd16d

Browse files
committed
net/frr: watchfrr service handling
1 parent a5fdb9c commit 2bcd16d

File tree

4 files changed

+93
-13
lines changed

4 files changed

+93
-13
lines changed
Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,37 @@
1-
#!/bin/sh
1+
#!/usr/local/bin/php
2+
<?php
23

3-
# XXX this should not be strictly needed
4-
/usr/local/etc/rc.d/frr start
4+
/*
5+
* Copyright (C) 2018 Franco Fichtner <[email protected]>
6+
* Copyright (C) 2004 Scott Ullrich <[email protected]>
7+
* All rights reserved.
8+
*
9+
* Redistribution and use in source and binary forms, with or without
10+
* modification, are permitted provided that the following conditions are met:
11+
*
12+
* 1. Redistributions of source code must retain the above copyright notice,
13+
* this list of conditions and the following disclaimer.
14+
*
15+
* 2. Redistributions in binary form must reproduce the above copyright
16+
* notice, this list of conditions and the following disclaimer in the
17+
* documentation and/or other materials provided with the distribution.
18+
*
19+
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
20+
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
21+
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22+
* AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
23+
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28+
* POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
31+
require_once('config.inc');
32+
require_once('util.inc');
33+
require_once('plugins.inc.d/frr.inc');
34+
35+
if (frr_enabled()) {
36+
shell_exec('/usr/local/opnsense/scripts/frr/carp_event_handler');
37+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/bin/sh
2+
3+
# Copyright (c) 2025 Andy Binder <[email protected]>
4+
#
5+
# Redistribution and use in source and binary forms, with or without
6+
# modification, are permitted provided that the following conditions
7+
# are met:
8+
#
9+
# 1. Redistributions of source code must retain the above copyright
10+
# notice, this list of conditions and the following disclaimer.
11+
#
12+
# 2. Redistributions in binary form must reproduce the above copyright
13+
# notice, this list of conditions and the following disclaimer in the
14+
# documentation and/or other materials provided with the distribution.
15+
#
16+
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17+
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22+
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23+
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24+
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25+
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26+
# SUCH DAMAGE.
27+
28+
# Service wrapper for starting/restarting frr service
29+
# This wrapper is needed to react on specific service interactions through watchfrr.
30+
# Startup details with watchfrr enabled (default):
31+
# 1. "service frr start" calls "service frr start watchfrr"
32+
# 2. watchfrr once started calls "service frr restart all"
33+
# 3. "restart all" need to loop the list of $frr_daemons to start each
34+
# of then
35+
# 4. vtysh -b is executed to load boot startup configuration
36+
37+
ACTION="$1"
38+
COMMAND="$2"
39+
40+
/usr/sbin/service frr "$ACTION" "$COMMAND"
41+
SERVICE_EXIT_CODE=$?
42+
43+
# If frr starts/restarts ospfd, e.g. on process error (parameter: start/restart ospfd)
44+
if [ "$2" = "ospfd" ]; then
45+
logger -t frr_wrapper "WATCHFRR - OSPFD - Starting CARP event handler now"
46+
/usr/local/opnsense/scripts/frr/carp_event_handler
47+
fi
48+
# If frr starts up (parameter: restart all)
49+
if [ "$2" = "all" ]; then
50+
(
51+
/usr/bin/logger -t frr_wrapper "WATCHFRR - STARTUP - Starting CARP event handler now"
52+
/usr/local/opnsense/scripts/frr/carp_event_handler
53+
) &
54+
fi
55+
exit $SERVICE_EXIT_CODE

net/frr/src/opnsense/service/conf/actions.d/actions_quagga.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ message:restarting frr
1818
description:Restart FRR
1919

2020
[reload]
21-
command:service frr reload
21+
command:service frr reload; /usr/local/opnsense/scripts/frr/carp_event_handler
2222
parameters:
2323
type:script
2424
message:reloading frr

net/frr/src/opnsense/service/templates/OPNsense/Quagga/frr

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,7 @@ frr_carp_demote="{%
1818
if not helpers.empty('OPNsense.quagga.ospf.carp_demote') %} ospfd{% endif %}{%
1919
if not helpers.empty('OPNsense.quagga.ospf6.carp_demote') %} ospf6d{% endif
2020
%}"
21-
start_postcmd='
22-
# XXX rc.d/frr declares its own post command we need to hook first
23-
start_postcmd
24-
# XXX rc.d/frr iterates through daemons so we need to hook last one
25-
if [ "${frr_daemons}" != "${frr_daemons% ${name}}" ]; then
26-
echo "Starting CARP event handler now"
27-
/usr/local/opnsense/scripts/frr/carp_event_handler
28-
fi
29-
'
21+
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"
3022
{% if OPNsense.quagga.general.enablesnmp == '1' %}
3123
zebra_flags="${zebra_flags} -M snmp"
3224
bgpd_flags="${bgpd_flags} -M snmp"

0 commit comments

Comments
 (0)