You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

libiptc.h 5.6KB

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