Skip to content

Commit

Permalink
sock_stress: use URL path for svcID
Browse files Browse the repository at this point in the history
This avoids the problem with `url.Parse` rejecting the non-integer port.

Signed-off-by: David Scott <dave@recoil.org>
  • Loading branch information
djs55 committed May 22, 2022
1 parent f8627e0 commit 4a6cb97
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
17 changes: 5 additions & 12 deletions cmd/sock_stress/hvsock.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,18 @@ 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()
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, "-") {
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

0 comments on commit 4a6cb97

Please sign in to comment.