ebpf-allowed-memory.rs 833 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. // SPDX-License-Identifier: (Apache-2.0 OR MIT)
  2. // Copyright 2024 Akenes SA <wouter.dullaert@exoscale.ch>
  3. #![no_std]
  4. #![no_main]
  5. use aya_ebpf::{
  6. bindings::{BPF_F_NO_PREALLOC, TC_ACT_PIPE},
  7. macros::{classifier, map},
  8. maps::HashMap,
  9. programs::TcContext,
  10. };
  11. #[map]
  12. static RULES: HashMap<Key, Value> = HashMap::<Key, Value>::with_max_entries(1, BPF_F_NO_PREALLOC);
  13. #[repr(C, packed)]
  14. pub struct Key {
  15. pub protocol: u8,
  16. }
  17. #[repr(C, packed)]
  18. pub struct Value {
  19. pub result: i32,
  20. }
  21. #[classifier]
  22. pub fn ingress_tc(_ctx: TcContext) -> i32 {
  23. let key = Key { protocol: 1 };
  24. if let Some(action) = unsafe { RULES.get(&key) } {
  25. return action.result;
  26. }
  27. return TC_ACT_PIPE;
  28. }
  29. #[panic_handler]
  30. fn panic(_info: &core::panic::PanicInfo) -> ! {
  31. unsafe { core::hint::unreachable_unchecked() }
  32. }