Skip to content

Commit

Permalink
Merge pull request #2478 from pqarmitage/updates
Browse files Browse the repository at this point in the history
Various segfault fixes, compiler warnings on 32 bit systems and add milli-second timers for vrrp track scripts
  • Loading branch information
pqarmitage authored Oct 8, 2024
2 parents d750f45 + 6f9ace3 commit 59c39af
Show file tree
Hide file tree
Showing 30 changed files with 381 additions and 166 deletions.
70 changes: 68 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ AC_PREREQ([2.63])
AC_INIT([Keepalived], [2.3.1], [[email protected]], [], [http://www.keepalived.org/])
AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_MACRO_DIR([m4])
AC_LANG([C])
AM_INIT_AUTOMAKE([-Wall -Werror -Woverride foreign])

AC_CONFIG_SRCDIR([keepalived/core/main.c])
Expand Down Expand Up @@ -424,6 +425,15 @@ ENABLE_LOG_FILE_APPEND=No
# AC_PROG_LIBTOOL
# Ensure we don't override FORTIFY_SOURCE
ADD_FORTIFY_SOURCE=1
grep -q -- "-D *_FORTIFY_SOURCE=" <<<$CPPFLAGS
AS_IF([test $? -eq 0],
[
FORTIFY_SOURCE=$(<<<$CPPFLAGS $SED -e "s/.*-D *_FORTIFY_SOURCE=//" -e "s/ .*//")
ADD_FORTIFY_SOURCE=0
],[FORTIFY_SOURCE=2])
#
# save the configure arguments
#
Expand Down Expand Up @@ -655,6 +665,61 @@ AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
])
CFLAGS=$SAV_CFLAGS
dnl -- printing time types (32 bit Ubuntu uses long long int for time_t timeval tv_sec/tv_usec and timespec tv_sec - but timespec tv_nsec is long int!)
dnl -- normally all the fields are long int
AC_MSG_CHECKING([time print types])
AH_TEMPLATE([PRI_time_t], [Define for print format for time_t])
AH_TEMPLATE([PRI_tv_sec], [Define for print format for struct timeval tv_sec])
AH_TEMPLATE([PRI_tv_usec], [Define for print format for struct timeval tv_usec])
AH_TEMPLATE([PRI_ts_sec], [Define for print format for struct timespec tv_sec])
AH_TEMPLATE([PRI_ts_nsec], [Define for print format for struct timespec tv_nsec])
SAV_CFLAGS=$CFLAGS
CFLAGS="$CFLAGS -Wformat -Wformat-signedness"
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
int main(void)
{
}
]])],
[
signs="d u"
WARN_SIGN="-Werror=format-signedness"
],
[
signs="d"
WARN_SIGN=""
])
CFLAGS="$CFLAGS -Werror=format $WARN_SIGN"
for field in t tv.tv_sec tv.tv_usec ts.tv_sec ts.tv_nsec; do
for sign in $signs; do
for len in "" l ll; do
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
#include <time.h>
#include <sys/time.h>
#include <stdio.h>
int main(void)
{
time_t t = 1;
struct timeval tv = { .tv_sec = 2 };
struct timespec ts = { .tv_sec = 3 };
printf("%$len$sign", $field);
}
]])],
[
if [[ $field = t ]]; then
name=time_t
else
name=$(<<<$field $SED -e "s/\.tv//")
fi
AC_DEFINE_UNQUOTED([PRI_$name], [ "$len$sign" ])
], [])
done
done
done
CFLAGS=$SAV_CFLAGS
AC_MSG_RESULT([done])
dnl -- Check for diagnostic pragmas in functions - GCC 4.6.0
AC_MSG_CHECKING([diagnostic pragmas in functions])
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
Expand Down Expand Up @@ -705,7 +770,8 @@ if test "$enable_conversion_checks" = yes; then
# Check if we can sensibly enable -Wconversion
AC_MSG_CHECKING([for usable -Wconversion])
SAV_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -Wconversion -O2 -Wp,-D_FORTIFY_SOURCE=2 -Werror"
CFLAGS="$CFLAGS -Wconversion -O2 -Werror"
AS_IF([test $ADD_FORTIFY_SOURCE -eq 1], [CFLAGS="$CFLAGS -Wp,-D_FORTIFY_SOURCE=$FORTIFY_SOURCE"])
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
#include <sys/types.h>
#include <sys/select.h>
Expand Down Expand Up @@ -939,7 +1005,7 @@ if test "$enable_hardening" != no; then
for FLAG in \
"-Wformat -Werror=format-security" \
"-Wp,-D_FORTIFY_SOURCE=2" \
"-Wp,-D_FORTIFY_SOURCE=$FORTIFY_SOURCE" \
"-fexceptions" \
"-fstack-protector-strong" \
"--param=ssp-buffer-size=4" \
Expand Down
30 changes: 27 additions & 3 deletions doc/KEEPALIVED-MIB.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ IMPORTS
FROM SNMPv2-TC;

keepalived MODULE-IDENTITY
LAST-UPDATED "202404050001Z"
LAST-UPDATED "202410040001Z"
ORGANIZATION "Keepalived"
CONTACT-INFO "http://www.keepalived.org"
DESCRIPTION
"This MIB describes objects used by keepalived, both
for VRRP and health checker."
REVISION "202410040001Z"
DESCRIPTION "add VrrpSciptIntervalUsec and VrrpScriptTimeoutUsec for higher resolution timers"
REVISION "202404050001Z"
DESCRIPTION "add missing 64 bit counters for 64 bit stats"
REVISION "202403180001Z"
Expand Down Expand Up @@ -2592,7 +2594,9 @@ VrrpScriptEntry ::= SEQUENCE {
vrrpScriptRise Unsigned32,
vrrpScriptFall Unsigned32,
vrrpScriptWgtRev Integer32,
vrrpScriptPath DisplayString
vrrpScriptPath DisplayString,
vrrpScriptIntervalUsec Unsigned32,
vrrpScriptTimeoutUsec Unsigned32
}

vrrpScriptIndex OBJECT-TYPE
Expand Down Expand Up @@ -2681,6 +2685,24 @@ vrrpScriptPath OBJECT-TYPE
"Path to file to be executed when running the script."
::= { vrrpScriptEntry 10 }

vrrpScriptIntervalUsec OBJECT-TYPE
SYNTAX Unsigned32
UNITS "micro-seconds"
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"Interval in micro-seconds between two runs of the script."
::= { vrrpScriptEntry 11 }

vrrpScriptTimeoutUsec OBJECT-TYPE
SYNTAX Unsigned32
UNITS "micro-seconds"
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"Timeout in micro-seconds for a run of the script."
::= { vrrpScriptEntry 12 }

-- VRRP files
-- see vrrp_track.h

Expand Down Expand Up @@ -5225,7 +5247,9 @@ vrrpScriptGroup OBJECT-GROUP
vrrpScriptRise,
vrrpScriptFall,
vrrpScriptWgtRev,
vrrpScriptPath
vrrpScriptPath,
vrrpScriptIntervalUsec,
vrrpScriptTimeoutUsec
}
STATUS current
DESCRIPTION
Expand Down
20 changes: 13 additions & 7 deletions doc/man/man5/keepalived.conf.5.in
Original file line number Diff line number Diff line change
Expand Up @@ -1326,9 +1326,15 @@ The syntax for bfd instance is :
# Default tracking weight
# Normally, positive weights are added to the vrrp instance priority when
# the bfd instance is up, negative weights reduce the priority when it is down.
# However, if reverse is specified, the priority is decreased when up and
# increased when down. 'weight 0 reverse' will cause the vrrp instance to be down
# when the bfd instance is up, and vice versa.
# However, if reverse is specified, a positive weight decreases the priority the
# script is up, and a negative weight increases the priority when the script is
# 'weight 0 reverse' will cause the vrrp instance to be down when the bfd
# instance is up, and vice versa.
# Weight Reverse Script up Script down
# +ve No prio + -
# -ve No - prio -
# +ve Yes prio - -
# -ve Yes - prio +
\fBweight\fR <-253:253> [reverse]

