kernel_ipsec_t.query_sa() additionally returns the number of processed packets

This commit is contained in:
Martin Willi
2013-03-14 14:20:54 +01:00
parent 003452d18f
commit 7eeeb1c702
9 changed files with 50 additions and 16 deletions
@@ -85,7 +85,8 @@ METHOD(kernel_ipsec_t, update_sa, status_t,
METHOD(kernel_ipsec_t, query_sa, status_t, METHOD(kernel_ipsec_t, query_sa, status_t,
private_kernel_android_ipsec_t *this, host_t *src, host_t *dst, private_kernel_android_ipsec_t *this, host_t *src, host_t *dst,
u_int32_t spi, u_int8_t protocol, mark_t mark, u_int64_t *bytes) u_int32_t spi, u_int8_t protocol, mark_t mark,
u_int64_t *bytes, u_int64_t *packets)
{ {
return NOT_SUPPORTED; return NOT_SUPPORTED;
} }
@@ -70,7 +70,8 @@ METHOD(kernel_ipsec_t, update_sa, status_t,
METHOD(kernel_ipsec_t, query_sa, status_t, METHOD(kernel_ipsec_t, query_sa, status_t,
private_load_tester_ipsec_t *this, host_t *src, host_t *dst, private_load_tester_ipsec_t *this, host_t *src, host_t *dst,
u_int32_t spi, u_int8_t protocol, mark_t mark, u_int64_t *bytes) u_int32_t spi, u_int8_t protocol, mark_t mark,
u_int64_t *bytes, u_int64_t *packets)
{ {
return NOT_SUPPORTED; return NOT_SUPPORTED;
} }
@@ -145,4 +146,3 @@ load_tester_ipsec_t *load_tester_ipsec_create()
return &this->public; return &this->public;
} }
+15 -3
View File
@@ -182,6 +182,16 @@ struct private_child_sa_t {
* last number of outbound bytes * last number of outbound bytes
*/ */
u_int64_t other_usebytes; u_int64_t other_usebytes;
/**
* last number of inbound packets
*/
u_int64_t my_usepackets;
/**
* last number of outbound bytes
*/
u_int64_t other_usepackets;
}; };
/** /**
@@ -413,7 +423,7 @@ METHOD(child_sa_t, create_policy_enumerator, enumerator_t*,
static status_t update_usebytes(private_child_sa_t *this, bool inbound) static status_t update_usebytes(private_child_sa_t *this, bool inbound)
{ {
status_t status = FAILED; status_t status = FAILED;
u_int64_t bytes; u_int64_t bytes, packets;
if (inbound) if (inbound)
{ {
@@ -422,12 +432,13 @@ static status_t update_usebytes(private_child_sa_t *this, bool inbound)
status = hydra->kernel_interface->query_sa(hydra->kernel_interface, status = hydra->kernel_interface->query_sa(hydra->kernel_interface,
this->other_addr, this->my_addr, this->my_spi, this->other_addr, this->my_addr, this->my_spi,
proto_ike2ip(this->protocol), this->mark_in, proto_ike2ip(this->protocol), this->mark_in,
&bytes); &bytes, &packets);
if (status == SUCCESS) if (status == SUCCESS)
{ {
if (bytes > this->my_usebytes) if (bytes > this->my_usebytes)
{ {
this->my_usebytes = bytes; this->my_usebytes = bytes;
this->my_usepackets = packets;
return SUCCESS; return SUCCESS;
} }
return FAILED; return FAILED;
@@ -441,12 +452,13 @@ static status_t update_usebytes(private_child_sa_t *this, bool inbound)
status = hydra->kernel_interface->query_sa(hydra->kernel_interface, status = hydra->kernel_interface->query_sa(hydra->kernel_interface,
this->my_addr, this->other_addr, this->other_spi, this->my_addr, this->other_addr, this->other_spi,
proto_ike2ip(this->protocol), this->mark_out, proto_ike2ip(this->protocol), this->mark_out,
&bytes); &bytes, &packets);
if (status == SUCCESS) if (status == SUCCESS)
{ {
if (bytes > this->other_usebytes) if (bytes > this->other_usebytes)
{ {
this->other_usebytes = bytes; this->other_usebytes = bytes;
this->other_usepackets = packets;
return SUCCESS; return SUCCESS;
} }
return FAILED; return FAILED;
+4 -2
View File
@@ -207,13 +207,15 @@ METHOD(kernel_interface_t, update_sa, status_t,
METHOD(kernel_interface_t, query_sa, status_t, METHOD(kernel_interface_t, query_sa, status_t,
private_kernel_interface_t *this, host_t *src, host_t *dst, private_kernel_interface_t *this, host_t *src, host_t *dst,
u_int32_t spi, u_int8_t protocol, mark_t mark, u_int64_t *bytes) u_int32_t spi, u_int8_t protocol, mark_t mark,
u_int64_t *bytes, u_int64_t *packets)
{ {
if (!this->ipsec) if (!this->ipsec)
{ {
return NOT_SUPPORTED; return NOT_SUPPORTED;
} }
return this->ipsec->query_sa(this->ipsec, src, dst, spi, protocol, mark, bytes); return this->ipsec->query_sa(this->ipsec, src, dst, spi, protocol, mark,
bytes, packets);
} }
METHOD(kernel_interface_t, del_sa, status_t, METHOD(kernel_interface_t, del_sa, status_t,
+2 -1
View File
@@ -194,11 +194,12 @@ struct kernel_interface_t {
* @param protocol protocol for this SA (ESP/AH) * @param protocol protocol for this SA (ESP/AH)
* @param mark optional mark for this SA * @param mark optional mark for this SA
* @param[out] bytes the number of bytes processed by SA * @param[out] bytes the number of bytes processed by SA
* @param[out] packets number of packets processed by SA
* @return SUCCESS if operation completed * @return SUCCESS if operation completed
*/ */
status_t (*query_sa) (kernel_interface_t *this, host_t *src, host_t *dst, status_t (*query_sa) (kernel_interface_t *this, host_t *src, host_t *dst,
u_int32_t spi, u_int8_t protocol, mark_t mark, u_int32_t spi, u_int8_t protocol, mark_t mark,
u_int64_t *bytes); u_int64_t *bytes, u_int64_t *packets);
/** /**
* Delete a previously installed SA from the SAD. * Delete a previously installed SA from the SAD.
+2 -1
View File
@@ -154,11 +154,12 @@ struct kernel_ipsec_t {
* @param protocol protocol for this SA (ESP/AH) * @param protocol protocol for this SA (ESP/AH)
* @param mark optional mark for this SA * @param mark optional mark for this SA
* @param[out] bytes the number of bytes processed by SA * @param[out] bytes the number of bytes processed by SA
* @param[out] packets number of packets processed by SA
* @return SUCCESS if operation completed * @return SUCCESS if operation completed
*/ */
status_t (*query_sa) (kernel_ipsec_t *this, host_t *src, host_t *dst, status_t (*query_sa) (kernel_ipsec_t *this, host_t *src, host_t *dst,
u_int32_t spi, u_int8_t protocol, mark_t mark, u_int32_t spi, u_int8_t protocol, mark_t mark,
u_int64_t *bytes); u_int64_t *bytes, u_int64_t *packets);
/** /**
* Delete a previusly installed SA from the SAD. * Delete a previusly installed SA from the SAD.
@@ -1910,7 +1910,8 @@ METHOD(kernel_ipsec_t, update_sa, status_t,
METHOD(kernel_ipsec_t, query_sa, status_t, METHOD(kernel_ipsec_t, query_sa, status_t,
private_kernel_klips_ipsec_t *this, host_t *src, host_t *dst, private_kernel_klips_ipsec_t *this, host_t *src, host_t *dst,
u_int32_t spi, u_int8_t protocol, mark_t mark, u_int64_t *bytes) u_int32_t spi, u_int8_t protocol, mark_t mark,
u_int64_t *bytes, u_int64_t *packets)
{ {
return NOT_SUPPORTED; /* TODO */ return NOT_SUPPORTED; /* TODO */
} }
@@ -2648,4 +2649,3 @@ kernel_klips_ipsec_t *kernel_klips_ipsec_create()
return &this->public; return &this->public;
} }
@@ -1649,7 +1649,8 @@ static void get_replay_state(private_kernel_netlink_ipsec_t *this,
METHOD(kernel_ipsec_t, query_sa, status_t, METHOD(kernel_ipsec_t, query_sa, status_t,
private_kernel_netlink_ipsec_t *this, host_t *src, host_t *dst, private_kernel_netlink_ipsec_t *this, host_t *src, host_t *dst,
u_int32_t spi, u_int8_t protocol, mark_t mark, u_int64_t *bytes) u_int32_t spi, u_int8_t protocol, mark_t mark,
u_int64_t *bytes, u_int64_t *packets)
{ {
netlink_buf_t request; netlink_buf_t request;
struct nlmsghdr *out = NULL, *hdr; struct nlmsghdr *out = NULL, *hdr;
@@ -1739,7 +1740,14 @@ METHOD(kernel_ipsec_t, query_sa, status_t,
} }
else else
{ {
*bytes = sa->curlft.bytes; if (bytes)
{
*bytes = sa->curlft.bytes;
}
if (packets)
{
*packets = sa->curlft.packets;
}
status = SUCCESS; status = SUCCESS;
} }
memwipe(out, len); memwipe(out, len);
@@ -1767,7 +1767,8 @@ METHOD(kernel_ipsec_t, update_sa, status_t,
METHOD(kernel_ipsec_t, query_sa, status_t, METHOD(kernel_ipsec_t, query_sa, status_t,
private_kernel_pfkey_ipsec_t *this, host_t *src, host_t *dst, private_kernel_pfkey_ipsec_t *this, host_t *src, host_t *dst,
u_int32_t spi, u_int8_t protocol, mark_t mark, u_int64_t *bytes) u_int32_t spi, u_int8_t protocol, mark_t mark,
u_int64_t *bytes, u_int64_t *packets)
{ {
unsigned char request[PFKEY_BUFFER_SIZE]; unsigned char request[PFKEY_BUFFER_SIZE];
struct sadb_msg *msg, *out; struct sadb_msg *msg, *out;
@@ -1816,7 +1817,15 @@ METHOD(kernel_ipsec_t, query_sa, status_t,
free(out); free(out);
return FAILED; return FAILED;
} }
*bytes = response.lft_current->sadb_lifetime_bytes; if (bytes)
{
*bytes = response.lft_current->sadb_lifetime_bytes;
}
if (packets)
{
/* not supported by PF_KEY */
*packets = 0;
}
free(out); free(out);
return SUCCESS; return SUCCESS;