/* SPDX-License-Identifier: Apache-2.0 * * Copyright (C) 2017-2019 Jason A. Donenfeld . All Rights Reserved. * Copyright (C) 2021 Mullvad VPN AB. All Rights Reserved. */ package main // #include import "C" import ( "bufio" "bytes" "runtime" "unsafe" "github.com/mullvad/mullvadvpn-app/wireguard/libwg/tunnelcontainer" ) const ( ERROR_GENERAL_FAILURE = -1 ERROR_INTERMITTENT_FAILURE = -2 ) var tunnels tunnelcontainer.Container func init() { tunnels = tunnelcontainer.New() } //export wgTurnOff func wgTurnOff(tunnelHandle int32) { { tunnel, err := tunnels.Remove(tunnelHandle) if err != nil { return } tunnel.Device.Close() } // Calling twice convinces the GC to release NOW. runtime.GC() runtime.GC() } //export wgGetConfig func wgGetConfig(tunnelHandle int32) *C.char { tunnel, err := tunnels.Get(tunnelHandle) if err != nil { return nil } settings := new(bytes.Buffer) writer := bufio.NewWriter(settings) if err := tunnel.Device.IpcGetOperation(writer); err != nil { tunnel.Logger.Errorf("Failed to get config for tunnel: %s\n", err) return nil } writer.Flush() return C.CString(settings.String()) } //export wgFreePtr func wgFreePtr(ptr unsafe.Pointer) { C.free(ptr) } func main() {}