Add a "resetcounters" command to ipsec, clearing global or connection counters
This commit is contained in:
@@ -336,6 +336,27 @@ METHOD(stroke_counter_t, print, void,
|
||||
}
|
||||
}
|
||||
|
||||
METHOD(stroke_counter_t, reset, void,
|
||||
private_stroke_counter_t *this, char *name)
|
||||
{
|
||||
this->lock->lock(this->lock);
|
||||
if (name)
|
||||
{
|
||||
entry_t *entry;
|
||||
|
||||
entry = this->conns->remove(this->conns, name);
|
||||
if (entry)
|
||||
{
|
||||
destroy_entry(entry);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
memset(&this->counter, 0, sizeof(this->counter));
|
||||
}
|
||||
this->lock->unlock(this->lock);
|
||||
}
|
||||
|
||||
METHOD(stroke_counter_t, destroy, void,
|
||||
private_stroke_counter_t *this)
|
||||
{
|
||||
@@ -370,6 +391,7 @@ stroke_counter_t *stroke_counter_create()
|
||||
.message = _message_hook,
|
||||
},
|
||||
.print = _print,
|
||||
.reset = _reset,
|
||||
.destroy = _destroy,
|
||||
},
|
||||
.conns = hashtable_create((hashtable_hash_t)hash,
|
||||
|
||||
@@ -91,6 +91,13 @@ struct stroke_counter_t {
|
||||
*/
|
||||
void (*print)(stroke_counter_t *this, FILE *out, char *name);
|
||||
|
||||
/**
|
||||
* Reset global or connection specific counters.
|
||||
*
|
||||
* @param name name of connection counters to reset, NULL for global
|
||||
*/
|
||||
void (*reset)(stroke_counter_t *this, char *name);
|
||||
|
||||
/**
|
||||
* Destroy a stroke_counter_t.
|
||||
*/
|
||||
|
||||
@@ -509,7 +509,14 @@ static void stroke_counters(private_stroke_socket_t *this,
|
||||
{
|
||||
pop_string(msg, &msg->counters.name);
|
||||
|
||||
this->counter->print(this->counter, out, msg->counters.name);
|
||||
if (msg->counters.reset)
|
||||
{
|
||||
this->counter->reset(this->counter, msg->counters.name);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->counter->print(this->counter, out, msg->counters.name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -675,6 +682,7 @@ static job_requeue_t process(stroke_job_context_t *ctx)
|
||||
break;
|
||||
case STR_COUNTERS:
|
||||
stroke_counters(this, msg, out);
|
||||
break;
|
||||
default:
|
||||
DBG1(DBG_CFG, "received unknown stroke");
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user