From 355e9bd619c8ec8bdd0f2934739a87a15ceb6920 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Mon, 14 May 2018 12:27:29 +0200 Subject: Clean more --- tun_linux.go | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'tun_linux.go') 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 } -- cgit v1.2.3