diff --git a/SPEC.md b/SPEC.md index ef3fe73a..a6235af2 100644 --- a/SPEC.md +++ b/SPEC.md @@ -580,6 +580,7 @@ Plugins must output a JSON object with the following keys upon a successful `ADD - `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. + - `table` (uint): The table to add the route to. - `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. diff --git a/pkg/types/types.go b/pkg/types/types.go index 58b57947..ea307e4a 100644 --- a/pkg/types/types.go +++ b/pkg/types/types.go @@ -170,10 +170,16 @@ type Route struct { MTU int AdvMSS int Priority int + Table *int } func (r *Route) String() string { - return fmt.Sprintf("%+v", *r) + table := "" + if r.Table != nil { + table = fmt.Sprintf("%d", *r.Table) + } + + 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) } func (r *Route) Copy() *Route { @@ -181,13 +187,20 @@ func (r *Route) Copy() *Route { return nil } - return &Route{ + route := &Route{ Dst: r.Dst, GW: r.GW, MTU: r.MTU, AdvMSS: r.AdvMSS, Priority: r.Priority, } + + if r.Table != nil { + table := *r.Table + route.Table = &table + } + + return route } // Well known error codes @@ -242,6 +255,7 @@ type route struct { MTU int `json:"mtu,omitempty"` AdvMSS int `json:"advmss,omitempty"` Priority int `json:"priority,omitempty"` + Table *int `json:"table,omitempty"` } func (r *Route) UnmarshalJSON(data []byte) error { @@ -255,6 +269,7 @@ func (r *Route) UnmarshalJSON(data []byte) error { r.MTU = rt.MTU r.AdvMSS = rt.AdvMSS r.Priority = rt.Priority + r.Table = rt.Table return nil } @@ -266,6 +281,7 @@ func (r Route) MarshalJSON() ([]byte, error) { MTU: r.MTU, AdvMSS: r.AdvMSS, Priority: r.Priority, + Table: r.Table, } return json.Marshal(rt) diff --git a/pkg/types/types_test.go b/pkg/types/types_test.go index 235f08cf..149c2bb0 100644 --- a/pkg/types/types_test.go +++ b/pkg/types/types_test.go @@ -22,6 +22,7 @@ import ( . "github.com/onsi/gomega" "github.com/containernetworking/cni/pkg/types" + types040 "github.com/containernetworking/cni/pkg/types/040" current "github.com/containernetworking/cni/pkg/types/100" ) @@ -91,13 +92,14 @@ var _ = Describe("Types", func() { MTU: 1500, AdvMSS: 1340, Priority: 100, + Table: types040.Int(50), } }) 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", "mtu": 1500, "advmss": 1340, "priority": 100 }`)) + Expect(jsonBytes).To(MatchJSON(`{ "dst": "1.2.3.0/24", "gw": "1.2.3.1", "mtu": 1500, "advmss": 1340, "priority": 100, "table": 50 }`)) var unmarshaled types.Route Expect(json.Unmarshal(jsonBytes, &unmarshaled)).To(Succeed()) @@ -113,7 +115,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 MTU:1500 AdvMSS:1340 Priority:100}`)) + 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}`)) }) })