Remove expected_revision from TCX API

Signed-off-by: Andre Fredette <afredette@redhat.com>
reviewable/pr921/r12
Andre Fredette 2 months ago
parent dc71e5a4f2
commit 3d056c5d45

@ -78,7 +78,6 @@ impl CgroupDevice {
None,
mode.into(),
None,
None,
)
.map_err(|(_, io_error)| SyscallError {
call: "bpf_link_create",

@ -106,7 +106,6 @@ impl CgroupSkb {
None,
mode.into(),
None,
None,
)
.map_err(|(_, io_error)| SyscallError {
call: "bpf_link_create",

@ -84,7 +84,6 @@ impl CgroupSock {
None,
mode.into(),
None,
None,
)
.map_err(|(_, io_error)| SyscallError {
call: "bpf_link_create",

@ -85,7 +85,6 @@ impl CgroupSockAddr {
None,
mode.into(),
None,
None,
)
.map_err(|(_, io_error)| SyscallError {
call: "bpf_link_create",

@ -82,7 +82,6 @@ impl CgroupSockopt {
None,
mode.into(),
None,
None,
)
.map_err(|(_, io_error)| SyscallError {
call: "bpf_link_create",

@ -77,7 +77,6 @@ impl CgroupSysctl {
None,
mode.into(),
None,
None,
)
.map_err(|(_, io_error)| SyscallError {
call: "bpf_link_create",

@ -104,7 +104,6 @@ impl Extension {
Some(btf_id),
0,
None,
None,
)
.map_err(|(_, io_error)| SyscallError {
call: "bpf_link_create",
@ -143,7 +142,6 @@ impl Extension {
Some(btf_id),
0,
None,
None,
)
.map_err(|(_, io_error)| SyscallError {
call: "bpf_link_create",

@ -450,7 +450,6 @@ bitflags::bitflags! {
#[derive(Debug)]
pub struct LinkOrder {
pub(crate) link_ref: LinkRef,
pub(crate) expected_revision: Option<u64>,
pub(crate) flags: MprogFlags,
}
@ -460,7 +459,6 @@ impl Default for LinkOrder {
Self {
link_ref: LinkRef::Fd(0),
flags: MprogFlags::AFTER,
expected_revision: None,
}
}
}
@ -471,7 +469,6 @@ impl LinkOrder {
Self {
link_ref: LinkRef::Id(0),
flags: MprogFlags::BEFORE,
expected_revision: None,
}
}
@ -480,7 +477,6 @@ impl LinkOrder {
Self {
link_ref: LinkRef::Id(0),
flags: MprogFlags::AFTER,
expected_revision: None,
}
}
@ -489,7 +485,6 @@ impl LinkOrder {
Ok(Self {
link_ref: LinkRef::Fd(link.fd()?.as_raw_fd()),
flags: MprogFlags::BEFORE | MprogFlags::LINK,
expected_revision: None,
})
}
@ -498,7 +493,6 @@ impl LinkOrder {
Ok(Self {
link_ref: LinkRef::Fd(link.fd()?.as_raw_fd()),
flags: MprogFlags::AFTER | MprogFlags::LINK,
expected_revision: None,
})
}
@ -507,7 +501,6 @@ impl LinkOrder {
Ok(Self {
link_ref: LinkRef::Id(id.0),
flags: MprogFlags::BEFORE | MprogFlags::LINK | MprogFlags::ID,
expected_revision: None,
})
}
@ -516,7 +509,6 @@ impl LinkOrder {
Ok(Self {
link_ref: LinkRef::Id(id.0),
flags: MprogFlags::AFTER | MprogFlags::LINK | MprogFlags::ID,
expected_revision: None,
})
}
@ -525,7 +517,6 @@ impl LinkOrder {
Ok(Self {
link_ref: LinkRef::Fd(program.fd()?.as_raw_fd()),
flags: MprogFlags::BEFORE,
expected_revision: None,
})
}
@ -534,7 +525,6 @@ impl LinkOrder {
Ok(Self {
link_ref: LinkRef::Fd(program.fd()?.as_raw_fd()),
flags: MprogFlags::AFTER,
expected_revision: None,
})
}
@ -543,7 +533,6 @@ impl LinkOrder {
Self {
link_ref: LinkRef::Id(id.0),
flags: MprogFlags::BEFORE | MprogFlags::ID,
expected_revision: None,
}
}
@ -552,17 +541,8 @@ impl LinkOrder {
Self {
link_ref: LinkRef::Id(id.0),
flags: MprogFlags::AFTER | MprogFlags::ID,
expected_revision: None,
}
}
/// set the expected revision for the link, the revision changes
/// with each modification of the list of attached programs. User space
/// can pass an expected revision when creating a new link. The kernel
/// then rejects the update if the revision has changed.
pub fn set_expected_revision(&mut self, revision: u64) {
self.expected_revision = Some(revision);
}
}
#[cfg(test)]

@ -82,7 +82,6 @@ pub(crate) fn perf_attach(
None,
0,
None,
None,
)
.map_err(|(_, io_error)| SyscallError {
call: "bpf_link_create",

@ -72,7 +72,6 @@ impl SkLookup {
None,
0,
None,
None,
)
.map_err(|(_, io_error)| SyscallError {
call: "bpf_link_create",

@ -76,7 +76,6 @@ impl SockOps {
None,
mode.into(),
None,
None,
)
.map_err(|(_, io_error)| SyscallError {
call: "bpf_link_create",

@ -302,7 +302,6 @@ impl SchedClassifier {
None,
options.flags.bits(),
Some(&options.link_ref),
options.expected_revision,
)
.map_err(|(_, io_error)| SyscallError {
call: "bpf_mprog_attach",

@ -151,7 +151,6 @@ impl Xdp {
None,
flags.bits(),
None,
None,
)
.map_err(|(_, io_error)| SyscallError {
call: "bpf_link_create",

@ -387,7 +387,6 @@ pub(crate) fn bpf_link_create(
btf_id: Option<u32>,
flags: u32,
link_ref: Option<&LinkRef>,
expected_revision: Option<u64>,
) -> SysResult<crate::MockableFd> {
let mut attr = unsafe { mem::zeroed::<bpf_attr>() };
@ -410,10 +409,6 @@ pub(crate) fn bpf_link_create(
attr.link_create.flags = flags;
// since kernel 6.6
if let Some(expected_revision) = expected_revision {
attr.link_create.__bindgen_anon_3.tcx.expected_revision = expected_revision;
}
match link_ref {
Some(LinkRef::Fd(fd)) => {
attr.link_create
@ -854,7 +849,7 @@ pub(crate) fn is_perf_link_supported() -> bool {
let fd = fd.as_fd();
matches!(
// Uses an invalid target FD so we get EBADF if supported.
bpf_link_create(fd, LinkTarget::IfIndex(u32::MAX), bpf_attach_type::BPF_PERF_EVENT, None, 0, None, None),
bpf_link_create(fd, LinkTarget::IfIndex(u32::MAX), bpf_attach_type::BPF_PERF_EVENT, None, 0, None),
// Returns EINVAL if unsupported. EBADF if supported.
Err((_, e)) if e.raw_os_error() == Some(libc::EBADF),
)

@ -104,17 +104,15 @@ async fn tcx_ordering() {
.unwrap();
prog3.load().unwrap();
// Test LinkOrder::last() with correct expected_revision
let mut order: LinkOrder = LinkOrder::last();
order.set_expected_revision(1);
// Test LinkOrder::last()
let order: LinkOrder = LinkOrder::last();
let options = TcAttachOptions::TcxOrder(order);
prog0
.attach_with_options("lo", TcAttachType::Ingress, options)
.unwrap();
// Test LinkOrder::after_program() with correct expected_revision
let mut order = LinkOrder::after_program(prog0).unwrap();
order.set_expected_revision(2);
// Test LinkOrder::after_program()
let order = LinkOrder::after_program(prog0).unwrap();
let options = TcAttachOptions::TcxOrder(order);
let prog1_link_id = prog1
.attach_with_options("lo", TcAttachType::Ingress, options)
@ -122,23 +120,14 @@ async fn tcx_ordering() {
let prog1_link = prog1.take_link(prog1_link_id).unwrap();
// Test incorrect expected_revision and expect an error
let mut order = LinkOrder::after_link(&prog1_link).unwrap();
order.set_expected_revision(7);
let options = TcAttachOptions::TcxOrder(order);
let result = prog2.attach_with_options("lo", TcAttachType::Ingress, options);
assert!(result.is_err());
// Test LinkOrder::after_link() again with expected_revision == 0 which
// means the expected_revision should be ignored.
let mut order = LinkOrder::after_link(&prog1_link).unwrap();
order.set_expected_revision(0);
// Test LinkOrder::after_link()
let order = LinkOrder::after_link(&prog1_link).unwrap();
let options = TcAttachOptions::TcxOrder(order);
prog2
.attach_with_options("lo", TcAttachType::Ingress, options)
.unwrap();
// Test LinkOrder::last() with no expected_revision
// Test LinkOrder::last()
let options = TcAttachOptions::TcxOrder(LinkOrder::last());
prog3
.attach_with_options("lo", TcAttachType::Ingress, options)

Loading…
Cancel
Save