Skip to content

Commit

Permalink
Scope 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 cadae61 commit 0685f31
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
20 changes: 16 additions & 4 deletions pkg/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,26 +170,38 @@ type Route struct {
MTU int
AdvMSS int
Priority int
Scope int
Scope *int
}

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

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

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,
Scope: r.Scope,
}

if r.Scope != nil {
scope := *r.Scope
route.Scope = &scope
}

return route
}

// Well known error codes
Expand Down Expand Up @@ -244,7 +256,7 @@ type route struct {
MTU int `json:"mtu,omitempty"`
AdvMSS int `json:"advmss,omitempty"`
Priority int `json:"priority,omitempty"`
Scope int `json:"scope,omitempty"`
Scope *int `json:"scope,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,
Scope: 253,
Scope: types040.Int(253),
}
})

Expand Down

0 comments on commit 0685f31

Please sign in to comment.