diff options
author | Phil Sutter <phil@nwl.cc> | 2016-06-10 13:42:08 +0200 |
---|---|---|
committer | Stephen Hemminger <shemming@brocade.com> | 2016-06-14 14:35:56 -0700 |
commit | 2ef4008585ec9184a0abf7534bf7f575ce6579d1 (patch) | |
tree | 5953be75826e19579d81a9d913f38c6886896d0f /tc/m_xt.c | |
parent | f6ddd9c5da4e552322baf237075aae6db17237d4 (diff) | |
download | platform_external_iproute2-2ef4008585ec9184a0abf7534bf7f575ce6579d1.tar.gz platform_external_iproute2-2ef4008585ec9184a0abf7534bf7f575ce6579d1.tar.bz2 platform_external_iproute2-2ef4008585ec9184a0abf7534bf7f575ce6579d1.zip |
tc: m_xt: Introduce get_xtables_target_opts()
This pulls common code from parse_ipt() and print_ipt() functions
together.
While here, also fix for incorrect use of the global 'optarg' variable
in print_ipt().
Signed-off-by: Phil Sutter <phil@nwl.cc>
Diffstat (limited to 'tc/m_xt.c')
-rw-r--r-- | tc/m_xt.c | 58 |
1 files changed, 29 insertions, 29 deletions
@@ -116,6 +116,27 @@ static void set_lib_dir(void) } +static int get_xtables_target_opts(struct xtables_globals *globals, + struct xtables_target *m) +{ + struct option *opts; + +#if (XTABLES_VERSION_CODE >= 6) + opts = xtables_options_xfrm(globals->orig_opts, + globals->opts, + m->x6_options, + &m->option_offset); +#else + opts = xtables_merge_options(globals->opts, + m->extra_opts, + &m->option_offset); +#endif + if (!opts) + return -1; + globals->opts = opts; + return 0; +} + static int parse_ipt(struct action_util *a, int *argc_p, char ***argv_p, int tca_id, struct nlmsghdr *n) { @@ -129,7 +150,6 @@ static int parse_ipt(struct action_util *a, int *argc_p, int size = 0; int iok = 0, ok = 0; __u32 hook = 0, index = 0; - struct option *opts = NULL; /* copy tcipt_globals because .opts will be modified by iptables */ struct xtables_globals tmp_tcipt_globals = tcipt_globals; @@ -163,21 +183,11 @@ static int parse_ipt(struct action_util *a, int *argc_p, printf(" %s error\n", m->name); return -1; } -#if (XTABLES_VERSION_CODE >= 6) - opts = xtables_options_xfrm(tmp_tcipt_globals.orig_opts, - tmp_tcipt_globals.opts, - m->x6_options, - &m->option_offset); -#else - opts = xtables_merge_options(tmp_tcipt_globals.opts, - m->extra_opts, - &m->option_offset); -#endif - if (opts == NULL) { + + if (get_xtables_target_opts(&tmp_tcipt_globals, m) < 0) { fprintf(stderr, " failed to find additional options for target %s\n\n", optarg); return -1; - } else - tmp_tcipt_globals.opts = opts; + } ok++; break; @@ -292,7 +302,6 @@ print_ipt(struct action_util *au, FILE * f, struct rtattr *arg) struct xtables_target *m; struct rtattr *tb[TCA_IPT_MAX + 1]; struct xt_entry_target *t = NULL; - struct option *opts = NULL; if (arg == NULL) return -1; @@ -339,21 +348,12 @@ print_ipt(struct action_util *au, FILE * f, struct rtattr *arg) return -1; } -#if (XTABLES_VERSION_CODE >= 6) - opts = xtables_options_xfrm(tmp_tcipt_globals.orig_opts, - tmp_tcipt_globals.opts, - m->x6_options, - &m->option_offset); -#else - opts = xtables_merge_options(tmp_tcipt_globals.opts, - m->extra_opts, - &m->option_offset); -#endif - if (opts == NULL) { - fprintf(stderr, " failed to find additional options for target %s\n\n", optarg); + if (get_xtables_target_opts(&tmp_tcipt_globals, m) < 0) { + fprintf(stderr, + " failed to find additional options for target %s\n\n", + t->u.user.name); return -1; - } else - tmp_tcipt_globals.opts = opts; + } fprintf(f, "\ttarget "); m->print(NULL, m->t, 0); if (tb[TCA_IPT_INDEX] == NULL) { |