Skip to content

Commit 7f2b136

Browse files
e0neaboch
authored andcommitted
qdisc ingress_block support
1 parent e0988fd commit 7f2b136

File tree

4 files changed

+29
-7
lines changed

4 files changed

+29
-7
lines changed

nl/tc_linux.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,14 @@ const (
4242
TCA_FCNT
4343
TCA_STATS2
4444
TCA_STAB
45-
TCA_MAX = TCA_STAB
45+
TCA_PAD
46+
TCA_DUMP_INVISIBLE
47+
TCA_CHAIN
48+
TCA_HW_OFFLOAD
49+
TCA_INGRESS_BLOCK
50+
TCA_EGRESS_BLOCK
51+
TCA_DUMP_FLAGS
52+
TCA_MAX = TCA_DUMP_FLAGS
4653
)
4754

4855
const (

qdisc.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ type Qdisc interface {
3232
// has a handle, a parent and a refcnt. The root qdisc of a device should
3333
// have parent == HANDLE_ROOT.
3434
type QdiscAttrs struct {
35-
LinkIndex int
36-
Handle uint32
37-
Parent uint32
38-
Refcnt uint32 // read only
35+
LinkIndex int
36+
Handle uint32
37+
Parent uint32
38+
Refcnt uint32 // read only
39+
IngressBlock *uint32
3940
}
4041

4142
func (q QdiscAttrs) String() string {

qdisc_linux.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ func (h *Handle) qdiscModify(cmd, flags int, qdisc Qdisc) error {
159159
func qdiscPayload(req *nl.NetlinkRequest, qdisc Qdisc) error {
160160

161161
req.AddData(nl.NewRtAttr(nl.TCA_KIND, nl.ZeroTerminated(qdisc.Type())))
162+
if qdisc.Attrs().IngressBlock != nil {
163+
req.AddData(nl.NewRtAttr(nl.TCA_INGRESS_BLOCK, nl.Uint32Attr(*qdisc.Attrs().IngressBlock)))
164+
}
162165

163166
options := nl.NewRtAttr(nl.TCA_OPTIONS, nil)
164167

@@ -448,6 +451,10 @@ func (h *Handle) QdiscList(link Link) ([]Qdisc, error) {
448451

449452
// no options for ingress
450453
}
454+
case nl.TCA_INGRESS_BLOCK:
455+
ingressBlock := new(uint32)
456+
*ingressBlock = native.Uint32(attr.Value)
457+
base.IngressBlock = ingressBlock
451458
}
452459
}
453460
*qdisc.Attrs() = base

qdisc_test.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build linux
12
// +build linux
23

34
package netlink
@@ -590,10 +591,13 @@ func TestIngressAddDel(t *testing.T) {
590591
if err != nil {
591592
t.Fatal(err)
592593
}
594+
ingressBlock := new(uint32)
595+
*ingressBlock = 8
593596
qdisc := &Ingress{
594597
QdiscAttrs: QdiscAttrs{
595-
LinkIndex: link.Attrs().Index,
596-
Parent: HANDLE_INGRESS,
598+
LinkIndex: link.Attrs().Index,
599+
Parent: HANDLE_INGRESS,
600+
IngressBlock: ingressBlock,
597601
},
598602
}
599603
err = QdiscAdd(qdisc)
@@ -607,6 +611,9 @@ func TestIngressAddDel(t *testing.T) {
607611
if len(qdiscs) != 1 {
608612
t.Fatal("Failed to add qdisc")
609613
}
614+
if *qdiscs[0].Attrs().IngressBlock != *ingressBlock {
615+
t.Fatal("IngressBlock does not match")
616+
}
610617
if err = QdiscDel(qdisc); err != nil {
611618
t.Fatal(err)
612619
}

0 commit comments

Comments
 (0)