Add a "resetcounters" command to ipsec, clearing global or connection counters

This commit is contained in:
Martin Willi
2013-03-15 10:55:22 +01:00
parent d022322bed
commit cf729248b2
8 changed files with 53 additions and 14 deletions
+6 -9
View File
@@ -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);
+1
View File
@@ -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
+1
View File
@@ -66,3 +66,4 @@ leases, STROKE_LEASES
memusage, STROKE_MEMUSAGE
user-creds, STROKE_USER_CREDS
listcounters, STROKE_COUNTERS
resetcounters, STROKE_COUNTERS_RESET
+3 -1
View File
@@ -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;
};