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