diff --git a/Makefile.am b/Makefile.am index f5be2fb0..987c9b29 100644 --- a/Makefile.am +++ b/Makefile.am @@ -9,9 +9,11 @@ bin_PROGRAMS=ipfixprobe ipfixprobe_stats DISTCHECK_CONFIGURE_FLAGS="--with-systemdsystemunitdir=$$dc_install_base/$(systemdsystemunitdir)" +AM_CPPFLAGS=-I$(srcdir)/include/ + ipfixprobe_LDFLAGS=-lpthread -ldl -latomic ipfixprobe_CFLAGS=-I$(srcdir)/include/ -fPIC -ipfixprobe_CXXFLAGS=-std=gnu++11 -Wno-write-strings -I$(srcdir)/include/ -fPIC +ipfixprobe_CXXFLAGS=-Wno-write-strings -I$(srcdir)/include/ -fPIC if OS_CYGWIN ipfixprobe_CXXFLAGS+=-Wl,--export-all-symbols @@ -32,6 +34,11 @@ ipfixprobe_input_src=\ #example_la_SOURCES=example.cpp example.hpp #example_la_LDFLAGS=-module -shared -avoid-version +if ENABLE_PCAP +pkglib_LTLIBRARIES=input-pcap.la +input_pcap_la_SOURCES= input/pcap.cpp input/pcap.hpp +input_pcap_la_LDFLAGS=-module -shared -avoid-version -lpcap +endif if WITH_NDP ipfixprobe_LDFLAGS+=-lnuma -lndpRI -L$(srcdir)/input/nfbCInterface/ @@ -39,6 +46,12 @@ ipfixprobe_CXXFLAGS+=-I$(srcdir)/input/nfbCInterface/include/ ipfixprobe_input_src+=\ input/ndp.cpp \ input/ndp.hpp + +pkglib_LTLIBRARIES=input-ndp.la +input_ndp_la_CXXFLAGS=-I$(srcdir)/input/nfbCInterface/include/ +input_ndp_la_SOURCES= input/ndp.cpp input/ndp.hpp +input_ndp_la_LDFLAGS=-module -shared -avoid-version -lnuma -lndpRI -L$(srcdir)/input/nfbCInterface/ + endif if WITH_RAW @@ -156,6 +169,12 @@ if WITH_DPDK ipfixprobe_input_src+=\ input/dpdk.cpp \ input/dpdk.h + +pkglib_LTLIBRARIES=input-dpdk.la +input_dpdk_la_CFLAGS=-I$(srcdir)/include/ $(DPDK_CFLAGS) +input_dpdk_la_CXXFLAGS=$(DPDK_CFLAGS) +input_dpdk_la_SOURCES=input/dpdk.cpp input/dpdk.h +input_dpdk_la_LDFLAGS=-module -shared -avoid-version $(DPDK_LIBS) endif ipfixprobe_headers_src=\ @@ -200,7 +219,7 @@ endif ipfixprobe_SOURCES=$(ipfixprobe_src) main.cpp -ipfixprobe_stats_CXXFLAGS=-std=gnu++11 -Wno-write-strings -I$(srcdir)/include/ +ipfixprobe_stats_CXXFLAGS=-Wno-write-strings ipfixprobe_stats_SOURCES=ipfixprobe_stats.cpp \ include/ipfixprobe/options.hpp \ include/ipfixprobe/utils.hpp \ @@ -268,6 +287,8 @@ srpm: make ${AM_MAKEFLAGS} distdir='$(RPMDIR)/SOURCES/$(RPMFILENAME)' distdir ( cd "$(RPMDIR)/SOURCES/"; tar -z -c -f $(RPMFILENAME)-$(RELEASE).tar.gz $(RPMFILENAME); rm -rf $(RPMFILENAME); ) $(RPMBUILD) -bs $(PACKAGE_NAME).spec --define "_topdir `pwd`/$(RPMDIR)"; + $(RPMBUILD) -bs $(PACKAGE_NAME)-dpdk.spec --define "_topdir `pwd`/$(RPMDIR)"; + $(RPMBUILD) -bs $(PACKAGE_NAME)-ndp.spec --define "_topdir `pwd`/$(RPMDIR)"; .PHONY: rpm rpm: srpm @@ -279,7 +300,11 @@ rpm-nemea: srpm .PHONY: rpm-ndp rpm-ndp: srpm - $(RPMBUILD) --define "_topdir `pwd`/$(RPMDIR)" --rebuild $(RPMDIR)/SRPMS/$(RPMFILENAME)-$(RELEASE).src.rpm --with ndp --with unwind; + $(RPMBUILD) --define "_topdir `pwd`/$(RPMDIR)" --rebuild $(RPMDIR)/SRPMS/$(PACKAGE_NAME)-ndp-$(VERSION)-$(RELEASE).src.rpm --with unwind; + +.PHONY: rpm-dpdk +rpm-dpdk: srpm + $(RPMBUILD) --define "_topdir `pwd`/$(RPMDIR)" --rebuild $(RPMDIR)/SRPMS/$(PACKAGE_NAME)-dpdk-$(VERSION)-$(RELEASE).src.rpm --with unwind; else endif diff --git a/configure.ac b/configure.ac index 1f9166d0..96f90ced 100644 --- a/configure.ac +++ b/configure.ac @@ -20,16 +20,17 @@ RPM_BUILDREQ= AC_CONFIG_MACRO_DIR([m4]) # Must be checked before default -g -O2 is set: +CXXFLAGS=" -std=gnu++11 " AC_ARG_ENABLE([debug], AC_HELP_STRING([--enable-debug], [Enable build with debug symbols and without optimizations.]), [if test "$enableval" = "yes"; then - CXXFLAGS="-Wall -g -O0 $CXXFLAGS" + CXXFLAGS+="-Wall -g -O0 $CXXFLAGS" CFLAGS="-Wall -g -O0 $CFLAGS" else - CXXFLAGS="-Wall -g -O3 $CXXFLAGS" + CXXFLAGS+="-Wall -g -O3 $CXXFLAGS" CFLAGS="-Wall -g -O3 $CFLAGS" - fi], [CXXFLAGS="-Wall -g -O3 $CXXFLAGS" + fi], [CXXFLAGS+="-Wall -g -O3 $CXXFLAGS" CPPFLAGS="-DNDEBUG=1 $CPPFLAGS" CFLAGS="-Wall -g -O3"]) AM_CONDITIONAL(DEBUG, test x"$debug" = x"true") @@ -81,6 +82,9 @@ AC_ARG_WITH([defaultsocketdir], AC_SUBST([defaultsocketdir], [$with_defaultsocketdir]) AC_DEFINE_DIR([DEFAULTSOCKETDIR], [defaultsocketdir], [Default path to socket directory]) +pkglibdir=$libdir/ipfixprobe +AC_DEFINE_DIR([PLUGINDIR], [pkglibdir], [Path to loadable plugins]) + AC_CHECK_LIB(atomic, __atomic_store, [libatomic=yes], AC_MSG_ERROR([libatomic not found])) ### gtest @@ -206,7 +210,7 @@ if test x${withndp} = xyes; then ), AC_MSG_ERROR([nfb/nfb.h not found. Try installing netcope-common-devel])) fi -AM_CONDITIONAL(WITH_NDP, test x${libnfb} = xyes && test x${withndp} = xyes) +AM_CONDITIONAL(WITH_NDP, test x${libnfb} = xyes -a x${withndp} = xyes) if [[ -z "$WITH_NDP_TRUE" ]]; then AC_DEFINE([WITH_NDP], [1], [Define to 1 if the ndp is available]) CPPFLAGS="$CPPFLAGS -DIPXP_FLOW_CACHE_SIZE=19 -DIPXP_FLOW_LINE_SIZE=2" # 524288 cache records, 4 record per line @@ -225,31 +229,47 @@ AC_ARG_WITH([pcap], fi ], [withpcap="no"] ) - -if test x${withpcap} = xyes; then - AC_CHECK_HEADER(pcap.h, - AC_CHECK_LIB(pcap, pcap_open_live, [libpcap=yes], - AC_CHECK_LIB(wpcap, pcap_open_live, [libwpcap=yes], AC_MSG_ERROR([libpcap not found. Try installing libpcap]))), - AC_MSG_ERROR([pcap.h not found. Try installing libpcap-devel or libwpcap-devel])) +AC_ARG_ENABLE([pcap-plugin], + AC_HELP_STRING([--disable-pcap-plugin], + [Disable build of input-pcap plugin.]), + [if test "$enableval" = "yes"; then + disablepcapplugin=no + else + disablepcapplugin=yes + fi], [disablepcapplugin=no]) +AM_CONDITIONAL(DISABLE_PCAP_MODULE, test x"$disablepcapplugin" = x"yes") + +BACKUPLIBS=$LIBS +AC_CHECK_HEADER(pcap.h, + AC_CHECK_LIB(pcap, pcap_open_live, [libpcap=yes + have_pcap=yes], + AC_CHECK_LIB(wpcap, pcap_open_live, [libwpcap=yes + have_pcap=yes], [AC_MSG_WARN([libpcap not found. Try installing libpcap]) + have_pcap=no])), + [AC_MSG_WARN([pcap.h not found. Try installing libpcap-devel or libwpcap-devel]) + have_pcap=no]) + +if test x${withpcap} = xyes -a x${have_pcap} = xno; then + AC_MSG_ERROR([Cannot compile pcap plugin that was enabled by --with-pcap.]) fi -AM_CONDITIONAL(WITH_PCAP, test x${withpcap} && (test x${libpcap} = xyes || test x${libwpcap} = xyes)) -if [[ -z "$WITH_PCAP_TRUE" ]]; then +AM_CONDITIONAL(ENABLE_PCAP, test x${have_pcap} = xyes -a x${disablepcapplugin} = xno) +AM_CONDITIONAL(WITH_PCAP, test x${withpcap} = xyes -a x${have_pcap} = xyes) +if test x${withpcap} = xyes -a x${have_pcap} = xyes; then AC_DEFINE([WITH_PCAP], [1], [Define to 1 if the libpcap is available]) - if [[ -z "$WITH_PCAP_TRUE" ]]; then - if test x${libpcap} = xyes; then - LIBS="-lpcap $LIBS" - RPM_REQUIRES+=" libpcap" - RPM_BUILDREQ+=" libpcap-devel" - else - LIBS="-lwpcap $LIBS" - RPM_REQUIRES+=" libwpcap" - RPM_BUILDREQ+=" libwpcap-devel" - fi + if test x${libpcap} = xyes; then + LIBS="-lpcap $LIBS" + RPM_REQUIRES+=" libpcap" + RPM_BUILDREQ+=" libpcap-devel" + else + LIBS="-lwpcap $LIBS" + RPM_REQUIRES+=" libwpcap" + RPM_BUILDREQ+=" libwpcap-devel" fi +else + LIBS=$BACKUPLIBS fi - AC_ARG_WITH([unwind], AC_HELP_STRING([--with-unwind],[Compile ipfixprobe with libunwind to print stack on crash]), [ @@ -375,7 +395,7 @@ AM_CONDITIONAL(WITH_STEM, test x${withstem} = xyes) if [[ -z "$WITH_STEM_TRUE" ]]; then AC_DEFINE([WITH_STEM], [1], [Define to 1 to use flexprobe testing interface]) CFLAGS="-I/usr/local/include/Stem $CFLAGS" - CXXFLAGS="-I/usr/local/include/Stem -std=gnu++17 -g -Wno-write-strings $CXXFLAGS" + CXXFLAGS="-I/usr/local/include/Stem -g -Wno-write-strings $CXXFLAGS" LIBS="-lstem $LIBS" fi @@ -436,6 +456,8 @@ fi AC_CONFIG_FILES([Makefile ipfixprobe.spec + ipfixprobe-dpdk.spec + ipfixprobe-ndp.spec ipfixprobe.bash input/nfbCInterface/Makefile init/Makefile @@ -472,6 +494,12 @@ echo " LIBS...................: $LIBS" echo "Enforced NEMEA (for copr): $COPRRPM" echo "FlexProbe Data Interface.: $withflexprobe" echo "DPDK Interface...........: $withdpdk" +echo "pcap Interface...........: $withpcap" +if test -n "$ENABLE_PCAP_TRUE"; then +echo " pcap module...........: no" +else +echo " pcap module...........: yes" +fi echo echo "Installation.............: make install (as root if needed, with 'su' or 'sudo')" echo " prefix.................: $prefix" diff --git a/ipfixprobe-dpdk.spec.in b/ipfixprobe-dpdk.spec.in new file mode 100644 index 00000000..c776e057 --- /dev/null +++ b/ipfixprobe-dpdk.spec.in @@ -0,0 +1,109 @@ +%bcond_without raw +%bcond_with nemea +%bcond_with unwind +%bcond_with is_el7 + +%if %{with raw} +%global compile_raw yes +%else +%global compile_raw no +%endif + +%if %{with nemea} +%global compile_nemea yes +%else +%global compile_nemea @COPRRPM@ +%endif + +%if %{with unwind} +%global compile_unwind yes +%else +%global compile_unwind @COPRRPM@ +%endif + +%if "%{dist}" == ".el7" +%global is_el7 yes +%else +%global is_el7 no +%endif + +Name: ipfixprobe-dpdk +Version: @PACKAGE_VERSION@ +Release: @RELEASE@ +URL: http://nemea.liberouter.org/ +Source: https://www.liberouter.org/repo/SOURCES/ipfixprobe-%{version}-%{release}.tar.gz +Group: Liberouter +License: BSD +Vendor: CESNET, z.s.p.o. +Packager: @USERNAME@ <@USERMAIL@> +BuildRoot: %{_tmppath}/ipfixprobe-%{version}-%{release} +Summary: IPFIX flow exporter with DPDK support and various extending IPFIX elements exported by plugins. +Requires: libatomic +BuildRequires: gcc gcc-c++ make doxygen pkgconfig libatomic +Provides: ipfixprobe +Requires: dpdk +BuildRequires: dpdk-devel + +%if %{with nemea} || "@COPRRPM@" == "yes" +Requires: libtrap +BuildRequires: libtrap-devel +BuildRequires: unirec +%endif + +%if %{with unwind} || "@COPRRPM@" == "yes" +Requires: libunwind +BuildRequires: libunwind-devel +%endif + +%if "%{is_el7}" == "yes" +Requires: openssl11 +BuildRequires: openssl11-devel +%else +Requires: openssl +BuildRequires: openssl-devel +%endif + +%description +This package contains IPFIX flow exporter with DPDK support. + +%package -n ipfixprobe-input-dpdk +Group: Liberouter +License: BSD +Vendor: CESNET, z.s.p.o. +Packager: @USERNAME@ <@USERMAIL@> +Summary: NDP input plugin for ipfixprobe IPFIX flow exporter. +Requires: dpdk +BuildRequires: dpdk-devel +Provides: ipfixprobe-input-dpdk + +%description -n ipfixprobe-input-dpdk +Input plugin to monitor network traffic on network interface using DPDK and HW acceleration cards. + +%prep +%setup -n ipfixprobe-%{version} + +%build +./configure -q --enable-silent-rules --prefix=%{_prefix} --libdir=%{_libdir} --bindir=%{_bindir} --sysconfdir=%{_sysconfdir} --docdir=%{_docdir} --mandir=%{_mandir} --datadir=%{_datadir} --with-raw=%{compile_raw} --with-nemea=%{compile_nemea} --with-unwind=%{compile_unwind} --enable-legacy-ssl=%{is_el7} --with-dpdk --disable-pcap-plugin +make clean +make -j5 + +%install +make -j5 DESTDIR=$RPM_BUILD_ROOT install + +%post +test -x %{_bindir}/ipfixprobe && setcap "CAP_NET_RAW+eip" %{_bindir}/ipfixprobe || true +ldconfig + +%files +%attr(0755, root, nemead) %{_bindir}/ipfixprobe +%attr(0755, root, nemead) %{_bindir}/ipfixprobe_stats +%attr(0755, root, nemead) %{_bindir}/ipfixprobed +%{_sysconfdir}/bash_completion.d/ipfixprobe.bash +%{_sysconfdir}/ipfixprobe/link0.conf.example +%{_docdir}/ipfixprobe/README.md +@systemdsystemunitdir@ + +%files -n ipfixprobe-input-dpdk +%{_libdir}/ipfixprobe/input-dpdk.so +%{_libdir}/ipfixprobe/input-dpdk.la + diff --git a/ipfixprobe-ndp.spec.in b/ipfixprobe-ndp.spec.in new file mode 100644 index 00000000..9886f19e --- /dev/null +++ b/ipfixprobe-ndp.spec.in @@ -0,0 +1,123 @@ +%bcond_without raw +%bcond_with nemea +%bcond_with unwind +%bcond_with is_el7 + +%if %{with raw} +%global compile_raw yes +%else +%global compile_raw no +%endif + +%if %{with nemea} +%global compile_nemea yes +%else +%global compile_nemea @COPRRPM@ +%endif + +%if %{with unwind} +%global compile_unwind yes +%else +%global compile_unwind @COPRRPM@ +%endif + +%if "%{dist}" == ".el7" +%global is_el7 yes +%else +%global is_el7 no +%endif + +Name: ipfixprobe-ndp +Version: @PACKAGE_VERSION@ +Release: @RELEASE@ +URL: http://nemea.liberouter.org/ +Source: https://www.liberouter.org/repo/SOURCES/ipfixprobe-%{version}-%{release}.tar.gz +Group: Liberouter +License: BSD +Vendor: CESNET, z.s.p.o. +Packager: @USERNAME@ <@USERMAIL@> +BuildRoot: %{_tmppath}/ipfixprobe-%{version}-%{release} +Summary: IPFIX flow exporter with NDP support and various extending IPFIX elements exported by plugins. +Requires: libatomic +BuildRequires: gcc gcc-c++ make doxygen pkgconfig libatomic +Provides: ipfixprobe +Requires: netcope-common +Requires: numactl +BuildRequires: netcope-common +BuildRequires: numactl-devel + +%if %{with nemea} || "@COPRRPM@" == "yes" +Requires: libtrap +BuildRequires: libtrap-devel +BuildRequires: unirec +%endif + +%if %{with unwind} || "@COPRRPM@" == "yes" +Requires: libunwind +BuildRequires: libunwind-devel +%endif + +%if "%{is_el7}" == "yes" +Requires: openssl11 +BuildRequires: openssl11-devel +%else +Requires: openssl +BuildRequires: openssl-devel +%endif + +%description +This package contains IPFIX flow exporter with NDP support. + +%package -n ipfixprobe-input-ndp +Group: Liberouter +License: BSD +Vendor: CESNET, z.s.p.o. +Packager: @USERNAME@ <@USERMAIL@> +Summary: NDP input plugin for ipfixprobe IPFIX flow exporter. +Requires: netcope-common +Requires: numactl +BuildRequires: netcope-common +BuildRequires: numactl-devel +Provides: ipfixprobe-input-ndp + +%description -n ipfixprobe-input-ndp +Input plugin to monitor network traffic on network interface using NDP and HW acceleration cards. + +%prep +%setup -n ipfixprobe-%{version} + +%build +./configure -q --enable-silent-rules --prefix=%{_prefix} --libdir=%{_libdir} --bindir=%{_bindir} --sysconfdir=%{_sysconfdir} --docdir=%{_docdir} --mandir=%{_mandir} --datadir=%{_datadir} --with-raw=%{compile_raw} --with-nemea=%{compile_nemea} --with-unwind=%{compile_unwind} --enable-legacy-ssl=%{is_el7} --with-ndp --disable-pcap-plugin +make clean +make -j5 + +%install +make -j5 DESTDIR=$RPM_BUILD_ROOT install + +%post +test -x %{_bindir}/ipfixprobe && setcap "CAP_NET_RAW+eip" %{_bindir}/ipfixprobe || true +ldconfig + +%files +%attr(0755, root, nemead) %{_bindir}/ipfixprobe +%attr(0755, root, nemead) %{_bindir}/ipfixprobe_stats +%attr(0755, root, nemead) %{_bindir}/ipfixprobed +%{_sysconfdir}/bash_completion.d/ipfixprobe.bash +%{_sysconfdir}/ipfixprobe/link0.conf.example +%{_docdir}/ipfixprobe/README.md +%{_libdir}/libndpRI.so.0 +%{_libdir}/libndpRI.so.0.0.0 +%{_includedir}/ndpheader.h +%{_includedir}/ndpreader.h +%{_includedir}/ndpreader.hpp +%{_libdir}/libndpRI.a +%{_libdir}/libndpRI.la +%{_libdir}/libndpRI.so +@systemdsystemunitdir@ + +%files -n ipfixprobe-input-ndp +%{_libdir}/ipfixprobe/input-ndp.so +%{_libdir}/ipfixprobe/input-ndp.la +%{_libdir}/libndpRI.so.0 +%{_libdir}/libndpRI.so.0.0.0 + diff --git a/ipfixprobe.spec.in b/ipfixprobe.spec.in index b88bbb45..786bff43 100644 --- a/ipfixprobe.spec.in +++ b/ipfixprobe.spec.in @@ -11,12 +11,6 @@ %global compile_ndp no %endif -%if %{with pcap} -%global compile_pcap yes -%else -%global compile_pcap @COPRRPM@ -%endif - %if %{with raw} %global compile_raw yes %else @@ -86,6 +80,19 @@ BuildRequires: openssl-devel %description This package contains nemea flow exporter. +%package input-pcap +Group: Liberouter +License: BSD +Vendor: CESNET, z.s.p.o. +Packager: @USERNAME@ <@USERMAIL@> +Summary: Libpcap input plugin for ipfixprobe IPFIX flow exporter. +Requires: libpcap +BuildRequires: libpcap-devel +Provides: ipfixprobe-input-pcap + +%description input-pcap +Input plugin to monitor network traffic on network interface using libpcap or to process packets stored in PCAP files. + %prep %setup @@ -136,5 +143,7 @@ This package contains header file for liburfilter. %{_libdir}/libndpRI.so %endif - +%files input-pcap +%{_libdir}/ipfixprobe/input-pcap.so +%{_libdir}/ipfixprobe/input-pcap.la diff --git a/pluginmgr.cpp b/pluginmgr.cpp index 1a34468a..e5d7395b 100644 --- a/pluginmgr.cpp +++ b/pluginmgr.cpp @@ -41,6 +41,8 @@ * */ +#include + #include #include "pluginmgr.hpp" @@ -111,9 +113,22 @@ std::vector PluginManager::get() const Plugin *PluginManager::load(const std::string &name) { dlerror(); + void *handle = dlopen(name.c_str(), RTLD_LAZY); if (handle == nullptr) { - return nullptr; + std::string filename = std::string(PLUGINDIR) + "/input-" + name + ".so"; + handle = dlopen(filename.c_str(), RTLD_LAZY); + if (handle == nullptr) { + filename = std::string(PLUGINDIR) + "/output-" + name + ".so"; + handle = dlopen(filename.c_str(), RTLD_LAZY); + if (handle == nullptr) { + filename = std::string(PLUGINDIR) + "/process-" + name + ".so"; + handle = dlopen(filename.c_str(), RTLD_LAZY); + if (handle == nullptr) { + return nullptr; + } + } + } } if (m_last_rec == nullptr || m_last_rec->m_next == nullptr) { dlclose(handle);