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