2 GoVPN -- simple secure free software virtual private network daemon
3 Copyright (C) 2014-2016 Sergey Matveev <stargrave@stargrave.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
26 "github.com/Sirupsen/logrus"
29 func TapListenFileDescriptor(fd uintptr, ifaceName string, mtu int) *TAP {
30 tap, exists := taps[ifaceName]
37 dev: os.NewFile(fd, ifaceName),
38 Sink: make(chan []byte),
44 buf0 := make([]byte, mtu)
45 buf1 := make([]byte, mtu)
54 n, err = tap.dev.Read(buf)
56 e, ok := err.(*os.PathError)
57 if ok && e.Err == syscall.EAGAIN {
58 time.Sleep(time.Millisecond * 20)
62 logger.WithError(err).WithFields(logrus.Fields{
63 "func", logFuncPrefix + "TUN read sink loop",
66 }).Error("Can't read interface, stop")
68 // TODO: need a way to warn consumer that something is wrong
69 // TODO: to force peer to just disconnect
70 // TODO: use the client/server error channel?