]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
lldpd: add a warning if the kernel seems to be too old
authorVincent Bernat <vincent@bernat.im>
Wed, 23 Sep 2015 18:07:08 +0000 (20:07 +0200)
committerVincent Bernat <vincent@bernat.im>
Wed, 23 Sep 2015 18:07:08 +0000 (20:07 +0200)
configure.ac
src/daemon/lldpd.c

index f260edaaef79b925a61e82b13c2dba6749804e3c..4ae80302ac15f90a9f5d98695dd771581af433c6 100644 (file)
@@ -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
index ab1ad613d851c66a8ee0c23eb4bf87fc562b0a39..5fb3f2040820ff4dbf49685215e87f2854c08e94 100644 (file)
@@ -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