From c81889d02f716eede7602cf24dcd50a24db2f01b Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Sun, 30 Apr 2023 14:37:45 -0500 Subject: [PATCH 01/11] Refactoring the autoconf to towards always having a valid Makefile - this will allow simple build instructions --- .gitignore | 2 +- Makefile.in => Makefile | 21 ++++++--------------- autogen.sh | 2 +- config.mak.in | 9 +++++++++ configure.ac | 18 +++++++++--------- 5 files changed, 26 insertions(+), 26 deletions(-) rename Makefile.in => Makefile (97%) create mode 100644 config.mak.in diff --git a/.gitignore b/.gitignore index caf8f6f..cf9a09d 100644 --- a/.gitignore +++ b/.gitignore @@ -3,11 +3,11 @@ *.gz configure config.log +config.mak config.rpath config.status include/config.h include/config.h.in -/Makefile tools/Makefile autom4te.cache edge diff --git a/Makefile.in b/Makefile similarity index 97% rename from Makefile.in rename to Makefile index d1062ab..1bb818f 100644 --- a/Makefile.in +++ b/Makefile @@ -1,24 +1,16 @@ -# NOTE: these are needed by the configure.in inside the packages folder -N2N_VERSION=@N2N_VERSION@ - -######## - export CC export AR -CC=@CC@ -AR=@AR@ +export CFLAGS +export LDFLAGS +export LDLIBS + +include config.mak #Ultrasparc64 users experiencing SIGBUS should try the following gcc options #(thanks to Robert Gibbon) PLATOPTS_SPARC64=-mcpu=ultrasparc -pipe -fomit-frame-pointer -ffast-math -finline-functions -fweb -frename-registers -mapp-regs -export CFLAGS -export LDFLAGS - -CFLAGS=@CFLAGS@ -I./include -LDFLAGS=@LDFLAGS@ -L. - OPENSSL_CFLAGS=$(shell pkg-config openssl; echo $$?) ifeq ($(OPENSSL_CFLAGS), 0) CFLAGS+=$(shell pkg-config --cflags-only-I openssl) @@ -119,10 +111,9 @@ LINT_CCODE=\ tools/tests-transform.c \ tools/tests-wire.c \ -export LDLIBS LDLIBS+=-ln2n -LDLIBS+=@N2N_LIBS@ +LDLIBS+=$(LDLIBS_EXTRA) #For OpenSolaris (Solaris too?) ifeq ($(CONFIG_TARGET), sunos) diff --git a/autogen.sh b/autogen.sh index 0ff6b12..d6aac56 100755 --- a/autogen.sh +++ b/autogen.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -rm -f include/config.h include/config.h.in include/config.h.in~ Makefile configure +rm -f include/config.h include/config.h.in include/config.h.in~ config.mak configure echo "Wait please..." autoreconf -if diff --git a/config.mak.in b/config.mak.in new file mode 100644 index 0000000..692a5aa --- /dev/null +++ b/config.mak.in @@ -0,0 +1,9 @@ + +# NOTE: these are needed by the configure.in inside the packages folder +N2N_VERSION=@N2N_VERSION@ + +CC=@CC@ +AR=@AR@ +CFLAGS=@CFLAGS@ -I./include +LDFLAGS=@LDFLAGS@ -L. +LDLIBS_EXTRA+=@N2N_LIBS_EXTRA@ diff --git a/configure.ac b/configure.ac index 105cd32..0b81865 100644 --- a/configure.ac +++ b/configure.ac @@ -11,7 +11,7 @@ if test "${AR+set}" != set; then AR=ar fi -N2N_LIBS= +N2N_LIBS_EXTRA= AC_PROG_CC @@ -35,7 +35,7 @@ AS_IF([test "x$with_zstd" != "xno"], [AC_CHECK_LIB([zstd], [ZSTD_compress], [ AC_DEFINE([HAVE_ZSTD], [1], [Have ZSTD support]) - N2N_LIBS="-lzstd ${N2N_LIBS}" + N2N_LIBS_EXTRA="-lzstd ${N2N_LIBS_EXTRA}" ], [AC_MSG_ERROR([zstd library not found])] )], @@ -49,7 +49,7 @@ AS_IF([test "x$with_openssl" != xno], [AC_CHECK_LIB([crypto], [EVP_CIPHER_CTX_reset], [ AC_DEFINE([HAVE_OPENSSL_1_1], [1], [OpenSSL 1.1 is present]) - N2N_LIBS="-lcrypto ${N2N_LIBS}" + N2N_LIBS_EXTRA="-lcrypto ${N2N_LIBS_EXTRA}" ], [AC_MSG_ERROR([openssl library not found])] )], @@ -62,7 +62,7 @@ AS_IF([test "x$enable_miniupnp" != xno], [AC_CHECK_LIB([miniupnpc], [upnpDiscover], [ AC_DEFINE([HAVE_MINIUPNP], [1], [Have miniupnp library]) - N2N_LIBS="-lminiupnpc ${N2N_LIBS}" + N2N_LIBS_EXTRA="-lminiupnpc ${N2N_LIBS_EXTRA}" ], [AC_MSG_ERROR([miniupnp library not found])] )], @@ -75,7 +75,7 @@ AS_IF([test "x$enable_natpmp" != xno], [AC_CHECK_LIB([natpmp], [initnatpmp], [ AC_DEFINE([HAVE_NATPMP], [1], [Have natpmp library]) - N2N_LIBS="-lnatpmp ${N2N_LIBS}" + N2N_LIBS_EXTRA="-lnatpmp ${N2N_LIBS_EXTRA}" ], [AC_MSG_ERROR([natpmp library not found])] )], @@ -88,7 +88,7 @@ AS_IF([test "x$enable_pcap" != xno], [AC_CHECK_LIB([pcap], [pcap_open_live], [ AC_DEFINE([N2N_HAVE_PCAP], [1], [Have PCAP library]) - N2N_LIBS="-lpcap ${N2N_LIBS}" + N2N_LIBS_EXTRA="-lpcap ${N2N_LIBS_EXTRA}" ADDITIONAL_TOOLS="$ADDITIONAL_TOOLS n2n-decode" # TODO @@ -109,7 +109,7 @@ AS_IF([test "x$enable_cap" != xno], [AC_CHECK_LIB([cap], [cap_get_proc], [ AC_DEFINE([HAVE_LIBCAP],[1],[Support for linux capabilities]) - N2N_LIBS="${N2N_LIBS} -lcap" + N2N_LIBS_EXTRA="${N2N_LIBS_EXTRA} -lcap" ], [AC_MSG_ERROR([cap library not found])] )], @@ -150,10 +150,10 @@ AC_SUBST(AR) AC_SUBST(CFLAGS) AC_SUBST(LDFLAGS) AC_SUBST(N2N_VERSION) -AC_SUBST(N2N_LIBS) +AC_SUBST(N2N_LIBS_EXTRA) AC_SUBST(ADDITIONAL_TOOLS) AC_CONFIG_HEADERS(include/config.h) -AC_CONFIG_FILES(Makefile) +AC_CONFIG_FILES(config.mak) AC_CONFIG_FILES(tools/Makefile) AC_OUTPUT From bee517a753db3b66386104bfcdf4770fa4b2dc01 Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Sun, 30 Apr 2023 14:50:10 -0500 Subject: [PATCH 02/11] Update windows build for new config.mak --- scripts/hack_fakeautoconf.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/scripts/hack_fakeautoconf.sh b/scripts/hack_fakeautoconf.sh index a7f9203..91e1ca4 100755 --- a/scripts/hack_fakeautoconf.sh +++ b/scripts/hack_fakeautoconf.sh @@ -3,13 +3,13 @@ # Specifically for windows, where installing autoconf looks suspiciously # like boiling the ocean. -sed \ - -e "s%@CC@%gcc%g" \ - -e "s%@AR@%ar%g" \ - -e "s%@CFLAGS@%$CFLAGS%g" \ - -e "s%@LDFLAGS@%$LDFLAGS%g" \ - -e "s%@N2N_LIBS@%$LDLIBS%g" \ - < Makefile.in > Makefile +cat >config.mak < Date: Sun, 30 Apr 2023 18:07:40 -0500 Subject: [PATCH 03/11] Convert the tools dir makefile similarly to the topdir --- .gitignore | 2 +- configure.ac | 6 +++--- scripts/hack_fakeautoconf.sh | 6 +++--- tools/{Makefile.in => Makefile} | 4 +++- tools/config.mak.in | 2 ++ 5 files changed, 12 insertions(+), 8 deletions(-) rename tools/{Makefile.in => Makefile} (95%) create mode 100644 tools/config.mak.in diff --git a/.gitignore b/.gitignore index cf9a09d..c51830a 100644 --- a/.gitignore +++ b/.gitignore @@ -8,7 +8,7 @@ config.rpath config.status include/config.h include/config.h.in -tools/Makefile +tools/config.mak autom4te.cache edge example_edge_embed_quick_edge_init diff --git a/configure.ac b/configure.ac index 0b81865..fb37696 100644 --- a/configure.ac +++ b/configure.ac @@ -89,7 +89,7 @@ AS_IF([test "x$enable_pcap" != xno], [ AC_DEFINE([N2N_HAVE_PCAP], [1], [Have PCAP library]) N2N_LIBS_EXTRA="-lpcap ${N2N_LIBS_EXTRA}" - ADDITIONAL_TOOLS="$ADDITIONAL_TOOLS n2n-decode" + TOOLS_ADDITIONAL="$TOOLS_ADDITIONAL n2n-decode" # TODO # - pcap_set_immediate_mode has been available since libpcap 1.5 @@ -151,9 +151,9 @@ AC_SUBST(CFLAGS) AC_SUBST(LDFLAGS) AC_SUBST(N2N_VERSION) AC_SUBST(N2N_LIBS_EXTRA) -AC_SUBST(ADDITIONAL_TOOLS) +AC_SUBST(TOOLS_ADDITIONAL) AC_CONFIG_HEADERS(include/config.h) AC_CONFIG_FILES(config.mak) -AC_CONFIG_FILES(tools/Makefile) +AC_CONFIG_FILES(tools/config.mak) AC_OUTPUT diff --git a/scripts/hack_fakeautoconf.sh b/scripts/hack_fakeautoconf.sh index 91e1ca4..4d06fe7 100755 --- a/scripts/hack_fakeautoconf.sh +++ b/scripts/hack_fakeautoconf.sh @@ -11,9 +11,9 @@ LDFLAGS=$LDFLAGS N2N_LIBS_EXTRA=$LDLIBS EOF -sed \ - -e "s%@ADDITIONAL_TOOLS@%%g" \ - < tools/Makefile.in > tools/Makefile +cat >tools/config.mak <include/config.h #define PACKAGE_VERSION "FIXME" diff --git a/tools/Makefile.in b/tools/Makefile similarity index 95% rename from tools/Makefile.in rename to tools/Makefile index a5860eb..683311e 100644 --- a/tools/Makefile.in +++ b/tools/Makefile @@ -2,6 +2,8 @@ # This is not a standalone makefile, it must be called from the toplevel # makefile to inherit the correct environment +include config.mak + DEBUG?=-g3 HEADERS=$(wildcard include/*.h) @@ -16,7 +18,7 @@ LDFLAGS+=-L.. N2N_LIB=../libn2n.a TOOLS=n2n-benchmark n2n-keygen n2n-route n2n-portfwd -TOOLS+=@ADDITIONAL_TOOLS@ +TOOLS+=$(TOOLS_ADDITIONAL) TESTS=tests-compress tests-elliptic tests-hashing tests-transform TESTS+=tests-wire diff --git a/tools/config.mak.in b/tools/config.mak.in new file mode 100644 index 0000000..d396110 --- /dev/null +++ b/tools/config.mak.in @@ -0,0 +1,2 @@ + +TOOLS_ADDITIONAL=@TOOLS_ADDITIONAL@ From 4e2b9e0a919013326f374758b99211ad2f9eead0 Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Sun, 30 Apr 2023 18:53:30 -0500 Subject: [PATCH 04/11] First, build the project - allowing build errors to easily show up --- .github/workflows/tests.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f1b5b88..c434b27 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -282,6 +282,10 @@ jobs: ./scripts/hack_fakeautoconf.sh shell: bash + - name: Build the project + run: make + shell: bash + - name: Run embedded unit tests run: make test.units shell: bash From 37722ab8b61ef6c170e361dff31ce4c6506af96f Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Sun, 30 Apr 2023 19:00:04 -0500 Subject: [PATCH 05/11] Consolidate the config.mak settings --- Makefile | 6 ------ config.mak.in | 12 +++++++++--- configure.ac | 1 - tools/Makefile | 2 -- tools/config.mak.in | 2 -- 5 files changed, 9 insertions(+), 14 deletions(-) delete mode 100644 tools/config.mak.in diff --git a/Makefile b/Makefile index 1bb818f..08633dc 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,4 @@ -export CC -export AR -export CFLAGS -export LDFLAGS -export LDLIBS - include config.mak #Ultrasparc64 users experiencing SIGBUS should try the following gcc options diff --git a/config.mak.in b/config.mak.in index 692a5aa..6c1345f 100644 --- a/config.mak.in +++ b/config.mak.in @@ -1,9 +1,15 @@ +export N2N_VERSION +export CC +export AR +export CFLAGS +export LDFLAGS +export LDLIBS_EXTRA +export TOOLS_ADDITIONAL -# NOTE: these are needed by the configure.in inside the packages folder N2N_VERSION=@N2N_VERSION@ - CC=@CC@ AR=@AR@ CFLAGS=@CFLAGS@ -I./include LDFLAGS=@LDFLAGS@ -L. -LDLIBS_EXTRA+=@N2N_LIBS_EXTRA@ +LDLIBS_EXTRA=@N2N_LIBS_EXTRA@ +TOOLS_ADDITIONAL=@TOOLS_ADDITIONAL@ diff --git a/configure.ac b/configure.ac index fb37696..a15a6d6 100644 --- a/configure.ac +++ b/configure.ac @@ -154,6 +154,5 @@ AC_SUBST(N2N_LIBS_EXTRA) AC_SUBST(TOOLS_ADDITIONAL) AC_CONFIG_HEADERS(include/config.h) AC_CONFIG_FILES(config.mak) -AC_CONFIG_FILES(tools/config.mak) AC_OUTPUT diff --git a/tools/Makefile b/tools/Makefile index 683311e..74e1fad 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -2,8 +2,6 @@ # This is not a standalone makefile, it must be called from the toplevel # makefile to inherit the correct environment -include config.mak - DEBUG?=-g3 HEADERS=$(wildcard include/*.h) diff --git a/tools/config.mak.in b/tools/config.mak.in deleted file mode 100644 index d396110..0000000 --- a/tools/config.mak.in +++ /dev/null @@ -1,2 +0,0 @@ - -TOOLS_ADDITIONAL=@TOOLS_ADDITIONAL@ From 897ccd9780c3e217ed6ff6473928c8f3a2f1ee46 Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Sun, 30 Apr 2023 19:16:59 -0500 Subject: [PATCH 06/11] Stop auto creating the OBJ list, allowing a libn2n that does not contain a main() function --- Makefile | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 08633dc..615ea97 100644 --- a/Makefile +++ b/Makefile @@ -64,8 +64,44 @@ MAN7DIR=$(MANDIR)/man7 MAN8DIR=$(MANDIR)/man8 N2N_LIB=libn2n.a -N2N_OBJS=$(patsubst src/%.c, src/%.o, $(wildcard src/*.c)) -N2N_DEPS=$(wildcard include/*.h) $(wildcard src/*.c) Makefile +N2N_OBJS=\ + src/aes.o \ + src/auth.o \ + src/cc20.o \ + src/curve25519.o \ + src/edge_management.o \ + src/edge_utils.o \ + src/edge_utils_win32.o \ + src/header_encryption.o \ + src/hexdump.o \ + src/json.o \ + src/management.o \ + src/minilzo.o \ + src/n2n.o \ + src/n2n_port_mapping.o \ + src/n2n_regex.o \ + src/network_traffic_filter.o \ + src/pearson.o \ + src/random_numbers.o \ + src/sn_management.o \ + src/sn_selection.o \ + src/sn_utils.o \ + src/speck.o \ + src/tf.o \ + src/transform_aes.o \ + src/transform_cc20.o \ + src/transform_lzo.o \ + src/transform_null.o \ + src/transform_speck.o \ + src/transform_tf.o \ + src/transform_zstd.o \ + src/tuntap_freebsd.o \ + src/tuntap_linux.o \ + src/tuntap_netbsd.o \ + src/tuntap_osx.o \ + src/wire.o \ + +N2N_DEPS=$(wildcard include/*.h) $(wildcard src/*.c) config.mak # As source files pass the linter, they can be added here (If all the source # is passing the linter tests, this can be refactored) @@ -244,6 +280,7 @@ endif .PHONY: clean clean: + rm -f src/edge.o src/supernode.o src/example_edge_embed.o src/example_edge_embed_quick_edge_init.o src/example_sn_embed.o rm -rf $(N2N_OBJS) $(N2N_LIB) $(APPS) $(DOCS) $(COVERAGEDIR)/ *.dSYM *~ rm -f tests/*.out src/*.gcno src/*.gcda for dir in $(SUBDIRS); do $(MAKE) -C $$dir clean; done From 9de98c2bb0817494201f32faf6dba3624ed4bf4d Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Sun, 30 Apr 2023 19:36:06 -0500 Subject: [PATCH 07/11] Ensure the library is linked to the tools --- tools/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/Makefile b/tools/Makefile index 74e1fad..d5d8807 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -6,6 +6,7 @@ DEBUG?=-g3 HEADERS=$(wildcard include/*.h) CFLAGS+=-I../include +LDLIBS+=-ln2n ifeq ($(CONFIG_TARGET),mingw) CFLAGS+=-I../win32 LDLIBS+=-lnetapi32 From 1accc76ad3280c36de48e44af1714b7c39fdfe1f Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Sun, 30 Apr 2023 19:44:38 -0500 Subject: [PATCH 08/11] Fix the building the win32 subdir. It looks like the github windows build environment is not correctly inheriting environment variables. Which is strange, as that has not been changed with the recent updates. Include the vars directly as a workaround (and plan to refactor later) --- include/n2n_typedefs.h | 1 + scripts/hack_fakeautoconf.sh | 4 ++-- tools/Makefile | 8 +++++++- win32/Makefile | 6 +++++- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/include/n2n_typedefs.h b/include/n2n_typedefs.h index 047c991..bb8e4f5 100644 --- a/include/n2n_typedefs.h +++ b/include/n2n_typedefs.h @@ -51,6 +51,7 @@ typedef int ssize_t; typedef unsigned long in_addr_t; #include "n2n_win32.h" +// FIXME - the above include is from a different subdir #endif /* #if defined(_MSC_VER) || defined(__MINGW32__) */ diff --git a/scripts/hack_fakeautoconf.sh b/scripts/hack_fakeautoconf.sh index 4d06fe7..c8f195c 100755 --- a/scripts/hack_fakeautoconf.sh +++ b/scripts/hack_fakeautoconf.sh @@ -6,8 +6,8 @@ cat >config.mak < Date: Sun, 30 Apr 2023 20:45:27 -0500 Subject: [PATCH 09/11] Remove left over cmake file --- win32/CMakeLists.txt | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 win32/CMakeLists.txt diff --git a/win32/CMakeLists.txt b/win32/CMakeLists.txt deleted file mode 100644 index 2e96b18..0000000 --- a/win32/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -add_library(n2n_win32 - getopt1.c - getopt.c - wintap.c) -target_link_libraries(n2n_win32 PUBLIC ws2_32.lib) From c9447689fb129bd9e092680ddf96e55a453add26 Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Sun, 30 Apr 2023 20:45:44 -0500 Subject: [PATCH 10/11] Update dependancies for new configure file --- tools/Makefile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/Makefile b/tools/Makefile index fce1d47..fb7b222 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -32,12 +32,12 @@ TESTS+=tests-auth .PHONY: all clean install all: $(TOOLS) $(TESTS) -n2n-benchmark.o: $(N2N_LIB) $(HEADERS) ../Makefile Makefile -n2n-keygen.o: $(N2N_LIB) $(HEADERS) ../Makefile Makefile -n2n-route.o: $(N2N_LIB) $(HEADERS) ../Makefile Makefile -n2n-portfwd.o: $(N2N_LIB) $(HEADERS) ../Makefile Makefile +n2n-benchmark.o: $(N2N_LIB) $(HEADERS) ../config.mak +n2n-keygen.o: $(N2N_LIB) $(HEADERS) ../config.mak +n2n-route.o: $(N2N_LIB) $(HEADERS) ../config.mak +n2n-portfwd.o: $(N2N_LIB) $(HEADERS) ../config.mak -n2n-decode: n2n-decode.c $(N2N_LIB) $(HEADERS) ../Makefile Makefile +n2n-decode: n2n-decode.c $(N2N_LIB) $(HEADERS) ../config.mak $(CC) $(CFLAGS) $< $(LDFLAGS) $(LDLIBS) -lpcap -o $@ # See comments in the topdir Makefile about how to generate coverage From 6b4a9c4387626dc06d1278d9d3410f673e32d876 Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Sun, 30 Apr 2023 20:45:55 -0500 Subject: [PATCH 11/11] Remove duplicated build targets --- .github/workflows/tests.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c434b27..e752555 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -106,7 +106,6 @@ jobs: fail-fast: true matrix: os: - - ubuntu-22.04 - ubuntu-20.04 - ubuntu-22.04 @@ -178,7 +177,6 @@ jobs: fail-fast: true matrix: os: - - macos-12 - macos-11 - macos-12