Skip to content

Commit 0685f31

Browse files
committed
Scope property as int pointer
Signed-off-by: Lionel Jouin <[email protected]>
1 parent cadae61 commit 0685f31

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

pkg/types/types.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,26 +170,38 @@ type Route struct {
170170
MTU int
171171
AdvMSS int
172172
Priority int
173-
Scope int
173+
Scope *int
174174
}
175175

176176
func (r *Route) String() string {
177-
return fmt.Sprintf("%+v", *r)
177+
scope := "<nil>"
178+
if r.Scope != nil {
179+
scope = fmt.Sprintf("%d", *r.Scope)
180+
}
181+
182+
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)
178183
}
179184

180185
func (r *Route) Copy() *Route {
181186
if r == nil {
182187
return nil
183188
}
184189

185-
return &Route{
190+
route := &Route{
186191
Dst: r.Dst,
187192
GW: r.GW,
188193
MTU: r.MTU,
189194
AdvMSS: r.AdvMSS,
190195
Priority: r.Priority,
191196
Scope: r.Scope,
192197
}
198+
199+
if r.Scope != nil {
200+
scope := *r.Scope
201+
route.Scope = &scope
202+
}
203+
204+
return route
193205
}
194206

195207
// Well known error codes
@@ -244,7 +256,7 @@ type route struct {
244256
MTU int `json:"mtu,omitempty"`
245257
AdvMSS int `json:"advmss,omitempty"`
246258
Priority int `json:"priority,omitempty"`
247-
Scope int `json:"scope,omitempty"`
259+
Scope *int `json:"scope,omitempty"`
248260
}
249261

250262
func (r *Route) UnmarshalJSON(data []byte) error {

pkg/types/types_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
. "github.com/onsi/gomega"
2323

2424
"github.com/containernetworking/cni/pkg/types"
25+
types040 "github.com/containernetworking/cni/pkg/types/040"
2526
current "github.com/containernetworking/cni/pkg/types/100"
2627
)
2728

@@ -91,7 +92,7 @@ var _ = Describe("Types", func() {
9192
MTU: 1500,
9293
AdvMSS: 1340,
9394
Priority: 100,
94-
Scope: 253,
95+
Scope: types040.Int(253),
9596
}
9697
})
9798

0 commit comments

Comments
 (0)