Skip to content

Commit ad3a2f2

Browse files
committed
fix(NRC): prevent adding routes with mixed families
1 parent 4283f32 commit ad3a2f2

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

pkg/controllers/routing/network_routes_controller.go

+8
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,14 @@ func (nrc *NetworkRoutingController) injectRoute(path *gobgpapi.Path) error {
692692
case sameSubnet:
693693
// if the nextHop is within the same subnet, add a route for the destination so that traffic can bet routed
694694
// at layer 2 and minimize the need to traverse a router
695+
// First check that destination and nexthop are in the same IP family
696+
dstIsIPv4 := dst.IP.To4() != nil
697+
gwIsIPv4 := nextHop.To4() != nil
698+
if dstIsIPv4 != gwIsIPv4 {
699+
return fmt.Errorf("not able to add route as destination %s and gateway %s are not in the same IP family - "+
700+
"this shouldn't ever happen from IPs that kube-router advertises, but if it does report it as a bug",
701+
dst.IP, nextHop)
702+
}
695703
route = &netlink.Route{
696704
Dst: dst,
697705
Gw: nextHop,

0 commit comments

Comments
 (0)