logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

x_tables.h (4464B)


  1. /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
  2. #ifndef _X_TABLES_H
  3. #define _X_TABLES_H
  4. #include <linux/const.h>
  5. #include <linux/types.h>
  6. #define XT_FUNCTION_MAXNAMELEN 30
  7. #define XT_EXTENSION_MAXNAMELEN 29
  8. #define XT_TABLE_MAXNAMELEN 32
  9. struct xt_entry_match {
  10. union {
  11. struct {
  12. __u16 match_size;
  13. /* Used by userspace */
  14. char name[XT_EXTENSION_MAXNAMELEN];
  15. __u8 revision;
  16. } user;
  17. struct {
  18. __u16 match_size;
  19. /* Used inside the kernel */
  20. struct xt_match *match;
  21. } kernel;
  22. /* Total length */
  23. __u16 match_size;
  24. } u;
  25. unsigned char data[];
  26. };
  27. struct xt_entry_target {
  28. union {
  29. struct {
  30. __u16 target_size;
  31. /* Used by userspace */
  32. char name[XT_EXTENSION_MAXNAMELEN];
  33. __u8 revision;
  34. } user;
  35. struct {
  36. __u16 target_size;
  37. /* Used inside the kernel */
  38. struct xt_target *target;
  39. } kernel;
  40. /* Total length */
  41. __u16 target_size;
  42. } u;
  43. unsigned char data[0];
  44. };
  45. #define XT_TARGET_INIT(__name, __size) \
  46. { \
  47. .target.u.user = { \
  48. .target_size = XT_ALIGN(__size), \
  49. .name = __name, \
  50. }, \
  51. }
  52. struct xt_standard_target {
  53. struct xt_entry_target target;
  54. int verdict;
  55. };
  56. struct xt_error_target {
  57. struct xt_entry_target target;
  58. char errorname[XT_FUNCTION_MAXNAMELEN];
  59. };
  60. /* The argument to IPT_SO_GET_REVISION_*. Returns highest revision
  61. * kernel supports, if >= revision. */
  62. struct xt_get_revision {
  63. char name[XT_EXTENSION_MAXNAMELEN];
  64. __u8 revision;
  65. };
  66. /* CONTINUE verdict for targets */
  67. #define XT_CONTINUE 0xFFFFFFFF
  68. /* For standard target */
  69. #define XT_RETURN (-NF_REPEAT - 1)
  70. /* this is a dummy structure to find out the alignment requirement for a struct
  71. * containing all the fundamental data types that are used in ipt_entry,
  72. * ip6t_entry and arpt_entry. This sucks, and it is a hack. It will be my
  73. * personal pleasure to remove it -HW
  74. */
  75. struct _xt_align {
  76. __u8 u8;
  77. __u16 u16;
  78. __u32 u32;
  79. __u64 u64;
  80. };
  81. #define XT_ALIGN(s) __ALIGN_KERNEL((s), __alignof__(struct _xt_align))
  82. /* Standard return verdict, or do jump. */
  83. #define XT_STANDARD_TARGET ""
  84. /* Error verdict. */
  85. #define XT_ERROR_TARGET "ERROR"
  86. #define SET_COUNTER(c,b,p) do { (c).bcnt = (b); (c).pcnt = (p); } while(0)
  87. #define ADD_COUNTER(c,b,p) do { (c).bcnt += (b); (c).pcnt += (p); } while(0)
  88. struct xt_counters {
  89. __u64 pcnt, bcnt; /* Packet and byte counters */
  90. };
  91. /* The argument to IPT_SO_ADD_COUNTERS. */
  92. struct xt_counters_info {
  93. /* Which table. */
  94. char name[XT_TABLE_MAXNAMELEN];
  95. unsigned int num_counters;
  96. /* The counters (actually `number' of these). */
  97. struct xt_counters counters[];
  98. };
  99. #define XT_INV_PROTO 0x40 /* Invert the sense of PROTO. */
  100. /* fn returns 0 to continue iteration */
  101. #define XT_MATCH_ITERATE(type, e, fn, args...) \
  102. ({ \
  103. unsigned int __i; \
  104. int __ret = 0; \
  105. struct xt_entry_match *__m; \
  106. \
  107. for (__i = sizeof(type); \
  108. __i < (e)->target_offset; \
  109. __i += __m->u.match_size) { \
  110. __m = (void *)e + __i; \
  111. \
  112. __ret = fn(__m , ## args); \
  113. if (__ret != 0) \
  114. break; \
  115. } \
  116. __ret; \
  117. })
  118. /* fn returns 0 to continue iteration */
  119. #define XT_ENTRY_ITERATE_CONTINUE(type, entries, size, n, fn, args...) \
  120. ({ \
  121. unsigned int __i, __n; \
  122. int __ret = 0; \
  123. type *__entry; \
  124. \
  125. for (__i = 0, __n = 0; __i < (size); \
  126. __i += __entry->next_offset, __n++) { \
  127. __entry = (void *)(entries) + __i; \
  128. if (__n < n) \
  129. continue; \
  130. \
  131. __ret = fn(__entry , ## args); \
  132. if (__ret != 0) \
  133. break; \
  134. } \
  135. __ret; \
  136. })
  137. /* fn returns 0 to continue iteration */
  138. #define XT_ENTRY_ITERATE(type, entries, size, fn, args...) \
  139. XT_ENTRY_ITERATE_CONTINUE(type, entries, size, 0, fn, args)
  140. /* pos is normally a struct ipt_entry/ip6t_entry/etc. */
  141. #define xt_entry_foreach(pos, ehead, esize) \
  142. for ((pos) = (typeof(pos))(ehead); \
  143. (pos) < (typeof(pos))((char *)(ehead) + (esize)); \
  144. (pos) = (typeof(pos))((char *)(pos) + (pos)->next_offset))
  145. /* can only be xt_entry_match, so no use of typeof here */
  146. #define xt_ematch_foreach(pos, entry) \
  147. for ((pos) = (struct xt_entry_match *)entry->elems; \
  148. (pos) < (struct xt_entry_match *)((char *)(entry) + \
  149. (entry)->target_offset); \
  150. (pos) = (struct xt_entry_match *)((char *)(pos) + \
  151. (pos)->u.match_size))
  152. #endif /* _X_TABLES_H */