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