mirror of
https://github.com/containers/gvisor-tap-vsock.git
synced 2025-09-26 21:01:42 +08:00
Fix all linting errors found by cross-lint
Signed-off-by: Gunjan Vyas <vyasgun20@gmail.com>
This commit is contained in:
@@ -100,12 +100,16 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
logrus.Debug("Setting up proxies")
|
logrus.Debug("Setting up proxies")
|
||||||
setupProxies(ctx, group, sources, dests, identities)
|
err = setupProxies(ctx, group, sources, dests, identities)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Errorf("Error setting up proxies: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Wait for cmopletion (cancellation) or error
|
// Wait for completion (cancellation) or error
|
||||||
if err := group.Wait(); err != nil {
|
if err := group.Wait(); err != nil {
|
||||||
logrus.Errorf("Error occured in execution group: " + err.Error())
|
logrus.Errorf("Error occurred in execution group: " + err.Error())
|
||||||
os.Exit(1)
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
|
//go:build windows
|
||||||
// +build windows
|
// +build windows
|
||||||
|
|
||||||
package fs
|
package fs
|
||||||
|
@@ -30,7 +30,7 @@ func ListenNpipe(socketURI *url.URL) (net.Listener, error) {
|
|||||||
InputBufferSize: 65536,
|
InputBufferSize: 65536,
|
||||||
OutputBufferSize: 65536,
|
OutputBufferSize: 65536,
|
||||||
}
|
}
|
||||||
path := strings.Replace(socketURI.Path, "/", "\\", -1)
|
path := strings.ReplaceAll(socketURI.Path, "/", "\\")
|
||||||
|
|
||||||
listener, err := winio.ListenPipe(path, &config)
|
listener, err := winio.ListenPipe(path, &config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@@ -47,7 +47,9 @@ var _ = Describe("connectivity", func() {
|
|||||||
It("proxies over a windows pipe", func() {
|
It("proxies over a windows pipe", func() {
|
||||||
err := startProxy()
|
err := startProxy()
|
||||||
Expect(err).ShouldNot(HaveOccurred())
|
Expect(err).ShouldNot(HaveOccurred())
|
||||||
defer stopProxy(false)
|
defer func() {
|
||||||
|
Expect(stopProxy(false)).ShouldNot(HaveOccurred())
|
||||||
|
}()
|
||||||
httpClient := &http.Client{
|
httpClient := &http.Client{
|
||||||
Transport: &http.Transport{
|
Transport: &http.Transport{
|
||||||
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
|
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
|
||||||
@@ -71,19 +73,18 @@ var _ = Describe("connectivity", func() {
|
|||||||
g.Expect(string(reply)).To(Equal("pong"))
|
g.Expect(string(reply)).To(Equal("pong"))
|
||||||
|
|
||||||
}).Should(Succeed())
|
}).Should(Succeed())
|
||||||
|
|
||||||
err = stopProxy(true)
|
|
||||||
Expect(err).ShouldNot(HaveOccurred())
|
|
||||||
})
|
})
|
||||||
|
|
||||||
It("windows event logs were created", func() {
|
It("windows event logs were created", func() {
|
||||||
cmd := exec.Command("powershell", "-Command", "&{Get-WinEvent -ProviderName \".NET Runtime\" -MaxEvents 10 | Where-Object -Property Message -Match \"test:\"}")
|
cmd := exec.Command("powershell", "-Command", "&{Get-WinEvent -ProviderName \".NET Runtime\" -MaxEvents 10 | Where-Object -Property Message -Match \"test:\"}")
|
||||||
reader, err := cmd.StdoutPipe()
|
reader, err := cmd.StdoutPipe()
|
||||||
Expect(err).ShouldNot(HaveOccurred())
|
Expect(err).ShouldNot(HaveOccurred())
|
||||||
cmd.Start()
|
err = cmd.Start()
|
||||||
|
Expect(err).ShouldNot(HaveOccurred())
|
||||||
output, err := io.ReadAll(reader)
|
output, err := io.ReadAll(reader)
|
||||||
Expect(err).ShouldNot(HaveOccurred())
|
Expect(err).ShouldNot(HaveOccurred())
|
||||||
cmd.Wait()
|
err = cmd.Wait()
|
||||||
|
Expect(err).ShouldNot(HaveOccurred())
|
||||||
Expect(strings.Contains(string(output), `[info ] test: Listening on: \\.\pipe\fake_docker_engine`)).Should(BeTrue())
|
Expect(strings.Contains(string(output), `[info ] test: Listening on: \\.\pipe\fake_docker_engine`)).Should(BeTrue())
|
||||||
Expect(strings.Contains(string(output), `[debug] test: Socket forward established`)).Should(BeTrue())
|
Expect(strings.Contains(string(output), `[debug] test: Socket forward established`)).Should(BeTrue())
|
||||||
})
|
})
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
|
//go:build windows
|
||||||
// +build windows
|
// +build windows
|
||||||
|
|
||||||
package e2e
|
package e2e
|
||||||
@@ -42,7 +43,7 @@ func startMockServer() {
|
|||||||
}
|
}
|
||||||
sshConfig.AddHostKey(key)
|
sshConfig.AddHostKey(key)
|
||||||
|
|
||||||
listener, err := net.Listen("tcp", ":2134")
|
listener, err := net.Listen("tcp", "localhost:2134")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@@ -58,7 +59,7 @@ func startMockServer() {
|
|||||||
break loop
|
break loop
|
||||||
default:
|
default:
|
||||||
// proceed
|
// proceed
|
||||||
}
|
}
|
||||||
conn, err := listener.Accept()
|
conn, err := listener.Accept()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@@ -83,7 +84,7 @@ func stopMockServer() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func handleRequests(reqs <-chan *ssh.Request) {
|
func handleRequests(reqs <-chan *ssh.Request) {
|
||||||
for _ = range reqs {
|
for range reqs {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,14 +92,20 @@ func handleChannels(chans <-chan ssh.NewChannel) {
|
|||||||
directMsg := streamLocalDirect{}
|
directMsg := streamLocalDirect{}
|
||||||
for newChannel := range chans {
|
for newChannel := range chans {
|
||||||
if t := newChannel.ChannelType(); t != "direct-streamlocal@openssh.com" {
|
if t := newChannel.ChannelType(); t != "direct-streamlocal@openssh.com" {
|
||||||
newChannel.Reject(ssh.UnknownChannelType, fmt.Sprintf("unknown channel type: %s", t))
|
err := newChannel.Reject(ssh.UnknownChannelType, fmt.Sprintf("unknown channel type: %s", t))
|
||||||
|
if err != nil {
|
||||||
|
logrus.Errorf("could not reject channel: %s", err)
|
||||||
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := ssh.Unmarshal(newChannel.ExtraData(), &directMsg); err != nil {
|
if err := ssh.Unmarshal(newChannel.ExtraData(), &directMsg); err != nil {
|
||||||
logrus.Errorf("could not direct-streamlocal data: %s", err)
|
logrus.Errorf("could not direct-streamlocal data: %s", err)
|
||||||
|
|
||||||
newChannel.Reject(ssh.Prohibited, "invalid format")
|
err = newChannel.Reject(ssh.Prohibited, "invalid format")
|
||||||
|
if err != nil {
|
||||||
|
logrus.Errorf("could not reject channel: %s", err)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,7 +131,13 @@ func handleChannels(chans <-chan ssh.NewChannel) {
|
|||||||
resp.StatusCode = 404
|
resp.StatusCode = 404
|
||||||
resp.ContentLength = 0
|
resp.ContentLength = 0
|
||||||
}
|
}
|
||||||
resp.Write(channel)
|
err = resp.Write(channel)
|
||||||
channel.CloseWrite()
|
if err != nil {
|
||||||
|
logrus.Errorf("could not write response: %s", err)
|
||||||
|
}
|
||||||
|
err = channel.CloseWrite()
|
||||||
|
if err != nil {
|
||||||
|
logrus.Errorf("could not close write: %s", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
|
//go:build windows
|
||||||
// +build windows
|
// +build windows
|
||||||
|
|
||||||
package e2e
|
package e2e
|
||||||
@@ -14,6 +15,7 @@ import (
|
|||||||
|
|
||||||
. "github.com/onsi/ginkgo"
|
. "github.com/onsi/ginkgo"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -64,14 +66,20 @@ func readTid() (uint32, uint32, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var pid, tid uint32
|
var pid, tid uint32
|
||||||
fmt.Sscanf(string(contents), "%d:%d", &pid, &tid)
|
_, err = fmt.Sscanf(string(contents), "%d:%d", &pid, &tid)
|
||||||
|
if err != nil {
|
||||||
|
return 0, 0, err
|
||||||
|
}
|
||||||
return pid, tid, nil
|
return pid, tid, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendQuit(tid uint32) {
|
func sendQuit(tid uint32) {
|
||||||
user32 := syscall.NewLazyDLL("user32.dll")
|
user32 := syscall.NewLazyDLL("user32.dll")
|
||||||
postMessage := user32.NewProc("PostThreadMessageW")
|
postMessage := user32.NewProc("PostThreadMessageW")
|
||||||
postMessage.Call(uintptr(tid), WM_QUIT, 0, 0)
|
_, _, err := postMessage.Call(uintptr(tid), WM_QUIT, 0, 0)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Errorf("Error posting quit message: %v", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func stopProxy(noKill bool) error {
|
func stopProxy(noKill bool) error {
|
||||||
|
Reference in New Issue
Block a user