You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

261 lines
8.1 KiB

project(n2n)
cmake_minimum_required(VERSION 2.6)
include(CheckFunctionExists)
SET(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# N2n release information
set(N2N_OSNAME ${CMAKE_SYSTEM_NAME})
execute_process(
COMMAND scripts/version.sh
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE PACKAGE_VERSION
)
string(STRIP "${PACKAGE_VERSION}" PACKAGE_VERSION)
MESSAGE(STATUS "Build for version: ${PACKAGE_VERSION}")
add_definitions(-DCMAKE_BUILD)
add_definitions(-DPACKAGE_OSNAME="${N2N_OSNAME}" -DN2N_OSNAME="${N2N_OSNAME}")
add_definitions(-DPACKAGE_VERSION="${PACKAGE_VERSION}")
# Build information
OPTION(BUILD_SHARED_LIBS "BUILD Shared Library" OFF)
# N2n specific params
OPTION(N2N_OPTION_USE_PTHREAD "USE PTHREAD Library" ON)
OPTION(N2N_OPTION_USE_OPENSSL "USE OPENSSL Library" OFF)
OPTION(N2N_OPTION_USE_PCAPLIB "USE PCAP Library" OFF)
OPTION(N2N_OPTION_USE_ZSTD "USE ZSTD Library" OFF)
if(N2N_OPTION_USE_PTHREAD)
find_library(PTHREAD_LIB pthread)
if(PTHREAD_LIB)
ADD_DEFINITIONS("-DHAVE_PTHREAD")
else()
MESSAGE(WARNING "libpthread not found.")
set(N2N_OPTION_USE_PTHREAD OFF)
endif(PTHREAD_LIB)
endif(N2N_OPTION_USE_PTHREAD)
if(NOT DEFINED N2N_OPTION_USE_OPENSSL)
set(N2N_OPTION_USE_OPENSSL OFF)
endif(NOT DEFINED N2N_OPTION_USE_OPENSSL)
if(N2N_OPTION_USE_OPENSSL)
find_package(OpenSSL QUIET)
if(NOT OPENSSL_FOUND)
MESSAGE(WARNING "OpenSSL not found, Use built-in AES.")
set(N2N_OPTION_USE_OPENSSL OFF)
else()
MESSAGE(STATUS "Found OpenSSL ${OPENSSL_VERSION}")
string(COMPARE GREATER "${OPENSSL_VERSION}" "1.1" OPENSSL_V11)
if(OPENSSL_V11)
MESSAGE(STATUS "Use OpenSSL With -DHAVE_OPENSSL_1_1")
include_directories(${OPENSSL_INCLUDE_DIR})
add_definitions(-DHAVE_OPENSSL_1_1)
endif()
endif(NOT OPENSSL_FOUND)
endif(N2N_OPTION_USE_OPENSSL)
if(N2N_OPTION_USE_ZSTD)
add_definitions(-DN2N_HAVE_ZSTD)
endif(N2N_OPTION_USE_ZSTD)
if(NOT DEFINED CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE None)
endif(NOT DEFINED CMAKE_BUILD_TYPE)
#set(CMAKE_BUILD_TYPE Debug)
#set(CMAKE_BUILD_TYPE Release)
if (DEFINED UNIX)
# None
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wshadow -Wpointer-arith -Wmissing-declarations -Wnested-externs")
set(CMAKE_CXX_FLAGS "-Wall -Wshadow -Wpointer-arith -Wmissing-declarations -Wnested-externs")
# Debug
set(CMAKE_C_FLAGS_DEBUG "-g")
set(CMAKE_CXX_FLAGS_DEBUG "-g")
# Release
set(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG")
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")
endif(DEFINED UNIX)
# Static target.
#SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -static")
INCLUDE_DIRECTORIES(.)
INCLUDE_DIRECTORIES(include)
if(DEFINED WIN32)
INCLUDE_DIRECTORIES(win32)
# Customize include.
# INCLUDE_DIRECTORIES("D:/Program Files/MinGW/opt/include/" "D:/Program Files/MinGW/x86_64-w64-mingw32/include/")
# Customize library.
# LINK_DIRECTORIES("D:/Program Files/MinGW/opt/lib/" "D:/Program Files/MinGW/x86_64-w64-mingw32/lib/")
endif(DEFINED WIN32)
#aux_source_directory(./src N2N_DIR_SRCS)
#add_library(n2n STATIC ${N2N_DIR_SRCS})
add_library(n2n STATIC
src/n2n.c
JSON Reply Management API - feature parity with old management interfaces (#861) * Ensure that recent code additions pass the linter * Include some of the more obviously correct lint fixes to edge_utils.c * Refactor edge JSON api into its own source file * Use shorter names for static management functions * Implement a JSON RPC way of managing the verbosity * Tidy up help display in n2nctl script * Make note of issue with implementing the stop command * Implement a JSON RPC call to fetch current community * Make n2nhttpd time value be more self-contained * Make n2nhttpd order more closely match the existing management stats output * Wire up status page to the verbosity setting * Add JSON versions of the remainder of the edge management stats * Add new file to cmake * Properly define management handler * Only update the last updated timestamp after a successful data fetch * Function and types definition cleanup * Force correct type for python scripts mgmt port * Implement initial JSON API for supernode * Fix whitespace error * Use helper function for rendering peers ip4 address * Proxy the auth requirement back out to the http client, allowing normal http auth to be used * Ensure that we do not leak the federation community * Use the same rpc method name and output for both edge and supernode for peers/edges * Allow n2nctl to show raw data returned without resorting to tricks * Make n2nctl pretty printer understandable with an empty table * Use the full name for supernodes RPC call * Use same RPC method name (but some missing fields) for getting communities from both edge and supernode * Add *_sup_broadcast stats to edge packet stats output * Refacter the stats into a packetstats method for supernode RPC * Even if I am not going to prettyprint the timestamps, at least make all the timestamps on the page the same unit * Simplify the RPC handlers by flagging some as writable and checking that in the multiplexer * Remove invalid edges data * Avoid crash on bad data to verbose RPC * Avoid showing bad or inconsistant protocol data in communities RPC * Minor clarification on when --write is handled * Make linter happy * Fix changed method name in n2nhttpd * Move mainloop stop flag into the n2n_edge_t structure, allowing access from management commands * Implement edge RPC stop command * Move mainloop stop flag into the n2n_sn_t structure, allowing access from management commands * Implement supernode RPC stop command * Allow multiple pages to be served from mini httpd * Extract common script functions into a separate URL * Handle an edge case in the python rpc class With a proper tag-based demultiplexer, this case should be a nop, but we are single-threaded and rely on the packet ordering in this library. * Add n2nhttpd support to query supernode using urls prefixed with /supernode/ * Handle missing values in javascript table print * Add another less filtering javascript key/value renderer * Add a supernode.html page to the n2nhttpd * Address lint issue * Mention the second html page on the Scripts doc * Remove purgable column from supernode edges list - it looks like it is rarely going to be set * Add a simple one-line example command at the top of the API documentation * Acknowledge that this is not the most efficient protocol, but point out that it was not supposed to be * Make it clear that the n2nctl script works for both edge and supernode * Fight with inconsistant github runner results * Turn off the /right/ coverage generator
3 years ago
src/edge_management.c
src/edge_utils.c
JSON Reply Management API - feature parity with old management interfaces (#861) * Ensure that recent code additions pass the linter * Include some of the more obviously correct lint fixes to edge_utils.c * Refactor edge JSON api into its own source file * Use shorter names for static management functions * Implement a JSON RPC way of managing the verbosity * Tidy up help display in n2nctl script * Make note of issue with implementing the stop command * Implement a JSON RPC call to fetch current community * Make n2nhttpd time value be more self-contained * Make n2nhttpd order more closely match the existing management stats output * Wire up status page to the verbosity setting * Add JSON versions of the remainder of the edge management stats * Add new file to cmake * Properly define management handler * Only update the last updated timestamp after a successful data fetch * Function and types definition cleanup * Force correct type for python scripts mgmt port * Implement initial JSON API for supernode * Fix whitespace error * Use helper function for rendering peers ip4 address * Proxy the auth requirement back out to the http client, allowing normal http auth to be used * Ensure that we do not leak the federation community * Use the same rpc method name and output for both edge and supernode for peers/edges * Allow n2nctl to show raw data returned without resorting to tricks * Make n2nctl pretty printer understandable with an empty table * Use the full name for supernodes RPC call * Use same RPC method name (but some missing fields) for getting communities from both edge and supernode * Add *_sup_broadcast stats to edge packet stats output * Refacter the stats into a packetstats method for supernode RPC * Even if I am not going to prettyprint the timestamps, at least make all the timestamps on the page the same unit * Simplify the RPC handlers by flagging some as writable and checking that in the multiplexer * Remove invalid edges data * Avoid crash on bad data to verbose RPC * Avoid showing bad or inconsistant protocol data in communities RPC * Minor clarification on when --write is handled * Make linter happy * Fix changed method name in n2nhttpd * Move mainloop stop flag into the n2n_edge_t structure, allowing access from management commands * Implement edge RPC stop command * Move mainloop stop flag into the n2n_sn_t structure, allowing access from management commands * Implement supernode RPC stop command * Allow multiple pages to be served from mini httpd * Extract common script functions into a separate URL * Handle an edge case in the python rpc class With a proper tag-based demultiplexer, this case should be a nop, but we are single-threaded and rely on the packet ordering in this library. * Add n2nhttpd support to query supernode using urls prefixed with /supernode/ * Handle missing values in javascript table print * Add another less filtering javascript key/value renderer * Add a supernode.html page to the n2nhttpd * Address lint issue * Mention the second html page on the Scripts doc * Remove purgable column from supernode edges list - it looks like it is rarely going to be set * Add a simple one-line example command at the top of the API documentation * Acknowledge that this is not the most efficient protocol, but point out that it was not supposed to be * Make it clear that the n2nctl script works for both edge and supernode * Fight with inconsistant github runner results * Turn off the /right/ coverage generator
3 years ago
src/sn_management.c
src/sn_utils.c
src/wire.c
added test framework and code coverage reporting (#797) * Add a simple test framework * Add a code coverage report example oneliner * Move the coverage report into a separate directory * Add a github action to run tests and publish a branch with the coverage report * Fix: Missing job separator * Fix: remember to actually run configure * Fix: Gotta autogen before I configure * Dont try to upload coverage report unless this is a push * Clearly show the git ref tested in the coverage report * Add a test for the various transforms * Add tests for the elliptic curve and pearson hash * Ensure we ignore new generated output * Remove unneeded boilerplate from the compression tests * Add an example of a test of the encoded wire packets * Ensure that correctly testable data is output even when zstd is not compiled * Factor test runner out into its own script and attempt to add it to the cmake file * Tell cmake about a new object file * Stop trying to make Cmake work... * Stop trying to make cmake work, round 2 * In the middle of a thousand lines of cmake output was one important one - windows could not find assert() - try again * Try again to plumb the tests into cmake * Add missing library to our superset install line * Fix build error when libcap-dev is installed * Switch to using artifact uploads instead of pages to store/show the coverage report * Fix artifact upload yaml * Upload coverage report to codecov * Fix codecov - clearly it doesnt do a recursive search for coverage files * Fix codecov - my hopeful use of a list of directories didnt work * Fix codecov - unfortunately, it doesnt just consume the coverage data and needs us to generate the gcov output * Fix codecov - nope, it still doesnt recursively search * Fix codecov - it really helps if I run the gcov data generator * Add a simple matrix build * Fix older ubuntu versions of gcovr that do not support the '--html-title' option * Ensure we use gcover options that are identical on older ubuntu * Improve coverage generation and required build packages
3 years ago
src/hexdump.c
src/minilzo.c
src/tf.c
4 years ago
src/cc20.c
src/transform_null.c
src/transform_tf.c
src/transform_aes.c
src/transform_cc20.c
src/transform_speck.c
src/aes.c
src/speck.c
src/random_numbers.c
src/pearson.c
src/header_encryption.c
src/tuntap_freebsd.c
src/tuntap_netbsd.c
src/tuntap_linux.c
src/tuntap_osx.c
src/n2n_regex.c
src/network_traffic_filter.c
src/sn_selection.c
src/auth.c
src/curve25519.c)
if(N2N_OPTION_USE_PTHREAD)
target_link_libraries(n2n pthread)
endif(N2N_OPTION_USE_PTHREAD)
if(N2N_OPTION_USE_OPENSSL)
# target_link_libraries(n2n crypto)
target_link_libraries(n2n ${OPENSSL_LIBRARIES})
endif(N2N_OPTION_USE_OPENSSL)
if(N2N_OPTION_USE_ZSTD)
target_link_libraries(n2n zstd)
endif(N2N_OPTION_USE_ZSTD)
if(DEFINED WIN32)
add_library(edge_utils_win32 src/edge_utils_win32.c)
add_subdirectory(win32)
target_link_libraries(n2n edge_utils_win32 n2n_win32 iphlpapi)
endif(DEFINED WIN32)
add_executable(edge src/edge.c)
target_link_libraries(edge n2n)
add_executable(supernode src/supernode.c)
target_link_libraries(supernode n2n)
add_executable(example_edge_embed_quick_edge_init src/example_edge_embed_quick_edge_init.c)
target_link_libraries(example_edge_embed_quick_edge_init n2n)
add_executable(example_edge_embed src/example_edge_embed.c)
target_link_libraries(example_edge_embed n2n)
add_executable(example_sn_embed src/example_sn_embed.c)
target_link_libraries(example_sn_embed n2n)
if(N2N_OPTION_USE_PCAPLIB AND (NOT DEFINED WIN32))
# Linux Capabilities
find_library(CAP_LIB cap)
if(CAP_LIB)
target_link_libraries(edge cap.a)
set(CMAKE_REQUIRED_LIBRARIES ${CAP_LIB})
ADD_DEFINITIONS("-DHAVE_LIBCAP")
endif()
endif(N2N_OPTION_USE_PCAPLIB AND (NOT DEFINED WIN32))
install(TARGETS edge supernode
RUNTIME DESTINATION sbin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)
# Tools
add_executable(n2n-benchmark tools/n2n-benchmark.c)
target_link_libraries(n2n-benchmark n2n)
add_executable(n2n-keygen tools/n2n-keygen.c)
target_link_libraries(n2n-keygen n2n)
added test framework and code coverage reporting (#797) * Add a simple test framework * Add a code coverage report example oneliner * Move the coverage report into a separate directory * Add a github action to run tests and publish a branch with the coverage report * Fix: Missing job separator * Fix: remember to actually run configure * Fix: Gotta autogen before I configure * Dont try to upload coverage report unless this is a push * Clearly show the git ref tested in the coverage report * Add a test for the various transforms * Add tests for the elliptic curve and pearson hash * Ensure we ignore new generated output * Remove unneeded boilerplate from the compression tests * Add an example of a test of the encoded wire packets * Ensure that correctly testable data is output even when zstd is not compiled * Factor test runner out into its own script and attempt to add it to the cmake file * Tell cmake about a new object file * Stop trying to make Cmake work... * Stop trying to make cmake work, round 2 * In the middle of a thousand lines of cmake output was one important one - windows could not find assert() - try again * Try again to plumb the tests into cmake * Add missing library to our superset install line * Fix build error when libcap-dev is installed * Switch to using artifact uploads instead of pages to store/show the coverage report * Fix artifact upload yaml * Upload coverage report to codecov * Fix codecov - clearly it doesnt do a recursive search for coverage files * Fix codecov - my hopeful use of a list of directories didnt work * Fix codecov - unfortunately, it doesnt just consume the coverage data and needs us to generate the gcov output * Fix codecov - nope, it still doesnt recursively search * Fix codecov - it really helps if I run the gcov data generator * Add a simple matrix build * Fix older ubuntu versions of gcovr that do not support the '--html-title' option * Ensure we use gcover options that are identical on older ubuntu * Improve coverage generation and required build packages
3 years ago
add_executable(tests-compress tools/tests-compress.c)
target_link_libraries(tests-compress n2n)
add_executable(tests-elliptic tools/tests-elliptic.c)
target_link_libraries(tests-elliptic n2n)
add_executable(tests-hashing tools/tests-hashing.c)
target_link_libraries(tests-hashing n2n)
add_executable(tests-transform tools/tests-transform.c)
target_link_libraries(tests-transform n2n)
add_executable(tests-wire tools/tests-wire.c)
target_link_libraries(tests-wire n2n)
if(N2N_OPTION_USE_PCAPLIB)
find_library(PCAP_LIB pcap)
if(PCAP_LIB)
add_executable(n2n-decode tools/n2n-decode.c)
target_link_libraries(n2n-decode n2n pcap)
install(TARGETS n2n-decode RUNTIME DESTINATION bin)
set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIB})
check_function_exists(pcap_set_immediate_mode HAVE_PCAP_IMMEDIATE_MODE)
IF(HAVE_PCAP_IMMEDIATE_MODE)
ADD_DEFINITIONS("-DHAVE_PCAP_IMMEDIATE_MODE")
ENDIF(HAVE_PCAP_IMMEDIATE_MODE)
endif(PCAP_LIB)
endif(N2N_OPTION_USE_PCAPLIB)
install(TARGETS n2n-benchmark RUNTIME DESTINATION bin)
# Documentation
if(DEFINED UNIX)
add_dependencies(n2n doc)
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/doc)
add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/doc/edge.8.gz
COMMAND gzip -c ${PROJECT_SOURCE_DIR}/edge.8 > ${PROJECT_BINARY_DIR}/doc/edge.8.gz
DEPENDS ${PROJECT_SOURCE_DIR}/edge.8
)
add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/doc/supernode.1.gz
COMMAND gzip -c ${PROJECT_SOURCE_DIR}/supernode.1 > ${PROJECT_BINARY_DIR}/doc/supernode.1.gz
DEPENDS ${PROJECT_SOURCE_DIR}/supernode.1
)
add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/doc/n2n.7.gz
COMMAND gzip -c ${PROJECT_SOURCE_DIR}/n2n.7 > ${PROJECT_BINARY_DIR}/doc/n2n.7.gz
DEPENDS ${PROJECT_SOURCE_DIR}/n2n.7
)
add_custom_target(doc DEPENDS ${PROJECT_BINARY_DIR}/doc/edge.8.gz
${PROJECT_BINARY_DIR}/doc/supernode.1.gz
${PROJECT_BINARY_DIR}/doc/n2n.7.gz
)
set_source_files_properties(${PROJECT_BINARY_DIR}/doc/edge.8.gz
${PROJECT_BINARY_DIR}/doc/supernode.1.gz
${PROJECT_BINARY_DIR}/doc/n2n.7.gz
PROPERTIES GENERATED 1)
install(FILES ${PROJECT_BINARY_DIR}/doc/edge.8.gz
DESTINATION /usr/share/man/man8)
install(FILES ${PROJECT_BINARY_DIR}/doc/supernode.1.gz
DESTINATION /usr/share/man/man1)
install(FILES ${PROJECT_BINARY_DIR}/doc/n2n.7.gz
DESTINATION /usr/share/man/man7)
added test framework and code coverage reporting (#797) * Add a simple test framework * Add a code coverage report example oneliner * Move the coverage report into a separate directory * Add a github action to run tests and publish a branch with the coverage report * Fix: Missing job separator * Fix: remember to actually run configure * Fix: Gotta autogen before I configure * Dont try to upload coverage report unless this is a push * Clearly show the git ref tested in the coverage report * Add a test for the various transforms * Add tests for the elliptic curve and pearson hash * Ensure we ignore new generated output * Remove unneeded boilerplate from the compression tests * Add an example of a test of the encoded wire packets * Ensure that correctly testable data is output even when zstd is not compiled * Factor test runner out into its own script and attempt to add it to the cmake file * Tell cmake about a new object file * Stop trying to make Cmake work... * Stop trying to make cmake work, round 2 * In the middle of a thousand lines of cmake output was one important one - windows could not find assert() - try again * Try again to plumb the tests into cmake * Add missing library to our superset install line * Fix build error when libcap-dev is installed * Switch to using artifact uploads instead of pages to store/show the coverage report * Fix artifact upload yaml * Upload coverage report to codecov * Fix codecov - clearly it doesnt do a recursive search for coverage files * Fix codecov - my hopeful use of a list of directories didnt work * Fix codecov - unfortunately, it doesnt just consume the coverage data and needs us to generate the gcov output * Fix codecov - nope, it still doesnt recursively search * Fix codecov - it really helps if I run the gcov data generator * Add a simple matrix build * Fix older ubuntu versions of gcovr that do not support the '--html-title' option * Ensure we use gcover options that are identical on older ubuntu * Improve coverage generation and required build packages
3 years ago
# TODO:
# - Add the right dependancy so that the tests binaries get built first
enable_testing()
Basic C Code lint checker and shell checker (#859) * Factor build packages out into a more maintainable list * Create a location for scripts to live * Provide a make target to return the source dir as close as reasonable to the original distributed state * Add a code lint step, checking the coding style * Change test harness as recommended by shellcheck * Ensure we actually have the linter tool installed * Use the correct directory for cmake to run the tests * Adjust for the older uncrustify in the current github ubuntu-latest * Make one file pass the linter * Integrate the lint with the existing test workflow * Add files with minimal changes needed to the linter * Add more files with minimal changes needed to the linter * Dont build binaries if we fail the lint test * Update the phony targets with the lint steps * Ensure the flake8 package is installed in the new lint workflow job * Use the makefile to drive the packages needed to install for linting * No need to add dependancies on lint, just rely on the workflow status to show failure * Update the scripts dir README to reflect current assumptions * Rename and briefly document the indent.sh script * Fix the ignore to ignore the right Makefile * Rename the test_harness script to make it clear it is a shell script * Provide a master lint make target and add a shell script lint tool * Elminate stray tabs * Drop include/auth.h from linter - there are inconsistant results with function definitions when using the current uncrustify rules
3 years ago
add_test(tests ${PROJECT_SOURCE_DIR}/scripts/test_harness.sh ${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR}/tests)
added test framework and code coverage reporting (#797) * Add a simple test framework * Add a code coverage report example oneliner * Move the coverage report into a separate directory * Add a github action to run tests and publish a branch with the coverage report * Fix: Missing job separator * Fix: remember to actually run configure * Fix: Gotta autogen before I configure * Dont try to upload coverage report unless this is a push * Clearly show the git ref tested in the coverage report * Add a test for the various transforms * Add tests for the elliptic curve and pearson hash * Ensure we ignore new generated output * Remove unneeded boilerplate from the compression tests * Add an example of a test of the encoded wire packets * Ensure that correctly testable data is output even when zstd is not compiled * Factor test runner out into its own script and attempt to add it to the cmake file * Tell cmake about a new object file * Stop trying to make Cmake work... * Stop trying to make cmake work, round 2 * In the middle of a thousand lines of cmake output was one important one - windows could not find assert() - try again * Try again to plumb the tests into cmake * Add missing library to our superset install line * Fix build error when libcap-dev is installed * Switch to using artifact uploads instead of pages to store/show the coverage report * Fix artifact upload yaml * Upload coverage report to codecov * Fix codecov - clearly it doesnt do a recursive search for coverage files * Fix codecov - my hopeful use of a list of directories didnt work * Fix codecov - unfortunately, it doesnt just consume the coverage data and needs us to generate the gcov output * Fix codecov - nope, it still doesnt recursively search * Fix codecov - it really helps if I run the gcov data generator * Add a simple matrix build * Fix older ubuntu versions of gcovr that do not support the '--html-title' option * Ensure we use gcover options that are identical on older ubuntu * Improve coverage generation and required build packages
3 years ago
endif(DEFINED UNIX)