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_FCNT
TCA_STATS2 TCA_STATS2
TCA_STAB 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 ( const (

View File

@ -36,6 +36,7 @@ type QdiscAttrs struct {
Handle uint32 Handle uint32
Parent uint32 Parent uint32
Refcnt uint32 // read only Refcnt uint32 // read only
IngressBlock *uint32
} }
func (q QdiscAttrs) String() string { 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 { func qdiscPayload(req *nl.NetlinkRequest, qdisc Qdisc) error {
req.AddData(nl.NewRtAttr(nl.TCA_KIND, nl.ZeroTerminated(qdisc.Type()))) 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) options := nl.NewRtAttr(nl.TCA_OPTIONS, nil)
@ -448,6 +451,10 @@ func (h *Handle) QdiscList(link Link) ([]Qdisc, error) {
// no options for ingress // no options for ingress
} }
case nl.TCA_INGRESS_BLOCK:
ingressBlock := new(uint32)
*ingressBlock = native.Uint32(attr.Value)
base.IngressBlock = ingressBlock
} }
} }
*qdisc.Attrs() = base *qdisc.Attrs() = base

View File

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