fix issue with the FNE not properly rewriting TGIDs for configured peers (the original implementation was slighly naive in assumptions, the new implementation techincally allows rewrites to *any* peer *from* any peer not just ISSI peers); perform some minor cleanup of the REST classes; revert change in ClientConnection and ServerConnection initializing the m_buffer class variable (hopefully this may fix some strange issues being seen);

pull/48/head
Bryan Biedenkapp 2 years ago
parent af27a13c8c
commit 345495076b

@ -262,7 +262,8 @@ TalkgroupRuleGroupVoice TalkgroupRulesLookup::findByRewrite(uint32_t peerId, uin
if (x.config().rewrite().size() == 0) if (x.config().rewrite().size() == 0)
return false; return false;
auto innerIt = std::find_if(x.config().rewrite().begin(), x.config().rewrite().end(), std::vector<TalkgroupRuleRewrite> rewrite = x.config().rewrite();
auto innerIt = std::find_if(rewrite.begin(), rewrite.end(),
[&](TalkgroupRuleRewrite y) [&](TalkgroupRuleRewrite y)
{ {
if (slot != 0U) { if (slot != 0U) {
@ -272,7 +273,7 @@ TalkgroupRuleGroupVoice TalkgroupRulesLookup::findByRewrite(uint32_t peerId, uin
return y.peerId() == peerId && y.tgId() == id; return y.peerId() == peerId && y.tgId() == id;
}); });
if (innerIt != x.config().rewrite().end()) if (innerIt != rewrite.end())
return true; return true;
return false; return false;
}); });

@ -85,7 +85,7 @@ namespace lookups
TalkgroupRuleRewrite(yaml::Node& node) : TalkgroupRuleRewrite(yaml::Node& node) :
TalkgroupRuleRewrite() 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);
} }
@ -169,6 +169,7 @@ namespace lookups
m_parrot = data.m_parrot; m_parrot = data.m_parrot;
m_inclusion = data.m_inclusion; m_inclusion = data.m_inclusion;
m_exclusion = data.m_exclusion; m_exclusion = data.m_exclusion;
m_rewrite = data.m_rewrite;
} }
return *this; return *this;

@ -38,20 +38,18 @@ namespace network
template <typename RequestHandlerType> template <typename RequestHandlerType>
class ClientConnection { class ClientConnection {
public: public:
auto operator=(ClientConnection&) -> ClientConnection& = delete;
auto operator=(ClientConnection&&) -> ClientConnection& = delete;
ClientConnection(ClientConnection&) = delete;
/// <summary>Initializes a new instance of the ClientConnection class.</summary> /// <summary>Initializes a new instance of the ClientConnection class.</summary>
explicit ClientConnection(asio::ip::tcp::socket socket, RequestHandlerType& handler) : explicit ClientConnection(asio::ip::tcp::socket socket, RequestHandlerType& handler) :
m_socket(std::move(socket)), m_socket(std::move(socket)),
m_requestHandler(handler), m_requestHandler(handler),
m_buffer(),
m_lexer(HTTPLexer(true)) m_lexer(HTTPLexer(true))
{ {
/* stub */ /* stub */
} }
/// <summary>Initializes a copy instance of the ClientConnection class.</summary>
ClientConnection(const ClientConnection&) = delete;
/// <summary></summary>
ClientConnection& operator=(const ClientConnection&) = delete;
/// <summary>Start the first asynchronous operation for the connection.</summary> /// <summary>Start the first asynchronous operation for the connection.</summary>
void start() { read(); } void start() { read(); }
@ -81,7 +79,7 @@ namespace network
{ {
asio::error_code ec = e.code(); asio::error_code ec = e.code();
if (ec) { if (ec) {
::LogError(LOG_REST, "%s, code = %u", ec.message().c_str(), ec.value()); ::LogError(LOG_REST, "ClientConnection::ensureNoLinger(), %s, code = %u", ec.message().c_str(), ec.value());
} }
} }
} }
@ -123,7 +121,7 @@ namespace network
} }
else if (ec != asio::error::operation_aborted) { else if (ec != asio::error::operation_aborted) {
if (ec) { if (ec) {
::LogError(LOG_REST, "%s, code = %u", ec.message().c_str(), ec.value()); ::LogError(LOG_REST, "ClientConnection::read(), %s, code = %u", ec.message().c_str(), ec.value());
} }
stop(); stop();
} }
@ -150,7 +148,9 @@ namespace network
asio::error_code ignored_ec; asio::error_code ignored_ec;
m_socket.shutdown(asio::ip::tcp::socket::shutdown_both, ignored_ec); m_socket.shutdown(asio::ip::tcp::socket::shutdown_both, ignored_ec);
} }
catch(const std::exception& e) { ::LogError(LOG_REST, "%s", ec.message().c_str()); } catch(const std::exception& e) {
::LogError(LOG_REST, "ClientConnection::write(), %s, code = %u", ec.message().c_str(), ec.value());
}
} }
} }
} }

