From 39a71513f4b247650b923306868906402bfaa009 Mon Sep 17 00:00:00 2001 From: Logan oos Even <46396513+Logan007@users.noreply.github.com> Date: Thu, 28 Jan 2021 00:07:11 +0545 Subject: [PATCH] reworked supernode help text (#605) --- include/n2n.h | 1 + src/sn.c | 174 ++++++++++++++++++++++++++++++++++---------------- 2 files changed, 121 insertions(+), 54 deletions(-) diff --git a/include/n2n.h b/include/n2n.h index d0e3ae5..baf6aaf 100644 --- a/include/n2n.h +++ b/include/n2n.h @@ -31,6 +31,7 @@ tunctl -u UID -t tunX */ +#define N2N_HAVE_DAEMON /* needs to be defined before it gets undefined */ /* #define N2N_CAN_NAME_IFACE */ diff --git a/src/sn.c b/src/sn.c index 78e885e..b959cd0 100644 --- a/src/sn.c +++ b/src/sn.c @@ -174,58 +174,111 @@ static int load_allowed_sn_community (n2n_sn_t *sss, char *path) { /* *************************************************** */ /** Help message to print if the command line arguments are not valid. */ -static void help () { +static void help (int level) { + printf("\n"); print_n2n_version(); - printf("supernode (see supernode.conf)\n" - "or\n" - ); - printf("supernode "); - printf("-p "); - printf("-c "); - printf("-l "); - -#if defined(N2N_HAVE_DAEMON) - printf("[-f] "); + if(level == 0) /* short help */ { + + printf(" basic usage: supernode (see supernode.conf)\n" + "\n" + " or supernode " + " -p " + "\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: supernode (see supernode.conf)\n" + "\n" + " or supernode " + " -p " + "\n " + "[-F ] " + "\n options for under- " + "[-l ] " + "\n lying connection " +#ifdef SN_MANUAL_MAC + "[-m ] " #endif - printf("[-F ] "); -#if 0 - printf("[-m ] "); + "\n\n overlay network " + "[-c ] " + "\n configuration " + "[-a -/] " + "\n\n local options " +#if defined(N2N_HAVE_DAEMON) + "[-f] " #endif + "[-t ] " + "[-v] " #ifndef WIN32 - printf("[-u -g ] "); -#endif /* ifndef WIN32 */ - printf("[-t ] "); - printf("[-a ] "); - printf("[-v] "); - printf("\n\n"); - - printf("-p | Set UDP main listen port to \n"); - printf("-c | File containing the allowed communities.\n"); - printf("-l | Name/IP of a known supernode:port.\n"); + "\n " + "[-u ]" + "[-g ]" +#endif + "\n\n meaning of the " #if defined(N2N_HAVE_DAEMON) - printf("-f | Run in foreground.\n"); -#endif /* #if defined(N2N_HAVE_DAEMON) */ - printf("-F | Name of the supernodes federation (otherwise use '%s' by default)\n", (char *)FEDERATION_NAME); -#if 0 - printf("-m | Fix MAC address for the supernode (otherwise it may be random)\n" - " | eg. -m 01:02:03:04:05:06\n"); -#endif /* #if 0 */ + "[-f] do not fork but run in foreground" +#endif + "\n flag options " + "[-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: supernode (see supernode.conf)\n" + "\n" + " or supernode -p \n" + " [further optional command line parameters]\n\n" + ); + printf (" OPTIONS FOR THE UNDERLYING NETWORK CONNECTION\n"); + printf (" ---------------------------------------------\n\n"); + printf(" -p | fixed local UDP port\n"); + printf(" -F | name of the supernode's federation, defaults to\n" + " | '%s'\n", (char *)FEDERATION_NAME); + printf(" -l | ip address or name, and port of known supernode\n"); +#ifdef SN_MANUAL_MAC + printf(" -m | fixed MAC address for the supernode, e.g.\n" + " | '-m 10:20:30:40:50:60', random otherwise\n"); +#endif + printf ("\n"); + printf (" TAP DEVICE AND OVERLAY NETWORK CONFIGURATION\n"); + printf (" --------------------------------------------\n\n"); + printf(" -c | file containing the allowed communities\n"); + printf(" -a | subnet range for auto ip address service, e.g.\n" + " | '-a 192.168.0.0-192.168.255.0/24', defaults\n" + " | to '10.128.255.0-10.255.255.0/24'\n"); + printf ("\n"); + printf (" LOCAL OPTIONS\n"); + printf (" -------------\n\n"); +#if defined(N2N_HAVE_DAEMON) + printf(" -f | do not fork and run as a daemon, rather run in foreground\n"); +#endif + printf(" -t | management UDP port, for multiple supernodes on a machine\n"); + printf(" -v | make more verbose, repeat as required\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 */ - printf("-t | Management UDP Port (for multiple supernodes on a machine).\n"); - printf("-a | Subnet range for auto ip address service, e.g.\n"); - printf(" | -a 192.168.0.0-192.168.255.0/24, defaults to 10.128.255.0-10.255.255.0/24\n"); - printf("-v | Increase verbosity. Can be used multiple times.\n"); - printf("-h | This help message.\n"); - printf("\n"); + 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 -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(1); + exit(0); } + /* *************************************************** */ static int setOption (int optkey, char *_optarg, n2n_sn_t *sss) { @@ -344,7 +397,6 @@ static int setOption (int optkey, char *_optarg, n2n_sn_t *sss) { break; } - #ifndef WIN32 case 'u': /* unprivileged uid */ sss->userid = atoi(_optarg); @@ -354,7 +406,6 @@ static int setOption (int optkey, char *_optarg, n2n_sn_t *sss) { sss->groupid = atoi(_optarg); break; #endif - case 'F': { /* federation name */ snprintf(sss->federation->community, N2N_COMMUNITY_SIZE - 1 ,"*%s", _optarg); @@ -362,24 +413,26 @@ static int setOption (int optkey, char *_optarg, n2n_sn_t *sss) { break; } - -#if 0 +#ifdef SN_MANUAL_MAC case 'm': {/* MAC address */ str2mac(sss->mac_addr,_optarg); break; } -#endif /* #if 0 */ - +#endif case 'c': /* community file */ load_allowed_sn_community(sss, _optarg); break; - +#if defined(N2N_HAVE_DAEMON) case 'f': /* foreground */ sss->daemon = 0; break; +#endif + case 'h': /* quick reference */ + help(1); + break; - case 'h': /* help */ - help(); + case '@': /* long help */ + help(2); break; case 'v': /* verbose */ @@ -399,11 +452,13 @@ static int setOption (int optkey, char *_optarg, n2n_sn_t *sss) { static const struct option long_options[] = { {"communities", required_argument, NULL, 'c'}, +#if defined(N2N_HAVE_DAEMON) {"foreground", no_argument, NULL, 'f'}, +#endif {"local-port", required_argument, NULL, 'p'}, {"mgmt-port", required_argument, NULL, 't'}, {"autoip", required_argument, NULL, 'a'}, - {"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} }; @@ -415,8 +470,19 @@ static int loadFromCLI (int argc, char * const argv[], n2n_sn_t *sss) { u_char c; - while((c = getopt_long(argc, argv, "fp:l:u:g:t:a:c:F:m:vh", - long_options, NULL)) != '?') { + while((c = getopt_long(argc, argv, + "p:l:t:a:c:F:vh" +#ifdef SN_MANUAL_MAC + "m:" +#endif +#if defined(N2N_HAVE_DAEMON) + "f" +#endif +#ifndef WIN32 + "u:g:" +#endif + , + long_options, NULL)) != '?') { if(c == 255) { break; } @@ -609,7 +675,7 @@ int main (int argc, char * const argv[]) { #endif if(rc < 0) { - help(); + help(0); /* short help */ } #if defined(N2N_HAVE_DAEMON)