Commit f7b2214a authored by Sergey Ulanov's avatar Sergey Ulanov Committed by Commit Bot

Reland "[Fuchsia] Use Netstack FIDL interface to get network interfaces."

This is a reland of b29fc269

Original change's description:
> [Fuchsia] Use Netstack FIDL interface to get network interfaces.
>
> 1. Updated FILD GN template to generate and compile tables file, FIDL
>    generated code was failing to link without them.
> 2. Updated GetNetworkList() for Fuchsia to FIDL API instead of ioctl().
>
> Bug: 831384
> Change-Id: Ib90303a5110a465ea5f2bad787a7b63a2bf13f61
> Reviewed-on: https://chromium-review.googlesource.com/1023124
> Commit-Queue: Sergey Ulanov <sergeyu@chromium.org>
> Reviewed-by: James Robinson <jamesr@chromium.org>
> Reviewed-by: Matt Menke <mmenke@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#554868}

TBR=mmenke@chromium.org

Bug: 831384
Change-Id: Iabb29661680b835b947b2780d169e204fd5e2559
Reviewed-on: https://chromium-review.googlesource.com/1036484
Commit-Queue: Sergey Ulanov <sergeyu@chromium.org>
Reviewed-by: default avatarKevin Marshall <kmarshall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#554946}
parent 594ebee4
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef BASE_FUCHSIA_COMPONENT_CONTEXT_H_ #ifndef BASE_FUCHSIA_COMPONENT_CONTEXT_H_
#define BASE_FUCHSIA_COMPONENT_CONTEXT_H_ #define BASE_FUCHSIA_COMPONENT_CONTEXT_H_
#include "base/base_export.h"
#include "base/fuchsia/fidl_interface_request.h" #include "base/fuchsia/fidl_interface_request.h"
#include "base/fuchsia/scoped_zx_handle.h" #include "base/fuchsia/scoped_zx_handle.h"
#include "base/macros.h" #include "base/macros.h"
...@@ -25,7 +26,7 @@ namespace fuchsia { ...@@ -25,7 +26,7 @@ namespace fuchsia {
// Provides access to the component's environment and allows it to publish // Provides access to the component's environment and allows it to publish
// outgoing services. // outgoing services.
class ComponentContext { class BASE_EXPORT ComponentContext {
public: public:
ComponentContext(); ComponentContext();
~ComponentContext(); ~ComponentContext();
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef BASE_FUCHSIA_FIDL_INTERFACE_REQUEST_H_ #ifndef BASE_FUCHSIA_FIDL_INTERFACE_REQUEST_H_
#define BASE_FUCHSIA_FIDL_INTERFACE_REQUEST_H_ #define BASE_FUCHSIA_FIDL_INTERFACE_REQUEST_H_
#include "base/base_export.h"
#include "base/fuchsia/scoped_zx_handle.h" #include "base/fuchsia/scoped_zx_handle.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/strings/string_piece.h" #include "base/strings/string_piece.h"
...@@ -30,7 +31,7 @@ namespace fuchsia { ...@@ -30,7 +31,7 @@ namespace fuchsia {
// need to connect to a service. FidlInterfaceRequest is resolved when the // need to connect to a service. FidlInterfaceRequest is resolved when the
// channel is passed to the service implementation, e.g. through // channel is passed to the service implementation, e.g. through
// ComponentContext. // ComponentContext.
class FidlInterfaceRequest { class BASE_EXPORT FidlInterfaceRequest {
public: public:
template <typename Interface> template <typename Interface>
explicit FidlInterfaceRequest(fidl::InterfaceRequest<Interface> request) explicit FidlInterfaceRequest(fidl::InterfaceRequest<Interface> request)
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <zircon/status.h> #include <zircon/status.h>
#include <zircon/syscalls.h> #include <zircon/syscalls.h>
#include "base/base_export.h"
#include "base/fuchsia/fuchsia_logging.h" #include "base/fuchsia/fuchsia_logging.h"
#include "base/scoped_generic.h" #include "base/scoped_generic.h"
...@@ -29,7 +30,7 @@ struct ScopedZxHandleTraits { ...@@ -29,7 +30,7 @@ struct ScopedZxHandleTraits {
} // namespace internal } // namespace internal
class ScopedZxHandle class BASE_EXPORT ScopedZxHandle
: public ScopedGeneric<zx_handle_t, internal::ScopedZxHandleTraits> { : public ScopedGeneric<zx_handle_t, internal::ScopedZxHandleTraits> {
public: public:
ScopedZxHandle() = default; ScopedZxHandle() = default;
......
...@@ -2046,6 +2046,7 @@ component("net") { ...@@ -2046,6 +2046,7 @@ component("net") {
"cert/cert_database_fuchsia.cc", "cert/cert_database_fuchsia.cc",
"cert/test_root_certs_fuchsia.cc", "cert/test_root_certs_fuchsia.cc",
] ]
deps += [ "//third_party/fuchsia-sdk:netstack" ]
} }
} else { } else {
public_deps += [ "//native_client_sdk/src/libraries/nacl_io" ] public_deps += [ "//native_client_sdk/src/libraries/nacl_io" ]
......
...@@ -4,68 +4,57 @@ ...@@ -4,68 +4,57 @@
#include "net/base/network_interfaces.h" #include "net/base/network_interfaces.h"
#include <netstack/netconfig.h> #include <fuchsia/cpp/netstack.h>
#include "base/fuchsia/component_context.h"
#include "net/base/ip_endpoint.h" #include "net/base/ip_endpoint.h"
#include "net/base/network_interfaces_posix.h"
namespace net { namespace net {
bool GetNetworkList(NetworkInterfaceList* networks, int policy) { IPAddress NetAddressToIPAddress(const netstack::NetAddress& addr) {
int s = socket(AF_INET, SOCK_DGRAM, 0); if (addr.ipv4) {
if (s <= 0) { return IPAddress(addr.ipv4->addr.data(), addr.ipv4->addr.count());
PLOG(ERROR) << "socket";
return false;
} }
if (addr.ipv6) {
uint32_t num_ifs = 0; return IPAddress(addr.ipv6->addr.data(), addr.ipv6->addr.count());
if (ioctl_netc_get_num_ifs(s, &num_ifs) < 0) {
PLOG(ERROR) << "ioctl_netc_get_num_ifs";
PCHECK(close(s) == 0);
return false;
} }
return IPAddress();
}
for (uint32_t i = 0; i < num_ifs; ++i) { bool GetNetworkList(NetworkInterfaceList* networks, int policy) {
netc_if_info_t interface; netstack::NetstackSyncPtr netstack =
base::fuchsia::ComponentContext::GetDefault()
->ConnectToServiceSync<netstack::Netstack>();
if (ioctl_netc_get_if_info_at(s, &i, &interface) < 0) { fidl::VectorPtr<netstack::NetInterface> interfaces;
PLOG(WARNING) << "ioctl_netc_get_if_info_at"; if (!netstack->GetInterfaces(&interfaces))
continue; return false;
}
// Skip loopback addresses. for (auto& interface : interfaces.get()) {
if (internal::IsLoopbackOrUnspecifiedAddress( // Check if the interface is up.
reinterpret_cast<sockaddr*>(&(interface.addr)))) { if (!(interface.flags & netstack::NetInterfaceFlagUp))
continue; continue;
}
IPEndPoint address; // Skip loopback.
if (!address.FromSockAddr(reinterpret_cast<sockaddr*>(&(interface.addr)), if (interface.features & netstack::interfaceFeatureLoopback)
sizeof(interface.addr))) {
DLOG(WARNING) << "ioctl_netc_get_if_info returned invalid address.";
continue; continue;
}
int prefix_length = 0; NetworkChangeNotifier::ConnectionType connection_type =
IPEndPoint netmask; (interface.features & netstack::interfaceFeatureWlan)
if (netmask.FromSockAddr(reinterpret_cast<sockaddr*>(&(interface.netmask)), ? NetworkChangeNotifier::CONNECTION_WIFI
sizeof(interface.netmask))) { : NetworkChangeNotifier::CONNECTION_UNKNOWN;
prefix_length = MaskPrefixLength(netmask.address());
}
// TODO(sergeyu): attributes field is used to return address state for IPv6 // TODO(sergeyu): attributes field is used to return address state for IPv6
// addresses. Currently ioctl_netc_get_if_info doesn't provide this // addresses. Currently Netstack doesn't provide this information.
// information.
int attributes = 0; int attributes = 0;
networks->push_back( networks->push_back(NetworkInterface(
NetworkInterface(interface.name, interface.name, interface.index, *interface.name, *interface.name, interface.id, connection_type,
NetworkChangeNotifier::CONNECTION_UNKNOWN, NetAddressToIPAddress(interface.addr),
address.address(), prefix_length, attributes)); MaskPrefixLength(NetAddressToIPAddress(interface.netmask)),
attributes));
} }
PCHECK(close(s) == 0);
return true; return true;
} }
......
...@@ -156,6 +156,7 @@ fuchsia_sdk_pkg("fidl_cpp") { ...@@ -156,6 +156,7 @@ fuchsia_sdk_pkg("fidl_cpp") {
"internal/message_handler.cc", "internal/message_handler.cc",
"internal/message_reader.cc", "internal/message_reader.cc",
"internal/pending_response.cc", "internal/pending_response.cc",
"internal/proxy.cc",
"internal/proxy_controller.cc", "internal/proxy_controller.cc",
"internal/stub.cc", "internal/stub.cc",
"internal/stub_controller.cc", "internal/stub_controller.cc",
...@@ -181,3 +182,10 @@ fuchsia_sdk_pkg("fdio") { ...@@ -181,3 +182,10 @@ fuchsia_sdk_pkg("fdio") {
"include/fdio/watcher.h", "include/fdio/watcher.h",
] ]
} }
fuchsia_sdk_pkg("netstack") {
fidl_files = [
"net_address.fidl",
"netstack.fidl",
]
}
...@@ -19,6 +19,7 @@ template("fuchsia_sdk_pkg") { ...@@ -19,6 +19,7 @@ template("fuchsia_sdk_pkg") {
json_representation = "$target_gen_dir/$pkg_name.fidl.json" json_representation = "$target_gen_dir/$pkg_name.fidl.json"
output_gen_base = "$target_gen_dir/fidl" output_gen_base = "$target_gen_dir/fidl"
output_gen_dir = "$output_gen_base/fuchsia/cpp" output_gen_dir = "$output_gen_base/fuchsia/cpp"
tables_file = "$output_gen_base/$pkg_name.fidl-tables.cc"
action("${target_name}_response_file") { action("${target_name}_response_file") {
visibility = [ ":*" ] visibility = [ ":*" ]
...@@ -34,7 +35,7 @@ template("fuchsia_sdk_pkg") { ...@@ -34,7 +35,7 @@ template("fuchsia_sdk_pkg") {
sources = [] sources = []
foreach(file, invoker.fidl_files) { foreach(file, invoker.fidl_files) {
sources += [ "sdk/pkg/${pkg_name}/${file}" ] sources += [ "sdk/fidl/${pkg_name}/${file}" ]
} }
libraries_file = "$target_gen_dir/$pkg_name.fidl_libraries" libraries_file = "$target_gen_dir/$pkg_name.fidl_libraries"
...@@ -49,6 +50,8 @@ template("fuchsia_sdk_pkg") { ...@@ -49,6 +50,8 @@ template("fuchsia_sdk_pkg") {
rebase_path(response_file, root_build_dir), rebase_path(response_file, root_build_dir),
"--out-libraries", "--out-libraries",
rebase_path(libraries_file, root_build_dir), rebase_path(libraries_file, root_build_dir),
"--tables",
rebase_path(tables_file, root_build_dir),
"--json", "--json",
rebase_path(json_representation, root_build_dir), rebase_path(json_representation, root_build_dir),
"--name", "--name",
...@@ -91,6 +94,7 @@ template("fuchsia_sdk_pkg") { ...@@ -91,6 +94,7 @@ template("fuchsia_sdk_pkg") {
outputs = [ outputs = [
json_representation, json_representation,
tables_file,
] ]
rebased_response_file = rebase_path(response_file, root_build_dir) rebased_response_file = rebase_path(response_file, root_build_dir)
...@@ -159,11 +163,15 @@ template("fuchsia_sdk_pkg") { ...@@ -159,11 +163,15 @@ template("fuchsia_sdk_pkg") {
if (!defined(deps)) { if (!defined(deps)) {
deps = [] deps = []
} }
deps += [ ":${invoker.target_name}_cpp_gen" ] deps += [
":${invoker.target_name}_compile",
":${invoker.target_name}_cpp_gen",
]
sources = [ sources = [
"$output_gen_dir/$pkg_name.cc", "$output_gen_dir/$pkg_name.cc",
"$output_gen_dir/$pkg_name.h", "$output_gen_dir/$pkg_name.h",
tables_file,
] ]
assert(pkg_name != "fidl" && pkg_name != "fidl_cpp") assert(pkg_name != "fidl" && pkg_name != "fidl_cpp")
......
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