From f352c992555cfd4bb2f127dea799c2ef8d796206 Mon Sep 17 00:00:00 2001 From: Logan oos Even <46396513+Logan007@users.noreply.github.com> Date: Thu, 28 Jan 2021 00:07:28 +0545 Subject: [PATCH] reworked edge help text (#604) --- src/edge.c | 262 ++++++++++++++++++++++++++++++++++--------------- src/n2n.c | 2 +- win32/wintap.c | 2 +- 3 files changed, 184 insertions(+), 82 deletions(-) diff --git a/src/edge.c b/src/edge.c index 33a671d..898c287 100644 --- a/src/edge.c +++ b/src/edge.c @@ -117,98 +117,194 @@ static int scan_address (char * ip_addr, size_t addr_size, /* *************************************************** */ -static void help () { +static void help (int level) { + + printf("\n"); print_n2n_version(); - printf("edge (see edge.conf)\n" - "or\n" - ); - printf("edge " -#if defined(N2N_CAN_NAME_IFACE) - "-d " -#endif /* #if defined(N2N_CAN_NAME_IFACE) */ - "-a [static:|dhcp:][/nn] " - "-c " - "[-k ]\n" - " " -#ifndef WIN32 - "[-u -g ]" -#endif /* #ifndef WIN32 */ + if(level == 0) /* short help */ { -#ifndef WIN32 - "[-f]" -#endif /* #ifndef WIN32 */ + printf(" basic usage: edge (see edge.conf)\n" + "\n" + " or edge " + " -c " + "\n " + " -l : " + "\n " + "[-a ] " + "\n " +#if defined(N2N_CAN_NAME_IFACE) + "[-d ] " + "\n " +#endif + "[-k ] " + "\n" + "\n -h shows a quick reference including all available options" + "\n --help gives a detailed parameter description" + "\n man files for n2n, edge, and superndode contain in-depth information" + "\n\n"); + + } else if(level == 1) /* quick reference */ { + + printf(" general usage: edge (see edge.conf)\n" + "\n" + " or edge " + " -c " + " -l " + "\n " + "[-p ] " #ifdef __linux__ - "[-T ]" + "[-T ] " #endif - "[-n cidr:gateway] " - "[-m ] " - "-l \n" - " " - "[-p ] [-M ] " #ifndef __APPLE__ - "[-D] " + "[-D] " #endif - "[-r] [-E] [-v] [-i ] [-L ] [-t ] [-A[]] [-H] [-z[]] " - "[-R ] " - "[-h]\n\n"); - + "[-S] " + "\n options for under- " + "[-i ]" + "[-L ]" + "\n lying connection " + "[-k ] " + "[-A] " + "[-H] " + "[-z]" + "\n\n tap device and " + "[-a [static:|dhcp:][/]] " + "\n overlay network " + "[-m ] " #if defined(N2N_CAN_NAME_IFACE) - printf("-d | tap device name\n"); + "[-d ] " #endif + "\n configuration " + "[-M ] " + "[-r] " + "[-E] " + "[-I ] " + "\n " + "[-R ] " + "\n\n local options " +#ifndef WIN32 + "[-f] " +#endif + "[-t ] " + "[-v] " + "[-n ] " +#ifndef WIN32 + "\n " + "[-u ]" + "[-g ]" +#endif + "\n\n environment " + "N2N_KEY instead of [-k ]" + "\n variables " + "\n " - printf("-a [mode:]
[/nn] | Interface address and optional subnet (cidr, default /24). For DHCP use '-r -a dhcp:0.0.0.0'\n"); - printf("-c | n2n community name the edge belongs to.\n"); - printf("-k | Encryption key (ASCII) - also N2N_KEY=.\n"); - printf("-l | Supernode IP:port\n"); - printf("-i | Registration interval, for NAT hole punching (default 20 seconds)\n"); - printf("-I | Annotate the edge's description (hint), identified in the manage port\n"); - printf("-L | TTL for registration packet when UDP NAT hole punching through supernode (default 0 for not set )\n"); - printf("-p | Fixed local UDP port.\n"); -#ifndef WIN32 - printf("-u | User ID (numeric) to use when privileges are dropped.\n"); - printf("-g | Group ID (numeric) to use when privileges are dropped.\n"); -#endif /* ifndef WIN32 */ -#ifndef WIN32 - printf("-f | Do not fork and run as a daemon; rather run in foreground.\n"); -#endif /* #ifndef WIN32 */ - printf("-m | Fix MAC address for the TAP interface (otherwise it may be random)\n" - " | eg. -m 01:02:03:04:05:06\n"); - printf("-M | Specify n2n MTU of edge interface (default %d).\n", DEFAULT_MTU); + "\n meaning of the " #ifndef __APPLE__ - printf("-D | Enable PMTU discovery. PMTU discovery can reduce fragmentation but\n" - " | causes connections stall when not properly supported.\n"); + "[-D] enable PMTU discovery" #endif - printf("-r | Enable packet forwarding through n2n community.\n"); - printf("-A1 | Disable payload encryption. Do not use with key (defaulting to AES then).\n"); - printf("-A2 ... -A5 or -A | Choose a cipher for payload encryption, requires a key: -A2 = Twofish,\n"); - printf(" | -A3 or -A (deprecated) = AES (default), " - "-A4 = ChaCha20, " - "-A5 = Speck-CTR.\n"); - printf("-H | Enable full header encryption. Requires supernode with fixed community.\n"); - printf("-z1 ... -z2 or -z | Enable compression for outgoing data packets: -z1 or -z = lzo1x" + "\n flag options [-S] do not connect p2p, always use supernode" + "\n [-H] enable header encryption" + "\n [-r] enable packet forwarding through n2n community" + "\n [-E] accept multicast MAC addresses" +#ifndef WIN32 + "\n [-f] do not fork but run in foreground" +#endif + "\n [-v] make more verbose, repeat as required" + "\n " + + "\n -h shows this quick reference including all available options" + "\n --help gives a detailed parameter description" + "\n man files for n2n, edge, and superndode contain in-depth information" + "\n\n"); + + } else /* long help */ { + + printf(" general usage: edge (see edge.conf)\n" + "\n" + " or edge -c -l \n" + " [further optional command line parameters]\n\n" + ); + printf (" OPTIONS FOR THE UNDERLYING NETWORK CONNECTION\n"); + printf (" ---------------------------------------------\n\n"); + printf(" -c | n2n community name the edge belongs to\n"); + printf(" -l | supernode ip address or name, and port\n"); + printf(" -p | fixed local UDP port\n"); +#ifdef __linux__ + printf(" -T | TOS for packets, e.g. 0x48 for SSH like priority\n"); +#endif +#ifndef __APPLE__ + printf(" -D | enable PMTU discovery, it can reduce fragmentation but\n" + " | causes connections to stall if not properly supported\n"); +#endif + printf(" -S | do not connect p2p, always use the supernode\n"); + printf(" -i | registration interval, for NAT hole punching (default\n" + " | 20 seconds)\n"); + printf(" -L | TTL for registration packet for NAT hole punching through\n" + " | supernode (default 0 for not set)\n"); + printf(" -k | encryption key (ASCII) - also N2N_KEY=\n"); + printf(" -A1 | disable payload encryption, do not use with key, defaults\n" + " | to AES then\n"); + printf(" -A2 ... -A5 or -A | choose a cipher for payload encryption, requires a key,\n" + " | -A2 = Twofish, -A3 or -A (deprecated) = AES (default),\n" + " | -A4 = ChaCha20, -A5 = Speck-CTR\n"); + printf(" -H | use header encryption, supernode needs fixed community\n"); + printf(" -z1 ... -z2 or -z | compress outgoing data packets, -z1 or -z lzo1x,\n" + " | " #ifdef N2N_HAVE_ZSTD - ", -z2 = zstd" + "-z2 = zstd, " #endif - " (default=disabled).\n"); - printf("-E | Accept multicast MAC addresses (default=drop).\n"); - printf("-S | Do not connect P2P. Always use the supernode.\n"); -#ifdef __linux__ - printf("-T | TOS for packets (e.g. 0x48 for SSH like priority)\n"); + "disabled by default\n"); + printf ("\n"); + printf (" TAP DEVICE AND OVERLAY NETWORK CONFIGURATION\n"); + printf (" --------------------------------------------\n\n"); + printf(" -a [mode][/n] | interface address and optional CIDR subnet, default '/24',\n" + " | mode = [static|dhcp]:, for DHCP use '-r -a dhcp:0.0.0.0',\n" + " | edge draws IP address from supernode if no '-a ...' given\n"); + printf(" -m | fixed MAC address for the TAP interface, e.g.\n" + " | '-m 10:20:30:40:50:60', random otherwise\n"); +#if defined(N2N_CAN_NAME_IFACE) + printf(" -d | TAP device name\n"); #endif - printf("-n | Route an IPv4 network via the gw. Use 0.0.0.0/0 for the default gw. Can be set multiple times.\n"); - printf("-v | Make more verbose. Repeat as required.\n"); - printf("-R | Drop or accept packets by rules. Can be set multiple times. \n"); - printf(" | Rule format: src_ip/len:[b_port,e_port],dst_ip/len:[s_port,e_port],TCP+/-,UDP+/-,ICMP+/- \n"); - printf("-t | Management UDP Port (for multiple edges on a machine).\n"); - - printf("\nEnvironment variables:\n"); - printf(" N2N_KEY | Encryption key (ASCII). Not with -k.\n"); - + printf(" -M | specify n2n MTU of TAP interface, default %d\n", DEFAULT_MTU); + printf(" -r | enable packet forwarding through n2n community\n"); + printf(" -E | accept multicast MAC addresses, drop by default\n"); + printf(" -I | annotate the edge's description used for easier\n" + " | identification in management port output\n"); + printf(" -R | drop or accept packets by rules, can be set multiple times\n"); + printf(" | rule format: 'src_ip/n:[s_port,e_port],...\n" + " | |on same| ...dst_ip/n:[s_port,e_port],...\n" + " | | line | ...TCP+/-,UDP+/-,ICMP+/-'\n"); + printf ("\n"); + printf (" LOCAL OPTIONS\n"); + printf (" -------------\n\n"); +#ifndef WIN32 + printf(" -f | do not fork and run as a daemon, rather run in foreground\n"); +#endif + printf(" -t | management UDP port, for multiple edges on a machine\n"); + printf(" -v | make more verbose, repeat as required\n"); + printf(" -n | route an IPv4 network via the gateway, use 0.0.0.0/0 for\n" + " | the default gateway, can be set multiple times\n"); +#ifndef WIN32 + printf(" -u | numeric user ID to use when privileges are dropped\n"); + printf(" -g | numeric group ID to use when privileges are dropped\n"); +#endif + printf ("\n"); + printf (" ENVIRONMENT VARIABLES\n"); + printf (" ---------------------\n\n"); + printf(" N2N_KEY | encryption key (ASCII), not with '-k ...'\n"); #ifdef WIN32 - printf("\nAvailable TAP adapters:\n"); - win_print_available_adapters(); + printf ("\n"); + printf (" AVAILABLE TAP ADAPTERS\n"); + printf (" ----------------------\n\n"); + win_print_available_adapters(); #endif + printf ("\n" + "\n -h shows a quick reference including all available options" + "\n --help gives this detailed parameter description" + "\n man files for n2n, edge, and superndode contain in-depth information" + "\n\n"); + } exit(0); } @@ -494,8 +590,13 @@ static int setOption (int optkey, char *optargument, n2n_tuntap_priv_config_t *e break; } - case 'h': /* help */ { - help(); + case 'h': /* quick reference */ { + help(1); + break; + } + + case '@': /* long help */ { + help(2); break; } @@ -528,6 +629,7 @@ static int setOption (int optkey, char *optargument, n2n_tuntap_priv_config_t *e /* *********************************************** */ + static const struct option long_options[] = { { "community", required_argument, NULL, 'c' }, @@ -535,7 +637,7 @@ static const struct option long_options[] = { "tap-device", required_argument, NULL, 'd' }, { "euid", required_argument, NULL, 'u' }, { "egid", required_argument, NULL, 'g' }, - { "help" , no_argument, NULL, 'h' }, + { "help" , no_argument, NULL, '@' }, /* special character '@' to identify long help case */ { "verbose", no_argument, NULL, 'v' }, { NULL, 0, NULL, 0 } }; @@ -775,10 +877,10 @@ int main (int argc, char* argv[]) { } if(rc < 0) - help(); + help(0); /* short help */ if(edge_verify_conf(&conf) != 0) - help(); + help(0); /* short help */ traceEvent(TRACE_NORMAL, "Starting n2n edge %s %s", PACKAGE_VERSION, PACKAGE_BUILDDATE); diff --git a/src/n2n.c b/src/n2n.c index 04e013d..7e8ac3d 100644 --- a/src/n2n.c +++ b/src/n2n.c @@ -433,7 +433,7 @@ void print_n2n_version () { printf("Welcome to n2n v.%s for %s\n" "Built on %s\n" - "Copyright 2007-2020 - ntop.org and contributors\n\n", + "Copyright 2007-2021 - ntop.org and contributors\n\n", GIT_RELEASE, PACKAGE_OSNAME, PACKAGE_BUILDDATE); } diff --git a/win32/wintap.c b/win32/wintap.c index 2a48608..7a50b58 100644 --- a/win32/wintap.c +++ b/win32/wintap.c @@ -103,7 +103,7 @@ static void iterate_win_network_adapters( /* ***************************************************** */ static int print_adapter_callback(struct win_adapter_info *adapter, struct tuntap_dev *device) { - printf(" %s - %s\n", adapter->adapterid, adapter->adaptername); + printf(" %s - %s\n", adapter->adapterid, adapter->adaptername); /* continue */ return(1);