Skip to content

Fix some additional RHEL 7 etc compilation problems #2615

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2126,6 +2126,11 @@ if test .${enable_nftables} != .no; then

# NFTNL_SET_EXPR since Linux 5.7, libnftnl 1.1.7, nft 0.9.5 - counters on set elements
AC_CHECK_DECLS([NFTNL_SET_EXPR], [], [], [[#include <libnftnl/set.h>]])

SAV_LIBS="$LIBS"
LIBS="$LIBS $(pkg-config --libs libmnl)"
AC_CHECK_FUNCS([mnl_socket_open2], [AC_DEFINE([HAVE_MNL_SOCKET_OPEN2], [ 1 ], [Define to 1 if have mnl_socket_open2()])])
LIBS="$SAV_LIBS"
fi
fi
CPPFLAGS="$SAV_CPPFLAGS"
Expand Down Expand Up @@ -2381,12 +2386,12 @@ if test "$enable_vrrp" != no; then
#include <sys/socket.h>
#include <linux/if_link.h>
]])
dnl - IPVLAN_MODE_L3S since Linux 4.9, IFLA_IPVLAN_FLAGS since Linux 4.15
AC_CHECK_DECLS([IPVLAN_MODE_L3S, IFLA_IPVLAN_FLAGS], [], [],
[[
#include <linux/if_link.h>
]])
if test $IPVLAN_SUPPORT = Yes; then
dnl - IPVLAN_MODE_L3S since Linux 4.9, IFLA_IPVLAN_FLAGS since Linux 4.15
AC_CHECK_DECLS([IPVLAN_MODE_L3S, IFLA_IPVLAN_FLAGS], [], [],
[[
#include <linux/if_link.h>
]])
AC_DEFINE([_HAVE_VRRP_IPVLAN_], [ 1 ], [Define to 1 if have IP VLAN support])
add_system_opt([VRRP_IPVLAN])
fi
Expand Down
11 changes: 11 additions & 0 deletions keepalived/core/nftables.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
#include <libnftnl/set.h>
#include <libnftnl/rule.h>
#include <libnftnl/expr.h>
#ifndef HAVE_MNL_SOCKET_OPEN2
#include <fcntl.h>
#endif

#include <netinet/ip.h>
#include <netinet/ip6.h>
Expand Down Expand Up @@ -139,7 +142,11 @@ nl_socket_open(void)
}
#endif

#ifdef HAVE_MNL_SOCKET_OPEN2
nl = mnl_socket_open2(NETLINK_NETFILTER, SOCK_CLOEXEC);
#else
nl = mnl_socket_open(NETLINK_NETFILTER);
#endif
if (nl == NULL) {
log_message(LOG_INFO, "mnl_socket_open failed - %d", errno);

Expand All @@ -148,6 +155,10 @@ nl_socket_open(void)

return false;
}
#ifndef HAVE_MNL_SOCKET_OPEN2
int nl_fd = mnl_socket_get_fd(nl);
fcntl(nl_fd, F_SETFD, fcntl(nl_fd, F_GETFD) | FD_CLOEXEC);
#endif

