wireguard-go-bridge: allow querying internal settings

This commit is contained in:
Jason A. Donenfeld 2019-01-23 22:15:01 +01:00
parent 7122123c3e
commit 8203a322c1
3 changed files with 23 additions and 8 deletions

@ -1 +1 @@
Subproject commit 8fde8334dcf3a7f3934159f45b6fc1d5f4be8a90 Subproject commit c614add90fbb9ccf0fafb17e237dfb9df54a7043

View File

@ -15,10 +15,10 @@ import "C"
import ( import (
"bufio" "bufio"
"bytes"
"errors" "errors"
"git.zx2c4.com/wireguard-go/tun" "git.zx2c4.com/wireguard-go/tun"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
"io/ioutil"
"log" "log"
"math" "math"
"os" "os"
@ -94,8 +94,7 @@ func wgTurnOn(settings string, tunFd int32) int32 {
logger.Info.Println("Attaching to interface") logger.Info.Println("Attaching to interface")
device := NewDevice(tun, logger) device := NewDevice(tun, logger)
bufferedSettings := bufio.NewReadWriter(bufio.NewReader(strings.NewReader(settings)), bufio.NewWriter(ioutil.Discard)) setError := ipcSetOperation(device, bufio.NewReader(strings.NewReader(settings)))
setError := ipcSetOperation(device, bufferedSettings)
if setError != nil { if setError != nil {
logger.Error.Println(setError) logger.Error.Println(setError)
return -1 return -1
@ -133,15 +132,30 @@ func wgSetConfig(tunnelHandle int32, settings string) int64 {
if !ok { if !ok {
return 0 return 0
} }
bufferedSettings := bufio.NewReadWriter(bufio.NewReader(strings.NewReader(settings)), bufio.NewWriter(ioutil.Discard)) err := ipcSetOperation(device, bufio.NewReader(strings.NewReader(settings)))
err := ipcSetOperation(device, bufferedSettings)
if err != nil { if err != nil {
device.log.Error.Println(err) device.log.Error.Println(err)
return err.Code return err.int64
} }
return 0 return 0
} }
//export wgGetConfig
func wgGetConfig(tunnelHandle int32) *C.char {
device, ok := tunnelHandles[tunnelHandle]
if !ok {
return nil
}
settings := new(bytes.Buffer)
writer := bufio.NewWriter(settings)
err := ipcGetOperation(device, writer)
if err != nil {
return nil
}
writer.Flush()
return C.CString(settings.String())
}
//export wgBindInterfaceScope //export wgBindInterfaceScope
func wgBindInterfaceScope(tunnelHandle int32, ifscope int32) { func wgBindInterfaceScope(tunnelHandle int32, ifscope int32) {
var operr error var operr error

View File

@ -17,7 +17,8 @@ extern void wgSetLogger(logger_fn_t logger_fn);
extern int wgTurnOn(gostring_t settings, int32_t tun_fd); extern int wgTurnOn(gostring_t settings, int32_t tun_fd);
extern void wgTurnOff(int handle); extern void wgTurnOff(int handle);
extern int64_t wgSetConfig(int handle, gostring_t settings); extern int64_t wgSetConfig(int handle, gostring_t settings);
extern char *wgGetConfig(int handle);
extern void wgBindInterfaceScope(int handle, int32_t ifscope); extern void wgBindInterfaceScope(int handle, int32_t ifscope);
extern char *wgVersion(); extern const char *wgVersion();
#endif #endif