Skip to content

Commit 11705e6

Browse files
committed
device: return generic error from Ipc{Get,Set}Operation.
This makes uapi.go's public API conform to Go style in terms of error types. Signed-off-by: David Anderson <[email protected]>
1 parent e852f4c commit 11705e6

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

device/uapi.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package device
77

88
import (
99
"bufio"
10+
"errors"
1011
"fmt"
1112
"io"
1213
"net"
@@ -31,7 +32,7 @@ func (s IPCError) ErrorCode() int64 {
3132
return s.int64
3233
}
3334

34-
func (device *Device) IpcGetOperation(socket *bufio.Writer) *IPCError {
35+
func (device *Device) IpcGetOperation(socket *bufio.Writer) error {
3536
lines := make([]string, 0, 100)
3637
send := func(line string) {
3738
lines = append(lines, line)
@@ -106,7 +107,7 @@ func (device *Device) IpcGetOperation(socket *bufio.Writer) *IPCError {
106107
return nil
107108
}
108109

109-
func (device *Device) IpcSetOperation(socket *bufio.Reader) *IPCError {
110+
func (device *Device) IpcSetOperation(socket *bufio.Reader) error {
110111
scanner := bufio.NewScanner(socket)
111112
logError := device.log.Error
112113
logDebug := device.log.Debug
@@ -421,10 +422,20 @@ func (device *Device) IpcHandle(socket net.Conn) {
421422

422423
switch op {
423424
case "set=1\n":
424-
status = device.IpcSetOperation(buffered.Reader)
425+
err = device.IpcSetOperation(buffered.Reader)
426+
if !errors.As(err, &status) {
427+
// should never happen
428+
device.log.Error.Println("Invalid UAPI error:", err)
429+
status = &IPCError{1}
430+
}
425431

426432
case "get=1\n":
427-
status = device.IpcGetOperation(buffered.Writer)
433+
err = device.IpcGetOperation(buffered.Writer)
434+
if !errors.As(err, &status) {
435+
// should never happen
436+
device.log.Error.Println("Invalid UAPI error:", err)
437+
status = &IPCError{1}
438+
}
428439

429440
default:
430441
device.log.Error.Println("Invalid UAPI operation:", op)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module golang.zx2c4.com/wireguard
22

3-
go 1.12
3+
go 1.13
44

55
require (
66
golang.org/x/crypto v0.0.0-20191002192127-34f69633bfdc

0 commit comments

Comments
 (0)