[qdisc] move building payload i its own function

This commit is contained in:
chantra 2015-11-12 09:42:26 -05:00
parent b530ef5ad1
commit e1c5c4e664
1 changed files with 13 additions and 3 deletions

View File

@ -57,6 +57,17 @@ func qdiscModify(qdisc Qdisc, flags int) error {
Parent: base.Parent,
}
req.AddData(msg)
if err := qdiscPayload(req, qdisc); err != nil {
return err
}
_, err := req.Execute(syscall.NETLINK_ROUTE, 0)
return err
}
func qdiscPayload(req *nl.NetlinkRequest, qdisc Qdisc) error {
req.AddData(nl.NewRtAttr(nl.TCA_KIND, nl.ZeroTerminated(qdisc.Type())))
options := nl.NewRtAttr(nl.TCA_OPTIONS, nil)
@ -117,14 +128,13 @@ func qdiscModify(qdisc Qdisc, flags int) error {
}
} else if _, ok := qdisc.(*Ingress); ok {
// ingress filters must use the proper handle
if msg.Parent != HANDLE_INGRESS {
if qdisc.Attrs().Parent != HANDLE_INGRESS {
return fmt.Errorf("Ingress filters must set Parent to HANDLE_INGRESS")
}
}
req.AddData(options)
_, err := req.Execute(syscall.NETLINK_ROUTE, 0)
return err
return nil
}
// QdiscList gets a list of qdiscs in the system.