Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Commit

Permalink
Add documentation to TUN library
Browse files Browse the repository at this point in the history
  • Loading branch information
alecbcs committed Feb 3, 2022
1 parent 43d0df3 commit 0f7a7c3
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cli/down.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions cli/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions tun/options.go
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
4 changes: 4 additions & 0 deletions tun/tun.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ 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
Src string
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 {
Expand Down

0 comments on commit 0f7a7c3

Please sign in to comment.