#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "net/base/address_tracker_linux.h"
#include <errno.h>
#include <linux/if.h>
#include <stdint.h>
#include <sys/ioctl.h>
#include <optional>
#include <utility>
#include <vector>
#include "base/check.h"
#include "base/compiler_specific.h"
#include "base/containers/span.h"
#include "base/dcheck_is_on.h"
#include "base/files/scoped_file.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/logging.h"
#include "base/memory/page_size.h"
#include "base/posix/eintr_wrapper.h"
#include "base/sequence_checker.h"
#include "base/task/current_thread.h"
#include "base/threading/scoped_blocking_call.h"
#include "base/threading/thread_restrictions.h"
#include "build/build_config.h"
#include "net/base/network_interfaces_linux.h"
#if BUILDFLAG(IS_ANDROID)
#include "base/android/build_info.h"
#endif
namespace net::internal {
namespace {
bool IgnoreWirelessChange(const struct ifinfomsg* msg, int length) { … }
bool GetAddress(const struct nlmsghdr* header,
int header_length,
IPAddress* out,
bool* really_deprecated) { … }
template <typename T>
T* SafelyCastNetlinkMsgData(const struct nlmsghdr* header, int length) { … }
}
char* AddressTrackerLinux::GetInterfaceName(int interface_index, char* buf) { … }
AddressTrackerLinux::AddressTrackerLinux()
: … { … }
AddressTrackerLinux::AddressTrackerLinux(
const base::RepeatingClosure& address_callback,
const base::RepeatingClosure& link_callback,
const base::RepeatingClosure& tunnel_callback,
const std::unordered_set<std::string>& ignored_interfaces,
scoped_refptr<base::SequencedTaskRunner> blocking_thread_runner)
: … { … }
AddressTrackerLinux::~AddressTrackerLinux() = default;
void AddressTrackerLinux::InitWithFdForTesting(base::ScopedFD fd) { … }
void AddressTrackerLinux::Init() { … }
bool AddressTrackerLinux::DidTrackingInitSucceedForTesting() const { … }
void AddressTrackerLinux::AbortAndForceOnline() { … }
AddressTrackerLinux::AddressMap AddressTrackerLinux::GetAddressMap() const { … }
std::unordered_set<int> AddressTrackerLinux::GetOnlineLinks() const { … }
AddressTrackerLinux* AddressTrackerLinux::GetAddressTrackerLinux() { … }
std::pair<AddressTrackerLinux::AddressMap, std::unordered_set<int>>
AddressTrackerLinux::GetInitialDataAndStartRecordingDiffs() { … }
void AddressTrackerLinux::SetDiffCallback(DiffCallback diff_callback) { … }
bool AddressTrackerLinux::IsInterfaceIgnored(int interface_index) const { … }
NetworkChangeNotifier::ConnectionType
AddressTrackerLinux::GetCurrentConnectionType() { … }
void AddressTrackerLinux::DumpInitialAddressesAndWatch() { … }
void AddressTrackerLinux::ReadMessages(bool* address_changed,
bool* link_changed,
bool* tunnel_changed) { … }
void AddressTrackerLinux::HandleMessage(const char* buffer,
int length,
bool* address_changed,
bool* link_changed,
bool* tunnel_changed) { … }
void AddressTrackerLinux::OnFileCanReadWithoutBlocking() { … }
bool AddressTrackerLinux::IsTunnelInterface(int interface_index) const { … }
bool AddressTrackerLinux::IsTunnelInterfaceName(const char* name) { … }
void AddressTrackerLinux::UpdateCurrentConnectionType() { … }
void AddressTrackerLinux::RunDiffCallback() { … }
int AddressTrackerLinux::GetThreadsWaitingForConnectionTypeInitForTesting() { … }
AddressTrackerLinux::AddressTrackerAutoLock::AddressTrackerAutoLock(
const AddressTrackerLinux& tracker,
base::Lock& lock)
: … { … }
AddressTrackerLinux::AddressTrackerAutoLock::~AddressTrackerAutoLock() { … }
}