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