summaryrefslogtreecommitdiffstats
path: root/ip6tables.c
diff options
context:
space:
mode:
authorJan Engelhardt <jengelh@medozas.de>2011-02-07 03:39:36 +0100
committerJan Engelhardt <jengelh@medozas.de>2011-02-07 03:42:56 +0100
commit9bb76094b26d22c7a85d98a075640f054b7910f4 (patch)
tree51ea0f732ebad8b2ff5a12e479770bce5dcde7f5 /ip6tables.c
parent94e247b80a0c28140056ee07ea24e54ca5dbebaf (diff)
src: move jump option handling from do_command6 into its own function
Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
Diffstat (limited to 'ip6tables.c')
-rw-r--r--ip6tables.c72
1 files changed, 38 insertions, 34 deletions
diff --git a/ip6tables.c b/ip6tables.c
index c475bf26..eb28dc0a 100644
--- a/ip6tables.c
+++ b/ip6tables.c
@@ -1302,6 +1302,33 @@ static void command_default(struct iptables_command_state *cs)
xtables_error(PARAMETER_PROBLEM, "Unknown arg \"%s\"", optarg);
}
+static void command_jump(struct iptables_command_state *cs)
+{
+ size_t size;
+
+ set_option(&cs->options, OPT_JUMP, &cs->fw6.ipv6.invflags, cs->invert);
+ cs->jumpto = parse_target(optarg);
+ /* TRY_LOAD (may be chain name) */
+ cs->target = xtables_find_target(cs->jumpto, XTF_TRY_LOAD);
+
+ if (cs->target == NULL)
+ return;
+
+ size = IP6T_ALIGN(sizeof(struct ip6t_entry_target)) + cs->target->size;
+
+ cs->target->t = xtables_calloc(1, size);
+ cs->target->t->u.target_size = size;
+ strcpy(cs->target->t->u.user.name, cs->jumpto);
+ cs->target->t->u.user.revision = cs->target->revision;
+ if (cs->target->init != NULL)
+ cs->target->init(cs->target->t);
+ opts = xtables_merge_options(ip6tables_globals.orig_opts, opts,
+ cs->target->extra_opts,
+ &cs->target->option_offset);
+ if (opts == NULL)
+ xtables_error(OTHER_PROBLEM, "can't alloc memory!");
+}
+
int do_command6(int argc, char *argv[], char **table, struct ip6tc_handle **handle)
{
struct iptables_command_state cs;
@@ -1320,10 +1347,10 @@ int do_command6(int argc, char *argv[], char **table, struct ip6tc_handle **hand
struct xtables_match *m;
struct xtables_rule_match *matchp;
struct xtables_target *t;
- const char *jumpto = "";
unsigned long long cnt;
memset(&cs, 0, sizeof(cs));
+ cs.jumpto = "";
cs.argv = argv;
/* re-set optind to 0 in case do_command gets called
@@ -1548,36 +1575,12 @@ int do_command6(int argc, char *argv[], char **table, struct ip6tc_handle **hand
set_option(&cs.options, OPT_JUMP, &cs.fw6.ipv6.invflags,
cs.invert);
cs.fw6.ipv6.flags |= IP6T_F_GOTO;
- jumpto = parse_target(optarg);
+ cs.jumpto = parse_target(optarg);
break;
#endif
case 'j':
- set_option(&cs.options, OPT_JUMP, &cs.fw6.ipv6.invflags,
- cs.invert);
- jumpto = parse_target(optarg);
- /* TRY_LOAD (may be chain name) */
- cs.target = xtables_find_target(jumpto, XTF_TRY_LOAD);
-
- if (cs.target) {
- size_t size;
-
- size = IP6T_ALIGN(sizeof(struct ip6t_entry_target))
- + cs.target->size;
-
- cs.target->t = xtables_calloc(1, size);
- cs.target->t->u.target_size = size;
- strcpy(cs.target->t->u.user.name, jumpto);
- cs.target->t->u.user.revision = cs.target->revision;
- if (cs.target->init != NULL)
- cs.target->init(cs.target->t);
- opts = xtables_merge_options(ip6tables_globals.orig_opts, opts,
- cs.target->extra_opts,
- &cs.target->option_offset);
- if (opts == NULL)
- xtables_error(OTHER_PROBLEM,
- "can't alloc memory!");
- }
+ command_jump(&cs);
break;
@@ -1806,10 +1809,10 @@ int do_command6(int argc, char *argv[], char **table, struct ip6tc_handle **hand
chain);
}
- if (cs.target && ip6tc_is_chain(jumpto, *handle)) {
+ if (cs.target && ip6tc_is_chain(cs.jumpto, *handle)) {
fprintf(stderr,
"Warning: using chain %s, not extension\n",
- jumpto);
+ cs.jumpto);
if (cs.target->t)
free(cs.target->t);
@@ -1820,8 +1823,8 @@ int do_command6(int argc, char *argv[], char **table, struct ip6tc_handle **hand
/* If they didn't specify a target, or it's a chain
name, use standard. */
if (!cs.target
- && (strlen(jumpto) == 0
- || ip6tc_is_chain(jumpto, *handle))) {
+ && (strlen(cs.jumpto) == 0
+ || ip6tc_is_chain(cs.jumpto, *handle))) {
size_t size;
cs.target = xtables_find_target(IP6T_STANDARD_TARGET,
@@ -1831,7 +1834,7 @@ int do_command6(int argc, char *argv[], char **table, struct ip6tc_handle **hand
+ cs.target->size;
cs.target->t = xtables_calloc(1, size);
cs.target->t->u.target_size = size;
- strcpy(cs.target->t->u.user.name, jumpto);
+ strcpy(cs.target->t->u.user.name, cs.jumpto);
if (cs.target->init != NULL)
cs.target->init(cs.target->t);
}
@@ -1844,9 +1847,10 @@ int do_command6(int argc, char *argv[], char **table, struct ip6tc_handle **hand
#ifdef IP6T_F_GOTO
if (cs.fw6.ipv6.flags & IP6T_F_GOTO)
xtables_error(PARAMETER_PROBLEM,
- "goto '%s' is not a chain\n", jumpto);
+ "goto '%s' is not a chain\n",
+ cs.jumpto);
#endif
- xtables_find_target(jumpto, XTF_LOAD_MUST_SUCCEED);
+ xtables_find_target(cs.jumpto, XTF_LOAD_MUST_SUCCEED);
} else {
e = generate_entry(&cs.fw6, cs.matches, cs.target->t);
free(cs.target->t);