Restore YSF native DG-ID module switching (native clients only)

REGRESSION FIXED

Yaesu radios in System Fusion V/D mode transmit the operator's
selected DG-ID (Digital Group ID) in the FICH SQ field. xlxd
previously (2021, upstream commits 32c9e0c + e752b76 by narspt)
allowed a native YSF client to switch which reflector module they
were linked to by dialling the DG-ID on their radio. That feature
was silently removed in upstream commit 27f5678 -- part of a
large multi-protocol peering rewrite -- and stayed removed through
the recent hardening work in this fork.

Current behaviour before this fix: every YSF native client was
pinned to whichever module they auto-linked or Wires-X CONN_REQ'd
to, with no way to switch mid-session. This restores the DG-ID
mechanism with the correct scope and the gatekeeper-bypass fix
that narspt applied in the second 2021 commit.

DESIGN

Three-part change in cysfprotocol.cpp, no other files touched.

1. Task() -- new DG-ID stamping block between the isPeer check
   (lines 139-158) and the gatekeeper check (lines 213+):

     if ( !isPeer )
     {
         unsigned char sq = Fich.getSQ();
         char dgidModule;
         if ( (sq >= 10) && (sq < 10 + NB_OF_MODULES) )
         {
             dgidModule = 'A' + (char)(sq - 10);
         }
         else
         {
             dgidModule = clientModule;   // client's current module
         }
         Header->SetRpt2Module(dgidModule);
     }

   DG-ID values 10..(10 + NB_OF_MODULES - 1) map to modules A..(letter).
   Values outside that range (typically 0..9 for "no DG-ID intent",
   or above the module range) leave the client on their currently-
   linked module.

   Applied to native clients ONLY (isPeer gate). Peers represent
   external reflectors whose module identity is fixed by interlink
   config -- a peer's upstream user's DG-ID must not move the peer's
   own link.

2. Task() -- gatekeeper call at line 215 changed from passing
   `clientModule` (client's current module) to passing
   `Header->GetRpt2Module()` (the DG-ID destination if applicable,
   otherwise the client's current module).

   This closes the gatekeeper bypass narspt fixed in 2021:
   without this, a callsign muted on module A could dial DG-ID
   for module B and transmit under B's (unmuted) rules because
   MayTransmit was checking module A's whitelist / loop-suppress
   state instead of module B's.

3. OnDvHeaderPacketIn -- unconditional
   `Header->SetRpt2Module(client->GetReflectorModule())` at line
   422-423 replaced with peer-vs-native branching:

     if ( client->IsPeer() )
     {
         // Peer traffic: always use peer's assigned link module.
         Header->SetRpt2Module(client->GetReflectorModule());
     }
     else
     {
         // Native client: apply DG-ID module switch if the module
         // stamped by Task() differs from the client's current one.
         char headerModule = Header->GetRpt2Module();
         bool validModule = (headerModule >= 'A') &&
                            (headerModule < 'A' + NB_OF_MODULES);
         if ( validModule &&
              (headerModule != client->GetReflectorModule()) )
         {
             std::cout << "YSF client " << client->GetCallsign()
                       << " linking on module " << headerModule
                       << " (DG-ID)" << std::endl;
             client->SetReflectorModule(headerModule);
         }
         if ( !validModule )
         {
             Header->SetRpt2Module(client->GetReflectorModule());
         }
     }

   The validModule test is sentinel-agnostic -- it accepts only
   real module letters A..(A+NB_OF_MODULES-1). The parser's 'G'
   default and any accidental ' ' value both fail the test and
   trigger the fallback. This decouples the OnDvHeader logic from
   whatever sentinel the parser uses for "unset" -- if the parser
   default changes later, this code doesn't need updating.

PEER EXCLUSION -- three independent layers

  Layer 1: Task() DG-ID stamping is gated on !isPeer, where isPeer
  comes from FindPeerByIpPort at existing lines 143-144. Peer
  packets never have DG-ID mapped to rpt2 in the first place.

  Layer 2: OnDvHeaderPacketIn's client->IsPeer() branch
  unconditionally overwrites rpt2 with the peer's assigned
  ReflectorModule. Belt-and-braces against any future code path
  that might stamp rpt2 for peer traffic.

  Layer 3: Class hierarchy. CYsfPeerClient::IsPeer() returns true
  (cysfpeerclient.h:48); CYsfClient (native user) inherits
  CClient::IsPeer() returning false (cclient.h:90). Peer and native
  clients are physically different types -- no runtime state can
  make one look like the other.

WIRE-LEVEL SAFETY -- confirmed no DG-ID propagation

The three outgoing FICH builders in cysfprotocol.cpp (lines 1067,
1122, 1217) all set setSQ(0) hardcoded on every outbound packet.
The source's DG-ID is consumed on ingress (in the Fich local at
RxTask() line 94) and discarded when RxTask() returns; the
CDvHeaderPacket/CDvFramePacket objects that traverse xlxd's
internal packet routing carry no FICH bytes and no SQ field. TX
FICH is rebuilt from scratch with SQ=0 on the other end.

Consequence: DG-ID is a purely receive-side, per-reflector
decision. No cross-reflector propagation is possible even if
DG-ID handling malfunctioned upstream.

DG-ID MAPPING

  DG-ID  | Module | Behaviour
  -------|--------|--------------------------------------------------
  0..9   | -      | No DG-ID intent -- keep client's current module
  10     | A      | Switch client to module A (if not already there)
  11     | B      | Switch client to module B
  ...    |        |
  10+N-1 | (nth)  | Switch client to nth module (default 10 modules: A..J)
  36+    | -      | Out of range -- keep client's current module

The 10-offset avoids collision with the SQ values a Yaesu radio
typically emits for non-DG-ID situations (0..9 span the
"no group set" states).

EXPLICITLY OUT OF SCOPE

  - Parser default at IsValidDvHeaderPacket line 862-863
    (`rpt2.SetModule('G')`) is unchanged.
  - Dead ysfModule peer-lookup at lines 848-856 is unchanged.
  - Pre-existing peer-classification gap where a peer packet
    arriving on a mismatched source port could be misclassified
    by Task()'s FindPeerByIpPort as !isPeer, while
    OnDvHeaderPacketIn's IsPeer()-based fallback correctly
    identifies it. In that divergent case: Task() would run
    the native-client DG-ID path (potentially stamping a wrong
    rpt2) and MayTransmit path (running the wrong gate). Layer 2
    in OnDvHeaderPacketIn still correctly forces the peer's
    module. Not addressed in this commit.
pull/268/head
Andy Taylor 4 months ago
parent a86b16ad9a
commit e34b0e0282

@ -157,6 +157,42 @@ void CYsfProtocol::RxTask(void)
g_Reflector.ReleaseClients();
}
// DG-ID module selection (Yaesu radio user-facing feature).
// Yaesu radios in System Fusion V/D mode transmit their
// selected DG-ID in the FICH SQ field. Values 10..(10 +
// NB_OF_MODULES - 1) map to modules A..(letter). Other
// values (typically 0..9, or above the module range) mean
// "no module change intent" — the client stays on their
// currently-linked module.
//
// Applied to native clients ONLY. Peers represent external
// reflectors whose module identity is fixed by interlink
// config; DG-ID from a peer's upstream user must not move
// the peer's link. See also the IsPeer() safety belt in
// OnDvHeaderPacketIn.
//
// Rpt2 module is stamped here so the gatekeeper's
// MayTransmit call below sees the DESTINATION module,
// not the client's stale current module — closes the
// "mute on A, dial DG-ID for B, transmit under B's rules"
// bypass that narspt fixed in the pre-regression 2021
// code (upstream commits 32c9e0c + e752b76).
if ( !isPeer )
{
unsigned char sq = Fich.getSQ();
char dgidModule;
if ( (sq >= 10) && (sq < 10 + NB_OF_MODULES) )
{
dgidModule = 'A' + (char)(sq - 10);
}
else
{
// no DG-ID intent — keep on client's current module
dgidModule = clientModule;
}
Header->SetRpt2Module(dgidModule);
}
// Peer traffic bypasses MayTransmit (peers are trusted
// interlinks, not subject to whitelist/blacklist/
// callsign-validity checks) but is still subject to
@ -177,7 +213,7 @@ void CYsfProtocol::RxTask(void)
}
else if ( !g_GateKeeper.MayTransmit(
Header->GetMyCallsign(), Ip,
PROTOCOL_YSF, clientModule) )
PROTOCOL_YSF, Header->GetRpt2Module()) )
{
delete Header;
Header = NULL;
@ -419,8 +455,45 @@ bool CYsfProtocol::OnDvHeaderPacketIn(CDvHeaderPacket *Header, const CIp &Ip)
// get client callsign
via = client->GetCallsign();
// For YSF, always use client's assigned module (RPT2 is a D-Star concept)
Header->SetRpt2Module(client->GetReflectorModule());
if ( client->IsPeer() )
{
// Peer traffic: always use peer's assigned link module
// (fixed by interlink config). Never let a wire field
// move a peer's client — safety belt against upstream
// sources that might carry DG-ID or a garbled rpt2.
// Task() doesn't stamp DG-ID for peers, but this
// belt-and-braces guarantee protects against any
// future code path that might.
Header->SetRpt2Module(client->GetReflectorModule());
}
else
{
// Native client: Task() already stamped rpt2 with either
// the DG-ID target (SQ in [10..10+NB_OF_MODULES)) or the
// client's current module (no DG-ID intent). Anything
// outside the valid module range A..(A+NB_OF_MODULES-1)
// — including the parser's 'G' sentinel or an unset ' '
// from an edge case where Task() couldn't resolve the
// client — is treated as "no valid destination stamped"
// and falls back to the client's current module.
char headerModule = Header->GetRpt2Module();
bool validModule = (headerModule >= 'A') &&
(headerModule < 'A' + NB_OF_MODULES);
if ( validModule &&
(headerModule != client->GetReflectorModule()) )
{
// DG-ID-driven module switch — log for operator visibility
std::cout << "YSF client " << client->GetCallsign()
<< " linking on module " << headerModule
<< " (DG-ID)" << std::endl;
client->SetReflectorModule(headerModule);
}
if ( !validModule )
{
// Fall back so downstream routing has a real module letter
Header->SetRpt2Module(client->GetReflectorModule());
}
}
// save callsigns before OpenStream — OpenStream transfers Header
// to the router queue where the router thread may delete it

Loading…
Cancel
Save

Powered by TurnKey Linux.