libipsec: Support usage statistics and query_sa() on IPsec SAs

This commit is contained in:
Martin Willi
2013-10-11 10:23:17 +02:00
parent d7083b6541
commit b08967d6d8
5 changed files with 102 additions and 4 deletions
+40
View File
@@ -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),