Merge pull request #590 from Kab1r/main

aya-bpf: Add helper `change_proto`
pull/545/head^2
vadorovsky 2 years ago committed by GitHub
commit fce1d763f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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