mirror of
https://github.com/postgres/postgres.git
synced 2025-12-12 02:37:31 +03:00
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
This commit is contained in:
@@ -19,110 +19,132 @@ INSERT INTO INET_TBL (c, i) VALUES ('10.1', '10.1.2.3/16');
|
||||
INSERT INTO INET_TBL (c, i) VALUES ('10', '10.1.2.3/8');
|
||||
INSERT INTO INET_TBL (c, i) VALUES ('10', '11.1.2.3/8');
|
||||
INSERT INTO INET_TBL (c, i) VALUES ('10', '9.1.2.3/8');
|
||||
INSERT INTO INET_TBL (c, i) VALUES ('10:23::f1', '10:23::f1/64');
|
||||
INSERT INTO INET_TBL (c, i) VALUES ('10:23::8000/113', '10:23::ffff');
|
||||
INSERT INTO INET_TBL (c, i) VALUES ('::ffff:1.2.3.4', '::4.3.2.1/24');
|
||||
-- check that CIDR rejects invalid input:
|
||||
INSERT INTO INET_TBL (c, i) VALUES ('192.168.1.2/24', '192.168.1.226');
|
||||
ERROR: invalid CIDR value '192.168.1.2/24': has bits set to right of mask
|
||||
INSERT INTO INET_TBL (c, i) VALUES ('1234::1234::1234', '::1.2.3.4');
|
||||
ERROR: invalid CIDR value '1234::1234::1234'
|
||||
-- check that CIDR rejects invalid input when converting from text:
|
||||
INSERT INTO INET_TBL (c, i) VALUES (cidr('192.168.1.2/24'), '192.168.1.226');
|
||||
ERROR: invalid CIDR value '192.168.1.2/24': has bits set to right of mask
|
||||
INSERT INTO INET_TBL (c, i) VALUES (cidr('ffff:ffff:ffff:ffff::/24'), '::192.168.1.226');
|
||||
ERROR: invalid CIDR value 'ffff:ffff:ffff:ffff::/24': has bits set to right of mask
|
||||
SELECT '' AS ten, c AS cidr, i AS inet FROM INET_TBL;
|
||||
ten | cidr | inet
|
||||
-----+----------------+------------------
|
||||
| 192.168.1.0/24 | 192.168.1.226/24
|
||||
| 192.168.1.0/24 | 192.168.1.226
|
||||
| 192.168.1.0/24 | 192.168.1.0/24
|
||||
| 192.168.1.0/24 | 192.168.1.0/25
|
||||
| 192.168.1.0/24 | 192.168.1.255/24
|
||||
| 192.168.1.0/24 | 192.168.1.255/25
|
||||
| 10.0.0.0/8 | 10.1.2.3/8
|
||||
| 10.0.0.0/32 | 10.1.2.3/8
|
||||
| 10.1.2.3/32 | 10.1.2.3
|
||||
| 10.1.2.0/24 | 10.1.2.3/24
|
||||
| 10.1.0.0/16 | 10.1.2.3/16
|
||||
| 10.0.0.0/8 | 10.1.2.3/8
|
||||
| 10.0.0.0/8 | 11.1.2.3/8
|
||||
| 10.0.0.0/8 | 9.1.2.3/8
|
||||
(14 rows)
|
||||
ten | cidr | inet
|
||||
-----+--------------------+------------------
|
||||
| 192.168.1.0/24 | 192.168.1.226/24
|
||||
| 192.168.1.0/24 | 192.168.1.226
|
||||
| 192.168.1.0/24 | 192.168.1.0/24
|
||||
| 192.168.1.0/24 | 192.168.1.0/25
|
||||
| 192.168.1.0/24 | 192.168.1.255/24
|
||||
| 192.168.1.0/24 | 192.168.1.255/25
|
||||
| 10.0.0.0/8 | 10.1.2.3/8
|
||||
| 10.0.0.0/32 | 10.1.2.3/8
|
||||
| 10.1.2.3/32 | 10.1.2.3
|
||||
| 10.1.2.0/24 | 10.1.2.3/24
|
||||
| 10.1.0.0/16 | 10.1.2.3/16
|
||||
| 10.0.0.0/8 | 10.1.2.3/8
|
||||
| 10.0.0.0/8 | 11.1.2.3/8
|
||||
| 10.0.0.0/8 | 9.1.2.3/8
|
||||
| 10:23::f1/128 | 10:23::f1/64
|
||||
| 10:23::8000/113 | 10:23::ffff
|
||||
| ::ffff:1.2.3.4/128 | ::4.3.2.1/24
|
||||
(17 rows)
|
||||
|
||||
-- now test some support functions
|
||||
SELECT '' AS ten, i AS inet, host(i), text(i) FROM INET_TBL;
|
||||
ten | inet | host | text
|
||||
-----+------------------+---------------+------------------
|
||||
| 192.168.1.226/24 | 192.168.1.226 | 192.168.1.226/24
|
||||
| 192.168.1.226 | 192.168.1.226 | 192.168.1.226/32
|
||||
| 192.168.1.0/24 | 192.168.1.0 | 192.168.1.0/24
|
||||
| 192.168.1.0/25 | 192.168.1.0 | 192.168.1.0/25
|
||||
| 192.168.1.255/24 | 192.168.1.255 | 192.168.1.255/24
|
||||
| 192.168.1.255/25 | 192.168.1.255 | 192.168.1.255/25
|
||||
| 10.1.2.3/8 | 10.1.2.3 | 10.1.2.3/8
|
||||
| 10.1.2.3/8 | 10.1.2.3 | 10.1.2.3/8
|
||||
| 10.1.2.3 | 10.1.2.3 | 10.1.2.3/32
|
||||
| 10.1.2.3/24 | 10.1.2.3 | 10.1.2.3/24
|
||||
| 10.1.2.3/16 | 10.1.2.3 | 10.1.2.3/16
|
||||
| 10.1.2.3/8 | 10.1.2.3 | 10.1.2.3/8
|
||||
| 11.1.2.3/8 | 11.1.2.3 | 11.1.2.3/8
|
||||
| 9.1.2.3/8 | 9.1.2.3 | 9.1.2.3/8
|
||||
(14 rows)
|
||||
SELECT '' AS ten, i AS inet, host(i), text(i), family(i) FROM INET_TBL;
|
||||
ten | inet | host | text | family
|
||||
-----+------------------+---------------+------------------+--------
|
||||
| 192.168.1.226/24 | 192.168.1.226 | 192.168.1.226/24 | 4
|
||||
| 192.168.1.226 | 192.168.1.226 | 192.168.1.226/32 | 4
|
||||
| 192.168.1.0/24 | 192.168.1.0 | 192.168.1.0/24 | 4
|
||||
| 192.168.1.0/25 | 192.168.1.0 | 192.168.1.0/25 | 4
|
||||
| 192.168.1.255/24 | 192.168.1.255 | 192.168.1.255/24 | 4
|
||||
| 192.168.1.255/25 | 192.168.1.255 | 192.168.1.255/25 | 4
|
||||
| 10.1.2.3/8 | 10.1.2.3 | 10.1.2.3/8 | 4
|
||||
| 10.1.2.3/8 | 10.1.2.3 | 10.1.2.3/8 | 4
|
||||
| 10.1.2.3 | 10.1.2.3 | 10.1.2.3/32 | 4
|
||||
| 10.1.2.3/24 | 10.1.2.3 | 10.1.2.3/24 | 4
|
||||
| 10.1.2.3/16 | 10.1.2.3 | 10.1.2.3/16 | 4
|
||||
| 10.1.2.3/8 | 10.1.2.3 | 10.1.2.3/8 | 4
|
||||
| 11.1.2.3/8 | 11.1.2.3 | 11.1.2.3/8 | 4
|
||||
| 9.1.2.3/8 | 9.1.2.3 | 9.1.2.3/8 | 4
|
||||
| 10:23::f1/64 | 10:23::f1 | 10:23::f1/64 | 6
|
||||
| 10:23::ffff | 10:23::ffff | 10:23::ffff/128 | 6
|
||||
| ::4.3.2.1/24 | ::4.3.2.1 | ::4.3.2.1/24 | 6
|
||||
(17 rows)
|
||||
|
||||
SELECT '' AS ten, c AS cidr, broadcast(c),
|
||||
i AS inet, broadcast(i) FROM INET_TBL;
|
||||
ten | cidr | broadcast | inet | broadcast
|
||||
-----+----------------+------------------+------------------+------------------
|
||||
| 192.168.1.0/24 | 192.168.1.255/24 | 192.168.1.226/24 | 192.168.1.255/24
|
||||
| 192.168.1.0/24 | 192.168.1.255/24 | 192.168.1.226 | 192.168.1.226
|
||||
| 192.168.1.0/24 | 192.168.1.255/24 | 192.168.1.0/24 | 192.168.1.255/24
|
||||
| 192.168.1.0/24 | 192.168.1.255/24 | 192.168.1.0/25 | 192.168.1.127/25
|
||||
| 192.168.1.0/24 | 192.168.1.255/24 | 192.168.1.255/24 | 192.168.1.255/24
|
||||
| 192.168.1.0/24 | 192.168.1.255/24 | 192.168.1.255/25 | 192.168.1.255/25
|
||||
| 10.0.0.0/8 | 10.255.255.255/8 | 10.1.2.3/8 | 10.255.255.255/8
|
||||
| 10.0.0.0/32 | 10.0.0.0 | 10.1.2.3/8 | 10.255.255.255/8
|
||||
| 10.1.2.3/32 | 10.1.2.3 | 10.1.2.3 | 10.1.2.3
|
||||
| 10.1.2.0/24 | 10.1.2.255/24 | 10.1.2.3/24 | 10.1.2.255/24
|
||||
| 10.1.0.0/16 | 10.1.255.255/16 | 10.1.2.3/16 | 10.1.255.255/16
|
||||
| 10.0.0.0/8 | 10.255.255.255/8 | 10.1.2.3/8 | 10.255.255.255/8
|
||||
| 10.0.0.0/8 | 10.255.255.255/8 | 11.1.2.3/8 | 11.255.255.255/8
|
||||
| 10.0.0.0/8 | 10.255.255.255/8 | 9.1.2.3/8 | 9.255.255.255/8
|
||||
(14 rows)
|
||||
ten | cidr | broadcast | inet | broadcast
|
||||
-----+--------------------+------------------+------------------+---------------------------------------
|
||||
| 192.168.1.0/24 | 192.168.1.255/24 | 192.168.1.226/24 | 192.168.1.255/24
|
||||
| 192.168.1.0/24 | 192.168.1.255/24 | 192.168.1.226 | 192.168.1.226
|
||||
| 192.168.1.0/24 | 192.168.1.255/24 | 192.168.1.0/24 | 192.168.1.255/24
|
||||
| 192.168.1.0/24 | 192.168.1.255/24 | 192.168.1.0/25 | 192.168.1.127/25
|
||||
| 192.168.1.0/24 | 192.168.1.255/24 | 192.168.1.255/24 | 192.168.1.255/24
|
||||
| 192.168.1.0/24 | 192.168.1.255/24 | 192.168.1.255/25 | 192.168.1.255/25
|
||||
| 10.0.0.0/8 | 10.255.255.255/8 | 10.1.2.3/8 | 10.255.255.255/8
|
||||
| 10.0.0.0/32 | 10.0.0.0 | 10.1.2.3/8 | 10.255.255.255/8
|
||||
| 10.1.2.3/32 | 10.1.2.3 | 10.1.2.3 | 10.1.2.3
|
||||
| 10.1.2.0/24 | 10.1.2.255/24 | 10.1.2.3/24 | 10.1.2.255/24
|
||||
| 10.1.0.0/16 | 10.1.255.255/16 | 10.1.2.3/16 | 10.1.255.255/16
|
||||
| 10.0.0.0/8 | 10.255.255.255/8 | 10.1.2.3/8 | 10.255.255.255/8
|
||||
| 10.0.0.0/8 | 10.255.255.255/8 | 11.1.2.3/8 | 11.255.255.255/8
|
||||
| 10.0.0.0/8 | 10.255.255.255/8 | 9.1.2.3/8 | 9.255.255.255/8
|
||||
| 10:23::f1/128 | 10:23::f1 | 10:23::f1/64 | 10:23::ffff:ffff:ffff:ffff/64
|
||||
| 10:23::8000/113 | 10:23::ffff/113 | 10:23::ffff | 10:23::ffff
|
||||
| ::ffff:1.2.3.4/128 | ::ffff:1.2.3.4 | ::4.3.2.1/24 | 0:ff:ffff:ffff:ffff:ffff:ffff:ffff/24
|
||||
(17 rows)
|
||||
|
||||
SELECT '' AS ten, c AS cidr, network(c) AS "network(cidr)",
|
||||
i AS inet, network(i) AS "network(inet)" FROM INET_TBL;
|
||||
ten | cidr | network(cidr) | inet | network(inet)
|
||||
-----+----------------+----------------+------------------+------------------
|
||||
| 192.168.1.0/24 | 192.168.1.0/24 | 192.168.1.226/24 | 192.168.1.0/24
|
||||
| 192.168.1.0/24 | 192.168.1.0/24 | 192.168.1.226 | 192.168.1.226/32
|
||||
| 192.168.1.0/24 | 192.168.1.0/24 | 192.168.1.0/24 | 192.168.1.0/24
|
||||
| 192.168.1.0/24 | 192.168.1.0/24 | 192.168.1.0/25 | 192.168.1.0/25
|
||||
| 192.168.1.0/24 | 192.168.1.0/24 | 192.168.1.255/24 | 192.168.1.0/24
|
||||
| 192.168.1.0/24 | 192.168.1.0/24 | 192.168.1.255/25 | 192.168.1.128/25
|
||||
| 10.0.0.0/8 | 10.0.0.0/8 | 10.1.2.3/8 | 10.0.0.0/8
|
||||
| 10.0.0.0/32 | 10.0.0.0/32 | 10.1.2.3/8 | 10.0.0.0/8
|
||||
| 10.1.2.3/32 | 10.1.2.3/32 | 10.1.2.3 | 10.1.2.3/32
|
||||
| 10.1.2.0/24 | 10.1.2.0/24 | 10.1.2.3/24 | 10.1.2.0/24
|
||||
| 10.1.0.0/16 | 10.1.0.0/16 | 10.1.2.3/16 | 10.1.0.0/16
|
||||
| 10.0.0.0/8 | 10.0.0.0/8 | 10.1.2.3/8 | 10.0.0.0/8
|
||||
| 10.0.0.0/8 | 10.0.0.0/8 | 11.1.2.3/8 | 11.0.0.0/8
|
||||
| 10.0.0.0/8 | 10.0.0.0/8 | 9.1.2.3/8 | 9.0.0.0/8
|
||||
(14 rows)
|
||||
ten | cidr | network(cidr) | inet | network(inet)
|
||||
-----+--------------------+--------------------+------------------+------------------
|
||||
| 192.168.1.0/24 | 192.168.1.0/24 | 192.168.1.226/24 | 192.168.1.0/24
|
||||
| 192.168.1.0/24 | 192.168.1.0/24 | 192.168.1.226 | 192.168.1.226/32
|
||||
| 192.168.1.0/24 | 192.168.1.0/24 | 192.168.1.0/24 | 192.168.1.0/24
|
||||
| 192.168.1.0/24 | 192.168.1.0/24 | 192.168.1.0/25 | 192.168.1.0/25
|
||||
| 192.168.1.0/24 | 192.168.1.0/24 | 192.168.1.255/24 | 192.168.1.0/24
|
||||
| 192.168.1.0/24 | 192.168.1.0/24 | 192.168.1.255/25 | 192.168.1.128/25
|
||||
| 10.0.0.0/8 | 10.0.0.0/8 | 10.1.2.3/8 | 10.0.0.0/8
|
||||
| 10.0.0.0/32 | 10.0.0.0/32 | 10.1.2.3/8 | 10.0.0.0/8
|
||||
| 10.1.2.3/32 | 10.1.2.3/32 | 10.1.2.3 | 10.1.2.3/32
|
||||
| 10.1.2.0/24 | 10.1.2.0/24 | 10.1.2.3/24 | 10.1.2.0/24
|
||||
| 10.1.0.0/16 | 10.1.0.0/16 | 10.1.2.3/16 | 10.1.0.0/16
|
||||
| 10.0.0.0/8 | 10.0.0.0/8 | 10.1.2.3/8 | 10.0.0.0/8
|
||||
| 10.0.0.0/8 | 10.0.0.0/8 | 11.1.2.3/8 | 11.0.0.0/8
|
||||
| 10.0.0.0/8 | 10.0.0.0/8 | 9.1.2.3/8 | 9.0.0.0/8
|
||||
| 10:23::f1/128 | 10:23::f1/128 | 10:23::f1/64 | 10:23::/64
|
||||
| 10:23::8000/113 | 10:23::8000/113 | 10:23::ffff | 10:23::ffff/128
|
||||
| ::ffff:1.2.3.4/128 | ::ffff:1.2.3.4/128 | ::4.3.2.1/24 | ::/24
|
||||
(17 rows)
|
||||
|
||||
SELECT '' AS ten, c AS cidr, masklen(c) AS "masklen(cidr)",
|
||||
i AS inet, masklen(i) AS "masklen(inet)" FROM INET_TBL;
|
||||
ten | cidr | masklen(cidr) | inet | masklen(inet)
|
||||
-----+----------------+---------------+------------------+---------------
|
||||
| 192.168.1.0/24 | 24 | 192.168.1.226/24 | 24
|
||||
| 192.168.1.0/24 | 24 | 192.168.1.226 | 32
|
||||
| 192.168.1.0/24 | 24 | 192.168.1.0/24 | 24
|
||||
| 192.168.1.0/24 | 24 | 192.168.1.0/25 | 25
|
||||
| 192.168.1.0/24 | 24 | 192.168.1.255/24 | 24
|
||||
| 192.168.1.0/24 | 24 | 192.168.1.255/25 | 25
|
||||
| 10.0.0.0/8 | 8 | 10.1.2.3/8 | 8
|
||||
| 10.0.0.0/32 | 32 | 10.1.2.3/8 | 8
|
||||
| 10.1.2.3/32 | 32 | 10.1.2.3 | 32
|
||||
| 10.1.2.0/24 | 24 | 10.1.2.3/24 | 24
|
||||
| 10.1.0.0/16 | 16 | 10.1.2.3/16 | 16
|
||||
| 10.0.0.0/8 | 8 | 10.1.2.3/8 | 8
|
||||
| 10.0.0.0/8 | 8 | 11.1.2.3/8 | 8
|
||||
| 10.0.0.0/8 | 8 | 9.1.2.3/8 | 8
|
||||
(14 rows)
|
||||
ten | cidr | masklen(cidr) | inet | masklen(inet)
|
||||
-----+--------------------+---------------+------------------+---------------
|
||||
| 192.168.1.0/24 | 24 | 192.168.1.226/24 | 24
|
||||
| 192.168.1.0/24 | 24 | 192.168.1.226 | 32
|
||||
| 192.168.1.0/24 | 24 | 192.168.1.0/24 | 24
|
||||
| 192.168.1.0/24 | 24 | 192.168.1.0/25 | 25
|
||||
| 192.168.1.0/24 | 24 | 192.168.1.255/24 | 24
|
||||
| 192.168.1.0/24 | 24 | 192.168.1.255/25 | 25
|
||||
| 10.0.0.0/8 | 8 | 10.1.2.3/8 | 8
|
||||
| 10.0.0.0/32 | 32 | 10.1.2.3/8 | 8
|
||||
| 10.1.2.3/32 | 32 | 10.1.2.3 | 32
|
||||
| 10.1.2.0/24 | 24 | 10.1.2.3/24 | 24
|
||||
| 10.1.0.0/16 | 16 | 10.1.2.3/16 | 16
|
||||
| 10.0.0.0/8 | 8 | 10.1.2.3/8 | 8
|
||||
| 10.0.0.0/8 | 8 | 11.1.2.3/8 | 8
|
||||
| 10.0.0.0/8 | 8 | 9.1.2.3/8 | 8
|
||||
| 10:23::f1/128 | 128 | 10:23::f1/64 | 64
|
||||
| 10:23::8000/113 | 113 | 10:23::ffff | 128
|
||||
| ::ffff:1.2.3.4/128 | 128 | ::4.3.2.1/24 | 24
|
||||
(17 rows)
|
||||
|
||||
SELECT '' AS four, c AS cidr, masklen(c) AS "masklen(cidr)",
|
||||
i AS inet, masklen(i) AS "masklen(inet)" FROM INET_TBL
|
||||
@@ -149,23 +171,26 @@ SELECT '' AS ten, i, c,
|
||||
i << c AS sb, i <<= c AS sbe,
|
||||
i >> c AS sup, i >>= c AS spe
|
||||
FROM INET_TBL;
|
||||
ten | i | c | lt | le | eq | ge | gt | ne | sb | sbe | sup | spe
|
||||
-----+------------------+----------------+----+----+----+----+----+----+----+-----+-----+-----
|
||||
| 192.168.1.226/24 | 192.168.1.0/24 | f | f | f | t | t | t | f | t | f | t
|
||||
| 192.168.1.226 | 192.168.1.0/24 | f | f | f | t | t | t | t | t | f | f
|
||||
| 192.168.1.0/24 | 192.168.1.0/24 | f | t | t | t | f | f | f | t | f | t
|
||||
| 192.168.1.0/25 | 192.168.1.0/24 | f | f | f | t | t | t | t | t | f | f
|
||||
| 192.168.1.255/24 | 192.168.1.0/24 | f | f | f | t | t | t | f | t | f | t
|
||||
| 192.168.1.255/25 | 192.168.1.0/24 | f | f | f | t | t | t | t | t | f | f
|
||||
| 10.1.2.3/8 | 10.0.0.0/8 | f | f | f | t | t | t | f | t | f | t
|
||||
| 10.1.2.3/8 | 10.0.0.0/32 | t | t | f | f | f | t | f | f | t | t
|
||||
| 10.1.2.3 | 10.1.2.3/32 | f | t | t | t | f | f | f | t | f | t
|
||||
| 10.1.2.3/24 | 10.1.2.0/24 | f | f | f | t | t | t | f | t | f | t
|
||||
| 10.1.2.3/16 | 10.1.0.0/16 | f | f | f | t | t | t | f | t | f | t
|
||||
| 10.1.2.3/8 | 10.0.0.0/8 | f | f | f | t | t | t | f | t | f | t
|
||||
| 11.1.2.3/8 | 10.0.0.0/8 | f | f | f | t | t | t | f | f | f | f
|
||||
| 9.1.2.3/8 | 10.0.0.0/8 | t | t | f | f | f | t | f | f | f | f
|
||||
(14 rows)
|
||||
ten | i | c | lt | le | eq | ge | gt | ne | sb | sbe | sup | spe
|
||||
-----+------------------+--------------------+----+----+----+----+----+----+----+-----+-----+-----
|
||||
| 192.168.1.226/24 | 192.168.1.0/24 | f | f | f | t | t | t | f | t | f | t
|
||||
| 192.168.1.226 | 192.168.1.0/24 | f | f | f | t | t | t | t | t | f | f
|
||||
| 192.168.1.0/24 | 192.168.1.0/24 | f | t | t | t | f | f | f | t | f | t
|
||||
| 192.168.1.0/25 | 192.168.1.0/24 | f | f | f | t | t | t | t | t | f | f
|
||||
| 192.168.1.255/24 | 192.168.1.0/24 | f | f | f | t | t | t | f | t | f | t
|
||||
| 192.168.1.255/25 | 192.168.1.0/24 | f | f | f | t | t | t | t | t | f | f
|
||||
| 10.1.2.3/8 | 10.0.0.0/8 | f | f | f | t | t | t | f | t | f | t
|
||||
| 10.1.2.3/8 | 10.0.0.0/32 | t | t | f | f | f | t | f | f | t | t
|
||||
| 10.1.2.3 | 10.1.2.3/32 | f | t | t | t | f | f | f | t | f | t
|
||||
| 10.1.2.3/24 | 10.1.2.0/24 | f | f | f | t | t | t | f | t | f | t
|
||||
| 10.1.2.3/16 | 10.1.0.0/16 | f | f | f | t | t | t | f | t | f | t
|
||||
| 10.1.2.3/8 | 10.0.0.0/8 | f | f | f | t | t | t | f | t | f | t
|
||||
| 11.1.2.3/8 | 10.0.0.0/8 | f | f | f | t | t | t | f | f | f | f
|
||||
| 9.1.2.3/8 | 10.0.0.0/8 | t | t | f | f | f | t | f | f | f | f
|
||||
| 10:23::f1/64 | 10:23::f1/128 | t | t | f | f | f | t | f | f | t | t
|
||||
| 10:23::ffff | 10:23::8000/113 | f | f | f | t | t | t | t | t | f | f
|
||||
| ::4.3.2.1/24 | ::ffff:1.2.3.4/128 | t | t | f | f | f | t | f | f | t | t
|
||||
(17 rows)
|
||||
|
||||
-- check the conversion to/from text and set_netmask
|
||||
SELECT '' AS ten, set_masklen(inet(text(i)), 24) FROM INET_TBL;
|
||||
@@ -185,7 +210,10 @@ SELECT '' AS ten, set_masklen(inet(text(i)), 24) FROM INET_TBL;
|
||||
| 10.1.2.3/24
|
||||
| 11.1.2.3/24
|
||||
| 9.1.2.3/24
|
||||
(14 rows)
|
||||
| 10:23::f1/24
|
||||
| 10:23::ffff/24
|
||||
| ::4.3.2.1/24
|
||||
(17 rows)
|
||||
|
||||
-- check that index works correctly
|
||||
CREATE INDEX inet_idx1 ON inet_tbl(i);
|
||||
|
||||
@@ -20,16 +20,20 @@ INSERT INTO INET_TBL (c, i) VALUES ('10.1', '10.1.2.3/16');
|
||||
INSERT INTO INET_TBL (c, i) VALUES ('10', '10.1.2.3/8');
|
||||
INSERT INTO INET_TBL (c, i) VALUES ('10', '11.1.2.3/8');
|
||||
INSERT INTO INET_TBL (c, i) VALUES ('10', '9.1.2.3/8');
|
||||
INSERT INTO INET_TBL (c, i) VALUES ('10:23::f1', '10:23::f1/64');
|
||||
INSERT INTO INET_TBL (c, i) VALUES ('10:23::8000/113', '10:23::ffff');
|
||||
INSERT INTO INET_TBL (c, i) VALUES ('::ffff:1.2.3.4', '::4.3.2.1/24');
|
||||
-- check that CIDR rejects invalid input:
|
||||
INSERT INTO INET_TBL (c, i) VALUES ('192.168.1.2/24', '192.168.1.226');
|
||||
INSERT INTO INET_TBL (c, i) VALUES ('1234::1234::1234', '::1.2.3.4');
|
||||
-- check that CIDR rejects invalid input when converting from text:
|
||||
INSERT INTO INET_TBL (c, i) VALUES (cidr('192.168.1.2/24'), '192.168.1.226');
|
||||
|
||||
INSERT INTO INET_TBL (c, i) VALUES (cidr('ffff:ffff:ffff:ffff::/24'), '::192.168.1.226');
|
||||
SELECT '' AS ten, c AS cidr, i AS inet FROM INET_TBL;
|
||||
|
||||
-- now test some support functions
|
||||
|
||||
SELECT '' AS ten, i AS inet, host(i), text(i) FROM INET_TBL;
|
||||
SELECT '' AS ten, i AS inet, host(i), text(i), family(i) FROM INET_TBL;
|
||||
SELECT '' AS ten, c AS cidr, broadcast(c),
|
||||
i AS inet, broadcast(i) FROM INET_TBL;
|
||||
SELECT '' AS ten, c AS cidr, network(c) AS "network(cidr)",
|
||||
|
||||
Reference in New Issue
Block a user