Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6f43925
keepalived: Fixed print_track_script_indent function
rishabhshah2005 Mar 30, 2026
6d48739
keepalived: Added track_script option for sync group
rishabhshah2005 Mar 30, 2026
169fcb7
keepalived: Updated keepalived.config
rishabhshah2005 Mar 30, 2026
b956c7f
keepalived: Added option timeout in vrrp_script.
rishabhshah2005 Mar 30, 2026
2983ba4
keepalived: changed curr_track_elem in vrrp_instance
rishabhshah2005 Mar 30, 2026
e527de8
keepalived: Bumped keepalived PKG_RELEASE to 3
rishabhshah2005 Mar 30, 2026
4285957
keepalived: Removed keyword 'if'
rishabhshah2005 Mar 31, 2026
8848d0b
keepalived: added back the trailing lines
rishabhshah2005 Mar 31, 2026
70f77b5
keepalived: added new line ending
rishabhshah2005 Apr 5, 2026
c2efbec
Merge branch 'openwrt:master' into master
rishabhshah2005 Apr 5, 2026
74df60d
Merge branch 'openwrt:master' into master
rishabhshah2005 Apr 17, 2026
294f983
keepalived: added indentation in config_section_open
Apr 17, 2026
1ed1a07
keepalived: added indent in config_section_close
Apr 17, 2026
d73d73b
keepalived: updated parse logic for track_script
rishabhshah2005 Apr 18, 2026
d9773e8
keepalived: update in parse logic for track_script
rishabhshah2005 Apr 18, 2026
ca3d0eb
keepalived: updated parse logic for virtual_routes
rishabhshah2005 Apr 18, 2026
597e31c
keepalived: updated parse logic for virtual_ipaddr
rishabhshah2005 Apr 18, 2026
f6ea206
keepalived: updated parse logic for track_interface
rishabhshah2005 Apr 18, 2026
2294eaa
keepalived: updated parse logic for track_bfd
rishabhshah2005 Apr 18, 2026
dd30c72
keepalived: added docs for bfd_instance section
rishabhshah2005 Apr 18, 2026
51940d0
keepalived: updated parse logic for unicast_peer
rishabhshah2005 Apr 18, 2026
3c4f35b
keepalived: updated print_unicast_peer_indent func
rishabhshah2005 Apr 18, 2026
5bee3a7
keepalived: updated config for unicast_peer
rishabhshah2005 Apr 18, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion net/keepalived/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk

PKG_NAME:=keepalived
PKG_VERSION:=2.3.3
PKG_RELEASE:=2
PKG_RELEASE:=3

PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://www.keepalived.org/software
Expand Down
43 changes: 37 additions & 6 deletions net/keepalived/files/keepalived.config
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,12 @@ config globals 'globals'
# list route "route1"

#config vrrp_sync_group
# option name "VI_sync_group_1"
# list group "VI_1"
# list group "VI_2"
# option name "VI_sync_group_1"
# list group "VI_1"
# list group "VI_2"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes

#	option name		  "VI_sync_group_1"
#	list group		  "VI_1"
#	list group		  "VI_2"

are not needed leave it as it is

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added some documentation for the new option here. Is the documentation not needed?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s fine that this is documented. But you’ve changed lines that you didn’t need to change.

# Note that priority will not work with vrrp_script
# when in sync group
# list track_script "vrrp_script1"
Comment on lines +79 to +83
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sync-group example now shows list track_script "vrrp_script1", but the config template still includes (elsewhere) the old config track_script sections and vrrp_instance examples referencing track_script1/track_script2. Since the init script now looks up track_script entries via vrrp_script sections, please update the remaining examples to reference vrrp_script names (and remove/adjust the config track_script examples) to avoid misleading users and potential breakage on upgrade.

Copilot uses AI. Check for mistakes.
# option smtp_alert "1"
# option global_tracking 1

Expand All @@ -101,6 +104,29 @@ config globals 'globals'
# option value "<script-file2>"
# option weight "2"

#config bfd_instance
# option name "bfd_instance1"
# option neighbor_ip '192.168.10.1'
# option source_ip '192.168.20.1'
# option min_rx '300'
# option min_tx '300'
# option idle_tx "1000"
# option hoplimit '30'
# option max_hops '30'
# option weight '50'

#config peer
# option name 'peer1'
# option address '192.168.0.1'
# option min_ttl '1'
# option max_ttl '255

#config peer
# option name 'peer2'
# option address '192.168.1.1'
# option min_ttl '1'
# option max_ttl '255

#config vrrp_instance
# option name "VI_1"
# option use_vmac "eth0"
Expand All @@ -112,14 +138,15 @@ config globals 'globals'
# list track_script "track_script1"
# list track_script "track_script2"
# option dont_track_primary "1"
# list unicast_peer "192.168.0.1"
# list unicast_peer "192.168.1.1"
# list unicast_peer "peer1"
# list unicast_peer "peer2"
# list virtual_ipaddress "ipaddress2"
# list virtual_ipaddress "ipaddress3"
# list virtual_ipaddress_excluded "ipaddress4"
# list virtual_ipaddress_excluded "ipaddress5"
# list virtual_routes "route1"
# list virtual_routes "route2"
# list track_bfd "bfd_instance1"
# option mcast_src_ip "224.0.0.1"
# option unicast_src_ip "192.168.0.1"
# option virtual_router_id "128"
Expand All @@ -132,11 +159,16 @@ config globals 'globals'
# option accept "1"

