]> Cypherpunks.ru repositories - govpn.git/commitdiff
FreeBSD TAP support 1.1
authorSergey Matveev <stargrave@stargrave.org>
Sat, 6 Dec 2014 12:18:40 +0000 (15:18 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sat, 6 Dec 2014 12:18:40 +0000 (15:18 +0300)
Signed-off-by: Sergey Matveev <stargrave@stargrave.org>
README
govpn.go
tap_freebsd.go [new file with mode: 0644]
tap_linux.go [new file with mode: 0644]

diff --git a/README b/README
index 34d8be8314e4247805b5579f49cf66290e2827b1..f4361278041d337cc0de064755e34ac8f32fb9ce 100644 (file)
--- 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
 
index fcd1a00b898591fe2ccc034685ce2d82ca164a02..a06456d452138cc1676d7a4bfef3e8d86d1fe93d 100644 (file)
--- a/govpn.go
+++ b/govpn.go
@@ -22,13 +22,13 @@ import (
        "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 (
@@ -48,6 +48,11 @@ const (
        S20BS = 64
 )
 
+type TAP interface {
+       io.Reader
+       io.Writer
+}
+
 type Peer struct {
        addr      *net.UDPAddr
        key       *[KeySize]byte // encryption key
@@ -78,10 +83,7 @@ func main() {
        // 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 @@ func main() {
                        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 (file)
index 0000000..d4b45e6
--- /dev/null
@@ -0,0 +1,19 @@
+// +build freebsd
+/*
+govpn -- high-performance secure virtual private network daemon
+Copyright (C) 2014 Sergey Matveev <stargrave@stargrave.org>
+*/
+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 (file)
index 0000000..90ece18
--- /dev/null
@@ -0,0 +1,18 @@
+// +build linux
+/*
+govpn -- high-performance secure virtual private network daemon
+Copyright (C) 2014 Sergey Matveev <stargrave@stargrave.org>
+*/
+package main
+
+import (
+       "github.com/chon219/water"
+)
+
+func NewTAP(string ifaceName) TAP {
+       iface, err := water.NewTAP(ifaceName)
+       if err != nil {
+               panic(err)
+       }
+       return iface
+}