aya: implement TryFrom<[Program Type]> for FdLink for various program types

Implements TryFrom for FdLink for CgroupSkb, CgroupSock, CgroupSockAddr
and SockOps program types. This allows support for link pinning for
these program types, aligning with the documentation for FdLink.

Fixes: #739

Co-authored-by: Benjamin Barzen <bbarzen@amazon.com>
reviewable/pr1264/r3
Mehnaz Yunus 4 weeks ago
parent 1029e1c46c
commit 6314e6100e

@ -17,6 +17,8 @@ use crate::{
util::KernelVersion,
};
use super::links::LinkError;
/// A program used to inspect or filter network activity for a given cgroup.
///
/// [`CgroupSkb`] programs can be used to inspect or filter network activity
@ -194,3 +196,14 @@ pub enum CgroupSkbAttachType {
/// Attach to egress.
Egress,
}
impl TryFrom<CgroupSkbLink> for FdLink {
type Error = LinkError;
fn try_from(value: CgroupSkbLink) -> Result<Self, Self::Error> {
match value.into_inner() {
CgroupSkbLinkInner::Fd(fd) => Ok(fd),
CgroupSkbLinkInner::ProgAttach(_) => Err(LinkError::InvalidLink),
}
}
}

@ -15,6 +15,8 @@ use crate::{
util::KernelVersion,
};
use super::links::LinkError;
/// A program that is called on socket creation, bind and release.
///
/// [`CgroupSock`] programs can be used to allow or deny socket creation from
@ -161,3 +163,14 @@ define_link_wrapper!(
CgroupSockLinkIdInner,
CgroupSock,
);
impl TryFrom<CgroupSockLink> for FdLink {
type Error = LinkError;
fn try_from(value: CgroupSockLink) -> Result<Self, Self::Error> {
match value.into_inner() {
CgroupSockLinkInner::Fd(fd) => Ok(fd),
CgroupSockLinkInner::ProgAttach(_) => Err(LinkError::InvalidLink),
}
}
}

@ -15,6 +15,8 @@ use crate::{
util::KernelVersion,
};
use super::links::LinkError;
/// A program that can be used to inspect or modify socket addresses (`struct sockaddr`).
///
/// [`CgroupSockAddr`] programs can be used to inspect or modify socket addresses passed to
@ -162,3 +164,14 @@ define_link_wrapper!(
CgroupSockAddrLinkIdInner,
CgroupSockAddr,
);
impl TryFrom<CgroupSockAddrLink> for FdLink {
type Error = LinkError;
fn try_from(value: CgroupSockAddrLink) -> Result<Self, Self::Error> {
match value.into_inner() {
CgroupSockAddrLinkInner::Fd(fd) => Ok(fd),
CgroupSockAddrLinkInner::ProgAttach(_) => Err(LinkError::InvalidLink),
}
}
}

@ -14,6 +14,8 @@ use crate::{
util::KernelVersion,
};
use super::links::LinkError;
/// A program used to work with sockets.
///
/// [`SockOps`] programs can access or set socket options, connection
@ -140,3 +142,14 @@ define_link_wrapper!(
SockOpsLinkIdInner,
SockOps,
);
impl TryFrom<SockOpsLink> for FdLink {
type Error = LinkError;
fn try_from(value: SockOpsLink) -> Result<Self, Self::Error> {
match value.into_inner() {
SockOpsLinkInner::Fd(fd) => Ok(fd),
SockOpsLinkInner::ProgAttach(_) => Err(LinkError::InvalidLink),
}
}
}

Loading…
Cancel
Save