oxidecomputer / oxidecomputer/omicron

SourceNatConfig could store infallible block numbers instead of fallible port pairs

Open
#5,571 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
572
Forks
97
Avg merge
2d 12h
Merged PRs (30d)
96

Description

So.... I'm wondering if rather than first_port and last_port this can just take the multiple of NUM_SOURCE_NAT_PORTS. Since NUM_SOURCE_NAT_PORTS is 2^14 and the number of ports is 2^16, there are only 4 possible values. So this could actually take an enum, say, SourceNatPortBlock { Block0, Block1, Block2, Block3 }. That would make this constructor infallible.

Then you can serialize the data in that fashion as well, and deserialization won't require further validation.

Some places may have a port pair, and you can have a constructor that converts that into a SourceNatPortBlock, returning the below error. But places that don't have the raw ports won't have to deal with errors.

Not sure how much it increases work for you, maybe in a followup/after r8 if it disrupts this work too much?

Originally posted by @sunshowers in https://github.com/oxidecomputer/omicron/pull/5560#discussion_r1571610090

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating SourceNatConfig, NUM_SOURCE_NAT_PORTS, and the first_port/last_port usages in the repository; no file or test is named in the issue. Read the discussion linked from pull request #5560, then trace serialization, deserialization, and port-pair conversion. Done means the four valid blocks are represented infallibly and all affected callers and validation paths are updated.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
backend-api-design, networking
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.