Commit 352892bf authored by Tamir Duberstein's avatar Tamir Duberstein Committed by Commit Bot

[fuchsia] Migrate NetInterface::features to bits

Bug: 1099393
Change-Id: Id9076b0c92ac0583ffd8cb845663db3ff236c381
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2353294Reviewed-by: default avatarDaniel Nicoara <dnicoara@chromium.org>
Reviewed-by: default avatarDavid Benjamin <davidben@chromium.org>
Reviewed-by: default avatarWez <wez@chromium.org>
Commit-Queue: Tamir Duberstein <tamird@google.com>
Cr-Commit-Position: refs/heads/master@{#798901}
parent 43298a05
...@@ -14,10 +14,9 @@ namespace chromecast { ...@@ -14,10 +14,9 @@ namespace chromecast {
std::unique_ptr<net::NetworkChangeNotifier> std::unique_ptr<net::NetworkChangeNotifier>
NetworkChangeNotifierFactoryFuchsia::CreateInstance() { NetworkChangeNotifierFactoryFuchsia::CreateInstance() {
uint32_t required_features = auto required_features = GetSwitchValueBoolean(switches::kRequireWlan, false)
GetSwitchValueBoolean(switches::kRequireWlan, false) ? fuchsia::hardware::ethernet::Features::WLAN
? fuchsia::hardware::ethernet::INFO_FEATURE_WLAN : fuchsia::hardware::ethernet::Features();
: 0;
// Caller assumes ownership. // Caller assumes ownership.
return std::make_unique<net::NetworkChangeNotifierFuchsia>(required_features); return std::make_unique<net::NetworkChangeNotifierFuchsia>(required_features);
......
...@@ -243,7 +243,7 @@ std::unique_ptr<NetworkChangeNotifier> NetworkChangeNotifier::CreateIfNeeded( ...@@ -243,7 +243,7 @@ std::unique_ptr<NetworkChangeNotifier> NetworkChangeNotifier::CreateIfNeeded(
return std::make_unique<NetworkChangeNotifierMac>(); return std::make_unique<NetworkChangeNotifierMac>();
#elif defined(OS_FUCHSIA) #elif defined(OS_FUCHSIA)
return std::make_unique<NetworkChangeNotifierFuchsia>( return std::make_unique<NetworkChangeNotifierFuchsia>(
0 /* required_features */); fuchsia::hardware::ethernet::Features());
#else #else
NOTIMPLEMENTED(); NOTIMPLEMENTED();
return NULL; return NULL;
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
namespace net { namespace net {
NetworkChangeNotifierFuchsia::NetworkChangeNotifierFuchsia( NetworkChangeNotifierFuchsia::NetworkChangeNotifierFuchsia(
uint32_t required_features) fuchsia::hardware::ethernet::Features required_features)
: NetworkChangeNotifierFuchsia(base::ComponentContextForProcess() : NetworkChangeNotifierFuchsia(base::ComponentContextForProcess()
->svc() ->svc()
->Connect<fuchsia::netstack::Netstack>(), ->Connect<fuchsia::netstack::Netstack>(),
...@@ -31,7 +31,7 @@ NetworkChangeNotifierFuchsia::NetworkChangeNotifierFuchsia( ...@@ -31,7 +31,7 @@ NetworkChangeNotifierFuchsia::NetworkChangeNotifierFuchsia(
NetworkChangeNotifierFuchsia::NetworkChangeNotifierFuchsia( NetworkChangeNotifierFuchsia::NetworkChangeNotifierFuchsia(
fidl::InterfaceHandle<fuchsia::netstack::Netstack> netstack, fidl::InterfaceHandle<fuchsia::netstack::Netstack> netstack,
uint32_t required_features, fuchsia::hardware::ethernet::Features required_features,
SystemDnsConfigChangeNotifier* system_dns_config_notifier) SystemDnsConfigChangeNotifier* system_dns_config_notifier)
: NetworkChangeNotifier(NetworkChangeCalculatorParams(), : NetworkChangeNotifier(NetworkChangeCalculatorParams(),
system_dns_config_notifier), system_dns_config_notifier),
...@@ -100,18 +100,16 @@ void NetworkChangeNotifierFuchsia::OnRouteTableReceived( ...@@ -100,18 +100,16 @@ void NetworkChangeNotifierFuchsia::OnRouteTableReceived(
base::flat_set<IPAddress> addresses; base::flat_set<IPAddress> addresses;
for (auto& interface : interfaces) { for (auto& interface : interfaces) {
// Filter out loopback and invalid connection types. // Filter out loopback and invalid connection types.
auto loopback = static_cast<decltype(interface.features)>(
fuchsia::hardware::ethernet::INFO_FEATURE_LOOPBACK);
if ((internal::ConvertConnectionType(interface) == if ((internal::ConvertConnectionType(interface) ==
NetworkChangeNotifier::CONNECTION_NONE) || NetworkChangeNotifier::CONNECTION_NONE) ||
((interface.features & loopback) == loopback)) { (interface.features &
fuchsia::hardware::ethernet::Features::LOOPBACK) ==
fuchsia::hardware::ethernet::Features::LOOPBACK) {
continue; continue;
} }
// Filter out interfaces that do not meet the |required_features_|. // Filter out interfaces that do not meet the |required_features_|.
auto required_features = if ((interface.features & required_features_) != required_features_) {
static_cast<decltype(interface.features)>(required_features_);
if ((interface.features & required_features) != required_features) {
continue; continue;
} }
......
...@@ -23,9 +23,9 @@ class NET_EXPORT_PRIVATE NetworkChangeNotifierFuchsia ...@@ -23,9 +23,9 @@ class NET_EXPORT_PRIVATE NetworkChangeNotifierFuchsia
: public NetworkChangeNotifier { : public NetworkChangeNotifier {
public: public:
// Registers for asynchronous notifications of changes to network interfaces. // Registers for asynchronous notifications of changes to network interfaces.
// Interfaces can be filtered out by passing in |required_features|, which is // Interfaces are filtered by |required_features|.
// defined in fuchsia::hardware::ethernet. explicit NetworkChangeNotifierFuchsia(
explicit NetworkChangeNotifierFuchsia(uint32_t required_features); fuchsia::hardware::ethernet::Features required_features);
~NetworkChangeNotifierFuchsia() override; ~NetworkChangeNotifierFuchsia() override;
// NetworkChangeNotifier implementation. // NetworkChangeNotifier implementation.
...@@ -35,11 +35,10 @@ class NET_EXPORT_PRIVATE NetworkChangeNotifierFuchsia ...@@ -35,11 +35,10 @@ class NET_EXPORT_PRIVATE NetworkChangeNotifierFuchsia
friend class NetworkChangeNotifierFuchsiaTest; friend class NetworkChangeNotifierFuchsiaTest;
// For testing purposes. Receives a |netstack| pointer for easy mocking. // For testing purposes. Receives a |netstack| pointer for easy mocking.
// Interfaces can be filtered out by passing in |required_features|, which is // Interfaces are filtered by |required_features|.
// defined in fuchsia::hardware::ethernet.
NetworkChangeNotifierFuchsia( NetworkChangeNotifierFuchsia(
fidl::InterfaceHandle<fuchsia::netstack::Netstack> netstack, fidl::InterfaceHandle<fuchsia::netstack::Netstack> netstack,
uint32_t required_features, fuchsia::hardware::ethernet::Features required_features,
SystemDnsConfigChangeNotifier* system_dns_config_notifier = nullptr); SystemDnsConfigChangeNotifier* system_dns_config_notifier = nullptr);
// Forwards the network interface list along with the result of // Forwards the network interface list along with the result of
...@@ -54,9 +53,8 @@ class NET_EXPORT_PRIVATE NetworkChangeNotifierFuchsia ...@@ -54,9 +53,8 @@ class NET_EXPORT_PRIVATE NetworkChangeNotifierFuchsia
std::vector<fuchsia::netstack::NetInterface> interfaces, std::vector<fuchsia::netstack::NetInterface> interfaces,
std::vector<fuchsia::netstack::RouteTableEntry> table); std::vector<fuchsia::netstack::RouteTableEntry> table);
// Bitmap of required features for an interface to be taken into account. The // Required features for an interface to be taken into account.
// features are defined in fuchsia::hardware::ethernet. const fuchsia::hardware::ethernet::Features required_features_;
const uint32_t required_features_;
fuchsia::netstack::NetstackPtr netstack_; fuchsia::netstack::NetstackPtr netstack_;
......
...@@ -303,7 +303,8 @@ class NetworkChangeNotifierFuchsiaTest : public testing::Test { ...@@ -303,7 +303,8 @@ class NetworkChangeNotifierFuchsiaTest : public testing::Test {
// populate from the list of interfaces which have already been added to // populate from the list of interfaces which have already been added to
// |netstack_|. |observer_| is registered last, so that tests need only // |netstack_|. |observer_| is registered last, so that tests need only
// express expectations on changes they make themselves. // express expectations on changes they make themselves.
void CreateNotifier(uint32_t required_features = 0) { void CreateNotifier(
fuchsia::hardware::ethernet::Features required_features = {}) {
// Ensure that the Netstack internal state is up-to-date before the // Ensure that the Netstack internal state is up-to-date before the
// notifier queries it. // notifier queries it.
netstack_.FlushNetstackThread(); netstack_.FlushNetstackThread();
...@@ -357,8 +358,7 @@ TEST_F(NetworkChangeNotifierFuchsiaTest, NotifyNetworkChangeOnInitialIPChange) { ...@@ -357,8 +358,7 @@ TEST_F(NetworkChangeNotifierFuchsiaTest, NotifyNetworkChangeOnInitialIPChange) {
// Set a live interface with an IP address and create the notifier. // Set a live interface with an IP address and create the notifier.
std::vector<fuchsia::netstack::NetInterface> interfaces(1); std::vector<fuchsia::netstack::NetInterface> interfaces(1);
interfaces[0] = DefaultNetInterface(); interfaces[0] = DefaultNetInterface();
interfaces[0].features = static_cast<decltype(interfaces[0].features)>( interfaces[0].features = fuchsia::hardware::ethernet::Features::WLAN;
fuchsia::hardware::ethernet::INFO_FEATURE_WLAN);
netstack_.SetInterfaces(interfaces); netstack_.SetInterfaces(interfaces);
CreateNotifier(); CreateNotifier();
...@@ -560,8 +560,7 @@ TEST_F(NetworkChangeNotifierFuchsiaTest, InterfaceAdded) { ...@@ -560,8 +560,7 @@ TEST_F(NetworkChangeNotifierFuchsiaTest, InterfaceAdded) {
std::vector<fuchsia::netstack::NetInterface> interfaces(1); std::vector<fuchsia::netstack::NetInterface> interfaces(1);
interfaces[0] = DefaultNetInterface(); interfaces[0] = DefaultNetInterface();
interfaces[0].features = static_cast<decltype(interfaces[0].features)>( interfaces[0].features = fuchsia::hardware::ethernet::Features::WLAN;
fuchsia::hardware::ethernet::INFO_FEATURE_WLAN);
netstack_.SetInterfaces(interfaces); netstack_.SetInterfaces(interfaces);
...@@ -596,8 +595,7 @@ TEST_F(NetworkChangeNotifierFuchsiaTest, SecondaryInterfaceDeletedNoop) { ...@@ -596,8 +595,7 @@ TEST_F(NetworkChangeNotifierFuchsiaTest, SecondaryInterfaceDeletedNoop) {
TEST_F(NetworkChangeNotifierFuchsiaTest, FoundWiFi) { TEST_F(NetworkChangeNotifierFuchsiaTest, FoundWiFi) {
std::vector<fuchsia::netstack::NetInterface> interfaces(1); std::vector<fuchsia::netstack::NetInterface> interfaces(1);
interfaces[0] = DefaultNetInterface(); interfaces[0] = DefaultNetInterface();
interfaces[0].features = static_cast<decltype(interfaces[0].features)>( interfaces[0].features = fuchsia::hardware::ethernet::Features::WLAN;
fuchsia::hardware::ethernet::INFO_FEATURE_WLAN);
netstack_.SetInterfaces(interfaces); netstack_.SetInterfaces(interfaces);
CreateNotifier(); CreateNotifier();
...@@ -608,11 +606,10 @@ TEST_F(NetworkChangeNotifierFuchsiaTest, FoundWiFi) { ...@@ -608,11 +606,10 @@ TEST_F(NetworkChangeNotifierFuchsiaTest, FoundWiFi) {
TEST_F(NetworkChangeNotifierFuchsiaTest, FindsInterfaceWithRequiredFeature) { TEST_F(NetworkChangeNotifierFuchsiaTest, FindsInterfaceWithRequiredFeature) {
std::vector<fuchsia::netstack::NetInterface> interfaces(1); std::vector<fuchsia::netstack::NetInterface> interfaces(1);
interfaces[0] = DefaultNetInterface(); interfaces[0] = DefaultNetInterface();
interfaces[0].features = static_cast<decltype(interfaces[0].features)>( interfaces[0].features = fuchsia::hardware::ethernet::Features::WLAN;
fuchsia::hardware::ethernet::INFO_FEATURE_WLAN);
netstack_.SetInterfaces(interfaces); netstack_.SetInterfaces(interfaces);
CreateNotifier(fuchsia::hardware::ethernet::INFO_FEATURE_WLAN); CreateNotifier(fuchsia::hardware::ethernet::Features::WLAN);
EXPECT_EQ(NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, EXPECT_EQ(NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI,
notifier_->GetCurrentConnectionType()); notifier_->GetCurrentConnectionType());
} }
...@@ -622,7 +619,7 @@ TEST_F(NetworkChangeNotifierFuchsiaTest, IgnoresInterfaceWithMissingFeature) { ...@@ -622,7 +619,7 @@ TEST_F(NetworkChangeNotifierFuchsiaTest, IgnoresInterfaceWithMissingFeature) {
interfaces[0] = DefaultNetInterface(); interfaces[0] = DefaultNetInterface();
netstack_.SetInterfaces(interfaces); netstack_.SetInterfaces(interfaces);
CreateNotifier(fuchsia::hardware::ethernet::INFO_FEATURE_WLAN); CreateNotifier(fuchsia::hardware::ethernet::Features::WLAN);
EXPECT_EQ(NetworkChangeNotifier::ConnectionType::CONNECTION_NONE, EXPECT_EQ(NetworkChangeNotifier::ConnectionType::CONNECTION_NONE,
notifier_->GetCurrentConnectionType()); notifier_->GetCurrentConnectionType());
} }
......
...@@ -60,13 +60,12 @@ NetworkInterface NetworkInterfaceFromAddress( ...@@ -60,13 +60,12 @@ NetworkInterface NetworkInterfaceFromAddress(
NetworkChangeNotifier::ConnectionType ConvertConnectionType( NetworkChangeNotifier::ConnectionType ConvertConnectionType(
const fuchsia::netstack::NetInterface& iface) { const fuchsia::netstack::NetInterface& iface) {
auto wlan = static_cast<decltype(iface.features)>(
fuchsia::hardware::ethernet::INFO_FEATURE_WLAN);
auto up = auto up =
static_cast<decltype(iface.flags)>(fuchsia::netstack::NetInterfaceFlagUp); static_cast<decltype(iface.flags)>(fuchsia::netstack::NetInterfaceFlagUp);
if ((iface.flags & up) != up) { if ((iface.flags & up) != up) {
return NetworkChangeNotifier::CONNECTION_NONE; return NetworkChangeNotifier::CONNECTION_NONE;
} else if ((iface.features & wlan) == wlan) { } else if ((iface.features & fuchsia::hardware::ethernet::Features::WLAN) ==
fuchsia::hardware::ethernet::Features::WLAN) {
return NetworkChangeNotifier::CONNECTION_WIFI; return NetworkChangeNotifier::CONNECTION_WIFI;
} }
return NetworkChangeNotifier::CONNECTION_UNKNOWN; return NetworkChangeNotifier::CONNECTION_UNKNOWN;
...@@ -122,11 +121,11 @@ bool GetNetworkList(NetworkInterfaceList* networks, int policy) { ...@@ -122,11 +121,11 @@ bool GetNetworkList(NetworkInterfaceList* networks, int policy) {
} }
for (auto& interface : interfaces) { for (auto& interface : interfaces) {
auto loopback = static_cast<decltype(interface.features)>(
fuchsia::hardware::ethernet::INFO_FEATURE_LOOPBACK);
if ((internal::ConvertConnectionType(interface) == if ((internal::ConvertConnectionType(interface) ==
NetworkChangeNotifier::CONNECTION_NONE) || NetworkChangeNotifier::CONNECTION_NONE) ||
((interface.features & loopback) == loopback)) { (interface.features &
fuchsia::hardware::ethernet::Features::LOOPBACK) ==
fuchsia::hardware::ethernet::Features::LOOPBACK) {
continue; continue;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment