X-Git-Url: http://git.sameswireless.fr/l2tpns.git/blobdiff_plain/26a2025a1b7f12e9d962294583d76da30fb668d9..dac7fe82bb8d933fb3a68cb9c0256dac6f4470ae:/cli.c diff --git a/cli.c b/cli.c index d2262d5..876ad06 100644 --- a/cli.c +++ b/cli.c @@ -21,6 +21,7 @@ #include #include #include +#include #include "l2tpns.h" #include "constants.h" @@ -75,6 +76,7 @@ static char *debug_levels[] = { #endif static int cmd_show_session(struct cli_def *cli, const char *command, char **argv, int argc); +static int cmd_show_group(struct cli_def *cli, const char *command, char **argv, int argc); static int cmd_show_tunnels(struct cli_def *cli, const char *command, char **argv, int argc); static int cmd_show_users(struct cli_def *cli, const char *command, char **argv, int argc); static int cmd_show_radius(struct cli_def *cli, const char *command, char **argv, int argc); @@ -154,6 +156,7 @@ void init_cli() cli_register_command(cli, c, "running-config", cmd_show_run, PRIVILEGE_PRIVILEGED, MODE_EXEC, "Show the currently running configuration"); cli_register_command(cli, c, "remotelns-conf", cmd_show_rmtlnsconf, PRIVILEGE_PRIVILEGED, MODE_EXEC, "Show a list of remote LNS configuration"); cli_register_command(cli, c, "session", cmd_show_session, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, "Show a list of sessions or details for a single session"); + cli_register_command(cli, c, "group", cmd_show_group, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, "Show a list of groups or details for a single group"); cli_register_command(cli, c, "tbf", cmd_show_tbf, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, "List all token bucket filters in use"); cli_register_command(cli, c, "throttle", cmd_show_throttle, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, "List all throttled sessions and associated TBFs"); cli_register_command(cli, c, "tunnels", cmd_show_tunnels, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, "Show a list of tunnels or details for a single tunnel"); @@ -730,7 +733,7 @@ static int cmd_show_counters(struct cli_def *cli, const char *command, char **ar GET_STAT(tun_tx_bytes), GET_STAT(tun_tx_packets), GET_STAT(tun_tx_errors)); - cli_print(cli, ""); + cli_print(cli, " "); cli_print(cli, "%-10s %10s %10s %10s %10s", "Tunnel", "Bytes", "Packets", "Errors", "Retries"); cli_print(cli, "%-10s %10u %10u %10u", "RX", @@ -742,7 +745,7 @@ static int cmd_show_counters(struct cli_def *cli, const char *command, char **ar GET_STAT(tunnel_tx_packets), GET_STAT(tunnel_tx_errors), GET_STAT(tunnel_retries)); - cli_print(cli, ""); + cli_print(cli, " "); cli_print(cli, "%-30s%-10s", "Counter", "Value"); cli_print(cli, "-----------------------------------------"); @@ -808,7 +811,7 @@ static int cmd_show_counters(struct cli_def *cli, const char *command, char **ar char *p = strchr(t, '\n'); if (p) *p = 0; - cli_print(cli, ""); + cli_print(cli, " "); cli_print(cli, "Last counter reset %s", t); } @@ -1791,7 +1794,7 @@ static int cmd_uptime(struct cli_def *cli, const char *command, char **argv, int return CLI_HELP_NO_ARGS; fh = fopen("/proc/loadavg", "r"); - fgets(buf, 100, fh); + p = fgets(buf, 100, fh); fclose(fh); for (i = 0; i < 3; i++) @@ -2220,7 +2223,7 @@ static int cmd_show_bgp(struct cli_def *cli, const char *command, char **argv, i if (!hdr++) { - cli_print(cli, ""); + cli_print(cli, " "); cli_print(cli, "Peer AS Address " "State Retries Retry in Route Pend Timers"); cli_print(cli, "------------------ ----- --------------- " @@ -3110,6 +3113,77 @@ static int cmd_reload(struct cli_def *cli, const char *command, char **argv, int return CLI_OK; } +static int cmd_show_group(struct cli_def *cli, const char *command, char **argv, int argc) +{ + int i; + groupidt g; + + if (CLI_HELP_REQUESTED) + return cli_arg_help(cli, 1, + "<1-%d>", MAXGROUPE-1, "Show specific group by id", + NULL); + + time(&time_now); + if (argc > 0) + { + // Show individual group + for (i = 0; i < argc; i++) + { + sessionidt s; + + g = atoi(argv[i]); + if (g <= 0 || g >= MAXGROUPE) + { + cli_print(cli, "Invalid group id \"%s\"", argv[i]); + continue; + } + + cli_print(cli, "\r\nGroup %d:", g); + cli_print(cli, "\tNb Session:\t\t%d", grpsession[g].nbsession); + cli_print(cli, "\tNb Routes:\t\t%d", grpsession[g].nbroutesgrp); + cli_print(cli, "\ttime_changed:\t\t%d\n", grpsession[g].time_changed); + + for (i = 0; i < grpsession[g].nbsession; i++) + { + if ((s = grpsession[g].sesslist[i].sid)) + { + cli_print(cli, "\tSession:\t%d\tTx Rate:%d Kbps\t\t\tweight:\t%d", + s, + grpsession[g].sesslist[i].tx_rate/(1024/8), + grpsession[g].sesslist[i].weight); + } + } + + for (i = 0; i < grpsession[g].nbroutesgrp; i++) + { + if (grpsession[g].route[i].ip != 0) + { + cli_print(cli, "\tRoute:\t%s/%d", fmtaddr(htonl(grpsession[g].route[i].ip), 0), grpsession[g].route[i].prefixlen); + } + } + } + return CLI_OK; + } + + // Show Summary + cli_print(cli, "%5s %7s %9s %12s", + "GID", + "Nb Sess", + "Nb Routes", + "Time changed"); + + for (g = gnextgrpid; g != 0; g = grpsession[g].prev) + { + cli_print(cli, "%5d %7d %9d %12d", + g, + grpsession[g].nbsession, + grpsession[g].nbroutesgrp, + grpsession[g].time_changed); + } + + return CLI_OK; +} + static int cmd_setforward(struct cli_def *cli, const char *command, char **argv, int argc) { int ret;