netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jan Engelhardt <jengelh@medozas.de>
To: kaber@trash.net
Cc: netfilter-devel@vger.kernel.org
Subject: [PATCH 2/7] iptables: improve error reporting with extension loading troubles
Date: Mon, 31 Jan 2011 03:12:47 +0100	[thread overview]
Message-ID: <1296439973-16089-3-git-send-email-jengelh@medozas.de> (raw)
In-Reply-To: <1296439973-16089-1-git-send-email-jengelh@medozas.de>

ip6tables v1.4.8: Could not load match "osf":
/usr/lib/xtables/libip6t_osf.so: cannot open shared object file: No
such file or directory

Given that libxt_osf.so exists, a better error is now emitted.

References: http://bugzilla.netfilter.org/show_bug.cgi?id=637
Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
---
 xtables.c |   55 ++++++++++++++++++++++++++++---------------------------
 1 files changed, 28 insertions(+), 27 deletions(-)

diff --git a/xtables.c b/xtables.c
index eec1733..0036299 100644
--- a/xtables.c
+++ b/xtables.c
@@ -492,9 +492,11 @@ void xtables_parse_interface(const char *arg, char *vianame,
 }
 
 #ifndef NO_SHARED_LIBS
-static void *load_extension(const char *search_path, const char *prefix,
+static void *load_extension(const char *search_path, const char *af_prefix,
     const char *name, bool is_target)
 {
+	const char *all_prefixes[] = {"libxt_", af_prefix, NULL};
+	const char **prefix;
 	const char *dir = search_path, *next;
 	void *ptr = NULL;
 	struct stat sb;
@@ -504,39 +506,38 @@ static void *load_extension(const char *search_path, const char *prefix,
 		next = strchr(dir, ':');
 		if (next == NULL)
 			next = dir + strlen(dir);
-		snprintf(path, sizeof(path), "%.*s/libxt_%s.so",
-		         (unsigned int)(next - dir), dir, name);
 
-		if (dlopen(path, RTLD_NOW) != NULL) {
-			/* Found library.  If it didn't register itself,
-			   maybe they specified target as match. */
-			if (is_target)
-				ptr = xtables_find_target(name, XTF_DONT_LOAD);
-			else
-				ptr = xtables_find_match(name,
-				      XTF_DONT_LOAD, NULL);
-		} else if (stat(path, &sb) == 0) {
-			fprintf(stderr, "%s: %s\n", path, dlerror());
-		}
+		for (prefix = all_prefixes; *prefix != NULL; ++prefix) {
+			snprintf(path, sizeof(path), "%.*s/%s%s.so",
+			         (unsigned int)(next - dir), dir,
+			         *prefix, name);
 
-		if (ptr != NULL)
-			return ptr;
+			if (stat(path, &sb) != 0) {
+				if (errno == ENOENT)
+					continue;
+				fprintf(stderr, "%s: %s\n", path,
+					strerror(errno));
+				return NULL;
+			}
+			if (dlopen(path, RTLD_NOW) == NULL) {
+				fprintf(stderr, "%s: %s\n", path, dlerror());
+				break;
+			}
 
-		snprintf(path, sizeof(path), "%.*s/%s%s.so",
-		         (unsigned int)(next - dir), dir, prefix, name);
-		if (dlopen(path, RTLD_NOW) != NULL) {
 			if (is_target)
 				ptr = xtables_find_target(name, XTF_DONT_LOAD);
 			else
 				ptr = xtables_find_match(name,
 				      XTF_DONT_LOAD, NULL);
-		} else if (stat(path, &sb) == 0) {
-			fprintf(stderr, "%s: %s\n", path, dlerror());
-		}
 
-		if (ptr != NULL)
-			return ptr;
+			if (ptr != NULL)
+				return ptr;
 
+			fprintf(stderr, "%s: no \"%s\" extension found for "
+				"this protocol\n", path, name);
+			errno = ENOENT;
+			return NULL;
+		}
 		dir = next + 1;
 	} while (*next != '\0');
 
@@ -591,7 +592,7 @@ xtables_find_match(const char *name, enum xtables_tryload tryload,
 		if (ptr == NULL && tryload == XTF_LOAD_MUST_SUCCEED)
 			xt_params->exit_err(PARAMETER_PROBLEM,
 				   "Couldn't load match `%s':%s\n",
-				   name, dlerror());
+				   name, strerror(errno));
 	}
 #else
 	if (ptr && !ptr->loaded) {
@@ -651,7 +652,7 @@ xtables_find_target(const char *name, enum xtables_tryload tryload)
 		if (ptr == NULL && tryload == XTF_LOAD_MUST_SUCCEED)
 			xt_params->exit_err(PARAMETER_PROBLEM,
 				   "Couldn't load target `%s':%s\n",
-				   name, dlerror());
+				   name, strerror(errno));
 	}
 #else
 	if (ptr && !ptr->loaded) {
-- 
1.7.1


  parent reply	other threads:[~2011-01-31  2:12 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-31  2:12 iptables: misc fixes Jan Engelhardt
2011-01-31  2:12 ` [PATCH 1/7] libxt_quota: clarifications on matching Jan Engelhardt
2011-01-31  2:12 ` Jan Engelhardt [this message]
2011-01-31  2:12 ` [PATCH 3/7] libxt_u32: enclose argument in quotes Jan Engelhardt
2011-01-31  2:12 ` [PATCH 4/7] xtables: set custom opts to NULL on free Jan Engelhardt
2011-01-31  2:12 ` [PATCH 5/7] iptables: warn when parameter limit is exceeded Jan Engelhardt
2011-01-31  2:12 ` [PATCH 6/7] iptables: remove bogus address-of Jan Engelhardt
2011-01-31  2:12 ` [PATCH 7/7] iptables: remove more redundant casts Jan Engelhardt
2011-01-31  2:16 ` [PATCH 8/8] iptables: do not print trailing whitespaces Jan Engelhardt
2011-01-31 16:12 ` iptables: misc fixes Patrick McHardy

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=1296439973-16089-3-git-send-email-jengelh@medozas.de \
    --to=jengelh@medozas.de \
    --cc=kaber@trash.net \
    --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).