diff mbox

Only send Acct-Session-Id and Connect-Info in Accounting-Requests

Message ID CAGnO3doszE7kJ9UGe5QCq=jvf26zjVm5k7um8r=jYOOeMeN03g@mail.gmail.com
State Rejected
Headers show

Commit Message

Nick Lowe Jan. 25, 2016, 1:07 p.m. UTC
Version without broken whitespace attached.

Only send Acct-Session-Id and Connect-Info in Accounting-Requests

Signed-off-by: Nick Lowe <nick.lowe@lugatech.com>
---
 src/ap/ieee802_1x.c | 29 +++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)

                         RADIUS_ATTR_NAS_PORT) &&
@@ -430,22 +431,26 @@ static int add_common_radius_sta_attr(struct
hostapd_data *hapd,
                 radius_mode_txt(hapd));
         buf[sizeof(buf) - 1] = '\0';
     }
-    if (!hostapd_config_get_radius_attr(req_attr,
-                        RADIUS_ATTR_CONNECT_INFO) &&
-        !radius_msg_add_attr(msg, RADIUS_ATTR_CONNECT_INFO,
-                 (u8 *) buf, os_strlen(buf))) {
-        wpa_printf(MSG_ERROR, "Could not add Connect-Info");
-        return -1;
-    }

