All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2/2] Accept named realm
@ 2006-05-21 16:13 Simon Lodal
  2006-05-24 16:06 ` Patrick McHardy
  0 siblings, 1 reply; 3+ messages in thread
From: Simon Lodal @ 2006-05-21 16:13 UTC (permalink / raw)
  To: Netfilter Developer

[-- Attachment #1: Type: text/plain, Size: 79 bytes --]


Make the realm match accept named realms, defined in /etc/iproute2/rt_realms.

[-- Attachment #2: realm_named.diff --]
[-- Type: text/x-diff, Size: 3247 bytes --]

diff -ruN iptables-1.3.5.mod1/extensions/libipt_realm.c iptables-1.3.5.mod2/extensions/libipt_realm.c
--- iptables-1.3.5.mod1/extensions/libipt_realm.c	2006-05-21 17:50:24.000000000 +0200
+++ iptables-1.3.5.mod2/extensions/libipt_realm.c	2006-05-21 17:51:19.000000000 +0200
@@ -3,6 +3,7 @@
 #include <netdb.h>
 #include <string.h>
 #include <stdlib.h>
+#include <errno.h>
 #include <getopt.h>
 #if defined(__GLIBC__) && __GLIBC__ == 2
 #include <net/ethernet.h>
@@ -28,6 +29,46 @@
 	{0}
 };
 
+/* Lookup realm in /etc/iproute2/rt_realms. Return: True and realm id in *rid
+ * if found, false and *rid not touched if not found.
+ */
+static int
+find_named_realm(const char* rnm, u_int32_t* rid)
+{
+	const char* rfnm = "/etc/iproute2/rt_realms";
+	char buf[512];
+	FILE *fil;
+	char *cur, *nxt;
+	unsigned long int id;
+	int	len = strlen(rnm);
+
+	fil = fopen(rfnm, "r");
+	if (!fil) return 0;
+
+	while (fgets(buf, sizeof(buf), fil)) {
+		cur = buf;
+		while ((*cur == ' ') || (*cur == '\t')) cur++;
+		if ((*cur == '#') || (*cur == '\n')) continue;
+
+		id = strtoul(cur, &nxt, 0);
+		if ((nxt == cur) || errno) continue;
+		cur = nxt;
+
+		while ((*cur == ' ') || (*cur == '\t')) cur++;
+		if (strncmp(cur, rnm, len)) continue;
+		nxt = cur + len;
+		while ((*nxt == ' ') || (*nxt == '\t')) nxt++;
+		if ((*nxt == '\n') || (*nxt == 0) || (*nxt == '#')) {
+			*rid = (u_int32_t)id;
+			fclose(fil);
+			return 1;
+		}
+	}
+
+	fclose(fil);
+	return 0;
+}
+
 /* Function which parses command options; returns true if it
    ate an option */
 static int
@@ -42,14 +83,23 @@
 		char *end;
 	case '1':
 		check_inverse(argv[optind-1], &invert, &optind, 0);
-		optarg = argv[optind-1];
+		end = optarg = argv[optind-1];
 		realminfo->id = strtoul(optarg, &end, 0);
-		if (*end == '/') {
-			realminfo->mask = strtoul(end+1, &end, 0);
-		} else
-			realminfo->mask = 0xffffffff;
-		if (*end != '\0' || end == optarg)
-			exit_error(PARAMETER_PROBLEM, "Bad realm value `%s'", optarg);
+		if ((end != optarg) && (('/' == *end) || ('\0' == *end))) {
+			if (*end == '/') {
+				realminfo->mask = strtoul(end+1, &end, 0);
+			} else
+				realminfo->mask = 0xffffffff;
+			if (*end != '\0' || end == optarg)
+				exit_error(PARAMETER_PROBLEM,
+					   "Bad realm value `%s'", optarg);
+		} else {
+			if (find_named_realm(optarg, &realminfo->id))
+				realminfo->mask = 0xffffffff;
+			else
+				exit_error(PARAMETER_PROBLEM,
+					   "Realm `%s' not found", optarg);
+		}
 		if (invert)
 			realminfo->invert = 1;
 		*flags = 1;
diff -ruN iptables-1.3.5.mod1/extensions/libipt_realm.man iptables-1.3.5.mod2/extensions/libipt_realm.man
--- iptables-1.3.5.mod1/extensions/libipt_realm.man	2004-10-10 11:56:27.000000000 +0200
+++ iptables-1.3.5.mod2/extensions/libipt_realm.man	2006-05-21 17:51:17.000000000 +0200
@@ -1,5 +1,7 @@
 This matches the routing realm.  Routing realms are used in complex routing
 setups involving dynamic routing protocols like BGP.
 .TP
-.BI "--realm " "[!]" "value[/mask]"
-Matches a given realm number (and optionally mask).
+.BI "--realm " "[!] " "value[/mask]"
+Matches a given realm number (and optionally mask). If not a number, value
+can be a named realm from /etc/iproute2/rt_realms (mask can not be used in
+that case).

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 2/2] Accept named realm
  2006-05-21 16:13 [PATCH 2/2] Accept named realm Simon Lodal
@ 2006-05-24 16:06 ` Patrick McHardy
  2006-05-24 17:35   ` Simon Lodal
  0 siblings, 1 reply; 3+ messages in thread
From: Patrick McHardy @ 2006-05-24 16:06 UTC (permalink / raw)
  To: Simon Lodal; +Cc: Netfilter Developer

Simon Lodal wrote:
> Make the realm match accept named realms, defined in /etc/iproute2/rt_realms.

I think this is a good idea, but it should also show realm names when
listing without -n. For that it makes little sense to read in the
realms file once for each rule shown, so you should keep a map of
realm->name values. I actually had a patch to do exactly that long
ago, but I lost it.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 2/2] Accept named realm
  2006-05-24 16:06 ` Patrick McHardy
@ 2006-05-24 17:35   ` Simon Lodal
  0 siblings, 0 replies; 3+ messages in thread
From: Simon Lodal @ 2006-05-24 17:35 UTC (permalink / raw)
  To: Patrick McHardy; +Cc: Netfilter Developer

On Wednesday 24 May 2006 18:06, Patrick McHardy wrote:
> Simon Lodal wrote:
> > Make the realm match accept named realms, defined in
> > /etc/iproute2/rt_realms.
>
> I think this is a good idea, but it should also show realm names when
> listing without -n. For that it makes little sense to read in the
> realms file once for each rule shown, so you should keep a map of
> realm->name values. I actually had a patch to do exactly that long
> ago, but I lost it.

Same thought, I will post another patch soon.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2006-05-24 17:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-05-21 16:13 [PATCH 2/2] Accept named realm Simon Lodal
2006-05-24 16:06 ` Patrick McHardy
2006-05-24 17:35   ` Simon Lodal

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.