diff --git a/src/RADIUS_Destination.h b/src/RADIUS_Destination.h index 87987edb..ee6c6f01 100644 --- a/src/RADIUS_Destination.h +++ b/src/RADIUS_Destination.h @@ -74,7 +74,7 @@ namespace OpenWifi { } } else if ((Utils::Now() - LastKeepAlive) > Pool_.radsecKeepAlive) { RADIUS::RadiusOutputPacket P(Pool_.authConfig.servers[ServerIndex_].radsecSecret); - P.MakeStatusMessage(); + P.MakeStatusMessage(Pool_.authConfig.servers[ServerIndex_].name); poco_trace(Logger_, fmt::format("{}: Keep-Alive message.", Pool_.authConfig.servers[ServerIndex_].name)); Socket_->sendBytes(P.Data(), P.Len()); LastKeepAlive = Utils::Now(); @@ -115,6 +115,7 @@ namespace OpenWifi { try { auto NumberOfReceivedBytes = Socket_->receiveBytes(Buffer, sizeof(Buffer)); + std::string ReplySource; if (NumberOfReceivedBytes >= 20) { RADIUS::RadiusPacket P(Buffer, NumberOfReceivedBytes); if (P.IsAuthentication()) { @@ -125,11 +126,9 @@ namespace OpenWifi { P.PacketType(), NumberOfReceivedBytes)); AP_WS_Server()->SendRadiusAuthenticationData(SerialNumber, Buffer, NumberOfReceivedBytes); - } else if(P.IsStatusMessageReply()) { - DBGLINE + } else if(P.IsStatusMessageReply(ReplySource)) { poco_debug(Logger_, - fmt::format("{}: Keepalive message received.", SerialNumber)); - DBGLINE + fmt::format("{}: Keepalive message received.", ReplySource)); } else { poco_debug(Logger_, "AUTH packet dropped."); } diff --git a/src/RADIUS_helpers.h b/src/RADIUS_helpers.h index fea5e955..c12d5608 100644 --- a/src/RADIUS_helpers.h +++ b/src/RADIUS_helpers.h @@ -429,17 +429,20 @@ namespace OpenWifi::RADIUS { P_.code == RADIUS::CoA_ACK || P_.code == RADIUS::CoA_NAK); } - inline bool IsStatusMessageReply() { + inline bool IsStatusMessageReply(std::string &ReplySource) { std::string Result; for (const auto &attribute : Attrs_) { if (attribute.type == RADIUS::Attributes::PROXY_STATE) { - DBGLINE std::string Attr33; // format is serial:IP:port:interface Attr33.assign((const char *)(const char *)&P_.attributes[attribute.pos], attribute.len); - DBGLINE - return Attr33 == "status"; + auto Parts = Poco::StringTokenizer(Attr33, ":"); + if(Parts.count() == 2) { + ReplySource = Parts[1]; + return true; + } + return false; } } DBGLINE @@ -1003,12 +1006,13 @@ namespace OpenWifi::RADIUS { public: explicit RadiusOutputPacket(const std::string &Secret) : Secret_(Secret) {} - inline void MakeStatusMessage() { + inline void MakeStatusMessage(const std::string &Source) { P_.code = RADIUS::Status_Server; P_.identifier = std::rand() & 0x00ff; MakeRadiusAuthenticator(P_.authenticator); unsigned char MessageAuthenticator[16]{0}; - AddAttribute(RADIUS::Attributes::PROXY_STATE, 6, (const unsigned char *)"status" ); + std::string FullSource = "status:" + Source; + AddAttribute(RADIUS::Attributes::PROXY_STATE, FullSource.size(), (const unsigned char *)FullSource.c_str()); AddAttribute(RADIUS::Attributes::MESSAGE_AUTHENTICATOR, sizeof(MessageAuthenticator), MessageAuthenticator); // int PktLen = 1 + 1 + 2 + 16 + 1 + 1 + 16 ; @@ -1019,9 +1023,9 @@ namespace OpenWifi::RADIUS { Poco::HMACEngine H(Secret_); H.update((const unsigned char *)&P_, PktLen); auto digest = H.digest(); - int p = 0; + int p = 0, offset = (int)FullSource.size() + 2 ; for (const auto &i : digest) - P_.attributes[8 + 1 + 1 + p++] = i; + P_.attributes[offset + 1 + 1 + p++] = i; } inline void AddAttribute(unsigned char attr, uint8_t len, const unsigned char *data) {