Skip to contentSkip to conversation

iptables: mainloop cleanup, symbol vis+versioning

PATCH In review Jan Engelhardt 2 participants 12 messages Feb 4, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

The following changes since commit 9ee2a9fe2f74b616da34878104bd1ff406534ad1:

extensions: add extension for devgroup match (2011-02-03 06:10:41 +0100)

are available in the git repository at:
git://dev.medozas.de/iptables master

Jan Engelhardt (8):
iptables: reduce indentation of parse loop (1/3)
iptables: reduce indentation of parse loop (2/3)
iptables: use variable as shortcut in parse loop
iptables: reduce indentation of parse loop (3/3)
iptables: fix error message for unknown options
build: directly use config.h in internal.h
libxtables: symbol visibility
libxtables: symbol versioning

 .gitignore                     |    1 -
 Makefile.am                    |    9 +-
 configure.ac                   |    6 +-
 extensions/GNUmakefile.in      |    2 +-
 include/iptables/internal.h    |   21 +++++
 include/iptables/internal.h.in |   13 ---
 ip6tables.c                    |  187 ++++++++++++++++++---------------------
 iptables.c                     |  194 ++++++++++++++++++----------------------
 libxtables.map                 |   55 +++++++++++
 m4/gcc4_visibility.m4          |   21 +++++
 xtables.c                      |  109 +++++++++++++----------
 11 files changed, 340 insertions(+), 278 deletions(-)
 create mode 100644 include/iptables/internal.h
 delete mode 100644 include/iptables/internal.h.in
 create mode 100644 libxtables.map
 create mode 100644 m4/gcc4_visibility.m4
#1 lore raw

PATCH 1/8 iptables: reduce indentation of parse loop (1/3)

Trying to make this code suck less by using early
exclusion/break/return.

References: http://iq0.com/notes/deep.nesting.html

---
 ip6tables.c |  184 ++++++++++++++++++++++++++++----------------------------
 iptables.c  |  196 +++++++++++++++++++++++++++++-----------------------------
 2 files changed, 190 insertions(+), 190 deletions(-)
