Expand description
A hash map of TCP or UDP sockets.
A SockHash
is used to store TCP or UDP sockets. eBPF programs can then be
attached to the map to inspect, filter or redirect network buffers on those
sockets.
A SockHash
can also be used to redirect packets to sockets contained by the
map using bpf_redirect_map()
, bpf_sk_redirect_hash()
etc.
Minimum kernel version
The minimum kernel version required to use this feature is 4.18.
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<T: Deref<Target = Map>, K: Pod> SockHash<T, K>
impl<T: Deref<Target = Map>, K: Pod> SockHash<T, K>
sourcepub fn get(&self, key: &K, flags: u64) -> Result<RawFd, MapError>
pub fn get(&self, key: &K, flags: u64) -> Result<RawFd, MapError>
Returns the fd of the socket stored at the given key.
sourcepub fn iter(&self) -> MapIter<'_, K, RawFd, Self>ⓘNotable traits for MapIter<'_, K, V, I>impl<K: Pod, V, I: IterableMap<K, V>> Iterator for MapIter<'_, K, V, I> type Item = Result<(K, V), MapError>;
pub fn iter(&self) -> MapIter<'_, K, RawFd, Self>ⓘNotable traits for MapIter<'_, K, V, I>impl<K: Pod, V, I: IterableMap<K, V>> Iterator for MapIter<'_, K, V, I> type Item = Result<(K, V), MapError>;
An iterator visiting all key-value pairs in arbitrary order. The
iterator item type is Result<(K, V), MapError>
.
Trait Implementations
Auto Trait Implementations
impl<T, K> RefUnwindSafe for SockHash<T, K> where
K: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, K> Send for SockHash<T, K> where
K: Send,
T: Send,
impl<T, K> Sync for SockHash<T, K> where
K: Sync,
T: Sync,
impl<T, K> Unpin for SockHash<T, K> where
K: Unpin,
T: Unpin,
impl<T, K> UnwindSafe for SockHash<T, K> where
K: UnwindSafe,
T: UnwindSafe,
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