Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
592daad
Add consts where possible to the conf option structs
hamishcoleman Mar 8, 2026
abb8ae5
Rename test option to make it clearly grouped
hamishcoleman Mar 8, 2026
909821e
Relax const requirements for the sections, the assumption is a little…
hamishcoleman Mar 8, 2026
681d519
Make test config option an actual config option
hamishcoleman Mar 8, 2026
0412c89
Address linter concerns
hamishcoleman Mar 8, 2026
69242d3
Improve help text
hamishcoleman Mar 8, 2026
e90e56e
Refactor setup/teardown for better reuse
hamishcoleman Mar 10, 2026
2293c0c
Add record of context size, ready for simplifying structures
hamishcoleman Mar 10, 2026
ece3086
Simplify NOP benchmark handling
hamishcoleman Mar 11, 2026
68a88fa
Refactor most tests to use simpler setup
hamishcoleman Mar 11, 2026
f431ad4
Do not use brittle debug PEEK/POKE
hamishcoleman Mar 11, 2026
e70cb79
Remove edge cases by putting timer into child.
hamishcoleman Mar 11, 2026
d0738d8
Adjust comments to address lint concern
hamishcoleman Mar 11, 2026
65f4126
Allow debugging unexpected signals by outputing basic regs info
hamishcoleman Mar 12, 2026
a4d7c24
Add better initialisation and better checks for initialisation to sup…
hamishcoleman Mar 12, 2026
2a80f72
Switch pdu2tun to using the standardised malloc system
hamishcoleman Mar 12, 2026
b68e918
Refactor common operation into shared function
hamishcoleman Mar 13, 2026
3b32e4d
More consistant flagging for benchmark items
hamishcoleman Mar 14, 2026
18f7cf5
Rename the check mode subcmd to match the action it performs
hamishcoleman Mar 14, 2026
4737c69
Make non-variant test name more pretty
hamishcoleman Mar 14, 2026
51a42ad
Add a test list subcmd
hamishcoleman Mar 14, 2026
806dcc3
Address lint concerns
hamishcoleman Mar 14, 2026
3770dda
Use one consistant method for specifying which tests should run
hamishcoleman Mar 15, 2026
827fb86
Use consistant benchmark function names
hamishcoleman Mar 16, 2026
17dfc05
Fix non linux ptrace stubs for current function prototype
hamishcoleman Mar 16, 2026
63166a1
Enable using a test time of zero to indicate one single loop
hamishcoleman Mar 16, 2026
a243d9b
Add tun2pdu to complement the pdu2tun
claude Mar 31, 2026
69b744b
Remove unneeded memset operations
claude Mar 31, 2026
5468c04
Minor docs tweaks
hamishcoleman Apr 7, 2026
5cb3f2d
Fix build on windows
hamishcoleman Apr 16, 2026
c7afb68
Address lint concerns
hamishcoleman Apr 16, 2026
2c87037
Ensure new test is captured in CI results
hamishcoleman Apr 16, 2026
d3d489f
Fix building on Windows
hamishcoleman Apr 23, 2026
cb0dc69
Fix windows build - cannot check output, so use the fake check
hamishcoleman Apr 23, 2026
08aebc3
Only try to access regs on x86-64 - other arch have different structu…
hamishcoleman Apr 23, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@

# n3n

