Repository navigation
Code hygiene: drop unused csv crate, document unsafe blocks, audit dead_code allows - #182
Merged
Merged
Conversation
CSV export is written by hand in src/export/csv.rs; the csv crate was never referenced. The 'pub use csv::*' in src/export/mod.rs re-exports the local module, not the crate.
Add a SAFETY comment to each unsafe block naming the invariant it relies on (fd validity, buffer pointers and lengths, zeroable C structs, the cmsg bounds read_cmsg_ttl needs) and enable clippy's undocumented_unsafe_blocks lint crate-wide so new blocks need one too. The root-only on-wire test in rawip.rs now reads through socket2's safe Read impl instead of reinterpreting a MaybeUninit buffer.
Delete items unused in every cfg: ProbeResult (public, listed under Removed), create_udp_send_socket, create_udp_dgram_socket_bound, IxLookup::prefix_count, SocketCapability::Dgram, Theme::border_focused. Gate test-only helpers with #[cfg(test)] (build_tcp_syn and its consts, build_udp_payload, the raw-IPv6 ICMP parser chain in correlate.rs). Give public library API kept for lib users a reason, and narrow InterfaceInfo::index to non-macOS.
The cmsg_len >= CMSG_LEN(0) + 1 check only makes data_len nonzero. The bytes are readable because the kernel (or the test) wrote cmsg_len to end inside the control buffer and the caller skips MSG_CTRUNC.
The engine imports rawip::IPPROTO_UDP and correlate.rs has its own, so this one is dead on every platform.
# Conflicts: # CHANGELOG.md # src/lookup/ix.rs
lance0
marked this pull request as ready for review
November 14, 2026 21:03
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hygiene only. Nothing here changes runtime behavior. The one API change is the removal of the public
ttl::state::ProbeResult, which is breaking for library users and is listed under Removed in the CHANGELOG.1. Remove the unused
csvcrateCSV export is written by hand in
src/export/csv.rs. Thepub use csv::*line insrc/export/mod.rsre-exports that local module, not the crate. Nothing in src, tests, build.rs or examples refers to the crate, and cargo'sunused_dependencieslint flags it on master. The entry is gone from Cargo.toml, and Cargo.lock dropscsvandcsv-core.2. SAFETY comments and a lint
Each
unsafeblock now has a// SAFETY:comment that names the invariant it depends on: fd validity, live pointer/length pairs in recvmsg, zeroable C structs, the sockaddr family casts, and the cmsg bounds thatread_cmsg_ttlrequires. This covers the Linux, macOS, FreeBSD, NetBSD and Windows cfg-gated blocks.[lints.clippy] undocumented_unsafe_blocks = "warn"is now set in Cargo.toml, so the-D warningsclippy runs in CI (Linux, macOS, FreeBSD, Windows) enforce it.The comments in the
set_dont_fragmentsetsockopt blocks sit inside the block. That keeps them off the lines #176 edits, so the two PRs merge cleanly.The root-only on-wire test in rawip.rs now reads through socket2's safe
Readimpl. It no longer reinterprets aMaybeUninitbuffer.I kept
libc::if_nametoindex. No existing safe API matches what it does.3.
allow(dead_code)auditDeleted (unused in every cfg):
ttl::state::ProbeResult: public, so this is a breaking library change (CHANGELOG Removed).create_udp_send_socketandcreate_udp_dgram_socket_boundudp::IPPROTO_UDP: the engine usesrawip::IPPROTO_UDPand correlate.rs has its own.IxLookup::prefix_countSocketCapability::Dgram: never constructed on any platform.Theme::border_focused: never read. The theme.rs diff also includes rustfmt re-aligning trailing comments.IPV6_NH_HOP_BY_HOP.#[cfg(test)](used only by tests):build_tcp_syn,TCP_SRC_PORTandDEFAULT_TCP_PAYLOADbuild_udp_payloadparse_icmp_response_v6,skip_ipv6_extension_headers,parse_icmp_error_payload_v6_with_mtuandIPV6_NH_ICMPV6.I gated the chain with an attribute instead of deleting it, so this PR stays clear of the parser code that PMTUD DF cleanup, PMTUD tick lock, and UDP header-only ICMP quotes #176 adds right after
parse_icmp_error_payload_v6_with_mtu. It can be deleted in a follow-up, along with the third case in its test.cfg_attr:InterfaceInfo::indexis read only by the macOS bind path.Kept, with a reason:
export_json_string,generate_report_string,ResponderStats::record_timeout,FlowPathStats::new/loss_pctandHop::record_response.BatchedResponse::responder_scope_id: never read. Deleting it is a logic edit in receiver.rs.Testing
cargo fmt --check,cargo clippy --all-targets -- -D warningswith default features and with--no-default-features,cargo test, andcargo test --no-default-featuresall pass.RUSTFLAGS='--cfg per_probe_send'clippy (the BSD send path compiled on Linux) is clean too.ttl -p icmp -c 3 --json 1.1.1.1andttl -p udp -c 3 --json 1.1.1.1, against a master build: the same responders, sent and received counts on every hop up to the destination in both modes.src/lookup/ix.rs, where Bound per-hop responders, the live event log and PeeringDB reads #178 deletes thefetch_*helpers next to the deletedprefix_count(drop both sides), plus the usual CHANGELOG hunk. After resolving, fmt, both clippy runs andcargo testpass. No unsafe block in those PRs lacks a SAFETY comment.Not verified
setsockoptpattern as the Linux one.