pax_global_header00006660000000000000000000000064123362031740014513gustar00rootroot0000000000000052 comment=fe0c0c9221d744074bc8e97a70fc2f974bcc71b0 ip4r-2.0.2/000077500000000000000000000000001233620317400123725ustar00rootroot00000000000000ip4r-2.0.2/.gitignore000066400000000000000000000003641233620317400143650ustar00rootroot00000000000000*.o *.so *.so.[0-9] *.so.[0-9].[0-9] *.sl *.sl.[0-9] *.sl.[0-9].[0-9] *.dylib *.dll *.a *.mo objfiles.txt .deps/ *.gcno *.gcda *.gcov *.gcov.out lcov.info coverage/ /results/ /ip4r.sql /ip4r.sql.in /sql/ip4r-legacy.sql /expected/ip4r-legacy.outip4r-2.0.2/Makefile000066400000000000000000000020461233620317400140340ustar00rootroot00000000000000 MODULE_big = ip4r ifndef NO_EXTENSION EXTENSION = ip4r DATA = ip4r--2.0.sql ip4r--unpackaged2.0--2.0.sql ip4r--unpackaged1--2.0.sql REGRESS = ip4r else DATA_built = ip4r.sql EXTRA_CLEAN += ip4r.sql.in sql/ip4r-legacy.sql expected/ip4r-legacy.out REGRESS = ip4r-legacy endif DOCS = README.ip4r OBJS = ip4r_module.o ip4r.o ip6r.o ipaddr.o iprange.o raw_io.o ifndef NO_PGXS PG_CONFIG = pg_config PGXS = $(shell $(PG_CONFIG) --pgxs) include $(PGXS) else subdir = contrib/ip4r top_builddir = ../.. include $(top_builddir)/src/Makefile.global include $(top_srcdir)/contrib/contrib-global.mk endif ifndef EXTENSION ip4r.sql.in: ip4r--2.0.sql legacy.sed sed -f legacy.sed $< >$@ sql/ip4r-legacy.sql: sql/ip4r.sql legacy-r.sed sed -f legacy-r.sed $< >$@ expected/ip4r-legacy.out: expected/ip4r.out sed -f legacy-r.sed $< | sed -e '/^\\i /,+1d' >$@ installcheck: sql/ip4r-legacy.sql expected/ip4r-legacy.out else ifeq ($(filter-out 7.% 8.% 9.0, $(MAJORVERSION)),) $(error extension build not supported in versions before 9.1, use NO_EXTENSION=1) endif endif ip4r-2.0.2/README.ip4r000066400000000000000000000374411233620317400141400ustar00rootroot00000000000000 IP4R - IPv4/v6 and IPv4/v6 range index type for PostgreSQL =========================================================== CHANGES from version 1.x: ========================= * 9.1+ extension packaging mechanism is the default for this version (use NO_EXTENSION=1 to build on pre-9.1 or without packaging) * New types for ip6, ip6r, ipaddress, iprange * ip4 input no longer accepts spurious leading whitespace UPGRADING ========= If upgrading from ip4r-2.0 installed outside the extension mechanism, use: CREATE EXTENSION ip4r FROM unpackaged2.0; If upgrading from ip4r-1.x, use: CREATE EXTENSION ip4r FROM unpackaged1; PRE-9.1 SYSTEMS =============== On versions before 9.1, or to build without extension packaging, use the RATIONALE ========= While PostgreSQL already has builtin types 'inet' and 'cidr', the authors of this module found that they had a number of requirements that were not addressed by the builtin type. Firstly and most importantly, the builtin types have no support for index lookups of the form (column >>= parameter), i.e. where you have a table of IP address ranges and wish to find which ones include a given IP address. This requires an rtree or gist index to do efficiently, and also requires a way to represent IP address ranges that do not fall precisely on CIDR boundaries. Secondly, the builtin inet/cidr are somewhat overloaded with semantics, with inet combining two distinct concepts (a netblock, and a specific IP within that netblock). Furthermore, they are variable length types (to support ipv6) with non-trivial overheads, and the authors (whose applications mainly deal in large volumes of single IPv4 addresses) wanted a more lightweight representation. IP4R therefore supports six distinct data types: ip4 - a single IPv4 address ip4r - an arbitrary range of IPv4 addresses ip6 - a single IPv6 address ip6r - an arbitrary range of IPv6 addresses ipaddress - a single IPv4 or IPv6 address iprange - an arbitrary range of IPv4 or IPv6 addresses Simple usage examples: CREATE TABLE ipranges (range ip4r primary key, description text not null); CREATE INDEX ipranges_range_idx ON ipranges USING gist (range); INSERT INTO ipranges VALUES ('10.0.0.0/8','rfc1918 block 1'); INSERT INTO ipranges VALUES ('172.16.0.0/12','rfc1918 block 2'); INSERT INTO ipranges VALUES ('192.168.0.0/16','rfc1918 block 3'); INSERT INTO ipranges VALUES ('0.0.0.0/1','classical class A space'); INSERT INTO ipranges VALUES ('10.0.1.10-10.0.1.20','my internal network'); INSERT INTO ipranges VALUES ('127.0.0.1','localhost'); CREATE TABLE access_log (id serial primary key, ip ip4 not null); CREATE INDEX access_log_ip_idx ON access_log (ip); INSERT INTO access_log(ip) VALUES ('10.0.1.15'); INSERT INTO access_log(ip) VALUES ('24.1.2.3'); INSERT INTO access_log(ip) VALUES ('192.168.10.20'); INSERT INTO access_log(ip) VALUES ('127.0.0.1'); -- find all accesses from 10.0.0.0/8 SELECT * FROM access_log WHERE ip BETWEEN '10.0.0.0' AND '10.255.255.255'; -- find all applicable descriptions for all entry in the access log -- returns multiple rows for each entry if there are overlapping ranges SELECT id,ip,range,description FROM access_log, ipranges WHERE ip <<= range; -- find only the most specific description for all IPs in the access log SELECT DISTINCT ON (ip) ip,range,description FROM access_log, ipranges WHERE ip <<= range ORDER BY ip, @ range; INSTALLATION ============ ip4r can be installed via the pgxs mechanism (which is now the default). Unpack the distribution and do: make make install (as with PostgreSQL itself, this requires GNU Make. The second command will usually need to be run as root.) USAGE ===== Types "ip4", "ip6", "ipaddress" ------------------------------- "ip4" accepts input in the form 'nnn.nnn.nnn.nnn' in decimal base only (no hex, octal, etc.). An ip4 value is a single IP address, and is stored as a 32-bit unsigned integer. "ip6" accepts input in the standard hexadecimal representation for IPv6 addresses, e.g. '2001:1234:aa55::2323'. "Mixed" format input (using an IPv4 dotted-decimal for the last two words) is accepted. An ip6 value is a single IP address, and is stored as two 64-bit values for convenience. Output is represented according to the specification in RFC 5952 (including output in mixed format for v4-mapped addresses). "ipaddress" accepts any input which is valid for either ip4 or ip6. An ipaddress value is a single IP address, either v4 or v6. The v4 and v6 ranges are treated as disjoint - all v4 addresses are considered lower than all v6 addresses, and '1.2.3.4' and '::ffff:1.2.3.4' are not equal. "ipX" will be used below to represent any of the above three types. The following type conversions are supported: Source type | Dest type | Form ----------------|------------|------------------------------------------------ ipX | text | text(ipX) or ipX::text (explicit) text | ipX | ipX(text) or text::ipX (explicit) ipX | cidr | cidr(ipX) or ipX::cidr (assignment) inet | ipX | ipX(inet) or inet::ipX (assignment) ipX | numeric | to_numeric(ipX) or ipX::numeric (explicit) numeric | ipX | ipX(numeric) or bigint::ipX (explicit) ip4 | bigint | to_bigint(ip4) or ip4::bigint (explicit) bigint | ip4 | ip4(bigint) or bigint::ip4 (explicit) ip4 | float8 | to_double(ip4) or ip4::float8 (explicit) float8 | ip4 | ip4(float8) or float8::ip4 (explicit) ipX | ipXr | ipXr(ipX) or ipX::ipXr (implicit) ip4 | ipaddress | ipaddress(ip4) or ip4::ipaddress (implicit) ip6 | ipaddress | ipaddress(ip6) or ip6::ipaddress (implicit) ipaddress | ip4 | ip4(ipaddress) or ipaddress::ip4 (explicit) ipaddress | ip6 | ip6(ipaddress) or ipaddress::ip6 (explicit) The conversions from bigint and float8 are available only for ip4, and accept values which are exact integers in the range 0 .. 2^32-1, which are converted to IPs in the range 0.0.0.0 - 255.255.255.255 in the obvious way. This is useful for conversions from applications which store IPs in numeric form, as is often done for performance in certain other databases. Conversions to and from the 'numeric' type are available for all formats with the obvious behaviour. The conversion to cidr always results in a /32 (for v4) or /128 (for v6). The conversion from inet ignores any prefix length and just takes the specific IP address. An ipX value implicitly converts to either the corresponding range type (ip4 -> ip4r, ip6 -> ip6r), or to the iprange type, producing a range containing only the single IP address. ipX supports the following operators with the conventional meanings: =, <>, <, >, <=, >=, and supports ORDER BY and btree indexes in the obvious fashion. However, the planner does not understand how to transform a query of the form WHERE ipcolumn <<= value into a btree range scan (it does this transformation for the builtin inet type using a function which is not extensible by plugins). As a workaround, use the following form instead: WHERE ipcolumn BETWEEN lower(value) AND upper(value) which will use a btree range scan. ipX supports the following additional operators and functions: family(ipX) returns integer | returns the value 4 or 6 depending on address family ip4_netmask(integer) returns ip4 | returns an ip4 value that represents a netmask for a prefix length ip6_netmask(integer) returns ip6 | returns an ip6 value that represents a netmask for a prefix length ipX_net_lower(ipX, integer) returns ipX | returns the lowest address in the cidr block of the specified prefix | length, containing the specified IP | equivalent to: network(set_masklen(cidr(ipX),integer)) ipX_net_upper(ipX, integer) returns ipX | returns the highest address in the cidr block of the specified prefix | length, containing the specified IP | equivalent to: broadcast(set_masklen(cidr(ip4),integer)) Operator | Description ------------------|-------------------------------------------------------- ipX + integer | add the given integer to the IP ipX - integer | subtract the given integer from the IP ipX + bigint | add the given integer to the IP ipX - bigint | subtract the given integer from the IP ipX + numeric | add the given integer to the IP ipX - numeric | subtract the given integer from the IP ipX - ipX | (returns bigint or numeric) difference between two IPs ipX & ipX | bitwise-AND the two values ipX | ipX | bitwise-OR the two values ipX # ipX | bitwise-XOR the two values ~ ipX | bitwise-NOT the value Arithmetic on ip4 values does not wrap below 0.0.0.0 or above 255.255.255.255 - attempting to go beyond these limits raises an error. More complex arithmetic on IP addresses can be performed by converting the IPs to numeric first; the above are only intended to cover the common cases without requiring casts. Types "ip4r", "ip6r", "iprange" ------------------------------- An "ip4r" value denotes a single range of one or more IPv4 addresses, for example '192.0.2.100-192.0.2.200'. Arbitrary ranges are allowed, though input can also be in the form of CIDR netblocks, e.g. '192.0.2.0/24' is equivalent to '192.0.2.0-192.0.2.255'. A single value such as '192.0.2.25' represents a range containing only that value. An "ip6r" value denotes a single range of one or more IPv6 addresses, for example '2001::1234-2001::2000:0000'. Arbitrary ranges are allowed, though input can also be in the form of CIDR netblocks, e.g. '2001::/112' is equivalent to '2001::-2001::ffff'. A single value such as '2001::1234' represents a range containing only that value. Output formatting is as specified in RFC 5952. An "iprange" value denotes either an IPv4 range or an IPv6 range, or the special value '-' which includes all of both IPv4 and IPv6 space. Mixing of address families is not otherwise supported. For all of the above types, values are displayed in CIDR form if they represent a CIDR range, otherwise in range form. Currently, abbreviated CIDR forms for IPv4 are not accepted at all, i.e. all octets must be supplied. For IPv6, words may only be omitted from the address as permitted by the zero-compression rules of RFC 5952. "ipXr" will be used below to represent any one of the above three types. An ipXr value can be constructed from two IPs explicitly using the function ipXr(ipX,ipX). The ends of the range can be specified in either order. An ipXr value can be constructed from an IP and a prefix length using the / operator (see below). For backward compatibility, the function names ipXr_net_prefix and ipXr_net_mask are still accepted for this operator. ipXr supports the following type conversions: Source type | Dest type | Form ----------------|-----------|---------------------------------------------- ipX | ipXr | ipXr(ipX) or ipX::ipXr (implicit) ipXr | text | text(ipXr) or ipXr::text (explicit) text | ipXr | ipXr(text) or text::ipXr (explicit) ipXr | cidr | cidr(ipXr) or ipXr::cidr (explicit) cidr | ipXr | ipXr(cidr) or cidr::ipXr (assignment) The conversion cidr(ipXr) returns NULL if the ipXr value does not represent a valid CIDR range. In addition, type conversions between ip4r, ip6r and iprange are permitted in all valid combinations. ipXr supports the following functions: family(ipXr) returns integer | returns 4 or 6 according to address family, or NULL for '-'::iprange is_cidr(ipXr) returns boolean | returns TRUE if the ipXr value is a valid CIDR range lower(ipXr) returns ipX | returns the lower end of the ipXr range, as an ipX value upper(ipXr) returns ipX | returns the upper end of the ipXr range, as an ipX value ipXr supports the following operators: Operator | Description ------------------|-------------------------------------------------------- a = b | exact equality a <> b | exact inequality a < b | note [1] a <= b | note [1] a > b | note [1] a >= b | note [1] a >>= b | a contains b or is equal to b a >> b | a strictly contains b a <<= b | a is contained in b or is equal to b a << b | a is strictly contained in b a && b | a and b overlap @ a | approximate size of a (returns double) @@ a | exact size of a (returns numeric) a / n | construct CIDR range from address a length n a / b | construct CIDR range from address a netmask b [1]: the operators <, <=, >, >= implement an ordering for the purposes of btree indexes, DISTINCT and ORDER BY; the ordering is not necessarily useful for applications. The ordering used is a lexicographic ordering of (lower,upper). For testing whether an ipXr range contains a specified single ip, use the >>= operator, i.e. ipXr >>= ipX. The implicit conversion from ipX to ipXr handles this case. ipXr Indexes ------------ ipXr values can be indexed in several ways. A conventional btree index on ipXr values will work for the purposes of unique/primary key constraints, ordering, and equality lookups (i.e. WHERE column = value). Btree indexes are created in the usual way and are the default index type. However, ipXr's utility comes from its ability to use gist indexes to support the following lookup types: WHERE column >>= value (or >>) WHERE column <<= value (or <<) WHERE column && value These lookups require a GiST index. This can be created as follows: CREATE INDEX indexname ON tablename USING gist (column); It is also possible to create a functional ip4r index over a column of 'cidr' type as follows: CREATE INDEX indexname ON tablename USING gist (iprange(cidrcolumn)); (ip4r(column) or ip6r(column) can also be used if the column is constrained to contain only values of the specified address family) This can then be used for queries of the form: WHERE iprange(cidrcolumn) >>= value (or >>, <<=, && etc) One advantage of this method is that the ip4r type can be dropped and recreated without losing data. This is useful for accelerating queries on an existing table designed without ip4r in mind. Another idiom sometimes seen for representation of ranges of IP addresses is for applications to create two integer columns, and do range queries of the form: WHERE value BETWEEN column1 and column2 This is an attempt to get some use out of a btree index, but it performs poorly in most cases. This can also be converted to use a functional ip4r index as follows: CREATE INDEX indexname ON tablename USING gist (ip4r(column1::ip4,column2::ip4)); and then doing queries of the form: WHERE ip4r(column1::ip4,column2::ip4) >>= value This method is not usually practical for IPv6. A common requirement is to get the longest-prefix (most specific) match to an IP address from a table of ranges or CIDR prefixes. This can usually be best achieved using ORDER BY @ column, for example: SELECT * FROM tablename WHERE column >>= value ORDER BY @ column LIMIT 1 The use of @ column (approximate size) is sufficient if the values are IPv4 ranges or are always CIDR prefixes. If arbitrary IPv6 ranges are present, then overlapping ranges with small size differences might compare equal; in this case use ORDER BY @@ column. When looking up multiple IPs, one can do queries of the following form: SELECT DISTINCT ON (ips.ip) ips.ip, ranges.range FROM ips, ranges WHERE ranges.range >>= ips.ip ORDER BY ips.ip, @ ranges.range AUTHORS ======= this code by andrew@tao11.riddles.org.uk Oct 2004 - Nov 2011 derived from 'ipr' by Steve Atkins August 2003 derived from the 'seg' type distributed with PostgreSQL. Distributed under the same terms as PostgreSQL itself. Currently maintained at: http://pgfoundry.org/projects/ip4r/ ip4r-2.0.2/expected/000077500000000000000000000000001233620317400141735ustar00rootroot00000000000000ip4r-2.0.2/expected/ip4r.out000066400000000000000000013241741233620317400156160ustar00rootroot00000000000000-- CREATE EXTENSION ip4r; \set VERBOSITY terse -- -- Valid and invalid addresses -- --valid ip4 select '1.2.3.4'::ip4; ip4 --------- 1.2.3.4 (1 row) select '0.0.0.0'::ip4; ip4 --------- 0.0.0.0 (1 row) select '255.255.255.255'::ip4; ip4 ----------------- 255.255.255.255 (1 row) select '0.0.0.255'::ip4; ip4 ----------- 0.0.0.255 (1 row) select '0.0.255.0'::ip4; ip4 ----------- 0.0.255.0 (1 row) select '0.255.0.0'::ip4; ip4 ----------- 0.255.0.0 (1 row) select '255.0.0.0'::ip4; ip4 ----------- 255.0.0.0 (1 row) select '192.168.123.210'::ip4; ip4 ----------------- 192.168.123.210 (1 row) select '127.0.0.1'::ip4; ip4 ----------- 127.0.0.1 (1 row) --invalid ip4 select '1.2.3'::ip4; ERROR: invalid IP4 value: '1.2.3' at character 8 select '0'::ip4; ERROR: invalid IP4 value: '0' at character 8 select ' 1.2.3.4'::ip4; ERROR: invalid IP4 value: ' 1.2.3.4' at character 8 select '1.2.3.4 '::ip4; ERROR: invalid IP4 value: '1.2.3.4 ' at character 8 select '0.0.0.256'::ip4; ERROR: invalid IP4 value: '0.0.0.256' at character 8 select '0.0.256'::ip4; ERROR: invalid IP4 value: '0.0.256' at character 8 select '0..255.0'::ip4; ERROR: invalid IP4 value: '0..255.0' at character 8 select '+0.255.0.0'::ip4; ERROR: invalid IP4 value: '+0.255.0.0' at character 8 select '1.2.3.4-1.2.3.4'::ip4; ERROR: invalid IP4 value: '1.2.3.4-1.2.3.4' at character 8 -- valid ip6 select '0000:0000:0000:0000:0000:0000:0000:0000'::ip6; ip6 ----- :: (1 row) select '0000:0000:0000:0000:0000:0000:0000:0001'::ip6; ip6 ----- ::1 (1 row) select '0:0:0:0:0:0:0:0'::ip6; ip6 ----- :: (1 row) select '0:0:0:0:0:0:0:1'::ip6; ip6 ----- ::1 (1 row) select '0:0:0:0:0:0:13.1.68.3'::ip6; ip6 ------------- ::13.1.68.3 (1 row) select '0:0:0:0:0:FFFF:129.144.52.38'::ip6; ip6 ---------------------- ::ffff:129.144.52.38 (1 row) select '0::0'::ip6; ip6 ----- :: (1 row) select '1:2:3:4:5:6:1.2.3.4'::ip6; ip6 --------------------- 1:2:3:4:5:6:102:304 (1 row) select '1:2:3:4:5:6:7:8'::ip6; ip6 ----------------- 1:2:3:4:5:6:7:8 (1 row) select '1:2:3:4:5:6::'::ip6; ip6 --------------- 1:2:3:4:5:6:: (1 row) select '1:2:3:4:5:6::8'::ip6; ip6 ----------------- 1:2:3:4:5:6:0:8 (1 row) select '1:2:3:4:5::'::ip6; ip6 ------------- 1:2:3:4:5:: (1 row) select '1:2:3:4:5::1.2.3.4'::ip6; ip6 --------------------- 1:2:3:4:5:0:102:304 (1 row) select '1:2:3:4:5::7:8'::ip6; ip6 ----------------- 1:2:3:4:5:0:7:8 (1 row) select '1:2:3:4:5::8'::ip6; ip6 -------------- 1:2:3:4:5::8 (1 row) select '1:2:3:4::'::ip6; ip6 ----------- 1:2:3:4:: (1 row) select '1:2:3:4::1.2.3.4'::ip6; ip6 ------------------ 1:2:3:4::102:304 (1 row) select '1:2:3:4::5:1.2.3.4'::ip6; ip6 --------------------- 1:2:3:4:0:5:102:304 (1 row) select '1:2:3:4::7:8'::ip6; ip6 -------------- 1:2:3:4::7:8 (1 row) select '1:2:3:4::8'::ip6; ip6 ------------ 1:2:3:4::8 (1 row) select '1:2:3::'::ip6; ip6 --------- 1:2:3:: (1 row) select '1:2:3::1.2.3.4'::ip6; ip6 ---------------- 1:2:3::102:304 (1 row) select '1:2:3::5:1.2.3.4'::ip6; ip6 ------------------ 1:2:3::5:102:304 (1 row) select '1:2:3::7:8'::ip6; ip6 ------------ 1:2:3::7:8 (1 row) select '1:2:3::8'::ip6; ip6 ---------- 1:2:3::8 (1 row) select '1:2::'::ip6; ip6 ------- 1:2:: (1 row) select '1:2::1.2.3.4'::ip6; ip6 -------------- 1:2::102:304 (1 row) select '1:2::5:1.2.3.4'::ip6; ip6 ---------------- 1:2::5:102:304 (1 row) select '1:2::7:8'::ip6; ip6 ---------- 1:2::7:8 (1 row) select '1:2::8'::ip6; ip6 -------- 1:2::8 (1 row) select '1::'::ip6; ip6 ----- 1:: (1 row) select '1::1.2.3.4'::ip6; ip6 ------------ 1::102:304 (1 row) select '1::2:3'::ip6; ip6 -------- 1::2:3 (1 row) select '1::2:3:4'::ip6; ip6 ---------- 1::2:3:4 (1 row) select '1::2:3:4:5'::ip6; ip6 ------------ 1::2:3:4:5 (1 row) select '1::2:3:4:5:6'::ip6; ip6 -------------- 1::2:3:4:5:6 (1 row) select '1::2:3:4:5:6:7'::ip6; ip6 ----------------- 1:0:2:3:4:5:6:7 (1 row) select '1::5:1.2.3.4'::ip6; ip6 -------------- 1::5:102:304 (1 row) select '1::5:11.22.33.44'::ip6; ip6 --------------- 1::5:b16:212c (1 row) select '1::7:8'::ip6; ip6 -------- 1::7:8 (1 row) select '1::8'::ip6; ip6 ------ 1::8 (1 row) select '2001:0000:1234:0000:0000:C1C0:ABCD:0876'::ip6; ip6 ---------------------------- 2001:0:1234::c1c0:abcd:876 (1 row) select '2001:0db8:0000:0000:0000:0000:1428:57ab'::ip6; ip6 --------------------- 2001:db8::1428:57ab (1 row) select '2001:0db8:0000:0000:0000::1428:57ab'::ip6; ip6 --------------------- 2001:db8::1428:57ab (1 row) select '2001:0db8:0:0:0:0:1428:57ab'::ip6; ip6 --------------------- 2001:db8::1428:57ab (1 row) select '2001:0db8:0:0::1428:57ab'::ip6; ip6 --------------------- 2001:db8::1428:57ab (1 row) select '2001:0db8:1234:0000:0000:0000:0000:0000'::ip6; ip6 ----------------- 2001:db8:1234:: (1 row) select '2001:0db8:1234::'::ip6; ip6 ----------------- 2001:db8:1234:: (1 row) select '2001:0db8:1234:ffff:ffff:ffff:ffff:ffff'::ip6; ip6 ---------------------------------------- 2001:db8:1234:ffff:ffff:ffff:ffff:ffff (1 row) select '2001:0db8:85a3:0000:0000:8a2e:0370:7334'::ip6; ip6 ------------------------------ 2001:db8:85a3::8a2e:370:7334 (1 row) select '2001:0db8::1428:57ab'::ip6; ip6 --------------------- 2001:db8::1428:57ab (1 row) select '2001:10::'::ip6; ip6 ----------- 2001:10:: (1 row) select '2001::'::ip6; ip6 -------- 2001:: (1 row) select '2001:DB8:0:0:8:800:200C:417A'::ip6; ip6 --------------------------- 2001:db8::8:800:200c:417a (1 row) select '2001:DB8::8:800:200C:417A'::ip6; ip6 --------------------------- 2001:db8::8:800:200c:417a (1 row) select '2001:db8:85a3:0:0:8a2e:370:7334'::ip6; ip6 ------------------------------ 2001:db8:85a3::8a2e:370:7334 (1 row) select '2001:db8:85a3::8a2e:370:7334'::ip6; ip6 ------------------------------ 2001:db8:85a3::8a2e:370:7334 (1 row) select '2001:db8::'::ip6; ip6 ------------ 2001:db8:: (1 row) select '2001:db8::'::ip6; ip6 ------------ 2001:db8:: (1 row) select '2001:db8::1428:57ab'::ip6; ip6 --------------------- 2001:db8::1428:57ab (1 row) select '2001:db8:a::123'::ip6; ip6 ----------------- 2001:db8:a::123 (1 row) select '2002::'::ip6; ip6 -------- 2002:: (1 row) select '2::10'::ip6; ip6 ------- 2::10 (1 row) select '3ffe:0b00:0000:0000:0001:0000:0000:000a'::ip6; ip6 ------------------- 3ffe:b00::1:0:0:a (1 row) select '::'::ip6; ip6 ----- :: (1 row) select '::1'::ip6; ip6 ----- ::1 (1 row) select '::127.0.0.1'::ip6; ip6 ------------- ::127.0.0.1 (1 row) select '::13.1.68.3'::ip6; ip6 ------------- ::13.1.68.3 (1 row) select '::2:3'::ip6; ip6 ----------- ::0.2.0.3 (1 row) select '::2:3:4'::ip6; ip6 --------- ::2:3:4 (1 row) select '::2:3:4:5'::ip6; ip6 ----------- ::2:3:4:5 (1 row) select '::2:3:4:5:6'::ip6; ip6 ------------- ::2:3:4:5:6 (1 row) select '::2:3:4:5:6:7'::ip6; ip6 --------------- ::2:3:4:5:6:7 (1 row) select '::2:3:4:5:6:7:8'::ip6; ip6 ----------------- 0:2:3:4:5:6:7:8 (1 row) select '::8'::ip6; ip6 ----- ::8 (1 row) select '::FFFF:129.144.52.38'::ip6; ip6 ---------------------- ::ffff:129.144.52.38 (1 row) select '::ffff:0:0'::ip6; ip6 ---------------- ::ffff:0.0.0.0 (1 row) select '::ffff:0:192.168.1.1'::ip6; ip6 ---------------------- ::ffff:0:192.168.1.1 (1 row) select '::ffff:1:1.2.3.4'::ip6; ip6 ------------------ ::ffff:1:102:304 (1 row) select '::ffff:0c22:384e'::ip6; ip6 -------------------- ::ffff:12.34.56.78 (1 row) select '::ffff:12.34.56.78'::ip6; ip6 -------------------- ::ffff:12.34.56.78 (1 row) select '::ffff:192.0.2.128'::ip6; ip6 -------------------- ::ffff:192.0.2.128 (1 row) select '::ffff:192.168.1.1'::ip6; ip6 -------------------- ::ffff:192.168.1.1 (1 row) select '::ffff:192.168.1.26'::ip6; ip6 --------------------- ::ffff:192.168.1.26 (1 row) select '::ffff:c000:280'::ip6; ip6 -------------------- ::ffff:192.0.2.128 (1 row) select 'FF01:0:0:0:0:0:0:101'::ip6; ip6 ----------- ff01::101 (1 row) select 'FF01::101'::ip6; ip6 ----------- ff01::101 (1 row) select 'FF02:0000:0000:0000:0000:0000:0000:0001'::ip6; ip6 --------- ff02::1 (1 row) select 'fc00::'::ip6; ip6 -------- fc00:: (1 row) select 'fe80:0000:0000:0000:0204:61ff:fe9d:f156'::ip6; ip6 -------------------------- fe80::204:61ff:fe9d:f156 (1 row) select 'fe80:0:0:0:204:61ff:254.157.241.86'::ip6; ip6 -------------------------- fe80::204:61ff:fe9d:f156 (1 row) select 'fe80:0:0:0:204:61ff:fe9d:f156'::ip6; ip6 -------------------------- fe80::204:61ff:fe9d:f156 (1 row) select 'fe80::'::ip6; ip6 -------- fe80:: (1 row) select 'fe80::1'::ip6; ip6 --------- fe80::1 (1 row) select 'fe80::204:61ff:254.157.241.86'::ip6; ip6 -------------------------- fe80::204:61ff:fe9d:f156 (1 row) select 'fe80::204:61ff:fe9d:f156'::ip6; ip6 -------------------------- fe80::204:61ff:fe9d:f156 (1 row) select 'fe80::217:f2ff:254.7.237.98'::ip6; ip6 -------------------------- fe80::217:f2ff:fe07:ed62 (1 row) select 'fe80::217:f2ff:fe07:ed62'::ip6; ip6 -------------------------- fe80::217:f2ff:fe07:ed62 (1 row) select 'ff02::1'::ip6; ip6 --------- ff02::1 (1 row) -- invalid ip6 select ''::ip6; ERROR: invalid IP6 value: '' at character 8 select '02001:0000:1234:0000:0000:C1C0:ABCD:0876'::ip6; ERROR: invalid IP6 value: '02001:0000:1234:0000:0000:C1C0:ABCD:0876' at character 8 select '1.2.3.4:1111:2222:3333:4444::5555'::ip6; ERROR: invalid IP6 value: '1.2.3.4:1111:2222:3333:4444::5555' at character 8 select '1.2.3.4:1111:2222:3333::5555'::ip6; ERROR: invalid IP6 value: '1.2.3.4:1111:2222:3333::5555' at character 8 select '1.2.3.4:1111:2222::5555'::ip6; ERROR: invalid IP6 value: '1.2.3.4:1111:2222::5555' at character 8 select '1.2.3.4:1111::5555'::ip6; ERROR: invalid IP6 value: '1.2.3.4:1111::5555' at character 8 select '1.2.3.4::'::ip6; ERROR: invalid IP6 value: '1.2.3.4::' at character 8 select '1.2.3.4::5555'::ip6; ERROR: invalid IP6 value: '1.2.3.4::5555' at character 8 select '1111:'::ip6; ERROR: invalid IP6 value: '1111:' at character 8 select '1111:2222:3333:4444::5555:'::ip6; ERROR: invalid IP6 value: '1111:2222:3333:4444::5555:' at character 8 select '1111:2222:3333::5555:'::ip6; ERROR: invalid IP6 value: '1111:2222:3333::5555:' at character 8 select '1111:2222::5555:'::ip6; ERROR: invalid IP6 value: '1111:2222::5555:' at character 8 select '1111::5555:'::ip6; ERROR: invalid IP6 value: '1111::5555:' at character 8 select '123'::ip6; ERROR: invalid IP6 value: '123' at character 8 select '12345::6:7:8'::ip6; ERROR: invalid IP6 value: '12345::6:7:8' at character 8 select '127.0.0.1'::ip6; ERROR: invalid IP6 value: '127.0.0.1' at character 8 select '1:2:3:4:5:6:7:8:9'::ip6; ERROR: invalid IP6 value: '1:2:3:4:5:6:7:8:9' at character 8 select '1:2:3::4:5:6:7:8:9'::ip6; ERROR: invalid IP6 value: '1:2:3::4:5:6:7:8:9' at character 8 select '1:2:3::4:5::7:8'::ip6; ERROR: invalid IP6 value: '1:2:3::4:5::7:8' at character 8 select '1::1.2.256.4'::ip6; ERROR: invalid IP6 value: '1::1.2.256.4' at character 8 select '1::1.2.3.256'::ip6; ERROR: invalid IP6 value: '1::1.2.3.256' at character 8 select '1::1.2.3.300'::ip6; ERROR: invalid IP6 value: '1::1.2.3.300' at character 8 select '1::1.2.3.900'::ip6; ERROR: invalid IP6 value: '1::1.2.3.900' at character 8 select '1::1.2.300.4'::ip6; ERROR: invalid IP6 value: '1::1.2.300.4' at character 8 select '1::1.2.900.4'::ip6; ERROR: invalid IP6 value: '1::1.2.900.4' at character 8 select '1::1.256.3.4'::ip6; ERROR: invalid IP6 value: '1::1.256.3.4' at character 8 select '1::1.300.3.4'::ip6; ERROR: invalid IP6 value: '1::1.300.3.4' at character 8 select '1::1.900.3.4'::ip6; ERROR: invalid IP6 value: '1::1.900.3.4' at character 8 select '1::256.2.3.4'::ip6; ERROR: invalid IP6 value: '1::256.2.3.4' at character 8 select '1::260.2.3.4'::ip6; ERROR: invalid IP6 value: '1::260.2.3.4' at character 8 select '1::2::3'::ip6; ERROR: invalid IP6 value: '1::2::3' at character 8 select '1::300.2.3.4'::ip6; ERROR: invalid IP6 value: '1::300.2.3.4' at character 8 select '1::300.300.300.300'::ip6; ERROR: invalid IP6 value: '1::300.300.300.300' at character 8 select '1::3000.30.30.30'::ip6; ERROR: invalid IP6 value: '1::3000.30.30.30' at character 8 select '1::400.2.3.4'::ip6; ERROR: invalid IP6 value: '1::400.2.3.4' at character 8 select '1::5:1.2.256.4'::ip6; ERROR: invalid IP6 value: '1::5:1.2.256.4' at character 8 select '1::5:1.2.3.256'::ip6; ERROR: invalid IP6 value: '1::5:1.2.3.256' at character 8 select '1::5:1.2.3.300'::ip6; ERROR: invalid IP6 value: '1::5:1.2.3.300' at character 8 select '1::5:1.2.3.900'::ip6; ERROR: invalid IP6 value: '1::5:1.2.3.900' at character 8 select '1::5:1.2.300.4'::ip6; ERROR: invalid IP6 value: '1::5:1.2.300.4' at character 8 select '1::5:1.2.900.4'::ip6; ERROR: invalid IP6 value: '1::5:1.2.900.4' at character 8 select '1::5:1.256.3.4'::ip6; ERROR: invalid IP6 value: '1::5:1.256.3.4' at character 8 select '1::5:1.300.3.4'::ip6; ERROR: invalid IP6 value: '1::5:1.300.3.4' at character 8 select '1::5:1.900.3.4'::ip6; ERROR: invalid IP6 value: '1::5:1.900.3.4' at character 8 select '1::5:256.2.3.4'::ip6; ERROR: invalid IP6 value: '1::5:256.2.3.4' at character 8 select '1::5:260.2.3.4'::ip6; ERROR: invalid IP6 value: '1::5:260.2.3.4' at character 8 select '1::5:300.2.3.4'::ip6; ERROR: invalid IP6 value: '1::5:300.2.3.4' at character 8 select '1::5:300.300.300.300'::ip6; ERROR: invalid IP6 value: '1::5:300.300.300.300' at character 8 select '1::5:3000.30.30.30'::ip6; ERROR: invalid IP6 value: '1::5:3000.30.30.30' at character 8 select '1::5:400.2.3.4'::ip6; ERROR: invalid IP6 value: '1::5:400.2.3.4' at character 8 select '1::5:900.2.3.4'::ip6; ERROR: invalid IP6 value: '1::5:900.2.3.4' at character 8 select '1::900.2.3.4'::ip6; ERROR: invalid IP6 value: '1::900.2.3.4' at character 8 select '1:::3:4:5'::ip6; ERROR: invalid IP6 value: '1:::3:4:5' at character 8 select '2001:0000:1234: 0000:0000:C1C0:ABCD:0876'::ip6; ERROR: invalid IP6 value: '2001:0000:1234: 0000:0000:C1C0:ABCD:0876' at character 8 select '2001:0000:1234:0000:00001:C1C0:ABCD:0876'::ip6; ERROR: invalid IP6 value: '2001:0000:1234:0000:00001:C1C0:ABCD:0876' at character 8 select '2001:0000:1234:0000:0000:C1C0:ABCD:0876 0'::ip6; ERROR: invalid IP6 value: '2001:0000:1234:0000:0000:C1C0:ABCD:0876 0' at character 8 select '2001::FFD3::57ab'::ip6; ERROR: invalid IP6 value: '2001::FFD3::57ab' at character 8 select '2001:DB8:0:0:8:800:200C:417A:221'::ip6; ERROR: invalid IP6 value: '2001:DB8:0:0:8:800:200C:417A:221' at character 8 select '2001:db8:85a3::8a2e:37023:7334'::ip6; ERROR: invalid IP6 value: '2001:db8:85a3::8a2e:37023:7334' at character 8 select '2001:db8:85a3::8a2e:370k:7334'::ip6; ERROR: invalid IP6 value: '2001:db8:85a3::8a2e:370k:7334' at character 8 select '3ffe:0b00:0000:0001:0000:0000:000a'::ip6; ERROR: invalid IP6 value: '3ffe:0b00:0000:0001:0000:0000:000a' at character 8 select '3ffe:b00::1::a'::ip6; ERROR: invalid IP6 value: '3ffe:b00::1::a' at character 8 select ':'::ip6; ERROR: invalid IP6 value: ':' at character 8 select ':1111:2222:3333:4444::5555'::ip6; ERROR: invalid IP6 value: ':1111:2222:3333:4444::5555' at character 8 select ':1111:2222:3333::5555'::ip6; ERROR: invalid IP6 value: ':1111:2222:3333::5555' at character 8 select ':1111:2222::5555'::ip6; ERROR: invalid IP6 value: ':1111:2222::5555' at character 8 select ':1111::5555'::ip6; ERROR: invalid IP6 value: ':1111::5555' at character 8 select '::1.2.256.4'::ip6; ERROR: invalid IP6 value: '::1.2.256.4' at character 8 select '::1.2.3.256'::ip6; ERROR: invalid IP6 value: '::1.2.3.256' at character 8 select '::1.2.3.300'::ip6; ERROR: invalid IP6 value: '::1.2.3.300' at character 8 select '::1.2.3.900'::ip6; ERROR: invalid IP6 value: '::1.2.3.900' at character 8 select '::1.2.300.4'::ip6; ERROR: invalid IP6 value: '::1.2.300.4' at character 8 select '::1.2.900.4'::ip6; ERROR: invalid IP6 value: '::1.2.900.4' at character 8 select '::1.256.3.4'::ip6; ERROR: invalid IP6 value: '::1.256.3.4' at character 8 select '::1.300.3.4'::ip6; ERROR: invalid IP6 value: '::1.300.3.4' at character 8 select '::1.900.3.4'::ip6; ERROR: invalid IP6 value: '::1.900.3.4' at character 8 select '::1111:2222:3333:4444:5555:6666::'::ip6; ERROR: invalid IP6 value: '::1111:2222:3333:4444:5555:6666::' at character 8 select '::256.2.3.4'::ip6; ERROR: invalid IP6 value: '::256.2.3.4' at character 8 select '::260.2.3.4'::ip6; ERROR: invalid IP6 value: '::260.2.3.4' at character 8 select '::300.2.3.4'::ip6; ERROR: invalid IP6 value: '::300.2.3.4' at character 8 select '::300.300.300.300'::ip6; ERROR: invalid IP6 value: '::300.300.300.300' at character 8 select '::3000.30.30.30'::ip6; ERROR: invalid IP6 value: '::3000.30.30.30' at character 8 select '::400.2.3.4'::ip6; ERROR: invalid IP6 value: '::400.2.3.4' at character 8 select '::5555:'::ip6; ERROR: invalid IP6 value: '::5555:' at character 8 select '::900.2.3.4'::ip6; ERROR: invalid IP6 value: '::900.2.3.4' at character 8 select ':::'::ip6; ERROR: invalid IP6 value: ':::' at character 8 select ':::5555'::ip6; ERROR: invalid IP6 value: ':::5555' at character 8 select '::ffff:2.3.4'::ip6; ERROR: invalid IP6 value: '::ffff:2.3.4' at character 8 select '::ffff:257.1.2.3'::ip6; ERROR: invalid IP6 value: '::ffff:257.1.2.3' at character 8 select 'FF01::101::2'::ip6; ERROR: invalid IP6 value: 'FF01::101::2' at character 8 select 'FF02:0000:0000:0000:0000:0000:0000:0000:0001'::ip6; ERROR: invalid IP6 value: 'FF02:0000:0000:0000:0000:0000:0000:0000:0001' at character 8 select 'ldkfj'::ip6; ERROR: invalid IP6 value: 'ldkfj' at character 8 -- valid ip4r select '1.2.3.4'::ip4r; ip4r --------- 1.2.3.4 (1 row) select '255.255.255.255/32'::ip4r; ip4r ----------------- 255.255.255.255 (1 row) select '255.255.255.254/31'::ip4r; ip4r -------------------- 255.255.255.254/31 (1 row) select '255.255.255.252/30'::ip4r; ip4r -------------------- 255.255.255.252/30 (1 row) select '255.255.255.248/29'::ip4r; ip4r -------------------- 255.255.255.248/29 (1 row) select '255.255.255.240/28'::ip4r; ip4r -------------------- 255.255.255.240/28 (1 row) select '255.255.255.224/27'::ip4r; ip4r -------------------- 255.255.255.224/27 (1 row) select '255.255.255.192/26'::ip4r; ip4r -------------------- 255.255.255.192/26 (1 row) select '255.255.255.128/25'::ip4r; ip4r -------------------- 255.255.255.128/25 (1 row) select '255.255.255.0/24'::ip4r; ip4r ------------------ 255.255.255.0/24 (1 row) select '255.255.254.0/23'::ip4r; ip4r ------------------ 255.255.254.0/23 (1 row) select '255.255.252.0/22'::ip4r; ip4r ------------------ 255.255.252.0/22 (1 row) select '255.255.248.0/21'::ip4r; ip4r ------------------ 255.255.248.0/21 (1 row) select '255.255.240.0/20'::ip4r; ip4r ------------------ 255.255.240.0/20 (1 row) select '255.255.224.0/19'::ip4r; ip4r ------------------ 255.255.224.0/19 (1 row) select '255.255.192.0/18'::ip4r; ip4r ------------------ 255.255.192.0/18 (1 row) select '255.255.128.0/17'::ip4r; ip4r ------------------ 255.255.128.0/17 (1 row) select '255.255.0.0/16'::ip4r; ip4r ---------------- 255.255.0.0/16 (1 row) select '255.254.0.0/15'::ip4r; ip4r ---------------- 255.254.0.0/15 (1 row) select '255.252.0.0/14'::ip4r; ip4r ---------------- 255.252.0.0/14 (1 row) select '255.248.0.0/13'::ip4r; ip4r ---------------- 255.248.0.0/13 (1 row) select '255.240.0.0/12'::ip4r; ip4r ---------------- 255.240.0.0/12 (1 row) select '255.224.0.0/11'::ip4r; ip4r ---------------- 255.224.0.0/11 (1 row) select '255.192.0.0/10'::ip4r; ip4r ---------------- 255.192.0.0/10 (1 row) select '255.128.0.0/9'::ip4r; ip4r --------------- 255.128.0.0/9 (1 row) select '255.0.0.0/8'::ip4r; ip4r ------------- 255.0.0.0/8 (1 row) select '254.0.0.0/7'::ip4r; ip4r ------------- 254.0.0.0/7 (1 row) select '252.0.0.0/6'::ip4r; ip4r ------------- 252.0.0.0/6 (1 row) select '248.0.0.0/5'::ip4r; ip4r ------------- 248.0.0.0/5 (1 row) select '240.0.0.0/4'::ip4r; ip4r ------------- 240.0.0.0/4 (1 row) select '224.0.0.0/3'::ip4r; ip4r ------------- 224.0.0.0/3 (1 row) select '192.0.0.0/2'::ip4r; ip4r ------------- 192.0.0.0/2 (1 row) select '128.0.0.0/1'::ip4r; ip4r ------------- 128.0.0.0/1 (1 row) select '0.0.0.0/0'::ip4r; ip4r ----------- 0.0.0.0/0 (1 row) select '1.2.3.4-5.6.7.8'::ip4r; ip4r ----------------- 1.2.3.4-5.6.7.8 (1 row) select '5.6.7.8-1.2.3.4'::ip4r; ip4r ----------------- 1.2.3.4-5.6.7.8 (1 row) select '1.2.3.4-1.2.3.4'::ip4r; ip4r --------- 1.2.3.4 (1 row) -- invalid ip4r select '1.2.3'::ip4r; ERROR: invalid IP4R value: "1.2.3" at character 8 select '255.255.255.255.255.255.255.255.255'::ip4r; ERROR: invalid IP4R value: "255.255.255.255.255.255.255.255.255" at character 8 select '255.255.255.255.255-255.255.255.255.255'::ip4r; ERROR: invalid IP4R value: "255.255.255.255.255-255.255.255.255.255" at character 8 select '255.255.255.255-1.2.3.4.5'::ip4r; ERROR: invalid IP4R value: "255.255.255.255-1.2.3.4.5" at character 8 select '255.255.255.255-1.2.3'::ip4r; ERROR: invalid IP4R value: "255.255.255.255-1.2.3" at character 8 select '0.0.0.1/31'::ip4r; ERROR: invalid IP4R value: "0.0.0.1/31" at character 8 select '0.0.0.1/30'::ip4r; ERROR: invalid IP4R value: "0.0.0.1/30" at character 8 select '0.0.0.1/29'::ip4r; ERROR: invalid IP4R value: "0.0.0.1/29" at character 8 select '0.0.0.1/28'::ip4r; ERROR: invalid IP4R value: "0.0.0.1/28" at character 8 select '0.0.0.1/27'::ip4r; ERROR: invalid IP4R value: "0.0.0.1/27" at character 8 select '0.0.0.1/26'::ip4r; ERROR: invalid IP4R value: "0.0.0.1/26" at character 8 select '0.0.0.1/25'::ip4r; ERROR: invalid IP4R value: "0.0.0.1/25" at character 8 select '0.0.0.1/24'::ip4r; ERROR: invalid IP4R value: "0.0.0.1/24" at character 8 select '0.0.0.1/23'::ip4r; ERROR: invalid IP4R value: "0.0.0.1/23" at character 8 select '0.0.0.1/22'::ip4r; ERROR: invalid IP4R value: "0.0.0.1/22" at character 8 select '0.0.0.1/21'::ip4r; ERROR: invalid IP4R value: "0.0.0.1/21" at character 8 select '0.0.0.1/20'::ip4r; ERROR: invalid IP4R value: "0.0.0.1/20" at character 8 select '0.0.0.1/19'::ip4r; ERROR: invalid IP4R value: "0.0.0.1/19" at character 8 select '0.0.0.1/18'::ip4r; ERROR: invalid IP4R value: "0.0.0.1/18" at character 8 select '0.0.0.1/17'::ip4r; ERROR: invalid IP4R value: "0.0.0.1/17" at character 8 select '0.0.0.1/16'::ip4r; ERROR: invalid IP4R value: "0.0.0.1/16" at character 8 select '0.0.0.1/15'::ip4r; ERROR: invalid IP4R value: "0.0.0.1/15" at character 8 select '0.0.0.1/14'::ip4r; ERROR: invalid IP4R value: "0.0.0.1/14" at character 8 select '0.0.0.1/13'::ip4r; ERROR: invalid IP4R value: "0.0.0.1/13" at character 8 select '0.0.0.1/12'::ip4r; ERROR: invalid IP4R value: "0.0.0.1/12" at character 8 select '0.0.0.1/11'::ip4r; ERROR: invalid IP4R value: "0.0.0.1/11" at character 8 select '0.0.0.1/10'::ip4r; ERROR: invalid IP4R value: "0.0.0.1/10" at character 8 select '0.0.0.1/9'::ip4r; ERROR: invalid IP4R value: "0.0.0.1/9" at character 8 select '0.0.0.1/8'::ip4r; ERROR: invalid IP4R value: "0.0.0.1/8" at character 8 select '0.0.0.1/7'::ip4r; ERROR: invalid IP4R value: "0.0.0.1/7" at character 8 select '0.0.0.1/6'::ip4r; ERROR: invalid IP4R value: "0.0.0.1/6" at character 8 select '0.0.0.1/5'::ip4r; ERROR: invalid IP4R value: "0.0.0.1/5" at character 8 select '0.0.0.1/4'::ip4r; ERROR: invalid IP4R value: "0.0.0.1/4" at character 8 select '0.0.0.1/3'::ip4r; ERROR: invalid IP4R value: "0.0.0.1/3" at character 8 select '0.0.0.1/2'::ip4r; ERROR: invalid IP4R value: "0.0.0.1/2" at character 8 select '0.0.0.1/1'::ip4r; ERROR: invalid IP4R value: "0.0.0.1/1" at character 8 select '0.0.0.1/0'::ip4r; ERROR: invalid IP4R value: "0.0.0.1/0" at character 8 select '0.0.0.2/30'::ip4r; ERROR: invalid IP4R value: "0.0.0.2/30" at character 8 select '0.0.0.4/29'::ip4r; ERROR: invalid IP4R value: "0.0.0.4/29" at character 8 select '0.0.0.8/28'::ip4r; ERROR: invalid IP4R value: "0.0.0.8/28" at character 8 select '0.0.0.16/27'::ip4r; ERROR: invalid IP4R value: "0.0.0.16/27" at character 8 select '0.0.0.32/26'::ip4r; ERROR: invalid IP4R value: "0.0.0.32/26" at character 8 select '0.0.0.64/25'::ip4r; ERROR: invalid IP4R value: "0.0.0.64/25" at character 8 select '0.0.0.128/24'::ip4r; ERROR: invalid IP4R value: "0.0.0.128/24" at character 8 select '0.0.1.0/23'::ip4r; ERROR: invalid IP4R value: "0.0.1.0/23" at character 8 select '0.0.2.0/22'::ip4r; ERROR: invalid IP4R value: "0.0.2.0/22" at character 8 select '0.0.4.0/21'::ip4r; ERROR: invalid IP4R value: "0.0.4.0/21" at character 8 select '0.0.8.0/20'::ip4r; ERROR: invalid IP4R value: "0.0.8.0/20" at character 8 select '0.0.16.0/19'::ip4r; ERROR: invalid IP4R value: "0.0.16.0/19" at character 8 select '0.0.32.0/18'::ip4r; ERROR: invalid IP4R value: "0.0.32.0/18" at character 8 select '0.0.64.0/17'::ip4r; ERROR: invalid IP4R value: "0.0.64.0/17" at character 8 select '0.0.128.0/16'::ip4r; ERROR: invalid IP4R value: "0.0.128.0/16" at character 8 select '0.1.0.0/15'::ip4r; ERROR: invalid IP4R value: "0.1.0.0/15" at character 8 select '0.2.0.0/14'::ip4r; ERROR: invalid IP4R value: "0.2.0.0/14" at character 8 select '0.4.0.0/13'::ip4r; ERROR: invalid IP4R value: "0.4.0.0/13" at character 8 select '0.8.0.0/12'::ip4r; ERROR: invalid IP4R value: "0.8.0.0/12" at character 8 select '0.16.0.0/11'::ip4r; ERROR: invalid IP4R value: "0.16.0.0/11" at character 8 select '0.32.0.0/10'::ip4r; ERROR: invalid IP4R value: "0.32.0.0/10" at character 8 select '0.64.0.0/9'::ip4r; ERROR: invalid IP4R value: "0.64.0.0/9" at character 8 select '0.128.0.0/8'::ip4r; ERROR: invalid IP4R value: "0.128.0.0/8" at character 8 select '1.0.0.0/7'::ip4r; ERROR: invalid IP4R value: "1.0.0.0/7" at character 8 select '2.0.0.0/6'::ip4r; ERROR: invalid IP4R value: "2.0.0.0/6" at character 8 select '4.0.0.0/5'::ip4r; ERROR: invalid IP4R value: "4.0.0.0/5" at character 8 select '8.0.0.0/4'::ip4r; ERROR: invalid IP4R value: "8.0.0.0/4" at character 8 select '16.0.0.0/3'::ip4r; ERROR: invalid IP4R value: "16.0.0.0/3" at character 8 select '32.0.0.0/2'::ip4r; ERROR: invalid IP4R value: "32.0.0.0/2" at character 8 select '64.0.0.0/1'::ip4r; ERROR: invalid IP4R value: "64.0.0.0/1" at character 8 select '128.0.0.0/0'::ip4r; ERROR: invalid IP4R value: "128.0.0.0/0" at character 8 select '0.0.0.0/33'::ip4r; ERROR: invalid IP4R value: "0.0.0.0/33" at character 8 select '0.0.0.0/3.0'::ip4r; ERROR: invalid IP4R value: "0.0.0.0/3.0" at character 8 select '0.0.0.0/+33'::ip4r; ERROR: invalid IP4R value: "0.0.0.0/+33" at character 8 -- valid ip6r select '::'::ip6r; ip6r ------ :: (1 row) select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'::ip6r; ip6r ----------------------------------------- ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff (1 row) select '1::2'::ip6r; ip6r ------ 1::2 (1 row) select '::-ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'::ip6r; ip6r ------ ::/0 (1 row) select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff-::'::ip6r; ip6r ------ ::/0 (1 row) select '1::2-3::4'::ip6r; ip6r ----------- 1::2-3::4 (1 row) select '3::4-3::4'::ip6r; ip6r ------ 3::4 (1 row) select '3::4-1::2'::ip6r; ip6r ----------- 1::2-3::4 (1 row) select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128'::ip6r; ip6r ----------------------------------------- ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff (1 row) select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffe/127'::ip6r; ip6r --------------------------------------------- ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffe/127 (1 row) select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffc/126'::ip6r; ip6r --------------------------------------------- ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffc/126 (1 row) select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:fff8/125'::ip6r; ip6r --------------------------------------------- ffff:ffff:ffff:ffff:ffff:ffff:ffff:fff8/125 (1 row) select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:fff0/124'::ip6r; ip6r --------------------------------------------- ffff:ffff:ffff:ffff:ffff:ffff:ffff:fff0/124 (1 row) select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ff00/120'::ip6r; ip6r --------------------------------------------- ffff:ffff:ffff:ffff:ffff:ffff:ffff:ff00/120 (1 row) select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:f000/116'::ip6r; ip6r --------------------------------------------- ffff:ffff:ffff:ffff:ffff:ffff:ffff:f000/116 (1 row) select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:0000/112'::ip6r; ip6r ------------------------------------------ ffff:ffff:ffff:ffff:ffff:ffff:ffff:0/112 (1 row) select 'ffff:ffff:ffff:ffff:ffff:ffff:0000:0000/96'::ip6r; ip6r ------------------------------------ ffff:ffff:ffff:ffff:ffff:ffff::/96 (1 row) select 'ffff:ffff:ffff:ffff:ffff:0000:0000:0000/80'::ip6r; ip6r ------------------------------- ffff:ffff:ffff:ffff:ffff::/80 (1 row) select 'ffff:ffff:ffff:ffff:fff0:0000:0000:0000/76'::ip6r; ip6r ------------------------------- ffff:ffff:ffff:ffff:fff0::/76 (1 row) select 'ffff:ffff:ffff:ffff:ff00:0000:0000:0000/72'::ip6r; ip6r ------------------------------- ffff:ffff:ffff:ffff:ff00::/72 (1 row) select 'ffff:ffff:ffff:ffff:f000:0000:0000:0000/68'::ip6r; ip6r ------------------------------- ffff:ffff:ffff:ffff:f000::/68 (1 row) select 'ffff:ffff:ffff:ffff:e000:0000:0000:0000/67'::ip6r; ip6r ------------------------------- ffff:ffff:ffff:ffff:e000::/67 (1 row) select 'ffff:ffff:ffff:ffff:c000:0000:0000:0000/66'::ip6r; ip6r ------------------------------- ffff:ffff:ffff:ffff:c000::/66 (1 row) select 'ffff:ffff:ffff:ffff:8000:0000:0000:0000/65'::ip6r; ip6r ------------------------------- ffff:ffff:ffff:ffff:8000::/65 (1 row) select 'ffff:ffff:ffff:ffff:0000:0000:0000:0000/64'::ip6r; ip6r -------------------------- ffff:ffff:ffff:ffff::/64 (1 row) select 'ffff:ffff:ffff:fffe:0000:0000:0000:0000/63'::ip6r; ip6r -------------------------- ffff:ffff:ffff:fffe::/63 (1 row) select 'ffff:ffff:ffff:fffc:0000:0000:0000:0000/62'::ip6r; ip6r -------------------------- ffff:ffff:ffff:fffc::/62 (1 row) select 'ffff:ffff:ffff:fff8:0000:0000:0000:0000/61'::ip6r; ip6r -------------------------- ffff:ffff:ffff:fff8::/61 (1 row) select 'ffff:ffff:ffff:fff0:0000:0000:0000:0000/60'::ip6r; ip6r -------------------------- ffff:ffff:ffff:fff0::/60 (1 row) select 'ffff:ffff:ffff:ff00:0000:0000:0000:0000/56'::ip6r; ip6r -------------------------- ffff:ffff:ffff:ff00::/56 (1 row) select 'ffff:ffff:ffff:f000:0000:0000:0000:0000/52'::ip6r; ip6r -------------------------- ffff:ffff:ffff:f000::/52 (1 row) select 'ffff:ffff:ffff:0000:0000:0000:0000:0000/48'::ip6r; ip6r --------------------- ffff:ffff:ffff::/48 (1 row) select 'ffff:ffff:0000:0000:0000:0000:0000:0000/32'::ip6r; ip6r ---------------- ffff:ffff::/32 (1 row) select 'ffff:0000:0000:0000:0000:0000:0000:0000/16'::ip6r; ip6r ----------- ffff::/16 (1 row) select 'fff0:0000:0000:0000:0000:0000:0000:0000/12'::ip6r; ip6r ----------- fff0::/12 (1 row) select 'ff00:0000:0000:0000:0000:0000:0000:0000/8'::ip6r; ip6r ---------- ff00::/8 (1 row) select 'f000:0000:0000:0000:0000:0000:0000:0000/4'::ip6r; ip6r ---------- f000::/4 (1 row) select 'e000:0000:0000:0000:0000:0000:0000:0000/3'::ip6r; ip6r ---------- e000::/3 (1 row) select 'c000:0000:0000:0000:0000:0000:0000:0000/2'::ip6r; ip6r ---------- c000::/2 (1 row) select '8000:0000:0000:0000:0000:0000:0000:0000/1'::ip6r; ip6r ---------- 8000::/1 (1 row) select '0000:0000:0000:0000:0000:0000:0000:0000/0'::ip6r; ip6r ------ ::/0 (1 row) -- invalid ip6r select '::-::-::'::ip6r; ERROR: invalid IP6R value: "::-::-::" at character 8 select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff-ffff'::ip6r; ERROR: invalid IP6R value: "ffff:ffff:ffff:ffff:ffff:ffff:ffff-ffff" at character 8 select '::-ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'::ip6r; ERROR: invalid IP6R value: "::-ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff" at character 8 select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff-::'::ip6r; ERROR: invalid IP6R value: "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff-::" at character 8 select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128'::ip6r; ERROR: invalid IP6R value: "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128" at character 8 select '0000:0000:0000:0000:0000:0000:0000:0001/127'::ip6r; ERROR: invalid IP6R value: "0000:0000:0000:0000:0000:0000:0000:0001/127" at character 8 select '0000:0000:0000:0000:0000:0000:0000:0001/120'::ip6r; ERROR: invalid IP6R value: "0000:0000:0000:0000:0000:0000:0000:0001/120" at character 8 select '0000:0000:0000:0000:0000:0000:0000:0001/112'::ip6r; ERROR: invalid IP6R value: "0000:0000:0000:0000:0000:0000:0000:0001/112" at character 8 select '0000:0000:0000:0000:0000:0000:0000:0001/96'::ip6r; ERROR: invalid IP6R value: "0000:0000:0000:0000:0000:0000:0000:0001/96" at character 8 select '0000:0000:0000:0000:0000:0000:0000:0001/80'::ip6r; ERROR: invalid IP6R value: "0000:0000:0000:0000:0000:0000:0000:0001/80" at character 8 select '0000:0000:0000:0000:0000:0000:0000:0001/64'::ip6r; ERROR: invalid IP6R value: "0000:0000:0000:0000:0000:0000:0000:0001/64" at character 8 select '0000:0000:0000:0000:0000:0000:0000:0001/48'::ip6r; ERROR: invalid IP6R value: "0000:0000:0000:0000:0000:0000:0000:0001/48" at character 8 select '0000:0000:0000:0000:0000:0000:0000:0001/32'::ip6r; ERROR: invalid IP6R value: "0000:0000:0000:0000:0000:0000:0000:0001/32" at character 8 select '0000:0000:0000:0000:0000:0000:0000:0001/16'::ip6r; ERROR: invalid IP6R value: "0000:0000:0000:0000:0000:0000:0000:0001/16" at character 8 select '0000:0000:0000:0000:0000:0000:0000:0001/8'::ip6r; ERROR: invalid IP6R value: "0000:0000:0000:0000:0000:0000:0000:0001/8" at character 8 select '0000:0000:0000:0000:0000:0000:0000:0001/4'::ip6r; ERROR: invalid IP6R value: "0000:0000:0000:0000:0000:0000:0000:0001/4" at character 8 select '0000:0000:0000:0000:0000:0000:0000:0001/0'::ip6r; ERROR: invalid IP6R value: "0000:0000:0000:0000:0000:0000:0000:0001/0" at character 8 select '0000:0000:0000:0000:0000:0000:0000:0008/124'::ip6r; ERROR: invalid IP6R value: "0000:0000:0000:0000:0000:0000:0000:0008/124" at character 8 select '0000:0000:0000:0000:0000:0000:0000:0080/120'::ip6r; ERROR: invalid IP6R value: "0000:0000:0000:0000:0000:0000:0000:0080/120" at character 8 select '0000:0000:0000:0000:0000:0000:0000:8000/112'::ip6r; ERROR: invalid IP6R value: "0000:0000:0000:0000:0000:0000:0000:8000/112" at character 8 select '0000:0000:0000:0000:0000:0000:8000:0000/96'::ip6r; ERROR: invalid IP6R value: "0000:0000:0000:0000:0000:0000:8000:0000/96" at character 8 select '0000:0000:0000:0000:0000:8000:0000:0000/80'::ip6r; ERROR: invalid IP6R value: "0000:0000:0000:0000:0000:8000:0000:0000/80" at character 8 select '0000:0000:0000:0000:8000:0000:0000:0000/64'::ip6r; ERROR: invalid IP6R value: "0000:0000:0000:0000:8000:0000:0000:0000/64" at character 8 select '0000:0000:0000:8000:0000:0000:0000:0000/48'::ip6r; ERROR: invalid IP6R value: "0000:0000:0000:8000:0000:0000:0000:0000/48" at character 8 select '0000:0000:8000:0000:0000:0000:0000:0000/32'::ip6r; ERROR: invalid IP6R value: "0000:0000:8000:0000:0000:0000:0000:0000/32" at character 8 select '0000:8000:0000:0000:0000:0000:0000:0000/16'::ip6r; ERROR: invalid IP6R value: "0000:8000:0000:0000:0000:0000:0000:0000/16" at character 8 select '0080:0000:0000:0000:0000:0000:0000:0000/8'::ip6r; ERROR: invalid IP6R value: "0080:0000:0000:0000:0000:0000:0000:0000/8" at character 8 select '0800:0000:0000:0000:0000:0000:0000:0000/4'::ip6r; ERROR: invalid IP6R value: "0800:0000:0000:0000:0000:0000:0000:0000/4" at character 8 select '8000:0000:0000:0000:0000:0000:0000:0000/0'::ip6r; ERROR: invalid IP6R value: "8000:0000:0000:0000:0000:0000:0000:0000/0" at character 8 select '::/129'::ip6r; ERROR: invalid IP6R value: "::/129" at character 8 select '::/255'::ip6r; ERROR: invalid IP6R value: "::/255" at character 8 select '::/256'::ip6r; ERROR: invalid IP6R value: "::/256" at character 8 select '::/+0'::ip6r; ERROR: invalid IP6R value: "::/+0" at character 8 select '::/0-0'::ip6r; ERROR: invalid IP6R value: "::/0-0" at character 8 select '::-::/0'::ip6r; ERROR: invalid IP6R value: "::-::/0" at character 8 -- valid ipaddress select a, family(a) from (select '1.2.3.4'::ipaddress as a) s1; a | family ---------+-------- 1.2.3.4 | 4 (1 row) select a, family(a) from (select '0.0.0.0'::ipaddress as a) s1; a | family ---------+-------- 0.0.0.0 | 4 (1 row) select a, family(a) from (select '255.255.255.255'::ipaddress as a) s1; a | family -----------------+-------- 255.255.255.255 | 4 (1 row) select a, family(a) from (select '0.0.0.255'::ipaddress as a) s1; a | family -----------+-------- 0.0.0.255 | 4 (1 row) select a, family(a) from (select '0.0.255.0'::ipaddress as a) s1; a | family -----------+-------- 0.0.255.0 | 4 (1 row) select a, family(a) from (select '0.255.0.0'::ipaddress as a) s1; a | family -----------+-------- 0.255.0.0 | 4 (1 row) select a, family(a) from (select '255.0.0.0'::ipaddress as a) s1; a | family -----------+-------- 255.0.0.0 | 4 (1 row) select a, family(a) from (select '192.168.123.210'::ipaddress as a) s1; a | family -----------------+-------- 192.168.123.210 | 4 (1 row) select a, family(a) from (select '127.0.0.1'::ipaddress as a) s1; a | family -----------+-------- 127.0.0.1 | 4 (1 row) select a, family(a) from (select '0000:0000:0000:0000:0000:0000:0000:0000'::ipaddress as a) s1; a | family ----+-------- :: | 6 (1 row) select a, family(a) from (select '0000:0000:0000:0000:0000:0000:0000:0001'::ipaddress as a) s1; a | family -----+-------- ::1 | 6 (1 row) select a, family(a) from (select '0:0:0:0:0:0:0:0'::ipaddress as a) s1; a | family ----+-------- :: | 6 (1 row) select a, family(a) from (select '0:0:0:0:0:0:0:1'::ipaddress as a) s1; a | family -----+-------- ::1 | 6 (1 row) select a, family(a) from (select '0:0:0:0:0:0:13.1.68.3'::ipaddress as a) s1; a | family -------------+-------- ::13.1.68.3 | 6 (1 row) select a, family(a) from (select '0:0:0:0:0:FFFF:129.144.52.38'::ipaddress as a) s1; a | family ----------------------+-------- ::ffff:129.144.52.38 | 6 (1 row) select a, family(a) from (select '0::0'::ipaddress as a) s1; a | family ----+-------- :: | 6 (1 row) select a, family(a) from (select '1:2:3:4:5:6:1.2.3.4'::ipaddress as a) s1; a | family ---------------------+-------- 1:2:3:4:5:6:102:304 | 6 (1 row) select a, family(a) from (select '1:2:3:4:5:6:7:8'::ipaddress as a) s1; a | family -----------------+-------- 1:2:3:4:5:6:7:8 | 6 (1 row) select a, family(a) from (select '1:2:3:4:5:6::'::ipaddress as a) s1; a | family ---------------+-------- 1:2:3:4:5:6:: | 6 (1 row) select a, family(a) from (select '1:2:3:4:5:6::8'::ipaddress as a) s1; a | family -----------------+-------- 1:2:3:4:5:6:0:8 | 6 (1 row) select a, family(a) from (select '1:2:3:4:5::'::ipaddress as a) s1; a | family -------------+-------- 1:2:3:4:5:: | 6 (1 row) select a, family(a) from (select '1:2:3:4:5::1.2.3.4'::ipaddress as a) s1; a | family ---------------------+-------- 1:2:3:4:5:0:102:304 | 6 (1 row) select a, family(a) from (select '1:2:3:4:5::7:8'::ipaddress as a) s1; a | family -----------------+-------- 1:2:3:4:5:0:7:8 | 6 (1 row) select a, family(a) from (select '1:2:3:4:5::8'::ipaddress as a) s1; a | family --------------+-------- 1:2:3:4:5::8 | 6 (1 row) select a, family(a) from (select '1:2:3:4::'::ipaddress as a) s1; a | family -----------+-------- 1:2:3:4:: | 6 (1 row) select a, family(a) from (select '1:2:3:4::1.2.3.4'::ipaddress as a) s1; a | family ------------------+-------- 1:2:3:4::102:304 | 6 (1 row) select a, family(a) from (select '1:2:3:4::5:1.2.3.4'::ipaddress as a) s1; a | family ---------------------+-------- 1:2:3:4:0:5:102:304 | 6 (1 row) select a, family(a) from (select '1:2:3:4::7:8'::ipaddress as a) s1; a | family --------------+-------- 1:2:3:4::7:8 | 6 (1 row) select a, family(a) from (select '1:2:3:4::8'::ipaddress as a) s1; a | family ------------+-------- 1:2:3:4::8 | 6 (1 row) select a, family(a) from (select '1:2:3::'::ipaddress as a) s1; a | family ---------+-------- 1:2:3:: | 6 (1 row) select a, family(a) from (select '1:2:3::1.2.3.4'::ipaddress as a) s1; a | family ----------------+-------- 1:2:3::102:304 | 6 (1 row) select a, family(a) from (select '1:2:3::5:1.2.3.4'::ipaddress as a) s1; a | family ------------------+-------- 1:2:3::5:102:304 | 6 (1 row) select a, family(a) from (select '1:2:3::7:8'::ipaddress as a) s1; a | family ------------+-------- 1:2:3::7:8 | 6 (1 row) select a, family(a) from (select '1:2:3::8'::ipaddress as a) s1; a | family ----------+-------- 1:2:3::8 | 6 (1 row) select a, family(a) from (select '1:2::'::ipaddress as a) s1; a | family -------+-------- 1:2:: | 6 (1 row) select a, family(a) from (select '1:2::1.2.3.4'::ipaddress as a) s1; a | family --------------+-------- 1:2::102:304 | 6 (1 row) select a, family(a) from (select '1:2::5:1.2.3.4'::ipaddress as a) s1; a | family ----------------+-------- 1:2::5:102:304 | 6 (1 row) select a, family(a) from (select '1:2::7:8'::ipaddress as a) s1; a | family ----------+-------- 1:2::7:8 | 6 (1 row) select a, family(a) from (select '1:2::8'::ipaddress as a) s1; a | family --------+-------- 1:2::8 | 6 (1 row) select a, family(a) from (select '1::'::ipaddress as a) s1; a | family -----+-------- 1:: | 6 (1 row) select a, family(a) from (select '1::1.2.3.4'::ipaddress as a) s1; a | family ------------+-------- 1::102:304 | 6 (1 row) select a, family(a) from (select '1::2:3'::ipaddress as a) s1; a | family --------+-------- 1::2:3 | 6 (1 row) select a, family(a) from (select '1::2:3:4'::ipaddress as a) s1; a | family ----------+-------- 1::2:3:4 | 6 (1 row) select a, family(a) from (select '1::2:3:4:5'::ipaddress as a) s1; a | family ------------+-------- 1::2:3:4:5 | 6 (1 row) select a, family(a) from (select '1::2:3:4:5:6'::ipaddress as a) s1; a | family --------------+-------- 1::2:3:4:5:6 | 6 (1 row) select a, family(a) from (select '1::2:3:4:5:6:7'::ipaddress as a) s1; a | family -----------------+-------- 1:0:2:3:4:5:6:7 | 6 (1 row) select a, family(a) from (select '1::5:1.2.3.4'::ipaddress as a) s1; a | family --------------+-------- 1::5:102:304 | 6 (1 row) select a, family(a) from (select '1::5:11.22.33.44'::ipaddress as a) s1; a | family ---------------+-------- 1::5:b16:212c | 6 (1 row) select a, family(a) from (select '1::7:8'::ipaddress as a) s1; a | family --------+-------- 1::7:8 | 6 (1 row) select a, family(a) from (select '1::8'::ipaddress as a) s1; a | family ------+-------- 1::8 | 6 (1 row) select a, family(a) from (select '2001:0000:1234:0000:0000:C1C0:ABCD:0876'::ipaddress as a) s1; a | family ----------------------------+-------- 2001:0:1234::c1c0:abcd:876 | 6 (1 row) select a, family(a) from (select '2001:0db8:0000:0000:0000:0000:1428:57ab'::ipaddress as a) s1; a | family ---------------------+-------- 2001:db8::1428:57ab | 6 (1 row) select a, family(a) from (select '2001:0db8:0000:0000:0000::1428:57ab'::ipaddress as a) s1; a | family ---------------------+-------- 2001:db8::1428:57ab | 6 (1 row) select a, family(a) from (select '2001:0db8:0:0:0:0:1428:57ab'::ipaddress as a) s1; a | family ---------------------+-------- 2001:db8::1428:57ab | 6 (1 row) select a, family(a) from (select '2001:0db8:0:0::1428:57ab'::ipaddress as a) s1; a | family ---------------------+-------- 2001:db8::1428:57ab | 6 (1 row) select a, family(a) from (select '2001:0db8:1234:0000:0000:0000:0000:0000'::ipaddress as a) s1; a | family -----------------+-------- 2001:db8:1234:: | 6 (1 row) select a, family(a) from (select '2001:0db8:1234::'::ipaddress as a) s1; a | family -----------------+-------- 2001:db8:1234:: | 6 (1 row) select a, family(a) from (select '2001:0db8:1234:ffff:ffff:ffff:ffff:ffff'::ipaddress as a) s1; a | family ----------------------------------------+-------- 2001:db8:1234:ffff:ffff:ffff:ffff:ffff | 6 (1 row) select a, family(a) from (select '2001:0db8:85a3:0000:0000:8a2e:0370:7334'::ipaddress as a) s1; a | family ------------------------------+-------- 2001:db8:85a3::8a2e:370:7334 | 6 (1 row) select a, family(a) from (select '2001:0db8::1428:57ab'::ipaddress as a) s1; a | family ---------------------+-------- 2001:db8::1428:57ab | 6 (1 row) select a, family(a) from (select '2001:10::'::ipaddress as a) s1; a | family -----------+-------- 2001:10:: | 6 (1 row) select a, family(a) from (select '2001::'::ipaddress as a) s1; a | family --------+-------- 2001:: | 6 (1 row) select a, family(a) from (select '2001:DB8:0:0:8:800:200C:417A'::ipaddress as a) s1; a | family ---------------------------+-------- 2001:db8::8:800:200c:417a | 6 (1 row) select a, family(a) from (select '2001:DB8::8:800:200C:417A'::ipaddress as a) s1; a | family ---------------------------+-------- 2001:db8::8:800:200c:417a | 6 (1 row) select a, family(a) from (select '2001:db8:85a3:0:0:8a2e:370:7334'::ipaddress as a) s1; a | family ------------------------------+-------- 2001:db8:85a3::8a2e:370:7334 | 6 (1 row) select a, family(a) from (select '2001:db8:85a3::8a2e:370:7334'::ipaddress as a) s1; a | family ------------------------------+-------- 2001:db8:85a3::8a2e:370:7334 | 6 (1 row) select a, family(a) from (select '2001:db8::'::ipaddress as a) s1; a | family ------------+-------- 2001:db8:: | 6 (1 row) select a, family(a) from (select '2001:db8::'::ipaddress as a) s1; a | family ------------+-------- 2001:db8:: | 6 (1 row) select a, family(a) from (select '2001:db8::1428:57ab'::ipaddress as a) s1; a | family ---------------------+-------- 2001:db8::1428:57ab | 6 (1 row) select a, family(a) from (select '2001:db8:a::123'::ipaddress as a) s1; a | family -----------------+-------- 2001:db8:a::123 | 6 (1 row) select a, family(a) from (select '2002::'::ipaddress as a) s1; a | family --------+-------- 2002:: | 6 (1 row) select a, family(a) from (select '2::10'::ipaddress as a) s1; a | family -------+-------- 2::10 | 6 (1 row) select a, family(a) from (select '3ffe:0b00:0000:0000:0001:0000:0000:000a'::ipaddress as a) s1; a | family -------------------+-------- 3ffe:b00::1:0:0:a | 6 (1 row) select a, family(a) from (select '::'::ipaddress as a) s1; a | family ----+-------- :: | 6 (1 row) select a, family(a) from (select '::1'::ipaddress as a) s1; a | family -----+-------- ::1 | 6 (1 row) select a, family(a) from (select '::127.0.0.1'::ipaddress as a) s1; a | family -------------+-------- ::127.0.0.1 | 6 (1 row) select a, family(a) from (select '::13.1.68.3'::ipaddress as a) s1; a | family -------------+-------- ::13.1.68.3 | 6 (1 row) select a, family(a) from (select '::2:3'::ipaddress as a) s1; a | family -----------+-------- ::0.2.0.3 | 6 (1 row) select a, family(a) from (select '::2:3:4'::ipaddress as a) s1; a | family ---------+-------- ::2:3:4 | 6 (1 row) select a, family(a) from (select '::2:3:4:5'::ipaddress as a) s1; a | family -----------+-------- ::2:3:4:5 | 6 (1 row) select a, family(a) from (select '::2:3:4:5:6'::ipaddress as a) s1; a | family -------------+-------- ::2:3:4:5:6 | 6 (1 row) select a, family(a) from (select '::2:3:4:5:6:7'::ipaddress as a) s1; a | family ---------------+-------- ::2:3:4:5:6:7 | 6 (1 row) select a, family(a) from (select '::2:3:4:5:6:7:8'::ipaddress as a) s1; a | family -----------------+-------- 0:2:3:4:5:6:7:8 | 6 (1 row) select a, family(a) from (select '::8'::ipaddress as a) s1; a | family -----+-------- ::8 | 6 (1 row) select a, family(a) from (select '::FFFF:129.144.52.38'::ipaddress as a) s1; a | family ----------------------+-------- ::ffff:129.144.52.38 | 6 (1 row) select a, family(a) from (select '::ffff:0:0'::ipaddress as a) s1; a | family ----------------+-------- ::ffff:0.0.0.0 | 6 (1 row) select a, family(a) from (select '::ffff:0:192.168.1.1'::ipaddress as a) s1; a | family ----------------------+-------- ::ffff:0:192.168.1.1 | 6 (1 row) select a, family(a) from (select '::ffff:1:1.2.3.4'::ipaddress as a) s1; a | family ------------------+-------- ::ffff:1:102:304 | 6 (1 row) select a, family(a) from (select '::ffff:0c22:384e'::ipaddress as a) s1; a | family --------------------+-------- ::ffff:12.34.56.78 | 6 (1 row) select a, family(a) from (select '::ffff:12.34.56.78'::ipaddress as a) s1; a | family --------------------+-------- ::ffff:12.34.56.78 | 6 (1 row) select a, family(a) from (select '::ffff:192.0.2.128'::ipaddress as a) s1; a | family --------------------+-------- ::ffff:192.0.2.128 | 6 (1 row) select a, family(a) from (select '::ffff:192.168.1.1'::ipaddress as a) s1; a | family --------------------+-------- ::ffff:192.168.1.1 | 6 (1 row) select a, family(a) from (select '::ffff:192.168.1.26'::ipaddress as a) s1; a | family ---------------------+-------- ::ffff:192.168.1.26 | 6 (1 row) select a, family(a) from (select '::ffff:c000:280'::ipaddress as a) s1; a | family --------------------+-------- ::ffff:192.0.2.128 | 6 (1 row) select a, family(a) from (select 'FF01:0:0:0:0:0:0:101'::ipaddress as a) s1; a | family -----------+-------- ff01::101 | 6 (1 row) select a, family(a) from (select 'FF01::101'::ipaddress as a) s1; a | family -----------+-------- ff01::101 | 6 (1 row) select a, family(a) from (select 'FF02:0000:0000:0000:0000:0000:0000:0001'::ipaddress as a) s1; a | family ---------+-------- ff02::1 | 6 (1 row) select a, family(a) from (select 'fc00::'::ipaddress as a) s1; a | family --------+-------- fc00:: | 6 (1 row) select a, family(a) from (select 'fe80:0000:0000:0000:0204:61ff:fe9d:f156'::ipaddress as a) s1; a | family --------------------------+-------- fe80::204:61ff:fe9d:f156 | 6 (1 row) select a, family(a) from (select 'fe80:0:0:0:204:61ff:254.157.241.86'::ipaddress as a) s1; a | family --------------------------+-------- fe80::204:61ff:fe9d:f156 | 6 (1 row) select a, family(a) from (select 'fe80:0:0:0:204:61ff:fe9d:f156'::ipaddress as a) s1; a | family --------------------------+-------- fe80::204:61ff:fe9d:f156 | 6 (1 row) select a, family(a) from (select 'fe80::'::ipaddress as a) s1; a | family --------+-------- fe80:: | 6 (1 row) select a, family(a) from (select 'fe80::1'::ipaddress as a) s1; a | family ---------+-------- fe80::1 | 6 (1 row) select a, family(a) from (select 'fe80::204:61ff:254.157.241.86'::ipaddress as a) s1; a | family --------------------------+-------- fe80::204:61ff:fe9d:f156 | 6 (1 row) select a, family(a) from (select 'fe80::204:61ff:fe9d:f156'::ipaddress as a) s1; a | family --------------------------+-------- fe80::204:61ff:fe9d:f156 | 6 (1 row) select a, family(a) from (select 'fe80::217:f2ff:254.7.237.98'::ipaddress as a) s1; a | family --------------------------+-------- fe80::217:f2ff:fe07:ed62 | 6 (1 row) select a, family(a) from (select 'fe80::217:f2ff:fe07:ed62'::ipaddress as a) s1; a | family --------------------------+-------- fe80::217:f2ff:fe07:ed62 | 6 (1 row) select a, family(a) from (select 'ff02::1'::ipaddress as a) s1; a | family ---------+-------- ff02::1 | 6 (1 row) -- invalid ipaddress select '1.2.3'::ipaddress; ERROR: invalid IP value: '1.2.3' at character 8 select '0'::ipaddress; ERROR: invalid IP value: '0' at character 8 select ' 1.2.3.4'::ipaddress; ERROR: invalid IP value: ' 1.2.3.4' at character 8 select '1.2.3.4 '::ipaddress; ERROR: invalid IP value: '1.2.3.4 ' at character 8 select '0.0.0.256'::ipaddress; ERROR: invalid IP value: '0.0.0.256' at character 8 select '0.0.256'::ipaddress; ERROR: invalid IP value: '0.0.256' at character 8 select '0..255.0'::ipaddress; ERROR: invalid IP value: '0..255.0' at character 8 select '+0.255.0.0'::ipaddress; ERROR: invalid IP value: '+0.255.0.0' at character 8 select '1.2.3.4-1.2.3.4'::ipaddress; ERROR: invalid IP value: '1.2.3.4-1.2.3.4' at character 8 select ''::ipaddress; ERROR: invalid IP value: '' at character 8 select '02001:0000:1234:0000:0000:C1C0:ABCD:0876'::ipaddress; ERROR: invalid IP value: '02001:0000:1234:0000:0000:C1C0:ABCD:0876' at character 8 select '1.2.3.4:1111:2222:3333:4444::5555'::ipaddress; ERROR: invalid IP value: '1.2.3.4:1111:2222:3333:4444::5555' at character 8 select '1.2.3.4:1111:2222:3333::5555'::ipaddress; ERROR: invalid IP value: '1.2.3.4:1111:2222:3333::5555' at character 8 select '1.2.3.4:1111:2222::5555'::ipaddress; ERROR: invalid IP value: '1.2.3.4:1111:2222::5555' at character 8 select '1.2.3.4:1111::5555'::ipaddress; ERROR: invalid IP value: '1.2.3.4:1111::5555' at character 8 select '1.2.3.4::'::ipaddress; ERROR: invalid IP value: '1.2.3.4::' at character 8 select '1.2.3.4::5555'::ipaddress; ERROR: invalid IP value: '1.2.3.4::5555' at character 8 select '1111:'::ipaddress; ERROR: invalid IP value: '1111:' at character 8 select '1111:2222:3333:4444::5555:'::ipaddress; ERROR: invalid IP value: '1111:2222:3333:4444::5555:' at character 8 select '1111:2222:3333::5555:'::ipaddress; ERROR: invalid IP value: '1111:2222:3333::5555:' at character 8 select '1111:2222::5555:'::ipaddress; ERROR: invalid IP value: '1111:2222::5555:' at character 8 select '1111::5555:'::ipaddress; ERROR: invalid IP value: '1111::5555:' at character 8 select '123'::ipaddress; ERROR: invalid IP value: '123' at character 8 select '12345::6:7:8'::ipaddress; ERROR: invalid IP value: '12345::6:7:8' at character 8 select '1:2:3:4:5:6:7:8:9'::ipaddress; ERROR: invalid IP value: '1:2:3:4:5:6:7:8:9' at character 8 select '1:2:3::4:5:6:7:8:9'::ipaddress; ERROR: invalid IP value: '1:2:3::4:5:6:7:8:9' at character 8 select '1:2:3::4:5::7:8'::ipaddress; ERROR: invalid IP value: '1:2:3::4:5::7:8' at character 8 select '1::1.2.256.4'::ipaddress; ERROR: invalid IP value: '1::1.2.256.4' at character 8 select '1::1.2.3.256'::ipaddress; ERROR: invalid IP value: '1::1.2.3.256' at character 8 select '1::1.2.3.300'::ipaddress; ERROR: invalid IP value: '1::1.2.3.300' at character 8 select '1::1.2.3.900'::ipaddress; ERROR: invalid IP value: '1::1.2.3.900' at character 8 select '1::1.2.300.4'::ipaddress; ERROR: invalid IP value: '1::1.2.300.4' at character 8 select '1::1.2.900.4'::ipaddress; ERROR: invalid IP value: '1::1.2.900.4' at character 8 select '1::1.256.3.4'::ipaddress; ERROR: invalid IP value: '1::1.256.3.4' at character 8 select '1::1.300.3.4'::ipaddress; ERROR: invalid IP value: '1::1.300.3.4' at character 8 select '1::1.900.3.4'::ipaddress; ERROR: invalid IP value: '1::1.900.3.4' at character 8 select '1::256.2.3.4'::ipaddress; ERROR: invalid IP value: '1::256.2.3.4' at character 8 select '1::260.2.3.4'::ipaddress; ERROR: invalid IP value: '1::260.2.3.4' at character 8 select '1::2::3'::ipaddress; ERROR: invalid IP value: '1::2::3' at character 8 select '1::300.2.3.4'::ipaddress; ERROR: invalid IP value: '1::300.2.3.4' at character 8 select '1::300.300.300.300'::ipaddress; ERROR: invalid IP value: '1::300.300.300.300' at character 8 select '1::3000.30.30.30'::ipaddress; ERROR: invalid IP value: '1::3000.30.30.30' at character 8 select '1::400.2.3.4'::ipaddress; ERROR: invalid IP value: '1::400.2.3.4' at character 8 select '1::5:1.2.256.4'::ipaddress; ERROR: invalid IP value: '1::5:1.2.256.4' at character 8 select '1::5:1.2.3.256'::ipaddress; ERROR: invalid IP value: '1::5:1.2.3.256' at character 8 select '1::5:1.2.3.300'::ipaddress; ERROR: invalid IP value: '1::5:1.2.3.300' at character 8 select '1::5:1.2.3.900'::ipaddress; ERROR: invalid IP value: '1::5:1.2.3.900' at character 8 select '1::5:1.2.300.4'::ipaddress; ERROR: invalid IP value: '1::5:1.2.300.4' at character 8 select '1::5:1.2.900.4'::ipaddress; ERROR: invalid IP value: '1::5:1.2.900.4' at character 8 select '1::5:1.256.3.4'::ipaddress; ERROR: invalid IP value: '1::5:1.256.3.4' at character 8 select '1::5:1.300.3.4'::ipaddress; ERROR: invalid IP value: '1::5:1.300.3.4' at character 8 select '1::5:1.900.3.4'::ipaddress; ERROR: invalid IP value: '1::5:1.900.3.4' at character 8 select '1::5:256.2.3.4'::ipaddress; ERROR: invalid IP value: '1::5:256.2.3.4' at character 8 select '1::5:260.2.3.4'::ipaddress; ERROR: invalid IP value: '1::5:260.2.3.4' at character 8 select '1::5:300.2.3.4'::ipaddress; ERROR: invalid IP value: '1::5:300.2.3.4' at character 8 select '1::5:300.300.300.300'::ipaddress; ERROR: invalid IP value: '1::5:300.300.300.300' at character 8 select '1::5:3000.30.30.30'::ipaddress; ERROR: invalid IP value: '1::5:3000.30.30.30' at character 8 select '1::5:400.2.3.4'::ipaddress; ERROR: invalid IP value: '1::5:400.2.3.4' at character 8 select '1::5:900.2.3.4'::ipaddress; ERROR: invalid IP value: '1::5:900.2.3.4' at character 8 select '1::900.2.3.4'::ipaddress; ERROR: invalid IP value: '1::900.2.3.4' at character 8 select '1:::3:4:5'::ipaddress; ERROR: invalid IP value: '1:::3:4:5' at character 8 select '2001:0000:1234: 0000:0000:C1C0:ABCD:0876'::ipaddress; ERROR: invalid IP value: '2001:0000:1234: 0000:0000:C1C0:ABCD:0876' at character 8 select '2001:0000:1234:0000:00001:C1C0:ABCD:0876'::ipaddress; ERROR: invalid IP value: '2001:0000:1234:0000:00001:C1C0:ABCD:0876' at character 8 select '2001:0000:1234:0000:0000:C1C0:ABCD:0876 0'::ipaddress; ERROR: invalid IP value: '2001:0000:1234:0000:0000:C1C0:ABCD:0876 0' at character 8 select '2001::FFD3::57ab'::ipaddress; ERROR: invalid IP value: '2001::FFD3::57ab' at character 8 select '2001:DB8:0:0:8:800:200C:417A:221'::ipaddress; ERROR: invalid IP value: '2001:DB8:0:0:8:800:200C:417A:221' at character 8 select '2001:db8:85a3::8a2e:37023:7334'::ipaddress; ERROR: invalid IP value: '2001:db8:85a3::8a2e:37023:7334' at character 8 select '2001:db8:85a3::8a2e:370k:7334'::ipaddress; ERROR: invalid IP value: '2001:db8:85a3::8a2e:370k:7334' at character 8 select '3ffe:0b00:0000:0001:0000:0000:000a'::ipaddress; ERROR: invalid IP value: '3ffe:0b00:0000:0001:0000:0000:000a' at character 8 select '3ffe:b00::1::a'::ipaddress; ERROR: invalid IP value: '3ffe:b00::1::a' at character 8 select ':'::ipaddress; ERROR: invalid IP value: ':' at character 8 select ':1111:2222:3333:4444::5555'::ipaddress; ERROR: invalid IP value: ':1111:2222:3333:4444::5555' at character 8 select ':1111:2222:3333::5555'::ipaddress; ERROR: invalid IP value: ':1111:2222:3333::5555' at character 8 select ':1111:2222::5555'::ipaddress; ERROR: invalid IP value: ':1111:2222::5555' at character 8 select ':1111::5555'::ipaddress; ERROR: invalid IP value: ':1111::5555' at character 8 select '::1.2.256.4'::ipaddress; ERROR: invalid IP value: '::1.2.256.4' at character 8 select '::1.2.3.256'::ipaddress; ERROR: invalid IP value: '::1.2.3.256' at character 8 select '::1.2.3.300'::ipaddress; ERROR: invalid IP value: '::1.2.3.300' at character 8 select '::1.2.3.900'::ipaddress; ERROR: invalid IP value: '::1.2.3.900' at character 8 select '::1.2.300.4'::ipaddress; ERROR: invalid IP value: '::1.2.300.4' at character 8 select '::1.2.900.4'::ipaddress; ERROR: invalid IP value: '::1.2.900.4' at character 8 select '::1.256.3.4'::ipaddress; ERROR: invalid IP value: '::1.256.3.4' at character 8 select '::1.300.3.4'::ipaddress; ERROR: invalid IP value: '::1.300.3.4' at character 8 select '::1.900.3.4'::ipaddress; ERROR: invalid IP value: '::1.900.3.4' at character 8 select '::1111:2222:3333:4444:5555:6666::'::ipaddress; ERROR: invalid IP value: '::1111:2222:3333:4444:5555:6666::' at character 8 select '::256.2.3.4'::ipaddress; ERROR: invalid IP value: '::256.2.3.4' at character 8 select '::260.2.3.4'::ipaddress; ERROR: invalid IP value: '::260.2.3.4' at character 8 select '::300.2.3.4'::ipaddress; ERROR: invalid IP value: '::300.2.3.4' at character 8 select '::300.300.300.300'::ipaddress; ERROR: invalid IP value: '::300.300.300.300' at character 8 select '::3000.30.30.30'::ipaddress; ERROR: invalid IP value: '::3000.30.30.30' at character 8 select '::400.2.3.4'::ipaddress; ERROR: invalid IP value: '::400.2.3.4' at character 8 select '::5555:'::ipaddress; ERROR: invalid IP value: '::5555:' at character 8 select '::900.2.3.4'::ipaddress; ERROR: invalid IP value: '::900.2.3.4' at character 8 select ':::'::ipaddress; ERROR: invalid IP value: ':::' at character 8 select ':::5555'::ipaddress; ERROR: invalid IP value: ':::5555' at character 8 select '::ffff:2.3.4'::ipaddress; ERROR: invalid IP value: '::ffff:2.3.4' at character 8 select '::ffff:257.1.2.3'::ipaddress; ERROR: invalid IP value: '::ffff:257.1.2.3' at character 8 select 'FF01::101::2'::ipaddress; ERROR: invalid IP value: 'FF01::101::2' at character 8 select 'FF02:0000:0000:0000:0000:0000:0000:0000:0001'::ipaddress; ERROR: invalid IP value: 'FF02:0000:0000:0000:0000:0000:0000:0000:0001' at character 8 select 'ldkfj'::ipaddress; ERROR: invalid IP value: 'ldkfj' at character 8 -- valid iprange select r, family(r), iprange_size(r) from (select '-'::iprange as r) s; r | family | iprange_size ---+--------+---------------------- - | | 6.80564733841877e+38 (1 row) select r, family(r), iprange_size(r) from (select '1.2.3.4'::iprange as r) s; r | family | iprange_size ---------+--------+-------------- 1.2.3.4 | 4 | 1 (1 row) select r, family(r), iprange_size(r) from (select '255.255.255.255/32'::iprange as r) s; r | family | iprange_size -----------------+--------+-------------- 255.255.255.255 | 4 | 1 (1 row) select r, family(r), iprange_size(r) from (select '255.255.255.254/31'::iprange as r) s; r | family | iprange_size --------------------+--------+-------------- 255.255.255.254/31 | 4 | 2 (1 row) select r, family(r), iprange_size(r) from (select '255.255.255.252/30'::iprange as r) s; r | family | iprange_size --------------------+--------+-------------- 255.255.255.252/30 | 4 | 4 (1 row) select r, family(r), iprange_size(r) from (select '255.255.255.248/29'::iprange as r) s; r | family | iprange_size --------------------+--------+-------------- 255.255.255.248/29 | 4 | 8 (1 row) select r, family(r), iprange_size(r) from (select '255.255.255.240/28'::iprange as r) s; r | family | iprange_size --------------------+--------+-------------- 255.255.255.240/28 | 4 | 16 (1 row) select r, family(r), iprange_size(r) from (select '255.255.255.224/27'::iprange as r) s; r | family | iprange_size --------------------+--------+-------------- 255.255.255.224/27 | 4 | 32 (1 row) select r, family(r), iprange_size(r) from (select '255.255.255.192/26'::iprange as r) s; r | family | iprange_size --------------------+--------+-------------- 255.255.255.192/26 | 4 | 64 (1 row) select r, family(r), iprange_size(r) from (select '255.255.255.128/25'::iprange as r) s; r | family | iprange_size --------------------+--------+-------------- 255.255.255.128/25 | 4 | 128 (1 row) select r, family(r), iprange_size(r) from (select '255.255.255.0/24'::iprange as r) s; r | family | iprange_size ------------------+--------+-------------- 255.255.255.0/24 | 4 | 256 (1 row) select r, family(r), iprange_size(r) from (select '255.255.254.0/23'::iprange as r) s; r | family | iprange_size ------------------+--------+-------------- 255.255.254.0/23 | 4 | 512 (1 row) select r, family(r), iprange_size(r) from (select '255.255.252.0/22'::iprange as r) s; r | family | iprange_size ------------------+--------+-------------- 255.255.252.0/22 | 4 | 1024 (1 row) select r, family(r), iprange_size(r) from (select '255.255.248.0/21'::iprange as r) s; r | family | iprange_size ------------------+--------+-------------- 255.255.248.0/21 | 4 | 2048 (1 row) select r, family(r), iprange_size(r) from (select '255.255.240.0/20'::iprange as r) s; r | family | iprange_size ------------------+--------+-------------- 255.255.240.0/20 | 4 | 4096 (1 row) select r, family(r), iprange_size(r) from (select '255.255.224.0/19'::iprange as r) s; r | family | iprange_size ------------------+--------+-------------- 255.255.224.0/19 | 4 | 8192 (1 row) select r, family(r), iprange_size(r) from (select '255.255.192.0/18'::iprange as r) s; r | family | iprange_size ------------------+--------+-------------- 255.255.192.0/18 | 4 | 16384 (1 row) select r, family(r), iprange_size(r) from (select '255.255.128.0/17'::iprange as r) s; r | family | iprange_size ------------------+--------+-------------- 255.255.128.0/17 | 4 | 32768 (1 row) select r, family(r), iprange_size(r) from (select '255.255.0.0/16'::iprange as r) s; r | family | iprange_size ----------------+--------+-------------- 255.255.0.0/16 | 4 | 65536 (1 row) select r, family(r), iprange_size(r) from (select '255.254.0.0/15'::iprange as r) s; r | family | iprange_size ----------------+--------+-------------- 255.254.0.0/15 | 4 | 131072 (1 row) select r, family(r), iprange_size(r) from (select '255.252.0.0/14'::iprange as r) s; r | family | iprange_size ----------------+--------+-------------- 255.252.0.0/14 | 4 | 262144 (1 row) select r, family(r), iprange_size(r) from (select '255.248.0.0/13'::iprange as r) s; r | family | iprange_size ----------------+--------+-------------- 255.248.0.0/13 | 4 | 524288 (1 row) select r, family(r), iprange_size(r) from (select '255.240.0.0/12'::iprange as r) s; r | family | iprange_size ----------------+--------+-------------- 255.240.0.0/12 | 4 | 1048576 (1 row) select r, family(r), iprange_size(r) from (select '255.224.0.0/11'::iprange as r) s; r | family | iprange_size ----------------+--------+-------------- 255.224.0.0/11 | 4 | 2097152 (1 row) select r, family(r), iprange_size(r) from (select '255.192.0.0/10'::iprange as r) s; r | family | iprange_size ----------------+--------+-------------- 255.192.0.0/10 | 4 | 4194304 (1 row) select r, family(r), iprange_size(r) from (select '255.128.0.0/9'::iprange as r) s; r | family | iprange_size ---------------+--------+-------------- 255.128.0.0/9 | 4 | 8388608 (1 row) select r, family(r), iprange_size(r) from (select '255.0.0.0/8'::iprange as r) s; r | family | iprange_size -------------+--------+-------------- 255.0.0.0/8 | 4 | 16777216 (1 row) select r, family(r), iprange_size(r) from (select '254.0.0.0/7'::iprange as r) s; r | family | iprange_size -------------+--------+-------------- 254.0.0.0/7 | 4 | 33554432 (1 row) select r, family(r), iprange_size(r) from (select '252.0.0.0/6'::iprange as r) s; r | family | iprange_size -------------+--------+-------------- 252.0.0.0/6 | 4 | 67108864 (1 row) select r, family(r), iprange_size(r) from (select '248.0.0.0/5'::iprange as r) s; r | family | iprange_size -------------+--------+-------------- 248.0.0.0/5 | 4 | 134217728 (1 row) select r, family(r), iprange_size(r) from (select '240.0.0.0/4'::iprange as r) s; r | family | iprange_size -------------+--------+-------------- 240.0.0.0/4 | 4 | 268435456 (1 row) select r, family(r), iprange_size(r) from (select '224.0.0.0/3'::iprange as r) s; r | family | iprange_size -------------+--------+-------------- 224.0.0.0/3 | 4 | 536870912 (1 row) select r, family(r), iprange_size(r) from (select '192.0.0.0/2'::iprange as r) s; r | family | iprange_size -------------+--------+-------------- 192.0.0.0/2 | 4 | 1073741824 (1 row) select r, family(r), iprange_size(r) from (select '128.0.0.0/1'::iprange as r) s; r | family | iprange_size -------------+--------+-------------- 128.0.0.0/1 | 4 | 2147483648 (1 row) select r, family(r), iprange_size(r) from (select '0.0.0.0/0'::iprange as r) s; r | family | iprange_size -----------+--------+-------------- 0.0.0.0/0 | 4 | 4294967296 (1 row) select r, family(r), iprange_size(r) from (select '1.2.3.4-5.6.7.8'::iprange as r) s; r | family | iprange_size -----------------+--------+-------------- 1.2.3.4-5.6.7.8 | 4 | 67372037 (1 row) select r, family(r), iprange_size(r) from (select '5.6.7.8-1.2.3.4'::iprange as r) s; r | family | iprange_size -----------------+--------+-------------- 1.2.3.4-5.6.7.8 | 4 | 67372037 (1 row) select r, family(r), iprange_size(r) from (select '1.2.3.4-1.2.3.4'::iprange as r) s; r | family | iprange_size ---------+--------+-------------- 1.2.3.4 | 4 | 1 (1 row) select r, family(r), iprange_size(r) from (select '::'::iprange as r) s; r | family | iprange_size ----+--------+-------------- :: | 6 | 1 (1 row) select r, family(r), iprange_size(r) from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'::iprange as r) s; r | family | iprange_size -----------------------------------------+--------+-------------- ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff | 6 | 1 (1 row) select r, family(r), iprange_size(r) from (select '1::2'::iprange as r) s; r | family | iprange_size ------+--------+-------------- 1::2 | 6 | 1 (1 row) select r, family(r), iprange_size(r) from (select '::-ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'::iprange as r) s; r | family | iprange_size ------+--------+---------------------- ::/0 | 6 | 3.40282366920938e+38 (1 row) select r, family(r), iprange_size(r) from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff-::'::iprange as r) s; r | family | iprange_size ------+--------+---------------------- ::/0 | 6 | 3.40282366920938e+38 (1 row) select r, family(r), iprange_size(r) from (select '1::2-3::4'::iprange as r) s; r | family | iprange_size -----------+--------+---------------------- 1::2-3::4 | 6 | 1.03845937170697e+34 (1 row) select r, family(r), iprange_size(r) from (select '3::4-3::4'::iprange as r) s; r | family | iprange_size ------+--------+-------------- 3::4 | 6 | 1 (1 row) select r, family(r), iprange_size(r) from (select '3::4-1::2'::iprange as r) s; r | family | iprange_size -----------+--------+---------------------- 1::2-3::4 | 6 | 1.03845937170697e+34 (1 row) select r, family(r), iprange_size(r) from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128'::iprange as r) s; r | family | iprange_size -----------------------------------------+--------+-------------- ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff | 6 | 1 (1 row) select r, family(r), iprange_size(r) from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffe/127'::iprange as r) s; r | family | iprange_size ---------------------------------------------+--------+-------------- ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffe/127 | 6 | 2 (1 row) select r, family(r), iprange_size(r) from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffc/126'::iprange as r) s; r | family | iprange_size ---------------------------------------------+--------+-------------- ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffc/126 | 6 | 4 (1 row) select r, family(r), iprange_size(r) from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:fff8/125'::iprange as r) s; r | family | iprange_size ---------------------------------------------+--------+-------------- ffff:ffff:ffff:ffff:ffff:ffff:ffff:fff8/125 | 6 | 8 (1 row) select r, family(r), iprange_size(r) from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:fff0/124'::iprange as r) s; r | family | iprange_size ---------------------------------------------+--------+-------------- ffff:ffff:ffff:ffff:ffff:ffff:ffff:fff0/124 | 6 | 16 (1 row) select r, family(r), iprange_size(r) from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ff00/120'::iprange as r) s; r | family | iprange_size ---------------------------------------------+--------+-------------- ffff:ffff:ffff:ffff:ffff:ffff:ffff:ff00/120 | 6 | 256 (1 row) select r, family(r), iprange_size(r) from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:f000/116'::iprange as r) s; r | family | iprange_size ---------------------------------------------+--------+-------------- ffff:ffff:ffff:ffff:ffff:ffff:ffff:f000/116 | 6 | 4096 (1 row) select r, family(r), iprange_size(r) from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:0000/112'::iprange as r) s; r | family | iprange_size ------------------------------------------+--------+-------------- ffff:ffff:ffff:ffff:ffff:ffff:ffff:0/112 | 6 | 65536 (1 row) select r, family(r), iprange_size(r) from (select 'ffff:ffff:ffff:ffff:ffff:ffff:0000:0000/96'::iprange as r) s; r | family | iprange_size ------------------------------------+--------+-------------- ffff:ffff:ffff:ffff:ffff:ffff::/96 | 6 | 4294967296 (1 row) select r, family(r), iprange_size(r) from (select 'ffff:ffff:ffff:ffff:ffff:0000:0000:0000/80'::iprange as r) s; r | family | iprange_size -------------------------------+--------+----------------- ffff:ffff:ffff:ffff:ffff::/80 | 6 | 281474976710656 (1 row) select r, family(r), iprange_size(r) from (select 'ffff:ffff:ffff:ffff:fff0:0000:0000:0000/76'::iprange as r) s; r | family | iprange_size -------------------------------+--------+--------------------- ffff:ffff:ffff:ffff:fff0::/76 | 6 | 4.5035996273705e+15 (1 row) select r, family(r), iprange_size(r) from (select 'ffff:ffff:ffff:ffff:ff00:0000:0000:0000/72'::iprange as r) s; r | family | iprange_size -------------------------------+--------+---------------------- ffff:ffff:ffff:ffff:ff00::/72 | 6 | 7.20575940379279e+16 (1 row) select r, family(r), iprange_size(r) from (select 'ffff:ffff:ffff:ffff:f000:0000:0000:0000/68'::iprange as r) s; r | family | iprange_size -------------------------------+--------+---------------------- ffff:ffff:ffff:ffff:f000::/68 | 6 | 1.15292150460685e+18 (1 row) select r, family(r), iprange_size(r) from (select 'ffff:ffff:ffff:ffff:e000:0000:0000:0000/67'::iprange as r) s; r | family | iprange_size -------------------------------+--------+---------------------- ffff:ffff:ffff:ffff:e000::/67 | 6 | 2.30584300921369e+18 (1 row) select r, family(r), iprange_size(r) from (select 'ffff:ffff:ffff:ffff:c000:0000:0000:0000/66'::iprange as r) s; r | family | iprange_size -------------------------------+--------+---------------------- ffff:ffff:ffff:ffff:c000::/66 | 6 | 4.61168601842739e+18 (1 row) select r, family(r), iprange_size(r) from (select 'ffff:ffff:ffff:ffff:8000:0000:0000:0000/65'::iprange as r) s; r | family | iprange_size -------------------------------+--------+---------------------- ffff:ffff:ffff:ffff:8000::/65 | 6 | 9.22337203685478e+18 (1 row) select r, family(r), iprange_size(r) from (select 'ffff:ffff:ffff:ffff:0000:0000:0000:0000/64'::iprange as r) s; r | family | iprange_size --------------------------+--------+---------------------- ffff:ffff:ffff:ffff::/64 | 6 | 1.84467440737096e+19 (1 row) select r, family(r), iprange_size(r) from (select 'ffff:ffff:ffff:fffe:0000:0000:0000:0000/63'::iprange as r) s; r | family | iprange_size --------------------------+--------+---------------------- ffff:ffff:ffff:fffe::/63 | 6 | 3.68934881474191e+19 (1 row) select r, family(r), iprange_size(r) from (select 'ffff:ffff:ffff:fffc:0000:0000:0000:0000/62'::iprange as r) s; r | family | iprange_size --------------------------+--------+---------------------- ffff:ffff:ffff:fffc::/62 | 6 | 7.37869762948382e+19 (1 row) select r, family(r), iprange_size(r) from (select 'ffff:ffff:ffff:fff8:0000:0000:0000:0000/61'::iprange as r) s; r | family | iprange_size --------------------------+--------+---------------------- ffff:ffff:ffff:fff8::/61 | 6 | 1.47573952589676e+20 (1 row) select r, family(r), iprange_size(r) from (select 'ffff:ffff:ffff:fff0:0000:0000:0000:0000/60'::iprange as r) s; r | family | iprange_size --------------------------+--------+---------------------- ffff:ffff:ffff:fff0::/60 | 6 | 2.95147905179353e+20 (1 row) select r, family(r), iprange_size(r) from (select 'ffff:ffff:ffff:ff00:0000:0000:0000:0000/56'::iprange as r) s; r | family | iprange_size --------------------------+--------+---------------------- ffff:ffff:ffff:ff00::/56 | 6 | 4.72236648286965e+21 (1 row) select r, family(r), iprange_size(r) from (select 'ffff:ffff:ffff:f000:0000:0000:0000:0000/52'::iprange as r) s; r | family | iprange_size --------------------------+--------+---------------------- ffff:ffff:ffff:f000::/52 | 6 | 7.55578637259143e+22 (1 row) select r, family(r), iprange_size(r) from (select 'ffff:ffff:ffff:0000:0000:0000:0000:0000/48'::iprange as r) s; r | family | iprange_size ---------------------+--------+---------------------- ffff:ffff:ffff::/48 | 6 | 1.20892581961463e+24 (1 row) select r, family(r), iprange_size(r) from (select 'ffff:ffff:0000:0000:0000:0000:0000:0000/32'::iprange as r) s; r | family | iprange_size ----------------+--------+---------------------- ffff:ffff::/32 | 6 | 7.92281625142643e+28 (1 row) select r, family(r), iprange_size(r) from (select 'ffff:0000:0000:0000:0000:0000:0000:0000/16'::iprange as r) s; r | family | iprange_size -----------+--------+---------------------- ffff::/16 | 6 | 5.19229685853483e+33 (1 row) select r, family(r), iprange_size(r) from (select 'fff0:0000:0000:0000:0000:0000:0000:0000/12'::iprange as r) s; r | family | iprange_size -----------+--------+---------------------- fff0::/12 | 6 | 8.30767497365572e+34 (1 row) select r, family(r), iprange_size(r) from (select 'ff00:0000:0000:0000:0000:0000:0000:0000/8'::iprange as r) s; r | family | iprange_size ----------+--------+---------------------- ff00::/8 | 6 | 1.32922799578492e+36 (1 row) select r, family(r), iprange_size(r) from (select 'f000:0000:0000:0000:0000:0000:0000:0000/4'::iprange as r) s; r | family | iprange_size ----------+--------+---------------------- f000::/4 | 6 | 2.12676479325587e+37 (1 row) select r, family(r), iprange_size(r) from (select 'e000:0000:0000:0000:0000:0000:0000:0000/3'::iprange as r) s; r | family | iprange_size ----------+--------+---------------------- e000::/3 | 6 | 4.25352958651173e+37 (1 row) select r, family(r), iprange_size(r) from (select 'c000:0000:0000:0000:0000:0000:0000:0000/2'::iprange as r) s; r | family | iprange_size ----------+--------+---------------------- c000::/2 | 6 | 8.50705917302346e+37 (1 row) select r, family(r), iprange_size(r) from (select '8000:0000:0000:0000:0000:0000:0000:0000/1'::iprange as r) s; r | family | iprange_size ----------+--------+---------------------- 8000::/1 | 6 | 1.70141183460469e+38 (1 row) select r, family(r), iprange_size(r) from (select '0000:0000:0000:0000:0000:0000:0000:0000/0'::iprange as r) s; r | family | iprange_size ------+--------+---------------------- ::/0 | 6 | 3.40282366920938e+38 (1 row) -- invalid iprange select '1.2.3'::iprange; ERROR: invalid IP4R value: "1.2.3" at character 8 select '255.255.255.255.255.255.255.255.255'::iprange; ERROR: invalid IP4R value: "255.255.255.255.255.255.255.255.255" at character 8 select '255.255.255.255.255-255.255.255.255.255'::iprange; ERROR: invalid IP4R value: "255.255.255.255.255-255.255.255.255.255" at character 8 select '255.255.255.255-1.2.3.4.5'::iprange; ERROR: invalid IP4R value: "255.255.255.255-1.2.3.4.5" at character 8 select '255.255.255.255-1.2.3'::iprange; ERROR: invalid IP4R value: "255.255.255.255-1.2.3" at character 8 select '0.0.0.1/31'::iprange; ERROR: invalid IP4R value: "0.0.0.1/31" at character 8 select '0.0.0.1/30'::iprange; ERROR: invalid IP4R value: "0.0.0.1/30" at character 8 select '0.0.0.1/29'::iprange; ERROR: invalid IP4R value: "0.0.0.1/29" at character 8 select '0.0.0.1/28'::iprange; ERROR: invalid IP4R value: "0.0.0.1/28" at character 8 select '0.0.0.1/27'::iprange; ERROR: invalid IP4R value: "0.0.0.1/27" at character 8 select '0.0.0.1/26'::iprange; ERROR: invalid IP4R value: "0.0.0.1/26" at character 8 select '0.0.0.1/25'::iprange; ERROR: invalid IP4R value: "0.0.0.1/25" at character 8 select '0.0.0.1/24'::iprange; ERROR: invalid IP4R value: "0.0.0.1/24" at character 8 select '0.0.0.1/23'::iprange; ERROR: invalid IP4R value: "0.0.0.1/23" at character 8 select '0.0.0.1/22'::iprange; ERROR: invalid IP4R value: "0.0.0.1/22" at character 8 select '0.0.0.1/21'::iprange; ERROR: invalid IP4R value: "0.0.0.1/21" at character 8 select '0.0.0.1/20'::iprange; ERROR: invalid IP4R value: "0.0.0.1/20" at character 8 select '0.0.0.1/19'::iprange; ERROR: invalid IP4R value: "0.0.0.1/19" at character 8 select '0.0.0.1/18'::iprange; ERROR: invalid IP4R value: "0.0.0.1/18" at character 8 select '0.0.0.1/17'::iprange; ERROR: invalid IP4R value: "0.0.0.1/17" at character 8 select '0.0.0.1/16'::iprange; ERROR: invalid IP4R value: "0.0.0.1/16" at character 8 select '0.0.0.1/15'::iprange; ERROR: invalid IP4R value: "0.0.0.1/15" at character 8 select '0.0.0.1/14'::iprange; ERROR: invalid IP4R value: "0.0.0.1/14" at character 8 select '0.0.0.1/13'::iprange; ERROR: invalid IP4R value: "0.0.0.1/13" at character 8 select '0.0.0.1/12'::iprange; ERROR: invalid IP4R value: "0.0.0.1/12" at character 8 select '0.0.0.1/11'::iprange; ERROR: invalid IP4R value: "0.0.0.1/11" at character 8 select '0.0.0.1/10'::iprange; ERROR: invalid IP4R value: "0.0.0.1/10" at character 8 select '0.0.0.1/9'::iprange; ERROR: invalid IP4R value: "0.0.0.1/9" at character 8 select '0.0.0.1/8'::iprange; ERROR: invalid IP4R value: "0.0.0.1/8" at character 8 select '0.0.0.1/7'::iprange; ERROR: invalid IP4R value: "0.0.0.1/7" at character 8 select '0.0.0.1/6'::iprange; ERROR: invalid IP4R value: "0.0.0.1/6" at character 8 select '0.0.0.1/5'::iprange; ERROR: invalid IP4R value: "0.0.0.1/5" at character 8 select '0.0.0.1/4'::iprange; ERROR: invalid IP4R value: "0.0.0.1/4" at character 8 select '0.0.0.1/3'::iprange; ERROR: invalid IP4R value: "0.0.0.1/3" at character 8 select '0.0.0.1/2'::iprange; ERROR: invalid IP4R value: "0.0.0.1/2" at character 8 select '0.0.0.1/1'::iprange; ERROR: invalid IP4R value: "0.0.0.1/1" at character 8 select '0.0.0.1/0'::iprange; ERROR: invalid IP4R value: "0.0.0.1/0" at character 8 select '0.0.0.2/30'::iprange; ERROR: invalid IP4R value: "0.0.0.2/30" at character 8 select '0.0.0.4/29'::iprange; ERROR: invalid IP4R value: "0.0.0.4/29" at character 8 select '0.0.0.8/28'::iprange; ERROR: invalid IP4R value: "0.0.0.8/28" at character 8 select '0.0.0.16/27'::iprange; ERROR: invalid IP4R value: "0.0.0.16/27" at character 8 select '0.0.0.32/26'::iprange; ERROR: invalid IP4R value: "0.0.0.32/26" at character 8 select '0.0.0.64/25'::iprange; ERROR: invalid IP4R value: "0.0.0.64/25" at character 8 select '0.0.0.128/24'::iprange; ERROR: invalid IP4R value: "0.0.0.128/24" at character 8 select '0.0.1.0/23'::iprange; ERROR: invalid IP4R value: "0.0.1.0/23" at character 8 select '0.0.2.0/22'::iprange; ERROR: invalid IP4R value: "0.0.2.0/22" at character 8 select '0.0.4.0/21'::iprange; ERROR: invalid IP4R value: "0.0.4.0/21" at character 8 select '0.0.8.0/20'::iprange; ERROR: invalid IP4R value: "0.0.8.0/20" at character 8 select '0.0.16.0/19'::iprange; ERROR: invalid IP4R value: "0.0.16.0/19" at character 8 select '0.0.32.0/18'::iprange; ERROR: invalid IP4R value: "0.0.32.0/18" at character 8 select '0.0.64.0/17'::iprange; ERROR: invalid IP4R value: "0.0.64.0/17" at character 8 select '0.0.128.0/16'::iprange; ERROR: invalid IP4R value: "0.0.128.0/16" at character 8 select '0.1.0.0/15'::iprange; ERROR: invalid IP4R value: "0.1.0.0/15" at character 8 select '0.2.0.0/14'::iprange; ERROR: invalid IP4R value: "0.2.0.0/14" at character 8 select '0.4.0.0/13'::iprange; ERROR: invalid IP4R value: "0.4.0.0/13" at character 8 select '0.8.0.0/12'::iprange; ERROR: invalid IP4R value: "0.8.0.0/12" at character 8 select '0.16.0.0/11'::iprange; ERROR: invalid IP4R value: "0.16.0.0/11" at character 8 select '0.32.0.0/10'::iprange; ERROR: invalid IP4R value: "0.32.0.0/10" at character 8 select '0.64.0.0/9'::iprange; ERROR: invalid IP4R value: "0.64.0.0/9" at character 8 select '0.128.0.0/8'::iprange; ERROR: invalid IP4R value: "0.128.0.0/8" at character 8 select '1.0.0.0/7'::iprange; ERROR: invalid IP4R value: "1.0.0.0/7" at character 8 select '2.0.0.0/6'::iprange; ERROR: invalid IP4R value: "2.0.0.0/6" at character 8 select '4.0.0.0/5'::iprange; ERROR: invalid IP4R value: "4.0.0.0/5" at character 8 select '8.0.0.0/4'::iprange; ERROR: invalid IP4R value: "8.0.0.0/4" at character 8 select '16.0.0.0/3'::iprange; ERROR: invalid IP4R value: "16.0.0.0/3" at character 8 select '32.0.0.0/2'::iprange; ERROR: invalid IP4R value: "32.0.0.0/2" at character 8 select '64.0.0.0/1'::iprange; ERROR: invalid IP4R value: "64.0.0.0/1" at character 8 select '128.0.0.0/0'::iprange; ERROR: invalid IP4R value: "128.0.0.0/0" at character 8 select '0.0.0.0/33'::iprange; ERROR: invalid IP4R value: "0.0.0.0/33" at character 8 select '0.0.0.0/3.0'::iprange; ERROR: invalid IP4R value: "0.0.0.0/3.0" at character 8 select '0.0.0.0/+33'::iprange; ERROR: invalid IP4R value: "0.0.0.0/+33" at character 8 select '::-::-::'::iprange; ERROR: invalid IP6R value: "::-::-::" at character 8 select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff-ffff'::ip6r; ERROR: invalid IP6R value: "ffff:ffff:ffff:ffff:ffff:ffff:ffff-ffff" at character 8 select '::-ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'::iprange; ERROR: invalid IP6R value: "::-ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff" at character 8 select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff-::'::iprange; ERROR: invalid IP6R value: "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff-::" at character 8 select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128'::iprange; ERROR: invalid IP6R value: "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128" at character 8 select '0000:0000:0000:0000:0000:0000:0000:0001/127'::iprange; ERROR: invalid IP6R value: "0000:0000:0000:0000:0000:0000:0000:0001/127" at character 8 select '0000:0000:0000:0000:0000:0000:0000:0001/120'::iprange; ERROR: invalid IP6R value: "0000:0000:0000:0000:0000:0000:0000:0001/120" at character 8 select '0000:0000:0000:0000:0000:0000:0000:0001/112'::iprange; ERROR: invalid IP6R value: "0000:0000:0000:0000:0000:0000:0000:0001/112" at character 8 select '0000:0000:0000:0000:0000:0000:0000:0001/96'::iprange; ERROR: invalid IP6R value: "0000:0000:0000:0000:0000:0000:0000:0001/96" at character 8 select '0000:0000:0000:0000:0000:0000:0000:0001/80'::iprange; ERROR: invalid IP6R value: "0000:0000:0000:0000:0000:0000:0000:0001/80" at character 8 select '0000:0000:0000:0000:0000:0000:0000:0001/64'::iprange; ERROR: invalid IP6R value: "0000:0000:0000:0000:0000:0000:0000:0001/64" at character 8 select '0000:0000:0000:0000:0000:0000:0000:0001/48'::iprange; ERROR: invalid IP6R value: "0000:0000:0000:0000:0000:0000:0000:0001/48" at character 8 select '0000:0000:0000:0000:0000:0000:0000:0001/32'::iprange; ERROR: invalid IP6R value: "0000:0000:0000:0000:0000:0000:0000:0001/32" at character 8 select '0000:0000:0000:0000:0000:0000:0000:0001/16'::iprange; ERROR: invalid IP6R value: "0000:0000:0000:0000:0000:0000:0000:0001/16" at character 8 select '0000:0000:0000:0000:0000:0000:0000:0001/8'::iprange; ERROR: invalid IP6R value: "0000:0000:0000:0000:0000:0000:0000:0001/8" at character 8 select '0000:0000:0000:0000:0000:0000:0000:0001/4'::iprange; ERROR: invalid IP6R value: "0000:0000:0000:0000:0000:0000:0000:0001/4" at character 8 select '0000:0000:0000:0000:0000:0000:0000:0001/0'::iprange; ERROR: invalid IP6R value: "0000:0000:0000:0000:0000:0000:0000:0001/0" at character 8 select '0000:0000:0000:0000:0000:0000:0000:0008/124'::iprange; ERROR: invalid IP6R value: "0000:0000:0000:0000:0000:0000:0000:0008/124" at character 8 select '0000:0000:0000:0000:0000:0000:0000:0080/120'::iprange; ERROR: invalid IP6R value: "0000:0000:0000:0000:0000:0000:0000:0080/120" at character 8 select '0000:0000:0000:0000:0000:0000:0000:8000/112'::iprange; ERROR: invalid IP6R value: "0000:0000:0000:0000:0000:0000:0000:8000/112" at character 8 select '0000:0000:0000:0000:0000:0000:8000:0000/96'::iprange; ERROR: invalid IP6R value: "0000:0000:0000:0000:0000:0000:8000:0000/96" at character 8 select '0000:0000:0000:0000:0000:8000:0000:0000/80'::iprange; ERROR: invalid IP6R value: "0000:0000:0000:0000:0000:8000:0000:0000/80" at character 8 select '0000:0000:0000:0000:8000:0000:0000:0000/64'::iprange; ERROR: invalid IP6R value: "0000:0000:0000:0000:8000:0000:0000:0000/64" at character 8 select '0000:0000:0000:8000:0000:0000:0000:0000/48'::iprange; ERROR: invalid IP6R value: "0000:0000:0000:8000:0000:0000:0000:0000/48" at character 8 select '0000:0000:8000:0000:0000:0000:0000:0000/32'::iprange; ERROR: invalid IP6R value: "0000:0000:8000:0000:0000:0000:0000:0000/32" at character 8 select '0000:8000:0000:0000:0000:0000:0000:0000/16'::iprange; ERROR: invalid IP6R value: "0000:8000:0000:0000:0000:0000:0000:0000/16" at character 8 select '0080:0000:0000:0000:0000:0000:0000:0000/8'::iprange; ERROR: invalid IP6R value: "0080:0000:0000:0000:0000:0000:0000:0000/8" at character 8 select '0800:0000:0000:0000:0000:0000:0000:0000/4'::iprange; ERROR: invalid IP6R value: "0800:0000:0000:0000:0000:0000:0000:0000/4" at character 8 select '8000:0000:0000:0000:0000:0000:0000:0000/0'::iprange; ERROR: invalid IP6R value: "8000:0000:0000:0000:0000:0000:0000:0000/0" at character 8 select '::/129'::iprange; ERROR: invalid IP6R value: "::/129" at character 8 select '::/255'::iprange; ERROR: invalid IP6R value: "::/255" at character 8 select '::/256'::iprange; ERROR: invalid IP6R value: "::/256" at character 8 select '::/+0'::iprange; ERROR: invalid IP6R value: "::/+0" at character 8 select '::/0-0'::iprange; ERROR: invalid IP6R value: "::/0-0" at character 8 select '::-::/0'::iprange; ERROR: invalid IP6R value: "::-::/0" at character 8 select '-::'::iprange; ERROR: invalid IP6R value: "-::" at character 8 select '-1.2.3.4'::iprange; ERROR: invalid IP4R value: "-1.2.3.4" at character 8 select '1.2.3.4-'::iprange; ERROR: invalid IP4R value: "1.2.3.4-" at character 8 -- text casts and cross-type casts select r::text from (select '-'::iprange as r) s; r --- - (1 row) select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '1.2.3.4'::iprange as r) s; r | r | lower | upper ---------+---------+---------+--------- 1.2.3.4 | 1.2.3.4 | 1.2.3.4 | 1.2.3.4 (1 row) select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '255.255.255.255/32'::iprange as r) s; r | r | lower | upper -----------------+-----------------+-----------------+----------------- 255.255.255.255 | 255.255.255.255 | 255.255.255.255 | 255.255.255.255 (1 row) select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '255.255.255.254/31'::iprange as r) s; r | r | lower | upper --------------------+--------------------+-----------------+----------------- 255.255.255.254/31 | 255.255.255.254/31 | 255.255.255.254 | 255.255.255.255 (1 row) select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '255.255.255.252/30'::iprange as r) s; r | r | lower | upper --------------------+--------------------+-----------------+----------------- 255.255.255.252/30 | 255.255.255.252/30 | 255.255.255.252 | 255.255.255.255 (1 row) select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '255.255.255.248/29'::iprange as r) s; r | r | lower | upper --------------------+--------------------+-----------------+----------------- 255.255.255.248/29 | 255.255.255.248/29 | 255.255.255.248 | 255.255.255.255 (1 row) select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '255.255.255.240/28'::iprange as r) s; r | r | lower | upper --------------------+--------------------+-----------------+----------------- 255.255.255.240/28 | 255.255.255.240/28 | 255.255.255.240 | 255.255.255.255 (1 row) select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '255.255.255.224/27'::iprange as r) s; r | r | lower | upper --------------------+--------------------+-----------------+----------------- 255.255.255.224/27 | 255.255.255.224/27 | 255.255.255.224 | 255.255.255.255 (1 row) select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '255.255.255.192/26'::iprange as r) s; r | r | lower | upper --------------------+--------------------+-----------------+----------------- 255.255.255.192/26 | 255.255.255.192/26 | 255.255.255.192 | 255.255.255.255 (1 row) select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '255.255.255.128/25'::iprange as r) s; r | r | lower | upper --------------------+--------------------+-----------------+----------------- 255.255.255.128/25 | 255.255.255.128/25 | 255.255.255.128 | 255.255.255.255 (1 row) select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '255.255.255.0/24'::iprange as r) s; r | r | lower | upper ------------------+------------------+---------------+----------------- 255.255.255.0/24 | 255.255.255.0/24 | 255.255.255.0 | 255.255.255.255 (1 row) select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '255.255.254.0/23'::iprange as r) s; r | r | lower | upper ------------------+------------------+---------------+----------------- 255.255.254.0/23 | 255.255.254.0/23 | 255.255.254.0 | 255.255.255.255 (1 row) select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '255.255.252.0/22'::iprange as r) s; r | r | lower | upper ------------------+------------------+---------------+----------------- 255.255.252.0/22 | 255.255.252.0/22 | 255.255.252.0 | 255.255.255.255 (1 row) select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '255.255.248.0/21'::iprange as r) s; r | r | lower | upper ------------------+------------------+---------------+----------------- 255.255.248.0/21 | 255.255.248.0/21 | 255.255.248.0 | 255.255.255.255 (1 row) select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '255.255.240.0/20'::iprange as r) s; r | r | lower | upper ------------------+------------------+---------------+----------------- 255.255.240.0/20 | 255.255.240.0/20 | 255.255.240.0 | 255.255.255.255 (1 row) select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '255.255.224.0/19'::iprange as r) s; r | r | lower | upper ------------------+------------------+---------------+----------------- 255.255.224.0/19 | 255.255.224.0/19 | 255.255.224.0 | 255.255.255.255 (1 row) select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '255.255.192.0/18'::iprange as r) s; r | r | lower | upper ------------------+------------------+---------------+----------------- 255.255.192.0/18 | 255.255.192.0/18 | 255.255.192.0 | 255.255.255.255 (1 row) select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '255.255.128.0/17'::iprange as r) s; r | r | lower | upper ------------------+------------------+---------------+----------------- 255.255.128.0/17 | 255.255.128.0/17 | 255.255.128.0 | 255.255.255.255 (1 row) select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '255.255.0.0/16'::iprange as r) s; r | r | lower | upper ----------------+----------------+-------------+----------------- 255.255.0.0/16 | 255.255.0.0/16 | 255.255.0.0 | 255.255.255.255 (1 row) select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '255.254.0.0/15'::iprange as r) s; r | r | lower | upper ----------------+----------------+-------------+----------------- 255.254.0.0/15 | 255.254.0.0/15 | 255.254.0.0 | 255.255.255.255 (1 row) select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '255.252.0.0/14'::iprange as r) s; r | r | lower | upper ----------------+----------------+-------------+----------------- 255.252.0.0/14 | 255.252.0.0/14 | 255.252.0.0 | 255.255.255.255 (1 row) select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '255.248.0.0/13'::iprange as r) s; r | r | lower | upper ----------------+----------------+-------------+----------------- 255.248.0.0/13 | 255.248.0.0/13 | 255.248.0.0 | 255.255.255.255 (1 row) select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '255.240.0.0/12'::iprange as r) s; r | r | lower | upper ----------------+----------------+-------------+----------------- 255.240.0.0/12 | 255.240.0.0/12 | 255.240.0.0 | 255.255.255.255 (1 row) select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '255.224.0.0/11'::iprange as r) s; r | r | lower | upper ----------------+----------------+-------------+----------------- 255.224.0.0/11 | 255.224.0.0/11 | 255.224.0.0 | 255.255.255.255 (1 row) select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '255.192.0.0/10'::iprange as r) s; r | r | lower | upper ----------------+----------------+-------------+----------------- 255.192.0.0/10 | 255.192.0.0/10 | 255.192.0.0 | 255.255.255.255 (1 row) select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '255.128.0.0/9'::iprange as r) s; r | r | lower | upper ---------------+---------------+-------------+----------------- 255.128.0.0/9 | 255.128.0.0/9 | 255.128.0.0 | 255.255.255.255 (1 row) select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '255.0.0.0/8'::iprange as r) s; r | r | lower | upper -------------+-------------+-----------+----------------- 255.0.0.0/8 | 255.0.0.0/8 | 255.0.0.0 | 255.255.255.255 (1 row) select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '254.0.0.0/7'::iprange as r) s; r | r | lower | upper -------------+-------------+-----------+----------------- 254.0.0.0/7 | 254.0.0.0/7 | 254.0.0.0 | 255.255.255.255 (1 row) select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '252.0.0.0/6'::iprange as r) s; r | r | lower | upper -------------+-------------+-----------+----------------- 252.0.0.0/6 | 252.0.0.0/6 | 252.0.0.0 | 255.255.255.255 (1 row) select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '248.0.0.0/5'::iprange as r) s; r | r | lower | upper -------------+-------------+-----------+----------------- 248.0.0.0/5 | 248.0.0.0/5 | 248.0.0.0 | 255.255.255.255 (1 row) select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '240.0.0.0/4'::iprange as r) s; r | r | lower | upper -------------+-------------+-----------+----------------- 240.0.0.0/4 | 240.0.0.0/4 | 240.0.0.0 | 255.255.255.255 (1 row) select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '224.0.0.0/3'::iprange as r) s; r | r | lower | upper -------------+-------------+-----------+----------------- 224.0.0.0/3 | 224.0.0.0/3 | 224.0.0.0 | 255.255.255.255 (1 row) select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '192.0.0.0/2'::iprange as r) s; r | r | lower | upper -------------+-------------+-----------+----------------- 192.0.0.0/2 | 192.0.0.0/2 | 192.0.0.0 | 255.255.255.255 (1 row) select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '128.0.0.0/1'::iprange as r) s; r | r | lower | upper -------------+-------------+-----------+----------------- 128.0.0.0/1 | 128.0.0.0/1 | 128.0.0.0 | 255.255.255.255 (1 row) select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '0.0.0.0/0'::iprange as r) s; r | r | lower | upper -----------+-----------+---------+----------------- 0.0.0.0/0 | 0.0.0.0/0 | 0.0.0.0 | 255.255.255.255 (1 row) select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '1.2.3.4-5.6.7.8'::iprange as r) s; r | r | lower | upper -----------------+-----------------+---------+--------- 1.2.3.4-5.6.7.8 | 1.2.3.4-5.6.7.8 | 1.2.3.4 | 5.6.7.8 (1 row) select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '5.6.7.8-1.2.3.4'::iprange as r) s; r | r | lower | upper -----------------+-----------------+---------+--------- 1.2.3.4-5.6.7.8 | 1.2.3.4-5.6.7.8 | 1.2.3.4 | 5.6.7.8 (1 row) select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '1.2.3.4-1.2.3.4'::iprange as r) s; r | r | lower | upper ---------+---------+---------+--------- 1.2.3.4 | 1.2.3.4 | 1.2.3.4 | 1.2.3.4 (1 row) select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select '::'::iprange as r) s; r | r | lower | upper ----+----+-------+------- :: | :: | :: | :: (1 row) select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'::iprange as r) s; r | r | lower | upper -----------------------------------------+-----------------------------------------+-----------------------------------------+----------------------------------------- ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff | ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff | ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff | ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff (1 row) select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select '1::2'::iprange as r) s; r | r | lower | upper ------+------+-------+------- 1::2 | 1::2 | 1::2 | 1::2 (1 row) select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select '::-ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'::iprange as r) s; r | r | lower | upper ------+------+-------+----------------------------------------- ::/0 | ::/0 | :: | ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff (1 row) select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff-::'::iprange as r) s; r | r | lower | upper ------+------+-------+----------------------------------------- ::/0 | ::/0 | :: | ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff (1 row) select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select '1::2-3::4'::iprange as r) s; r | r | lower | upper -----------+-----------+-------+------- 1::2-3::4 | 1::2-3::4 | 1::2 | 3::4 (1 row) select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select '3::4-3::4'::iprange as r) s; r | r | lower | upper ------+------+-------+------- 3::4 | 3::4 | 3::4 | 3::4 (1 row) select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select '3::4-1::2'::iprange as r) s; r | r | lower | upper -----------+-----------+-------+------- 1::2-3::4 | 1::2-3::4 | 1::2 | 3::4 (1 row) select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128'::iprange as r) s; r | r | lower | upper -----------------------------------------+-----------------------------------------+-----------------------------------------+----------------------------------------- ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff | ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff | ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff | ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff (1 row) select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffe/127'::iprange as r) s; r | r | lower | upper ---------------------------------------------+---------------------------------------------+-----------------------------------------+----------------------------------------- ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffe/127 | ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffe/127 | ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffe | ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff (1 row) select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffc/126'::iprange as r) s; r | r | lower | upper ---------------------------------------------+---------------------------------------------+-----------------------------------------+----------------------------------------- ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffc/126 | ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffc/126 | ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffc | ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff (1 row) select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:fff8/125'::iprange as r) s; r | r | lower | upper ---------------------------------------------+---------------------------------------------+-----------------------------------------+----------------------------------------- ffff:ffff:ffff:ffff:ffff:ffff:ffff:fff8/125 | ffff:ffff:ffff:ffff:ffff:ffff:ffff:fff8/125 | ffff:ffff:ffff:ffff:ffff:ffff:ffff:fff8 | ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff (1 row) select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:fff0/124'::iprange as r) s; r | r | lower | upper ---------------------------------------------+---------------------------------------------+-----------------------------------------+----------------------------------------- ffff:ffff:ffff:ffff:ffff:ffff:ffff:fff0/124 | ffff:ffff:ffff:ffff:ffff:ffff:ffff:fff0/124 | ffff:ffff:ffff:ffff:ffff:ffff:ffff:fff0 | ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff (1 row) select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ff00/120'::iprange as r) s; r | r | lower | upper ---------------------------------------------+---------------------------------------------+-----------------------------------------+----------------------------------------- ffff:ffff:ffff:ffff:ffff:ffff:ffff:ff00/120 | ffff:ffff:ffff:ffff:ffff:ffff:ffff:ff00/120 | ffff:ffff:ffff:ffff:ffff:ffff:ffff:ff00 | ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff (1 row) select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:f000/116'::iprange as r) s; r | r | lower | upper ---------------------------------------------+---------------------------------------------+-----------------------------------------+----------------------------------------- ffff:ffff:ffff:ffff:ffff:ffff:ffff:f000/116 | ffff:ffff:ffff:ffff:ffff:ffff:ffff:f000/116 | ffff:ffff:ffff:ffff:ffff:ffff:ffff:f000 | ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff (1 row) select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:0000/112'::iprange as r) s; r | r | lower | upper ------------------------------------------+------------------------------------------+--------------------------------------+----------------------------------------- ffff:ffff:ffff:ffff:ffff:ffff:ffff:0/112 | ffff:ffff:ffff:ffff:ffff:ffff:ffff:0/112 | ffff:ffff:ffff:ffff:ffff:ffff:ffff:0 | ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff (1 row) select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'ffff:ffff:ffff:ffff:ffff:ffff:0000:0000/96'::iprange as r) s; r | r | lower | upper ------------------------------------+------------------------------------+---------------------------------+----------------------------------------- ffff:ffff:ffff:ffff:ffff:ffff::/96 | ffff:ffff:ffff:ffff:ffff:ffff::/96 | ffff:ffff:ffff:ffff:ffff:ffff:: | ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff (1 row) select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'ffff:ffff:ffff:ffff:ffff:0000:0000:0000/80'::iprange as r) s; r | r | lower | upper -------------------------------+-------------------------------+----------------------------+----------------------------------------- ffff:ffff:ffff:ffff:ffff::/80 | ffff:ffff:ffff:ffff:ffff::/80 | ffff:ffff:ffff:ffff:ffff:: | ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff (1 row) select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'ffff:ffff:ffff:ffff:fff0:0000:0000:0000/76'::iprange as r) s; r | r | lower | upper -------------------------------+-------------------------------+----------------------------+----------------------------------------- ffff:ffff:ffff:ffff:fff0::/76 | ffff:ffff:ffff:ffff:fff0::/76 | ffff:ffff:ffff:ffff:fff0:: | ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff (1 row) select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'ffff:ffff:ffff:ffff:ff00:0000:0000:0000/72'::iprange as r) s; r | r | lower | upper -------------------------------+-------------------------------+----------------------------+----------------------------------------- ffff:ffff:ffff:ffff:ff00::/72 | ffff:ffff:ffff:ffff:ff00::/72 | ffff:ffff:ffff:ffff:ff00:: | ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff (1 row) select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'ffff:ffff:ffff:ffff:f000:0000:0000:0000/68'::iprange as r) s; r | r | lower | upper -------------------------------+-------------------------------+----------------------------+----------------------------------------- ffff:ffff:ffff:ffff:f000::/68 | ffff:ffff:ffff:ffff:f000::/68 | ffff:ffff:ffff:ffff:f000:: | ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff (1 row) select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'ffff:ffff:ffff:ffff:e000:0000:0000:0000/67'::iprange as r) s; r | r | lower | upper -------------------------------+-------------------------------+----------------------------+----------------------------------------- ffff:ffff:ffff:ffff:e000::/67 | ffff:ffff:ffff:ffff:e000::/67 | ffff:ffff:ffff:ffff:e000:: | ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff (1 row) select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'ffff:ffff:ffff:ffff:c000:0000:0000:0000/66'::iprange as r) s; r | r | lower | upper -------------------------------+-------------------------------+----------------------------+----------------------------------------- ffff:ffff:ffff:ffff:c000::/66 | ffff:ffff:ffff:ffff:c000::/66 | ffff:ffff:ffff:ffff:c000:: | ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff (1 row) select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'ffff:ffff:ffff:ffff:8000:0000:0000:0000/65'::iprange as r) s; r | r | lower | upper -------------------------------+-------------------------------+----------------------------+----------------------------------------- ffff:ffff:ffff:ffff:8000::/65 | ffff:ffff:ffff:ffff:8000::/65 | ffff:ffff:ffff:ffff:8000:: | ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff (1 row) select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'ffff:ffff:ffff:ffff:0000:0000:0000:0000/64'::iprange as r) s; r | r | lower | upper --------------------------+--------------------------+-----------------------+----------------------------------------- ffff:ffff:ffff:ffff::/64 | ffff:ffff:ffff:ffff::/64 | ffff:ffff:ffff:ffff:: | ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff (1 row) select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'ffff:ffff:ffff:fffe:0000:0000:0000:0000/63'::iprange as r) s; r | r | lower | upper --------------------------+--------------------------+-----------------------+----------------------------------------- ffff:ffff:ffff:fffe::/63 | ffff:ffff:ffff:fffe::/63 | ffff:ffff:ffff:fffe:: | ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff (1 row) select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'ffff:ffff:ffff:fffc:0000:0000:0000:0000/62'::iprange as r) s; r | r | lower | upper --------------------------+--------------------------+-----------------------+----------------------------------------- ffff:ffff:ffff:fffc::/62 | ffff:ffff:ffff:fffc::/62 | ffff:ffff:ffff:fffc:: | ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff (1 row) select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'ffff:ffff:ffff:fff8:0000:0000:0000:0000/61'::iprange as r) s; r | r | lower | upper --------------------------+--------------------------+-----------------------+----------------------------------------- ffff:ffff:ffff:fff8::/61 | ffff:ffff:ffff:fff8::/61 | ffff:ffff:ffff:fff8:: | ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff (1 row) select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'ffff:ffff:ffff:fff0:0000:0000:0000:0000/60'::iprange as r) s; r | r | lower | upper --------------------------+--------------------------+-----------------------+----------------------------------------- ffff:ffff:ffff:fff0::/60 | ffff:ffff:ffff:fff0::/60 | ffff:ffff:ffff:fff0:: | ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff (1 row) select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'ffff:ffff:ffff:ff00:0000:0000:0000:0000/56'::iprange as r) s; r | r | lower | upper --------------------------+--------------------------+-----------------------+----------------------------------------- ffff:ffff:ffff:ff00::/56 | ffff:ffff:ffff:ff00::/56 | ffff:ffff:ffff:ff00:: | ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff (1 row) select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'ffff:ffff:ffff:f000:0000:0000:0000:0000/52'::iprange as r) s; r | r | lower | upper --------------------------+--------------------------+-----------------------+----------------------------------------- ffff:ffff:ffff:f000::/52 | ffff:ffff:ffff:f000::/52 | ffff:ffff:ffff:f000:: | ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff (1 row) select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'ffff:ffff:ffff:0000:0000:0000:0000:0000/48'::iprange as r) s; r | r | lower | upper ---------------------+---------------------+------------------+----------------------------------------- ffff:ffff:ffff::/48 | ffff:ffff:ffff::/48 | ffff:ffff:ffff:: | ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff (1 row) select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'ffff:ffff:0000:0000:0000:0000:0000:0000/32'::iprange as r) s; r | r | lower | upper ----------------+----------------+-------------+----------------------------------------- ffff:ffff::/32 | ffff:ffff::/32 | ffff:ffff:: | ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff (1 row) select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'ffff:0000:0000:0000:0000:0000:0000:0000/16'::iprange as r) s; r | r | lower | upper -----------+-----------+--------+----------------------------------------- ffff::/16 | ffff::/16 | ffff:: | ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff (1 row) select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'fff0:0000:0000:0000:0000:0000:0000:0000/12'::iprange as r) s; r | r | lower | upper -----------+-----------+--------+----------------------------------------- fff0::/12 | fff0::/12 | fff0:: | ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff (1 row) select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'ff00:0000:0000:0000:0000:0000:0000:0000/8'::iprange as r) s; r | r | lower | upper ----------+----------+--------+----------------------------------------- ff00::/8 | ff00::/8 | ff00:: | ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff (1 row) select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'f000:0000:0000:0000:0000:0000:0000:0000/4'::iprange as r) s; r | r | lower | upper ----------+----------+--------+----------------------------------------- f000::/4 | f000::/4 | f000:: | ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff (1 row) select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'e000:0000:0000:0000:0000:0000:0000:0000/3'::iprange as r) s; r | r | lower | upper ----------+----------+--------+----------------------------------------- e000::/3 | e000::/3 | e000:: | ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff (1 row) select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'c000:0000:0000:0000:0000:0000:0000:0000/2'::iprange as r) s; r | r | lower | upper ----------+----------+--------+----------------------------------------- c000::/2 | c000::/2 | c000:: | ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff (1 row) select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select '8000:0000:0000:0000:0000:0000:0000:0000/1'::iprange as r) s; r | r | lower | upper ----------+----------+--------+----------------------------------------- 8000::/1 | 8000::/1 | 8000:: | ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff (1 row) select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select '0000:0000:0000:0000:0000:0000:0000:0000/0'::iprange as r) s; r | r | lower | upper ------+------+-------+----------------------------------------- ::/0 | ::/0 | :: | ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff (1 row) select a::ipaddress, a::ip4 from (select '1.2.3.4'::text as a) s1; a | a ---------+--------- 1.2.3.4 | 1.2.3.4 (1 row) select a::ipaddress, a::ip4 from (select '0.0.0.0'::text as a) s1; a | a ---------+--------- 0.0.0.0 | 0.0.0.0 (1 row) select a::ipaddress, a::ip4 from (select '255.255.255.255'::text as a) s1; a | a -----------------+----------------- 255.255.255.255 | 255.255.255.255 (1 row) select a::ipaddress, a::ip4 from (select '0.0.0.255'::text as a) s1; a | a -----------+----------- 0.0.0.255 | 0.0.0.255 (1 row) select a::ipaddress, a::ip4 from (select '0.0.255.0'::text as a) s1; a | a -----------+----------- 0.0.255.0 | 0.0.255.0 (1 row) select a::ipaddress, a::ip4 from (select '0.255.0.0'::text as a) s1; a | a -----------+----------- 0.255.0.0 | 0.255.0.0 (1 row) select a::ipaddress, a::ip4 from (select '255.0.0.0'::text as a) s1; a | a -----------+----------- 255.0.0.0 | 255.0.0.0 (1 row) select a::ipaddress, a::ip4 from (select '192.168.123.210'::text as a) s1; a | a -----------------+----------------- 192.168.123.210 | 192.168.123.210 (1 row) select a::ipaddress, a::ip4 from (select '127.0.0.1'::text as a) s1; a | a -----------+----------- 127.0.0.1 | 127.0.0.1 (1 row) select a::ipaddress, a::ip6 from (select '0000:0000:0000:0000:0000:0000:0000:0000'::text as a) s1; a | a ----+---- :: | :: (1 row) select a::ipaddress, a::ip6 from (select '0000:0000:0000:0000:0000:0000:0000:0001'::text as a) s1; a | a -----+----- ::1 | ::1 (1 row) select a::ipaddress, a::ip6 from (select '0:0:0:0:0:0:0:0'::text as a) s1; a | a ----+---- :: | :: (1 row) select a::ipaddress, a::ip6 from (select '0:0:0:0:0:0:0:1'::text as a) s1; a | a -----+----- ::1 | ::1 (1 row) select a::ipaddress, a::ip6 from (select '0:0:0:0:0:0:13.1.68.3'::text as a) s1; a | a -------------+------------- ::13.1.68.3 | ::13.1.68.3 (1 row) select a::ipaddress, a::ip6 from (select '0:0:0:0:0:FFFF:129.144.52.38'::text as a) s1; a | a ----------------------+---------------------- ::ffff:129.144.52.38 | ::ffff:129.144.52.38 (1 row) select a::ipaddress, a::ip6 from (select '0::0'::text as a) s1; a | a ----+---- :: | :: (1 row) select a::ipaddress, a::ip6 from (select '1:2:3:4:5:6:1.2.3.4'::text as a) s1; a | a ---------------------+--------------------- 1:2:3:4:5:6:102:304 | 1:2:3:4:5:6:102:304 (1 row) select a::ipaddress, a::ip6 from (select '1:2:3:4:5:6:7:8'::text as a) s1; a | a -----------------+----------------- 1:2:3:4:5:6:7:8 | 1:2:3:4:5:6:7:8 (1 row) select a::ipaddress, a::ip6 from (select '1:2:3:4:5:6::'::text as a) s1; a | a ---------------+--------------- 1:2:3:4:5:6:: | 1:2:3:4:5:6:: (1 row) select a::ipaddress, a::ip6 from (select '1:2:3:4:5:6::8'::text as a) s1; a | a -----------------+----------------- 1:2:3:4:5:6:0:8 | 1:2:3:4:5:6:0:8 (1 row) select a::ipaddress, a::ip6 from (select '1:2:3:4:5::'::text as a) s1; a | a -------------+------------- 1:2:3:4:5:: | 1:2:3:4:5:: (1 row) select a::ipaddress, a::ip6 from (select '1:2:3:4:5::1.2.3.4'::text as a) s1; a | a ---------------------+--------------------- 1:2:3:4:5:0:102:304 | 1:2:3:4:5:0:102:304 (1 row) select a::ipaddress, a::ip6 from (select '1:2:3:4:5::7:8'::text as a) s1; a | a -----------------+----------------- 1:2:3:4:5:0:7:8 | 1:2:3:4:5:0:7:8 (1 row) select a::ipaddress, a::ip6 from (select '1:2:3:4:5::8'::text as a) s1; a | a --------------+-------------- 1:2:3:4:5::8 | 1:2:3:4:5::8 (1 row) select a::ipaddress, a::ip6 from (select '1:2:3:4::'::text as a) s1; a | a -----------+----------- 1:2:3:4:: | 1:2:3:4:: (1 row) select a::ipaddress, a::ip6 from (select '1:2:3:4::1.2.3.4'::text as a) s1; a | a ------------------+------------------ 1:2:3:4::102:304 | 1:2:3:4::102:304 (1 row) select a::ipaddress, a::ip6 from (select '1:2:3:4::5:1.2.3.4'::text as a) s1; a | a ---------------------+--------------------- 1:2:3:4:0:5:102:304 | 1:2:3:4:0:5:102:304 (1 row) select a::ipaddress, a::ip6 from (select '1:2:3:4::7:8'::text as a) s1; a | a --------------+-------------- 1:2:3:4::7:8 | 1:2:3:4::7:8 (1 row) select a::ipaddress, a::ip6 from (select '1:2:3:4::8'::text as a) s1; a | a ------------+------------ 1:2:3:4::8 | 1:2:3:4::8 (1 row) select a::ipaddress, a::ip6 from (select '1:2:3::'::text as a) s1; a | a ---------+--------- 1:2:3:: | 1:2:3:: (1 row) select a::ipaddress, a::ip6 from (select '1:2:3::1.2.3.4'::text as a) s1; a | a ----------------+---------------- 1:2:3::102:304 | 1:2:3::102:304 (1 row) select a::ipaddress, a::ip6 from (select '1:2:3::5:1.2.3.4'::text as a) s1; a | a ------------------+------------------ 1:2:3::5:102:304 | 1:2:3::5:102:304 (1 row) select a::ipaddress, a::ip6 from (select '1:2:3::7:8'::text as a) s1; a | a ------------+------------ 1:2:3::7:8 | 1:2:3::7:8 (1 row) select a::ipaddress, a::ip6 from (select '1:2:3::8'::text as a) s1; a | a ----------+---------- 1:2:3::8 | 1:2:3::8 (1 row) select a::ipaddress, a::ip6 from (select '1:2::'::text as a) s1; a | a -------+------- 1:2:: | 1:2:: (1 row) select a::ipaddress, a::ip6 from (select '1:2::1.2.3.4'::text as a) s1; a | a --------------+-------------- 1:2::102:304 | 1:2::102:304 (1 row) select a::ipaddress, a::ip6 from (select '1:2::5:1.2.3.4'::text as a) s1; a | a ----------------+---------------- 1:2::5:102:304 | 1:2::5:102:304 (1 row) select a::ipaddress, a::ip6 from (select '1:2::7:8'::text as a) s1; a | a ----------+---------- 1:2::7:8 | 1:2::7:8 (1 row) select a::ipaddress, a::ip6 from (select '1:2::8'::text as a) s1; a | a --------+-------- 1:2::8 | 1:2::8 (1 row) select a::ipaddress, a::ip6 from (select '1::'::text as a) s1; a | a -----+----- 1:: | 1:: (1 row) select a::ipaddress, a::ip6 from (select '1::1.2.3.4'::text as a) s1; a | a ------------+------------ 1::102:304 | 1::102:304 (1 row) select a::ipaddress, a::ip6 from (select '1::2:3'::text as a) s1; a | a --------+-------- 1::2:3 | 1::2:3 (1 row) select a::ipaddress, a::ip6 from (select '1::2:3:4'::text as a) s1; a | a ----------+---------- 1::2:3:4 | 1::2:3:4 (1 row) select a::ipaddress, a::ip6 from (select '1::2:3:4:5'::text as a) s1; a | a ------------+------------ 1::2:3:4:5 | 1::2:3:4:5 (1 row) select a::ipaddress, a::ip6 from (select '1::2:3:4:5:6'::text as a) s1; a | a --------------+-------------- 1::2:3:4:5:6 | 1::2:3:4:5:6 (1 row) select a::ipaddress, a::ip6 from (select '1::2:3:4:5:6:7'::text as a) s1; a | a -----------------+----------------- 1:0:2:3:4:5:6:7 | 1:0:2:3:4:5:6:7 (1 row) select a::ipaddress, a::ip6 from (select '1::5:1.2.3.4'::text as a) s1; a | a --------------+-------------- 1::5:102:304 | 1::5:102:304 (1 row) select a::ipaddress, a::ip6 from (select '1::5:11.22.33.44'::text as a) s1; a | a ---------------+--------------- 1::5:b16:212c | 1::5:b16:212c (1 row) select a::ipaddress, a::ip6 from (select '1::7:8'::text as a) s1; a | a --------+-------- 1::7:8 | 1::7:8 (1 row) select a::ipaddress, a::ip6 from (select '1::8'::text as a) s1; a | a ------+------ 1::8 | 1::8 (1 row) select a::ipaddress, a::ip6 from (select '2001:0000:1234:0000:0000:C1C0:ABCD:0876'::text as a) s1; a | a ----------------------------+---------------------------- 2001:0:1234::c1c0:abcd:876 | 2001:0:1234::c1c0:abcd:876 (1 row) select a::ipaddress, a::ip6 from (select '2001:0db8:0000:0000:0000:0000:1428:57ab'::text as a) s1; a | a ---------------------+--------------------- 2001:db8::1428:57ab | 2001:db8::1428:57ab (1 row) select a::ipaddress, a::ip6 from (select '2001:0db8:0000:0000:0000::1428:57ab'::text as a) s1; a | a ---------------------+--------------------- 2001:db8::1428:57ab | 2001:db8::1428:57ab (1 row) select a::ipaddress, a::ip6 from (select '2001:0db8:0:0:0:0:1428:57ab'::text as a) s1; a | a ---------------------+--------------------- 2001:db8::1428:57ab | 2001:db8::1428:57ab (1 row) select a::ipaddress, a::ip6 from (select '2001:0db8:0:0::1428:57ab'::text as a) s1; a | a ---------------------+--------------------- 2001:db8::1428:57ab | 2001:db8::1428:57ab (1 row) select a::ipaddress, a::ip6 from (select '2001:0db8:1234:0000:0000:0000:0000:0000'::text as a) s1; a | a -----------------+----------------- 2001:db8:1234:: | 2001:db8:1234:: (1 row) select a::ipaddress, a::ip6 from (select '2001:0db8:1234::'::text as a) s1; a | a -----------------+----------------- 2001:db8:1234:: | 2001:db8:1234:: (1 row) select a::ipaddress, a::ip6 from (select '2001:0db8:1234:ffff:ffff:ffff:ffff:ffff'::text as a) s1; a | a ----------------------------------------+---------------------------------------- 2001:db8:1234:ffff:ffff:ffff:ffff:ffff | 2001:db8:1234:ffff:ffff:ffff:ffff:ffff (1 row) select a::ipaddress, a::ip6 from (select '2001:0db8:85a3:0000:0000:8a2e:0370:7334'::text as a) s1; a | a ------------------------------+------------------------------ 2001:db8:85a3::8a2e:370:7334 | 2001:db8:85a3::8a2e:370:7334 (1 row) select a::ipaddress, a::ip6 from (select '2001:0db8::1428:57ab'::text as a) s1; a | a ---------------------+--------------------- 2001:db8::1428:57ab | 2001:db8::1428:57ab (1 row) select a::ipaddress, a::ip6 from (select '2001:10::'::text as a) s1; a | a -----------+----------- 2001:10:: | 2001:10:: (1 row) select a::ipaddress, a::ip6 from (select '2001::'::text as a) s1; a | a --------+-------- 2001:: | 2001:: (1 row) select a::ipaddress, a::ip6 from (select '2001:DB8:0:0:8:800:200C:417A'::text as a) s1; a | a ---------------------------+--------------------------- 2001:db8::8:800:200c:417a | 2001:db8::8:800:200c:417a (1 row) select a::ipaddress, a::ip6 from (select '2001:DB8::8:800:200C:417A'::text as a) s1; a | a ---------------------------+--------------------------- 2001:db8::8:800:200c:417a | 2001:db8::8:800:200c:417a (1 row) select a::ipaddress, a::ip6 from (select '2001:db8:85a3:0:0:8a2e:370:7334'::text as a) s1; a | a ------------------------------+------------------------------ 2001:db8:85a3::8a2e:370:7334 | 2001:db8:85a3::8a2e:370:7334 (1 row) select a::ipaddress, a::ip6 from (select '2001:db8:85a3::8a2e:370:7334'::text as a) s1; a | a ------------------------------+------------------------------ 2001:db8:85a3::8a2e:370:7334 | 2001:db8:85a3::8a2e:370:7334 (1 row) select a::ipaddress, a::ip6 from (select '2001:db8::'::text as a) s1; a | a ------------+------------ 2001:db8:: | 2001:db8:: (1 row) select a::ipaddress, a::ip6 from (select '2001:db8::'::text as a) s1; a | a ------------+------------ 2001:db8:: | 2001:db8:: (1 row) select a::ipaddress, a::ip6 from (select '2001:db8::1428:57ab'::text as a) s1; a | a ---------------------+--------------------- 2001:db8::1428:57ab | 2001:db8::1428:57ab (1 row) select a::ipaddress, a::ip6 from (select '2001:db8:a::123'::text as a) s1; a | a -----------------+----------------- 2001:db8:a::123 | 2001:db8:a::123 (1 row) select a::ipaddress, a::ip6 from (select '2002::'::text as a) s1; a | a --------+-------- 2002:: | 2002:: (1 row) select a::ipaddress, a::ip6 from (select '2::10'::text as a) s1; a | a -------+------- 2::10 | 2::10 (1 row) select a::ipaddress, a::ip6 from (select '3ffe:0b00:0000:0000:0001:0000:0000:000a'::text as a) s1; a | a -------------------+------------------- 3ffe:b00::1:0:0:a | 3ffe:b00::1:0:0:a (1 row) select a::ipaddress, a::ip6 from (select '::'::text as a) s1; a | a ----+---- :: | :: (1 row) select a::ipaddress, a::ip6 from (select '::1'::text as a) s1; a | a -----+----- ::1 | ::1 (1 row) select a::ipaddress, a::ip6 from (select '::127.0.0.1'::text as a) s1; a | a -------------+------------- ::127.0.0.1 | ::127.0.0.1 (1 row) select a::ipaddress, a::ip6 from (select '::13.1.68.3'::text as a) s1; a | a -------------+------------- ::13.1.68.3 | ::13.1.68.3 (1 row) select a::ipaddress, a::ip6 from (select '::2:3'::text as a) s1; a | a -----------+----------- ::0.2.0.3 | ::0.2.0.3 (1 row) select a::ipaddress, a::ip6 from (select '::2:3:4'::text as a) s1; a | a ---------+--------- ::2:3:4 | ::2:3:4 (1 row) select a::ipaddress, a::ip6 from (select '::2:3:4:5'::text as a) s1; a | a -----------+----------- ::2:3:4:5 | ::2:3:4:5 (1 row) select a::ipaddress, a::ip6 from (select '::2:3:4:5:6'::text as a) s1; a | a -------------+------------- ::2:3:4:5:6 | ::2:3:4:5:6 (1 row) select a::ipaddress, a::ip6 from (select '::2:3:4:5:6:7'::text as a) s1; a | a ---------------+--------------- ::2:3:4:5:6:7 | ::2:3:4:5:6:7 (1 row) select a::ipaddress, a::ip6 from (select '::2:3:4:5:6:7:8'::text as a) s1; a | a -----------------+----------------- 0:2:3:4:5:6:7:8 | 0:2:3:4:5:6:7:8 (1 row) select a::ipaddress, a::ip6 from (select '::8'::text as a) s1; a | a -----+----- ::8 | ::8 (1 row) select a::ipaddress, a::ip6 from (select '::FFFF:129.144.52.38'::text as a) s1; a | a ----------------------+---------------------- ::ffff:129.144.52.38 | ::ffff:129.144.52.38 (1 row) select a::ipaddress, a::ip6 from (select '::ffff:0:0'::text as a) s1; a | a ----------------+---------------- ::ffff:0.0.0.0 | ::ffff:0.0.0.0 (1 row) select a::ipaddress, a::ip6 from (select '::ffff:0:192.168.1.1'::text as a) s1; a | a ----------------------+---------------------- ::ffff:0:192.168.1.1 | ::ffff:0:192.168.1.1 (1 row) select a::ipaddress, a::ip6 from (select '::ffff:1:1.2.3.4'::text as a) s1; a | a ------------------+------------------ ::ffff:1:102:304 | ::ffff:1:102:304 (1 row) select a::ipaddress, a::ip6 from (select '::ffff:0c22:384e'::text as a) s1; a | a --------------------+-------------------- ::ffff:12.34.56.78 | ::ffff:12.34.56.78 (1 row) select a::ipaddress, a::ip6 from (select '::ffff:12.34.56.78'::text as a) s1; a | a --------------------+-------------------- ::ffff:12.34.56.78 | ::ffff:12.34.56.78 (1 row) select a::ipaddress, a::ip6 from (select '::ffff:192.0.2.128'::text as a) s1; a | a --------------------+-------------------- ::ffff:192.0.2.128 | ::ffff:192.0.2.128 (1 row) select a::ipaddress, a::ip6 from (select '::ffff:192.168.1.1'::text as a) s1; a | a --------------------+-------------------- ::ffff:192.168.1.1 | ::ffff:192.168.1.1 (1 row) select a::ipaddress, a::ip6 from (select '::ffff:192.168.1.26'::text as a) s1; a | a ---------------------+--------------------- ::ffff:192.168.1.26 | ::ffff:192.168.1.26 (1 row) select a::ipaddress, a::ip6 from (select '::ffff:c000:280'::text as a) s1; a | a --------------------+-------------------- ::ffff:192.0.2.128 | ::ffff:192.0.2.128 (1 row) select a::ipaddress, a::ip6 from (select 'FF01:0:0:0:0:0:0:101'::text as a) s1; a | a -----------+----------- ff01::101 | ff01::101 (1 row) select a::ipaddress, a::ip6 from (select 'FF01::101'::text as a) s1; a | a -----------+----------- ff01::101 | ff01::101 (1 row) select a::ipaddress, a::ip6 from (select 'FF02:0000:0000:0000:0000:0000:0000:0001'::text as a) s1; a | a ---------+--------- ff02::1 | ff02::1 (1 row) select a::ipaddress, a::ip6 from (select 'fc00::'::text as a) s1; a | a --------+-------- fc00:: | fc00:: (1 row) select a::ipaddress, a::ip6 from (select 'fe80:0000:0000:0000:0204:61ff:fe9d:f156'::text as a) s1; a | a --------------------------+-------------------------- fe80::204:61ff:fe9d:f156 | fe80::204:61ff:fe9d:f156 (1 row) select a::ipaddress, a::ip6 from (select 'fe80:0:0:0:204:61ff:254.157.241.86'::text as a) s1; a | a --------------------------+-------------------------- fe80::204:61ff:fe9d:f156 | fe80::204:61ff:fe9d:f156 (1 row) select a::ipaddress, a::ip6 from (select 'fe80:0:0:0:204:61ff:fe9d:f156'::text as a) s1; a | a --------------------------+-------------------------- fe80::204:61ff:fe9d:f156 | fe80::204:61ff:fe9d:f156 (1 row) select a::ipaddress, a::ip6 from (select 'fe80::'::text as a) s1; a | a --------+-------- fe80:: | fe80:: (1 row) select a::ipaddress, a::ip6 from (select 'fe80::1'::text as a) s1; a | a ---------+--------- fe80::1 | fe80::1 (1 row) select a::ipaddress, a::ip6 from (select 'fe80::204:61ff:254.157.241.86'::text as a) s1; a | a --------------------------+-------------------------- fe80::204:61ff:fe9d:f156 | fe80::204:61ff:fe9d:f156 (1 row) select a::ipaddress, a::ip6 from (select 'fe80::204:61ff:fe9d:f156'::text as a) s1; a | a --------------------------+-------------------------- fe80::204:61ff:fe9d:f156 | fe80::204:61ff:fe9d:f156 (1 row) select a::ipaddress, a::ip6 from (select 'fe80::217:f2ff:254.7.237.98'::text as a) s1; a | a --------------------------+-------------------------- fe80::217:f2ff:fe07:ed62 | fe80::217:f2ff:fe07:ed62 (1 row) select a::ipaddress, a::ip6 from (select 'fe80::217:f2ff:fe07:ed62'::text as a) s1; a | a --------------------------+-------------------------- fe80::217:f2ff:fe07:ed62 | fe80::217:f2ff:fe07:ed62 (1 row) select a::ipaddress, a::ip6 from (select 'ff02::1'::text as a) s1; a | a ---------+--------- ff02::1 | ff02::1 (1 row) select r::iprange from (select '-'::text as r) s; r --- - (1 row) select r::iprange, r::ip4r from (select '1.2.3.4'::text as r) s; r | r ---------+--------- 1.2.3.4 | 1.2.3.4 (1 row) select r::iprange, r::ip4r from (select '255.255.255.255/32'::text as r) s; r | r -----------------+----------------- 255.255.255.255 | 255.255.255.255 (1 row) select r::iprange, r::ip4r from (select '255.255.255.254/31'::text as r) s; r | r --------------------+-------------------- 255.255.255.254/31 | 255.255.255.254/31 (1 row) select r::iprange, r::ip4r from (select '255.255.255.252/30'::text as r) s; r | r --------------------+-------------------- 255.255.255.252/30 | 255.255.255.252/30 (1 row) select r::iprange, r::ip4r from (select '255.255.255.248/29'::text as r) s; r | r --------------------+-------------------- 255.255.255.248/29 | 255.255.255.248/29 (1 row) select r::iprange, r::ip4r from (select '255.255.255.240/28'::text as r) s; r | r --------------------+-------------------- 255.255.255.240/28 | 255.255.255.240/28 (1 row) select r::iprange, r::ip4r from (select '255.255.255.224/27'::text as r) s; r | r --------------------+-------------------- 255.255.255.224/27 | 255.255.255.224/27 (1 row) select r::iprange, r::ip4r from (select '255.255.255.192/26'::text as r) s; r | r --------------------+-------------------- 255.255.255.192/26 | 255.255.255.192/26 (1 row) select r::iprange, r::ip4r from (select '255.255.255.128/25'::text as r) s; r | r --------------------+-------------------- 255.255.255.128/25 | 255.255.255.128/25 (1 row) select r::iprange, r::ip4r from (select '255.255.255.0/24'::text as r) s; r | r ------------------+------------------ 255.255.255.0/24 | 255.255.255.0/24 (1 row) select r::iprange, r::ip4r from (select '255.255.254.0/23'::text as r) s; r | r ------------------+------------------ 255.255.254.0/23 | 255.255.254.0/23 (1 row) select r::iprange, r::ip4r from (select '255.255.252.0/22'::text as r) s; r | r ------------------+------------------ 255.255.252.0/22 | 255.255.252.0/22 (1 row) select r::iprange, r::ip4r from (select '255.255.248.0/21'::text as r) s; r | r ------------------+------------------ 255.255.248.0/21 | 255.255.248.0/21 (1 row) select r::iprange, r::ip4r from (select '255.255.240.0/20'::text as r) s; r | r ------------------+------------------ 255.255.240.0/20 | 255.255.240.0/20 (1 row) select r::iprange, r::ip4r from (select '255.255.224.0/19'::text as r) s; r | r ------------------+------------------ 255.255.224.0/19 | 255.255.224.0/19 (1 row) select r::iprange, r::ip4r from (select '255.255.192.0/18'::text as r) s; r | r ------------------+------------------ 255.255.192.0/18 | 255.255.192.0/18 (1 row) select r::iprange, r::ip4r from (select '255.255.128.0/17'::text as r) s; r | r ------------------+------------------ 255.255.128.0/17 | 255.255.128.0/17 (1 row) select r::iprange, r::ip4r from (select '255.255.0.0/16'::text as r) s; r | r ----------------+---------------- 255.255.0.0/16 | 255.255.0.0/16 (1 row) select r::iprange, r::ip4r from (select '255.254.0.0/15'::text as r) s; r | r ----------------+---------------- 255.254.0.0/15 | 255.254.0.0/15 (1 row) select r::iprange, r::ip4r from (select '255.252.0.0/14'::text as r) s; r | r ----------------+---------------- 255.252.0.0/14 | 255.252.0.0/14 (1 row) select r::iprange, r::ip4r from (select '255.248.0.0/13'::text as r) s; r | r ----------------+---------------- 255.248.0.0/13 | 255.248.0.0/13 (1 row) select r::iprange, r::ip4r from (select '255.240.0.0/12'::text as r) s; r | r ----------------+---------------- 255.240.0.0/12 | 255.240.0.0/12 (1 row) select r::iprange, r::ip4r from (select '255.224.0.0/11'::text as r) s; r | r ----------------+---------------- 255.224.0.0/11 | 255.224.0.0/11 (1 row) select r::iprange, r::ip4r from (select '255.192.0.0/10'::text as r) s; r | r ----------------+---------------- 255.192.0.0/10 | 255.192.0.0/10 (1 row) select r::iprange, r::ip4r from (select '255.128.0.0/9'::text as r) s; r | r ---------------+--------------- 255.128.0.0/9 | 255.128.0.0/9 (1 row) select r::iprange, r::ip4r from (select '255.0.0.0/8'::text as r) s; r | r -------------+------------- 255.0.0.0/8 | 255.0.0.0/8 (1 row) select r::iprange, r::ip4r from (select '254.0.0.0/7'::text as r) s; r | r -------------+------------- 254.0.0.0/7 | 254.0.0.0/7 (1 row) select r::iprange, r::ip4r from (select '252.0.0.0/6'::text as r) s; r | r -------------+------------- 252.0.0.0/6 | 252.0.0.0/6 (1 row) select r::iprange, r::ip4r from (select '248.0.0.0/5'::text as r) s; r | r -------------+------------- 248.0.0.0/5 | 248.0.0.0/5 (1 row) select r::iprange, r::ip4r from (select '240.0.0.0/4'::text as r) s; r | r -------------+------------- 240.0.0.0/4 | 240.0.0.0/4 (1 row) select r::iprange, r::ip4r from (select '224.0.0.0/3'::text as r) s; r | r -------------+------------- 224.0.0.0/3 | 224.0.0.0/3 (1 row) select r::iprange, r::ip4r from (select '192.0.0.0/2'::text as r) s; r | r -------------+------------- 192.0.0.0/2 | 192.0.0.0/2 (1 row) select r::iprange, r::ip4r from (select '128.0.0.0/1'::text as r) s; r | r -------------+------------- 128.0.0.0/1 | 128.0.0.0/1 (1 row) select r::iprange, r::ip4r from (select '0.0.0.0/0'::text as r) s; r | r -----------+----------- 0.0.0.0/0 | 0.0.0.0/0 (1 row) select r::iprange, r::ip4r from (select '1.2.3.4-5.6.7.8'::text as r) s; r | r -----------------+----------------- 1.2.3.4-5.6.7.8 | 1.2.3.4-5.6.7.8 (1 row) select r::iprange, r::ip4r from (select '5.6.7.8-1.2.3.4'::text as r) s; r | r -----------------+----------------- 1.2.3.4-5.6.7.8 | 1.2.3.4-5.6.7.8 (1 row) select r::iprange, r::ip4r from (select '1.2.3.4-1.2.3.4'::text as r) s; r | r ---------+--------- 1.2.3.4 | 1.2.3.4 (1 row) select r::iprange, r::ip6r from (select '::'::text as r) s; r | r ----+---- :: | :: (1 row) select r::iprange, r::ip6r from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'::text as r) s; r | r -----------------------------------------+----------------------------------------- ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff | ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff (1 row) select r::iprange, r::ip6r from (select '1::2'::text as r) s; r | r ------+------ 1::2 | 1::2 (1 row) select r::iprange, r::ip6r from (select '::-ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'::text as r) s; r | r ------+------ ::/0 | ::/0 (1 row) select r::iprange, r::ip6r from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff-::'::text as r) s; r | r ------+------ ::/0 | ::/0 (1 row) select r::iprange, r::ip6r from (select '1::2-3::4'::text as r) s; r | r -----------+----------- 1::2-3::4 | 1::2-3::4 (1 row) select r::iprange, r::ip6r from (select '3::4-3::4'::text as r) s; r | r ------+------ 3::4 | 3::4 (1 row) select r::iprange, r::ip6r from (select '3::4-1::2'::text as r) s; r | r -----------+----------- 1::2-3::4 | 1::2-3::4 (1 row) select r::iprange, r::ip6r from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128'::text as r) s; r | r -----------------------------------------+----------------------------------------- ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff | ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff (1 row) select r::iprange, r::ip6r from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffe/127'::text as r) s; r | r ---------------------------------------------+--------------------------------------------- ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffe/127 | ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffe/127 (1 row) select r::iprange, r::ip6r from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffc/126'::text as r) s; r | r ---------------------------------------------+--------------------------------------------- ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffc/126 | ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffc/126 (1 row) select r::iprange, r::ip6r from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:fff8/125'::text as r) s; r | r ---------------------------------------------+--------------------------------------------- ffff:ffff:ffff:ffff:ffff:ffff:ffff:fff8/125 | ffff:ffff:ffff:ffff:ffff:ffff:ffff:fff8/125 (1 row) select r::iprange, r::ip6r from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:fff0/124'::text as r) s; r | r ---------------------------------------------+--------------------------------------------- ffff:ffff:ffff:ffff:ffff:ffff:ffff:fff0/124 | ffff:ffff:ffff:ffff:ffff:ffff:ffff:fff0/124 (1 row) select r::iprange, r::ip6r from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ff00/120'::text as r) s; r | r ---------------------------------------------+--------------------------------------------- ffff:ffff:ffff:ffff:ffff:ffff:ffff:ff00/120 | ffff:ffff:ffff:ffff:ffff:ffff:ffff:ff00/120 (1 row) select r::iprange, r::ip6r from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:f000/116'::text as r) s; r | r ---------------------------------------------+--------------------------------------------- ffff:ffff:ffff:ffff:ffff:ffff:ffff:f000/116 | ffff:ffff:ffff:ffff:ffff:ffff:ffff:f000/116 (1 row) select r::iprange, r::ip6r from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:0000/112'::text as r) s; r | r ------------------------------------------+------------------------------------------ ffff:ffff:ffff:ffff:ffff:ffff:ffff:0/112 | ffff:ffff:ffff:ffff:ffff:ffff:ffff:0/112 (1 row) select r::iprange, r::ip6r from (select 'ffff:ffff:ffff:ffff:ffff:ffff:0000:0000/96'::text as r) s; r | r ------------------------------------+------------------------------------ ffff:ffff:ffff:ffff:ffff:ffff::/96 | ffff:ffff:ffff:ffff:ffff:ffff::/96 (1 row) select r::iprange, r::ip6r from (select 'ffff:ffff:ffff:ffff:ffff:0000:0000:0000/80'::text as r) s; r | r -------------------------------+------------------------------- ffff:ffff:ffff:ffff:ffff::/80 | ffff:ffff:ffff:ffff:ffff::/80 (1 row) select r::iprange, r::ip6r from (select 'ffff:ffff:ffff:ffff:fff0:0000:0000:0000/76'::text as r) s; r | r -------------------------------+------------------------------- ffff:ffff:ffff:ffff:fff0::/76 | ffff:ffff:ffff:ffff:fff0::/76 (1 row) select r::iprange, r::ip6r from (select 'ffff:ffff:ffff:ffff:ff00:0000:0000:0000/72'::text as r) s; r | r -------------------------------+------------------------------- ffff:ffff:ffff:ffff:ff00::/72 | ffff:ffff:ffff:ffff:ff00::/72 (1 row) select r::iprange, r::ip6r from (select 'ffff:ffff:ffff:ffff:f000:0000:0000:0000/68'::text as r) s; r | r -------------------------------+------------------------------- ffff:ffff:ffff:ffff:f000::/68 | ffff:ffff:ffff:ffff:f000::/68 (1 row) select r::iprange, r::ip6r from (select 'ffff:ffff:ffff:ffff:e000:0000:0000:0000/67'::text as r) s; r | r -------------------------------+------------------------------- ffff:ffff:ffff:ffff:e000::/67 | ffff:ffff:ffff:ffff:e000::/67 (1 row) select r::iprange, r::ip6r from (select 'ffff:ffff:ffff:ffff:c000:0000:0000:0000/66'::text as r) s; r | r -------------------------------+------------------------------- ffff:ffff:ffff:ffff:c000::/66 | ffff:ffff:ffff:ffff:c000::/66 (1 row) select r::iprange, r::ip6r from (select 'ffff:ffff:ffff:ffff:8000:0000:0000:0000/65'::text as r) s; r | r -------------------------------+------------------------------- ffff:ffff:ffff:ffff:8000::/65 | ffff:ffff:ffff:ffff:8000::/65 (1 row) select r::iprange, r::ip6r from (select 'ffff:ffff:ffff:ffff:0000:0000:0000:0000/64'::text as r) s; r | r --------------------------+-------------------------- ffff:ffff:ffff:ffff::/64 | ffff:ffff:ffff:ffff::/64 (1 row) select r::iprange, r::ip6r from (select 'ffff:ffff:ffff:fffe:0000:0000:0000:0000/63'::text as r) s; r | r --------------------------+-------------------------- ffff:ffff:ffff:fffe::/63 | ffff:ffff:ffff:fffe::/63 (1 row) select r::iprange, r::ip6r from (select 'ffff:ffff:ffff:fffc:0000:0000:0000:0000/62'::text as r) s; r | r --------------------------+-------------------------- ffff:ffff:ffff:fffc::/62 | ffff:ffff:ffff:fffc::/62 (1 row) select r::iprange, r::ip6r from (select 'ffff:ffff:ffff:fff8:0000:0000:0000:0000/61'::text as r) s; r | r --------------------------+-------------------------- ffff:ffff:ffff:fff8::/61 | ffff:ffff:ffff:fff8::/61 (1 row) select r::iprange, r::ip6r from (select 'ffff:ffff:ffff:fff0:0000:0000:0000:0000/60'::text as r) s; r | r --------------------------+-------------------------- ffff:ffff:ffff:fff0::/60 | ffff:ffff:ffff:fff0::/60 (1 row) select r::iprange, r::ip6r from (select 'ffff:ffff:ffff:ff00:0000:0000:0000:0000/56'::text as r) s; r | r --------------------------+-------------------------- ffff:ffff:ffff:ff00::/56 | ffff:ffff:ffff:ff00::/56 (1 row) select r::iprange, r::ip6r from (select 'ffff:ffff:ffff:f000:0000:0000:0000:0000/52'::text as r) s; r | r --------------------------+-------------------------- ffff:ffff:ffff:f000::/52 | ffff:ffff:ffff:f000::/52 (1 row) select r::iprange, r::ip6r from (select 'ffff:ffff:ffff:0000:0000:0000:0000:0000/48'::text as r) s; r | r ---------------------+--------------------- ffff:ffff:ffff::/48 | ffff:ffff:ffff::/48 (1 row) select r::iprange, r::ip6r from (select 'ffff:ffff:0000:0000:0000:0000:0000:0000/32'::text as r) s; r | r ----------------+---------------- ffff:ffff::/32 | ffff:ffff::/32 (1 row) select r::iprange, r::ip6r from (select 'ffff:0000:0000:0000:0000:0000:0000:0000/16'::text as r) s; r | r -----------+----------- ffff::/16 | ffff::/16 (1 row) select r::iprange, r::ip6r from (select 'fff0:0000:0000:0000:0000:0000:0000:0000/12'::text as r) s; r | r -----------+----------- fff0::/12 | fff0::/12 (1 row) select r::iprange, r::ip6r from (select 'ff00:0000:0000:0000:0000:0000:0000:0000/8'::text as r) s; r | r ----------+---------- ff00::/8 | ff00::/8 (1 row) select r::iprange, r::ip6r from (select 'f000:0000:0000:0000:0000:0000:0000:0000/4'::text as r) s; r | r ----------+---------- f000::/4 | f000::/4 (1 row) select r::iprange, r::ip6r from (select 'e000:0000:0000:0000:0000:0000:0000:0000/3'::text as r) s; r | r ----------+---------- e000::/3 | e000::/3 (1 row) select r::iprange, r::ip6r from (select 'c000:0000:0000:0000:0000:0000:0000:0000/2'::text as r) s; r | r ----------+---------- c000::/2 | c000::/2 (1 row) select r::iprange, r::ip6r from (select '8000:0000:0000:0000:0000:0000:0000:0000/1'::text as r) s; r | r ----------+---------- 8000::/1 | 8000::/1 (1 row) select r::iprange, r::ip6r from (select '0000:0000:0000:0000:0000:0000:0000:0000/0'::text as r) s; r | r ------+------ ::/0 | ::/0 (1 row) -- invalid text casts select '1.2.3'::text::ip4; ERROR: invalid IP4 value in text select '0'::text::ip4; ERROR: invalid IP4 value in text select ' 1.2.3.4'::text::ip4; ERROR: invalid IP4 value in text select '1.2.3.4 '::text::ip4; ERROR: invalid IP4 value in text select '0.0.0.256'::text::ip4; ERROR: invalid IP4 value in text select '0.0.256'::text::ip4; ERROR: invalid IP4 value in text select '0..255.0'::text::ip4; ERROR: invalid IP4 value in text select '+0.255.0.0'::text::ip4; ERROR: invalid IP4 value in text select '1.2.3.4-1.2.3.4'::text::ip4; ERROR: invalid IP4 value in text select '1.2.3'::text::ip4r; ERROR: invalid IP4R value in text select '255.255.255.255.255.255.255.255.255'::text::ip4r; ERROR: invalid IP4R value in text select '255.255.255.255.255-255.255.255.255.255'::text::ip4r; ERROR: invalid IP4R value in text select '255.255.255.255-1.2.3.4.5'::text::ip4r; ERROR: invalid IP4R value in text select '255.255.255.255-1.2.3'::text::ip4r; ERROR: invalid IP4R value in text select '0.0.0.1/31'::text::ip4r; ERROR: invalid IP4R value in text select '0.0.0.1/30'::text::ip4r; ERROR: invalid IP4R value in text select '0.0.0.1/29'::text::ip4r; ERROR: invalid IP4R value in text select '0.0.0.1/28'::text::ip4r; ERROR: invalid IP4R value in text select '0.0.0.1/27'::text::ip4r; ERROR: invalid IP4R value in text select '0.0.0.1/26'::text::ip4r; ERROR: invalid IP4R value in text select '0.0.0.1/25'::text::ip4r; ERROR: invalid IP4R value in text select '0.0.0.1/24'::text::ip4r; ERROR: invalid IP4R value in text select '0.0.0.1/23'::text::ip4r; ERROR: invalid IP4R value in text select '0.0.0.1/22'::text::ip4r; ERROR: invalid IP4R value in text select '0.0.0.1/21'::text::ip4r; ERROR: invalid IP4R value in text select '0.0.0.1/20'::text::ip4r; ERROR: invalid IP4R value in text select '0.0.0.1/19'::text::ip4r; ERROR: invalid IP4R value in text select '0.0.0.1/18'::text::ip4r; ERROR: invalid IP4R value in text select '0.0.0.1/17'::text::ip4r; ERROR: invalid IP4R value in text select '0.0.0.1/16'::text::ip4r; ERROR: invalid IP4R value in text select '0.0.0.1/15'::text::ip4r; ERROR: invalid IP4R value in text select '0.0.0.1/14'::text::ip4r; ERROR: invalid IP4R value in text select '0.0.0.1/13'::text::ip4r; ERROR: invalid IP4R value in text select '0.0.0.1/12'::text::ip4r; ERROR: invalid IP4R value in text select '0.0.0.1/11'::text::ip4r; ERROR: invalid IP4R value in text select '0.0.0.1/10'::text::ip4r; ERROR: invalid IP4R value in text select '0.0.0.1/9'::text::ip4r; ERROR: invalid IP4R value in text select '0.0.0.1/8'::text::ip4r; ERROR: invalid IP4R value in text select '0.0.0.1/7'::text::ip4r; ERROR: invalid IP4R value in text select '0.0.0.1/6'::text::ip4r; ERROR: invalid IP4R value in text select '0.0.0.1/5'::text::ip4r; ERROR: invalid IP4R value in text select '0.0.0.1/4'::text::ip4r; ERROR: invalid IP4R value in text select '0.0.0.1/3'::text::ip4r; ERROR: invalid IP4R value in text select '0.0.0.1/2'::text::ip4r; ERROR: invalid IP4R value in text select '0.0.0.1/1'::text::ip4r; ERROR: invalid IP4R value in text select '0.0.0.1/0'::text::ip4r; ERROR: invalid IP4R value in text select '0.0.0.2/30'::text::ip4r; ERROR: invalid IP4R value in text select '0.0.0.4/29'::text::ip4r; ERROR: invalid IP4R value in text select '0.0.0.8/28'::text::ip4r; ERROR: invalid IP4R value in text select '0.0.0.16/27'::text::ip4r; ERROR: invalid IP4R value in text select '0.0.0.32/26'::text::ip4r; ERROR: invalid IP4R value in text select '0.0.0.64/25'::text::ip4r; ERROR: invalid IP4R value in text select '0.0.0.128/24'::text::ip4r; ERROR: invalid IP4R value in text select '0.0.1.0/23'::text::ip4r; ERROR: invalid IP4R value in text select '0.0.2.0/22'::text::ip4r; ERROR: invalid IP4R value in text select '0.0.4.0/21'::text::ip4r; ERROR: invalid IP4R value in text select '0.0.8.0/20'::text::ip4r; ERROR: invalid IP4R value in text select '0.0.16.0/19'::text::ip4r; ERROR: invalid IP4R value in text select '0.0.32.0/18'::text::ip4r; ERROR: invalid IP4R value in text select '0.0.64.0/17'::text::ip4r; ERROR: invalid IP4R value in text select '0.0.128.0/16'::text::ip4r; ERROR: invalid IP4R value in text select '0.1.0.0/15'::text::ip4r; ERROR: invalid IP4R value in text select '0.2.0.0/14'::text::ip4r; ERROR: invalid IP4R value in text select '0.4.0.0/13'::text::ip4r; ERROR: invalid IP4R value in text select '0.8.0.0/12'::text::ip4r; ERROR: invalid IP4R value in text select '0.16.0.0/11'::text::ip4r; ERROR: invalid IP4R value in text select '0.32.0.0/10'::text::ip4r; ERROR: invalid IP4R value in text select '0.64.0.0/9'::text::ip4r; ERROR: invalid IP4R value in text select '0.128.0.0/8'::text::ip4r; ERROR: invalid IP4R value in text select '1.0.0.0/7'::text::ip4r; ERROR: invalid IP4R value in text select '2.0.0.0/6'::text::ip4r; ERROR: invalid IP4R value in text select '4.0.0.0/5'::text::ip4r; ERROR: invalid IP4R value in text select '8.0.0.0/4'::text::ip4r; ERROR: invalid IP4R value in text select '16.0.0.0/3'::text::ip4r; ERROR: invalid IP4R value in text select '32.0.0.0/2'::text::ip4r; ERROR: invalid IP4R value in text select '64.0.0.0/1'::text::ip4r; ERROR: invalid IP4R value in text select '128.0.0.0/0'::text::ip4r; ERROR: invalid IP4R value in text select '0.0.0.0/33'::text::ip4r; ERROR: invalid IP4R value in text select '0.0.0.0/3.0'::text::ip4r; ERROR: invalid IP4R value in text select '0.0.0.0/+33'::text::ip4r; ERROR: invalid IP4R value in text select ''::text::ip6; ERROR: invalid IP6 value in text select '02001:0000:1234:0000:0000:C1C0:ABCD:0876'::text::ip6; ERROR: invalid IP6 value in text select '1.2.3.4:1111:2222:3333:4444::5555'::text::ip6; ERROR: invalid IP6 value in text select '1.2.3.4:1111:2222:3333::5555'::text::ip6; ERROR: invalid IP6 value in text select '1.2.3.4:1111:2222::5555'::text::ip6; ERROR: invalid IP6 value in text select '1.2.3.4:1111::5555'::text::ip6; ERROR: invalid IP6 value in text select '1.2.3.4::'::text::ip6; ERROR: invalid IP6 value in text select '1.2.3.4::5555'::text::ip6; ERROR: invalid IP6 value in text select '1111:'::text::ip6; ERROR: invalid IP6 value in text select '1111:2222:3333:4444::5555:'::text::ip6; ERROR: invalid IP6 value in text select '1111:2222:3333::5555:'::text::ip6; ERROR: invalid IP6 value in text select '1111:2222::5555:'::text::ip6; ERROR: invalid IP6 value in text select '1111::5555:'::text::ip6; ERROR: invalid IP6 value in text select '123'::text::ip6; ERROR: invalid IP6 value in text select '12345::6:7:8'::text::ip6; ERROR: invalid IP6 value in text select '127.0.0.1'::text::ip6; ERROR: invalid IP6 value in text select '1:2:3:4:5:6:7:8:9'::text::ip6; ERROR: invalid IP6 value in text select '1:2:3::4:5:6:7:8:9'::text::ip6; ERROR: invalid IP6 value in text select '1:2:3::4:5::7:8'::text::ip6; ERROR: invalid IP6 value in text select '1::1.2.256.4'::text::ip6; ERROR: invalid IP6 value in text select '1::1.2.3.256'::text::ip6; ERROR: invalid IP6 value in text select '1::1.2.3.300'::text::ip6; ERROR: invalid IP6 value in text select '1::1.2.3.900'::text::ip6; ERROR: invalid IP6 value in text select '1::1.2.300.4'::text::ip6; ERROR: invalid IP6 value in text select '1::1.2.900.4'::text::ip6; ERROR: invalid IP6 value in text select '1::1.256.3.4'::text::ip6; ERROR: invalid IP6 value in text select '1::1.300.3.4'::text::ip6; ERROR: invalid IP6 value in text select '1::1.900.3.4'::text::ip6; ERROR: invalid IP6 value in text select '1::256.2.3.4'::text::ip6; ERROR: invalid IP6 value in text select '1::260.2.3.4'::text::ip6; ERROR: invalid IP6 value in text select '1::2::3'::text::ip6; ERROR: invalid IP6 value in text select '1::300.2.3.4'::text::ip6; ERROR: invalid IP6 value in text select '1::300.300.300.300'::text::ip6; ERROR: invalid IP6 value in text select '1::3000.30.30.30'::text::ip6; ERROR: invalid IP6 value in text select '1::400.2.3.4'::text::ip6; ERROR: invalid IP6 value in text select '1::5:1.2.256.4'::text::ip6; ERROR: invalid IP6 value in text select '1::5:1.2.3.256'::text::ip6; ERROR: invalid IP6 value in text select '1::5:1.2.3.300'::text::ip6; ERROR: invalid IP6 value in text select '1::5:1.2.3.900'::text::ip6; ERROR: invalid IP6 value in text select '1::5:1.2.300.4'::text::ip6; ERROR: invalid IP6 value in text select '1::5:1.2.900.4'::text::ip6; ERROR: invalid IP6 value in text select '1::5:1.256.3.4'::text::ip6; ERROR: invalid IP6 value in text select '1::5:1.300.3.4'::text::ip6; ERROR: invalid IP6 value in text select '1::5:1.900.3.4'::text::ip6; ERROR: invalid IP6 value in text select '1::5:256.2.3.4'::text::ip6; ERROR: invalid IP6 value in text select '1::5:260.2.3.4'::text::ip6; ERROR: invalid IP6 value in text select '1::5:300.2.3.4'::text::ip6; ERROR: invalid IP6 value in text select '1::5:300.300.300.300'::text::ip6; ERROR: invalid IP6 value in text select '1::5:3000.30.30.30'::text::ip6; ERROR: invalid IP6 value in text select '1::5:400.2.3.4'::text::ip6; ERROR: invalid IP6 value in text select '1::5:900.2.3.4'::text::ip6; ERROR: invalid IP6 value in text select '1::900.2.3.4'::text::ip6; ERROR: invalid IP6 value in text select '1:::3:4:5'::text::ip6; ERROR: invalid IP6 value in text select '2001:0000:1234: 0000:0000:C1C0:ABCD:0876'::text::ip6; ERROR: invalid IP6 value in text select '2001:0000:1234:0000:00001:C1C0:ABCD:0876'::text::ip6; ERROR: invalid IP6 value in text select '2001:0000:1234:0000:0000:C1C0:ABCD:0876 0'::text::ip6; ERROR: invalid IP6 value in text select '2001::FFD3::57ab'::text::ip6; ERROR: invalid IP6 value in text select '2001:DB8:0:0:8:800:200C:417A:221'::text::ip6; ERROR: invalid IP6 value in text select '2001:db8:85a3::8a2e:37023:7334'::text::ip6; ERROR: invalid IP6 value in text select '2001:db8:85a3::8a2e:370k:7334'::text::ip6; ERROR: invalid IP6 value in text select '3ffe:0b00:0000:0001:0000:0000:000a'::text::ip6; ERROR: invalid IP6 value in text select '3ffe:b00::1::a'::text::ip6; ERROR: invalid IP6 value in text select ':'::text::ip6; ERROR: invalid IP6 value in text select ':1111:2222:3333:4444::5555'::text::ip6; ERROR: invalid IP6 value in text select ':1111:2222:3333::5555'::text::ip6; ERROR: invalid IP6 value in text select ':1111:2222::5555'::text::ip6; ERROR: invalid IP6 value in text select ':1111::5555'::text::ip6; ERROR: invalid IP6 value in text select '::1.2.256.4'::text::ip6; ERROR: invalid IP6 value in text select '::1.2.3.256'::text::ip6; ERROR: invalid IP6 value in text select '::1.2.3.300'::text::ip6; ERROR: invalid IP6 value in text select '::1.2.3.900'::text::ip6; ERROR: invalid IP6 value in text select '::1.2.300.4'::text::ip6; ERROR: invalid IP6 value in text select '::1.2.900.4'::text::ip6; ERROR: invalid IP6 value in text select '::1.256.3.4'::text::ip6; ERROR: invalid IP6 value in text select '::1.300.3.4'::text::ip6; ERROR: invalid IP6 value in text select '::1.900.3.4'::text::ip6; ERROR: invalid IP6 value in text select '::1111:2222:3333:4444:5555:6666::'::text::ip6; ERROR: invalid IP6 value in text select '::256.2.3.4'::text::ip6; ERROR: invalid IP6 value in text select '::260.2.3.4'::text::ip6; ERROR: invalid IP6 value in text select '::300.2.3.4'::text::ip6; ERROR: invalid IP6 value in text select '::300.300.300.300'::text::ip6; ERROR: invalid IP6 value in text select '::3000.30.30.30'::text::ip6; ERROR: invalid IP6 value in text select '::400.2.3.4'::text::ip6; ERROR: invalid IP6 value in text select '::5555:'::text::ip6; ERROR: invalid IP6 value in text select '::900.2.3.4'::text::ip6; ERROR: invalid IP6 value in text select ':::'::text::ip6; ERROR: invalid IP6 value in text select ':::5555'::text::ip6; ERROR: invalid IP6 value in text select '::ffff:2.3.4'::text::ip6; ERROR: invalid IP6 value in text select '::ffff:257.1.2.3'::text::ip6; ERROR: invalid IP6 value in text select 'FF01::101::2'::text::ip6; ERROR: invalid IP6 value in text select 'FF02:0000:0000:0000:0000:0000:0000:0000:0001'::text::ip6; ERROR: invalid IP6 value in text select 'ldkfj'::text::ip6; ERROR: invalid IP6 value in text select '::-::-::'::text::ip6r; ERROR: invalid IP6R value in text select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff-ffff'::text::ip6r; ERROR: invalid IP6R value in text select '::-ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'::text::ip6r; ERROR: invalid IP6R value in text select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff-::'::text::ip6r; ERROR: invalid IP6R value in text select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128'::text::ip6r; ERROR: invalid IP6R value in text select '0000:0000:0000:0000:0000:0000:0000:0001/127'::text::ip6r; ERROR: invalid IP6R value in text select '0000:0000:0000:0000:0000:0000:0000:0001/120'::text::ip6r; ERROR: invalid IP6R value in text select '0000:0000:0000:0000:0000:0000:0000:0001/112'::text::ip6r; ERROR: invalid IP6R value in text select '0000:0000:0000:0000:0000:0000:0000:0001/96'::text::ip6r; ERROR: invalid IP6R value in text select '0000:0000:0000:0000:0000:0000:0000:0001/80'::text::ip6r; ERROR: invalid IP6R value in text select '0000:0000:0000:0000:0000:0000:0000:0001/64'::text::ip6r; ERROR: invalid IP6R value in text select '0000:0000:0000:0000:0000:0000:0000:0001/48'::text::ip6r; ERROR: invalid IP6R value in text select '0000:0000:0000:0000:0000:0000:0000:0001/32'::text::ip6r; ERROR: invalid IP6R value in text select '0000:0000:0000:0000:0000:0000:0000:0001/16'::text::ip6r; ERROR: invalid IP6R value in text select '0000:0000:0000:0000:0000:0000:0000:0001/8'::text::ip6r; ERROR: invalid IP6R value in text select '0000:0000:0000:0000:0000:0000:0000:0001/4'::text::ip6r; ERROR: invalid IP6R value in text select '0000:0000:0000:0000:0000:0000:0000:0001/0'::text::ip6r; ERROR: invalid IP6R value in text select '0000:0000:0000:0000:0000:0000:0000:0008/124'::text::ip6r; ERROR: invalid IP6R value in text select '0000:0000:0000:0000:0000:0000:0000:0080/120'::text::ip6r; ERROR: invalid IP6R value in text select '0000:0000:0000:0000:0000:0000:0000:8000/112'::text::ip6r; ERROR: invalid IP6R value in text select '0000:0000:0000:0000:0000:0000:8000:0000/96'::text::ip6r; ERROR: invalid IP6R value in text select '0000:0000:0000:0000:0000:8000:0000:0000/80'::text::ip6r; ERROR: invalid IP6R value in text select '0000:0000:0000:0000:8000:0000:0000:0000/64'::text::ip6r; ERROR: invalid IP6R value in text select '0000:0000:0000:8000:0000:0000:0000:0000/48'::text::ip6r; ERROR: invalid IP6R value in text select '0000:0000:8000:0000:0000:0000:0000:0000/32'::text::ip6r; ERROR: invalid IP6R value in text select '0000:8000:0000:0000:0000:0000:0000:0000/16'::text::ip6r; ERROR: invalid IP6R value in text select '0080:0000:0000:0000:0000:0000:0000:0000/8'::text::ip6r; ERROR: invalid IP6R value in text select '0800:0000:0000:0000:0000:0000:0000:0000/4'::text::ip6r; ERROR: invalid IP6R value in text select '8000:0000:0000:0000:0000:0000:0000:0000/0'::text::ip6r; ERROR: invalid IP6R value in text select '::/129'::text::ip6r; ERROR: invalid IP6R value in text select '::/255'::text::ip6r; ERROR: invalid IP6R value in text select '::/256'::text::ip6r; ERROR: invalid IP6R value in text select '::/+0'::text::ip6r; ERROR: invalid IP6R value in text select '::/0-0'::text::ip6r; ERROR: invalid IP6R value in text select '::-::/0'::text::ip6r; ERROR: invalid IP6R value in text select '1.2.3'::text::ipaddress; ERROR: invalid IP value in text select '0'::text::ipaddress; ERROR: invalid IP value in text select ' 1.2.3.4'::text::ipaddress; ERROR: invalid IP value in text select '1.2.3.4 '::text::ipaddress; ERROR: invalid IP value in text select '0.0.0.256'::text::ipaddress; ERROR: invalid IP value in text select '0.0.256'::text::ipaddress; ERROR: invalid IP value in text select '0..255.0'::text::ipaddress; ERROR: invalid IP value in text select '+0.255.0.0'::text::ipaddress; ERROR: invalid IP value in text select '1.2.3.4-1.2.3.4'::text::ipaddress; ERROR: invalid IP value in text select ''::text::ipaddress; ERROR: invalid IP value in text select '02001:0000:1234:0000:0000:C1C0:ABCD:0876'::text::ipaddress; ERROR: invalid IP value in text select '1.2.3.4:1111:2222:3333:4444::5555'::text::ipaddress; ERROR: invalid IP value in text select '1.2.3.4:1111:2222:3333::5555'::text::ipaddress; ERROR: invalid IP value in text select '1.2.3.4:1111:2222::5555'::text::ipaddress; ERROR: invalid IP value in text select '1.2.3.4:1111::5555'::text::ipaddress; ERROR: invalid IP value in text select '1.2.3.4::'::text::ipaddress; ERROR: invalid IP value in text select '1.2.3.4::5555'::text::ipaddress; ERROR: invalid IP value in text select '1111:'::text::ipaddress; ERROR: invalid IP value in text select '1111:2222:3333:4444::5555:'::text::ipaddress; ERROR: invalid IP value in text select '1111:2222:3333::5555:'::text::ipaddress; ERROR: invalid IP value in text select '1111:2222::5555:'::text::ipaddress; ERROR: invalid IP value in text select '1111::5555:'::text::ipaddress; ERROR: invalid IP value in text select '123'::text::ipaddress; ERROR: invalid IP value in text select '12345::6:7:8'::text::ipaddress; ERROR: invalid IP value in text select '1:2:3:4:5:6:7:8:9'::text::ipaddress; ERROR: invalid IP value in text select '1:2:3::4:5:6:7:8:9'::text::ipaddress; ERROR: invalid IP value in text select '1:2:3::4:5::7:8'::text::ipaddress; ERROR: invalid IP value in text select '1::1.2.256.4'::text::ipaddress; ERROR: invalid IP value in text select '1::1.2.3.256'::text::ipaddress; ERROR: invalid IP value in text select '1::1.2.3.300'::text::ipaddress; ERROR: invalid IP value in text select '1::1.2.3.900'::text::ipaddress; ERROR: invalid IP value in text select '1::1.2.300.4'::text::ipaddress; ERROR: invalid IP value in text select '1::1.2.900.4'::text::ipaddress; ERROR: invalid IP value in text select '1::1.256.3.4'::text::ipaddress; ERROR: invalid IP value in text select '1::1.300.3.4'::text::ipaddress; ERROR: invalid IP value in text select '1::1.900.3.4'::text::ipaddress; ERROR: invalid IP value in text select '1::256.2.3.4'::text::ipaddress; ERROR: invalid IP value in text select '1::260.2.3.4'::text::ipaddress; ERROR: invalid IP value in text select '1::2::3'::text::ipaddress; ERROR: invalid IP value in text select '1::300.2.3.4'::text::ipaddress; ERROR: invalid IP value in text select '1::300.300.300.300'::text::ipaddress; ERROR: invalid IP value in text select '1::3000.30.30.30'::text::ipaddress; ERROR: invalid IP value in text select '1::400.2.3.4'::text::ipaddress; ERROR: invalid IP value in text select '1::5:1.2.256.4'::text::ipaddress; ERROR: invalid IP value in text select '1::5:1.2.3.256'::text::ipaddress; ERROR: invalid IP value in text select '1::5:1.2.3.300'::text::ipaddress; ERROR: invalid IP value in text select '1::5:1.2.3.900'::text::ipaddress; ERROR: invalid IP value in text select '1::5:1.2.300.4'::text::ipaddress; ERROR: invalid IP value in text select '1::5:1.2.900.4'::text::ipaddress; ERROR: invalid IP value in text select '1::5:1.256.3.4'::text::ipaddress; ERROR: invalid IP value in text select '1::5:1.300.3.4'::text::ipaddress; ERROR: invalid IP value in text select '1::5:1.900.3.4'::text::ipaddress; ERROR: invalid IP value in text select '1::5:256.2.3.4'::text::ipaddress; ERROR: invalid IP value in text select '1::5:260.2.3.4'::text::ipaddress; ERROR: invalid IP value in text select '1::5:300.2.3.4'::text::ipaddress; ERROR: invalid IP value in text select '1::5:300.300.300.300'::text::ipaddress; ERROR: invalid IP value in text select '1::5:3000.30.30.30'::text::ipaddress; ERROR: invalid IP value in text select '1::5:400.2.3.4'::text::ipaddress; ERROR: invalid IP value in text select '1::5:900.2.3.4'::text::ipaddress; ERROR: invalid IP value in text select '1::900.2.3.4'::text::ipaddress; ERROR: invalid IP value in text select '1:::3:4:5'::text::ipaddress; ERROR: invalid IP value in text select '2001:0000:1234: 0000:0000:C1C0:ABCD:0876'::text::ipaddress; ERROR: invalid IP value in text select '2001:0000:1234:0000:00001:C1C0:ABCD:0876'::text::ipaddress; ERROR: invalid IP value in text select '2001:0000:1234:0000:0000:C1C0:ABCD:0876 0'::text::ipaddress; ERROR: invalid IP value in text select '2001::FFD3::57ab'::text::ipaddress; ERROR: invalid IP value in text select '2001:DB8:0:0:8:800:200C:417A:221'::text::ipaddress; ERROR: invalid IP value in text select '2001:db8:85a3::8a2e:37023:7334'::text::ipaddress; ERROR: invalid IP value in text select '2001:db8:85a3::8a2e:370k:7334'::text::ipaddress; ERROR: invalid IP value in text select '3ffe:0b00:0000:0001:0000:0000:000a'::text::ipaddress; ERROR: invalid IP value in text select '3ffe:b00::1::a'::text::ipaddress; ERROR: invalid IP value in text select ':'::text::ipaddress; ERROR: invalid IP value in text select ':1111:2222:3333:4444::5555'::text::ipaddress; ERROR: invalid IP value in text select ':1111:2222:3333::5555'::text::ipaddress; ERROR: invalid IP value in text select ':1111:2222::5555'::text::ipaddress; ERROR: invalid IP value in text select ':1111::5555'::text::ipaddress; ERROR: invalid IP value in text select '::1.2.256.4'::text::ipaddress; ERROR: invalid IP value in text select '::1.2.3.256'::text::ipaddress; ERROR: invalid IP value in text select '::1.2.3.300'::text::ipaddress; ERROR: invalid IP value in text select '::1.2.3.900'::text::ipaddress; ERROR: invalid IP value in text select '::1.2.300.4'::text::ipaddress; ERROR: invalid IP value in text select '::1.2.900.4'::text::ipaddress; ERROR: invalid IP value in text select '::1.256.3.4'::text::ipaddress; ERROR: invalid IP value in text select '::1.300.3.4'::text::ipaddress; ERROR: invalid IP value in text select '::1.900.3.4'::text::ipaddress; ERROR: invalid IP value in text select '::1111:2222:3333:4444:5555:6666::'::text::ipaddress; ERROR: invalid IP value in text select '::256.2.3.4'::text::ipaddress; ERROR: invalid IP value in text select '::260.2.3.4'::text::ipaddress; ERROR: invalid IP value in text select '::300.2.3.4'::text::ipaddress; ERROR: invalid IP value in text select '::300.300.300.300'::text::ipaddress; ERROR: invalid IP value in text select '::3000.30.30.30'::text::ipaddress; ERROR: invalid IP value in text select '::400.2.3.4'::text::ipaddress; ERROR: invalid IP value in text select '::5555:'::text::ipaddress; ERROR: invalid IP value in text select '::900.2.3.4'::text::ipaddress; ERROR: invalid IP value in text select ':::'::text::ipaddress; ERROR: invalid IP value in text select ':::5555'::text::ipaddress; ERROR: invalid IP value in text select '::ffff:2.3.4'::text::ipaddress; ERROR: invalid IP value in text select '::ffff:257.1.2.3'::text::ipaddress; ERROR: invalid IP value in text select 'FF01::101::2'::text::ipaddress; ERROR: invalid IP value in text select 'FF02:0000:0000:0000:0000:0000:0000:0000:0001'::text::ipaddress; ERROR: invalid IP value in text select 'ldkfj'::text::ipaddress; ERROR: invalid IP value in text -- numeric casts select n::ip4 from (select 0::bigint as n) s; n --------- 0.0.0.0 (1 row) select n::ip4 from (select 256::bigint as n) s; n --------- 0.0.1.0 (1 row) select n::ip4 from (select 65536::bigint as n) s; n --------- 0.1.0.0 (1 row) select n::ip4 from (select 16777216::bigint as n) s; n --------- 1.0.0.0 (1 row) select n::ip4 from (select -1::bigint as n) s; n ----------------- 255.255.255.255 (1 row) select n::ip4 from (select -2147483647::bigint as n) s; n ----------- 128.0.0.1 (1 row) select n::ip4 from (select -2147483648::bigint as n) s; n ----------- 128.0.0.0 (1 row) select n::ip4 from (select 2147483647::bigint as n) s; n ----------------- 127.255.255.255 (1 row) select n::ip4 from (select 2147483648::bigint as n) s; n ----------- 128.0.0.0 (1 row) select n::ip4 from (select 4294967295::bigint as n) s; n ----------------- 255.255.255.255 (1 row) select n::ip4 from (select 0::float8 as n) s; n --------- 0.0.0.0 (1 row) select n::ip4 from (select 256::float8 as n) s; n --------- 0.0.1.0 (1 row) select n::ip4 from (select 65536::float8 as n) s; n --------- 0.1.0.0 (1 row) select n::ip4 from (select 16777216::float8 as n) s; n --------- 1.0.0.0 (1 row) select n::ip4 from (select -1::float8 as n) s; n ----------------- 255.255.255.255 (1 row) select n::ip4 from (select -2147483647::float8 as n) s; n ----------- 128.0.0.1 (1 row) select n::ip4 from (select -2147483648::float8 as n) s; n ----------- 128.0.0.0 (1 row) select n::ip4 from (select 2147483647::float8 as n) s; n ----------------- 127.255.255.255 (1 row) select n::ip4 from (select 2147483648::float8 as n) s; n ----------- 128.0.0.0 (1 row) select n::ip4 from (select 4294967295::float8 as n) s; n ----------------- 255.255.255.255 (1 row) select n::ip4 from (select 0::numeric as n) s; n --------- 0.0.0.0 (1 row) select n::ip4 from (select 256::numeric as n) s; n --------- 0.0.1.0 (1 row) select n::ip4 from (select 65536::numeric as n) s; n --------- 0.1.0.0 (1 row) select n::ip4 from (select 16777216::numeric as n) s; n --------- 1.0.0.0 (1 row) select n::ip4 from (select -1::numeric as n) s; n ----------------- 255.255.255.255 (1 row) select n::ip4 from (select -2147483647::numeric as n) s; n ----------- 128.0.0.1 (1 row) select n::ip4 from (select -2147483648::numeric as n) s; n ----------- 128.0.0.0 (1 row) select n::ip4 from (select 2147483647::numeric as n) s; n ----------------- 127.255.255.255 (1 row) select n::ip4 from (select 2147483648::numeric as n) s; n ----------- 128.0.0.0 (1 row) select n::ip4 from (select 4294967295::numeric as n) s; n ----------------- 255.255.255.255 (1 row) select n::ip6 from (select 0::numeric as n) s; n ---- :: (1 row) select n::ip6 from (select 256::numeric as n) s; n ------- ::100 (1 row) select n::ip6 from (select 65536::numeric as n) s; n ----------- ::0.1.0.0 (1 row) select n::ip6 from (select 16777216::numeric as n) s; n ----------- ::1.0.0.0 (1 row) select n::ip6 from (select 4294967296::numeric as n) s; n --------- ::1:0:0 (1 row) select n::ip6 from (select 281474976710656::numeric as n) s; n ----------- ::1:0:0:0 (1 row) select n::ip6 from (select 18446744073709551616::numeric as n) s; n ----------- 0:0:0:1:: (1 row) select n::ip6 from (select 1208925819614629174706176::numeric as n) s; n --------- 0:0:1:: (1 row) select n::ip6 from (select 79228162514264337593543950336::numeric as n) s; n ------- 0:1:: (1 row) select n::ip6 from (select 5192296858534827628530496329220096::numeric as n) s; n ----- 1:: (1 row) select n::ip6 from (select 170141183460469231731687303715884105728::numeric as n) s; n -------- 8000:: (1 row) select n::ip6 from (select 340282366920938463463374607431768211455::numeric as n) s; n ----------------------------------------- ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff (1 row) select a::numeric, a::ipaddress::numeric, a::bigint, a::float8 from (select '0.0.0.0'::ip4 as a) s; a | a | a | a ---+---+---+--- 0 | 0 | 0 | 0 (1 row) select a::numeric, a::ipaddress::numeric, a::bigint, a::float8 from (select '255.255.255.255'::ip4 as a) s; a | a | a | a ------------+------------+------------+------------ 4294967295 | 4294967295 | 4294967295 | 4294967295 (1 row) select a::numeric, a::ipaddress::numeric, a::bigint, a::float8 from (select '0.0.0.1'::ip4 as a) s; a | a | a | a ---+---+---+--- 1 | 1 | 1 | 1 (1 row) select a::numeric, a::ipaddress::numeric, a::bigint, a::float8 from (select '0.0.1.0'::ip4 as a) s; a | a | a | a -----+-----+-----+----- 256 | 256 | 256 | 256 (1 row) select a::numeric, a::ipaddress::numeric, a::bigint, a::float8 from (select '0.1.0.0'::ip4 as a) s; a | a | a | a -------+-------+-------+------- 65536 | 65536 | 65536 | 65536 (1 row) select a::numeric, a::ipaddress::numeric, a::bigint, a::float8 from (select '1.0.0.0'::ip4 as a) s; a | a | a | a ----------+----------+----------+---------- 16777216 | 16777216 | 16777216 | 16777216 (1 row) select a::numeric, a::ipaddress::numeric from (select '::'::ip6 as a) s; a | a ---+--- 0 | 0 (1 row) select a::numeric, a::ipaddress::numeric from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'::ip6 as a) s; a | a -----------------------------------------+----------------------------------------- 340282366920938463463374607431768211455 | 340282366920938463463374607431768211455 (1 row) select a::numeric, a::ipaddress::numeric from (select '::1'::ip6 as a) s; a | a ---+--- 1 | 1 (1 row) select a::numeric, a::ipaddress::numeric from (select '::1:0'::ip6 as a) s; a | a -------+------- 65536 | 65536 (1 row) select a::numeric, a::ipaddress::numeric from (select '::1:0:0'::ip6 as a) s; a | a ------------+------------ 4294967296 | 4294967296 (1 row) select a::numeric, a::ipaddress::numeric from (select '::1:0:0:0'::ip6 as a) s; a | a -----------------+----------------- 281474976710656 | 281474976710656 (1 row) select a::numeric, a::ipaddress::numeric from (select '0:0:0:1::'::ip6 as a) s; a | a ----------------------+---------------------- 18446744073709551616 | 18446744073709551616 (1 row) select a::numeric, a::ipaddress::numeric from (select '0:0:1::'::ip6 as a) s; a | a ---------------------------+--------------------------- 1208925819614629174706176 | 1208925819614629174706176 (1 row) select a::numeric, a::ipaddress::numeric from (select '0:1::'::ip6 as a) s; a | a -------------------------------+------------------------------- 79228162514264337593543950336 | 79228162514264337593543950336 (1 row) select a::numeric, a::ipaddress::numeric from (select '1::'::ip6 as a) s; a | a ------------------------------------+------------------------------------ 5192296858534827628530496329220096 | 5192296858534827628530496329220096 (1 row) -- invalid numeric casts select (-4294967295::bigint)::ip4; ERROR: ip address out of range select (4294967296::bigint)::ip4; ERROR: ip address out of range select 0.1::float8::ip4; WARNING: double converted to IP4 is not integral ip4 --------- 0.0.0.0 (1 row) select (-0.1)::float8::ip4; WARNING: double converted to IP4 is not integral ip4 --------- 0.0.0.0 (1 row) select (-4294967295::float8)::ip4; ERROR: ip address out of range select (4294967296::float8)::ip4; ERROR: ip address out of range select (-3000000000::float8)::ip4; ERROR: ip address out of range select 6000000000::float8::ip4; ERROR: ip address out of range select 6e10::float8::ip4; ERROR: ip address out of range select 6e30::float8::ip4; ERROR: ip address out of range select (-1::numeric)::ip6; ERROR: invalid numeric value for conversion to IP6 select 340282366920938463463374607431768211456::numeric::ip6; ERROR: numeric value too large for conversion to IP6 select 0.1::numeric::ip6; ERROR: invalid numeric value for conversion to IP6 select 0.00000000000000000001::numeric::ip6; ERROR: invalid numeric value for conversion to IP6 select (-0.00000000000000000001::numeric)::ip6; ERROR: invalid numeric value for conversion to IP6 -- inet/cidr casts select a::ip4, a::ipaddress from (select '0.0.0.0'::inet as a) s; a | a ---------+--------- 0.0.0.0 | 0.0.0.0 (1 row) select a::ip4, a::ipaddress from (select '1.2.3.4'::inet as a) s; a | a ---------+--------- 1.2.3.4 | 1.2.3.4 (1 row) select a::ip4, a::ipaddress from (select '255.255.255.255'::inet as a) s; a | a -----------------+----------------- 255.255.255.255 | 255.255.255.255 (1 row) select a::ip4, a::ipaddress from (select '10.20.30.40/24'::inet as a) s; a | a -------------+------------- 10.20.30.40 | 10.20.30.40 (1 row) select a::ip4, a::ipaddress from (select '10.20.30.40/16'::inet as a) s; a | a -------------+------------- 10.20.30.40 | 10.20.30.40 (1 row) select a::ip6, a::ipaddress from (select '::'::inet as a) s; a | a ----+---- :: | :: (1 row) select a::ip6, a::ipaddress from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'::inet as a) s; a | a -----------------------------------------+----------------------------------------- ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff | ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff (1 row) select a::ip6, a::ipaddress from (select '::1'::inet as a) s; a | a -----+----- ::1 | ::1 (1 row) select a::ip6, a::ipaddress from (select '1234:2345:3456:4567:5678:6789:789a:89ab'::inet as a) s; a | a -----------------------------------------+----------------------------------------- 1234:2345:3456:4567:5678:6789:789a:89ab | 1234:2345:3456:4567:5678:6789:789a:89ab (1 row) select a::ip6, a::ipaddress from (select '1234:2345:3456:4567:5678:6789:789a:89ab/96'::inet as a) s; a | a -----------------------------------------+----------------------------------------- 1234:2345:3456:4567:5678:6789:789a:89ab | 1234:2345:3456:4567:5678:6789:789a:89ab (1 row) select a::ip6, a::ipaddress from (select '1234:2345:3456:4567:5678:6789:789a:89ab/64'::inet as a) s; a | a -----------------------------------------+----------------------------------------- 1234:2345:3456:4567:5678:6789:789a:89ab | 1234:2345:3456:4567:5678:6789:789a:89ab (1 row) select a::ip6, a::ipaddress from (select '1234:2345:3456:4567:5678:6789:789a:89ab/32'::inet as a) s; a | a -----------------------------------------+----------------------------------------- 1234:2345:3456:4567:5678:6789:789a:89ab | 1234:2345:3456:4567:5678:6789:789a:89ab (1 row) select a::ip4r, a::iprange from (select '0.0.0.0/16'::cidr as a) s; a | a ------------+------------ 0.0.0.0/16 | 0.0.0.0/16 (1 row) select a::ip4r, a::iprange from (select '0.1.0.0/16'::cidr as a) s; a | a ------------+------------ 0.1.0.0/16 | 0.1.0.0/16 (1 row) select a::ip4r, a::iprange from (select '1.2.3.0/24'::cidr as a) s; a | a ------------+------------ 1.2.3.0/24 | 1.2.3.0/24 (1 row) select a::ip4r, a::iprange from (select '0.0.0.0/0'::cidr as a) s; a | a -----------+----------- 0.0.0.0/0 | 0.0.0.0/0 (1 row) select a::ip6r, a::iprange from (select '::/0'::cidr as a) s; a | a ------+------ ::/0 | ::/0 (1 row) select a::ip6r, a::iprange from (select 'ffff::/64'::cidr as a) s; a | a -----------+----------- ffff::/64 | ffff::/64 (1 row) select a::ip6r, a::iprange from (select '0:0:0:0:ffff::/128'::cidr as a) s; a | a ------------------+------------------ ::ffff:0:0.0.0.0 | ::ffff:0:0.0.0.0 (1 row) select a::ip6r, a::iprange from (select '1234:2345:3456:4567:5678:6789::/96'::cidr as a) s; a | a ------------------------------------+------------------------------------ 1234:2345:3456:4567:5678:6789::/96 | 1234:2345:3456:4567:5678:6789::/96 (1 row) select '1.2.3.4'::ip4::cidr; cidr ------------ 1.2.3.4/32 (1 row) select '0.0.0.0'::ip4::cidr; cidr ------------ 0.0.0.0/32 (1 row) select '255.255.255.255'::ip4::cidr; cidr -------------------- 255.255.255.255/32 (1 row) select '1.2.3.0/24'::ip4r::cidr; cidr ------------ 1.2.3.0/24 (1 row) select '0.0.0.0/0'::ip4r::cidr; cidr ----------- 0.0.0.0/0 (1 row) select '255.255.255.255/32'::ip4r::cidr; cidr -------------------- 255.255.255.255/32 (1 row) select '1234:2345:3456:4567:5678:6789:789a:89ab'::ip6::cidr; cidr --------------------------------------------- 1234:2345:3456:4567:5678:6789:789a:89ab/128 (1 row) select '::'::ip6::cidr; cidr -------- ::/128 (1 row) select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'::ip6::cidr; cidr --------------------------------------------- ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128 (1 row) select '1234:2345:3456:4567:5678:6789:789a:0000/112'::ip6r::cidr; cidr ------------------------------------------ 1234:2345:3456:4567:5678:6789:789a:0/112 (1 row) select '::/0'::ip6r::cidr; cidr ------ ::/0 (1 row) select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128'::ip6r::cidr; cidr --------------------------------------------- ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128 (1 row) select 'ffff:ffff:ffff::/48'::ip6r::cidr; cidr --------------------- ffff:ffff:ffff::/48 (1 row) select '1.2.3.4'::ipaddress::cidr; cidr ------------ 1.2.3.4/32 (1 row) select '0.0.0.0'::ipaddress::cidr; cidr ------------ 0.0.0.0/32 (1 row) select '255.255.255.255'::ipaddress::cidr; cidr -------------------- 255.255.255.255/32 (1 row) select '1234:2345:3456:4567:5678:6789:789a:89ab'::ipaddress::cidr; cidr --------------------------------------------- 1234:2345:3456:4567:5678:6789:789a:89ab/128 (1 row) select '::'::ipaddress::cidr; cidr -------- ::/128 (1 row) select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'::ipaddress::cidr; cidr --------------------------------------------- ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128 (1 row) select '1.2.3.0/24'::iprange::cidr; cidr ------------ 1.2.3.0/24 (1 row) select '0.0.0.0/0'::iprange::cidr; cidr ----------- 0.0.0.0/0 (1 row) select '255.255.255.255/32'::iprange::cidr; cidr -------------------- 255.255.255.255/32 (1 row) select '1234:2345:3456:4567:5678:6789:789a:0000/112'::iprange::cidr; cidr ------------------------------------------ 1234:2345:3456:4567:5678:6789:789a:0/112 (1 row) select '::/0'::iprange::cidr; cidr ------ ::/0 (1 row) select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128'::iprange::cidr; cidr --------------------------------------------- ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128 (1 row) select 'ffff:ffff:ffff::/48'::iprange::cidr; cidr --------------------- ffff:ffff:ffff::/48 (1 row) select '-'::iprange::cidr; cidr ------ (1 row) -- invalid inet/cidr casts select '::'::inet::ip4; ERROR: invalid INET value for conversion to IP4 select '0.0.0.0'::inet::ip6; ERROR: invalid INET value for conversion to IP6 select '::/128'::cidr::ip4r; ERROR: invalid CIDR value for conversion to IP4R select '0.0.0.0/32'::cidr::ip6r; ERROR: invalid CIDR value for conversion to IP6R -- invalid cross-type casts select '::/0'::iprange::ip4r; ERROR: invalid IPR value for conversion to IP4R select '0.0.0.0/0'::iprange::ip6r; ERROR: invalid IPR value for conversion to IP6R select '::'::ipaddress::ip4; ERROR: invalid IP value in cast to IP4 select '0.0.0.0'::ipaddress::ip6; ERROR: invalid IP value in cast to IP4 -- constructor functions select ip4r('0.0.0.0','255.255.255.255'); ip4r ----------- 0.0.0.0/0 (1 row) select ip4r('255.255.255.255','0.0.0.0'); ip4r ----------- 0.0.0.0/0 (1 row) select ip4r('1.2.3.4','5.6.7.8'); ip4r ----------------- 1.2.3.4-5.6.7.8 (1 row) select ip6r('::','ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'); ip6r ------ ::/0 (1 row) select ip6r('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff','::'); ip6r ------ ::/0 (1 row) select ip6r('1234:2345:3456:4567:5678:6789:789a:89ab','ffff::ffff'); ip6r ---------------------------------------------------- 1234:2345:3456:4567:5678:6789:789a:89ab-ffff::ffff (1 row) select iprange('0.0.0.0'::ip4,'255.255.255.255'::ip4); iprange ----------- 0.0.0.0/0 (1 row) select iprange('255.255.255.255'::ip4,'0.0.0.0'::ip4); iprange ----------- 0.0.0.0/0 (1 row) select iprange('1.2.3.4'::ip4,'5.6.7.8'::ip4); iprange ----------------- 1.2.3.4-5.6.7.8 (1 row) select iprange('::'::ip6,'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'::ip6); iprange --------- ::/0 (1 row) select iprange('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'::ip6,'::'::ip6); iprange --------- ::/0 (1 row) select iprange('1234:2345:3456:4567:5678:6789:789a:89ab'::ip6,'ffff::ffff'::ip6); iprange ---------------------------------------------------- 1234:2345:3456:4567:5678:6789:789a:89ab-ffff::ffff (1 row) select iprange('0.0.0.0'::ipaddress,'255.255.255.255'::ipaddress); iprange ----------- 0.0.0.0/0 (1 row) select iprange('255.255.255.255'::ipaddress,'0.0.0.0'::ipaddress); iprange ----------- 0.0.0.0/0 (1 row) select iprange('1.2.3.4'::ipaddress,'5.6.7.8'::ipaddress); iprange ----------------- 1.2.3.4-5.6.7.8 (1 row) select iprange('::'::ipaddress,'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'::ipaddress); iprange --------- ::/0 (1 row) select iprange('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'::ipaddress,'::'::ipaddress); iprange --------- ::/0 (1 row) select iprange('1234:2345:3456:4567:5678:6789:789a:89ab'::ipaddress,'ffff::ffff'::ipaddress); iprange ---------------------------------------------------- 1234:2345:3456:4567:5678:6789:789a:89ab-ffff::ffff (1 row) -- utility functions -- (family, lower, upper were tested above) select ip4_netmask(0), ip4_netmask(1), ip4_netmask(31), ip4_netmask(32); ip4_netmask | ip4_netmask | ip4_netmask | ip4_netmask -------------+-------------+-----------------+----------------- 0.0.0.0 | 128.0.0.0 | 255.255.255.254 | 255.255.255.255 (1 row) select ip4_netmask(33); ERROR: prefix length out of range select ip4_netmask(-1); ERROR: prefix length out of range select ip6_netmask(0), ip6_netmask(1); ip6_netmask | ip6_netmask -------------+------------- :: | 8000:: (1 row) select ip6_netmask(63), ip6_netmask(64), ip6_netmask(65); ip6_netmask | ip6_netmask | ip6_netmask -----------------------+-----------------------+---------------------------- ffff:ffff:ffff:fffe:: | ffff:ffff:ffff:ffff:: | ffff:ffff:ffff:ffff:8000:: (1 row) select ip6_netmask(127), ip6_netmask(128); ip6_netmask | ip6_netmask -----------------------------------------+----------------------------------------- ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffe | ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff (1 row) select ip6_netmask(129); ERROR: prefix length out of range select ip6_netmask(-1); ERROR: prefix length out of range select is_cidr(a), is_cidr(a::iprange), masklen(a), masklen(a::iprange) from (select '1.2.3.4-5.6.7.8'::ip4r as a) s; is_cidr | is_cidr | masklen | masklen ---------+---------+---------+--------- f | f | | (1 row) select is_cidr(a), is_cidr(a::iprange), masklen(a), masklen(a::iprange) from (select '1.2.3.0-1.2.3.255'::ip4r as a) s; is_cidr | is_cidr | masklen | masklen ---------+---------+---------+--------- t | t | 24 | 24 (1 row) select is_cidr(a), is_cidr(a::iprange), masklen(a), masklen(a::iprange) from (select '0.0.0.0/32'::ip4r as a) s; is_cidr | is_cidr | masklen | masklen ---------+---------+---------+--------- t | t | 32 | 32 (1 row) select is_cidr(a), is_cidr(a::iprange), masklen(a), masklen(a::iprange) from (select '0.0.0.0/31'::ip4r as a) s; is_cidr | is_cidr | masklen | masklen ---------+---------+---------+--------- t | t | 31 | 31 (1 row) select is_cidr(a), is_cidr(a::iprange), masklen(a), masklen(a::iprange) from (select '0.0.0.0/1'::ip4r as a) s; is_cidr | is_cidr | masklen | masklen ---------+---------+---------+--------- t | t | 1 | 1 (1 row) select is_cidr(a), is_cidr(a::iprange), masklen(a), masklen(a::iprange) from (select '0.0.0.0/0'::ip4r as a) s; is_cidr | is_cidr | masklen | masklen ---------+---------+---------+--------- t | t | 0 | 0 (1 row) select is_cidr(a), is_cidr(a::iprange), masklen(a), masklen(a::iprange) from (select '255.255.255.255/32'::ip4r as a) s; is_cidr | is_cidr | masklen | masklen ---------+---------+---------+--------- t | t | 32 | 32 (1 row) select is_cidr(a), is_cidr(a::iprange), masklen(a), masklen(a::iprange) from (select '255.255.255.254/31'::ip4r as a) s; is_cidr | is_cidr | masklen | masklen ---------+---------+---------+--------- t | t | 31 | 31 (1 row) select is_cidr(a), is_cidr(a::iprange), masklen(a), masklen(a::iprange) from (select '128.0.0.0/1'::ip4r as a) s; is_cidr | is_cidr | masklen | masklen ---------+---------+---------+--------- t | t | 1 | 1 (1 row) select is_cidr(a), is_cidr(a::iprange), masklen(a), masklen(a::iprange) from (select '1234::-5678::ffff:0'::ip6r as a) s; is_cidr | is_cidr | masklen | masklen ---------+---------+---------+--------- f | f | | (1 row) select is_cidr(a), is_cidr(a::iprange), masklen(a), masklen(a::iprange) from (select '::1234-::5678'::ip6r as a) s; is_cidr | is_cidr | masklen | masklen ---------+---------+---------+--------- f | f | | (1 row) select is_cidr(a), is_cidr(a::iprange), masklen(a), masklen(a::iprange) from (select 'ffff::-ffff::ffff:0'::ip6r as a) s; is_cidr | is_cidr | masklen | masklen ---------+---------+---------+--------- f | f | | (1 row) select is_cidr(a), is_cidr(a::iprange), masklen(a), masklen(a::iprange) from (select 'ffff::-ffff::ffff'::ip6r as a) s; is_cidr | is_cidr | masklen | masklen ---------+---------+---------+--------- t | t | 112 | 112 (1 row) select is_cidr(a), is_cidr(a::iprange), masklen(a), masklen(a::iprange) from (select 'ffff::-ffff:0:0:0:ffff:ffff:ffff:ffff'::ip6r as a) s; is_cidr | is_cidr | masklen | masklen ---------+---------+---------+--------- t | t | 64 | 64 (1 row) select is_cidr(a), is_cidr(a::iprange), masklen(a), masklen(a::iprange) from (select 'ffff::-ffff:0:0:1:ffff:ffff:ffff:ffff'::ip6r as a) s; is_cidr | is_cidr | masklen | masklen ---------+---------+---------+--------- t | t | 63 | 63 (1 row) select is_cidr(a), is_cidr(a::iprange), masklen(a), masklen(a::iprange) from (select '::/128'::ip6r as a) s; is_cidr | is_cidr | masklen | masklen ---------+---------+---------+--------- t | t | 128 | 128 (1 row) select is_cidr(a), is_cidr(a::iprange), masklen(a), masklen(a::iprange) from (select '::/127'::ip6r as a) s; is_cidr | is_cidr | masklen | masklen ---------+---------+---------+--------- t | t | 127 | 127 (1 row) select is_cidr(a), is_cidr(a::iprange), masklen(a), masklen(a::iprange) from (select '::/1'::ip6r as a) s; is_cidr | is_cidr | masklen | masklen ---------+---------+---------+--------- t | t | 1 | 1 (1 row) select is_cidr(a), is_cidr(a::iprange), masklen(a), masklen(a::iprange) from (select '::/0'::ip6r as a) s; is_cidr | is_cidr | masklen | masklen ---------+---------+---------+--------- t | t | 0 | 0 (1 row) select is_cidr(a), is_cidr(a::iprange), masklen(a), masklen(a::iprange) from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128'::ip6r as a) s; is_cidr | is_cidr | masklen | masklen ---------+---------+---------+--------- t | t | 128 | 128 (1 row) select is_cidr(a), is_cidr(a::iprange), masklen(a), masklen(a::iprange) from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffe/127'::ip6r as a) s; is_cidr | is_cidr | masklen | masklen ---------+---------+---------+--------- t | t | 127 | 127 (1 row) select is_cidr(a), is_cidr(a::iprange), masklen(a), masklen(a::iprange) from (select 'ffff:ffff:ffff:ffff:8000::/65'::ip6r as a) s; is_cidr | is_cidr | masklen | masklen ---------+---------+---------+--------- t | t | 65 | 65 (1 row) select is_cidr(a), is_cidr(a::iprange), masklen(a), masklen(a::iprange) from (select 'ffff:ffff:ffff:ffff::/64'::ip6r as a) s; is_cidr | is_cidr | masklen | masklen ---------+---------+---------+--------- t | t | 64 | 64 (1 row) select is_cidr(a), is_cidr(a::iprange), masklen(a), masklen(a::iprange) from (select 'ffff:ffff:ffff:fffe::/63'::ip6r as a) s; is_cidr | is_cidr | masklen | masklen ---------+---------+---------+--------- t | t | 63 | 63 (1 row) select is_cidr(a), is_cidr(a::iprange), masklen(a), masklen(a::iprange) from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128'::ip6r as a) s; is_cidr | is_cidr | masklen | masklen ---------+---------+---------+--------- t | t | 128 | 128 (1 row) select ip4_net_lower('255.255.255.255',0); ip4_net_lower --------------- 0.0.0.0 (1 row) select ip4_net_lower('255.255.255.255',1); ip4_net_lower --------------- 128.0.0.0 (1 row) select ip4_net_lower('255.255.255.255',24); ip4_net_lower --------------- 255.255.255.0 (1 row) select ip4_net_lower('255.255.255.255',31); ip4_net_lower ----------------- 255.255.255.254 (1 row) select ip4_net_lower('255.255.255.255',32); ip4_net_lower ----------------- 255.255.255.255 (1 row) select ip4_net_lower('255.255.255.255',33); ERROR: prefix length out of range select ip4_net_lower('255.255.255.255',-1); ERROR: prefix length out of range select ip4_net_upper('0.0.0.0',0); ip4_net_upper ----------------- 255.255.255.255 (1 row) select ip4_net_upper('0.0.0.0',1); ip4_net_upper ----------------- 127.255.255.255 (1 row) select ip4_net_upper('0.0.0.0',24); ip4_net_upper --------------- 0.0.0.255 (1 row) select ip4_net_upper('0.0.0.0',31); ip4_net_upper --------------- 0.0.0.1 (1 row) select ip4_net_upper('0.0.0.0',32); ip4_net_upper --------------- 0.0.0.0 (1 row) select ip4_net_upper('0.0.0.0',33); ERROR: prefix length out of range select ip4_net_upper('0.0.0.0',-1); ERROR: prefix length out of range select ip6_net_lower('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',0); ip6_net_lower --------------- :: (1 row) select ip6_net_lower('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',1); ip6_net_lower --------------- 8000:: (1 row) select ip6_net_lower('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',63); ip6_net_lower ----------------------- ffff:ffff:ffff:fffe:: (1 row) select ip6_net_lower('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',64); ip6_net_lower ----------------------- ffff:ffff:ffff:ffff:: (1 row) select ip6_net_lower('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',65); ip6_net_lower ---------------------------- ffff:ffff:ffff:ffff:8000:: (1 row) select ip6_net_lower('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',127); ip6_net_lower ----------------------------------------- ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffe (1 row) select ip6_net_lower('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',128); ip6_net_lower ----------------------------------------- ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff (1 row) select ip6_net_lower('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',129); ERROR: prefix length out of range select ip6_net_lower('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',-1); ERROR: prefix length out of range select ip6_net_upper('::',0); ip6_net_upper ----------------------------------------- ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff (1 row) select ip6_net_upper('::',1); ip6_net_upper ----------------------------------------- 7fff:ffff:ffff:ffff:ffff:ffff:ffff:ffff (1 row) select ip6_net_upper('::',63); ip6_net_upper ------------------------- ::1:ffff:ffff:ffff:ffff (1 row) select ip6_net_upper('::',64); ip6_net_upper ----------------------- ::ffff:ffff:ffff:ffff (1 row) select ip6_net_upper('::',65); ip6_net_upper ----------------------- ::7fff:ffff:ffff:ffff (1 row) select ip6_net_upper('::',127); ip6_net_upper --------------- ::1 (1 row) select ip6_net_upper('::',128); ip6_net_upper --------------- :: (1 row) select ip6_net_upper('::',129); ERROR: prefix length out of range select ip6_net_upper('::',-1); ERROR: prefix length out of range select ipaddress_net_lower('255.255.255.255',0); ipaddress_net_lower --------------------- 0.0.0.0 (1 row) select ipaddress_net_lower('255.255.255.255',1); ipaddress_net_lower --------------------- 128.0.0.0 (1 row) select ipaddress_net_lower('255.255.255.255',24); ipaddress_net_lower --------------------- 255.255.255.0 (1 row) select ipaddress_net_lower('255.255.255.255',31); ipaddress_net_lower --------------------- 255.255.255.254 (1 row) select ipaddress_net_lower('255.255.255.255',32); ipaddress_net_lower --------------------- 255.255.255.255 (1 row) select ipaddress_net_lower('255.255.255.255',33); ERROR: prefix length out of range select ipaddress_net_lower('255.255.255.255',-1); ERROR: prefix length out of range select ipaddress_net_upper('0.0.0.0',0); ipaddress_net_upper --------------------- 255.255.255.255 (1 row) select ipaddress_net_upper('0.0.0.0',1); ipaddress_net_upper --------------------- 127.255.255.255 (1 row) select ipaddress_net_upper('0.0.0.0',24); ipaddress_net_upper --------------------- 0.0.0.255 (1 row) select ipaddress_net_upper('0.0.0.0',31); ipaddress_net_upper --------------------- 0.0.0.1 (1 row) select ipaddress_net_upper('0.0.0.0',32); ipaddress_net_upper --------------------- 0.0.0.0 (1 row) select ipaddress_net_upper('0.0.0.0',33); ERROR: prefix length out of range select ipaddress_net_upper('0.0.0.0',-1); ERROR: prefix length out of range select ipaddress_net_lower('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',0); ipaddress_net_lower --------------------- :: (1 row) select ipaddress_net_lower('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',1); ipaddress_net_lower --------------------- 8000:: (1 row) select ipaddress_net_lower('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',63); ipaddress_net_lower ----------------------- ffff:ffff:ffff:fffe:: (1 row) select ipaddress_net_lower('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',64); ipaddress_net_lower ----------------------- ffff:ffff:ffff:ffff:: (1 row) select ipaddress_net_lower('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',65); ipaddress_net_lower ---------------------------- ffff:ffff:ffff:ffff:8000:: (1 row) select ipaddress_net_lower('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',127); ipaddress_net_lower ----------------------------------------- ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffe (1 row) select ipaddress_net_lower('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',128); ipaddress_net_lower ----------------------------------------- ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff (1 row) select ipaddress_net_lower('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',129); ERROR: prefix length out of range select ipaddress_net_lower('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',-1); ERROR: prefix length out of range select ipaddress_net_upper('::',0); ipaddress_net_upper ----------------------------------------- ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff (1 row) select ipaddress_net_upper('::',1); ipaddress_net_upper ----------------------------------------- 7fff:ffff:ffff:ffff:ffff:ffff:ffff:ffff (1 row) select ipaddress_net_upper('::',63); ipaddress_net_upper ------------------------- ::1:ffff:ffff:ffff:ffff (1 row) select ipaddress_net_upper('::',64); ipaddress_net_upper ----------------------- ::ffff:ffff:ffff:ffff (1 row) select ipaddress_net_upper('::',65); ipaddress_net_upper ----------------------- ::7fff:ffff:ffff:ffff (1 row) select ipaddress_net_upper('::',127); ipaddress_net_upper --------------------- ::1 (1 row) select ipaddress_net_upper('::',128); ipaddress_net_upper --------------------- :: (1 row) select ipaddress_net_upper('::',129); ERROR: prefix length out of range select ipaddress_net_upper('::',-1); ERROR: prefix length out of range select ip4r_union('1.0.0.0/24','2.0.0.0/16'); ip4r_union --------------------- 1.0.0.0-2.0.255.255 (1 row) select ip4r_union('0.0.0.0/0','2.0.0.0/16'); ip4r_union ------------ 0.0.0.0/0 (1 row) select ip4r_union('0.0.0.0-3.0.0.0','2.0.0.0-4.0.0.0'); ip4r_union ----------------- 0.0.0.0-4.0.0.0 (1 row) select ip6r_union('2000::/16','3000::/16'); ip6r_union ------------------------------------------------ 2000::-3000:ffff:ffff:ffff:ffff:ffff:ffff:ffff (1 row) select ip6r_union('2000::-4000::','3000::-5000::'); ip6r_union --------------- 2000::-5000:: (1 row) select ip6r_union('::/0','3000::-5000::'); ip6r_union ------------ ::/0 (1 row) select iprange_union('0.0.0.0/0','::/0'); iprange_union --------------- - (1 row) select iprange_union('128.0.0.0/32','8000::/16'); iprange_union --------------- - (1 row) select iprange_union('1.0.0.0/24','2.0.0.0/16'); iprange_union --------------------- 1.0.0.0-2.0.255.255 (1 row) select iprange_union('0.0.0.0/0','2.0.0.0/16'); iprange_union --------------- 0.0.0.0/0 (1 row) select iprange_union('0.0.0.0-3.0.0.0','2.0.0.0-4.0.0.0'); iprange_union ----------------- 0.0.0.0-4.0.0.0 (1 row) select iprange_union('2000::/16','3000::/16'); iprange_union ------------------------------------------------ 2000::-3000:ffff:ffff:ffff:ffff:ffff:ffff:ffff (1 row) select iprange_union('2000::-4000::','3000::-5000::'); iprange_union --------------- 2000::-5000:: (1 row) select iprange_union('::/0','3000::-5000::'); iprange_union --------------- ::/0 (1 row) select ip4r_inter('1.0.0.0/24','2.0.0.0/16'); ip4r_inter ------------ (1 row) select ip4r_inter('0.0.0.0/0','2.0.0.0/16'); ip4r_inter ------------ 2.0.0.0/16 (1 row) select ip4r_inter('0.0.0.0-3.0.0.0','2.0.0.0-4.0.0.0'); ip4r_inter ----------------- 2.0.0.0-3.0.0.0 (1 row) select ip6r_inter('2000::/16','3000::/16'); ip6r_inter ------------ (1 row) select ip6r_inter('2000::-4000::','3000::-5000::'); ip6r_inter --------------- 3000::-4000:: (1 row) select ip6r_inter('::/0','3000::-5000::'); ip6r_inter --------------- 3000::-5000:: (1 row) select iprange_inter('0.0.0.0/0','::/0'); iprange_inter --------------- (1 row) select iprange_inter('128.0.0.0/32','8000::/16'); iprange_inter --------------- (1 row) select iprange_inter('1.0.0.0/24','2.0.0.0/16'); iprange_inter --------------- (1 row) select iprange_inter('0.0.0.0/0','2.0.0.0/16'); iprange_inter --------------- 2.0.0.0/16 (1 row) select iprange_inter('0.0.0.0-3.0.0.0','2.0.0.0-4.0.0.0'); iprange_inter ----------------- 2.0.0.0-3.0.0.0 (1 row) select iprange_inter('2000::/16','3000::/16'); iprange_inter --------------- (1 row) select iprange_inter('2000::-4000::','3000::-5000::'); iprange_inter --------------- 3000::-4000:: (1 row) select iprange_inter('::/0','3000::-5000::'); iprange_inter --------------- 3000::-5000:: (1 row) -- operators select ip4 '255.255.255.255' / 32; ?column? ----------------- 255.255.255.255 (1 row) select ip4 '255.255.255.255' / 31; ?column? -------------------- 255.255.255.254/31 (1 row) select ip4 '255.255.255.255' / 16; ?column? ---------------- 255.255.0.0/16 (1 row) select ip4 '255.255.255.255' / 0; ?column? ----------- 0.0.0.0/0 (1 row) select ip4 '255.255.255.255' / 1; ?column? ------------- 128.0.0.0/1 (1 row) select ip4 '255.255.255.255' / 33; ERROR: prefix length out of range select ip4 '255.255.255.255' / -1; ERROR: prefix length out of range select ip4 '255.255.255.255' / ip4 '255.255.255.0'; ?column? ------------------ 255.255.255.0/24 (1 row) select ip4 '255.255.255.255' / ip4 '255.0.0.0'; ?column? ------------- 255.0.0.0/8 (1 row) select ip4 '255.255.255.255' / ip4 '0.255.255.255'; ERROR: invalid netmask select ip4 '255.255.255.255' / ip4 '255.254.255.255'; ERROR: invalid netmask select ip6 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' / 128; ?column? ----------------------------------------- ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff (1 row) select ip6 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' / 127; ?column? --------------------------------------------- ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffe/127 (1 row) select ip6 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' / 65; ?column? ------------------------------- ffff:ffff:ffff:ffff:8000::/65 (1 row) select ip6 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' / 64; ?column? -------------------------- ffff:ffff:ffff:ffff::/64 (1 row) select ip6 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' / 63; ?column? -------------------------- ffff:ffff:ffff:fffe::/63 (1 row) select ip6 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' / 1; ?column? ---------- 8000::/1 (1 row) select ip6 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' / 0; ?column? ---------- ::/0 (1 row) select ip6 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' / 129; ERROR: prefix length out of range select ip6 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' / -1; ERROR: prefix length out of range select ip6 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' / ip6 'ffff:ffff:ffff:ffff:ffff::'; ?column? ------------------------------- ffff:ffff:ffff:ffff:ffff::/80 (1 row) select ip6 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' / ip6 'ffff:ffff:ffff::'; ?column? --------------------- ffff:ffff:ffff::/48 (1 row) select ip6 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' / ip6 'ffff:ffff:ffff:ffff:ffff::ffff'; ERROR: invalid netmask select ip6 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' / ip6 'ffff:ffff:ffff::ffff'; ERROR: invalid netmask select ipaddress '255.255.255.255' / 32; ?column? ----------------- 255.255.255.255 (1 row) select ipaddress '255.255.255.255' / 31; ?column? -------------------- 255.255.255.254/31 (1 row) select ipaddress '255.255.255.255' / 16; ?column? ---------------- 255.255.0.0/16 (1 row) select ipaddress '255.255.255.255' / 0; ?column? ----------- 0.0.0.0/0 (1 row) select ipaddress '255.255.255.255' / 1; ?column? ------------- 128.0.0.0/1 (1 row) select ipaddress '255.255.255.255' / 33; ERROR: prefix length out of range select ipaddress '255.255.255.255' / -1; ERROR: prefix length out of range select ipaddress '255.255.255.255' / ipaddress '255.255.255.0'; ?column? ------------------ 255.255.255.0/24 (1 row) select ipaddress '255.255.255.255' / ipaddress '255.0.0.0'; ?column? ------------- 255.0.0.0/8 (1 row) select ipaddress 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' / 128; ?column? ----------------------------------------- ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff (1 row) select ipaddress 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' / 127; ?column? --------------------------------------------- ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffe/127 (1 row) select ipaddress 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' / 65; ?column? ------------------------------- ffff:ffff:ffff:ffff:8000::/65 (1 row) select ipaddress 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' / 64; ?column? -------------------------- ffff:ffff:ffff:ffff::/64 (1 row) select ipaddress 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' / 63; ?column? -------------------------- ffff:ffff:ffff:fffe::/63 (1 row) select ipaddress 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' / 1; ?column? ---------- 8000::/1 (1 row) select ipaddress 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' / 0; ?column? ---------- ::/0 (1 row) select ipaddress 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' / 129; ERROR: prefix length out of range select ipaddress 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' / -1; ERROR: prefix length out of range select ipaddress 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' / ipaddress 'ffff:ffff:ffff:ffff:ffff::'; ?column? ------------------------------- ffff:ffff:ffff:ffff:ffff::/80 (1 row) select ipaddress 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' / ipaddress 'ffff:ffff:ffff::'; ?column? --------------------- ffff:ffff:ffff::/48 (1 row) select ipaddress '255.255.255.255' / ipaddress '0.255.255.255'; ERROR: invalid netmask select ipaddress '255.255.255.255' / ipaddress '255.254.255.255'; ERROR: invalid netmask select ipaddress 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' / ipaddress 'ffff:ffff:ffff:ffff:ffff::ffff'; ERROR: invalid netmask select ipaddress 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' / ipaddress 'ffff:ffff:ffff::ffff'; ERROR: invalid netmask select ipaddress 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' / ipaddress '0.0.0.0'; ERROR: invalid mixing of IP address families select ipaddress '255.255.255.255' / ipaddress '::'; ERROR: invalid mixing of IP address families select @ a, @@ a, @ (a::iprange), @@ (a::iprange) from (select '0.0.0.0/32'::ip4r as a) s; ?column? | ?column? | ?column? | ?column? ----------+----------+----------+---------- 1 | 1 | 1 | 1 (1 row) select @ a, @@ a, @ (a::iprange), @@ (a::iprange) from (select '0.0.0.0/31'::ip4r as a) s; ?column? | ?column? | ?column? | ?column? ----------+----------+----------+---------- 2 | 2 | 2 | 2 (1 row) select @ a, @@ a, @ (a::iprange), @@ (a::iprange) from (select '0.0.0.0/16'::ip4r as a) s; ?column? | ?column? | ?column? | ?column? ----------+----------+----------+---------- 65536 | 65536 | 65536 | 65536 (1 row) select @ a, @@ a, @ (a::iprange), @@ (a::iprange) from (select '0.0.0.0/1'::ip4r as a) s; ?column? | ?column? | ?column? | ?column? ------------+------------+------------+------------ 2147483648 | 2147483648 | 2147483648 | 2147483648 (1 row) select @ a, @@ a, @ (a::iprange), @@ (a::iprange) from (select '0.0.0.0/0'::ip4r as a) s; ?column? | ?column? | ?column? | ?column? ------------+------------+------------+------------ 4294967296 | 4294967296 | 4294967296 | 4294967296 (1 row) select @ a, @@ a, @ (a::iprange), @@ (a::iprange) from (select '1.2.3.4-5.6.7.8'::ip4r as a) s; ?column? | ?column? | ?column? | ?column? ----------+----------+----------+---------- 67372037 | 67372037 | 67372037 | 67372037 (1 row) select @ a, @@ a, @ (a::iprange), @@ (a::iprange) from (select '::/128'::ip6r as a) s; ?column? | ?column? | ?column? | ?column? ----------+----------+----------+---------- 1 | 1 | 1 | 1 (1 row) select @ a, @@ a, @ (a::iprange), @@ (a::iprange) from (select '::/127'::ip6r as a) s; ?column? | ?column? | ?column? | ?column? ----------+----------+----------+---------- 2 | 2 | 2 | 2 (1 row) select @ a, @@ a, @ (a::iprange), @@ (a::iprange) from (select '::/65'::ip6r as a) s; ?column? | ?column? | ?column? | ?column? ----------------------+---------------------+----------------------+--------------------- 9.22337203685478e+18 | 9223372036854775808 | 9.22337203685478e+18 | 9223372036854775808 (1 row) select @ a, @@ a, @ (a::iprange), @@ (a::iprange) from (select '::/64'::ip6r as a) s; ?column? | ?column? | ?column? | ?column? ----------------------+----------------------+----------------------+---------------------- 1.84467440737096e+19 | 18446744073709551616 | 1.84467440737096e+19 | 18446744073709551616 (1 row) select @ a, @@ a, @ (a::iprange), @@ (a::iprange) from (select '::/63'::ip6r as a) s; ?column? | ?column? | ?column? | ?column? ----------------------+----------------------+----------------------+---------------------- 3.68934881474191e+19 | 36893488147419103232 | 3.68934881474191e+19 | 36893488147419103232 (1 row) select @ a, @@ a, @ (a::iprange), @@ (a::iprange) from (select '::/1'::ip6r as a) s; ?column? | ?column? | ?column? | ?column? ----------------------+-----------------------------------------+----------------------+----------------------------------------- 1.70141183460469e+38 | 170141183460469231731687303715884105728 | 1.70141183460469e+38 | 170141183460469231731687303715884105728 (1 row) select @ a, @@ a, @ (a::iprange), @@ (a::iprange) from (select '::/0'::ip6r as a) s; ?column? | ?column? | ?column? | ?column? ----------------------+-----------------------------------------+----------------------+----------------------------------------- 3.40282366920938e+38 | 340282366920938463463374607431768211456 | 3.40282366920938e+38 | 340282366920938463463374607431768211456 (1 row) select @ a, @@ a, @ (a::iprange), @@ (a::iprange) from (select 'ffff:ffff:ffff:ffff::-ffff:ffff:ffff:ffff:8000::'::ip6r as a) s; ?column? | ?column? | ?column? | ?column? ----------------------+---------------------+----------------------+--------------------- 9.22337203685478e+18 | 9223372036854775809 | 9.22337203685478e+18 | 9223372036854775809 (1 row) select @ a, @@ a, @ (a::iprange), @@ (a::iprange) from (select 'ffff:ffff:ffff::-ffff:ffff:ffff:8000::'::ip6r as a) s; ?column? | ?column? | ?column? | ?column? ----------------------+--------------------------+----------------------+-------------------------- 6.04462909807315e+23 | 604462909807314587353089 | 6.04462909807315e+23 | 604462909807314587353089 (1 row) select @ a, @@ a, @ (a::iprange), @@ (a::iprange) from (select 'ffff:ffff::-ffff:ffff:8000::'::ip6r as a) s; ?column? | ?column? | ?column? | ?column? ----------------------+-------------------------------+----------------------+------------------------------- 3.96140812571322e+28 | 39614081257132168796771975169 | 3.96140812571322e+28 | 39614081257132168796771975169 (1 row) select @ a, @@ a, @ (a::iprange), @@ (a::iprange) from (select 'ffff::-ffff:8000::'::ip6r as a) s; ?column? | ?column? | ?column? | ?column? ----------------------+------------------------------------+----------------------+------------------------------------ 2.59614842926741e+33 | 2596148429267413814265248164610049 | 2.59614842926741e+33 | 2596148429267413814265248164610049 (1 row) select @ a, @@ a from (select '-'::iprange as a) s; ?column? | ?column? ----------------------+----------------------------------------- 6.80564733841877e+38 | 680564733841876926926749214863536422912 (1 row) -- bitwise ops select a & b, a::ipaddress & b::ipaddress from (select ip4 '1.2.3.4' as a, ip4 '255.0.255.0' as b) s; ?column? | ?column? ----------+---------- 1.0.3.0 | 1.0.3.0 (1 row) select a | b, a::ipaddress | b::ipaddress from (select ip4 '1.2.3.4' as a, ip4 '255.0.255.0' as b) s; ?column? | ?column? -------------+------------- 255.2.255.4 | 255.2.255.4 (1 row) select a # b, a::ipaddress # b::ipaddress from (select ip4 '1.2.3.4' as a, ip4 '255.0.255.0' as b) s; ?column? | ?column? -------------+------------- 254.2.252.4 | 254.2.252.4 (1 row) select ~a, ~(a::ipaddress) from (select ip4 '1.2.3.4' as a) s; ?column? | ?column? -----------------+----------------- 254.253.252.251 | 254.253.252.251 (1 row) select a & b, a::ipaddress & b::ipaddress from (select ip6 '1234::5678' as a, ip6 'ffff:0000:ffff:0000:ffff:0000:ffff:0000' as b) s; ?column? | ?column? ----------+---------- 1234:: | 1234:: (1 row) select a | b, a::ipaddress | b::ipaddress from (select ip6 '1234::5678' as a, ip6 'ffff:0000:ffff:0000:ffff:0000:ffff:0000' as b) s; ?column? | ?column? --------------------------------+-------------------------------- ffff:0:ffff:0:ffff:0:ffff:5678 | ffff:0:ffff:0:ffff:0:ffff:5678 (1 row) select a # b, a::ipaddress # b::ipaddress from (select ip6 '1234::5678' as a, ip6 'ffff:0000:ffff:0000:ffff:0000:ffff:0000' as b) s; ?column? | ?column? --------------------------------+-------------------------------- edcb:0:ffff:0:ffff:0:ffff:5678 | edcb:0:ffff:0:ffff:0:ffff:5678 (1 row) select ~a, ~(a::ipaddress) from (select ip6 '1234::5678' as a) s; ?column? | ?column? -----------------------------------------+----------------------------------------- edcb:ffff:ffff:ffff:ffff:ffff:ffff:a987 | edcb:ffff:ffff:ffff:ffff:ffff:ffff:a987 (1 row) -- arithmetic select a + 1234, a::ipaddress + 1234 from (select ip4 '0.0.0.0' as a) s; ?column? | ?column? -----------+----------- 0.0.4.210 | 0.0.4.210 (1 row) select a + 1, a::ipaddress + 1 from (select ip4 '255.255.255.254' as a) s; ?column? | ?column? -----------------+----------------- 255.255.255.255 | 255.255.255.255 (1 row) select a + 1 from (select ip4 '255.255.255.255' as a) s; ERROR: ip address out of range select a::ipaddress + 1 from (select ip4 '255.255.255.255' as a) s; ERROR: ip address out of range select a - 1234, a::ipaddress - 1234 from (select ip4 '1.0.0.0' as a) s; ?column? | ?column? --------------+-------------- 0.255.251.46 | 0.255.251.46 (1 row) select a - 1, a::ipaddress - 1 from (select ip4 '0.0.0.1' as a) s; ?column? | ?column? ----------+---------- 0.0.0.0 | 0.0.0.0 (1 row) select a - 1 from (select ip4 '0.0.0.0' as a) s; ERROR: ip address out of range select a::ipaddress - 1 from (select ip4 '0.0.0.0' as a) s; ERROR: ip address out of range select a + 1234::bigint, a::ipaddress + 1234::bigint from (select ip4 '0.0.0.0' as a) s; ?column? | ?column? -----------+----------- 0.0.4.210 | 0.0.4.210 (1 row) select a + 1::bigint, a::ipaddress + 1::bigint from (select ip4 '255.255.255.254' as a) s; ?column? | ?column? -----------------+----------------- 255.255.255.255 | 255.255.255.255 (1 row) select a + 1::bigint from (select ip4 '255.255.255.255' as a) s; ERROR: ip address out of range select a::ipaddress + 1::bigint from (select ip4 '255.255.255.255' as a) s; ERROR: ip address out of range select a + 4294967296::bigint from (select ip4 '0.0.0.0' as a) s; ERROR: ip address out of range select a::ipaddress + 4294967296::bigint from (select ip4 '0.0.0.0' as a) s; ERROR: ip address out of range select a - 1234::bigint, a::ipaddress - 1234::bigint from (select ip4 '1.0.0.0' as a) s; ?column? | ?column? --------------+-------------- 0.255.251.46 | 0.255.251.46 (1 row) select a - 1::bigint, a::ipaddress - 1::bigint from (select ip4 '0.0.0.1' as a) s; ?column? | ?column? ----------+---------- 0.0.0.0 | 0.0.0.0 (1 row) select a - 1::bigint from (select ip4 '0.0.0.0' as a) s; ERROR: ip address out of range select a::ipaddress - 1::bigint from (select ip4 '0.0.0.0' as a) s; ERROR: ip address out of range select a - 4294967296::bigint from (select ip4 '255.255.255.255' as a) s; ERROR: ip address out of range select a::ipaddress - 4294967296::bigint from (select ip4 '255.255.255.255' as a) s; ERROR: ip address out of range select a + 1234::numeric, a::ipaddress + 1234::numeric from (select ip4 '0.0.0.0' as a) s; ?column? | ?column? -----------+----------- 0.0.4.210 | 0.0.4.210 (1 row) select a + 1::numeric, a::ipaddress + 1::numeric from (select ip4 '255.255.255.254' as a) s; ?column? | ?column? -----------------+----------------- 255.255.255.255 | 255.255.255.255 (1 row) select a + 1::numeric from (select ip4 '255.255.255.255' as a) s; ERROR: ip address out of range select a::ipaddress + 1::numeric from (select ip4 '255.255.255.255' as a) s; ERROR: ip address out of range select a + 4294967296::numeric from (select ip4 '0.0.0.0' as a) s; ERROR: ip address out of range select a::ipaddress + 4294967296::numeric from (select ip4 '0.0.0.0' as a) s; ERROR: ip address out of range select a - 1234::numeric, a::ipaddress - 1234::numeric from (select ip4 '1.0.0.0' as a) s; ?column? | ?column? --------------+-------------- 0.255.251.46 | 0.255.251.46 (1 row) select a - 1::numeric, a::ipaddress - 1::numeric from (select ip4 '0.0.0.1' as a) s; ?column? | ?column? ----------+---------- 0.0.0.0 | 0.0.0.0 (1 row) select a - 1::numeric from (select ip4 '0.0.0.0' as a) s; ERROR: ip address out of range select a::ipaddress - 1::numeric from (select ip4 '0.0.0.0' as a) s; ERROR: ip address out of range select a - 4294967296::bigint from (select ip4 '255.255.255.255' as a) s; ERROR: ip address out of range select a::ipaddress - 4294967296::bigint from (select ip4 '255.255.255.255' as a) s; ERROR: ip address out of range -- predicates and indexing create table ipranges (r iprange, r4 ip4r, r6 ip6r); insert into ipranges select r, null, r from (select ip6r(regexp_replace(ls, E'(....(?!$))', E'\\1:', 'g')::ip6, regexp_replace(substring(ls for n+1) || substring(us from n+2), E'(....(?!$))', E'\\1:', 'g')::ip6) as r from (select md5(i || ' lower 1') as ls, md5(i || ' upper 1') as us, (i % 11) + (i/11 % 11) + (i/121 % 11) as n from generate_series(1,13310) i) s1) s2; insert into ipranges select r, r, null from (select ip4r(ip4 '0.0.0.0' + ((la & '::ffff:ffff') - ip6 '::'), ip4 '0.0.0.0' + ((( (la & ip6_netmask(127-n)) | (ua & ~ip6_netmask(127-n)) ) & '::ffff:ffff') - ip6 '::')) as r from (select regexp_replace(md5(i || ' lower 2'), E'(....(?!$))', E'\\1:', 'g')::ip6 as la, regexp_replace(md5(i || ' upper 2'), E'(....(?!$))', E'\\1:', 'g')::ip6 as ua, (i % 11) + (i/11 % 11) + (i/121 % 11) as n from generate_series(1,1331) i) s1) s2; insert into ipranges select r, null, r from (select n::ip6 / 68 as r from (select ((8192 + i/256)::numeric * (2::numeric ^ 112) + (131072 + (i % 256))::numeric * (2::numeric ^ 60)) as n from generate_series(0,4095) i) s1) s2; insert into ipranges select r, r, null from (select n / 28 as r from (select ip4 '172.16.0.0' + (i * 256) as n from generate_series(0,4095) i) s1) s2; insert into ipranges select r, null, r from (select n::ip6 / 48 as r from (select ((8192 + i/256)::numeric * (2::numeric ^ 112) + (i % 256)::numeric * (2::numeric ^ 84)) as n from generate_series(0,4095) i) s1) s2; insert into ipranges select r, r, null from (select n / 16 as r from (select ip4 '128.0.0.0' + (i * 65536) as n from generate_series(0,4095) i) s1) s2; insert into ipranges values ('-',null,null); create table ipaddrs (a ipaddress, a4 ip4, a6 ip6); insert into ipaddrs select a, null, a from (select regexp_replace(md5(i || ' address 1'), E'(....(?!$))', E'\\1:', 'g')::ip6 as a from generate_series(1,256) i) s1; insert into ipaddrs select a, a, null from (select ip4 '0.0.0.0' + ((regexp_replace(md5(i || ' address 1'), E'(....(?!$))', E'\\1:', 'g')::ip6 & '::ffff:ffff') - '::') as a from generate_series(1,16) i) s1; select * from ipranges where r >>= '5555::' order by r; r | r4 | r6 --------------------------------------------------------------------------------+----+-------------------------------------------------------------------------------- - | | 5538:b6cb:ac50:bafe:dcd4:19e6:9ed0:2f2d-55f1:14f:6870:73ba:d803:ba0e:b968:d45e | | 5538:b6cb:ac50:bafe:dcd4:19e6:9ed0:2f2d-55f1:14f:6870:73ba:d803:ba0e:b968:d45e (2 rows) select * from ipranges where r <<= '5555::/16' order by r; r | r4 | r6 ---------------------------------------------------------------------------------+----+--------------------------------------------------------------------------------- 5555:50fc:35c2:a4c9:7424:1aac:86c8:b3db-5555:50fc:35c2:a4c9:7424:1aaf:fe86:d6d4 | | 5555:50fc:35c2:a4c9:7424:1aac:86c8:b3db-5555:50fc:35c2:a4c9:7424:1aaf:fe86:d6d4 (1 row) select * from ipranges where r && '5555::/16' order by r; r | r4 | r6 ---------------------------------------------------------------------------------+----+--------------------------------------------------------------------------------- - | | 5538:b6cb:ac50:bafe:dcd4:19e6:9ed0:2f2d-55f1:14f:6870:73ba:d803:ba0e:b968:d45e | | 5538:b6cb:ac50:bafe:dcd4:19e6:9ed0:2f2d-55f1:14f:6870:73ba:d803:ba0e:b968:d45e 5555:50fc:35c2:a4c9:7424:1aac:86c8:b3db-5555:50fc:35c2:a4c9:7424:1aaf:fe86:d6d4 | | 5555:50fc:35c2:a4c9:7424:1aac:86c8:b3db-5555:50fc:35c2:a4c9:7424:1aaf:fe86:d6d4 (3 rows) select * from ipranges where r6 >>= '5555::' order by r6; r | r4 | r6 --------------------------------------------------------------------------------+----+-------------------------------------------------------------------------------- 5538:b6cb:ac50:bafe:dcd4:19e6:9ed0:2f2d-55f1:14f:6870:73ba:d803:ba0e:b968:d45e | | 5538:b6cb:ac50:bafe:dcd4:19e6:9ed0:2f2d-55f1:14f:6870:73ba:d803:ba0e:b968:d45e (1 row) select * from ipranges where r6 <<= '5555::/16' order by r6; r | r4 | r6 ---------------------------------------------------------------------------------+----+--------------------------------------------------------------------------------- 5555:50fc:35c2:a4c9:7424:1aac:86c8:b3db-5555:50fc:35c2:a4c9:7424:1aaf:fe86:d6d4 | | 5555:50fc:35c2:a4c9:7424:1aac:86c8:b3db-5555:50fc:35c2:a4c9:7424:1aaf:fe86:d6d4 (1 row) select * from ipranges where r6 && '5555::/16' order by r6; r | r4 | r6 ---------------------------------------------------------------------------------+----+--------------------------------------------------------------------------------- 5538:b6cb:ac50:bafe:dcd4:19e6:9ed0:2f2d-55f1:14f:6870:73ba:d803:ba0e:b968:d45e | | 5538:b6cb:ac50:bafe:dcd4:19e6:9ed0:2f2d-55f1:14f:6870:73ba:d803:ba0e:b968:d45e 5555:50fc:35c2:a4c9:7424:1aac:86c8:b3db-5555:50fc:35c2:a4c9:7424:1aaf:fe86:d6d4 | | 5555:50fc:35c2:a4c9:7424:1aac:86c8:b3db-5555:50fc:35c2:a4c9:7424:1aaf:fe86:d6d4 (2 rows) select * from ipranges where r >>= '172.16.2.0' order by r; r | r4 | r6 -------------------------------+-------------------------------+---- - | | 155.206.49.182-190.20.159.162 | 155.206.49.182-190.20.159.162 | 172.16.2.0/28 | 172.16.2.0/28 | (3 rows) select * from ipranges where r <<= '10.0.0.0/12' order by r; r | r4 | r6 -----------------------------+-----------------------------+---- 10.4.12.130-10.5.82.192 | 10.4.12.130-10.5.82.192 | 10.10.145.149-10.13.167.136 | 10.10.145.149-10.13.167.136 | (2 rows) select * from ipranges where r && '10.128.0.0/12' order by r; r | r4 | r6 ----------------------------+----------------------------+---- - | | 9.228.56.34-28.197.214.173 | 9.228.56.34-28.197.214.173 | (2 rows) select * from ipranges where r4 >>= '172.16.2.0' order by r4; r | r4 | r6 -------------------------------+-------------------------------+---- 155.206.49.182-190.20.159.162 | 155.206.49.182-190.20.159.162 | 172.16.2.0/28 | 172.16.2.0/28 | (2 rows) select * from ipranges where r4 <<= '10.0.0.0/12' order by r4; r | r4 | r6 -----------------------------+-----------------------------+---- 10.4.12.130-10.5.82.192 | 10.4.12.130-10.5.82.192 | 10.10.145.149-10.13.167.136 | 10.10.145.149-10.13.167.136 | (2 rows) select * from ipranges where r4 && '10.128.0.0/12' order by r4; r | r4 | r6 ----------------------------+----------------------------+---- 9.228.56.34-28.197.214.173 | 9.228.56.34-28.197.214.173 | (1 row) select * from ipranges where r >>= '2001:0:0:2000:a123::' order by r; r | r4 | r6 -------------------------+----+------------------------- - | | 2001::/48 | | 2001::/48 2001:0:0:2000:a000::/68 | | 2001:0:0:2000:a000::/68 (3 rows) select * from ipranges where r >>= '2001:0:0:2000::' order by r; r | r4 | r6 --------------------+----+-------------------- - | | 2001::/48 | | 2001::/48 2001:0:0:2000::/68 | | 2001:0:0:2000::/68 (3 rows) select * from ipranges where r >>= '2001:0:0:2000::/68' order by r; r | r4 | r6 --------------------+----+-------------------- - | | 2001::/48 | | 2001::/48 2001:0:0:2000::/68 | | 2001:0:0:2000::/68 (3 rows) select * from ipranges where r >> '2001:0:0:2000::/68' order by r; r | r4 | r6 -----------+----+----------- - | | 2001::/48 | | 2001::/48 (2 rows) select * from ipranges where r6 >>= '2001:0:0:2000:a123::' order by r6; r | r4 | r6 -------------------------+----+------------------------- 2001::/48 | | 2001::/48 2001:0:0:2000:a000::/68 | | 2001:0:0:2000:a000::/68 (2 rows) select * from ipranges where r6 >>= '2001:0:0:2000::' order by r6; r | r4 | r6 --------------------+----+-------------------- 2001::/48 | | 2001::/48 2001:0:0:2000::/68 | | 2001:0:0:2000::/68 (2 rows) select * from ipranges where r6 >>= '2001:0:0:2000::/68' order by r6; r | r4 | r6 --------------------+----+-------------------- 2001::/48 | | 2001::/48 2001:0:0:2000::/68 | | 2001:0:0:2000::/68 (2 rows) select * from ipranges where r6 >> '2001:0:0:2000::/68' order by r6; r | r4 | r6 -----------+----+----------- 2001::/48 | | 2001::/48 (1 row) select * from ipranges where r4 >>= '172.16.2.0/28' order by r4; r | r4 | r6 -------------------------------+-------------------------------+---- 155.206.49.182-190.20.159.162 | 155.206.49.182-190.20.159.162 | 172.16.2.0/28 | 172.16.2.0/28 | (2 rows) select * from ipranges where r4 >> '172.16.2.0/28' order by r4; r | r4 | r6 -------------------------------+-------------------------------+---- 155.206.49.182-190.20.159.162 | 155.206.49.182-190.20.159.162 | (1 row) select * from ipaddrs where a between '8.0.0.0' and '15.0.0.0' order by a; a | a4 | a6 --------------+--------------+---- 12.174.29.15 | 12.174.29.15 | (1 row) select * from ipaddrs where a4 between '8.0.0.0' and '15.0.0.0' order by a4; a | a4 | a6 --------------+--------------+---- 12.174.29.15 | 12.174.29.15 | (1 row) create index ipranges_r on ipranges using gist (r); create index ipranges_r4 on ipranges using gist (r4); create index ipranges_r6 on ipranges using gist (r6); create index ipaddrs_a on ipaddrs (a); create index ipaddrs_a4 on ipaddrs (a4); create index ipaddrs_a6 on ipaddrs (a6); select * from ipranges where r >>= '5555::' order by r; r | r4 | r6 --------------------------------------------------------------------------------+----+-------------------------------------------------------------------------------- - | | 5538:b6cb:ac50:bafe:dcd4:19e6:9ed0:2f2d-55f1:14f:6870:73ba:d803:ba0e:b968:d45e | | 5538:b6cb:ac50:bafe:dcd4:19e6:9ed0:2f2d-55f1:14f:6870:73ba:d803:ba0e:b968:d45e (2 rows) select * from ipranges where r <<= '5555::/16' order by r; r | r4 | r6 ---------------------------------------------------------------------------------+----+--------------------------------------------------------------------------------- 5555:50fc:35c2:a4c9:7424:1aac:86c8:b3db-5555:50fc:35c2:a4c9:7424:1aaf:fe86:d6d4 | | 5555:50fc:35c2:a4c9:7424:1aac:86c8:b3db-5555:50fc:35c2:a4c9:7424:1aaf:fe86:d6d4 (1 row) select * from ipranges where r && '5555::/16' order by r; r | r4 | r6 ---------------------------------------------------------------------------------+----+--------------------------------------------------------------------------------- - | | 5538:b6cb:ac50:bafe:dcd4:19e6:9ed0:2f2d-55f1:14f:6870:73ba:d803:ba0e:b968:d45e | | 5538:b6cb:ac50:bafe:dcd4:19e6:9ed0:2f2d-55f1:14f:6870:73ba:d803:ba0e:b968:d45e 5555:50fc:35c2:a4c9:7424:1aac:86c8:b3db-5555:50fc:35c2:a4c9:7424:1aaf:fe86:d6d4 | | 5555:50fc:35c2:a4c9:7424:1aac:86c8:b3db-5555:50fc:35c2:a4c9:7424:1aaf:fe86:d6d4 (3 rows) select * from ipranges where r6 >>= '5555::' order by r6; r | r4 | r6 --------------------------------------------------------------------------------+----+-------------------------------------------------------------------------------- 5538:b6cb:ac50:bafe:dcd4:19e6:9ed0:2f2d-55f1:14f:6870:73ba:d803:ba0e:b968:d45e | | 5538:b6cb:ac50:bafe:dcd4:19e6:9ed0:2f2d-55f1:14f:6870:73ba:d803:ba0e:b968:d45e (1 row) select * from ipranges where r6 <<= '5555::/16' order by r6; r | r4 | r6 ---------------------------------------------------------------------------------+----+--------------------------------------------------------------------------------- 5555:50fc:35c2:a4c9:7424:1aac:86c8:b3db-5555:50fc:35c2:a4c9:7424:1aaf:fe86:d6d4 | | 5555:50fc:35c2:a4c9:7424:1aac:86c8:b3db-5555:50fc:35c2:a4c9:7424:1aaf:fe86:d6d4 (1 row) select * from ipranges where r6 && '5555::/16' order by r6; r | r4 | r6 ---------------------------------------------------------------------------------+----+--------------------------------------------------------------------------------- 5538:b6cb:ac50:bafe:dcd4:19e6:9ed0:2f2d-55f1:14f:6870:73ba:d803:ba0e:b968:d45e | | 5538:b6cb:ac50:bafe:dcd4:19e6:9ed0:2f2d-55f1:14f:6870:73ba:d803:ba0e:b968:d45e 5555:50fc:35c2:a4c9:7424:1aac:86c8:b3db-5555:50fc:35c2:a4c9:7424:1aaf:fe86:d6d4 | | 5555:50fc:35c2:a4c9:7424:1aac:86c8:b3db-5555:50fc:35c2:a4c9:7424:1aaf:fe86:d6d4 (2 rows) select * from ipranges where r >>= '172.16.2.0' order by r; r | r4 | r6 -------------------------------+-------------------------------+---- - | | 155.206.49.182-190.20.159.162 | 155.206.49.182-190.20.159.162 | 172.16.2.0/28 | 172.16.2.0/28 | (3 rows) select * from ipranges where r <<= '10.0.0.0/12' order by r; r | r4 | r6 -----------------------------+-----------------------------+---- 10.4.12.130-10.5.82.192 | 10.4.12.130-10.5.82.192 | 10.10.145.149-10.13.167.136 | 10.10.145.149-10.13.167.136 | (2 rows) select * from ipranges where r && '10.128.0.0/12' order by r; r | r4 | r6 ----------------------------+----------------------------+---- - | | 9.228.56.34-28.197.214.173 | 9.228.56.34-28.197.214.173 | (2 rows) select * from ipranges where r4 >>= '172.16.2.0' order by r4; r | r4 | r6 -------------------------------+-------------------------------+---- 155.206.49.182-190.20.159.162 | 155.206.49.182-190.20.159.162 | 172.16.2.0/28 | 172.16.2.0/28 | (2 rows) select * from ipranges where r4 <<= '10.0.0.0/12' order by r4; r | r4 | r6 -----------------------------+-----------------------------+---- 10.4.12.130-10.5.82.192 | 10.4.12.130-10.5.82.192 | 10.10.145.149-10.13.167.136 | 10.10.145.149-10.13.167.136 | (2 rows) select * from ipranges where r4 && '10.128.0.0/12' order by r4; r | r4 | r6 ----------------------------+----------------------------+---- 9.228.56.34-28.197.214.173 | 9.228.56.34-28.197.214.173 | (1 row) select * from ipranges where r >>= '2001:0:0:2000:a123::' order by r; r | r4 | r6 -------------------------+----+------------------------- - | | 2001::/48 | | 2001::/48 2001:0:0:2000:a000::/68 | | 2001:0:0:2000:a000::/68 (3 rows) select * from ipranges where r >>= '2001:0:0:2000::' order by r; r | r4 | r6 --------------------+----+-------------------- - | | 2001::/48 | | 2001::/48 2001:0:0:2000::/68 | | 2001:0:0:2000::/68 (3 rows) select * from ipranges where r >>= '2001:0:0:2000::/68' order by r; r | r4 | r6 --------------------+----+-------------------- - | | 2001::/48 | | 2001::/48 2001:0:0:2000::/68 | | 2001:0:0:2000::/68 (3 rows) select * from ipranges where r >> '2001:0:0:2000::/68' order by r; r | r4 | r6 -----------+----+----------- - | | 2001::/48 | | 2001::/48 (2 rows) select * from ipranges where r6 >>= '2001:0:0:2000:a123::' order by r6; r | r4 | r6 -------------------------+----+------------------------- 2001::/48 | | 2001::/48 2001:0:0:2000:a000::/68 | | 2001:0:0:2000:a000::/68 (2 rows) select * from ipranges where r6 >>= '2001:0:0:2000::' order by r6; r | r4 | r6 --------------------+----+-------------------- 2001::/48 | | 2001::/48 2001:0:0:2000::/68 | | 2001:0:0:2000::/68 (2 rows) select * from ipranges where r6 >>= '2001:0:0:2000::/68' order by r6; r | r4 | r6 --------------------+----+-------------------- 2001::/48 | | 2001::/48 2001:0:0:2000::/68 | | 2001:0:0:2000::/68 (2 rows) select * from ipranges where r6 >> '2001:0:0:2000::/68' order by r6; r | r4 | r6 -----------+----+----------- 2001::/48 | | 2001::/48 (1 row) select * from ipranges where r4 >>= '172.16.2.0/28' order by r4; r | r4 | r6 -------------------------------+-------------------------------+---- 155.206.49.182-190.20.159.162 | 155.206.49.182-190.20.159.162 | 172.16.2.0/28 | 172.16.2.0/28 | (2 rows) select * from ipranges where r4 >> '172.16.2.0/28' order by r4; r | r4 | r6 -------------------------------+-------------------------------+---- 155.206.49.182-190.20.159.162 | 155.206.49.182-190.20.159.162 | (1 row) select * from ipaddrs where a between '8.0.0.0' and '15.0.0.0' order by a; a | a4 | a6 --------------+--------------+---- 12.174.29.15 | 12.174.29.15 | (1 row) select * from ipaddrs where a4 between '8.0.0.0' and '15.0.0.0' order by a4; a | a4 | a6 --------------+--------------+---- 12.174.29.15 | 12.174.29.15 | (1 row) select * from ipaddrs a join ipranges r on (r.r >>= a.a) order by a,r; a | a4 | a6 | r | r4 | r6 -----------------------------------------+-----------------+-----------------------------------------+---------------------------------------------------------------------------------+--------------------------------+--------------------------------------------------------------------------------- 12.174.29.15 | 12.174.29.15 | | - | | 12.174.29.15 | 12.174.29.15 | | 9.228.56.34-28.197.214.173 | 9.228.56.34-28.197.214.173 | 33.8.16.211 | 33.8.16.211 | | - | | 33.8.16.211 | 33.8.16.211 | | 32.219.217.193-34.140.113.120 | 32.219.217.193-34.140.113.120 | 55.224.125.146 | 55.224.125.146 | | - | | 73.239.169.71 | 73.239.169.71 | | - | | 73.239.169.71 | 73.239.169.71 | | 65.76.62.93-75.189.2.219 | 65.76.62.93-75.189.2.219 | 73.239.169.71 | 73.239.169.71 | | 70.178.141.1-79.252.178.95 | 70.178.141.1-79.252.178.95 | 76.178.38.194 | 76.178.38.194 | | - | | 76.178.38.194 | 76.178.38.194 | | 70.178.141.1-79.252.178.95 | 70.178.141.1-79.252.178.95 | 76.178.38.194 | 76.178.38.194 | | 75.211.173.58-77.84.189.178 | 75.211.173.58-77.84.189.178 | 76.178.38.194 | 76.178.38.194 | | 76.164.111.154-76.183.66.114 | 76.164.111.154-76.183.66.114 | 96.76.124.246 | 96.76.124.246 | | - | | 104.175.11.72 | 104.175.11.72 | | - | | 104.175.11.72 | 104.175.11.72 | | 104.76.127.225-105.198.184.62 | 104.76.127.225-105.198.184.62 | 163.145.90.183 | 163.145.90.183 | | - | | 163.145.90.183 | 163.145.90.183 | | 155.206.49.182-190.20.159.162 | 155.206.49.182-190.20.159.162 | 189.85.58.60 | 189.85.58.60 | | - | | 189.85.58.60 | 189.85.58.60 | | 155.206.49.182-190.20.159.162 | 155.206.49.182-190.20.159.162 | 189.85.58.60 | 189.85.58.60 | | 184.142.247.0-191.129.204.149 | 184.142.247.0-191.129.204.149 | 195.58.214.186 | 195.58.214.186 | | - | | 195.58.214.186 | 195.58.214.186 | | 192.198.196.94-195.116.202.186 | 192.198.196.94-195.116.202.186 | 195.58.214.186 | 195.58.214.186 | | 194.50.23.161-195.215.1.54 | 194.50.23.161-195.215.1.54 | 203.156.110.93 | 203.156.110.93 | | - | | 223.213.219.214 | 223.213.219.214 | | - | | 223.213.219.214 | 223.213.219.214 | | 207.129.8.36-240.135.140.181 | 207.129.8.36-240.135.140.181 | 235.64.97.205 | 235.64.97.205 | | - | | 235.64.97.205 | 235.64.97.205 | | 207.129.8.36-240.135.140.181 | 207.129.8.36-240.135.140.181 | 235.64.97.205 | 235.64.97.205 | | 233.169.207.115-238.213.223.60 | 233.169.207.115-238.213.223.60 | 235.64.97.205 | 235.64.97.205 | | 234.48.112.251-235.130.33.88 | 234.48.112.251-235.130.33.88 | 240.116.30.226 | 240.116.30.226 | | - | | 240.116.30.226 | 240.116.30.226 | | 207.129.8.36-240.135.140.181 | 207.129.8.36-240.135.140.181 | 254.251.8.237 | 254.251.8.237 | | - | | 255.226.130.53 | 255.226.130.53 | | - | | 255.226.130.53 | 255.226.130.53 | | 255.148.94.59-255.232.142.189 | 255.148.94.59-255.232.142.189 | 73:3c34:57a:2a84:b1df:81b0:eb40:61cd | | 73:3c34:57a:2a84:b1df:81b0:eb40:61cd | - | | 73:3c34:57a:2a84:b1df:81b0:eb40:61cd | | 73:3c34:57a:2a84:b1df:81b0:eb40:61cd | 6d:d4d7:e3dc:b30c:d0f3:6ae3:907e:beb2-a4:f5d3:b64e:8e01:5f11:d5c3:be0b:e20c | | 6d:d4d7:e3dc:b30c:d0f3:6ae3:907e:beb2-a4:f5d3:b64e:8e01:5f11:d5c3:be0b:e20c b6:8ebc:c326:48a6:5615:a65e:e87a:25d7 | | b6:8ebc:c326:48a6:5615:a65e:e87a:25d7 | - | | 166:b8ea:1fc5:8913:17ea:d6a0:ac2b:90e1 | | 166:b8ea:1fc5:8913:17ea:d6a0:ac2b:90e1 | - | | 227:b768:d43b:773d:6168:5133:867c:13f2 | | 227:b768:d43b:773d:6168:5133:867c:13f2 | - | | 227:b768:d43b:773d:6168:5133:867c:13f2 | | 227:b768:d43b:773d:6168:5133:867c:13f2 | 176:6781:47c:8022:8ab8:8b64:a8ce:da2c-863:40d1:76b:fbce:b89e:221f:ddb0:7679 | | 176:6781:47c:8022:8ab8:8b64:a8ce:da2c-863:40d1:76b:fbce:b89e:221f:ddb0:7679 453:2d:fbd3:191:95c6:3751:eb62:e90 | | 453:2d:fbd3:191:95c6:3751:eb62:e90 | - | | 453:2d:fbd3:191:95c6:3751:eb62:e90 | | 453:2d:fbd3:191:95c6:3751:eb62:e90 | 176:6781:47c:8022:8ab8:8b64:a8ce:da2c-863:40d1:76b:fbce:b89e:221f:ddb0:7679 | | 176:6781:47c:8022:8ab8:8b64:a8ce:da2c-863:40d1:76b:fbce:b89e:221f:ddb0:7679 4a6:7a28:b05b:f9b4:cc5b:9c4c:eefe:3e06 | | 4a6:7a28:b05b:f9b4:cc5b:9c4c:eefe:3e06 | - | | 4a6:7a28:b05b:f9b4:cc5b:9c4c:eefe:3e06 | | 4a6:7a28:b05b:f9b4:cc5b:9c4c:eefe:3e06 | 176:6781:47c:8022:8ab8:8b64:a8ce:da2c-863:40d1:76b:fbce:b89e:221f:ddb0:7679 | | 176:6781:47c:8022:8ab8:8b64:a8ce:da2c-863:40d1:76b:fbce:b89e:221f:ddb0:7679 550:fe90:bd02:a3ed:35a2:3254:e280:cd20 | | 550:fe90:bd02:a3ed:35a2:3254:e280:cd20 | - | | 550:fe90:bd02:a3ed:35a2:3254:e280:cd20 | | 550:fe90:bd02:a3ed:35a2:3254:e280:cd20 | 176:6781:47c:8022:8ab8:8b64:a8ce:da2c-863:40d1:76b:fbce:b89e:221f:ddb0:7679 | | 176:6781:47c:8022:8ab8:8b64:a8ce:da2c-863:40d1:76b:fbce:b89e:221f:ddb0:7679 75d:e701:5702:6087:a69a:1a2d:376e:4eb | | 75d:e701:5702:6087:a69a:1a2d:376e:4eb | - | | 75d:e701:5702:6087:a69a:1a2d:376e:4eb | | 75d:e701:5702:6087:a69a:1a2d:376e:4eb | 176:6781:47c:8022:8ab8:8b64:a8ce:da2c-863:40d1:76b:fbce:b89e:221f:ddb0:7679 | | 176:6781:47c:8022:8ab8:8b64:a8ce:da2c-863:40d1:76b:fbce:b89e:221f:ddb0:7679 7e1:a608:dadd:684d:679e:698b:4db:c8c2 | | 7e1:a608:dadd:684d:679e:698b:4db:c8c2 | - | | 7e1:a608:dadd:684d:679e:698b:4db:c8c2 | | 7e1:a608:dadd:684d:679e:698b:4db:c8c2 | 176:6781:47c:8022:8ab8:8b64:a8ce:da2c-863:40d1:76b:fbce:b89e:221f:ddb0:7679 | | 176:6781:47c:8022:8ab8:8b64:a8ce:da2c-863:40d1:76b:fbce:b89e:221f:ddb0:7679 9ec:8fec:9a0e:3f2a:66e2:9b5c:498a:1090 | | 9ec:8fec:9a0e:3f2a:66e2:9b5c:498a:1090 | - | | a4b:4e55:7510:69b9:ba73:6550:eaa7:f16e | | a4b:4e55:7510:69b9:ba73:6550:eaa7:f16e | - | | bdb:15d3:fbaf:4bf6:194e:4d0d:4cb2:26c2 | | bdb:15d3:fbaf:4bf6:194e:4d0d:4cb2:26c2 | - | | cc6:3030:8e26:ed4a:ae48:4496:63c3:94d0 | | cc6:3030:8e26:ed4a:ae48:4496:63c3:94d0 | - | | ce0:f080:aff1:6780:4951:55a7:4c23:f108 | | ce0:f080:aff1:6780:4951:55a7:4c23:f108 | - | | d6b:f94a:4040:ba81:2347:d486:ac79:96f7 | | d6b:f94a:4040:ba81:2347:d486:ac79:96f7 | - | | d9a:933a:3c47:801a:51d4:5a48:13bb:f59b | | d9a:933a:3c47:801a:51d4:5a48:13bb:f59b | - | | ded:898a:e003:6046:72e6:5584:1012:62cc | | ded:898a:e003:6046:72e6:5584:1012:62cc | - | | f47:6def:21e4:4620:3bc:9abc:8abd:aba2 | | f47:6def:21e4:4620:3bc:9abc:8abd:aba2 | - | | 1009:d4ec:fe15:7946:eff2:6827:349e:6f0c | | 1009:d4ec:fe15:7946:eff2:6827:349e:6f0c | - | | 10a5:994f:884d:9f98:4920:408d:1504:561d | | 10a5:994f:884d:9f98:4920:408d:1504:561d | - | | 1378:f0c0:8ca:c76d:f062:4b7a:2573:5710 | | 1378:f0c0:8ca:c76d:f062:4b7a:2573:5710 | - | | 1395:59cf:33f6:988:1cf8:5ef3:3c2f:64dc | | 1395:59cf:33f6:988:1cf8:5ef3:3c2f:64dc | - | | 13d9:9e39:ff4a:875f:82a0:77bc:1559:cf8d | | 13d9:9e39:ff4a:875f:82a0:77bc:1559:cf8d | - | | 13fb:9738:a243:f879:730:2b72:783f:75e9 | | 13fb:9738:a243:f879:730:2b72:783f:75e9 | - | | 14fd:6de8:95f:fade:a20c:81d3:98da:c560 | | 14fd:6de8:95f:fade:a20c:81d3:98da:c560 | - | | 1520:c2bc:8426:2927:9e12:5f90:f4b0:30e6 | | 1520:c2bc:8426:2927:9e12:5f90:f4b0:30e6 | - | | 163a:503e:a2d7:c0d8:f5ee:657e:7f23:ea52 | | 163a:503e:a2d7:c0d8:f5ee:657e:7f23:ea52 | - | | 1685:dcd3:5113:5d84:2e64:d9e2:a602:aab7 | | 1685:dcd3:5113:5d84:2e64:d9e2:a602:aab7 | - | | 1839:8d68:ec5f:a4e7:711d:124e:150b:cddf | | 1839:8d68:ec5f:a4e7:711d:124e:150b:cddf | - | | 1863:bf8e:aef5:1ac4:f85a:6683:8f7c:d191 | | 1863:bf8e:aef5:1ac4:f85a:6683:8f7c:d191 | - | | 18e8:f97:72d0:5444:c94:99fe:4a9e:f657 | | 18e8:f97:72d0:5444:c94:99fe:4a9e:f657 | - | | 18eb:378d:f12f:6114:34d2:ce03:e0d8:cffc | | 18eb:378d:f12f:6114:34d2:ce03:e0d8:cffc | - | | 1962:ff9f:665f:ba25:d25a:f530:a391:5ab7 | | 1962:ff9f:665f:ba25:d25a:f530:a391:5ab7 | - | | 1b96:6d23:348f:a5f2:1869:1cd5:eff5:d09a | | 1b96:6d23:348f:a5f2:1869:1cd5:eff5:d09a | - | | 1bc2:3fea:257c:553e:eb87:d8c7:ef94:4c9 | | 1bc2:3fea:257c:553e:eb87:d8c7:ef94:4c9 | - | | 1be9:3504:b341:17a8:10ec:e646:b0:433 | | 1be9:3504:b341:17a8:10ec:e646:b0:433 | - | | 1c3e:17b6:1bfd:77ea:2185:9748:38d:ac80 | | 1c3e:17b6:1bfd:77ea:2185:9748:38d:ac80 | - | | 1c3e:17b6:1bfd:77ea:2185:9748:38d:ac80 | | 1c3e:17b6:1bfd:77ea:2185:9748:38d:ac80 | 1c1d:d54b:5bb8:fe5b:db91:4edb:6870:34f5-1d9f:9898:7888:7b02:1064:a19a:ccc8:4849 | | 1c1d:d54b:5bb8:fe5b:db91:4edb:6870:34f5-1d9f:9898:7888:7b02:1064:a19a:ccc8:4849 1c90:5c1b:9431:11ea:f6dd:bb7c:c57f:6cc6 | | 1c90:5c1b:9431:11ea:f6dd:bb7c:c57f:6cc6 | - | | 1c90:5c1b:9431:11ea:f6dd:bb7c:c57f:6cc6 | | 1c90:5c1b:9431:11ea:f6dd:bb7c:c57f:6cc6 | 1c1d:d54b:5bb8:fe5b:db91:4edb:6870:34f5-1d9f:9898:7888:7b02:1064:a19a:ccc8:4849 | | 1c1d:d54b:5bb8:fe5b:db91:4edb:6870:34f5-1d9f:9898:7888:7b02:1064:a19a:ccc8:4849 1cc5:18d6:116d:d727:86b:9655:f44d:4fb7 | | 1cc5:18d6:116d:d727:86b:9655:f44d:4fb7 | - | | 1cc5:18d6:116d:d727:86b:9655:f44d:4fb7 | | 1cc5:18d6:116d:d727:86b:9655:f44d:4fb7 | 1c1d:d54b:5bb8:fe5b:db91:4edb:6870:34f5-1d9f:9898:7888:7b02:1064:a19a:ccc8:4849 | | 1c1d:d54b:5bb8:fe5b:db91:4edb:6870:34f5-1d9f:9898:7888:7b02:1064:a19a:ccc8:4849 1dbf:c6d8:ce1a:e3e3:c9a2:8458:3674:f6b | | 1dbf:c6d8:ce1a:e3e3:c9a2:8458:3674:f6b | - | | 1f38:cd00:b368:80e5:7579:df75:3c50:b21b | | 1f38:cd00:b368:80e5:7579:df75:3c50:b21b | - | | 204f:510d:e7e9:9c02:9576:48b1:bfb7:468 | | 204f:510d:e7e9:9c02:9576:48b1:bfb7:468 | - | | 21ef:74a4:2571:e430:47b1:a582:9723:9b14 | | 21ef:74a4:2571:e430:47b1:a582:9723:9b14 | - | | 2394:74d2:f34d:3801:3a23:f022:dc17:2cf | | 2394:74d2:f34d:3801:3a23:f022:dc17:2cf | - | | 23fd:5d2:8e6a:628:b4e:3ff2:d386:d2b0 | | 23fd:5d2:8e6a:628:b4e:3ff2:d386:d2b0 | - | | 2408:f23d:d1ac:746d:2c8f:3dd6:7ed0:5507 | | 2408:f23d:d1ac:746d:2c8f:3dd6:7ed0:5507 | - | | 25d9:67f6:f409:c774:60ad:9d6a:b95b:4ad2 | | 25d9:67f6:f409:c774:60ad:9d6a:b95b:4ad2 | - | | 25f0:72d:e515:bc9b:f9a2:6061:b18b:758e | | 25f0:72d:e515:bc9b:f9a2:6061:b18b:758e | - | | 2689:eae5:4101:f97c:628a:58fa:f0b5:159 | | 2689:eae5:4101:f97c:628a:58fa:f0b5:159 | - | | 26a3:7ac5:3ce2:cb2d:994d:8f10:82b6:419d | | 26a3:7ac5:3ce2:cb2d:994d:8f10:82b6:419d | - | | 26ad:4d5b:192c:f85a:71db:38be:c6ca:19de | | 26ad:4d5b:192c:f85a:71db:38be:c6ca:19de | - | | 28a6:2032:8a38:de85:f6f3:47bd:5124:7dc8 | | 28a6:2032:8a38:de85:f6f3:47bd:5124:7dc8 | - | | 28a6:2032:8a38:de85:f6f3:47bd:5124:7dc8 | | 28a6:2032:8a38:de85:f6f3:47bd:5124:7dc8 | 282c:2276:9cc1:58aa:1e30:2fce:a695:c42e-28f8:52d4:b106:5e5c:b22a:6a84:e581:7934 | | 282c:2276:9cc1:58aa:1e30:2fce:a695:c42e-28f8:52d4:b106:5e5c:b22a:6a84:e581:7934 28e7:4441:e0a4:bf30:4cf4:edb0:638d:ad72 | | 28e7:4441:e0a4:bf30:4cf4:edb0:638d:ad72 | - | | 28e7:4441:e0a4:bf30:4cf4:edb0:638d:ad72 | | 28e7:4441:e0a4:bf30:4cf4:edb0:638d:ad72 | 282c:2276:9cc1:58aa:1e30:2fce:a695:c42e-28f8:52d4:b106:5e5c:b22a:6a84:e581:7934 | | 282c:2276:9cc1:58aa:1e30:2fce:a695:c42e-28f8:52d4:b106:5e5c:b22a:6a84:e581:7934 29a4:a288:457e:57a9:bbb3:2a76:b117:b1e8 | | 29a4:a288:457e:57a9:bbb3:2a76:b117:b1e8 | - | | 29b2:d3c1:26c4:86b6:19b5:14dc:ab2d:bc67 | | 29b2:d3c1:26c4:86b6:19b5:14dc:ab2d:bc67 | - | | 2a8a:5b38:cbdd:5d1c:e1b0:d627:f31f:285a | | 2a8a:5b38:cbdd:5d1c:e1b0:d627:f31f:285a | - | | 2b47:da0e:8c52:cc33:afaa:f85f:f143:88c6 | | 2b47:da0e:8c52:cc33:afaa:f85f:f143:88c6 | - | | 2b47:da0e:8c52:cc33:afaa:f85f:f143:88c6 | | 2b47:da0e:8c52:cc33:afaa:f85f:f143:88c6 | 2b09:bce8:a5eb:7add:f388:6ff3:3247:6bc4-2bce:b195:8b4d:d7a2:e6f9:6325:c4cf:dcd7 | | 2b09:bce8:a5eb:7add:f388:6ff3:3247:6bc4-2bce:b195:8b4d:d7a2:e6f9:6325:c4cf:dcd7 2ee9:6428:5482:9721:9e51:ca52:ba3:99eb | | 2ee9:6428:5482:9721:9e51:ca52:ba3:99eb | - | | 2f48:4d4b:443c:6de6:9cbe:9766:fd5:c88b | | 2f48:4d4b:443c:6de6:9cbe:9766:fd5:c88b | - | | 2ff2:b6b6:ffd1:dc5f:fc2:defe:fd16:a414 | | 2ff2:b6b6:ffd1:dc5f:fc2:defe:fd16:a414 | - | | 3138:9022:3412:4cfb:fc2a:729a:651c:40f9 | | 3138:9022:3412:4cfb:fc2a:729a:651c:40f9 | - | | 318f:1162:8f48:3397:cb9a:f54e:f1e8:d05d | | 318f:1162:8f48:3397:cb9a:f54e:f1e8:d05d | - | | 32ca:6639:c07e:c474:fa11:c83:2886:516c | | 32ca:6639:c07e:c474:fa11:c83:2886:516c | - | | 35f1:eb03:921c:f397:cd41:9201:f7e0:dfad | | 35f1:eb03:921c:f397:cd41:9201:f7e0:dfad | - | | 35f3:d696:b49e:1a25:375:5e28:15c9:96ce | | 35f3:d696:b49e:1a25:375:5e28:15c9:96ce | - | | 3902:4c48:d872:37bd:2e53:678d:3a0a:3cf6 | | 3902:4c48:d872:37bd:2e53:678d:3a0a:3cf6 | - | | 390b:b7a:6606:af43:233b:2e27:8336:5b2e | | 390b:b7a:6606:af43:233b:2e27:8336:5b2e | - | | 39ec:d6ba:1f45:64d0:f4d2:3f0f:78e:a404 | | 39ec:d6ba:1f45:64d0:f4d2:3f0f:78e:a404 | - | | 3af7:2de9:30a7:818d:9715:3eaf:d8f7:2583 | | 3af7:2de9:30a7:818d:9715:3eaf:d8f7:2583 | - | | 3b13:802b:cfd:15ef:bab3:f337:8b00:5744 | | 3b13:802b:cfd:15ef:bab3:f337:8b00:5744 | - | | 3bc9:de98:c700:5aa:d993:223e:dad:1949 | | 3bc9:de98:c700:5aa:d993:223e:dad:1949 | - | | 4068:6d06:7463:589:3262:86d1:f1f1:f088 | | 4068:6d06:7463:589:3262:86d1:f1f1:f088 | - | | 4068:6d06:7463:589:3262:86d1:f1f1:f088 | | 4068:6d06:7463:589:3262:86d1:f1f1:f088 | 403e:a65:913d:bf17:1650:f48c:967f:6cee-42a0:8ac9:38d0:b9ba:bc91:ac9:9f19:24f6 | | 403e:a65:913d:bf17:1650:f48c:967f:6cee-42a0:8ac9:38d0:b9ba:bc91:ac9:9f19:24f6 4111:e35f:ce3:c4de:dc4e:8764:8cd:1686 | | 4111:e35f:ce3:c4de:dc4e:8764:8cd:1686 | - | | 4111:e35f:ce3:c4de:dc4e:8764:8cd:1686 | | 4111:e35f:ce3:c4de:dc4e:8764:8cd:1686 | 403e:a65:913d:bf17:1650:f48c:967f:6cee-42a0:8ac9:38d0:b9ba:bc91:ac9:9f19:24f6 | | 403e:a65:913d:bf17:1650:f48c:967f:6cee-42a0:8ac9:38d0:b9ba:bc91:ac9:9f19:24f6 4131:d8b6:82af:797d:25fd:7bd4:b94d:ce34 | | 4131:d8b6:82af:797d:25fd:7bd4:b94d:ce34 | - | | 4131:d8b6:82af:797d:25fd:7bd4:b94d:ce34 | | 4131:d8b6:82af:797d:25fd:7bd4:b94d:ce34 | 403e:a65:913d:bf17:1650:f48c:967f:6cee-42a0:8ac9:38d0:b9ba:bc91:ac9:9f19:24f6 | | 403e:a65:913d:bf17:1650:f48c:967f:6cee-42a0:8ac9:38d0:b9ba:bc91:ac9:9f19:24f6 42e2:d76f:c784:7a61:67c1:b931:6f49:32c5 | | 42e2:d76f:c784:7a61:67c1:b931:6f49:32c5 | - | | 4430:8b98:82c8:3d6c:dbd6:579e:c3fc:ec9d | | 4430:8b98:82c8:3d6c:dbd6:579e:c3fc:ec9d | - | | 4439:44b6:c04:de6a:c0af:cf35:d9f3:f8ee | | 4439:44b6:c04:de6a:c0af:cf35:d9f3:f8ee | - | | 450b:493b:a4d7:f0d3:6fe4:6da0:b550:f4ca | | 450b:493b:a4d7:f0d3:6fe4:6da0:b550:f4ca | - | | 454c:20ee:35b9:b48b:a59f:e4bc:7b76:f228 | | 454c:20ee:35b9:b48b:a59f:e4bc:7b76:f228 | - | | 454e:bfa0:ed21:4983:7572:22c9:413d:d4db | | 454e:bfa0:ed21:4983:7572:22c9:413d:d4db | - | | 4620:c642:9985:6a1f:6c66:50c0:2108:10d3 | | 4620:c642:9985:6a1f:6c66:50c0:2108:10d3 | - | | 4647:353:5292:8bef:e5b5:c13a:1176:deef | | 4647:353:5292:8bef:e5b5:c13a:1176:deef | - | | 4bd6:2076:745e:acbe:c511:3786:60be:b51d | | 4bd6:2076:745e:acbe:c511:3786:60be:b51d | - | | 4d6a:edd6:a446:6d89:e2a3:ab27:79ec:e148 | | 4d6a:edd6:a446:6d89:e2a3:ab27:79ec:e148 | - | | 4ee3:bfaa:5f22:2c05:573e:e87c:a6c2:81e0 | | 4ee3:bfaa:5f22:2c05:573e:e87c:a6c2:81e0 | - | | 53ad:31ab:bc5e:c535:bc7c:5762:c11e:fcec | | 53ad:31ab:bc5e:c535:bc7c:5762:c11e:fcec | - | | 53d6:7f94:6b26:59cb:9c16:2aa:9722:b8ef | | 53d6:7f94:6b26:59cb:9c16:2aa:9722:b8ef | - | | 5412:a54d:dbd8:8448:4728:5fb0:ec6f:4381 | | 5412:a54d:dbd8:8448:4728:5fb0:ec6f:4381 | - | | 5466:93e3:8343:3686:394:778:79ac:772 | | 5466:93e3:8343:3686:394:778:79ac:772 | - | | 54b6:4a85:c1a5:89b0:b7ff:5306:32be:d30f | | 54b6:4a85:c1a5:89b0:b7ff:5306:32be:d30f | - | | 5637:5e57:c050:53fe:e182:697:ab46:21cc | | 5637:5e57:c050:53fe:e182:697:ab46:21cc | - | | 56fd:83db:3ff7:b0b:7d5:8378:a486:f20 | | 56fd:83db:3ff7:b0b:7d5:8378:a486:f20 | - | | 5721:3c79:a6ff:c8d8:5e3:c785:808:e40 | | 5721:3c79:a6ff:c8d8:5e3:c785:808:e40 | - | | 5721:3c79:a6ff:c8d8:5e3:c785:808:e40 | | 5721:3c79:a6ff:c8d8:5e3:c785:808:e40 | 570d:9354:14c4:e9c9:dc63:be77:d70a:947c-57cb:4a7a:c3c:fcd2:e130:41d9:165:df | | 570d:9354:14c4:e9c9:dc63:be77:d70a:947c-57cb:4a7a:c3c:fcd2:e130:41d9:165:df 5889:8398:cb90:8df:b3d6:3f5c:72cb:cd64 | | 5889:8398:cb90:8df:b3d6:3f5c:72cb:cd64 | - | | 599b:9e01:9a22:aebf:a731:ce57:fefb:8ed | | 599b:9e01:9a22:aebf:a731:ce57:fefb:8ed | - | | 5a0b:33a9:3407:aa9c:f1c7:a538:2f25:bf14 | | 5a0b:33a9:3407:aa9c:f1c7:a538:2f25:bf14 | - | | 5a3f:b436:785f:32a4:8c86:13f8:e682:8b6a | | 5a3f:b436:785f:32a4:8c86:13f8:e682:8b6a | - | | 5d63:9613:7b87:5c26:5c80:bbd3:14b5:1e63 | | 5d63:9613:7b87:5c26:5c80:bbd3:14b5:1e63 | - | | 5d63:9613:7b87:5c26:5c80:bbd3:14b5:1e63 | | 5d63:9613:7b87:5c26:5c80:bbd3:14b5:1e63 | 5d63:3959:e781:2931:84ab:7fd7:2f85:8101-5d6c:d5a2:e9c3:9ab4:4aab:7f0a:9c18:8dca | | 5d63:3959:e781:2931:84ab:7fd7:2f85:8101-5d6c:d5a2:e9c3:9ab4:4aab:7f0a:9c18:8dca 5e52:9aa9:8f83:2a67:5959:720d:f6ba:5d42 | | 5e52:9aa9:8f83:2a67:5959:720d:f6ba:5d42 | - | | 5ee2:4fab:1073:b2f5:61c1:eea6:302f:685 | | 5ee2:4fab:1073:b2f5:61c1:eea6:302f:685 | - | | 5fa8:25bb:15e8:5b35:758c:2044:d194:1962 | | 5fa8:25bb:15e8:5b35:758c:2044:d194:1962 | - | | 61f2:afe0:d1af:18e9:5d40:7a4d:f112:2d09 | | 61f2:afe0:d1af:18e9:5d40:7a4d:f112:2d09 | - | | 6251:ab4b:3b37:d71f:6b5f:1b2d:bd55:3a3c | | 6251:ab4b:3b37:d71f:6b5f:1b2d:bd55:3a3c | - | | 62b8:256d:637a:82bf:3b69:420:eea5:300b | | 62b8:256d:637a:82bf:3b69:420:eea5:300b | - | | 62db:eab9:a54e:3cea:46f3:b7c2:cb9c:6e5d | | 62db:eab9:a54e:3cea:46f3:b7c2:cb9c:6e5d | - | | 6656:e87d:865c:3237:8d42:ff01:a82b:f308 | | 6656:e87d:865c:3237:8d42:ff01:a82b:f308 | - | | 6a93:ccd3:5002:233f:1c5f:400e:601c:75a | | 6a93:ccd3:5002:233f:1c5f:400e:601c:75a | - | | 6b0c:4791:ccea:c286:437e:d268:87ef:b6ad | | 6b0c:4791:ccea:c286:437e:d268:87ef:b6ad | - | | 6e1b:5e9c:f623:6134:7754:fdac:323a:dba2 | | 6e1b:5e9c:f623:6134:7754:fdac:323a:dba2 | - | | 6e81:4a6a:d383:140d:8416:c09b:af3b:5b45 | | 6e81:4a6a:d383:140d:8416:c09b:af3b:5b45 | - | | 6e9d:66e:27c5:c7c4:aefe:ecfc:6568:ccf | | 6e9d:66e:27c5:c7c4:aefe:ecfc:6568:ccf | - | | 6ff2:94f5:5755:164d:1301:28ce:8a04:eac0 | | 6ff2:94f5:5755:164d:1301:28ce:8a04:eac0 | - | | 72c4:104f:960c:baf1:8ef7:60d2:c58:8b03 | | 72c4:104f:960c:baf1:8ef7:60d2:c58:8b03 | - | | 7341:d21f:e576:f226:f690:a99c:6b55:9933 | | 7341:d21f:e576:f226:f690:a99c:6b55:9933 | - | | 739b:8093:31c6:a42f:a604:d5cb:1350:2d2f | | 739b:8093:31c6:a42f:a604:d5cb:1350:2d2f | - | | 7524:1f76:fe52:991e:667b:a302:dfd5:dbd6 | | 7524:1f76:fe52:991e:667b:a302:dfd5:dbd6 | - | | 7524:1f76:fe52:991e:667b:a302:dfd5:dbd6 | | 7524:1f76:fe52:991e:667b:a302:dfd5:dbd6 | 742e:1d26:42a5:cc7c:4ffd:726f:19e0:61f7-76b8:303d:bb7:c766:cf35:f22e:c86f:1400 | | 742e:1d26:42a5:cc7c:4ffd:726f:19e0:61f7-76b8:303d:bb7:c766:cf35:f22e:c86f:1400 7608:50bf:a29a:6805:c760:9ae3:1216:8e4a | | 7608:50bf:a29a:6805:c760:9ae3:1216:8e4a | - | | 7608:50bf:a29a:6805:c760:9ae3:1216:8e4a | | 7608:50bf:a29a:6805:c760:9ae3:1216:8e4a | 742e:1d26:42a5:cc7c:4ffd:726f:19e0:61f7-76b8:303d:bb7:c766:cf35:f22e:c86f:1400 | | 742e:1d26:42a5:cc7c:4ffd:726f:19e0:61f7-76b8:303d:bb7:c766:cf35:f22e:c86f:1400 78c8:1cde:4b95:55d8:b211:a95d:37e0:7d92 | | 78c8:1cde:4b95:55d8:b211:a95d:37e0:7d92 | - | | 7924:9e5b:2c7:3920:9c9f:bfb6:369d:fa4f | | 7924:9e5b:2c7:3920:9c9f:bfb6:369d:fa4f | - | | 798f:ea8:61f6:5d79:1656:d8d8:9b6e:57f0 | | 798f:ea8:61f6:5d79:1656:d8d8:9b6e:57f0 | - | | 79c9:d301:92cd:c774:abbb:2f7d:92c3:3ccd | | 79c9:d301:92cd:c774:abbb:2f7d:92c3:3ccd | - | | 79eb:6133:5173:8f43:87d4:cb1d:906b:e8c9 | | 79eb:6133:5173:8f43:87d4:cb1d:906b:e8c9 | - | | 7cba:a835:f850:6409:dba7:1300:f2b8:1db3 | | 7cba:a835:f850:6409:dba7:1300:f2b8:1db3 | - | | 7cdf:1ed8:690e:9e54:6f39:613e:f187:8ef2 | | 7cdf:1ed8:690e:9e54:6f39:613e:f187:8ef2 | - | | 7dcc:877b:8e07:aeb4:d891:581e:c10c:af54 | | 7dcc:877b:8e07:aeb4:d891:581e:c10c:af54 | - | | 7e1f:eb76:49c9:39f8:deb9:c447:b40c:a13d | | 7e1f:eb76:49c9:39f8:deb9:c447:b40c:a13d | - | | 7ec8:2b00:5994:7f0f:d765:5e16:c274:5645 | | 7ec8:2b00:5994:7f0f:d765:5e16:c274:5645 | - | | 7f3d:d8ea:7a7c:8700:5b81:412f:c33a:d6ba | | 7f3d:d8ea:7a7c:8700:5b81:412f:c33a:d6ba | - | | 7fa2:dbdb:e889:e24b:4d30:962e:89f3:676f | | 7fa2:dbdb:e889:e24b:4d30:962e:89f3:676f | - | | 8119:1220:b888:3d8a:1250:ce77:b2b9:bdcd | | 8119:1220:b888:3d8a:1250:ce77:b2b9:bdcd | - | | 8129:3e9c:70ff:1df1:f26f:86aa:c7ba:8245 | | 8129:3e9c:70ff:1df1:f26f:86aa:c7ba:8245 | - | | 8172:4609:d700:5bd2:24a2:8f78:f1cc:c1a0 | | 8172:4609:d700:5bd2:24a2:8f78:f1cc:c1a0 | - | | 8241:abe3:7537:de41:ef5a:7d2a:9e57:833b | | 8241:abe3:7537:de41:ef5a:7d2a:9e57:833b | - | | 828e:fa1d:9bb1:ad4c:4874:9da8:40bf:25b5 | | 828e:fa1d:9bb1:ad4c:4874:9da8:40bf:25b5 | - | | 828e:fa1d:9bb1:ad4c:4874:9da8:40bf:25b5 | | 828e:fa1d:9bb1:ad4c:4874:9da8:40bf:25b5 | 8261:c35e:8e93:a1d1:4000:42a9:b632:112c-82f4:6c3e:dff3:6472:7292:3bbc:abd7:1e73 | | 8261:c35e:8e93:a1d1:4000:42a9:b632:112c-82f4:6c3e:dff3:6472:7292:3bbc:abd7:1e73 8298:9399:271f:a3fe:270c:21cf:7c34:7340 | | 8298:9399:271f:a3fe:270c:21cf:7c34:7340 | - | | 8298:9399:271f:a3fe:270c:21cf:7c34:7340 | | 8298:9399:271f:a3fe:270c:21cf:7c34:7340 | 8261:c35e:8e93:a1d1:4000:42a9:b632:112c-82f4:6c3e:dff3:6472:7292:3bbc:abd7:1e73 | | 8261:c35e:8e93:a1d1:4000:42a9:b632:112c-82f4:6c3e:dff3:6472:7292:3bbc:abd7:1e73 82ed:ac69:4ea7:5301:b005:3e17:f541:4fbc | | 82ed:ac69:4ea7:5301:b005:3e17:f541:4fbc | - | | 82ed:ac69:4ea7:5301:b005:3e17:f541:4fbc | | 82ed:ac69:4ea7:5301:b005:3e17:f541:4fbc | 8261:c35e:8e93:a1d1:4000:42a9:b632:112c-82f4:6c3e:dff3:6472:7292:3bbc:abd7:1e73 | | 8261:c35e:8e93:a1d1:4000:42a9:b632:112c-82f4:6c3e:dff3:6472:7292:3bbc:abd7:1e73 8357:a24:2f6e:f909:3853:899a:68af:b48 | | 8357:a24:2f6e:f909:3853:899a:68af:b48 | - | | 8474:e00a:5b49:6e2a:5074:ecd5:cece:7dad | | 8474:e00a:5b49:6e2a:5074:ecd5:cece:7dad | - | | 84fe:7351:7b39:349e:1bb7:e333:daec:141a | | 84fe:7351:7b39:349e:1bb7:e333:daec:141a | - | | 8586:595:7bdd:359b:2fd9:1ffa:49ef:a947 | | 8586:595:7bdd:359b:2fd9:1ffa:49ef:a947 | - | | 86fa:3a3:6a26:5ce3:fd8d:6267:b3c:4bf0 | | 86fa:3a3:6a26:5ce3:fd8d:6267:b3c:4bf0 | - | | 86fa:3a3:6a26:5ce3:fd8d:6267:b3c:4bf0 | | 86fa:3a3:6a26:5ce3:fd8d:6267:b3c:4bf0 | 8664:644c:adba:dc68:650:c853:c8b1:ee7e-8d83:a669:a387:5f8a:c300:f46a:aa19:2422 | | 8664:644c:adba:dc68:650:c853:c8b1:ee7e-8d83:a669:a387:5f8a:c300:f46a:aa19:2422 874b:a74e:e292:c13:cf80:778c:35b4:d37c | | 874b:a74e:e292:c13:cf80:778c:35b4:d37c | - | | 874b:a74e:e292:c13:cf80:778c:35b4:d37c | | 874b:a74e:e292:c13:cf80:778c:35b4:d37c | 8664:644c:adba:dc68:650:c853:c8b1:ee7e-8d83:a669:a387:5f8a:c300:f46a:aa19:2422 | | 8664:644c:adba:dc68:650:c853:c8b1:ee7e-8d83:a669:a387:5f8a:c300:f46a:aa19:2422 88bb:cf40:1f19:c897:f001:2d56:8f4f:ac68 | | 88bb:cf40:1f19:c897:f001:2d56:8f4f:ac68 | - | | 88bb:cf40:1f19:c897:f001:2d56:8f4f:ac68 | | 88bb:cf40:1f19:c897:f001:2d56:8f4f:ac68 | 8664:644c:adba:dc68:650:c853:c8b1:ee7e-8d83:a669:a387:5f8a:c300:f46a:aa19:2422 | | 8664:644c:adba:dc68:650:c853:c8b1:ee7e-8d83:a669:a387:5f8a:c300:f46a:aa19:2422 8909:5e3:cff9:483c:1fb7:2ee2:ab05:222a | | 8909:5e3:cff9:483c:1fb7:2ee2:ab05:222a | - | | 8909:5e3:cff9:483c:1fb7:2ee2:ab05:222a | | 8909:5e3:cff9:483c:1fb7:2ee2:ab05:222a | 8664:644c:adba:dc68:650:c853:c8b1:ee7e-8d83:a669:a387:5f8a:c300:f46a:aa19:2422 | | 8664:644c:adba:dc68:650:c853:c8b1:ee7e-8d83:a669:a387:5f8a:c300:f46a:aa19:2422 890b:aa44:e2b1:ff61:eb7a:c4df:5a25:2eaf | | 890b:aa44:e2b1:ff61:eb7a:c4df:5a25:2eaf | - | | 890b:aa44:e2b1:ff61:eb7a:c4df:5a25:2eaf | | 890b:aa44:e2b1:ff61:eb7a:c4df:5a25:2eaf | 8664:644c:adba:dc68:650:c853:c8b1:ee7e-8d83:a669:a387:5f8a:c300:f46a:aa19:2422 | | 8664:644c:adba:dc68:650:c853:c8b1:ee7e-8d83:a669:a387:5f8a:c300:f46a:aa19:2422 8a1f:674e:63cd:f241:8f53:aec9:d8db:8e5c | | 8a1f:674e:63cd:f241:8f53:aec9:d8db:8e5c | - | | 8a1f:674e:63cd:f241:8f53:aec9:d8db:8e5c | | 8a1f:674e:63cd:f241:8f53:aec9:d8db:8e5c | 8664:644c:adba:dc68:650:c853:c8b1:ee7e-8d83:a669:a387:5f8a:c300:f46a:aa19:2422 | | 8664:644c:adba:dc68:650:c853:c8b1:ee7e-8d83:a669:a387:5f8a:c300:f46a:aa19:2422 8b0c:b103:3302:90bb:bac:809e:9c7d:3569 | | 8b0c:b103:3302:90bb:bac:809e:9c7d:3569 | - | | 8b0c:b103:3302:90bb:bac:809e:9c7d:3569 | | 8b0c:b103:3302:90bb:bac:809e:9c7d:3569 | 8664:644c:adba:dc68:650:c853:c8b1:ee7e-8d83:a669:a387:5f8a:c300:f46a:aa19:2422 | | 8664:644c:adba:dc68:650:c853:c8b1:ee7e-8d83:a669:a387:5f8a:c300:f46a:aa19:2422 8b61:6b31:d02c:87d3:22cf:f01c:c045:b822 | | 8b61:6b31:d02c:87d3:22cf:f01c:c045:b822 | - | | 8b61:6b31:d02c:87d3:22cf:f01c:c045:b822 | | 8b61:6b31:d02c:87d3:22cf:f01c:c045:b822 | 8664:644c:adba:dc68:650:c853:c8b1:ee7e-8d83:a669:a387:5f8a:c300:f46a:aa19:2422 | | 8664:644c:adba:dc68:650:c853:c8b1:ee7e-8d83:a669:a387:5f8a:c300:f46a:aa19:2422 8b87:864a:8e83:6783:c552:cb07:8e96:c0e5 | | 8b87:864a:8e83:6783:c552:cb07:8e96:c0e5 | - | | 8b87:864a:8e83:6783:c552:cb07:8e96:c0e5 | | 8b87:864a:8e83:6783:c552:cb07:8e96:c0e5 | 8664:644c:adba:dc68:650:c853:c8b1:ee7e-8d83:a669:a387:5f8a:c300:f46a:aa19:2422 | | 8664:644c:adba:dc68:650:c853:c8b1:ee7e-8d83:a669:a387:5f8a:c300:f46a:aa19:2422 8c86:2c19:c38d:626b:b5a4:e0cb:bbaf:476b | | 8c86:2c19:c38d:626b:b5a4:e0cb:bbaf:476b | - | | 8c86:2c19:c38d:626b:b5a4:e0cb:bbaf:476b | | 8c86:2c19:c38d:626b:b5a4:e0cb:bbaf:476b | 8664:644c:adba:dc68:650:c853:c8b1:ee7e-8d83:a669:a387:5f8a:c300:f46a:aa19:2422 | | 8664:644c:adba:dc68:650:c853:c8b1:ee7e-8d83:a669:a387:5f8a:c300:f46a:aa19:2422 8ec2:3493:ad95:cb7e:ae1c:8c2c:6a34:eccb | | 8ec2:3493:ad95:cb7e:ae1c:8c2c:6a34:eccb | - | | 8ecc:14db:7aba:bbde:f2a7:c4bc:7a1e:c8c1 | | 8ecc:14db:7aba:bbde:f2a7:c4bc:7a1e:c8c1 | - | | 8f7a:5e8b:f526:a8ba:8c6f:3cae:7b7e:1a5 | | 8f7a:5e8b:f526:a8ba:8c6f:3cae:7b7e:1a5 | - | | 8fa1:e604:6ad4:c318:ba8f:eaec:76be:ad4b | | 8fa1:e604:6ad4:c318:ba8f:eaec:76be:ad4b | - | | 8fac:3b7e:463d:1b38:2f59:6fdf:3bef:4aaf | | 8fac:3b7e:463d:1b38:2f59:6fdf:3bef:4aaf | - | | 933f:d5b:d307:c3e0:5e0:b947:1cb5:6928 | | 933f:d5b:d307:c3e0:5e0:b947:1cb5:6928 | - | | 9520:88f9:9498:8a73:ac7a:dc77:4495:3dfc | | 9520:88f9:9498:8a73:ac7a:dc77:4495:3dfc | - | | 9631:3557:7591:6ade:1882:6dad:8413:c3b3 | | 9631:3557:7591:6ade:1882:6dad:8413:c3b3 | - | | 977b:de6f:3ef9:3cad:fb02:fb07:458c:e88e | | 977b:de6f:3ef9:3cad:fb02:fb07:458c:e88e | - | | 982a:e6d8:49bc:49a7:80b:4417:45f7:4fb7 | | 982a:e6d8:49bc:49a7:80b:4417:45f7:4fb7 | - | | 9943:4095:cf6c:bf1d:f1b4:7883:f929:a315 | | 9943:4095:cf6c:bf1d:f1b4:7883:f929:a315 | - | | 99b7:bba0:206c:6042:6778:2f3b:9a:6393 | | 99b7:bba0:206c:6042:6778:2f3b:9a:6393 | - | | 9b3d:56d7:b18e:21b9:7448:3cea:2ec:77f8 | | 9b3d:56d7:b18e:21b9:7448:3cea:2ec:77f8 | - | | 9c51:8c1b:a051:a87e:c65a:cc8:a38e:4953 | | 9c51:8c1b:a051:a87e:c65a:cc8:a38e:4953 | - | | 9d35:9c4f:517d:2391:f59c:af03:1681:6d9b | | 9d35:9c4f:517d:2391:f59c:af03:1681:6d9b | - | | 9da1:e3ce:660a:cde4:7576:554:55cc:38ad | | 9da1:e3ce:660a:cde4:7576:554:55cc:38ad | - | | 9ee9:65bd:81d2:b2c6:c3c4:b36b:16a2:fc9e | | 9ee9:65bd:81d2:b2c6:c3c4:b36b:16a2:fc9e | - | | a0d3:f0b5:7a50:2d3e:923e:3832:76c0:b15d | | a0d3:f0b5:7a50:2d3e:923e:3832:76c0:b15d | - | | a252:248:a123:3287:680f:a67c:2fcd:b2a0 | | a252:248:a123:3287:680f:a67c:2fcd:b2a0 | - | | a300:d184:bf44:e8f1:4a80:723c:909:f178 | | a300:d184:bf44:e8f1:4a80:723c:909:f178 | - | | a335:f1a7:be5c:b341:5325:e8d3:2631:74ae | | a335:f1a7:be5c:b341:5325:e8d3:2631:74ae | - | | a335:f1a7:be5c:b341:5325:e8d3:2631:74ae | | a335:f1a7:be5c:b341:5325:e8d3:2631:74ae | a306:48c9:17c3:be92:bc17:3993:65e5:6855-a346:5383:4104:e53d:72b3:7e11:4d32:d696 | | a306:48c9:17c3:be92:bc17:3993:65e5:6855-a346:5383:4104:e53d:72b3:7e11:4d32:d696 a42d:662e:1816:1fe3:a392:9190:7d4e:f418 | | a42d:662e:1816:1fe3:a392:9190:7d4e:f418 | - | | a52f:f73a:413e:a43a:5000:cd8f:ef1f:3603 | | a52f:f73a:413e:a43a:5000:cd8f:ef1f:3603 | - | | a75b:c708:8e74:b252:f8e8:7269:c214:dc07 | | a75b:c708:8e74:b252:f8e8:7269:c214:dc07 | - | | a87b:8920:6e0:9c1b:92a8:3a1e:f074:1ee2 | | a87b:8920:6e0:9c1b:92a8:3a1e:f074:1ee2 | - | | a87b:8920:6e0:9c1b:92a8:3a1e:f074:1ee2 | | a87b:8920:6e0:9c1b:92a8:3a1e:f074:1ee2 | a798:ae68:f434:630e:121d:acf7:c1dd:ccf8-a94a:2e2c:77c1:f913:6d64:fc:7eb6:2507 | | a798:ae68:f434:630e:121d:acf7:c1dd:ccf8-a94a:2e2c:77c1:f913:6d64:fc:7eb6:2507 a884:9796:ca7c:ec37:9cb4:4158:ce4c:ced5 | | a884:9796:ca7c:ec37:9cb4:4158:ce4c:ced5 | - | | a884:9796:ca7c:ec37:9cb4:4158:ce4c:ced5 | | a884:9796:ca7c:ec37:9cb4:4158:ce4c:ced5 | a798:ae68:f434:630e:121d:acf7:c1dd:ccf8-a94a:2e2c:77c1:f913:6d64:fc:7eb6:2507 | | a798:ae68:f434:630e:121d:acf7:c1dd:ccf8-a94a:2e2c:77c1:f913:6d64:fc:7eb6:2507 a9e9:74a5:864a:dfeb:a5f0:4424:d294:95a1 | | a9e9:74a5:864a:dfeb:a5f0:4424:d294:95a1 | - | | a9e9:74a5:864a:dfeb:a5f0:4424:d294:95a1 | | a9e9:74a5:864a:dfeb:a5f0:4424:d294:95a1 | a993:6021:2abb:60c4:63fc:8e04:7b20:cbb4-ac46:82d9:f719:584:7006:227:6076:a331 | | a993:6021:2abb:60c4:63fc:8e04:7b20:cbb4-ac46:82d9:f719:584:7006:227:6076:a331 ac4c:23a6:9c5f:8a2a:ccfc:ea69:48cd:dffc | | ac4c:23a6:9c5f:8a2a:ccfc:ea69:48cd:dffc | - | | ac71:fd2c:4352:c28a:2f4b:3cd1:4d6f:927b | | ac71:fd2c:4352:c28a:2f4b:3cd1:4d6f:927b | - | | ad73:992f:b3d8:31f7:306d:a418:fdcf:3e60 | | ad73:992f:b3d8:31f7:306d:a418:fdcf:3e60 | - | | ae64:d6a3:11d7:b6bc:aa3:60c6:b16f:4305 | | ae64:d6a3:11d7:b6bc:aa3:60c6:b16f:4305 | - | | af5a:6507:2c50:f0a8:b211:fc0d:425e:bd47 | | af5a:6507:2c50:f0a8:b211:fc0d:425e:bd47 | - | | afeb:a771:735e:1a18:9297:e9f4:2e53:c5e1 | | afeb:a771:735e:1a18:9297:e9f4:2e53:c5e1 | - | | b105:5518:a963:9a0a:d10d:b42b:dfd1:96a2 | | b105:5518:a963:9a0a:d10d:b42b:dfd1:96a2 | - | | b113:66f:e222:f032:7161:1f27:b080:2111 | | b113:66f:e222:f032:7161:1f27:b080:2111 | - | | b218:c6f2:4929:7d70:8b4d:5458:fc85:d0fc | | b218:c6f2:4929:7d70:8b4d:5458:fc85:d0fc | - | | b237:dac3:62d7:725e:d772:c88c:af71:cec5 | | b237:dac3:62d7:725e:d772:c88c:af71:cec5 | - | | b310:3d72:ea86:6ee:45fc:d57f:4a7a:bb43 | | b310:3d72:ea86:6ee:45fc:d57f:4a7a:bb43 | - | | b3da:187b:cc2e:3c78:e060:aab6:63cb:1780 | | b3da:187b:cc2e:3c78:e060:aab6:63cb:1780 | - | | b408:9874:22a3:9f56:35f:cfd1:b00:ddac | | b408:9874:22a3:9f56:35f:cfd1:b00:ddac | - | | b48c:eccb:32f4:2b4:e2ee:e787:a16f:8647 | | b48c:eccb:32f4:2b4:e2ee:e787:a16f:8647 | - | | b8ef:17e2:febe:431d:9d8c:88c6:6604:a678 | | b8ef:17e2:febe:431d:9d8c:88c6:6604:a678 | - | | ba0d:d2d4:b5e3:573f:98f4:98e:aac1:47fa | | ba0d:d2d4:b5e3:573f:98f4:98e:aac1:47fa | - | | baf9:2948:a8a1:8865:912a:839f:45e8:78d3 | | baf9:2948:a8a1:8865:912a:839f:45e8:78d3 | - | | bb1b:6a20:8513:14e4:5fc6:c0e9:17df:9c0 | | bb1b:6a20:8513:14e4:5fc6:c0e9:17df:9c0 | - | | bc1d:d3ba:50da:14d3:f496:6847:3b91:2830 | | bc1d:d3ba:50da:14d3:f496:6847:3b91:2830 | - | | bc52:8171:9377:d593:1c0a:75e4:e2d:5e1a | | bc52:8171:9377:d593:1c0a:75e4:e2d:5e1a | - | | bd6f:44b9:45d3:529f:84c7:612:b25c:aaf8 | | bd6f:44b9:45d3:529f:84c7:612:b25c:aaf8 | - | | bd6f:44b9:45d3:529f:84c7:612:b25c:aaf8 | | bd6f:44b9:45d3:529f:84c7:612:b25c:aaf8 | bd2a:be6d:190:4507:74a2:e822:1268:d65b-bdd8:dc9a:1e65:6d42:1548:579b:2494:ad37 | | bd2a:be6d:190:4507:74a2:e822:1268:d65b-bdd8:dc9a:1e65:6d42:1548:579b:2494:ad37 bdc5:94f5:8249:7120:8132:ca25:d3fc:c394 | | bdc5:94f5:8249:7120:8132:ca25:d3fc:c394 | - | | bdc5:94f5:8249:7120:8132:ca25:d3fc:c394 | | bdc5:94f5:8249:7120:8132:ca25:d3fc:c394 | bd2a:be6d:190:4507:74a2:e822:1268:d65b-bdd8:dc9a:1e65:6d42:1548:579b:2494:ad37 | | bd2a:be6d:190:4507:74a2:e822:1268:d65b-bdd8:dc9a:1e65:6d42:1548:579b:2494:ad37 c0fc:f3ee:3707:19dc:62c1:5c9a:df3d:1b58 | | c0fc:f3ee:3707:19dc:62c1:5c9a:df3d:1b58 | - | | c0fc:f3ee:3707:19dc:62c1:5c9a:df3d:1b58 | | c0fc:f3ee:3707:19dc:62c1:5c9a:df3d:1b58 | c09a:e3ed:e52c:439b:84ae:dd00:96a1:d7f3-cebe:ab0d:21cd:f20:e2d6:1bbb:319a:55b8 | | c09a:e3ed:e52c:439b:84ae:dd00:96a1:d7f3-cebe:ab0d:21cd:f20:e2d6:1bbb:319a:55b8 c2e3:4cea:30dd:cb39:c5a0:86e7:8b05:3f7 | | c2e3:4cea:30dd:cb39:c5a0:86e7:8b05:3f7 | - | | c2e3:4cea:30dd:cb39:c5a0:86e7:8b05:3f7 | | c2e3:4cea:30dd:cb39:c5a0:86e7:8b05:3f7 | c09a:e3ed:e52c:439b:84ae:dd00:96a1:d7f3-cebe:ab0d:21cd:f20:e2d6:1bbb:319a:55b8 | | c09a:e3ed:e52c:439b:84ae:dd00:96a1:d7f3-cebe:ab0d:21cd:f20:e2d6:1bbb:319a:55b8 c36f:f4fd:4853:a07c:c25d:349f:3af4:3432 | | c36f:f4fd:4853:a07c:c25d:349f:3af4:3432 | - | | c36f:f4fd:4853:a07c:c25d:349f:3af4:3432 | | c36f:f4fd:4853:a07c:c25d:349f:3af4:3432 | c09a:e3ed:e52c:439b:84ae:dd00:96a1:d7f3-cebe:ab0d:21cd:f20:e2d6:1bbb:319a:55b8 | | c09a:e3ed:e52c:439b:84ae:dd00:96a1:d7f3-cebe:ab0d:21cd:f20:e2d6:1bbb:319a:55b8 c504:481e:2756:3ca2:f0c:a26a:4e64:7804 | | c504:481e:2756:3ca2:f0c:a26a:4e64:7804 | - | | c504:481e:2756:3ca2:f0c:a26a:4e64:7804 | | c504:481e:2756:3ca2:f0c:a26a:4e64:7804 | c09a:e3ed:e52c:439b:84ae:dd00:96a1:d7f3-cebe:ab0d:21cd:f20:e2d6:1bbb:319a:55b8 | | c09a:e3ed:e52c:439b:84ae:dd00:96a1:d7f3-cebe:ab0d:21cd:f20:e2d6:1bbb:319a:55b8 c504:481e:2756:3ca2:f0c:a26a:4e64:7804 | | c504:481e:2756:3ca2:f0c:a26a:4e64:7804 | c406:cc08:31e:a2ac:e9c0:e1a6:d216:8597-c9d1:f946:9f2b:487:86a1:a082:b31:c9e8 | | c406:cc08:31e:a2ac:e9c0:e1a6:d216:8597-c9d1:f946:9f2b:487:86a1:a082:b31:c9e8 c6ff:8d3c:d2d1:ee46:65ca:27f9:cc07:8e6d | | c6ff:8d3c:d2d1:ee46:65ca:27f9:cc07:8e6d | - | | c6ff:8d3c:d2d1:ee46:65ca:27f9:cc07:8e6d | | c6ff:8d3c:d2d1:ee46:65ca:27f9:cc07:8e6d | c09a:e3ed:e52c:439b:84ae:dd00:96a1:d7f3-cebe:ab0d:21cd:f20:e2d6:1bbb:319a:55b8 | | c09a:e3ed:e52c:439b:84ae:dd00:96a1:d7f3-cebe:ab0d:21cd:f20:e2d6:1bbb:319a:55b8 c6ff:8d3c:d2d1:ee46:65ca:27f9:cc07:8e6d | | c6ff:8d3c:d2d1:ee46:65ca:27f9:cc07:8e6d | c406:cc08:31e:a2ac:e9c0:e1a6:d216:8597-c9d1:f946:9f2b:487:86a1:a082:b31:c9e8 | | c406:cc08:31e:a2ac:e9c0:e1a6:d216:8597-c9d1:f946:9f2b:487:86a1:a082:b31:c9e8 c8c0:5117:331a:f029:8d24:6775:fe7d:5976 | | c8c0:5117:331a:f029:8d24:6775:fe7d:5976 | - | | c8c0:5117:331a:f029:8d24:6775:fe7d:5976 | | c8c0:5117:331a:f029:8d24:6775:fe7d:5976 | c09a:e3ed:e52c:439b:84ae:dd00:96a1:d7f3-cebe:ab0d:21cd:f20:e2d6:1bbb:319a:55b8 | | c09a:e3ed:e52c:439b:84ae:dd00:96a1:d7f3-cebe:ab0d:21cd:f20:e2d6:1bbb:319a:55b8 c8c0:5117:331a:f029:8d24:6775:fe7d:5976 | | c8c0:5117:331a:f029:8d24:6775:fe7d:5976 | c406:cc08:31e:a2ac:e9c0:e1a6:d216:8597-c9d1:f946:9f2b:487:86a1:a082:b31:c9e8 | | c406:cc08:31e:a2ac:e9c0:e1a6:d216:8597-c9d1:f946:9f2b:487:86a1:a082:b31:c9e8 c963:10d0:1586:d1d4:79bc:d7af:5486:43e5 | | c963:10d0:1586:d1d4:79bc:d7af:5486:43e5 | - | | c963:10d0:1586:d1d4:79bc:d7af:5486:43e5 | | c963:10d0:1586:d1d4:79bc:d7af:5486:43e5 | c09a:e3ed:e52c:439b:84ae:dd00:96a1:d7f3-cebe:ab0d:21cd:f20:e2d6:1bbb:319a:55b8 | | c09a:e3ed:e52c:439b:84ae:dd00:96a1:d7f3-cebe:ab0d:21cd:f20:e2d6:1bbb:319a:55b8 c963:10d0:1586:d1d4:79bc:d7af:5486:43e5 | | c963:10d0:1586:d1d4:79bc:d7af:5486:43e5 | c406:cc08:31e:a2ac:e9c0:e1a6:d216:8597-c9d1:f946:9f2b:487:86a1:a082:b31:c9e8 | | c406:cc08:31e:a2ac:e9c0:e1a6:d216:8597-c9d1:f946:9f2b:487:86a1:a082:b31:c9e8 c99c:bd43:6161:d17d:2fdd:ab61:922:ba62 | | c99c:bd43:6161:d17d:2fdd:ab61:922:ba62 | - | | c99c:bd43:6161:d17d:2fdd:ab61:922:ba62 | | c99c:bd43:6161:d17d:2fdd:ab61:922:ba62 | c09a:e3ed:e52c:439b:84ae:dd00:96a1:d7f3-cebe:ab0d:21cd:f20:e2d6:1bbb:319a:55b8 | | c09a:e3ed:e52c:439b:84ae:dd00:96a1:d7f3-cebe:ab0d:21cd:f20:e2d6:1bbb:319a:55b8 c99c:bd43:6161:d17d:2fdd:ab61:922:ba62 | | c99c:bd43:6161:d17d:2fdd:ab61:922:ba62 | c406:cc08:31e:a2ac:e9c0:e1a6:d216:8597-c9d1:f946:9f2b:487:86a1:a082:b31:c9e8 | | c406:cc08:31e:a2ac:e9c0:e1a6:d216:8597-c9d1:f946:9f2b:487:86a1:a082:b31:c9e8 cb2f:b8da:ba34:1c5c:4839:710a:f75b:bdd0 | | cb2f:b8da:ba34:1c5c:4839:710a:f75b:bdd0 | - | | cb2f:b8da:ba34:1c5c:4839:710a:f75b:bdd0 | | cb2f:b8da:ba34:1c5c:4839:710a:f75b:bdd0 | c09a:e3ed:e52c:439b:84ae:dd00:96a1:d7f3-cebe:ab0d:21cd:f20:e2d6:1bbb:319a:55b8 | | c09a:e3ed:e52c:439b:84ae:dd00:96a1:d7f3-cebe:ab0d:21cd:f20:e2d6:1bbb:319a:55b8 cb70:a0cc:6919:db7f:8fc8:cb69:6fcc:5f5b | | cb70:a0cc:6919:db7f:8fc8:cb69:6fcc:5f5b | - | | cb70:a0cc:6919:db7f:8fc8:cb69:6fcc:5f5b | | cb70:a0cc:6919:db7f:8fc8:cb69:6fcc:5f5b | c09a:e3ed:e52c:439b:84ae:dd00:96a1:d7f3-cebe:ab0d:21cd:f20:e2d6:1bbb:319a:55b8 | | c09a:e3ed:e52c:439b:84ae:dd00:96a1:d7f3-cebe:ab0d:21cd:f20:e2d6:1bbb:319a:55b8 cc17:3814:d80f:41a1:1309:35d3:ea0a:d31e | | cc17:3814:d80f:41a1:1309:35d3:ea0a:d31e | - | | cc17:3814:d80f:41a1:1309:35d3:ea0a:d31e | | cc17:3814:d80f:41a1:1309:35d3:ea0a:d31e | c09a:e3ed:e52c:439b:84ae:dd00:96a1:d7f3-cebe:ab0d:21cd:f20:e2d6:1bbb:319a:55b8 | | c09a:e3ed:e52c:439b:84ae:dd00:96a1:d7f3-cebe:ab0d:21cd:f20:e2d6:1bbb:319a:55b8 ce47:e5eb:41f3:23af:6209:5ade:82ce:3b00 | | ce47:e5eb:41f3:23af:6209:5ade:82ce:3b00 | - | | ce47:e5eb:41f3:23af:6209:5ade:82ce:3b00 | | ce47:e5eb:41f3:23af:6209:5ade:82ce:3b00 | c09a:e3ed:e52c:439b:84ae:dd00:96a1:d7f3-cebe:ab0d:21cd:f20:e2d6:1bbb:319a:55b8 | | c09a:e3ed:e52c:439b:84ae:dd00:96a1:d7f3-cebe:ab0d:21cd:f20:e2d6:1bbb:319a:55b8 cfb9:d37e:2427:af8d:b728:8f90:f54c:9141 | | cfb9:d37e:2427:af8d:b728:8f90:f54c:9141 | - | | d066:f25b:e8a5:4ae6:4c99:2a98:8cb7:2530 | | d066:f25b:e8a5:4ae6:4c99:2a98:8cb7:2530 | - | | d066:f25b:e8a5:4ae6:4c99:2a98:8cb7:2530 | | d066:f25b:e8a5:4ae6:4c99:2a98:8cb7:2530 | d05d:6ab5:422e:c783:15fc:6439:918c:f8bd-d091:8c1c:5e1d:903c:50fc:dded:2e4a:bf02 | | d05d:6ab5:422e:c783:15fc:6439:918c:f8bd-d091:8c1c:5e1d:903c:50fc:dded:2e4a:bf02 d105:1597:c912:51c7:e5b6:f628:cae:1d0f | | d105:1597:c912:51c7:e5b6:f628:cae:1d0f | - | | d2de:7aa1:975:e510:dfa1:2a3:89bc:eedb | | d2de:7aa1:975:e510:dfa1:2a3:89bc:eedb | - | | d33e:e847:b4c6:d5ca:f75:216b:342c:3d04 | | d33e:e847:b4c6:d5ca:f75:216b:342c:3d04 | - | | d395:c008:43a4:48d9:15a7:ce74:6546:c56b | | d395:c008:43a4:48d9:15a7:ce74:6546:c56b | - | | d452:6fb9:f2b0:d387:80ca:47d5:330f:577 | | d452:6fb9:f2b0:d387:80ca:47d5:330f:577 | - | | d524:77db:2a21:e05b:68c4:575c:f04b:b0b7 | | d524:77db:2a21:e05b:68c4:575c:f04b:b0b7 | - | | d6d1:e96c:cd2f:8396:23f2:c96d:9376:54cb | | d6d1:e96c:cd2f:8396:23f2:c96d:9376:54cb | - | | d76b:986d:d38b:252a:e6a2:254e:b0f7:db24 | | d76b:986d:d38b:252a:e6a2:254e:b0f7:db24 | - | | d9f3:2018:6aa2:7ee4:64be:e2d:c32c:2d15 | | d9f3:2018:6aa2:7ee4:64be:e2d:c32c:2d15 | - | | d9f3:2018:6aa2:7ee4:64be:e2d:c32c:2d15 | | d9f3:2018:6aa2:7ee4:64be:e2d:c32c:2d15 | d98e:be37:92ff:fcc7:2c26:4d2d:b393:95cb-d9fe:570d:e24e:1d2b:403:6c50:eb8d:fc3 | | d98e:be37:92ff:fcc7:2c26:4d2d:b393:95cb-d9fe:570d:e24e:1d2b:403:6c50:eb8d:fc3 da3e:c57c:ccc8:edbf:f66e:85a5:e252:a3a4 | | da3e:c57c:ccc8:edbf:f66e:85a5:e252:a3a4 | - | | da52:3791:27b8:f773:7a59:1414:6d76:bd8a | | da52:3791:27b8:f773:7a59:1414:6d76:bd8a | - | | da97:ecc5:bf17:1bb2:5710:f753:604c:7cf6 | | da97:ecc5:bf17:1bb2:5710:f753:604c:7cf6 | - | | dc61:8bf4:4b82:90a4:8af0:6a43:a917:14ee | | dc61:8bf4:4b82:90a4:8af0:6a43:a917:14ee | - | | dd3b:ad95:1e55:a555:daae:8218:99d7:7bce | | dd3b:ad95:1e55:a555:daae:8218:99d7:7bce | - | | defd:c729:62b4:8959:6ad1:7b1f:5835:8ffb | | defd:c729:62b4:8959:6ad1:7b1f:5835:8ffb | - | | dfe2:c097:49ae:1d60:e3db:26c1:bb5d:c4e0 | | dfe2:c097:49ae:1d60:e3db:26c1:bb5d:c4e0 | - | | e11c:4f21:dd57:c814:af4e:3f55:4adf:f1a0 | | e11c:4f21:dd57:c814:af4e:3f55:4adf:f1a0 | - | | e11c:4f21:dd57:c814:af4e:3f55:4adf:f1a0 | | e11c:4f21:dd57:c814:af4e:3f55:4adf:f1a0 | e104:d364:b55e:bf80:97f3:cf03:61ed:c6ef-e1b7:f280:7b4a:2a4:2e0e:c372:f0ab:158 | | e104:d364:b55e:bf80:97f3:cf03:61ed:c6ef-e1b7:f280:7b4a:2a4:2e0e:c372:f0ab:158 e199:2ea0:f3b4:3a31:5d15:dfc9:68cd:c948 | | e199:2ea0:f3b4:3a31:5d15:dfc9:68cd:c948 | - | | e199:2ea0:f3b4:3a31:5d15:dfc9:68cd:c948 | | e199:2ea0:f3b4:3a31:5d15:dfc9:68cd:c948 | e104:d364:b55e:bf80:97f3:cf03:61ed:c6ef-e1b7:f280:7b4a:2a4:2e0e:c372:f0ab:158 | | e104:d364:b55e:bf80:97f3:cf03:61ed:c6ef-e1b7:f280:7b4a:2a4:2e0e:c372:f0ab:158 e57b:76e8:3f3a:3020:a22a:38b7:9c02:5db4 | | e57b:76e8:3f3a:3020:a22a:38b7:9c02:5db4 | - | | e6da:dc3c:a935:a718:4744:a216:84bd:cfa9 | | e6da:dc3c:a935:a718:4744:a216:84bd:cfa9 | - | | e7a7:adbe:d6de:41ba:a34f:d10b:46a7:a4cf | | e7a7:adbe:d6de:41ba:a34f:d10b:46a7:a4cf | - | | e86d:edb4:8702:1774:c97d:cbee:394:a083 | | e86d:edb4:8702:1774:c97d:cbee:394:a083 | - | | e97f:c466:f346:cf67:23e4:bd36:72be:af44 | | e97f:c466:f346:cf67:23e4:bd36:72be:af44 | - | | ec36:7c6d:3077:267e:399a:d47:55a4:218a | | ec36:7c6d:3077:267e:399a:d47:55a4:218a | - | | ee1d:a078:25d4:94e3:9a89:707d:6fae:7573 | | ee1d:a078:25d4:94e3:9a89:707d:6fae:7573 | - | | ee34:9ba:9281:593c:ab74:57fa:e439:e0f3 | | ee34:9ba:9281:593c:ab74:57fa:e439:e0f3 | - | | ee76:e9ac:dd2:66c1:380:5f1e:1c4d:2867 | | ee76:e9ac:dd2:66c1:380:5f1e:1c4d:2867 | - | | eea0:9aef:71b:3cfd:e2ad:864c:41b8:938c | | eea0:9aef:71b:3cfd:e2ad:864c:41b8:938c | - | | ef15:3aa9:3c5b:b993:5209:a130:2d37:3a64 | | ef15:3aa9:3c5b:b993:5209:a130:2d37:3a64 | - | | ef9a:b980:e9:d50a:d867:8a88:2cae:8aa1 | | ef9a:b980:e9:d50a:d867:8a88:2cae:8aa1 | - | | effb:1a90:1dd5:e52c:1d7f:c716:3744:170a | | effb:1a90:1dd5:e52c:1d7f:c716:3744:170a | - | | f0a1:e730:68b9:2e1c:649a:5450:a256:4665 | | f0a1:e730:68b9:2e1c:649a:5450:a256:4665 | - | | f3df:f155:d5c6:d664:c93c:13fa:9d77:6bf2 | | f3df:f155:d5c6:d664:c93c:13fa:9d77:6bf2 | - | | f499:668f:fbb8:f0dc:8e41:d43b:c025:26a | | f499:668f:fbb8:f0dc:8e41:d43b:c025:26a | - | | f57a:a3dc:3b11:f28a:8b25:8d5b:ec2f:c729 | | f57a:a3dc:3b11:f28a:8b25:8d5b:ec2f:c729 | - | | f7b8:dfc:496c:9718:ae3c:5c3e:b98a:4c5f | | f7b8:dfc:496c:9718:ae3c:5c3e:b98a:4c5f | - | | fa78:68ce:4fb1:d54c:2007:1820:ffe2:8235 | | fa78:68ce:4fb1:d54c:2007:1820:ffe2:8235 | - | | fbb6:2d70:42eb:55ab:6235:6867:2b3:8d47 | | fbb6:2d70:42eb:55ab:6235:6867:2b3:8d47 | - | | fcea:f739:a97d:cefc:49c4:b3c3:c7b4:99d6 | | fcea:f739:a97d:cefc:49c4:b3c3:c7b4:99d6 | - | | fda3:3e75:37c5:c1f:912b:5e32:6aa9:aeb2 | | fda3:3e75:37c5:c1f:912b:5e32:6aa9:aeb2 | - | | ff3d:7d5b:b0fe:c30:9e6c:23e0:7b5:e9de | | ff3d:7d5b:b0fe:c30:9e6c:23e0:7b5:e9de | - | | ff4a:cbbf:695a:9e46:f27c:e1be:861f:9e7 | | ff4a:cbbf:695a:9e46:f27c:e1be:861f:9e7 | - | | ff6b:af36:5fc2:93d9:ebf3:3c62:a19f:307f | | ff6b:af36:5fc2:93d9:ebf3:3c62:a19f:307f | - | | (351 rows) select * from ipaddrs a join ipranges r on (r.r4 >>= a.a4) order by a4,r4; a | a4 | a6 | r | r4 | r6 -----------------+-----------------+----+--------------------------------+--------------------------------+---- 12.174.29.15 | 12.174.29.15 | | 9.228.56.34-28.197.214.173 | 9.228.56.34-28.197.214.173 | 33.8.16.211 | 33.8.16.211 | | 32.219.217.193-34.140.113.120 | 32.219.217.193-34.140.113.120 | 73.239.169.71 | 73.239.169.71 | | 65.76.62.93-75.189.2.219 | 65.76.62.93-75.189.2.219 | 73.239.169.71 | 73.239.169.71 | | 70.178.141.1-79.252.178.95 | 70.178.141.1-79.252.178.95 | 76.178.38.194 | 76.178.38.194 | | 70.178.141.1-79.252.178.95 | 70.178.141.1-79.252.178.95 | 76.178.38.194 | 76.178.38.194 | | 75.211.173.58-77.84.189.178 | 75.211.173.58-77.84.189.178 | 76.178.38.194 | 76.178.38.194 | | 76.164.111.154-76.183.66.114 | 76.164.111.154-76.183.66.114 | 104.175.11.72 | 104.175.11.72 | | 104.76.127.225-105.198.184.62 | 104.76.127.225-105.198.184.62 | 163.145.90.183 | 163.145.90.183 | | 155.206.49.182-190.20.159.162 | 155.206.49.182-190.20.159.162 | 189.85.58.60 | 189.85.58.60 | | 155.206.49.182-190.20.159.162 | 155.206.49.182-190.20.159.162 | 189.85.58.60 | 189.85.58.60 | | 184.142.247.0-191.129.204.149 | 184.142.247.0-191.129.204.149 | 195.58.214.186 | 195.58.214.186 | | 192.198.196.94-195.116.202.186 | 192.198.196.94-195.116.202.186 | 195.58.214.186 | 195.58.214.186 | | 194.50.23.161-195.215.1.54 | 194.50.23.161-195.215.1.54 | 223.213.219.214 | 223.213.219.214 | | 207.129.8.36-240.135.140.181 | 207.129.8.36-240.135.140.181 | 235.64.97.205 | 235.64.97.205 | | 207.129.8.36-240.135.140.181 | 207.129.8.36-240.135.140.181 | 235.64.97.205 | 235.64.97.205 | | 233.169.207.115-238.213.223.60 | 233.169.207.115-238.213.223.60 | 235.64.97.205 | 235.64.97.205 | | 234.48.112.251-235.130.33.88 | 234.48.112.251-235.130.33.88 | 240.116.30.226 | 240.116.30.226 | | 207.129.8.36-240.135.140.181 | 207.129.8.36-240.135.140.181 | 255.226.130.53 | 255.226.130.53 | | 255.148.94.59-255.232.142.189 | 255.148.94.59-255.232.142.189 | (19 rows) select * from ipaddrs a join ipranges r on (r.r6 >>= a.a6) order by a6,r6; a | a4 | a6 | r | r4 | r6 -----------------------------------------+----+-----------------------------------------+---------------------------------------------------------------------------------+----+--------------------------------------------------------------------------------- 73:3c34:57a:2a84:b1df:81b0:eb40:61cd | | 73:3c34:57a:2a84:b1df:81b0:eb40:61cd | 6d:d4d7:e3dc:b30c:d0f3:6ae3:907e:beb2-a4:f5d3:b64e:8e01:5f11:d5c3:be0b:e20c | | 6d:d4d7:e3dc:b30c:d0f3:6ae3:907e:beb2-a4:f5d3:b64e:8e01:5f11:d5c3:be0b:e20c 227:b768:d43b:773d:6168:5133:867c:13f2 | | 227:b768:d43b:773d:6168:5133:867c:13f2 | 176:6781:47c:8022:8ab8:8b64:a8ce:da2c-863:40d1:76b:fbce:b89e:221f:ddb0:7679 | | 176:6781:47c:8022:8ab8:8b64:a8ce:da2c-863:40d1:76b:fbce:b89e:221f:ddb0:7679 453:2d:fbd3:191:95c6:3751:eb62:e90 | | 453:2d:fbd3:191:95c6:3751:eb62:e90 | 176:6781:47c:8022:8ab8:8b64:a8ce:da2c-863:40d1:76b:fbce:b89e:221f:ddb0:7679 | | 176:6781:47c:8022:8ab8:8b64:a8ce:da2c-863:40d1:76b:fbce:b89e:221f:ddb0:7679 4a6:7a28:b05b:f9b4:cc5b:9c4c:eefe:3e06 | | 4a6:7a28:b05b:f9b4:cc5b:9c4c:eefe:3e06 | 176:6781:47c:8022:8ab8:8b64:a8ce:da2c-863:40d1:76b:fbce:b89e:221f:ddb0:7679 | | 176:6781:47c:8022:8ab8:8b64:a8ce:da2c-863:40d1:76b:fbce:b89e:221f:ddb0:7679 550:fe90:bd02:a3ed:35a2:3254:e280:cd20 | | 550:fe90:bd02:a3ed:35a2:3254:e280:cd20 | 176:6781:47c:8022:8ab8:8b64:a8ce:da2c-863:40d1:76b:fbce:b89e:221f:ddb0:7679 | | 176:6781:47c:8022:8ab8:8b64:a8ce:da2c-863:40d1:76b:fbce:b89e:221f:ddb0:7679 75d:e701:5702:6087:a69a:1a2d:376e:4eb | | 75d:e701:5702:6087:a69a:1a2d:376e:4eb | 176:6781:47c:8022:8ab8:8b64:a8ce:da2c-863:40d1:76b:fbce:b89e:221f:ddb0:7679 | | 176:6781:47c:8022:8ab8:8b64:a8ce:da2c-863:40d1:76b:fbce:b89e:221f:ddb0:7679 7e1:a608:dadd:684d:679e:698b:4db:c8c2 | | 7e1:a608:dadd:684d:679e:698b:4db:c8c2 | 176:6781:47c:8022:8ab8:8b64:a8ce:da2c-863:40d1:76b:fbce:b89e:221f:ddb0:7679 | | 176:6781:47c:8022:8ab8:8b64:a8ce:da2c-863:40d1:76b:fbce:b89e:221f:ddb0:7679 1c3e:17b6:1bfd:77ea:2185:9748:38d:ac80 | | 1c3e:17b6:1bfd:77ea:2185:9748:38d:ac80 | 1c1d:d54b:5bb8:fe5b:db91:4edb:6870:34f5-1d9f:9898:7888:7b02:1064:a19a:ccc8:4849 | | 1c1d:d54b:5bb8:fe5b:db91:4edb:6870:34f5-1d9f:9898:7888:7b02:1064:a19a:ccc8:4849 1c90:5c1b:9431:11ea:f6dd:bb7c:c57f:6cc6 | | 1c90:5c1b:9431:11ea:f6dd:bb7c:c57f:6cc6 | 1c1d:d54b:5bb8:fe5b:db91:4edb:6870:34f5-1d9f:9898:7888:7b02:1064:a19a:ccc8:4849 | | 1c1d:d54b:5bb8:fe5b:db91:4edb:6870:34f5-1d9f:9898:7888:7b02:1064:a19a:ccc8:4849 1cc5:18d6:116d:d727:86b:9655:f44d:4fb7 | | 1cc5:18d6:116d:d727:86b:9655:f44d:4fb7 | 1c1d:d54b:5bb8:fe5b:db91:4edb:6870:34f5-1d9f:9898:7888:7b02:1064:a19a:ccc8:4849 | | 1c1d:d54b:5bb8:fe5b:db91:4edb:6870:34f5-1d9f:9898:7888:7b02:1064:a19a:ccc8:4849 28a6:2032:8a38:de85:f6f3:47bd:5124:7dc8 | | 28a6:2032:8a38:de85:f6f3:47bd:5124:7dc8 | 282c:2276:9cc1:58aa:1e30:2fce:a695:c42e-28f8:52d4:b106:5e5c:b22a:6a84:e581:7934 | | 282c:2276:9cc1:58aa:1e30:2fce:a695:c42e-28f8:52d4:b106:5e5c:b22a:6a84:e581:7934 28e7:4441:e0a4:bf30:4cf4:edb0:638d:ad72 | | 28e7:4441:e0a4:bf30:4cf4:edb0:638d:ad72 | 282c:2276:9cc1:58aa:1e30:2fce:a695:c42e-28f8:52d4:b106:5e5c:b22a:6a84:e581:7934 | | 282c:2276:9cc1:58aa:1e30:2fce:a695:c42e-28f8:52d4:b106:5e5c:b22a:6a84:e581:7934 2b47:da0e:8c52:cc33:afaa:f85f:f143:88c6 | | 2b47:da0e:8c52:cc33:afaa:f85f:f143:88c6 | 2b09:bce8:a5eb:7add:f388:6ff3:3247:6bc4-2bce:b195:8b4d:d7a2:e6f9:6325:c4cf:dcd7 | | 2b09:bce8:a5eb:7add:f388:6ff3:3247:6bc4-2bce:b195:8b4d:d7a2:e6f9:6325:c4cf:dcd7 4068:6d06:7463:589:3262:86d1:f1f1:f088 | | 4068:6d06:7463:589:3262:86d1:f1f1:f088 | 403e:a65:913d:bf17:1650:f48c:967f:6cee-42a0:8ac9:38d0:b9ba:bc91:ac9:9f19:24f6 | | 403e:a65:913d:bf17:1650:f48c:967f:6cee-42a0:8ac9:38d0:b9ba:bc91:ac9:9f19:24f6 4111:e35f:ce3:c4de:dc4e:8764:8cd:1686 | | 4111:e35f:ce3:c4de:dc4e:8764:8cd:1686 | 403e:a65:913d:bf17:1650:f48c:967f:6cee-42a0:8ac9:38d0:b9ba:bc91:ac9:9f19:24f6 | | 403e:a65:913d:bf17:1650:f48c:967f:6cee-42a0:8ac9:38d0:b9ba:bc91:ac9:9f19:24f6 4131:d8b6:82af:797d:25fd:7bd4:b94d:ce34 | | 4131:d8b6:82af:797d:25fd:7bd4:b94d:ce34 | 403e:a65:913d:bf17:1650:f48c:967f:6cee-42a0:8ac9:38d0:b9ba:bc91:ac9:9f19:24f6 | | 403e:a65:913d:bf17:1650:f48c:967f:6cee-42a0:8ac9:38d0:b9ba:bc91:ac9:9f19:24f6 5721:3c79:a6ff:c8d8:5e3:c785:808:e40 | | 5721:3c79:a6ff:c8d8:5e3:c785:808:e40 | 570d:9354:14c4:e9c9:dc63:be77:d70a:947c-57cb:4a7a:c3c:fcd2:e130:41d9:165:df | | 570d:9354:14c4:e9c9:dc63:be77:d70a:947c-57cb:4a7a:c3c:fcd2:e130:41d9:165:df 5d63:9613:7b87:5c26:5c80:bbd3:14b5:1e63 | | 5d63:9613:7b87:5c26:5c80:bbd3:14b5:1e63 | 5d63:3959:e781:2931:84ab:7fd7:2f85:8101-5d6c:d5a2:e9c3:9ab4:4aab:7f0a:9c18:8dca | | 5d63:3959:e781:2931:84ab:7fd7:2f85:8101-5d6c:d5a2:e9c3:9ab4:4aab:7f0a:9c18:8dca 7524:1f76:fe52:991e:667b:a302:dfd5:dbd6 | | 7524:1f76:fe52:991e:667b:a302:dfd5:dbd6 | 742e:1d26:42a5:cc7c:4ffd:726f:19e0:61f7-76b8:303d:bb7:c766:cf35:f22e:c86f:1400 | | 742e:1d26:42a5:cc7c:4ffd:726f:19e0:61f7-76b8:303d:bb7:c766:cf35:f22e:c86f:1400 7608:50bf:a29a:6805:c760:9ae3:1216:8e4a | | 7608:50bf:a29a:6805:c760:9ae3:1216:8e4a | 742e:1d26:42a5:cc7c:4ffd:726f:19e0:61f7-76b8:303d:bb7:c766:cf35:f22e:c86f:1400 | | 742e:1d26:42a5:cc7c:4ffd:726f:19e0:61f7-76b8:303d:bb7:c766:cf35:f22e:c86f:1400 828e:fa1d:9bb1:ad4c:4874:9da8:40bf:25b5 | | 828e:fa1d:9bb1:ad4c:4874:9da8:40bf:25b5 | 8261:c35e:8e93:a1d1:4000:42a9:b632:112c-82f4:6c3e:dff3:6472:7292:3bbc:abd7:1e73 | | 8261:c35e:8e93:a1d1:4000:42a9:b632:112c-82f4:6c3e:dff3:6472:7292:3bbc:abd7:1e73 8298:9399:271f:a3fe:270c:21cf:7c34:7340 | | 8298:9399:271f:a3fe:270c:21cf:7c34:7340 | 8261:c35e:8e93:a1d1:4000:42a9:b632:112c-82f4:6c3e:dff3:6472:7292:3bbc:abd7:1e73 | | 8261:c35e:8e93:a1d1:4000:42a9:b632:112c-82f4:6c3e:dff3:6472:7292:3bbc:abd7:1e73 82ed:ac69:4ea7:5301:b005:3e17:f541:4fbc | | 82ed:ac69:4ea7:5301:b005:3e17:f541:4fbc | 8261:c35e:8e93:a1d1:4000:42a9:b632:112c-82f4:6c3e:dff3:6472:7292:3bbc:abd7:1e73 | | 8261:c35e:8e93:a1d1:4000:42a9:b632:112c-82f4:6c3e:dff3:6472:7292:3bbc:abd7:1e73 86fa:3a3:6a26:5ce3:fd8d:6267:b3c:4bf0 | | 86fa:3a3:6a26:5ce3:fd8d:6267:b3c:4bf0 | 8664:644c:adba:dc68:650:c853:c8b1:ee7e-8d83:a669:a387:5f8a:c300:f46a:aa19:2422 | | 8664:644c:adba:dc68:650:c853:c8b1:ee7e-8d83:a669:a387:5f8a:c300:f46a:aa19:2422 874b:a74e:e292:c13:cf80:778c:35b4:d37c | | 874b:a74e:e292:c13:cf80:778c:35b4:d37c | 8664:644c:adba:dc68:650:c853:c8b1:ee7e-8d83:a669:a387:5f8a:c300:f46a:aa19:2422 | | 8664:644c:adba:dc68:650:c853:c8b1:ee7e-8d83:a669:a387:5f8a:c300:f46a:aa19:2422 88bb:cf40:1f19:c897:f001:2d56:8f4f:ac68 | | 88bb:cf40:1f19:c897:f001:2d56:8f4f:ac68 | 8664:644c:adba:dc68:650:c853:c8b1:ee7e-8d83:a669:a387:5f8a:c300:f46a:aa19:2422 | | 8664:644c:adba:dc68:650:c853:c8b1:ee7e-8d83:a669:a387:5f8a:c300:f46a:aa19:2422 8909:5e3:cff9:483c:1fb7:2ee2:ab05:222a | | 8909:5e3:cff9:483c:1fb7:2ee2:ab05:222a | 8664:644c:adba:dc68:650:c853:c8b1:ee7e-8d83:a669:a387:5f8a:c300:f46a:aa19:2422 | | 8664:644c:adba:dc68:650:c853:c8b1:ee7e-8d83:a669:a387:5f8a:c300:f46a:aa19:2422 890b:aa44:e2b1:ff61:eb7a:c4df:5a25:2eaf | | 890b:aa44:e2b1:ff61:eb7a:c4df:5a25:2eaf | 8664:644c:adba:dc68:650:c853:c8b1:ee7e-8d83:a669:a387:5f8a:c300:f46a:aa19:2422 | | 8664:644c:adba:dc68:650:c853:c8b1:ee7e-8d83:a669:a387:5f8a:c300:f46a:aa19:2422 8a1f:674e:63cd:f241:8f53:aec9:d8db:8e5c | | 8a1f:674e:63cd:f241:8f53:aec9:d8db:8e5c | 8664:644c:adba:dc68:650:c853:c8b1:ee7e-8d83:a669:a387:5f8a:c300:f46a:aa19:2422 | | 8664:644c:adba:dc68:650:c853:c8b1:ee7e-8d83:a669:a387:5f8a:c300:f46a:aa19:2422 8b0c:b103:3302:90bb:bac:809e:9c7d:3569 | | 8b0c:b103:3302:90bb:bac:809e:9c7d:3569 | 8664:644c:adba:dc68:650:c853:c8b1:ee7e-8d83:a669:a387:5f8a:c300:f46a:aa19:2422 | | 8664:644c:adba:dc68:650:c853:c8b1:ee7e-8d83:a669:a387:5f8a:c300:f46a:aa19:2422 8b61:6b31:d02c:87d3:22cf:f01c:c045:b822 | | 8b61:6b31:d02c:87d3:22cf:f01c:c045:b822 | 8664:644c:adba:dc68:650:c853:c8b1:ee7e-8d83:a669:a387:5f8a:c300:f46a:aa19:2422 | | 8664:644c:adba:dc68:650:c853:c8b1:ee7e-8d83:a669:a387:5f8a:c300:f46a:aa19:2422 8b87:864a:8e83:6783:c552:cb07:8e96:c0e5 | | 8b87:864a:8e83:6783:c552:cb07:8e96:c0e5 | 8664:644c:adba:dc68:650:c853:c8b1:ee7e-8d83:a669:a387:5f8a:c300:f46a:aa19:2422 | | 8664:644c:adba:dc68:650:c853:c8b1:ee7e-8d83:a669:a387:5f8a:c300:f46a:aa19:2422 8c86:2c19:c38d:626b:b5a4:e0cb:bbaf:476b | | 8c86:2c19:c38d:626b:b5a4:e0cb:bbaf:476b | 8664:644c:adba:dc68:650:c853:c8b1:ee7e-8d83:a669:a387:5f8a:c300:f46a:aa19:2422 | | 8664:644c:adba:dc68:650:c853:c8b1:ee7e-8d83:a669:a387:5f8a:c300:f46a:aa19:2422 a335:f1a7:be5c:b341:5325:e8d3:2631:74ae | | a335:f1a7:be5c:b341:5325:e8d3:2631:74ae | a306:48c9:17c3:be92:bc17:3993:65e5:6855-a346:5383:4104:e53d:72b3:7e11:4d32:d696 | | a306:48c9:17c3:be92:bc17:3993:65e5:6855-a346:5383:4104:e53d:72b3:7e11:4d32:d696 a87b:8920:6e0:9c1b:92a8:3a1e:f074:1ee2 | | a87b:8920:6e0:9c1b:92a8:3a1e:f074:1ee2 | a798:ae68:f434:630e:121d:acf7:c1dd:ccf8-a94a:2e2c:77c1:f913:6d64:fc:7eb6:2507 | | a798:ae68:f434:630e:121d:acf7:c1dd:ccf8-a94a:2e2c:77c1:f913:6d64:fc:7eb6:2507 a884:9796:ca7c:ec37:9cb4:4158:ce4c:ced5 | | a884:9796:ca7c:ec37:9cb4:4158:ce4c:ced5 | a798:ae68:f434:630e:121d:acf7:c1dd:ccf8-a94a:2e2c:77c1:f913:6d64:fc:7eb6:2507 | | a798:ae68:f434:630e:121d:acf7:c1dd:ccf8-a94a:2e2c:77c1:f913:6d64:fc:7eb6:2507 a9e9:74a5:864a:dfeb:a5f0:4424:d294:95a1 | | a9e9:74a5:864a:dfeb:a5f0:4424:d294:95a1 | a993:6021:2abb:60c4:63fc:8e04:7b20:cbb4-ac46:82d9:f719:584:7006:227:6076:a331 | | a993:6021:2abb:60c4:63fc:8e04:7b20:cbb4-ac46:82d9:f719:584:7006:227:6076:a331 bd6f:44b9:45d3:529f:84c7:612:b25c:aaf8 | | bd6f:44b9:45d3:529f:84c7:612:b25c:aaf8 | bd2a:be6d:190:4507:74a2:e822:1268:d65b-bdd8:dc9a:1e65:6d42:1548:579b:2494:ad37 | | bd2a:be6d:190:4507:74a2:e822:1268:d65b-bdd8:dc9a:1e65:6d42:1548:579b:2494:ad37 bdc5:94f5:8249:7120:8132:ca25:d3fc:c394 | | bdc5:94f5:8249:7120:8132:ca25:d3fc:c394 | bd2a:be6d:190:4507:74a2:e822:1268:d65b-bdd8:dc9a:1e65:6d42:1548:579b:2494:ad37 | | bd2a:be6d:190:4507:74a2:e822:1268:d65b-bdd8:dc9a:1e65:6d42:1548:579b:2494:ad37 c0fc:f3ee:3707:19dc:62c1:5c9a:df3d:1b58 | | c0fc:f3ee:3707:19dc:62c1:5c9a:df3d:1b58 | c09a:e3ed:e52c:439b:84ae:dd00:96a1:d7f3-cebe:ab0d:21cd:f20:e2d6:1bbb:319a:55b8 | | c09a:e3ed:e52c:439b:84ae:dd00:96a1:d7f3-cebe:ab0d:21cd:f20:e2d6:1bbb:319a:55b8 c2e3:4cea:30dd:cb39:c5a0:86e7:8b05:3f7 | | c2e3:4cea:30dd:cb39:c5a0:86e7:8b05:3f7 | c09a:e3ed:e52c:439b:84ae:dd00:96a1:d7f3-cebe:ab0d:21cd:f20:e2d6:1bbb:319a:55b8 | | c09a:e3ed:e52c:439b:84ae:dd00:96a1:d7f3-cebe:ab0d:21cd:f20:e2d6:1bbb:319a:55b8 c36f:f4fd:4853:a07c:c25d:349f:3af4:3432 | | c36f:f4fd:4853:a07c:c25d:349f:3af4:3432 | c09a:e3ed:e52c:439b:84ae:dd00:96a1:d7f3-cebe:ab0d:21cd:f20:e2d6:1bbb:319a:55b8 | | c09a:e3ed:e52c:439b:84ae:dd00:96a1:d7f3-cebe:ab0d:21cd:f20:e2d6:1bbb:319a:55b8 c504:481e:2756:3ca2:f0c:a26a:4e64:7804 | | c504:481e:2756:3ca2:f0c:a26a:4e64:7804 | c09a:e3ed:e52c:439b:84ae:dd00:96a1:d7f3-cebe:ab0d:21cd:f20:e2d6:1bbb:319a:55b8 | | c09a:e3ed:e52c:439b:84ae:dd00:96a1:d7f3-cebe:ab0d:21cd:f20:e2d6:1bbb:319a:55b8 c504:481e:2756:3ca2:f0c:a26a:4e64:7804 | | c504:481e:2756:3ca2:f0c:a26a:4e64:7804 | c406:cc08:31e:a2ac:e9c0:e1a6:d216:8597-c9d1:f946:9f2b:487:86a1:a082:b31:c9e8 | | c406:cc08:31e:a2ac:e9c0:e1a6:d216:8597-c9d1:f946:9f2b:487:86a1:a082:b31:c9e8 c6ff:8d3c:d2d1:ee46:65ca:27f9:cc07:8e6d | | c6ff:8d3c:d2d1:ee46:65ca:27f9:cc07:8e6d | c09a:e3ed:e52c:439b:84ae:dd00:96a1:d7f3-cebe:ab0d:21cd:f20:e2d6:1bbb:319a:55b8 | | c09a:e3ed:e52c:439b:84ae:dd00:96a1:d7f3-cebe:ab0d:21cd:f20:e2d6:1bbb:319a:55b8 c6ff:8d3c:d2d1:ee46:65ca:27f9:cc07:8e6d | | c6ff:8d3c:d2d1:ee46:65ca:27f9:cc07:8e6d | c406:cc08:31e:a2ac:e9c0:e1a6:d216:8597-c9d1:f946:9f2b:487:86a1:a082:b31:c9e8 | | c406:cc08:31e:a2ac:e9c0:e1a6:d216:8597-c9d1:f946:9f2b:487:86a1:a082:b31:c9e8 c8c0:5117:331a:f029:8d24:6775:fe7d:5976 | | c8c0:5117:331a:f029:8d24:6775:fe7d:5976 | c09a:e3ed:e52c:439b:84ae:dd00:96a1:d7f3-cebe:ab0d:21cd:f20:e2d6:1bbb:319a:55b8 | | c09a:e3ed:e52c:439b:84ae:dd00:96a1:d7f3-cebe:ab0d:21cd:f20:e2d6:1bbb:319a:55b8 c8c0:5117:331a:f029:8d24:6775:fe7d:5976 | | c8c0:5117:331a:f029:8d24:6775:fe7d:5976 | c406:cc08:31e:a2ac:e9c0:e1a6:d216:8597-c9d1:f946:9f2b:487:86a1:a082:b31:c9e8 | | c406:cc08:31e:a2ac:e9c0:e1a6:d216:8597-c9d1:f946:9f2b:487:86a1:a082:b31:c9e8 c963:10d0:1586:d1d4:79bc:d7af:5486:43e5 | | c963:10d0:1586:d1d4:79bc:d7af:5486:43e5 | c09a:e3ed:e52c:439b:84ae:dd00:96a1:d7f3-cebe:ab0d:21cd:f20:e2d6:1bbb:319a:55b8 | | c09a:e3ed:e52c:439b:84ae:dd00:96a1:d7f3-cebe:ab0d:21cd:f20:e2d6:1bbb:319a:55b8 c963:10d0:1586:d1d4:79bc:d7af:5486:43e5 | | c963:10d0:1586:d1d4:79bc:d7af:5486:43e5 | c406:cc08:31e:a2ac:e9c0:e1a6:d216:8597-c9d1:f946:9f2b:487:86a1:a082:b31:c9e8 | | c406:cc08:31e:a2ac:e9c0:e1a6:d216:8597-c9d1:f946:9f2b:487:86a1:a082:b31:c9e8 c99c:bd43:6161:d17d:2fdd:ab61:922:ba62 | | c99c:bd43:6161:d17d:2fdd:ab61:922:ba62 | c09a:e3ed:e52c:439b:84ae:dd00:96a1:d7f3-cebe:ab0d:21cd:f20:e2d6:1bbb:319a:55b8 | | c09a:e3ed:e52c:439b:84ae:dd00:96a1:d7f3-cebe:ab0d:21cd:f20:e2d6:1bbb:319a:55b8 c99c:bd43:6161:d17d:2fdd:ab61:922:ba62 | | c99c:bd43:6161:d17d:2fdd:ab61:922:ba62 | c406:cc08:31e:a2ac:e9c0:e1a6:d216:8597-c9d1:f946:9f2b:487:86a1:a082:b31:c9e8 | | c406:cc08:31e:a2ac:e9c0:e1a6:d216:8597-c9d1:f946:9f2b:487:86a1:a082:b31:c9e8 cb2f:b8da:ba34:1c5c:4839:710a:f75b:bdd0 | | cb2f:b8da:ba34:1c5c:4839:710a:f75b:bdd0 | c09a:e3ed:e52c:439b:84ae:dd00:96a1:d7f3-cebe:ab0d:21cd:f20:e2d6:1bbb:319a:55b8 | | c09a:e3ed:e52c:439b:84ae:dd00:96a1:d7f3-cebe:ab0d:21cd:f20:e2d6:1bbb:319a:55b8 cb70:a0cc:6919:db7f:8fc8:cb69:6fcc:5f5b | | cb70:a0cc:6919:db7f:8fc8:cb69:6fcc:5f5b | c09a:e3ed:e52c:439b:84ae:dd00:96a1:d7f3-cebe:ab0d:21cd:f20:e2d6:1bbb:319a:55b8 | | c09a:e3ed:e52c:439b:84ae:dd00:96a1:d7f3-cebe:ab0d:21cd:f20:e2d6:1bbb:319a:55b8 cc17:3814:d80f:41a1:1309:35d3:ea0a:d31e | | cc17:3814:d80f:41a1:1309:35d3:ea0a:d31e | c09a:e3ed:e52c:439b:84ae:dd00:96a1:d7f3-cebe:ab0d:21cd:f20:e2d6:1bbb:319a:55b8 | | c09a:e3ed:e52c:439b:84ae:dd00:96a1:d7f3-cebe:ab0d:21cd:f20:e2d6:1bbb:319a:55b8 ce47:e5eb:41f3:23af:6209:5ade:82ce:3b00 | | ce47:e5eb:41f3:23af:6209:5ade:82ce:3b00 | c09a:e3ed:e52c:439b:84ae:dd00:96a1:d7f3-cebe:ab0d:21cd:f20:e2d6:1bbb:319a:55b8 | | c09a:e3ed:e52c:439b:84ae:dd00:96a1:d7f3-cebe:ab0d:21cd:f20:e2d6:1bbb:319a:55b8 d066:f25b:e8a5:4ae6:4c99:2a98:8cb7:2530 | | d066:f25b:e8a5:4ae6:4c99:2a98:8cb7:2530 | d05d:6ab5:422e:c783:15fc:6439:918c:f8bd-d091:8c1c:5e1d:903c:50fc:dded:2e4a:bf02 | | d05d:6ab5:422e:c783:15fc:6439:918c:f8bd-d091:8c1c:5e1d:903c:50fc:dded:2e4a:bf02 d9f3:2018:6aa2:7ee4:64be:e2d:c32c:2d15 | | d9f3:2018:6aa2:7ee4:64be:e2d:c32c:2d15 | d98e:be37:92ff:fcc7:2c26:4d2d:b393:95cb-d9fe:570d:e24e:1d2b:403:6c50:eb8d:fc3 | | d98e:be37:92ff:fcc7:2c26:4d2d:b393:95cb-d9fe:570d:e24e:1d2b:403:6c50:eb8d:fc3 e11c:4f21:dd57:c814:af4e:3f55:4adf:f1a0 | | e11c:4f21:dd57:c814:af4e:3f55:4adf:f1a0 | e104:d364:b55e:bf80:97f3:cf03:61ed:c6ef-e1b7:f280:7b4a:2a4:2e0e:c372:f0ab:158 | | e104:d364:b55e:bf80:97f3:cf03:61ed:c6ef-e1b7:f280:7b4a:2a4:2e0e:c372:f0ab:158 e199:2ea0:f3b4:3a31:5d15:dfc9:68cd:c948 | | e199:2ea0:f3b4:3a31:5d15:dfc9:68cd:c948 | e104:d364:b55e:bf80:97f3:cf03:61ed:c6ef-e1b7:f280:7b4a:2a4:2e0e:c372:f0ab:158 | | e104:d364:b55e:bf80:97f3:cf03:61ed:c6ef-e1b7:f280:7b4a:2a4:2e0e:c372:f0ab:158 (60 rows) -- hashing select lower(a / 4), count(*) from ipaddrs group by 1 order by 2,1; lower | count -----------+------- 0.0.0.0 | 1 32.0.0.0 | 1 48.0.0.0 | 1 160.0.0.0 | 1 176.0.0.0 | 1 208.0.0.0 | 1 224.0.0.0 | 1 64.0.0.0 | 2 96.0.0.0 | 2 192.0.0.0 | 2 240.0.0.0 | 3 3000:: | 11 6000:: | 11 9000:: | 12 f000:: | 12 c000:: | 13 4000:: | 14 e000:: | 15 5000:: | 16 a000:: | 16 b000:: | 16 7000:: | 17 d000:: | 17 :: | 18 2000:: | 19 1000:: | 23 8000:: | 26 (27 rows) select a4 & '240.0.0.0', count(*) from ipaddrs group by 1 order by 2,1; ?column? | count -----------+------- 0.0.0.0 | 1 32.0.0.0 | 1 48.0.0.0 | 1 160.0.0.0 | 1 176.0.0.0 | 1 208.0.0.0 | 1 224.0.0.0 | 1 64.0.0.0 | 2 96.0.0.0 | 2 192.0.0.0 | 2 240.0.0.0 | 3 | 256 (12 rows) select a6 & 'f000::', count(*) from ipaddrs group by 1 order by 2,1; ?column? | count ----------+------- 3000:: | 11 6000:: | 11 9000:: | 12 f000:: | 12 c000:: | 13 4000:: | 14 e000:: | 15 5000:: | 16 a000:: | 16 b000:: | 16 | 16 7000:: | 17 d000:: | 17 :: | 18 2000:: | 19 1000:: | 23 8000:: | 26 (17 rows) select a / 4, count(*) from ipaddrs group by 1 order by 2,1; ?column? | count -------------+------- 0.0.0.0/4 | 1 32.0.0.0/4 | 1 48.0.0.0/4 | 1 160.0.0.0/4 | 1 176.0.0.0/4 | 1 208.0.0.0/4 | 1 224.0.0.0/4 | 1 64.0.0.0/4 | 2 96.0.0.0/4 | 2 192.0.0.0/4 | 2 240.0.0.0/4 | 3 3000::/4 | 11 6000::/4 | 11 9000::/4 | 12 f000::/4 | 12 c000::/4 | 13 4000::/4 | 14 e000::/4 | 15 5000::/4 | 16 a000::/4 | 16 b000::/4 | 16 7000::/4 | 17 d000::/4 | 17 ::/4 | 18 2000::/4 | 19 1000::/4 | 23 8000::/4 | 26 (27 rows) select a4 / 4, count(*) from ipaddrs group by 1 order by 2,1; ?column? | count -------------+------- 0.0.0.0/4 | 1 32.0.0.0/4 | 1 48.0.0.0/4 | 1 160.0.0.0/4 | 1 176.0.0.0/4 | 1 208.0.0.0/4 | 1 224.0.0.0/4 | 1 64.0.0.0/4 | 2 96.0.0.0/4 | 2 192.0.0.0/4 | 2 240.0.0.0/4 | 3 | 256 (12 rows) select a6 / 4, count(*) from ipaddrs group by 1 order by 2,1; ?column? | count ----------+------- 3000::/4 | 11 6000::/4 | 11 9000::/4 | 12 f000::/4 | 12 c000::/4 | 13 4000::/4 | 14 e000::/4 | 15 5000::/4 | 16 a000::/4 | 16 b000::/4 | 16 | 16 7000::/4 | 17 d000::/4 | 17 ::/4 | 18 2000::/4 | 19 1000::/4 | 23 8000::/4 | 26 (17 rows) -- comparison ops select sum((r < '2000::/48')::integer) as s_lt, sum((r <= '2000::/48')::integer) as s_le, sum((r = '2000::/48')::integer) as s_eq, sum((r >= '2000::/48')::integer) as s_ge, sum((r > '2000::/48')::integer) as s_gt, sum((r <> '2000::/48')::integer) as s_ne from ipranges; s_lt | s_le | s_eq | s_ge | s_gt | s_ne -------+-------+------+-------+-------+------- 11182 | 11183 | 1 | 19844 | 19843 | 31025 (1 row) select sum((r6 < '2000::/48')::integer) as s_lt, sum((r6 <= '2000::/48')::integer) as s_le, sum((r6 = '2000::/48')::integer) as s_eq, sum((r6 >= '2000::/48')::integer) as s_ge, sum((r6 > '2000::/48')::integer) as s_gt, sum((r6 <> '2000::/48')::integer) as s_ne from ipranges; s_lt | s_le | s_eq | s_ge | s_gt | s_ne ------+------+------+-------+-------+------- 1658 | 1659 | 1 | 19844 | 19843 | 21501 (1 row) select sum((r4 < '172.16.0.0/28')::integer) as s_lt, sum((r4 <= '172.16.0.0/28')::integer) as s_le, sum((r4 = '172.16.0.0/28')::integer) as s_eq, sum((r4 >= '172.16.0.0/28')::integer) as s_ge, sum((r4 > '172.16.0.0/28')::integer) as s_gt, sum((r4 <> '172.16.0.0/28')::integer) as s_ne from ipranges; s_lt | s_le | s_eq | s_ge | s_gt | s_ne ------+------+------+------+------+------ 5019 | 5020 | 1 | 4504 | 4503 | 9522 (1 row) select sum((a < '8ecc:14db:7aba:bbde:f2a7:c4bc:7a1e:c8c1')::integer) as s_lt, sum((a <= '8ecc:14db:7aba:bbde:f2a7:c4bc:7a1e:c8c1')::integer) as s_le, sum((a = '8ecc:14db:7aba:bbde:f2a7:c4bc:7a1e:c8c1')::integer) as s_eq, sum((a >= '8ecc:14db:7aba:bbde:f2a7:c4bc:7a1e:c8c1')::integer) as s_ge, sum((a > '8ecc:14db:7aba:bbde:f2a7:c4bc:7a1e:c8c1')::integer) as s_gt, sum((a <> '8ecc:14db:7aba:bbde:f2a7:c4bc:7a1e:c8c1')::integer) as s_ne from ipaddrs; s_lt | s_le | s_eq | s_ge | s_gt | s_ne ------+------+------+------+------+------ 167 | 168 | 1 | 105 | 104 | 271 (1 row) select sum((a6 < '8ecc:14db:7aba:bbde:f2a7:c4bc:7a1e:c8c1')::integer) as s_lt, sum((a6 <= '8ecc:14db:7aba:bbde:f2a7:c4bc:7a1e:c8c1')::integer) as s_le, sum((a6 = '8ecc:14db:7aba:bbde:f2a7:c4bc:7a1e:c8c1')::integer) as s_eq, sum((a6 >= '8ecc:14db:7aba:bbde:f2a7:c4bc:7a1e:c8c1')::integer) as s_ge, sum((a6 > '8ecc:14db:7aba:bbde:f2a7:c4bc:7a1e:c8c1')::integer) as s_gt, sum((a6 <> '8ecc:14db:7aba:bbde:f2a7:c4bc:7a1e:c8c1')::integer) as s_ne from ipaddrs; s_lt | s_le | s_eq | s_ge | s_gt | s_ne ------+------+------+------+------+------ 151 | 152 | 1 | 105 | 104 | 255 (1 row) select sum((a4 < '104.175.11.72')::integer) as s_lt, sum((a4 <= '104.175.11.72')::integer) as s_le, sum((a4 = '104.175.11.72')::integer) as s_eq, sum((a4 >= '104.175.11.72')::integer) as s_ge, sum((a4 > '104.175.11.72')::integer) as s_gt, sum((a4 <> '104.175.11.72')::integer) as s_ne from ipaddrs; s_lt | s_le | s_eq | s_ge | s_gt | s_ne ------+------+------+------+------+------ 6 | 7 | 1 | 10 | 9 | 15 (1 row) -- end ip4r-2.0.2/ip4r--2.0.sql000066400000000000000000001456251233620317400143600ustar00rootroot00000000000000-- ip4r extension -- complain if script is sourced in psql, rather than via CREATE EXTENSION \echo Use "CREATE EXTENSION ip4r" to load this file. \quit -- ---------------------------------------------------------------------- -- Type definitions -- type creation is needlessly chatty CREATE TYPE ip4; CREATE FUNCTION ip4_in(cstring) RETURNS ip4 AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip4_out(ip4) RETURNS cstring AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip4_recv(internal) RETURNS ip4 AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip4_send(ip4) RETURNS bytea AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE TYPE ip4 ( INPUT = ip4_in, OUTPUT = ip4_out, RECEIVE = ip4_recv, SEND = ip4_send, INTERNALLENGTH = 4, ALIGNMENT = int4, PASSEDBYVALUE ); COMMENT ON TYPE ip4 IS 'IPv4 address ''#.#.#.#'''; CREATE TYPE ip4r; CREATE FUNCTION ip4r_in(cstring) RETURNS ip4r AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip4r_out(ip4r) RETURNS cstring AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip4r_recv(internal) RETURNS ip4r AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip4r_send(ip4r) RETURNS bytea AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE TYPE ip4r ( INPUT = ip4r_in, OUTPUT = ip4r_out, RECEIVE = ip4r_recv, SEND = ip4r_send, INTERNALLENGTH = 8, ALIGNMENT = int4 ); COMMENT ON TYPE ip4r IS 'IPv4 range ''#.#.#.#-#.#.#.#'' or ''#.#.#.#/#'' or ''#.#.#.#'''; CREATE TYPE ip6; CREATE FUNCTION ip6_in(cstring) RETURNS ip6 AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip6_out(ip6) RETURNS cstring AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip6_recv(internal) RETURNS ip6 AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip6_send(ip6) RETURNS bytea AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE TYPE ip6 ( INPUT = ip6_in, OUTPUT = ip6_out, RECEIVE = ip6_recv, SEND = ip6_send, INTERNALLENGTH = 16, ALIGNMENT = double ); COMMENT ON TYPE ip6 IS 'IPv6 address ''xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx'''; CREATE TYPE ip6r; CREATE FUNCTION ip6r_in(cstring) RETURNS ip6r AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip6r_out(ip6r) RETURNS cstring AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip6r_recv(internal) RETURNS ip6r AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip6r_send(ip6r) RETURNS bytea AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE TYPE ip6r ( INPUT = ip6r_in, OUTPUT = ip6r_out, RECEIVE = ip6r_recv, SEND = ip6r_send, INTERNALLENGTH = 32, ALIGNMENT = double ); COMMENT ON TYPE ip6r IS 'IPv6 range ''#-#'' or ''#/#'' or ''#'''; CREATE TYPE ipaddress; CREATE FUNCTION ipaddress_in(cstring) RETURNS ipaddress AS 'MODULE_PATHNAME','ipaddr_in' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ipaddress_out(ipaddress) RETURNS cstring AS 'MODULE_PATHNAME','ipaddr_out' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ipaddress_recv(internal) RETURNS ipaddress AS 'MODULE_PATHNAME','ipaddr_recv' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ipaddress_send(ipaddress) RETURNS bytea AS 'MODULE_PATHNAME','ipaddr_send' LANGUAGE C IMMUTABLE STRICT; CREATE TYPE ipaddress ( INPUT = ipaddress_in, OUTPUT = ipaddress_out, RECEIVE = ipaddress_recv, SEND = ipaddress_send, INTERNALLENGTH = VARIABLE, ALIGNMENT = int4, STORAGE = main ); COMMENT ON TYPE ipaddress IS 'IPv4 or IPv6 address'; CREATE TYPE iprange; CREATE FUNCTION iprange_in(cstring) RETURNS iprange AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION iprange_out(iprange) RETURNS cstring AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION iprange_recv(internal) RETURNS iprange AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION iprange_send(iprange) RETURNS bytea AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE TYPE iprange ( INPUT = iprange_in, OUTPUT = iprange_out, RECEIVE = iprange_recv, SEND = iprange_send, INTERNALLENGTH = VARIABLE, ALIGNMENT = int4, STORAGE = main ); COMMENT ON TYPE iprange IS 'IPv4 or IPv6 range'; -- ---------------------------------------------------------------------- -- Cast functions (inward) CREATE FUNCTION ip4(bigint) RETURNS ip4 AS 'MODULE_PATHNAME','ip4_cast_from_bigint' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip4(double precision) RETURNS ip4 AS 'MODULE_PATHNAME','ip4_cast_from_double' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip4(numeric) RETURNS ip4 AS 'MODULE_PATHNAME','ip4_cast_from_numeric' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip4(inet) RETURNS ip4 AS 'MODULE_PATHNAME','ip4_cast_from_inet' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip4(text) RETURNS ip4 AS 'MODULE_PATHNAME','ip4_cast_from_text' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip4(ipaddress) RETURNS ip4 AS 'MODULE_PATHNAME','ipaddr_cast_to_ip4' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip6(numeric) RETURNS ip6 AS 'MODULE_PATHNAME','ip6_cast_from_numeric' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip6(inet) RETURNS ip6 AS 'MODULE_PATHNAME','ip6_cast_from_inet' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip6(text) RETURNS ip6 AS 'MODULE_PATHNAME','ip6_cast_from_text' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip6(ipaddress) RETURNS ip6 AS 'MODULE_PATHNAME','ipaddr_cast_to_ip6' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ipaddress(inet) RETURNS ipaddress AS 'MODULE_PATHNAME','ipaddr_cast_from_inet' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ipaddress(ip4) RETURNS ipaddress AS 'MODULE_PATHNAME','ipaddr_cast_from_ip4' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ipaddress(ip6) RETURNS ipaddress AS 'MODULE_PATHNAME','ipaddr_cast_from_ip6' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ipaddress(text) RETURNS ipaddress AS 'MODULE_PATHNAME','ipaddr_cast_from_text' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip4r(cidr) RETURNS ip4r AS 'MODULE_PATHNAME','ip4r_cast_from_cidr' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip4r(ip4) RETURNS ip4r AS 'MODULE_PATHNAME','ip4r_cast_from_ip4' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip4r(text) RETURNS ip4r AS 'MODULE_PATHNAME','ip4r_cast_from_text' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip4r(iprange) RETURNS ip4r AS 'MODULE_PATHNAME','iprange_cast_to_ip4r' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip6r(cidr) RETURNS ip6r AS 'MODULE_PATHNAME','ip6r_cast_from_cidr' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip6r(ip6) RETURNS ip6r AS 'MODULE_PATHNAME','ip6r_cast_from_ip6' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip6r(text) RETURNS ip6r AS 'MODULE_PATHNAME','ip6r_cast_from_text' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip6r(iprange) RETURNS ip6r AS 'MODULE_PATHNAME','iprange_cast_to_ip6r' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION iprange(cidr) RETURNS iprange AS 'MODULE_PATHNAME','iprange_cast_from_cidr' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION iprange(ip4) RETURNS iprange AS 'MODULE_PATHNAME','iprange_cast_from_ip4' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION iprange(ip6) RETURNS iprange AS 'MODULE_PATHNAME','iprange_cast_from_ip6' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION iprange(ip4r) RETURNS iprange AS 'MODULE_PATHNAME','iprange_cast_from_ip4r' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION iprange(ip6r) RETURNS iprange AS 'MODULE_PATHNAME','iprange_cast_from_ip6r' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION iprange(ipaddress) RETURNS iprange AS 'MODULE_PATHNAME','iprange_cast_from_ipaddr' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION iprange(text) RETURNS iprange AS 'MODULE_PATHNAME','iprange_cast_from_text' LANGUAGE C IMMUTABLE STRICT; -- ---------------------------------------------------------------------- -- Cast functions (outward) CREATE FUNCTION cidr(ip4) RETURNS cidr AS 'MODULE_PATHNAME','ip4_cast_to_cidr' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION cidr(ip4r) RETURNS cidr AS 'MODULE_PATHNAME','ip4r_cast_to_cidr' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION cidr(ip6) RETURNS cidr AS 'MODULE_PATHNAME','ip6_cast_to_cidr' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION cidr(ip6r) RETURNS cidr AS 'MODULE_PATHNAME','ip6r_cast_to_cidr' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION cidr(ipaddress) RETURNS cidr AS 'MODULE_PATHNAME','ipaddr_cast_to_cidr' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION cidr(iprange) RETURNS cidr AS 'MODULE_PATHNAME','iprange_cast_to_cidr' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION text(ip4) RETURNS text AS 'MODULE_PATHNAME','ip4_cast_to_text' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION text(ip4r) RETURNS text AS 'MODULE_PATHNAME','ip4r_cast_to_text' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION text(ip6) RETURNS text AS 'MODULE_PATHNAME','ip6_cast_to_text' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION text(ip6r) RETURNS text AS 'MODULE_PATHNAME','ip6r_cast_to_text' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION text(ipaddress) RETURNS text AS 'MODULE_PATHNAME','ipaddr_cast_to_text' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION text(iprange) RETURNS text AS 'MODULE_PATHNAME','iprange_cast_to_text' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION to_bigint(ip4) RETURNS bigint AS 'MODULE_PATHNAME','ip4_cast_to_bigint' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION to_double(ip4) RETURNS double precision AS 'MODULE_PATHNAME','ip4_cast_to_double' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION to_numeric(ip4) RETURNS numeric AS 'MODULE_PATHNAME','ip4_cast_to_numeric' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION to_numeric(ip6) RETURNS numeric AS 'MODULE_PATHNAME','ip6_cast_to_numeric' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION to_numeric(ipaddress) RETURNS numeric AS 'MODULE_PATHNAME','ipaddr_cast_to_numeric' LANGUAGE C IMMUTABLE STRICT; -- ---------------------------------------------------------------------- -- Cast definitions (outward) -- all these are explicit, with the exception of casts from single-address -- types to "cidr", which we make assignment casts since they are lossless -- and preserve general semantics. CREATE CAST (ip4 as bigint) WITH FUNCTION to_bigint(ip4); CREATE CAST (ip4 as double precision) WITH FUNCTION to_double(ip4); CREATE CAST (ip4 as numeric) WITH FUNCTION to_numeric(ip4); CREATE CAST (ip4 as text) WITH FUNCTION text(ip4); CREATE CAST (ip4 as cidr) WITH FUNCTION cidr(ip4) AS ASSIGNMENT; CREATE CAST (ip4r as cidr) WITH FUNCTION cidr(ip4r); CREATE CAST (ip4r as text) WITH FUNCTION text(ip4r); CREATE CAST (ip6 as numeric) WITH FUNCTION to_numeric(ip6); CREATE CAST (ip6 as text) WITH FUNCTION text(ip6); CREATE CAST (ip6 as cidr) WITH FUNCTION cidr(ip6) AS ASSIGNMENT; CREATE CAST (ip6r as cidr) WITH FUNCTION cidr(ip6r); CREATE CAST (ip6r as text) WITH FUNCTION text(ip6r); CREATE CAST (ipaddress as numeric) WITH FUNCTION to_numeric(ipaddress); CREATE CAST (ipaddress as text) WITH FUNCTION text(ipaddress); CREATE CAST (ipaddress as cidr) WITH FUNCTION cidr(ipaddress) AS ASSIGNMENT; CREATE CAST (iprange as cidr) WITH FUNCTION cidr(iprange); CREATE CAST (iprange as text) WITH FUNCTION text(iprange); -- ---------------------------------------------------------------------- -- Cast definitions (inward) -- these are explicit except for casts from inet/cidr types. Even though -- such casts are lossy for inet, since the masklen isn't preserved, the -- semantics and common usage are enough to justify an assignment cast. CREATE CAST (text as ip4) WITH FUNCTION ip4(text); CREATE CAST (text as ip4r) WITH FUNCTION ip4r(text); CREATE CAST (text as ip6) WITH FUNCTION ip6(text); CREATE CAST (text as ip6r) WITH FUNCTION ip6r(text); CREATE CAST (text as ipaddress) WITH FUNCTION ipaddress(text); CREATE CAST (text as iprange) WITH FUNCTION iprange(text); CREATE CAST (bigint as ip4) WITH FUNCTION ip4(bigint); CREATE CAST (double precision as ip4) WITH FUNCTION ip4(double precision); CREATE CAST (numeric as ip4) WITH FUNCTION ip4(numeric); CREATE CAST (numeric as ip6) WITH FUNCTION ip6(numeric); CREATE CAST (cidr as ip4r) WITH FUNCTION ip4r(cidr) AS ASSIGNMENT; CREATE CAST (cidr as ip6r) WITH FUNCTION ip6r(cidr) AS ASSIGNMENT; CREATE CAST (cidr as iprange) WITH FUNCTION iprange(cidr) AS ASSIGNMENT; CREATE CAST (inet as ip4) WITH FUNCTION ip4(inet) AS ASSIGNMENT; CREATE CAST (inet as ip6) WITH FUNCTION ip6(inet) AS ASSIGNMENT; CREATE CAST (inet as ipaddress) WITH FUNCTION ipaddress(inet) AS ASSIGNMENT; -- ---------------------------------------------------------------------- -- Cast definitions (cross-type) -- the lossless "upward" casts are made implict. CREATE CAST (ip4 as ip4r) WITH FUNCTION ip4r(ip4) AS IMPLICIT; CREATE CAST (ip4 as ipaddress) WITH FUNCTION ipaddress(ip4) AS IMPLICIT; CREATE CAST (ip4 as iprange) WITH FUNCTION iprange(ip4) AS IMPLICIT; CREATE CAST (ip4r as iprange) WITH FUNCTION iprange(ip4r) AS IMPLICIT; CREATE CAST (ip6 as ip6r) WITH FUNCTION ip6r(ip6) AS IMPLICIT; CREATE CAST (ip6 as ipaddress) WITH FUNCTION ipaddress(ip6) AS IMPLICIT; CREATE CAST (ip6 as iprange) WITH FUNCTION iprange(ip6) AS IMPLICIT; CREATE CAST (ip6r as iprange) WITH FUNCTION iprange(ip6r) AS IMPLICIT; CREATE CAST (ipaddress as iprange) WITH FUNCTION iprange(ipaddress) AS IMPLICIT; CREATE CAST (ipaddress as ip4) WITH FUNCTION ip4(ipaddress); CREATE CAST (ipaddress as ip6) WITH FUNCTION ip6(ipaddress); CREATE CAST (iprange as ip4r) WITH FUNCTION ip4r(iprange); CREATE CAST (iprange as ip6r) WITH FUNCTION ip6r(iprange); -- ---------------------------------------------------------------------- -- Constructor functions CREATE FUNCTION ip4r(ip4,ip4) RETURNS ip4r AS 'MODULE_PATHNAME', 'ip4r_from_ip4s' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip6r(ip6,ip6) RETURNS ip6r AS 'MODULE_PATHNAME', 'ip6r_from_ip6s' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION iprange(ip4,ip4) RETURNS iprange AS 'MODULE_PATHNAME', 'iprange_from_ip4s' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION iprange(ip6,ip6) RETURNS iprange AS 'MODULE_PATHNAME', 'iprange_from_ip6s' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION iprange(ipaddress,ipaddress) RETURNS iprange AS 'MODULE_PATHNAME', 'iprange_from_ipaddrs' LANGUAGE C IMMUTABLE STRICT; -- ---------------------------------------------------------------------- -- Utility functions (no operator equivalent) CREATE FUNCTION family(ip4) RETURNS integer AS $f$ select 4; $f$ LANGUAGE SQL IMMUTABLE; CREATE FUNCTION family(ip4r) RETURNS integer AS $f$ select 4; $f$ LANGUAGE SQL IMMUTABLE; CREATE FUNCTION family(ip6) RETURNS integer AS $f$ select 6; $f$ LANGUAGE SQL IMMUTABLE; CREATE FUNCTION family(ip6r) RETURNS integer AS $f$ select 6; $f$ LANGUAGE SQL IMMUTABLE; CREATE FUNCTION family(ipaddress) RETURNS integer AS 'MODULE_PATHNAME', 'ipaddr_family' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION family(iprange) RETURNS integer AS 'MODULE_PATHNAME', 'iprange_family' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip4_netmask(integer) RETURNS ip4 AS 'MODULE_PATHNAME', 'ip4_netmask' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip6_netmask(integer) RETURNS ip6 AS 'MODULE_PATHNAME', 'ip6_netmask' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION is_cidr(ip4r) RETURNS boolean AS 'MODULE_PATHNAME', 'ip4r_is_cidr' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION is_cidr(ip6r) RETURNS boolean AS 'MODULE_PATHNAME', 'ip6r_is_cidr' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION is_cidr(iprange) RETURNS boolean AS 'MODULE_PATHNAME', 'iprange_is_cidr' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION masklen(ip4r) RETURNS integer AS 'MODULE_PATHNAME','ip4r_prefixlen' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION masklen(ip6r) RETURNS integer AS 'MODULE_PATHNAME','ip6r_prefixlen' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION masklen(iprange) RETURNS integer AS 'MODULE_PATHNAME','iprange_prefixlen' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION lower(ip4r) RETURNS ip4 AS 'MODULE_PATHNAME', 'ip4r_lower' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION lower(ip6r) RETURNS ip6 AS 'MODULE_PATHNAME', 'ip6r_lower' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION lower(iprange) RETURNS ipaddress AS 'MODULE_PATHNAME', 'iprange_lower' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION upper(ip4r) RETURNS ip4 AS 'MODULE_PATHNAME', 'ip4r_upper' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION upper(ip6r) RETURNS ip6 AS 'MODULE_PATHNAME', 'ip6r_upper' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION upper(iprange) RETURNS ipaddress AS 'MODULE_PATHNAME', 'iprange_upper' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip4_net_lower(ip4,integer) RETURNS ip4 AS 'MODULE_PATHNAME', 'ip4_net_lower' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip6_net_lower(ip6,integer) RETURNS ip6 AS 'MODULE_PATHNAME', 'ip6_net_lower' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ipaddress_net_lower(ipaddress,integer) RETURNS ipaddress AS 'MODULE_PATHNAME', 'ipaddr_net_lower' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip4_net_upper(ip4,integer) RETURNS ip4 AS 'MODULE_PATHNAME', 'ip4_net_upper' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip6_net_upper(ip6,integer) RETURNS ip6 AS 'MODULE_PATHNAME', 'ip6_net_upper' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ipaddress_net_upper(ipaddress,integer) RETURNS ipaddress AS 'MODULE_PATHNAME', 'ipaddr_net_upper' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip4r_union(ip4r, ip4r) RETURNS ip4r AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip6r_union(ip6r, ip6r) RETURNS ip6r AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION iprange_union(iprange, iprange) RETURNS iprange AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip4r_inter(ip4r,ip4r) RETURNS ip4r AS 'MODULE_PATHNAME','ip4r_inter' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip6r_inter(ip6r,ip6r) RETURNS ip6r AS 'MODULE_PATHNAME','ip6r_inter' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION iprange_inter(iprange,iprange) RETURNS iprange AS 'MODULE_PATHNAME','iprange_inter' LANGUAGE C IMMUTABLE STRICT; -- ---------------------------------------------------------------------- -- Functions with operator equivalents -- it's intended that either the function form or the operator form be used, -- as desired. -- (ip / len) or (ip / mask) CREATE FUNCTION ip4r_net_mask(ip4,ip4) RETURNS ip4r AS 'MODULE_PATHNAME','ip4r_net_mask' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip6r_net_mask(ip6,ip6) RETURNS ip6r AS 'MODULE_PATHNAME','ip6r_net_mask' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION iprange_net_mask(ip4,ip4) RETURNS iprange AS 'MODULE_PATHNAME','iprange_net_mask_ip4' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION iprange_net_mask(ip6,ip6) RETURNS iprange AS 'MODULE_PATHNAME','iprange_net_mask_ip6' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION iprange_net_mask(ipaddress,ipaddress) RETURNS iprange AS 'MODULE_PATHNAME','iprange_net_mask' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip4r_net_prefix(ip4,integer) RETURNS ip4r AS 'MODULE_PATHNAME','ip4r_net_prefix' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip6r_net_prefix(ip6,integer) RETURNS ip6r AS 'MODULE_PATHNAME','ip6r_net_prefix' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION iprange_net_prefix(ip4,integer) RETURNS iprange AS 'MODULE_PATHNAME','iprange_net_prefix_ip4' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION iprange_net_prefix(ip6,integer) RETURNS iprange AS 'MODULE_PATHNAME','iprange_net_prefix_ip6' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION iprange_net_prefix(ipaddress,integer) RETURNS iprange AS 'MODULE_PATHNAME','iprange_net_prefix' LANGUAGE C IMMUTABLE STRICT; CREATE OPERATOR / ( LEFTARG = ip4, RIGHTARG = ip4, PROCEDURE = ip4r_net_mask ); CREATE OPERATOR / ( LEFTARG = ip6, RIGHTARG = ip6, PROCEDURE = ip6r_net_mask ); CREATE OPERATOR / ( LEFTARG = ipaddress, RIGHTARG = ipaddress, PROCEDURE = iprange_net_mask ); CREATE OPERATOR / ( LEFTARG = ip4, RIGHTARG = integer, PROCEDURE = ip4r_net_prefix ); CREATE OPERATOR / ( LEFTARG = ip6, RIGHTARG = integer, PROCEDURE = ip6r_net_prefix ); CREATE OPERATOR / ( LEFTARG = ipaddress, RIGHTARG = integer, PROCEDURE = iprange_net_prefix ); -- @ ipr (approximate size) or @@ ipr (exact size) CREATE FUNCTION ip4r_size(ip4r) RETURNS double precision AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip6r_size(ip6r) RETURNS double precision AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION iprange_size(iprange) RETURNS double precision AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip4r_size_exact(ip4r) RETURNS numeric AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip6r_size_exact(ip6r) RETURNS numeric AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION iprange_size_exact(iprange) RETURNS numeric AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OPERATOR @ ( RIGHTARG = ip4r, PROCEDURE = ip4r_size ); CREATE OPERATOR @ ( RIGHTARG = ip6r, PROCEDURE = ip6r_size ); CREATE OPERATOR @ ( RIGHTARG = iprange, PROCEDURE = iprange_size ); CREATE OPERATOR @@ ( RIGHTARG = ip4r, PROCEDURE = ip4r_size_exact ); CREATE OPERATOR @@ ( RIGHTARG = ip6r, PROCEDURE = ip6r_size_exact ); CREATE OPERATOR @@ ( RIGHTARG = iprange, PROCEDURE = iprange_size_exact ); -- ---------------------------------------------------------------------- -- Operators -- the function forms of these aren't intended for general use -- bitwise ops: and (a & b), or (a | b), xor (a # b), not (~a) CREATE FUNCTION ip4_and(ip4,ip4) RETURNS ip4 AS 'MODULE_PATHNAME', 'ip4_and' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip6_and(ip6,ip6) RETURNS ip6 AS 'MODULE_PATHNAME', 'ip6_and' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ipaddress_and(ipaddress,ipaddress) RETURNS ipaddress AS 'MODULE_PATHNAME', 'ipaddr_and' LANGUAGE C IMMUTABLE STRICT; CREATE OPERATOR & ( LEFTARG = ip4, RIGHTARG = ip4, PROCEDURE = ip4_and ); CREATE OPERATOR & ( LEFTARG = ip6, RIGHTARG = ip6, PROCEDURE = ip6_and ); CREATE OPERATOR & ( LEFTARG = ipaddress, RIGHTARG = ipaddress, PROCEDURE = ipaddress_and ); CREATE FUNCTION ip4_or(ip4,ip4) RETURNS ip4 AS 'MODULE_PATHNAME', 'ip4_or' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip6_or(ip6,ip6) RETURNS ip6 AS 'MODULE_PATHNAME', 'ip6_or' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ipaddress_or(ipaddress,ipaddress) RETURNS ipaddress AS 'MODULE_PATHNAME', 'ipaddr_or' LANGUAGE C IMMUTABLE STRICT; CREATE OPERATOR | ( LEFTARG = ip4, RIGHTARG = ip4, PROCEDURE = ip4_or ); CREATE OPERATOR | ( LEFTARG = ip6, RIGHTARG = ip6, PROCEDURE = ip6_or ); CREATE OPERATOR | ( LEFTARG = ipaddress, RIGHTARG = ipaddress, PROCEDURE = ipaddress_or ); CREATE FUNCTION ip4_not(ip4) RETURNS ip4 AS 'MODULE_PATHNAME', 'ip4_not' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip6_not(ip6) RETURNS ip6 AS 'MODULE_PATHNAME', 'ip6_not' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ipaddress_not(ipaddress) RETURNS ipaddress AS 'MODULE_PATHNAME', 'ipaddr_not' LANGUAGE C IMMUTABLE STRICT; CREATE OPERATOR ~ ( RIGHTARG = ip4, PROCEDURE = ip4_not ); CREATE OPERATOR ~ ( RIGHTARG = ip6, PROCEDURE = ip6_not ); CREATE OPERATOR ~ ( RIGHTARG = ipaddress, PROCEDURE = ipaddress_not ); CREATE FUNCTION ip4_xor(ip4,ip4) RETURNS ip4 AS 'MODULE_PATHNAME', 'ip4_xor' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip6_xor(ip6,ip6) RETURNS ip6 AS 'MODULE_PATHNAME', 'ip6_xor' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ipaddress_xor(ipaddress,ipaddress) RETURNS ipaddress AS 'MODULE_PATHNAME', 'ipaddr_xor' LANGUAGE C IMMUTABLE STRICT; CREATE OPERATOR # ( LEFTARG = ip4, RIGHTARG = ip4, PROCEDURE = ip4_xor ); CREATE OPERATOR # ( LEFTARG = ip6, RIGHTARG = ip6, PROCEDURE = ip6_xor ); CREATE OPERATOR # ( LEFTARG = ipaddress, RIGHTARG = ipaddress, PROCEDURE = ipaddress_xor ); -- arithmetic ops: (ip + n), (ip - n), (ip - ip) where n is a numeric or integer type CREATE FUNCTION ip4_plus_bigint(ip4,bigint) RETURNS ip4 AS 'MODULE_PATHNAME', 'ip4_plus_bigint' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip4_plus_int(ip4,integer) RETURNS ip4 AS 'MODULE_PATHNAME', 'ip4_plus_int' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip4_plus_numeric(ip4,numeric) RETURNS ip4 AS 'MODULE_PATHNAME', 'ip4_plus_numeric' LANGUAGE C IMMUTABLE STRICT; CREATE OPERATOR + ( LEFTARG = ip4, RIGHTARG = bigint, PROCEDURE = ip4_plus_bigint ); CREATE OPERATOR + ( LEFTARG = ip4, RIGHTARG = integer, PROCEDURE = ip4_plus_int ); CREATE OPERATOR + ( LEFTARG = ip4, RIGHTARG = numeric, PROCEDURE = ip4_plus_numeric ); CREATE FUNCTION ip6_plus_bigint(ip6,bigint) RETURNS ip6 AS 'MODULE_PATHNAME', 'ip6_plus_bigint' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip6_plus_int(ip6,integer) RETURNS ip6 AS 'MODULE_PATHNAME', 'ip6_plus_int' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip6_plus_numeric(ip6,numeric) RETURNS ip6 AS 'MODULE_PATHNAME', 'ip6_plus_numeric' LANGUAGE C IMMUTABLE STRICT; CREATE OPERATOR + ( LEFTARG = ip6, RIGHTARG = bigint, PROCEDURE = ip6_plus_bigint ); CREATE OPERATOR + ( LEFTARG = ip6, RIGHTARG = integer, PROCEDURE = ip6_plus_int ); CREATE OPERATOR + ( LEFTARG = ip6, RIGHTARG = numeric, PROCEDURE = ip6_plus_numeric ); CREATE FUNCTION ipaddress_plus_bigint(ipaddress,bigint) RETURNS ipaddress AS 'MODULE_PATHNAME', 'ipaddr_plus_bigint' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ipaddress_plus_int(ipaddress,integer) RETURNS ipaddress AS 'MODULE_PATHNAME', 'ipaddr_plus_int' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ipaddress_plus_numeric(ipaddress,numeric) RETURNS ipaddress AS 'MODULE_PATHNAME', 'ipaddr_plus_numeric' LANGUAGE C IMMUTABLE STRICT; CREATE OPERATOR + ( LEFTARG = ipaddress, RIGHTARG = bigint, PROCEDURE = ipaddress_plus_bigint ); CREATE OPERATOR + ( LEFTARG = ipaddress, RIGHTARG = integer, PROCEDURE = ipaddress_plus_int ); CREATE OPERATOR + ( LEFTARG = ipaddress, RIGHTARG = numeric, PROCEDURE = ipaddress_plus_numeric ); CREATE FUNCTION ip4_minus_bigint(ip4,bigint) RETURNS ip4 AS 'MODULE_PATHNAME', 'ip4_minus_bigint' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip4_minus_int(ip4,integer) RETURNS ip4 AS 'MODULE_PATHNAME', 'ip4_minus_int' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip4_minus_numeric(ip4,numeric) RETURNS ip4 AS 'MODULE_PATHNAME', 'ip4_minus_numeric' LANGUAGE C IMMUTABLE STRICT; CREATE OPERATOR - ( LEFTARG = ip4, RIGHTARG = bigint, PROCEDURE = ip4_minus_bigint ); CREATE OPERATOR - ( LEFTARG = ip4, RIGHTARG = integer, PROCEDURE = ip4_minus_int ); CREATE OPERATOR - ( LEFTARG = ip4, RIGHTARG = numeric, PROCEDURE = ip4_minus_numeric ); CREATE FUNCTION ip6_minus_bigint(ip6,bigint) RETURNS ip6 AS 'MODULE_PATHNAME', 'ip6_minus_bigint' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip6_minus_int(ip6,integer) RETURNS ip6 AS 'MODULE_PATHNAME', 'ip6_minus_int' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip6_minus_numeric(ip6,numeric) RETURNS ip6 AS 'MODULE_PATHNAME', 'ip6_minus_numeric' LANGUAGE C IMMUTABLE STRICT; CREATE OPERATOR - ( LEFTARG = ip6, RIGHTARG = bigint, PROCEDURE = ip6_minus_bigint ); CREATE OPERATOR - ( LEFTARG = ip6, RIGHTARG = integer, PROCEDURE = ip6_minus_int ); CREATE OPERATOR - ( LEFTARG = ip6, RIGHTARG = numeric, PROCEDURE = ip6_minus_numeric ); CREATE FUNCTION ipaddress_minus_bigint(ipaddress,bigint) RETURNS ipaddress AS 'MODULE_PATHNAME', 'ipaddr_minus_bigint' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ipaddress_minus_int(ipaddress,integer) RETURNS ipaddress AS 'MODULE_PATHNAME', 'ipaddr_minus_int' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ipaddress_minus_numeric(ipaddress,numeric) RETURNS ipaddress AS 'MODULE_PATHNAME', 'ipaddr_minus_numeric' LANGUAGE C IMMUTABLE STRICT; CREATE OPERATOR - ( LEFTARG = ipaddress, RIGHTARG = bigint, PROCEDURE = ipaddress_minus_bigint ); CREATE OPERATOR - ( LEFTARG = ipaddress, RIGHTARG = integer, PROCEDURE = ipaddress_minus_int ); CREATE OPERATOR - ( LEFTARG = ipaddress, RIGHTARG = numeric, PROCEDURE = ipaddress_minus_numeric ); CREATE FUNCTION ip4_minus_ip4(ip4,ip4) RETURNS bigint AS 'MODULE_PATHNAME', 'ip4_minus_ip4' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip6_minus_ip6(ip6,ip6) RETURNS numeric AS 'MODULE_PATHNAME', 'ip6_minus_ip6' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ipaddress_minus_ipaddress(ipaddress,ipaddress) RETURNS numeric AS 'MODULE_PATHNAME', 'ipaddr_minus_ipaddr' LANGUAGE C IMMUTABLE STRICT; CREATE OPERATOR - ( LEFTARG = ip4, RIGHTARG = ip4, PROCEDURE = ip4_minus_ip4 ); CREATE OPERATOR - ( LEFTARG = ip6, RIGHTARG = ip6, PROCEDURE = ip6_minus_ip6 ); CREATE OPERATOR - ( LEFTARG = ipaddress, RIGHTARG = ipaddress, PROCEDURE = ipaddress_minus_ipaddress ); -- containment predicates: (a >>= b), (a >> b), (a <<= b), (a << b), (a && b) CREATE FUNCTION ip4r_contained_by(ip4r,ip4r) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip6r_contained_by(ip6r,ip6r) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION iprange_contained_by(iprange,iprange) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OPERATOR <<= ( LEFTARG = ip4r, RIGHTARG = ip4r, PROCEDURE = ip4r_contained_by, COMMUTATOR = '>>=', RESTRICT = contsel, JOIN = contjoinsel ); CREATE OPERATOR <<= ( LEFTARG = ip6r, RIGHTARG = ip6r, PROCEDURE = ip6r_contained_by, COMMUTATOR = '>>=', RESTRICT = contsel, JOIN = contjoinsel ); CREATE OPERATOR <<= ( LEFTARG = iprange, RIGHTARG = iprange, PROCEDURE = iprange_contained_by, COMMUTATOR = '>>=', RESTRICT = contsel, JOIN = contjoinsel ); CREATE FUNCTION ip4r_contained_by_strict(ip4r,ip4r) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip6r_contained_by_strict(ip6r,ip6r) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION iprange_contained_by_strict(iprange,iprange) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OPERATOR << ( LEFTARG = ip4r, RIGHTARG = ip4r, PROCEDURE = ip4r_contained_by_strict, COMMUTATOR = '>>', RESTRICT = contsel, JOIN = contjoinsel ); CREATE OPERATOR << ( LEFTARG = ip6r, RIGHTARG = ip6r, PROCEDURE = ip6r_contained_by_strict, COMMUTATOR = '>>', RESTRICT = contsel, JOIN = contjoinsel ); CREATE OPERATOR << ( LEFTARG = iprange, RIGHTARG = iprange, PROCEDURE = iprange_contained_by_strict, COMMUTATOR = '>>', RESTRICT = contsel, JOIN = contjoinsel ); CREATE FUNCTION ip4r_contains(ip4r,ip4r) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip6r_contains(ip6r,ip6r) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION iprange_contains(iprange,iprange) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OPERATOR >>= ( LEFTARG = ip4r, RIGHTARG = ip4r, PROCEDURE = ip4r_contains, COMMUTATOR = '<<=', RESTRICT = contsel, JOIN = contjoinsel ); CREATE OPERATOR >>= ( LEFTARG = ip6r, RIGHTARG = ip6r, PROCEDURE = ip6r_contains, COMMUTATOR = '<<=', RESTRICT = contsel, JOIN = contjoinsel ); CREATE OPERATOR >>= ( LEFTARG = iprange, RIGHTARG = iprange, PROCEDURE = iprange_contains, COMMUTATOR = '<<=', RESTRICT = contsel, JOIN = contjoinsel ); CREATE FUNCTION ip4r_contains_strict(ip4r,ip4r) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip6r_contains_strict(ip6r,ip6r) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION iprange_contains_strict(iprange,iprange) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OPERATOR >> ( LEFTARG = ip4r, RIGHTARG = ip4r, PROCEDURE = ip4r_contains_strict, COMMUTATOR = '<<', RESTRICT = contsel, JOIN = contjoinsel ); CREATE OPERATOR >> ( LEFTARG = ip6r, RIGHTARG = ip6r, PROCEDURE = ip6r_contains_strict, COMMUTATOR = '<<', RESTRICT = contsel, JOIN = contjoinsel ); CREATE OPERATOR >> ( LEFTARG = iprange, RIGHTARG = iprange, PROCEDURE = iprange_contains_strict, COMMUTATOR = '<<', RESTRICT = contsel, JOIN = contjoinsel ); CREATE FUNCTION ip4r_overlaps(ip4r,ip4r) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip6r_overlaps(ip6r,ip6r) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION iprange_overlaps(iprange,iprange) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OPERATOR && ( LEFTARG = ip4r, RIGHTARG = ip4r, PROCEDURE = ip4r_overlaps, COMMUTATOR = '&&', RESTRICT = areasel, JOIN = areajoinsel ); CREATE OPERATOR && ( LEFTARG = ip6r, RIGHTARG = ip6r, PROCEDURE = ip6r_overlaps, COMMUTATOR = '&&', RESTRICT = areasel, JOIN = areajoinsel ); CREATE OPERATOR && ( LEFTARG = iprange, RIGHTARG = iprange, PROCEDURE = iprange_overlaps, COMMUTATOR = '&&', RESTRICT = areasel, JOIN = areajoinsel ); -- cross-type containment -- no operators for these since they seem to do more harm than good. These cases -- are handled by implicit casts instead. CREATE FUNCTION ip4_contained_by(ip4,ip4r) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip4_contained_by(ip4,iprange) RETURNS bool AS 'MODULE_PATHNAME','iprange_ip4_contained_by' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip6_contained_by(ip6,ip6r) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip6_contained_by(ip6,iprange) RETURNS bool AS 'MODULE_PATHNAME','iprange_ip6_contained_by' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ipaddress_contained_by(ipaddress,iprange) RETURNS bool AS 'MODULE_PATHNAME','iprange_ip_contained_by' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip4_contains(ip4r,ip4) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip6_contains(ip6r,ip6) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip4_contains(iprange,ip4) RETURNS bool AS 'MODULE_PATHNAME','iprange_contains_ip4' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip6_contains(iprange,ip6) RETURNS bool AS 'MODULE_PATHNAME','iprange_contains_ip6' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ipaddress_contains(iprange,ipaddress) RETURNS bool AS 'MODULE_PATHNAME','iprange_contains_ip' LANGUAGE C IMMUTABLE STRICT; -- btree (strict weak) ordering operators -- meaning of < > for ip4 and ip6 is obvious. -- for ipaddress, all ip4 addresses are less than all ip6 addresses -- for ip4r/ip6r, the order is lexicographic on (lower,upper) -- for iprange, the universal range is lowest, then all ip4 ranges, then ip6 CREATE FUNCTION ip4_eq(ip4,ip4) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip4r_eq(ip4r,ip4r) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip6_eq(ip6,ip6) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip6r_eq(ip6r,ip6r) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ipaddress_eq(ipaddress,ipaddress) RETURNS bool AS 'MODULE_PATHNAME','ipaddr_eq' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION iprange_eq(iprange,iprange) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OPERATOR = ( LEFTARG = ip4, RIGHTARG = ip4, PROCEDURE = ip4_eq, COMMUTATOR = '=', NEGATOR = '<>', RESTRICT = eqsel, JOIN = eqjoinsel, SORT1 = '<', SORT2 = '<', HASHES ); CREATE OPERATOR = ( LEFTARG = ip4r, RIGHTARG = ip4r, PROCEDURE = ip4r_eq, COMMUTATOR = '=', NEGATOR = '<>', RESTRICT = eqsel, JOIN = eqjoinsel, SORT1 = '<', SORT2 = '<', HASHES ); CREATE OPERATOR = ( LEFTARG = ip6, RIGHTARG = ip6, PROCEDURE = ip6_eq, COMMUTATOR = '=', NEGATOR = '<>', RESTRICT = eqsel, JOIN = eqjoinsel, SORT1 = '<', SORT2 = '<', HASHES ); CREATE OPERATOR = ( LEFTARG = ip6r, RIGHTARG = ip6r, PROCEDURE = ip6r_eq, COMMUTATOR = '=', NEGATOR = '<>', RESTRICT = eqsel, JOIN = eqjoinsel, SORT1 = '<', SORT2 = '<', HASHES ); CREATE OPERATOR = ( LEFTARG = ipaddress, RIGHTARG = ipaddress, PROCEDURE = ipaddress_eq, COMMUTATOR = '=', NEGATOR = '<>', RESTRICT = eqsel, JOIN = eqjoinsel, SORT1 = '<', SORT2 = '<', HASHES ); CREATE OPERATOR = ( LEFTARG = iprange, RIGHTARG = iprange, PROCEDURE = iprange_eq, COMMUTATOR = '=', NEGATOR = '<>', RESTRICT = eqsel, JOIN = eqjoinsel, SORT1 = '<', SORT2 = '<', HASHES ); CREATE FUNCTION ip4_ge(ip4,ip4) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip4r_ge(ip4r,ip4r) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip6_ge(ip6,ip6) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip6r_ge(ip6r,ip6r) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ipaddress_ge(ipaddress,ipaddress) RETURNS bool AS 'MODULE_PATHNAME','ipaddr_ge' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION iprange_ge(iprange,iprange) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OPERATOR >= ( LEFTARG = ip4, RIGHTARG = ip4, PROCEDURE = ip4_ge, COMMUTATOR = '<=', NEGATOR = '<', RESTRICT = scalargtsel, JOIN = scalargtjoinsel ); CREATE OPERATOR >= ( LEFTARG = ip4r, RIGHTARG = ip4r, PROCEDURE = ip4r_ge, COMMUTATOR = '<=', NEGATOR = '<', RESTRICT = scalargtsel, JOIN = scalargtjoinsel ); CREATE OPERATOR >= ( LEFTARG = ip6, RIGHTARG = ip6, PROCEDURE = ip6_ge, COMMUTATOR = '<=', NEGATOR = '<', RESTRICT = scalargtsel, JOIN = scalargtjoinsel ); CREATE OPERATOR >= ( LEFTARG = ip6r, RIGHTARG = ip6r, PROCEDURE = ip6r_ge, COMMUTATOR = '<=', NEGATOR = '<', RESTRICT = scalargtsel, JOIN = scalargtjoinsel ); CREATE OPERATOR >= ( LEFTARG = ipaddress, RIGHTARG = ipaddress, PROCEDURE = ipaddress_ge, COMMUTATOR = '<=', NEGATOR = '<', RESTRICT = scalargtsel, JOIN = scalargtjoinsel ); CREATE OPERATOR >= ( LEFTARG = iprange, RIGHTARG = iprange, PROCEDURE = iprange_ge, COMMUTATOR = '<=', NEGATOR = '<', RESTRICT = scalargtsel, JOIN = scalargtjoinsel ); CREATE FUNCTION ip4_gt(ip4,ip4) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip4r_gt(ip4r,ip4r) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip6_gt(ip6,ip6) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip6r_gt(ip6r,ip6r) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ipaddress_gt(ipaddress,ipaddress) RETURNS bool AS 'MODULE_PATHNAME','ipaddr_gt' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION iprange_gt(iprange,iprange) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OPERATOR > ( LEFTARG = ip4, RIGHTARG = ip4, PROCEDURE = ip4_gt, COMMUTATOR = '<', NEGATOR = '<=', RESTRICT = scalargtsel, JOIN = scalargtjoinsel ); CREATE OPERATOR > ( LEFTARG = ip4r, RIGHTARG = ip4r, PROCEDURE = ip4r_gt, COMMUTATOR = '<', NEGATOR = '<=', RESTRICT = scalargtsel, JOIN = scalargtjoinsel ); CREATE OPERATOR > ( LEFTARG = ip6, RIGHTARG = ip6, PROCEDURE = ip6_gt, COMMUTATOR = '<', NEGATOR = '<=', RESTRICT = scalargtsel, JOIN = scalargtjoinsel ); CREATE OPERATOR > ( LEFTARG = ip6r, RIGHTARG = ip6r, PROCEDURE = ip6r_gt, COMMUTATOR = '<', NEGATOR = '<=', RESTRICT = scalargtsel, JOIN = scalargtjoinsel ); CREATE OPERATOR > ( LEFTARG = ipaddress, RIGHTARG = ipaddress, PROCEDURE = ipaddress_gt, COMMUTATOR = '<', NEGATOR = '<=', RESTRICT = scalargtsel, JOIN = scalargtjoinsel ); CREATE OPERATOR > ( LEFTARG = iprange, RIGHTARG = iprange, PROCEDURE = iprange_gt, COMMUTATOR = '<', NEGATOR = '<=', RESTRICT = scalargtsel, JOIN = scalargtjoinsel ); CREATE FUNCTION ip4_le(ip4,ip4) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip4r_le(ip4r,ip4r) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip6_le(ip6,ip6) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip6r_le(ip6r,ip6r) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ipaddress_le(ipaddress,ipaddress) RETURNS bool AS 'MODULE_PATHNAME','ipaddr_le' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION iprange_le(iprange,iprange) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OPERATOR <= ( LEFTARG = ip4, RIGHTARG = ip4, PROCEDURE = ip4_le, COMMUTATOR = '>=', NEGATOR = '>', RESTRICT = scalarltsel, JOIN = scalarltjoinsel ); CREATE OPERATOR <= ( LEFTARG = ip4r, RIGHTARG = ip4r, PROCEDURE = ip4r_le, COMMUTATOR = '>=', NEGATOR = '>', RESTRICT = scalarltsel, JOIN = scalarltjoinsel ); CREATE OPERATOR <= ( LEFTARG = ip6, RIGHTARG = ip6, PROCEDURE = ip6_le, COMMUTATOR = '>=', NEGATOR = '>', RESTRICT = scalarltsel, JOIN = scalarltjoinsel ); CREATE OPERATOR <= ( LEFTARG = ip6r, RIGHTARG = ip6r, PROCEDURE = ip6r_le, COMMUTATOR = '>=', NEGATOR = '>', RESTRICT = scalarltsel, JOIN = scalarltjoinsel ); CREATE OPERATOR <= ( LEFTARG = ipaddress, RIGHTARG = ipaddress, PROCEDURE = ipaddress_le, COMMUTATOR = '>=', NEGATOR = '>', RESTRICT = scalarltsel, JOIN = scalarltjoinsel ); CREATE OPERATOR <= ( LEFTARG = iprange, RIGHTARG = iprange, PROCEDURE = iprange_le, COMMUTATOR = '>=', NEGATOR = '>', RESTRICT = scalarltsel, JOIN = scalarltjoinsel ); CREATE FUNCTION ip4_lt(ip4,ip4) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip4r_lt(ip4r,ip4r) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip6_lt(ip6,ip6) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip6r_lt(ip6r,ip6r) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ipaddress_lt(ipaddress,ipaddress) RETURNS bool AS 'MODULE_PATHNAME','ipaddr_lt' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION iprange_lt(iprange,iprange) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OPERATOR < ( LEFTARG = ip4, RIGHTARG = ip4, PROCEDURE = ip4_lt, COMMUTATOR = '>', NEGATOR = '>=', RESTRICT = scalarltsel, JOIN = scalarltjoinsel ); CREATE OPERATOR < ( LEFTARG = ip4r, RIGHTARG = ip4r, PROCEDURE = ip4r_lt, COMMUTATOR = '>', NEGATOR = '>=', RESTRICT = scalarltsel, JOIN = scalarltjoinsel ); CREATE OPERATOR < ( LEFTARG = ip6, RIGHTARG = ip6, PROCEDURE = ip6_lt, COMMUTATOR = '>', NEGATOR = '>=', RESTRICT = scalarltsel, JOIN = scalarltjoinsel ); CREATE OPERATOR < ( LEFTARG = ip6r, RIGHTARG = ip6r, PROCEDURE = ip6r_lt, COMMUTATOR = '>', NEGATOR = '>=', RESTRICT = scalarltsel, JOIN = scalarltjoinsel ); CREATE OPERATOR < ( LEFTARG = ipaddress, RIGHTARG = ipaddress, PROCEDURE = ipaddress_lt, COMMUTATOR = '>', NEGATOR = '>=', RESTRICT = scalarltsel, JOIN = scalarltjoinsel ); CREATE OPERATOR < ( LEFTARG = iprange, RIGHTARG = iprange, PROCEDURE = iprange_lt, COMMUTATOR = '>', NEGATOR = '>=', RESTRICT = scalarltsel, JOIN = scalarltjoinsel ); CREATE FUNCTION ip4_neq(ip4,ip4) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip4r_neq(ip4r,ip4r) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip6_neq(ip6,ip6) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip6r_neq(ip6r,ip6r) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ipaddress_neq(ipaddress,ipaddress) RETURNS bool AS 'MODULE_PATHNAME','ipaddr_neq' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION iprange_neq(iprange,iprange) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OPERATOR <> ( LEFTARG = ip4, RIGHTARG = ip4, PROCEDURE = ip4_neq, COMMUTATOR = '<>', NEGATOR = '=', RESTRICT = neqsel, JOIN = neqjoinsel ); CREATE OPERATOR <> ( LEFTARG = ip4r, RIGHTARG = ip4r, PROCEDURE = ip4r_neq, COMMUTATOR = '<>', NEGATOR = '=', RESTRICT = neqsel, JOIN = neqjoinsel ); CREATE OPERATOR <> ( LEFTARG = ip6, RIGHTARG = ip6, PROCEDURE = ip6_neq, COMMUTATOR = '<>', NEGATOR = '=', RESTRICT = neqsel, JOIN = neqjoinsel ); CREATE OPERATOR <> ( LEFTARG = ip6r, RIGHTARG = ip6r, PROCEDURE = ip6r_neq, COMMUTATOR = '<>', NEGATOR = '=', RESTRICT = neqsel, JOIN = neqjoinsel ); CREATE OPERATOR <> ( LEFTARG = ipaddress, RIGHTARG = ipaddress, PROCEDURE = ipaddress_neq, COMMUTATOR = '<>', NEGATOR = '=', RESTRICT = neqsel, JOIN = neqjoinsel ); CREATE OPERATOR <> ( LEFTARG = iprange, RIGHTARG = iprange, PROCEDURE = iprange_neq, COMMUTATOR = '<>', NEGATOR = '=', RESTRICT = neqsel, JOIN = neqjoinsel ); -- ---------------------------------------------------------------------- -- Btree index CREATE FUNCTION ip4_cmp(ip4,ip4) RETURNS integer AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip4r_cmp(ip4r,ip4r) RETURNS integer AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip6_cmp(ip6,ip6) RETURNS integer AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip6r_cmp(ip6r,ip6r) RETURNS integer AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ipaddress_cmp(ipaddress,ipaddress) RETURNS integer AS 'MODULE_PATHNAME','ipaddr_cmp' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION iprange_cmp(iprange,iprange) RETURNS integer AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OPERATOR CLASS btree_ip4_ops DEFAULT FOR TYPE ip4 USING btree AS OPERATOR 1 < , OPERATOR 2 <= , OPERATOR 3 = , OPERATOR 4 >= , OPERATOR 5 > , FUNCTION 1 ip4_cmp(ip4, ip4); CREATE OPERATOR CLASS btree_ip4r_ops DEFAULT FOR TYPE ip4r USING btree AS OPERATOR 1 < , OPERATOR 2 <= , OPERATOR 3 = , OPERATOR 4 >= , OPERATOR 5 > , FUNCTION 1 ip4r_cmp(ip4r, ip4r); CREATE OPERATOR CLASS btree_ip6_ops DEFAULT FOR TYPE ip6 USING btree AS OPERATOR 1 < , OPERATOR 2 <= , OPERATOR 3 = , OPERATOR 4 >= , OPERATOR 5 > , FUNCTION 1 ip6_cmp(ip6, ip6); CREATE OPERATOR CLASS btree_ip6r_ops DEFAULT FOR TYPE ip6r USING btree AS OPERATOR 1 < , OPERATOR 2 <= , OPERATOR 3 = , OPERATOR 4 >= , OPERATOR 5 > , FUNCTION 1 ip6r_cmp(ip6r, ip6r); CREATE OPERATOR CLASS btree_ipaddress_ops DEFAULT FOR TYPE ipaddress USING btree AS OPERATOR 1 < , OPERATOR 2 <= , OPERATOR 3 = , OPERATOR 4 >= , OPERATOR 5 > , FUNCTION 1 ipaddress_cmp(ipaddress, ipaddress); CREATE OPERATOR CLASS btree_iprange_ops DEFAULT FOR TYPE iprange USING btree AS OPERATOR 1 < , OPERATOR 2 <= , OPERATOR 3 = , OPERATOR 4 >= , OPERATOR 5 > , FUNCTION 1 iprange_cmp(iprange, iprange); -- ---------------------------------------------------------------------- -- Hash index -- the hash index definitions are needed for hashagg, hashjoin, hash-distinct, hashsetop -- etc. even if no actual hash indexes are used. CREATE FUNCTION ip4hash(ip4) RETURNS integer AS 'MODULE_PATHNAME', 'ip4hash' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip6hash(ip6) RETURNS integer AS 'MODULE_PATHNAME', 'ip6hash' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ipaddresshash(ipaddress) RETURNS integer AS 'MODULE_PATHNAME', 'ipaddr_hash' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip4rhash(ip4r) RETURNS integer AS 'MODULE_PATHNAME', 'ip4rhash' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION ip6rhash(ip6r) RETURNS integer AS 'MODULE_PATHNAME', 'ip6rhash' LANGUAGE C IMMUTABLE STRICT; CREATE FUNCTION iprangehash(iprange) RETURNS integer AS 'MODULE_PATHNAME', 'iprange_hash' LANGUAGE C IMMUTABLE STRICT; CREATE OPERATOR CLASS hash_ip4_ops DEFAULT FOR TYPE ip4 USING hash AS OPERATOR 1 = , FUNCTION 1 ip4hash(ip4); CREATE OPERATOR CLASS hash_ip4r_ops DEFAULT FOR TYPE ip4r USING hash AS OPERATOR 1 = , FUNCTION 1 ip4rhash(ip4r); CREATE OPERATOR CLASS hash_ip6_ops DEFAULT FOR TYPE ip6 USING hash AS OPERATOR 1 = , FUNCTION 1 ip6hash(ip6); CREATE OPERATOR CLASS hash_ip6r_ops DEFAULT FOR TYPE ip6r USING hash AS OPERATOR 1 = , FUNCTION 1 ip6rhash(ip6r); CREATE OPERATOR CLASS hash_ipaddress_ops DEFAULT FOR TYPE ipaddress USING hash AS OPERATOR 1 = , FUNCTION 1 ipaddresshash(ipaddress); CREATE OPERATOR CLASS hash_iprange_ops DEFAULT FOR TYPE iprange USING hash AS OPERATOR 1 = , FUNCTION 1 iprangehash(iprange); -- ---------------------------------------------------------------------- -- GiST -- these type declarations are actually wrong for 8.4+ (which added -- more args to consistent) but we ignore that because the access -- method code doesn't actually look at the function declaration, and -- the differences are handled in the C code. Having the SQL -- definition changing is just too much of a pain. CREATE FUNCTION gip4r_consistent(internal,ip4r,int4) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C; CREATE FUNCTION gip4r_compress(internal) RETURNS internal AS 'MODULE_PATHNAME' LANGUAGE C; CREATE FUNCTION gip4r_decompress(internal) RETURNS internal AS 'MODULE_PATHNAME' LANGUAGE C; CREATE FUNCTION gip4r_penalty(internal,internal,internal) RETURNS internal AS 'MODULE_PATHNAME' LANGUAGE C STRICT; CREATE FUNCTION gip4r_picksplit(internal, internal) RETURNS internal AS 'MODULE_PATHNAME' LANGUAGE C; CREATE FUNCTION gip4r_union(internal, internal) RETURNS ip4r AS 'MODULE_PATHNAME' LANGUAGE C; CREATE FUNCTION gip4r_same(ip4r, ip4r, internal) RETURNS internal AS 'MODULE_PATHNAME' LANGUAGE C; CREATE FUNCTION gip6r_consistent(internal,ip6r,int4) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C; CREATE FUNCTION gip6r_compress(internal) RETURNS internal AS 'MODULE_PATHNAME' LANGUAGE C; CREATE FUNCTION gip6r_decompress(internal) RETURNS internal AS 'MODULE_PATHNAME' LANGUAGE C; CREATE FUNCTION gip6r_penalty(internal,internal,internal) RETURNS internal AS 'MODULE_PATHNAME' LANGUAGE C STRICT; CREATE FUNCTION gip6r_picksplit(internal, internal) RETURNS internal AS 'MODULE_PATHNAME' LANGUAGE C; CREATE FUNCTION gip6r_union(internal, internal) RETURNS ip6r AS 'MODULE_PATHNAME' LANGUAGE C; CREATE FUNCTION gip6r_same(ip6r, ip6r, internal) RETURNS internal AS 'MODULE_PATHNAME' LANGUAGE C; CREATE FUNCTION gipr_consistent(internal,iprange,int4) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C; CREATE FUNCTION gipr_compress(internal) RETURNS internal AS 'MODULE_PATHNAME' LANGUAGE C; CREATE FUNCTION gipr_decompress(internal) RETURNS internal AS 'MODULE_PATHNAME' LANGUAGE C; CREATE FUNCTION gipr_penalty(internal,internal,internal) RETURNS internal AS 'MODULE_PATHNAME' LANGUAGE C STRICT; CREATE FUNCTION gipr_picksplit(internal, internal) RETURNS internal AS 'MODULE_PATHNAME' LANGUAGE C; CREATE FUNCTION gipr_union(internal, internal) RETURNS iprange AS 'MODULE_PATHNAME' LANGUAGE C; CREATE FUNCTION gipr_same(iprange, iprange, internal) RETURNS internal AS 'MODULE_PATHNAME' LANGUAGE C; CREATE OPERATOR CLASS gist_ip4r_ops DEFAULT FOR TYPE ip4r USING gist AS OPERATOR 1 >>= , OPERATOR 2 <<= , OPERATOR 3 >> , OPERATOR 4 << , OPERATOR 5 && , OPERATOR 6 = , FUNCTION 1 gip4r_consistent (internal, ip4r, int4), FUNCTION 2 gip4r_union (internal, internal), FUNCTION 3 gip4r_compress (internal), FUNCTION 4 gip4r_decompress (internal), FUNCTION 5 gip4r_penalty (internal, internal, internal), FUNCTION 6 gip4r_picksplit (internal, internal), FUNCTION 7 gip4r_same (ip4r, ip4r, internal); CREATE OPERATOR CLASS gist_ip6r_ops DEFAULT FOR TYPE ip6r USING gist AS OPERATOR 1 >>= , OPERATOR 2 <<= , OPERATOR 3 >> , OPERATOR 4 << , OPERATOR 5 && , OPERATOR 6 = , FUNCTION 1 gip6r_consistent (internal, ip6r, int4), FUNCTION 2 gip6r_union (internal, internal), FUNCTION 3 gip6r_compress (internal), FUNCTION 4 gip6r_decompress (internal), FUNCTION 5 gip6r_penalty (internal, internal, internal), FUNCTION 6 gip6r_picksplit (internal, internal), FUNCTION 7 gip6r_same (ip6r, ip6r, internal); CREATE OPERATOR CLASS gist_iprange_ops DEFAULT FOR TYPE iprange USING gist AS OPERATOR 1 >>= , OPERATOR 2 <<= , OPERATOR 3 >> , OPERATOR 4 << , OPERATOR 5 && , OPERATOR 6 = , FUNCTION 1 gipr_consistent (internal, iprange, int4), FUNCTION 2 gipr_union (internal, internal), FUNCTION 3 gipr_compress (internal), FUNCTION 4 gipr_decompress (internal), FUNCTION 5 gipr_penalty (internal, internal, internal), FUNCTION 6 gipr_picksplit (internal, internal), FUNCTION 7 gipr_same (iprange, iprange, internal); -- end ip4r-2.0.2/ip4r--unpackaged1--2.0.sql000066400000000000000000001455211233620317400166110ustar00rootroot00000000000000-- ip4r extension -- complain if script is sourced in psql, rather than via CREATE EXTENSION \echo Use "CREATE EXTENSION ip4r" to load this file. \quit -- ---------------------------------------------------------------------- -- Type definitions --CREATE TYPE ip4; CREATE OR REPLACE FUNCTION ip4_in(cstring) RETURNS ip4 AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip4_out(ip4) RETURNS cstring AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip4_recv(internal) RETURNS ip4 AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip4_send(ip4) RETURNS bytea AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; /* CREATE TYPE ip4 ( INPUT = ip4_in, OUTPUT = ip4_out, RECEIVE = ip4_recv, SEND = ip4_send, INTERNALLENGTH = 4, ALIGNMENT = int4, PASSEDBYVALUE ); */ ALTER EXTENSION ip4r ADD TYPE ip4; COMMENT ON TYPE ip4 IS 'IPv4 address ''#.#.#.#'''; --CREATE TYPE ip4r; CREATE OR REPLACE FUNCTION ip4r_in(cstring) RETURNS ip4r AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip4r_out(ip4r) RETURNS cstring AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip4r_recv(internal) RETURNS ip4r AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip4r_send(ip4r) RETURNS bytea AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; /* CREATE TYPE ip4r ( INPUT = ip4r_in, OUTPUT = ip4r_out, RECEIVE = ip4r_recv, SEND = ip4r_send, INTERNALLENGTH = 8, ALIGNMENT = int4 ); */ ALTER EXTENSION ip4r ADD TYPE ip4r; COMMENT ON TYPE ip4r IS 'IPv4 range ''#.#.#.#-#.#.#.#'' or ''#.#.#.#/#'' or ''#.#.#.#'''; CREATE TYPE ip6; CREATE OR REPLACE FUNCTION ip6_in(cstring) RETURNS ip6 AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip6_out(ip6) RETURNS cstring AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip6_recv(internal) RETURNS ip6 AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip6_send(ip6) RETURNS bytea AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE TYPE ip6 ( INPUT = ip6_in, OUTPUT = ip6_out, RECEIVE = ip6_recv, SEND = ip6_send, INTERNALLENGTH = 16, ALIGNMENT = double ); COMMENT ON TYPE ip6 IS 'IPv6 address ''xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx'''; CREATE TYPE ip6r; CREATE OR REPLACE FUNCTION ip6r_in(cstring) RETURNS ip6r AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip6r_out(ip6r) RETURNS cstring AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip6r_recv(internal) RETURNS ip6r AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip6r_send(ip6r) RETURNS bytea AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE TYPE ip6r ( INPUT = ip6r_in, OUTPUT = ip6r_out, RECEIVE = ip6r_recv, SEND = ip6r_send, INTERNALLENGTH = 32, ALIGNMENT = double ); COMMENT ON TYPE ip6r IS 'IPv6 range ''#-#'' or ''#/#'' or ''#'''; CREATE TYPE ipaddress; CREATE OR REPLACE FUNCTION ipaddress_in(cstring) RETURNS ipaddress AS 'MODULE_PATHNAME','ipaddr_in' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ipaddress_out(ipaddress) RETURNS cstring AS 'MODULE_PATHNAME','ipaddr_out' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ipaddress_recv(internal) RETURNS ipaddress AS 'MODULE_PATHNAME','ipaddr_recv' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ipaddress_send(ipaddress) RETURNS bytea AS 'MODULE_PATHNAME','ipaddr_send' LANGUAGE C IMMUTABLE STRICT; CREATE TYPE ipaddress ( INPUT = ipaddress_in, OUTPUT = ipaddress_out, RECEIVE = ipaddress_recv, SEND = ipaddress_send, INTERNALLENGTH = VARIABLE, ALIGNMENT = int4, STORAGE = main ); COMMENT ON TYPE ipaddress IS 'IPv4 or IPv6 address'; CREATE TYPE iprange; CREATE OR REPLACE FUNCTION iprange_in(cstring) RETURNS iprange AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION iprange_out(iprange) RETURNS cstring AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION iprange_recv(internal) RETURNS iprange AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION iprange_send(iprange) RETURNS bytea AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE TYPE iprange ( INPUT = iprange_in, OUTPUT = iprange_out, RECEIVE = iprange_recv, SEND = iprange_send, INTERNALLENGTH = VARIABLE, ALIGNMENT = int4, STORAGE = main ); COMMENT ON TYPE iprange IS 'IPv4 or IPv6 range'; -- ---------------------------------------------------------------------- -- Cast functions (inward) CREATE OR REPLACE FUNCTION ip4(bigint) RETURNS ip4 AS 'MODULE_PATHNAME','ip4_cast_from_bigint' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip4(double precision) RETURNS ip4 AS 'MODULE_PATHNAME','ip4_cast_from_double' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip4(numeric) RETURNS ip4 AS 'MODULE_PATHNAME','ip4_cast_from_numeric' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip4(inet) RETURNS ip4 AS 'MODULE_PATHNAME','ip4_cast_from_inet' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip4(text) RETURNS ip4 AS 'MODULE_PATHNAME','ip4_cast_from_text' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip4(ipaddress) RETURNS ip4 AS 'MODULE_PATHNAME','ipaddr_cast_to_ip4' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip6(numeric) RETURNS ip6 AS 'MODULE_PATHNAME','ip6_cast_from_numeric' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip6(inet) RETURNS ip6 AS 'MODULE_PATHNAME','ip6_cast_from_inet' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip6(text) RETURNS ip6 AS 'MODULE_PATHNAME','ip6_cast_from_text' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip6(ipaddress) RETURNS ip6 AS 'MODULE_PATHNAME','ipaddr_cast_to_ip6' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ipaddress(inet) RETURNS ipaddress AS 'MODULE_PATHNAME','ipaddr_cast_from_inet' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ipaddress(ip4) RETURNS ipaddress AS 'MODULE_PATHNAME','ipaddr_cast_from_ip4' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ipaddress(ip6) RETURNS ipaddress AS 'MODULE_PATHNAME','ipaddr_cast_from_ip6' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ipaddress(text) RETURNS ipaddress AS 'MODULE_PATHNAME','ipaddr_cast_from_text' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip4r(cidr) RETURNS ip4r AS 'MODULE_PATHNAME','ip4r_cast_from_cidr' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip4r(ip4) RETURNS ip4r AS 'MODULE_PATHNAME','ip4r_cast_from_ip4' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip4r(text) RETURNS ip4r AS 'MODULE_PATHNAME','ip4r_cast_from_text' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip4r(iprange) RETURNS ip4r AS 'MODULE_PATHNAME','iprange_cast_to_ip4r' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip6r(cidr) RETURNS ip6r AS 'MODULE_PATHNAME','ip6r_cast_from_cidr' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip6r(ip6) RETURNS ip6r AS 'MODULE_PATHNAME','ip6r_cast_from_ip6' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip6r(text) RETURNS ip6r AS 'MODULE_PATHNAME','ip6r_cast_from_text' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip6r(iprange) RETURNS ip6r AS 'MODULE_PATHNAME','iprange_cast_to_ip6r' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION iprange(cidr) RETURNS iprange AS 'MODULE_PATHNAME','iprange_cast_from_cidr' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION iprange(ip4) RETURNS iprange AS 'MODULE_PATHNAME','iprange_cast_from_ip4' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION iprange(ip6) RETURNS iprange AS 'MODULE_PATHNAME','iprange_cast_from_ip6' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION iprange(ip4r) RETURNS iprange AS 'MODULE_PATHNAME','iprange_cast_from_ip4r' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION iprange(ip6r) RETURNS iprange AS 'MODULE_PATHNAME','iprange_cast_from_ip6r' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION iprange(ipaddress) RETURNS iprange AS 'MODULE_PATHNAME','iprange_cast_from_ipaddr' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION iprange(text) RETURNS iprange AS 'MODULE_PATHNAME','iprange_cast_from_text' LANGUAGE C IMMUTABLE STRICT; -- ---------------------------------------------------------------------- -- Cast functions (outward) CREATE OR REPLACE FUNCTION cidr(ip4) RETURNS cidr AS 'MODULE_PATHNAME','ip4_cast_to_cidr' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION cidr(ip4r) RETURNS cidr AS 'MODULE_PATHNAME','ip4r_cast_to_cidr' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION cidr(ip6) RETURNS cidr AS 'MODULE_PATHNAME','ip6_cast_to_cidr' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION cidr(ip6r) RETURNS cidr AS 'MODULE_PATHNAME','ip6r_cast_to_cidr' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION cidr(ipaddress) RETURNS cidr AS 'MODULE_PATHNAME','ipaddr_cast_to_cidr' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION cidr(iprange) RETURNS cidr AS 'MODULE_PATHNAME','iprange_cast_to_cidr' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION text(ip4) RETURNS text AS 'MODULE_PATHNAME','ip4_cast_to_text' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION text(ip4r) RETURNS text AS 'MODULE_PATHNAME','ip4r_cast_to_text' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION text(ip6) RETURNS text AS 'MODULE_PATHNAME','ip6_cast_to_text' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION text(ip6r) RETURNS text AS 'MODULE_PATHNAME','ip6r_cast_to_text' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION text(ipaddress) RETURNS text AS 'MODULE_PATHNAME','ipaddr_cast_to_text' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION text(iprange) RETURNS text AS 'MODULE_PATHNAME','iprange_cast_to_text' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION to_bigint(ip4) RETURNS bigint AS 'MODULE_PATHNAME','ip4_cast_to_bigint' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION to_double(ip4) RETURNS double precision AS 'MODULE_PATHNAME','ip4_cast_to_double' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION to_numeric(ip4) RETURNS numeric AS 'MODULE_PATHNAME','ip4_cast_to_numeric' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION to_numeric(ip6) RETURNS numeric AS 'MODULE_PATHNAME','ip6_cast_to_numeric' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION to_numeric(ipaddress) RETURNS numeric AS 'MODULE_PATHNAME','ipaddr_cast_to_numeric' LANGUAGE C IMMUTABLE STRICT; -- ---------------------------------------------------------------------- -- Cast definitions (outward) -- all these are explicit, with the exception of casts from single-address -- types to "cidr", which we make assignment casts since they are lossless -- and preserve general semantics. ALTER EXTENSION ip4r ADD CAST (ip4 as bigint); ALTER EXTENSION ip4r ADD CAST (ip4 as double precision); CREATE CAST (ip4 as numeric) WITH FUNCTION to_numeric(ip4); ALTER EXTENSION ip4r ADD CAST (ip4 as text); ALTER EXTENSION ip4r ADD CAST (ip4 as cidr); ALTER EXTENSION ip4r ADD CAST (ip4r as cidr); ALTER EXTENSION ip4r ADD CAST (ip4r as text); CREATE CAST (ip6 as numeric) WITH FUNCTION to_numeric(ip6); CREATE CAST (ip6 as text) WITH FUNCTION text(ip6); CREATE CAST (ip6 as cidr) WITH FUNCTION cidr(ip6) AS ASSIGNMENT; CREATE CAST (ip6r as cidr) WITH FUNCTION cidr(ip6r); CREATE CAST (ip6r as text) WITH FUNCTION text(ip6r); CREATE CAST (ipaddress as numeric) WITH FUNCTION to_numeric(ipaddress); CREATE CAST (ipaddress as text) WITH FUNCTION text(ipaddress); CREATE CAST (ipaddress as cidr) WITH FUNCTION cidr(ipaddress) AS ASSIGNMENT; CREATE CAST (iprange as cidr) WITH FUNCTION cidr(iprange); CREATE CAST (iprange as text) WITH FUNCTION text(iprange); -- ---------------------------------------------------------------------- -- Cast definitions (inward) -- these are explicit except for casts from inet/cidr types. Even though -- such casts are lossy for inet, since the masklen isn't preserved, the -- semantics and common usage are enough to justify an assignment cast. ALTER EXTENSION ip4r ADD CAST (text as ip4); ALTER EXTENSION ip4r ADD CAST (text as ip4r); CREATE CAST (text as ip6) WITH FUNCTION ip6(text); CREATE CAST (text as ip6r) WITH FUNCTION ip6r(text); CREATE CAST (text as ipaddress) WITH FUNCTION ipaddress(text); CREATE CAST (text as iprange) WITH FUNCTION iprange(text); ALTER EXTENSION ip4r ADD CAST (bigint as ip4); ALTER EXTENSION ip4r ADD CAST (double precision as ip4); CREATE CAST (numeric as ip4) WITH FUNCTION ip4(numeric); CREATE CAST (numeric as ip6) WITH FUNCTION ip6(numeric); ALTER EXTENSION ip4r ADD CAST (cidr as ip4r); CREATE CAST (cidr as ip6r) WITH FUNCTION ip6r(cidr) AS ASSIGNMENT; CREATE CAST (cidr as iprange) WITH FUNCTION iprange(cidr) AS ASSIGNMENT; ALTER EXTENSION ip4r ADD CAST (inet as ip4); CREATE CAST (inet as ip6) WITH FUNCTION ip6(inet) AS ASSIGNMENT; CREATE CAST (inet as ipaddress) WITH FUNCTION ipaddress(inet) AS ASSIGNMENT; -- ---------------------------------------------------------------------- -- Cast definitions (cross-type) -- the lossless "upward" casts are made implict. ALTER EXTENSION ip4r ADD CAST (ip4 as ip4r); CREATE CAST (ip4 as ipaddress) WITH FUNCTION ipaddress(ip4) AS IMPLICIT; CREATE CAST (ip4 as iprange) WITH FUNCTION iprange(ip4) AS IMPLICIT; CREATE CAST (ip4r as iprange) WITH FUNCTION iprange(ip4r) AS IMPLICIT; CREATE CAST (ip6 as ip6r) WITH FUNCTION ip6r(ip6) AS IMPLICIT; CREATE CAST (ip6 as ipaddress) WITH FUNCTION ipaddress(ip6) AS IMPLICIT; CREATE CAST (ip6 as iprange) WITH FUNCTION iprange(ip6) AS IMPLICIT; CREATE CAST (ip6r as iprange) WITH FUNCTION iprange(ip6r) AS IMPLICIT; CREATE CAST (ipaddress as iprange) WITH FUNCTION iprange(ipaddress) AS IMPLICIT; CREATE CAST (ipaddress as ip4) WITH FUNCTION ip4(ipaddress); CREATE CAST (ipaddress as ip6) WITH FUNCTION ip6(ipaddress); CREATE CAST (iprange as ip4r) WITH FUNCTION ip4r(iprange); CREATE CAST (iprange as ip6r) WITH FUNCTION ip6r(iprange); -- ---------------------------------------------------------------------- -- Constructor functions CREATE OR REPLACE FUNCTION ip4r(ip4,ip4) RETURNS ip4r AS 'MODULE_PATHNAME', 'ip4r_from_ip4s' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip6r(ip6,ip6) RETURNS ip6r AS 'MODULE_PATHNAME', 'ip6r_from_ip6s' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION iprange(ip4,ip4) RETURNS iprange AS 'MODULE_PATHNAME', 'iprange_from_ip4s' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION iprange(ip6,ip6) RETURNS iprange AS 'MODULE_PATHNAME', 'iprange_from_ip6s' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION iprange(ipaddress,ipaddress) RETURNS iprange AS 'MODULE_PATHNAME', 'iprange_from_ipaddrs' LANGUAGE C IMMUTABLE STRICT; -- ---------------------------------------------------------------------- -- Utility functions (no operator equivalent) CREATE OR REPLACE FUNCTION family(ip4) RETURNS integer AS $f$ select 4; $f$ LANGUAGE SQL IMMUTABLE; CREATE OR REPLACE FUNCTION family(ip4r) RETURNS integer AS $f$ select 4; $f$ LANGUAGE SQL IMMUTABLE; CREATE OR REPLACE FUNCTION family(ip6) RETURNS integer AS $f$ select 6; $f$ LANGUAGE SQL IMMUTABLE; CREATE OR REPLACE FUNCTION family(ip6r) RETURNS integer AS $f$ select 6; $f$ LANGUAGE SQL IMMUTABLE; CREATE OR REPLACE FUNCTION family(ipaddress) RETURNS integer AS 'MODULE_PATHNAME', 'ipaddr_family' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION family(iprange) RETURNS integer AS 'MODULE_PATHNAME', 'iprange_family' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip4_netmask(integer) RETURNS ip4 AS 'MODULE_PATHNAME', 'ip4_netmask' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip6_netmask(integer) RETURNS ip6 AS 'MODULE_PATHNAME', 'ip6_netmask' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION is_cidr(ip4r) RETURNS boolean AS 'MODULE_PATHNAME', 'ip4r_is_cidr' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION is_cidr(ip6r) RETURNS boolean AS 'MODULE_PATHNAME', 'ip6r_is_cidr' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION is_cidr(iprange) RETURNS boolean AS 'MODULE_PATHNAME', 'iprange_is_cidr' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION masklen(ip4r) RETURNS integer AS 'MODULE_PATHNAME','ip4r_prefixlen' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION masklen(ip6r) RETURNS integer AS 'MODULE_PATHNAME','ip6r_prefixlen' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION masklen(iprange) RETURNS integer AS 'MODULE_PATHNAME','iprange_prefixlen' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION lower(ip4r) RETURNS ip4 AS 'MODULE_PATHNAME', 'ip4r_lower' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION lower(ip6r) RETURNS ip6 AS 'MODULE_PATHNAME', 'ip6r_lower' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION lower(iprange) RETURNS ipaddress AS 'MODULE_PATHNAME', 'iprange_lower' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION upper(ip4r) RETURNS ip4 AS 'MODULE_PATHNAME', 'ip4r_upper' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION upper(ip6r) RETURNS ip6 AS 'MODULE_PATHNAME', 'ip6r_upper' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION upper(iprange) RETURNS ipaddress AS 'MODULE_PATHNAME', 'iprange_upper' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip4_net_lower(ip4,integer) RETURNS ip4 AS 'MODULE_PATHNAME', 'ip4_net_lower' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip6_net_lower(ip6,integer) RETURNS ip6 AS 'MODULE_PATHNAME', 'ip6_net_lower' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ipaddress_net_lower(ipaddress,integer) RETURNS ipaddress AS 'MODULE_PATHNAME', 'ipaddr_net_lower' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip4_net_upper(ip4,integer) RETURNS ip4 AS 'MODULE_PATHNAME', 'ip4_net_upper' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip6_net_upper(ip6,integer) RETURNS ip6 AS 'MODULE_PATHNAME', 'ip6_net_upper' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ipaddress_net_upper(ipaddress,integer) RETURNS ipaddress AS 'MODULE_PATHNAME', 'ipaddr_net_upper' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip4r_union(ip4r, ip4r) RETURNS ip4r AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip6r_union(ip6r, ip6r) RETURNS ip6r AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION iprange_union(iprange, iprange) RETURNS iprange AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip4r_inter(ip4r,ip4r) RETURNS ip4r AS 'MODULE_PATHNAME','ip4r_inter' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip6r_inter(ip6r,ip6r) RETURNS ip6r AS 'MODULE_PATHNAME','ip6r_inter' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION iprange_inter(iprange,iprange) RETURNS iprange AS 'MODULE_PATHNAME','iprange_inter' LANGUAGE C IMMUTABLE STRICT; -- ---------------------------------------------------------------------- -- Functions with operator equivalents -- it's intended that either the function form or the operator form be used, -- as desired. -- (ip / len) or (ip / mask) CREATE OR REPLACE FUNCTION ip4r_net_mask(ip4,ip4) RETURNS ip4r AS 'MODULE_PATHNAME','ip4r_net_mask' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip6r_net_mask(ip6,ip6) RETURNS ip6r AS 'MODULE_PATHNAME','ip6r_net_mask' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION iprange_net_mask(ip4,ip4) RETURNS iprange AS 'MODULE_PATHNAME','iprange_net_mask_ip4' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION iprange_net_mask(ip6,ip6) RETURNS iprange AS 'MODULE_PATHNAME','iprange_net_mask_ip6' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION iprange_net_mask(ipaddress,ipaddress) RETURNS iprange AS 'MODULE_PATHNAME','iprange_net_mask' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip4r_net_prefix(ip4,integer) RETURNS ip4r AS 'MODULE_PATHNAME','ip4r_net_prefix' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip6r_net_prefix(ip6,integer) RETURNS ip6r AS 'MODULE_PATHNAME','ip6r_net_prefix' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION iprange_net_prefix(ip4,integer) RETURNS iprange AS 'MODULE_PATHNAME','iprange_net_prefix_ip4' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION iprange_net_prefix(ip6,integer) RETURNS iprange AS 'MODULE_PATHNAME','iprange_net_prefix_ip6' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION iprange_net_prefix(ipaddress,integer) RETURNS iprange AS 'MODULE_PATHNAME','iprange_net_prefix' LANGUAGE C IMMUTABLE STRICT; CREATE OPERATOR / ( LEFTARG = ip4, RIGHTARG = ip4, PROCEDURE = ip4r_net_mask ); CREATE OPERATOR / ( LEFTARG = ip6, RIGHTARG = ip6, PROCEDURE = ip6r_net_mask ); CREATE OPERATOR / ( LEFTARG = ipaddress, RIGHTARG = ipaddress, PROCEDURE = iprange_net_mask ); CREATE OPERATOR / ( LEFTARG = ip4, RIGHTARG = integer, PROCEDURE = ip4r_net_prefix ); CREATE OPERATOR / ( LEFTARG = ip6, RIGHTARG = integer, PROCEDURE = ip6r_net_prefix ); CREATE OPERATOR / ( LEFTARG = ipaddress, RIGHTARG = integer, PROCEDURE = iprange_net_prefix ); -- @ ipr (approximate size) or @@ ipr (exact size) CREATE OR REPLACE FUNCTION ip4r_size(ip4r) RETURNS double precision AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip6r_size(ip6r) RETURNS double precision AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION iprange_size(iprange) RETURNS double precision AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip4r_size_exact(ip4r) RETURNS numeric AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip6r_size_exact(ip6r) RETURNS numeric AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION iprange_size_exact(iprange) RETURNS numeric AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OPERATOR @ ( RIGHTARG = ip4r, PROCEDURE = ip4r_size ); CREATE OPERATOR @ ( RIGHTARG = ip6r, PROCEDURE = ip6r_size ); CREATE OPERATOR @ ( RIGHTARG = iprange, PROCEDURE = iprange_size ); CREATE OPERATOR @@ ( RIGHTARG = ip4r, PROCEDURE = ip4r_size_exact ); CREATE OPERATOR @@ ( RIGHTARG = ip6r, PROCEDURE = ip6r_size_exact ); CREATE OPERATOR @@ ( RIGHTARG = iprange, PROCEDURE = iprange_size_exact ); -- ---------------------------------------------------------------------- -- Operators -- the function forms of these aren't intended for general use -- bitwise ops: and (a & b), or (a | b), xor (a # b), not (~a) CREATE OR REPLACE FUNCTION ip4_and(ip4,ip4) RETURNS ip4 AS 'MODULE_PATHNAME', 'ip4_and' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip6_and(ip6,ip6) RETURNS ip6 AS 'MODULE_PATHNAME', 'ip6_and' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ipaddress_and(ipaddress,ipaddress) RETURNS ipaddress AS 'MODULE_PATHNAME', 'ipaddr_and' LANGUAGE C IMMUTABLE STRICT; ALTER EXTENSION ip4r ADD OPERATOR &(ip4,ip4); CREATE OPERATOR & ( LEFTARG = ip6, RIGHTARG = ip6, PROCEDURE = ip6_and ); CREATE OPERATOR & ( LEFTARG = ipaddress, RIGHTARG = ipaddress, PROCEDURE = ipaddress_and ); CREATE OR REPLACE FUNCTION ip4_or(ip4,ip4) RETURNS ip4 AS 'MODULE_PATHNAME', 'ip4_or' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip6_or(ip6,ip6) RETURNS ip6 AS 'MODULE_PATHNAME', 'ip6_or' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ipaddress_or(ipaddress,ipaddress) RETURNS ipaddress AS 'MODULE_PATHNAME', 'ipaddr_or' LANGUAGE C IMMUTABLE STRICT; ALTER EXTENSION ip4r ADD OPERATOR |(ip4,ip4); CREATE OPERATOR | ( LEFTARG = ip6, RIGHTARG = ip6, PROCEDURE = ip6_or ); CREATE OPERATOR | ( LEFTARG = ipaddress, RIGHTARG = ipaddress, PROCEDURE = ipaddress_or ); CREATE OR REPLACE FUNCTION ip4_not(ip4) RETURNS ip4 AS 'MODULE_PATHNAME', 'ip4_not' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip6_not(ip6) RETURNS ip6 AS 'MODULE_PATHNAME', 'ip6_not' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ipaddress_not(ipaddress) RETURNS ipaddress AS 'MODULE_PATHNAME', 'ipaddr_not' LANGUAGE C IMMUTABLE STRICT; ALTER EXTENSION ip4r ADD OPERATOR ~(NONE,ip4); CREATE OPERATOR ~ ( RIGHTARG = ip6, PROCEDURE = ip6_not ); CREATE OPERATOR ~ ( RIGHTARG = ipaddress, PROCEDURE = ipaddress_not ); CREATE OR REPLACE FUNCTION ip4_xor(ip4,ip4) RETURNS ip4 AS 'MODULE_PATHNAME', 'ip4_xor' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip6_xor(ip6,ip6) RETURNS ip6 AS 'MODULE_PATHNAME', 'ip6_xor' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ipaddress_xor(ipaddress,ipaddress) RETURNS ipaddress AS 'MODULE_PATHNAME', 'ipaddr_xor' LANGUAGE C IMMUTABLE STRICT; ALTER EXTENSION ip4r ADD OPERATOR #(ip4,ip4); CREATE OPERATOR # ( LEFTARG = ip6, RIGHTARG = ip6, PROCEDURE = ip6_xor ); CREATE OPERATOR # ( LEFTARG = ipaddress, RIGHTARG = ipaddress, PROCEDURE = ipaddress_xor ); -- arithmetic ops: (ip + n), (ip - n), (ip - ip) where n is a numeric or integer type CREATE OR REPLACE FUNCTION ip4_plus_bigint(ip4,bigint) RETURNS ip4 AS 'MODULE_PATHNAME', 'ip4_plus_bigint' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip4_plus_int(ip4,integer) RETURNS ip4 AS 'MODULE_PATHNAME', 'ip4_plus_int' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip4_plus_numeric(ip4,numeric) RETURNS ip4 AS 'MODULE_PATHNAME', 'ip4_plus_numeric' LANGUAGE C IMMUTABLE STRICT; ALTER EXTENSION ip4r ADD OPERATOR +(ip4,bigint); ALTER EXTENSION ip4r ADD OPERATOR +(ip4,integer); CREATE OPERATOR + ( LEFTARG = ip4, RIGHTARG = numeric, PROCEDURE = ip4_plus_numeric ); CREATE OR REPLACE FUNCTION ip6_plus_bigint(ip6,bigint) RETURNS ip6 AS 'MODULE_PATHNAME', 'ip6_plus_bigint' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip6_plus_int(ip6,integer) RETURNS ip6 AS 'MODULE_PATHNAME', 'ip6_plus_int' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip6_plus_numeric(ip6,numeric) RETURNS ip6 AS 'MODULE_PATHNAME', 'ip6_plus_numeric' LANGUAGE C IMMUTABLE STRICT; CREATE OPERATOR + ( LEFTARG = ip6, RIGHTARG = bigint, PROCEDURE = ip6_plus_bigint ); CREATE OPERATOR + ( LEFTARG = ip6, RIGHTARG = integer, PROCEDURE = ip6_plus_int ); CREATE OPERATOR + ( LEFTARG = ip6, RIGHTARG = numeric, PROCEDURE = ip6_plus_numeric ); CREATE OR REPLACE FUNCTION ipaddress_plus_bigint(ipaddress,bigint) RETURNS ipaddress AS 'MODULE_PATHNAME', 'ipaddr_plus_bigint' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ipaddress_plus_int(ipaddress,integer) RETURNS ipaddress AS 'MODULE_PATHNAME', 'ipaddr_plus_int' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ipaddress_plus_numeric(ipaddress,numeric) RETURNS ipaddress AS 'MODULE_PATHNAME', 'ipaddr_plus_numeric' LANGUAGE C IMMUTABLE STRICT; CREATE OPERATOR + ( LEFTARG = ipaddress, RIGHTARG = bigint, PROCEDURE = ipaddress_plus_bigint ); CREATE OPERATOR + ( LEFTARG = ipaddress, RIGHTARG = integer, PROCEDURE = ipaddress_plus_int ); CREATE OPERATOR + ( LEFTARG = ipaddress, RIGHTARG = numeric, PROCEDURE = ipaddress_plus_numeric ); CREATE OR REPLACE FUNCTION ip4_minus_bigint(ip4,bigint) RETURNS ip4 AS 'MODULE_PATHNAME', 'ip4_minus_bigint' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip4_minus_int(ip4,integer) RETURNS ip4 AS 'MODULE_PATHNAME', 'ip4_minus_int' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip4_minus_numeric(ip4,numeric) RETURNS ip4 AS 'MODULE_PATHNAME', 'ip4_minus_numeric' LANGUAGE C IMMUTABLE STRICT; ALTER EXTENSION ip4r ADD OPERATOR -(ip4,bigint); ALTER EXTENSION ip4r ADD OPERATOR -(ip4,integer); CREATE OPERATOR - ( LEFTARG = ip4, RIGHTARG = numeric, PROCEDURE = ip4_minus_numeric ); CREATE OR REPLACE FUNCTION ip6_minus_bigint(ip6,bigint) RETURNS ip6 AS 'MODULE_PATHNAME', 'ip6_minus_bigint' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip6_minus_int(ip6,integer) RETURNS ip6 AS 'MODULE_PATHNAME', 'ip6_minus_int' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip6_minus_numeric(ip6,numeric) RETURNS ip6 AS 'MODULE_PATHNAME', 'ip6_minus_numeric' LANGUAGE C IMMUTABLE STRICT; CREATE OPERATOR - ( LEFTARG = ip6, RIGHTARG = bigint, PROCEDURE = ip6_minus_bigint ); CREATE OPERATOR - ( LEFTARG = ip6, RIGHTARG = integer, PROCEDURE = ip6_minus_int ); CREATE OPERATOR - ( LEFTARG = ip6, RIGHTARG = numeric, PROCEDURE = ip6_minus_numeric ); CREATE OR REPLACE FUNCTION ipaddress_minus_bigint(ipaddress,bigint) RETURNS ipaddress AS 'MODULE_PATHNAME', 'ipaddr_minus_bigint' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ipaddress_minus_int(ipaddress,integer) RETURNS ipaddress AS 'MODULE_PATHNAME', 'ipaddr_minus_int' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ipaddress_minus_numeric(ipaddress,numeric) RETURNS ipaddress AS 'MODULE_PATHNAME', 'ipaddr_minus_numeric' LANGUAGE C IMMUTABLE STRICT; CREATE OPERATOR - ( LEFTARG = ipaddress, RIGHTARG = bigint, PROCEDURE = ipaddress_minus_bigint ); CREATE OPERATOR - ( LEFTARG = ipaddress, RIGHTARG = integer, PROCEDURE = ipaddress_minus_int ); CREATE OPERATOR - ( LEFTARG = ipaddress, RIGHTARG = numeric, PROCEDURE = ipaddress_minus_numeric ); CREATE OR REPLACE FUNCTION ip4_minus_ip4(ip4,ip4) RETURNS bigint AS 'MODULE_PATHNAME', 'ip4_minus_ip4' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip6_minus_ip6(ip6,ip6) RETURNS numeric AS 'MODULE_PATHNAME', 'ip6_minus_ip6' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ipaddress_minus_ipaddress(ipaddress,ipaddress) RETURNS numeric AS 'MODULE_PATHNAME', 'ipaddr_minus_ipaddr' LANGUAGE C IMMUTABLE STRICT; ALTER EXTENSION ip4r ADD OPERATOR -(ip4,ip4); CREATE OPERATOR - ( LEFTARG = ip6, RIGHTARG = ip6, PROCEDURE = ip6_minus_ip6 ); CREATE OPERATOR - ( LEFTARG = ipaddress, RIGHTARG = ipaddress, PROCEDURE = ipaddress_minus_ipaddress ); -- containment predicates: (a >>= b), (a >> b), (a <<= b), (a << b), (a && b) CREATE OR REPLACE FUNCTION ip4r_contained_by(ip4r,ip4r) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip6r_contained_by(ip6r,ip6r) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION iprange_contained_by(iprange,iprange) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; ALTER EXTENSION ip4r ADD OPERATOR <<=(ip4r,ip4r); CREATE OPERATOR <<= ( LEFTARG = ip6r, RIGHTARG = ip6r, PROCEDURE = ip6r_contained_by, COMMUTATOR = '>>=', RESTRICT = contsel, JOIN = contjoinsel ); CREATE OPERATOR <<= ( LEFTARG = iprange, RIGHTARG = iprange, PROCEDURE = iprange_contained_by, COMMUTATOR = '>>=', RESTRICT = contsel, JOIN = contjoinsel ); CREATE OR REPLACE FUNCTION ip4r_contained_by_strict(ip4r,ip4r) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip6r_contained_by_strict(ip6r,ip6r) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION iprange_contained_by_strict(iprange,iprange) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; ALTER EXTENSION ip4r ADD OPERATOR <<(ip4r,ip4r); CREATE OPERATOR << ( LEFTARG = ip6r, RIGHTARG = ip6r, PROCEDURE = ip6r_contained_by_strict, COMMUTATOR = '>>', RESTRICT = contsel, JOIN = contjoinsel ); CREATE OPERATOR << ( LEFTARG = iprange, RIGHTARG = iprange, PROCEDURE = iprange_contained_by_strict, COMMUTATOR = '>>', RESTRICT = contsel, JOIN = contjoinsel ); CREATE OR REPLACE FUNCTION ip4r_contains(ip4r,ip4r) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip6r_contains(ip6r,ip6r) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION iprange_contains(iprange,iprange) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; ALTER EXTENSION ip4r ADD OPERATOR >>=(ip4r,ip4r); CREATE OPERATOR >>= ( LEFTARG = ip6r, RIGHTARG = ip6r, PROCEDURE = ip6r_contains, COMMUTATOR = '<<=', RESTRICT = contsel, JOIN = contjoinsel ); CREATE OPERATOR >>= ( LEFTARG = iprange, RIGHTARG = iprange, PROCEDURE = iprange_contains, COMMUTATOR = '<<=', RESTRICT = contsel, JOIN = contjoinsel ); CREATE OR REPLACE FUNCTION ip4r_contains_strict(ip4r,ip4r) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip6r_contains_strict(ip6r,ip6r) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION iprange_contains_strict(iprange,iprange) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; ALTER EXTENSION ip4r ADD OPERATOR >>(ip4r,ip4r); CREATE OPERATOR >> ( LEFTARG = ip6r, RIGHTARG = ip6r, PROCEDURE = ip6r_contains_strict, COMMUTATOR = '<<', RESTRICT = contsel, JOIN = contjoinsel ); CREATE OPERATOR >> ( LEFTARG = iprange, RIGHTARG = iprange, PROCEDURE = iprange_contains_strict, COMMUTATOR = '<<', RESTRICT = contsel, JOIN = contjoinsel ); CREATE OR REPLACE FUNCTION ip4r_overlaps(ip4r,ip4r) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip6r_overlaps(ip6r,ip6r) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION iprange_overlaps(iprange,iprange) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; ALTER EXTENSION ip4r ADD OPERATOR &&(ip4r,ip4r); CREATE OPERATOR && ( LEFTARG = ip6r, RIGHTARG = ip6r, PROCEDURE = ip6r_overlaps, COMMUTATOR = '&&', RESTRICT = areasel, JOIN = areajoinsel ); CREATE OPERATOR && ( LEFTARG = iprange, RIGHTARG = iprange, PROCEDURE = iprange_overlaps, COMMUTATOR = '&&', RESTRICT = areasel, JOIN = areajoinsel ); -- cross-type containment -- no operators for these since they seem to do more harm than good. These cases -- are handled by implicit casts instead. CREATE OR REPLACE FUNCTION ip4_contained_by(ip4,ip4r) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip4_contained_by(ip4,iprange) RETURNS bool AS 'MODULE_PATHNAME','iprange_ip4_contained_by' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip6_contained_by(ip6,ip6r) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip6_contained_by(ip6,iprange) RETURNS bool AS 'MODULE_PATHNAME','iprange_ip6_contained_by' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ipaddress_contained_by(ipaddress,iprange) RETURNS bool AS 'MODULE_PATHNAME','iprange_ip_contained_by' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip4_contains(ip4r,ip4) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip6_contains(ip6r,ip6) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip4_contains(iprange,ip4) RETURNS bool AS 'MODULE_PATHNAME','iprange_contains_ip4' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip6_contains(iprange,ip6) RETURNS bool AS 'MODULE_PATHNAME','iprange_contains_ip6' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ipaddress_contains(iprange,ipaddress) RETURNS bool AS 'MODULE_PATHNAME','iprange_contains_ip' LANGUAGE C IMMUTABLE STRICT; -- btree (strict weak) ordering operators -- meaning of < > for ip4 and ip6 is obvious. -- for ipaddress, all ip4 addresses are less than all ip6 addresses -- for ip4r/ip6r, the order is lexicographic on (lower,upper) -- for iprange, the universal range is lowest, then all ip4 ranges, then ip6 CREATE OR REPLACE FUNCTION ip4_eq(ip4,ip4) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip4r_eq(ip4r,ip4r) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip6_eq(ip6,ip6) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip6r_eq(ip6r,ip6r) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ipaddress_eq(ipaddress,ipaddress) RETURNS bool AS 'MODULE_PATHNAME','ipaddr_eq' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION iprange_eq(iprange,iprange) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; ALTER EXTENSION ip4r ADD OPERATOR =(ip4,ip4); ALTER EXTENSION ip4r ADD OPERATOR =(ip4r,ip4r); CREATE OPERATOR = ( LEFTARG = ip6, RIGHTARG = ip6, PROCEDURE = ip6_eq, COMMUTATOR = '=', NEGATOR = '<>', RESTRICT = eqsel, JOIN = eqjoinsel, SORT1 = '<', SORT2 = '<', HASHES ); CREATE OPERATOR = ( LEFTARG = ip6r, RIGHTARG = ip6r, PROCEDURE = ip6r_eq, COMMUTATOR = '=', NEGATOR = '<>', RESTRICT = eqsel, JOIN = eqjoinsel, SORT1 = '<', SORT2 = '<', HASHES ); CREATE OPERATOR = ( LEFTARG = ipaddress, RIGHTARG = ipaddress, PROCEDURE = ipaddress_eq, COMMUTATOR = '=', NEGATOR = '<>', RESTRICT = eqsel, JOIN = eqjoinsel, SORT1 = '<', SORT2 = '<', HASHES ); CREATE OPERATOR = ( LEFTARG = iprange, RIGHTARG = iprange, PROCEDURE = iprange_eq, COMMUTATOR = '=', NEGATOR = '<>', RESTRICT = eqsel, JOIN = eqjoinsel, SORT1 = '<', SORT2 = '<', HASHES ); CREATE OR REPLACE FUNCTION ip4_ge(ip4,ip4) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip4r_ge(ip4r,ip4r) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip6_ge(ip6,ip6) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip6r_ge(ip6r,ip6r) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ipaddress_ge(ipaddress,ipaddress) RETURNS bool AS 'MODULE_PATHNAME','ipaddr_ge' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION iprange_ge(iprange,iprange) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; ALTER EXTENSION ip4r ADD OPERATOR >=(ip4,ip4); ALTER EXTENSION ip4r ADD OPERATOR >=(ip4r,ip4r); CREATE OPERATOR >= ( LEFTARG = ip6, RIGHTARG = ip6, PROCEDURE = ip6_ge, COMMUTATOR = '<=', NEGATOR = '<', RESTRICT = scalargtsel, JOIN = scalargtjoinsel ); CREATE OPERATOR >= ( LEFTARG = ip6r, RIGHTARG = ip6r, PROCEDURE = ip6r_ge, COMMUTATOR = '<=', NEGATOR = '<', RESTRICT = scalargtsel, JOIN = scalargtjoinsel ); CREATE OPERATOR >= ( LEFTARG = ipaddress, RIGHTARG = ipaddress, PROCEDURE = ipaddress_ge, COMMUTATOR = '<=', NEGATOR = '<', RESTRICT = scalargtsel, JOIN = scalargtjoinsel ); CREATE OPERATOR >= ( LEFTARG = iprange, RIGHTARG = iprange, PROCEDURE = iprange_ge, COMMUTATOR = '<=', NEGATOR = '<', RESTRICT = scalargtsel, JOIN = scalargtjoinsel ); CREATE OR REPLACE FUNCTION ip4_gt(ip4,ip4) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip4r_gt(ip4r,ip4r) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip6_gt(ip6,ip6) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip6r_gt(ip6r,ip6r) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ipaddress_gt(ipaddress,ipaddress) RETURNS bool AS 'MODULE_PATHNAME','ipaddr_gt' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION iprange_gt(iprange,iprange) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; ALTER EXTENSION ip4r ADD OPERATOR >(ip4,ip4); ALTER EXTENSION ip4r ADD OPERATOR >(ip4r,ip4r); CREATE OPERATOR > ( LEFTARG = ip6, RIGHTARG = ip6, PROCEDURE = ip6_gt, COMMUTATOR = '<', NEGATOR = '<=', RESTRICT = scalargtsel, JOIN = scalargtjoinsel ); CREATE OPERATOR > ( LEFTARG = ip6r, RIGHTARG = ip6r, PROCEDURE = ip6r_gt, COMMUTATOR = '<', NEGATOR = '<=', RESTRICT = scalargtsel, JOIN = scalargtjoinsel ); CREATE OPERATOR > ( LEFTARG = ipaddress, RIGHTARG = ipaddress, PROCEDURE = ipaddress_gt, COMMUTATOR = '<', NEGATOR = '<=', RESTRICT = scalargtsel, JOIN = scalargtjoinsel ); CREATE OPERATOR > ( LEFTARG = iprange, RIGHTARG = iprange, PROCEDURE = iprange_gt, COMMUTATOR = '<', NEGATOR = '<=', RESTRICT = scalargtsel, JOIN = scalargtjoinsel ); CREATE OR REPLACE FUNCTION ip4_le(ip4,ip4) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip4r_le(ip4r,ip4r) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip6_le(ip6,ip6) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip6r_le(ip6r,ip6r) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ipaddress_le(ipaddress,ipaddress) RETURNS bool AS 'MODULE_PATHNAME','ipaddr_le' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION iprange_le(iprange,iprange) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; ALTER EXTENSION ip4r ADD OPERATOR <=(ip4,ip4); ALTER EXTENSION ip4r ADD OPERATOR <=(ip4r,ip4r); CREATE OPERATOR <= ( LEFTARG = ip6, RIGHTARG = ip6, PROCEDURE = ip6_le, COMMUTATOR = '>=', NEGATOR = '>', RESTRICT = scalarltsel, JOIN = scalarltjoinsel ); CREATE OPERATOR <= ( LEFTARG = ip6r, RIGHTARG = ip6r, PROCEDURE = ip6r_le, COMMUTATOR = '>=', NEGATOR = '>', RESTRICT = scalarltsel, JOIN = scalarltjoinsel ); CREATE OPERATOR <= ( LEFTARG = ipaddress, RIGHTARG = ipaddress, PROCEDURE = ipaddress_le, COMMUTATOR = '>=', NEGATOR = '>', RESTRICT = scalarltsel, JOIN = scalarltjoinsel ); CREATE OPERATOR <= ( LEFTARG = iprange, RIGHTARG = iprange, PROCEDURE = iprange_le, COMMUTATOR = '>=', NEGATOR = '>', RESTRICT = scalarltsel, JOIN = scalarltjoinsel ); CREATE OR REPLACE FUNCTION ip4_lt(ip4,ip4) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip4r_lt(ip4r,ip4r) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip6_lt(ip6,ip6) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip6r_lt(ip6r,ip6r) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ipaddress_lt(ipaddress,ipaddress) RETURNS bool AS 'MODULE_PATHNAME','ipaddr_lt' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION iprange_lt(iprange,iprange) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; ALTER EXTENSION ip4r ADD OPERATOR <(ip4,ip4); ALTER EXTENSION ip4r ADD OPERATOR <(ip4r,ip4r); CREATE OPERATOR < ( LEFTARG = ip6, RIGHTARG = ip6, PROCEDURE = ip6_lt, COMMUTATOR = '>', NEGATOR = '>=', RESTRICT = scalarltsel, JOIN = scalarltjoinsel ); CREATE OPERATOR < ( LEFTARG = ip6r, RIGHTARG = ip6r, PROCEDURE = ip6r_lt, COMMUTATOR = '>', NEGATOR = '>=', RESTRICT = scalarltsel, JOIN = scalarltjoinsel ); CREATE OPERATOR < ( LEFTARG = ipaddress, RIGHTARG = ipaddress, PROCEDURE = ipaddress_lt, COMMUTATOR = '>', NEGATOR = '>=', RESTRICT = scalarltsel, JOIN = scalarltjoinsel ); CREATE OPERATOR < ( LEFTARG = iprange, RIGHTARG = iprange, PROCEDURE = iprange_lt, COMMUTATOR = '>', NEGATOR = '>=', RESTRICT = scalarltsel, JOIN = scalarltjoinsel ); CREATE OR REPLACE FUNCTION ip4_neq(ip4,ip4) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip4r_neq(ip4r,ip4r) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip6_neq(ip6,ip6) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip6r_neq(ip6r,ip6r) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ipaddress_neq(ipaddress,ipaddress) RETURNS bool AS 'MODULE_PATHNAME','ipaddr_neq' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION iprange_neq(iprange,iprange) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; ALTER EXTENSION ip4r ADD OPERATOR <>(ip4,ip4); ALTER EXTENSION ip4r ADD OPERATOR <>(ip4r,ip4r); CREATE OPERATOR <> ( LEFTARG = ip6, RIGHTARG = ip6, PROCEDURE = ip6_neq, COMMUTATOR = '<>', NEGATOR = '=', RESTRICT = neqsel, JOIN = neqjoinsel ); CREATE OPERATOR <> ( LEFTARG = ip6r, RIGHTARG = ip6r, PROCEDURE = ip6r_neq, COMMUTATOR = '<>', NEGATOR = '=', RESTRICT = neqsel, JOIN = neqjoinsel ); CREATE OPERATOR <> ( LEFTARG = ipaddress, RIGHTARG = ipaddress, PROCEDURE = ipaddress_neq, COMMUTATOR = '<>', NEGATOR = '=', RESTRICT = neqsel, JOIN = neqjoinsel ); CREATE OPERATOR <> ( LEFTARG = iprange, RIGHTARG = iprange, PROCEDURE = iprange_neq, COMMUTATOR = '<>', NEGATOR = '=', RESTRICT = neqsel, JOIN = neqjoinsel ); -- ---------------------------------------------------------------------- -- Btree index CREATE OR REPLACE FUNCTION ip4_cmp(ip4,ip4) RETURNS integer AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip4r_cmp(ip4r,ip4r) RETURNS integer AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip6_cmp(ip6,ip6) RETURNS integer AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip6r_cmp(ip6r,ip6r) RETURNS integer AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ipaddress_cmp(ipaddress,ipaddress) RETURNS integer AS 'MODULE_PATHNAME','ipaddr_cmp' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION iprange_cmp(iprange,iprange) RETURNS integer AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT; ALTER EXTENSION ip4r ADD OPERATOR CLASS btree_ip4_ops USING btree; ALTER EXTENSION ip4r ADD OPERATOR CLASS btree_ip4r_ops USING btree; CREATE OPERATOR CLASS btree_ip6_ops DEFAULT FOR TYPE ip6 USING btree AS OPERATOR 1 < , OPERATOR 2 <= , OPERATOR 3 = , OPERATOR 4 >= , OPERATOR 5 > , FUNCTION 1 ip6_cmp(ip6, ip6); CREATE OPERATOR CLASS btree_ip6r_ops DEFAULT FOR TYPE ip6r USING btree AS OPERATOR 1 < , OPERATOR 2 <= , OPERATOR 3 = , OPERATOR 4 >= , OPERATOR 5 > , FUNCTION 1 ip6r_cmp(ip6r, ip6r); CREATE OPERATOR CLASS btree_ipaddress_ops DEFAULT FOR TYPE ipaddress USING btree AS OPERATOR 1 < , OPERATOR 2 <= , OPERATOR 3 = , OPERATOR 4 >= , OPERATOR 5 > , FUNCTION 1 ipaddress_cmp(ipaddress, ipaddress); CREATE OPERATOR CLASS btree_iprange_ops DEFAULT FOR TYPE iprange USING btree AS OPERATOR 1 < , OPERATOR 2 <= , OPERATOR 3 = , OPERATOR 4 >= , OPERATOR 5 > , FUNCTION 1 iprange_cmp(iprange, iprange); -- ---------------------------------------------------------------------- -- Hash index -- the hash index definitions are needed for hashagg, hashjoin, hash-distinct, hashsetop -- etc. even if no actual hash indexes are used. CREATE OR REPLACE FUNCTION ip4hash(ip4) RETURNS integer AS 'MODULE_PATHNAME', 'ip4hash' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip6hash(ip6) RETURNS integer AS 'MODULE_PATHNAME', 'ip6hash' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ipaddresshash(ipaddress) RETURNS integer AS 'MODULE_PATHNAME', 'ipaddr_hash' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip4rhash(ip4r) RETURNS integer AS 'MODULE_PATHNAME', 'ip4rhash' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION ip6rhash(ip6r) RETURNS integer AS 'MODULE_PATHNAME', 'ip6rhash' LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION iprangehash(iprange) RETURNS integer AS 'MODULE_PATHNAME', 'iprange_hash' LANGUAGE C IMMUTABLE STRICT; ALTER EXTENSION ip4r ADD OPERATOR CLASS hash_ip4_ops USING hash; ALTER EXTENSION ip4r ADD OPERATOR CLASS hash_ip4r_ops USING hash; CREATE OPERATOR CLASS hash_ip6_ops DEFAULT FOR TYPE ip6 USING hash AS OPERATOR 1 = , FUNCTION 1 ip6hash(ip6); CREATE OPERATOR CLASS hash_ip6r_ops DEFAULT FOR TYPE ip6r USING hash AS OPERATOR 1 = , FUNCTION 1 ip6rhash(ip6r); CREATE OPERATOR CLASS hash_ipaddress_ops DEFAULT FOR TYPE ipaddress USING hash AS OPERATOR 1 = , FUNCTION 1 ipaddresshash(ipaddress); CREATE OPERATOR CLASS hash_iprange_ops DEFAULT FOR TYPE iprange USING hash AS OPERATOR 1 = , FUNCTION 1 iprangehash(iprange); -- ---------------------------------------------------------------------- -- GiST -- these type declarations are actually wrong for 8.4+ (which added -- more args to consistent) but we ignore that because the access -- method code doesn't actually look at the function declaration, and -- the differences are handled in the C code. Having the SQL -- definition changing is just too much of a pain. CREATE OR REPLACE FUNCTION gip4r_consistent(internal,ip4r,int4) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C; CREATE OR REPLACE FUNCTION gip4r_compress(internal) RETURNS internal AS 'MODULE_PATHNAME' LANGUAGE C; CREATE OR REPLACE FUNCTION gip4r_decompress(internal) RETURNS internal AS 'MODULE_PATHNAME' LANGUAGE C; CREATE OR REPLACE FUNCTION gip4r_penalty(internal,internal,internal) RETURNS internal AS 'MODULE_PATHNAME' LANGUAGE C STRICT; CREATE OR REPLACE FUNCTION gip4r_picksplit(internal, internal) RETURNS internal AS 'MODULE_PATHNAME' LANGUAGE C; CREATE OR REPLACE FUNCTION gip4r_union(internal, internal) RETURNS ip4r AS 'MODULE_PATHNAME' LANGUAGE C; CREATE OR REPLACE FUNCTION gip4r_same(ip4r, ip4r, internal) RETURNS internal AS 'MODULE_PATHNAME' LANGUAGE C; CREATE OR REPLACE FUNCTION gip6r_consistent(internal,ip6r,int4) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C; CREATE OR REPLACE FUNCTION gip6r_compress(internal) RETURNS internal AS 'MODULE_PATHNAME' LANGUAGE C; CREATE OR REPLACE FUNCTION gip6r_decompress(internal) RETURNS internal AS 'MODULE_PATHNAME' LANGUAGE C; CREATE OR REPLACE FUNCTION gip6r_penalty(internal,internal,internal) RETURNS internal AS 'MODULE_PATHNAME' LANGUAGE C STRICT; CREATE OR REPLACE FUNCTION gip6r_picksplit(internal, internal) RETURNS internal AS 'MODULE_PATHNAME' LANGUAGE C; CREATE OR REPLACE FUNCTION gip6r_union(internal, internal) RETURNS ip6r AS 'MODULE_PATHNAME' LANGUAGE C; CREATE OR REPLACE FUNCTION gip6r_same(ip6r, ip6r, internal) RETURNS internal AS 'MODULE_PATHNAME' LANGUAGE C; CREATE OR REPLACE FUNCTION gipr_consistent(internal,iprange,int4) RETURNS bool AS 'MODULE_PATHNAME' LANGUAGE C; CREATE OR REPLACE FUNCTION gipr_compress(internal) RETURNS internal AS 'MODULE_PATHNAME' LANGUAGE C; CREATE OR REPLACE FUNCTION gipr_decompress(internal) RETURNS internal AS 'MODULE_PATHNAME' LANGUAGE C; CREATE OR REPLACE FUNCTION gipr_penalty(internal,internal,internal) RETURNS internal AS 'MODULE_PATHNAME' LANGUAGE C STRICT; CREATE OR REPLACE FUNCTION gipr_picksplit(internal, internal) RETURNS internal AS 'MODULE_PATHNAME' LANGUAGE C; CREATE OR REPLACE FUNCTION gipr_union(internal, internal) RETURNS iprange AS 'MODULE_PATHNAME' LANGUAGE C; CREATE OR REPLACE FUNCTION gipr_same(iprange, iprange, internal) RETURNS internal AS 'MODULE_PATHNAME' LANGUAGE C; ALTER EXTENSION ip4r ADD OPERATOR CLASS gist_ip4r_ops USING gist; CREATE OPERATOR CLASS gist_ip6r_ops DEFAULT FOR TYPE ip6r USING gist AS OPERATOR 1 >>= , OPERATOR 2 <<= , OPERATOR 3 >> , OPERATOR 4 << , OPERATOR 5 && , OPERATOR 6 = , FUNCTION 1 gip6r_consistent (internal, ip6r, int4), FUNCTION 2 gip6r_union (internal, internal), FUNCTION 3 gip6r_compress (internal), FUNCTION 4 gip6r_decompress (internal), FUNCTION 5 gip6r_penalty (internal, internal, internal), FUNCTION 6 gip6r_picksplit (internal, internal), FUNCTION 7 gip6r_same (ip6r, ip6r, internal); CREATE OPERATOR CLASS gist_iprange_ops DEFAULT FOR TYPE iprange USING gist AS OPERATOR 1 >>= , OPERATOR 2 <<= , OPERATOR 3 >> , OPERATOR 4 << , OPERATOR 5 && , OPERATOR 6 = , FUNCTION 1 gipr_consistent (internal, iprange, int4), FUNCTION 2 gipr_union (internal, internal), FUNCTION 3 gipr_compress (internal), FUNCTION 4 gipr_decompress (internal), FUNCTION 5 gipr_penalty (internal, internal, internal), FUNCTION 6 gipr_picksplit (internal, internal), FUNCTION 7 gipr_same (iprange, iprange, internal); -- cleanup old cruft DROP OPERATOR IF EXISTS @(ip4r,ip4r); DROP OPERATOR IF EXISTS ~(ip4r,ip4r); DROP OPERATOR IF EXISTS &<<(ip4r,ip4r); DROP OPERATOR IF EXISTS &>>(ip4r,ip4r); DROP OPERATOR IF EXISTS <<<(ip4r,ip4r); DROP OPERATOR IF EXISTS >>>(ip4r,ip4r); DROP FUNCTION IF EXISTS ip4r_left_of(ip4r,ip4r); DROP FUNCTION IF EXISTS ip4r_left_overlap(ip4r,ip4r); DROP FUNCTION IF EXISTS ip4r_right_of(ip4r,ip4r); DROP FUNCTION IF EXISTS ip4r_right_overlap(ip4r,ip4r); -- end ip4r-2.0.2/ip4r--unpackaged2.0--2.0.sql000066400000000000000000000542751233620317400167550ustar00rootroot00000000000000-- ip4r extension -- complain if script is sourced in psql, rather than via CREATE EXTENSION \echo Use "CREATE EXTENSION ip4r" to load this file. \quit ALTER EXTENSION ip4r ADD FUNCTION ip4_in(cstring); ALTER EXTENSION ip4r ADD FUNCTION ip4_out(ip4); ALTER EXTENSION ip4r ADD FUNCTION ip4_recv(internal); ALTER EXTENSION ip4r ADD FUNCTION ip4_send(ip4); ALTER EXTENSION ip4r ADD TYPE ip4; ALTER EXTENSION ip4r ADD FUNCTION ip4r_in(cstring); ALTER EXTENSION ip4r ADD FUNCTION ip4r_out(ip4r); ALTER EXTENSION ip4r ADD FUNCTION ip4r_recv(internal); ALTER EXTENSION ip4r ADD FUNCTION ip4r_send(ip4r); ALTER EXTENSION ip4r ADD TYPE ip4r; ALTER EXTENSION ip4r ADD FUNCTION ip6_in(cstring); ALTER EXTENSION ip4r ADD FUNCTION ip6_out(ip6); ALTER EXTENSION ip4r ADD FUNCTION ip6_recv(internal); ALTER EXTENSION ip4r ADD FUNCTION ip6_send(ip6); ALTER EXTENSION ip4r ADD TYPE ip6; ALTER EXTENSION ip4r ADD FUNCTION ip6r_in(cstring); ALTER EXTENSION ip4r ADD FUNCTION ip6r_out(ip6r); ALTER EXTENSION ip4r ADD FUNCTION ip6r_recv(internal); ALTER EXTENSION ip4r ADD FUNCTION ip6r_send(ip6r); ALTER EXTENSION ip4r ADD TYPE ip6r; ALTER EXTENSION ip4r ADD FUNCTION ipaddress_in(cstring); ALTER EXTENSION ip4r ADD FUNCTION ipaddress_out(ipaddress); ALTER EXTENSION ip4r ADD FUNCTION ipaddress_recv(internal); ALTER EXTENSION ip4r ADD FUNCTION ipaddress_send(ipaddress); ALTER EXTENSION ip4r ADD TYPE ipaddress; ALTER EXTENSION ip4r ADD FUNCTION iprange_in(cstring); ALTER EXTENSION ip4r ADD FUNCTION iprange_out(iprange); ALTER EXTENSION ip4r ADD FUNCTION iprange_recv(internal); ALTER EXTENSION ip4r ADD FUNCTION iprange_send(iprange); ALTER EXTENSION ip4r ADD TYPE iprange; ALTER EXTENSION ip4r ADD FUNCTION ip4(bigint); ALTER EXTENSION ip4r ADD FUNCTION ip4(double precision); ALTER EXTENSION ip4r ADD FUNCTION ip4(numeric); ALTER EXTENSION ip4r ADD FUNCTION ip4(inet); ALTER EXTENSION ip4r ADD FUNCTION ip4(text); ALTER EXTENSION ip4r ADD FUNCTION ip4(ipaddress); ALTER EXTENSION ip4r ADD FUNCTION ip6(numeric); ALTER EXTENSION ip4r ADD FUNCTION ip6(inet); ALTER EXTENSION ip4r ADD FUNCTION ip6(text); ALTER EXTENSION ip4r ADD FUNCTION ip6(ipaddress); ALTER EXTENSION ip4r ADD FUNCTION ipaddress(inet); ALTER EXTENSION ip4r ADD FUNCTION ipaddress(ip4); ALTER EXTENSION ip4r ADD FUNCTION ipaddress(ip6); ALTER EXTENSION ip4r ADD FUNCTION ipaddress(text); ALTER EXTENSION ip4r ADD FUNCTION ip4r(cidr); ALTER EXTENSION ip4r ADD FUNCTION ip4r(ip4); ALTER EXTENSION ip4r ADD FUNCTION ip4r(text); ALTER EXTENSION ip4r ADD FUNCTION ip4r(iprange); ALTER EXTENSION ip4r ADD FUNCTION ip6r(cidr); ALTER EXTENSION ip4r ADD FUNCTION ip6r(ip6); ALTER EXTENSION ip4r ADD FUNCTION ip6r(text); ALTER EXTENSION ip4r ADD FUNCTION ip6r(iprange); ALTER EXTENSION ip4r ADD FUNCTION iprange(cidr); ALTER EXTENSION ip4r ADD FUNCTION iprange(ip4); ALTER EXTENSION ip4r ADD FUNCTION iprange(ip6); ALTER EXTENSION ip4r ADD FUNCTION iprange(ip4r); ALTER EXTENSION ip4r ADD FUNCTION iprange(ip6r); ALTER EXTENSION ip4r ADD FUNCTION iprange(ipaddress); ALTER EXTENSION ip4r ADD FUNCTION iprange(text); ALTER EXTENSION ip4r ADD FUNCTION cidr(ip4); ALTER EXTENSION ip4r ADD FUNCTION cidr(ip4r); ALTER EXTENSION ip4r ADD FUNCTION cidr(ip6); ALTER EXTENSION ip4r ADD FUNCTION cidr(ip6r); ALTER EXTENSION ip4r ADD FUNCTION cidr(ipaddress); ALTER EXTENSION ip4r ADD FUNCTION cidr(iprange); ALTER EXTENSION ip4r ADD FUNCTION text(ip4); ALTER EXTENSION ip4r ADD FUNCTION text(ip4r); ALTER EXTENSION ip4r ADD FUNCTION text(ip6); ALTER EXTENSION ip4r ADD FUNCTION text(ip6r); ALTER EXTENSION ip4r ADD FUNCTION text(ipaddress); ALTER EXTENSION ip4r ADD FUNCTION text(iprange); ALTER EXTENSION ip4r ADD FUNCTION to_bigint(ip4); ALTER EXTENSION ip4r ADD FUNCTION to_double(ip4); ALTER EXTENSION ip4r ADD FUNCTION to_numeric(ip4); ALTER EXTENSION ip4r ADD FUNCTION to_numeric(ip6); ALTER EXTENSION ip4r ADD FUNCTION to_numeric(ipaddress); ALTER EXTENSION ip4r ADD CAST (ip4 as bigint); ALTER EXTENSION ip4r ADD CAST (ip4 as double precision); ALTER EXTENSION ip4r ADD CAST (ip4 as numeric); ALTER EXTENSION ip4r ADD CAST (ip4 as text); ALTER EXTENSION ip4r ADD CAST (ip4 as cidr); ALTER EXTENSION ip4r ADD CAST (ip4r as cidr); ALTER EXTENSION ip4r ADD CAST (ip4r as text); ALTER EXTENSION ip4r ADD CAST (ip6 as numeric); ALTER EXTENSION ip4r ADD CAST (ip6 as text); ALTER EXTENSION ip4r ADD CAST (ip6 as cidr); ALTER EXTENSION ip4r ADD CAST (ip6r as cidr); ALTER EXTENSION ip4r ADD CAST (ip6r as text); ALTER EXTENSION ip4r ADD CAST (ipaddress as numeric); ALTER EXTENSION ip4r ADD CAST (ipaddress as text); ALTER EXTENSION ip4r ADD CAST (ipaddress as cidr); ALTER EXTENSION ip4r ADD CAST (iprange as cidr); ALTER EXTENSION ip4r ADD CAST (iprange as text); ALTER EXTENSION ip4r ADD CAST (text as ip4); ALTER EXTENSION ip4r ADD CAST (text as ip4r); ALTER EXTENSION ip4r ADD CAST (text as ip6); ALTER EXTENSION ip4r ADD CAST (text as ip6r); ALTER EXTENSION ip4r ADD CAST (text as ipaddress); ALTER EXTENSION ip4r ADD CAST (text as iprange); ALTER EXTENSION ip4r ADD CAST (bigint as ip4); ALTER EXTENSION ip4r ADD CAST (double precision as ip4); ALTER EXTENSION ip4r ADD CAST (numeric as ip4); ALTER EXTENSION ip4r ADD CAST (numeric as ip6); ALTER EXTENSION ip4r ADD CAST (cidr as ip4r); ALTER EXTENSION ip4r ADD CAST (cidr as ip6r); ALTER EXTENSION ip4r ADD CAST (cidr as iprange); ALTER EXTENSION ip4r ADD CAST (inet as ip4); ALTER EXTENSION ip4r ADD CAST (inet as ip6); ALTER EXTENSION ip4r ADD CAST (inet as ipaddress); ALTER EXTENSION ip4r ADD CAST (ip4 as ip4r); ALTER EXTENSION ip4r ADD CAST (ip4 as ipaddress); ALTER EXTENSION ip4r ADD CAST (ip4 as iprange); ALTER EXTENSION ip4r ADD CAST (ip4r as iprange); ALTER EXTENSION ip4r ADD CAST (ip6 as ip6r); ALTER EXTENSION ip4r ADD CAST (ip6 as ipaddress); ALTER EXTENSION ip4r ADD CAST (ip6 as iprange); ALTER EXTENSION ip4r ADD CAST (ip6r as iprange); ALTER EXTENSION ip4r ADD CAST (ipaddress as iprange); ALTER EXTENSION ip4r ADD CAST (ipaddress as ip4); ALTER EXTENSION ip4r ADD CAST (ipaddress as ip6); ALTER EXTENSION ip4r ADD CAST (iprange as ip4r); ALTER EXTENSION ip4r ADD CAST (iprange as ip6r); ALTER EXTENSION ip4r ADD FUNCTION ip4r(ip4,ip4); ALTER EXTENSION ip4r ADD FUNCTION ip6r(ip6,ip6); ALTER EXTENSION ip4r ADD FUNCTION iprange(ip4,ip4); ALTER EXTENSION ip4r ADD FUNCTION iprange(ip6,ip6); ALTER EXTENSION ip4r ADD FUNCTION iprange(ipaddress,ipaddress); ALTER EXTENSION ip4r ADD FUNCTION family(ip4); ALTER EXTENSION ip4r ADD FUNCTION family(ip4r); ALTER EXTENSION ip4r ADD FUNCTION family(ip6); ALTER EXTENSION ip4r ADD FUNCTION family(ip6r); ALTER EXTENSION ip4r ADD FUNCTION family(ipaddress); ALTER EXTENSION ip4r ADD FUNCTION family(iprange); ALTER EXTENSION ip4r ADD FUNCTION ip4_netmask(integer); ALTER EXTENSION ip4r ADD FUNCTION ip6_netmask(integer); ALTER EXTENSION ip4r ADD FUNCTION is_cidr(ip4r); ALTER EXTENSION ip4r ADD FUNCTION is_cidr(ip6r); ALTER EXTENSION ip4r ADD FUNCTION is_cidr(iprange); ALTER EXTENSION ip4r ADD FUNCTION masklen(ip4r); ALTER EXTENSION ip4r ADD FUNCTION masklen(ip6r); ALTER EXTENSION ip4r ADD FUNCTION masklen(iprange); ALTER EXTENSION ip4r ADD FUNCTION lower(ip4r); ALTER EXTENSION ip4r ADD FUNCTION lower(ip6r); ALTER EXTENSION ip4r ADD FUNCTION lower(iprange); ALTER EXTENSION ip4r ADD FUNCTION upper(ip4r); ALTER EXTENSION ip4r ADD FUNCTION upper(ip6r); ALTER EXTENSION ip4r ADD FUNCTION upper(iprange); ALTER EXTENSION ip4r ADD FUNCTION ip4_net_lower(ip4,integer); ALTER EXTENSION ip4r ADD FUNCTION ip6_net_lower(ip6,integer); ALTER EXTENSION ip4r ADD FUNCTION ipaddress_net_lower(ipaddress,integer); ALTER EXTENSION ip4r ADD FUNCTION ip4_net_upper(ip4,integer); ALTER EXTENSION ip4r ADD FUNCTION ip6_net_upper(ip6,integer); ALTER EXTENSION ip4r ADD FUNCTION ipaddress_net_upper(ipaddress,integer); ALTER EXTENSION ip4r ADD FUNCTION ip4r_union(ip4r, ip4r); ALTER EXTENSION ip4r ADD FUNCTION ip6r_union(ip6r, ip6r); ALTER EXTENSION ip4r ADD FUNCTION iprange_union(iprange, iprange); ALTER EXTENSION ip4r ADD FUNCTION ip4r_inter(ip4r,ip4r); ALTER EXTENSION ip4r ADD FUNCTION ip6r_inter(ip6r,ip6r); ALTER EXTENSION ip4r ADD FUNCTION iprange_inter(iprange,iprange); ALTER EXTENSION ip4r ADD FUNCTION ip4r_net_mask(ip4,ip4); ALTER EXTENSION ip4r ADD FUNCTION ip6r_net_mask(ip6,ip6); ALTER EXTENSION ip4r ADD FUNCTION iprange_net_mask(ip4,ip4); ALTER EXTENSION ip4r ADD FUNCTION iprange_net_mask(ip6,ip6); ALTER EXTENSION ip4r ADD FUNCTION iprange_net_mask(ipaddress,ipaddress); ALTER EXTENSION ip4r ADD FUNCTION ip4r_net_prefix(ip4,integer); ALTER EXTENSION ip4r ADD FUNCTION ip6r_net_prefix(ip6,integer); ALTER EXTENSION ip4r ADD FUNCTION iprange_net_prefix(ip4,integer); ALTER EXTENSION ip4r ADD FUNCTION iprange_net_prefix(ip6,integer); ALTER EXTENSION ip4r ADD FUNCTION iprange_net_prefix(ipaddress,integer); ALTER EXTENSION ip4r ADD OPERATOR /(ip4,ip4); ALTER EXTENSION ip4r ADD OPERATOR /(ip6,ip6); ALTER EXTENSION ip4r ADD OPERATOR /(ipaddress,ipaddress); ALTER EXTENSION ip4r ADD OPERATOR /(ip4,integer); ALTER EXTENSION ip4r ADD OPERATOR /(ip6,integer); ALTER EXTENSION ip4r ADD OPERATOR /(ipaddress,integer); ALTER EXTENSION ip4r ADD FUNCTION ip4r_size(ip4r); ALTER EXTENSION ip4r ADD FUNCTION ip6r_size(ip6r); ALTER EXTENSION ip4r ADD FUNCTION iprange_size(iprange); ALTER EXTENSION ip4r ADD FUNCTION ip4r_size_exact(ip4r); ALTER EXTENSION ip4r ADD FUNCTION ip6r_size_exact(ip6r); ALTER EXTENSION ip4r ADD FUNCTION iprange_size_exact(iprange); ALTER EXTENSION ip4r ADD OPERATOR @(NONE,ip4r); ALTER EXTENSION ip4r ADD OPERATOR @(NONE,ip6r); ALTER EXTENSION ip4r ADD OPERATOR @(NONE,iprange); ALTER EXTENSION ip4r ADD OPERATOR @@(NONE,ip4r); ALTER EXTENSION ip4r ADD OPERATOR @@(NONE,ip6r); ALTER EXTENSION ip4r ADD OPERATOR @@(NONE,iprange); ALTER EXTENSION ip4r ADD FUNCTION ip4_and(ip4,ip4); ALTER EXTENSION ip4r ADD FUNCTION ip6_and(ip6,ip6); ALTER EXTENSION ip4r ADD FUNCTION ipaddress_and(ipaddress,ipaddress); ALTER EXTENSION ip4r ADD OPERATOR &(ip4,ip4); ALTER EXTENSION ip4r ADD OPERATOR &(ip6,ip6); ALTER EXTENSION ip4r ADD OPERATOR &(ipaddress,ipaddress); ALTER EXTENSION ip4r ADD FUNCTION ip4_or(ip4,ip4); ALTER EXTENSION ip4r ADD FUNCTION ip6_or(ip6,ip6); ALTER EXTENSION ip4r ADD FUNCTION ipaddress_or(ipaddress,ipaddress); ALTER EXTENSION ip4r ADD OPERATOR |(ip4,ip4); ALTER EXTENSION ip4r ADD OPERATOR |(ip6,ip6); ALTER EXTENSION ip4r ADD OPERATOR |(ipaddress,ipaddress); ALTER EXTENSION ip4r ADD FUNCTION ip4_not(ip4); ALTER EXTENSION ip4r ADD FUNCTION ip6_not(ip6); ALTER EXTENSION ip4r ADD FUNCTION ipaddress_not(ipaddress); ALTER EXTENSION ip4r ADD OPERATOR ~(NONE,ip4); ALTER EXTENSION ip4r ADD OPERATOR ~(NONE,ip6); ALTER EXTENSION ip4r ADD OPERATOR ~(NONE,ipaddress); ALTER EXTENSION ip4r ADD FUNCTION ip4_xor(ip4,ip4); ALTER EXTENSION ip4r ADD FUNCTION ip6_xor(ip6,ip6); ALTER EXTENSION ip4r ADD FUNCTION ipaddress_xor(ipaddress,ipaddress); ALTER EXTENSION ip4r ADD OPERATOR #(ip4,ip4); ALTER EXTENSION ip4r ADD OPERATOR #(ip6,ip6); ALTER EXTENSION ip4r ADD OPERATOR #(ipaddress,ipaddress); ALTER EXTENSION ip4r ADD FUNCTION ip4_plus_bigint(ip4,bigint); ALTER EXTENSION ip4r ADD FUNCTION ip4_plus_int(ip4,integer); ALTER EXTENSION ip4r ADD FUNCTION ip4_plus_numeric(ip4,numeric); ALTER EXTENSION ip4r ADD OPERATOR +(ip4,bigint); ALTER EXTENSION ip4r ADD OPERATOR +(ip4,integer); ALTER EXTENSION ip4r ADD OPERATOR +(ip4,numeric); ALTER EXTENSION ip4r ADD FUNCTION ip6_plus_bigint(ip6,bigint); ALTER EXTENSION ip4r ADD FUNCTION ip6_plus_int(ip6,integer); ALTER EXTENSION ip4r ADD FUNCTION ip6_plus_numeric(ip6,numeric); ALTER EXTENSION ip4r ADD OPERATOR +(ip6,bigint); ALTER EXTENSION ip4r ADD OPERATOR +(ip6,integer); ALTER EXTENSION ip4r ADD OPERATOR +(ip6,numeric); ALTER EXTENSION ip4r ADD FUNCTION ipaddress_plus_bigint(ipaddress,bigint); ALTER EXTENSION ip4r ADD FUNCTION ipaddress_plus_int(ipaddress,integer); ALTER EXTENSION ip4r ADD FUNCTION ipaddress_plus_numeric(ipaddress,numeric); ALTER EXTENSION ip4r ADD OPERATOR +(ipaddress,bigint); ALTER EXTENSION ip4r ADD OPERATOR +(ipaddress,integer); ALTER EXTENSION ip4r ADD OPERATOR +(ipaddress,numeric); ALTER EXTENSION ip4r ADD FUNCTION ip4_minus_bigint(ip4,bigint); ALTER EXTENSION ip4r ADD FUNCTION ip4_minus_int(ip4,integer); ALTER EXTENSION ip4r ADD FUNCTION ip4_minus_numeric(ip4,numeric); ALTER EXTENSION ip4r ADD OPERATOR -(ip4,bigint); ALTER EXTENSION ip4r ADD OPERATOR -(ip4,integer); ALTER EXTENSION ip4r ADD OPERATOR -(ip4,numeric); ALTER EXTENSION ip4r ADD FUNCTION ip6_minus_bigint(ip6,bigint); ALTER EXTENSION ip4r ADD FUNCTION ip6_minus_int(ip6,integer); ALTER EXTENSION ip4r ADD FUNCTION ip6_minus_numeric(ip6,numeric); ALTER EXTENSION ip4r ADD OPERATOR -(ip6,bigint); ALTER EXTENSION ip4r ADD OPERATOR -(ip6,integer); ALTER EXTENSION ip4r ADD OPERATOR -(ip6,numeric); ALTER EXTENSION ip4r ADD FUNCTION ipaddress_minus_bigint(ipaddress,bigint); ALTER EXTENSION ip4r ADD FUNCTION ipaddress_minus_int(ipaddress,integer); ALTER EXTENSION ip4r ADD FUNCTION ipaddress_minus_numeric(ipaddress,numeric); ALTER EXTENSION ip4r ADD OPERATOR -(ipaddress,bigint); ALTER EXTENSION ip4r ADD OPERATOR -(ipaddress,integer); ALTER EXTENSION ip4r ADD OPERATOR -(ipaddress,numeric); ALTER EXTENSION ip4r ADD FUNCTION ip4_minus_ip4(ip4,ip4); ALTER EXTENSION ip4r ADD FUNCTION ip6_minus_ip6(ip6,ip6); ALTER EXTENSION ip4r ADD FUNCTION ipaddress_minus_ipaddress(ipaddress,ipaddress); ALTER EXTENSION ip4r ADD OPERATOR -(ip4,ip4); ALTER EXTENSION ip4r ADD OPERATOR -(ip6,ip6); ALTER EXTENSION ip4r ADD OPERATOR -(ipaddress,ipaddress); ALTER EXTENSION ip4r ADD FUNCTION ip4r_contained_by(ip4r,ip4r); ALTER EXTENSION ip4r ADD FUNCTION ip6r_contained_by(ip6r,ip6r); ALTER EXTENSION ip4r ADD FUNCTION iprange_contained_by(iprange,iprange); ALTER EXTENSION ip4r ADD OPERATOR <<=(ip4r,ip4r); ALTER EXTENSION ip4r ADD OPERATOR <<=(ip6r,ip6r); ALTER EXTENSION ip4r ADD OPERATOR <<=(iprange,iprange); ALTER EXTENSION ip4r ADD FUNCTION ip4r_contained_by_strict(ip4r,ip4r); ALTER EXTENSION ip4r ADD FUNCTION ip6r_contained_by_strict(ip6r,ip6r); ALTER EXTENSION ip4r ADD FUNCTION iprange_contained_by_strict(iprange,iprange); ALTER EXTENSION ip4r ADD OPERATOR <<(ip4r,ip4r); ALTER EXTENSION ip4r ADD OPERATOR <<(ip6r,ip6r); ALTER EXTENSION ip4r ADD OPERATOR <<(iprange,iprange); ALTER EXTENSION ip4r ADD FUNCTION ip4r_contains(ip4r,ip4r); ALTER EXTENSION ip4r ADD FUNCTION ip6r_contains(ip6r,ip6r); ALTER EXTENSION ip4r ADD FUNCTION iprange_contains(iprange,iprange); ALTER EXTENSION ip4r ADD OPERATOR >>=(ip4r,ip4r); ALTER EXTENSION ip4r ADD OPERATOR >>=(ip6r,ip6r); ALTER EXTENSION ip4r ADD OPERATOR >>=(iprange,iprange); ALTER EXTENSION ip4r ADD FUNCTION ip4r_contains_strict(ip4r,ip4r); ALTER EXTENSION ip4r ADD FUNCTION ip6r_contains_strict(ip6r,ip6r); ALTER EXTENSION ip4r ADD FUNCTION iprange_contains_strict(iprange,iprange); ALTER EXTENSION ip4r ADD OPERATOR >>(ip4r,ip4r); ALTER EXTENSION ip4r ADD OPERATOR >>(ip6r,ip6r); ALTER EXTENSION ip4r ADD OPERATOR >>(iprange,iprange); ALTER EXTENSION ip4r ADD FUNCTION ip4r_overlaps(ip4r,ip4r); ALTER EXTENSION ip4r ADD FUNCTION ip6r_overlaps(ip6r,ip6r); ALTER EXTENSION ip4r ADD FUNCTION iprange_overlaps(iprange,iprange); ALTER EXTENSION ip4r ADD OPERATOR &&(ip4r,ip4r); ALTER EXTENSION ip4r ADD OPERATOR &&(ip6r,ip6r); ALTER EXTENSION ip4r ADD OPERATOR &&(iprange,iprange); ALTER EXTENSION ip4r ADD FUNCTION ip4_contained_by(ip4,ip4r); ALTER EXTENSION ip4r ADD FUNCTION ip4_contained_by(ip4,iprange); ALTER EXTENSION ip4r ADD FUNCTION ip6_contained_by(ip6,ip6r); ALTER EXTENSION ip4r ADD FUNCTION ip6_contained_by(ip6,iprange); ALTER EXTENSION ip4r ADD FUNCTION ipaddress_contained_by(ipaddress,iprange); ALTER EXTENSION ip4r ADD FUNCTION ip4_contains(ip4r,ip4); ALTER EXTENSION ip4r ADD FUNCTION ip6_contains(ip6r,ip6); ALTER EXTENSION ip4r ADD FUNCTION ip4_contains(iprange,ip4); ALTER EXTENSION ip4r ADD FUNCTION ip6_contains(iprange,ip6); ALTER EXTENSION ip4r ADD FUNCTION ipaddress_contains(iprange,ipaddress); ALTER EXTENSION ip4r ADD FUNCTION ip4_eq(ip4,ip4); ALTER EXTENSION ip4r ADD FUNCTION ip4r_eq(ip4r,ip4r); ALTER EXTENSION ip4r ADD FUNCTION ip6_eq(ip6,ip6); ALTER EXTENSION ip4r ADD FUNCTION ip6r_eq(ip6r,ip6r); ALTER EXTENSION ip4r ADD FUNCTION ipaddress_eq(ipaddress,ipaddress); ALTER EXTENSION ip4r ADD FUNCTION iprange_eq(iprange,iprange); ALTER EXTENSION ip4r ADD OPERATOR =(ip4,ip4); ALTER EXTENSION ip4r ADD OPERATOR =(ip4r,ip4r); ALTER EXTENSION ip4r ADD OPERATOR =(ip6,ip6); ALTER EXTENSION ip4r ADD OPERATOR =(ip6r,ip6r); ALTER EXTENSION ip4r ADD OPERATOR =(ipaddress,ipaddress); ALTER EXTENSION ip4r ADD OPERATOR =(iprange,iprange); ALTER EXTENSION ip4r ADD FUNCTION ip4_ge(ip4,ip4); ALTER EXTENSION ip4r ADD FUNCTION ip4r_ge(ip4r,ip4r); ALTER EXTENSION ip4r ADD FUNCTION ip6_ge(ip6,ip6); ALTER EXTENSION ip4r ADD FUNCTION ip6r_ge(ip6r,ip6r); ALTER EXTENSION ip4r ADD FUNCTION ipaddress_ge(ipaddress,ipaddress); ALTER EXTENSION ip4r ADD FUNCTION iprange_ge(iprange,iprange); ALTER EXTENSION ip4r ADD OPERATOR >=(ip4,ip4); ALTER EXTENSION ip4r ADD OPERATOR >=(ip4r,ip4r); ALTER EXTENSION ip4r ADD OPERATOR >=(ip6,ip6); ALTER EXTENSION ip4r ADD OPERATOR >=(ip6r,ip6r); ALTER EXTENSION ip4r ADD OPERATOR >=(ipaddress,ipaddress); ALTER EXTENSION ip4r ADD OPERATOR >=(iprange,iprange); ALTER EXTENSION ip4r ADD FUNCTION ip4_gt(ip4,ip4); ALTER EXTENSION ip4r ADD FUNCTION ip4r_gt(ip4r,ip4r); ALTER EXTENSION ip4r ADD FUNCTION ip6_gt(ip6,ip6); ALTER EXTENSION ip4r ADD FUNCTION ip6r_gt(ip6r,ip6r); ALTER EXTENSION ip4r ADD FUNCTION ipaddress_gt(ipaddress,ipaddress); ALTER EXTENSION ip4r ADD FUNCTION iprange_gt(iprange,iprange); ALTER EXTENSION ip4r ADD OPERATOR >(ip4,ip4); ALTER EXTENSION ip4r ADD OPERATOR >(ip4r,ip4r); ALTER EXTENSION ip4r ADD OPERATOR >(ip6,ip6); ALTER EXTENSION ip4r ADD OPERATOR >(ip6r,ip6r); ALTER EXTENSION ip4r ADD OPERATOR >(ipaddress,ipaddress); ALTER EXTENSION ip4r ADD OPERATOR >(iprange,iprange); ALTER EXTENSION ip4r ADD FUNCTION ip4_le(ip4,ip4); ALTER EXTENSION ip4r ADD FUNCTION ip4r_le(ip4r,ip4r); ALTER EXTENSION ip4r ADD FUNCTION ip6_le(ip6,ip6); ALTER EXTENSION ip4r ADD FUNCTION ip6r_le(ip6r,ip6r); ALTER EXTENSION ip4r ADD FUNCTION ipaddress_le(ipaddress,ipaddress); ALTER EXTENSION ip4r ADD FUNCTION iprange_le(iprange,iprange); ALTER EXTENSION ip4r ADD OPERATOR <=(ip4,ip4); ALTER EXTENSION ip4r ADD OPERATOR <=(ip4r,ip4r); ALTER EXTENSION ip4r ADD OPERATOR <=(ip6,ip6); ALTER EXTENSION ip4r ADD OPERATOR <=(ip6r,ip6r); ALTER EXTENSION ip4r ADD OPERATOR <=(ipaddress,ipaddress); ALTER EXTENSION ip4r ADD OPERATOR <=(iprange,iprange); ALTER EXTENSION ip4r ADD FUNCTION ip4_lt(ip4,ip4); ALTER EXTENSION ip4r ADD FUNCTION ip4r_lt(ip4r,ip4r); ALTER EXTENSION ip4r ADD FUNCTION ip6_lt(ip6,ip6); ALTER EXTENSION ip4r ADD FUNCTION ip6r_lt(ip6r,ip6r); ALTER EXTENSION ip4r ADD FUNCTION ipaddress_lt(ipaddress,ipaddress); ALTER EXTENSION ip4r ADD FUNCTION iprange_lt(iprange,iprange); ALTER EXTENSION ip4r ADD OPERATOR <(ip4,ip4); ALTER EXTENSION ip4r ADD OPERATOR <(ip4r,ip4r); ALTER EXTENSION ip4r ADD OPERATOR <(ip6,ip6); ALTER EXTENSION ip4r ADD OPERATOR <(ip6r,ip6r); ALTER EXTENSION ip4r ADD OPERATOR <(ipaddress,ipaddress); ALTER EXTENSION ip4r ADD OPERATOR <(iprange,iprange); ALTER EXTENSION ip4r ADD FUNCTION ip4_neq(ip4,ip4); ALTER EXTENSION ip4r ADD FUNCTION ip4r_neq(ip4r,ip4r); ALTER EXTENSION ip4r ADD FUNCTION ip6_neq(ip6,ip6); ALTER EXTENSION ip4r ADD FUNCTION ip6r_neq(ip6r,ip6r); ALTER EXTENSION ip4r ADD FUNCTION ipaddress_neq(ipaddress,ipaddress); ALTER EXTENSION ip4r ADD FUNCTION iprange_neq(iprange,iprange); ALTER EXTENSION ip4r ADD OPERATOR <>(ip4,ip4); ALTER EXTENSION ip4r ADD OPERATOR <>(ip4r,ip4r); ALTER EXTENSION ip4r ADD OPERATOR <>(ip6,ip6); ALTER EXTENSION ip4r ADD OPERATOR <>(ip6r,ip6r); ALTER EXTENSION ip4r ADD OPERATOR <>(ipaddress,ipaddress); ALTER EXTENSION ip4r ADD OPERATOR <>(iprange,iprange); ALTER EXTENSION ip4r ADD FUNCTION ip4_cmp(ip4,ip4); ALTER EXTENSION ip4r ADD FUNCTION ip4r_cmp(ip4r,ip4r); ALTER EXTENSION ip4r ADD FUNCTION ip6_cmp(ip6,ip6); ALTER EXTENSION ip4r ADD FUNCTION ip6r_cmp(ip6r,ip6r); ALTER EXTENSION ip4r ADD FUNCTION ipaddress_cmp(ipaddress,ipaddress); ALTER EXTENSION ip4r ADD FUNCTION iprange_cmp(iprange,iprange); ALTER EXTENSION ip4r ADD OPERATOR CLASS btree_ip4_ops; ALTER EXTENSION ip4r ADD OPERATOR CLASS btree_ip4r_ops; ALTER EXTENSION ip4r ADD OPERATOR CLASS btree_ip6_ops; ALTER EXTENSION ip4r ADD OPERATOR CLASS btree_ip6r_ops; ALTER EXTENSION ip4r ADD OPERATOR CLASS btree_ipaddress_ops; ALTER EXTENSION ip4r ADD OPERATOR CLASS btree_iprange_ops; ALTER EXTENSION ip4r ADD FUNCTION ip4hash(ip4); ALTER EXTENSION ip4r ADD FUNCTION ip6hash(ip6); ALTER EXTENSION ip4r ADD FUNCTION ipaddresshash(ipaddress); ALTER EXTENSION ip4r ADD FUNCTION ip4rhash(ip4r); ALTER EXTENSION ip4r ADD FUNCTION ip6rhash(ip6r); ALTER EXTENSION ip4r ADD FUNCTION iprangehash(iprange); ALTER EXTENSION ip4r ADD OPERATOR CLASS hash_ip4_ops; ALTER EXTENSION ip4r ADD OPERATOR CLASS hash_ip4r_ops; ALTER EXTENSION ip4r ADD OPERATOR CLASS hash_ip6_ops; ALTER EXTENSION ip4r ADD OPERATOR CLASS hash_ip6r_ops; ALTER EXTENSION ip4r ADD OPERATOR CLASS hash_ipaddress_ops; ALTER EXTENSION ip4r ADD OPERATOR CLASS hash_iprange_ops; ALTER EXTENSION ip4r ADD FUNCTION gip4r_consistent(internal,ip4r,int4); ALTER EXTENSION ip4r ADD FUNCTION gip4r_compress(internal); ALTER EXTENSION ip4r ADD FUNCTION gip4r_decompress(internal); ALTER EXTENSION ip4r ADD FUNCTION gip4r_penalty(internal,internal,internal); ALTER EXTENSION ip4r ADD FUNCTION gip4r_picksplit(internal, internal); ALTER EXTENSION ip4r ADD FUNCTION gip4r_union(internal, internal); ALTER EXTENSION ip4r ADD FUNCTION gip4r_same(ip4r, ip4r, internal); ALTER EXTENSION ip4r ADD FUNCTION gip6r_consistent(internal,ip6r,int4); ALTER EXTENSION ip4r ADD FUNCTION gip6r_compress(internal); ALTER EXTENSION ip4r ADD FUNCTION gip6r_decompress(internal); ALTER EXTENSION ip4r ADD FUNCTION gip6r_penalty(internal,internal,internal); ALTER EXTENSION ip4r ADD FUNCTION gip6r_picksplit(internal, internal); ALTER EXTENSION ip4r ADD FUNCTION gip6r_union(internal, internal); ALTER EXTENSION ip4r ADD FUNCTION gip6r_same(ip6r, ip6r, internal); ALTER EXTENSION ip4r ADD FUNCTION gipr_consistent(internal,iprange,int4); ALTER EXTENSION ip4r ADD FUNCTION gipr_compress(internal); ALTER EXTENSION ip4r ADD FUNCTION gipr_decompress(internal); ALTER EXTENSION ip4r ADD FUNCTION gipr_penalty(internal,internal,internal); ALTER EXTENSION ip4r ADD FUNCTION gipr_picksplit(internal, internal); ALTER EXTENSION ip4r ADD FUNCTION gipr_union(internal, internal); ALTER EXTENSION ip4r ADD FUNCTION gipr_same(iprange, iprange, internal); ALTER EXTENSION ip4r ADD OPERATOR CLASS gist_ip4r_ops; ALTER EXTENSION ip4r ADD OPERATOR CLASS gist_ip6r_ops; ALTER EXTENSION ip4r ADD OPERATOR CLASS gist_iprange_ops; -- end ip4r-2.0.2/ip4r.c000066400000000000000000001062161233620317400134220ustar00rootroot00000000000000/* $Id: ip4r.c,v 1.12 2011/08/22 14:05:19 andrewsn Exp $ */ #include "ipr.h" #include "ip4r_funcs.h" /* extract an IP range from text. */ static bool ip4r_from_str(char *str, IP4R *ipr) { char buf[IP4_STRING_MAX]; int pos = strcspn(str, "-/"); IP4 ip; switch (str[pos]) { case 0: /* no separator, must be single ip4 addr */ { if (!ip4_raw_input(str, &ip)) return FALSE; ipr->lower = ip; ipr->upper = ip; return TRUE; } case '-': /* lower-upper */ { char *rest = str + pos + 1; if (pos >= sizeof(buf)) return FALSE; memcpy(buf, str, pos); buf[pos] = 0; if (!ip4_raw_input(buf, &ip)) return FALSE; ipr->lower = ip; if (!ip4_raw_input(rest, &ip)) return FALSE; if (!ip4_lessthan(ip, ipr->lower)) ipr->upper = ip; else { ipr->upper = ipr->lower; ipr->lower = ip; } return TRUE; } case '/': /* prefix/len */ { char *rest = str + pos + 1; unsigned pfxlen; char dummy; if (pos >= sizeof(buf)) return FALSE; memcpy(buf, str, pos); buf[pos] = 0; if (!ip4_raw_input(buf, &ip)) return FALSE; if (rest[strspn(rest,"0123456789")]) return FALSE; if (sscanf(rest, "%u%c", &pfxlen, &dummy) != 1) return FALSE; return ip4r_from_cidr(ip, pfxlen, ipr); } default: return FALSE; /* can't happen */ } } /* Output an ip range in text form */ static inline int ip4r_to_str(IP4R *ipr, char *str, int slen) { char buf1[IP4_STRING_MAX]; char buf2[IP4_STRING_MAX]; unsigned msk; if (ip4_equal(ipr->lower, ipr->upper)) return ip4_raw_output(ipr->lower, str, slen); if ((msk = masklen(ipr->lower,ipr->upper)) <= 32) { ip4_raw_output(ipr->lower, buf1, sizeof(buf1)); return snprintf(str, slen, "%s/%u", buf1, msk); } ip4_raw_output(ipr->lower, buf1, sizeof(buf1)); ip4_raw_output(ipr->upper, buf2, sizeof(buf2)); return snprintf(str, slen, "%s-%s", buf1, buf2); } /**************************************************************************/ /* This part handles all aspects of postgres interfacing. */ static text * make_text(char *str, int len) { text *ret = (text *) palloc(len + VARHDRSZ); SET_VARSIZE(ret, len + VARHDRSZ); if (str) memcpy(VARDATA(ret), str, len); else memset(VARDATA(ret), 0, len); return ret; } static inline void set_text_len(text *txt, int len) { if ((len + VARHDRSZ) < VARSIZE(txt)) SET_VARSIZE(txt, len + VARHDRSZ); } static inline int get_text_len(text *txt) { return VARSIZE(txt) - VARHDRSZ; } /* ** Input/Output routines */ PG_FUNCTION_INFO_V1(ip4_in); Datum ip4_in(PG_FUNCTION_ARGS) { char *str = PG_GETARG_CSTRING(0); IP4 ip; if (ip4_raw_input(str, &ip)) PG_RETURN_IP4(ip); ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("invalid IP4 value: '%s'", str))); PG_RETURN_NULL(); } PG_FUNCTION_INFO_V1(ip4_out); Datum ip4_out(PG_FUNCTION_ARGS) { IP4 ip = PG_GETARG_IP4(0); char *out = palloc(IP4_STRING_MAX); ip4_raw_output(ip, out, IP4_STRING_MAX); PG_RETURN_CSTRING(out); } PG_FUNCTION_INFO_V1(ip4_recv); Datum ip4_recv(PG_FUNCTION_ARGS) { StringInfo buf = (StringInfo) PG_GETARG_POINTER(0); PG_RETURN_IP4((IP4) pq_getmsgint(buf, sizeof(IP4))); } PG_FUNCTION_INFO_V1(ip4_send); Datum ip4_send(PG_FUNCTION_ARGS) { IP4 arg1 = PG_GETARG_IP4(0); StringInfoData buf; pq_begintypsend(&buf); pq_sendint(&buf, arg1, sizeof(IP4)); PG_RETURN_BYTEA_P(pq_endtypsend(&buf)); } PG_FUNCTION_INFO_V1(ip4hash); Datum ip4hash(PG_FUNCTION_ARGS) { IP4 arg1 = PG_GETARG_IP4(0); return hash_any((unsigned char *)&arg1, sizeof(IP4)); } PG_FUNCTION_INFO_V1(ip4_cast_to_text); Datum ip4_cast_to_text(PG_FUNCTION_ARGS) { IP4 ip = PG_GETARG_IP4(0); text *out = make_text(NULL,IP4_STRING_MAX); set_text_len(out, ip4_raw_output(ip, VARDATA(out), IP4_STRING_MAX)); PG_RETURN_TEXT_P(out); } PG_FUNCTION_INFO_V1(ip4_cast_from_text); Datum ip4_cast_from_text(PG_FUNCTION_ARGS) { text *txt = PG_GETARG_TEXT_P(0); int tlen = get_text_len(txt); char buf[IP4_STRING_MAX]; if (tlen < sizeof(buf)) { IP4 ip; memcpy(buf, VARDATA(txt), tlen); buf[tlen] = 0; if (ip4_raw_input(buf, &ip)) PG_RETURN_IP4(ip); } ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("invalid IP4 value in text"))); PG_RETURN_NULL(); } PG_FUNCTION_INFO_V1(ip4_cast_from_inet); Datum ip4_cast_from_inet(PG_FUNCTION_ARGS) { inet *inetptr = PG_GETARG_INET_P(0); inet_struct *in = INET_STRUCT_DATA(inetptr); if (in->family == PGSQL_AF_INET) { unsigned char *p = in->ipaddr; IP4 ip = (p[0] << 24)|(p[1] << 16)|(p[2] << 8)|p[3]; PG_RETURN_IP4(ip); } ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("invalid INET value for conversion to IP4"))); PG_RETURN_NULL(); } PG_FUNCTION_INFO_V1(ip4_cast_to_cidr); Datum ip4_cast_to_cidr(PG_FUNCTION_ARGS) { IP4 ip = PG_GETARG_IP4(0); inet *res = palloc0(VARHDRSZ + sizeof(inet_struct)); inet_struct *in; SET_VARSIZE(res, VARHDRSZ + offsetof(inet_struct, ipaddr) + 4); in = ((inet_struct *)VARDATA(res)); INET_INIT_CIDR(in); in->bits = 32; in->family = PGSQL_AF_INET; { unsigned char *p = in->ipaddr; p[0] = (ip >> 24) & 0xff; p[1] = (ip >> 16) & 0xff; p[2] = (ip >> 8) & 0xff; p[3] = (ip ) & 0xff; } PG_RETURN_INET_P(res); } PG_FUNCTION_INFO_V1(ip4_cast_to_bigint); Datum ip4_cast_to_bigint(PG_FUNCTION_ARGS) { IP4 ip = PG_GETARG_IP4(0); PG_RETURN_INT64(ip); } PG_FUNCTION_INFO_V1(ip4_cast_to_numeric); Datum ip4_cast_to_numeric(PG_FUNCTION_ARGS) { IP4 ip = PG_GETARG_IP4(0); int64 v = ip; PG_RETURN_DATUM(DirectFunctionCall1(int8_numeric, Int64GetDatumFast(v))); } PG_FUNCTION_INFO_V1(ip4_cast_from_bigint); Datum ip4_cast_from_bigint(PG_FUNCTION_ARGS) { int64 val = PG_GETARG_INT64(0); if (val < -(int64)0x80000000UL || val > (int64)0xFFFFFFFFUL) ereport(ERROR, (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), errmsg("ip address out of range"))); PG_RETURN_IP4(val); } PG_FUNCTION_INFO_V1(ip4_cast_to_double); Datum ip4_cast_to_double(PG_FUNCTION_ARGS) { IP4 ip = PG_GETARG_IP4(0); PG_RETURN_FLOAT8(ip); } PG_FUNCTION_INFO_V1(ip4_cast_from_double); Datum ip4_cast_from_double(PG_FUNCTION_ARGS) { float8 val = PG_GETARG_FLOAT8(0); float8 ival = 0; if (modf(val,&ival) != 0.0) { ereport(WARNING, (errcode(ERRCODE_WARNING), errmsg("double converted to IP4 is not integral"))); } if (ival < -(float8)0x80000000UL || ival > (float8)0xFFFFFFFFUL) ereport(ERROR, (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), errmsg("ip address out of range"))); PG_RETURN_IP4((unsigned long) ival); } PG_FUNCTION_INFO_V1(ip4_cast_from_numeric); Datum ip4_cast_from_numeric(PG_FUNCTION_ARGS) { Datum val_num = PG_GETARG_DATUM(0); int64 val = DatumGetInt64(DirectFunctionCall1(numeric_int8,val_num)); if (val < -(int64)0x80000000UL || val > (int64)0xFFFFFFFFUL) ereport(ERROR, (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), errmsg("ip address out of range"))); PG_RETURN_IP4((unsigned long) val); } PG_FUNCTION_INFO_V1(ip4_netmask); Datum ip4_netmask(PG_FUNCTION_ARGS) { int pfxlen = PG_GETARG_INT32(0); if (pfxlen < 0 || pfxlen > 32) { ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("prefix length out of range"))); } PG_RETURN_IP4( netmask(pfxlen) ); } PG_FUNCTION_INFO_V1(ip4_net_lower); Datum ip4_net_lower(PG_FUNCTION_ARGS) { IP4 ip = PG_GETARG_IP4(0); int pfxlen = PG_GETARG_INT32(1); if (pfxlen < 0 || pfxlen > 32) { ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("prefix length out of range"))); } PG_RETURN_IP4( ip & netmask(pfxlen) ); } PG_FUNCTION_INFO_V1(ip4_net_upper); Datum ip4_net_upper(PG_FUNCTION_ARGS) { IP4 ip = PG_GETARG_IP4(0); int pfxlen = PG_GETARG_INT32(1); if (pfxlen < 0 || pfxlen > 32) { ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("prefix length out of range"))); } PG_RETURN_IP4( ip | hostmask(pfxlen) ); } PG_FUNCTION_INFO_V1(ip4_plus_int); Datum ip4_plus_int(PG_FUNCTION_ARGS) { IP4 ip = PG_GETARG_IP4(0); int addend = PG_GETARG_INT32(1); IP4 result = ip + (IP4) addend; if ((addend < 0) != (result < ip)) { ereport(ERROR, (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), errmsg("ip address out of range"))); } PG_RETURN_IP4(result); } PG_FUNCTION_INFO_V1(ip4_plus_bigint); Datum ip4_plus_bigint(PG_FUNCTION_ARGS) { IP4 ip = PG_GETARG_IP4(0); int64 addend = PG_GETARG_INT64(1); int64 result = (int64) ip + addend; if (((addend < 0) != (result < ip)) || result != (int64)(IP4)result) { ereport(ERROR, (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), errmsg("ip address out of range"))); } PG_RETURN_IP4( (IP4)(result) ); } PG_FUNCTION_INFO_V1(ip4_plus_numeric); Datum ip4_plus_numeric(PG_FUNCTION_ARGS) { IP4 ip = PG_GETARG_IP4(0); Datum addend_num = PG_GETARG_DATUM(1); int64 addend = DatumGetInt64(DirectFunctionCall1(numeric_int8,addend_num)); int64 result = (int64) ip + addend; if (((addend < 0) != (result < ip)) || result != (int64)(IP4)result) { ereport(ERROR, (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), errmsg("ip address out of range"))); } PG_RETURN_IP4( (IP4)(result) ); } PG_FUNCTION_INFO_V1(ip4_minus_int); Datum ip4_minus_int(PG_FUNCTION_ARGS) { IP4 ip = PG_GETARG_IP4(0); int subtrahend = PG_GETARG_INT32(1); IP4 result = ip - (IP4) subtrahend; if ((subtrahend > 0) != (result < ip)) { ereport(ERROR, (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), errmsg("ip address out of range"))); } PG_RETURN_IP4(result); } PG_FUNCTION_INFO_V1(ip4_minus_bigint); Datum ip4_minus_bigint(PG_FUNCTION_ARGS) { IP4 ip = PG_GETARG_IP4(0); int64 subtrahend = PG_GETARG_INT64(1); int64 result = (int64) ip - subtrahend; if (((subtrahend > 0) != (result < ip)) || result != (int64)(IP4)result) { ereport(ERROR, (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), errmsg("ip address out of range"))); } PG_RETURN_IP4( (IP4)(result) ); } PG_FUNCTION_INFO_V1(ip4_minus_numeric); Datum ip4_minus_numeric(PG_FUNCTION_ARGS) { IP4 ip = PG_GETARG_IP4(0); Datum subtrahend_num = PG_GETARG_DATUM(1); int64 subtrahend = DatumGetInt64(DirectFunctionCall1(numeric_int8,subtrahend_num)); int64 result = (int64) ip - subtrahend; if (((subtrahend > 0) != (result < ip)) || result != (int64)(IP4)result) { ereport(ERROR, (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), errmsg("ip address out of range"))); } PG_RETURN_IP4( (IP4)(result) ); } PG_FUNCTION_INFO_V1(ip4_minus_ip4); Datum ip4_minus_ip4(PG_FUNCTION_ARGS) { IP4 minuend = PG_GETARG_IP4(0); IP4 subtrahend = PG_GETARG_IP4(1); int64 result = (int64) minuend - (int64) subtrahend; PG_RETURN_INT64(result); } PG_FUNCTION_INFO_V1(ip4_and); Datum ip4_and(PG_FUNCTION_ARGS) { IP4 a = PG_GETARG_IP4(0); IP4 b = PG_GETARG_IP4(1); PG_RETURN_IP4(a & b); } PG_FUNCTION_INFO_V1(ip4_or); Datum ip4_or(PG_FUNCTION_ARGS) { IP4 a = PG_GETARG_IP4(0); IP4 b = PG_GETARG_IP4(1); PG_RETURN_IP4(a | b); } PG_FUNCTION_INFO_V1(ip4_xor); Datum ip4_xor(PG_FUNCTION_ARGS) { IP4 a = PG_GETARG_IP4(0); IP4 b = PG_GETARG_IP4(1); PG_RETURN_IP4(a ^ b); } PG_FUNCTION_INFO_V1(ip4_not); Datum ip4_not(PG_FUNCTION_ARGS) { IP4 a = PG_GETARG_IP4(0); PG_RETURN_IP4(~a); } /*---- ip4r ----*/ PG_FUNCTION_INFO_V1(ip4r_in); Datum ip4r_in(PG_FUNCTION_ARGS) { char *str = PG_GETARG_CSTRING(0); IP4R ipr; if (ip4r_from_str(str, &ipr)) { IP4R *res = palloc(sizeof(IP4R)); *res = ipr; PG_RETURN_IP4R_P(res); } ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("invalid IP4R value: \"%s\"", str))); PG_RETURN_NULL(); } PG_FUNCTION_INFO_V1(ip4r_out); Datum ip4r_out(PG_FUNCTION_ARGS) { IP4R *ipr = PG_GETARG_IP4R_P(0); char *out = palloc(IP4R_STRING_MAX); ip4r_to_str(ipr, out, IP4R_STRING_MAX); PG_RETURN_CSTRING(out); } PG_FUNCTION_INFO_V1(ip4r_recv); Datum ip4r_recv(PG_FUNCTION_ARGS) { StringInfo buf = (StringInfo) PG_GETARG_POINTER(0); IP4R *ipr = palloc(sizeof(IP4R)); ipr->lower = (IP4) pq_getmsgint(buf, sizeof(IP4)); ipr->upper = (IP4) pq_getmsgint(buf, sizeof(IP4)); PG_RETURN_IP4R_P(ipr); } PG_FUNCTION_INFO_V1(ip4r_send); Datum ip4r_send(PG_FUNCTION_ARGS) { IP4R *ipr = PG_GETARG_IP4R_P(0); StringInfoData buf; pq_begintypsend(&buf); pq_sendint(&buf, ipr->lower, sizeof(IP4)); pq_sendint(&buf, ipr->upper, sizeof(IP4)); PG_RETURN_BYTEA_P(pq_endtypsend(&buf)); } PG_FUNCTION_INFO_V1(ip4rhash); Datum ip4rhash(PG_FUNCTION_ARGS) { IP4R *arg1 = PG_GETARG_IP4R_P(0); return hash_any((unsigned char *)arg1, sizeof(IP4R)); } PG_FUNCTION_INFO_V1(ip4r_cast_to_text); Datum ip4r_cast_to_text(PG_FUNCTION_ARGS) { IP4R *ipr = PG_GETARG_IP4R_P(0); text *out = make_text(NULL,IP4R_STRING_MAX); set_text_len(out, ip4r_to_str(ipr, VARDATA(out), IP4R_STRING_MAX)); PG_RETURN_TEXT_P(out); } PG_FUNCTION_INFO_V1(ip4r_cast_from_text); Datum ip4r_cast_from_text(PG_FUNCTION_ARGS) { text *txt = PG_GETARG_TEXT_P(0); int tlen = get_text_len(txt); char buf[IP4R_STRING_MAX]; if (tlen < sizeof(buf)) { IP4R ipr; memcpy(buf, VARDATA(txt), tlen); buf[tlen] = 0; if (ip4r_from_str(buf, &ipr)) { IP4R *res = palloc(sizeof(IP4R)); *res = ipr; PG_RETURN_IP4R_P(res); } } ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("invalid IP4R value in text"))); PG_RETURN_NULL(); } PG_FUNCTION_INFO_V1(ip4r_cast_from_cidr); Datum ip4r_cast_from_cidr(PG_FUNCTION_ARGS) { inet *inetptr = PG_GETARG_INET_P(0); inet_struct *in = INET_STRUCT_DATA(inetptr); if (INET_IS_CIDR(in) && in->family == PGSQL_AF_INET) { unsigned char *p = in->ipaddr; IP4 ip = (p[0] << 24)|(p[1] << 16)|(p[2] << 8)|p[3]; IP4R ipr; if (ip4r_from_cidr(ip, in->bits, &ipr)) { IP4R *res = palloc(sizeof(IP4R)); *res = ipr; PG_RETURN_IP4R_P(res); } } ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("invalid CIDR value for conversion to IP4R"))); PG_RETURN_NULL(); } PG_FUNCTION_INFO_V1(ip4r_cast_to_cidr); Datum ip4r_cast_to_cidr(PG_FUNCTION_ARGS) { IP4R *ipr = PG_GETARG_IP4R_P(0); IP4 ip = ipr->lower; inet *res; inet_struct *in; unsigned bits = masklen(ip, ipr->upper); if (bits > 32) PG_RETURN_NULL(); res = palloc0(VARHDRSZ + sizeof(inet_struct)); SET_VARSIZE(res, VARHDRSZ + offsetof(inet_struct, ipaddr) + 4); in = ((inet_struct *)VARDATA(res)); INET_INIT_CIDR(in); in->bits = bits; in->family = PGSQL_AF_INET; { unsigned char *p = in->ipaddr; p[0] = (ip >> 24) & 0xff; p[1] = (ip >> 16) & 0xff; p[2] = (ip >> 8) & 0xff; p[3] = (ip ) & 0xff; } PG_RETURN_INET_P(res); } PG_FUNCTION_INFO_V1(ip4r_cast_from_ip4); Datum ip4r_cast_from_ip4(PG_FUNCTION_ARGS) { IP4 ip = PG_GETARG_IP4(0); IP4R *res = palloc(sizeof(IP4R)); if (ip4r_from_inet(ip, 32, res)) { PG_RETURN_IP4R_P(res); } pfree(res); ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("invalid IP4 value for conversion to IP4R (shouldn't be possible)"))); PG_RETURN_NULL(); } PG_FUNCTION_INFO_V1(ip4r_from_ip4s); Datum ip4r_from_ip4s(PG_FUNCTION_ARGS) { IP4 a = PG_GETARG_IP4(0); IP4 b = PG_GETARG_IP4(1); IP4R *res = palloc(sizeof(IP4R)); if (a < b) res->lower = a, res->upper = b; else res->lower = b, res->upper = a; PG_RETURN_IP4R_P( res ); } PG_FUNCTION_INFO_V1(ip4r_net_prefix); Datum ip4r_net_prefix(PG_FUNCTION_ARGS) { IP4 ip = PG_GETARG_IP4(0); int pfxlen = PG_GETARG_INT32(1); if (pfxlen < 0 || pfxlen > 32) { ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("prefix length out of range"))); } { IP4 mask = netmask(pfxlen); IP4R *res = palloc(sizeof(IP4R)); res->lower = ip & mask; res->upper = ip | ~mask; PG_RETURN_IP4R_P(res); } } PG_FUNCTION_INFO_V1(ip4r_net_mask); Datum ip4r_net_mask(PG_FUNCTION_ARGS) { IP4 ip = PG_GETARG_IP4(0); IP4 mask = PG_GETARG_IP4(1); if (!ip4_valid_netmask(mask)) { ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("invalid netmask"))); } { IP4R *res = palloc(sizeof(IP4R)); res->lower = ip & mask; res->upper = ip | ~mask; PG_RETURN_IP4R_P(res); } } PG_FUNCTION_INFO_V1(ip4r_lower); Datum ip4r_lower(PG_FUNCTION_ARGS) { IP4R *ipr = PG_GETARG_IP4R_P(0); PG_RETURN_IP4( ipr->lower ); } PG_FUNCTION_INFO_V1(ip4r_upper); Datum ip4r_upper(PG_FUNCTION_ARGS) { IP4R *ipr = PG_GETARG_IP4R_P(0); PG_RETURN_IP4( ipr->upper ); } PG_FUNCTION_INFO_V1(ip4r_is_cidr); Datum ip4r_is_cidr(PG_FUNCTION_ARGS) { IP4R *ipr = PG_GETARG_IP4R_P(0); PG_RETURN_BOOL( (masklen(ipr->lower,ipr->upper) <= 32U) ); } PG_FUNCTION_INFO_V1(ip4_lt); Datum ip4_lt(PG_FUNCTION_ARGS) { PG_RETURN_BOOL( ip4_lessthan(PG_GETARG_IP4(0), PG_GETARG_IP4(1)) ); } PG_FUNCTION_INFO_V1(ip4_le); Datum ip4_le(PG_FUNCTION_ARGS) { PG_RETURN_BOOL( ip4_less_eq(PG_GETARG_IP4(0), PG_GETARG_IP4(1)) ); } PG_FUNCTION_INFO_V1(ip4_gt); Datum ip4_gt(PG_FUNCTION_ARGS) { PG_RETURN_BOOL( ip4_lessthan(PG_GETARG_IP4(1), PG_GETARG_IP4(0)) ); } PG_FUNCTION_INFO_V1(ip4_ge); Datum ip4_ge(PG_FUNCTION_ARGS) { PG_RETURN_BOOL( ip4_less_eq(PG_GETARG_IP4(1), PG_GETARG_IP4(0)) ); } PG_FUNCTION_INFO_V1(ip4_eq); Datum ip4_eq(PG_FUNCTION_ARGS) { PG_RETURN_BOOL( ip4_equal(PG_GETARG_IP4(0), PG_GETARG_IP4(1)) ); } PG_FUNCTION_INFO_V1(ip4_neq); Datum ip4_neq(PG_FUNCTION_ARGS) { PG_RETURN_BOOL( !ip4_equal(PG_GETARG_IP4(0), PG_GETARG_IP4(1)) ); } PG_FUNCTION_INFO_V1(ip4r_lt); Datum ip4r_lt(PG_FUNCTION_ARGS) { PG_RETURN_BOOL( ip4r_lessthan(PG_GETARG_IP4R_P(0), PG_GETARG_IP4R_P(1)) ); } PG_FUNCTION_INFO_V1(ip4r_le); Datum ip4r_le(PG_FUNCTION_ARGS) { PG_RETURN_BOOL( ip4r_less_eq(PG_GETARG_IP4R_P(0), PG_GETARG_IP4R_P(1)) ); } PG_FUNCTION_INFO_V1(ip4r_gt); Datum ip4r_gt(PG_FUNCTION_ARGS) { PG_RETURN_BOOL( ip4r_lessthan(PG_GETARG_IP4R_P(1), PG_GETARG_IP4R_P(0)) ); } PG_FUNCTION_INFO_V1(ip4r_ge); Datum ip4r_ge(PG_FUNCTION_ARGS) { PG_RETURN_BOOL( ip4r_less_eq(PG_GETARG_IP4R_P(1), PG_GETARG_IP4R_P(0)) ); } PG_FUNCTION_INFO_V1(ip4r_eq); Datum ip4r_eq(PG_FUNCTION_ARGS) { PG_RETURN_BOOL( ip4r_equal(PG_GETARG_IP4R_P(0), PG_GETARG_IP4R_P(1)) ); } PG_FUNCTION_INFO_V1(ip4r_neq); Datum ip4r_neq(PG_FUNCTION_ARGS) { PG_RETURN_BOOL( !ip4r_equal(PG_GETARG_IP4R_P(0), PG_GETARG_IP4R_P(1)) ); } PG_FUNCTION_INFO_V1(ip4r_overlaps); Datum ip4r_overlaps(PG_FUNCTION_ARGS) { PG_RETURN_BOOL( ip4r_overlaps_internal(PG_GETARG_IP4R_P(0), PG_GETARG_IP4R_P(1)) ); } PG_FUNCTION_INFO_V1(ip4r_contains); Datum ip4r_contains(PG_FUNCTION_ARGS) { PG_RETURN_BOOL( ip4r_contains_internal(PG_GETARG_IP4R_P(0), PG_GETARG_IP4R_P(1), TRUE) ); } PG_FUNCTION_INFO_V1(ip4r_contains_strict); Datum ip4r_contains_strict(PG_FUNCTION_ARGS) { PG_RETURN_BOOL( ip4r_contains_internal(PG_GETARG_IP4R_P(0), PG_GETARG_IP4R_P(1), FALSE) ); } PG_FUNCTION_INFO_V1(ip4r_contained_by); Datum ip4r_contained_by(PG_FUNCTION_ARGS) { PG_RETURN_BOOL( ip4r_contains_internal(PG_GETARG_IP4R_P(1), PG_GETARG_IP4R_P(0), TRUE) ); } PG_FUNCTION_INFO_V1(ip4r_contained_by_strict); Datum ip4r_contained_by_strict(PG_FUNCTION_ARGS) { PG_RETURN_BOOL( ip4r_contains_internal(PG_GETARG_IP4R_P(1), PG_GETARG_IP4R_P(0), FALSE) ); } PG_FUNCTION_INFO_V1(ip4_contains); Datum ip4_contains(PG_FUNCTION_ARGS) { PG_RETURN_BOOL( ip4_contains_internal(PG_GETARG_IP4R_P(0), PG_GETARG_IP4(1)) ); } PG_FUNCTION_INFO_V1(ip4_contained_by); Datum ip4_contained_by(PG_FUNCTION_ARGS) { PG_RETURN_BOOL( ip4_contains_internal(PG_GETARG_IP4R_P(1), PG_GETARG_IP4(0)) ); } PG_FUNCTION_INFO_V1(ip4r_left_of); Datum ip4r_left_of(PG_FUNCTION_ARGS) { PG_RETURN_BOOL( ip4r_left_internal(PG_GETARG_IP4R_P(0), PG_GETARG_IP4R_P(1)) ); } PG_FUNCTION_INFO_V1(ip4r_right_of); Datum ip4r_right_of(PG_FUNCTION_ARGS) { PG_RETURN_BOOL( ip4r_left_internal(PG_GETARG_IP4R_P(1), PG_GETARG_IP4R_P(0)) ); } PG_FUNCTION_INFO_V1(ip4r_union); Datum ip4r_union(PG_FUNCTION_ARGS) { IP4R *res = (IP4R *) palloc(sizeof(IP4R)); ip4r_union_internal(PG_GETARG_IP4R_P(0), PG_GETARG_IP4R_P(1), res); PG_RETURN_IP4R_P(res); } PG_FUNCTION_INFO_V1(ip4r_inter); Datum ip4r_inter(PG_FUNCTION_ARGS) { IP4R *res = (IP4R *) palloc(sizeof(IP4R)); if (ip4r_inter_internal(PG_GETARG_IP4R_P(0), PG_GETARG_IP4R_P(1), res)) { PG_RETURN_IP4R_P(res); } pfree(res); PG_RETURN_NULL(); } PG_FUNCTION_INFO_V1(ip4r_size); Datum ip4r_size(PG_FUNCTION_ARGS) { double size = ip4r_metric(PG_GETARG_IP4R_P(0)); PG_RETURN_FLOAT8(size); } PG_FUNCTION_INFO_V1(ip4r_size_exact); Datum ip4r_size_exact(PG_FUNCTION_ARGS) { int64 size = (int64) ip4r_metric(PG_GETARG_IP4R_P(0)); PG_RETURN_DATUM(DirectFunctionCall1(int8_numeric, Int64GetDatumFast(size))); } PG_FUNCTION_INFO_V1(ip4r_prefixlen); Datum ip4r_prefixlen(PG_FUNCTION_ARGS) { IP4R *ipr = PG_GETARG_IP4R_P(0); unsigned len = masklen(ipr->lower, ipr->upper); if (len <= 32) PG_RETURN_INT32((int32) len); PG_RETURN_NULL(); } /***************************************************************************** * Btree functions *****************************************************************************/ PG_FUNCTION_INFO_V1(ip4r_cmp); Datum ip4r_cmp(PG_FUNCTION_ARGS) { IP4R *a = PG_GETARG_IP4R_P(0); IP4R *b = PG_GETARG_IP4R_P(1); if (ip4r_lessthan(a,b)) PG_RETURN_INT32(-1); if (ip4r_equal(a,b)) PG_RETURN_INT32(0); PG_RETURN_INT32(1); } PG_FUNCTION_INFO_V1(ip4_cmp); Datum ip4_cmp(PG_FUNCTION_ARGS) { IP4 a = PG_GETARG_IP4(0); IP4 b = PG_GETARG_IP4(1); if (ip4_lessthan(a,b)) PG_RETURN_INT32(-1); if (ip4_equal(a,b)) PG_RETURN_INT32(0); PG_RETURN_INT32(1); } /***************************************************************************** * GiST functions *****************************************************************************/ /* ** GiST support methods */ Datum gip4r_consistent(PG_FUNCTION_ARGS); Datum gip4r_compress(PG_FUNCTION_ARGS); Datum gip4r_decompress(PG_FUNCTION_ARGS); Datum gip4r_penalty(PG_FUNCTION_ARGS); Datum gip4r_picksplit(PG_FUNCTION_ARGS); Datum gip4r_union(PG_FUNCTION_ARGS); Datum gip4r_same(PG_FUNCTION_ARGS); static bool gip4r_leaf_consistent(IP4R * key, IP4R * query, StrategyNumber strategy); static bool gip4r_internal_consistent(IP4R * key, IP4R * query, StrategyNumber strategy); /* ** The GiST Consistent method for IP ranges ** Should return false if for all data items x below entry, ** the predicate x op query == FALSE, where op is the oper ** corresponding to strategy in the pg_amop table. */ PG_FUNCTION_INFO_V1(gip4r_consistent); Datum gip4r_consistent(PG_FUNCTION_ARGS) { GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); IP4R *query = (IP4R *) PG_GETARG_POINTER(1); StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2); bool *recheck = GIST_RECHECK_ARG; IP4R *key = (IP4R *) DatumGetPointer(entry->key); bool retval; /* recheck is never needed with this type */ if (recheck) *recheck = false; /* * * if entry is not leaf, use gip4r_internal_consistent, * else use * gip4r_leaf_consistent */ if (GIST_LEAF(entry)) retval = gip4r_leaf_consistent(key, query, strategy); else retval = gip4r_internal_consistent(key, query, strategy); PG_RETURN_BOOL(retval); } /* ** The GiST Union method for IP ranges ** returns the minimal bounding IP4R that encloses all the entries in entryvec */ PG_FUNCTION_INFO_V1(gip4r_union); Datum gip4r_union(PG_FUNCTION_ARGS) { GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0); int *sizep = (int *) PG_GETARG_POINTER(1); GISTENTRY *ent = GISTENTRYVEC(entryvec); int numranges, i; IP4R *out = (IP4R *) palloc(sizeof(IP4R)); IP4R *tmp; #ifdef GIST_DEBUG fprintf(stderr, "union\n"); #endif numranges = GISTENTRYCOUNT(entryvec); tmp = (IP4R *) DatumGetPointer(ent[0].key); *sizep = sizeof(IP4R); *out = *tmp; for (i = 1; i < numranges; i++) { tmp = (IP4R *) DatumGetPointer(ent[i].key); if (tmp->lower < out->lower) out->lower = tmp->lower; if (tmp->upper > out->upper) out->upper = tmp->upper; } PG_RETURN_IP4R_P(out); } /* ** GiST Compress and Decompress methods for IP ranges ** do not do anything. */ PG_FUNCTION_INFO_V1(gip4r_compress); Datum gip4r_compress(PG_FUNCTION_ARGS) { PG_RETURN_POINTER(PG_GETARG_POINTER(0)); } PG_FUNCTION_INFO_V1(gip4r_decompress); Datum gip4r_decompress(PG_FUNCTION_ARGS) { PG_RETURN_POINTER(PG_GETARG_POINTER(0)); } /* ** The GiST Penalty method for IP ranges ** As in the R-tree paper, we use change in area as our penalty metric */ PG_FUNCTION_INFO_V1(gip4r_penalty); Datum gip4r_penalty(PG_FUNCTION_ARGS) { GISTENTRY *origentry = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *newentry = (GISTENTRY *) PG_GETARG_POINTER(1); float *result = (float *) PG_GETARG_POINTER(2); IP4R *key; IP4R ud; float tmp1, tmp2; key = (IP4R *) DatumGetPointer(origentry->key); ud = *key; tmp2 = ip4r_metric(&ud); key = (IP4R *) DatumGetPointer(newentry->key); if (key->lower < ud.lower) ud.lower = key->lower; if (key->upper > ud.upper) ud.upper = key->upper; tmp1 = ip4r_metric(&ud); *result = tmp1 - tmp2; #ifdef GIST_DEBUG fprintf(stderr, "penalty\n"); fprintf(stderr, "\t%g\n", *result); #endif PG_RETURN_POINTER(result); } /* Helper functions for picksplit. We might need to sort a list of * ranges by size; these are for that. */ struct gip4r_sort { IP4R *key; OffsetNumber pos; }; static int gip4r_sort_compare(const void *a, const void *b) { double sa = ip4r_metric(((struct gip4r_sort *)a)->key); double sb = ip4r_metric(((struct gip4r_sort *)b)->key); return (sa > sb) ? 1 : ((sa == sb) ? 0 : -1); } /* ** The GiST PickSplit method for IP ranges ** This is a linear-time algorithm based on a left/right split, ** based on the box functions in rtree_gist simplified to one ** dimension */ PG_FUNCTION_INFO_V1(gip4r_picksplit); Datum gip4r_picksplit(PG_FUNCTION_ARGS) { GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0); GIST_SPLITVEC *v = (GIST_SPLITVEC *) PG_GETARG_POINTER(1); GISTENTRY *ent = GISTENTRYVEC(entryvec); OffsetNumber i; int nbytes; OffsetNumber maxoff; OffsetNumber *listL; OffsetNumber *listR; bool allisequal = true; IP4R pageunion; IP4R *cur; IP4R *unionL; IP4R *unionR; int posL = 0; int posR = 0; posL = posR = 0; maxoff = GISTENTRYCOUNT(entryvec) - 1; cur = (IP4R *) DatumGetPointer(ent[FirstOffsetNumber].key); pageunion = *cur; /* find MBR */ for (i = OffsetNumberNext(FirstOffsetNumber); i <= maxoff; i = OffsetNumberNext(i)) { cur = (IP4R *) DatumGetPointer(ent[i].key); if (allisequal == true && (pageunion.lower != cur->lower || pageunion.upper != cur->upper)) allisequal = false; if (cur->lower < pageunion.lower) pageunion.lower = cur->lower; if (cur->upper > pageunion.upper) pageunion.upper = cur->upper; } nbytes = (maxoff + 2) * sizeof(OffsetNumber); listL = (OffsetNumber *) palloc(nbytes); listR = (OffsetNumber *) palloc(nbytes); unionL = (IP4R *) palloc(sizeof(IP4R)); unionR = (IP4R *) palloc(sizeof(IP4R)); v->spl_ldatum = PointerGetDatum(unionL); v->spl_rdatum = PointerGetDatum(unionR); v->spl_left = listL; v->spl_right = listR; if (allisequal) { cur = (IP4R *) DatumGetPointer(ent[OffsetNumberNext(FirstOffsetNumber)].key); if (ip4r_equal(cur, &pageunion)) { OffsetNumber split_at = FirstOffsetNumber + (maxoff - FirstOffsetNumber + 1)/2; v->spl_nleft = v->spl_nright = 0; *unionL = pageunion; *unionR = pageunion; for (i = FirstOffsetNumber; i < split_at; i = OffsetNumberNext(i)) v->spl_left[v->spl_nleft++] = i; for (; i <= maxoff; i = OffsetNumberNext(i)) v->spl_right[v->spl_nright++] = i; PG_RETURN_POINTER(v); } } #define ADDLIST( list_, u_, pos_, num_ ) do { \ if ( pos_ ) { \ if ( (u_)->upper < (cur)->upper ) (u_)->upper = (cur)->upper; \ if ( (u_)->lower > (cur)->lower ) (u_)->lower = (cur)->lower; \ } else { \ *(u_) = *(cur); \ } \ (list_)[(pos_)++] = (num_); \ } while(0) for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i)) { cur = (IP4R *) DatumGetPointer(ent[i].key); if (cur->lower - pageunion.lower < pageunion.upper - cur->upper) ADDLIST(listL, unionL, posL, i); else ADDLIST(listR, unionR, posR, i); } /* bad disposition, sort by ascending size and resplit */ if (posR == 0 || posL == 0) { struct gip4r_sort *arr = (struct gip4r_sort *) palloc(sizeof(struct gip4r_sort) * (maxoff + FirstOffsetNumber)); for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i)) { arr[i].key = (IP4R *) DatumGetPointer(ent[i].key); arr[i].pos = i; } qsort(arr + FirstOffsetNumber, maxoff - FirstOffsetNumber + 1, sizeof(struct gip4r_sort), gip4r_sort_compare); posL = posR = 0; for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i)) { cur = arr[i].key; if (cur->lower - pageunion.lower < pageunion.upper - cur->upper) ADDLIST(listL, unionL, posL, arr[i].pos); else if (cur->lower - pageunion.lower == pageunion.upper - cur->upper) { if (posL > posR) ADDLIST(listR, unionR, posR, arr[i].pos); else ADDLIST(listL, unionL, posL, arr[i].pos); } else ADDLIST(listR, unionR, posR, arr[i].pos); } pfree(arr); } v->spl_nleft = posL; v->spl_nright = posR; PG_RETURN_POINTER(v); } #undef ADDLIST /* ** Equality methods */ PG_FUNCTION_INFO_V1(gip4r_same); Datum gip4r_same(PG_FUNCTION_ARGS) { IP4R *v1 = (IP4R *) PG_GETARG_POINTER(0); IP4R *v2 = (IP4R *) PG_GETARG_POINTER(1); bool *result = (bool *) PG_GETARG_POINTER(2); if (v1 && v2) *result = ip4r_equal(v1,v2); else *result = (v1 == NULL && v2 == NULL); #ifdef GIST_DEBUG fprintf(stderr, "same: %s\n", (*result ? "TRUE" : "FALSE")); #endif PG_RETURN_POINTER(result); } /* * Strategy numbers: * OPERATOR 1 >>= , * OPERATOR 2 <<= , * OPERATOR 3 >> , * OPERATOR 4 << , * OPERATOR 5 && , * OPERATOR 6 = , */ /* ** SUPPORT ROUTINES */ static bool gip4r_leaf_consistent(IP4R * key, IP4R * query, StrategyNumber strategy) { #ifdef GIST_QUERY_DEBUG fprintf(stderr, "leaf_consistent, %d\n", strategy); #endif switch (strategy) { case 1: /* left contains right nonstrict */ return ip4r_contains_internal(key, query, TRUE); case 2: /* left contained in right nonstrict */ return ip4r_contains_internal(query, key, TRUE); case 3: /* left contains right strict */ return ip4r_contains_internal(key, query, FALSE); case 4: /* left contained in right strict */ return ip4r_contains_internal(query, key, FALSE); case 5: /* left overlaps right */ return ip4r_overlaps_internal(key, query); case 6: /* left equal right */ return ip4r_equal(key, query); default: return FALSE; } } /* logic notes: * If the union value we're looking at overlaps with our query value * at all, then any of the values underneath it might overlap with us * or be contained by us, so all the "contained by" and "overlaps" * cases degenerate to "overlap". * If the union value is equal to the query value, then none of the * values under it can strictly contain the query value, so for * "contained" queries the strictness is preserved. * If we're looking for an "equal" value, then we have to enter any * subtree whose union contains (not strictly) our query value. */ bool gip4r_internal_consistent(IP4R * key, IP4R * query, StrategyNumber strategy) { #ifdef GIST_QUERY_DEBUG fprintf(stderr, "internal_consistent, %d\n", strategy); #endif switch (strategy) { case 2: /* left contained in right nonstrict */ case 4: /* left contained in right strict */ case 5: /* left overlaps right */ return ip4r_overlaps_internal(key, query); case 3: /* left contains right strict */ return ip4r_contains_internal(key, query, FALSE); case 1: /* left contains right nonstrict */ case 6: /* left equal right */ return ip4r_contains_internal(key, query, TRUE); default: return FALSE; } } /* end */ ip4r-2.0.2/ip4r.control000066400000000000000000000001251233620317400146500ustar00rootroot00000000000000# ip4r default_version = '2.0' relocatable = 'true' module_pathname = '$libdir/ip4r' ip4r-2.0.2/ip4r_funcs.h000066400000000000000000000107731233620317400146270ustar00rootroot00000000000000/* $Id: ip4r_funcs.h,v 1.1 2011/08/03 20:16:03 andrewsn Exp $ */ static inline uint32 hostmask(unsigned masklen) { return (masklen) ? ( (((uint32)(1U)) << (32-masklen)) - 1U ) : 0xFFFFFFFFU; } static inline uint32 netmask(unsigned masklen) { return ~hostmask(masklen); } /* if LO and HI are ends of a CIDR prefix, return the mask length. * If not, returns ~0. */ static inline unsigned masklen(uint32 lo, uint32 hi) { uint32 d = (lo ^ hi) + 1; /* at this point, d can be: * 0 if A and B have all bits different * 1 if A and B are equal * 1 << (32-masklen) * some other value if A and B are not ends of a CIDR range * but in any case, after extracting the masklen, we have to * recheck because some non-CIDR ranges will produce the same * results. */ int fbit = ffs(d); switch (fbit) { case 0: return (lo == 0 && hi == ~0) ? 0 : ~0; case 1: return (lo == hi) ? 32 : ~0; default: if ( ((uint32)(1U) << (fbit-1)) == d ) { uint32 mask = hostmask(33-fbit); if ((lo & mask) == 0 && (hi & mask) == mask) return 33-fbit; } return ~0; } } static inline bool ip4_valid_netmask(uint32 mask) { uint32 d = ~mask + 1; /* at this point, d can be: * 0 if mask was 0x00000000 (valid) * 1 << (32-masklen) (valid) * some other value (invalid) */ int fbit = ffs(d); switch (fbit) { case 0: return true; default: return ( ((uint32)(1U) << (fbit-1)) == d ); } } static inline bool ip4r_from_cidr(IP4 prefix, unsigned masklen, IP4R *ipr) { uint32 mask = hostmask(masklen); if (masklen > 32) return FALSE; if (prefix & mask) return FALSE; ipr->lower = prefix; ipr->upper = prefix | mask; return TRUE; } static inline bool ip4r_from_inet(IP4 addr, unsigned masklen, IP4R *ipr) { uint32 mask = hostmask(masklen); if (masklen > 32) return FALSE; ipr->lower = addr & ~mask; ipr->upper = addr | mask; return TRUE; } /* comparisons */ static inline bool ip4_equal(IP4 a, IP4 b) { return (a == b); } static inline bool ip4_lessthan(IP4 a, IP4 b) { return (a < b); } static inline bool ip4_less_eq(IP4 a, IP4 b) { return (a <= b); } /* helpers for union/intersection for indexing */ static inline IP4R *ip4r_union_internal(IP4R *a, IP4R *b, IP4R *result) { if (a->lower < b->lower) result->lower = a->lower; else result->lower = b->lower; if (a->upper > b->upper) result->upper = a->upper; else result->upper = b->upper; return result; } static inline IP4R *ip4r_inter_internal(IP4R *a, IP4R *b, IP4R *result) { if (a->upper < b->lower || a->lower > b->upper) { /* disjoint */ result->lower = 1; result->upper = 0; /* INVALID VALUE */ return NULL; } if (a->upper < b->upper) result->upper = a->upper; else result->upper = b->upper; if (a->lower > b->lower) result->lower = a->lower; else result->lower = b->lower; return result; } static inline double ip4r_metric(IP4R *v) { if (!v) return 0.0; return ((v->upper - v->lower) + 1.0); } static inline bool ip4r_equal(IP4R *a, IP4R *b) { return (a->lower == b->lower && a->upper == b->upper); } static inline bool ip4r_lessthan(IP4R *a, IP4R *b) { return (a->lower == b->lower) ? (a->upper < b->upper) : (a->lower < b->lower); } static inline bool ip4r_less_eq(IP4R *a, IP4R *b) { return (a->lower == b->lower) ? (a->upper <= b->upper) : (a->lower < b->lower); } static inline bool ip4r_contains_internal(IP4R *left, IP4R *right, bool eqval) { if (ip4r_equal(left,right)) return eqval; return ((left->lower <= right->lower) && (left->upper >= right->upper)); } static inline bool ip4r_overlaps_internal(IP4R *left, IP4R *right) { return (left->upper >= right->lower && left->lower <= right->upper); } static inline bool ip4_contains_internal(IP4R *left, IP4 right) { return (left->lower <= right && left->upper >= right); } static inline bool ip4r_left_internal(IP4R *left, IP4R *right) { return (left->upper < right->lower); } static inline bool ip4r_extends_left_of_internal(IP4R *left, IP4R *right) { return (left->lower < right->lower); } static inline bool ip4r_extends_right_of_internal(IP4R *left, IP4R *right) { return (left->upper > right->upper); } /* end */ ip4r-2.0.2/ip4r_module.c000066400000000000000000000001471233620317400147630ustar00rootroot00000000000000/* $Id: ip4r_module.c,v 1.1 2011/08/22 14:06:31 andrewsn Exp $ */ #include "ipr.h" PG_MODULE_MAGIC; ip4r-2.0.2/ip6r.c000066400000000000000000001240741233620317400134260ustar00rootroot00000000000000/* $Id: ip6r.c,v 1.2 2011/08/22 14:05:19 andrewsn Exp $ */ #include "ipr.h" #include "ip6r_funcs.h" /* extract an IP range from text. */ static bool ip6r_from_str(char *str, IP6R *ipr) { char buf[IP6_STRING_MAX]; int pos = strcspn(str, "-/"); IP6 ip; switch (str[pos]) { case 0: /* no separator, must be single ip6 addr */ { if (!ip6_raw_input(str, ip.bits)) return FALSE; ipr->lower = ip; ipr->upper = ip; return TRUE; } case '-': /* lower-upper */ { char *rest = str + pos + 1; if (pos > sizeof(buf)-2) return FALSE; memcpy(buf, str, pos); buf[pos] = 0; if (!ip6_raw_input(buf, ip.bits)) return FALSE; ipr->lower = ip; if (!ip6_raw_input(rest, ip.bits)) return FALSE; if (!ip6_lessthan(&ip, &ipr->lower)) ipr->upper = ip; else { ipr->upper = ipr->lower; ipr->lower = ip; } return TRUE; } case '/': /* prefix/len */ { char *rest = str + pos + 1; unsigned pfxlen; char dummy; if (pos > sizeof(buf)-2) return FALSE; memcpy(buf, str, pos); buf[pos] = 0; if (!ip6_raw_input(buf, ip.bits)) return FALSE; if (rest[strspn(rest,"0123456789")]) return FALSE; if (sscanf(rest, "%u%c", &pfxlen, &dummy) != 1) return FALSE; return ip6r_from_cidr(&ip, pfxlen, ipr); } default: return FALSE; /* can't happen */ } } /* Output an ip range in text form */ static int ip6r_to_str(IP6R *ipr, char *str, int slen) { char buf1[IP6_STRING_MAX]; char buf2[IP6_STRING_MAX]; unsigned msk; if (ip6_equal(&ipr->lower, &ipr->upper)) return ip6_raw_output(ipr->lower.bits, str, slen); if ((msk = masklen6(&ipr->lower,&ipr->upper)) <= 128) { ip6_raw_output(ipr->lower.bits, buf1, sizeof(buf1)); return snprintf(str, slen, "%s/%u", buf1, msk); } ip6_raw_output(ipr->lower.bits, buf1, sizeof(buf1)); ip6_raw_output(ipr->upper.bits, buf2, sizeof(buf2)); return snprintf(str, slen, "%s-%s", buf1, buf2); } /**************************************************************************/ /* This part handles all aspects of postgres interfacing. */ /* end of version dependencies */ /* #define GIST_DEBUG #define GIST_QUERY_DEBUG */ static text * make_text(char *str, int len) { text *ret = (text *) palloc(len + VARHDRSZ); SET_VARSIZE(ret, len + VARHDRSZ); if (str) memcpy(VARDATA(ret), str, len); else memset(VARDATA(ret), 0, len); return ret; } static inline void set_text_len(text *txt, int len) { if ((len + VARHDRSZ) < VARSIZE(txt)) SET_VARSIZE(txt, len + VARHDRSZ); } static inline int get_text_len(text *txt) { return VARSIZE(txt) - VARHDRSZ; } /* ** Input/Output routines */ PG_FUNCTION_INFO_V1(ip6_in); Datum ip6_in(PG_FUNCTION_ARGS) { char *str = PG_GETARG_CSTRING(0); IP6 *ip = palloc(sizeof(IP6)); if (ip6_raw_input(str, ip->bits)) PG_RETURN_IP6_P(ip); ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("invalid IP6 value: '%s'", str))); PG_RETURN_NULL(); } PG_FUNCTION_INFO_V1(ip6_out); Datum ip6_out(PG_FUNCTION_ARGS) { IP6 *ip = PG_GETARG_IP6_P(0); char *out = palloc(IP6_STRING_MAX); ip6_raw_output(ip->bits, out, IP6_STRING_MAX); PG_RETURN_CSTRING(out); } PG_FUNCTION_INFO_V1(ip6_recv); Datum ip6_recv(PG_FUNCTION_ARGS) { StringInfo buf = (StringInfo) PG_GETARG_POINTER(0); IP6 *ip = palloc(sizeof(IP6)); ip->bits[0] = pq_getmsgint64(buf); ip->bits[1] = pq_getmsgint64(buf); PG_RETURN_IP6_P(ip); } PG_FUNCTION_INFO_V1(ip6_send); Datum ip6_send(PG_FUNCTION_ARGS) { IP6 *arg1 = PG_GETARG_IP6_P(0); StringInfoData buf; pq_begintypsend(&buf); pq_sendint64(&buf, arg1->bits[0]); pq_sendint64(&buf, arg1->bits[1]); PG_RETURN_BYTEA_P(pq_endtypsend(&buf)); } PG_FUNCTION_INFO_V1(ip6hash); Datum ip6hash(PG_FUNCTION_ARGS) { IP6 *arg1 = PG_GETARG_IP6_P(0); return hash_any((unsigned char *)arg1, sizeof(IP6)); } PG_FUNCTION_INFO_V1(ip6_cast_to_text); Datum ip6_cast_to_text(PG_FUNCTION_ARGS) { IP6 *ip = PG_GETARG_IP6_P(0); text *out = make_text(NULL,IP6_STRING_MAX); set_text_len(out, ip6_raw_output(ip->bits, VARDATA(out), IP6_STRING_MAX)); PG_RETURN_TEXT_P(out); } PG_FUNCTION_INFO_V1(ip6_cast_from_text); Datum ip6_cast_from_text(PG_FUNCTION_ARGS) { text *txt = PG_GETARG_TEXT_P(0); int tlen = get_text_len(txt); char buf[IP6_STRING_MAX]; if (tlen < sizeof(buf)) { IP6 *ip = palloc(sizeof(IP6)); memcpy(buf, VARDATA(txt), tlen); buf[tlen] = 0; if (ip6_raw_input(buf, ip->bits)) PG_RETURN_IP6_P(ip); } ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("invalid IP6 value in text"))); PG_RETURN_NULL(); } PG_FUNCTION_INFO_V1(ip6_cast_from_inet); Datum ip6_cast_from_inet(PG_FUNCTION_ARGS) { inet *inetptr = PG_GETARG_INET_P(0); inet_struct *in = INET_STRUCT_DATA(inetptr); if (in->family == PGSQL_AF_INET6) { unsigned char *p = in->ipaddr; IP6 *ip = palloc(sizeof(IP6)); ip->bits[0] = (((uint64)p[0] << 56) | ((uint64)p[1] << 48) | ((uint64)p[2] << 40) | ((uint64)p[3] << 32) | ((uint64)p[4] << 24) | ((uint64)p[5] << 16) | ((uint64)p[6] << 8) | p[7]); ip->bits[1] = (((uint64)p[8] << 56) | ((uint64)p[9] << 48) | ((uint64)p[10] << 40) | ((uint64)p[11] << 32) | ((uint64)p[12] << 24) | ((uint64)p[13] << 16) | ((uint64)p[14] << 8) | p[15]); PG_RETURN_IP6_P(ip); } ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("invalid INET value for conversion to IP6"))); PG_RETURN_NULL(); } PG_FUNCTION_INFO_V1(ip6_cast_to_cidr); Datum ip6_cast_to_cidr(PG_FUNCTION_ARGS) { IP6 *ip = PG_GETARG_IP6_P(0); inet *res = palloc0(VARHDRSZ + sizeof(inet_struct)); inet_struct *in; SET_VARSIZE(res, VARHDRSZ + offsetof(inet_struct, ipaddr) + 16); in = ((inet_struct *)VARDATA(res)); INET_INIT_CIDR(in); in->bits = 128; in->family = PGSQL_AF_INET6; { unsigned char *p = in->ipaddr; p[0] = (ip->bits[0] >> 56); p[1] = (ip->bits[0] >> 48); p[2] = (ip->bits[0] >> 40); p[3] = (ip->bits[0] >> 32); p[4] = (ip->bits[0] >> 24); p[5] = (ip->bits[0] >> 16); p[6] = (ip->bits[0] >> 8); p[7] = (ip->bits[0]); p[8] = (ip->bits[1] >> 56); p[9] = (ip->bits[1] >> 48); p[10] = (ip->bits[1] >> 40); p[11] = (ip->bits[1] >> 32); p[12] = (ip->bits[1] >> 24); p[13] = (ip->bits[1] >> 16); p[14] = (ip->bits[1] >> 8); p[15] = (ip->bits[1]); } PG_RETURN_INET_P(res); } PG_FUNCTION_INFO_V1(ip6_cast_to_numeric); Datum ip6_cast_to_numeric(PG_FUNCTION_ARGS) { IP6 *ip = PG_GETARG_IP6_P(0); Datum res,tmp,mul; static int64 mul_val = ((int64)1 << 56); int64 tmp_val; mul = DirectFunctionCall1(int8_numeric,Int64GetDatumFast(mul_val)); tmp_val = (ip->bits[0] >> 48); res = DirectFunctionCall1(int8_numeric,Int64GetDatumFast(tmp_val)); tmp_val = ((ip->bits[0] & (uint64)(0xFFFFFFFFFFFFULL)) << 8) | (ip->bits[1] >> 56); tmp = DirectFunctionCall1(int8_numeric,Int64GetDatumFast(tmp_val)); res = DirectFunctionCall2(numeric_mul,res,mul); res = DirectFunctionCall2(numeric_add,res,tmp); tmp_val = (ip->bits[1] & (uint64)(0xFFFFFFFFFFFFFFULL)); tmp = DirectFunctionCall1(int8_numeric,Int64GetDatumFast(tmp_val)); res = DirectFunctionCall2(numeric_mul,res,mul); res = DirectFunctionCall2(numeric_add,res,tmp); PG_RETURN_DATUM(res); } PG_FUNCTION_INFO_V1(ip6_cast_from_numeric); Datum ip6_cast_from_numeric(PG_FUNCTION_ARGS) { Datum val = NumericGetDatum(PG_GETARG_NUMERIC(0)); Datum rem,tmp,div,mul; static int64 mul_val = ((int64)1 << 56); uint64 tmp_val; IP6 *res; tmp = DirectFunctionCall1(numeric_floor,DirectFunctionCall1(numeric_abs,val)); if (!DatumGetBool(DirectFunctionCall2(numeric_eq,tmp,val))) { ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("invalid numeric value for conversion to IP6"))); } res = palloc(sizeof(IP6)); /* we use div/mul here rather than mod because numeric_mod is implemented as * a div/mul/subtract in any case, so we save a division step by doing the * mul/subtract ourselves */ mul = DirectFunctionCall1(int8_numeric,Int64GetDatumFast(mul_val)); div = DirectFunctionCall2(numeric_div_trunc,val,mul); tmp = DirectFunctionCall2(numeric_mul,div,mul); rem = DirectFunctionCall2(numeric_sub,val,tmp); res->bits[1] = (uint64)DatumGetInt64(DirectFunctionCall1(numeric_int8,rem)); val = div; div = DirectFunctionCall2(numeric_div_trunc,val,mul); tmp = DirectFunctionCall2(numeric_mul,div,mul); rem = DirectFunctionCall2(numeric_sub,val,tmp); tmp_val = (uint64)DatumGetInt64(DirectFunctionCall1(numeric_int8,rem)); res->bits[1] |= ((tmp_val & 0xFF) << 56); res->bits[0] = (tmp_val >> 8); if (!DatumGetBool(DirectFunctionCall2(numeric_gt,div,mul))) { tmp_val = (uint64)DatumGetInt64(DirectFunctionCall1(numeric_int8,div)); if (tmp_val <= (uint64)0xFFFFU) { res->bits[0] |= (tmp_val << 48); PG_RETURN_IP6_P(res); } } ereport(ERROR, (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), errmsg("numeric value too large for conversion to IP6"))); PG_RETURN_NULL(); } PG_FUNCTION_INFO_V1(ip6_netmask); Datum ip6_netmask(PG_FUNCTION_ARGS) { int pfxlen = PG_GETARG_INT32(0); IP6 *mask; if (pfxlen < 0 || pfxlen > 128) { ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("prefix length out of range"))); } mask = palloc(sizeof(IP6)); mask->bits[0] = netmask6_hi(pfxlen); mask->bits[1] = netmask6_lo(pfxlen); PG_RETURN_IP6_P(mask); } PG_FUNCTION_INFO_V1(ip6_net_lower); Datum ip6_net_lower(PG_FUNCTION_ARGS) { IP6 *ip = PG_GETARG_IP6_P(0); int pfxlen = PG_GETARG_INT32(1); IP6 *res; if (pfxlen < 0 || pfxlen > 128) { ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("prefix length out of range"))); } res = palloc(sizeof(IP6)); res->bits[0] = ip->bits[0] & netmask6_hi(pfxlen); res->bits[1] = ip->bits[1] & netmask6_lo(pfxlen); PG_RETURN_IP6_P(res); } PG_FUNCTION_INFO_V1(ip6_net_upper); Datum ip6_net_upper(PG_FUNCTION_ARGS) { IP6 *ip = PG_GETARG_IP6_P(0); int pfxlen = PG_GETARG_INT32(1); IP6 *res; if (pfxlen < 0 || pfxlen > 128) { ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("prefix length out of range"))); } res = palloc(sizeof(IP6)); res->bits[0] = ip->bits[0] | hostmask6_hi(pfxlen); res->bits[1] = ip->bits[1] | hostmask6_lo(pfxlen); PG_RETURN_IP6_P(res); } PG_FUNCTION_INFO_V1(ip6_plus_int); Datum ip6_plus_int(PG_FUNCTION_ARGS) { IP6 *ip = PG_GETARG_IP6_P(0); int addend = PG_GETARG_INT32(1); IP6 *result = palloc(sizeof(IP6)); if (addend >= 0) { result->bits[1] = ip->bits[1] + addend; result->bits[0] = ip->bits[0] + (result->bits[1] < ip->bits[1]); } else { result->bits[1] = ip->bits[1] - (uint64)(-addend); result->bits[0] = ip->bits[0] - (result->bits[1] > ip->bits[1]); } if ((addend < 0) != ip6_lessthan(result,ip)) { ereport(ERROR, (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), errmsg("ip address out of range"))); } PG_RETURN_IP6_P(result); } PG_FUNCTION_INFO_V1(ip6_plus_bigint); Datum ip6_plus_bigint(PG_FUNCTION_ARGS) { IP6 *ip = PG_GETARG_IP6_P(0); int64 addend = PG_GETARG_INT64(1); IP6 *result = palloc(sizeof(IP6)); if (addend >= 0) { result->bits[1] = ip->bits[1] + addend; result->bits[0] = ip->bits[0] + (result->bits[1] < ip->bits[1]); } else { result->bits[1] = ip->bits[1] - (uint64)(-addend); result->bits[0] = ip->bits[0] - (result->bits[1] > ip->bits[1]); } if ((addend < 0) != ip6_lessthan(result,ip)) { ereport(ERROR, (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), errmsg("ip address out of range"))); } PG_RETURN_IP6_P(result); } PG_FUNCTION_INFO_V1(ip6_plus_numeric); Datum ip6_plus_numeric(PG_FUNCTION_ARGS) { IP6 *ip = PG_GETARG_IP6_P(0); Datum addend_num = NumericGetDatum(PG_GETARG_NUMERIC(1)); Datum addend_abs; IP6 *addend; IP6 *result = palloc(sizeof(IP6)); bool is_negative; addend_abs = DirectFunctionCall1(numeric_abs,addend_num); addend = DatumGetIP6P(DirectFunctionCall1(ip6_cast_from_numeric,addend_abs)); if (DatumGetBool(DirectFunctionCall2(numeric_eq,addend_num,addend_abs))) { is_negative = false; result->bits[1] = ip->bits[1] + addend->bits[1]; result->bits[0] = ip->bits[0] + addend->bits[0] + (result->bits[1] < ip->bits[1]); } else { is_negative = true; result->bits[1] = ip->bits[1] - addend->bits[1]; result->bits[0] = ip->bits[0] - addend->bits[0] - (result->bits[1] > ip->bits[1]); } if (is_negative != ip6_lessthan(result,ip)) { ereport(ERROR, (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), errmsg("ip address out of range"))); } PG_RETURN_IP6_P(result); } PG_FUNCTION_INFO_V1(ip6_minus_int); Datum ip6_minus_int(PG_FUNCTION_ARGS) { IP6 *ip = PG_GETARG_IP6_P(0); int subtrahend = PG_GETARG_INT32(1); IP6 *result = palloc(sizeof(IP6)); ip6_sub_int(ip, subtrahend, result); if ((subtrahend > 0) != ip6_lessthan(result,ip)) { ereport(ERROR, (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), errmsg("ip address out of range"))); } PG_RETURN_IP6_P(result); } PG_FUNCTION_INFO_V1(ip6_minus_bigint); Datum ip6_minus_bigint(PG_FUNCTION_ARGS) { IP6 *ip = PG_GETARG_IP6_P(0); int64 subtrahend = PG_GETARG_INT64(1); IP6 *result = palloc(sizeof(IP6)); if (subtrahend >= 0) { result->bits[1] = ip->bits[1] - (uint64)subtrahend; result->bits[0] = ip->bits[0] - (result->bits[1] > ip->bits[1]); } else { result->bits[1] = ip->bits[1] + (uint64)(-subtrahend); result->bits[0] = ip->bits[0] + (result->bits[1] < ip->bits[1]); } if ((subtrahend > 0) != ip6_lessthan(result,ip)) { ereport(ERROR, (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), errmsg("ip address out of range"))); } PG_RETURN_IP6_P(result); } PG_FUNCTION_INFO_V1(ip6_minus_numeric); Datum ip6_minus_numeric(PG_FUNCTION_ARGS) { Datum ip = PG_GETARG_DATUM(0); Datum subtrahend = PG_GETARG_DATUM(1); subtrahend = DirectFunctionCall1(numeric_uminus,subtrahend); return DirectFunctionCall2(ip6_plus_numeric,ip,subtrahend); } PG_FUNCTION_INFO_V1(ip6_minus_ip6); Datum ip6_minus_ip6(PG_FUNCTION_ARGS) { Datum minuend = PG_GETARG_DATUM(0); Datum subtrahend = PG_GETARG_DATUM(1); Datum res; res = DirectFunctionCall2(numeric_sub, DirectFunctionCall1(ip6_cast_to_numeric,minuend), DirectFunctionCall1(ip6_cast_to_numeric,subtrahend)); PG_RETURN_DATUM(res); } PG_FUNCTION_INFO_V1(ip6_and); Datum ip6_and(PG_FUNCTION_ARGS) { IP6 *a = PG_GETARG_IP6_P(0); IP6 *b = PG_GETARG_IP6_P(1); IP6 *res = palloc(sizeof(IP6)); res->bits[0] = a->bits[0] & b->bits[0]; res->bits[1] = a->bits[1] & b->bits[1]; PG_RETURN_IP6_P(res); } PG_FUNCTION_INFO_V1(ip6_or); Datum ip6_or(PG_FUNCTION_ARGS) { IP6 *a = PG_GETARG_IP6_P(0); IP6 *b = PG_GETARG_IP6_P(1); IP6 *res = palloc(sizeof(IP6)); res->bits[0] = a->bits[0] | b->bits[0]; res->bits[1] = a->bits[1] | b->bits[1]; PG_RETURN_IP6_P(res); } PG_FUNCTION_INFO_V1(ip6_xor); Datum ip6_xor(PG_FUNCTION_ARGS) { IP6 *a = PG_GETARG_IP6_P(0); IP6 *b = PG_GETARG_IP6_P(1); IP6 *res = palloc(sizeof(IP6)); res->bits[0] = a->bits[0] ^ b->bits[0]; res->bits[1] = a->bits[1] ^ b->bits[1]; PG_RETURN_IP6_P(res); } PG_FUNCTION_INFO_V1(ip6_not); Datum ip6_not(PG_FUNCTION_ARGS) { IP6 *a = PG_GETARG_IP6_P(0); IP6 *res = palloc(sizeof(IP6)); res->bits[0] = ~a->bits[0]; res->bits[1] = ~a->bits[1]; PG_RETURN_IP6_P(res); } /*---- ip6r ----*/ PG_FUNCTION_INFO_V1(ip6r_in); Datum ip6r_in(PG_FUNCTION_ARGS) { char *str = PG_GETARG_CSTRING(0); IP6R ipr; if (ip6r_from_str(str, &ipr)) { IP6R *res = palloc(sizeof(IP6R)); *res = ipr; PG_RETURN_IP6R_P(res); } ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("invalid IP6R value: \"%s\"", str))); PG_RETURN_NULL(); } PG_FUNCTION_INFO_V1(ip6r_out); Datum ip6r_out(PG_FUNCTION_ARGS) { IP6R *ipr = PG_GETARG_IP6R_P(0); char *out = palloc(IP6R_STRING_MAX); ip6r_to_str(ipr, out, IP6R_STRING_MAX); PG_RETURN_CSTRING(out); } PG_FUNCTION_INFO_V1(ip6r_recv); Datum ip6r_recv(PG_FUNCTION_ARGS) { StringInfo buf = (StringInfo) PG_GETARG_POINTER(0); IP6R *ipr = palloc(sizeof(IP6R)); ipr->lower.bits[0] = pq_getmsgint64(buf); ipr->lower.bits[1] = pq_getmsgint64(buf); ipr->upper.bits[0] = pq_getmsgint64(buf); ipr->upper.bits[1] = pq_getmsgint64(buf); PG_RETURN_IP6R_P(ipr); } PG_FUNCTION_INFO_V1(ip6r_send); Datum ip6r_send(PG_FUNCTION_ARGS) { IP6R *ipr = PG_GETARG_IP6R_P(0); StringInfoData buf; pq_begintypsend(&buf); pq_sendint64(&buf, ipr->lower.bits[0]); pq_sendint64(&buf, ipr->lower.bits[1]); pq_sendint64(&buf, ipr->upper.bits[0]); pq_sendint64(&buf, ipr->upper.bits[1]); PG_RETURN_BYTEA_P(pq_endtypsend(&buf)); } PG_FUNCTION_INFO_V1(ip6rhash); Datum ip6rhash(PG_FUNCTION_ARGS) { IP6R *arg1 = PG_GETARG_IP6R_P(0); return hash_any((unsigned char *)arg1, sizeof(IP6R)); } PG_FUNCTION_INFO_V1(ip6r_cast_to_text); Datum ip6r_cast_to_text(PG_FUNCTION_ARGS) { IP6R *ipr = PG_GETARG_IP6R_P(0); text *out = make_text(NULL,IP6R_STRING_MAX); set_text_len(out, ip6r_to_str(ipr, VARDATA(out), IP6R_STRING_MAX)); PG_RETURN_TEXT_P(out); } PG_FUNCTION_INFO_V1(ip6r_cast_from_text); Datum ip6r_cast_from_text(PG_FUNCTION_ARGS) { text *txt = PG_GETARG_TEXT_P(0); int tlen = get_text_len(txt); char buf[IP6R_STRING_MAX]; if (tlen < sizeof(buf)) { IP6R ipr; memcpy(buf, VARDATA(txt), tlen); buf[tlen] = 0; if (ip6r_from_str(buf, &ipr)) { IP6R *res = palloc(sizeof(IP6R)); *res = ipr; PG_RETURN_IP6R_P(res); } } ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("invalid IP6R value in text"))); PG_RETURN_NULL(); } PG_FUNCTION_INFO_V1(ip6r_cast_from_cidr); Datum ip6r_cast_from_cidr(PG_FUNCTION_ARGS) { inet *inetptr = PG_GETARG_INET_P(0); inet_struct *in = INET_STRUCT_DATA(inetptr); if (INET_IS_CIDR(in) && in->family == PGSQL_AF_INET6) { unsigned char *p = in->ipaddr; IP6 ip; IP6R ipr; ip.bits[0] = (((uint64)p[0] << 56) | ((uint64)p[1] << 48) | ((uint64)p[2] << 40) | ((uint64)p[3] << 32) | ((uint64)p[4] << 24) | ((uint64)p[5] << 16) | ((uint64)p[6] << 8) | p[7]); ip.bits[1] = (((uint64)p[8] << 56) | ((uint64)p[9] << 48) | ((uint64)p[10] << 40) | ((uint64)p[11] << 32) | ((uint64)p[12] << 24) | ((uint64)p[13] << 16) | ((uint64)p[14] << 8) | p[15]); if (ip6r_from_cidr(&ip, in->bits, &ipr)) { IP6R *res = palloc(sizeof(IP6R)); *res = ipr; PG_RETURN_IP6R_P(res); } } ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("invalid CIDR value for conversion to IP6R"))); PG_RETURN_NULL(); } PG_FUNCTION_INFO_V1(ip6r_cast_to_cidr); Datum ip6r_cast_to_cidr(PG_FUNCTION_ARGS) { IP6R *ipr = PG_GETARG_IP6R_P(0); IP6 *ip = &ipr->lower; inet *res; inet_struct *in; unsigned bits = masklen6(ip, &ipr->upper); if (bits > 128) PG_RETURN_NULL(); res = palloc0(VARHDRSZ + sizeof(inet_struct)); SET_VARSIZE(res, VARHDRSZ + offsetof(inet_struct, ipaddr) + 16); in = ((inet_struct *)VARDATA(res)); INET_INIT_CIDR(in); in->bits = bits; in->family = PGSQL_AF_INET6; { unsigned char *p = in->ipaddr; p[0] = (ip->bits[0] >> 56); p[1] = (ip->bits[0] >> 48); p[2] = (ip->bits[0] >> 40); p[3] = (ip->bits[0] >> 32); p[4] = (ip->bits[0] >> 24); p[5] = (ip->bits[0] >> 16); p[6] = (ip->bits[0] >> 8); p[7] = (ip->bits[0]); p[8] = (ip->bits[1] >> 56); p[9] = (ip->bits[1] >> 48); p[10] = (ip->bits[1] >> 40); p[11] = (ip->bits[1] >> 32); p[12] = (ip->bits[1] >> 24); p[13] = (ip->bits[1] >> 16); p[14] = (ip->bits[1] >> 8); p[15] = (ip->bits[1]); } PG_RETURN_INET_P(res); } PG_FUNCTION_INFO_V1(ip6r_cast_from_ip6); Datum ip6r_cast_from_ip6(PG_FUNCTION_ARGS) { IP6 *ip = PG_GETARG_IP6_P(0); IP6R *res = palloc(sizeof(IP6R)); if (ip6r_from_inet(ip, 128, res)) { PG_RETURN_IP6R_P(res); } pfree(res); ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("invalid IP6 value for conversion to IP6R (shouldn't be possible)"))); PG_RETURN_NULL(); } PG_FUNCTION_INFO_V1(ip6r_from_ip6s); Datum ip6r_from_ip6s(PG_FUNCTION_ARGS) { IP6 *a = PG_GETARG_IP6_P(0); IP6 *b = PG_GETARG_IP6_P(1); IP6R *res = palloc(sizeof(IP6R)); if (ip6_lessthan(a,b)) res->lower = *a, res->upper = *b; else res->lower = *b, res->upper = *a; PG_RETURN_IP6R_P(res); } PG_FUNCTION_INFO_V1(ip6r_net_prefix); Datum ip6r_net_prefix(PG_FUNCTION_ARGS) { IP6 *ip = PG_GETARG_IP6_P(0); int pfxlen = PG_GETARG_INT32(1); if (pfxlen < 0 || pfxlen > 128) { ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("prefix length out of range"))); } { IP6R *res = palloc(sizeof(IP6R)); ip6r_from_inet(ip, (unsigned)pfxlen, res); PG_RETURN_IP6R_P(res); } } PG_FUNCTION_INFO_V1(ip6r_net_mask); Datum ip6r_net_mask(PG_FUNCTION_ARGS) { IP6 *ip = PG_GETARG_IP6_P(0); IP6 *mask = PG_GETARG_IP6_P(1); if (!ip6_valid_netmask(mask->bits[0], mask->bits[1])) { ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("invalid netmask"))); } { IP6R *res = palloc(sizeof(IP6R)); res->lower.bits[0] = ip->bits[0] & mask->bits[0]; res->lower.bits[1] = ip->bits[1] & mask->bits[1]; res->upper.bits[0] = ip->bits[0] | ~(mask->bits[0]); res->upper.bits[1] = ip->bits[1] | ~(mask->bits[1]); PG_RETURN_IP6R_P(res); } } PG_FUNCTION_INFO_V1(ip6r_lower); Datum ip6r_lower(PG_FUNCTION_ARGS) { IP6R *ipr = PG_GETARG_IP6R_P(0); IP6 *res = palloc(sizeof(IP6)); *res = ipr->lower; PG_RETURN_IP6_P(res); } PG_FUNCTION_INFO_V1(ip6r_upper); Datum ip6r_upper(PG_FUNCTION_ARGS) { IP6R *ipr = PG_GETARG_IP6R_P(0); IP6 *res = palloc(sizeof(IP6)); *res = ipr->upper; PG_RETURN_IP6_P(res); } PG_FUNCTION_INFO_V1(ip6r_is_cidr); Datum ip6r_is_cidr(PG_FUNCTION_ARGS) { IP6R *ipr = PG_GETARG_IP6R_P(0); PG_RETURN_BOOL( (masklen6(&ipr->lower,&ipr->upper) <= 128U) ); } PG_FUNCTION_INFO_V1(ip6_lt); Datum ip6_lt(PG_FUNCTION_ARGS) { PG_RETURN_BOOL( ip6_lessthan(PG_GETARG_IP6_P(0), PG_GETARG_IP6_P(1)) ); } PG_FUNCTION_INFO_V1(ip6_le); Datum ip6_le(PG_FUNCTION_ARGS) { PG_RETURN_BOOL( ip6_less_eq(PG_GETARG_IP6_P(0), PG_GETARG_IP6_P(1)) ); } PG_FUNCTION_INFO_V1(ip6_gt); Datum ip6_gt(PG_FUNCTION_ARGS) { PG_RETURN_BOOL( ip6_lessthan(PG_GETARG_IP6_P(1), PG_GETARG_IP6_P(0)) ); } PG_FUNCTION_INFO_V1(ip6_ge); Datum ip6_ge(PG_FUNCTION_ARGS) { PG_RETURN_BOOL( ip6_less_eq(PG_GETARG_IP6_P(1), PG_GETARG_IP6_P(0)) ); } PG_FUNCTION_INFO_V1(ip6_eq); Datum ip6_eq(PG_FUNCTION_ARGS) { PG_RETURN_BOOL( ip6_equal(PG_GETARG_IP6_P(0), PG_GETARG_IP6_P(1)) ); } PG_FUNCTION_INFO_V1(ip6_neq); Datum ip6_neq(PG_FUNCTION_ARGS) { PG_RETURN_BOOL( !ip6_equal(PG_GETARG_IP6_P(0), PG_GETARG_IP6_P(1)) ); } PG_FUNCTION_INFO_V1(ip6r_lt); Datum ip6r_lt(PG_FUNCTION_ARGS) { PG_RETURN_BOOL( ip6r_lessthan(PG_GETARG_IP6R_P(0), PG_GETARG_IP6R_P(1)) ); } PG_FUNCTION_INFO_V1(ip6r_le); Datum ip6r_le(PG_FUNCTION_ARGS) { PG_RETURN_BOOL( ip6r_less_eq(PG_GETARG_IP6R_P(0), PG_GETARG_IP6R_P(1)) ); } PG_FUNCTION_INFO_V1(ip6r_gt); Datum ip6r_gt(PG_FUNCTION_ARGS) { PG_RETURN_BOOL( ip6r_lessthan(PG_GETARG_IP6R_P(1), PG_GETARG_IP6R_P(0)) ); } PG_FUNCTION_INFO_V1(ip6r_ge); Datum ip6r_ge(PG_FUNCTION_ARGS) { PG_RETURN_BOOL( ip6r_less_eq(PG_GETARG_IP6R_P(1), PG_GETARG_IP6R_P(0)) ); } PG_FUNCTION_INFO_V1(ip6r_eq); Datum ip6r_eq(PG_FUNCTION_ARGS) { PG_RETURN_BOOL( ip6r_equal(PG_GETARG_IP6R_P(0), PG_GETARG_IP6R_P(1)) ); } PG_FUNCTION_INFO_V1(ip6r_neq); Datum ip6r_neq(PG_FUNCTION_ARGS) { PG_RETURN_BOOL( !ip6r_equal(PG_GETARG_IP6R_P(0), PG_GETARG_IP6R_P(1)) ); } PG_FUNCTION_INFO_V1(ip6r_overlaps); Datum ip6r_overlaps(PG_FUNCTION_ARGS) { PG_RETURN_BOOL( ip6r_overlaps_internal(PG_GETARG_IP6R_P(0), PG_GETARG_IP6R_P(1)) ); } PG_FUNCTION_INFO_V1(ip6r_contains); Datum ip6r_contains(PG_FUNCTION_ARGS) { PG_RETURN_BOOL( ip6r_contains_internal(PG_GETARG_IP6R_P(0), PG_GETARG_IP6R_P(1), TRUE) ); } PG_FUNCTION_INFO_V1(ip6r_contains_strict); Datum ip6r_contains_strict(PG_FUNCTION_ARGS) { PG_RETURN_BOOL( ip6r_contains_internal(PG_GETARG_IP6R_P(0), PG_GETARG_IP6R_P(1), FALSE) ); } PG_FUNCTION_INFO_V1(ip6r_contained_by); Datum ip6r_contained_by(PG_FUNCTION_ARGS) { PG_RETURN_BOOL( ip6r_contains_internal(PG_GETARG_IP6R_P(1), PG_GETARG_IP6R_P(0), TRUE) ); } PG_FUNCTION_INFO_V1(ip6r_contained_by_strict); Datum ip6r_contained_by_strict(PG_FUNCTION_ARGS) { PG_RETURN_BOOL( ip6r_contains_internal(PG_GETARG_IP6R_P(1), PG_GETARG_IP6R_P(0), FALSE) ); } PG_FUNCTION_INFO_V1(ip6_contains); Datum ip6_contains(PG_FUNCTION_ARGS) { PG_RETURN_BOOL( ip6_contains_internal(PG_GETARG_IP6R_P(0), PG_GETARG_IP6_P(1)) ); } PG_FUNCTION_INFO_V1(ip6_contained_by); Datum ip6_contained_by(PG_FUNCTION_ARGS) { PG_RETURN_BOOL( ip6_contains_internal(PG_GETARG_IP6R_P(1), PG_GETARG_IP6_P(0)) ); } PG_FUNCTION_INFO_V1(ip6r_union); Datum ip6r_union(PG_FUNCTION_ARGS) { IP6R *res = palloc(sizeof(IP6R)); ip6r_union_internal(PG_GETARG_IP6R_P(0), PG_GETARG_IP6R_P(1), res); PG_RETURN_IP6R_P(res); } PG_FUNCTION_INFO_V1(ip6r_inter); Datum ip6r_inter(PG_FUNCTION_ARGS) { IP6R *res = palloc(sizeof(IP6R)); if (ip6r_inter_internal(PG_GETARG_IP6R_P(0), PG_GETARG_IP6R_P(1), res)) { PG_RETURN_IP6R_P(res); } pfree(res); PG_RETURN_NULL(); } PG_FUNCTION_INFO_V1(ip6r_size); Datum ip6r_size(PG_FUNCTION_ARGS) { double size = ip6r_metric(PG_GETARG_IP6R_P(0)); PG_RETURN_FLOAT8(size); } PG_FUNCTION_INFO_V1(ip6r_size_exact); Datum ip6r_size_exact(PG_FUNCTION_ARGS) { IP6R *ipr = PG_GETARG_IP6R_P(0); Datum l = DirectFunctionCall1(ip6_cast_to_numeric, IP6PGetDatum(&ipr->lower)); Datum u = DirectFunctionCall1(ip6_cast_to_numeric, IP6PGetDatum(&ipr->upper)); Datum d = DirectFunctionCall2(numeric_sub, u, l); Datum s = DirectFunctionCall1(numeric_inc, d); PG_RETURN_DATUM(s); } PG_FUNCTION_INFO_V1(ip6r_prefixlen); Datum ip6r_prefixlen(PG_FUNCTION_ARGS) { IP6R *ipr = PG_GETARG_IP6R_P(0); unsigned len = masklen6(&ipr->lower, &ipr->upper); if (len <= 128) PG_RETURN_INT32((int32) len); PG_RETURN_NULL(); } /***************************************************************************** * Btree functions *****************************************************************************/ PG_FUNCTION_INFO_V1(ip6r_cmp); Datum ip6r_cmp(PG_FUNCTION_ARGS) { IP6R *a = PG_GETARG_IP6R_P(0); IP6R *b = PG_GETARG_IP6R_P(1); if (ip6r_lessthan(a,b)) PG_RETURN_INT32(-1); if (ip6r_equal(a,b)) PG_RETURN_INT32(0); PG_RETURN_INT32(1); } PG_FUNCTION_INFO_V1(ip6_cmp); Datum ip6_cmp(PG_FUNCTION_ARGS) { IP6 *a = PG_GETARG_IP6_P(0); IP6 *b = PG_GETARG_IP6_P(1); PG_RETURN_INT32(ip6_compare(a,b)); } /***************************************************************************** * GiST functions *****************************************************************************/ /* ** GiST support methods */ Datum gip6r_consistent(PG_FUNCTION_ARGS); Datum gip6r_compress(PG_FUNCTION_ARGS); Datum gip6r_decompress(PG_FUNCTION_ARGS); Datum gip6r_penalty(PG_FUNCTION_ARGS); Datum gip6r_picksplit(PG_FUNCTION_ARGS); Datum gip6r_union(PG_FUNCTION_ARGS); Datum gip6r_same(PG_FUNCTION_ARGS); static bool gip6r_leaf_consistent(IP6R * key, IP6R * query, StrategyNumber strategy); static bool gip6r_internal_consistent(IP6R * key, IP6R * query, StrategyNumber strategy); /* ** The GiST Consistent method for IP ranges ** Should return false if for all data items x below entry, ** the predicate x op query == FALSE, where op is the oper ** corresponding to strategy in the pg_amop table. */ PG_FUNCTION_INFO_V1(gip6r_consistent); Datum gip6r_consistent(PG_FUNCTION_ARGS) { GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); IP6R *query = (IP6R *) PG_GETARG_POINTER(1); StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2); bool *recheck = GIST_RECHECK_ARG; IP6R *key = (IP6R *) DatumGetPointer(entry->key); bool retval; /* recheck is never needed with this type */ if (recheck) *recheck = false; /* * * if entry is not leaf, use gip6r_internal_consistent, * else use * gip6r_leaf_consistent */ if (GIST_LEAF(entry)) retval = gip6r_leaf_consistent(key, query, strategy); else retval = gip6r_internal_consistent(key, query, strategy); PG_RETURN_BOOL(retval); } /* ** The GiST Union method for IP ranges ** returns the minimal bounding IP4R that encloses all the entries in entryvec */ PG_FUNCTION_INFO_V1(gip6r_union); Datum gip6r_union(PG_FUNCTION_ARGS) { GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0); int *sizep = (int *) PG_GETARG_POINTER(1); GISTENTRY *ent = GISTENTRYVEC(entryvec); int numranges, i; IP6R *out = palloc(sizeof(IP6R)); IP6R *tmp; #ifdef GIST_DEBUG fprintf(stderr, "union\n"); #endif numranges = GISTENTRYCOUNT(entryvec); tmp = (IP6R *) DatumGetPointer(ent[0].key); *sizep = sizeof(IP6R); *out = *tmp; for (i = 1; i < numranges; i++) { tmp = (IP6R *) DatumGetPointer(ent[i].key); if (ip6_lessthan(&tmp->lower,&out->lower)) out->lower = tmp->lower; if (ip6_lessthan(&out->upper,&tmp->upper)) out->upper = tmp->upper; } PG_RETURN_IP6R_P(out); } /* ** GiST Compress and Decompress methods for IP ranges ** do not do anything. */ PG_FUNCTION_INFO_V1(gip6r_compress); Datum gip6r_compress(PG_FUNCTION_ARGS) { PG_RETURN_POINTER(PG_GETARG_POINTER(0)); } PG_FUNCTION_INFO_V1(gip6r_decompress); Datum gip6r_decompress(PG_FUNCTION_ARGS) { PG_RETURN_POINTER(PG_GETARG_POINTER(0)); } /* ** The GiST Penalty method for IP ranges ** As in the R-tree paper, we use change in area as our penalty metric */ PG_FUNCTION_INFO_V1(gip6r_penalty); Datum gip6r_penalty(PG_FUNCTION_ARGS) { GISTENTRY *origentry = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *newentry = (GISTENTRY *) PG_GETARG_POINTER(1); float *result = (float *) PG_GETARG_POINTER(2); IP6R *key = (IP6R *) DatumGetPointer(origentry->key); IP6R *newkey = (IP6R *) DatumGetPointer(newentry->key); IP6R ud; double tmp = 0.0; /* rather than subtract the sizes, which might lose due to rounding errors, * we calculate the actual number of addresses added to the range. */ if (ip6_lessthan(&newkey->lower,&key->lower)) { ud.lower = newkey->lower; ud.upper = key->lower; ip6_sub_int(&ud.upper,1,&ud.upper); tmp = ip6r_metric(&ud); } if (ip6_lessthan(&key->upper,&newkey->upper)) { ud.lower = key->upper; ud.upper = newkey->upper; ip6_sub_int(&ud.upper,1,&ud.upper); tmp += ip6r_metric(&ud); } /* * we want to scale the result a bit. For one thing, the gist code implicitly * assigns a penalty of 1e10 for a union of null and non-null values, and we * want to keep our values less than that. For another, the penalty is sometimes * summed across columns of a multi-column index, and we don't want our huge * metrics (>2^80) to completely swamp anything else. * * So, we scale as the fourth power of the log2 of the computed penalty, which * gives us a range 0 - 268435456. */ *result = (float) pow(log(tmp+1) / log(2), 4); #ifdef GIST_DEBUG fprintf(stderr, "penalty\n"); fprintf(stderr, "\t%g\n", *result); #endif PG_RETURN_POINTER(result); } /* Helper functions for picksplit. We might need to sort a list of * ranges by size; these are for that. */ struct gip6r_sort { IP6R *key; OffsetNumber pos; }; static int gip6r_sort_compare(const void *a, const void *b) { double sa = ip6r_metric(((struct gip6r_sort *)a)->key); double sb = ip6r_metric(((struct gip6r_sort *)b)->key); return (sa > sb) ? 1 : ((sa == sb) ? 0 : -1); } /* ** The GiST PickSplit method for IP ranges ** This is a linear-time algorithm based on a left/right split, ** based on the box functions in rtree_gist simplified to one ** dimension */ PG_FUNCTION_INFO_V1(gip6r_picksplit); Datum gip6r_picksplit(PG_FUNCTION_ARGS) { GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0); GIST_SPLITVEC *v = (GIST_SPLITVEC *) PG_GETARG_POINTER(1); GISTENTRY *ent = GISTENTRYVEC(entryvec); OffsetNumber i; int nbytes; OffsetNumber maxoff; OffsetNumber *listL; OffsetNumber *listR; bool allisequal = true; IP6R pageunion; IP6R *cur; IP6R *unionL; IP6R *unionR; int posL = 0; int posR = 0; posL = posR = 0; maxoff = GISTENTRYCOUNT(entryvec) - 1; cur = (IP6R *) DatumGetPointer(ent[FirstOffsetNumber].key); pageunion = *cur; /* find MBR */ for (i = OffsetNumberNext(FirstOffsetNumber); i <= maxoff; i = OffsetNumberNext(i)) { cur = (IP6R *) DatumGetPointer(ent[i].key); if (allisequal == true && !ip6r_equal(&pageunion,cur)) allisequal = false; if (ip6_lessthan(&cur->lower,&pageunion.lower)) pageunion.lower = cur->lower; if (ip6_lessthan(&pageunion.upper,&cur->upper)) pageunion.upper = cur->upper; } nbytes = (maxoff + 2) * sizeof(OffsetNumber); listL = (OffsetNumber *) palloc(nbytes); listR = (OffsetNumber *) palloc(nbytes); unionL = palloc(sizeof(IP6R)); unionR = palloc(sizeof(IP6R)); v->spl_ldatum = PointerGetDatum(unionL); v->spl_rdatum = PointerGetDatum(unionR); v->spl_left = listL; v->spl_right = listR; if (allisequal) { cur = (IP6R *) DatumGetPointer(ent[OffsetNumberNext(FirstOffsetNumber)].key); if (ip6r_equal(cur, &pageunion)) { OffsetNumber split_at = FirstOffsetNumber + (maxoff - FirstOffsetNumber + 1)/2; v->spl_nleft = v->spl_nright = 0; *unionL = pageunion; *unionR = pageunion; for (i = FirstOffsetNumber; i < split_at; i = OffsetNumberNext(i)) v->spl_left[v->spl_nleft++] = i; for (; i <= maxoff; i = OffsetNumberNext(i)) v->spl_right[v->spl_nright++] = i; PG_RETURN_POINTER(v); } } #define ADDLIST( list_, u_, pos_, num_ ) do { \ if ( pos_ ) { \ if ( ip6_lessthan(&(u_)->upper, &(cur)->upper) ) (u_)->upper = (cur)->upper; \ if ( ip6_lessthan(&(cur)->lower, &(u_)->lower) ) (u_)->lower = (cur)->lower; \ } else { \ *(u_) = *(cur); \ } \ (list_)[(pos_)++] = (num_); \ } while(0) for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i)) { IP6 diff1; IP6 diff2; cur = (IP6R *) DatumGetPointer(ent[i].key); ip6_sub(&cur->lower, &pageunion.lower, &diff1); ip6_sub(&pageunion.upper, &cur->upper, &diff2); if (ip6_lessthan(&diff1,&diff2)) ADDLIST(listL, unionL, posL, i); else ADDLIST(listR, unionR, posR, i); } /* bad disposition, sort by ascending size and resplit */ if (posR == 0 || posL == 0) { struct gip6r_sort *arr = (struct gip6r_sort *) palloc(sizeof(struct gip6r_sort) * (maxoff + FirstOffsetNumber)); for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i)) { arr[i].key = (IP6R *) DatumGetPointer(ent[i].key); arr[i].pos = i; } qsort(arr + FirstOffsetNumber, maxoff - FirstOffsetNumber + 1, sizeof(struct gip6r_sort), gip6r_sort_compare); posL = posR = 0; for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i)) { IP6 diff1; IP6 diff2; cur = arr[i].key; ip6_sub(&cur->lower, &pageunion.lower, &diff1); ip6_sub(&pageunion.upper, &cur->upper, &diff2); if (ip6_lessthan(&diff1,&diff2)) ADDLIST(listL, unionL, posL, arr[i].pos); else if (ip6_equal(&diff1,&diff2)) { if (posL > posR) ADDLIST(listR, unionR, posR, arr[i].pos); else ADDLIST(listL, unionL, posL, arr[i].pos); } else ADDLIST(listR, unionR, posR, arr[i].pos); } pfree(arr); } v->spl_nleft = posL; v->spl_nright = posR; PG_RETURN_POINTER(v); } #undef ADDLIST /* ** Equality methods */ PG_FUNCTION_INFO_V1(gip6r_same); Datum gip6r_same(PG_FUNCTION_ARGS) { IP6R *v1 = (IP6R *) PG_GETARG_POINTER(0); IP6R *v2 = (IP6R *) PG_GETARG_POINTER(1); bool *result = (bool *) PG_GETARG_POINTER(2); if (v1 && v2) *result = ip6r_equal(v1,v2); else *result = (v1 == NULL && v2 == NULL); #ifdef GIST_DEBUG fprintf(stderr, "same: %s\n", (*result ? "TRUE" : "FALSE")); #endif PG_RETURN_POINTER(result); } /* * Strategy numbers: * OPERATOR 1 >>= , * OPERATOR 2 <<= , * OPERATOR 3 >> , * OPERATOR 4 << , * OPERATOR 5 && , * OPERATOR 6 = , */ /* ** SUPPORT ROUTINES */ static bool gip6r_leaf_consistent(IP6R * key, IP6R * query, StrategyNumber strategy) { #ifdef GIST_QUERY_DEBUG fprintf(stderr, "leaf_consistent, %d\n", strategy); #endif switch (strategy) { case 1: /* left contains right nonstrict */ return ip6r_contains_internal(key, query, TRUE); case 2: /* left contained in right nonstrict */ return ip6r_contains_internal(query, key, TRUE); case 3: /* left contains right strict */ return ip6r_contains_internal(key, query, FALSE); case 4: /* left contained in right strict */ return ip6r_contains_internal(query, key, FALSE); case 5: /* left overlaps right */ return ip6r_overlaps_internal(key, query); case 6: /* left equal right */ return ip6r_equal(key, query); default: return FALSE; } } /* logic notes: * If the union value we're looking at overlaps with our query value * at all, then any of the values underneath it might overlap with us * or be contained by us, so all the "contained by" and "overlaps" * cases degenerate to "overlap". * If the union value is equal to the query value, then none of the * values under it can strictly contain the query value, so for * "contained" queries the strictness is preserved. * If we're looking for an "equal" value, then we have to enter any * subtree whose union contains (not strictly) our query value. */ bool gip6r_internal_consistent(IP6R * key, IP6R * query, StrategyNumber strategy) { #ifdef GIST_QUERY_DEBUG fprintf(stderr, "internal_consistent, %d\n", strategy); #endif switch (strategy) { case 2: /* left contained in right nonstrict */ case 4: /* left contained in right strict */ case 5: /* left overlaps right */ return ip6r_overlaps_internal(key, query); case 3: /* left contains right strict */ return ip6r_contains_internal(key, query, FALSE); case 1: /* left contains right nonstrict */ case 6: /* left equal right */ return ip6r_contains_internal(key, query, TRUE); default: return FALSE; } } /* end */ ip4r-2.0.2/ip6r_funcs.h000066400000000000000000000164771233620317400146400ustar00rootroot00000000000000/* $Id: ip6r_funcs.h,v 1.1 2011/08/03 20:16:03 andrewsn Exp $ */ /**************************************************************************/ /* This part is the internal implementation of all functionality, with no * reference to the interface with postgres. That part comes later and is * implemented in terms of these functions. */ static inline uint64 hostmask6_hi(unsigned masklen) { if (masklen >= 64) return 0; if (masklen == 0) return ~((uint64)0); return (((uint64)(1U)) << (64-masklen)) - 1U; } static inline uint64 hostmask6_lo(unsigned masklen) { if (masklen <= 64) return ~((uint64)0); return (((uint64)(1U)) << (128-masklen)) - 1U; } static inline uint64 netmask6_hi(unsigned masklen) { return ~hostmask6_hi(masklen); } static inline uint64 netmask6_lo(unsigned masklen) { return ~hostmask6_lo(masklen); } /* if LO and HI are ends of a CIDR prefix, return the mask length. * If not, returns ~0. */ static inline unsigned masklen64(uint64 lo, uint64 hi, int offset) { uint64 d = (lo ^ hi) + 1; int t = 0; int b; /* at this point, d can be: * 0 if A and B have all bits different * 1 if A and B are equal * 1 << (64-masklen) * some other value if A and B are not ends of a CIDR range * but in any case, after extracting the masklen, we have to * recheck because some non-CIDR ranges will produce the same * results. */ if (d == 0) return (lo == 0 && hi == ~((uint64)0)) ? offset : ~0; if (d == 1) return (lo == hi) ? 64+offset : ~0; if (!(d & 0xFFFFFFFFUL)) { t = 32; d >>= 32; } b = ffs((uint32) d); if ((((uint32)1U) << (b-1)) != d) return ~0; { uint64 mask = ((uint64)(1U) << (t+b-1)) - 1U; if ((lo & mask) == 0 && (hi & mask) == mask) return 65-t-b + offset; } return ~0; } static inline unsigned masklen6(IP6 *lo, IP6 *hi) { if (lo->bits[0] == hi->bits[0]) /* masklen >= 64 */ { return masklen64(lo->bits[1], hi->bits[1], 64); } else /* masklen < 64 */ { if (lo->bits[1] != 0 || hi->bits[1] != ~((uint64)0)) return ~0U; return masklen64(lo->bits[0], hi->bits[0], 0); } } static inline bool ip6_valid_netmask(uint64 maskhi, uint64 masklo) { uint64 d; int fbit; if (maskhi == ~((uint64)0)) d = ~masklo + 1; else if (masklo == 0) d = ~maskhi + 1; else return FALSE; /* at this point, d can be: * 0 if mask was 0x00000000 (valid) * 1 << (32-masklen) (valid) * some other value (invalid) */ if (!(d & 0xFFFFFFFFUL)) d >>= 32; if (!d) return TRUE; fbit = ffs((uint32)d); return ((uint32)(1U) << (fbit-1)) == d; } static inline bool ip6_equal(IP6 *a, IP6 *b) { return (a->bits[0] == b->bits[0]) && (a->bits[1] == b->bits[1]); } static inline int ip6_compare(IP6 *a, IP6 *b) { if (a->bits[0] != b->bits[0]) return (a->bits[0] > b->bits[0]) ? 1 : -1; if (a->bits[1] != b->bits[1]) return (a->bits[1] > b->bits[1]) ? 1 : -1; return 0; } static inline bool ip6_lessthan(IP6 *a, IP6 *b) { return ( (a->bits[0] < b->bits[0]) || ((a->bits[0] == b->bits[0]) && (a->bits[1] < b->bits[1])) ); } static inline void ip6_sub(IP6 *minuend, IP6 *subtrahend, IP6 *result) { result->bits[1] = minuend->bits[1] - subtrahend->bits[1]; result->bits[0] = minuend->bits[0] - subtrahend->bits[0] - (minuend->bits[1] < subtrahend->bits[1]); } static inline void ip6_sub_int(IP6 *minuend, int subtrahend, IP6 *result) { uint64 res_lo; if (subtrahend >= 0) { res_lo = minuend->bits[1] - (uint64)(subtrahend); result->bits[0] = minuend->bits[0] - (res_lo > minuend->bits[1]); } else { res_lo = minuend->bits[1] + (uint64)(-subtrahend); result->bits[0] = minuend->bits[0] + (res_lo < minuend->bits[1]); } result->bits[1] = res_lo; } static inline bool ip6r_from_cidr(IP6 *prefix, unsigned masklen, IP6R *ipr) { uint64 mask_lo = hostmask6_lo(masklen); uint64 mask_hi = hostmask6_hi(masklen); if (masklen > 128) return FALSE; if ((prefix->bits[0] & mask_hi) || (prefix->bits[1] & mask_lo)) return FALSE; ipr->upper.bits[0] = (prefix->bits[0] | mask_hi); ipr->upper.bits[1] = (prefix->bits[1] | mask_lo); ipr->lower = *prefix; return TRUE; } static inline bool ip6r_from_inet(IP6 *addr, unsigned masklen, IP6R *ipr) { uint64 mask_lo = hostmask6_lo(masklen); uint64 mask_hi = hostmask6_hi(masklen); if (masklen > 128) return FALSE; ipr->lower.bits[0] = (addr->bits[0] & ~mask_hi); ipr->lower.bits[1] = (addr->bits[1] & ~mask_lo); ipr->upper.bits[0] = (addr->bits[0] | mask_hi); ipr->upper.bits[1] = (addr->bits[1] | mask_lo); return TRUE; } /* helpers for union/intersection for indexing */ /* note that this function has to handle the case where RESULT aliases * either of A or B */ static inline IP6R *ip6r_union_internal(IP6R *a, IP6R *b, IP6R *result) { if (ip6_lessthan(&a->lower,&b->lower)) result->lower = a->lower; else result->lower = b->lower; if (ip6_lessthan(&b->upper,&a->upper)) result->upper = a->upper; else result->upper = b->upper; return result; } static inline IP6R *ip6r_inter_internal(IP6R *a, IP6R *b, IP6R *result) { if (ip6_lessthan(&a->upper,&b->lower) || ip6_lessthan(&b->upper,&a->lower)) { /* disjoint */ result->lower.bits[0] = 0; result->lower.bits[1] = 1; result->upper.bits[0] = 0; /* INVALID VALUE */ result->upper.bits[1] = 0; /* INVALID VALUE */ return NULL; } if (ip6_lessthan(&a->upper,&b->upper)) result->upper = a->upper; else result->upper = b->upper; if (ip6_lessthan(&b->lower,&a->lower)) result->lower = a->lower; else result->lower = b->lower; return result; } static inline double ip6r_metric(IP6R *v) { IP6 diff; double res = 0.0; if (!v) return res; ip6_sub(&v->upper, &v->lower, &diff); return ( (ldexp((double)diff.bits[0],64)) + (diff.bits[1] + 1.0) ); } /* comparisons */ static inline bool ip6_less_eq(IP6 *a, IP6 *b) { return !ip6_lessthan(b,a); } static inline bool ip6r_equal(IP6R *a, IP6R *b) { return ip6_equal(&a->lower,&b->lower) && ip6_equal(&a->upper,&b->upper); } static inline bool ip6r_lessthan(IP6R *a, IP6R *b) { switch (ip6_compare(&a->lower,&b->lower)) { default: return ip6_lessthan(&a->upper,&b->upper); case -1: return true; case 1: return false; } } static inline bool ip6r_less_eq(IP6R *a, IP6R *b) { return !ip6r_lessthan(b,a); } static inline bool ip6r_contains_internal(IP6R *left, IP6R *right, bool eqval) { if (ip6r_equal(left,right)) return eqval; return !ip6_lessthan(&right->lower,&left->lower) && !ip6_lessthan(&left->upper,&right->upper); } static inline bool ip6r_overlaps_internal(IP6R *left, IP6R *right) { return !ip6_lessthan(&left->upper,&right->lower) && !ip6_lessthan(&right->upper,&left->lower); } static inline bool ip6_contains_internal(IP6R *left, IP6 *right) { return !ip6_lessthan(right,&left->lower) && !ip6_lessthan(&left->upper,right); } /* end */ ip4r-2.0.2/ipaddr.c000066400000000000000000000376541233620317400140200ustar00rootroot00000000000000/* $Id: ipaddr.c,v 1.1 2011/08/03 20:16:03 andrewsn Exp $ */ #include "ipr.h" #include "ip4r_funcs.h" #include "ip6r_funcs.h" void ipaddr_internal_error(void) { elog(ERROR,"Invalid IP datum"); /* just to shut the compiler up */ abort(); } /* * generic transforms of IP values - apply the specified ip4 or ip6 function * to the given args according to parameter type. Where the result type is an * IP, it's the same family as the parameter IP. */ /* func(IP) returns Datum */ static inline Datum ipaddr_transform_1d(Datum d, PGFunction ip4func, PGFunction ip6func) { IP_P ipp = DatumGetIP_P(d); IP ip; int af = ip_unpack(ipp, &ip); switch (af) { case PGSQL_AF_INET: return DirectFunctionCall1(ip4func, IP4GetDatum(ip.ip4)); case PGSQL_AF_INET6: return DirectFunctionCall1(ip6func, IP6PGetDatum(&ip.ip6)); } ipaddr_internal_error(); } /* func(IP) returns IP */ static inline IP_P ipaddr_transform_1(Datum d, PGFunction ip4func, PGFunction ip6func) { IP_P ipp = DatumGetIP_P(d); IP ip; int af = ip_unpack(ipp, &ip); switch (af) { case PGSQL_AF_INET: ip.ip4 = DatumGetIP4(DirectFunctionCall1(ip4func, IP4GetDatum(ip.ip4))); break; case PGSQL_AF_INET6: ip.ip6 = *(DatumGetIP6P(DirectFunctionCall1(ip6func, IP6PGetDatum(&ip.ip6)))); break; default: ipaddr_internal_error(); } return ip_pack(af, &ip); } /* func(IP, Datum) returns IP */ static inline IP_P ipaddr_transform_2d(Datum d1, Datum d2, PGFunction ip4func, PGFunction ip6func) { IP_P ipp = DatumGetIP_P(d1); IP ip; int af = ip_unpack(ipp, &ip); switch (af) { case PGSQL_AF_INET: ip.ip4 = DatumGetIP4(DirectFunctionCall2(ip4func, IP4GetDatum(ip.ip4), d2)); break; case PGSQL_AF_INET6: ip.ip6 = *(DatumGetIP6P(DirectFunctionCall2(ip6func, IP6PGetDatum(&ip.ip6), d2))); break; default: ipaddr_internal_error(); } return ip_pack(af, &ip); } /* func(IP,IP) returns IP; it's an error for the source IPs to be in different families */ static inline IP_P ipaddr_transform_2(Datum d1, Datum d2, PGFunction ip4func, PGFunction ip6func) { IP_P ipp1 = DatumGetIP_P(d1); IP_P ipp2 = DatumGetIP_P(d2); IP ip1; IP ip2; IP out; int af1 = ip_unpack(ipp1, &ip1); int af2 = ip_unpack(ipp2, &ip2); if (af1 != af2) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("invalid mixing of IP address families"))); switch (af1) { case PGSQL_AF_INET: out.ip4 = DatumGetIP4(DirectFunctionCall2(ip4func, IP4GetDatum(ip1.ip4), IP4GetDatum(ip2.ip4))); break; case PGSQL_AF_INET6: out.ip6 = *(DatumGetIP6P(DirectFunctionCall2(ip6func, IP6PGetDatum(&ip1.ip6), IP6PGetDatum(&ip2.ip6)))); break; default: ipaddr_internal_error(); } return ip_pack(af1, &out); } /* #define GIST_DEBUG #define GIST_QUERY_DEBUG */ static text * make_text(char *str, int len) { text *ret = (text *) palloc(len + VARHDRSZ); SET_VARSIZE(ret, len + VARHDRSZ); if (str) memcpy(VARDATA(ret), str, len); else memset(VARDATA(ret), 0, len); return ret; } static inline void set_text_len(text *txt, int len) { if ((len + VARHDRSZ) < VARSIZE(txt)) SET_VARSIZE(txt, len + VARHDRSZ); } /* ** Input/Output routines */ PG_FUNCTION_INFO_V1(ipaddr_in); Datum ipaddr_in(PG_FUNCTION_ARGS) { char *str = PG_GETARG_CSTRING(0); IP ip; if (strchr(str,':')) { if (ip6_raw_input(str, ip.ip6.bits)) PG_RETURN_IP_P(ip_pack(PGSQL_AF_INET6, &ip)); } else { if (ip4_raw_input(str, &ip.ip4)) PG_RETURN_IP_P(ip_pack(PGSQL_AF_INET, &ip)); } ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("invalid IP value: '%s'", str))); PG_RETURN_NULL(); } PG_FUNCTION_INFO_V1(ipaddr_out); Datum ipaddr_out(PG_FUNCTION_ARGS) { IP_P ipp = PG_GETARG_IP_P(0); char *out = palloc(IP6_STRING_MAX); IP ip; switch (ip_unpack(ipp, &ip)) { case PGSQL_AF_INET: ip4_raw_output(ip.ip4, out, IP6_STRING_MAX); break; case PGSQL_AF_INET6: ip6_raw_output(ip.ip6.bits, out, IP6_STRING_MAX); break; } PG_RETURN_CSTRING(out); } PG_FUNCTION_INFO_V1(ipaddr_recv); Datum ipaddr_recv(PG_FUNCTION_ARGS) { StringInfo buf = (StringInfo) PG_GETARG_POINTER(0); IP ip; int af, bits, flag, nbytes; /* we copy the external format used by inet/cidr, just because. */ af = pq_getmsgbyte(buf); if (af != PGSQL_AF_INET && af != PGSQL_AF_INET6) ereport(ERROR, (errcode(ERRCODE_INVALID_BINARY_REPRESENTATION), errmsg("invalid address family in external IP value"))); bits = pq_getmsgbyte(buf); if (bits != ipr_af_maxbits(af)) ereport(ERROR, (errcode(ERRCODE_INVALID_BINARY_REPRESENTATION), errmsg("invalid bit length in external IP value"))); flag = pq_getmsgbyte(buf); /* ignored */ nbytes = pq_getmsgbyte(buf); if (nbytes*8 != bits) ereport(ERROR, (errcode(ERRCODE_INVALID_BINARY_REPRESENTATION), errmsg("invalid address length in external IP value"))); switch (af) { case PGSQL_AF_INET: ip.ip4 = (IP4) pq_getmsgint(buf, sizeof(IP4)); break; case PGSQL_AF_INET6: ip.ip6.bits[0] = pq_getmsgint64(buf); ip.ip6.bits[1] = pq_getmsgint64(buf); break; } PG_RETURN_IP_P(ip_pack(af, &ip)); } PG_FUNCTION_INFO_V1(ipaddr_send); Datum ipaddr_send(PG_FUNCTION_ARGS) { IP_P arg1 = PG_GETARG_IP_P(0); StringInfoData buf; IP ip; int af = ip_unpack(arg1, &ip); pq_begintypsend(&buf); pq_sendbyte(&buf, af); pq_sendbyte(&buf, ipr_af_maxbits(af)); pq_sendbyte(&buf, 1); pq_sendbyte(&buf, ip_sizeof(af)); switch (af) { case PGSQL_AF_INET: pq_sendint(&buf, ip.ip4, sizeof(IP4)); break; case PGSQL_AF_INET6: pq_sendint64(&buf, ip.ip6.bits[0]); pq_sendint64(&buf, ip.ip6.bits[1]); break; } PG_RETURN_BYTEA_P(pq_endtypsend(&buf)); } PG_FUNCTION_INFO_V1(ipaddr_hash); Datum ipaddr_hash(PG_FUNCTION_ARGS) { IP_P arg1 = PG_GETARG_IP_P(0); return hash_any((void*)(VARDATA_ANY(arg1)), VARSIZE_ANY_EXHDR(arg1)); } PG_FUNCTION_INFO_V1(ipaddr_cast_to_text); Datum ipaddr_cast_to_text(PG_FUNCTION_ARGS) { IP_P ipp = PG_GETARG_IP_P(0); IP ip; int af = ip_unpack(ipp, &ip); text *out = NULL; switch (af) { case PGSQL_AF_INET: out = make_text(NULL, IP4_STRING_MAX); set_text_len(out, ip4_raw_output(ip.ip4, VARDATA(out), IP4_STRING_MAX)); break; case PGSQL_AF_INET6: out = make_text(NULL, IP6_STRING_MAX); set_text_len(out, ip6_raw_output(ip.ip6.bits, VARDATA(out), IP6_STRING_MAX)); break; } PG_RETURN_TEXT_P(out); } PG_FUNCTION_INFO_V1(ipaddr_cast_from_text); Datum ipaddr_cast_from_text(PG_FUNCTION_ARGS) { text *txt = PG_GETARG_TEXT_PP(0); int tlen = VARSIZE_ANY_EXHDR(txt); char buf[IP6_STRING_MAX]; if (tlen < sizeof(buf)) { IP ip; memcpy(buf, VARDATA_ANY(txt), tlen); buf[tlen] = 0; if (strchr(buf,':')) { if (ip6_raw_input(buf, ip.ip6.bits)) PG_RETURN_IP_P(ip_pack(PGSQL_AF_INET6, &ip)); } else { if (ip4_raw_input(buf, &ip.ip4)) PG_RETURN_IP_P(ip_pack(PGSQL_AF_INET, &ip)); } } ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("invalid IP value in text"))); PG_RETURN_NULL(); } PG_FUNCTION_INFO_V1(ipaddr_cast_from_inet); Datum ipaddr_cast_from_inet(PG_FUNCTION_ARGS) { inet *inetptr = PG_GETARG_INET_P(0); inet_struct *in = INET_STRUCT_DATA(inetptr); IP ip; switch (in->family) { case PGSQL_AF_INET: ip.ip4 = DatumGetIP4(DirectFunctionCall1(ip4_cast_from_inet, InetPGetDatum(inetptr))); PG_RETURN_IP_P(ip_pack(PGSQL_AF_INET, &ip)); case PGSQL_AF_INET6: ip.ip6 = *(DatumGetIP6P(DirectFunctionCall1(ip6_cast_from_inet, InetPGetDatum(inetptr)))); PG_RETURN_IP_P(ip_pack(PGSQL_AF_INET6, &ip)); } ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("invalid INET value for conversion to IP"))); PG_RETURN_NULL(); } PG_FUNCTION_INFO_V1(ipaddr_cast_to_cidr); Datum ipaddr_cast_to_cidr(PG_FUNCTION_ARGS) { PG_RETURN_DATUM(ipaddr_transform_1d(PG_GETARG_DATUM(0), ip4_cast_to_cidr, ip6_cast_to_cidr)); } PG_FUNCTION_INFO_V1(ipaddr_cast_to_numeric); Datum ipaddr_cast_to_numeric(PG_FUNCTION_ARGS) { PG_RETURN_DATUM(ipaddr_transform_1d(PG_GETARG_DATUM(0), ip4_cast_to_numeric, ip6_cast_to_numeric)); } PG_FUNCTION_INFO_V1(ipaddr_cast_from_ip4); Datum ipaddr_cast_from_ip4(PG_FUNCTION_ARGS) { IP ip; ip.ip4 = PG_GETARG_IP4(0); PG_RETURN_IP_P(ip_pack(PGSQL_AF_INET, &ip)); } PG_FUNCTION_INFO_V1(ipaddr_cast_from_ip6); Datum ipaddr_cast_from_ip6(PG_FUNCTION_ARGS) { IP6 *in = PG_GETARG_IP6_P(0); IP ip; ip.ip6 = *in; PG_RETURN_IP_P(ip_pack(PGSQL_AF_INET6, &ip)); } PG_FUNCTION_INFO_V1(ipaddr_cast_to_ip4); Datum ipaddr_cast_to_ip4(PG_FUNCTION_ARGS) { IP_P ipp = PG_GETARG_IP_P(0); IP ip; if (ip_unpack(ipp, &ip) == PGSQL_AF_INET) { PG_RETURN_IP4(ip.ip4); } ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("invalid IP value in cast to IP4"))); PG_RETURN_NULL(); } PG_FUNCTION_INFO_V1(ipaddr_cast_to_ip6); Datum ipaddr_cast_to_ip6(PG_FUNCTION_ARGS) { IP_P ipp = PG_GETARG_IP_P(0); IP ip; if (ip_unpack(ipp, &ip) == PGSQL_AF_INET6) { IP6 *out = palloc(sizeof(IP6)); *out = ip.ip6; PG_RETURN_IP6_P(out); } ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("invalid IP value in cast to IP4"))); PG_RETURN_NULL(); } PG_FUNCTION_INFO_V1(ipaddr_family); Datum ipaddr_family(PG_FUNCTION_ARGS) { IP_P ipp = PG_GETARG_IP_P(0); IP ip; if (ip_unpack(ipp, &ip) == PGSQL_AF_INET6) PG_RETURN_INT32(6); else PG_RETURN_INT32(4); } PG_FUNCTION_INFO_V1(ipaddr_net_lower); Datum ipaddr_net_lower(PG_FUNCTION_ARGS) { PG_RETURN_IP_P(ipaddr_transform_2d(PG_GETARG_DATUM(0), PG_GETARG_DATUM(1), ip4_net_lower, ip6_net_lower)); } PG_FUNCTION_INFO_V1(ipaddr_net_upper); Datum ipaddr_net_upper(PG_FUNCTION_ARGS) { PG_RETURN_IP_P(ipaddr_transform_2d(PG_GETARG_DATUM(0), PG_GETARG_DATUM(1), ip4_net_upper, ip6_net_upper)); } PG_FUNCTION_INFO_V1(ipaddr_plus_int); Datum ipaddr_plus_int(PG_FUNCTION_ARGS) { PG_RETURN_IP_P(ipaddr_transform_2d(PG_GETARG_DATUM(0), PG_GETARG_DATUM(1), ip4_plus_int, ip6_plus_int)); } PG_FUNCTION_INFO_V1(ipaddr_plus_bigint); Datum ipaddr_plus_bigint(PG_FUNCTION_ARGS) { PG_RETURN_IP_P(ipaddr_transform_2d(PG_GETARG_DATUM(0), PG_GETARG_DATUM(1), ip4_plus_bigint, ip6_plus_bigint)); } PG_FUNCTION_INFO_V1(ipaddr_plus_numeric); Datum ipaddr_plus_numeric(PG_FUNCTION_ARGS) { PG_RETURN_IP_P(ipaddr_transform_2d(PG_GETARG_DATUM(0), PG_GETARG_DATUM(1), ip4_plus_numeric, ip6_plus_numeric)); } PG_FUNCTION_INFO_V1(ipaddr_minus_int); Datum ipaddr_minus_int(PG_FUNCTION_ARGS) { PG_RETURN_IP_P(ipaddr_transform_2d(PG_GETARG_DATUM(0), PG_GETARG_DATUM(1), ip4_minus_int, ip6_minus_int)); } PG_FUNCTION_INFO_V1(ipaddr_minus_bigint); Datum ipaddr_minus_bigint(PG_FUNCTION_ARGS) { PG_RETURN_IP_P(ipaddr_transform_2d(PG_GETARG_DATUM(0), PG_GETARG_DATUM(1), ip4_minus_bigint, ip6_minus_bigint)); } PG_FUNCTION_INFO_V1(ipaddr_minus_numeric); Datum ipaddr_minus_numeric(PG_FUNCTION_ARGS) { PG_RETURN_IP_P(ipaddr_transform_2d(PG_GETARG_DATUM(0), PG_GETARG_DATUM(1), ip4_minus_numeric, ip6_minus_numeric)); } PG_FUNCTION_INFO_V1(ipaddr_minus_ipaddr); Datum ipaddr_minus_ipaddr(PG_FUNCTION_ARGS) { Datum minuend = PG_GETARG_DATUM(0); Datum subtrahend = PG_GETARG_DATUM(1); Datum res; IP ip1; IP ip2; int af1 = ip_unpack(DatumGetIP_P(minuend), &ip1); int af2 = ip_unpack(DatumGetIP_P(subtrahend), &ip2); if (af1 != af2) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("invalid mixing of IP address families"))); switch (af1) { case PGSQL_AF_INET: res = DirectFunctionCall2(numeric_sub, DirectFunctionCall1(ip4_cast_to_numeric,IP4GetDatum(ip1.ip4)), DirectFunctionCall1(ip4_cast_to_numeric,IP4GetDatum(ip2.ip4))); break; case PGSQL_AF_INET6: res = DirectFunctionCall2(numeric_sub, DirectFunctionCall1(ip6_cast_to_numeric,IP6PGetDatum(&ip1.ip6)), DirectFunctionCall1(ip6_cast_to_numeric,IP6PGetDatum(&ip2.ip6))); break; default: ipaddr_internal_error(); } PG_RETURN_DATUM(res); } PG_FUNCTION_INFO_V1(ipaddr_and); Datum ipaddr_and(PG_FUNCTION_ARGS) { PG_RETURN_IP_P(ipaddr_transform_2(PG_GETARG_DATUM(0), PG_GETARG_DATUM(1), ip4_and, ip6_and)); } PG_FUNCTION_INFO_V1(ipaddr_or); Datum ipaddr_or(PG_FUNCTION_ARGS) { PG_RETURN_IP_P(ipaddr_transform_2(PG_GETARG_DATUM(0), PG_GETARG_DATUM(1), ip4_or, ip6_or)); } PG_FUNCTION_INFO_V1(ipaddr_xor); Datum ipaddr_xor(PG_FUNCTION_ARGS) { PG_RETURN_IP_P(ipaddr_transform_2(PG_GETARG_DATUM(0), PG_GETARG_DATUM(1), ip4_xor, ip6_xor)); } PG_FUNCTION_INFO_V1(ipaddr_not); Datum ipaddr_not(PG_FUNCTION_ARGS) { PG_RETURN_IP_P(ipaddr_transform_1(PG_GETARG_DATUM(0), ip4_not, ip6_not)); } /* * generic boolean comparison of two IPs. If in the same family, then the * passed-in comparison function is called; if in different families, then * the result is mismatch_af1 or _af2 according to which of the first or * second address is in the larger family. */ static inline bool ipaddr_comparison_bool(Datum d1, Datum d2, bool mismatch_af1, bool mismatch_af2, PGFunction ip4func, PGFunction ip6func) { IP_P ipp1 = DatumGetIP_P(d1); IP_P ipp2 = DatumGetIP_P(d2); IP ip1; IP ip2; int af1 = ip_unpack(ipp1, &ip1); int af2 = ip_unpack(ipp2, &ip2); bool retval; if (af1 != af2) { retval = (af1 > af2) ? mismatch_af1 : mismatch_af2; } else { switch (af1) { case PGSQL_AF_INET: retval = DatumGetBool(DirectFunctionCall2(ip4func, IP4GetDatum(ip1.ip4), IP4GetDatum(ip2.ip4))); break; case PGSQL_AF_INET6: retval = DatumGetBool(DirectFunctionCall2(ip6func, IP6PGetDatum(&ip1.ip6), IP6PGetDatum(&ip2.ip6))); break; default: ipaddr_internal_error(); } } if ((Pointer)ipp1 != DatumGetPointer(d1)) pfree(ipp1); if ((Pointer)ipp2 != DatumGetPointer(d2)) pfree(ipp2); return retval; } PG_FUNCTION_INFO_V1(ipaddr_lt); Datum ipaddr_lt(PG_FUNCTION_ARGS) { PG_RETURN_BOOL( ipaddr_comparison_bool(PG_GETARG_DATUM(0), PG_GETARG_DATUM(1), false, true, ip4_lt, ip6_lt)); } PG_FUNCTION_INFO_V1(ipaddr_le); Datum ipaddr_le(PG_FUNCTION_ARGS) { PG_RETURN_BOOL( ipaddr_comparison_bool(PG_GETARG_DATUM(0), PG_GETARG_DATUM(1), false, true, ip4_le, ip6_le)); } PG_FUNCTION_INFO_V1(ipaddr_gt); Datum ipaddr_gt(PG_FUNCTION_ARGS) { PG_RETURN_BOOL( ipaddr_comparison_bool(PG_GETARG_DATUM(0), PG_GETARG_DATUM(1), true, false, ip4_gt, ip6_gt)); } PG_FUNCTION_INFO_V1(ipaddr_ge); Datum ipaddr_ge(PG_FUNCTION_ARGS) { PG_RETURN_BOOL( ipaddr_comparison_bool(PG_GETARG_DATUM(0), PG_GETARG_DATUM(1), true, false, ip4_ge, ip6_ge)); } PG_FUNCTION_INFO_V1(ipaddr_eq); Datum ipaddr_eq(PG_FUNCTION_ARGS) { PG_RETURN_BOOL( ipaddr_comparison_bool(PG_GETARG_DATUM(0), PG_GETARG_DATUM(1), false, false, ip4_eq, ip6_eq)); } PG_FUNCTION_INFO_V1(ipaddr_neq); Datum ipaddr_neq(PG_FUNCTION_ARGS) { PG_RETURN_BOOL( ipaddr_comparison_bool(PG_GETARG_DATUM(0), PG_GETARG_DATUM(1), true, true, ip4_neq, ip6_neq)); } /***************************************************************************** * Btree functions *****************************************************************************/ PG_FUNCTION_INFO_V1(ipaddr_cmp); Datum ipaddr_cmp(PG_FUNCTION_ARGS) { IP_P ipp1 = PG_GETARG_IP_P(0); IP_P ipp2 = PG_GETARG_IP_P(1); IP ip1; IP ip2; int af1 = ip_unpack(ipp1, &ip1); int af2 = ip_unpack(ipp2, &ip2); int32 retval; if (af1 != af2) { retval = (af1 > af2) ? 1 : -1; } else { switch (af1) { case PGSQL_AF_INET: retval = DatumGetInt32(DirectFunctionCall2(ip4_cmp, IP4GetDatum(ip1.ip4), IP4GetDatum(ip2.ip4))); break; case PGSQL_AF_INET6: retval = DatumGetInt32(DirectFunctionCall2(ip6_cmp, IP6PGetDatum(&ip1.ip6), IP6PGetDatum(&ip2.ip6))); break; default: ipaddr_internal_error(); } } PG_FREE_IF_COPY(ipp1,0); PG_FREE_IF_COPY(ipp2,1); PG_RETURN_INT32(retval); } ip4r-2.0.2/ipr.h000066400000000000000000000356561233620317400133540ustar00rootroot00000000000000/* $Id: ipr.h,v 1.2 2011/08/22 14:05:19 andrewsn Exp $ */ #include #include "postgres.h" #include "access/gist.h" #include "access/skey.h" #include "access/hash.h" #include "libpq/pqformat.h" #include "utils/elog.h" #include "utils/palloc.h" #include "utils/builtins.h" #include "utils/inet.h" #include "utils/numeric.h" #include #include #include bool ip4_raw_input(const char *src, uint32 *dst); bool ip6_raw_input(const char *src, uint64 *dst); int ip4_raw_output(uint32 ip, char *str, int len); int ip6_raw_output(uint64 *ip, char *str, int len); /* IP4 = uint32, stored in host-order. fixed-length and pass by value. */ typedef uint32 IP4; /* IP4R = range of IP4, stored in host-order. fixed-length by reference */ typedef struct IP4R { IP4 lower; IP4 upper; } IP4R; /* * IP6 = 2 x uint64, stored hi to lo, each stored in host-order. * fixed-length and pass by reference. */ typedef struct IP6 { uint64 bits[2]; } IP6; /* IP6R = range of IP6. fixed-length by reference */ typedef struct IP6R { IP6 lower; IP6 upper; } IP6R; #define IP6_STRING_MAX (sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")+2) #define IP6R_STRING_MAX (2*IP6_STRING_MAX) #define IP4_STRING_MAX (sizeof("255.255.255.255")) #define IP4R_STRING_MAX (2*IP4_STRING_MAX) typedef union IP { IP4 ip4; IP6 ip6; } IP; #define ipr_af_maxbits(af_) ((af_) == PGSQL_AF_INET ? 32 : 128) #define ip_sizeof(af_) ((af_) == PGSQL_AF_INET ? sizeof(IP4) : sizeof(IP6)) #define ipr_sizeof(af_) ((af_) == PGSQL_AF_INET ? sizeof(IP4R) : sizeof(IP6R)) typedef void *IP_P; /* unaligned! */ void ipaddr_internal_error(void) __attribute__((noreturn)); static inline int ip_unpack(IP_P in, IP *out) { switch (VARSIZE_ANY_EXHDR(in)) { case sizeof(IP4): memcpy(&out->ip4, VARDATA_ANY(in), sizeof(IP4)); return PGSQL_AF_INET; case sizeof(IP6): memcpy(&out->ip6, VARDATA_ANY(in), sizeof(IP6)); return PGSQL_AF_INET6; default: ipaddr_internal_error(); } } static inline IP_P ip_pack(int af, IP *val) { int sz = ip_sizeof(af); IP_P out = palloc(VARHDRSZ + sz); SET_VARSIZE(out, VARHDRSZ + sz); memcpy(VARDATA(out), val, sz); return out; } typedef union IPR { IP4R ip4r; IP6R ip6r; } IPR; typedef void *IPR_P; /* unaligned! */ #define DatumGetIP4RP(X) ((IP4R *) DatumGetPointer(X)) #define IP4RPGetDatum(X) PointerGetDatum(X) #define PG_GETARG_IP4R_P(n) DatumGetIP4RP(PG_GETARG_DATUM(n)) #define PG_RETURN_IP4R_P(x) return IP4RPGetDatum(x) #define DatumGetIP4(X) DatumGetUInt32(X) #define IP4GetDatum(X) UInt32GetDatum(X) #define PG_GETARG_IP4(n) PG_GETARG_UINT32(n) #define PG_RETURN_IP4(x) PG_RETURN_UINT32(x) #define DatumGetIP6RP(X) ((IP6R *) DatumGetPointer(X)) #define IP6RPGetDatum(X) PointerGetDatum(X) #define PG_GETARG_IP6R_P(n) DatumGetIP6RP(PG_GETARG_DATUM(n)) #define PG_RETURN_IP6R_P(x) return IP6RPGetDatum(x) #define DatumGetIP6P(X) ((IP6 *) DatumGetPointer(X)) #define IP6PGetDatum(X) PointerGetDatum(X) #define PG_GETARG_IP6_P(n) DatumGetIP6P(PG_GETARG_DATUM(n)) #define PG_RETURN_IP6_P(x) return IP6PGetDatum(x) #define DatumGetIP_P(X) ((IP_P) PG_DETOAST_DATUM_PACKED(X)) #define IP_PGetDatum(X) PointerGetDatum(X) #define PG_GETARG_IP_P(n) DatumGetIP_P(PG_GETARG_DATUM(n)) #define PG_RETURN_IP_P(x) return IP_PGetDatum(x) #define DatumGetIPR_P(X) ((IP_P) PG_DETOAST_DATUM_PACKED(X)) #define IPR_PGetDatum(X) PointerGetDatum(X) #define PG_GETARG_IPR_P(n) DatumGetIPR_P(PG_GETARG_DATUM(n)) #define PG_RETURN_IPR_P(x) return IPR_PGetDatum(x) /* PG version dependencies */ /* now that we don't support pre-8.1, we can try and determine the pg * version without needing our own compile hack. * * PG_VERSION_NUM starts at 8.2; we distinguish 8.1 from 8.0 and before * by checking for BKI_BOOSTRAP (defined in postgres.h) */ #if !defined(PG_VERSION_NUM) #ifdef BKI_BOOSTRAP #define PG_VERSION_NUM 80100 #else #error "Unknown or unsupported postgresql version" #endif #endif /* 9.0 has no known changes from 8.4 that affect this code. */ /* 8.4 adds parameters to gist consistent() to support dynamic setting * of the "recheck" flag, and defaults recheck to true (giving us some * performance loss since we don't need recheck). */ #if PG_VERSION_NUM >= 80400 #define GIST_HAS_RECHECK #define GIST_RECHECK_ARG ((bool *) PG_GETARG_POINTER(4)) #else #define GIST_RECHECK_ARG (NULL) #endif /* 8.3 changes the varlena header (to support "short" varlenas without * needing a full 32-bit length field) and changes the varlena macros * to support this. Keep the new interface (which is cleaner than the * old one anyway) and emulate it for older versions. * * But for the "inet" type, unlike all other types, 8.3 does not convert * the packed short format back to the unpacked format in the normal * parameter macros. So we need additional macros to hide that change. * We implicitly assume here that none of the fields of 'inet_struct' * require any alignment stricter than byte (which is true at the moment, * but it's anyone's guess whether it will stay true, given how often it * seems to get changed). * * Also, for things like text strings, we might as well take advantage of * the ability to read them without forcing alignment by making a palloc'd * copy. This requires faking out a few macros on pre-8.3. */ #define INET_STRUCT_DATA(is_) ((inet_struct *)VARDATA_ANY(is_)) #if PG_VERSION_NUM < 80300 #define VARDATA_ANY(v_) VARDATA(v_) #define VARSIZE_ANY_EXHDR(v_) (VARSIZE(v_) - VARHDRSZ) #define SET_VARSIZE(var_,val_) VARATT_SIZEP(var_) = (val_) #define PG_GETARG_TEXT_PP(v_) PG_GETARG_TEXT_P(v_) #endif /* PG_MODULE_MAGIC was introduced in 8.2. */ #if PG_VERSION_NUM < 80200 #define PG_MODULE_MAGIC extern int no_such_variable #endif /* The "inet" type representation lost its "type" field in 8.2 - it was * always redundant */ #if PG_VERSION_NUM >= 80200 #define INET_INIT_CIDR(i) #define INET_IS_CIDR(i) (1) #else /* PG_VERSION_NUM < 80200 */ #define INET_INIT_CIDR(i) ((i)->type = 1) #define INET_IS_CIDR(i) ((i)->type) #endif #define GISTENTRYCOUNT(v) ((v)->n) #define GISTENTRYVEC(v) ((v)->vector) /* funcs */ Datum ip4_in(PG_FUNCTION_ARGS); Datum ip4_out(PG_FUNCTION_ARGS); Datum ip4_recv(PG_FUNCTION_ARGS); Datum ip4_send(PG_FUNCTION_ARGS); Datum ip4hash(PG_FUNCTION_ARGS); Datum ip4_cast_to_text(PG_FUNCTION_ARGS); Datum ip4_cast_from_text(PG_FUNCTION_ARGS); Datum ip4_cast_from_inet(PG_FUNCTION_ARGS); Datum ip4_cast_to_cidr(PG_FUNCTION_ARGS); Datum ip4_cast_to_bigint(PG_FUNCTION_ARGS); Datum ip4_cast_to_numeric(PG_FUNCTION_ARGS); Datum ip4_cast_from_bigint(PG_FUNCTION_ARGS); Datum ip4_cast_from_numeric(PG_FUNCTION_ARGS); Datum ip4_cast_to_double(PG_FUNCTION_ARGS); Datum ip4_cast_from_double(PG_FUNCTION_ARGS); Datum ip4r_in(PG_FUNCTION_ARGS); Datum ip4r_out(PG_FUNCTION_ARGS); Datum ip4r_recv(PG_FUNCTION_ARGS); Datum ip4r_send(PG_FUNCTION_ARGS); Datum ip4rhash(PG_FUNCTION_ARGS); Datum ip4r_cast_to_text(PG_FUNCTION_ARGS); Datum ip4r_cast_from_text(PG_FUNCTION_ARGS); Datum ip4r_cast_from_cidr(PG_FUNCTION_ARGS); Datum ip4r_cast_to_cidr(PG_FUNCTION_ARGS); Datum ip4r_cast_from_ip4(PG_FUNCTION_ARGS); Datum ip4r_from_ip4s(PG_FUNCTION_ARGS); Datum ip4r_net_prefix(PG_FUNCTION_ARGS); Datum ip4r_net_mask(PG_FUNCTION_ARGS); Datum ip4r_lower(PG_FUNCTION_ARGS); Datum ip4r_upper(PG_FUNCTION_ARGS); Datum ip4r_is_cidr(PG_FUNCTION_ARGS); Datum ip4_netmask(PG_FUNCTION_ARGS); Datum ip4_net_lower(PG_FUNCTION_ARGS); Datum ip4_net_upper(PG_FUNCTION_ARGS); Datum ip4_plus_int(PG_FUNCTION_ARGS); Datum ip4_plus_bigint(PG_FUNCTION_ARGS); Datum ip4_plus_numeric(PG_FUNCTION_ARGS); Datum ip4_minus_int(PG_FUNCTION_ARGS); Datum ip4_minus_bigint(PG_FUNCTION_ARGS); Datum ip4_minus_numeric(PG_FUNCTION_ARGS); Datum ip4_minus_ip4(PG_FUNCTION_ARGS); Datum ip4_and(PG_FUNCTION_ARGS); Datum ip4_or(PG_FUNCTION_ARGS); Datum ip4_xor(PG_FUNCTION_ARGS); Datum ip4_not(PG_FUNCTION_ARGS); Datum ip4_lt(PG_FUNCTION_ARGS); Datum ip4_le(PG_FUNCTION_ARGS); Datum ip4_gt(PG_FUNCTION_ARGS); Datum ip4_ge(PG_FUNCTION_ARGS); Datum ip4_eq(PG_FUNCTION_ARGS); Datum ip4_neq(PG_FUNCTION_ARGS); Datum ip4r_lt(PG_FUNCTION_ARGS); Datum ip4r_le(PG_FUNCTION_ARGS); Datum ip4r_gt(PG_FUNCTION_ARGS); Datum ip4r_ge(PG_FUNCTION_ARGS); Datum ip4r_eq(PG_FUNCTION_ARGS); Datum ip4r_neq(PG_FUNCTION_ARGS); Datum ip4r_overlaps(PG_FUNCTION_ARGS); Datum ip4r_contains(PG_FUNCTION_ARGS); Datum ip4r_contains_strict(PG_FUNCTION_ARGS); Datum ip4r_contained_by(PG_FUNCTION_ARGS); Datum ip4r_contained_by_strict(PG_FUNCTION_ARGS); Datum ip4_contains(PG_FUNCTION_ARGS); Datum ip4_contained_by(PG_FUNCTION_ARGS); Datum ip4r_union(PG_FUNCTION_ARGS); Datum ip4r_inter(PG_FUNCTION_ARGS); Datum ip4r_size(PG_FUNCTION_ARGS); Datum ip4r_size_exact(PG_FUNCTION_ARGS); Datum ip4r_prefixlen(PG_FUNCTION_ARGS); Datum ip4r_cmp(PG_FUNCTION_ARGS); Datum ip4_cmp(PG_FUNCTION_ARGS); Datum ip4r_left_of(PG_FUNCTION_ARGS); Datum ip4r_right_of(PG_FUNCTION_ARGS); Datum ip6_in(PG_FUNCTION_ARGS); Datum ip6_out(PG_FUNCTION_ARGS); Datum ip6_recv(PG_FUNCTION_ARGS); Datum ip6_send(PG_FUNCTION_ARGS); Datum ip6hash(PG_FUNCTION_ARGS); Datum ip6_cast_to_text(PG_FUNCTION_ARGS); Datum ip6_cast_from_text(PG_FUNCTION_ARGS); Datum ip6_cast_from_inet(PG_FUNCTION_ARGS); Datum ip6_cast_to_cidr(PG_FUNCTION_ARGS); Datum ip6_cast_to_numeric(PG_FUNCTION_ARGS); Datum ip6_cast_from_numeric(PG_FUNCTION_ARGS); Datum ip6r_in(PG_FUNCTION_ARGS); Datum ip6r_out(PG_FUNCTION_ARGS); Datum ip6r_recv(PG_FUNCTION_ARGS); Datum ip6r_send(PG_FUNCTION_ARGS); Datum ip6rhash(PG_FUNCTION_ARGS); Datum ip6r_cast_to_text(PG_FUNCTION_ARGS); Datum ip6r_cast_from_text(PG_FUNCTION_ARGS); Datum ip6r_cast_from_cidr(PG_FUNCTION_ARGS); Datum ip6r_cast_to_cidr(PG_FUNCTION_ARGS); Datum ip6r_cast_from_ip6(PG_FUNCTION_ARGS); Datum ip6r_from_ip6s(PG_FUNCTION_ARGS); Datum ip6r_net_prefix(PG_FUNCTION_ARGS); Datum ip6r_net_mask(PG_FUNCTION_ARGS); Datum ip6r_lower(PG_FUNCTION_ARGS); Datum ip6r_upper(PG_FUNCTION_ARGS); Datum ip6r_is_cidr(PG_FUNCTION_ARGS); Datum ip6_netmask(PG_FUNCTION_ARGS); Datum ip6_net_lower(PG_FUNCTION_ARGS); Datum ip6_net_upper(PG_FUNCTION_ARGS); Datum ip6_plus_int(PG_FUNCTION_ARGS); Datum ip6_plus_bigint(PG_FUNCTION_ARGS); Datum ip6_plus_numeric(PG_FUNCTION_ARGS); Datum ip6_minus_int(PG_FUNCTION_ARGS); Datum ip6_minus_bigint(PG_FUNCTION_ARGS); Datum ip6_minus_numeric(PG_FUNCTION_ARGS); Datum ip6_minus_ip6(PG_FUNCTION_ARGS); Datum ip6_and(PG_FUNCTION_ARGS); Datum ip6_or(PG_FUNCTION_ARGS); Datum ip6_xor(PG_FUNCTION_ARGS); Datum ip6_not(PG_FUNCTION_ARGS); Datum ip6_lt(PG_FUNCTION_ARGS); Datum ip6_le(PG_FUNCTION_ARGS); Datum ip6_gt(PG_FUNCTION_ARGS); Datum ip6_ge(PG_FUNCTION_ARGS); Datum ip6_eq(PG_FUNCTION_ARGS); Datum ip6_neq(PG_FUNCTION_ARGS); Datum ip6r_lt(PG_FUNCTION_ARGS); Datum ip6r_le(PG_FUNCTION_ARGS); Datum ip6r_gt(PG_FUNCTION_ARGS); Datum ip6r_ge(PG_FUNCTION_ARGS); Datum ip6r_eq(PG_FUNCTION_ARGS); Datum ip6r_neq(PG_FUNCTION_ARGS); Datum ip6r_overlaps(PG_FUNCTION_ARGS); Datum ip6r_contains(PG_FUNCTION_ARGS); Datum ip6r_contains_strict(PG_FUNCTION_ARGS); Datum ip6r_contained_by(PG_FUNCTION_ARGS); Datum ip6r_contained_by_strict(PG_FUNCTION_ARGS); Datum ip6_contains(PG_FUNCTION_ARGS); Datum ip6_contained_by(PG_FUNCTION_ARGS); Datum ip6r_union(PG_FUNCTION_ARGS); Datum ip6r_inter(PG_FUNCTION_ARGS); Datum ip6r_size(PG_FUNCTION_ARGS); Datum ip6r_size_exact(PG_FUNCTION_ARGS); Datum ip6r_prefixlen(PG_FUNCTION_ARGS); Datum ip6r_cmp(PG_FUNCTION_ARGS); Datum ip6_cmp(PG_FUNCTION_ARGS); Datum ip6r_left_of(PG_FUNCTION_ARGS); Datum ip6r_right_of(PG_FUNCTION_ARGS); Datum ipaddr_in(PG_FUNCTION_ARGS); Datum ipaddr_out(PG_FUNCTION_ARGS); Datum ipaddr_recv(PG_FUNCTION_ARGS); Datum ipaddr_send(PG_FUNCTION_ARGS); Datum ipaddr_hash(PG_FUNCTION_ARGS); Datum ipaddr_cast_to_text(PG_FUNCTION_ARGS); Datum ipaddr_cast_from_text(PG_FUNCTION_ARGS); Datum ipaddr_cast_from_inet(PG_FUNCTION_ARGS); Datum ipaddr_cast_to_cidr(PG_FUNCTION_ARGS); Datum ipaddr_cast_to_numeric(PG_FUNCTION_ARGS); Datum ipaddr_cast_from_ip4(PG_FUNCTION_ARGS); Datum ipaddr_cast_from_ip6(PG_FUNCTION_ARGS); Datum ipaddr_cast_to_ip4(PG_FUNCTION_ARGS); Datum ipaddr_cast_to_ip6(PG_FUNCTION_ARGS); Datum ipaddr_net_lower(PG_FUNCTION_ARGS); Datum ipaddr_net_upper(PG_FUNCTION_ARGS); Datum ipaddr_family(PG_FUNCTION_ARGS); Datum ipaddr_plus_int(PG_FUNCTION_ARGS); Datum ipaddr_plus_bigint(PG_FUNCTION_ARGS); Datum ipaddr_plus_numeric(PG_FUNCTION_ARGS); Datum ipaddr_minus_int(PG_FUNCTION_ARGS); Datum ipaddr_minus_bigint(PG_FUNCTION_ARGS); Datum ipaddr_minus_numeric(PG_FUNCTION_ARGS); Datum ipaddr_minus_ipaddr(PG_FUNCTION_ARGS); Datum ipaddr_and(PG_FUNCTION_ARGS); Datum ipaddr_or(PG_FUNCTION_ARGS); Datum ipaddr_xor(PG_FUNCTION_ARGS); Datum ipaddr_not(PG_FUNCTION_ARGS); Datum ipaddr_lt(PG_FUNCTION_ARGS); Datum ipaddr_le(PG_FUNCTION_ARGS); Datum ipaddr_gt(PG_FUNCTION_ARGS); Datum ipaddr_ge(PG_FUNCTION_ARGS); Datum ipaddr_eq(PG_FUNCTION_ARGS); Datum ipaddr_neq(PG_FUNCTION_ARGS); Datum ipaddr_cmp(PG_FUNCTION_ARGS); Datum iprange_in(PG_FUNCTION_ARGS); Datum iprange_out(PG_FUNCTION_ARGS); Datum iprange_recv(PG_FUNCTION_ARGS); Datum iprange_send(PG_FUNCTION_ARGS); Datum iprange_hash(PG_FUNCTION_ARGS); Datum iprange_cast_to_text(PG_FUNCTION_ARGS); Datum iprange_cast_from_text(PG_FUNCTION_ARGS); Datum iprange_cast_from_cidr(PG_FUNCTION_ARGS); Datum iprange_cast_to_cidr(PG_FUNCTION_ARGS); Datum iprange_cast_from_ip4(PG_FUNCTION_ARGS); Datum iprange_cast_from_ip6(PG_FUNCTION_ARGS); Datum iprange_cast_from_ipaddr(PG_FUNCTION_ARGS); Datum iprange_cast_from_ip4r(PG_FUNCTION_ARGS); Datum iprange_cast_from_ip6r(PG_FUNCTION_ARGS); Datum iprange_cast_to_ip4r(PG_FUNCTION_ARGS); Datum iprange_cast_to_ip6r(PG_FUNCTION_ARGS); Datum iprange_from_ip4s(PG_FUNCTION_ARGS); Datum iprange_from_ip6s(PG_FUNCTION_ARGS); Datum iprange_from_ipaddrs(PG_FUNCTION_ARGS); Datum iprange_net_prefix_ip4(PG_FUNCTION_ARGS); Datum iprange_net_prefix_ip6(PG_FUNCTION_ARGS); Datum iprange_net_prefix(PG_FUNCTION_ARGS); Datum iprange_net_mask_ip4(PG_FUNCTION_ARGS); Datum iprange_net_mask_ip6(PG_FUNCTION_ARGS); Datum iprange_net_mask(PG_FUNCTION_ARGS); Datum iprange_lower(PG_FUNCTION_ARGS); Datum iprange_upper(PG_FUNCTION_ARGS); Datum iprange_is_cidr(PG_FUNCTION_ARGS); Datum iprange_family(PG_FUNCTION_ARGS); Datum iprange_lt(PG_FUNCTION_ARGS); Datum iprange_le(PG_FUNCTION_ARGS); Datum iprange_gt(PG_FUNCTION_ARGS); Datum iprange_ge(PG_FUNCTION_ARGS); Datum iprange_eq(PG_FUNCTION_ARGS); Datum iprange_neq(PG_FUNCTION_ARGS); Datum iprange_overlaps(PG_FUNCTION_ARGS); Datum iprange_contains(PG_FUNCTION_ARGS); Datum iprange_contains_strict(PG_FUNCTION_ARGS); Datum iprange_contained_by(PG_FUNCTION_ARGS); Datum iprange_contained_by_strict(PG_FUNCTION_ARGS); Datum iprange_contains_ip(PG_FUNCTION_ARGS); Datum iprange_contains_ip4(PG_FUNCTION_ARGS); Datum iprange_contains_ip6(PG_FUNCTION_ARGS); Datum iprange_ip_contained_by(PG_FUNCTION_ARGS); Datum iprange_ip4_contained_by(PG_FUNCTION_ARGS); Datum iprange_ip6_contained_by(PG_FUNCTION_ARGS); Datum iprange_union(PG_FUNCTION_ARGS); Datum iprange_inter(PG_FUNCTION_ARGS); Datum iprange_size(PG_FUNCTION_ARGS); Datum iprange_size_exact(PG_FUNCTION_ARGS); Datum iprange_prefixlen(PG_FUNCTION_ARGS); Datum iprange_cmp(PG_FUNCTION_ARGS); ip4r-2.0.2/iprange.c000066400000000000000000001501331233620317400141660ustar00rootroot00000000000000/* $Id: iprange.c,v 1.4 2011/11/02 07:47:24 andrewsn Exp $ */ #include "ipr.h" #include "ip4r_funcs.h" #include "ip6r_funcs.h" static void iprange_internal_error(void) __attribute__((noreturn,noinline)); static void iprange_af_mismatch(void) __attribute__((noreturn,noinline)); static void iprange_internal_error(void) { elog(ERROR,"Invalid IPR datum"); /* just to shut the compiler up */ abort(); } static void iprange_af_mismatch(void) { ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("invalid mixing of IP address families"))); /* just to shut the compiler up */ abort(); } /* * Rather than use 32 bytes + length for every IP range, we make the * assumption that most ranges (at least in table data and hence gist * leaf nodes) will be CIDRs, and many of those /64 or shorter. * * So we allow the following formats (excluding varlena header): * * 0 bytes - special 'match all' range (af==0) * 8 bytes - IP4R * 1 byte pfxlen + 8 bytes - IP6R cidr range /64 or shorter * 1 byte pfxlen + 16 bytes - IP6R cidr range /65 or longer * 32 bytes - arbitrary IP6R range */ static int ipr_unpack(IPR_P in, IPR *out) { unsigned char *ptr = (unsigned char *) VARDATA_ANY(in); switch (VARSIZE_ANY_EXHDR(in)) { case 0: return 0; case sizeof(IP4R): memcpy(&out->ip4r, ptr, sizeof(IP4R)); return PGSQL_AF_INET; case 1+sizeof(uint64): { unsigned pfxlen = *ptr++; memcpy(out->ip6r.lower.bits, ptr, sizeof(uint64)); out->ip6r.lower.bits[1] = 0; out->ip6r.upper.bits[0] = out->ip6r.lower.bits[0] | hostmask6_hi(pfxlen); out->ip6r.upper.bits[1] = hostmask6_lo(pfxlen); return PGSQL_AF_INET6; } case 1+sizeof(IP6): { unsigned pfxlen = *ptr++; memcpy(&out->ip6r.lower, ptr, sizeof(IP6)); out->ip6r.upper.bits[0] = out->ip6r.lower.bits[0] | hostmask6_hi(pfxlen); out->ip6r.upper.bits[1] = out->ip6r.lower.bits[1] | hostmask6_lo(pfxlen); return PGSQL_AF_INET6; } case sizeof(IP6R): memcpy(&out->ip6r, ptr, sizeof(IP6R)); return PGSQL_AF_INET6; default: iprange_internal_error(); } } static IPR_P ipr_pack(int af, IPR *val) { IPR_P out = palloc(VARHDRSZ + sizeof(IP6R)); unsigned char *ptr = (unsigned char *) VARDATA(out); switch (af) { case 0: SET_VARSIZE(out, VARHDRSZ); break; case PGSQL_AF_INET: memcpy(ptr, &val->ip4r, sizeof(IP4R)); SET_VARSIZE(out, VARHDRSZ + sizeof(IP4R)); break; case PGSQL_AF_INET6: { unsigned pfxlen = masklen6(&val->ip6r.lower, &val->ip6r.upper); if (pfxlen <= 64) { *ptr++ = pfxlen; memcpy(ptr, val->ip6r.lower.bits, sizeof(uint64)); SET_VARSIZE(out, VARHDRSZ + 1 + sizeof(uint64)); } else if (pfxlen <= 128) { *ptr++ = pfxlen; memcpy(ptr, &val->ip6r.lower, sizeof(IP6)); SET_VARSIZE(out, VARHDRSZ + 1 + sizeof(IP6)); } else { memcpy(ptr, &val->ip6r, sizeof(IP6R)); SET_VARSIZE(out, VARHDRSZ + sizeof(IP6R)); } break; } default: iprange_internal_error(); } return out; } /**************************************************************************/ /* This part handles all aspects of postgres interfacing. */ /* end of version dependencies */ /* #define GIST_DEBUG #define GIST_QUERY_DEBUG */ static text * make_text(char *str, int len) { text *ret = (text *) palloc(len + VARHDRSZ); SET_VARSIZE(ret, len + VARHDRSZ); if (str) memcpy(VARDATA(ret), str, len); else memset(VARDATA(ret), 0, len); return ret; } static inline void set_text_len(text *txt, int len) { if ((len + VARHDRSZ) < VARSIZE(txt)) SET_VARSIZE(txt, len + VARHDRSZ); } static inline int get_text_len(text *txt) { return VARSIZE(txt) - VARHDRSZ; } /* ** Input/Output routines */ /*---- ipr ----*/ PG_FUNCTION_INFO_V1(iprange_in); Datum iprange_in(PG_FUNCTION_ARGS) { char *str = PG_GETARG_CSTRING(0); IPR ipr; if (str[0] == '-' && str[1] == 0) { PG_RETURN_IPR_P(ipr_pack(0, NULL)); } else if (strchr(str,':')) { ipr.ip6r = *DatumGetIP6RP(DirectFunctionCall1(ip6r_in,CStringGetDatum(str))); PG_RETURN_IPR_P(ipr_pack(PGSQL_AF_INET6, &ipr)); } else { ipr.ip4r = *DatumGetIP4RP(DirectFunctionCall1(ip4r_in,CStringGetDatum(str))); PG_RETURN_IPR_P(ipr_pack(PGSQL_AF_INET, &ipr)); } } PG_FUNCTION_INFO_V1(iprange_out); Datum iprange_out(PG_FUNCTION_ARGS) { IPR_P *iprp = PG_GETARG_IPR_P(0); IPR ipr; int af = ipr_unpack(iprp, &ipr); switch (af) { case 0: { char *out = palloc(2); strcpy(out,"-"); PG_RETURN_CSTRING(out); } case PGSQL_AF_INET: PG_RETURN_DATUM(DirectFunctionCall1(ip4r_out,IP4RPGetDatum(&ipr.ip4r))); case PGSQL_AF_INET6: PG_RETURN_DATUM(DirectFunctionCall1(ip6r_out,IP6RPGetDatum(&ipr.ip6r))); default: iprange_internal_error(); } } PG_FUNCTION_INFO_V1(iprange_recv); Datum iprange_recv(PG_FUNCTION_ARGS) { StringInfo buf = (StringInfo) PG_GETARG_POINTER(0); IPR ipr; unsigned af, bits, flag, nbytes; /* * This isn't quite the same format as inet/cidr but we keep reasonably * close for no very good reason. * * 1 byte AF * 1 byte pfx len (255 if the range is not a prefix) * 1 byte flag (unused) * 1 byte number of remaining bytes (0,4,8,16 or 32) * */ af = pq_getmsgbyte(buf); if (af != 0 && af != PGSQL_AF_INET && af != PGSQL_AF_INET6) ereport(ERROR, (errcode(ERRCODE_INVALID_BINARY_REPRESENTATION), errmsg("invalid address family in external IPR value"))); bits = pq_getmsgbyte(buf); if (bits != 255 && bits > ipr_af_maxbits(af)) ereport(ERROR, (errcode(ERRCODE_INVALID_BINARY_REPRESENTATION), errmsg("invalid bit length in external IP value"))); flag = pq_getmsgbyte(buf); /* ignored */ nbytes = pq_getmsgbyte(buf); switch (af) { case 0: /* special 'match all' range */ if (nbytes == 0) PG_RETURN_IPR_P(ipr_pack(0,NULL)); break; case PGSQL_AF_INET: if (nbytes == sizeof(IP4) && bits <= ipr_af_maxbits(PGSQL_AF_INET)) { ipr.ip4r.lower = (IP4) pq_getmsgint(buf, sizeof(IP4)); ipr.ip4r.upper = ipr.ip4r.lower | hostmask(bits); PG_RETURN_IPR_P(ipr_pack(PGSQL_AF_INET,&ipr)); } else if (nbytes == sizeof(IP4R)) { ipr.ip4r.lower = (IP4) pq_getmsgint(buf, sizeof(IP4)); ipr.ip4r.upper = (IP4) pq_getmsgint(buf, sizeof(IP4)); PG_RETURN_IPR_P(ipr_pack(PGSQL_AF_INET,&ipr)); } break; case PGSQL_AF_INET6: if (nbytes == sizeof(uint64) && bits <= 64) { ipr.ip6r.lower.bits[0] = (uint64) pq_getmsgint64(buf); ipr.ip6r.lower.bits[1] = 0; ipr.ip6r.upper.bits[0] = ipr.ip6r.lower.bits[0] | hostmask6_hi(bits); ipr.ip6r.upper.bits[1] = ~(uint64)0; PG_RETURN_IPR_P(ipr_pack(PGSQL_AF_INET6,&ipr)); } else if (nbytes == sizeof(IP6) && bits <= ipr_af_maxbits(PGSQL_AF_INET6)) { ipr.ip6r.lower.bits[0] = (uint64) pq_getmsgint64(buf); ipr.ip6r.lower.bits[1] = (uint64) pq_getmsgint64(buf); ipr.ip6r.upper.bits[0] = ipr.ip6r.lower.bits[0] | hostmask6_hi(bits); ipr.ip6r.upper.bits[1] = ipr.ip6r.lower.bits[1] | hostmask6_lo(bits); PG_RETURN_IPR_P(ipr_pack(PGSQL_AF_INET6,&ipr)); } else if (nbytes == sizeof(IP4R)) { ipr.ip6r.lower.bits[0] = (uint64) pq_getmsgint64(buf); ipr.ip6r.lower.bits[1] = (uint64) pq_getmsgint64(buf); ipr.ip6r.upper.bits[0] = (uint64) pq_getmsgint64(buf); ipr.ip6r.upper.bits[1] = (uint64) pq_getmsgint64(buf); PG_RETURN_IPR_P(ipr_pack(PGSQL_AF_INET6,&ipr)); } break; } ereport(ERROR, (errcode(ERRCODE_INVALID_BINARY_REPRESENTATION), errmsg("invalid address length in external IPR value"))); PG_RETURN_NULL(); } PG_FUNCTION_INFO_V1(iprange_send); Datum iprange_send(PG_FUNCTION_ARGS) { IPR_P *iprp = PG_GETARG_IPR_P(0); IPR ipr; int af = ipr_unpack(iprp, &ipr); StringInfoData buf; unsigned bits = ~0; switch (af) { case PGSQL_AF_INET: bits = masklen(ipr.ip4r.lower,ipr.ip4r.upper); break; case PGSQL_AF_INET6: bits = masklen6(&ipr.ip6r.lower,&ipr.ip6r.upper); break; } pq_begintypsend(&buf); pq_sendbyte(&buf, af); pq_sendbyte(&buf, ipr_af_maxbits(af)); pq_sendbyte(&buf, 1); switch (af) { case 0: pq_sendbyte(&buf,0); break; case PGSQL_AF_INET: if (bits <= ipr_af_maxbits(PGSQL_AF_INET)) { pq_sendbyte(&buf, sizeof(IP4)); pq_sendint(&buf, ipr.ip4r.lower, sizeof(IP4)); } else { pq_sendbyte(&buf, sizeof(IP4R)); pq_sendint(&buf, ipr.ip4r.lower, sizeof(IP4)); pq_sendint(&buf, ipr.ip4r.upper, sizeof(IP4)); } break; case PGSQL_AF_INET6: if (bits <= 64) { pq_sendbyte(&buf, sizeof(uint64)); pq_sendint64(&buf, ipr.ip6r.lower.bits[0]); } else if (bits <= ipr_af_maxbits(PGSQL_AF_INET6)) { pq_sendbyte(&buf, sizeof(IP6)); pq_sendint64(&buf, ipr.ip6r.lower.bits[0]); pq_sendint64(&buf, ipr.ip6r.lower.bits[1]); } else { pq_sendbyte(&buf, sizeof(IP6R)); pq_sendint64(&buf, ipr.ip6r.lower.bits[0]); pq_sendint64(&buf, ipr.ip6r.lower.bits[1]); pq_sendint64(&buf, ipr.ip6r.upper.bits[0]); pq_sendint64(&buf, ipr.ip6r.upper.bits[1]); } break; } PG_RETURN_BYTEA_P(pq_endtypsend(&buf)); } PG_FUNCTION_INFO_V1(iprange_hash); Datum iprange_hash(PG_FUNCTION_ARGS) { IPR_P arg1 = PG_GETARG_IPR_P(0); return hash_any((void *) VARDATA_ANY(arg1), VARSIZE_ANY_EXHDR(arg1)); } PG_FUNCTION_INFO_V1(iprange_cast_to_text); Datum iprange_cast_to_text(PG_FUNCTION_ARGS) { IPR_P iprp = PG_GETARG_IPR_P(0); IPR ipr; int af = ipr_unpack(iprp,&ipr); switch (af) { case 0: { text *out = make_text("-",1); PG_RETURN_TEXT_P(out); } case PGSQL_AF_INET: PG_RETURN_DATUM(DirectFunctionCall1(ip4r_cast_to_text,IP4RPGetDatum(&ipr.ip4r))); case PGSQL_AF_INET6: PG_RETURN_DATUM(DirectFunctionCall1(ip6r_cast_to_text,IP6RPGetDatum(&ipr.ip6r))); default: iprange_internal_error(); } } PG_FUNCTION_INFO_V1(iprange_cast_from_text); Datum iprange_cast_from_text(PG_FUNCTION_ARGS) { text *txt = PG_GETARG_TEXT_PP(0); int tlen = VARSIZE_ANY_EXHDR(txt); char buf[IP6R_STRING_MAX]; if (tlen < sizeof(buf)) { memcpy(buf, VARDATA_ANY(txt), tlen); buf[tlen] = 0; PG_RETURN_DATUM(DirectFunctionCall1(iprange_in, CStringGetDatum(buf))); } ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("invalid IPR value in text"))); PG_RETURN_NULL(); } PG_FUNCTION_INFO_V1(iprange_cast_from_cidr); Datum iprange_cast_from_cidr(PG_FUNCTION_ARGS) { inet *inetptr = PG_GETARG_INET_P(0); inet_struct *in = INET_STRUCT_DATA(inetptr); unsigned char *p = in->ipaddr; IPR ipr; if (INET_IS_CIDR(in) && in->bits <= ipr_af_maxbits(in->family)) { switch (in->family) { case PGSQL_AF_INET: { IP4 ip = (p[0] << 24)|(p[1] << 16)|(p[2] << 8)|p[3]; if (ip4r_from_cidr(ip, in->bits, &ipr.ip4r)) PG_RETURN_IPR_P(ipr_pack(PGSQL_AF_INET,&ipr)); } break; case PGSQL_AF_INET6: { IP6 ip; ip.bits[0] = (((uint64)p[0] << 56) | ((uint64)p[1] << 48) | ((uint64)p[2] << 40) | ((uint64)p[3] << 32) | ((uint64)p[4] << 24) | ((uint64)p[5] << 16) | ((uint64)p[6] << 8) | p[7]); ip.bits[1] = (((uint64)p[8] << 56) | ((uint64)p[9] << 48) | ((uint64)p[10] << 40) | ((uint64)p[11] << 32) | ((uint64)p[12] << 24) | ((uint64)p[13] << 16) | ((uint64)p[14] << 8) | p[15]); if (ip6r_from_cidr(&ip, in->bits, &ipr.ip6r)) PG_RETURN_IPR_P(ipr_pack(PGSQL_AF_INET6,&ipr)); } break; } } ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("invalid CIDR value for conversion to IPR"))); PG_RETURN_NULL(); } PG_FUNCTION_INFO_V1(iprange_cast_to_cidr); Datum iprange_cast_to_cidr(PG_FUNCTION_ARGS) { IPR_P iprp = PG_GETARG_IPR_P(0); IPR ipr; int af = ipr_unpack(iprp, &ipr); inet *res; inet_struct *in; unsigned bits; switch (af) { case 0: PG_RETURN_NULL(); case PGSQL_AF_INET: bits = masklen(ipr.ip4r.lower, ipr.ip4r.upper); if (bits > ipr_af_maxbits(PGSQL_AF_INET)) PG_RETURN_NULL(); res = palloc0(VARHDRSZ + sizeof(inet_struct)); SET_VARSIZE(res, VARHDRSZ + offsetof(inet_struct, ipaddr) + 4); in = ((inet_struct *)VARDATA(res)); INET_INIT_CIDR(in); in->bits = bits; in->family = PGSQL_AF_INET; { unsigned char *p = in->ipaddr; IP4 ip = ipr.ip4r.lower; p[0] = (ip >> 24); p[1] = (ip >> 16); p[2] = (ip >> 8); p[3] = (ip ); } PG_RETURN_INET_P(res); case PGSQL_AF_INET6: bits = masklen6(&ipr.ip6r.lower, &ipr.ip6r.upper); if (bits > ipr_af_maxbits(PGSQL_AF_INET6)) PG_RETURN_NULL(); res = palloc0(VARHDRSZ + sizeof(inet_struct)); SET_VARSIZE(res, VARHDRSZ + offsetof(inet_struct, ipaddr) + 16); in = ((inet_struct *)VARDATA(res)); INET_INIT_CIDR(in); in->bits = bits; in->family = PGSQL_AF_INET6; { unsigned char *p = in->ipaddr; uint64 b = ipr.ip6r.lower.bits[0]; p[0] = (b >> 56); p[1] = (b >> 48); p[2] = (b >> 40); p[3] = (b >> 32); p[4] = (b >> 24); p[5] = (b >> 16); p[6] = (b >> 8); p[7] = (b); b = ipr.ip6r.lower.bits[1]; p[8] = (b >> 56); p[9] = (b >> 48); p[10] = (b >> 40); p[11] = (b >> 32); p[12] = (b >> 24); p[13] = (b >> 16); p[14] = (b >> 8); p[15] = (b); } PG_RETURN_INET_P(res); default: iprange_internal_error(); } } PG_FUNCTION_INFO_V1(iprange_cast_from_ip4); Datum iprange_cast_from_ip4(PG_FUNCTION_ARGS) { IP4 ip = PG_GETARG_IP4(0); IPR res; if (ip4r_from_inet(ip, 32, &res.ip4r)) PG_RETURN_IPR_P(ipr_pack(PGSQL_AF_INET, &res)); ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("invalid IP4 value for conversion to IPR (shouldn't be possible)"))); PG_RETURN_NULL(); } PG_FUNCTION_INFO_V1(iprange_cast_from_ip6); Datum iprange_cast_from_ip6(PG_FUNCTION_ARGS) { IP6 *ip = PG_GETARG_IP6_P(0); IPR res; if (ip6r_from_inet(ip, 128, &res.ip6r)) PG_RETURN_IPR_P(ipr_pack(PGSQL_AF_INET6, &res)); ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("invalid IP6 value for conversion to IPR (shouldn't be possible)"))); PG_RETURN_NULL(); } PG_FUNCTION_INFO_V1(iprange_cast_from_ipaddr); Datum iprange_cast_from_ipaddr(PG_FUNCTION_ARGS) { IP_P ipp = PG_GETARG_IP_P(0); IP ip; IPR res; int af = ip_unpack(ipp, &ip); switch (af) { case PGSQL_AF_INET: if (ip4r_from_inet(ip.ip4, 32, &res.ip4r)) PG_RETURN_IPR_P(ipr_pack(PGSQL_AF_INET, &res)); break; case PGSQL_AF_INET6: if (ip6r_from_inet(&ip.ip6, 128, &res.ip6r)) PG_RETURN_IPR_P(ipr_pack(PGSQL_AF_INET6, &res)); break; } ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("invalid IP6 value for conversion to IPR (shouldn't be possible)"))); PG_RETURN_NULL(); } PG_FUNCTION_INFO_V1(iprange_cast_from_ip4r); Datum iprange_cast_from_ip4r(PG_FUNCTION_ARGS) { IP4R *ipr = PG_GETARG_IP4R_P(0); IPR res; res.ip4r = *ipr; PG_RETURN_IPR_P(ipr_pack(PGSQL_AF_INET, &res)); } PG_FUNCTION_INFO_V1(iprange_cast_from_ip6r); Datum iprange_cast_from_ip6r(PG_FUNCTION_ARGS) { IP6R *ipr = PG_GETARG_IP6R_P(0); IPR res; res.ip6r = *ipr; PG_RETURN_IPR_P(ipr_pack(PGSQL_AF_INET6, &res)); } PG_FUNCTION_INFO_V1(iprange_cast_to_ip4r); Datum iprange_cast_to_ip4r(PG_FUNCTION_ARGS) { IPR_P iprp = PG_GETARG_IPR_P(0); IPR ipr; int af = ipr_unpack(iprp,&ipr); IP4R *res; if (af != PGSQL_AF_INET) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("invalid IPR value for conversion to IP4R"))); res = palloc(sizeof(IP4R)); *res = ipr.ip4r; PG_RETURN_IP4R_P(res); } PG_FUNCTION_INFO_V1(iprange_cast_to_ip6r); Datum iprange_cast_to_ip6r(PG_FUNCTION_ARGS) { IPR_P iprp = PG_GETARG_IPR_P(0); IPR ipr; int af = ipr_unpack(iprp,&ipr); IP6R *res; if (af != PGSQL_AF_INET6) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("invalid IPR value for conversion to IP6R"))); res = palloc(sizeof(IP6R)); *res = ipr.ip6r; PG_RETURN_IP6R_P(res); } static Datum iprange_from_ipaddrs_internal(int af, IP4 a4, IP4 b4, IP6 *a6, IP6 *b6) { IPR res; switch (af) { case PGSQL_AF_INET: if (ip4_lessthan(a4,b4)) res.ip4r.lower = a4, res.ip4r.upper = b4; else res.ip4r.lower = b4, res.ip4r.upper = a4; PG_RETURN_IPR_P(ipr_pack(PGSQL_AF_INET,&res)); case PGSQL_AF_INET6: if (ip6_lessthan(a6,b6)) res.ip6r.lower = *a6, res.ip6r.upper = *b6; else res.ip6r.lower = *b6, res.ip6r.upper = *a6; PG_RETURN_IPR_P(ipr_pack(PGSQL_AF_INET6,&res)); default: iprange_internal_error(); } } PG_FUNCTION_INFO_V1(iprange_from_ip4s); Datum iprange_from_ip4s(PG_FUNCTION_ARGS) { IP4 a = PG_GETARG_IP4(0); IP4 b = PG_GETARG_IP4(1); PG_RETURN_DATUM(iprange_from_ipaddrs_internal(PGSQL_AF_INET, a, b, NULL, NULL)); } PG_FUNCTION_INFO_V1(iprange_from_ip6s); Datum iprange_from_ip6s(PG_FUNCTION_ARGS) { IP6 *a = PG_GETARG_IP6_P(0); IP6 *b = PG_GETARG_IP6_P(1); PG_RETURN_DATUM(iprange_from_ipaddrs_internal(PGSQL_AF_INET6, 0, 0, a, b)); } PG_FUNCTION_INFO_V1(iprange_from_ipaddrs); Datum iprange_from_ipaddrs(PG_FUNCTION_ARGS) { IP_P ap = PG_GETARG_IP_P(0); IP_P bp = PG_GETARG_IP_P(1); IP a,b; int af_a = ip_unpack(ap,&a); int af_b = ip_unpack(bp,&b); if (af_a != af_b) iprange_af_mismatch(); PG_RETURN_DATUM(iprange_from_ipaddrs_internal(af_a, a.ip4, b.ip4, &a.ip6, &b.ip6)); } static Datum iprange_net_prefix_internal(int af, IP4 ip4, IP6 *ip6, int pfxlen) { IPR res; if (pfxlen < 0 || pfxlen > ipr_af_maxbits(af)) { ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("prefix length out of range"))); } switch (af) { case PGSQL_AF_INET: ip4r_from_inet(ip4, (unsigned)pfxlen, &res.ip4r); break; case PGSQL_AF_INET6: ip6r_from_inet(ip6, (unsigned)pfxlen, &res.ip6r); break; default: iprange_internal_error(); } PG_RETURN_IPR_P(ipr_pack(af,&res)); } PG_FUNCTION_INFO_V1(iprange_net_prefix_ip4); Datum iprange_net_prefix_ip4(PG_FUNCTION_ARGS) { IP4 ip = PG_GETARG_IP4(0); int pfxlen = PG_GETARG_INT32(1); PG_RETURN_DATUM(iprange_net_prefix_internal(PGSQL_AF_INET, ip, NULL, pfxlen)); } PG_FUNCTION_INFO_V1(iprange_net_prefix_ip6); Datum iprange_net_prefix_ip6(PG_FUNCTION_ARGS) { IP6 *ip = PG_GETARG_IP6_P(0); int pfxlen = PG_GETARG_INT32(1); PG_RETURN_DATUM(iprange_net_prefix_internal(PGSQL_AF_INET6, 0, ip, pfxlen)); } PG_FUNCTION_INFO_V1(iprange_net_prefix); Datum iprange_net_prefix(PG_FUNCTION_ARGS) { IP_P ipp = PG_GETARG_IP_P(0); IP ip; int pfxlen = PG_GETARG_INT32(1); int af = ip_unpack(ipp,&ip); PG_RETURN_DATUM(iprange_net_prefix_internal(af, ip.ip4, &ip.ip6, pfxlen)); } static Datum iprange_net_mask_internal(int af, IP4 ip4, IP6 *ip6, IP4 mask4, IP6 *mask6) { IPR res; switch (af) { case PGSQL_AF_INET: if (!ip4_valid_netmask(mask4)) break; res.ip4r.lower = ip4 & mask4; res.ip4r.upper = ip4 | ~mask4; PG_RETURN_IPR_P(ipr_pack(PGSQL_AF_INET,&res)); case PGSQL_AF_INET6: if (!ip6_valid_netmask(mask6->bits[0], mask6->bits[1])) break; res.ip6r.lower.bits[0] = ip6->bits[0] & mask6->bits[0]; res.ip6r.lower.bits[1] = ip6->bits[1] & mask6->bits[1]; res.ip6r.upper.bits[0] = ip6->bits[0] | ~(mask6->bits[0]); res.ip6r.upper.bits[1] = ip6->bits[1] | ~(mask6->bits[1]); PG_RETURN_IPR_P(ipr_pack(PGSQL_AF_INET6,&res)); } ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("invalid netmask"))); PG_RETURN_VOID(); } PG_FUNCTION_INFO_V1(iprange_net_mask_ip4); Datum iprange_net_mask_ip4(PG_FUNCTION_ARGS) { IP4 ip = PG_GETARG_IP4(0); IP4 mask = PG_GETARG_IP4(1); PG_RETURN_DATUM(iprange_net_mask_internal(PGSQL_AF_INET, ip, NULL, mask, NULL)); } PG_FUNCTION_INFO_V1(iprange_net_mask_ip6); Datum iprange_net_mask_ip6(PG_FUNCTION_ARGS) { IP6 *ip = PG_GETARG_IP6_P(0); IP6 *mask = PG_GETARG_IP6_P(1); PG_RETURN_DATUM(iprange_net_mask_internal(PGSQL_AF_INET6, 0, ip, 0, mask)); } PG_FUNCTION_INFO_V1(iprange_net_mask); Datum iprange_net_mask(PG_FUNCTION_ARGS) { IP_P ipp = PG_GETARG_IP_P(0); IP_P maskp = PG_GETARG_IP_P(1); IP ip; IP mask; int af1 = ip_unpack(ipp,&ip); int af2 = ip_unpack(maskp,&mask); if (af1 != af2) iprange_af_mismatch(); PG_RETURN_DATUM(iprange_net_mask_internal(af1, ip.ip4, &ip.ip6, mask.ip4, &mask.ip6)); } PG_FUNCTION_INFO_V1(iprange_lower); Datum iprange_lower(PG_FUNCTION_ARGS) { IPR_P iprp = PG_GETARG_IPR_P(0); IPR ipr; IP ip; int af = ipr_unpack(iprp,&ipr); switch (af) { case 0: ip.ip4 = 0; PG_RETURN_IP_P(ip_pack(PGSQL_AF_INET,&ip)); case PGSQL_AF_INET: ip.ip4 = ipr.ip4r.lower; PG_RETURN_IP_P(ip_pack(PGSQL_AF_INET,&ip)); case PGSQL_AF_INET6: ip.ip6 = ipr.ip6r.lower; PG_RETURN_IP_P(ip_pack(PGSQL_AF_INET6,&ip)); default: iprange_internal_error(); } } PG_FUNCTION_INFO_V1(iprange_upper); Datum iprange_upper(PG_FUNCTION_ARGS) { IPR_P iprp = PG_GETARG_IPR_P(0); IPR ipr; IP ip; int af = ipr_unpack(iprp,&ipr); switch (af) { case 0: ip.ip6.bits[0] = ip.ip6.bits[1] = ~(uint64)0; PG_RETURN_IP_P(ip_pack(PGSQL_AF_INET6,&ip)); case PGSQL_AF_INET: ip.ip4 = ipr.ip4r.upper; PG_RETURN_IP_P(ip_pack(PGSQL_AF_INET,&ip)); case PGSQL_AF_INET6: ip.ip6 = ipr.ip6r.upper; PG_RETURN_IP_P(ip_pack(PGSQL_AF_INET6,&ip)); default: iprange_internal_error(); } } PG_FUNCTION_INFO_V1(iprange_is_cidr); Datum iprange_is_cidr(PG_FUNCTION_ARGS) { IPR_P iprp = PG_GETARG_IPR_P(0); IPR ipr; int af = ipr_unpack(iprp,&ipr); switch (af) { case 0: PG_RETURN_BOOL(false); case PGSQL_AF_INET: PG_RETURN_BOOL( (masklen(ipr.ip4r.lower,ipr.ip4r.upper) <= 32U) ); case PGSQL_AF_INET6: PG_RETURN_BOOL( (masklen6(&ipr.ip6r.lower,&ipr.ip6r.upper) <= 128U) ); default: iprange_internal_error(); } } PG_FUNCTION_INFO_V1(iprange_family); Datum iprange_family(PG_FUNCTION_ARGS) { IPR_P iprp = PG_GETARG_IPR_P(0); IPR ipr; int af = ipr_unpack(iprp,&ipr); switch (af) { case 0: PG_RETURN_NULL(); case PGSQL_AF_INET: PG_RETURN_INT32(4); case PGSQL_AF_INET6: PG_RETURN_INT32(6); default: iprange_internal_error(); } } static int iprange_cmp_internal(Datum d1, Datum d2) { IPR_P ipp1 = DatumGetIPR_P(d1); IPR_P ipp2 = DatumGetIPR_P(d2); IPR ipr1; IPR ipr2; int af1 = ipr_unpack(ipp1, &ipr1); int af2 = ipr_unpack(ipp2, &ipr2); int retval = 0; if (af1 == af2) { switch (af1) { case 0: break; case PGSQL_AF_INET: if (ip4r_lessthan(&ipr1.ip4r,&ipr2.ip4r)) retval = -1; else if (ip4r_lessthan(&ipr2.ip4r,&ipr1.ip4r)) retval = 1; break; case PGSQL_AF_INET6: if (ip6r_lessthan(&ipr1.ip6r,&ipr2.ip6r)) retval = -1; if (ip6r_lessthan(&ipr2.ip6r,&ipr1.ip6r)) retval = 1; break; default: iprange_internal_error(); } } else if (af1 < af2) retval = -1; else retval = 1; if ((Pointer)ipp1 != DatumGetPointer(d1)) pfree(ipp1); if ((Pointer)ipp2 != DatumGetPointer(d2)) pfree(ipp2); return retval; } PG_FUNCTION_INFO_V1(iprange_lt); Datum iprange_lt(PG_FUNCTION_ARGS) { PG_RETURN_BOOL( iprange_cmp_internal(PG_GETARG_DATUM(0), PG_GETARG_DATUM(1)) < 0 ); } PG_FUNCTION_INFO_V1(iprange_le); Datum iprange_le(PG_FUNCTION_ARGS) { PG_RETURN_BOOL( iprange_cmp_internal(PG_GETARG_DATUM(0), PG_GETARG_DATUM(1)) <= 0 ); } PG_FUNCTION_INFO_V1(iprange_gt); Datum iprange_gt(PG_FUNCTION_ARGS) { PG_RETURN_BOOL( iprange_cmp_internal(PG_GETARG_DATUM(0), PG_GETARG_DATUM(1)) > 0 ); } PG_FUNCTION_INFO_V1(iprange_ge); Datum iprange_ge(PG_FUNCTION_ARGS) { PG_RETURN_BOOL( iprange_cmp_internal(PG_GETARG_DATUM(0), PG_GETARG_DATUM(1)) >= 0 ); } PG_FUNCTION_INFO_V1(iprange_eq); Datum iprange_eq(PG_FUNCTION_ARGS) { PG_RETURN_BOOL( iprange_cmp_internal(PG_GETARG_DATUM(0), PG_GETARG_DATUM(1)) == 0 ); } PG_FUNCTION_INFO_V1(iprange_neq); Datum iprange_neq(PG_FUNCTION_ARGS) { PG_RETURN_BOOL( iprange_cmp_internal(PG_GETARG_DATUM(0), PG_GETARG_DATUM(1)) != 0 ); } static bool iprange_overlaps_internal(Datum d1, Datum d2) { IPR_P ipp1 = DatumGetIPR_P(d1); IPR_P ipp2 = DatumGetIPR_P(d2); IPR ipr1; IPR ipr2; int af1 = ipr_unpack(ipp1, &ipr1); int af2 = ipr_unpack(ipp2, &ipr2); bool retval; if (af1 == af2) { switch (af1) { case 0: retval = true; break; case PGSQL_AF_INET: retval = ip4r_overlaps_internal(&ipr1.ip4r,&ipr2.ip4r); break; case PGSQL_AF_INET6: retval = ip6r_overlaps_internal(&ipr1.ip6r,&ipr2.ip6r); break; default: iprange_internal_error(); } } else if (af1 != af2) retval = (af1 == 0) || (af2 == 0); if ((Pointer)ipp1 != DatumGetPointer(d1)) pfree(ipp1); if ((Pointer)ipp2 != DatumGetPointer(d2)) pfree(ipp2); return retval; } static int iprange_contains_internal(Datum d1, Datum d2, bool eqval) { IPR_P ipp1 = DatumGetIPR_P(d1); IPR_P ipp2 = DatumGetIPR_P(d2); IPR ipr1; IPR ipr2; int af1 = ipr_unpack(ipp1, &ipr1); int af2 = ipr_unpack(ipp2, &ipr2); bool retval; if (af1 == af2) { switch (af1) { case 0: retval = eqval; break; case PGSQL_AF_INET: retval = ip4r_contains_internal(&ipr1.ip4r,&ipr2.ip4r,eqval); break; case PGSQL_AF_INET6: retval = ip6r_contains_internal(&ipr1.ip6r,&ipr2.ip6r,eqval); break; default: iprange_internal_error(); } } else if (af1 != af2) retval = (af1 == 0); if ((Pointer)ipp1 != DatumGetPointer(d1)) pfree(ipp1); if ((Pointer)ipp2 != DatumGetPointer(d2)) pfree(ipp2); return retval; } static int iprange_contains_ip_internal(Datum d1, int af2, IP4 ip4, IP6 *ip6) { IPR_P ipp1 = DatumGetIPR_P(d1); IPR ipr1; int af1 = ipr_unpack(ipp1, &ipr1); bool retval; if (af1 == af2) { switch (af1) { case 0: retval = true; break; case PGSQL_AF_INET: retval = ip4_contains_internal(&ipr1.ip4r,ip4); break; case PGSQL_AF_INET6: retval = ip6_contains_internal(&ipr1.ip6r,ip6); break; default: iprange_internal_error(); } } else if (af1 != af2) retval = (af1 == 0); if ((Pointer)ipp1 != DatumGetPointer(d1)) pfree(ipp1); return retval; } PG_FUNCTION_INFO_V1(iprange_overlaps); Datum iprange_overlaps(PG_FUNCTION_ARGS) { PG_RETURN_BOOL( iprange_overlaps_internal(PG_GETARG_DATUM(0), PG_GETARG_DATUM(1)) ); } PG_FUNCTION_INFO_V1(iprange_contains); Datum iprange_contains(PG_FUNCTION_ARGS) { PG_RETURN_BOOL( iprange_contains_internal(PG_GETARG_DATUM(0), PG_GETARG_DATUM(1), TRUE) ); } PG_FUNCTION_INFO_V1(iprange_contains_strict); Datum iprange_contains_strict(PG_FUNCTION_ARGS) { PG_RETURN_BOOL( iprange_contains_internal(PG_GETARG_DATUM(0), PG_GETARG_DATUM(1), FALSE) ); } PG_FUNCTION_INFO_V1(iprange_contained_by); Datum iprange_contained_by(PG_FUNCTION_ARGS) { PG_RETURN_BOOL( iprange_contains_internal(PG_GETARG_DATUM(1), PG_GETARG_DATUM(0), TRUE) ); } PG_FUNCTION_INFO_V1(iprange_contained_by_strict); Datum iprange_contained_by_strict(PG_FUNCTION_ARGS) { PG_RETURN_BOOL( iprange_contains_internal(PG_GETARG_DATUM(1), PG_GETARG_DATUM(0), FALSE) ); } PG_FUNCTION_INFO_V1(iprange_contains_ip); Datum iprange_contains_ip(PG_FUNCTION_ARGS) { IP_P ipp = PG_GETARG_IP_P(1); IP ip; int af = ip_unpack(ipp,&ip); bool retval = iprange_contains_ip_internal(PG_GETARG_DATUM(0), af, ip.ip4, &ip.ip6); PG_FREE_IF_COPY(ipp,1); PG_RETURN_BOOL(retval); } PG_FUNCTION_INFO_V1(iprange_contains_ip4); Datum iprange_contains_ip4(PG_FUNCTION_ARGS) { IP4 ip = PG_GETARG_IP4(1); PG_RETURN_BOOL(iprange_contains_ip_internal(PG_GETARG_DATUM(0), PGSQL_AF_INET, ip, NULL)); } PG_FUNCTION_INFO_V1(iprange_contains_ip6); Datum iprange_contains_ip6(PG_FUNCTION_ARGS) { IP6 *ip = PG_GETARG_IP6_P(1); PG_RETURN_BOOL(iprange_contains_ip_internal(PG_GETARG_DATUM(0), PGSQL_AF_INET6, 0, ip)); } PG_FUNCTION_INFO_V1(iprange_ip6_contained_by); Datum iprange_ip6_contained_by(PG_FUNCTION_ARGS) { IP6 *ip = PG_GETARG_IP6_P(0); PG_RETURN_BOOL( iprange_contains_ip_internal(PG_GETARG_DATUM(1), PGSQL_AF_INET6, 0, ip) ); } PG_FUNCTION_INFO_V1(iprange_ip4_contained_by); Datum iprange_ip4_contained_by(PG_FUNCTION_ARGS) { IP4 ip = PG_GETARG_IP4(0); PG_RETURN_BOOL( iprange_contains_ip_internal(PG_GETARG_DATUM(1), PGSQL_AF_INET, ip, NULL) ); } PG_FUNCTION_INFO_V1(iprange_ip_contained_by); Datum iprange_ip_contained_by(PG_FUNCTION_ARGS) { IP_P ipp = PG_GETARG_IP_P(0); IP ip; int af = ip_unpack(ipp,&ip); bool retval = iprange_contains_ip_internal(PG_GETARG_DATUM(1), af, ip.ip4, &ip.ip6); PG_FREE_IF_COPY(ipp,0); PG_RETURN_BOOL(retval); } PG_FUNCTION_INFO_V1(iprange_union); Datum iprange_union(PG_FUNCTION_ARGS) { IPR_P ipp1 = PG_GETARG_IPR_P(0); IPR_P ipp2 = PG_GETARG_IPR_P(1); IPR ipr1; IPR ipr2; int af1 = ipr_unpack(ipp1, &ipr1); int af2 = ipr_unpack(ipp2, &ipr2); IPR res; if (af1 == af2) { switch (af1) { case 0: PG_RETURN_IPR_P(ipr_pack(0,NULL)); case PGSQL_AF_INET: ip4r_union_internal(&ipr1.ip4r,&ipr2.ip4r,&res.ip4r); PG_RETURN_IPR_P(ipr_pack(PGSQL_AF_INET,&res)); case PGSQL_AF_INET6: ip6r_union_internal(&ipr1.ip6r,&ipr2.ip6r,&res.ip6r); PG_RETURN_IPR_P(ipr_pack(PGSQL_AF_INET6,&res)); default: iprange_internal_error(); } } else PG_RETURN_IPR_P(ipr_pack(0,NULL)); } PG_FUNCTION_INFO_V1(iprange_inter); Datum iprange_inter(PG_FUNCTION_ARGS) { IPR_P ipp1 = PG_GETARG_IPR_P(0); IPR_P ipp2 = PG_GETARG_IPR_P(1); IPR ipr1; IPR ipr2; int af1 = ipr_unpack(ipp1, &ipr1); int af2 = ipr_unpack(ipp2, &ipr2); IPR res; if (af1 == af2) { switch (af1) { case 0: PG_RETURN_IPR_P(ipr_pack(0,NULL)); case PGSQL_AF_INET: if (ip4r_inter_internal(&ipr1.ip4r,&ipr2.ip4r,&res.ip4r)) PG_RETURN_IPR_P(ipr_pack(PGSQL_AF_INET,&res)); break; case PGSQL_AF_INET6: if (ip6r_inter_internal(&ipr1.ip6r,&ipr2.ip6r,&res.ip6r)) PG_RETURN_IPR_P(ipr_pack(PGSQL_AF_INET6,&res)); break; default: iprange_internal_error(); } } else if (af1 == 0) PG_RETURN_IPR_P(ipr_pack(af2,&ipr2)); else if (af2 == 0) PG_RETURN_IPR_P(ipr_pack(af1,&ipr1)); PG_RETURN_NULL(); } PG_FUNCTION_INFO_V1(iprange_size); Datum iprange_size(PG_FUNCTION_ARGS) { IPR_P ipp = PG_GETARG_IPR_P(0); IPR ipr; int af = ipr_unpack(ipp, &ipr); switch (af) { case 0: PG_RETURN_FLOAT8(ldexp(1.0, 129)); case PGSQL_AF_INET: PG_RETURN_FLOAT8(ip4r_metric(&ipr.ip4r)); case PGSQL_AF_INET6: PG_RETURN_FLOAT8(ip6r_metric(&ipr.ip6r)); default: iprange_internal_error(); } } PG_FUNCTION_INFO_V1(iprange_size_exact); Datum iprange_size_exact(PG_FUNCTION_ARGS) { IPR_P ipp = PG_GETARG_IPR_P(0); IPR ipr; int af = ipr_unpack(ipp, &ipr); Datum u,l,d,s; switch (af) { case 0: s = DirectFunctionCall3(numeric_in, CStringGetDatum("680564733841876926926749214863536422912"), 0, Int32GetDatum(-1)); PG_RETURN_DATUM(s); case PGSQL_AF_INET: l = DirectFunctionCall1(ip4_cast_to_numeric, IP4GetDatum(ipr.ip4r.lower)); u = DirectFunctionCall1(ip4_cast_to_numeric, IP4GetDatum(ipr.ip4r.upper)); break; case PGSQL_AF_INET6: l = DirectFunctionCall1(ip6_cast_to_numeric, IP6PGetDatum(&ipr.ip6r.lower)); u = DirectFunctionCall1(ip6_cast_to_numeric, IP6PGetDatum(&ipr.ip6r.upper)); break; default: iprange_internal_error(); } d = DirectFunctionCall2(numeric_sub, u, l); s = DirectFunctionCall1(numeric_inc, d); PG_RETURN_DATUM(s); } PG_FUNCTION_INFO_V1(iprange_prefixlen); Datum iprange_prefixlen(PG_FUNCTION_ARGS) { IPR_P iprp = PG_GETARG_IPR_P(0); IPR ipr; int af = ipr_unpack(iprp,&ipr); unsigned len = ~0; unsigned maxbits = 0; if (af == PGSQL_AF_INET) maxbits = 32, len = masklen(ipr.ip4r.lower, ipr.ip4r.upper); else if (af == PGSQL_AF_INET6) maxbits = 128, len = masklen6(&ipr.ip6r.lower, &ipr.ip6r.upper); if (len <= maxbits) PG_RETURN_INT32((int32) len); PG_RETURN_NULL(); } /***************************************************************************** * Btree functions *****************************************************************************/ PG_FUNCTION_INFO_V1(iprange_cmp); Datum iprange_cmp(PG_FUNCTION_ARGS) { PG_RETURN_INT32( iprange_cmp_internal(PG_GETARG_DATUM(0), PG_GETARG_DATUM(1)) ); } /***************************************************************************** * GiST functions *****************************************************************************/ /* ** GiST support methods */ Datum gipr_consistent(PG_FUNCTION_ARGS); Datum gipr_compress(PG_FUNCTION_ARGS); Datum gipr_decompress(PG_FUNCTION_ARGS); Datum gipr_penalty(PG_FUNCTION_ARGS); Datum gipr_picksplit(PG_FUNCTION_ARGS); Datum gipr_union(PG_FUNCTION_ARGS); Datum gipr_same(PG_FUNCTION_ARGS); typedef struct { int32 vl_len_; int32 af; IPR ipr; } IPR_KEY; static bool gipr_leaf_consistent(IPR_KEY *key, IPR_P query, StrategyNumber strategy); static bool gipr_internal_consistent(IPR_KEY *key, IPR_P query, StrategyNumber strategy); /* * compress is passed a GISTENTRY* containing a leaf or nonleaf key, and is * expected to return either the same entry or a new one containing the data to * be actually written to the index tuple. The key is a leaf key if and only if * it came from outside GiST (via insert or bulkinsert). */ PG_FUNCTION_INFO_V1(gipr_compress); Datum gipr_compress(PG_FUNCTION_ARGS) { GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *retval = entry; if (!entry->leafkey) { IPR_KEY *key = (IPR_KEY *) DatumGetPointer(entry->key); retval = palloc(sizeof(GISTENTRY)); Assert(!VARATT_IS_EXTENDED(key) && VARSIZE(key) == sizeof(IPR_KEY)); Assert(key->af == 0 || key->af == PGSQL_AF_INET || key->af == PGSQL_AF_INET6); gistentryinit(*retval, PointerGetDatum(ipr_pack(key->af, &key->ipr)), entry->rel, entry->page, entry->offset, FALSE); } PG_RETURN_POINTER(retval); } PG_FUNCTION_INFO_V1(gipr_decompress); Datum gipr_decompress(PG_FUNCTION_ARGS) { GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *retval = palloc(sizeof(GISTENTRY)); IPR_KEY *key = palloc(sizeof(IPR_KEY)); SET_VARSIZE(key, sizeof(IPR_KEY)); key->af = ipr_unpack((IPR_P) DatumGetPointer(entry->key), &key->ipr); gistentryinit(*retval, PointerGetDatum(key), entry->rel, entry->page, entry->offset, FALSE); PG_RETURN_POINTER(retval); } /* ** The GiST Consistent method for IP ranges ** Should return false if for all data items x below entry, ** the predicate x op query == FALSE, where op is the oper ** corresponding to strategy in the pg_amop table. */ PG_FUNCTION_INFO_V1(gipr_consistent); Datum gipr_consistent(PG_FUNCTION_ARGS) { GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); IPR_P query = (IPR_P) PG_GETARG_POINTER(1); StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2); bool *recheck = GIST_RECHECK_ARG; IPR_KEY *key = (IPR_KEY *) DatumGetPointer(entry->key); bool retval; /* recheck is never needed with this type */ if (recheck) *recheck = false; /* * * if entry is not leaf, use gipr_internal_consistent, * else use * gipr_leaf_consistent */ if (GIST_LEAF(entry)) retval = gipr_leaf_consistent(key, query, strategy); else retval = gipr_internal_consistent(key, query, strategy); PG_RETURN_BOOL(retval); } /* ** The GiST Union method for IP ranges ** returns the minimal bounding IPR that encloses all the entries in entryvec */ static void gipr_union_internal_1(IPR_KEY *out, IPR_KEY *tmp) { if (out->af != tmp->af) out->af = 0; switch (out->af) { case 0: break; case PGSQL_AF_INET: { if (ip4_lessthan(tmp->ipr.ip4r.lower,out->ipr.ip4r.lower)) out->ipr.ip4r.lower = tmp->ipr.ip4r.lower; if (ip4_lessthan(out->ipr.ip4r.upper,tmp->ipr.ip4r.upper)) out->ipr.ip4r.upper = tmp->ipr.ip4r.upper; break; } case PGSQL_AF_INET6: { if (ip6_lessthan(&tmp->ipr.ip6r.lower,&out->ipr.ip6r.lower)) out->ipr.ip6r.lower = tmp->ipr.ip6r.lower; if (ip6_lessthan(&out->ipr.ip6r.upper,&tmp->ipr.ip6r.upper)) out->ipr.ip6r.upper = tmp->ipr.ip6r.upper; break; } default: iprange_internal_error(); } } static void gipr_union_internal(IPR_KEY *out, bool *allequalp, bool *afequalp, GISTENTRY *ent, int numranges) { int i; bool allequal = true; bool afequal = true; IPR_KEY *tmp; tmp = (IPR_KEY *) DatumGetPointer(ent[0].key); *out = *tmp; for (i = 1; out->af != 0 && i < numranges; ++i) { tmp = (IPR_KEY *) DatumGetPointer(ent[i].key); if (tmp->af != out->af) { out->af = 0; afequal = allequal = false; } } switch (out->af) { case 0: break; case PGSQL_AF_INET: { tmp = (IPR_KEY *) DatumGetPointer(ent[0].key); out->ipr.ip4r = tmp->ipr.ip4r; for (i = 1; i < numranges; i++) { tmp = (IPR_KEY *) DatumGetPointer(ent[i].key); if (allequal && !ip4r_equal(&tmp->ipr.ip4r, &out->ipr.ip4r)) allequal = false; if (ip4_lessthan(tmp->ipr.ip4r.lower,out->ipr.ip4r.lower)) out->ipr.ip4r.lower = tmp->ipr.ip4r.lower; if (ip4_lessthan(out->ipr.ip4r.upper,tmp->ipr.ip4r.upper)) out->ipr.ip4r.upper = tmp->ipr.ip4r.upper; } break; } case PGSQL_AF_INET6: { tmp = (IPR_KEY *) DatumGetPointer(ent[0].key); out->ipr.ip4r = tmp->ipr.ip4r; for (i = 1; i < numranges; i++) { tmp = (IPR_KEY *) DatumGetPointer(ent[i].key); if (allequal && !ip6r_equal(&tmp->ipr.ip6r, &out->ipr.ip6r)) allequal = false; if (ip6_lessthan(&tmp->ipr.ip6r.lower,&out->ipr.ip6r.lower)) out->ipr.ip6r.lower = tmp->ipr.ip6r.lower; if (ip6_lessthan(&out->ipr.ip6r.upper,&tmp->ipr.ip6r.upper)) out->ipr.ip6r.upper = tmp->ipr.ip6r.upper; } break; } default: iprange_internal_error(); } if (afequalp) *afequalp = afequal; if (allequalp) *allequalp = allequal; } PG_FUNCTION_INFO_V1(gipr_union); Datum gipr_union(PG_FUNCTION_ARGS) { GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0); int *sizep = (int *) PG_GETARG_POINTER(1); GISTENTRY *ent = GISTENTRYVEC(entryvec); int numranges; IPR_KEY *out = palloc(sizeof(IPR_KEY)); #ifdef GIST_DEBUG fprintf(stderr, "union\n"); #endif numranges = GISTENTRYCOUNT(entryvec); gipr_union_internal(out, NULL, NULL, ent, numranges); *sizep = sizeof(IPR_KEY); PG_RETURN_POINTER(out); } /* ** The GiST Penalty method for IP ranges ** As in the R-tree paper, we use change in area as our penalty metric */ PG_FUNCTION_INFO_V1(gipr_penalty); Datum gipr_penalty(PG_FUNCTION_ARGS) { GISTENTRY *origentry = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *newentry = (GISTENTRY *) PG_GETARG_POINTER(1); float *result = (float *) PG_GETARG_POINTER(2); IPR_KEY *key = (IPR_KEY *) DatumGetPointer(origentry->key); IPR_KEY *newkey = (IPR_KEY *) DatumGetPointer(newentry->key); IP4R ud4; IP6R ud6; double tmp = 0.0; if (key->af != newkey->af) { if (key->af != 0 && newkey->af != 0) tmp = 1e10; } else { switch (key->af) { case 0: break; /* * rather than subtract the sizes, which might lose * due to rounding errors in v6, we calculate the * actual number of addresses added to the range. */ case PGSQL_AF_INET: if (newkey->ipr.ip4r.lower < key->ipr.ip4r.lower) { ud4.lower = newkey->ipr.ip4r.lower; ud4.upper = key->ipr.ip4r.lower - 1; tmp = ip4r_metric(&ud4); } if (key->ipr.ip4r.upper < newkey->ipr.ip4r.upper) { ud4.lower = key->ipr.ip4r.upper; ud4.upper = newkey->ipr.ip4r.upper - 1; tmp += ip4r_metric(&ud4); } break; case PGSQL_AF_INET6: if (ip6_lessthan(&newkey->ipr.ip6r.lower,&key->ipr.ip6r.lower)) { ud6.lower = newkey->ipr.ip6r.lower; ud6.upper = key->ipr.ip6r.lower; ip6_sub_int(&ud6.upper,1,&ud6.upper); tmp = ip6r_metric(&ud6); } if (ip6_lessthan(&key->ipr.ip6r.upper,&newkey->ipr.ip6r.upper)) { ud6.lower = key->ipr.ip6r.upper; ud6.upper = newkey->ipr.ip6r.upper; ip6_sub_int(&ud6.upper,1,&ud6.upper); tmp += ip6r_metric(&ud6); } /* * we want to scale the result a bit. For one thing, the gist code implicitly * assigns a penalty of 1e10 for a union of null and non-null values, and we * want to keep our values less than that. For another, the penalty is sometimes * summed across columns of a multi-column index, and we don't want our huge * metrics (>2^80) to completely swamp anything else. * * So, we scale as the fourth power of the log2 of the computed penalty, which * gives us a range 0 - 268435456. */ tmp = pow(log(tmp+1) / log(2), 4); break; default: iprange_internal_error(); } } *result = (float) tmp; #ifdef GIST_DEBUG fprintf(stderr, "penalty\n"); fprintf(stderr, "\t%g\n", *result); #endif PG_RETURN_POINTER(result); } /* Helper functions for picksplit. We might need to sort a list of * ranges by size; these are for that. We don't ever need to sort * mixed address families though. */ struct gipr_sort { IPR_KEY *key; OffsetNumber pos; }; static int gipr_sort_compare_v4(const void *av, const void *bv) { IPR_KEY *a = ((struct gipr_sort *)av)->key; IPR_KEY *b = ((struct gipr_sort *)bv)->key; double sa = ip4r_metric(&a->ipr.ip4r); double sb = ip4r_metric(&b->ipr.ip4r); return (sa > sb) ? 1 : ((sa == sb) ? 0 : -1); } static int gipr_sort_compare_v6(const void *av, const void *bv) { IPR_KEY *a = ((struct gipr_sort *)av)->key; IPR_KEY *b = ((struct gipr_sort *)bv)->key; double sa = ip6r_metric(&a->ipr.ip6r); double sb = ip6r_metric(&b->ipr.ip6r); return (sa > sb) ? 1 : ((sa == sb) ? 0 : -1); } /* ** The GiST PickSplit method for IP ranges ** This is a linear-time algorithm based on a left/right split, ** based on the box functions in rtree_gist simplified to one ** dimension */ PG_FUNCTION_INFO_V1(gipr_picksplit); Datum gipr_picksplit(PG_FUNCTION_ARGS) { GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0); GIST_SPLITVEC *v = (GIST_SPLITVEC *) PG_GETARG_POINTER(1); GISTENTRY *ent = GISTENTRYVEC(entryvec); OffsetNumber i; int nbytes; OffsetNumber maxoff; OffsetNumber *listL; OffsetNumber *listR; bool allisequal = true; bool allafequal = true; IPR_KEY pageunion; IPR_KEY *cur; IPR_KEY *unionL; IPR_KEY *unionR; int posL = 0; int posR = 0; posL = posR = 0; maxoff = GISTENTRYCOUNT(entryvec) - 1; gipr_union_internal(&pageunion, &allisequal, &allafequal, &ent[FirstOffsetNumber], maxoff); nbytes = (maxoff + 2) * sizeof(OffsetNumber); listL = (OffsetNumber *) palloc(nbytes); listR = (OffsetNumber *) palloc(nbytes); unionL = palloc(sizeof(IPR_KEY)); unionR = palloc(sizeof(IPR_KEY)); v->spl_ldatum = PointerGetDatum(unionL); v->spl_rdatum = PointerGetDatum(unionR); v->spl_left = listL; v->spl_right = listR; if (allisequal) { OffsetNumber split_at = FirstOffsetNumber + (maxoff - FirstOffsetNumber + 1)/2; v->spl_nleft = v->spl_nright = 0; *unionL = pageunion; *unionR = pageunion; for (i = FirstOffsetNumber; i < split_at; i = OffsetNumberNext(i)) v->spl_left[v->spl_nleft++] = i; for (; i <= maxoff; i = OffsetNumberNext(i)) v->spl_right[v->spl_nright++] = i; PG_RETURN_POINTER(v); } /* * if we have a mix of address families present, then we split by AF regardless * of all other factors, since the penalty for mixing them is so high. If there's * at least one universal range, we split those into the right page and leave * everything else in the left page; otherwise, we split ivp6 into the right page. * We accept a bad split ratio here in the interests of keeping AFs separate. */ #define ADDLIST( list_, u_, pos_, num_ ) do { \ if ( pos_ ) { \ gipr_union_internal_1(u_, cur); \ } else { \ *(u_) = *(cur); \ } \ (list_)[(pos_)++] = (num_); \ } while(0) if (!allafequal) { int right_af = PGSQL_AF_INET6; for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i)) if ( ((IPR_KEY *)DatumGetPointer(ent[i].key))->af == 0) break; if (i <= maxoff) right_af = 0; for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i)) { cur = (IPR_KEY *)DatumGetPointer(ent[i].key); if (cur->af != right_af) ADDLIST(listL, unionL, posL, i); else ADDLIST(listR, unionR, posR, i); } } else if (pageunion.af == PGSQL_AF_INET) { for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i)) { cur = (IPR_KEY *) DatumGetPointer(ent[i].key); if ((cur->ipr.ip4r.upper - pageunion.ipr.ip4r.lower) < (pageunion.ipr.ip4r.upper - cur->ipr.ip4r.lower)) ADDLIST(listL, unionL, posL, i); else ADDLIST(listR, unionR, posR, i); } } else { for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i)) { IP6 diff1; IP6 diff2; cur = (IPR_KEY *) DatumGetPointer(ent[i].key); ip6_sub(&cur->ipr.ip6r.upper, &pageunion.ipr.ip6r.lower, &diff1); ip6_sub(&pageunion.ipr.ip6r.upper, &cur->ipr.ip6r.lower, &diff2); if (ip6_lessthan(&diff1,&diff2)) ADDLIST(listL, unionL, posL, i); else ADDLIST(listR, unionR, posR, i); } } /* bad disposition, sort by ascending size and resplit */ if (posR == 0 || posL == 0) { struct gipr_sort *arr = (struct gipr_sort *) palloc(sizeof(struct gipr_sort) * (maxoff + FirstOffsetNumber)); Assert(allafequal); for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i)) { arr[i].key = (IPR_KEY *) DatumGetPointer(ent[i].key); arr[i].pos = i; } qsort(arr + FirstOffsetNumber, maxoff - FirstOffsetNumber + 1, sizeof(struct gipr_sort), (pageunion.af == PGSQL_AF_INET6) ? gipr_sort_compare_v6 : gipr_sort_compare_v4); posL = posR = 0; for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i)) { IP6 diff1; IP6 diff2; cur = arr[i].key; if (pageunion.af == PGSQL_AF_INET) { diff1.bits[0] = (cur->ipr.ip4r.upper - pageunion.ipr.ip4r.lower); diff2.bits[0] = (pageunion.ipr.ip4r.upper - cur->ipr.ip4r.lower); diff1.bits[1] = diff2.bits[1] = 0; } else { ip6_sub(&cur->ipr.ip6r.upper, &pageunion.ipr.ip6r.lower, &diff1); ip6_sub(&pageunion.ipr.ip6r.upper, &cur->ipr.ip6r.lower, &diff2); } switch (ip6_compare(&diff1,&diff2)) { case -1: ADDLIST(listL, unionL, posL, arr[i].pos); break; case 0: if (posL > posR) ADDLIST(listR, unionR, posR, arr[i].pos); else ADDLIST(listL, unionL, posL, arr[i].pos); break; case 1: ADDLIST(listR, unionR, posR, arr[i].pos); break; } } pfree(arr); } v->spl_nleft = posL; v->spl_nright = posR; PG_RETURN_POINTER(v); } #undef ADDLIST /* ** Equality methods */ PG_FUNCTION_INFO_V1(gipr_same); Datum gipr_same(PG_FUNCTION_ARGS) { IPR_KEY *v1 = (IPR_KEY *) PG_GETARG_POINTER(0); IPR_KEY *v2 = (IPR_KEY *) PG_GETARG_POINTER(1); bool *result = (bool *) PG_GETARG_POINTER(2); if (!v1 || !v2) *result = (v1 == NULL && v2 == NULL); if (v1->af != v2->af) *result = false; else { switch (v1->af) { case 0: *result = true; break; case PGSQL_AF_INET: *result = ip4r_equal(&v1->ipr.ip4r,&v2->ipr.ip4r); break; case PGSQL_AF_INET6: *result = ip6r_equal(&v1->ipr.ip6r,&v2->ipr.ip6r); break; } } #ifdef GIST_DEBUG fprintf(stderr, "same: %s\n", (*result ? "TRUE" : "FALSE")); #endif PG_RETURN_POINTER(result); } /* * Strategy numbers: * OPERATOR 1 >>= , * OPERATOR 2 <<= , * OPERATOR 3 >> , * OPERATOR 4 << , * OPERATOR 5 && , * OPERATOR 6 = , */ /* ** SUPPORT ROUTINES */ static bool gipr_leaf_consistent(IPR_KEY *key, IPR_P queryp, StrategyNumber strategy) { IPR query; int af = ipr_unpack(queryp, &query); #ifdef GIST_QUERY_DEBUG fprintf(stderr, "leaf_consistent, %d\n", strategy); #endif if (key->af == 0) { switch (strategy) { case 1: /* left contains right nonstrict */ return true; case 2: /* left contained in right nonstrict */ return (af == 0); case 3: /* left contains right strict */ return !(af == 0); case 4: /* left contained in right strict */ return false; case 5: /* left overlaps right */ return true; case 6: /* left equal right */ return (af == 0); } } else if (af == 0) { switch (strategy) { case 1: /* left contains right nonstrict */ return false; case 2: /* left contained in right nonstrict */ return true; case 3: /* left contains right strict */ return false; case 4: /* left contained in right strict */ return true; case 5: /* left overlaps right */ return true; case 6: /* left equal right */ return false; } } else if (af != key->af) return false; else if (af == PGSQL_AF_INET) { switch (strategy) { case 1: /* left contains right nonstrict */ return ip4r_contains_internal(&key->ipr.ip4r, &query.ip4r, TRUE); case 2: /* left contained in right nonstrict */ return ip4r_contains_internal(&query.ip4r, &key->ipr.ip4r, TRUE); case 3: /* left contains right strict */ return ip4r_contains_internal(&key->ipr.ip4r, &query.ip4r, FALSE); case 4: /* left contained in right strict */ return ip4r_contains_internal(&query.ip4r, &key->ipr.ip4r, FALSE); case 5: /* left overlaps right */ return ip4r_overlaps_internal(&key->ipr.ip4r, &query.ip4r); case 6: /* left equal right */ return ip4r_equal(&key->ipr.ip4r, &query.ip4r); } } else if (af == PGSQL_AF_INET6) { switch (strategy) { case 1: /* left contains right nonstrict */ return ip6r_contains_internal(&key->ipr.ip6r, &query.ip6r, TRUE); case 2: /* left contained in right nonstrict */ return ip6r_contains_internal(&query.ip6r, &key->ipr.ip6r, TRUE); case 3: /* left contains right strict */ return ip6r_contains_internal(&key->ipr.ip6r, &query.ip6r, FALSE); case 4: /* left contained in right strict */ return ip6r_contains_internal(&query.ip6r, &key->ipr.ip6r, FALSE); case 5: /* left overlaps right */ return ip6r_overlaps_internal(&key->ipr.ip6r, &query.ip6r); case 6: /* left equal right */ return ip6r_equal(&key->ipr.ip6r, &query.ip6r); } } return FALSE; } /* logic notes: * If the union value we're looking at overlaps with our query value * at all, then any of the values underneath it might overlap with us * or be contained by us, so all the "contained by" and "overlaps" * cases degenerate to "overlap". * If the union value is equal to the query value, then none of the * values under it can strictly contain the query value, so for * "contained" queries the strictness is preserved. * If we're looking for an "equal" value, then we have to enter any * subtree whose union contains (not strictly) our query value. */ static bool gipr_internal_consistent(IPR_KEY *key, IPR_P queryp, StrategyNumber strategy) { IPR query; int af = ipr_unpack(queryp, &query); #ifdef GIST_QUERY_DEBUG fprintf(stderr, "leaf_consistent, %d\n", strategy); #endif if (af == 0 && strategy == 4) return false; else if (key->af == 0 || af == 0) return true; else if (af != key->af) return false; else if (af == PGSQL_AF_INET) { switch (strategy) { case 2: /* left contained in right nonstrict */ case 4: /* left contained in right strict */ case 5: /* left overlaps right */ return ip4r_overlaps_internal(&key->ipr.ip4r, &query.ip4r); case 3: /* left contains right strict */ return ip4r_contains_internal(&key->ipr.ip4r, &query.ip4r, FALSE); case 1: /* left contains right nonstrict */ case 6: /* left equal right */ return ip4r_contains_internal(&key->ipr.ip4r, &query.ip4r, TRUE); } } else if (af == PGSQL_AF_INET6) { switch (strategy) { case 2: /* left contained in right nonstrict */ case 4: /* left contained in right strict */ case 5: /* left overlaps right */ return ip6r_overlaps_internal(&key->ipr.ip6r, &query.ip6r); case 3: /* left contains right strict */ return ip6r_contains_internal(&key->ipr.ip6r, &query.ip6r, FALSE); case 1: /* left contains right nonstrict */ case 6: /* left equal right */ return ip6r_contains_internal(&key->ipr.ip6r, &query.ip6r, TRUE); } } return FALSE; } /* end */ ip4r-2.0.2/legacy-r.sed000066400000000000000000000002061233620317400145700ustar00rootroot00000000000000# /^CREATE EXTENSION/c\ SET client_min_messages = warning;\ \\set ECHO none\ \\i ip4r.sql\ \\set ECHO all\ RESET client_min_messages; ip4r-2.0.2/legacy.sed000066400000000000000000000006171233620317400143370ustar00rootroot00000000000000# /^-- complain.*CREATE EXTENSION/,/^$/c\ -- Adjust this setting to control where the objects get created.\ SET search_path = public;\ \ # /^-- Type definitions/a\ \ BEGIN; # /^-- type creation is needlessly chatty/a\ \ SET LOCAL client_min_messages = warning; # /^COMMENT ON TYPE iprange/a\ \ COMMIT; # /^CREATE TYPE [^()]*;/,/^$/d /^CREATE FUNCTION/s/CREATE FUNCTION/CREATE OR REPLACE FUNCTION/ ip4r-2.0.2/raw_io.c000066400000000000000000000137501233620317400140240ustar00rootroot00000000000000/* $Id: raw_io.c,v 1.2 2011/08/22 14:05:19 andrewsn Exp $ */ /* * Copyright (c) 2011 Andrew Gierth * * Licensed under the same terms as PostgreSQL itself. */ #include "ipr.h" bool ip4_raw_input(const char *osrc, uint32 *dst) { const unsigned char *src = (const unsigned char *)osrc; int digits = 0; int octets = 0; int ch; uint32 octet = 0; uint32 tmp = 0; for (;;) { switch ((ch = *src++)) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': if (digits++ && octet == 0) return false; /* must have been a leading 0, reject */ octet = (octet * 10) + (ch - '0'); if (octet > 255) return false; break; case '.': if (!digits || ++octets > 3) return false; tmp = (tmp << 8) | octet; digits = 0; octet = 0; break; case 0: if (!digits || octets != 3) return false; tmp = (tmp << 8) | octet; *dst = tmp; return true; default: return false; } } } bool ip6_raw_input(const char *osrc, uint64 *dst) { const unsigned char *src = (const unsigned char *)osrc; const unsigned char *backtrack = src; int ch; int digits = 0; int words = 0; int gap = -1; uint16 word = 0; uint16 tmp[8]; /* leading :: needs a special case */ if (*src == ':') if (*++src != ':') return false; for (;;) { switch ((ch = *src++)) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': word = (word << 4) | (ch - '0'); break; case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': word = (word << 4) | ((ch - 'a') + 10); break; case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': word = (word << 4) | ((ch - 'A') + 10); break; case ':': if (digits == 0) { if (gap >= 0) return false; gap = words; } else if (!*src) return false; /* trailing : not valid except as :: */ tmp[words++] = word; if (words > 7 && *src) return false; backtrack = src; word = 0; digits = 0; continue; case '.': if (words < 1 || words > 6) return false; { uint32 ip4val; if (!ip4_raw_input((const char *)backtrack, &ip4val)) return false; tmp[words++] = (ip4val >> 16); word = (ip4val & 0xffff); digits = 4; } /* FALLTHROUGH */ case 0: if (digits) tmp[words++] = word; if (words < 8) { int i,d; if (gap < 0) return false; d = 8 - words; for (i = 7; i > gap+d; --i) tmp[i] = tmp[i-d]; for (; i > gap; --i) tmp[i] = 0; } dst[0] = (((uint64)(tmp[0]) << 48) | ((uint64)(tmp[1]) << 32) | ((uint64)(tmp[2]) << 16) | tmp[3]); dst[1] = (((uint64)(tmp[4]) << 48) | ((uint64)(tmp[5]) << 32) | ((uint64)(tmp[6]) << 16) | tmp[7]); return true; default: return false; } if (++digits > 4) return false; } } int ip4_raw_output(uint32 ip, char *str, int len) { return snprintf(str, len, "%u.%u.%u.%u", (ip >> 24)&0xff, (ip >> 16)&0xff, (ip >> 8)&0xff, (ip)&0xff); } int ip6_raw_output(uint64 *ip, char *str, int len) { uint16 tmp[8]; char buf[sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255") + 2]; char *ptr = buf; unsigned flags = (1 << 8); int best = -1; int best_len = 1; int best_end; uint16 word; int i,j; tmp[0] = ip[0] >> 48; tmp[1] = ip[0] >> 32; tmp[2] = ip[0] >> 16; tmp[3] = ip[0]; tmp[4] = ip[1] >> 48; tmp[5] = ip[1] >> 32; tmp[6] = ip[1] >> 16; tmp[7] = ip[1]; /* * Find the best place to put :: in the output. Per RFC5952, we must: * - not use :: to replace a single 0 word * - use :: to replace the longest string of 0 words * - use :: to replace the leftmost candidate string of equal length * * The bitmask we construct here has the least significant bit * representing the leftmost word, and we process the bitmask by * shifting right, therefore we are processing the original words * left to right. Thus we take a new best position only if it is * strictly better than the previous one. * * best = -1 implies that there is no position to use :: */ for (i = 0; i < 8; ++i) flags |= (tmp[i] ? (1 << i) : 0); for (i = 0; i < 8; ++i, flags >>= 1) if ((flags & 1) == 0 && (ffs(flags)-1) > best_len) best = i, best_len = ffs(flags)-1; best_end = best + best_len - 1; /* * If we're starting with a string of more than one zero word, process * the special cases: * * all zeros (8 zero words) - '::' * 6 zero words followed by a non-zero word - '::1.2.3.4' * 5 zero words followed by 0xffff - '::ffff:1.2.3.4' * 4 zero words followed by ffff:0 - '::ffff:0:1.2.3.4' [rfc2765] * * The case of 7 zero words we leave alone; that avoids trying to output * '::1' as '::0.0.0.1'. We assume that '0.0.x.y' will never be a valid * IPv4 address used in an IPv4-compatible IPv6 address (which are in any * event deprecated). */ if (best == 0) { if (best_len == 6 || (best_len == 5 && tmp[5] == 0xffff) || (best_len == 4 && tmp[4] == 0xffff && tmp[5] == 0)) { ip4_raw_output(((uint32)(tmp[6]) << 16) | tmp[7], buf, sizeof(buf)-2); return snprintf(str, len, ":%s%s:%s", (best_len != 6) ? ":ffff" : "", (best_len == 4) ? ":0" : "", buf); } else if (best_len == 8) return snprintf(str, len, "::"); } for (i = 0; i < 8; ++i) { if (i >= best && i <= best_end) { if (i == best_end) *ptr++ = ':'; continue; } if (i > 0) *ptr++ = ':'; word = tmp[i]; /* * canonicalization rules: * * leading zeros must be suppressed. * output must be lowercase. */ if (!word) *ptr++ = '0'; else { word = (word >> 8) | (word << 8); word = ((word & 0xf0f0) >> 4) | ((word & 0x0f0f) << 4); for (j = 0; j < 3; ++j, word >>= 4) if (word & 0xf) break; for (; j < 4; ++j, word >>= 4) *ptr++ = ((word & 0xf) > 9) ? ((word & 0xf) + 'a' - 10) : ((word & 0xf) + '0'); } } if (best_end == 7) *ptr++ = ':'; *ptr = 0; return snprintf(str, len, "%s", buf); } ip4r-2.0.2/sql/000077500000000000000000000000001233620317400131715ustar00rootroot00000000000000ip4r-2.0.2/sql/ip4r.sql000066400000000000000000003242211233620317400145740ustar00rootroot00000000000000-- CREATE EXTENSION ip4r; \set VERBOSITY terse -- -- Valid and invalid addresses -- --valid ip4 select '1.2.3.4'::ip4; select '0.0.0.0'::ip4; select '255.255.255.255'::ip4; select '0.0.0.255'::ip4; select '0.0.255.0'::ip4; select '0.255.0.0'::ip4; select '255.0.0.0'::ip4; select '192.168.123.210'::ip4; select '127.0.0.1'::ip4; --invalid ip4 select '1.2.3'::ip4; select '0'::ip4; select ' 1.2.3.4'::ip4; select '1.2.3.4 '::ip4; select '0.0.0.256'::ip4; select '0.0.256'::ip4; select '0..255.0'::ip4; select '+0.255.0.0'::ip4; select '1.2.3.4-1.2.3.4'::ip4; -- valid ip6 select '0000:0000:0000:0000:0000:0000:0000:0000'::ip6; select '0000:0000:0000:0000:0000:0000:0000:0001'::ip6; select '0:0:0:0:0:0:0:0'::ip6; select '0:0:0:0:0:0:0:1'::ip6; select '0:0:0:0:0:0:13.1.68.3'::ip6; select '0:0:0:0:0:FFFF:129.144.52.38'::ip6; select '0::0'::ip6; select '1:2:3:4:5:6:1.2.3.4'::ip6; select '1:2:3:4:5:6:7:8'::ip6; select '1:2:3:4:5:6::'::ip6; select '1:2:3:4:5:6::8'::ip6; select '1:2:3:4:5::'::ip6; select '1:2:3:4:5::1.2.3.4'::ip6; select '1:2:3:4:5::7:8'::ip6; select '1:2:3:4:5::8'::ip6; select '1:2:3:4::'::ip6; select '1:2:3:4::1.2.3.4'::ip6; select '1:2:3:4::5:1.2.3.4'::ip6; select '1:2:3:4::7:8'::ip6; select '1:2:3:4::8'::ip6; select '1:2:3::'::ip6; select '1:2:3::1.2.3.4'::ip6; select '1:2:3::5:1.2.3.4'::ip6; select '1:2:3::7:8'::ip6; select '1:2:3::8'::ip6; select '1:2::'::ip6; select '1:2::1.2.3.4'::ip6; select '1:2::5:1.2.3.4'::ip6; select '1:2::7:8'::ip6; select '1:2::8'::ip6; select '1::'::ip6; select '1::1.2.3.4'::ip6; select '1::2:3'::ip6; select '1::2:3:4'::ip6; select '1::2:3:4:5'::ip6; select '1::2:3:4:5:6'::ip6; select '1::2:3:4:5:6:7'::ip6; select '1::5:1.2.3.4'::ip6; select '1::5:11.22.33.44'::ip6; select '1::7:8'::ip6; select '1::8'::ip6; select '2001:0000:1234:0000:0000:C1C0:ABCD:0876'::ip6; select '2001:0db8:0000:0000:0000:0000:1428:57ab'::ip6; select '2001:0db8:0000:0000:0000::1428:57ab'::ip6; select '2001:0db8:0:0:0:0:1428:57ab'::ip6; select '2001:0db8:0:0::1428:57ab'::ip6; select '2001:0db8:1234:0000:0000:0000:0000:0000'::ip6; select '2001:0db8:1234::'::ip6; select '2001:0db8:1234:ffff:ffff:ffff:ffff:ffff'::ip6; select '2001:0db8:85a3:0000:0000:8a2e:0370:7334'::ip6; select '2001:0db8::1428:57ab'::ip6; select '2001:10::'::ip6; select '2001::'::ip6; select '2001:DB8:0:0:8:800:200C:417A'::ip6; select '2001:DB8::8:800:200C:417A'::ip6; select '2001:db8:85a3:0:0:8a2e:370:7334'::ip6; select '2001:db8:85a3::8a2e:370:7334'::ip6; select '2001:db8::'::ip6; select '2001:db8::'::ip6; select '2001:db8::1428:57ab'::ip6; select '2001:db8:a::123'::ip6; select '2002::'::ip6; select '2::10'::ip6; select '3ffe:0b00:0000:0000:0001:0000:0000:000a'::ip6; select '::'::ip6; select '::1'::ip6; select '::127.0.0.1'::ip6; select '::13.1.68.3'::ip6; select '::2:3'::ip6; select '::2:3:4'::ip6; select '::2:3:4:5'::ip6; select '::2:3:4:5:6'::ip6; select '::2:3:4:5:6:7'::ip6; select '::2:3:4:5:6:7:8'::ip6; select '::8'::ip6; select '::FFFF:129.144.52.38'::ip6; select '::ffff:0:0'::ip6; select '::ffff:0:192.168.1.1'::ip6; select '::ffff:1:1.2.3.4'::ip6; select '::ffff:0c22:384e'::ip6; select '::ffff:12.34.56.78'::ip6; select '::ffff:192.0.2.128'::ip6; select '::ffff:192.168.1.1'::ip6; select '::ffff:192.168.1.26'::ip6; select '::ffff:c000:280'::ip6; select 'FF01:0:0:0:0:0:0:101'::ip6; select 'FF01::101'::ip6; select 'FF02:0000:0000:0000:0000:0000:0000:0001'::ip6; select 'fc00::'::ip6; select 'fe80:0000:0000:0000:0204:61ff:fe9d:f156'::ip6; select 'fe80:0:0:0:204:61ff:254.157.241.86'::ip6; select 'fe80:0:0:0:204:61ff:fe9d:f156'::ip6; select 'fe80::'::ip6; select 'fe80::1'::ip6; select 'fe80::204:61ff:254.157.241.86'::ip6; select 'fe80::204:61ff:fe9d:f156'::ip6; select 'fe80::217:f2ff:254.7.237.98'::ip6; select 'fe80::217:f2ff:fe07:ed62'::ip6; select 'ff02::1'::ip6; -- invalid ip6 select ''::ip6; select '02001:0000:1234:0000:0000:C1C0:ABCD:0876'::ip6; select '1.2.3.4:1111:2222:3333:4444::5555'::ip6; select '1.2.3.4:1111:2222:3333::5555'::ip6; select '1.2.3.4:1111:2222::5555'::ip6; select '1.2.3.4:1111::5555'::ip6; select '1.2.3.4::'::ip6; select '1.2.3.4::5555'::ip6; select '1111:'::ip6; select '1111:2222:3333:4444::5555:'::ip6; select '1111:2222:3333::5555:'::ip6; select '1111:2222::5555:'::ip6; select '1111::5555:'::ip6; select '123'::ip6; select '12345::6:7:8'::ip6; select '127.0.0.1'::ip6; select '1:2:3:4:5:6:7:8:9'::ip6; select '1:2:3::4:5:6:7:8:9'::ip6; select '1:2:3::4:5::7:8'::ip6; select '1::1.2.256.4'::ip6; select '1::1.2.3.256'::ip6; select '1::1.2.3.300'::ip6; select '1::1.2.3.900'::ip6; select '1::1.2.300.4'::ip6; select '1::1.2.900.4'::ip6; select '1::1.256.3.4'::ip6; select '1::1.300.3.4'::ip6; select '1::1.900.3.4'::ip6; select '1::256.2.3.4'::ip6; select '1::260.2.3.4'::ip6; select '1::2::3'::ip6; select '1::300.2.3.4'::ip6; select '1::300.300.300.300'::ip6; select '1::3000.30.30.30'::ip6; select '1::400.2.3.4'::ip6; select '1::5:1.2.256.4'::ip6; select '1::5:1.2.3.256'::ip6; select '1::5:1.2.3.300'::ip6; select '1::5:1.2.3.900'::ip6; select '1::5:1.2.300.4'::ip6; select '1::5:1.2.900.4'::ip6; select '1::5:1.256.3.4'::ip6; select '1::5:1.300.3.4'::ip6; select '1::5:1.900.3.4'::ip6; select '1::5:256.2.3.4'::ip6; select '1::5:260.2.3.4'::ip6; select '1::5:300.2.3.4'::ip6; select '1::5:300.300.300.300'::ip6; select '1::5:3000.30.30.30'::ip6; select '1::5:400.2.3.4'::ip6; select '1::5:900.2.3.4'::ip6; select '1::900.2.3.4'::ip6; select '1:::3:4:5'::ip6; select '2001:0000:1234: 0000:0000:C1C0:ABCD:0876'::ip6; select '2001:0000:1234:0000:00001:C1C0:ABCD:0876'::ip6; select '2001:0000:1234:0000:0000:C1C0:ABCD:0876 0'::ip6; select '2001::FFD3::57ab'::ip6; select '2001:DB8:0:0:8:800:200C:417A:221'::ip6; select '2001:db8:85a3::8a2e:37023:7334'::ip6; select '2001:db8:85a3::8a2e:370k:7334'::ip6; select '3ffe:0b00:0000:0001:0000:0000:000a'::ip6; select '3ffe:b00::1::a'::ip6; select ':'::ip6; select ':1111:2222:3333:4444::5555'::ip6; select ':1111:2222:3333::5555'::ip6; select ':1111:2222::5555'::ip6; select ':1111::5555'::ip6; select '::1.2.256.4'::ip6; select '::1.2.3.256'::ip6; select '::1.2.3.300'::ip6; select '::1.2.3.900'::ip6; select '::1.2.300.4'::ip6; select '::1.2.900.4'::ip6; select '::1.256.3.4'::ip6; select '::1.300.3.4'::ip6; select '::1.900.3.4'::ip6; select '::1111:2222:3333:4444:5555:6666::'::ip6; select '::256.2.3.4'::ip6; select '::260.2.3.4'::ip6; select '::300.2.3.4'::ip6; select '::300.300.300.300'::ip6; select '::3000.30.30.30'::ip6; select '::400.2.3.4'::ip6; select '::5555:'::ip6; select '::900.2.3.4'::ip6; select ':::'::ip6; select ':::5555'::ip6; select '::ffff:2.3.4'::ip6; select '::ffff:257.1.2.3'::ip6; select 'FF01::101::2'::ip6; select 'FF02:0000:0000:0000:0000:0000:0000:0000:0001'::ip6; select 'ldkfj'::ip6; -- valid ip4r select '1.2.3.4'::ip4r; select '255.255.255.255/32'::ip4r; select '255.255.255.254/31'::ip4r; select '255.255.255.252/30'::ip4r; select '255.255.255.248/29'::ip4r; select '255.255.255.240/28'::ip4r; select '255.255.255.224/27'::ip4r; select '255.255.255.192/26'::ip4r; select '255.255.255.128/25'::ip4r; select '255.255.255.0/24'::ip4r; select '255.255.254.0/23'::ip4r; select '255.255.252.0/22'::ip4r; select '255.255.248.0/21'::ip4r; select '255.255.240.0/20'::ip4r; select '255.255.224.0/19'::ip4r; select '255.255.192.0/18'::ip4r; select '255.255.128.0/17'::ip4r; select '255.255.0.0/16'::ip4r; select '255.254.0.0/15'::ip4r; select '255.252.0.0/14'::ip4r; select '255.248.0.0/13'::ip4r; select '255.240.0.0/12'::ip4r; select '255.224.0.0/11'::ip4r; select '255.192.0.0/10'::ip4r; select '255.128.0.0/9'::ip4r; select '255.0.0.0/8'::ip4r; select '254.0.0.0/7'::ip4r; select '252.0.0.0/6'::ip4r; select '248.0.0.0/5'::ip4r; select '240.0.0.0/4'::ip4r; select '224.0.0.0/3'::ip4r; select '192.0.0.0/2'::ip4r; select '128.0.0.0/1'::ip4r; select '0.0.0.0/0'::ip4r; select '1.2.3.4-5.6.7.8'::ip4r; select '5.6.7.8-1.2.3.4'::ip4r; select '1.2.3.4-1.2.3.4'::ip4r; -- invalid ip4r select '1.2.3'::ip4r; select '255.255.255.255.255.255.255.255.255'::ip4r; select '255.255.255.255.255-255.255.255.255.255'::ip4r; select '255.255.255.255-1.2.3.4.5'::ip4r; select '255.255.255.255-1.2.3'::ip4r; select '0.0.0.1/31'::ip4r; select '0.0.0.1/30'::ip4r; select '0.0.0.1/29'::ip4r; select '0.0.0.1/28'::ip4r; select '0.0.0.1/27'::ip4r; select '0.0.0.1/26'::ip4r; select '0.0.0.1/25'::ip4r; select '0.0.0.1/24'::ip4r; select '0.0.0.1/23'::ip4r; select '0.0.0.1/22'::ip4r; select '0.0.0.1/21'::ip4r; select '0.0.0.1/20'::ip4r; select '0.0.0.1/19'::ip4r; select '0.0.0.1/18'::ip4r; select '0.0.0.1/17'::ip4r; select '0.0.0.1/16'::ip4r; select '0.0.0.1/15'::ip4r; select '0.0.0.1/14'::ip4r; select '0.0.0.1/13'::ip4r; select '0.0.0.1/12'::ip4r; select '0.0.0.1/11'::ip4r; select '0.0.0.1/10'::ip4r; select '0.0.0.1/9'::ip4r; select '0.0.0.1/8'::ip4r; select '0.0.0.1/7'::ip4r; select '0.0.0.1/6'::ip4r; select '0.0.0.1/5'::ip4r; select '0.0.0.1/4'::ip4r; select '0.0.0.1/3'::ip4r; select '0.0.0.1/2'::ip4r; select '0.0.0.1/1'::ip4r; select '0.0.0.1/0'::ip4r; select '0.0.0.2/30'::ip4r; select '0.0.0.4/29'::ip4r; select '0.0.0.8/28'::ip4r; select '0.0.0.16/27'::ip4r; select '0.0.0.32/26'::ip4r; select '0.0.0.64/25'::ip4r; select '0.0.0.128/24'::ip4r; select '0.0.1.0/23'::ip4r; select '0.0.2.0/22'::ip4r; select '0.0.4.0/21'::ip4r; select '0.0.8.0/20'::ip4r; select '0.0.16.0/19'::ip4r; select '0.0.32.0/18'::ip4r; select '0.0.64.0/17'::ip4r; select '0.0.128.0/16'::ip4r; select '0.1.0.0/15'::ip4r; select '0.2.0.0/14'::ip4r; select '0.4.0.0/13'::ip4r; select '0.8.0.0/12'::ip4r; select '0.16.0.0/11'::ip4r; select '0.32.0.0/10'::ip4r; select '0.64.0.0/9'::ip4r; select '0.128.0.0/8'::ip4r; select '1.0.0.0/7'::ip4r; select '2.0.0.0/6'::ip4r; select '4.0.0.0/5'::ip4r; select '8.0.0.0/4'::ip4r; select '16.0.0.0/3'::ip4r; select '32.0.0.0/2'::ip4r; select '64.0.0.0/1'::ip4r; select '128.0.0.0/0'::ip4r; select '0.0.0.0/33'::ip4r; select '0.0.0.0/3.0'::ip4r; select '0.0.0.0/+33'::ip4r; -- valid ip6r select '::'::ip6r; select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'::ip6r; select '1::2'::ip6r; select '::-ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'::ip6r; select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff-::'::ip6r; select '1::2-3::4'::ip6r; select '3::4-3::4'::ip6r; select '3::4-1::2'::ip6r; select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128'::ip6r; select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffe/127'::ip6r; select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffc/126'::ip6r; select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:fff8/125'::ip6r; select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:fff0/124'::ip6r; select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ff00/120'::ip6r; select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:f000/116'::ip6r; select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:0000/112'::ip6r; select 'ffff:ffff:ffff:ffff:ffff:ffff:0000:0000/96'::ip6r; select 'ffff:ffff:ffff:ffff:ffff:0000:0000:0000/80'::ip6r; select 'ffff:ffff:ffff:ffff:fff0:0000:0000:0000/76'::ip6r; select 'ffff:ffff:ffff:ffff:ff00:0000:0000:0000/72'::ip6r; select 'ffff:ffff:ffff:ffff:f000:0000:0000:0000/68'::ip6r; select 'ffff:ffff:ffff:ffff:e000:0000:0000:0000/67'::ip6r; select 'ffff:ffff:ffff:ffff:c000:0000:0000:0000/66'::ip6r; select 'ffff:ffff:ffff:ffff:8000:0000:0000:0000/65'::ip6r; select 'ffff:ffff:ffff:ffff:0000:0000:0000:0000/64'::ip6r; select 'ffff:ffff:ffff:fffe:0000:0000:0000:0000/63'::ip6r; select 'ffff:ffff:ffff:fffc:0000:0000:0000:0000/62'::ip6r; select 'ffff:ffff:ffff:fff8:0000:0000:0000:0000/61'::ip6r; select 'ffff:ffff:ffff:fff0:0000:0000:0000:0000/60'::ip6r; select 'ffff:ffff:ffff:ff00:0000:0000:0000:0000/56'::ip6r; select 'ffff:ffff:ffff:f000:0000:0000:0000:0000/52'::ip6r; select 'ffff:ffff:ffff:0000:0000:0000:0000:0000/48'::ip6r; select 'ffff:ffff:0000:0000:0000:0000:0000:0000/32'::ip6r; select 'ffff:0000:0000:0000:0000:0000:0000:0000/16'::ip6r; select 'fff0:0000:0000:0000:0000:0000:0000:0000/12'::ip6r; select 'ff00:0000:0000:0000:0000:0000:0000:0000/8'::ip6r; select 'f000:0000:0000:0000:0000:0000:0000:0000/4'::ip6r; select 'e000:0000:0000:0000:0000:0000:0000:0000/3'::ip6r; select 'c000:0000:0000:0000:0000:0000:0000:0000/2'::ip6r; select '8000:0000:0000:0000:0000:0000:0000:0000/1'::ip6r; select '0000:0000:0000:0000:0000:0000:0000:0000/0'::ip6r; -- invalid ip6r select '::-::-::'::ip6r; select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff-ffff'::ip6r; select '::-ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'::ip6r; select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff-::'::ip6r; select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128'::ip6r; select '0000:0000:0000:0000:0000:0000:0000:0001/127'::ip6r; select '0000:0000:0000:0000:0000:0000:0000:0001/120'::ip6r; select '0000:0000:0000:0000:0000:0000:0000:0001/112'::ip6r; select '0000:0000:0000:0000:0000:0000:0000:0001/96'::ip6r; select '0000:0000:0000:0000:0000:0000:0000:0001/80'::ip6r; select '0000:0000:0000:0000:0000:0000:0000:0001/64'::ip6r; select '0000:0000:0000:0000:0000:0000:0000:0001/48'::ip6r; select '0000:0000:0000:0000:0000:0000:0000:0001/32'::ip6r; select '0000:0000:0000:0000:0000:0000:0000:0001/16'::ip6r; select '0000:0000:0000:0000:0000:0000:0000:0001/8'::ip6r; select '0000:0000:0000:0000:0000:0000:0000:0001/4'::ip6r; select '0000:0000:0000:0000:0000:0000:0000:0001/0'::ip6r; select '0000:0000:0000:0000:0000:0000:0000:0008/124'::ip6r; select '0000:0000:0000:0000:0000:0000:0000:0080/120'::ip6r; select '0000:0000:0000:0000:0000:0000:0000:8000/112'::ip6r; select '0000:0000:0000:0000:0000:0000:8000:0000/96'::ip6r; select '0000:0000:0000:0000:0000:8000:0000:0000/80'::ip6r; select '0000:0000:0000:0000:8000:0000:0000:0000/64'::ip6r; select '0000:0000:0000:8000:0000:0000:0000:0000/48'::ip6r; select '0000:0000:8000:0000:0000:0000:0000:0000/32'::ip6r; select '0000:8000:0000:0000:0000:0000:0000:0000/16'::ip6r; select '0080:0000:0000:0000:0000:0000:0000:0000/8'::ip6r; select '0800:0000:0000:0000:0000:0000:0000:0000/4'::ip6r; select '8000:0000:0000:0000:0000:0000:0000:0000/0'::ip6r; select '::/129'::ip6r; select '::/255'::ip6r; select '::/256'::ip6r; select '::/+0'::ip6r; select '::/0-0'::ip6r; select '::-::/0'::ip6r; -- valid ipaddress select a, family(a) from (select '1.2.3.4'::ipaddress as a) s1; select a, family(a) from (select '0.0.0.0'::ipaddress as a) s1; select a, family(a) from (select '255.255.255.255'::ipaddress as a) s1; select a, family(a) from (select '0.0.0.255'::ipaddress as a) s1; select a, family(a) from (select '0.0.255.0'::ipaddress as a) s1; select a, family(a) from (select '0.255.0.0'::ipaddress as a) s1; select a, family(a) from (select '255.0.0.0'::ipaddress as a) s1; select a, family(a) from (select '192.168.123.210'::ipaddress as a) s1; select a, family(a) from (select '127.0.0.1'::ipaddress as a) s1; select a, family(a) from (select '0000:0000:0000:0000:0000:0000:0000:0000'::ipaddress as a) s1; select a, family(a) from (select '0000:0000:0000:0000:0000:0000:0000:0001'::ipaddress as a) s1; select a, family(a) from (select '0:0:0:0:0:0:0:0'::ipaddress as a) s1; select a, family(a) from (select '0:0:0:0:0:0:0:1'::ipaddress as a) s1; select a, family(a) from (select '0:0:0:0:0:0:13.1.68.3'::ipaddress as a) s1; select a, family(a) from (select '0:0:0:0:0:FFFF:129.144.52.38'::ipaddress as a) s1; select a, family(a) from (select '0::0'::ipaddress as a) s1; select a, family(a) from (select '1:2:3:4:5:6:1.2.3.4'::ipaddress as a) s1; select a, family(a) from (select '1:2:3:4:5:6:7:8'::ipaddress as a) s1; select a, family(a) from (select '1:2:3:4:5:6::'::ipaddress as a) s1; select a, family(a) from (select '1:2:3:4:5:6::8'::ipaddress as a) s1; select a, family(a) from (select '1:2:3:4:5::'::ipaddress as a) s1; select a, family(a) from (select '1:2:3:4:5::1.2.3.4'::ipaddress as a) s1; select a, family(a) from (select '1:2:3:4:5::7:8'::ipaddress as a) s1; select a, family(a) from (select '1:2:3:4:5::8'::ipaddress as a) s1; select a, family(a) from (select '1:2:3:4::'::ipaddress as a) s1; select a, family(a) from (select '1:2:3:4::1.2.3.4'::ipaddress as a) s1; select a, family(a) from (select '1:2:3:4::5:1.2.3.4'::ipaddress as a) s1; select a, family(a) from (select '1:2:3:4::7:8'::ipaddress as a) s1; select a, family(a) from (select '1:2:3:4::8'::ipaddress as a) s1; select a, family(a) from (select '1:2:3::'::ipaddress as a) s1; select a, family(a) from (select '1:2:3::1.2.3.4'::ipaddress as a) s1; select a, family(a) from (select '1:2:3::5:1.2.3.4'::ipaddress as a) s1; select a, family(a) from (select '1:2:3::7:8'::ipaddress as a) s1; select a, family(a) from (select '1:2:3::8'::ipaddress as a) s1; select a, family(a) from (select '1:2::'::ipaddress as a) s1; select a, family(a) from (select '1:2::1.2.3.4'::ipaddress as a) s1; select a, family(a) from (select '1:2::5:1.2.3.4'::ipaddress as a) s1; select a, family(a) from (select '1:2::7:8'::ipaddress as a) s1; select a, family(a) from (select '1:2::8'::ipaddress as a) s1; select a, family(a) from (select '1::'::ipaddress as a) s1; select a, family(a) from (select '1::1.2.3.4'::ipaddress as a) s1; select a, family(a) from (select '1::2:3'::ipaddress as a) s1; select a, family(a) from (select '1::2:3:4'::ipaddress as a) s1; select a, family(a) from (select '1::2:3:4:5'::ipaddress as a) s1; select a, family(a) from (select '1::2:3:4:5:6'::ipaddress as a) s1; select a, family(a) from (select '1::2:3:4:5:6:7'::ipaddress as a) s1; select a, family(a) from (select '1::5:1.2.3.4'::ipaddress as a) s1; select a, family(a) from (select '1::5:11.22.33.44'::ipaddress as a) s1; select a, family(a) from (select '1::7:8'::ipaddress as a) s1; select a, family(a) from (select '1::8'::ipaddress as a) s1; select a, family(a) from (select '2001:0000:1234:0000:0000:C1C0:ABCD:0876'::ipaddress as a) s1; select a, family(a) from (select '2001:0db8:0000:0000:0000:0000:1428:57ab'::ipaddress as a) s1; select a, family(a) from (select '2001:0db8:0000:0000:0000::1428:57ab'::ipaddress as a) s1; select a, family(a) from (select '2001:0db8:0:0:0:0:1428:57ab'::ipaddress as a) s1; select a, family(a) from (select '2001:0db8:0:0::1428:57ab'::ipaddress as a) s1; select a, family(a) from (select '2001:0db8:1234:0000:0000:0000:0000:0000'::ipaddress as a) s1; select a, family(a) from (select '2001:0db8:1234::'::ipaddress as a) s1; select a, family(a) from (select '2001:0db8:1234:ffff:ffff:ffff:ffff:ffff'::ipaddress as a) s1; select a, family(a) from (select '2001:0db8:85a3:0000:0000:8a2e:0370:7334'::ipaddress as a) s1; select a, family(a) from (select '2001:0db8::1428:57ab'::ipaddress as a) s1; select a, family(a) from (select '2001:10::'::ipaddress as a) s1; select a, family(a) from (select '2001::'::ipaddress as a) s1; select a, family(a) from (select '2001:DB8:0:0:8:800:200C:417A'::ipaddress as a) s1; select a, family(a) from (select '2001:DB8::8:800:200C:417A'::ipaddress as a) s1; select a, family(a) from (select '2001:db8:85a3:0:0:8a2e:370:7334'::ipaddress as a) s1; select a, family(a) from (select '2001:db8:85a3::8a2e:370:7334'::ipaddress as a) s1; select a, family(a) from (select '2001:db8::'::ipaddress as a) s1; select a, family(a) from (select '2001:db8::'::ipaddress as a) s1; select a, family(a) from (select '2001:db8::1428:57ab'::ipaddress as a) s1; select a, family(a) from (select '2001:db8:a::123'::ipaddress as a) s1; select a, family(a) from (select '2002::'::ipaddress as a) s1; select a, family(a) from (select '2::10'::ipaddress as a) s1; select a, family(a) from (select '3ffe:0b00:0000:0000:0001:0000:0000:000a'::ipaddress as a) s1; select a, family(a) from (select '::'::ipaddress as a) s1; select a, family(a) from (select '::1'::ipaddress as a) s1; select a, family(a) from (select '::127.0.0.1'::ipaddress as a) s1; select a, family(a) from (select '::13.1.68.3'::ipaddress as a) s1; select a, family(a) from (select '::2:3'::ipaddress as a) s1; select a, family(a) from (select '::2:3:4'::ipaddress as a) s1; select a, family(a) from (select '::2:3:4:5'::ipaddress as a) s1; select a, family(a) from (select '::2:3:4:5:6'::ipaddress as a) s1; select a, family(a) from (select '::2:3:4:5:6:7'::ipaddress as a) s1; select a, family(a) from (select '::2:3:4:5:6:7:8'::ipaddress as a) s1; select a, family(a) from (select '::8'::ipaddress as a) s1; select a, family(a) from (select '::FFFF:129.144.52.38'::ipaddress as a) s1; select a, family(a) from (select '::ffff:0:0'::ipaddress as a) s1; select a, family(a) from (select '::ffff:0:192.168.1.1'::ipaddress as a) s1; select a, family(a) from (select '::ffff:1:1.2.3.4'::ipaddress as a) s1; select a, family(a) from (select '::ffff:0c22:384e'::ipaddress as a) s1; select a, family(a) from (select '::ffff:12.34.56.78'::ipaddress as a) s1; select a, family(a) from (select '::ffff:192.0.2.128'::ipaddress as a) s1; select a, family(a) from (select '::ffff:192.168.1.1'::ipaddress as a) s1; select a, family(a) from (select '::ffff:192.168.1.26'::ipaddress as a) s1; select a, family(a) from (select '::ffff:c000:280'::ipaddress as a) s1; select a, family(a) from (select 'FF01:0:0:0:0:0:0:101'::ipaddress as a) s1; select a, family(a) from (select 'FF01::101'::ipaddress as a) s1; select a, family(a) from (select 'FF02:0000:0000:0000:0000:0000:0000:0001'::ipaddress as a) s1; select a, family(a) from (select 'fc00::'::ipaddress as a) s1; select a, family(a) from (select 'fe80:0000:0000:0000:0204:61ff:fe9d:f156'::ipaddress as a) s1; select a, family(a) from (select 'fe80:0:0:0:204:61ff:254.157.241.86'::ipaddress as a) s1; select a, family(a) from (select 'fe80:0:0:0:204:61ff:fe9d:f156'::ipaddress as a) s1; select a, family(a) from (select 'fe80::'::ipaddress as a) s1; select a, family(a) from (select 'fe80::1'::ipaddress as a) s1; select a, family(a) from (select 'fe80::204:61ff:254.157.241.86'::ipaddress as a) s1; select a, family(a) from (select 'fe80::204:61ff:fe9d:f156'::ipaddress as a) s1; select a, family(a) from (select 'fe80::217:f2ff:254.7.237.98'::ipaddress as a) s1; select a, family(a) from (select 'fe80::217:f2ff:fe07:ed62'::ipaddress as a) s1; select a, family(a) from (select 'ff02::1'::ipaddress as a) s1; -- invalid ipaddress select '1.2.3'::ipaddress; select '0'::ipaddress; select ' 1.2.3.4'::ipaddress; select '1.2.3.4 '::ipaddress; select '0.0.0.256'::ipaddress; select '0.0.256'::ipaddress; select '0..255.0'::ipaddress; select '+0.255.0.0'::ipaddress; select '1.2.3.4-1.2.3.4'::ipaddress; select ''::ipaddress; select '02001:0000:1234:0000:0000:C1C0:ABCD:0876'::ipaddress; select '1.2.3.4:1111:2222:3333:4444::5555'::ipaddress; select '1.2.3.4:1111:2222:3333::5555'::ipaddress; select '1.2.3.4:1111:2222::5555'::ipaddress; select '1.2.3.4:1111::5555'::ipaddress; select '1.2.3.4::'::ipaddress; select '1.2.3.4::5555'::ipaddress; select '1111:'::ipaddress; select '1111:2222:3333:4444::5555:'::ipaddress; select '1111:2222:3333::5555:'::ipaddress; select '1111:2222::5555:'::ipaddress; select '1111::5555:'::ipaddress; select '123'::ipaddress; select '12345::6:7:8'::ipaddress; select '1:2:3:4:5:6:7:8:9'::ipaddress; select '1:2:3::4:5:6:7:8:9'::ipaddress; select '1:2:3::4:5::7:8'::ipaddress; select '1::1.2.256.4'::ipaddress; select '1::1.2.3.256'::ipaddress; select '1::1.2.3.300'::ipaddress; select '1::1.2.3.900'::ipaddress; select '1::1.2.300.4'::ipaddress; select '1::1.2.900.4'::ipaddress; select '1::1.256.3.4'::ipaddress; select '1::1.300.3.4'::ipaddress; select '1::1.900.3.4'::ipaddress; select '1::256.2.3.4'::ipaddress; select '1::260.2.3.4'::ipaddress; select '1::2::3'::ipaddress; select '1::300.2.3.4'::ipaddress; select '1::300.300.300.300'::ipaddress; select '1::3000.30.30.30'::ipaddress; select '1::400.2.3.4'::ipaddress; select '1::5:1.2.256.4'::ipaddress; select '1::5:1.2.3.256'::ipaddress; select '1::5:1.2.3.300'::ipaddress; select '1::5:1.2.3.900'::ipaddress; select '1::5:1.2.300.4'::ipaddress; select '1::5:1.2.900.4'::ipaddress; select '1::5:1.256.3.4'::ipaddress; select '1::5:1.300.3.4'::ipaddress; select '1::5:1.900.3.4'::ipaddress; select '1::5:256.2.3.4'::ipaddress; select '1::5:260.2.3.4'::ipaddress; select '1::5:300.2.3.4'::ipaddress; select '1::5:300.300.300.300'::ipaddress; select '1::5:3000.30.30.30'::ipaddress; select '1::5:400.2.3.4'::ipaddress; select '1::5:900.2.3.4'::ipaddress; select '1::900.2.3.4'::ipaddress; select '1:::3:4:5'::ipaddress; select '2001:0000:1234: 0000:0000:C1C0:ABCD:0876'::ipaddress; select '2001:0000:1234:0000:00001:C1C0:ABCD:0876'::ipaddress; select '2001:0000:1234:0000:0000:C1C0:ABCD:0876 0'::ipaddress; select '2001::FFD3::57ab'::ipaddress; select '2001:DB8:0:0:8:800:200C:417A:221'::ipaddress; select '2001:db8:85a3::8a2e:37023:7334'::ipaddress; select '2001:db8:85a3::8a2e:370k:7334'::ipaddress; select '3ffe:0b00:0000:0001:0000:0000:000a'::ipaddress; select '3ffe:b00::1::a'::ipaddress; select ':'::ipaddress; select ':1111:2222:3333:4444::5555'::ipaddress; select ':1111:2222:3333::5555'::ipaddress; select ':1111:2222::5555'::ipaddress; select ':1111::5555'::ipaddress; select '::1.2.256.4'::ipaddress; select '::1.2.3.256'::ipaddress; select '::1.2.3.300'::ipaddress; select '::1.2.3.900'::ipaddress; select '::1.2.300.4'::ipaddress; select '::1.2.900.4'::ipaddress; select '::1.256.3.4'::ipaddress; select '::1.300.3.4'::ipaddress; select '::1.900.3.4'::ipaddress; select '::1111:2222:3333:4444:5555:6666::'::ipaddress; select '::256.2.3.4'::ipaddress; select '::260.2.3.4'::ipaddress; select '::300.2.3.4'::ipaddress; select '::300.300.300.300'::ipaddress; select '::3000.30.30.30'::ipaddress; select '::400.2.3.4'::ipaddress; select '::5555:'::ipaddress; select '::900.2.3.4'::ipaddress; select ':::'::ipaddress; select ':::5555'::ipaddress; select '::ffff:2.3.4'::ipaddress; select '::ffff:257.1.2.3'::ipaddress; select 'FF01::101::2'::ipaddress; select 'FF02:0000:0000:0000:0000:0000:0000:0000:0001'::ipaddress; select 'ldkfj'::ipaddress; -- valid iprange select r, family(r), iprange_size(r) from (select '-'::iprange as r) s; select r, family(r), iprange_size(r) from (select '1.2.3.4'::iprange as r) s; select r, family(r), iprange_size(r) from (select '255.255.255.255/32'::iprange as r) s; select r, family(r), iprange_size(r) from (select '255.255.255.254/31'::iprange as r) s; select r, family(r), iprange_size(r) from (select '255.255.255.252/30'::iprange as r) s; select r, family(r), iprange_size(r) from (select '255.255.255.248/29'::iprange as r) s; select r, family(r), iprange_size(r) from (select '255.255.255.240/28'::iprange as r) s; select r, family(r), iprange_size(r) from (select '255.255.255.224/27'::iprange as r) s; select r, family(r), iprange_size(r) from (select '255.255.255.192/26'::iprange as r) s; select r, family(r), iprange_size(r) from (select '255.255.255.128/25'::iprange as r) s; select r, family(r), iprange_size(r) from (select '255.255.255.0/24'::iprange as r) s; select r, family(r), iprange_size(r) from (select '255.255.254.0/23'::iprange as r) s; select r, family(r), iprange_size(r) from (select '255.255.252.0/22'::iprange as r) s; select r, family(r), iprange_size(r) from (select '255.255.248.0/21'::iprange as r) s; select r, family(r), iprange_size(r) from (select '255.255.240.0/20'::iprange as r) s; select r, family(r), iprange_size(r) from (select '255.255.224.0/19'::iprange as r) s; select r, family(r), iprange_size(r) from (select '255.255.192.0/18'::iprange as r) s; select r, family(r), iprange_size(r) from (select '255.255.128.0/17'::iprange as r) s; select r, family(r), iprange_size(r) from (select '255.255.0.0/16'::iprange as r) s; select r, family(r), iprange_size(r) from (select '255.254.0.0/15'::iprange as r) s; select r, family(r), iprange_size(r) from (select '255.252.0.0/14'::iprange as r) s; select r, family(r), iprange_size(r) from (select '255.248.0.0/13'::iprange as r) s; select r, family(r), iprange_size(r) from (select '255.240.0.0/12'::iprange as r) s; select r, family(r), iprange_size(r) from (select '255.224.0.0/11'::iprange as r) s; select r, family(r), iprange_size(r) from (select '255.192.0.0/10'::iprange as r) s; select r, family(r), iprange_size(r) from (select '255.128.0.0/9'::iprange as r) s; select r, family(r), iprange_size(r) from (select '255.0.0.0/8'::iprange as r) s; select r, family(r), iprange_size(r) from (select '254.0.0.0/7'::iprange as r) s; select r, family(r), iprange_size(r) from (select '252.0.0.0/6'::iprange as r) s; select r, family(r), iprange_size(r) from (select '248.0.0.0/5'::iprange as r) s; select r, family(r), iprange_size(r) from (select '240.0.0.0/4'::iprange as r) s; select r, family(r), iprange_size(r) from (select '224.0.0.0/3'::iprange as r) s; select r, family(r), iprange_size(r) from (select '192.0.0.0/2'::iprange as r) s; select r, family(r), iprange_size(r) from (select '128.0.0.0/1'::iprange as r) s; select r, family(r), iprange_size(r) from (select '0.0.0.0/0'::iprange as r) s; select r, family(r), iprange_size(r) from (select '1.2.3.4-5.6.7.8'::iprange as r) s; select r, family(r), iprange_size(r) from (select '5.6.7.8-1.2.3.4'::iprange as r) s; select r, family(r), iprange_size(r) from (select '1.2.3.4-1.2.3.4'::iprange as r) s; select r, family(r), iprange_size(r) from (select '::'::iprange as r) s; select r, family(r), iprange_size(r) from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'::iprange as r) s; select r, family(r), iprange_size(r) from (select '1::2'::iprange as r) s; select r, family(r), iprange_size(r) from (select '::-ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'::iprange as r) s; select r, family(r), iprange_size(r) from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff-::'::iprange as r) s; select r, family(r), iprange_size(r) from (select '1::2-3::4'::iprange as r) s; select r, family(r), iprange_size(r) from (select '3::4-3::4'::iprange as r) s; select r, family(r), iprange_size(r) from (select '3::4-1::2'::iprange as r) s; select r, family(r), iprange_size(r) from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128'::iprange as r) s; select r, family(r), iprange_size(r) from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffe/127'::iprange as r) s; select r, family(r), iprange_size(r) from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffc/126'::iprange as r) s; select r, family(r), iprange_size(r) from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:fff8/125'::iprange as r) s; select r, family(r), iprange_size(r) from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:fff0/124'::iprange as r) s; select r, family(r), iprange_size(r) from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ff00/120'::iprange as r) s; select r, family(r), iprange_size(r) from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:f000/116'::iprange as r) s; select r, family(r), iprange_size(r) from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:0000/112'::iprange as r) s; select r, family(r), iprange_size(r) from (select 'ffff:ffff:ffff:ffff:ffff:ffff:0000:0000/96'::iprange as r) s; select r, family(r), iprange_size(r) from (select 'ffff:ffff:ffff:ffff:ffff:0000:0000:0000/80'::iprange as r) s; select r, family(r), iprange_size(r) from (select 'ffff:ffff:ffff:ffff:fff0:0000:0000:0000/76'::iprange as r) s; select r, family(r), iprange_size(r) from (select 'ffff:ffff:ffff:ffff:ff00:0000:0000:0000/72'::iprange as r) s; select r, family(r), iprange_size(r) from (select 'ffff:ffff:ffff:ffff:f000:0000:0000:0000/68'::iprange as r) s; select r, family(r), iprange_size(r) from (select 'ffff:ffff:ffff:ffff:e000:0000:0000:0000/67'::iprange as r) s; select r, family(r), iprange_size(r) from (select 'ffff:ffff:ffff:ffff:c000:0000:0000:0000/66'::iprange as r) s; select r, family(r), iprange_size(r) from (select 'ffff:ffff:ffff:ffff:8000:0000:0000:0000/65'::iprange as r) s; select r, family(r), iprange_size(r) from (select 'ffff:ffff:ffff:ffff:0000:0000:0000:0000/64'::iprange as r) s; select r, family(r), iprange_size(r) from (select 'ffff:ffff:ffff:fffe:0000:0000:0000:0000/63'::iprange as r) s; select r, family(r), iprange_size(r) from (select 'ffff:ffff:ffff:fffc:0000:0000:0000:0000/62'::iprange as r) s; select r, family(r), iprange_size(r) from (select 'ffff:ffff:ffff:fff8:0000:0000:0000:0000/61'::iprange as r) s; select r, family(r), iprange_size(r) from (select 'ffff:ffff:ffff:fff0:0000:0000:0000:0000/60'::iprange as r) s; select r, family(r), iprange_size(r) from (select 'ffff:ffff:ffff:ff00:0000:0000:0000:0000/56'::iprange as r) s; select r, family(r), iprange_size(r) from (select 'ffff:ffff:ffff:f000:0000:0000:0000:0000/52'::iprange as r) s; select r, family(r), iprange_size(r) from (select 'ffff:ffff:ffff:0000:0000:0000:0000:0000/48'::iprange as r) s; select r, family(r), iprange_size(r) from (select 'ffff:ffff:0000:0000:0000:0000:0000:0000/32'::iprange as r) s; select r, family(r), iprange_size(r) from (select 'ffff:0000:0000:0000:0000:0000:0000:0000/16'::iprange as r) s; select r, family(r), iprange_size(r) from (select 'fff0:0000:0000:0000:0000:0000:0000:0000/12'::iprange as r) s; select r, family(r), iprange_size(r) from (select 'ff00:0000:0000:0000:0000:0000:0000:0000/8'::iprange as r) s; select r, family(r), iprange_size(r) from (select 'f000:0000:0000:0000:0000:0000:0000:0000/4'::iprange as r) s; select r, family(r), iprange_size(r) from (select 'e000:0000:0000:0000:0000:0000:0000:0000/3'::iprange as r) s; select r, family(r), iprange_size(r) from (select 'c000:0000:0000:0000:0000:0000:0000:0000/2'::iprange as r) s; select r, family(r), iprange_size(r) from (select '8000:0000:0000:0000:0000:0000:0000:0000/1'::iprange as r) s; select r, family(r), iprange_size(r) from (select '0000:0000:0000:0000:0000:0000:0000:0000/0'::iprange as r) s; -- invalid iprange select '1.2.3'::iprange; select '255.255.255.255.255.255.255.255.255'::iprange; select '255.255.255.255.255-255.255.255.255.255'::iprange; select '255.255.255.255-1.2.3.4.5'::iprange; select '255.255.255.255-1.2.3'::iprange; select '0.0.0.1/31'::iprange; select '0.0.0.1/30'::iprange; select '0.0.0.1/29'::iprange; select '0.0.0.1/28'::iprange; select '0.0.0.1/27'::iprange; select '0.0.0.1/26'::iprange; select '0.0.0.1/25'::iprange; select '0.0.0.1/24'::iprange; select '0.0.0.1/23'::iprange; select '0.0.0.1/22'::iprange; select '0.0.0.1/21'::iprange; select '0.0.0.1/20'::iprange; select '0.0.0.1/19'::iprange; select '0.0.0.1/18'::iprange; select '0.0.0.1/17'::iprange; select '0.0.0.1/16'::iprange; select '0.0.0.1/15'::iprange; select '0.0.0.1/14'::iprange; select '0.0.0.1/13'::iprange; select '0.0.0.1/12'::iprange; select '0.0.0.1/11'::iprange; select '0.0.0.1/10'::iprange; select '0.0.0.1/9'::iprange; select '0.0.0.1/8'::iprange; select '0.0.0.1/7'::iprange; select '0.0.0.1/6'::iprange; select '0.0.0.1/5'::iprange; select '0.0.0.1/4'::iprange; select '0.0.0.1/3'::iprange; select '0.0.0.1/2'::iprange; select '0.0.0.1/1'::iprange; select '0.0.0.1/0'::iprange; select '0.0.0.2/30'::iprange; select '0.0.0.4/29'::iprange; select '0.0.0.8/28'::iprange; select '0.0.0.16/27'::iprange; select '0.0.0.32/26'::iprange; select '0.0.0.64/25'::iprange; select '0.0.0.128/24'::iprange; select '0.0.1.0/23'::iprange; select '0.0.2.0/22'::iprange; select '0.0.4.0/21'::iprange; select '0.0.8.0/20'::iprange; select '0.0.16.0/19'::iprange; select '0.0.32.0/18'::iprange; select '0.0.64.0/17'::iprange; select '0.0.128.0/16'::iprange; select '0.1.0.0/15'::iprange; select '0.2.0.0/14'::iprange; select '0.4.0.0/13'::iprange; select '0.8.0.0/12'::iprange; select '0.16.0.0/11'::iprange; select '0.32.0.0/10'::iprange; select '0.64.0.0/9'::iprange; select '0.128.0.0/8'::iprange; select '1.0.0.0/7'::iprange; select '2.0.0.0/6'::iprange; select '4.0.0.0/5'::iprange; select '8.0.0.0/4'::iprange; select '16.0.0.0/3'::iprange; select '32.0.0.0/2'::iprange; select '64.0.0.0/1'::iprange; select '128.0.0.0/0'::iprange; select '0.0.0.0/33'::iprange; select '0.0.0.0/3.0'::iprange; select '0.0.0.0/+33'::iprange; select '::-::-::'::iprange; select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff-ffff'::ip6r; select '::-ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'::iprange; select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff-::'::iprange; select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128'::iprange; select '0000:0000:0000:0000:0000:0000:0000:0001/127'::iprange; select '0000:0000:0000:0000:0000:0000:0000:0001/120'::iprange; select '0000:0000:0000:0000:0000:0000:0000:0001/112'::iprange; select '0000:0000:0000:0000:0000:0000:0000:0001/96'::iprange; select '0000:0000:0000:0000:0000:0000:0000:0001/80'::iprange; select '0000:0000:0000:0000:0000:0000:0000:0001/64'::iprange; select '0000:0000:0000:0000:0000:0000:0000:0001/48'::iprange; select '0000:0000:0000:0000:0000:0000:0000:0001/32'::iprange; select '0000:0000:0000:0000:0000:0000:0000:0001/16'::iprange; select '0000:0000:0000:0000:0000:0000:0000:0001/8'::iprange; select '0000:0000:0000:0000:0000:0000:0000:0001/4'::iprange; select '0000:0000:0000:0000:0000:0000:0000:0001/0'::iprange; select '0000:0000:0000:0000:0000:0000:0000:0008/124'::iprange; select '0000:0000:0000:0000:0000:0000:0000:0080/120'::iprange; select '0000:0000:0000:0000:0000:0000:0000:8000/112'::iprange; select '0000:0000:0000:0000:0000:0000:8000:0000/96'::iprange; select '0000:0000:0000:0000:0000:8000:0000:0000/80'::iprange; select '0000:0000:0000:0000:8000:0000:0000:0000/64'::iprange; select '0000:0000:0000:8000:0000:0000:0000:0000/48'::iprange; select '0000:0000:8000:0000:0000:0000:0000:0000/32'::iprange; select '0000:8000:0000:0000:0000:0000:0000:0000/16'::iprange; select '0080:0000:0000:0000:0000:0000:0000:0000/8'::iprange; select '0800:0000:0000:0000:0000:0000:0000:0000/4'::iprange; select '8000:0000:0000:0000:0000:0000:0000:0000/0'::iprange; select '::/129'::iprange; select '::/255'::iprange; select '::/256'::iprange; select '::/+0'::iprange; select '::/0-0'::iprange; select '::-::/0'::iprange; select '-::'::iprange; select '-1.2.3.4'::iprange; select '1.2.3.4-'::iprange; -- text casts and cross-type casts select r::text from (select '-'::iprange as r) s; select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '1.2.3.4'::iprange as r) s; select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '255.255.255.255/32'::iprange as r) s; select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '255.255.255.254/31'::iprange as r) s; select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '255.255.255.252/30'::iprange as r) s; select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '255.255.255.248/29'::iprange as r) s; select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '255.255.255.240/28'::iprange as r) s; select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '255.255.255.224/27'::iprange as r) s; select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '255.255.255.192/26'::iprange as r) s; select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '255.255.255.128/25'::iprange as r) s; select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '255.255.255.0/24'::iprange as r) s; select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '255.255.254.0/23'::iprange as r) s; select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '255.255.252.0/22'::iprange as r) s; select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '255.255.248.0/21'::iprange as r) s; select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '255.255.240.0/20'::iprange as r) s; select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '255.255.224.0/19'::iprange as r) s; select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '255.255.192.0/18'::iprange as r) s; select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '255.255.128.0/17'::iprange as r) s; select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '255.255.0.0/16'::iprange as r) s; select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '255.254.0.0/15'::iprange as r) s; select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '255.252.0.0/14'::iprange as r) s; select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '255.248.0.0/13'::iprange as r) s; select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '255.240.0.0/12'::iprange as r) s; select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '255.224.0.0/11'::iprange as r) s; select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '255.192.0.0/10'::iprange as r) s; select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '255.128.0.0/9'::iprange as r) s; select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '255.0.0.0/8'::iprange as r) s; select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '254.0.0.0/7'::iprange as r) s; select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '252.0.0.0/6'::iprange as r) s; select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '248.0.0.0/5'::iprange as r) s; select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '240.0.0.0/4'::iprange as r) s; select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '224.0.0.0/3'::iprange as r) s; select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '192.0.0.0/2'::iprange as r) s; select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '128.0.0.0/1'::iprange as r) s; select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '0.0.0.0/0'::iprange as r) s; select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '1.2.3.4-5.6.7.8'::iprange as r) s; select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '5.6.7.8-1.2.3.4'::iprange as r) s; select r::text, r::ip4r::text, lower(r)::ip4::text, upper(r::ip4r)::text from (select '1.2.3.4-1.2.3.4'::iprange as r) s; select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select '::'::iprange as r) s; select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'::iprange as r) s; select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select '1::2'::iprange as r) s; select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select '::-ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'::iprange as r) s; select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff-::'::iprange as r) s; select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select '1::2-3::4'::iprange as r) s; select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select '3::4-3::4'::iprange as r) s; select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select '3::4-1::2'::iprange as r) s; select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128'::iprange as r) s; select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffe/127'::iprange as r) s; select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffc/126'::iprange as r) s; select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:fff8/125'::iprange as r) s; select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:fff0/124'::iprange as r) s; select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ff00/120'::iprange as r) s; select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:f000/116'::iprange as r) s; select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:0000/112'::iprange as r) s; select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'ffff:ffff:ffff:ffff:ffff:ffff:0000:0000/96'::iprange as r) s; select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'ffff:ffff:ffff:ffff:ffff:0000:0000:0000/80'::iprange as r) s; select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'ffff:ffff:ffff:ffff:fff0:0000:0000:0000/76'::iprange as r) s; select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'ffff:ffff:ffff:ffff:ff00:0000:0000:0000/72'::iprange as r) s; select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'ffff:ffff:ffff:ffff:f000:0000:0000:0000/68'::iprange as r) s; select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'ffff:ffff:ffff:ffff:e000:0000:0000:0000/67'::iprange as r) s; select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'ffff:ffff:ffff:ffff:c000:0000:0000:0000/66'::iprange as r) s; select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'ffff:ffff:ffff:ffff:8000:0000:0000:0000/65'::iprange as r) s; select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'ffff:ffff:ffff:ffff:0000:0000:0000:0000/64'::iprange as r) s; select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'ffff:ffff:ffff:fffe:0000:0000:0000:0000/63'::iprange as r) s; select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'ffff:ffff:ffff:fffc:0000:0000:0000:0000/62'::iprange as r) s; select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'ffff:ffff:ffff:fff8:0000:0000:0000:0000/61'::iprange as r) s; select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'ffff:ffff:ffff:fff0:0000:0000:0000:0000/60'::iprange as r) s; select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'ffff:ffff:ffff:ff00:0000:0000:0000:0000/56'::iprange as r) s; select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'ffff:ffff:ffff:f000:0000:0000:0000:0000/52'::iprange as r) s; select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'ffff:ffff:ffff:0000:0000:0000:0000:0000/48'::iprange as r) s; select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'ffff:ffff:0000:0000:0000:0000:0000:0000/32'::iprange as r) s; select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'ffff:0000:0000:0000:0000:0000:0000:0000/16'::iprange as r) s; select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'fff0:0000:0000:0000:0000:0000:0000:0000/12'::iprange as r) s; select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'ff00:0000:0000:0000:0000:0000:0000:0000/8'::iprange as r) s; select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'f000:0000:0000:0000:0000:0000:0000:0000/4'::iprange as r) s; select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'e000:0000:0000:0000:0000:0000:0000:0000/3'::iprange as r) s; select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select 'c000:0000:0000:0000:0000:0000:0000:0000/2'::iprange as r) s; select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select '8000:0000:0000:0000:0000:0000:0000:0000/1'::iprange as r) s; select r::text, r::ip6r::text, lower(r)::ip6::text, upper(r::ip6r)::text from (select '0000:0000:0000:0000:0000:0000:0000:0000/0'::iprange as r) s; select a::ipaddress, a::ip4 from (select '1.2.3.4'::text as a) s1; select a::ipaddress, a::ip4 from (select '0.0.0.0'::text as a) s1; select a::ipaddress, a::ip4 from (select '255.255.255.255'::text as a) s1; select a::ipaddress, a::ip4 from (select '0.0.0.255'::text as a) s1; select a::ipaddress, a::ip4 from (select '0.0.255.0'::text as a) s1; select a::ipaddress, a::ip4 from (select '0.255.0.0'::text as a) s1; select a::ipaddress, a::ip4 from (select '255.0.0.0'::text as a) s1; select a::ipaddress, a::ip4 from (select '192.168.123.210'::text as a) s1; select a::ipaddress, a::ip4 from (select '127.0.0.1'::text as a) s1; select a::ipaddress, a::ip6 from (select '0000:0000:0000:0000:0000:0000:0000:0000'::text as a) s1; select a::ipaddress, a::ip6 from (select '0000:0000:0000:0000:0000:0000:0000:0001'::text as a) s1; select a::ipaddress, a::ip6 from (select '0:0:0:0:0:0:0:0'::text as a) s1; select a::ipaddress, a::ip6 from (select '0:0:0:0:0:0:0:1'::text as a) s1; select a::ipaddress, a::ip6 from (select '0:0:0:0:0:0:13.1.68.3'::text as a) s1; select a::ipaddress, a::ip6 from (select '0:0:0:0:0:FFFF:129.144.52.38'::text as a) s1; select a::ipaddress, a::ip6 from (select '0::0'::text as a) s1; select a::ipaddress, a::ip6 from (select '1:2:3:4:5:6:1.2.3.4'::text as a) s1; select a::ipaddress, a::ip6 from (select '1:2:3:4:5:6:7:8'::text as a) s1; select a::ipaddress, a::ip6 from (select '1:2:3:4:5:6::'::text as a) s1; select a::ipaddress, a::ip6 from (select '1:2:3:4:5:6::8'::text as a) s1; select a::ipaddress, a::ip6 from (select '1:2:3:4:5::'::text as a) s1; select a::ipaddress, a::ip6 from (select '1:2:3:4:5::1.2.3.4'::text as a) s1; select a::ipaddress, a::ip6 from (select '1:2:3:4:5::7:8'::text as a) s1; select a::ipaddress, a::ip6 from (select '1:2:3:4:5::8'::text as a) s1; select a::ipaddress, a::ip6 from (select '1:2:3:4::'::text as a) s1; select a::ipaddress, a::ip6 from (select '1:2:3:4::1.2.3.4'::text as a) s1; select a::ipaddress, a::ip6 from (select '1:2:3:4::5:1.2.3.4'::text as a) s1; select a::ipaddress, a::ip6 from (select '1:2:3:4::7:8'::text as a) s1; select a::ipaddress, a::ip6 from (select '1:2:3:4::8'::text as a) s1; select a::ipaddress, a::ip6 from (select '1:2:3::'::text as a) s1; select a::ipaddress, a::ip6 from (select '1:2:3::1.2.3.4'::text as a) s1; select a::ipaddress, a::ip6 from (select '1:2:3::5:1.2.3.4'::text as a) s1; select a::ipaddress, a::ip6 from (select '1:2:3::7:8'::text as a) s1; select a::ipaddress, a::ip6 from (select '1:2:3::8'::text as a) s1; select a::ipaddress, a::ip6 from (select '1:2::'::text as a) s1; select a::ipaddress, a::ip6 from (select '1:2::1.2.3.4'::text as a) s1; select a::ipaddress, a::ip6 from (select '1:2::5:1.2.3.4'::text as a) s1; select a::ipaddress, a::ip6 from (select '1:2::7:8'::text as a) s1; select a::ipaddress, a::ip6 from (select '1:2::8'::text as a) s1; select a::ipaddress, a::ip6 from (select '1::'::text as a) s1; select a::ipaddress, a::ip6 from (select '1::1.2.3.4'::text as a) s1; select a::ipaddress, a::ip6 from (select '1::2:3'::text as a) s1; select a::ipaddress, a::ip6 from (select '1::2:3:4'::text as a) s1; select a::ipaddress, a::ip6 from (select '1::2:3:4:5'::text as a) s1; select a::ipaddress, a::ip6 from (select '1::2:3:4:5:6'::text as a) s1; select a::ipaddress, a::ip6 from (select '1::2:3:4:5:6:7'::text as a) s1; select a::ipaddress, a::ip6 from (select '1::5:1.2.3.4'::text as a) s1; select a::ipaddress, a::ip6 from (select '1::5:11.22.33.44'::text as a) s1; select a::ipaddress, a::ip6 from (select '1::7:8'::text as a) s1; select a::ipaddress, a::ip6 from (select '1::8'::text as a) s1; select a::ipaddress, a::ip6 from (select '2001:0000:1234:0000:0000:C1C0:ABCD:0876'::text as a) s1; select a::ipaddress, a::ip6 from (select '2001:0db8:0000:0000:0000:0000:1428:57ab'::text as a) s1; select a::ipaddress, a::ip6 from (select '2001:0db8:0000:0000:0000::1428:57ab'::text as a) s1; select a::ipaddress, a::ip6 from (select '2001:0db8:0:0:0:0:1428:57ab'::text as a) s1; select a::ipaddress, a::ip6 from (select '2001:0db8:0:0::1428:57ab'::text as a) s1; select a::ipaddress, a::ip6 from (select '2001:0db8:1234:0000:0000:0000:0000:0000'::text as a) s1; select a::ipaddress, a::ip6 from (select '2001:0db8:1234::'::text as a) s1; select a::ipaddress, a::ip6 from (select '2001:0db8:1234:ffff:ffff:ffff:ffff:ffff'::text as a) s1; select a::ipaddress, a::ip6 from (select '2001:0db8:85a3:0000:0000:8a2e:0370:7334'::text as a) s1; select a::ipaddress, a::ip6 from (select '2001:0db8::1428:57ab'::text as a) s1; select a::ipaddress, a::ip6 from (select '2001:10::'::text as a) s1; select a::ipaddress, a::ip6 from (select '2001::'::text as a) s1; select a::ipaddress, a::ip6 from (select '2001:DB8:0:0:8:800:200C:417A'::text as a) s1; select a::ipaddress, a::ip6 from (select '2001:DB8::8:800:200C:417A'::text as a) s1; select a::ipaddress, a::ip6 from (select '2001:db8:85a3:0:0:8a2e:370:7334'::text as a) s1; select a::ipaddress, a::ip6 from (select '2001:db8:85a3::8a2e:370:7334'::text as a) s1; select a::ipaddress, a::ip6 from (select '2001:db8::'::text as a) s1; select a::ipaddress, a::ip6 from (select '2001:db8::'::text as a) s1; select a::ipaddress, a::ip6 from (select '2001:db8::1428:57ab'::text as a) s1; select a::ipaddress, a::ip6 from (select '2001:db8:a::123'::text as a) s1; select a::ipaddress, a::ip6 from (select '2002::'::text as a) s1; select a::ipaddress, a::ip6 from (select '2::10'::text as a) s1; select a::ipaddress, a::ip6 from (select '3ffe:0b00:0000:0000:0001:0000:0000:000a'::text as a) s1; select a::ipaddress, a::ip6 from (select '::'::text as a) s1; select a::ipaddress, a::ip6 from (select '::1'::text as a) s1; select a::ipaddress, a::ip6 from (select '::127.0.0.1'::text as a) s1; select a::ipaddress, a::ip6 from (select '::13.1.68.3'::text as a) s1; select a::ipaddress, a::ip6 from (select '::2:3'::text as a) s1; select a::ipaddress, a::ip6 from (select '::2:3:4'::text as a) s1; select a::ipaddress, a::ip6 from (select '::2:3:4:5'::text as a) s1; select a::ipaddress, a::ip6 from (select '::2:3:4:5:6'::text as a) s1; select a::ipaddress, a::ip6 from (select '::2:3:4:5:6:7'::text as a) s1; select a::ipaddress, a::ip6 from (select '::2:3:4:5:6:7:8'::text as a) s1; select a::ipaddress, a::ip6 from (select '::8'::text as a) s1; select a::ipaddress, a::ip6 from (select '::FFFF:129.144.52.38'::text as a) s1; select a::ipaddress, a::ip6 from (select '::ffff:0:0'::text as a) s1; select a::ipaddress, a::ip6 from (select '::ffff:0:192.168.1.1'::text as a) s1; select a::ipaddress, a::ip6 from (select '::ffff:1:1.2.3.4'::text as a) s1; select a::ipaddress, a::ip6 from (select '::ffff:0c22:384e'::text as a) s1; select a::ipaddress, a::ip6 from (select '::ffff:12.34.56.78'::text as a) s1; select a::ipaddress, a::ip6 from (select '::ffff:192.0.2.128'::text as a) s1; select a::ipaddress, a::ip6 from (select '::ffff:192.168.1.1'::text as a) s1; select a::ipaddress, a::ip6 from (select '::ffff:192.168.1.26'::text as a) s1; select a::ipaddress, a::ip6 from (select '::ffff:c000:280'::text as a) s1; select a::ipaddress, a::ip6 from (select 'FF01:0:0:0:0:0:0:101'::text as a) s1; select a::ipaddress, a::ip6 from (select 'FF01::101'::text as a) s1; select a::ipaddress, a::ip6 from (select 'FF02:0000:0000:0000:0000:0000:0000:0001'::text as a) s1; select a::ipaddress, a::ip6 from (select 'fc00::'::text as a) s1; select a::ipaddress, a::ip6 from (select 'fe80:0000:0000:0000:0204:61ff:fe9d:f156'::text as a) s1; select a::ipaddress, a::ip6 from (select 'fe80:0:0:0:204:61ff:254.157.241.86'::text as a) s1; select a::ipaddress, a::ip6 from (select 'fe80:0:0:0:204:61ff:fe9d:f156'::text as a) s1; select a::ipaddress, a::ip6 from (select 'fe80::'::text as a) s1; select a::ipaddress, a::ip6 from (select 'fe80::1'::text as a) s1; select a::ipaddress, a::ip6 from (select 'fe80::204:61ff:254.157.241.86'::text as a) s1; select a::ipaddress, a::ip6 from (select 'fe80::204:61ff:fe9d:f156'::text as a) s1; select a::ipaddress, a::ip6 from (select 'fe80::217:f2ff:254.7.237.98'::text as a) s1; select a::ipaddress, a::ip6 from (select 'fe80::217:f2ff:fe07:ed62'::text as a) s1; select a::ipaddress, a::ip6 from (select 'ff02::1'::text as a) s1; select r::iprange from (select '-'::text as r) s; select r::iprange, r::ip4r from (select '1.2.3.4'::text as r) s; select r::iprange, r::ip4r from (select '255.255.255.255/32'::text as r) s; select r::iprange, r::ip4r from (select '255.255.255.254/31'::text as r) s; select r::iprange, r::ip4r from (select '255.255.255.252/30'::text as r) s; select r::iprange, r::ip4r from (select '255.255.255.248/29'::text as r) s; select r::iprange, r::ip4r from (select '255.255.255.240/28'::text as r) s; select r::iprange, r::ip4r from (select '255.255.255.224/27'::text as r) s; select r::iprange, r::ip4r from (select '255.255.255.192/26'::text as r) s; select r::iprange, r::ip4r from (select '255.255.255.128/25'::text as r) s; select r::iprange, r::ip4r from (select '255.255.255.0/24'::text as r) s; select r::iprange, r::ip4r from (select '255.255.254.0/23'::text as r) s; select r::iprange, r::ip4r from (select '255.255.252.0/22'::text as r) s; select r::iprange, r::ip4r from (select '255.255.248.0/21'::text as r) s; select r::iprange, r::ip4r from (select '255.255.240.0/20'::text as r) s; select r::iprange, r::ip4r from (select '255.255.224.0/19'::text as r) s; select r::iprange, r::ip4r from (select '255.255.192.0/18'::text as r) s; select r::iprange, r::ip4r from (select '255.255.128.0/17'::text as r) s; select r::iprange, r::ip4r from (select '255.255.0.0/16'::text as r) s; select r::iprange, r::ip4r from (select '255.254.0.0/15'::text as r) s; select r::iprange, r::ip4r from (select '255.252.0.0/14'::text as r) s; select r::iprange, r::ip4r from (select '255.248.0.0/13'::text as r) s; select r::iprange, r::ip4r from (select '255.240.0.0/12'::text as r) s; select r::iprange, r::ip4r from (select '255.224.0.0/11'::text as r) s; select r::iprange, r::ip4r from (select '255.192.0.0/10'::text as r) s; select r::iprange, r::ip4r from (select '255.128.0.0/9'::text as r) s; select r::iprange, r::ip4r from (select '255.0.0.0/8'::text as r) s; select r::iprange, r::ip4r from (select '254.0.0.0/7'::text as r) s; select r::iprange, r::ip4r from (select '252.0.0.0/6'::text as r) s; select r::iprange, r::ip4r from (select '248.0.0.0/5'::text as r) s; select r::iprange, r::ip4r from (select '240.0.0.0/4'::text as r) s; select r::iprange, r::ip4r from (select '224.0.0.0/3'::text as r) s; select r::iprange, r::ip4r from (select '192.0.0.0/2'::text as r) s; select r::iprange, r::ip4r from (select '128.0.0.0/1'::text as r) s; select r::iprange, r::ip4r from (select '0.0.0.0/0'::text as r) s; select r::iprange, r::ip4r from (select '1.2.3.4-5.6.7.8'::text as r) s; select r::iprange, r::ip4r from (select '5.6.7.8-1.2.3.4'::text as r) s; select r::iprange, r::ip4r from (select '1.2.3.4-1.2.3.4'::text as r) s; select r::iprange, r::ip6r from (select '::'::text as r) s; select r::iprange, r::ip6r from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'::text as r) s; select r::iprange, r::ip6r from (select '1::2'::text as r) s; select r::iprange, r::ip6r from (select '::-ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'::text as r) s; select r::iprange, r::ip6r from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff-::'::text as r) s; select r::iprange, r::ip6r from (select '1::2-3::4'::text as r) s; select r::iprange, r::ip6r from (select '3::4-3::4'::text as r) s; select r::iprange, r::ip6r from (select '3::4-1::2'::text as r) s; select r::iprange, r::ip6r from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128'::text as r) s; select r::iprange, r::ip6r from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffe/127'::text as r) s; select r::iprange, r::ip6r from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffc/126'::text as r) s; select r::iprange, r::ip6r from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:fff8/125'::text as r) s; select r::iprange, r::ip6r from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:fff0/124'::text as r) s; select r::iprange, r::ip6r from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ff00/120'::text as r) s; select r::iprange, r::ip6r from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:f000/116'::text as r) s; select r::iprange, r::ip6r from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:0000/112'::text as r) s; select r::iprange, r::ip6r from (select 'ffff:ffff:ffff:ffff:ffff:ffff:0000:0000/96'::text as r) s; select r::iprange, r::ip6r from (select 'ffff:ffff:ffff:ffff:ffff:0000:0000:0000/80'::text as r) s; select r::iprange, r::ip6r from (select 'ffff:ffff:ffff:ffff:fff0:0000:0000:0000/76'::text as r) s; select r::iprange, r::ip6r from (select 'ffff:ffff:ffff:ffff:ff00:0000:0000:0000/72'::text as r) s; select r::iprange, r::ip6r from (select 'ffff:ffff:ffff:ffff:f000:0000:0000:0000/68'::text as r) s; select r::iprange, r::ip6r from (select 'ffff:ffff:ffff:ffff:e000:0000:0000:0000/67'::text as r) s; select r::iprange, r::ip6r from (select 'ffff:ffff:ffff:ffff:c000:0000:0000:0000/66'::text as r) s; select r::iprange, r::ip6r from (select 'ffff:ffff:ffff:ffff:8000:0000:0000:0000/65'::text as r) s; select r::iprange, r::ip6r from (select 'ffff:ffff:ffff:ffff:0000:0000:0000:0000/64'::text as r) s; select r::iprange, r::ip6r from (select 'ffff:ffff:ffff:fffe:0000:0000:0000:0000/63'::text as r) s; select r::iprange, r::ip6r from (select 'ffff:ffff:ffff:fffc:0000:0000:0000:0000/62'::text as r) s; select r::iprange, r::ip6r from (select 'ffff:ffff:ffff:fff8:0000:0000:0000:0000/61'::text as r) s; select r::iprange, r::ip6r from (select 'ffff:ffff:ffff:fff0:0000:0000:0000:0000/60'::text as r) s; select r::iprange, r::ip6r from (select 'ffff:ffff:ffff:ff00:0000:0000:0000:0000/56'::text as r) s; select r::iprange, r::ip6r from (select 'ffff:ffff:ffff:f000:0000:0000:0000:0000/52'::text as r) s; select r::iprange, r::ip6r from (select 'ffff:ffff:ffff:0000:0000:0000:0000:0000/48'::text as r) s; select r::iprange, r::ip6r from (select 'ffff:ffff:0000:0000:0000:0000:0000:0000/32'::text as r) s; select r::iprange, r::ip6r from (select 'ffff:0000:0000:0000:0000:0000:0000:0000/16'::text as r) s; select r::iprange, r::ip6r from (select 'fff0:0000:0000:0000:0000:0000:0000:0000/12'::text as r) s; select r::iprange, r::ip6r from (select 'ff00:0000:0000:0000:0000:0000:0000:0000/8'::text as r) s; select r::iprange, r::ip6r from (select 'f000:0000:0000:0000:0000:0000:0000:0000/4'::text as r) s; select r::iprange, r::ip6r from (select 'e000:0000:0000:0000:0000:0000:0000:0000/3'::text as r) s; select r::iprange, r::ip6r from (select 'c000:0000:0000:0000:0000:0000:0000:0000/2'::text as r) s; select r::iprange, r::ip6r from (select '8000:0000:0000:0000:0000:0000:0000:0000/1'::text as r) s; select r::iprange, r::ip6r from (select '0000:0000:0000:0000:0000:0000:0000:0000/0'::text as r) s; -- invalid text casts select '1.2.3'::text::ip4; select '0'::text::ip4; select ' 1.2.3.4'::text::ip4; select '1.2.3.4 '::text::ip4; select '0.0.0.256'::text::ip4; select '0.0.256'::text::ip4; select '0..255.0'::text::ip4; select '+0.255.0.0'::text::ip4; select '1.2.3.4-1.2.3.4'::text::ip4; select '1.2.3'::text::ip4r; select '255.255.255.255.255.255.255.255.255'::text::ip4r; select '255.255.255.255.255-255.255.255.255.255'::text::ip4r; select '255.255.255.255-1.2.3.4.5'::text::ip4r; select '255.255.255.255-1.2.3'::text::ip4r; select '0.0.0.1/31'::text::ip4r; select '0.0.0.1/30'::text::ip4r; select '0.0.0.1/29'::text::ip4r; select '0.0.0.1/28'::text::ip4r; select '0.0.0.1/27'::text::ip4r; select '0.0.0.1/26'::text::ip4r; select '0.0.0.1/25'::text::ip4r; select '0.0.0.1/24'::text::ip4r; select '0.0.0.1/23'::text::ip4r; select '0.0.0.1/22'::text::ip4r; select '0.0.0.1/21'::text::ip4r; select '0.0.0.1/20'::text::ip4r; select '0.0.0.1/19'::text::ip4r; select '0.0.0.1/18'::text::ip4r; select '0.0.0.1/17'::text::ip4r; select '0.0.0.1/16'::text::ip4r; select '0.0.0.1/15'::text::ip4r; select '0.0.0.1/14'::text::ip4r; select '0.0.0.1/13'::text::ip4r; select '0.0.0.1/12'::text::ip4r; select '0.0.0.1/11'::text::ip4r; select '0.0.0.1/10'::text::ip4r; select '0.0.0.1/9'::text::ip4r; select '0.0.0.1/8'::text::ip4r; select '0.0.0.1/7'::text::ip4r; select '0.0.0.1/6'::text::ip4r; select '0.0.0.1/5'::text::ip4r; select '0.0.0.1/4'::text::ip4r; select '0.0.0.1/3'::text::ip4r; select '0.0.0.1/2'::text::ip4r; select '0.0.0.1/1'::text::ip4r; select '0.0.0.1/0'::text::ip4r; select '0.0.0.2/30'::text::ip4r; select '0.0.0.4/29'::text::ip4r; select '0.0.0.8/28'::text::ip4r; select '0.0.0.16/27'::text::ip4r; select '0.0.0.32/26'::text::ip4r; select '0.0.0.64/25'::text::ip4r; select '0.0.0.128/24'::text::ip4r; select '0.0.1.0/23'::text::ip4r; select '0.0.2.0/22'::text::ip4r; select '0.0.4.0/21'::text::ip4r; select '0.0.8.0/20'::text::ip4r; select '0.0.16.0/19'::text::ip4r; select '0.0.32.0/18'::text::ip4r; select '0.0.64.0/17'::text::ip4r; select '0.0.128.0/16'::text::ip4r; select '0.1.0.0/15'::text::ip4r; select '0.2.0.0/14'::text::ip4r; select '0.4.0.0/13'::text::ip4r; select '0.8.0.0/12'::text::ip4r; select '0.16.0.0/11'::text::ip4r; select '0.32.0.0/10'::text::ip4r; select '0.64.0.0/9'::text::ip4r; select '0.128.0.0/8'::text::ip4r; select '1.0.0.0/7'::text::ip4r; select '2.0.0.0/6'::text::ip4r; select '4.0.0.0/5'::text::ip4r; select '8.0.0.0/4'::text::ip4r; select '16.0.0.0/3'::text::ip4r; select '32.0.0.0/2'::text::ip4r; select '64.0.0.0/1'::text::ip4r; select '128.0.0.0/0'::text::ip4r; select '0.0.0.0/33'::text::ip4r; select '0.0.0.0/3.0'::text::ip4r; select '0.0.0.0/+33'::text::ip4r; select ''::text::ip6; select '02001:0000:1234:0000:0000:C1C0:ABCD:0876'::text::ip6; select '1.2.3.4:1111:2222:3333:4444::5555'::text::ip6; select '1.2.3.4:1111:2222:3333::5555'::text::ip6; select '1.2.3.4:1111:2222::5555'::text::ip6; select '1.2.3.4:1111::5555'::text::ip6; select '1.2.3.4::'::text::ip6; select '1.2.3.4::5555'::text::ip6; select '1111:'::text::ip6; select '1111:2222:3333:4444::5555:'::text::ip6; select '1111:2222:3333::5555:'::text::ip6; select '1111:2222::5555:'::text::ip6; select '1111::5555:'::text::ip6; select '123'::text::ip6; select '12345::6:7:8'::text::ip6; select '127.0.0.1'::text::ip6; select '1:2:3:4:5:6:7:8:9'::text::ip6; select '1:2:3::4:5:6:7:8:9'::text::ip6; select '1:2:3::4:5::7:8'::text::ip6; select '1::1.2.256.4'::text::ip6; select '1::1.2.3.256'::text::ip6; select '1::1.2.3.300'::text::ip6; select '1::1.2.3.900'::text::ip6; select '1::1.2.300.4'::text::ip6; select '1::1.2.900.4'::text::ip6; select '1::1.256.3.4'::text::ip6; select '1::1.300.3.4'::text::ip6; select '1::1.900.3.4'::text::ip6; select '1::256.2.3.4'::text::ip6; select '1::260.2.3.4'::text::ip6; select '1::2::3'::text::ip6; select '1::300.2.3.4'::text::ip6; select '1::300.300.300.300'::text::ip6; select '1::3000.30.30.30'::text::ip6; select '1::400.2.3.4'::text::ip6; select '1::5:1.2.256.4'::text::ip6; select '1::5:1.2.3.256'::text::ip6; select '1::5:1.2.3.300'::text::ip6; select '1::5:1.2.3.900'::text::ip6; select '1::5:1.2.300.4'::text::ip6; select '1::5:1.2.900.4'::text::ip6; select '1::5:1.256.3.4'::text::ip6; select '1::5:1.300.3.4'::text::ip6; select '1::5:1.900.3.4'::text::ip6; select '1::5:256.2.3.4'::text::ip6; select '1::5:260.2.3.4'::text::ip6; select '1::5:300.2.3.4'::text::ip6; select '1::5:300.300.300.300'::text::ip6; select '1::5:3000.30.30.30'::text::ip6; select '1::5:400.2.3.4'::text::ip6; select '1::5:900.2.3.4'::text::ip6; select '1::900.2.3.4'::text::ip6; select '1:::3:4:5'::text::ip6; select '2001:0000:1234: 0000:0000:C1C0:ABCD:0876'::text::ip6; select '2001:0000:1234:0000:00001:C1C0:ABCD:0876'::text::ip6; select '2001:0000:1234:0000:0000:C1C0:ABCD:0876 0'::text::ip6; select '2001::FFD3::57ab'::text::ip6; select '2001:DB8:0:0:8:800:200C:417A:221'::text::ip6; select '2001:db8:85a3::8a2e:37023:7334'::text::ip6; select '2001:db8:85a3::8a2e:370k:7334'::text::ip6; select '3ffe:0b00:0000:0001:0000:0000:000a'::text::ip6; select '3ffe:b00::1::a'::text::ip6; select ':'::text::ip6; select ':1111:2222:3333:4444::5555'::text::ip6; select ':1111:2222:3333::5555'::text::ip6; select ':1111:2222::5555'::text::ip6; select ':1111::5555'::text::ip6; select '::1.2.256.4'::text::ip6; select '::1.2.3.256'::text::ip6; select '::1.2.3.300'::text::ip6; select '::1.2.3.900'::text::ip6; select '::1.2.300.4'::text::ip6; select '::1.2.900.4'::text::ip6; select '::1.256.3.4'::text::ip6; select '::1.300.3.4'::text::ip6; select '::1.900.3.4'::text::ip6; select '::1111:2222:3333:4444:5555:6666::'::text::ip6; select '::256.2.3.4'::text::ip6; select '::260.2.3.4'::text::ip6; select '::300.2.3.4'::text::ip6; select '::300.300.300.300'::text::ip6; select '::3000.30.30.30'::text::ip6; select '::400.2.3.4'::text::ip6; select '::5555:'::text::ip6; select '::900.2.3.4'::text::ip6; select ':::'::text::ip6; select ':::5555'::text::ip6; select '::ffff:2.3.4'::text::ip6; select '::ffff:257.1.2.3'::text::ip6; select 'FF01::101::2'::text::ip6; select 'FF02:0000:0000:0000:0000:0000:0000:0000:0001'::text::ip6; select 'ldkfj'::text::ip6; select '::-::-::'::text::ip6r; select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff-ffff'::text::ip6r; select '::-ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'::text::ip6r; select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff-::'::text::ip6r; select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128'::text::ip6r; select '0000:0000:0000:0000:0000:0000:0000:0001/127'::text::ip6r; select '0000:0000:0000:0000:0000:0000:0000:0001/120'::text::ip6r; select '0000:0000:0000:0000:0000:0000:0000:0001/112'::text::ip6r; select '0000:0000:0000:0000:0000:0000:0000:0001/96'::text::ip6r; select '0000:0000:0000:0000:0000:0000:0000:0001/80'::text::ip6r; select '0000:0000:0000:0000:0000:0000:0000:0001/64'::text::ip6r; select '0000:0000:0000:0000:0000:0000:0000:0001/48'::text::ip6r; select '0000:0000:0000:0000:0000:0000:0000:0001/32'::text::ip6r; select '0000:0000:0000:0000:0000:0000:0000:0001/16'::text::ip6r; select '0000:0000:0000:0000:0000:0000:0000:0001/8'::text::ip6r; select '0000:0000:0000:0000:0000:0000:0000:0001/4'::text::ip6r; select '0000:0000:0000:0000:0000:0000:0000:0001/0'::text::ip6r; select '0000:0000:0000:0000:0000:0000:0000:0008/124'::text::ip6r; select '0000:0000:0000:0000:0000:0000:0000:0080/120'::text::ip6r; select '0000:0000:0000:0000:0000:0000:0000:8000/112'::text::ip6r; select '0000:0000:0000:0000:0000:0000:8000:0000/96'::text::ip6r; select '0000:0000:0000:0000:0000:8000:0000:0000/80'::text::ip6r; select '0000:0000:0000:0000:8000:0000:0000:0000/64'::text::ip6r; select '0000:0000:0000:8000:0000:0000:0000:0000/48'::text::ip6r; select '0000:0000:8000:0000:0000:0000:0000:0000/32'::text::ip6r; select '0000:8000:0000:0000:0000:0000:0000:0000/16'::text::ip6r; select '0080:0000:0000:0000:0000:0000:0000:0000/8'::text::ip6r; select '0800:0000:0000:0000:0000:0000:0000:0000/4'::text::ip6r; select '8000:0000:0000:0000:0000:0000:0000:0000/0'::text::ip6r; select '::/129'::text::ip6r; select '::/255'::text::ip6r; select '::/256'::text::ip6r; select '::/+0'::text::ip6r; select '::/0-0'::text::ip6r; select '::-::/0'::text::ip6r; select '1.2.3'::text::ipaddress; select '0'::text::ipaddress; select ' 1.2.3.4'::text::ipaddress; select '1.2.3.4 '::text::ipaddress; select '0.0.0.256'::text::ipaddress; select '0.0.256'::text::ipaddress; select '0..255.0'::text::ipaddress; select '+0.255.0.0'::text::ipaddress; select '1.2.3.4-1.2.3.4'::text::ipaddress; select ''::text::ipaddress; select '02001:0000:1234:0000:0000:C1C0:ABCD:0876'::text::ipaddress; select '1.2.3.4:1111:2222:3333:4444::5555'::text::ipaddress; select '1.2.3.4:1111:2222:3333::5555'::text::ipaddress; select '1.2.3.4:1111:2222::5555'::text::ipaddress; select '1.2.3.4:1111::5555'::text::ipaddress; select '1.2.3.4::'::text::ipaddress; select '1.2.3.4::5555'::text::ipaddress; select '1111:'::text::ipaddress; select '1111:2222:3333:4444::5555:'::text::ipaddress; select '1111:2222:3333::5555:'::text::ipaddress; select '1111:2222::5555:'::text::ipaddress; select '1111::5555:'::text::ipaddress; select '123'::text::ipaddress; select '12345::6:7:8'::text::ipaddress; select '1:2:3:4:5:6:7:8:9'::text::ipaddress; select '1:2:3::4:5:6:7:8:9'::text::ipaddress; select '1:2:3::4:5::7:8'::text::ipaddress; select '1::1.2.256.4'::text::ipaddress; select '1::1.2.3.256'::text::ipaddress; select '1::1.2.3.300'::text::ipaddress; select '1::1.2.3.900'::text::ipaddress; select '1::1.2.300.4'::text::ipaddress; select '1::1.2.900.4'::text::ipaddress; select '1::1.256.3.4'::text::ipaddress; select '1::1.300.3.4'::text::ipaddress; select '1::1.900.3.4'::text::ipaddress; select '1::256.2.3.4'::text::ipaddress; select '1::260.2.3.4'::text::ipaddress; select '1::2::3'::text::ipaddress; select '1::300.2.3.4'::text::ipaddress; select '1::300.300.300.300'::text::ipaddress; select '1::3000.30.30.30'::text::ipaddress; select '1::400.2.3.4'::text::ipaddress; select '1::5:1.2.256.4'::text::ipaddress; select '1::5:1.2.3.256'::text::ipaddress; select '1::5:1.2.3.300'::text::ipaddress; select '1::5:1.2.3.900'::text::ipaddress; select '1::5:1.2.300.4'::text::ipaddress; select '1::5:1.2.900.4'::text::ipaddress; select '1::5:1.256.3.4'::text::ipaddress; select '1::5:1.300.3.4'::text::ipaddress; select '1::5:1.900.3.4'::text::ipaddress; select '1::5:256.2.3.4'::text::ipaddress; select '1::5:260.2.3.4'::text::ipaddress; select '1::5:300.2.3.4'::text::ipaddress; select '1::5:300.300.300.300'::text::ipaddress; select '1::5:3000.30.30.30'::text::ipaddress; select '1::5:400.2.3.4'::text::ipaddress; select '1::5:900.2.3.4'::text::ipaddress; select '1::900.2.3.4'::text::ipaddress; select '1:::3:4:5'::text::ipaddress; select '2001:0000:1234: 0000:0000:C1C0:ABCD:0876'::text::ipaddress; select '2001:0000:1234:0000:00001:C1C0:ABCD:0876'::text::ipaddress; select '2001:0000:1234:0000:0000:C1C0:ABCD:0876 0'::text::ipaddress; select '2001::FFD3::57ab'::text::ipaddress; select '2001:DB8:0:0:8:800:200C:417A:221'::text::ipaddress; select '2001:db8:85a3::8a2e:37023:7334'::text::ipaddress; select '2001:db8:85a3::8a2e:370k:7334'::text::ipaddress; select '3ffe:0b00:0000:0001:0000:0000:000a'::text::ipaddress; select '3ffe:b00::1::a'::text::ipaddress; select ':'::text::ipaddress; select ':1111:2222:3333:4444::5555'::text::ipaddress; select ':1111:2222:3333::5555'::text::ipaddress; select ':1111:2222::5555'::text::ipaddress; select ':1111::5555'::text::ipaddress; select '::1.2.256.4'::text::ipaddress; select '::1.2.3.256'::text::ipaddress; select '::1.2.3.300'::text::ipaddress; select '::1.2.3.900'::text::ipaddress; select '::1.2.300.4'::text::ipaddress; select '::1.2.900.4'::text::ipaddress; select '::1.256.3.4'::text::ipaddress; select '::1.300.3.4'::text::ipaddress; select '::1.900.3.4'::text::ipaddress; select '::1111:2222:3333:4444:5555:6666::'::text::ipaddress; select '::256.2.3.4'::text::ipaddress; select '::260.2.3.4'::text::ipaddress; select '::300.2.3.4'::text::ipaddress; select '::300.300.300.300'::text::ipaddress; select '::3000.30.30.30'::text::ipaddress; select '::400.2.3.4'::text::ipaddress; select '::5555:'::text::ipaddress; select '::900.2.3.4'::text::ipaddress; select ':::'::text::ipaddress; select ':::5555'::text::ipaddress; select '::ffff:2.3.4'::text::ipaddress; select '::ffff:257.1.2.3'::text::ipaddress; select 'FF01::101::2'::text::ipaddress; select 'FF02:0000:0000:0000:0000:0000:0000:0000:0001'::text::ipaddress; select 'ldkfj'::text::ipaddress; -- numeric casts select n::ip4 from (select 0::bigint as n) s; select n::ip4 from (select 256::bigint as n) s; select n::ip4 from (select 65536::bigint as n) s; select n::ip4 from (select 16777216::bigint as n) s; select n::ip4 from (select -1::bigint as n) s; select n::ip4 from (select -2147483647::bigint as n) s; select n::ip4 from (select -2147483648::bigint as n) s; select n::ip4 from (select 2147483647::bigint as n) s; select n::ip4 from (select 2147483648::bigint as n) s; select n::ip4 from (select 4294967295::bigint as n) s; select n::ip4 from (select 0::float8 as n) s; select n::ip4 from (select 256::float8 as n) s; select n::ip4 from (select 65536::float8 as n) s; select n::ip4 from (select 16777216::float8 as n) s; select n::ip4 from (select -1::float8 as n) s; select n::ip4 from (select -2147483647::float8 as n) s; select n::ip4 from (select -2147483648::float8 as n) s; select n::ip4 from (select 2147483647::float8 as n) s; select n::ip4 from (select 2147483648::float8 as n) s; select n::ip4 from (select 4294967295::float8 as n) s; select n::ip4 from (select 0::numeric as n) s; select n::ip4 from (select 256::numeric as n) s; select n::ip4 from (select 65536::numeric as n) s; select n::ip4 from (select 16777216::numeric as n) s; select n::ip4 from (select -1::numeric as n) s; select n::ip4 from (select -2147483647::numeric as n) s; select n::ip4 from (select -2147483648::numeric as n) s; select n::ip4 from (select 2147483647::numeric as n) s; select n::ip4 from (select 2147483648::numeric as n) s; select n::ip4 from (select 4294967295::numeric as n) s; select n::ip6 from (select 0::numeric as n) s; select n::ip6 from (select 256::numeric as n) s; select n::ip6 from (select 65536::numeric as n) s; select n::ip6 from (select 16777216::numeric as n) s; select n::ip6 from (select 4294967296::numeric as n) s; select n::ip6 from (select 281474976710656::numeric as n) s; select n::ip6 from (select 18446744073709551616::numeric as n) s; select n::ip6 from (select 1208925819614629174706176::numeric as n) s; select n::ip6 from (select 79228162514264337593543950336::numeric as n) s; select n::ip6 from (select 5192296858534827628530496329220096::numeric as n) s; select n::ip6 from (select 170141183460469231731687303715884105728::numeric as n) s; select n::ip6 from (select 340282366920938463463374607431768211455::numeric as n) s; select a::numeric, a::ipaddress::numeric, a::bigint, a::float8 from (select '0.0.0.0'::ip4 as a) s; select a::numeric, a::ipaddress::numeric, a::bigint, a::float8 from (select '255.255.255.255'::ip4 as a) s; select a::numeric, a::ipaddress::numeric, a::bigint, a::float8 from (select '0.0.0.1'::ip4 as a) s; select a::numeric, a::ipaddress::numeric, a::bigint, a::float8 from (select '0.0.1.0'::ip4 as a) s; select a::numeric, a::ipaddress::numeric, a::bigint, a::float8 from (select '0.1.0.0'::ip4 as a) s; select a::numeric, a::ipaddress::numeric, a::bigint, a::float8 from (select '1.0.0.0'::ip4 as a) s; select a::numeric, a::ipaddress::numeric from (select '::'::ip6 as a) s; select a::numeric, a::ipaddress::numeric from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'::ip6 as a) s; select a::numeric, a::ipaddress::numeric from (select '::1'::ip6 as a) s; select a::numeric, a::ipaddress::numeric from (select '::1:0'::ip6 as a) s; select a::numeric, a::ipaddress::numeric from (select '::1:0:0'::ip6 as a) s; select a::numeric, a::ipaddress::numeric from (select '::1:0:0:0'::ip6 as a) s; select a::numeric, a::ipaddress::numeric from (select '0:0:0:1::'::ip6 as a) s; select a::numeric, a::ipaddress::numeric from (select '0:0:1::'::ip6 as a) s; select a::numeric, a::ipaddress::numeric from (select '0:1::'::ip6 as a) s; select a::numeric, a::ipaddress::numeric from (select '1::'::ip6 as a) s; -- invalid numeric casts select (-4294967295::bigint)::ip4; select (4294967296::bigint)::ip4; select 0.1::float8::ip4; select (-0.1)::float8::ip4; select (-4294967295::float8)::ip4; select (4294967296::float8)::ip4; select (-3000000000::float8)::ip4; select 6000000000::float8::ip4; select 6e10::float8::ip4; select 6e30::float8::ip4; select (-1::numeric)::ip6; select 340282366920938463463374607431768211456::numeric::ip6; select 0.1::numeric::ip6; select 0.00000000000000000001::numeric::ip6; select (-0.00000000000000000001::numeric)::ip6; -- inet/cidr casts select a::ip4, a::ipaddress from (select '0.0.0.0'::inet as a) s; select a::ip4, a::ipaddress from (select '1.2.3.4'::inet as a) s; select a::ip4, a::ipaddress from (select '255.255.255.255'::inet as a) s; select a::ip4, a::ipaddress from (select '10.20.30.40/24'::inet as a) s; select a::ip4, a::ipaddress from (select '10.20.30.40/16'::inet as a) s; select a::ip6, a::ipaddress from (select '::'::inet as a) s; select a::ip6, a::ipaddress from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'::inet as a) s; select a::ip6, a::ipaddress from (select '::1'::inet as a) s; select a::ip6, a::ipaddress from (select '1234:2345:3456:4567:5678:6789:789a:89ab'::inet as a) s; select a::ip6, a::ipaddress from (select '1234:2345:3456:4567:5678:6789:789a:89ab/96'::inet as a) s; select a::ip6, a::ipaddress from (select '1234:2345:3456:4567:5678:6789:789a:89ab/64'::inet as a) s; select a::ip6, a::ipaddress from (select '1234:2345:3456:4567:5678:6789:789a:89ab/32'::inet as a) s; select a::ip4r, a::iprange from (select '0.0.0.0/16'::cidr as a) s; select a::ip4r, a::iprange from (select '0.1.0.0/16'::cidr as a) s; select a::ip4r, a::iprange from (select '1.2.3.0/24'::cidr as a) s; select a::ip4r, a::iprange from (select '0.0.0.0/0'::cidr as a) s; select a::ip6r, a::iprange from (select '::/0'::cidr as a) s; select a::ip6r, a::iprange from (select 'ffff::/64'::cidr as a) s; select a::ip6r, a::iprange from (select '0:0:0:0:ffff::/128'::cidr as a) s; select a::ip6r, a::iprange from (select '1234:2345:3456:4567:5678:6789::/96'::cidr as a) s; select '1.2.3.4'::ip4::cidr; select '0.0.0.0'::ip4::cidr; select '255.255.255.255'::ip4::cidr; select '1.2.3.0/24'::ip4r::cidr; select '0.0.0.0/0'::ip4r::cidr; select '255.255.255.255/32'::ip4r::cidr; select '1234:2345:3456:4567:5678:6789:789a:89ab'::ip6::cidr; select '::'::ip6::cidr; select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'::ip6::cidr; select '1234:2345:3456:4567:5678:6789:789a:0000/112'::ip6r::cidr; select '::/0'::ip6r::cidr; select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128'::ip6r::cidr; select 'ffff:ffff:ffff::/48'::ip6r::cidr; select '1.2.3.4'::ipaddress::cidr; select '0.0.0.0'::ipaddress::cidr; select '255.255.255.255'::ipaddress::cidr; select '1234:2345:3456:4567:5678:6789:789a:89ab'::ipaddress::cidr; select '::'::ipaddress::cidr; select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'::ipaddress::cidr; select '1.2.3.0/24'::iprange::cidr; select '0.0.0.0/0'::iprange::cidr; select '255.255.255.255/32'::iprange::cidr; select '1234:2345:3456:4567:5678:6789:789a:0000/112'::iprange::cidr; select '::/0'::iprange::cidr; select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128'::iprange::cidr; select 'ffff:ffff:ffff::/48'::iprange::cidr; select '-'::iprange::cidr; -- invalid inet/cidr casts select '::'::inet::ip4; select '0.0.0.0'::inet::ip6; select '::/128'::cidr::ip4r; select '0.0.0.0/32'::cidr::ip6r; -- invalid cross-type casts select '::/0'::iprange::ip4r; select '0.0.0.0/0'::iprange::ip6r; select '::'::ipaddress::ip4; select '0.0.0.0'::ipaddress::ip6; -- constructor functions select ip4r('0.0.0.0','255.255.255.255'); select ip4r('255.255.255.255','0.0.0.0'); select ip4r('1.2.3.4','5.6.7.8'); select ip6r('::','ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'); select ip6r('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff','::'); select ip6r('1234:2345:3456:4567:5678:6789:789a:89ab','ffff::ffff'); select iprange('0.0.0.0'::ip4,'255.255.255.255'::ip4); select iprange('255.255.255.255'::ip4,'0.0.0.0'::ip4); select iprange('1.2.3.4'::ip4,'5.6.7.8'::ip4); select iprange('::'::ip6,'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'::ip6); select iprange('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'::ip6,'::'::ip6); select iprange('1234:2345:3456:4567:5678:6789:789a:89ab'::ip6,'ffff::ffff'::ip6); select iprange('0.0.0.0'::ipaddress,'255.255.255.255'::ipaddress); select iprange('255.255.255.255'::ipaddress,'0.0.0.0'::ipaddress); select iprange('1.2.3.4'::ipaddress,'5.6.7.8'::ipaddress); select iprange('::'::ipaddress,'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'::ipaddress); select iprange('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'::ipaddress,'::'::ipaddress); select iprange('1234:2345:3456:4567:5678:6789:789a:89ab'::ipaddress,'ffff::ffff'::ipaddress); -- utility functions -- (family, lower, upper were tested above) select ip4_netmask(0), ip4_netmask(1), ip4_netmask(31), ip4_netmask(32); select ip4_netmask(33); select ip4_netmask(-1); select ip6_netmask(0), ip6_netmask(1); select ip6_netmask(63), ip6_netmask(64), ip6_netmask(65); select ip6_netmask(127), ip6_netmask(128); select ip6_netmask(129); select ip6_netmask(-1); select is_cidr(a), is_cidr(a::iprange), masklen(a), masklen(a::iprange) from (select '1.2.3.4-5.6.7.8'::ip4r as a) s; select is_cidr(a), is_cidr(a::iprange), masklen(a), masklen(a::iprange) from (select '1.2.3.0-1.2.3.255'::ip4r as a) s; select is_cidr(a), is_cidr(a::iprange), masklen(a), masklen(a::iprange) from (select '0.0.0.0/32'::ip4r as a) s; select is_cidr(a), is_cidr(a::iprange), masklen(a), masklen(a::iprange) from (select '0.0.0.0/31'::ip4r as a) s; select is_cidr(a), is_cidr(a::iprange), masklen(a), masklen(a::iprange) from (select '0.0.0.0/1'::ip4r as a) s; select is_cidr(a), is_cidr(a::iprange), masklen(a), masklen(a::iprange) from (select '0.0.0.0/0'::ip4r as a) s; select is_cidr(a), is_cidr(a::iprange), masklen(a), masklen(a::iprange) from (select '255.255.255.255/32'::ip4r as a) s; select is_cidr(a), is_cidr(a::iprange), masklen(a), masklen(a::iprange) from (select '255.255.255.254/31'::ip4r as a) s; select is_cidr(a), is_cidr(a::iprange), masklen(a), masklen(a::iprange) from (select '128.0.0.0/1'::ip4r as a) s; select is_cidr(a), is_cidr(a::iprange), masklen(a), masklen(a::iprange) from (select '1234::-5678::ffff:0'::ip6r as a) s; select is_cidr(a), is_cidr(a::iprange), masklen(a), masklen(a::iprange) from (select '::1234-::5678'::ip6r as a) s; select is_cidr(a), is_cidr(a::iprange), masklen(a), masklen(a::iprange) from (select 'ffff::-ffff::ffff:0'::ip6r as a) s; select is_cidr(a), is_cidr(a::iprange), masklen(a), masklen(a::iprange) from (select 'ffff::-ffff::ffff'::ip6r as a) s; select is_cidr(a), is_cidr(a::iprange), masklen(a), masklen(a::iprange) from (select 'ffff::-ffff:0:0:0:ffff:ffff:ffff:ffff'::ip6r as a) s; select is_cidr(a), is_cidr(a::iprange), masklen(a), masklen(a::iprange) from (select 'ffff::-ffff:0:0:1:ffff:ffff:ffff:ffff'::ip6r as a) s; select is_cidr(a), is_cidr(a::iprange), masklen(a), masklen(a::iprange) from (select '::/128'::ip6r as a) s; select is_cidr(a), is_cidr(a::iprange), masklen(a), masklen(a::iprange) from (select '::/127'::ip6r as a) s; select is_cidr(a), is_cidr(a::iprange), masklen(a), masklen(a::iprange) from (select '::/1'::ip6r as a) s; select is_cidr(a), is_cidr(a::iprange), masklen(a), masklen(a::iprange) from (select '::/0'::ip6r as a) s; select is_cidr(a), is_cidr(a::iprange), masklen(a), masklen(a::iprange) from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128'::ip6r as a) s; select is_cidr(a), is_cidr(a::iprange), masklen(a), masklen(a::iprange) from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffe/127'::ip6r as a) s; select is_cidr(a), is_cidr(a::iprange), masklen(a), masklen(a::iprange) from (select 'ffff:ffff:ffff:ffff:8000::/65'::ip6r as a) s; select is_cidr(a), is_cidr(a::iprange), masklen(a), masklen(a::iprange) from (select 'ffff:ffff:ffff:ffff::/64'::ip6r as a) s; select is_cidr(a), is_cidr(a::iprange), masklen(a), masklen(a::iprange) from (select 'ffff:ffff:ffff:fffe::/63'::ip6r as a) s; select is_cidr(a), is_cidr(a::iprange), masklen(a), masklen(a::iprange) from (select 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128'::ip6r as a) s; select ip4_net_lower('255.255.255.255',0); select ip4_net_lower('255.255.255.255',1); select ip4_net_lower('255.255.255.255',24); select ip4_net_lower('255.255.255.255',31); select ip4_net_lower('255.255.255.255',32); select ip4_net_lower('255.255.255.255',33); select ip4_net_lower('255.255.255.255',-1); select ip4_net_upper('0.0.0.0',0); select ip4_net_upper('0.0.0.0',1); select ip4_net_upper('0.0.0.0',24); select ip4_net_upper('0.0.0.0',31); select ip4_net_upper('0.0.0.0',32); select ip4_net_upper('0.0.0.0',33); select ip4_net_upper('0.0.0.0',-1); select ip6_net_lower('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',0); select ip6_net_lower('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',1); select ip6_net_lower('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',63); select ip6_net_lower('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',64); select ip6_net_lower('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',65); select ip6_net_lower('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',127); select ip6_net_lower('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',128); select ip6_net_lower('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',129); select ip6_net_lower('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',-1); select ip6_net_upper('::',0); select ip6_net_upper('::',1); select ip6_net_upper('::',63); select ip6_net_upper('::',64); select ip6_net_upper('::',65); select ip6_net_upper('::',127); select ip6_net_upper('::',128); select ip6_net_upper('::',129); select ip6_net_upper('::',-1); select ipaddress_net_lower('255.255.255.255',0); select ipaddress_net_lower('255.255.255.255',1); select ipaddress_net_lower('255.255.255.255',24); select ipaddress_net_lower('255.255.255.255',31); select ipaddress_net_lower('255.255.255.255',32); select ipaddress_net_lower('255.255.255.255',33); select ipaddress_net_lower('255.255.255.255',-1); select ipaddress_net_upper('0.0.0.0',0); select ipaddress_net_upper('0.0.0.0',1); select ipaddress_net_upper('0.0.0.0',24); select ipaddress_net_upper('0.0.0.0',31); select ipaddress_net_upper('0.0.0.0',32); select ipaddress_net_upper('0.0.0.0',33); select ipaddress_net_upper('0.0.0.0',-1); select ipaddress_net_lower('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',0); select ipaddress_net_lower('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',1); select ipaddress_net_lower('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',63); select ipaddress_net_lower('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',64); select ipaddress_net_lower('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',65); select ipaddress_net_lower('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',127); select ipaddress_net_lower('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',128); select ipaddress_net_lower('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',129); select ipaddress_net_lower('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',-1); select ipaddress_net_upper('::',0); select ipaddress_net_upper('::',1); select ipaddress_net_upper('::',63); select ipaddress_net_upper('::',64); select ipaddress_net_upper('::',65); select ipaddress_net_upper('::',127); select ipaddress_net_upper('::',128); select ipaddress_net_upper('::',129); select ipaddress_net_upper('::',-1); select ip4r_union('1.0.0.0/24','2.0.0.0/16'); select ip4r_union('0.0.0.0/0','2.0.0.0/16'); select ip4r_union('0.0.0.0-3.0.0.0','2.0.0.0-4.0.0.0'); select ip6r_union('2000::/16','3000::/16'); select ip6r_union('2000::-4000::','3000::-5000::'); select ip6r_union('::/0','3000::-5000::'); select iprange_union('0.0.0.0/0','::/0'); select iprange_union('128.0.0.0/32','8000::/16'); select iprange_union('1.0.0.0/24','2.0.0.0/16'); select iprange_union('0.0.0.0/0','2.0.0.0/16'); select iprange_union('0.0.0.0-3.0.0.0','2.0.0.0-4.0.0.0'); select iprange_union('2000::/16','3000::/16'); select iprange_union('2000::-4000::','3000::-5000::'); select iprange_union('::/0','3000::-5000::'); select ip4r_inter('1.0.0.0/24','2.0.0.0/16'); select ip4r_inter('0.0.0.0/0','2.0.0.0/16'); select ip4r_inter('0.0.0.0-3.0.0.0','2.0.0.0-4.0.0.0'); select ip6r_inter('2000::/16','3000::/16'); select ip6r_inter('2000::-4000::','3000::-5000::'); select ip6r_inter('::/0','3000::-5000::'); select iprange_inter('0.0.0.0/0','::/0'); select iprange_inter('128.0.0.0/32','8000::/16'); select iprange_inter('1.0.0.0/24','2.0.0.0/16'); select iprange_inter('0.0.0.0/0','2.0.0.0/16'); select iprange_inter('0.0.0.0-3.0.0.0','2.0.0.0-4.0.0.0'); select iprange_inter('2000::/16','3000::/16'); select iprange_inter('2000::-4000::','3000::-5000::'); select iprange_inter('::/0','3000::-5000::'); -- operators select ip4 '255.255.255.255' / 32; select ip4 '255.255.255.255' / 31; select ip4 '255.255.255.255' / 16; select ip4 '255.255.255.255' / 0; select ip4 '255.255.255.255' / 1; select ip4 '255.255.255.255' / 33; select ip4 '255.255.255.255' / -1; select ip4 '255.255.255.255' / ip4 '255.255.255.0'; select ip4 '255.255.255.255' / ip4 '255.0.0.0'; select ip4 '255.255.255.255' / ip4 '0.255.255.255'; select ip4 '255.255.255.255' / ip4 '255.254.255.255'; select ip6 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' / 128; select ip6 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' / 127; select ip6 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' / 65; select ip6 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' / 64; select ip6 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' / 63; select ip6 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' / 1; select ip6 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' / 0; select ip6 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' / 129; select ip6 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' / -1; select ip6 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' / ip6 'ffff:ffff:ffff:ffff:ffff::'; select ip6 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' / ip6 'ffff:ffff:ffff::'; select ip6 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' / ip6 'ffff:ffff:ffff:ffff:ffff::ffff'; select ip6 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' / ip6 'ffff:ffff:ffff::ffff'; select ipaddress '255.255.255.255' / 32; select ipaddress '255.255.255.255' / 31; select ipaddress '255.255.255.255' / 16; select ipaddress '255.255.255.255' / 0; select ipaddress '255.255.255.255' / 1; select ipaddress '255.255.255.255' / 33; select ipaddress '255.255.255.255' / -1; select ipaddress '255.255.255.255' / ipaddress '255.255.255.0'; select ipaddress '255.255.255.255' / ipaddress '255.0.0.0'; select ipaddress 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' / 128; select ipaddress 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' / 127; select ipaddress 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' / 65; select ipaddress 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' / 64; select ipaddress 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' / 63; select ipaddress 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' / 1; select ipaddress 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' / 0; select ipaddress 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' / 129; select ipaddress 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' / -1; select ipaddress 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' / ipaddress 'ffff:ffff:ffff:ffff:ffff::'; select ipaddress 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' / ipaddress 'ffff:ffff:ffff::'; select ipaddress '255.255.255.255' / ipaddress '0.255.255.255'; select ipaddress '255.255.255.255' / ipaddress '255.254.255.255'; select ipaddress 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' / ipaddress 'ffff:ffff:ffff:ffff:ffff::ffff'; select ipaddress 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' / ipaddress 'ffff:ffff:ffff::ffff'; select ipaddress 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' / ipaddress '0.0.0.0'; select ipaddress '255.255.255.255' / ipaddress '::'; select @ a, @@ a, @ (a::iprange), @@ (a::iprange) from (select '0.0.0.0/32'::ip4r as a) s; select @ a, @@ a, @ (a::iprange), @@ (a::iprange) from (select '0.0.0.0/31'::ip4r as a) s; select @ a, @@ a, @ (a::iprange), @@ (a::iprange) from (select '0.0.0.0/16'::ip4r as a) s; select @ a, @@ a, @ (a::iprange), @@ (a::iprange) from (select '0.0.0.0/1'::ip4r as a) s; select @ a, @@ a, @ (a::iprange), @@ (a::iprange) from (select '0.0.0.0/0'::ip4r as a) s; select @ a, @@ a, @ (a::iprange), @@ (a::iprange) from (select '1.2.3.4-5.6.7.8'::ip4r as a) s; select @ a, @@ a, @ (a::iprange), @@ (a::iprange) from (select '::/128'::ip6r as a) s; select @ a, @@ a, @ (a::iprange), @@ (a::iprange) from (select '::/127'::ip6r as a) s; select @ a, @@ a, @ (a::iprange), @@ (a::iprange) from (select '::/65'::ip6r as a) s; select @ a, @@ a, @ (a::iprange), @@ (a::iprange) from (select '::/64'::ip6r as a) s; select @ a, @@ a, @ (a::iprange), @@ (a::iprange) from (select '::/63'::ip6r as a) s; select @ a, @@ a, @ (a::iprange), @@ (a::iprange) from (select '::/1'::ip6r as a) s; select @ a, @@ a, @ (a::iprange), @@ (a::iprange) from (select '::/0'::ip6r as a) s; select @ a, @@ a, @ (a::iprange), @@ (a::iprange) from (select 'ffff:ffff:ffff:ffff::-ffff:ffff:ffff:ffff:8000::'::ip6r as a) s; select @ a, @@ a, @ (a::iprange), @@ (a::iprange) from (select 'ffff:ffff:ffff::-ffff:ffff:ffff:8000::'::ip6r as a) s; select @ a, @@ a, @ (a::iprange), @@ (a::iprange) from (select 'ffff:ffff::-ffff:ffff:8000::'::ip6r as a) s; select @ a, @@ a, @ (a::iprange), @@ (a::iprange) from (select 'ffff::-ffff:8000::'::ip6r as a) s; select @ a, @@ a from (select '-'::iprange as a) s; -- bitwise ops select a & b, a::ipaddress & b::ipaddress from (select ip4 '1.2.3.4' as a, ip4 '255.0.255.0' as b) s; select a | b, a::ipaddress | b::ipaddress from (select ip4 '1.2.3.4' as a, ip4 '255.0.255.0' as b) s; select a # b, a::ipaddress # b::ipaddress from (select ip4 '1.2.3.4' as a, ip4 '255.0.255.0' as b) s; select ~a, ~(a::ipaddress) from (select ip4 '1.2.3.4' as a) s; select a & b, a::ipaddress & b::ipaddress from (select ip6 '1234::5678' as a, ip6 'ffff:0000:ffff:0000:ffff:0000:ffff:0000' as b) s; select a | b, a::ipaddress | b::ipaddress from (select ip6 '1234::5678' as a, ip6 'ffff:0000:ffff:0000:ffff:0000:ffff:0000' as b) s; select a # b, a::ipaddress # b::ipaddress from (select ip6 '1234::5678' as a, ip6 'ffff:0000:ffff:0000:ffff:0000:ffff:0000' as b) s; select ~a, ~(a::ipaddress) from (select ip6 '1234::5678' as a) s; -- arithmetic select a + 1234, a::ipaddress + 1234 from (select ip4 '0.0.0.0' as a) s; select a + 1, a::ipaddress + 1 from (select ip4 '255.255.255.254' as a) s; select a + 1 from (select ip4 '255.255.255.255' as a) s; select a::ipaddress + 1 from (select ip4 '255.255.255.255' as a) s; select a - 1234, a::ipaddress - 1234 from (select ip4 '1.0.0.0' as a) s; select a - 1, a::ipaddress - 1 from (select ip4 '0.0.0.1' as a) s; select a - 1 from (select ip4 '0.0.0.0' as a) s; select a::ipaddress - 1 from (select ip4 '0.0.0.0' as a) s; select a + 1234::bigint, a::ipaddress + 1234::bigint from (select ip4 '0.0.0.0' as a) s; select a + 1::bigint, a::ipaddress + 1::bigint from (select ip4 '255.255.255.254' as a) s; select a + 1::bigint from (select ip4 '255.255.255.255' as a) s; select a::ipaddress + 1::bigint from (select ip4 '255.255.255.255' as a) s; select a + 4294967296::bigint from (select ip4 '0.0.0.0' as a) s; select a::ipaddress + 4294967296::bigint from (select ip4 '0.0.0.0' as a) s; select a - 1234::bigint, a::ipaddress - 1234::bigint from (select ip4 '1.0.0.0' as a) s; select a - 1::bigint, a::ipaddress - 1::bigint from (select ip4 '0.0.0.1' as a) s; select a - 1::bigint from (select ip4 '0.0.0.0' as a) s; select a::ipaddress - 1::bigint from (select ip4 '0.0.0.0' as a) s; select a - 4294967296::bigint from (select ip4 '255.255.255.255' as a) s; select a::ipaddress - 4294967296::bigint from (select ip4 '255.255.255.255' as a) s; select a + 1234::numeric, a::ipaddress + 1234::numeric from (select ip4 '0.0.0.0' as a) s; select a + 1::numeric, a::ipaddress + 1::numeric from (select ip4 '255.255.255.254' as a) s; select a + 1::numeric from (select ip4 '255.255.255.255' as a) s; select a::ipaddress + 1::numeric from (select ip4 '255.255.255.255' as a) s; select a + 4294967296::numeric from (select ip4 '0.0.0.0' as a) s; select a::ipaddress + 4294967296::numeric from (select ip4 '0.0.0.0' as a) s; select a - 1234::numeric, a::ipaddress - 1234::numeric from (select ip4 '1.0.0.0' as a) s; select a - 1::numeric, a::ipaddress - 1::numeric from (select ip4 '0.0.0.1' as a) s; select a - 1::numeric from (select ip4 '0.0.0.0' as a) s; select a::ipaddress - 1::numeric from (select ip4 '0.0.0.0' as a) s; select a - 4294967296::bigint from (select ip4 '255.255.255.255' as a) s; select a::ipaddress - 4294967296::bigint from (select ip4 '255.255.255.255' as a) s; -- predicates and indexing create table ipranges (r iprange, r4 ip4r, r6 ip6r); insert into ipranges select r, null, r from (select ip6r(regexp_replace(ls, E'(....(?!$))', E'\\1:', 'g')::ip6, regexp_replace(substring(ls for n+1) || substring(us from n+2), E'(....(?!$))', E'\\1:', 'g')::ip6) as r from (select md5(i || ' lower 1') as ls, md5(i || ' upper 1') as us, (i % 11) + (i/11 % 11) + (i/121 % 11) as n from generate_series(1,13310) i) s1) s2; insert into ipranges select r, r, null from (select ip4r(ip4 '0.0.0.0' + ((la & '::ffff:ffff') - ip6 '::'), ip4 '0.0.0.0' + ((( (la & ip6_netmask(127-n)) | (ua & ~ip6_netmask(127-n)) ) & '::ffff:ffff') - ip6 '::')) as r from (select regexp_replace(md5(i || ' lower 2'), E'(....(?!$))', E'\\1:', 'g')::ip6 as la, regexp_replace(md5(i || ' upper 2'), E'(....(?!$))', E'\\1:', 'g')::ip6 as ua, (i % 11) + (i/11 % 11) + (i/121 % 11) as n from generate_series(1,1331) i) s1) s2; insert into ipranges select r, null, r from (select n::ip6 / 68 as r from (select ((8192 + i/256)::numeric * (2::numeric ^ 112) + (131072 + (i % 256))::numeric * (2::numeric ^ 60)) as n from generate_series(0,4095) i) s1) s2; insert into ipranges select r, r, null from (select n / 28 as r from (select ip4 '172.16.0.0' + (i * 256) as n from generate_series(0,4095) i) s1) s2; insert into ipranges select r, null, r from (select n::ip6 / 48 as r from (select ((8192 + i/256)::numeric * (2::numeric ^ 112) + (i % 256)::numeric * (2::numeric ^ 84)) as n from generate_series(0,4095) i) s1) s2; insert into ipranges select r, r, null from (select n / 16 as r from (select ip4 '128.0.0.0' + (i * 65536) as n from generate_series(0,4095) i) s1) s2; insert into ipranges values ('-',null,null); create table ipaddrs (a ipaddress, a4 ip4, a6 ip6); insert into ipaddrs select a, null, a from (select regexp_replace(md5(i || ' address 1'), E'(....(?!$))', E'\\1:', 'g')::ip6 as a from generate_series(1,256) i) s1; insert into ipaddrs select a, a, null from (select ip4 '0.0.0.0' + ((regexp_replace(md5(i || ' address 1'), E'(....(?!$))', E'\\1:', 'g')::ip6 & '::ffff:ffff') - '::') as a from generate_series(1,16) i) s1; select * from ipranges where r >>= '5555::' order by r; select * from ipranges where r <<= '5555::/16' order by r; select * from ipranges where r && '5555::/16' order by r; select * from ipranges where r6 >>= '5555::' order by r6; select * from ipranges where r6 <<= '5555::/16' order by r6; select * from ipranges where r6 && '5555::/16' order by r6; select * from ipranges where r >>= '172.16.2.0' order by r; select * from ipranges where r <<= '10.0.0.0/12' order by r; select * from ipranges where r && '10.128.0.0/12' order by r; select * from ipranges where r4 >>= '172.16.2.0' order by r4; select * from ipranges where r4 <<= '10.0.0.0/12' order by r4; select * from ipranges where r4 && '10.128.0.0/12' order by r4; select * from ipranges where r >>= '2001:0:0:2000:a123::' order by r; select * from ipranges where r >>= '2001:0:0:2000::' order by r; select * from ipranges where r >>= '2001:0:0:2000::/68' order by r; select * from ipranges where r >> '2001:0:0:2000::/68' order by r; select * from ipranges where r6 >>= '2001:0:0:2000:a123::' order by r6; select * from ipranges where r6 >>= '2001:0:0:2000::' order by r6; select * from ipranges where r6 >>= '2001:0:0:2000::/68' order by r6; select * from ipranges where r6 >> '2001:0:0:2000::/68' order by r6; select * from ipranges where r4 >>= '172.16.2.0/28' order by r4; select * from ipranges where r4 >> '172.16.2.0/28' order by r4; select * from ipaddrs where a between '8.0.0.0' and '15.0.0.0' order by a; select * from ipaddrs where a4 between '8.0.0.0' and '15.0.0.0' order by a4; create index ipranges_r on ipranges using gist (r); create index ipranges_r4 on ipranges using gist (r4); create index ipranges_r6 on ipranges using gist (r6); create index ipaddrs_a on ipaddrs (a); create index ipaddrs_a4 on ipaddrs (a4); create index ipaddrs_a6 on ipaddrs (a6); select * from ipranges where r >>= '5555::' order by r; select * from ipranges where r <<= '5555::/16' order by r; select * from ipranges where r && '5555::/16' order by r; select * from ipranges where r6 >>= '5555::' order by r6; select * from ipranges where r6 <<= '5555::/16' order by r6; select * from ipranges where r6 && '5555::/16' order by r6; select * from ipranges where r >>= '172.16.2.0' order by r; select * from ipranges where r <<= '10.0.0.0/12' order by r; select * from ipranges where r && '10.128.0.0/12' order by r; select * from ipranges where r4 >>= '172.16.2.0' order by r4; select * from ipranges where r4 <<= '10.0.0.0/12' order by r4; select * from ipranges where r4 && '10.128.0.0/12' order by r4; select * from ipranges where r >>= '2001:0:0:2000:a123::' order by r; select * from ipranges where r >>= '2001:0:0:2000::' order by r; select * from ipranges where r >>= '2001:0:0:2000::/68' order by r; select * from ipranges where r >> '2001:0:0:2000::/68' order by r; select * from ipranges where r6 >>= '2001:0:0:2000:a123::' order by r6; select * from ipranges where r6 >>= '2001:0:0:2000::' order by r6; select * from ipranges where r6 >>= '2001:0:0:2000::/68' order by r6; select * from ipranges where r6 >> '2001:0:0:2000::/68' order by r6; select * from ipranges where r4 >>= '172.16.2.0/28' order by r4; select * from ipranges where r4 >> '172.16.2.0/28' order by r4; select * from ipaddrs where a between '8.0.0.0' and '15.0.0.0' order by a; select * from ipaddrs where a4 between '8.0.0.0' and '15.0.0.0' order by a4; select * from ipaddrs a join ipranges r on (r.r >>= a.a) order by a,r; select * from ipaddrs a join ipranges r on (r.r4 >>= a.a4) order by a4,r4; select * from ipaddrs a join ipranges r on (r.r6 >>= a.a6) order by a6,r6; -- hashing select lower(a / 4), count(*) from ipaddrs group by 1 order by 2,1; select a4 & '240.0.0.0', count(*) from ipaddrs group by 1 order by 2,1; select a6 & 'f000::', count(*) from ipaddrs group by 1 order by 2,1; select a / 4, count(*) from ipaddrs group by 1 order by 2,1; select a4 / 4, count(*) from ipaddrs group by 1 order by 2,1; select a6 / 4, count(*) from ipaddrs group by 1 order by 2,1; -- comparison ops select sum((r < '2000::/48')::integer) as s_lt, sum((r <= '2000::/48')::integer) as s_le, sum((r = '2000::/48')::integer) as s_eq, sum((r >= '2000::/48')::integer) as s_ge, sum((r > '2000::/48')::integer) as s_gt, sum((r <> '2000::/48')::integer) as s_ne from ipranges; select sum((r6 < '2000::/48')::integer) as s_lt, sum((r6 <= '2000::/48')::integer) as s_le, sum((r6 = '2000::/48')::integer) as s_eq, sum((r6 >= '2000::/48')::integer) as s_ge, sum((r6 > '2000::/48')::integer) as s_gt, sum((r6 <> '2000::/48')::integer) as s_ne from ipranges; select sum((r4 < '172.16.0.0/28')::integer) as s_lt, sum((r4 <= '172.16.0.0/28')::integer) as s_le, sum((r4 = '172.16.0.0/28')::integer) as s_eq, sum((r4 >= '172.16.0.0/28')::integer) as s_ge, sum((r4 > '172.16.0.0/28')::integer) as s_gt, sum((r4 <> '172.16.0.0/28')::integer) as s_ne from ipranges; select sum((a < '8ecc:14db:7aba:bbde:f2a7:c4bc:7a1e:c8c1')::integer) as s_lt, sum((a <= '8ecc:14db:7aba:bbde:f2a7:c4bc:7a1e:c8c1')::integer) as s_le, sum((a = '8ecc:14db:7aba:bbde:f2a7:c4bc:7a1e:c8c1')::integer) as s_eq, sum((a >= '8ecc:14db:7aba:bbde:f2a7:c4bc:7a1e:c8c1')::integer) as s_ge, sum((a > '8ecc:14db:7aba:bbde:f2a7:c4bc:7a1e:c8c1')::integer) as s_gt, sum((a <> '8ecc:14db:7aba:bbde:f2a7:c4bc:7a1e:c8c1')::integer) as s_ne from ipaddrs; select sum((a6 < '8ecc:14db:7aba:bbde:f2a7:c4bc:7a1e:c8c1')::integer) as s_lt, sum((a6 <= '8ecc:14db:7aba:bbde:f2a7:c4bc:7a1e:c8c1')::integer) as s_le, sum((a6 = '8ecc:14db:7aba:bbde:f2a7:c4bc:7a1e:c8c1')::integer) as s_eq, sum((a6 >= '8ecc:14db:7aba:bbde:f2a7:c4bc:7a1e:c8c1')::integer) as s_ge, sum((a6 > '8ecc:14db:7aba:bbde:f2a7:c4bc:7a1e:c8c1')::integer) as s_gt, sum((a6 <> '8ecc:14db:7aba:bbde:f2a7:c4bc:7a1e:c8c1')::integer) as s_ne from ipaddrs; select sum((a4 < '104.175.11.72')::integer) as s_lt, sum((a4 <= '104.175.11.72')::integer) as s_le, sum((a4 = '104.175.11.72')::integer) as s_eq, sum((a4 >= '104.175.11.72')::integer) as s_ge, sum((a4 > '104.175.11.72')::integer) as s_gt, sum((a4 <> '104.175.11.72')::integer) as s_ne from ipaddrs; -- end