Skip to content

Commit 06d9dec

Browse files
authored
Merge pull request #1062 from LionelJouin/tableid
Add table ID property for routes
2 parents c822f13 + d9f3a7b commit 06d9dec

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

SPEC.md

+1
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,7 @@ Plugins must output a JSON object with the following keys upon a successful `ADD
580580
- `mtu` (uint): The MTU (Maximum transmission unit) along the path to the destination.
581581
- `advmss` (uint): The MSS (Maximal Segment Size) to advertise to these destinations when establishing TCP connections.
582582
- `priority` (uint): The priority of route, lower is higher.
583+
- `table` (uint): The table to add the route to.
583584
- `dns`: a dictionary consisting of DNS configuration information
584585
- `nameservers` (list of strings): list of a priority-ordered list of DNS nameservers that this network is aware of. Each entry in the list is a string containing either an IPv4 or an IPv6 address.
585586
- `domain` (string): the local domain used for short hostname lookups.

pkg/types/types.go

+18-2
Original file line numberDiff line numberDiff line change
@@ -170,24 +170,37 @@ type Route struct {
170170
MTU int
171171
AdvMSS int
172172
Priority int
173+
Table *int
173174
}
174175

175176
func (r *Route) String() string {
176-
return fmt.Sprintf("%+v", *r)
177+
table := "<nil>"
178+
if r.Table != nil {
179+
table = fmt.Sprintf("%d", *r.Table)
180+
}
181+
182+
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)
177183
}
178184

179185
func (r *Route) Copy() *Route {
180186
if r == nil {
181187
return nil
182188
}
183189

184-
return &Route{
190+
route := &Route{
185191
Dst: r.Dst,
186192
GW: r.GW,
187193
MTU: r.MTU,
188194
AdvMSS: r.AdvMSS,
189195
Priority: r.Priority,
190196
}
197+
198+
if r.Table != nil {
199+
table := *r.Table
200+
route.Table = &table
201+
}
202+
203+
return route
191204
}
192205

193206
// Well known error codes
@@ -242,6 +255,7 @@ type route struct {
242255
MTU int `json:"mtu,omitempty"`
243256
AdvMSS int `json:"advmss,omitempty"`
244257
Priority int `json:"priority,omitempty"`
258+
Table *int `json:"table,omitempty"`
245259
}
246260

247261
func (r *Route) UnmarshalJSON(data []byte) error {
@@ -255,6 +269,7 @@ func (r *Route) UnmarshalJSON(data []byte) error {
255269
r.MTU = rt.MTU
256270
r.AdvMSS = rt.AdvMSS
257271
r.Priority = rt.Priority
272+
r.Table = rt.Table
258273

259274
return nil
260275
}
@@ -266,6 +281,7 @@ func (r Route) MarshalJSON() ([]byte, error) {
266281
MTU: r.MTU,
267282
AdvMSS: r.AdvMSS,
268283
Priority: r.Priority,
284+
Table: r.Table,
269285
}
270286

271287
return json.Marshal(rt)

pkg/types/types_test.go

+4-2
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,13 +92,14 @@ var _ = Describe("Types", func() {
9192
MTU: 1500,
9293
AdvMSS: 1340,
9394
Priority: 100,
95+
Table: types040.Int(50),
9496
}
9597
})
9698

9799
It("marshals and unmarshals to JSON", func() {
98100
jsonBytes, err := json.Marshal(example)
99101
Expect(err).NotTo(HaveOccurred())
100-
Expect(jsonBytes).To(MatchJSON(`{ "dst": "1.2.3.0/24", "gw": "1.2.3.1", "mtu": 1500, "advmss": 1340, "priority": 100 }`))
102+
Expect(jsonBytes).To(MatchJSON(`{ "dst": "1.2.3.0/24", "gw": "1.2.3.1", "mtu": 1500, "advmss": 1340, "priority": 100, "table": 50 }`))
101103

102104
var unmarshaled types.Route
103105
Expect(json.Unmarshal(jsonBytes, &unmarshaled)).To(Succeed())
@@ -113,7 +115,7 @@ var _ = Describe("Types", func() {
113115
})
114116

115117
It("formats as a string with a hex mask", func() {
116-
Expect(example.String()).To(Equal(`{Dst:{IP:1.2.3.0 Mask:ffffff00} GW:1.2.3.1 MTU:1500 AdvMSS:1340 Priority:100}`))
118+
Expect(example.String()).To(Equal(`{Dst:{IP:1.2.3.0 Mask:ffffff00} GW:1.2.3.1 MTU:1500 AdvMSS:1340 Priority:100 Table:50}`))
117119
})
118120
})
119121

0 commit comments

Comments
 (0)