@ -42,6 +42,10 @@ namespace network
template<typename RequestHandlerType, template<class> class ConnectionImpl = ClientConnection> template<typename RequestHandlerType, template<class> class ConnectionImpl = ClientConnection>
class HTTPClient : private Thread { class HTTPClient : private Thread {
public: public:
auto operator=(HTTPClient&) -> HTTPClient& = delete;
auto operator=(HTTPClient&&) -> HTTPClient& = delete;
HTTPClient(HTTPClient&) = delete;
/// <summary>Initializes a new instance of the HTTPClient class.</summary> /// <summary>Initializes a new instance of the HTTPClient class.</summary>
HTTPClient(const std::string& address, uint16_t port) : HTTPClient(const std::string& address, uint16_t port) :
m_address(address), m_address(address),
@ -53,8 +57,6 @@ namespace network
{ {
/* stub */ /* stub */
} }
/// <summary>Initializes a copy instance of the HTTPClient class.</summary>
HTTPClient(const HTTPClient&) = delete;
/// <summary>Finalizes a instance of the HTTPClient class.</summary> /// <summary>Finalizes a instance of the HTTPClient class.</summary>
~HTTPClient() override ~HTTPClient() override
{ {
@ -63,9 +65,6 @@ namespace network
} }
} }
/// <summary></summary>
HTTPClient& operator=(const HTTPClient&) = delete;
/// <summary>Helper to set the HTTP request handlers.</summary> /// <summary>Helper to set the HTTP request handlers.</summary>
template<typename Handler> template<typename Handler>
void setHandler(Handler&& handler) void setHandler(Handler&& handler)

