aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjames <james@e7ae566f-a301-0410-adde-c780ea21d3b5>2006-02-10 10:01:46 +0000
committerjames <james@e7ae566f-a301-0410-adde-c780ea21d3b5>2006-02-10 10:01:46 +0000
commit34a507c9ab159a1e56715246c594b93a93d68469 (patch)
tree99a2a001fe9a0e87c5e593f75f1b65146dc90c6a
parentAdded feature to --management-client to confirm connection (diff)
downloadopenvpn-34a507c9ab159a1e56715246c594b93a93d68469.tar.xz
Added "bytecount" command to management interface.
git-svn-id: http://svn.openvpn.net/projects/openvpn/branches/BETA21/openvpn@887 e7ae566f-a301-0410-adde-c780ea21d3b5
-rw-r--r--ChangeLog3
-rw-r--r--configure.ac2
-rw-r--r--forward.c8
-rw-r--r--manage.c25
-rw-r--r--manage.h34
5 files changed, 70 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index a9a0d0e..e38de18 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,11 +3,12 @@ Copyright (C) 2002-2005 OpenVPN Solutions LLC <info@openvpn.net>
$Id$
-2006.01.xx -- Version 2.1-beta9
+2006.xx.xx -- Version 2.1-beta9
* Added --management-client option to connect as a client
to management GUI app rather than be connected to as a
server.
+* Added "bytecount" command to management interface.
2006.01.03 -- Version 2.1-beta8
diff --git a/configure.ac b/configure.ac
index 13d7d32..47c9bea 100644
--- a/configure.ac
+++ b/configure.ac
@@ -25,7 +25,7 @@ dnl Process this file with autoconf to produce a configure script.
AC_PREREQ(2.50)
-AC_INIT([OpenVPN], [2.1_beta8a], [openvpn-users@lists.sourceforge.net], [openvpn])
+AC_INIT([OpenVPN], [2.1_beta8b], [openvpn-users@lists.sourceforge.net], [openvpn])
AM_CONFIG_HEADER(config.h)
AC_CONFIG_SRCDIR(syshead.h)
diff --git a/forward.c b/forward.c
index 4705f44..be041b9 100644
--- a/forward.c
+++ b/forward.c
@@ -686,6 +686,10 @@ process_incoming_link (struct context *c)
{
c->c2.link_read_bytes += c->c2.buf.len;
c->c2.original_recv_size = c->c2.buf.len;
+#ifdef ENABLE_MANAGEMENT
+ if (management)
+ management_bytes_in (management, c->c2.buf.len);
+#endif
}
else
c->c2.original_recv_size = 0;
@@ -1066,6 +1070,10 @@ process_outgoing_link (struct context *c)
{
c->c2.max_send_size_local = max_int (size, c->c2.max_send_size_local);
c->c2.link_write_bytes += size;
+#ifdef ENABLE_MANAGEMENT
+ if (management)
+ management_bytes_out (management, size);
+#endif
}
}
diff --git a/manage.c b/manage.c
index 9c2a178..3fdca46 100644
--- a/manage.c
+++ b/manage.c
@@ -67,6 +67,7 @@ man_help ()
msg (M_CLIENT, "Management Interface for %s", title_string);
msg (M_CLIENT, "Commands:");
msg (M_CLIENT, "auth-retry t : Auth failure retry mode (none,interact,nointeract).");
+ msg (M_CLIENT, "bytecount n : Show bytes in/out, update every n secs (0=off).");
msg (M_CLIENT, "echo [on|off] [N|all] : Like log, but only show messages in echo buffer.");
msg (M_CLIENT, "exit|quit : Close management session.");
msg (M_CLIENT, "help : Print this message.");
@@ -301,6 +302,24 @@ man_status (struct management *man, const int version, struct status_output *so)
}
static void
+man_bytecount (struct management *man, const int update_seconds)
+{
+ man->connection.bytecount_update_seconds = update_seconds;
+}
+
+void
+man_bytecount_output (struct management *man)
+{
+ char in[32];
+ char out[32];
+ /* do in a roundabout way to work around possible mingw or mingw-glibc bug */
+ openvpn_snprintf (in, sizeof (in), counter_format, man->persist.bytes_in);
+ openvpn_snprintf (out, sizeof (out), counter_format, man->persist.bytes_out);
+ msg (M_CLIENT, ">BYTECOUNT:%s,%s", in, out);
+ man->connection.bytecount_last_update = now;
+}
+
+static void
man_kill (struct management *man, const char *victim)
{
struct gc_arena gc = gc_new ();
@@ -744,6 +763,11 @@ man_dispatch_command (struct management *man, struct status_output *so, const ch
{
man_hold (man, p[1]);
}
+ else if (streq (p[0], "bytecount"))
+ {
+ if (man_need (man, p, 1, 0))
+ man_bytecount (man, atoi(p[1]));
+ }
#if 1
else if (streq (p[0], "test"))
{
@@ -840,6 +864,7 @@ man_connection_settings_reset (struct management *man)
man->connection.state_realtime = false;
man->connection.log_realtime = false;
man->connection.echo_realtime = false;
+ man->connection.bytecount_update_seconds = 0;
man->connection.password_verified = false;
man->connection.password_tries = 0;
man->connection.halt = false;
diff --git a/manage.h b/manage.h
index d7ed79c..1a776c3 100644
--- a/manage.h
+++ b/manage.h
@@ -187,6 +187,9 @@ struct man_persist {
bool hold_release;
const char *special_state_msg;
+
+ counter_type bytes_in;
+ counter_type bytes_out;
};
struct man_settings {
@@ -239,6 +242,8 @@ struct man_connection {
bool state_realtime;
bool log_realtime;
bool echo_realtime;
+ int bytecount_update_seconds;
+ time_t bytecount_last_update;
const char *up_query_type;
int up_query_mode;
@@ -347,6 +352,35 @@ void management_echo (struct management *man, const char *string, const bool pul
void management_auth_failure (struct management *man, const char *type);
+/*
+ * These functions drive the bytecount in/out counters.
+ */
+
+void man_bytecount_output (struct management *man);
+
+static inline void
+man_bytecount_possible_output (struct management *man)
+{
+ if (man->connection.bytecount_update_seconds > 0
+ && now >= man->connection.bytecount_last_update
+ + man->connection.bytecount_update_seconds)
+ man_bytecount_output (man);
+}
+
+static inline void
+management_bytes_out (struct management *man, const int size)
+{
+ man->persist.bytes_out += size;
+ man_bytecount_possible_output (man);
+}
+
+static inline void
+management_bytes_in (struct management *man, const int size)
+{
+ man->persist.bytes_in += size;
+ man_bytecount_possible_output (man);
+}
+
#endif
#endif