version without broken whitespace attached. An Acct-Session-Id is required on Accounting-On and Accounting-Off forms of Accounting-Request Signed-off-by: Nick Lowe <nick.lowe@xxxxxxxxxxxx> --- src/ap/accounting.c | 10 ++++++++-- src/ap/hostapd.h | 1 + src/ap/ieee802_1x.c | 20 ++++++++++++++++++-- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/ap/accounting.c b/src/ap/accounting.c index 09cd431..babfe2d 100644 --- a/src/ap/accounting.c +++ b/src/ap/accounting.c @@ -399,9 +399,8 @@ int accounting_sta_get_id(struct hostapd_data *hapd, * A high quality random number is required therefore. * This could be be improved by switching to a GUID. */ if (os_get_random((u8 *) &sta->acct_session_id, - sizeof(sta->acct_session_id)) < 0) { + sizeof(sta->acct_session_id)) < 0) return -1; - } return 0; } @@ -462,6 +461,13 @@ static void accounting_report_state(struct hostapd_data *hapd, int on) */ int accounting_init(struct hostapd_data *hapd) { + /* Acct-Session-Id should be globally and temporarily unique. + * A high quality random number is required therefore. + * This could be be improved by switching to a GUID. */ + if (os_get_random((u8 *) &hapd->acct_session_id, + sizeof(hapd->acct_session_id)) < 0) + return -1; + if (radius_client_register(hapd->radius, RADIUS_ACCT, accounting_receive, hapd)) return -1; diff --git a/src/ap/hostapd.h b/src/ap/hostapd.h index 72f8252..b3d702e 100644 --- a/src/ap/hostapd.h +++ b/src/ap/hostapd.h @@ -138,6 +138,7 @@ struct hostapd_data { void *msg_ctx_parent; /* parent interface ctx for wpa_msg() calls */ struct radius_client_data *radius; + u64 acct_session_id; struct radius_das_data *radius_das; struct iapp_data *iapp; diff --git a/src/ap/ieee802_1x.c b/src/ap/ieee802_1x.c index e153f08..5f95a65 100644 --- a/src/ap/ieee802_1x.c +++ b/src/ap/ieee802_1x.c @@ -479,6 +479,7 @@ int add_common_radius_attr(struct hostapd_data *hapd, char buf[128]; struct hostapd_radius_attr *attr; int len; + struct radius_hdr *hdr; if (!hostapd_config_get_radius_attr(req_attr, RADIUS_ATTR_NAS_IP_ADDRESS) && @@ -547,8 +548,23 @@ int add_common_radius_attr(struct hostapd_data *hapd, } #endif /* CONFIG_INTERWORKING */ - if (sta && add_common_radius_sta_attr(hapd, req_attr, sta, msg) < 0) - return -1; + + if (sta) { + if (add_common_radius_sta_attr(hapd, req_attr, sta, msg) < 0) + return -1; + } else { + hdr = radius_msg_get_hdr(msg); + if (hdr->code == RADIUS_CODE_ACCOUNTING_REQUEST && + hapd->acct_session_id) { + os_snprintf(buf, sizeof(buf), "%016lX", + hapd->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; + } + } + } for (attr = req_attr; attr; attr = attr->next) { if (!radius_msg_add_attr(msg, attr->type, -- 2.5.0
From 421da22bf5172200f199a87d284a8d1fbbb34cb3 Mon Sep 17 00:00:00 2001 From: Nick Lowe <nick.lowe@xxxxxxxxxxxx> Date: Mon, 25 Jan 2016 10:43:33 +0000 Subject: [PATCH 4/6] An Acct-Session-Id is required on Accounting-On and Accounting-Off forms of Accounting-Request. Signed-off-by: Nick Lowe <nick.lowe@xxxxxxxxxxxx> --- src/ap/accounting.c | 10 ++++++++-- src/ap/hostapd.h | 1 + src/ap/ieee802_1x.c | 20 ++++++++++++++++++-- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/ap/accounting.c b/src/ap/accounting.c index 09cd431..babfe2d 100644 --- a/src/ap/accounting.c +++ b/src/ap/accounting.c @@ -399,9 +399,8 @@ int accounting_sta_get_id(struct hostapd_data *hapd, * A high quality random number is required therefore. * This could be be improved by switching to a GUID. */ if (os_get_random((u8 *) &sta->acct_session_id, - sizeof(sta->acct_session_id)) < 0) { + sizeof(sta->acct_session_id)) < 0) return -1; - } return 0; } @@ -462,6 +461,13 @@ static void accounting_report_state(struct hostapd_data *hapd, int on) */ int accounting_init(struct hostapd_data *hapd) { + /* Acct-Session-Id should be globally and temporarily unique. + * A high quality random number is required therefore. + * This could be be improved by switching to a GUID. */ + if (os_get_random((u8 *) &hapd->acct_session_id, + sizeof(hapd->acct_session_id)) < 0) + return -1; + if (radius_client_register(hapd->radius, RADIUS_ACCT, accounting_receive, hapd)) return -1; diff --git a/src/ap/hostapd.h b/src/ap/hostapd.h index 72f8252..b3d702e 100644 --- a/src/ap/hostapd.h +++ b/src/ap/hostapd.h @@ -138,6 +138,7 @@ struct hostapd_data { void *msg_ctx_parent; /* parent interface ctx for wpa_msg() calls */ struct radius_client_data *radius; + u64 acct_session_id; struct radius_das_data *radius_das; struct iapp_data *iapp; diff --git a/src/ap/ieee802_1x.c b/src/ap/ieee802_1x.c index e153f08..5f95a65 100644 --- a/src/ap/ieee802_1x.c +++ b/src/ap/ieee802_1x.c @@ -479,6 +479,7 @@ int add_common_radius_attr(struct hostapd_data *hapd, char buf[128]; struct hostapd_radius_attr *attr; int len; + struct radius_hdr *hdr; if (!hostapd_config_get_radius_attr(req_attr, RADIUS_ATTR_NAS_IP_ADDRESS) && @@ -547,8 +548,23 @@ int add_common_radius_attr(struct hostapd_data *hapd, } #endif /* CONFIG_INTERWORKING */ - if (sta && add_common_radius_sta_attr(hapd, req_attr, sta, msg) < 0) - return -1; + + if (sta) { + if (add_common_radius_sta_attr(hapd, req_attr, sta, msg) < 0) + return -1; + } else { + hdr = radius_msg_get_hdr(msg); + if (hdr->code == RADIUS_CODE_ACCOUNTING_REQUEST && + hapd->acct_session_id) { + os_snprintf(buf, sizeof(buf), "%016lX", + hapd->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; + } + } + } for (attr = req_attr; attr; attr = attr->next) { if (!radius_msg_add_attr(msg, attr->type, -- 2.5.0
_______________________________________________ Hostap mailing list Hostap@xxxxxxxxxxxxxxxxxxx http://lists.infradead.org/mailman/listinfo/hostap