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