README | 2 +- govpn.go | 14 ++++++++------ tap_freebsd.go | 19 +++++++++++++++++++ tap_linux.go | 18 ++++++++++++++++++ diff --git a/README b/README index 34d8be8314e4247805b5579f49cf66290e2827b1..f4361278041d337cc0de064755e34ac8f32fb9ce 100644 --- a/README +++ b/README @@ -4,7 +4,7 @@ SYNOPSIS govpn is simple high-performance secure virtual private network daemon. It uses DH-EKE for mutual zero-knowledge authentication and -authenticated encrypted transport. +authenticated encrypted transport. It runs under GNU/Linux and FreeBSD. DESCRIPTION diff --git a/govpn.go b/govpn.go index fcd1a00b898591fe2ccc034685ce2d82ca164a02..a06456d452138cc1676d7a4bfef3e8d86d1fe93d 100644 --- a/govpn.go +++ b/govpn.go @@ -22,13 +22,13 @@ "encoding/binary" "encoding/hex" "flag" "fmt" + "io" "log" "net" "time" "code.google.com/p/go.crypto/poly1305" "code.google.com/p/go.crypto/salsa20" - "github.com/chon219/water" ) var ( @@ -47,6 +47,11 @@ KeySize = 32 // S20BS is Salsa20's internal blocksize in bytes S20BS = 64 ) + +type TAP interface { + io.Reader + io.Writer +} type Peer struct { addr *net.UDPAddr @@ -78,10 +83,7 @@ // Interface listening maxIfacePktSize := *mtu - poly1305.TagSize - NonceSize log.Println("Max MTU", maxIfacePktSize, "on interface", *ifaceName) - iface, err := water.NewTAP(*ifaceName) - if err != nil { - panic(err) - } + iface := NewTAP(*ifaceName) ethBuf := make([]byte, maxIfacePktSize) ethSink := make(chan int) ethSinkReady := make(chan bool) @@ -236,7 +238,7 @@ } peer.nonceRecv = nonceRecv timeouts = 0 if _, err := iface.Write(buf[S20BS : S20BS+udpPkt.size-NonceSize-poly1305.TagSize]); err != nil { - log.Println("Error writing to iface") + log.Println("Error writing to iface: ", err) } if *verbose { fmt.Print("r") diff --git a/tap_freebsd.go b/tap_freebsd.go new file mode 100644 index 0000000000000000000000000000000000000000..d4b45e6fe111c7a4de39396025a9665af506d898 --- /dev/null +++ b/tap_freebsd.go @@ -0,0 +1,19 @@ +// +build freebsd +/* +govpn -- high-performance secure virtual private network daemon +Copyright (C) 2014 Sergey Matveev +*/ +package main + +import ( + "os" + "path" +) + +func NewTAP(ifaceName string) TAP { + fd, err := os.OpenFile(path.Join("/dev/", ifaceName), os.O_RDWR, os.ModePerm) + if err != nil { + panic(err) + } + return fd +} diff --git a/tap_linux.go b/tap_linux.go new file mode 100644 index 0000000000000000000000000000000000000000..90ece189583d020c9441dd1256de6b47e9a6d3d2 --- /dev/null +++ b/tap_linux.go @@ -0,0 +1,18 @@ +// +build linux +/* +govpn -- high-performance secure virtual private network daemon +Copyright (C) 2014 Sergey Matveev +*/ +package main + +import ( + "github.com/chon219/water" +) + +func NewTAP(string ifaceName) TAP { + iface, err := water.NewTAP(ifaceName) + if err != nil { + panic(err) + } + return iface +}