Skip to content

Commit f87ceef

Browse files
committed
vey-reuseport: add udp reuseport socket selector
1 parent 14c7389 commit f87ceef

13 files changed

Lines changed: 897 additions & 3 deletions

File tree

.github/workflows/codecov.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ jobs:
4646
run: |
4747
sudo apt-get update
4848
sudo apt-get install capnproto libjemalloc-dev libmimalloc-dev libc-ares-dev libssl-dev liblua5.4-dev
49+
sudo apt-get install libbpf-dev linux-bpf-dev
4950
- name: Install binutils
5051
run: |
5152
cargo install cargo-binutils@0.3.6

.github/workflows/linux-basic.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ jobs:
5252
run: |
5353
sudo apt-get update
5454
sudo apt-get install capnproto libjemalloc-dev libmimalloc-dev libc-ares-dev libssl-dev liblua5.4-dev
55+
sudo apt-get install libbpf-dev linux-bpf-dev
5556
- name: Cargo build
5657
run: cargo build --features jemalloc,lua54
5758
- name: Cargo test
@@ -73,5 +74,6 @@ jobs:
7374
run: |
7475
sudo apt-get update
7576
sudo apt-get install capnproto libjemalloc-dev libmimalloc-dev libc-ares-dev libssl-dev liblua5.4-dev
77+
sudo apt-get install libbpf-dev linux-bpf-dev
7678
- name: Cargo clippy
7779
run: cargo clippy --tests --workspace --features jemalloc,lua54 -- --deny warnings

.github/workflows/macos-basic.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,4 @@ jobs:
5050
- name: Cargo clippy
5151
run: cargo clippy --tests --features jemalloc,lua55 -- --deny warnings
5252
- name: Cargo test
53-
run: cargo test --workspace --features jemalloc,lua55 --exclude vey-journal
53+
run: cargo test --workspace --features jemalloc,lua55 --exclude vey-journal --exclude vey-reuseport

.github/workflows/windows-basic.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,4 @@ jobs:
5454
- name: Cargo clippy
5555
run: cargo clippy --no-default-features --features $env:WIN_FEATURES --tests -- --deny warnings
5656
- name: Cargo test
57-
run: cargo test --no-default-features --features $env:WIN_FEATURES --workspace --exclude vey-journal
57+
run: cargo test --no-default-features --features $env:WIN_FEATURES --workspace --exclude vey-journal --exclude vey-reuseport

Cargo.lock

Lines changed: 58 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ members = [
4949
"lib/vey-openssl",
5050
"lib/vey-redis-client",
5151
"lib/vey-resolver",
52+
"lib/vey-reuseport",
5253
"lib/vey-runtime",
5354
"lib/vey-rustls-provider",
5455
"lib/vey-slog-types",
@@ -109,6 +110,7 @@ chrono = { version = "0.4.45", default-features = false }
109110
ascii = "1.0"
110111
humanize-rs = "0.1"
111112
zeroize = "1.8"
113+
zerocopy = { version = "0.8", default-features = false, features = ["derive"] }
112114
#
113115
portable-atomic = "1.9"
114116
itoa = "1.0"
@@ -187,6 +189,7 @@ capnpc = "0.26"
187189
libc = "0.2.182"
188190
rustix = { version = "1.1", default-features = false }
189191
windows-sys = "0.61"
192+
socket2 = { version = "0.6.4", features = ["all"] }
190193
#
191194
serde = "1.0"
192195
yaml-rust = { package = "yaml-rust2", version = "0.11" }
@@ -233,6 +236,7 @@ vey-msgpack = { version = "0.4", path = "lib/vey-msgpack" }
233236
vey-openssl = { version = "0.4", path = "lib/vey-openssl" }
234237
vey-redis-client = { version = "0.3", path = "lib/vey-redis-client" }
235238
vey-resolver = { version = "0.9", path = "lib/vey-resolver" }
239+
vey-reuseport = { version = "0.1", path = "lib/vey-reuseport" }
236240
vey-runtime = { version = "0.5", path = "lib/vey-runtime" }
237241
vey-rustls-provider = { version = "0.1", path = "lib/vey-rustls-provider" }
238242
vey-slog-types = { version = "0.3", path = "lib/vey-slog-types" }

lib/vey-reuseport/Cargo.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[package]
2+
name = "vey-reuseport"
3+
version = "0.1.0"
4+
license.workspace = true
5+
edition.workspace = true
6+
rust-version.workspace = true
7+
8+
[dependencies]
9+
anyhow.workspace = true
10+
libbpf-sys = { version = "1.7", default-features = false }
11+
libbpf-rs = { version = "0.26", default-features = false }
12+
libc.workspace = true
13+
log.workspace = true
14+
zerocopy.workspace = true
15+
socket2.workspace = true
16+
17+
[build-dependencies]

lib/vey-reuseport/build.rs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
* SPDX-FileCopyrightText: 2026 VEY-OSS Developers.
4+
*/
5+
6+
use std::path::PathBuf;
7+
use std::process::Command;
8+
use std::{env, fs};
9+
10+
fn main() {
11+
let mut out = PathBuf::from(env::var("OUT_DIR").unwrap());
12+
out.push("udp.skel.rs");
13+
14+
compile_single("udp");
15+
}
16+
17+
fn compile_single(name: &str) {
18+
let mut source = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
19+
source.push("src");
20+
source.push("bpf");
21+
source.push(format!("{name}.bpf.c"));
22+
23+
println!("cargo:rerun-if-changed={}", source.display());
24+
25+
let mut out = PathBuf::from(env::var("OUT_DIR").unwrap());
26+
out.push(format!("{name}.bpf.o"));
27+
28+
let mut cmd = Command::new("clang");
29+
30+
let mut arch_path = PathBuf::from("/usr/lib/linux/uapi");
31+
if let Ok(true) = fs::exists(&arch_path) {
32+
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap();
33+
match target_arch.as_str() {
34+
"aarch64" => arch_path.push("arm64"),
35+
"x86_64" => arch_path.push("x86"),
36+
"loongarch64" => arch_path.push("loongaarch"),
37+
"powerpc64" | "powerpc64le" => arch_path.push("powerpc"),
38+
"riscv64a23" | "riscv64gc" => arch_path.push("riscv"),
39+
"s390x" => arch_path.push("s390"),
40+
"sparc64" => arch_path.push("sparc"),
41+
"mips64" | "mips64el" | "mipsisa64r6" | "mipsisa64r6el" => arch_path.push("mips"),
42+
arch => {
43+
panic!("Unsupported architecture: {arch}");
44+
}
45+
}
46+
cmd.arg("-I").arg(&arch_path);
47+
}
48+
49+
cmd.arg("-g")
50+
.arg("-O2")
51+
.arg("-target")
52+
.arg("bpf")
53+
.arg("-Wno-visibility")
54+
.arg("-c")
55+
.arg(source)
56+
.arg("-o")
57+
.arg(out);
58+
59+
let output = cmd.output().unwrap();
60+
if !output.stderr.is_empty() {
61+
let stderr = String::from_utf8_lossy(&output.stderr);
62+
for line in stderr.split("\n") {
63+
if !line.trim().is_empty() {
64+
println!("cargo:warning=STDERR:{}", line);
65+
}
66+
}
67+
}
68+
if !output.status.success() {
69+
panic!("{name} bpf compile failed");
70+
}
71+
}

0 commit comments

Comments
 (0)