Skip to content

Commit 65a253d

Browse files
champtaraboch
authored andcommitted
link_linux: add support for IFLA_MACVLAN_BC_QUEUE_LEN(_USED)
Signed-off-by: Etienne Champetier <e.champetier@ateme.com>
1 parent 3b7e16c commit 65a253d

4 files changed

Lines changed: 81 additions & 9 deletions

File tree

‎link.go‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,9 @@ type Macvlan struct {
318318

319319
// MACAddrs is only populated for Macvlan SOURCE links
320320
MACAddrs []net.HardwareAddr
321+
322+
BCQueueLen uint32
323+
UsedBCQueueLen uint32
321324
}
322325

323326
func (macvlan *Macvlan) Attrs() *LinkAttrs {

‎link_linux.go‎

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1733,15 +1733,9 @@ func (h *Handle) linkModify(link Link, flags int) error {
17331733
data.AddRtAttr(nl.IFLA_IPVLAN_MODE, nl.Uint16Attr(uint16(link.Mode)))
17341734
data.AddRtAttr(nl.IFLA_IPVLAN_FLAG, nl.Uint16Attr(uint16(link.Flag)))
17351735
case *Macvlan:
1736-
if link.Mode != MACVLAN_MODE_DEFAULT {
1737-
data := linkInfo.AddRtAttr(nl.IFLA_INFO_DATA, nil)
1738-
data.AddRtAttr(nl.IFLA_MACVLAN_MODE, nl.Uint32Attr(macvlanModes[link.Mode]))
1739-
}
1736+
addMacvlanAttrs(link, linkInfo)
17401737
case *Macvtap:
1741-
if link.Mode != MACVLAN_MODE_DEFAULT {
1742-
data := linkInfo.AddRtAttr(nl.IFLA_INFO_DATA, nil)
1743-
data.AddRtAttr(nl.IFLA_MACVLAN_MODE, nl.Uint32Attr(macvlanModes[link.Mode]))
1744-
}
1738+
addMacvtapAttrs(link, linkInfo)
17451739
case *Geneve:
17461740
addGeneveAttrs(link, linkInfo)
17471741
case *Gretap:
@@ -2953,11 +2947,30 @@ func parseIPVtapData(link Link, data []syscall.NetlinkRouteAttr) {
29532947
}
29542948
}
29552949

2950+
func addMacvtapAttrs(macvtap *Macvtap, linkInfo *nl.RtAttr) {
2951+
addMacvlanAttrs(&macvtap.Macvlan, linkInfo)
2952+
}
2953+
29562954
func parseMacvtapData(link Link, data []syscall.NetlinkRouteAttr) {
29572955
macv := link.(*Macvtap)
29582956
parseMacvlanData(&macv.Macvlan, data)
29592957
}
29602958

2959+
func addMacvlanAttrs(macvlan *Macvlan, linkInfo *nl.RtAttr) {
2960+
var data *nl.RtAttr
2961+
2962+
if macvlan.Mode != MACVLAN_MODE_DEFAULT || macvlan.BCQueueLen > 0 {
2963+
data = linkInfo.AddRtAttr(nl.IFLA_INFO_DATA, nil)
2964+
}
2965+
2966+
if macvlan.Mode != MACVLAN_MODE_DEFAULT {
2967+
data.AddRtAttr(nl.IFLA_MACVLAN_MODE, nl.Uint32Attr(macvlanModes[macvlan.Mode]))
2968+
}
2969+
if macvlan.BCQueueLen > 0 {
2970+
data.AddRtAttr(nl.IFLA_MACVLAN_BC_QUEUE_LEN, nl.Uint32Attr(macvlan.BCQueueLen))
2971+
}
2972+
}
2973+
29612974
func parseMacvlanData(link Link, data []syscall.NetlinkRouteAttr) {
29622975
macv := link.(*Macvlan)
29632976
for _, datum := range data {
@@ -2985,6 +2998,10 @@ func parseMacvlanData(link Link, data []syscall.NetlinkRouteAttr) {
29852998
for _, macDatum := range macs {
29862999
macv.MACAddrs = append(macv.MACAddrs, net.HardwareAddr(macDatum.Value[0:6]))
29873000
}
3001+
case nl.IFLA_MACVLAN_BC_QUEUE_LEN:
3002+
macv.BCQueueLen = native.Uint32(datum.Value[0:4])
3003+
case nl.IFLA_MACVLAN_BC_QUEUE_LEN_USED:
3004+
macv.UsedBCQueueLen = native.Uint32(datum.Value[0:4])
29883005
}
29893006
}
29903007
}

‎link_test.go‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,16 @@ func testLinkAddDel(t *testing.T, link Link) {
201201
if macv.Mode != other.Mode {
202202
t.Fatalf("Got unexpected mode: %d, expected: %d", other.Mode, macv.Mode)
203203
}
204+
if other.BCQueueLen > 0 || other.UsedBCQueueLen > 0 {
205+
if other.UsedBCQueueLen < other.BCQueueLen {
206+
t.Fatalf("UsedBCQueueLen (%d) is smaller than BCQueueLen (%d)", other.UsedBCQueueLen, other.BCQueueLen)
207+
}
208+
}
209+
if macv.BCQueueLen > 0 {
210+
if macv.BCQueueLen != other.BCQueueLen {
211+
t.Fatalf("BCQueueLen not set correctly: %d, expected: %d", other.BCQueueLen, macv.BCQueueLen)
212+
}
213+
}
204214
}
205215

206216
if macv, ok := link.(*Macvtap); ok {
@@ -211,6 +221,16 @@ func testLinkAddDel(t *testing.T, link Link) {
211221
if macv.Mode != other.Mode {
212222
t.Fatalf("Got unexpected mode: %d, expected: %d", other.Mode, macv.Mode)
213223
}
224+
if other.BCQueueLen > 0 || other.UsedBCQueueLen > 0 {
225+
if other.UsedBCQueueLen < other.BCQueueLen {
226+
t.Fatalf("UsedBCQueueLen (%d) is smaller than BCQueueLen (%d)", other.UsedBCQueueLen, other.BCQueueLen)
227+
}
228+
}
229+
if macv.BCQueueLen > 0 {
230+
if macv.BCQueueLen != other.BCQueueLen {
231+
t.Fatalf("BCQueueLen not set correctly: %d, expected: %d", other.BCQueueLen, macv.BCQueueLen)
232+
}
233+
}
214234
}
215235

216236
if _, ok := link.(*Vti); ok {
@@ -916,6 +936,36 @@ func TestLinkAddDelMacvtap(t *testing.T) {
916936
}
917937
}
918938

939+
func TestLinkMacvBCQueueLen(t *testing.T) {
940+
minKernelRequired(t, 5, 11)
941+
942+
tearDown := setUpNetlinkTest(t)
943+
defer tearDown()
944+
945+
parent := &Dummy{LinkAttrs{Name: "foo"}}
946+
if err := LinkAdd(parent); err != nil {
947+
t.Fatal(err)
948+
}
949+
950+
testLinkAddDel(t, &Macvlan{
951+
LinkAttrs: LinkAttrs{Name: "bar", ParentIndex: parent.Attrs().Index},
952+
Mode: MACVLAN_MODE_PRIVATE,
953+
BCQueueLen: 10000,
954+
})
955+
956+
testLinkAddDel(t, &Macvtap{
957+
Macvlan: Macvlan{
958+
LinkAttrs: LinkAttrs{Name: "bar", ParentIndex: parent.Attrs().Index},
959+
Mode: MACVLAN_MODE_PRIVATE,
960+
BCQueueLen: 10000,
961+
},
962+
})
963+
964+
if err := LinkDel(parent); err != nil {
965+
t.Fatal(err)
966+
}
967+
}
968+
919969
func TestNetkitPeerNs(t *testing.T) {
920970
minKernelRequired(t, 6, 7)
921971
tearDown := setUpNetlinkTest(t)

‎nl/link_linux.go‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,9 @@ const (
144144
IFLA_MACVLAN_MACADDR
145145
IFLA_MACVLAN_MACADDR_DATA
146146
IFLA_MACVLAN_MACADDR_COUNT
147-
IFLA_MACVLAN_MAX = IFLA_MACVLAN_FLAGS
147+
IFLA_MACVLAN_BC_QUEUE_LEN
148+
IFLA_MACVLAN_BC_QUEUE_LEN_USED
149+
IFLA_MACVLAN_MAX = IFLA_MACVLAN_BC_QUEUE_LEN_USED
148150
)
149151

150152
const (

0 commit comments

Comments
 (0)