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));
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;
}
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
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);
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
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;
}
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!
*
}
}
- /*
- * "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
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);
* 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);
}
/*