From: Tomasz Bursztyka Date: Thu, 22 Sep 2011 12:39:25 +0000 (+0300) Subject: tools: Code factorization for rule inclusion in iptables-test X-Git-Tag: accepted/2.0alpha-wayland/20121110.002834~1101 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9268cea5c670024112409741fdbfa957a2aca092;p=profile%2Fivi%2Fconnman.git tools: Code factorization for rule inclusion in iptables-test --- diff --git a/tools/iptables-test.c b/tools/iptables-test.c index c1d4f86..8acff94 100644 --- a/tools/iptables-test.c +++ b/tools/iptables-test.c @@ -619,30 +619,27 @@ static void update_hooks(struct connman_iptables *table, GList *chain_head, } } -static int -connman_iptables_add_rule(struct connman_iptables *table, +static struct ipt_entry *prepare_rule_inclusion(struct connman_iptables *table, struct ipt_ip *ip, char *chain_name, char *target_name, struct xtables_target *xt_t, - char *match_name, struct xtables_match *xt_m) + char *match_name, struct xtables_match *xt_m, + int *builtin) { GList *chain_tail, *chain_head; struct ipt_entry *new_entry; struct connman_iptables_entry *head; - int builtin = -1, ret; chain_head = find_chain_head(table, chain_name); if (chain_head == NULL) - return -EINVAL; + return NULL; chain_tail = find_chain_tail(table, chain_name); if (chain_tail == NULL) - return -EINVAL; + return NULL; - new_entry = new_rule(table, ip, - target_name, xt_t, - match_name, xt_m); + new_entry = new_rule(table, ip, target_name, xt_t, match_name, xt_m); if (new_entry == NULL) - return -EINVAL; + return NULL; update_hooks(table, chain_head, new_entry); @@ -653,12 +650,34 @@ connman_iptables_add_rule(struct connman_iptables *table, */ head = chain_head->data; if (head->builtin < 0) - builtin = -1; + *builtin = -1; else if (chain_head == chain_tail->prev) { - builtin = head->builtin; + *builtin = head->builtin; head->builtin = -1; } + return new_entry; +} + +static int +connman_iptables_add_rule(struct connman_iptables *table, + struct ipt_ip *ip, char *chain_name, + char *target_name, struct xtables_target *xt_t, + char *match_name, struct xtables_match *xt_m) +{ + GList *chain_tail; + struct ipt_entry *new_entry; + int builtin = -1, ret; + + chain_tail = find_chain_tail(table, chain_name); + if (chain_tail == NULL) + return -EINVAL; + + new_entry = prepare_rule_inclusion(table, ip, chain_name, + target_name, xt_t, match_name, xt_m, &builtin); + if (new_entry == NULL) + return -EINVAL; + ret = connman_add_entry(table, new_entry, chain_tail->prev, builtin); if (ret < 0) g_free(new_entry);