netcnt_common.h 910 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // SPDX-License-Identifier: GPL-2.0
  2. #ifndef __NETCNT_COMMON_H
  3. #define __NETCNT_COMMON_H
  4. #include <linux/types.h>
  5. #define MAX_PERCPU_PACKETS 32
  6. /* sizeof(struct bpf_local_storage_elem):
  7. *
  8. * It really is about 128 bytes on x86_64, but allocate more to account for
  9. * possible layout changes, different architectures, etc.
  10. * The kernel will wrap up to PAGE_SIZE internally anyway.
  11. */
  12. #define SIZEOF_BPF_LOCAL_STORAGE_ELEM 256
  13. /* Try to estimate kernel's BPF_LOCAL_STORAGE_MAX_VALUE_SIZE: */
  14. #define BPF_LOCAL_STORAGE_MAX_VALUE_SIZE (0xFFFF - \
  15. SIZEOF_BPF_LOCAL_STORAGE_ELEM)
  16. #define PCPU_MIN_UNIT_SIZE 32768
  17. union percpu_net_cnt {
  18. struct {
  19. __u64 packets;
  20. __u64 bytes;
  21. __u64 prev_ts;
  22. __u64 prev_packets;
  23. __u64 prev_bytes;
  24. };
  25. __u8 data[PCPU_MIN_UNIT_SIZE];
  26. };
  27. union net_cnt {
  28. struct {
  29. __u64 packets;
  30. __u64 bytes;
  31. };
  32. __u8 data[BPF_LOCAL_STORAGE_MAX_VALUE_SIZE];
  33. };
  34. #endif