trifid/nebula-ffi/main.go

106 lines
2.6 KiB
Go

package main
import "C"
import (
"os"
"fmt"
"github.com/sirupsen/logrus"
"github.com/slackhq/nebula"
"github.com/slackhq/nebula/config"
)
// A version string that can be set with
//
// -ldflags "-X main.Build=SOMEVERSION"
//
// at compile-time.
var Build string
var neb_config *config.C
var control *nebula.Control
//export NebulaSetup
func NebulaSetup(configPathCStr *C.char, configTest bool) (reterr *C.char) {
configPath := C.GoString(configPathCStr)
if configPath == "" {
fmt.Println("a config path must be provided")
return C.CString("a config path must be provided")
}
fmt.Println(configPath)
fmt.Println("Loading configuration from", configPath)
l := logrus.New()
l.Out = os.Stdout
neb_config = config.NewC(l)
err := neb_config.Load(configPath)
if err != nil {
fmt.Println(err.Error())
return C.CString(err.Error())
}
ctrl, err := nebula.Main(neb_config, configTest, Build, l, nil)
control = ctrl
if err != nil {
fmt.Println(err.Error())
return C.CString(err.Error())
}
fmt.Println("NO_FAILURE")
return C.CString("NO_FAILURE")
}
//export NebulaReloadConfig
func NebulaReloadConfig() (reterr *C.char) {
if neb_config == nil {
fmt.Println("NebulaSetup has not yet been called")
return C.CString("NebulaSetup has not yet been called")
}
neb_config.ReloadConfig()
return C.CString("NO_FAILURE")
}
//export NebulaStart
func NebulaStart() (reterr *C.char) {
if control == nil {
fmt.Println("NebulaSetup has not yet been called")
return C.CString("NebulaSetup has not yet been called")
}
control.Start()
return C.CString("NO_FAILURE")
}
//export NebulaStop
func NebulaStop() (reterr *C.char) {
if control == nil {
fmt.Println("NebulaSetup has not yet been called")
return C.CString("NebulaSetup has not yet been called")
}
control.Stop()
return C.CString("NO_FAILURE")
}
//export NebulaShutdownBlock
func NebulaShutdownBlock() (reterr *C.char) {
if control == nil {
fmt.Println("NebulaSetup has not yet been called")
return C.CString("NebulaSetup has not yet been called")
}
control.ShutdownBlock()
return C.CString("NO_FAILURE")
}
//export NebulaRebindUDP
func NebulaRebindUDP() (reterr *C.char) {
if control == nil {
fmt.Println("NebulaSetup has not yet been called")
return C.CString("NebulaSetup has not yet been called")
}
control.RebindUDPServer()
return C.CString("NO_FAILURE")
}
func main() {}