foniod / redbpf

Rust library for building and running BPF/eBPF modules
Apache License 2.0
1.71k stars 136 forks source link

Get size of packet via skbuff variable #182

Closed sebastiaoamaro closed 3 years ago

sebastiaoamaro commented 3 years ago

Hello everyone, I was looking into the tc_map_share[1] and tcp_lifetime[2] to find a way to get the size of the packet ( len parameter in the __sk_buff) however I can't seem to access it correctly has someone done this before? It is probably just a line of code similar to accessing a parameter of the ip header, however, I can't seem to crack it. [1] https://github.com/foniod/redbpf/blob/main/examples/example-probes/src/tc_map_share/main.rs [2] https://github.com/foniod/redbpf/blob/main/examples/example-probes/src/tcp_lifetime/main.rs

Thanks in advance.

rhdxmr commented 3 years ago

Hello @sebastiaoamaro

You can do that like below:

(*skb.skb).len

skb is redbpf_probes::socket::SkBuff

And skb.skb is __sk_buff. It is rust binding of __sk_buff

I wish you luck.

rhdxmr commented 3 years ago

@sebastiaoamaro I just wonder that the answer replied above helped you solve your problem. If you need more help or have any questions please let me hear from you. Thanks

sebastiaoamaro commented 3 years ago

@sebastiaoamaro I just wonder that the answer replied above helped you solve your problem. If you need more help or have any questions please let me hear from you. Thanks

Sorry! I forgot to reply it solved it yes, thank you so much!

rhdxmr commented 3 years ago

I'm glad to hear that! Thank you 👍 I'm closing this issue. If you have further questions please feel free to reopen this issue.