Skip to content

Commit 59c39af

Browse files
authored
Merge pull request #2478 from pqarmitage/updates
Various segfault fixes, compiler warnings on 32 bit systems and add milli-second timers for vrrp track scripts
2 parents d750f45 + 6f9ace3 commit 59c39af

30 files changed

+381
-166
lines changed

configure.ac

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ AC_PREREQ([2.63])
9797
AC_INIT([Keepalived], [2.3.1], [[email protected]], [], [http://www.keepalived.org/])
9898
AC_CONFIG_AUX_DIR([build-aux])
9999
AC_CONFIG_MACRO_DIR([m4])
100+
AC_LANG([C])
100101
AM_INIT_AUTOMAKE([-Wall -Werror -Woverride foreign])
101102

102103
AC_CONFIG_SRCDIR([keepalived/core/main.c])
@@ -424,6 +425,15 @@ ENABLE_LOG_FILE_APPEND=No
424425
425426
# AC_PROG_LIBTOOL
426427
428+
# Ensure we don't override FORTIFY_SOURCE
429+
ADD_FORTIFY_SOURCE=1
430+
grep -q -- "-D *_FORTIFY_SOURCE=" <<<$CPPFLAGS
431+
AS_IF([test $? -eq 0],
432+
[
433+
FORTIFY_SOURCE=$(<<<$CPPFLAGS $SED -e "s/.*-D *_FORTIFY_SOURCE=//" -e "s/ .*//")
434+
ADD_FORTIFY_SOURCE=0
435+
],[FORTIFY_SOURCE=2])
436+
427437
#
428438
# save the configure arguments
429439
#
@@ -655,6 +665,61 @@ AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
655665
])
656666
CFLAGS=$SAV_CFLAGS
657667
668+
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!)
669+
dnl -- normally all the fields are long int
670+
AC_MSG_CHECKING([time print types])
671+
AH_TEMPLATE([PRI_time_t], [Define for print format for time_t])
672+
AH_TEMPLATE([PRI_tv_sec], [Define for print format for struct timeval tv_sec])
673+
AH_TEMPLATE([PRI_tv_usec], [Define for print format for struct timeval tv_usec])
674+
AH_TEMPLATE([PRI_ts_sec], [Define for print format for struct timespec tv_sec])
675+
AH_TEMPLATE([PRI_ts_nsec], [Define for print format for struct timespec tv_nsec])
676+
SAV_CFLAGS=$CFLAGS
677+
CFLAGS="$CFLAGS -Wformat -Wformat-signedness"
678+
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
679+
int main(void)
680+
{
681+
}
682+
]])],
683+
[
684+
signs="d u"
685+
WARN_SIGN="-Werror=format-signedness"
686+
],
687+
[
688+
signs="d"
689+
WARN_SIGN=""
690+
])
691+
CFLAGS="$CFLAGS -Werror=format $WARN_SIGN"
692+
for field in t tv.tv_sec tv.tv_usec ts.tv_sec ts.tv_nsec; do
693+
for sign in $signs; do
694+
for len in "" l ll; do
695+
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
696+
#include <time.h>
697+
#include <sys/time.h>
698+
#include <stdio.h>
699+
700+
int main(void)
701+
{
702+
time_t t = 1;
703+
struct timeval tv = { .tv_sec = 2 };
704+
struct timespec ts = { .tv_sec = 3 };
705+
706+
printf("%$len$sign", $field);
707+
}
708+
]])],
709+
[
710+
if [[ $field = t ]]; then
711+
name=time_t
712+
else
713+
name=$(<<<$field $SED -e "s/\.tv//")
714+
fi
715+
AC_DEFINE_UNQUOTED([PRI_$name], [ "$len$sign" ])
716+
], [])
717+
done
718+
done
719+
done
720+
CFLAGS=$SAV_CFLAGS
721+
AC_MSG_RESULT([done])
722+
658723
dnl -- Check for diagnostic pragmas in functions - GCC 4.6.0
659724
AC_MSG_CHECKING([diagnostic pragmas in functions])
660725
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
@@ -705,7 +770,8 @@ if test "$enable_conversion_checks" = yes; then
705770
# Check if we can sensibly enable -Wconversion
706771
AC_MSG_CHECKING([for usable -Wconversion])
707772
SAV_CFLAGS="$CFLAGS"
708-
CFLAGS="$CFLAGS -Wconversion -O2 -Wp,-D_FORTIFY_SOURCE=2 -Werror"
773+
CFLAGS="$CFLAGS -Wconversion -O2 -Werror"
774+
AS_IF([test $ADD_FORTIFY_SOURCE -eq 1], [CFLAGS="$CFLAGS -Wp,-D_FORTIFY_SOURCE=$FORTIFY_SOURCE"])
709775
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
710776
#include <sys/types.h>
711777
#include <sys/select.h>
@@ -939,7 +1005,7 @@ if test "$enable_hardening" != no; then
9391005
9401006
for FLAG in \
9411007
"-Wformat -Werror=format-security" \
942-
"-Wp,-D_FORTIFY_SOURCE=2" \
1008+
"-Wp,-D_FORTIFY_SOURCE=$FORTIFY_SOURCE" \
9431009
"-fexceptions" \
9441010
"-fstack-protector-strong" \
9451011
"--param=ssp-buffer-size=4" \

