Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for BPF_PROG_TYPE_CGROUP_SOCK #315

Merged
merged 2 commits into from
Jun 12, 2022
Merged

Conversation

dave-tucker
Copy link
Member

Tested and it works.
Sample BPF code:

#[cgroup_sock]
pub fn cgroup_sock(ctx: SockContext) -> i32 {
    match try_cgroup_sock(ctx) {
        Ok(ret) => ret,
        Err(ret) => ret,
    }
}

fn try_cgroup_sock(ctx: SockContext) -> Result<i32, i32> {
    unsafe {
        let family = (*(ctx.sock)).family;
        let type_ = (*(ctx.sock)).type_;
        let protocol = (*(ctx.sock)).protocol;
        // let src_port = (*(ctx.sock)).src_port;
        let dst_port = (*(ctx.sock)).dst_port;
        
        if family == AF_INET {
            // let src_ipv4  = (*(ctx.sock)).src_ip4;
            let dst_ipv4 = (*(ctx.sock)).dst_ip4;
        
            info!(&ctx, "got a sock create event: family: {}, type: {}, proto: {}, dip {}, dport {}",       
            family,
            type_,
            protocol,
            //src_ipv4,
            dst_ipv4,
            //src_port,
            dst_port,
            )
        }
    }
    Ok(0)
}

@dave-tucker dave-tucker added feature A PR that implements a new feature or enhancement aya-bpf This is about aya-bpf (kernel) aya This is about aya (userspace) labels Jun 9, 2022
@netlify
Copy link

netlify bot commented Jun 9, 2022

Deploy Preview for aya-rs ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 7b21a2d
🔍 Latest deploy log https://app.netlify.com/sites/aya-rs/deploys/62a149292a974b0009df6bfe
😎 Deploy Preview https://deploy-preview-315--aya-rs.netlify.app/src/aya_bpf_macros/expand.rs
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
@alessandrod alessandrod merged commit 7549eb9 into aya-rs:main Jun 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aya This is about aya (userspace) aya-bpf This is about aya-bpf (kernel) feature A PR that implements a new feature or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants