📄 aaa_peer_fsm.cxx
字号:
cap.m_VendorSpecificId.push_back(vsid); grouped = vendorSpecificId.GetAvp(AAA_AVPNAME_VENDORAPPID, ndx); } DumpPeerCapabilities();}void AAA_PeerStateMachine::AssembleDW(AAAMessage &msg, bool request){ AAADiameterHeader &h = msg.hdr; ACE_OS::memset(&msg.hdr, 0, sizeof(msg.hdr)); h.ver = AAA_PROTOCOL_VERSION; h.length = 0; h.flags.r = request ? AAA_FLG_SET : AAA_FLG_CLR; h.flags.p = AAA_FLG_CLR; h.flags.e = AAA_FLG_CLR; h.code = AAA_MSGCODE_WATCHDOG; h.appId = AAA_BASE_APPLICATION_ID; MsgIdTxMessage(msg); AAA_IdentityAvpWidget originHost(AAA_AVPNAME_ORIGINHOST); AAA_IdentityAvpWidget originRealm(AAA_AVPNAME_ORIGINREALM); AAA_UInt32AvpWidget originStateId(AAA_AVPNAME_ORIGINSTATEID); originHost.Get() = AAA_CFG_TRANSPORT()->identity; originRealm.Get() = AAA_CFG_TRANSPORT()->realm; originStateId.Get() = AAA_CFG_RUNTIME()->originStateId; msg.acl.add(originHost()); msg.acl.add(originRealm()); msg.acl.add(originStateId());}void AAA_PeerStateMachine::DisassembleDW(AAAMessage &msg){ diameter_identity_t Host; diameter_identity_t Realm; AAA_IdentityAvpContainerWidget originHost(msg.acl); AAA_IdentityAvpContainerWidget originRealm(msg.acl); AAA_UInt32AvpContainerWidget originState(msg.acl); diameter_identity_t *identity = originHost.GetAvp(AAA_AVPNAME_ORIGINHOST); Host.assign((identity) ? identity->data() : "", (identity) ? identity->length() : 0); identity = originRealm.GetAvp(AAA_AVPNAME_ORIGINREALM); Realm.assign((identity) ? identity->data() : "", (identity) ? identity->length() : 0); diameter_unsigned32_t *uint32 = originState.GetAvp(AAA_AVPNAME_ORIGINSTATEID); diameter_unsigned32_t OriginStateId = (uint32) ? *uint32 : 0; AAA_LOG(LM_INFO, "(%P|%t) Watchdog msg from [%s.%s], state=%d, time=%d\n", Host.data(), Realm.data(), OriginStateId, time(0));}void AAA_PeerStateMachine::AssembleDP(AAAMessage &msg, bool request){ AAADiameterHeader &h = msg.hdr; h.ver = AAA_PROTOCOL_VERSION; h.length = 0; h.flags.r = request ? AAA_FLG_SET : AAA_FLG_CLR; h.flags.p = AAA_FLG_CLR; h.flags.e = AAA_FLG_CLR; h.code = AAA_MSGCODE_DISCONNECT_PEER; h.appId = AAA_BASE_APPLICATION_ID; MsgIdTxMessage(msg); AAA_IdentityAvpWidget originHost(AAA_AVPNAME_ORIGINHOST); AAA_IdentityAvpWidget originRealm(AAA_AVPNAME_ORIGINREALM); originHost.Get() = AAA_CFG_TRANSPORT()->identity; originRealm.Get() = AAA_CFG_TRANSPORT()->realm; msg.acl.add(originHost()); msg.acl.add(originRealm());}void AAA_PeerStateMachine::DisassembleDP(AAAMessage &msg){ diameter_identity_t Host; diameter_identity_t Realm; AAA_IdentityAvpContainerWidget originHost(msg.acl); AAA_IdentityAvpContainerWidget originRealm(msg.acl); diameter_identity_t *identity = originHost.GetAvp(AAA_AVPNAME_ORIGINHOST); Host.assign((identity) ? identity->data() : "", (identity) ? identity->length() : 0); identity = originRealm.GetAvp(AAA_AVPNAME_ORIGINREALM); Realm.assign((identity) ? identity->data() : "", (identity) ? identity->length() : 0); AAA_LOG(LM_INFO, "(%P|%t) Disconnect msg from [%s.%s]\n", Host.data(), Realm.data());}void AAA_PeerStateMachine::SendCER(){ /* 5.3.1. Capabilities-Exchange-Request The Capabilities-Exchange-Request (CER), indicated by the Command- Code set to 257 and the Command Flags' 'R' bit set, is sent to exchange local capabilities. Upon detection of a transport failure, this message MUST NOT be sent to an alternate peer. When Diameter is run over SCTP [SCTP], which allows for connections to span multiple interfaces and multiple IP addresses, the Capabilities-Exchange-Request message MUST contain one Host-IP- Address AVP for each potential IP address that MAY be locally used when transmitting Diameter messages. Message Format <CER> ::= < Diameter Header: 257, REQ > { Origin-Host } { Origin-Realm } 1* { Host-IP-Address } { Vendor-Id } { Product-Name } [ Origin-State-Id ] * [ Supported-Vendor-Id ] * [ Auth-Application-Id ] * [ Inband-Security-Id ] * [ Acct-Application-Id ] * [ Vendor-Specific-Application-Id ] [ Firmware-Revision ] * [ AVP ] */ std::auto_ptr<AAAMessage> msg(new AAAMessage); AssembleCE(*msg); if (RawSend(msg, m_Data.m_IOInitiator.get()) == 0) { AAA_LOG(LM_INFO, "(%P|%t) Sent CER\n"); }}void AAA_PeerStateMachine::SendCEA(diameter_unsigned32_t rcode, std::string &message){ /* 5.3.2. Capabilities-Exchange-Answer The Capabilities-Exchange-Answer (CEA), indicated by the Command-Code set to 257 and the Command Flags' 'R' bit cleared, is sent in response to a CER message. When Diameter is run over SCTP [SCTP], which allows connections to span multiple interfaces, hence, multiple IP addresses, the Capabilities-Exchange-Answer message MUST contain one Host-IP-Address AVP for each potential IP address that MAY be locally used when transmitting Diameter messages. Message Format <CEA> ::= < Diameter Header: 257 > { Result-Code } { Origin-Host } { Origin-Realm } 1* { Host-IP-Address } { Vendor-Id } { Product-Name } [ Origin-State-Id ] [ Error-Message ] * [ Failed-AVP ] * [ Supported-Vendor-Id ] * [ Auth-Application-Id ] * [ Inband-Security-Id ] * [ Acct-Application-Id ] * [ Vendor-Specific-Application-Id ] [ Firmware-Revision ] * [ AVP ] */ std::auto_ptr<AAAMessage> msg(new AAAMessage); AssembleCE(*msg, false); AAA_UInt32AvpWidget resultCode(AAA_AVPNAME_RESULTCODE, rcode); msg->acl.add(resultCode()); if (message.length() > 0) { AAA_Utf8AvpWidget errorMsg(AAA_AVPNAME_ERRORMESSAGE); errorMsg.Get() = message.data(); msg->acl.add(errorMsg()); } // check resulting state to determine // which IO to use AAA_IO_Base *io = (state == AAA_PEER_ST_I_OPEN) ? m_Data.m_IOInitiator.get() : m_Data.m_IOResponder.get(); if (RawSend(msg, io) == 0) { AAA_LOG(LM_INFO, "(%P|%t) Sent CEA: rcode=%d\n", rcode); }}void AAA_PeerStateMachine::SendDWR(){ /* 5.5.1. Device-Watchdog-Request The Device-Watchdog-Request (DWR), indicated by the Command-Code set to 280 and the Command Flags' 'R' bit set, is sent to a peer when no traffic has been exchanged between two peers (see Section 5.5.3). Upon detection of a transport failure, this message MUST NOT be sent to an alternate peer. Message Format <DWR> ::= < Diameter Header: 280, REQ > { Origin-Host } { Origin-Realm } [ Origin-State-Id ] */ std::auto_ptr<AAAMessage> msg(new AAAMessage); AssembleDW(*msg); // check resulting state to determine // which IO to use AAA_IO_Base *io = (state == AAA_PEER_ST_I_OPEN) ? m_Data.m_IOInitiator.get() : m_Data.m_IOResponder.get(); if (RawSend(msg, io) < 0) { AAA_LOG(LM_INFO, "(%P|%t) Failed sending DWR\n"); }}void AAA_PeerStateMachine::SendDWA(diameter_unsigned32_t rcode, std::string &message){ /* 5.5.2. Device-Watchdog-Answer The Device-Watchdog-Answer (DWA), indicated by the Command-Code set to 280 and the Command Flags' 'R' bit cleared, is sent as a response to the Device-Watchdog-Request message. Message Format <DWA> ::= < Diameter Header: 280 > { Result-Code } { Origin-Host } { Origin-Realm } [ Error-Message ] * [ Failed-AVP ] [ Original-State-Id ] */ std::auto_ptr<AAAMessage> msg(new AAAMessage); AssembleDW(*msg, false); AAA_UInt32AvpWidget resultCode(AAA_AVPNAME_RESULTCODE, rcode); msg->acl.add(resultCode()); if (message.length() > 0) { AAA_Utf8AvpWidget errorMsg(AAA_AVPNAME_ERRORMESSAGE); errorMsg.Get() = message.data(); msg->acl.add(errorMsg()); } // check resulting state to determine // which IO to use AAA_IO_Base *io = (state == AAA_PEER_ST_I_OPEN) ? m_Data.m_IOInitiator.get() : m_Data.m_IOResponder.get(); if (RawSend(msg, io) < 0) { AAA_LOG(LM_INFO, "(%P|%t) Failed sending DWA: rcode=%d\n", rcode); }}void AAA_PeerStateMachine::SendDPR(bool initiator){ /* 5.4.1. Disconnect-Peer-Request The Disconnect-Peer-Request (DPR), indicated by the Command-Code set to 282 and the Command Flags' 'R' bit set, is sent to a peer to inform its intentions to shutdown the transport connection. Upon detection of a transport failure, this message MUST NOT be sent to an alternate peer. Message Format <DPR> ::= < Diameter Header: 282, REQ > { Origin-Host } { Origin-Realm } { Disconnect-Cause } */ std::auto_ptr<AAAMessage> msg(new AAAMessage); AssembleDP(*msg); AAA_UInt32AvpWidget disCause(AAA_AVPNAME_DISCONNECT_CAUSE); disCause.Get() = diameter_unsigned32_t(m_Data.m_DisconnectCause); msg->acl.add(disCause()); AAA_IO_Base *io = (initiator) ? m_Data.m_IOInitiator.get() : m_Data.m_IOResponder.get(); if (RawSend(msg, io) < 0) { AAA_LOG(LM_INFO, "(%P|%t) Failed sending Disconnect\n"); }}void AAA_PeerStateMachine::SendDPA(bool initiator, diameter_unsigned32_t rcode, std::string &message){ /* 5.4.2. Disconnect-Peer-Answer The Disconnect-Peer-Answer (DPA), indicated by the Command-Code set to 282 and the Command Flags' 'R' bit cleared, is sent as a response to the Disconnect-Peer-Request message. Upon receipt of this message, the transport connection is shutdown. Message Format <DPA> ::= < Diameter Header: 282 > { Result-Code } { Origin-Host } { Origin-Realm } [ Error-Message ] * [ Failed-AVP ] */ std::auto_ptr<AAAMessage> msg(new AAAMessage); AssembleDP(*msg, false); AAA_UInt32AvpWidget resultCode(AAA_AVPNAME_RESULTCODE, rcode); msg->acl.add(resultCode()); if (message.length() > 0) { AAA_Utf8AvpWidget errorMsg(AAA_AVPNAME_ERRORMESSAGE); errorMsg.Get() = message.data(); msg->acl.add(errorMsg()); } AAA_IO_Base *io = (initiator) ? m_Data.m_IOInitiator.get() : m_Data.m_IOResponder.get(); if (RawSend(msg, io) < 0) { AAA_LOG(LM_INFO, "(%P|%t) Failed sending DWA: rcode=%d\n", rcode); }}void AAA_PeerStateMachine::Elect(){ /* 5.6.4. The Election Process The election is performed on the responder. The responder compares the Origin-Host received in the CER sent by its peer with its own Origin-Host. If the local Diameter entity's Origin-Host is higher than the peer's, a Win-Election event is issued locally. The comparison proceeds by considering the shorter OctetString to be padded with zeros so that it length is the same as the length of the longer, then performing an octet-by-octet unsigned comparison with the first octet being most significant. Any remaining octets are assumed to have value 0x80. */ AAA_LOG(LM_DEBUG, "(%P|%t) Election occurring ...\n"); std::string localHost = AAA_CFG_TRANSPORT()->identity; std::string peerHost = m_Data.m_PeerCapabilities.m_Host; if (localHost.length() < peerHost.length()) { localHost += std::string(peerHost.length() - localHost.length(), char(0x80));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -