]> git.ipfire.org Git - thirdparty/wireguard-go.git/commitdiff
device: return generic error from Ipc{Get,Set}Operation.
authorDavid Anderson <danderson@tailscale.com>
Wed, 1 Apr 2020 16:27:02 +0000 (09:27 -0700)
committerJason A. Donenfeld <Jason@zx2c4.com>
Sat, 2 May 2020 07:49:47 +0000 (01:49 -0600)
This makes uapi.go's public API conform to Go style in terms
of error types.

Signed-off-by: David Anderson <danderson@tailscale.com>
device/uapi.go
go.mod

index 6cdccd61589086b868ae12f434d2f596a39789d5..1080ca117978f0a6f410d98d15db6d996e2dd65e 100644 (file)
@@ -7,6 +7,7 @@ package device
 
 import (
        "bufio"
+       "errors"
        "fmt"
        "io"
        "net"
@@ -31,7 +32,7 @@ func (s IPCError) ErrorCode() int64 {
        return s.int64
 }
 
-func (device *Device) IpcGetOperation(socket *bufio.Writer) *IPCError {
+func (device *Device) IpcGetOperation(socket *bufio.Writer) error {
        lines := make([]string, 0, 100)
        send := func(line string) {
                lines = append(lines, line)
@@ -106,7 +107,7 @@ func (device *Device) IpcGetOperation(socket *bufio.Writer) *IPCError {
        return nil
 }
 
-func (device *Device) IpcSetOperation(socket *bufio.Reader) *IPCError {
+func (device *Device) IpcSetOperation(socket *bufio.Reader) error {
        scanner := bufio.NewScanner(socket)
        logError := device.log.Error
        logDebug := device.log.Debug
@@ -421,10 +422,20 @@ func (device *Device) IpcHandle(socket net.Conn) {
 
        switch op {
        case "set=1\n":
-               status = device.IpcSetOperation(buffered.Reader)
+               err = device.IpcSetOperation(buffered.Reader)
+               if err != nil && !errors.As(err, &status) {
+                       // should never happen
+                       device.log.Error.Println("Invalid UAPI error:", err)
+                       status = &IPCError{1}
+               }
 
        case "get=1\n":
-               status = device.IpcGetOperation(buffered.Writer)
+               err = device.IpcGetOperation(buffered.Writer)
+               if err != nil && !errors.As(err, &status) {
+                       // should never happen
+                       device.log.Error.Println("Invalid UAPI error:", err)
+                       status = &IPCError{1}
+               }
 
        default:
                device.log.Error.Println("Invalid UAPI operation:", op)
diff --git a/go.mod b/go.mod
index f4e7b97c993e3417afefabb7d6515ce3a73d58a2..c2183e0227873a36d8a7073246875f7330d6cf3f 100644 (file)
--- a/go.mod
+++ b/go.mod
@@ -1,6 +1,6 @@
 module golang.zx2c4.com/wireguard
 
-go 1.12
+go 1.13
 
 require (
        golang.org/x/crypto v0.0.0-20191002192127-34f69633bfdc