Skip to content
Merged
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
16 changes: 8 additions & 8 deletions include/stun_intern.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,15 @@ struct StunClientStats

typedef struct
{
STUN_STATE state;
bool inUse;
uint32_t inst;
STUN_STATE state;
bool inUse;
uint32_t inst;
StunBindReqStruct stunBindReq;

uint8_t stunReqMsgBuf[STUN_MAX_PACKET_SIZE]; /* encoded STUN request
* */
int stunReqMsgBufLen; /* of encoded STUN
*request */
int stunReqMsgBufLen; /* of encoded STUN
* request */

STUN_USER_CREDENTIALS userCredentials;
bool authenticated;
Expand All @@ -130,22 +130,22 @@ typedef struct
DiscussData discussData;

struct StunClientStats stats;
STUN_CLIENT_DATA* client;
STUN_CLIENT_DATA* client;

} STUN_TRANSACTION_DATA;


struct STUN_CLIENT_DATA
{
void* userCtx;
void* userCtx;
STUN_TRANSACTION_DATA data [MAX_STUN_TRANSACTIONS];


/*duplicated for logging on unknown transactions etc.*/
STUN_INFO_FUNC_PTR Log_cb;
void* logUserData;
struct StunClientStats stats;
struct hiutResult traceResult;
struct hiutResult traceResult;
};


