aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/network.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2007-05-17 23:31:59 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2007-05-17 23:31:59 +0000
commit2f6d85101b6720edef691e854216a266966c44ba (patch)
tree9c7be9b8caaed6e09356cb1e697790452a0e0da5 /src/backend/utils/adt/network.c
parentd42e2b75027c4ea4c8140d7734a6e751ec155b6c (diff)
downloadpostgresql-2f6d85101b6720edef691e854216a266966c44ba.tar.gz
postgresql-2f6d85101b6720edef691e854216a266966c44ba.zip
Temporary fix for the problem that pg_stat_activity, inet_client_addr(),
and inet_server_addr() fail if the client connected over a "scoped" IPv6 address. In this case getnameinfo() will return a string ending with a poorly-standardized "%something" zone specifier, which these functions try to feed to network_in(), which won't take it. So that we don't lose functionality altogether, suppress the zone specifier before giving the string to network_in(). Per report from Brian Hirt. TODO: probably someday the inet type should support scoped IPv6 addresses, and then this patch should be reverted. Backpatch to 8.2 ... is it worth going further?
Diffstat (limited to 'src/backend/utils/adt/network.c')
-rw-r--r--src/backend/utils/adt/network.c35
1 files changed, 34 insertions, 1 deletions
diff --git a/src/backend/utils/adt/network.c b/src/backend/utils/adt/network.c
index bd7406bc2b5..bb9210e16d2 100644
--- a/src/backend/utils/adt/network.c
+++ b/src/backend/utils/adt/network.c
@@ -1,7 +1,7 @@
/*
* PostgreSQL type definitions for the INET and CIDR types.
*
- * $PostgreSQL: pgsql/src/backend/utils/adt/network.c,v 1.66 2006/10/04 00:29:59 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/network.c,v 1.66.2.1 2007/05/17 23:31:59 tgl Exp $
*
* Jon Postel RIP 16 Oct 1998
*/
@@ -1138,6 +1138,8 @@ inet_client_addr(PG_FUNCTION_ARGS)
if (ret)
PG_RETURN_NULL();
+ clean_ipv6_addr(port->raddr.addr.ss_family, remote_host);
+
PG_RETURN_INET_P(network_in(remote_host, false));
}
@@ -1212,6 +1214,8 @@ inet_server_addr(PG_FUNCTION_ARGS)
if (ret)
PG_RETURN_NULL();
+ clean_ipv6_addr(port->laddr.addr.ss_family, local_host);
+
PG_RETURN_INET_P(network_in(local_host, false));
}
@@ -1483,3 +1487,32 @@ inetmi(PG_FUNCTION_ARGS)
PG_RETURN_INT64(res);
}
+
+
+/*
+ * clean_ipv6_addr --- remove any '%zone' part from an IPv6 address string
+ *
+ * XXX This should go away someday!
+ *
+ * This is a kluge needed because we don't yet support zones in stored inet
+ * values. Since the result of getnameinfo() might include a zone spec,
+ * call this to remove it anywhere we want to feed getnameinfo's output to
+ * network_in. Beats failing entirely.
+ *
+ * An alternative approach would be to let network_in ignore %-parts for
+ * itself, but that would mean we'd silently drop zone specs in user input,
+ * which seems not such a good idea.
+ */
+void
+clean_ipv6_addr(int addr_family, char *addr)
+{
+#ifdef HAVE_IPV6
+ if (addr_family == AF_INET6)
+ {
+ char *pct = strchr(addr, '%');
+
+ if (pct)
+ *pct = '\0';
+ }
+#endif
+}