From 95c6836cb0e7f4cf4472afd8da766f63d912b157 Mon Sep 17 00:00:00 2001 From: Matt Layher Date: Wed, 23 Feb 2022 20:07:59 -0500 Subject: [PATCH] unix: add Kernel Connection Multiplexor ioctl helpers Builds upon the structures added in CL 348449. Change-Id: Ia8c95f52930ac90d1a37aedcda8cc46894630bf4 Reviewed-on: https://go-review.googlesource.com/c/sys/+/387794 Trust: Matt Layher Run-TryBot: Matt Layher TryBot-Result: Gopher Robot Reviewed-by: Tobias Klauser --- unix/ioctl_linux.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/unix/ioctl_linux.go b/unix/ioctl_linux.go index 1dadead2..884430b8 100644 --- a/unix/ioctl_linux.go +++ b/unix/ioctl_linux.go @@ -194,3 +194,26 @@ func ioctlIfreqData(fd int, req uint, value *ifreqData) error { // identical so pass *IfreqData directly. return ioctlPtr(fd, req, unsafe.Pointer(value)) } + +// IoctlKCMClone attaches a new file descriptor to a multiplexor by cloning an +// existing KCM socket, returning a structure containing the file descriptor of +// the new socket. +func IoctlKCMClone(fd int) (*KCMClone, error) { + var info KCMClone + if err := ioctlPtr(fd, SIOCKCMCLONE, unsafe.Pointer(&info)); err != nil { + return nil, err + } + + return &info, nil +} + +// IoctlKCMAttach attaches a TCP socket and associated BPF program file +// descriptor to a multiplexor. +func IoctlKCMAttach(fd int, info KCMAttach) error { + return ioctlPtr(fd, SIOCKCMATTACH, unsafe.Pointer(&info)) +} + +// IoctlKCMUnattach unattaches a TCP socket file descriptor from a multiplexor. +func IoctlKCMUnattach(fd int, info KCMUnattach) error { + return ioctlPtr(fd, SIOCKCMUNATTACH, unsafe.Pointer(&info)) +}