libiptc.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. #ifndef _LIBIPTC_H
  2. #define _LIBIPTC_H
  3. /* Library which manipulates filtering rules. */
  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 ip_tables.h */
  10. #endif
  11. #include <linux/netfilter_ipv4/ip_tables.h>
  12. #include <libiptc/xtcshared.h>
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. #define iptc_handle xtc_handle
  17. #define ipt_chainlabel xt_chainlabel
  18. #define IPTC_LABEL_ACCEPT "ACCEPT"
  19. #define IPTC_LABEL_DROP "DROP"
  20. #define IPTC_LABEL_QUEUE "QUEUE"
  21. #define IPTC_LABEL_RETURN "RETURN"
  22. /* Does this chain exist? */
  23. int iptc_is_chain(const char *chain, struct xtc_handle *const handle);
  24. /* Take a snapshot of the rules. Returns NULL on error. */
  25. struct xtc_handle *iptc_init(const char *tablename);
  26. /* Cleanup after iptc_init(). */
  27. void iptc_free(struct xtc_handle *h);
  28. /* Iterator functions to run through the chains. Returns NULL at end. */
  29. const char *iptc_first_chain(struct xtc_handle *handle);
  30. const char *iptc_next_chain(struct xtc_handle *handle);
  31. /* Get first rule in the given chain: NULL for empty chain. */
  32. const struct ipt_entry *iptc_first_rule(const char *chain,
  33. struct xtc_handle *handle);
  34. /* Returns NULL when rules run out. */
  35. const struct ipt_entry *iptc_next_rule(const struct ipt_entry *prev,
  36. struct xtc_handle *handle);
  37. /* Returns a pointer to the target name of this entry. */
  38. const char *iptc_get_target(const struct ipt_entry *e,
  39. struct xtc_handle *handle);
  40. /* Is this a built-in chain? */
  41. int iptc_builtin(const char *chain, struct xtc_handle *const handle);
  42. /* Get the policy of a given built-in chain */
  43. const char *iptc_get_policy(const char *chain,
  44. struct xt_counters *counter,
  45. struct xtc_handle *handle);
  46. /* These functions return TRUE for OK or 0 and set errno. If errno ==
  47. 0, it means there was a version error (ie. upgrade libiptc). */
  48. /* Rule numbers start at 1 for the first rule. */
  49. /* Insert the entry `e' in chain `chain' into position `rulenum'. */
  50. int iptc_insert_entry(const xt_chainlabel chain,
  51. const struct ipt_entry *e,
  52. unsigned int rulenum,
  53. struct xtc_handle *handle);
  54. /* Atomically replace rule `rulenum' in `chain' with `e'. */
  55. int iptc_replace_entry(const xt_chainlabel chain,
  56. const struct ipt_entry *e,
  57. unsigned int rulenum,
  58. struct xtc_handle *handle);
  59. /* Append entry `e' to chain `chain'. Equivalent to insert with
  60. rulenum = length of chain. */
  61. int iptc_append_entry(const xt_chainlabel chain,
  62. const struct ipt_entry *e,
  63. struct xtc_handle *handle);
  64. /* Check whether a mathching rule exists */
  65. int iptc_check_entry(const xt_chainlabel chain,
  66. const struct ipt_entry *origfw,
  67. unsigned char *matchmask,
  68. struct xtc_handle *handle);
  69. /* Delete the first rule in `chain' which matches `e', subject to
  70. matchmask (array of length == origfw) */
  71. int iptc_delete_entry(const xt_chainlabel chain,
  72. const struct ipt_entry *origfw,
  73. unsigned char *matchmask,
  74. struct xtc_handle *handle);
  75. /* Delete the rule in position `rulenum' in `chain'. */
  76. int iptc_delete_num_entry(const xt_chainlabel chain,
  77. unsigned int rulenum,
  78. struct xtc_handle *handle);
  79. /* Check the packet `e' on chain `chain'. Returns the verdict, or
  80. NULL and sets errno. */
  81. const char *iptc_check_packet(const xt_chainlabel chain,
  82. struct ipt_entry *entry,
  83. struct xtc_handle *handle);
  84. /* Flushes the entries in the given chain (ie. empties chain). */
  85. int iptc_flush_entries(const xt_chainlabel chain,
  86. struct xtc_handle *handle);
  87. /* Zeroes the counters in a chain. */
  88. int iptc_zero_entries(const xt_chainlabel chain,
  89. struct xtc_handle *handle);
  90. /* Creates a new chain. */
  91. int iptc_create_chain(const xt_chainlabel chain,
  92. struct xtc_handle *handle);
  93. /* Deletes a chain. */
  94. int iptc_delete_chain(const xt_chainlabel chain,
  95. struct xtc_handle *handle);
  96. /* Renames a chain. */
  97. int iptc_rename_chain(const xt_chainlabel oldname,
  98. const xt_chainlabel newname,
  99. struct xtc_handle *handle);
  100. /* Sets the policy on a built-in chain. */
  101. int iptc_set_policy(const xt_chainlabel chain,
  102. const xt_chainlabel policy,
  103. struct xt_counters *counters,
  104. struct xtc_handle *handle);
  105. /* Get the number of references to this chain */
  106. int iptc_get_references(unsigned int *ref,
  107. const xt_chainlabel chain,
  108. struct xtc_handle *handle);
  109. /* read packet and byte counters for a specific rule */
  110. struct xt_counters *iptc_read_counter(const xt_chainlabel chain,
  111. unsigned int rulenum,
  112. struct xtc_handle *handle);
  113. /* zero packet and byte counters for a specific rule */
  114. int iptc_zero_counter(const xt_chainlabel chain,
  115. unsigned int rulenum,
  116. struct xtc_handle *handle);
  117. /* set packet and byte counters for a specific rule */
  118. int iptc_set_counter(const xt_chainlabel chain,
  119. unsigned int rulenum,
  120. struct xt_counters *counters,
  121. struct xtc_handle *handle);
  122. /* Makes the actual changes. */
  123. int iptc_commit(struct xtc_handle *handle);
  124. /* Get raw socket. */
  125. int iptc_get_raw_socket(void);
  126. /* Translates errno numbers into more human-readable form than strerror. */
  127. const char *iptc_strerror(int err);
  128. extern void dump_entries(struct xtc_handle *const);
  129. extern const struct xtc_ops iptc_ops;
  130. #ifdef __cplusplus
  131. }
  132. #endif
  133. #endif /* _LIBIPTC_H */