Skip to content

Commit e903507

Browse files
committed
vrf: keep nexthop flags when a multipath route collapses
A single remaining nexthop was copied as Gw and LinkIndex only, so onlink never made it onto the route installed in the VRF table. Signed-off-by: Dean Chen <862469039@qq.com>
1 parent 040a108 commit e903507

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

‎plugins/meta/vrf/vrf.go‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,12 +279,15 @@ func routeForInterface(route netlink.Route, linkIndex int) (netlink.Route, bool)
279279
if len(nhs) == 1 {
280280
// Prefer a simple single-nexthop form; this is what IPAM originally
281281
// installed before the kernel merged it into an ECMP route.
282+
// onlink and the other nexthop flags live on the nexthop, not the
283+
// multipath route header, so copy them onto the single-hop route.
282284
r.MultiPath = nil
283285
r.LinkIndex = nhs[0].LinkIndex
284286
r.Gw = nhs[0].Gw
285287
r.NewDst = nhs[0].NewDst
286288
r.Encap = nhs[0].Encap
287289
r.Via = nhs[0].Via
290+
r.Flags |= nhs[0].Flags
288291
} else {
289292
r.MultiPath = nhs
290293
r.LinkIndex = 0

‎plugins/meta/vrf/vrf_test.go‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,31 @@ var _ = Describe("unit tests", func() {
11301130
Expect(got.Priority).To(Equal(1024))
11311131
})
11321132

1133+
It("keeps nexthop flags when a multipath route collapses to one hop", func() {
1134+
route := netlink.Route{
1135+
LinkIndex: 0,
1136+
Dst: ipv6Default,
1137+
Priority: 1024,
1138+
Flags: int(netlink.FLAG_PERVASIVE),
1139+
MultiPath: []*netlink.NexthopInfo{
1140+
{LinkIndex: eth0Index, Gw: net.ParseIP("fe80::1")},
1141+
{
1142+
LinkIndex: net1Index,
1143+
Gw: net.ParseIP("2001:db8:1::1"),
1144+
Flags: int(netlink.FLAG_ONLINK),
1145+
},
1146+
},
1147+
}
1148+
1149+
got, ok := routeForInterface(route, net1Index)
1150+
Expect(ok).To(BeTrue())
1151+
Expect(got.MultiPath).To(BeNil())
1152+
Expect(got.LinkIndex).To(Equal(net1Index))
1153+
Expect(got.Gw.Equal(net.ParseIP("2001:db8:1::1"))).To(BeTrue())
1154+
Expect(got.Flags & int(netlink.FLAG_ONLINK)).To(Equal(int(netlink.FLAG_ONLINK)))
1155+
Expect(got.Flags & int(netlink.FLAG_PERVASIVE)).To(Equal(int(netlink.FLAG_PERVASIVE)))
1156+
})
1157+
11331158
It("rejects multipath routes with no nexthop on the target interface", func() {
11341159
route := netlink.Route{
11351160
Dst: ipv6Default,

0 commit comments

Comments
 (0)