Skip to content

opteadm/OpteHdl cleanup #735

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open

opteadm/OpteHdl cleanup #735

wants to merge 16 commits into from

Conversation

FelixMcFelix
Copy link
Collaborator

@FelixMcFelix FelixMcFelix commented Apr 24, 2025

This PR moves all base ioctl operations into opte_ioctl::OpteHdl, allowing us to remove the vast majority of code in the OpteAdm handle.

In addition, I've done some extra reorganisation and dependency grooming s.t. opteadm no longer compiles any engine features/code from OPTE, which gets the release binary size from 46.2 -> 31.7 MiB. Thin LTO takes that down to 21.3 MiB. Opteadm compile time drops from ~40s on master to ~30s here 🎉.

One of the blockers here was that several ioctls relied on serialising/deserialising types which were only exposed as part of the engine feature flag. Accordingly, a few type definitions have been moved into opte_api (RuleId, TcpState) and opte::api (InnerFlowId). I've tried to be cognisant of the longer term goal of having primitives like InnerFlowId be chosen by the NetworkImpl by parametrising the Dump ioctls.

Closes #529.
Closes #755.

@FelixMcFelix FelixMcFelix changed the title Optehdl cleanup opteadm/OpteHdl cleanup May 12, 2025
Copy link
Collaborator Author

@FelixMcFelix FelixMcFelix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fell into a bit of a rabbithole around build-features while cleaning this up. I've opened #755 as a result of staring at one lockfile too many.

Comment on lines +49 to +70
pub struct InnerFlowId {
// Using a `u8` here for `proto` hides the enum repr from SDTs.
pub proto: u8,
// We could also theoretically get to a 38B packing if we reduce
// AddrPair's repr from `u16` to `u8`. However, on the dtrace/illumos
// side `union addrs` is 4B aligned -- in6_addr_t has a 4B alignment.
// So, this layout has to match that constraint -- placing addrs at
// offset 0x2 with `u16` discriminant sets up 4B alignment for the
// enum variant data (and this struct itself is 4B aligned).
pub addrs: AddrPair,
pub src_port: u16,
pub dst_port: u16,
}

impl InnerFlowId {
#[cfg(feature = "engine")]
pub fn crc32(&self) -> u32 {
let mut hasher = Hasher::new();
self.hash(&mut hasher);
hasher.finalize()
}
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main reason this type lives here and not in opte_api is so that we can have this crc32 method implemented directly on the flow ID, while keeping crc32fast limited to engine. Adding a conditional import to opte_api itself felt... bad.

In the fullness of time (#754), we probably want our base FlowId trait, at which point opte::engine can add its own FlowIdExt: FlowId trait with methods like this.

Comment on lines +425 to +430
build_cargo_bin(
&["--bin", "opteadm"],
p_name,
Some("bin/opteadm"),
true,
)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Building from the workspace root appeared to be pulling in more dependencies via feature unification.

@FelixMcFelix FelixMcFelix marked this pull request as ready for review May 12, 2025 13:38
@FelixMcFelix FelixMcFelix requested a review from luqmana May 12, 2025 13:38
The cost is minimal (~1s extra) for a further binary reduction to
~21.3MiB. Full-fat LTO still costs us an extra 18s (baseline on my
machine w/o LTO is 30s).
@FelixMcFelix FelixMcFelix marked this pull request as draft May 12, 2025 16:11
@FelixMcFelix
Copy link
Collaborator Author

Moved back to draft -- looks like there's a CI issue between older scripts pointing at release vs release-lto. Will fix that up first.

@FelixMcFelix FelixMcFelix marked this pull request as ready for review May 12, 2025 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

opteadm is pulling in tokio as a dependency OpteAdm duplicates a significant amount of code from OpteHdl
1 participant