bpf: Implement redirect for skbs on sockmap/sockhash

This implements redirect_skb and renames redirect to redirect_msg

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
pull/103/head
Dave Tucker 3 years ago
parent 2206fb6456
commit 2a8ba55b7e

@ -4,9 +4,9 @@ use aya_bpf_cty::c_void;
use crate::{
bindings::{bpf_map_def, bpf_map_type::BPF_MAP_TYPE_SOCKHASH, bpf_sock_ops},
helpers::{bpf_msg_redirect_hash, bpf_sock_hash_update},
helpers::{bpf_msg_redirect_hash, bpf_sk_redirect_hash, bpf_sock_hash_update},
maps::PinningType,
programs::SkMsgContext,
programs::{SkMsgContext, SkSkbContext},
BpfContext,
};
@ -66,7 +66,7 @@ impl<K> SockHash<K> {
}
}
pub unsafe fn redirect(&mut self, ctx: &SkMsgContext, key: &mut K, flags: u64) -> i64 {
pub unsafe fn redirect_msg(&mut self, ctx: &SkMsgContext, key: &mut K, flags: u64) -> i64 {
bpf_msg_redirect_hash(
ctx.as_ptr() as *mut _,
&mut self.def as *mut _ as *mut _,
@ -74,4 +74,13 @@ impl<K> SockHash<K> {
flags,
)
}
pub unsafe fn redirect_skb(&mut self, ctx: &SkSkbContext, key: &mut K, flags: u64) -> i64 {
bpf_sk_redirect_hash(
ctx.as_ptr() as *mut _,
&mut self.def as *mut _ as *mut _,
key as *mut _ as *mut _,
flags,
)
}
}

@ -4,9 +4,9 @@ use aya_bpf_cty::c_void;
use crate::{
bindings::{bpf_map_def, bpf_map_type::BPF_MAP_TYPE_SOCKMAP, bpf_sock_ops},
helpers::{bpf_msg_redirect_map, bpf_sock_map_update},
helpers::{bpf_msg_redirect_map, bpf_sk_redirect_map, bpf_sock_map_update},
maps::PinningType,
programs::SkMsgContext,
programs::{SkMsgContext, SkSkbContext},
BpfContext,
};
@ -63,7 +63,7 @@ impl SockMap {
}
}
pub unsafe fn redirect(&mut self, ctx: &SkMsgContext, index: u32, flags: u64) -> i64 {
pub unsafe fn redirect_msg(&mut self, ctx: &SkMsgContext, index: u32, flags: u64) -> i64 {
bpf_msg_redirect_map(
ctx.as_ptr() as *mut _,
&mut self.def as *mut _ as *mut _,
@ -71,4 +71,13 @@ impl SockMap {
flags,
)
}
pub unsafe fn redirect_skb(&mut self, ctx: &SkSkbContext, index: u32, flags: u64) -> i64 {
bpf_sk_redirect_map(
ctx.as_ptr() as *mut _,
&mut self.def as *mut _ as *mut _,
index,
flags,
)
}
}

Loading…
Cancel
Save