From 60a4ba90cee4eb30def782f0aa753f3c0421aea3 Mon Sep 17 00:00:00 2001 From: emanuele-f Date: Sat, 21 Sep 2019 16:12:43 +0200 Subject: [PATCH] Add tools subdirectory --- .gitignore | 4 ++-- CMakeLists.txt | 15 ++++++++++-- Makefile.in | 26 ++++++++++---------- README.md | 2 +- configure.seed | 9 +++++++ n2n.h | 2 ++ tools/Makefile.in | 38 ++++++++++++++++++++++++++++++ benchmark.c => tools/benchmark.c | 0 n2n_decode.c => tools/n2n_decode.c | 0 9 files changed, 77 insertions(+), 19 deletions(-) create mode 100644 tools/Makefile.in rename benchmark.c => tools/benchmark.c (100%) rename n2n_decode.c => tools/n2n_decode.c (100%) diff --git a/.gitignore b/.gitignore index 53002e6..735ec3a 100644 --- a/.gitignore +++ b/.gitignore @@ -6,11 +6,11 @@ configure.ac config.* Makefile autom4te.cache -benchmark edge -n2n-decode example_edge_embed supernode +tools/n2n-benchmark +tools/n2n-decode build packages/debian/debian/changelog packages/debian/debian/control diff --git a/CMakeLists.txt b/CMakeLists.txt index 1fd0a03..2c8bd7e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,6 +16,8 @@ if(NOT DEFINED N2N_OPTION_AES) set(N2N_OPTION_AES ON) endif(NOT DEFINED N2N_OPTION_AES) +add_definitions(-DCMAKE_BUILD) +add_definitions(-DGIT_RELEASE="" -DPACKAGE_VERSION="${N2N_VERSION}" -DPACKAGE_OSNAME="${CMAKE_SYSTEM}") add_definitions(-DN2N_VERSION="${N2N_VERSION}" -DN2N_OSNAME="${N2N_OSNAME}") if(N2N_OPTION_AES) @@ -79,8 +81,17 @@ target_link_libraries(edge n2n) add_executable(supernode sn.c) target_link_libraries(supernode n2n) -add_executable(benchmark benchmark.c) -target_link_libraries(benchmark n2n) +# Tools +include_directories(.) + +add_executable(n2n-benchmark tools/benchmark.c) +target_link_libraries(n2n-benchmark n2n) + +find_library(PCAP_LIB pcap) +if(PCAP_LIB) + add_executable(n2n-decode tools/n2n_decode.c) + target_link_libraries(n2n-decode n2n pcap) +endif() install(TARGETS edge supernode RUNTIME DESTINATION sbin diff --git a/Makefile.in b/Makefile.in index 4f4a79b..ef523f3 100644 --- a/Makefile.in +++ b/Makefile.in @@ -8,7 +8,7 @@ GIT_COMMITS=@GIT_COMMITS@ CC?=gcc DEBUG?=-g3 #OPTIMIZATION?=-O2 -WARN?=-Wall -Wshadow -Wpointer-arith -Wmissing-declarations -Wnested-externs +WARN?=-Wall #Ultrasparc64 users experiencing SIGBUS should try the following gcc options #(thanks to Robert Gibbon) @@ -63,29 +63,26 @@ endif APPS=edge APPS+=supernode APPS+=example_edge_embed -APPS+=benchmark DOCS=edge.8.gz supernode.1.gz n2n.7.gz -all: $(APPS) $(DOCS) +.PHONY: steps build push all clean install tools +all: $(APPS) $(DOCS) tools + +tools: $(N2N_LIB) + $(MAKE) -C $@ edge: edge.c $(N2N_LIB) n2n_wire.h n2n.h Makefile - $(CC) $(CFLAGS) edge.c $(N2N_LIB) $(LIBS_EDGE) -o edge + $(CC) $(CFLAGS) $< $(N2N_LIB) $(LIBS_EDGE) -o $@ supernode: sn.c $(N2N_LIB) n2n.h Makefile - $(CC) $(CFLAGS) sn.c $(N2N_LIB) $(LIBS_SN) -o supernode - -benchmark: benchmark.c $(N2N_LIB) n2n_wire.h n2n.h Makefile - $(CC) $(CFLAGS) benchmark.c $(N2N_LIB) $(LIBS_EDGE) -o benchmark - -n2n-decode: n2n_decode.c $(N2N_LIB) n2n_wire.h n2n.h Makefile - $(CC) $(CFLAGS) n2n_decode.c $(N2N_LIB) $(LIBS_EDGE) -lpcap -o n2n-decode + $(CC) $(CFLAGS) $< $(N2N_LIB) $(LIBS_SN) -o $@ example_edge_embed: example_edge_embed.c $(N2N_LIB) n2n.h - $(CC) $(CFLAGS) example_edge_embed.c $(N2N_LIB) $(LIBS_EDGE) -o example_edge_embed + $(CC) $(CFLAGS) $< $(N2N_LIB) $(LIBS_EDGE) -o $@ .c.o: n2n.h n2n_transforms.h n2n_wire.h twofish.h Makefile - $(CC) $(CFLAGS) -c $< + $(CC) $(CFLAGS) -c $< -o $@ %.gz : % gzip -c $< > $@ @@ -96,6 +93,7 @@ $(N2N_LIB): $(N2N_OBJS) clean: rm -rf $(N2N_OBJS) $(N2N_LIB) $(APPS) $(DOCS) test n2n-decode *.dSYM *~ + $(MAKE) -C tools clean install: edge supernode edge.8.gz supernode.1.gz n2n.7.gz echo "MANDIR=$(MANDIR)" @@ -105,6 +103,7 @@ install: edge supernode edge.8.gz supernode.1.gz n2n.7.gz $(INSTALL_DOC) edge.8.gz $(MAN8DIR)/ $(INSTALL_DOC) supernode.1.gz $(MAN1DIR)/ $(INSTALL_DOC) n2n.7.gz $(MAN7DIR)/ + $(MAKE) -C tools install # Docker builder section DOCKER_IMAGE_NAME=ntop/supernode @@ -140,5 +139,4 @@ push: echo "Please pass TARGET_ARCHITECTURE, see README.md."; \ fi -.PHONY: steps build push # End Docker builder section diff --git a/README.md b/README.md index 7e15dfc..2c80601 100644 --- a/README.md +++ b/README.md @@ -133,7 +133,7 @@ two edge nodes, but it will now that edge A is talking with edge B. Recently AES encryption support has been implemented, which increases both security and performance, so it is recommended to enable it on all the edge nodes by specifying the `-A` option. -A benchmark of the encryption methods is available when compiled from source with `./benchmark`. +A benchmark of the encryption methods is available when compiled from source with `tools/n2n-benchmark`. Contribution ------------ diff --git a/configure.seed b/configure.seed index 1faea83..432650a 100644 --- a/configure.seed +++ b/configure.seed @@ -24,6 +24,13 @@ else N2N_LIBS=-lcrypto fi +AC_CHECK_LIB([pcap], [pcap_open_live], pcap=true) + +if test x$pcap != x; then + AC_DEFINE([N2N_HAVE_PCAP], [], [Have PCAP library]) + ADDITIONAL_TOOLS="$ADDITIONAL_TOOLS n2n-decode" +fi + MACHINE=`uname -m` SYSTEM=`uname -s` @@ -60,8 +67,10 @@ AC_SUBST(GIT_REVISION) AC_SUBST(GIT_RELEASE) AC_SUBST(N2N_DEFINES) AC_SUBST(N2N_LIBS) +AC_SUBST(ADDITIONAL_TOOLS) AC_CONFIG_HEADERS(config.h) AC_CONFIG_FILES(Makefile) +AC_CONFIG_FILES(tools/Makefile) AC_OUTPUT diff --git a/n2n.h b/n2n.h index 79151ff..a8dff99 100644 --- a/n2n.h +++ b/n2n.h @@ -42,8 +42,10 @@ #undef N2N_HAVE_DAEMON #undef N2N_HAVE_SETUID #else +#ifndef CMAKE_BUILD #include "config.h" #endif +#endif #define PACKAGE_BUILDDATE (__DATE__ " " __TIME__) diff --git a/tools/Makefile.in b/tools/Makefile.in new file mode 100644 index 0000000..82f3887 --- /dev/null +++ b/tools/Makefile.in @@ -0,0 +1,38 @@ +CC?=gcc +DEBUG?=-g3 +#OPTIMIZATION?=-O2 +WARN?=-Wall + +INSTALL=install +INSTALL_PROG=$(INSTALL) -m755 +MKDIR=mkdir -p + +LIBS_EDGE_OPT=@N2N_LIBS@ +LIBS_EDGE+=$(LIBS_EDGE_OPT) +HEADERS=../n2n_wire.h ../n2n.h ../twofish.h ../n2n_transforms.h +CFLAGS+=-I.. +LDFLAGS+=-L.. +CFLAGS+=$(DEBUG) $(OPTIMIZATION) $(WARN) + +N2N_LIB=../libn2n.a + +TOOLS=n2n-benchmark +TOOLS+=@ADDITIONAL_TOOLS@ + +.PHONY: all clean install +all: $(TOOLS) + +n2n-benchmark: benchmark.c $(N2N_LIB) $(HEADERS) + $(CC) $(CFLAGS) $< $(N2N_LIB) $(LIBS_EDGE) -o $@ + +n2n-decode: n2n_decode.c $(N2N_LIB) $(HEADERS) + $(CC) $(CFLAGS) $< $(N2N_LIB) $(LIBS_EDGE) -lpcap -o $@ + +.c.o: $(HEADERS) ../Makefile Makefile + $(CC) $(CFLAGS) -c $< -o $@ + +clean: + rm -rf $(TOOLS) $(N2N_LIB) *.o *.dSYM *~ + +install: $(TOOLS) + $(INSTALL_PROG) $(TOOLS) $(SBINDIR)/ diff --git a/benchmark.c b/tools/benchmark.c similarity index 100% rename from benchmark.c rename to tools/benchmark.c diff --git a/n2n_decode.c b/tools/n2n_decode.c similarity index 100% rename from n2n_decode.c rename to tools/n2n_decode.c