8cadff2b79
* CNI: bump to 1.0.1 This commit bumps the declared version of CNI in the Kilo manifests to 1.0.1. This is possible with no changes to the configuration lists because our simple configuration is not affected by any of the deprecations, and there was effectively no change between 0.4.0 and 1.0.0, other than the declaration of a stable API. Similarly, this commit also bumps the version of the CNI library and the plugins package. Bumping to CNI 1.0.0 will help ensure that Kilo stays compatible with container runtimes in the future. Signed-off-by: Lucas Servén Marín <lserven@gmail.com> * vendor: revendor Signed-off-by: Lucas Servén Marín <lserven@gmail.com>
75 lines
1.8 KiB
Go
75 lines
1.8 KiB
Go
package netlink
|
|
|
|
import (
|
|
"fmt"
|
|
"syscall"
|
|
|
|
"github.com/vishvananda/netlink/nl"
|
|
"golang.org/x/sys/unix"
|
|
)
|
|
|
|
func LinkGetProtinfo(link Link) (Protinfo, error) {
|
|
return pkgHandle.LinkGetProtinfo(link)
|
|
}
|
|
|
|
func (h *Handle) LinkGetProtinfo(link Link) (Protinfo, error) {
|
|
base := link.Attrs()
|
|
h.ensureIndex(base)
|
|
var pi Protinfo
|
|
req := h.newNetlinkRequest(unix.RTM_GETLINK, unix.NLM_F_DUMP)
|
|
msg := nl.NewIfInfomsg(unix.AF_BRIDGE)
|
|
req.AddData(msg)
|
|
msgs, err := req.Execute(unix.NETLINK_ROUTE, 0)
|
|
if err != nil {
|
|
return pi, err
|
|
}
|
|
|
|
for _, m := range msgs {
|
|
ans := nl.DeserializeIfInfomsg(m)
|
|
if int(ans.Index) != base.Index {
|
|
continue
|
|
}
|
|
attrs, err := nl.ParseRouteAttr(m[ans.Len():])
|
|
if err != nil {
|
|
return pi, err
|
|
}
|
|
for _, attr := range attrs {
|
|
if attr.Attr.Type != unix.IFLA_PROTINFO|unix.NLA_F_NESTED {
|
|
continue
|
|
}
|
|
infos, err := nl.ParseRouteAttr(attr.Value)
|
|
if err != nil {
|
|
return pi, err
|
|
}
|
|
pi = parseProtinfo(infos)
|
|
|
|
return pi, nil
|
|
}
|
|
}
|
|
return pi, fmt.Errorf("Device with index %d not found", base.Index)
|
|
}
|
|
|
|
func parseProtinfo(infos []syscall.NetlinkRouteAttr) (pi Protinfo) {
|
|
for _, info := range infos {
|
|
switch info.Attr.Type {
|
|
case nl.IFLA_BRPORT_MODE:
|
|
pi.Hairpin = byteToBool(info.Value[0])
|
|
case nl.IFLA_BRPORT_GUARD:
|
|
pi.Guard = byteToBool(info.Value[0])
|
|
case nl.IFLA_BRPORT_FAST_LEAVE:
|
|
pi.FastLeave = byteToBool(info.Value[0])
|
|
case nl.IFLA_BRPORT_PROTECT:
|
|
pi.RootBlock = byteToBool(info.Value[0])
|
|
case nl.IFLA_BRPORT_LEARNING:
|
|
pi.Learning = byteToBool(info.Value[0])
|
|
case nl.IFLA_BRPORT_UNICAST_FLOOD:
|
|
pi.Flood = byteToBool(info.Value[0])
|
|
case nl.IFLA_BRPORT_PROXYARP:
|
|
pi.ProxyArp = byteToBool(info.Value[0])
|
|
case nl.IFLA_BRPORT_PROXYARP_WIFI:
|
|
pi.ProxyArpWiFi = byteToBool(info.Value[0])
|
|
}
|
|
}
|
|
return
|
|
}
|