summaryrefslogtreecommitdiff
path: root/tuntap
diff options
context:
space:
mode:
authorChristian Pointner <equinox@anytun.org>2017-08-14 23:33:31 +0200
committerChristian Pointner <equinox@anytun.org>2017-08-14 23:33:31 +0200
commit387a7c762edf84ea7862947034f036db1bc0c3e1 (patch)
tree2bd9845e8b558d44bd17dcfea57c4e998594e224 /tuntap
parentbasic interface configuration works now (diff)
implemented post up script
Diffstat (limited to 'tuntap')
-rw-r--r--tuntap/tuntap.go21
1 files changed, 18 insertions, 3 deletions
diff --git a/tuntap/tuntap.go b/tuntap/tuntap.go
index 6c27171..db1492f 100644
--- a/tuntap/tuntap.go
+++ b/tuntap/tuntap.go
@@ -31,14 +31,25 @@
package tuntap
import (
+ "context"
"fmt"
"net"
+ "os/exec"
"strings"
+ "time"
extlib "github.com/lab11/go-tuntap/tuntap"
"github.com/vishvananda/netlink"
)
+const (
+ EtherTypeIPv4 = 0x0800
+ EtherTypeIPv6 = 0x86DD
+ EtherTypeTransparentEthernetBridge = 0x6558
+
+ PostUpScriptTimeout = 10 * time.Second
+)
+
type Device struct {
iface *extlib.Interface
iftype extlib.DevKind
@@ -68,15 +79,19 @@ func (dev *Device) Configure(addr net.IPNet) error {
}
func (dev *Device) RunPostUp(script string) error {
- // TODO: implement this
- fmt.Printf("running: %s %s\n", script, dev.iface.Name())
+ ctx, cancel := context.WithTimeout(context.Background(), PostUpScriptTimeout)
+ defer cancel()
+
+ if err := exec.CommandContext(ctx, script, dev.ifname).Run(); err != nil {
+ return err
+ }
return nil
}
func (dev *Device) ReadPacket() (pkt *extlib.Packet, err error) {
pkt, err = dev.iface.ReadPacket()
if dev.iftype == extlib.DevTap {
- pkt.Protocol = 0x6558 // TODO: hardcoded value
+ pkt.Protocol = EtherTypeTransparentEthernetBridge
}
return
}