feat(bpf+sk_skb): wrap `change_proto` helper

pull/590/head
Kabir Kwatra 2 years ago
parent ed14751c79
commit 92f9c43230
No known key found for this signature in database

@ -6,8 +6,8 @@ use core::{
use aya_bpf_bindings::helpers::{
bpf_clone_redirect, bpf_get_socket_uid, bpf_l3_csum_replace, bpf_l4_csum_replace,
bpf_skb_adjust_room, bpf_skb_change_type, bpf_skb_load_bytes, bpf_skb_pull_data,
bpf_skb_store_bytes,
bpf_skb_adjust_room, bpf_skb_change_proto, bpf_skb_change_type, bpf_skb_load_bytes,
bpf_skb_pull_data, bpf_skb_store_bytes,
};
use aya_bpf_cty::c_long;
@ -189,6 +189,16 @@ impl SkBuff {
}
}
#[inline]
pub fn change_proto(&self, proto: u16, flags: u64) -> Result<(), c_long> {
let ret = unsafe { bpf_skb_change_proto(self.as_ptr() as *mut _, proto, flags) };
if ret == 0 {
Ok(())
} else {
Err(ret)
}
}
#[inline]
pub fn change_type(&self, ty: u32) -> Result<(), c_long> {
let ret = unsafe { bpf_skb_change_type(self.as_ptr() as *mut _, ty) };

@ -142,6 +142,11 @@ impl TcContext {
self.skb.clone_redirect(if_index, flags)
}
#[inline]
pub fn change_proto(&self, proto: u16, flags: u64) -> Result<(), c_long> {
self.skb.change_proto(proto, flags)
}
#[inline]
pub fn change_type(&self, ty: u32) -> Result<(), c_long> {
self.skb.change_type(ty)

Loading…
Cancel
Save