[![Testing](https://github.com/n42n/n3n/actions/workflows/tests.yml/badge.svg)](https://github.com/n42n/n3n/actions/workflows/tests.yml)
[![Latest Release](https://img.shields.io/github/v/release/n42n/n3n)](https://github.com/n42n/n3n/releases/latest)

n3n is a lightweight Peer-to-Peer VPN that creates virtual networks.

In order to start using n3n, two elements are required:
Expand All @@ -19,8 +22,16 @@ n3n tries to establish a direct peer-to-peer connection via udp between the
edge nodes when possible. When this is not possible (usually due to special NAT
devices), the supernode is also used to relay the packets.

```
[edge-A] ──────────────────── [edge-B]
\ direct p2p /
\ /
└──── [supernode] ────┘
(discovery + relay)
```

n3n was originally based on an older n2n project and hopes to keep protocol
compatiblilty with that.
compatibility with that.

Note that some distributions have very old versions of n2n packaged that are
incompatible with the protocol used by n3n. At the least, Debian has a n2n
Expand Down Expand Up @@ -54,9 +65,11 @@ For Debian, Ubuntu or similar dpkg based systems:

- Start the service: `sudo systemctl start n3n-edge@mynetwork`

- Check the connection: `sudo n3nctl -s mynetwork supernodes`
- Use `n3nctl` (the n3n management CLI) to inspect the running daemon:

- Check the connection: `sudo n3nctl -s mynetwork supernodes`

- List other nodes found: `sudo n3nctl -s mynetwork edges`
- List other nodes found: `sudo n3nctl -s mynetwork edges`

**IMPORTANT:** It is strongly advised to choose a custom community name (the
`community.name` option) and a secret encryption key (the `community.key`
Expand All @@ -82,6 +95,7 @@ You can contribute to n3n in various ways:
- Improve the documentation
- Provide pull requests with enhancements

For dev setup and internals, see the [Hacking guide](doc/Hacking.md).

---

Expand Down
77 changes: 43 additions & 34 deletions apps/n3n-edge.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,38 +340,26 @@ static void cmd_test_config_roundtrip (int argc, char **argv, void *_conf) {

static void cmd_test_benchmark (int argc, char **argv, void *_conf) {
n2n_edge_conf_t *conf = (n2n_edge_conf_t *)_conf;
int level=0;
if(argc == 2) {
if(strcmp("pretty", argv[1])==0) {
level=0;
} else if(strcmp("raw", argv[1])==0) {
level=1;
} else {
printf(
"benchmark:\n"
"\n"
" usage: n3n-edge test benchmark [mode]\n"
"\n"
"The mode can be `raw` or `pretty` and defaults to pretty\n"
);
exit(1);
}
}

// TODO:
// - provide a way to run a partial set of benchmarks
// - provide a way to output in normalised or raw numbers

benchmark_run_all(level, conf->benchmark_seconds);
benchmark_run_bench(
conf->test_output_format,
conf->test_benchmark_seconds,
argc-1,
++argv
);
exit(0);
}

static void cmd_test_builtin (int argc, char **argv, void *conf) {
int level=0;
if(argv[1]) {
level = atoi(argv[1]);
}
int errors = benchmark_check_all(level);
static void cmd_test_check (int argc, char **argv, void *_conf) {
n2n_edge_conf_t *conf = (n2n_edge_conf_t *)_conf;
int errors = benchmark_run_check(
conf->test_output_format,
argc-1,
++argv
);
if(errors) {
printf("ERROR\n");
} else {
Expand All @@ -382,13 +370,23 @@ static void cmd_test_builtin (int argc, char **argv, void *conf) {

static void cmd_test_fakebench (int argc, char **argv, void *_conf) {
n2n_edge_conf_t *conf = (n2n_edge_conf_t *)_conf;
benchmark_run_all_ptrace_instr(conf->benchmark_seconds, argv[1]);
benchmark_run_ptrace(
conf->test_benchmark_seconds,
argc-1,
++argv
);
exit(0);
}

static void cmd_test_list (int argc, char **argv, void *_conf) {
n2n_edge_conf_t *conf = (n2n_edge_conf_t *)_conf;
benchmark_list(conf->test_output_format);
exit(0);
}

static void cmd_test_hashing (int argc, char **argv, void *conf) {
fprintf(stderr, "Deprecated: use `n3n-edge test builtin` instead\n");
cmd_test_builtin(argc, argv, conf);
fprintf(stderr, "Deprecated: use `n3n-edge test check` instead\n");
cmd_test_check(argc, argv, conf);
}

static void cmd_tools_keygen (int argc, char **argv, void *conf) {
Expand Down Expand Up @@ -582,15 +580,17 @@ static struct n3n_subcmd_def cmd_tools[] = {
static struct n3n_subcmd_def cmd_test[] = {
{
.name = "benchmark",
.help = "[pretty|raw] - run internal benchmarks",
.help = "[name..] - run built-in tests and benchmark results",
.type = n3n_subcmd_type_fn,
.fn = &cmd_test_benchmark,
.session_arg = true,
},
{
.name = "builtin",
.help = "[level] - run built-in tests",
.name = "check",
.help = "[name..] - run built-in tests and check results",
.type = n3n_subcmd_type_fn,
.fn = &cmd_test_builtin,
.fn = &cmd_test_check,
.session_arg = true,
},
{
.name = "config",
Expand All @@ -603,11 +603,19 @@ static struct n3n_subcmd_def cmd_test[] = {
.type = n3n_subcmd_type_fn,
.fn = &cmd_test_hashing,
},
{
.name = "list",
.help = "Show the built-in tests",
.type = n3n_subcmd_type_fn,
.fn = &cmd_test_list,
.session_arg = true,
},
{
.name = "fakebench",
.help = "[name] - count test instructions (when perf is unavailable)",
.help = "[name..] - run tests, counting instructions (when perf is unavailable)",
.type = n3n_subcmd_type_fn,
.fn = &cmd_test_fakebench,
.session_arg = true,
},
{ .name = NULL }
};
Expand Down Expand Up @@ -682,7 +690,8 @@ static void n3n_config (int argc, char **argv, char *defname, n2n_edge_conf_t *c
exit(1);
}
if(r == -2) {
printf(
traceEvent(
TRACE_INFO,
"Warning: no config file found for session '%s'\n",
cmd.sessionname
);
Expand Down
2 changes: 1 addition & 1 deletion doc/Building.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ In order to run n3n on Windows, you will need the following:
The `edge.exe` program reads the `%USERPROFILE%\n3n\edge.conf` file if no
session name option is provided.

The `supernode.exe` program reads the `%UERPROFILE%\n3n\supernode.conf` file if
The `supernode.exe` program reads the `%USERPROFILE%\n3n\supernode.conf` file if
no session name option is provided.

Example [edge.conf](edge.conf.sample)
Expand Down
2 changes: 1 addition & 1 deletion doc/Tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ compare test output and expected results to quickly show deviations, helpful
when on bug hunt.

Example:
- `tools/tests-transforms`
- `tools/tests-transform`

### `n3n-decode`

Expand Down
1 change: 1 addition & 0 deletions include/n2n.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ struct n3n_runtime_data* edge_init (const n2n_edge_conf_t *conf, int *rv);
void update_supernode_reg (struct n3n_runtime_data * eee, time_t nowTime);
void readFromIPSocket (struct n3n_runtime_data * eee, int in_sock);
void edge_term (struct n3n_runtime_data *eee);
size_t edge_encode_packet (struct n3n_runtime_data *eee, uint8_t *tap_pkt, size_t len, uint8_t *pktbuf, size_t pktbuf_size, n2n_mac_t out_destMac);
void edge_send_packet2net (struct n3n_runtime_data *eee, uint8_t *tap_pkt, size_t len);
int run_edge_loop (struct n3n_runtime_data *eee);
int quick_edge_init (char *device_name, char *community_name,
Expand Down
4 changes: 3 additions & 1 deletion include/n2n_typedefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,9 @@ typedef struct n2n_edge_conf {
devstr_t tuntap_dev_name;
struct n2n_ip_subnet tuntap_v4;
uint8_t tuntap_ip_mode; /**< Interface IP address allocated mode, eg. DHCP. */
uint32_t benchmark_seconds;

uint32_t test_benchmark_seconds;
int test_output_format;

// Supernode specific config
n2n_mac_t sn_mac_addr;
Expand Down
17 changes: 11 additions & 6 deletions include/n3n/benchmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,21 @@ enum n3n_test_data {
test_data_tf,
test_data_pdu_v3,
test_data_pdu_eth,
test_data_tun2pdu,
};

#define BENCH_ITEM_CHECKONLY 0x1 // benchmark should be skipped
#define BENCH_ITEM_NOPTRACE 0x2 // fakebench takes too long, skip item
#define BENCH_SKIP_CHECK 0x1 // Default to skip check
#define BENCH_SKIP_BENCH 0x2 // Default to skip benchmark
#define BENCH_SKIP_PTRACE 0x4 // Default to skip fakebench

struct bench_item {
struct bench_item *next;

const char *name; // What is this testing
const char *variant; // variant, eg name of optimisation
int flags;
void *(*const setup)(void); // Any pre-run setup
const ssize_t ctx_size; // NR bytes to allocate for context
void *(*const setup)(void *const ctx); // Any pre-run setup
const ssize_t(*const run)(
void *const ctx,
const void *data_in,
Expand Down Expand Up @@ -62,8 +65,10 @@ struct bench_item {

void n3n_benchmark_register (struct bench_item *);

void benchmark_run_all (const int level, const int seconds);
void benchmark_run_all_ptrace_instr (const int seconds, const char *filter_name);
int benchmark_check_all (int level);
void benchmark_run_bench (const int level, const int seconds, int filterc, char **filterv);
void benchmark_run_ptrace (const int seconds, int filterc, char **filterv);
int benchmark_run_check (int level, int filterc, char **filterv);

void benchmark_list (const int level);

#endif
25 changes: 17 additions & 8 deletions include/n3n/conffile.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,30 @@ enum n3n_conf_type {
n3n_conf_groupid,
n3n_conf_macaddr, // TODO: conf has another macaddr string type
n3n_conf_hostname_str,
n3n_conf_str2id, // TODO: refactor some other types to use this
};

struct n3n_conf_str2id_data {
const int id;
const char *name;
};

struct n3n_conf_option {
char *name; // The name used to configure this option
int length; // Max length for string copy types
int offset; // offset within the conf structure of value
char *desc; // Short description
char *help; // lengthy description
enum n3n_conf_type type; // Which parser/validator to use
const char *name; // The name used to configure this option
union {
const int length; // Max length for string copy types
struct n3n_conf_str2id_data *str2id_data;
};
const int offset; // offset within the conf structure of value
const char *desc; // Short description
const char *help; // lengthy description
const enum n3n_conf_type type; // Which parser/validator to use
};

struct n3n_conf_section {
struct n3n_conf_section *next;
char *name; // The name of this config section
char *help; // A description for this section
const char *name; // The name of this config section
const char *help; // A description for this section
struct n3n_conf_option *options;
};

Expand Down
1 change: 1 addition & 0 deletions scripts/benchmark2graphdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def main():
"aes_decr,",
"aes_encr,",
"pdu2tun,",
"tun2pdu,",
"NOP,",
]

Expand Down
2 changes: 1 addition & 1 deletion scripts/test_builtin_edge.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ docmd() {
return $S
}

docmd "$BINDIR"/apps/n3n-edge test builtin
docmd "$BINDIR"/apps/n3n-edge test check

docmd "$BINDIR"/apps/n3n-edge test config roundtrip

Expand Down
Loading
Loading