2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2008-10-01 02:27:06 +04:00
|
|
|
|
|
|
|
#ifndef NSNETWORKLINKSERVICEMAC_H_
|
|
|
|
#define NSNETWORKLINKSERVICEMAC_H_
|
|
|
|
|
|
|
|
#include "nsINetworkLinkService.h"
|
|
|
|
#include "nsIObserver.h"
|
2019-10-17 17:24:57 +03:00
|
|
|
#include "nsITimer.h"
|
2019-06-28 15:41:27 +03:00
|
|
|
#include "mozilla/Mutex.h"
|
2019-09-17 21:58:39 +03:00
|
|
|
#include "mozilla/SHA1.h"
|
2008-10-01 02:27:06 +04:00
|
|
|
|
|
|
|
#include <SystemConfiguration/SCNetworkReachability.h>
|
2014-10-28 06:53:00 +03:00
|
|
|
#include <SystemConfiguration/SystemConfiguration.h>
|
2008-10-01 02:27:06 +04:00
|
|
|
|
2019-09-17 21:58:39 +03:00
|
|
|
using prefix_and_netmask = std::pair<in6_addr, in6_addr>;
|
|
|
|
|
2019-10-17 17:24:57 +03:00
|
|
|
class nsNetworkLinkService : public nsINetworkLinkService,
|
|
|
|
public nsIObserver,
|
|
|
|
public nsITimerCallback {
|
2008-10-01 02:27:06 +04:00
|
|
|
public:
|
2019-08-14 16:20:25 +03:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2008-10-01 02:27:06 +04:00
|
|
|
NS_DECL_NSINETWORKLINKSERVICE
|
|
|
|
NS_DECL_NSIOBSERVER
|
2019-10-17 17:24:57 +03:00
|
|
|
NS_DECL_NSITIMERCALLBACK
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2008-10-01 02:27:06 +04:00
|
|
|
nsNetworkLinkService();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2008-10-01 02:27:06 +04:00
|
|
|
nsresult Init();
|
|
|
|
nsresult Shutdown();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-09-17 21:58:39 +03:00
|
|
|
static void HashSortedPrefixesAndNetmasks(
|
|
|
|
std::vector<prefix_and_netmask> prefixAndNetmaskStore,
|
|
|
|
mozilla::SHA1Sum* sha1);
|
|
|
|
|
2014-07-06 00:35:35 +04:00
|
|
|
protected:
|
|
|
|
virtual ~nsNetworkLinkService();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2008-10-01 02:27:06 +04:00
|
|
|
private:
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mLinkUp;
|
|
|
|
bool mStatusKnown;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2008-10-01 02:27:06 +04:00
|
|
|
SCNetworkReachabilityRef mReachability;
|
|
|
|
CFRunLoopRef mCFRunLoop;
|
2014-10-28 06:53:00 +03:00
|
|
|
CFRunLoopSourceRef mRunLoopSource;
|
|
|
|
SCDynamicStoreRef mStoreRef;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-11-15 00:25:17 +03:00
|
|
|
bool IPv4NetworkId(mozilla::SHA1Sum* sha1);
|
|
|
|
bool IPv6NetworkId(mozilla::SHA1Sum* sha1);
|
|
|
|
|
2008-10-01 02:27:06 +04:00
|
|
|
void UpdateReachability();
|
2019-10-30 02:19:03 +03:00
|
|
|
void OnIPConfigChanged();
|
|
|
|
void OnNetworkIdChanged();
|
|
|
|
void OnReachabilityChanged();
|
2019-11-19 13:33:43 +03:00
|
|
|
void NotifyObservers(const char* aTopic, const char* aData);
|
2008-10-01 02:27:06 +04:00
|
|
|
static void ReachabilityChanged(SCNetworkReachabilityRef target,
|
|
|
|
SCNetworkConnectionFlags flags, void* info);
|
2019-10-30 02:05:17 +03:00
|
|
|
static void NetworkConfigChanged(SCDynamicStoreRef store,
|
|
|
|
CFArrayRef changedKeys, void* info);
|
2019-10-17 17:24:57 +03:00
|
|
|
void calculateNetworkIdWithDelay(uint32_t aDelay);
|
2019-08-14 16:20:25 +03:00
|
|
|
void calculateNetworkIdInternal(void);
|
2019-10-30 02:05:17 +03:00
|
|
|
void DNSConfigChanged();
|
|
|
|
void GetDnsSuffixListInternal();
|
2019-11-15 00:25:17 +03:00
|
|
|
bool RoutingFromKernel(nsTArray<nsCString>& aHash);
|
|
|
|
bool RoutingTable(nsTArray<nsCString>& aHash);
|
2019-06-28 15:41:27 +03:00
|
|
|
|
|
|
|
mozilla::Mutex mMutex;
|
2016-04-28 05:51:00 +03:00
|
|
|
nsCString mNetworkId;
|
2019-10-30 02:05:17 +03:00
|
|
|
nsTArray<nsCString> mDNSSuffixList;
|
2019-08-30 21:18:19 +03:00
|
|
|
|
2019-10-17 17:24:57 +03:00
|
|
|
// The timer used to delay the calculation of network id since it takes some
|
|
|
|
// time to discover the gateway's MAC address.
|
|
|
|
nsCOMPtr<nsITimer> mNetworkIdTimer;
|
2019-11-15 00:25:17 +03:00
|
|
|
|
2019-12-03 10:26:07 +03:00
|
|
|
// IP address used to check the route for public traffic.
|
2019-11-15 00:25:17 +03:00
|
|
|
struct in_addr mRouteCheckIPv4;
|
2008-10-01 02:27:06 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* NSNETWORKLINKSERVICEMAC_H_ */
|