Skip to content

Commit

Permalink
extend m_mirred
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Lehner <dev@der-flo.net>
  • Loading branch information
florianl committed Dec 23, 2024
1 parent 50b1499 commit fb8dc4c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions m_mirred.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ const (
tcaMirredTm
tcaMirredParms
tcaMirredPad
tcaMirredBlockID
)

// Mirred represents policing attributes of various filters and classes
type Mirred struct {
Parms *MirredParam
Tm *Tcft
Parms *MirredParam
Tm *Tcft
BlockID *uint32
}

// MirredParam from include/uapi/linux/tc_act/tc_mirred.h
Expand Down Expand Up @@ -50,6 +52,8 @@ func unmarshalMirred(data []byte, info *Mirred) error {
info.Tm = tm
case tcaMirredPad:
// padding does not contain data, we just skip it
case tcaMirredBlockID:
info.BlockID = uint32Ptr(ad.Uint32())
default:
return fmt.Errorf("unmarshalMirred()\t%d\n\t%v", ad.Type(), ad.Bytes())
}
Expand All @@ -75,5 +79,8 @@ func marshalMirred(info *Mirred) ([]byte, error) {
}
options = append(options, tcOption{Interpretation: vtBytes, Type: tcaMirredParms, Data: data})
}
if info.BlockID != nil {
options = append(options, tcOption{Interpretation: vtUint32, Type: tcaMirredBlockID, Data: uint32Value(info.BlockID)})
}
return marshalAttributes(options)
}
2 changes: 1 addition & 1 deletion m_mirred_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func TestMirred(t *testing.T) {
err1 error
err2 error
}{
"simple": {val: Mirred{Parms: &MirredParam{Index: 42, Action: 1}}},
"all": {val: Mirred{Parms: &MirredParam{Index: 42, Action: 1}, BlockID: uint32Ptr(73)}},
"invalidArgument": {val: Mirred{Tm: &Tcft{Install: 1}}, err1: ErrNoArgAlter},
}
for name, testcase := range tests {
Expand Down

0 comments on commit fb8dc4c

Please sign in to comment.