Skip to content

Commit

Permalink
Bug 465158 - Minefield Nightly fails to initiate dial-up login when u…
Browse files Browse the repository at this point in the history
…sing internet connection sharing; r=cbiesinger
  • Loading branch information
mayhemer committed Feb 26, 2009
1 parent f304cdf commit 67f87f0
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 5 deletions.
14 changes: 14 additions & 0 deletions netwerk/base/src/nsIOService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ nsIOService::nsIOService()
, mOfflineForProfileChange(PR_FALSE)
, mSettingOffline(PR_FALSE)
, mSetOfflineValue(PR_FALSE)
, mShutdown(PR_FALSE)
, mManageOfflineStatus(PR_TRUE)
, mChannelEventSinks(NS_CHANNEL_EVENT_SINK_CATEGORY)
, mContentSniffers(NS_CONTENT_SNIFFER_CATEGORY)
Expand Down Expand Up @@ -617,6 +618,11 @@ nsIOService::GetOffline(PRBool *offline)
NS_IMETHODIMP
nsIOService::SetOffline(PRBool offline)
{
// When someone wants to go online (!offline) after we got XPCOM shutdown
// throw ERROR_NOT_AVAILABLE to prevent return to online state.
if (mShutdown && !offline)
return NS_ERROR_NOT_AVAILABLE;

// SetOffline() may re-enter while it's shutting down services.
// If that happens, save the most recent value and it will be
// processed when the first SetOffline() call is done bringing
Expand Down Expand Up @@ -834,6 +840,11 @@ nsIOService::Observe(nsISupports *subject,
}
}
else if (!strcmp(topic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
// Remember we passed XPCOM shutdown notification to prevent any
// changes of the offline status from now. We must not allow going
// online after this point.
mShutdown = PR_TRUE;

SetOffline(PR_TRUE);

// Break circular reference.
Expand Down Expand Up @@ -950,6 +961,9 @@ nsIOService::TrackNetworkLinkStatusForOffline()
"Don't call this unless we're managing the offline status");
if (!mNetworkLinkService)
return NS_ERROR_FAILURE;

if (mShutdown)
return NS_ERROR_NOT_AVAILABLE;

// check to make sure this won't collide with Autodial
if (mSocketTransportService) {
Expand Down
2 changes: 2 additions & 0 deletions netwerk/base/src/nsIOService.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ class nsIOService : public nsIIOService2
PRPackedBool mSettingOffline;
PRPackedBool mSetOfflineValue;

PRPackedBool mShutdown;

nsCOMPtr<nsPISocketTransportService> mSocketTransportService;
nsCOMPtr<nsPIDNSService> mDNSService;
nsCOMPtr<nsIProtocolProxyService2> mProxyService;
Expand Down
36 changes: 31 additions & 5 deletions netwerk/system/win32/nsNotifyAddrListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
#include <winbase.h>
#include <wingdi.h>
#include <winuser.h>
#include <winsock2.h>
#include <iprtrmib.h>
#include <time.h>
#include "prmem.h"
Expand Down Expand Up @@ -152,6 +151,7 @@ nsNotifyAddrListener::Run()
PRBool shuttingDown = PR_FALSE;

overlapped.hEvent = ev;
CheckLinkStatus();
while (!shuttingDown) {
HANDLE h;
DWORD ret = sNotifyAddrChange(&h, &overlapped);
Expand Down Expand Up @@ -318,7 +318,11 @@ nsNotifyAddrListener::CheckIPAddrTable(void)
for (DWORD i = 0; !linkUp && i < table->dwNumEntries; i++) {
if (GetOperationalStatus(table->table[i].dwIndex) >=
MIB_IF_OPER_STATUS_CONNECTED &&
table->table[i].dwAddr != 0)
table->table[i].dwAddr != 0 &&
// Also not 192.168.0.1 - the LAN ICS gateway...
table->table[i].dwAddr != 0x0100A8C0 &&
// ...and nor a loopback
table->table[i].dwAddr != 0x0100007F)
linkUp = PR_TRUE;
}
mLinkUp = linkUp;
Expand Down Expand Up @@ -368,9 +372,14 @@ nsNotifyAddrListener::CheckAdaptersInfo(void)
else {
PIP_ADDR_STRING ipAddr;
for (ipAddr = &ptr->IpAddressList; ipAddr && !linkUp;
ipAddr = ipAddr->Next)
if (PL_strcmp(ipAddr->IpAddress.String, "0.0.0.0"))
ipAddr = ipAddr->Next) {
if (PL_strcmp(ipAddr->IpAddress.String,
"0.0.0.0") &&
PL_strcmp(ipAddr->IpAddress.String,
"192.168.0.1")) {
linkUp = PR_TRUE;
}
}
}
}
}
Expand All @@ -382,6 +391,20 @@ nsNotifyAddrListener::CheckAdaptersInfo(void)
return ret;
}

BOOL
nsNotifyAddrListener::CheckAddressIsGateway(LPSOCKADDR aAddress)
{
if (!aAddress)
return FALSE;

PSOCKADDR_IN in_addr = (PSOCKADDR_IN)aAddress;
return aAddress->sa_family == AF_INET &&
in_addr->sin_addr.S_un.S_un_b.s_b1 == 192 &&
in_addr->sin_addr.S_un.S_un_b.s_b2 == 168 &&
in_addr->sin_addr.S_un.S_un_b.s_b3 == 0 &&
in_addr->sin_addr.S_un.S_un_b.s_b4 == 1;
}

DWORD
nsNotifyAddrListener::CheckAdaptersAddresses(void)
{
Expand All @@ -405,7 +428,10 @@ nsNotifyAddrListener::CheckAdaptersAddresses(void)

for (ptr = addresses; !linkUp && ptr; ptr = ptr->Next) {
if (ptr->OperStatus == IfOperStatusUp &&
ptr->IfType != IF_TYPE_SOFTWARE_LOOPBACK)
ptr->IfType != IF_TYPE_SOFTWARE_LOOPBACK &&
ptr->FirstUnicastAddress &&
!CheckAddressIsGateway(ptr->FirstUnicastAddress->
Address.lpSockaddr))
linkUp = TRUE;
}
mLinkUp = linkUp;
Expand Down
2 changes: 2 additions & 0 deletions netwerk/system/win32/nsNotifyAddrListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#define NSNOTIFYADDRLISTENER_H_

#include <windows.h>
#include <winsock2.h>
#include "nsINetworkLinkService.h"
#include "nsIRunnable.h"
#include "nsIObserver.h"
Expand Down Expand Up @@ -82,6 +83,7 @@ class nsNotifyAddrListener : public nsINetworkLinkService,
DWORD CheckIPAddrTable(void);
DWORD CheckAdaptersInfo(void);
DWORD CheckAdaptersAddresses(void);
BOOL CheckAddressIsGateway(LPSOCKADDR aAddress);
void CheckLinkStatus(void);

nsCOMPtr<nsIThread> mThread;
Expand Down

0 comments on commit 67f87f0

Please sign in to comment.