Pfx.iana_special
iana_special
, go back to Pfx module for more information.
Specs
Returns one or all the properties as per Iana's special purpose address
registry for given prefix
.
See:
If given either :ip4
or :ip6
as the first argument, the property
argument is ignored and the associated list of prefixes and their properties
is returned. The list contains two-element tuples, the first element is a
Pfx.t/0
struct and the second element a map with the properties
associated with the prefix. The list is ordered on the first tuple element,
more to less specific.
Otherwise, prefix
is taken to be a prefix/0
and can be a full address.
If there is no match with any of the prefixes in the associated special purpose
address registry, nil
is returned.
If the property argument is omitted, it defaults to nil
and in case of a match
the property map is returned. If there is no match, nil is returned.
Otherwise, an individual property value is returned and property
can be one of:
:prefix
, a string: the owner prefix:source
, a semi-boolean: whether or notprefix
is a valid source address:destination
, a semi-boolean: whether or notprefix
is a valid destination address:forward
, a semi-boolean: whether or notprefix
can be forwarded (by a router):global
, a semi-boolean: whether or notprefix
is reachable on the Internet:reserved
, a semi-boolean: whether or notprefix
is reserved-by-protocol:name
: a string: the description of the entry in the special purpose address registryspec
: a list of strings: naming the rfc's and errata related to givenprefix
allocation
: a string denotingyyyy-mm
of the registry's entry
A semi-boolean, for lack of a better word, can have 3 values:
true
,false
, or:na
, which means not-applicable in the eyes of iana
The :na
case currently appears only for:
192.88.99.0/24
(deprecated 6to4),2002::/16
(6to4), and2001::/32
(teredo)
The :name
property value is somewhat normalized, but will be tricky to rely
on in code since that may change at the whim of the RFC editors.
Examples
iex> iana_special(:ip4) |> hd()
{%Pfx{bits: <<0, 0, 0, 0>>, maxlen: 32},
%{
allocation: "1981-09",
destination: false,
forward: false,
global: false,
name: "this-host-on-this-network",
prefix: "0.0.0.0/32",
reserved: true,
source: true,
spec: ["rfc1122"]
}}
iex> iana_special(:ip4) |> length()
25
iex> iana_special(:ip6) |> length()
20
iex> iana_special("10.10.10.10")
%{
allocation: "1996-02",
destination: true,
forward: true,
global: false,
name: "private-use",
prefix: "10.0.0.0/8",
reserved: false,
source: true,
spec: ["rfc1918"]
}
iex> iana_special("10.11.12.13", :global)
false
iex> iana_special("10.11.12.13", :name)
"private-use"
iex> iana_special("fc00::/7", :global)
false
iex> iana_special("fc00::/7", :name)
"unique-local"
iex> iana_special("2001::/32", :global)
:na
iex> iana_special("2001::/32", :name)
"teredo"
iex> iana_special("2001::/23", :name)
"ietf-protocol-assignments"