mirror of
https://github.com/yggdrasil-network/water.git
synced 2025-05-19 16:35:10 +03:00
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:
parent
80f6655041
commit
70591d2499
9 changed files with 38 additions and 48 deletions
12
if.go
12
if.go
|
@ -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
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue