Commit c05c3e38 authored by Marina Ciocea's avatar Marina Ciocea Committed by Chromium LUCI CQ

Reland "[fuchsia] Migrate to fuchsia.net.interfaces/State"

This is a reland of 022c5b0e.
Consumers of WebEngine have been prepared for a soft transition, and
runners_integration_tests.test-cmx is now updated.

Original change's description:
> [fuchsia] Migrate to fuchsia.net.interfaces/State
>
> Fixed: fuchsia:21155
> Change-Id: I85b388be33d4c9697ba866cf11a143493b2b3239
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2380329
> Reviewed-by: Robert Sesek <rsesek@chromium.org>
> Reviewed-by: Adam Langley <agl@chromium.org>
> Reviewed-by: Sergey Volk <servolk@chromium.org>
> Reviewed-by: Wez <wez@chromium.org>
> Commit-Queue: Marina Ciocea <marinaciocea@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#828229}

TBR=servolk@chromium.org

Change-Id: I7c63e2ab88ce8b087411de97bc4ee2eceebc7c3a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2554857
Commit-Queue: Marina Ciocea <marinaciocea@chromium.org>
Reviewed-by: default avatarDavid Dorwin <ddorwin@chromium.org>
Reviewed-by: default avatarRobert Sesek <rsesek@chromium.org>
Reviewed-by: default avatarWez <wez@chromium.org>
Reviewed-by: default avatarMarina Ciocea <marinaciocea@chromium.org>
Reviewed-by: default avatarAdam Langley <agl@chromium.org>
Cr-Commit-Position: refs/heads/master@{#833397}
parent 2bb775b6
{
"sandbox": {
"dev": [
"null",
"zero"
],
"features": [
"deprecated-ambient-replace-as-executable",
"isolated-cache-storage",
......@@ -8,10 +12,6 @@
"root-ssl-certificates",
"vulkan"
],
"dev": [
"null",
"zero"
],
"services": [
"fuchsia.accessibility.semantics.SemanticsManager",
"fuchsia.camera3.DeviceWatcher",
......@@ -26,7 +26,7 @@
"fuchsia.mediacodec.CodecFactory",
"fuchsia.memorypressure.Provider",
"fuchsia.net.NameLookup",
"fuchsia.netstack.Netstack",
"fuchsia.net.interfaces.State",
"fuchsia.posix.socket.Provider",
"fuchsia.process.Launcher",
"fuchsia.sys.Environment",
......
{
"sandbox": {
"dev": [
"null",
"zero"
],
"features": [
"config-data",
"isolated-cache-storage",
......@@ -8,10 +12,6 @@
"root-ssl-certificates",
"vulkan"
],
"dev": [
"null",
"zero"
],
"services": [
"fuchsia.accessibility.semantics.SemanticsManager",
"fuchsia.camera3.DeviceWatcher",
......@@ -26,7 +26,7 @@
"fuchsia.mediacodec.CodecFactory",
"fuchsia.memorypressure.Provider",
"fuchsia.net.NameLookup",
"fuchsia.netstack.Netstack",
"fuchsia.net.interfaces.State",
"fuchsia.posix.socket.Provider",
"fuchsia.process.Launcher",
"fuchsia.sys.Environment",
......
......@@ -32,10 +32,7 @@ cast_source_set("net") {
"network_change_notifier_factory_fuchsia.h",
]
deps += [
"//chromecast/base:chromecast_switches",
"//third_party/fuchsia-sdk/sdk/fidl/fuchsia.hardware.ethernet",
]
deps += [ "//chromecast/base:chromecast_switches" ]
}
}
......@@ -51,9 +48,7 @@ cast_source_set("time_sync_tracker") {
"time_sync_tracker.cc",
"time_sync_tracker.h",
]
deps = [
"//base",
]
deps = [ "//base" ]
if (is_fuchsia) {
sources += [
......
......@@ -4,8 +4,6 @@
#include "chromecast/net/network_change_notifier_factory_fuchsia.h"
#include <fuchsia/hardware/ethernet/cpp/fidl.h>
#include "base/command_line.h"
#include "chromecast/base/chromecast_switches.h"
#include "net/base/network_change_notifier_fuchsia.h"
......@@ -14,12 +12,10 @@ namespace chromecast {
std::unique_ptr<net::NetworkChangeNotifier>
NetworkChangeNotifierFactoryFuchsia::CreateInstance() {
auto required_features = GetSwitchValueBoolean(switches::kRequireWlan, false)
? fuchsia::hardware::ethernet::Features::WLAN
: fuchsia::hardware::ethernet::Features();
auto require_wlan = GetSwitchValueBoolean(switches::kRequireWlan, false);
// Caller assumes ownership.
return std::make_unique<net::NetworkChangeNotifierFuchsia>(required_features);
return std::make_unique<net::NetworkChangeNotifierFuchsia>(require_wlan);
}
NetworkChangeNotifierFactoryFuchsia::NetworkChangeNotifierFactoryFuchsia() =
......
......@@ -19,7 +19,7 @@
"fuchsia.mediacodec.CodecFactory",
"fuchsia.memorypressure.Provider",
"fuchsia.net.NameLookup",
"fuchsia.netstack.Netstack",
"fuchsia.net.interfaces.State",
"fuchsia.posix.socket.Provider",
"fuchsia.process.Launcher",
"fuchsia.sys.Launcher",
......
{
"sandbox": {
"features": [
"isolated-persistent-storage",
"deprecated-ambient-replace-as-executable"
"deprecated-ambient-replace-as-executable",
"isolated-persistent-storage"
],
"services": [
"fuchsia.accessibility.semantics.SemanticsManager",
......@@ -17,7 +17,7 @@
"fuchsia.mediacodec.CodecFactory",
"fuchsia.memorypressure.Provider",
"fuchsia.net.NameLookup",
"fuchsia.netstack.Netstack",
"fuchsia.net.interfaces.State",
"fuchsia.posix.socket.Provider",
"fuchsia.process.Launcher",
"fuchsia.sys.Launcher",
......
......@@ -16,7 +16,7 @@
"fuchsia.media.SessionAudioConsumerFactory",
"fuchsia.memorypressure.Provider",
"fuchsia.net.NameLookup",
"fuchsia.netstack.Netstack",
"fuchsia.net.interfaces.State",
"fuchsia.posix.socket.Provider",
"fuchsia.process.Launcher",
"fuchsia.sys.Launcher",
......
{
"sandbox": {
"features": [
"root-ssl-certificates",
"deprecated-ambient-replace-as-executable"
"deprecated-ambient-replace-as-executable",
"root-ssl-certificates"
],
"services": [
"fuchsia.device.NameProvider",
"fuchsia.intl.PropertyProvider",
"fuchsia.logger.LogSink",
"fuchsia.net.NameLookup",
"fuchsia.netstack.Netstack",
"fuchsia.net.interfaces.State",
"fuchsia.posix.socket.Provider"
]
}
......
......@@ -43,7 +43,7 @@ static constexpr const char* kServices[] = {
"fuchsia.mediacodec.CodecFactory",
"fuchsia.memorypressure.Provider",
"fuchsia.net.NameLookup",
"fuchsia.netstack.Netstack",
"fuchsia.net.interfaces.State",
"fuchsia.posix.socket.Provider",
"fuchsia.process.Launcher",
"fuchsia.settings.Display",
......
......@@ -20,7 +20,7 @@
"fuchsia.mediacodec.CodecFactory",
"fuchsia.memorypressure.Provider",
"fuchsia.net.NameLookup",
"fuchsia.netstack.Netstack",
"fuchsia.net.interfaces.State",
"fuchsia.posix.socket.Provider",
"fuchsia.process.Launcher",
"fuchsia.settings.Display",
......
......@@ -5,7 +5,7 @@
"fuchsia.fonts.Provider": "fuchsia-pkg://fuchsia.com/fonts#meta/fonts.cmx",
"fuchsia.intl.PropertyProvider": "fuchsia-pkg://fuchsia.com/intl_property_manager#meta/intl_property_manager.cmx",
"fuchsia.memorypressure.Provider": "fuchsia-pkg://fuchsia.com/memory_monitor#meta/memory_monitor.cmx",
"fuchsia.netstack.Netstack": "fuchsia-pkg://fuchsia.com/netstack#meta/netstack.cmx",
"fuchsia.net.interfaces.State": "fuchsia-pkg://fuchsia.com/netstack#meta/netstack.cmx",
"fuchsia.posix.socket.Provider": "fuchsia-pkg://fuchsia.com/netstack#meta/netstack.cmx",
"fuchsia.web.ContextProvider": "fuchsia-pkg://fuchsia.com/web_engine#meta/context_provider.cmx"
},
......@@ -26,7 +26,7 @@
"fuchsia.fonts.Provider",
"fuchsia.intl.PropertyProvider",
"fuchsia.memorypressure.Provider",
"fuchsia.netstack.Netstack",
"fuchsia.net.interfaces.State",
"fuchsia.posix.socket.Provider",
"fuchsia.process.Launcher",
"fuchsia.sys.Launcher",
......
......@@ -5,8 +5,8 @@
],
"services": [
"fuchsia.accessibility.semantics.SemanticsManager",
"fuchsia.device.NameProvider",
"fuchsia.camera3.DeviceWatcher",
"fuchsia.device.NameProvider",
"fuchsia.fonts.Provider",
"fuchsia.intl.PropertyProvider",
"fuchsia.logger.LogSink",
......@@ -16,7 +16,7 @@
"fuchsia.mediacodec.CodecFactory",
"fuchsia.memorypressure.Provider",
"fuchsia.net.NameLookup",
"fuchsia.netstack.Netstack",
"fuchsia.net.interfaces.State",
"fuchsia.posix.socket.Provider",
"fuchsia.process.Launcher",
"fuchsia.sysmem.Allocator",
......
......@@ -1458,7 +1458,8 @@ component("net") {
if (is_fuchsia) {
deps += [ "//third_party/fuchsia-sdk/sdk/pkg/async-loop-cpp" ]
public_deps += [ "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.netstack" ]
public_deps +=
[ "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.net.interfaces" ]
sources += [
"base/network_change_notifier_fuchsia.cc",
"base/network_change_notifier_fuchsia.h",
......@@ -1710,8 +1711,8 @@ source_set("net_deps") {
if (is_fuchsia) {
public_deps += [
"//third_party/fuchsia-sdk/sdk/fidl/fuchsia.hardware.ethernet",
"//third_party/fuchsia-sdk/sdk/fidl/fuchsia.netstack",
"//third_party/fuchsia-sdk/sdk/fidl/fuchsia.hardware.network",
"//third_party/fuchsia-sdk/sdk/fidl/fuchsia.net.interfaces",
"//third_party/fuchsia-sdk/sdk/pkg/sys_cpp",
]
}
......@@ -4630,7 +4631,7 @@ test("net_unittests") {
if (is_fuchsia) {
use_test_server = true
deps += [
"//third_party/fuchsia-sdk/sdk/fidl/fuchsia.netstack",
"//third_party/fuchsia-sdk/sdk/fidl/fuchsia.net.interfaces",
"//third_party/fuchsia-sdk/sdk/pkg/fidl_cpp",
]
sources += [ "base/network_change_notifier_fuchsia_unittest.cc" ]
......
......@@ -251,7 +251,7 @@ std::unique_ptr<NetworkChangeNotifier> NetworkChangeNotifier::CreateIfNeeded(
return std::make_unique<NetworkChangeNotifierMac>();
#elif defined(OS_FUCHSIA)
return std::make_unique<NetworkChangeNotifierFuchsia>(
fuchsia::hardware::ethernet::Features());
/*require_wlan=*/false);
#else
NOTIMPLEMENTED();
return NULL;
......
This diff is collapsed.
......@@ -5,19 +5,21 @@
#ifndef NET_BASE_NETWORK_CHANGE_NOTIFIER_FUCHSIA_H_
#define NET_BASE_NETWORK_CHANGE_NOTIFIER_FUCHSIA_H_
#include <fuchsia/netstack/cpp/fidl.h>
#include <fuchsia/net/interfaces/cpp/fidl.h>
#include <lib/fidl/cpp/binding.h>
#include <vector>
#include "base/atomicops.h"
#include "base/callback.h"
#include "base/containers/flat_set.h"
#include "base/containers/flat_map.h"
#include "base/gtest_prod_util.h"
#include "base/strings/string_piece.h"
#include "base/threading/thread_checker.h"
#include "net/base/net_export.h"
#include "net/base/network_change_notifier.h"
#include "net/base/network_interfaces.h"
#include "net/base/network_interfaces_fuchsia.h"
namespace net {
......@@ -25,9 +27,8 @@ class NET_EXPORT_PRIVATE NetworkChangeNotifierFuchsia
: public NetworkChangeNotifier {
public:
// Registers for asynchronous notifications of changes to network interfaces.
// Interfaces are filtered by |required_features|.
explicit NetworkChangeNotifierFuchsia(
fuchsia::hardware::ethernet::Features required_features);
// Only WLAN interfaces are observed if |require_wlan| is requested.
explicit NetworkChangeNotifierFuchsia(bool require_wlan);
NetworkChangeNotifierFuchsia(const NetworkChangeNotifierFuchsia&) = delete;
NetworkChangeNotifierFuchsia& operator=(const NetworkChangeNotifierFuchsia&) =
delete;
......@@ -37,42 +38,55 @@ class NET_EXPORT_PRIVATE NetworkChangeNotifierFuchsia
ConnectionType GetCurrentConnectionType() const override;
private:
using InterfacePropertiesMap =
base::flat_map<uint64_t, internal::InterfaceProperties>;
friend class NetworkChangeNotifierFuchsiaTest;
// For testing purposes. Receives a |netstack| pointer for easy mocking.
// Interfaces are filtered by |required_features|.
NetworkChangeNotifierFuchsia(
fidl::InterfaceHandle<fuchsia::netstack::Netstack> netstack,
fuchsia::hardware::ethernet::Features required_features,
fidl::InterfaceHandle<fuchsia::net::interfaces::Watcher> watcher,
bool require_wlan,
SystemDnsConfigChangeNotifier* system_dns_config_notifier = nullptr);
// Forwards the network interface list along with the result of
// GetRouteTable() to OnRouteTableReceived().
void ProcessInterfaceList(
std::vector<fuchsia::netstack::NetInterface> interfaces);
// Processes events from the watcher for interface addition, change, or
// removal.
void OnInterfacesEvent(fuchsia::net::interfaces::Event event);
// Computes network change notification state change from the list of
// interfaces and routing table data, sending observer events if IP or
// connection type changes are detected.
void OnRouteTableReceived(
std::vector<fuchsia::netstack::NetInterface> interfaces,
std::vector<fuchsia::netstack::RouteTableEntry> table);
// Handlers for the interface change events. Listeners are notified of changes
// that affect them. |watcher_| is closed if an event is malformed in some
// way.
void OnInterfaceAdded(fuchsia::net::interfaces::Properties properties);
void OnInterfaceRemoved(uint64_t interface_id);
void OnInterfaceChanged(fuchsia::net::interfaces::Properties properties);
// Required features for an interface to be taken into account.
const fuchsia::hardware::ethernet::Features required_features_;
// Unbinds the watcher, reset the connection type and logs |error_message|.
void OnWatcherError(base::StringPiece error_message);
fuchsia::netstack::NetstackPtr netstack_;
// Updates the connection type from |interface_cache_| and notifies observers
// of changes.
void UpdateConnectionType();
// Used to allow the constructor to block until the initial state is received
// from |netstack_|.
base::OnceClosure on_initial_interfaces_received_;
// Resets the connection type to CONNECTION_UNKNOWN.
void ResetConnectionType();
// Returns the ConnectionType converted from |properties|' device_class.
// Returns CONNECTION_NONE if the interface is not publicly routable, taking
// into account the |requires_wlan_| setting.
ConnectionType GetEffectiveConnectionType(
const internal::InterfaceProperties& properties);
// Returns true if the effective connection type is not CONNECTION_NONE.
bool CanReachExternalNetwork(const internal::InterfaceProperties& properties);
// Whether only WLAN interfaces should be taken into account.
const bool require_wlan_;
fuchsia::net::interfaces::WatcherPtr watcher_;
// The ConnectionType of the default network interface, stored as an atomic
// 32-bit int for safe concurrent access.
base::subtle::Atomic32 cached_connection_type_ = CONNECTION_UNKNOWN;
// Set of addresses from the previous query/update for the default interface.
base::flat_set<IPAddress> cached_addresses_;
InterfacePropertiesMap interface_cache_;
THREAD_CHECKER(thread_checker_);
};
......
This diff is collapsed.
......@@ -5,41 +5,81 @@
#ifndef NET_BASE_NETWORK_INTERFACES_FUCHSIA_H_
#define NET_BASE_NETWORK_INTERFACES_FUCHSIA_H_
#include <fuchsia/net/interfaces/cpp/fidl.h>
#include <vector>
#include "net/base/network_change_notifier.h"
#include "net/base/network_interfaces.h"
namespace fuchsia {
namespace net {
class IpAddress;
}
namespace netstack {
class NetInterface;
} // namespace netstack
} // namespace fuchsia
namespace internal {
namespace net {
// Move-only wrapper for fuchsia::net::interface::Properties that guarantees
// that its inner |properties_| are valid and complete properties as reported by
// |VerifyCompleteInterfaceProperties|.
class InterfaceProperties final {
public:
// Creates an |InterfaceProperties| if |properties| are valid complete
// properties as reported by |VerifyCompleteInterfaceProperties|.
static base::Optional<InterfaceProperties> VerifyAndCreate(
fuchsia::net::interfaces::Properties properties);
InterfaceProperties(InterfaceProperties&& interface);
InterfaceProperties& operator=(InterfaceProperties&& interface);
~InterfaceProperties();
class IPAddress;
struct NetworkInterface;
// Updates this instance with the values set in |properties|.
// Fields not set in |properties| retain their previous values.
// Returns false if the |properties| has a missing or mismatched |id| field,
// or if any field set in |properties| has an invalid value (e.g. addresses of
// unknown types).
bool Update(fuchsia::net::interfaces::Properties properties);
namespace internal {
// Appends the NetworkInterfaces for this interface to |interfaces|.
void AppendNetworkInterfaces(NetworkInterfaceList* interfaces) const;
// Returns true if the interface is online and it has either an IPv4 default
// route and a non-link-local address, or an IPv6 default route and a global
// address.
bool IsPubliclyRoutable() const;
bool HasAddresses() const { return !properties_.addresses().empty(); }
uint64_t id() const { return properties_.id(); }
bool online() const { return properties_.online(); }
const fuchsia::net::interfaces::DeviceClass& device_class() const {
return properties_.device_class();
}
private:
explicit InterfaceProperties(fuchsia::net::interfaces::Properties properties);
fuchsia::net::interfaces::Properties properties_;
};
using ExistingInterfaceProperties =
std::vector<std::pair<uint64_t, InterfaceProperties>>;
// Returns the //net ConnectionType for the supplied netstack interface
// description. Returns ConnectionType::CONNECTION_NONE if the interface is not
// "up".
// description. Returns CONNECTION_NONE for loopback interfaces.
NetworkChangeNotifier::ConnectionType ConvertConnectionType(
const fuchsia::netstack::NetInterface& iface);
const fuchsia::net::interfaces::DeviceClass& device_class);
// Connects to the service via the process' ComponentContext, and connects the
// Watcher to the service.
fuchsia::net::interfaces::WatcherHandle ConnectInterfacesWatcher();
// Converts a Fuchsia Netstack NetInterface object to NetworkInterface objects.
// Interfaces with more than one IPv6 address will yield multiple
// NetworkInterface objects, with friendly names to distinguish the different
// IPs (e.g. "wlan" with three IPv6 IPs yields wlan-0, wlan-1, wlan-2).
std::vector<NetworkInterface> NetInterfaceToNetworkInterfaces(
const fuchsia::netstack::NetInterface& iface_in);
// Validates that |properties| contains all the required fields, returning
// |true| if so.
bool VerifyCompleteInterfaceProperties(
const fuchsia::net::interfaces::Properties& properties);
// Converts a Fuchsia IPv4/IPv6 address to a Chromium IPAddress.
IPAddress FuchsiaIpAddressToIPAddress(const fuchsia::net::IpAddress& addr);
// Consumes events describing existing interfaces from |watcher| and
// returns a vector of interface Id & properties pairs. |watcher| must
// be a newly-connected Watcher channel.
// Returns base::nullopt if any protocol error is encountered, e.g.
// |watcher| supplies an invalid event, or disconnects.
base::Optional<internal::ExistingInterfaceProperties> GetExistingInterfaces(
const fuchsia::net::interfaces::WatcherSyncPtr& watcher);
} // namespace internal
} // namespace net
......
......@@ -129,7 +129,7 @@ component("policy") {
"//third_party/fuchsia-sdk/sdk/fidl/fuchsia.logger",
"//third_party/fuchsia-sdk/sdk/fidl/fuchsia.mediacodec",
"//third_party/fuchsia-sdk/sdk/fidl/fuchsia.net",
"//third_party/fuchsia-sdk/sdk/fidl/fuchsia.netstack",
"//third_party/fuchsia-sdk/sdk/fidl/fuchsia.net.interfaces",
"//third_party/fuchsia-sdk/sdk/fidl/fuchsia.sysmem",
"//third_party/fuchsia-sdk/sdk/fidl/fuchsia.ui.scenic",
]
......
......@@ -15,7 +15,7 @@
#include <fuchsia/logger/cpp/fidl.h>
#include <fuchsia/mediacodec/cpp/fidl.h>
#include <fuchsia/net/cpp/fidl.h>
#include <fuchsia/netstack/cpp/fidl.h>
#include <fuchsia/net/interfaces/cpp/fidl.h>
#include <fuchsia/sysmem/cpp/fidl.h>
#include <fuchsia/ui/scenic/cpp/fidl.h>
#include <lib/sys/cpp/component_context.h>
......@@ -90,7 +90,7 @@ constexpr SandboxConfig kGpuConfig = {
constexpr SandboxConfig kNetworkConfig = {
base::make_span((const char* const[]){
fuchsia::net::NameLookup::Name_,
fuchsia::netstack::Netstack::Name_,
fuchsia::net::interfaces::State::Name_,
"fuchsia.posix.socket.Provider",
}),
kProvideSslConfig,
......
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