pub struct SkMsg { /* private fields */ }
Expand description
A program used to intercept messages sent with sendmsg()
/sendfile()
.
SkMsg
programs are attached to socket maps, and can be used inspect,
filter and redirect messages sent on sockets. See also SockMap
and
SockHash
.
Minimum kernel version
The minimum kernel version required to use this feature is 4.17.
Examples
use std::convert::{TryFrom, TryInto};
use std::io::Write;
use std::net::TcpStream;
use std::os::unix::io::AsRawFd;
use aya::maps::SockHash;
use aya::programs::SkMsg;
let mut intercept_egress = SockHash::try_from(bpf.map_mut("INTERCEPT_EGRESS")?)?;
let prog: &mut SkMsg = bpf.program_mut("intercept_egress_packet").unwrap().try_into()?;
prog.load()?;
prog.attach(&intercept_egress)?;
let mut client = TcpStream::connect("127.0.0.1:1234")?;
intercept_egress.insert(1234, client.as_raw_fd(), 0)?;
// the write will be intercepted
client.write_all(b"foo")?;
Implementations
sourceimpl SkMsg
impl SkMsg
sourcepub fn load(&mut self) -> Result<(), ProgramError>
pub fn load(&mut self) -> Result<(), ProgramError>
Loads the program inside the kernel.
sourcepub fn attach(
&mut self,
map: &dyn SocketMap
) -> Result<SkMsgLinkId, ProgramError>
pub fn attach(
&mut self,
map: &dyn SocketMap
) -> Result<SkMsgLinkId, ProgramError>
Attaches the program to the given sockmap.
The returned value can be used to detach, see SkMsg::detach.
sourcepub fn detach(&mut self, link_id: SkMsgLinkId) -> Result<(), ProgramError>
pub fn detach(&mut self, link_id: SkMsgLinkId) -> Result<(), ProgramError>
Detaches the program from a sockmap.
See SkMsg::attach.
sourcepub fn take_link(
&mut self,
link_id: SkMsgLinkId
) -> Result<OwnedLink<SkMsgLink>, ProgramError>
pub fn take_link(
&mut self,
link_id: SkMsgLinkId
) -> Result<OwnedLink<SkMsgLink>, ProgramError>
Takes ownership of the link referenced by the provided link_id.
The link will be detached on Drop
and the caller is now responsible
for managing its lifetime.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for SkMsg
impl Send for SkMsg
impl Sync for SkMsg
impl Unpin for SkMsg
impl UnwindSafe for SkMsg
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more