src/connectivity/weave/adaptation/warm_support.cpp
// Add or remove route to/from forwarding table.
Add or remove route to/from forwarding table.
Add or remove route to / from forwarding table .
PlatformResult AddRemoveHostRoute(InterfaceType in_interface_type, const Inet::IPPrefix &in_prefix,
                                  RoutePriority in_priority, bool in_add) {
  uint64_t interface_id = 0;
  fuchsia::net::stack::StackSyncPtr stack_sync_ptr;
  fuchsia::net::Ipv6Address v6;
  fuchsia::net::stack::ForwardingEntry entry;
  auto svc = nl::Weave::DeviceLayer::PlatformMgrImpl().GetComponentContextForProcess()->svc();
  zx_status_t status = svc->Connect(stack_sync_ptr.NewRequest());
  if (status != ZX_OK) {
    FX_LOGS(ERROR) << "Connect to netstack failed: " << status;
    return kPlatformResultFailure;
  }
  status = GetInterface(stack_sync_ptr, &interface_id);
  if (status != ZX_OK) {
    return kPlatformResultSuccess;
  }
  std::memcpy(v6.addr.data(), (uint8_t *)(in_prefix.IPAddr.Addr), v6.addr.size());
  if (in_add) {
    fuchsia::net::stack::Stack_AddForwardingEntry_Result result;
    entry.subnet.addr.set_ipv6(v6);
    entry.subnet.prefix_len = kSubnetPrefixLen;
    entry.destination.set_device_id(interface_id);
    status = stack_sync_ptr->AddForwardingEntry(std::move(entry), &result);
    if (status != ZX_OK) {
      FX_LOGS(ERROR) << "AddForwardingEntry failed: " << zx_status_get_string(status);
      return kPlatformResultFailure;
    }
    if (result.is_err()) {
      FX_LOGS(ERROR) << "AddForwardingEntry failed result:";
      return kPlatformResultFailure;
    }
  } else {
    fuchsia::net::Subnet subnet;
    subnet.addr.set_ipv6(v6);
    subnet.prefix_len = in_prefix.Length;
    fuchsia::net::stack::Stack_DelForwardingEntry_Result result;
    status = stack_sync_ptr->DelForwardingEntry(std::move(subnet), &result);
    if (status != ZX_OK) {
      FX_LOGS(ERROR) << "DelForwardingEntry failed: " << zx_status_get_string(status);
      return kPlatformResultFailure;
    }
    if (result.is_err()) {
      FX_LOGS(ERROR) << "DelForwardingEntry failed result";
      return kPlatformResultFailure;
    }
  }
  FX_LOGS(ERROR) << "AddRemoveHostRoute successful";
  return kPlatformResultSuccess;
}
PlatformResult AddRemoveHostRoute ( InterfaceType in_interface_type , const Inet :: IPPrefix & in_prefix , RoutePriority in_priority , bool in_add ) { uint64_t interface_id = 0 ; fuchsia :: net :: stack :: StackSyncPtr stack_sync_ptr ; fuchsia :: net :: Ipv6Address v6 ; fuchsia :: net :: stack :: ForwardingEntry entry ; auto svc = nl :: Weave :: DeviceLayer :: PlatformMgrImpl ( ) . GetComponentContextForProcess ( ) -> svc ( ) ; zx_status_t status = svc -> Connect ( stack_sync_ptr . NewRequest ( ) ) ; if ( status != ZX_OK ) { FX_LOGS ( ERROR ) << " " << status ; return kPlatformResultFailure ; } status = GetInterface ( stack_sync_ptr , & interface_id ) ; if ( status != ZX_OK ) { return kPlatformResultSuccess ; } std :: memcpy ( v6 . addr . data ( ) , ( uint8_t * ) ( in_prefix . IPAddr . Addr ) , v6 . addr . size ( ) ) ; if ( in_add ) { fuchsia :: net :: stack :: Stack_AddForwardingEntry_Result result ; entry . subnet . addr . set_ipv6 ( v6 ) ; entry . subnet . prefix_len = kSubnetPrefixLen ; entry . destination . set_device_id ( interface_id ) ; status = stack_sync_ptr -> AddForwardingEntry ( std :: move ( entry ) , & result ) ; if ( status != ZX_OK ) { FX_LOGS ( ERROR ) << " " << zx_status_get_string ( status ) ; return kPlatformResultFailure ; } if ( result . is_err ( ) ) { FX_LOGS ( ERROR ) << " " ; return kPlatformResultFailure ; } } else { fuchsia :: net :: Subnet subnet ; subnet . addr . set_ipv6 ( v6 ) ; subnet . prefix_len = in_prefix . Length ; fuchsia :: net :: stack :: Stack_DelForwardingEntry_Result result ; status = stack_sync_ptr -> DelForwardingEntry ( std :: move ( subnet ) , & result ) ; if ( status != ZX_OK ) { FX_LOGS ( ERROR ) << " " << zx_status_get_string ( status ) ; return kPlatformResultFailure ; } if ( result . is_err ( ) ) { FX_LOGS ( ERROR ) << " " ; return kPlatformResultFailure ; } } FX_LOGS ( ERROR ) << " " ; return kPlatformResultSuccess ; }
Add or remove route to/from forwarding table.
Add or remove route to / from forwarding table .