From: Vincent Bernat Date: Wed, 23 Sep 2015 18:07:08 +0000 (+0200) Subject: lldpd: add a warning if the kernel seems to be too old X-Git-Tag: 0.8.0~64 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2472bfdaf3b391e04c78b25eff2c8abcef382bb0;p=thirdparty%2Flldpd.git lldpd: add a warning if the kernel seems to be too old --- diff --git a/configure.ac b/configure.ac index f260edaa..4ae80302 100644 --- a/configure.ac +++ b/configure.ac @@ -305,7 +305,15 @@ lldp_ARG_ENABLE([dot3], [Dot3 extension (PHY stuff)], [yes]) lldp_ARG_ENABLE([custom], [Custom TLV support], [yes]) # Oldies +MIN_LINUX_KERNEL_VERSION=2.6.39 lldp_ARG_ENABLE([oldies], [compatibility with Linux kernel older than 2.6.39], [no]) +if test x"$os" = x"Linux"; then + if test x"$enable_oldies" = x"no"; then + AC_DEFINE_UNQUOTED(MIN_LINUX_KERNEL_VERSION, "[$MIN_LINUX_KERNEL_VERSION]", [Minimal Linux kernel version required]) + else + AC_DEFINE(MIN_LINUX_KERNEL_VERSION, "2.6.11", [Minimal kernel version required]) + fi +fi ####################### # Output results diff --git a/src/daemon/lldpd.c b/src/daemon/lldpd.c index ab1ad613..5fb3f204 100644 --- a/src/daemon/lldpd.c +++ b/src/daemon/lldpd.c @@ -1376,6 +1376,43 @@ lldpd_started_by_systemd() } #endif +#ifdef HOST_OS_LINUX +static void +version_convert(const char *sversion, unsigned iversion[], size_t n) +{ + const char *p = sversion; + char *end; + for (size_t i = 0; i < n; i++) { + iversion[i] = strtol(p, &end, 10); + if (*end != '.') break; + p = end + 1; + } +} + +static void +version_check(void) +{ + struct utsname uts; + if (uname(&uts) == -1) return; + unsigned version_min[3] = {}; + unsigned version_cur[3] = {}; + version_convert(uts.release, version_cur, 3); + version_convert(MIN_LINUX_KERNEL_VERSION, version_min, 3); + if (version_min[0] > version_cur[0] || + (version_min[0] == version_cur[0] && version_min[1] > version_cur[1]) || + (version_min[1] == version_cur[1] && version_min[2] > version_cur[2])) { + log_warnx("lldpd", "minimal kernel version required is %s, got %s", + MIN_LINUX_KERNEL_VERSION, uts.release); + log_warnx("lldpd", "lldpd may be unable to detect bonds and bridges correctly"); +#ifndef ENABLE_OLDIES + log_warnx("lldpd", "consider recompiling with --enable-oldies option"); +#endif + } +} +#else +static void version_check(void) {} +#endif + int lldpd_main(int argc, char *argv[], char *envp[]) { @@ -1566,6 +1603,7 @@ lldpd_main(int argc, char *argv[], char *envp[]) tzset(); /* Get timezone info before chroot */ log_debug("main", "lldpd " PACKAGE_VERSION " starting..."); + version_check(); /* Grab uid and gid to use for priv sep */ #ifdef ENABLE_PRIVSEP