Skip to content

Commit 7cdb02a

Browse files
committed
Add Scope property for routes
Fixes: #598 Signed-off-by: Lionel Jouin <[email protected]>
1 parent b62753a commit 7cdb02a

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

SPEC.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,7 @@ Plugins must output a JSON object with the following keys upon a successful `ADD
578578
- `mtu` (uint): The MTU (Maximum transmission unit) along the path to the destination.
579579
- `advmss` (uint): The MSS (Maximal Segment Size) to advertise to these destinations when establishing TCP connections.
580580
- `priority` (uint): The priority of route, lower is higher.
581+
- `scope` (uint): The scope of the destinations covered by the route prefix (global (0), link (253), host (254)).
581582
- `dns`: a dictionary consisting of DNS configuration information
582583
- `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.
583584
- `domain` (string): the local domain used for short hostname lookups.

pkg/types/types.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ type Route struct {
170170
MTU int
171171
AdvMSS int
172172
Priority int
173+
Scope int
173174
}
174175

175176
func (r *Route) String() string {
@@ -182,11 +183,11 @@ func (r *Route) Copy() *Route {
182183
}
183184

184185
return &Route{
185-
Dst: r.Dst,
186-
GW: r.GW,
187-
MTU: r.MTU,
188-
AdvMSS: r.AdvMSS,
189-
Priority: r.Priority,
186+
Dst: r.Dst,
187+
GW: r.GW,
188+
MTU: r.MTU,
189+
AdvMSS: r.AdvMSS,
190+
Scope: r.Scope,
190191
}
191192
}
192193

@@ -242,6 +243,7 @@ type route struct {
242243
MTU int `json:"mtu,omitempty"`
243244
AdvMSS int `json:"advmss,omitempty"`
244245
Priority int `json:"priority,omitempty"`
246+
Scope int `json:"scope,omitempty"`
245247
}
246248

247249
func (r *Route) UnmarshalJSON(data []byte) error {
@@ -255,6 +257,7 @@ func (r *Route) UnmarshalJSON(data []byte) error {
255257
r.MTU = rt.MTU
256258
r.AdvMSS = rt.AdvMSS
257259
r.Priority = rt.Priority
260+
r.Scope = rt.Scope
258261

259262
return nil
260263
}
@@ -266,6 +269,7 @@ func (r Route) MarshalJSON() ([]byte, error) {
266269
MTU: r.MTU,
267270
AdvMSS: r.AdvMSS,
268271
Priority: r.Priority,
272+
Scope: r.Scope,
269273
}
270274

271275
return json.Marshal(rt)

pkg/types/types_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,14 @@ var _ = Describe("Types", func() {
9191
MTU: 1500,
9292
AdvMSS: 1340,
9393
Priority: 100,
94+
Scope: 253,
9495
}
9596
})
9697

9798
It("marshals and unmarshals to JSON", func() {
9899
jsonBytes, err := json.Marshal(example)
99100
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 }`))
101+
Expect(jsonBytes).To(MatchJSON(`{ "dst": "1.2.3.0/24", "gw": "1.2.3.1", "mtu": 1500, "advmss": 1340, "priority": 100, "scope": 253 }`))
101102

102103
var unmarshaled types.Route
103104
Expect(json.Unmarshal(jsonBytes, &unmarshaled)).To(Succeed())
@@ -113,7 +114,7 @@ var _ = Describe("Types", func() {
113114
})
114115

115116
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}`))
117+
Expect(example.String()).To(Equal(`{Dst:{IP:1.2.3.0 Mask:ffffff00} GW:1.2.3.1 MTU:1500 AdvMSS:1340 Priority:100 Scope:253}`))
117118
})
118119
})
119120

0 commit comments

Comments
 (0)