summaryrefslogtreecommitdiffhomepage
path: root/src/tun_linux.go
diff options
context:
space:
mode:
authorMathias Hall-Andersen <mathias@hall-andersen.dk>2017-11-14 18:26:28 +0100
committerMathias Hall-Andersen <mathias@hall-andersen.dk>2017-11-14 18:26:28 +0100
commit88801529fd4097993f7c448b1c3eee0abc8cb51c (patch)
treed1750dc52489b7d5c665918ae522aae5b8fc4f6b /src/tun_linux.go
parent69fe86edf0ba371b9b0a54e522ec20d33e0ae129 (diff)
Moved TUN device creation to pre-fork
Diffstat (limited to 'src/tun_linux.go')
-rw-r--r--src/tun_linux.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/tun_linux.go b/src/tun_linux.go
index accc6c6..ce6304c 100644
--- a/src/tun_linux.go
+++ b/src/tun_linux.go
@@ -56,6 +56,11 @@ type NativeTun struct {
events chan TUNEvent // device related events
}
+func (tun *NativeTun) File() *os.File {
+ println(tun.fd.Name())
+ return tun.fd
+}
+
func (tun *NativeTun) RoutineNetlinkListener() {
sock := int(C.bind_rtmgrp())
if sock < 0 {
@@ -248,6 +253,29 @@ func (tun *NativeTun) Close() error {
return nil
}
+func CreateTUNFromFile(name string, fd *os.File) (TUNDevice, error) {
+ device := &NativeTun{
+ fd: fd,
+ name: name,
+ events: make(chan TUNEvent, 5),
+ errors: make(chan error, 5),
+ }
+
+ // start event listener
+
+ var err error
+ device.index, err = getIFIndex(device.name)
+ if err != nil {
+ return nil, err
+ }
+
+ go device.RoutineNetlinkListener()
+
+ // set default MTU
+
+ return device, device.setMTU(DefaultMTU)
+}
+
func CreateTUN(name string) (TUNDevice, error) {
// open clone device