blob: 82c6e8205f7ce342fced86e5d127378b2cdcdd5c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
/* SPDX-License-Identifier: Apache-2.0
*
* Copyright (C) 2017-2019 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
* Copyright (C) 2021 Mullvad VPN AB. All Rights Reserved.
*/
package main
// #include <stdlib.h>
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() {}
|