qdisc ingress_block support

This commit is contained in:
Ivan Kolodyazhny 2022-08-23 12:42:50 +03:00 committed by Alessandro Boch
parent e0988fd129
commit 7f2b136d34
4 changed files with 29 additions and 7 deletions

View File

@ -42,7 +42,14 @@ const (
TCA_FCNT
TCA_STATS2
TCA_STAB
TCA_MAX = TCA_STAB
TCA_PAD
TCA_DUMP_INVISIBLE
TCA_CHAIN
TCA_HW_OFFLOAD
TCA_INGRESS_BLOCK
TCA_EGRESS_BLOCK
TCA_DUMP_FLAGS
TCA_MAX = TCA_DUMP_FLAGS
)
const (

View File

@ -32,10 +32,11 @@ type Qdisc interface {
// has a handle, a parent and a refcnt. The root qdisc of a device should
// have parent == HANDLE_ROOT.
type QdiscAttrs struct {
LinkIndex int
Handle uint32
Parent uint32
Refcnt uint32 // read only
LinkIndex int
Handle uint32
Parent uint32
Refcnt uint32 // read only
IngressBlock *uint32
}
func (q QdiscAttrs) String() string {

View File

@ -159,6 +159,9 @@ func (h *Handle) qdiscModify(cmd, flags int, qdisc Qdisc) error {
func qdiscPayload(req *nl.NetlinkRequest, qdisc Qdisc) error {
req.AddData(nl.NewRtAttr(nl.TCA_KIND, nl.ZeroTerminated(qdisc.Type())))
if qdisc.Attrs().IngressBlock != nil {
req.AddData(nl.NewRtAttr(nl.TCA_INGRESS_BLOCK, nl.Uint32Attr(*qdisc.Attrs().IngressBlock)))
}
options := nl.NewRtAttr(nl.TCA_OPTIONS, nil)
@ -448,6 +451,10 @@ func (h *Handle) QdiscList(link Link) ([]Qdisc, error) {
// no options for ingress
}
case nl.TCA_INGRESS_BLOCK:
ingressBlock := new(uint32)
*ingressBlock = native.Uint32(attr.Value)
base.IngressBlock = ingressBlock
}
}
*qdisc.Attrs() = base

View File

@ -1,3 +1,4 @@
//go:build linux
// +build linux
package netlink
@ -590,10 +591,13 @@ func TestIngressAddDel(t *testing.T) {
if err != nil {
t.Fatal(err)
}
ingressBlock := new(uint32)
*ingressBlock = 8
qdisc := &Ingress{
QdiscAttrs: QdiscAttrs{
LinkIndex: link.Attrs().Index,
Parent: HANDLE_INGRESS,
LinkIndex: link.Attrs().Index,
Parent: HANDLE_INGRESS,
IngressBlock: ingressBlock,
},
}
err = QdiscAdd(qdisc)
@ -607,6 +611,9 @@ func TestIngressAddDel(t *testing.T) {
if len(qdiscs) != 1 {
t.Fatal("Failed to add qdisc")
}
if *qdiscs[0].Attrs().IngressBlock != *ingressBlock {
t.Fatal("IngressBlock does not match")
}
if err = QdiscDel(qdisc); err != nil {
t.Fatal(err)
}