From 9816ef34f02ebbffece0ec7d298742f1d73e1acd Mon Sep 17 00:00:00 2001
From: Phil Sutter <psutter@redhat.com>
Date: Tue, 4 Apr 2017 16:23:42 +0200
Subject: [PATCH] tc: m_xt: Introduce get_xtables_target_opts()
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1326726
Upstream Status: iproute2.git commit 2ef4008585ec9
Conflicts: Context change due to missing upstream commit 32a121cba2579
("tc: code cleanup").
commit 2ef4008585ec9184a0abf7534bf7f575ce6579d1
Author: Phil Sutter <phil@nwl.cc>
Date: Fri Jun 10 13:42:08 2016 +0200
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>
---
tc/m_xt.c | 60 ++++++++++++++++++++++++++++++------------------------------
1 file changed, 30 insertions(+), 30 deletions(-)
diff --git a/tc/m_xt.c b/tc/m_xt.c
index da3f7ab..c96d58c 100644
--- a/tc/m_xt.c
+++ b/tc/m_xt.c
@@ -116,7 +116,28 @@ static void set_lib_dir(void)
}
-static int parse_ipt(struct action_util *a,int *argc_p,
+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)
{
struct xtables_target *m = NULL;
@@ -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;
@@ -291,7 +301,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;
@@ -337,21 +346,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) {
--
1.8.3.1