]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
fix up so that adding intermediate names work
authorAlan T. DeKok <aland@freeradius.org>
Thu, 2 Aug 2018 20:20:15 +0000 (16:20 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Thu, 2 Aug 2018 20:20:15 +0000 (16:20 -0400)
all fr_cmd_table_t now have to have `.name`

where we want to add a qualifier, e.g. `network X`, the table
has to have `.add_name = true,` added to it.

and fix `,dup` in network.c && worker.c

src/lib/io/network.c
src/lib/io/worker.c
src/lib/server/command.c
src/lib/server/command.h

index e011ee4254bf6c67315b657e4a94b430ccb740f0..c6abb4413129655b662567c05b0a2a99019fe202 100644 (file)
@@ -1496,13 +1496,13 @@ int fr_network_stats(fr_network_t const *nr, int num, uint64_t *stats)
        return 5;
 }
 
-static int cmd_stats_network(FILE *fp, UNUSED FILE *fp_err, void *ctx, UNUSED fr_cmd_info_t const *info)
+static int cmd_stats_self(FILE *fp, UNUSED FILE *fp_err, void *ctx, UNUSED fr_cmd_info_t const *info)
 {
        fr_network_t const *nr = ctx;
 
        fprintf(fp, "count.in\t%" PRIu64 "\n", nr->stats.in);
        fprintf(fp, "count.out\t%" PRIu64 "\n", nr->stats.out);
-       fprintf(fp, "stats,dup\t%" PRIu64 "\n", nr->stats.dup);
+       fprintf(fp, "count.dup\t%" PRIu64 "\n", nr->stats.dup);
        fprintf(fp, "count.dropped\t%" PRIu64 "\n", nr->stats.dropped);
        fprintf(fp, "count.sockets\t%d\n", rbtree_num_elements(nr->sockets));
 
@@ -1519,7 +1519,7 @@ static int socket_list(void *ctx, void *data)
                return 0;
        }
 
-       fprintf(fp, "%s\n", s->listen->app_io->get_name(s->listen->app_io_instance));
+       fprintf(fp, "%d\t%s\n", s->number, s->listen->app_io->get_name(s->listen->app_io_instance));
        return 0;
 }
 
@@ -1531,30 +1531,67 @@ static int cmd_socket_list(FILE *fp, UNUSED FILE *fp_err, void *ctx, UNUSED fr_c
        return 0;
 }
 