doc/KEEPALIVED-MIB.txt

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ IMPORTS
2222
FROM SNMPv2-TC;
2323

2424
keepalived MODULE-IDENTITY
25-
LAST-UPDATED "202404050001Z"
25+
LAST-UPDATED "202410040001Z"
2626
ORGANIZATION "Keepalived"
2727
CONTACT-INFO "http://www.keepalived.org"
2828
DESCRIPTION
2929
"This MIB describes objects used by keepalived, both
3030
for VRRP and health checker."
31+
REVISION "202410040001Z"
32+
DESCRIPTION "add VrrpSciptIntervalUsec and VrrpScriptTimeoutUsec for higher resolution timers"
3133
REVISION "202404050001Z"
3234
DESCRIPTION "add missing 64 bit counters for 64 bit stats"
3335
REVISION "202403180001Z"
@@ -2592,7 +2594,9 @@ VrrpScriptEntry ::= SEQUENCE {
25922594
vrrpScriptRise Unsigned32,
25932595
vrrpScriptFall Unsigned32,
25942596
vrrpScriptWgtRev Integer32,
2595-
vrrpScriptPath DisplayString
2597+
vrrpScriptPath DisplayString,
2598+
vrrpScriptIntervalUsec Unsigned32,
2599+
vrrpScriptTimeoutUsec Unsigned32
25962600
}
25972601

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

2688+
vrrpScriptIntervalUsec OBJECT-TYPE
2689+
SYNTAX Unsigned32
2690+
UNITS "micro-seconds"
2691+
MAX-ACCESS read-only
2692+
STATUS current
2693+
DESCRIPTION
2694+
"Interval in micro-seconds between two runs of the script."
2695+
::= { vrrpScriptEntry 11 }
2696+
2697+
vrrpScriptTimeoutUsec OBJECT-TYPE
2698+
SYNTAX Unsigned32
2699+
UNITS "micro-seconds"
2700+
MAX-ACCESS read-only
2701+
STATUS current
2702+
DESCRIPTION
2703+
"Timeout in micro-seconds for a run of the script."
2704+
::= { vrrpScriptEntry 12 }
2705+
26842706
-- VRRP files
26852707
-- see vrrp_track.h
26862708

@@ -5225,7 +5247,9 @@ vrrpScriptGroup OBJECT-GROUP
52255247
vrrpScriptRise,
52265248
vrrpScriptFall,
52275249
vrrpScriptWgtRev,
5228-
vrrpScriptPath
5250+
vrrpScriptPath,
5251+
vrrpScriptIntervalUsec,
5252+
vrrpScriptTimeoutUsec
52295253
}
52305254
STATUS current
52315255
DESCRIPTION

doc/man/man5/keepalived.conf.5.in

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,9 +1326,15 @@ The syntax for bfd instance is :
13261326
# Default tracking weight
13271327
# Normally, positive weights are added to the vrrp instance priority when
13281328
# the bfd instance is up, negative weights reduce the priority when it is down.
1329-
# However, if reverse is specified, the priority is decreased when up and
1330-
# increased when down. 'weight 0 reverse' will cause the vrrp instance to be down
1331-
# when the bfd instance is up, and vice versa.
1329+
# However, if reverse is specified, a positive weight decreases the priority the
1330+
# script is up, and a negative weight increases the priority when the script is
1331+
# 'weight 0 reverse' will cause the vrrp instance to be down when the bfd
1332+
# instance is up, and vice versa.
1333+
# Weight Reverse Script up Script down
1334+
# +ve No prio + -
1335+
# -ve No - prio -
1336+
# +ve Yes prio - -
1337+
# -ve Yes - prio +
13321338
\fBweight\fR <-253:253> [reverse]
13331339

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

1376-
# seconds between script invocations, (default: 1 second)
1377-
\fBinterval \fR<INTEGER>
1382+
# seconds between script invocations, (default: 1 second, resolution milliseconds)
1383+
\fBinterval \fR<DECIMAL>
13781384

1379-
# seconds after which script is considered to have failed
1380-
\fBtimeout \fR<INTEGER>
1385+
# seconds after which script is considered to have failed (default = interval, resolution milliseconds)
1386+
\fBtimeout \fR<DECIMAL>
13811387

13821388
# adjust priority by this weight, (default: 0)
13831389
# For description of reverse, see track_script.

keepalived/bfd/bfd_data.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ alloc_bfd(const char *name)
5454
" name too long (maximum length is %zu"
5555
" characters) - ignoring", name,
5656
sizeof(bfd->iname) - 1);
57-
return false;
57+
return NULL;
5858
}
5959

6060
if (find_bfd_by_name(name)) {
6161
report_config_error(CONFIG_GENERAL_ERROR,
6262
"Configuration error: BFD instance %s"
6363
" already configured - ignoring", name);
64-
return false;
64+
return NULL;
6565
}
6666

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

126126
/* Dump BFD instance configuration parameters */
@@ -186,7 +186,7 @@ dump_bfd(FILE *fp, const bfd_t *bfd)
186186
conf_write(fp, " last_seen = [never]");
187187
else {
188188
ctime_r(&bfd->last_seen.tv_sec, time_str);
189-
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);
189+
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);
190190
}
191191
}
192192
}

keepalived/check/check_http.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ free_url(url_t *url)
196196

197197
#ifdef _WITH_REGEX_TIMERS_
198198
if (do_regex_timers)
199-
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);
199+
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);
200200
#endif
201201
}
202202
}

keepalived/check/check_misc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ dump_misc_check(FILE *fp, const checker_t *checker)
7676
conf_write(fp, " dynamic = %s", misck_checker->dynamic ? "YES" : "NO");
7777
conf_write(fp, " uid:gid = %u:%u", misck_checker->script.uid, misck_checker->script.gid);
7878
ctime_r(&misck_checker->last_ran.tv_sec, time_str);
79-
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);
79+
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);
8080
conf_write(fp, " Last status = %u", misck_checker->last_exit_code);
8181
}
8282

keepalived/check/check_parser.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -545,12 +545,18 @@ pgr_handler(const vector_t *strvec)
545545
}
546546
#endif
547547

548-
/* Cast via void * to stop -Wcast-align warning.
549-
* Since alignment of struct addrinfo >= alignment of struct sockaddr_in and res->ai_addr is
550-
* aligned to a struct addrinfo, it is not a problem.
551-
* e.g. vs->persistence_granularity = ((struct sockaddr_in *)((void *)res->ai_addr))->sin_addr.s_addr;
548+
/* On 32 bit systems, gcc produces a warning : cast increases required alignment of target type [-Wcast-align]
549+
* for
550+
* current_vs->persistence_granularity = ((struct sockaddr_in *)res->ai_addr)->sin_addr.s_addr;
552551
*/
553-
current_vs->persistence_granularity = ((struct sockaddr_in *)res->ai_addr)->sin_addr.s_addr;
552+
union {
553+
struct sockaddr sa;
554+
struct sockaddr_in sa_in;
555+
} sa;
556+
557+
sa.sa = *res->ai_addr;
558+
current_vs->persistence_granularity = sa.sa_in.sin_addr.s_addr;
559+
554560
freeaddrinfo(res);
555561
}
556562

keepalived/core/global_data.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ dump_global_data(FILE *fp, data_t * data)
746746
conf_write(fp, " Gratuitous ARP delay = %u",
747747
data->vrrp_garp_delay/TIMER_HZ);
748748
conf_write(fp, " Gratuitous ARP repeat = %u", data->vrrp_garp_rep);
749-
conf_write(fp, " Gratuitous ARP refresh timer = %ld", data->vrrp_garp_refresh.tv_sec);
749+
conf_write(fp, " Gratuitous ARP refresh timer = %" PRI_tv_sec, data->vrrp_garp_refresh.tv_sec);
750750
conf_write(fp, " Gratuitous ARP refresh repeat = %u", data->vrrp_garp_refresh_rep);
751751
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);
752752
conf_write(fp, " Gratuitous ARP lower priority repeat = %u", data->vrrp_garp_lower_prio_rep);
@@ -814,7 +814,7 @@ dump_global_data(FILE *fp, data_t * data)
814814
conf_write(fp, " Max auto priority = Disabled");
815815
else
816816
conf_write(fp, " Max auto priority = %d", data->max_auto_priority);
817-
conf_write(fp, " Min auto priority delay = %ld usecs", data->min_auto_priority_delay);
817+
conf_write(fp, " Min auto priority delay = %u usecs", data->min_auto_priority_delay);
818818
conf_write(fp, " VRRP process priority = %d", data->vrrp_process_priority);
819819
conf_write(fp, " VRRP don't swap = %s", data->vrrp_no_swap ? "true" : "false");
820820
conf_write(fp, " VRRP realtime priority = %u", data->vrrp_realtime_priority);

keepalived/core/global_parser.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,13 +403,13 @@ max_auto_priority_handler(const vector_t *strvec)
403403
static void
404404
min_auto_priority_delay_handler(const vector_t *strvec)
405405
{
406-
int delay;
406+
unsigned delay;
407407

408408
if (vector_size(strvec) < 2) {
409409
report_config_error(CONFIG_GENERAL_ERROR, "min_auto_priority_delay requires delay time");
410410
return;
411411
}
412-
if (!read_int_strvec(strvec, 1, &delay, 1, 10000000, true)) {
412+
if (!read_unsigned_strvec(strvec, 1, &delay, 1U, 10000000U, true)) {
413413
report_config_error(CONFIG_GENERAL_ERROR, "min_auto_priority_delay '%s' must be in [1, 10000000] - ignoring", strvec_slot(strvec, 1));
414414
return;
415415
}

0 commit comments

Comments
 (0)