aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/ipsec/_ipsec.in7
-rw-r--r--src/libcharon/plugins/stroke/stroke_counter.c22
-rw-r--r--src/libcharon/plugins/stroke/stroke_counter.h7
-rw-r--r--src/libcharon/plugins/stroke/stroke_socket.c10
-rw-r--r--src/stroke/stroke.c15
-rw-r--r--src/stroke/stroke_keywords.h1
-rw-r--r--src/stroke/stroke_keywords.txt1
-rw-r--r--src/stroke/stroke_msg.h4
8 files changed, 53 insertions, 14 deletions
diff --git a/src/ipsec/_ipsec.in b/src/ipsec/_ipsec.in
index 8b6ad660d..6b406f6d9 100644
--- a/src/ipsec/_ipsec.in
+++ b/src/ipsec/_ipsec.in
@@ -59,7 +59,8 @@ case "$1" in
echo " listalgs|listpubkeys|listcerts [--utc]"
echo " listcacerts|listaacerts|listocspcerts [--utc]"
echo " listacerts|listgroups|listcainfos [--utc]"
- echo " listcrls|listocsp|listcards|listplugins|listcounters|listall [--utc]"
+ echo " listcrls|listocsp|listcards|listplugins|listall [--utc]"
+ echo " listcounters|resetcounters [name]"
echo " leases [<poolname> [<address>]]"
echo " rereadsecrets|rereadgroups"
echo " rereadcacerts|rereadaacerts|rereadocspcerts"
@@ -149,10 +150,10 @@ leases)
listalgs|listpubkeys|listplugins|\
listcerts|listcacerts|listaacerts|\
listacerts|listgroups|listocspcerts|\
-listcainfos|listcrls|listocsp|listcounters|listall|\
+listcainfos|listcrls|listocsp|listall|\
rereadsecrets|rereadcacerts|rereadaacerts|\
rereadacerts|rereadocspcerts|rereadcrls|\
-rereadall|purgeocsp)
+rereadall|purgeocsp|listcounters|resetcounters)
op="$1"
rc=7
shift
diff --git a/src/libcharon/plugins/stroke/stroke_counter.c b/src/libcharon/plugins/stroke/stroke_counter.c
index e64415f5d..ff4746bf4 100644
--- a/src/libcharon/plugins/stroke/stroke_counter.c
+++ b/src/libcharon/plugins/stroke/stroke_counter.c
@@ -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,
diff --git a/src/libcharon/plugins/stroke/stroke_counter.h b/src/libcharon/plugins/stroke/stroke_counter.h
index b39fcb8dd..fecf39f56 100644
--- a/src/libcharon/plugins/stroke/stroke_counter.h
+++ b/src/libcharon/plugins/stroke/stroke_counter.h
@@ -92,6 +92,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.
*/
void (*destroy)(stroke_counter_t *this);
diff --git a/src/libcharon/plugins/stroke/stroke_socket.c b/src/libcharon/plugins/stroke/stroke_socket.c
index ebb3c723d..7d41682fb 100644
--- a/src/libcharon/plugins/stroke/stroke_socket.c
+++ b/src/libcharon/plugins/stroke/stroke_socket.c
@@ -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;
diff --git a/src/stroke/stroke.c b/src/stroke/stroke.c
index 1be275c28..c8c8e7cf7 100644
--- a/src/stroke/stroke.c
+++ b/src/stroke/stroke.c
@@ -364,13 +364,15 @@ static int user_credentials(char *name, char *user, char *pass)
return send_stroke_msg(&msg);
}
-static int counters(char *name)
+static int counters(int reset, char *name)
{
stroke_msg_t msg;
msg.type = STR_COUNTERS;
msg.length = offsetof(stroke_msg_t, buffer);
msg.counters.name = push_string(&msg, name);
+ msg.counters.reset = reset;
+
return send_stroke_msg(&msg);
}
@@ -605,14 +607,9 @@ int main(int argc, char *argv[])
res = user_credentials(argv[2], argv[3], argc > 4 ? argv[4] : NULL);
break;
case STROKE_COUNTERS:
- if (argc > 2)
- {
- res = counters(argv[2]);
- }
- else
- {
- res = counters(NULL);
- }
+ case STROKE_COUNTERS_RESET:
+ res = counters(token->kw == STROKE_COUNTERS_RESET,
+ argc > 2 ? argv[2] : NULL);
break;
default:
exit_usage(NULL);
diff --git a/src/stroke/stroke_keywords.h b/src/stroke/stroke_keywords.h
index 12abce1d3..f5979a0e5 100644
--- a/src/stroke/stroke_keywords.h
+++ b/src/stroke/stroke_keywords.h
@@ -59,6 +59,7 @@ typedef enum {
STROKE_MEMUSAGE,
STROKE_USER_CREDS,
STROKE_COUNTERS,
+ STROKE_COUNTERS_RESET,
} stroke_keyword_t;
#define STROKE_LIST_FIRST STROKE_LIST_PUBKEYS
diff --git a/src/stroke/stroke_keywords.txt b/src/stroke/stroke_keywords.txt
index 12c590962..5d2ebd9e2 100644
--- a/src/stroke/stroke_keywords.txt
+++ b/src/stroke/stroke_keywords.txt
@@ -66,3 +66,4 @@ leases, STROKE_LEASES
memusage, STROKE_MEMUSAGE
user-creds, STROKE_USER_CREDS
listcounters, STROKE_COUNTERS
+resetcounters, STROKE_COUNTERS_RESET
diff --git a/src/stroke/stroke_msg.h b/src/stroke/stroke_msg.h
index 494acba11..c415a92c3 100644
--- a/src/stroke/stroke_msg.h
+++ b/src/stroke/stroke_msg.h
@@ -223,7 +223,7 @@ struct stroke_msg_t {
STR_MEMUSAGE,
/* set username and password for a connection */
STR_USER_CREDS,
- /* print counters */
+ /* print/reset counters */
STR_COUNTERS,
/* more to come */
} type;
@@ -357,6 +357,8 @@ struct stroke_msg_t {
/* data for STR_COUNTERS */
struct {
+ /* reset or print counters? */
+ int reset;
char *name;
} counters;
};