📄 pana_session.cxx
字号:
msg->avpList().add(causeAvp()); // add notification if any AddNotification(*msg); // auth avp if any if (SecurityAssociation().IsSet()) { SecurityAssociation().AddAuthAvp(*msg); } ACE_DEBUG((LM_INFO, "(%P|%t) TxPTR: S-flag %d, N-flag=%d, seq=%d\n", msg->flags().separate, msg->flags().nap, msg->seq())); // session timer m_Timer.CancelSession(); SendReqMsg(msg);}void PANA_Session::RxPTR(){ /* 7.12 PANA-Termination-Request (PTR) The PANA-Termination-Request (PTR) message is sent either by the PaC or the PAA to terminate a PANA session. PANA-Termination-Request ::= < PANA-Header: 7, REQ > < Session-Id > < Termination-Cause > [ Notification ] * [ AVP ] 0*1 < AUTH > */ std::auto_ptr<PANA_Message> cleanup(AuxVariables(). RxMsgQueue().Dequeue()); PANA_Message &msg = *cleanup; ACE_DEBUG((LM_INFO, "(%P|%t) RxPTR: S-flag %d, N-flag=%d, seq=%d\n", msg.flags().separate, msg.flags().nap, msg.seq())); // process notification ProcessNotification(msg); TxPTA(); // termination cause AAA_UInt32AvpContainerWidget causeAvp(msg.avpList()); diameter_unsigned32_t *cause = causeAvp.GetAvp(PANA_AVPNAME_TERMCAUSE); if (cause) { Disconnect(ACE_NTOHL(*cause)); } else { Disconnect(PANA_TERMCAUSE_ADMINISTRATIVE); }}void PANA_Session::TxPTA(){ /* 7.13 PANA-Termination-Answer (PTA) The PANA-Termination-Answer (PTA) message is sent either by the PaC or the PAA in response to PANA-Termination-Request. PANA-Termination-Answer ::= < PANA-Header: 7 > < Session-Id > [ Notification ] * [ AVP ] 0*1 < AUTH > */ boost::shared_ptr<PANA_Message> msg(new PANA_Message); // Populate header msg->type() = PANA_MTYPE_PTA; msg->seq() = LastRxSeqNum().Value(); // add session id AAA_Utf8AvpWidget sessionIdAvp(PANA_AVPNAME_SESSIONID); sessionIdAvp.Get() = SessionId(); msg->avpList().add(sessionIdAvp()); // add notification if any AddNotification(*msg); // auth avp if any if (SecurityAssociation().IsSet()) { SecurityAssociation().AddAuthAvp(*msg); } ACE_DEBUG((LM_INFO, "(%P|%t) TxPTA: S-flag %d, N-flag=%d, seq=%d\n", msg->flags().separate, msg->flags().nap, msg->seq())); SendAnsMsg(msg);}void PANA_Session::RxPTA(){ /* 7.13 PANA-Termination-Answer (PTA) The PANA-Termination-Answer (PTA) message is sent either by the PaC or the PAA in response to PANA-Termination-Request. PANA-Termination-Answer ::= < PANA-Header: 7 > < Session-Id > [ Notification ] * [ AVP ] 0*1 < AUTH > */ std::auto_ptr<PANA_Message> cleanup(AuxVariables(). RxMsgQueue().Dequeue()); PANA_Message &msg = *cleanup; ACE_DEBUG((LM_INFO, "(%P|%t) RxPTA: S-flag %d, N-flag=%d, seq=%d\n", msg.flags().separate, msg.flags().nap, msg.seq())); // process notification ProcessNotification(msg); Disconnect(PANA_TERMCAUSE_LOGOUT);}void PANA_Session::TxPER(diameter_unsigned32_t rcode){ /* 7.14 PANA-Error-Request (PER) The PANA-Error-Request (PER) message is sent either by the PaC or the PAA to report an error with the last received PANA message. PANA-Error-Request ::= < PANA-Header: 8, REQ > < Session-Id > < Result-Code > * [ Failed-AVP ] [ Notification ] * [ AVP ] 0*1 < AUTH > */ boost::shared_ptr<PANA_Message> msg(new PANA_Message); // Populate header msg->type() = PANA_MTYPE_PER; msg->flags().request = true; // adjust serial num ++ LastTxSeqNum(); msg->seq() = LastTxSeqNum().Value(); // add session id AAA_Utf8AvpWidget sessionIdAvp(PANA_AVPNAME_SESSIONID); sessionIdAvp.Get() = SessionId(); msg->avpList().add(sessionIdAvp()); // add result-code AAA_UInt32AvpWidget rcodeAvp(PANA_AVPNAME_RESULTCODE); rcodeAvp.Get() = ACE_HTONL(rcode); msg->avpList().add(rcodeAvp()); // TBD: Add Failed-AVP // add notification if any AddNotification(*msg); // auth avp if (SecurityAssociation().IsSet()) { SecurityAssociation().AddAuthAvp(*msg); } ACE_DEBUG((LM_INFO, "(%P|%t) TxPER: [RCODE=%d] S-flag %d, N-flag=%d, seq=%d\n", rcode, msg->flags().separate, msg->flags().nap, msg->seq())); SendReqMsg(msg);}void PANA_Session::RxPER(){ /* 7.14 PANA-Error-Request (PER) The PANA-Error-Request (PER) message is sent either by the PaC or the PAA to report an error with the last received PANA message. PANA-Error-Request ::= < PANA-Header: 8, REQ > < Session-Id > < Result-Code > * [ Failed-AVP ] [ Notification ] * [ AVP ] 0*1 < AUTH > */ std::auto_ptr<PANA_Message> cleanup(AuxVariables(). RxMsgQueue().Dequeue()); PANA_Message &msg = *cleanup; ACE_DEBUG((LM_INFO, "(%P|%t) RxPER: S-flag %d, N-flag=%d, seq=%d\n", msg.flags().separate, msg.flags().nap, msg.seq())); // process notification ProcessNotification(msg); // result-code AAA_UInt32AvpContainerWidget rcodeAvp(msg.avpList()); diameter_unsigned32_t *rcode = rcodeAvp.GetAvp(PANA_AVPNAME_RESULTCODE); if (rcode == NULL) { throw (PANA_Exception(PANA_Exception::FAILED, "No Result-Code AVP in PER message")); } Error(ACE_NTOHL(*rcode)); // TBD: Process Failed-AVP }void PANA_Session::TxPEA(){ /* 7.15 PANA-Error-Answer (PEA) The PANA-Error-Answer (PEA) message is sent in response to a PANA- Error-Request. PANA-Error-Answer ::= < PANA-Header: 8 > < Session-Id > [ Notification ] * [ AVP ] 0*1 < AUTH > */ boost::shared_ptr<PANA_Message> msg(new PANA_Message); // Populate header msg->type() = PANA_MTYPE_PEA; msg->seq() = LastRxSeqNum().Value(); // add session id AAA_Utf8AvpWidget sessionIdAvp(PANA_AVPNAME_SESSIONID); sessionIdAvp.Get() = SessionId(); msg->avpList().add(sessionIdAvp()); // add notification if any AddNotification(*msg); ACE_DEBUG((LM_INFO, "(%P|%t) TxPEA: S-flag %d, N-flag=%d, seq=%d\n", msg->flags().separate, msg->flags().nap, msg->seq())); SendAnsMsg(msg);}void PANA_Session::RxPEA(bool fatal){ /* 7.15 PANA-Error-Answer (PEA) The PANA-Error-Answer (PEA) message is sent in response to a PANA- Error-Request. PANA-Error-Answer ::= < PANA-Header: 8 > < Session-Id > [ Notification ] * [ AVP ] 0*1 < AUTH > */ std::auto_ptr<PANA_Message> cleanup(AuxVariables(). RxMsgQueue().Dequeue()); PANA_Message &msg = *cleanup; ACE_DEBUG((LM_INFO, "(%P|%t) RxPEA: S-flag %d, N-flag=%d, seq=%d\n", msg.flags().separate, msg.flags().nap, msg.seq())); // process notification ProcessNotification(msg); m_Timer.CancelTxRetry(); if (fatal) { Disconnect(); }}void PANA_Session::RxValidateMsg(PANA_Message &msg, bool skipAuth){ bool doUpdate = true; // validate seq number if (msg.flags().request) { if (LastRxSeqNum() == 0) { // update the seq number LastRxSeqNum() = msg.seq(); doUpdate = false; } else if (LastRxSeqNum() == msg.seq()) { if (msg.type() == CachedAnsMsg()->type()) { // re-transmitt cached answer message TxLastAnsMsg(); throw (PANA_Exception(PANA_Exception::INVALID_MESSAGE, "Re-transmitting answer message")); } else { throw (PANA_Exception(PANA_Exception::INVALID_MESSAGE, "unexpected request msg with invalid seq number")); } } else if (msg.seq() != (LastRxSeqNum().Value() + 1)) { throw (PANA_Exception(PANA_Exception::INVALID_MESSAGE, "request msg with invalid seq number")); } } else if (msg.seq() != LastTxSeqNum().Value()) { throw (PANA_Exception(PANA_Exception::INVALID_MESSAGE, "answer msg with invalid seq number")); } // validate auth-avp if (! skipAuth) { AAA_StringAvpContainerWidget authAvp(msg.avpList()); if (authAvp.GetAvp(PANA_AVPNAME_AUTH) && SecurityAssociation().IsSet()) { if (SecurityAssociation().ValidateAuthAvp(msg) == false) { throw (PANA_Exception(PANA_Exception::INVALID_MESSAGE, "PANA session received msg with invalid AUTH value")); } ACE_DEBUG((LM_INFO, "(%P|%t) Auth validated\n")); } } // verify the session id AAA_Utf8AvpContainerWidget sessionIdAvp(msg.avpList()); diameter_utf8string_t *sid = sessionIdAvp.GetAvp(PANA_AVPNAME_SESSIONID); if (sid) { if (ACE_OS::memcmp(SessionId().data(), sid->data(), sid->size())) { throw (PANA_Exception(PANA_Exception::INVALID_MESSAGE, "Received invalid session id")); } } // wait till all validation happens before // we update seq number if (msg.flags().request && doUpdate) { ++ LastRxSeqNum(); }}bool PANA_Session::TxLastReqMsg(){ if (m_Timer.ReScheduleTxRetry()) { ACE_DEBUG((LM_INFO, "(%P|%t) Re-transmitting last request\n")); // reset the master list LastTxReqMsg()->avpList().reset(); // re-send last req msg TxFormatAddress(*LastTxReqMsg()); m_TxChannel.Send(LastTxReqMsg()); return (true); } else { ACE_DEBUG((LM_INFO, "(%P|%t) Re-transmission giving up\n")); m_Timer.ScheduleSession(0); } return (false);}bool PANA_Session::TxLastAnsMsg(){ ACE_DEBUG((LM_INFO, "(%P|%t) Re-transmitting last answer\n")); // reset the master list CachedAnsMsg()->avpList().reset(); // re-transmitt cached answer message TxFormatAddress(*CachedAnsMsg()); m_TxChannel.Send(CachedAnsMsg()); return (true);}void PANA_Session::TxFormatAddress(PANA_Message &msg){}void PANA_Session::AddNotification(PANA_Message& msg){ if (LastTxNotification().size() > 0) { AAA_StringAvpWidget NotificationAvp(PANA_AVPNAME_NOTIFICATION); NotificationAvp.Get() = LastTxNotification(); msg.avpList().add(NotificationAvp()); // reset LastTxNotification() = ""; } }void PANA_Session::ProcessNotification(PANA_Message &msg){ AAA_StringAvpContainerWidget NotificationAvp(msg.avpList()); diameter_octetstring_t *note = NotificationAvp.GetAvp (PANA_AVPNAME_NOTIFICATION); if (note) { ACE_DEBUG((LM_INFO, "(%P|%t) NOTIFICATION: %s\n", note->data())); m_Event.Notification(*note); } }void PANA_Session::SendReqMsg(boost::shared_ptr<PANA_Message> msg, bool useRetransmission) { TxFormatAddress(*msg); m_TxChannel.Send(msg); if (useRetransmission) { m_Timer.ScheduleTxRetry(); LastTxReqMsg()= msg; }}void PANA_Session::SendAnsMsg(boost::shared_ptr<PANA_Message> msg) { TxFormatAddress(*msg); m_TxChannel.Send(msg); CachedAnsMsg() = msg;}void PANA_Session::Reset() { m_SA.Reset(); m_AuxVariables.Reset(); PANA_SessionAttribute::Reset();}void PANA_Session::Disconnect(ACE_UINT32 cause){ ACE_DEBUG((LM_INFO, "(%P|%t) Disconnect: cause=%d\n", cause)); m_Timer.CancelTxRetry(); m_Timer.CancelSession(); m_Timer.CancelEapResponse(); m_Event.Disconnect(cause); Reset();}void PANA_Session::Error(ACE_UINT32 resultCode){ ACE_DEBUG((LM_INFO, "(%P|%t) Error: result-code=%d\n", resultCode)); m_Timer.CancelTxRetry(); m_Timer.CancelSession(); m_Timer.CancelEapResponse(); m_Event.Error(resultCode); Reset();}void PANA_AuxillarySessionVariables::Reset() { m_SeparateAuth = PANA_CFG_GENERAL().m_SeparateAuth; m_NapAuth = false; m_FirstEapResult = 0; m_SessionResumed = false; m_AbortOnFirstEapFailure = PANA_CFG_GENERAL(). m_AbortOnFirstEapFailure; m_Authorized = false; m_AlgorithmIsSet = false; m_CarryDeviceId = (PANA_CFG_PAA().m_CarryDeviceId != 0) ? true : false; while (! RxMsgQueue().Empty()) { std::auto_ptr<PANA_Message> cleanup (RxMsgQueue().Dequeue()); } while (! TxEapMessageQueue().Empty()) { PANA_MsgBlockGuard eapPkt(TxEapMessageQueue().Dequeue()); }}void PANA_SessionAttribute::Reset(){ m_SessionId = ""; m_EpDeviceId.clear(); m_LastTxSeqNum.Reset(); m_LastRxSeqNum = 0; m_ReAuthInterval = PANA_CFG_GENERAL().m_KeepAliveInterval; m_SessionLifetime = PANA_CFG_PAA().m_SessionLifetime; m_ProtectionCapability = PANA_CFG_GENERAL().m_ProtectionCap; m_PPAC = PANA_CFG_GENERAL().m_PPAC; m_DhcpKey = "";}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -