Skip to content

Commit d556f26

Browse files
authored
Merge pull request bpfman#849 from Billy99/billy99-panic-unwrap
bpfman: Fix panic if XDP prog already loaded
2 parents 217087d + 472a9c8 commit d556f26

File tree

4 files changed

+52
-642
lines changed

4 files changed

+52
-642
lines changed

bpfman/src/multiprog/xdp.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,19 @@ impl XdpDispatcher {
157157
.unwrap();
158158
} else {
159159
let flags = self.mode.as_flags();
160-
let link = dispatcher.attach(&iface, flags).unwrap();
160+
let link = dispatcher.attach(&iface, flags).map_err(|e| {
161+
BpfmanError::Error(format!(
162+
"dispatcher attach failed on interface {iface}: {e}"
163+
))
164+
})?;
161165
let owned_link = dispatcher.take_link(link)?;
162166
let path = format!("{RTDIR_FS_XDP}/dispatcher_{if_index}_link");
163167
let _ = TryInto::<FdLink>::try_into(owned_link)
164-
.unwrap() // TODO: Don't unwrap, although due to minimum kernel version this shouldn't ever panic
168+
.map_err(|e| {
169+
BpfmanError::Error(format!(
170+
"FdLink conversion failed on interface {iface}: {e}"
171+
))
172+
})?
165173
.pin(path)
166174
.map_err(BpfmanError::UnableToPinLink)?;
167175
}

0 commit comments

Comments
 (0)