diff options
author | Christian Pointner <equinox@anytun.org> | 2017-08-14 23:33:31 +0200 |
---|---|---|
committer | Christian Pointner <equinox@anytun.org> | 2017-08-14 23:33:31 +0200 |
commit | 387a7c762edf84ea7862947034f036db1bc0c3e1 (patch) | |
tree | 2bd9845e8b558d44bd17dcfea57c4e998594e224 | |
parent | basic interface configuration works now (diff) |
implemented post up script
-rw-r--r-- | app/anygone.go | 2 | ||||
-rw-r--r-- | tuntap/tuntap.go | 21 |
2 files changed, 20 insertions, 3 deletions
diff --git a/app/anygone.go b/app/anygone.go index 239f4e8..7979a4d 100644 --- a/app/anygone.go +++ b/app/anygone.go @@ -82,10 +82,12 @@ func main() { } } if cfg.PostUp != "" { + al.Printf("running post-up script: %s", cfg.PostUp) if err = dev.RunPostUp(cfg.PostUp); err != nil { al.Printf("Error while running post-up script: %v", err) os.Exit(1) } + al.Printf("post-up script: success") } for { 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 } |