keepalived: add new uci section config interface_up_down_delays
authorFlorian Eckert <fe@dev.tdt.de>
Tue, 4 Feb 2025 12:01:53 +0000 (13:01 +0100)
committerFlorian Eckert <Eckert.Florian@googlemail.com>
Thu, 13 Feb 2025 12:34:08 +0000 (13:34 +0100)
If an interface that is being used (or tracked) by a VRRP instance goes to
down state, the VRRP instance(s) will, by default, immediately transition to
FAULT state, and when all relevant interfaces are back up again the VRRP
instance(s) will immediately transition to BACKUP state.

This can cause problems if interfaces are bouncing, and so delays can be
specified between the interface state change and the transition to
FAULT/BACKUP state. If the interface returns to its original state before
the delay expires, no associated VRRP instance state transition will occur.

New uci section 'interface_up_down_delay':

config interface_up_down_delays
option device <device>
option down_delay <number in seconds>
option up_delay <number in seconds>

Signed-off-by: Florian Eckert <fe@dev.tdt.de>
net/keepalived/files/keepalived.init

index cbbff49410e094cad162195bea1ca7c5fd1596d7..c017a679f8547b5dc18a539cfa3e2a34d9981872 100644 (file)
@@ -287,6 +287,25 @@ static_routes() {
        done
 }
 
+interface_up_down_delays() {
+       local device
+       local down_delay
+       local up_delay
+       local line
+
+       config_get device "$1" device
+       config_get down_delay "$1" down_delay
+       config_get up_delay "$1" up_delay
+
+       [ -z "$device" ] && return
+       [ -z "$down_delay" ] && return
+
+       line="${device} ${down_delay}"
+       [ -z "$up_delay" ] || line="${line} ${up_delay}"
+
+       printf '%b%s\n' "$INDENT_1" "$line" >> "$KEEPALIVED_CONF"
+}
+
 # Count 'vrrp_instance' with the given name ; called by vrrp_instance_check()
 vrrp_instance_name_count() {
        local name
@@ -613,6 +632,10 @@ process_config() {
        config_foreach_wrapper static_routes
        config_section_close
 
+       config_section_open "interface_up_down_delays"
+       config_foreach_wrapper interface_up_down_delays
+       config_section_close
+
        config_foreach_wrapper vrrp_script
        config_foreach_wrapper bfd_instance
        config_foreach_wrapper vrrp_sync_group