Routing

BGP Path Attributes

AS_PATH, NEXT_HOP, LOCAL_PREF, and other BGP decision-making attributes.

Introduction: BGP attributes in route selection

In an interior routing protocol such as OSPF, a router compares paths using that protocol's metric or cost and follows its selection rules. Shared topology and selection criteria make these rules suitable for a network under one administrative control.

The global Internet, however, is a federation of thousands of independent networks, or . In this environment, the preferred path need not be the fastest one. Routing decisions consider relationships between operators, agreements, and technical policies. The Border Gateway Protocol (BGP) represents these decisions with attributes attached to each route.

BGP attributes are pieces of information, or properties, attached to a BGP route that describe its characteristics. They allow network administrators to implement policies and influence how traffic flows into and out of their networks. Knowledge of these attributes is necessary for interpreting BGP decisions.

The Four Categories of BGP Attributes

BGP attributes are not all created equal. They are classified into four categories based on how well-known they are and whether they must be passed along between routers.

Well-known Mandatory

These attributes must be understood by every BGP-speaking router and must be present in every BGP UPDATE message that contains NLRI. They describe required parts of the route information.

AS_PATH, ORIGIN, and NEXT_HOP belong to this category and are required to interpret the advertisement.

Examples: AS_PATH, ORIGIN, NEXT_HOP.

Well-known Discretionary

These attributes are understood by every BGP router, but their transmission depends on the session and the attribute's function. LOCAL_PREF is included in every UPDATE sent to an iBGP peer and appears in messages to eBGP peers only within confederations.

BGP uses LOCAL_PREF to communicate the degree of preference for a route inside the AS.

Example: LOCAL_PREF.

Optional Transitive

These attributes may not be understood by every router. If a router does not understand a transitive attribute, it should accept it, set the Partial flag, and pass it along with the route to its BGP peers.

An unknown transitive attribute remains in later UPDATE messages, while Partial records that it was not fully understood.

Example: AGGREGATOR, COMMUNITY.

Optional Non-transitive

These attributes may not be understood by every router. If a router does not recognize a non-transitive attribute, it should simply ignore it and not pass it on to its peers.

An unknown non-transitive attribute is ignored and is not included in later UPDATE messages.

Example: MED (Multi-Exit Discriminator).

AS_PATH: loop prevention and path selection

The AS_PATH is a Well-known Mandatory attribute. It identifies the autonomous systems traversed by the information, limits loops at the AS level, and participates in path selection.

Function 1: Loop Prevention

The AS_PATH is a list of all Autonomous System Numbers (ASNs) a route advertisement has traversed. As a router forwards an update to a peer in a different AS, it prepends (adds its own ASN to the beginning of) the list.

This enables loop detection at the autonomous-system level. A router excludes a route from the decision process if its own ASN is already present in AS_PATH. The AS then cannot select this route.

Function 2: Path Selection

After local policy has assigned comparable preference, AS_PATH length is one of the selection criteria. When a router has multiple resolvable paths to the same destination, it prefers the one with the shortest AS_PATH.

This comparison applies only to routes whose NEXT_HOP can be resolved in the routing table. If the next-hop address is not resolvable, the route is excluded before the remaining criteria are evaluated. Path length also depends on the segments: an AS_SET counts as one element, while an AS_SEQUENCE counts its AS numbers. The final choice follows the complete decision process and local configuration. Attribute order within an UPDATE does not change these rules.

Example: Shortest Path Wins

Router D needs to choose a path to Network X.

  • It receives a route from neighbor B with AS_PATH: (65002, 65001). The length is 2.
  • It receives a route from neighbor C with AS_PATH: (65003, 65005, 65004, 65001). The length is 4.

Because the path through B has a shorter AS_PATH (2 AS numbers versus 4), Router D will choose it as the best path and install it in its routing table.

NEXT_HOP: the next-hop address

The NEXT_HOP is a Well-known Mandatory attribute. It contains the IP address of the router used as the next hop for prefixes in the UPDATE. The way this field is set depends on whether the session is eBGP or iBGP.

NEXT_HOP in eBGP (External BGP)

For a typical directly connected eBGP session, the advertising router sets NEXT_HOP to its own IP addresson the interface used to connect to the peer. Under specified conditions, a neighboring router's address, known as a third-party NEXT_HOP, is also permitted.

NEXT_HOP in iBGP (Internal BGP)

When a route learned from an eBGP neighbor is advertised to an iBGP peer in the same AS, the NEXT_HOP attribute is, by default, left unchanged. A router can change it through explicit configuration.

Example: The Unreachable Next-Hop Problem

  1. The ISP's router (at IP 203.0.113.1203.0.113.1) sends an eBGP update to your company's Edge_Router (at IP 203.0.113.2203.0.113.2) for the network 8.8.8.0/248.8.8.0/24. The NEXT_HOP attribute in this update is 203.0.113.1203.0.113.1.
  2. Edge_Router now has a valid route. It forwards this information to its iBGP peer, Internal_Router.
  3. By default, Edge_Router does not change the NEXT_HOP. So, Internal_Router receives an update for 8.8.8.0/248.8.8.0/24 with the NEXT_HOP still set to 203.0.113.1203.0.113.1.
  4. Problem: Internal_Router is inside your company network and has no direct connection to the ISP. If its IGP table, for example OSPF, has no route to 203.0.113.1203.0.113.1, the NEXT_HOP cannot be resolved and the route cannot be used.
The Solution: Next-Hop-Self

A common solution is to configure Edge_Router to change NEXT_HOP for routes advertised to iBGP peers. A next-hop-selfsetting advertises the router's own internal address as NEXT_HOP. Internal routers can then resolve that address through the IGP.

Other attributes in path selection

Beyond AS_PATH and NEXT_HOP, other attributes participate in BGP path selection. Network administrators use them to define routing policy.

ORIGIN (Well-known Mandatory)

The ORIGIN attribute indicates how the route information was introduced into BGP. It is one of the tie-breaking criteria applied after earlier preferences. There are three origin codes, listed in order of preference, with the lowest code preferred:

  • IGP (Code 0): The prefix information is interior to the originating AS, for example it was specified with a network command in BGP configuration. This code has priority in an ORIGIN comparison.
  • EGP (Code 1): The route was learned via the historic Exterior Gateway Protocol, BGP's predecessor. This is virtually never seen today.
  • INCOMPLETE (Code 2): The route was injected into BGP via . This code has the lowest priority in an ORIGIN comparison because BGP does not define how the route was obtained before redistribution.

When the preceding comparisons do not decide the route, a router prefers the path with the lower ORIGIN code.

LOCAL_PREF (Well-known Discretionary)

LOCAL_PREF influences the choice of exit for outbound traffic within one AS. It is a numerical value sent to iBGP peers. It is not included in UPDATE messages sent to external neighbors except in BGP confederations.

A higher LOCAL_PREF has priority. The default depends on the implementation and is often 100. Setting a higher preference for routes learned from a selected ISP directs route selection within the AS to that exit point.

MED (Optional Non-transitive)

The Multi-Exit Discriminator (MED) can influence inbound trafficfrom a neighboring AS. It is used to compare multiple entry points to that same neighboring AS, subject to the neighbor's policy.

With other factors equal, a lower MED value has priority. If an AS has two links to the same provider, it can advertise routes with a lower MED on the primary link and a higher MED on the backup link. MED received from one neighboring AS should not be passed to other ASes, and its use depends on the receiving policy.

Related articles