Skip to content
This repository was archived by the owner on Sep 2, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 131 commits
Commits
Show all changes
135 commits
Select commit Hold shift + click to select a range
cba785b
feat: Obtain info via routing sockets
larseggert Oct 1, 2024
f3bd16f
Fixes
larseggert Oct 1, 2024
36d2c49
Fixes
larseggert Oct 1, 2024
3d3833c
Linux
larseggert Oct 1, 2024
b491400
Windows
larseggert Oct 1, 2024
44a1163
Fixes
larseggert Oct 1, 2024
89d1fe7
Clippy
larseggert Oct 1, 2024
ed1795f
Clippy
larseggert Oct 1, 2024
e95c38f
Update src/bsd.rs
larseggert Oct 2, 2024
f2444ce
Try and fix sanitizer issue
larseggert Oct 2, 2024
ee08c78
Rearrange Windows code
larseggert Oct 2, 2024
ff7fb82
Fixes
larseggert Oct 2, 2024
fa0cd57
Merge branch 'main' into feat-from-routing
larseggert Oct 2, 2024
356c669
Fixes
larseggert Oct 2, 2024
66fdaab
Omit win_bindings.rs from codecov (again)
larseggert Oct 2, 2024
4d0e274
Update docs
larseggert Oct 2, 2024
8e35eea
Read all socket responses to allow socket reuse
larseggert Oct 3, 2024
e8060db
Update README
larseggert Oct 3, 2024
71aa8de
Add .clippy.toml
larseggert Oct 3, 2024
6b700d6
Merge branch 'main' into feat-from-routing
larseggert Oct 7, 2024
a58dc65
Update src/windows/mod.rs
larseggert Oct 7, 2024
9c892c7
Drop neli
larseggert Oct 7, 2024
774d6ff
Cleanups
larseggert Oct 7, 2024
856d12b
Nit
larseggert Oct 7, 2024
2cfa562
Fixes
larseggert Oct 7, 2024
c5f0d1f
Fix
larseggert Oct 7, 2024
62de28c
Fix
larseggert Oct 7, 2024
4fda855
Simplify
larseggert Oct 7, 2024
f3336c5
Also install llvm-symbolizer for the sanitizer runs
larseggert Oct 8, 2024
a0816e6
Fixes
larseggert Oct 8, 2024
8fbcbfb
Fixes
larseggert Oct 8, 2024
7825347
Merge branch 'main' into feat-from-routing
larseggert Oct 8, 2024
87eb36c
README
larseggert Oct 8, 2024
9a8b72d
clippy
larseggert Oct 8, 2024
6aac56c
Tweaks
larseggert Oct 9, 2024
a0428ca
Misc improvements
larseggert Oct 10, 2024
cd3b4f3
ASAN_OPTIONS: detect_leaks=1:detect_stack_use_after_return=1
larseggert Oct 10, 2024
dab41d1
Suppress
larseggert Oct 10, 2024
7c51f5f
LSAN_OPTIONS
larseggert Oct 10, 2024
41d51bb
llvm
larseggert Oct 10, 2024
cfa9077
path
larseggert Oct 10, 2024
473fadc
Again
larseggert Oct 10, 2024
30444c3
Again
larseggert Oct 10, 2024
a69908d
Again
larseggert Oct 10, 2024
b80169d
Again
larseggert Oct 10, 2024
75e00c0
Again
larseggert Oct 10, 2024
20b2396
Again
larseggert Oct 10, 2024
86a592f
Again
larseggert Oct 10, 2024
6467f8b
Again
larseggert Oct 10, 2024
9e536ce
Again
larseggert Oct 10, 2024
d8d7dc1
Again
larseggert Oct 10, 2024
3f3fe9a
Again
larseggert Oct 10, 2024
a9b372c
Again
larseggert Oct 10, 2024
ee711fc
Again
larseggert Oct 10, 2024
4d43a3c
Again
larseggert Oct 10, 2024
c58eda9
Update src/linux.rs
larseggert Oct 11, 2024
5f57b4a
Use `OwnedFd`
larseggert Oct 11, 2024
248391b
Address code review
larseggert Oct 21, 2024
4a77574
BSDs and Windows
larseggert Oct 21, 2024
b00aebd
ifconfig
larseggert Oct 21, 2024
075f311
env
larseggert Oct 21, 2024
18a6938
rmx_filler
larseggert Oct 21, 2024
e571427
Debug
larseggert Oct 21, 2024
6942ecc
Debug
larseggert Oct 21, 2024
1eac2ee
send
larseggert Oct 21, 2024
a20ffea
recv
larseggert Oct 21, 2024
0901ad8
Again
larseggert Oct 21, 2024
546a452
Again
larseggert Oct 21, 2024
807116f
Again
larseggert Oct 21, 2024
1304c70
mtu
larseggert Oct 21, 2024
6b7d0f5
Fix cloudflare.com v6 address
larseggert Oct 22, 2024
813ae8d
Undo
larseggert Oct 22, 2024
789d964
rt_metrics
larseggert Oct 22, 2024
c2b27a9
More BSD
larseggert Oct 22, 2024
4691e18
RTAX_IFA
larseggert Oct 22, 2024
76d7eb9
All the BSDs are different, sigh
larseggert Oct 22, 2024
8f71dea
More
larseggert Oct 23, 2024
63ed25f
codecov
larseggert Oct 23, 2024
5155ee7
Again
larseggert Oct 23, 2024
33e9a9b
binstall
larseggert Oct 23, 2024
a873c43
cargo-llvm-cov
larseggert Oct 23, 2024
c9a8d5b
Again
larseggert Oct 23, 2024
b667a86
llvm
larseggert Oct 24, 2024
42b9747
Minimize conversions
larseggert Oct 24, 2024
fe78985
More
larseggert Oct 24, 2024
647308e
Merge branch 'main' into feat-from-routing
larseggert Oct 24, 2024
54c6435
Again
larseggert Oct 24, 2024
59f806b
Again
larseggert Oct 24, 2024
4c95881
Again
larseggert Oct 24, 2024
f9e5544
Again
larseggert Oct 24, 2024
4871a6b
Again
larseggert Oct 24, 2024
707f8ba
More
larseggert Oct 24, 2024
1dc568a
Again
larseggert Oct 24, 2024
ccdc7d5
Again
larseggert Oct 24, 2024
a080cff
Linux fix
larseggert Oct 24, 2024
858f344
More
larseggert Oct 24, 2024
bb96df8
stable
larseggert Oct 24, 2024
f7a9cc5
Simplify
larseggert Oct 25, 2024
fe9b4bd
More comments
larseggert Oct 25, 2024
9a89840
Merge branch 'main' into feat-from-routing
larseggert Oct 28, 2024
017dac4
Use bindgen
larseggert Oct 28, 2024
88a6363
Address code review
larseggert Oct 29, 2024
e02ccc2
Iterator
larseggert Nov 1, 2024
01ab445
Final fixes
larseggert Nov 1, 2024
e632413
Install llvm
larseggert Nov 1, 2024
cccc097
Workflow fixes
larseggert Nov 1, 2024
7f70fa9
Hack
larseggert Nov 1, 2024
acda937
Fix?
larseggert Nov 1, 2024
a0f8aac
CI
larseggert Nov 1, 2024
7aa1395
llvm-16.0.6p30
larseggert Nov 1, 2024
7601069
netbsd
larseggert Nov 1, 2024
cefe001
netbsd
larseggert Nov 1, 2024
a5b2795
clang
larseggert Nov 1, 2024
c372658
Remove unused code.
larseggert Nov 1, 2024
fc4793f
More helpers
larseggert Nov 1, 2024
91786da
Tweaks
larseggert Nov 2, 2024
6bb1324
Fix
larseggert Nov 2, 2024
15ccf0b
Address code review
larseggert Nov 8, 2024
f52f2d4
Merge branch 'main' into feat-from-routing
larseggert Nov 8, 2024
6b3dd15
Update .github/workflows/check.yml
larseggert Nov 11, 2024
fd20bfe
Update .github/workflows/check.yml
larseggert Nov 11, 2024
23867de
Update .github/workflows/check.yml
larseggert Nov 11, 2024
c27bbce
Update src/bsd.rs
larseggert Nov 12, 2024
226a16d
Update src/linux.rs
larseggert Nov 12, 2024
58f761b
Address first batch of comments from @martinthomson
larseggert Nov 12, 2024
a6f8773
Suppress shellcheck warning
larseggert Nov 12, 2024
26ea760
More suggestions from @martinthomson
larseggert Nov 12, 2024
269ff34
Use `std::io::Result`
larseggert Nov 12, 2024
dfdf14a
clippy
larseggert Nov 15, 2024
bd0305d
Nits
larseggert Nov 15, 2024
a3b2240
Merge branch 'main' into feat-from-routing
larseggert Nov 18, 2024
0a07c86
Suggestions from @martinthomson
larseggert Nov 21, 2024
766a075
Fix
larseggert Nov 21, 2024
bc104e9
Macro
larseggert Nov 21, 2024
0f1c742
Not Windows
larseggert Nov 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .codecov.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
ignore:
- "src/win_bindings.rs"

