From 112dc008d1a555b3ff4f5c051d44470110cd429f Mon Sep 17 00:00:00 2001 From: Penny Zheng Date: Thu, 9 Jan 2020 01:27:28 +0000 Subject: [PATCH] DEBUG: vendor update Add changes from kata-containers/agent#706. THIS IS ONLY FOR DEBUGGING! Signed-off-by: Penny Zheng --- .../agent/protocols/client/client.go | 46 ++++++++++--------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/vendor/github.com/kata-containers/agent/protocols/client/client.go b/vendor/github.com/kata-containers/agent/protocols/client/client.go index 43b9a94525..c250792f7f 100644 --- a/vendor/github.com/kata-containers/agent/protocols/client/client.go +++ b/vendor/github.com/kata-containers/agent/protocols/client/client.go @@ -7,21 +7,22 @@ package client import ( + "bufio" "context" + "errors" "fmt" - "io" "net" "net/url" + "os" "strconv" "strings" - "syscall" "time" "github.com/grpc-ecosystem/grpc-opentracing/go/otgrpc" "github.com/hashicorp/yamux" "github.com/mdlayher/vsock" opentracing "github.com/opentracing/opentracing-go" - "golang.org/x/sys/unix" + "github.com/sirupsen/logrus" "google.golang.org/grpc" "google.golang.org/grpc/codes" grpcStatus "google.golang.org/grpc/status" @@ -40,6 +41,14 @@ var defaultCloseTimeout = 5 * time.Second var hybridVSockPort uint32 +var agentClientFields = logrus.Fields{ + "name": "agent-client", + "pid": os.Getpid(), + "source": "agent-client", +} + +var agentClientLog = logrus.WithFields(agentClientFields) + // AgentClient is an agent gRPC client connection wrapper for agentgrpc.AgentServiceClient type AgentClient struct { agentgrpc.AgentServiceClient @@ -410,24 +419,19 @@ func HybridVSockDialer(sock string, timeout time.Duration) (net.Conn, error) { return nil, err } - // Receive the packet from the connection without removing it from - // the receive queue (MSG_PEEK), ensuring the connection is usable. - if uc, ok := conn.(*net.UnixConn); ok { - file, err := uc.File() - if err != nil { - conn.Close() - return nil, err - } - eot := make([]byte, 1) - n, _, err := unix.Recvfrom(int(file.Fd()), eot, syscall.MSG_PEEK) - file.Close() - if err != nil || n == 0 { - conn.Close() - if err == nil { - err = io.EOF - } - return nil, err - } + // A trivial handshake is included in the host-initiated vsock connection protocol. + // It looks like this: + // - [host] CONNECT + // - [guest/success] OK + reader := bufio.NewReader(conn) + response, err := reader.ReadString('\n') + agentClientLog.WithField("response", response).Debug("HybridVsock trivial handshake") + if err != nil { + conn.Close() + return nil, err + } else if !strings.Contains(response, "OK") { + conn.Close() + return nil, errors.New("malformed response code") } return conn, nil