bpf-netns.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _BPF_NETNS_H
  3. #define _BPF_NETNS_H
  4. #include <linux/mutex.h>
  5. #include <uapi/linux/bpf.h>
  6. enum netns_bpf_attach_type {
  7. NETNS_BPF_INVALID = -1,
  8. NETNS_BPF_FLOW_DISSECTOR = 0,
  9. NETNS_BPF_SK_LOOKUP,
  10. MAX_NETNS_BPF_ATTACH_TYPE
  11. };
  12. static inline enum netns_bpf_attach_type
  13. to_netns_bpf_attach_type(enum bpf_attach_type attach_type)
  14. {
  15. switch (attach_type) {
  16. case BPF_FLOW_DISSECTOR:
  17. return NETNS_BPF_FLOW_DISSECTOR;
  18. case BPF_SK_LOOKUP:
  19. return NETNS_BPF_SK_LOOKUP;
  20. default:
  21. return NETNS_BPF_INVALID;
  22. }
  23. }
  24. /* Protects updates to netns_bpf */
  25. extern struct mutex netns_bpf_mutex;
  26. union bpf_attr;
  27. struct bpf_prog;
  28. #ifdef CONFIG_NET
  29. int netns_bpf_prog_query(const union bpf_attr *attr,
  30. union bpf_attr __user *uattr);
  31. int netns_bpf_prog_attach(const union bpf_attr *attr,
  32. struct bpf_prog *prog);
  33. int netns_bpf_prog_detach(const union bpf_attr *attr, enum bpf_prog_type ptype);
  34. int netns_bpf_link_create(const union bpf_attr *attr,
  35. struct bpf_prog *prog);
  36. #else
  37. static inline int netns_bpf_prog_query(const union bpf_attr *attr,
  38. union bpf_attr __user *uattr)
  39. {
  40. return -EOPNOTSUPP;
  41. }
  42. static inline int netns_bpf_prog_attach(const union bpf_attr *attr,
  43. struct bpf_prog *prog)
  44. {
  45. return -EOPNOTSUPP;
  46. }
  47. static inline int netns_bpf_prog_detach(const union bpf_attr *attr,
  48. enum bpf_prog_type ptype)
  49. {
  50. return -EOPNOTSUPP;
  51. }
  52. static inline int netns_bpf_link_create(const union bpf_attr *attr,
  53. struct bpf_prog *prog)
  54. {
  55. return -EOPNOTSUPP;
  56. }
  57. #endif
  58. #endif /* _BPF_NETNS_H */