# GoBGP leaves a stale VPN route in the FIB after its Route Target changes

## Description

On GoBGP v4.11.0 (commit 53ceb78fe284018ce83a92f3039198f0a86dc823) with FRR/Zebra 8.1 (commit 1752bfdfc14409c667f10b7ee2c99b9014abb271), a configured VPNv4 peer can announce a route with RT 65000:100, replace the same NLRI with RT 65000:200, then withdraw it. GoBGP removes the route from its RIBs while Zebra/Linux retains the MPLS route installed under the first RT. A customer probe continues to reach the peer-controlled next-hop endpoint after the RT change and withdrawal.

The peer is configured for VPNv4, and import policy accepts the route into GoBGP's global VPN RIB for both RT values. RT 65000:100 matches the target VRF's import RT; RT 65000:200 does not. The next hop is reachable in the target VRF and the default forwarding table.

## Impact

After the RT change, the route disappears from the VRF IPv4 RIB while remaining in the global VPN RIB and Linux MPLS table. After withdrawal, it disappears from both GoBGP RIB views while the Linux route still points to the old next hop. The packet capture records the customer probe at the router egress and at that endpoint. A direct-withdraw control removes the route and produces no matching packet.

## Steps to reproduce

From this finding directory, run the reproducer with Docker:

~~~sh
./attachments/reproduce.sh
~~~

If the GoBGP build is absent, the script builds v4.11.0 from the pinned source tag first. It then starts fresh GoBGP and Zebra processes in a disposable container and runs the RT-change candidate plus direct-withdraw control. Success prints PASS for one candidate and one control. The [reproduction guide](attachments/README.md) lists the prerequisites and output location. Fresh output is written to replay-output/<timestamp>/.

## Expected behavior

When a route stops matching a VRF's import RT, GoBGP should remove it from that VRF's forwarding table. When the peer withdraws the VPN NLRI, the route should disappear from the GoBGP RIBs and Linux FIB, and customer traffic should stop using it.

## Observed behavior

The candidate sends the valid sequence RT 65000:100, RT 65000:200, then MP_UNREACH_NLRI for the same VPN NLRI. After the RT change, the VRF route disappears while the global VPN route and Linux MPLS route remain. After withdrawal, the route disappears from the GoBGP RIBs, but the Linux route still points to the old next hop with label 100. Zebra records route adds without a delete. The direct-withdraw control records the delete, removes the FIB entry, and sends no matching packet.

The packet capture measures delivery to the next-hop endpoint.

On 2026-11-11, the RT-change candidate left the old MPLS route installed and the direct-withdraw control removed it once on GoBGP v4.11.0 and once on main commit `f7daa917b9e3a075849693c9148a82f5563c4020`. Both runs used FRR/Zebra 8.1. The [release](attachments/evidence/replay/20261111/release-gobgp-v4.11.0.json) and [main](attachments/evidence/replay/20261111/main-gobgp.json) summaries contain the VPN RIB, VRF/MPLS route, and packet results.

## Root cause

[CanImportToVrf()](https://github.com/osrg/gobgp/blob/53ceb78fe284018ce83a92f3039198f0a86dc823/internal/pkg/table/policy.go#L4940-L4955) checks a path's current RTs against the VRF import targets. [setPathVrfIdMap()](https://github.com/osrg/gobgp/blob/53ceb78fe284018ce83a92f3039198f0a86dc823/pkg/server/server.go#L941-L953) builds the VRF list for a ZAPI route event from paths that pass that check. After the peer replaces RT 65000:100 with RT 65000:200, the old VRF is absent from the event.

[The ZAPI route update loop](https://github.com/osrg/gobgp/blob/53ceb78fe284018ce83a92f3039198f0a86dc823/pkg/server/zclient.go#L545-L571) calls SendIPRoute() only for VRFs in that list. With no VRF entry, GoBGP sends no update or delete to Zebra. The later withdrawal has no currently importable path from which to recover the old VRF entry, so Zebra retains the route installed before the RT change.

[RFC 4364, Section 4.3.1](https://www.rfc-editor.org/rfc/rfc4364.html#section-4.3.1) defines VRF import eligibility by matching a route's RT against a VRF's import targets. [RFC 4271, Section 3.1](https://www.rfc-editor.org/rfc/rfc4271.html#section-3.1) describes replacement and withdrawal of routes with the same NLRI. [RFC 4760, Section 4](https://www.rfc-editor.org/rfc/rfc4760.html#section-4) defines MP_UNREACH_NLRI for the VPN withdrawal used here.

The GoBGP tracker contains [issue #1647](https://github.com/osrg/gobgp/issues/1647) and [PR #1649](https://github.com/osrg/gobgp/pull/1649) about RTC Route Target Membership withdrawals leaving VPN routes on remote peers. PR #1649 was closed; merged [PR #1699](https://github.com/osrg/gobgp/pull/1699) implemented the fix for that RTM withdrawal path. [Issue #3648](https://github.com/osrg/gobgp/issues/3648) and [PR #3706](https://github.com/osrg/gobgp/pull/3706) concern stale local FIB state after next-hop invalidation. The fix proposed in #3706 landed as [commit 8ea07aa](https://github.com/osrg/gobgp/commit/8ea07aa85bac64f3e23966fc124fcd2ca6920662), which is included in the tested v4.11.0 source. The current replay replaces the RT on a VPN NLRI and then withdraws that NLRI. Its checked open and closed issue/PR searches for RT changes, VRF import targets, VPN withdrawals, and FIB/MPLS terms surfaced no report of this local stale-MPLS sequence.

## Suggested fix

When a VPN path stops matching a VRF's import targets, send a delete for each VRF where the prior path was installed. Preserve the previous and current VRF sets or identify affected VRFs before discarding the old eligibility. Add a regression case for RT A to RT B to withdrawal and check the GoBGP RIB, ZAPI delete, Linux FIB, and packet delivery.
