Commit d0689dce authored by Kevin Marshall's avatar Kevin Marshall Committed by Commit Bot

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

This reverts commit b29fc269.

Reason for revert: Generated code lacks export directives, causing linker errors on component/debug builds. https://logs.chromium.org/v/?s=chromium%2Fbb%2Fchromium.fyi%2FFuchsia__dbg_%2F18935%2F%2B%2Frecipes%2Fsteps%2Fcompile%2F0%2Fstdout

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=jamesr@chromium.org,mmenke@chromium.org,sergeyu@chromium.org

Change-Id: Iaaa6e563c90acced9c87bd1adccd2e313c57292e
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 831384
Reviewed-on: https://chromium-review.googlesource.com/1036383Reviewed-by: default avatarKevin Marshall <kmarshall@chromium.org>
Commit-Queue: Kevin Marshall <kmarshall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#554885}
parent bbcce752
......@@ -2046,7 +2046,6 @@ 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,57 +4,68 @@
#include "net/base/network_interfaces.h"
#include <fuchsia/cpp/netstack.h>
#include <netstack/netconfig.h>
#include "base/fuchsia/component_context.h"
#include "net/base/ip_endpoint.h"
#include "net/base/network_interfaces_posix.h"
namespace net {
IPAddress NetAddressToIPAddress(const netstack::NetAddress& addr) {
if (addr.ipv4) {
return IPAddress(addr.ipv4->addr.data(), addr.ipv4->addr.count());
bool GetNetworkList(NetworkInterfaceList* networks, int policy) {
int s = socket(AF_INET, SOCK_DGRAM, 0);
if (s <= 0) {
PLOG(ERROR) << "socket";
return false;
}
if (addr.ipv6) {
return IPAddress(addr.ipv6->addr.data(), addr.ipv6->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;
}
return IPAddress();
}
bool GetNetworkList(NetworkInterfaceList* networks, int policy) {
netstack::NetstackSyncPtr netstack =
base::fuchsia::ComponentContext::GetDefault()
->ConnectToServiceSync<netstack::Netstack>();
for (uint32_t i = 0; i < num_ifs; ++i) {
netc_if_info_t interface;
fidl::VectorPtr<netstack::NetInterface> interfaces;
if (!netstack->GetInterfaces(&interfaces))
return false;
if (ioctl_netc_get_if_info_at(s, &i, &interface) < 0) {
PLOG(WARNING) << "ioctl_netc_get_if_info_at";
continue;
}
for (auto& interface : interfaces.get()) {
// Check if the interface is up.
if (!(interface.flags & netstack::NetInterfaceFlagUp))
// Skip loopback addresses.
if (internal::IsLoopbackOrUnspecifiedAddress(
reinterpret_cast<sockaddr*>(&(interface.addr)))) {
continue;
}
// Skip loopback.
if (interface.features & netstack::interfaceFeatureLoopback)
IPEndPoint address;
if (!address.FromSockAddr(reinterpret_cast<sockaddr*>(&(interface.addr)),
sizeof(interface.addr))) {
DLOG(WARNING) << "ioctl_netc_get_if_info returned invalid address.";
continue;
}
NetworkChangeNotifier::ConnectionType connection_type =
(interface.features & netstack::interfaceFeatureWlan)
? NetworkChangeNotifier::CONNECTION_WIFI
: NetworkChangeNotifier::CONNECTION_UNKNOWN;
int prefix_length = 0;
IPEndPoint netmask;
if (netmask.FromSockAddr(reinterpret_cast<sockaddr*>(&(interface.netmask)),
sizeof(interface.netmask))) {
prefix_length = MaskPrefixLength(netmask.address());
}
// TODO(sergeyu): attributes field is used to return address state for IPv6
// addresses. Currently Netstack doesn't provide this information.
// addresses. Currently ioctl_netc_get_if_info doesn't provide this
// information.
int attributes = 0;
networks->push_back(NetworkInterface(
*interface.name, *interface.name, interface.id, connection_type,
NetAddressToIPAddress(interface.addr),
MaskPrefixLength(NetAddressToIPAddress(interface.netmask)),
attributes));
networks->push_back(
NetworkInterface(interface.name, interface.name, interface.index,
NetworkChangeNotifier::CONNECTION_UNKNOWN,
address.address(), prefix_length, attributes));
}
PCHECK(close(s) == 0);
return true;
}
......
......@@ -181,10 +181,3 @@ fuchsia_sdk_pkg("fdio") {
"include/fdio/watcher.h",
]
}
fuchsia_sdk_pkg("netstack") {
fidl_files = [
"net_address.fidl",
"netstack.fidl",
]
}
......@@ -19,7 +19,6 @@ 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 = [ ":*" ]
......@@ -35,7 +34,7 @@ template("fuchsia_sdk_pkg") {
sources = []
foreach(file, invoker.fidl_files) {
sources += [ "sdk/fidl/${pkg_name}/${file}" ]
sources += [ "sdk/pkg/${pkg_name}/${file}" ]
}
libraries_file = "$target_gen_dir/$pkg_name.fidl_libraries"
......@@ -50,8 +49,6 @@ 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",
......@@ -94,7 +91,6 @@ template("fuchsia_sdk_pkg") {
outputs = [
json_representation,
tables_file,
]
rebased_response_file = rebase_path(response_file, root_build_dir)
......@@ -163,15 +159,11 @@ template("fuchsia_sdk_pkg") {
if (!defined(deps)) {
deps = []
}
deps += [
":${invoker.target_name}_compile",
":${invoker.target_name}_cpp_gen",
]
deps += [ ":${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