Skip to content

bgpd: Fix EVPN-MH route cleanup race condition during interfaces flap - #20710

Merged
ton31337 merged 1 commit into
FRRouting:masterfrom
krishna-samy:krishna/evpn-mh-stale-route-fix
Mar 3, 2026
Merged

bgpd: Fix EVPN-MH route cleanup race condition during interfaces flap#20710
ton31337 merged 1 commit into
FRRouting:masterfrom
krishna-samy:krishna/evpn-mh-stale-route-fix

Conversation

@krishna-samy

Copy link
Copy Markdown
Contributor

Issue:
In EVPN-MH setup, when all the interfaces are flapped(using 'ifdown/ifup'), the VTEP ends up having stale route entries(via vxlan) to the multi-homed hosts even though they are connected MH hosts.

The events sequencing is as below:
ifdown br_default:

  • Brings down all the host facing interfaces/vni/es
  • So, new route entries(via vxlan) created for the hosts, because the multi-homed hosts(before ifdown) are not connected hosts now.

ifup br_default:

  • The ES becomes active now.
  • We should clear/uninstall the above created routes as the hosts are multi-homed now. This does not happen.
  • This is because of the events sequencing where a local ES add event arrives bgpd before before the VNI-VRF association becomes available.
  • When this happens, the current code that handles the es_evi add is skipping the unistall_local_routes (bgp_evpn_local_es_evi_add->bgp_evpn_local_es_evi_unistall_local_routes_in_vrfs).
  • This is because the explicit check 'if(es_evi->es_vrf)' fails in this path as the VRF mapping is not yet received.
  • Also, we never go for an attempt to clear the global routes in the same ES when the 'es_evi->es_vrf' mapping is received later.
  • So, This causes stale routes in the system and traffic drop as well.

Fix:
Add 'sweep_local_routes' flag in es-evi to track when cleanup is needed but VRF is not yet available.
Once we receive vni-vrf update, clean up the local routes that were installed earlier for remote ES(now local ES hosts).

@greptile-apps

greptile-apps Bot commented Feb 5, 2026

Copy link
Copy Markdown

Greptile Overview

Greptile Summary

This PR fixes a race condition in EVPN multi-homing (MH) that causes stale route entries when interfaces are flapped. The issue occurs when a local ES add event arrives before the VNI-VRF association is available, causing route cleanup to be skipped.

The fix introduces a deferred cleanup mechanism using a sweep_local_routes flag:

  • When bgp_evpn_local_es_evi_uninstall_local_routes_in_vrfs() is called but VRF is not yet available, the flag is set to true
  • When VNI-VRF association is later received via bgp_evpn_es_evi_vrf_ref(), the deferred cleanup is executed

Key changes:

  • Added sweep_local_routes boolean flag to bgp_evpn_es_evi structure
  • Modified bgp_evpn_local_es_evi_uninstall_local_routes_in_vrfs() to set flag when VRF unavailable
  • Modified bgp_evpn_es_evi_vrf_ref() to check flag and execute deferred cleanup
  • Initialized flag to false in bgp_evpn_es_evi_new()

Confidence Score: 4/5

  • This PR is safe to merge with low risk - it addresses a specific race condition with a targeted fix
  • The implementation is straightforward and correctly addresses the race condition. The flag-based deferred cleanup approach is sound. Minor concern: flag is cleared before cleanup executes, but this is acceptable given the function design. The fix is well-scoped to the specific issue.
  • No files require special attention - changes are minimal and well-contained

Important Files Changed

Filename Overview
bgpd/bgp_evpn_mh.h Added sweep_local_routes boolean flag to bgp_evpn_es_evi struct for deferred route cleanup tracking
bgpd/bgp_evpn_mh.c Implemented deferred route cleanup logic using flag: sets flag when VRF unavailable, clears routes when VRF becomes available

Sequence Diagram

sequenceDiagram
    participant User
    participant System
    participant ES as Ethernet Segment (ES)
    participant ESEVI as ES-EVI
    participant VRF

    Note over User,VRF: Interface Flap Scenario (ifdown/ifup)
    
    User->>System: ifdown br_default
    System->>ES: Deactivate ES
    System->>ESEVI: Remove local host interfaces
    Note over ESEVI: Multi-homed hosts become remote<br/>Create vxlan routes for hosts
    
    User->>System: ifup br_default
    System->>ES: ES becomes active (local)
    ES->>ESEVI: bgp_evpn_local_es_evi_add()
    
    alt VRF not yet available
        ESEVI->>ESEVI: bgp_evpn_local_es_evi_uninstall_local_routes_in_vrfs()
        Note over ESEVI: es_vrf is NULL
        ESEVI->>ESEVI: Set sweep_local_routes = true
        Note over ESEVI: Defer route cleanup
    end
    
    System->>VRF: VNI-VRF association received
    VRF->>ESEVI: bgp_evpn_es_evi_vrf_ref()
    ESEVI->>ESEVI: bgp_evpn_es_vrf_ref()
    Note over ESEVI: es_vrf is now set
    
    alt sweep_local_routes is true
        ESEVI->>ESEVI: Check sweep_local_routes && es_vrf
        ESEVI->>ESEVI: Set sweep_local_routes = false
        ESEVI->>ESEVI: bgp_evpn_local_es_evi_uninstall_local_routes_in_vrfs()
        Note over ESEVI: Clean up stale vxlan routes<br/>Routes now point to local hosts
    end
Loading

@krishna-samy
krishna-samy marked this pull request as draft February 5, 2026 09:53
@krishna-samy
krishna-samy force-pushed the krishna/evpn-mh-stale-route-fix branch from 6189f13 to 91f2e95 Compare February 5, 2026 10:03
@krishna-samy
krishna-samy marked this pull request as ready for review February 5, 2026 10:06
@krishna-samy

Copy link
Copy Markdown
Contributor Author

ci:rerun

1 similar comment
@krishna-samy

Copy link
Copy Markdown
Contributor Author

ci:rerun

Comment thread bgpd/bgp_evpn_mh.c Outdated
es_evi->es = es;
es_evi->vpn = vpn;
es_evi->flags = 0;
es_evi->sweep_local_routes = false;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we just reuse es_evi->flags?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Agree
updated the changes, please check.

Issue:
In EVPN-MH setup, when all the interfaces are flapped(using 'ifdown/ifup'),
the VTEP ends up having stale route entries(via vxlan) to the multi-homed hosts
even though they are connected MH hosts.

The events sequencing is as below:
ifdown br_default:
 - Brings down all the host facing interfaces/vni/es
 - So, new route entries(via vxlan) created for the hosts, because the multi-homed
   hosts(before ifdown) are not connected hosts now.

ifup br_default:
 - The ES becomes active now.
 - We should clear/uninstall the above created routes as the hosts are
   multi-homed now. This does not happen.
 - This is because of the events sequencing where a local ES add event arrives
   bgpd before before the VNI-VRF association becomes available.
 - When this happens, the current code that handles the es_evi add is skipping
   the unistall_local_routes (bgp_evpn_local_es_evi_add->bgp_evpn_local_es_evi_unistall_local_routes_in_vrfs).
 - This is because the explicit check 'if(es_evi->es_vrf)' fails in this path
   as the VRF mapping is not yet received.
 - Also, we never go for an attempt to clear the global routes in the same ES
   when the 'es_evi->es_vrf' mapping is received later.
 - So, This causes stale routes in the system and traffic drop as well.

Fix:
Add 'sweep_local_routes' flag in es-evi to track when cleanup is needed but VRF
is not yet available.
Once we receive vni-vrf update, clean up the local routes that were installed
earlier for remote ES(now local ES hosts).

Signed-off-by: Krishnasamy R <krishnasamyr@nvidia.com>
@krishna-samy
krishna-samy force-pushed the krishna/evpn-mh-stale-route-fix branch from 91f2e95 to efc795a Compare February 10, 2026 13:10

@ton31337 ton31337 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@krishna-samy

Copy link
Copy Markdown
Contributor Author

@ton31337
Is it good to merge ?(I hope it is not blocked by release).

@ton31337
ton31337 merged commit e07063d into FRRouting:master Mar 3, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants