iana

package
v1.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 2, 2021 License: MIT Imports: 3 Imported by: 1

README

iana

Documentation CircleCI Go Report Card Coverage Status

This package imports the Internet Assigned Number Authority (IANA) Special IP Address Registry for IPv4 and IPv6 and exposes it as a data structure. Functions allow a caller to compare the registry against net.IP and iplib.Net objects to see if they contain or are contained within an reserved IP address block.

Installing

go get -u github.com/c-robinson/iplib/iana

Using IANA

Here are examples comparing against both an address and a network. Note that in the network case it is entirely possible for a broad-enough network to contain multiple reservations. If this is the case all reservations will be returned.

package main

import (
	"fmt"
	"net"
	
	"github.com/c-robinson/iplib"
	"github.com/c-robinson/iplib/iana"
)

func main() {
	ipa := net.ParseIP("144.21.21.21")
	ipb := net.ParseIP("192.168.12.5")
	
	res := iana.GetReservationsForIP(ipa)
	fmt.Println(len(res))                 // 0
	
	res = iana.GetReservationsForIP(ipb)
	fmt.Println(len(res))                 // 1
	fmt.Println(res[0].Title)             // "Private-Use"
	fmt.Println(res[0].RFC)               // ["RFC1918"]
	
	_, neta, _ := iplib.ParseCIDR("2001::/16")
	
	res = iana.GetReservationsForNetwork(neta)
	fmt.Println(len(res))                     // 10
	fmt.Println(iana.IsForwardable(neta))     // false
	fmt.Println(iana.IsGlobal(neta))          // false
	fmt.Println(iana.IsReserved(neta))        // true
	fmt.Println(iana.GetRFCsForNetwork(neta)) // all relevant RFCs, in this case: 
	                                          // [RFC1752,RFC2928,RFC3849,RFC4380,
	                                          //  RFC5180,RFC7343,RFC7450,RFC7535,
	                                          //  RFC7723,RFC7954,RFC8155,RFC8190]
}

Documentation

Overview

Package iana imports the Internet Assigned Numbers Authority (IANA) IP Special Registries as a data structure and implements functions to compare the reserved networks against iplib.Net objects. The IANA registry is used to reserve portions of IP network space for special use, examples being the IPv4 Private Use blocks (10.0.0/8, 172.16.0.0/12 and 192.168.0.0/16) and the IPv6 netblock set aside for documentation purposes (2001:db8::/32).

Note that this package does not contain historical reservations. So IPv6 2001:10::/28 (ORCHIDv1) is listed in the document as "deprecated" and not present in this library.

The data-set for the IANA registries is available from:

- https://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml

- https://www.iana.org/assignments/iana-ipv6-special-registry/iana-ipv6-special-registry.xhtml

Index

Constants

This section is empty.

Variables

View Source
var Registry []*Reservation

Registry holds the aggregated network list from IANA's v4 and v6 registries. Only the following fields were imported: Address Block, Name, RFC, Forwardable, Globally Reachable and Reserved-by-Protocol

Functions

func GetRFCsForNetwork

func GetRFCsForNetwork(n iplib.Net) []string

GetRFCsForNetwork returns a list of all RFCs that apply to the given network

func IsForwardable

func IsForwardable(n iplib.Net) bool

IsForwardable will return false if the given iplib.Net contains or is contained in a network that is marked not-forwardable in the IANA registry. IANA defines a forwardable network as one where "...a router may forward an IP datagram whose destination address is drawn from the allocated special- purpose address block between external interfaces." The default is 'true'

func IsGlobal

func IsGlobal(n iplib.Net) bool

IsGlobal will return false if the given iplib.Net contains or is contained in a network that is marked not-global in the IANA registry. IANA defines a global network as one where "...an IP datagram whose destination address is drawn from the allocated special-purpose address block is forwardable beyond a specified administrative domain." The default is 'true'

func IsReserved

func IsReserved(n iplib.Net) bool

IsReserved will return true if the given iplib.Net contains or is contained in a network that is marked reserved-by-protocol in the IANA registry. IANA defines a reserved network as one where "...the RFC that created the special-purpose address block requires all compliant IP implementations to behave in a special way when processing packets either to or from addresses contained by the address block." The default is 'false'

Types

type Reservation

type Reservation struct {

	// Network is the reserved network
	Network iplib.Net

	// Title is a name given to the reservation
	Title string

	// RFC is the list of relevant RFCs
	RFC []string

	// true if a router may forward packets bound for this network between
	// external interfaces
	Forwardable bool

	// true if a router may pass packets bound for this network outside of
	// a private network
	Global bool

	// true if an IP implementation must implement this policy in order to
	// be compliant
	Reserved bool
}

Reservation describes an entry in the IANA IP Special Registry

func GetReservationsForIP

func GetReservationsForIP(ip net.IP) []*Reservation

GetReservationsForIP returns a list of any IANA reserved networks that the supplied IP is part of

func GetReservationsForNetwork

func GetReservationsForNetwork(n iplib.Net) []*Reservation

GetReservationsForNetwork returns a list of any IANA reserved networks that are either part of the supplied network or that the supplied network is part of

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL