src/connectivity/weave/adaptation/warm_support.cpp
// Add or remove address on tunnel interface.
Add or remove address on tunnel interface.
Add or remove address on tunnel interface .
PlatformResult AddRemoveHostAddress(InterfaceType in_interface_type,
                                    const Inet::IPAddress &in_address, uint8_t in_prefix_length,
                                    bool in_add) {
  fuchsia::net::stack::StackSyncPtr stack_sync_ptr;
  fuchsia::net::IpAddress addr;
  fuchsia::net::Ipv6Address v6;
  uint64_t interface_id = 0;
  fuchsia::net::Subnet ifaddr;
  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 kPlatformResultFailure;
  }
  std::memcpy(v6.addr.data(), (uint8_t *)(in_address.Addr), v6.addr.size());
  addr.set_ipv6(v6);
  ifaddr.addr = std::move(addr);
  ifaddr.prefix_len = in_prefix_length;
  if (in_add) {
    fuchsia::net::stack::Stack_AddInterfaceAddress_Result result;
    status = stack_sync_ptr->AddInterfaceAddress(interface_id, std::move(ifaddr), &result);
    if (status != ZX_OK || result.is_err()) {
      FX_LOGS(ERROR) << "Failed to add interface address to id: " << interface_id
                     << " status: " << zx_status_get_string(status);
      return kPlatformResultFailure;
    }
  } else {
    fuchsia::net::stack::Stack_DelInterfaceAddress_Result result;
    status = stack_sync_ptr->DelInterfaceAddress(interface_id, std::move(ifaddr), &result);
    if (status != ZX_OK || result.is_err()) {
      FX_LOGS(ERROR) << "Failed to delete interface address for id: " << interface_id
                     << " status: " << zx_status_get_string(status);
      return kPlatformResultFailure;
    }
  }
  FX_LOGS(INFO) << "AddRemoveHostAddress successful";
  return kPlatformResultSuccess;
}
PlatformResult AddRemoveHostAddress ( InterfaceType in_interface_type , const Inet :: IPAddress & in_address , uint8_t in_prefix_length , bool in_add ) { fuchsia :: net :: stack :: StackSyncPtr stack_sync_ptr ; fuchsia :: net :: IpAddress addr ; fuchsia :: net :: Ipv6Address v6 ; uint64_t interface_id = 0 ; fuchsia :: net :: Subnet ifaddr ; 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 kPlatformResultFailure ; } std :: memcpy ( v6 . addr . data ( ) , ( uint8_t * ) ( in_address . Addr ) , v6 . addr . size ( ) ) ; addr . set_ipv6 ( v6 ) ; ifaddr . addr = std :: move ( addr ) ; ifaddr . prefix_len = in_prefix_length ; if ( in_add ) { fuchsia :: net :: stack :: Stack_AddInterfaceAddress_Result result ; status = stack_sync_ptr -> AddInterfaceAddress ( interface_id , std :: move ( ifaddr ) , & result ) ; if ( status != ZX_OK || result . is_err ( ) ) { FX_LOGS ( ERROR ) << " " << interface_id << " " << zx_status_get_string ( status ) ; return kPlatformResultFailure ; } } else { fuchsia :: net :: stack :: Stack_DelInterfaceAddress_Result result ; status = stack_sync_ptr -> DelInterfaceAddress ( interface_id , std :: move ( ifaddr ) , & result ) ; if ( status != ZX_OK || result . is_err ( ) ) { FX_LOGS ( ERROR ) << " " << interface_id << " " << zx_status_get_string ( status ) ; return kPlatformResultFailure ; } } FX_LOGS ( INFO ) << " " ; return kPlatformResultSuccess ; }
Add or remove address on tunnel interface.
Add or remove address on tunnel interface .