forked from florianl/go-tc
-
Notifications
You must be signed in to change notification settings - Fork 2
/
q_drr.go
50 lines (42 loc) · 1.06 KB
/
q_drr.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package tc
import (
"fmt"
"github.com/mdlayher/netlink"
)
const (
tcaDrrUnspec = iota
tcaDrrQuantum
)
// Drr contains attributes of the drr discipline
type Drr struct {
Quantum *uint32
}
// unmarshalDrr parses the Drr-encoded data and stores the result in the value pointed to by info.
func unmarshalDrr(data []byte, info *Drr) error {
ad, err := netlink.NewAttributeDecoder(data)
if err != nil {
return err
}
ad.ByteOrder = nativeEndian
for ad.Next() {
switch ad.Type() {
case tcaDrrQuantum:
info.Quantum = uint32Ptr(ad.Uint32())
default:
return fmt.Errorf("UnmarshalDrr()\t%d\n\t%v", ad.Type(), ad.Bytes())
}
}
return nil
}
// marshalDrr returns the binary encoding of Qfq
func marshalDrr(info *Drr) ([]byte, error) {
options := []tcOption{}
if info == nil {
return []byte{}, fmt.Errorf("Drr: %w", ErrNoArg)
}
// TODO: improve logic and check combinations
if info.Quantum != nil {
options = append(options, tcOption{Interpretation: vtUint32, Type: tcaDrrQuantum, Data: uint32Value(info.Quantum)})
}
return marshalAttributes(options)
}