diff options
author | Bruce Momjian | 2003-06-24 22:21:24 +0000 |
---|---|---|
committer | Bruce Momjian | 2003-06-24 22:21:24 +0000 |
commit | 945543d919ced497e3fc8165b11142ddc014b9cb (patch) | |
tree | 78b5bc6d56d9d8b85040aa9a45bec4d8c2adaa70 /doc/src | |
parent | 4dab978c52700b6323919876463ae23c5d7ddf9f (diff) |
Add ipv6 address parsing support to 'inet' and 'cidr' data types.
Regression tests for IPv6 operations added.
Documentation updated to document IPv6 bits.
Stop treating IPv4 as an "unsigned int" and IPv6 as an array of
characters. Instead, always use the array of characters so we
can have one function fits all. This makes bitncmp(), addressOK(),
and several other functions "just work" on both address families.
add family() function which returns integer 4 or 6 for IPv4 or
IPv6. (See examples below) Note that to add this new function
you will need to dump/initdb/reload or find the correct magic
to add the function to the postgresql function catalogs.
IPv4 addresses always sort before IPv6.
On disk we use AF_INET for IPv4, and AF_INET+1 for IPv6 addresses.
This prevents the need for a dump and reload, but lets IPv6 parsing
work on machines without AF_INET6.
To select all IPv4 addresses from a table:
select * from foo where family(addr) = 4 ...
Order by and other bits should all work.
Michael Graff
Diffstat (limited to 'doc/src')
-rw-r--r-- | doc/src/sgml/datatype.sgml | 80 |
1 files changed, 56 insertions, 24 deletions
diff --git a/doc/src/sgml/datatype.sgml b/doc/src/sgml/datatype.sgml index 05faaa422f3..32dcfc72a5d 100644 --- a/doc/src/sgml/datatype.sgml +++ b/doc/src/sgml/datatype.sgml @@ -1,5 +1,5 @@ <!-- -$Header: /cvsroot/pgsql/doc/src/sgml/datatype.sgml,v 1.117 2003/06/17 23:12:36 tgl Exp $ +$Header: /cvsroot/pgsql/doc/src/sgml/datatype.sgml,v 1.118 2003/06/24 22:21:21 momjian Exp $ --> <chapter id="datatype"> @@ -100,7 +100,7 @@ $Header: /cvsroot/pgsql/doc/src/sgml/datatype.sgml,v 1.117 2003/06/17 23:12:36 t <row> <entry><type>cidr</type></entry> <entry></entry> - <entry>IP network address</entry> + <entry>IPv4 or IPv6 network address</entry> </row> <row> @@ -124,7 +124,7 @@ $Header: /cvsroot/pgsql/doc/src/sgml/datatype.sgml,v 1.117 2003/06/17 23:12:36 t <row> <entry><type>inet</type></entry> <entry></entry> - <entry>IP host address</entry> + <entry>IPv4 or IPv6 host address</entry> </row> <row> @@ -2425,7 +2425,7 @@ SELECT * FROM test1 WHERE a; </indexterm> <para> - <productname>PostgreSQL</> offers data types to store IP and MAC + <productname>PostgreSQL</> offers data types to store IPv4, IPv6, and MAC addresses, shown in <xref linkend="datatype-net-types-table">. It is preferable to use these types over plain text types, because these types offer input error checking and several specialized @@ -2446,14 +2446,14 @@ SELECT * FROM test1 WHERE a; <row> <entry><type>cidr</type></entry> - <entry>12 bytes</entry> - <entry>IPv4 networks</entry> + <entry>12 or 24 bytes</entry> + <entry>IPv4 or IPv6 networks</entry> </row> <row> <entry><type>inet</type></entry> - <entry>12 bytes</entry> - <entry>IPv4 hosts and networks</entry> + <entry>12 or 24 bytes</entry> + <entry>IPv4 and IPv6 hosts and networks</entry> </row> <row> @@ -2467,7 +2467,10 @@ SELECT * FROM test1 WHERE a; </table> <para> - IPv6 is not yet supported. + When sorting <type>inet</type> or <type>cidr</type> data types, + IPv4 addresses will always sort before IPv6 addresses, including + IPv4 addresses encapsulated or mapped into IPv6 addresses, such as + ::10.2.3.4 or ::ffff::10.4.3.2. </para> @@ -2479,26 +2482,32 @@ SELECT * FROM test1 WHERE a; </indexterm> <para> - The <type>inet</type> type holds an IP host address, and + The <type>inet</type> type holds an IPv4 or IPv6 host address, and optionally the identity of the subnet it is in, all in one field. The subnet identity is represented by stating how many bits of the host address represent the network address (the - <quote>netmask</quote>). If the netmask is 32, then the value - does not indicate a subnet, only a single host. Note that if you + <quote>netmask</quote>). If the netmask is 32 and the address is IPv4, + then the value does not indicate a subnet, only a single host. + In IPv6, the address length is 128 bits, so 128 bits will specify a + unique host address. Note that if you want to accept networks only, you should use the <type>cidr</type> type rather than <type>inet</type>. </para> <para> - The input format for this type is <replaceable - class="parameter">x.x.x.x/y</replaceable> where <replaceable - class="parameter">x.x.x.x</replaceable> is an IP address and - <replaceable class="parameter">y</replaceable> is the number of - bits in the netmask. If the <replaceable - class="parameter">/y</replaceable> part is left off, then the - netmask is 32, and the value represents just a single host. - On display, the <replaceable class="parameter">/y</replaceable> - portion is suppressed if the netmask is 32. + The input format for this type is + <replaceable class="parameter">address/y</replaceable> + where + <replaceable class="parameter">address</replaceable> + is an IPv4 or IPv6 address and + <replaceable class="parameter">y</replaceable> + is the number of bits in the netmask. If the + <replaceable class="parameter">/y</replaceable> + part is left off, then the + netmask is 32 for IPv4 and 128 for IPv6, and the value represents + just a single host. On display, the + <replaceable class="parameter">/y</replaceable> + portion is suppressed if the netmask specifies a single host. </para> </sect2> @@ -2510,12 +2519,13 @@ SELECT * FROM test1 WHERE a; </indexterm> <para> - The <type>cidr</type> type holds an IP network specification. + The <type>cidr</type> type holds an IPv4 or IPv6 network specification. Input and output formats follow Classless Internet Domain Routing conventions. The format for specifying networks is <replaceable - class="parameter">x.x.x.x/y</> where <replaceable - class="parameter">x.x.x.x</> is the network and <replaceable + class="parameter">address/y</> where <replaceable + class="parameter">address</> is the network represented as an + IPv4 or IPv6 address, and <replaceable class="parameter">y</> is the number of bits in the netmask. If <replaceable class="parameter">y</> is omitted, it is calculated using assumptions from the older classful network numbering system, except @@ -2594,6 +2604,28 @@ SELECT * FROM test1 WHERE a; <entry>10.0.0.0/8</entry> <entry>10/8</entry> </row> + <row> + <entry>10.1.2.3/32</entry> + <entry>10.1.2.3/32</entry> + <entry>10.1.2.3/32</entry> + <row> + <entry>2001:4f8:3:ba::/64</entry> + <entry>2001:4f8:3:ba::/64</entry> + <entry>2001:4f8:3:ba::/64</entry> + </row> + <row> + <entry>2001:4f8:3:ba:2e0:81ff:fe22:d1f1/128</entry> + <entry>2001:4f8:3:ba:2e0:81ff:fe22:d1f1/128</entry> + <entry>2001:4f8:3:ba:2e0:81ff:fe22:d1f1</entry> + </row> + <row> + <entry>::ffff:1.2.3.0/120</entry> + <entry>::ffff:1.2.3.0/120</entry> + <entry>::ffff:1.2.3/120</entry> + <row> + <entry>::ffff:1.2.3.0/128</entry> + <entry>::ffff:1.2.3.0/128</entry> + <entry>::ffff:1.2.3.0/128</entry> </tbody> </tgroup> </table> |