Skip to content

Commit

Permalink
build: don't check or include some kernel headers if inappropriate fo…
Browse files Browse the repository at this point in the history
…r 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 <quentin@armitage.org.uk>
  • Loading branch information
pqarmitage committed Feb 20, 2024
1 parent bc365d5 commit 6eb9303
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 26 deletions.
56 changes: 34 additions & 22 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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 <fcntl.h>
#include <linux/errqueue.h>
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 <fcntl.h>
#include <linux/errqueue.h>
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 <sys/socket.h>]])
CPPFLAGS="$SAV_CPPFLAGS"
# Checks for typedefs, structures, and compiler characteristics.
Expand Down
6 changes: 2 additions & 4 deletions keepalived/core/keepalived_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,12 @@
#include <time.h>
#ifdef _WITH_VRRP_
#include <linux/version.h>
#ifdef _WITH_VRRP_
#include <linux/fib_rules.h>
#endif
#endif
#include <linux/ip.h>
#include <linux/if_link.h>
#endif
#include <unistd.h>
#include <inttypes.h>
#include <linux/if_link.h>

#ifdef THREAD_DUMP
#include "scheduler.h"
Expand Down
2 changes: 2 additions & 0 deletions keepalived/core/layer4.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@
#include <fcntl.h>
#include <netinet/in.h>
#include <net/if.h>
#ifdef _WITH_LVS_
#include <linux/icmp.h>
#include <linux/icmpv6.h>
#ifdef ERRQUEUE_NEEDS_SYS_TIME
#include <sys/time.h>
#endif
#include <linux/errqueue.h>
#endif

#include "layer4.h"
#include "logger.h"
Expand Down

0 comments on commit 6eb9303

Please sign in to comment.