+static int cmd_stats_socket(FILE *fp, FILE *fp_err, void *ctx, fr_cmd_info_t const *info)
+{
+       fr_network_t const *nr = ctx;
+       fr_network_socket_t *s, my_s;
+
+       my_s.number = info->box[0]->vb_uint32;
+
+       s = rbtree_finddata(nr->sockets_by_num, &my_s);
+       if (!s) {
+               fprintf(fp_err, "No such socket number '%s'.\n", info->argv[0]);
+               return -1;
+       }
+
+       fprintf(fp, "count.in\t%" PRIu64 "\n", s->stats.in);
+       fprintf(fp, "count.out\t%" PRIu64 "\n", s->stats.out);
+       fprintf(fp, "count.dup\t%" PRIu64 "\n", s->stats.dup);
+       fprintf(fp, "count.dropped\t%" PRIu64 "\n", s->stats.dropped);
+
+       return 0;
+}
+
+
 fr_cmd_table_t cmd_network_table[] = {
        {
-               .parent = "stats network",
+               .parent = "stats",
+               .name = "network",
                .help = "Statistics for network threads.",
                .read_only = true
        },
 
        {
                .parent = "stats network",
-               .syntax = "self",
-               .func = cmd_stats_network,
+               .add_name = true,
+               .name = "self",
+               .func = cmd_stats_self,
                .help = "Show statistics for a specific network thread.",
                .read_only = true
        },
 
        {
-               .parent = "show network",
+               .parent = "stats network",
+               .add_name = true,
+               .name = "socket",
+               .syntax = "INTEGER",
+               .func = cmd_stats_socket,
+               .help = "Show statistics for a specific socket",
+               .read_only = true
+       },
+
+       {
+               .parent = "show",
+               .name = "network",
                .help = "Show information about network threads.",
                .read_only = true
        },
 
        {
                .parent = "show network",
-               .syntax = "socket list",
+               .add_name = true,
+               .name = "socket",
+               .syntax = "list",
                .func = cmd_socket_list,
                .help = "List the sockets associated with this network thread.",
                .read_only = true
index 0dc1891b121843eebc19048c34c64983161d8e93..46b3be0c23f8e44a663ad751a24e3c6712f14015 100644 (file)
@@ -1631,7 +1631,7 @@ static int cmd_stats_worker(FILE *fp, UNUSED FILE *fp_err, void *ctx, UNUSED fr_
 
        fprintf(fp, "count.in\t%" PRIu64 "\n", worker->stats.in);
        fprintf(fp, "count.out\t%" PRIu64 "\n", worker->stats.out);
-       fprintf(fp, "stats,dup\t%" PRIu64 "\n", worker->stats.dup);
+       fprintf(fp, "count.dup\t%" PRIu64 "\n", worker->stats.dup);
        fprintf(fp, "count.dropped\t%" PRIu64 "\n", worker->stats.dropped);
        fprintf(fp, "count.decoded\t%" PRIu64 "\n", worker->num_decoded);
        fprintf(fp, "count.timeouts\t%" PRIu64 "\n", worker->num_timeouts);
@@ -1652,13 +1652,16 @@ static int cmd_stats_worker(FILE *fp, UNUSED FILE *fp_err, void *ctx, UNUSED fr_
 
 fr_cmd_table_t cmd_worker_table[] = {
        {
-               .parent = "stats worker",
+               .parent = "stats",
+               .name = "worker",
                .help = "Statistics for workers threads.",
                .read_only = true
        },
 
        {
                .parent = "stats worker",
+               .add_name = true,
+               .name = "self",
                .func = cmd_stats_worker,
                .help = "Show statistics for a specific worker thread.",
                .read_only = true
index 75fbdc9d5eba19c529811bde09e3b59476fc2f14..f7a9e1dae8370094f6ba004d7db4084b567db464 100644 (file)
@@ -702,12 +702,17 @@ int fr_command_add(TALLOC_CTX *talloc_ctx, fr_cmd_t **head, char const *name, vo
        int argc = 0, depth = 0;
        fr_cmd_argv_t *syntax_argv;
 
-       if (name && !fr_command_valid_name(name)) {
+       if (!table->name) {
+               fr_strerror_printf("A name MUST be specified for table with parent %s syntax %s", table->parent, table->syntax);
+               return -1;
+       }
+
+       if (!name && table->add_name) {
+               fr_strerror_printf("An additional name must be specified");
                return -1;
        }
 
-       if (!name && !table->name) {
-               fr_strerror_printf("A name MUST be specified");
+       if (name && !fr_command_valid_name(name)) {
                return -1;
        }
 
@@ -763,6 +768,19 @@ int fr_command_add(TALLOC_CTX *talloc_ctx, fr_cmd_t **head, char const *name, vo
                depth = i;
        }
 
+       /*
+        *      Add an intermediate name, e.g. "network X"
+        */
+       if (table->add_name) {
+               cmd = fr_command_find(start, name, &insert);
+               if (!cmd) {
+                       cmd = fr_command_alloc(talloc_ctx, insert, name);
+               }
+
+               start = &(cmd->child);
+               depth++;
+       }
+
        /*
         *      @todo - check syntax, too!
         *
@@ -807,18 +825,12 @@ int fr_command_add(TALLOC_CTX *talloc_ctx, fr_cmd_t **head, char const *name, vo
                }
        }
 
-       /*
-        *      "name" is used only when the table doesn't specify a name.
-        */
-       if (table->name) name = table->name;
-
        /*
         *      "head" is now pointing to the list where we insert
         *      this new command.  We now see if the "name" currently
         *      exists.
         */
-
-       cmd = fr_command_find(start, name, &insert);
+       cmd = fr_command_find(start, table->name, &insert);
 
        /*
         *      The command exists already.  We can't have TWO
@@ -838,8 +850,8 @@ int fr_command_add(TALLOC_CTX *talloc_ctx, fr_cmd_t **head, char const *name, vo
                        if (cmd->help == table->help) return 0;
 
                        if (cmd->help != NULL) {
-                               fr_strerror_printf("Cannot change help for command %s %s",
-                                                  name , cmd->name);
+                               fr_strerror_printf("Cannot change help for command %s",
+                                                  cmd->name);
                                return -1;
                        }
                        rad_assert(cmd->intermediate);
@@ -862,7 +874,7 @@ int fr_command_add(TALLOC_CTX *talloc_ctx, fr_cmd_t **head, char const *name, vo
                 *      Allocate cmd and insert it into the current point.
                 */
                rad_assert(insert != NULL);
-               cmd = fr_command_alloc(talloc_ctx, insert, name);
+               cmd = fr_command_alloc(talloc_ctx, insert, table->name);
        }
 
        /*
index 1a9fae41926bbfde8c0a841f10cf619a122e8509..18b52eae3f13e6e89bccd0aa6e156faf49e4a971 100644 (file)
@@ -56,6 +56,7 @@ typedef struct fr_cmd_table_t {
        fr_cmd_func_t           func;                   //!< function to process this command
        fr_cmd_tab_t            tab_expand;             //!< tab expand things in the syntax string
        bool                    read_only;
+       bool                    add_name;               //!< do we add a name here?
 } fr_cmd_table_t;
 
 #define CMD_TABLE_END { .help = NULL }