Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added HV Socket tests #235

Closed
wants to merge 1 commit into from
Closed

Conversation

helsaawy
Copy link
Contributor

@helsaawy helsaawy commented Feb 23, 2022

Added tests for Hyper-V sockets, including CloseRead and CloseWrite, and that addresses are set appropriately.

Bug fixes:

  • Listen (and now Dial) now properly initialize their sockets correctly after AcceptEx (and ConnectEx), so that GetSockName, GetPeerName, and Shutdown (for CloseRead and CloseWrite) now function properly.
  • The socketError used to check bind's return value was incorrect, it should be uintptr(^uint32(0)), not ^uintptr(0)

Added resources to support testing:

  • Well-know Hyper-V VMIDs for parents, children, and loopback.
  • Dial() and DialContext() (along with a corresponding HvsockDialer struct) to dial a specific Hyper-V socket at an address.

Additionally, added functionality to register an application (service GUID and name) in the registry to enable Hyper-V sockets using that service GUID

Created a sockets package, currently only with syscalls to Bind, ConnectEx and GetSockName, bypassing syscall/windows restrictions that they only be used on socket address types defined by the package.

Upgraded to go v1.17 to use unsafe.Slice().

Signed-off-by: Hamza El-Saawy hamzaelsaawy@microsoft.com

Added tests for core Hyper-V socket functionality, including testing
CloseRead and CloseWrite, as well as checking addresses are appropriate
and timeouts work.

Added resources to support testing:
* Well-know Hyper-V VMIDs for parents, children, and loopback.
* VSock interop service GUID.
* `Dial()` and `DialContext()` to dial a specific Hyper-V socket at a
  known address (along with a corresponding `HvsockDialer` struct.

Bug fixes:
* Dial (and Listen) now properly initialize and set properties of their
  sockets after ConnectEx (and AcceptEx).
* The `socketError` used by `bind` was incorrect, it should be `int32(-1)`,
  not `uintptr(^0)`

Added functionality to register application (service GUID and name) in the
registry to enable Hyper-V sockets using that service GUID

Created a `sockets` package, currently only with syscalls to `Bind`,
`ConnectEx` and `GetSockName`, bypassing `syscall/windows` restrictions
on the types that can do so.

Upgraded to go v1.17 to use `unsafe.Slice()`.

Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com>
@helsaawy helsaawy requested a review from a team as a code owner February 23, 2022 20:59
sock, err := newHvSocket()
if err != nil {
return nil, err
return nil, conn.opErr("dial", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should use the op var we made on the first line

Comment on lines +335 to +337
windows.Handle(sock.handle), &sa,
nil /*sendBuf*/, 0, /*sendDataLen*/
&bytes, (*windows.Overlapped)(unsafe.Pointer(&c.o)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what the idiomatic answer is here, but I generally feel like every argument on a new line is easier to read. Also I'd prefer // comments to the c block comment style

Comment on lines +89 to +92
// "golang.org/x/sys/windows".ConnectEx and .Bind only accept internal implementations of the
// their sockaddr interface, so they cannot be used with HvsockAddr
// Replicate functionality here from
// https://cs.opensource.google/go/x/sys/+/master:windows/syscall_windows.go
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, this may be why you defined bind above.

@dcantah
Copy link
Contributor

dcantah commented Mar 21, 2022

This does a heck of a lot more than the title leads on 😆. Preferably this should be split across multiple commits (possibly even multiple PRs). I don't think we should bump to 1.17 in this PR at the very least, we can shoot to get this in #230, but I think the more important fact is the dial and registry work here

@dcantah dcantah self-assigned this Mar 21, 2022
@helsaawy
Copy link
Contributor Author

I don't think we should bump to 1.17 in this PR at the very least, we can shoot to get this in #230, but I think the more important fact is the dial and registry work here

I think my implementation of dial needs 1.17 for unsafe.Slice, so I'll wait for #230 to be merged

@helsaawy
Copy link
Contributor Author

Ill split this into a functionality PR and a tests PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants