diff --git a/Makefile b/Makefile index 7c25e5af5824429669efadd7c2f4a78e51d62bc5..e816a0107e64b6043cc1bf1669b2a36b7049e46d 100644 --- a/Makefile +++ b/Makefile @@ -16,6 +16,9 @@ CFLAGS += -Wno-error=sign-conversion CXXFLAGS += -Wno-error=sign-conversion endif +CFLAGS += `pkg-config --cflags libnl-3.0` +CXXFLAGS += `pkg-config --cflags libnl-3.0` + CC ?= gcc CXX ?= g++ diff --git a/src/app/mumta.cpp b/src/app/mumta.cpp index 002e8111dd80c7014a534dff5428e55815165e2b..001c8fafcc6c74fe039eae5bfe34e9083a297665 100644 --- a/src/app/mumta.cpp +++ b/src/app/mumta.cpp @@ -4,6 +4,7 @@ #include <thread> #include "lib/ev/ev.hpp" +#include "lib/nl/nl.hpp" #include "mumta/evloop.hpp" @@ -14,6 +15,9 @@ int main() { if(!check_version_libev()) { return 1; } + if (!check_version_libnl()) { + return 1; + } dctl_status_msg("Initializing"); dctl_status_msg("Reading configuration"); diff --git a/src/app/mumta.ldflags b/src/app/mumta.ldflags index 5cee85c8c4c37ef4f91f3d6e2af590506200ea54..8c91bf42df5f889a4de0bb9777dfe33adbb3216a 100644 --- a/src/app/mumta.ldflags +++ b/src/app/mumta.ldflags @@ -1,3 +1,4 @@ `pkg-config --cflags --libs libsystemd` +`pkg-config --cflags --libs libnl-3.0` -lev -pthread diff --git a/src/lib/nl/nl.cpp b/src/lib/nl/nl.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f8b14f9b5c3287ccb14e1ce283e7d091dfcdd94d --- /dev/null +++ b/src/lib/nl/nl.cpp @@ -0,0 +1,34 @@ +#include <lib/nl/nl.hpp> + +#include <iomanip> +#include <sstream> +#include <string> + +#include <netlink/utils.h> + +#include "service/daemonctl.hpp" + +bool check_version_libnl() +{ + auto nl_major{nl_ver_maj}; + auto nl_minor{nl_ver_min}; + + constexpr auto exp_major{LIBNL_VER_MAJ}; + constexpr auto exp_minor{LIBNL_VER_MIN}; + + std::stringstream str; + str << "Checking dependency: libnl: detected " << std::dec << nl_major << "." << std::setw(2) << std::setfill('0') << nl_minor << ", compiled " << std::dec << exp_major << "." << std::setw(2) << std::setfill('0') << exp_minor; + dctl_status_msg(str.str().c_str()); + + if (nl_major != exp_major) { + dctl_status_err("Checking dependency: libnl: failed version check: Major API version mismatch.\n"); + return false; + } + + if (nl_minor < exp_minor) { + dctl_status_err("Checking dependency: libnl: failed version check: Minor API version too old.\n"); + return false; + } + + return true; +} diff --git a/src/lib/nl/nl.hpp b/src/lib/nl/nl.hpp new file mode 100644 index 0000000000000000000000000000000000000000..8f0b05a60ea3b1369ede7787c3d41169688f9ef9 --- /dev/null +++ b/src/lib/nl/nl.hpp @@ -0,0 +1,3 @@ +#pragma once + +bool check_version_libnl();