fixed statistic calcuation for static leases
This commit is contained in:
@@ -87,9 +87,8 @@ Usage:\n\
|
|||||||
name: Name of the pool to resize\n\
|
name: Name of the pool to resize\n\
|
||||||
end: New end address for the pool\n\
|
end: New end address for the pool\n\
|
||||||
\n\
|
\n\
|
||||||
ipsec pool --leases <name> [--filter <filter>] [--utc]\n\
|
ipsec pool --leases [--filter <filter>] [--utc]\n\
|
||||||
Show lease information using filters:\n\
|
Show lease information using filters:\n\
|
||||||
name: Name of the pool to show leases from\n\
|
|
||||||
filter: Filter string containing comma separated key=value filters,\n\
|
filter: Filter string containing comma separated key=value filters,\n\
|
||||||
e.g. [email protected],addr=1.1.1.1\n\
|
e.g. [email protected],addr=1.1.1.1\n\
|
||||||
pool: name of the pool\n\
|
pool: name of the pool\n\
|
||||||
@@ -128,8 +127,8 @@ static void status(void)
|
|||||||
{
|
{
|
||||||
if (!found)
|
if (!found)
|
||||||
{
|
{
|
||||||
printf("%8s %15s %15s %8s %6s %11s %11s\n",
|
printf("%8s %15s %15s %8s %6s %11s %11s\n", "name", "start",
|
||||||
"name", "start", "end", "timeout", "size", "online", "leases");
|
"end", "timeout", "size", "online", "usage");
|
||||||
found = TRUE;
|
found = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,11 +156,12 @@ static void status(void)
|
|||||||
}
|
}
|
||||||
printf("%5d (%2d%%) ", online, online*100/size);
|
printf("%5d (%2d%%) ", online, online*100/size);
|
||||||
/* get number of online or valid lieases */
|
/* get number of online or valid lieases */
|
||||||
lease = db->query(db, "SELECT COUNT(*) FROM addresses JOIN pools "
|
lease = db->query(db, "SELECT COUNT(*) FROM addresses "
|
||||||
"ON addresses.pool = pools.id "
|
"WHERE addresses.pool = ? "
|
||||||
"WHERE pools.id = ? "
|
"AND ((? AND acquired != 0) "
|
||||||
"AND (released = 0 OR released > ? - timeout) ",
|
" OR released = 0 OR released > ?) ",
|
||||||
DB_UINT, id, DB_UINT, time(NULL), DB_UINT);
|
DB_UINT, id, DB_UINT, !timeout,
|
||||||
|
DB_UINT, time(NULL) - timeout, DB_UINT);
|
||||||
if (lease)
|
if (lease)
|
||||||
{
|
{
|
||||||
lease->enumerate(lease, &used);
|
lease->enumerate(lease, &used);
|
||||||
@@ -232,15 +232,18 @@ static void add(char *name, host_t *start, host_t *end, int timeout)
|
|||||||
{ /* run population in a transaction for sqlite */
|
{ /* run population in a transaction for sqlite */
|
||||||
db->execute(db, NULL, "BEGIN TRANSACTION");
|
db->execute(db, NULL, "BEGIN TRANSACTION");
|
||||||
}
|
}
|
||||||
do
|
while (TRUE)
|
||||||
{
|
{
|
||||||
db->execute(db, NULL,
|
db->execute(db, NULL,
|
||||||
"INSERT INTO addresses (pool, address, identity, acquired, released) "
|
"INSERT INTO addresses (pool, address, identity, acquired, released) "
|
||||||
"VALUES (?, ?, ?, ?, ?)",
|
"VALUES (?, ?, ?, ?, ?)",
|
||||||
DB_UINT, id, DB_BLOB, cur_addr, DB_UINT, 0, DB_UINT, 0, DB_UINT, 1);
|
DB_UINT, id, DB_BLOB, cur_addr, DB_UINT, 0, DB_UINT, 0, DB_UINT, 1);
|
||||||
|
if (chunk_equals(cur_addr, end_addr))
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
increment_chunk(cur_addr);
|
increment_chunk(cur_addr);
|
||||||
}
|
}
|
||||||
while (!chunk_equals(cur_addr, end_addr));
|
|
||||||
if (db->get_driver(db) == DB_SQLITE)
|
if (db->get_driver(db) == DB_SQLITE)
|
||||||
{
|
{
|
||||||
db->execute(db, NULL, "END TRANSACTION");
|
db->execute(db, NULL, "END TRANSACTION");
|
||||||
|
|||||||
Reference in New Issue
Block a user