diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-05-14 12:27:29 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-05-14 12:27:29 +0200 |
commit | 355e9bd619c8ec8bdd0f2934739a87a15ceb6920 (patch) | |
tree | 36dfb2a5d34e63873281f1d6ed23ca6eaf34a425 /tun_linux.go | |
parent | 8b30278ce666a74b46f607b47bf3fbe87744c016 (diff) |
Clean more
Diffstat (limited to 'tun_linux.go')
-rw-r--r-- | tun_linux.go | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/tun_linux.go b/tun_linux.go index 18fb72c..8e42d44 100644 --- a/tun_linux.go +++ b/tun_linux.go @@ -395,7 +395,7 @@ func CreateTUN(name string) (TUNDevice, error) { } func CreateTUNFromFile(fd *os.File) (TUNDevice, error) { - device := &NativeTun{ + tun := &NativeTun{ fd: fd, events: make(chan TUNEvent, 5), errors: make(chan error, 5), @@ -404,37 +404,38 @@ func CreateTUNFromFile(fd *os.File) (TUNDevice, error) { } var err error - device.rwcancel, err = rwcancel.NewRWCancel(int(fd.Fd())) + tun.rwcancel, err = rwcancel.NewRWCancel(int(fd.Fd())) if err != nil { return nil, err } - _, err = device.Name() + _, err = tun.Name() if err != nil { return nil, err } // start event listener - device.index, err = getIFIndex(device.name) + tun.index, err = getIFIndex(tun.name) if err != nil { return nil, err } - // set default MTU - - err = device.setMTU(DefaultMTU) + tun.netlinkSock, err = createNetlinkSocket() if err != nil { return nil, err } - device.netlinkSock, err = createNetlinkSocket() + go tun.RoutineNetlinkListener() + go tun.RoutineHackListener() // cross namespace + + // set default MTU + + err = tun.setMTU(DefaultMTU) if err != nil { + tun.Close() return nil, err } - go device.RoutineNetlinkListener() - go device.RoutineHackListener() // cross namespace - - return device, nil + return tun, nil } |