Skip to content

dpd: Want a better API for bulk NAT entry operations #255

Open

Description

@jgallagher

As a part of oxidecomputer/omicron#10167, sled-agent running on each scrimlet wants to ensure the NAT entries for all Omicron services are correct on its switch zone's dpd. The information it has is a generation-numbered-guarded declarative set of "entries that should exist".

The existing dpd API makes it easy to ensure each of those entries does exist, but I don't think there's an easy way for sled-agent to remove stale Omicron service NAT entries that shouldn't exist. It doesn't know what entries might have existed in the past; only what should exist now.

I have a prototype branch that makes this work, but it's pretty gnarly: it reads all current NAT entries from dpd across a series of API calls:

  • For each IP returned by looping over all pages of nat_ipv4_addresses_list, fetch all NAT entries associated with that IP via nat_ipv4_list.
  • For each IP returned by looping over all pages of nat_ipv6_addresses_list, fetch all NAT entries associated with that IP via nat_ipv6_list.

As a heuristic for "what entries exist that shouldn't", it filters all the returned NAT entries down to just those with a VNI matching the Omicron services VNI. Now it can diff locally and decide whether any entries exist that shouldn't, and delete those.

This issue is similar in spirit to #209. In this specific case we don't necessarily need a generation number on the dpd side for correctness, since there is only one client (the local sled-agent) and it already guards changes via a generation number of its own. But I could imagine wanting a similar kind of "bulk" API if we wanted to invert the Nexus <-> dpd NAT syncing path (which we do at some point - this is #83), and it would be easy for us to pass through the generation number we do have if needed.

I'm not sure exactly what shape this should be. The features I'd like are:

  • Some way of identifying an entire set of related NAT entries. I'm using VNI to do this now - maybe that's fine / correct? Or there could be some metadata that described a group of "all Omicron service entries".
  • Either:
    • A single "ensure" API that takes a generation-guarded, identified-by-group set of NAT entries, and then dpd internally removes any stale entries that are in the same group but not in the new request, and adds/updates all entries that are in the new request. (I believe this is similar to the way BGP is configured in mgd - there's a single bgp_apply() endpoint that takes the config that should exist, then internally does whatever it needs to do to make that happen.)
    • A bulk "get" API (presumably paginated) that returns all the current entries in a group. This would be more similar to the prototype branch I have, but the filter-down-to-a-group would happen on the dpd side instead of the client needing to fetch all NAT entries. Given this, the client can do its own diffing and then use the existing add/remove APIs to make updates as needed.

I think the first of those options is more generally useful - the second is only useful if there's a single client that can't race with others, since it opens an obvious TOCTOU between the "bulk get" and the "local diff then apply changes". But either would be a big improvement for the current project, and I assume (perhaps naively) that the second would be a smaller lift.

Activity

  1. self-assigned this
    on Jul 8, 2026
  2. nicolaskagami commented on Aug 5, 2026

    @nicolaskagami
    Contributor

    I took a look at this today as a potential first PR for dendrite.

    I'm currently leaning towards a "tagged" group apply (PUT) because of the following:

    • Set participation is explicit, so we'll never delete a conflicting entry.
    • While we're apparently only using SERVICE_VNI=100, ServiceZoneNatEntry can have any vni.
    • We might want to use the per-entry API to configure entries with any VNI without interfering with the reconciled set.

    There's still concern about some non-functional requirements:

    • We don't expect there to be dueling writers so we could eschew generation numbers for now, but it would also be nice for omicron to be able to check what's been installed so it doesn't needlessly push (though perhaps this set is expected to be small).
    • Since we're moving away from a pull-based system (with scrimlet-reconcilers), we don't have a (very) quick way to recover from a restarted dpd. We could look for a (hopefully stable) omicron API to indicate that they should reconcile sooner rather than setting the period aggressively.
  3. jgallagher commented on Aug 5, 2026

    @jgallagher
    ContributorAuthor

    We don't expect there to be dueling writers so we could eschew generation numbers for now, but it would also be nice for omicron to be able to check what's been installed so it doesn't needlessly push (though perhaps this set is expected to be small).

    FWIW, if you want to put a generation number in the API, that'd be trivial to populate from the omicron side - we already have a generation number on the ServiceZoneNatEntry set for our own use (avoiding dueling Nexuses updating the bootstore), so we could easily pass it down to dpd too.

    Since we're moving away from a pull-based system (with scrimlet-reconcilers), we don't have a (very) quick way to recover from a restarted dpd. We could look for a (hopefully stable) omicron API to indicate that they should reconcile sooner rather than setting the period aggressively.

    My gut feeling here is that setting a relatively aggressive-on-human-scale-but-not-on-computer-scale reconciliation retry period (it's set to 30 seconds now) is probably good enough to cover the occasional and unusual dpd restart. If we have so many dpd restarts that 30 seconds is too long, we presumably need to fix whatever's causing the restarts. And if reconciling becomes so expensive we don't want to do it every 30 seconds, we should fix that too. This issue should help quite a lot with that, since we won't need to fetch all the NAT entries during each reconciliation pass. The complete set of ServiceZoneNatEntrys is currently 6-10 entries total (3 Nexus, 2 NTP, 1-5 external DNS). I'm not sure what multirack will do to these numbers - we'll have more services that need NAT entries, but I don't know whether every dpd on every rack has NAT entries for all services, or if it only has NAT entries for the services on its rack, but either way this is going to be a very small number compared to the number of instance NAT entries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions