Skip to content

Commit

Permalink
Table ID property as int pointer
Browse files Browse the repository at this point in the history
Signed-off-by: Lionel Jouin <lionel.jouin@est.tech>
  • Loading branch information
LionelJouin committed Feb 19, 2024
1 parent 3c4079b commit 94fc2b1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
21 changes: 16 additions & 5 deletions pkg/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,26 +170,37 @@ type Route struct {
MTU int
AdvMSS int
Priority int
Table int
Table *int
}

func (r *Route) String() string {
return fmt.Sprintf("%+v", *r)
table := "<nil>"
if r.Table != nil {
table = fmt.Sprintf("%d", *r.Table)
}

return fmt.Sprintf("{Dst:%+v GW:%v MTU:%d AdvMSS:%d Priority:%d Table:%s}", r.Dst, r.GW, r.MTU, r.AdvMSS, r.Priority, table)
}

func (r *Route) Copy() *Route {
if r == nil {
return nil
}

return &Route{
route := &Route{
Dst: r.Dst,
GW: r.GW,
MTU: r.MTU,
AdvMSS: r.AdvMSS,
Priority: r.Priority,
Table: r.Table,
}

if r.Table != nil {
table := *r.Table
route.Table = &table
}

return route
}

// Well known error codes
Expand Down Expand Up @@ -244,7 +255,7 @@ type route struct {
MTU int `json:"mtu,omitempty"`
AdvMSS int `json:"advmss,omitempty"`
Priority int `json:"priority,omitempty"`
Table int `json:"table,omitempty"`
Table *int `json:"table,omitempty"`
}

func (r *Route) UnmarshalJSON(data []byte) error {
Expand Down
3 changes: 2 additions & 1 deletion pkg/types/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
. "github.com/onsi/gomega"

"github.com/containernetworking/cni/pkg/types"
types040 "github.com/containernetworking/cni/pkg/types/040"
current "github.com/containernetworking/cni/pkg/types/100"
)

Expand Down Expand Up @@ -91,7 +92,7 @@ var _ = Describe("Types", func() {
MTU: 1500,
AdvMSS: 1340,
Priority: 100,
Table: 50,
Table: types040.Int(50),
}
})

Expand Down

0 comments on commit 94fc2b1

Please sign in to comment.