Skip to content

Commit

Permalink
Merge pull request #2482 from pqarmitage/updates
Browse files Browse the repository at this point in the history
GARP/GNA fixes and improvements to parsing quoted strings
  • Loading branch information
pqarmitage authored Oct 21, 2024
2 parents 59c39af + 07153ca commit 06486a0
Show file tree
Hide file tree
Showing 23 changed files with 440 additions and 348 deletions.
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ AS_IF([test $? -eq 0],
# save the configure arguments
#
args=`echo $ac_configure_args | $SED -e "s/'//g"`
AS_IF([test .$enable_reproducible_build = .yes], [`echo $ac_configure_args | $SED -e "s/-ffile-prefix-map=[[^ ]]*//g"`])
AC_DEFINE_UNQUOTED(KEEPALIVED_CONFIGURE_OPTIONS,"$args", [configure options specified])
AS_IF([test .$enable_lto = .yes],
Expand Down
66 changes: 41 additions & 25 deletions doc/man/man5/keepalived.conf.5.in
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,31 @@ will be the three strings:
i.e. the " and ' characters are removed and any intervening whitespace is retained.
.PP
Quoted strings can also have escaped characters, like the shell. \\a, \\b, \\E, \\f,
\\n, \\r, \\t, \\v, \\nnn and \\xXX (where nnn is up to 3 octal digits, and XX is any
sequence of hex digits) and \\cC (which produces the control version of
character C) are all supported. \\C for any other character C is just
treated as an escaped version of character C, so \\\\ is a \\ character and
\\" will be a " character, but it won't start or terminate a quoted string.
\\n, \\r, \\t, \\v, \\nnn and \\xXX (where nnn is up to 3 octal digits, and XX is up
to two hex digits) and \\cC (which produces the control version of character C) are
all supported. \\C for any other character C is just treated as an escaped version
of character C, so \\\\ is a \\ character and \\" will be a " character, but it
won't start or terminate a quoted string.
.PP
For specifying scripts with parameters, unquoted spaces will separate the parameters.
If it is required for a parameter to contain a space, it should be enclosed in single
quotes (').
quotes ('). For example

.nf
.RS
$SG_NAME=SG1
$INST=low
$USER=user
notify_master "/etc/keepalived/notify_event.sh ' spaces\\\\x20f\\x69le ' '\\"s p a c e \\"' ${SG_NAME}.$INST master" $USER group
.RE

.fi
specifies a notify_master script /etc/keepalived/notify_event.sh that will be executed as user:group with parameters

.nf
.RS
\' spaces\\x20file \', \'"s p a c e "\', \'SG1.low\' and \'master\'
.RE

.PP
.SH CONFIGURATION PARSER
Expand Down Expand Up @@ -367,29 +383,26 @@ possibly following any cleanup actions needed.
# remove them).
\fBlvs_flush_on_stop [VS]\fR

# number of gratuitous ARP messages to send at a time after
# transition to MASTER.
# (default: 5)
\fBvrrp_garp_master_repeat \fR1

# delay for second set of gratuitous ARPs after transition to MASTER.
# in seconds, 0 for no second set.
# (default: 5)
\fBvrrp_garp_master_delay \fR10

# number of gratuitous ARP messages to send at a time after
# transition to MASTER.
# (default: 5)
\fBvrrp_garp_master_repeat \fR1
# lower priority advert received when MASTER.
# (default: vrrp_garp_master_repeat)
\fBvrrp_garp_lower_prio_repeat \fR1

# delay for second set of gratuitous ARPs after lower priority
# advert received when MASTER.
# (default: vrrp_garp_master_delay)
\fBvrrp_garp_lower_prio_delay \fR10

# Default value for vrrp down_timer_adverts.
\fBvrrp_down_timer_adverts \fR[1:100]

# number of gratuitous ARP messages to send at a time after
# lower priority advert received when MASTER.
# (default: vrrp_garp_master_repeat)
\fBvrrp_garp_lower_prio_repeat \fR1

# minimum time interval for refreshing gratuitous ARPs while MASTER.
# in seconds (resolution seconds).
# (default: 0 (no refreshing))
Expand Down Expand Up @@ -428,9 +441,12 @@ possibly following any cleanup actions needed.
# will cause it to send GARP/NA on each interface used by the VRRP instance.
\fBvrrp_garp_extra_if [all] \fR100

# Default value for vrrp down_timer_adverts.
\fBvrrp_down_timer_adverts \fR[1:100]

# If a lower priority advert is received, don't send another advert.
# This causes adherence to the RFCs. Defaults to false, unless
# strict_mode is set.
# This causes adherence to the RFCs prior to RFC9568.
# Defaults to false, unless strict_mode is set.
\fBvrrp_lower_prio_no_advert \fR[<BOOL>]

# If we are master and receive a higher priority advert, send an advert
Expand Down Expand Up @@ -731,7 +747,7 @@ possibly following any cleanup actions needed.

# script to be run by keepalived to process notify events
# The FIFO name will be passed to the script as the last parameter
\fBnotify_fifo_script \fRSTRING|QUOTED_STRING [username [groupname]]
\fBnotify_fifo_script \fRSTRING|QUOTED-STRING [username [groupname]]

# FIFO to write vrrp notify events to.
# The string written will be a line of the form: INSTANCE "VI_1" MASTER 100
Expand All @@ -742,7 +758,7 @@ possibly following any cleanup actions needed.

# script to be run by keepalived to process vrrp notify events
# The FIFO name will be passed to the script as the last parameter
\fBvrrp_notify_fifo_script \fRSTRING|QUOTED_STRING [username [groupname]]
\fBvrrp_notify_fifo_script \fRSTRING|QUOTED-STRING [username [groupname]]

# FIFO to write notify healthchecker events to
# The string written will be a line of the form:
Expand All @@ -753,7 +769,7 @@ possibly following any cleanup actions needed.

# script to be run by keepalived to process healthchecher notify events
# The FIFO name will be passed to the script as the last parameter
\fBlvs_notify_fifo_script \fRSTRING|QUOTED_STRING [username [groupname]]
\fBlvs_notify_fifo_script \fRSTRING|QUOTED-STRING [username [groupname]]

# By default, when keepalived reloads the vrrp instance and sync group states
# are not written to the relevant FIFOs. Setting this option will cause the
Expand Down Expand Up @@ -1127,7 +1143,7 @@ The syntax for track file is:

\fBtrack_file \fR<STRING> { # vrrp_track_file is a deprecated synonym
# file to track (weight defaults to 1)
\fBfile \fR<QUOTED_STRING>
\fBfile \fR<QUOTED-STRING>

# optional default weight
\fBweight \fR<-2147483647..2147483647> [reverse]
Expand Down Expand Up @@ -1155,7 +1171,7 @@ The configuration block looks like:
# process "@KA_TMP_DIR@/a b" param1 "param 2"
# would mean a process named '@KA_TMP_DIR@/a b' (quotes removed) with 2 parameters
# 'param1' and 'param 2'.
\fBprocess\fR <STRING>|<QUOTED_STRING> [<STRING>|<QUOTED_STRING> ...]
\fBprocess\fR <STRING>|<QUOTED-STRING> [<STRING>|<QUOTED-STRING> ...]

# If matching parameters, this specifies a partial match (i.e. the first
# n parameters match exactly), or an initial match, i.e. the last
Expand Down Expand Up @@ -1572,7 +1588,7 @@ and the limits apply to the switch as a whole.

If the global vrrp_garp_interval and/or vrrp_gna_interval are set, any
interfaces that aren't specified in a garp_group will inherit the global
settings.
settings on a per interface basis.
.PP
.nf
The syntax for garp_group is :
Expand Down
4 changes: 2 additions & 2 deletions keepalived/check/check_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ misc_path_handler(__attribute__((unused)) const vector_t *strvec)
misc_checker_t *new_misck_checker = current_checker->data;

/* We need to allow quoted and escaped strings for the script and parameters */
strvec_qe = alloc_strvec_quoted_escaped(NULL);
strvec_qe = alloc_strvec_quoted(NULL);

set_script_params_array(strvec_qe, &new_misck_checker->script, 0);

Expand Down Expand Up @@ -209,7 +209,7 @@ install_misc_check_keyword(void)
install_keyword("MISC_CHECK", &misc_check_handler);
check_ptr = install_sublevel(VPP &current_checker);
install_checker_common_keywords(false);
install_keyword("misc_path", &misc_path_handler);
install_keyword_quoted("misc_path", &misc_path_handler);
install_keyword("misc_timeout", &misc_timeout_handler);
install_keyword("misc_dynamic", &misc_dynamic_handler);
install_keyword("user", &misc_user_handler);
Expand Down
8 changes: 4 additions & 4 deletions keepalived/check/check_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -987,8 +987,8 @@ init_check_keywords(bool active)
/* Pool regression detection and handling. */
install_keyword("alpha", &vs_alpha_handler);
install_keyword("omega", &omega_handler);
install_keyword("quorum_up", &quorum_up_handler);
install_keyword("quorum_down", &quorum_down_handler);
install_keyword_quoted("quorum_up", &quorum_up_handler);
install_keyword_quoted("quorum_down", &quorum_down_handler);
install_keyword("quorum", &quorum_handler);
install_keyword("hysteresis", &hysteresis_handler);
install_keyword("weight", &vs_weight_handler);
Expand All @@ -1004,8 +1004,8 @@ init_check_keywords(bool active)
install_keyword("uthreshold", &uthreshold_handler);
install_keyword("lthreshold", &lthreshold_handler);
install_keyword("inhibit_on_failure", &rs_inhibit_handler);
install_keyword("notify_up", &notify_up_handler);
install_keyword("notify_down", &notify_down_handler);
install_keyword_quoted("notify_up", &notify_up_handler);
install_keyword_quoted("notify_down", &notify_down_handler);
install_keyword("alpha", &rs_alpha_handler);
install_keyword("retry", &rs_retry_handler);
install_keyword("delay_before_retry", &rs_delay_before_retry_handler);
Expand Down
10 changes: 5 additions & 5 deletions keepalived/core/global_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -2474,9 +2474,9 @@ init_global_keywords(bool global_active)
install_keyword("smtp_connect_timeout", &smtpto_handler);
install_keyword("notification_email", &email_handler);
install_keyword("smtp_alert", &smtp_alert_handler);
install_keyword("startup_script", &startup_script_handler);
install_keyword_quoted("startup_script", &startup_script_handler);
install_keyword("startup_script_timeout", &startup_script_timeout_handler);
install_keyword("shutdown_script", &shutdown_script_handler);
install_keyword_quoted("shutdown_script", &shutdown_script_handler);
install_keyword("shutdown_script_timeout", &shutdown_script_timeout_handler);
install_keyword("max_auto_priority", &max_auto_priority_handler);
install_keyword("min_auto_priority_delay", &min_auto_priority_delay_handler);
Expand Down Expand Up @@ -2556,16 +2556,16 @@ init_global_keywords(bool global_active)
install_keyword("vrrp_rlimit_rtime", &vrrp_rt_rlimit_handler); /* Deprecated 02/02/2020 */
#endif
install_keyword("notify_fifo", &global_notify_fifo);
install_keyword("notify_fifo_script", &global_notify_fifo_script);
install_keyword_quoted("notify_fifo_script", &global_notify_fifo_script);
#ifdef _WITH_VRRP_
install_keyword("vrrp_notify_fifo", &vrrp_notify_fifo);
install_keyword("vrrp_notify_fifo_script", &vrrp_notify_fifo_script);
install_keyword_quoted("vrrp_notify_fifo_script", &vrrp_notify_fifo_script);
install_keyword("vrrp_notify_priority_changes", &vrrp_notify_priority_changes);
install_keyword("fifo_write_vrrp_states_on_reload", &fifo_write_vrrp_states_on_reload);
#endif
#ifdef _WITH_LVS_
install_keyword("lvs_notify_fifo", &lvs_notify_fifo);
install_keyword("lvs_notify_fifo_script", &lvs_notify_fifo_script);
install_keyword_quoted("lvs_notify_fifo_script", &lvs_notify_fifo_script);
install_keyword("checker_priority", &checker_prio_handler);
install_keyword("checker_no_swap", &checker_no_swap_handler);
install_keyword("checker_rt_priority", &checker_rt_priority_handler);
Expand Down
5 changes: 1 addition & 4 deletions keepalived/include/vrrp.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,19 +299,15 @@ typedef struct _vrrp_t {
timeval_t last_transition; /* Store transition time */
unsigned garp_delay; /* Delay to launch gratuitous ARP */
timeval_t garp_refresh; /* Next scheduled gratuitous ARP refresh */
timeval_t garp_refresh_timer; /* Next scheduled gratuitous ARP timer */
unsigned garp_rep; /* gratuitous ARP repeat value */
unsigned garp_refresh_rep; /* refresh gratuitous ARP repeat value */
unsigned garp_lower_prio_delay; /* Delay to second set or ARP messages */
bool garp_pending; /* Are there gratuitous ARP messages still to be sent */
bool gna_pending; /* Are there gratuitous NA messages still to be sent */
unsigned garp_lower_prio_rep; /* Number of ARP messages to send at a time */
unsigned down_timer_adverts; /* Number of adverts missed before backup takes over as master */
unsigned lower_prio_no_advert; /* Don't send advert after lower prio advert received */
unsigned higher_prio_send_advert; /* Send advert after higher prio advert received */
#ifdef _HAVE_VRRP_VMAC_
timeval_t vmac_garp_intvl; /* Interval between GARPs on each VMAC */
timeval_t vmac_garp_timer; /* Next scheduled GARP for each VMAC */
#endif
uint8_t vrid; /* virtual id. from 1(!) to 255 */
uint8_t base_priority; /* configured priority value */
Expand Down Expand Up @@ -477,6 +473,7 @@ extern void open_sockpool_socket(sock_t *);
extern int new_vrrp_socket(vrrp_t *);
extern void vrrp_send_adv(vrrp_t *, uint8_t);
extern void vrrp_send_link_update(vrrp_t *, unsigned);
extern void vrrp_send_vmac_update(vrrp_t *);
extern void add_vrrp_to_interface(vrrp_t *, interface_t *, int, bool, bool, track_t);
extern void del_vrrp_from_interface(vrrp_t *, interface_t *);
extern bool vrrp_state_master_rx(vrrp_t *, const vrrphdr_t *, const char *, ssize_t);
Expand Down
2 changes: 1 addition & 1 deletion keepalived/include/vrrp_arp.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ typedef struct ipoib_hdr {
/* prototypes */
extern bool gratuitous_arp_init(void);
extern void gratuitous_arp_close(void);
extern void send_gratuitous_arp(vrrp_t *, ip_address_t *);
extern void send_gratuitous_arp(ip_address_t *, unsigned);
extern ssize_t send_gratuitous_arp_immediate(interface_t *, ip_address_t *);
#endif
7 changes: 5 additions & 2 deletions keepalived/include/vrrp_if.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,12 @@ typedef struct _garp_delay {
bool have_gna_interval; /* True if delay */
timeval_t garp_next_time; /* Time when next gratuitous ARP message can be sent */
timeval_t gna_next_time; /* Time when next gratuitous NA message can be sent */
int aggregation_group; /* Index of multi-interface group */

/* linked list member */
/* linked list of ip_address_t that have GARP/NAs pending */
list_head_t garp_list;
list_head_t gna_list;

/* linked list member of garp_delay_t */
list_head_t e_list;
} garp_delay_t;

Expand Down
3 changes: 2 additions & 1 deletion keepalived/include/vrrp_ipaddress.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ typedef struct _ip_address {
#ifdef _WITH_NFTABLES_
bool nftable_rule_set; /* TRUE if in nftables set */
#endif
bool garp_gna_pending; /* Is a gratuitous ARP/NA message still to be sent */
unsigned garp_gna_pending; /* Number of GARPs/GNAs still to be sent */
list_head_t garp_gna_list;
uint32_t preferred_lft; /* IPv6 preferred_lft (0 means address deprecated) */

/* linked list member */
Expand Down
2 changes: 1 addition & 1 deletion keepalived/include/vrrp_ndisc.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ struct ip6hdr {
/* prototypes */
extern bool ndisc_init(void);
extern void ndisc_close(void);
extern void ndisc_send_unsolicited_na(vrrp_t *, ip_address_t *);
extern void ndisc_send_unsolicited_na(ip_address_t *, unsigned);
extern void ndisc_send_unsolicited_na_immediate(interface_t *, ip_address_t *);

#endif
Expand Down
7 changes: 5 additions & 2 deletions keepalived/include/vrrp_scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
#include "vrrp.h"

/* global vars */
extern timeval_t garp_next_time;
extern thread_ref_t garp_thread;
extern bool vrrp_initialised;
extern timeval_t vrrp_delayed_start_time;

Expand Down Expand Up @@ -68,7 +66,12 @@ extern void cancel_vrrp_threads(void);
extern void vrrp_dispatcher_release(vrrp_data_t *);
extern void vrrp_gratuitous_arp_thread(thread_ref_t);
extern void vrrp_lower_prio_gratuitous_arp_thread(thread_ref_t);
extern void vrrp_gratuitous_arp_refresh_thread(thread_ref_t);
#ifdef _HAVE_VRRP_VMAC_
extern void vrrp_gratuitous_arp_vmac_update_thread(thread_ref_t);
#endif
extern void vrrp_arp_thread(thread_ref_t);
extern void vrrp_gna_thread(thread_ref_t);
extern void try_up_instance(vrrp_t *, bool);
#ifdef _WITH_DUMP_THREADS_
extern void dump_threads(void);
Expand Down
Loading

0 comments on commit 06486a0

Please sign in to comment.