Skip to content

Commit 845a737

Browse files
authored
Merge pull request #1068 from LionelJouin/scope
Add Scope property for routes
2 parents 06d9dec + 00576a2 commit 845a737

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

SPEC.md

+1
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,7 @@ Plugins must output a JSON object with the following keys upon a successful `ADD
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.
583583
- `table` (uint): The table to add the route to.
584+
- `scope` (uint): The scope of the destinations covered by the route prefix (global (0), link (253), host (254)).
584585
- `dns`: a dictionary consisting of DNS configuration information
585586
- `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.
586587
- `domain` (string): the local domain used for short hostname lookups.

pkg/types/types.go

+16-1
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ type Route struct {
171171
AdvMSS int
172172
Priority int
173173
Table *int
174+
Scope *int
174175
}
175176

176177
func (r *Route) String() string {
@@ -179,7 +180,12 @@ func (r *Route) String() string {
179180
table = fmt.Sprintf("%d", *r.Table)
180181
}
181182

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)
183+
scope := "<nil>"
184+
if r.Scope != nil {
185+
scope = fmt.Sprintf("%d", *r.Scope)
186+
}
187+
188+
return fmt.Sprintf("{Dst:%+v GW:%v MTU:%d AdvMSS:%d Priority:%d Table:%s Scope:%s}", r.Dst, r.GW, r.MTU, r.AdvMSS, r.Priority, table, scope)
183189
}
184190

185191
func (r *Route) Copy() *Route {
@@ -193,13 +199,19 @@ func (r *Route) Copy() *Route {
193199
MTU: r.MTU,
194200
AdvMSS: r.AdvMSS,
195201
Priority: r.Priority,
202+
Scope: r.Scope,
196203
}
197204

198205
if r.Table != nil {
199206
table := *r.Table
200207
route.Table = &table
201208
}
202209

210+
if r.Scope != nil {
211+
scope := *r.Scope
212+
route.Scope = &scope
213+
}
214+
203215
return route
204216
}
205217

@@ -256,6 +268,7 @@ type route struct {
256268
AdvMSS int `json:"advmss,omitempty"`
257269
Priority int `json:"priority,omitempty"`
258270
Table *int `json:"table,omitempty"`
271+
Scope *int `json:"scope,omitempty"`
259272
}
260273

261274
func (r *Route) UnmarshalJSON(data []byte) error {
@@ -270,6 +283,7 @@ func (r *Route) UnmarshalJSON(data []byte) error {
270283
r.AdvMSS = rt.AdvMSS
271284
r.Priority = rt.Priority
272285
r.Table = rt.Table
286+
r.Scope = rt.Scope
273287

274288
return nil
275289
}
@@ -282,6 +296,7 @@ func (r Route) MarshalJSON() ([]byte, error) {
282296
AdvMSS: r.AdvMSS,
283297
Priority: r.Priority,
284298
Table: r.Table,
299+
Scope: r.Scope,
285300
}
286301

287302
return json.Marshal(rt)

pkg/types/types_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,14 @@ var _ = Describe("Types", func() {
9393
AdvMSS: 1340,
9494
Priority: 100,
9595
Table: types040.Int(50),
96+
Scope: types040.Int(253),
9697
}
9798
})
9899

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

104105
var unmarshaled types.Route
105106
Expect(json.Unmarshal(jsonBytes, &unmarshaled)).To(Succeed())
@@ -115,7 +116,7 @@ var _ = Describe("Types", func() {
115116
})
116117

117118
It("formats as a string with a hex mask", func() {
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}`))
119+
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 Scope:253}`))
119120
})
120121
})
121122

0 commit comments

Comments
 (0)