libip6tc.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. #ifndef _LIBIP6TC_H
  2. #define _LIBIP6TC_H
  3. /* Library which manipulates firewall rules. Version 0.2. */
  4. #include <linux/types.h>
  5. #include <libiptc/ipt_kernel_headers.h>
  6. #ifdef __cplusplus
  7. # include <climits>
  8. #else
  9. # include <limits.h> /* INT_MAX in ip6_tables.h */
  10. #endif
  11. #include <linux/netfilter_ipv6/ip6_tables.h>
  12. #include <libiptc/xtcshared.h>
  13. #define ip6tc_handle xtc_handle
  14. #define ip6t_chainlabel xt_chainlabel
  15. #define IP6TC_LABEL_ACCEPT "ACCEPT"
  16. #define IP6TC_LABEL_DROP "DROP"
  17. #define IP6TC_LABEL_QUEUE "QUEUE"
  18. #define IP6TC_LABEL_RETURN "RETURN"
  19. /* Does this chain exist? */
  20. int ip6tc_is_chain(const char *chain, struct xtc_handle *const handle);
  21. /* Take a snapshot of the rules. Returns NULL on error. */
  22. struct xtc_handle *ip6tc_init(const char *tablename);
  23. /* Cleanup after ip6tc_init(). */
  24. void ip6tc_free(struct xtc_handle *h);
  25. /* Iterator functions to run through the chains. Returns NULL at end. */
  26. const char *ip6tc_first_chain(struct xtc_handle *handle);
  27. const char *ip6tc_next_chain(struct xtc_handle *handle);
  28. /* Get first rule in the given chain: NULL for empty chain. */
  29. const struct ip6t_entry *ip6tc_first_rule(const char *chain,
  30. struct xtc_handle *handle);
  31. /* Returns NULL when rules run out. */
  32. const struct ip6t_entry *ip6tc_next_rule(const struct ip6t_entry *prev,
  33. struct xtc_handle *handle);
  34. /* Returns a pointer to the target name of this position. */
  35. const char *ip6tc_get_target(const struct ip6t_entry *e,
  36. struct xtc_handle *handle);
  37. /* Is this a built-in chain? */
  38. int ip6tc_builtin(const char *chain, struct xtc_handle *const handle);
  39. /* Get the policy of a given built-in chain */
  40. const char *ip6tc_get_policy(const char *chain,
  41. struct xt_counters *counters,
  42. struct xtc_handle *handle);
  43. /* These functions return TRUE for OK or 0 and set errno. If errno ==
  44. 0, it means there was a version error (ie. upgrade libiptc). */
  45. /* Rule numbers start at 1 for the first rule. */
  46. /* Insert the entry `fw' in chain `chain' into position `rulenum'. */
  47. int ip6tc_insert_entry(const xt_chainlabel chain,
  48. const struct ip6t_entry *e,
  49. unsigned int rulenum,
  50. struct xtc_handle *handle);
  51. /* Atomically replace rule `rulenum' in `chain' with `fw'. */
  52. int ip6tc_replace_entry(const xt_chainlabel chain,
  53. const struct ip6t_entry *e,
  54. unsigned int rulenum,
  55. struct xtc_handle *handle);
  56. /* Append entry `fw' to chain `chain'. Equivalent to insert with
  57. rulenum = length of chain. */
  58. int ip6tc_append_entry(const xt_chainlabel chain,
  59. const struct ip6t_entry *e,
  60. struct xtc_handle *handle);
  61. /* Check whether a matching rule exists */
  62. int ip6tc_check_entry(const xt_chainlabel chain,
  63. const struct ip6t_entry *origfw,
  64. unsigned char *matchmask,
  65. struct xtc_handle *handle);
  66. /* Delete the first rule in `chain' which matches `fw'. */
  67. int ip6tc_delete_entry(const xt_chainlabel chain,
  68. const struct ip6t_entry *origfw,
  69. unsigned char *matchmask,
  70. struct xtc_handle *handle);
  71. /* Delete the rule in position `rulenum' in `chain'. */
  72. int ip6tc_delete_num_entry(const xt_chainlabel chain,
  73. unsigned int rulenum,
  74. struct xtc_handle *handle);
  75. /* Check the packet `fw' on chain `chain'. Returns the verdict, or
  76. NULL and sets errno. */
  77. const char *ip6tc_check_packet(const xt_chainlabel chain,
  78. struct ip6t_entry *,
  79. struct xtc_handle *handle);
  80. /* Flushes the entries in the given chain (ie. empties chain). */
  81. int ip6tc_flush_entries(const xt_chainlabel chain,
  82. struct xtc_handle *handle);
  83. /* Zeroes the counters in a chain. */
  84. int ip6tc_zero_entries(const xt_chainlabel chain,
  85. struct xtc_handle *handle);
  86. /* Creates a new chain. */
  87. int ip6tc_create_chain(const xt_chainlabel chain,
  88. struct xtc_handle *handle);
  89. /* Deletes a chain. */
  90. int ip6tc_delete_chain(const xt_chainlabel chain,
  91. struct xtc_handle *handle);
  92. /* Renames a chain. */
  93. int ip6tc_rename_chain(const xt_chainlabel oldname,
  94. const xt_chainlabel newname,
  95. struct xtc_handle *handle);
  96. /* Sets the policy on a built-in chain. */
  97. int ip6tc_set_policy(const xt_chainlabel chain,
  98. const xt_chainlabel policy,
  99. struct xt_counters *counters,
  100. struct xtc_handle *handle);
  101. /* Get the number of references to this chain */
  102. int ip6tc_get_references(unsigned int *ref, const xt_chainlabel chain,
  103. struct xtc_handle *handle);
  104. /* read packet and byte counters for a specific rule */
  105. struct xt_counters *ip6tc_read_counter(const xt_chainlabel chain,
  106. unsigned int rulenum,
  107. struct xtc_handle *handle);
  108. /* zero packet and byte counters for a specific rule */
  109. int ip6tc_zero_counter(const xt_chainlabel chain,
  110. unsigned int rulenum,
  111. struct xtc_handle *handle);
  112. /* set packet and byte counters for a specific rule */
  113. int ip6tc_set_counter(const xt_chainlabel chain,
  114. unsigned int rulenum,
  115. struct xt_counters *counters,
  116. struct xtc_handle *handle);
  117. /* Makes the actual changes. */
  118. int ip6tc_commit(struct xtc_handle *handle);
  119. /* Get raw socket. */
  120. int ip6tc_get_raw_socket(void);
  121. /* Translates errno numbers into more human-readable form than strerror. */
  122. const char *ip6tc_strerror(int err);
  123. /* Return prefix length, or -1 if not contiguous */
  124. int ipv6_prefix_length(const struct in6_addr *a);
  125. extern void dump_entries6(struct xtc_handle *const);
  126. extern const struct xtc_ops ip6tc_ops;
  127. #endif /* _LIBIP6TC_H */