diff options
| author | Denys Fedoryshchenko <denys.f@collabora.com> | 2025-08-05 01:49:03 +0300 |
|---|---|---|
| committer | Denys Fedoryshchenko <denys.f@collabora.com> | 2025-08-07 18:19:48 +0300 |
| commit | a1816927ce0f26d00e95bfdf24a0f81262c72646 (patch) | |
| tree | 8bc8fe6a0d593572c37ec2dfd9ae9c6b3ca98f5d | |
| parent | 7351d79ab52964bbf4185c14c458064180f756f9 (diff) | |
| download | accel-ppp-a1816927ce0f26d00e95bfdf24a0f81262c72646.tar.gz accel-ppp-a1816927ce0f26d00e95bfdf24a0f81262c72646.zip | |
cmd: implement show ippool command
Command Usage:
accel-ppp# show ippool
IP Pool Usage Report
====================
<default>
total: 16384
used: 0
available: 16384
usage: 0%
Signed-off-by: Denys Fedoryshchenko <denys.f@collabora.com>
| -rw-r--r-- | accel-pppd/extra/ippool.c | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/accel-pppd/extra/ippool.c b/accel-pppd/extra/ippool.c index 3ae48e95..f839a376 100644 --- a/accel-pppd/extra/ippool.c +++ b/accel-pppd/extra/ippool.c @@ -13,6 +13,7 @@ #include "ap_session_backup.h" #include "ipdb.h" +#include "cli.h" #ifdef RADIUS #include "radius.h" @@ -612,6 +613,81 @@ static void ippool_init1(void) ipdb_register(&ipdb); } +static int show_ippool_exec(const char *cmd, char * const *fields, int fields_cnt, void *client) +{ + struct ippool_t *pool; + uint32_t total, available, used; + struct ippool_item_t *it; + + cli_send(client, "IP Pool Usage Report\r\n"); + cli_send(client, "====================\r\n"); + + // Show default pool first + if (def_pool) { + spin_lock(&def_pool->lock); + + total = 0; + available = 0; + + if (def_pool->startip && def_pool->endip) { + total = def_pool->endip - def_pool->startip + 1; + } + + list_for_each_entry(it, &def_pool->items, entry) { + available++; + } + + used = total - available; + spin_unlock(&def_pool->lock); + + if (total > 0) { + cli_sendv(client, "<default>\r\n total: %u\r\n used: %u\r\n available: %u\r\n usage: %u%%\r\n", + total, used, available, + total ? (used * 100 / total) : 0); + } + } + + // Show named pools + list_for_each_entry(pool, &pool_list, entry) { + if (!pool->name) continue; + + spin_lock(&pool->lock); + + total = 0; + available = 0; + + if (pool->startip && pool->endip) { + total = pool->endip - pool->startip + 1; + } + + list_for_each_entry(it, &pool->items, entry) { + available++; + } + + used = total - available; + spin_unlock(&pool->lock); + + if (total > 0) { + if (used * 1000 / total % 10 > 5) + cli_sendv(client, "%s\r\n total: %u\r\n used: %u\r\n available: %u\r\n usage: %u.%u%%\r\n", + pool->name, total, used, available, + total ? (used * 100 / total) : 0, + total ? (used * 1000 / total % 10) : 0); + else + cli_sendv(client, "%s\r\n total: %u\r\n used: %u\r\n available: %u\r\n usage: %u%%\r\n", + pool->name, total, used, available, + total ? (used * 100 / total) : 0); + } + } + + return CLI_CMD_OK; +} + +static void show_ippool_help(char * const *fields, int fields_cnt, void *client) +{ + cli_send(client, "show ippool - shows IP pool statistics\r\n"); +} + static void ippool_init2(void) { struct conf_sect_t *s = conf_get_section("ip-pool"); @@ -676,6 +752,8 @@ static void ippool_init2(void) if (triton_module_loaded("radius")) triton_event_register_handler(EV_RADIUS_ACCESS_ACCEPT, (triton_event_func)ev_radius_access_accept); #endif + + cli_register_simple_cmd2(show_ippool_exec, show_ippool_help, 2, "show", "ippool"); } DEFINE_INIT(51, ippool_init1); |
