aboutsummaryrefslogtreecommitdiffstats
path: root/src/libipsec/ipsec_sa.c
diff options
context:
space:
mode:
authorMartin Willi <martin@revosec.ch>2013-09-23 12:10:07 +0200
committerMartin Willi <martin@revosec.ch>2013-10-11 10:23:17 +0200
commitb08967d6d8b9377ac5cf375113c345b9b52d4f49 (patch)
tree7df0bd586c72b537411a1b397bffd18f6b732195 /src/libipsec/ipsec_sa.c
parentd7083b65419633a9f3569d71e4461efaa20a262e (diff)
downloadstrongswan-b08967d6d8b9377ac5cf375113c345b9b52d4f49.tar.bz2
strongswan-b08967d6d8b9377ac5cf375113c345b9b52d4f49.tar.xz
libipsec: Support usage statistics and query_sa() on IPsec SAs
Diffstat (limited to 'src/libipsec/ipsec_sa.c')
-rw-r--r--src/libipsec/ipsec_sa.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/libipsec/ipsec_sa.c b/src/libipsec/ipsec_sa.c
index 2ff5cff55..3fbe56240 100644
--- a/src/libipsec/ipsec_sa.c
+++ b/src/libipsec/ipsec_sa.c
@@ -81,6 +81,18 @@ struct private_ipsec_sa_t {
* ESP context
*/
esp_context_t *esp_context;
+
+ /**
+ * Usage statistics
+ */
+ struct {
+ /** last time of use */
+ time_t time;
+ /** number of packets processed */
+ u_int64_t packets;
+ /** number of bytes processed */
+ u_int64_t bytes;
+ } use;
};
METHOD(ipsec_sa_t, get_source, host_t*,
@@ -145,6 +157,32 @@ METHOD(ipsec_sa_t, get_esp_context, esp_context_t*,
return this->esp_context;
}
+METHOD(ipsec_sa_t, get_usestats, void,
+ private_ipsec_sa_t *this, u_int64_t *bytes, u_int64_t *packets,
+ time_t *time)
+{
+ if (bytes)
+ {
+ *bytes = this->use.bytes;
+ }
+ if (packets)
+ {
+ *packets = this->use.packets;
+ }
+ if (time)
+ {
+ *time = this->use.time;
+ }
+}
+
+METHOD(ipsec_sa_t, update_usestats, void,
+ private_ipsec_sa_t *this, u_int32_t bytes)
+{
+ this->use.time = time_monotonic(NULL);
+ this->use.packets++;
+ this->use.bytes += bytes;
+}
+
METHOD(ipsec_sa_t, match_by_spi_dst, bool,
private_ipsec_sa_t *this, u_int32_t spi, host_t *dst)
{
@@ -227,6 +265,8 @@ ipsec_sa_t *ipsec_sa_create(u_int32_t spi, host_t *src, host_t *dst,
.match_by_spi_src_dst = _match_by_spi_src_dst,
.match_by_reqid = _match_by_reqid,
.get_esp_context = _get_esp_context,
+ .get_usestats = _get_usestats,
+ .update_usestats = _update_usestats,
},
.spi = spi,
.src = src->clone(src),