Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 36 additions & 7 deletions dashboard2/pgs/peers.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,42 @@
<td>'.$Reflector->Peers[$i]->GetLinkedModule().'</td>';
if ($PageOptions['PeerPage']['IPModus'] != 'HideIP') {
echo '<td>';
$Bytes = explode(".", $Reflector->Peers[$i]->GetIP());
if ($Bytes !== false && count($Bytes) == 4) {
switch ($PageOptions['PeerPage']['IPModus']) {
case 'ShowLast1ByteOfIP' : echo $PageOptions['PeerPage']['MasqueradeCharacter'].'.'.$PageOptions['PeerPage']['MasqueradeCharacter'].'.'.$PageOptions['PeerPage']['MasqueradeCharacter'].'.'.$Bytes[3]; break;
case 'ShowLast2ByteOfIP' : echo $PageOptions['PeerPage']['MasqueradeCharacter'].'.'.$PageOptions['PeerPage']['MasqueradeCharacter'].'.'.$Bytes[2].'.'.$Bytes[3]; break;
case 'ShowLast3ByteOfIP' : echo $PageOptions['PeerPage']['MasqueradeCharacter'].'.'.$Bytes[1].'.'.$Bytes[2].'.'.$Bytes[3]; break;
default : echo '<a href="http://'.$Reflector->Peers[$i]->GetIP().'" target="_blank" style="text-decoration:none;color:#000000;">'.$Reflector->Peers[$i]->GetIP().'</a>';
$IPBinary = inet_pton($Reflector->Peers[$i]->GetIP());
$IPLength = strlen($IPBinary);
$Bytes = str_split($IPBinary, 1);
switch ($PageOptions['PeerPage']['IPModus']) {
case 'ShowLast1ByteOfIP' : $MasqByte = 3; break;
case 'ShowLast2ByteOfIP' : $MasqByte = 2; break;
case 'ShowLast3ByteOfIP' : $MasqByte = 1; break;
default : $MasqByte = 0; break;
}
if ($MasqByte == 0) {
switch ($IPLength) {
case 16: $IPAddrBracketL = '['; $IPAddrBracketR = ']'; break;
default: $IPAddrBracketL = ''; $IPAddrBracketR = ''; break;
}
echo '<a href="http://'.$IPAddrBracketL.$Reflector->Peers[$i]->GetIP().$IPAddrBracketR.'" target="_blank" style="text-decoration:none;color:#000000;">'.$Reflector->Peers[$i]->GetIP().'</a>';
} else {
switch ($IPLength) {
case 4:
for ($pos = 0; $pos < $IPLength; $pos++) {
if ($pos) echo '.';
if ($pos < $MasqByte) echo $PageOptions['PeerPage']['MasqueradeCharacter'];
else echo ord($Bytes[$pos]);
}
break;
case 16:
for ($pos = 0; $pos < $IPLength; $pos += 2) {
if ($pos) echo ':';
if ($pos < ($MasqByte * 4)) echo $PageOptions['PeerPage']['MasqueradeCharacter'];
else {
echo bin2hex($Bytes[$pos]);
echo bin2hex($Bytes[$pos + 1]);
}
}
break;
default:
break;
}
}
echo '</td>';
Expand Down
37 changes: 29 additions & 8 deletions dashboard2/pgs/repeaters.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,35 @@
if ($PageOptions['RepeatersPage']['IPModus'] != 'HideIP') {
echo '
<td>';
$Bytes = explode(".", $Reflector->Nodes[$i]->GetIP());
if ($Bytes !== false && count($Bytes) == 4) {
switch ($PageOptions['RepeatersPage']['IPModus']) {
case 'ShowLast1ByteOfIP' : echo $PageOptions['RepeatersPage']['MasqueradeCharacter'].'.'.$PageOptions['RepeatersPage']['MasqueradeCharacter'].'.'.$PageOptions['RepeatersPage']['MasqueradeCharacter'].'.'.$Bytes[3]; break;
case 'ShowLast2ByteOfIP' : echo $PageOptions['RepeatersPage']['MasqueradeCharacter'].'.'.$PageOptions['RepeatersPage']['MasqueradeCharacter'].'.'.$Bytes[2].'.'.$Bytes[3]; break;
case 'ShowLast3ByteOfIP' : echo $PageOptions['RepeatersPage']['MasqueradeCharacter'].'.'.$Bytes[1].'.'.$Bytes[2].'.'.$Bytes[3]; break;
default : echo $Reflector->Nodes[$i]->GetIP();
}
$IPBinary = inet_pton($Reflector->Nodes[$i]->GetIP());
$IPLength = strlen($IPBinary);
$Bytes = str_split($IPBinary, 1);
switch ($PageOptions['RepeatersPage']['IPModus']) {
case 'ShowLast1ByteOfIP' : $MasqByte = 3; break;
case 'ShowLast2ByteOfIP' : $MasqByte = 2; break;
case 'ShowLast3ByteOfIP' : $MasqByte = 1; break;
default : $MasqByte = 0; break;
}
switch ($IPLength) {
case 4:
for ($pos = 0; $pos < $IPLength; $pos++) {
if ($pos) echo '.';
if ($pos < $MasqByte) echo $PageOptions['RepeatersPage']['MasqueradeCharacter'];
else echo ord($Bytes[$pos]);
}
break;
case 16:
for ($pos = 0; $pos < $IPLength; $pos += 2) {
if ($pos) echo ':';
if ($pos < ($MasqByte * 4)) echo $PageOptions['RepeatersPage']['MasqueradeCharacter'];
else {
echo bin2hex($Bytes[$pos]);
echo bin2hex($Bytes[$pos + 1]);
}
}
break;
default:
break;
}
echo '</td>';
}
Expand Down
5 changes: 4 additions & 1 deletion src/cdmriddir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,10 @@ bool CDmridDir::IsValidDmrid(const char *sz)
ok = true;
for ( size_t i = 0; (i < n) && ok; i++ )
{
ok &= ::isdigit(sz[i]);
if ( !::isdigit(sz[i]) )
{
ok = false;
}
}
}
return ok;
Expand Down
5 changes: 2 additions & 3 deletions src/cdmrmmdvmprotocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,8 @@ bool CDmrmmdvmProtocol::Init(void)
m_LastKeepaliveTime.Now();

// random number generator
time_t t;
::srand((unsigned) time(&t));
m_uiAuthSeed = (uint32)rand();
std::random_device rd;
m_uiAuthSeed = rd();

// done
return ok;
Expand Down
21 changes: 11 additions & 10 deletions src/cdmrplusprotocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ bool CDmrplusProtocol::Init(void)
m_LastKeepaliveTime.Now();

// random number generator
time_t t;
::srand((unsigned) time(&t));
std::random_device rd;
std::mt19937 mt(rd());
m_Random = mt;

// done
return ok;
Expand All @@ -88,7 +89,7 @@ void CDmrplusProtocol::Task(void)
if ( m_Socket.Receive(&Buffer, &Ip, 20) != -1 )
{
// crack the packet
if ( IsValidDvFramePacket(Ip, Buffer, Frames) )
if ( IsValidDvFramePacket(Buffer, Frames) )
{
//std::cout << "DMRplus DV frame" << std::endl;
//Buffer.DebugDump(g_Reflector.m_DebugFile);
Expand All @@ -108,7 +109,7 @@ void CDmrplusProtocol::Task(void)
}*/
}
}
else if ( IsValidDvHeaderPacket(Ip, Buffer, &Header) )
else if ( IsValidDvHeaderPacket(Buffer, &Header) )
{
//std::cout << "DMRplus DV header:" << std::endl;
//std::cout << "DMRplus DV header:" << std::endl << *Header << std::endl;
Expand Down Expand Up @@ -444,7 +445,7 @@ bool CDmrplusProtocol::IsValidDisconnectPacket(const CBuffer &Buffer, CCallsign
return valid;
}

bool CDmrplusProtocol::IsValidDvHeaderPacket(const CIp &Ip, const CBuffer &Buffer, CDvHeaderPacket **Header)
bool CDmrplusProtocol::IsValidDvHeaderPacket(const CBuffer &Buffer, CDvHeaderPacket **Header)
{
bool valid = false;
*Header = NULL;
Expand All @@ -470,7 +471,7 @@ bool CDmrplusProtocol::IsValidDvHeaderPacket(const CIp &Ip, const CBuffer &Buffe
rpt1.SetModule(DMRPLUS_MODULE_ID);
CCallsign rpt2 = m_ReflectorCallsign;
rpt2.SetModule(DmrDstIdToModule(uiDstId));
uint32 uiStreamId = IpToStreamId(Ip);
uint32 uiStreamId = CreateStreamId();

// and packet
*Header = new CDvHeaderPacket(uiSrcId, CCallsign("CQCQCQ"), rpt1, rpt2, uiStreamId, 0, 0);
Expand All @@ -486,7 +487,7 @@ bool CDmrplusProtocol::IsValidDvHeaderPacket(const CIp &Ip, const CBuffer &Buffe
return valid;
}

bool CDmrplusProtocol::IsValidDvFramePacket(const CIp &Ip, const CBuffer &Buffer, CDvFramePacket **frames)
bool CDmrplusProtocol::IsValidDvFramePacket(const CBuffer &Buffer, CDvFramePacket **frames)
{
bool valid = false;
frames[0] = NULL;
Expand Down Expand Up @@ -528,7 +529,7 @@ bool CDmrplusProtocol::IsValidDvFramePacket(const CIp &Ip, const CBuffer &Buffer
dmrsync[6] = dmrframe[19] & 0xF0;

// and create 3 dv frames
uint32 uiStreamId = IpToStreamId(Ip);
uint32 uiStreamId = CreateStreamId();
// frame1
memcpy(dmrambe, &dmr3ambe[0], 9);
frames[0] = new CDvFramePacket(dmrambe, dmrsync, uiStreamId, uiVoiceSeq, 1);
Expand Down Expand Up @@ -840,7 +841,7 @@ void CDmrplusProtocol::ReplaceEMBInBuffer(CBuffer *buffer, uint8 uiDmrPacketId)


// uiStreamId helpers
uint32 CDmrplusProtocol::IpToStreamId(const CIp &ip) const
uint32 CDmrplusProtocol::CreateStreamId(void) const
{
return ip.GetAddr() ^ (uint32)(MAKEDWORD(ip.GetPort(), ip.GetPort()));
return m_Random();
}
9 changes: 6 additions & 3 deletions src/cdmrplusprotocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ class CDmrplusProtocol : public CProtocol
// packet decoding helpers
bool IsValidConnectPacket(const CBuffer &, CCallsign *, char *, const CIp &);
bool IsValidDisconnectPacket(const CBuffer &, CCallsign *, char *);
bool IsValidDvHeaderPacket(const CIp &, const CBuffer &, CDvHeaderPacket **);
bool IsValidDvFramePacket(const CIp &, const CBuffer &, CDvFramePacket **);
bool IsValidDvHeaderPacket(const CBuffer &, CDvHeaderPacket **);
bool IsValidDvFramePacket(const CBuffer &, CDvFramePacket **);

// packet encoding helpers
void EncodeConnectAckPacket(CBuffer *);
Expand All @@ -102,7 +102,7 @@ class CDmrplusProtocol : public CProtocol
uint32 ModuleToDmrDestId(char) const;

// uiStreamId helpers
uint32 IpToStreamId(const CIp &) const;
uint32 CreateStreamId(void) const;

// Buffer & LC helpers
void AppendVoiceLCToBuffer(CBuffer *, uint32) const;
Expand All @@ -116,6 +116,9 @@ class CDmrplusProtocol : public CProtocol

// for queue header caches
std::array<CDmrplusStreamCacheItem, NB_OF_MODULES> m_StreamsCache;

// random number generator
mutable std::mt19937 m_Random;
};

////////////////////////////////////////////////////////////////////////////////////////
Expand Down
29 changes: 25 additions & 4 deletions src/cg3protocol.cpp
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
#include <netinet/ip.h>
#include <netinet/ip_icmp.h>

#if !defined(ICMP_DEST_UNREACH) && defined(ICMP_UNREACH)
#define ICMP_DEST_UNREACH ICMP_UNREACH
#endif

////////////////////////////////////////////////////////////////////////////////////////
// operation
Expand All @@ -46,18 +49,34 @@ bool CG3Protocol::Init(void)
// base class
ok = CProtocol::Init();

// G3 needs IPv4 address
bool ipv4 = false;
#if !defined(DEBUG_NO_G3_SUPPORT)
for ( int i = 0; i < UDP_SOCKET_MAX; i++ )
{
CIp ip = g_Reflector.GetListenIp(i);
socklen_t ss_len;
ipv4 |= ( ip.GetSockAddr(ss_len)->ss_family == AF_INET );
}
#endif
if ( !ipv4 ) {
std::cout << "No IPv4 address, G3 support is disabled" << std::endl;
m_bStopThread = true;
return true;
}

// update reflector callsign
m_ReflectorCallsign.PatchCallsign(0, (const uint8 *)"XLX", 3);

// create our DV socket
ok &= m_Socket.Open(G3_DV_PORT);
ok &= m_Socket.Open(G3_DV_PORT, AF_INET);
if ( !ok )
{
std::cout << "Error opening socket on port UDP" << G3_DV_PORT << " on ip " << g_Reflector.GetListenIp() << std::endl;
}

//create helper sockets
ok &= m_PresenceSocket.Open(G3_PRESENCE_PORT);
ok &= m_PresenceSocket.Open(G3_PRESENCE_PORT, AF_INET);
if ( !ok )
{
std::cout << "Error opening socket on port UDP" << G3_PRESENCE_PORT << " on ip " << g_Reflector.GetListenIp() << std::endl;
Expand Down Expand Up @@ -161,7 +180,9 @@ void CG3Protocol::PresenceTask(void)
{

CIp Ip(ReqIp);
Ip.GetSockAddr()->sin_port = htons(G3_DV_PORT);
socklen_t len;
struct sockaddr_in *sin = (struct sockaddr_in *)Ip.GetSockAddr(len);
sin->sin_port = htons(G3_DV_PORT);

if (Buffer.size() == 32)
{
Expand Down Expand Up @@ -600,7 +621,7 @@ bool CG3Protocol::OnDvHeaderPacketIn(CDvHeaderPacket *Header, const CIp &Ip)
// drop if invalid module
delete Header;
g_Reflector.ReleaseClients();
return NULL;
return false;
}
}

Expand Down
24 changes: 15 additions & 9 deletions src/cimrsprotocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ bool CImrsProtocol::Init(void)
// update time
m_LastKeepaliveTime.Now();

// random number generator
std::random_device rd;
std::mt19937 mt(rd());
m_Random = mt;

// done
return ok;
}
Expand All @@ -76,9 +81,10 @@ void CImrsProtocol::Task(void)
//CYSFFICH Fich;
CDvHeaderPacket *Header;
CDvFramePacket *Frames[5];
int sno;

// handle incoming packets
if ( m_Socket.Receive(&Buffer, &Ip, 20) != -1 )
if ( m_Socket.Receive(&Buffer, &Ip, 20, &sno) != -1 )
{
// force port
Ip.SetPort(IMRS_PORT);
Expand Down Expand Up @@ -123,7 +129,7 @@ void CImrsProtocol::Task(void)
//std::cout << "IMRS ping packet from " << Ip << std::endl;

// acknowledge request
EncodePongPacket(&Buffer);
EncodePongPacket(&Buffer, sno);
m_Socket.Send(Buffer, Ip, IMRS_PORT);

// our turn
Expand Down Expand Up @@ -406,7 +412,7 @@ bool CImrsProtocol::IsValidDvHeaderPacket(const CIp &Ip, const CBuffer &Buffer,
if ( (Buffer.size() == 91) && (Buffer.at(1) == 0x4B) )
{
// get stream id
uint32 uiStreamId = IpToStreamId(Ip);
uint32 uiStreamId = CreateStreamId();

// and payload
CBuffer payload;
Expand Down Expand Up @@ -485,7 +491,7 @@ bool CImrsProtocol::IsValidDvFramePacket(const CIp &Ip, const CBuffer &Buffer, C
if ( (Buffer.size() == 181) && (Buffer.at(1) == 0xA5) )
{
// get stream id
uint32 uiStreamId = IpToStreamId(Ip);
uint32 uiStreamId = CreateStreamId();

// and payload
CBuffer payload;
Expand Down Expand Up @@ -578,7 +584,7 @@ bool CImrsProtocol::IsValidDvLastFramePacket(const CIp &Ip, const CBuffer &Buffe
if ( (Buffer.size() == 31) && (Buffer.at(1) == 0x0F) )
{
// get stream id
uint32 uiStreamId = IpToStreamId(Ip);
uint32 uiStreamId = CreateStreamId();

// and payload
CBuffer payload;
Expand Down Expand Up @@ -641,7 +647,7 @@ void CImrsProtocol::EncodePingPacket(CBuffer *Buffer) const
Buffer->Set(tag, sizeof(tag));
}

void CImrsProtocol::EncodePongPacket(CBuffer *Buffer) const
void CImrsProtocol::EncodePongPacket(CBuffer *Buffer, int sno) const
{
uint8 tag1[] = { 0x00,0x2C,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x04,0x00,0x00 };
uint8 radioid[] = { 'G','0','g','B','J' };
Expand All @@ -650,7 +656,7 @@ void CImrsProtocol::EncodePongPacket(CBuffer *Buffer) const
// tag
Buffer->Set(tag1, sizeof(tag1));
// mac address
Buffer->Append(g_Reflector.GetListenMac(), 6);
Buffer->Append(g_Reflector.GetListenMac(sno), 6);
// callsign
::memset(sz, ' ', sizeof(sz));
g_Reflector.GetCallsign().GetCallsignString(sz);
Expand Down Expand Up @@ -896,9 +902,9 @@ bool CImrsProtocol::EncodeDvLastPacket(const CDvHeaderPacket &Header, const CDvL
////////////////////////////////////////////////////////////////////////////////////////
// uiStreamId helpers

uint32 CImrsProtocol::IpToStreamId(const CIp &ip) const
uint32 CImrsProtocol::CreateStreamId(void) const
{
return ip.GetAddr() ^ (uint32)(MAKEDWORD(ip.GetPort(), ip.GetPort()));
return m_Random();
}

////////////////////////////////////////////////////////////////////////////////////////
Expand Down
Loading