2 GoVPN -- simple secure free software virtual private network daemon
3 Copyright (C) 2014-2017 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/>.
25 "github.com/pkg/errors"
26 "github.com/songgao/water"
29 func newTAPer(ifaceName *string) (io.ReadWriteCloser, error) {
30 config := water.Config{}
32 if len(*ifaceName) == 0 {
33 return nil, errors.New("Can't figure interface type, empty name")
36 if strings.HasPrefix(*ifaceName, interfaceTap) {
37 config.DeviceType = water.TAP
38 if len(*ifaceName) > len(interfaceTap) {
39 config.Name = *ifaceName
41 } else if strings.HasPrefix(*ifaceName, interfaceTun) {
42 config.DeviceType = water.TUN
43 if len(*ifaceName) > len(interfaceTun) {
44 config.Name = *ifaceName
47 return nil, errors.Errorf("Unrecognized interface name %q", *ifaceName)
50 output, err := water.New(config)
52 return nil, errors.Wrap(err, "water.New")
54 *ifaceName = output.Name()