Page MenuHomeVyOS Platform

IPsec vti-up-down: DB keyed only by connection name causes admin-down of a VTI still carried by a live IKE_SA
In progress, HighPublicBUG

Description

IPsec vti-up-down: DB keyed only by connection name causes admin-down of a VTI still carried by a live IKE_SA

When two IKE_SAs for the same connection exist briefly — which happens whenever a peer re-establishes a tunnel before the local side finishes timing out the old one via DPD — vti_updown_db.py can't tell them apart. Its key is {interface}:{connection}:{protocol}, with no SA identifier, stored in a set.

Sequence of events:

  1. New IKE_SA comes up → add() finds the key already present (from the old, still-registered SA) → no-op. The interface is never marked up for this SA.
  2. Old IKE_SA finally times out → remove() deletes the only entry → interface count drops to zero → VTI is administratively downed, even though the new SA's CHILD_SA is INSTALLED and carrying traffic.

The VTI does not recover on its own, since the surviving SA already ran its up-client hook and won't fire it again. Everything downstream (BGP, routing) stays down silently — show vpn ipsec sa and show interfaces vti both look healthy, so the failure is hard to detect (observed: 4.5-hour undetected outage).

Affected files: src/etc/ipsec.d/vti-up-down, python/vyos/utils/vti_updown_db.py
Present since: introduction of the file (T5873), still present in rolling.

Proposed fix: Key the DB entry by IKE_SA identity, not just connection name — include strongSwan's PLUTO_UNIQUEID in the ifspec string ({interface}:{connection}:{protocol}:{uniqueid}). All existing readers split on : and take index 0 for the interface, so this is backward compatible. Note: this changes the failure mode so a missed down event leaks an entry and leaves the interface up (arguably safer than the current bug), which suggests optionally reconciling the DB against swanctl --list-sas on commit as a follow-up.

Reproduction: A new unit test (test_same_connection_multiple_sas) demonstrates the bug against current rolling; on hardware, force the peer to initiate a fresh IKE_SA while the local side is mid-DPD-timeout on the old one.

Workaround: sudo ip link set <vtiN> up (or reset vpn ipsec) — no IPsec-level action needed since the SA is already installed.

Full report with logs, mermaid sequence diagram, and diff:
https://forum.vyos.io/t/ipsec-vti-up-down-db-keyed-by-connection-name-teardown-of-a-stale-ike-sa-admin-downs-a-vti-still-carried-by-a-live-sa/17603

Details

Version
1.5
Is it a breaking change?
Unspecified (possibly destroys the router)
Issue type
Bug (incorrect behavior)
Forum thread
https://forum.vyos.io/t/ipsec-vti-up-down-db-keyed-by-connection-name-teardown-of-a-stale-ike-sa-admin-downs-a-vti-still-carried-by-a-live-sa/17603

Event Timeline

Viacheslav triaged this task as High priority.

Gonna bump this. It's been more than a month since this was put in and still hasn't been fixed.

At the moment, there are requests for changes; the status of the PR is waiting for the author

Another instance, VyOS Stream 2026.03 (vyos-1x 1.5dev0-3990-g9a296ec12), site-to-site to an Azure VPN Gateway (IKEv2, no reauth, DPD restart). On 2026-10-12 the vti was left admin-down while its CHILD_SA stayed INSTALLED: IKE and child SA reported up, BGP over the vti sat in Active, bytes out 0 for two days. /tmp/ipsec_vti_interfaces had lost the entry; reset vpn ipsec site-to-site peer re-ran up-client and recovered it. Confirms the DB key needs the SA identity (PLUTO_UNIQUEID), as proposed. Workaround in place: a cron job that re-raises any xfrm interface whose if_id matches an INSTALLED CHILD_SA (via vici) by re-running the updown hook's up path.

I have implemented new approach to drive the admin state of VTI interfaces from strongSwan via VICI plugin:

I will be grateful for review and feedback.

Viacheslav changed the task status from Open to In progress.Tue, Oct 27, 12:47 PM
Viacheslav assigned this task to o.kuchmystyi.

Two notes from vyos/vyos-1x#5565 (T9468, vpn ipsec site-to-site peer <peer> vti traffic-selector split-by-family), in case it helps the review here.

Textual conflict. #5565 rewrites the VTI child block of data/templates/ipsec/swanctl/peer.j2 into a loop over vti_children, with the updown line inside the loop and different indentation. This PR removes the updown lines of the same block, so the two will conflict. Whichever is merged second needs a rebase. I will do mine if this one lands first.

Two CHILD_SAs on one VTI. With split-by-family the peer gets two children on the same if_id, <name>-vti for IPv4 and <name>-vti6 for IPv6, for peers that narrow a CHILD_SA to one address family. In such a setup one of the two may be missing or may be rekeyed on its own. From reading vyos-vti-updown, a VTI is wanted up when a peer bound to it holds a live CHILD_SA on its if_id, so one installed child should be enough, and the children are matched by if_id and not by name. I did not run it with two children, so please confirm that this is the intended behaviour. A test with two children where one goes down while the other stays installed would cover it.

@rherold

so please confirm that this is the intended behaviour.

Yes this is the intended behavior and I think it will work on the current version of vyos-vti-updown.
A VTI should stay up as long as any one installed CHILD_SA of a bound peer carries its if_id.