filter.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
  2. /*
  3. * Linux Socket Filter Data Structures
  4. */
  5. #ifndef _UAPI__LINUX_FILTER_H__
  6. #define _UAPI__LINUX_FILTER_H__
  7. #include <linux/compiler.h>
  8. #include <linux/types.h>
  9. #include <linux/bpf_common.h>
  10. /*
  11. * Current version of the filter code architecture.
  12. */
  13. #define BPF_MAJOR_VERSION 1
  14. #define BPF_MINOR_VERSION 1
  15. /*
  16. * Try and keep these values and structures similar to BSD, especially
  17. * the BPF code definitions which need to match so you can share filters
  18. */
  19. struct sock_filter { /* Filter block */
  20. __u16 code; /* Actual filter code */
  21. __u8 jt; /* Jump true */
  22. __u8 jf; /* Jump false */
  23. __u32 k; /* Generic multiuse field */
  24. };
  25. struct sock_fprog { /* Required for SO_ATTACH_FILTER. */
  26. unsigned short len; /* Number of filter blocks */
  27. struct sock_filter __user *filter;
  28. };
  29. /* ret - BPF_K and BPF_X also apply */
  30. #define BPF_RVAL(code) ((code) & 0x18)
  31. #define BPF_A 0x10
  32. /* misc */
  33. #define BPF_MISCOP(code) ((code) & 0xf8)
  34. #define BPF_TAX 0x00
  35. #define BPF_TXA 0x80
  36. /*
  37. * Macros for filter block array initializers.
  38. */
  39. #ifndef BPF_STMT
  40. #define BPF_STMT(code, k) { (unsigned short)(code), 0, 0, k }
  41. #endif
  42. #ifndef BPF_JUMP
  43. #define BPF_JUMP(code, k, jt, jf) { (unsigned short)(code), jt, jf, k }
  44. #endif
  45. /*
  46. * Number of scratch memory words for: BPF_ST and BPF_STX
  47. */
  48. #define BPF_MEMWORDS 16
  49. /* RATIONALE. Negative offsets are invalid in BPF.
  50. We use them to reference ancillary data.
  51. Unlike introduction new instructions, it does not break
  52. existing compilers/optimizers.
  53. */
  54. #define SKF_AD_OFF (-0x1000)
  55. #define SKF_AD_PROTOCOL 0
  56. #define SKF_AD_PKTTYPE 4
  57. #define SKF_AD_IFINDEX 8
  58. #define SKF_AD_NLATTR 12
  59. #define SKF_AD_NLATTR_NEST 16
  60. #define SKF_AD_MARK 20
  61. #define SKF_AD_QUEUE 24
  62. #define SKF_AD_HATYPE 28
  63. #define SKF_AD_RXHASH 32
  64. #define SKF_AD_CPU 36
  65. #define SKF_AD_ALU_XOR_X 40
  66. #define SKF_AD_VLAN_TAG 44
  67. #define SKF_AD_VLAN_TAG_PRESENT 48
  68. #define SKF_AD_PAY_OFFSET 52
  69. #define SKF_AD_RANDOM 56
  70. #define SKF_AD_VLAN_TPID 60
  71. #define SKF_AD_MAX 64
  72. #define SKF_NET_OFF (-0x100000)
  73. #define SKF_LL_OFF (-0x200000)
  74. #define BPF_NET_OFF SKF_NET_OFF
  75. #define BPF_LL_OFF SKF_LL_OFF
  76. #endif /* _UAPI__LINUX_FILTER_H__ */