func (c *Client) execute(command uint8, flags netlink.HeaderFlags, attrb []byte) ([]genetlink.Message, error) {
	msg := genetlink.Message{
		Header: genetlink.Header{
			Command: command,
			Version: wgh.GenlVersion,
		},
		Data: attrb,
	}
	msgs, err := c.c.Execute(msg, c.family.ID, flags)
	if err == nil {
		return msgs, nil
	}
	oerr, ok := err.(*netlink.OpError)
	if !ok {
		return nil, fmt.Errorf("wglinux: netlink operation returned non-netlink error (please file a bug: https://golang.zx2c4.com/wireguard/wgctrl): %v", err)
	}
	switch oerr.Err {
	case unix.ENODEV, unix.ENOTSUP:
		return nil, os.ErrNotExist
	default:
		return nil, oerr.Err
	}
}
execute executes a single WireGuard netlink request with the specified command,
header flags, and attribute arguments.
package wglinux
import (
	"errors"
	"fmt"
	"os"
	"syscall"
	"github.com/mdlayher/genetlink"
	"github.com/mdlayher/netlink"
	"github.com/mdlayher/netlink/nlenc"
	"golang.org/x/sys/unix"
	"golang.zx2c4.com/wireguard/wgctrl/internal/wginternal"
	"golang.zx2c4.com/wireguard/wgctrl/internal/wglinux/internal/wgh"
	"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
)
var _ wginternal.Client = &Client{}
type Client struct {
	c      *genetlink.Conn
	family genetlink.Family
	interfaces func() ([]string, error)
}
func New() (*Client, bool, error) {
	c, err := genetlink.Dial(nil)
	if err != nil {
		return nil, false, err
	}
	return initClient(c)
}
func initClient(c *genetlink.Conn) (*Client, bool, error) {
	f, err := c.GetFamily(wgh.GenlName)
	if err != nil {
		_ = c.Close()
		if errors.Is(err, os.ErrNotExist) {
			return nil, false, nil
		}
		return nil, false, err
	}
	return &Client{
		c:      c,
		family: f,
		interfaces: rtnlInterfaces,
	}, true, nil
}
func (c *Client) Close() error {
	return c.c.Close()
}
func (c *Client) Devices() ([]*wgtypes.Device, error) {
	ifis, err := c.interfaces()
	if err != nil {
		return nil, err
	}
	ds := make([]*wgtypes.Device, 0, len(ifis))
	for _, ifi := range ifis {
		d, err := c.Device(ifi)
		if err != nil {
			return nil, err
		}
		ds = append(ds, d)
	}
	return ds, nil
}
func (c *Client) Device(name string) (*wgtypes.Device, error) {
	if name == "" {
		return nil, os.ErrNotExist
	}
	b, err := netlink.MarshalAttributes([]netlink.Attribute{{
		Type: wgh.DeviceAIfname,
		Data: nlenc.Bytes(name),
	}})
	if err != nil {
		return nil, err
	}
	msgs, err := c.execute(wgh.CmdGetDevice, netlink.Request|netlink.Dump, b)
	if err != nil {
		return nil, err
	}
	return parseDevice(msgs)
}
func (c *Client) ConfigureDevice(name string, cfg wgtypes.Config) error {
	for _, b := range buildBatches(cfg) {
		attrs, err := configAttrs(name, b)
		if err != nil {
			return err
		}
		if _, err := c.execute(wgh.CmdSetDevice, netlink.Request|netlink.Acknowledge, attrs); err != nil {
			return err
		}
	}
	return nil
}