Skip to main content
Version: 7.26

Nexthop selection

The NEXT_HOP attribute of a BGP route is the address to which the receiving router forwards the traffic. This page describes how RouterOS reads the next hop of received routes, and how it chooses the next hop it sends.

Received routes​

RouterOS does not reject a received route because its next hop is unreachable. It stores the route, and the routing table decides whether the next hop can be used. A route whose next hop cannot be resolved stays in the table with the U (unreachable) flag and is not used. Checks on the next hop are up to the routing filters you create.

What happens on input:

  • The router reads the next hop from the NEXT_HOP attribute.
  • For multiprotocol NLRI (IPv6, VPN and other address families), it checks that the next hop has a valid length:
    • If the length is invalid, the router sends an UPDATE error NOTIFICATION and stops processing the message.
    • Otherwise it stores the next hop.
    • If the update also carries a link-local next hop, the router determines the interface of the connection and stores the link-local address with that interface.
  • The input routing filter can change the next hop (set gw, set gw-ll).
  • The route goes to the routing table, where the reachability of the next hop is determined.

The next hop is resolved through other routes as described in Nexthop lookup. Routes from single-hop eBGP peers have target scope 10: their next hop must be on a connected network. Routes from iBGP peers, and from eBGP peers with multihop set to yes, have target scope 30, so their next hop can also be resolved through IGP and static routes.

Advertised routes​

The next hop the router sends depends on the session type and on nexthop-choice. The usual results:

SessionNext hop sent
eBGP, nexthop-choice not setThe router's local address of the session.
eBGP, nexthop-choice=propagateThe route's next hop, or the value an output filter set with set gw.
iBGP, route originated by the router (output.network)The router's local address of the session.
iBGP route reflector, reflected routeThe route's next hop, unchanged.
iBGP or route reflector, nexthop-choice=force-selfThe router's local address of the session.
IPv6 route on a session between IPv4 addressesThe local IPv4 address as an IPv4-mapped IPv6 address, for example ::ffff:10.0.12.2.
IPv4 route on an unnumbered sessionThe router's IPv6 link-local address.

The router decides in this order:

  • If nexthop-choice is not force-self, or the route's address family is not IPv4 or IPv6:
    • If the peer is a route reflector, or nexthop-choice is propagate, or the peer is not eBGP:
      • Check the next hop's address family and try to set the outgoing link-local next hop.
      • Check the next hop's address family and try to set the outgoing next hop.
    • If the outgoing next hop is still not set and the peer is not multihop:
      • Go through the available immediate next hops and try to set the outgoing next hop and the link-local next hop.
    • If the outgoing next hop equals the peer's router-id, unset it.
    • If the outgoing next hop equals the peer's address, unset it.
    • If the interface of the peer's address is not the interface of the link-local next hop, unset the outgoing link-local next hop.
    • If the outgoing link-local next hop equals the peer's address, unset it.
  • If the outgoing next hop is still not set, check the address family and use the local address of the session.
  • If the outgoing next hop is still not set and the route's address family is IPv6 or L2VPN:
    • If the local address of the session is IPv4, use it as an IPv4-mapped IPv6 address.

A next hop set by an output routing filter (set gw) is sent on a session with nexthop-choice=propagate. On an eBGP session without it, the router sends its local address whatever the filter set. When the filter sets the peer's own address, the router sends its local address instead.