-
Notifications
You must be signed in to change notification settings - Fork 313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add IPv6 support for host candidates #382
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -254,8 +254,10 @@ STATUS iceAgentAddRemoteCandidate(PIceAgent pIceAgent, PCHAR pIceCandidateString | |
BOOL locked = FALSE; | ||
PIceCandidate pIceCandidate = NULL, pDuplicatedIceCandidate = NULL; | ||
PCHAR curr, tail, next; | ||
UINT32 tokenLen, portValue, remoteCandidateCount, i; | ||
BOOL foundIpAndPort = FALSE, freeIceCandidateIfFail = TRUE; | ||
UINT32 tokenLen, portValue, remoteCandidateCount, i, len; | ||
BOOL freeIceCandidateIfFail = TRUE; | ||
BOOL foundIp = FALSE, foundPort = FALSE; | ||
CHAR ipBuf[KVS_IP_ADDRESS_STRING_BUFFER_LEN]; | ||
KvsIpAddress candidateIpAddr; | ||
|
||
CHK(pIceAgent != NULL && pIceCandidateString != NULL, STATUS_NULL_ARG); | ||
|
@@ -271,26 +273,32 @@ STATUS iceAgentAddRemoteCandidate(PIceAgent pIceAgent, PCHAR pIceCandidateString | |
|
||
curr = pIceCandidateString; | ||
tail = pIceCandidateString + STRLEN(pIceCandidateString); | ||
while ((next = STRNCHR(curr, tail - curr, ' ')) != NULL && !foundIpAndPort) { | ||
while ((next = STRNCHR(curr, tail - curr, ' ')) != NULL && !(foundIp && foundPort)) { | ||
tokenLen = (UINT32) (next - curr); | ||
CHK(STRNCMPI("tcp", curr, tokenLen) != 0, STATUS_ICE_CANDIDATE_STRING_IS_TCP); | ||
|
||
if (candidateIpAddr.address[0] != 0) { | ||
if (foundIp) { | ||
CHK_STATUS(STRTOUI32(curr, curr + tokenLen, 10, &portValue)); | ||
|
||
candidateIpAddr.port = htons(portValue); | ||
candidateIpAddr.family = KVS_IP_FAMILY_TYPE_IPV4; | ||
} else if (STRNCHR(curr, tokenLen, '.') != NULL) { | ||
CHK(tokenLen <= KVS_MAX_IPV4_ADDRESS_STRING_LEN, STATUS_ICE_CANDIDATE_STRING_INVALID_IP); // IPv4 is 15 characters at most | ||
CHK_STATUS(populateIpFromString(&candidateIpAddr, curr)); | ||
foundPort = TRUE; | ||
} else { | ||
len = MIN(next - curr, KVS_IP_ADDRESS_STRING_BUFFER_LEN - 1); | ||
STRNCPY(ipBuf, curr, len); | ||
ipBuf[len] = '\0'; | ||
|
||
if ((foundIp = inet_pton(AF_INET, ipBuf, candidateIpAddr.address) == 1 ? TRUE : FALSE)) { | ||
candidateIpAddr.family = KVS_IP_FAMILY_TYPE_IPV4; | ||
} else if ((foundIp = inet_pton(AF_INET6, ipBuf, candidateIpAddr.address) == 1 ? TRUE : FALSE)) { | ||
candidateIpAddr.family = KVS_IP_FAMILY_TYPE_IPV6; | ||
} | ||
} | ||
|
||
curr = next + 1; | ||
foundIpAndPort = (candidateIpAddr.port != 0) && (candidateIpAddr.address[0] != 0); | ||
} | ||
|
||
CHK(candidateIpAddr.port != 0, STATUS_ICE_CANDIDATE_STRING_MISSING_PORT); | ||
CHK(candidateIpAddr.address[0] != 0, STATUS_ICE_CANDIDATE_STRING_MISSING_IP); | ||
CHK(foundPort, STATUS_ICE_CANDIDATE_STRING_MISSING_PORT); | ||
CHK(foundIp, STATUS_ICE_CANDIDATE_STRING_MISSING_IP); | ||
|
||
CHK_STATUS(findCandidateWithIp(&candidateIpAddr, pIceAgent->remoteCandidates, &pDuplicatedIceCandidate)); | ||
CHK(pDuplicatedIceCandidate == NULL, retStatus); | ||
|
@@ -341,8 +349,7 @@ STATUS iceAgentInitHostCandidate(PIceAgent pIceAgent) | |
// make sure pIceAgent->localCandidates has no duplicates | ||
CHK_STATUS(findCandidateWithIp(pIpAddress, pIceAgent->localCandidates, &pDuplicatedIceCandidate)); | ||
|
||
if (pIpAddress->family == KVS_IP_FAMILY_TYPE_IPV4 && // Disable ipv6 gathering for now | ||
pDuplicatedIceCandidate == NULL && | ||
if (pDuplicatedIceCandidate == NULL && | ||
STATUS_SUCCEEDED(createSocketConnection(pIpAddress, NULL, KVS_SOCKET_PROTOCOL_UDP, (UINT64) pIceAgent, | ||
incomingDataHandler, pIceAgent->kvsRtcConfiguration.sendBufSize, &pSocketConnection))) { | ||
pTmpIceCandidate = MEMCALLOC(1, SIZEOF(IceCandidate)); | ||
|
@@ -747,7 +754,10 @@ STATUS createIceCandidatePairs(PIceAgent pIceAgent, PIceCandidate pIceCandidate, | |
pCurrentIceCandidate = (PIceCandidate) data; | ||
pCurNode = pCurNode->pNext; | ||
|
||
if (pCurrentIceCandidate->state == ICE_CANDIDATE_STATE_VALID) { | ||
// https://tools.ietf.org/html/rfc8445#section-6.1.2.2 | ||
// pair local and remote candidates with the same family | ||
if (pCurrentIceCandidate->state == ICE_CANDIDATE_STATE_VALID && | ||
pCurrentIceCandidate->ipAddress.family == pIceCandidate->ipAddress.family) { | ||
pIceCandidatePair = (PIceCandidatePair) MEMCALLOC(1, SIZEOF(IceCandidatePair)); | ||
CHK(pIceCandidatePair != NULL, STATUS_NOT_ENOUGH_MEMORY); | ||
|
||
|
@@ -1047,20 +1057,21 @@ STATUS iceAgentSendSrflxCandidateRequest(PIceAgent pIceAgent) | |
switch(pCandidate->iceCandidateType) { | ||
case ICE_CANDIDATE_TYPE_SERVER_REFLEXIVE: | ||
pIceServer = &(pIceAgent->iceServers[pCandidate->iceServerIndex]); | ||
transactionIdStoreInsert(pIceAgent->pStunBindingRequestTransactionIdStore, | ||
pBindingRequest->header.transactionId); | ||
retStatus = iceUtilsSendStunPacket(pBindingRequest, | ||
NULL, | ||
0, | ||
&pIceServer->ipAddress, | ||
pCandidate->pSocketConnection, | ||
NULL, | ||
FALSE); | ||
if (STATUS_FAILED(retStatus)) { | ||
DLOGD("iceUtilsSendStunPacket failed with 0x%08x", retStatus); | ||
retStatus = STATUS_SUCCESS; | ||
if (pIceServer->ipAddress.family == pCandidate->ipAddress.family) { | ||
transactionIdStoreInsert(pIceAgent->pStunBindingRequestTransactionIdStore, | ||
pBindingRequest->header.transactionId); | ||
retStatus = iceUtilsSendStunPacket(pBindingRequest, | ||
NULL, | ||
0, | ||
&pIceServer->ipAddress, | ||
pCandidate->pSocketConnection, | ||
NULL, | ||
FALSE); | ||
if (STATUS_FAILED(retStatus)) { | ||
DLOGD("iceUtilsSendStunPacket failed with 0x%08x", retStatus); | ||
retStatus = STATUS_SUCCESS; | ||
} | ||
} | ||
|
||
break; | ||
|
||
default: | ||
|
@@ -1324,7 +1335,9 @@ STATUS iceAgentInitSrflxCandidate(PIceAgent pIceAgent) | |
pCurNode = pCurNode->pNext; | ||
pCandidate = (PIceCandidate) data; | ||
|
||
if (pCandidate->iceCandidateType == ICE_CANDIDATE_TYPE_HOST) { | ||
// TODO: Stop skipping IPv6. Stun serialization and deserialization needs to be implemented properly first. | ||
if (pCandidate->iceCandidateType == ICE_CANDIDATE_TYPE_HOST && | ||
IS_IPV4_ADDR(&pCandidate->ipAddress)) { | ||
for (j = 0; j < pIceAgent->iceServersCount; j++) { | ||
if (!pIceAgent->iceServers[j].isTurn) { | ||
CHK((pNewCandidate = (PIceCandidate) MEMCALLOC(1, SIZEOF(IceCandidate))) != NULL, | ||
|
@@ -1402,8 +1415,15 @@ STATUS iceAgentInitRelayCandidate(PIceAgent pIceAgent) | |
pSocketAddrForTurn = NULL; | ||
// if an VPN interface (isPointToPoint is TRUE) is found, use that instead | ||
for(i = 0; i < pIceAgent->localNetworkInterfaceCount; ++i) { | ||
if(pIceAgent->localNetworkInterfaces[i].family == pIceAgent->iceServers[j].ipAddress.family && | ||
(pSocketAddrForTurn == NULL || pIceAgent->localNetworkInterfaces[i].isPointToPoint)) { | ||
// TODO: Stop skipping IPv6. Stun serialization and deserialization needs to be implemented properly first. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment about GitHub issue tracking it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as above. |
||
// Also, we need to handle the following kinds of relays: | ||
// 1. IPv4-to-IPv6 | ||
// 2. IPv6-to-IPv6 | ||
// 3. IPv6-to-IPv4 | ||
// RFC: https://tools.ietf.org/html/rfc6156 | ||
if(pIceAgent->localNetworkInterfaces[i].family == KVS_IP_FAMILY_TYPE_IPV4 && | ||
pIceAgent->localNetworkInterfaces[i].family == pIceAgent->iceServers[j].ipAddress.family && | ||
(pSocketAddrForTurn == NULL || pIceAgent->localNetworkInterfaces[i].isPointToPoint)) { | ||
pSocketAddrForTurn = &pIceAgent->localNetworkInterfaces[i]; | ||
} | ||
} | ||
|
@@ -1460,8 +1480,12 @@ STATUS iceAgentInitRelayCandidate(PIceAgent pIceAgent) | |
pCurNode = pCurNode->pNext; | ||
pCandidate = (PIceCandidate) data; | ||
|
||
CHK_STATUS(turnConnectionAddPeer(pCurrentTurnConnectionTracker->pTurnConnection, | ||
&pCandidate->ipAddress)); | ||
// TODO: Stop skipping IPv6. Since we're allowing IPv6 remote candidates from iceAgentAddRemoteCandidate for host candidates, | ||
// it's possible to have a situation where the turn server uses IPv4 and the remote candidate uses IPv6. | ||
if (IS_IPV4_ADDR(&pCandidate->ipAddress)) { | ||
CHK_STATUS(turnConnectionAddPeer(pCurrentTurnConnectionTracker->pTurnConnection, | ||
&pCandidate->ipAddress)); | ||
} | ||
} | ||
|
||
MUTEX_UNLOCK(pIceAgent->lock); | ||
|
@@ -1863,18 +1887,32 @@ STATUS iceCandidateSerialize(PIceCandidate pIceCandidate, PCHAR pOutputData, PUI | |
pIceCandidate->ipAddress.address[3], | ||
(UINT16) getInt16(pIceCandidate->ipAddress.port), | ||
iceAgentGetCandidateTypeStr(pIceCandidate->iceCandidateType)); | ||
} else { | ||
amountWritten = SNPRINTF(pOutputData, | ||
pOutputData == NULL ? 0 : *pOutputLength, | ||
"%u 1 udp %u %02X%02X:%02X%02X:%02X%02X:%02X%02X:%02X%02X:%02X%02X:%02X%02X:%02X%02X " | ||
"%d typ %s raddr ::/0 rport 0 generation 0 network-cost 999", | ||
pIceCandidate->foundation, | ||
pIceCandidate->priority, | ||
pIceCandidate->ipAddress.address[0], pIceCandidate->ipAddress.address[1], | ||
pIceCandidate->ipAddress.address[2], pIceCandidate->ipAddress.address[3], | ||
pIceCandidate->ipAddress.address[4], pIceCandidate->ipAddress.address[5], | ||
pIceCandidate->ipAddress.address[6], pIceCandidate->ipAddress.address[7], | ||
pIceCandidate->ipAddress.address[8], pIceCandidate->ipAddress.address[9], | ||
pIceCandidate->ipAddress.address[10], pIceCandidate->ipAddress.address[11], | ||
pIceCandidate->ipAddress.address[12], pIceCandidate->ipAddress.address[13], | ||
pIceCandidate->ipAddress.address[14], pIceCandidate->ipAddress.address[15], | ||
(UINT16) getInt16(pIceCandidate->ipAddress.port), | ||
iceAgentGetCandidateTypeStr(pIceCandidate->iceCandidateType)); | ||
} | ||
|
||
CHK_WARN(amountWritten > 0, STATUS_INTERNAL_ERROR, "SNPRINTF failed"); | ||
|
||
if (pOutputData == NULL) { | ||
*pOutputLength = ((UINT32) amountWritten) + 1; // +1 for null terminator | ||
} else { | ||
// amountWritten doesnt account for null char | ||
CHK(amountWritten < (INT32) *pOutputLength, STATUS_BUFFER_TOO_SMALL); | ||
} | ||
CHK_WARN(amountWritten > 0, STATUS_INTERNAL_ERROR, "SNPRINTF failed"); | ||
|
||
if (pOutputData == NULL) { | ||
*pOutputLength = ((UINT32) amountWritten) + 1; // +1 for null terminator | ||
} else { | ||
DLOGW("ipv6 not supported yet"); | ||
// amountWritten doesnt account for null char | ||
CHK(amountWritten < (INT32) *pOutputLength, STATUS_BUFFER_TOO_SMALL); | ||
} | ||
|
||
CleanUp: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a GitHub issue tracking this work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#394