aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMartin Willi <martin@revosec.ch>2012-02-24 11:12:18 +0100
committerMartin Willi <martin@revosec.ch>2012-02-24 11:12:18 +0100
commitd15ae70c8c08e0d7f0a5ddac245d5fb9eb097cb2 (patch)
treef30e1928dc3d911f79d99604713674e999600139 /src
parentd93f204ca5374fb96a154e57223a53003c4445af (diff)
downloadstrongswan-d15ae70c8c08e0d7f0a5ddac245d5fb9eb097cb2.tar.bz2
strongswan-d15ae70c8c08e0d7f0a5ddac245d5fb9eb097cb2.tar.xz
Refactored construction of RADIUS accounting messages
Diffstat (limited to 'src')
-rw-r--r--src/libcharon/plugins/eap_radius/eap_radius_accounting.c44
1 files changed, 21 insertions, 23 deletions
diff --git a/src/libcharon/plugins/eap_radius/eap_radius_accounting.c b/src/libcharon/plugins/eap_radius/eap_radius_accounting.c
index 1f32a565e..d2e2cb341 100644
--- a/src/libcharon/plugins/eap_radius/eap_radius_accounting.c
+++ b/src/libcharon/plugins/eap_radius/eap_radius_accounting.c
@@ -140,13 +140,30 @@ static bool send_message(private_eap_radius_accounting_t *this,
}
/**
+ * Add common IKE_SA parameters to RADIUS account message
+ */
+static void add_ike_sa_parameters(radius_message_t *message, ike_sa_t *ike_sa)
+{
+ host_t *vip;
+ char buf[64];
+
+ snprintf(buf, sizeof(buf), "%Y", ike_sa->get_other_eap_id(ike_sa));
+ message->add(message, RAT_USER_NAME, chunk_create(buf, strlen(buf)));
+ snprintf(buf, sizeof(buf), "%#H", ike_sa->get_other_host(ike_sa));
+ message->add(message, RAT_CALLING_STATION_ID, chunk_create(buf, strlen(buf)));
+ vip = ike_sa->get_virtual_ip(ike_sa, FALSE);
+ if (vip)
+ {
+ message->add(message, RAT_FRAMED_IP_ADDRESS, vip->get_address(vip));
+ }
+}
+
+/**
* Send an accounting start message
*/
static void send_start(private_eap_radius_accounting_t *this, ike_sa_t *ike_sa)
{
- char buf[64];
radius_message_t *message;
- host_t *vip;
entry_t *entry;
u_int32_t id, value;
@@ -161,15 +178,7 @@ static void send_start(private_eap_radius_accounting_t *this, ike_sa_t *ike_sa)
message->add(message, RAT_ACCT_STATUS_TYPE, chunk_from_thing(value));
message->add(message, RAT_ACCT_SESSION_ID,
chunk_create(entry->sid, strlen(entry->sid)));
- snprintf(buf, sizeof(buf), "%Y", ike_sa->get_other_eap_id(ike_sa));
- message->add(message, RAT_USER_NAME, chunk_create(buf, strlen(buf)));
- snprintf(buf, sizeof(buf), "%#H", ike_sa->get_other_host(ike_sa));
- message->add(message, RAT_CALLING_STATION_ID, chunk_create(buf, strlen(buf)));
- vip = ike_sa->get_virtual_ip(ike_sa, FALSE);
- if (vip)
- {
- message->add(message, RAT_FRAMED_IP_ADDRESS, vip->get_address(vip));
- }
+ add_ike_sa_parameters(message, ike_sa);
if (send_message(this, message))
{
this->mutex->lock(this->mutex);
@@ -188,8 +197,6 @@ static void send_stop(private_eap_radius_accounting_t *this, ike_sa_t *ike_sa)
radius_message_t *message;
entry_t *entry;
u_int32_t id, value;
- host_t *vip;
- char buf[64];
id = ike_sa->get_unique_id(ike_sa);
this->mutex->lock(this->mutex);
@@ -202,16 +209,7 @@ static void send_stop(private_eap_radius_accounting_t *this, ike_sa_t *ike_sa)
message->add(message, RAT_ACCT_STATUS_TYPE, chunk_from_thing(value));
message->add(message, RAT_ACCT_SESSION_ID,
chunk_create(entry->sid, strlen(entry->sid)));
- snprintf(buf, sizeof(buf), "%Y", ike_sa->get_other_eap_id(ike_sa));
- message->add(message, RAT_USER_NAME, chunk_create(buf, strlen(buf)));
- snprintf(buf, sizeof(buf), "%#H", ike_sa->get_other_host(ike_sa));
- message->add(message, RAT_CALLING_STATION_ID,
- chunk_create(buf, strlen(buf)));
- vip = ike_sa->get_virtual_ip(ike_sa, FALSE);
- if (vip)
- {
- message->add(message, RAT_FRAMED_IP_ADDRESS, vip->get_address(vip));
- }
+ add_ike_sa_parameters(message, ike_sa);
value = htonl(entry->sent);
message->add(message, RAT_ACCT_OUTPUT_OCTETS, chunk_from_thing(value));
value = htonl(entry->sent >> 32);