diff options
author | Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com> | 2011-10-27 10:24:47 +0300 |
---|---|---|
committer | Samuel Ortiz <sameo@linux.intel.com> | 2011-10-28 21:26:12 +0200 |
commit | 7fddd5a9b33817028e889cefb5aa16bfd7997630 (patch) | |
tree | 053d78c6a87c6cdd36eb10cc7384241e53f35a5f /tools | |
parent | 1e1cf8166f48eef131738d672292750e32301d73 (diff) | |
download | connman-7fddd5a9b33817028e889cefb5aa16bfd7997630.tar.gz connman-7fddd5a9b33817028e889cefb5aa16bfd7997630.tar.bz2 connman-7fddd5a9b33817028e889cefb5aa16bfd7997630.zip |
tools: Refactor iptables_test matches preparation
Diffstat (limited to 'tools')
-rw-r--r-- | tools/iptables-test.c | 73 |
1 files changed, 48 insertions, 25 deletions
diff --git a/tools/iptables-test.c b/tools/iptables-test.c index 5ee1ec39..2c5c6704 100644 --- a/tools/iptables-test.c +++ b/tools/iptables-test.c @@ -1306,6 +1306,48 @@ static struct xtables_target *prepare_target(struct connman_iptables *table, return xt_t; } +static struct xtables_match *prepare_matches(struct connman_iptables *table, + char *match_name) +{ + struct xtables_match *xt_m; + size_t match_size; + + if (match_name == NULL) + return NULL; + + xt_m = xtables_find_match(match_name, XTF_LOAD_MUST_SUCCEED, NULL); + match_size = ALIGN(sizeof(struct ipt_entry_match)) + xt_m->size; + + xt_m->m = g_try_malloc0(match_size); + if (xt_m->m == NULL) + return NULL; + + xt_m->m->u.match_size = match_size; + strcpy(xt_m->m->u.user.name, xt_m->name); + xt_m->m->u.user.revision = xt_m->revision; + + if (xt_m->init != NULL) + xt_m->init(xt_m->m); + + if (xt_m != xt_m->next) { + connman_iptables_globals.opts = + xtables_merge_options( +#if XTABLES_VERSION_CODE > 5 + connman_iptables_globals.orig_opts, +#endif + connman_iptables_globals.opts, + xt_m->extra_opts, + &xt_m->option_offset); + + if (connman_iptables_globals.opts == NULL) { + g_free(xt_m->m); + xt_m = NULL; + } + } + + return xt_m; +} + int main(int argc, char *argv[]) { struct connman_iptables *table; @@ -1315,7 +1357,6 @@ int main(int argc, char *argv[]) char *table_name, *chain, *new_chain, *match_name, *target_name; char *delete_chain, *flush_chain; int c, in_len, out_len; - size_t size; gboolean dump, invert, delete, insert, delete_rule; struct in_addr src, dst; @@ -1411,30 +1452,6 @@ int main(int argc, char *argv[]) case 'm': match_name = optarg; - - xt_m = xtables_find_match(optarg, XTF_LOAD_MUST_SUCCEED, NULL); - size = ALIGN(sizeof(struct ipt_entry_match)) + xt_m->size; - xt_m->m = g_try_malloc0(size); - if (xt_m == NULL) - goto out; - xt_m->m->u.match_size = size; - strcpy(xt_m->m->u.user.name, xt_m->name); - xt_m->m->u.user.revision = xt_m->revision; - if (xt_m->init != NULL) - xt_m->init(xt_m->m); - if (xt_m != xt_m->next) { - connman_iptables_globals.opts = - xtables_merge_options( -#if XTABLES_VERSION_CODE > 5 - connman_iptables_globals.orig_opts, -#endif - connman_iptables_globals.opts, - xt_m->extra_opts, - &xt_m->option_offset); - if (connman_iptables_globals.opts == NULL) - goto out; - } - break; case 'o': @@ -1544,6 +1561,12 @@ int main(int argc, char *argv[]) if (xt_t == NULL) goto out; + if (match_name != NULL) { + xt_m = prepare_matches(table, match_name); + if (xt_m == NULL) + goto out; + } + if (delete_rule == TRUE) { printf("Deleting %s to %s (match %s)\n", target_name, chain, match_name); |