-    if (sta->acct_session_id) {
-        os_snprintf(buf, sizeof(buf), "%016lX",
-                sta->acct_session_id);
-        if (!radius_msg_add_attr(msg, RADIUS_ATTR_ACCT_SESSION_ID,
+    hdr = radius_msg_get_hdr(msg);
+    if (hdr->code == RADIUS_CODE_ACCOUNTING_REQUEST) {
+        if (!hostapd_config_get_radius_attr(req_attr,
+                            RADIUS_ATTR_CONNECT_INFO) &&
+            !radius_msg_add_attr(msg, RADIUS_ATTR_CONNECT_INFO,
                      (u8 *) buf, os_strlen(buf))) {
-            wpa_printf(MSG_ERROR, "Could not add Acct-Session-Id");
+            wpa_printf(MSG_ERROR, "Could not add Connect-Info");
             return -1;
         }
+
+        if (sta->acct_session_id) {
+            os_snprintf(buf, sizeof(buf), "%016lX",
+                    sta->acct_session_id);
+            if (!radius_msg_add_attr(msg, RADIUS_ATTR_ACCT_SESSION_ID,
+                         (u8 *) buf, os_strlen(buf))) {
+                wpa_printf(MSG_ERROR, "Could not add Acct-Session-Id");
+                return -1;
+            }
+        }
     }

 #ifdef CONFIG_IEEE80211R

Comments

Alan DeKok Jan. 25, 2016, 1:19 p.m. UTC | #1
On Jan 25, 2016, at 8:07 AM, Nick Lowe <nick.lowe@lugatech.com> wrote:
> 
> Version without broken whitespace attached.
> 
> Only send Acct-Session-Id and Connect-Info in Accounting-Requests

  These really belong in Access-Requests, too.  They're not forbidden there, and they can help.

  Alan DeKok.
Nick Lowe Jan. 25, 2016, 1:43 p.m. UTC | #2
The Acct-Session-Id isn't actually being sent at the moment in
Access-Requests as it isn't generated until accounting_sta_get_id() is
called.

If we are going to do that, I feel we should also include the
Acct-Multi-Session-Id in the Access-Requests too. Thoughts?

Nick
Alan DeKok Jan. 25, 2016, 1:46 p.m. UTC | #3
On Jan 25, 2016, at 8:43 AM, Nick Lowe <nick.lowe@lugatech.com> wrote:
> 
> The Acct-Session-Id isn't actually being sent at the moment in
> Access-Requests as it isn't generated until accounting_sta_get_id() is
> called.
> 
> If we are going to do that, I feel we should also include the
> Acct-Multi-Session-Id in the Access-Requests too. Thoughts?

  Yes.  My preference would be that NASes include Acct-Session-Id in Access-Request packets.  That way you can safely tie together the Access-Request and subsequent Accounting-Request.  What's done now can only be described as "guessing".

  Alan DeKok.
Nick Lowe Jan. 25, 2016, 1:52 p.m. UTC | #4
Ok, I've reverted this from my local copy and will rework things to
include the Acct-Session-Id and Acct-Multi-Session-Id in
Access-Requests too.

Nick
Nick Lowe Jan. 25, 2016, 2:26 p.m. UTC | #5
Connect-Info is also broken at present as it gives inaccurate
information with 802.11ng, 802.11na and 802.11ac clients

const char *radius_mode_txt(struct hostapd_data *hapd)
{
switch (hapd->iface->conf->hw_mode) {
case HOSTAPD_MODE_IEEE80211AD:
return "802.11ad";
case HOSTAPD_MODE_IEEE80211A:
return "802.11a";
case HOSTAPD_MODE_IEEE80211G:
return "802.11g";
case HOSTAPD_MODE_IEEE80211B:
default:
return "802.11b";
}
}
Nick Lowe Jan. 25, 2016, 3:53 p.m. UTC | #6
Ah, I'm wrong about the Acct-Session-Id being missed from Access-Requests.

More haste less speed!

Nick

On Mon, Jan 25, 2016 at 1:43 PM, Nick Lowe <nick.lowe@lugatech.com> wrote:
> The Acct-Session-Id isn't actually being sent at the moment in
> Access-Requests as it isn't generated until accounting_sta_get_id() is
> called.
>
> If we are going to do that, I feel we should also include the
> Acct-Multi-Session-Id in the Access-Requests too. Thoughts?
>
> Nick
Nick Lowe Jan. 25, 2016, 5:06 p.m. UTC | #7
This patch should not be applied.
diff mbox

Patch

From 032e3fa6ebab90cdb40e1aeadd2d9bebee06b7a1 Mon Sep 17 00:00:00 2001
From: Nick Lowe <nick.lowe@lugatech.com>
Date: Mon, 25 Jan 2016 10:49:33 +0000
Subject: [PATCH 5/6] Only send Acct-Session-Id and Connect-Info in
 Accounting-Requests

Signed-off-by: Nick Lowe <nick.lowe@lugatech.com>
---
 src/ap/ieee802_1x.c | 29 +++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)

diff --git a/src/ap/ieee802_1x.c b/src/ap/ieee802_1x.c
index 5f95a65..041b230 100644
--- a/src/ap/ieee802_1x.c
+++ b/src/ap/ieee802_1x.c
@@ -403,6 +403,7 @@  static int add_common_radius_sta_attr(struct hostapd_data *hapd,
 				      struct radius_msg *msg)
 {
 	char buf[128];
+	struct radius_hdr *hdr;
 
 	if (!hostapd_config_get_radius_attr(req_attr,
 					    RADIUS_ATTR_NAS_PORT) &&
@@ -430,22 +431,26 @@  static int add_common_radius_sta_attr(struct hostapd_data *hapd,
 			    radius_mode_txt(hapd));
 		buf[sizeof(buf) - 1] = '\0';
 	}
-	if (!hostapd_config_get_radius_attr(req_attr,
-					    RADIUS_ATTR_CONNECT_INFO) &&
-	    !radius_msg_add_attr(msg, RADIUS_ATTR_CONNECT_INFO,
-				 (u8 *) buf, os_strlen(buf))) {
-		wpa_printf(MSG_ERROR, "Could not add Connect-Info");
-		return -1;
-	}
 
-	if (sta->acct_session_id) {
-		os_snprintf(buf, sizeof(buf), "%016lX",
-			    sta->acct_session_id);
-		if (!radius_msg_add_attr(msg, RADIUS_ATTR_ACCT_SESSION_ID,
+	hdr = radius_msg_get_hdr(msg);
+	if (hdr->code == RADIUS_CODE_ACCOUNTING_REQUEST) {
+		if (!hostapd_config_get_radius_attr(req_attr,
+							RADIUS_ATTR_CONNECT_INFO) &&
+			!radius_msg_add_attr(msg, RADIUS_ATTR_CONNECT_INFO,
 					 (u8 *) buf, os_strlen(buf))) {
-			wpa_printf(MSG_ERROR, "Could not add Acct-Session-Id");
+			wpa_printf(MSG_ERROR, "Could not add Connect-Info");
 			return -1;
 		}
+
+		if (sta->acct_session_id) {
+			os_snprintf(buf, sizeof(buf), "%016lX",
+					sta->acct_session_id);
+			if (!radius_msg_add_attr(msg, RADIUS_ATTR_ACCT_SESSION_ID,
+						 (u8 *) buf, os_strlen(buf))) {
+				wpa_printf(MSG_ERROR, "Could not add Acct-Session-Id");
+				return -1;
+			}
+		}
 	}
 
 #ifdef CONFIG_IEEE80211R
-- 
2.5.0