0

Is there any way to get interface statistics using bpf. More specifically im looking for getting virtual interface stats using bpf.

I know it can be done using iptable chain but i want to do it specifically with bpf.

Thanks

Update : Iamable to get count of TCP , UDP and ICMP packets separately. I want to know in_octets , out_octets , in_pkts and out_pkts count now.

  • 1
    Can you post your current program? If you can get number of TCP packets, what's the difficulty to get number of packets? Is it to differentiate `in_pkts` from `out_pkts`? – pchaigno Aug 07 '20 at 07:00
  • https://github.com/mechpen/bpf-examples/tree/master/packetcount i used it as reference. So im basically looking for basic RMON counters (in & out packets & bytes) . – karikjoshi21 Aug 07 '20 at 07:20
  • 1
    I would suggest writing the BPF programs in C rather than bytecode... You can go from one of the kernel sample files (https://github.com/torvalds/linux/tree/master/samples/bpf) and modify them to attach to both ingress and egress for example at the tc hook. Retrieving statistics is then just a matter of incrementing map values. – pchaigno Aug 07 '20 at 07:26
  • @pchaignolinux doesnt give counters for virtual interfaces separately otherwise i would have used netlink sockets , i want to accomplish getting virtual interfaces basic RMON counters using bpf. Is that possible using bpf ? – karikjoshi21 Aug 07 '20 at 07:31
  • Yes it is, as detailed above. – pchaigno Aug 07 '20 at 08:01

0 Answers0