diff mbox series

[RFC,2/2] rtnl: Check if RTA_EXPIRES enum value is available

Message ID 20231111180753.51488-2-marcel@holtmann.org (mailing list archive)
State New
Headers show
Series [RFC,1/2] netlink: Workaround missing NETLINK_EXT_ACK define | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success

Commit Message

Marcel Holtmann Nov. 11, 2023, 6:07 p.m. UTC
Work around the missing RTA_EXPIRES settings of really really old
kernels and disable setting that attribute if the enum value is not
present.
---
 acinclude.m4 | 15 +++++++++++++++
 configure.ac |  2 ++
 ell/rtnl.c   |  4 ++++
 3 files changed, 21 insertions(+)

Comments

Marcel Holtmann Nov. 19, 2023, 4:50 p.m. UTC | #1
Hi,

> Work around the missing RTA_EXPIRES settings of really really old
> kernels and disable setting that attribute if the enum value is not
> present.
> ---
> acinclude.m4 | 15 +++++++++++++++
> configure.ac |  2 ++
> ell/rtnl.c   |  4 ++++
> 3 files changed, 21 insertions(+)
> 
> diff --git a/acinclude.m4 b/acinclude.m4
> index 6fb1de565a1d..3bb7b51d9ee6 100644
> --- a/acinclude.m4
> +++ b/acinclude.m4
> @@ -75,3 +75,18 @@ AC_DEFUN([COMPILER_FLAGS], [
> CFLAGS+=" -Wno-unknown-pragmas"
> fi
> ])
> +
> +AC_DEFUN([TEST_RTNL], [
> + AC_MSG_CHECKING([for RTA_EXPIRES])
> + AC_LANG_PUSH([C])
> + ac_rtnl_save_CFLAGS="$CFLAGS"
> + CFLAGS=""
> + AC_COMPILE_IFELSE([
> + AC_LANG_PROGRAM([#include <linux/rtnetlink.h>],
> + [enum rtattr_type_t t = RTA_EXPIRES;])],
> + AC_DEFINE(HAVE_RTA_EXPIRES, 1,
> + [Define to 1 if you have the RTA_EXPIRES enum value.])
> + AC_MSG_RESULT([yes]), AC_MSG_RESULT([no]))
> + CFLAGS=$ac_rtnl_save_CFLAGS
> + AC_LANG_POP([C])
> +])
> diff --git a/configure.ac b/configure.ac
> index cf3b53cfb574..44084bc4384b 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -111,6 +111,8 @@ AC_CHECK_FUNC(epoll_create, dummy=yes,
> 
> AC_CHECK_HEADERS(linux/types.h linux/if_alg.h)
> 
> +TEST_RTNL
> +
> AC_ARG_ENABLE(glib, AS_HELP_STRING([--enable-glib],
> [enable ell/glib main loop example]),
> [enable_glib=${enableval}])
> diff --git a/ell/rtnl.c b/ell/rtnl.c
> index ad2dca2f9e3c..5b392eae3fb3 100644
> --- a/ell/rtnl.c
> +++ b/ell/rtnl.c
> @@ -1348,7 +1348,9 @@ static uint32_t _rtnl_route_change(struct l_netlink *rtnl,
> size_t bufsize;
> void *rta_buf;
> uint16_t flags;
> +#ifdef HAVE_RTA_EXPIRES
> uint64_t now = l_time_now();
> +#endif
> 
> bufsize = NLMSG_ALIGN(sizeof(struct rtmsg)) +
> RTA_SPACE(sizeof(uint32_t)) +        /* RTA_OIF */
> @@ -1404,9 +1406,11 @@ static uint32_t _rtnl_route_change(struct l_netlink *rtnl,
> if (rt->preference)
> rta_buf += rta_add_u8(rta_buf, RTA_PREF, rt->preference);
> 
> +#ifdef HAVE_RTA_EXPIRES
> if (rt->expiry_time > now)
> rta_buf += rta_add_u32(rta_buf, RTA_EXPIRES,
> l_time_to_secs(rt->expiry_time - now));
> +#endif

while I think this is simple enough, it might make sense to actually add RTA_EXPIRES even if older kernels don’t support it.

What other obstacles do we have to get ELL compiled and working on older kernels?

Regards

Marcel
diff mbox series

Patch

diff --git a/acinclude.m4 b/acinclude.m4
index 6fb1de565a1d..3bb7b51d9ee6 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -75,3 +75,18 @@  AC_DEFUN([COMPILER_FLAGS], [
 		CFLAGS+=" -Wno-unknown-pragmas"
 	fi
 ])
+
+AC_DEFUN([TEST_RTNL], [
+	AC_MSG_CHECKING([for RTA_EXPIRES])
+	AC_LANG_PUSH([C])
+	ac_rtnl_save_CFLAGS="$CFLAGS"
+	CFLAGS=""
+	AC_COMPILE_IFELSE([
+		AC_LANG_PROGRAM([#include <linux/rtnetlink.h>],
+			[enum rtattr_type_t t = RTA_EXPIRES;])],
+		AC_DEFINE(HAVE_RTA_EXPIRES, 1,
+			[Define to 1 if you have the RTA_EXPIRES enum value.])
+		AC_MSG_RESULT([yes]), AC_MSG_RESULT([no]))
+	CFLAGS=$ac_rtnl_save_CFLAGS
+	AC_LANG_POP([C])
+])
diff --git a/configure.ac b/configure.ac
index cf3b53cfb574..44084bc4384b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -111,6 +111,8 @@  AC_CHECK_FUNC(epoll_create, dummy=yes,
 
 AC_CHECK_HEADERS(linux/types.h linux/if_alg.h)
 
+TEST_RTNL
+
 AC_ARG_ENABLE(glib, AS_HELP_STRING([--enable-glib],
 				[enable ell/glib main loop example]),
 					[enable_glib=${enableval}])
diff --git a/ell/rtnl.c b/ell/rtnl.c
index ad2dca2f9e3c..5b392eae3fb3 100644
--- a/ell/rtnl.c
+++ b/ell/rtnl.c
@@ -1348,7 +1348,9 @@  static uint32_t _rtnl_route_change(struct l_netlink *rtnl,
 	size_t bufsize;
 	void *rta_buf;
 	uint16_t flags;
+#ifdef HAVE_RTA_EXPIRES
 	uint64_t now = l_time_now();
+#endif
 
 	bufsize = NLMSG_ALIGN(sizeof(struct rtmsg)) +
 			RTA_SPACE(sizeof(uint32_t)) +        /* RTA_OIF */
@@ -1404,9 +1406,11 @@  static uint32_t _rtnl_route_change(struct l_netlink *rtnl,
 	if (rt->preference)
 		rta_buf += rta_add_u8(rta_buf, RTA_PREF, rt->preference);
 
+#ifdef HAVE_RTA_EXPIRES
 	if (rt->expiry_time > now)
 		rta_buf += rta_add_u32(rta_buf, RTA_EXPIRES,
 					l_time_to_secs(rt->expiry_time - now));
+#endif
 
 	return l_netlink_send(rtnl, nlmsg_type, flags, rtmmsg,
 				rta_buf - (void *) rtmmsg, cb, user_data,