# Normally bfd event notifications are sent to both the VRRP and checker processes.
Expand Down Expand Up @@ -1373,11 +1379,11 @@ The syntax for the vrrp script is:
# path of the script to execute
\fBscript \fR<STRING>|<QUOTED-STRING>

# seconds between script invocations, (default: 1 second)
\fBinterval \fR<INTEGER>
# seconds between script invocations, (default: 1 second, resolution milliseconds)
\fBinterval \fR<DECIMAL>

# seconds after which script is considered to have failed
\fBtimeout \fR<INTEGER>
# seconds after which script is considered to have failed (default = interval, resolution milliseconds)
\fBtimeout \fR<DECIMAL>

# adjust priority by this weight, (default: 0)
# For description of reverse, see track_script.
Expand Down
8 changes: 4 additions & 4 deletions keepalived/bfd/bfd_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ alloc_bfd(const char *name)
" name too long (maximum length is %zu"
" characters) - ignoring", name,
sizeof(bfd->iname) - 1);
return false;
return NULL;
}

if (find_bfd_by_name(name)) {
report_config_error(CONFIG_GENERAL_ERROR,
"Configuration error: BFD instance %s"
" already configured - ignoring", name);
return false;
return NULL;
}

PMALLOC(bfd);
Expand Down Expand Up @@ -120,7 +120,7 @@ conf_write_sands(FILE *fp, const char *text, unsigned long sands)
secs = sands / TIMER_HZ;
if (!ctime_r(&secs, time_str))
strcpy(time_str, "invalid time ");
conf_write(fp, " %s = %ld.%6.6lu (%.19s.%6.6lu)", text, secs, sands % TIMER_HZ, time_str, sands % TIMER_HZ);
conf_write(fp, " %s = %" PRI_time_t ".%6.6lu (%.19s.%6.6lu)", text, secs, sands % TIMER_HZ, time_str, sands % TIMER_HZ);
}

/* Dump BFD instance configuration parameters */
Expand Down Expand Up @@ -186,7 +186,7 @@ dump_bfd(FILE *fp, const bfd_t *bfd)
conf_write(fp, " last_seen = [never]");
else {
ctime_r(&bfd->last_seen.tv_sec, time_str);
conf_write(fp, " last seen = %ld.%6.6ld (%.24s.%6.6ld)", bfd->last_seen.tv_sec, bfd->last_seen.tv_usec, time_str, bfd->last_seen.tv_usec);
conf_write(fp, " last seen = %" PRI_tv_sec ".%6.6" PRI_tv_usec " (%.24s.%6.6" PRI_tv_usec ")", bfd->last_seen.tv_sec, bfd->last_seen.tv_usec, time_str, bfd->last_seen.tv_usec);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion keepalived/check/check_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ free_url(url_t *url)

#ifdef _WITH_REGEX_TIMERS_
if (do_regex_timers)
log_message(LOG_INFO, "Total regex time %ld.%9.9ld, num match calls %u, num url checks %u", total_regex_times.tv_sec, total_regex_times.tv_nsec, total_num_matches, total_regex_urls);
log_message(LOG_INFO, "Total regex time %" PRI_ts_sec ".%9.9" PRI_ts_nsec ", num match calls %u, num url checks %u", total_regex_times.tv_sec, total_regex_times.tv_nsec, total_num_matches, total_regex_urls);
#endif
}
}
Expand Down
2 changes: 1 addition & 1 deletion keepalived/check/check_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ dump_misc_check(FILE *fp, const checker_t *checker)
conf_write(fp, " dynamic = %s", misck_checker->dynamic ? "YES" : "NO");
conf_write(fp, " uid:gid = %u:%u", misck_checker->script.uid, misck_checker->script.gid);
ctime_r(&misck_checker->last_ran.tv_sec, time_str);
conf_write(fp, " Last ran = %ld.%6.6ld (%.24s.%6.6ld)", misck_checker->last_ran.tv_sec, misck_checker->last_ran.tv_usec, time_str, misck_checker->last_ran.tv_usec);
conf_write(fp, " Last ran = %" PRI_tv_sec ".%6.6" PRI_tv_usec " (%.24s.%6.6" PRI_tv_usec ")", misck_checker->last_ran.tv_sec, misck_checker->last_ran.tv_usec, time_str, misck_checker->last_ran.tv_usec);
conf_write(fp, " Last status = %u", misck_checker->last_exit_code);
}