# Do not notify until at least three results have been uploaded from the CI pipeline.
# (This corresponds to the three main platforms we support: Linux, macOS, and Windows.)
Expand Down
128 changes: 96 additions & 32 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,34 @@ concurrency:
permissions:
contents: read

defaults:
run:
shell: bash

jobs:
toolchains:
runs-on: ubuntu-latest
outputs:
toolchains: ${{ steps.toolchains.outputs.toolchains }}
steps:
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
with:
sparse-checkout: Cargo.toml
- id: toolchains
run: |
msrv="$(grep rust-version Cargo.toml | tr -d '"' | cut -f3 -d\ )"
echo "toolchains=[\"$msrv\", \"stable\", \"nightly\"]" >> "$GITHUB_OUTPUT"

check:
needs: toolchains
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
# Keep low end in sync with Cargo.toml
rust-toolchain: [1.76.0, stable, nightly]
rust-toolchain: ${{ fromJSON(needs.toolchains.outputs.toolchains) }}
type: [debug]
include:
# Also do some release builds on the latest OS versions.
- os: ubuntu-latest
rust-toolchain: stable
type: release
Expand All @@ -37,6 +55,7 @@ jobs:
- os: windows-latest
rust-toolchain: stable
type: release
# Also do some debug builds on the oldest OS versions.
- os: ubuntu-20.04
rust-toolchain: stable
type: debug
Expand All @@ -49,9 +68,6 @@ jobs:
env:
BUILD_TYPE: ${{ matrix.type == 'release' && '--release' || '' }}
runs-on: ${{ matrix.os }}
defaults:
run:
shell: bash

steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
Expand All @@ -65,30 +81,37 @@ jobs:
- uses: ./neqo/.github/actions/rust
with:
version: ${{ matrix.rust-toolchain }}
components: ${{ matrix.rust-toolchain == 'stable' && 'llvm-tools-preview' || '' }} ${{ matrix.rust-toolchain == 'nightly' && 'rust-src' || '' }}
components: ${{ matrix.rust-toolchain == 'stable' && 'llvm-tools' || '' }} ${{ matrix.rust-toolchain == 'nightly' && 'rust-src' || '' }}
tools: ${{ matrix.rust-toolchain == 'stable' && 'cargo-llvm-cov, ' || '' }}
token: ${{ secrets.GITHUB_TOKEN }}

- name: Check
run: |
# shellcheck disable=SC2086
cargo +${{ matrix.rust-toolchain }} check $BUILD_TYPE --all-targets
OPTIONS=(--all-targets)
if [ "$BUILD_TYPE" ]; then
OPTIONS+=("$BUILD_TYPE")
fi
cargo +${{ matrix.rust-toolchain }} check "${OPTIONS[@]}"

- name: Run tests and determine coverage
env:
RUST_LOG: trace
run: |
# shellcheck disable=SC2086
OPTIONS=(--no-fail-fast)
if [ "$BUILD_TYPE" ]; then
OPTIONS+=("$BUILD_TYPE")
fi
if [ "${{ matrix.rust-toolchain }}" == "stable" ] && [ "${{ matrix.type }}" == "debug" ] && [ "${{endsWith(matrix.os, '-latest') && 'latest' || '' }}" == "latest" ]; then
cargo +${{ matrix.rust-toolchain }} llvm-cov test $BUILD_TYPE --no-fail-fast --lcov --output-path lcov.info
cargo +${{ matrix.rust-toolchain }} llvm-cov test "${OPTIONS[@]}" --lcov --output-path lcov.info
else
if [ "${{ startsWith(matrix.os, 'windows') && 'windows' || '' }}" == "windows" ]; then
# The codegen_windows_bindings test only succeeds when run via llvm-cov?!
export FILTER="-- --skip codegen_windows_bindings"
OPTIONS+=(-- --skip codegen_windows_bindings)
fi
cargo +${{ matrix.rust-toolchain }} test $BUILD_TYPE --no-fail-fast $FILTER
cargo +${{ matrix.rust-toolchain }} test "${OPTIONS[@]}"
fi
cargo +${{ matrix.rust-toolchain }} bench --no-run

- uses: codecov/codecov-action@5c47607acb93fed5485fdbf7232e8a31425f672a # v5.0.2
with:
files: lcov.info
Expand All @@ -103,18 +126,30 @@ jobs:
if: (matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest') && matrix.rust-toolchain == 'nightly'
env:
RUST_LOG: trace
ASAN_OPTIONS: detect_leaks=1:detect_stack_use_after_return=1
run: |
if [ "${{ matrix.os }}" = "ubuntu-latest" ]; then
sudo apt-get install -y --no-install-recommends llvm
TARGET="x86_64-unknown-linux-gnu"
SANITIZERS="address thread leak memory"
elif [ "${{ matrix.os }}" = "macos-latest" ]; then
# llvm-symbolizer (as part of llvm) is installed by default on macOS runners
TARGET="aarch64-apple-darwin"
# no memory and leak sanitizer support yet
SANITIZERS="address thread"
# Suppress non-mtu leaks on macOS. TODO: Check occasionally if these are still needed.
{
echo "leak:dyld4::RuntimeState"
echo "leak:fetchInitializingClassList"
} > suppressions.txt
# shellcheck disable=SC2155
export LSAN_OPTIONS="suppressions=$(pwd)/suppressions.txt"
fi
for sanitizer in $SANITIZERS; do
echo "Running tests with $sanitizer sanitizer..."
RUSTFLAGS="-Z sanitizer=$sanitizer" RUSTDOCFLAGS="-Z sanitizer=$sanitizer" cargo +nightly test -Z build-std --target "$TARGET"
export RUSTFLAGS="-Z sanitizer=$sanitizer"
export RUSTDOCFLAGS="$RUSTFLAGS"
cargo +nightly test -Z build-std --target "$TARGET"
done

clippy:
Expand All @@ -123,9 +158,6 @@ jobs:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
Expand Down Expand Up @@ -226,50 +258,82 @@ jobs:

steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- run: curl -o rustup.sh --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs

- if: matrix.os == 'freebsd'
uses: vmactions/freebsd-vm@debf37ca7b7fa40e19c542ef7ba30d6054a706a4
with:
usesh: true
copyback: false
envs: "CARGO_TERM_COLOR RUST_BACKTRACE GITHUB_ACTIONS"
prepare: |
mkdir -p /usr/local/etc/pkg/repos
sed 's/quarterly/latest/' /etc/pkg/FreeBSD.conf > /usr/local/etc/pkg/repos/FreeBSD.conf
pkg update
pkg install -y rust
pkg install -y curl llvm
run: |
sh rustup.sh --default-toolchain stable --component llvm-tools -y
. "$HOME/.cargo/env"
export RUST_LOG=trace
cargo install cargo-llvm-cov --locked
cargo check --all-targets
RUST_LOG=trace cargo test --no-fail-fast
cargo clippy
cargo llvm-cov test --no-fail-fast --lcov --output-path lcov.info
cargo test --no-fail-fast --release

- if: matrix.os == 'openbsd'
uses: vmactions/openbsd-vm@0cfe06e734a0ea3a546fca7ebf200b984b94d58a
with:
usesh: true
copyback: false
envs: "CARGO_TERM_COLOR RUST_BACKTRACE GITHUB_ACTIONS"
prepare: |
pkg_add rust
pkg_add rust llvm-16.0.6p30 # rustup doesn't support OpenBSD at all
run: |
export LIBCLANG_PATH=/usr/local/llvm16/lib
export RUST_LOG=trace
cargo check --all-targets
RUST_LOG=trace cargo test --no-fail-fast
cargo clippy
cargo test --no-fail-fast
cargo test --no-fail-fast --release

- if: matrix.os == 'netbsd'
uses: vmactions/netbsd-vm@7c9086fdb4cc1aa814cda6e305390c2b966551a9
with:
usesh: true
copyback: false
envs: "CARGO_TERM_COLOR RUST_BACKTRACE GITHUB_ACTIONS"
prepare: |
/usr/sbin/pkg_add rust
/usr/sbin/pkg_add pkgin
pkgin -y install curl clang
run: |
sh rustup.sh --default-toolchain stable --component llvm-tools -y
. "$HOME/.cargo/env"
export LIBCLANG_PATH=/usr/pkg/lib
export RUST_LOG=trace
cargo install cargo-llvm-cov --locked
cargo check --all-targets
RUST_LOG=trace cargo test --no-fail-fast
cargo clippy
cargo test --no-fail-fast
# FIXME: error[E0463]: can't find crate for `profiler_builtins`,
# so don't fail the workflow when that happens.
cargo llvm-cov test --no-fail-fast --lcov --output-path lcov.info || true
cargo test --no-fail-fast --release

- if: matrix.os == 'solaris'
uses: vmactions/solaris-vm@a89b9438868c70db27e41625f0a5de6ff5e90809
with:
usesh: true
copyback: false
prepare: |
pkg install cargo
envs: "CARGO_TERM_COLOR RUST_BACKTRACE GITHUB_ACTIONS"
run: |
sh rustup.sh --default-toolchain stable --component llvm-tools -y
. "$HOME/.cargo/env"
export RUST_LOG=trace
cargo install cargo-llvm-cov --locked
cargo check --all-targets
RUST_LOG=trace cargo test --no-fail-fast
cargo clippy
cargo llvm-cov test --no-fail-fast --lcov --output-path lcov.info
cargo test --no-fail-fast --release

- uses: codecov/codecov-action@b9fd7d16f6d7d1b5d2bec1a2887e65ceed900238 # v4.6.0
with:
file: lcov.info
fail_ci_if_error: false
token: ${{ secrets.CODECOV_TOKEN }}
verbose: true
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
19 changes: 11 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ edition = "2021"
license = "MIT OR Apache-2.0"
# Don't increase beyond what Firefox is currently using:
# https://searchfox.org/mozilla-central/search?q=MINIMUM_RUST_VERSION&path=python/mozboot/mozboot/util.py
# Also keep in sync with .github/workflows/check.yml
rust-version = "1.76.0"

[badges]
Expand All @@ -23,18 +22,22 @@ maintenance = { status = "actively-developed", branch = "main" }

[dependencies]
# Don't increase beyond what Firefox is currently using: https://searchfox.org/mozilla-central/source/Cargo.lock
libc = { version = "0.2", default-features = false }
libc = { version = ">=0.2.161", default-features = false }
static_assertions = { version = "1.1", default-features = false }

[dev-dependencies]
rand = { version = "0.8", default-features = false, features = ["std", "std_rng"] }

[target."cfg(windows)".dependencies]
[target.'cfg(windows)'.dependencies]
# Don't increase beyond what Firefox is currently using: https://searchfox.org/mozilla-central/source/Cargo.lock
windows-core = "0.58"
windows-targets = "0.52"

[target."cfg(windows)".dev-dependencies]
windows-bindgen = { version = "0.58" } # MSRV is 1.70
[build-dependencies]
cfg_aliases = "0.2"

[target.'cfg(not(windows))'.build-dependencies]
bindgen = { version = "0.69.5" }

[target.'cfg(windows)'.build-dependencies]
windows-bindgen = { version = "0.58" }

[lints.clippy]
cargo = { level = "warn", priority = -1 }
Expand Down
15 changes: 6 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,15 @@ towards a given destination `SocketAddr`, optionally from a given local `SocketA

## Usage

This crate exports a single function `interface_and_mtu` that, given a pair of local and remote `SocketAddr`s, returns the name and [maximum transmission unit (MTU)](https://en.wikipedia.org/wiki/Maximum_transmission_unit) of the local network interface used by a socket bound to the local address and connected towards the remote destination.

If the local address is `None`, the function will let the operating system choose the local
address based on the given remote address. If the remote address is `None`, the function will
return the name and MTU of the local network interface with the given local address.
This crate exports a single function `interface_and_mtu` that returns the name and
[maximum transmission unit (MTU)](https://en.wikipedia.org/wiki/Maximum_transmission_unit)
of the outgoing network interface towards a remote destination identified by an `IpAddr`.

## Example

```rust
let saddr = "127.0.0.1:443".parse().unwrap();
let (name, mtu) = mtu::interface_and_mtu(&(None, saddr)).unwrap();
println!("MTU for {saddr:?} is {mtu} on {name}");
let destination = IpAddr::V4(Ipv4Addr::LOCALHOST);
let (name, mtu): (String, usize) = mtu::interface_and_mtu(destination).unwrap();
println!("MTU towards {destination} is {mtu} on {name}");
```

## Supported Platforms
Expand Down
Loading