From 1f48971a80f48257e478e532f6971d0557026120 Mon Sep 17 00:00:00 2001 From: Matt Layher Date: Mon, 10 Jun 2019 17:33:40 -0400 Subject: tun: remove TUN prefix from types to reduce stutter elsewhere Signed-off-by: Matt Layher --- tun/tun.go | 12 ++++++------ tun/tun_darwin.go | 16 ++++++++-------- tun/tun_freebsd.go | 16 ++++++++-------- tun/tun_linux.go | 32 ++++++++++++++++---------------- tun/tun_openbsd.go | 16 ++++++++-------- tun/tun_windows.go | 10 +++++----- 6 files changed, 51 insertions(+), 51 deletions(-) (limited to 'tun') diff --git a/tun/tun.go b/tun/tun.go index 12febb8..5395bdb 100644 --- a/tun/tun.go +++ b/tun/tun.go @@ -9,21 +9,21 @@ import ( "os" ) -type TUNEvent int +type Event int const ( - TUNEventUp = 1 << iota - TUNEventDown - TUNEventMTUUpdate + EventUp = 1 << iota + EventDown + EventMTUUpdate ) -type TUNDevice interface { +type Device interface { File() *os.File // returns the file descriptor of the device Read([]byte, int) (int, error) // read a packet from the device (without any additional headers) Write([]byte, int) (int, error) // writes a packet to the device (without any additional headers) Flush() error // flush all previous writes to the device MTU() (int, error) // returns the MTU of the device Name() (string, error) // fetches and returns the current name - Events() chan TUNEvent // returns a constant channel of events related to the device + Events() chan Event // returns a constant channel of events related to the device Close() error // stops the device and closes the event channel } diff --git a/tun/tun_darwin.go b/tun/tun_darwin.go index 8cd22a8..0815495 100644 --- a/tun/tun_darwin.go +++ b/tun/tun_darwin.go @@ -35,7 +35,7 @@ type sockaddrCtl struct { type NativeTun struct { name string tunFile *os.File - events chan TUNEvent + events chan Event errors chan error routeSocket int } @@ -86,22 +86,22 @@ func (tun *NativeTun) routineRouteListener(tunIfindex int) { // Up / Down event up := (iface.Flags & net.FlagUp) != 0 if up != statusUp && up { - tun.events <- TUNEventUp + tun.events <- EventUp } if up != statusUp && !up { - tun.events <- TUNEventDown + tun.events <- EventDown } statusUp = up // MTU changes if iface.MTU != statusMTU { - tun.events <- TUNEventMTUUpdate + tun.events <- EventMTUUpdate } statusMTU = iface.MTU } } -func CreateTUN(name string, mtu int) (TUNDevice, error) { +func CreateTUN(name string, mtu int) (Device, error) { ifIndex := -1 if name != "utun" { _, err := fmt.Sscanf(name, "utun%d", &ifIndex) @@ -171,10 +171,10 @@ func CreateTUN(name string, mtu int) (TUNDevice, error) { return tun, err } -func CreateTUNFromFile(file *os.File, mtu int) (TUNDevice, error) { +func CreateTUNFromFile(file *os.File, mtu int) (Device, error) { tun := &NativeTun{ tunFile: file, - events: make(chan TUNEvent, 10), + events: make(chan Event, 10), errors: make(chan error, 5), } @@ -244,7 +244,7 @@ func (tun *NativeTun) File() *os.File { return tun.tunFile } -func (tun *NativeTun) Events() chan TUNEvent { +func (tun *NativeTun) Events() chan Event { return tun.events } diff --git a/tun/tun_freebsd.go b/tun/tun_freebsd.go index df43ab7..6cf9313 100644 --- a/tun/tun_freebsd.go +++ b/tun/tun_freebsd.go @@ -79,7 +79,7 @@ type in6_ndireq struct { type NativeTun struct { name string tunFile *os.File - events chan TUNEvent + events chan Event errors chan error routeSocket int } @@ -125,16 +125,16 @@ func (tun *NativeTun) routineRouteListener(tunIfindex int) { // Up / Down event up := (iface.Flags & net.FlagUp) != 0 if up != statusUp && up { - tun.events <- TUNEventUp + tun.events <- EventUp } if up != statusUp && !up { - tun.events <- TUNEventDown + tun.events <- EventDown } statusUp = up // MTU changes if iface.MTU != statusMTU { - tun.events <- TUNEventMTUUpdate + tun.events <- EventMTUUpdate } statusMTU = iface.MTU } @@ -246,7 +246,7 @@ func tunDestroy(name string) error { return nil } -func CreateTUN(name string, mtu int) (TUNDevice, error) { +func CreateTUN(name string, mtu int) (Device, error) { if len(name) > unix.IFNAMSIZ-1 { return nil, errors.New("interface name too long") } @@ -365,11 +365,11 @@ func CreateTUN(name string, mtu int) (TUNDevice, error) { return CreateTUNFromFile(tunFile, mtu) } -func CreateTUNFromFile(file *os.File, mtu int) (TUNDevice, error) { +func CreateTUNFromFile(file *os.File, mtu int) (Device, error) { tun := &NativeTun{ tunFile: file, - events: make(chan TUNEvent, 10), + events: make(chan Event, 10), errors: make(chan error, 1), } @@ -425,7 +425,7 @@ func (tun *NativeTun) File() *os.File { return tun.tunFile } -func (tun *NativeTun) Events() chan TUNEvent { +func (tun *NativeTun) Events() chan Event { return tun.events } diff --git a/tun/tun_linux.go b/tun/tun_linux.go index 2168f5b..61902e9 100644 --- a/tun/tun_linux.go +++ b/tun/tun_linux.go @@ -31,11 +31,11 @@ const ( type NativeTun struct { tunFile *os.File - index int32 // if index - name string // name of interface - errors chan error // async error handling - events chan TUNEvent // device related events - nopi bool // the device was pased IFF_NO_PI + index int32 // if index + name string // name of interface + errors chan error // async error handling + events chan Event // device related events + nopi bool // the device was pased IFF_NO_PI netlinkSock int netlinkCancel *rwcancel.RWCancel hackListenerClosed sync.Mutex @@ -64,9 +64,9 @@ func (tun *NativeTun) routineHackListener() { } switch err { case unix.EINVAL: - tun.events <- TUNEventUp + tun.events <- EventUp case unix.EIO: - tun.events <- TUNEventDown + tun.events <- EventDown default: return } @@ -148,14 +148,14 @@ func (tun *NativeTun) routineNetlinkListener() { } if info.Flags&unix.IFF_RUNNING != 0 { - tun.events <- TUNEventUp + tun.events <- EventUp } if info.Flags&unix.IFF_RUNNING == 0 { - tun.events <- TUNEventDown + tun.events <- EventDown } - tun.events <- TUNEventMTUUpdate + tun.events <- EventMTUUpdate default: remain = remain[hdr.Len:] @@ -342,7 +342,7 @@ func (tun *NativeTun) Read(buff []byte, offset int) (int, error) { } } -func (tun *NativeTun) Events() chan TUNEvent { +func (tun *NativeTun) Events() chan Event { return tun.events } @@ -364,7 +364,7 @@ func (tun *NativeTun) Close() error { return err2 } -func CreateTUN(name string, mtu int) (TUNDevice, error) { +func CreateTUN(name string, mtu int) (Device, error) { nfd, err := unix.Open(cloneDevicePath, os.O_RDWR, 0) if err != nil { return nil, err @@ -400,10 +400,10 @@ func CreateTUN(name string, mtu int) (TUNDevice, error) { return CreateTUNFromFile(fd, mtu) } -func CreateTUNFromFile(file *os.File, mtu int) (TUNDevice, error) { +func CreateTUNFromFile(file *os.File, mtu int) (Device, error) { tun := &NativeTun{ tunFile: file, - events: make(chan TUNEvent, 5), + events: make(chan Event, 5), errors: make(chan error, 5), statusListenersShutdown: make(chan struct{}), nopi: false, @@ -445,7 +445,7 @@ func CreateTUNFromFile(file *os.File, mtu int) (TUNDevice, error) { return tun, nil } -func CreateUnmonitoredTUNFromFD(fd int) (TUNDevice, string, error) { +func CreateUnmonitoredTUNFromFD(fd int) (Device, string, error) { err := unix.SetNonblock(fd, true) if err != nil { return nil, "", err @@ -453,7 +453,7 @@ func CreateUnmonitoredTUNFromFD(fd int) (TUNDevice, string, error) { file := os.NewFile(uintptr(fd), "/dev/tun") tun := &NativeTun{ tunFile: file, - events: make(chan TUNEvent, 5), + events: make(chan Event, 5), errors: make(chan error, 5), nopi: true, } diff --git a/tun/tun_openbsd.go b/tun/tun_openbsd.go index b0f5ca4..1e6191f 100644 --- a/tun/tun_openbsd.go +++ b/tun/tun_openbsd.go @@ -29,7 +29,7 @@ const _TUNSIFMODE = 0x8004745d type NativeTun struct { name string tunFile *os.File - events chan TUNEvent + events chan Event errors chan error routeSocket int } @@ -75,16 +75,16 @@ func (tun *NativeTun) routineRouteListener(tunIfindex int) { // Up / Down event up := (iface.Flags & net.FlagUp) != 0 if up != statusUp && up { - tun.events <- TUNEventUp + tun.events <- EventUp } if up != statusUp && !up { - tun.events <- TUNEventDown + tun.events <- EventDown } statusUp = up // MTU changes if iface.MTU != statusMTU { - tun.events <- TUNEventMTUUpdate + tun.events <- EventMTUUpdate } statusMTU = iface.MTU } @@ -100,7 +100,7 @@ func errorIsEBUSY(err error) bool { return false } -func CreateTUN(name string, mtu int) (TUNDevice, error) { +func CreateTUN(name string, mtu int) (Device, error) { ifIndex := -1 if name != "tun" { _, err := fmt.Sscanf(name, "tun%d", &ifIndex) @@ -139,11 +139,11 @@ func CreateTUN(name string, mtu int) (TUNDevice, error) { return tun, err } -func CreateTUNFromFile(file *os.File, mtu int) (TUNDevice, error) { +func CreateTUNFromFile(file *os.File, mtu int) (Device, error) { tun := &NativeTun{ tunFile: file, - events: make(chan TUNEvent, 10), + events: make(chan Event, 10), errors: make(chan error, 1), } @@ -197,7 +197,7 @@ func (tun *NativeTun) File() *os.File { return tun.tunFile } -func (tun *NativeTun) Events() chan TUNEvent { +func (tun *NativeTun) Events() chan Event { return tun.events } diff --git a/tun/tun_windows.go b/tun/tun_windows.go index 4850bb5..b88129d 100644 --- a/tun/tun_windows.go +++ b/tun/tun_windows.go @@ -46,7 +46,7 @@ type NativeTun struct { close bool rdBuff *exchgBufRead wrBuff *exchgBufWrite - events chan TUNEvent + events chan Event errors chan error forcedMTU int } @@ -59,7 +59,7 @@ func packetAlign(size uint32) uint32 { // CreateTUN creates a Wintun adapter with the given name. Should a Wintun // adapter with the same name exist, it is reused. // -func CreateTUN(ifname string) (TUNDevice, error) { +func CreateTUN(ifname string) (Device, error) { return CreateTUNWithRequestedGUID(ifname, nil) } @@ -67,7 +67,7 @@ func CreateTUN(ifname string) (TUNDevice, error) { // CreateTUNWithRequestedGUID creates a Wintun adapter with the given name and // a requested GUID. Should a Wintun adapter with the same name exist, it is reused. // -func CreateTUNWithRequestedGUID(ifname string, requestedGUID *windows.GUID) (TUNDevice, error) { +func CreateTUNWithRequestedGUID(ifname string, requestedGUID *windows.GUID) (Device, error) { var err error var wt *wintun.Wintun @@ -97,7 +97,7 @@ func CreateTUNWithRequestedGUID(ifname string, requestedGUID *windows.GUID) (TUN wt: wt, rdBuff: &exchgBufRead{}, wrBuff: &exchgBufWrite{}, - events: make(chan TUNEvent, 10), + events: make(chan Event, 10), errors: make(chan error, 1), forcedMTU: 1500, }, nil @@ -202,7 +202,7 @@ func (tun *NativeTun) File() *os.File { return nil } -func (tun *NativeTun) Events() chan TUNEvent { +func (tun *NativeTun) Events() chan Event { return tun.events } -- cgit v1.2.3