From efffbeeef40b0bdc73e1e354629f71176439ac92 Mon Sep 17 00:00:00 2001 From: Alexander Lopintsev Date: Sat, 18 Nov 2023 20:32:24 +0300 Subject: [PATCH 1/2] Add route attributes - MTU, AdvMSS, Priority Signed-off-by: Alexander Lopintsev --- pkg/types/types.go | 32 ++++++++++++++++++++++++-------- pkg/types/types_test.go | 9 ++++++--- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/pkg/types/types.go b/pkg/types/types.go index 62ee7481..2c12d73b 100644 --- a/pkg/types/types.go +++ b/pkg/types/types.go @@ -129,8 +129,11 @@ func (d *DNS) Copy() *DNS { } type Route struct { - Dst net.IPNet - GW net.IP + Dst net.IPNet + GW net.IP + MTU int + AdvMSS int + Priority int } func (r *Route) String() string { @@ -143,8 +146,11 @@ func (r *Route) Copy() *Route { } return &Route{ - Dst: r.Dst, - GW: r.GW, + Dst: r.Dst, + GW: r.GW, + MTU: r.MTU, + AdvMSS: r.AdvMSS, + Priority: r.Priority, } } @@ -195,8 +201,11 @@ func (e *Error) Print() error { // JSON (un)marshallable types type route struct { - Dst IPNet `json:"dst"` - GW net.IP `json:"gw,omitempty"` + Dst IPNet `json:"dst"` + GW net.IP `json:"gw,omitempty"` + MTU int `json:"mtu,omitempty"` + AdvMSS int `json:"advmss,omitempty"` + Priority int `json:"priority,omitempty"` } func (r *Route) UnmarshalJSON(data []byte) error { @@ -207,13 +216,20 @@ func (r *Route) UnmarshalJSON(data []byte) error { r.Dst = net.IPNet(rt.Dst) r.GW = rt.GW + r.MTU = rt.MTU + r.AdvMSS = rt.AdvMSS + r.Priority = rt.Priority + return nil } func (r Route) MarshalJSON() ([]byte, error) { rt := route{ - Dst: IPNet(r.Dst), - GW: r.GW, + Dst: IPNet(r.Dst), + GW: r.GW, + MTU: r.MTU, + AdvMSS: r.AdvMSS, + Priority: r.Priority, } return json.Marshal(rt) diff --git a/pkg/types/types_test.go b/pkg/types/types_test.go index 4fed4a67..ee0a829c 100644 --- a/pkg/types/types_test.go +++ b/pkg/types/types_test.go @@ -87,14 +87,17 @@ var _ = Describe("Types", func() { IP: net.ParseIP("1.2.3.0"), Mask: net.CIDRMask(24, 32), }, - GW: net.ParseIP("1.2.3.1"), + GW: net.ParseIP("1.2.3.1"), + MTU: 1500, + AdvMSS: 1340, + Priority: 100, } }) It("marshals and unmarshals to JSON", func() { jsonBytes, err := json.Marshal(example) Expect(err).NotTo(HaveOccurred()) - Expect(jsonBytes).To(MatchJSON(`{ "dst": "1.2.3.0/24", "gw": "1.2.3.1" }`)) + Expect(jsonBytes).To(MatchJSON(`{ "dst": "1.2.3.0/24", "gw": "1.2.3.1", "mtu": 1500, "advmss": 1340, "priority": 100 }`)) var unmarshaled types.Route Expect(json.Unmarshal(jsonBytes, &unmarshaled)).To(Succeed()) @@ -110,7 +113,7 @@ var _ = Describe("Types", func() { }) It("formats as a string with a hex mask", func() { - Expect(example.String()).To(Equal(`{Dst:{IP:1.2.3.0 Mask:ffffff00} GW:1.2.3.1}`)) + Expect(example.String()).To(Equal(`{Dst:{IP:1.2.3.0 Mask:ffffff00} GW:1.2.3.1 MTU:1500 AdvMSS:1340 Priority:100}`)) }) }) From 4a0bccb249ba8ae378c30e6e6d617f865dce22ec Mon Sep 17 00:00:00 2001 From: Alexander Lopintsev Date: Tue, 28 Nov 2023 18:23:52 +0300 Subject: [PATCH 2/2] describe mtu, advmss, priority attributes of route object in specification Signed-off-by: Alexander Lopintsev --- SPEC.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/SPEC.md b/SPEC.md index 0fec14f1..4d1a8624 100644 --- a/SPEC.md +++ b/SPEC.md @@ -536,6 +536,9 @@ Plugins must output a JSON object with the following keys upon a successful `ADD - `routes`: Routes created by this attachment: - `dst`: The destination of the route, in CIDR notation - `gw`: The next hop address. If unset, a value in `gateway` in the `ips` array may be used. + - `mtu` (uint): The MTU (Maximum transmission unit) along the path to the destination. + - `advmss` (uint): The MSS (Maximal Segment Size) to advertise to these destinations when establishing TCP connections. + - `priority` (uint): The priority of route, lower is higher. - `dns`: a dictionary consisting of DNS configuration information - `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. - `domain` (string): the local domain used for short hostname lookups.