Skip to content

Commit

Permalink
link_linux: add support for IFLA_MACVLAN_BC_QUEUE_LEN(_USED)
Browse files Browse the repository at this point in the history
Signed-off-by: Etienne Champetier <e.champetier@ateme.com>
  • Loading branch information
champtar committed Jun 5, 2024
1 parent 4d4ba14 commit f093d59
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
3 changes: 3 additions & 0 deletions link.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,9 @@ type Macvlan struct {

// MACAddrs is only populated for Macvlan SOURCE links
MACAddrs []net.HardwareAddr

BCQueueLen uint32
UsedBCQueueLen uint32
}

func (macvlan *Macvlan) Attrs() *LinkAttrs {
Expand Down
33 changes: 25 additions & 8 deletions link_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -1733,15 +1733,9 @@ func (h *Handle) linkModify(link Link, flags int) error {
data.AddRtAttr(nl.IFLA_IPVLAN_MODE, nl.Uint16Attr(uint16(link.Mode)))
data.AddRtAttr(nl.IFLA_IPVLAN_FLAG, nl.Uint16Attr(uint16(link.Flag)))
case *Macvlan:
if link.Mode != MACVLAN_MODE_DEFAULT {
data := linkInfo.AddRtAttr(nl.IFLA_INFO_DATA, nil)
data.AddRtAttr(nl.IFLA_MACVLAN_MODE, nl.Uint32Attr(macvlanModes[link.Mode]))
}
addMacvlanAttrs(link, linkInfo)
case *Macvtap:
if link.Mode != MACVLAN_MODE_DEFAULT {
data := linkInfo.AddRtAttr(nl.IFLA_INFO_DATA, nil)
data.AddRtAttr(nl.IFLA_MACVLAN_MODE, nl.Uint32Attr(macvlanModes[link.Mode]))
}
addMacvtapAttrs(link, linkInfo)
case *Geneve:
addGeneveAttrs(link, linkInfo)
case *Gretap:
Expand Down Expand Up @@ -2941,11 +2935,30 @@ func parseIPVtapData(link Link, data []syscall.NetlinkRouteAttr) {
}
}

func addMacvtapAttrs(macvtap *Macvtap, linkInfo *nl.RtAttr) {
addMacvlanAttrs(&macvtap.Macvlan, linkInfo)
}

func parseMacvtapData(link Link, data []syscall.NetlinkRouteAttr) {
macv := link.(*Macvtap)
parseMacvlanData(&macv.Macvlan, data)
}

func addMacvlanAttrs(macvlan *Macvlan, linkInfo *nl.RtAttr) {
var data *nl.RtAttr

if macvlan.Mode != MACVLAN_MODE_DEFAULT || macvlan.BCQueueLen > 0 {
data = linkInfo.AddRtAttr(nl.IFLA_INFO_DATA, nil)
}

if macvlan.Mode != MACVLAN_MODE_DEFAULT {
data.AddRtAttr(nl.IFLA_MACVLAN_MODE, nl.Uint32Attr(macvlanModes[macvlan.Mode]))
}
if macvlan.BCQueueLen > 0 {
data.AddRtAttr(nl.IFLA_MACVLAN_BC_QUEUE_LEN, nl.Uint32Attr(macvlan.BCQueueLen))
}
}

func parseMacvlanData(link Link, data []syscall.NetlinkRouteAttr) {
macv := link.(*Macvlan)
for _, datum := range data {
Expand Down Expand Up @@ -2973,6 +2986,10 @@ func parseMacvlanData(link Link, data []syscall.NetlinkRouteAttr) {
for _, macDatum := range macs {
macv.MACAddrs = append(macv.MACAddrs, net.HardwareAddr(macDatum.Value[0:6]))
}
case nl.IFLA_MACVLAN_BC_QUEUE_LEN:
macv.BCQueueLen = native.Uint32(datum.Value[0:4])
case nl.IFLA_MACVLAN_BC_QUEUE_LEN_USED:
macv.UsedBCQueueLen = native.Uint32(datum.Value[0:4])
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion nl/link_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ const (
IFLA_MACVLAN_MACADDR
IFLA_MACVLAN_MACADDR_DATA
IFLA_MACVLAN_MACADDR_COUNT
IFLA_MACVLAN_MAX = IFLA_MACVLAN_FLAGS
IFLA_MACVLAN_BC_QUEUE_LEN
IFLA_MACVLAN_BC_QUEUE_LEN_USED
IFLA_MACVLAN_MAX = IFLA_MACVLAN_BC_QUEUE_LEN_USED
)

const (
Expand Down

0 comments on commit f093d59

Please sign in to comment.