if (mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID) < 0) {
log_message(LOG_INFO, "mnl_socket_bind error - %d", errno);
Expand Down
11 changes: 6 additions & 5 deletions keepalived/core/snmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "config.h"

#include <stdio.h>
#if defined HAVE_DECL_CLOSE_RANGE_CLOEXEC
#if HAVE_DECL_CLOSE_RANGE_CLOEXEC
#if !defined USE_CLOSE_RANGE_SYSCALL && !defined _GNU_SOURCE
#define _GNU_SOURCE
#endif
Expand Down Expand Up @@ -466,15 +466,16 @@ snmp_unregister_mib(oid *myoid, size_t len)
void
snmp_agent_init(const char *snmp_socket_name, bool base_mib)
{
#ifndef HAVE_DECL_CLOSE_RANGE_CLOEXEC
#if !HAVE_DECL_CLOSE_RANGE_CLOEXEC
uint64_t fds[2][16];
unsigned max_fd;
size_t i;
#endif

if (snmp_running)
return;

#ifndef HAVE_DECL_CLOSE_RANGE_CLOEXEC
#if !HAVE_DECL_CLOSE_RANGE_CLOEXEC
get_open_fds(fds[0], sizeof(fds[0]) / sizeof(fds[0][0]));
#endif

Expand Down Expand Up @@ -528,13 +529,13 @@ snmp_agent_init(const char *snmp_socket_name, bool base_mib)
/* Set up the fd threads */
snmp_epoll_info(master);

#ifdef HAVE_DECL_CLOSE_RANGE_CLOEXEC
#if HAVE_DECL_CLOSE_RANGE_CLOEXEC
/* This assumes that child processes should only have stdin, stdout and stderr open */
close_range(STDERR_FILENO + 1, ~0U, CLOSE_RANGE_CLOEXEC);
#else
max_fd = get_open_fds(fds[1], sizeof(fds[1]) / sizeof(fds[1][0]));

for (size_t i = 0; i < sizeof(fds[0]) / sizeof(fds[0][0]) && i * 64 <= max_fd; i++) {
for (i = 0; i < sizeof(fds[0]) / sizeof(fds[0][0]) && i * 64 <= max_fd; i++) {
if (fds[0][i] != fds[1][i]) {
uint64_t fds_diff = fds[0][i] ^ fds[1][i], bit_mask;
unsigned j;
Expand Down
2 changes: 1 addition & 1 deletion keepalived/include/vrrp_if.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ typedef struct _interface {
#ifdef _HAVE_VRRP_VMAC_
if_type_t if_type; /* interface type */
int vmac_type; /* Type of macvlan or ipvlan */
#ifdef HAVE_DECL_IFLA_IPVLAN_FLAGS
#if HAVE_DECL_IFLA_IPVLAN_FLAGS
int ipvlan_flags; /* bridge/private/vepa */
#endif
ifindex_t base_ifindex; /* Only used at startup if we find vmac i/f before base i/f */
Expand Down
6 changes: 4 additions & 2 deletions keepalived/vrrp/vrrp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2712,10 +2712,12 @@ open_vrrp_read_socket(sa_family_t family, int proto, const interface_t *ifp,
if (family == AF_INET6) {
if (setsockopt(fd, IPPROTO_IPV6, IPV6_TRANSPARENT, &on, sizeof on))
log_message(LOG_INFO, "IPV6_TRANSPARENT failed %d - %m", errno);
} else
#endif
} else if (setsockopt(fd, IPPROTO_IP, IP_FREEBIND, &on, sizeof on))
log_message(LOG_INFO, "IP_FREEBIND failed %d - %m", errno);
#else
if (setsockopt(fd, family == AF_INET ? IPPROTO_IP : IPPROTO_IPV6, family == AF_INET ? IP_FREEBIND : IPV6_FREEBIND, &on, sizeof on))
log_message(LOG_INFO, "IP%s_FREEBIND failed %d - %m", family == AF_INET ? "" : "V6", errno);
#endif

/* Bind to the local unicast address */
if (bind(fd, PTR_CAST_CONST(struct sockaddr, unicast_src), unicast_src->ss_family == AF_INET ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6))) {
Expand Down
4 changes: 2 additions & 2 deletions lib/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
#include <sys/epoll.h>
#include <sys/inotify.h>
#endif
#ifndef HAVE_DECL_CLOSE_RANGE_CLOEXEC
#if !HAVE_DECL_CLOSE_RANGE_CLOEXEC
#include <dirent.h>
#include <stdlib.h>
#include <ctype.h>
Expand Down Expand Up @@ -1485,7 +1485,7 @@ make_tmp_filename(const char *file_name)
return path;
}

#ifdef HAVE_DECL_CLOSE_RANGE_CLOEXEC
#if HAVE_DECL_CLOSE_RANGE_CLOEXEC
#ifdef USE_CLOSE_RANGE_SYSCALL
int
close_range(unsigned first, unsigned last, int flags)
Expand Down
2 changes: 1 addition & 1 deletion lib/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ extern bool keepalived_modprobe(const char *);
#endif
extern void set_tmp_dir(void);
extern const char *make_tmp_filename(const char *);
#ifndef HAVE_DECL_CLOSE_RANGE_CLOEXEC
#if !HAVE_DECL_CLOSE_RANGE_CLOEXEC
extern unsigned get_open_fds(uint64_t *, unsigned);
#elif defined USE_CLOSE_RANGE_SYSCALL
extern int close_range(unsigned, unsigned, int);
Expand Down