diff options
-rw-r--r-- | pkg/tcpip/link/wireguard/gtun.go (renamed from pkg/tcpip/sample/wg_tunnel/gtun.go) | 24 | ||||
-rw-r--r-- | pkg/tcpip/sample/wg_tunnel/main.go | 5 |
2 files changed, 15 insertions, 14 deletions
diff --git a/pkg/tcpip/sample/wg_tunnel/gtun.go b/pkg/tcpip/link/wireguard/gtun.go index d641fc42d..d533ca5ba 100644 --- a/pkg/tcpip/sample/wg_tunnel/gtun.go +++ b/pkg/tcpip/link/wireguard/gtun.go @@ -1,4 +1,4 @@ -package main +package wireguard import ( "context" @@ -13,7 +13,7 @@ import ( wgtun "golang.zx2c4.com/wireguard/tun" ) -type GoTun struct { +type WgTun struct { events chan wgtun.Event ch *channel.Endpoint stack *stack.Stack @@ -21,12 +21,12 @@ type GoTun struct { cancel context.CancelFunc } -func (tun *GoTun) File() *os.File { +func (tun *WgTun) File() *os.File { fmt.Println("File") return nil } -func (tun *GoTun) Read(buff []byte, offset int) (int, error) { +func (tun *WgTun) Read(buff []byte, offset int) (int, error) { fmt.Println("Read ", len(buff), offset) p, ok := tun.ch.ReadContext(tun.ctx) @@ -58,7 +58,7 @@ func versionToProtocol(version int) tcpip.NetworkProtocolNumber { return 0 } -func (tun *GoTun) Write(buff []byte, offset int) (int, error) { +func (tun *WgTun) Write(buff []byte, offset int) (int, error) { size := len(buff) - offset fmt.Println("Write ", len(buff), offset, size) @@ -86,38 +86,38 @@ func (tun *GoTun) Write(buff []byte, offset int) (int, error) { return size, nil } -func (tun *GoTun) Flush() error { +func (tun *WgTun) Flush() error { // TODO: can flushing be implemented by buffering and using sendmmsg? fmt.Println("Flush") return nil } -func (tun *GoTun) MTU() (int, error) { +func (tun *WgTun) MTU() (int, error) { fmt.Println("MTU") return 1280, nil } -func (tun *GoTun) Name() (string, error) { +func (tun *WgTun) Name() (string, error) { fmt.Println("Name") return "foobar", nil } -func (tun *GoTun) Events() chan wgtun.Event { +func (tun *WgTun) Events() chan wgtun.Event { fmt.Println("Events") return tun.events } -func (tun *GoTun) Close() error { +func (tun *WgTun) Close() error { fmt.Println("Close") // TODO // tun.cancel() return nil } -func CreateGoTun(s *stack.Stack, ch *channel.Endpoint) (wgtun.Device, error) { +func CreateWgTun(s *stack.Stack, ch *channel.Endpoint) (wgtun.Device, error) { size := 16 ctx, cancel := context.WithCancel(context.Background()) - tun := &GoTun{ + tun := &WgTun{ ch: ch, events: make(chan wgtun.Event, size), stack: s, diff --git a/pkg/tcpip/sample/wg_tunnel/main.go b/pkg/tcpip/sample/wg_tunnel/main.go index b859dff7a..1c87a09c2 100644 --- a/pkg/tcpip/sample/wg_tunnel/main.go +++ b/pkg/tcpip/sample/wg_tunnel/main.go @@ -44,6 +44,7 @@ import ( "gvisor.dev/gvisor/pkg/tcpip/link/loopback" "gvisor.dev/gvisor/pkg/tcpip/link/rawfile" "gvisor.dev/gvisor/pkg/tcpip/link/tun" + "gvisor.dev/gvisor/pkg/tcpip/link/wireguard" "gvisor.dev/gvisor/pkg/tcpip/network/arp" "gvisor.dev/gvisor/pkg/tcpip/network/ipv4" "gvisor.dev/gvisor/pkg/tcpip/network/ipv6" @@ -295,9 +296,9 @@ func addWgLink(s *stack.Stack, nic tcpip.NICID, interfaceName string, addr tcpip //mtu := 1500 // tun, err := wg_tun.CreateTUN(interfaceName, mtu) - tun, err := CreateGoTun(s, ep) + tun, err := wireguard.CreateWgTun(s, ep) if err != nil { - log.Fatal("CreateGoTun", err) + log.Fatal("CreateWgTun", err) } |