use better terminology for FNE peer TGID rewriting;

pull/48/head
Bryan Biedenkapp 2 years ago
parent 2226e1e6f7
commit 9bd06b916a

@ -20,8 +20,8 @@ groupVoice:
inclusion: [] inclusion: []
# List of peer IDs excluded for this talkgroup (peers listed here will be ignored for traffic). # List of peer IDs excluded for this talkgroup (peers listed here will be ignored for traffic).
exclusion: [] exclusion: []
# List of peer talkgroup mutations. # List of peer talkgroup rewrites.
mutations: [] rewrite: []
# #
# Source Configuration # Source Configuration
# #
@ -45,8 +45,8 @@ groupVoice:
inclusion: [] inclusion: []
# List of peer IDs excluded for this talkgroup (peers listed here will be ignored for traffic). # List of peer IDs excluded for this talkgroup (peers listed here will be ignored for traffic).
exclusion: [] exclusion: []
# List of peer talkgroup mutations. # List of peer talkgroup rewrites.
mutations: [] rewrite: []
# #
# Source Configuration # Source Configuration
# #
@ -70,9 +70,9 @@ groupVoice:
inclusion: [] inclusion: []
# List of peer IDs excluded for this talkgroup (peers listed here will be ignored for traffic). # List of peer IDs excluded for this talkgroup (peers listed here will be ignored for traffic).
exclusion: [] exclusion: []
# List of peer talkgroup mutations. # List of peer talkgroup rewrites.
mutations: rewrite:
# Network Peer ID to mutate. # Network Peer ID to rewrite this TGID for.
- peerid: 9000990 - peerid: 9000990
# Numerical talkgroup ID number. # Numerical talkgroup ID number.
tgid: 9999 tgid: 9999
@ -99,8 +99,8 @@ groupVoice:
inclusion: [] inclusion: []
# List of peer IDs excluded for this talkgroup (peers listed here will be ignored for traffic). # List of peer IDs excluded for this talkgroup (peers listed here will be ignored for traffic).
exclusion: [] exclusion: []
# List of peer talkgroup mutations. # List of peer talkgroup rewrites.
mutations: [] rewrite: []
# #
# Source Configuration # Source Configuration
# #
@ -122,8 +122,8 @@ groupVoice:
inclusion: [] inclusion: []
# List of peer IDs excluded for this talkgroup (peers listed here will be ignored for traffic). # List of peer IDs excluded for this talkgroup (peers listed here will be ignored for traffic).
exclusion: [] exclusion: []
# List of peer talkgroup mutations. # List of peer talkgroup rewrites.
mutations: [] rewrite: []
# #
# Source Configuration # Source Configuration
# #
@ -145,8 +145,8 @@ groupVoice:
inclusion: [] inclusion: []
# List of peer IDs excluded for this talkgroup (peers listed here will be ignored for traffic). # List of peer IDs excluded for this talkgroup (peers listed here will be ignored for traffic).
exclusion: [] exclusion: []
# List of peer talkgroup mutations. # List of peer talkgroup rewrites.
mutations: [] rewrite: []
# #
# Source Configuration # Source Configuration
# #

@ -271,7 +271,7 @@ TalkgroupRuleGroupVoice TalkgroupRulesLookup::find(uint32_t id, uint8_t slot)
/// <param name="id">Unique identifier for table entry.</param> /// <param name="id">Unique identifier for table entry.</param>
/// <param name="slot">DMR slot this talkgroup is valid on.</param> /// <param name="slot">DMR slot this talkgroup is valid on.</param>
/// <returns>Table entry.</returns> /// <returns>Table entry.</returns>
TalkgroupRuleGroupVoice TalkgroupRulesLookup::findByMutation(uint32_t peerId, uint32_t id, uint8_t slot) TalkgroupRuleGroupVoice TalkgroupRulesLookup::findByRewrite(uint32_t peerId, uint32_t id, uint8_t slot)
{ {
TalkgroupRuleGroupVoice entry; TalkgroupRuleGroupVoice entry;
@ -280,11 +280,11 @@ TalkgroupRuleGroupVoice TalkgroupRulesLookup::findByMutation(uint32_t peerId, ui
auto it = std::find_if(m_groupVoice.begin(), m_groupVoice.end(), auto it = std::find_if(m_groupVoice.begin(), m_groupVoice.end(),
[&](TalkgroupRuleGroupVoice x) [&](TalkgroupRuleGroupVoice x)
{ {
if (x.config().mutation().size() == 0) if (x.config().rewrite().size() == 0)
return false; return false;
auto innerIt = std::find_if(x.config().mutation().begin(), x.config().mutation().end(), auto innerIt = std::find_if(x.config().rewrite().begin(), x.config().rewrite().end(),
[&](TalkgroupRuleMutation y) [&](TalkgroupRuleRewrite y)
{ {
if (slot != 0U) { if (slot != 0U) {
return y.peerId() == peerId && y.tgId() == id && y.tgSlot() == slot; return y.peerId() == peerId && y.tgId() == id && y.tgSlot() == slot;
@ -293,7 +293,7 @@ TalkgroupRuleGroupVoice TalkgroupRulesLookup::findByMutation(uint32_t peerId, ui
return y.peerId() == peerId && y.tgId() == id; return y.peerId() == peerId && y.tgId() == id;
}); });
if (innerIt != x.config().mutation().end()) if (innerIt != x.config().rewrite().end())
return true; return true;
return false; return false;
}); });
@ -367,12 +367,13 @@ bool TalkgroupRulesLookup::load()
uint32_t incCount = groupVoice.config().inclusion().size(); uint32_t incCount = groupVoice.config().inclusion().size();
uint32_t excCount = groupVoice.config().exclusion().size(); uint32_t excCount = groupVoice.config().exclusion().size();
uint32_t rewrCount = groupVoice.config().rewrite().size();
if (incCount > 0 && excCount > 0) { if (incCount > 0 && excCount > 0) {
::LogWarning(LOG_HOST, "Talkgroup (%s) defines both inclusions and exclusions! Inclusions take precedence and exclusions will be ignored.", groupName.c_str()); ::LogWarning(LOG_HOST, "Talkgroup (%s) defines both inclusions and exclusions! Inclusions take precedence and exclusions will be ignored.", groupName.c_str());
} }
::LogInfoEx(LOG_HOST, "Talkgroup NAME: %s SRC_TGID: %u SRC_TS: %u ACTIVE: %u PARROT: %u INCLUSIONS: %u EXCLUSIONS: %u", groupName.c_str(), tgId, tgSlot, active, parrot, incCount, excCount); ::LogInfoEx(LOG_HOST, "Talkgroup NAME: %s SRC_TGID: %u SRC_TS: %u ACTIVE: %u PARROT: %u INCLUSIONS: %u EXCLUSIONS: %u REWRITES: %u", groupName.c_str(), tgId, tgSlot, active, parrot, incCount, excCount, rewrCount);
} }
} }
m_mutex.unlock(); m_mutex.unlock();

@ -81,31 +81,31 @@ namespace lookups
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// Class Declaration // Class Declaration
// Represents an mutation block for a routing rule. // Represents an rewrite block for a routing rule rewrites.
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
class HOST_SW_API TalkgroupRuleMutation { class HOST_SW_API TalkgroupRuleRewrite {
public: public:
/// <summary>Initializes a new insatnce of the TalkgroupRuleMutation class.</summary> /// <summary>Initializes a new insatnce of the TalkgroupRuleRewrite class.</summary>
TalkgroupRuleMutation() : TalkgroupRuleRewrite() :
m_peerId(0U), m_peerId(0U),
m_tgId(0U), m_tgId(0U),
m_tgSlot(0U) m_tgSlot(0U)
{ {
/* stub */ /* stub */
} }
/// <summary>Initializes a new insatnce of the TalkgroupRuleMutation class.</summary> /// <summary>Initializes a new insatnce of the TalkgroupRuleRewrite class.</summary>
/// <param name="node"></param> /// <param name="node"></param>
TalkgroupRuleMutation(yaml::Node& node) : TalkgroupRuleRewrite(yaml::Node& node) :
TalkgroupRuleMutation() TalkgroupRuleRewrite()
{ {
m_peerId = node["peerId"].as<uint32_t>(0U); m_peerId = node["peerId"].as<uint32_t>(0U);
m_tgId = node["tgid"].as<uint32_t>(0U); m_tgId = node["tgid"].as<uint32_t>(0U);
m_tgSlot = (uint8_t)node["slot"].as<uint32_t>(0U); m_tgSlot = (uint8_t)node["slot"].as<uint32_t>(0U);
} }
/// <summary>Equals operator. Copies this TalkgroupRuleMutation to another TalkgroupRuleMutation.</summary> /// <summary>Equals operator. Copies this TalkgroupRuleRewrite to another TalkgroupRuleRewrite.</summary>
virtual TalkgroupRuleMutation& operator=(const TalkgroupRuleMutation& data) virtual TalkgroupRuleRewrite& operator=(const TalkgroupRuleRewrite& data)
{ {
if (this != &data) { if (this != &data) {
m_peerId = data.m_peerId; m_peerId = data.m_peerId;
@ -138,7 +138,7 @@ namespace lookups
m_parrot(false), m_parrot(false),
m_inclusion(), m_inclusion(),
m_exclusion(), m_exclusion(),
m_mutation() m_rewrite()
{ {
/* stub */ /* stub */
} }
@ -166,11 +166,11 @@ namespace lookups
} }
} }
yaml::Node& mutationList = node["mutations"]; yaml::Node& rewriteList = node["rewrite"];
if (mutationList.size() > 0U) { if (rewriteList.size() > 0U) {
for (size_t i = 0; i < mutationList.size(); i++) { for (size_t i = 0; i < rewriteList.size(); i++) {
TalkgroupRuleMutation mutation = TalkgroupRuleMutation(mutationList[i]); TalkgroupRuleRewrite rewrite = TalkgroupRuleRewrite(rewriteList[i]);
m_mutation.push_back(mutation); m_rewrite.push_back(rewrite);
} }
} }
} }
@ -197,8 +197,8 @@ namespace lookups
__PROPERTY_PLAIN(std::vector<uint32_t>, inclusion, inclusion); __PROPERTY_PLAIN(std::vector<uint32_t>, inclusion, inclusion);
/// <summary>List of peer IDs excluded by this rule.</summary> /// <summary>List of peer IDs excluded by this rule.</summary>
__PROPERTY_PLAIN(std::vector<uint32_t>, exclusion, exclusion); __PROPERTY_PLAIN(std::vector<uint32_t>, exclusion, exclusion);
/// <summary>List of mutations performed by this rule.</summary> /// <summary>List of rewrites performed by this rule.</summary>
__PROPERTY_PLAIN(std::vector<TalkgroupRuleMutation>, mutation, mutation); __PROPERTY_PLAIN(std::vector<TalkgroupRuleRewrite>, rewrite, rewrite);
}; };
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
@ -287,8 +287,8 @@ namespace lookups
void eraseEntry(uint32_t id, uint8_t slot); void eraseEntry(uint32_t id, uint8_t slot);
/// <summary>Finds a table entry in this lookup table.</summary> /// <summary>Finds a table entry in this lookup table.</summary>
virtual TalkgroupRuleGroupVoice find(uint32_t id, uint8_t slot = 0U); virtual TalkgroupRuleGroupVoice find(uint32_t id, uint8_t slot = 0U);
/// <summary>Finds a table entry in this lookup table by mutation.</summary> /// <summary>Finds a table entry in this lookup table by rewrite.</summary>
virtual TalkgroupRuleGroupVoice findByMutation(uint32_t peerId, uint32_t id, uint8_t slot = 0U); virtual TalkgroupRuleGroupVoice findByRewrite(uint32_t peerId, uint32_t id, uint8_t slot = 0U);
/// <summary>Flag indicating whether talkgroup ID access control is enabled or not.</summary> /// <summary>Flag indicating whether talkgroup ID access control is enabled or not.</summary>
bool getACL(); bool getACL();

