]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
eap-radius: Add unclaimed IPs to Accounting-Stop messages
authorTobias Brunner <tobias@strongswan.org>
Tue, 11 Dec 2018 10:07:05 +0000 (11:07 +0100)
committerTobias Brunner <tobias@strongswan.org>
Tue, 18 Dec 2018 09:28:51 +0000 (10:28 +0100)
Some RADIUS servers may use these to release them early.

src/libcharon/plugins/eap_radius/eap_radius_accounting.c

index 6f35d0861fc8ef4f69dc35032a90c271e5118702..ecb2083c962ed9bba7b01d48f5f2de1567826c79 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015-2017 Tobias Brunner
+ * Copyright (C) 2015-2018 Tobias Brunner
  * HSR Hochschule fuer Technik Rapperswil
  *
  * Copyright (C) 2012 Martin Willi
@@ -17,6 +17,7 @@
  */
 
 #include "eap_radius_accounting.h"
+#include "eap_radius_provider.h"
 #include "eap_radius_plugin.h"
 
 #include <time.h>
@@ -460,6 +461,37 @@ static void add_ike_sa_parameters(private_eap_radius_accounting_t *this,
        enumerator->destroy(enumerator);
 }
 
+/**
+ * Add any unclaimed IP addresses to the message
+ */
+static void add_unclaimed_ips(radius_message_t *message, ike_sa_t *ike_sa)
+{
+       eap_radius_provider_t *provider;
+       enumerator_t *enumerator;
+       host_t *vip;
+
+       provider = eap_radius_provider_get();
+       enumerator = provider->clear_unclaimed(provider,
+                                                                                  ike_sa->get_unique_id(ike_sa));
+       while (enumerator->enumerate(enumerator, &vip))
+       {
+               switch (vip->get_family(vip))
+               {
+                       case AF_INET:
+                               message->add(message, RAT_FRAMED_IP_ADDRESS,
+                                                        vip->get_address(vip));
+                               break;
+                       case AF_INET6:
+                               message->add(message, RAT_FRAMED_IPV6_ADDRESS,
+                                                        vip->get_address(vip));
+                               break;
+                       default:
+                               break;
+               }
+       }
+       enumerator->destroy(enumerator);
+}
+
 /**
  * Add the Class attributes received in the Access-Accept message to the
  * RADIUS accounting message
@@ -790,6 +822,7 @@ static void send_stop(private_eap_radius_accounting_t *this, ike_sa_t *ike_sa)
                                         chunk_create(entry->sid, strlen(entry->sid)));
                add_class_attributes(message, entry);
                add_ike_sa_parameters(this, message, ike_sa);
+               add_unclaimed_ips(message, ike_sa);
 
                value = htonl(entry->usage.bytes.sent);
                message->add(message, RAT_ACCT_OUTPUT_OCTETS, chunk_from_thing(value));
@@ -816,7 +849,6 @@ static void send_stop(private_eap_radius_accounting_t *this, ike_sa_t *ike_sa)
                value = htonl(time_monotonic(NULL) - entry->created);
                message->add(message, RAT_ACCT_SESSION_TIME, chunk_from_thing(value));
 
-
                value = htonl(entry->cause);
                message->add(message, RAT_ACCT_TERMINATE_CAUSE, chunk_from_thing(value));