Expand Down
33 changes: 10 additions & 23 deletions include/stunclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ StunClient_RegisterLogger(STUN_CLIENT_DATA* clientData,
* serverAddr - Address of TURN server in format "a.b.c.d:port"
* baseAddr - Address of BASE in format "a.b.c.d:port"
* proto - Optional context passed to sendFunc. eg.
*IPPROTO_UDP/TCP.
* IPPROTO_UDP/TCP.
* useRelay - True to send via TURN server
* uFrag - Combination of local and remote ufrag exchanged in
* INVITE(LFRAG) / OK(RFRAG) in format <LFRAG>:<RFRAG>
Expand Down Expand Up @@ -179,23 +179,7 @@ StunClient_startBindTransaction(STUN_CLIENT_DATA* clientData,
uint32_t sockhandle,
STUN_SENDFUNC sendFunc,
STUNCB stunCbFunc,
DiscussData* discussData); /*
*
*nullptr
*
*if
*
*no
*
*malicedata
*
*should
*
*be
*
*sent.
**/

DiscussData* discussData);
uint32_t
StunClient_startSTUNTrace(STUN_CLIENT_DATA* clientData,
void* userCtx,
Expand All @@ -209,11 +193,7 @@ StunClient_startSTUNTrace(STUN_CLIENT_DATA* clientData,
uint32_t sockhandle,
STUN_SENDFUNC sendFunc,
STUNCB stunCbFunc,
DiscussData* discussData); /*NULL
* if
*
*none*/

DiscussData* discussData);
/*
* This function must be called by the application every N msec. N must be same
* as in StunClientBind_Init(instances, N)
Expand Down Expand Up @@ -279,6 +259,13 @@ StunClient_dumpStats(STUN_CLIENT_DATA* clientData,
STUN_INFO_FUNC_PTR logPtr,
void* userData);

void
StunPrint(void* userData,
STUN_INFO_FUNC_PTR Log_cb,
StunInfoCategory_T category,
const char* fmt,
...);


#ifdef __cplusplus
}
Expand Down
17 changes: 9 additions & 8 deletions include/stuntrace.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#define MAX_TTL 64
#define MAX_TTL 40
#define MAX_CONCECUTIVE_INACTIVE 4

#define STUNTRACE_MAX_RETRANSMITS 3
Expand Down Expand Up @@ -49,12 +49,12 @@ struct hiutResult {
STUN_SENDFUNC sendFunc;


int32_t currentTTL;
int32_t currentTTL;
StunMsgId currStunMsgId;
int32_t user_start_ttl;
int32_t user_max_ttl;
int32_t user_paralell_traces;
int32_t path_max_ttl; /*got port unreachable or STUN response
int32_t user_start_ttl;
int32_t user_max_ttl;
int32_t user_paralell_traces;
int32_t path_max_ttl; /*got port unreachable or STUN response
**/
uint32_t wait_ms;
struct sockaddr_storage localAddr;
Expand All @@ -63,8 +63,9 @@ struct hiutResult {

/* Initial Length of first STUN packet (TTL=1) */
uint32_t stunLen;
struct hiutPathElement pathElement[MAX_TTL];
//struct hiutTTLinfo ttlInfo[MAX_TTL];
struct hiutPathElement pathElement[MAX_TTL + 1];
bool remoteAlive;
/* struct hiutTTLinfo ttlInfo[MAX_TTL]; */
/* struct npa_trace trace; */

/* Recurring traces*/
Expand Down
66 changes: 35 additions & 31 deletions src/stunclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,6 @@ StunClientMain(STUN_CLIENT_DATA* clientData,
int ctx,
STUN_SIGNAL sig,
uint8_t* payload);
static void
StunPrint(void* userData,
STUN_INFO_FUNC_PTR Log_cb,
StunInfoCategory_T category,
const char* fmt,
...);

static void
StunClientFsm(STUN_TRANSACTION_DATA* trans,
Expand Down Expand Up @@ -99,7 +93,7 @@ TimerHasExpired(STUN_TRANSACTION_DATA* trans,
* If the application has defined a callback function to handle the output
* then this is called with the string and the severity.
*/
static void
void
StunPrint(void* userData,
STUN_INFO_FUNC_PTR Log_cb,
StunInfoCategory_T category,
Expand Down Expand Up @@ -150,7 +144,7 @@ TransIdIsEqual(const StunMsgId* a,

static void
StoreStunBindReq(STUN_TRANSACTION_DATA* trans,
StunBindReqStruct* pMsgIn)
StunBindReqStruct* pMsgIn)
{
/* copy whole msg */
memcpy( &trans->stunBindReq, pMsgIn, sizeof(StunBindReqStruct) );
Expand Down Expand Up @@ -255,7 +249,7 @@ StunClient_Alloc(STUN_CLIENT_DATA** clientDataPtr)

if (!clientDataPtr)
{
return false;
return false;
}

clientData = malloc(sizeof *clientData);
Expand Down Expand Up @@ -351,7 +345,7 @@ StunClient_startBindTransaction(STUN_CLIENT_DATA* clientData,

if (clientData == NULL)
{
return STUNCLIENT_CTX_UNKNOWN;
return STUNCLIENT_CTX_UNKNOWN;
}

memset( &m, 0, sizeof(m) );
Expand Down Expand Up @@ -398,7 +392,7 @@ StunClient_startSTUNTrace(STUN_CLIENT_DATA* clientData,
* none*/

{
StunBindReqStruct m;
StunBindReqStruct m;
STUN_TRANSACTION_DATA trans;
StunMessage stunMsg;
uint8_t stunBuff[STUN_MAX_PACKET_SIZE];
Expand Down Expand Up @@ -431,7 +425,6 @@ StunClient_startSTUNTrace(STUN_CLIENT_DATA* clientData,

StoreStunBindReq(&trans, &m);
BuildStunBindReq(&trans, &stunMsg);

StunClientMain(clientData, STUNCLIENT_CTX_UNKNOWN, STUN_SIGNAL_BindReq,
(uint8_t*)&m);
len = stunlib_encodeMessage(&stunMsg,
Expand Down Expand Up @@ -486,33 +479,44 @@ StunClient_HandleICMP(STUN_CLIENT_DATA* clientData,
return;
}
/* Todo: Test if this is fr me.. */
(void)srcAddr;
StunPrint(clientData->logUserData,
clientData->Log_cb,
StunInfoCategory_Trace,
"<STUNTRACE> StunClient_HandleICMP: Got ICMP type: %i\n ", ICMPtype);

for (int i = 0; i < MAX_STUN_TRANSACTIONS; i++)
if ( ( (ICMPtype == 11 || ICMPtype == 3) && (srcAddr->sa_family == AF_INET) ) ||
( (ICMPtype == 3 || ICMPtype == 1) && (srcAddr->sa_family == AF_INET6) ) )
{
STUN_TRANSACTION_DATA* trans = &clientData->data[i];
if ( trans->inUse &&
TransIdIsEqual(&clientData->traceResult.currStunMsgId,
&trans->stunBindReq.transactionId) )
for (int i = 0; i < MAX_STUN_TRANSACTIONS; i++)
{
StunRespStruct m;
gettimeofday(&trans->stop[trans->retransmits], NULL);
/* memcpy(&m.stunRespMessage, msg, sizeof(m.stunRespMessage)); */
sockaddr_copy( (struct sockaddr*)&m.srcAddr, srcAddr );
m.ICMPtype = ICMPtype;
m.ttl = clientData->traceResult.currentTTL;
StunClientMain(clientData, i, STUN_SIGNAL_ICMPResp, (void*)&m);
return;
STUN_TRANSACTION_DATA* trans = &clientData->data[i];
if ( trans->inUse &&
TransIdIsEqual(&clientData->traceResult.currStunMsgId,
&trans->stunBindReq.transactionId) )
{
StunRespStruct m;
gettimeofday(&trans->stop[trans->retransmits], NULL);
/* memcpy(&m.stunRespMessage, msg, sizeof(m.stunRespMessage)); */
sockaddr_copy( (struct sockaddr*)&m.srcAddr, srcAddr );
m.ICMPtype = ICMPtype;
m.ttl = clientData->traceResult.currentTTL;
StunClientMain(clientData, i, STUN_SIGNAL_ICMPResp, (void*)&m);
return;

}
}
}
StunPrint(clientData->logUserData,
clientData->Log_cb,
StunInfoCategory_Trace,
"<STUNCLIENT> no instance with transId, discarding, ICMP message\n ");
}else{
StunPrint(clientData->logUserData,
clientData->Log_cb,
StunInfoCategory_Trace,
"<STUNCLIENT> no instance with transId, discarding, ICMP message\n ");
"<STUNTRACE> StunClient_HandleICMP: Ignoring ICMP Type, nothing to do\n ", ICMPtype);
}
}


/*
* Cancel a transaction with matching transaction id
* transactionId - Transaction id.
Expand Down Expand Up @@ -1144,7 +1148,7 @@ RetransmitLastReq(STUN_TRANSACTION_DATA* trans,
trans->stunReqMsgBuf,
trans->stunReqMsgBufLen,
(struct sockaddr*)destAddr,
trans->stunBindReq.proto,
trans->stunBindReq.proto,
trans->stunBindReq.useRelay,
trans->stunBindReq.ttl);
}
Expand Down Expand Up @@ -1424,7 +1428,7 @@ StunState_Idle(STUN_TRANSACTION_DATA* trans,
case STUN_SIGNAL_BindReq:
{
StunBindReqStruct* pMsgIn = (StunBindReqStruct*)payload;
StunMessage stunReqMsg; /* decoded */
StunMessage stunReqMsg; /* decoded */
/* clear instance data */
InitInstData(trans);
/* store msg */
Expand Down
Loading