summaryrefslogtreecommitdiffstats
path: root/ip6tables.c
diff options
context:
space:
mode:
authorJan Engelhardt <jengelh@medozas.de>2011-02-07 03:20:02 +0100
committerJan Engelhardt <jengelh@medozas.de>2011-02-07 03:31:50 +0100
commit94e247b80a0c28140056ee07ea24e54ca5dbebaf (patch)
treeb32d1dd7639e562240f09c3b574737f168ca544e /ip6tables.c
parentacef6043f647806096c41294b00472f6ce7462d7 (diff)
src: unclutter command_default function
(Essentially, 5 levels of indentation have been stripped compared to the original layout, and this is surely a result that looks a lot better than it did before.) Things to note: 1. If the m->parse call succeeded, we can return from the function and do not need to go through the other code. As such, "m" is guaranteed to be useless at the end of the match loop, and so, conditions can be removed. 2. Since the per-extension parse function only ever get their own option codes (since v1.4.10-26-gd09b6d5), their return value no longer has a meaning and can be ignored. Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
Diffstat (limited to 'ip6tables.c')
-rw-r--r--ip6tables.c100
1 files changed, 44 insertions, 56 deletions
diff --git a/ip6tables.c b/ip6tables.c
index 3330420f..c475bf26 100644
--- a/ip6tables.c
+++ b/ip6tables.c
@@ -1247,71 +1247,59 @@ static void command_default(struct iptables_command_state *cs)
if (cs->target == NULL || cs->target->parse == NULL ||
cs->c < cs->target->option_offset ||
- cs->c >= cs->target->option_offset + XT_OPTION_OFFSET_SCALE ||
- !cs->target->parse(cs->c - cs->target->option_offset,
- cs->argv, cs->invert,
- &cs->target->tflags,
- &cs->fw6, &cs->target->t)) {
- for (matchp = cs->matches; matchp; matchp = matchp->next) {
- if (matchp->completed ||
- matchp->match->parse == NULL)
- continue;
- if (cs->c < matchp->match->option_offset ||
- cs->c >= matchp->match->option_offset + XT_OPTION_OFFSET_SCALE)
- continue;
- if (matchp->match->parse(cs->c - matchp->match->option_offset,
- cs->argv, cs->invert,
- &matchp->match->mflags,
- &cs->fw6,
- &matchp->match->m))
- break;
- }
- m = matchp ? matchp->match : NULL;
+ cs->c >= cs->target->option_offset + XT_OPTION_OFFSET_SCALE) {
+ cs->target->parse(cs->c - cs->target->option_offset, cs->argv,
+ cs->invert, &cs->target->tflags, &cs->fw6,
+ &cs->target->t);
+ return;
+ }
- if (m == NULL && (m = load_proto(cs)) != NULL) {
- /* Try loading protocol */
- size_t size;
+ for (matchp = cs->matches; matchp; matchp = matchp->next) {
+ m = matchp->match;
- cs->proto_used = 1;
+ if (matchp->completed || m->parse == NULL)
+ continue;
+ if (cs->c < matchp->match->option_offset ||
+ cs->c >= matchp->match->option_offset + XT_OPTION_OFFSET_SCALE)
+ continue;
+ m->parse(cs->c - m->option_offset, cs->argv, cs->invert,
+ &m->mflags, &cs->fw6, &m->m);
+ return;
+ }
- size = IP6T_ALIGN(sizeof(struct ip6t_entry_match))
- + m->size;
+ /* Try loading protocol */
+ m = load_proto(cs);
+ if (m != NULL) {
+ size_t size;
- m->m = xtables_calloc(1, size);
- m->m->u.match_size = size;
- strcpy(m->m->u.user.name, m->name);
- m->m->u.user.revision = m->revision;
- if (m->init != NULL)
- m->init(m->m);
+ cs->proto_used = 1;
- opts = xtables_merge_options(ip6tables_globals.orig_opts, opts,
- m->extra_opts, &m->option_offset);
+ size = IP6T_ALIGN(sizeof(struct ip6t_entry_match)) + m->size;
- optind--;
- return;
- }
+ m->m = xtables_calloc(1, size);
+ m->m->u.match_size = size;
+ strcpy(m->m->u.user.name, m->name);
+ m->m->u.user.revision = m->revision;
+ if (m->init != NULL)
+ m->init(m->m);
- if (!m) {
- if (cs->c == '?') {
- if (optopt) {
- xtables_error(
- PARAMETER_PROBLEM,
- "option `%s' "
- "requires an "
- "argument",
- cs->argv[optind-1]);
- } else {
- xtables_error(
- PARAMETER_PROBLEM,
- "unknown option "
- "`%s'",
- cs->argv[optind-1]);
- }
- }
+ opts = xtables_merge_options(ip6tables_globals.orig_opts, opts,
+ m->extra_opts, &m->option_offset);
+
+ optind--;
+ return;
+ }
+
+ if (cs->c == '?') {
+ if (optopt)
xtables_error(PARAMETER_PROBLEM,
- "Unknown arg `%s'", optarg);
- }
+ "option \"%s\" requires an argument",
+ cs->argv[optind-1]);
+ else
+ xtables_error(PARAMETER_PROBLEM,
+ "unknown option \"%s\"", cs->argv[optind-1]);
}
+ xtables_error(PARAMETER_PROBLEM, "Unknown arg \"%s\"", optarg);
}
int do_command6(int argc, char *argv[], char **table, struct ip6tc_handle **handle)