Skip to content

bfd: actually insert peers into persistent db - #884

Open
taspelund wants to merge 2 commits into
mainfrom
trey/bfd-db
Open

bfd: actually insert peers into persistent db#884
taspelund wants to merge 2 commits into
mainfrom
trey/bfd-db

Conversation

@taspelund

Copy link
Copy Markdown
Contributor

BFD peers were not being inserted into the sled db, which means they
weren't recoverable on daemon restart/crash.

This moves all of the BFD API handlers' core logic into methods of
BfdContext, and makes BfdContext.daemon private. With BfdContext being
the sole owner of its inner state, all locking invariants can be upheld
without requiring any participation from its callers.

API operations now lock the daemon slightly earlier, ensuring updates to
both the DB and the runtime state happen during the critical section of
the mutex. This prevents concurrent API Add/Del requests from partially
trampling over each other by enforcing serialization.

Peer add requests now implement a rollback function upon runtime errors.
e.g.

  1. Add peer to DB (success)
  2. Add peer to daemon (failure)
  3. Rollback DB entry

Rollback failures return a 500 error.

before:

treyaspelund@Tallon-IV …/oxidecomputer/maghemite/bfd-db xsml 8e0f (empty) (no description)
› ./target/debug/mgadm bfd add-peer 100.64.0.0 0.0.0.0 1000 3 single-hop

treyaspelund@Tallon-IV …/oxidecomputer/maghemite/bfd-db xsml 8e0f (empty) (no description)
› ./target/debug/mgadm bfd get-peers
Peer        Listen   Required Rx  Detection Threshold  Mode       Status
100.64.0.0  0.0.0.0  1000         3                    SingleHop  Down

treyaspelund@Tallon-IV …/oxidecomputer/maghemite/bfd-db xsml 8e0f (empty) (no description)
› pkill mgd
pkill: signalling pid 33096: Operation not permitted

treyaspelund@Tallon-IV …/oxidecomputer/maghemite/bfd-db xsml 8e0f (empty) (no description) ✕
› sudo !!

treyaspelund@Tallon-IV …/oxidecomputer/maghemite/bfd-db xsml 8e0f (empty) (no description) ✕
› sudo pkill mgd

treyaspelund@Tallon-IV …/oxidecomputer/maghemite/bfd-db xsml 8e0f (empty) (no description)
› pkill mgd
pkill: signalling pid 35931: Operation not permitted

treyaspelund@Tallon-IV …/oxidecomputer/maghemite/bfd-db xsml 8e0f (empty) (no description) ✕
› ./target/debug/mgadm bfd get-peers
Peer  Listen  Required Rx  Detection Threshold  Mode  Status

treyaspelund@Tallon-IV …/oxidecomputer/maghemite/bfd-db xsml 8e0f (empty) (no description)
›

after:

treyaspelund@Tallon-IV …/oxidecomputer/maghemite/bfd-db xsml 1651 bfd: actually insert peers into persistent db ±1 +15 -9
› ./target/debug/mgadm bfd get-peers
Peer  Listen  Required Rx  Detection Threshold  Mode  Status

treyaspelund@Tallon-IV …/oxidecomputer/maghemite/bfd-db xsml 1651 bfd: actually insert peers into persistent db ±1 +15 -9
› ./target/debug/mgadm bfd add-peer 100.64.0.0 0.0.0.0 1000 3 single-hop

treyaspelund@Tallon-IV …/oxidecomputer/maghemite/bfd-db xsml 1651 bfd: actually insert peers into persistent db ±1 +15 -9
› pgrep mgd
42931

treyaspelund@Tallon-IV …/oxidecomputer/maghemite/bfd-db xsml 1651 bfd: actually insert peers into persistent db ±1 +15 -9
› sudo pkill mgd

treyaspelund@Tallon-IV …/oxidecomputer/maghemite/bfd-db xsml 1651 bfd: actually insert peers into persistent db ±1 +15 -9
› pgrep mgd
43407

treyaspelund@Tallon-IV …/oxidecomputer/maghemite/bfd-db xsml 1651 bfd: actually insert peers into persistent db ±1 +15 -9
› ./target/debug/mgadm bfd get-peers
Peer        Listen   Required Rx  Detection Threshold  Mode       Status
100.64.0.0  0.0.0.0  1000         3                    SingleHop  Down

Signed-off-by: Trey Aspelund trey@oxidecomputer.com

BFD peers were not being inserted into the sled db, which means they
weren't recoverable on daemon restart/crash.

This moves all of the BFD API handlers' core logic into methods of
BfdContext, and makes BfdContext.daemon private. With BfdContext being
the sole owner of its inner state, all locking invariants can be upheld
without requiring any participation from its callers.

API operations now lock the daemon slightly earlier, ensuring updates to
both the DB and the runtime state happen during the critical section of
the mutex. This prevents concurrent API Add/Del requests from partially
trampling over each other by enforcing serialization.

Peer add requests now implement a rollback function upon runtime errors.
e.g.
1) Add peer to DB (success)
2) Add peer to daemon (failure)
3) Rollback DB entry

Rollback failures return a 500 error.

before:
```
treyaspelund@Tallon-IV …/oxidecomputer/maghemite/bfd-db xsml 8e0f (empty) (no description)
› ./target/debug/mgadm bfd add-peer 100.64.0.0 0.0.0.0 1000 3 single-hop

treyaspelund@Tallon-IV …/oxidecomputer/maghemite/bfd-db xsml 8e0f (empty) (no description)
› ./target/debug/mgadm bfd get-peers
Peer        Listen   Required Rx  Detection Threshold  Mode       Status
100.64.0.0  0.0.0.0  1000         3                    SingleHop  Down

treyaspelund@Tallon-IV …/oxidecomputer/maghemite/bfd-db xsml 8e0f (empty) (no description)
› pkill mgd
pkill: signalling pid 33096: Operation not permitted

treyaspelund@Tallon-IV …/oxidecomputer/maghemite/bfd-db xsml 8e0f (empty) (no description) ✕
› sudo !!

treyaspelund@Tallon-IV …/oxidecomputer/maghemite/bfd-db xsml 8e0f (empty) (no description) ✕
› sudo pkill mgd

treyaspelund@Tallon-IV …/oxidecomputer/maghemite/bfd-db xsml 8e0f (empty) (no description)
› pkill mgd
pkill: signalling pid 35931: Operation not permitted

treyaspelund@Tallon-IV …/oxidecomputer/maghemite/bfd-db xsml 8e0f (empty) (no description) ✕
› ./target/debug/mgadm bfd get-peers
Peer  Listen  Required Rx  Detection Threshold  Mode  Status

treyaspelund@Tallon-IV …/oxidecomputer/maghemite/bfd-db xsml 8e0f (empty) (no description)
›
```

after:
```
treyaspelund@Tallon-IV …/oxidecomputer/maghemite/bfd-db xsml 1651 bfd: actually insert peers into persistent db ±1 +15 -9
› ./target/debug/mgadm bfd get-peers
Peer  Listen  Required Rx  Detection Threshold  Mode  Status

treyaspelund@Tallon-IV …/oxidecomputer/maghemite/bfd-db xsml 1651 bfd: actually insert peers into persistent db ±1 +15 -9
› ./target/debug/mgadm bfd add-peer 100.64.0.0 0.0.0.0 1000 3 single-hop

treyaspelund@Tallon-IV …/oxidecomputer/maghemite/bfd-db xsml 1651 bfd: actually insert peers into persistent db ±1 +15 -9
› pgrep mgd
42931

treyaspelund@Tallon-IV …/oxidecomputer/maghemite/bfd-db xsml 1651 bfd: actually insert peers into persistent db ±1 +15 -9
› sudo pkill mgd

treyaspelund@Tallon-IV …/oxidecomputer/maghemite/bfd-db xsml 1651 bfd: actually insert peers into persistent db ±1 +15 -9
› pgrep mgd
43407

treyaspelund@Tallon-IV …/oxidecomputer/maghemite/bfd-db xsml 1651 bfd: actually insert peers into persistent db ±1 +15 -9
› ./target/debug/mgadm bfd get-peers
Peer        Listen   Required Rx  Detection Threshold  Mode       Status
100.64.0.0  0.0.0.0  1000         3                    SingleHop  Down
```

Signed-off-by: Trey Aspelund <trey@oxidecomputer.com>
Signed-off-by: Trey Aspelund <trey@oxidecomputer.com>
@taspelund taspelund self-assigned this Aug 20, 2026
@taspelund taspelund added Bug bfd Bidirectional Forwarding Detection mgd Maghemite daemon rust Pull requests that update rust code labels Aug 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bfd Bidirectional Forwarding Detection Bug mgd Maghemite daemon rust Pull requests that update rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant