tun: allow special methods in NativeTun
This commit is contained in:
parent
88ff67fb6f
commit
967d1a0f3d
6 changed files with 65 additions and 65 deletions
|
|
@ -31,7 +31,7 @@ type sockaddrCtl struct {
|
|||
scReserved [5]uint32
|
||||
}
|
||||
|
||||
type nativeTun struct {
|
||||
type NativeTun struct {
|
||||
name string
|
||||
tunFile *os.File
|
||||
events chan TUNEvent
|
||||
|
|
@ -41,7 +41,7 @@ type nativeTun struct {
|
|||
|
||||
var sockaddrCtlSize uintptr = 32
|
||||
|
||||
func (tun *nativeTun) routineRouteListener(tunIfindex int) {
|
||||
func (tun *NativeTun) routineRouteListener(tunIfindex int) {
|
||||
var (
|
||||
statusUp bool
|
||||
statusMTU int
|
||||
|
|
@ -160,7 +160,7 @@ func CreateTUN(name string, mtu int) (TUNDevice, error) {
|
|||
if err == nil && name == "utun" {
|
||||
fname := os.Getenv("WG_TUN_NAME_FILE")
|
||||
if fname != "" {
|
||||
ioutil.WriteFile(fname, []byte(tun.(*nativeTun).name+"\n"), 0400)
|
||||
ioutil.WriteFile(fname, []byte(tun.(*NativeTun).name+"\n"), 0400)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -168,7 +168,7 @@ func CreateTUN(name string, mtu int) (TUNDevice, error) {
|
|||
}
|
||||
|
||||
func CreateTUNFromFile(file *os.File, mtu int) (TUNDevice, error) {
|
||||
tun := &nativeTun{
|
||||
tun := &NativeTun{
|
||||
tunFile: file,
|
||||
events: make(chan TUNEvent, 10),
|
||||
errors: make(chan error, 1),
|
||||
|
|
@ -209,7 +209,7 @@ func CreateTUNFromFile(file *os.File, mtu int) (TUNDevice, error) {
|
|||
return tun, nil
|
||||
}
|
||||
|
||||
func (tun *nativeTun) Name() (string, error) {
|
||||
func (tun *NativeTun) Name() (string, error) {
|
||||
var ifName struct {
|
||||
name [16]byte
|
||||
}
|
||||
|
|
@ -234,15 +234,15 @@ func (tun *nativeTun) Name() (string, error) {
|
|||
return tun.name, nil
|
||||
}
|
||||
|
||||
func (tun *nativeTun) File() *os.File {
|
||||
func (tun *NativeTun) File() *os.File {
|
||||
return tun.tunFile
|
||||
}
|
||||
|
||||
func (tun *nativeTun) Events() chan TUNEvent {
|
||||
func (tun *NativeTun) Events() chan TUNEvent {
|
||||
return tun.events
|
||||
}
|
||||
|
||||
func (tun *nativeTun) Read(buff []byte, offset int) (int, error) {
|
||||
func (tun *NativeTun) Read(buff []byte, offset int) (int, error) {
|
||||
select {
|
||||
case err := <-tun.errors:
|
||||
return 0, err
|
||||
|
|
@ -256,7 +256,7 @@ func (tun *nativeTun) Read(buff []byte, offset int) (int, error) {
|
|||
}
|
||||
}
|
||||
|
||||
func (tun *nativeTun) Write(buff []byte, offset int) (int, error) {
|
||||
func (tun *NativeTun) Write(buff []byte, offset int) (int, error) {
|
||||
|
||||
// reserve space for header
|
||||
|
||||
|
|
@ -279,7 +279,7 @@ func (tun *nativeTun) Write(buff []byte, offset int) (int, error) {
|
|||
return tun.tunFile.Write(buff)
|
||||
}
|
||||
|
||||
func (tun *nativeTun) Close() error {
|
||||
func (tun *NativeTun) Close() error {
|
||||
var err2 error
|
||||
err1 := tun.tunFile.Close()
|
||||
if tun.routeSocket != -1 {
|
||||
|
|
@ -295,7 +295,7 @@ func (tun *nativeTun) Close() error {
|
|||
return err2
|
||||
}
|
||||
|
||||
func (tun *nativeTun) setMTU(n int) error {
|
||||
func (tun *NativeTun) setMTU(n int) error {
|
||||
|
||||
// open datagram socket
|
||||
|
||||
|
|
@ -332,7 +332,7 @@ func (tun *nativeTun) setMTU(n int) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (tun *nativeTun) MTU() (int, error) {
|
||||
func (tun *NativeTun) MTU() (int, error) {
|
||||
|
||||
// open datagram socket
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue