extern int do_command6(int argc, char *argv[], char **table,
struct ip6tc_handle **handle);
-extern int for_each_chain(int (*fn)(const ip6t_chainlabel, int, struct ip6tc_handle **), int verbose, int builtinstoo, struct ip6tc_handle **handle);
-extern int flush_entries(const ip6t_chainlabel chain, int verbose, struct ip6tc_handle **handle);
-extern int delete_chain(const ip6t_chainlabel chain, int verbose, struct ip6tc_handle **handle);
-void print_rule(const struct ip6t_entry *e, struct ip6tc_handle **h, const char *chain, int counters);
+extern int for_each_chain(int (*fn)(const ip6t_chainlabel, int, struct ip6tc_handle *), int verbose, int builtinstoo, struct ip6tc_handle *handle);
+extern int flush_entries(const ip6t_chainlabel chain, int verbose, struct ip6tc_handle *handle);
+extern int delete_chain(const ip6t_chainlabel chain, int verbose, struct ip6tc_handle *handle);
+void print_rule(const struct ip6t_entry *e, struct ip6tc_handle *h, const char *chain, int counters);
#endif /*_IP6TABLES_USER_H*/
extern int do_command(int argc, char *argv[], char **table,
struct iptc_handle **handle);
extern int delete_chain(const ipt_chainlabel chain, int verbose,
- struct iptc_handle **handle);
+ struct iptc_handle *handle);
extern int flush_entries(const ipt_chainlabel chain, int verbose,
- struct iptc_handle **handle);
-extern int for_each_chain(int (*fn)(const ipt_chainlabel, int, struct iptc_handle **),
- int verbose, int builtinstoo, struct iptc_handle **handle);
+ struct iptc_handle *handle);
+extern int for_each_chain(int (*fn)(const ipt_chainlabel, int, struct iptc_handle *),
+ int verbose, int builtinstoo, struct iptc_handle *handle);
extern void print_rule(const struct ipt_entry *e,
- struct iptc_handle **handle, const char *chain, int counters);
+ struct iptc_handle *handle, const char *chain, int counters);
/* kernel revision handling */
extern int kernel_version;
struct ip6tc_handle *ip6tc_init(const char *tablename);
/* Cleanup after ip6tc_init(). */
-void ip6tc_free(struct ip6tc_handle **h);
+void ip6tc_free(struct ip6tc_handle *h);
/* Iterator functions to run through the chains. Returns NULL at end. */
-const char *ip6tc_first_chain(struct ip6tc_handle **handle);
-const char *ip6tc_next_chain(struct ip6tc_handle **handle);
+const char *ip6tc_first_chain(struct ip6tc_handle *handle);
+const char *ip6tc_next_chain(struct ip6tc_handle *handle);
/* Get first rule in the given chain: NULL for empty chain. */
const struct ip6t_entry *ip6tc_first_rule(const char *chain,
- struct ip6tc_handle **handle);
+ struct ip6tc_handle *handle);
/* Returns NULL when rules run out. */
const struct ip6t_entry *ip6tc_next_rule(const struct ip6t_entry *prev,
- struct ip6tc_handle **handle);
+ struct ip6tc_handle *handle);
/* Returns a pointer to the target name of this position. */
const char *ip6tc_get_target(const struct ip6t_entry *e,
- struct ip6tc_handle **handle);
+ struct ip6tc_handle *handle);
/* Is this a built-in chain? */
int ip6tc_builtin(const char *chain, struct ip6tc_handle *const handle);
/* Get the policy of a given built-in chain */
const char *ip6tc_get_policy(const char *chain,
struct ip6t_counters *counters,
- struct ip6tc_handle **handle);
+ struct ip6tc_handle *handle);
/* These functions return TRUE for OK or 0 and set errno. If errno ==
0, it means there was a version error (ie. upgrade libiptc). */
int ip6tc_insert_entry(const ip6t_chainlabel chain,
const struct ip6t_entry *e,
unsigned int rulenum,
- struct ip6tc_handle **handle);
+ struct ip6tc_handle *handle);
/* Atomically replace rule `rulenum' in `chain' with `fw'. */
int ip6tc_replace_entry(const ip6t_chainlabel chain,
const struct ip6t_entry *e,
unsigned int rulenum,
- struct ip6tc_handle **handle);
+ struct ip6tc_handle *handle);
/* Append entry `fw' to chain `chain'. Equivalent to insert with
rulenum = length of chain. */
int ip6tc_append_entry(const ip6t_chainlabel chain,
const struct ip6t_entry *e,
- struct ip6tc_handle **handle);
+ struct ip6tc_handle *handle);
/* Delete the first rule in `chain' which matches `fw'. */
int ip6tc_delete_entry(const ip6t_chainlabel chain,
const struct ip6t_entry *origfw,
unsigned char *matchmask,
- struct ip6tc_handle **handle);
+ struct ip6tc_handle *handle);
/* Delete the rule in position `rulenum' in `chain'. */
int ip6tc_delete_num_entry(const ip6t_chainlabel chain,
unsigned int rulenum,
- struct ip6tc_handle **handle);
+ struct ip6tc_handle *handle);
/* Check the packet `fw' on chain `chain'. Returns the verdict, or
NULL and sets errno. */
const char *ip6tc_check_packet(const ip6t_chainlabel chain,
struct ip6t_entry *,
- struct ip6tc_handle **handle);
+ struct ip6tc_handle *handle);
/* Flushes the entries in the given chain (ie. empties chain). */
int ip6tc_flush_entries(const ip6t_chainlabel chain,
- struct ip6tc_handle **handle);
+ struct ip6tc_handle *handle);
/* Zeroes the counters in a chain. */
int ip6tc_zero_entries(const ip6t_chainlabel chain,
- struct ip6tc_handle **handle);
+ struct ip6tc_handle *handle);
/* Creates a new chain. */
int ip6tc_create_chain(const ip6t_chainlabel chain,
- struct ip6tc_handle **handle);
+ struct ip6tc_handle *handle);
/* Deletes a chain. */
int ip6tc_delete_chain(const ip6t_chainlabel chain,
- struct ip6tc_handle **handle);
+ struct ip6tc_handle *handle);
/* Renames a chain. */
int ip6tc_rename_chain(const ip6t_chainlabel oldname,
const ip6t_chainlabel newname,
- struct ip6tc_handle **handle);
+ struct ip6tc_handle *handle);
/* Sets the policy on a built-in chain. */
int ip6tc_set_policy(const ip6t_chainlabel chain,
const ip6t_chainlabel policy,
struct ip6t_counters *counters,
- struct ip6tc_handle **handle);
+ struct ip6tc_handle *handle);
/* Get the number of references to this chain */
int ip6tc_get_references(unsigned int *ref, const ip6t_chainlabel chain,
- struct ip6tc_handle **handle);
+ struct ip6tc_handle *handle);
/* read packet and byte counters for a specific rule */
struct ip6t_counters *ip6tc_read_counter(const ip6t_chainlabel chain,
unsigned int rulenum,
- struct ip6tc_handle **handle);
+ struct ip6tc_handle *handle);
/* zero packet and byte counters for a specific rule */
int ip6tc_zero_counter(const ip6t_chainlabel chain,
unsigned int rulenum,
- struct ip6tc_handle **handle);
+ struct ip6tc_handle *handle);
/* set packet and byte counters for a specific rule */
int ip6tc_set_counter(const ip6t_chainlabel chain,
unsigned int rulenum,
struct ip6t_counters *counters,
- struct ip6tc_handle **handle);
+ struct ip6tc_handle *handle);
/* Makes the actual changes. */
-int ip6tc_commit(struct ip6tc_handle **handle);
+int ip6tc_commit(struct ip6tc_handle *handle);
/* Get raw socket. */
int ip6tc_get_raw_socket(void);
struct iptc_handle *iptc_init(const char *tablename);
/* Cleanup after iptc_init(). */
-void iptc_free(struct iptc_handle **h);
+void iptc_free(struct iptc_handle *h);
/* Iterator functions to run through the chains. Returns NULL at end. */
-const char *iptc_first_chain(struct iptc_handle **handle);
-const char *iptc_next_chain(struct iptc_handle **handle);
+const char *iptc_first_chain(struct iptc_handle *handle);
+const char *iptc_next_chain(struct iptc_handle *handle);
/* Get first rule in the given chain: NULL for empty chain. */
const struct ipt_entry *iptc_first_rule(const char *chain,
- struct iptc_handle **handle);
+ struct iptc_handle *handle);
/* Returns NULL when rules run out. */
const struct ipt_entry *iptc_next_rule(const struct ipt_entry *prev,
- struct iptc_handle **handle);
+ struct iptc_handle *handle);
/* Returns a pointer to the target name of this entry. */
const char *iptc_get_target(const struct ipt_entry *e,
- struct iptc_handle **handle);
+ struct iptc_handle *handle);
/* Is this a built-in chain? */
int iptc_builtin(const char *chain, struct iptc_handle *const handle);
/* Get the policy of a given built-in chain */
const char *iptc_get_policy(const char *chain,
struct ipt_counters *counter,
- struct iptc_handle **handle);
+ struct iptc_handle *handle);
/* These functions return TRUE for OK or 0 and set errno. If errno ==
0, it means there was a version error (ie. upgrade libiptc). */
int iptc_insert_entry(const ipt_chainlabel chain,
const struct ipt_entry *e,
unsigned int rulenum,
- struct iptc_handle **handle);
+ struct iptc_handle *handle);
/* Atomically replace rule `rulenum' in `chain' with `e'. */
int iptc_replace_entry(const ipt_chainlabel chain,
const struct ipt_entry *e,
unsigned int rulenum,
- struct iptc_handle **handle);
+ struct iptc_handle *handle);
/* Append entry `e' to chain `chain'. Equivalent to insert with
rulenum = length of chain. */
int iptc_append_entry(const ipt_chainlabel chain,
const struct ipt_entry *e,
- struct iptc_handle **handle);
+ struct iptc_handle *handle);
/* Delete the first rule in `chain' which matches `e', subject to
matchmask (array of length == origfw) */
int iptc_delete_entry(const ipt_chainlabel chain,
const struct ipt_entry *origfw,
unsigned char *matchmask,
- struct iptc_handle **handle);
+ struct iptc_handle *handle);
/* Delete the rule in position `rulenum' in `chain'. */
int iptc_delete_num_entry(const ipt_chainlabel chain,
unsigned int rulenum,
- struct iptc_handle **handle);
+ struct iptc_handle *handle);
/* Check the packet `e' on chain `chain'. Returns the verdict, or
NULL and sets errno. */
const char *iptc_check_packet(const ipt_chainlabel chain,
struct ipt_entry *entry,
- struct iptc_handle **handle);
+ struct iptc_handle *handle);
/* Flushes the entries in the given chain (ie. empties chain). */
int iptc_flush_entries(const ipt_chainlabel chain,
- struct iptc_handle **handle);
+ struct iptc_handle *handle);
/* Zeroes the counters in a chain. */
int iptc_zero_entries(const ipt_chainlabel chain,
- struct iptc_handle **handle);
+ struct iptc_handle *handle);
/* Creates a new chain. */
int iptc_create_chain(const ipt_chainlabel chain,
- struct iptc_handle **handle);
+ struct iptc_handle *handle);
/* Deletes a chain. */
int iptc_delete_chain(const ipt_chainlabel chain,
- struct iptc_handle **handle);
+ struct iptc_handle *handle);
/* Renames a chain. */
int iptc_rename_chain(const ipt_chainlabel oldname,
const ipt_chainlabel newname,
- struct iptc_handle **handle);
+ struct iptc_handle *handle);
/* Sets the policy on a built-in chain. */
int iptc_set_policy(const ipt_chainlabel chain,
const ipt_chainlabel policy,
struct ipt_counters *counters,
- struct iptc_handle **handle);
+ struct iptc_handle *handle);
/* Get the number of references to this chain */
int iptc_get_references(unsigned int *ref,
const ipt_chainlabel chain,
- struct iptc_handle **handle);
+ struct iptc_handle *handle);
/* read packet and byte counters for a specific rule */
struct ipt_counters *iptc_read_counter(const ipt_chainlabel chain,
unsigned int rulenum,
- struct iptc_handle **handle);
+ struct iptc_handle *handle);
/* zero packet and byte counters for a specific rule */
int iptc_zero_counter(const ipt_chainlabel chain,
unsigned int rulenum,
- struct iptc_handle **handle);
+ struct iptc_handle *handle);
/* set packet and byte counters for a specific rule */
int iptc_set_counter(const ipt_chainlabel chain,
unsigned int rulenum,
struct ipt_counters *counters,
- struct iptc_handle **handle);
+ struct iptc_handle *handle);
/* Makes the actual changes. */
-int iptc_commit(struct iptc_handle **handle);
+int iptc_commit(struct iptc_handle *handle);
/* Get raw socket. */
int iptc_get_raw_socket(void);
} else if ((strcmp(buffer, "COMMIT\n") == 0) && (in_table)) {
if (!testing) {
DEBUGP("Calling commit\n");
- ret = ip6tc_commit(&handle);
+ ret = ip6tc_commit(handle);
+ ip6tc_free(handle);
+ handle = NULL;
} else {
DEBUGP("Not calling commit, testing\n");
ret = 1;
curtable[IP6T_TABLE_MAXNAMELEN] = '\0';
if (handle)
- ip6tc_free(&handle);
+ ip6tc_free(handle);
handle = create_handle(table, modprobe);
if (noflush == 0) {
DEBUGP("Cleaning all chains of table '%s'\n",
table);
for_each_chain(flush_entries, verbose, 1,
- &handle);
+ handle);
DEBUGP("Deleting all user-defined chains "
"of table '%s'\n", table);
for_each_chain(delete_chain, verbose, 0,
- &handle) ;
+ handle);
}
ret = 1;
if (ip6tc_builtin(chain, handle) <= 0) {
if (noflush && ip6tc_is_chain(chain, handle)) {
DEBUGP("Flushing existing user defined chain '%s'\n", chain);
- if (!ip6tc_flush_entries(chain, &handle))
+ if (!ip6tc_flush_entries(chain, handle))
exit_error(PARAMETER_PROBLEM,
"error flushing chain "
"'%s':%s\n", chain,
strerror(errno));
} else {
DEBUGP("Creating new chain '%s'\n", chain);
- if (!ip6tc_create_chain(chain, &handle))
+ if (!ip6tc_create_chain(chain, handle))
exit_error(PARAMETER_PROBLEM,
"error creating chain "
"'%s':%s\n", chain,
chain, policy);
if (!ip6tc_set_policy(chain, policy, &count,
- &handle))
+ handle))
exit_error(OTHER_PROBLEM,
"Can't set policy `%s'"
" on `%s' line %u: %s\n",
/* Dump out chain names first,
* thereby preventing dependency conflicts */
- for (chain = ip6tc_first_chain(&h);
+ for (chain = ip6tc_first_chain(h);
chain;
- chain = ip6tc_next_chain(&h)) {
+ chain = ip6tc_next_chain(h)) {
printf(":%s ", chain);
if (ip6tc_builtin(chain, h)) {
struct ip6t_counters count;
printf("%s ",
- ip6tc_get_policy(chain, &count, &h));
+ ip6tc_get_policy(chain, &count, h));
printf("[%llu:%llu]\n", (unsigned long long)count.pcnt, (unsigned long long)count.bcnt);
} else {
printf("- [0:0]\n");
}
- for (chain = ip6tc_first_chain(&h);
+ for (chain = ip6tc_first_chain(h);
chain;
- chain = ip6tc_next_chain(&h)) {
+ chain = ip6tc_next_chain(h)) {
const struct ip6t_entry *e;
/* Dump out rules */
- e = ip6tc_first_rule(chain, &h);
+ e = ip6tc_first_rule(chain, h);
while(e) {
- print_rule(e, &h, chain, show_counters);
- e = ip6tc_next_rule(e, &h);
+ print_rule(e, h, chain, show_counters);
+ e = ip6tc_next_rule(e, h);
}
}
exit_error(OTHER_PROBLEM, "Binary NYI\n");
}
- ip6tc_free(&h);
+ ip6tc_free(h);
return 1;
}
#endif
ret = do_command6(argc, argv, &table, &handle);
- if (ret)
- ret = ip6tc_commit(&handle);
+ if (ret) {
+ ret = ip6tc_commit(handle);
+ ip6tc_free(handle);
+ }
if (!ret)
fprintf(stderr, "ip6tables: %s\n",
static void
-print_header(unsigned int format, const char *chain, struct ip6tc_handle **handle)
+print_header(unsigned int format, const char *chain, struct ip6tc_handle *handle)
{
struct ip6t_counters counters;
const char *pol = ip6tc_get_policy(chain, &counters, handle);
unsigned int ndaddrs,
const struct in6_addr daddrs[],
int verbose,
- struct ip6tc_handle **handle)
+ struct ip6tc_handle *handle)
{
unsigned int i, j;
int ret = 1;
for (j = 0; j < ndaddrs; j++) {
fw->ipv6.dst = daddrs[j];
if (verbose)
- print_firewall_line(fw, *handle);
+ print_firewall_line(fw, handle);
ret &= ip6tc_append_entry(chain, fw, handle);
}
}
const struct in6_addr *saddr,
const struct in6_addr *daddr,
int verbose,
- struct ip6tc_handle **handle)
+ struct ip6tc_handle *handle)
{
fw->ipv6.src = *saddr;
fw->ipv6.dst = *daddr;
if (verbose)
- print_firewall_line(fw, *handle);
+ print_firewall_line(fw, handle);
return ip6tc_replace_entry(chain, fw, rulenum, handle);
}
unsigned int ndaddrs,
const struct in6_addr daddrs[],
int verbose,
- struct ip6tc_handle **handle)
+ struct ip6tc_handle *handle)
{
unsigned int i, j;
int ret = 1;
for (j = 0; j < ndaddrs; j++) {
fw->ipv6.dst = daddrs[j];
if (verbose)
- print_firewall_line(fw, *handle);
+ print_firewall_line(fw, handle);
ret &= ip6tc_insert_entry(chain, fw, rulenum, handle);
}
}
unsigned int ndaddrs,
const struct in6_addr daddrs[],
int verbose,
- struct ip6tc_handle **handle,
+ struct ip6tc_handle *handle,
struct ip6tables_rule_match *matches)
{
unsigned int i, j;
for (j = 0; j < ndaddrs; j++) {
fw->ipv6.dst = daddrs[j];
if (verbose)
- print_firewall_line(fw, *handle);
+ print_firewall_line(fw, handle);
ret &= ip6tc_delete_entry(chain, fw, mask, handle);
}
}
}
int
-for_each_chain(int (*fn)(const ip6t_chainlabel, int, struct ip6tc_handle **),
- int verbose, int builtinstoo, struct ip6tc_handle **handle)
+for_each_chain(int (*fn)(const ip6t_chainlabel, int, struct ip6tc_handle *),
+ int verbose, int builtinstoo, struct ip6tc_handle *handle)
{
int ret = 1;
const char *chain;
for (i = 0; i < chaincount; i++) {
if (!builtinstoo
&& ip6tc_builtin(chains + i*sizeof(ip6t_chainlabel),
- *handle) == 1)
+ handle) == 1)
continue;
ret &= fn(chains + i*sizeof(ip6t_chainlabel), verbose, handle);
}
int
flush_entries(const ip6t_chainlabel chain, int verbose,
- struct ip6tc_handle **handle)
+ struct ip6tc_handle *handle)
{
if (!chain)
return for_each_chain(flush_entries, verbose, 1, handle);
static int
zero_entries(const ip6t_chainlabel chain, int verbose,
- struct ip6tc_handle **handle)
+ struct ip6tc_handle *handle)
{
if (!chain)
return for_each_chain(zero_entries, verbose, 1, handle);
int
delete_chain(const ip6t_chainlabel chain, int verbose,
- struct ip6tc_handle **handle)
+ struct ip6tc_handle *handle)
{
if (!chain)
return for_each_chain(delete_chain, verbose, 0, handle);
static int
list_entries(const ip6t_chainlabel chain, int rulenum, int verbose, int numeric,
- int expanded, int linenumbers, struct ip6tc_handle **handle)
+ int expanded, int linenumbers, struct ip6tc_handle *handle)
{
int found = 0;
unsigned int format;
ip6tc_get_target(i, handle),
num,
format,
- *handle);
+ handle);
i = ip6tc_next_rule(i, handle);
}
found = 1;
/* We want this to be readable, so only print out neccessary fields.
* Because that's the kind of world I want to live in. */
void print_rule(const struct ip6t_entry *e,
- struct ip6tc_handle **h, const char *chain, int counters)
+ struct ip6tc_handle *h, const char *chain, int counters)
{
struct ip6t_entry_target *t;
const char *target_name;
static int
list_rules(const ip6t_chainlabel chain, int rulenum, int counters,
- struct ip6tc_handle **handle)
+ struct ip6tc_handle *handle)
{
const char *this = NULL;
int found = 0;
if (chain && strcmp(this, chain) != 0)
continue;
- if (ip6tc_builtin(this, *handle)) {
+ if (ip6tc_builtin(this, handle)) {
struct ip6t_counters count;
printf("-P %s %s", this, ip6tc_get_policy(this, &count, handle));
if (counters)
ret = append_entry(chain, e,
nsaddrs, saddrs, ndaddrs, daddrs,
options&OPT_VERBOSE,
- handle);
+ *handle);
break;
case CMD_DELETE:
ret = delete_entry(chain, e,
nsaddrs, saddrs, ndaddrs, daddrs,
options&OPT_VERBOSE,
- handle, matches);
+ *handle, matches);
break;
case CMD_DELETE_NUM:
- ret = ip6tc_delete_num_entry(chain, rulenum - 1, handle);
+ ret = ip6tc_delete_num_entry(chain, rulenum - 1, *handle);
break;
case CMD_REPLACE:
ret = replace_entry(chain, e, rulenum - 1,
saddrs, daddrs, options&OPT_VERBOSE,
- handle);
+ *handle);
break;
case CMD_INSERT:
ret = insert_entry(chain, e, rulenum - 1,
nsaddrs, saddrs, ndaddrs, daddrs,
options&OPT_VERBOSE,
- handle);
+ *handle);
break;
case CMD_FLUSH:
- ret = flush_entries(chain, options&OPT_VERBOSE, handle);
+ ret = flush_entries(chain, options&OPT_VERBOSE, *handle);
break;
case CMD_ZERO:
- ret = zero_entries(chain, options&OPT_VERBOSE, handle);
+ ret = zero_entries(chain, options&OPT_VERBOSE, *handle);
break;
case CMD_LIST:
case CMD_LIST|CMD_ZERO:
options&OPT_NUMERIC,
options&OPT_EXPANDED,
options&OPT_LINENUMBERS,
- handle);
+ *handle);
if (ret && (command & CMD_ZERO))
ret = zero_entries(chain,
- options&OPT_VERBOSE, handle);
+ options&OPT_VERBOSE, *handle);
break;
case CMD_LIST_RULES:
case CMD_LIST_RULES|CMD_ZERO:
ret = list_rules(chain,
rulenum,
options&OPT_VERBOSE,
- handle);
+ *handle);
if (ret && (command & CMD_ZERO))
ret = zero_entries(chain,
- options&OPT_VERBOSE, handle);
+ options&OPT_VERBOSE, *handle);
break;
case CMD_NEW_CHAIN:
- ret = ip6tc_create_chain(chain, handle);
+ ret = ip6tc_create_chain(chain, *handle);
break;
case CMD_DELETE_CHAIN:
- ret = delete_chain(chain, options&OPT_VERBOSE, handle);
+ ret = delete_chain(chain, options&OPT_VERBOSE, *handle);
break;
case CMD_RENAME_CHAIN:
- ret = ip6tc_rename_chain(chain, newname, handle);
+ ret = ip6tc_rename_chain(chain, newname, *handle);
break;
case CMD_SET_POLICY:
- ret = ip6tc_set_policy(chain, policy, options&OPT_COUNTERS ? &fw.counters : NULL, handle);
+ ret = ip6tc_set_policy(chain, policy, options&OPT_COUNTERS ? &fw.counters : NULL, *handle);
break;
default:
/* We should never reach this... */
} else if ((strcmp(buffer, "COMMIT\n") == 0) && (in_table)) {
if (!testing) {
DEBUGP("Calling commit\n");
- ret = iptc_commit(&handle);
+ ret = iptc_commit(handle);
+ iptc_free(handle);
+ handle = NULL;
} else {
DEBUGP("Not calling commit, testing\n");
ret = 1;
if (tablename && (strcmp(tablename, table) != 0))
continue;
if (handle)
- iptc_free(&handle);
+ iptc_free(handle);
handle = create_handle(table, modprobe);
if (noflush == 0) {
DEBUGP("Cleaning all chains of table '%s'\n",
table);
for_each_chain(flush_entries, verbose, 1,
- &handle);
+ handle);
DEBUGP("Deleting all user-defined chains "
"of table '%s'\n", table);
for_each_chain(delete_chain, verbose, 0,
- &handle) ;
+ handle);
}
ret = 1;
if (iptc_builtin(chain, handle) <= 0) {
if (noflush && iptc_is_chain(chain, handle)) {
DEBUGP("Flushing existing user defined chain '%s'\n", chain);
- if (!iptc_flush_entries(chain, &handle))
+ if (!iptc_flush_entries(chain, handle))
exit_error(PARAMETER_PROBLEM,
"error flushing chain "
"'%s':%s\n", chain,
strerror(errno));
} else {
DEBUGP("Creating new chain '%s'\n", chain);
- if (!iptc_create_chain(chain, &handle))
+ if (!iptc_create_chain(chain, handle))
exit_error(PARAMETER_PROBLEM,
"error creating chain "
"'%s':%s\n", chain,
chain, policy);
if (!iptc_set_policy(chain, policy, &count,
- &handle))
+ handle))
exit_error(OTHER_PROBLEM,
"Can't set policy `%s'"
" on `%s' line %u: %s\n",
/* Dump out chain names first,
* thereby preventing dependency conflicts */
- for (chain = iptc_first_chain(&h);
+ for (chain = iptc_first_chain(h);
chain;
- chain = iptc_next_chain(&h)) {
+ chain = iptc_next_chain(h)) {
printf(":%s ", chain);
if (iptc_builtin(chain, h)) {
struct ipt_counters count;
printf("%s ",
- iptc_get_policy(chain, &count, &h));
+ iptc_get_policy(chain, &count, h));
printf("[%llu:%llu]\n", (unsigned long long)count.pcnt, (unsigned long long)count.bcnt);
} else {
printf("- [0:0]\n");
}
- for (chain = iptc_first_chain(&h);
+ for (chain = iptc_first_chain(h);
chain;
- chain = iptc_next_chain(&h)) {
+ chain = iptc_next_chain(h)) {
const struct ipt_entry *e;
/* Dump out rules */
- e = iptc_first_rule(chain, &h);
+ e = iptc_first_rule(chain, h);
while(e) {
- print_rule(e, &h, chain, show_counters);
- e = iptc_next_rule(e, &h);
+ print_rule(e, h, chain, show_counters);
+ e = iptc_next_rule(e, h);
}
}
exit_error(OTHER_PROBLEM, "Binary NYI\n");
}
- iptc_free(&h);
+ iptc_free(h);
return 1;
}
#endif
ret = do_command(argc, argv, &table, &handle);
- if (ret)
- ret = iptc_commit(&handle);
+ if (ret) {
+ ret = iptc_commit(handle);
+ iptc_free(handle);
+ }
if (!ret) {
fprintf(stderr, "iptables: %s\n",
static void
-print_header(unsigned int format, const char *chain, struct iptc_handle **handle)
+print_header(unsigned int format, const char *chain, struct iptc_handle *handle)
{
struct ipt_counters counters;
const char *pol = iptc_get_policy(chain, &counters, handle);
unsigned int ndaddrs,
const struct in_addr daddrs[],
int verbose,
- struct iptc_handle **handle)
+ struct iptc_handle *handle)
{
unsigned int i, j;
int ret = 1;
for (j = 0; j < ndaddrs; j++) {
fw->ip.dst.s_addr = daddrs[j].s_addr;
if (verbose)
- print_firewall_line(fw, *handle);
+ print_firewall_line(fw, handle);
ret &= iptc_append_entry(chain, fw, handle);
}
}
const struct in_addr *saddr,
const struct in_addr *daddr,
int verbose,
- struct iptc_handle **handle)
+ struct iptc_handle *handle)
{
fw->ip.src.s_addr = saddr->s_addr;
fw->ip.dst.s_addr = daddr->s_addr;
if (verbose)
- print_firewall_line(fw, *handle);
+ print_firewall_line(fw, handle);
return iptc_replace_entry(chain, fw, rulenum, handle);
}
unsigned int ndaddrs,
const struct in_addr daddrs[],
int verbose,
- struct iptc_handle **handle)
+ struct iptc_handle *handle)
{
unsigned int i, j;
int ret = 1;
for (j = 0; j < ndaddrs; j++) {
fw->ip.dst.s_addr = daddrs[j].s_addr;
if (verbose)
- print_firewall_line(fw, *handle);
+ print_firewall_line(fw, handle);
ret &= iptc_insert_entry(chain, fw, rulenum, handle);
}
}
unsigned int ndaddrs,
const struct in_addr daddrs[],
int verbose,
- struct iptc_handle **handle,
+ struct iptc_handle *handle,
struct iptables_rule_match *matches)
{
unsigned int i, j;
for (j = 0; j < ndaddrs; j++) {
fw->ip.dst.s_addr = daddrs[j].s_addr;
if (verbose)
- print_firewall_line(fw, *handle);
+ print_firewall_line(fw, handle);
ret &= iptc_delete_entry(chain, fw, mask, handle);
}
}
}
int
-for_each_chain(int (*fn)(const ipt_chainlabel, int, struct iptc_handle **),
- int verbose, int builtinstoo, struct iptc_handle **handle)
+for_each_chain(int (*fn)(const ipt_chainlabel, int, struct iptc_handle *),
+ int verbose, int builtinstoo, struct iptc_handle *handle)
{
int ret = 1;
const char *chain;
for (i = 0; i < chaincount; i++) {
if (!builtinstoo
&& iptc_builtin(chains + i*sizeof(ipt_chainlabel),
- *handle) == 1)
+ handle) == 1)
continue;
ret &= fn(chains + i*sizeof(ipt_chainlabel), verbose, handle);
}
int
flush_entries(const ipt_chainlabel chain, int verbose,
- struct iptc_handle **handle)
+ struct iptc_handle *handle)
{
if (!chain)
return for_each_chain(flush_entries, verbose, 1, handle);
static int
zero_entries(const ipt_chainlabel chain, int verbose,
- struct iptc_handle **handle)
+ struct iptc_handle *handle)
{
if (!chain)
return for_each_chain(zero_entries, verbose, 1, handle);
int
delete_chain(const ipt_chainlabel chain, int verbose,
- struct iptc_handle **handle)
+ struct iptc_handle *handle)
{
if (!chain)
return for_each_chain(delete_chain, verbose, 0, handle);
static int
list_entries(const ipt_chainlabel chain, int rulenum, int verbose, int numeric,
- int expanded, int linenumbers, struct iptc_handle **handle)
+ int expanded, int linenumbers, struct iptc_handle *handle)
{
int found = 0;
unsigned int format;
iptc_get_target(i, handle),
num,
format,
- *handle);
+ handle);
i = iptc_next_rule(i, handle);
}
found = 1;
/* We want this to be readable, so only print out neccessary fields.
* Because that's the kind of world I want to live in. */
void print_rule(const struct ipt_entry *e,
- struct iptc_handle **h, const char *chain, int counters)
+ struct iptc_handle *h, const char *chain, int counters)
{
struct ipt_entry_target *t;
const char *target_name;
static int
list_rules(const ipt_chainlabel chain, int rulenum, int counters,
- struct iptc_handle **handle)
+ struct iptc_handle *handle)
{
const char *this = NULL;
int found = 0;
if (chain && strcmp(this, chain) != 0)
continue;
- if (iptc_builtin(this, *handle)) {
+ if (iptc_builtin(this, handle)) {
struct ipt_counters count;
printf("-P %s %s", this, iptc_get_policy(this, &count, handle));
if (counters)
ret = append_entry(chain, e,
nsaddrs, saddrs, ndaddrs, daddrs,
options&OPT_VERBOSE,
- handle);
+ *handle);
break;
case CMD_DELETE:
ret = delete_entry(chain, e,
nsaddrs, saddrs, ndaddrs, daddrs,
options&OPT_VERBOSE,
- handle, matches);
+ *handle, matches);
break;
case CMD_DELETE_NUM:
- ret = iptc_delete_num_entry(chain, rulenum - 1, handle);
+ ret = iptc_delete_num_entry(chain, rulenum - 1, *handle);
break;
case CMD_REPLACE:
ret = replace_entry(chain, e, rulenum - 1,
saddrs, daddrs, options&OPT_VERBOSE,
- handle);
+ *handle);
break;
case CMD_INSERT:
ret = insert_entry(chain, e, rulenum - 1,
nsaddrs, saddrs, ndaddrs, daddrs,
options&OPT_VERBOSE,
- handle);
+ *handle);
break;
case CMD_FLUSH:
- ret = flush_entries(chain, options&OPT_VERBOSE, handle);
+ ret = flush_entries(chain, options&OPT_VERBOSE, *handle);
break;
case CMD_ZERO:
- ret = zero_entries(chain, options&OPT_VERBOSE, handle);
+ ret = zero_entries(chain, options&OPT_VERBOSE, *handle);
break;
case CMD_LIST:
case CMD_LIST|CMD_ZERO:
options&OPT_NUMERIC,
options&OPT_EXPANDED,
options&OPT_LINENUMBERS,
- handle);
+ *handle);
if (ret && (command & CMD_ZERO))
ret = zero_entries(chain,
- options&OPT_VERBOSE, handle);
+ options&OPT_VERBOSE, *handle);
break;
case CMD_LIST_RULES:
case CMD_LIST_RULES|CMD_ZERO:
ret = list_rules(chain,
rulenum,
options&OPT_VERBOSE,
- handle);
+ *handle);
if (ret && (command & CMD_ZERO))
ret = zero_entries(chain,
- options&OPT_VERBOSE, handle);
+ options&OPT_VERBOSE, *handle);
break;
case CMD_NEW_CHAIN:
- ret = iptc_create_chain(chain, handle);
+ ret = iptc_create_chain(chain, *handle);
break;
case CMD_DELETE_CHAIN:
- ret = delete_chain(chain, options&OPT_VERBOSE, handle);
+ ret = delete_chain(chain, options&OPT_VERBOSE, *handle);
break;
case CMD_RENAME_CHAIN:
- ret = iptc_rename_chain(chain, newname, handle);
+ ret = iptc_rename_chain(chain, newname, *handle);
break;
case CMD_SET_POLICY:
- ret = iptc_set_policy(chain, policy, options&OPT_COUNTERS ? &fw.counters : NULL, handle);
+ ret = iptc_set_policy(chain, policy, options&OPT_COUNTERS ? &fw.counters : NULL, *handle);
break;
default:
/* We should never reach this... */
CHECK(h);
return h;
error:
- TC_FREE(&h);
+ TC_FREE(h);
/* A different process changed the ruleset size, retry */
if (errno == EAGAIN)
goto retry;
}
void
-TC_FREE(struct xtc_handle **h)
+TC_FREE(struct xtc_handle *h)
{
struct chain_head *c, *tmp;
sockfd = -1;
}
- list_for_each_entry_safe(c, tmp, &(*h)->chains, list) {
+ list_for_each_entry_safe(c, tmp, &h->chains, list) {
struct rule_head *r, *rtmp;
list_for_each_entry_safe(r, rtmp, &c->rules, list) {
free(c);
}
- iptcc_chain_index_free(*h);
-
- free((*h)->entries);
- free(*h);
+ iptcc_chain_index_free(h);
- *h = NULL;
+ free(h->entries);
+ free(h);
}
static inline int
/* Iterator functions to run through the chains. */
const char *
-TC_FIRST_CHAIN(struct xtc_handle **handle)
+TC_FIRST_CHAIN(struct xtc_handle *handle)
{
- struct chain_head *c = list_entry((*handle)->chains.next,
+ struct chain_head *c = list_entry(handle->chains.next,
struct chain_head, list);
iptc_fn = TC_FIRST_CHAIN;
- if (list_empty(&(*handle)->chains)) {
+ if (list_empty(&handle->chains)) {
DEBUGP(": no chains\n");
return NULL;
}
- (*handle)->chain_iterator_cur = c;
- iptcc_chain_iterator_advance(*handle);
+ handle->chain_iterator_cur = c;
+ iptcc_chain_iterator_advance(handle);
DEBUGP(": returning `%s'\n", c->name);
return c->name;
/* Iterator functions to run through the chains. Returns NULL at end. */
const char *
-TC_NEXT_CHAIN(struct xtc_handle **handle)
+TC_NEXT_CHAIN(struct xtc_handle *handle)
{
- struct chain_head *c = (*handle)->chain_iterator_cur;
+ struct chain_head *c = handle->chain_iterator_cur;
iptc_fn = TC_NEXT_CHAIN;
return NULL;
}
- iptcc_chain_iterator_advance(*handle);
+ iptcc_chain_iterator_advance(handle);
DEBUGP(": returning `%s'\n", c->name);
return c->name;
/* Get first rule in the given chain: NULL for empty chain. */
const STRUCT_ENTRY *
-TC_FIRST_RULE(const char *chain, struct xtc_handle **handle)
+TC_FIRST_RULE(const char *chain, struct xtc_handle *handle)
{
struct chain_head *c;
struct rule_head *r;
DEBUGP("first rule(%s): ", chain);
- c = iptcc_find_label(chain, *handle);
+ c = iptcc_find_label(chain, handle);
if (!c) {
errno = ENOENT;
return NULL;
}
r = list_entry(c->rules.next, struct rule_head, list);
- (*handle)->rule_iterator_cur = r;
+ handle->rule_iterator_cur = r;
DEBUGP_C("%p\n", r);
return r->entry;
/* Returns NULL when rules run out. */
const STRUCT_ENTRY *
-TC_NEXT_RULE(const STRUCT_ENTRY *prev, struct xtc_handle **handle)
+TC_NEXT_RULE(const STRUCT_ENTRY *prev, struct xtc_handle *handle)
{
struct rule_head *r;
iptc_fn = TC_NEXT_RULE;
- DEBUGP("rule_iterator_cur=%p...", (*handle)->rule_iterator_cur);
+ DEBUGP("rule_iterator_cur=%p...", handle->rule_iterator_cur);
- if (!(*handle)->rule_iterator_cur) {
+ if (handle->rule_iterator_cur == NULL) {
DEBUGP_C("returning NULL\n");
return NULL;
}
- r = list_entry((*handle)->rule_iterator_cur->list.next,
+ r = list_entry(handle->rule_iterator_cur->list.next,
struct rule_head, list);
iptc_fn = TC_NEXT_RULE;
DEBUGP_C("next=%p, head=%p...", &r->list,
- &(*handle)->rule_iterator_cur->chain->rules);
+ &handle->rule_iterator_cur->chain->rules);
- if (&r->list == &(*handle)->rule_iterator_cur->chain->rules) {
- (*handle)->rule_iterator_cur = NULL;
+ if (&r->list == &handle->rule_iterator_cur->chain->rules) {
+ handle->rule_iterator_cur = NULL;
DEBUGP_C("finished, returning NULL\n");
return NULL;
}
- (*handle)->rule_iterator_cur = r;
+ handle->rule_iterator_cur = r;
/* NOTE: prev is without any influence ! */
DEBUGP_C("returning rule %p\n", r);
/* How many rules in this chain? */
static unsigned int
-TC_NUM_RULES(const char *chain, struct xtc_handle **handle)
+TC_NUM_RULES(const char *chain, struct xtc_handle *handle)
{
struct chain_head *c;
iptc_fn = TC_NUM_RULES;
- CHECK(*handle);
+ CHECK(handle);
- c = iptcc_find_label(chain, *handle);
+ c = iptcc_find_label(chain, handle);
if (!c) {
errno = ENOENT;
return (unsigned int)-1;
}
static const STRUCT_ENTRY *
-TC_GET_RULE(const char *chain, unsigned int n, struct xtc_handle **handle)
+TC_GET_RULE(const char *chain, unsigned int n, struct xtc_handle *handle)
{
struct chain_head *c;
struct rule_head *r;
iptc_fn = TC_GET_RULE;
- CHECK(*handle);
+ CHECK(handle);
- c = iptcc_find_label(chain, *handle);
+ c = iptcc_find_label(chain, handle);
if (!c) {
errno = ENOENT;
return NULL;
/* Returns a pointer to the target name of this position. */
const char *TC_GET_TARGET(const STRUCT_ENTRY *ce,
- struct xtc_handle **handle)
+ struct xtc_handle *handle)
{
STRUCT_ENTRY *e = (STRUCT_ENTRY *)ce;
struct rule_head *r = container_of(e, struct rule_head, entry[0]);
const char *
TC_GET_POLICY(const char *chain,
STRUCT_COUNTERS *counters,
- struct xtc_handle **handle)
+ struct xtc_handle *handle)
{
struct chain_head *c;
DEBUGP("called for chain %s\n", chain);
- c = iptcc_find_label(chain, *handle);
+ c = iptcc_find_label(chain, handle);
if (!c) {
errno = ENOENT;
return NULL;
TC_INSERT_ENTRY(const IPT_CHAINLABEL chain,
const STRUCT_ENTRY *e,
unsigned int rulenum,
- struct xtc_handle **handle)
+ struct xtc_handle *handle)
{
struct chain_head *c;
struct rule_head *r;
iptc_fn = TC_INSERT_ENTRY;
- if (!(c = iptcc_find_label(chain, *handle))) {
+ if (!(c = iptcc_find_label(chain, handle))) {
errno = ENOENT;
return 0;
}
memcpy(r->entry, e, e->next_offset);
r->counter_map.maptype = COUNTER_MAP_SET;
- if (!iptcc_map_target(*handle, r)) {
+ if (!iptcc_map_target(handle, r)) {
free(r);
return 0;
}
list_add_tail(&r->list, prev);
c->num_rules++;
- set_changed(*handle);
+ set_changed(handle);
return 1;
}
TC_REPLACE_ENTRY(const IPT_CHAINLABEL chain,
const STRUCT_ENTRY *e,
unsigned int rulenum,
- struct xtc_handle **handle)
+ struct xtc_handle *handle)
{
struct chain_head *c;
struct rule_head *r, *old;
iptc_fn = TC_REPLACE_ENTRY;
- if (!(c = iptcc_find_label(chain, *handle))) {
+ if (!(c = iptcc_find_label(chain, handle))) {
errno = ENOENT;
return 0;
}
memcpy(r->entry, e, e->next_offset);
r->counter_map.maptype = COUNTER_MAP_SET;
- if (!iptcc_map_target(*handle, r)) {
+ if (!iptcc_map_target(handle, r)) {
free(r);
return 0;
}
list_add(&r->list, &old->list);
iptcc_delete_rule(old);
- set_changed(*handle);
+ set_changed(handle);
return 1;
}
int
TC_APPEND_ENTRY(const IPT_CHAINLABEL chain,
const STRUCT_ENTRY *e,
- struct xtc_handle **handle)
+ struct xtc_handle *handle)
{
struct chain_head *c;
struct rule_head *r;
iptc_fn = TC_APPEND_ENTRY;
- if (!(c = iptcc_find_label(chain, *handle))) {
+ if (!(c = iptcc_find_label(chain, handle))) {
DEBUGP("unable to find chain `%s'\n", chain);
errno = ENOENT;
return 0;
memcpy(r->entry, e, e->next_offset);
r->counter_map.maptype = COUNTER_MAP_SET;
- if (!iptcc_map_target(*handle, r)) {
+ if (!iptcc_map_target(handle, r)) {
DEBUGP("unable to map target of rule for chain `%s'\n", chain);
free(r);
return 0;
list_add_tail(&r->list, &c->rules);
c->num_rules++;
- set_changed(*handle);
+ set_changed(handle);
return 1;
}
TC_DELETE_ENTRY(const IPT_CHAINLABEL chain,
const STRUCT_ENTRY *origfw,
unsigned char *matchmask,
- struct xtc_handle **handle)
+ struct xtc_handle *handle)
{
struct chain_head *c;
struct rule_head *r, *i;
iptc_fn = TC_DELETE_ENTRY;
- if (!(c = iptcc_find_label(chain, *handle))) {
+ if (!(c = iptcc_find_label(chain, handle))) {
errno = ENOENT;
return 0;
}
memcpy(r->entry, origfw, origfw->next_offset);
r->counter_map.maptype = COUNTER_MAP_NOMAP;
- if (!iptcc_map_target(*handle, r)) {
+ if (!iptcc_map_target(handle, r)) {
DEBUGP("unable to map target of rule for chain `%s'\n", chain);
free(r);
return 0;
/* If we are about to delete the rule that is the
* current iterator, move rule iterator back. next
* pointer will then point to real next node */
- if (i == (*handle)->rule_iterator_cur) {
- (*handle)->rule_iterator_cur =
- list_entry((*handle)->rule_iterator_cur->list.prev,
+ if (i == handle->rule_iterator_cur) {
+ handle->rule_iterator_cur =
+ list_entry(handle->rule_iterator_cur->list.prev,
struct rule_head, list);
}
c->num_rules--;
iptcc_delete_rule(i);
- set_changed(*handle);
+ set_changed(handle);
free(r);
return 1;
}
int
TC_DELETE_NUM_ENTRY(const IPT_CHAINLABEL chain,
unsigned int rulenum,
- struct xtc_handle **handle)
+ struct xtc_handle *handle)
{
struct chain_head *c;
struct rule_head *r;
iptc_fn = TC_DELETE_NUM_ENTRY;
- if (!(c = iptcc_find_label(chain, *handle))) {
+ if (!(c = iptcc_find_label(chain, handle))) {
errno = ENOENT;
return 0;
}
/* If we are about to delete the rule that is the current
* iterator, move rule iterator back. next pointer will then
* point to real next node */
- if (r == (*handle)->rule_iterator_cur) {
- (*handle)->rule_iterator_cur =
- list_entry((*handle)->rule_iterator_cur->list.prev,
+ if (r == handle->rule_iterator_cur) {
+ handle->rule_iterator_cur =
+ list_entry(handle->rule_iterator_cur->list.prev,
struct rule_head, list);
}
c->num_rules--;
iptcc_delete_rule(r);
- set_changed(*handle);
+ set_changed(handle);
return 1;
}
const char *
TC_CHECK_PACKET(const IPT_CHAINLABEL chain,
STRUCT_ENTRY *entry,
- struct xtc_handle **handle)
+ struct xtc_handle *handle)
{
iptc_fn = TC_CHECK_PACKET;
errno = ENOSYS;
/* Flushes the entries in the given chain (ie. empties chain). */
int
-TC_FLUSH_ENTRIES(const IPT_CHAINLABEL chain, struct xtc_handle **handle)
+TC_FLUSH_ENTRIES(const IPT_CHAINLABEL chain, struct xtc_handle *handle)
{
struct chain_head *c;
struct rule_head *r, *tmp;
iptc_fn = TC_FLUSH_ENTRIES;
- if (!(c = iptcc_find_label(chain, *handle))) {
+ if (!(c = iptcc_find_label(chain, handle))) {
errno = ENOENT;
return 0;
}
c->num_rules = 0;
- set_changed(*handle);
+ set_changed(handle);
return 1;
}
/* Zeroes the counters in a chain. */
int
-TC_ZERO_ENTRIES(const IPT_CHAINLABEL chain, struct xtc_handle **handle)
+TC_ZERO_ENTRIES(const IPT_CHAINLABEL chain, struct xtc_handle *handle)
{
struct chain_head *c;
struct rule_head *r;
iptc_fn = TC_ZERO_ENTRIES;
- if (!(c = iptcc_find_label(chain, *handle))) {
+ if (!(c = iptcc_find_label(chain, handle))) {
errno = ENOENT;
return 0;
}
r->counter_map.maptype = COUNTER_MAP_ZEROED;
}
- set_changed(*handle);
+ set_changed(handle);
return 1;
}
STRUCT_COUNTERS *
TC_READ_COUNTER(const IPT_CHAINLABEL chain,
unsigned int rulenum,
- struct xtc_handle **handle)
+ struct xtc_handle *handle)
{
struct chain_head *c;
struct rule_head *r;
iptc_fn = TC_READ_COUNTER;
CHECK(*handle);
- if (!(c = iptcc_find_label(chain, *handle))) {
+ if (!(c = iptcc_find_label(chain, handle))) {
errno = ENOENT;
return NULL;
}
int
TC_ZERO_COUNTER(const IPT_CHAINLABEL chain,
unsigned int rulenum,
- struct xtc_handle **handle)
+ struct xtc_handle *handle)
{
struct chain_head *c;
struct rule_head *r;
iptc_fn = TC_ZERO_COUNTER;
- CHECK(*handle);
+ CHECK(handle);
- if (!(c = iptcc_find_label(chain, *handle))) {
+ if (!(c = iptcc_find_label(chain, handle))) {
errno = ENOENT;
return 0;
}
if (r->counter_map.maptype == COUNTER_MAP_NORMAL_MAP)
r->counter_map.maptype = COUNTER_MAP_ZEROED;
- set_changed(*handle);
+ set_changed(handle);
return 1;
}
TC_SET_COUNTER(const IPT_CHAINLABEL chain,
unsigned int rulenum,
STRUCT_COUNTERS *counters,
- struct xtc_handle **handle)
+ struct xtc_handle *handle)
{
struct chain_head *c;
struct rule_head *r;
STRUCT_ENTRY *e;
iptc_fn = TC_SET_COUNTER;
- CHECK(*handle);
+ CHECK(handle);
- if (!(c = iptcc_find_label(chain, *handle))) {
+ if (!(c = iptcc_find_label(chain, handle))) {
errno = ENOENT;
return 0;
}
memcpy(&e->counters, counters, sizeof(STRUCT_COUNTERS));
- set_changed(*handle);
+ set_changed(handle);
return 1;
}
/* To create a chain, create two rules: error node and unconditional
* return. */
int
-TC_CREATE_CHAIN(const IPT_CHAINLABEL chain, struct xtc_handle **handle)
+TC_CREATE_CHAIN(const IPT_CHAINLABEL chain, struct xtc_handle *handle)
{
static struct chain_head *c;
int capacity;
/* find_label doesn't cover built-in targets: DROP, ACCEPT,
QUEUE, RETURN. */
- if (iptcc_find_label(chain, *handle)
+ if (iptcc_find_label(chain, handle)
|| strcmp(chain, LABEL_DROP) == 0
|| strcmp(chain, LABEL_ACCEPT) == 0
|| strcmp(chain, LABEL_QUEUE) == 0
return 0;
}
- (*handle)->num_chains++; /* New user defined chain */
+ handle->num_chains++; /* New user defined chain */
DEBUGP("Creating chain `%s'\n", chain);
- iptc_insert_chain(*handle, c); /* Insert sorted */
+ iptc_insert_chain(handle, c); /* Insert sorted */
/* Inserting chains don't change the correctness of the chain
* index (except if its smaller than index[0], but that
* in the buckets. Thus, only rebuild chain index when the
* capacity is exceed with CHAIN_INDEX_INSERT_MAX chains.
*/
- capacity = (*handle)->chain_index_sz * CHAIN_INDEX_BUCKET_LEN;
- exceeded = ((((*handle)->num_chains)-capacity));
+ capacity = handle->chain_index_sz * CHAIN_INDEX_BUCKET_LEN;
+ exceeded = handle->num_chains - capacity;
if (exceeded > CHAIN_INDEX_INSERT_MAX) {
debug("Capacity(%d) exceeded(%d) rebuild (chains:%d)\n",
- capacity, exceeded, (*handle)->num_chains);
- iptcc_chain_index_rebuild(*handle);
+ capacity, exceeded, handle->num_chains);
+ iptcc_chain_index_rebuild(handle);
}
- set_changed(*handle);
+ set_changed(handle);
return 1;
}
/* Get the number of references to this chain. */
int
TC_GET_REFERENCES(unsigned int *ref, const IPT_CHAINLABEL chain,
- struct xtc_handle **handle)
+ struct xtc_handle *handle)
{
struct chain_head *c;
iptc_fn = TC_GET_REFERENCES;
- if (!(c = iptcc_find_label(chain, *handle))) {
+ if (!(c = iptcc_find_label(chain, handle))) {
errno = ENOENT;
return 0;
}
/* Deletes a chain. */
int
-TC_DELETE_CHAIN(const IPT_CHAINLABEL chain, struct xtc_handle **handle)
+TC_DELETE_CHAIN(const IPT_CHAINLABEL chain, struct xtc_handle *handle)
{
unsigned int references;
struct chain_head *c;
iptc_fn = TC_DELETE_CHAIN;
- if (!(c = iptcc_find_label(chain, *handle))) {
+ if (!(c = iptcc_find_label(chain, handle))) {
DEBUGP("cannot find chain `%s'\n", chain);
errno = ENOENT;
return 0;
}
- if (TC_BUILTIN(chain, *handle)) {
+ if (TC_BUILTIN(chain, handle)) {
DEBUGP("cannot remove builtin chain `%s'\n", chain);
errno = EINVAL;
return 0;
/* If we are about to delete the chain that is the current
* iterator, move chain iterator forward. */
- if (c == (*handle)->chain_iterator_cur)
- iptcc_chain_iterator_advance(*handle);
+ if (c == handle->chain_iterator_cur)
+ iptcc_chain_iterator_advance(handle);
- (*handle)->num_chains--; /* One user defined chain deleted */
+ handle->num_chains--; /* One user defined chain deleted */
//list_del(&c->list); /* Done in iptcc_chain_index_delete_chain() */
- iptcc_chain_index_delete_chain(c, *handle);
+ iptcc_chain_index_delete_chain(c, handle);
free(c);
DEBUGP("chain `%s' deleted\n", chain);
- set_changed(*handle);
+ set_changed(handle);
return 1;
}
/* Renames a chain. */
int TC_RENAME_CHAIN(const IPT_CHAINLABEL oldname,
const IPT_CHAINLABEL newname,
- struct xtc_handle **handle)
+ struct xtc_handle *handle)
{
struct chain_head *c;
iptc_fn = TC_RENAME_CHAIN;
/* find_label doesn't cover built-in targets: DROP, ACCEPT,
QUEUE, RETURN. */
- if (iptcc_find_label(newname, *handle)
+ if (iptcc_find_label(newname, handle)
|| strcmp(newname, LABEL_DROP) == 0
|| strcmp(newname, LABEL_ACCEPT) == 0
|| strcmp(newname, LABEL_QUEUE) == 0
return 0;
}
- if (!(c = iptcc_find_label(oldname, *handle))
- || TC_BUILTIN(oldname, *handle)) {
+ if (!(c = iptcc_find_label(oldname, handle))
+ || TC_BUILTIN(oldname, handle)) {
errno = ENOENT;
return 0;
}
strncpy(c->name, newname, sizeof(IPT_CHAINLABEL));
- set_changed(*handle);
+ set_changed(handle);
return 1;
}
TC_SET_POLICY(const IPT_CHAINLABEL chain,
const IPT_CHAINLABEL policy,
STRUCT_COUNTERS *counters,
- struct xtc_handle **handle)
+ struct xtc_handle *handle)
{
struct chain_head *c;
iptc_fn = TC_SET_POLICY;
- if (!(c = iptcc_find_label(chain, *handle))) {
+ if (!(c = iptcc_find_label(chain, handle))) {
DEBUGP("cannot find chain `%s'\n", chain);
errno = ENOENT;
return 0;
c->counter_map.maptype = COUNTER_MAP_NOMAP;
}
- set_changed(*handle);
+ set_changed(handle);
return 1;
}
int
-TC_COMMIT(struct xtc_handle **handle)
+TC_COMMIT(struct xtc_handle *handle)
{
/* Replace, then map back the counters. */
STRUCT_REPLACE *repl;
CHECK(*handle);
/* Don't commit if nothing changed. */
- if (!(*handle)->changed)
+ if (!handle->changed)
goto finished;
- new_number = iptcc_compile_table_prep(*handle, &new_size);
+ new_number = iptcc_compile_table_prep(handle, &new_size);
if (new_number < 0) {
errno = ENOMEM;
goto out_zero;
/* These are the old counters we will get from kernel */
repl->counters = malloc(sizeof(STRUCT_COUNTERS)
- * (*handle)->info.num_entries);
+ * handle->info.num_entries);
if (!repl->counters) {
errno = ENOMEM;
goto out_free_repl;
}
memset(newcounters, 0, counterlen);
- strcpy(repl->name, (*handle)->info.name);
+ strcpy(repl->name, handle->info.name);
repl->num_entries = new_number;
repl->size = new_size;
- repl->num_counters = (*handle)->info.num_entries;
- repl->valid_hooks = (*handle)->info.valid_hooks;
+ repl->num_counters = handle->info.num_entries;
+ repl->valid_hooks = handle->info.valid_hooks;
DEBUGP("num_entries=%u, size=%u, num_counters=%u\n",
repl->num_entries, repl->size, repl->num_counters);
- ret = iptcc_compile_table(*handle, repl);
+ ret = iptcc_compile_table(handle, repl);
if (ret < 0) {
errno = ret;
goto out_free_newcounters;
goto out_free_newcounters;
/* Put counters back. */
- strcpy(newcounters->name, (*handle)->info.name);
+ strcpy(newcounters->name, handle->info.name);
newcounters->num_counters = new_number;
- list_for_each_entry(c, &(*handle)->chains, list) {
+ list_for_each_entry(c, &handle->chains, list) {
struct rule_head *r;
/* Builtin chains have their own counters */
free(newcounters);
finished:
- TC_FREE(handle);
return 1;
out_free_newcounters: