github.com/keysonzzz/kmg@v0.0.0-20151121023212-05317bfd7d39/kmgSys/taptun.go (about)

     1  package kmgSys
     2  
     3  import (
     4  	"errors"
     5  	"io"
     6  )
     7  
     8  type DeviceType string
     9  
    10  func (s DeviceType) String() string {
    11  	return string(s)
    12  }
    13  
    14  var DeviceTypeTap DeviceType = "tap"
    15  var DeviceTypeTun DeviceType = "tun"
    16  
    17  var ErrAllDeviceBusy = errors.New("tun/tap: all dev is busy.")
    18  
    19  // Interface is a TUN/TAP interface.
    20  type TunTapInterface interface {
    21  	io.ReadWriteCloser
    22  	GetDeviceType() DeviceType
    23  	Name() string
    24  }
    25  
    26  /*
    27  //set tun p2p ip and up this device
    28  // mtu default to 1500
    29  func SetP2PIpAndUp(ifac Interface, srcIp string, destIp string, mtu int) error {
    30  	if mtu == 0 {
    31  		mtu = 1500
    32  	}
    33  	switch runtime.GOOS {
    34  	case "darwin":
    35  		return kmgCmd.StdioSliceRun([]string{"ifconfig", ifac.Name(), srcIp, destIp, "mtu", strconv.Itoa(mtu), "up"})
    36  	case "linux":
    37  		return kmgCmd.StdioSliceRun([]string{"ifconfig", ifac.Name(), srcIp, "pointopoint", destIp, "mtu", strconv.Itoa(mtu), "up"})
    38  	default:
    39  		return ErrPlatformNotSupport
    40  	}
    41  }
    42  
    43  //set mtu on a device
    44  func SetMtu(ifac Interface, mtu int) error {
    45  	return kmgCmd.StdioSliceRun([]string{"ifconfig", ifac.Name(), "mtu", strconv.Itoa(mtu)})
    46  }
    47  */