Skip to content

Commit e931118

Browse files
author
Alexander Lopintsev
committed
Add route attributes - MTU, AdvMSS, Priority
Signed-off-by: Alexander Lopintsev <[email protected]>
1 parent cf9ca9e commit e931118

File tree

2 files changed

+30
-11
lines changed

2 files changed

+30
-11
lines changed

pkg/types/types.go

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,11 @@ func (d *DNS) Copy() *DNS {
129129
}
130130

131131
type Route struct {
132-
Dst net.IPNet
133-
GW net.IP
132+
Dst net.IPNet
133+
GW net.IP
134+
MTU int
135+
AdvMSS int
136+
Priority int
134137
}
135138

136139
func (r *Route) String() string {
@@ -143,8 +146,11 @@ func (r *Route) Copy() *Route {
143146
}
144147

145148
return &Route{
146-
Dst: r.Dst,
147-
GW: r.GW,
149+
Dst: r.Dst,
150+
GW: r.GW,
151+
MTU: r.MTU,
152+
AdvMSS: r.AdvMSS,
153+
Priority: r.Priority,
148154
}
149155
}
150156

@@ -195,8 +201,11 @@ func (e *Error) Print() error {
195201

196202
// JSON (un)marshallable types
197203
type route struct {
198-
Dst IPNet `json:"dst"`
199-
GW net.IP `json:"gw,omitempty"`
204+
Dst IPNet `json:"dst"`
205+
GW net.IP `json:"gw,omitempty"`
206+
MTU int `json:"mtu,omitempty"`
207+
AdvMSS int `json:"advmss,omitempty"`
208+
Priority int `json:"priority,omitempty"`
200209
}
201210

202211
func (r *Route) UnmarshalJSON(data []byte) error {
@@ -207,13 +216,20 @@ func (r *Route) UnmarshalJSON(data []byte) error {
207216

208217
r.Dst = net.IPNet(rt.Dst)
209218
r.GW = rt.GW
219+
r.MTU = rt.MTU
220+
r.AdvMSS = rt.AdvMSS
221+
r.Priority = rt.Priority
222+
210223
return nil
211224
}
212225

213226
func (r Route) MarshalJSON() ([]byte, error) {
214227
rt := route{
215-
Dst: IPNet(r.Dst),
216-
GW: r.GW,
228+
Dst: IPNet(r.Dst),
229+
GW: r.GW,
230+
MTU: r.MTU,
231+
AdvMSS: r.AdvMSS,
232+
Priority: r.Priority,
217233
}
218234

219235
return json.Marshal(rt)

pkg/types/types_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,17 @@ var _ = Describe("Types", func() {
8787
IP: net.ParseIP("1.2.3.0"),
8888
Mask: net.CIDRMask(24, 32),
8989
},
90-
GW: net.ParseIP("1.2.3.1"),
90+
GW: net.ParseIP("1.2.3.1"),
91+
MTU: 1500,
92+
AdvMSS: 1340,
93+
Priority: 100,
9194
}
9295
})
9396

9497
It("marshals and unmarshals to JSON", func() {
9598
jsonBytes, err := json.Marshal(example)
9699
Expect(err).NotTo(HaveOccurred())
97-
Expect(jsonBytes).To(MatchJSON(`{ "dst": "1.2.3.0/24", "gw": "1.2.3.1" }`))
100+
Expect(jsonBytes).To(MatchJSON(`{ "dst": "1.2.3.0/24", "gw": "1.2.3.1", "mtu": 1500, "advmss": 1340, "priority": 100 }`))
98101

99102
var unmarshaled types.Route
100103
Expect(json.Unmarshal(jsonBytes, &unmarshaled)).To(Succeed())
@@ -110,7 +113,7 @@ var _ = Describe("Types", func() {
110113
})
111114

112115
It("formats as a string with a hex mask", func() {
113-
Expect(example.String()).To(Equal(`{Dst:{IP:1.2.3.0 Mask:ffffff00} GW:1.2.3.1}`))
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}`))
114117
})
115118
})
116119

0 commit comments

Comments
 (0)