github.com/vmware/govmomi@v0.51.0/toolbox/backdoor.go (about)

     1  // © Broadcom. All Rights Reserved.
     2  // The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
     3  // SPDX-License-Identifier: Apache-2.0
     4  
     5  package toolbox
     6  
     7  import (
     8  	"errors"
     9  
    10  	"github.com/vmware/vmw-guestinfo/message"
    11  	"github.com/vmware/vmw-guestinfo/vmcheck"
    12  )
    13  
    14  const (
    15  	rpciProtocol uint32 = 0x49435052
    16  	tcloProtocol uint32 = 0x4f4c4354
    17  )
    18  
    19  var (
    20  	ErrNotVirtualWorld = errors.New("not in a virtual world")
    21  )
    22  
    23  type backdoorChannel struct {
    24  	protocol uint32
    25  
    26  	*message.Channel
    27  }
    28  
    29  func (b *backdoorChannel) Start() error {
    30  	if !vmcheck.IsVirtualCPU() {
    31  		return ErrNotVirtualWorld
    32  	}
    33  
    34  	channel, err := message.NewChannel(b.protocol)
    35  	if err != nil {
    36  		return err
    37  	}
    38  
    39  	b.Channel = channel
    40  
    41  	return nil
    42  }
    43  
    44  func (b *backdoorChannel) Stop() error {
    45  	if b.Channel == nil {
    46  		return nil
    47  	}
    48  
    49  	err := b.Channel.Close()
    50  
    51  	b.Channel = nil
    52  
    53  	return err
    54  }
    55  
    56  // NewBackdoorChannelOut creates a Channel for use with the RPCI protocol
    57  func NewBackdoorChannelOut() Channel {
    58  	return &backdoorChannel{
    59  		protocol: rpciProtocol,
    60  	}
    61  }
    62  
    63  // NewBackdoorChannelIn creates a Channel for use with the TCLO protocol
    64  func NewBackdoorChannelIn() Channel {
    65  	return &backdoorChannel{
    66  		protocol: tcloProtocol,
    67  	}
    68  }