From: Peter Warasin <peter@endian.com>
To: netfilter-devel@vger.kernel.org
Subject: [PATCH] Makes little part of iptables target parsing code better readable
Date: Sun, 06 Jan 2008 04:37:07 +0100 [thread overview]
Message-ID: <47804CE3.8060608@endian.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 291 bytes --]
This patch sources out the target getopt parsing into a separate
code-block which before has been done as a side-effect of a check.
This removes also a level of indentation and makes the part more
understandable when reading the code.
Signed-off-by: Peter Warasin <peter@endian.com>
---
[-- Attachment #2: iptables_readable_targetparsing.patch --]
[-- Type: text/x-patch, Size: 5060 bytes --]
Index: iptables/iptables.c
===================================================================
--- iptables.orig/iptables.c 2008-01-06 02:59:40.000000000 +0100
+++ iptables/iptables.c 2008-01-06 03:03:03.000000000 +0100
@@ -1822,83 +1822,88 @@
exit_tryhelp(2);
default:
- if (!target
- || !(target->parse(c - target->option_offset,
- argv, invert,
- &target->tflags,
- &fw, &target->t))) {
- for (matchp = matches; matchp; matchp = matchp->next) {
- if (matchp->completed)
- continue;
- if (matchp->match->parse(c - matchp->match->option_offset,
- argv, invert,
- &matchp->match->mflags,
- &fw,
- &matchp->match->m))
- break;
- }
- m = matchp ? matchp->match : NULL;
-
- /* If you listen carefully, you can
- actually hear this code suck. */
-
- /* some explanations (after four different bugs
- * in 3 different releases): If we encounter a
- * parameter, that has not been parsed yet,
- * it's not an option of an explicitly loaded
- * match or a target. However, we support
- * implicit loading of the protocol match
- * extension. '-p tcp' means 'l4 proto 6' and
- * at the same time 'load tcp protocol match on
- * demand if we specify --dport'.
- *
- * To make this work, we need to make sure:
- * - the parameter has not been parsed by
- * a match (m above)
- * - a protocol has been specified
- * - the protocol extension has not been
- * loaded yet, or is loaded and unused
- * [think of iptables-restore!]
- * - the protocol extension can be successively
- * loaded
- */
- if (m == NULL
- && protocol
- && (!find_proto(protocol, DONT_LOAD,
- options&OPT_NUMERIC, NULL)
- || (find_proto(protocol, DONT_LOAD,
- options&OPT_NUMERIC, NULL)
- && (proto_used == 0))
- )
- && (m = find_proto(protocol, TRY_LOAD,
- options&OPT_NUMERIC, &matches))) {
- /* Try loading protocol */
- size_t size;
-
- proto_used = 1;
-
- size = IPT_ALIGN(sizeof(struct ipt_entry_match))
- + m->size;
-
- m->m = fw_calloc(1, size);
- m->m->u.match_size = size;
- strcpy(m->m->u.user.name, m->name);
- set_revision(m->m->u.user.name,
- m->revision);
- if (m->init != NULL)
- m->init(m->m);
-
- opts = merge_options(opts,
- m->extra_opts, &m->option_offset);
+ /* handles targets */
+ if (target && target->parse(c - target->option_offset,
+ argv, invert,
+ &target->tflags,
+ &fw, &target->t)) {
+ continue;
+ }
- optind--;
+ /* handles matches */
+ for (matchp = matches; matchp; matchp = matchp->next) {
+ if (matchp->completed)
continue;
- }
- if (!m)
- exit_error(PARAMETER_PROBLEM,
- "Unknown arg `%s'",
- argv[optind-1]);
+ if (matchp->match->parse(c - matchp->match->option_offset,
+ argv, invert,
+ &matchp->match->mflags,
+ &fw,
+ &matchp->match->m))
+ break;
}
+
+ /* handles options of autoloaded matches (explaination below) */
+ m = matchp ? matchp->match : NULL;
+
+ /* If you listen carefully, you can
+ actually hear this code suck. */
+
+ /* some explanations (after four different bugs
+ * in 3 different releases): If we encounter a
+ * parameter, that has not been parsed yet,
+ * it's not an option of an explicitly loaded
+ * match or a target. However, we support
+ * implicit loading of the protocol match
+ * extension. '-p tcp' means 'l4 proto 6' and
+ * at the same time 'load tcp protocol match on
+ * demand if we specify --dport'.
+ *
+ * To make this work, we need to make sure:
+ * - the parameter has not been parsed by
+ * a match (m above)
+ * - a protocol has been specified
+ * - the protocol extension has not been
+ * loaded yet, or is loaded and unused
+ * [think of iptables-restore!]
+ * - the protocol extension can be successively
+ * loaded
+ */
+ if (m == NULL
+ && protocol
+ && (!find_proto(protocol, DONT_LOAD,
+ options&OPT_NUMERIC, NULL)
+ || (find_proto(protocol, DONT_LOAD,
+ options&OPT_NUMERIC, NULL)
+ && (proto_used == 0))
+ )
+ && (m = find_proto(protocol, TRY_LOAD,
+ options&OPT_NUMERIC, &matches))) {
+ /* Try loading protocol */
+ size_t size;
+
+ proto_used = 1;
+
+ size = IPT_ALIGN(sizeof(struct ipt_entry_match))
+ + m->size;
+
+ m->m = fw_calloc(1, size);
+ m->m->u.match_size = size;
+ strcpy(m->m->u.user.name, m->name);
+ set_revision(m->m->u.user.name,
+ m->revision);
+ if (m->init != NULL)
+ m->init(m->m);
+
+ opts = merge_options(opts,
+ m->extra_opts, &m->option_offset);
+
+ optind--;
+ continue;
+ }
+ if (!m)
+ exit_error(PARAMETER_PROBLEM,
+ "Unknown arg `%s'",
+ argv[optind-1]);
}
invert = FALSE;
}
reply other threads:[~2008-01-06 3:37 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=47804CE3.8060608@endian.com \
--to=peter@endian.com \
--cc=netfilter-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).