2 GoVPN -- simple secure free software virtual private network daemon
3 Copyright (C) 2014-2017 Sergey Matveev <stargrave@stargrave.org>
4 2016-2017 Bruno Clermont <bruno@robotinfra.com>
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
26 "github.com/pkg/errors"
27 "github.com/songgao/water"
30 func newTAPer(ifaceName *string) (io.ReadWriteCloser, error) {
31 config := water.Config{}
33 if len(*ifaceName) == 0 {
34 return nil, errors.New("Can't figure interface type, empty name")
37 if strings.HasPrefix(*ifaceName, interfaceTap) {
38 config.DeviceType = water.TAP
39 if len(*ifaceName) > len(interfaceTap) {
40 config.Name = *ifaceName
42 } else if strings.HasPrefix(*ifaceName, interfaceTun) {
43 config.DeviceType = water.TUN
44 if len(*ifaceName) > len(interfaceTun) {
45 config.Name = *ifaceName
48 return nil, errors.Errorf("Unrecognized interface name %q", *ifaceName)
51 output, err := water.New(config)
53 return nil, errors.Wrap(err, "water.New")
55 *ifaceName = output.Name()