Skip to content

Commit

Permalink
fix(NRC): prevent adding routes with mixed families
Browse files Browse the repository at this point in the history
  • Loading branch information
aauren committed Oct 7, 2023
1 parent bab0d4f commit 5cf1265
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/controllers/routing/network_routes_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,14 @@ func (nrc *NetworkRoutingController) injectRoute(path *gobgpapi.Path) error {
case sameSubnet:
// if the nextHop is within the same subnet, add a route for the destination so that traffic can bet routed
// at layer 2 and minimize the need to traverse a router
// First check that destination and nexthop are in the same IP family
dstIsIPv4 := dst.IP.To4() != nil
gwIsIPv4 := nextHop.To4() != nil
if dstIsIPv4 != gwIsIPv4 {
return fmt.Errorf("not able to add route as destination %s and gateway %s are not in the same IP family - "+
"this shouldn't ever happen from IPs that kube-router advertises, but if it does report it as a bug",
dst.IP, nextHop)
}
route = &netlink.Route{
Dst: dst,
Gw: nextHop,
Expand Down

0 comments on commit 5cf1265

Please sign in to comment.