From edaebf3b46194d24f168ab97504c42dd9ca05065 Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Tue, 13 Jun 2023 19:59:59 +0100 Subject: [PATCH 01/47] Ensure that data from failed tests is not overwritten by other jobs --- .github/workflows/tests.yml | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 9c6cebb..3da0500 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -25,6 +25,13 @@ jobs: ./configure make test + - if: ${{ failure() }} + name: Upload tests output + uses: actions/upload-artifact@v3 + with: + name: tests-smoketest + path: tests + smoketest_all_opts: name: Smoke test With all options turned on runs-on: ubuntu-latest @@ -174,7 +181,7 @@ jobs: name: Upload tests output uses: actions/upload-artifact@v3 with: - name: tests-out + name: tests-linux path: tests - name: Generate coverage reports @@ -244,7 +251,7 @@ jobs: name: Upload tests output uses: actions/upload-artifact@v3 with: - name: tests-out + name: tests-macos path: tests - name: Generate coverage reports @@ -321,7 +328,7 @@ jobs: name: Upload tests output uses: actions/upload-artifact@v3 with: - name: tests-out + name: tests-windows path: tests - name: Generate coverage data From ae3d54eed6068fe9d36b14f5e5182509b8d85099 Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Tue, 13 Jun 2023 21:24:30 +0100 Subject: [PATCH 02/47] iwym: auth.h --- include/auth.h | 8 +++++--- include/n2n.h | 1 - src/auth.c | 5 +++++ src/edge.c | 1 + src/edge_utils.c | 1 + src/sn_utils.c | 1 + tools/n2n-keygen.c | 1 + tools/tests-auth.c | 1 + 8 files changed, 15 insertions(+), 4 deletions(-) diff --git a/include/auth.h b/include/auth.h index 0376d3f..d4d65d4 100644 --- a/include/auth.h +++ b/include/auth.h @@ -17,13 +17,15 @@ */ -#include "n2n.h" - - #ifndef AUTH_H #define AUTH_H +#include // for size_t +#include // for uint8_t, uint32_t +#include "n2n.h" // for n2n_private_public_key_t, n2n_community_t, N2N_A... + + int bin_to_ascii (char *out, uint8_t *in, size_t in_len); int ascii_to_bin (uint8_t *out, char *in); diff --git a/include/n2n.h b/include/n2n.h index c798722..0d0f860 100644 --- a/include/n2n.h +++ b/include/n2n.h @@ -149,7 +149,6 @@ #include "n2n_regex.h" #include "sn_selection.h" #include "network_traffic_filter.h" -#include "auth.h" #include "n2n_port_mapping.h" diff --git a/src/auth.c b/src/auth.c index c4422a2..b2d76cf 100644 --- a/src/auth.c +++ b/src/auth.c @@ -18,6 +18,11 @@ #include "auth.h" +#include // for calloc, free +#include // for strlen, size_t +#include "curve25519.h" // for curve25519 +#include "pearson.h" // for pearson_hash_128, pearson_hash_256 +#include "speck.h" // for speck_context_t, speck_128_encrypt, speck_init // mapping six binary bits to printable ascii character diff --git a/src/edge.c b/src/edge.c index 33040a3..c626004 100644 --- a/src/edge.c +++ b/src/edge.c @@ -16,6 +16,7 @@ * */ +#include "auth.h" // for generate_private_key, generate_p... #include "n2n.h" /* *************************************************** */ diff --git a/src/edge_utils.c b/src/edge_utils.c index 378376d..81b5e3a 100644 --- a/src/edge_utils.c +++ b/src/edge_utils.c @@ -16,6 +16,7 @@ * */ +#include "auth.h" // for generate_private_key #include "n2n.h" #include "network_traffic_filter.h" #include "edge_utils_win32.h" diff --git a/src/sn_utils.c b/src/sn_utils.c index 16b9d64..ed90b9e 100644 --- a/src/sn_utils.c +++ b/src/sn_utils.c @@ -16,6 +16,7 @@ * */ +#include "auth.h" // for ascii_to_bin, calculate_dynamic_key #include "n2n.h" #define HASH_FIND_COMMUNITY(head, name, out) HASH_FIND_STR(head, name, out) diff --git a/tools/n2n-keygen.c b/tools/n2n-keygen.c index 3ce25f9..a734464 100644 --- a/tools/n2n-keygen.c +++ b/tools/n2n-keygen.c @@ -17,6 +17,7 @@ */ +#include "auth.h" // for bin_to_ascii, bind_private_key_to_username, gene... #include "n2n.h" diff --git a/tools/tests-auth.c b/tools/tests-auth.c index 232df6e..05f0b46 100644 --- a/tools/tests-auth.c +++ b/tools/tests-auth.c @@ -18,6 +18,7 @@ #include +#include "auth.h" // for ascii_to_bin, bin_to_ascii, generate_private_key #include "n2n.h" #include "hexdump.h" From 20df771af78753cf591957909bc4805847aee482 Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Tue, 13 Jun 2023 21:36:07 +0100 Subject: [PATCH 03/47] iwym: cc20.h --- include/cc20.h | 8 +++----- include/n2n.h | 1 - src/cc20.c | 8 ++++++++ src/transform_cc20.c | 1 + 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/include/cc20.h b/include/cc20.h index 3a5b553..51f4425 100644 --- a/include/cc20.h +++ b/include/cc20.h @@ -21,9 +21,9 @@ #define CC20_H -#include - -#include "n2n.h" // HAVE_OPENSSL_1_1, traceEvent ... +#include // for size_t +#include // for uint32_t, uint8_t +#include "config.h" // HAVE_OPENSSL_1_1 #define CC20_IV_SIZE 16 @@ -46,8 +46,6 @@ typedef struct cc20_context_t { #elif defined (__SSE2__) // SSE2 --------------------------------------------------------------------------------- -#include - typedef struct cc20_context { uint32_t keystream32[16]; uint8_t key[CC20_KEY_BYTES]; diff --git a/include/n2n.h b/include/n2n.h index 0d0f860..61b8db0 100644 --- a/include/n2n.h +++ b/include/n2n.h @@ -143,7 +143,6 @@ #include "pearson.h" #include "portable_endian.h" #include "aes.h" -#include "cc20.h" #include "speck.h" #include "curve25519.h" #include "n2n_regex.h" diff --git a/src/cc20.c b/src/cc20.c index 73fab8c..6a4ae1f 100644 --- a/src/cc20.c +++ b/src/cc20.c @@ -17,7 +17,11 @@ */ +#include // for calloc, free, size_t +#include // for memcpy #include "cc20.h" +#include "config.h" // HAVE_OPENSSL_1_1 +#include "portable_endian.h" // for htole32 #if defined (HAVE_OPENSSL_1_1) // openSSL 1.1 --------------------------------------------------------------------- @@ -84,6 +88,10 @@ int cc20_crypt (unsigned char *out, const unsigned char *in, size_t in_len, // https://github.com/Ginurx/chacha20-c (public domain) +#include // for _mm_xor_si128, _mm_add_epi32, _mm_slli_epi32 +#include // for _MM_SHUFFLE + + #define SL _mm_slli_epi32 #define SR _mm_srli_epi32 #define XOR _mm_xor_si128 diff --git a/src/transform_cc20.c b/src/transform_cc20.c index fe6eb8b..05061a6 100644 --- a/src/transform_cc20.c +++ b/src/transform_cc20.c @@ -17,6 +17,7 @@ */ +#include "cc20.h" // for CC20_IV_SIZE, cc20_crypt, cc20_deinit #include "n2n.h" From 4838dd8d755a16e2d1f30126d40787036b15b5da Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Tue, 13 Jun 2023 22:38:47 +0100 Subject: [PATCH 04/47] iwym: header_encryption.h --- include/header_encryption.h | 1 + include/n2n.h | 1 - src/edge_utils.c | 1 + src/header_encryption.c | 1 + src/sn_utils.c | 1 + src/supernode.c | 1 - 6 files changed, 4 insertions(+), 2 deletions(-) diff --git a/include/header_encryption.h b/include/header_encryption.h index a5e3f89..6e10254 100644 --- a/include/header_encryption.h +++ b/include/header_encryption.h @@ -16,6 +16,7 @@ * */ +#include "n2n_typedefs.h" int packet_header_decrypt (uint8_t packet[], uint16_t packet_len, char *community_name, diff --git a/include/n2n.h b/include/n2n.h index 61b8db0..8c52927 100644 --- a/include/n2n.h +++ b/include/n2n.h @@ -155,7 +155,6 @@ /* ************************************** */ -#include "header_encryption.h" #include "tf.h" #ifndef TRACE_ERROR diff --git a/src/edge_utils.c b/src/edge_utils.c index 81b5e3a..a5acc73 100644 --- a/src/edge_utils.c +++ b/src/edge_utils.c @@ -17,6 +17,7 @@ */ #include "auth.h" // for generate_private_key +#include "header_encryption.h" // for packet_header_encrypt, packet_he... #include "n2n.h" #include "network_traffic_filter.h" #include "edge_utils_win32.h" diff --git a/src/header_encryption.c b/src/header_encryption.c index 5511557..3567bbe 100644 --- a/src/header_encryption.c +++ b/src/header_encryption.c @@ -17,6 +17,7 @@ */ +#include "header_encryption.h" // for packet_header_change_dynamic_key, pac... #include "n2n.h" diff --git a/src/sn_utils.c b/src/sn_utils.c index ed90b9e..13e2ffb 100644 --- a/src/sn_utils.c +++ b/src/sn_utils.c @@ -17,6 +17,7 @@ */ #include "auth.h" // for ascii_to_bin, calculate_dynamic_key +#include "header_encryption.h" // for packet_header_encrypt, packet_header_... #include "n2n.h" #define HASH_FIND_COMMUNITY(head, name, out) HASH_FIND_STR(head, name, out) diff --git a/src/supernode.c b/src/supernode.c index b178d81..4454fbd 100644 --- a/src/supernode.c +++ b/src/supernode.c @@ -19,7 +19,6 @@ /* Supernode for n2n-2.x */ #include "n2n.h" -#include "header_encryption.h" #define HASH_FIND_COMMUNITY(head, name, out) HASH_FIND_STR(head, name, out) From 04ce678969ab4e9e86f945f2c3f9920eac9faf8d Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Wed, 14 Jun 2023 19:52:10 +0100 Subject: [PATCH 05/47] iwym: json.h --- include/json.h | 6 ------ include/n2n.h | 2 -- src/json.c | 2 ++ tools/n2n-portfwd.c | 3 ++- tools/n2n-route.c | 3 ++- 5 files changed, 6 insertions(+), 10 deletions(-) diff --git a/include/json.h b/include/json.h index aabdbb1..585a7bf 100644 --- a/include/json.h +++ b/include/json.h @@ -27,17 +27,11 @@ #define JSON_H -#include -#include - #define json_str_is_whitespace(x) x == '\r' || x == '\n' || x == '\t' || x == ' ' #define json_str_is_numeral(x) (x >= '0' && x <= '9') || x == 'e' || x == 'E' \ || x == '.' || x == '+' || x == '-' #define json_str_remove_whitespace_calc_offset(x, y) while(json_str_is_whitespace(*x)) { x++; y++; } -struct _jsonobject; -struct _jsonpair; -union _jsonvalue; typedef enum { JSON_STRING = 0, diff --git a/include/n2n.h b/include/n2n.h index 8c52927..bab521a 100644 --- a/include/n2n.h +++ b/include/n2n.h @@ -151,8 +151,6 @@ #include "n2n_port_mapping.h" -#include "json.h" - /* ************************************** */ #include "tf.h" diff --git a/src/json.c b/src/json.c index d048b36..1aaab41 100644 --- a/src/json.c +++ b/src/json.c @@ -23,6 +23,8 @@ // https://github.com/forkachild/C-Simple-JSON-Parser/issues/3#issuecomment-1073520808 +#include // for malloc, free, NULL, atof, realloc +#include // for memcpy #include "json.h" diff --git a/tools/n2n-portfwd.c b/tools/n2n-portfwd.c index b06e6e4..6bfba95 100644 --- a/tools/n2n-portfwd.c +++ b/tools/n2n-portfwd.c @@ -17,7 +17,8 @@ */ -#include "n2n.h" +#include "json.h" // for _jsonpair, json_object_t, json_free +#include "n2n.h" // for traceEvent, setTraceLevel, getTraceLevel #define WITH_PORT 1 diff --git a/tools/n2n-route.c b/tools/n2n-route.c index 4740f9a..3cd0880 100644 --- a/tools/n2n-route.c +++ b/tools/n2n-route.c @@ -17,7 +17,8 @@ */ -#include "n2n.h" +#include "json.h" // for _jsonpair, json_object_t, _jsonvalue +#include "n2n.h" // for inaddrtoa, traceEvent, TRACE_WARNING #if defined (__linux__) || defined(WIN32) /* currently, Linux and Windows only */ From 15ad901b41763588e880022a3a0630169769c2fa Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Wed, 14 Jun 2023 20:02:54 +0100 Subject: [PATCH 06/47] iwym: pearson.h --- include/pearson.h | 6 ++---- src/edge.c | 1 + src/edge_utils.c | 3 ++- src/header_encryption.c | 3 ++- src/management.c | 5 +++-- src/pearson.c | 1 + src/sn_utils.c | 5 ++++- src/supernode.c | 5 ++++- src/transform_aes.c | 3 ++- src/transform_cc20.c | 3 ++- src/transform_speck.c | 4 ++-- src/transform_tf.c | 3 ++- tools/n2n-benchmark.c | 3 ++- tools/tests-hashing.c | 3 ++- 14 files changed, 31 insertions(+), 17 deletions(-) diff --git a/include/pearson.h b/include/pearson.h index 908f24f..9ceae47 100644 --- a/include/pearson.h +++ b/include/pearson.h @@ -17,10 +17,8 @@ */ -#include -#include - -#include "portable_endian.h" +#include // for size_t +#include // for uint8_t, uint16_t, uint32_t, uint64_t void pearson_hash_256 (uint8_t *out, const uint8_t *in, size_t len); diff --git a/src/edge.c b/src/edge.c index c626004..a7c2846 100644 --- a/src/edge.c +++ b/src/edge.c @@ -18,6 +18,7 @@ #include "auth.h" // for generate_private_key, generate_p... #include "n2n.h" +#include "pearson.h" // for pearson_hash_64 /* *************************************************** */ diff --git a/src/edge_utils.c b/src/edge_utils.c index a5acc73..6091969 100644 --- a/src/edge_utils.c +++ b/src/edge_utils.c @@ -18,7 +18,8 @@ #include "auth.h" // for generate_private_key #include "header_encryption.h" // for packet_header_encrypt, packet_he... -#include "n2n.h" +#include "n2n.h" // for n2n_edge_t, peer_info, n2n_edge_... +#include "pearson.h" // for pearson_hash_128, pearson_hash_64 #include "network_traffic_filter.h" #include "edge_utils_win32.h" diff --git a/src/header_encryption.c b/src/header_encryption.c index 3567bbe..981d7ea 100644 --- a/src/header_encryption.c +++ b/src/header_encryption.c @@ -18,7 +18,8 @@ #include "header_encryption.h" // for packet_header_change_dynamic_key, pac... -#include "n2n.h" +#include "n2n.h" // for he_context_t, N2N_COMMUNITY_SIZE, TRA... +#include "pearson.h" // for pearson_hash_128, pearson_hash_64 #define HASH_FIND_COMMUNITY(head, name, out) HASH_FIND_STR(head, name, out) diff --git a/src/management.c b/src/management.c index 5a27dcf..a207e00 100644 --- a/src/management.c +++ b/src/management.c @@ -9,6 +9,9 @@ #include #endif +#include // for pearson_hash_64 +#include "n2n.h" // for TRACE_DEBUG, traceEvent + // TODO: move logging defs in their own header and include that void setTraceLevel (int level); int getTraceLevel (); @@ -16,8 +19,6 @@ int getTraceLevel (); #include #include "management.h" -#include "n2n.h" // for traceEvent and friends - ssize_t send_reply (mgmt_req_t *req, strbuf_t *buf, size_t msg_len) { // TODO: better error handling (counters?) return sendto(req->mgmt_sock, buf->str, msg_len, 0, diff --git a/src/pearson.c b/src/pearson.c index 4852b43..bf0273a 100644 --- a/src/pearson.c +++ b/src/pearson.c @@ -22,6 +22,7 @@ #include "pearson.h" +#include "portable_endian.h" // for le64toh, htobe64 // Christopher Wellons' triple32 from https://github.com/skeeto/hash-prospector diff --git a/src/sn_utils.c b/src/sn_utils.c index 13e2ffb..26ffe06 100644 --- a/src/sn_utils.c +++ b/src/sn_utils.c @@ -16,9 +16,12 @@ * */ + #include "auth.h" // for ascii_to_bin, calculate_dynamic_key #include "header_encryption.h" // for packet_header_encrypt, packet_header_... -#include "n2n.h" +#include "n2n.h" // for sn_community, n2n_sn_t, peer_info +#include "pearson.h" // for pearson_hash_128, pearson_hash_32 + #define HASH_FIND_COMMUNITY(head, name, out) HASH_FIND_STR(head, name, out) diff --git a/src/supernode.c b/src/supernode.c index 4454fbd..8d7b7f9 100644 --- a/src/supernode.c +++ b/src/supernode.c @@ -18,7 +18,10 @@ /* Supernode for n2n-2.x */ -#include "n2n.h" + +#include "n2n.h" // for n2n_sn_t, sn_community, traceEvent +#include "pearson.h" // for pearson_hash_64 + #define HASH_FIND_COMMUNITY(head, name, out) HASH_FIND_STR(head, name, out) diff --git a/src/transform_aes.c b/src/transform_aes.c index 3a285c7..d60a78a 100644 --- a/src/transform_aes.c +++ b/src/transform_aes.c @@ -17,7 +17,8 @@ */ -#include "n2n.h" +#include "n2n.h" // for n2n_trans_op_t, traceEvent, TRACE_ERROR +#include "pearson.h" // for pearson_hash_256 // size of random value prepended to plaintext defaults to AES BLOCK_SIZE; diff --git a/src/transform_cc20.c b/src/transform_cc20.c index 05061a6..fdf3c6d 100644 --- a/src/transform_cc20.c +++ b/src/transform_cc20.c @@ -18,7 +18,8 @@ #include "cc20.h" // for CC20_IV_SIZE, cc20_crypt, cc20_deinit -#include "n2n.h" +#include "n2n.h" // for n2n_trans_op_t, traceEvent, TRACE_ERROR +#include "pearson.h" // for pearson_hash_256 // ChaCha20 plaintext preamble diff --git a/src/transform_speck.c b/src/transform_speck.c index a633844..872c356 100644 --- a/src/transform_speck.c +++ b/src/transform_speck.c @@ -17,8 +17,8 @@ */ -#include "n2n.h" - +#include "n2n.h" // for n2n_trans_op_t, traceEvent, TRACE_DEBUG +#include "pearson.h" // for pearson_hash_256 // Speck plaintext preamble #define TRANSOP_SPECK_PREAMBLE_SIZE (N2N_SPECK_IVEC_SIZE) diff --git a/src/transform_tf.c b/src/transform_tf.c index 2900639..be0adc7 100644 --- a/src/transform_tf.c +++ b/src/transform_tf.c @@ -17,7 +17,8 @@ */ -#include "n2n.h" +#include "n2n.h" // for n2n_trans_op_t, traceEvent, TRACE_ERROR +#include "pearson.h" // for pearson_hash_256 // size of random value prepended to plaintext defaults to TF_BLOCK_SIZE; diff --git a/tools/n2n-benchmark.c b/tools/n2n-benchmark.c index b4a3c95..510ddf5 100644 --- a/tools/n2n-benchmark.c +++ b/tools/n2n-benchmark.c @@ -22,7 +22,8 @@ #include #endif -#include "n2n.h" +#include "n2n.h" // for n2n_trans_op_t, n2n_common_t, n2n_edge_conf_t +#include "pearson.h" // for pearson_hash_64, pearson_hash_init #define DURATION 2.5 // test duration per algorithm #define PACKETS_BEFORE_GETTIME 2047 // do not check time after every packet but after (2 ^ n - 1) diff --git a/tools/tests-hashing.c b/tools/tests-hashing.c index dbbbbb8..6e40fe7 100644 --- a/tools/tests-hashing.c +++ b/tools/tests-hashing.c @@ -19,7 +19,8 @@ #include #include "n2n.h" -#include "hexdump.h" +#include "hexdump.h" // for fhexdump +#include "pearson.h" // for pearson_hash_128, pearson_hash_16, pearson_has... uint8_t PKT_CONTENT[]={ From f67cc8f2a6fe39140b6be6e10da2b9b0037477d3 Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Wed, 14 Jun 2023 20:14:11 +0100 Subject: [PATCH 07/47] iwyu: random_numbers.h --- include/random_numbers.h | 9 ++------- src/edge.c | 2 ++ src/edge_utils.c | 5 +++-- src/example_edge_embed_quick_edge_init.c | 5 ++++- src/header_encryption.c | 1 + src/n2n.c | 3 ++- src/random_numbers.c | 5 +++++ src/sn_utils.c | 1 + src/transform_aes.c | 1 + src/transform_cc20.c | 1 + src/transform_speck.c | 1 + src/transform_tf.c | 1 + tools/n2n-portfwd.c | 1 + tools/n2n-route.c | 1 + 14 files changed, 26 insertions(+), 11 deletions(-) diff --git a/include/random_numbers.h b/include/random_numbers.h index b998bcf..2c7eba4 100644 --- a/include/random_numbers.h +++ b/include/random_numbers.h @@ -21,21 +21,16 @@ #define RND_H -#include -#include -#include /* time, clock */ - -#include "n2n.h" /* traceEvent */ +#include // for uint64_t, uint32_t // syscall and inquiring random number from hardware generators might fail, so we will retry #define RND_RETRIES 1000 #if defined (__linux__) -#include /* syscall, SYS_getrandom */ +#include // for SYS_getrandom #ifdef SYS_getrandom #define GRND_NONBLOCK 1 -#include /* errno, EAGAIN */ #endif #endif diff --git a/src/edge.c b/src/edge.c index a7c2846..a898b63 100644 --- a/src/edge.c +++ b/src/edge.c @@ -19,6 +19,8 @@ #include "auth.h" // for generate_private_key, generate_p... #include "n2n.h" #include "pearson.h" // for pearson_hash_64 +#include "random_numbers.h" // for n2n_seed, n2n_srand + /* *************************************************** */ diff --git a/src/edge_utils.c b/src/edge_utils.c index 6091969..dba863a 100644 --- a/src/edge_utils.c +++ b/src/edge_utils.c @@ -17,11 +17,12 @@ */ #include "auth.h" // for generate_private_key +#include "edge_utils_win32.h" #include "header_encryption.h" // for packet_header_encrypt, packet_he... #include "n2n.h" // for n2n_edge_t, peer_info, n2n_edge_... +#include "network_traffic_filter.h" // for create_network_traffic_filter #include "pearson.h" // for pearson_hash_128, pearson_hash_64 -#include "network_traffic_filter.h" -#include "edge_utils_win32.h" +#include "random_numbers.h" // for n2n_rand, n2n_rand_sqr /* ************************************** */ diff --git a/src/example_edge_embed_quick_edge_init.c b/src/example_edge_embed_quick_edge_init.c index e96a765..72a8ae6 100644 --- a/src/example_edge_embed_quick_edge_init.c +++ b/src/example_edge_embed_quick_edge_init.c @@ -16,7 +16,10 @@ * */ -#include "n2n.h" + +#include "n2n.h" // for quick_edge_init, setTraceLevel +#include "random_numbers.h" // for n2n_seed, n2n_srand + /* This tool demonstrates how to easily embed diff --git a/src/header_encryption.c b/src/header_encryption.c index 981d7ea..9ee2ee9 100644 --- a/src/header_encryption.c +++ b/src/header_encryption.c @@ -20,6 +20,7 @@ #include "header_encryption.h" // for packet_header_change_dynamic_key, pac... #include "n2n.h" // for he_context_t, N2N_COMMUNITY_SIZE, TRA... #include "pearson.h" // for pearson_hash_128, pearson_hash_64 +#include "random_numbers.h" // for n2n_rand #define HASH_FIND_COMMUNITY(head, name, out) HASH_FIND_STR(head, name, out) diff --git a/src/n2n.c b/src/n2n.c index c6a7ace..3f75c94 100644 --- a/src/n2n.c +++ b/src/n2n.c @@ -18,7 +18,8 @@ #include "n2n.h" -#include "sn_selection.h" +#include "random_numbers.h" // for n2n_rand +#include "sn_selection.h" // for sn_selection_criterion_default #include "minilzo.h" diff --git a/src/random_numbers.c b/src/random_numbers.c index 0828f22..ed6ca8c 100644 --- a/src/random_numbers.c +++ b/src/random_numbers.c @@ -17,6 +17,11 @@ */ +#include // for errno, EAGAIN +#include // for NULL, size_t +#include // for clock, time +#include // for syscall +#include "n2n.h" // for TRACE_ERROR, traceEvent #include "random_numbers.h" diff --git a/src/sn_utils.c b/src/sn_utils.c index 26ffe06..56e8a89 100644 --- a/src/sn_utils.c +++ b/src/sn_utils.c @@ -21,6 +21,7 @@ #include "header_encryption.h" // for packet_header_encrypt, packet_header_... #include "n2n.h" // for sn_community, n2n_sn_t, peer_info #include "pearson.h" // for pearson_hash_128, pearson_hash_32 +#include "random_numbers.h" // for n2n_rand, n2n_rand_sqr, n2n_seed, n2n... #define HASH_FIND_COMMUNITY(head, name, out) HASH_FIND_STR(head, name, out) diff --git a/src/transform_aes.c b/src/transform_aes.c index d60a78a..ca6eb4f 100644 --- a/src/transform_aes.c +++ b/src/transform_aes.c @@ -19,6 +19,7 @@ #include "n2n.h" // for n2n_trans_op_t, traceEvent, TRACE_ERROR #include "pearson.h" // for pearson_hash_256 +#include "random_numbers.h" // for n2n_rand // size of random value prepended to plaintext defaults to AES BLOCK_SIZE; diff --git a/src/transform_cc20.c b/src/transform_cc20.c index fdf3c6d..6bbecac 100644 --- a/src/transform_cc20.c +++ b/src/transform_cc20.c @@ -20,6 +20,7 @@ #include "cc20.h" // for CC20_IV_SIZE, cc20_crypt, cc20_deinit #include "n2n.h" // for n2n_trans_op_t, traceEvent, TRACE_ERROR #include "pearson.h" // for pearson_hash_256 +#include "random_numbers.h" // for n2n_rand // ChaCha20 plaintext preamble diff --git a/src/transform_speck.c b/src/transform_speck.c index 872c356..1f9661d 100644 --- a/src/transform_speck.c +++ b/src/transform_speck.c @@ -19,6 +19,7 @@ #include "n2n.h" // for n2n_trans_op_t, traceEvent, TRACE_DEBUG #include "pearson.h" // for pearson_hash_256 +#include "random_numbers.h" // for n2n_rand // Speck plaintext preamble #define TRANSOP_SPECK_PREAMBLE_SIZE (N2N_SPECK_IVEC_SIZE) diff --git a/src/transform_tf.c b/src/transform_tf.c index be0adc7..e6ae404 100644 --- a/src/transform_tf.c +++ b/src/transform_tf.c @@ -19,6 +19,7 @@ #include "n2n.h" // for n2n_trans_op_t, traceEvent, TRACE_ERROR #include "pearson.h" // for pearson_hash_256 +#include "random_numbers.h" // for n2n_rand // size of random value prepended to plaintext defaults to TF_BLOCK_SIZE; diff --git a/tools/n2n-portfwd.c b/tools/n2n-portfwd.c index 6bfba95..5d7f698 100644 --- a/tools/n2n-portfwd.c +++ b/tools/n2n-portfwd.c @@ -19,6 +19,7 @@ #include "json.h" // for _jsonpair, json_object_t, json_free #include "n2n.h" // for traceEvent, setTraceLevel, getTraceLevel +#include "random_numbers.h" // for n2n_rand, n2n_seed, n2n_srand #define WITH_PORT 1 diff --git a/tools/n2n-route.c b/tools/n2n-route.c index 3cd0880..18cd7fc 100644 --- a/tools/n2n-route.c +++ b/tools/n2n-route.c @@ -19,6 +19,7 @@ #include "json.h" // for _jsonpair, json_object_t, _jsonvalue #include "n2n.h" // for inaddrtoa, traceEvent, TRACE_WARNING +#include "random_numbers.h" // for n2n_rand, n2n_seed, n2n_srand #if defined (__linux__) || defined(WIN32) /* currently, Linux and Windows only */ From 3ad14dc6a7053731d6d41fdc3652d0417f7ad837 Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Wed, 14 Jun 2023 20:26:21 +0100 Subject: [PATCH 08/47] iwyu: missed deletions --- include/n2n.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/include/n2n.h b/include/n2n.h index bab521a..cf8ebc6 100644 --- a/include/n2n.h +++ b/include/n2n.h @@ -139,8 +139,6 @@ #endif /* #ifdef WIN32 */ #include "n2n_wire.h" -#include "random_numbers.h" -#include "pearson.h" #include "portable_endian.h" #include "aes.h" #include "speck.h" From 4e0bec79b7f83f08fcc027e1fd24c702a58dc324 Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Wed, 14 Jun 2023 20:30:43 +0100 Subject: [PATCH 09/47] iwyu: speck.h --- include/n2n.h | 1 - include/speck.h | 5 +---- src/edge.c | 1 + src/edge_utils.c | 1 + src/header_encryption.c | 1 + src/sn_utils.c | 1 + src/speck.c | 3 +++ src/transform_speck.c | 2 ++ 8 files changed, 10 insertions(+), 5 deletions(-) diff --git a/include/n2n.h b/include/n2n.h index cf8ebc6..9da119d 100644 --- a/include/n2n.h +++ b/include/n2n.h @@ -141,7 +141,6 @@ #include "n2n_wire.h" #include "portable_endian.h" #include "aes.h" -#include "speck.h" #include "curve25519.h" #include "n2n_regex.h" #include "sn_selection.h" diff --git a/include/speck.h b/include/speck.h index 686818b..9f9cb18 100644 --- a/include/speck.h +++ b/include/speck.h @@ -26,10 +26,7 @@ #define SPECK_H -#include -#include - -#include "portable_endian.h" +#include // for uint64_t, uint32_t #define u32 uint32_t diff --git a/src/edge.c b/src/edge.c index a898b63..cd671f0 100644 --- a/src/edge.c +++ b/src/edge.c @@ -20,6 +20,7 @@ #include "n2n.h" #include "pearson.h" // for pearson_hash_64 #include "random_numbers.h" // for n2n_seed, n2n_srand +#include "speck.h" // for speck_init, speck_context_t /* *************************************************** */ diff --git a/src/edge_utils.c b/src/edge_utils.c index dba863a..7bff220 100644 --- a/src/edge_utils.c +++ b/src/edge_utils.c @@ -23,6 +23,7 @@ #include "network_traffic_filter.h" // for create_network_traffic_filter #include "pearson.h" // for pearson_hash_128, pearson_hash_64 #include "random_numbers.h" // for n2n_rand, n2n_rand_sqr +#include "speck.h" // for speck_128_decrypt, speck_128_enc... /* ************************************** */ diff --git a/src/header_encryption.c b/src/header_encryption.c index 9ee2ee9..d2d0b56 100644 --- a/src/header_encryption.c +++ b/src/header_encryption.c @@ -21,6 +21,7 @@ #include "n2n.h" // for he_context_t, N2N_COMMUNITY_SIZE, TRA... #include "pearson.h" // for pearson_hash_128, pearson_hash_64 #include "random_numbers.h" // for n2n_rand +#include "speck.h" // for speck_init, speck_context_t, speck_ctr #define HASH_FIND_COMMUNITY(head, name, out) HASH_FIND_STR(head, name, out) diff --git a/src/sn_utils.c b/src/sn_utils.c index 56e8a89..442e954 100644 --- a/src/sn_utils.c +++ b/src/sn_utils.c @@ -22,6 +22,7 @@ #include "n2n.h" // for sn_community, n2n_sn_t, peer_info #include "pearson.h" // for pearson_hash_128, pearson_hash_32 #include "random_numbers.h" // for n2n_rand, n2n_rand_sqr, n2n_seed, n2n... +#include "speck.h" // for speck_128_encrypt, speck_context_t #define HASH_FIND_COMMUNITY(head, name, out) HASH_FIND_STR(head, name, out) diff --git a/src/speck.c b/src/speck.c index 4c43003..948f7c8 100644 --- a/src/speck.c +++ b/src/speck.c @@ -23,6 +23,9 @@ #include "speck.h" +#include // for htole64, le64toh +#include // for _mm_free, _mm_malloc +#include // for size_t #if defined (__AVX512F__) // AVX512 support ---------------------------------------------------------------------- diff --git a/src/transform_speck.c b/src/transform_speck.c index 1f9661d..9b18591 100644 --- a/src/transform_speck.c +++ b/src/transform_speck.c @@ -20,6 +20,8 @@ #include "n2n.h" // for n2n_trans_op_t, traceEvent, TRACE_DEBUG #include "pearson.h" // for pearson_hash_256 #include "random_numbers.h" // for n2n_rand +#include "speck.h" // for N2N_SPECK_IVEC_SIZE, speck_ctr, speck_de... + // Speck plaintext preamble #define TRANSOP_SPECK_PREAMBLE_SIZE (N2N_SPECK_IVEC_SIZE) From 91357d3cbfc470ad78c28c29646409469ebff6a0 Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Wed, 14 Jun 2023 20:42:02 +0100 Subject: [PATCH 10/47] Fixup for speck.c --- src/speck.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/speck.c b/src/speck.c index 948f7c8..1a2574a 100644 --- a/src/speck.c +++ b/src/speck.c @@ -23,10 +23,12 @@ #include "speck.h" -#include // for htole64, le64toh -#include // for _mm_free, _mm_malloc -#include // for size_t +#include "portable_endian.h" // for htole64, le64toh +#include // for size_t, malloc, free +#if defined (SPECK_ALIGNED_CTX) +#include // for _mm_free, _mm_malloc +#endif #if defined (__AVX512F__) // AVX512 support ---------------------------------------------------------------------- From 8e1d63fa51f9352ee0753817803076dd2a5e70d5 Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Wed, 14 Jun 2023 20:59:09 +0100 Subject: [PATCH 11/47] iwyu: tf.h --- include/n2n.h | 2 -- include/tf.h | 7 ++----- src/tf.c | 2 ++ src/transform_tf.c | 1 + 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/include/n2n.h b/include/n2n.h index 9da119d..21b5ea2 100644 --- a/include/n2n.h +++ b/include/n2n.h @@ -150,8 +150,6 @@ /* ************************************** */ -#include "tf.h" - #ifndef TRACE_ERROR #define TRACE_ERROR 0 #define TRACE_WARNING 1 diff --git a/include/tf.h b/include/tf.h index 5f13f76..d2d0a65 100644 --- a/include/tf.h +++ b/include/tf.h @@ -51,11 +51,8 @@ #define TF_H -#include -#include -#include - -#include "portable_endian.h" +#include // for uint32_t +#include // for size_t #define TF_BLOCK_SIZE 16 diff --git a/src/tf.c b/src/tf.c index 793c527..288ea84 100644 --- a/src/tf.c +++ b/src/tf.c @@ -48,6 +48,8 @@ #include "tf.h" +#include // for le32toh, htole32 +#include // for memcpy const uint8_t RS[4][8] = { { 0x01, 0xA4, 0x55, 0x87, 0x5A, 0x58, 0xDB, 0x9E, }, diff --git a/src/transform_tf.c b/src/transform_tf.c index e6ae404..f92ff92 100644 --- a/src/transform_tf.c +++ b/src/transform_tf.c @@ -20,6 +20,7 @@ #include "n2n.h" // for n2n_trans_op_t, traceEvent, TRACE_ERROR #include "pearson.h" // for pearson_hash_256 #include "random_numbers.h" // for n2n_rand +#include "tf.h" // for TF_BLOCK_SIZE, tf_cbc_decrypt, tf_cbc_en... // size of random value prepended to plaintext defaults to TF_BLOCK_SIZE; From ce9e3d0e54b8791f33eaf55e7e0d007ee9171899 Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Wed, 14 Jun 2023 21:06:40 +0100 Subject: [PATCH 12/47] Fix tf.h --- src/tf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tf.c b/src/tf.c index 288ea84..f27e903 100644 --- a/src/tf.c +++ b/src/tf.c @@ -48,7 +48,7 @@ #include "tf.h" -#include // for le32toh, htole32 +#include "portable_endian.h" // for le32toh, htole32 #include // for memcpy From 14780a72d3b2c7cc4276ced45828790453dc8634 Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Wed, 14 Jun 2023 21:22:25 +0100 Subject: [PATCH 13/47] iwyu: aes.c --- include/aes.h | 3 --- src/aes.c | 7 ++++++- src/transform_aes.c | 1 + 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/include/aes.h b/include/aes.h index b22f0f8..4604a16 100644 --- a/include/aes.h +++ b/include/aes.h @@ -17,9 +17,6 @@ */ -#include "n2n.h" // HAVE_OPENSSL_1_1, traceEvent ... - - #ifndef AES_H #define AES_H diff --git a/src/aes.c b/src/aes.c index 35375bd..3fbea53 100644 --- a/src/aes.c +++ b/src/aes.c @@ -17,7 +17,12 @@ */ -#include "n2n.h" +#include // for be32toh, htobe32 +#include // for uint32_t, uint8_t +#include // for calloc, free +#include // for memcpy, size_t +#include "aes.h" // for AES_BLOCK_SIZE, aes_context_t, AES128_KEY_BYTES +#include "n2n.h" // for TRACE_ERROR, traceEvent #if defined (HAVE_OPENSSL_1_1) // openSSL 1.1 --------------------------------------------------------------------- diff --git a/src/transform_aes.c b/src/transform_aes.c index ca6eb4f..6e66ada 100644 --- a/src/transform_aes.c +++ b/src/transform_aes.c @@ -17,6 +17,7 @@ */ +#include "aes.h" // for AES_BLOCK_SIZE, aes_cbc_decrypt, aes_cbc... #include "n2n.h" // for n2n_trans_op_t, traceEvent, TRACE_ERROR #include "pearson.h" // for pearson_hash_256 #include "random_numbers.h" // for n2n_rand From f6cebecd015548faa103cd02393437de82de3f60 Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Wed, 14 Jun 2023 21:25:51 +0100 Subject: [PATCH 14/47] iwyu: edge.c --- src/edge.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/edge.c b/src/edge.c index cd671f0..6ed461f 100644 --- a/src/edge.c +++ b/src/edge.c @@ -16,11 +16,36 @@ * */ + +#include // for inet_addr, inet_ntop +#include // for optind, optarg +#include // for isspace +#include // for htobe32 +#include // for errno +#include // for required_argument, no_argument +#include // for INADDR_ANY, INADDR_NONE, ntohl +#include // for getpwnam, passwd +#include // for signal, SIG_IGN, SIGPIPE, SIGCHLD +#include // for uint8_t, uint16_t +#include // for printf, NULL, fclose, snprintf +#include // for atoi, exit, calloc, free, malloc +#include // for strncpy, memset, strlen, strcmp +#include // for MIN +#include // for select, FD_ISSET, FD_SET, FD_ZERO +#include // for AF_INET +#include // for timeval +#include // for u_char +#include // for time +#include // for setuid, _exit, chdir, fork, getgid #include "auth.h" // for generate_private_key, generate_p... -#include "n2n.h" +#include "config.h" // for PACKAGE_BUILDDATE, PACKAGE_VERSION +#include "n2n.h" // for n2n_edge_conf_t, n2n_edge_t, fil... +#include "network_traffic_filter.h" // for process_traffic_filter_rule_str #include "pearson.h" // for pearson_hash_64 #include "random_numbers.h" // for n2n_seed, n2n_srand +#include "sn_selection.h" // for sn_selection_sort, sn_selection_... #include "speck.h" // for speck_init, speck_context_t +#include "uthash.h" // for UT_hash_handle, HASH_ADD, HASH_C... /* *************************************************** */ @@ -37,7 +62,6 @@ #include #include -#include "network_traffic_filter.h" static cap_value_t cap_values[] = { //CAP_NET_RAW, /* Use RAW and PACKET sockets */ From 991a8bc59f0937e12eec71aef9552ee7054b213c Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Thu, 15 Jun 2023 21:39:54 +0100 Subject: [PATCH 15/47] Fix aes.c --- src/aes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aes.c b/src/aes.c index 3fbea53..2d4ec03 100644 --- a/src/aes.c +++ b/src/aes.c @@ -17,12 +17,12 @@ */ -#include // for be32toh, htobe32 #include // for uint32_t, uint8_t #include // for calloc, free #include // for memcpy, size_t #include "aes.h" // for AES_BLOCK_SIZE, aes_context_t, AES128_KEY_BYTES #include "n2n.h" // for TRACE_ERROR, traceEvent +#include "portable_endian.h" // for be32toh, htobe32 #if defined (HAVE_OPENSSL_1_1) // openSSL 1.1 --------------------------------------------------------------------- From 0fcf18fab2a63fe7ed225abce55e01f2692b3900 Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Thu, 15 Jun 2023 21:45:59 +0100 Subject: [PATCH 16/47] Fix edge.c --- src/edge.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/edge.c b/src/edge.c index 6ed461f..9e6b501 100644 --- a/src/edge.c +++ b/src/edge.c @@ -17,22 +17,15 @@ */ -#include // for inet_addr, inet_ntop -#include // for optind, optarg #include // for isspace -#include // for htobe32 #include // for errno #include // for required_argument, no_argument -#include // for INADDR_ANY, INADDR_NONE, ntohl -#include // for getpwnam, passwd #include // for signal, SIG_IGN, SIGPIPE, SIGCHLD #include // for uint8_t, uint16_t #include // for printf, NULL, fclose, snprintf #include // for atoi, exit, calloc, free, malloc #include // for strncpy, memset, strlen, strcmp #include // for MIN -#include // for select, FD_ISSET, FD_SET, FD_ZERO -#include // for AF_INET #include // for timeval #include // for u_char #include // for time @@ -42,11 +35,22 @@ #include "n2n.h" // for n2n_edge_conf_t, n2n_edge_t, fil... #include "network_traffic_filter.h" // for process_traffic_filter_rule_str #include "pearson.h" // for pearson_hash_64 +#include "portable_endian.h" // for htobe32 #include "random_numbers.h" // for n2n_seed, n2n_srand #include "sn_selection.h" // for sn_selection_sort, sn_selection_... #include "speck.h" // for speck_init, speck_context_t #include "uthash.h" // for UT_hash_handle, HASH_ADD, HASH_C... +#ifdef WIN32 +#include +#include +#else +#include // for inet_addr, inet_ntop +#include // for INADDR_ANY, INADDR_NONE, ntohl +#include // for getpwnam, passwd +#include // for select, FD_ISSET, FD_SET, FD_ZERO +#include // for AF_INET +#endif /* *************************************************** */ From 5b00ff480ee18bdf6b5b4a4930ff2a35bedabb37 Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Thu, 15 Jun 2023 22:18:47 +0100 Subject: [PATCH 17/47] iwyu: edge_management.c --- src/edge_management.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/edge_management.c b/src/edge_management.c index 42b78fa..3741b04 100644 --- a/src/edge_management.c +++ b/src/edge_management.c @@ -16,11 +16,33 @@ * */ -#include "n2n.h" -#include "edge_utils_win32.h" +#include "n2n.h" // for n2n_edge_t, peer_info, getTraceLevel, N2N_... +// FIXME: if this headers is sorted alphabetically, the test_integration_edge +// fails with what looks like a struct rearrangement involving eee->stats -#include "strbuf.h" -#include "management.h" +#include // for errno +#include // for uint32_t +#include // for snprintf, size_t, NULL +#include // for memcmp, memcpy, strerror, strncpy +#include // for ssize_t +#include // for time, time_t +#include "config.h" // for PACKAGE_VERSION +#include "management.h" // for mgmt_req_t, send_reply, send_json_1str +#include "n2n_define.h" // for N2N_PKT_BUF_SIZE, N2N_EVENT_DEBUG, N2N_EVE... +#include "n2n_typedefs.h" // for n2n_edge_t, peer_info, n2n_edge_conf_t +#include "sn_selection.h" // for sn_selection_criterion_str, selection_crit... +#include "strbuf.h" // for strbuf_t, STRBUF_INIT +#include "uthash.h" // for UT_hash_handle, HASH_ITER + +#ifdef WIN32 +#include +#include +#include "edge_utils_win32.h" +#else +#include // for inet_ntoa +#include // for in_addr, htonl, in_addr_t +#include // for sendto, recvfrom, sockaddr_storage +#endif size_t event_debug (strbuf_t *buf, char *tag, int data0, void *data1) { traceEvent(TRACE_DEBUG, "Unexpected call to event_debug"); From c6a9b17338de9e39a192732e96c518d91a482980 Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Thu, 15 Jun 2023 22:28:01 +0100 Subject: [PATCH 18/47] iwyu: edge_utils.c --- src/edge_utils.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/edge_utils.c b/src/edge_utils.c index 7bff220..9474377 100644 --- a/src/edge_utils.c +++ b/src/edge_utils.c @@ -16,14 +16,40 @@ * */ + +#include // for errno, EAFNOSUPPORT, EINPROGRESS +#include // for fcntl, F_SETFL, O_NONBLOCK +#include // for uint8_t, uint16_t, uint32_t, uin... +#include // for snprintf, sprintf +#include // for free, calloc, getenv +#include // for memcpy, memset, NULL, memcmp +#include // for timeval +#include // for time_t, ssize_t, u_int +#include // for time +#include // for gethostname, sleep #include "auth.h" // for generate_private_key -#include "edge_utils_win32.h" +#include "portable_endian.h" // for be16toh, htobe16 #include "header_encryption.h" // for packet_header_encrypt, packet_he... #include "n2n.h" // for n2n_edge_t, peer_info, n2n_edge_... +#include "n2n_wire.h" // for encode_mac, fill_sockaddr, decod... #include "network_traffic_filter.h" // for create_network_traffic_filter #include "pearson.h" // for pearson_hash_128, pearson_hash_64 #include "random_numbers.h" // for n2n_rand, n2n_rand_sqr +#include "sn_selection.h" // for sn_selection_criterion_common_da... #include "speck.h" // for speck_128_decrypt, speck_128_enc... +#include "uthash.h" // for UT_hash_handle, HASH_COUNT, HASH... + +#ifdef WIN32 +#include +#include +#include "edge_utils_win32.h" +#else +#include // for inet_ntoa, inet_addr, inet_ntop +#include // for sockaddr_in, ntohl, IPPROTO_IP +#include // for TCP_NODELAY +#include // for select, FD_SET, FD_ISSET, FD_ZERO +#include // for setsockopt, AF_INET, connect +#endif /* ************************************** */ From 89bd21d6b80608e4ef2739d69ca192328d97918a Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Thu, 15 Jun 2023 22:34:53 +0100 Subject: [PATCH 19/47] iwyu: example_edge_embed.c and example_sn_embed.c --- src/example_edge_embed.c | 6 +++++- src/example_sn_embed.c | 11 ++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/example_edge_embed.c b/src/example_edge_embed.c index 76388b7..b8b8180 100644 --- a/src/example_edge_embed.c +++ b/src/example_edge_embed.c @@ -16,7 +16,11 @@ * */ -#include "n2n.h" + +#include // for snprintf, NULL +#include // for exit +#include "n2n.h" // for n2n_edge_conf_t, edge_conf_add_supernode, edge_init + static int keep_running; diff --git a/src/example_sn_embed.c b/src/example_sn_embed.c index dc1ed18..77dca85 100644 --- a/src/example_sn_embed.c +++ b/src/example_sn_embed.c @@ -16,7 +16,16 @@ * */ -#include "n2n.h" + +#include // for exit +#include "n2n.h" // for n2n_sn_t, open_socket, run_sn_loop, sn_init + +#ifdef WIN32 +#include +#else +#include // for INADDR_ANY, INADDR_LOOPBACK +#endif + static int keep_running; From 9fc5782efd98d089eaec7261ce5730bc8dd68f62 Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Thu, 15 Jun 2023 22:44:34 +0100 Subject: [PATCH 20/47] iwyu: header_encryption.c --- src/header_encryption.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/header_encryption.c b/src/header_encryption.c index d2d0b56..0cf2e02 100644 --- a/src/header_encryption.c +++ b/src/header_encryption.c @@ -17,11 +17,18 @@ */ +#include // for uint32_t, uint8_t, uint64_t, uint16_t +#include // for calloc +#include // for memcpy #include "header_encryption.h" // for packet_header_change_dynamic_key, pac... #include "n2n.h" // for he_context_t, N2N_COMMUNITY_SIZE, TRA... +#include "n2n_define.h" // for N2N_COMMUNITY_SIZE +#include "n2n_typedefs.h" // for he_context_t, N2N_AUTH_CHALLENGE_SIZE #include "pearson.h" // for pearson_hash_128, pearson_hash_64 +#include "portable_endian.h" // for htobe32, be32toh, be64toh, htobe64 #include "random_numbers.h" // for n2n_rand #include "speck.h" // for speck_init, speck_context_t, speck_ctr +#include "uthash.h" // for HASH_FIND_STR #define HASH_FIND_COMMUNITY(head, name, out) HASH_FIND_STR(head, name, out) From 0c6f7ca5cb18c017d1138ff62726ade28ef26689 Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Fri, 16 Jun 2023 08:14:36 +0100 Subject: [PATCH 21/47] iwyu: hexdump.c --- src/hexdump.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/hexdump.c b/src/hexdump.c index a9cbd00..3692a85 100644 --- a/src/hexdump.c +++ b/src/hexdump.c @@ -16,10 +16,11 @@ * */ -#include -#include "n2n.h" -#include "hexdump.h" +#include // for uint8_t +#include // for fprintf, FILE +#include "hexdump.h" // for fhexdump + void fhexdump(unsigned int display_addr, void *in, int size, FILE *stream) { uint8_t *p = in; From 06c2e012d79f6dece73b7975e83353ce4847f357 Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Fri, 16 Jun 2023 08:30:22 +0100 Subject: [PATCH 22/47] iwyu: management.c --- src/management.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/management.c b/src/management.c index a207e00..7a7b7cc 100644 --- a/src/management.c +++ b/src/management.c @@ -3,22 +3,24 @@ * */ -#include -#ifndef WIN32 -#include -#include -#endif #include // for pearson_hash_64 +#include // for snprintf, NULL, size_t +#include // for strtoul +#include // for strtok, strlen, strncpy +#include "management.h" #include "n2n.h" // for TRACE_DEBUG, traceEvent +#ifndef WIN32 +#include // for getnameinfo, NI_NUMERICHOST, NI_NUMERICSERV +#include // for sendto, sockaddr +#endif + + // TODO: move logging defs in their own header and include that void setTraceLevel (int level); int getTraceLevel (); -#include -#include "management.h" - ssize_t send_reply (mgmt_req_t *req, strbuf_t *buf, size_t msg_len) { // TODO: better error handling (counters?) return sendto(req->mgmt_sock, buf->str, msg_len, 0, From 796ca2cb973ad3c3f6cfb5bac89a53ba788a5322 Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Fri, 16 Jun 2023 08:36:10 +0100 Subject: [PATCH 23/47] iwyu: management.h --- src/management.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/management.h b/src/management.h index 3dc542d..59cbce4 100644 --- a/src/management.h +++ b/src/management.h @@ -8,10 +8,19 @@ #ifndef MANAGEMENT_H #define MANAGEMENT_H 1 -#include // For the n2n_edge_t and n2n_sn_t defs - +#include // For the n2n_edge_t and n2n_sn_t defs +#include // for size_t +#include // for uint64_t +#include // for ssize_t +#include "n2n_define.h" // for n2n_event_topic #include "strbuf.h" +#ifdef WIN32 +#include +#else +#include // for sockaddr, sockaddr_storage, socklen_t +#endif + enum n2n_mgmt_type { N2N_MGMT_UNKNOWN = 0, N2N_MGMT_READ = 1, From b1cb7fe03e3c4ae74ad590df55dc33f210b9e660 Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Fri, 16 Jun 2023 08:38:58 +0100 Subject: [PATCH 24/47] iwyu: n2n.c --- src/n2n.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/n2n.c b/src/n2n.c index 3f75c94..0675dec 100644 --- a/src/n2n.c +++ b/src/n2n.c @@ -16,15 +16,29 @@ * */ -#include "n2n.h" +#include // for errno +#include // for va_end, va_list, va_start +#include // for free, atoi, calloc, strtol +#include // for memcmp, memcpy, memset, strlen, strerror +#include // for gettimeofday, timeval +#include // for time, localtime, strftime +#include "config.h" // for PACKAGE_BUILDDATE, PACKAGE_OSNAME, PACKA... +#include "n2n.h" #include "random_numbers.h" // for n2n_rand #include "sn_selection.h" // for sn_selection_criterion_default +#include "uthash.h" // for UT_hash_handle, HASH_DEL, HASH_ITER, HAS... -#include "minilzo.h" - -#include - +#ifdef WIN32 +#include +#include +#include +#else +#include // for inet_ntop +#include // for addrinfo, freeaddrinfo, gai_strerror +#include // for AF_INET, PF_INET, bind, setsockopt, shut... +#include // for closelog, openlog, syslog, LOG_DAEMON +#endif /* ************************************** */ From c3ed39375c9f52b3b6107f98065da181ce2a3fb7 Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Fri, 16 Jun 2023 09:07:58 +0100 Subject: [PATCH 25/47] iwyu: n2n_port_mapping.c --- src/n2n_port_mapping.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/n2n_port_mapping.c b/src/n2n_port_mapping.c index 35d1670..a5a057f 100644 --- a/src/n2n_port_mapping.c +++ b/src/n2n_port_mapping.c @@ -54,7 +54,8 @@ */ -#include "n2n.h" +#include // for uint16_t +#include "n2n_port_mapping.h" // for n2n_del_port_mapping, n2n_set_port_map... #ifdef HAVE_MINIUPNP From 3452b7ee4d6527272e4ac8707bf6b9fd5f71c453 Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Fri, 16 Jun 2023 09:09:16 +0100 Subject: [PATCH 26/47] iwyu: n2n_regex.c --- src/n2n_regex.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/n2n_regex.c b/src/n2n_regex.c index 6539451..49e6965 100644 --- a/src/n2n_regex.c +++ b/src/n2n_regex.c @@ -49,8 +49,12 @@ */ -#include "n2n.h" -#include "n2n_regex.h" +#include // for printf +#include // for calloc, free +#include // for memcpy +#include "n2n_typedefs.h" // for re_t +#include "n2n_regex.h" // for re_compile, re_match, re_matchp + /* Definitions: */ From aae43c5eb869c1614ba4853697b6682c97d10aee Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Fri, 16 Jun 2023 09:11:40 +0100 Subject: [PATCH 27/47] iwyu: network_traffic_filter.c --- src/network_traffic_filter.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/network_traffic_filter.c b/src/network_traffic_filter.c index dfdb54d..fc8b4c1 100644 --- a/src/network_traffic_filter.c +++ b/src/network_traffic_filter.c @@ -16,9 +16,22 @@ * */ -#include "n2n.h" -#include "network_traffic_filter.h" -#include "uthash.h" + +#include // for uint8_t, uint16_t, uint32_t +#include // for sprintf +#include // for free, malloc, atoi +#include // for memcpy, strcpy, NULL, memset +#include "n2n.h" // for filter_rule_t, filter_rule_pair_... +#include "network_traffic_filter.h" // for create_network_traffic_filter +#include "uthash.h" // for UT_hash_handle, HASH_ITER, HASH_DEL + +#ifdef WIN32 +#include +#include +#else +#include // for inet_ntoa, inet_addr +#include // for in_addr, in_addr_t, ntohs, ntohl +#endif // cache that hit less than 10 while 10000 package processed will be delete; #define CLEAR_CACHE_EVERY_X_COUNT 10000 From 4f769e765b278eb336852dcb91a137cbf1cd7235 Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Fri, 16 Jun 2023 09:13:40 +0100 Subject: [PATCH 28/47] iwyu: sn_management.c --- src/sn_management.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/sn_management.c b/src/sn_management.c index 61c94b9..9b422fa 100644 --- a/src/sn_management.c +++ b/src/sn_management.c @@ -21,11 +21,26 @@ * code. In the fullness of time, they should both be merged */ -#include "n2n.h" -#include "edge_utils_win32.h" -#include "strbuf.h" -#include "management.h" +#include // for errno +#include // for uint8_t, uint32_t +#include // for snprintf, size_t, sprintf, NULL +#include // for memcmp, memcpy, strerror, strncpy +#include // for ssize_t, time_t +#include "management.h" // for mgmt_req_t, send_reply, mgmt_handler_t, mgmt... +#include "n2n.h" // for n2n_sn_t, sn_community, peer_info, N2N_SN_PK... +#include "n2n_define.h" // for N2N_SN_PKTBUF_SIZE, UNPURGEABLE +#include "n2n_typedefs.h" // for n2n_sn_t, sn_community, peer_info, sn_stats_t +#include "strbuf.h" // for strbuf_t, STRBUF_INIT +#include "uthash.h" // for UT_hash_handle, HASH_ITER, HASH_COUNT + +#ifdef WIN32 +#include +#include "edge_utils_win32.h" +#else +#include // for sendto, socklen_t +#endif + int load_allowed_sn_community (n2n_sn_t *sss); /* defined in sn_utils.c */ From a8356c93dbe318237072a9c626fa0b9dacafb8fa Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Fri, 16 Jun 2023 09:15:29 +0100 Subject: [PATCH 29/47] iwyu: sn_selection.c --- src/sn_selection.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/sn_selection.c b/src/sn_selection.c index 0c865ee..6ad3962 100644 --- a/src/sn_selection.c +++ b/src/sn_selection.c @@ -17,7 +17,13 @@ */ -#include "n2n.h" +#include // for UINT64_MAX, uint32_t, int64_t, uint64_t +#include // for snprintf, NULL +#include // for memcpy, memset +#include "n2n.h" // for peer_info_t, n2n_edge_t, SN_SELECTION_CRIT... +#include "portable_endian.h" // for be32toh, be64toh, htobe64 +#include "sn_selection.h" // for selection_criterion_str_t, sn_selection_cr... +#include "uthash.h" // for UT_hash_handle, HASH_COUNT, HASH_ITER, HAS... static SN_SELECTION_CRITERION_DATA_TYPE sn_selection_criterion_common_read (n2n_edge_t *eee); From 6ee14559f95438eb12790a9cf187e52cde30c832 Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Fri, 16 Jun 2023 09:26:04 +0100 Subject: [PATCH 30/47] iwyu: sn_utils.c --- src/sn_utils.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/sn_utils.c b/src/sn_utils.c index 442e954..a1c3117 100644 --- a/src/sn_utils.c +++ b/src/sn_utils.c @@ -17,12 +17,38 @@ */ +#include // for errno, EAFNOSUPPORT +#include // for uint8_t, uint32_t, uint16_t, uint64_t +#include // for sscanf, snprintf, fclose, fgets, fopen +#include // for free, calloc, getenv +#include // for memcpy, NULL, memset, size_t, strerror +#include // for MAX +#include // for timeval +#include // for ssize_t +#include // for time_t, time #include "auth.h" // for ascii_to_bin, calculate_dynamic_key +#include "config.h" // for PACKAGE_VERSION #include "header_encryption.h" // for packet_header_encrypt, packet_header_... #include "n2n.h" // for sn_community, n2n_sn_t, peer_info +#include "n2n_regex.h" // for re_matchp, re_compile +#include "n2n_wire.h" // for encode_buf, encode_PEER_INFO, encode_... #include "pearson.h" // for pearson_hash_128, pearson_hash_32 +#include "portable_endian.h" // for be16toh, htobe16 #include "random_numbers.h" // for n2n_rand, n2n_rand_sqr, n2n_seed, n2n... +#include "sn_selection.h" // for sn_selection_criterion_gather_data #include "speck.h" // for speck_128_encrypt, speck_context_t +#include "uthash.h" // for UT_hash_handle, HASH_ITER, HASH_DEL + +#ifdef WIN32 +#include +#include +#else +#include // for inet_addr, inet_ntoa +#include // for ntohl, in_addr_t, sockaddr_in, INADDR... +#include // for TCP_NODELAY +#include // for FD_ISSET, FD_SET, select, FD_SETSIZE +#include // for recvfrom, shutdown, sockaddr_storage +#endif #define HASH_FIND_COMMUNITY(head, name, out) HASH_FIND_STR(head, name, out) From fa4cf74ff2414d58a241292f17a25978866e146f Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Fri, 16 Jun 2023 09:29:37 +0100 Subject: [PATCH 31/47] iwyu: supernode.c --- src/supernode.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/supernode.c b/src/supernode.c index 8d7b7f9..3155d86 100644 --- a/src/supernode.c +++ b/src/supernode.c @@ -19,9 +19,30 @@ /* Supernode for n2n-2.x */ +#include // for isspace +#include // for errno +#include // for required_argument, getopt_long, no_arg... +#include // for signal, SIGHUP, SIGINT, SIGPIPE, SIGTERM +#include // for uint8_t, uint32_t +#include // for printf, NULL, fclose, fgets, fopen +#include // for exit, atoi, calloc, free +#include // for strerror, strlen, memcpy, strncpy, str... +#include // for time_t, u_char, u_int +#include // for time +#include // for _exit, daemon, getgid, getuid, setgid #include "n2n.h" // for n2n_sn_t, sn_community, traceEvent #include "pearson.h" // for pearson_hash_64 +#include "uthash.h" // for UT_hash_handle, HASH_ITER, HASH_ADD_STR +#ifdef WIN32 +#include +#include +#else +#include // for inet_addr +#include // for ntohl, INADDR_ANY, INADDR_NONE, in_addr_t +#include // for getpwnam, passwd +#include // for listen, AF_INET +#endif #define HASH_FIND_COMMUNITY(head, name, out) HASH_FIND_STR(head, name, out) From 8443c294280804d49f6854219c575cf4f5369f21 Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Fri, 16 Jun 2023 09:40:16 +0100 Subject: [PATCH 32/47] iwyu: transform_aes.c --- src/transform_aes.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/transform_aes.c b/src/transform_aes.c index 6e66ada..4abf686 100644 --- a/src/transform_aes.c +++ b/src/transform_aes.c @@ -17,8 +17,13 @@ */ +#include // for uint8_t +#include // for calloc, free +#include // for memcpy, size_t, memset, memcmp, strlen +#include // for u_char, ssize_t, time_t #include "aes.h" // for AES_BLOCK_SIZE, aes_cbc_decrypt, aes_cbc... #include "n2n.h" // for n2n_trans_op_t, traceEvent, TRACE_ERROR +#include "n2n_wire.h" // for encode_uint64, encode_buf #include "pearson.h" // for pearson_hash_256 #include "random_numbers.h" // for n2n_rand From 8b6fcb8ab6b652803b5029b9735b27d4c161651e Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Fri, 16 Jun 2023 09:41:08 +0100 Subject: [PATCH 33/47] iwyu: transform_cc20.c --- src/transform_cc20.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/transform_cc20.c b/src/transform_cc20.c index 6bbecac..6cc8c8e 100644 --- a/src/transform_cc20.c +++ b/src/transform_cc20.c @@ -17,8 +17,13 @@ */ +#include // for uint8_t +#include // for size_t, calloc, free +#include // for memset, strlen +#include // for u_char, ssize_t, time_t #include "cc20.h" // for CC20_IV_SIZE, cc20_crypt, cc20_deinit #include "n2n.h" // for n2n_trans_op_t, traceEvent, TRACE_ERROR +#include "n2n_wire.h" // for encode_uint64 #include "pearson.h" // for pearson_hash_256 #include "random_numbers.h" // for n2n_rand From 89cb9419c7dc06648c3b5b795c269eb4eb01a926 Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Fri, 16 Jun 2023 09:42:18 +0100 Subject: [PATCH 34/47] iwyu: transform_lzo.c --- src/transform_lzo.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/transform_lzo.c b/src/transform_lzo.c index 69a1eff..ef6af55 100644 --- a/src/transform_lzo.c +++ b/src/transform_lzo.c @@ -17,7 +17,12 @@ */ -#include "n2n.h" +#include // for uint8_t +#include // for size_t, calloc, free, NULL +#include // for memset +#include // for time_t +#include "minilzo.h" // for lzo1x_1_compress, lzo1x_decompress, LZO1X_1_M... +#include "n2n.h" // for n2n_trans_op_t, TRACE_ERROR, traceEvent, N2N_... /* heap allocation for compression as per lzo example doc */ From 6deebe6f1ac42d9b39bd0406182c0ae2cb91de57 Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Fri, 16 Jun 2023 09:43:02 +0100 Subject: [PATCH 35/47] iwyu: transform_null.c --- src/transform_null.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/transform_null.c b/src/transform_null.c index cc3cbf3..50e06a8 100644 --- a/src/transform_null.c +++ b/src/transform_null.c @@ -17,7 +17,10 @@ */ -#include "n2n.h" +#include // for uint8_t +#include // for memcpy, size_t, memset +#include // for time_t +#include "n2n.h" // for n2n_trans_op_t, TRACE_DEBUG, traceEvent, N2N_... static int transop_deinit_null (n2n_trans_op_t *arg ) { From 76629dcf6ac2ad64efcd4725f45bfc18cd8d22d9 Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Fri, 16 Jun 2023 09:44:04 +0100 Subject: [PATCH 36/47] iwyu: transform_speck.c --- src/transform_speck.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/transform_speck.c b/src/transform_speck.c index 9b18591..7e79367 100644 --- a/src/transform_speck.c +++ b/src/transform_speck.c @@ -17,7 +17,12 @@ */ +#include // for uint8_t +#include // for size_t, calloc, free +#include // for memset, strlen +#include // for u_char, ssize_t, time_t #include "n2n.h" // for n2n_trans_op_t, traceEvent, TRACE_DEBUG +#include "n2n_wire.h" // for encode_uint64 #include "pearson.h" // for pearson_hash_256 #include "random_numbers.h" // for n2n_rand #include "speck.h" // for N2N_SPECK_IVEC_SIZE, speck_ctr, speck_de... From 0e175d35f6c1e20049b62a63700f1c1633b742a9 Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Fri, 16 Jun 2023 09:44:53 +0100 Subject: [PATCH 37/47] iwyu: transform_tf.c --- src/transform_tf.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/transform_tf.c b/src/transform_tf.c index f92ff92..478fed7 100644 --- a/src/transform_tf.c +++ b/src/transform_tf.c @@ -17,7 +17,12 @@ */ +#include // for uint8_t +#include // for calloc, free +#include // for memcpy, size_t, memset, memcmp, strlen +#include // for u_char, ssize_t, time_t #include "n2n.h" // for n2n_trans_op_t, traceEvent, TRACE_ERROR +#include "n2n_wire.h" // for encode_uint64, encode_buf #include "pearson.h" // for pearson_hash_256 #include "random_numbers.h" // for n2n_rand #include "tf.h" // for TF_BLOCK_SIZE, tf_cbc_decrypt, tf_cbc_en... From 3e47641630f021f4da8cff61154e04d3b3485e30 Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Fri, 16 Jun 2023 09:56:53 +0100 Subject: [PATCH 38/47] Actually test the zstd support before editing the transform_zstd --- .github/workflows/tests.yml | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 3da0500..c942631 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -46,12 +46,24 @@ jobs: - name: Install libraries needed for all options turned on run: | - sudo apt-get install -y libminiupnpc-dev libnatpmp-dev libpcap-dev libcap-dev + sudo apt-get install -y \ + libminiupnpc-dev \ + libnatpmp-dev \ + libpcap-dev \ + libcap-dev \ + libzstd-dev - name: Run minimal test set run: | ./autogen.sh - ./configure --enable-pthread --enable-miniupnp --enable-natpmp --enable-cap --enable-pcap CFLAGS="-O3 -DN2N_OPTION_USE_PORTMAPPING" + ./configure \ + --enable-pthread \ + --enable-miniupnp \ + --enable-natpmp \ + --enable-cap \ + --enable-pcap \ + --with-zstd \ + CFLAGS="-O3 -DN2N_OPTION_USE_PORTMAPPING" make test lint: From 852fc6ea8f1b605d92ebbb0f940007e9db99aa97 Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Fri, 16 Jun 2023 09:59:03 +0100 Subject: [PATCH 39/47] Minimal update to transform_zstd suggested by iwyu. This file was not active during the iwyu run, so it will need to be expanded upon later. --- src/transform_zstd.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/transform_zstd.c b/src/transform_zstd.c index c39ec3b..33aef23 100644 --- a/src/transform_zstd.c +++ b/src/transform_zstd.c @@ -17,12 +17,15 @@ */ -#include "n2n.h" +#include "config.h" // for HAVE_ZSTD #ifdef HAVE_ZSTD +#include "n2n.h" + + typedef struct transop_zstd { // no local data } transop_zstd_t; From de56ebb127073a2100d5b1c2dae70255d5a49ea7 Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Sun, 18 Jun 2023 09:06:17 +0100 Subject: [PATCH 40/47] iwyu: tuntap_linux.c --- src/tuntap_linux.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/tuntap_linux.c b/src/tuntap_linux.c index 75bda23..863684f 100644 --- a/src/tuntap_linux.c +++ b/src/tuntap_linux.c @@ -20,7 +20,23 @@ #ifdef __linux__ -#include "n2n.h" +#include // for inet_addr, inet_pton +#include // for iovec +#include // for errno +#include // for open, O_RDWR +#include // for IFF_NO_PI, IFF_TAP, TUNSETIFF +#include // for sockaddr_nl, nlmsghdr, NETLINK_... +#include // for ifinfomsg, RTMGRP_LINK +#include // for ifreq, IFNAMSIZ, ifr_name, ifr_... +#include // for ARPHRD_ETHER +#include // for sockaddr_in, IPPROTO_IP, in_addr +#include // for uint8_t +#include // for strerror, memset, strncpy, memcpy +#include // for ioctl, SIOCGIFADDR, SIOCGIFFLAGS +#include // for MIN +#include // for socket, msghdr, AF_INET, sockaddr +#include // for close, getpid, read, write, ssi... +#include "n2n.h" // for tuntap_dev, traceEvent, TRACE_E... static int setup_ifname (int fd, const char *ifname, const char *ipaddr, From b9dcb3fd35523149da01e1caeacdd7851fe0ae39 Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Sun, 18 Jun 2023 09:21:30 +0100 Subject: [PATCH 41/47] iwyu: wire.c --- src/wire.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/wire.c b/src/wire.c index 332c2d2..af1011f 100644 --- a/src/wire.c +++ b/src/wire.c @@ -26,7 +26,21 @@ * example. */ -#include "n2n.h" + +#include // for uint8_t, uint16_t, uint32_t, uint64_t +#include // for size_t, memset, memcpy +#include "portable_endian.h" // for be64toh, htobe64 +#include "n2n.h" // for n2n_sock_t, n2n_common_t, n2n_auth_t, n2n_RE... +#include "n2n_wire.h" // for decode_PACKET, decode_PEER_INFO, decode_QUER... + +#ifdef WIN32 +#include +#include +#else +#include // for sockaddr_in, sockaddr_in6, in6_addr, in_addr +#include // for AF_INET, AF_INET6, SOCK_STREAM, SOCK_DGRAM +#include // for sa_family_t +#endif int encode_uint8 (uint8_t * base, From 11fbea42237907f538feb89a7482b16a8630e6e2 Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Sun, 18 Jun 2023 10:55:07 +0100 Subject: [PATCH 42/47] iwyu: n2n-benchmark.c --- tools/n2n-benchmark.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tools/n2n-benchmark.c b/tools/n2n-benchmark.c index 510ddf5..8a4f8fd 100644 --- a/tools/n2n-benchmark.c +++ b/tools/n2n-benchmark.c @@ -16,14 +16,22 @@ * */ + +#include // for uint8_t, uint64_t +#include // for printf, fflush, size_t, NULL, stdout +#include // for memset, memcpy, memcmp, strncpy +#include // for ssize_t +#include "curve25519.h" // for curve25519 +#include "n2n.h" // for n2n_trans_op_t, n2n_common_t, n2n_edge_conf_t +#include "n2n_wire.h" // for decode_PACKET, decode_common, encode_PACKET +#include "pearson.h" // for pearson_hash_64, pearson_hash_init + #ifndef _MSC_VER /* MinGW has undefined function gettimeofday() warnings without this header * but Visual C++ doesnt even have the header */ -#include +#include // for gettimeofday, timeval #endif -#include "n2n.h" // for n2n_trans_op_t, n2n_common_t, n2n_edge_conf_t -#include "pearson.h" // for pearson_hash_64, pearson_hash_init #define DURATION 2.5 // test duration per algorithm #define PACKETS_BEFORE_GETTIME 2047 // do not check time after every packet but after (2 ^ n - 1) From 7439d88a00c3be38075da03eae82adedc07b1c69 Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Sun, 18 Jun 2023 10:56:05 +0100 Subject: [PATCH 43/47] iwyu: n2n-keygen.c --- tools/n2n-keygen.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/n2n-keygen.c b/tools/n2n-keygen.c index a734464..233256d 100644 --- a/tools/n2n-keygen.c +++ b/tools/n2n-keygen.c @@ -17,8 +17,11 @@ */ +#include // for uint8_t +#include // for fprintf, stdout, stderr +#include // for memset, strcmp #include "auth.h" // for bin_to_ascii, bind_private_key_to_username, gene... -#include "n2n.h" +#include "n2n.h" // for n2n_private_public_key_t, N2N_USER_KEY_LINE_STARTER int main(int argc, char * argv[]) { From 290ac83788d93b389abe22188cbbe5064552408e Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Sun, 18 Jun 2023 10:58:00 +0100 Subject: [PATCH 44/47] iwyu: n2n-portfwd.c --- tools/n2n-portfwd.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tools/n2n-portfwd.c b/tools/n2n-portfwd.c index 5d7f698..0e1bdd4 100644 --- a/tools/n2n-portfwd.c +++ b/tools/n2n-portfwd.c @@ -17,10 +17,29 @@ */ +#include // for getopt_long +#include // for optarg +#include // for signal, SIGINT, SIGPIPE, SIGTERM, SIG_IGN +#include // for uint16_t, uint32_t, uint8_t +#include // for printf, snprintf +#include // for NULL, atoi, exit, size_t +#include // for strchr, strcmp +#include // for timeval +#include // for time, time_t +#include // for STDIN_FILENO, _exit #include "json.h" // for _jsonpair, json_object_t, json_free #include "n2n.h" // for traceEvent, setTraceLevel, getTraceLevel +#include "n2n_port_mapping.h" // for n2n_del_port_mapping, n2n_set_port_map... #include "random_numbers.h" // for n2n_rand, n2n_seed, n2n_srand +#ifdef WIN32 +#include +#include +#else +#include // for sockaddr_in, htonl, htons, INADDR_LOOP... +#include // for select, FD_ISSET, FD_SET, FD_ZERO, fd_set +#include // for connect, recv, send, socket, AF_INET +#endif #define WITH_PORT 1 #define CORRECT_TAG 2 From 0a20265228fec716463bd9d5b4183f0baa62170e Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Sun, 18 Jun 2023 11:00:48 +0100 Subject: [PATCH 45/47] iwyu: n2n-route.c --- tools/n2n-route.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tools/n2n-route.c b/tools/n2n-route.c index 18cd7fc..d19f329 100644 --- a/tools/n2n-route.c +++ b/tools/n2n-route.c @@ -17,10 +17,38 @@ */ +#include // for errno +#include // for getopt_long, optind, optarg +#include // for signal, SIGINT, SIGPIPE, SIGTERM, SIG_IGN +#include // for uint8_t, uint16_t, uint32_t +#include // for snprintf, printf, sscanf +#include // for calloc, free, atoi, EXIT_FAILURE, exit +#include // for memset, NULL, memcmp, strchr, strcmp +#include // for timeval +#include // for time, time_t +#include // for getpid, STDIN_FILENO, _exit, geteuid #include "json.h" // for _jsonpair, json_object_t, _jsonvalue #include "n2n.h" // for inaddrtoa, traceEvent, TRACE_WARNING #include "random_numbers.h" // for n2n_rand, n2n_seed, n2n_srand +#include "uthash.h" // for UT_hash_handle, HASH_ADD, HASH_DEL +#ifdef __linux__ +#include // for nlmsghdr, NLMSG_OK, NETLINK_ROUTE, NLM... +#include // for RTA_DATA, rtmsg, RTA_GATEWAY, RTA_NEXT +#endif + +#ifdef WIN32 +#include +#include +#else +#include // for inet_pton +#include // for if_indextoname +#include // for rtentry, RTF_GATEWAY, RTF_UP +#include // for in_addr, sockaddr_in, htonl, htons, ntohl +#include // for ioctl, SIOCADDRT, SIOCDELRT +#include // for select, FD_ISSET, FD_SET, FD_ZERO, fd_set +#include // for send, socket, AF_INET, recv, connect +#endif #if defined (__linux__) || defined(WIN32) /* currently, Linux and Windows only */ From 771fdec013613b6601f1c996bd86349ad8b3a228 Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Sun, 18 Jun 2023 11:34:28 +0100 Subject: [PATCH 46/47] iwyu: tools/test*.c --- tools/tests-auth.c | 8 +++++--- tools/tests-compress.c | 13 +++++++++---- tools/tests-elliptic.c | 8 ++++++-- tools/tests-hashing.c | 4 +++- tools/tests-transform.c | 13 ++++++++++--- tools/tests-wire.c | 11 ++++++++--- 6 files changed, 41 insertions(+), 16 deletions(-) diff --git a/tools/tests-auth.c b/tools/tests-auth.c index 05f0b46..060cfc2 100644 --- a/tools/tests-auth.c +++ b/tools/tests-auth.c @@ -16,11 +16,13 @@ * */ -#include +#include // for uint8_t +#include // for printf, fprintf, stdout, stderr +#include // for memset #include "auth.h" // for ascii_to_bin, bin_to_ascii, generate_private_key -#include "n2n.h" -#include "hexdump.h" +#include "hexdump.h" // for fhexdump +#include "n2n.h" // for n2n_private_public_key_t uint8_t PKT_CONTENT1[]={ diff --git a/tools/tests-compress.c b/tools/tests-compress.c index dded8bc..273d0f1 100644 --- a/tools/tests-compress.c +++ b/tools/tests-compress.c @@ -16,12 +16,17 @@ * */ -#include -#include +#include // for assert +#include // for PRIx64 +#include // for uint8_t +#include // for printf, fprintf, stderr, stdout, NULL +#include // for exit +#include // for memcmp +#include "hexdump.h" // for fhexdump +#include "minilzo.h" // for lzo1x_1_compress, lzo1x_decompress, LZO1X_1_ME... +#include "n2n.h" // for N2N_PKT_BUF_SIZE, TRACE_ERROR, traceEvent -#include "n2n.h" -#include "hexdump.h" /* heap allocation for compression as per lzo example doc */ #define HEAP_ALLOC(var,size) lzo_align_t __LZO_MMODEL var [ ((size) + (sizeof(lzo_align_t) - 1)) / sizeof(lzo_align_t) ] diff --git a/tools/tests-elliptic.c b/tools/tests-elliptic.c index eb96365..25ac471 100644 --- a/tools/tests-elliptic.c +++ b/tools/tests-elliptic.c @@ -16,8 +16,12 @@ * */ -#include "n2n.h" -#include "hexdump.h" + +#include // for printf, fprintf, stdout, stderr +#include // for memset +#include "curve25519.h" // for curve25519 +#include "hexdump.h" // for fhexdump + void test_curve25519 (unsigned char *pkt_input, unsigned char *key) { char *test_name = "curve25519"; diff --git a/tools/tests-hashing.c b/tools/tests-hashing.c index 6e40fe7..1781744 100644 --- a/tools/tests-hashing.c +++ b/tools/tests-hashing.c @@ -16,8 +16,10 @@ * */ -#include +#include // for PRIx64, PRIx16, PRIx32 +#include // for uint8_t, uint16_t, uint32_t, uint64_t +#include // for printf, fprintf, stderr, stdout #include "n2n.h" #include "hexdump.h" // for fhexdump #include "pearson.h" // for pearson_hash_128, pearson_hash_16, pearson_has... diff --git a/tools/tests-transform.c b/tools/tests-transform.c index 11f0deb..4a48924 100644 --- a/tools/tests-transform.c +++ b/tools/tests-transform.c @@ -16,10 +16,17 @@ * */ -#include -#include "n2n.h" -#include "hexdump.h" +#include // for PRIx64 +#include // for uint8_t +#include // for printf, fprintf, size_t, stderr, stdout +#include // for exit +#include // for memcpy, memset, memcmp, strncpy +#include // for ssize_t +#include "hexdump.h" // for fhexdump +#include "n2n.h" // for n2n_trans_op_t, n2n_edge_conf_t, n2n_common_t +#include "n2n_wire.h" // for decode_PACKET, decode_common, encode_PACKET + #define DURATION 2.5 // test duration per algorithm #define PACKETS_BEFORE_GETTIME 2047 // do not check time after every packet but after (2 ^ n - 1) diff --git a/tools/tests-wire.c b/tools/tests-wire.c index e194f72..b6d7e18 100644 --- a/tools/tests-wire.c +++ b/tools/tests-wire.c @@ -16,10 +16,15 @@ * */ -#include -#include "n2n.h" -#include "hexdump.h" +#include // for PRIx64, PRIi32 +#include // for uint8_t +#include // for printf, fprintf, size_t, stderr, stdout +#include // for memset, strcpy, strncpy +#include "hexdump.h" // for fhexdump +#include "n2n.h" // for n2n_common_t, n2n_REGISTER_SUPER_t, n2n_REGIST... +#include "n2n_wire.h" // for encode_REGISTER, encode_REGISTER_SUPER, encode... + void init_ip_subnet (n2n_ip_subnet_t * d) { d->net_addr = 0x20212223; From 585b3cec593c4970d301d020056a3fd86c000577 Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Sun, 18 Jun 2023 11:51:56 +0100 Subject: [PATCH 47/47] iwyu: n2n.h There is still cleanup work to be done in the headers, but this concludes the major include-what-you-use refactoring. No functional change is intended or expected and all tests are passing. It is now a lot easier to see what is used from each header and work on possible refactoring in the future. The include-what-you-use tool is awkward to use with the current state of the build system - and will always be difficult to use in a multi-platform safe way. However, I hope to provide a non manual process for running with the tool in the future. --- include/n2n.h | 93 ++++++++++------------------------------------ src/tuntap_osx.c | 1 + tools/n2n-decode.c | 3 ++ 3 files changed, 23 insertions(+), 74 deletions(-) diff --git a/include/n2n.h b/include/n2n.h index 21b5ea2..99644dc 100644 --- a/include/n2n.h +++ b/include/n2n.h @@ -47,106 +47,51 @@ #undef N2N_HAVE_DAEMON #undef N2N_HAVE_TCP /* as explained on https://github.com/ntop/n2n/pull/627#issuecomment-782093706 */ #undef N2N_HAVE_SETUID -#endif +#endif /* WIN32 */ +#include // for size_t, FILE +#include "n2n_define.h" +#include "n2n_typedefs.h" -#include -#include -#include +#ifdef WIN32 +#include /* for privilege check in tools/n2n-route */ +#include /* for privilege check in tools/n2n-route */ +#include +#include /* for privilege check in tools/n2n-route */ +#include /* for tcp */ +#include "wintap.h" +#define SHUT_RDWR SD_BOTH /* for tcp */ +#endif /* #ifdef WIN32 */ #ifndef WIN32 -#include -#endif - -#ifndef _MSC_VER -#include -#endif /* #ifndef _MSC_VER */ - -#include -#include -#include -#include -#include - -#ifndef WIN32 -#include -#include -#include -#include -#include +#include // for in_addr (ptr only), in_addr_t +#include +#include // for uint8_t, uint64_t, uint32_t, uint16_t +#include // for time_t +#include // for close +#define closesocket(a) close(a) #ifdef __linux__ #define N2N_CAN_NAME_IFACE 1 -#include -#include -#include -#include -#include -#include -#include #endif /* #ifdef __linux__ */ #ifdef __FreeBSD__ #include #endif /* #ifdef __FreeBSD__ */ -#include -#include - #ifdef HAVE_ZSTD #include #endif -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #if defined (HAVE_OPENSSL_1_1) #include #include #endif - -#define closesocket(a) close(a) #endif /* #ifndef WIN32 */ -#include "minilzo.h" -#include -#include -#include -#include "lzoconf.h" -#include "uthash.h" -#include "n2n_define.h" -#include "n2n_typedefs.h" -#ifdef WIN32 -#include /* for privilege check in tools/n2n-route */ -#include /* for privilege check in tools/n2n-route */ -#include /* for privilege check in tools/n2n-route */ -#include /* for tcp */ -#define SHUT_RDWR SD_BOTH /* for tcp */ -#include "wintap.h" -#include -#else -#include -#endif /* #ifdef WIN32 */ -#include "n2n_wire.h" -#include "portable_endian.h" -#include "aes.h" -#include "curve25519.h" -#include "n2n_regex.h" -#include "sn_selection.h" -#include "network_traffic_filter.h" - -#include "n2n_port_mapping.h" /* ************************************** */ diff --git a/src/tuntap_osx.c b/src/tuntap_osx.c index 6d4092d..e46755d 100644 --- a/src/tuntap_osx.c +++ b/src/tuntap_osx.c @@ -17,6 +17,7 @@ */ +#include #include "n2n.h" diff --git a/tools/n2n-decode.c b/tools/n2n-decode.c index 94b14d6..cf5844b 100644 --- a/tools/n2n-decode.c +++ b/tools/n2n-decode.c @@ -16,8 +16,11 @@ * */ +#include // for errno #include +#include // for signal, SIGINT, SIGTERM #include "n2n.h" +#include "n2n_wire.h" #define SNAPLEN 1500 #define TIMEOUT 200