Simplifies Platform Specific Interface Creation

The interface `Config` object is now passed directly into each creation
function in order to more easily use additional options.

In addition, the linux and darwin parameters were split to better
capture different options for each platform.
This commit is contained in:
Matthew Ellison 2017-05-22 12:25:48 -04:00
parent 80f6655041
commit 70591d2499
No known key found for this signature in database
GPG key ID: A815A44BDC8DD409
9 changed files with 38 additions and 48 deletions

12
if.go
View file

@ -2,6 +2,7 @@ package water
import (
"io"
"errors"
)
// Interface is a TUN/TAP interface.
@ -48,7 +49,14 @@ func New(config Config) (ifce *Interface, err error) {
if zeroConfig == config {
config = defaultConfig()
}
return newDev(config)
switch config.DeviceType {
case TUN:
return newTUN(config)
case TAP:
return newTAP(config)
default:
return nil, errors.New("unknown device type")
}
}
// IsTUN returns true if ifce is a TUN interface.
@ -65,3 +73,5 @@ func (ifce *Interface) IsTAP() bool {
func (ifce *Interface) Name() string {
return ifce.name
}