ip6tables.c +92 -92
index 8c1b504..d453868 100644
@@ -1703,104 +1703,104 @@ int do_command6(int argc, char *argv[], char **table, struct ip6tc_handle **hand
 			exit_tryhelp(2);
 
 		default:
-			if (target == NULL || target->parse == NULL ||
-			    c < target->option_offset ||
-			    c >= target->option_offset + XT_OPTION_OFFSET_SCALE ||
-			    !target->parse(c - target->option_offset,
+			if (target != NULL && target->parse != NULL &&
+			    c >= target->option_offset &&
+			    c < target->option_offset + XT_OPTION_OFFSET_SCALE &&
+			    target->parse(c - target->option_offset,
 					       argv, invert,
 					       &target->tflags,
-					       &fw, &target->t)) {
-				for (matchp = matches; matchp; matchp = matchp->next) {
-					if (matchp->completed ||
-					    matchp->match->parse == NULL)
-						continue;
-					if (c < matchp->match->option_offset ||
-					    c >= matchp->match->option_offset + XT_OPTION_OFFSET_SCALE)
-						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 ip6tables-restore!]
-				 * - the protocol extension can be successively
-				 *   loaded
-				 */
-				if (m == NULL
-				    && protocol
-				    && (!find_proto(protocol, XTF_DONT_LOAD,
-						   options&OPT_NUMERIC, NULL)
-					|| (find_proto(protocol, XTF_DONT_LOAD,
-							options&OPT_NUMERIC, NULL)
-					    && (proto_used == 0))
-				       )
-				    && (m = find_proto(protocol, XTF_TRY_LOAD,
-						       options&OPT_NUMERIC, &matches))) {
-					/* Try loading protocol */
-					size_t size;
-
-					proto_used = 1;
-
-					size = IP6T_ALIGN(sizeof(struct ip6t_entry_match))
-							 + m->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);
-
-					opts = xtables_merge_options(ip6tables_globals.orig_opts, opts,
-					    m->extra_opts, &m->option_offset);
-
-					optind--;
+					       &fw, &target->t))
+				break;
+			for (matchp = matches; matchp; matchp = matchp->next) {
+				if (matchp->completed ||
+				    matchp->match->parse == NULL)
 					continue;
-				}
+				if (c < matchp->match->option_offset ||
+				    c >= matchp->match->option_offset + XT_OPTION_OFFSET_SCALE)
+					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 ip6tables-restore!]
+			 * - the protocol extension can be successively
+			 *   loaded
+			 */
+			if (m == NULL
+			    && protocol
+			    && (!find_proto(protocol, XTF_DONT_LOAD,
+					   options&OPT_NUMERIC, NULL)
+				|| (find_proto(protocol, XTF_DONT_LOAD,
+						options&OPT_NUMERIC, NULL)
+				    && (proto_used == 0))
+			       )
+			    && (m = find_proto(protocol, XTF_TRY_LOAD,
+					       options&OPT_NUMERIC, &matches))) {
+				/* Try loading protocol */
+				size_t size;
+
+				proto_used = 1;
+
+				size = IP6T_ALIGN(sizeof(struct ip6t_entry_match))
+						 + m->size;
 
-				if (!m) {
-					if (c == '?') {
-						if (optopt) {
-							xtables_error(
-							   PARAMETER_PROBLEM,
-							   "option `%s' "
-							   "requires an "
-							   "argument",
-							   argv[optind-1]);
-						} else {
-							xtables_error(
-							   PARAMETER_PROBLEM,
-							   "unknown option "
-							   "`%s'",
-							   argv[optind-1]);
-						}
+				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);
+
+				opts = xtables_merge_options(ip6tables_globals.orig_opts, opts,
+				    m->extra_opts, &m->option_offset);
+
+				optind--;
+				continue;
+			}
+
+			if (!m) {
+				if (c == '?') {
+					if (optopt) {
+						xtables_error(
+						   PARAMETER_PROBLEM,
+						   "option `%s' "
+						   "requires an "
+						   "argument",
+						   argv[optind-1]);
+					} else {
+						xtables_error(
+						   PARAMETER_PROBLEM,
+						   "unknown option "
+						   "`%s'",
+						   argv[optind-1]);
 					}
-					xtables_error(PARAMETER_PROBLEM,
-						   "Unknown arg `%s'", optarg);
 				}
+				xtables_error(PARAMETER_PROBLEM,
+					   "Unknown arg `%s'", optarg);
 			}
 		}
 		invert = FALSE;
iptables.c +98 -98

207 lines not on this page · raw message

Signature · 1 line
1.7.1
#2 lore raw

PATCH 2/8 iptables: reduce indentation of parse loop (2/3)

In reply to Jan Engelhardt

The stop flag is temporary (see next patch). By using such early break, less clauses can be removed.

---
 ip6tables.c |   50 ++++++++++++++++++++++++++------------------------
 iptables.c  |   49 ++++++++++++++++++++++++++-----------------------
 2 files changed, 52 insertions(+), 47 deletions(-)
ip6tables.c +26 -24
index d453868..f581509 100644
@@ -1702,7 +1702,9 @@ int do_command6(int argc, char *argv[], char **table, struct ip6tc_handle **hand
 			fprintf(stderr, "Bad argument `%s'\n", optarg);
 			exit_tryhelp(2);
 
-		default:
+		default: {
+			bool stop = false;
+
 			if (target != NULL && target->parse != NULL &&
 			    c >= target->option_offset &&
 			    c < target->option_offset + XT_OPTION_OFFSET_SCALE &&
@@ -1722,10 +1724,13 @@ int do_command6(int argc, char *argv[], char **table, struct ip6tc_handle **hand
 					     argv, invert,
 					     &matchp->match->mflags,
 					     &fw,
-					     &matchp->match->m))
+					     &matchp->match->m)) {
+					stop = true;
 					break;
+				}
 			}
-			m = matchp ? matchp->match : NULL;
+			if (stop)
+				break;
 
 			/* If you listen carefully, you can
 			   actually hear this code suck. */
