test_obj_id.c 819 B

1234567891011121314151617181920212223242526272829303132333435
  1. /* Copyright (c) 2017 Facebook
  2. *
  3. * This program is free software; you can redistribute it and/or
  4. * modify it under the terms of version 2 of the GNU General Public
  5. * License as published by the Free Software Foundation.
  6. */
  7. #include <stddef.h>
  8. #include <linux/bpf.h>
  9. #include <linux/pkt_cls.h>
  10. #include "bpf_helpers.h"
  11. /* It is a dumb bpf program such that it must have no
  12. * issue to be loaded since testing the verifier is
  13. * not the focus here.
  14. */
  15. int _version SEC("version") = 1;
  16. struct bpf_map_def SEC("maps") test_map_id = {
  17. .type = BPF_MAP_TYPE_ARRAY,
  18. .key_size = sizeof(__u32),
  19. .value_size = sizeof(__u64),
  20. .max_entries = 1,
  21. };
  22. SEC("test_obj_id_dummy")
  23. int test_obj_id(struct __sk_buff *skb)
  24. {
  25. __u32 key = 0;
  26. __u64 *value;
  27. value = bpf_map_lookup_elem(&test_map_id, &key);
  28. return TC_ACT_OK;
  29. }