bpf-cgroup-defs.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _BPF_CGROUP_DEFS_H
  3. #define _BPF_CGROUP_DEFS_H
  4. #ifdef CONFIG_CGROUP_BPF
  5. #include <linux/list.h>
  6. #include <linux/percpu-refcount.h>
  7. #include <linux/workqueue.h>
  8. struct bpf_prog_array;
  9. #ifdef CONFIG_BPF_LSM
  10. /* Maximum number of concurrently attachable per-cgroup LSM hooks. */
  11. #define CGROUP_LSM_NUM 10
  12. #else
  13. #define CGROUP_LSM_NUM 0
  14. #endif
  15. enum cgroup_bpf_attach_type {
  16. CGROUP_BPF_ATTACH_TYPE_INVALID = -1,
  17. CGROUP_INET_INGRESS = 0,
  18. CGROUP_INET_EGRESS,
  19. CGROUP_INET_SOCK_CREATE,
  20. CGROUP_SOCK_OPS,
  21. CGROUP_DEVICE,
  22. CGROUP_INET4_BIND,
  23. CGROUP_INET6_BIND,
  24. CGROUP_INET4_CONNECT,
  25. CGROUP_INET6_CONNECT,
  26. CGROUP_INET4_POST_BIND,
  27. CGROUP_INET6_POST_BIND,
  28. CGROUP_UDP4_SENDMSG,
  29. CGROUP_UDP6_SENDMSG,
  30. CGROUP_SYSCTL,
  31. CGROUP_UDP4_RECVMSG,
  32. CGROUP_UDP6_RECVMSG,
  33. CGROUP_GETSOCKOPT,
  34. CGROUP_SETSOCKOPT,
  35. CGROUP_INET4_GETPEERNAME,
  36. CGROUP_INET6_GETPEERNAME,
  37. CGROUP_INET4_GETSOCKNAME,
  38. CGROUP_INET6_GETSOCKNAME,
  39. CGROUP_INET_SOCK_RELEASE,
  40. CGROUP_LSM_START,
  41. CGROUP_LSM_END = CGROUP_LSM_START + CGROUP_LSM_NUM - 1,
  42. MAX_CGROUP_BPF_ATTACH_TYPE
  43. };
  44. struct cgroup_bpf {
  45. /* array of effective progs in this cgroup */
  46. struct bpf_prog_array __rcu *effective[MAX_CGROUP_BPF_ATTACH_TYPE];
  47. /* attached progs to this cgroup and attach flags
  48. * when flags == 0 or BPF_F_ALLOW_OVERRIDE the progs list will
  49. * have either zero or one element
  50. * when BPF_F_ALLOW_MULTI the list can have up to BPF_CGROUP_MAX_PROGS
  51. */
  52. struct hlist_head progs[MAX_CGROUP_BPF_ATTACH_TYPE];
  53. u8 flags[MAX_CGROUP_BPF_ATTACH_TYPE];
  54. /* list of cgroup shared storages */
  55. struct list_head storages;
  56. /* temp storage for effective prog array used by prog_attach/detach */
  57. struct bpf_prog_array *inactive;
  58. /* reference counter used to detach bpf programs after cgroup removal */
  59. struct percpu_ref refcnt;
  60. /* cgroup_bpf is released using a work queue */
  61. struct work_struct release_work;
  62. };
  63. #else /* CONFIG_CGROUP_BPF */
  64. struct cgroup_bpf {};
  65. #endif /* CONFIG_CGROUP_BPF */
  66. #endif