From 85f200a46cf5e002e59e36b11ab4fba2f0422b33 Mon Sep 17 00:00:00 2001 From: Dave Hibberd Date: Tue, 11 Nov 2025 21:50:47 +0000 Subject: New upstream version 6.0.25.11+repack --- Events.c | 1001 ++++++++++---------------------------------------------------- 1 file changed, 155 insertions(+), 846 deletions(-) (limited to 'Events.c') diff --git a/Events.c b/Events.c index 1a64b3b..bb2a8ef 100644 --- a/Events.c +++ b/Events.c @@ -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,18 +60,6 @@ extern char LOC[7]; extern char VersionString[50]; extern double LatFromLOC; extern double LonFromLOC; -<<<<<<< Updated upstream - -void hookL2SessionClosed(struct _LINKTABLE * LINK, char * Reason, char * Direction); -int ConvFromAX25(unsigned char * incall, unsigned char * outcall); -int COUNT_AT_L2(struct _LINKTABLE * LINK); -int CountFramesQueuedOnSession(TRANSPORTENTRY * Session); -int decodeNETROMUIMsg(unsigned char * Msg, int iLen, char * Buffer, int BufferLen); -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); -||||||| Stash base -======= extern int NUMBEROFNODES, MAXDESTS, L4CONNECTSOUT, L4CONNECTSIN, L4FRAMESTX, L4FRAMESRX, L4FRAMESRETRIED, OLDFRAMES; extern int L2CONNECTSOUT, L2CONNECTSIN; @@ -81,7 +72,6 @@ int decodeNETROMIFrame(unsigned char * Msg, int iLen, char * Buffer, int BufferL 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); ->>>>>>> Stashed changes // Runs use specified routine on certain event @@ -157,27 +147,12 @@ DllExport void APIENTRY RunEventProgram(char * Program, char * Param) void hookL2SessionAccepted(int Port, char * remotecall, char * ourcall, struct _LINKTABLE * LINK) { // Incoming SABM accepted -<<<<<<< Updated upstream - - char UDPMsg[1024]; - int udplen; -||||||| Stash base - // Incoming SABM -======= ->>>>>>> Stashed changes -<<<<<<< Updated upstream - LINK->ConnectTime = time(NULL); - LINK->bytesTXed = LINK->bytesRXed = LINK->framesResent = LINK->framesRXed = LINK->framesTXed = 0; -||||||| Stash base - LINK->ConnectTime = time(NULL); - LINK->bytesTXed = LINK->bytesRXed = 0; -======= char UDPMsg[1024]; int udplen; ->>>>>>> Stashed changes L2CONNECTSIN++; + LINK->apiSeq = linkSeq++; LINK->lastStatusSentTime = LINK->ConnectTime = time(NULL); LINK->bytesTXed = LINK->bytesRXed = LINK->framesResent = LINK->framesRXed = LINK->framesTXed = 0; @@ -190,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); @@ -251,19 +226,9 @@ void hookL2SessionDeleted(struct _LINKTABLE * LINK) void hookL2SessionAttempt(int Port, char * ourcall, char * remotecall, struct _LINKTABLE * LINK) { -<<<<<<< Updated upstream - LINK->ConnectTime = time(NULL); - LINK->bytesTXed = LINK->bytesRXed = LINK->framesResent = LINK->framesRXed = LINK->framesTXed = 0; - -||||||| Stash base - LINK->ConnectTime = time(NULL); - LINK->bytesTXed = LINK->bytesRXed = 0; - -======= LINK->lastStatusSentTime = LINK->ConnectTime = time(NULL); LINK->bytesTXed = LINK->bytesRXed = LINK->framesResent = LINK->framesRXed = LINK->framesTXed = 0; LINK->LastStatusbytesTXed = LINK->LastStatusbytesRXed = 0; ->>>>>>> Stashed changes strcpy(LINK->callingCall, ourcall); strcpy(LINK->receivingCall, remotecall); strcpy(LINK->Direction, "Out"); @@ -276,82 +241,15 @@ void hookL2SessionConnected(struct _LINKTABLE * LINK) char UDPMsg[1024]; int udplen; -<<<<<<< Updated upstream - 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); - -// Debugprintf(UDPMsg); - - sendto(NodeAPISocket, UDPMsg, udplen, 0, (struct sockaddr *)&UDPreportdest, sizeof(UDPreportdest)); - } -} - -void hookL2SessionClosed(struct _LINKTABLE * LINK, char * Reason, char * Direction) -{ - // Link closed. Could be normal, ie disc send/received or restried out etc - - char UDPMsg[1024]; - int udplen; - - if (NodeAPISocket) - { - if (LINK->receivingCall[0] == 0 || LINK->callingCall[0] == 0) - return; - - 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); - 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); - -// Debugprintf(UDPMsg); - - sendto(NodeAPISocket, UDPMsg, udplen, 0, (struct sockaddr *)&UDPreportdest, sizeof(UDPreportdest)); - } -} - -void hookL2SessionStatus(struct _LINKTABLE * LINK) -{ - // Send at regular intervals on open links - - char UDPMsg[1024]; - int udplen; - - if (NodeAPISocket) - { - LINK->lastStatusSentTime = time(NULL); - - 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); - 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); - -// Debugprintf(UDPMsg); -||||||| Stash base -======= 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); @@ -375,20 +273,19 @@ 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\"," - " \"time\": %d, \"upForSecs\": %d, \"frmsQdPeak\": %d}", - NODECALLLOPPED, UDPSeq++, LINK->LINKPORT->PORTNUMBER, LINK->receivingCall, LINK->callingCall, + " \"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); + (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\"," - " \"time\": %d, \"upForSecs\": %d, \"frmsQdPeak\": %d}", - NODECALLLOPPED, UDPSeq++, LINK->LINKPORT->PORTNUMBER, LINK->callingCall, LINK->receivingCall, + " \"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); - + (int)Now, (int)Now - LINK->ConnectTime, LINK->maxQueued, (LINK->LINKPORT->isRF)?"true":"false"); - Debugprintf(UDPMsg); +// Debugprintf(UDPMsg); sendto(NodeAPISocket, UDPMsg, udplen, 0, (struct sockaddr *)&UDPreportdest, sizeof(UDPreportdest)); } @@ -416,23 +313,21 @@ void hookL2SessionStatus(struct _LINKTABLE * LINK) 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," - "\"upForSecs\": %d, \"frmsQdPeak\": %d, \"bpsTxMean\": %d, \"bpsRxMean\": %d, \"frmQMax\": %d, \"l2rttMs\": %d}", - NODECALLLOPPED, UDPSeq++, LINK->LINKPORT->PORTNUMBER, LINK->receivingCall, LINK->callingCall, + "\"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); + (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," - "\"upForSecs\": %d, \"frmsQdPeak\": %d, \"bpsTxMean\": %d, \"bpsRxMean\": %d, \"frmQMax\": %d, \"l2rttMs\": %d}", - NODECALLLOPPED, UDPSeq++, LINK->LINKPORT->PORTNUMBER, LINK->callingCall, LINK->receivingCall, + "\"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); + (int)Now - LINK->ConnectTime, LINK->maxQueued, bpsTx, bpsRx, LINK->intervalMaxQueued, LINK->RTT, (LINK->LINKPORT->isRF)?"true":"false"); LINK->intervalMaxQueued = 0; - Debugprintf(UDPMsg); ->>>>>>> Stashed changes - +// Debugprintf(UDPMsg); sendto(NodeAPISocket, UDPMsg, udplen, 0, (struct sockaddr *)&UDPreportdest, sizeof(UDPreportdest)); } } @@ -547,9 +442,9 @@ void hookNodeClosing(char * Reason) if (NodeAPISocket) { -<<<<<<< Updated upstream - 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); @@ -574,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); @@ -592,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; @@ -606,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)); @@ -624,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; @@ -639,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)); @@ -699,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)); @@ -715,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; @@ -735,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)); @@ -769,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; @@ -785,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; @@ -792,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"); @@ -920,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) { @@ -980,714 +958,46 @@ void APIL2Trace(struct _MESSAGE * Message, char Dirn) } -int decodeNETROMUIMsg(unsigned char * Msg, int iLen, char * Buffer, int BufferLen) -{ - int Len = 0; - - // UI with NETROM PID are assumed to by NODES broadcast (INP3 routes are sent in I frames) - - // But check first byte is 0xff to be sure, or 0xfe for Paula's char Alias[7]= ""; - - char Dest[10]; - char Node[10]; - char Alias[10] = ""; - - memcpy(Alias, &Msg[1], 6); - strlop(Alias, ' '); - - if (Msg[0] == 0xfe) // Paula's Nodes Poll - { - Len = snprintf(Buffer, BufferLen, ", \"l3Type\": \"Routing info\", \"type\": \"Routing poll\""); - return Len; - } - - if (Msg[0] != 0xff) - return 0; - - Msg += 7; // to first field - - Len = snprintf(Buffer, BufferLen, ", \"l3Type\": \"Routing info\", \"type\": \"NODES\", \"nodes\": ["); - - iLen -= 7; //Header, mnemonic and signature length - - if (iLen < 21) // No Entries - { - Buffer[Len++] = ']'; - return Len; - } - - while(iLen > 20) // Entries are 21 bytes - { - Dest[ConvFromAX25(Msg, Dest)] = 0; - Msg +=7; - memcpy(Alias, Msg, 6); - Msg +=6; - strlop(Alias, ' '); - Node[ConvFromAX25(Msg, Node)] = 0; - Msg +=7; - - Len += snprintf(&Buffer[Len], BufferLen - Len, "{\"call\": \"%s\", \"alias\": \"%s\", \"via\": \"%s\", \"qual\": %d},", Dest, Alias, Node, Msg[0]); - Msg++; - iLen -= 21; - } - // Have to replace trailing , with ] - - Buffer[Len - 1] = ']'; - return Len; -} + //"@type" = @L3Trace, reportFrom, time, dirn, -int decodeNETROMIFrame(unsigned char * Msg, int iLen, char * Buffer, int BufferLen) +void NetromTCPTrace(struct _MESSAGE * Message, char * Dirn) { - int Len = 0; - L3MESSAGE * L3MSG = (L3MESSAGE *)Msg; - char srcecall[64]; - char destcall[16]; - char srcUser[16]; - char srcNode[16]; - int Opcode; - int netromx = 0; - int service = 0; - - - if (Msg[0] == 0xff) // RIF? - return decodeINP3RIF(&Msg[1], iLen - 1, Buffer, BufferLen); - - // Netrom L3 /4 frame. Do standard L3 header - - destcall[ConvFromAX25(L3MSG->L3DEST, destcall)] = 0; - srcecall[ConvFromAX25(L3MSG->L3SRCE, srcecall)] = 0; + char UDPMsg[2048]; + int udplen; + time_t Now = time(NULL); + int iLen = Message->LENGTH - (15 + MSGHDDRLEN); + int isRF = 0; - if (strcmp(destcall, "KEEPLI") == 0) - return 0; - Len = snprintf(Buffer, BufferLen, ", \"l3Type\": \"NetRom\", \"l3src\": \"%s\", \"l3dst\": \"%s\", \"ttl\": %d", srcecall, destcall, L3MSG->L3TTL); + 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); - // L4 Stuff - Opcode = L3MSG->L4FLAGS & 15; + udplen += snprintf(&UDPMsg[udplen], 2048 - udplen, + ", \"ilen\": %d, \"pid\": %d, \"ptcl\": \"%s\"", + iLen, Message->PID, PIDtoText(Message->PID)); - switch (Opcode) + if (Message->PID == NETROM_PID) { - case 0: + int n = decodeNETROMIFrame(Message->L2DATA, iLen, &UDPMsg[udplen], 2048 - udplen); - // OPCODE 0 is used for a variety of functions, using L4INDEX and L4ID as qualifiers - // 0c0c is used for IP. Ignore for now + if (n == 0) + return; // Can't decode so don't trace anything; - // 00 01 Seesm to be Netrom Record Route + udplen += n; + } - if (L3MSG->L4ID == 1 && L3MSG->L4INDEX == 0) - { - Len += decodeRecordRoute(L3MSG, iLen, &Buffer[Len], BufferLen - Len); - return Len; - } - case L4CREQX: - netromx = 1; - service = (L3MSG->L4RXNO << 8) | L3MSG->L4TXNO; + UDPMsg[udplen++] = '}'; + UDPMsg[udplen] = 0; +// Debugprintf(UDPMsg); + sendto(NodeAPISocket, UDPMsg, udplen, 0, (struct sockaddr *)&UDPreportdest, sizeof(UDPreportdest)); - case L4CREQ: +} - srcUser[ConvFromAX25(&L3MSG->L4DATA[1], srcUser)] = 0; - srcNode[ConvFromAX25(&L3MSG->L4DATA[8], srcNode)] = 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); - else - Len += snprintf(&Buffer[Len], BufferLen - Len, ", \"l4Type\": \"CONN REQ\", \"fromCct\": %d, \"srcUser\": \"%s\", \"srcNode\": \"%s\", \"window\": %d", - (L3MSG->L4INDEX << 8) | L3MSG->L4ID, srcUser, srcNode, L3MSG->L4DATA[0]); - - return Len; - - case L4CACK: - - // Can be ACK or NACK depending on Choke flag - - if (L3MSG->L4FLAGS & L4BUSY) - Len += snprintf(&Buffer[Len], BufferLen - Len, ", \"l4Type\": \"CONN NACK\", \"toCct\": %d", - (L3MSG->L4INDEX << 8) | L3MSG->L4ID); - else - Len += snprintf(&Buffer[Len], BufferLen - Len, ", \"l4Type\": \"CONN ACK\", \"toCct\": %d, \"fromCct\": %d, \"accWin\": %d", - (L3MSG->L4INDEX << 8) | L3MSG->L4ID, (L3MSG->L4TXNO << 8) | L3MSG->L4RXNO, L3MSG->L4DATA[0]); - - return Len; - - - case L4INFO: - - Len += snprintf(&Buffer[Len], BufferLen - Len, ", \"l4Type\": \"INFO\", \"toCct\": %d, \"txSeq\": %d, \"rxSeq\": %d, \"paylen\": %d", - (L3MSG->L4INDEX << 8) | L3MSG->L4ID, L3MSG->L4TXNO, L3MSG->L4RXNO, iLen - 20); - - return Len; - - case L4IACK: - - Len += snprintf(&Buffer[Len], BufferLen - Len, ", \"l4Type\": \"INFO ACK\", \"toCct\": %d, \"rxSeq\": %d", - (L3MSG->L4INDEX << 8) | L3MSG->L4ID, L3MSG->L4RXNO); - - return Len; - - - case L4DREQ: - - Len += snprintf(&Buffer[Len], BufferLen - Len, ", \"l4Type\": \"DISC REQ\", \"toCct\": %d", (L3MSG->L4INDEX << 8) | L3MSG->L4ID); - return Len; - - case L4DACK: - - Len += snprintf(&Buffer[Len], BufferLen - Len, ", \"l4Type\": \"DISC ACK\", \"toCct\": %d", (L3MSG->L4INDEX << 8) | L3MSG->L4ID); - return Len; - - case L4RESET: - - Len += snprintf(&Buffer[Len], BufferLen - Len, ", \"l4Type\": \"RSET\", \"fromCct\": %d", (L3MSG->L4INDEX << 8) | L3MSG->L4ID); - return Len; - - - /* - "NRR Request" Netrom Record Route Request - "NRR Reply" Netrom Record Route Reply - "CONN REQ" Connect Request - "CONN REQX" Extended Connect Request - "CONN ACK" Connection Acknowledgement - "CONN NAK" Connection Negative Ack (refusal) - "DISC REQ" Disconnect request - "DISC ACK" Disconnect Acknowledgement - "INFO" Information-bearing frame - "INFO ACK" Acknowledgement for an INFO frame. - "RSET" Circuit Reset (kill) - "PROT EXT" Protocol Extension (e.g. IP, NCMP etc) - "unknown" Unrecognised type (shouldn't happen) - - - - - "l4type": "CONN ACK", - "fromCct": 10, - "toCct": 23809, - "accWin": 4, - */ - - } - return Len; -} - -int decodeRecordRoute(L3MESSAGE * L3, int iLen, char * Buffer, int BufferLen) -{ - int Len = 0; - char callList[512]; - char * ptr1 = callList; - unsigned char * ptr = L3->L4DATA; - char call[16]; - int Response = 0; - - iLen -= 20; - - while (iLen > 0) - { - call[ConvFromAX25(ptr, call)] = 0; - - ptr1 += sprintf(ptr1, " %s", call); - - if ((ptr[7] & 0x80) == 0x80) // Check turnround bit - { - *ptr1++ = '*'; - Response = 1; - } - - ptr += 8; - iLen -= 8; - } - - *ptr1 = 0; - - if (Response) - Len += snprintf(&Buffer[Len], BufferLen - Len, ", \"l4Type\": \"NRR Reply\", \"nrrId\": %d, \"nrrRoute\": \"%s\"", - (L3->L4TXNO << 8) | L3->L4RXNO, callList); - else - Len += snprintf(&Buffer[Len], BufferLen - Len, ", \"l4Type\": \"NRR Request\", \"nrrId\": %d, \"nrrRoute\": \"%s\"", - (L3->L4TXNO << 8) | L3->L4RXNO, callList); - - Debugprintf(Buffer); -||||||| Stash base -======= - 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); - - sendto(NodeAPISocket, UDPMsg, udplen, 0, (struct sockaddr *)&UDPreportdest, sizeof(UDPreportdest)); - } -} - -void hookNodeRunning() -{ - char UDPMsg[1024]; - int udplen; -#ifdef LINBPQ - char Software[80] = "LinBPQ"; - - if (sizeof(void *) == 4) - strcat(Software, "(32 bit)"); -#else - char Software[80] = "BPQ32"; -#endif - - if (NodeAPISocket) - { - - udplen = sprintf(UDPMsg, "{\"@type\": \"NodeStatus\", \"nodeCall\": \"%s\", \"nodeAlias\": \"%s\", \"locator\": \"%s\"," - "\"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); - - sendto(NodeAPISocket, UDPMsg, udplen, 0, (struct sockaddr *)&UDPreportdest, sizeof(UDPreportdest)); - } -} - -void IncomingL4ConnectionEvent(TRANSPORTENTRY * L4) -{ - char UDPMsg[1024]; - int udplen; - - char remotecall[64]; - char ourcall[64]; - char circuitinfo[32]; - - // CACK sent to CREQ - - if (NodeAPISocket) - { - remotecall[ConvFromAX25(L4->L4TARGET.DEST->DEST_CALL, remotecall)] = 0; - // remotecall[ConvFromAX25(L4->L4USER, remotecall)] = 0; - ourcall[ConvFromAX25(L4->L4MYCALL, ourcall)] = 0; - - sprintf(circuitinfo, ":%02x%02x", L4->FARINDEX, L4->FARID); - strcat(remotecall, circuitinfo); - - sprintf(circuitinfo, ":%02x%02x", L4->CIRCUITINDEX, L4->CIRCUITID); - strcat(ourcall, circuitinfo); - - udplen = sprintf(UDPMsg, "{\"@type\": \"CircuitUpEvent\", \"node\": \"%s\", \"id\": %d, \"direction\": \"incoming\"," - "\"service\": %d, \"remote\": \"%s\", \"local\": \"%s\"}", - NODECALLLOPPED, UDPSeq++, L4->Service, remotecall, ourcall); - -// Debugprintf(UDPMsg); - sendto(NodeAPISocket, UDPMsg, udplen, 0, (struct sockaddr *)&UDPreportdest, sizeof(UDPreportdest)); - } -} - - -void OutgoingL4ConnectionEvent(TRANSPORTENTRY * L4) -{ - char UDPMsg[1024]; - int udplen; - char remotecall[64]; - char ourcall[64]; - char circuitinfo[32]; - - // CACK received - - if (NodeAPISocket) - { - remotecall[ConvFromAX25(L4->L4TARGET.DEST->DEST_CALL, remotecall)] = 0; - // remotecall[ConvFromAX25(L4->L4USER, remotecall)] = 0; - ourcall[ConvFromAX25(L4->L4MYCALL, ourcall)] = 0; - - sprintf(circuitinfo, ":%02x%02x", L4->FARID, L4->FARINDEX); - strcat(remotecall, circuitinfo); - - sprintf(circuitinfo, ":%02x%02x", L4->CIRCUITID, L4->CIRCUITINDEX); - strcat(ourcall, circuitinfo); - - udplen = sprintf(UDPMsg, "{\"@type\": \"CircuitUpEvent\", \"node\": \"%s\", \"id\": %d, \"direction\": \"outgoing\"," - "\"service\": %d, \"remote\": \"%s\", \"local\": \"%s\"}", - NODECALLLOPPED, UDPSeq++, L4->Service, remotecall, ourcall); - -// Debugprintf(UDPMsg); - sendto(NodeAPISocket, UDPMsg, udplen, 0, (struct sockaddr *)&UDPreportdest, sizeof(UDPreportdest)); - } -} - -/* - { - "@type": "CircuitUpEvent", - "node": "G8PZT" - "id": 1, - "direction": "incoming", - "service": 0, - "remote": "G8PZT@G8PZT:14c0", - "local": "G8PZT-4:0001" - } - - - "segsSent": 5, - "segsRcvd": 27, - "segsResent": 0, - "segsQueued": 0, - "reason": "rcvd DREQ" - -*/ - -void L4DisconnectEvent(TRANSPORTENTRY * L4, char * Direction, char * Reason) -{ - char UDPMsg[1024]; - int udplen; - char remotecall[64]; - char ourcall[64]; - char circuitinfo[32]; - int Count; - - // CACK received - - if (NodeAPISocket) - { - remotecall[ConvFromAX25(L4->L4TARGET.DEST->DEST_CALL, remotecall)] = 0; -// remotecall[ConvFromAX25(L4->L4USER, remotecall)] = 0; - ourcall[ConvFromAX25(L4->L4MYCALL, ourcall)] = 0; - - sprintf(circuitinfo, ":%02x%02x", L4->FARINDEX, L4->FARID); - strcat(remotecall, circuitinfo); - - sprintf(circuitinfo, ":%02x%02x", L4->CIRCUITINDEX, L4->CIRCUITID); - strcat(ourcall, circuitinfo); - - - if (L4->L4CROSSLINK) // CONNECTED? - Count = CountFramesQueuedOnSession(L4->L4CROSSLINK); - else - Count = CountFramesQueuedOnSession(L4); - - 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); - -// Debugprintf(UDPMsg); - sendto(NodeAPISocket, UDPMsg, udplen, 0, (struct sockaddr *)&UDPreportdest, sizeof(UDPreportdest)); - } -} - -void L4StatusSeport(TRANSPORTENTRY * L4) -{ - char UDPMsg[1024]; - int udplen; - char remotecall[64]; - char ourcall[64]; - char nodecall[16]; - char circuitinfo[32]; - int Count; - - // CACK received - - if (NodeAPISocket) - { - nodecall[ConvFromAX25(L4->L4TARGET.DEST->DEST_CALL, nodecall)] = 0; - remotecall[ConvFromAX25(L4->L4USER, remotecall)] = 0; - ourcall[ConvFromAX25(L4->L4MYCALL, ourcall)] = 0; - - sprintf(circuitinfo, ":%02x%02x", L4->FARINDEX, L4->FARID); - strcat(remotecall, circuitinfo); - - sprintf(circuitinfo, ":%02x%02x", L4->CIRCUITINDEX, L4->CIRCUITID); - strcat(ourcall, circuitinfo); - - - if (L4->L4CROSSLINK) // CONNECTED? - 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); - -// Debugprintf(UDPMsg); - sendto(NodeAPISocket, UDPMsg, udplen, 0, (struct sockaddr *)&UDPreportdest, sizeof(UDPreportdest)); - } -} - - -// L2/3/4 Tracing - -#define PFBIT 0x10 // POLL/FINAL BIT IN CONTROL BYTE -#define NETROM_PID 0xCF -#define IP_PID 0xCC -#define ARP_PID 0xCD - -char * PIDtoText(int PID) -{ - switch (PID) - { - case 240: - return "DATA"; - case NETROM_PID: - return "NET/ROM"; - case IP_PID: - return "IP"; - case ARP_PID: - return "ARP"; - } - return "?"; -} - -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; - char srcecall[64]; - char destcall[16]; - char CR[3] = ""; - char PF[2] = ""; - int iLen = 0; - int CTL = Message->CTL; - char Type[16] = "Unknown"; - int UIFlag = 0; - int IFlag = 0; - int UFlag = 0; - int NS; - int NR; - - - if ((Message->ORIGIN[6] & 1) == 0) // Digis - return; - - destcall[ConvFromAX25(Message->DEST, destcall)] = 0; - srcecall[ConvFromAX25(Message->ORIGIN, srcecall)] = 0; - - // Validate source and dest calls - if duff, dump packet - - 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"); - else if ((Message->DEST[6] & 0x80)) - strcpy(CR, "C"); - else if (Message->ORIGIN[6] & 0x80) - strcpy(CR, "R"); - else - strcpy(CR, "V1"); - - if (CTL & PFBIT) - { - if (CR[0] == 'C') - PF[0] = 'P'; - else if (CR[0] == 'R') - PF[0] = 'F'; - } - - CTL &= ~PFBIT; - - if ((CTL & 1) == 0) // I frame - { - NS = (CTL >> 1) & 7; // ISOLATE RECEIVED N(S) - NR = (CTL >> 5) & 7; - - IFlag = 1; - iLen = Message->LENGTH - (MSGHDDRLEN + 16); // Dest origin ctl pid - - strcpy(Type, "I"); - } - else if (CTL == 3) - { - // Un-numbered Information Frame - - strcpy(Type, "UI"); - UIFlag = 1; - iLen = Message->LENGTH - (MSGHDDRLEN + 16); // Dest origin ctl pid - } - - if (CTL & 2) - { - // UnNumbered - - UFlag = 1; - - switch (CTL) - { - case SABM: - - strcpy(Type, "C"); - break; - - case SABME: - - strcpy(Type, "SABME"); - break; - - case XID: - - strcpy(Type, "XID"); - break; - - case TEST: - - strcpy(Type, "TEST"); - break; - - case DISC: - - strcpy(Type, "D"); - break; - - case DM: - - strcpy(Type, "DM"); - break; - - case UA: - - strcpy(Type, "UA"); - break; - - - case FRMR: - - strcpy(Type, "FRMR"); - break; - } - } - else - { - // Super - - NR = (CTL >> 5) & 7; - NS = (CTL >> 1) & 7; // ISOLATE RECEIVED N(S) - - switch (CTL & 0x0F) - { - case RR: - - strcpy(Type, "RR"); - break; - - case RNR: - - strcpy(Type, "RNR"); - break; - - case REJ: - - strcpy(Type, "REJ"); - break; - - case SREJ: - - strcpy(Type, "SREJ"); - break; - } - } - - // Common to all frame types - - udplen = snprintf(UDPMsg, 2048, - "{\"@type\": \"L2Trace\", \"dirn\": \"%s\", \"reportFrom\": \"%s\", \"port\": \"%d\", \"srce\": \"%s\", \"dest\": \"%s\", \"ctrl\": %d," - "\"l2Type\": \"%s\", \"modulo\": 8, \"cr\": \"%s\"", - Dirn, NODECALLLOPPED, Message->PORT, srcecall, destcall, Message->CTL, Type, CR); - - if (UIFlag) - { - udplen += snprintf(&UDPMsg[udplen], 2048 - udplen, - ", \"ilen\": %d, \"pid\": %d, \"ptcl\": \"%s\"", iLen, Message->PID, PIDtoText(Message->PID)); - - if (Message->PID == NETROM_PID) - { - udplen += decodeNETROMUIMsg(Message->L2DATA, iLen, &UDPMsg[udplen], 2048 - udplen); - } - } - else if (IFlag) - { - if (PF[0]) - udplen += snprintf(&UDPMsg[udplen], 2048 - udplen, - ", \"ilen\": %d, \"pid\": %d, \"ptcl\": \"%s\", \"pf\": \"%s\", \"rseq\": %d, \"tseq\": %d", - iLen, Message->PID, PIDtoText(Message->PID), PF, NR, NS); - else - udplen += snprintf(&UDPMsg[udplen], 2048 - udplen, - ", \"ilen\": %d, \"pid\": %d, \"ptcl\": \"%s\", \"rseq\": %d, \"tseq\": %d", - iLen, Message->PID, PIDtoText(Message->PID), NR, NS); - - 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; - } - - } - else if (UFlag) - { - if (PF[0]) - udplen += snprintf(&UDPMsg[udplen], 2048 - udplen, ", \"pf\": \"%s\"", PF); - } - else - { - // supervisory - - if (PF[0]) - udplen += snprintf(&UDPMsg[udplen], 2048 - udplen, ", \"pf\": \"%s\", \"rseq\": %d, \"tseq\": %d", PF, NR, NS); - else - udplen += snprintf(&UDPMsg[udplen], 2048 - udplen, ", \"rseq\": %d, \"tseq\": %d", NR, NS); - } - - - 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) @@ -1716,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 @@ -1935,7 +1245,6 @@ int decodeRecordRoute(L3MESSAGE * L3, int iLen, char * Buffer, int BufferLen) (L3->L4TXNO << 8) | L3->L4RXNO, callList); // Debugprintf(Buffer); ->>>>>>> Stashed changes return Len; } -- cgit v1.2.3