@ -129,8 +129,8 @@ bool TagDMRData::processFrame(const uint8_t* data, uint32_t len, uint32_t peerId
// is this data from a peer connection? // is this data from a peer connection?
if (fromPeer) { if (fromPeer) {
// perform TGID mutations if configured // perform TGID route rewrites if configured
mutateBuffer(buffer, peerId, dmrData, dataType, dstId, slotNo, false); routeRewrite(buffer, peerId, dmrData, dataType, dstId, slotNo, false);
} }
// is the stream valid? // is the stream valid?
@ -254,8 +254,8 @@ bool TagDMRData::processFrame(const uint8_t* data, uint32_t len, uint32_t peerId
::memset(outboundPeerBuffer, 0x00U, len); ::memset(outboundPeerBuffer, 0x00U, len);
::memcpy(outboundPeerBuffer, buffer, len); ::memcpy(outboundPeerBuffer, buffer, len);
// perform TGID mutations if configured // perform TGID route rewrites if configured
mutateBuffer(outboundPeerBuffer, peerId, dmrData, dataType, dstId, slotNo); routeRewrite(outboundPeerBuffer, peerId, dmrData, dataType, dstId, slotNo);
peer.second->writeMaster({ NET_FUNC_PROTOCOL, NET_PROTOCOL_SUBFUNC_DMR }, outboundPeerBuffer, len, pktSeq, streamId); peer.second->writeMaster({ NET_FUNC_PROTOCOL, NET_PROTOCOL_SUBFUNC_DMR }, outboundPeerBuffer, len, pktSeq, streamId);
} }
@ -300,7 +300,7 @@ void TagDMRData::playbackParrot()
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
/// <summary> /// <summary>
/// Helper to mutate the network data buffer. /// Helper to route rewrite the network data buffer.
/// </summary> /// </summary>
/// <param name="buffer"></param> /// <param name="buffer"></param>
/// <param name="peerId">Peer ID</param> /// <param name="peerId">Peer ID</param>
@ -309,20 +309,20 @@ void TagDMRData::playbackParrot()
/// <param name="dstId"></param> /// <param name="dstId"></param>
/// <param name="slotNo"></param> /// <param name="slotNo"></param>
/// <param name="outbound"></param> /// <param name="outbound"></param>
void TagDMRData::mutateBuffer(uint8_t* buffer, uint32_t peerId, dmr::data::Data dmrData, uint8_t dataType, uint32_t dstId, uint32_t slotNo, bool outbound) void TagDMRData::routeRewrite(uint8_t* buffer, uint32_t peerId, dmr::data::Data dmrData, uint8_t dataType, uint32_t dstId, uint32_t slotNo, bool outbound)
{ {
uint32_t mutatedDstId = dstId; uint32_t rewriteDstId = dstId;
uint32_t mutatedSlotNo = slotNo; uint32_t rewriteSlotNo = slotNo;
// does the data require mutation? // does the data require route rewriting?
if (peerMutate(peerId, mutatedDstId, mutatedSlotNo, outbound)) { if (peerRewrite(peerId, rewriteDstId, rewriteSlotNo, outbound)) {
// rewrite destination TGID in the frame // rewrite destination TGID in the frame
__SET_UINT16(mutatedDstId, buffer, 8U); __SET_UINT16(rewriteDstId, buffer, 8U);
// set or clear the e.Slot flag (if 0x80 is set Slot 2 otherwise Slot 1) // set or clear the e.Slot flag (if 0x80 is set Slot 2 otherwise Slot 1)
if (mutatedSlotNo == 2 && (buffer[15U] & 0x80U) == 0x00U) if (rewriteSlotNo == 2 && (buffer[15U] & 0x80U) == 0x00U)
buffer[15U] |= 0x80; buffer[15U] |= 0x80;
if (mutatedSlotNo == 1 && (buffer[15U] & 0x80U) == 0x80U) if (rewriteSlotNo == 1 && (buffer[15U] & 0x80U) == 0x80U)
buffer[15U] = buffer[15U] & ~0x80U; buffer[15U] = buffer[15U] & ~0x80U;
uint8_t data[DMR_FRAME_LENGTH_BYTES + 2U]; uint8_t data[DMR_FRAME_LENGTH_BYTES + 2U];
@ -335,10 +335,10 @@ void TagDMRData::mutateBuffer(uint8_t* buffer, uint32_t peerId, dmr::data::Data
std::unique_ptr<lc::LC> lc = fullLC.decode(data + 2U, dataType); std::unique_ptr<lc::LC> lc = fullLC.decode(data + 2U, dataType);
if (lc == nullptr) { if (lc == nullptr) {
LogWarning(LOG_NET, "DMR Slot %u, bad LC received from the network, replacing", slotNo); LogWarning(LOG_NET, "DMR Slot %u, bad LC received from the network, replacing", slotNo);
lc = new_unique(lc::LC, dmrData.getFLCO(), dmrData.getSrcId(), mutatedDstId); lc = new_unique(lc::LC, dmrData.getFLCO(), dmrData.getSrcId(), rewriteDstId);
} }
lc->setDstId(mutatedDstId); lc->setDstId(rewriteDstId);
// Regenerate the LC data // Regenerate the LC data
fullLC.encode(*lc, data + 2U, dataType); fullLC.encode(*lc, data + 2U, dataType);
@ -353,7 +353,7 @@ void TagDMRData::mutateBuffer(uint8_t* buffer, uint32_t peerId, dmr::data::Data
lc = new_unique(lc::PrivacyLC); lc = new_unique(lc::PrivacyLC);
} }
lc->setDstId(mutatedDstId); lc->setDstId(rewriteDstId);
// Regenerate the LC data // Regenerate the LC data
fullLC.encodePI(*lc, data + 2U); fullLC.encodePI(*lc, data + 2U);
@ -365,27 +365,27 @@ void TagDMRData::mutateBuffer(uint8_t* buffer, uint32_t peerId, dmr::data::Data
} }
/// <summary> /// <summary>
/// Helper to mutate destination ID and slot. /// Helper to route rewrite destination ID and slot.
/// </summary> /// </summary>
/// <param name="peerId">Peer ID</param> /// <param name="peerId">Peer ID</param>
/// <param name="dstId"></param> /// <param name="dstId"></param>
/// <param name="slotNo"></param> /// <param name="slotNo"></param>
/// <param name="outbound"></param> /// <param name="outbound"></param>
bool TagDMRData::peerMutate(uint32_t peerId, uint32_t& dstId, uint32_t& slotNo, bool outbound) bool TagDMRData::peerRewrite(uint32_t peerId, uint32_t& dstId, uint32_t& slotNo, bool outbound)
{ {
lookups::TalkgroupRuleGroupVoice tg; lookups::TalkgroupRuleGroupVoice tg;
if (outbound) { if (outbound) {
tg = m_network->m_tidLookup->find(dstId, slotNo); tg = m_network->m_tidLookup->find(dstId, slotNo);
} }
else { else {
tg = m_network->m_tidLookup->findByMutation(peerId, dstId, slotNo); tg = m_network->m_tidLookup->findByRewrite(peerId, dstId, slotNo);
} }
std::vector<lookups::TalkgroupRuleMutation> mutations = tg.config().mutation(); std::vector<lookups::TalkgroupRuleRewrite> rewrites = tg.config().rewrite();
bool mutated = false; bool rewrote = false;
if (mutations.size() > 0) { if (rewrites.size() > 0) {
for (auto entry : mutations) { for (auto entry : rewrites) {
if (entry.peerId() == peerId) { if (entry.peerId() == peerId) {
if (outbound) { if (outbound) {
dstId = tg.source().tgId(); dstId = tg.source().tgId();
@ -395,13 +395,13 @@ bool TagDMRData::peerMutate(uint32_t peerId, uint32_t& dstId, uint32_t& slotNo,
dstId = entry.tgId(); dstId = entry.tgId();
slotNo = entry.tgSlot(); slotNo = entry.tgSlot();
} }
mutated = true; rewrote = true;
break; break;
} }
} }
} }
return mutated; return rewrote;
} }
/// <summary> /// <summary>

@ -77,10 +77,10 @@ namespace network
bool m_debug; bool m_debug;
/// <summary>Helper to mutate the network data buffer.</summary> /// <summary>Helper to route rewrite the network data buffer.</summary>
void mutateBuffer(uint8_t* buffer, uint32_t peerId, dmr::data::Data dmrData, uint8_t dataType, uint32_t dstId, uint32_t slotNo, bool outbound = true); void routeRewrite(uint8_t* buffer, uint32_t peerId, dmr::data::Data dmrData, uint8_t dataType, uint32_t dstId, uint32_t slotNo, bool outbound = true);
/// <summary>Helper to mutate destination ID and slot.</summary> /// <summary>Helper to route rewrite destination ID and slot.</summary>
bool peerMutate(uint32_t peerId, uint32_t& dstId, uint32_t& slotNo, bool outbound = true); bool peerRewrite(uint32_t peerId, uint32_t& dstId, uint32_t& slotNo, bool outbound = true);
/// <summary>Helper to determine if the peer is permitted for traffic.</summary> /// <summary>Helper to determine if the peer is permitted for traffic.</summary>
bool isPeerPermitted(uint32_t peerId, dmr::data::Data& data, uint32_t streamId); bool isPeerPermitted(uint32_t peerId, dmr::data::Data& data, uint32_t streamId);

@ -104,8 +104,8 @@ bool TagNXDNData::processFrame(const uint8_t* data, uint32_t len, uint32_t peerI
// is this data from a peer connection? // is this data from a peer connection?
if (fromPeer) { if (fromPeer) {
// perform TGID mutations if configured // perform TGID route rewrites if configured
mutateBuffer(buffer, peerId, messageType, dstId, false); routeRewrite(buffer, peerId, messageType, dstId, false);
} }
// is the stream valid? // is the stream valid?
@ -224,8 +224,8 @@ bool TagNXDNData::processFrame(const uint8_t* data, uint32_t len, uint32_t peerI
::memset(outboundPeerBuffer, 0x00U, len); ::memset(outboundPeerBuffer, 0x00U, len);
::memcpy(outboundPeerBuffer, buffer, len); ::memcpy(outboundPeerBuffer, buffer, len);
// perform TGID mutations if configured // perform TGID route rewrites if configured
mutateBuffer(outboundPeerBuffer, peerId, messageType, dstId); routeRewrite(outboundPeerBuffer, peerId, messageType, dstId);
peer.second->writeMaster({ NET_FUNC_PROTOCOL, NET_PROTOCOL_SUBFUNC_NXDN }, outboundPeerBuffer, len, pktSeq, streamId); peer.second->writeMaster({ NET_FUNC_PROTOCOL, NET_PROTOCOL_SUBFUNC_NXDN }, outboundPeerBuffer, len, pktSeq, streamId);
} }
@ -270,45 +270,45 @@ void TagNXDNData::playbackParrot()
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
/// <summary> /// <summary>
/// Helper to mutate the network data buffer. /// Helper to route rewrite the network data buffer.
/// </summary> /// </summary>
/// <param name="buffer"></param> /// <param name="buffer"></param>
/// <param name="peerId">Peer ID</param> /// <param name="peerId">Peer ID</param>
/// <param name="duid"></param> /// <param name="duid"></param>
/// <param name="dstId"></param> /// <param name="dstId"></param>
/// <param name="outbound"></param> /// <param name="outbound"></param>
void TagNXDNData::mutateBuffer(uint8_t* buffer, uint32_t peerId, uint8_t messageType, uint32_t dstId, bool outbound) void TagNXDNData::routeRewrite(uint8_t* buffer, uint32_t peerId, uint8_t messageType, uint32_t dstId, bool outbound)
{ {
uint32_t mutatedDstId = dstId; uint32_t rewriteDstId = dstId;
// does the data require mutation? // does the data require route writing?
if (peerMutate(peerId, mutatedDstId, outbound)) { if (peerRewrite(peerId, rewriteDstId, outbound)) {
// rewrite destination TGID in the frame // rewrite destination TGID in the frame
__SET_UINT16(mutatedDstId, buffer, 8U); __SET_UINT16(rewriteDstId, buffer, 8U);
} }
} }
/// <summary> /// <summary>
/// Helper to mutate destination ID. /// Helper to route rewrite destination ID.
/// </summary> /// </summary>
/// <param name="peerId">Peer ID</param> /// <param name="peerId">Peer ID</param>
/// <param name="dstId"></param> /// <param name="dstId"></param>
/// <param name="outbound"></param> /// <param name="outbound"></param>
bool TagNXDNData::peerMutate(uint32_t peerId, uint32_t& dstId, bool outbound) bool TagNXDNData::peerRewrite(uint32_t peerId, uint32_t& dstId, bool outbound)
{ {
lookups::TalkgroupRuleGroupVoice tg; lookups::TalkgroupRuleGroupVoice tg;
if (outbound) { if (outbound) {
tg = m_network->m_tidLookup->find(dstId); tg = m_network->m_tidLookup->find(dstId);
} }
else { else {
tg = m_network->m_tidLookup->findByMutation(peerId, dstId); tg = m_network->m_tidLookup->findByRewrite(peerId, dstId);
} }
std::vector<lookups::TalkgroupRuleMutation> mutations = tg.config().mutation(); std::vector<lookups::TalkgroupRuleRewrite> rewrites = tg.config().rewrite();
bool mutated = false; bool rewrote = false;
if (mutations.size() > 0) { if (rewrites.size() > 0) {
for (auto entry : mutations) { for (auto entry : rewrites) {
if (entry.peerId() == peerId) { if (entry.peerId() == peerId) {
if (outbound) { if (outbound) {
dstId = tg.source().tgId(); dstId = tg.source().tgId();
@ -316,13 +316,13 @@ bool TagNXDNData::peerMutate(uint32_t peerId, uint32_t& dstId, bool outbound)
else { else {
dstId = entry.tgId(); dstId = entry.tgId();
} }
mutated = true; rewrote = true;
break; break;
} }
} }
} }
return mutated; return rewrote;
} }
/// <summary> /// <summary>

@ -76,10 +76,10 @@ namespace network
bool m_debug; bool m_debug;
/// <summary>Helper to mutate the network data buffer.</summary> /// <summary>Helper to route rewrite the network data buffer.</summary>
void mutateBuffer(uint8_t* buffer, uint32_t peerId, uint8_t messageType, uint32_t dstId, bool outbound = true); void routeRewrite(uint8_t* buffer, uint32_t peerId, uint8_t messageType, uint32_t dstId, bool outbound = true);
/// <summary>Helper to mutate destination ID.</summary> /// <summary>Helper to route rewrite destination ID.</summary>
bool peerMutate(uint32_t peerId, uint32_t& dstId, bool outbound = true); bool peerRewrite(uint32_t peerId, uint32_t& dstId, bool outbound = true);
/// <summary>Helper to determine if the peer is permitted for traffic.</summary> /// <summary>Helper to determine if the peer is permitted for traffic.</summary>
bool isPeerPermitted(uint32_t peerId, nxdn::lc::RTCH& lc, uint8_t messageType, uint32_t streamId); bool isPeerPermitted(uint32_t peerId, nxdn::lc::RTCH& lc, uint8_t messageType, uint32_t streamId);

@ -148,8 +148,8 @@ bool TagP25Data::processFrame(const uint8_t* data, uint32_t len, uint32_t peerId
// is this data from a peer connection? // is this data from a peer connection?
if (fromPeer) { if (fromPeer) {
// perform TGID mutations if configured // perform TGID route rewrites if configured
mutateBuffer(buffer, peerId, duid, dstId, false); routeRewrite(buffer, peerId, duid, dstId, false);
} }
// is the stream valid? // is the stream valid?
@ -267,8 +267,8 @@ bool TagP25Data::processFrame(const uint8_t* data, uint32_t len, uint32_t peerId
::memset(outboundPeerBuffer, 0x00U, len); ::memset(outboundPeerBuffer, 0x00U, len);
::memcpy(outboundPeerBuffer, buffer, len); ::memcpy(outboundPeerBuffer, buffer, len);
// perform TGID mutations if configured // perform TGID route rewrites if configured
mutateBuffer(outboundPeerBuffer, peerId, duid, dstId); routeRewrite(outboundPeerBuffer, peerId, duid, dstId);
peer.second->writeMaster({ NET_FUNC_PROTOCOL, NET_PROTOCOL_SUBFUNC_P25 }, outboundPeerBuffer, len, pktSeq, streamId); peer.second->writeMaster({ NET_FUNC_PROTOCOL, NET_PROTOCOL_SUBFUNC_P25 }, outboundPeerBuffer, len, pktSeq, streamId);
} }
@ -324,7 +324,7 @@ void TagP25Data::playbackParrot()
m_parrotFirstFrame = false; m_parrotFirstFrame = false;
} }
// repeat traffic to the connected peers // repeat traffic to the connected peersmutations
for (auto peer : m_network->m_peers) { for (auto peer : m_network->m_peers) {
m_network->writePeer(peer.first, { NET_FUNC_PROTOCOL, NET_PROTOCOL_SUBFUNC_P25 }, std::get<0>(pkt), std::get<1>(pkt), std::get<2>(pkt), std::get<3>(pkt), false); m_network->writePeer(peer.first, { NET_FUNC_PROTOCOL, NET_PROTOCOL_SUBFUNC_P25 }, std::get<0>(pkt), std::get<1>(pkt), std::get<2>(pkt), std::get<3>(pkt), false);
if (m_network->m_debug) { if (m_network->m_debug) {
@ -344,24 +344,24 @@ void TagP25Data::playbackParrot()
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
/// <summary> /// <summary>
/// Helper to mutate the network data buffer. /// Helper to route rewrite the network data buffer.
/// </summary> /// </summary>
/// <param name="buffer"></param> /// <param name="buffer"></param>
/// <param name="peerId">Peer ID</param> /// <param name="peerId">Peer ID</param>
/// <param name="duid"></param> /// <param name="duid"></param>
/// <param name="dstId"></param> /// <param name="dstId"></param>
/// <param name="outbound"></param> /// <param name="outbound"></param>
void TagP25Data::mutateBuffer(uint8_t* buffer, uint32_t peerId, uint8_t duid, uint32_t dstId, bool outbound) void TagP25Data::routeRewrite(uint8_t* buffer, uint32_t peerId, uint8_t duid, uint32_t dstId, bool outbound)
{ {
uint32_t srcId = __GET_UINT16(buffer, 5U); uint32_t srcId = __GET_UINT16(buffer, 5U);
uint32_t frameLength = buffer[23U]; uint32_t frameLength = buffer[23U];
uint32_t mutatedDstId = dstId; uint32_t rewriteDstId = dstId;
// does the data require mutation? // does the data require route writing?
if (peerMutate(peerId, mutatedDstId, outbound)) { if (peerRewrite(peerId, rewriteDstId, outbound)) {
// rewrite destination TGID in the frame // rewrite destination TGID in the frame
__SET_UINT16(mutatedDstId, buffer, 8U); __SET_UINT16(rewriteDstId, buffer, 8U);
UInt8Array data = std::unique_ptr<uint8_t[]>(new uint8_t[frameLength]); UInt8Array data = std::unique_ptr<uint8_t[]>(new uint8_t[frameLength]);
::memset(data.get(), 0x00U, frameLength); ::memset(data.get(), 0x00U, frameLength);
@ -376,9 +376,9 @@ void TagP25Data::mutateBuffer(uint8_t* buffer, uint32_t peerId, uint8_t duid, ui
case TSBK_IOSP_GRP_VCH: case TSBK_IOSP_GRP_VCH:
{ {
LogMessage(LOG_NET, P25_TSDU_STR ", %s, emerg = %u, encrypt = %u, prio = %u, chNo = %u, srcId = %u, dstId = %u", LogMessage(LOG_NET, P25_TSDU_STR ", %s, emerg = %u, encrypt = %u, prio = %u, chNo = %u, srcId = %u, dstId = %u",
tsbk->toString(true).c_str(), tsbk->getEmergency(), tsbk->getEncrypted(), tsbk->getPriority(), tsbk->getGrpVchNo(), srcId, dstId); tsbk->toString(true).c_str(), tsbk->getEmergency(), tsbk->getEncrypted(), tsbk->getPriority(), tsbk->getGrpVchNo(), srcId, rewriteDstId);
tsbk->setDstId(dstId); tsbk->setDstId(rewriteDstId);
} }
break; break;
} }
@ -409,26 +409,26 @@ void TagP25Data::mutateBuffer(uint8_t* buffer, uint32_t peerId, uint8_t duid, ui
} }
/// <summary> /// <summary>
/// Helper to mutate destination ID. /// Helper to route rewrite destination ID.
/// </summary> /// </summary>
/// <param name="peerId">Peer ID</param> /// <param name="peerId">Peer ID</param>
/// <param name="dstId"></param> /// <param name="dstId"></param>
/// <param name="outbound"></param> /// <param name="outbound"></param>
bool TagP25Data::peerMutate(uint32_t peerId, uint32_t& dstId, bool outbound) bool TagP25Data::peerRewrite(uint32_t peerId, uint32_t& dstId, bool outbound)
{ {
lookups::TalkgroupRuleGroupVoice tg; lookups::TalkgroupRuleGroupVoice tg;
if (outbound) { if (outbound) {
tg = m_network->m_tidLookup->find(dstId); tg = m_network->m_tidLookup->find(dstId);
} }
else { else {
tg = m_network->m_tidLookup->findByMutation(peerId, dstId); tg = m_network->m_tidLookup->findByRewrite(peerId, dstId);
} }
std::vector<lookups::TalkgroupRuleMutation> mutations = tg.config().mutation(); std::vector<lookups::TalkgroupRuleRewrite> rewrites = tg.config().rewrite();
bool mutated = false; bool rewrote = false;
if (mutations.size() > 0) { if (rewrites.size() > 0) {
for (auto entry : mutations) { for (auto entry : rewrites) {
if (entry.peerId() == peerId) { if (entry.peerId() == peerId) {
if (outbound) { if (outbound) {
dstId = tg.source().tgId(); dstId = tg.source().tgId();
@ -436,13 +436,13 @@ bool TagP25Data::peerMutate(uint32_t peerId, uint32_t& dstId, bool outbound)
else { else {
dstId = entry.tgId(); dstId = entry.tgId();
} }
mutated = true; rewrote = true;
break; break;
} }
} }
} }
return mutated; return rewrote;
} }
/// <summary> /// <summary>

@ -83,10 +83,10 @@ namespace network
bool m_debug; bool m_debug;
/// <summary>Helper to mutate the network data buffer.</summary> /// <summary>Helper to route rewrite the network data buffer.</summary>
void mutateBuffer(uint8_t* buffer, uint32_t peerId, uint8_t duid, uint32_t dstId, bool outbound = true); void routeRewrite(uint8_t* buffer, uint32_t peerId, uint8_t duid, uint32_t dstId, bool outbound = true);
/// <summary>Helper to mutate destination ID.</summary> /// <summary>Helper to route rewrite destination ID.</summary>
bool peerMutate(uint32_t peerId, uint32_t& dstId, bool outbound = true); bool peerRewrite(uint32_t peerId, uint32_t& dstId, bool outbound = true);
/// <summary>Helper to determine if the peer is permitted for traffic.</summary> /// <summary>Helper to determine if the peer is permitted for traffic.</summary>
bool isPeerPermitted(uint32_t peerId, p25::lc::LC& control, uint8_t duid, uint32_t streamId); bool isPeerPermitted(uint32_t peerId, p25::lc::LC& control, uint8_t duid, uint32_t streamId);

Loading…
Cancel
Save

Powered by TurnKey Linux.