From 01c44a087ba8a8fee3ffad561e0c603f2a4c2d1d Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Sat, 24 Sep 2022 14:41:47 +0100 Subject: [PATCH] Rename `tuntap` package to `tun` We haven't had TAP support in ages. --- cmd/yggdrasil/main.go | 20 ++++++++++---------- cmd/yggdrasilctl/main.go | 4 ++-- src/defaults/defaults.go | 2 +- src/defaults/defaults_darwin.go | 2 +- src/defaults/defaults_freebsd.go | 2 +- src/defaults/defaults_linux.go | 2 +- src/defaults/defaults_openbsd.go | 2 +- src/defaults/defaults_other.go | 2 +- src/defaults/defaults_windows.go | 2 +- src/{tuntap => tun}/admin.go | 2 +- src/{tuntap => tun}/iface.go | 2 +- src/{tuntap => tun}/options.go | 2 +- src/{tuntap => tun}/tun.go | 7 +------ src/{tuntap => tun}/tun_bsd.go | 2 +- src/{tuntap => tun}/tun_darwin.go | 2 +- src/{tuntap => tun}/tun_linux.go | 4 ++-- src/{tuntap => tun}/tun_other.go | 2 +- src/{tuntap => tun}/tun_windows.go | 6 +++--- 18 files changed, 31 insertions(+), 36 deletions(-) rename src/{tuntap => tun}/admin.go (98%) rename src/{tuntap => tun}/iface.go (98%) rename src/{tuntap => tun}/options.go (95%) rename src/{tuntap => tun}/tun.go (96%) rename src/{tuntap => tun}/tun_bsd.go (99%) rename src/{tuntap => tun}/tun_darwin.go (99%) rename src/{tuntap => tun}/tun_linux.go (94%) rename src/{tuntap => tun}/tun_other.go (98%) rename src/{tuntap => tun}/tun_windows.go (97%) diff --git a/cmd/yggdrasil/main.go b/cmd/yggdrasil/main.go index 1ef6738..abce0ce 100644 --- a/cmd/yggdrasil/main.go +++ b/cmd/yggdrasil/main.go @@ -32,13 +32,13 @@ import ( "github.com/yggdrasil-network/yggdrasil-go/src/core" "github.com/yggdrasil-network/yggdrasil-go/src/multicast" - "github.com/yggdrasil-network/yggdrasil-go/src/tuntap" + "github.com/yggdrasil-network/yggdrasil-go/src/tun" "github.com/yggdrasil-network/yggdrasil-go/src/version" ) type node struct { core *core.Core - tuntap *tuntap.TunAdapter + tun *tun.TunAdapter multicast *multicast.Multicast admin *admin.AdminSocket } @@ -219,7 +219,7 @@ func run(args yggArgs, ctx context.Context, done chan struct{}) { return case args.autoconf: // Use an autoconf-generated config, this will give us random keys and - // port numbers, and will use an automatically selected TUN/TAP interface. + // port numbers, and will use an automatically selected TUN interface. cfg = defaults.GenerateConfig() case args.useconffile != "" || args.useconf: // Read the configuration from either stdin or from the filesystem @@ -348,15 +348,15 @@ func run(args yggArgs, ctx context.Context, done chan struct{}) { // Setup the TUN module. { - options := []tuntap.SetupOption{ - tuntap.InterfaceName(cfg.IfName), - tuntap.InterfaceMTU(cfg.IfMTU), + options := []tun.SetupOption{ + tun.InterfaceName(cfg.IfName), + tun.InterfaceMTU(cfg.IfMTU), } - if n.tuntap, err = tuntap.New(ipv6rwc.NewReadWriteCloser(n.core), logger, options...); err != nil { + if n.tun, err = tun.New(ipv6rwc.NewReadWriteCloser(n.core), logger, options...); err != nil { panic(err) } - if n.admin != nil && n.tuntap != nil { - n.tuntap.SetupAdminHandlers(n.admin) + if n.admin != nil && n.tun != nil { + n.tun.SetupAdminHandlers(n.admin) } } @@ -378,7 +378,7 @@ func run(args yggArgs, ctx context.Context, done chan struct{}) { func (n *node) shutdown() { _ = n.admin.Stop() _ = n.multicast.Stop() - _ = n.tuntap.Stop() + _ = n.tun.Stop() n.core.Stop() } diff --git a/cmd/yggdrasilctl/main.go b/cmd/yggdrasilctl/main.go index 0ec0ccf..1e93b98 100644 --- a/cmd/yggdrasilctl/main.go +++ b/cmd/yggdrasilctl/main.go @@ -17,7 +17,7 @@ import ( "github.com/yggdrasil-network/yggdrasil-go/src/admin" "github.com/yggdrasil-network/yggdrasil-go/src/core" "github.com/yggdrasil-network/yggdrasil-go/src/multicast" - "github.com/yggdrasil-network/yggdrasil-go/src/tuntap" + "github.com/yggdrasil-network/yggdrasil-go/src/tun" "github.com/yggdrasil-network/yggdrasil-go/src/version" ) @@ -256,7 +256,7 @@ func run() int { table.Render() case "gettun": - var resp tuntap.GetTUNResponse + var resp tun.GetTUNResponse if err := json.Unmarshal(recv.Response, &resp); err != nil { panic(err) } diff --git a/src/defaults/defaults.go b/src/defaults/defaults.go index a7492de..6374f4e 100644 --- a/src/defaults/defaults.go +++ b/src/defaults/defaults.go @@ -20,7 +20,7 @@ type platformDefaultParameters struct { // Multicast interfaces DefaultMulticastInterfaces []MulticastInterfaceConfig - // TUN/TAP + // TUN MaximumIfMTU uint64 DefaultIfMTU uint64 DefaultIfName string diff --git a/src/defaults/defaults_darwin.go b/src/defaults/defaults_darwin.go index a848342..3ffd9ff 100644 --- a/src/defaults/defaults_darwin.go +++ b/src/defaults/defaults_darwin.go @@ -19,7 +19,7 @@ func getDefaults() platformDefaultParameters { {Regex: "bridge.*", Beacon: true, Listen: true}, }, - // TUN/TAP + // TUN MaximumIfMTU: 65535, DefaultIfMTU: 65535, DefaultIfName: "auto", diff --git a/src/defaults/defaults_freebsd.go b/src/defaults/defaults_freebsd.go index c8f918b..4335938 100644 --- a/src/defaults/defaults_freebsd.go +++ b/src/defaults/defaults_freebsd.go @@ -18,7 +18,7 @@ func getDefaults() platformDefaultParameters { {Regex: ".*", Beacon: true, Listen: true}, }, - // TUN/TAP + // TUN MaximumIfMTU: 32767, DefaultIfMTU: 32767, DefaultIfName: "/dev/tun0", diff --git a/src/defaults/defaults_linux.go b/src/defaults/defaults_linux.go index ea646db..bad6233 100644 --- a/src/defaults/defaults_linux.go +++ b/src/defaults/defaults_linux.go @@ -18,7 +18,7 @@ func getDefaults() platformDefaultParameters { {Regex: ".*", Beacon: true, Listen: true}, }, - // TUN/TAP + // TUN MaximumIfMTU: 65535, DefaultIfMTU: 65535, DefaultIfName: "auto", diff --git a/src/defaults/defaults_openbsd.go b/src/defaults/defaults_openbsd.go index 6e9d174..e5d1fa9 100644 --- a/src/defaults/defaults_openbsd.go +++ b/src/defaults/defaults_openbsd.go @@ -18,7 +18,7 @@ func getDefaults() platformDefaultParameters { {Regex: ".*", Beacon: true, Listen: true}, }, - // TUN/TAP + // TUN MaximumIfMTU: 16384, DefaultIfMTU: 16384, DefaultIfName: "tun0", diff --git a/src/defaults/defaults_other.go b/src/defaults/defaults_other.go index f42b087..bb22864 100644 --- a/src/defaults/defaults_other.go +++ b/src/defaults/defaults_other.go @@ -18,7 +18,7 @@ func getDefaults() platformDefaultParameters { {Regex: ".*", Beacon: true, Listen: true}, }, - // TUN/TAP + // TUN MaximumIfMTU: 65535, DefaultIfMTU: 65535, DefaultIfName: "none", diff --git a/src/defaults/defaults_windows.go b/src/defaults/defaults_windows.go index 90f3b9e..e2601bf 100644 --- a/src/defaults/defaults_windows.go +++ b/src/defaults/defaults_windows.go @@ -18,7 +18,7 @@ func getDefaults() platformDefaultParameters { {Regex: ".*", Beacon: true, Listen: true}, }, - // TUN/TAP + // TUN MaximumIfMTU: 65535, DefaultIfMTU: 65535, DefaultIfName: "Yggdrasil", diff --git a/src/tuntap/admin.go b/src/tun/admin.go similarity index 98% rename from src/tuntap/admin.go rename to src/tun/admin.go index 24521fe..90f712e 100644 --- a/src/tuntap/admin.go +++ b/src/tun/admin.go @@ -1,4 +1,4 @@ -package tuntap +package tun import ( "encoding/json" diff --git a/src/tuntap/iface.go b/src/tun/iface.go similarity index 98% rename from src/tuntap/iface.go rename to src/tun/iface.go index f629399..c98b56d 100644 --- a/src/tuntap/iface.go +++ b/src/tun/iface.go @@ -1,4 +1,4 @@ -package tuntap +package tun const TUN_OFFSET_BYTES = 4 diff --git a/src/tuntap/options.go b/src/tun/options.go similarity index 95% rename from src/tuntap/options.go rename to src/tun/options.go index 10af8d9..7be7921 100644 --- a/src/tuntap/options.go +++ b/src/tun/options.go @@ -1,4 +1,4 @@ -package tuntap +package tun func (m *TunAdapter) _applyOption(opt SetupOption) { switch v := opt.(type) { diff --git a/src/tuntap/tun.go b/src/tun/tun.go similarity index 96% rename from src/tuntap/tun.go rename to src/tun/tun.go index b0c444f..0f7a70e 100644 --- a/src/tuntap/tun.go +++ b/src/tun/tun.go @@ -1,10 +1,7 @@ -package tuntap +package tun // This manages the tun driver to send/recv packets to/from applications -// TODO: Crypto-key routing support -// TODO: Set MTU of session properly -// TODO: Reject packets that exceed session MTU with ICMPv6 for PMTU Discovery // TODO: Connection timeouts (call Conn.Close() when we want to time out) // TODO: Don't block in reader on writes that are pending searches @@ -13,8 +10,6 @@ import ( "fmt" "net" - //"sync" - "github.com/Arceliar/phony" "golang.zx2c4.com/wireguard/tun" diff --git a/src/tuntap/tun_bsd.go b/src/tun/tun_bsd.go similarity index 99% rename from src/tuntap/tun_bsd.go rename to src/tun/tun_bsd.go index fe36266..9a8f70c 100644 --- a/src/tuntap/tun_bsd.go +++ b/src/tun/tun_bsd.go @@ -1,7 +1,7 @@ //go:build openbsd || freebsd // +build openbsd freebsd -package tuntap +package tun import ( "encoding/binary" diff --git a/src/tuntap/tun_darwin.go b/src/tun/tun_darwin.go similarity index 99% rename from src/tuntap/tun_darwin.go rename to src/tun/tun_darwin.go index 6f6e252..a6d87a0 100644 --- a/src/tuntap/tun_darwin.go +++ b/src/tun/tun_darwin.go @@ -1,7 +1,7 @@ //go:build !mobile // +build !mobile -package tuntap +package tun // The darwin platform specific tun parts diff --git a/src/tuntap/tun_linux.go b/src/tun/tun_linux.go similarity index 94% rename from src/tuntap/tun_linux.go rename to src/tun/tun_linux.go index f849c00..1e42b7b 100644 --- a/src/tuntap/tun_linux.go +++ b/src/tun/tun_linux.go @@ -1,7 +1,7 @@ //go:build !mobile // +build !mobile -package tuntap +package tun // The linux platform specific tun parts @@ -28,7 +28,7 @@ func (tun *TunAdapter) setup(ifname string, addr string, mtu uint64) error { return tun.setupAddress(addr) } -// Configures the TAP adapter with the correct IPv6 address and MTU. Netlink +// Configures the TUN adapter with the correct IPv6 address and MTU. Netlink // is used to do this, so there is not a hard requirement on "ip" or "ifconfig" // to exist on the system, but this will fail if Netlink is not present in the // kernel (it nearly always is). diff --git a/src/tuntap/tun_other.go b/src/tun/tun_other.go similarity index 98% rename from src/tuntap/tun_other.go rename to src/tun/tun_other.go index 8ce2495..c618d83 100644 --- a/src/tuntap/tun_other.go +++ b/src/tun/tun_other.go @@ -1,7 +1,7 @@ //go:build !linux && !darwin && !windows && !openbsd && !freebsd && !mobile // +build !linux,!darwin,!windows,!openbsd,!freebsd,!mobile -package tuntap +package tun // This is to catch unsupported platforms // If your platform supports tun devices, you could try configuring it manually diff --git a/src/tuntap/tun_windows.go b/src/tun/tun_windows.go similarity index 97% rename from src/tuntap/tun_windows.go rename to src/tun/tun_windows.go index 8dce727..c3e3659 100644 --- a/src/tuntap/tun_windows.go +++ b/src/tun/tun_windows.go @@ -1,7 +1,7 @@ //go:build windows // +build windows -package tuntap +package tun import ( "bytes" @@ -50,7 +50,7 @@ func (tun *TunAdapter) setup(ifname string, addr string, mtu uint64) error { }) } -// Sets the MTU of the TAP adapter. +// Sets the MTU of the TUN adapter. func (tun *TunAdapter) setupMTU(mtu uint64) error { if tun.iface == nil || tun.Name() == "" { return errors.New("Can't configure MTU as TUN adapter is not present") @@ -77,7 +77,7 @@ func (tun *TunAdapter) setupMTU(mtu uint64) error { return nil } -// Sets the IPv6 address of the TAP adapter. +// Sets the IPv6 address of the TUN adapter. func (tun *TunAdapter) setupAddress(addr string) error { if tun.iface == nil || tun.Name() == "" { return errors.New("Can't configure IPv6 address as TUN adapter is not present")