#config vrrp_script
# option name "vrrp_script1"
# option script "<script-file>"
# option interval "5"
# weight will increase +10 if script status is OK, otherwise -10
# option weight "10"
# option fall "2"
# option rise "3"
# valid values for direction reverse|noreverse -- reverse flips weight change
# option direction "reverse"
# option timeout "5"
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the vrrp_script example, the newly added timeout line has inconsistent spacing (#\toption timeout "5"). For readability and consistency with the rest of the template, align it to the same option <key>\t\t"<val>" format used by the surrounding options.

Suggested change
# option timeout "5"
# option timeout "5"

Copilot uses AI. Check for mistakes.

#config virtual_server
# option enabled "1"
Expand Down Expand Up @@ -191,4 +223,3 @@ config globals 'globals'
# option name "url2"
# option path "/testurl/test2.jsp"
# option digest "22"

61 changes: 41 additions & 20 deletions net/keepalived/files/keepalived.init
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@ INDENT_4="${INDENT_1}${INDENT_1}${INDENT_1}${INDENT_1}"
config_section_open() {
local tag="$1"
local name="$2"
local indent="$3"

[ -n "$indent" ] && printf '%b' "$indent" >> "$KEEPALIVED_CONF"
printf '%s' "$tag" >> "$KEEPALIVED_CONF"
[ -n "$name" ] && printf ' %s' "$name" >> "$KEEPALIVED_CONF"
printf ' {\n' >> "$KEEPALIVED_CONF"
}

config_section_close() {
local indent="$1"
[ -n "$indent" ] && printf '%b' "$indent" >> "$KEEPALIVED_CONF"
printf '}\n\n' >> "$KEEPALIVED_CONF"
}

Expand Down Expand Up @@ -215,16 +219,14 @@ print_track_script_indent() {

local name value weight direction
config_get name "$section" name
[ "$name" != "$curr_track_elem" ] && return 0
[ -z "$name" ] && return 0

config_get value "$section" value
config_get weight "$section" weight
Comment on lines 220 to 224
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

print_track_script_indent() currently has a shell syntax error (if [ -z "$name" ] && return 0) and it no longer filters by curr_track_elem. As a result, every config_foreach ... vrrp_script invocation will print all vrrp_script sections (and, in the current loops, likely print them repeatedly), instead of only the script referenced by the list entry. Replace the invalid if with a normal test, and restore a name != curr_track_elem guard (while still printing the referenced script name).

Copilot uses AI. Check for mistakes.
config_get direction "$section" direction

[ -z "$value" ] && return 0
[ "$direction" != "reverse" ] && [ "$direction" != "noreverse" ] && unset direction

printf '%b%s' "$indent" "$value" >> "$KEEPALIVED_CONF"
printf '%b%s' "$indent" "$name" >> "$KEEPALIVED_CONF"
[ -n "$weight" ] && printf ' weight %s' "$weight ${direction:+${direction}}" >> "$KEEPALIVED_CONF"
printf '\n' >> "$KEEPALIVED_CONF"
}
Expand Down Expand Up @@ -268,15 +270,23 @@ print_unicast_peer_indent() {
local section="$1"
local curr_track_elem="$2"
local indent="$3"
local name address
local name address max_ttl min_ttl

config_get name "$section" name
[ "$name" != "$curr_track_elem" ] && return 0

config_get address "$section" address
[ -z "$address" ] && return 0

printf '%b%s\n' "${indent}" "$address">> "$KEEPALIVED_CONF"
printf '%b%s' "${indent}" "$address" >> "$KEEPALIVED_CONF"

config_get min_ttl "$section" min_ttl
config_get max_ttl "$section" max_ttl

[ -n "$min_ttl" ] && printf ' min_ttl %s' "$min_ttl" >> "$KEEPALIVED_CONF"
[ -n "$max_ttl" ] && printf ' max_ttl %s' "$max_ttl" >> "$KEEPALIVED_CONF"
printf '\n' >> "$KEEPALIVED_CONF"

}

static_routes() {
Expand Down Expand Up @@ -347,6 +357,17 @@ vrrp_sync_group() {

print_elems_indent "$1" "$INDENT_1" no_val_smtp_alert no_val_global_tracking

# Handle track_script list for sync group
local track_script_val
config_get track_script_val "$1" track_script
if [ -n "$track_script_val" ]; then
config_section_open "track_script" "" "$INDENT_1"
for t in $track_script_val; do
config_foreach print_track_script_indent vrrp_script "$t" "$INDENT_2"
done
config_section_close "$INDENT_1"
fi

print_notify "GROUP" "$name" "$INDENT_1" notify_backup notify_master \
notify_fault notify

Expand Down Expand Up @@ -387,71 +408,71 @@ vrrp_instance() {
config_get "$opt" "$1" "$opt"
eval optval=\$$opt
[ -z "$optval" ] && continue
printf '%b%s {\n' "${INDENT_1}" "$opt" >> "$KEEPALIVED_CONF"
config_section_open "$opt" "" "$INDENT_1"
for a in $optval; do
config_foreach print_ipaddress_indent ipaddress "$a" "$INDENT_2"
done
printf '%b}\n' "${INDENT_1}" >> "$KEEPALIVED_CONF"
config_section_close "$INDENT_1"
done

# Handle virtual_routes
for opt in virtual_routes; do
config_get "$opt" "$1" "$opt"
eval optval=\$$opt
[ -z "$optval" ] && continue
printf '%b%s {\n' "${INDENT_1}" "$opt" >> "$KEEPALIVED_CONF"
config_section_open "$opt" "" "$INDENT_1"
for r in $optval; do
config_foreach print_route_indent route "$r" "$INDENT_2"
done
printf '%b}\n' "${INDENT_1}" >> "$KEEPALIVED_CONF"
config_section_close "$INDENT_1"
done

# Handle track_script lists
for opt in track_script; do
config_get "$opt" "$1" "$opt"
eval optval=\$$opt
[ -z "$optval" ] && continue
printf '%b%s {\n' "${INDENT_1}" "$opt" >> "$KEEPALIVED_CONF"
config_section_open "$opt" "" "$INDENT_1"
for t in $optval; do
config_foreach print_track_script_indent track_script "$t" "$INDENT_2"
config_foreach print_track_script_indent vrrp_script "$t" "$INDENT_2"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see what you do, but can you please explain why this is needed?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently theres no support for track_script section, only for vrrp_script.
So inside print_track_script_indent what config_get does (from my understanding) is tries to fetch track_script section, which doesnt exist. But vrrp_script does.

I am not sure if this is how it was supposed to be done so correct me if I'm wrong but I tested this and it works.
In the future once track_script section is supported then we can add support for both here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the old option is still valid, we need to extend it to include the new option too. What would a correct keepalived configuration look like if both the track_script and the vrrp_script options is set in the uci.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old option doesn't exist in the code. However its still present in the keepalived.config as of now.

This is the sample configuration

config vrrp_instance 'vrrp_instance_10'
        option name 'vrrp_instance_10'
        option state 'MASTER'
        option interface 'br-i10'
        list virtual_ipaddress 'floatingIPaddr_10'
        option virtual_router_id '100'
        option priority '100'
        option advert_int '1'
        option preempt_delay '0'
        option auth_type 'PASS'
        option auth_pass 'pass'
        #list track_script 'sla_check'

config ipaddress 'floatingIPaddr_10'
        option name 'floatingIPaddr_10'
        option address '192.168.10.1/24'
        option device 'br-i10'
        option scope 'global'

config vrrp_sync_group 'vrrp_sync_group'
        option name 'sync_group'
        list group 'vrrp_instance_10'
        list track_script 'sla_check'

config vrrp_script 'sla_check'
        option name 'sla_check'
        option timeout '1'
        option interval '1'
        option fall '2'
        option rise '2'
        #option weight '50'
        option script '/etc/scripts/vrrp_sla_check.sh'

config track_script 'script1'
        option name     "track_script1"
        option value "/etc/scripts/vrrp_sla_check.sh"
        option weight   "1"

The above config generates this keepalived.conf file

! Configuration file for keepalived (autogenerated via init script)
! Written Tue Mar 31 09:39:16 2026

global_defs {
}

static_ipaddress {
}

static_routes {
}

interface_up_down_delays {
}

vrrp_script sla_check {
        script /etc/scripts/vrrp_sla_check.sh
        interval 1
        fall 2
        rise 2
        timeout 1
}

vrrp_sync_group sync_group {
        group {
                vrrp_instance_10
        }
        track_script {
                sla_check
        }
        notify_backup "/bin/busybox env -i ACTION=NOTIFY_BACKUP TYPE=GROUP NAME=sync_group /sbin/hotplug-call keepalived"
        notify_master "/bin/busybox env -i ACTION=NOTIFY_MASTER TYPE=GROUP NAME=sync_group /sbin/hotplug-call keepalived"
        notify_fault "/bin/busybox env -i ACTION=NOTIFY_FAULT TYPE=GROUP NAME=sync_group /sbin/hotplug-call keepalived"
        notify "/bin/busybox env -i ACTION=NOTIFY TYPE=GROUP NAME=sync_group /sbin/hotplug-call keepalived"
}

vrrp_instance vrrp_instance_10 {
        authentication {
                auth_type PASS
                auth_pass pass
        }
        state MASTER
        interface br-i10
        virtual_router_id 100
        priority 100
        advert_int 1
        preempt_delay 0
        notify_backup "/bin/busybox env -i ACTION=NOTIFY_BACKUP TYPE=INSTANCE NAME=vrrp_instance_10 /sbin/hotplug-call keepalived"
        notify_master "/bin/busybox env -i ACTION=NOTIFY_MASTER TYPE=INSTANCE NAME=vrrp_instance_10 /sbin/hotplug-call keepalived"
        notify_fault "/bin/busybox env -i ACTION=NOTIFY_FAULT TYPE=INSTANCE NAME=vrrp_instance_10 /sbin/hotplug-call keepalived"
        notify_stop "/bin/busybox env -i ACTION=NOTIFY_STOP TYPE=INSTANCE NAME=vrrp_instance_10 /sbin/hotplug-call keepalived"
        virtual_ipaddress {
                192.168.10.1/24 dev br-i10 label br-i10:vip scope global
        }
}

As you can see no section for track_script was generated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But then I do not understand the uci why do i have to specifies the path to the script /ec/scripts/vrr_sla_check.sh twice in vrrp_script and track_script section. In the generate keepalived.conf the track_script references only to thevrrp_script section. In your case sla_check.
I’ll have to take a closer look at that when I get the more time.

config vrrp_script 'sla_check'
        option name 'sla_check'
        option timeout '1'
        option interval '1'
        option fall '2'
        option rise '2'
        #option weight '50'
        option script '/etc/scripts/vrrp_sla_check.sh'

config track_script 'script1'
        option name     "track_script1"
        option value "/etc/scripts/vrrp_sla_check.sh"
        option weight   "1"
vrrp_script sla_check {
        script /etc/scripts/vrrp_sla_check.sh
        interval 1
        fall 2
        rise 2
        timeout 1
}

vrrp_sync_group sync_group {
        group {
                vrrp_instance_10
        }
        track_script {
                sla_check
        }
        notify_backup "/bin/busybox env -i ACTION=NOTIFY_BACKUP TYPE=GROUP NAME=sync_group /sbin/hotplug-call keepalived"
        notify_master "/bin/busybox env -i ACTION=NOTIFY_MASTER TYPE=GROUP NAME=sync_group /sbin/hotplug-call keepalived"
        notify_fault "/bin/busybox env -i ACTION=NOTIFY_FAULT TYPE=GROUP NAME=sync_group /sbin/hotplug-call keepalived"
        notify "/bin/busybox env -i ACTION=NOTIFY TYPE=GROUP NAME=sync_group /sbin/hotplug-call keepalived"
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are absolutely right, we dont need the section track_script. On reviewing the docs of keepalived, a seprate track_script section doesnt exist. My guess is that it was removed and the config file was not updated, same with the init file.

I think we should update keepalived.config accordingly

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey do you need me to do something else?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make your suggested change.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all the suggest changes have been made.

done
printf '%b}\n' "${INDENT_1}" >> "$KEEPALIVED_CONF"
config_section_close "$INDENT_1"
done

# Handle track_interface lists
for opt in track_interface; do
config_get "$opt" "$1" "$opt"
eval optval=\$$opt
[ -z "$optval" ] && continue
printf '%b%s {\n' "${INDENT_1}" "$opt" >> "$KEEPALIVED_CONF"
config_section_open "$opt" "" "$INDENT_1"
for t in $optval; do
config_foreach print_track_elem_indent track_interface "$t" "$INDENT_2"
done
printf '%b}\n' "${INDENT_1}" >> "$KEEPALIVED_CONF"
config_section_close "$INDENT_1"
done

# Handle track_bfd lists
for opt in track_bfd; do
config_get "$opt" "$1" "$opt"
eval optval=\$$opt
[ -z "$optval" ] && continue
printf '%b%s {\n' "${INDENT_1}" "$opt" >> "$KEEPALIVED_CONF"
config_section_open "$opt" "" "$INDENT_1"
for t in $optval; do
config_foreach print_track_bfd_indent bfd_instance "$t" "$INDENT_2"
done
printf '%b}\n' "${INDENT_1}" >> "$KEEPALIVED_CONF"
config_section_close "$INDENT_1"
done

# Handle simple lists of strings (with no spaces in between)
for opt in unicast_peer; do
config_get "$opt" "$1" "$opt"
eval optval=\$$opt
[ -z "$optval" ] && continue
printf '%b%s {\n' "${INDENT_1}" "$opt" >> "$KEEPALIVED_CONF"
config_section_open "$opt" "" "$INDENT_1"
for t in $optval; do
config_foreach print_unicast_peer_indent peer "$t" "$INDENT_2"
done
printf '%b}\n' "${INDENT_1}" >> "$KEEPALIVED_CONF"
config_section_close "$INDENT_1"
done
unset optval

Expand All @@ -466,7 +487,7 @@ vrrp_script() {

config_section_open "vrrp_script" "$name"

print_elems_indent "$1" "$INDENT_1" script interval weight fall rise
print_elems_indent "$1" "$INDENT_1" script interval weight fall rise timeout

config_section_close
}
Expand Down