Merge branch 'feature/satellite-filter'

Adds SATELLITE_FILTER support (bidirectional TG filter between a
satellite and its parent) via MsgTrunkFilter (type 122).

Contains:
  - test: satellite TG filter (RED commit reproducing the bug)
  - satellite: sysop patch (Jens DJ1JAY / FM-Funknetz) making it pass
  - docs: clarify that SATELLITE_FILTER is bidirectional in scope
This commit is contained in:
Audric committed 2026-04-20 14:31:16 +02:00
commit 2d3f2c97af
6 files changed
+179 -1

No files matched your search

+24
View File
@@ -66,6 +66,14 @@ bool SatelliteClient::initialize(void)
m_satellite_id = "satellite"; m_satellite_id = "satellite";
m_cfg.getValue("GLOBAL", "SATELLITE_ID", m_satellite_id); 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, geulog::info("satellite", "Connecting to parent ", m_parent_host,
":", m_parent_port, " as '", m_satellite_id, "'"); ":", m_parent_port, " as '", m_satellite_id, "'");
@@ -80,6 +88,7 @@ void SatelliteClient::onLocalTalkerStart(uint32_t tg,
const std::string& callsign) const std::string& callsign)
{ {
if (!m_con.isConnected() || !m_hello_received) return; if (!m_con.isConnected() || !m_hello_received) return;
if (!m_filter.empty() && !m_filter.matches(tg)) return;
sendMsg(MsgTrunkTalkerStart(tg, callsign)); sendMsg(MsgTrunkTalkerStart(tg, callsign));
} /* SatelliteClient::onLocalTalkerStart */ } /* SatelliteClient::onLocalTalkerStart */
@@ -87,6 +96,7 @@ void SatelliteClient::onLocalTalkerStart(uint32_t tg,
void SatelliteClient::onLocalTalkerStop(uint32_t tg) void SatelliteClient::onLocalTalkerStop(uint32_t tg)
{ {
if (!m_con.isConnected() || !m_hello_received) return; if (!m_con.isConnected() || !m_hello_received) return;
if (!m_filter.empty() && !m_filter.matches(tg)) return;
sendMsg(MsgTrunkTalkerStop(tg)); sendMsg(MsgTrunkTalkerStop(tg));
} /* SatelliteClient::onLocalTalkerStop */ } /* SatelliteClient::onLocalTalkerStop */
@@ -95,6 +105,7 @@ void SatelliteClient::onLocalAudio(uint32_t tg,
const std::vector<uint8_t>& audio) const std::vector<uint8_t>& audio)
{ {
if (!m_con.isConnected() || !m_hello_received) return; if (!m_con.isConnected() || !m_hello_received) return;
if (!m_filter.empty() && !m_filter.matches(tg)) return;
sendMsg(MsgTrunkAudio(tg, audio)); sendMsg(MsgTrunkAudio(tg, audio));
} /* SatelliteClient::onLocalAudio */ } /* SatelliteClient::onLocalAudio */
@@ -102,6 +113,7 @@ void SatelliteClient::onLocalAudio(uint32_t tg,
void SatelliteClient::onLocalFlush(uint32_t tg) void SatelliteClient::onLocalFlush(uint32_t tg)
{ {
if (!m_con.isConnected() || !m_hello_received) return; if (!m_con.isConnected() || !m_hello_received) return;
if (!m_filter.empty() && !m_filter.matches(tg)) return;
sendMsg(MsgTrunkFlush(tg)); sendMsg(MsgTrunkFlush(tg));
} /* SatelliteClient::onLocalFlush */ } /* SatelliteClient::onLocalFlush */
@@ -206,9 +218,21 @@ void SatelliteClient::handleMsgTrunkHello(std::istream& is)
m_hello_received = true; m_hello_received = true;
geulog::info("satellite", "Parent authenticated (id='", msg.id(), "')"); 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 */ } /* 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) void SatelliteClient::handleMsgTrunkTalkerStart(std::istream& is)
{ {
MsgTrunkTalkerStart msg; MsgTrunkTalkerStart msg;
+12
View File
@@ -9,6 +9,8 @@
#include <AsyncFramedTcpConnection.h> #include <AsyncFramedTcpConnection.h>
#include <AsyncTimer.h> #include <AsyncTimer.h>
#include "TgFilter.h"
class Reflector; class Reflector;
class ReflectorMsg; class ReflectorMsg;
@@ -19,6 +21,13 @@ When SATELLITE_OF is configured, the reflector runs in satellite mode:
it connects to a parent reflector and relays all local client events. it connects to a parent reflector and relays all local client events.
Events received from the parent are broadcast to local clients. Events received from the parent are broadcast to local clients.
No prefix logic, no trunk mesh participation. No prefix logic, no trunk mesh participation.
An optional SATELLITE_FILTER scopes which TGs this satellite cares about,
in both directions (TgFilter syntax: exact, prefix "24*", range
"2427-2438", comma-separated):
- outbound: local events for non-matching TGs are not sent to the parent;
- inbound: the filter is sent to the parent via MsgTrunkFilter (type 122)
after authentication; the parent skips forwarding non-matching TGs.
*/ */
class SatelliteClient : public sigc::trackable class SatelliteClient : public sigc::trackable
{ {
@@ -53,6 +62,8 @@ class SatelliteClient : public sigc::trackable
Async::Timer m_heartbeat_timer; Async::Timer m_heartbeat_timer;
unsigned m_hb_tx_cnt; unsigned m_hb_tx_cnt;
unsigned m_hb_rx_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 onConnected(void);
void onDisconnected(Async::TcpConnection* con, void onDisconnected(Async::TcpConnection* con,
@@ -66,6 +77,7 @@ class SatelliteClient : public sigc::trackable
void handleMsgTrunkFlush(std::istream& is); void handleMsgTrunkFlush(std::istream& is);
void handleMsgTrunkHeartbeat(void); void handleMsgTrunkHeartbeat(void);
void sendMsg(const ReflectorMsg& msg); void sendMsg(const ReflectorMsg& msg);
void sendFilter(void);
void heartbeatTick(Async::Timer* t); void heartbeatTick(Async::Timer* t);
}; };
+43
View File
@@ -62,6 +62,7 @@ void SatelliteLink::onParentTalkerStart(uint32_t tg,
const std::string& callsign) const std::string& callsign)
{ {
if (!m_hello_received) return; if (!m_hello_received) return;
if (!filterPassesTg(tg)) return;
sendMsg(MsgTrunkTalkerStart(tg, callsign)); sendMsg(MsgTrunkTalkerStart(tg, callsign));
} /* SatelliteLink::onParentTalkerStart */ } /* SatelliteLink::onParentTalkerStart */
@@ -69,6 +70,7 @@ void SatelliteLink::onParentTalkerStart(uint32_t tg,
void SatelliteLink::onParentTalkerStop(uint32_t tg) void SatelliteLink::onParentTalkerStop(uint32_t tg)
{ {
if (!m_hello_received) return; if (!m_hello_received) return;
if (!filterPassesTg(tg)) return;
sendMsg(MsgTrunkTalkerStop(tg)); sendMsg(MsgTrunkTalkerStop(tg));
} /* SatelliteLink::onParentTalkerStop */ } /* SatelliteLink::onParentTalkerStop */
@@ -77,6 +79,7 @@ void SatelliteLink::onParentAudio(uint32_t tg,
const std::vector<uint8_t>& audio) const std::vector<uint8_t>& audio)
{ {
if (!m_hello_received) return; if (!m_hello_received) return;
if (!filterPassesTg(tg)) return;
sendMsg(MsgTrunkAudio(tg, audio)); sendMsg(MsgTrunkAudio(tg, audio));
} /* SatelliteLink::onParentAudio */ } /* SatelliteLink::onParentAudio */
@@ -84,6 +87,7 @@ void SatelliteLink::onParentAudio(uint32_t tg,
void SatelliteLink::onParentFlush(uint32_t tg) void SatelliteLink::onParentFlush(uint32_t tg)
{ {
if (!m_hello_received) return; if (!m_hello_received) return;
if (!filterPassesTg(tg)) return;
sendMsg(MsgTrunkFlush(tg)); sendMsg(MsgTrunkFlush(tg));
} /* SatelliteLink::onParentFlush */ } /* SatelliteLink::onParentFlush */
@@ -133,6 +137,9 @@ void SatelliteLink::onFrameReceived(FramedTcpConnection* con,
case MsgTrunkFlush::TYPE: case MsgTrunkFlush::TYPE:
handleMsgTrunkFlush(ss); handleMsgTrunkFlush(ss);
break; break;
case MsgTrunkFilter::TYPE:
handleMsgTrunkFilter(ss);
break;
default: default:
geulog::warn("satellite", "Unknown message type=", header.type()); geulog::warn("satellite", "Unknown message type=", header.type());
break; break;
@@ -295,3 +302,39 @@ void SatelliteLink::heartbeatTick(Async::Timer* t)
linkFailed(this); linkFailed(this);
} }
} /* SatelliteLink::heartbeatTick */ } /* 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 */
+8 -1
View File
@@ -9,6 +9,8 @@
#include <AsyncFramedTcpConnection.h> #include <AsyncFramedTcpConnection.h>
#include <AsyncTimer.h> #include <AsyncTimer.h>
#include "TgFilter.h"
class Reflector; class Reflector;
class ReflectorMsg; class ReflectorMsg;
@@ -16,7 +18,9 @@ class ReflectorMsg;
@brief Handles one inbound satellite connection on the parent reflector @brief Handles one inbound satellite connection on the parent reflector
A SatelliteLink is created for each satellite that connects to the parent's 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. The parent always wins talker arbitration over satellites.
*/ */
class SatelliteLink : public sigc::trackable class SatelliteLink : public sigc::trackable
@@ -64,6 +68,7 @@ class SatelliteLink : public sigc::trackable
unsigned m_hb_tx_cnt; unsigned m_hb_tx_cnt;
unsigned m_hb_rx_cnt; unsigned m_hb_rx_cnt;
std::set<uint32_t> m_sat_active_tgs; std::set<uint32_t> m_sat_active_tgs;
TgFilter m_tg_filter;
void onFrameReceived(Async::FramedTcpConnection* con, void onFrameReceived(Async::FramedTcpConnection* con,
std::vector<uint8_t>& data); std::vector<uint8_t>& data);
@@ -73,6 +78,8 @@ class SatelliteLink : public sigc::trackable
void handleMsgTrunkAudio(std::istream& is); void handleMsgTrunkAudio(std::istream& is);
void handleMsgTrunkFlush(std::istream& is); void handleMsgTrunkFlush(std::istream& is);
void handleMsgTrunkHeartbeat(void); void handleMsgTrunkHeartbeat(void);
void handleMsgTrunkFilter(std::istream& is);
bool filterPassesTg(uint32_t tg) const;
void sendMsg(const ReflectorMsg& msg); void sendMsg(const ReflectorMsg& msg);
void heartbeatTick(Async::Timer* t); void heartbeatTick(Async::Timer* t);
}; };
@@ -175,6 +175,13 @@ CERT_CA_HOOK=@SVX_SHARE_INSTALL_DIR@/ca-hook.py
#SATELLITE_PORT=5303 #SATELLITE_PORT=5303
#SATELLITE_SECRET=change_this_satellite_secret #SATELLITE_SECRET=change_this_satellite_secret
#SATELLITE_ID=my-satellite #SATELLITE_ID=my-satellite
# Optional TG filter — restricts which TGs this satellite cares about.
# Applied in both directions: the satellite skips sending local events for
# non-matching TGs, and advertises the filter to the parent via
# MsgTrunkFilter (type 122) so the parent skips forwarding them back.
# Syntax: exact "26200", prefix "24*", range "2427-2438", comma-separated.
# Empty or absent = no filtering (all TGs pass in both directions).
#SATELLITE_FILTER=24*,262*
# #
# MQTT publishing. Optional — omit this section to disable. # MQTT publishing. Optional — omit this section to disable.
+85
View File
@@ -69,6 +69,7 @@ MSG_TRUNK_AUDIO = 118
MSG_TRUNK_FLUSH = 119 MSG_TRUNK_FLUSH = 119
MSG_TRUNK_HEARTBEAT = 120 MSG_TRUNK_HEARTBEAT = 120
MSG_TRUNK_NODE_LIST = 121 MSG_TRUNK_NODE_LIST = 121
MSG_TRUNK_FILTER = 122
# Filter test peer constants # Filter test peer constants
FILTER_SECRET = T.TEST_PEER_FILTER["secret"] FILTER_SECRET = T.TEST_PEER_FILTER["secret"]
@@ -166,6 +167,12 @@ def build_heartbeat() -> bytes:
return struct.pack("!H", MSG_TRUNK_HEARTBEAT) return struct.pack("!H", MSG_TRUNK_HEARTBEAT)
def build_trunk_filter(filter_str: str) -> bytes:
payload = struct.pack("!H", MSG_TRUNK_FILTER)
payload += pack_string(filter_str)
return payload
def build_node_list(nodes) -> bytes: def build_node_list(nodes) -> bytes:
"""Build a MsgTrunkNodeList frame. """Build a MsgTrunkNodeList frame.
@@ -369,6 +376,9 @@ class SatellitePeer(TrunkPeer):
assert msg_type == MSG_TRUNK_HELLO, \ assert msg_type == MSG_TRUNK_HELLO, \
f"Expected hello reply, got type={msg_type}" f"Expected hello reply, got type={msg_type}"
def send_filter(self, filter_str: str):
send_frame(self.sock, build_trunk_filter(filter_str))
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
# ClientPeer — fake V2 SvxLink client (no SSL) # ClientPeer — fake V2 SvxLink client (no SSL)
@@ -1242,6 +1252,81 @@ class TestTrunkIntegration(unittest.TestCase):
wait_until(sat_gone, timeout=20.0, wait_until(sat_gone, timeout=20.0,
msg="satellite not cleared from /status after disconnect") msg="satellite not cleared from /status after disconnect")
# ------------------------------------------------------------------
# Test 16b: Satellite advertises a TG filter; parent honors it
# ------------------------------------------------------------------
def test_16b_satellite_tg_filter(self):
"""Satellite sends MsgTrunkFilter after Hello; parent must drop
forwarded events for TGs outside the filter.
Setup:
- CLUSTER_TGS are [222, 999] — both normally reach a satellite
via the parent (see test_14).
- This satellite subscribes to only "222" via the filter.
- A trunk peer originates talker+audio on TG 999 (should NOT
reach the satellite) and on TG 222 (should reach it).
"""
sat = SatellitePeer()
sat.connect_satellite()
sat.handshake()
# Advertise filter; give the parent a moment to install it
assert T.CLUSTER_TGS == [222, 999], \
"test assumes CLUSTER_TGS = [222, 999]"
tg_allowed = T.CLUSTER_TGS[0] # 222 — matches
tg_blocked = T.CLUSTER_TGS[1] # 999 — does not match
sat.send_filter(str(tg_allowed))
time.sleep(0.5)
sender, _ = self._connect_peer()
try:
# Originate on the BLOCKED TG first, then on the ALLOWED TG
for tg, who in ((tg_blocked, "BLOCKED_SRC"),
(tg_allowed, "ALLOWED_SRC")):
sender.send_talker_start(tg, who)
for _ in range(3):
sender.send_audio(tg, b"\xAA\x55" * 80)
sender.send_flush(tg)
sender.send_talker_stop(tg)
# Drain everything the satellite receives in 3s
sat.sock.settimeout(3.0)
allowed_talker = False
allowed_audio = False
blocked_talker = False
blocked_audio = False
try:
while True:
data = recv_frame(sat.sock)
msg_type, fields = parse_msg(data)
if msg_type == MSG_TRUNK_HEARTBEAT:
continue
tg = fields.get("tg")
if msg_type == MSG_TRUNK_TALKER_START:
if tg == tg_allowed: allowed_talker = True
if tg == tg_blocked: blocked_talker = True
elif msg_type == MSG_TRUNK_AUDIO:
if tg == tg_allowed: allowed_audio = True
if tg == tg_blocked: blocked_audio = True
except (socket.timeout, ConnectionError, OSError):
pass
self.assertTrue(allowed_talker,
f"satellite did not receive TalkerStart for TG {tg_allowed} "
f"(should match filter)")
self.assertTrue(allowed_audio,
f"satellite did not receive audio for TG {tg_allowed} "
f"(should match filter)")
self.assertFalse(blocked_talker,
f"satellite received TalkerStart for TG {tg_blocked} "
f"(should have been filtered by parent)")
self.assertFalse(blocked_audio,
f"satellite received audio for TG {tg_blocked} "
f"(should have been filtered by parent)")
finally:
sender.close()
sat.close()
# ------------------------------------------------------------------ # ------------------------------------------------------------------
# Test 17: Trunk talker notification reaches monitoring clients # Test 17: Trunk talker notification reaches monitoring clients
# ------------------------------------------------------------------ # ------------------------------------------------------------------