Do not send Acct-Authentic in Accounting-On/Off
[mech_eap.git] / src / ap / accounting.c
index 7c55146..c4aea40 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * hostapd / RADIUS Accounting
- * Copyright (c) 2002-2009, 2012, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2002-2009, 2012-2015, Jouni Malinen <j@w1.fi>
  *
  * This software may be distributed under the terms of the BSD license.
  * See README for more details.
@@ -76,17 +76,18 @@ static struct radius_msg * accounting_msg(struct hostapd_data *hapd,
                goto fail;
        }
 
-       if (!hostapd_config_get_radius_attr(hapd->conf->radius_acct_req_attr,
-                                           RADIUS_ATTR_ACCT_AUTHENTIC) &&
-           !radius_msg_add_attr_int32(msg, RADIUS_ATTR_ACCT_AUTHENTIC,
-                                      hapd->conf->ieee802_1x ?
-                                      RADIUS_ACCT_AUTHENTIC_RADIUS :
-                                      RADIUS_ACCT_AUTHENTIC_LOCAL)) {
-               wpa_printf(MSG_INFO, "Could not add Acct-Authentic");
-               goto fail;
-       }
-
        if (sta) {
+               if (!hostapd_config_get_radius_attr(
+                           hapd->conf->radius_acct_req_attr,
+                           RADIUS_ATTR_ACCT_AUTHENTIC) &&
+                   !radius_msg_add_attr_int32(msg, RADIUS_ATTR_ACCT_AUTHENTIC,
+                                              hapd->conf->ieee802_1x ?
+                                              RADIUS_ACCT_AUTHENTIC_RADIUS :
+                                              RADIUS_ACCT_AUTHENTIC_LOCAL)) {
+                       wpa_printf(MSG_INFO, "Could not add Acct-Authentic");
+                       goto fail;
+               }
+
                /* Use 802.1X identity if available */
                val = ieee802_1x_get_identity(sta->eapol_sm, &len);
 
@@ -147,6 +148,15 @@ static struct radius_msg * accounting_msg(struct hostapd_data *hapd,
                        wpa_printf(MSG_ERROR, "Could not add CUI from ACL");
                        goto fail;
                }
+
+               if (sta->ipaddr &&
+                   !radius_msg_add_attr_int32(msg,
+                                              RADIUS_ATTR_FRAMED_IP_ADDRESS,
+                                              be_to_host32(sta->ipaddr))) {
+                       wpa_printf(MSG_ERROR,
+                                  "Could not add Framed-IP-Address");
+                       goto fail;
+               }
        }
 
        return msg;
@@ -437,14 +447,6 @@ static void accounting_report_state(struct hostapd_data *hapd, int on)
        if (!msg)
                return;
 
-       if (!radius_msg_add_attr_int32(msg, RADIUS_ATTR_ACCT_TERMINATE_CAUSE,
-                                      RADIUS_ACCT_TERMINATE_CAUSE_NAS_REBOOT))
-       {
-               wpa_printf(MSG_INFO, "Could not add Acct-Terminate-Cause");
-               radius_msg_free(msg);
-               return;
-       }
-
        if (radius_client_send(hapd->radius, msg, RADIUS_ACCT, NULL) < 0)
                radius_msg_free(msg);
 }
@@ -459,10 +461,14 @@ int accounting_init(struct hostapd_data *hapd)
 {
        struct os_time now;
 
-       /* Acct-Session-Id should be unique over reboots. If reliable clock is
-        * not available, this could be replaced with reboot counter, etc. */
+       /* Acct-Session-Id should be unique over reboots. Using a random number
+        * is preferred. If that is not available, take the current time. Mix
+        * in microseconds to make this more likely to be unique. */
        os_get_time(&now);
-       hapd->acct_session_id_hi = now.sec;
+       if (os_get_random((u8 *) &hapd->acct_session_id_hi,
+                         sizeof(hapd->acct_session_id_hi)) < 0)
+               hapd->acct_session_id_hi = now.sec;
+       hapd->acct_session_id_hi ^= now.usec;
 
        if (radius_client_register(hapd->radius, RADIUS_ACCT,
                                   accounting_receive, hapd))
@@ -475,7 +481,7 @@ int accounting_init(struct hostapd_data *hapd)
 
 
 /**
- * accounting_deinit: Deinitilize accounting
+ * accounting_deinit: Deinitialize accounting
  * @hapd: hostapd BSS data
  */
 void accounting_deinit(struct hostapd_data *hapd)