4
0

map_test.rs 977 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Socket Filter program for testing with an arbitrary program with maps.
  2. // This is mainly used in tests with consideration for old kernels.
  3. #![no_std]
  4. #![no_main]
  5. use aya_ebpf::{
  6. macros::{map, socket_filter},
  7. maps::{Array, HashMap},
  8. programs::SkBuffContext,
  9. };
  10. // Introduced in kernel v3.19.
  11. #[map]
  12. static FOO: Array<u32> = Array::<u32>::with_max_entries(10, 0);
  13. // Introduced in kernel v3.19.
  14. #[map(name = "BAR")]
  15. static BAZ: HashMap<u32, u8> = HashMap::<u32, u8>::with_max_entries(8, 0);
  16. // Introduced in kernel v3.19.
  17. #[socket_filter]
  18. pub fn simple_prog(_ctx: SkBuffContext) -> i64 {
  19. // So that these maps show up under the `map_ids` field.
  20. FOO.get(0);
  21. // If we use the literal value `0` instead of the local variable `i`, then an additional
  22. // `.rodata` map will be associated with the program.
  23. let i = 0;
  24. BAZ.get_ptr(&i);
  25. 0
  26. }
  27. #[cfg(not(test))]
  28. #[panic_handler]
  29. fn panic(_info: &core::panic::PanicInfo) -> ! {
  30. loop {}
  31. }