From fe194eac7683a122d8f20cbb19acb53024c326c0 Mon Sep 17 00:00:00 2001 From: Kr328 <39107975+Kr328@users.noreply.github.com> Date: Tue, 19 Nov 2019 09:27:18 +0800 Subject: [PATCH] tun device private --- core/src/main/golang/tun/dev.go | 10 +++++----- core/src/main/golang/tun/tun.go | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/core/src/main/golang/tun/dev.go b/core/src/main/golang/tun/dev.go index dc97232..ecac297 100644 --- a/core/src/main/golang/tun/dev.go +++ b/core/src/main/golang/tun/dev.go @@ -11,13 +11,13 @@ import ( "github.com/Dreamacro/clash/log" ) -type TunDevice struct { +type tunDevice struct { mtu int fd int linkCache *stack.LinkEndpoint } -func OpenTunDevice(fd int, mtu int) (*TunDevice, error) { +func openTunDevice(fd int, mtu int) (*tunDevice, error) { var ifr struct { name [16]byte flags uint16 @@ -35,13 +35,13 @@ func OpenTunDevice(fd int, mtu int) (*TunDevice, error) { log.Infoln("Open tun fd = %d mtu = %d", fd, mtu) - return &TunDevice{ + return &tunDevice{ fd: fd, mtu: mtu, }, nil } -func (t TunDevice) AsLinkEndpoint() (result stack.LinkEndpoint, err error) { +func (t tunDevice) asLinkEndpoint() (result stack.LinkEndpoint, err error) { if t.linkCache != nil { return *t.linkCache, nil } @@ -61,6 +61,6 @@ func (t TunDevice) AsLinkEndpoint() (result stack.LinkEndpoint, err error) { return result, nil } -func (t TunDevice) Close() { +func (t tunDevice) close() { syscall.Close(t.fd) } diff --git a/core/src/main/golang/tun/tun.go b/core/src/main/golang/tun/tun.go index cd2ed2f..4bb6425 100644 --- a/core/src/main/golang/tun/tun.go +++ b/core/src/main/golang/tun/tun.go @@ -25,7 +25,7 @@ import ( ) type tun struct { - device *TunDevice + device *tunDevice ipstack *stack.Stack } @@ -56,7 +56,7 @@ func StopTunProxy() { } func newTunProxy(fd int, mtu int) (*tun, error) { - tundev, err := OpenTunDevice(fd, mtu) + tundev, err := openTunDevice(fd, mtu) if err != nil { return nil, fmt.Errorf("Can't open tun: %v", err) } @@ -66,7 +66,7 @@ func newTunProxy(fd int, mtu int) (*tun, error) { TransportProtocols: []stack.TransportProtocol{tcp.NewProtocol(), udp.NewProtocol()}, }) - linkEP, err := tundev.AsLinkEndpoint() + linkEP, err := tundev.asLinkEndpoint() if err != nil { return nil, fmt.Errorf("Unable to create virtual endpoint: %v", err) } @@ -120,14 +120,14 @@ func newTunProxy(fd int, mtu int) (*tun, error) { ipstack: ipstack, } - log.Infoln("Tun device opened") + log.Infoln("Tun Adapter ready", fd, mtu) return tl, nil } // Close close the TunAdapter func (t *tun) close() { - t.device.Close() + t.device.close() t.ipstack.Close() }