From bc365d51dbe00b06255931d8c6a064fec45863da Mon Sep 17 00:00:00 2001 From: Quentin Armitage Date: Tue, 20 Feb 2024 00:46:12 +0000 Subject: [PATCH 1/2] build: fix building with VRRP disabled Signed-off-by: Quentin Armitage --- keepalived/core/keepalived_netlink.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/keepalived/core/keepalived_netlink.c b/keepalived/core/keepalived_netlink.c index 163b845b80..64dd6fa5d4 100644 --- a/keepalived/core/keepalived_netlink.c +++ b/keepalived/core/keepalived_netlink.c @@ -2672,6 +2672,8 @@ void register_keepalived_netlink_addresses(void) { register_thread_address("kernel_netlink", kernel_netlink); +#ifdef _WITH_VRRP_ register_thread_address("delayed_if_flags_change_thread", delayed_if_flags_change_thread); +#endif } #endif From 6eb93032a66680e86d112cffeefd679447cc6f5a Mon Sep 17 00:00:00 2001 From: Quentin Armitage Date: Tue, 20 Feb 2024 00:47:53 +0000 Subject: [PATCH 2/2] build: don't check or include some kernel headers if inappropriate for build Some kernel headers are not needed if building without IPVS support, and similarly some some kernel headers are not needed if building without VRRP support. In these cases, do not check for the existence of some of the headers at configure time, and do not include the headers at compile time. Signed-off-by: Quentin Armitage --- configure.ac | 56 +++++++++++++++++----------- keepalived/core/keepalived_netlink.c | 6 +-- keepalived/core/layer4.c | 2 + 3 files changed, 38 insertions(+), 26 deletions(-) diff --git a/configure.ac b/configure.ac index 4367bfd613..ce6af5bbc5 100644 --- a/configure.ac +++ b/configure.ac @@ -1142,37 +1142,49 @@ AC_LINK_IFELSE([AC_LANG_SOURCE([[ # Checks for header files. AC_CHECK_HEADERS([arpa/inet.h fcntl.h limits.h netdb.h netinet/in.h stdint.h stdlib.h string.h sys/ioctl.h sys/param.h sys/prctl.h sys/socket.h sys/time.h syslog.h unistd.h], [], [AC_MSG_ERROR([Missing/unusable system header file <$ac_header>])]) +AS_IF([test .$enable_lvs != .no], + [AC_CHECK_HEADERS([net/if_arp.h], + [], [AC_MSG_ERROR([Missing/unusable <$ac_header> - is glibc headers package installed?])]) + ]) # check for kernel headers SAV_CPPFLAGS="$CPPFLAGS" CPPFLAGS="$CPPFLAGS $kernelinc" -dnl -- linux/errqueue.h need sys/time.h before Linux < v5.1 -AC_MSG_CHECKING([linux/errqueue.h needs sys/time.h]) -AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ - #include - #include - - int main(void) - { - } - ]])], +AC_CHECK_HEADERS([linux/types.h], + [], [AC_MSG_ERROR([Missing/unusable kernel header file <$ac_header> - is kernel headers package installed?])]) +AS_IF([test .$enable_vrrp != .no], [ - AC_MSG_RESULT([no]) - ], + AC_CHECK_HEADERS([linux/ethtool.h linux/if_ether.h linux/if_packet.h linux/ip.h linux/sockios.h], + [], [AC_MSG_ERROR([Missing/unusable kernel header file <$ac_header> - is kernel headers package installed?])]) + AC_CHECK_HEADERS([linux/fib_rules.h linux/if_addr.h linux/if_link.h], + [], [AC_MSG_ERROR([Missing/unusable kernel header file <$ac_header> - is kernel headers package installed?])], + [[$NETLINK_EXTRA_INCLUDE]]) + ]) +AS_IF([test .$enable_lvs != .no], [ - AC_MSG_RESULT([yes]) - AC_DEFINE([ERRQUEUE_NEEDS_SYS_TIME], [ 1 ], [Define to 1 if linux/errqueue.h needs sys/time.h]) + AC_CHECK_HEADERS([linux/icmp.h linux/icmpv6.h linux/errqueue.h], + [], [AC_MSG_ERROR([Missing/unusable kernel header file <$ac_header> - is kernel headers package installed?])]) + + dnl -- linux/errqueue.h need sys/time.h before Linux < v5.1 + AC_MSG_CHECKING([linux/errqueue.h needs sys/time.h]) + AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ + #include + #include + + int main(void) + { + } + ]])], + [ + AC_MSG_RESULT([no]) + ], + [ + AC_MSG_RESULT([yes]) + AC_DEFINE([ERRQUEUE_NEEDS_SYS_TIME], [ 1 ], [Define to 1 if linux/errqueue.h needs sys/time.h]) + ]) ]) -AC_CHECK_HEADERS([asm/types.h linux/ethtool.h linux/icmpv6.h linux/if_ether.h linux/if_packet.h linux/ip.h linux/sockios.h linux/types.h], - [], [AC_MSG_ERROR([Missing/unusable kernel header file <$ac_header>])]) -AC_CHECK_HEADERS([linux/fib_rules.h linux/if_addr.h linux/if_link.h], - [], [AC_MSG_ERROR([Missing/unusable kernel header file <$ac_header>])], - [[$NETLINK_EXTRA_INCLUDE]]) -AC_CHECK_HEADERS([linux/if_arp.h], - [], [AC_MSG_ERROR([Missing/unusable <$ac_header>])], - [[#include ]]) CPPFLAGS="$SAV_CPPFLAGS" # Checks for typedefs, structures, and compiler characteristics. diff --git a/keepalived/core/keepalived_netlink.c b/keepalived/core/keepalived_netlink.c index 64dd6fa5d4..198d0e10f8 100644 --- a/keepalived/core/keepalived_netlink.c +++ b/keepalived/core/keepalived_netlink.c @@ -42,14 +42,12 @@ #include #ifdef _WITH_VRRP_ #include -#ifdef _WITH_VRRP_ #include -#endif -#endif #include +#include +#endif #include #include -#include #ifdef THREAD_DUMP #include "scheduler.h" diff --git a/keepalived/core/layer4.c b/keepalived/core/layer4.c index 64a84f7bb9..c00d0047b8 100644 --- a/keepalived/core/layer4.c +++ b/keepalived/core/layer4.c @@ -29,12 +29,14 @@ #include #include #include +#ifdef _WITH_LVS_ #include #include #ifdef ERRQUEUE_NEEDS_SYS_TIME #include #endif #include +#endif #include "layer4.h" #include "logger.h"