@@ -1750,8 +1755,7 @@ int do_command6(int argc, char *argv[], char **table, struct ip6tc_handle **hand
 			 * - the protocol extension can be successively
 			 *   loaded
 			 */
-			if (m == NULL
-			    && protocol
+			if (protocol != NULL
 			    && (!find_proto(protocol, XTF_DONT_LOAD,
 					   options&OPT_NUMERIC, NULL)
 				|| (find_proto(protocol, XTF_DONT_LOAD,
@@ -1781,27 +1785,25 @@ int do_command6(int argc, char *argv[], char **table, struct ip6tc_handle **hand
 				optind--;
 				continue;
 			}
-
-			if (!m) {
-				if (c == '?') {
-					if (optopt) {
-						xtables_error(
-						   PARAMETER_PROBLEM,
-						   "option `%s' "
-						   "requires an "
-						   "argument",
-						   argv[optind-1]);
-					} else {
-						xtables_error(
-						   PARAMETER_PROBLEM,
-						   "unknown option "
-						   "`%s'",
-						   argv[optind-1]);
-					}
+			if (c == '?') {
+				if (optopt) {
+					xtables_error(
+					   PARAMETER_PROBLEM,
+					   "option `%s' "
+					   "requires an "
+					   "argument",
+					   argv[optind-1]);
+				} else {
+					xtables_error(
+					   PARAMETER_PROBLEM,
+					   "unknown option "
+					   "`%s'",
+					   argv[optind-1]);
 				}
-				xtables_error(PARAMETER_PROBLEM,
-					   "Unknown arg `%s'", optarg);
 			}
+			xtables_error(PARAMETER_PROBLEM,
+				   "Unknown arg `%s'", optarg);
+		} /* default */
 		}
 		invert = FALSE;
 	}
iptables.c +26 -23

77 lines not on this page · raw message

Signature · 1 line
1.7.1
#3 lore raw

PATCH 3/8 iptables: use variable as shortcut in parse loop

In reply to Jan Engelhardt

"m" is around, so use it, cut the code.

---
 ip6tables.c |   17 ++++++++---------
 iptables.c  |   17 ++++++++---------
 2 files changed, 16 insertions(+), 18 deletions(-)
ip6tables.c +8 -9
index f581509..caee730 100644
@@ -1714,17 +1714,16 @@ int do_command6(int argc, char *argv[], char **table, struct ip6tc_handle **hand
 					       &fw, &target->t))
 				break;
 			for (matchp = matches; matchp; matchp = matchp->next) {
-				if (matchp->completed ||
-				    matchp->match->parse == NULL)
+				m = matchp->match;
+
+				if (matchp->completed || m->parse == NULL)
 					continue;
-				if (c < matchp->match->option_offset ||
-				    c >= matchp->match->option_offset + XT_OPTION_OFFSET_SCALE)
+				if (c < m->option_offset ||
+				    c >= m->option_offset + XT_OPTION_OFFSET_SCALE)
 					continue;
-				if (matchp->match->parse(c - matchp->match->option_offset,
-					     argv, invert,
-					     &matchp->match->mflags,
-					     &fw,
-					     &matchp->match->m)) {
+				if (m->parse(c - matchp->match->option_offset,
+					     argv, invert, &m->mflags, &fw,
+					     &m->m)) {
 					stop = true;
 					break;
 				}
iptables.c +8 -9
index b957e66..db8e136 100644
@@ -1746,17 +1746,16 @@ int do_command(int argc, char *argv[], char **table, struct iptc_handle **handle
 					       &fw, &target->t))
 				break;
 			for (matchp = matches; matchp; matchp = matchp->next) {
-				if (matchp->completed ||
-				    matchp->match->parse == NULL)
+				m = matchp->match;
+
+				if (matchp->completed || m->parse == NULL)
 					continue;
-				if (c < matchp->match->option_offset ||
-				    c >= matchp->match->option_offset + XT_OPTION_OFFSET_SCALE)
+				if (c < m->option_offset ||
+				    c >= m->option_offset + XT_OPTION_OFFSET_SCALE)
 					continue;
-				if (matchp->match->parse(c - matchp->match->option_offset,
-					     argv, invert,
-					     &matchp->match->mflags,
-					     &fw,
-					     &matchp->match->m)) {
+				if (m->parse(c - matchp->match->option_offset,
+					     argv, invert, &m->mflags, &fw,
+					     &m->m)) {
 					stop = true;
 					break;
 				}
Signature · 1 line
1.7.1
#4 lore raw

PATCH 4/8 iptables: reduce indentation of parse loop (3/3)

In reply to Jan Engelhardt

Put the default case into its own function. Essentially, 5 levels of indentation have been stripped, and this is surely a result that looks a lot better than it did before.

---
 ip6tables.c |  190 ++++++++++++++++++++++++++-------------------------------
 iptables.c  |  196 ++++++++++++++++++++++++++--------------------------------
 2 files changed, 176 insertions(+), 210 deletions(-)
ip6tables.c +88 -102
index caee730..fb3b320 100644
@@ -1288,6 +1288,88 @@ static void clear_rule_matches(struct xtables_rule_match **matches)
 	*matches = NULL;
 }
 
+static void
+command_default(int c, char **argv, bool invert, struct ip6t_entry *fw,
+		const char *protocol, bool *proto_used, unsigned int options,
+		struct xtables_target *target,
+		struct xtables_rule_match **matches)
+{
+	struct xtables_rule_match *matchp;
+	struct xtables_match *m;
+
+	if (target != NULL && target->parse != NULL &&
+	    c >= target->option_offset &&
+	    c < target->option_offset + XT_OPTION_OFFSET_SCALE)
+		if (target->parse(c - target->option_offset, argv, invert,
+		    &target->tflags, fw, &target->t))
+			return;
+
+	for (matchp = *matches; matchp != NULL; matchp = matchp->next) {
+		m = matchp->match;
+
+		if (matchp->completed || m->parse == NULL)
+			continue;
+		if (c < m->option_offset ||
+		    c >= m->option_offset + XT_OPTION_OFFSET_SCALE)
+			continue;
+		if (m->parse(c - matchp->match->option_offset,
+		    argv, invert, &matchp->match->mflags, fw,
+		    &matchp->match->m))
+			return;
+	}
+
+	/*
+	 * 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 != NULL &&
+	    (!find_proto(protocol, XTF_DONT_LOAD, options & OPT_NUMERIC, NULL) ||
+	     (find_proto(protocol, XTF_DONT_LOAD, options & OPT_NUMERIC, NULL) && !*proto_used)) &&
+	    (m = find_proto(protocol, XTF_TRY_LOAD, options & OPT_NUMERIC, matches))) {
+		/* Try loading protocol */
+		size_t size;
+
+		*proto_used = true;
+		size = IP6T_ALIGN(sizeof(struct ip6t_entry_match)) + m->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);
+
+		opts = xtables_merge_options(ip6tables_globals.orig_opts, opts,
+					     m->extra_opts, &m->option_offset);
+		if (opts == NULL)
+			xtables_error(OTHER_PROBLEM, "can't alloc memory!");
+		optind--;
+		return;
+	}
+	if (c == '?') {
+		if (optopt)
+			xtables_error(PARAMETER_PROBLEM, "option \"%s\" "
+			              "requires an argument", argv[optind-1]);
+		else
+			xtables_error(PARAMETER_PROBLEM, "unknown option "
+				      "\"%s\"", optarg);
+	}
+	xtables_error(PARAMETER_PROBLEM, "Unknown arg \"%s\"", argv[optind-1]);
+}
+
 int do_command6(int argc, char *argv[], char **table, struct ip6tc_handle **handle)
 {
 	struct ip6t_entry fw, *e = NULL;
@@ -1310,7 +1392,7 @@ int do_command6(int argc, char *argv[], char **table, struct ip6tc_handle **hand
 	struct xtables_target *t;
 	const char *jumpto = "";
 	char *protocol = NULL;
-	int proto_used = 0;
+	bool proto_used = false;
 	unsigned long long cnt;
 
 	memset(&fw, 0, sizeof(fw));
@@ -1702,107 +1784,11 @@ int do_command6(int argc, char *argv[], char **table, struct ip6tc_handle **hand
 			fprintf(stderr, "Bad argument `%s'\n", optarg);
 			exit_tryhelp(2);
 
-		default: {
-			bool stop = false;
-
-			if (target != NULL && target->parse != NULL &&
-			    c >= target->option_offset &&
-			    c < target->option_offset + XT_OPTION_OFFSET_SCALE &&
-			    target->parse(c - target->option_offset,
-					       argv, invert,
-					       &target->tflags,
-					       &fw, &target->t))
-				break;
-			for (matchp = matches; matchp; matchp = matchp->next) {
-				m = matchp->match;
-
-				if (matchp->completed || m->parse == NULL)
-					continue;
-				if (c < m->option_offset ||
-				    c >= m->option_offset + XT_OPTION_OFFSET_SCALE)
-					continue;
-				if (m->parse(c - matchp->match->option_offset,
-					     argv, invert, &m->mflags, &fw,
-					     &m->m)) {
-					stop = true;
-					break;
-				}
-			}
-			if (stop)
-				break;
-
-			/* 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 ip6tables-restore!]
-			 * - the protocol extension can be successively
-			 *   loaded
-			 */
-			if (protocol != NULL
-			    && (!find_proto(protocol, XTF_DONT_LOAD,
-					   options&OPT_NUMERIC, NULL)
-				|| (find_proto(protocol, XTF_DONT_LOAD,
-						options&OPT_NUMERIC, NULL)
-				    && (proto_used == 0))
-			       )
-			    && (m = find_proto(protocol, XTF_TRY_LOAD,
-					       options&OPT_NUMERIC, &matches))) {
-				/* Try loading protocol */
-				size_t size;
-
-				proto_used = 1;
-
-				size = IP6T_ALIGN(sizeof(struct ip6t_entry_match))
-						 + m->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);
-
-				opts = xtables_merge_options(ip6tables_globals.orig_opts, opts,
-				    m->extra_opts, &m->option_offset);
-
-				optind--;
-				continue;
-			}
-			if (c == '?') {
-				if (optopt) {
-					xtables_error(
-					   PARAMETER_PROBLEM,
-					   "option `%s' "
-					   "requires an "
-					   "argument",
-					   argv[optind-1]);
-				} else {
-					xtables_error(
-					   PARAMETER_PROBLEM,
-					   "unknown option "
-					   "`%s'",
-					   argv[optind-1]);
-				}
-			}
-			xtables_error(PARAMETER_PROBLEM,
-				   "Unknown arg `%s'", optarg);
-		} /* default */
+		default:
+			command_default(c, argv, invert, &fw, protocol,
+					&proto_used, options,
+					target, &matches);
+			break;
 		}
 		invert = FALSE;
 	}
iptables.c +88 -108

214 lines not on this page · raw message

Signature · 1 line
1.7.1
#5 lore raw

PATCH 5/8 iptables: fix error message for unknown options

In reply to Jan Engelhardt

-From: iptables v1.4.10: option "-q" requires an argument
+To: iptables v1.4.10: unknown option "-q"

---
 ip6tables.c |   16 +++++++---------
 iptables.c  |   16 +++++++---------
 2 files changed, 14 insertions(+), 18 deletions(-)
ip6tables.c +7 -9
index fb3b320..8cacf61 100644
@@ -1359,14 +1359,12 @@ command_default(int c, char **argv, bool invert, struct ip6t_entry *fw,
 		optind--;
 		return;
 	}
-	if (c == '?') {
-		if (optopt)
-			xtables_error(PARAMETER_PROBLEM, "option \"%s\" "
-			              "requires an argument", argv[optind-1]);
-		else
-			xtables_error(PARAMETER_PROBLEM, "unknown option "
-				      "\"%s\"", optarg);
-	}
+	if (c == ':')
+		xtables_error(PARAMETER_PROBLEM, "option \"%s\" "
+		              "requires an argument", argv[optind-1]);
+	if (c == '?')
+		xtables_error(PARAMETER_PROBLEM, "unknown option "
+			      "\"%s\"", argv[optind-1]);
 	xtables_error(PARAMETER_PROBLEM, "Unknown arg \"%s\"", argv[optind-1]);
 }
 
@@ -1417,7 +1415,7 @@ int do_command6(int argc, char *argv[], char **table, struct ip6tc_handle **hand
 
 	opts = xt_params->orig_opts;
 	while ((c = getopt_long(argc, argv,
-	   "-A:D:R:I:L::S::M:F::Z::N:X::E:P:Vh::o:p:s:d:j:i:bvnt:m:xc:g:",
+	   "-:A:D:R:I:L::S::M:F::Z::N:X::E:P:Vh::o:p:s:d:j:i:bvnt:m:xc:g:",
 					   opts, NULL)) != -1) {
 		switch (c) {
 			/*
iptables.c +7 -9
index 9977634..504bcd8 100644
@@ -1382,14 +1382,12 @@ command_default(int c, char **argv, bool invert, struct ipt_entry *fw,
 		optind--;
 		return;
 	}
-	if (c == '?') {
-		if (optopt)
-			xtables_error(PARAMETER_PROBLEM, "option \"%s\" "
-			              "requires an argument", argv[optind-1]);
-		else
-			xtables_error(PARAMETER_PROBLEM, "unknown option "
-				      "\"%s\"", argv[optind-1]);
-	}
+	if (c == ':')
+		xtables_error(PARAMETER_PROBLEM, "option \"%s\" "
+		              "requires an argument", argv[optind-1]);
+	if (c == '?')
+		xtables_error(PARAMETER_PROBLEM, "unknown option "
+			      "\"%s\"", argv[optind-1]);
 	xtables_error(PARAMETER_PROBLEM, "Unknown arg \"%s\"", optarg);
 }
 
@@ -1440,7 +1438,7 @@ int do_command(int argc, char *argv[], char **table, struct iptc_handle **handle
 
 	opts = xt_params->orig_opts;
 	while ((c = getopt_long(argc, argv,
-	   "-A:D:R:I:L::S::M:F::Z::N:X::E:P:Vh::o:p:s:d:j:i:fbvnt:m:xc:g:",
+	   "-:A:D:R:I:L::S::M:F::Z::N:X::E:P:Vh::o:p:s:d:j:i:fbvnt:m:xc:g:",
 					   opts, NULL)) != -1) {
 		switch (c) {
 			/*
Signature · 1 line
1.7.1
#6 lore raw

PATCH 6/8 build: directly use config.h in internal.h

In reply to Jan Engelhardt

This avoids the extra indirection via the .h.in file.

---
 .gitignore                     |    1 -
 Makefile.am                    |    3 +--
 configure.ac                   |    2 +-
 include/iptables/internal.h    |   15 +++++++++++++++
 include/iptables/internal.h.in |   13 -------------
 5 files changed, 17 insertions(+), 17 deletions(-)
 create mode 100644 include/iptables/internal.h
 delete mode 100644 include/iptables/internal.h.in
.gitignore +0 -1
index e5d3099..7d0df25 100644
@@ -18,7 +18,6 @@ Makefile.in
 /extensions/targets?.man
 
 /include/xtables.h
-/include/iptables/internal.h
 
 /aclocal.m4
 /autom4te*.cache
Makefile.am +1 -2
index 7f0eb2f..cfccbf2 100644
@@ -89,8 +89,7 @@ tarball:
 	tar -C /tmp -cjf ${PACKAGE_TARNAME}-${PACKAGE_VERSION}.tar.bz2 --owner=root --group=root ${PACKAGE_TARNAME}-${PACKAGE_VERSION}/;
 	rm -Rf /tmp/${PACKAGE_TARNAME}-${PACKAGE_VERSION};
 
-config.status: extensions/GNUmakefile.in \
-	include/xtables.h.in include/iptables/internal.h.in
+config.status: extensions/GNUmakefile.in include/xtables.h.in
 
 # Using if..fi avoids an ugly "error (ignored)" message :)
 install-exec-hook:
configure.ac +1 -1
index eb447e0..94d5ab2 100644
@@ -111,5 +111,5 @@ AC_SUBST([libxtables_vmajor])
 
 AC_CONFIG_FILES([Makefile extensions/GNUmakefile include/Makefile
 	libipq/Makefile utils/Makefile
-	include/xtables.h include/iptables/internal.h libiptc.pc xtables.pc])
+	include/xtables.h libiptc.pc xtables.pc])
 AC_OUTPUT
include/iptables/internal.h new file +15 -0
new file mode 100644
index 0000000..531fe4f
@@ -0,0 +1,15 @@
+#ifndef IPTABLES_INTERNAL_H
+#define IPTABLES_INTERNAL_H 1
+
+#include "config.h"
+
+#define IPTABLES_VERSION PACKAGE_VERSION
+
+/**
+ * Program's own name and version.
+ */
+extern const char *program_name, *program_version;
+
+extern int line;
+
+#endif /* IPTABLES_INTERNAL_H */
include/iptables/internal.h.in deleted +0 -13
deleted file mode 100644
index 8568e58..0000000
@@ -1,13 +0,0 @@
-#ifndef IPTABLES_INTERNAL_H
-#define IPTABLES_INTERNAL_H 1
-
-#define IPTABLES_VERSION "@PACKAGE_VERSION@"
-
-/**
- * Program's own name and version.
- */
-extern const char *program_name, *program_version;
-
-extern int line;
-
-#endif /* IPTABLES_INTERNAL_H */
Signature · 1 line
1.7.1
#7 lore raw

PATCH 7/8 libxtables: symbol visibility

In reply to Jan Engelhardt
---
 Makefile.am                 |    4 +-
 configure.ac                |    2 +
 extensions/GNUmakefile.in   |    2 +-
 include/iptables/internal.h |    6 ++
 iptables.c                  |    2 +-
 m4/gcc4_visibility.m4       |   21 ++++++++
 xtables.c                   |  109 ++++++++++++++++++++++++-------------------
 7 files changed, 94 insertions(+), 52 deletions(-)
 create mode 100644 m4/gcc4_visibility.m4
Makefile.am +2 -2
index cfccbf2..a560113 100644
@@ -29,11 +29,11 @@ libiptc_libip6tc_la_LDFLAGS = -version-info 0:0:0 ${libiptc_LDFLAGS2}
 lib_LTLIBRARIES      += libxtables.la
 libxtables_la_SOURCES = xtables.c
 libxtables_la_LDFLAGS = -version-info ${libxtables_vcurrent}:0:${libxtables_vage}
+libxtables_la_CFLAGS  = ${AM_CFLAGS} ${GCC_FVISIBILITY_HIDDEN}
 if ENABLE_SHARED
-libxtables_la_CFLAGS  = ${AM_CFLAGS}
 libxtables_la_LIBADD  = -ldl
 else
-libxtables_la_CFLAGS  = ${AM_CFLAGS} -DNO_SHARED_LIBS=1
+libxtables_la_CFLAGS += -DNO_SHARED_LIBS=1
 libxtables_la_LIBADD  =
 endif
 
configure.ac +2 -0
index 94d5ab2..cba1dc5 100644
@@ -14,6 +14,8 @@ AM_PROG_CC_C_O
 AC_DISABLE_STATIC
 AM_PROG_LIBTOOL
 
+CHECK_GCC_FVISIBILITY
+
 AC_ARG_WITH([kernel],
 	AS_HELP_STRING([--with-kernel=PATH],
 	[Path to kernel source/build directory]),
extensions/GNUmakefile.in +1 -1
index 74a058c..899a52d 100644
@@ -18,7 +18,7 @@ LDFLAGS        := @LDFLAGS@
 regular_CFLAGS := @regular_CFLAGS@
 kinclude_CFLAGS := @kinclude_CFLAGS@
 
-AM_CFLAGS      := ${regular_CFLAGS} -I${top_builddir}/include -I${top_srcdir}/include ${kinclude_CFLAGS}
+AM_CFLAGS      := ${regular_CFLAGS} -I${top_builddir}/include -I${top_srcdir}/include ${kinclude_CFLAGS} -I${top_builddir}
 AM_DEPFLAGS     = -Wp,-MMD,$(@D)/.$(@F).d,-MT,$@
 
 ifeq (${V},)
include/iptables/internal.h +6 -0
index 531fe4f..89d11cb 100644
@@ -3,6 +3,12 @@
 
 #include "config.h"
 
+#ifdef HAVE_VISIBILITY_HIDDEN
+#	define EXPORT_SYMBOL __attribute__((visibility("default")))
+#else
+#	define EXPORT_SYMBOL
+#endif
+
 #define IPTABLES_VERSION PACKAGE_VERSION
 
 /**
iptables.c +1 -1
index 504bcd8..1bc9d84 100644
@@ -200,7 +200,7 @@ static const int inverse_for_options[NUMBER_OF_OPT] =
 #define prog_name iptables_globals.program_name
 #define prog_vers iptables_globals.program_version
 
-int kernel_version;
+EXPORT_SYMBOL int kernel_version;
 
 /* Primitive headers... */
 /* defined in netinet/in.h */
m4/gcc4_visibility.m4 new file +21 -0
new file mode 100644
index 0000000..84959f3
@@ -0,0 +1,21 @@
+
+# GCC 4.x -fvisibility=hidden
+
+AC_DEFUN([CHECK_GCC_FVISIBILITY], [
+	AC_LANG_PUSH([C])
+	saved_CFLAGS="$CFLAGS"
+	CFLAGS="$saved_CFLAGS -fvisibility=hidden"
+	AC_CACHE_CHECK([whether compiler accepts -fvisibility=hidden],
+	  [ac_cv_fvisibility_hidden], AC_COMPILE_IFELSE(
+		AC_LANG_PROGRAM([], []),
+		[ac_cv_fvisibility_hidden=yes],
+		[ac_cv_fvisibility_hidden=no]
+	))
+	if test "$ac_cv_fvisibility_hidden" = "yes"; then
+		AC_DEFINE([HAVE_VISIBILITY_HIDDEN], [1],
+		  [True if compiler supports -fvisibility=hidden])
+		AC_SUBST([GCC_FVISIBILITY_HIDDEN], [-fvisibility=hidden])
+	fi
+	CFLAGS="$saved_CFLAGS"
+	AC_LANG_POP([C])
+])
xtables.c +61 -48

337 lines not on this page · raw message

Signature · 1 line
1.7.1
#8 lore raw

Re: [PATCH 7/8] libxtables: symbol visibility

xtables.c void basic_exit_err(enum xtables_exittype status, const char *msg, ...) · line 77

Quoted 2 lines · Jan Engelhardt
xtables.c +1 -1
-void xtables_free_opts(int unused)
+EXPORT_SYMBOL void xtables_free_opts(int unused)

This is pretty ugly in my opinion. Please do something like this:

#define EXPORT_SYMBOL(x) typeof(x) (x)
__attribute__((visibility("default")))

so you can use EXPORT_SYMBOL as in the kernel.

#9 lore raw

Re: [PATCH 7/8] libxtables: symbol visibility

Quoted 10 lines · Patrick McHardy

xtables.c void basic_exit_err(enum xtables_exittype status, const char *msg, ...) · line 77

Quoted 2 lines · Jan Engelhardt
xtables.c +1 -1
-void xtables_free_opts(int unused)
+EXPORT_SYMBOL void xtables_free_opts(int unused)

This is pretty ugly in my opinion. Please do something like this:

#define EXPORT_SYMBOL(x) typeof(x) (x)
__attribute__((visibility("default")))

so you can use EXPORT_SYMBOL as in the kernel.

But that is redundancy nonplusultra. The reason why EXPORT_SYMBOL is a separate statement is because it is much more than just a function attribute inside the kernel.

#10 lore raw

Re: [PATCH 7/8] libxtables: symbol visibility

Quoted 8 lines · Jan Engelhardt
Quoted 6 lines · Patrick McHardy

xtables.c void basic_exit_err(enum xtables_exittype status, const char *msg, ...) · line 77

Quoted 2 lines · Jan Engelhardt
xtables.c +1 -1
-void xtables_free_opts(int unused)
+EXPORT_SYMBOL void xtables_free_opts(int unused)

This is pretty ugly in my opinion. Please do something like this:

Quoted 6 lines
Quoted 4 lines

#define EXPORT_SYMBOL(x) typeof(x) (x)
__attribute__((visibility("default")))

so you can use EXPORT_SYMBOL as in the kernel.

But that is redundancy nonplusultra.

Who cares? Its a lot nicer to look at and people are used to using it this way. In fact Pablo just changed libmnl to the same style.

Quoted 3 lines

The reason why EXPORT_SYMBOL is a
separate statement is because it is much more than just a function attribute inside the kernel.

That might be one reason.

#11 lore raw

PATCH 8/8 libxtables: symbol versioning

In reply to Jan Engelhardt
---
 Makefile.am    |    2 +-
 configure.ac   |    2 +-
 libxtables.map |   55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 57 insertions(+), 2 deletions(-)
 create mode 100644 libxtables.map
Makefile.am +1 -1
index a560113..4406435 100644
@@ -28,7 +28,7 @@ libiptc_libip6tc_la_LDFLAGS = -version-info 0:0:0 ${libiptc_LDFLAGS2}
 
 lib_LTLIBRARIES      += libxtables.la
 libxtables_la_SOURCES = xtables.c
-libxtables_la_LDFLAGS = -version-info ${libxtables_vcurrent}:0:${libxtables_vage}
+libxtables_la_LDFLAGS = -version-info ${libxtables_vcurrent}:0:${libxtables_vage} -Wl,--version-script=${srcdir}/libxtables.map
 libxtables_la_CFLAGS  = ${AM_CFLAGS} ${GCC_FVISIBILITY_HIDDEN}
 if ENABLE_SHARED
 libxtables_la_LIBADD  = -ldl
configure.ac +1 -1
index cba1dc5..ec44c3a 100644
@@ -2,7 +2,7 @@
 AC_INIT([iptables], [1.4.10])
 
 # See libtool.info "Libtool's versioning system"
-libxtables_vcurrent=5
+libxtables_vcurrent=6
 libxtables_vage=0
 
 AC_CONFIG_HEADERS([config.h])
libxtables.map new file +55 -0

55 lines not on this page · raw message

Signature · 1 line
1.7.1