Expand Down
16 changes: 11 additions & 5 deletions keepalived/check/check_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -545,12 +545,18 @@ pgr_handler(const vector_t *strvec)
}
#endif

/* Cast via void * to stop -Wcast-align warning.
* Since alignment of struct addrinfo >= alignment of struct sockaddr_in and res->ai_addr is
* aligned to a struct addrinfo, it is not a problem.
* e.g. vs->persistence_granularity = ((struct sockaddr_in *)((void *)res->ai_addr))->sin_addr.s_addr;
/* On 32 bit systems, gcc produces a warning : cast increases required alignment of target type [-Wcast-align]
* for
* current_vs->persistence_granularity = ((struct sockaddr_in *)res->ai_addr)->sin_addr.s_addr;
*/
current_vs->persistence_granularity = ((struct sockaddr_in *)res->ai_addr)->sin_addr.s_addr;
union {
struct sockaddr sa;
struct sockaddr_in sa_in;
} sa;

sa.sa = *res->ai_addr;
current_vs->persistence_granularity = sa.sa_in.sin_addr.s_addr;

freeaddrinfo(res);
}

Expand Down
4 changes: 2 additions & 2 deletions keepalived/core/global_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ dump_global_data(FILE *fp, data_t * data)
conf_write(fp, " Gratuitous ARP delay = %u",
data->vrrp_garp_delay/TIMER_HZ);
conf_write(fp, " Gratuitous ARP repeat = %u", data->vrrp_garp_rep);
conf_write(fp, " Gratuitous ARP refresh timer = %ld", data->vrrp_garp_refresh.tv_sec);
conf_write(fp, " Gratuitous ARP refresh timer = %" PRI_tv_sec, data->vrrp_garp_refresh.tv_sec);
conf_write(fp, " Gratuitous ARP refresh repeat = %u", data->vrrp_garp_refresh_rep);
conf_write(fp, " Gratuitous ARP lower priority delay = %u", data->vrrp_garp_lower_prio_delay == PARAMETER_UNSET ? PARAMETER_UNSET : data->vrrp_garp_lower_prio_delay / TIMER_HZ);
conf_write(fp, " Gratuitous ARP lower priority repeat = %u", data->vrrp_garp_lower_prio_rep);
Expand Down Expand Up @@ -814,7 +814,7 @@ dump_global_data(FILE *fp, data_t * data)
conf_write(fp, " Max auto priority = Disabled");
else
conf_write(fp, " Max auto priority = %d", data->max_auto_priority);
conf_write(fp, " Min auto priority delay = %ld usecs", data->min_auto_priority_delay);
conf_write(fp, " Min auto priority delay = %u usecs", data->min_auto_priority_delay);
conf_write(fp, " VRRP process priority = %d", data->vrrp_process_priority);
conf_write(fp, " VRRP don't swap = %s", data->vrrp_no_swap ? "true" : "false");
conf_write(fp, " VRRP realtime priority = %u", data->vrrp_realtime_priority);
Expand Down
4 changes: 2 additions & 2 deletions keepalived/core/global_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -403,13 +403,13 @@ max_auto_priority_handler(const vector_t *strvec)
static void
min_auto_priority_delay_handler(const vector_t *strvec)
{
int delay;
unsigned delay;

if (vector_size(strvec) < 2) {
report_config_error(CONFIG_GENERAL_ERROR, "min_auto_priority_delay requires delay time");
return;
}
if (!read_int_strvec(strvec, 1, &delay, 1, 10000000, true)) {
if (!read_unsigned_strvec(strvec, 1, &delay, 1U, 10000000U, true)) {
report_config_error(CONFIG_GENERAL_ERROR, "min_auto_priority_delay '%s' must be in [1, 10000000] - ignoring", strvec_slot(strvec, 1));
return;
}
Expand Down
Loading

0 comments on commit 59c39af

Please sign in to comment.