From 0f7a7c336ff5f304b73def40ca180977a9479d0f Mon Sep 17 00:00:00 2001 From: Alec Scott Date: Thu, 3 Feb 2022 09:17:23 -0700 Subject: [PATCH] Add documentation to TUN library --- cli/down.go | 2 +- cli/up.go | 3 +++ tun/options.go | 7 +++++++ tun/tun.go | 4 ++++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/cli/down.go b/cli/down.go index 3fc34fc..4965c19 100644 --- a/cli/down.go +++ b/cli/down.go @@ -52,7 +52,7 @@ func DownRun(r *cmd.Root, c *cmd.Sub) { // Different types of systems may need the tun devices destroyed first or // the process to exit first don't worry as long as one of these two has - // suceeded. + // succeeded. if err0 != nil && err1 != nil { checkErr(err0) checkErr(err1) diff --git a/cli/up.go b/cli/up.go index c21a0e2..535035d 100644 --- a/cli/up.go +++ b/cli/up.go @@ -301,6 +301,9 @@ func createDaemon(cfg *config.Config) error { fmt.Println(line.Text) if strings.HasPrefix(line.Text, "[+] Connection to") { numConnected++ + if numConnected >= len(cfg.Peers) { + break + } } } out <- numConnected diff --git a/tun/options.go b/tun/options.go index 39011ec..046055e 100644 --- a/tun/options.go +++ b/tun/options.go @@ -1,19 +1,26 @@ package tun +// Option defines a TUN device modifier option. type Option func(tun *TUN) error +// Address sets the local address and subnet for an interface. +// On MacOS devices use this function to set the Src Address +// for an interface and use DestAddress to set the destination ip. func Address(address string) Option { return func(tun *TUN) error { return tun.setAddress(address) } } +// MTU sets the Maximum Transmission Unit size for an interface. func MTU(mtu int) Option { return func(tun *TUN) error { return tun.setMTU(mtu) } } +// DestAddress sets the destination address for a point-to-point interface. +// Only use this option on MacOS devices. func DestAddress(address string) Option { return func(tun *TUN) error { return tun.setDestAddress(address) diff --git a/tun/tun.go b/tun/tun.go index efe8271..38b68ba 100644 --- a/tun/tun.go +++ b/tun/tun.go @@ -2,6 +2,9 @@ package tun import "github.com/songgao/water" +// TUN is a struct containing the fields necessary +// to configure a system TUN device. Access the +// internal TUN device through TUN.Iface type TUN struct { Iface *water.Interface MTU int @@ -9,6 +12,7 @@ type TUN struct { Dst string } +// Apply configures the specified options for a TUN device. func (t *TUN) Apply(opts ...Option) error { for _, opt := range opts { if opt == nil {