Skip to content

Commit

Permalink
Rename functions for consistency.
Browse files Browse the repository at this point in the history
  • Loading branch information
NullHypothesis committed Dec 25, 2024
1 parent 8c0d07c commit 502fd3f
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 13 deletions.
4 changes: 2 additions & 2 deletions cmd/veil-proxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ func acceptLoop(ln net.Listener) {

var wg sync.WaitGroup
wg.Add(2)
go proxy.VsockToTun(vm, tunDev, ch, &wg)
go proxy.TunToVsock(tunDev, vm, ch, &wg)
go proxy.VSOCKToTun(vm, tunDev, ch, &wg)
go proxy.TunToVSOCK(tunDev, vm, ch, &wg)
wg.Wait()
}
}
Expand Down
3 changes: 2 additions & 1 deletion internal/net/nat/nat.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package nat

import (
"github.com/Amnesic-Systems/veil/internal/net/tun"
"github.com/coreos/go-iptables/iptables"

"github.com/Amnesic-Systems/veil/internal/net/tun"
)

// Enable enables our iptables NAT rules, which connect the enclave to the
Expand Down
18 changes: 14 additions & 4 deletions internal/net/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,16 @@ import (

const lenBufSize = 2

// TunToVsock forwards network packets from the tun device to our
// TunToVSOCK forwards network packets from the tun device to our
// TCP-over-VSOCK connection. The function keeps on forwarding packets until we
// encounter an error or EOF. Errors (including EOF) are written to the given
// channel.
func TunToVsock(from io.ReadCloser, to io.WriteCloser, ch chan error, wg *sync.WaitGroup) {
func TunToVSOCK(
from io.ReadCloser,
to io.WriteCloser,
ch chan error,
wg *sync.WaitGroup,
) {
defer to.Close()
defer wg.Done()
var (
Expand Down Expand Up @@ -43,11 +48,16 @@ func TunToVsock(from io.ReadCloser, to io.WriteCloser, ch chan error, wg *sync.W
ch <- fmt.Errorf("stopped tun-to-vsock forwarding: %w", err)
}

// VsockToTun forwards network packets from our TCP-over-VSOCK connection to
// VSOCKToTun forwards network packets from our TCP-over-VSOCK connection to
// the tun interface. The function keeps on forwarding packets until we
// encounter an error or EOF. Errors (including EOF) are written to the given
// channel.
func VsockToTun(from io.ReadCloser, to io.WriteCloser, ch chan error, wg *sync.WaitGroup) {
func VSOCKToTun(
from io.ReadCloser,
to io.WriteCloser,
ch chan error,
wg *sync.WaitGroup,
) {
defer to.Close()
defer wg.Done()
var (
Expand Down
8 changes: 4 additions & 4 deletions internal/net/proxy/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ func TestNettest(t *testing.T) {
ch = make(chan error)
)
wg.Add(2)
go TunToVsock(in, fwd1, ch, &wg)
go VsockToTun(fwd2, out, ch, &wg)
go TunToVSOCK(in, fwd1, ch, &wg)
go VSOCKToTun(fwd2, out, ch, &wg)
return in, out, func() {}, nil
}
nettest.TestConn(t, nettest.MakePipe(mkPipe))
Expand Down Expand Up @@ -69,8 +69,8 @@ func TestAToB(t *testing.T) {
assertEq(t, err, nil)

wg.Add(2)
go TunToVsock(io.NopCloser(bytes.NewReader(sendBuf)), conn1, ch, &wg)
go VsockToTun(conn2, recvBuf, ch, &wg)
go TunToVSOCK(io.NopCloser(bytes.NewReader(sendBuf)), conn1, ch, &wg)
go VSOCKToTun(conn2, recvBuf, ch, &wg)
wg.Wait()

assertEq(t, bytes.Equal(
Expand Down
4 changes: 2 additions & 2 deletions internal/tunnel/vsock.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ func setupTunnel(
// Spawn goroutines that forward traffic and wait for them to finish.
wg.Add(2)
defer wg.Wait()
go proxy.VsockToTun(conn, tun, errCh, &wg)
go proxy.TunToVsock(tun, conn, errCh, &wg)
go proxy.VSOCKToTun(conn, tun, errCh, &wg)
go proxy.TunToVSOCK(tun, conn, errCh, &wg)
log.Println("Started goroutines to forward traffic.")

// Reset the backoff interval.
Expand Down

0 comments on commit 502fd3f

Please sign in to comment.