Skip to content

Commit 348a53c

Browse files
committed
determine NetworkDevice to use for xdp early
1 parent ef5d037 commit 348a53c

File tree

7 files changed

+21
-36
lines changed

7 files changed

+21
-36
lines changed

Cargo.lock

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

core/src/validator.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,10 +1573,7 @@ impl Validator {
15731573
.port();
15741574
let src_ip = match node.bind_ip_addrs.active() {
15751575
IpAddr::V4(ip) if !ip.is_unspecified() => Some(ip),
1576-
IpAddr::V4(_unspecified) => xdp_config
1577-
.interface
1578-
.as_ref()
1579-
.and_then(|iface| master_ip_if_bonded(iface)),
1576+
IpAddr::V4(_unspecified) => master_ip_if_bonded(&xdp_config.network_device.if_name),
15801577
_ => panic!("IPv6 not supported"),
15811578
};
15821579
let (rtx, sender) = XdpRetransmitter::new(xdp_config, src_port, src_ip, exit.clone())

turbine/src/xdp.rs

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,8 @@ pub use agave_xdp::set_cpu_affinity;
33
#[cfg(target_os = "linux")]
44
use {
55
agave_xdp::{
6-
device::{NetworkDevice, QueueId},
7-
load_xdp_program,
8-
route::Router,
9-
route_monitor::RouteMonitor,
10-
tx_loop::tx_loop,
6+
device::QueueId, get_network_device::NetworkDevice, load_xdp_program, route::Router,
7+
route_monitor::RouteMonitor, tx_loop::tx_loop,
118
},
129
arc_swap::ArcSwap,
1310
crossbeam_channel::TryRecvError,
@@ -29,7 +26,7 @@ const ROUTE_MONITOR_UPDATE_INTERVAL: Duration = Duration::from_millis(50);
2926

3027
#[derive(Clone, Debug)]
3128
pub struct XdpConfig {
32-
pub interface: Option<String>,
29+
pub network_device: NetworkDevice,
3330
pub cpus: Vec<usize>,
3431
pub zero_copy: bool,
3532
// The capacity of the channel that sits between retransmit stage and each XDP thread that
@@ -42,21 +39,10 @@ impl XdpConfig {
4239
const DEFAULT_RTX_CHANNEL_CAP: usize = 1_000_000;
4340
}
4441

45-
impl Default for XdpConfig {
46-
fn default() -> Self {
47-
Self {
48-
interface: None,
49-
cpus: vec![],
50-
zero_copy: false,
51-
rtx_channel_cap: Self::DEFAULT_RTX_CHANNEL_CAP,
52-
}
53-
}
54-
}
55-
5642
impl XdpConfig {
57-
pub fn new(interface: Option<impl Into<String>>, cpus: Vec<usize>, zero_copy: bool) -> Self {
43+
pub fn new(network_device: NetworkDevice, cpus: Vec<usize>, zero_copy: bool) -> Self {
5844
Self {
59-
interface: interface.map(|s| s.into()),
45+
network_device,
6046
cpus,
6147
zero_copy,
6248
rtx_channel_cap: XdpConfig::DEFAULT_RTX_CHANNEL_CAP,
@@ -138,19 +124,15 @@ impl XdpRetransmitter {
138124
};
139125
const DROP_CHANNEL_CAP: usize = 1_000_000;
140126

127+
let dev = config.network_device;
128+
141129
// switch to higher caps while we setup XDP. We assume that an error in
142130
// this function is irrecoverable so we don't try to drop on errors.
143131
for cap in [CAP_NET_ADMIN, CAP_NET_RAW, CAP_BPF, CAP_PERFMON] {
144132
caps::raise(None, CapSet::Effective, cap)
145133
.map_err(|e| format!("failed to raise {cap:?} capability: {e}"))?;
146134
}
147135

148-
let dev = Arc::new(if let Some(interface) = config.interface {
149-
NetworkDevice::new(interface).unwrap()
150-
} else {
151-
NetworkDevice::new_from_default_route().unwrap()
152-
});
153-
154136
let ebpf = if config.zero_copy {
155137
Some(load_xdp_program(&dev).map_err(|e| format!("failed to attach xdp program: {e}"))?)
156138
} else {
@@ -205,7 +187,7 @@ impl XdpRetransmitter {
205187
.zip(config.cpus.into_iter())
206188
.enumerate()
207189
{
208-
let dev = Arc::clone(&dev);
190+
let dev = dev.clone();
209191
let drop_sender = drop_sender.clone();
210192
let atomic_router = Arc::clone(&atomic_router);
211193
threads.push(

validator/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ solana-vote-program = { workspace = true }
9191
symlink = { workspace = true }
9292
thiserror = { workspace = true }
9393
tokio = { workspace = true }
94+
agave-xdp ={workspace=true}
9495

9596
[target.'cfg(not(any(target_env = "msvc", target_os = "freebsd")))'.dependencies]
9697
jemallocator = { workspace = true }

validator/src/commands/run/execute.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use {
1111
snapshot_config::{SnapshotConfig, SnapshotUsage},
1212
ArchiveFormat, SnapshotInterval, SnapshotVersion,
1313
},
14+
agave_xdp::get_network_device::get_network_device,
1415
clap::{crate_name, value_t, value_t_or_exit, values_t, values_t_or_exit, ArgMatches},
1516
crossbeam_channel::unbounded,
1617
log::*,
@@ -462,11 +463,10 @@ pub fn execute(
462463
let xdp_interface = matches.value_of("retransmit_xdp_interface");
463464
let xdp_zero_copy = matches.is_present("retransmit_xdp_zero_copy");
464465
let retransmit_xdp = matches.value_of("retransmit_xdp_cpu_cores").map(|cpus| {
465-
XdpConfig::new(
466-
xdp_interface,
467-
parse_cpu_ranges(cpus).unwrap(),
468-
xdp_zero_copy,
469-
)
466+
// this will only succeed on linux
467+
let xdp_device =
468+
get_network_device(xdp_interface).expect("XDP interface must be a valid net device");
469+
XdpConfig::new(xdp_device, parse_cpu_ranges(cpus).unwrap(), xdp_zero_copy)
470470
});
471471

472472
let account_paths: Vec<PathBuf> =

xdp/src/device.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ use {
2424
#[derive(Copy, Clone, Debug)]
2525
pub struct QueueId(pub u64);
2626

27+
#[derive(Debug, Clone)]
2728
pub struct NetworkDevice {
2829
if_index: u32,
29-
if_name: String,
30+
pub if_name: String,
3031
}
3132

3233
impl NetworkDevice {

xdp/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ pub mod umem;
3636

3737
#[cfg(target_os = "linux")]
3838
pub use program::load_xdp_program;
39+
40+
pub mod get_network_device;
41+
3942
use std::io;
4043

4144
#[cfg(target_os = "linux")]

0 commit comments

Comments
 (0)