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

sock_stress: fix hvsock URL parsing #67

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 9 additions & 16 deletions cmd/sock_stress/hvsock.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

var (
svcid, _ = hvsock.GUIDFromString("3049197C-FACB-11E6-BD58-64006A7986D3")
svcid, _ = hvsock.GUIDFromString("3049197C-FACB-11E6-BD58-64006A7986D3")
useHVSock = false
)

Expand All @@ -28,30 +28,23 @@ func init() {
// The format is "VMID:Service", "VMID", or ":Service" as well as an
// empty string. For VMID we also support "parent" and assume
// "loopback" if the string can't be parsed.
func hvsockParseSockStr(sockStr string) hvsockAddr {
func hvsockParseSockStr(vmStr, svcStr string) hvsockAddr {
hvAddr := hvsock.Addr{hvsock.GUIDZero, svcid}
port, _ := svcid.Port()
port, _ := svcid.Port()
vAddr := vsock.Addr{vsock.CIDAny, port}
if sockStr == "" {
if svcStr != "" && svcStr[0] == '/' {
svcStr = svcStr[1:]
}
if vmStr == "" && svcStr == "" {
return hvsockAddr{hvAddr: hvAddr, vAddr: vAddr}
}

var err error
vmStr := ""
svcStr := ""
if strings.Contains(sockStr, ":") {
vmStr, svcStr, err = net.SplitHostPort(sockStr)
if err != nil {
log.Fatalf("Error parsing socket string '%s': %v", sockStr, err)
}
} else {
vmStr = sockStr
}

if vmStr != "" {
if strings.Contains(vmStr, "-") {
if !useHVSock {
log.Fatalf("Can't use VM GUIDs in vsock mode")
log.Fatalf("Can't use VM GUIDs in vsock mode")
}
hvAddr.VMID, err = hvsock.GUIDFromString(vmStr)
if err != nil {
Expand All @@ -72,7 +65,7 @@ func hvsockParseSockStr(sockStr string) hvsockAddr {
}
if !useHVSock {
if vAddr.Port, err = hvAddr.ServiceID.Port(); err != nil {
log.Fatal("Error parsing SVC '%s': %v", svcStr, err)
log.Fatalf("Error parsing SVC '%s': %v", svcStr, err)
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/sock_stress/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ func init() {
fmt.Printf(" %s -s vsock Start server in vsock mode on standard port\n", prog)
fmt.Printf(" %s -s vsock://:1235 Start server in vsock mode on a non-standard port\n", prog)
fmt.Printf(" %s -c hvsock://<vmid> Start client in hvsock mode connecting to VM with <vmid>\n", prog)
fmt.Printf(" %s -c hvsock://<vmid>/<svcid> Start client in hvsock mode connecting to VM with <vmid> on a non-standard <svcid>\n", prog)
}
rand.Seed(time.Now().UnixNano())
}
Expand Down Expand Up @@ -172,7 +173,7 @@ func parseSockStr(inStr string) (string, Sock) {
case "vsock":
return u.Scheme, vsockParseSockStr(u.Host)
case "hvsock":
return u.Scheme, hvsockParseSockStr(u.Host)
return u.Scheme, hvsockParseSockStr(u.Host, u.Path)
case "tcp", "tcp4", "tcp6":
return u.Scheme, tcpParseSockStr(u.Scheme, u.Host)
case "udp", "udp4", "udp6":
Expand Down
13 changes: 13 additions & 0 deletions cmd/sock_stress/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package main

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestParseHVSock(t *testing.T) {
scheme, sock := parseSockStr("hvsock://00000000-0000-0000-0000-000000000000/00001010-FACB-11E6-BD58-64006A7986D3")
assert.Equal(t, "hvsock", scheme)
assert.Equal(t, "00000000-0000-0000-0000-000000000000:00001010-facb-11e6-bd58-64006a7986d3", sock.String())
}
15 changes: 15 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module github.com/linuxkit/virtsock

go 1.17

require (
github.com/pkg/errors v0.8.1-0.20170910134614-2b3a18b5f0fb
github.com/stretchr/testify v1.7.1
golang.org/x/sys v0.0.0-20170511214829-9c9d83fe39ed
)

require (
github.com/davecgh/go-spew v1.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
)
14 changes: 14 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pkg/errors v0.8.1-0.20170910134614-2b3a18b5f0fb h1:CKWls8QOVQs/qmuUuGOeHMpIqSx6f9S72udJ48vEeKo=
github.com/pkg/errors v0.8.1-0.20170910134614-2b3a18b5f0fb/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/sys v0.0.0-20170511214829-9c9d83fe39ed h1:zZ09nMxaZ+d+ObsmknNM+RrXWBw+22dzC/Fm62ueXgs=
golang.org/x/sys v0.0.0-20170511214829-9c9d83fe39ed/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
15 changes: 15 additions & 0 deletions vendor/github.com/davecgh/go-spew/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

152 changes: 152 additions & 0 deletions vendor/github.com/davecgh/go-spew/spew/bypass.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions vendor/github.com/davecgh/go-spew/spew/bypasssafe.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading