Skip to content

Commit

Permalink
Fix various XDP bugs (#1072)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake-Shadle authored Jan 22, 2025
1 parent ab30d6b commit b346e89
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,6 @@ crates/ebpf/target/

# These are backup files generated by rustfmt
**/*.rs.bk

# Unaccepted snapshots should never be checked in
**/*.snap.new
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/test/tests/snapshots/xdp__changes_ip_version-2.snap
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ PacketHeaders {
),
time_to_live: 63,
protocol: 17 (UDP - User Datagram),
header_checksum: 0,
header_checksum: 28089,
source: [
2,
2,
Expand Down
2 changes: 1 addition & 1 deletion crates/test/tests/snapshots/xdp__simple_forwarding.snap
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ PacketHeaders {
),
time_to_live: 63,
protocol: 17 (UDP - User Datagram),
header_checksum: 0,
header_checksum: 30145,
source: [
2,
2,
Expand Down
11 changes: 7 additions & 4 deletions crates/xdp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,13 @@ pub fn get_default_nic() -> std::io::Result<Option<NicIndex>> {
};

if let Some(def) = def_iface {
return Err(std::io::Error::new(
std::io::ErrorKind::Unsupported,
format!("unable to determine default interface, found {def:?} and {iface:?}"),
));
// A NIC can have multiple routes, so don't error when it comes up again
if def != iface {
return Err(std::io::Error::new(
std::io::ErrorKind::Unsupported,
format!("unable to determine default interface, found {def:?} and {iface:?}"),
));
}
}

def_iface = Some(iface);
Expand Down
6 changes: 6 additions & 0 deletions src/net/xdp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,12 @@ pub fn spawn(workers: XdpWorkers, config: Arc<crate::Config>) -> Result<XdpLoop,
// Now that all the io loops are running, attach the eBPF program to route
// packets to the bound sockets
let mut ebpf_prog = workers.ebpf_prog;

// We use the default flags here, which means that the program will be attached
// in driver mode if the NIC + driver is capable of it, otherwise it will fallback
// to SKB mode. This allows maximum compatibility, and we already provide
// flags to force zerocopy, which relies on driver mode, so the user can use
// that if they don't want the fallback behavior
let xdp_link =
ebpf_prog.attach(workers.nic, quilkin_xdp::aya::programs::XdpFlags::default())?;

Expand Down

0 comments on commit b346e89

Please sign in to comment.