|
|
4aca6e |
From 9816ef34f02ebbffece0ec7d298742f1d73e1acd Mon Sep 17 00:00:00 2001
|
|
|
4aca6e |
From: Phil Sutter <psutter@redhat.com>
|
|
|
4aca6e |
Date: Tue, 4 Apr 2017 16:23:42 +0200
|
|
|
4aca6e |
Subject: [PATCH] tc: m_xt: Introduce get_xtables_target_opts()
|
|
|
4aca6e |
|
|
|
4aca6e |
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1326726
|
|
|
4aca6e |
Upstream Status: iproute2.git commit 2ef4008585ec9
|
|
|
4aca6e |
Conflicts: Context change due to missing upstream commit 32a121cba2579
|
|
|
4aca6e |
("tc: code cleanup").
|
|
|
4aca6e |
|
|
|
4aca6e |
commit 2ef4008585ec9184a0abf7534bf7f575ce6579d1
|
|
|
4aca6e |
Author: Phil Sutter <phil@nwl.cc>
|
|
|
4aca6e |
Date: Fri Jun 10 13:42:08 2016 +0200
|
|
|
4aca6e |
|
|
|
4aca6e |
tc: m_xt: Introduce get_xtables_target_opts()
|
|
|
4aca6e |
|
|
|
4aca6e |
This pulls common code from parse_ipt() and print_ipt() functions
|
|
|
4aca6e |
together.
|
|
|
4aca6e |
|
|
|
4aca6e |
While here, also fix for incorrect use of the global 'optarg' variable
|
|
|
4aca6e |
in print_ipt().
|
|
|
4aca6e |
|
|
|
4aca6e |
Signed-off-by: Phil Sutter <phil@nwl.cc>
|
|
|
4aca6e |
---
|
|
|
4aca6e |
tc/m_xt.c | 60 ++++++++++++++++++++++++++++++------------------------------
|
|
|
4aca6e |
1 file changed, 30 insertions(+), 30 deletions(-)
|
|
|
4aca6e |
|
|
|
4aca6e |
diff --git a/tc/m_xt.c b/tc/m_xt.c
|
|
|
4aca6e |
index da3f7ab..c96d58c 100644
|
|
|
4aca6e |
--- a/tc/m_xt.c
|
|
|
4aca6e |
+++ b/tc/m_xt.c
|
|
|
4aca6e |
@@ -116,7 +116,28 @@ static void set_lib_dir(void)
|
|
|
4aca6e |
|
|
|
4aca6e |
}
|
|
|
4aca6e |
|
|
|
4aca6e |
-static int parse_ipt(struct action_util *a,int *argc_p,
|
|
|
4aca6e |
+static int get_xtables_target_opts(struct xtables_globals *globals,
|
|
|
4aca6e |
+ struct xtables_target *m)
|
|
|
4aca6e |
+{
|
|
|
4aca6e |
+ struct option *opts;
|
|
|
4aca6e |
+
|
|
|
4aca6e |
+#if (XTABLES_VERSION_CODE >= 6)
|
|
|
4aca6e |
+ opts = xtables_options_xfrm(globals->orig_opts,
|
|
|
4aca6e |
+ globals->opts,
|
|
|
4aca6e |
+ m->x6_options,
|
|
|
4aca6e |
+ &m->option_offset);
|
|
|
4aca6e |
+#else
|
|
|
4aca6e |
+ opts = xtables_merge_options(globals->opts,
|
|
|
4aca6e |
+ m->extra_opts,
|
|
|
4aca6e |
+ &m->option_offset);
|
|
|
4aca6e |
+#endif
|
|
|
4aca6e |
+ if (!opts)
|
|
|
4aca6e |
+ return -1;
|
|
|
4aca6e |
+ globals->opts = opts;
|
|
|
4aca6e |
+ return 0;
|
|
|
4aca6e |
+}
|
|
|
4aca6e |
+
|
|
|
4aca6e |
+static int parse_ipt(struct action_util *a, int *argc_p,
|
|
|
4aca6e |
char ***argv_p, int tca_id, struct nlmsghdr *n)
|
|
|
4aca6e |
{
|
|
|
4aca6e |
struct xtables_target *m = NULL;
|
|
|
4aca6e |
@@ -129,7 +150,6 @@ static int parse_ipt(struct action_util *a,int *argc_p,
|
|
|
4aca6e |
int size = 0;
|
|
|
4aca6e |
int iok = 0, ok = 0;
|
|
|
4aca6e |
__u32 hook = 0, index = 0;
|
|
|
4aca6e |
- struct option *opts = NULL;
|
|
|
4aca6e |
|
|
|
4aca6e |
/* copy tcipt_globals because .opts will be modified by iptables */
|
|
|
4aca6e |
struct xtables_globals tmp_tcipt_globals = tcipt_globals;
|
|
|
4aca6e |
@@ -163,21 +183,11 @@ static int parse_ipt(struct action_util *a,int *argc_p,
|
|
|
4aca6e |
printf(" %s error\n", m->name);
|
|
|
4aca6e |
return -1;
|
|
|
4aca6e |
}
|
|
|
4aca6e |
-#if (XTABLES_VERSION_CODE >= 6)
|
|
|
4aca6e |
- opts = xtables_options_xfrm(tmp_tcipt_globals.orig_opts,
|
|
|
4aca6e |
- tmp_tcipt_globals.opts,
|
|
|
4aca6e |
- m->x6_options,
|
|
|
4aca6e |
- &m->option_offset);
|
|
|
4aca6e |
-#else
|
|
|
4aca6e |
- opts = xtables_merge_options(tmp_tcipt_globals.opts,
|
|
|
4aca6e |
- m->extra_opts,
|
|
|
4aca6e |
- &m->option_offset);
|
|
|
4aca6e |
-#endif
|
|
|
4aca6e |
- if (opts == NULL) {
|
|
|
4aca6e |
+
|
|
|
4aca6e |
+ if (get_xtables_target_opts(&tmp_tcipt_globals, m) < 0) {
|
|
|
4aca6e |
fprintf(stderr, " failed to find additional options for target %s\n\n", optarg);
|
|
|
4aca6e |
return -1;
|
|
|
4aca6e |
- } else
|
|
|
4aca6e |
- tmp_tcipt_globals.opts = opts;
|
|
|
4aca6e |
+ }
|
|
|
4aca6e |
ok++;
|
|
|
4aca6e |
break;
|
|
|
4aca6e |
|
|
|
4aca6e |
@@ -291,7 +301,6 @@ print_ipt(struct action_util *au,FILE * f, struct rtattr *arg)
|
|
|
4aca6e |
struct xtables_target *m;
|
|
|
4aca6e |
struct rtattr *tb[TCA_IPT_MAX + 1];
|
|
|
4aca6e |
struct xt_entry_target *t = NULL;
|
|
|
4aca6e |
- struct option *opts = NULL;
|
|
|
4aca6e |
|
|
|
4aca6e |
if (arg == NULL)
|
|
|
4aca6e |
return -1;
|
|
|
4aca6e |
@@ -337,21 +346,12 @@ print_ipt(struct action_util *au,FILE * f, struct rtattr *arg)
|
|
|
4aca6e |
return -1;
|
|
|
4aca6e |
}
|
|
|
4aca6e |
|
|
|
4aca6e |
-#if (XTABLES_VERSION_CODE >= 6)
|
|
|
4aca6e |
- opts = xtables_options_xfrm(tmp_tcipt_globals.orig_opts,
|
|
|
4aca6e |
- tmp_tcipt_globals.opts,
|
|
|
4aca6e |
- m->x6_options,
|
|
|
4aca6e |
- &m->option_offset);
|
|
|
4aca6e |
-#else
|
|
|
4aca6e |
- opts = xtables_merge_options(tmp_tcipt_globals.opts,
|
|
|
4aca6e |
- m->extra_opts,
|
|
|
4aca6e |
- &m->option_offset);
|
|
|
4aca6e |
-#endif
|
|
|
4aca6e |
- if (opts == NULL) {
|
|
|
4aca6e |
- fprintf(stderr, " failed to find additional options for target %s\n\n", optarg);
|
|
|
4aca6e |
+ if (get_xtables_target_opts(&tmp_tcipt_globals, m) < 0) {
|
|
|
4aca6e |
+ fprintf(stderr,
|
|
|
4aca6e |
+ " failed to find additional options for target %s\n\n",
|
|
|
4aca6e |
+ t->u.user.name);
|
|
|
4aca6e |
return -1;
|
|
|
4aca6e |
- } else
|
|
|
4aca6e |
- tmp_tcipt_globals.opts = opts;
|
|
|
4aca6e |
+ }
|
|
|
4aca6e |
fprintf(f, "\ttarget ");
|
|
|
4aca6e |
m->print(NULL, m->t, 0);
|
|
|
4aca6e |
if (tb[TCA_IPT_INDEX] == NULL) {
|
|
|
4aca6e |
--
|
|
|
4aca6e |
1.8.3.1
|
|
|
4aca6e |
|