Merge pull request #103 from dave-tucker/redirect_sk

bpf: Implement redirect for skbs on sockmap/sockhash
pull/105/head
Alessandro Decina 3 years ago committed by GitHub
commit 0b3e398f11
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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