bpf-netns.h 1.4 KB

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