Skip to content

Commit 9043a45

Browse files
datapath/tables: Add fields to routes
The desired routes we will have for route reconciliation have the MTU and Type fields which the routing table currently does not store. In order to be able to compare observed and desired routes, add these fields to the observed route objects. Also add string methods for the scope and type field to allow for better human readable table output. Signed-off-by: Dylan Reimerink <dylan.reimerink@isovalent.com>
1 parent c50b0ba commit 9043a45

File tree

5 files changed

+125
-33
lines changed

5 files changed

+125
-33
lines changed

pkg/datapath/linux/devices_controller.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,9 +475,11 @@ func (dc *devicesController) processBatch(txn statedb.WriteTxn, batch map[int][]
475475
r := tables.Route{
476476
Table: tables.RouteTable(u.Table),
477477
LinkIndex: index,
478-
Scope: uint8(u.Scope),
478+
Type: tables.RouteType(u.Route.Type),
479+
Scope: tables.RouteScope(u.Scope),
479480
Dst: ipnetToPrefix(u.Family, u.Dst),
480481
Priority: u.Priority,
482+
MTU: u.MTU,
481483
}
482484
r.Src, _ = netip.AddrFromSlice(u.Src)
483485
r.Gw, _ = netip.AddrFromSlice(u.Gw)
@@ -500,6 +502,7 @@ func (dc *devicesController) processBatch(txn statedb.WriteTxn, batch map[int][]
500502
)
501503
}
502504
}
505+
503506
case netlink.NeighUpdate:
504507
if dc.deadLinkIndexes.Has(u.LinkIndex) {
505508
// Ignore neighbor updates for a device that has been removed
@@ -576,7 +579,6 @@ func (dc *devicesController) processBatch(txn statedb.WriteTxn, batch map[int][]
576579
for r := range routes {
577580
dc.params.RouteTable.Delete(txn, r)
578581
}
579-
580582
// Remove all neighbors for the device. For a deleted device netlink does not
581583
// always send complete set of neighbor delete messages.
582584
neighbors := dc.params.NeighborTable.List(txn, tables.NeighborLinkIndex.Query(d.Index))

pkg/datapath/linux/testdata/device-controller-tables.txtar

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -97,39 +97,39 @@ Destination Source Gateway LinkIndex Table Scope Priority
9797

9898
-- routes_dummy0.table --
9999
Destination Source Gateway Table Scope Priority
100-
192.168.0.1/32 192.168.0.1 255 254 0
100+
192.168.0.1/32 192.168.0.1 local host 0
101101

102102
-- routes_dummy01.table --
103-
Destination Source Gateway Table Scope Priority
104-
0.0.0.0/0 192.168.1.254 254 0 0
105-
192.168.1.0/24 192.168.1.1 254 253 0
106-
192.168.1.253/32 254 253 0
107-
192.168.1.254/32 254 253 0
108-
192.168.0.1/32 192.168.0.1 255 254 0
109-
192.168.1.1/32 192.168.1.1 255 254 0
110-
192.168.1.2/32 192.168.1.1 255 254 0
111-
192.168.1.255/32 192.168.1.1 255 253 0
112-
ff00::/8 255 0 256
103+
Destination Source Gateway Table Scope Priority
104+
0.0.0.0/0 192.168.1.254 main universe 0
105+
192.168.1.0/24 192.168.1.1 main link 0
106+
192.168.1.253/32 main link 0
107+
192.168.1.254/32 main link 0
108+
192.168.0.1/32 192.168.0.1 local host 0
109+
192.168.1.1/32 192.168.1.1 local host 0
110+
192.168.1.2/32 192.168.1.1 local host 0
111+
192.168.1.255/32 192.168.1.1 local link 0
112+
ff00::/8 local universe 256
113113

114114
-- routes_table254_link3_254.table --
115115
Destination Source Gateway Table Scope Priority
116-
192.168.1.254/32 254 253
116+
192.168.1.254/32 main link
117117
-- routes_table254_link3_all.table --
118-
Destination Source Gateway Table Scope Priority
119-
0.0.0.0/0 192.168.1.254 254 0 0
120-
192.168.1.0/24 192.168.1.1 254 253 0
121-
192.168.1.253/32 254 253 0
122-
192.168.1.254/32 254 253 0
118+
Destination Source Gateway Table Scope Priority
119+
0.0.0.0/0 192.168.1.254 main universe 0
120+
192.168.1.0/24 192.168.1.1 main link 0
121+
192.168.1.253/32 main link 0
122+
192.168.1.254/32 main link 0
123123
-- routes_link3.table --
124-
Destination Source Gateway Table Scope Priority
125-
192.168.1.254/32 254 253 0
126-
192.168.1.253/32 254 253 0
127-
192.168.1.0/24 192.168.1.1 254 253 0
128-
0.0.0.0/0 192.168.1.254 254 0 0
129-
192.168.1.1/32 192.168.1.1 255 254 0
130-
192.168.1.2/32 192.168.1.1 255 254 0
131-
192.168.1.255/32 192.168.1.1 255 253 0
132-
ff00::/8 255 0 0
124+
Destination Source Gateway Table Scope Priority
125+
192.168.1.254/32 main link 0
126+
192.168.1.253/32 main link 0
127+
192.168.1.0/24 192.168.1.1 main link 0
128+
0.0.0.0/0 192.168.1.254 main universe 0
129+
192.168.1.1/32 192.168.1.1 local host 0
130+
192.168.1.2/32 192.168.1.1 local host 0
131+
192.168.1.255/32 192.168.1.1 local link 0
132+
ff00::/8 local universe 0
133133
-- routes_placeholder --
134134

135135

pkg/datapath/tables/node_address.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ func (n *nodeAddressController) reconcile() (<-chan struct{}, <-chan struct{}) {
350350
// We are only interested in local routes, which are used for IPs that are assigned
351351
// to the host (e.g. on GCE). These routes are in the local table, have host scope,
352352
// and have no source address.
353-
if route.Scope != uint8(RT_SCOPE_HOST) || route.Src.IsValid() {
353+
if route.Scope != RT_SCOPE_HOST || route.Src.IsValid() {
354354
continue
355355
}
356356

pkg/datapath/tables/node_address_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,7 @@ func TestNodeAddressFromRoute(t *testing.T) {
11101110
route := &Route{
11111111
LinkIndex: testDevice.Index,
11121112
Dst: routeBasedPrefix,
1113-
Scope: uint8(RT_SCOPE_HOST),
1113+
Scope: RT_SCOPE_HOST,
11141114
Table: RT_TABLE_LOCAL,
11151115
}
11161116
if tc.customizeRoute != nil {

pkg/datapath/tables/route.go

Lines changed: 93 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,13 @@ type Route struct {
104104
Table RouteTable
105105
LinkIndex int
106106

107-
Scope uint8
107+
Type RouteType
108+
Scope RouteScope
108109
Dst netip.Prefix
109110
Src netip.Addr
110111
Gw netip.Addr
111112
Priority int
113+
MTU int
112114
}
113115

114116
func (r *Route) DeepCopy() *Route {
@@ -127,7 +129,9 @@ func (*Route) TableHeader() []string {
127129
"Source",
128130
"Gateway",
129131
"LinkIndex",
132+
"MTU",
130133
"Table",
134+
"Type",
131135
"Scope",
132136
"Priority",
133137
}
@@ -143,13 +147,21 @@ func (r *Route) TableRow() []string {
143147
}
144148
return addr.String()
145149
}
150+
151+
mtu := ""
152+
if r.MTU != 0 {
153+
mtu = fmt.Sprintf("%d", r.MTU)
154+
}
155+
146156
return []string{
147157
r.Dst.String(),
148158
showAddr(r.Src),
149159
showAddr(r.Gw),
150160
fmt.Sprintf("%d", r.LinkIndex),
151-
fmt.Sprintf("%d", r.Table),
152-
fmt.Sprintf("%d", r.Scope),
161+
mtu,
162+
r.Table.String(),
163+
r.Type.String(),
164+
r.Scope.String(),
153165
fmt.Sprintf("%d", r.Priority),
154166
}
155167
}
@@ -177,6 +189,7 @@ var (
177189

178190
type (
179191
RouteScope uint8
192+
RouteType uint16
180193
RouteTable uint32
181194
)
182195

@@ -194,4 +207,81 @@ const (
194207
RT_TABLE_MAIN = RouteTable(0xfe)
195208
RT_TABLE_LOCAL = RouteTable(0xff)
196209
RT_TABLE_MAX = RouteTable(0xffffffff)
210+
RTN_UNSPEC = RouteType(0)
211+
RTN_UNICAST = RouteType(1)
212+
RTN_LOCAL = RouteType(2)
213+
RTN_BROADCAST = RouteType(3)
214+
RTN_ANYCAST = RouteType(4)
215+
RTN_MULTICAST = RouteType(5)
216+
RTN_BLACKHOLE = RouteType(6)
217+
RTN_UNREACHABLE = RouteType(7)
218+
RTN_PROHIBIT = RouteType(8)
219+
RTN_THROW = RouteType(9)
220+
RTN_NAT = RouteType(10)
221+
RTN_XRESOLVE = RouteType(11)
197222
)
223+
224+
func (table RouteTable) String() string {
225+
switch table {
226+
case RT_TABLE_UNSPEC:
227+
return "unspec"
228+
case RT_TABLE_COMPAT:
229+
return "compat"
230+
case RT_TABLE_DEFAULT:
231+
return "default"
232+
case RT_TABLE_MAIN:
233+
return "main"
234+
case RT_TABLE_LOCAL:
235+
return "local"
236+
default:
237+
return fmt.Sprintf("%d", table)
238+
}
239+
}
240+
241+
func (scope RouteScope) String() string {
242+
switch scope {
243+
case RT_SCOPE_UNIVERSE:
244+
return "universe"
245+
case RT_SCOPE_SITE:
246+
return "site"
247+
case RT_SCOPE_LINK:
248+
return "link"
249+
case RT_SCOPE_HOST:
250+
return "host"
251+
case RT_SCOPE_NOWHERE:
252+
return "nowhere"
253+
default:
254+
return fmt.Sprintf("%d", scope)
255+
}
256+
}
257+
258+
func (typ RouteType) String() string {
259+
switch typ {
260+
case RTN_UNSPEC:
261+
return "unspec"
262+
case RTN_UNICAST:
263+
return "unicast"
264+
case RTN_LOCAL:
265+
return "local"
266+
case RTN_BROADCAST:
267+
return "broadcast"
268+
case RTN_ANYCAST:
269+
return "anycast"
270+
case RTN_MULTICAST:
271+
return "multicast"
272+
case RTN_BLACKHOLE:
273+
return "blackhole"
274+
case RTN_UNREACHABLE:
275+
return "unreachable"
276+
case RTN_PROHIBIT:
277+
return "prohibit"
278+
case RTN_THROW:
279+
return "throw"
280+
case RTN_NAT:
281+
return "nat"
282+
case RTN_XRESOLVE:
283+
return "xresolve"
284+
default:
285+
return fmt.Sprintf("%d", typ)
286+
}
287+
}

0 commit comments

Comments
 (0)