From 8c37960e950e6630ab82dbc515ea9f210afa3030 Mon Sep 17 00:00:00 2001 From: Hamza El-Saawy Date: Thu, 24 Mar 2022 11:05:38 -0400 Subject: [PATCH] PR: naming Signed-off-by: Hamza El-Saawy --- hvsock.go | 28 ++++++++++++++-------------- pkg/sockets/rawaddr.go | 28 +--------------------------- pkg/sockets/sockets.go | 1 - 3 files changed, 15 insertions(+), 42 deletions(-) diff --git a/hvsock.go b/hvsock.go index 94a2a263..b52664b5 100644 --- a/hvsock.go +++ b/hvsock.go @@ -24,50 +24,50 @@ const afHvSock = 34 // AF_HYPERV var ( // https://docs.microsoft.com/en-us/virtualization/hyper-v-on-windows/user-guide/make-integration-service#vmid-wildcards - // HVguidWildcard is the wildcard VmId for accepting connections from all partitions. - HVguidWildcard = guid.GUID{} // 00000000-0000-0000-0000-000000000000 + // HvsockGUIDWildcard is the wildcard VmId for accepting connections from all partitions. + HvsockGUIDWildcard = guid.GUID{} // 00000000-0000-0000-0000-000000000000 - // HVguidBroadcast is the wildcard VmId for broadcasting sends to all partitions - HVguidBroadcast = guid.GUID{ //ffffffff-ffff-ffff-ffff-ffffffffffff + // HvsockGUIDBroadcast is the wildcard VmId for broadcasting sends to all partitions + HvsockGUIDBroadcast = guid.GUID{ //ffffffff-ffff-ffff-ffff-ffffffffffff Data1: 0xffffffff, Data2: 0xffff, Data3: 0xffff, Data4: [8]uint8{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, } - // HVGUIDLoopback is the Loopback VmId for accepting connections to the same partition as the connector. - HVguidLoopback = guid.GUID{ // e0e16197-dd56-4a10-9195-5ee7a155a838 + // HvsockGUIDLoopback is the Loopback VmId for accepting connections to the same partition as the connector. + HvsockGUIDLoopback = guid.GUID{ // e0e16197-dd56-4a10-9195-5ee7a155a838 Data1: 0xe0e16197, Data2: 0xdd56, Data3: 0x4a10, Data4: [8]uint8{0x91, 0x95, 0x5e, 0xe7, 0xa1, 0x55, 0xa8, 0x38}, } - // HVguidSiloHost is the address of a silo's host partition: + // HvsockGUIDSiloHost is the address of a silo's host partition: // - The silo host of a hosted silo is the utility VM. // - The silo host of a silo on a physical host is the physical host. - HVguidSiloHost = guid.GUID{ // 36bd0c5c-7276-4223-88ba-7d03b654c568 + HvsockGUIDSiloHost = guid.GUID{ // 36bd0c5c-7276-4223-88ba-7d03b654c568 Data1: 0x36bd0c5c, Data2: 0x7276, Data3: 0x4223, Data4: [8]byte{0x88, 0xba, 0x7d, 0x03, 0xb6, 0x54, 0xc5, 0x68}, } - // HVguidChildren is the wildcard VmId for accepting connections from the connector's child partitions. - HVguidChildren = guid.GUID{ // 90db8b89-0d35-4f79-8ce9-49ea0ac8b7cd + // HvsockGUIDchildren is the wildcard VmId for accepting connections from the connector's child partitions. + HvsockGUIDchildren = guid.GUID{ // 90db8b89-0d35-4f79-8ce9-49ea0ac8b7cd Data1: 0x90db8b89, Data2: 0xd35, Data3: 0x4f79, Data4: [8]uint8{0x8c, 0xe9, 0x49, 0xea, 0xa, 0xc8, 0xb7, 0xcd}, } - // HVguidParent is the wildcard VmId for accepting connections from the connector's parent partition. + // HvsockGUIDParent is the wildcard VmId for accepting connections from the connector's parent partition. // Listening on this VmId accepts connection from: // - Inside silos: silo host partition. // - Inside hosted silo: host of the VM. // - Inside VM: VM host. // - Physical host: Not supported. - HVguidParent = guid.GUID{ // a42e7cda-d03f-480c-9cc2-a4de20abb878 + HvsockGUIDParent = guid.GUID{ // a42e7cda-d03f-480c-9cc2-a4de20abb878 Data1: 0xa42e7cda, Data2: 0xd03f, Data3: 0x480c, @@ -75,7 +75,7 @@ var ( } // HVguidVSockServiceGUIDTemplate is the Service GUID used for the VSOCK protocol - hvguidVSockServiceTemplate = guid.GUID{ // 00000000-facb-11e6-bd58-64006a7986d3 + hvsockVsockServiceTemplate = guid.GUID{ // 00000000-facb-11e6-bd58-64006a7986d3 Data2: 0xfacb, Data3: 0x11e6, Data4: [8]uint8{0xbd, 0x58, 0x64, 0x00, 0x6a, 0x79, 0x86, 0xd3}, @@ -108,7 +108,7 @@ func (addr *HvsockAddr) String() string { // VsockServiceID returns an hvsock service ID corresponding to the specified AF_VSOCK port. func VsockServiceID(port uint32) guid.GUID { - g := hvguidVSockServiceTemplate // make a copy + g := hvsockVsockServiceTemplate // make a copy g.Data1 = port return g } diff --git a/pkg/sockets/rawaddr.go b/pkg/sockets/rawaddr.go index 03b8fc4a..3680cbdd 100644 --- a/pkg/sockets/rawaddr.go +++ b/pkg/sockets/rawaddr.go @@ -14,33 +14,7 @@ var ( ErrAddrFamily = errors.New("address family") ) -// todo: replace this with generics -// The function calls should be: -// -// type RawSockaddrHeader { -// Family uint16 -// } -// -// func ConnectEx[T ~RawSockaddrHeader] (s Handle, a *T, ...) error { -// n := unsafe.SizeOf(*a) -// r1, _, e1 := syscall.Syscall9(connectExFunc.addr, 7, uintptr(s), -// uintptr(unsafe.Pointer(a)), uintptr(n), /* ... */) -// /* ... */ -// } -// -// Similarly, `GetAcceptExSockaddrs` requires a `**sockaddr`, so the syscall can change the pointer -// to data it allocates. Currently, the options are (1) dealing with pointers to the interface -// `* RawSockaddr`, use reflection or pull the pointer from the internal interface representation, -// and change where the interface points to; or (2) allocate dedicate, presized buffers based on -// `(r RawSockaddr).Sockaddr()`'s return, and pass that to `(r RawSockaddr).FromBytes()`. -// It would be safer and more readable to have: -// -// func GetAcceptExSockaddrs[L ~RawSockaddrHeader, R ~RawSockaddrHeader]( -// b *byte, -// rxlen uint32, -// local **L, -// remote **R, -// ) error { /*...*/ } +// todo: replace this with generics, along with GetSockName and co. // RawSockaddr allows structs to be used with Bind and ConnectEx. The // struct must meet the Wind32 sockaddr requirements specified here: diff --git a/pkg/sockets/sockets.go b/pkg/sockets/sockets.go index 74360f6b..ffe8a87c 100644 --- a/pkg/sockets/sockets.go +++ b/pkg/sockets/sockets.go @@ -37,7 +37,6 @@ type CloseReader interface { // buffer returned by the getsockname syscall. The buffer is allocated to the size specified // by `rsa.Sockaddr()`. func GetSockName(s windows.Handle, rsa RawSockaddr) error { - // todo: replace this (and RawSockaddr) with generics ptr, l, err := rsa.Sockaddr() if err != nil { return fmt.Errorf("could not find socket size to allocate buffer: %w", err)