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") {
"cert/cert_database_fuchsia.cc",
"cert/test_root_certs_fuchsia.cc",
]
deps += [ "//third_party/fuchsia-sdk:netstack" ]
}
} else {
public_deps += [ "//native_client_sdk/src/libraries/nacl_io" ]
......
......@@ -4,68 +4,57 @@
#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/network_interfaces_posix.h"
namespace net {
bool GetNetworkList(NetworkInterfaceList* networks, int policy) {
int s = socket(AF_INET, SOCK_DGRAM, 0);
if (s <= 0) {
PLOG(ERROR) << "socket";
return false;
IPAddress NetAddressToIPAddress(const netstack::NetAddress& addr) {
if (addr.ipv4) {
return IPAddress(addr.ipv4->addr.data(), addr.ipv4->addr.count());
}
uint32_t num_ifs = 0;
if (ioctl_netc_get_num_ifs(s, &num_ifs) < 0) {
PLOG(ERROR) << "ioctl_netc_get_num_ifs";
PCHECK(close(s) == 0);
return false;
if (addr.ipv6) {
return IPAddress(addr.ipv6->addr.data(), addr.ipv6->addr.count());
}
return IPAddress();
}
for (uint32_t i = 0; i < num_ifs; ++i) {
netc_if_info_t interface;
bool GetNetworkList(NetworkInterfaceList* networks, int policy) {
netstack::NetstackSyncPtr netstack =
base::fuchsia::ComponentContext::GetDefault()
->ConnectToServiceSync<netstack::Netstack>();
if (ioctl_netc_get_if_info_at(s, &i, &interface) < 0) {
PLOG(WARNING) << "ioctl_netc_get_if_info_at";
continue;
}
fidl::VectorPtr<netstack::NetInterface> interfaces;
if (!netstack->GetInterfaces(&interfaces))
return false;
// Skip loopback addresses.
if (internal::IsLoopbackOrUnspecifiedAddress(
reinterpret_cast<sockaddr*>(&(interface.addr)))) {
for (auto& interface : interfaces.get()) {
// Check if the interface is up.
if (!(interface.flags & netstack::NetInterfaceFlagUp))
continue;
}
IPEndPoint address;
if (!address.FromSockAddr(reinterpret_cast<sockaddr*>(&(interface.addr)),
sizeof(interface.addr))) {
DLOG(WARNING) << "ioctl_netc_get_if_info returned invalid address.";
// Skip loopback.
if (interface.features & netstack::interfaceFeatureLoopback)
continue;
}
int prefix_length = 0;
IPEndPoint netmask;
if (netmask.FromSockAddr(reinterpret_cast<sockaddr*>(&(interface.netmask)),
sizeof(interface.netmask))) {
prefix_length = MaskPrefixLength(netmask.address());
}
NetworkChangeNotifier::ConnectionType connection_type =
(interface.features & netstack::interfaceFeatureWlan)
? NetworkChangeNotifier::CONNECTION_WIFI
: NetworkChangeNotifier::CONNECTION_UNKNOWN;
// TODO(sergeyu): attributes field is used to return address state for IPv6
// addresses. Currently ioctl_netc_get_if_info doesn't provide this
// information.
// addresses. Currently Netstack doesn't provide this information.
int attributes = 0;
networks->push_back(
NetworkInterface(interface.name, interface.name, interface.index,
NetworkChangeNotifier::CONNECTION_UNKNOWN,
address.address(), prefix_length, attributes));
networks->push_back(NetworkInterface(
*interface.name, *interface.name, interface.id, connection_type,
NetAddressToIPAddress(interface.addr),
MaskPrefixLength(NetAddressToIPAddress(interface.netmask)),
attributes));
}
PCHECK(close(s) == 0);
return true;
}
......
......@@ -181,3 +181,10 @@ fuchsia_sdk_pkg("fdio") {
"include/fdio/watcher.h",
]
}
fuchsia_sdk_pkg("netstack") {
fidl_files = [
"net_address.fidl",
"netstack.fidl",
]
}
......@@ -19,6 +19,7 @@ template("fuchsia_sdk_pkg") {
json_representation = "$target_gen_dir/$pkg_name.fidl.json"
output_gen_base = "$target_gen_dir/fidl"
output_gen_dir = "$output_gen_base/fuchsia/cpp"
tables_file = "$output_gen_base/$pkg_name.fidl-tables.cc"
action("${target_name}_response_file") {
visibility = [ ":*" ]
......@@ -34,7 +35,7 @@ template("fuchsia_sdk_pkg") {
sources = []
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"
......@@ -49,6 +50,8 @@ template("fuchsia_sdk_pkg") {
rebase_path(response_file, root_build_dir),
"--out-libraries",
rebase_path(libraries_file, root_build_dir),
"--tables",
rebase_path(tables_file, root_build_dir),
"--json",
rebase_path(json_representation, root_build_dir),
"--name",
......@@ -91,6 +94,7 @@ template("fuchsia_sdk_pkg") {
outputs = [
json_representation,
tables_file,
]
rebased_response_file = rebase_path(response_file, root_build_dir)
......@@ -159,11 +163,15 @@ template("fuchsia_sdk_pkg") {
if (!defined(deps)) {
deps = []
}
deps += [ ":${invoker.target_name}_cpp_gen" ]
deps += [
":${invoker.target_name}_compile",
":${invoker.target_name}_cpp_gen",
]
sources = [
"$output_gen_dir/$pkg_name.cc",
"$output_gen_dir/$pkg_name.h",
tables_file,
]
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