Skip to contentSkip to conversation

Two more patches related to mountd IPv6 support

PATCH In review Chuck Lever 2 participants 4 messages May 7, 2010 – May 24, 2010 1 message not in the archive

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

cover Two more patches related to mountd IPv6 support

Steve-

Here are two more minor clean-up patches for IPv6 support in mountd. The second patch defines the format in which IPv6 address are stored in rmtab. Since IPv6 addresses are new to this file, I hope there are no backward-compatibility concerns about this change, but please let me know if there might be a problem.

---

Chuck Lever (2):
mountd: Convert colons in IPv6 presentation addresses to semicolons libexport.a: Refactor rmtab_read()

 support/export/rmtab.c |   64 +++++++++++++++++++++++++++++++-----------------
 support/nfs/rmtab.c    |   42 +++++++++++++++++++++++++++++---
 2 files changed, 80 insertions(+), 26 deletions(-)
Signature · 1 line
Chuck Lever

A message that is not in the archive (sent off-list or not yet received): 20100507174128.4221.36914.stgit-bi+AKbBUZKY6gyzm1THtWbp2dZbC/[email protected]

#2 lore raw

PATCH 1/2 libexport.a: Refactor rmtab_read()

Clean up: Make it easier to add IPv6 support by refactoring part of rmtab_read() into a helper function.

---

 support/export/rmtab.c |   64 +++++++++++++++++++++++++++++++-----------------
 1 files changed, 41 insertions(+), 23 deletions(-)
support/export/rmtab.c +41 -23
index b49e1aa..0ec495c 100644
@@ -19,39 +19,57 @@
 #include "xio.h"
 #include "xlog.h"
 
+/*
+ * See if the entry already exists.  If not,
+ * this was an instantiated wild card, and we
+ * must add it.
+ */
+static void
+rmtab_read_wildcard(struct rmtabent *rep)
+{
+	nfs_export *exp, *exp2;
+	struct hostent *hp;
+
+	hp = gethostbyname(rep->r_client);
+	if (hp == NULL)
+		return;
+	hp = hostent_dup(hp);
+	if (hp == NULL)
+		return;
+
+	exp = export_allowed(hp, rep->r_path);
+	free(hp);
+	if (exp == NULL)
+		return;
+
+	exp2 = export_lookup(rep->r_client, exp->m_export.e_path, 0);
+	if (exp2 == NULL) {
+		struct exportent ee;
+
+		memset(&ee, 0, sizeof(ee));
+		dupexportent(&ee, &exp->m_export);
+
+		ee.e_hostname = rep->r_client;
+		exp2 = export_create(&ee, 0);
+		exp2->m_changed = exp->m_changed;
+	}
+	exp2->m_mayexport = 1;
+}
+
 int
 rmtab_read(void)
 {
 	struct rmtabent		*rep;
-	nfs_export		*exp = NULL;
 
 	setrmtabent("r");
 	while ((rep = getrmtabent(1, NULL)) != NULL) {
-		struct hostent		*hp = NULL;
 		int			htype;
-		
+
 		htype = client_gettype(rep->r_client);
-		if ((htype == MCL_FQDN || htype == MCL_SUBNETWORK)
-		    && (hp = gethostbyname (rep->r_client))
-		    && (hp = hostent_dup (hp),
-			exp = export_allowed (hp, rep->r_path))) {
-			/* see if the entry already exists, otherwise this was an instantiated
-			 * wild card, and we must add it
-			 */
-			nfs_export *exp2 = export_lookup(rep->r_client,
-							exp->m_export.e_path, 0);
-			if (!exp2) {
-				struct exportent ee;
-				dupexportent(&ee, &exp->m_export);
-				ee.e_hostname = rep->r_client;
-				exp2 = export_create(&ee, 0);
-				exp2->m_changed = exp->m_changed;
-			}
-			free (hp);
-			exp2->m_mayexport = 1;
-		} else if (hp) /* export_allowed failed */
-			free(hp);
+		if (htype == MCL_FQDN || htype == MCL_SUBNETWORK)
+			rmtab_read_wildcard(rep);
 	}
+
 	if (errno == EINVAL) {
 		/* Something goes wrong. We need to fix the rmtab
 		   file. */
#3 lore raw

PATCH 2/2 mountd: Convert colons in IPv6 presentation addresses to semicolons

In reply to a message not in the archive

The /var/lib/nfs/rmtab file delineates fields in each of its lines with a ":". The first field contains the IP address of a client, in presentation format. IPv6 presentation format addresses contain colons, which screws up the field delineation of rmtab.

Use a simple simple scheme to convert the colons in incoming client names to some other character, and then convert them back when the rmtab file is read.

---

 support/nfs/rmtab.c |   42 +++++++++++++++++++++++++++++++++++++++---
 1 files changed, 39 insertions(+), 3 deletions(-)
support/nfs/rmtab.c +39 -3
index a28abf3..ca789a3 100644
@@ -19,6 +19,18 @@
 #include <signal.h>
 #include "nfslib.h"
 
+/*
+ * Colons in incoming IPv6 presentation addresses have to
+ * replaced with another character, since rmtab already
+ * uses colons to delineate fields.
+ *
+ * Use a printable character, but one that would never be
+ * found in a presentation address or domain name
+ */
+#define IPV6_COLON	';'
+
+#define LINELEN		(2048)
+
 static FILE	*rmfp = NULL;
 
 int
@@ -56,7 +68,8 @@ struct rmtabent *
 fgetrmtabent(FILE *fp, int log, long *pos)
 {
 	static struct rmtabent	re;
-	char	buf[2048], *count, *host, *path;
+	char		*count, *host, *path, *c;
+	static char	buf[LINELEN];
 
 	errno = 0;
 	if (!fp)
@@ -84,10 +97,16 @@ fgetrmtabent(FILE *fp, int log, long *pos)
 		else
 			re.r_count = 1;
 	} while (0);
+
 	strncpy(re.r_client, host, sizeof (re.r_client) - 1);
 	re.r_client[sizeof (re.r_client) - 1] = '\0';
+	for (c = re.r_client; *c != '\0'; c++)
+		if (*c == IPV6_COLON)
+			*c = ':';
+
 	strncpy(re.r_path, path, sizeof (re.r_path) - 1);
 	re.r_path[sizeof (re.r_path) - 1] = '\0';
+
 	return &re;
 }
 
@@ -100,10 +119,27 @@ putrmtabent(struct rmtabent *rep, long *pos)
 void
 fputrmtabent(FILE *fp, struct rmtabent *rep, long *pos)
 {
+	static char	buf[LINELEN];
+	char		*c;
+
 	if (!fp || (pos && fseek (fp, *pos, SEEK_SET) != 0))
 		return;
-	fprintf(fp, "%s:%s:0x%.8x\n", rep->r_client, rep->r_path,
-		rep->r_count);
+
+	/*
+	 * To avoid confusing the token parser in fgetrmtabent(),
+	 * convert colons in incoming IPv6 presentation addresses
+	 * to semicolons.
+	 */
+	if (strlen(rep->r_client) > sizeof(buf)) {
+		xlog(L_ERROR, "client name too large");
+		return;
+	}
+	strncpy(buf, rep->r_client, sizeof(buf));
+	for (c = buf; *c != '\0'; c++)
+		if (*c == ':')
+			*c = IPV6_COLON;
+
+	(void)fprintf(fp, "%s:%s:0x%.8x\n", buf, rep->r_path, rep->r_count);
 }
 
 void
#4 lore raw
In reply to a message not in the archive
Quoted 10 lines · Chuck Lever

Steve-

Here are two more minor clean-up patches for IPv6 support in mountd. The second patch defines the format in which IPv6 address are stored in rmtab. Since IPv6 addresses are new to this file, I hope there are no backward-compatibility concerns about this change, but please let me know if there might be a problem.

---

Quoted 9 lines

Chuck Lever (2):
mountd: Convert colons in IPv6 presentation addresses to semicolons libexport.a: Refactor rmtab_read()

 support/export/rmtab.c |   64 +++++++++++++++++++++++++++++++-----------------
 support/nfs/rmtab.c    |   42 +++++++++++++++++++++++++++++---
 2 files changed, 80 insertions(+), 26 deletions(-)

Committed...

steved.