aboutsummaryrefslogtreecommitdiffstats
path: root/src/config.go
diff options
context:
space:
mode:
authorMathias Hall-Andersen <mathias@hall-andersen.dk>2017-06-01 21:31:30 +0200
committerMathias Hall-Andersen <mathias@hall-andersen.dk>2017-06-01 21:31:30 +0200
commitec3d656bebb9ee7c38724500779b7ad322ba0377 (patch)
tree766c47aa8bcd69e6d6db1383dfdf62fc861723c1 /src/config.go
parentMerge branch 'master' of git.zx2c4.com:wireguard-go (diff)
downloadwireguard-go-ec3d656bebb9ee7c38724500779b7ad322ba0377.tar.xz
wireguard-go-ec3d656bebb9ee7c38724500779b7ad322ba0377.zip
Inital implementation of trie
Diffstat (limited to 'src/config.go')
-rw-r--r--src/config.go25
1 files changed, 19 insertions, 6 deletions
diff --git a/src/config.go b/src/config.go
index f6f1378..62af67a 100644
--- a/src/config.go
+++ b/src/config.go
@@ -6,6 +6,7 @@ import (
"fmt"
"io"
"log"
+ "net"
)
/* todo : use real error code
@@ -18,6 +19,7 @@ const (
ipcErrorInvalidPrivateKey = 3
ipcErrorInvalidPublicKey = 4
ipcErrorInvalidPort = 5
+ ipcErrorInvalidIPAddress = 6
)
type IPCError struct {
@@ -104,6 +106,10 @@ func ipcSetOperation(dev *Device, socket *bufio.ReadWriter) *IPCError {
}
case "replace_peers":
+ if key == "true" {
+ dev.RemoveAllPeers()
+ }
+ // todo: else fail
default:
/* Peer configuration */
@@ -116,20 +122,27 @@ func ipcSetOperation(dev *Device, socket *bufio.ReadWriter) *IPCError {
case "remove":
peer.mutex.Lock()
-
+ dev.RemovePeer(peer.publicKey)
peer = nil
case "preshared_key":
- func() {
+ err := func() error {
peer.mutex.Lock()
defer peer.mutex.Unlock()
+ return peer.presharedKey.FromHex(value)
}()
+ if err != nil {
+ return &IPCError{Code: ipcErrorInvalidPublicKey}
+ }
case "endpoint":
- func() {
- peer.mutex.Lock()
- defer peer.mutex.Unlock()
- }()
+ ip := net.ParseIP(value)
+ if ip == nil {
+ return &IPCError{Code: ipcErrorInvalidIPAddress}
+ }
+ peer.mutex.Lock()
+ peer.endpoint = ip
+ peer.mutex.Unlock()
case "persistent_keepalive_interval":
func() {