Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdbb7693

Browse files
committed
Temporary fix for the problem that pg_stat_activity, inet_client_addr(),
and inet_server_addr() fail if the client connected over a "scoped" IPv6address. In this case getnameinfo() will return a string ending witha poorly-standardized "%something" zone specifier, which these functionstry to feed to network_in(), which won't take it. So that we don't losefunctionality altogether, suppress the zone specifier before giving thestring 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?
1 parent3f186a2 commitdbb7693

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

‎src/backend/utils/adt/network.c

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
*PostgreSQL type definitions for the INET and CIDR types.
33
*
4-
*$PostgreSQL: pgsql/src/backend/utils/adt/network.c,v 1.69 2007/04/06 04:21:43 tgl Exp $
4+
*$PostgreSQL: pgsql/src/backend/utils/adt/network.c,v 1.70 2007/05/17 23:31:49 tgl Exp $
55
*
66
*Jon Postel RIP 16 Oct 1998
77
*/
@@ -1142,6 +1142,8 @@ inet_client_addr(PG_FUNCTION_ARGS)
11421142
if (ret)
11431143
PG_RETURN_NULL();
11441144

1145+
clean_ipv6_addr(port->raddr.addr.ss_family,remote_host);
1146+
11451147
PG_RETURN_INET_P(network_in(remote_host, false));
11461148
}
11471149

@@ -1216,6 +1218,8 @@ inet_server_addr(PG_FUNCTION_ARGS)
12161218
if (ret)
12171219
PG_RETURN_NULL();
12181220

1221+
clean_ipv6_addr(port->laddr.addr.ss_family,local_host);
1222+
12191223
PG_RETURN_INET_P(network_in(local_host, false));
12201224
}
12211225

@@ -1479,3 +1483,32 @@ inetmi(PG_FUNCTION_ARGS)
14791483

14801484
PG_RETURN_INT64(res);
14811485
}
1486+
1487+
1488+
/*
1489+
* clean_ipv6_addr --- remove any '%zone' part from an IPv6 address string
1490+
*
1491+
* XXX This should go away someday!
1492+
*
1493+
* This is a kluge needed because we don't yet support zones in stored inet
1494+
* values. Since the result of getnameinfo() might include a zone spec,
1495+
* call this to remove it anywhere we want to feed getnameinfo's output to
1496+
* network_in. Beats failing entirely.
1497+
*
1498+
* An alternative approach would be to let network_in ignore %-parts for
1499+
* itself, but that would mean we'd silently drop zone specs in user input,
1500+
* which seems not such a good idea.
1501+
*/
1502+
void
1503+
clean_ipv6_addr(intaddr_family,char*addr)
1504+
{
1505+
#ifdefHAVE_IPV6
1506+
if (addr_family==AF_INET6)
1507+
{
1508+
char*pct=strchr(addr,'%');
1509+
1510+
if (pct)
1511+
*pct='\0';
1512+
}
1513+
#endif
1514+
}

‎src/backend/utils/adt/pgstatfuncs.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/pgstatfuncs.c,v 1.41 2007/03/30 18:34:55 mha Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/pgstatfuncs.c,v 1.42 2007/05/17 23:31:49 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -550,6 +550,8 @@ pg_stat_get_backend_client_addr(PG_FUNCTION_ARGS)
550550
if (ret)
551551
PG_RETURN_NULL();
552552

553+
clean_ipv6_addr(beentry->st_clientaddr.addr.ss_family,remote_host);
554+
553555
PG_RETURN_INET_P(DirectFunctionCall1(inet_in,
554556
CStringGetDatum(remote_host)));
555557
}

‎src/include/utils/builtins.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/utils/builtins.h,v 1.292 2007/05/08 18:56:48 neilc Exp $
10+
* $PostgreSQL: pgsql/src/include/utils/builtins.h,v 1.293 2007/05/17 23:31:49 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -797,6 +797,7 @@ extern Datum inetor(PG_FUNCTION_ARGS);
797797
externDatuminetpl(PG_FUNCTION_ARGS);
798798
externDatuminetmi_int8(PG_FUNCTION_ARGS);
799799
externDatuminetmi(PG_FUNCTION_ARGS);
800+
externvoidclean_ipv6_addr(intaddr_family,char*addr);
800801

801802
/* mac.c */
802803
externDatummacaddr_in(PG_FUNCTION_ARGS);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp