diff options
| author | Dave Hibberd <hibby@debian.org> | 2025-11-22 15:09:21 +0000 |
|---|---|---|
| committer | Dave Hibberd <hibby@debian.org> | 2025-11-22 15:09:21 +0000 |
| commit | 52e35f45b4cfefc21707b42883dd1afa142ac7d4 (patch) | |
| tree | 0a9b58677b2f8dad558593277a547b17c38af976 /Events.c | |
| parent | 453f162d225b192d5da5a843633208f0307e6afc (diff) | |
New upstream version 6.0.25.12+repack
Diffstat (limited to 'Events.c')
| -rw-r--r-- | Events.c | 271 |
1 files changed, 221 insertions, 50 deletions
@@ -26,6 +26,7 @@ along with LinBPQ/BPQ32. If not, see http://www.gnu.org/licenses #include "asmstrucs.h"
#include "tncinfo.h"
#include "cheaders.h"
+#include "kiss.h"
VOID __cdecl Debugprintf(const char * format, ...);
@@ -44,7 +45,9 @@ void MQTTReportSession(char * Msg); extern int MQTT;
extern time_t TimeLoaded;
-int UDPSeq = 1;
+uint16_t UDPSeq = 1;
+int linkSeq = 1;
+int cctSeq = 1;
extern SOCKET NodeAPISocket;
extern SOCKADDR_IN UDPreportdest;
@@ -57,6 +60,8 @@ extern char LOC[7]; extern char VersionString[50];
extern double LatFromLOC;
extern double LonFromLOC;
+extern int NUMBEROFNODES, MAXDESTS, L4CONNECTSOUT, L4CONNECTSIN, L4FRAMESTX, L4FRAMESRX, L4FRAMESRETRIED, OLDFRAMES;
+extern int L2CONNECTSOUT, L2CONNECTSIN;
void hookL2SessionClosed(struct _LINKTABLE * LINK, char * Reason, char * Direction);
int ConvFromAX25(unsigned char * incall, unsigned char * outcall);
@@ -66,6 +71,7 @@ int decodeNETROMUIMsg(unsigned char * Msg, int iLen, char * Buffer, int BufferLe int decodeNETROMIFrame(unsigned char * Msg, int iLen, char * Buffer, int BufferLen);
int decodeINP3RIF(unsigned char * Msg, int iLen, char * Buffer, int BufferLen);
int decodeRecordRoute(L3MESSAGE * L3, int iLen, char * Buffer, int BufferLen);
+char * byte_base64_encode(char *str, int len);
// Runs use specified routine on certain event
@@ -145,9 +151,12 @@ void hookL2SessionAccepted(int Port, char * remotecall, char * ourcall, struct _ char UDPMsg[1024];
int udplen;
- LINK->ConnectTime = time(NULL);
- LINK->bytesTXed = LINK->bytesRXed = LINK->framesResent = LINK->framesRXed = LINK->framesTXed = 0;
+ L2CONNECTSIN++;
+ LINK->apiSeq = linkSeq++;
+ LINK->lastStatusSentTime = LINK->ConnectTime = time(NULL);
+ LINK->bytesTXed = LINK->bytesRXed = LINK->framesResent = LINK->framesRXed = LINK->framesTXed = 0;
+ LINK->LastStatusbytesTXed = LINK->LastStatusbytesRXed = 0;
strcpy(LINK->callingCall, remotecall);
strcpy(LINK->receivingCall, ourcall);
strcpy(LINK->Direction, "In");
@@ -156,8 +165,8 @@ void hookL2SessionAccepted(int Port, char * remotecall, char * ourcall, struct _ {
LINK->lastStatusSentTime = time(NULL);
- udplen = sprintf(UDPMsg, "{\"@type\":\"LinkUpEvent\", \"node\": \"%s\", \"id\": %d, \"direction\": \"incoming\", \"port\": \"%d\", \"remote\": \"%s\", \"local\": \"%s\"}",
- NODECALLLOPPED, UDPSeq++, LINK->LINKPORT->PORTNUMBER, LINK->callingCall, LINK->receivingCall);
+ udplen = sprintf(UDPMsg, "{\"@type\":\"LinkUpEvent\", \"node\": \"%s\", \"id\": %d, \"direction\": \"incoming\", \"port\": \"%d\", \"remote\": \"%s\", \"local\": \"%s\", \"isRF\": %s}",
+ NODECALLLOPPED, LINK->apiSeq, LINK->LINKPORT->PORTNUMBER, LINK->callingCall, LINK->receivingCall, (LINK->LINKPORT->isRF)?"true":"false");
// Debugprintf(UDPMsg);
@@ -217,9 +226,9 @@ void hookL2SessionDeleted(struct _LINKTABLE * LINK) void hookL2SessionAttempt(int Port, char * ourcall, char * remotecall, struct _LINKTABLE * LINK)
{
- LINK->ConnectTime = time(NULL);
+ LINK->lastStatusSentTime = LINK->ConnectTime = time(NULL);
LINK->bytesTXed = LINK->bytesRXed = LINK->framesResent = LINK->framesRXed = LINK->framesTXed = 0;
-
+ LINK->LastStatusbytesTXed = LINK->LastStatusbytesRXed = 0;
strcpy(LINK->callingCall, ourcall);
strcpy(LINK->receivingCall, remotecall);
strcpy(LINK->Direction, "Out");
@@ -232,12 +241,15 @@ void hookL2SessionConnected(struct _LINKTABLE * LINK) char UDPMsg[1024];
int udplen;
+ L2CONNECTSOUT++;
+ LINK->apiSeq = linkSeq++;
+
if (NodeAPISocket)
{
LINK->lastStatusSentTime = time(NULL);
- udplen = sprintf(UDPMsg, "{\"@type\":\"LinkUpEvent\", \"node\": \"%s\", \"id\": %d, \"direction\": \"outgoing\", \"port\": \"%d\", \"remote\": \"%s\", \"local\": \"%s\"}",
- NODECALLLOPPED, UDPSeq++, LINK->LINKPORT->PORTNUMBER, LINK->callingCall, LINK->receivingCall);
+ udplen = sprintf(UDPMsg, "{\"@type\":\"LinkUpEvent\", \"node\": \"%s\", \"id\": %d, \"direction\": \"outgoing\", \"port\": \"%d\", \"remote\": \"%s\", \"local\": \"%s\", \"isRF\": %s}",
+ NODECALLLOPPED, LINK->apiSeq, LINK->LINKPORT->PORTNUMBER, LINK->callingCall, LINK->receivingCall, (LINK->LINKPORT->isRF)?"true":"false");
// Debugprintf(UDPMsg);
@@ -251,6 +263,7 @@ void hookL2SessionClosed(struct _LINKTABLE * LINK, char * Reason, char * Directi char UDPMsg[1024];
int udplen;
+ time_t Now = time(NULL);
if (NodeAPISocket)
{
@@ -259,14 +272,18 @@ void hookL2SessionClosed(struct _LINKTABLE * LINK, char * Reason, char * Directi if (strcmp(Direction, "Out") == 0)
udplen = sprintf(UDPMsg, "{\"@type\":\"LinkDownEvent\", \"node\": \"%s\", \"id\": %d, \"direction\": \"outgoing\", \"port\": \"%d\", \"remote\": \"%s\", \"local\": \"%s\","
- "\"bytesSent\": %d, \"bytesRcvd\": %d, \"frmsSent\": %d, \"frmsRcvd\": %d, \"frmsQueued\": %d, \"frmsResent\": %d, \"reason\": \"%s\"}",
- NODECALLLOPPED, UDPSeq++, LINK->LINKPORT->PORTNUMBER, LINK->receivingCall, LINK->callingCall,
- LINK->bytesTXed , LINK->bytesRXed, LINK->framesTXed, LINK->framesRXed, COUNT_AT_L2(LINK), LINK->framesResent, Reason);
+ "\"bytesSent\": %d, \"bytesRcvd\": %d, \"frmsSent\": %d, \"frmsRcvd\": %d, \"frmsQueued\": %d, \"frmsResent\": %d, \"reason\": \"%s\","
+ " \"time\": %d, \"upForSecs\": %d, \"frmsQdPeak\": %d, \"isRF\": %s}",
+ NODECALLLOPPED, LINK->apiSeq, LINK->LINKPORT->PORTNUMBER, LINK->receivingCall, LINK->callingCall,
+ LINK->bytesTXed , LINK->bytesRXed, LINK->framesTXed, LINK->framesRXed, COUNT_AT_L2(LINK), LINK->framesResent, Reason,
+ (int)Now, (int)Now - LINK->ConnectTime, LINK->maxQueued, (LINK->LINKPORT->isRF)?"true":"false");
else
udplen = sprintf(UDPMsg, "{\"@type\":\"LinkDownEvent\", \"node\": \"%s\", \"id\": %d, \"direction\": \"incoming\", \"port\": \"%d\", \"remote\": \"%s\", \"local\": \"%s\","
- "\"bytesSent\": %d, \"bytesRcvd\": %d, \"frmsSent\": %d, \"frmsRcvd\": %d, \"frmsQueued\": %d, \"frmsResent\": %d, \"reason\": \"%s\"}",
- NODECALLLOPPED, UDPSeq++, LINK->LINKPORT->PORTNUMBER, LINK->callingCall, LINK->receivingCall,
- LINK->bytesTXed , LINK->bytesRXed, LINK->framesTXed, LINK->framesRXed, COUNT_AT_L2(LINK), LINK->framesResent, Reason);
+ "\"bytesSent\": %d, \"bytesRcvd\": %d, \"frmsSent\": %d, \"frmsRcvd\": %d, \"frmsQueued\": %d, \"frmsResent\": %d, \"reason\": \"%s\","
+ " \"time\": %d, \"upForSecs\": %d, \"frmsQdPeak\": %d, \"isRF\": %s}",
+ NODECALLLOPPED, LINK->apiSeq, LINK->LINKPORT->PORTNUMBER, LINK->callingCall, LINK->receivingCall,
+ LINK->bytesTXed , LINK->bytesRXed, LINK->framesTXed, LINK->framesRXed, COUNT_AT_L2(LINK), LINK->framesResent, Reason,
+ (int)Now, (int)Now - LINK->ConnectTime, LINK->maxQueued, (LINK->LINKPORT->isRF)?"true":"false");
// Debugprintf(UDPMsg);
@@ -280,24 +297,37 @@ void hookL2SessionStatus(struct _LINKTABLE * LINK) char UDPMsg[1024];
int udplen;
+ time_t Now = time(NULL);
+ int bpsTx, bpsRx, interval;
if (NodeAPISocket)
{
- LINK->lastStatusSentTime = time(NULL);
+ interval = Now - (int)LINK->lastStatusSentTime;
+ bpsTx = (LINK->bytesTXed - LINK->LastStatusbytesTXed) / interval;
+ bpsRx = (LINK->bytesRXed - LINK->LastStatusbytesRXed) / interval;
+
+ LINK->lastStatusSentTime = Now;
+ LINK->LastStatusbytesTXed = LINK->bytesTXed;
+ LINK->LastStatusbytesRXed = LINK->bytesRXed;
if (strcmp(LINK->Direction, "Out") == 0)
udplen = sprintf(UDPMsg, "{\"@type\":\"LinkStatus\", \"node\": \"%s\", \"id\": %d, \"direction\": \"outgoing\", \"port\": \"%d\", \"remote\": \"%s\", \"local\": \"%s\","
- "\"bytesSent\": %d, \"bytesRcvd\": %d, \"frmsSent\": %d, \"frmsRcvd\": %d, \"frmsQueued\": %d, \"frmsResent\": %d}",
- NODECALLLOPPED, UDPSeq++, LINK->LINKPORT->PORTNUMBER, LINK->receivingCall, LINK->callingCall,
- LINK->bytesTXed , LINK->bytesRXed, LINK->framesTXed, LINK->framesRXed, 0, LINK->framesResent);
+ "\"bytesSent\": %d, \"bytesRcvd\": %d, \"frmsSent\": %d, \"frmsRcvd\": %d, \"frmsQueued\": %d, \"frmsResent\": %d,"
+ "\"upForSecs\": %d, \"frmsQdPeak\": %d, \"bpsTxMean\": %d, \"bpsRxMean\": %d, \"frmQMax\": %d, \"l2rttMs\": %d, \"isRF\": %s}",
+ NODECALLLOPPED, LINK->apiSeq, LINK->LINKPORT->PORTNUMBER, LINK->receivingCall, LINK->callingCall,
+ LINK->bytesTXed, LINK->bytesRXed, LINK->framesTXed, LINK->framesRXed, 0, LINK->framesResent,
+ (int)Now - LINK->ConnectTime, LINK->maxQueued, bpsTx, bpsRx, LINK->intervalMaxQueued, LINK->RTT, (LINK->LINKPORT->isRF)?"true":"false");
else
udplen = sprintf(UDPMsg, "{\"@type\":\"LinkStatus\", \"node\": \"%s\", \"id\": %d, \"direction\": \"incoming\", \"port\": \"%d\", \"remote\": \"%s\", \"local\": \"%s\","
- "\"bytesSent\": %d, \"bytesRcvd\": %d, \"frmsSent\": %d, \"frmsRcvd\": %d, \"frmsQueued\": %d, \"frmsResent\": %d}",
- NODECALLLOPPED, UDPSeq++, LINK->LINKPORT->PORTNUMBER, LINK->callingCall, LINK->receivingCall,
- LINK->bytesTXed , LINK->bytesRXed, LINK->framesTXed, LINK->framesRXed, COUNT_AT_L2(LINK), LINK->framesResent);
+ "\"bytesSent\": %d, \"bytesRcvd\": %d, \"frmsSent\": %d, \"frmsRcvd\": %d, \"frmsQueued\": %d, \"frmsResent\": %d,"
+ "\"upForSecs\": %d, \"frmsQdPeak\": %d, \"bpsTxMean\": %d, \"bpsRxMean\": %d, \"frmQMax\": %d, \"l2rttMs\": %d, \"isRF\": %s}",
+ NODECALLLOPPED, LINK->apiSeq, LINK->LINKPORT->PORTNUMBER, LINK->callingCall, LINK->receivingCall,
+ LINK->bytesTXed, LINK->bytesRXed, LINK->framesTXed, LINK->framesRXed, 0, LINK->framesResent,
+ (int)Now - LINK->ConnectTime, LINK->maxQueued, bpsTx, bpsRx, LINK->intervalMaxQueued, LINK->RTT, (LINK->LINKPORT->isRF)?"true":"false");
-// Debugprintf(UDPMsg);
+ LINK->intervalMaxQueued = 0;
+// Debugprintf(UDPMsg);
sendto(NodeAPISocket, UDPMsg, udplen, 0, (struct sockaddr *)&UDPreportdest, sizeof(UDPreportdest));
}
}
@@ -412,8 +442,9 @@ void hookNodeClosing(char * Reason) if (NodeAPISocket)
{
- udplen = sprintf(UDPMsg, "{\"@type\": \"NodeDownEvent\", \"nodeCall\": \"%s\", \"nodeAlias\": \"%s\", \"reason\": \"%s\"}",
- NODECALLLOPPED, MYALIASLOPPED, Reason);
+ udplen = sprintf(UDPMsg, "{\"@type\": \"NodeDownEvent\", \"nodeCall\": \"%s\", \"nodeAlias\": \"%s\", \"reason\": \"%s\", \"uptimeSecs\": %d,"
+ "\"linksIn\": %d, \"linksOut\": %d, \"cctsIn\": %d, \"cctsOut\": %d, \"l3Relayed\": %d}",
+ NODECALLLOPPED, MYALIASLOPPED, Reason, time(NULL) - TimeLoaded, L2CONNECTSIN, L2CONNECTSOUT, L4CONNECTSIN, L4CONNECTSOUT, L3FRAMES);
// Debugprintf(UDPMsg);
@@ -438,9 +469,10 @@ void hookNodeRunning() {
udplen = sprintf(UDPMsg, "{\"@type\": \"NodeStatus\", \"nodeCall\": \"%s\", \"nodeAlias\": \"%s\", \"locator\": \"%s\","
- "\"latitude\": %f, \"longitude\": %f, \"software\": \"%s\", \"version\": \"%s\", \"uptimeSecs\": %d}",
- NODECALLLOPPED, MYALIASLOPPED, LOC, LatFromLOC, LonFromLOC, Software, VersionString, time(NULL) - TimeLoaded);
-
+ "\"latitude\": %f, \"longitude\": %f, \"software\": \"%s\", \"version\": \"%s\", \"uptimeSecs\": %d,"
+ "\"linksIn\": %d, \"linksOut\": %d, \"cctsIn\": %d, \"cctsOut\": %d, \"l3Relayed\": %d}",
+ NODECALLLOPPED, MYALIASLOPPED, LOC, LatFromLOC, LonFromLOC, Software, VersionString, time(NULL) - TimeLoaded,
+ L2CONNECTSIN, L2CONNECTSOUT, L4CONNECTSIN, L4CONNECTSOUT, L3FRAMES);
// Debugprintf(UDPMsg);
@@ -456,11 +488,17 @@ void IncomingL4ConnectionEvent(TRANSPORTENTRY * L4) char remotecall[64];
char ourcall[64];
char circuitinfo[32];
+ int Service = L4->Service;
// CACK sent to CREQ
+ L4->apiSeq = cctSeq++;
+ strcpy(L4->Direction, "incoming");
+
if (NodeAPISocket)
{
+ L4->lastStatusSentTime = time(NULL);
+
remotecall[ConvFromAX25(L4->L4TARGET.DEST->DEST_CALL, remotecall)] = 0;
// remotecall[ConvFromAX25(L4->L4USER, remotecall)] = 0;
ourcall[ConvFromAX25(L4->L4MYCALL, ourcall)] = 0;
@@ -470,10 +508,16 @@ void IncomingL4ConnectionEvent(TRANSPORTENTRY * L4) sprintf(circuitinfo, ":%02x%02x", L4->CIRCUITINDEX, L4->CIRCUITID);
strcat(ourcall, circuitinfo);
-
- udplen = sprintf(UDPMsg, "{\"@type\": \"CircuitUpEvent\", \"node\": \"%s\", \"id\": %d, \"direction\": \"incoming\","
+
+ if (Service == -1)
+ udplen = sprintf(UDPMsg, "{\"@type\": \"CircuitUpEvent\", \"node\": \"%s\", \"id\": %d, \"direction\": \"incoming\", "
+ "\"remote\": \"%s\", \"local\": \"%s\"}",
+ NODECALLLOPPED, L4->apiSeq, remotecall, ourcall);
+ else
+ udplen = sprintf(UDPMsg, "{\"@type\": \"CircuitUpEvent\", \"node\": \"%s\", \"id\": %d, \"direction\": \"incoming\", "
"\"service\": %d, \"remote\": \"%s\", \"local\": \"%s\"}",
- NODECALLLOPPED, UDPSeq++, L4->Service, remotecall, ourcall);
+ NODECALLLOPPED, L4->apiSeq, Service, remotecall, ourcall);
+
// Debugprintf(UDPMsg);
sendto(NodeAPISocket, UDPMsg, udplen, 0, (struct sockaddr *)&UDPreportdest, sizeof(UDPreportdest));
@@ -488,11 +532,18 @@ void OutgoingL4ConnectionEvent(TRANSPORTENTRY * L4) char remotecall[64];
char ourcall[64];
char circuitinfo[32];
+ int Service = L4->Service;
// CACK received
+ strcpy(L4->Direction, "outgoing");
+
+ L4->apiSeq = cctSeq++;
+
if (NodeAPISocket)
{
+ L4->lastStatusSentTime = time(NULL);
+
remotecall[ConvFromAX25(L4->L4TARGET.DEST->DEST_CALL, remotecall)] = 0;
// remotecall[ConvFromAX25(L4->L4USER, remotecall)] = 0;
ourcall[ConvFromAX25(L4->L4MYCALL, ourcall)] = 0;
@@ -503,9 +554,14 @@ void OutgoingL4ConnectionEvent(TRANSPORTENTRY * L4) sprintf(circuitinfo, ":%02x%02x", L4->CIRCUITID, L4->CIRCUITINDEX);
strcat(ourcall, circuitinfo);
- udplen = sprintf(UDPMsg, "{\"@type\": \"CircuitUpEvent\", \"node\": \"%s\", \"id\": %d, \"direction\": \"outgoing\","
+ if (Service == -1)
+ udplen = sprintf(UDPMsg, "{\"@type\": \"CircuitUpEvent\", \"node\": \"%s\", \"id\": %d, \"direction\": \"outgoing\", "
+ "\"remote\": \"%s\", \"local\": \"%s\"}",
+ NODECALLLOPPED, L4->apiSeq, remotecall, ourcall);
+ else
+ udplen = sprintf(UDPMsg, "{\"@type\": \"CircuitUpEvent\", \"node\": \"%s\", \"id\": %d, \"direction\": \"outgoing\", "
"\"service\": %d, \"remote\": \"%s\", \"local\": \"%s\"}",
- NODECALLLOPPED, UDPSeq++, L4->Service, remotecall, ourcall);
+ NODECALLLOPPED, L4->apiSeq, Service, remotecall, ourcall);
// Debugprintf(UDPMsg);
sendto(NodeAPISocket, UDPMsg, udplen, 0, (struct sockaddr *)&UDPreportdest, sizeof(UDPreportdest));
@@ -563,7 +619,7 @@ void L4DisconnectEvent(TRANSPORTENTRY * L4, char * Direction, char * Reason) udplen = sprintf(UDPMsg, "{\"@type\": \"CircuitDownEvent\", \"node\": \"%s\", \"id\": %d, \"direction\": \"%s\","
"\"service\": %d, \"remote\": \"%s\", \"local\": \"%s\", \"segsSent\": %d, \"segsRcvd\": %d, \"segsResent\": %d, \"segsQueued\": %d, \"reason\": \"%s\"}",
- NODECALLLOPPED, UDPSeq++, Direction, 0, remotecall, ourcall,L4->segsSent, L4->segsRcvd, L4->segsResent, Count, Reason);
+ NODECALLLOPPED, L4->apiSeq, Direction, 0, remotecall, ourcall,L4->segsSent, L4->segsRcvd, L4->segsResent, Count, Reason);
// Debugprintf(UDPMsg);
sendto(NodeAPISocket, UDPMsg, udplen, 0, (struct sockaddr *)&UDPreportdest, sizeof(UDPreportdest));
@@ -579,11 +635,16 @@ void L4StatusSeport(TRANSPORTENTRY * L4) char nodecall[16];
char circuitinfo[32];
int Count;
+ time_t Now = time(NULL);
+ int Service = L4->Service;
+
- // CACK received
+
+ // Regular Status reports
if (NodeAPISocket)
{
+ L4->lastStatusSentTime = Now;
nodecall[ConvFromAX25(L4->L4TARGET.DEST->DEST_CALL, nodecall)] = 0;
remotecall[ConvFromAX25(L4->L4USER, remotecall)] = 0;
ourcall[ConvFromAX25(L4->L4MYCALL, ourcall)] = 0;
@@ -599,10 +660,15 @@ void L4StatusSeport(TRANSPORTENTRY * L4) Count = CountFramesQueuedOnSession(L4->L4CROSSLINK);
else
Count = CountFramesQueuedOnSession(L4);
-
- udplen = sprintf(UDPMsg, "{\"@type\": \"CircuitStatus\", \"node\": \"%s\", \"id\": %d, \"direction\": \"outgoing\","
- "\"service\": %d, \"remote\": %s, \"local\": \"%s\", \"segsSent\": %d, \"segsRcvd\": %d, \"segsResent\": %d, \"segsQueued\": %d}",
- NODECALLLOPPED, UDPSeq++, 0, remotecall, ourcall,L4->segsSent, L4->segsRcvd, L4->segsResent, Count);
+
+ if (Service == -1)
+ udplen = sprintf(UDPMsg, "{\"@type\": \"CircuitStatus\", \"node\": \"%s\", \"id\": %d, \"direction\": \"%s\","
+ "\"upForSecs\": %d,\"remote\": \"%s\", \"local\": \"%s\", \"segsSent\": %d, \"segsRcvd\": %d, \"segsResent\": %d, \"segsQueued\": %d}",
+ NODECALLLOPPED, L4->apiSeq, L4->Direction, Now - L4->ConnectTime, remotecall, ourcall,L4->segsSent, L4->segsRcvd, L4->segsResent, Count);
+ else
+ udplen = sprintf(UDPMsg, "{\"@type\": \"CircuitStatus\", \"node\": \"%s\", \"id\": %d, \"direction\": \"%s\","
+ "\"upForSecs\": %d, \"service\": %d, \"remote\": \"%s\", \"local\": \"%s\", \"segsSent\": %d, \"segsRcvd\": %d, \"segsResent\": %d, \"segsQueued\": %d}",
+ NODECALLLOPPED, L4->apiSeq, L4->Direction, Now - L4->ConnectTime, Service, remotecall, ourcall,L4->segsSent, L4->segsRcvd, L4->segsResent, Count);
// Debugprintf(UDPMsg);
sendto(NodeAPISocket, UDPMsg, udplen, 0, (struct sockaddr *)&UDPreportdest, sizeof(UDPreportdest));
@@ -633,7 +699,42 @@ char * PIDtoText(int PID) return "?";
}
-void APIL2Trace(struct _MESSAGE * Message, char Dirn)
+void dumpDuffPacket(char * call, char * Buffer, int Len)
+{
+ // log to syslog in base64
+
+ char * Base64;
+
+ Base64 = byte_base64_encode(Buffer, Len);
+
+ Debugprintf("Trace Error %s %s", call, Base64);
+ free(Base64);
+}
+
+int checkCall(char * call, unsigned char * Buffer, int Len)
+{
+ char c;
+ int i;
+
+ // Validate source and dest calls - if duff, dump packet
+
+ for (i = 0; i < strlen(call); i++)
+ {
+ c = call[i];
+
+ if (isalnum(c) || c == '-' || c == '@')
+ continue;
+
+ dumpDuffPacket(call, Buffer, Len);
+ return 0;
+ }
+
+ return 1;
+}
+
+
+
+void APIL2Trace(struct _MESSAGE * Message, char * Dirn)
{
char UDPMsg[2048];
int udplen;
@@ -649,6 +750,12 @@ void APIL2Trace(struct _MESSAGE * Message, char Dirn) int UFlag = 0;
int NS;
int NR;
+ struct PORTCONTROL * PORT = GetPortTableEntryFromPortNum(Message->PORT);
+ time_t Now = time(NULL);
+
+
+ if (PORT == 0)
+ return;
if ((Message->ORIGIN[6] & 1) == 0) // Digis
return;
@@ -656,11 +763,18 @@ void APIL2Trace(struct _MESSAGE * Message, char Dirn) destcall[ConvFromAX25(Message->DEST, destcall)] = 0;
srcecall[ConvFromAX25(Message->ORIGIN, srcecall)] = 0;
- // See if any Digis
+ // Validate source and dest calls - if duff, dump packet
- if ((Message->ORIGIN[6] & 1) == 0) // Digis - ignore for now
+ if (!checkCall(destcall,(char *) Message, Message->LENGTH))
+ return;
+
+ if (!checkCall(srcecall, (char *) Message, Message->LENGTH))
return;
+
+ // see if any Digis
+ if ((Message->ORIGIN[6] & 1) == 0) // Digis - ignore for now
+ return;
if ((Message->DEST[6] & 0x80) == 0 && (Message->ORIGIN[6] & 0x80) == 0)
strcpy(CR, "V1");
@@ -784,9 +898,9 @@ void APIL2Trace(struct _MESSAGE * Message, char Dirn) // Common to all frame types
udplen = snprintf(UDPMsg, 2048,
- "{\"@type\": \"L2Trace\", \"reportFrom\": \"%s\", \"port\": \"%d\", \"srce\": \"%s\", \"dest\": \"%s\", \"ctrl\": %d,"
- "\"l2type\": \"%s\", \"modulo\": 8, \"cr\": \"%s\"",
- NODECALLLOPPED, Message->PORT, srcecall, destcall, Message->CTL, Type, CR);
+ "{\"@type\": \"L2Trace\", \"serial\": %d, \"time\": %d, \"dirn\": \"%s\", \"isRF\": %s, \"reportFrom\": \"%s\", \"port\": \"%d\", \"srce\": \"%s\", \"dest\": \"%s\", \"ctrl\": %d,"
+ "\"l2Type\": \"%s\", \"modulo\": 8, \"cr\": \"%s\"",
+ UDPSeq++, (int)Now, Dirn, (PORT->isRF)?"true":"false", NODECALLLOPPED, Message->PORT, srcecall, destcall, Message->CTL, Type, CR);
if (UIFlag)
{
@@ -830,9 +944,9 @@ void APIL2Trace(struct _MESSAGE * Message, char Dirn) // supervisory
if (PF[0])
- udplen += snprintf(&UDPMsg[udplen], 2048 - udplen, ", \"pf\": \"%s\", \"rseq\": %d, \"tseq\": %d", PF, NR, NS);
+ udplen += snprintf(&UDPMsg[udplen], 2048 - udplen, ", \"pf\": \"%s\", \"rseq\": %d", PF, NR);
else
- udplen += snprintf(&UDPMsg[udplen], 2048 - udplen, ", \"rseq\": %d, \"tseq\": %d", NR, NS);
+ udplen += snprintf(&UDPMsg[udplen], 2048 - udplen, ", \"rseq\": %d", NR);
}
@@ -844,6 +958,48 @@ void APIL2Trace(struct _MESSAGE * Message, char Dirn) }
+ //"@type" = @L3Trace, reportFrom, time, dirn,
+
+void NetromTCPTrace(struct _MESSAGE * Message, char * Dirn)
+{
+ char UDPMsg[2048];
+ int udplen;
+ time_t Now = time(NULL);
+ int iLen = Message->LENGTH - (15 + MSGHDDRLEN);
+ int isRF = 0;
+
+
+ udplen = snprintf(UDPMsg, 2048,
+ "{\"@type\": \"L3Trace\", \"serial\": %d, \"time\": %d, \"dirn\": \"%s\", \"isRF\": %s, \"reportFrom\": \"%s\", \"port\": %d",
+ UDPSeq++, (int)Now, Dirn, (isRF)?"true":"false", NODECALLLOPPED, Message->PORT);
+
+
+ udplen += snprintf(&UDPMsg[udplen], 2048 - udplen,
+ ", \"ilen\": %d, \"pid\": %d, \"ptcl\": \"%s\"",
+ iLen, Message->PID, PIDtoText(Message->PID));
+
+ if (Message->PID == NETROM_PID)
+ {
+ int n = decodeNETROMIFrame(Message->L2DATA, iLen, &UDPMsg[udplen], 2048 - udplen);
+
+ if (n == 0)
+ return; // Can't decode so don't trace anything;
+
+ udplen += n;
+ }
+
+
+
+ UDPMsg[udplen++] = '}';
+ UDPMsg[udplen] = 0;
+// Debugprintf(UDPMsg);
+ sendto(NodeAPISocket, UDPMsg, udplen, 0, (struct sockaddr *)&UDPreportdest, sizeof(UDPreportdest));
+
+}
+
+
+
+
int decodeNETROMUIMsg(unsigned char * Msg, int iLen, char * Buffer, int BufferLen)
{
int Len = 0;
@@ -870,7 +1026,7 @@ int decodeNETROMUIMsg(unsigned char * Msg, int iLen, char * Buffer, int BufferLe Msg += 7; // to first field
- Len = snprintf(Buffer, BufferLen, ", \"l3Type\": \"Routing info\", \"type\": \"NODES\", \"nodes\": [");
+ Len = snprintf(Buffer, BufferLen, ", \"l3Type\": \"Routing info\", \"type\": \"NODES\", \"fromAlias\": \"%s\", \"nodes\": [", Alias);
iLen -= 7; //Header, mnemonic and signature length
@@ -921,6 +1077,13 @@ int decodeNETROMIFrame(unsigned char * Msg, int iLen, char * Buffer, int BufferL destcall[ConvFromAX25(L3MSG->L3DEST, destcall)] = 0;
srcecall[ConvFromAX25(L3MSG->L3SRCE, srcecall)] = 0;
+ if (!checkCall(destcall, Msg, iLen))
+ return 0;
+
+ if (!checkCall(srcecall, Msg, iLen))
+ return 0;
+
+
if (strcmp(destcall, "KEEPLI") == 0)
return 0;
@@ -955,6 +1118,14 @@ int decodeNETROMIFrame(unsigned char * Msg, int iLen, char * Buffer, int BufferL srcUser[ConvFromAX25(&L3MSG->L4DATA[1], srcUser)] = 0;
srcNode[ConvFromAX25(&L3MSG->L4DATA[8], srcNode)] = 0;
+ if (!checkCall(srcUser, Msg, iLen))
+ return 0;
+
+
+ if (!checkCall(srcNode, Msg, iLen))
+ return 0;
+
+
if (netromx)
Len += snprintf(&Buffer[Len], BufferLen - Len, ", \"l4Type\": \"CONN REQX\", \"fromCct\": %d, \"srcUser\": \"%s\", \"srcNode\": \"%s\", \"window\": %d, \"service\": %d",
(L3MSG->L4INDEX << 8) | L3MSG->L4ID, srcUser, srcNode, L3MSG->L4DATA[0], service);
@@ -969,7 +1140,7 @@ int decodeNETROMIFrame(unsigned char * Msg, int iLen, char * Buffer, int BufferL // Can be ACK or NACK depending on Choke flag
if (L3MSG->L4FLAGS & L4BUSY)
- Len += snprintf(&Buffer[Len], BufferLen - Len, ", \"l4Type\": \"CONN NACK\", \"toCct\": %d",
+ Len += snprintf(&Buffer[Len], BufferLen - Len, ", \"l4Type\": \"CONN NAK\", \"toCct\": %d",
(L3MSG->L4INDEX << 8) | L3MSG->L4ID);
else
Len += snprintf(&Buffer[Len], BufferLen - Len, ", \"l4Type\": \"CONN ACK\", \"toCct\": %d, \"fromCct\": %d, \"accWin\": %d",
@@ -1073,7 +1244,7 @@ int decodeRecordRoute(L3MESSAGE * L3, int iLen, char * Buffer, int BufferLen) Len += snprintf(&Buffer[Len], BufferLen - Len, ", \"l4Type\": \"NRR Request\", \"nrrId\": %d, \"nrrRoute\": \"%s\"",
(L3->L4TXNO << 8) | L3->L4RXNO, callList);
- Debugprintf(Buffer);
+// Debugprintf(Buffer);
return Len;
}
|
