Several minor bugfixes from final pre-release testing

This commit is contained in:
Cameron Gutman
2018-11-10 00:21:01 -08:00
parent 732b430da8
commit e7b5b07c4a
3 changed files with 27 additions and 14 deletions

View File

@@ -711,9 +711,13 @@ void UpdatePortMappingsForTarget(bool enable, char* targetAddressIP4, char* inte
// Don't try with NAT-PMP if the UPnP attempt for the same gateway failed due to being
// disconnected or some other error. This will avoid overwriting UPnP rules on a disconnected IGD
// with duplicate NAT-PMP rules. We want to allow deletion of NAT-PMP rules in any case though.
if (tryNatPmp && enable && !strcmp(upstreamAddrNatPmp, upstreamAddrUPnP)) {
printf("Not attempting to use NAT-PMP to talk to the same UPnP gateway\n");
if (enable && !strcmp(upstreamAddrNatPmp, upstreamAddrUPnP)) {
printf("Not attempting to use NAT-PMP/PCP to talk to the same UPnP gateway\n");
tryNatPmp = false;
// We have both UPnP and NAT-PMP on the same upstream gateway, so let's
// assume PCP is on the same box too.
tryPcp = false;
}
if (tryNatPmp) {
@@ -737,7 +741,12 @@ void UpdatePortMappingsForTarget(bool enable, char* targetAddressIP4, char* inte
if (success) {
printf("NAT-PMP IPv4 port mapping successful" NL);
tryPcp = false;
// Always try all possibilities when disabling to ensure
// we completely clean up
if (enable) {
tryPcp = false;
}
}
}
@@ -835,8 +844,9 @@ void UpdatePortMappings(bool enable)
printf("Found %d hops" NL, hopCount);
}
// Start at hop 1 since we don't want to count the default gateway
int nextHopIndex = 1;
// getHopsIP4() already skips the default gateway, so 0
// is actually the first hop after the default gateway
int nextHopIndex = 0;
// Start by probing for the default gateway
UpdatePortMappingsForTarget(enable, nullptr, nullptr, upstreamAddrStr);
@@ -990,7 +1000,7 @@ HandlerEx(DWORD dwControl, DWORD dwEventType, LPVOID lpEventData, LPVOID lpConte
ServiceStatus.dwControlsAccepted = 0;
SetServiceStatus(ServiceStatusHandle, &ServiceStatus);
printf("Removing UPnP/NAT-PMP rules after service stop request\n");
printf("Removing UPnP/NAT-PMP/PCP rules after service stop request\n");
UpdatePortMappings(false);
printf("The service is stopping\n");

View File

@@ -188,7 +188,7 @@ bool PCPMapPort(PSOCKADDR_STORAGE localAddr, int localAddrLen, PSOCKADDR_STORAGE
// This must be done after the rest of the message is populated
populateMappingNonce(&reqMsg, pcpAddr, pcpAddrLen);
bytesRead = SOCKET_ERROR;
bytesRead = 0;
for (i = 0; i < RECV_TIMEOUT_SEC; i++) {
// Retransmit the request every second until the timeout elapses
if (send(sock, (char *)&reqMsg, reqMsgLen, 0) == SOCKET_ERROR) {
@@ -222,7 +222,7 @@ bool PCPMapPort(PSOCKADDR_STORAGE localAddr, int localAddrLen, PSOCKADDR_STORAGE
}
if (bytesRead == 0) {
printf("No response from PCP server\n");
printf("NO RESPONSE\n");
goto fail;
}
else if (bytesRead == SOCKET_ERROR) {

View File

@@ -157,6 +157,9 @@ struct UPNPDev* getUPnPDevicesByAddress(IN_ADDR address)
return deviceList;
}
// Start at TTL 2 to skip contacting our default gateway
#define TTL_START 2
bool getHopsIP4(IN_ADDR* hopAddress, int* hopAddressCount)
{
HANDLE icmpFile;
@@ -179,8 +182,8 @@ bool getHopsIP4(IN_ADDR* hopAddress, int* hopAddressCount)
return false;
}
int ttl = 1;
for (; ttl < *hopAddressCount; ttl++)
int ttl;
for (ttl = TTL_START; ttl - TTL_START < *hopAddressCount; ttl++)
{
IP_OPTION_INFORMATION ipOptions;
@@ -206,19 +209,19 @@ bool getHopsIP4(IN_ADDR* hopAddress, int* hopAddressCount)
if (replies[0].Status == IP_TTL_EXPIRED_TRANSIT) {
// Get the IP address that responded to us
printf("Hop %d: %s\n", ttl, inet_ntoa(*(IN_ADDR*)&replies[0].Address));
hopAddress[ttl - 1] = *(IN_ADDR*)&replies[0].Address;
printf("Hop %d: %s\n", ttl - TTL_START, inet_ntoa(*(IN_ADDR*)&replies[0].Address));
hopAddress[ttl - TTL_START] = *(IN_ADDR*)&replies[0].Address;
}
else {
// Bail on anything else
printf("Hop %d: %s (error %d)\n", ttl, inet_ntoa(*(IN_ADDR*)&replies[0].Address), replies[0].Status);
printf("Hop %d: %s (error %d)\n", ttl - TTL_START, inet_ntoa(*(IN_ADDR*)&replies[0].Address), replies[0].Status);
break;
}
}
IcmpCloseHandle(icmpFile);
*hopAddressCount = ttl - 1;
*hopAddressCount = ttl - TTL_START;
return true;
}