Skip to content

Commit 610a79b

Browse files
committed
add OffloadHorizon
Signed-off-by: Florian Lehner <[email protected]>
1 parent ff2cd3c commit 610a79b

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

q_fq.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const (
2727
tcaFqHorizonDrop
2828
tcaFqPrioMap
2929
tcaFqWeights
30+
tcaFqOffloadHorizon
3031
)
3132

3233
// FqPrioQopt according to tc_prio_qopt in /include/uapi/linux/pkt_sched.h
@@ -54,6 +55,7 @@ type Fq struct {
5455
HorizonDrop *uint8
5556
PrioMap *FqPrioQopt
5657
Weights *[]int32
58+
OffloadHorizon *uint32
5759
}
5860

5961
// unmarshalFq parses the Fq-encoded data and stores the result in the value pointed to by info.
@@ -62,7 +64,6 @@ func unmarshalFq(data []byte, info *Fq) error {
6264
if err != nil {
6365
return err
6466
}
65-
var multiError error
6667
for ad.Next() {
6768
switch ad.Type() {
6869
case tcaFqPLimit:
@@ -97,21 +98,21 @@ func unmarshalFq(data []byte, info *Fq) error {
9798
info.HorizonDrop = uint8Ptr(ad.Uint8())
9899
case tcaFqPrioMap:
99100
priomap := &FqPrioQopt{}
100-
err := unmarshalStruct(ad.Bytes(), priomap)
101-
multiError = concatError(multiError, err)
101+
err = unmarshalStruct(ad.Bytes(), priomap)
102102
info.PrioMap = priomap
103103
case tcaFqWeights:
104104
size := len(ad.Bytes()) / 4
105105
weights := make([]int32, size)
106106
reader := bytes.NewReader(ad.Bytes())
107-
err := binary.Read(reader, nativeEndian, weights)
108-
multiError = concatError(multiError, err)
107+
err = binary.Read(reader, nativeEndian, weights)
109108
info.Weights = &weights
109+
case tcaFqOffloadHorizon:
110+
info.OffloadHorizon = uint32Ptr(ad.Uint32())
110111
default:
111112
return fmt.Errorf("unmarshalFq()\t%d\n\t%v", ad.Type(), ad.Bytes())
112113
}
113114
}
114-
return concatError(multiError, ad.Err())
115+
return concatError(err, ad.Err())
115116
}
116117

117118
// marshalFq returns the binary encoding of Fq
@@ -180,6 +181,9 @@ func marshalFq(info *Fq) ([]byte, error) {
180181
multiError = concatError(multiError, err)
181182
options = append(options, tcOption{Interpretation: vtBytes, Type: tcaFqWeights, Data: buf.Bytes()})
182183
}
184+
if info.OffloadHorizon != nil {
185+
options = append(options, tcOption{Interpretation: vtUint32, Type: tcaFqOffloadHorizon, Data: uint32Value(info.OffloadHorizon)})
186+
}
183187

184188
if multiError != nil {
185189
return []byte{}, multiError

q_fq_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ func TestFq(t *testing.T) {
5050
Bands: 3,
5151
PrioMap: [16]uint8{1, 2, 2, 2, 1, 2, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1},
5252
},
53-
Weights: &weights,
53+
Weights: &weights,
54+
OffloadHorizon: uint32Ptr(73),
5455
},
5556
},
5657
}
@@ -84,4 +85,10 @@ func TestFq(t *testing.T) {
8485
t.Fatalf("unexpected error: %v", err)
8586
}
8687
})
88+
t.Run("unmarshalFq(0x0)", func(t *testing.T) {
89+
err := unmarshalFq([]byte{0x0}, nil)
90+
if err == nil {
91+
t.Fatalf("expected error but got none")
92+
}
93+
})
8794
}

0 commit comments

Comments
 (0)