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

[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: default avatarJames Robinson <jamesr@chromium.org>
Reviewed-by: default avatarMatt Menke <mmenke@chromium.org>
Cr-Commit-Position: refs/heads/master@{#554868}
parent 9f6e4b03
...@@ -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;
} }
......
...@@ -181,3 +181,10 @@ fuchsia_sdk_pkg("fdio") { ...@@ -181,3 +181,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