[PATCH] device: revert pipelining UAPI requests
Laura Zelenku
laura.zelenku at wandera.com
Tue Mar 9 15:02:41 UTC 2021
Hello devs,
there is an issue when using wg-quick tool and wg tool bellow from wireguard-tools repository (version v1.0.20210223). I’m running: wg-quick up operation with config file in /etc/wireguard/ directory. Get operations are ok. Processed without a problem. But for Set operation the processing will stuck on "buffered.ReadString('\n’)” (in the second run of for loop cycle, after set command is processed in first for loop cycle) because bufio.Scanner will read everything from the socket.
Please revert till proper fix is ready.
thanks
Laura
Signed-off-by: Laura Zelenku <laura.zelenku at wandera.com>
---
device/uapi.go | 64 +++++++++++++++++++++-----------------------------
1 file changed, 27 insertions(+), 37 deletions(-)
diff --git a/device/uapi.go b/device/uapi.go
index 659af0a..9fab911 100644
--- a/device/uapi.go
+++ b/device/uapi.go
@@ -414,44 +414,34 @@ func (device *Device) IpcHandle(socket net.Conn) {
return bufio.NewReadWriter(reader, writer)
}(socket)
- for {
- op, err := buffered.ReadString('\n')
- if err != nil {
- return
- }
+ defer buffered.Flush()
- // handle operation
- switch op {
- case "set=1\n":
- err = device.IpcSetOperation(buffered.Reader)
- case "get=1\n":
- var nextByte byte
- nextByte, err = buffered.ReadByte()
- if err != nil {
- return
- }
- if nextByte != '\n' {
- err = ipcErrorf(ipc.IpcErrorInvalid, "trailing character in UAPI get: %q", nextByte)
- break
- }
- err = device.IpcGetOperation(buffered.Writer)
- default:
- device.log.Errorf("invalid UAPI operation: %v", op)
- return
- }
+ op, err := buffered.ReadString('\n')
+ if err != nil {
+ return
+ }
- // write status
- var status *IPCError
- if err != nil && !errors.As(err, &status) {
- // shouldn't happen
- status = ipcErrorf(ipc.IpcErrorUnknown, "other UAPI error: %w", err)
- }
- if status != nil {
- device.log.Errorf("%v", status)
- fmt.Fprintf(buffered, "errno=%d\n\n", status.ErrorCode())
- } else {
- fmt.Fprintf(buffered, "errno=0\n\n")
- }
- buffered.Flush()
+ // handle operation
+ switch op {
+ case "set=1\n":
+ err = device.IpcSetOperation(buffered.Reader)
+ case "get=1\n":
+ err = device.IpcGetOperation(buffered.Writer)
+ default:
+ device.log.Errorf("invalid UAPI operation: %v", op)
+ return
+ }
+
+ // write status
+ var status *IPCError
+ if err != nil && !errors.As(err, &status) {
+ // shouldn't happen
+ status = ipcErrorf(ipc.IpcErrorUnknown, "other UAPI error: %w", err)
+ }
+ if status != nil {
+ device.log.Errorf("%v", status)
+ fmt.Fprintf(buffered, "errno=%d\n\n", status.ErrorCode())
+ } else {
+ fmt.Fprintf(buffered, "errno=0\n\n")
}
}
--
2.28.0
--
*IMPORTANT NOTICE*: This email, its attachments and any rights attaching
hereto are confidential and intended exclusively for the person to whom the
email is addressed. If you are not the intended recipient, do not read,
copy, disclose or use the contents in any way. Wandera accepts no liability
for any loss, damage or consequence resulting directly or indirectly from
the use of this email and attachments.
More information about the WireGuard
mailing list