filter.h 2.2 KB

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