MCPcopy
hub / github.com/WireGuard/wireguard-go / IpcHandle

Method IpcHandle

device/uapi.go:419–468  ·  view source on GitHub ↗
(socket net.Conn)

Source from the content-addressed store, hash-verified

417}
418
419func (device *Device) IpcHandle(socket net.Conn) {
420 defer socket.Close()
421
422 buffered := func(s io.ReadWriter) *bufio.ReadWriter {
423 reader := bufio.NewReader(s)
424 writer := bufio.NewWriter(s)
425 return bufio.NewReadWriter(reader, writer)
426 }(socket)
427
428 for {
429 op, err := buffered.ReadString('\n')
430 if err != nil {
431 return
432 }
433
434 // handle operation
435 switch op {
436 case "set=1\n":
437 err = device.IpcSetOperation(buffered.Reader)
438 case "get=1\n":
439 var nextByte byte
440 nextByte, err = buffered.ReadByte()
441 if err != nil {
442 return
443 }
444 if nextByte != '\n' {
445 err = ipcErrorf(ipc.IpcErrorInvalid, "trailing character in UAPI get: %q", nextByte)
446 break
447 }
448 err = device.IpcGetOperation(buffered.Writer)
449 default:
450 device.log.Errorf("invalid UAPI operation: %v", op)
451 return
452 }
453
454 // write status
455 var status *IPCError
456 if err != nil && !errors.As(err, &status) {
457 // shouldn't happen
458 status = ipcErrorf(ipc.IpcErrorUnknown, "other UAPI error: %w", err)
459 }
460 if status != nil {
461 device.log.Errorf("%v", status)
462 fmt.Fprintf(buffered, "errno=%d\n\n", status.ErrorCode())
463 } else {
464 fmt.Fprintf(buffered, "errno=0\n\n")
465 }
466 buffered.Flush()
467 }
468}

Callers 2

mainFunction · 0.95
mainFunction · 0.95

Implementers 4

NativeTuntun/tun_linux.go
netTuntun/netstack/tun.go
chTuntun/tuntest/tuntest.go
fakeTUNDeviceSizeddevice/device_test.go

Calls 6

IpcSetOperationMethod · 0.95
IpcGetOperationMethod · 0.95
ErrorCodeMethod · 0.95
ipcErrorfFunction · 0.85
FlushMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected