summaryrefslogtreecommitdiff
path: root/vendor/github.com/vishvananda/netlink/devlink_linux.go
diff options
context:
space:
mode:
authorPaul Holzinger <pholzing@redhat.com>2021-09-17 15:39:16 +0200
committerPaul Holzinger <pholzing@redhat.com>2021-09-22 11:51:40 +0200
commitaf49810a6e08ed084294ce03e1c8a5efb8d1a705 (patch)
tree719dbe463ccfbfc54914869576b2f1bbcf4c6680 /vendor/github.com/vishvananda/netlink/devlink_linux.go
parent8e2d25e93706190acf25bcf74bd18cdf98fb3a12 (diff)
downloadpodman-af49810a6e08ed084294ce03e1c8a5efb8d1a705.tar.gz
podman-af49810a6e08ed084294ce03e1c8a5efb8d1a705.tar.bz2
podman-af49810a6e08ed084294ce03e1c8a5efb8d1a705.zip
Bump CNI to v1.0.1
Update CNI so we can match wrapped errors. This should silence ENOENT warnings when trying to read the cni conflist files. Fixes #10926 Because CNI v1.0.0 contains breaking changes we have to change some import paths. Also we cannot update the CNI version used for the conflist files created by `podman network create` because this would require at least containernetwork-plugins v1.0.1 and a updated dnsname plugin. Because this will take a while until it lands in most distros we should not use this version. So keep using v0.4.0 for now. The update from checkpoint-restore/checkpointctl is also required to make sure it no longer uses CNI to read the network status. [NO TESTS NEEDED] Signed-off-by: Paul Holzinger <pholzing@redhat.com>
Diffstat (limited to 'vendor/github.com/vishvananda/netlink/devlink_linux.go')
-rw-r--r--vendor/github.com/vishvananda/netlink/devlink_linux.go121
1 files changed, 121 insertions, 0 deletions
diff --git a/vendor/github.com/vishvananda/netlink/devlink_linux.go b/vendor/github.com/vishvananda/netlink/devlink_linux.go
index 29b3f8ec1..7d57080e8 100644
--- a/vendor/github.com/vishvananda/netlink/devlink_linux.go
+++ b/vendor/github.com/vishvananda/netlink/devlink_linux.go
@@ -27,6 +27,18 @@ type DevlinkDevice struct {
Attrs DevlinkDevAttrs
}
+// DevlinkPort represents port and its attributes
+type DevlinkPort struct {
+ BusName string
+ DeviceName string
+ PortIndex uint32
+ PortType uint16
+ NetdeviceName string
+ NetdevIfIndex uint32
+ RdmaDeviceName string
+ PortFlavour uint16
+}
+
func parseDevLinkDeviceList(msgs [][]byte) ([]*DevlinkDevice, error) {
devices := make([]*DevlinkDevice, 0, len(msgs))
for _, m := range msgs {
@@ -270,3 +282,112 @@ func (h *Handle) DevLinkSetEswitchMode(Dev *DevlinkDevice, NewMode string) error
func DevLinkSetEswitchMode(Dev *DevlinkDevice, NewMode string) error {
return pkgHandle.DevLinkSetEswitchMode(Dev, NewMode)
}
+
+func (port *DevlinkPort) parseAttributes(attrs []syscall.NetlinkRouteAttr) error {
+ for _, a := range attrs {
+ switch a.Attr.Type {
+ case nl.DEVLINK_ATTR_BUS_NAME:
+ port.BusName = string(a.Value)
+ case nl.DEVLINK_ATTR_DEV_NAME:
+ port.DeviceName = string(a.Value)
+ case nl.DEVLINK_ATTR_PORT_INDEX:
+ port.PortIndex = native.Uint32(a.Value)
+ case nl.DEVLINK_ATTR_PORT_TYPE:
+ port.PortType = native.Uint16(a.Value)
+ case nl.DEVLINK_ATTR_PORT_NETDEV_NAME:
+ port.NetdeviceName = string(a.Value)
+ case nl.DEVLINK_ATTR_PORT_NETDEV_IFINDEX:
+ port.NetdevIfIndex = native.Uint32(a.Value)
+ case nl.DEVLINK_ATTR_PORT_IBDEV_NAME:
+ port.RdmaDeviceName = string(a.Value)
+ case nl.DEVLINK_ATTR_PORT_FLAVOUR:
+ port.PortFlavour = native.Uint16(a.Value)
+ }
+ }
+ return nil
+}
+
+func parseDevLinkAllPortList(msgs [][]byte) ([]*DevlinkPort, error) {
+ ports := make([]*DevlinkPort, 0, len(msgs))
+ for _, m := range msgs {
+ attrs, err := nl.ParseRouteAttr(m[nl.SizeofGenlmsg:])
+ if err != nil {
+ return nil, err
+ }
+ port := &DevlinkPort{}
+ if err = port.parseAttributes(attrs); err != nil {
+ return nil, err
+ }
+ ports = append(ports, port)
+ }
+ return ports, nil
+}
+
+// DevLinkGetPortList provides a pointer to devlink ports and nil error,
+// otherwise returns an error code.
+func (h *Handle) DevLinkGetAllPortList() ([]*DevlinkPort, error) {
+ f, err := h.GenlFamilyGet(nl.GENL_DEVLINK_NAME)
+ if err != nil {
+ return nil, err
+ }
+ msg := &nl.Genlmsg{
+ Command: nl.DEVLINK_CMD_PORT_GET,
+ Version: nl.GENL_DEVLINK_VERSION,
+ }
+ req := h.newNetlinkRequest(int(f.ID),
+ unix.NLM_F_REQUEST|unix.NLM_F_ACK|unix.NLM_F_DUMP)
+ req.AddData(msg)
+ msgs, err := req.Execute(unix.NETLINK_GENERIC, 0)
+ if err != nil {
+ return nil, err
+ }
+ ports, err := parseDevLinkAllPortList(msgs)
+ if err != nil {
+ return nil, err
+ }
+ return ports, nil
+}
+
+// DevLinkGetPortList provides a pointer to devlink ports and nil error,
+// otherwise returns an error code.
+func DevLinkGetAllPortList() ([]*DevlinkPort, error) {
+ return pkgHandle.DevLinkGetAllPortList()
+}
+
+func parseDevlinkPortMsg(msgs [][]byte) (*DevlinkPort, error) {
+ m := msgs[0]
+ attrs, err := nl.ParseRouteAttr(m[nl.SizeofGenlmsg:])
+ if err != nil {
+ return nil, err
+ }
+ port := &DevlinkPort{}
+ if err = port.parseAttributes(attrs); err != nil {
+ return nil, err
+ }
+ return port, nil
+}
+
+// DevLinkGetPortByIndexprovides a pointer to devlink device and nil error,
+// otherwise returns an error code.
+func (h *Handle) DevLinkGetPortByIndex(Bus string, Device string, PortIndex uint32) (*DevlinkPort, error) {
+
+ _, req, err := h.createCmdReq(nl.DEVLINK_CMD_PORT_GET, Bus, Device)
+ if err != nil {
+ return nil, err
+ }
+
+ req.AddData(nl.NewRtAttr(nl.DEVLINK_ATTR_PORT_INDEX, nl.Uint32Attr(PortIndex)))
+
+ respmsg, err := req.Execute(unix.NETLINK_GENERIC, 0)
+ if err != nil {
+ return nil, err
+ }
+ port, err := parseDevlinkPortMsg(respmsg)
+ return port, err
+}
+
+// DevLinkGetPortByIndex provides a pointer to devlink portand nil error,
+// otherwise returns an error code.
+func DevLinkGetPortByIndex(Bus string, Device string, PortIndex uint32) (*DevlinkPort, error) {
+ return pkgHandle.DevLinkGetPortByIndex(Bus, Device, PortIndex)
+}