2015-02-07 02:58:24 +00:00
|
|
|
package netlink
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"syscall"
|
|
|
|
|
|
|
|
"github.com/vishvananda/netlink/nl"
|
2017-10-20 20:38:07 +00:00
|
|
|
"golang.org/x/sys/unix"
|
2015-02-07 02:58:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func LinkGetProtinfo(link Link) (Protinfo, error) {
|
2016-05-09 23:55:00 +00:00
|
|
|
return pkgHandle.LinkGetProtinfo(link)
|
2016-05-08 18:35:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (h *Handle) LinkGetProtinfo(link Link) (Protinfo, error) {
|
2015-02-07 02:58:24 +00:00
|
|
|
base := link.Attrs()
|
2016-05-08 18:35:49 +00:00
|
|
|
h.ensureIndex(base)
|
2015-02-07 02:58:24 +00:00
|
|
|
var pi Protinfo
|
2017-10-20 20:38:07 +00:00
|
|
|
req := h.newNetlinkRequest(unix.RTM_GETLINK, unix.NLM_F_DUMP)
|
|
|
|
msg := nl.NewIfInfomsg(unix.AF_BRIDGE)
|
2015-02-07 02:58:24 +00:00
|
|
|
req.AddData(msg)
|
2017-10-20 20:38:07 +00:00
|
|
|
msgs, err := req.Execute(unix.NETLINK_ROUTE, 0)
|
2015-02-07 02:58:24 +00:00
|
|
|
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 {
|
2017-10-20 20:38:07 +00:00
|
|
|
if attr.Attr.Type != unix.IFLA_PROTINFO|unix.NLA_F_NESTED {
|
2015-02-07 02:58:24 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
infos, err := nl.ParseRouteAttr(attr.Value)
|
|
|
|
if err != nil {
|
|
|
|
return pi, err
|
|
|
|
}
|
2018-09-30 20:42:25 +00:00
|
|
|
pi = parseProtinfo(infos)
|
2016-11-24 18:32:30 +00:00
|
|
|
|
2015-02-07 02:58:24 +00:00
|
|
|
return pi, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return pi, fmt.Errorf("Device with index %d not found", base.Index)
|
|
|
|
}
|
2016-11-24 18:32:30 +00:00
|
|
|
|
2018-09-30 20:42:25 +00:00
|
|
|
func parseProtinfo(infos []syscall.NetlinkRouteAttr) (pi Protinfo) {
|
2016-11-24 18:32:30 +00:00
|
|
|
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])
|
2017-04-19 23:03:46 +00:00
|
|
|
case nl.IFLA_BRPORT_PROXYARP:
|
|
|
|
pi.ProxyArp = byteToBool(info.Value[0])
|
|
|
|
case nl.IFLA_BRPORT_PROXYARP_WIFI:
|
|
|
|
pi.ProxyArpWiFi = byteToBool(info.Value[0])
|
2023-05-24 11:14:53 +00:00
|
|
|
case nl.IFLA_BRPORT_ISOLATED:
|
|
|
|
pi.Isolated = byteToBool(info.Value[0])
|
2023-07-14 15:00:46 +00:00
|
|
|
case nl.IFLA_BRPORT_NEIGH_SUPPRESS:
|
|
|
|
pi.NeighSuppress = byteToBool(info.Value[0])
|
2016-11-24 18:32:30 +00:00
|
|
|
}
|
|
|
|
}
|
2018-09-30 20:42:25 +00:00
|
|
|
return
|
2016-11-24 18:32:30 +00:00
|
|
|
}
|