Development discussion of WireGuard
 help / color / mirror / Atom feed
From: Laura Zelenku <laura.zelenku@wandera.com>
To: WireGuard mailing list <wireguard@lists.zx2c4.com>
Subject: [PATCH] device: revert pipelining UAPI requests
Date: Tue, 9 Mar 2021 16:02:41 +0100	[thread overview]
Message-ID: <038632B3-A3F3-4FC6-8242-265A42F89F1F@wandera.com> (raw)

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.

             reply	other threads:[~2021-03-09 15:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-09 15:02 Laura Zelenku [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=038632B3-A3F3-4FC6-8242-265A42F89F1F@wandera.com \
    --to=laura.zelenku@wandera.com \
    --cc=wireguard@lists.zx2c4.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).