Development discussion of WireGuard
 help / color / mirror / Atom feed
* [PATCH] device: revert pipelining UAPI requests
@ 2021-03-09 15:02 Laura Zelenku
  2021-03-09 15:09 ` Jason A. Donenfeld
  0 siblings, 1 reply; 5+ messages in thread
From: Laura Zelenku @ 2021-03-09 15:02 UTC (permalink / raw)
  To: WireGuard mailing list

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@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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-03-10 12:15 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-09 15:02 [PATCH] device: revert pipelining UAPI requests Laura Zelenku
2021-03-09 15:09 ` Jason A. Donenfeld
2021-03-09 16:30   ` Laura Zelenku
2021-03-09 16:33     ` Jason A. Donenfeld
2021-03-10 12:13       ` Laura Zelenku

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).