@ -39,15 +39,14 @@ namespace network
class HTTPRequestHandler { class HTTPRequestHandler {
public: public:
auto operator=(HTTPRequestHandler&) -> HTTPRequestHandler& = delete;
HTTPRequestHandler(HTTPRequestHandler&) = delete;
/// <summary>Initializes a new instance of the HTTPRequestHandler class.</summary> /// <summary>Initializes a new instance of the HTTPRequestHandler class.</summary>
explicit HTTPRequestHandler(const std::string& docRoot); explicit HTTPRequestHandler(const std::string& docRoot);
/// <summary>Initializes a copy instance of the HTTPRequestHandler class.</summary>
HTTPRequestHandler(const HTTPRequestHandler&) = delete;
/// <summary></summary> /// <summary></summary>
HTTPRequestHandler(HTTPRequestHandler&&) = default; HTTPRequestHandler(HTTPRequestHandler&&) = default;
/// <summary></summary>
HTTPRequestHandler& operator=(const HTTPRequestHandler&) = delete;
/// <summary></summary> /// <summary></summary>
HTTPRequestHandler& operator=(HTTPRequestHandler&&) = default; HTTPRequestHandler& operator=(HTTPRequestHandler&&) = default;

@ -43,6 +43,10 @@ namespace network
template<typename RequestHandlerType, template<class> class ConnectionImpl = ServerConnection> template<typename RequestHandlerType, template<class> class ConnectionImpl = ServerConnection>
class HTTPServer { class HTTPServer {
public: public:
auto operator=(HTTPServer&) -> HTTPServer& = delete;
auto operator=(HTTPServer&&) -> HTTPServer& = delete;
HTTPServer(HTTPServer&) = delete;
/// <summary>Initializes a new instance of the HTTPServer class.</summary> /// <summary>Initializes a new instance of the HTTPServer class.</summary>
explicit HTTPServer(const std::string& address, uint16_t port) : explicit HTTPServer(const std::string& address, uint16_t port) :
m_ioService(), m_ioService(),
@ -63,11 +67,6 @@ namespace network
accept(); accept();
} }
/// <summary>Initializes a copy instance of the HTTPServer class.</summary>
HTTPServer(const HTTPServer&) = delete;
/// <summary></summary>
HTTPServer& operator=(const HTTPServer&) = delete;
/// <summary>Helper to set the HTTP request handlers.</summary> /// <summary>Helper to set the HTTP request handlers.</summary>
template<typename Handler> template<typename Handler>

@ -49,23 +49,21 @@ namespace network
typedef std::shared_ptr<selfType> selfTypePtr; typedef std::shared_ptr<selfType> selfTypePtr;
typedef ServerConnectionManager<selfTypePtr> ConnectionManagerType; typedef ServerConnectionManager<selfTypePtr> ConnectionManagerType;
public: public:
auto operator=(ServerConnection&) -> ServerConnection& = delete;
auto operator=(ServerConnection&&) -> ServerConnection& = delete;
ServerConnection(ServerConnection&) = delete;
/// <summary>Initializes a new instance of the ServerConnection class.</summary> /// <summary>Initializes a new instance of the ServerConnection class.</summary>
explicit ServerConnection(asio::ip::tcp::socket socket, ConnectionManagerType& manager, RequestHandlerType& handler, explicit ServerConnection(asio::ip::tcp::socket socket, ConnectionManagerType& manager, RequestHandlerType& handler,
bool persistent = false) : bool persistent = false) :
m_socket(std::move(socket)), m_socket(std::move(socket)),
m_connectionManager(manager), m_connectionManager(manager),
m_requestHandler(handler), m_requestHandler(handler),
m_buffer(),
m_lexer(HTTPLexer(false)), m_lexer(HTTPLexer(false)),
m_persistent(persistent) m_persistent(persistent)
{ {
/* stub */ /* stub */
} }
/// <summary>Initializes a copy instance of the ServerConnection class.</summary>
ServerConnection(const ServerConnection&) = delete;
/// <summary></summary>
ServerConnection& operator=(const ServerConnection&) = delete;
/// <summary>Start the first asynchronous operation for the connection.</summary> /// <summary>Start the first asynchronous operation for the connection.</summary>
void start() { read(); } void start() { read(); }
@ -118,7 +116,7 @@ namespace network
} }
else if (ec != asio::error::operation_aborted) { else if (ec != asio::error::operation_aborted) {
if (ec) { if (ec) {
::LogError(LOG_REST, "%s, code = %u", ec.message().c_str(), ec.value()); ::LogError(LOG_REST, "ServerConnection::read(), %s, code = %u", ec.message().c_str(), ec.value());
} }
m_connectionManager.stop(this->shared_from_this()); m_connectionManager.stop(this->shared_from_this());
} }
@ -157,7 +155,7 @@ namespace network
if (ec != asio::error::operation_aborted) { if (ec != asio::error::operation_aborted) {
if (ec) { if (ec) {
::LogError(LOG_REST, "%s, code = %u", ec.message().c_str(), ec.value()); ::LogError(LOG_REST, "ServerConnection::write(), %s, code = %u", ec.message().c_str(), ec.value());
} }
m_connectionManager.stop(this->shared_from_this()); m_connectionManager.stop(this->shared_from_this());
} }

@ -36,13 +36,12 @@ namespace network
template<typename ConnectionPtr> template<typename ConnectionPtr>
class ServerConnectionManager { class ServerConnectionManager {
public: public:
auto operator=(ServerConnectionManager&) -> ServerConnectionManager& = delete;
auto operator=(ServerConnectionManager&&) -> ServerConnectionManager& = delete;
ServerConnectionManager(ServerConnectionManager&) = delete;
/// <summary>Initializes a new instance of the ServerConnectionManager class.</summary> /// <summary>Initializes a new instance of the ServerConnectionManager class.</summary>
ServerConnectionManager() = default; ServerConnectionManager() = default;
/// <summary>Initializes a copy instance of the ServerConnectionManager class.</summary>
ServerConnectionManager(const ServerConnectionManager&) = delete;
/// <summary></summary>
ServerConnectionManager& operator=(const ServerConnectionManager&) = delete;
/// <summary>Add the specified connection to the manager and start it.</summary> /// <summary>Add the specified connection to the manager and start it.</summary>
void start(ConnectionPtr c) void start(ConnectionPtr c)

@ -491,7 +491,7 @@ bool HostFNE::createPeerNetworks()
if (key.size() == 32) { if (key.size() == 32) {
// bryanb: shhhhhhh....dirty nasty hacks // bryanb: shhhhhhh....dirty nasty hacks
key = key.append(key); // since the key is 32 characters (16 hex pairs), double it on itself for 64 characters (32 hex pairs) key = key.append(key); // since the key is 32 characters (16 hex pairs), double it on itself for 64 characters (32 hex pairs)
LogWarning(LOG_HOST, "Half-length peer network preshared encryption key detected, doubling key on itself."); LogWarning(LOG_HOST, "Half-length peer %u network preshared encryption key detected, doubling key on itself.", id);
} }
if (key.size() == 64) { if (key.size() == 64) {
@ -534,7 +534,7 @@ bool HostFNE::createPeerNetworks()
network::PeerNetwork* network = new PeerNetwork(masterAddress, masterPort, 0U, id, password, true, debug, m_dmrEnabled, m_p25Enabled, m_nxdnEnabled, true, true, m_allowActivityTransfer, m_allowDiagnosticTransfer, false); network::PeerNetwork* network = new PeerNetwork(masterAddress, masterPort, 0U, id, password, true, debug, m_dmrEnabled, m_p25Enabled, m_nxdnEnabled, true, true, m_allowActivityTransfer, m_allowDiagnosticTransfer, false);
network->setMetadata(identity, rxFrequency, txFrequency, 0.0F, 0.0F, 0, 0, 0, latitude, longitude, 0, location); network->setMetadata(identity, rxFrequency, txFrequency, 0.0F, 0.0F, 0, 0, 0, latitude, longitude, 0, location);
if (encrypted) { if (encrypted) {
m_network->setPresharedKey(presharedKey); network->setPresharedKey(presharedKey);
} }
network->enable(enabled); network->enable(enabled);
@ -576,7 +576,7 @@ void HostFNE::processPeer(network::PeerNetwork* peerNetwork)
uint32_t slotNo = (data[15U] & 0x80U) == 0x80U ? 2U : 1U; uint32_t slotNo = (data[15U] & 0x80U) == 0x80U ? 2U : 1U;
uint32_t streamId = peerNetwork->getDMRStreamId(slotNo); uint32_t streamId = peerNetwork->getDMRStreamId(slotNo);
m_network->dmrTrafficHandler()->processFrame(data.get(), length, peerId, peerNetwork->pktLastSeq(), streamId, true); m_network->dmrTrafficHandler()->processFrame(data.get(), length, peerId, peerNetwork->pktLastSeq(), streamId);
} }
} }
@ -589,7 +589,7 @@ void HostFNE::processPeer(network::PeerNetwork* peerNetwork)
uint32_t peerId = peerNetwork->getPeerId(); uint32_t peerId = peerNetwork->getPeerId();
uint32_t streamId = peerNetwork->getP25StreamId(); uint32_t streamId = peerNetwork->getP25StreamId();
m_network->p25TrafficHandler()->processFrame(data.get(), length, peerId, peerNetwork->pktLastSeq(), streamId, true); m_network->p25TrafficHandler()->processFrame(data.get(), length, peerId, peerNetwork->pktLastSeq(), streamId);
} }
} }
@ -602,7 +602,7 @@ void HostFNE::processPeer(network::PeerNetwork* peerNetwork)
uint32_t peerId = peerNetwork->getPeerId(); uint32_t peerId = peerNetwork->getPeerId();
uint32_t streamId = peerNetwork->getNXDNStreamId(); uint32_t streamId = peerNetwork->getNXDNStreamId();
m_network->nxdnTrafficHandler()->processFrame(data.get(), length, peerId, peerNetwork->pktLastSeq(), streamId, true); m_network->nxdnTrafficHandler()->processFrame(data.get(), length, peerId, peerNetwork->pktLastSeq(), streamId);
} }
} }
} }

@ -60,9 +60,8 @@ TagDMRData::~TagDMRData() = default;
/// <param name="peerId">Peer ID</param> /// <param name="peerId">Peer ID</param>
/// <param name="pktSeq"></param> /// <param name="pktSeq"></param>
/// <param name="streamId">Stream ID</param> /// <param name="streamId">Stream ID</param>
/// <param name="fromPeer">Flag indicating whether this traffic is from a peer connection or not.</param>
/// <returns></returns> /// <returns></returns>
bool TagDMRData::processFrame(const uint8_t* data, uint32_t len, uint32_t peerId, uint16_t pktSeq, uint32_t streamId, bool fromPeer) bool TagDMRData::processFrame(const uint8_t* data, uint32_t len, uint32_t peerId, uint16_t pktSeq, uint32_t streamId)
{ {
hrc::hrc_t pktTime = hrc::now(); hrc::hrc_t pktTime = hrc::now();
@ -108,11 +107,9 @@ bool TagDMRData::processFrame(const uint8_t* data, uint32_t len, uint32_t peerId
dmrData.setN(n); dmrData.setN(n);
} }
// is this data from a peer connection?
if (fromPeer) {
// perform TGID route rewrites if configured // perform TGID route rewrites if configured
routeRewrite(buffer, peerId, dmrData, dataType, dstId, slotNo, false); routeRewrite(buffer, peerId, dmrData, dataType, dstId, slotNo, false);
} dstId = __GET_UINT16(buffer, 8U);
// is the stream valid? // is the stream valid?
if (validate(peerId, dmrData, streamId)) { if (validate(peerId, dmrData, streamId)) {
@ -211,7 +208,14 @@ bool TagDMRData::processFrame(const uint8_t* data, uint32_t len, uint32_t peerId
continue; continue;
} }
m_network->writePeer(peer.first, { NET_FUNC_PROTOCOL, NET_PROTOCOL_SUBFUNC_DMR }, buffer, len, pktSeq, streamId, true); uint8_t outboundPeerBuffer[len];
::memset(outboundPeerBuffer, 0x00U, len);
::memcpy(outboundPeerBuffer, buffer, len);
// perform TGID route rewrites if configured
routeRewrite(outboundPeerBuffer, peer.first, dmrData, dataType, dstId, slotNo);
m_network->writePeer(peer.first, { NET_FUNC_PROTOCOL, NET_PROTOCOL_SUBFUNC_DMR }, outboundPeerBuffer, len, pktSeq, streamId, true);
if (m_network->m_debug) { if (m_network->m_debug) {
LogDebug(LOG_NET, "DMR, srcPeer = %u, dstPeer = %u, seqNo = %u, srcId = %u, dstId = %u, flco = $%02X, slotNo = %u, len = %u, pktSeq = %u, stream = %u", LogDebug(LOG_NET, "DMR, srcPeer = %u, dstPeer = %u, seqNo = %u, srcId = %u, dstId = %u, flco = $%02X, slotNo = %u, len = %u, pktSeq = %u, stream = %u",
peerId, peer.first, seqNo, srcId, dstId, flco, slotNo, len, pktSeq, streamId); peerId, peer.first, seqNo, srcId, dstId, flco, slotNo, len, pktSeq, streamId);
@ -303,7 +307,7 @@ 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::routeRewrite(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 rewriteDstId = dstId; uint32_t rewriteDstId = dstId;
uint32_t rewriteSlotNo = slotNo; uint32_t rewriteSlotNo = slotNo;
@ -369,10 +373,10 @@ bool TagDMRData::peerRewrite(uint32_t peerId, uint32_t& dstId, uint32_t& slotNo,
{ {
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);
} }
else { else {
tg = m_network->m_tidLookup->findByRewrite(peerId, dstId, slotNo); tg = m_network->m_tidLookup->findByRewrite(peerId, dstId);
} }
std::vector<lookups::TalkgroupRuleRewrite> rewrites = tg.config().rewrite(); std::vector<lookups::TalkgroupRuleRewrite> rewrites = tg.config().rewrite();
@ -382,13 +386,13 @@ bool TagDMRData::peerRewrite(uint32_t peerId, uint32_t& dstId, uint32_t& slotNo,
for (auto entry : rewrites) { for (auto entry : rewrites) {
if (entry.peerId() == peerId) { if (entry.peerId() == peerId) {
if (outbound) { if (outbound) {
dstId = tg.source().tgId();
slotNo = tg.source().tgSlot();
}
else {
dstId = entry.tgId(); dstId = entry.tgId();
slotNo = entry.tgSlot(); slotNo = entry.tgSlot();
} }
else {
dstId = tg.source().tgId();
slotNo = tg.source().tgSlot();
}
rewrote = true; rewrote = true;
break; break;
} }

@ -38,7 +38,7 @@ namespace network
~TagDMRData(); ~TagDMRData();
/// <summary>Process a data frame from the network.</summary> /// <summary>Process a data frame from the network.</summary>
bool processFrame(const uint8_t* data, uint32_t len, uint32_t peerId, uint16_t pktSeq, uint32_t streamId, bool fromPeer = false); bool processFrame(const uint8_t* data, uint32_t len, uint32_t peerId, uint16_t pktSeq, uint32_t streamId);
/// <summary>Helper to playback a parrot frame to the network.</summary> /// <summary>Helper to playback a parrot frame to the network.</summary>
void playbackParrot(); void playbackParrot();
@ -65,7 +65,7 @@ namespace network
bool m_debug; bool m_debug;
/// <summary>Helper to route rewrite the network data buffer.</summary> /// <summary>Helper to route rewrite the network data buffer.</summary>
void routeRewrite(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 route rewrite destination ID and slot.</summary> /// <summary>Helper to route rewrite destination ID and slot.</summary>
bool peerRewrite(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);

@ -59,9 +59,8 @@ TagNXDNData::~TagNXDNData() = default;
/// <param name="peerId">Peer ID</param> /// <param name="peerId">Peer ID</param>
/// <param name="pktSeq"></param> /// <param name="pktSeq"></param>
/// <param name="streamId">Stream ID</param> /// <param name="streamId">Stream ID</param>
/// <param name="fromPeer">Flag indicating whether this traffic is from a peer connection or not.</param>
/// <returns></returns> /// <returns></returns>
bool TagNXDNData::processFrame(const uint8_t* data, uint32_t len, uint32_t peerId, uint16_t pktSeq, uint32_t streamId, bool fromPeer) bool TagNXDNData::processFrame(const uint8_t* data, uint32_t len, uint32_t peerId, uint16_t pktSeq, uint32_t streamId)
{ {
hrc::hrc_t pktTime = hrc::now(); hrc::hrc_t pktTime = hrc::now();
@ -74,6 +73,10 @@ bool TagNXDNData::processFrame(const uint8_t* data, uint32_t len, uint32_t peerI
uint32_t srcId = __GET_UINT16(data, 5U); uint32_t srcId = __GET_UINT16(data, 5U);
uint32_t dstId = __GET_UINT16(data, 8U); uint32_t dstId = __GET_UINT16(data, 8U);
// perform TGID route rewrites if configured
routeRewrite(buffer, peerId, messageType, dstId, false);
dstId = __GET_UINT16(buffer, 8U);
lc::RTCH lc; lc::RTCH lc;
lc.setMessageType(messageType); lc.setMessageType(messageType);
@ -83,12 +86,6 @@ bool TagNXDNData::processFrame(const uint8_t* data, uint32_t len, uint32_t peerI
bool group = (data[15U] & 0x40U) == 0x40U ? false : true; bool group = (data[15U] & 0x40U) == 0x40U ? false : true;
lc.setGroup(group); lc.setGroup(group);
// is this data from a peer connection?
if (fromPeer) {
// perform TGID route rewrites if configured
routeRewrite(buffer, peerId, messageType, dstId, false);
}
// is the stream valid? // is the stream valid?
if (validate(peerId, lc, messageType, streamId)) { if (validate(peerId, lc, messageType, streamId)) {
// is this peer ignored? // is this peer ignored?
@ -181,7 +178,14 @@ bool TagNXDNData::processFrame(const uint8_t* data, uint32_t len, uint32_t peerI
continue; continue;
} }
m_network->writePeer(peer.first, { NET_FUNC_PROTOCOL, NET_PROTOCOL_SUBFUNC_NXDN }, buffer, len, pktSeq, streamId, true); uint8_t outboundPeerBuffer[len];
::memset(outboundPeerBuffer, 0x00U, len);
::memcpy(outboundPeerBuffer, buffer, len);
// perform TGID route rewrites if configured
routeRewrite(outboundPeerBuffer, peer.first, messageType, dstId);
m_network->writePeer(peer.first, { NET_FUNC_PROTOCOL, NET_PROTOCOL_SUBFUNC_NXDN }, outboundPeerBuffer, len, pktSeq, streamId, true);
if (m_network->m_debug) { if (m_network->m_debug) {
LogDebug(LOG_NET, "NXDN, srcPeer = %u, dstPeer = %u, messageType = $%02X, srcId = %u, dstId = %u, len = %u, pktSeq = %u, streamId = %u", LogDebug(LOG_NET, "NXDN, srcPeer = %u, dstPeer = %u, messageType = $%02X, srcId = %u, dstId = %u, len = %u, pktSeq = %u, streamId = %u",
peerId, peer.first, messageType, srcId, dstId, len, pktSeq, streamId); peerId, peer.first, messageType, srcId, dstId, len, pktSeq, streamId);
@ -305,10 +309,10 @@ bool TagNXDNData::peerRewrite(uint32_t peerId, uint32_t& dstId, bool outbound)
for (auto entry : rewrites) { for (auto entry : rewrites) {
if (entry.peerId() == peerId) { if (entry.peerId() == peerId) {
if (outbound) { if (outbound) {
dstId = tg.source().tgId(); dstId = entry.tgId();
} }
else { else {
dstId = entry.tgId(); dstId = tg.source().tgId();
} }
rewrote = true; rewrote = true;
break; break;

@ -38,7 +38,7 @@ namespace network
~TagNXDNData(); ~TagNXDNData();
/// <summary>Process a data frame from the network.</summary> /// <summary>Process a data frame from the network.</summary>
bool processFrame(const uint8_t* data, uint32_t len, uint32_t peerId, uint16_t pktSeq, uint32_t streamId, bool fromPeer = false); bool processFrame(const uint8_t* data, uint32_t len, uint32_t peerId, uint16_t pktSeq, uint32_t streamId);
/// <summary>Helper to playback a parrot frame to the network.</summary> /// <summary>Helper to playback a parrot frame to the network.</summary>
void playbackParrot(); void playbackParrot();

@ -62,9 +62,8 @@ TagP25Data::~TagP25Data() = default;
/// <param name="peerId">Peer ID</param> /// <param name="peerId">Peer ID</param>
/// <param name="pktSeq"></param> /// <param name="pktSeq"></param>
/// <param name="streamId">Stream ID</param> /// <param name="streamId">Stream ID</param>
/// <param name="fromPeer">Flag indicating whether this traffic is from a peer connection or not.</param>
/// <returns></returns> /// <returns></returns>
bool TagP25Data::processFrame(const uint8_t* data, uint32_t len, uint32_t peerId, uint16_t pktSeq, uint32_t streamId, bool fromPeer) bool TagP25Data::processFrame(const uint8_t* data, uint32_t len, uint32_t peerId, uint16_t pktSeq, uint32_t streamId)
{ {
hrc::hrc_t pktTime = hrc::now(); hrc::hrc_t pktTime = hrc::now();
@ -85,6 +84,10 @@ bool TagP25Data::processFrame(const uint8_t* data, uint32_t len, uint32_t peerId
uint8_t duid = data[22U]; uint8_t duid = data[22U];
uint8_t frameType = P25_FT_DATA_UNIT; uint8_t frameType = P25_FT_DATA_UNIT;
// perform TGID route rewrites if configured
routeRewrite(buffer, peerId, duid, dstId, false);
dstId = __GET_UINT16(buffer, 8U);
lc::LC control; lc::LC control;
data::LowSpeedData lsd; data::LowSpeedData lsd;
@ -127,12 +130,6 @@ bool TagP25Data::processFrame(const uint8_t* data, uint32_t len, uint32_t peerId
lsd.setLSD1(lsd1); lsd.setLSD1(lsd1);
lsd.setLSD2(lsd2); lsd.setLSD2(lsd2);
// is this data from a peer connection?
if (fromPeer) {
// perform TGID route rewrites if configured
routeRewrite(buffer, peerId, duid, dstId, false);
}
// is the stream valid? // is the stream valid?
if (validate(peerId, control, duid, streamId)) { if (validate(peerId, control, duid, streamId)) {
// is this peer ignored? // is this peer ignored?
@ -233,7 +230,14 @@ bool TagP25Data::processFrame(const uint8_t* data, uint32_t len, uint32_t peerId
continue; continue;
} }
m_network->writePeer(peer.first, { NET_FUNC_PROTOCOL, NET_PROTOCOL_SUBFUNC_P25 }, buffer, len, pktSeq, streamId, true); uint8_t outboundPeerBuffer[len];
::memset(outboundPeerBuffer, 0x00U, len);
::memcpy(outboundPeerBuffer, buffer, len);
// perform TGID route rewrites if configured
routeRewrite(outboundPeerBuffer, peer.first, duid, dstId);
m_network->writePeer(peer.first, { NET_FUNC_PROTOCOL, NET_PROTOCOL_SUBFUNC_P25 }, outboundPeerBuffer, len, pktSeq, streamId, true);
if (m_network->m_debug) { if (m_network->m_debug) {
LogDebug(LOG_NET, "P25, srcPeer = %u, dstPeer = %u, duid = $%02X, lco = $%02X, MFId = $%02X, srcId = %u, dstId = %u, len = %u, pktSeq = %u, streamId = %u", LogDebug(LOG_NET, "P25, srcPeer = %u, dstPeer = %u, duid = $%02X, lco = $%02X, MFId = $%02X, srcId = %u, dstId = %u, len = %u, pktSeq = %u, streamId = %u",
peerId, peer.first, duid, lco, MFId, srcId, dstId, len, pktSeq, streamId); peerId, peer.first, duid, lco, MFId, srcId, dstId, len, pktSeq, streamId);
@ -429,23 +433,21 @@ bool TagP25Data::peerRewrite(uint32_t peerId, uint32_t& dstId, bool outbound)
std::vector<lookups::TalkgroupRuleRewrite> rewrites = tg.config().rewrite(); std::vector<lookups::TalkgroupRuleRewrite> rewrites = tg.config().rewrite();
bool rewrote = false;
if (rewrites.size() > 0) { if (rewrites.size() > 0) {
for (auto entry : rewrites) { for (auto entry : rewrites) {
if (entry.peerId() == peerId) { if (entry.peerId() == peerId) {
if (outbound) { if (outbound) {
dstId = tg.source().tgId(); dstId = entry.tgId();
} }
else { else {
dstId = entry.tgId(); dstId = tg.source().tgId();
} }
rewrote = true; return true;
break;
} }
} }
} }
return rewrote; return false;
} }
/// <summary> /// <summary>

@ -44,7 +44,7 @@ namespace network
~TagP25Data(); ~TagP25Data();
/// <summary>Process a data frame from the network.</summary> /// <summary>Process a data frame from the network.</summary>
bool processFrame(const uint8_t* data, uint32_t len, uint32_t peerId, uint16_t pktSeq, uint32_t streamId, bool fromPeer = false); bool processFrame(const uint8_t* data, uint32_t len, uint32_t peerId, uint16_t pktSeq, uint32_t streamId);
/// <summary>Helper to playback a parrot frame to the network.</summary> /// <summary>Helper to playback a parrot frame to the network.</summary>
void playbackParrot(); void playbackParrot();

Loading…
Cancel
Save

Powered by TurnKey Linux.