-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handling closing of conns on dispatch loop and tracking deleted conns…
… on stats
- Loading branch information
Showing
7 changed files
with
152 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package gonat | ||
|
||
import ( | ||
"io" | ||
"os/exec" | ||
"strconv" | ||
|
||
"github.com/getlantern/errors" | ||
"github.com/songgao/water" | ||
) | ||
|
||
// TUNDevice creates a TUN device with the given name and configures an interface for that TUN | ||
// device at the given address and netmask and given mtu (should usually be 1500). | ||
func TUNDevice(name, addr, netmask string, mtu int) (io.ReadWriteCloser, error) { | ||
cfg := water.Config{DeviceType: water.TUN} | ||
cfg.Name = name | ||
dev, err := water.New(cfg) | ||
if err != nil { | ||
return nil, errors.New("error opening TUN device: %v", err) | ||
} | ||
log.Debugf("Created TUN device named %v", dev.Name()) | ||
|
||
if out, configErr := exec.Command("ifconfig", dev.Name(), addr, "netmask", netmask, "mtu", strconv.Itoa(mtu)).CombinedOutput(); configErr != nil { | ||
dev.Close() | ||
return nil, errors.New("failed to configure tun device address: %v", string(out)) | ||
} | ||
|
||
return dev, nil | ||
} |