satellite: honor SATELLITE_FILTER on parent and satellite legs
Adds optional SATELLITE_FILTER in [GLOBAL] on the satellite side using
TgFilter grammar (exact, "24*" prefix, "2427-2438" range, comma-separated).
Flow:
- SatelliteClient parses SATELLITE_FILTER at init and applies it to its
own outbound (onLocalTalkerStart/Stop/Audio/Flush): events for TGs
outside the filter are not forwarded to the parent.
- After authenticating, the satellite sends the filter to the parent via
MsgTrunkFilter (type 122, already defined in ReflectorMsg.h and
reserved for this use).
- SatelliteLink (parent side) dispatches MsgTrunkFilter and stores a
TgFilter. Every parent->satellite send is gated by filterPassesTg();
empty filter = pass-all (pre-existing behavior).
Backwards compatible: older satellites never send the message; older
parents silently ignore unknown message types. The patched parent keeps
forwarding all TGs until it receives a MsgTrunkFilter.
Fixes the bug where a satellite could not restrict the TGs it received
from its parent — prior to this change SatelliteLink explicitly relayed
ALL TGs bidirectionally regardless of any local filter.
This commit is contained in:
1 parent
ba5d03e491
commit
719aa3e37c
5 files changed
+91
-1
No files matched your search
@@ -66,6 +66,14 @@ bool SatelliteClient::initialize(void)
|
||||
m_satellite_id = "satellite";
|
||||
m_cfg.getValue("GLOBAL", "SATELLITE_ID", m_satellite_id);
|
||||
|
||||
// Optional TG filter — restrict which TGs to receive from parent
|
||||
if (m_cfg.getValue("GLOBAL", "SATELLITE_FILTER", m_filter_str) &&
|
||||
!m_filter_str.empty())
|
||||
{
|
||||
m_filter = TgFilter::parse(m_filter_str);
|
||||
geulog::info("satellite", "TG filter: ", m_filter.toString());
|
||||
}
|
||||
|
||||
geulog::info("satellite", "Connecting to parent ", m_parent_host,
|
||||
":", m_parent_port, " as '", m_satellite_id, "'");
|
||||
|
||||
@@ -80,6 +88,7 @@ void SatelliteClient::onLocalTalkerStart(uint32_t tg,
|
||||
const std::string& callsign)
|
||||
{
|
||||
if (!m_con.isConnected() || !m_hello_received) return;
|
||||
if (!m_filter.empty() && !m_filter.matches(tg)) return;
|
||||
sendMsg(MsgTrunkTalkerStart(tg, callsign));
|
||||
} /* SatelliteClient::onLocalTalkerStart */
|
||||
|
||||
@@ -87,6 +96,7 @@ void SatelliteClient::onLocalTalkerStart(uint32_t tg,
|
||||
void SatelliteClient::onLocalTalkerStop(uint32_t tg)
|
||||
{
|
||||
if (!m_con.isConnected() || !m_hello_received) return;
|
||||
if (!m_filter.empty() && !m_filter.matches(tg)) return;
|
||||
sendMsg(MsgTrunkTalkerStop(tg));
|
||||
} /* SatelliteClient::onLocalTalkerStop */
|
||||
|
||||
@@ -95,6 +105,7 @@ void SatelliteClient::onLocalAudio(uint32_t tg,
|
||||
const std::vector<uint8_t>& audio)
|
||||
{
|
||||
if (!m_con.isConnected() || !m_hello_received) return;
|
||||
if (!m_filter.empty() && !m_filter.matches(tg)) return;
|
||||
sendMsg(MsgTrunkAudio(tg, audio));
|
||||
} /* SatelliteClient::onLocalAudio */
|
||||
|
||||
@@ -102,6 +113,7 @@ void SatelliteClient::onLocalAudio(uint32_t tg,
|
||||
void SatelliteClient::onLocalFlush(uint32_t tg)
|
||||
{
|
||||
if (!m_con.isConnected() || !m_hello_received) return;
|
||||
if (!m_filter.empty() && !m_filter.matches(tg)) return;
|
||||
sendMsg(MsgTrunkFlush(tg));
|
||||
} /* SatelliteClient::onLocalFlush */
|
||||
|
||||
@@ -206,9 +218,21 @@ void SatelliteClient::handleMsgTrunkHello(std::istream& is)
|
||||
|
||||
m_hello_received = true;
|
||||
geulog::info("satellite", "Parent authenticated (id='", msg.id(), "')");
|
||||
|
||||
// Advertise our TG filter to the parent so it can skip TGs we
|
||||
// don't want. The parent applies the filter on its outbound path.
|
||||
sendFilter();
|
||||
} /* SatelliteClient::handleMsgTrunkHello */
|
||||
|
||||
|
||||
void SatelliteClient::sendFilter(void)
|
||||
{
|
||||
if (m_filter_str.empty()) return;
|
||||
sendMsg(MsgTrunkFilter(m_filter_str));
|
||||
geulog::info("satellite", "Sent TG filter to parent: ", m_filter_str);
|
||||
} /* SatelliteClient::sendFilter */
|
||||
|
||||
|
||||
void SatelliteClient::handleMsgTrunkTalkerStart(std::istream& is)
|
||||
{
|
||||
MsgTrunkTalkerStart msg;
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
#include <AsyncFramedTcpConnection.h>
|
||||
#include <AsyncTimer.h>
|
||||
|
||||
#include "TgFilter.h"
|
||||
|
||||
class Reflector;
|
||||
class ReflectorMsg;
|
||||
|
||||
@@ -19,6 +21,12 @@ When SATELLITE_OF is configured, the reflector runs in satellite mode:
|
||||
it connects to a parent reflector and relays all local client events.
|
||||
Events received from the parent are broadcast to local clients.
|
||||
No prefix logic, no trunk mesh participation.
|
||||
|
||||
An optional SATELLITE_FILTER restricts which TGs the satellite wants to
|
||||
receive from the parent (uses the standard TgFilter syntax: exact, prefix
|
||||
"24*", range "2427-2438", comma-separated). The filter is sent to the
|
||||
parent via MsgTrunkFilter (type 122) after authentication. The parent
|
||||
applies it to outbound traffic so filtered TGs are never forwarded.
|
||||
*/
|
||||
class SatelliteClient : public sigc::trackable
|
||||
{
|
||||
@@ -53,6 +61,8 @@ class SatelliteClient : public sigc::trackable
|
||||
Async::Timer m_heartbeat_timer;
|
||||
unsigned m_hb_tx_cnt;
|
||||
unsigned m_hb_rx_cnt;
|
||||
TgFilter m_filter; // optional TG filter (SATELLITE_FILTER)
|
||||
std::string m_filter_str; // raw config string for MsgTrunkFilter
|
||||
|
||||
void onConnected(void);
|
||||
void onDisconnected(Async::TcpConnection* con,
|
||||
@@ -66,6 +76,7 @@ class SatelliteClient : public sigc::trackable
|
||||
void handleMsgTrunkFlush(std::istream& is);
|
||||
void handleMsgTrunkHeartbeat(void);
|
||||
void sendMsg(const ReflectorMsg& msg);
|
||||
void sendFilter(void);
|
||||
void heartbeatTick(Async::Timer* t);
|
||||
};
|
||||
|
||||
|
||||
@@ -62,6 +62,7 @@ void SatelliteLink::onParentTalkerStart(uint32_t tg,
|
||||
const std::string& callsign)
|
||||
{
|
||||
if (!m_hello_received) return;
|
||||
if (!filterPassesTg(tg)) return;
|
||||
sendMsg(MsgTrunkTalkerStart(tg, callsign));
|
||||
} /* SatelliteLink::onParentTalkerStart */
|
||||
|
||||
@@ -69,6 +70,7 @@ void SatelliteLink::onParentTalkerStart(uint32_t tg,
|
||||
void SatelliteLink::onParentTalkerStop(uint32_t tg)
|
||||
{
|
||||
if (!m_hello_received) return;
|
||||
if (!filterPassesTg(tg)) return;
|
||||
sendMsg(MsgTrunkTalkerStop(tg));
|
||||
} /* SatelliteLink::onParentTalkerStop */
|
||||
|
||||
@@ -77,6 +79,7 @@ void SatelliteLink::onParentAudio(uint32_t tg,
|
||||
const std::vector<uint8_t>& audio)
|
||||
{
|
||||
if (!m_hello_received) return;
|
||||
if (!filterPassesTg(tg)) return;
|
||||
sendMsg(MsgTrunkAudio(tg, audio));
|
||||
} /* SatelliteLink::onParentAudio */
|
||||
|
||||
@@ -84,6 +87,7 @@ void SatelliteLink::onParentAudio(uint32_t tg,
|
||||
void SatelliteLink::onParentFlush(uint32_t tg)
|
||||
{
|
||||
if (!m_hello_received) return;
|
||||
if (!filterPassesTg(tg)) return;
|
||||
sendMsg(MsgTrunkFlush(tg));
|
||||
} /* SatelliteLink::onParentFlush */
|
||||
|
||||
@@ -133,6 +137,9 @@ void SatelliteLink::onFrameReceived(FramedTcpConnection* con,
|
||||
case MsgTrunkFlush::TYPE:
|
||||
handleMsgTrunkFlush(ss);
|
||||
break;
|
||||
case MsgTrunkFilter::TYPE:
|
||||
handleMsgTrunkFilter(ss);
|
||||
break;
|
||||
default:
|
||||
geulog::warn("satellite", "Unknown message type=", header.type());
|
||||
break;
|
||||
@@ -295,3 +302,39 @@ void SatelliteLink::heartbeatTick(Async::Timer* t)
|
||||
linkFailed(this);
|
||||
}
|
||||
} /* SatelliteLink::heartbeatTick */
|
||||
|
||||
|
||||
void SatelliteLink::handleMsgTrunkFilter(std::istream& is)
|
||||
{
|
||||
MsgTrunkFilter msg;
|
||||
if (!msg.unpack(is))
|
||||
{
|
||||
geulog::error("satellite", "Failed to unpack MsgTrunkFilter from '",
|
||||
m_satellite_id, "'");
|
||||
return;
|
||||
}
|
||||
|
||||
if (msg.filter().empty())
|
||||
{
|
||||
// Empty filter = clear any previously set filter (allow all)
|
||||
m_tg_filter = TgFilter();
|
||||
geulog::info("satellite", "Satellite '", m_satellite_id,
|
||||
"': TG filter cleared (all TGs forwarded)");
|
||||
}
|
||||
else
|
||||
{
|
||||
m_tg_filter = TgFilter::parse(msg.filter());
|
||||
geulog::info("satellite", "Satellite '", m_satellite_id,
|
||||
"': TG filter set: ", m_tg_filter.toString());
|
||||
}
|
||||
|
||||
statusChanged(this);
|
||||
} /* SatelliteLink::handleMsgTrunkFilter */
|
||||
|
||||
|
||||
bool SatelliteLink::filterPassesTg(uint32_t tg) const
|
||||
{
|
||||
// Empty filter = no filtering = pass everything
|
||||
if (m_tg_filter.empty()) return true;
|
||||
return m_tg_filter.matches(tg);
|
||||
} /* SatelliteLink::filterPassesTg */
|
||||
@@ -9,6 +9,8 @@
|
||||
#include <AsyncFramedTcpConnection.h>
|
||||
#include <AsyncTimer.h>
|
||||
|
||||
#include "TgFilter.h"
|
||||
|
||||
class Reflector;
|
||||
class ReflectorMsg;
|
||||
|
||||
@@ -16,7 +18,9 @@ class ReflectorMsg;
|
||||
@brief Handles one inbound satellite connection on the parent reflector
|
||||
|
||||
A SatelliteLink is created for each satellite that connects to the parent's
|
||||
satellite port. It relays ALL TGs bidirectionally (no prefix filtering).
|
||||
satellite port. By default it relays ALL TGs bidirectionally. When the
|
||||
satellite sends a MsgTrunkFilter (type 122), the parent applies the filter
|
||||
to outbound traffic — only matching TGs are forwarded to this satellite.
|
||||
The parent always wins talker arbitration over satellites.
|
||||
*/
|
||||
class SatelliteLink : public sigc::trackable
|
||||
@@ -64,6 +68,7 @@ class SatelliteLink : public sigc::trackable
|
||||
unsigned m_hb_tx_cnt;
|
||||
unsigned m_hb_rx_cnt;
|
||||
std::set<uint32_t> m_sat_active_tgs;
|
||||
TgFilter m_tg_filter;
|
||||
|
||||
void onFrameReceived(Async::FramedTcpConnection* con,
|
||||
std::vector<uint8_t>& data);
|
||||
@@ -73,6 +78,8 @@ class SatelliteLink : public sigc::trackable
|
||||
void handleMsgTrunkAudio(std::istream& is);
|
||||
void handleMsgTrunkFlush(std::istream& is);
|
||||
void handleMsgTrunkHeartbeat(void);
|
||||
void handleMsgTrunkFilter(std::istream& is);
|
||||
bool filterPassesTg(uint32_t tg) const;
|
||||
void sendMsg(const ReflectorMsg& msg);
|
||||
void heartbeatTick(Async::Timer* t);
|
||||
};
|
||||
|
||||
@@ -175,6 +175,11 @@ CERT_CA_HOOK=@SVX_SHARE_INSTALL_DIR@/ca-hook.py
|
||||
#SATELLITE_PORT=5303
|
||||
#SATELLITE_SECRET=change_this_satellite_secret
|
||||
#SATELLITE_ID=my-satellite
|
||||
# Optional TG filter — restrict which TGs to receive from parent.
|
||||
# Uses standard filter syntax: exact "26200", prefix "24*", range "2427-2438",
|
||||
# comma-separated. Empty or absent = receive all TGs.
|
||||
# Sent to the parent via MsgTrunkFilter (type 122) after authentication.
|
||||
#SATELLITE_FILTER=24*,262*
|
||||
|
||||
#
|
||||
# MQTT publishing. Optional — omit this section to disable.
|
||||
|
||||
Reference in new issue
Block a user